@nmmty/lazycanvas 0.6.4 → 1.0.0-dev.3

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 +18 -39
  27. package/dist/structures/components/BezierLayer.js +85 -48
  28. package/dist/structures/components/{Group.d.ts → Div.d.ts} +26 -20
  29. package/dist/structures/components/{Group.js → Div.js} +39 -40
  30. package/dist/structures/components/ImageLayer.d.ts +2 -2
  31. package/dist/structures/components/ImageLayer.js +25 -26
  32. package/dist/structures/components/LineLayer.d.ts +13 -39
  33. package/dist/structures/components/LineLayer.js +44 -44
  34. package/dist/structures/components/MorphLayer.d.ts +4 -33
  35. package/dist/structures/components/MorphLayer.js +33 -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 +95 -0
  39. package/dist/structures/components/PolygonLayer.js +205 -0
  40. package/dist/structures/components/QuadraticLayer.d.ts +27 -44
  41. package/dist/structures/components/QuadraticLayer.js +87 -49
  42. package/dist/structures/components/TextLayer.d.ts +16 -45
  43. package/dist/structures/components/TextLayer.js +66 -68
  44. package/dist/structures/components/index.d.ts +10 -10
  45. package/dist/structures/components/index.js +2 -2
  46. package/dist/structures/helpers/Exporter.d.ts +13 -4
  47. package/dist/structures/helpers/Exporter.js +79 -42
  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 -40
  55. package/dist/structures/helpers/readers/YAMLReader.js +5 -5
  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 +4 -3
  64. package/dist/types/enum.js +3 -2
  65. package/dist/types/index.d.ts +1 -1
  66. package/dist/utils/APNGEncoder.d.ts +67 -0
  67. package/dist/utils/APNGEncoder.js +205 -0
  68. package/dist/utils/DrawUtils.d.ts +9 -0
  69. package/dist/utils/DrawUtils.js +42 -0
  70. package/dist/utils/LazyUtil.js +1 -2
  71. package/dist/utils/utils.d.ts +5 -9
  72. package/dist/utils/utils.js +148 -77
  73. package/package.json +62 -59
  74. package/dist/structures/components/ClearLayer.d.ts +0 -147
  75. package/dist/structures/components/ClearLayer.js +0 -158
  76. package/dist/structures/managers/AnimationManager.d.ts +0 -120
  77. package/dist/structures/managers/AnimationManager.js +0 -99
  78. package/dist/structures/managers/PluginManager.d.ts +0 -230
  79. package/dist/structures/managers/PluginManager.js +0 -182
  80. package/dist/types/types.d.ts +0 -105
@@ -1,5 +1,5 @@
1
1
  import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
- import { ColorType, Point, ScaleType, LayerType } from "../../types";
2
+ import { ColorType, Point, 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,20 @@ export interface IBezierLayer extends IBaseLayer {
19
19
  * Interface representing the properties of a Bezier layer.
20
20
  */
21
21
  export interface IBezierLayerProps extends IBaseLayerProps {
22
+ position: IBaseLayerProps["position"] & {
23
+ /**
24
+ * The end x of the Bézier curve.
25
+ */
26
+ endX: ScaleType;
27
+ /**
28
+ * The end y of the Bézier curve.
29
+ */
30
+ endY: ScaleType;
31
+ };
22
32
  /**
23
33
  * The control points of the Bézier curve.
24
34
  */
25
35
  controlPoints: Array<Point>;
26
- /**
27
- * The end point of the Bézier curve.
28
- */
29
- endPoint: Point;
30
- /**
31
- * Whether the layer is filled.
32
- */
33
- filled: boolean;
34
36
  /**
35
37
  * The fill style (color or pattern) of the layer.
36
38
  */
@@ -38,32 +40,7 @@ export interface IBezierLayerProps extends IBaseLayerProps {
38
40
  /**
39
41
  * The stroke properties of the Bézier curve.
40
42
  */
41
- stroke: {
42
- /**
43
- * The width of the stroke.
44
- */
45
- width: number;
46
- /**
47
- * The cap style of the stroke.
48
- */
49
- cap: CanvasLineCap;
50
- /**
51
- * The join style of the stroke.
52
- */
53
- join: CanvasLineJoin;
54
- /**
55
- * The dash offset of the stroke.
56
- */
57
- dashOffset: number;
58
- /**
59
- * The dash pattern of the stroke.
60
- */
61
- dash: number[];
62
- /**
63
- * The miter limit of the stroke.
64
- */
65
- miterLimit: number;
66
- };
43
+ stroke: StrokeOptions;
67
44
  }
68
45
  /**
69
46
  * Class representing a Bezier layer, extending the BaseLayer class.
@@ -90,12 +67,14 @@ export declare class BezierLayer extends BaseLayer<IBezierLayerProps> {
90
67
  y: ScaleType;
91
68
  }[]): this;
92
69
  /**
93
- * Sets the end position of the Bezier layer.
70
+ * Sets the position of the Bezier layer.
94
71
  * @param {ScaleType} [x] - The x-coordinate of the end point.
95
72
  * @param {ScaleType} [y] - The y-coordinate of the end point.
73
+ * @param {ScaleType} [endX] - The x-coordinate of the end point.
74
+ * @param {ScaleType} [endY] - The y-coordinate of the end point.
96
75
  * @returns {this} The current instance for chaining.
97
76
  */
98
- setEndPosition(x: ScaleType, y: ScaleType): this;
77
+ setPosition(x: ScaleType, y: ScaleType, endX?: ScaleType, endY?: ScaleType): this;
99
78
  /**
100
79
  * Sets the color of the Bezier layer.
101
80
  * @param {ColorType} [color] - The color of the layer.
@@ -118,7 +97,7 @@ export declare class BezierLayer extends BaseLayer<IBezierLayerProps> {
118
97
  * Calculates the bounding box of the Bezier layer.
119
98
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
120
99
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
121
- * @param {LayersManager} [manager] - The layers manager.
100
+ * @param {LayersManager} [manager] - The layer's manager.
122
101
  * @returns {Object} The bounding box details including max, min, center, width, and height.
123
102
  */
124
103
  getBoundingBox(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager): {
@@ -132,7 +111,7 @@ export declare class BezierLayer extends BaseLayer<IBezierLayerProps> {
132
111
  * Draws the Bezier layer on the canvas.
133
112
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
134
113
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
135
- * @param {LayersManager} [manager] - The layers manager.
114
+ * @param {LayersManager} [manager] - The layer's manager.
136
115
  * @param {boolean} [debug] - Whether to enable debug logging.
137
116
  */
138
117
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
@@ -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,
@@ -84,61 +83,92 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
84
83
  * Calculates the bounding box of the Bezier layer.
85
84
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
86
85
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
87
- * @param {LayersManager} [manager] - The layers manager.
86
+ * @param {LayersManager} [manager] - The layer's manager.
88
87
  * @returns {Object} The bounding box details including max, min, center, width, and height.
89
88
  */
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
  /**
106
110
  * Draws the Bezier layer on the canvas.
107
111
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
108
112
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
109
- * @param {LayersManager} [manager] - The layers manager.
113
+ * @param {LayersManager} [manager] - The layer's manager.
110
114
  * @param {boolean} [debug] - Whether to enable debug logging.
111
115
  */
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
  }
@@ -2,9 +2,9 @@ import { AnyGlobalCompositeOperation, AnyLayer, LayerType } from "../../types";
2
2
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
3
3
  import { LayersManager } from "../managers";
4
4
  /**
5
- * Interface representing a group of layers.
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
  */
@@ -22,24 +22,25 @@ export interface IGroup {
22
22
  */
23
23
  zIndex: number;
24
24
  /**
25
- * The layers contained within the group.
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
- * Class representing a group of layers.
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
  */
@@ -57,10 +58,10 @@ export declare class Group implements IGroup {
57
58
  */
58
59
  zIndex: number;
59
60
  /**
60
- * The layers contained within the group.
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
- * Class representing a group of layers.
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 layers 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
  };
@@ -78,7 +78,7 @@ export declare class ImageLayer extends BaseLayer<IImageLayerProps> {
78
78
  * Draws the Image Layer on the canvas.
79
79
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
80
80
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
81
- * @param {LayersManager} [manager] - The layers manager.
81
+ * @param {LayersManager} [manager] - The layer's manager.
82
82
  * @param {boolean} [debug] - Whether to enable debug logging.
83
83
  * @throws {LazyError} If the image could not be loaded.
84
84
  */