@nmmty/lazycanvas 0.6.5 → 1.0.0-dev.4

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 +16 -37
  27. package/dist/structures/components/BezierLayer.js +83 -46
  28. package/dist/structures/components/{Group.d.ts → Div.d.ts} +22 -16
  29. package/dist/structures/components/{Group.js → Div.js} +38 -39
  30. package/dist/structures/components/ImageLayer.d.ts +1 -1
  31. package/dist/structures/components/ImageLayer.js +27 -26
  32. package/dist/structures/components/LineLayer.d.ts +11 -37
  33. package/dist/structures/components/LineLayer.js +42 -42
  34. package/dist/structures/components/MorphLayer.d.ts +3 -32
  35. package/dist/structures/components/MorphLayer.js +35 -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 +2 -31
  39. package/dist/structures/components/PolygonLayer.js +35 -38
  40. package/dist/structures/components/QuadraticLayer.d.ts +16 -33
  41. package/dist/structures/components/QuadraticLayer.js +80 -42
  42. package/dist/structures/components/TextLayer.d.ts +4 -33
  43. package/dist/structures/components/TextLayer.js +60 -62
  44. package/dist/structures/components/index.d.ts +10 -11
  45. package/dist/structures/components/index.js +1 -2
  46. package/dist/structures/helpers/Exporter.d.ts +13 -4
  47. package/dist/structures/helpers/Exporter.js +80 -43
  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 -42
  55. package/dist/structures/helpers/readers/YAMLReader.js +7 -7
  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 +1 -2
  64. package/dist/types/enum.js +1 -2
  65. package/dist/types/index.d.ts +1 -1
  66. package/dist/types/types.d.ts +232 -107
  67. package/dist/utils/APNGEncoder.d.ts +67 -0
  68. package/dist/utils/APNGEncoder.js +205 -0
  69. package/dist/utils/DrawUtils.d.ts +9 -0
  70. package/dist/utils/DrawUtils.js +42 -0
  71. package/dist/utils/LazyUtil.js +1 -2
  72. package/dist/utils/utils.d.ts +4 -7
  73. package/dist/utils/utils.js +136 -77
  74. package/package.json +60 -59
  75. package/dist/structures/components/ClearLayer.d.ts +0 -147
  76. package/dist/structures/components/ClearLayer.js +0 -158
  77. package/dist/structures/managers/AnimationManager.d.ts +0 -120
  78. package/dist/structures/managers/AnimationManager.js +0 -99
  79. package/dist/structures/managers/PluginManager.d.ts +0 -230
  80. package/dist/structures/managers/PluginManager.js +0 -182
@@ -8,32 +8,16 @@ const utils_1 = require("../../utils/utils");
8
8
  * Class representing a gradient with properties and methods to manipulate it.
9
9
  */
10
10
  class Gradient {
11
- /**
12
- * The type of fill, which is always `Gradient`.
13
- */
14
- fillType = types_1.FillType.Gradient;
15
- /**
16
- * The type of gradient (e.g., linear, radial, conic).
17
- */
18
- type;
19
- /**
20
- * The points defining the gradient.
21
- */
22
- points;
23
- /**
24
- * The color stops for the gradient.
25
- */
26
- stops;
27
- /**
28
- * The angle of the gradient (optional, used for linear gradients).
29
- */
30
- angle;
31
11
  /**
32
12
  * Constructs a new Gradient instance.
33
13
  * @param {Object} [opts] - Optional properties for the gradient.
34
14
  * @param {IGradient} [opts.props] - The gradient properties.
35
15
  */
36
16
  constructor(opts) {
17
+ /**
18
+ * The type of fill, which is always `Gradient`.
19
+ */
20
+ this.fillType = types_1.FillType.Gradient;
37
21
  this.type = opts?.props?.type || types_1.GradientType.Linear;
38
22
  this.points = opts?.props?.points || [];
39
23
  this.stops = opts?.props?.stops || [];
@@ -115,33 +99,36 @@ class Gradient {
115
99
  let gradientData = this.toJSON();
116
100
  let gradient;
117
101
  if (opts.debug)
118
- LazyUtil_1.LazyLog.log('none', `Gradient:`, gradientData);
102
+ LazyUtil_1.LazyLog.log("none", `Gradient:`, gradientData);
119
103
  const parse = (0, utils_1.parser)(ctx, ctx.canvas, opts.manager);
120
104
  const { x0, y0, x1, y1 } = parse.parseBatch({
121
105
  x0: { v: gradientData.points[0]?.x || 0 },
122
106
  y0: { v: gradientData.points[0]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) },
123
107
  x1: { v: gradientData.points[1]?.x || 0 },
124
- y1: { v: gradientData.points[1]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) }
108
+ y1: { v: gradientData.points[1]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) },
125
109
  });
126
110
  if (opts.debug)
127
- LazyUtil_1.LazyLog.log('none', `Gradient points:`, { x0, y0, x1, y1 });
111
+ LazyUtil_1.LazyLog.log("none", `Gradient points:`, { x0, y0, x1, y1 });
128
112
  switch (gradientData.type) {
129
113
  case types_1.GradientType.Linear:
130
114
  case "linear":
131
- if (gradientData.type === "linear" && (gradientData.angle || gradientData.angle === 0) && opts.layer && gradientData.points.length < 2) {
115
+ if (gradientData.type === "linear" &&
116
+ (gradientData.angle || gradientData.angle === 0) &&
117
+ opts.layer &&
118
+ gradientData.points.length < 2) {
132
119
  const { width, height, x, y, align } = opts.layer;
133
- const cx = this.getPosition(x, width, align, 'x');
134
- const cy = this.getPosition(y, height, align, 'y');
120
+ const cx = this.getPosition(x, width, align, "x");
121
+ const cy = this.getPosition(y, height, align, "y");
135
122
  if (opts.debug)
136
- LazyUtil_1.LazyLog.log('none', `Center for angle calculation:`, { cx, cy });
123
+ LazyUtil_1.LazyLog.log("none", `Center for angle calculation:`, { cx, cy });
137
124
  const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
138
125
  if (opts.debug)
139
- LazyUtil_1.LazyLog.log('none', `Linear Gradient Points from angle:`, { p1, p2 });
126
+ LazyUtil_1.LazyLog.log("none", `Linear Gradient Points from angle:`, { p1, p2 });
140
127
  gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
141
128
  }
142
129
  else {
143
130
  if (opts.debug)
144
- LazyUtil_1.LazyLog.log('none', `Linear Gradient created from points.`);
131
+ LazyUtil_1.LazyLog.log("none", `Linear Gradient created from points.`);
145
132
  gradient = ctx.createLinearGradient(x0, y0, x1 || x0, y1 || y0);
146
133
  }
147
134
  break;
@@ -156,8 +143,8 @@ class Gradient {
156
143
  default:
157
144
  if ((gradientData.angle || gradientData.angle === 0) && opts.layer) {
158
145
  const { width, height, x, y, align } = opts.layer;
159
- const cx = this.getPosition(x, width, align, 'x');
160
- const cy = this.getPosition(y, height, align, 'y');
146
+ const cx = this.getPosition(x, width, align, "x");
147
+ const cy = this.getPosition(y, height, align, "y");
161
148
  const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
162
149
  gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
163
150
  }
@@ -167,7 +154,7 @@ class Gradient {
167
154
  break;
168
155
  }
169
156
  for (let stop of gradientData.stops) {
170
- gradient.addColorStop(stop.offset, stop.color);
157
+ gradient.addColorStop(stop.offset, (0, utils_1.parseFillStyle)(ctx, stop.color, opts));
171
158
  }
172
159
  return gradient;
173
160
  }
@@ -181,7 +168,7 @@ class Gradient {
181
168
  type: this.type,
182
169
  points: this.points,
183
170
  stops: this.stops,
184
- angle: this.angle
171
+ angle: this.angle,
185
172
  };
186
173
  }
187
174
  getLinearGradientPoints(cx, cy, w, h, angleInDegrees) {
@@ -198,41 +185,41 @@ class Gradient {
198
185
  const y2r = cy + (x2 - cx) * sin + (y2 - cy) * cos;
199
186
  return [
200
187
  { x: x1r, y: y1r },
201
- { x: x2r, y: y2r }
188
+ { x: x2r, y: y2r },
202
189
  ];
203
190
  }
204
- getPosition(pos, side, align, type = 'x') {
191
+ getPosition(pos, side, align, type = "x") {
205
192
  switch (align) {
206
193
  case types_1.Centring.StartTop:
207
194
  case "start-top":
208
- return type === 'x' ? pos + (side / 2) : pos + (side / 2);
195
+ return type === "x" ? pos + side / 2 : pos + side / 2;
209
196
  case types_1.Centring.Start:
210
197
  case "start":
211
- return type === 'x' ? pos + (side / 2) : pos;
198
+ return type === "x" ? pos + side / 2 : pos;
212
199
  case types_1.Centring.StartBottom:
213
200
  case "start-bottom":
214
- return type === 'x' ? pos + (side / 2) : pos - (side / 2);
201
+ return type === "x" ? pos + side / 2 : pos - side / 2;
215
202
  case types_1.Centring.CenterTop:
216
203
  case "center-top":
217
- return type === 'x' ? pos : pos - (side / 2);
204
+ return type === "x" ? pos : pos - side / 2;
218
205
  case types_1.Centring.Center:
219
206
  case "center":
220
- return type === 'x' ? pos : pos;
207
+ return type === "x" ? pos : pos;
221
208
  case types_1.Centring.CenterBottom:
222
209
  case "center-bottom":
223
- return type === 'x' ? pos : pos - (side / 2);
210
+ return type === "x" ? pos : pos - side / 2;
224
211
  case types_1.Centring.EndTop:
225
212
  case "end-top":
226
- return type === 'x' ? pos - (side / 2) : pos + (side / 2);
213
+ return type === "x" ? pos - side / 2 : pos + side / 2;
227
214
  case types_1.Centring.End:
228
215
  case "end":
229
- return type === 'x' ? pos - (side / 2) : pos;
216
+ return type === "x" ? pos - side / 2 : pos;
230
217
  case types_1.Centring.EndBottom:
231
218
  case "end-bottom":
232
- return type === 'x' ? pos - (side / 2) : pos - (side / 2);
219
+ return type === "x" ? pos - side / 2 : pos - side / 2;
233
220
  case types_1.Centring.None:
234
221
  case "none":
235
- return type === 'x' ? pos + (side / 2) : pos + (side / 2);
222
+ return type === "x" ? pos + side / 2 : pos + side / 2;
236
223
  default:
237
224
  throw new LazyUtil_1.LazyError(`Invalid centring type: ${align}`);
238
225
  }
@@ -6,25 +6,13 @@ const types_1 = require("../../types");
6
6
  * Class representing a link between layers with properties and methods to manipulate it.
7
7
  */
8
8
  class Link {
9
- /**
10
- * The source layers ID.
11
- */
12
- source;
13
- /**
14
- * The type of the link (e.g., width, height, etc.).
15
- */
16
- type;
17
- /**
18
- * The additional spacing applied to the link.
19
- */
20
- additionalSpacing;
21
9
  /**
22
10
  * Constructs a new Link instance.
23
11
  * @param {Object} [opts] - Optional properties for the link.
24
12
  * @param {ILink} [opts.props] - The link properties.
25
13
  */
26
14
  constructor(opts) {
27
- this.source = opts?.props?.source || '';
15
+ this.source = opts?.props?.source || "";
28
16
  this.type = opts?.props?.type || types_1.LinkType.Width;
29
17
  this.additionalSpacing = opts?.props?.additionalSpacing || 0;
30
18
  }
@@ -63,7 +51,7 @@ class Link {
63
51
  return {
64
52
  source: this.source,
65
53
  type: this.type,
66
- additionalSpacing: this.additionalSpacing
54
+ additionalSpacing: this.additionalSpacing,
67
55
  };
68
56
  }
69
57
  }
@@ -10,26 +10,18 @@ const LazyUtil_1 = require("../../utils/LazyUtil");
10
10
  * Class representing a pattern with properties and methods to manipulate it.
11
11
  */
12
12
  class Pattern {
13
- /**
14
- * The type of fill, which is always `Pattern`.
15
- */
16
- fillType = types_1.FillType.Pattern;
17
- /**
18
- * The type of the pattern (e.g., repeat, no-repeat, etc.).
19
- */
20
- type;
21
- /**
22
- * The source of the pattern, which can be a string (URL or path) or a LazyCanvas instance.
23
- */
24
- src;
25
13
  /**
26
14
  * Constructs a new Pattern instance.
27
15
  * @param {Object} [opts] - Optional properties for the pattern.
28
16
  * @param {IPattern} [opts.props] - The pattern properties.
29
17
  */
30
18
  constructor(opts) {
19
+ /**
20
+ * The type of fill, which is always `Pattern`.
21
+ */
22
+ this.fillType = types_1.FillType.Pattern;
31
23
  this.type = opts?.props?.type || types_1.PatternType.Repeat;
32
- this.src = opts?.props?.src || '';
24
+ this.src = opts?.props?.src || "";
33
25
  }
34
26
  /**
35
27
  * Sets the type of the pattern.
@@ -56,9 +48,9 @@ class Pattern {
56
48
  */
57
49
  async draw(ctx) {
58
50
  if (!this.src)
59
- throw new LazyUtil_1.LazyError('Pattern source is not set');
51
+ throw new LazyUtil_1.LazyError("Pattern source is not set");
60
52
  if (this.src instanceof LazyCanvas_1.LazyCanvas) {
61
- return ctx.createPattern((await this.src.manager.render.render('canvas')), this.type);
53
+ return ctx.createPattern((await this.src.manager.render.render("canvas")), this.type);
62
54
  }
63
55
  return ctx.createPattern(await (0, canvas_1.loadImage)(this.src), this.type);
64
56
  }
@@ -70,12 +62,12 @@ class Pattern {
70
62
  let src = this.src;
71
63
  if (this.src instanceof LazyCanvas_1.LazyCanvas) {
72
64
  // @ts-ignore
73
- src = new Exporter_1.Exporter(this.src).syncExport('json');
65
+ src = new Exporter_1.Exporter(this.src).syncExport("json");
74
66
  }
75
67
  return {
76
68
  fillType: this.fillType,
77
69
  type: this.type,
78
- src: src
70
+ src: src,
79
71
  };
80
72
  }
81
73
  }
@@ -1,7 +1,7 @@
1
- export * from './Exporter';
2
- export * from './Font';
3
- export * from './Gradient';
4
- export * from './Link';
5
- export * from './Pattern';
6
- export * from './readers/JSONReader';
7
- export * from './readers/YAMLReader';
1
+ export * from "./Exporter";
2
+ export * from "./Font";
3
+ export * from "./Gradient";
4
+ export * from "./Link";
5
+ export * from "./Pattern";
6
+ export * from "./readers/JSONReader";
7
+ export * from "./readers/YAMLReader";
@@ -27,17 +27,17 @@ export declare class JSONReader {
27
27
  }): LazyCanvas;
28
28
  /**
29
29
  * Parses an array of JSON layers into an array of AnyLayer or Group instances.
30
- * @param {Array<JSONLayer | Group>} [data] - The array of JSON layers to parse.
30
+ * @param {Array<JSONLayer | Div>} [data] - The array of JSON layers to parse.
31
31
  * @param {Object} [opts] - Optional settings.
32
32
  * @param {boolean} [opts.debug] - Whether to enable debug logging.
33
- * @returns {Array<AnyLayer | Group>} The parsed layers.
33
+ * @returns {Array<AnyLayer | Div>} The parsed layers.
34
34
  */
35
35
  private static layersParse;
36
36
  /**
37
37
  * Parses a single JSON layer into an AnyLayer or Group instance.
38
- * @param {JSONLayer | IGroup | Group} [layer] - The JSON layer to parse.
38
+ * @param {JSONLayer | IDiv | Div} [layer] - The JSON layer to parse.
39
39
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
40
- * @returns {AnyLayer | Group} The parsed layer.
40
+ * @returns {AnyLayer | Div} The parsed layer.
41
41
  */
42
42
  private static layerParse;
43
43
  /**
@@ -38,9 +38,10 @@ const types_1 = require("../../../types");
38
38
  const components_1 = require("../../components");
39
39
  const __1 = require("../");
40
40
  const LazyCanvas_1 = require("../../LazyCanvas");
41
- const fs = __importStar(require("fs"));
41
+ const fs = __importStar(require("node:fs"));
42
42
  const LazyUtil_1 = require("../../../utils/LazyUtil");
43
- const path = __importStar(require("path"));
43
+ const path = __importStar(require("node:path"));
44
+ const Signal_1 = require("../../../core/Signal");
44
45
  /**
45
46
  * Class responsible for reading and parsing JSON data into a LazyCanvas instance.
46
47
  */
@@ -60,17 +61,13 @@ class JSONReader {
60
61
  if (data.options.exportType === undefined) {
61
62
  throw new LazyUtil_1.LazyError("Invalid export type");
62
63
  }
63
- if (data.options.flag === undefined) {
64
- throw new LazyUtil_1.LazyError("Invalid export flag");
65
- }
66
64
  if (data.layers === undefined || data.layers.length === 0) {
67
65
  throw new LazyUtil_1.LazyError("No layers found");
68
66
  }
69
67
  if (opts?.debug)
70
- LazyUtil_1.LazyLog.log("info", "Reading JSON...\nOptions:", data.options, "\nAnimation:", data.animation, "\nLayers Number:", data.layers.length, "\nLayers:", data.layers);
68
+ LazyUtil_1.LazyLog.log("info", "Reading JSON...\nOptions:", data.options, "\nLayers Number:", data.layers.length, "\nLayers:", data.layers);
71
69
  const layers = JSONReader.layersParse(data.layers, opts);
72
- const canvas = new LazyCanvas_1.LazyCanvas({ settings: data, debug: opts?.debug })
73
- .create(data.options.width, data.options.height);
70
+ const canvas = new LazyCanvas_1.LazyCanvas({ settings: data, debug: opts?.debug }).create(data.options.width, data.options.height);
74
71
  canvas.manager.layers.add(...layers);
75
72
  return canvas;
76
73
  }
@@ -94,37 +91,31 @@ class JSONReader {
94
91
  }
95
92
  /**
96
93
  * Parses an array of JSON layers into an array of AnyLayer or Group instances.
97
- * @param {Array<JSONLayer | Group>} [data] - The array of JSON layers to parse.
94
+ * @param {Array<JSONLayer | Div>} [data] - The array of JSON layers to parse.
98
95
  * @param {Object} [opts] - Optional settings.
99
96
  * @param {boolean} [opts.debug] - Whether to enable debug logging.
100
- * @returns {Array<AnyLayer | Group>} The parsed layers.
97
+ * @returns {Array<AnyLayer | Div>} The parsed layers.
101
98
  */
102
99
  static layersParse(data, opts) {
103
100
  return data.map((layer) => {
104
101
  if (opts?.debug)
105
- LazyUtil_1.LazyLog.log('info', `Parsing layer ${layer.id}...\nData:`, layer);
106
- const misc = {
102
+ LazyUtil_1.LazyLog.log("info", `Parsing layer ${layer.id}...\nData:`, layer);
103
+ return this.layerParse(layer, {
107
104
  id: layer.id,
108
105
  zIndex: layer.zIndex,
109
106
  visible: layer.visible,
110
- };
111
- if (layer.type === types_1.LayerType.Group) {
112
- return new components_1.Group(misc).add(...layer.layers.map((l) => this.layerParse(l, { id: l.id, zIndex: l.zIndex, visible: l.visible })));
113
- }
114
- else {
115
- return this.layerParse(layer, misc);
116
- }
107
+ });
117
108
  });
118
109
  }
119
110
  /**
120
111
  * Parses a single JSON layer into an AnyLayer or Group instance.
121
- * @param {JSONLayer | IGroup | Group} [layer] - The JSON layer to parse.
112
+ * @param {JSONLayer | IDiv | Div} [layer] - The JSON layer to parse.
122
113
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
123
- * @returns {AnyLayer | Group} The parsed layer.
114
+ * @returns {AnyLayer | Div} The parsed layer.
124
115
  */
125
116
  static layerParse(layer, misc) {
126
- if (layer instanceof components_1.Group) {
127
- return new components_1.Group(misc).add(...layer.layers.map((l) => this.layerParse(l)));
117
+ if (layer instanceof components_1.Div) {
118
+ return new components_1.Div(misc).add(...layer.layers.map((l) => this.layerParse(l)));
128
119
  }
129
120
  else {
130
121
  switch (layer.type) {
@@ -140,15 +131,12 @@ class JSONReader {
140
131
  return new components_1.MorphLayer(layer.props, misc).setColor(this.fillParse(layer));
141
132
  case types_1.LayerType.Line:
142
133
  return new components_1.LineLayer(layer.props, misc).setColor(this.fillParse(layer));
143
- case types_1.LayerType.Clear:
144
- return new components_1.ClearLayer(layer.props, misc);
145
134
  case types_1.LayerType.Path:
146
135
  return new components_1.Path2DLayer(layer.props, misc).setColor(this.fillParse(layer));
147
136
  case types_1.LayerType.Polygon:
148
137
  return new components_1.PolygonLayer(layer.props, misc).setColor(this.fillParse(layer));
149
138
  case types_1.LayerType.Group:
150
- return new components_1.Group(misc)
151
- .add(...layer.layers.map((l) => this.layerParse(l)));
139
+ return new components_1.Div(misc).add(...layer.layers.map((l) => this.layerParse(l)));
152
140
  default:
153
141
  return layer;
154
142
  }
@@ -160,24 +148,28 @@ class JSONReader {
160
148
  * @returns {string | Gradient | Pattern} The parsed fill style.
161
149
  */
162
150
  static fillParse(layer) {
163
- if ('fillStyle' in layer.props && layer.props.fillStyle && typeof layer.props.fillStyle !== 'string') {
164
- switch (layer.props.fillStyle?.fillType) {
165
- case 'gradient':
166
- return new __1.Gradient({ props: layer.props.fillStyle });
167
- case 'pattern':
168
- return new __1.Pattern()
169
- .setType(layer.props.fillStyle.type)
170
- .setSrc(typeof layer.props.fillStyle.src === 'string' ? layer.props.fillStyle.src : this.read(layer.props.fillStyle.src));
171
- default:
172
- return layer.props.fillStyle;
151
+ if ("fillStyle" in layer.props) {
152
+ if ((0, Signal_1.isSignal)(layer.props.fillStyle)) {
153
+ throw new LazyUtil_1.LazyError("Signals are not supported in JSON fill styles");
173
154
  }
174
- }
175
- else if ('fillStyle' in layer.props) {
176
- console.log(layer.type, layer);
177
- return layer.props.fillStyle || '#000000';
155
+ if (typeof layer.props.fillStyle === "object") {
156
+ switch (layer.props.fillStyle?.fillType) {
157
+ case "gradient":
158
+ return new __1.Gradient({ props: layer.props.fillStyle });
159
+ case "pattern":
160
+ return new __1.Pattern()
161
+ .setType(layer.props.fillStyle.type)
162
+ .setSrc(typeof layer.props.fillStyle.src === "string"
163
+ ? layer.props.fillStyle.src
164
+ : this.read(layer.props.fillStyle.src));
165
+ default:
166
+ return layer.props.fillStyle;
167
+ }
168
+ }
169
+ return layer.props.fillStyle || "#000000";
178
170
  }
179
171
  else {
180
- return '#000000';
172
+ return "#000000";
181
173
  }
182
174
  }
183
175
  }
@@ -36,9 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.YAMLReader = void 0;
37
37
  const JSONReader_1 = require("./JSONReader");
38
38
  const _yaml = __importStar(require("js-yaml"));
39
- const fs = __importStar(require("fs"));
39
+ const fs = __importStar(require("node:fs"));
40
40
  const LazyUtil_1 = require("../../../utils/LazyUtil");
41
- const path = __importStar(require("path"));
41
+ const path = __importStar(require("node:path"));
42
42
  class YAMLReader {
43
43
  /**
44
44
  * Reads a YAML string and converts it to a LazyCanvas object.
@@ -49,9 +49,9 @@ class YAMLReader {
49
49
  static read(data, opts) {
50
50
  const yamlContent = _yaml.load(data);
51
51
  if (opts?.debug) {
52
- LazyUtil_1.LazyLog.log('info', 'YAML content loaded:', yamlContent);
52
+ LazyUtil_1.LazyLog.log("info", "YAML content loaded:", yamlContent);
53
53
  }
54
- if (typeof yamlContent === 'object' && yamlContent !== null) {
54
+ if (typeof yamlContent === "object" && yamlContent !== null) {
55
55
  return JSONReader_1.JSONReader.read(yamlContent, opts);
56
56
  }
57
57
  else {
@@ -70,12 +70,12 @@ class YAMLReader {
70
70
  throw new LazyUtil_1.LazyError(`File not found: ${filePath}`);
71
71
  }
72
72
  const ext = path.extname(filePath).toLowerCase();
73
- if (ext !== '.yaml' && ext !== '.yml') {
73
+ if (ext !== ".yaml" && ext !== ".yml") {
74
74
  throw new LazyUtil_1.LazyError(`Invalid file extension: ${ext}. Expected .yaml or .yml.`);
75
75
  }
76
- const data = fs.readFileSync(filePath, 'utf8');
76
+ const data = fs.readFileSync(filePath, "utf8");
77
77
  if (opts?.debug) {
78
- LazyUtil_1.LazyLog.log('info', `Reading YAML file: ${filePath}`);
78
+ LazyUtil_1.LazyLog.log("info", `Reading YAML file: ${filePath}`);
79
79
  }
80
80
  return this.read(data, opts);
81
81
  }
@@ -9,14 +9,6 @@ const canvas_1 = require("@napi-rs/canvas");
9
9
  * Class representing a manager for handling fonts.
10
10
  */
11
11
  class FontsManager {
12
- /**
13
- * A map storing fonts with their family and weight as the key.
14
- */
15
- map;
16
- /**
17
- * Whether debugging is enabled.
18
- */
19
- debug;
20
12
  /**
21
13
  * Constructs a new FontsManager instance.
22
14
  * @param {Object} [opts] - Optional settings for the FontsManager.
@@ -33,14 +25,13 @@ class FontsManager {
33
25
  * @returns {this} The current instance for chaining.
34
26
  */
35
27
  loadFonts(fontList) {
36
- this.add(...Object.entries(fontList).map(([fontFamily, fontWeights]) => {
28
+ this.add(...Object.entries(fontList)
29
+ .map(([fontFamily, fontWeights]) => {
37
30
  return Object.entries(fontWeights).map(([weight, base64]) => {
38
- return new helpers_1.Font()
39
- .setFamily(fontFamily)
40
- .setWeight(Number(weight))
41
- .setBase64(base64);
31
+ return new helpers_1.Font().setFamily(fontFamily).setWeight(Number(weight)).setBase64(base64);
42
32
  });
43
- }).flat());
33
+ })
34
+ .flat());
44
35
  return this;
45
36
  }
46
37
  /**
@@ -53,10 +44,10 @@ class FontsManager {
53
44
  */
54
45
  add(...fonts) {
55
46
  if (this.debug)
56
- LazyUtil_1.LazyLog.log('info', `Adding fonts...\nlength: ${fonts.length}`);
47
+ LazyUtil_1.LazyLog.log("info", `Adding fonts...\nlength: ${fonts.length}`);
57
48
  for (const font of fonts) {
58
49
  if (this.debug)
59
- LazyUtil_1.LazyLog.log('none', `Data:`, font.toJSON());
50
+ LazyUtil_1.LazyLog.log("none", `Data:`, font.toJSON());
60
51
  if (!font.family)
61
52
  throw new LazyUtil_1.LazyError("Family must be provided");
62
53
  if (!font.weight)
@@ -101,7 +92,7 @@ class FontsManager {
101
92
  get(family, weight) {
102
93
  if (weight)
103
94
  return this.map.get(`${family}_${weight}`);
104
- return Array.from(this.map.values()).filter(font => font.family === family);
95
+ return Array.from(this.map.values()).filter((font) => font.family === family);
105
96
  }
106
97
  /**
107
98
  * Checks if a font exists in the manager.
@@ -112,7 +103,7 @@ class FontsManager {
112
103
  has(family, weight) {
113
104
  if (weight)
114
105
  return this.map.has(`${family}_${weight}`);
115
- return Array.from(this.map.values()).some(font => font.family === family);
106
+ return Array.from(this.map.values()).some((font) => font.family === family);
116
107
  }
117
108
  /**
118
109
  * Retrieves the number of fonts in the manager.