@nmmty/lazycanvas 0.6.4 → 1.0.0-dev.10

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 (91) hide show
  1. package/ReadMe.md +1 -1
  2. package/dist/core/Interpolation.d.ts +30 -0
  3. package/dist/core/Interpolation.js +200 -0
  4. package/dist/core/Scene.d.ts +94 -0
  5. package/dist/core/Scene.js +157 -0
  6. package/dist/core/Signal.d.ts +133 -0
  7. package/dist/core/Signal.js +255 -0
  8. package/dist/core/SignalUtils.d.ts +133 -0
  9. package/dist/core/SignalUtils.js +333 -0
  10. package/dist/core/ThreadScheduler.d.ts +38 -0
  11. package/dist/core/ThreadScheduler.js +74 -0
  12. package/dist/core/index.d.ts +5 -0
  13. package/dist/core/index.js +21 -0
  14. package/dist/helpers/Filters.js +1 -1
  15. package/dist/helpers/FontsList.js +18 -18
  16. package/dist/helpers/Utlis.d.ts +3 -3
  17. package/dist/helpers/Utlis.js +25 -36
  18. package/dist/helpers/index.d.ts +3 -3
  19. package/dist/index.d.ts +4 -1
  20. package/dist/index.js +4 -1
  21. package/dist/jsx-runtime.d.ts +17 -0
  22. package/dist/jsx-runtime.js +111 -0
  23. package/dist/structures/LazyCanvas.d.ts +10 -48
  24. package/dist/structures/LazyCanvas.js +17 -78
  25. package/dist/structures/components/BaseLayer.d.ts +78 -32
  26. package/dist/structures/components/BaseLayer.js +106 -37
  27. package/dist/structures/components/BezierLayer.d.ts +27 -40
  28. package/dist/structures/components/BezierLayer.js +90 -55
  29. package/dist/structures/components/{Group.d.ts → Div.d.ts} +41 -22
  30. package/dist/structures/components/Div.js +202 -0
  31. package/dist/structures/components/ImageLayer.d.ts +2 -2
  32. package/dist/structures/components/ImageLayer.js +29 -30
  33. package/dist/structures/components/LineLayer.d.ts +20 -38
  34. package/dist/structures/components/LineLayer.js +45 -47
  35. package/dist/structures/components/MorphLayer.d.ts +5 -34
  36. package/dist/structures/components/MorphLayer.js +38 -52
  37. package/dist/structures/components/Path2DLayer.d.ts +7 -35
  38. package/dist/structures/components/Path2DLayer.js +32 -41
  39. package/dist/structures/components/PolygonLayer.d.ts +95 -0
  40. package/dist/structures/components/PolygonLayer.js +203 -0
  41. package/dist/structures/components/QuadraticLayer.d.ts +36 -45
  42. package/dist/structures/components/QuadraticLayer.js +90 -54
  43. package/dist/structures/components/TextLayer.d.ts +17 -46
  44. package/dist/structures/components/TextLayer.js +94 -77
  45. package/dist/structures/components/index.d.ts +10 -10
  46. package/dist/structures/components/index.js +2 -2
  47. package/dist/structures/helpers/Exporter.d.ts +13 -4
  48. package/dist/structures/helpers/Exporter.js +82 -46
  49. package/dist/structures/helpers/Font.js +1 -17
  50. package/dist/structures/helpers/Gradient.js +35 -49
  51. package/dist/structures/helpers/Link.js +2 -14
  52. package/dist/structures/helpers/Pattern.js +10 -18
  53. package/dist/structures/helpers/index.d.ts +7 -7
  54. package/dist/structures/helpers/readers/JSONReader.d.ts +4 -4
  55. package/dist/structures/helpers/readers/JSONReader.js +46 -48
  56. package/dist/structures/helpers/readers/YAMLReader.js +11 -11
  57. package/dist/structures/managers/FontsManager.js +9 -18
  58. package/dist/structures/managers/LayersManager.d.ts +18 -28
  59. package/dist/structures/managers/LayersManager.js +14 -36
  60. package/dist/structures/managers/LayoutManager.d.ts +23 -0
  61. package/dist/structures/managers/LayoutManager.js +409 -0
  62. package/dist/structures/managers/index.d.ts +3 -5
  63. package/dist/structures/managers/index.js +1 -3
  64. package/dist/structures/managers/{RenderManager.d.ts → piplines/ClassicRenderPipeline.d.ts} +4 -30
  65. package/dist/structures/managers/piplines/ClassicRenderPipeline.js +90 -0
  66. package/dist/structures/managers/piplines/ModernRenderPipeline.d.ts +44 -0
  67. package/dist/structures/managers/piplines/ModernRenderPipeline.js +123 -0
  68. package/dist/structures/managers/piplines/index.d.ts +24 -0
  69. package/dist/structures/managers/piplines/index.js +18 -0
  70. package/dist/types/enum.d.ts +4 -3
  71. package/dist/types/enum.js +3 -2
  72. package/dist/types/index.d.ts +1 -1
  73. package/dist/types/types.d.ts +257 -105
  74. package/dist/utils/APNGEncoder.d.ts +67 -0
  75. package/dist/utils/APNGEncoder.js +205 -0
  76. package/dist/utils/DrawUtils.d.ts +9 -0
  77. package/dist/utils/DrawUtils.js +42 -0
  78. package/dist/utils/LazyUtil.js +1 -2
  79. package/dist/utils/index.d.ts +4 -0
  80. package/dist/utils/index.js +20 -0
  81. package/dist/utils/utils.d.ts +5 -9
  82. package/dist/utils/utils.js +154 -78
  83. package/package.json +61 -59
  84. package/dist/structures/components/ClearLayer.d.ts +0 -147
  85. package/dist/structures/components/ClearLayer.js +0 -158
  86. package/dist/structures/components/Group.js +0 -153
  87. package/dist/structures/managers/AnimationManager.d.ts +0 -120
  88. package/dist/structures/managers/AnimationManager.js +0 -99
  89. package/dist/structures/managers/PluginManager.d.ts +0 -230
  90. package/dist/structures/managers/PluginManager.js +0 -182
  91. package/dist/structures/managers/RenderManager.js +0 -183
@@ -6,22 +6,6 @@ const types_1 = require("../../types");
6
6
  * Class representing a font with properties such as family, weight, path, and base64.
7
7
  */
8
8
  class Font {
9
- /**
10
- * The font family.
11
- */
12
- family;
13
- /**
14
- * The weight of the font.
15
- */
16
- weight;
17
- /**
18
- * The file path of the font (optional).
19
- */
20
- path;
21
- /**
22
- * The base64 representation of the font (optional).
23
- */
24
- base64;
25
9
  /**
26
10
  * Constructs a new Font instance with default values.
27
11
  */
@@ -86,7 +70,7 @@ class Font {
86
70
  family: this.family,
87
71
  weight: this.weight,
88
72
  path: this.path,
89
- base64: this.base64
73
+ base64: this.base64,
90
74
  };
91
75
  }
92
76
  }
@@ -2,38 +2,21 @@
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
+ const utils_1 = require("../../utils");
7
6
  /**
8
7
  * Class representing a gradient with properties and methods to manipulate it.
9
8
  */
10
9
  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
10
  /**
32
11
  * Constructs a new Gradient instance.
33
12
  * @param {Object} [opts] - Optional properties for the gradient.
34
13
  * @param {IGradient} [opts.props] - The gradient properties.
35
14
  */
36
15
  constructor(opts) {
16
+ /**
17
+ * The type of fill, which is always `Gradient`.
18
+ */
19
+ this.fillType = types_1.FillType.Gradient;
37
20
  this.type = opts?.props?.type || types_1.GradientType.Linear;
38
21
  this.points = opts?.props?.points || [];
39
22
  this.stops = opts?.props?.stops || [];
@@ -115,33 +98,36 @@ class Gradient {
115
98
  let gradientData = this.toJSON();
116
99
  let gradient;
117
100
  if (opts.debug)
118
- LazyUtil_1.LazyLog.log('none', `Gradient:`, gradientData);
101
+ utils_1.LazyLog.log("none", `Gradient:`, gradientData);
119
102
  const parse = (0, utils_1.parser)(ctx, ctx.canvas, opts.manager);
120
103
  const { x0, y0, x1, y1 } = parse.parseBatch({
121
104
  x0: { v: gradientData.points[0]?.x || 0 },
122
- y0: { v: gradientData.points[0]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) },
105
+ y0: { v: gradientData.points[0]?.y || 0, options: utils_1.defaultArg.vl(true) },
123
106
  x1: { v: gradientData.points[1]?.x || 0 },
124
- y1: { v: gradientData.points[1]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) }
107
+ y1: { v: gradientData.points[1]?.y || 0, options: utils_1.defaultArg.vl(true) },
125
108
  });
126
109
  if (opts.debug)
127
- LazyUtil_1.LazyLog.log('none', `Gradient points:`, { x0, y0, x1, y1 });
110
+ utils_1.LazyLog.log("none", `Gradient points:`, { x0, y0, x1, y1 });
128
111
  switch (gradientData.type) {
129
112
  case types_1.GradientType.Linear:
130
113
  case "linear":
131
- if (gradientData.type === "linear" && (gradientData.angle || gradientData.angle === 0) && opts.layer && gradientData.points.length < 2) {
114
+ if (gradientData.type === "linear" &&
115
+ (gradientData.angle || gradientData.angle === 0) &&
116
+ opts.layer &&
117
+ gradientData.points.length < 2) {
132
118
  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');
119
+ const cx = this.getPosition(x, width, align, "x");
120
+ const cy = this.getPosition(y, height, align, "y");
135
121
  if (opts.debug)
136
- LazyUtil_1.LazyLog.log('none', `Center for angle calculation:`, { cx, cy });
122
+ utils_1.LazyLog.log("none", `Center for angle calculation:`, { cx, cy });
137
123
  const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
138
124
  if (opts.debug)
139
- LazyUtil_1.LazyLog.log('none', `Linear Gradient Points from angle:`, { p1, p2 });
125
+ utils_1.LazyLog.log("none", `Linear Gradient Points from angle:`, { p1, p2 });
140
126
  gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
141
127
  }
142
128
  else {
143
129
  if (opts.debug)
144
- LazyUtil_1.LazyLog.log('none', `Linear Gradient created from points.`);
130
+ utils_1.LazyLog.log("none", `Linear Gradient created from points.`);
145
131
  gradient = ctx.createLinearGradient(x0, y0, x1 || x0, y1 || y0);
146
132
  }
147
133
  break;
@@ -156,8 +142,8 @@ class Gradient {
156
142
  default:
157
143
  if ((gradientData.angle || gradientData.angle === 0) && opts.layer) {
158
144
  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');
145
+ const cx = this.getPosition(x, width, align, "x");
146
+ const cy = this.getPosition(y, height, align, "y");
161
147
  const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
162
148
  gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
163
149
  }
@@ -167,7 +153,7 @@ class Gradient {
167
153
  break;
168
154
  }
169
155
  for (let stop of gradientData.stops) {
170
- gradient.addColorStop(stop.offset, stop.color);
156
+ gradient.addColorStop(stop.offset, (0, utils_1.parseFillStyle)(ctx, stop.color, opts));
171
157
  }
172
158
  return gradient;
173
159
  }
@@ -181,7 +167,7 @@ class Gradient {
181
167
  type: this.type,
182
168
  points: this.points,
183
169
  stops: this.stops,
184
- angle: this.angle
170
+ angle: this.angle,
185
171
  };
186
172
  }
187
173
  getLinearGradientPoints(cx, cy, w, h, angleInDegrees) {
@@ -198,43 +184,43 @@ class Gradient {
198
184
  const y2r = cy + (x2 - cx) * sin + (y2 - cy) * cos;
199
185
  return [
200
186
  { x: x1r, y: y1r },
201
- { x: x2r, y: y2r }
187
+ { x: x2r, y: y2r },
202
188
  ];
203
189
  }
204
- getPosition(pos, side, align, type = 'x') {
190
+ getPosition(pos, side, align, type = "x") {
205
191
  switch (align) {
206
192
  case types_1.Centring.StartTop:
207
193
  case "start-top":
208
- return type === 'x' ? pos + (side / 2) : pos + (side / 2);
194
+ return type === "x" ? pos + side / 2 : pos + side / 2;
209
195
  case types_1.Centring.Start:
210
196
  case "start":
211
- return type === 'x' ? pos + (side / 2) : pos;
197
+ return type === "x" ? pos + side / 2 : pos;
212
198
  case types_1.Centring.StartBottom:
213
199
  case "start-bottom":
214
- return type === 'x' ? pos + (side / 2) : pos - (side / 2);
200
+ return type === "x" ? pos + side / 2 : pos - side / 2;
215
201
  case types_1.Centring.CenterTop:
216
202
  case "center-top":
217
- return type === 'x' ? pos : pos - (side / 2);
203
+ return type === "x" ? pos : pos - side / 2;
218
204
  case types_1.Centring.Center:
219
205
  case "center":
220
- return type === 'x' ? pos : pos;
206
+ return type === "x" ? pos : pos;
221
207
  case types_1.Centring.CenterBottom:
222
208
  case "center-bottom":
223
- return type === 'x' ? pos : pos - (side / 2);
209
+ return type === "x" ? pos : pos - side / 2;
224
210
  case types_1.Centring.EndTop:
225
211
  case "end-top":
226
- return type === 'x' ? pos - (side / 2) : pos + (side / 2);
212
+ return type === "x" ? pos - side / 2 : pos + side / 2;
227
213
  case types_1.Centring.End:
228
214
  case "end":
229
- return type === 'x' ? pos - (side / 2) : pos;
215
+ return type === "x" ? pos - side / 2 : pos;
230
216
  case types_1.Centring.EndBottom:
231
217
  case "end-bottom":
232
- return type === 'x' ? pos - (side / 2) : pos - (side / 2);
218
+ return type === "x" ? pos - side / 2 : pos - side / 2;
233
219
  case types_1.Centring.None:
234
220
  case "none":
235
- return type === 'x' ? pos + (side / 2) : pos + (side / 2);
221
+ return type === "x" ? pos + side / 2 : pos + side / 2;
236
222
  default:
237
- throw new LazyUtil_1.LazyError(`Invalid centring type: ${align}`);
223
+ throw new utils_1.LazyError(`Invalid centring type: ${align}`);
238
224
  }
239
225
  }
240
226
  }
@@ -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
  }
@@ -5,31 +5,23 @@ const types_1 = require("../../types");
5
5
  const LazyCanvas_1 = require("../LazyCanvas");
6
6
  const canvas_1 = require("@napi-rs/canvas");
7
7
  const Exporter_1 = require("./Exporter");
8
- const LazyUtil_1 = require("../../utils/LazyUtil");
8
+ const utils_1 = require("../../utils");
9
9
  /**
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 utils_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,11 @@ 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"));
42
- const LazyUtil_1 = require("../../../utils/LazyUtil");
43
- const path = __importStar(require("path"));
41
+ const fs = __importStar(require("node:fs"));
42
+ const utils_1 = require("../../../utils");
43
+ const path = __importStar(require("node:path"));
44
+ const core_1 = require("../../../core");
45
+ const managers_1 = require("../../managers");
44
46
  /**
45
47
  * Class responsible for reading and parsing JSON data into a LazyCanvas instance.
46
48
  */
@@ -55,22 +57,21 @@ class JSONReader {
55
57
  */
56
58
  static read(data, opts) {
57
59
  if (data.options.width <= 0 || data.options.height <= 0) {
58
- throw new LazyUtil_1.LazyError("Invalid width or height");
60
+ throw new utils_1.LazyError("Invalid width or height");
59
61
  }
60
62
  if (data.options.exportType === undefined) {
61
- throw new LazyUtil_1.LazyError("Invalid export type");
62
- }
63
- if (data.options.flag === undefined) {
64
- throw new LazyUtil_1.LazyError("Invalid export flag");
63
+ throw new utils_1.LazyError("Invalid export type");
65
64
  }
66
65
  if (data.layers === undefined || data.layers.length === 0) {
67
- throw new LazyUtil_1.LazyError("No layers found");
66
+ throw new utils_1.LazyError("No layers found");
68
67
  }
69
68
  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);
69
+ utils_1.LazyLog.log("info", "Reading JSON...\nOptions:", data.options, "\nLayers Number:", data.layers.length, "\nLayers:", data.layers);
71
70
  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);
71
+ const canvas = new LazyCanvas_1.LazyCanvas(managers_1.ClassicRenderPipeline, {
72
+ settings: data,
73
+ debug: opts?.debug,
74
+ }).create(data.options.width, data.options.height);
74
75
  canvas.manager.layers.add(...layers);
75
76
  return canvas;
76
77
  }
@@ -85,46 +86,40 @@ class JSONReader {
85
86
  static readFile(file, opts) {
86
87
  const filePath = path.resolve(file);
87
88
  if (!fs.existsSync(filePath))
88
- throw new LazyUtil_1.LazyError("File not found");
89
+ throw new utils_1.LazyError("File not found");
89
90
  const json = fs.readFileSync(filePath, "utf-8");
90
91
  const data = JSON.parse(json);
91
92
  if (opts?.debug)
92
- LazyUtil_1.LazyLog.log("info", "Reading JSON file...\nFile:", filePath, "\nData:", data);
93
+ utils_1.LazyLog.log("info", "Reading JSON file...\nFile:", filePath, "\nData:", data);
93
94
  return JSONReader.read(data, opts);
94
95
  }
95
96
  /**
96
97
  * 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.
98
+ * @param {Array<JSONLayer | Div>} [data] - The array of JSON layers to parse.
98
99
  * @param {Object} [opts] - Optional settings.
99
100
  * @param {boolean} [opts.debug] - Whether to enable debug logging.
100
- * @returns {Array<AnyLayer | Group>} The parsed layers.
101
+ * @returns {Array<AnyLayer | Div>} The parsed layers.
101
102
  */
102
103
  static layersParse(data, opts) {
103
104
  return data.map((layer) => {
104
105
  if (opts?.debug)
105
- LazyUtil_1.LazyLog.log('info', `Parsing layer ${layer.id}...\nData:`, layer);
106
- const misc = {
106
+ utils_1.LazyLog.log("info", `Parsing layer ${layer.id}...\nData:`, layer);
107
+ return this.layerParse(layer, {
107
108
  id: layer.id,
108
109
  zIndex: layer.zIndex,
109
110
  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
- }
111
+ });
117
112
  });
118
113
  }
119
114
  /**
120
115
  * Parses a single JSON layer into an AnyLayer or Group instance.
121
- * @param {JSONLayer | IGroup | Group} [layer] - The JSON layer to parse.
116
+ * @param {JSONLayer | IDiv | Div} [layer] - The JSON layer to parse.
122
117
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
123
- * @returns {AnyLayer | Group} The parsed layer.
118
+ * @returns {AnyLayer | Div} The parsed layer.
124
119
  */
125
120
  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)));
121
+ if (layer instanceof components_1.Div) {
122
+ return new components_1.Div({}, misc).add(...layer.layers.map((l) => this.layerParse(l)));
128
123
  }
129
124
  else {
130
125
  switch (layer.type) {
@@ -140,13 +135,12 @@ class JSONReader {
140
135
  return new components_1.MorphLayer(layer.props, misc).setColor(this.fillParse(layer));
141
136
  case types_1.LayerType.Line:
142
137
  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
138
  case types_1.LayerType.Path:
146
139
  return new components_1.Path2DLayer(layer.props, misc).setColor(this.fillParse(layer));
140
+ case types_1.LayerType.Polygon:
141
+ return new components_1.PolygonLayer(layer.props, misc).setColor(this.fillParse(layer));
147
142
  case types_1.LayerType.Group:
148
- return new components_1.Group(misc)
149
- .add(...layer.layers.map((l) => this.layerParse(l)));
143
+ return new components_1.Div({}, misc).add(...layer.layers.map((l) => this.layerParse(l)));
150
144
  default:
151
145
  return layer;
152
146
  }
@@ -158,24 +152,28 @@ class JSONReader {
158
152
  * @returns {string | Gradient | Pattern} The parsed fill style.
159
153
  */
160
154
  static fillParse(layer) {
161
- if ('fillStyle' in layer.props && layer.props.fillStyle && typeof layer.props.fillStyle !== 'string') {
162
- switch (layer.props.fillStyle?.fillType) {
163
- case 'gradient':
164
- return new __1.Gradient({ props: layer.props.fillStyle });
165
- case 'pattern':
166
- return new __1.Pattern()
167
- .setType(layer.props.fillStyle.type)
168
- .setSrc(typeof layer.props.fillStyle.src === 'string' ? layer.props.fillStyle.src : this.read(layer.props.fillStyle.src));
169
- default:
170
- return layer.props.fillStyle;
155
+ if ("color" in layer.props) {
156
+ if ((0, core_1.isSignal)(layer.props.color)) {
157
+ throw new utils_1.LazyError("Signals are not supported in JSON fill styles");
171
158
  }
172
- }
173
- else if ('fillStyle' in layer.props) {
174
- console.log(layer.type, layer);
175
- return layer.props.fillStyle || '#000000';
159
+ if (typeof layer.props.color === "object") {
160
+ switch (layer.props.color?.fillType) {
161
+ case "gradient":
162
+ return new __1.Gradient({ props: layer.props.color });
163
+ case "pattern":
164
+ return new __1.Pattern()
165
+ .setType(layer.props.color.type)
166
+ .setSrc(typeof layer.props.color.src === "string"
167
+ ? layer.props.color.src
168
+ : this.read(layer.props.color.src));
169
+ default:
170
+ return layer.props.color;
171
+ }
172
+ }
173
+ return layer.props.color || "#000000";
176
174
  }
177
175
  else {
178
- return '#000000';
176
+ return "#000000";
179
177
  }
180
178
  }
181
179
  }
@@ -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"));
40
- const LazyUtil_1 = require("../../../utils/LazyUtil");
41
- const path = __importStar(require("path"));
39
+ const fs = __importStar(require("node:fs"));
40
+ const utils_1 = require("../../../utils");
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,13 +49,13 @@ 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
+ utils_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 {
58
- throw new LazyUtil_1.LazyError("Invalid YAML content: Expected an object.");
58
+ throw new utils_1.LazyError("Invalid YAML content: Expected an object.");
59
59
  }
60
60
  }
61
61
  /**
@@ -67,15 +67,15 @@ class YAMLReader {
67
67
  */
68
68
  static readFile(filePath, opts) {
69
69
  if (!fs.existsSync(filePath)) {
70
- throw new LazyUtil_1.LazyError(`File not found: ${filePath}`);
70
+ throw new utils_1.LazyError(`File not found: ${filePath}`);
71
71
  }
72
72
  const ext = path.extname(filePath).toLowerCase();
73
- if (ext !== '.yaml' && ext !== '.yml') {
74
- throw new LazyUtil_1.LazyError(`Invalid file extension: ${ext}. Expected .yaml or .yml.`);
73
+ if (ext !== ".yaml" && ext !== ".yml") {
74
+ throw new utils_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
+ utils_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.