blob: c2758e4a6244a2d96350ce54a0fbfc8825d3b0e9 [file] [log] [blame]
Kevin Lubick217056c2018-09-20 17:39:31 -04001/*
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 the output. That JS will be
7 * hit by the closure compiler and thus needs to know about what functions
8 * have special names and should not be minified.
9 *
10 * Emscripten does not support automatically generating an externs file, so we
11 * do it by hand. The general process is to write some JS code, and then put any
12 * calls to CanvasKit or related things in here. Running ./compile.sh and then
13 * looking at the minified results or running the Release trybot should
14 * verify nothing was missed. Optionally, looking directly at the minified
15 * pathkit.js can be useful when developing locally.
16 *
17 * Docs:
18 * https://github.com/cljsjs/packages/wiki/Creating-Externs
19 * https://github.com/google/closure-compiler/wiki/Types-in-the-Closure-Type-System
20 *
21 * Example externs:
22 * https://github.com/google/closure-compiler/tree/master/externs
23 */
24
25var CanvasKit = {
26 // public API (i.e. things we declare in the pre-js file)
Kevin Lubick006a6f32018-10-19 14:34:34 -040027 Color: function() {},
28 /** @return {CanvasKit.SkRect} */
29 LTRBRect: function() {},
30 MakeCanvas: function() {},
31 MakeCanvasSurface: function() {},
Kevin Lubickb07204a2018-11-20 14:07:42 -050032 MakeSWCanvasSurface: function() {},
33 MakeWebGLCanvasSurface: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040034 MakeImageShader: function() {},
35 MakeLinearGradientShader: function() {},
36 MakeRadialGradientShader: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040037 MakeNimaActor: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040038 MakeSkDashPathEffect: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040039 MakeSkVertices: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040040 MakeSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040041 currentContext: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040042 getSkDataBytes: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040043 initFonts: function() {},
44 setCurrentContext: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040045
46 // private API (i.e. things declared in the bindings that we use
47 // in the pre-js file)
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040048 _MakeImageShader: function() {},
49 _MakeLinearGradientShader: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040050 _MakeNimaActor: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040051 _MakeRadialGradientShader: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040052 _MakeSkDashPathEffect: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040053 _MakeSkVertices: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040054 _getRasterN32PremulSurface: function() {},
55 _getWebGLSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040056
Kevin Lubick1a05fce2018-11-20 12:51:16 -050057 // The testing object is meant to expose internal functions
58 // for more fine-grained testing, e.g. parseColor
59 _testing: {},
60
Kevin Lubick217056c2018-09-20 17:39:31 -040061 // Objects and properties on CanvasKit
62
Kevin Lubick134be1d2018-10-30 15:05:04 -040063 NimaActor: {
64 // public API (from C++ bindings)
65 duration: function() {},
66 getAnimationNames: function() {},
67 render: function() {},
68 seek: function() {},
69 setAnimationByIndex: function() {},
70 setAnimationByName: function() {},
71
72 // private API
73 },
74
Kevin Lubick006a6f32018-10-19 14:34:34 -040075 SkCanvas: {
76 // public API (from C++ bindings)
77 clear: function() {},
78 drawPaint: function() {},
79 drawPath: function() {},
80 drawText: function() {},
81 flush: function() {},
82 rotate: function() {},
83 save: function() {},
84 scale: function() {},
85 setMatrix: function() {},
86 skew: function() {},
87 translate: function() {},
88
89 // private API
90 delete: function() {},
91 },
92
93 SkImage: {
Alexander Khovansky3e119332018-11-15 02:01:19 +030094 // private API
95 _encodeToData: function() {},
96 _encodeToDataWithFormat: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040097 },
98
Kevin Lubick1a05fce2018-11-20 12:51:16 -050099 SkMatrix: {
Kevin Lubickb9db3902018-11-26 11:47:54 -0500100 identity: function() {},
101 mapPoints: function() {},
102 multiply: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500103 rotated: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500104 scaled: function() {},
105 skewed: function() {},
106 translated: function() {},
107 },
108
109 SkPaint: {
110 // public API (from C++ bindings)
111 /** @return {CanvasKit.SkPaint} */
112 copy: function() {},
113 getStrokeCap: function() {},
114 getStrokeJoin: function() {},
115 getStrokeMiter: function() {},
116 getStrokeWidth: function() {},
117 getTextSize: function() {},
118 measureText: function() {},
119 setAntiAlias: function() {},
120 setColor: function() {},
121 setPathEffect: function() {},
122 setShader: function() {},
123 setStrokeCap: function() {},
124 setStrokeJoin: function() {},
125 setStrokeMiter: function() {},
126 setStrokeWidth: function() {},
127 setStyle: function() {},
128 setTextSize: function() {},
129
130 //private API
131 delete: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500132 },
133
Kevin Lubick006a6f32018-10-19 14:34:34 -0400134 SkPath: {
135 // public API (from C++ bindings)
Kevin Lubickb9db3902018-11-26 11:47:54 -0500136 computeTightBounds: function() {},
137 /** @return {CanvasKit.SkPath} */
138 copy: function() {},
139 countPoints: function() {},
140 equals: function() {},
141 getBounds: function() {},
142 getFillType: function() {},
143 getPoint: function() {},
144 setFillType: function() {},
145 toSVGString: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400146
147 // private API
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500148 _addArc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400149 _addPath: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500150 _addRect: function() {},
Alexander Khovansky3e119332018-11-15 02:01:19 +0300151 _arc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400152 _arcTo: function() {},
153 _close: function() {},
154 _conicTo: function() {},
155 _cubicTo: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400156 _dash: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400157 _lineTo: function() {},
158 _moveTo: function() {},
159 _op: function() {},
160 _quadTo: function() {},
161 _rect: function() {},
162 _simplify: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400163 _stroke: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400164 _transform: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400165 _trim: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400166 delete: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500167 dump: function() {},
168 dumpHex: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400169 },
170
171 SkRect: {
172 fLeft: {},
173 fTop: {},
174 fRight: {},
175 fBottom: {},
176 },
177
178 SkSurface: {
179 // public API (from C++ bindings)
180 /** @return {CanvasKit.SkCanvas} */
181 getCanvas: function() {},
182 /** @return {CanvasKit.SkImage} */
183 makeImageSnapshot: function() {},
184
185 // private API
186 _flush: function() {},
187 _getRasterN32PremulSurface: function() {},
188 _readPixels: function() {},
189 delete: function() {},
190 },
191
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400192 SkVertices: {
193 // public API (from C++ bindings)
194 /** @return {CanvasKit.SkVertices} */
195 applyBones: function() {},
196
197 // private API
198 /** @return {CanvasKit.SkVertices} */
199 _applyBones: function() {},
200 },
201
Kevin Lubick006a6f32018-10-19 14:34:34 -0400202 // Constants and Enums
203 gpu: {},
204 skottie: {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400205
206 FillType: {
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500207 Winding: {},
208 EvenOdd: {},
209 InverseWinding: {},
210 InverseEvenOdd: {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400211 },
212
Alexander Khovansky3e119332018-11-15 02:01:19 +0300213 ImageFormat: {
214 PNG: {},
215 JPEG: {},
216 },
217
Kevin Lubickb9db3902018-11-26 11:47:54 -0500218 PaintStyle: {
219 Fill: {},
220 Stroke: {},
221 StrokeAndFill: {},
222 },
223
224 StrokeCap: {
225 Butt: {},
226 Round: {},
227 Square: {},
228 },
229
230 StrokeJoin: {
231 Miter: {},
232 Round: {},
233 Bevel: {},
234 },
235
Kevin Lubick006a6f32018-10-19 14:34:34 -0400236 // Things Enscriptem adds for us
237
Kevin Lubick53965c92018-10-11 08:51:55 -0400238 /** Represents the heap of the WASM code
239 * @type {ArrayBuffer}
240 */
241 buffer: {},
242 /**
243 * @type {Float32Array}
244 */
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400245 HEAPF32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400246 /**
247 * @type {Uint8Array}
248 */
249 HEAPU8: {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400250 /**
251 * @type {Uint16Array}
252 */
253 HEAPU16: {},
254 /**
255 * @type {Int32Array}
256 */
257 HEAP32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400258
Kevin Lubick006a6f32018-10-19 14:34:34 -0400259 _malloc: function() {},
260 _free: function() {},
261 onRuntimeInitialized: function() {},
262};
Kevin Lubick217056c2018-09-20 17:39:31 -0400263
Kevin Lubick006a6f32018-10-19 14:34:34 -0400264// Public API things that are newly declared in the JS should go here.
265// It's not enough to declare them above, because closure can still erase them
266// unless they go on the prototype.
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500267CanvasKit.SkPath.prototype.addArc = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400268CanvasKit.SkPath.prototype.addPath = function() {};
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500269CanvasKit.SkPath.prototype.addRect = function() {};
Alexander Khovansky3e119332018-11-15 02:01:19 +0300270CanvasKit.SkPath.prototype.arc = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400271CanvasKit.SkPath.prototype.arcTo = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400272CanvasKit.SkPath.prototype.close = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400273CanvasKit.SkPath.prototype.conicTo = function() {};
274CanvasKit.SkPath.prototype.cubicTo = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400275CanvasKit.SkPath.prototype.dash = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400276CanvasKit.SkPath.prototype.lineTo = function() {};
277CanvasKit.SkPath.prototype.moveTo = function() {};
278CanvasKit.SkPath.prototype.op = function() {};
279CanvasKit.SkPath.prototype.quadTo = function() {};
280CanvasKit.SkPath.prototype.rect = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400281CanvasKit.SkPath.prototype.simplify = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400282CanvasKit.SkPath.prototype.stroke = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400283CanvasKit.SkPath.prototype.transform = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400284CanvasKit.SkPath.prototype.trim = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400285
Kevin Lubick53965c92018-10-11 08:51:55 -0400286CanvasKit.SkSurface.prototype.flush = function() {};
Kevin Lubick5b90b842018-10-17 07:57:18 -0400287CanvasKit.SkSurface.prototype.dispose = function() {};
Kevin Lubick53965c92018-10-11 08:51:55 -0400288
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400289CanvasKit.SkVertices.prototype.applyBones = function() {};
290
Alexander Khovansky3e119332018-11-15 02:01:19 +0300291CanvasKit.SkImage.prototype.encodeToData = function() {};
292
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400293// Define StrokeOpts object
294var StrokeOpts = {};
295StrokeOpts.prototype.width;
296StrokeOpts.prototype.miter_limit;
297StrokeOpts.prototype.cap;
298StrokeOpts.prototype.join;
299
Kevin Lubickb9db3902018-11-26 11:47:54 -0500300var HTMLCanvas = {};
301HTMLCanvas.prototype.getContext = function() {};
302HTMLCanvas.prototype.toDataURL = function() {};
303HTMLCanvas.prototype.dispose = function() {};
304
305var CanvasRenderingContext2D = {};
306CanvasRenderingContext2D.prototype.addHitRegion = function() {};
307CanvasRenderingContext2D.prototype.arc = function() {};
308CanvasRenderingContext2D.prototype.arcTo = function() {};
309CanvasRenderingContext2D.prototype.beginPath = function() {};
310CanvasRenderingContext2D.prototype.bezierCurveTo = function() {};
311CanvasRenderingContext2D.prototype.clearHitRegions = function() {};
312CanvasRenderingContext2D.prototype.closePath = function() {};
313CanvasRenderingContext2D.prototype.drawFocusIfNeeded = function() {};
314CanvasRenderingContext2D.prototype.ellipse = function() {};
315CanvasRenderingContext2D.prototype.fillText = function() {};
316CanvasRenderingContext2D.prototype.lineTo = function() {};
317CanvasRenderingContext2D.prototype.measureText = function() {};
318CanvasRenderingContext2D.prototype.moveTo = function() {};
319CanvasRenderingContext2D.prototype.quadraticCurveTo = function() {};
320CanvasRenderingContext2D.prototype.rect = function() {};
321CanvasRenderingContext2D.prototype.removeHitRegion = function() {};
322CanvasRenderingContext2D.prototype.resetTransform = function() {};
323CanvasRenderingContext2D.prototype.rotate = function() {};
324CanvasRenderingContext2D.prototype.scale = function() {};
325CanvasRenderingContext2D.prototype.scrollPathIntoView = function() {};
326CanvasRenderingContext2D.prototype.setTransform = function() {};
327CanvasRenderingContext2D.prototype.stroke = function() {};
328CanvasRenderingContext2D.prototype.strokeText = function() {};
329CanvasRenderingContext2D.prototype.transform = function() {};
330CanvasRenderingContext2D.prototype.translate = function() {};
331
332
Kevin Lubick217056c2018-09-20 17:39:31 -0400333// Not sure why this is needed - might be a bug in emsdk that this isn't properly declared.
Kevin Lubick6fccc9d2018-11-20 15:55:10 -0500334function loadWebAssemblyModule() {};