blob: d239325e3c64390904de5a616fbd4fc2720bfb70 [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 Lubick134be1d2018-10-30 15:05:04 -040043 getSkDataBytes: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -050044 getColorComponents: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040045 initFonts: function() {},
46 setCurrentContext: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040047
48 // private API (i.e. things declared in the bindings that we use
49 // in the pre-js file)
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040050 _MakeImageShader: function() {},
51 _MakeLinearGradientShader: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040052 _MakeNimaActor: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040053 _MakeRadialGradientShader: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040054 _MakeSkDashPathEffect: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -040055 _MakeSkVertices: function() {},
Kevin Lubick134be1d2018-10-30 15:05:04 -040056 _getRasterN32PremulSurface: function() {},
57 _getWebGLSurface: function() {},
Kevin Lubick217056c2018-09-20 17:39:31 -040058
Kevin Lubick1a05fce2018-11-20 12:51:16 -050059 // The testing object is meant to expose internal functions
60 // for more fine-grained testing, e.g. parseColor
61 _testing: {},
62
Kevin Lubick217056c2018-09-20 17:39:31 -040063 // Objects and properties on CanvasKit
64
Kevin Lubick134be1d2018-10-30 15:05:04 -040065 NimaActor: {
66 // public API (from C++ bindings)
67 duration: function() {},
68 getAnimationNames: function() {},
69 render: function() {},
70 seek: function() {},
71 setAnimationByIndex: function() {},
72 setAnimationByName: function() {},
73
74 // private API
75 },
76
Kevin Lubick006a6f32018-10-19 14:34:34 -040077 SkCanvas: {
78 // public API (from C++ bindings)
79 clear: function() {},
80 drawPaint: function() {},
81 drawPath: function() {},
82 drawText: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -050083 drawShadow: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -040084 flush: function() {},
85 rotate: function() {},
86 save: function() {},
87 scale: function() {},
88 setMatrix: function() {},
89 skew: function() {},
90 translate: function() {},
91
92 // private API
93 delete: function() {},
94 },
95
96 SkImage: {
Alexander Khovansky3e119332018-11-15 02:01:19 +030097 // private API
98 _encodeToData: function() {},
99 _encodeToDataWithFormat: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400100 },
101
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500102 SkMatrix: {
Kevin Lubickb9db3902018-11-26 11:47:54 -0500103 identity: function() {},
104 mapPoints: function() {},
105 multiply: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500106 rotated: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500107 scaled: function() {},
108 skewed: function() {},
109 translated: function() {},
110 },
111
112 SkPaint: {
113 // public API (from C++ bindings)
114 /** @return {CanvasKit.SkPaint} */
115 copy: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500116 getColor: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500117 getStrokeCap: function() {},
118 getStrokeJoin: function() {},
119 getStrokeMiter: function() {},
120 getStrokeWidth: function() {},
121 getTextSize: function() {},
122 measureText: function() {},
123 setAntiAlias: function() {},
124 setColor: function() {},
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500125 setMaskFilter: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500126 setPathEffect: function() {},
127 setShader: function() {},
128 setStrokeCap: function() {},
129 setStrokeJoin: function() {},
130 setStrokeMiter: function() {},
131 setStrokeWidth: function() {},
132 setStyle: function() {},
133 setTextSize: function() {},
134
135 //private API
136 delete: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500137 },
138
Kevin Lubick006a6f32018-10-19 14:34:34 -0400139 SkPath: {
140 // public API (from C++ bindings)
Kevin Lubickb9db3902018-11-26 11:47:54 -0500141 computeTightBounds: function() {},
142 /** @return {CanvasKit.SkPath} */
143 copy: function() {},
144 countPoints: function() {},
145 equals: function() {},
146 getBounds: function() {},
147 getFillType: function() {},
148 getPoint: function() {},
149 setFillType: function() {},
150 toSVGString: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400151
152 // private API
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500153 _addArc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400154 _addPath: function() {},
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500155 _addRect: function() {},
Alexander Khovansky3e119332018-11-15 02:01:19 +0300156 _arc: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400157 _arcTo: function() {},
158 _close: function() {},
159 _conicTo: function() {},
160 _cubicTo: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400161 _dash: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400162 _lineTo: function() {},
163 _moveTo: function() {},
164 _op: function() {},
165 _quadTo: function() {},
166 _rect: function() {},
167 _simplify: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400168 _stroke: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400169 _transform: function() {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400170 _trim: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400171 delete: function() {},
Kevin Lubickb9db3902018-11-26 11:47:54 -0500172 dump: function() {},
173 dumpHex: function() {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400174 },
175
176 SkRect: {
177 fLeft: {},
178 fTop: {},
179 fRight: {},
180 fBottom: {},
181 },
182
183 SkSurface: {
184 // public API (from C++ bindings)
185 /** @return {CanvasKit.SkCanvas} */
186 getCanvas: function() {},
187 /** @return {CanvasKit.SkImage} */
188 makeImageSnapshot: function() {},
189
190 // private API
191 _flush: function() {},
192 _getRasterN32PremulSurface: function() {},
193 _readPixels: function() {},
194 delete: function() {},
195 },
196
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400197 SkVertices: {
198 // public API (from C++ bindings)
199 /** @return {CanvasKit.SkVertices} */
200 applyBones: function() {},
201
202 // private API
203 /** @return {CanvasKit.SkVertices} */
204 _applyBones: function() {},
205 },
206
Kevin Lubick006a6f32018-10-19 14:34:34 -0400207 // Constants and Enums
208 gpu: {},
209 skottie: {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400210
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500211 TRANSPARENT: {},
212 RED: {},
213 BLUE: {},
214 YELLOW: {},
215 CYAN: {},
216 BLACK: {},
217
218 BlendMode: {
219 Clear: {},
220 Src: {},
221 Dst: {},
222 SrcOver: {},
223 DstOver: {},
224 SrcIn: {},
225 DstIn: {},
226 SrcOut: {},
227 DstOut: {},
228 SrcATop: {},
229 DstATop: {},
230 Xor: {},
231 Plus: {},
232 Modulate: {},
233 Screen: {},
234 Overlay: {},
235 Darken: {},
236 Lighten: {},
237 ColorDodge: {},
238 ColorBurn: {},
239 HardLight: {},
240 SoftLight: {},
241 Difference: {},
242 Exclusion: {},
243 Multiply: {},
244 Hue: {},
245 Saturation: {},
246 Color: {},
247 Luminosity: {},
248 },
249
250 BlurStyle: {
251 Normal: {},
252 Solid: {},
253 Outer: {},
254 Inner: {},
255 },
256
Kevin Lubick006a6f32018-10-19 14:34:34 -0400257 FillType: {
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500258 Winding: {},
259 EvenOdd: {},
260 InverseWinding: {},
261 InverseEvenOdd: {},
Kevin Lubick006a6f32018-10-19 14:34:34 -0400262 },
263
Alexander Khovansky3e119332018-11-15 02:01:19 +0300264 ImageFormat: {
265 PNG: {},
266 JPEG: {},
267 },
268
Kevin Lubickb9db3902018-11-26 11:47:54 -0500269 PaintStyle: {
270 Fill: {},
271 Stroke: {},
272 StrokeAndFill: {},
273 },
274
275 StrokeCap: {
276 Butt: {},
277 Round: {},
278 Square: {},
279 },
280
281 StrokeJoin: {
282 Miter: {},
283 Round: {},
284 Bevel: {},
285 },
286
Kevin Lubick006a6f32018-10-19 14:34:34 -0400287 // Things Enscriptem adds for us
288
Kevin Lubick53965c92018-10-11 08:51:55 -0400289 /** Represents the heap of the WASM code
290 * @type {ArrayBuffer}
291 */
292 buffer: {},
293 /**
294 * @type {Float32Array}
295 */
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400296 HEAPF32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400297 /**
298 * @type {Uint8Array}
299 */
300 HEAPU8: {},
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400301 /**
302 * @type {Uint16Array}
303 */
304 HEAPU16: {},
305 /**
306 * @type {Int32Array}
307 */
308 HEAP32: {},
Kevin Lubick53965c92018-10-11 08:51:55 -0400309
Kevin Lubick006a6f32018-10-19 14:34:34 -0400310 _malloc: function() {},
311 _free: function() {},
312 onRuntimeInitialized: function() {},
313};
Kevin Lubick217056c2018-09-20 17:39:31 -0400314
Kevin Lubick006a6f32018-10-19 14:34:34 -0400315// Public API things that are newly declared in the JS should go here.
316// It's not enough to declare them above, because closure can still erase them
317// unless they go on the prototype.
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500318CanvasKit.SkPath.prototype.addArc = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400319CanvasKit.SkPath.prototype.addPath = function() {};
Kevin Lubick1a05fce2018-11-20 12:51:16 -0500320CanvasKit.SkPath.prototype.addRect = function() {};
Alexander Khovansky3e119332018-11-15 02:01:19 +0300321CanvasKit.SkPath.prototype.arc = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400322CanvasKit.SkPath.prototype.arcTo = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400323CanvasKit.SkPath.prototype.close = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400324CanvasKit.SkPath.prototype.conicTo = function() {};
325CanvasKit.SkPath.prototype.cubicTo = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400326CanvasKit.SkPath.prototype.dash = function() {};
Kevin Lubick006a6f32018-10-19 14:34:34 -0400327CanvasKit.SkPath.prototype.lineTo = function() {};
328CanvasKit.SkPath.prototype.moveTo = function() {};
329CanvasKit.SkPath.prototype.op = function() {};
330CanvasKit.SkPath.prototype.quadTo = function() {};
331CanvasKit.SkPath.prototype.rect = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400332CanvasKit.SkPath.prototype.simplify = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400333CanvasKit.SkPath.prototype.stroke = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400334CanvasKit.SkPath.prototype.transform = function() {};
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400335CanvasKit.SkPath.prototype.trim = function() {};
Kevin Lubick217056c2018-09-20 17:39:31 -0400336
Kevin Lubick53965c92018-10-11 08:51:55 -0400337CanvasKit.SkSurface.prototype.flush = function() {};
Kevin Lubick5b90b842018-10-17 07:57:18 -0400338CanvasKit.SkSurface.prototype.dispose = function() {};
Kevin Lubick53965c92018-10-11 08:51:55 -0400339
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400340CanvasKit.SkVertices.prototype.applyBones = function() {};
341
Alexander Khovansky3e119332018-11-15 02:01:19 +0300342CanvasKit.SkImage.prototype.encodeToData = function() {};
343
Kevin Lubickb5ae3b52018-11-03 07:51:19 -0400344// Define StrokeOpts object
345var StrokeOpts = {};
346StrokeOpts.prototype.width;
347StrokeOpts.prototype.miter_limit;
348StrokeOpts.prototype.cap;
349StrokeOpts.prototype.join;
350
Kevin Lubickb9db3902018-11-26 11:47:54 -0500351var HTMLCanvas = {};
352HTMLCanvas.prototype.getContext = function() {};
353HTMLCanvas.prototype.toDataURL = function() {};
354HTMLCanvas.prototype.dispose = function() {};
355
356var CanvasRenderingContext2D = {};
357CanvasRenderingContext2D.prototype.addHitRegion = function() {};
358CanvasRenderingContext2D.prototype.arc = function() {};
359CanvasRenderingContext2D.prototype.arcTo = function() {};
360CanvasRenderingContext2D.prototype.beginPath = function() {};
361CanvasRenderingContext2D.prototype.bezierCurveTo = function() {};
362CanvasRenderingContext2D.prototype.clearHitRegions = function() {};
363CanvasRenderingContext2D.prototype.closePath = function() {};
364CanvasRenderingContext2D.prototype.drawFocusIfNeeded = function() {};
365CanvasRenderingContext2D.prototype.ellipse = function() {};
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500366CanvasRenderingContext2D.prototype.fill = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500367CanvasRenderingContext2D.prototype.fillText = function() {};
368CanvasRenderingContext2D.prototype.lineTo = function() {};
369CanvasRenderingContext2D.prototype.measureText = function() {};
370CanvasRenderingContext2D.prototype.moveTo = function() {};
371CanvasRenderingContext2D.prototype.quadraticCurveTo = function() {};
372CanvasRenderingContext2D.prototype.rect = function() {};
373CanvasRenderingContext2D.prototype.removeHitRegion = function() {};
374CanvasRenderingContext2D.prototype.resetTransform = function() {};
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500375CanvasRenderingContext2D.prototype.restore = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500376CanvasRenderingContext2D.prototype.rotate = function() {};
Kevin Lubick61ef7b22018-11-27 13:26:59 -0500377CanvasRenderingContext2D.prototype.save = function() {};
Kevin Lubickb9db3902018-11-26 11:47:54 -0500378CanvasRenderingContext2D.prototype.scale = function() {};
379CanvasRenderingContext2D.prototype.scrollPathIntoView = function() {};
380CanvasRenderingContext2D.prototype.setTransform = function() {};
381CanvasRenderingContext2D.prototype.stroke = function() {};
382CanvasRenderingContext2D.prototype.strokeText = function() {};
383CanvasRenderingContext2D.prototype.transform = function() {};
384CanvasRenderingContext2D.prototype.translate = function() {};
385
386
Kevin Lubick217056c2018-09-20 17:39:31 -0400387// 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 -0500388function loadWebAssemblyModule() {};