blob: e0c3be5e2497e719582fd8983e31f2a1d438ffaf [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() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -050030 MakeBlurMaskFilter: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040031 MakeCanvas: function() {},
32 MakeCanvasSurface: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040033 MakeImageShader: function() {},
34 MakeLinearGradientShader: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040035 MakeNimaActor: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -050036 MakeRadialGradientShader: function() {},
37 MakeSWCanvasSurface: 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 Lubick61ef7b22018-11-27 13:26:59 -050041 MakeWebGLCanvasSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040042 currentContext: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -050043 getColorComponents: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -050044 getSkDataBytes: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040045 initFonts: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -050046 multiplyByAlpha: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040047 setCurrentContext: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040048
49 // private API (i.e. things declared in the bindings that we use
50 // in the pre-js file)
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040051 _MakeImageShader: function() {},
52 _MakeLinearGradientShader: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040053 _MakeNimaActor: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040054 _MakeRadialGradientShader: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040055 _MakeSkDashPathEffect: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040056 _MakeSkVertices: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040057 _getRasterN32PremulSurface: function() {},
58 _getWebGLSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040059
Kevin Lubick1a05fce2018-11-20 12:51:16 -050060 // The testing object is meant to expose internal functions
61 // for more fine-grained testing, e.g. parseColor
62 _testing: {},
63
Kevin Lubick217056c2018-09-20 17:39:31 -040064 // Objects and properties on CanvasKit
65
Kevin Lubick134be1d2018-10-30 15:05:04 -040066 NimaActor: {
67 // public API (from C++ bindings)
68 duration: function() {},
69 getAnimationNames: function() {},
70 render: function() {},
71 seek: function() {},
72 setAnimationByIndex: function() {},
73 setAnimationByName: function() {},
74
75 // private API
76 },
77
Kevin Lubick006a6f32018-10-19 14:34:34 -040078 SkCanvas: {
79 // public API (from C++ bindings)
80 clear: function() {},
81 drawPaint: function() {},
82 drawPath: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -050083 drawRect: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -050084 drawShadow: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -050085 drawText: function() {},
86 drawVertices: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040087 flush: function() {},
88 rotate: function() {},
89 save: function() {},
90 scale: function() {},
91 setMatrix: function() {},
92 skew: function() {},
93 translate: function() {},
94
95 // private API
96 delete: function() {},
97 },
98
99 SkImage: {
Alexander Khovansky3e119332018-11-15 02:01:19 +0300100 // private API
101 _encodeToData: function() {},
102 _encodeToDataWithFormat: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400103 },
104
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500105 SkMatrix: {
Kevin Lubickb9db3902018-11-26 11:47:54 -0500106 identity: function() {},
107 mapPoints: function() {},
108 multiply: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500109 rotated: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500110 scaled: function() {},
111 skewed: function() {},
112 translated: function() {},
113 },
114
115 SkPaint: {
116 // public API (from C++ bindings)
117 /** @return {CanvasKit.SkPaint} */
118 copy: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -0500119 getBlendMode: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500120 getColor: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500121 getStrokeCap: function() {},
122 getStrokeJoin: function() {},
123 getStrokeMiter: function() {},
124 getStrokeWidth: function() {},
125 getTextSize: function() {},
126 measureText: function() {},
127 setAntiAlias: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -0500128 setBlendMode: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500129 setColor: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500130 setMaskFilter: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500131 setPathEffect: function() {},
132 setShader: function() {},
133 setStrokeCap: function() {},
134 setStrokeJoin: function() {},
135 setStrokeMiter: function() {},
136 setStrokeWidth: function() {},
137 setStyle: function() {},
138 setTextSize: function() {},
139
140 //private API
141 delete: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500142 },
143
Kevin Lubick006a6f32018-10-19 14:34:34 -0400144 SkPath: {
145 // public API (from C++ bindings)
Kevin Lubickb9db3902018-11-26 11:47:54 -0500146 computeTightBounds: function() {},
147 /** @return {CanvasKit.SkPath} */
148 copy: function() {},
149 countPoints: function() {},
150 equals: function() {},
151 getBounds: function() {},
152 getFillType: function() {},
153 getPoint: function() {},
154 setFillType: function() {},
155 toSVGString: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400156
157 // private API
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500158 _addArc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400159 _addPath: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500160 _addRect: function() {},
Alexander Khovansky3e119332018-11-15 02:01:19 +0300161 _arc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400162 _arcTo: function() {},
163 _close: function() {},
164 _conicTo: function() {},
165 _cubicTo: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400166 _dash: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400167 _lineTo: function() {},
168 _moveTo: function() {},
169 _op: function() {},
170 _quadTo: function() {},
171 _rect: function() {},
172 _simplify: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400173 _stroke: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400174 _transform: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400175 _trim: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400176 delete: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500177 dump: function() {},
178 dumpHex: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400179 },
180
181 SkRect: {
182 fLeft: {},
183 fTop: {},
184 fRight: {},
185 fBottom: {},
186 },
187
188 SkSurface: {
189 // public API (from C++ bindings)
190 /** @return {CanvasKit.SkCanvas} */
191 getCanvas: function() {},
192 /** @return {CanvasKit.SkImage} */
193 makeImageSnapshot: function() {},
194
195 // private API
196 _flush: function() {},
197 _getRasterN32PremulSurface: function() {},
198 _readPixels: function() {},
199 delete: function() {},
200 },
201
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400202 SkVertices: {
203 // public API (from C++ bindings)
Kevin Lubick12c0e502018-11-28 12:51:56 -0500204 bounds: function() {},
205 mode: function() {},
206 uniqueID: function() {},
207 vertexCount: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400208
209 // private API
210 /** @return {CanvasKit.SkVertices} */
211 _applyBones: function() {},
212 },
213
Kevin Lubick006a6f32018-10-19 14:34:34 -0400214 // Constants and Enums
215 gpu: {},
216 skottie: {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400217
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500218 TRANSPARENT: {},
219 RED: {},
220 BLUE: {},
221 YELLOW: {},
222 CYAN: {},
223 BLACK: {},
224
225 BlendMode: {
226 Clear: {},
227 Src: {},
228 Dst: {},
229 SrcOver: {},
230 DstOver: {},
231 SrcIn: {},
232 DstIn: {},
233 SrcOut: {},
234 DstOut: {},
235 SrcATop: {},
236 DstATop: {},
237 Xor: {},
238 Plus: {},
239 Modulate: {},
240 Screen: {},
241 Overlay: {},
242 Darken: {},
243 Lighten: {},
244 ColorDodge: {},
245 ColorBurn: {},
246 HardLight: {},
247 SoftLight: {},
248 Difference: {},
249 Exclusion: {},
250 Multiply: {},
251 Hue: {},
252 Saturation: {},
253 Color: {},
254 Luminosity: {},
255 },
256
257 BlurStyle: {
258 Normal: {},
259 Solid: {},
260 Outer: {},
261 Inner: {},
262 },
263
Kevin Lubick006a6f32018-10-19 14:34:34 -0400264 FillType: {
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500265 Winding: {},
266 EvenOdd: {},
267 InverseWinding: {},
268 InverseEvenOdd: {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400269 },
270
Alexander Khovansky3e119332018-11-15 02:01:19 +0300271 ImageFormat: {
272 PNG: {},
273 JPEG: {},
274 },
275
Kevin Lubickb9db3902018-11-26 11:47:54 -0500276 PaintStyle: {
277 Fill: {},
278 Stroke: {},
279 StrokeAndFill: {},
280 },
281
282 StrokeCap: {
283 Butt: {},
284 Round: {},
285 Square: {},
286 },
287
288 StrokeJoin: {
289 Miter: {},
290 Round: {},
291 Bevel: {},
292 },
293
Kevin Lubick006a6f32018-10-19 14:34:34 -0400294 // Things Enscriptem adds for us
295
Kevin Lubick53965c92018-10-11 08:51:55 -0400296 /** Represents the heap of the WASM code
297 * @type {ArrayBuffer}
298 */
299 buffer: {},
300 /**
301 * @type {Float32Array}
302 */
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400303 HEAPF32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400304 /**
305 * @type {Uint8Array}
306 */
307 HEAPU8: {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400308 /**
309 * @type {Uint16Array}
310 */
311 HEAPU16: {},
312 /**
313 * @type {Int32Array}
314 */
315 HEAP32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400316
Kevin Lubick006a6f32018-10-19 14:34:34 -0400317 _malloc: function() {},
318 _free: function() {},
319 onRuntimeInitialized: function() {},
320};
Kevin Lubick217056c2018-09-20 17:39:31 -0400321
Kevin Lubick006a6f32018-10-19 14:34:34 -0400322// Public API things that are newly declared in the JS should go here.
323// It's not enough to declare them above, because closure can still erase them
324// unless they go on the prototype.
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500325CanvasKit.SkPath.prototype.addArc = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400326CanvasKit.SkPath.prototype.addPath = function() {};
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500327CanvasKit.SkPath.prototype.addRect = function() {};
Alexander Khovansky3e119332018-11-15 02:01:19 +0300328CanvasKit.SkPath.prototype.arc = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400329CanvasKit.SkPath.prototype.arcTo = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400330CanvasKit.SkPath.prototype.close = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400331CanvasKit.SkPath.prototype.conicTo = function() {};
332CanvasKit.SkPath.prototype.cubicTo = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400333CanvasKit.SkPath.prototype.dash = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400334CanvasKit.SkPath.prototype.lineTo = function() {};
335CanvasKit.SkPath.prototype.moveTo = function() {};
336CanvasKit.SkPath.prototype.op = function() {};
337CanvasKit.SkPath.prototype.quadTo = function() {};
338CanvasKit.SkPath.prototype.rect = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400339CanvasKit.SkPath.prototype.simplify = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400340CanvasKit.SkPath.prototype.stroke = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400341CanvasKit.SkPath.prototype.transform = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400342CanvasKit.SkPath.prototype.trim = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400343
Kevin Lubick53965c92018-10-11 08:51:55 -0400344CanvasKit.SkSurface.prototype.flush = function() {};
Kevin Lubick5b90b842018-10-17 07:57:18 -0400345CanvasKit.SkSurface.prototype.dispose = function() {};
Kevin Lubick53965c92018-10-11 08:51:55 -0400346
Kevin Lubick12c0e502018-11-28 12:51:56 -0500347/** @return {CanvasKit.SkVertices} */
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400348CanvasKit.SkVertices.prototype.applyBones = function() {};
349
Alexander Khovansky3e119332018-11-15 02:01:19 +0300350CanvasKit.SkImage.prototype.encodeToData = function() {};
351
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400352// Define StrokeOpts object
353var StrokeOpts = {};
354StrokeOpts.prototype.width;
355StrokeOpts.prototype.miter_limit;
356StrokeOpts.prototype.cap;
357StrokeOpts.prototype.join;
358
Kevin Lubickb9db3902018-11-26 11:47:54 -0500359var HTMLCanvas = {};
360HTMLCanvas.prototype.getContext = function() {};
361HTMLCanvas.prototype.toDataURL = function() {};
362HTMLCanvas.prototype.dispose = function() {};
363
364var CanvasRenderingContext2D = {};
365CanvasRenderingContext2D.prototype.addHitRegion = function() {};
366CanvasRenderingContext2D.prototype.arc = function() {};
367CanvasRenderingContext2D.prototype.arcTo = function() {};
368CanvasRenderingContext2D.prototype.beginPath = function() {};
369CanvasRenderingContext2D.prototype.bezierCurveTo = function() {};
370CanvasRenderingContext2D.prototype.clearHitRegions = function() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500371CanvasRenderingContext2D.prototype.clearRect = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500372CanvasRenderingContext2D.prototype.closePath = function() {};
373CanvasRenderingContext2D.prototype.drawFocusIfNeeded = function() {};
374CanvasRenderingContext2D.prototype.ellipse = function() {};
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500375CanvasRenderingContext2D.prototype.fill = function() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500376CanvasRenderingContext2D.prototype.fillRect = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500377CanvasRenderingContext2D.prototype.fillText = function() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500378CanvasRenderingContext2D.prototype.getLineDash = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500379CanvasRenderingContext2D.prototype.lineTo = function() {};
380CanvasRenderingContext2D.prototype.measureText = function() {};
381CanvasRenderingContext2D.prototype.moveTo = function() {};
382CanvasRenderingContext2D.prototype.quadraticCurveTo = function() {};
383CanvasRenderingContext2D.prototype.rect = function() {};
384CanvasRenderingContext2D.prototype.removeHitRegion = function() {};
385CanvasRenderingContext2D.prototype.resetTransform = function() {};
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500386CanvasRenderingContext2D.prototype.restore = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500387CanvasRenderingContext2D.prototype.rotate = function() {};
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500388CanvasRenderingContext2D.prototype.save = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500389CanvasRenderingContext2D.prototype.scale = function() {};
390CanvasRenderingContext2D.prototype.scrollPathIntoView = function() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500391CanvasRenderingContext2D.prototype.setLineDash = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500392CanvasRenderingContext2D.prototype.setTransform = function() {};
393CanvasRenderingContext2D.prototype.stroke = function() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500394CanvasRenderingContext2D.prototype.strokeRect = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500395CanvasRenderingContext2D.prototype.strokeText = function() {};
396CanvasRenderingContext2D.prototype.transform = function() {};
397CanvasRenderingContext2D.prototype.translate = function() {};
398
Kevin Lubick217056c2018-09-20 17:39:31 -0400399// 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 -0500400function loadWebAssemblyModule() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500401
402var DOMMatrix = {};