@nmmty/lazycanvas 0.6.4 → 1.0.0-dev.3

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 (80) hide show
  1. package/ReadMe.md +1 -1
  2. package/biome.json +41 -0
  3. package/dist/core/Interpolation.d.ts +30 -0
  4. package/dist/core/Interpolation.js +200 -0
  5. package/dist/core/Scene.d.ts +96 -0
  6. package/dist/core/Scene.js +172 -0
  7. package/dist/core/Signal.d.ts +133 -0
  8. package/dist/core/Signal.js +255 -0
  9. package/dist/core/SignalUtils.d.ts +133 -0
  10. package/dist/core/SignalUtils.js +333 -0
  11. package/dist/core/ThreadScheduler.d.ts +38 -0
  12. package/dist/core/ThreadScheduler.js +74 -0
  13. package/dist/helpers/Filters.js +1 -1
  14. package/dist/helpers/FontsList.js +18 -18
  15. package/dist/helpers/Utlis.d.ts +3 -3
  16. package/dist/helpers/Utlis.js +15 -18
  17. package/dist/helpers/index.d.ts +3 -3
  18. package/dist/index.d.ts +10 -0
  19. package/dist/index.js +10 -0
  20. package/dist/jsx-runtime.d.ts +17 -0
  21. package/dist/jsx-runtime.js +111 -0
  22. package/dist/structures/LazyCanvas.d.ts +3 -45
  23. package/dist/structures/LazyCanvas.js +11 -74
  24. package/dist/structures/components/BaseLayer.d.ts +34 -12
  25. package/dist/structures/components/BaseLayer.js +68 -35
  26. package/dist/structures/components/BezierLayer.d.ts +18 -39
  27. package/dist/structures/components/BezierLayer.js +85 -48
  28. package/dist/structures/components/{Group.d.ts → Div.d.ts} +26 -20
  29. package/dist/structures/components/{Group.js → Div.js} +39 -40
  30. package/dist/structures/components/ImageLayer.d.ts +2 -2
  31. package/dist/structures/components/ImageLayer.js +25 -26
  32. package/dist/structures/components/LineLayer.d.ts +13 -39
  33. package/dist/structures/components/LineLayer.js +44 -44
  34. package/dist/structures/components/MorphLayer.d.ts +4 -33
  35. package/dist/structures/components/MorphLayer.js +33 -47
  36. package/dist/structures/components/Path2DLayer.d.ts +4 -32
  37. package/dist/structures/components/Path2DLayer.js +28 -33
  38. package/dist/structures/components/PolygonLayer.d.ts +95 -0
  39. package/dist/structures/components/PolygonLayer.js +205 -0
  40. package/dist/structures/components/QuadraticLayer.d.ts +27 -44
  41. package/dist/structures/components/QuadraticLayer.js +87 -49
  42. package/dist/structures/components/TextLayer.d.ts +16 -45
  43. package/dist/structures/components/TextLayer.js +66 -68
  44. package/dist/structures/components/index.d.ts +10 -10
  45. package/dist/structures/components/index.js +2 -2
  46. package/dist/structures/helpers/Exporter.d.ts +13 -4
  47. package/dist/structures/helpers/Exporter.js +79 -42
  48. package/dist/structures/helpers/Font.js +1 -17
  49. package/dist/structures/helpers/Gradient.js +32 -45
  50. package/dist/structures/helpers/Link.js +2 -14
  51. package/dist/structures/helpers/Pattern.js +9 -17
  52. package/dist/structures/helpers/index.d.ts +7 -7
  53. package/dist/structures/helpers/readers/JSONReader.d.ts +4 -4
  54. package/dist/structures/helpers/readers/JSONReader.js +34 -40
  55. package/dist/structures/helpers/readers/YAMLReader.js +5 -5
  56. package/dist/structures/managers/FontsManager.js +9 -18
  57. package/dist/structures/managers/LayersManager.d.ts +18 -28
  58. package/dist/structures/managers/LayersManager.js +14 -36
  59. package/dist/structures/managers/RenderManager.d.ts +1 -15
  60. package/dist/structures/managers/RenderManager.js +17 -110
  61. package/dist/structures/managers/index.d.ts +3 -5
  62. package/dist/structures/managers/index.js +0 -2
  63. package/dist/types/enum.d.ts +4 -3
  64. package/dist/types/enum.js +3 -2
  65. package/dist/types/index.d.ts +1 -1
  66. package/dist/utils/APNGEncoder.d.ts +67 -0
  67. package/dist/utils/APNGEncoder.js +205 -0
  68. package/dist/utils/DrawUtils.d.ts +9 -0
  69. package/dist/utils/DrawUtils.js +42 -0
  70. package/dist/utils/LazyUtil.js +1 -2
  71. package/dist/utils/utils.d.ts +5 -9
  72. package/dist/utils/utils.js +148 -77
  73. package/package.json +62 -59
  74. package/dist/structures/components/ClearLayer.d.ts +0 -147
  75. package/dist/structures/components/ClearLayer.js +0 -158
  76. package/dist/structures/managers/AnimationManager.d.ts +0 -120
  77. package/dist/structures/managers/AnimationManager.js +0 -99
  78. package/dist/structures/managers/PluginManager.d.ts +0 -230
  79. package/dist/structures/managers/PluginManager.js +0 -182
  80. package/dist/types/types.d.ts +0 -105
@@ -5,17 +5,14 @@ const BaseLayer_1 = require("./BaseLayer");
5
5
  const types_1 = require("../../types");
6
6
  const utils_1 = require("../../utils/utils");
7
7
  const LazyUtil_1 = require("../../utils/LazyUtil");
8
+ const DrawUtils_1 = require("../../utils/DrawUtils");
8
9
  /**
9
- * Class representing a Quadratic Layer, extending the BaseLayer class.
10
+ * Class representing a Quadratic layer, extending the BaseLayer class.
10
11
  */
11
12
  class QuadraticLayer extends BaseLayer_1.BaseLayer {
12
- /**
13
- * The properties of the Quadratic Layer.
14
- */
15
- props;
16
13
  /**
17
14
  * Constructs a new QuadraticLayer instance.
18
- * @param {IQuadraticLayerProps} [props] - The properties of the Quadratic Layer.
15
+ * @param {IQuadraticLayerProps} [props] - The properties of the Quadratic layer.
19
16
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
20
17
  */
21
18
  constructor(props, misc) {
@@ -34,13 +31,15 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
34
31
  return this;
35
32
  }
36
33
  /**
37
- * Sets the end point of the quadratic layer.
34
+ * Sets the position of the quadratic layer.
38
35
  * @param {ScaleType} [x] - The x-coordinate of the end point.
39
36
  * @param {ScaleType} [y] - The y-coordinate of the end point.
37
+ * @param {ScaleType} [endX] - The x-coordinate of the end point.
38
+ * @param {ScaleType} [endY] - The y-coordinate of the end point.
40
39
  * @returns {this} The current instance for chaining.
41
40
  */
42
- setEndPosition(x, y) {
43
- this.props.endPoint = { x, y };
41
+ setPosition(x, y, endX, endY) {
42
+ this.props.position = { x, y, endX: endX || 0, endY: endY || 0 };
44
43
  return this;
45
44
  }
46
45
  /**
@@ -51,9 +50,9 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
51
50
  */
52
51
  setColor(color) {
53
52
  if (!color)
54
- throw new LazyUtil_1.LazyError('The color of the layer must be provided');
53
+ throw new LazyUtil_1.LazyError("The color of the layer must be provided");
55
54
  if (!(0, utils_1.isColor)(color))
56
- throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
55
+ throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
57
56
  this.props.fillStyle = color;
58
57
  return this;
59
58
  }
@@ -70,8 +69,8 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
70
69
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
71
70
  this.props.stroke = {
72
71
  width,
73
- cap: cap || 'butt',
74
- join: join || 'miter',
72
+ cap: cap || "butt",
73
+ join: join || "miter",
75
74
  dash: dash || [],
76
75
  dashOffset: dashOffset || 0,
77
76
  miterLimit: miterLimit || 10,
@@ -82,97 +81,136 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
82
81
  * Calculates the bounding box of the quadratic curve.
83
82
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
84
83
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
85
- * @param {LayersManager} [manager] - The layers manager.
84
+ * @param {LayersManager} [manager] - The layer's manager.
86
85
  * @returns {Object} The bounding box details including max, min, center, width, and height.
87
86
  */
88
87
  getBoundingBox(ctx, canvas, manager) {
89
88
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
90
89
  const { xs, ys, cx, cy, xe, ye } = parcer.parseBatch({
91
- xs: { v: this.props.x },
92
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
90
+ xs: { v: this.props.position.x },
91
+ ys: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
93
92
  cx: { v: this.props.controlPoints[0].x },
94
93
  cy: { v: this.props.controlPoints[0].y, options: LazyUtil_1.defaultArg.vl(true) },
95
- xe: { v: this.props.endPoint.x },
96
- ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
94
+ xe: { v: this.props.position.endX },
95
+ ye: { v: this.props.position.endY, options: LazyUtil_1.defaultArg.vl(true) },
97
96
  });
98
- const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cx, y: cy }, { x: xe, y: ye }]);
97
+ const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([
98
+ { x: xs, y: ys },
99
+ { x: cx, y: cy },
100
+ { x: xe, y: ye },
101
+ ]);
99
102
  return { max, min, center, width, height };
100
103
  }
101
104
  /**
102
105
  * Draws the quadratic curve on the canvas.
103
106
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
104
107
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
105
- * @param {LayersManager} [manager] - The layers manager.
108
+ * @param {LayersManager} [manager] - The layer's manager.
106
109
  * @param {boolean} [debug] - Whether to enable debug logging.
107
110
  */
108
111
  async draw(ctx, canvas, manager, debug) {
109
112
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
110
113
  const { xs, ys, cx, cy, xe, ye } = parcer.parseBatch({
111
- xs: { v: this.props.x },
112
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
114
+ xs: { v: this.props.position.x },
115
+ ys: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
113
116
  cx: { v: this.props.controlPoints[0].x },
114
117
  cy: { v: this.props.controlPoints[0].y, options: LazyUtil_1.defaultArg.vl(true) },
115
- xe: { v: this.props.endPoint.x },
116
- ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
118
+ xe: { v: this.props.position.endX },
119
+ ye: { v: this.props.position.endY, options: LazyUtil_1.defaultArg.vl(true) },
120
+ });
121
+ const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([
122
+ { x: xs, y: ys },
123
+ { x: cx, y: cy },
124
+ { x: xe, y: ye },
125
+ ]);
126
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, {
127
+ debug,
128
+ layer: { width, height, x: min.x, y: min.y, align: "none" },
129
+ manager,
117
130
  });
118
- const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cx, y: cy }, { x: xe, y: ye }]);
119
- let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width, height, x: min.x, y: min.y, align: 'none' }, manager });
120
131
  if (debug)
121
- LazyUtil_1.LazyLog.log('none', `BezierLayer:`, { xs, ys, cx, cy, xe, ye, max, min, center, width, height, fillStyle });
132
+ LazyUtil_1.LazyLog.log("none", `BezierLayer:`, {
133
+ xs,
134
+ ys,
135
+ cx,
136
+ cy,
137
+ xe,
138
+ ye,
139
+ max,
140
+ min,
141
+ center,
142
+ width,
143
+ height,
144
+ fillStyle,
145
+ });
122
146
  ctx.save();
123
- (0, utils_1.transform)(ctx, this.props.transform, { x: center.x, y: center.y, width, height, type: this.type });
124
- (0, utils_1.drawShadow)(ctx, this.props.shadow);
125
- (0, utils_1.opacity)(ctx, this.props.opacity);
126
- (0, utils_1.filters)(ctx, this.props.filter);
147
+ if (this.props.transform) {
148
+ (0, utils_1.transform)(ctx, this.props.transform, {
149
+ x: center.x,
150
+ y: center.y,
151
+ width,
152
+ height,
153
+ type: this.type,
154
+ });
155
+ }
156
+ DrawUtils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
157
+ DrawUtils_1.DrawUtils.opacity(ctx, this.props.opacity);
158
+ DrawUtils_1.DrawUtils.filters(ctx, this.props.filter);
159
+ DrawUtils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
127
160
  ctx.beginPath();
128
161
  ctx.moveTo(xs, ys);
129
- ctx.strokeStyle = fillStyle;
130
- ctx.lineWidth = this.props.stroke?.width || 1;
131
- ctx.lineCap = this.props.stroke?.cap || 'butt';
132
- ctx.lineJoin = this.props.stroke?.join || 'miter';
133
- ctx.miterLimit = this.props.stroke?.miterLimit || 10;
134
- ctx.lineDashOffset = this.props.stroke?.dashOffset || 0;
135
- ctx.setLineDash(this.props.stroke?.dash || []);
136
162
  ctx.quadraticCurveTo(cx, cy, xe, ye);
137
163
  ctx.stroke();
138
164
  ctx.closePath();
139
165
  ctx.restore();
140
166
  }
141
167
  /**
142
- * Converts the Quadratic Layer to a JSON representation.
143
- * @returns {IQuadraticLayer} The JSON representation of the Quadratic Layer.
168
+ * Converts the Quadratic layer to a JSON representation.
169
+ * @returns {IQuadraticLayer} The JSON representation of the Quadratic layer.
144
170
  */
145
171
  toJSON() {
146
172
  let data = super.toJSON();
147
173
  let copy = { ...this.props };
148
- for (const key of ['x', 'y', 'endPoint.x', 'endPoint.y', 'controlPoint.x', 'controlPoint.y', 'fillStyle']) {
149
- if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
174
+ for (const key of [
175
+ "x",
176
+ "y",
177
+ "endPoint.x",
178
+ "endPoint.y",
179
+ "controlPoint.x",
180
+ "controlPoint.y",
181
+ "fillStyle",
182
+ ]) {
183
+ if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
150
184
  copy[key] = copy[key].toJSON();
151
185
  }
152
186
  }
153
187
  return { ...data, props: copy };
154
188
  }
155
189
  /**
156
- * Validates the properties of the Quadratic Layer.
190
+ * Validates the properties of the Quadratic layer.
157
191
  * @param {IQuadraticLayerProps} [data] - The properties to validate.
158
192
  * @returns {IQuadraticLayerProps} The validated properties.
159
193
  */
160
194
  validateProps(data) {
161
195
  return {
162
196
  ...super.validateProps(data),
163
- filled: data.filled || false,
164
- fillStyle: data.fillStyle || '#000000',
197
+ position: {
198
+ x: data.position?.x || 0,
199
+ y: data.position?.y || 0,
200
+ endX: data.position?.endX || 0,
201
+ endY: data.position?.endY || 0,
202
+ },
203
+ fillStyle: data.fillStyle || "#000000",
165
204
  centring: data.centring || types_1.Centring.None,
166
205
  controlPoints: data.controlPoints || [{ x: 0, y: 0 }],
167
- endPoint: data.endPoint || { x: 0, y: 0 },
168
206
  stroke: {
169
207
  width: data.stroke?.width || 1,
170
- cap: data.stroke?.cap || 'butt',
171
- join: data.stroke?.join || 'miter',
208
+ cap: data.stroke?.cap || "butt",
209
+ join: data.stroke?.join || "miter",
172
210
  dashOffset: data.stroke?.dashOffset || 0,
173
211
  dash: data.stroke?.dash || [],
174
212
  miterLimit: data.stroke?.miterLimit || 10,
175
- }
213
+ },
176
214
  };
177
215
  }
178
216
  }
@@ -1,9 +1,9 @@
1
1
  import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
- import { AnyTextAlign, AnyTextBaseline, AnyTextDirection, AnyWeight, ColorType, LayerType, LineCap, LineJoin, ScaleType, SubStringColor } from "../../types";
2
+ import { AnyTextAlign, AnyTextBaseline, AnyTextDirection, AnyWeight, ColorType, LayerType, LineCap, LineJoin, ScaleType, StrokeOptions, SubStringColor } from "../../types";
3
3
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
4
  import { LayersManager } from "../managers";
5
5
  /**
6
- * Interface representing a Text Layer.
6
+ * Interface representing a Text layer.
7
7
  */
8
8
  export interface ITextLayer extends IBaseLayer {
9
9
  /**
@@ -11,22 +11,18 @@ export interface ITextLayer extends IBaseLayer {
11
11
  */
12
12
  type: LayerType.Text;
13
13
  /**
14
- * The properties specific to the Text Layer.
14
+ * The properties specific to the Text layer.
15
15
  */
16
16
  props: ITextLayerProps;
17
17
  }
18
18
  /**
19
- * Interface representing the properties of a Text Layer.
19
+ * Interface representing the properties of a Text layer.
20
20
  */
21
21
  export interface ITextLayerProps extends IBaseLayerProps {
22
22
  /**
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
26
  /**
31
27
  * The fill style (color or pattern) of the layer.
32
28
  */
@@ -55,7 +51,7 @@ export interface ITextLayerProps extends IBaseLayerProps {
55
51
  /**
56
52
  * Configuration for multiline text.
57
53
  */
58
- multiline: {
54
+ multiline?: {
59
55
  /**
60
56
  * Whether multiline is enabled.
61
57
  */
@@ -66,15 +62,15 @@ export interface ITextLayerProps extends IBaseLayerProps {
66
62
  spacing?: number;
67
63
  };
68
64
  /**
69
- * The size of the text layer, including width and height.
65
+ * The size of the Text layer, including width and height.
70
66
  */
71
- size: {
67
+ size?: {
72
68
  /**
73
- * The width of the text layer.
69
+ * The width of the Text layer.
74
70
  */
75
71
  width: ScaleType;
76
72
  /**
77
- * The height of the text layer.
73
+ * The height of the Text layer.
78
74
  */
79
75
  height: ScaleType;
80
76
  };
@@ -101,35 +97,10 @@ export interface ITextLayerProps extends IBaseLayerProps {
101
97
  /**
102
98
  * The stroke properties of the text.
103
99
  */
104
- stroke?: {
105
- /**
106
- * The width of the stroke.
107
- */
108
- width: number;
109
- /**
110
- * The cap style of the stroke.
111
- */
112
- cap: CanvasLineCap;
113
- /**
114
- * The join style of the stroke.
115
- */
116
- join: CanvasLineJoin;
117
- /**
118
- * The dash offset of the stroke.
119
- */
120
- dashOffset: number;
121
- /**
122
- * The dash pattern of the stroke.
123
- */
124
- dash: number[];
125
- /**
126
- * The miter limit of the stroke.
127
- */
128
- miterLimit: number;
129
- };
100
+ stroke?: StrokeOptions;
130
101
  }
131
102
  /**
132
- * Class representing a Text Layer, extending the BaseLayer class.
103
+ * Class representing a Text layer, extending the BaseLayer class.
133
104
  */
134
105
  export declare class TextLayer extends BaseLayer<ITextLayerProps> {
135
106
  /**
@@ -138,7 +109,7 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
138
109
  props: ITextLayerProps;
139
110
  /**
140
111
  * Constructs a new TextLayer instance.
141
- * @param {ITextLayerProps} [props] - The properties of the Text Layer.
112
+ * @param {ITextLayerProps} [props] - The properties of the Text layer.
142
113
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
143
114
  */
144
115
  constructor(props?: ITextLayerProps, misc?: IBaseLayerMisc);
@@ -232,7 +203,7 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
232
203
  * Draws the text layer on the canvas.
233
204
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
234
205
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
235
- * @param {LayersManager} [manager] - The layers manager.
206
+ * @param {LayersManager} [manager] - The layer's manager.
236
207
  * @param {boolean} [debug] - Whether to enable debug logging.
237
208
  */
238
209
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
@@ -249,12 +220,12 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
249
220
  */
250
221
  private drawText;
251
222
  /**
252
- * Converts the Text Layer to a JSON representation.
253
- * @returns {ITextLayer} The JSON representation of the Text Layer.
223
+ * Converts the Text layer to a JSON representation.
224
+ * @returns {ITextLayer} The JSON representation of the Text layer.
254
225
  */
255
226
  toJSON(): ITextLayer;
256
227
  /**
257
- * Validates the properties of the Text Layer.
228
+ * Validates the properties of the Text layer.
258
229
  * @param {ITextLayerProps} [data] - The properties to validate.
259
230
  * @returns {ITextLayerProps} The validated properties.
260
231
  */
@@ -5,17 +5,14 @@ const BaseLayer_1 = require("./BaseLayer");
5
5
  const types_1 = require("../../types");
6
6
  const LazyUtil_1 = require("../../utils/LazyUtil");
7
7
  const utils_1 = require("../../utils/utils");
8
+ const DrawUtils_1 = require("../../utils/DrawUtils");
8
9
  /**
9
- * Class representing a Text Layer, extending the BaseLayer class.
10
+ * Class representing a Text layer, extending the BaseLayer class.
10
11
  */
11
12
  class TextLayer extends BaseLayer_1.BaseLayer {
12
- /**
13
- * The properties of the Text Layer.
14
- */
15
- props;
16
13
  /**
17
14
  * Constructs a new TextLayer instance.
18
- * @param {ITextLayerProps} [props] - The properties of the Text Layer.
15
+ * @param {ITextLayerProps} [props] - The properties of the Text layer.
19
16
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
20
17
  */
21
18
  constructor(props, misc) {
@@ -43,9 +40,9 @@ class TextLayer extends BaseLayer_1.BaseLayer {
43
40
  setFont(familyOrConfig, size, weight) {
44
41
  if (typeof familyOrConfig === "string") {
45
42
  if (!size)
46
- throw new LazyUtil_1.LazyError('The size of the font must be provided');
43
+ throw new LazyUtil_1.LazyError("The size of the font must be provided");
47
44
  if (!weight)
48
- throw new LazyUtil_1.LazyError('The weight of the font must be provided');
45
+ throw new LazyUtil_1.LazyError("The weight of the font must be provided");
49
46
  this.props.font = {
50
47
  family: familyOrConfig,
51
48
  size,
@@ -88,9 +85,9 @@ class TextLayer extends BaseLayer_1.BaseLayer {
88
85
  */
89
86
  setColor(color, ...sub) {
90
87
  if (!color)
91
- throw new LazyUtil_1.LazyError('The color of the layer must be provided');
88
+ throw new LazyUtil_1.LazyError("The color of the layer must be provided");
92
89
  if (!(0, utils_1.isColor)(color))
93
- throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
90
+ throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
94
91
  this.props.fillStyle = color;
95
92
  if (sub && sub.length > 0) {
96
93
  this.props.subStringColors = sub;
@@ -137,13 +134,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
137
134
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
138
135
  this.props.stroke = {
139
136
  width,
140
- cap: cap || 'butt',
141
- join: join || 'miter',
137
+ cap: cap || "butt",
138
+ join: join || "miter",
142
139
  dash: dash || [],
143
140
  dashOffset: dashOffset || 0,
144
141
  miterLimit: miterLimit || 10,
145
142
  };
146
- this.props.filled = false; // Ensure filled is false when stroke is set
147
143
  return this;
148
144
  }
149
145
  /**
@@ -171,9 +167,9 @@ class TextLayer extends BaseLayer_1.BaseLayer {
171
167
  * @returns {Object} The width and height of the text.
172
168
  */
173
169
  measureText(ctx, canvas) {
174
- const w = (0, utils_1.parseToNormal)(this.props.size?.width, ctx, canvas);
175
- const h = (0, utils_1.parseToNormal)(this.props.size?.height, ctx, canvas, { width: w, height: 0 }, { vertical: true });
176
- if (this.props.multiline.enabled) {
170
+ if (this.props?.multiline?.enabled) {
171
+ const w = (0, utils_1.parseToNormal)(this.props.size?.width || "vw", ctx, canvas);
172
+ const h = (0, utils_1.parseToNormal)(this.props.size?.height || 0, ctx, canvas, { width: w, height: 0 }, { vertical: true });
177
173
  return { width: w, height: h };
178
174
  }
179
175
  else {
@@ -186,25 +182,32 @@ class TextLayer extends BaseLayer_1.BaseLayer {
186
182
  * Draws the text layer on the canvas.
187
183
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
188
184
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
189
- * @param {LayersManager} [manager] - The layers manager.
185
+ * @param {LayersManager} [manager] - The layer's manager.
190
186
  * @param {boolean} [debug] - Whether to enable debug logging.
191
187
  */
192
188
  async draw(ctx, canvas, manager, debug) {
193
189
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
194
190
  const { x, y, w } = parcer.parseBatch({
195
- x: { v: this.props.x },
196
- y: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
197
- w: { v: this.props.size?.width },
191
+ x: { v: this.props.position.x },
192
+ y: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
193
+ w: { v: this.props.size?.width || "vw" },
198
194
  });
199
- const h = parcer.parse(this.props.size?.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
195
+ const h = parcer.parse(this.props.size?.height || 0, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
200
196
  if (debug)
201
- LazyUtil_1.LazyLog.log('none', `TextLayer:`, { x, y, w, h });
197
+ LazyUtil_1.LazyLog.log("none", `TextLayer:`, { x, y, w, h });
202
198
  ctx.save();
203
- (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type }, { text: this.props.text, textAlign: this.props.align, fontSize: this.props.font.size, multiline: this.props.multiline.enabled });
199
+ if (this.props.transform) {
200
+ (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type }, {
201
+ text: this.props.text,
202
+ textAlign: this.props.align,
203
+ fontSize: this.props.font.size,
204
+ multiline: this.props?.multiline?.enabled || false,
205
+ });
206
+ }
204
207
  ctx.beginPath();
205
- (0, utils_1.drawShadow)(ctx, this.props.shadow);
206
- (0, utils_1.opacity)(ctx, this.props.opacity);
207
- (0, utils_1.filters)(ctx, this.props.filter);
208
+ DrawUtils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
209
+ DrawUtils_1.DrawUtils.opacity(ctx, this.props.opacity);
210
+ DrawUtils_1.DrawUtils.filters(ctx, this.props.filter);
208
211
  ctx.textAlign = this.props.align;
209
212
  if (this.props.letterSpacing)
210
213
  ctx.letterSpacing = `${this.props.letterSpacing}px`;
@@ -214,9 +217,13 @@ class TextLayer extends BaseLayer_1.BaseLayer {
214
217
  ctx.textBaseline = this.props.baseline;
215
218
  if (this.props.direction)
216
219
  ctx.direction = this.props.direction;
217
- let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width: w, height: h, x, y, align: 'center' }, manager });
218
- if (this.props.multiline.enabled) {
219
- const words = this.props.text.split(' ');
220
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, {
221
+ debug,
222
+ layer: { width: w, height: h, x, y, align: "center" },
223
+ manager,
224
+ });
225
+ if (this.props?.multiline?.enabled) {
226
+ const words = this.props.text.split(" ");
220
227
  let lines = [];
221
228
  for (let fontSize = 1; fontSize <= this.props.font.size; fontSize++) {
222
229
  let lineHeight = fontSize * (this.props.multiline.spacing || 1.1);
@@ -224,14 +231,14 @@ class TextLayer extends BaseLayer_1.BaseLayer {
224
231
  let xm = x;
225
232
  let ym = y;
226
233
  lines = [];
227
- let line = '';
234
+ let line = "";
228
235
  let charOffset = 0; // Track position in original text
229
236
  for (let word of words) {
230
- let linePlus = line + word + ' ';
237
+ let linePlus = line + word + " ";
231
238
  if (ctx.measureText(linePlus).width > w) {
232
239
  lines.push({ text: line, x: xm, y: ym, startOffset: charOffset });
233
240
  charOffset += line.length;
234
- line = word + ' ';
241
+ line = word + " ";
235
242
  ym += lineHeight;
236
243
  }
237
244
  else {
@@ -267,19 +274,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
267
274
  drawText(props, ctx, fillStyle, text, x, y, w, textOffset = 0) {
268
275
  // If no substring colors are defined, draw normally
269
276
  if (!props.subStringColors || props.subStringColors.length === 0) {
270
- if (props.filled) {
271
- ctx.fillStyle = fillStyle;
272
- ctx.fillText(text, x, y, w);
277
+ DrawUtils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
278
+ if (props.stroke) {
279
+ ctx.strokeText(text, x, y, w);
273
280
  }
274
281
  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);
282
+ ctx.fillText(text, x, y, w);
283
283
  }
284
284
  return;
285
285
  }
@@ -288,14 +288,17 @@ class TextLayer extends BaseLayer_1.BaseLayer {
288
288
  let currentX = x;
289
289
  // Save original text alignment and set to left for manual positioning
290
290
  const originalAlign = ctx.textAlign;
291
- ctx.textAlign = 'left';
291
+ ctx.textAlign = "left";
292
292
  // Adjust starting X based on text alignment
293
293
  const alignValue = props.align;
294
- if (alignValue === types_1.TextAlign.Center || alignValue === 'center') {
294
+ if (alignValue === types_1.TextAlign.Center || alignValue === "center") {
295
295
  const totalWidth = ctx.measureText(text).width;
296
296
  currentX = x - totalWidth / 2;
297
297
  }
298
- else if (alignValue === types_1.TextAlign.Right || alignValue === 'right' || alignValue === types_1.TextAlign.End || alignValue === 'end') {
298
+ else if (alignValue === types_1.TextAlign.Right ||
299
+ alignValue === "right" ||
300
+ alignValue === types_1.TextAlign.End ||
301
+ alignValue === "end") {
299
302
  const totalWidth = ctx.measureText(text).width;
300
303
  currentX = x - totalWidth;
301
304
  }
@@ -323,16 +326,19 @@ class TextLayer extends BaseLayer_1.BaseLayer {
323
326
  text: text.substring(currentIndex, localStart),
324
327
  color: fillStyle,
325
328
  start: currentIndex,
326
- end: localStart
329
+ end: localStart,
327
330
  });
328
331
  }
329
332
  // Add colored substring
330
333
  if (localStart < localEnd) {
331
334
  segments.push({
332
335
  text: text.substring(localStart, localEnd),
333
- color: subColor.color,
336
+ color: (0, utils_1.parseFillStyle)(ctx, subColor.color, {
337
+ debug: false,
338
+ layer: { width: w, height: 0, x: 0, y: 0, align: "center" },
339
+ }),
334
340
  start: localStart,
335
- end: localEnd
341
+ end: localEnd,
336
342
  });
337
343
  currentIndex = localEnd;
338
344
  }
@@ -343,7 +349,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
343
349
  text: text.substring(currentIndex),
344
350
  color: fillStyle,
345
351
  start: currentIndex,
346
- end: textLength
352
+ end: textLength,
347
353
  });
348
354
  }
349
355
  // Draw each segment
@@ -351,19 +357,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
351
357
  if (segment.text.length === 0)
352
358
  continue;
353
359
  const segmentWidth = ctx.measureText(segment.text).width;
354
- if (props.filled) {
355
- ctx.fillStyle = segment.color;
356
- ctx.fillText(segment.text, currentX, y);
360
+ DrawUtils_1.DrawUtils.fillStyle(ctx, segment.color, this.props.stroke);
361
+ if (props.stroke) {
362
+ ctx.strokeText(segment.text, currentX, y);
357
363
  }
358
364
  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);
365
+ ctx.fillText(segment.text, currentX, y);
367
366
  }
368
367
  currentX += segmentWidth;
369
368
  }
@@ -371,29 +370,28 @@ class TextLayer extends BaseLayer_1.BaseLayer {
371
370
  ctx.textAlign = originalAlign;
372
371
  }
373
372
  /**
374
- * Converts the Text Layer to a JSON representation.
375
- * @returns {ITextLayer} The JSON representation of the Text Layer.
373
+ * Converts the Text layer to a JSON representation.
374
+ * @returns {ITextLayer} The JSON representation of the Text layer.
376
375
  */
377
376
  toJSON() {
378
377
  let data = super.toJSON();
379
378
  let copy = { ...this.props };
380
- for (const key of ['x', 'y', 'size.width', 'size.height', 'fillStyle']) {
381
- if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
379
+ for (const key of ["x", "y", "size.width", "size.height", "fillStyle"]) {
380
+ if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
382
381
  copy[key] = copy[key].toJSON();
383
382
  }
384
383
  }
385
384
  return { ...data, props: copy };
386
385
  }
387
386
  /**
388
- * Validates the properties of the Text Layer.
387
+ * Validates the properties of the Text layer.
389
388
  * @param {ITextLayerProps} [data] - The properties to validate.
390
389
  * @returns {ITextLayerProps} The validated properties.
391
390
  */
392
391
  validateProps(data) {
393
392
  return {
394
393
  ...super.validateProps(data),
395
- filled: data.filled || true,
396
- fillStyle: data.fillStyle || '#000000',
394
+ fillStyle: data.fillStyle || "#000000",
397
395
  text: data.text || "",
398
396
  font: {
399
397
  family: data.font?.family || "Arial",