Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 1 | /* |
| 2 | * This externs file prevents the Closure JS compiler from minifying away |
| 3 | * names of objects created by Emscripten. |
| 4 | * Basically, by defining empty objects and functions here, Closure will |
| 5 | * know not to rename them. This is needed because of our pre-js files, |
| 6 | * that is, the JS we hand-write to bundle into PathKit. |
| 7 | * |
| 8 | * Emscripten does not support automatically generating an externs file, so we |
| 9 | * do it by hand. The general process is to write some JS code, and then put any |
| 10 | * calls to PathKit or related things in here. Running ./compile.sh and then |
| 11 | * looking at the minified results or running the Release-PathKit trybot should |
| 12 | * verify nothing was missed. Optionally, looking directly at the minified |
| 13 | * pathkit.js can be useful when developing locally. |
| 14 | * |
| 15 | * Docs: |
| 16 | * https://github.com/cljsjs/packages/wiki/Creating-Externs |
| 17 | * https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System |
| 18 | * |
| 19 | * Example externs: |
| 20 | * https://github.com/google/closure-compiler/tree/master/externs |
| 21 | */ |
| 22 | |
| 23 | var PathKit = { |
| 24 | SkBits2FloatUnsigned: function(num) {}, |
| 25 | _malloc: function(size) {}, |
Kevin Lubick | 556350d | 2018-10-12 15:21:17 -0400 | [diff] [blame^] | 26 | _free: function(ptr) {}, |
Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 27 | onRuntimeInitialized: function() {}, |
Kevin Lubick | d993648 | 2018-08-24 10:44:16 -0400 | [diff] [blame] | 28 | _FromCmds: function(ptr, size) {}, |
| 29 | loadCmdsTypedArray: function(arr) {}, |
| 30 | FromCmds: function(arr) {}, |
Kevin Lubick | 774be5a | 2018-09-07 14:00:41 -0400 | [diff] [blame] | 31 | _SkCubicMap: function(cp1, cp2) {}, |
| 32 | cubicYFromX: function(cpx1, cpy1, cpx2, cpy2, X) {}, |
| 33 | cubicPtFromT: function(cpx1, cpy1, cpx2, cpy2, T) {}, |
Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 34 | |
Kevin Lubick | 556350d | 2018-10-12 15:21:17 -0400 | [diff] [blame^] | 35 | /** |
| 36 | * @type {Float32Array} |
| 37 | */ |
Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 38 | HEAPF32: {}, |
| 39 | |
| 40 | SkPath: { |
| 41 | _addPath: function(path, scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2) {}, |
| 42 | _arc: function(x, y, radius, startAngle, endAngle, ccw) {}, |
| 43 | _arcTo: function(x1, y1, x2, y2, radius) {}, |
| 44 | _dash: function(on, off, phase) {}, |
| 45 | _close: function() {}, |
| 46 | _conicTo: function(x1, y1, x2, y2, w) {}, |
| 47 | copy: function() {}, |
| 48 | _cubicTo: function(cp1x, cp1y, cp2x, cp2y, x, y) {}, |
| 49 | _ellipse: function(x, y, radiusX, radiusY, rotation, startAngle, endAngle, ccw) {}, |
| 50 | _lineTo: function(x1, y1) {}, |
| 51 | _moveTo: function(x1, y1) {}, |
| 52 | _op: function(otherPath, op) {}, |
Kevin Lubick | d993648 | 2018-08-24 10:44:16 -0400 | [diff] [blame] | 53 | _quadTo: function(cpx, cpy, x, y) {}, |
Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 54 | _rect: function(x, y, w, h) {}, |
| 55 | _simplify: function() {}, |
| 56 | _stroke: function(opts) {}, |
| 57 | _trim: function(startT, stopT, isComplement) {}, |
| 58 | _transform: function() {}, // takes 1 or 9 params |
| 59 | }, |
| 60 | |
| 61 | StrokeCap: { |
| 62 | BUTT: {}, |
| 63 | ROUND: {}, |
| 64 | SQUARE: {}, |
| 65 | }, |
| 66 | StrokeJoin: { |
| 67 | MITER: {}, |
| 68 | ROUND: {}, |
| 69 | BEVEL: {}, |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | // Define StrokeOpts object |
| 74 | var StrokeOpts = {}; |
| 75 | StrokeOpts.prototype.width; |
| 76 | StrokeOpts.prototype.miter_limit; |
| 77 | StrokeOpts.prototype.cap; |
| 78 | StrokeOpts.prototype.join; |
| 79 | |
Kevin Lubick | 774be5a | 2018-09-07 14:00:41 -0400 | [diff] [blame] | 80 | // Define CubicMap object |
| 81 | var CubicMap = {}; |
| 82 | CubicMap.prototype.computeYFromX = function(x) {}; |
| 83 | CubicMap.prototype.computePtFromT = function(t) {}; |
Kevin Lubick | 11194ab | 2018-08-17 13:52:56 -0400 | [diff] [blame] | 84 | |
| 85 | |
| 86 | // For whatever reason, the closure compiler thinks it can rename some of our |
| 87 | // prototype methods. Not entirely sure why. |
| 88 | // Listing them here prevents that. |
| 89 | PathKit.SkPath.prototype.addPath = function() {}; |
| 90 | PathKit.SkPath.prototype.arc = function(x, y, radius, startAngle, endAngle, ccw) {}; |
| 91 | PathKit.SkPath.prototype.arcTo = function(x1, y1, x2, y2, radius) {}; |
| 92 | PathKit.SkPath.prototype.bezierCurveTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {}; |
| 93 | PathKit.SkPath.prototype.close = function() {}; |
| 94 | PathKit.SkPath.prototype.closePath = function() {}; |
| 95 | PathKit.SkPath.prototype.conicTo = function(x1, y1, x2, y2, w) {}; |
| 96 | PathKit.SkPath.prototype.cubicTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {}; |
| 97 | PathKit.SkPath.prototype.dash = function(on, off, phase) {}; |
| 98 | PathKit.SkPath.prototype.ellipse = function(x, y, radiusX, radiusY, rotation, startAngle, endAngle, ccw) {}; |
| 99 | PathKit.SkPath.prototype.lineTo = function(x, y) {}; |
| 100 | PathKit.SkPath.prototype.moveTo = function(x, y) {}; |
| 101 | PathKit.SkPath.prototype.op = function(otherPath, op) {}; |
| 102 | PathKit.SkPath.prototype.quadTo = function(x1, y1, x2, y2) {}; |
| 103 | PathKit.SkPath.prototype.quadraticCurveTo = function(x1, y1, x2, y2) {}; |
| 104 | PathKit.SkPath.prototype.rect = function(x, y, w, h) {}; |
| 105 | PathKit.SkPath.prototype.simplify = function() {}; |
| 106 | PathKit.SkPath.prototype.stroke = function(opts) {}; |
| 107 | PathKit.SkPath.prototype.transform = function() {}; |
| 108 | PathKit.SkPath.prototype.trim = function(startT, stopT, isComplement) {}; |
| 109 | // The following was taken from https://github.com/google/closure-compiler/blob/master/contrib/externs/svg.js |
| 110 | |
| 111 | /** |
| 112 | * @constructor |
| 113 | */ |
| 114 | function SVGMatrix(){} |
| 115 | |
| 116 | |
| 117 | /** |
| 118 | * @type {number} |
| 119 | */ |
| 120 | SVGMatrix.prototype.a; |
| 121 | |
| 122 | |
| 123 | /** |
| 124 | * @type {number} |
| 125 | */ |
| 126 | SVGMatrix.prototype.b; |
| 127 | |
| 128 | |
| 129 | /** |
| 130 | * @type {number} |
| 131 | */ |
| 132 | SVGMatrix.prototype.c; |
| 133 | |
| 134 | |
| 135 | /** |
| 136 | * @type {number} |
| 137 | */ |
| 138 | SVGMatrix.prototype.d; |
| 139 | |
| 140 | |
| 141 | /** |
| 142 | * @type {number} |
| 143 | */ |
| 144 | SVGMatrix.prototype.e; |
| 145 | |
| 146 | |
| 147 | /** |
| 148 | * @type {number} |
| 149 | */ |
| 150 | SVGMatrix.prototype.f; |