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) {}, |
| 26 | onRuntimeInitialized: function() {}, |
| 27 | |
| 28 | HEAPF32: {}, |
| 29 | |
| 30 | SkPath: { |
| 31 | _addPath: function(path, scaleX, skewX, transX, skewY, scaleY, transY, pers0, pers1, pers2) {}, |
| 32 | _arc: function(x, y, radius, startAngle, endAngle, ccw) {}, |
| 33 | _arcTo: function(x1, y1, x2, y2, radius) {}, |
| 34 | _dash: function(on, off, phase) {}, |
| 35 | _close: function() {}, |
| 36 | _conicTo: function(x1, y1, x2, y2, w) {}, |
| 37 | copy: function() {}, |
| 38 | _cubicTo: function(cp1x, cp1y, cp2x, cp2y, x, y) {}, |
| 39 | _ellipse: function(x, y, radiusX, radiusY, rotation, startAngle, endAngle, ccw) {}, |
| 40 | _lineTo: function(x1, y1) {}, |
| 41 | _moveTo: function(x1, y1) {}, |
| 42 | _op: function(otherPath, op) {}, |
| 43 | _quadTo: function(x1, y1, x2, y2) {}, |
| 44 | _rect: function(x, y, w, h) {}, |
| 45 | _simplify: function() {}, |
| 46 | _stroke: function(opts) {}, |
| 47 | _trim: function(startT, stopT, isComplement) {}, |
| 48 | _transform: function() {}, // takes 1 or 9 params |
| 49 | }, |
| 50 | |
| 51 | StrokeCap: { |
| 52 | BUTT: {}, |
| 53 | ROUND: {}, |
| 54 | SQUARE: {}, |
| 55 | }, |
| 56 | StrokeJoin: { |
| 57 | MITER: {}, |
| 58 | ROUND: {}, |
| 59 | BEVEL: {}, |
| 60 | } |
| 61 | }; |
| 62 | |
| 63 | // Define StrokeOpts object |
| 64 | var StrokeOpts = {}; |
| 65 | StrokeOpts.prototype.width; |
| 66 | StrokeOpts.prototype.miter_limit; |
| 67 | StrokeOpts.prototype.cap; |
| 68 | StrokeOpts.prototype.join; |
| 69 | |
| 70 | |
| 71 | |
| 72 | // For whatever reason, the closure compiler thinks it can rename some of our |
| 73 | // prototype methods. Not entirely sure why. |
| 74 | // Listing them here prevents that. |
| 75 | PathKit.SkPath.prototype.addPath = function() {}; |
| 76 | PathKit.SkPath.prototype.arc = function(x, y, radius, startAngle, endAngle, ccw) {}; |
| 77 | PathKit.SkPath.prototype.arcTo = function(x1, y1, x2, y2, radius) {}; |
| 78 | PathKit.SkPath.prototype.bezierCurveTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {}; |
| 79 | PathKit.SkPath.prototype.close = function() {}; |
| 80 | PathKit.SkPath.prototype.closePath = function() {}; |
| 81 | PathKit.SkPath.prototype.conicTo = function(x1, y1, x2, y2, w) {}; |
| 82 | PathKit.SkPath.prototype.cubicTo = function(cp1x, cp1y, cp2x, cp2y, x, y) {}; |
| 83 | PathKit.SkPath.prototype.dash = function(on, off, phase) {}; |
| 84 | PathKit.SkPath.prototype.ellipse = function(x, y, radiusX, radiusY, rotation, startAngle, endAngle, ccw) {}; |
| 85 | PathKit.SkPath.prototype.lineTo = function(x, y) {}; |
| 86 | PathKit.SkPath.prototype.moveTo = function(x, y) {}; |
| 87 | PathKit.SkPath.prototype.op = function(otherPath, op) {}; |
| 88 | PathKit.SkPath.prototype.quadTo = function(x1, y1, x2, y2) {}; |
| 89 | PathKit.SkPath.prototype.quadraticCurveTo = function(x1, y1, x2, y2) {}; |
| 90 | PathKit.SkPath.prototype.rect = function(x, y, w, h) {}; |
| 91 | PathKit.SkPath.prototype.simplify = function() {}; |
| 92 | PathKit.SkPath.prototype.stroke = function(opts) {}; |
| 93 | PathKit.SkPath.prototype.transform = function() {}; |
| 94 | PathKit.SkPath.prototype.trim = function(startT, stopT, isComplement) {}; |
| 95 | // The following was taken from https://github.com/google/closure-compiler/blob/master/contrib/externs/svg.js |
| 96 | |
| 97 | /** |
| 98 | * @constructor |
| 99 | */ |
| 100 | function SVGMatrix(){} |
| 101 | |
| 102 | |
| 103 | /** |
| 104 | * @type {number} |
| 105 | */ |
| 106 | SVGMatrix.prototype.a; |
| 107 | |
| 108 | |
| 109 | /** |
| 110 | * @type {number} |
| 111 | */ |
| 112 | SVGMatrix.prototype.b; |
| 113 | |
| 114 | |
| 115 | /** |
| 116 | * @type {number} |
| 117 | */ |
| 118 | SVGMatrix.prototype.c; |
| 119 | |
| 120 | |
| 121 | /** |
| 122 | * @type {number} |
| 123 | */ |
| 124 | SVGMatrix.prototype.d; |
| 125 | |
| 126 | |
| 127 | /** |
| 128 | * @type {number} |
| 129 | */ |
| 130 | SVGMatrix.prototype.e; |
| 131 | |
| 132 | |
| 133 | /** |
| 134 | * @type {number} |
| 135 | */ |
| 136 | SVGMatrix.prototype.f; |