@nmmty/lazycanvas 0.5.3 → 0.6.0-dev.1d5786

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 (34) hide show
  1. package/dist/helpers/Utlis.d.ts +28 -0
  2. package/dist/helpers/Utlis.js +78 -0
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +4 -1
  5. package/dist/structures/components/BaseLayer.d.ts +3 -2
  6. package/dist/structures/components/BaseLayer.js +15 -10
  7. package/dist/structures/components/BezierLayer.d.ts +6 -0
  8. package/dist/structures/components/BezierLayer.js +23 -4
  9. package/dist/structures/components/ClearLayer.d.ts +1 -0
  10. package/dist/structures/components/ClearLayer.js +14 -8
  11. package/dist/structures/components/ImageLayer.d.ts +6 -0
  12. package/dist/structures/components/ImageLayer.js +21 -5
  13. package/dist/structures/components/LineLayer.d.ts +6 -0
  14. package/dist/structures/components/LineLayer.js +27 -6
  15. package/dist/structures/components/MorphLayer.d.ts +6 -6
  16. package/dist/structures/components/MorphLayer.js +26 -15
  17. package/dist/structures/components/Path2DLayer.d.ts +6 -6
  18. package/dist/structures/components/Path2DLayer.js +24 -10
  19. package/dist/structures/components/QuadraticLayer.d.ts +6 -0
  20. package/dist/structures/components/QuadraticLayer.js +23 -4
  21. package/dist/structures/components/TextLayer.d.ts +11 -11
  22. package/dist/structures/components/TextLayer.js +36 -32
  23. package/dist/structures/helpers/Gradient.d.ts +48 -11
  24. package/dist/structures/helpers/Gradient.js +133 -8
  25. package/dist/structures/helpers/index.d.ts +1 -0
  26. package/dist/structures/helpers/index.js +1 -0
  27. package/dist/structures/helpers/readers/JSONReader.js +3 -3
  28. package/dist/structures/helpers/readers/YAMLReader.d.ts +22 -0
  29. package/dist/structures/helpers/readers/YAMLReader.js +73 -0
  30. package/dist/utils/utils.d.ts +13 -3
  31. package/dist/utils/utils.js +59 -92
  32. package/package.json +6 -4
  33. package/animation.gif +0 -0
  34. package/test.png +0 -0
@@ -73,23 +73,23 @@ export interface ITextLayerProps extends IBaseLayerProps {
73
73
  /**
74
74
  * The baseline of the text.
75
75
  */
76
- baseline: AnyTextBaseline;
76
+ baseline?: AnyTextBaseline;
77
77
  /**
78
78
  * The direction of the text.
79
79
  */
80
- direction: AnyTextDirection;
80
+ direction?: AnyTextDirection;
81
81
  /**
82
82
  * The spacing between letters.
83
83
  */
84
- letterSpacing: number;
84
+ letterSpacing?: number;
85
85
  /**
86
86
  * The spacing between words.
87
87
  */
88
- wordSpacing: number;
88
+ wordSpacing?: number;
89
89
  /**
90
90
  * The stroke properties of the text.
91
91
  */
92
- stroke: {
92
+ stroke?: {
93
93
  /**
94
94
  * The width of the stroke.
95
95
  */
@@ -194,12 +194,6 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
194
194
  * @returns {this} The current instance for chaining.
195
195
  */
196
196
  setStroke(width: number, cap?: LineCap, join?: LineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
197
- /**
198
- * Sets whether the text layer should be filled or stroked.
199
- * @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
200
- * @returns {this} The current instance for chaining.
201
- */
202
- setFilled(filled: boolean): this;
203
197
  /**
204
198
  * Sets the spacing between words in the text layer.
205
199
  * @param wordSpacing {number} - The spacing between words.
@@ -246,4 +240,10 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
246
240
  * @returns {ITextLayer} The JSON representation of the Text Layer.
247
241
  */
248
242
  toJSON(): ITextLayer;
243
+ /**
244
+ * Validates the properties of the Text Layer.
245
+ * @param props {ITextLayerProps} - The properties to validate.
246
+ * @returns {ITextLayerProps} The validated properties.
247
+ */
248
+ protected validateProps(props: ITextLayerProps): ITextLayerProps;
249
249
  }
@@ -21,25 +21,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
21
21
  constructor(props, misc) {
22
22
  super(types_1.LayerType.Text, props || {}, misc);
23
23
  this.props = props ? props : {};
24
- this.props.align = types_1.TextAlign.Left;
25
- this.props.font = {
26
- family: 'Geist',
27
- size: 16,
28
- weight: types_1.FontWeight.Regular,
29
- };
30
- this.props.fillStyle = '#ffffff';
31
- this.props.filled = true;
32
- this.props.multiline = {
33
- enabled: false,
34
- spacing: 1.1,
35
- };
36
- this.props.size = {
37
- width: 'vw',
38
- height: 0,
39
- };
40
- this.props.centring = types_1.Centring.Center;
41
- this.props.wordSpacing = 0;
42
- this.props.letterSpacing = 0;
24
+ this.props = this.validateProps(this.props);
43
25
  }
44
26
  /**
45
27
  * Sets the text of the text layer.
@@ -158,15 +140,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
158
140
  dashOffset: dashOffset || 0,
159
141
  miterLimit: miterLimit || 10,
160
142
  };
161
- return this;
162
- }
163
- /**
164
- * Sets whether the text layer should be filled or stroked.
165
- * @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
166
- * @returns {this} The current instance for chaining.
167
- */
168
- setFilled(filled) {
169
- this.props.filled = filled;
143
+ this.props.filled = false; // Ensure filled is false when stroke is set
170
144
  return this;
171
145
  }
172
146
  /**
@@ -229,12 +203,15 @@ class TextLayer extends BaseLayer_1.BaseLayer {
229
203
  (0, utils_1.opacity)(ctx, this.props.opacity);
230
204
  (0, utils_1.filters)(ctx, this.props.filter);
231
205
  ctx.textAlign = this.props.align;
232
- ctx.letterSpacing = `${this.props.letterSpacing}px`;
233
- ctx.wordSpacing = `${this.props.wordSpacing}px`;
206
+ if (this.props.letterSpacing)
207
+ ctx.letterSpacing = `${this.props.letterSpacing}px`;
208
+ if (this.props.wordSpacing)
209
+ ctx.wordSpacing = `${this.props.wordSpacing}px`;
234
210
  if (this.props.baseline)
235
211
  ctx.textBaseline = this.props.baseline;
236
212
  if (this.props.direction)
237
213
  ctx.direction = this.props.direction;
214
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width: w, height: h, x, y, align: 'none' }, manager });
238
215
  if (this.props.multiline.enabled) {
239
216
  const words = this.props.text.split(' ');
240
217
  let lines = [];
@@ -261,12 +238,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
261
238
  break;
262
239
  }
263
240
  for (let line of lines) {
264
- this.drawText(this.props, ctx, await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle), line.text, line.x, line.y, w);
241
+ this.drawText(this.props, ctx, fillStyle, line.text, line.x, line.y, w);
265
242
  }
266
243
  }
267
244
  else {
268
245
  ctx.font = `${this.props.font.weight} ${this.props.font.size}px ${this.props.font.family}`;
269
- this.drawText(this.props, ctx, await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle), this.props.text, x, y, w);
246
+ this.drawText(this.props, ctx, fillStyle, this.props.text, x, y, w);
270
247
  }
271
248
  ctx.closePath();
272
249
  ctx.restore();
@@ -311,5 +288,32 @@ class TextLayer extends BaseLayer_1.BaseLayer {
311
288
  }
312
289
  return { ...data, props: copy };
313
290
  }
291
+ /**
292
+ * Validates the properties of the Text Layer.
293
+ * @param props {ITextLayerProps} - The properties to validate.
294
+ * @returns {ITextLayerProps} The validated properties.
295
+ */
296
+ validateProps(props) {
297
+ return {
298
+ ...super.validateProps(props),
299
+ text: props.text || "",
300
+ font: {
301
+ family: props.font?.family || "Arial",
302
+ size: props.font?.size || 16,
303
+ weight: props.font?.weight || types_1.FontWeight.Regular,
304
+ },
305
+ multiline: {
306
+ enabled: props.multiline?.enabled || false,
307
+ spacing: props.multiline?.spacing || 1.1,
308
+ },
309
+ size: {
310
+ width: props.size?.width || "vw",
311
+ height: props.size?.height || 0,
312
+ },
313
+ align: props.align || types_1.TextAlign.Left,
314
+ fillStyle: props.fillStyle || "#000000",
315
+ filled: props.filled !== undefined ? props.filled : true,
316
+ };
317
+ }
314
318
  }
315
319
  exports.TextLayer = TextLayer;
@@ -1,5 +1,6 @@
1
- import { AnyGradientType, FillType, StringColorType } from "../../types";
1
+ import { AnyCentring, AnyGradientType, FillType, StringColorType, ScaleType } from "../../types";
2
2
  import { SKRSContext2D } from "@napi-rs/canvas";
3
+ import { LayersManager } from "../managers/LayersManager";
3
4
  /**
4
5
  * Interface representing a gradient.
5
6
  */
@@ -20,6 +21,10 @@ export interface IGradient {
20
21
  * The color stops for the gradient.
21
22
  */
22
23
  stops: Array<GradientColorStop>;
24
+ /**
25
+ * The angle of the gradient (optional, used for linear gradients).
26
+ */
27
+ angle?: number;
23
28
  }
24
29
  /**
25
30
  * Interface representing a color stop in a gradient.
@@ -41,19 +46,15 @@ export interface GradientPoint {
41
46
  /**
42
47
  * The x-coordinate of the point.
43
48
  */
44
- x: number;
49
+ x: ScaleType;
45
50
  /**
46
51
  * The y-coordinate of the point.
47
52
  */
48
- y: number;
53
+ y: ScaleType;
49
54
  /**
50
55
  * The radius of the point (optional, used for radial gradients).
51
56
  */
52
57
  r?: number;
53
- /**
54
- * The starting angle of the point (optional, used for conic gradients).
55
- */
56
- startAngle?: number;
57
58
  }
58
59
  /**
59
60
  * Class representing a gradient with properties and methods to manipulate it.
@@ -75,6 +76,10 @@ export declare class Gradient implements IGradient {
75
76
  * The color stops for the gradient.
76
77
  */
77
78
  stops: Array<GradientColorStop>;
79
+ /**
80
+ * The angle of the gradient (optional, used for linear gradients).
81
+ */
82
+ angle?: number;
78
83
  /**
79
84
  * Constructs a new Gradient instance.
80
85
  * @param opts {Object} - Optional properties for the gradient.
@@ -95,6 +100,18 @@ export declare class Gradient implements IGradient {
95
100
  * @returns {this} The current instance for chaining.
96
101
  */
97
102
  addPoints(...points: GradientPoint[]): this;
103
+ /**
104
+ * Sets the points of the gradient.
105
+ * @param points {GradientPoint[]} - The points to set for the gradient.
106
+ * @returns {this} The current instance for chaining.
107
+ */
108
+ setPoints(...points: GradientPoint[]): this;
109
+ /**
110
+ * Removes points from the gradient by their indexes.
111
+ * @param indexes {number[]} - The indexes of the points to remove.
112
+ * @returns {this} The current instance for chaining.
113
+ */
114
+ removePoints(...indexes: number[]): this;
98
115
  /**
99
116
  * Adds color stops to the gradient.
100
117
  * @param stops {GradientColorStop[]} - The color stops to add to the gradient.
@@ -102,14 +119,34 @@ export declare class Gradient implements IGradient {
102
119
  */
103
120
  addStops(...stops: GradientColorStop[]): this;
104
121
  /**
105
- * Draws the gradient on a canvas context.
106
- * @param ctx {SKRSContext2D} - The canvas rendering context.
107
- * @returns {CanvasGradient} The created gradient.
122
+ * Sets the color stops of the gradient.
123
+ * @param stops {GradientColorStop[]} - The color stops to set for the gradient.
124
+ * @returns {this} The current instance for chaining.
125
+ */
126
+ setStops(...stops: GradientColorStop[]): this;
127
+ /**
128
+ * Removes color stops from the gradient by their indexes.
129
+ * @param indexes {number[]} - The indexes of the color stops to remove.
130
+ * @returns {this} The current instance for chaining.
108
131
  */
109
- draw(ctx: SKRSContext2D): CanvasGradient;
132
+ removeStops(...indexes: number[]): this;
133
+ setAngle(angle: number): this;
134
+ draw(ctx: SKRSContext2D, opts?: {
135
+ debug?: boolean;
136
+ layer?: {
137
+ width: number;
138
+ height: number;
139
+ x: number;
140
+ y: number;
141
+ align: AnyCentring;
142
+ };
143
+ manager?: LayersManager;
144
+ }): CanvasGradient;
110
145
  /**
111
146
  * Converts the gradient to a JSON representation.
112
147
  * @returns {IGradient} The JSON representation of the gradient.
113
148
  */
114
149
  toJSON(): IGradient;
150
+ private getLinearGradientPoints;
151
+ private getPosition;
115
152
  }
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Gradient = void 0;
4
4
  const types_1 = require("../../types");
5
+ const LazyUtil_1 = require("../../utils/LazyUtil");
6
+ const utils_1 = require("../../utils/utils");
5
7
  /**
6
8
  * Class representing a gradient with properties and methods to manipulate it.
7
9
  */
@@ -22,6 +24,10 @@ class Gradient {
22
24
  * The color stops for the gradient.
23
25
  */
24
26
  stops;
27
+ /**
28
+ * The angle of the gradient (optional, used for linear gradients).
29
+ */
30
+ angle;
25
31
  /**
26
32
  * Constructs a new Gradient instance.
27
33
  * @param opts {Object} - Optional properties for the gradient.
@@ -31,6 +37,7 @@ class Gradient {
31
37
  this.type = opts?.props?.type || types_1.GradientType.Linear;
32
38
  this.points = opts?.props?.points || [];
33
39
  this.stops = opts?.props?.stops || [];
40
+ this.angle = opts?.props?.angle || 0;
34
41
  }
35
42
  /**
36
43
  * Sets the type of the gradient.
@@ -50,6 +57,24 @@ class Gradient {
50
57
  this.points.push(...points);
51
58
  return this;
52
59
  }
60
+ /**
61
+ * Sets the points of the gradient.
62
+ * @param points {GradientPoint[]} - The points to set for the gradient.
63
+ * @returns {this} The current instance for chaining.
64
+ */
65
+ setPoints(...points) {
66
+ this.points = points;
67
+ return this;
68
+ }
69
+ /**
70
+ * Removes points from the gradient by their indexes.
71
+ * @param indexes {number[]} - The indexes of the points to remove.
72
+ * @returns {this} The current instance for chaining.
73
+ */
74
+ removePoints(...indexes) {
75
+ this.points = this.points.filter((_, index) => !indexes.includes(index));
76
+ return this;
77
+ }
53
78
  /**
54
79
  * Adds color stops to the gradient.
55
80
  * @param stops {GradientColorStop[]} - The color stops to add to the gradient.
@@ -60,28 +85,74 @@ class Gradient {
60
85
  return this;
61
86
  }
62
87
  /**
63
- * Draws the gradient on a canvas context.
64
- * @param ctx {SKRSContext2D} - The canvas rendering context.
65
- * @returns {CanvasGradient} The created gradient.
88
+ * Sets the color stops of the gradient.
89
+ * @param stops {GradientColorStop[]} - The color stops to set for the gradient.
90
+ * @returns {this} The current instance for chaining.
91
+ */
92
+ setStops(...stops) {
93
+ this.stops = stops;
94
+ return this;
95
+ }
96
+ /**
97
+ * Removes color stops from the gradient by their indexes.
98
+ * @param indexes {number[]} - The indexes of the color stops to remove.
99
+ * @returns {this} The current instance for chaining.
66
100
  */
67
- draw(ctx) {
101
+ removeStops(...indexes) {
102
+ this.stops = this.stops.filter((_, index) => !indexes.includes(index));
103
+ return this;
104
+ }
105
+ setAngle(angle) {
106
+ this.angle = angle;
107
+ return this;
108
+ }
109
+ draw(ctx, opts = { debug: false }) {
68
110
  let gradientData = this.toJSON();
69
111
  let gradient;
112
+ if (opts.debug)
113
+ LazyUtil_1.LazyLog.log('none', `Gradient:`, gradientData);
114
+ const parse = (0, utils_1.parser)(ctx, ctx.canvas, opts.manager);
115
+ const { x0, y0, x1, y1 } = parse.parseBatch({
116
+ x0: { v: gradientData.points[0]?.x || 0 },
117
+ y0: { v: gradientData.points[0]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) },
118
+ x1: { v: gradientData.points[1]?.x || 0 },
119
+ y1: { v: gradientData.points[1]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) }
120
+ });
121
+ if (opts.debug)
122
+ LazyUtil_1.LazyLog.log('none', `Gradient points:`, { x0, y0, x1, y1 });
70
123
  switch (gradientData.type) {
71
124
  case types_1.GradientType.Linear:
72
125
  case "linear":
73
- gradient = ctx.createLinearGradient(gradientData.points[0].x, gradientData.points[0].y, gradientData.points[1].x, gradientData.points[1].y);
126
+ if (gradientData.type === "linear" && (gradientData.angle || gradientData.angle === 0) && opts.layer) {
127
+ const { width, height, x, y, align } = opts.layer;
128
+ const cx = this.getPosition(x, width, align, 'x');
129
+ const cy = this.getPosition(y, height, align, 'y');
130
+ const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
131
+ gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
132
+ }
133
+ else {
134
+ gradient = ctx.createLinearGradient(x0, y0, x1 || x0, y1 || y0);
135
+ }
74
136
  break;
75
137
  case types_1.GradientType.Radial:
76
138
  case "radial":
77
- gradient = ctx.createRadialGradient(gradientData.points[0].x, gradientData.points[0].y, gradientData.points[0].r || 0, gradientData.points[1].x || gradientData.points[0].x, gradientData.points[1].y || gradientData.points[0].y, gradientData.points[1].r || 0);
139
+ gradient = ctx.createRadialGradient(x0, y0, gradientData.points[0].r || 0, x1 || x0, y1 || y0, gradientData.points[1].r || 0);
78
140
  break;
79
141
  case types_1.GradientType.Conic:
80
142
  case "conic":
81
- gradient = ctx.createConicGradient(gradientData.points[0].startAngle || 0, gradientData.points[0].x, gradientData.points[0].y);
143
+ gradient = ctx.createConicGradient((gradientData.angle || 0) * (Math.PI / 180), x0, y0);
82
144
  break;
83
145
  default:
84
- gradient = ctx.createLinearGradient(gradientData.points[0].x, gradientData.points[0].y, gradientData.points[1].x, gradientData.points[1].y);
146
+ if ((gradientData.angle || gradientData.angle === 0) && opts.layer) {
147
+ const { width, height, x, y, align } = opts.layer;
148
+ const cx = this.getPosition(x, width, align, 'x');
149
+ const cy = this.getPosition(y, height, align, 'y');
150
+ const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
151
+ gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
152
+ }
153
+ else {
154
+ gradient = ctx.createLinearGradient(x0, y0, x1 || x0, y1 || y0);
155
+ }
85
156
  break;
86
157
  }
87
158
  for (let stop of gradientData.stops) {
@@ -99,7 +170,61 @@ class Gradient {
99
170
  type: this.type,
100
171
  points: this.points,
101
172
  stops: this.stops,
173
+ angle: this.angle
102
174
  };
103
175
  }
176
+ getLinearGradientPoints(cx, cy, w, h, angleInDegrees) {
177
+ const angle = angleInDegrees * (Math.PI / 180);
178
+ const x1 = cx;
179
+ const y1 = cy - h / 2;
180
+ const x2 = cx;
181
+ const y2 = cy + h / 2;
182
+ const cos = Math.cos(angle);
183
+ const sin = Math.sin(angle);
184
+ const x1r = cx + (x1 - cx) * cos - (y1 - cy) * sin;
185
+ const y1r = cy + (x1 - cx) * sin + (y1 - cy) * cos;
186
+ const x2r = cx + (x2 - cx) * cos - (y2 - cy) * sin;
187
+ const y2r = cy + (x2 - cx) * sin + (y2 - cy) * cos;
188
+ return [
189
+ { x: x1r, y: y1r },
190
+ { x: x2r, y: y2r }
191
+ ];
192
+ }
193
+ getPosition(pos, side, align, type = 'x') {
194
+ switch (align) {
195
+ case types_1.Centring.StartTop:
196
+ case "start-top":
197
+ return type === 'x' ? pos + (side / 2) : pos + (side / 2);
198
+ case types_1.Centring.Start:
199
+ case "start":
200
+ return type === 'x' ? pos + (side / 2) : pos;
201
+ case types_1.Centring.StartBottom:
202
+ case "start-bottom":
203
+ return type === 'x' ? pos + (side / 2) : pos - (side / 2);
204
+ case types_1.Centring.CenterTop:
205
+ case "center-top":
206
+ return type === 'x' ? pos : pos - (side / 2);
207
+ case types_1.Centring.Center:
208
+ case "center":
209
+ return type === 'x' ? pos : pos;
210
+ case types_1.Centring.CenterBottom:
211
+ case "center-bottom":
212
+ return type === 'x' ? pos : pos - (side / 2);
213
+ case types_1.Centring.EndTop:
214
+ case "end-top":
215
+ return type === 'x' ? pos - (side / 2) : pos + (side / 2);
216
+ case types_1.Centring.End:
217
+ case "end":
218
+ return type === 'x' ? pos - (side / 2) : pos;
219
+ case types_1.Centring.EndBottom:
220
+ case "end-bottom":
221
+ return type === 'x' ? pos - (side / 2) : pos - (side / 2);
222
+ case types_1.Centring.None:
223
+ case "none":
224
+ return type === 'x' ? pos + (side / 2) : pos + (side / 2);
225
+ default:
226
+ throw new LazyUtil_1.LazyError(`Invalid centring type: ${align}`);
227
+ }
228
+ }
104
229
  }
105
230
  exports.Gradient = Gradient;
@@ -4,3 +4,4 @@ export * from "./Gradient";
4
4
  export * from "./Link";
5
5
  export * from "./Pattern";
6
6
  export * from "./readers/JSONReader";
7
+ export * from "./readers/YAMLReader";
@@ -20,3 +20,4 @@ __exportStar(require("./Gradient"), exports);
20
20
  __exportStar(require("./Link"), exports);
21
21
  __exportStar(require("./Pattern"), exports);
22
22
  __exportStar(require("./readers/JSONReader"), exports);
23
+ __exportStar(require("./readers/YAMLReader"), exports);
@@ -58,7 +58,7 @@ class JSONReader {
58
58
  }
59
59
  if (opts?.debug)
60
60
  LazyUtil_1.LazyLog.log("info", "Reading JSON...\nOptions:", data.options, "\nAnimation:", data.animation, "\nLayers Number:", data.layers.length, "\nLayers:", data.layers);
61
- const layers = JSONReader.layersParse(data.layers);
61
+ const layers = JSONReader.layersParse(data.layers, opts);
62
62
  const canvas = new LazyCanvas_1.LazyCanvas({ settings: data, debug: opts?.debug })
63
63
  .create(data.options.width, data.options.height);
64
64
  canvas.manager.layers.add(...layers);
@@ -99,7 +99,7 @@ class JSONReader {
99
99
  visible: layer.visible,
100
100
  };
101
101
  if (layer.type === types_1.LayerType.Group) {
102
- return new components_1.Group(misc).add(...layer.layers.map((l) => this.layerParse(l)));
102
+ return new components_1.Group(misc).add(...layer.layers.map((l) => this.layerParse(l, { id: l.id, zIndex: l.zIndex, visible: l.visible })));
103
103
  }
104
104
  else {
105
105
  return this.layerParse(layer, misc);
@@ -153,7 +153,6 @@ class JSONReader {
153
153
  case 'gradient':
154
154
  return new __1.Gradient({ props: layer.props.fillStyle });
155
155
  case 'pattern':
156
- console.log('Pattern:', layer.props.fillStyle);
157
156
  return new __1.Pattern()
158
157
  .setType(layer.props.fillStyle.type)
159
158
  .setSrc(typeof layer.props.fillStyle.src === 'string' ? layer.props.fillStyle.src : this.read(layer.props.fillStyle.src));
@@ -162,6 +161,7 @@ class JSONReader {
162
161
  }
163
162
  }
164
163
  else if ('fillStyle' in layer.props) {
164
+ console.log(layer.type, layer);
165
165
  return layer.props.fillStyle || '#000000';
166
166
  }
167
167
  else {
@@ -0,0 +1,22 @@
1
+ import { LazyCanvas } from "../../LazyCanvas";
2
+ export declare class YAMLReader {
3
+ /**
4
+ * Reads a YAML string and converts it to a LazyCanvas object.
5
+ * @param data - The YAML string to read.
6
+ * @param opts - Optional parameters for debugging.
7
+ * @returns A Promise that resolves to a LazyCanvas object.
8
+ */
9
+ static read(data: string, opts?: {
10
+ debug?: boolean;
11
+ }): LazyCanvas;
12
+ /**
13
+ * Reads a YAML file and converts it to a LazyCanvas object.
14
+ * @param filePath - The path to the YAML file.
15
+ * @param opts - Optional parameters for debugging.
16
+ * @returns A Promise that resolves to a LazyCanvas object.
17
+ * @throws LazyError if the file does not exist or has an invalid extension.
18
+ */
19
+ static readFile(filePath: string, opts?: {
20
+ debug?: boolean;
21
+ }): LazyCanvas;
22
+ }
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.YAMLReader = void 0;
27
+ const JSONReader_1 = require("./JSONReader");
28
+ const _yaml = __importStar(require("js-yaml"));
29
+ const fs = __importStar(require("fs"));
30
+ const LazyUtil_1 = require("../../../utils/LazyUtil");
31
+ const path = __importStar(require("path"));
32
+ class YAMLReader {
33
+ /**
34
+ * Reads a YAML string and converts it to a LazyCanvas object.
35
+ * @param data - The YAML string to read.
36
+ * @param opts - Optional parameters for debugging.
37
+ * @returns A Promise that resolves to a LazyCanvas object.
38
+ */
39
+ static read(data, opts) {
40
+ const yamlContent = _yaml.load(data);
41
+ if (opts?.debug) {
42
+ LazyUtil_1.LazyLog.log('info', 'YAML content loaded:', yamlContent);
43
+ }
44
+ if (typeof yamlContent === 'object' && yamlContent !== null) {
45
+ return JSONReader_1.JSONReader.read(yamlContent, opts);
46
+ }
47
+ else {
48
+ throw new LazyUtil_1.LazyError("Invalid YAML content: Expected an object.");
49
+ }
50
+ }
51
+ /**
52
+ * Reads a YAML file and converts it to a LazyCanvas object.
53
+ * @param filePath - The path to the YAML file.
54
+ * @param opts - Optional parameters for debugging.
55
+ * @returns A Promise that resolves to a LazyCanvas object.
56
+ * @throws LazyError if the file does not exist or has an invalid extension.
57
+ */
58
+ static readFile(filePath, opts) {
59
+ if (!fs.existsSync(filePath)) {
60
+ throw new LazyUtil_1.LazyError(`File not found: ${filePath}`);
61
+ }
62
+ const ext = path.extname(filePath).toLowerCase();
63
+ if (ext !== '.yaml' && ext !== '.yml') {
64
+ throw new LazyUtil_1.LazyError(`Invalid file extension: ${ext}. Expected .yaml or .yml.`);
65
+ }
66
+ const data = fs.readFileSync(filePath, 'utf8');
67
+ if (opts?.debug) {
68
+ LazyUtil_1.LazyLog.log('info', `Reading YAML file: ${filePath}`);
69
+ }
70
+ return this.read(data, opts);
71
+ }
72
+ }
73
+ exports.YAMLReader = YAMLReader;
@@ -33,9 +33,19 @@ export declare function parser(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, m
33
33
  }>): Record<string, number>;
34
34
  };
35
35
  export declare function drawShadow(ctx: SKRSContext2D, shadow: any): void;
36
- export declare function opacity(ctx: SKRSContext2D, opacity: number): void;
37
- export declare function filters(ctx: SKRSContext2D, filters: string): void;
38
- export declare function parseFillStyle(ctx: SKRSContext2D, color: ColorType): string | CanvasGradient | Promise<CanvasPattern>;
36
+ export declare function opacity(ctx: SKRSContext2D, opacity?: number): void;
37
+ export declare function filters(ctx: SKRSContext2D, filters: string | null | undefined): void;
38
+ export declare function parseFillStyle(ctx: SKRSContext2D, color: ColorType, opts: {
39
+ debug?: boolean;
40
+ layer?: {
41
+ width: number;
42
+ height: number;
43
+ x: number;
44
+ y: number;
45
+ align: AnyCentring;
46
+ };
47
+ manager?: LayersManager;
48
+ }): string | Promise<CanvasPattern> | CanvasGradient;
39
49
  export declare function transform(ctx: SKRSContext2D, transform: Transform, layer?: {
40
50
  width: number;
41
51
  height: number;