@nmmty/lazycanvas 0.6.5 → 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 +25 -38
  28. package/dist/structures/components/BezierLayer.js +88 -53
  29. package/dist/structures/components/{Group.d.ts → Div.d.ts} +37 -18
  30. package/dist/structures/components/Div.js +202 -0
  31. package/dist/structures/components/ImageLayer.d.ts +1 -1
  32. package/dist/structures/components/ImageLayer.js +28 -29
  33. package/dist/structures/components/LineLayer.d.ts +18 -36
  34. package/dist/structures/components/LineLayer.js +43 -45
  35. package/dist/structures/components/MorphLayer.d.ts +4 -33
  36. package/dist/structures/components/MorphLayer.js +37 -51
  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 +3 -32
  40. package/dist/structures/components/PolygonLayer.js +37 -42
  41. package/dist/structures/components/QuadraticLayer.d.ts +25 -34
  42. package/dist/structures/components/QuadraticLayer.js +83 -47
  43. package/dist/structures/components/TextLayer.d.ts +5 -34
  44. package/dist/structures/components/TextLayer.js +88 -71
  45. package/dist/structures/components/index.d.ts +10 -11
  46. package/dist/structures/components/index.js +1 -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 +44 -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 +1 -2
  71. package/dist/types/enum.js +1 -2
  72. package/dist/types/index.d.ts +1 -1
  73. package/dist/types/types.d.ts +257 -107
  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 +4 -7
  82. package/dist/utils/utils.js +140 -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
@@ -1,19 +1,24 @@
1
1
  import { IOLazyCanvas, LazyCanvas } from "../LazyCanvas";
2
2
  import { AnyExport } from "../../types";
3
3
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
+ import { Scene } from "../../core";
4
5
  /**
5
- * Class responsible for exporting a LazyCanvas instance to various formats.
6
+ * Class responsible for exporting a LazyCanvas or Scene instance to various formats.
6
7
  */
7
8
  export declare class Exporter {
8
9
  /**
9
10
  * The LazyCanvas instance to be exported.
10
11
  */
11
- canvas: LazyCanvas;
12
+ canvas?: LazyCanvas;
13
+ /**
14
+ * The Scene instance to be exported.
15
+ */
16
+ scene?: Scene;
12
17
  /**
13
18
  * Constructs a new Exporter instance.
14
- * @param canvas {LazyCanvas} - The LazyCanvas instance to be exported.
19
+ * @param source {LazyCanvas | Scene} - The LazyCanvas or Scene instance to be exported.
15
20
  */
16
- constructor(canvas: LazyCanvas);
21
+ constructor(source: LazyCanvas | Scene);
17
22
  /**
18
23
  * Saves a file to the filesystem.
19
24
  * @param {any} [buffer] - The data to be saved.
@@ -34,12 +39,16 @@ export declare class Exporter {
34
39
  * @param {Object} [opts] - Optional settings.
35
40
  * @param {string} [opts.name] - The name of the file (optional).
36
41
  * @param {boolean} [opts.saveAsFile] - Whether to save the export as a file (optional).
42
+ * @param {number} [opts.duration] - Duration of the animation in seconds (Scene only).
43
+ * @param {number} [opts.fps] - Frames per second for animation (default: 60, Scene only).
37
44
  * @returns {Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>} The exported data.
38
45
  * @throws {LazyError} If the export type is not supported.
39
46
  */
40
47
  export(exportType: AnyExport, opts?: {
41
48
  name?: string;
42
49
  saveAsFile?: boolean;
50
+ duration?: number;
51
+ fps?: number;
43
52
  }): Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>;
44
53
  /**
45
54
  * Synchronously exports the canvas to the specified format.
@@ -32,27 +32,33 @@ var __importStar = (this && this.__importStar) || (function () {
32
32
  return result;
33
33
  };
34
34
  })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
35
38
  Object.defineProperty(exports, "__esModule", { value: true });
36
39
  exports.Exporter = void 0;
37
40
  const types_1 = require("../../types");
38
- const LazyUtil_1 = require("../../utils/LazyUtil");
39
- const fs = __importStar(require("fs"));
40
- const utils_1 = require("../../utils/utils");
41
+ const utils_1 = require("../../utils");
42
+ const fs = __importStar(require("node:fs"));
41
43
  const _yaml = __importStar(require("js-yaml"));
44
+ const APNGEncoder_1 = __importDefault(require("../../utils/APNGEncoder"));
45
+ const core_1 = require("../../core");
42
46
  /**
43
- * Class responsible for exporting a LazyCanvas instance to various formats.
47
+ * Class responsible for exporting a LazyCanvas or Scene instance to various formats.
44
48
  */
45
49
  class Exporter {
46
- /**
47
- * The LazyCanvas instance to be exported.
48
- */
49
- canvas;
50
50
  /**
51
51
  * Constructs a new Exporter instance.
52
- * @param canvas {LazyCanvas} - The LazyCanvas instance to be exported.
52
+ * @param source {LazyCanvas | Scene} - The LazyCanvas or Scene instance to be exported.
53
53
  */
54
- constructor(canvas) {
55
- this.canvas = canvas;
54
+ constructor(source) {
55
+ if (source instanceof core_1.Scene) {
56
+ this.scene = source;
57
+ this.canvas = source.lazyCanvas;
58
+ }
59
+ else {
60
+ this.canvas = source;
61
+ }
56
62
  }
57
63
  /**
58
64
  * Saves a file to the filesystem.
@@ -63,9 +69,9 @@ class Exporter {
63
69
  */
64
70
  async saveFile(buffer, extension, name) {
65
71
  if (!buffer)
66
- throw new LazyUtil_1.LazyError('Buffer must be provided');
72
+ throw new utils_1.LazyError("Buffer must be provided");
67
73
  if (!extension)
68
- throw new LazyUtil_1.LazyError('Extension must be provided');
74
+ throw new utils_1.LazyError("Extension must be provided");
69
75
  fs.writeFileSync(`${name === undefined ? (0, utils_1.generateRandomName)() : name}.${extension}`, buffer);
70
76
  }
71
77
  /**
@@ -86,12 +92,15 @@ class Exporter {
86
92
  * @param {Object} [opts] - Optional settings.
87
93
  * @param {string} [opts.name] - The name of the file (optional).
88
94
  * @param {boolean} [opts.saveAsFile] - Whether to save the export as a file (optional).
95
+ * @param {number} [opts.duration] - Duration of the animation in seconds (Scene only).
96
+ * @param {number} [opts.fps] - Frames per second for animation (default: 60, Scene only).
89
97
  * @returns {Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>} The exported data.
90
98
  * @throws {LazyError} If the export type is not supported.
91
99
  */
92
100
  async export(exportType, opts) {
93
- // beforeExport hook
94
- this.canvas.manager.plugins.executeHook('beforeExport', this.canvas);
101
+ if (!this.canvas) {
102
+ throw new utils_1.LazyError("Canvas is not initialized");
103
+ }
95
104
  let result;
96
105
  switch (exportType) {
97
106
  case types_1.Export.CTX:
@@ -100,69 +109,94 @@ class Exporter {
100
109
  break;
101
110
  case types_1.Export.SVG:
102
111
  case "svg":
103
- result = await this.canvas.manager.render.render('svg');
112
+ result = await this.canvas.manager.render.render("svg");
104
113
  if (opts?.saveAsFile) {
105
- await this.saveFile(result, 'svg', opts.name);
114
+ await this.saveFile(result, "svg", opts.name);
106
115
  }
107
116
  break;
108
117
  case types_1.Export.BUFFER:
109
118
  case "buffer":
110
- result = await this.canvas.manager.render.render('buffer');
111
- if (opts?.saveAsFile) {
112
- await this.saveFile(result, 'png', opts.name);
119
+ if (this.scene) {
120
+ result = await this.scene.renderFirstFrame().then((frame) => frame.toBuffer("image/png"));
121
+ }
122
+ else {
123
+ result = (await this.canvas.manager.render.render("buffer"));
113
124
  }
114
- break;
115
- case types_1.Export.GIF:
116
- case "gif":
117
- result = await this.canvas.manager.render.render('buffer');
118
125
  if (opts?.saveAsFile) {
119
- await this.saveFile(result, 'gif', opts.name);
126
+ await this.saveFile(result, "png", opts.name);
120
127
  }
121
128
  break;
122
129
  case types_1.Export.WEBP:
123
130
  case "webp":
124
- result = await this.canvas.manager.render.render('buffer');
131
+ if (this.scene) {
132
+ result = await this.scene
133
+ .renderFirstFrame()
134
+ .then((frame) => frame.toBuffer("image/webp"));
135
+ }
136
+ else {
137
+ result = await this.canvas.manager.render.render("webp");
138
+ }
125
139
  if (opts?.saveAsFile) {
126
- await this.saveFile(result, 'webp', opts.name);
140
+ await this.saveFile(result, "webp", opts.name);
127
141
  }
128
142
  break;
129
- case types_1.Export.JPEG:
130
- case "jpeg":
131
- result = await this.canvas.manager.render.render('buffer');
132
- await this.saveFile(result, 'jpeg', opts?.name);
133
- break;
134
143
  case types_1.Export.JPG:
135
144
  case "jpg":
136
- const jpg = await this.canvas.manager.render.render('buffer');
137
- await this.saveFile(jpg, 'jpg', opts?.name);
138
- return jpg;
145
+ if (this.scene) {
146
+ result = await this.scene
147
+ .renderFirstFrame()
148
+ .then((frame) => frame.toBuffer("image/jpeg"));
149
+ }
150
+ else {
151
+ result = await this.canvas.manager.render.render("jpg");
152
+ }
153
+ await this.saveFile(result, "jpg", opts?.name);
154
+ return result;
139
155
  case types_1.Export.PNG:
140
156
  case "png":
141
- const png = await this.canvas.manager.render.render('buffer');
142
- await this.saveFile(png, 'png', opts?.name);
143
- return png;
157
+ if (this.scene) {
158
+ result = await this.scene.renderFirstFrame().then((frame) => frame.toBuffer("image/png"));
159
+ }
160
+ else {
161
+ result = await this.canvas.manager.render.render("png");
162
+ }
163
+ await this.saveFile(result, "png", opts?.name);
164
+ return result;
165
+ case types_1.Export.APNG:
166
+ case "apng":
167
+ if (!this.scene) {
168
+ throw new utils_1.LazyError("APNG export requires a Scene instance. Use: new Exporter(scene)");
169
+ }
170
+ const duration = opts?.duration ?? 0;
171
+ const timeNow = Date.now();
172
+ const fps = opts?.fps ?? 60;
173
+ const frameData = await this.scene.renderAnimationData(timeNow, timeNow + duration, fps);
174
+ const encoder = new APNGEncoder_1.default(this.scene.width, this.scene.height, fps).addFrames(...frameData);
175
+ const buffer = encoder.encode();
176
+ if (opts?.saveAsFile !== false) {
177
+ fs.writeFileSync(`${opts?.name ?? "animation"}.png`, buffer);
178
+ }
179
+ return buffer;
144
180
  case types_1.Export.JSON:
145
181
  case "json":
146
182
  const json = this.syncExport(exportType);
147
183
  if (opts?.saveAsFile) {
148
- await this.saveFile(JSON.stringify(json), 'json', opts.name);
184
+ await this.saveFile(JSON.stringify(json), "json", opts.name);
149
185
  }
150
186
  return JSON.stringify(json);
151
187
  case types_1.Export.CANVAS:
152
188
  case "canvas":
153
- return await this.canvas.manager.render.render(exportType);
189
+ return (await this.canvas.manager.render.render(exportType));
154
190
  case types_1.Export.YAML:
155
191
  case "yaml":
156
192
  const yaml = _yaml.dump(this.syncExport(types_1.Export.JSON));
157
193
  if (opts?.saveAsFile) {
158
- await this.saveFile(yaml, 'yaml', opts.name);
194
+ await this.saveFile(yaml, "yaml", opts.name);
159
195
  }
160
196
  return yaml;
161
197
  default:
162
- throw new LazyUtil_1.LazyError(`Export type ${exportType} is not supported`);
198
+ throw new utils_1.LazyError(`Export type ${exportType} is not supported`);
163
199
  }
164
- // afterExport hook
165
- this.canvas.manager.plugins.executeHook('afterExport', this.canvas, result);
166
200
  return result;
167
201
  }
168
202
  /**
@@ -171,13 +205,15 @@ class Exporter {
171
205
  * @returns {IOLazyCanvas | void} The exported data or void if the export type is unsupported.
172
206
  */
173
207
  syncExport(exportType) {
208
+ if (!this.canvas) {
209
+ throw new utils_1.LazyError("Canvas is not initialized");
210
+ }
174
211
  switch (exportType) {
175
212
  case types_1.Export.JSON:
176
213
  case "json":
177
214
  return {
178
215
  options: this.canvas.options,
179
- animation: this.canvas.manager.animation.options,
180
- layers: this.exportLayers(this.canvas.manager.layers)
216
+ layers: this.exportLayers(this.canvas.manager.layers),
181
217
  };
182
218
  }
183
219
  }
@@ -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
  /**