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 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) 27 Color: function() {}, 28 /** @return {CanvasKit.SkRect} */ 29 LTRBRect: function() {}, 30 /** @return {CanvasKit.SkRect} */ 31 XYWHRect: function() {}, 32 /** @return {ImageData} */ 33 ImageData: function() {}, 34 MakeBlurMaskFilter: function() {}, 35 MakeCanvas: function() {}, 36 MakeCanvasSurface: function() {}, 37 MakeImageShader: function() {}, 38 /** @return {CanvasKit.SkImage} */ 39 MakeImageFromEncoded: function() {}, 40 /** @return {LinearCanvasGradient} */ 41 MakeLinearGradientShader: function() {}, 42 MakePathFromCmds: function() {}, 43 MakePathFromOp: function() {}, 44 MakePathFromSVGString: function() {}, 45 MakeRadialGradientShader: function() {}, 46 MakeSWCanvasSurface: function() {}, 47 MakeSkDashPathEffect: function() {}, 48 MakeSkVertices: function() {}, 49 MakeSurface: function() {}, 50 /** @return {RadialCanvasGradient} */ 51 MakeTwoPointConicalGradientShader: function() {}, 52 MakeWebGLCanvasSurface: function() {}, 53 currentContext: function() {}, 54 getColorComponents: function() {}, 55 getSkDataBytes: function() {}, 56 multiplyByAlpha: function() {}, 57 setCurrentContext: function() {}, 58 59 // private API (i.e. things declared in the bindings that we use 60 // in the pre-js file) 61 _MakeImage: function() {}, 62 _MakeImageShader: function() {}, 63 _MakeLinearGradientShader: function() {}, 64 _MakePathFromCmds: function() {}, 65 _MakeRadialGradientShader: function() {}, 66 _MakeSkDashPathEffect: function() {}, 67 _MakeSkVertices: function() {}, 68 _MakeTwoPointConicalGradientShader: function() {}, 69 _decodeImage: function() {}, 70 _getRasterDirectSurface: function() {}, 71 _getRasterN32PremulSurface: function() {}, 72 _getWebGLSurface: function() {}, 73 74 // The testing object is meant to expose internal functions 75 // for more fine-grained testing, e.g. parseColor 76 _testing: {}, 77 78 // Objects and properties on CanvasKit 79 80 SkCanvas: { 81 // public API (from C++ bindings) 82 clear: function() {}, 83 clipPath: function() {}, 84 clipRect: function() {}, 85 concat: function() {}, 86 drawArc: function() {}, 87 drawImage: function() {}, 88 drawImageRect: function() {}, 89 drawLine: function() {}, 90 drawOval: function() {}, 91 drawPaint: function() {}, 92 drawPath: function() {}, 93 drawRect: function() {}, 94 drawRoundRect: function() {}, 95 drawShadow: function() {}, 96 drawText: function() {}, 97 drawTextBlob: function() {}, 98 drawVertices: function() {}, 99 flush: function() {}, 100 getTotalMatrix: function() {}, 101 restore: function() {}, 102 rotate: function() {}, 103 save: function() {}, 104 scale: function() {}, 105 skew: function() {}, 106 translate: function() {}, 107 108 // private API 109 _drawSimpleText: function() {}, 110 _readPixels: function() {}, 111 _writePixels: function() {}, 112 delete: function() {}, 113 }, 114 115 SkFont: { 116 // public API (from C++ bindings) 117 getScaleX: function() {}, 118 getSize: function() {}, 119 getSkewX: function() {}, 120 getTypeface: function() {}, 121 measureText: function() {}, 122 setScaleX: function() {}, 123 setSize: function() {}, 124 setSkewX: function() {}, 125 setTypeface: function() {}, 126 }, 127 128 SkFontMgr: { 129 // public API (from C++ bindings) 130 RefDefault: function() {}, 131 countFamilies: function() {}, 132 133 // private API 134 _makeTypefaceFromData: function() {}, 135 }, 136 137 SkImage: { 138 // public API (from C++ bindings) 139 height: function() {}, 140 width: function() {}, 141 // private API 142 _encodeToData: function() {}, 143 _encodeToDataWithFormat: function() {}, 144 }, 145 146 SkMatrix: { 147 identity: function() {}, 148 mapPoints: function() {}, 149 multiply: function() {}, 150 rotated: function() {}, 151 scaled: function() {}, 152 skewed: function() {}, 153 translated: function() {}, 154 }, 155 156 SkPaint: { 157 // public API (from C++ bindings) 158 /** @return {CanvasKit.SkPaint} */ 159 copy: function() {}, 160 getBlendMode: function() {}, 161 getColor: function() {}, 162 getFilterQuality: function() {}, 163 getStrokeCap: function() {}, 164 getStrokeJoin: function() {}, 165 getStrokeMiter: function() {}, 166 getStrokeWidth: function() {}, 167 setAntiAlias: function() {}, 168 setBlendMode: function() {}, 169 setColor: function() {}, 170 setFilterQuality: function() {}, 171 setMaskFilter: function() {}, 172 setPathEffect: function() {}, 173 setShader: function() {}, 174 setStrokeCap: function() {}, 175 setStrokeJoin: function() {}, 176 setStrokeMiter: function() {}, 177 setStrokeWidth: function() {}, 178 setStyle: function() {}, 179 180 //private API 181 delete: function() {}, 182 }, 183 184 SkPath: { 185 // public API (from C++ bindings) 186 computeTightBounds: function() {}, 187 contains: function() {}, 188 /** @return {CanvasKit.SkPath} */ 189 copy: function() {}, 190 countPoints: function() {}, 191 equals: function() {}, 192 getBounds: function() {}, 193 getFillType: function() {}, 194 getPoint: function() {}, 195 isEmpty: function() {}, 196 isVolatile: function() {}, 197 reset: function() {}, 198 rewind: function() {}, 199 setFillType: function() {}, 200 setIsVolatile: function() {}, 201 toSVGString: function() {}, 202 203 // private API 204 _addArc: function() {}, 205 _addPath: function() {}, 206 _addRect: function() {}, 207 _addRoundRect: function() {}, 208 _arc: function() {}, 209 _arcTo: function() {}, 210 _close: function() {}, 211 _conicTo: function() {}, 212 _cubicTo: function() {}, 213 _dash: function() {}, 214 _lineTo: function() {}, 215 _moveTo: function() {}, 216 _op: function() {}, 217 _quadTo: function() {}, 218 _rect: function() {}, 219 _simplify: function() {}, 220 _stroke: function() {}, 221 _transform: function() {}, 222 _trim: function() {}, 223 delete: function() {}, 224 dump: function() {}, 225 dumpHex: function() {}, 226 }, 227 228 SkRect: { 229 fLeft: {}, 230 fTop: {}, 231 fRight: {}, 232 fBottom: {}, 233 }, 234 235 SkSurface: { 236 // public API (from C++ bindings) 237 /** @return {CanvasKit.SkCanvas} */ 238 getCanvas: function() {}, 239 /** @return {CanvasKit.SkImage} */ 240 makeImageSnapshot: function() {}, 241 242 // private API 243 _flush: function() {}, 244 _getRasterN32PremulSurface: function() {}, 245 delete: function() {}, 246 }, 247 248 SkTextBlob: { 249 MakeFromText: function() {}, 250 _MakeFromText: function() {}, 251 }, 252 253 SkVertices: { 254 // public API (from C++ bindings) 255 bounds: function() {}, 256 mode: function() {}, 257 uniqueID: function() {}, 258 vertexCount: function() {}, 259 260 // private API 261 /** @return {CanvasKit.SkVertices} */ 262 _applyBones: function() {}, 263 }, 264 265 // Constants and Enums 266 gpu: {}, 267 skottie: {}, 268 269 TRANSPARENT: {}, 270 RED: {}, 271 BLUE: {}, 272 YELLOW: {}, 273 CYAN: {}, 274 BLACK: {}, 275 WHITE: {}, 276 277 MOVE_VERB: {}, 278 LINE_VERB: {}, 279 QUAD_VERB: {}, 280 CONIC_VERB: {}, 281 CUBIC_VERB: {}, 282 CLOSE_VERB: {}, 283 284 AlphaType: { 285 Opaque: {}, 286 Premul: {}, 287 Unpremul: {}, 288 }, 289 290 BlendMode: { 291 Clear: {}, 292 Src: {}, 293 Dst: {}, 294 SrcOver: {}, 295 DstOver: {}, 296 SrcIn: {}, 297 DstIn: {}, 298 SrcOut: {}, 299 DstOut: {}, 300 SrcATop: {}, 301 DstATop: {}, 302 Xor: {}, 303 Plus: {}, 304 Modulate: {}, 305 Screen: {}, 306 Overlay: {}, 307 Darken: {}, 308 Lighten: {}, 309 ColorDodge: {}, 310 ColorBurn: {}, 311 HardLight: {}, 312 SoftLight: {}, 313 Difference: {}, 314 Exclusion: {}, 315 Multiply: {}, 316 Hue: {}, 317 Saturation: {}, 318 Color: {}, 319 Luminosity: {}, 320 }, 321 322 BlurStyle: { 323 Normal: {}, 324 Solid: {}, 325 Outer: {}, 326 Inner: {}, 327 }, 328 329 ClipOp: { 330 Difference: {}, 331 Intersect: {}, 332 }, 333 334 ColorType: { 335 Alpha_8: {}, 336 RGB_565: {}, 337 ARGB_4444: {}, 338 RGBA_8888: {}, 339 RGB_888x: {}, 340 BGRA_8888: {}, 341 RGBA_1010102: {}, 342 RGB_101010x: {}, 343 Gray_8: {}, 344 RGBA_F16: {}, 345 RGBA_F32: {}, 346 }, 347 348 FillType: { 349 Winding: {}, 350 EvenOdd: {}, 351 InverseWinding: {}, 352 InverseEvenOdd: {}, 353 }, 354 355 FilterQuality: { 356 None: {}, 357 Low: {}, 358 Medium: {}, 359 High: {}, 360 }, 361 362 ImageFormat: { 363 PNG: {}, 364 JPEG: {}, 365 }, 366 367 PaintStyle: { 368 Fill: {}, 369 Stroke: {}, 370 StrokeAndFill: {}, 371 }, 372 373 PathOp: { 374 Difference: {}, 375 Intersect: {}, 376 Union: {}, 377 XOR: {}, 378 ReverseDifference: {}, 379 }, 380 381 StrokeCap: { 382 Butt: {}, 383 Round: {}, 384 Square: {}, 385 }, 386 387 StrokeJoin: { 388 Miter: {}, 389 Round: {}, 390 Bevel: {}, 391 }, 392 393 TextEncoding: { 394 UTF8: {}, 395 UTF16: {}, 396 UTF32: {}, 397 GlyphID: {}, 398 }, 399 400 TileMode: { 401 Clamp: {}, 402 Repeat: {}, 403 Mirror: {}, 404 Decal: {}, 405 }, 406 407 VertexMode: { 408 Triangles: {}, 409 TrianglesStrip: {}, 410 TriangleFan: {}, 411 }, 412 413 // Things Enscriptem adds for us 414 415 /** Represents the heap of the WASM code 416 * @type {ArrayBuffer} 417 */ 418 buffer: {}, 419 /** 420 * @type {Float32Array} 421 */ 422 HEAPF32: {}, 423 /** 424 * @type {Uint8Array} 425 */ 426 HEAPU8: {}, 427 /** 428 * @type {Uint16Array} 429 */ 430 HEAPU16: {}, 431 /** 432 * @type {Int32Array} 433 */ 434 HEAP32: {}, 435 436 _malloc: function() {}, 437 _free: function() {}, 438 onRuntimeInitialized: function() {}, 439}; 440 441// Public API things that are newly declared in the JS should go here. 442// It's not enough to declare them above, because closure can still erase them 443// unless they go on the prototype. 444CanvasKit.SkPath.prototype.addArc = function() {}; 445CanvasKit.SkPath.prototype.addPath = function() {}; 446CanvasKit.SkPath.prototype.addRect = function() {}; 447CanvasKit.SkPath.prototype.addRoundRect = function() {}; 448CanvasKit.SkPath.prototype.arc = function() {}; 449CanvasKit.SkPath.prototype.arcTo = function() {}; 450CanvasKit.SkPath.prototype.close = function() {}; 451CanvasKit.SkPath.prototype.conicTo = function() {}; 452CanvasKit.SkPath.prototype.cubicTo = function() {}; 453CanvasKit.SkPath.prototype.dash = function() {}; 454CanvasKit.SkPath.prototype.lineTo = function() {}; 455CanvasKit.SkPath.prototype.moveTo = function() {}; 456CanvasKit.SkPath.prototype.op = function() {}; 457CanvasKit.SkPath.prototype.quadTo = function() {}; 458CanvasKit.SkPath.prototype.rect = function() {}; 459CanvasKit.SkPath.prototype.simplify = function() {}; 460CanvasKit.SkPath.prototype.stroke = function() {}; 461CanvasKit.SkPath.prototype.transform = function() {}; 462CanvasKit.SkPath.prototype.trim = function() {}; 463 464CanvasKit.SkSurface.prototype.flush = function() {}; 465CanvasKit.SkSurface.prototype.dispose = function() {}; 466 467/** @return {CanvasKit.SkVertices} */ 468CanvasKit.SkVertices.prototype.applyBones = function() {}; 469 470CanvasKit.SkImage.prototype.encodeToData = function() {}; 471 472CanvasKit.SkCanvas.prototype.drawText = function() {}; 473/** @return {Uint8Array} */ 474CanvasKit.SkCanvas.prototype.readPixels = function() {}; 475CanvasKit.SkCanvas.prototype.writePixels = function() {}; 476 477CanvasKit.SkFontMgr.prototype.MakeTypefaceFromData = function() {}; 478 479// Define StrokeOpts object 480var StrokeOpts = {}; 481StrokeOpts.prototype.width; 482StrokeOpts.prototype.miter_limit; 483StrokeOpts.prototype.cap; 484StrokeOpts.prototype.join; 485StrokeOpts.prototype.precision; 486 487// Define everything created in the canvas2d spec here 488var HTMLCanvas = {}; 489HTMLCanvas.prototype.decodeImage = function() {}; 490HTMLCanvas.prototype.dispose = function() {}; 491HTMLCanvas.prototype.getContext = function() {}; 492HTMLCanvas.prototype.loadFont = function() {}; 493HTMLCanvas.prototype.makePath2D = function() {}; 494HTMLCanvas.prototype.toDataURL = function() {}; 495 496var CanvasRenderingContext2D = {}; 497CanvasRenderingContext2D.prototype.addHitRegion = function() {}; 498CanvasRenderingContext2D.prototype.arc = function() {}; 499CanvasRenderingContext2D.prototype.arcTo = function() {}; 500CanvasRenderingContext2D.prototype.beginPath = function() {}; 501CanvasRenderingContext2D.prototype.bezierCurveTo = function() {}; 502CanvasRenderingContext2D.prototype.clearHitRegions = function() {}; 503CanvasRenderingContext2D.prototype.clearRect = function() {}; 504CanvasRenderingContext2D.prototype.clip = function() {}; 505CanvasRenderingContext2D.prototype.closePath = function() {}; 506CanvasRenderingContext2D.prototype.createImageData = function() {}; 507CanvasRenderingContext2D.prototype.createLinearGradient = function() {}; 508CanvasRenderingContext2D.prototype.createPattern = function() {}; 509CanvasRenderingContext2D.prototype.createRadialGradient = function() {}; 510CanvasRenderingContext2D.prototype.drawFocusIfNeeded = function() {}; 511CanvasRenderingContext2D.prototype.drawImage = function() {}; 512CanvasRenderingContext2D.prototype.ellipse = function() {}; 513CanvasRenderingContext2D.prototype.fill = function() {}; 514CanvasRenderingContext2D.prototype.fillRect = function() {}; 515CanvasRenderingContext2D.prototype.fillText = function() {}; 516CanvasRenderingContext2D.prototype.getImageData = function() {}; 517CanvasRenderingContext2D.prototype.getLineDash = function() {}; 518CanvasRenderingContext2D.prototype.isPointInPath = function() {}; 519CanvasRenderingContext2D.prototype.isPointInStroke = function() {}; 520CanvasRenderingContext2D.prototype.lineTo = function() {}; 521CanvasRenderingContext2D.prototype.measureText = function() {}; 522CanvasRenderingContext2D.prototype.moveTo = function() {}; 523CanvasRenderingContext2D.prototype.putImageData = function() {}; 524CanvasRenderingContext2D.prototype.quadraticCurveTo = function() {}; 525CanvasRenderingContext2D.prototype.rect = function() {}; 526CanvasRenderingContext2D.prototype.removeHitRegion = function() {}; 527CanvasRenderingContext2D.prototype.resetTransform = function() {}; 528CanvasRenderingContext2D.prototype.restore = function() {}; 529CanvasRenderingContext2D.prototype.rotate = function() {}; 530CanvasRenderingContext2D.prototype.save = function() {}; 531CanvasRenderingContext2D.prototype.scale = function() {}; 532CanvasRenderingContext2D.prototype.scrollPathIntoView = function() {}; 533CanvasRenderingContext2D.prototype.setLineDash = function() {}; 534CanvasRenderingContext2D.prototype.setTransform = function() {}; 535CanvasRenderingContext2D.prototype.stroke = function() {}; 536CanvasRenderingContext2D.prototype.strokeRect = function() {}; 537CanvasRenderingContext2D.prototype.strokeText = function() {}; 538CanvasRenderingContext2D.prototype.transform = function() {}; 539CanvasRenderingContext2D.prototype.translate = function() {}; 540 541var Path2D = {}; 542Path2D.prototype.addPath = function() {}; 543Path2D.prototype.arc = function() {}; 544Path2D.prototype.arcTo = function() {}; 545Path2D.prototype.bezierCurveTo = function() {}; 546Path2D.prototype.closePath = function() {}; 547Path2D.prototype.ellipse = function() {}; 548Path2D.prototype.lineTo = function() {}; 549Path2D.prototype.moveTo = function() {}; 550Path2D.prototype.quadraticCurveTo = function() {}; 551Path2D.prototype.rect = function() {}; 552 553var LinearCanvasGradient = {}; 554LinearCanvasGradient.prototype.addColorStop = function() {}; 555var RadialCanvasGradient = {}; 556RadialCanvasGradient.prototype.addColorStop = function() {}; 557var CanvasPattern = {}; 558CanvasPattern.prototype.setTransform = function() {}; 559 560var ImageData = { 561 /** 562 * @type {Uint8ClampedArray} 563 */ 564 data: {}, 565 height: {}, 566 width: {}, 567}; 568 569var DOMMatrix = { 570 a: {}, 571 b: {}, 572 c: {}, 573 d: {}, 574 e: {}, 575 f: {}, 576}; 577 578// Not sure why this is needed - might be a bug in emsdk that this isn't properly declared. 579function loadWebAssemblyModule() {}; 580 581var DOMMatrix = {};