This repository has been archived by the owner on Apr 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.ts
3862 lines (3415 loc) · 123 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import { Buffer } from './deps.ts';
// Minimum TypeScript Version: 3.7
export interface CanvasKitInitOptions {
/**
* This callback will be invoked when the CanvasKit loader needs to fetch a file (e.g.
* the blob of WASM code). The correct url prefix should be applied.
* @param file - the name of the file that is about to be loaded.
*/
locateFile(file: string): string;
}
export type CanvasDirection = 'ltr' | 'rtl' | 'inherit';
export type CanvasFillRule = 'nonzero' | 'evenodd';
export type CanvasLineCap = 'butt' | 'round' | 'square';
export type CanvasLineJoin = 'round' | 'bevel' | 'miter';
export type CanvasTextAlign = 'start' | 'end' | 'left' | 'right' | 'center';
export type CanvasTextBaseline = 'top' | 'hanging' | 'middle' | 'alphabetic' | 'ideographic' | 'bottom';
export type ImageSmoothingQuality = 'low' | 'medium' | 'high';
export interface DOMMatrix2DInit {
a: number;
b: number;
c: number;
d: number;
e: number;
f: number;
m11: number;
m12: number;
m21: number;
m22: number;
m41: number;
m42: number;
}
export interface CanvasGradient {
addColorStop(offset: number, color: string): void;
}
export interface CanvasPattern {
setTransform(transform?: DOMMatrix2DInit): void;
}
// TODO: Complete types here
export interface DOMMatrixInit {}
export interface DOMPoint {}
export interface DOMPointInit {}
export interface ImageBitmap {
height: number;
width: number;
close(): void;
}
// HTML Element; won't be adding its types here.
export interface Element { }
export interface HTMLCanvasElement { }
export type CanvasImageSource = EmulatedCanvas2D | ImageBitmap | EmbindObject<SkImage>;
export interface DOMMatrixReadOnly {
readonly a: number;
readonly b: number;
readonly c: number;
readonly d: number;
readonly e: number;
readonly f: number;
readonly is2D: boolean;
readonly isIdentity: boolean;
readonly m11: number;
readonly m12: number;
readonly m13: number;
readonly m14: number;
readonly m21: number;
readonly m22: number;
readonly m23: number;
readonly m24: number;
readonly m31: number;
readonly m32: number;
readonly m33: number;
readonly m34: number;
readonly m41: number;
readonly m42: number;
readonly m43: number;
readonly m44: number;
flipX(): DOMMatrix;
flipY(): DOMMatrix;
inverse(): DOMMatrix;
multiply(other?: DOMMatrixInit): DOMMatrix;
rotate(rotX?: number, rotY?: number, rotZ?: number): DOMMatrix;
rotateAxisAngle(x?: number, y?: number, z?: number, angle?: number): DOMMatrix;
rotateFromVector(x?: number, y?: number): DOMMatrix;
scale(scaleX?: number, scaleY?: number, scaleZ?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
scale3d(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
/** @deprecated */
scaleNonUniform(scaleX?: number, scaleY?: number): DOMMatrix;
skewX(sx?: number): DOMMatrix;
skewY(sy?: number): DOMMatrix;
toFloat32Array(): Float32Array;
toFloat64Array(): Float64Array;
toJSON(): any;
transformPoint(point?: DOMPointInit): DOMPoint;
translate(tx?: number, ty?: number, tz?: number): DOMMatrix;
toString(): string;
}
export interface DOMMatrix extends DOMMatrixReadOnly {
a: number;
b: number;
c: number;
d: number;
e: number;
f: number;
m11: number;
m12: number;
m13: number;
m14: number;
m21: number;
m22: number;
m23: number;
m24: number;
m31: number;
m32: number;
m33: number;
m34: number;
m41: number;
m42: number;
m43: number;
m44: number;
invertSelf(): DOMMatrix;
multiplySelf(other?: DOMMatrixInit): DOMMatrix;
preMultiplySelf(other?: DOMMatrixInit): DOMMatrix;
rotateAxisAngleSelf(x?: number, y?: number, z?: number, angle?: number): DOMMatrix;
rotateFromVectorSelf(x?: number, y?: number): DOMMatrix;
rotateSelf(rotX?: number, rotY?: number, rotZ?: number): DOMMatrix;
scale3dSelf(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
scaleSelf(scaleX?: number, scaleY?: number, scaleZ?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix;
setMatrixValue(transformList: string): DOMMatrix;
skewXSelf(sx?: number): DOMMatrix;
skewYSelf(sy?: number): DOMMatrix;
translateSelf(tx?: number, ty?: number, tz?: number): DOMMatrix;
}
export interface CanvasCompositing {
globalAlpha: number;
globalCompositeOperation: string;
}
export interface CanvasDrawImage {
drawImage(image: CanvasImageSource, dx: number, dy: number): void;
drawImage(image: CanvasImageSource, dx: number, dy: number, dw: number, dh: number): void;
drawImage(image: CanvasImageSource, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
}
export interface CanvasDrawPath {
beginPath(): void;
clip(fillRule?: CanvasFillRule): void;
clip(path: Path2D, fillRule?: CanvasFillRule): void;
fill(fillRule?: CanvasFillRule): void;
fill(path: Path2D, fillRule?: CanvasFillRule): void;
isPointInPath(x: number, y: number, fillRule?: CanvasFillRule): boolean;
isPointInPath(path: Path2D, x: number, y: number, fillRule?: CanvasFillRule): boolean;
isPointInStroke(x: number, y: number): boolean;
isPointInStroke(path: Path2D, x: number, y: number): boolean;
stroke(): void;
stroke(path: Path2D): void;
}
export interface CanvasFillStrokeStyles {
fillStyle: string | CanvasGradient | CanvasPattern;
strokeStyle: string | CanvasGradient | CanvasPattern;
createLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasGradient;
createPattern(image: CanvasImageSource, repetition: string | null): CanvasPattern | null;
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): CanvasGradient;
}
export interface CanvasFilters {
filter: string;
}
/** An opaque object describing a gradient. It is returned by the methods CanvasRenderingContext2D.createLinearGradient() or CanvasRenderingContext2D.createRadialGradient(). */
export interface CanvasGradient {
/**
* Adds a color stop with the given color to the gradient at the given offset. 0.0 is the offset at one end of the gradient, 1.0 is the offset at the other end.
*
* Throws an "IndexSizeError" DOMException if the offset is out of range. Throws a "SyntaxError" DOMException if the color cannot be parsed.
*/
addColorStop(offset: number, color: string): void;
}
declare var CanvasGradient: {
prototype: CanvasGradient;
new(): CanvasGradient;
};
export interface CanvasImageData {
createImageData(sw: number, sh: number): ImageData;
createImageData(imagedata: ImageData): ImageData;
getImageData(sx: number, sy: number, sw: number, sh: number): ImageData;
putImageData(imagedata: ImageData, dx: number, dy: number): void;
putImageData(imagedata: ImageData, dx: number, dy: number, dirtyX: number, dirtyY: number, dirtyWidth: number, dirtyHeight: number): void;
}
export interface CanvasImageSmoothing {
imageSmoothingEnabled: boolean;
imageSmoothingQuality: ImageSmoothingQuality;
}
export interface CanvasPath {
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
closePath(): void;
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void;
lineTo(x: number, y: number): void;
moveTo(x: number, y: number): void;
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
rect(x: number, y: number, w: number, h: number): void;
}
export interface CanvasPathDrawingStyles {
lineCap: CanvasLineCap;
lineDashOffset: number;
lineJoin: CanvasLineJoin;
lineWidth: number;
miterLimit: number;
getLineDash(): number[];
setLineDash(segments: number[]): void;
}
/** An opaque object describing a pattern, based on an image, a canvas, or a video, created by the CanvasRenderingContext2D.createPattern() method. */
export interface CanvasPattern {
/**
* Sets the transformation matrix that will be used when rendering the pattern during a fill or stroke painting operation.
*/
setTransform(transform?: DOMMatrix2DInit): void;
}
declare var CanvasPattern: {
prototype: CanvasPattern;
new(): CanvasPattern;
};
export interface CanvasRect {
clearRect(x: number, y: number, w: number, h: number): void;
fillRect(x: number, y: number, w: number, h: number): void;
strokeRect(x: number, y: number, w: number, h: number): void;
}
/** The CanvasRenderingContext2D export interface, part of the Canvas API, provides the 2D rendering context for the drawing surface of a <canvas> element. It is used for drawing shapes, text, images, and other objects. */
export interface CanvasRenderingContext2D extends CanvasCompositing, CanvasDrawImage, CanvasDrawPath, CanvasFillStrokeStyles, CanvasFilters, CanvasImageData, CanvasImageSmoothing, CanvasPath, CanvasPathDrawingStyles, CanvasRect, CanvasShadowStyles, CanvasState, CanvasText, CanvasTextDrawingStyles, CanvasTransform, CanvasUserInterface {
readonly canvas: HTMLCanvasElement;
}
declare var CanvasRenderingContext2D: {
prototype: CanvasRenderingContext2D;
new(): CanvasRenderingContext2D;
};
export interface CanvasShadowStyles {
shadowBlur: number;
shadowColor: string;
shadowOffsetX: number;
shadowOffsetY: number;
}
export interface CanvasState {
restore(): void;
save(): void;
}
export interface TextMetrics {
actualBoundingBoxAscent: number;
actualBoundingBoxDescent: number;
actualBoundingBoxLeft: number;
actualBoundingBoxRight: number;
alphabeticBaseline: number;
emHeightAscent: number;
emHeightDescent: number;
fontBoundingBoxAscent: number;
fontBoundingBoxDescent: number;
hangingBaseline: number;
ideographicBaseline: number;
width: number;
}
export interface CanvasText {
fillText(text: string, x: number, y: number, maxWidth?: number): void;
measureText(text: string): TextMetrics;
strokeText(text: string, x: number, y: number, maxWidth?: number): void;
}
export interface CanvasTextDrawingStyles {
direction: CanvasDirection;
font: string;
textAlign: CanvasTextAlign;
textBaseline: CanvasTextBaseline;
}
export interface CanvasTransform {
getTransform(): DOMMatrix;
resetTransform(): void;
rotate(angle: number): void;
scale(x: number, y: number): void;
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
setTransform(transform?: DOMMatrix2DInit): void;
transform(a: number, b: number, c: number, d: number, e: number, f: number): void;
translate(x: number, y: number): void;
}
export interface CanvasUserInterface {
drawFocusIfNeeded(element: Element): void;
drawFocusIfNeeded(path: Path2D, element: Element): void;
scrollPathIntoView(): void;
scrollPathIntoView(path: Path2D): void;
}
export interface ImageData {
data: Uint8ClampedArray;
height: number;
width: number;
}
export interface Path2D { }
export interface CanvasKit {
// Helpers
/**
* Constructs a Color with the same API as CSS's rgba(), that is
* Internally, Colors are four unpremultiplied 32-bit floats: r, g, b, a.
* In order to construct one with more precision or in a wider gamut,
* use CanvasKit.Color4f().
*
* @param r - red value, clamped to [0, 255].
* @param g - green value, clamped to [0, 255].
* @param b - blue value, clamped to [0, 255].
* @param a - alpha value, from 0 to 1.0. By default is 1.0 (opaque).
*/
Color(r: number, g: number, b: number, a?: number): SkColor;
/**
* Construct a 4-float color. Float values are typically between 0.0 and 1.0.
* @param r - red value.
* @param g - green value.
* @param b - blue value.
* @param a - alpha value. By default is 1.0 (opaque).
*/
Color4f(r: number, g: number, b: number, a?: number): SkColor;
/**
* Constructs a Color as a 32 bit unsigned integer, with 8 bits assigned to each channel.
* Channels are expected to be between 0 and 255 and will be clamped as such.
* If a is omitted, it will be 255 (opaque).
*
* This is not the preferred way to use colors in Skia APIs, use Color or Color4f.
* @param r - red value, clamped to [0, 255].
* @param g - green value, clamped to [0, 255].
* @param b - blue value, clamped to [0, 255].
* @param a - alpha value, from 0 to 1.0. By default is 1.0 (opaque).
*/
ColorAsInt(r: number, g: number, b: number, a?: number): SkColorInt;
/**
* Returns a css style [r, g, b, a] where r, g, b are returned as
* ints in the range [0, 255] and where a is scaled between 0 and 1.0.
* [Deprecated] - this is trivial now that SkColor is 4 floats.
*/
getColorComponents(c: SkColor): number[];
/**
* Takes in a CSS color value and returns a CanvasKit.Color
* (which is an array of 4 floats in RGBA order). An optional colorMap
* may be provided which maps custom strings to values.
* In the CanvasKit canvas2d shim layer, we provide this map for processing
* canvas2d calls, but not here for code size reasons.
*/
parseColorString(color: string, colorMap?: object): SkColor;
/**
* Returns a copy of the passed in color with a new alpha value applied.
* [Deprecated] - this is trivial now that SkColor is 4 floats.
*/
multiplyByAlpha(c: SkColor, alpha: number): SkColor;
/**
* Computes color values for one-pass tonal alpha.
* Note, if malloced colors are passed in, the memory pointed at by the MallocObj
* will be overwritten with the computed tonal colors (and thus the return val can be
* ignored).
* @param colors
*/
computeTonalColors(colors: TonalColorsInput): TonalColorsOutput;
/**
* Returns a rectangle with the given paramaters. See SkRect.h for more.
* @param left - The x coordinate of the upper-left corner.
* @param top - The y coordinate of the upper-left corner.
* @param right - The x coordinate of the lower-right corner.
* @param bottom - The y coordinate of the lower-right corner.
*/
LTRBRect(left: number, top: number, right: number, bottom: number): SkRect;
/**
* Returns a rectangle with the given paramaters. See SkRect.h for more.
* @param x - The x coordinate of the upper-left corner.
* @param y - The y coordinate of the upper-left corner.
* @param width - The width of the rectangle.
* @param height - The height of the rectangle.
*/
XYWHRect(x: number, y: number, width: number, height: number): SkRect;
/**
* Returns a rectangle with the given integer paramaters. See SkRect.h for more.
* @param left - The x coordinate of the upper-left corner.
* @param top - The y coordinate of the upper-left corner.
* @param right - The x coordinate of the lower-right corner.
* @param bottom - The y coordinate of the lower-right corner.
*/
LTRBiRect(left: number, top: number, right: number, bottom: number): SkIRect;
/**
* Returns a rectangle with the given paramaters. See SkRect.h for more.
* @param x - The x coordinate of the upper-left corner.
* @param y - The y coordinate of the upper-left corner.
* @param width - The width of the rectangle.
* @param height - The height of the rectangle.
*/
XYWHiRect(x: number, y: number, width: number, height: number): SkIRect;
/**
* Returns a rectangle with rounded corners consisting of the given rectangle and
* the same radiusX and radiusY for all four corners.
* @param rect - The base rectangle.
* @param rx - The radius of the corners in the x direction.
* @param ry - The radius of the corners in the y direction.
*/
RRectXY(rect: InputRect, rx: number, ry: number): SkRRect;
/**
* Malloc returns a TypedArray backed by the C++ memory of the
* given length. It should only be used by advanced users who
* can manage memory and initialize values properly. When used
* correctly, it can save copying of data between JS and C++.
* When used incorrectly, it can lead to memory leaks.
* Any memory allocated by CanvasKit.Malloc needs to be released with CanvasKit.Free.
*
* const mObj = CanvasKit.Malloc(Float32Array, 20);
* Get a TypedArray view around the malloc'd memory (this does not copy anything).
* const ta = mObj.toTypedArray();
* // store data into ta
* const cf = CanvasKit.SkColorFilter.MakeMatrix(ta); // mObj could also be used.
*
* // eventually...
* CanvasKit.Free(mObj);
*
* @param typedArray - constructor for the typedArray.
* @param len - number of *elements* to store.
*/
Malloc(typedArray: TypedArrayConstructor, len: number): MallocObj;
/**
* As Malloc but for GlyphIDs. This helper exists to make sure the JS side and the C++ side
* stay in agreement with how wide GlyphIDs are.
* @param len - number of GlyphIDs to make space for.
*/
MallocGlyphIDs(len: number): MallocObj;
/**
* Free frees the memory returned by Malloc.
* Any memory allocated by CanvasKit.Malloc needs to be released with CanvasKit.Free.
*/
Free(m: MallocObj): void;
// Surface related functions
/**
* Creates a Surface on a given canvas. If both GPU and CPU modes have been compiled in, this
* will first try to create a GPU surface and then fallback to a CPU one if that fails. If just
* the CPU mode has been compiled in, a CPU surface will be created.
* @param canvas - either the canvas element itself or a string with the DOM id of it.
*/
MakeCanvasSurface(canvas: HTMLCanvasElement | string): SkSurface | null;
/**
* Creates a CPU backed (aka raster) surface.
* @param canvas - either the canvas element itself or a string with the DOM id of it.
*/
MakeSWCanvasSurface(canvas: HTMLCanvasElement | string): SkSurface | null;
/**
* A helper for creating a WebGL backed (aka GPU) surface and falling back to a CPU surface if
* the GPU one cannot be created. This works for both WebGL 1 and WebGL 2.
* @param canvas - Either the canvas element itself or a string with the DOM id of it.
* @param colorSpace - One of the supported color spaces. Default is SRGB.
* @param opts - Options that will get passed to the creation of the WebGL context.
*/
MakeWebGLCanvasSurface(canvas: HTMLCanvasElement | string, colorSpace?: ColorSpace,
opts?: WebGLOptions): SkSurface | null;
/**
* Returns a CPU backed surface with the given dimensions, an SRGB colorspace, Unpremul
* alphaType and 8888 color type. The pixels belonging to this surface will be in memory and
* not visible.
* @param width - number of pixels of the width of the drawable area.
* @param height - number of pixels of the height of the drawable area.
*/
MakeSurface(width: number, height: number): SkSurface | null;
/**
* Creates a WebGL Context from the given canvas with the given options. If options are omitted,
* sensible defaults will be used.
* @param canvas
* @param opts
*/
GetWebGLContext(canvas: HTMLCanvasElement, opts?: WebGLOptions): WebGLContextHandle;
/**
* Creates a GrContext from the given WebGL Context.
* @param ctx
*/
MakeGrContext(ctx: WebGLContextHandle): GrContext;
/**
* Creates a Surface that will be drawn to the given GrContext (and show up on screen).
* @param ctx
* @param width - number of pixels of the width of the visible area.
* @param height - number of pixels of the height of the visible area.
* @param colorSpace
*/
MakeOnScreenGLSurface(ctx: GrContext, width: number, height: number,
colorSpace: ColorSpace): SkSurface | null;
/**
* Returns a (non-visible) SkSurface on the GPU. It has the given dimensions and uses 8888
* color depth and premultiplied alpha. See SkSurface.h for more details.
* @param ctx
* @param width
* @param height
*/
MakeRenderTarget(ctx: GrContext, width: number, height: number): SkSurface | null;
/**
* Returns a (non-visible) SkSurface on the GPU. It has the settings provided by image info.
* See SkSurface.h for more details.
* @param ctx
* @param info
*/
MakeRenderTarget(ctx: GrContext, info: SkImageInfo): SkSurface | null;
/**
* Returns the current WebGLContext that the wasm code is configured to draw to. It is
* recommended to capture this value after creating a new WebGL surface if there are multiple
* surfaces on the screen.
*/
currentContext(): WebGLContextHandle;
/**
* Sets the WebGLContext that the wasm code will draw to.
*
* When a WebGL call is made on the C++ side, it is routed to the JS side to target a specific
* WebGL context. WebGL calls are methods on a WebGL context, so CanvasKit needs to know which
* context to send the calls to.
* @param ctx
*/
setCurrentContext(ctx: WebGLContextHandle): void;
/**
* Returns the max size of the global cache for bitmaps used by CanvasKit.
*/
getDecodeCacheLimitBytes(): number;
/**
* Returns the current size of the global cache for bitmaps used by CanvasKit.
*/
getDecodeCacheUsedBytes(): number;
/**
* Sets the max size of the global cache for bitmaps used by CanvasKit.
* @param size - number of bytes that can be used to cache bitmaps.
*/
setDecodeCacheLimitBytes(size: number): void;
/**
* Decodes the given bytes into an animated image. Returns null if the bytes were invalid.
* The passed in bytes will be copied into the WASM heap, so the caller can dispose of them.
* @param bytes
*/
MakeAnimatedImageFromEncoded(bytes: Uint8Array | ArrayBuffer): SkAnimatedImage | null;
/**
* Returns an emulated Canvas2D of the given size.
* @param width
* @param height
*/
MakeCanvas(width: number, height: number): EmulatedCanvas2D;
/**
* Returns an emulated Canvas2D of the given size.
* @param width
* @param height
*/
createCanvas(width: number, height: number): EmulatedCanvas2D;
/**
* Return an SkImage backed by the encoded data, but attempt to defer decoding until the image
* is actually used/drawn. This deferral allows the system to cache the result, either on the
* CPU or on the GPU, depending on where the image is drawn.
* This decoding uses the codecs that have been compiled into CanvasKit. If the bytes are
* invalid (or an unrecognized codec), null will be returned. See SkImage.h for more details.
* @param bytes
*/
MakeImageFromEncoded(bytes: Uint8Array | ArrayBuffer): SkImage | null;
/**
* Returns an SkImage with the data from the provided CanvasImageSource (e.g. <img>). This will
* use the browser's built in codecs, in that src will be drawn to a canvas and then readback
* and placed into an SkImage.
* @param src
*/
MakeImageFromCanvasImageSource(src: CanvasImageSource): SkImage;
/**
* Creates a new path by combining the given paths according to op. If this fails, null will
* be returned instead.
* @param one
* @param two
* @param op
*/
MakePathFromOp(one: SkPath, two: SkPath, op: PathOp): SkPath | null;
/**
* Creates a new path from the provided SVG string. If this fails, null will be
* returned instead.
* @param str
*/
MakePathFromSVGString(str: string): SkPath | null;
/**
* Returns an SkPicture which has been serialized previously to the given bytes.
* @param bytes
*/
MakeSkPicture(bytes: Uint8Array | ArrayBuffer): SkPicture | null;
/**
* Returns an SkVertices based on the given positions and optional parameters.
* See SkVertices.h (especially the Builder) for more details.
* @param mode
* @param positions
* @param textureCoordinates
* @param colors - either a list of int colors or a flattened color array.
* @param indices
* @param isVolatile
*/
MakeSkVertices(mode: VertexMode, positions: number[][], textureCoordinates?: number[][] | null,
colors?: Float32Array | ColorIntArray | null, indices?: number[] | null,
isVolatile?: boolean): SkVertices;
/**
* Returns a Skottie animation built from the provided json string.
* Requires that Skottie be compiled into CanvasKit.
* @param json
*/
MakeAnimation(json: string): SkottieAnimation;
/**
* Returns a managed Skottie animation built from the provided json string and assets.
* Requires that Skottie be compiled into CanvasKit.
* @param json
* @param assets - a dictionary of named blobs: { key: ArrayBuffer, ... }
* @param filterPrefix - an optional string acting as a name filter for selecting "interesting"
* Lottie properties (surfaced in the embedded player controls)
*/
MakeManagedAnimation(json: string, assets?: Record<string, ArrayBuffer>,
filterPrefix?: string): ManagedSkottieAnimation;
/**
* Returns a Particles effect built from the provided json string and assets.
* Requires that Particles be compiled into CanvasKit
* @param json
* @param assets
*/
MakeParticles(json: string, assets?: Record<string, ArrayBuffer>): Particles;
/**
* Returns the underlying data from SkData as a Uint8Array.
* @param data
*/
getSkDataBytes(data: SkData): Uint8Array;
// Constructors, i.e. things made with `new CanvasKit.Foo()`;
readonly ImageData: ImageDataConstructor;
readonly ParagraphStyle: ParagraphStyleConstructor;
readonly ShapedText: ShapedTextConstructor;
readonly SkContourMeasureIter: SkContourMeasureIterConstructor;
readonly SkFont: SkFontConstructor;
readonly SkPaint: DefaultConstructor<SkPaint>;
readonly SkPath: SkPathConstructorAndFactory;
readonly SkPictureRecorder: DefaultConstructor<SkPictureRecorder>;
readonly TextStyle: TextStyleConstructor;
// Factories, i.e. things made with CanvasKit.Foo.MakeTurboEncapsulator()
readonly ParagraphBuilder: ParagraphBuilderFactory;
readonly SkColorFilter: SkColorFilterFactory;
readonly SkFontMgr: SkFontMgrFactory;
readonly SkImageFilter: SkImageFilterFactory;
readonly SkMaskFilter: SkMaskFilterFactory;
readonly SkPathEffect: SkPathEffectFactory;
readonly SkRuntimeEffect: SkRuntimeEffectFactory;
readonly SkShader: SkShaderFactory;
readonly SkTextBlob: SkTextBlobFactory;
readonly TypefaceFontProvider: TypefaceFontProviderFactory;
// Misc
readonly SkColorMatrix: ColorMatrixHelpers;
readonly SkMatrix: Matrix3x3Helpers;
readonly SkM44: Matrix4x4Helpers;
readonly SkVector: VectorHelpers;
// Core Enums
readonly AlphaType: AlphaTypeEnumValues;
readonly BlendMode: BlendModeEnumValues;
readonly BlurStyle: BlurStyleEnumValues;
readonly ClipOp: ClipOpEnumValues;
readonly ColorType: ColorTypeEnumValues;
readonly FillType: FillTypeEnumValues;
readonly FilterQuality: FilterQualityEnumValues;
readonly FontEdging: FontEdgingEnumValues;
readonly FontHinting: FontHintingEnumValues;
readonly ImageFormat: ImageFormatEnumValues;
readonly PaintStyle: PaintStyleEnumValues;
readonly PathOp: PathOpEnumValues;
readonly PointMode: PointModeEnumValues;
readonly SkColorSpace: ColorSpaceEnumValues;
readonly StrokeCap: StrokeCapEnumValues;
readonly StrokeJoin: StrokeJoinEnumValues;
readonly TileMode: TileModeEnumValues;
readonly VertexMode: VertexModeEnumValues;
// Core Constants
readonly TRANSPARENT: SkColor;
readonly BLACK: SkColor;
readonly WHITE: SkColor;
readonly RED: SkColor;
readonly GREEN: SkColor;
readonly BLUE: SkColor;
readonly YELLOW: SkColor;
readonly CYAN: SkColor;
readonly MAGENTA: SkColor;
readonly MOVE_VERB: number;
readonly LINE_VERB: number;
readonly QUAD_VERB: number;
readonly CONIC_VERB: number;
readonly CUBIC_VERB: number;
readonly CLOSE_VERB: number;
readonly SaveLayerInitWithPrevious: SaveLayerFlag;
readonly SaveLayerF16ColorType: SaveLayerFlag;
readonly gpu: boolean; // if GPU code was compiled in
// Paragraph Enums
readonly Affinity: AffinityEnumValues;
readonly DecorationStyle: DecorationStyleEnumValues;
readonly FontSlant: FontSlantEnumValues;
readonly FontWeight: FontWeightEnumValues;
readonly FontWidth: FontWidthEnumValues;
readonly PlaceholderAlignment: PlaceholderAlignmentEnumValues;
readonly RectHeightStyle: RectHeightStyleEnumValues;
readonly RectWidthStyle: RectWidthStyleEnumValues;
readonly TextAlign: TextAlignEnumValues;
readonly TextBaseline: TextBaselineEnumValues;
readonly TextDirection: TextDirectionEnumValues;
// Paragraph Constants
readonly NoDecoration: number;
readonly UnderlineDecoration: number;
readonly OverlineDecoration: number;
readonly LineThroughDecoration: number;
}
export interface Camera {
/** a 3d point locating the camera. */
eye: Vector3;
/** center of attention - the 3d point the camera is looking at. */
coa: Vector3;
/**
* A unit vector pointing the cameras up direction. Note that using only eye and coa
* would leave the roll of the camera unspecified.
*/
up: Vector3;
/** near clipping plane distance */
near: number;
/** far clipping plane distance */
far: number;
/** field of view in radians */
angle: AngleInRadians;
}
/**
* CanvasKit is built with Emscripten and Embind. Embind adds the following methods to all objects
* that are exposed with it.
*/
export interface EmbindObject<T extends EmbindObject<T>> {
clone(): T;
delete(): void;
deleteAfter(): void;
isAliasOf(other: any): boolean;
isDeleted(): boolean;
}
export interface EmbindSingleton {
// Technically Embind includes the other methods too, but they should not be called for a
// singleton.
isAliasOf(other: any): boolean;
}
/**
* Represents the set of enum values.
*/
export interface EmbindEnum {
readonly values: number[];
}
/**
* Represents a single member of an enum.
*/
export interface EmbindEnumEntity {
readonly value: number;
}
export interface EmulatedCanvas2D {
/**
* Cleans up all resources associated with this emulated canvas.
*/
dispose(): void;
/**
* Decodes an image with the given bytes.
* @param bytes
*/
decodeImage(bytes: ArrayBuffer | Uint8Array): SkImage;
/**
* Returns an emulated canvas2d context if type == '2d', null otherwise.
*
* null is not added as return type here, but '2d' is the ONLY valid context here.
* @param type
*/
getContext(type: '2d'): EmulatedCanvas2DContext;
/**
* Loads the given font with the given descriptors. Emulates new FontFace().
* @param bytes
* @param descriptors
*/
loadFont(bytes: ArrayBuffer | Uint8Array, descriptors: object): void;
/**
* Registers a font into Canvas. (node-canvas compatibility)
* @param src Source of the font (Path/URL)
* @param descriptors
*/
registerFont(src: string, descriptors: object): void;
/**
* Returns an new emulated Path2D object.
* @param str - an SVG string representing a path.
*/
makePath2D(str?: string): EmulatedPath2D;
/**
* Returns the current canvas as a base64 encoded image string.
* @param codec - image/png by default; image/jpeg also supported.
* @param quality
*/
toDataURL(codec?: string, quality?: number): string;
/**
* Returns Buffer containing Image data.
*/
toBuffer(options: BufferOptions & { buffer: true }): Buffer;
toBuffer(options?: BufferOptions & { buffer?: false }): Uint8Array;
toBuffer(options?: BufferOptions): Uint8Array | Buffer;
width: number;
height: number;
}
export interface BufferOptions {
/** image/png by default; image/jpeg also supported. */
codec?: string;
/** Image quality for jpeg encoding */
quality?: number;
/** If it should return buffer instead of Uint8Array */
buffer?: boolean;
}
/** Part of the Canvas2D emulation code */
export type EmulatedCanvas2DContext = CanvasRenderingContext2D;
export type EmulatedImageData = ImageData;
export type EmulatedPath2D = Path2D;
export interface FontStyle {
weight?: FontWeight;
width?: FontWidth;
slant?: FontSlant;
}
/**
* See GrContext.h for more on this class.
*/
export interface GrContext extends EmbindObject<GrContext> {
getResourceCacheLimitBytes(): number;
getResourceCacheUsageBytes(): number;
releaseResourcesAndAbandonContext(): void;
setResourceCacheLimitBytes(bytes: number): void;
}
/**
* This object is a wrapper around a pointer to some memory on the WASM heap. The type of the
* pointer was determined at creation time.
*/
export interface MallocObj {
/**
* The number of objects this pointer refers to.
*/
readonly length: number;
/**
* The "pointer" into the WASM memory. Should be fixed over the lifetime of the object.
*/
readonly byteOffset: number;
/**
* Return a read/write view into a subset of the memory. Do not cache the TypedArray this
* returns, it may be invalidated if the WASM heap is resized. This is the same as calling
* .toTypedArray().subarray() except the returned TypedArray can also be passed into an API
* and not cause an additional copy.
*/
subarray(start: number, end: number): TypedArray;
/**
* Return a read/write view of the memory. Do not cache the TypedArray this returns, it may be
* invalidated if the WASM heap is resized. If this TypedArray is passed into a CanvasKit API,
* it will not be copied again, only the pointer will be re-used.
*/
toTypedArray(): TypedArray;
}
export interface ManagedSkottieAnimation extends SkottieAnimation {
setColor(key: string, color: InputColor): void;
setOpacity(key: string, opacity: number): void;
getMarkers(): object[];
getColorProps(): object[];
getOpacityProps(): object[];
}
/**
* See Paragraph.h for more information on this class. This is only available if Paragraph has
* been compiled in.
*/
export interface Paragraph extends EmbindObject<Paragraph> {
didExceedMaxLines(): boolean;
getAlphabeticBaseline(): number;
/**
* Returns the index of the glyph that corresponds to the provided coordinate,
* with the top left corner as the origin, and +y direction as down.
*/
getGlyphPositionAtCoordinate(dx: number, dy: number): PositionWithAffinity;
getHeight(): number;
getIdeographicBaseline(): number;
getLongestLine(): number;
getMaxIntrinsicWidth(): number;
getMaxWidth(): number;
getMinIntrinsicWidth(): number;
getRectsForPlaceholders(): FlattenedRectangleArray;
/**
* Returns bounding boxes that enclose all text in the range of glpyh indexes [start, end).
* @param start
* @param end
* @param hStyle
* @param wStyle
*/
getRectsForRange(start: number, end: number, hStyle: RectHeightStyle,
wStyle: RectWidthStyle): FlattenedRectangleArray;
/**
* Finds the first and last glyphs that define a word containing the glyph at index offset.
* @param offset
*/
getWordBoundary(offset: number): URange;
/**
* Lays out the text in the paragraph so it is wrapped to the given width.
* @param width
*/
layout(width: number): void;
}
export interface ParagraphBuilder extends EmbindObject<ParagraphBuilder> {
/**
* Pushes the information required to leave an open space.