@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
@@ -5,14 +5,11 @@ const BaseLayer_1 = require("./BaseLayer");
5
5
  const types_1 = require("../../types");
6
6
  const utils_1 = require("../../utils/utils");
7
7
  const LazyUtil_1 = require("../../utils/LazyUtil");
8
+ const DrawUtils_1 = require("../../utils/DrawUtils");
8
9
  /**
9
10
  * Class representing a Bezier layer, extending the BaseLayer class.
10
11
  */
11
12
  class BezierLayer extends BaseLayer_1.BaseLayer {
12
- /**
13
- * The properties of the Bezier layer.
14
- */
15
- props;
16
13
  /**
17
14
  * Constructs a new BezierLayer instance.
18
15
  * @param {IBezierLayerProps} [props] - The properties of the Bezier layer.
@@ -31,18 +28,20 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
31
28
  */
32
29
  setControlPoints(...controlPoints) {
33
30
  if (controlPoints.length !== 2)
34
- throw new LazyUtil_1.LazyError('The control points of the layer must be provided');
31
+ throw new LazyUtil_1.LazyError("The control points of the layer must be provided");
35
32
  this.props.controlPoints = controlPoints.flat();
36
33
  return this;
37
34
  }
38
35
  /**
39
- * Sets the end position of the Bezier layer.
36
+ * Sets the position of the Bezier layer.
40
37
  * @param {ScaleType} [x] - The x-coordinate of the end point.
41
38
  * @param {ScaleType} [y] - The y-coordinate of the end point.
39
+ * @param {ScaleType} [endX] - The x-coordinate of the end point.
40
+ * @param {ScaleType} [endY] - The y-coordinate of the end point.
42
41
  * @returns {this} The current instance for chaining.
43
42
  */
44
- setEndPosition(x, y) {
45
- this.props.endPoint = { x, y };
43
+ setPosition(x, y, endX, endY) {
44
+ this.props.position = { x, y, endX: endX || 0, endY: endY || 0 };
46
45
  return this;
47
46
  }
48
47
  /**
@@ -53,9 +52,9 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
53
52
  */
54
53
  setColor(color) {
55
54
  if (!color)
56
- throw new LazyUtil_1.LazyError('The color of the layer must be provided');
55
+ throw new LazyUtil_1.LazyError("The color of the layer must be provided");
57
56
  if (!(0, utils_1.isColor)(color))
58
- throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
57
+ throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
59
58
  this.props.fillStyle = color;
60
59
  return this;
61
60
  }
@@ -72,8 +71,8 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
72
71
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
73
72
  this.props.stroke = {
74
73
  width,
75
- cap: cap || 'butt',
76
- join: join || 'miter',
74
+ cap: cap || "butt",
75
+ join: join || "miter",
77
76
  dash: dash || [],
78
77
  dashOffset: dashOffset || 0,
79
78
  miterLimit: miterLimit || 10,
@@ -90,16 +89,21 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
90
89
  getBoundingBox(ctx, canvas, manager) {
91
90
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
92
91
  const { xs, ys, cp1x, cp1y, cp2x, cp2y, xe, ye } = parcer.parseBatch({
93
- xs: { v: this.props.x },
94
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
92
+ xs: { v: this.props.position.x },
93
+ ys: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
95
94
  cp1x: { v: this.props.controlPoints[0].x },
96
95
  cp1y: { v: this.props.controlPoints[0].y, options: LazyUtil_1.defaultArg.vl(true) },
97
96
  cp2x: { v: this.props.controlPoints[1].x },
98
97
  cp2y: { v: this.props.controlPoints[1].y, options: LazyUtil_1.defaultArg.vl(true) },
99
- xe: { v: this.props.endPoint.x },
100
- ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
98
+ xe: { v: this.props.position.endX },
99
+ ye: { v: this.props.position.endY, options: LazyUtil_1.defaultArg.vl(true) },
101
100
  });
102
- const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cp1x, y: cp1y }, { x: cp2x, y: cp2y }, { x: xe, y: ye }]);
101
+ const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([
102
+ { x: xs, y: ys },
103
+ { x: cp1x, y: cp1y },
104
+ { x: cp2x, y: cp2y },
105
+ { x: xe, y: ye },
106
+ ]);
103
107
  return { max, min, center, width, height };
104
108
  }
105
109
  /**
@@ -112,33 +116,59 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
112
116
  async draw(ctx, canvas, manager, debug) {
113
117
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
114
118
  const { xs, ys, cp1x, cp1y, cp2x, cp2y, xe, ye } = parcer.parseBatch({
115
- xs: { v: this.props.x },
116
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
119
+ xs: { v: this.props.position.x },
120
+ ys: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
117
121
  cp1x: { v: this.props.controlPoints[0].x },
118
122
  cp1y: { v: this.props.controlPoints[0].y, options: LazyUtil_1.defaultArg.vl(true) },
119
123
  cp2x: { v: this.props.controlPoints[1].x },
120
124
  cp2y: { v: this.props.controlPoints[1].y, options: LazyUtil_1.defaultArg.vl(true) },
121
- xe: { v: this.props.endPoint.x },
122
- ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
125
+ xe: { v: this.props.position.endX },
126
+ ye: { v: this.props.position.endY, options: LazyUtil_1.defaultArg.vl(true) },
127
+ });
128
+ const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([
129
+ { x: xs, y: ys },
130
+ { x: cp1x, y: cp1y },
131
+ { x: cp2x, y: cp2y },
132
+ { x: xe, y: ye },
133
+ ]);
134
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, {
135
+ debug,
136
+ layer: { width, height, x: min.x, y: min.y, align: "none" },
137
+ manager,
123
138
  });
124
- const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cp1x, y: cp1y }, { x: cp2x, y: cp2y }, { x: xe, y: ye }]);
125
- let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width, height, x: min.x, y: min.y, align: 'none' }, manager });
126
139
  if (debug)
127
- LazyUtil_1.LazyLog.log('none', `BezierLayer:`, { xs, ys, cp1x, cp1y, cp2x, cp2y, xe, ye, max, min, center, width, height, fillStyle });
140
+ LazyUtil_1.LazyLog.log("none", `BezierLayer:`, {
141
+ xs,
142
+ ys,
143
+ cp1x,
144
+ cp1y,
145
+ cp2x,
146
+ cp2y,
147
+ xe,
148
+ ye,
149
+ max,
150
+ min,
151
+ center,
152
+ width,
153
+ height,
154
+ fillStyle,
155
+ });
128
156
  ctx.save();
129
- (0, utils_1.transform)(ctx, this.props.transform, { x: center.x, y: center.y, width, height, type: this.type });
130
- (0, utils_1.drawShadow)(ctx, this.props.shadow);
131
- (0, utils_1.opacity)(ctx, this.props.opacity);
132
- (0, utils_1.filters)(ctx, this.props.filter);
157
+ if (this.props.transform) {
158
+ (0, utils_1.transform)(ctx, this.props.transform, {
159
+ x: center.x,
160
+ y: center.y,
161
+ width,
162
+ height,
163
+ type: this.type,
164
+ });
165
+ }
166
+ DrawUtils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
167
+ DrawUtils_1.DrawUtils.opacity(ctx, this.props.opacity);
168
+ DrawUtils_1.DrawUtils.filters(ctx, this.props.filter);
169
+ DrawUtils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
133
170
  ctx.beginPath();
134
171
  ctx.moveTo(xs, ys);
135
- ctx.strokeStyle = fillStyle;
136
- ctx.lineWidth = this.props.stroke?.width || 1;
137
- ctx.lineCap = this.props.stroke?.cap || 'butt';
138
- ctx.lineJoin = this.props.stroke?.join || 'miter';
139
- ctx.miterLimit = this.props.stroke?.miterLimit || 10;
140
- ctx.lineDashOffset = this.props.stroke?.dashOffset || 0;
141
- ctx.setLineDash(this.props.stroke?.dash || []);
142
172
  ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, xe, ye);
143
173
  ctx.stroke();
144
174
  ctx.closePath();
@@ -151,18 +181,18 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
151
181
  toJSON() {
152
182
  let data = super.toJSON();
153
183
  let copy = { ...this.props };
154
- for (const key of ['x', 'y', 'endPoint.x', 'endPoint.y', 'fillStyle']) {
155
- if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
184
+ for (const key of ["x", "y", "endPoint.x", "endPoint.y", "fillStyle"]) {
185
+ if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
156
186
  copy[key] = copy[key].toJSON();
157
187
  }
158
188
  }
159
189
  if (copy.controlPoints) {
160
190
  copy.controlPoints = copy.controlPoints.map((point) => {
161
- if (point.x && typeof point.x === 'object' && 'toJSON' in point.x) {
191
+ if (point.x && typeof point.x === "object" && "toJSON" in point.x) {
162
192
  // @ts-ignore
163
193
  point.x = point.x.toJSON();
164
194
  }
165
- if (point.y && typeof point.y === 'object' && 'toJSON' in point.y) {
195
+ if (point.y && typeof point.y === "object" && "toJSON" in point.y) {
166
196
  // @ts-ignore
167
197
  point.y = point.y.toJSON();
168
198
  }
@@ -179,19 +209,26 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
179
209
  validateProps(data) {
180
210
  return {
181
211
  ...super.validateProps(data),
182
- filled: data.filled || false,
183
- fillStyle: data.fillStyle || '#000000',
212
+ position: {
213
+ x: data.position?.x || 0,
214
+ y: data.position?.y || 0,
215
+ endX: data.position?.endX || 0,
216
+ endY: data.position?.endY || 0,
217
+ },
218
+ fillStyle: data.fillStyle || "#000000",
184
219
  centring: data.centring || types_1.Centring.None,
185
- controlPoints: data.controlPoints || [{ x: 0, y: 0 }, { x: 0, y: 0 }],
186
- endPoint: data.endPoint || { x: 0, y: 0 },
220
+ controlPoints: data.controlPoints || [
221
+ { x: 0, y: 0 },
222
+ { x: 0, y: 0 },
223
+ ],
187
224
  stroke: {
188
225
  width: data.stroke?.width || 1,
189
- cap: data.stroke?.cap || 'butt',
190
- join: data.stroke?.join || 'miter',
226
+ cap: data.stroke?.cap || "butt",
227
+ join: data.stroke?.join || "miter",
191
228
  dashOffset: data.stroke?.dashOffset || 0,
192
229
  dash: data.stroke?.dash || [],
193
230
  miterLimit: data.stroke?.miterLimit || 10,
194
- }
231
+ },
195
232
  };
196
233
  }
197
234
  }
@@ -4,7 +4,7 @@ import { LayersManager } from "../managers";
4
4
  /**
5
5
  * Interface representing a group of layer's.
6
6
  */
7
- export interface IGroup {
7
+ export interface IDiv {
8
8
  /**
9
9
  * The unique identifier of the group.
10
10
  */
@@ -24,22 +24,23 @@ export interface IGroup {
24
24
  /**
25
25
  * The layer's contained within the group.
26
26
  */
27
- layers: Array<AnyLayer>;
27
+ layers: Array<AnyLayer | Div>;
28
28
  /**
29
29
  *
30
30
  */
31
- props?: IGroupProps;
31
+ props?: IDivProps;
32
32
  }
33
- export interface IGroupProps {
33
+ export interface IDivProps {
34
34
  /**
35
35
  * Don't use, this is just for compatibility.
36
36
  */
37
- globalComposite: AnyGlobalCompositeOperation;
37
+ globalComposite?: AnyGlobalCompositeOperation;
38
+ children?: Array<any>;
38
39
  }
39
40
  /**
40
41
  * Class representing a group of layer's.
41
42
  */
42
- export declare class Group implements IGroup {
43
+ export declare class Div implements IDiv {
43
44
  /**
44
45
  * The unique identifier of the group.
45
46
  */
@@ -59,8 +60,8 @@ export declare class Group implements IGroup {
59
60
  /**
60
61
  * The layer's contained within the group.
61
62
  */
62
- layers: Array<any>;
63
- props?: IGroupProps;
63
+ layers: Array<AnyLayer | Div>;
64
+ props?: IDivProps;
64
65
  /**
65
66
  * Constructs a new Group instance.
66
67
  * @param {string} [opts.id] - The unique identifier of the group.
@@ -92,10 +93,10 @@ export declare class Group implements IGroup {
92
93
  setZIndex(zIndex: number): this;
93
94
  /**
94
95
  * Adds components to the group.
95
- * @param {AnyLayer[]} [components] - The components to add to the group.
96
+ * @param {AnyLayer[] | Div[]} [components] - The components to add to the group.
96
97
  * @returns {this} The current instance for chaining.
97
98
  */
98
- add(...components: AnyLayer[]): this;
99
+ add(...components: Array<AnyLayer | Div>): this;
99
100
  /**
100
101
  * Removes a component from the group by its ID.
101
102
  * @param {string} [id] - The unique identifier of the component to remove.
@@ -110,23 +111,28 @@ export declare class Group implements IGroup {
110
111
  /**
111
112
  * Retrieves a component from the group by its ID.
112
113
  * @param {string} [id] - The unique identifier of the component to retrieve.
113
- * @returns {AnyLayer | undefined} The component with the specified ID, or undefined if not found.
114
+ * @returns {AnyLayer | Div | undefined} The component with the specified ID, or undefined if not found.
114
115
  */
115
- get(id: string): AnyLayer | undefined;
116
+ get(id: string): AnyLayer | Div | undefined;
116
117
  /**
117
118
  * Retrieves all components from the group.
118
- * @returns {AnyLayer[]} An array of all components in the group.
119
+ * @returns {AnyLayer[] | Div[]} An array of all components in the group.
119
120
  */
120
- getAll(): AnyLayer[];
121
+ getAll(): Array<AnyLayer | Div>;
121
122
  /**
122
123
  * Gets the number of components in the group.
123
124
  * @returns {number} The number of components in the group.
124
125
  */
125
126
  get length(): number;
127
+ /**
128
+ * Update state for all child layers (for animation support)
129
+ * @param {number} time - Current time in seconds
130
+ */
131
+ updateState(time: number): void;
126
132
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
127
133
  /**
128
134
  * Converts the group to a JSON representation.
129
- * @returns {IGroup} The JSON representation of the group.
135
+ * @returns {IDiv} The JSON representation of the group.
130
136
  */
131
- toJSON(): IGroup;
137
+ toJSON(): IDiv;
132
138
  }
@@ -1,34 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Group = void 0;
3
+ exports.Div = void 0;
4
4
  const types_1 = require("../../types");
5
5
  const utils_1 = require("../../utils/utils");
6
6
  const LazyUtil_1 = require("../../utils/LazyUtil");
7
7
  /**
8
8
  * Class representing a group of layer's.
9
9
  */
10
- class Group {
11
- /**
12
- * The unique identifier of the group.
13
- */
14
- id;
15
- /**
16
- * The type of the group, which is `Group`.
17
- */
18
- type = types_1.LayerType.Group;
19
- /**
20
- * The visibility of the group.
21
- */
22
- visible;
23
- /**
24
- * The z-index of the group, determining its stacking order.
25
- */
26
- zIndex;
27
- /**
28
- * The layer's contained within the group.
29
- */
30
- layers;
31
- props;
10
+ class Div {
32
11
  /**
33
12
  * Constructs a new Group instance.
34
13
  * @param {string} [opts.id] - The unique identifier of the group.
@@ -36,6 +15,10 @@ class Group {
36
15
  * @param {number} [opts.zIndex] - The z-index of the group.
37
16
  */
38
17
  constructor(opts) {
18
+ /**
19
+ * The type of the group, which is `Group`.
20
+ */
21
+ this.type = types_1.LayerType.Group;
39
22
  this.id = opts?.id || (0, utils_1.generateID)(types_1.LayerType.Group);
40
23
  this.visible = opts?.visible || true;
41
24
  this.zIndex = opts?.zIndex || 1;
@@ -71,12 +54,11 @@ class Group {
71
54
  }
72
55
  /**
73
56
  * Adds components to the group.
74
- * @param {AnyLayer[]} [components] - The components to add to the group.
57
+ * @param {AnyLayer[] | Div[]} [components] - The components to add to the group.
75
58
  * @returns {this} The current instance for chaining.
76
59
  */
77
60
  add(...components) {
78
- let layersArray = components.flat();
79
- layersArray = layersArray.filter(l => l !== undefined);
61
+ let layersArray = components.filter((l) => l !== undefined);
80
62
  layersArray = layersArray.sort((a, b) => a.zIndex - b.zIndex);
81
63
  this.layers.push(...layersArray);
82
64
  return this;
@@ -87,7 +69,7 @@ class Group {
87
69
  * @returns {this} The current instance for chaining.
88
70
  */
89
71
  remove(id) {
90
- this.layers = this.layers.filter(c => c.id !== id);
72
+ this.layers = this.layers.filter((c) => c.id !== id);
91
73
  return this;
92
74
  }
93
75
  /**
@@ -101,14 +83,14 @@ class Group {
101
83
  /**
102
84
  * Retrieves a component from the group by its ID.
103
85
  * @param {string} [id] - The unique identifier of the component to retrieve.
104
- * @returns {AnyLayer | undefined} The component with the specified ID, or undefined if not found.
86
+ * @returns {AnyLayer | Div | undefined} The component with the specified ID, or undefined if not found.
105
87
  */
106
88
  get(id) {
107
- return this.layers.find(c => c.id === id);
89
+ return this.layers.find((c) => c.id === id);
108
90
  }
109
91
  /**
110
92
  * Retrieves all components from the group.
111
- * @returns {AnyLayer[]} An array of all components in the group.
93
+ * @returns {AnyLayer[] | Div[]} An array of all components in the group.
112
94
  */
113
95
  getAll() {
114
96
  return this.layers;
@@ -120,25 +102,41 @@ class Group {
120
102
  get length() {
121
103
  return this.layers.length;
122
104
  }
105
+ /**
106
+ * Update state for all child layers (for animation support)
107
+ * @param {number} time - Current time in seconds
108
+ */
109
+ updateState(time) {
110
+ for (const layer of this.layers) {
111
+ if ("updateState" in layer && typeof layer.updateState === "function") {
112
+ layer.updateState(time);
113
+ }
114
+ }
115
+ }
123
116
  async draw(ctx, canvas, manager, debug) {
124
117
  for (const subLayer of this.layers) {
125
118
  if (debug)
126
- LazyUtil_1.LazyLog.log('info', `Rendering ${subLayer.id}...\nData:`, subLayer.toJSON());
119
+ LazyUtil_1.LazyLog.log("info", `Rendering ${subLayer.id}...\nData:`, subLayer.toJSON());
127
120
  if (subLayer.visible) {
128
- if ('globalComposite' in subLayer.props && subLayer.props.globalComposite) {
129
- ctx.globalCompositeOperation = subLayer.props.globalComposite;
121
+ if (subLayer instanceof Div) {
122
+ await subLayer.draw(ctx, canvas, manager, debug);
130
123
  }
131
124
  else {
132
- ctx.globalCompositeOperation = 'source-over';
125
+ if ("globalComposite" in subLayer.props && subLayer.props.globalComposite) {
126
+ ctx.globalCompositeOperation = subLayer.props.globalComposite;
127
+ }
128
+ else {
129
+ ctx.globalCompositeOperation = "source-over";
130
+ }
131
+ await subLayer.draw(ctx, canvas, manager, debug);
132
+ ctx.shadowColor = "transparent";
133
133
  }
134
- await subLayer.draw(ctx, canvas, manager, debug);
135
- ctx.shadowColor = 'transparent';
136
134
  }
137
135
  }
138
136
  }
139
137
  /**
140
138
  * Converts the group to a JSON representation.
141
- * @returns {IGroup} The JSON representation of the group.
139
+ * @returns {IDiv} The JSON representation of the group.
142
140
  */
143
141
  toJSON() {
144
142
  return {
@@ -146,8 +144,9 @@ class Group {
146
144
  type: this.type,
147
145
  visible: this.visible,
148
146
  zIndex: this.zIndex,
149
- layers: this.layers.map(c => c.toJSON())
147
+ // @ts-ignore
148
+ layers: this.layers.map((c) => c.toJSON()),
150
149
  };
151
150
  }
152
151
  }
153
- exports.Group = Group;
152
+ exports.Div = Div;
@@ -38,7 +38,7 @@ export interface IImageLayerProps extends IBaseLayerProps {
38
38
  /**
39
39
  * The radius of the image.
40
40
  */
41
- radius: {
41
+ radius?: {
42
42
  [corner in RadiusCorner]?: ScaleType;
43
43
  };
44
44
  };
@@ -7,14 +7,11 @@ const canvas_1 = require("@napi-rs/canvas");
7
7
  const utils_1 = require("../../utils/utils");
8
8
  const LazyUtil_1 = require("../../utils/LazyUtil");
9
9
  const helpers_1 = require("../helpers");
10
+ const DrawUtils_1 = require("../../utils/DrawUtils");
10
11
  /**
11
12
  * Class representing an Image Layer, extending the BaseLayer class.
12
13
  */
13
14
  class ImageLayer extends BaseLayer_1.BaseLayer {
14
- /**
15
- * The properties of the Image Layer.
16
- */
17
- props;
18
15
  /**
19
16
  * Constructs a new ImageLayer instance.
20
17
  * @param {IImageLayerProps} [props] - The properties of the Image Layer.
@@ -33,7 +30,7 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
33
30
  */
34
31
  setSrc(src) {
35
32
  if (!(0, utils_1.isImageUrlValid)(src))
36
- throw new LazyUtil_1.LazyError('The src of the image must be a valid URL');
33
+ throw new LazyUtil_1.LazyError("The src of the image must be a valid URL");
37
34
  this.props.src = src;
38
35
  return this;
39
36
  }
@@ -63,38 +60,42 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
63
60
  async draw(ctx, canvas, manager, debug) {
64
61
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
65
62
  const { xs, ys, w } = parcer.parseBatch({
66
- xs: { v: this.props.x },
67
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
68
- w: { v: this.props.size.width }
63
+ xs: { v: this.props.position.x },
64
+ ys: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
65
+ w: { v: this.props.size.width },
69
66
  });
70
67
  const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
71
68
  let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
72
69
  const rad = {};
73
- if (typeof this.props.size.radius === 'object' && this.props.size.radius !== helpers_1.Link) {
70
+ if (typeof this.props.size.radius === "object" && this.props.size.radius !== helpers_1.Link) {
74
71
  for (const corner in this.props.size.radius) {
75
72
  // @ts-ignore
76
- rad[corner] = parcer.parse(this.props.size.radius[corner], LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
73
+ rad[corner] = parcer.parse(
74
+ // @ts-ignore
75
+ this.props.size.radius[corner], LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
77
76
  }
78
77
  }
79
78
  if (debug)
80
- LazyUtil_1.LazyLog.log('none', `ImageLayer:`, { x, y, w, h, rad });
79
+ LazyUtil_1.LazyLog.log("none", `ImageLayer:`, { x, y, w, h, rad });
81
80
  ctx.save();
82
81
  let image = await (0, canvas_1.loadImage)(this.props.src);
83
82
  image.width = w;
84
83
  image.height = h;
85
84
  if (!image)
86
- throw new LazyUtil_1.LazyError('The image could not be loaded');
87
- (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
88
- (0, utils_1.drawShadow)(ctx, this.props.shadow);
89
- (0, utils_1.opacity)(ctx, this.props.opacity);
90
- (0, utils_1.filters)(ctx, this.props.filter);
85
+ throw new LazyUtil_1.LazyError("The image could not be loaded");
86
+ if (this.props.transform) {
87
+ (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
88
+ }
89
+ DrawUtils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
90
+ DrawUtils_1.DrawUtils.opacity(ctx, this.props.opacity);
91
+ DrawUtils_1.DrawUtils.filters(ctx, this.props.filter);
91
92
  if (Object.keys(rad).length > 0) {
92
93
  ctx.beginPath();
93
- ctx.moveTo(x + (w / 2), y);
94
- ctx.arcTo(x + w, y, x + w, y + (h / 2), rad.rightTop || rad.all || 0);
95
- ctx.arcTo(x + w, y + h, x + (w / 2), y + h, rad.rightBottom || rad.all || 0);
96
- ctx.arcTo(x, y + h, x, y + (h / 2), rad.leftBottom || rad.all || 0);
97
- ctx.arcTo(x, y, x + (w / 2), y, rad.leftTop || rad.all || 0);
94
+ ctx.moveTo(x + w / 2, y);
95
+ ctx.arcTo(x + w, y, x + w, y + h / 2, rad.rightTop || rad.all || 0);
96
+ ctx.arcTo(x + w, y + h, x + w / 2, y + h, rad.rightBottom || rad.all || 0);
97
+ ctx.arcTo(x, y + h, x, y + h / 2, rad.leftBottom || rad.all || 0);
98
+ ctx.arcTo(x, y, x + w / 2, y, rad.leftTop || rad.all || 0);
98
99
  ctx.closePath();
99
100
  ctx.clip();
100
101
  ctx.drawImage(image, x, y, w, h);
@@ -111,8 +112,8 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
111
112
  toJSON() {
112
113
  let data = super.toJSON();
113
114
  let copy = { ...this.props };
114
- for (const key of ['x', 'y', 'size.width', 'size.height', 'size.radius']) {
115
- if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
115
+ for (const key of ["x", "y", "size.width", "size.height", "size.radius"]) {
116
+ if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
116
117
  copy[key] = copy[key].toJSON();
117
118
  }
118
119
  }
@@ -126,12 +127,12 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
126
127
  validateProps(data) {
127
128
  return {
128
129
  ...super.validateProps(data),
129
- src: data.src || '',
130
+ src: data.src || "",
130
131
  size: {
131
132
  width: data.size?.width || 0,
132
133
  height: data.size?.height || 0,
133
- radius: data.size?.radius || { all: 0 }
134
- }
134
+ radius: data.size?.radius || { all: 0 },
135
+ },
135
136
  };
136
137
  }
137
138
  }
@@ -1,5 +1,5 @@
1
1
  import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
- import { ColorType, ScaleType, LayerType } from "../../types";
2
+ import { ColorType, ScaleType, LayerType, StrokeOptions } from "../../types";
3
3
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
4
  import { LayersManager } from "../managers";
5
5
  /**
@@ -19,18 +19,15 @@ export interface ILineLayer extends IBaseLayer {
19
19
  * Interface representing the properties of a Line Layer.
20
20
  */
21
21
  export interface ILineLayerProps extends IBaseLayerProps {
22
- /**
23
- * The end point of the line, including x and y coordinates.
24
- */
25
- endPoint: {
22
+ position: IBaseLayerProps["position"] & {
26
23
  /**
27
- * The x-coordinate of the end point.
24
+ * The x-coordinate of the end point of the line.
28
25
  */
29
- x: ScaleType;
26
+ endX: ScaleType;
30
27
  /**
31
- * The y-coordinate of the end point.
28
+ * The y-coordinate of the end point of the line.
32
29
  */
33
- y: ScaleType;
30
+ endY: ScaleType;
34
31
  };
35
32
  /**
36
33
  * Whether the layer is filled.
@@ -43,32 +40,7 @@ export interface ILineLayerProps extends IBaseLayerProps {
43
40
  /**
44
41
  * The stroke properties of the line.
45
42
  */
46
- stroke: {
47
- /**
48
- * The width of the stroke.
49
- */
50
- width: number;
51
- /**
52
- * The cap style of the stroke.
53
- */
54
- cap: CanvasLineCap;
55
- /**
56
- * The join style of the stroke.
57
- */
58
- join: CanvasLineJoin;
59
- /**
60
- * The dash offset of the stroke.
61
- */
62
- dashOffset: number;
63
- /**
64
- * The dash pattern of the stroke.
65
- */
66
- dash: number[];
67
- /**
68
- * The miter limit of the stroke.
69
- */
70
- miterLimit: number;
71
- };
43
+ stroke: StrokeOptions;
72
44
  }
73
45
  /**
74
46
  * Class representing a Line Layer, extending the BaseLayer class.
@@ -85,12 +57,14 @@ export declare class LineLayer extends BaseLayer<ILineLayerProps> {
85
57
  */
86
58
  constructor(props?: ILineLayerProps, misc?: IBaseLayerMisc);
87
59
  /**
88
- * Sets the end position of the line layer.
60
+ * Sets the position of the line layer.
89
61
  * @param {ScaleType} [x] - The x-coordinate of the end point.
90
62
  * @param {ScaleType} [y] - The y-coordinate of the end point.
63
+ * @param {ScaleType} [endX] - The x-coordinate of the end point.
64
+ * @param {ScaleType} [endY] - The y-coordinate of the end point.
91
65
  * @returns {this} The current instance for chaining.
92
66
  */
93
- setEndPosition(x: ScaleType, y: ScaleType): this;
67
+ setPosition(x: ScaleType, y: ScaleType, endX?: ScaleType, endY?: ScaleType): this;
94
68
  /**
95
69
  * Sets the color of the line layer.
96
70
  * @param {ColorType} [color] - The color of the layer.