blob: 6f2527b0b8b69c7398f2707df5b7c86ee15559c1 [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() {},
Kevin Lubickeb2f6b02018-11-29 15:07:02 -050034 /** @return {LinearCanvasGradient} */
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040035 MakeLinearGradientShader: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040036 MakeNimaActor: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -050037 MakeRadialGradientShader: function() {},
38 MakeSWCanvasSurface: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040039 MakeSkDashPathEffect: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040040 MakeSkVertices: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040041 MakeSurface: function() {},
Kevin Lubickeb2f6b02018-11-29 15:07:02 -050042 /** @return {RadialCanvasGradient} */
43 MakeTwoPointConicalGradientShader: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -050044 MakeWebGLCanvasSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040045 currentContext: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -050046 getColorComponents: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -050047 getSkDataBytes: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040048 initFonts: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -050049 multiplyByAlpha: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040050 setCurrentContext: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040051
52 // private API (i.e. things declared in the bindings that we use
53 // in the pre-js file)
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040054 _MakeImageShader: function() {},
55 _MakeLinearGradientShader: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040056 _MakeNimaActor: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040057 _MakeRadialGradientShader: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040058 _MakeSkDashPathEffect: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040059 _MakeSkVertices: function() {},
Kevin Lubickeb2f6b02018-11-29 15:07:02 -050060 _MakeTwoPointConicalGradientShader: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040061 _getRasterN32PremulSurface: function() {},
62 _getWebGLSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040063
Kevin Lubick1a05fce2018-11-20 12:51:16 -050064 // The testing object is meant to expose internal functions
65 // for more fine-grained testing, e.g. parseColor
66 _testing: {},
67
Kevin Lubick217056c2018-09-20 17:39:31 -040068 // Objects and properties on CanvasKit
69
Kevin Lubick134be1d2018-10-30 15:05:04 -040070 NimaActor: {
71 // public API (from C++ bindings)
72 duration: function() {},
73 getAnimationNames: function() {},
74 render: function() {},
75 seek: function() {},
76 setAnimationByIndex: function() {},
77 setAnimationByName: function() {},
78
79 // private API
80 },
81
Kevin Lubick006a6f32018-10-19 14:34:34 -040082 SkCanvas: {
83 // public API (from C++ bindings)
84 clear: function() {},
Kevin Lubickeb2f6b02018-11-29 15:07:02 -050085 clipPath: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040086 drawPaint: function() {},
87 drawPath: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -050088 drawRect: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -050089 drawShadow: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -050090 drawText: function() {},
91 drawVertices: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040092 flush: function() {},
Kevin Lubickeb2f6b02018-11-29 15:07:02 -050093 restore: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040094 rotate: function() {},
95 save: function() {},
96 scale: function() {},
97 setMatrix: function() {},
98 skew: function() {},
99 translate: function() {},
100
101 // private API
102 delete: function() {},
103 },
104
105 SkImage: {
Alexander Khovansky3e119332018-11-15 02:01:19 +0300106 // private API
107 _encodeToData: function() {},
108 _encodeToDataWithFormat: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400109 },
110
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500111 SkMatrix: {
Kevin Lubickb9db3902018-11-26 11:47:54 -0500112 identity: function() {},
113 mapPoints: function() {},
114 multiply: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500115 rotated: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500116 scaled: function() {},
117 skewed: function() {},
118 translated: function() {},
119 },
120
121 SkPaint: {
122 // public API (from C++ bindings)
123 /** @return {CanvasKit.SkPaint} */
124 copy: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -0500125 getBlendMode: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500126 getColor: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500127 getStrokeCap: function() {},
128 getStrokeJoin: function() {},
129 getStrokeMiter: function() {},
130 getStrokeWidth: function() {},
131 getTextSize: function() {},
132 measureText: function() {},
133 setAntiAlias: function() {},
Kevin Lubick12c0e502018-11-28 12:51:56 -0500134 setBlendMode: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500135 setColor: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500136 setMaskFilter: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500137 setPathEffect: function() {},
138 setShader: function() {},
139 setStrokeCap: function() {},
140 setStrokeJoin: function() {},
141 setStrokeMiter: function() {},
142 setStrokeWidth: function() {},
143 setStyle: function() {},
144 setTextSize: function() {},
145
146 //private API
147 delete: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500148 },
149
Kevin Lubick006a6f32018-10-19 14:34:34 -0400150 SkPath: {
151 // public API (from C++ bindings)
Kevin Lubickb9db3902018-11-26 11:47:54 -0500152 computeTightBounds: function() {},
153 /** @return {CanvasKit.SkPath} */
154 copy: function() {},
155 countPoints: function() {},
156 equals: function() {},
157 getBounds: function() {},
158 getFillType: function() {},
159 getPoint: function() {},
160 setFillType: function() {},
161 toSVGString: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400162
163 // private API
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500164 _addArc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400165 _addPath: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500166 _addRect: function() {},
Alexander Khovansky3e119332018-11-15 02:01:19 +0300167 _arc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400168 _arcTo: function() {},
169 _close: function() {},
170 _conicTo: function() {},
171 _cubicTo: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400172 _dash: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400173 _lineTo: function() {},
174 _moveTo: function() {},
175 _op: function() {},
176 _quadTo: function() {},
177 _rect: function() {},
178 _simplify: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400179 _stroke: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400180 _transform: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400181 _trim: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400182 delete: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500183 dump: function() {},
184 dumpHex: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400185 },
186
187 SkRect: {
188 fLeft: {},
189 fTop: {},
190 fRight: {},
191 fBottom: {},
192 },
193
194 SkSurface: {
195 // public API (from C++ bindings)
196 /** @return {CanvasKit.SkCanvas} */
197 getCanvas: function() {},
198 /** @return {CanvasKit.SkImage} */
199 makeImageSnapshot: function() {},
200
201 // private API
202 _flush: function() {},
203 _getRasterN32PremulSurface: function() {},
204 _readPixels: function() {},
205 delete: function() {},
206 },
207
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400208 SkVertices: {
209 // public API (from C++ bindings)
Kevin Lubick12c0e502018-11-28 12:51:56 -0500210 bounds: function() {},
211 mode: function() {},
212 uniqueID: function() {},
213 vertexCount: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400214
215 // private API
216 /** @return {CanvasKit.SkVertices} */
217 _applyBones: function() {},
218 },
219
Kevin Lubick006a6f32018-10-19 14:34:34 -0400220 // Constants and Enums
221 gpu: {},
222 skottie: {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400223
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500224 TRANSPARENT: {},
225 RED: {},
226 BLUE: {},
227 YELLOW: {},
228 CYAN: {},
229 BLACK: {},
230
231 BlendMode: {
232 Clear: {},
233 Src: {},
234 Dst: {},
235 SrcOver: {},
236 DstOver: {},
237 SrcIn: {},
238 DstIn: {},
239 SrcOut: {},
240 DstOut: {},
241 SrcATop: {},
242 DstATop: {},
243 Xor: {},
244 Plus: {},
245 Modulate: {},
246 Screen: {},
247 Overlay: {},
248 Darken: {},
249 Lighten: {},
250 ColorDodge: {},
251 ColorBurn: {},
252 HardLight: {},
253 SoftLight: {},
254 Difference: {},
255 Exclusion: {},
256 Multiply: {},
257 Hue: {},
258 Saturation: {},
259 Color: {},
260 Luminosity: {},
261 },
262
263 BlurStyle: {
264 Normal: {},
265 Solid: {},
266 Outer: {},
267 Inner: {},
268 },
269
Kevin Lubickeb2f6b02018-11-29 15:07:02 -0500270 ClipOp: {
271 Difference: {},
272 Intersect: {},
273 },
274
Kevin Lubick006a6f32018-10-19 14:34:34 -0400275 FillType: {
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500276 Winding: {},
277 EvenOdd: {},
278 InverseWinding: {},
279 InverseEvenOdd: {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400280 },
281
Alexander Khovansky3e119332018-11-15 02:01:19 +0300282 ImageFormat: {
283 PNG: {},
284 JPEG: {},
285 },
286
Kevin Lubickb9db3902018-11-26 11:47:54 -0500287 PaintStyle: {
288 Fill: {},
289 Stroke: {},
290 StrokeAndFill: {},
291 },
292
Kevin Lubickeb2f6b02018-11-29 15:07:02 -0500293 PathOp: {
294 Difference: {},
295 Intersect: {},
296 Union: {},
297 XOR: {},
298 ReverseDifference: {},
299 },
300
Kevin Lubickb9db3902018-11-26 11:47:54 -0500301 StrokeCap: {
302 Butt: {},
303 Round: {},
304 Square: {},
305 },
306
307 StrokeJoin: {
308 Miter: {},
309 Round: {},
310 Bevel: {},
311 },
312
Kevin Lubickeb2f6b02018-11-29 15:07:02 -0500313 TileMode: {
314 Clamp: {},
315 Repeat: {},
316 Mirror: {},
317 },
318
319 VertexMode: {
320 Triangles: {},
321 TrianglesStrip: {},
322 TriangleFan: {},
323 },
324
Kevin Lubick006a6f32018-10-19 14:34:34 -0400325 // Things Enscriptem adds for us
326
Kevin Lubick53965c92018-10-11 08:51:55 -0400327 /** Represents the heap of the WASM code
328 * @type {ArrayBuffer}
329 */
330 buffer: {},
331 /**
332 * @type {Float32Array}
333 */
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400334 HEAPF32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400335 /**
336 * @type {Uint8Array}
337 */
338 HEAPU8: {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400339 /**
340 * @type {Uint16Array}
341 */
342 HEAPU16: {},
343 /**
344 * @type {Int32Array}
345 */
346 HEAP32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400347
Kevin Lubick006a6f32018-10-19 14:34:34 -0400348 _malloc: function() {},
349 _free: function() {},
350 onRuntimeInitialized: function() {},
351};
Kevin Lubick217056c2018-09-20 17:39:31 -0400352
Kevin Lubick006a6f32018-10-19 14:34:34 -0400353// Public API things that are newly declared in the JS should go here.
354// It's not enough to declare them above, because closure can still erase them
355// unless they go on the prototype.
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500356CanvasKit.SkPath.prototype.addArc = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400357CanvasKit.SkPath.prototype.addPath = function() {};
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500358CanvasKit.SkPath.prototype.addRect = function() {};
Alexander Khovansky3e119332018-11-15 02:01:19 +0300359CanvasKit.SkPath.prototype.arc = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400360CanvasKit.SkPath.prototype.arcTo = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400361CanvasKit.SkPath.prototype.close = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400362CanvasKit.SkPath.prototype.conicTo = function() {};
363CanvasKit.SkPath.prototype.cubicTo = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400364CanvasKit.SkPath.prototype.dash = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400365CanvasKit.SkPath.prototype.lineTo = function() {};
366CanvasKit.SkPath.prototype.moveTo = function() {};
367CanvasKit.SkPath.prototype.op = function() {};
368CanvasKit.SkPath.prototype.quadTo = function() {};
369CanvasKit.SkPath.prototype.rect = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400370CanvasKit.SkPath.prototype.simplify = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400371CanvasKit.SkPath.prototype.stroke = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400372CanvasKit.SkPath.prototype.transform = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400373CanvasKit.SkPath.prototype.trim = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400374
Kevin Lubick53965c92018-10-11 08:51:55 -0400375CanvasKit.SkSurface.prototype.flush = function() {};
Kevin Lubick5b90b842018-10-17 07:57:18 -0400376CanvasKit.SkSurface.prototype.dispose = function() {};
Kevin Lubick53965c92018-10-11 08:51:55 -0400377
Kevin Lubick12c0e502018-11-28 12:51:56 -0500378/** @return {CanvasKit.SkVertices} */
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400379CanvasKit.SkVertices.prototype.applyBones = function() {};
380
Alexander Khovansky3e119332018-11-15 02:01:19 +0300381CanvasKit.SkImage.prototype.encodeToData = function() {};
382
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400383// Define StrokeOpts object
384var StrokeOpts = {};
385StrokeOpts.prototype.width;
386StrokeOpts.prototype.miter_limit;
387StrokeOpts.prototype.cap;
388StrokeOpts.prototype.join;
389
Kevin Lubickeb2f6b02018-11-29 15:07:02 -0500390// Define everything created in the canvas2d spec here
Kevin Lubickb9db3902018-11-26 11:47:54 -0500391var HTMLCanvas = {};
392HTMLCanvas.prototype.getContext = function() {};
393HTMLCanvas.prototype.toDataURL = function() {};
394HTMLCanvas.prototype.dispose = function() {};
395
396var CanvasRenderingContext2D = {};
397CanvasRenderingContext2D.prototype.addHitRegion = function() {};
398CanvasRenderingContext2D.prototype.arc = function() {};
399CanvasRenderingContext2D.prototype.arcTo = function() {};
400CanvasRenderingContext2D.prototype.beginPath = function() {};
401CanvasRenderingContext2D.prototype.bezierCurveTo = function() {};
402CanvasRenderingContext2D.prototype.clearHitRegions = function() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500403CanvasRenderingContext2D.prototype.clearRect = function() {};
Kevin Lubickeb2f6b02018-11-29 15:07:02 -0500404CanvasRenderingContext2D.prototype.clip = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500405CanvasRenderingContext2D.prototype.closePath = function() {};
Kevin Lubickeb2f6b02018-11-29 15:07:02 -0500406CanvasRenderingContext2D.prototype.createLinearGradient = function() {};
407CanvasRenderingContext2D.prototype.createRadialGradient = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500408CanvasRenderingContext2D.prototype.drawFocusIfNeeded = function() {};
409CanvasRenderingContext2D.prototype.ellipse = function() {};
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500410CanvasRenderingContext2D.prototype.fill = function() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500411CanvasRenderingContext2D.prototype.fillRect = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500412CanvasRenderingContext2D.prototype.fillText = function() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500413CanvasRenderingContext2D.prototype.getLineDash = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500414CanvasRenderingContext2D.prototype.lineTo = function() {};
415CanvasRenderingContext2D.prototype.measureText = function() {};
416CanvasRenderingContext2D.prototype.moveTo = function() {};
417CanvasRenderingContext2D.prototype.quadraticCurveTo = function() {};
418CanvasRenderingContext2D.prototype.rect = function() {};
419CanvasRenderingContext2D.prototype.removeHitRegion = function() {};
420CanvasRenderingContext2D.prototype.resetTransform = function() {};
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500421CanvasRenderingContext2D.prototype.restore = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500422CanvasRenderingContext2D.prototype.rotate = function() {};
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500423CanvasRenderingContext2D.prototype.save = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500424CanvasRenderingContext2D.prototype.scale = function() {};
425CanvasRenderingContext2D.prototype.scrollPathIntoView = function() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500426CanvasRenderingContext2D.prototype.setLineDash = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500427CanvasRenderingContext2D.prototype.setTransform = function() {};
428CanvasRenderingContext2D.prototype.stroke = function() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500429CanvasRenderingContext2D.prototype.strokeRect = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500430CanvasRenderingContext2D.prototype.strokeText = function() {};
431CanvasRenderingContext2D.prototype.transform = function() {};
432CanvasRenderingContext2D.prototype.translate = function() {};
433
Kevin Lubickeb2f6b02018-11-29 15:07:02 -0500434var LinearCanvasGradient = {};
435LinearCanvasGradient.prototype.addColorStop = function() {};
436var RadialCanvasGradient = {};
437RadialCanvasGradient.prototype.addColorStop = function() {};
438
Kevin Lubick217056c2018-09-20 17:39:31 -0400439// 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 -0500440function loadWebAssemblyModule() {};
Kevin Lubick12c0e502018-11-28 12:51:56 -0500441
442var DOMMatrix = {};