@nmmty/lazycanvas 0.6.0 → 0.6.2
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/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +19 -0
- package/dist/index.d.ts +5 -12
- package/dist/index.js +5 -31
- package/dist/structures/LazyCanvas.d.ts +12 -16
- package/dist/structures/LazyCanvas.js +24 -27
- package/dist/structures/components/BaseLayer.d.ts +17 -25
- package/dist/structures/components/BaseLayer.js +16 -18
- package/dist/structures/components/BezierLayer.d.ts +29 -21
- package/dist/structures/components/BezierLayer.js +22 -20
- package/dist/structures/components/ClearLayer.d.ts +15 -15
- package/dist/structures/components/ClearLayer.js +14 -14
- package/dist/structures/components/Group.d.ts +10 -11
- package/dist/structures/components/Group.js +9 -10
- package/dist/structures/components/ImageLayer.d.ts +15 -15
- package/dist/structures/components/ImageLayer.js +11 -11
- package/dist/structures/components/LineLayer.d.ts +28 -20
- package/dist/structures/components/LineLayer.js +21 -19
- package/dist/structures/components/MorphLayer.d.ts +29 -21
- package/dist/structures/components/MorphLayer.js +19 -17
- package/dist/structures/components/Path2DLayer.d.ts +21 -72
- package/dist/structures/components/Path2DLayer.js +4 -108
- package/dist/structures/components/QuadraticLayer.d.ts +30 -22
- package/dist/structures/components/QuadraticLayer.js +23 -21
- package/dist/structures/components/TextLayer.d.ts +54 -41
- package/dist/structures/components/TextLayer.js +165 -69
- package/dist/structures/helpers/Exporter.d.ts +9 -9
- package/dist/structures/helpers/Exporter.js +9 -9
- package/dist/structures/helpers/Font.d.ts +4 -4
- package/dist/structures/helpers/Font.js +4 -4
- package/dist/structures/helpers/Gradient.d.ts +15 -10
- package/dist/structures/helpers/Gradient.js +14 -9
- package/dist/structures/helpers/Link.d.ts +5 -5
- package/dist/structures/helpers/Link.js +5 -5
- package/dist/structures/helpers/Pattern.d.ts +5 -5
- package/dist/structures/helpers/Pattern.js +5 -5
- package/dist/structures/helpers/index.d.ts +7 -7
- package/dist/structures/helpers/readers/JSONReader.d.ts +12 -12
- package/dist/structures/helpers/readers/JSONReader.js +12 -12
- package/dist/structures/helpers/readers/YAMLReader.d.ts +4 -4
- package/dist/structures/helpers/readers/YAMLReader.js +4 -4
- package/dist/structures/managers/AnimationManager.d.ts +11 -11
- package/dist/structures/managers/AnimationManager.js +11 -11
- package/dist/structures/managers/FontsManager.d.ts +14 -15
- package/dist/structures/managers/FontsManager.js +14 -15
- package/dist/structures/managers/LayersManager.d.ts +15 -15
- package/dist/structures/managers/LayersManager.js +19 -19
- package/dist/structures/managers/PluginManager.d.ts +11 -9
- package/dist/structures/managers/PluginManager.js +9 -8
- package/dist/structures/managers/RenderManager.d.ts +10 -10
- package/dist/structures/managers/RenderManager.js +10 -10
- package/dist/structures/managers/index.d.ts +5 -0
- package/dist/structures/managers/index.js +21 -0
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.js +0 -1
- package/dist/types/types.d.ts +7 -1
- package/dist/utils/utils.d.ts +5 -5
- package/dist/utils/utils.js +8 -2
- package/package.json +1 -2
|
@@ -15,8 +15,8 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
15
15
|
props;
|
|
16
16
|
/**
|
|
17
17
|
* Constructs a new TextLayer instance.
|
|
18
|
-
* @param
|
|
19
|
-
* @param
|
|
18
|
+
* @param {ITextLayerProps} [props] - The properties of the Text Layer.
|
|
19
|
+
* @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
|
|
20
20
|
*/
|
|
21
21
|
constructor(props, misc) {
|
|
22
22
|
super(types_1.LayerType.Text, props || {}, misc);
|
|
@@ -25,7 +25,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Sets the text of the text layer.
|
|
28
|
-
* @param
|
|
28
|
+
* @param {string} [text] - The text content of the layer.
|
|
29
29
|
* @returns {this} The current instance for chaining.
|
|
30
30
|
*/
|
|
31
31
|
setText(text) {
|
|
@@ -34,9 +34,9 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Sets the font of the text layer.
|
|
37
|
-
* @param
|
|
38
|
-
* @param
|
|
39
|
-
* @param
|
|
37
|
+
* @param {string | { family: string; size: number; weight: AnyWeight }} [familyOrConfig] - The font family or configuration object.
|
|
38
|
+
* @param {number} [size] - The font size (required if `familyOrConfig` is a string).
|
|
39
|
+
* @param {AnyWeight} [weight] - The font weight (required if `familyOrConfig` is a string).
|
|
40
40
|
* @returns {this} The current instance for chaining.
|
|
41
41
|
* @throws {LazyError} If size or weight is not provided when `familyOrConfig` is a string.
|
|
42
42
|
*/
|
|
@@ -63,15 +63,14 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
63
63
|
}
|
|
64
64
|
/**
|
|
65
65
|
* Configures the multiline properties of the text layer.
|
|
66
|
-
* @param
|
|
67
|
-
* @param
|
|
68
|
-
* @param
|
|
69
|
-
* @param spacing {number} - The spacing between lines (optional).
|
|
66
|
+
* @param {ScaleType} [width] - The width of the multiline text area.
|
|
67
|
+
* @param {ScaleType} [height] - The height of the multiline text area.
|
|
68
|
+
* @param {number} [spacing] - The spacing between lines (optional).
|
|
70
69
|
* @returns {this} The current instance for chaining.
|
|
71
70
|
*/
|
|
72
|
-
setMultiline(
|
|
71
|
+
setMultiline(width, height, spacing) {
|
|
73
72
|
this.props.multiline = {
|
|
74
|
-
enabled:
|
|
73
|
+
enabled: true,
|
|
75
74
|
spacing: spacing || 1.1,
|
|
76
75
|
};
|
|
77
76
|
this.props.size = {
|
|
@@ -82,21 +81,25 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
82
81
|
}
|
|
83
82
|
/**
|
|
84
83
|
* Sets the color of the text layer.
|
|
85
|
-
* @param
|
|
84
|
+
* @param {ColorType} [color] - The base color of the text.
|
|
85
|
+
* @param {SubStringColor[]} [sub] - Optional substring colors for partial text coloring.
|
|
86
86
|
* @returns {this} The current instance for chaining.
|
|
87
87
|
* @throws {LazyError} If the color is not provided or invalid.
|
|
88
88
|
*/
|
|
89
|
-
setColor(color) {
|
|
89
|
+
setColor(color, ...sub) {
|
|
90
90
|
if (!color)
|
|
91
91
|
throw new LazyUtil_1.LazyError('The color of the layer must be provided');
|
|
92
92
|
if (!(0, utils_1.isColor)(color))
|
|
93
93
|
throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
|
|
94
94
|
this.props.fillStyle = color;
|
|
95
|
+
if (sub && sub.length > 0) {
|
|
96
|
+
this.props.subStringColors = sub;
|
|
97
|
+
}
|
|
95
98
|
return this;
|
|
96
99
|
}
|
|
97
100
|
/**
|
|
98
101
|
* Sets the alignment of the text layer.
|
|
99
|
-
* @param
|
|
102
|
+
* @param {AnyTextAlign} [align] - The alignment of the text.
|
|
100
103
|
* @returns {this} The current instance for chaining.
|
|
101
104
|
*/
|
|
102
105
|
setAlign(align) {
|
|
@@ -105,7 +108,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
105
108
|
}
|
|
106
109
|
/**
|
|
107
110
|
* Sets the baseline of the text layer.
|
|
108
|
-
* @param
|
|
111
|
+
* @param {AnyTextBaseline} [baseline] - The baseline of the text.
|
|
109
112
|
* @returns {this} The current instance for chaining.
|
|
110
113
|
*/
|
|
111
114
|
setBaseline(baseline) {
|
|
@@ -114,7 +117,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
114
117
|
}
|
|
115
118
|
/**
|
|
116
119
|
* Sets the direction of the text layer.
|
|
117
|
-
* @param
|
|
120
|
+
* @param {AnyTextDirection} [direction] - The direction of the text.
|
|
118
121
|
* @returns {this} The current instance for chaining.
|
|
119
122
|
*/
|
|
120
123
|
setDirection(direction) {
|
|
@@ -123,12 +126,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
123
126
|
}
|
|
124
127
|
/**
|
|
125
128
|
* Configures the stroke properties of the text layer.
|
|
126
|
-
* @param
|
|
127
|
-
* @param
|
|
128
|
-
* @param
|
|
129
|
-
* @param
|
|
130
|
-
* @param
|
|
131
|
-
* @param
|
|
129
|
+
* @param {number} [width] - The width of the stroke.
|
|
130
|
+
* @param {string} [cap] - The cap style of the stroke.
|
|
131
|
+
* @param {string} [join] - The join style of the stroke.
|
|
132
|
+
* @param {number[]} [dash] - The dash pattern of the stroke.
|
|
133
|
+
* @param {number} [dashOffset] - The dash offset of the stroke.
|
|
134
|
+
* @param {number} [miterLimit] - The miter limit of the stroke.
|
|
132
135
|
* @returns {this} The current instance for chaining.
|
|
133
136
|
*/
|
|
134
137
|
setStroke(width, cap, join, dash, dashOffset, miterLimit) {
|
|
@@ -145,7 +148,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
145
148
|
}
|
|
146
149
|
/**
|
|
147
150
|
* Sets the spacing between words in the text layer.
|
|
148
|
-
* @param
|
|
151
|
+
* @param {number} [wordSpacing] - The spacing between words.
|
|
149
152
|
* @returns {this} The current instance for chaining.
|
|
150
153
|
*/
|
|
151
154
|
setWordSpacing(wordSpacing) {
|
|
@@ -154,7 +157,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
154
157
|
}
|
|
155
158
|
/**
|
|
156
159
|
* Sets the spacing between letters in the text layer.
|
|
157
|
-
* @param
|
|
160
|
+
* @param {number} [letterSpacing] - The spacing between letters.
|
|
158
161
|
* @returns {this} The current instance for chaining.
|
|
159
162
|
*/
|
|
160
163
|
setLetterSpacing(letterSpacing) {
|
|
@@ -163,8 +166,8 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
163
166
|
}
|
|
164
167
|
/**
|
|
165
168
|
* Measures the dimensions of the text.
|
|
166
|
-
* @param
|
|
167
|
-
* @param
|
|
169
|
+
* @param {SKRSContext2D} [ctx] - The canvas rendering context.
|
|
170
|
+
* @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
|
|
168
171
|
* @returns {Object} The width and height of the text.
|
|
169
172
|
*/
|
|
170
173
|
measureText(ctx, canvas) {
|
|
@@ -181,10 +184,10 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
181
184
|
}
|
|
182
185
|
/**
|
|
183
186
|
* Draws the text layer on the canvas.
|
|
184
|
-
* @param
|
|
185
|
-
* @param
|
|
186
|
-
* @param
|
|
187
|
-
* @param
|
|
187
|
+
* @param {SKRSContext2D} [ctx] - The canvas rendering context.
|
|
188
|
+
* @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
|
|
189
|
+
* @param {LayersManager} [manager] - The layers manager.
|
|
190
|
+
* @param {boolean} [debug] - Whether to enable debug logging.
|
|
188
191
|
*/
|
|
189
192
|
async draw(ctx, canvas, manager, debug) {
|
|
190
193
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
@@ -222,10 +225,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
222
225
|
let ym = y;
|
|
223
226
|
lines = [];
|
|
224
227
|
let line = '';
|
|
228
|
+
let charOffset = 0; // Track position in original text
|
|
225
229
|
for (let word of words) {
|
|
226
230
|
let linePlus = line + word + ' ';
|
|
227
231
|
if (ctx.measureText(linePlus).width > w) {
|
|
228
|
-
lines.push({ text: line, x: xm, y: ym });
|
|
232
|
+
lines.push({ text: line, x: xm, y: ym, startOffset: charOffset });
|
|
233
|
+
charOffset += line.length;
|
|
229
234
|
line = word + ' ';
|
|
230
235
|
ym += lineHeight;
|
|
231
236
|
}
|
|
@@ -233,46 +238,137 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
233
238
|
line = linePlus;
|
|
234
239
|
}
|
|
235
240
|
}
|
|
236
|
-
lines.push({ text: line, x: xm, y: ym });
|
|
241
|
+
lines.push({ text: line, x: xm, y: ym, startOffset: charOffset });
|
|
237
242
|
if (ym > ym + h)
|
|
238
243
|
break;
|
|
239
244
|
}
|
|
240
245
|
for (let line of lines) {
|
|
241
|
-
this.drawText(this.props, ctx, fillStyle, line.text, line.x, line.y, w);
|
|
246
|
+
this.drawText(this.props, ctx, fillStyle, line.text, line.x, line.y, w, line.startOffset);
|
|
242
247
|
}
|
|
243
248
|
}
|
|
244
249
|
else {
|
|
245
250
|
ctx.font = `${this.props.font.weight} ${this.props.font.size}px ${this.props.font.family}`;
|
|
246
|
-
this.drawText(this.props, ctx, fillStyle, this.props.text, x, y, w);
|
|
251
|
+
this.drawText(this.props, ctx, fillStyle, this.props.text, x, y, w, 0);
|
|
247
252
|
}
|
|
248
253
|
ctx.closePath();
|
|
249
254
|
ctx.restore();
|
|
250
255
|
}
|
|
251
256
|
/**
|
|
252
257
|
* Draws the text on the canvas.
|
|
253
|
-
* @param
|
|
254
|
-
* @param
|
|
255
|
-
* @param
|
|
256
|
-
* @param
|
|
257
|
-
* @param
|
|
258
|
-
* @param
|
|
259
|
-
* @param
|
|
258
|
+
* @param {ITextLayerProps} [props] - The properties of the text layer.
|
|
259
|
+
* @param {SKRSContext2D} [ctx] - The canvas rendering context.
|
|
260
|
+
* @param {string | CanvasGradient | CanvasPattern} [fillStyle] - The fill style for the text.
|
|
261
|
+
* @param {string} [text] - The text content.
|
|
262
|
+
* @param {number} [x] - The x-coordinate of the text.
|
|
263
|
+
* @param {number} [y] - The y-coordinate of the text.
|
|
264
|
+
* @param {number} [w] - The width of the text area.
|
|
265
|
+
* @param {number} [textOffset] - The offset of this text segment in the original full text (for multiline support).
|
|
260
266
|
*/
|
|
261
|
-
drawText(props, ctx, fillStyle, text, x, y, w) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
267
|
+
drawText(props, ctx, fillStyle, text, x, y, w, textOffset = 0) {
|
|
268
|
+
// If no substring colors are defined, draw normally
|
|
269
|
+
if (!props.subStringColors || props.subStringColors.length === 0) {
|
|
270
|
+
if (props.filled) {
|
|
271
|
+
ctx.fillStyle = fillStyle;
|
|
272
|
+
ctx.fillText(text, x, y, w);
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
ctx.strokeStyle = fillStyle;
|
|
276
|
+
ctx.lineWidth = props.stroke?.width || 1;
|
|
277
|
+
ctx.lineCap = props.stroke?.cap || 'butt';
|
|
278
|
+
ctx.lineJoin = props.stroke?.join || 'miter';
|
|
279
|
+
ctx.miterLimit = props.stroke?.miterLimit || 10;
|
|
280
|
+
ctx.lineDashOffset = props.stroke?.dashOffset || 0;
|
|
281
|
+
ctx.setLineDash(props.stroke?.dash || []);
|
|
282
|
+
ctx.strokeText(text, x, y, w);
|
|
283
|
+
}
|
|
284
|
+
return;
|
|
265
285
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
286
|
+
// Draw text with substring colors
|
|
287
|
+
const textLength = text.length;
|
|
288
|
+
let currentX = x;
|
|
289
|
+
// Save original text alignment and set to left for manual positioning
|
|
290
|
+
const originalAlign = ctx.textAlign;
|
|
291
|
+
ctx.textAlign = 'left';
|
|
292
|
+
// Adjust starting X based on text alignment
|
|
293
|
+
const alignValue = props.align;
|
|
294
|
+
if (alignValue === types_1.TextAlign.Center || alignValue === 'center') {
|
|
295
|
+
const totalWidth = ctx.measureText(text).width;
|
|
296
|
+
currentX = x - totalWidth / 2;
|
|
297
|
+
}
|
|
298
|
+
else if (alignValue === types_1.TextAlign.Right || alignValue === 'right' || alignValue === types_1.TextAlign.End || alignValue === 'end') {
|
|
299
|
+
const totalWidth = ctx.measureText(text).width;
|
|
300
|
+
currentX = x - totalWidth;
|
|
301
|
+
}
|
|
302
|
+
// Create segments based on substring colors
|
|
303
|
+
const segments = [];
|
|
304
|
+
// Sort substring colors by start position
|
|
305
|
+
const sortedColors = [...props.subStringColors].sort((a, b) => a.start - b.start);
|
|
306
|
+
let currentIndex = 0;
|
|
307
|
+
for (const subColor of sortedColors) {
|
|
308
|
+
// Adjust positions based on textOffset (for multiline support)
|
|
309
|
+
const globalStart = subColor.start;
|
|
310
|
+
const globalEnd = subColor.end;
|
|
311
|
+
const lineStart = textOffset;
|
|
312
|
+
const lineEnd = textOffset + textLength;
|
|
313
|
+
// Skip if this color segment doesn't overlap with current line
|
|
314
|
+
if (globalEnd <= lineStart || globalStart >= lineEnd) {
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
// Calculate local positions within this line
|
|
318
|
+
const localStart = Math.max(0, globalStart - lineStart);
|
|
319
|
+
const localEnd = Math.min(textLength, globalEnd - lineStart);
|
|
320
|
+
// Add base color segment before this substring color
|
|
321
|
+
if (currentIndex < localStart) {
|
|
322
|
+
segments.push({
|
|
323
|
+
text: text.substring(currentIndex, localStart),
|
|
324
|
+
color: fillStyle,
|
|
325
|
+
start: currentIndex,
|
|
326
|
+
end: localStart
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
// Add colored substring
|
|
330
|
+
if (localStart < localEnd) {
|
|
331
|
+
segments.push({
|
|
332
|
+
text: text.substring(localStart, localEnd),
|
|
333
|
+
color: subColor.color,
|
|
334
|
+
start: localStart,
|
|
335
|
+
end: localEnd
|
|
336
|
+
});
|
|
337
|
+
currentIndex = localEnd;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
// Add remaining text with base color
|
|
341
|
+
if (currentIndex < textLength) {
|
|
342
|
+
segments.push({
|
|
343
|
+
text: text.substring(currentIndex),
|
|
344
|
+
color: fillStyle,
|
|
345
|
+
start: currentIndex,
|
|
346
|
+
end: textLength
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
// Draw each segment
|
|
350
|
+
for (const segment of segments) {
|
|
351
|
+
if (segment.text.length === 0)
|
|
352
|
+
continue;
|
|
353
|
+
const segmentWidth = ctx.measureText(segment.text).width;
|
|
354
|
+
if (props.filled) {
|
|
355
|
+
ctx.fillStyle = segment.color;
|
|
356
|
+
ctx.fillText(segment.text, currentX, y);
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
ctx.strokeStyle = segment.color;
|
|
360
|
+
ctx.lineWidth = props.stroke?.width || 1;
|
|
361
|
+
ctx.lineCap = props.stroke?.cap || 'butt';
|
|
362
|
+
ctx.lineJoin = props.stroke?.join || 'miter';
|
|
363
|
+
ctx.miterLimit = props.stroke?.miterLimit || 10;
|
|
364
|
+
ctx.lineDashOffset = props.stroke?.dashOffset || 0;
|
|
365
|
+
ctx.setLineDash(props.stroke?.dash || []);
|
|
366
|
+
ctx.strokeText(segment.text, currentX, y);
|
|
367
|
+
}
|
|
368
|
+
currentX += segmentWidth;
|
|
275
369
|
}
|
|
370
|
+
// Restore original text alignment
|
|
371
|
+
ctx.textAlign = originalAlign;
|
|
276
372
|
}
|
|
277
373
|
/**
|
|
278
374
|
* Converts the Text Layer to a JSON representation.
|
|
@@ -290,29 +386,29 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
290
386
|
}
|
|
291
387
|
/**
|
|
292
388
|
* Validates the properties of the Text Layer.
|
|
293
|
-
* @param
|
|
389
|
+
* @param {ITextLayerProps} [data] - The properties to validate.
|
|
294
390
|
* @returns {ITextLayerProps} The validated properties.
|
|
295
391
|
*/
|
|
296
|
-
validateProps(
|
|
392
|
+
validateProps(data) {
|
|
297
393
|
return {
|
|
298
|
-
...super.validateProps(
|
|
299
|
-
|
|
394
|
+
...super.validateProps(data),
|
|
395
|
+
filled: data.filled || true,
|
|
396
|
+
fillStyle: data.fillStyle || '#000000',
|
|
397
|
+
text: data.text || "",
|
|
300
398
|
font: {
|
|
301
|
-
family:
|
|
302
|
-
size:
|
|
303
|
-
weight:
|
|
399
|
+
family: data.font?.family || "Arial",
|
|
400
|
+
size: data.font?.size || 16,
|
|
401
|
+
weight: data.font?.weight || types_1.FontWeight.Regular,
|
|
304
402
|
},
|
|
305
403
|
multiline: {
|
|
306
|
-
enabled:
|
|
307
|
-
spacing:
|
|
404
|
+
enabled: data.multiline?.enabled || false,
|
|
405
|
+
spacing: data.multiline?.spacing || 1.1,
|
|
308
406
|
},
|
|
309
407
|
size: {
|
|
310
|
-
width:
|
|
311
|
-
height:
|
|
408
|
+
width: data.size?.width || "vw",
|
|
409
|
+
height: data.size?.height || 0,
|
|
312
410
|
},
|
|
313
|
-
align:
|
|
314
|
-
fillStyle: props.fillStyle || "#000000",
|
|
315
|
-
filled: props.filled !== undefined ? props.filled : true,
|
|
411
|
+
align: data.align || types_1.TextAlign.Left,
|
|
316
412
|
};
|
|
317
413
|
}
|
|
318
414
|
}
|
|
@@ -16,24 +16,24 @@ export declare class Exporter {
|
|
|
16
16
|
constructor(canvas: LazyCanvas);
|
|
17
17
|
/**
|
|
18
18
|
* Saves a file to the filesystem.
|
|
19
|
-
* @param
|
|
20
|
-
* @param
|
|
21
|
-
* @param
|
|
19
|
+
* @param {any} [buffer] - The data to be saved.
|
|
20
|
+
* @param {Extensions} [extension] - The file extension.
|
|
21
|
+
* @param {string} [name] - The name of the file (optional).
|
|
22
22
|
* @throws {LazyError} If the buffer or extension is not provided.
|
|
23
23
|
*/
|
|
24
24
|
private saveFile;
|
|
25
25
|
/**
|
|
26
26
|
* Exports all layers from the LayersManager as an array of JSON objects.
|
|
27
|
-
* @param
|
|
27
|
+
* @param {LayersManager} [manager] - The LayersManager instance.
|
|
28
28
|
* @returns {any[]} An array of JSON representations of the layers.
|
|
29
29
|
*/
|
|
30
30
|
private exportLayers;
|
|
31
31
|
/**
|
|
32
32
|
* Exports the canvas to the specified format.
|
|
33
|
-
* @param
|
|
34
|
-
* @param
|
|
35
|
-
* @param opts.name
|
|
36
|
-
* @param opts.saveAsFile
|
|
33
|
+
* @param {AnyExport} [exportType] - The type of export (e.g., "png", "json").
|
|
34
|
+
* @param {Object} [opts] - Optional settings.
|
|
35
|
+
* @param {string} [opts.name] - The name of the file (optional).
|
|
36
|
+
* @param {boolean} [opts.saveAsFile] - Whether to save the export as a file (optional).
|
|
37
37
|
* @returns {Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>} The exported data.
|
|
38
38
|
* @throws {LazyError} If the export type is not supported.
|
|
39
39
|
*/
|
|
@@ -43,7 +43,7 @@ export declare class Exporter {
|
|
|
43
43
|
}): Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>;
|
|
44
44
|
/**
|
|
45
45
|
* Synchronously exports the canvas to the specified format.
|
|
46
|
-
* @param
|
|
46
|
+
* @param {AnyExport} [exportType] - The type of export (e.g., "json").
|
|
47
47
|
* @returns {IOLazyCanvas | void} The exported data or void if the export type is unsupported.
|
|
48
48
|
*/
|
|
49
49
|
syncExport(exportType: AnyExport): IOLazyCanvas | void;
|
|
@@ -56,9 +56,9 @@ class Exporter {
|
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Saves a file to the filesystem.
|
|
59
|
-
* @param
|
|
60
|
-
* @param
|
|
61
|
-
* @param
|
|
59
|
+
* @param {any} [buffer] - The data to be saved.
|
|
60
|
+
* @param {Extensions} [extension] - The file extension.
|
|
61
|
+
* @param {string} [name] - The name of the file (optional).
|
|
62
62
|
* @throws {LazyError} If the buffer or extension is not provided.
|
|
63
63
|
*/
|
|
64
64
|
async saveFile(buffer, extension, name) {
|
|
@@ -70,7 +70,7 @@ class Exporter {
|
|
|
70
70
|
}
|
|
71
71
|
/**
|
|
72
72
|
* Exports all layers from the LayersManager as an array of JSON objects.
|
|
73
|
-
* @param
|
|
73
|
+
* @param {LayersManager} [manager] - The LayersManager instance.
|
|
74
74
|
* @returns {any[]} An array of JSON representations of the layers.
|
|
75
75
|
*/
|
|
76
76
|
exportLayers(manager) {
|
|
@@ -82,10 +82,10 @@ class Exporter {
|
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
84
|
* Exports the canvas to the specified format.
|
|
85
|
-
* @param
|
|
86
|
-
* @param
|
|
87
|
-
* @param opts.name
|
|
88
|
-
* @param opts.saveAsFile
|
|
85
|
+
* @param {AnyExport} [exportType] - The type of export (e.g., "png", "json").
|
|
86
|
+
* @param {Object} [opts] - Optional settings.
|
|
87
|
+
* @param {string} [opts.name] - The name of the file (optional).
|
|
88
|
+
* @param {boolean} [opts.saveAsFile] - Whether to save the export as a file (optional).
|
|
89
89
|
* @returns {Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>} The exported data.
|
|
90
90
|
* @throws {LazyError} If the export type is not supported.
|
|
91
91
|
*/
|
|
@@ -167,7 +167,7 @@ class Exporter {
|
|
|
167
167
|
}
|
|
168
168
|
/**
|
|
169
169
|
* Synchronously exports the canvas to the specified format.
|
|
170
|
-
* @param
|
|
170
|
+
* @param {AnyExport} [exportType] - The type of export (e.g., "json").
|
|
171
171
|
* @returns {IOLazyCanvas | void} The exported data or void if the export type is unsupported.
|
|
172
172
|
*/
|
|
173
173
|
syncExport(exportType) {
|
|
@@ -53,28 +53,28 @@ export declare class Font implements IFont {
|
|
|
53
53
|
constructor();
|
|
54
54
|
/**
|
|
55
55
|
* Sets the font family.
|
|
56
|
-
* @param
|
|
56
|
+
* @param {string} [family] - The `family` of the font.
|
|
57
57
|
* @returns {this} The current instance for chaining.
|
|
58
58
|
* @throws {Error} If the family is not provided.
|
|
59
59
|
*/
|
|
60
60
|
setFamily(family: string): this;
|
|
61
61
|
/**
|
|
62
62
|
* Sets the font weight.
|
|
63
|
-
* @param
|
|
63
|
+
* @param {AnyWeight} [weight] - The `weight` of the font.
|
|
64
64
|
* @returns {this} The current instance for chaining.
|
|
65
65
|
* @throws {Error} If the weight is not provided.
|
|
66
66
|
*/
|
|
67
67
|
setWeight(weight: AnyWeight): this;
|
|
68
68
|
/**
|
|
69
69
|
* Sets the file path of the font.
|
|
70
|
-
* @param
|
|
70
|
+
* @param {string} [path] - The `path` of the font.
|
|
71
71
|
* @returns {this} The current instance for chaining.
|
|
72
72
|
* @throws {Error} If the path is not provided.
|
|
73
73
|
*/
|
|
74
74
|
setPath(path: string): this;
|
|
75
75
|
/**
|
|
76
76
|
* Sets the base64 representation of the font.
|
|
77
|
-
* @param
|
|
77
|
+
* @param {Buffer} [base64] - The `base64` of the font.
|
|
78
78
|
* @returns {this} The current instance for chaining.
|
|
79
79
|
* @throws {Error} If the base64 is not provided.
|
|
80
80
|
*/
|
|
@@ -31,7 +31,7 @@ class Font {
|
|
|
31
31
|
}
|
|
32
32
|
/**
|
|
33
33
|
* Sets the font family.
|
|
34
|
-
* @param
|
|
34
|
+
* @param {string} [family] - The `family` of the font.
|
|
35
35
|
* @returns {this} The current instance for chaining.
|
|
36
36
|
* @throws {Error} If the family is not provided.
|
|
37
37
|
*/
|
|
@@ -43,7 +43,7 @@ class Font {
|
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* Sets the font weight.
|
|
46
|
-
* @param
|
|
46
|
+
* @param {AnyWeight} [weight] - The `weight` of the font.
|
|
47
47
|
* @returns {this} The current instance for chaining.
|
|
48
48
|
* @throws {Error} If the weight is not provided.
|
|
49
49
|
*/
|
|
@@ -55,7 +55,7 @@ class Font {
|
|
|
55
55
|
}
|
|
56
56
|
/**
|
|
57
57
|
* Sets the file path of the font.
|
|
58
|
-
* @param
|
|
58
|
+
* @param {string} [path] - The `path` of the font.
|
|
59
59
|
* @returns {this} The current instance for chaining.
|
|
60
60
|
* @throws {Error} If the path is not provided.
|
|
61
61
|
*/
|
|
@@ -67,7 +67,7 @@ class Font {
|
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Sets the base64 representation of the font.
|
|
70
|
-
* @param
|
|
70
|
+
* @param {Buffer} [base64] - The `base64` of the font.
|
|
71
71
|
* @returns {this} The current instance for chaining.
|
|
72
72
|
* @throws {Error} If the base64 is not provided.
|
|
73
73
|
*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AnyCentring, AnyGradientType, FillType, StringColorType, ScaleType } from "../../types";
|
|
2
2
|
import { SKRSContext2D } from "@napi-rs/canvas";
|
|
3
|
-
import { LayersManager } from "../managers
|
|
3
|
+
import { LayersManager } from "../managers";
|
|
4
4
|
/**
|
|
5
5
|
* Interface representing a gradient.
|
|
6
6
|
*/
|
|
@@ -82,54 +82,59 @@ export declare class Gradient implements IGradient {
|
|
|
82
82
|
angle?: number;
|
|
83
83
|
/**
|
|
84
84
|
* Constructs a new Gradient instance.
|
|
85
|
-
* @param
|
|
86
|
-
* @param opts.props
|
|
85
|
+
* @param {Object} [opts] - Optional properties for the gradient.
|
|
86
|
+
* @param {IGradient} [opts.props] - The gradient properties.
|
|
87
87
|
*/
|
|
88
88
|
constructor(opts?: {
|
|
89
89
|
props?: IGradient;
|
|
90
90
|
});
|
|
91
91
|
/**
|
|
92
92
|
* Sets the type of the gradient.
|
|
93
|
-
* @param
|
|
93
|
+
* @param {AnyGradientType} [type] - The type of the gradient (e.g., linear, radial, conic).
|
|
94
94
|
* @returns {this} The current instance for chaining.
|
|
95
95
|
*/
|
|
96
96
|
setType(type: AnyGradientType): this;
|
|
97
97
|
/**
|
|
98
98
|
* Adds points to the gradient.
|
|
99
|
-
* @param
|
|
99
|
+
* @param {GradientPoint[]} [points] - The points to add to the gradient.
|
|
100
100
|
* @returns {this} The current instance for chaining.
|
|
101
101
|
*/
|
|
102
102
|
addPoints(...points: GradientPoint[]): this;
|
|
103
103
|
/**
|
|
104
104
|
* Sets the points of the gradient.
|
|
105
|
-
* @param
|
|
105
|
+
* @param {GradientPoint[]} [points] - The points to set for the gradient.
|
|
106
106
|
* @returns {this} The current instance for chaining.
|
|
107
107
|
*/
|
|
108
108
|
setPoints(...points: GradientPoint[]): this;
|
|
109
109
|
/**
|
|
110
110
|
* Removes points from the gradient by their indexes.
|
|
111
|
-
* @param
|
|
111
|
+
* @param {number[]} [indexes] - The indexes of the points to remove.
|
|
112
112
|
* @returns {this} The current instance for chaining.
|
|
113
113
|
*/
|
|
114
114
|
removePoints(...indexes: number[]): this;
|
|
115
115
|
/**
|
|
116
116
|
* Adds color stops to the gradient.
|
|
117
|
-
* @param
|
|
117
|
+
* @param {GradientColorStop[]} [stops] - The color stops to add to the gradient.
|
|
118
118
|
* @returns {this} The current instance for chaining.
|
|
119
119
|
*/
|
|
120
120
|
addStops(...stops: GradientColorStop[]): this;
|
|
121
121
|
/**
|
|
122
122
|
* Sets the color stops of the gradient.
|
|
123
|
-
* @param
|
|
123
|
+
* @param {GradientColorStop[]} [stops] - The color stops to set for the gradient.
|
|
124
124
|
* @returns {this} The current instance for chaining.
|
|
125
125
|
*/
|
|
126
126
|
setStops(...stops: GradientColorStop[]): this;
|
|
127
127
|
/**
|
|
128
128
|
* Removes color stops from the gradient by their indexes.
|
|
129
|
-
* @param
|
|
129
|
+
* @param {number[]} [indexes] - The indexes of the color stops to remove.
|
|
130
130
|
* @returns {this} The current instance for chaining.
|
|
131
131
|
*/
|
|
132
132
|
removeStops(...indexes: number[]): this;
|
|
133
|
+
/**
|
|
134
|
+
* Sets the angle of the gradient (used for linear gradients).
|
|
135
|
+
* @param {number} [angle] - The angle in degrees.
|
|
136
|
+
* @returns {this} The current instance for chaining.
|
|
137
|
+
*/
|
|
133
138
|
setAngle(angle: number): this;
|
|
134
139
|
draw(ctx: SKRSContext2D, opts?: {
|
|
135
140
|
debug?: boolean;
|