@thorvg/webcanvas 1.0.0
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/LICENSE +21 -0
- package/README.md +204 -0
- package/dist/index.js +0 -0
- package/dist/thorvg.wasm +0 -0
- package/dist/webcanvas.cjs.js +2 -0
- package/dist/webcanvas.cjs.js.map +1 -0
- package/dist/webcanvas.d.ts +2344 -0
- package/dist/webcanvas.esm.js +2 -0
- package/dist/webcanvas.esm.js.map +1 -0
- package/dist/webcanvas.js +2 -0
- package/dist/webcanvas.js.map +1 -0
- package/package.json +69 -0
|
@@ -0,0 +1,2344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FinalizationRegistry instances for automatic memory management
|
|
3
|
+
*/
|
|
4
|
+
interface RegistryToken {
|
|
5
|
+
ptr: number;
|
|
6
|
+
cleanup: (ptr: number) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Base class for all WASM-backed objects
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
declare abstract class WasmObject {
|
|
14
|
+
#private;
|
|
15
|
+
constructor(ptr: number, registry?: FinalizationRegistry<RegistryToken>);
|
|
16
|
+
/**
|
|
17
|
+
* Gets the WASM pointer for this object
|
|
18
|
+
* Returns 0 if object has been disposed (error handled by global handler)
|
|
19
|
+
*/
|
|
20
|
+
get ptr(): number;
|
|
21
|
+
set ptr(ptr: number);
|
|
22
|
+
/**
|
|
23
|
+
* Manually dispose of this object and free its WASM memory
|
|
24
|
+
*/
|
|
25
|
+
dispose(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Check if this object has been disposed
|
|
28
|
+
*/
|
|
29
|
+
get isDisposed(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Cleanup function to be implemented by subclasses
|
|
32
|
+
* @param ptr - The WASM pointer to clean up
|
|
33
|
+
*/
|
|
34
|
+
protected abstract _cleanup(ptr: number): void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* ThorVG constants and enums
|
|
39
|
+
* @category Constants
|
|
40
|
+
*/
|
|
41
|
+
/**
|
|
42
|
+
* Blend method for compositing paint layers.
|
|
43
|
+
*
|
|
44
|
+
* Defines various blending modes for combining a source paint (top layer) with a destination (bottom layer).
|
|
45
|
+
* Notation: S = source paint, D = destination, Sa = source alpha, Da = destination alpha.
|
|
46
|
+
* @category Constants
|
|
47
|
+
*/
|
|
48
|
+
declare enum BlendMethod {
|
|
49
|
+
/** Perform alpha blending (default). S if (Sa == 255), otherwise (Sa * S) + (255 - Sa) * D */
|
|
50
|
+
Normal = 0,
|
|
51
|
+
/** Multiply the RGB values of each pixel. (S * D) */
|
|
52
|
+
Multiply = 1,
|
|
53
|
+
/** Invert, multiply, and invert again. (S + D) - (S * D) */
|
|
54
|
+
Screen = 2,
|
|
55
|
+
/** Combines Multiply and Screen modes. (2 * S * D) if (D < 128), otherwise 255 - 2 * (255 - S) * (255 - D) */
|
|
56
|
+
Overlay = 3,
|
|
57
|
+
/** Retains the smallest components. min(S, D) */
|
|
58
|
+
Darken = 4,
|
|
59
|
+
/** Retains the largest components. max(S, D) */
|
|
60
|
+
Lighten = 5,
|
|
61
|
+
/** Divides the bottom layer by the inverted top layer. D / (255 - S) */
|
|
62
|
+
ColorDodge = 6,
|
|
63
|
+
/** Divides the inverted bottom layer by the top layer, then inverts. 255 - (255 - D) / S */
|
|
64
|
+
ColorBurn = 7,
|
|
65
|
+
/** Same as Overlay but with color roles reversed. (2 * S * D) if (S < 128), otherwise 255 - 2 * (255 - S) * (255 - D) */
|
|
66
|
+
HardLight = 8,
|
|
67
|
+
/** Similar to Overlay but softer. (255 - 2 * S) * (D * D) + (2 * S * D) */
|
|
68
|
+
SoftLight = 9,
|
|
69
|
+
/** Absolute difference between layers. (S - D) if (S > D), otherwise (D - S) */
|
|
70
|
+
Difference = 10,
|
|
71
|
+
/** Twice the product subtracted from the sum. S + D - (2 * S * D) */
|
|
72
|
+
Exclusion = 11,
|
|
73
|
+
/** Combine with HSL(Sh + Ds + Dl) then convert to RGB */
|
|
74
|
+
Hue = 12,
|
|
75
|
+
/** Combine with HSL(Dh + Ss + Dl) then convert to RGB */
|
|
76
|
+
Saturation = 13,
|
|
77
|
+
/** Combine with HSL(Sh + Ss + Dl) then convert to RGB */
|
|
78
|
+
Color = 14,
|
|
79
|
+
/** Combine with HSL(Dh + Ds + Sl) then convert to RGB */
|
|
80
|
+
Luminosity = 15,
|
|
81
|
+
/** Simply adds pixel values. (S + D) */
|
|
82
|
+
Add = 16,
|
|
83
|
+
/** For intermediate composition layers; suitable for use with Scene or Picture */
|
|
84
|
+
Composition = 255
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Stroke cap style for line endings.
|
|
88
|
+
*
|
|
89
|
+
* Determines the shape of the endpoints of open paths when stroked.
|
|
90
|
+
* @category Shape
|
|
91
|
+
*/
|
|
92
|
+
declare enum StrokeCap {
|
|
93
|
+
/** Flat cap at the exact endpoint (no extension) */
|
|
94
|
+
Butt = 0,
|
|
95
|
+
/** Rounded cap extending beyond the endpoint by half the stroke width */
|
|
96
|
+
Round = 1,
|
|
97
|
+
/** Square cap extending beyond the endpoint by half the stroke width */
|
|
98
|
+
Square = 2
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Stroke join style for line corners.
|
|
102
|
+
*
|
|
103
|
+
* Determines the shape of corners where two path segments meet when stroked.
|
|
104
|
+
* @category Shape
|
|
105
|
+
*/
|
|
106
|
+
declare enum StrokeJoin {
|
|
107
|
+
/** Sharp corner with pointed edge (subject to miter limit) */
|
|
108
|
+
Miter = 0,
|
|
109
|
+
/** Rounded corner with circular arc */
|
|
110
|
+
Round = 1,
|
|
111
|
+
/** Flat corner with angled edge (beveled) */
|
|
112
|
+
Bevel = 2
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Fill rule for determining whether a point is inside a shape.
|
|
116
|
+
*
|
|
117
|
+
* Used to determine which regions should be filled when rendering complex paths
|
|
118
|
+
* with self-intersections or multiple contours.
|
|
119
|
+
* @category Shape
|
|
120
|
+
*/
|
|
121
|
+
declare enum FillRule {
|
|
122
|
+
/** Non-zero winding rule (default) - counts the number of times a path winds around a point */
|
|
123
|
+
Winding = 0,
|
|
124
|
+
/** Even-odd rule - alternates between filled and unfilled regions, useful for complex shapes with holes */
|
|
125
|
+
EvenOdd = 1
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Gradient spread method for areas outside the gradient bounds.
|
|
129
|
+
*
|
|
130
|
+
* Determines how the gradient behaves in regions outside the defined gradient vector.
|
|
131
|
+
* @category Gradients
|
|
132
|
+
*/
|
|
133
|
+
declare enum GradientSpread {
|
|
134
|
+
/** Extend the edge colors to infinity (default) */
|
|
135
|
+
Pad = 0,
|
|
136
|
+
/** Mirror the gradient pattern */
|
|
137
|
+
Reflect = 1,
|
|
138
|
+
/** Repeat the gradient pattern */
|
|
139
|
+
Repeat = 2
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Composite method for combining paint objects.
|
|
143
|
+
*
|
|
144
|
+
* Defines methods for compositing operations such as clipping and masking.
|
|
145
|
+
* @category Constants
|
|
146
|
+
*/
|
|
147
|
+
declare enum CompositeMethod {
|
|
148
|
+
/** No compositing is applied */
|
|
149
|
+
None = 0,
|
|
150
|
+
/** Use the paint as a clipping path */
|
|
151
|
+
ClipPath = 1,
|
|
152
|
+
/** Alpha masking using the mask's alpha values */
|
|
153
|
+
AlphaMask = 2,
|
|
154
|
+
/** Inverse alpha masking using the complement of the mask's alpha values */
|
|
155
|
+
InvAlphaMask = 3,
|
|
156
|
+
/** Luma masking using the grayscale of the mask */
|
|
157
|
+
LumaMask = 4,
|
|
158
|
+
/** Inverse luma masking using the complement of the mask's grayscale */
|
|
159
|
+
InvLumaMask = 5
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Mask method for masking operations.
|
|
163
|
+
*
|
|
164
|
+
* Defines various methods for applying masks to paint objects.
|
|
165
|
+
* @category Constants
|
|
166
|
+
*/
|
|
167
|
+
declare enum MaskMethod {
|
|
168
|
+
/** No masking is applied */
|
|
169
|
+
None = 0,
|
|
170
|
+
/** Alpha masking using the masking target's pixels as an alpha value */
|
|
171
|
+
Alpha = 1,
|
|
172
|
+
/** Alpha masking using the complement to the masking target's pixels */
|
|
173
|
+
InvAlpha = 2,
|
|
174
|
+
/** Alpha masking using the grayscale (0.2126R + 0.7152G + 0.0722B) of the masking target */
|
|
175
|
+
Luma = 3,
|
|
176
|
+
/** Alpha masking using the grayscale of the complement to the masking target */
|
|
177
|
+
InvLuma = 4,
|
|
178
|
+
/** Combines target and source using target alpha. (T * TA) + (S * (255 - TA)) */
|
|
179
|
+
Add = 5,
|
|
180
|
+
/** Subtracts source from target considering alpha. (T * TA) - (S * (255 - TA)) */
|
|
181
|
+
Subtract = 6,
|
|
182
|
+
/** Takes minimum alpha and multiplies with target. (T * min(TA, SA)) */
|
|
183
|
+
Intersect = 7,
|
|
184
|
+
/** Absolute difference between colors. abs(T - S * (255 - TA)) */
|
|
185
|
+
Difference = 8,
|
|
186
|
+
/** Where masks intersect, uses the highest transparency value */
|
|
187
|
+
Lighten = 9,
|
|
188
|
+
/** Where masks intersect, uses the lowest transparency value */
|
|
189
|
+
Darken = 10
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Scene effect for post-processing effects.
|
|
193
|
+
*
|
|
194
|
+
* Defines various visual effects that can be applied to a Scene to modify its final appearance.
|
|
195
|
+
* @category Scene
|
|
196
|
+
*/
|
|
197
|
+
declare enum SceneEffect {
|
|
198
|
+
/** Reset all previously applied scene effects, restoring the scene to its original state */
|
|
199
|
+
ClearAll = 0,
|
|
200
|
+
/** Apply a blur effect with a Gaussian filter. Params: sigma (>0), direction (both/horizontal/vertical), border (duplicate/wrap), quality (0-100) */
|
|
201
|
+
GaussianBlur = 1,
|
|
202
|
+
/** Apply a drop shadow effect with Gaussian blur. Params: color RGB (0-255), opacity (0-255), angle (0-360), distance, blur sigma (>0), quality (0-100) */
|
|
203
|
+
DropShadow = 2,
|
|
204
|
+
/** Override the scene content color with given fill. Params: color RGB (0-255), opacity (0-255) */
|
|
205
|
+
Fill = 3,
|
|
206
|
+
/** Tint the scene color with black and white parameters. Params: black RGB (0-255), white RGB (0-255), intensity (0-100) */
|
|
207
|
+
Tint = 4,
|
|
208
|
+
/** Apply tritone color effect using shadows, midtones, and highlights. Params: shadow RGB, midtone RGB, highlight RGB (all 0-255), blend (0-255) */
|
|
209
|
+
Tritone = 5
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Text wrapping mode for multi-line text layout.
|
|
213
|
+
*
|
|
214
|
+
* Controls how text breaks across multiple lines when it exceeds the layout width.
|
|
215
|
+
* @category Text
|
|
216
|
+
*/
|
|
217
|
+
declare enum TextWrapMode {
|
|
218
|
+
/** No wrapping - text remains on a single line */
|
|
219
|
+
None = 0,
|
|
220
|
+
/** Wrap at any character boundary */
|
|
221
|
+
Character = 1,
|
|
222
|
+
/** Wrap at word boundaries (default) */
|
|
223
|
+
Word = 2,
|
|
224
|
+
/** Intelligent wrapping with hyphenation support */
|
|
225
|
+
Smart = 3,
|
|
226
|
+
/** Truncate with ellipsis (...) when text exceeds bounds */
|
|
227
|
+
Ellipsis = 4
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Color space enum for raw image data.
|
|
231
|
+
* Specifies the channel order and alpha premultiplication.
|
|
232
|
+
* @category Picture
|
|
233
|
+
*/
|
|
234
|
+
declare enum ColorSpace {
|
|
235
|
+
/** Alpha, Blue, Green, Red - alpha-premultiplied */
|
|
236
|
+
ABGR8888 = 0,
|
|
237
|
+
/** Alpha, Red, Green, Blue - alpha-premultiplied */
|
|
238
|
+
ARGB8888 = 1,
|
|
239
|
+
/** Alpha, Blue, Green, Red - un-alpha-premultiplied */
|
|
240
|
+
ABGR8888S = 2,
|
|
241
|
+
/** Alpha, Red, Green, Blue - un-alpha-premultiplied */
|
|
242
|
+
ARGB8888S = 3,
|
|
243
|
+
/** Single channel grayscale data */
|
|
244
|
+
Grayscale8 = 4,
|
|
245
|
+
/** Unknown channel data (reserved for initial value) */
|
|
246
|
+
Unknown = 255
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* MIME type or format hint for loading picture data.
|
|
250
|
+
*
|
|
251
|
+
* Supported image and vector file formats for Picture class.
|
|
252
|
+
* @category Picture
|
|
253
|
+
*/
|
|
254
|
+
type MimeType = 'svg' | 'png' | 'jpg' | 'jpeg' | 'webp' | 'raw' | 'lot' | 'lottie+json';
|
|
255
|
+
/**
|
|
256
|
+
* Rendering backend type for Canvas.
|
|
257
|
+
*
|
|
258
|
+
* ThorVG supports three rendering backends, each with different performance
|
|
259
|
+
* characteristics and browser compatibility:
|
|
260
|
+
*
|
|
261
|
+
* ## Available Renderers
|
|
262
|
+
*
|
|
263
|
+
* ### `'sw'` - Software Renderer
|
|
264
|
+
* - **Rendering**: CPU-based software rendering
|
|
265
|
+
* - **Performance**: Slower, but works everywhere
|
|
266
|
+
* - **Compatibility**: All browsers and devices
|
|
267
|
+
* - **Best for**: Maximum compatibility, simple graphics, server-side rendering
|
|
268
|
+
*
|
|
269
|
+
* ### `'gl'` - WebGL Renderer (Recommended)
|
|
270
|
+
* - **Rendering**: GPU-accelerated using WebGL 2.0
|
|
271
|
+
* - **Performance**: Excellent performance with wide browser support
|
|
272
|
+
* - **Compatibility**: Chrome 56+, Firefox 51+, Safari 15+, Edge 79+
|
|
273
|
+
* - **Best for**: Production applications, interactive graphics, animations
|
|
274
|
+
* - **Recommended for most use cases**
|
|
275
|
+
*
|
|
276
|
+
* ### `'wg'` - WebGPU Renderer
|
|
277
|
+
* - **Rendering**: Next-generation GPU API
|
|
278
|
+
* - **Performance**: Best performance for complex scenes
|
|
279
|
+
* - **Compatibility**: Chrome 113+, Edge 113+ (limited support)
|
|
280
|
+
* - **Best for**: Maximum performance, modern browsers only
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* // Recommended setup with WebGL
|
|
285
|
+
* const TVG = await ThorVG.init({ renderer: 'gl' });
|
|
286
|
+
* const canvas = new TVG.Canvas('#canvas', { width: 800, height: 600 });
|
|
287
|
+
* ```
|
|
288
|
+
*
|
|
289
|
+
* @example
|
|
290
|
+
* ```typescript
|
|
291
|
+
* // Maximum performance with WebGPU (modern browsers only)
|
|
292
|
+
* const TVG = await ThorVG.init({ renderer: 'wg' });
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* // Maximum compatibility with Software renderer
|
|
298
|
+
* const TVG = await ThorVG.init({ renderer: 'sw' });
|
|
299
|
+
* ```
|
|
300
|
+
*
|
|
301
|
+
* @category Canvas
|
|
302
|
+
*/
|
|
303
|
+
type RendererType = 'sw' | 'gl' | 'wg';
|
|
304
|
+
|
|
305
|
+
type constants_BlendMethod = BlendMethod;
|
|
306
|
+
declare const constants_BlendMethod: typeof BlendMethod;
|
|
307
|
+
type constants_ColorSpace = ColorSpace;
|
|
308
|
+
declare const constants_ColorSpace: typeof ColorSpace;
|
|
309
|
+
type constants_CompositeMethod = CompositeMethod;
|
|
310
|
+
declare const constants_CompositeMethod: typeof CompositeMethod;
|
|
311
|
+
type constants_FillRule = FillRule;
|
|
312
|
+
declare const constants_FillRule: typeof FillRule;
|
|
313
|
+
type constants_GradientSpread = GradientSpread;
|
|
314
|
+
declare const constants_GradientSpread: typeof GradientSpread;
|
|
315
|
+
type constants_MaskMethod = MaskMethod;
|
|
316
|
+
declare const constants_MaskMethod: typeof MaskMethod;
|
|
317
|
+
type constants_MimeType = MimeType;
|
|
318
|
+
type constants_RendererType = RendererType;
|
|
319
|
+
type constants_SceneEffect = SceneEffect;
|
|
320
|
+
declare const constants_SceneEffect: typeof SceneEffect;
|
|
321
|
+
type constants_StrokeCap = StrokeCap;
|
|
322
|
+
declare const constants_StrokeCap: typeof StrokeCap;
|
|
323
|
+
type constants_StrokeJoin = StrokeJoin;
|
|
324
|
+
declare const constants_StrokeJoin: typeof StrokeJoin;
|
|
325
|
+
type constants_TextWrapMode = TextWrapMode;
|
|
326
|
+
declare const constants_TextWrapMode: typeof TextWrapMode;
|
|
327
|
+
declare namespace constants {
|
|
328
|
+
export { constants_BlendMethod as BlendMethod, constants_ColorSpace as ColorSpace, constants_CompositeMethod as CompositeMethod, constants_FillRule as FillRule, constants_GradientSpread as GradientSpread, constants_MaskMethod as MaskMethod, constants_SceneEffect as SceneEffect, constants_StrokeCap as StrokeCap, constants_StrokeJoin as StrokeJoin, constants_TextWrapMode as TextWrapMode };
|
|
329
|
+
export type { constants_MimeType as MimeType, constants_RendererType as RendererType };
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/**
|
|
333
|
+
* Base class for all drawable objects
|
|
334
|
+
* @category Paint
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* @category Shapes
|
|
339
|
+
*/
|
|
340
|
+
interface Bounds {
|
|
341
|
+
x: number;
|
|
342
|
+
y: number;
|
|
343
|
+
width: number;
|
|
344
|
+
height: number;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* @category Shapes
|
|
348
|
+
*/
|
|
349
|
+
interface Point {
|
|
350
|
+
x: number;
|
|
351
|
+
y: number;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* A 3x3 transformation matrix for 2D transformations.
|
|
355
|
+
*
|
|
356
|
+
* The matrix elements represent:
|
|
357
|
+
* - e11, e12: Rotation/scale in X
|
|
358
|
+
* - e21, e22: Rotation/scale in Y
|
|
359
|
+
* - e13, e23: Translation in X and Y
|
|
360
|
+
* - e31, e32: Always 0 (reserved for 3D)
|
|
361
|
+
* - e33: Always 1 (homogeneous coordinate)
|
|
362
|
+
*
|
|
363
|
+
* Matrix layout:
|
|
364
|
+
* ```
|
|
365
|
+
* | e11 e12 e13 |
|
|
366
|
+
* | e21 e22 e23 |
|
|
367
|
+
* | e31 e32 e33 |
|
|
368
|
+
* ```
|
|
369
|
+
*
|
|
370
|
+
* @category Shapes
|
|
371
|
+
*/
|
|
372
|
+
interface Matrix {
|
|
373
|
+
e11: number;
|
|
374
|
+
e12: number;
|
|
375
|
+
e13: number;
|
|
376
|
+
e21: number;
|
|
377
|
+
e22: number;
|
|
378
|
+
e23: number;
|
|
379
|
+
e31: number;
|
|
380
|
+
e32: number;
|
|
381
|
+
e33: number;
|
|
382
|
+
}
|
|
383
|
+
declare abstract class Paint extends WasmObject {
|
|
384
|
+
protected _cleanup(ptr: number): void;
|
|
385
|
+
/**
|
|
386
|
+
* Translate the paint by (x, y)
|
|
387
|
+
*/
|
|
388
|
+
translate(x: number, y: number): this;
|
|
389
|
+
/**
|
|
390
|
+
* Rotate the paint by angle (in degrees)
|
|
391
|
+
*/
|
|
392
|
+
rotate(angle: number): this;
|
|
393
|
+
/**
|
|
394
|
+
* Scale the paint by (sx, sy). If sy is not provided, use sx for both
|
|
395
|
+
*/
|
|
396
|
+
scale(sx: number, sy?: number): this;
|
|
397
|
+
/**
|
|
398
|
+
* Set the origin point for transformations (rotation, scale).
|
|
399
|
+
* The origin is specified as normalized coordinates (0.0 to 1.0).
|
|
400
|
+
* - (0, 0) = top-left corner
|
|
401
|
+
* - (0.5, 0.5) = center (default)
|
|
402
|
+
* - (1, 1) = bottom-right corner
|
|
403
|
+
*
|
|
404
|
+
* @param x - Normalized X coordinate (0.0 to 1.0)
|
|
405
|
+
* @param y - Normalized Y coordinate (0.0 to 1.0)
|
|
406
|
+
* @returns The Paint instance for method chaining
|
|
407
|
+
*
|
|
408
|
+
* @example
|
|
409
|
+
* ```typescript
|
|
410
|
+
* const picture = new TVG.Picture();
|
|
411
|
+
* picture.load(svgData, { type: 'svg' });
|
|
412
|
+
*
|
|
413
|
+
* // Set origin to center for rotation around center
|
|
414
|
+
* picture.origin(0.5, 0.5);
|
|
415
|
+
* picture.translate(300, 300);
|
|
416
|
+
* picture.rotate(45);
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
origin(x: number, y: number): this;
|
|
420
|
+
/**
|
|
421
|
+
* Set the blending method for this paint.
|
|
422
|
+
* Blending determines how this paint is combined with the content below it.
|
|
423
|
+
*
|
|
424
|
+
* @param method - The blending method to use
|
|
425
|
+
* @returns The Paint instance for method chaining
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* ```typescript
|
|
429
|
+
* const scene = new TVG.Scene();
|
|
430
|
+
* scene.blend(BlendMethod.Add);
|
|
431
|
+
*
|
|
432
|
+
* const shape = new TVG.Shape();
|
|
433
|
+
* shape.appendCircle(100, 100, 50, 50);
|
|
434
|
+
* shape.fill(255, 0, 0, 255);
|
|
435
|
+
* shape.blend(BlendMethod.Multiply);
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
blend(method: BlendMethod): this;
|
|
439
|
+
/**
|
|
440
|
+
* Get or set the opacity (0 to 255)
|
|
441
|
+
* @param value - The opacity value in the range [0 ~ 255], where 0 is completely transparent and 255 is opaque.
|
|
442
|
+
* @returns When setting, returns the Paint instance for method chaining. When getting, returns the opacity value (0-255).
|
|
443
|
+
*
|
|
444
|
+
* @example
|
|
445
|
+
* ```typescript
|
|
446
|
+
* // Set opacity to 50% (half transparent)
|
|
447
|
+
* shape.opacity(128);
|
|
448
|
+
*
|
|
449
|
+
* // Set to fully opaque
|
|
450
|
+
* shape.opacity(255);
|
|
451
|
+
*
|
|
452
|
+
* // Get current opacity value
|
|
453
|
+
* const currentOpacity = shape.opacity(); // returns 0-255
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
opacity(): number;
|
|
457
|
+
opacity(value: number): this;
|
|
458
|
+
/**
|
|
459
|
+
* Get or set the visibility
|
|
460
|
+
*/
|
|
461
|
+
visible(): boolean;
|
|
462
|
+
visible(value: boolean): this;
|
|
463
|
+
/**
|
|
464
|
+
* Get the axis-aligned bounding box (AABB) of this paint
|
|
465
|
+
*/
|
|
466
|
+
bounds(): Bounds;
|
|
467
|
+
/**
|
|
468
|
+
* Get the oriented bounding box (OBB) of this paint as 4 corner points
|
|
469
|
+
* @param options - Options object with oriented flag
|
|
470
|
+
*/
|
|
471
|
+
bounds(options: {
|
|
472
|
+
oriented: true;
|
|
473
|
+
}): Point[];
|
|
474
|
+
/**
|
|
475
|
+
* Duplicate this paint object
|
|
476
|
+
*/
|
|
477
|
+
duplicate<T extends Paint>(): T;
|
|
478
|
+
/**
|
|
479
|
+
* Applies a custom transformation matrix to the paint.
|
|
480
|
+
*
|
|
481
|
+
* This method allows you to apply complex transformations that combine
|
|
482
|
+
* translation, rotation, scaling, and skewing in a single operation.
|
|
483
|
+
* The matrix is multiplied with any existing transformations.
|
|
484
|
+
*
|
|
485
|
+
* @param matrix - A 3x3 transformation matrix
|
|
486
|
+
* @returns The Paint instance for method chaining
|
|
487
|
+
*
|
|
488
|
+
* @example
|
|
489
|
+
* ```typescript
|
|
490
|
+
* // Apply a combined transformation
|
|
491
|
+
* const shape = new TVG.Shape();
|
|
492
|
+
* shape.appendRect(0, 0, 100, 100);
|
|
493
|
+
*
|
|
494
|
+
* // Create a matrix for: scale(2, 1.5) + rotate(45deg) + translate(100, 50)
|
|
495
|
+
* const rad = (45 * Math.PI) / 180;
|
|
496
|
+
* const cos = Math.cos(rad);
|
|
497
|
+
* const sin = Math.sin(rad);
|
|
498
|
+
*
|
|
499
|
+
* shape.transform({
|
|
500
|
+
* e11: 2 * cos, e12: -2 * sin, e13: 100,
|
|
501
|
+
* e21: 1.5 * sin, e22: 1.5 * cos, e23: 50,
|
|
502
|
+
* e31: 0, e32: 0, e33: 1
|
|
503
|
+
* });
|
|
504
|
+
* ```
|
|
505
|
+
*
|
|
506
|
+
* @example
|
|
507
|
+
* ```typescript
|
|
508
|
+
* // Create a skew transformation
|
|
509
|
+
* const shape = new TVG.Shape();
|
|
510
|
+
* shape.appendRect(0, 0, 100, 100);
|
|
511
|
+
*
|
|
512
|
+
* // Skew in X direction
|
|
513
|
+
* shape.transform({
|
|
514
|
+
* e11: 1, e12: 0.5, e13: 0,
|
|
515
|
+
* e21: 0, e22: 1, e23: 0,
|
|
516
|
+
* e31: 0, e32: 0, e33: 1
|
|
517
|
+
* });
|
|
518
|
+
* ```
|
|
519
|
+
*/
|
|
520
|
+
transform(matrix: Matrix): this;
|
|
521
|
+
/**
|
|
522
|
+
* Sets a clipping path for this paint object.
|
|
523
|
+
*
|
|
524
|
+
* The clipping path restricts the area where the paint will be rendered.
|
|
525
|
+
* Only the parts of the paint that overlap with the clipper shape will be visible.
|
|
526
|
+
*
|
|
527
|
+
* @param clipper - A Paint object (typically a Shape) to use as the clipping path
|
|
528
|
+
* @returns The Paint instance for method chaining
|
|
529
|
+
*
|
|
530
|
+
* @example
|
|
531
|
+
* ```typescript
|
|
532
|
+
* const circle = new TVG.Shape();
|
|
533
|
+
* circle.appendCircle(150, 150, 100);
|
|
534
|
+
*
|
|
535
|
+
* const rect = new TVG.Shape();
|
|
536
|
+
* rect.appendRect(0, 0, 300, 300)
|
|
537
|
+
* .fill(255, 0, 0, 255)
|
|
538
|
+
* .clip(circle);
|
|
539
|
+
*
|
|
540
|
+
* canvas.add(rect);
|
|
541
|
+
* ```
|
|
542
|
+
*/
|
|
543
|
+
clip(clipper: Paint): this;
|
|
544
|
+
/**
|
|
545
|
+
* Sets a masking target object and the masking method.
|
|
546
|
+
*
|
|
547
|
+
* The masking restricts the transparency of the source paint using the target paint.
|
|
548
|
+
*
|
|
549
|
+
* @param target - A Paint object to use as the masking target
|
|
550
|
+
* @param method - The method used to mask the source object with the target
|
|
551
|
+
* @returns The Paint instance for method chaining
|
|
552
|
+
*
|
|
553
|
+
* @example
|
|
554
|
+
* ```typescript
|
|
555
|
+
* const mask = new TVG.Shape();
|
|
556
|
+
* mask.appendCircle(200, 200, 125);
|
|
557
|
+
* mask.fill(255, 255, 255);
|
|
558
|
+
*
|
|
559
|
+
* const shape = new TVG.Shape();
|
|
560
|
+
* shape.appendRect(0, 0, 400, 400)
|
|
561
|
+
* .fill(255, 0, 0, 255)
|
|
562
|
+
* .mask(mask, MaskMethod.Alpha);
|
|
563
|
+
*
|
|
564
|
+
* canvas.add(shape);
|
|
565
|
+
* ```
|
|
566
|
+
*/
|
|
567
|
+
mask(target: Paint, method: MaskMethod): this;
|
|
568
|
+
/**
|
|
569
|
+
* Checks if the paint intersects with the given rectangular region.
|
|
570
|
+
*
|
|
571
|
+
* @param x - The x-coordinate of the region's top-left corner
|
|
572
|
+
* @param y - The y-coordinate of the region's top-left corner
|
|
573
|
+
* @param width - The width of the region
|
|
574
|
+
* @param height - The height of the region
|
|
575
|
+
* @returns true if the paint intersects with the region, false otherwise
|
|
576
|
+
*
|
|
577
|
+
* @example
|
|
578
|
+
* ```typescript
|
|
579
|
+
* const shape = new TVG.Shape();
|
|
580
|
+
* shape.appendRect(100, 100, 200, 200);
|
|
581
|
+
*
|
|
582
|
+
* // Check if shape intersects with a region
|
|
583
|
+
* if (shape.intersects(150, 150, 100, 100)) {
|
|
584
|
+
* console.log('Shape intersects with region');
|
|
585
|
+
* }
|
|
586
|
+
* ```
|
|
587
|
+
*/
|
|
588
|
+
intersects(x: number, y: number, width: number, height: number): boolean;
|
|
589
|
+
/**
|
|
590
|
+
* Create a new instance of this paint type with the given pointer
|
|
591
|
+
* Must be implemented by subclasses
|
|
592
|
+
*/
|
|
593
|
+
protected abstract _createInstance(ptr: number): Paint;
|
|
594
|
+
}
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Canvas Rendering context for ThorVG
|
|
598
|
+
*
|
|
599
|
+
* The Canvas class manages the rendering context and provides methods for drawing
|
|
600
|
+
* vector graphics to an HTML canvas element. It supports multiple rendering backends
|
|
601
|
+
* (Software, WebGL, WebGPU) and handles the render loop.
|
|
602
|
+
*
|
|
603
|
+
* @category Canvas
|
|
604
|
+
*
|
|
605
|
+
* @example
|
|
606
|
+
* Basic usage
|
|
607
|
+
* ```typescript
|
|
608
|
+
* const TVG = await ThorVG.init({ renderer: 'gl' });
|
|
609
|
+
* const canvas = new TVG.Canvas('#canvas', {
|
|
610
|
+
* width: 800,
|
|
611
|
+
* height: 600
|
|
612
|
+
* });
|
|
613
|
+
*
|
|
614
|
+
* const shape = new TVG.Shape();
|
|
615
|
+
* shape.appendCircle(400, 300, 100)
|
|
616
|
+
* .fill(255, 0, 0, 255);
|
|
617
|
+
*
|
|
618
|
+
* canvas.add(shape).render();
|
|
619
|
+
* ```
|
|
620
|
+
*
|
|
621
|
+
* @example
|
|
622
|
+
* Rendering with animation loop
|
|
623
|
+
* ```typescript
|
|
624
|
+
* const canvas = new TVG.Canvas('#canvas');
|
|
625
|
+
* const animation = new TVG.Animation();
|
|
626
|
+
* await animation.load(lottieData);
|
|
627
|
+
*
|
|
628
|
+
* canvas.add(animation.picture);
|
|
629
|
+
*
|
|
630
|
+
* function animate() {
|
|
631
|
+
* animation.frame(currentFrame++);
|
|
632
|
+
* canvas.update().render();
|
|
633
|
+
* requestAnimationFrame(animate);
|
|
634
|
+
* }
|
|
635
|
+
* animate();
|
|
636
|
+
* ```
|
|
637
|
+
*/
|
|
638
|
+
|
|
639
|
+
/**
|
|
640
|
+
* Configuration options for Canvas initialization.
|
|
641
|
+
*
|
|
642
|
+
* @category Canvas
|
|
643
|
+
*/
|
|
644
|
+
interface CanvasOptions {
|
|
645
|
+
/** Canvas width in pixels. Default: 800 */
|
|
646
|
+
width?: number;
|
|
647
|
+
/** Canvas height in pixels. Default: 600 */
|
|
648
|
+
height?: number;
|
|
649
|
+
/** Enable device pixel ratio for high-DPI displays. Default: true */
|
|
650
|
+
enableDevicePixelRatio?: boolean;
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* Canvas rendering context for ThorVG vector graphics.
|
|
654
|
+
*
|
|
655
|
+
* Manages the rendering pipeline and provides methods for adding/removing Paint objects
|
|
656
|
+
* and controlling the render loop.
|
|
657
|
+
*
|
|
658
|
+
* @category Canvas
|
|
659
|
+
*
|
|
660
|
+
* @example
|
|
661
|
+
* ```typescript
|
|
662
|
+
* // Initialize with renderer
|
|
663
|
+
* const TVG = await ThorVG.init({ renderer: 'gl' });
|
|
664
|
+
*
|
|
665
|
+
* // Basic canvas setup with shapes
|
|
666
|
+
* const canvas = new TVG.Canvas('#canvas', { width: 800, height: 600 });
|
|
667
|
+
*
|
|
668
|
+
* const shape = new TVG.Shape();
|
|
669
|
+
* shape.appendRect(100, 100, 200, 150, 10)
|
|
670
|
+
* .fill(255, 100, 50, 255);
|
|
671
|
+
*
|
|
672
|
+
* canvas.add(shape).render();
|
|
673
|
+
* ```
|
|
674
|
+
*
|
|
675
|
+
* @example
|
|
676
|
+
* ```typescript
|
|
677
|
+
* // Animation loop
|
|
678
|
+
* const canvas = new TVG.Canvas('#canvas');
|
|
679
|
+
* const shape = new TVG.Shape();
|
|
680
|
+
*
|
|
681
|
+
* let rotation = 0;
|
|
682
|
+
* function animate() {
|
|
683
|
+
* shape.reset()
|
|
684
|
+
* .appendRect(0, 0, 100, 100)
|
|
685
|
+
* .fill(100, 150, 255, 255)
|
|
686
|
+
* .rotate(rotation++)
|
|
687
|
+
* .translate(400, 300);
|
|
688
|
+
*
|
|
689
|
+
* canvas.update().render();
|
|
690
|
+
* requestAnimationFrame(animate);
|
|
691
|
+
* }
|
|
692
|
+
* animate();
|
|
693
|
+
* ```
|
|
694
|
+
*/
|
|
695
|
+
declare class Canvas {
|
|
696
|
+
#private;
|
|
697
|
+
/**
|
|
698
|
+
* Creates a new Canvas rendering context.
|
|
699
|
+
*
|
|
700
|
+
* The renderer is determined by the global setting from ThorVG.init().
|
|
701
|
+
*
|
|
702
|
+
* @param selector - CSS selector for the target HTML canvas element (e.g., '#canvas', '.my-canvas')
|
|
703
|
+
* @param options - Configuration options for the canvas
|
|
704
|
+
*
|
|
705
|
+
* @throws {Error} If the canvas element is not found or renderer initialization fails
|
|
706
|
+
*
|
|
707
|
+
* @example
|
|
708
|
+
* ```typescript
|
|
709
|
+
* // Initialize with renderer
|
|
710
|
+
* const TVG = await ThorVG.init({ renderer: 'gl' });
|
|
711
|
+
*
|
|
712
|
+
* // Basic canvas with default options (DPR enabled by default)
|
|
713
|
+
* const canvas = new TVG.Canvas('#canvas');
|
|
714
|
+
* ```
|
|
715
|
+
*
|
|
716
|
+
* @example
|
|
717
|
+
* ```typescript
|
|
718
|
+
* // Canvas with custom size
|
|
719
|
+
* const TVG = await ThorVG.init({ renderer: 'wg' });
|
|
720
|
+
* const canvas = new TVG.Canvas('#myCanvas', {
|
|
721
|
+
* width: 1920,
|
|
722
|
+
* height: 1080
|
|
723
|
+
* });
|
|
724
|
+
* ```
|
|
725
|
+
*
|
|
726
|
+
* @example
|
|
727
|
+
* ```typescript
|
|
728
|
+
* // Canvas with DPR disabled for consistent rendering across devices
|
|
729
|
+
* const canvas = new TVG.Canvas('#canvas', {
|
|
730
|
+
* width: 800,
|
|
731
|
+
* height: 600,
|
|
732
|
+
* enableDevicePixelRatio: false
|
|
733
|
+
* });
|
|
734
|
+
* ```
|
|
735
|
+
*/
|
|
736
|
+
constructor(selector: string, options?: CanvasOptions);
|
|
737
|
+
/**
|
|
738
|
+
* Adds a Paint object to the canvas for rendering.
|
|
739
|
+
*
|
|
740
|
+
* Paint objects include Shape, Scene, Picture, Text, and Animation.picture.
|
|
741
|
+
* Objects are rendered in the order they are added (painter's algorithm).
|
|
742
|
+
*
|
|
743
|
+
* @param paint - A Paint object to add to the canvas
|
|
744
|
+
* @returns The canvas instance for method chaining
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* ```typescript
|
|
748
|
+
* const shape = new TVG.Shape();
|
|
749
|
+
* const text = new TVG.Text();
|
|
750
|
+
* canvas.add(shape);
|
|
751
|
+
* canvas.add(text);
|
|
752
|
+
* ```
|
|
753
|
+
*
|
|
754
|
+
* @example
|
|
755
|
+
* ```typescript
|
|
756
|
+
* // Method chaining
|
|
757
|
+
* canvas.add(shape1)
|
|
758
|
+
* .add(shape2)
|
|
759
|
+
* .render();
|
|
760
|
+
* ```
|
|
761
|
+
*/
|
|
762
|
+
add(paint: Paint): this;
|
|
763
|
+
/**
|
|
764
|
+
* Removes one or all Paint objects from the canvas.
|
|
765
|
+
*
|
|
766
|
+
* @param paint - Optional Paint object to remove. If omitted, removes all Paint objects.
|
|
767
|
+
* @returns The canvas instance for method chaining
|
|
768
|
+
*
|
|
769
|
+
* @example
|
|
770
|
+
* ```typescript
|
|
771
|
+
* // Remove a specific paint
|
|
772
|
+
* canvas.remove(shape);
|
|
773
|
+
* ```
|
|
774
|
+
*
|
|
775
|
+
* @example
|
|
776
|
+
* ```typescript
|
|
777
|
+
* // Remove all paints
|
|
778
|
+
* canvas.remove();
|
|
779
|
+
* ```
|
|
780
|
+
*/
|
|
781
|
+
remove(paint?: Paint): this;
|
|
782
|
+
/**
|
|
783
|
+
* Clears all Paint objects from the canvas and renders an empty frame.
|
|
784
|
+
*
|
|
785
|
+
* This is equivalent to {@link remove | remove()} without arguments,
|
|
786
|
+
* but also immediately renders the cleared canvas.
|
|
787
|
+
*
|
|
788
|
+
* @returns The canvas instance for method chaining
|
|
789
|
+
*
|
|
790
|
+
* @example
|
|
791
|
+
* ```typescript
|
|
792
|
+
* canvas.clear(); // Clears and renders empty canvas
|
|
793
|
+
* ```
|
|
794
|
+
*/
|
|
795
|
+
clear(): this;
|
|
796
|
+
/**
|
|
797
|
+
* Updates the canvas state before rendering.
|
|
798
|
+
*
|
|
799
|
+
* This method should be called before {@link render} when working with animations
|
|
800
|
+
* or when Paint objects have been modified. It ensures all transformations and
|
|
801
|
+
* changes are processed.
|
|
802
|
+
*
|
|
803
|
+
* @returns The canvas instance for method chaining
|
|
804
|
+
*
|
|
805
|
+
* @example
|
|
806
|
+
* ```typescript
|
|
807
|
+
* // Animation loop pattern
|
|
808
|
+
* function animate() {
|
|
809
|
+
* animation.frame(currentFrame++);
|
|
810
|
+
* canvas.update().render();
|
|
811
|
+
* requestAnimationFrame(animate);
|
|
812
|
+
* }
|
|
813
|
+
* ```
|
|
814
|
+
*
|
|
815
|
+
* @remarks
|
|
816
|
+
* For static scenes, calling {@link render} alone is sufficient.
|
|
817
|
+
* For animated content, always call update() before render().
|
|
818
|
+
*/
|
|
819
|
+
update(): this;
|
|
820
|
+
/**
|
|
821
|
+
* Renders all Paint objects to the canvas.
|
|
822
|
+
*
|
|
823
|
+
* This method draws all added Paint objects to the canvas using the configured
|
|
824
|
+
* rendering backend (Software, WebGL, or WebGPU).
|
|
825
|
+
*
|
|
826
|
+
* @returns The canvas instance for method chaining
|
|
827
|
+
*
|
|
828
|
+
* @example
|
|
829
|
+
* ```typescript
|
|
830
|
+
* // Static rendering
|
|
831
|
+
* canvas.add(shape).add(text).render();
|
|
832
|
+
* ```
|
|
833
|
+
*
|
|
834
|
+
* @example
|
|
835
|
+
* ```typescript
|
|
836
|
+
* // Animation loop
|
|
837
|
+
* function animate() {
|
|
838
|
+
* canvas.update().render();
|
|
839
|
+
* requestAnimationFrame(animate);
|
|
840
|
+
* }
|
|
841
|
+
* ```
|
|
842
|
+
*
|
|
843
|
+
* @remarks
|
|
844
|
+
* For animated content, call {@link update} before render().
|
|
845
|
+
* For static scenes, render() can be called directly.
|
|
846
|
+
*/
|
|
847
|
+
render(): this;
|
|
848
|
+
private _calculateDPR;
|
|
849
|
+
private _updateHTMLCanvas;
|
|
850
|
+
/**
|
|
851
|
+
* Resizes the canvas to new dimensions.
|
|
852
|
+
*
|
|
853
|
+
* @param width - New width in pixels
|
|
854
|
+
* @param height - New height in pixels
|
|
855
|
+
* @returns The canvas instance for method chaining
|
|
856
|
+
*
|
|
857
|
+
* @example
|
|
858
|
+
* ```typescript
|
|
859
|
+
* canvas.resize(1920, 1080).render();
|
|
860
|
+
* ```
|
|
861
|
+
*
|
|
862
|
+
* @example
|
|
863
|
+
* ```typescript
|
|
864
|
+
* // Responsive canvas
|
|
865
|
+
* window.addEventListener('resize', () => {
|
|
866
|
+
* canvas.resize(window.innerWidth, window.innerHeight).render();
|
|
867
|
+
* });
|
|
868
|
+
* ```
|
|
869
|
+
*/
|
|
870
|
+
resize(width: number, height: number): this;
|
|
871
|
+
/**
|
|
872
|
+
* Sets the viewport for rendering a specific region of the canvas.
|
|
873
|
+
*
|
|
874
|
+
* The viewport defines the rectangular region where rendering occurs.
|
|
875
|
+
* Useful for rendering to a portion of the canvas or implementing split-screen views.
|
|
876
|
+
*
|
|
877
|
+
* @param x - X coordinate of the viewport origin
|
|
878
|
+
* @param y - Y coordinate of the viewport origin
|
|
879
|
+
* @param w - Viewport width
|
|
880
|
+
* @param h - Viewport height
|
|
881
|
+
* @returns The canvas instance for method chaining
|
|
882
|
+
*
|
|
883
|
+
* @example
|
|
884
|
+
* ```typescript
|
|
885
|
+
* // Render to top-left quarter of canvas
|
|
886
|
+
* canvas.viewport(0, 0, canvas.width / 2, canvas.height / 2);
|
|
887
|
+
* ```
|
|
888
|
+
*/
|
|
889
|
+
viewport(x: number, y: number, w: number, h: number): this;
|
|
890
|
+
/**
|
|
891
|
+
* Destroys the canvas and frees its WASM memory.
|
|
892
|
+
*
|
|
893
|
+
* After calling destroy(), this canvas instance cannot be used.
|
|
894
|
+
* The ThorVG module remains loaded and new canvases can be created.
|
|
895
|
+
*
|
|
896
|
+
* @example
|
|
897
|
+
* ```typescript
|
|
898
|
+
* canvas.destroy();
|
|
899
|
+
* // Create a new canvas
|
|
900
|
+
* const newCanvas = new TVG.Canvas('#canvas');
|
|
901
|
+
* ```
|
|
902
|
+
*
|
|
903
|
+
* @remarks
|
|
904
|
+
* This method should be called when you're done with a canvas to free memory.
|
|
905
|
+
* It's particularly important in single-page applications where canvases
|
|
906
|
+
* may be created and destroyed frequently.
|
|
907
|
+
*/
|
|
908
|
+
destroy(): void;
|
|
909
|
+
/**
|
|
910
|
+
* Gets the rendering backend type currently in use.
|
|
911
|
+
*
|
|
912
|
+
* @returns The renderer type: 'sw' (Software), 'gl' (WebGL), or 'wg' (WebGPU)
|
|
913
|
+
*
|
|
914
|
+
* @example
|
|
915
|
+
* ```typescript
|
|
916
|
+
* const canvas = new TVG.Canvas('#canvas', { renderer: 'wg' });
|
|
917
|
+
* console.log(canvas.renderer); // 'wg'
|
|
918
|
+
* ```
|
|
919
|
+
*/
|
|
920
|
+
get renderer(): string;
|
|
921
|
+
/**
|
|
922
|
+
* Gets the current device pixel ratio applied to this canvas.
|
|
923
|
+
*
|
|
924
|
+
* ThorVG uses an optimized DPR formula for best performance:
|
|
925
|
+
* `1 + ((window.devicePixelRatio - 1) * 0.75)`
|
|
926
|
+
*
|
|
927
|
+
* This provides a balance between visual quality and rendering performance,
|
|
928
|
+
* especially on high-DPI displays.
|
|
929
|
+
*
|
|
930
|
+
* @category Canvas
|
|
931
|
+
* @returns The current effective DPR value, or 1.0 if DPR scaling is disabled
|
|
932
|
+
*
|
|
933
|
+
* @example
|
|
934
|
+
* ```typescript
|
|
935
|
+
* // Getting the current DPR
|
|
936
|
+
* const canvas = new TVG.Canvas('#canvas', {
|
|
937
|
+
* enableDevicePixelRatio: true
|
|
938
|
+
* });
|
|
939
|
+
*
|
|
940
|
+
* console.log(canvas.dpr); // e.g., 1.75 on a 2x display
|
|
941
|
+
* console.log(window.devicePixelRatio); // e.g., 2.0
|
|
942
|
+
* ```
|
|
943
|
+
*
|
|
944
|
+
* @example
|
|
945
|
+
* ```typescript
|
|
946
|
+
* // Using DPR for responsive calculations
|
|
947
|
+
* const canvas = new TVG.Canvas('#canvas');
|
|
948
|
+
* const shape = new TVG.Shape();
|
|
949
|
+
*
|
|
950
|
+
* // Adjust stroke width based on DPR for consistent appearance
|
|
951
|
+
* const strokeWidth = 2 / canvas.dpr;
|
|
952
|
+
* shape.appendCircle(100, 100, 50)
|
|
953
|
+
* .stroke(255, 0, 0, 255)
|
|
954
|
+
* .strokeWidth(strokeWidth);
|
|
955
|
+
* ```
|
|
956
|
+
*
|
|
957
|
+
* @see {@link CanvasOptions.enableDevicePixelRatio} for controlling DPR scaling
|
|
958
|
+
*/
|
|
959
|
+
get dpr(): number;
|
|
960
|
+
}
|
|
961
|
+
|
|
962
|
+
/**
|
|
963
|
+
* Base class for gradient fills
|
|
964
|
+
* @category Gradients
|
|
965
|
+
*/
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* @category Gradients
|
|
969
|
+
*/
|
|
970
|
+
type ColorStop = readonly [number, number, number, number];
|
|
971
|
+
interface ColorStopEntry {
|
|
972
|
+
offset: number;
|
|
973
|
+
color: ColorStop;
|
|
974
|
+
}
|
|
975
|
+
declare abstract class Fill extends WasmObject {
|
|
976
|
+
protected _stops: ColorStopEntry[];
|
|
977
|
+
protected _cleanup(ptr: number): void;
|
|
978
|
+
/**
|
|
979
|
+
* Add a color stop to the gradient
|
|
980
|
+
* @param offset - Position of the stop (0.0 to 1.0)
|
|
981
|
+
* @param color - RGBA color [r, g, b, a] where each value is 0-255
|
|
982
|
+
*/
|
|
983
|
+
addStop(offset: number, color: ColorStop): this;
|
|
984
|
+
/**
|
|
985
|
+
* Clear all pending color stops
|
|
986
|
+
* Use this to reset stops before adding new ones
|
|
987
|
+
*
|
|
988
|
+
* @returns The Fill instance for method chaining
|
|
989
|
+
*
|
|
990
|
+
* @example
|
|
991
|
+
* ```typescript
|
|
992
|
+
* const gradient = new TVG.LinearGradient(0, 0, 200, 0);
|
|
993
|
+
* gradient.addStop(0, [255, 0, 0, 255])
|
|
994
|
+
* .addStop(1, [0, 0, 255, 255]);
|
|
995
|
+
*
|
|
996
|
+
* // Change stops
|
|
997
|
+
* gradient.clearStops()
|
|
998
|
+
* .addStop(0, [0, 255, 0, 255])
|
|
999
|
+
* .addStop(1, [255, 255, 0, 255]);
|
|
1000
|
+
*
|
|
1001
|
+
* shape.fill(gradient);
|
|
1002
|
+
* ```
|
|
1003
|
+
*/
|
|
1004
|
+
clearStops(): this;
|
|
1005
|
+
/**
|
|
1006
|
+
* Replace all color stops with new ones
|
|
1007
|
+
* This is a convenience method that clears existing stops and adds new ones in one call
|
|
1008
|
+
*
|
|
1009
|
+
* @param stops - Variable number of [offset, color] tuples
|
|
1010
|
+
* @returns The Fill instance for method chaining
|
|
1011
|
+
*
|
|
1012
|
+
* @example
|
|
1013
|
+
* ```typescript
|
|
1014
|
+
* const gradient = new TVG.LinearGradient(0, 0, 200, 0);
|
|
1015
|
+
* gradient.setStops(
|
|
1016
|
+
* [0, [255, 0, 0, 255]], // Red at start
|
|
1017
|
+
* [0.5, [255, 255, 0, 255]], // Yellow at middle
|
|
1018
|
+
* [1, [0, 255, 0, 255]] // Green at end
|
|
1019
|
+
* );
|
|
1020
|
+
*
|
|
1021
|
+
* shape.fill(gradient);
|
|
1022
|
+
*
|
|
1023
|
+
* // Later, completely replace stops
|
|
1024
|
+
* gradient.setStops(
|
|
1025
|
+
* [0, [0, 0, 255, 255]], // Blue at start
|
|
1026
|
+
* [1, [255, 0, 255, 255]] // Magenta at end
|
|
1027
|
+
* );
|
|
1028
|
+
*
|
|
1029
|
+
* shape.fill(gradient); // Re-apply with new stops
|
|
1030
|
+
* ```
|
|
1031
|
+
*/
|
|
1032
|
+
setStops(...stops: Array<[number, ColorStop]>): this;
|
|
1033
|
+
/**
|
|
1034
|
+
* Apply collected color stops to the gradient
|
|
1035
|
+
* ColorStop struct: {float offset, uint8_t r, g, b, a} = 8 bytes per stop
|
|
1036
|
+
*/
|
|
1037
|
+
protected _applyStops(): void;
|
|
1038
|
+
/**
|
|
1039
|
+
* Set the gradient spread method
|
|
1040
|
+
*/
|
|
1041
|
+
spread(type: GradientSpread): this;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
/**
|
|
1045
|
+
* Vector path drawing and manipulation
|
|
1046
|
+
*
|
|
1047
|
+
* Shape is the fundamental drawing primitive in ThorVG WebCanvas. It provides methods for
|
|
1048
|
+
* creating paths using moveTo/lineTo/cubicTo commands, as well as convenience methods for
|
|
1049
|
+
* common shapes like rectangles and circles. Shapes can be filled with solid colors or
|
|
1050
|
+
* gradients, and stroked with customizable line styles.
|
|
1051
|
+
*
|
|
1052
|
+
* @category Shapes
|
|
1053
|
+
*
|
|
1054
|
+
* @example
|
|
1055
|
+
* ```typescript
|
|
1056
|
+
* // Basic triangle
|
|
1057
|
+
* const shape = new TVG.Shape();
|
|
1058
|
+
* shape.moveTo(100, 50)
|
|
1059
|
+
* .lineTo(150, 150)
|
|
1060
|
+
* .lineTo(50, 150)
|
|
1061
|
+
* .close()
|
|
1062
|
+
* .fill(255, 0, 0, 255);
|
|
1063
|
+
* canvas.add(shape).render();
|
|
1064
|
+
* ```
|
|
1065
|
+
*
|
|
1066
|
+
* @example
|
|
1067
|
+
* ```typescript
|
|
1068
|
+
* // Rectangle with rounded corners
|
|
1069
|
+
* const rect = new TVG.Shape();
|
|
1070
|
+
* rect.appendRect(50, 50, 200, 100, { rx: 10, ry: 10 })
|
|
1071
|
+
* .fill(0, 120, 255, 255)
|
|
1072
|
+
* .stroke({ width: 3, color: [0, 0, 0, 255] });
|
|
1073
|
+
* ```
|
|
1074
|
+
*
|
|
1075
|
+
* @example
|
|
1076
|
+
* ```typescript
|
|
1077
|
+
* // Circle with gradient fill
|
|
1078
|
+
* const circle = new TVG.Shape();
|
|
1079
|
+
* const gradient = new TVG.RadialGradient(150, 150, 50);
|
|
1080
|
+
* gradient.addStop(0, [255, 255, 255, 255])
|
|
1081
|
+
* .addStop(1, [0, 100, 255, 255]);
|
|
1082
|
+
*
|
|
1083
|
+
* circle.appendCircle(150, 150, 50)
|
|
1084
|
+
* .fill(gradient);
|
|
1085
|
+
* ```
|
|
1086
|
+
*
|
|
1087
|
+
* @example
|
|
1088
|
+
* ```typescript
|
|
1089
|
+
* // Complex path with bezier curves
|
|
1090
|
+
* const shape = new TVG.Shape();
|
|
1091
|
+
* shape.moveTo(50, 100)
|
|
1092
|
+
* .cubicTo(50, 50, 150, 50, 150, 100)
|
|
1093
|
+
* .cubicTo(150, 150, 50, 150, 50, 100)
|
|
1094
|
+
* .close()
|
|
1095
|
+
* .fill(255, 100, 0, 255);
|
|
1096
|
+
* ```
|
|
1097
|
+
*/
|
|
1098
|
+
|
|
1099
|
+
/**
|
|
1100
|
+
* Options for creating rectangles with rounded corners.
|
|
1101
|
+
*
|
|
1102
|
+
* @category Shapes
|
|
1103
|
+
*/
|
|
1104
|
+
interface RectOptions {
|
|
1105
|
+
/** Horizontal corner radius. Default: 0 */
|
|
1106
|
+
rx?: number;
|
|
1107
|
+
/** Vertical corner radius. Default: 0 */
|
|
1108
|
+
ry?: number;
|
|
1109
|
+
/** Path direction. true = clockwise, false = counter-clockwise. Default: true */
|
|
1110
|
+
clockwise?: boolean;
|
|
1111
|
+
}
|
|
1112
|
+
/**
|
|
1113
|
+
* Comprehensive stroke styling options.
|
|
1114
|
+
*
|
|
1115
|
+
* @category Shapes
|
|
1116
|
+
*/
|
|
1117
|
+
interface StrokeOptions {
|
|
1118
|
+
/** Stroke width in pixels */
|
|
1119
|
+
width?: number;
|
|
1120
|
+
/** Stroke color as [r, g, b, a] with values 0-255. Alpha is optional, defaults to 255. */
|
|
1121
|
+
color?: readonly [number, number, number, number?];
|
|
1122
|
+
/** Gradient fill for the stroke */
|
|
1123
|
+
gradient?: Fill;
|
|
1124
|
+
/** Line cap style: StrokeCap.Butt, StrokeCap.Round, or StrokeCap.Square. Default: StrokeCap.Butt */
|
|
1125
|
+
cap?: StrokeCap;
|
|
1126
|
+
/** Line join style: StrokeJoin.Miter, StrokeJoin.Round, or StrokeJoin.Bevel. Default: StrokeJoin.Miter */
|
|
1127
|
+
join?: StrokeJoin;
|
|
1128
|
+
/** Miter limit for 'miter' joins. Default: 4 */
|
|
1129
|
+
miterLimit?: number;
|
|
1130
|
+
/** Dash pattern as array of dash/gap lengths. Empty array [] resets to solid line. */
|
|
1131
|
+
dash?: number[];
|
|
1132
|
+
/** Dash pattern offset. Use with dash to shift pattern start position. */
|
|
1133
|
+
dashOffset?: number;
|
|
1134
|
+
}
|
|
1135
|
+
/**
|
|
1136
|
+
* Shape class for creating and manipulating vector graphics paths.
|
|
1137
|
+
*
|
|
1138
|
+
* Extends {@link Paint} to inherit transformation and opacity methods.
|
|
1139
|
+
*
|
|
1140
|
+
* @category Shapes
|
|
1141
|
+
*
|
|
1142
|
+
* @example
|
|
1143
|
+
* ```typescript
|
|
1144
|
+
* // Drawing basic shapes
|
|
1145
|
+
* const shape = new TVG.Shape();
|
|
1146
|
+
*
|
|
1147
|
+
* // Rectangle with rounded corners
|
|
1148
|
+
* shape.appendRect(50, 50, 200, 100, 10)
|
|
1149
|
+
* .fill(255, 100, 100, 255)
|
|
1150
|
+
* .stroke(50, 50, 50, 255, 2);
|
|
1151
|
+
*
|
|
1152
|
+
* canvas.add(shape);
|
|
1153
|
+
* ```
|
|
1154
|
+
*
|
|
1155
|
+
* @example
|
|
1156
|
+
* ```typescript
|
|
1157
|
+
* // Drawing paths with gradients
|
|
1158
|
+
* const shape = new TVG.Shape();
|
|
1159
|
+
* shape.moveTo(100, 100)
|
|
1160
|
+
* .lineTo(200, 150)
|
|
1161
|
+
* .lineTo(150, 250)
|
|
1162
|
+
* .close();
|
|
1163
|
+
*
|
|
1164
|
+
* const gradient = new TVG.LinearGradient(100, 100, 200, 250);
|
|
1165
|
+
* gradient.addStop(0, [255, 0, 0, 255])
|
|
1166
|
+
* .addStop(1, [0, 0, 255, 255]);
|
|
1167
|
+
*
|
|
1168
|
+
* shape.fillGradient(gradient);
|
|
1169
|
+
* canvas.add(shape);
|
|
1170
|
+
* ```
|
|
1171
|
+
*
|
|
1172
|
+
* @example
|
|
1173
|
+
* ```typescript
|
|
1174
|
+
* // Complex path with transformations
|
|
1175
|
+
* const shape = new TVG.Shape();
|
|
1176
|
+
* shape.appendCircle(0, 0, 50)
|
|
1177
|
+
* .fill(100, 200, 255, 255)
|
|
1178
|
+
* .translate(400, 300)
|
|
1179
|
+
* .scale(1.5)
|
|
1180
|
+
* .rotate(45);
|
|
1181
|
+
*
|
|
1182
|
+
* canvas.add(shape);
|
|
1183
|
+
* ```
|
|
1184
|
+
*/
|
|
1185
|
+
declare class Shape extends Paint {
|
|
1186
|
+
constructor(ptr?: number);
|
|
1187
|
+
protected _createInstance(ptr: number): Shape;
|
|
1188
|
+
/**
|
|
1189
|
+
* Moves the path cursor to a new point without drawing.
|
|
1190
|
+
*
|
|
1191
|
+
* This starts a new subpath at the specified coordinates. Subsequent drawing commands
|
|
1192
|
+
* will start from this point.
|
|
1193
|
+
*
|
|
1194
|
+
* @param x - X coordinate
|
|
1195
|
+
* @param y - Y coordinate
|
|
1196
|
+
* @returns The Shape instance for method chaining
|
|
1197
|
+
*
|
|
1198
|
+
* @example
|
|
1199
|
+
* ```typescript
|
|
1200
|
+
* shape.moveTo(100, 100)
|
|
1201
|
+
* .lineTo(200, 200);
|
|
1202
|
+
* ```
|
|
1203
|
+
*/
|
|
1204
|
+
moveTo(x: number, y: number): this;
|
|
1205
|
+
/**
|
|
1206
|
+
* Draws a straight line from the current point to the specified coordinates.
|
|
1207
|
+
*
|
|
1208
|
+
* @param x - End X coordinate
|
|
1209
|
+
* @param y - End Y coordinate
|
|
1210
|
+
* @returns The Shape instance for method chaining
|
|
1211
|
+
*
|
|
1212
|
+
* @example
|
|
1213
|
+
* ```typescript
|
|
1214
|
+
* // Draw a triangle
|
|
1215
|
+
* shape.moveTo(100, 50)
|
|
1216
|
+
* .lineTo(150, 150)
|
|
1217
|
+
* .lineTo(50, 150)
|
|
1218
|
+
* .close();
|
|
1219
|
+
* ```
|
|
1220
|
+
*/
|
|
1221
|
+
lineTo(x: number, y: number): this;
|
|
1222
|
+
/**
|
|
1223
|
+
* Draws a cubic Bézier curve from the current point to (x, y).
|
|
1224
|
+
*
|
|
1225
|
+
* @param cx1 - X coordinate of first control point
|
|
1226
|
+
* @param cy1 - Y coordinate of first control point
|
|
1227
|
+
* @param cx2 - X coordinate of second control point
|
|
1228
|
+
* @param cy2 - Y coordinate of second control point
|
|
1229
|
+
* @param x - End X coordinate
|
|
1230
|
+
* @param y - End Y coordinate
|
|
1231
|
+
* @returns The Shape instance for method chaining
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* ```typescript
|
|
1235
|
+
* // Draw a smooth curve
|
|
1236
|
+
* shape.moveTo(50, 100)
|
|
1237
|
+
* .cubicTo(50, 50, 150, 50, 150, 100);
|
|
1238
|
+
* ```
|
|
1239
|
+
*/
|
|
1240
|
+
cubicTo(cx1: number, cy1: number, cx2: number, cy2: number, x: number, y: number): this;
|
|
1241
|
+
/**
|
|
1242
|
+
* Closes the current subpath by drawing a straight line back to the starting point.
|
|
1243
|
+
*
|
|
1244
|
+
* @returns The Shape instance for method chaining
|
|
1245
|
+
*
|
|
1246
|
+
* @example
|
|
1247
|
+
* ```typescript
|
|
1248
|
+
* shape.moveTo(100, 50)
|
|
1249
|
+
* .lineTo(150, 150)
|
|
1250
|
+
* .lineTo(50, 150)
|
|
1251
|
+
* .close(); // Completes the triangle
|
|
1252
|
+
* ```
|
|
1253
|
+
*/
|
|
1254
|
+
close(): this;
|
|
1255
|
+
/**
|
|
1256
|
+
* Appends a rectangle path to the shape.
|
|
1257
|
+
*
|
|
1258
|
+
* Creates a rectangular path with optional rounded corners. Multiple rectangles
|
|
1259
|
+
* can be added to the same shape.
|
|
1260
|
+
*
|
|
1261
|
+
* @param x - X coordinate of the top-left corner
|
|
1262
|
+
* @param y - Y coordinate of the top-left corner
|
|
1263
|
+
* @param w - Width of the rectangle
|
|
1264
|
+
* @param h - Height of the rectangle
|
|
1265
|
+
* @param options - Optional corner rounding and path direction
|
|
1266
|
+
* @returns The Shape instance for method chaining
|
|
1267
|
+
*
|
|
1268
|
+
* @example
|
|
1269
|
+
* ```typescript
|
|
1270
|
+
* // Simple rectangle
|
|
1271
|
+
* shape.appendRect(50, 50, 200, 100);
|
|
1272
|
+
* ```
|
|
1273
|
+
*
|
|
1274
|
+
* @example
|
|
1275
|
+
* ```typescript
|
|
1276
|
+
* // Rounded rectangle
|
|
1277
|
+
* shape.appendRect(50, 50, 200, 100, { rx: 10, ry: 10 });
|
|
1278
|
+
* ```
|
|
1279
|
+
*/
|
|
1280
|
+
appendRect(x: number, y: number, w: number, h: number, options?: RectOptions): this;
|
|
1281
|
+
/**
|
|
1282
|
+
* Appends a circle or ellipse path to the shape.
|
|
1283
|
+
*
|
|
1284
|
+
* Creates a circular or elliptical path. If only one radius is provided,
|
|
1285
|
+
* creates a perfect circle. If two radii are provided, creates an ellipse.
|
|
1286
|
+
*
|
|
1287
|
+
* @param cx - X coordinate of the center
|
|
1288
|
+
* @param cy - Y coordinate of the center
|
|
1289
|
+
* @param rx - Horizontal radius
|
|
1290
|
+
* @param ry - Vertical radius (defaults to rx for perfect circle)
|
|
1291
|
+
* @param clockwise - Path direction. Default: true
|
|
1292
|
+
* @returns The Shape instance for method chaining
|
|
1293
|
+
*
|
|
1294
|
+
* @example
|
|
1295
|
+
* ```typescript
|
|
1296
|
+
* // Perfect circle
|
|
1297
|
+
* shape.appendCircle(150, 150, 50)
|
|
1298
|
+
* .fill(255, 0, 0, 255);
|
|
1299
|
+
* ```
|
|
1300
|
+
*
|
|
1301
|
+
* @example
|
|
1302
|
+
* ```typescript
|
|
1303
|
+
* // Ellipse
|
|
1304
|
+
* shape.appendCircle(150, 150, 80, 50)
|
|
1305
|
+
* .fill(0, 100, 255, 255);
|
|
1306
|
+
* ```
|
|
1307
|
+
*/
|
|
1308
|
+
appendCircle(cx: number, cy: number, rx: number, ry?: number, clockwise?: boolean): this;
|
|
1309
|
+
/**
|
|
1310
|
+
* Sets the fill rule for the shape.
|
|
1311
|
+
*
|
|
1312
|
+
* The fill rule determines how the interior of a shape is calculated when the path
|
|
1313
|
+
* intersects itself or when multiple subpaths overlap.
|
|
1314
|
+
*
|
|
1315
|
+
* @param rule - Fill rule: 'winding' (non-zero) or 'evenodd'
|
|
1316
|
+
* @returns The Shape instance for method chaining
|
|
1317
|
+
*
|
|
1318
|
+
* @example
|
|
1319
|
+
* ```typescript
|
|
1320
|
+
* const star = new TVG.Shape();
|
|
1321
|
+
* // Draw a self-intersecting star
|
|
1322
|
+
* star.moveTo(100, 10)
|
|
1323
|
+
* .lineTo(40, 180)
|
|
1324
|
+
* .lineTo(190, 60)
|
|
1325
|
+
* .lineTo(10, 60)
|
|
1326
|
+
* .lineTo(160, 180)
|
|
1327
|
+
* .close()
|
|
1328
|
+
* .fillRule(FillRule.EvenOdd) // Use even-odd rule for star shape
|
|
1329
|
+
* .fill(255, 200, 0, 255);
|
|
1330
|
+
* ```
|
|
1331
|
+
*/
|
|
1332
|
+
fillRule(rule: FillRule): this;
|
|
1333
|
+
/**
|
|
1334
|
+
* Sets the trim of the shape along the defined path segment, controlling which part is visible.
|
|
1335
|
+
*
|
|
1336
|
+
* This method allows you to trim/cut paths, showing only a portion from the begin to end point.
|
|
1337
|
+
* This is particularly useful for animations (e.g., drawing a line progressively) or creating
|
|
1338
|
+
* partial shapes like arcs from circles.
|
|
1339
|
+
*
|
|
1340
|
+
* If the values exceed the 0-1 range, they wrap around (similar to angle wrapping).
|
|
1341
|
+
*
|
|
1342
|
+
* @param begin - Start of the segment to display (0.0 to 1.0, where 0 is the path start)
|
|
1343
|
+
* @param end - End of the segment to display (0.0 to 1.0, where 1 is the path end)
|
|
1344
|
+
* @param simultaneous - How to handle multiple paths within the shape:
|
|
1345
|
+
* - `true` (default): Trimming applied simultaneously to all paths
|
|
1346
|
+
* - `false`: All paths treated as one entity with combined length
|
|
1347
|
+
* @returns The Shape instance for method chaining
|
|
1348
|
+
*
|
|
1349
|
+
* @example
|
|
1350
|
+
* ```typescript
|
|
1351
|
+
* // Draw half a circle (arc)
|
|
1352
|
+
* const arc = new TVG.Shape();
|
|
1353
|
+
* arc.appendCircle(150, 150, 100)
|
|
1354
|
+
* .trimPath(0, 0.5) // Show only first half
|
|
1355
|
+
* .stroke({ width: 5, color: [255, 0, 0, 255] });
|
|
1356
|
+
* ```
|
|
1357
|
+
*
|
|
1358
|
+
* @example
|
|
1359
|
+
* ```typescript
|
|
1360
|
+
* // Animated line drawing effect
|
|
1361
|
+
* const line = new TVG.Shape();
|
|
1362
|
+
* line.moveTo(50, 100)
|
|
1363
|
+
* .lineTo(250, 100)
|
|
1364
|
+
* .trimPath(0, progress) // progress from 0 to 1
|
|
1365
|
+
* .stroke({ width: 3, color: [0, 100, 255, 255] });
|
|
1366
|
+
* ```
|
|
1367
|
+
*
|
|
1368
|
+
* @example
|
|
1369
|
+
* ```typescript
|
|
1370
|
+
* // Trim multiple paths separately
|
|
1371
|
+
* const shape = new TVG.Shape();
|
|
1372
|
+
* shape.appendRect(50, 50, 100, 100)
|
|
1373
|
+
* .appendCircle(200, 100, 50)
|
|
1374
|
+
* .trimPath(0.25, 0.75, true) // Trim each path separately
|
|
1375
|
+
* .stroke({ width: 2, color: [0, 0, 0, 255] });
|
|
1376
|
+
* ```
|
|
1377
|
+
*/
|
|
1378
|
+
trimPath(begin: number, end: number, simultaneous?: boolean): this;
|
|
1379
|
+
/**
|
|
1380
|
+
* Sets the fill for the shape with a gradient.
|
|
1381
|
+
*
|
|
1382
|
+
* @param gradient - LinearGradient or RadialGradient to use as fill
|
|
1383
|
+
* @returns The Shape instance for method chaining
|
|
1384
|
+
*/
|
|
1385
|
+
fill(gradient: Fill): this;
|
|
1386
|
+
/**
|
|
1387
|
+
* Sets the fill for the shape with a solid color.
|
|
1388
|
+
*
|
|
1389
|
+
* @param r - Red component (0-255)
|
|
1390
|
+
* @param g - Green component (0-255)
|
|
1391
|
+
* @param b - Blue component (0-255)
|
|
1392
|
+
* @param a - Alpha component (0-255). Default: 255 (opaque)
|
|
1393
|
+
* @returns The Shape instance for method chaining
|
|
1394
|
+
*/
|
|
1395
|
+
fill(r: number, g: number, b: number, a?: number): this;
|
|
1396
|
+
/**
|
|
1397
|
+
* Sets the stroke width for the shape.
|
|
1398
|
+
*
|
|
1399
|
+
* @param width - Stroke width in pixels
|
|
1400
|
+
* @returns The Shape instance for method chaining
|
|
1401
|
+
*/
|
|
1402
|
+
stroke(width: number): this;
|
|
1403
|
+
/**
|
|
1404
|
+
* Sets comprehensive stroke styling options for the shape.
|
|
1405
|
+
*
|
|
1406
|
+
* @param options - Stroke configuration including width, color, gradient, caps, joins, and miter limit
|
|
1407
|
+
* @returns The Shape instance for method chaining
|
|
1408
|
+
*/
|
|
1409
|
+
stroke(options: StrokeOptions): this;
|
|
1410
|
+
/**
|
|
1411
|
+
* Resets the shape's path data while retaining fill and stroke properties.
|
|
1412
|
+
*
|
|
1413
|
+
* This method clears all path commands (moveTo, lineTo, cubicTo, appendRect, etc.)
|
|
1414
|
+
* but preserves the shape's fill color, gradient, stroke settings, and transformations.
|
|
1415
|
+
* This is useful for animations where you want to redraw the path while keeping
|
|
1416
|
+
* the same styling.
|
|
1417
|
+
*
|
|
1418
|
+
* @returns The Shape instance for method chaining
|
|
1419
|
+
*
|
|
1420
|
+
* @example
|
|
1421
|
+
* ```typescript
|
|
1422
|
+
* // Animating shape changes while keeping styles
|
|
1423
|
+
* const shape = new TVG.Shape();
|
|
1424
|
+
* shape.appendRect(0, 0, 100, 100);
|
|
1425
|
+
* shape.fill(255, 0, 0, 255);
|
|
1426
|
+
* shape.stroke({ width: 5, color: [0, 0, 255, 255] });
|
|
1427
|
+
*
|
|
1428
|
+
* // Later, change the shape but keep the fill/stroke
|
|
1429
|
+
* shape.reset();
|
|
1430
|
+
* shape.appendCircle(50, 50, 40);
|
|
1431
|
+
* // Still has red fill and blue stroke!
|
|
1432
|
+
* ```
|
|
1433
|
+
*/
|
|
1434
|
+
reset(): this;
|
|
1435
|
+
}
|
|
1436
|
+
|
|
1437
|
+
/**
|
|
1438
|
+
* Group and manage multiple paint objects
|
|
1439
|
+
* @category Scene
|
|
1440
|
+
*/
|
|
1441
|
+
|
|
1442
|
+
/**
|
|
1443
|
+
* Scene class for hierarchical grouping of Paint objects
|
|
1444
|
+
* @category Scene
|
|
1445
|
+
*
|
|
1446
|
+
* @example
|
|
1447
|
+
* ```typescript
|
|
1448
|
+
* // Grouping shapes in a scene
|
|
1449
|
+
* const scene = new TVG.Scene();
|
|
1450
|
+
*
|
|
1451
|
+
* const background = new TVG.Shape();
|
|
1452
|
+
* background.appendRect(0, 0, 800, 600).fill(240, 240, 240, 255);
|
|
1453
|
+
*
|
|
1454
|
+
* const circle = new TVG.Shape();
|
|
1455
|
+
* circle.appendCircle(100, 100, 50).fill(255, 100, 100, 255);
|
|
1456
|
+
*
|
|
1457
|
+
* scene.add(background);
|
|
1458
|
+
* scene.add(circle);
|
|
1459
|
+
* canvas.add(scene);
|
|
1460
|
+
* ```
|
|
1461
|
+
*
|
|
1462
|
+
* @example
|
|
1463
|
+
* ```typescript
|
|
1464
|
+
* // Scene transformations affect all children
|
|
1465
|
+
* const scene = new TVG.Scene();
|
|
1466
|
+
*
|
|
1467
|
+
* for (let i = 0; i < 5; i++) {
|
|
1468
|
+
* const shape = new TVG.Shape();
|
|
1469
|
+
* shape.appendRect(i * 60, 100, 50, 50)
|
|
1470
|
+
* .fill(100 + i * 30, 150, 255 - i * 30, 255);
|
|
1471
|
+
* scene.add(shape);
|
|
1472
|
+
* }
|
|
1473
|
+
*
|
|
1474
|
+
* // Transform entire group
|
|
1475
|
+
* scene.translate(200, 200).rotate(30);
|
|
1476
|
+
* canvas.add(scene);
|
|
1477
|
+
* ```
|
|
1478
|
+
*/
|
|
1479
|
+
declare class Scene extends Paint {
|
|
1480
|
+
constructor(ptr?: number);
|
|
1481
|
+
protected _createInstance(ptr: number): Scene;
|
|
1482
|
+
/**
|
|
1483
|
+
* Add a paint to the scene
|
|
1484
|
+
*/
|
|
1485
|
+
add(paint: Paint): this;
|
|
1486
|
+
/**
|
|
1487
|
+
* Remove paint(s) from the scene
|
|
1488
|
+
* If no paint is provided, removes all paints
|
|
1489
|
+
*/
|
|
1490
|
+
remove(paint?: Paint): this;
|
|
1491
|
+
/**
|
|
1492
|
+
* Clear all paints from the scene (alias for remove())
|
|
1493
|
+
*/
|
|
1494
|
+
clear(): this;
|
|
1495
|
+
/**
|
|
1496
|
+
* Reset all previously applied scene effects, restoring the scene to its original state.
|
|
1497
|
+
*
|
|
1498
|
+
* @returns The Scene instance for method chaining
|
|
1499
|
+
*
|
|
1500
|
+
* @example
|
|
1501
|
+
* ```typescript
|
|
1502
|
+
* const scene = new TVG.Scene();
|
|
1503
|
+
* scene.dropShadow(128, 128, 128, 200, 45, 5, 2, 60);
|
|
1504
|
+
* scene.resetEffects(); // Remove all effects
|
|
1505
|
+
* ```
|
|
1506
|
+
*/
|
|
1507
|
+
resetEffects(): this;
|
|
1508
|
+
/**
|
|
1509
|
+
* Apply a Gaussian blur effect to the scene.
|
|
1510
|
+
*
|
|
1511
|
+
* @param sigma - Blur intensity (> 0)
|
|
1512
|
+
* @param direction - Blur direction: 0 (both), 1 (horizontal), 2 (vertical)
|
|
1513
|
+
* @param border - Border mode: 0 (duplicate), 1 (wrap)
|
|
1514
|
+
* @param quality - Blur quality (0-100)
|
|
1515
|
+
* @returns The Scene instance for method chaining
|
|
1516
|
+
*
|
|
1517
|
+
* @example
|
|
1518
|
+
* ```typescript
|
|
1519
|
+
* const scene = new TVG.Scene();
|
|
1520
|
+
* scene.add(shape1);
|
|
1521
|
+
* scene.add(shape2);
|
|
1522
|
+
* scene.gaussianBlur(1.5, 0, 0, 75); // Apply blur to entire scene
|
|
1523
|
+
* ```
|
|
1524
|
+
*/
|
|
1525
|
+
gaussianBlur(sigma: number, direction?: number, border?: number, quality?: number): this;
|
|
1526
|
+
/**
|
|
1527
|
+
* Apply a drop shadow effect with Gaussian blur filter to the scene.
|
|
1528
|
+
*
|
|
1529
|
+
* @param r - Red component (0-255)
|
|
1530
|
+
* @param g - Green component (0-255)
|
|
1531
|
+
* @param b - Blue component (0-255)
|
|
1532
|
+
* @param a - Alpha/opacity (0-255)
|
|
1533
|
+
* @param angle - Shadow angle in degrees (0-360)
|
|
1534
|
+
* @param distance - Shadow distance/offset
|
|
1535
|
+
* @param sigma - Blur intensity for the shadow (> 0)
|
|
1536
|
+
* @param quality - Blur quality (0-100)
|
|
1537
|
+
* @returns The Scene instance for method chaining
|
|
1538
|
+
*
|
|
1539
|
+
* @example
|
|
1540
|
+
* ```typescript
|
|
1541
|
+
* const scene = new TVG.Scene();
|
|
1542
|
+
* scene.add(shape);
|
|
1543
|
+
* // Add gray drop shadow at 45° angle, 5px distance, 2px blur
|
|
1544
|
+
* scene.dropShadow(128, 128, 128, 200, 45, 5, 2, 60);
|
|
1545
|
+
* ```
|
|
1546
|
+
*/
|
|
1547
|
+
dropShadow(r: number, g: number, b: number, a: number, angle: number, distance: number, sigma: number, quality?: number): this;
|
|
1548
|
+
/**
|
|
1549
|
+
* Override the scene content color with a given fill color.
|
|
1550
|
+
*
|
|
1551
|
+
* @param r - Red component (0-255)
|
|
1552
|
+
* @param g - Green component (0-255)
|
|
1553
|
+
* @param b - Blue component (0-255)
|
|
1554
|
+
* @param a - Alpha/opacity (0-255)
|
|
1555
|
+
* @returns The Scene instance for method chaining
|
|
1556
|
+
*
|
|
1557
|
+
* @example
|
|
1558
|
+
* ```typescript
|
|
1559
|
+
* const scene = new TVG.Scene();
|
|
1560
|
+
* scene.add(shape1);
|
|
1561
|
+
* scene.add(shape2);
|
|
1562
|
+
* scene.fillEffect(255, 0, 0, 128); // Fill entire scene with semi-transparent red
|
|
1563
|
+
* ```
|
|
1564
|
+
*/
|
|
1565
|
+
fillEffect(r: number, g: number, b: number, a: number): this;
|
|
1566
|
+
/**
|
|
1567
|
+
* Apply a tint effect to the scene using black and white color parameters.
|
|
1568
|
+
*
|
|
1569
|
+
* @param blackR - Black tint red component (0-255)
|
|
1570
|
+
* @param blackG - Black tint green component (0-255)
|
|
1571
|
+
* @param blackB - Black tint blue component (0-255)
|
|
1572
|
+
* @param whiteR - White tint red component (0-255)
|
|
1573
|
+
* @param whiteG - White tint green component (0-255)
|
|
1574
|
+
* @param whiteB - White tint blue component (0-255)
|
|
1575
|
+
* @param intensity - Tint intensity (0-100)
|
|
1576
|
+
* @returns The Scene instance for method chaining
|
|
1577
|
+
*
|
|
1578
|
+
* @example
|
|
1579
|
+
* ```typescript
|
|
1580
|
+
* const scene = new TVG.Scene();
|
|
1581
|
+
* scene.add(picture);
|
|
1582
|
+
* // Apply sepia-like tint
|
|
1583
|
+
* scene.tint(112, 66, 20, 255, 236, 184, 50);
|
|
1584
|
+
* ```
|
|
1585
|
+
*/
|
|
1586
|
+
tint(blackR: number, blackG: number, blackB: number, whiteR: number, whiteG: number, whiteB: number, intensity: number): this;
|
|
1587
|
+
/**
|
|
1588
|
+
* Apply a tritone color effect to the scene using three color parameters for shadows, midtones, and highlights.
|
|
1589
|
+
* A blending factor determines the mix between the original color and the tritone colors.
|
|
1590
|
+
*
|
|
1591
|
+
* @param shadowR - Shadow red component (0-255)
|
|
1592
|
+
* @param shadowG - Shadow green component (0-255)
|
|
1593
|
+
* @param shadowB - Shadow blue component (0-255)
|
|
1594
|
+
* @param midtoneR - Midtone red component (0-255)
|
|
1595
|
+
* @param midtoneG - Midtone green component (0-255)
|
|
1596
|
+
* @param midtoneB - Midtone blue component (0-255)
|
|
1597
|
+
* @param highlightR - Highlight red component (0-255)
|
|
1598
|
+
* @param highlightG - Highlight green component (0-255)
|
|
1599
|
+
* @param highlightB - Highlight blue component (0-255)
|
|
1600
|
+
* @param blend - Blend factor (0-255)
|
|
1601
|
+
* @returns The Scene instance for method chaining
|
|
1602
|
+
*
|
|
1603
|
+
* @example
|
|
1604
|
+
* ```typescript
|
|
1605
|
+
* const scene = new TVG.Scene();
|
|
1606
|
+
* scene.add(picture);
|
|
1607
|
+
* // Apply tritone: dark blue shadows, gray midtones, yellow highlights
|
|
1608
|
+
* scene.tritone(0, 0, 128, 128, 128, 128, 255, 255, 0, 128);
|
|
1609
|
+
* ```
|
|
1610
|
+
*/
|
|
1611
|
+
tritone(shadowR: number, shadowG: number, shadowB: number, midtoneR: number, midtoneG: number, midtoneB: number, highlightR: number, highlightG: number, highlightB: number, blend: number): this;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
/**
|
|
1615
|
+
* Load and render images and vector files
|
|
1616
|
+
* @category Picture
|
|
1617
|
+
*/
|
|
1618
|
+
|
|
1619
|
+
/**
|
|
1620
|
+
* @category Picture
|
|
1621
|
+
*/
|
|
1622
|
+
interface LoadDataOptions {
|
|
1623
|
+
/** MIME type or format hint (e.g., 'svg', 'png', 'jpg', 'raw') */
|
|
1624
|
+
type?: MimeType;
|
|
1625
|
+
/** Width of raw image (required for type='raw') */
|
|
1626
|
+
width?: number;
|
|
1627
|
+
/** Height of raw image (required for type='raw') */
|
|
1628
|
+
height?: number;
|
|
1629
|
+
/** Color space of raw image (required for type='raw', default: ColorSpace.ARGB8888) */
|
|
1630
|
+
colorSpace?: ColorSpace;
|
|
1631
|
+
}
|
|
1632
|
+
/**
|
|
1633
|
+
* @category Picture
|
|
1634
|
+
*/
|
|
1635
|
+
interface PictureSize {
|
|
1636
|
+
width: number;
|
|
1637
|
+
height: number;
|
|
1638
|
+
}
|
|
1639
|
+
/**
|
|
1640
|
+
* Picture class for loading and displaying images and vector graphics
|
|
1641
|
+
* @category Picture
|
|
1642
|
+
*
|
|
1643
|
+
* @example
|
|
1644
|
+
* ```typescript
|
|
1645
|
+
* // Loading an SVG image
|
|
1646
|
+
* const picture = new TVG.Picture();
|
|
1647
|
+
*
|
|
1648
|
+
* fetch('/images/logo.svg')
|
|
1649
|
+
* .then(res => res.text())
|
|
1650
|
+
* .then(svgData => {
|
|
1651
|
+
* picture.load(svgData, { type: 'svg' });
|
|
1652
|
+
* const size = picture.size();
|
|
1653
|
+
* picture.size(200, 200 * size.height / size.width); // Scale
|
|
1654
|
+
* canvas.add(picture).render();
|
|
1655
|
+
* });
|
|
1656
|
+
* ```
|
|
1657
|
+
*
|
|
1658
|
+
* @example
|
|
1659
|
+
* ```typescript
|
|
1660
|
+
* // Loading a Lottie animation as static image
|
|
1661
|
+
* const picture = new TVG.Picture();
|
|
1662
|
+
*
|
|
1663
|
+
* fetch('/animations/loading.json')
|
|
1664
|
+
* .then(res => res.text())
|
|
1665
|
+
* .then(lottieData => {
|
|
1666
|
+
* picture.load(lottieData, { type: 'lottie' });
|
|
1667
|
+
* picture.translate(400, 300);
|
|
1668
|
+
* canvas.add(picture);
|
|
1669
|
+
* });
|
|
1670
|
+
* ```
|
|
1671
|
+
*/
|
|
1672
|
+
declare class Picture extends Paint {
|
|
1673
|
+
constructor(ptr?: number, skipRegistry?: boolean);
|
|
1674
|
+
protected _createInstance(ptr: number): Picture;
|
|
1675
|
+
/**
|
|
1676
|
+
* Load picture from raw data (Uint8Array or string for SVG)
|
|
1677
|
+
* @param data - Raw image data as Uint8Array or SVG string
|
|
1678
|
+
* @param options - Load options including type hint
|
|
1679
|
+
*/
|
|
1680
|
+
load(data: Uint8Array | string, options?: LoadDataOptions): this;
|
|
1681
|
+
/**
|
|
1682
|
+
* Set the size of the picture (scales it)
|
|
1683
|
+
* @param width - Target width
|
|
1684
|
+
* @param height - Target height
|
|
1685
|
+
*/
|
|
1686
|
+
size(width: number, height: number): this;
|
|
1687
|
+
/**
|
|
1688
|
+
* Get the current size of the picture
|
|
1689
|
+
*/
|
|
1690
|
+
size(): PictureSize;
|
|
1691
|
+
}
|
|
1692
|
+
|
|
1693
|
+
/**
|
|
1694
|
+
* Render text with fonts and styling
|
|
1695
|
+
* @category Text
|
|
1696
|
+
*/
|
|
1697
|
+
|
|
1698
|
+
/**
|
|
1699
|
+
* @category Text
|
|
1700
|
+
*/
|
|
1701
|
+
interface TextLayout {
|
|
1702
|
+
width: number;
|
|
1703
|
+
height?: number;
|
|
1704
|
+
}
|
|
1705
|
+
/**
|
|
1706
|
+
* @category Text
|
|
1707
|
+
*/
|
|
1708
|
+
interface TextOutline {
|
|
1709
|
+
width: number;
|
|
1710
|
+
color: readonly [number, number, number];
|
|
1711
|
+
}
|
|
1712
|
+
/**
|
|
1713
|
+
* Text rendering class with font support
|
|
1714
|
+
* @category Text
|
|
1715
|
+
*
|
|
1716
|
+
* @example
|
|
1717
|
+
* ```typescript
|
|
1718
|
+
* // Basic text rendering
|
|
1719
|
+
* const text = new TVG.Text();
|
|
1720
|
+
* text.font('Arial', 48)
|
|
1721
|
+
* .text('Hello ThorVG!')
|
|
1722
|
+
* .fill(50, 50, 50, 255)
|
|
1723
|
+
* .translate(100, 200);
|
|
1724
|
+
*
|
|
1725
|
+
* canvas.add(text);
|
|
1726
|
+
* ```
|
|
1727
|
+
*
|
|
1728
|
+
* @example
|
|
1729
|
+
* ```typescript
|
|
1730
|
+
* // Text with custom font and styling
|
|
1731
|
+
* // Load custom font first
|
|
1732
|
+
* const fontData = await fetch('/fonts/custom.ttf').then(r => r.arrayBuffer());
|
|
1733
|
+
* TVG.Font.load('CustomFont', new Uint8Array(fontData));
|
|
1734
|
+
*
|
|
1735
|
+
* const text = new TVG.Text();
|
|
1736
|
+
* text.font('CustomFont', 64)
|
|
1737
|
+
* .text('Custom Font')
|
|
1738
|
+
* .fill(100, 150, 255, 255)
|
|
1739
|
+
* .stroke(50, 50, 50, 255, 2);
|
|
1740
|
+
*
|
|
1741
|
+
* canvas.add(text);
|
|
1742
|
+
* ```
|
|
1743
|
+
*
|
|
1744
|
+
* @example
|
|
1745
|
+
* ```typescript
|
|
1746
|
+
* // Multi-line text with wrapping
|
|
1747
|
+
* const text = new TVG.Text();
|
|
1748
|
+
* text.font('Arial')
|
|
1749
|
+
* .fontSize(24)
|
|
1750
|
+
* .text('This is a long text that will wrap across multiple lines')
|
|
1751
|
+
* .fill(50, 50, 50)
|
|
1752
|
+
* .layout(300, 200)
|
|
1753
|
+
* .wrap(TextWrapMode.Word);
|
|
1754
|
+
*
|
|
1755
|
+
* canvas.add(text);
|
|
1756
|
+
* ```
|
|
1757
|
+
*/
|
|
1758
|
+
declare class Text extends Paint {
|
|
1759
|
+
constructor(ptr?: number);
|
|
1760
|
+
protected _createInstance(ptr: number): Text;
|
|
1761
|
+
/**
|
|
1762
|
+
* Set the font to use for this text
|
|
1763
|
+
* @param name - Font name (previously loaded via Font.load()) or "default"
|
|
1764
|
+
*/
|
|
1765
|
+
font(name: string): this;
|
|
1766
|
+
/**
|
|
1767
|
+
* Set the text content (UTF-8 supported)
|
|
1768
|
+
* @param content - Text content to display
|
|
1769
|
+
*/
|
|
1770
|
+
text(content: string): this;
|
|
1771
|
+
/**
|
|
1772
|
+
* Set the font size
|
|
1773
|
+
* @param size - Font size in pixels
|
|
1774
|
+
*/
|
|
1775
|
+
fontSize(size: number): this;
|
|
1776
|
+
/**
|
|
1777
|
+
* Set text color (RGB) or fill with gradient
|
|
1778
|
+
*/
|
|
1779
|
+
fill(gradient: Fill): this;
|
|
1780
|
+
fill(r: number, g: number, b: number): this;
|
|
1781
|
+
/**
|
|
1782
|
+
* Set text alignment/anchor point
|
|
1783
|
+
* @param x - Horizontal alignment/anchor in [0..1]: 0=left/start, 0.5=center, 1=right/end (Default: 0)
|
|
1784
|
+
* @param y - Vertical alignment/anchor in [0..1]: 0=top, 0.5=middle, 1=bottom (Default: 0)
|
|
1785
|
+
*/
|
|
1786
|
+
align(x: number, y: number): this;
|
|
1787
|
+
/**
|
|
1788
|
+
* Set text layout constraints (for wrapping)
|
|
1789
|
+
* @param width - Maximum width (0 = no constraint)
|
|
1790
|
+
* @param height - Maximum height (0 = no constraint)
|
|
1791
|
+
*/
|
|
1792
|
+
layout(width: number, height?: number): this;
|
|
1793
|
+
/**
|
|
1794
|
+
* Set text wrap mode
|
|
1795
|
+
* @param mode - Wrap mode: TextWrapMode.None, TextWrapMode.Character, TextWrapMode.Word, TextWrapMode.Smart, or TextWrapMode.Ellipsis
|
|
1796
|
+
*/
|
|
1797
|
+
wrap(mode: TextWrapMode): this;
|
|
1798
|
+
/**
|
|
1799
|
+
* Set text spacing (letter and line spacing)
|
|
1800
|
+
* @param letter - Letter spacing scale factor (1.0 = default, >1.0 = wider, <1.0 = narrower)
|
|
1801
|
+
* @param line - Line spacing scale factor (1.0 = default, >1.0 = wider, <1.0 = narrower)
|
|
1802
|
+
*/
|
|
1803
|
+
spacing(letter: number, line: number): this;
|
|
1804
|
+
/**
|
|
1805
|
+
* Set italic style with shear factor
|
|
1806
|
+
* @param shear - Shear factor (0.0 = no italic, default: 0.18, typical range: 0.1-0.3)
|
|
1807
|
+
*/
|
|
1808
|
+
italic(shear?: number): this;
|
|
1809
|
+
/**
|
|
1810
|
+
* Set text outline (stroke)
|
|
1811
|
+
* @param width - Outline width
|
|
1812
|
+
* @param r - Red (0-255)
|
|
1813
|
+
* @param g - Green (0-255)
|
|
1814
|
+
* @param b - Blue (0-255)
|
|
1815
|
+
*/
|
|
1816
|
+
outline(width: number, r: number, g: number, b: number): this;
|
|
1817
|
+
}
|
|
1818
|
+
|
|
1819
|
+
/**
|
|
1820
|
+
* Load and control Lottie animations
|
|
1821
|
+
* @category Animation
|
|
1822
|
+
*/
|
|
1823
|
+
|
|
1824
|
+
/**
|
|
1825
|
+
* @category Animation
|
|
1826
|
+
*/
|
|
1827
|
+
interface AnimationInfo {
|
|
1828
|
+
totalFrames: number;
|
|
1829
|
+
duration: number;
|
|
1830
|
+
fps: number;
|
|
1831
|
+
}
|
|
1832
|
+
/**
|
|
1833
|
+
* @category Animation
|
|
1834
|
+
*/
|
|
1835
|
+
interface AnimationSegment {
|
|
1836
|
+
start: number;
|
|
1837
|
+
end: number;
|
|
1838
|
+
}
|
|
1839
|
+
/**
|
|
1840
|
+
* Animation controller for Lottie animations
|
|
1841
|
+
* The Animation owns a Picture internally and manages frame updates
|
|
1842
|
+
* @category Animation
|
|
1843
|
+
*
|
|
1844
|
+
* @example
|
|
1845
|
+
* ```typescript
|
|
1846
|
+
* // Loading and playing a Lottie animation
|
|
1847
|
+
* const animation = new TVG.Animation();
|
|
1848
|
+
*
|
|
1849
|
+
* fetch('/animations/loader.json')
|
|
1850
|
+
* .then(res => res.text())
|
|
1851
|
+
* .then(lottieData => {
|
|
1852
|
+
* animation.load(lottieData);
|
|
1853
|
+
* const picture = animation.picture();
|
|
1854
|
+
*
|
|
1855
|
+
* // Center and scale animation
|
|
1856
|
+
* const size = picture.size();
|
|
1857
|
+
* picture.translate(400 - size.width / 2, 300 - size.height / 2);
|
|
1858
|
+
*
|
|
1859
|
+
* canvas.add(picture);
|
|
1860
|
+
* animation.play();
|
|
1861
|
+
* });
|
|
1862
|
+
* ```
|
|
1863
|
+
*
|
|
1864
|
+
* @example
|
|
1865
|
+
* ```typescript
|
|
1866
|
+
* // Controlling animation playback
|
|
1867
|
+
* const animation = new TVG.Animation();
|
|
1868
|
+
* animation.load(lottieData);
|
|
1869
|
+
*
|
|
1870
|
+
* const info = animation.getInfo();
|
|
1871
|
+
* console.log(`Duration: ${info.duration}s, FPS: ${info.fps}`);
|
|
1872
|
+
*
|
|
1873
|
+
* // Play with custom loop and speed
|
|
1874
|
+
* animation.loop(true).play();
|
|
1875
|
+
*
|
|
1876
|
+
* // Pause after 2 seconds
|
|
1877
|
+
* setTimeout(() => animation.pause(), 2000);
|
|
1878
|
+
*
|
|
1879
|
+
* // Jump to specific frame
|
|
1880
|
+
* animation.frame(30).render();
|
|
1881
|
+
* ```
|
|
1882
|
+
*
|
|
1883
|
+
* @example
|
|
1884
|
+
* ```typescript
|
|
1885
|
+
* // Animation segments and callbacks
|
|
1886
|
+
* const animation = new TVG.Animation();
|
|
1887
|
+
* animation.load(lottieData);
|
|
1888
|
+
*
|
|
1889
|
+
* // Play specific segment
|
|
1890
|
+
* animation.segment({ start: 0, end: 60 });
|
|
1891
|
+
*
|
|
1892
|
+
* // Listen to frame updates
|
|
1893
|
+
* animation.onFrame((frame) => {
|
|
1894
|
+
* console.log(`Current frame: ${frame}`);
|
|
1895
|
+
* });
|
|
1896
|
+
*
|
|
1897
|
+
* animation.play();
|
|
1898
|
+
* ```
|
|
1899
|
+
*/
|
|
1900
|
+
declare class Animation {
|
|
1901
|
+
#private;
|
|
1902
|
+
constructor();
|
|
1903
|
+
/**
|
|
1904
|
+
* Get the pointer (internal use)
|
|
1905
|
+
*/
|
|
1906
|
+
get ptr(): number;
|
|
1907
|
+
/**
|
|
1908
|
+
* Get the Picture object that contains the animation content
|
|
1909
|
+
* The Picture is owned by the Animation and should not be manually disposed
|
|
1910
|
+
*/
|
|
1911
|
+
get picture(): Picture | null;
|
|
1912
|
+
/**
|
|
1913
|
+
* Load Lottie animation from raw data
|
|
1914
|
+
* @param data - Lottie JSON data as Uint8Array or string
|
|
1915
|
+
*/
|
|
1916
|
+
load(data: Uint8Array | string): this;
|
|
1917
|
+
/**
|
|
1918
|
+
* Get animation information (frames, duration, fps)
|
|
1919
|
+
*/
|
|
1920
|
+
info(): AnimationInfo | null;
|
|
1921
|
+
/**
|
|
1922
|
+
* Get or set the current frame
|
|
1923
|
+
*/
|
|
1924
|
+
frame(): number;
|
|
1925
|
+
frame(frameNumber: number): this;
|
|
1926
|
+
/**
|
|
1927
|
+
* Set animation segment/marker (for partial playback)
|
|
1928
|
+
* @param segment - Segment index (0-based)
|
|
1929
|
+
*/
|
|
1930
|
+
segment(segment: number): this;
|
|
1931
|
+
/**
|
|
1932
|
+
* Play the animation
|
|
1933
|
+
* @param onFrame - Optional callback called on each frame update
|
|
1934
|
+
*/
|
|
1935
|
+
play(onFrame?: (frame: number) => void): this;
|
|
1936
|
+
/**
|
|
1937
|
+
* Pause the animation
|
|
1938
|
+
*/
|
|
1939
|
+
pause(): this;
|
|
1940
|
+
/**
|
|
1941
|
+
* Stop the animation and reset to frame 0
|
|
1942
|
+
*/
|
|
1943
|
+
stop(): this;
|
|
1944
|
+
/**
|
|
1945
|
+
* Check if animation is currently playing
|
|
1946
|
+
*/
|
|
1947
|
+
isPlaying(): boolean;
|
|
1948
|
+
/**
|
|
1949
|
+
* Set whether animation should loop
|
|
1950
|
+
*/
|
|
1951
|
+
setLoop(loop: boolean): this;
|
|
1952
|
+
/**
|
|
1953
|
+
* Get loop status
|
|
1954
|
+
*/
|
|
1955
|
+
getLoop(): boolean;
|
|
1956
|
+
/**
|
|
1957
|
+
* Seek to a specific time (in seconds)
|
|
1958
|
+
*/
|
|
1959
|
+
seek(time: number): this;
|
|
1960
|
+
/**
|
|
1961
|
+
* Get current time (in seconds)
|
|
1962
|
+
*/
|
|
1963
|
+
getCurrentTime(): number;
|
|
1964
|
+
/**
|
|
1965
|
+
* Dispose of the animation and free resources
|
|
1966
|
+
*/
|
|
1967
|
+
dispose(): void;
|
|
1968
|
+
}
|
|
1969
|
+
|
|
1970
|
+
/**
|
|
1971
|
+
* Linear gradient fill
|
|
1972
|
+
* @category Gradients
|
|
1973
|
+
*/
|
|
1974
|
+
|
|
1975
|
+
/**
|
|
1976
|
+
* Linear gradient for filling shapes
|
|
1977
|
+
* @category Gradients
|
|
1978
|
+
*
|
|
1979
|
+
* @example
|
|
1980
|
+
* ```typescript
|
|
1981
|
+
* // Basic linear gradient
|
|
1982
|
+
* const gradient = new TVG.LinearGradient(100, 100, 300, 100);
|
|
1983
|
+
* gradient.addStop(0, [255, 0, 0, 255]) // Red
|
|
1984
|
+
* .addStop(0.5, [255, 255, 0, 255]) // Yellow
|
|
1985
|
+
* .addStop(1, [0, 255, 0, 255]); // Green
|
|
1986
|
+
*
|
|
1987
|
+
* const shape = new TVG.Shape();
|
|
1988
|
+
* shape.appendRect(100, 100, 200, 100)
|
|
1989
|
+
* .fillGradient(gradient);
|
|
1990
|
+
*
|
|
1991
|
+
* canvas.add(shape);
|
|
1992
|
+
* ```
|
|
1993
|
+
*
|
|
1994
|
+
* @example
|
|
1995
|
+
* ```typescript
|
|
1996
|
+
* // Vertical gradient with transparency
|
|
1997
|
+
* const gradient = new TVG.LinearGradient(200, 100, 200, 300);
|
|
1998
|
+
* gradient.addStop(0, [100, 150, 255, 255])
|
|
1999
|
+
* .addStop(1, [100, 150, 255, 0])
|
|
2000
|
+
* .spread(GradientSpread.Pad);
|
|
2001
|
+
*
|
|
2002
|
+
* const shape = new TVG.Shape();
|
|
2003
|
+
* shape.appendRect(150, 100, 100, 200)
|
|
2004
|
+
* .fillGradient(gradient);
|
|
2005
|
+
*
|
|
2006
|
+
* canvas.add(shape);
|
|
2007
|
+
* ```
|
|
2008
|
+
*/
|
|
2009
|
+
declare class LinearGradient extends Fill {
|
|
2010
|
+
constructor(x1: number, y1: number, x2: number, y2: number);
|
|
2011
|
+
/**
|
|
2012
|
+
* Build the gradient (apply all color stops)
|
|
2013
|
+
* This should be called after all addStop() calls
|
|
2014
|
+
*/
|
|
2015
|
+
build(): this;
|
|
2016
|
+
}
|
|
2017
|
+
|
|
2018
|
+
/**
|
|
2019
|
+
* Radial gradient fill
|
|
2020
|
+
* @category Gradients
|
|
2021
|
+
*/
|
|
2022
|
+
|
|
2023
|
+
/**
|
|
2024
|
+
* Radial gradient for filling shapes
|
|
2025
|
+
* @category Gradients
|
|
2026
|
+
*
|
|
2027
|
+
* @example
|
|
2028
|
+
* ```typescript
|
|
2029
|
+
* // Basic radial gradient
|
|
2030
|
+
* const gradient = new TVG.RadialGradient(200, 200, 100);
|
|
2031
|
+
* gradient.addStop(0, [255, 255, 255, 255]) // White center
|
|
2032
|
+
* .addStop(1, [100, 100, 255, 255]); // Blue edge
|
|
2033
|
+
*
|
|
2034
|
+
* const shape = new TVG.Shape();
|
|
2035
|
+
* shape.appendCircle(200, 200, 100)
|
|
2036
|
+
* .fillGradient(gradient);
|
|
2037
|
+
*
|
|
2038
|
+
* canvas.add(shape);
|
|
2039
|
+
* ```
|
|
2040
|
+
*
|
|
2041
|
+
* @example
|
|
2042
|
+
* ```typescript
|
|
2043
|
+
* // Radial gradient with focal point
|
|
2044
|
+
* // Create gradient with offset focal point for lighting effect
|
|
2045
|
+
* const gradient = new TVG.RadialGradient(
|
|
2046
|
+
* 200, 200, 100, // Center and radius
|
|
2047
|
+
* 170, 170, 0 // Focal point (offset)
|
|
2048
|
+
* );
|
|
2049
|
+
* gradient.addStop(0, [255, 255, 200, 255])
|
|
2050
|
+
* .addStop(1, [255, 100, 100, 255]);
|
|
2051
|
+
*
|
|
2052
|
+
* const shape = new TVG.Shape();
|
|
2053
|
+
* shape.appendCircle(200, 200, 100)
|
|
2054
|
+
* .fillGradient(gradient);
|
|
2055
|
+
*
|
|
2056
|
+
* canvas.add(shape);
|
|
2057
|
+
* ```
|
|
2058
|
+
*/
|
|
2059
|
+
declare class RadialGradient extends Fill {
|
|
2060
|
+
constructor(cx: number, cy: number, r: number, fx?: number, fy?: number, fr?: number);
|
|
2061
|
+
/**
|
|
2062
|
+
* Build the gradient (apply all color stops)
|
|
2063
|
+
* This should be called after all addStop() calls
|
|
2064
|
+
*/
|
|
2065
|
+
build(): this;
|
|
2066
|
+
}
|
|
2067
|
+
|
|
2068
|
+
/**
|
|
2069
|
+
* Load and manage fonts
|
|
2070
|
+
* @category Font
|
|
2071
|
+
*/
|
|
2072
|
+
/**
|
|
2073
|
+
* Supported font file types.
|
|
2074
|
+
* - `'ttf'`: TrueType Font
|
|
2075
|
+
* @category Font
|
|
2076
|
+
*/
|
|
2077
|
+
type FontType = 'ttf';
|
|
2078
|
+
/**
|
|
2079
|
+
* @category Font
|
|
2080
|
+
*/
|
|
2081
|
+
interface LoadFontOptions {
|
|
2082
|
+
/** Font type ('ttf') */
|
|
2083
|
+
type?: FontType;
|
|
2084
|
+
}
|
|
2085
|
+
/**
|
|
2086
|
+
* Font loader class for managing custom fonts
|
|
2087
|
+
* Fonts are loaded globally and can be referenced by name in Text objects
|
|
2088
|
+
* @category Font
|
|
2089
|
+
*
|
|
2090
|
+
* @example
|
|
2091
|
+
* ```typescript
|
|
2092
|
+
* // Loading a custom font from URL
|
|
2093
|
+
* // Fetch and load custom font
|
|
2094
|
+
* const fontData = await fetch('/fonts/Roboto-Regular.ttf')
|
|
2095
|
+
* .then(res => res.arrayBuffer());
|
|
2096
|
+
*
|
|
2097
|
+
* TVG.Font.load('Roboto', new Uint8Array(fontData), { type: 'ttf' });
|
|
2098
|
+
*
|
|
2099
|
+
* // Use the loaded font
|
|
2100
|
+
* const text = new TVG.Text();
|
|
2101
|
+
* text.font('Roboto', 48)
|
|
2102
|
+
* .text('Hello with custom font!')
|
|
2103
|
+
* .fill(50, 50, 50, 255);
|
|
2104
|
+
*
|
|
2105
|
+
* canvas.add(text);
|
|
2106
|
+
* ```
|
|
2107
|
+
*
|
|
2108
|
+
* @example
|
|
2109
|
+
* ```typescript
|
|
2110
|
+
* // Loading multiple fonts
|
|
2111
|
+
* async function loadFonts() {
|
|
2112
|
+
* const fonts = [
|
|
2113
|
+
* { name: 'Roboto-Regular', url: '/fonts/Roboto-Regular.ttf' },
|
|
2114
|
+
* { name: 'Roboto-Bold', url: '/fonts/Roboto-Bold.ttf' }
|
|
2115
|
+
* ];
|
|
2116
|
+
*
|
|
2117
|
+
* for (const font of fonts) {
|
|
2118
|
+
* const data = await fetch(font.url).then(r => r.arrayBuffer());
|
|
2119
|
+
* TVG.Font.load(font.name, new Uint8Array(data));
|
|
2120
|
+
* }
|
|
2121
|
+
* }
|
|
2122
|
+
*
|
|
2123
|
+
* await loadFonts();
|
|
2124
|
+
*
|
|
2125
|
+
* // Now use any loaded font
|
|
2126
|
+
* const text = new TVG.Text();
|
|
2127
|
+
* text.font('Roboto-Bold', 64).text('Bold Text');
|
|
2128
|
+
* ```
|
|
2129
|
+
*/
|
|
2130
|
+
declare class Font {
|
|
2131
|
+
/**
|
|
2132
|
+
* Load font from raw data (Uint8Array)
|
|
2133
|
+
* @param name - Unique name to identify this font
|
|
2134
|
+
* @param data - Raw font data
|
|
2135
|
+
* @param options - Load options
|
|
2136
|
+
*/
|
|
2137
|
+
static load(name: string, data: Uint8Array, options?: LoadFontOptions): void;
|
|
2138
|
+
/**
|
|
2139
|
+
* Unload a previously loaded font
|
|
2140
|
+
* @param name - Font name to unload
|
|
2141
|
+
*/
|
|
2142
|
+
static unload(name: string): void;
|
|
2143
|
+
}
|
|
2144
|
+
|
|
2145
|
+
/**
|
|
2146
|
+
* ThorVG error result codes returned by native WASM operations.
|
|
2147
|
+
*
|
|
2148
|
+
* @category Error Handling
|
|
2149
|
+
*/
|
|
2150
|
+
declare enum ThorVGResultCode {
|
|
2151
|
+
Success = 0,
|
|
2152
|
+
InvalidArguments = 1,
|
|
2153
|
+
InsufficientCondition = 2,
|
|
2154
|
+
FailedAllocation = 3,
|
|
2155
|
+
MemoryCorruption = 4,
|
|
2156
|
+
NotSupported = 5,
|
|
2157
|
+
Unknown = 6
|
|
2158
|
+
}
|
|
2159
|
+
/**
|
|
2160
|
+
* Error class for ThorVG WASM operations.
|
|
2161
|
+
* Contains error code and operation information.
|
|
2162
|
+
*
|
|
2163
|
+
* @category Error Handling
|
|
2164
|
+
*/
|
|
2165
|
+
declare class ThorVGError extends Error {
|
|
2166
|
+
readonly code: ThorVGResultCode;
|
|
2167
|
+
readonly operation: string;
|
|
2168
|
+
constructor(message: string, code: ThorVGResultCode, operation: string);
|
|
2169
|
+
static fromCode(code: ThorVGResultCode, operation: string): ThorVGError;
|
|
2170
|
+
}
|
|
2171
|
+
/**
|
|
2172
|
+
* Context information provided when an error occurs.
|
|
2173
|
+
*
|
|
2174
|
+
* @category Error Handling
|
|
2175
|
+
*/
|
|
2176
|
+
interface ErrorContext {
|
|
2177
|
+
/** The operation that failed (e.g., 'moveTo', 'render', 'update') */
|
|
2178
|
+
operation: string;
|
|
2179
|
+
}
|
|
2180
|
+
/**
|
|
2181
|
+
* Error handler callback function.
|
|
2182
|
+
*
|
|
2183
|
+
* Handles both ThorVG WASM errors (ThorVGError) and JavaScript errors (Error).
|
|
2184
|
+
* Use instanceof to distinguish between error types.
|
|
2185
|
+
*
|
|
2186
|
+
* @category Error Handling
|
|
2187
|
+
*
|
|
2188
|
+
* @example
|
|
2189
|
+
* ```typescript
|
|
2190
|
+
* import { init } from '@thorvg/webcanvas';
|
|
2191
|
+
*
|
|
2192
|
+
* const TVG = await init({
|
|
2193
|
+
* onError: (error, context) => {
|
|
2194
|
+
* if (error instanceof ThorVGError) {
|
|
2195
|
+
* // WASM error - has error.code
|
|
2196
|
+
* console.log('WASM error code:', error.code);
|
|
2197
|
+
* } else {
|
|
2198
|
+
* // JavaScript error
|
|
2199
|
+
* console.log('JS error:', error.message);
|
|
2200
|
+
* }
|
|
2201
|
+
* }
|
|
2202
|
+
* });
|
|
2203
|
+
* ```
|
|
2204
|
+
*/
|
|
2205
|
+
interface ErrorHandler {
|
|
2206
|
+
(error: Error, context: ErrorContext): void;
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
/**
|
|
2210
|
+
* ThorVG WebCanvas - TypeScript API for ThorVG
|
|
2211
|
+
*
|
|
2212
|
+
* @packageDocumentation
|
|
2213
|
+
*
|
|
2214
|
+
* A high-performance TypeScript Canvas API for ThorVG, providing an object-oriented
|
|
2215
|
+
* interface with fluent API pattern for vector graphics rendering using WebAssembly.
|
|
2216
|
+
*
|
|
2217
|
+
* ## Features
|
|
2218
|
+
*
|
|
2219
|
+
* - **Intuitive OOP API** - Fluent interface with method chaining
|
|
2220
|
+
* - **Type-Safe** - Full TypeScript support with strict typing
|
|
2221
|
+
* - **High Performance** - WebGPU, WebGL, and Software rendering backends
|
|
2222
|
+
* - **Automatic Memory Management** - FinalizationRegistry for garbage collection
|
|
2223
|
+
* - **Method Chaining** - Ergonomic fluent API design
|
|
2224
|
+
* - **Zero Overhead** - Direct WASM bindings with minimal abstraction
|
|
2225
|
+
* - **Animation Support** - Frame-based Lottie animation playback
|
|
2226
|
+
* - **Rich Primitives** - Shapes, scenes, pictures, text, and gradients
|
|
2227
|
+
*
|
|
2228
|
+
* @example
|
|
2229
|
+
* ```typescript
|
|
2230
|
+
* import ThorVG from '@thorvg/webcanvas';
|
|
2231
|
+
*
|
|
2232
|
+
* // Initialize ThorVG with renderer
|
|
2233
|
+
* const TVG = await ThorVG.init({
|
|
2234
|
+
* locateFile: (path) => `/wasm/${path}`,
|
|
2235
|
+
* renderer: 'gl'
|
|
2236
|
+
* });
|
|
2237
|
+
*
|
|
2238
|
+
* // Create canvas and draw
|
|
2239
|
+
* const canvas = new TVG.Canvas('#canvas', { width: 800, height: 600 });
|
|
2240
|
+
* const shape = new TVG.Shape();
|
|
2241
|
+
* shape.appendRect(100, 100, 200, 150)
|
|
2242
|
+
* .fill(255, 0, 0, 255);
|
|
2243
|
+
* canvas.add(shape).render();
|
|
2244
|
+
* ```
|
|
2245
|
+
*
|
|
2246
|
+
* @module
|
|
2247
|
+
*/
|
|
2248
|
+
|
|
2249
|
+
/**
|
|
2250
|
+
* @category Initialization
|
|
2251
|
+
*/
|
|
2252
|
+
interface InitOptions {
|
|
2253
|
+
/** Optional function to locate WASM files. If not provided, assumes WASM files are in the same directory as the JavaScript bundle. */
|
|
2254
|
+
locateFile?: (path: string) => string;
|
|
2255
|
+
/** Renderer type: 'sw' (Software), 'gl' (WebGL), or 'wg' (WebGPU). Default: 'gl'. WebGPU provides best performance but requires Chrome 113+ or Edge 113+. */
|
|
2256
|
+
renderer?: RendererType;
|
|
2257
|
+
/** Global error handler for all ThorVG operations. If provided, errors will be passed to this handler instead of being thrown. */
|
|
2258
|
+
onError?: ErrorHandler;
|
|
2259
|
+
}
|
|
2260
|
+
interface ThorVGNamespace {
|
|
2261
|
+
Canvas: typeof Canvas;
|
|
2262
|
+
Shape: typeof Shape;
|
|
2263
|
+
Scene: typeof Scene;
|
|
2264
|
+
Picture: typeof Picture;
|
|
2265
|
+
Text: typeof Text;
|
|
2266
|
+
Animation: typeof Animation;
|
|
2267
|
+
LinearGradient: typeof LinearGradient;
|
|
2268
|
+
RadialGradient: typeof RadialGradient;
|
|
2269
|
+
Font: typeof Font;
|
|
2270
|
+
BlendMethod: typeof BlendMethod;
|
|
2271
|
+
StrokeCap: typeof StrokeCap;
|
|
2272
|
+
StrokeJoin: typeof StrokeJoin;
|
|
2273
|
+
FillRule: typeof FillRule;
|
|
2274
|
+
GradientSpread: typeof GradientSpread;
|
|
2275
|
+
CompositeMethod: typeof CompositeMethod;
|
|
2276
|
+
MaskMethod: typeof MaskMethod;
|
|
2277
|
+
SceneEffect: typeof SceneEffect;
|
|
2278
|
+
TextWrapMode: typeof TextWrapMode;
|
|
2279
|
+
ColorSpace: typeof ColorSpace;
|
|
2280
|
+
term(): void;
|
|
2281
|
+
}
|
|
2282
|
+
/**
|
|
2283
|
+
* Get the currently configured renderer
|
|
2284
|
+
* @internal
|
|
2285
|
+
*/
|
|
2286
|
+
declare function getGlobalRenderer(): RendererType;
|
|
2287
|
+
/**
|
|
2288
|
+
* Initialize ThorVG WASM module and rendering engine.
|
|
2289
|
+
*
|
|
2290
|
+
* This is the entry point for using ThorVG WebCanvas. It loads the WebAssembly module
|
|
2291
|
+
* and initializes the rendering engine with the specified backend (Software, WebGL, or WebGPU).
|
|
2292
|
+
*
|
|
2293
|
+
* @category Initialization
|
|
2294
|
+
* @param options - Initialization options
|
|
2295
|
+
* @param options.locateFile - Optional function to locate WASM files. If not provided, assumes
|
|
2296
|
+
* WASM files are in the same directory as the JavaScript bundle.
|
|
2297
|
+
* @param options.renderer - Renderer type: 'sw' (Software), 'gl' (WebGL), or 'wg' (WebGPU).
|
|
2298
|
+
* Default: 'gl'. WebGPU provides best performance but requires
|
|
2299
|
+
* Chrome 113+ or Edge 113+.
|
|
2300
|
+
*
|
|
2301
|
+
* @returns Promise that resolves to ThorVG namespace containing all classes and utilities
|
|
2302
|
+
*
|
|
2303
|
+
* @example
|
|
2304
|
+
* ```typescript
|
|
2305
|
+
* // Initialize with default WebGL renderer
|
|
2306
|
+
* const TVG = await ThorVG.init();
|
|
2307
|
+
* const canvas = new TVG.Canvas('#canvas');
|
|
2308
|
+
* ```
|
|
2309
|
+
*
|
|
2310
|
+
* @example
|
|
2311
|
+
* ```typescript
|
|
2312
|
+
* // Initialize with custom WASM file location
|
|
2313
|
+
* const TVG = await ThorVG.init({
|
|
2314
|
+
* locateFile: (path) => `/public/wasm/${path}`,
|
|
2315
|
+
* renderer: 'gl'
|
|
2316
|
+
* });
|
|
2317
|
+
* ```
|
|
2318
|
+
*
|
|
2319
|
+
* @example
|
|
2320
|
+
* ```typescript
|
|
2321
|
+
* // Initialize with WebGPU for maximum performance
|
|
2322
|
+
* const TVG = await ThorVG.init({
|
|
2323
|
+
* locateFile: (path) => '../dist/' + path.split('/').pop(),
|
|
2324
|
+
* renderer: 'wg'
|
|
2325
|
+
* });
|
|
2326
|
+
* ```
|
|
2327
|
+
*
|
|
2328
|
+
* @example
|
|
2329
|
+
* ```typescript
|
|
2330
|
+
* // Initialize with Software renderer for maximum compatibility
|
|
2331
|
+
* const TVG = await ThorVG.init({
|
|
2332
|
+
* renderer: 'sw'
|
|
2333
|
+
* });
|
|
2334
|
+
* ```
|
|
2335
|
+
*
|
|
2336
|
+
* @throws {Error} If WASM module fails to load or engine initialization fails
|
|
2337
|
+
*/
|
|
2338
|
+
declare function init(options?: InitOptions): Promise<ThorVGNamespace>;
|
|
2339
|
+
declare const ThorVG: {
|
|
2340
|
+
init: typeof init;
|
|
2341
|
+
};
|
|
2342
|
+
|
|
2343
|
+
export { Animation, Canvas, Font, LinearGradient, Picture, RadialGradient, Scene, Shape, Text, ThorVGError, ThorVGResultCode, constants, ThorVG as default, getGlobalRenderer, init };
|
|
2344
|
+
export type { AnimationInfo, AnimationSegment, Bounds, CanvasOptions, ColorStop, ErrorContext, ErrorHandler, FontType, InitOptions, LoadDataOptions, LoadFontOptions, Matrix, MimeType, PictureSize, RectOptions, RendererType, StrokeOptions, TextLayout, TextOutline, ThorVGNamespace };
|