@nexterm/canvas 0.0.0-stage → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.ts ADDED
@@ -0,0 +1,1362 @@
1
+ import { ReadableStream } from 'node:stream/web'
2
+
3
+ // Clear all type of caches in Skia
4
+ export function clearAllCache(): void
5
+
6
+ export type TextRenderer = 'portable' | 'system'
7
+
8
+ /**
9
+ * Selects how text is drawn.
10
+ *
11
+ * `'portable'` (the default) draws text the same way on every OS: FreeType,
12
+ * Skia's default text gamma, no LCD text and one font family table. Text gives
13
+ * the same pixels and TextMetrics on macOS, Linux and Windows when:
14
+ * - `ctx.font` names only fonts you registered (the default `10px sans-serif`
15
+ * and names like `Arial` use installed fonts, unless you registered a font
16
+ * under that name);
17
+ * - your registered fonts have every character you draw (a missing character
18
+ * comes from an installed font);
19
+ * - you set `ctx.lang` (for example `'en'`), because the default `'inherit'`
20
+ * follows the host language;
21
+ * - `FREETYPE_PROPERTIES` is not set.
22
+ * x64 and arm64 builds can still differ by 1 color level on some edge pixels.
23
+ *
24
+ * `'system'` draws text with each OS's own font renderer, as Chrome does:
25
+ * CoreText on macOS (Fontations for some color and variable fonts) with
26
+ * CoreText's installed fonts and fallback, Fontations on Linux, FreeType
27
+ * elsewhere; plus each OS's text gamma and contrast, LCD text on opaque macOS
28
+ * canvases, Chrome's per-OS font family settings and macOS metric rules.
29
+ *
30
+ * Applies to the whole process, worker threads included. Call it once at
31
+ * startup, before creating canvases. Setting the mode in use again changes
32
+ * nothing. Any other value throws a TypeError. Registered fonts keep their
33
+ * FontKey. A canvas created before the switch keeps its text gamma until its
34
+ * width or height is set. A `ctx.font` value set before the switch keeps its
35
+ * parsed form: sizes in `ex`/`ch`/... units and, on macOS, the
36
+ * BlinkMacSystemFont to system-ui rewrite. Set `ctx.font` again after the
37
+ * switch.
38
+ */
39
+ export function setTextRenderer(renderer: TextRenderer): void
40
+
41
+ /** The text renderer in use, set by {@link setTextRenderer}. */
42
+ export function getTextRenderer(): TextRenderer
43
+
44
+ interface CanvasRenderingContext2D
45
+ extends CanvasCompositing,
46
+ CanvasDrawPath,
47
+ CanvasFillStrokeStyles,
48
+ CanvasFilters,
49
+ CanvasImageData,
50
+ CanvasImageSmoothing,
51
+ CanvasPath,
52
+ CanvasPathDrawingStyles,
53
+ CanvasRect,
54
+ CanvasSettings,
55
+ CanvasShadowStyles,
56
+ CanvasState,
57
+ CanvasText,
58
+ CanvasTextDrawingStyles,
59
+ CanvasTransform,
60
+ CanvasPDFAnnotations { }
61
+
62
+ interface CanvasState {
63
+ isContextLost(): boolean
64
+ reset(): void
65
+ restore(): void
66
+ save(): void
67
+ }
68
+ interface CanvasShadowStyles {
69
+ shadowBlur: number
70
+ shadowColor: string
71
+ shadowOffsetX: number
72
+ shadowOffsetY: number
73
+ }
74
+ type CanvasPixelFormat = 'float16' | 'unorm8'
75
+ interface CanvasToneMapping {
76
+ mode?: 'extended' | 'standard'
77
+ }
78
+ interface CanvasRenderingContext2DSettings {
79
+ alpha?: boolean
80
+ colorSpace?: PredefinedColorSpace
81
+ /** 'float16' stores half floats, as Chrome does; `canvas.data()` then gives them premultiplied, 8 bytes a pixel. */
82
+ colorType?: CanvasPixelFormat
83
+ desynchronized?: boolean
84
+ /** Not read by getContext() (as in Chrome); getContextAttributes() reports `{ mode: 'standard' }`. */
85
+ toneMapping?: CanvasToneMapping
86
+ willReadFrequently?: boolean
87
+ }
88
+ interface CanvasSettings {
89
+ getContextAttributes(): Required<CanvasRenderingContext2DSettings>
90
+ }
91
+
92
+ interface CanvasRect {
93
+ clearRect(x: number, y: number, w: number, h: number): void
94
+ fillRect(x: number, y: number, w: number, h: number): void
95
+ strokeRect(x: number, y: number, w: number, h: number): void
96
+ }
97
+
98
+ interface TextMetrics {
99
+ readonly actualBoundingBoxAscent: number
100
+ readonly actualBoundingBoxDescent: number
101
+ readonly actualBoundingBoxLeft: number
102
+ readonly actualBoundingBoxRight: number
103
+ readonly alphabeticBaseline: number
104
+ readonly emHeightAscent: number
105
+ readonly emHeightDescent: number
106
+ readonly fontBoundingBoxAscent: number
107
+ readonly fontBoundingBoxDescent: number
108
+ readonly hangingBaseline: number
109
+ readonly ideographicBaseline: number
110
+ readonly width: number
111
+ }
112
+
113
+ interface CanvasText {
114
+ fillText(text: string, x: number, y: number, maxWidth?: number): void
115
+ measureText(text: string): TextMetrics
116
+ strokeText(text: string, x: number, y: number, maxWidth?: number): void
117
+ }
118
+
119
+ type CanvasLineCap = 'butt' | 'round' | 'square'
120
+ type CanvasLineJoin = 'bevel' | 'miter' | 'round'
121
+
122
+ interface CanvasPathDrawingStyles {
123
+ lineCap: CanvasLineCap
124
+ lineDashOffset: number
125
+ lineJoin: CanvasLineJoin
126
+ lineWidth: number
127
+ miterLimit: number
128
+ getLineDash(): number[]
129
+ setLineDash(segments: number[]): void
130
+ }
131
+
132
+ interface CanvasPath {
133
+ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void
134
+ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
135
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void
136
+ closePath(): void
137
+ ellipse(
138
+ x: number,
139
+ y: number,
140
+ radiusX: number,
141
+ radiusY: number,
142
+ rotation: number,
143
+ startAngle: number,
144
+ endAngle: number,
145
+ counterclockwise?: boolean,
146
+ ): void
147
+ lineTo(x: number, y: number): void
148
+ moveTo(x: number, y: number): void
149
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
150
+ rect(x: number, y: number, w: number, h: number): void
151
+ roundRect(
152
+ x: number,
153
+ y: number,
154
+ w: number,
155
+ h: number,
156
+ radii?: number | DOMPointInit | Iterable<number | DOMPointInit>,
157
+ ): void
158
+ }
159
+
160
+ type ImageSmoothingQuality = 'high' | 'low' | 'medium'
161
+
162
+ interface CanvasImageSmoothing {
163
+ imageSmoothingEnabled: boolean
164
+ imageSmoothingQuality: ImageSmoothingQuality
165
+ }
166
+
167
+ interface CanvasTransform {
168
+ resetTransform(): void
169
+ rotate(angle: number): void
170
+ scale(x: number, y: number): void
171
+ setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void
172
+ /** Missing members default to the identity; `a` and `m11` (and so on) must agree when both are given. */
173
+ setTransform(
174
+ transform?: Partial<DOMMatrixInit> & {
175
+ m11?: number
176
+ m12?: number
177
+ m21?: number
178
+ m22?: number
179
+ m41?: number
180
+ m42?: number
181
+ },
182
+ ): void
183
+ transform(a: number, b: number, c: number, d: number, e: number, f: number): void
184
+ translate(x: number, y: number): void
185
+ }
186
+
187
+ interface CanvasPDFAnnotations {
188
+ /**
189
+ * Create a clickable URL link annotation in a PDF document.
190
+ * This is only effective when used with PDF documents.
191
+ * @param left - Left coordinate of the link rectangle
192
+ * @param top - Top coordinate of the link rectangle
193
+ * @param right - Right coordinate of the link rectangle
194
+ * @param bottom - Bottom coordinate of the link rectangle
195
+ * @param url - The URL to link to
196
+ */
197
+ annotateLinkUrl(left: number, top: number, right: number, bottom: number, url: string): void
198
+
199
+ /**
200
+ * Create a named destination at a specific point in a PDF document.
201
+ * This destination can be used as a target for internal links.
202
+ * @param x - X coordinate of the destination point
203
+ * @param y - Y coordinate of the destination point
204
+ * @param name - Name identifier for the destination
205
+ */
206
+ annotateNamedDestination(x: number, y: number, name: string): void
207
+
208
+ /**
209
+ * Create a link to a named destination within the PDF document.
210
+ * This is only effective when used with PDF documents.
211
+ * @param left - Left coordinate of the link rectangle
212
+ * @param top - Top coordinate of the link rectangle
213
+ * @param right - Right coordinate of the link rectangle
214
+ * @param bottom - Bottom coordinate of the link rectangle
215
+ * @param name - Name of the destination to link to
216
+ */
217
+ annotateLinkToDestination(left: number, top: number, right: number, bottom: number, name: string): void
218
+ }
219
+
220
+ type PredefinedColorSpace = 'display-p3' | 'srgb'
221
+ /** 'rgba-float16' throws a NotSupportedError on a runtime without Float16Array (Node 22). */
222
+ type ImageDataPixelFormat = 'rgba-unorm8' | 'rgba-float16' | 'rgba-float32'
223
+ /** Float16Array, where the TypeScript lib has it. */
224
+ type ImageDataFloat16Array = typeof globalThis extends { Float16Array: { prototype: infer T } } ? T : never
225
+ type ImageDataArray = Uint8ClampedArray | ImageDataFloat16Array | Float32Array
226
+
227
+ interface ImageDataSettings {
228
+ colorSpace?: PredefinedColorSpace
229
+ pixelFormat?: ImageDataPixelFormat
230
+ }
231
+ interface CanvasImageData {
232
+ createImageData(sw: number, sh: number, settings?: ImageDataSettings & { pixelFormat?: 'rgba-unorm8' }): ImageData
233
+ createImageData(
234
+ sw: number,
235
+ sh: number,
236
+ settings: ImageDataSettings & { pixelFormat: 'rgba-float16' },
237
+ ): ImageData<ImageDataFloat16Array>
238
+ createImageData(
239
+ sw: number,
240
+ sh: number,
241
+ settings: ImageDataSettings & { pixelFormat: 'rgba-float32' },
242
+ ): ImageData<Float32Array>
243
+ createImageData(sw: number, sh: number, settings?: ImageDataSettings): ImageData<ImageDataArray>
244
+ createImageData<T extends ImageDataArray>(imagedata: ImageData<T>): ImageData<T>
245
+ getImageData(
246
+ sx: number,
247
+ sy: number,
248
+ sw: number,
249
+ sh: number,
250
+ settings?: ImageDataSettings & { pixelFormat?: 'rgba-unorm8' },
251
+ ): ImageData
252
+ getImageData(
253
+ sx: number,
254
+ sy: number,
255
+ sw: number,
256
+ sh: number,
257
+ settings: ImageDataSettings & { pixelFormat: 'rgba-float16' },
258
+ ): ImageData<ImageDataFloat16Array>
259
+ getImageData(
260
+ sx: number,
261
+ sy: number,
262
+ sw: number,
263
+ sh: number,
264
+ settings: ImageDataSettings & { pixelFormat: 'rgba-float32' },
265
+ ): ImageData<Float32Array>
266
+ getImageData(sx: number, sy: number, sw: number, sh: number, settings?: ImageDataSettings): ImageData<ImageDataArray>
267
+ putImageData(imagedata: ImageData<ImageDataArray>, dx: number, dy: number): void
268
+ putImageData(
269
+ imagedata: ImageData<ImageDataArray>,
270
+ dx: number,
271
+ dy: number,
272
+ dirtyX: number,
273
+ dirtyY: number,
274
+ dirtyWidth: number,
275
+ dirtyHeight: number,
276
+ ): void
277
+ }
278
+
279
+ type CanvasDirection = 'inherit' | 'ltr' | 'rtl'
280
+ type CanvasFontKerning = 'auto' | 'none' | 'normal'
281
+ type CanvasFontStretch =
282
+ | 'condensed'
283
+ | 'expanded'
284
+ | 'extra-condensed'
285
+ | 'extra-expanded'
286
+ | 'normal'
287
+ | 'semi-condensed'
288
+ | 'semi-expanded'
289
+ | 'ultra-condensed'
290
+ | 'ultra-expanded'
291
+ type CanvasFontVariantCaps =
292
+ | 'all-petite-caps'
293
+ | 'all-small-caps'
294
+ | 'normal'
295
+ | 'petite-caps'
296
+ | 'small-caps'
297
+ | 'titling-caps'
298
+ | 'unicase'
299
+ type CanvasTextAlign = 'center' | 'end' | 'left' | 'right' | 'start'
300
+ type CanvasTextBaseline = 'alphabetic' | 'bottom' | 'hanging' | 'ideographic' | 'middle' | 'top'
301
+ type CanvasTextRendering = 'auto' | 'geometricPrecision' | 'optimizeLegibility' | 'optimizeSpeed'
302
+
303
+ interface CanvasTextDrawingStyles {
304
+ direction: CanvasDirection
305
+ font: string
306
+ fontKerning: CanvasFontKerning
307
+ fontStretch: CanvasFontStretch
308
+ fontVariantCaps: CanvasFontVariantCaps
309
+ letterSpacing: string
310
+ textAlign: CanvasTextAlign
311
+ textBaseline: CanvasTextBaseline
312
+ textRendering: CanvasTextRendering
313
+ wordSpacing: string
314
+ fontVariationSettings: string
315
+ lang: string
316
+ }
317
+
318
+ interface CanvasFilters {
319
+ filter: string
320
+ }
321
+
322
+ interface CanvasFillStrokeStyles {
323
+ fillStyle: string | CanvasGradient | CanvasPattern
324
+ strokeStyle: string | CanvasGradient | CanvasPattern
325
+ createConicGradient(startAngle: number, x: number, y: number): CanvasGradient
326
+ createLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasGradient
327
+ createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): CanvasGradient
328
+ }
329
+
330
+ type CanvasFillRule = 'evenodd' | 'nonzero'
331
+
332
+ interface CanvasDrawPath {
333
+ beginPath(): void
334
+ clip(fillRule?: CanvasFillRule): void
335
+ clip(path: Path2D, fillRule?: CanvasFillRule): void
336
+ fill(fillRule?: CanvasFillRule): void
337
+ fill(path: Path2D, fillRule?: CanvasFillRule): void
338
+ isPointInPath(x: number, y: number, fillRule?: CanvasFillRule): boolean
339
+ isPointInPath(path: Path2D, x: number, y: number, fillRule?: CanvasFillRule): boolean
340
+ isPointInStroke(x: number, y: number): boolean
341
+ isPointInStroke(path: Path2D, x: number, y: number): boolean
342
+ stroke(): void
343
+ stroke(path: Path2D): void
344
+ }
345
+
346
+ type GlobalCompositeOperation =
347
+ | 'color'
348
+ | 'color-burn'
349
+ | 'color-dodge'
350
+ | 'copy'
351
+ | 'darken'
352
+ | 'destination-atop'
353
+ | 'destination-in'
354
+ | 'destination-out'
355
+ | 'destination-over'
356
+ | 'difference'
357
+ | 'exclusion'
358
+ | 'hard-light'
359
+ | 'hue'
360
+ | 'lighten'
361
+ | 'lighter'
362
+ | 'luminosity'
363
+ | 'multiply'
364
+ | 'overlay'
365
+ | 'saturation'
366
+ | 'screen'
367
+ | 'soft-light'
368
+ | 'source-atop'
369
+ | 'source-in'
370
+ | 'source-out'
371
+ | 'source-over'
372
+ | 'xor'
373
+
374
+ interface CanvasCompositing {
375
+ globalAlpha: number
376
+ globalCompositeOperation: GlobalCompositeOperation
377
+ }
378
+
379
+ interface DOMPointInit {
380
+ w?: number
381
+ x?: number
382
+ y?: number
383
+ z?: number
384
+ }
385
+ interface CanvasPattern {
386
+ /** Missing members default to the identity; `a` and `m11` (and so on) must agree when both are given. */
387
+ setTransform(
388
+ transform?: Partial<DOMMatrix2DInit> & {
389
+ m11?: number
390
+ m12?: number
391
+ m21?: number
392
+ m22?: number
393
+ m41?: number
394
+ m42?: number
395
+ },
396
+ ): void
397
+ }
398
+
399
+ interface CanvasGradient {
400
+ addColorStop(offset: number, color: string): void
401
+ }
402
+
403
+ interface DOMRectInit {
404
+ height?: number
405
+ width?: number
406
+ x?: number
407
+ y?: number
408
+ }
409
+
410
+ interface DOMMatrixInit extends DOMMatrix2DInit {
411
+ is2D?: boolean
412
+ m13?: number
413
+ m14?: number
414
+ m23?: number
415
+ m24?: number
416
+ m31?: number
417
+ m32?: number
418
+ m33?: number
419
+ m34?: number
420
+ m43?: number
421
+ m44?: number
422
+ }
423
+
424
+ // ----------- added types
425
+
426
+ export interface DOMMatrix2DInit {
427
+ a: number
428
+ b: number
429
+ c: number
430
+ d: number
431
+ e: number
432
+ f: number
433
+ }
434
+
435
+ interface DOMMatrixReadOnly {
436
+ readonly a: number
437
+ readonly b: number
438
+ readonly c: number
439
+ readonly d: number
440
+ readonly e: number
441
+ readonly f: number
442
+ readonly is2D: boolean
443
+ readonly isIdentity: boolean
444
+ readonly m11: number
445
+ readonly m12: number
446
+ readonly m13: number
447
+ readonly m14: number
448
+ readonly m21: number
449
+ readonly m22: number
450
+ readonly m23: number
451
+ readonly m24: number
452
+ readonly m31: number
453
+ readonly m32: number
454
+ readonly m33: number
455
+ readonly m34: number
456
+ readonly m41: number
457
+ readonly m42: number
458
+ readonly m43: number
459
+ readonly m44: number
460
+ flipX(): DOMMatrix
461
+ flipY(): DOMMatrix
462
+ inverse(): DOMMatrix
463
+ multiply(other?: DOMMatrixInit): DOMMatrix
464
+ rotate(rotX?: number, rotY?: number, rotZ?: number): DOMMatrix
465
+ rotateAxisAngle(x?: number, y?: number, z?: number, angle?: number): DOMMatrix
466
+ rotateFromVector(x?: number, y?: number): DOMMatrix
467
+ scale(
468
+ scaleX?: number,
469
+ scaleY?: number,
470
+ scaleZ?: number,
471
+ originX?: number,
472
+ originY?: number,
473
+ originZ?: number,
474
+ ): DOMMatrix
475
+ scale3d(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix
476
+ skewX(sx?: number): DOMMatrix
477
+ skewY(sy?: number): DOMMatrix
478
+ toFloat32Array(): Float32Array
479
+ toFloat64Array(): Float64Array
480
+ transformPoint(point?: DOMPointInit): DOMPoint
481
+ translate(tx?: number, ty?: number, tz?: number): DOMMatrix
482
+ toString(): string
483
+ }
484
+
485
+ export interface DOMMatrix extends DOMMatrixReadOnly {
486
+ a: number
487
+ b: number
488
+ c: number
489
+ d: number
490
+ e: number
491
+ f: number
492
+ m11: number
493
+ m12: number
494
+ m13: number
495
+ m14: number
496
+ m21: number
497
+ m22: number
498
+ m23: number
499
+ m24: number
500
+ m31: number
501
+ m32: number
502
+ m33: number
503
+ m34: number
504
+ m41: number
505
+ m42: number
506
+ m43: number
507
+ m44: number
508
+ invertSelf(): DOMMatrix
509
+ multiplySelf(other?: DOMMatrixInit): DOMMatrix
510
+ preMultiplySelf(other?: DOMMatrixInit): DOMMatrix
511
+ rotateAxisAngleSelf(x?: number, y?: number, z?: number, angle?: number): DOMMatrix
512
+ rotateFromVectorSelf(x?: number, y?: number): DOMMatrix
513
+ rotateSelf(rotX?: number, rotY?: number, rotZ?: number): DOMMatrix
514
+ scale3dSelf(scale?: number, originX?: number, originY?: number, originZ?: number): DOMMatrix
515
+ scaleSelf(
516
+ scaleX?: number,
517
+ scaleY?: number,
518
+ scaleZ?: number,
519
+ originX?: number,
520
+ originY?: number,
521
+ originZ?: number,
522
+ ): DOMMatrix
523
+ setMatrixValue(transformList: string): DOMMatrix
524
+ skewXSelf(sx?: number): DOMMatrix
525
+ skewYSelf(sy?: number): DOMMatrix
526
+ translateSelf(tx?: number, ty?: number, tz?: number): DOMMatrix
527
+ toJSON(): { [K in OmitNeverOfMatrix]: DOMMatrix[K] }
528
+ }
529
+
530
+ type OmitMatrixMethod = { [K in keyof DOMMatrix]: DOMMatrix[K] extends (...args: any[]) => any ? never : K }
531
+
532
+ type OmitNeverOfMatrix = OmitMatrixMethod[keyof OmitMatrixMethod]
533
+
534
+ export const DOMMatrix: {
535
+ prototype: DOMMatrix
536
+ new(init?: string | number[]): DOMMatrix
537
+ fromFloat32Array(array32: Float32Array): DOMMatrix
538
+ fromFloat64Array(array64: Float64Array): DOMMatrix
539
+ fromMatrix(other?: DOMMatrixInit): DOMMatrix
540
+ }
541
+
542
+ interface DOMRectReadOnly {
543
+ readonly bottom: number
544
+ readonly height: number
545
+ readonly left: number
546
+ readonly right: number
547
+ readonly top: number
548
+ readonly width: number
549
+ readonly x: number
550
+ readonly y: number
551
+ }
552
+
553
+ export interface DOMRect extends DOMRectReadOnly {
554
+ height: number
555
+ width: number
556
+ x: number
557
+ y: number
558
+ toJSON(): Omit<this, 'toJSON' | 'fromRect'>
559
+ }
560
+
561
+ export const DOMRect: {
562
+ prototype: DOMRect
563
+ new(x?: number, y?: number, width?: number, height?: number): DOMRect
564
+ fromRect(other?: DOMRectInit): DOMRect
565
+ }
566
+
567
+ interface DOMPointReadOnly {
568
+ readonly w: number
569
+ readonly x: number
570
+ readonly y: number
571
+ readonly z: number
572
+ matrixTransform(matrix?: DOMMatrixInit): DOMPoint
573
+ }
574
+
575
+ export interface DOMPoint extends DOMPointReadOnly {
576
+ w: number
577
+ x: number
578
+ y: number
579
+ z: number
580
+ toJSON(): Omit<DOMPoint, 'matrixTransform' | 'toJSON'>
581
+ }
582
+
583
+ export const DOMPoint: {
584
+ prototype: DOMPoint
585
+ new(x?: number, y?: number, z?: number, w?: number): DOMPoint
586
+ fromPoint(other?: DOMPointInit): DOMPoint
587
+ }
588
+
589
+ export class ImageData<T extends ImageDataArray = Uint8ClampedArray> {
590
+ /**
591
+ * Returns the one-dimensional array containing the data in RGBA order: integers in the range 0 to 255 for
592
+ * 'rgba-unorm8', unpremultiplied floats for 'rgba-float16' and 'rgba-float32'.
593
+ */
594
+ readonly data: T
595
+ /**
596
+ * Returns the actual dimensions of the data in the ImageData object, in pixels.
597
+ */
598
+ readonly height: number
599
+ /**
600
+ * Returns the actual dimensions of the data in the ImageData object, in pixels.
601
+ */
602
+ readonly width: number
603
+ readonly colorSpace: PredefinedColorSpace
604
+ readonly pixelFormat: ImageDataPixelFormat
605
+
606
+ /** Pass the data type for a float pixelFormat: `new ImageData<Float32Array>(w, h, { pixelFormat: 'rgba-float32' })`. */
607
+ constructor(sw: number, sh: number, settings?: ImageDataSettings)
608
+ /** The pixelFormat must match the data type. */
609
+ constructor(data: T, sw: number, sh?: number, settings?: ImageDataSettings)
610
+ }
611
+
612
+ export class Image {
613
+ constructor()
614
+ // attrs only affects SVG
615
+ constructor(width: number, height: number, attrs?: { colorSpace?: ColorSpace })
616
+ width: number
617
+ height: number
618
+ readonly naturalWidth: number
619
+ readonly naturalHeight: number
620
+ readonly complete: boolean
621
+ readonly currentSrc: string | null
622
+ alt: string
623
+ // the src can be a Uint8Array or a string
624
+ // if it's a string, it can be a file path, a data URL, a remote URL, or a SVG string
625
+ src: Uint8Array | string
626
+ onload?(): void
627
+ /** Called with an Event of type 'error', as in browsers. */
628
+ onerror?(event: Event): void
629
+ /** Rejects with an EncodingError DOMException when the image cannot be decoded. */
630
+ decode(): Promise<void>
631
+ }
632
+
633
+ export class Path2D {
634
+ constructor(path?: Path2D | string)
635
+
636
+ /** Missing members default to the identity; `a` and `m11` (and so on) must agree when both are given. */
637
+ addPath(
638
+ path: Path2D,
639
+ transform?: Partial<DOMMatrix2DInit> & {
640
+ m11?: number
641
+ m12?: number
642
+ m21?: number
643
+ m22?: number
644
+ m41?: number
645
+ m42?: number
646
+ },
647
+ ): void
648
+ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): void
649
+ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void
650
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void
651
+ closePath(): void
652
+ ellipse(
653
+ x: number,
654
+ y: number,
655
+ radiusX: number,
656
+ radiusY: number,
657
+ rotation: number,
658
+ startAngle: number,
659
+ endAngle: number,
660
+ anticlockwise?: boolean,
661
+ ): void
662
+ lineTo(x: number, y: number): void
663
+ moveTo(x: number, y: number): void
664
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void
665
+ rect(x: number, y: number, w: number, h: number): void
666
+ roundRect(
667
+ x: number,
668
+ y: number,
669
+ w: number,
670
+ h: number,
671
+ radii?: number | DOMPointInit | Iterable<number | DOMPointInit>,
672
+ ): void
673
+
674
+ // PathKit methods
675
+ op(path: Path2D, operation: PathOp): Path2D
676
+ toSVGString(): string
677
+ getFillType(): FillType
678
+ getFillTypeString(): string
679
+ setFillType(type: FillType): void
680
+ simplify(): Path2D
681
+ asWinding(): Path2D
682
+ stroke(stroke?: StrokeOptions): Path2D
683
+ transform(transform: DOMMatrix2DInit): Path2D
684
+ getBounds(): [left: number, top: number, right: number, bottom: number]
685
+ computeTightBounds(): [left: number, top: number, right: number, bottom: number]
686
+ trim(start: number, end: number, isComplement?: boolean): Path2D
687
+ dash(on: number, off: number, phase: number): Path2D
688
+ round(radius: number): Path2D
689
+ equals(path: Path2D): boolean
690
+ }
691
+
692
+ export interface StrokeOptions {
693
+ width?: number
694
+ miterLimit?: number
695
+ cap?: StrokeCap
696
+ join?: StrokeJoin
697
+ }
698
+
699
+ export interface SKRSContext2D extends CanvasRenderingContext2D {
700
+ readonly canvas: Canvas
701
+ /**
702
+ * @param startAngle The angle at which to begin the gradient, in radians. Angle measurements start vertically above the centre and move around clockwise.
703
+ * @param x The x-axis coordinate of the centre of the gradient.
704
+ * @param y The y-axis coordinate of the centre of the gradient.
705
+ */
706
+ createConicGradient(startAngle: number, x: number, y: number): CanvasGradient
707
+ drawImage(image: Image | Canvas | SvgCanvas, dx: number, dy: number): void
708
+ drawImage(image: Image | Canvas | SvgCanvas, dx: number, dy: number, dw: number, dh: number): void
709
+ drawImage(
710
+ image: Image | Canvas | SvgCanvas,
711
+ sx: number,
712
+ sy: number,
713
+ sw: number,
714
+ sh: number,
715
+ dx: number,
716
+ dy: number,
717
+ dw: number,
718
+ dh: number,
719
+ ): void
720
+ /**
721
+ * Draw another canvas, preserving vector graphics when possible.
722
+ * When the source canvas has recorded operations, this method preserves the
723
+ * SkPicture representation without rasterization, which can be faster than
724
+ * drawImage. Falls back to bitmap rendering if no picture is available.
725
+ */
726
+ drawCanvas(canvas: Canvas, dx: number, dy: number): void
727
+ drawCanvas(canvas: Canvas, dx: number, dy: number, dWidth: number, dHeight: number): void
728
+ drawCanvas(
729
+ canvas: Canvas,
730
+ sx: number,
731
+ sy: number,
732
+ sWidth: number,
733
+ sHeight: number,
734
+ dx: number,
735
+ dy: number,
736
+ dWidth: number,
737
+ dHeight: number,
738
+ ): void
739
+ /** null when `image` is an Image with no src or one that is still loading. */
740
+ createPattern(
741
+ image: Image | ImageData<ImageDataArray> | Canvas | SvgCanvas,
742
+ repeat: 'repeat' | 'repeat-x' | 'repeat-y' | 'no-repeat' | '' | null,
743
+ ): CanvasPattern | null
744
+ getContextAttributes(): Required<CanvasRenderingContext2DSettings>
745
+ getTransform(): DOMMatrix
746
+
747
+ letterSpacing: string
748
+ wordSpacing: string
749
+ /**
750
+ * Non-standard: Chrome's CanvasRenderingContext2D has no such attribute.
751
+ * Behaves like the CSS `font-feature-settings` property in Chrome.
752
+ * Invalid values are ignored. Default `"normal"`.
753
+ * @experimental
754
+ */
755
+ fontFeatureSettings: string
756
+ /**
757
+ * Non-standard: Chrome's CanvasRenderingContext2D has no such attribute.
758
+ * Behaves like the CSS `font-variant-ligatures` property in Chrome.
759
+ * Invalid values are ignored. Default `"normal"`.
760
+ * @experimental
761
+ */
762
+ fontVariantLigatures: string
763
+ /**
764
+ * Non-standard: Chrome's CanvasRenderingContext2D has no such attribute.
765
+ * Behaves like the CSS `font-variant-numeric` property in Chrome.
766
+ * Invalid values are ignored. Default `"normal"`.
767
+ * @experimental
768
+ */
769
+ fontVariantNumeric: string
770
+ /**
771
+ * Non-standard: Chrome's CanvasRenderingContext2D has no such attribute.
772
+ * Behaves like the CSS `font-variant-position` property in Chrome.
773
+ * Invalid values are ignored. Default `"normal"`.
774
+ * @experimental
775
+ */
776
+ fontVariantPosition: 'normal' | 'sub' | 'super'
777
+ /**
778
+ * Non-standard: Chrome's CanvasRenderingContext2D has no such attribute.
779
+ * Behaves like the CSS `font-size-adjust` property in Chrome.
780
+ * Invalid values are ignored. Default `"none"`.
781
+ * @experimental
782
+ */
783
+ fontSizeAdjust: string
784
+ /**
785
+ * Non-standard: Chrome's CanvasRenderingContext2D has no such attribute.
786
+ * Behaves like the CSS `font-optical-sizing` property in Chrome.
787
+ * Invalid values are ignored. Default `"auto"`.
788
+ * @experimental
789
+ */
790
+ fontOpticalSizing: 'auto' | 'none'
791
+ }
792
+
793
+ export type ColorSpace = 'srgb' | 'display-p3'
794
+
795
+ export interface ContextAttributes extends CanvasRenderingContext2DSettings {}
796
+
797
+ export interface SvgCanvas {
798
+ width: number
799
+ height: number
800
+ /**
801
+ * Returns null for an id other than '2d', as browsers do for an unsupported id.
802
+ * Declared before the '2d' overload, so `ReturnType` still gives the context.
803
+ */
804
+ getContext<T extends string>(
805
+ contextType: T extends '2d' ? never : T,
806
+ contextAttributes?: ContextAttributes,
807
+ ): SKRSContext2D | null
808
+ getContext(contextType: '2d', contextAttributes?: ContextAttributes): SKRSContext2D
809
+
810
+ getContent(): Buffer
811
+ }
812
+
813
+ export interface AvifConfig {
814
+ /**
815
+ * 0-100 scale, 100 is the best quality. 100 with 4:4:4 (the default) is
816
+ * lossless: R, G and B are coded as they are (CICP matrix 0, identity).
817
+ * Below 100, or with chroma subsampling, the pixels are lossy BT.601 YUV.
818
+ * Default 80.
819
+ */
820
+ quality?: number
821
+ /** 0-100 scale. Default 100 when `quality` is 100 (lossless alpha), else 90. */
822
+ alphaQuality?: number
823
+ /**
824
+ * aom encoder speed from 0 (slowest, smallest file) to 10 (fastest);
825
+ * larger values are 10. Default 5.
826
+ */
827
+ speed?: number
828
+ /** How many threads to use: 0 or unset is one per CPU core; at most 64. */
829
+ threads?: number
830
+ /** set to '4:2:0' to use chroma subsampling, default '4:4:4' */
831
+ chromaSubsampling?: ChromaSubsampling
832
+ }
833
+
834
+ /**
835
+ * Metadata that `toBuffer`, `encode` and `encodeSync` write into PNG and JPEG
836
+ * output. It goes in the same options object as the other options. WebP, AVIF
837
+ * and GIF output ignore it. `toDataURL`, `toDataURLAsync`, `toBlob`,
838
+ * `convertToBlob`, `encodeStream` and `savePng` never write it.
839
+ *
840
+ * Nothing is converted, as in node-canvas: a member counts only when it is a
841
+ * number (`resolution`) or a string (the text members). Any other value is
842
+ * ignored. U+0000 is removed from text, and text that is then empty writes
843
+ * nothing. In JPEG, the XMP text must fit in one 64 KB segment (about 65000
844
+ * bytes of UTF-8 in all) and `comment` in 65533 UTF-8 bytes; more is a
845
+ * RangeError. PNG text has no such limit.
846
+ */
847
+ export interface ImageMetadata {
848
+ /**
849
+ * Pixels per inch for both axes, as node-canvas's `PngConfig.resolution`.
850
+ * The fraction is dropped (300.9 is 300). A value below 1, NaN and the
851
+ * infinities write nothing.
852
+ * - PNG: a `pHYs` chunk of `Math.round(ppi * 39.3701)` pixels per metre (the
853
+ * bytes node-canvas writes), at most 2147483647.
854
+ * - JPEG: the JFIF density in dots per inch, at most 65535.
855
+ */
856
+ resolution?: number
857
+ /** PNG `Title` text chunk; JPEG XMP `dc:title`. */
858
+ title?: string
859
+ /** PNG `Author` text chunk; JPEG XMP `dc:creator`. */
860
+ author?: string
861
+ /** PNG `Description` text chunk; JPEG XMP `dc:description`. */
862
+ description?: string
863
+ /** PNG `Copyright` text chunk; JPEG XMP `dc:rights`. */
864
+ copyright?: string
865
+ /** PNG `Software` text chunk; JPEG XMP `xmp:CreatorTool`. */
866
+ software?: string
867
+ /** PNG `Comment` text chunk; JPEG `COM` segment. */
868
+ comment?: string
869
+ }
870
+
871
+ /** The object form of `encode('jpeg')` and `encodeSync('jpeg')`: a quality and metadata. */
872
+ export interface JpegEncodeOptions extends ImageMetadata {
873
+ /** 0-100; a larger value is 100. Default 92. */
874
+ quality?: number
875
+ }
876
+
877
+ /** GIF encoding configuration for single-frame encoding */
878
+ export interface GifConfig {
879
+ /**
880
+ * Quality for NeuQuant color quantization (1-30, lower = slower but better quality)
881
+ * @default 10
882
+ */
883
+ quality?: number
884
+ }
885
+
886
+ /** Configuration for the GIF encoder (animated GIFs) */
887
+ export interface GifEncoderConfig {
888
+ /**
889
+ * Loop count: 0 = infinite loop, positive number = finite loops
890
+ * @default 0 (infinite)
891
+ */
892
+ repeat?: number
893
+ /**
894
+ * Quality for NeuQuant color quantization (1-30, lower = slower but better quality)
895
+ * @default 10
896
+ */
897
+ quality?: number
898
+ }
899
+
900
+ /** Configuration for individual GIF frames */
901
+ export interface GifFrameConfig {
902
+ /**
903
+ * Frame delay in milliseconds
904
+ * @default 100
905
+ */
906
+ delay?: number
907
+ /** Disposal method for this frame */
908
+ disposal?: GifDisposal
909
+ /** Transparent color index (0-255), if the frame has transparency */
910
+ transparent?: number
911
+ /** X offset of this frame within the canvas */
912
+ left?: number
913
+ /** Y offset of this frame within the canvas */
914
+ top?: number
915
+ }
916
+
917
+ /** GIF frame disposal method */
918
+ export enum GifDisposal {
919
+ /** Keep the frame visible (default) */
920
+ Keep = 0,
921
+ /** Clear the frame area to the background color */
922
+ Background = 1,
923
+ /** Restore to the previous frame */
924
+ Previous = 2,
925
+ }
926
+
927
+ /**
928
+ * GIF Encoder for creating animated GIFs.
929
+ * Implements `Disposable` interface for use with the `using` keyword (ES2024).
930
+ *
931
+ * @example
932
+ * ```typescript
933
+ * // Basic usage
934
+ * const encoder = new GifEncoder(100, 100, { repeat: 0, quality: 10 });
935
+ * encoder.addFrame(rgbaData, 100, 100, { delay: 100 });
936
+ * encoder.addFrame(rgbaData2, 100, 100, { delay: 100 });
937
+ * const buffer = encoder.finish();
938
+ *
939
+ * // With `using` keyword (automatic cleanup)
940
+ * {
941
+ * using encoder = new GifEncoder(100, 100);
942
+ * encoder.addFrame(frame1, 100, 100, { delay: 100 });
943
+ * const buffer = encoder.finish();
944
+ * } // encoder automatically disposed
945
+ * ```
946
+ */
947
+ export class GifEncoder implements Disposable {
948
+ /**
949
+ * Create a new GIF encoder with the specified dimensions
950
+ * @param width - Width of the GIF canvas in pixels
951
+ * @param height - Height of the GIF canvas in pixels
952
+ * @param config - Optional encoder configuration
953
+ */
954
+ constructor(width: number, height: number, config?: GifEncoderConfig)
955
+
956
+ /** Width of the GIF canvas */
957
+ readonly width: number
958
+ /** Height of the GIF canvas */
959
+ readonly height: number
960
+ /** Number of frames added so far */
961
+ readonly frameCount: number
962
+
963
+ /**
964
+ * Add a frame from RGBA pixel data
965
+ * @param data - RGBA pixel data (must be width * height * 4 bytes)
966
+ * @param width - Width of the frame in pixels
967
+ * @param height - Height of the frame in pixels
968
+ * @param config - Optional frame configuration
969
+ */
970
+ addFrame(data: Uint8Array, width: number, height: number, config?: GifFrameConfig): void
971
+
972
+ /**
973
+ * Finish encoding and return the GIF data.
974
+ * Clears all accumulated frames after encoding.
975
+ * @throws Error if no frames have been added
976
+ */
977
+ finish(): Buffer
978
+
979
+ /**
980
+ * Dispose of the encoder, clearing all accumulated frames without encoding.
981
+ * Called automatically when using the `using` keyword.
982
+ */
983
+ dispose(): void
984
+
985
+ /**
986
+ * Symbol.dispose implementation for ES2024 Explicit Resource Management.
987
+ * Allows using `using encoder = new GifEncoder(...)` syntax.
988
+ */
989
+ [Symbol.dispose](): void
990
+ }
991
+ /**
992
+ * https://en.wikipedia.org/wiki/Chroma_subsampling#Types_of_sampling_and_subsampling
993
+ * https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_concepts
994
+ */
995
+ export enum ChromaSubsampling {
996
+ /**
997
+ * Each of the three Y'CbCr components has the same sample rate, thus there is no chroma subsampling. This scheme is sometimes used in high-end film scanners and cinematic post-production.
998
+ * Note that "4:4:4" may instead be wrongly referring to R'G'B' color space, which implicitly also does not have any chroma subsampling (except in JPEG R'G'B' can be subsampled).
999
+ * Formats such as HDCAM SR can record 4:4:4 R'G'B' over dual-link HD-SDI.
1000
+ */
1001
+ Yuv444 = 0,
1002
+ /**
1003
+ * The two chroma components are sampled at half the horizontal sample rate of luma: the horizontal chroma resolution is halved. This reduces the bandwidth of an uncompressed video signal by one-third.
1004
+ * Many high-end digital video formats and interfaces use this scheme:
1005
+ * - [AVC-Intra 100](https://en.wikipedia.org/wiki/AVC-Intra)
1006
+ * - [Digital Betacam](https://en.wikipedia.org/wiki/Betacam#Digital_Betacam)
1007
+ * - [Betacam SX](https://en.wikipedia.org/wiki/Betacam#Betacam_SX)
1008
+ * - [DVCPRO50](https://en.wikipedia.org/wiki/DV#DVCPRO) and [DVCPRO HD](https://en.wikipedia.org/wiki/DV#DVCPRO_HD)
1009
+ * - [Digital-S](https://en.wikipedia.org/wiki/Digital-S)
1010
+ * - [CCIR 601](https://en.wikipedia.org/wiki/Rec._601) / [Serial Digital Interface](https://en.wikipedia.org/wiki/Serial_digital_interface) / [D1](https://en.wikipedia.org/wiki/D-1_(Sony))
1011
+ * - [ProRes (HQ, 422, LT, and Proxy)](https://en.wikipedia.org/wiki/Apple_ProRes)
1012
+ * - [XDCAM HD422](https://en.wikipedia.org/wiki/XDCAM)
1013
+ * - [Canon MXF HD422](https://en.wikipedia.org/wiki/Canon_XF-300)
1014
+ */
1015
+ Yuv422 = 1,
1016
+ /**
1017
+ * n 4:2:0, the horizontal sampling is doubled compared to 4:1:1,
1018
+ * but as the **Cb** and **Cr** channels are only sampled on each alternate line in this scheme, the vertical resolution is halved.
1019
+ * The data rate is thus the same.
1020
+ * This fits reasonably well with the PAL color encoding system, since this has only half the vertical chrominance resolution of [NTSC](https://en.wikipedia.org/wiki/NTSC).
1021
+ * It would also fit extremely well with the [SECAM](https://en.wikipedia.org/wiki/SECAM) color encoding system,
1022
+ * since like that format, 4:2:0 only stores and transmits one color channel per line (the other channel being recovered from the previous line).
1023
+ * However, little equipment has actually been produced that outputs a SECAM analogue video signal.
1024
+ * In general, SECAM territories either have to use a PAL-capable display or a [transcoder](https://en.wikipedia.org/wiki/Transcoding) to convert the PAL signal to SECAM for display.
1025
+ */
1026
+ Yuv420 = 2,
1027
+ /**
1028
+ * What if the chroma subsampling model is 4:0:0?
1029
+ * That says to use every pixel of luma data, but that each row has 0 chroma samples applied to it. The resulting image, then, is comprised solely of the luminance data—a greyscale image.
1030
+ */
1031
+ Yuv400 = 3,
1032
+ }
1033
+
1034
+ /** OffscreenCanvas ImageEncodeOptions. */
1035
+ export interface ConvertToBlobOptions {
1036
+ /** Default 'image/png'; ASCII case-insensitive, and an unknown type is PNG. */
1037
+ type?: string
1038
+ /** 0 to 1 for JPEG, WebP (1 is lossless), AVIF and GIF. Default 1. */
1039
+ quality?: number
1040
+ }
1041
+
1042
+ export class Canvas {
1043
+ /**
1044
+ * A missing width or height is the default, 300 x 150, as is NaN, an infinity
1045
+ * or a non-zero number that converts to 0 (such as 0.5). 0 stays 0.
1046
+ */
1047
+ constructor(width?: number, height?: number, flag?: SvgExportFlag)
1048
+
1049
+ width: number
1050
+ height: number
1051
+ /**
1052
+ * Returns null for an id other than '2d', as browsers do for an unsupported id.
1053
+ * Declared before the '2d' overload, so `ReturnType` still gives the context.
1054
+ */
1055
+ getContext<T extends string>(
1056
+ contextType: T extends '2d' ? never : T,
1057
+ contextAttributes?: ContextAttributes,
1058
+ ): SKRSContext2D | null
1059
+ getContext(contextType: '2d', contextAttributes?: ContextAttributes): SKRSContext2D
1060
+ encodeSync(format: 'webp' | 'jpeg', quality?: number): Buffer
1061
+ encodeSync(format: 'jpeg', options: JpegEncodeOptions): Buffer
1062
+ encodeSync(format: 'png', options?: ImageMetadata): Buffer
1063
+ encodeSync(format: 'avif', cfg?: AvifConfig | number): Buffer
1064
+ encodeSync(format: 'gif', quality?: number): Buffer
1065
+ encode(format: 'webp' | 'jpeg', quality?: number): Promise<Buffer>
1066
+ encode(format: 'jpeg', options: JpegEncodeOptions): Promise<Buffer>
1067
+ encode(format: 'png', options?: ImageMetadata): Promise<Buffer>
1068
+ encode(format: 'avif', cfg?: AvifConfig | number): Promise<Buffer>
1069
+ encode(format: 'gif', quality?: number): Promise<Buffer>
1070
+ /** Writes no image metadata; use `encode` and stream the Buffer for that. */
1071
+ encodeStream(format: 'webp' | 'jpeg', quality?: number): ReadableStream<Buffer>
1072
+ encodeStream(format: 'png'): ReadableStream<Buffer>
1073
+ toBuffer(mime: 'image/png', options?: ImageMetadata): Buffer
1074
+ toBuffer(mime: 'image/jpeg' | 'image/webp', quality?: number): Buffer
1075
+ /**
1076
+ * JPEG with metadata, at quality 92: toBuffer does not read a quality from an
1077
+ * object. To set both, use `encodeSync('jpeg', { quality, ...metadata })`.
1078
+ */
1079
+ toBuffer(mime: 'image/jpeg', options: ImageMetadata): Buffer
1080
+ toBuffer(mime: 'image/avif', cfg?: AvifConfig | number): Buffer
1081
+ toBuffer(mime: 'image/gif', quality?: number): Buffer
1082
+ /** The stored pixels, premultiplied: RGBA bytes, or RGBA half floats (8 bytes a pixel) for colorType 'float16'. */
1083
+ data(): Buffer
1084
+ toDataURL(mime?: 'image/png'): string
1085
+ toDataURL(mime: 'image/jpeg' | 'image/webp', quality?: number): string
1086
+ toDataURL(mime: 'image/gif', quality?: number): string
1087
+ toDataURL(mime?: 'image/jpeg' | 'image/webp' | 'image/png' | 'image/gif', quality?: number): string
1088
+ toDataURL(mime?: 'image/avif', cfg?: AvifConfig | number): string
1089
+ /**
1090
+ * As in browsers: the type is ASCII case-insensitive and an unknown one is
1091
+ * PNG; the quality counts when it is a number from 0 to 1.
1092
+ */
1093
+ toDataURL(type?: string, quality?: any): string
1094
+
1095
+ toDataURLAsync(mime?: 'image/png'): Promise<string>
1096
+ toDataURLAsync(mime: 'image/jpeg' | 'image/webp', quality?: number): Promise<string>
1097
+ toDataURLAsync(mime: 'image/gif', quality?: number): Promise<string>
1098
+ toDataURLAsync(mime?: 'image/jpeg' | 'image/webp' | 'image/png' | 'image/gif', quality?: number): Promise<string>
1099
+ toDataURLAsync(mime?: 'image/avif', cfg?: AvifConfig | number): Promise<string>
1100
+ toDataURLAsync(type?: string, quality?: any): Promise<string>
1101
+
1102
+ toBlob(callback: (blob: Blob | null) => void, type?: string, quality?: any): void
1103
+ convertToBlob(options?: ConvertToBlobOptions): Promise<Blob>
1104
+ }
1105
+
1106
+ /**
1107
+ * A missing width or height is the default, 300 x 150, as is NaN, an infinity
1108
+ * or a non-zero number that converts to 0 (such as 0.5). 0 stays 0.
1109
+ */
1110
+ export function createCanvas(width?: number, height?: number): Canvas
1111
+
1112
+ export function createCanvas(width: number, height: number, svgExportFlag: SvgExportFlag): SvgCanvas
1113
+
1114
+ export declare class FontKey {
1115
+ // make it a unique type
1116
+ private readonly key: symbol
1117
+ readonly typefaceId: number
1118
+ }
1119
+
1120
+ export interface FontVariationAxis {
1121
+ /** OpenType tag as a 32-bit integer (e.g., 0x77676874 for 'wght') */
1122
+ tag: number
1123
+ /** Current value for this axis */
1124
+ value: number
1125
+ /** Minimum value for this axis */
1126
+ min: number
1127
+ /** Maximum value for this axis */
1128
+ max: number
1129
+ /** Default value for this axis */
1130
+ def: number
1131
+ /** Whether this axis should be hidden from UI */
1132
+ hidden: boolean
1133
+ }
1134
+
1135
+ interface IGlobalFonts {
1136
+ readonly families: { family: string; styles: { weight: number; width: string; style: string }[] }[]
1137
+ // return FontKey if succeeded, null if failed
1138
+ register(font: Buffer, nameAlias?: string): FontKey | null
1139
+ // absolute path - returns FontKey if succeeded, null if failed
1140
+ registerFromPath(path: string, nameAlias?: string): FontKey | null
1141
+ has(name: string): boolean
1142
+ loadFontsFromDir(path: string): number
1143
+ /**
1144
+ * Set an alias for a font family.
1145
+ * @param fontName The original font family name
1146
+ * @param alias The alias name to set
1147
+ * @returns true if the alias was set successfully, false if the font family doesn't exist
1148
+ */
1149
+ setAlias(fontName: string, alias: string): boolean
1150
+ remove(key: FontKey): boolean
1151
+ /**
1152
+ * Remove multiple fonts by their keys in a single operation.
1153
+ * More efficient than calling remove() multiple times as it triggers only one rebuild.
1154
+ * @param fontKeys Array of FontKey objects to remove
1155
+ * @returns Number of fonts successfully removed
1156
+ */
1157
+ removeBatch(fontKeys: FontKey[]): number
1158
+ /**
1159
+ * Remove ALL registered fonts.
1160
+ * @returns Number of fonts removed
1161
+ */
1162
+ removeAll(): number
1163
+ /**
1164
+ * Get variation axes for a specific font instance
1165
+ * @param familyName The font family name
1166
+ * @param weight Font weight (100-900)
1167
+ * @param width Font width/stretch value
1168
+ * @param slant Font slant (0 = upright, 1 = italic, 2 = oblique)
1169
+ * @returns Array of variation axes or empty array if not a variable font
1170
+ */
1171
+ getVariationAxes(familyName: string, weight: number, width: number, slant: number): FontVariationAxis[]
1172
+ /**
1173
+ * Check if a font has variable font capabilities
1174
+ * @param familyName The font family name
1175
+ * @param weight Font weight (100-900)
1176
+ * @param width Font width/stretch value
1177
+ * @param slant Font slant (0 = upright, 1 = italic, 2 = oblique)
1178
+ * @returns true if the font is a variable font
1179
+ */
1180
+ hasVariations(familyName: string, weight: number, width: number, slant: number): boolean
1181
+ }
1182
+
1183
+ export const GlobalFonts: IGlobalFonts
1184
+
1185
+ export enum PathOp {
1186
+ Difference = 0, // subtract the op path from the first path
1187
+ Intersect = 1, // intersect the two paths
1188
+ Union = 2, // union (inclusive-or) the two paths
1189
+ Xor = 3, // exclusive-or the two paths
1190
+ ReverseDifference = 4, // subtract the first path from the op path
1191
+ }
1192
+
1193
+ export enum FillType {
1194
+ Winding = 0,
1195
+ EvenOdd = 1,
1196
+ InverseWinding = 2,
1197
+ InverseEvenOdd = 3,
1198
+ }
1199
+
1200
+ export enum StrokeJoin {
1201
+ Miter = 0,
1202
+ Round = 1,
1203
+ Bevel = 2,
1204
+ }
1205
+
1206
+ export enum StrokeCap {
1207
+ Butt = 0,
1208
+ Round = 1,
1209
+ Square = 2,
1210
+ }
1211
+
1212
+ export enum SvgExportFlag {
1213
+ ConvertTextToPaths = 0x01,
1214
+ NoPrettyXML = 0x02,
1215
+ RelativePathEncoding = 0x04,
1216
+ }
1217
+
1218
+ export function convertSVGTextToPath(svg: Buffer | string): Buffer
1219
+
1220
+ export interface LoadImageOptions {
1221
+ alt?: string
1222
+ maxRedirects?: number
1223
+ requestOptions?: import('http').RequestOptions
1224
+ }
1225
+
1226
+ export function loadImage(
1227
+ source: string | URL | Buffer | ArrayBufferLike | Uint8Array | Image | import('stream').Readable,
1228
+ options?: LoadImageOptions,
1229
+ ): Promise<Image>
1230
+
1231
+ export interface PDFMetadata {
1232
+ /// The document's title
1233
+ title?: string
1234
+ /// The name of the person who created the document
1235
+ author?: string
1236
+ /// The subject of the document
1237
+ subject?: string
1238
+ /// Keywords associated with the document
1239
+ keywords?: string
1240
+ /// The product that created the original document
1241
+ creator?: string
1242
+ /// The product that is converting this document to PDF (defaults to "Skia/PDF")
1243
+ producer?: string
1244
+ /// The DPI for rasterization (default: 72.0)
1245
+ rasterDPI?: number
1246
+ /// Encoding quality: 0-100 for lossy JPEG, 101 for lossless (default: 101)
1247
+ encodingQuality?: number
1248
+ /// Whether to conform to PDF/A-2b standard (default: false)
1249
+ pdfa?: boolean
1250
+ /// Compression level: -1 (default), 0 (none), 1 (low/fast), 6 (average), 9 (high/slow)
1251
+ compressionLevel?: number
1252
+ }
1253
+
1254
+ export interface Rect {
1255
+ left: number
1256
+ top: number
1257
+ right: number
1258
+ bottom: number
1259
+ }
1260
+
1261
+ export declare class PDFDocument {
1262
+ constructor(metadata?: PDFMetadata | undefined | null)
1263
+ beginPage(width: number, height: number, rect?: Rect | undefined | null): CanvasRenderingContext2D
1264
+ endPage(): void
1265
+ close(): Buffer
1266
+ }
1267
+
1268
+ export interface LottieAnimationOptions {
1269
+ /** Base path for resolving external resources (images, fonts) */
1270
+ resourcePath?: string
1271
+ }
1272
+
1273
+ export interface LottieRenderRect {
1274
+ x: number
1275
+ y: number
1276
+ width: number
1277
+ height: number
1278
+ }
1279
+
1280
+ /**
1281
+ * Lottie animation class for loading and rendering Lottie JSON files.
1282
+ *
1283
+ * @example
1284
+ * ```typescript
1285
+ * import { LottieAnimation, createCanvas } from '@napi-rs/canvas'
1286
+ *
1287
+ * const animation = LottieAnimation.loadFromFile('./animation.json')
1288
+ * const canvas = createCanvas(animation.width, animation.height)
1289
+ * const ctx = canvas.getContext('2d')
1290
+ *
1291
+ * // Render frame 0
1292
+ * animation.seekFrame(0)
1293
+ * animation.render(ctx)
1294
+ *
1295
+ * // Save to PNG
1296
+ * const buffer = canvas.toBuffer('image/png')
1297
+ * ```
1298
+ */
1299
+ export declare class LottieAnimation {
1300
+ /**
1301
+ * Load animation from JSON string or Buffer
1302
+ * @param data - JSON string or Buffer containing Lottie animation data
1303
+ * @param options - Optional configuration
1304
+ */
1305
+ static loadFromData(data: string | Buffer, options?: LottieAnimationOptions): LottieAnimation
1306
+
1307
+ /**
1308
+ * Load animation from file path
1309
+ * External assets are resolved relative to the file's directory
1310
+ * @param path - Path to the Lottie JSON file
1311
+ */
1312
+ static loadFromFile(path: string): LottieAnimation
1313
+
1314
+ /** Animation duration in seconds */
1315
+ readonly duration: number
1316
+
1317
+ /** Frame rate (frames per second) */
1318
+ readonly fps: number
1319
+
1320
+ /** Total frame count */
1321
+ readonly frames: number
1322
+
1323
+ /** Animation width in pixels */
1324
+ readonly width: number
1325
+
1326
+ /** Animation height in pixels */
1327
+ readonly height: number
1328
+
1329
+ /** Lottie format version string */
1330
+ readonly version: string
1331
+
1332
+ /** Animation in-point (start frame) */
1333
+ readonly inPoint: number
1334
+
1335
+ /** Animation out-point (end frame) */
1336
+ readonly outPoint: number
1337
+
1338
+ /**
1339
+ * Seek to normalized position
1340
+ * @param t - Position between 0.0 (start) and 1.0 (end)
1341
+ */
1342
+ seek(t: number): void
1343
+
1344
+ /**
1345
+ * Seek to specific frame index
1346
+ * @param frame - Frame index (0 = first frame)
1347
+ */
1348
+ seekFrame(frame: number): void
1349
+
1350
+ /**
1351
+ * Seek to specific time in seconds
1352
+ * @param seconds - Time in seconds from start
1353
+ */
1354
+ seekTime(seconds: number): void
1355
+
1356
+ /**
1357
+ * Render current frame to canvas context
1358
+ * @param ctx - Canvas 2D rendering context
1359
+ * @param dst - Optional destination rectangle for scaling/positioning
1360
+ */
1361
+ render(ctx: CanvasRenderingContext2D, dst?: LottieRenderRect): void
1362
+ }