@nmmty/lazycanvas 0.6.5 → 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 +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 +24 -25
  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 +32 -46
  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 +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 +32 -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 +1 -2
  64. package/dist/types/enum.js +1 -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 +4 -7
  72. package/dist/utils/utils.js +133 -76
  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 -107
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jsxDEV = exports.jsxs = exports.jsx = void 0;
4
+ exports.createElement = createElement;
5
+ exports.Fragment = Fragment;
6
+ const components_1 = require("./structures/components");
7
+ const components_2 = require("./structures/components");
8
+ /**
9
+ * JSX createElement factory for LazyCanvas components
10
+ * Compatible with "jsx": "react" in tsconfig.json
11
+ */
12
+ function createElement(type, props, ...children) {
13
+ // Handle null props
14
+ const allProps = props || {};
15
+ // Flatten and filter children
16
+ const flatChildren = children
17
+ .flat(Infinity)
18
+ .filter((child) => child !== null && child !== undefined && child !== false);
19
+ // Extract special props
20
+ const { ref, children: propsChildren, ...restProps } = allProps;
21
+ // Merge children from props and arguments
22
+ const allChildren = [
23
+ ...(Array.isArray(propsChildren) ? propsChildren : propsChildren ? [propsChildren] : []),
24
+ ...flatChildren,
25
+ ].filter(Boolean);
26
+ let instance;
27
+ // Handle different component types
28
+ if (typeof type === "string") {
29
+ // Intrinsic elements (e.g., 'group', 'morph', etc.)
30
+ if (type === "group") {
31
+ instance = createGroupInstance(restProps, allChildren);
32
+ }
33
+ else {
34
+ throw new Error(`JSX: Unknown intrinsic element type: ${type}`);
35
+ }
36
+ }
37
+ else if (typeof type === "function") {
38
+ // Check if it's a class component (has prototype with methods)
39
+ if (type.prototype && (type.prototype.draw || type.prototype instanceof components_2.BaseLayer)) {
40
+ // Class component (Layer classes)
41
+ instance = createLayerInstance(type, restProps, allChildren);
42
+ }
43
+ else {
44
+ // Functional component
45
+ return type({ ...restProps, children: allChildren });
46
+ }
47
+ }
48
+ else {
49
+ throw new Error(`JSX: Invalid component type: ${typeof type}`);
50
+ }
51
+ // Handle ref
52
+ if (ref) {
53
+ if (typeof ref === "function") {
54
+ ref(instance);
55
+ }
56
+ else if (ref && typeof ref === "object" && "current" in ref) {
57
+ ref.current = instance;
58
+ }
59
+ }
60
+ return instance;
61
+ }
62
+ /**
63
+ * Create a Group instance
64
+ */
65
+ function createGroupInstance(props, children) {
66
+ const { id, visible, zIndex, ...otherProps } = props;
67
+ const group = new components_1.Div({
68
+ id,
69
+ visible,
70
+ zIndex,
71
+ });
72
+ // Add children to group
73
+ if (children.length > 0) {
74
+ group.add(...children);
75
+ }
76
+ return group;
77
+ }
78
+ /**
79
+ * Create a Layer instance (MorphLayer, TextLayer, etc.)
80
+ */
81
+ function createLayerInstance(LayerClass, props, children) {
82
+ // Extract misc props that go to the second constructor parameter
83
+ const { id, visible, zIndex, ...layerProps } = props;
84
+ const misc = {};
85
+ if (id !== undefined)
86
+ misc.id = id;
87
+ if (visible !== undefined)
88
+ misc.visible = visible;
89
+ if (zIndex !== undefined)
90
+ misc.zIndex = zIndex;
91
+ // Create instance
92
+ // Most layers have constructor(props, misc)
93
+ const instance = new LayerClass(layerProps, misc);
94
+ // Some layers might support children (like custom composite layers)
95
+ if (children.length > 0 && instance.add && typeof instance.add === "function") {
96
+ instance.add(...children);
97
+ }
98
+ return instance;
99
+ }
100
+ /**
101
+ * Fragment component for grouping elements without creating a Group layer
102
+ */
103
+ function Fragment(props) {
104
+ return props.children;
105
+ }
106
+ /**
107
+ * Export for compatibility with some JSX runtimes
108
+ */
109
+ exports.jsx = createElement;
110
+ exports.jsxs = createElement;
111
+ exports.jsxDEV = createElement;
@@ -1,7 +1,7 @@
1
1
  import { AnyExport, JSONLayer } from "../types";
2
2
  import { Canvas, SKRSContext2D, SvgCanvas, SvgExportFlag } from "@napi-rs/canvas";
3
- import { LayersManager, RenderManager, FontsManager, AnimationManager, IAnimationOptions, PluginManager, ILazyCanvasPlugin } from "./managers";
4
- import { Group } from "./components";
3
+ import { LayersManager, RenderManager, FontsManager } from "./managers";
4
+ import { IDiv } from "./components";
5
5
  /**
6
6
  * Interface representing the LazyCanvas structure.
7
7
  */
@@ -21,8 +21,6 @@ export interface ILazyCanvas {
21
21
  layers: LayersManager;
22
22
  render: RenderManager;
23
23
  fonts: FontsManager;
24
- animation: AnimationManager;
25
- plugins: PluginManager;
26
24
  };
27
25
  /**
28
26
  * The options for configuring the LazyCanvas instance.
@@ -62,14 +60,10 @@ export interface IOLazyCanvas {
62
60
  * The options for configuring the LazyCanvas instance.
63
61
  */
64
62
  options: ILazyCanvasOptions;
65
- /**
66
- * The animation options for the LazyCanvas instance.
67
- */
68
- animation: IAnimationOptions;
69
63
  /**
70
64
  * The layers to be added to the LazyCanvas instance.
71
65
  */
72
- layers: Array<JSONLayer | Group>;
66
+ layers: Array<JSONLayer | IDiv>;
73
67
  }
74
68
  /**
75
69
  * Class representing a LazyCanvas, which provides a structured way to manage canvas rendering.
@@ -84,15 +78,12 @@ export declare class LazyCanvas implements ILazyCanvas {
84
78
  */
85
79
  ctx: SKRSContext2D;
86
80
  /**
87
- * The manager object containing various managers for layers, rendering, fonts, and animation.
88
81
  * The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
89
82
  */
90
83
  manager: {
91
84
  layers: LayersManager;
92
85
  render: RenderManager;
93
86
  fonts: FontsManager;
94
- animation: AnimationManager;
95
- plugins: PluginManager;
96
87
  };
97
88
  /**
98
89
  * The options for configuring the LazyCanvas instance.
@@ -138,37 +129,4 @@ export declare class LazyCanvas implements ILazyCanvas {
138
129
  * @returns {this} The current instance for chaining.
139
130
  */
140
131
  create(width: number, height: number): this;
141
- /**
142
- * Installs a plugin to the canvas.
143
- * @param {ILazyCanvasPlugin} [plugin] - The plugin to install.
144
- * @returns {this} The current instance for chaining.
145
- */
146
- use(plugin: ILazyCanvasPlugin): this;
147
- /**
148
- * Removes a plugin from the canvas.
149
- * @param {string} [pluginName] - The name of the plugin to remove.
150
- * @returns {this} The current instance for chaining.
151
- */
152
- removePlugin(pluginName: string): this;
153
- /**
154
- * Gets a plugin by name.
155
- * @param {string} [pluginName] - The name of the plugin.
156
- * @returns {ILazyCanvasPlugin | undefined} The plugin or undefined if not found.
157
- */
158
- getPlugin(pluginName: string): ILazyCanvasPlugin | undefined;
159
- /**
160
- * Lists all installed plugins.
161
- * @returns {string[]} Array of plugin names.
162
- */
163
- listPlugins(): string[];
164
- /**
165
- * Gets information about all installed plugins.
166
- * @returns Array of plugin information objects.
167
- */
168
- getPluginsInfo(): Array<{
169
- name: string;
170
- version: string;
171
- description?: string;
172
- dependencies?: string[];
173
- }>;
174
132
  }
@@ -10,23 +10,6 @@ const utils_1 = require("../utils/utils");
10
10
  * Class representing a LazyCanvas, which provides a structured way to manage canvas rendering.
11
11
  */
12
12
  class LazyCanvas {
13
- /**
14
- * The canvas instance, which can be either a Canvas or SvgCanvas.
15
- */
16
- canvas;
17
- /**
18
- * The 2D rendering context of the canvas.
19
- */
20
- ctx;
21
- /**
22
- * The manager object containing various managers for layers, rendering, fonts, and animation.
23
- * The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
24
- */
25
- manager;
26
- /**
27
- * The options for configuring the LazyCanvas instance.
28
- */
29
- options;
30
13
  /**
31
14
  * Constructs a new LazyCanvas instance.
32
15
  * @param {Object} [opts] - Optional settings for the LazyCanvas instance.
@@ -35,13 +18,11 @@ class LazyCanvas {
35
18
  */
36
19
  constructor(opts) {
37
20
  this.canvas = new canvas_1.Canvas(0, 0);
38
- this.ctx = this.canvas.getContext('2d');
21
+ this.ctx = this.canvas.getContext("2d");
39
22
  this.manager = {
40
- layers: new managers_1.LayersManager(this, { debug: opts?.debug }),
23
+ layers: new managers_1.LayersManager({ debug: opts?.debug }),
41
24
  render: new managers_1.RenderManager(this, { debug: opts?.debug }),
42
25
  fonts: new managers_1.FontsManager({ debug: opts?.debug }),
43
- animation: new managers_1.AnimationManager({ debug: opts?.debug, settings: { options: opts?.settings?.animation } }),
44
- plugins: new managers_1.PluginManager(this, { debug: opts?.debug })
45
26
  };
46
27
  this.options = {
47
28
  width: 0,
@@ -49,10 +30,10 @@ class LazyCanvas {
49
30
  animated: false,
50
31
  exportType: types_1.Export.BUFFER,
51
32
  flag: canvas_1.SvgExportFlag.RelativePathEncoding,
52
- ...opts?.settings?.options
33
+ ...opts?.settings?.options,
53
34
  };
54
35
  if (opts?.debug)
55
- LazyUtil_1.LazyLog.log('info', 'LazyCanvas initialized with settings:', opts.settings);
36
+ LazyUtil_1.LazyLog.log("info", "LazyCanvas initialized with settings:", opts.settings);
56
37
  }
57
38
  /**
58
39
  * Sets the export type for the canvas.
@@ -64,13 +45,13 @@ class LazyCanvas {
64
45
  switch (type) {
65
46
  case types_1.Export.BUFFER:
66
47
  this.canvas = new canvas_1.Canvas(this.options.width, this.options.height);
67
- this.ctx = this.canvas.getContext('2d');
48
+ this.ctx = this.canvas.getContext("2d");
68
49
  break;
69
50
  case types_1.Export.CTX:
70
51
  break;
71
52
  case types_1.Export.SVG:
72
53
  this.canvas = new canvas_1.Canvas(this.options.width, this.options.height, this.options.flag || canvas_1.SvgExportFlag.RelativePathEncoding);
73
- this.ctx = this.canvas.getContext('2d');
54
+ this.ctx = this.canvas.getContext("2d");
74
55
  break;
75
56
  }
76
57
  return this;
@@ -83,7 +64,7 @@ class LazyCanvas {
83
64
  setSvgExportFlag(flag) {
84
65
  if (this.options.exportType === types_1.Export.SVG) {
85
66
  this.canvas = new canvas_1.Canvas(this.options.width, this.options.height, flag);
86
- this.ctx = this.canvas.getContext('2d');
67
+ this.ctx = this.canvas.getContext("2d");
87
68
  this.options.flag = flag;
88
69
  }
89
70
  return this;
@@ -103,7 +84,7 @@ class LazyCanvas {
103
84
  */
104
85
  resize(ratio) {
105
86
  if (this.options.width <= 0 || this.options.height <= 0) {
106
- throw new Error('Canvas dimensions are not set.');
87
+ throw new Error("Canvas dimensions are not set.");
107
88
  }
108
89
  this.options.width = (0, utils_1.resize)(this.options.width, ratio);
109
90
  this.options.height = (0, utils_1.resize)(this.options.height, ratio);
@@ -113,11 +94,9 @@ class LazyCanvas {
113
94
  else {
114
95
  this.canvas = new canvas_1.Canvas(this.options.width, this.options.height);
115
96
  }
116
- this.ctx = this.canvas.getContext('2d');
97
+ this.ctx = this.canvas.getContext("2d");
117
98
  const layers = (0, utils_1.resizeLayers)(this.manager.layers.toArray(), ratio);
118
99
  this.manager.layers.fromArray(layers);
119
- // Выполняем хук onResize для всех плагинов
120
- this.manager.plugins.executeHook('onResize', this, ratio);
121
100
  return this;
122
101
  }
123
102
  /**
@@ -135,51 +114,9 @@ class LazyCanvas {
135
114
  else {
136
115
  this.canvas = new canvas_1.Canvas(width, height);
137
116
  }
138
- this.ctx = this.canvas.getContext('2d');
139
- this.manager.layers = new managers_1.LayersManager(this, { debug: this.manager.layers.debug });
140
- // Выполняем хук onCanvasCreated для всех плагинов
141
- this.manager.plugins.executeHook('onCanvasCreated', this, width, height);
117
+ this.ctx = this.canvas.getContext("2d");
118
+ this.manager.layers = new managers_1.LayersManager({ debug: this.manager.layers.debug });
142
119
  return this;
143
120
  }
144
- /**
145
- * Installs a plugin to the canvas.
146
- * @param {ILazyCanvasPlugin} [plugin] - The plugin to install.
147
- * @returns {this} The current instance for chaining.
148
- */
149
- use(plugin) {
150
- this.manager.plugins.register(plugin);
151
- return this;
152
- }
153
- /**
154
- * Removes a plugin from the canvas.
155
- * @param {string} [pluginName] - The name of the plugin to remove.
156
- * @returns {this} The current instance for chaining.
157
- */
158
- removePlugin(pluginName) {
159
- this.manager.plugins.unregister(pluginName);
160
- return this;
161
- }
162
- /**
163
- * Gets a plugin by name.
164
- * @param {string} [pluginName] - The name of the plugin.
165
- * @returns {ILazyCanvasPlugin | undefined} The plugin or undefined if not found.
166
- */
167
- getPlugin(pluginName) {
168
- return this.manager.plugins.get(pluginName);
169
- }
170
- /**
171
- * Lists all installed plugins.
172
- * @returns {string[]} Array of plugin names.
173
- */
174
- listPlugins() {
175
- return this.manager.plugins.list();
176
- }
177
- /**
178
- * Gets information about all installed plugins.
179
- * @returns Array of plugin information objects.
180
- */
181
- getPluginsInfo() {
182
- return this.manager.plugins.getPluginInfo();
183
- }
184
121
  }
185
122
  exports.LazyCanvas = LazyCanvas;
@@ -1,4 +1,5 @@
1
1
  import { ScaleType, AnyCentring, AnyGlobalCompositeOperation, Transform, AnyFilter, LayerType } from "../../types";
2
+ import { Signal } from "../../core/Signal";
2
3
  /**
3
4
  * Interface representing the base structure of a layer.
4
5
  */
@@ -28,18 +29,20 @@ export interface IBaseLayer {
28
29
  * Interface representing the properties of a base layer.
29
30
  */
30
31
  export interface IBaseLayerProps {
31
- /**
32
- * The x-coordinate of the layer.
33
- */
34
- x: ScaleType;
35
- /**
36
- * The y-coordinate of the layer.
37
- */
38
- y: ScaleType;
32
+ position: {
33
+ /**
34
+ * The x-coordinate of the layer.
35
+ */
36
+ x: ScaleType;
37
+ /**
38
+ * The y-coordinate of the layer.
39
+ */
40
+ y: ScaleType;
41
+ };
39
42
  /**
40
43
  * The centring type of the layer.
41
44
  */
42
- centring: AnyCentring;
45
+ centring?: AnyCentring;
43
46
  /**
44
47
  * The filter effects applied to the layer.
45
48
  */
@@ -47,7 +50,7 @@ export interface IBaseLayerProps {
47
50
  /**
48
51
  * The opacity of the layer, ranging from 0 to 1.
49
52
  */
50
- opacity: number;
53
+ opacity?: number | Signal<number>;
51
54
  /**
52
55
  * The shadow properties of the layer.
53
56
  */
@@ -72,11 +75,11 @@ export interface IBaseLayerProps {
72
75
  /**
73
76
  * The transformation properties of the layer.
74
77
  */
75
- transform: Transform;
78
+ transform?: Transform;
76
79
  /**
77
80
  * The global composite operation applied to the layer.
78
81
  */
79
- globalComposite: AnyGlobalCompositeOperation;
82
+ globalComposite?: AnyGlobalCompositeOperation;
80
83
  }
81
84
  /**
82
85
  * Interface representing miscellaneous options for a base layer.
@@ -127,6 +130,7 @@ export declare class BaseLayer<T extends IBaseLayerProps> {
127
130
  * @type {T}
128
131
  */
129
132
  props: T;
133
+ _signals: Map<string, Signal<any>>;
130
134
  /**
131
135
  * Constructs a new `BaseLayer` instance.
132
136
  * @param {LayerType} [type] - The type of the layer.
@@ -134,6 +138,24 @@ export declare class BaseLayer<T extends IBaseLayerProps> {
134
138
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
135
139
  */
136
140
  constructor(type?: LayerType, props?: T, misc?: IBaseLayerMisc);
141
+ /**
142
+ * Recursively extract signals from props and nested objects
143
+ * @param obj - Object to extract signals from
144
+ * @param path - Current property path (e.g., "size.width")
145
+ */
146
+ private extractSignals;
147
+ /**
148
+ * Update layer properties from signals at given time
149
+ * @param time - Current time in seconds
150
+ */
151
+ updateState(time: number): void;
152
+ /**
153
+ * Set a nested property value using dot notation path
154
+ * @param obj - Object to set property on
155
+ * @param path - Property path (e.g., "size.width")
156
+ * @param value - Value to set
157
+ */
158
+ private setNestedProperty;
137
159
  /**
138
160
  * Sets the position of the layer in the 2D plane.
139
161
  * @param {ScaleType} [x] - The x-coordinate of the layer.
@@ -4,6 +4,8 @@ exports.BaseLayer = 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
+ const Signal_1 = require("../../core/Signal");
8
+ const helpers_1 = require("../helpers");
7
9
  /**
8
10
  * Represents a base layer with generic properties and methods for managing
9
11
  * its position, visibility, transformations, and other attributes.
@@ -11,31 +13,6 @@ const LazyUtil_1 = require("../../utils/LazyUtil");
11
13
  * @template T - A type extending `IBaseLayerProps` that defines the properties of the layer.
12
14
  */
13
15
  class BaseLayer {
14
- /**
15
- * The unique identifier of the layer.
16
- * @type {string}
17
- */
18
- id;
19
- /**
20
- * The type of the layer.
21
- * @type {LayerType}
22
- */
23
- type;
24
- /**
25
- * The z-index of the layer, determining its stacking order.
26
- * @type {number}
27
- */
28
- zIndex;
29
- /**
30
- * The visibility of the layer.
31
- * @type {boolean}
32
- */
33
- visible;
34
- /**
35
- * The properties of the layer, defined by the generic type `T`.
36
- * @type {T}
37
- */
38
- props;
39
16
  /**
40
17
  * Constructs a new `BaseLayer` instance.
41
18
  * @param {LayerType} [type] - The type of the layer.
@@ -43,13 +20,71 @@ class BaseLayer {
43
20
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
44
21
  */
45
22
  constructor(type, props, misc) {
23
+ this._signals = new Map();
46
24
  this.id = misc?.id || (0, utils_1.generateID)(type ? type : types_1.LayerType.Base);
47
25
  this.type = type ? type : types_1.LayerType.Base;
48
26
  this.zIndex = misc?.zIndex || 1;
49
- this.visible = misc?.visible || true;
27
+ this.visible = misc?.visible !== undefined ? misc.visible : true;
50
28
  this.props = props ? props : {};
29
+ this.extractSignals(this.props, "");
51
30
  this.props = this.validateProps(this.props);
52
31
  }
32
+ /**
33
+ * Recursively extract signals from props and nested objects
34
+ * @param obj - Object to extract signals from
35
+ * @param path - Current property path (e.g., "size.width")
36
+ */
37
+ extractSignals(obj, path) {
38
+ if (!obj || typeof obj !== "object")
39
+ return;
40
+ for (const key in obj) {
41
+ const value = obj[key];
42
+ const currentPath = path ? `${path}.${key}` : key;
43
+ if (value instanceof Signal_1.Signal) {
44
+ // Store signal with its path
45
+ this._signals.set(currentPath, value);
46
+ // Replace signal with its initial value (at time 0)
47
+ obj[key] = value.get(0);
48
+ }
49
+ else if (value &&
50
+ typeof value === "object" &&
51
+ !Array.isArray(value) &&
52
+ !(value instanceof helpers_1.Gradient) &&
53
+ !(value instanceof helpers_1.Pattern) &&
54
+ !(value instanceof helpers_1.Link)) {
55
+ // Recursively process nested objects (but not arrays or special types)
56
+ this.extractSignals(value, currentPath);
57
+ }
58
+ }
59
+ }
60
+ /**
61
+ * Update layer properties from signals at given time
62
+ * @param time - Current time in seconds
63
+ */
64
+ updateState(time) {
65
+ this._signals.forEach((signal, path) => {
66
+ // Just read the current value - signals are updated by the scheduler
67
+ const value = signal.value ? signal.value() : signal.get(time);
68
+ this.setNestedProperty(this.props, path, value);
69
+ });
70
+ }
71
+ /**
72
+ * Set a nested property value using dot notation path
73
+ * @param obj - Object to set property on
74
+ * @param path - Property path (e.g., "size.width")
75
+ * @param value - Value to set
76
+ */
77
+ setNestedProperty(obj, path, value) {
78
+ const keys = path.split(".");
79
+ let current = obj;
80
+ for (let i = 0; i < keys.length - 1; i++) {
81
+ if (!current[keys[i]] || typeof current[keys[i]] !== "object") {
82
+ current[keys[i]] = {};
83
+ }
84
+ current = current[keys[i]];
85
+ }
86
+ current[keys[keys.length - 1]] = value;
87
+ }
53
88
  /**
54
89
  * Sets the position of the layer in the 2D plane.
55
90
  * @param {ScaleType} [x] - The x-coordinate of the layer.
@@ -57,8 +92,7 @@ class BaseLayer {
57
92
  * @returns {this} The current instance for chaining.
58
93
  */
59
94
  setPosition(x, y) {
60
- this.props.x = x;
61
- this.props.y = y;
95
+ this.props.position = { x, y };
62
96
  return this;
63
97
  }
64
98
  /**
@@ -91,9 +125,9 @@ class BaseLayer {
91
125
  */
92
126
  setShadow(color, blur, offsetX, offsetY) {
93
127
  if (!color)
94
- throw new LazyUtil_1.LazyError('The color of the shadow must be provided');
128
+ throw new LazyUtil_1.LazyError("The color of the shadow must be provided");
95
129
  if (!(0, utils_1.isColor)(color))
96
- throw new LazyUtil_1.LazyError('The color of the shadow must be a valid color');
130
+ throw new LazyUtil_1.LazyError("The color of the shadow must be a valid color");
97
131
  this.props.shadow = {
98
132
  color: color,
99
133
  blur: blur || 0,
@@ -146,7 +180,7 @@ class BaseLayer {
146
180
  * @returns {this} The current instance for chaining.
147
181
  */
148
182
  setFilters(...filter) {
149
- this.props.filter = filter.join(' ');
183
+ this.props.filter = filter.join(" ");
150
184
  return this;
151
185
  }
152
186
  /**
@@ -201,13 +235,12 @@ class BaseLayer {
201
235
  validateProps(data) {
202
236
  return {
203
237
  ...data,
204
- x: data.x || 0,
205
- y: data.y || 0,
238
+ position: data.position || { x: 0, y: 0 },
206
239
  centring: data.centring || types_1.Centring.Center,
207
- filter: data.filter || '',
240
+ filter: data.filter || "",
208
241
  opacity: data.opacity || 1,
209
242
  transform: data.transform || {},
210
- globalComposite: data.globalComposite || 'source-over',
243
+ globalComposite: data.globalComposite || "source-over",
211
244
  };
212
245
  }
213
246
  }
@@ -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.