@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.
Files changed (59) hide show
  1. package/dist/helpers/index.d.ts +3 -0
  2. package/dist/helpers/index.js +19 -0
  3. package/dist/index.d.ts +5 -12
  4. package/dist/index.js +5 -31
  5. package/dist/structures/LazyCanvas.d.ts +12 -16
  6. package/dist/structures/LazyCanvas.js +24 -27
  7. package/dist/structures/components/BaseLayer.d.ts +17 -25
  8. package/dist/structures/components/BaseLayer.js +16 -18
  9. package/dist/structures/components/BezierLayer.d.ts +29 -21
  10. package/dist/structures/components/BezierLayer.js +22 -20
  11. package/dist/structures/components/ClearLayer.d.ts +15 -15
  12. package/dist/structures/components/ClearLayer.js +14 -14
  13. package/dist/structures/components/Group.d.ts +10 -11
  14. package/dist/structures/components/Group.js +9 -10
  15. package/dist/structures/components/ImageLayer.d.ts +15 -15
  16. package/dist/structures/components/ImageLayer.js +11 -11
  17. package/dist/structures/components/LineLayer.d.ts +28 -20
  18. package/dist/structures/components/LineLayer.js +21 -19
  19. package/dist/structures/components/MorphLayer.d.ts +29 -21
  20. package/dist/structures/components/MorphLayer.js +19 -17
  21. package/dist/structures/components/Path2DLayer.d.ts +21 -72
  22. package/dist/structures/components/Path2DLayer.js +4 -108
  23. package/dist/structures/components/QuadraticLayer.d.ts +30 -22
  24. package/dist/structures/components/QuadraticLayer.js +23 -21
  25. package/dist/structures/components/TextLayer.d.ts +54 -41
  26. package/dist/structures/components/TextLayer.js +165 -69
  27. package/dist/structures/helpers/Exporter.d.ts +9 -9
  28. package/dist/structures/helpers/Exporter.js +9 -9
  29. package/dist/structures/helpers/Font.d.ts +4 -4
  30. package/dist/structures/helpers/Font.js +4 -4
  31. package/dist/structures/helpers/Gradient.d.ts +15 -10
  32. package/dist/structures/helpers/Gradient.js +14 -9
  33. package/dist/structures/helpers/Link.d.ts +5 -5
  34. package/dist/structures/helpers/Link.js +5 -5
  35. package/dist/structures/helpers/Pattern.d.ts +5 -5
  36. package/dist/structures/helpers/Pattern.js +5 -5
  37. package/dist/structures/helpers/index.d.ts +7 -7
  38. package/dist/structures/helpers/readers/JSONReader.d.ts +12 -12
  39. package/dist/structures/helpers/readers/JSONReader.js +12 -12
  40. package/dist/structures/helpers/readers/YAMLReader.d.ts +4 -4
  41. package/dist/structures/helpers/readers/YAMLReader.js +4 -4
  42. package/dist/structures/managers/AnimationManager.d.ts +11 -11
  43. package/dist/structures/managers/AnimationManager.js +11 -11
  44. package/dist/structures/managers/FontsManager.d.ts +14 -15
  45. package/dist/structures/managers/FontsManager.js +14 -15
  46. package/dist/structures/managers/LayersManager.d.ts +15 -15
  47. package/dist/structures/managers/LayersManager.js +19 -19
  48. package/dist/structures/managers/PluginManager.d.ts +11 -9
  49. package/dist/structures/managers/PluginManager.js +9 -8
  50. package/dist/structures/managers/RenderManager.d.ts +10 -10
  51. package/dist/structures/managers/RenderManager.js +10 -10
  52. package/dist/structures/managers/index.d.ts +5 -0
  53. package/dist/structures/managers/index.js +21 -0
  54. package/dist/types/index.d.ts +0 -1
  55. package/dist/types/index.js +0 -1
  56. package/dist/types/types.d.ts +7 -1
  57. package/dist/utils/utils.d.ts +5 -5
  58. package/dist/utils/utils.js +8 -2
  59. package/package.json +1 -2
@@ -15,8 +15,8 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
15
15
  props;
16
16
  /**
17
17
  * Constructs a new QuadraticLayer instance.
18
- * @param props {IQuadraticLayerProps} - The properties of the Quadratic Layer.
19
- * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
18
+ * @param {IQuadraticLayerProps} [props] - The properties of the Quadratic Layer.
19
+ * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
20
20
  */
21
21
  constructor(props, misc) {
22
22
  super(types_1.LayerType.QuadraticCurve, props || {}, misc);
@@ -25,8 +25,8 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
25
25
  }
26
26
  /**
27
27
  * Sets the control point of the quadratic layer.
28
- * @param x {ScaleType} - The x-coordinate of the control point.
29
- * @param y {ScaleType} - The y-coordinate of the control point.
28
+ * @param {ScaleType} [x] - The x-coordinate of the control point.
29
+ * @param {ScaleType} [y] - The y-coordinate of the control point.
30
30
  * @returns {this} The current instance for chaining.
31
31
  */
32
32
  setControlPoint(x, y) {
@@ -35,8 +35,8 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
35
35
  }
36
36
  /**
37
37
  * Sets the end point of the quadratic layer.
38
- * @param x {ScaleType} - The x-coordinate of the end point.
39
- * @param y {ScaleType} - The y-coordinate of the end point.
38
+ * @param {ScaleType} [x] - The x-coordinate of the end point.
39
+ * @param {ScaleType} [y] - The y-coordinate of the end point.
40
40
  * @returns {this} The current instance for chaining.
41
41
  */
42
42
  setEndPosition(x, y) {
@@ -45,7 +45,7 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
45
45
  }
46
46
  /**
47
47
  * Sets the color of the layer.
48
- * @param color {ColorType} - The color of the layer.
48
+ * @param {ColorType} [color] - The color of the layer.
49
49
  * @returns {this} The current instance for chaining.
50
50
  * @throws {LazyError} If the color is not provided or invalid.
51
51
  */
@@ -59,12 +59,12 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
59
59
  }
60
60
  /**
61
61
  * Sets the stroke properties of the layer.
62
- * @param width {number} - The width of the stroke.
63
- * @param cap {CanvasLineCap} - The cap style of the stroke.
64
- * @param join {CanvasLineJoin} - The join style of the stroke.
65
- * @param dash {number[]} - The dash pattern of the stroke.
66
- * @param dashOffset {number} - The dash offset of the stroke.
67
- * @param miterLimit {number} - The miter limit of the stroke.
62
+ * @param {number} [width] - The width of the stroke.
63
+ * @param {string} [cap] - The cap style of the stroke.
64
+ * @param {string} [join] - The join style of the stroke.
65
+ * @param {number[]} [dash] - The dash pattern of the stroke.
66
+ * @param {number} [dashOffset] - The dash offset of the stroke.
67
+ * @param {number} [miterLimit] - The miter limit of the stroke.
68
68
  * @returns {this} The current instance for chaining.
69
69
  */
70
70
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
@@ -80,9 +80,9 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
80
80
  }
81
81
  /**
82
82
  * Calculates the bounding box of the quadratic curve.
83
- * @param ctx {SKRSContext2D} - The canvas rendering context.
84
- * @param canvas {Canvas | SvgCanvas} - The canvas instance.
85
- * @param manager {LayersManager} - The layers manager.
83
+ * @param {SKRSContext2D} [ctx] - The canvas rendering context.
84
+ * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
85
+ * @param {LayersManager} [manager] - The layers manager.
86
86
  * @returns {Object} The bounding box details including max, min, center, width, and height.
87
87
  */
88
88
  getBoundingBox(ctx, canvas, manager) {
@@ -100,10 +100,10 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
100
100
  }
101
101
  /**
102
102
  * Draws the quadratic curve on the canvas.
103
- * @param ctx {SKRSContext2D} - The canvas rendering context.
104
- * @param canvas {Canvas | SvgCanvas} - The canvas instance.
105
- * @param manager {LayersManager} - The layers manager.
106
- * @param debug {boolean} - Whether to enable debug logging.
103
+ * @param {SKRSContext2D} [ctx] - The canvas rendering context.
104
+ * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
105
+ * @param {LayersManager} [manager] - The layers manager.
106
+ * @param {boolean} [debug] - Whether to enable debug logging.
107
107
  */
108
108
  async draw(ctx, canvas, manager, debug) {
109
109
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
@@ -154,12 +154,14 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
154
154
  }
155
155
  /**
156
156
  * Validates the properties of the Quadratic Layer.
157
- * @param data {IQuadraticLayerProps} - The properties to validate.
157
+ * @param {IQuadraticLayerProps} [data] - The properties to validate.
158
158
  * @returns {IQuadraticLayerProps} The validated properties.
159
159
  */
160
160
  validateProps(data) {
161
161
  return {
162
162
  ...super.validateProps(data),
163
+ filled: data.filled || false,
164
+ fillStyle: data.fillStyle || '#000000',
163
165
  centring: data.centring || types_1.Centring.None,
164
166
  controlPoints: data.controlPoints || [{ x: 0, y: 0 }],
165
167
  endPoint: data.endPoint || { x: 0, y: 0 },
@@ -1,7 +1,7 @@
1
1
  import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
- import { ScaleType, ColorType, AnyWeight, AnyTextAlign, AnyTextBaseline, AnyTextDirection, LineCap, LineJoin, LayerType } from "../../types";
2
+ import { ScaleType, ColorType, AnyWeight, AnyTextAlign, AnyTextBaseline, AnyTextDirection, LineCap, LineJoin, LayerType, SubStringColor } from "../../types";
3
3
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
- import { LayersManager } from "../managers/LayersManager";
4
+ import { LayersManager } from "../managers";
5
5
  /**
6
6
  * Interface representing a Text Layer.
7
7
  */
@@ -23,6 +23,18 @@ export interface ITextLayerProps extends IBaseLayerProps {
23
23
  * The text content of the layer.
24
24
  */
25
25
  text: string;
26
+ /**
27
+ * Whether the layer is filled.
28
+ */
29
+ filled: boolean;
30
+ /**
31
+ * The fill style (color or pattern) of the layer.
32
+ */
33
+ fillStyle: ColorType;
34
+ /**
35
+ * Array of substring color configurations for partial text coloring.
36
+ */
37
+ subStringColors?: SubStringColor[];
26
38
  /**
27
39
  * The font configuration for the text.
28
40
  */
@@ -126,21 +138,21 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
126
138
  props: ITextLayerProps;
127
139
  /**
128
140
  * Constructs a new TextLayer instance.
129
- * @param props {ITextLayerProps} - The properties of the Text Layer.
130
- * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
141
+ * @param {ITextLayerProps} [props] - The properties of the Text Layer.
142
+ * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
131
143
  */
132
144
  constructor(props?: ITextLayerProps, misc?: IBaseLayerMisc);
133
145
  /**
134
146
  * Sets the text of the text layer.
135
- * @param text {string} - The text content of the layer.
147
+ * @param {string} [text] - The text content of the layer.
136
148
  * @returns {this} The current instance for chaining.
137
149
  */
138
150
  setText(text: string): this;
139
151
  /**
140
152
  * Sets the font of the text layer.
141
- * @param familyOrConfig {string | { family: string; size: number; weight: AnyWeight }} - The font family or configuration object.
142
- * @param size {number} - The font size (required if `familyOrConfig` is a string).
143
- * @param weight {AnyWeight} - The font weight (required if `familyOrConfig` is a string).
153
+ * @param {string | { family: string; size: number; weight: AnyWeight }} [familyOrConfig] - The font family or configuration object.
154
+ * @param {number} [size] - The font size (required if `familyOrConfig` is a string).
155
+ * @param {AnyWeight} [weight] - The font weight (required if `familyOrConfig` is a string).
144
156
  * @returns {this} The current instance for chaining.
145
157
  * @throws {LazyError} If size or weight is not provided when `familyOrConfig` is a string.
146
158
  */
@@ -151,65 +163,65 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
151
163
  }, size?: number, weight?: AnyWeight): this;
152
164
  /**
153
165
  * Configures the multiline properties of the text layer.
154
- * @param enabled {boolean} - Whether multiline is enabled.
155
- * @param width {ScaleType} - The width of the multiline text area.
156
- * @param height {ScaleType} - The height of the multiline text area.
157
- * @param spacing {number} - The spacing between lines (optional).
166
+ * @param {ScaleType} [width] - The width of the multiline text area.
167
+ * @param {ScaleType} [height] - The height of the multiline text area.
168
+ * @param {number} [spacing] - The spacing between lines (optional).
158
169
  * @returns {this} The current instance for chaining.
159
170
  */
160
- setMultiline(enabled: boolean, width: ScaleType, height: ScaleType, spacing?: number): this;
171
+ setMultiline(width: ScaleType, height: ScaleType, spacing?: number): this;
161
172
  /**
162
173
  * Sets the color of the text layer.
163
- * @param color {ColorType} - The color of the text.
174
+ * @param {ColorType} [color] - The base color of the text.
175
+ * @param {SubStringColor[]} [sub] - Optional substring colors for partial text coloring.
164
176
  * @returns {this} The current instance for chaining.
165
177
  * @throws {LazyError} If the color is not provided or invalid.
166
178
  */
167
- setColor(color: ColorType): this;
179
+ setColor(color: ColorType, ...sub: SubStringColor[]): this;
168
180
  /**
169
181
  * Sets the alignment of the text layer.
170
- * @param align {AnyTextAlign} - The alignment of the text.
182
+ * @param {AnyTextAlign} [align] - The alignment of the text.
171
183
  * @returns {this} The current instance for chaining.
172
184
  */
173
185
  setAlign(align: AnyTextAlign): this;
174
186
  /**
175
187
  * Sets the baseline of the text layer.
176
- * @param baseline {AnyTextBaseline} - The baseline of the text.
188
+ * @param {AnyTextBaseline} [baseline] - The baseline of the text.
177
189
  * @returns {this} The current instance for chaining.
178
190
  */
179
191
  setBaseline(baseline: AnyTextBaseline): this;
180
192
  /**
181
193
  * Sets the direction of the text layer.
182
- * @param direction {AnyTextDirection} - The direction of the text.
194
+ * @param {AnyTextDirection} [direction] - The direction of the text.
183
195
  * @returns {this} The current instance for chaining.
184
196
  */
185
197
  setDirection(direction: AnyTextDirection): this;
186
198
  /**
187
199
  * Configures the stroke properties of the text layer.
188
- * @param width {number} - The width of the stroke.
189
- * @param cap {string} - The cap style of the stroke (optional).
190
- * @param join {string} - The join style of the stroke (optional).
191
- * @param dash {number[]} - The dash pattern of the stroke (optional).
192
- * @param dashOffset {number} - The dash offset of the stroke (optional).
193
- * @param miterLimit {number} - The miter limit of the stroke (optional).
200
+ * @param {number} [width] - The width of the stroke.
201
+ * @param {string} [cap] - The cap style of the stroke.
202
+ * @param {string} [join] - The join style of the stroke.
203
+ * @param {number[]} [dash] - The dash pattern of the stroke.
204
+ * @param {number} [dashOffset] - The dash offset of the stroke.
205
+ * @param {number} [miterLimit] - The miter limit of the stroke.
194
206
  * @returns {this} The current instance for chaining.
195
207
  */
196
208
  setStroke(width: number, cap?: LineCap, join?: LineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
197
209
  /**
198
210
  * Sets the spacing between words in the text layer.
199
- * @param wordSpacing {number} - The spacing between words.
211
+ * @param {number} [wordSpacing] - The spacing between words.
200
212
  * @returns {this} The current instance for chaining.
201
213
  */
202
214
  setWordSpacing(wordSpacing: number): this;
203
215
  /**
204
216
  * Sets the spacing between letters in the text layer.
205
- * @param letterSpacing {number} - The spacing between letters.
217
+ * @param {number} [letterSpacing] - The spacing between letters.
206
218
  * @returns {this} The current instance for chaining.
207
219
  */
208
220
  setLetterSpacing(letterSpacing: number): this;
209
221
  /**
210
222
  * Measures the dimensions of the text.
211
- * @param ctx {SKRSContext2D} - The canvas rendering context.
212
- * @param canvas {Canvas | SvgCanvas} - The canvas instance.
223
+ * @param {SKRSContext2D} [ctx] - The canvas rendering context.
224
+ * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
213
225
  * @returns {Object} The width and height of the text.
214
226
  */
215
227
  measureText(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas): {
@@ -218,21 +230,22 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
218
230
  };
219
231
  /**
220
232
  * Draws the text layer on the canvas.
221
- * @param ctx {SKRSContext2D} - The canvas rendering context.
222
- * @param canvas {Canvas | SvgCanvas} - The canvas instance.
223
- * @param manager {LayersManager} - The layers manager.
224
- * @param debug {boolean} - Whether to enable debug logging.
233
+ * @param {SKRSContext2D} [ctx] - The canvas rendering context.
234
+ * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
235
+ * @param {LayersManager} [manager] - The layers manager.
236
+ * @param {boolean} [debug] - Whether to enable debug logging.
225
237
  */
226
238
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
227
239
  /**
228
240
  * Draws the text on the canvas.
229
- * @param props {ITextLayerProps} - The properties of the text layer.
230
- * @param ctx {SKRSContext2D} - The canvas rendering context.
231
- * @param fillStyle {string | CanvasGradient | CanvasPattern} - The fill style for the text.
232
- * @param text {string} - The text content.
233
- * @param x {number} - The x-coordinate of the text.
234
- * @param y {number} - The y-coordinate of the text.
235
- * @param w {number} - The width of the text area.
241
+ * @param {ITextLayerProps} [props] - The properties of the text layer.
242
+ * @param {SKRSContext2D} [ctx] - The canvas rendering context.
243
+ * @param {string | CanvasGradient | CanvasPattern} [fillStyle] - The fill style for the text.
244
+ * @param {string} [text] - The text content.
245
+ * @param {number} [x] - The x-coordinate of the text.
246
+ * @param {number} [y] - The y-coordinate of the text.
247
+ * @param {number} [w] - The width of the text area.
248
+ * @param {number} [textOffset] - The offset of this text segment in the original full text (for multiline support).
236
249
  */
237
250
  private drawText;
238
251
  /**
@@ -242,8 +255,8 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
242
255
  toJSON(): ITextLayer;
243
256
  /**
244
257
  * Validates the properties of the Text Layer.
245
- * @param props {ITextLayerProps} - The properties to validate.
258
+ * @param {ITextLayerProps} [data] - The properties to validate.
246
259
  * @returns {ITextLayerProps} The validated properties.
247
260
  */
248
- protected validateProps(props: ITextLayerProps): ITextLayerProps;
261
+ protected validateProps(data: ITextLayerProps): ITextLayerProps;
249
262
  }