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