@nmmty/lazycanvas 0.6.0-dev.f33019 → 0.6.1

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 (58) hide show
  1. package/dist/helpers/Utlis.d.ts +28 -0
  2. package/dist/helpers/Utlis.js +78 -0
  3. package/dist/helpers/index.d.ts +3 -0
  4. package/dist/helpers/index.js +19 -0
  5. package/dist/index.d.ts +5 -10
  6. package/dist/index.js +5 -29
  7. package/dist/structures/LazyCanvas.d.ts +46 -13
  8. package/dist/structures/LazyCanvas.js +66 -22
  9. package/dist/structures/components/BaseLayer.d.ts +16 -16
  10. package/dist/structures/components/BaseLayer.js +17 -17
  11. package/dist/structures/components/BezierLayer.d.ts +21 -21
  12. package/dist/structures/components/BezierLayer.js +20 -20
  13. package/dist/structures/components/ClearLayer.d.ts +15 -15
  14. package/dist/structures/components/ClearLayer.js +14 -14
  15. package/dist/structures/components/Group.d.ts +10 -11
  16. package/dist/structures/components/Group.js +9 -10
  17. package/dist/structures/components/ImageLayer.d.ts +12 -14
  18. package/dist/structures/components/ImageLayer.js +11 -11
  19. package/dist/structures/components/LineLayer.d.ts +20 -20
  20. package/dist/structures/components/LineLayer.js +19 -19
  21. package/dist/structures/components/MorphLayer.d.ts +18 -24
  22. package/dist/structures/components/MorphLayer.js +18 -26
  23. package/dist/structures/components/Path2DLayer.d.ts +4 -78
  24. package/dist/structures/components/Path2DLayer.js +2 -116
  25. package/dist/structures/components/QuadraticLayer.d.ts +22 -22
  26. package/dist/structures/components/QuadraticLayer.js +21 -21
  27. package/dist/structures/components/TextLayer.d.ts +37 -43
  28. package/dist/structures/components/TextLayer.js +37 -45
  29. package/dist/structures/helpers/Exporter.d.ts +9 -11
  30. package/dist/structures/helpers/Exporter.js +49 -32
  31. package/dist/structures/helpers/Font.d.ts +4 -6
  32. package/dist/structures/helpers/Font.js +4 -4
  33. package/dist/structures/helpers/Gradient.d.ts +15 -10
  34. package/dist/structures/helpers/Gradient.js +14 -9
  35. package/dist/structures/helpers/Link.d.ts +5 -5
  36. package/dist/structures/helpers/Link.js +5 -5
  37. package/dist/structures/helpers/Pattern.d.ts +5 -5
  38. package/dist/structures/helpers/Pattern.js +5 -5
  39. package/dist/structures/helpers/index.d.ts +7 -7
  40. package/dist/structures/helpers/readers/JSONReader.d.ts +12 -12
  41. package/dist/structures/helpers/readers/JSONReader.js +29 -19
  42. package/dist/structures/helpers/readers/YAMLReader.d.ts +4 -4
  43. package/dist/structures/helpers/readers/YAMLReader.js +21 -11
  44. package/dist/structures/managers/AnimationManager.d.ts +11 -11
  45. package/dist/structures/managers/AnimationManager.js +11 -11
  46. package/dist/structures/managers/FontsManager.d.ts +14 -15
  47. package/dist/structures/managers/FontsManager.js +14 -15
  48. package/dist/structures/managers/LayersManager.d.ts +22 -12
  49. package/dist/structures/managers/LayersManager.js +27 -12
  50. package/dist/structures/managers/PluginManager.d.ts +230 -0
  51. package/dist/structures/managers/PluginManager.js +182 -0
  52. package/dist/structures/managers/RenderManager.d.ts +10 -12
  53. package/dist/structures/managers/RenderManager.js +31 -16
  54. package/dist/structures/managers/index.d.ts +5 -0
  55. package/dist/structures/managers/index.js +21 -0
  56. package/dist/utils/utils.d.ts +1 -1
  57. package/dist/utils/utils.js +15 -16
  58. package/package.json +59 -56
@@ -1,9 +1,14 @@
1
1
  import { AnyLayer } from "../../types";
2
2
  import { Group } from "../components";
3
+ import { LazyCanvas } from "../LazyCanvas";
3
4
  /**
4
5
  * Interface representing the LayersManager.
5
6
  */
6
7
  export interface ILayersManager {
8
+ /**
9
+ * The LazyCanvas instance associated with this manager.
10
+ */
11
+ lazyCanvas: LazyCanvas;
7
12
  /**
8
13
  * A map storing layers or groups with their IDs as keys.
9
14
  */
@@ -17,6 +22,10 @@ export interface ILayersManager {
17
22
  * Class representing a manager for handling layers and groups.
18
23
  */
19
24
  export declare class LayersManager implements ILayersManager {
25
+ /**
26
+ * The LazyCanvas instance associated with this manager.
27
+ */
28
+ lazyCanvas: LazyCanvas;
20
29
  /**
21
30
  * A map storing layers or groups with their IDs as keys.
22
31
  */
@@ -27,22 +36,23 @@ export declare class LayersManager implements ILayersManager {
27
36
  debug: boolean;
28
37
  /**
29
38
  * Constructs a new LayersManager instance.
30
- * @param opts {Object} - Optional settings for the LayersManager.
31
- * @param opts.debug {boolean} - Whether debugging is enabled.
39
+ * @param {LazyCanvas} [lazyCanvas] - The LazyCanvas instance to associate with this manager.
40
+ * @param {Object} [opts] - Optional settings for the LayersManager.
41
+ * @param {boolean} [opts.debug] - Whether debugging is enabled.
32
42
  */
33
- constructor(opts?: {
43
+ constructor(lazyCanvas: LazyCanvas, opts?: {
34
44
  debug?: boolean;
35
45
  });
36
46
  /**
37
47
  * Adds layers or groups to the map.
38
- * @param layers {Array<AnyLayer | Group>} - The layers or groups to add to the map.
48
+ * @param {Array<AnyLayer | Group>} [layers] - The layers or groups to add to the map.
39
49
  * @returns {this} The current instance for chaining.
40
50
  * @throws {LazyError} If a layer with the same ID already exists.
41
51
  */
42
52
  add(...layers: Array<AnyLayer | Group>): this;
43
53
  /**
44
54
  * Removes layers or groups from the map by their IDs.
45
- * @param ids {string[]} - The IDs of the layers or groups to remove.
55
+ * @param {string[]} [ids] - The IDs of the layers or groups to remove.
46
56
  * @returns {this} The current instance for chaining.
47
57
  */
48
58
  remove(...ids: string[]): this;
@@ -53,14 +63,14 @@ export declare class LayersManager implements ILayersManager {
53
63
  clear(): this;
54
64
  /**
55
65
  * Retrieves a layer or group from the map by its ID.
56
- * @param id {string} - The ID of the layer or group to retrieve.
57
- * @param cross {boolean} - Whether to search within groups for the ID.
66
+ * @param {string} [id] - The ID of the layer or group to retrieve.
67
+ * @param {boolean} [cross] - Whether to search within groups for the ID.
58
68
  * @returns {AnyLayer | Group | undefined} The retrieved layer or group, or undefined if not found.
59
69
  */
60
70
  get(id: string, cross?: boolean): AnyLayer | Group | undefined;
61
71
  /**
62
72
  * Checks if a layer or group exists in the map by its ID.
63
- * @param id {string} - The ID of the layer or group to check.
73
+ * @param {string} [id] - The ID of the layer or group to check.
64
74
  * @returns {boolean} True if the layer or group exists, false otherwise.
65
75
  */
66
76
  has(id: string): boolean;
@@ -86,7 +96,7 @@ export declare class LayersManager implements ILayersManager {
86
96
  entries(): IterableIterator<[string, AnyLayer | Group]>;
87
97
  /**
88
98
  * Executes a callback function for each layer or group in the map.
89
- * @param callbackfn {Function} - The callback function to execute.
99
+ * @param {Function} [callbackfn] - The callback function to execute.
90
100
  * @returns {this} The current instance for chaining.
91
101
  */
92
102
  forEach(callbackfn: (value: AnyLayer | Group, key: string, map: Map<string, AnyLayer | Group>) => void): this;
@@ -97,7 +107,7 @@ export declare class LayersManager implements ILayersManager {
97
107
  toJSON(): object;
98
108
  /**
99
109
  * Populates the map from a JSON object.
100
- * @param json {object} - The JSON object to populate the map from.
110
+ * @param {object} [json] - The JSON object to populate the map from.
101
111
  * @returns {this} The current instance for chaining.
102
112
  */
103
113
  fromJSON(json: object): this;
@@ -108,7 +118,7 @@ export declare class LayersManager implements ILayersManager {
108
118
  toArray(): Array<AnyLayer | Group>;
109
119
  /**
110
120
  * Populates the map from an array of layers and groups.
111
- * @param array {Array<AnyLayer | Group>} - The array of layers and groups to populate the map from.
121
+ * @param {Array<AnyLayer | Group>} [array] - The array of layers and groups to populate the map from.
112
122
  * @returns {this} The current instance for chaining.
113
123
  */
114
124
  fromArray(array: Array<AnyLayer | Group>): this;
@@ -119,7 +129,7 @@ export declare class LayersManager implements ILayersManager {
119
129
  sort(): void;
120
130
  /**
121
131
  * Searches for a layer or group by its ID, including within groups.
122
- * @param id {string} - The ID of the layer or group to search for.
132
+ * @param {string} [id] - The ID of the layer or group to search for.
123
133
  * @returns {AnyLayer | Group | undefined} The found layer or group, or undefined if not found.
124
134
  */
125
135
  private crossSearch;
@@ -7,6 +7,10 @@ const LazyUtil_1 = require("../../utils/LazyUtil");
7
7
  * Class representing a manager for handling layers and groups.
8
8
  */
9
9
  class LayersManager {
10
+ /**
11
+ * The LazyCanvas instance associated with this manager.
12
+ */
13
+ lazyCanvas;
10
14
  /**
11
15
  * A map storing layers or groups with their IDs as keys.
12
16
  */
@@ -17,16 +21,18 @@ class LayersManager {
17
21
  debug;
18
22
  /**
19
23
  * Constructs a new LayersManager instance.
20
- * @param opts {Object} - Optional settings for the LayersManager.
21
- * @param opts.debug {boolean} - Whether debugging is enabled.
24
+ * @param {LazyCanvas} [lazyCanvas] - The LazyCanvas instance to associate with this manager.
25
+ * @param {Object} [opts] - Optional settings for the LayersManager.
26
+ * @param {boolean} [opts.debug] - Whether debugging is enabled.
22
27
  */
23
- constructor(opts) {
28
+ constructor(lazyCanvas, opts) {
29
+ this.lazyCanvas = lazyCanvas;
24
30
  this.map = new Map();
25
31
  this.debug = opts?.debug || false;
26
32
  }
27
33
  /**
28
34
  * Adds layers or groups to the map.
29
- * @param layers {Array<AnyLayer | Group>} - The layers or groups to add to the map.
35
+ * @param {Array<AnyLayer | Group>} [layers] - The layers or groups to add to the map.
30
36
  * @returns {this} The current instance for chaining.
31
37
  * @throws {LazyError} If a layer with the same ID already exists.
32
38
  */
@@ -41,18 +47,27 @@ class LayersManager {
41
47
  if (this.map.has(layer.id))
42
48
  throw new LazyUtil_1.LazyError("Layer already exists");
43
49
  this.map.set(layer.id, layer);
50
+ // onLayerAdded hook
51
+ if (this.lazyCanvas && this.lazyCanvas.manager?.plugins) {
52
+ this.lazyCanvas.manager.plugins.executeHook('onLayerAdded', this.lazyCanvas, layer);
53
+ }
44
54
  }
45
55
  this.sort();
46
56
  return this;
47
57
  }
48
58
  /**
49
59
  * Removes layers or groups from the map by their IDs.
50
- * @param ids {string[]} - The IDs of the layers or groups to remove.
60
+ * @param {string[]} [ids] - The IDs of the layers or groups to remove.
51
61
  * @returns {this} The current instance for chaining.
52
62
  */
53
63
  remove(...ids) {
54
64
  for (const id of ids) {
65
+ const layer = this.map.get(id);
55
66
  this.map.delete(id);
67
+ // onLayerRemoved hook
68
+ if (this.lazyCanvas && this.lazyCanvas.manager?.plugins) {
69
+ this.lazyCanvas.manager.plugins.executeHook('onLayerRemoved', this.lazyCanvas, id);
70
+ }
56
71
  }
57
72
  return this;
58
73
  }
@@ -66,8 +81,8 @@ class LayersManager {
66
81
  }
67
82
  /**
68
83
  * Retrieves a layer or group from the map by its ID.
69
- * @param id {string} - The ID of the layer or group to retrieve.
70
- * @param cross {boolean} - Whether to search within groups for the ID.
84
+ * @param {string} [id] - The ID of the layer or group to retrieve.
85
+ * @param {boolean} [cross] - Whether to search within groups for the ID.
71
86
  * @returns {AnyLayer | Group | undefined} The retrieved layer or group, or undefined if not found.
72
87
  */
73
88
  get(id, cross = false) {
@@ -78,7 +93,7 @@ class LayersManager {
78
93
  }
79
94
  /**
80
95
  * Checks if a layer or group exists in the map by its ID.
81
- * @param id {string} - The ID of the layer or group to check.
96
+ * @param {string} [id] - The ID of the layer or group to check.
82
97
  * @returns {boolean} True if the layer or group exists, false otherwise.
83
98
  */
84
99
  has(id) {
@@ -114,7 +129,7 @@ class LayersManager {
114
129
  }
115
130
  /**
116
131
  * Executes a callback function for each layer or group in the map.
117
- * @param callbackfn {Function} - The callback function to execute.
132
+ * @param {Function} [callbackfn] - The callback function to execute.
118
133
  * @returns {this} The current instance for chaining.
119
134
  */
120
135
  forEach(callbackfn) {
@@ -130,7 +145,7 @@ class LayersManager {
130
145
  }
131
146
  /**
132
147
  * Populates the map from a JSON object.
133
- * @param json {object} - The JSON object to populate the map from.
148
+ * @param {object} [json] - The JSON object to populate the map from.
134
149
  * @returns {this} The current instance for chaining.
135
150
  */
136
151
  fromJSON(json) {
@@ -146,7 +161,7 @@ class LayersManager {
146
161
  }
147
162
  /**
148
163
  * Populates the map from an array of layers and groups.
149
- * @param array {Array<AnyLayer | Group>} - The array of layers and groups to populate the map from.
164
+ * @param {Array<AnyLayer | Group>} [array] - The array of layers and groups to populate the map from.
150
165
  * @returns {this} The current instance for chaining.
151
166
  */
152
167
  fromArray(array) {
@@ -162,7 +177,7 @@ class LayersManager {
162
177
  }
163
178
  /**
164
179
  * Searches for a layer or group by its ID, including within groups.
165
- * @param id {string} - The ID of the layer or group to search for.
180
+ * @param {string} [id] - The ID of the layer or group to search for.
166
181
  * @returns {AnyLayer | Group | undefined} The found layer or group, or undefined if not found.
167
182
  */
168
183
  crossSearch(id) {
@@ -0,0 +1,230 @@
1
+ import { LazyCanvas } from "../LazyCanvas";
2
+ import { AnyLayer } from "../../types";
3
+ import { Group } from "../components";
4
+ import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
5
+ /**
6
+ * Interface representing a LazyCanvas plugin.
7
+ */
8
+ export interface ILazyCanvasPlugin {
9
+ /**
10
+ * The unique name of the plugin.
11
+ */
12
+ name: string;
13
+ /**
14
+ * The version of the plugin.
15
+ */
16
+ version: string;
17
+ /**
18
+ * Optional description of the plugin.
19
+ */
20
+ description?: string;
21
+ /**
22
+ * Optional author of the plugin.
23
+ */
24
+ author?: string;
25
+ /**
26
+ * Optional dependencies on other plugins.
27
+ */
28
+ dependencies?: string[];
29
+ /**
30
+ * Optional configuration object for the plugin.
31
+ */
32
+ config?: any;
33
+ /**
34
+ * Optional private data storage for the plugin.
35
+ */
36
+ private?: any;
37
+ /**
38
+ * Method called when the plugin is installed.
39
+ * @param canvas - The LazyCanvas instance.
40
+ * @returns true if installation was successful, false otherwise.
41
+ */
42
+ install(canvas: LazyCanvas): boolean;
43
+ /**
44
+ * Optional method called when the plugin is uninstalled.
45
+ * @param canvas - The LazyCanvas instance.
46
+ * @returns true if uninstallation was successful, false otherwise.
47
+ */
48
+ uninstall?(canvas: LazyCanvas): boolean;
49
+ /**
50
+ * Optional hooks for lifecycle events.
51
+ */
52
+ hooks?: IPluginHooks;
53
+ }
54
+ /**
55
+ * Interface representing plugin hooks for lifecycle events.
56
+ */
57
+ export interface IPluginHooks {
58
+ /**
59
+ * Called before rendering starts.
60
+ */
61
+ beforeRender?(canvas: LazyCanvas): void;
62
+ /**
63
+ * Called after rendering completes.
64
+ */
65
+ afterRender?(canvas: LazyCanvas): void;
66
+ /**
67
+ * Called before export starts.
68
+ */
69
+ beforeExport?(canvas: LazyCanvas): void;
70
+ /**
71
+ * Called after export completes.
72
+ */
73
+ afterExport?(canvas: LazyCanvas, result: string | Buffer<ArrayBufferLike> | SKRSContext2D | Canvas | SvgCanvas): void;
74
+ /**
75
+ * Called when canvas is resized.
76
+ */
77
+ onResize?(canvas: LazyCanvas, ratio: number): void;
78
+ /**
79
+ * Called when a layer is added.
80
+ */
81
+ onLayerAdded?(canvas: LazyCanvas, layer: AnyLayer | Group): void;
82
+ /**
83
+ * Called when a layer is removed.
84
+ */
85
+ onLayerRemoved?(canvas: LazyCanvas, layerId: string): void;
86
+ /**
87
+ * Called when canvas is created/recreated.
88
+ */
89
+ onCanvasCreated?(canvas: LazyCanvas, width: number, height: number): void;
90
+ /**
91
+ * Called when a layer is modified.
92
+ */
93
+ onLayerModified?(canvas: LazyCanvas, layer: AnyLayer | Group): void;
94
+ /**
95
+ * Called when animation frame is processed.
96
+ */
97
+ onAnimationFrame?(canvas: LazyCanvas, frame: number): void;
98
+ /**
99
+ * Called when an error occurs.
100
+ */
101
+ onError?(canvas: LazyCanvas, error: Error): void;
102
+ }
103
+ /**
104
+ * Interface representing the PluginManager.
105
+ */
106
+ export interface IPluginManager {
107
+ /**
108
+ * A map storing installed plugins with their names as keys.
109
+ */
110
+ plugins: Map<string, ILazyCanvasPlugin>;
111
+ /**
112
+ * Whether debugging is enabled.
113
+ */
114
+ debug: boolean;
115
+ /**
116
+ * Reference to the LazyCanvas instance.
117
+ */
118
+ canvas: LazyCanvas;
119
+ /**
120
+ * Registers a plugin.
121
+ * @param plugin - The plugin to register.
122
+ */
123
+ register(plugin: ILazyCanvasPlugin): void;
124
+ /**
125
+ * Unregisters a plugin by name.
126
+ * @param pluginName - The name of the plugin to unregister.
127
+ * @throws {LazyError} If the plugin is not found or if other plugins depend on it.
128
+ */
129
+ unregister(pluginName: string): void;
130
+ /**
131
+ * Gets a plugin by name.
132
+ * @param pluginName - The name of the plugin.
133
+ */
134
+ get(pluginName: string): ILazyCanvasPlugin | undefined;
135
+ /**
136
+ * Lists all registered plugin names.
137
+ */
138
+ list(): string[];
139
+ /**
140
+ * Checks if a plugin is registered.
141
+ * @param pluginName - The name of the plugin.
142
+ */
143
+ has(pluginName: string): boolean;
144
+ /**
145
+ * Executes a hook for all plugins that implement it.
146
+ * @param hookName - The name of the hook to execute.
147
+ * @param args - Arguments to pass to the hook.
148
+ */
149
+ executeHook(hookName: keyof IPluginHooks, ...args: any[]): void;
150
+ }
151
+ /**
152
+ * Class representing a manager for handling plugins.
153
+ */
154
+ export declare class PluginManager implements IPluginManager {
155
+ /**
156
+ * A map storing installed plugins with their names as keys.
157
+ */
158
+ plugins: Map<string, ILazyCanvasPlugin>;
159
+ /**
160
+ * Whether debugging is enabled.
161
+ */
162
+ debug: boolean;
163
+ /**
164
+ * Reference to the LazyCanvas instance.
165
+ */
166
+ canvas: LazyCanvas;
167
+ /**
168
+ * Constructs a new PluginManager instance.
169
+ * @param {LazyCanvas} [canvas] - The LazyCanvas instance.
170
+ * @param {Object} [opts] - Optional settings for the PluginManager.
171
+ * @param {boolean} [opts.debug] - Whether debugging is enabled.
172
+ */
173
+ constructor(canvas: LazyCanvas, opts?: {
174
+ debug?: boolean;
175
+ });
176
+ /**
177
+ * Registers a plugin.
178
+ * @param {ILazyCanvasPlugin} [plugin] - The plugin to register.
179
+ * @throws {LazyError} If a plugin with the same name is already registered.
180
+ */
181
+ register(plugin: ILazyCanvasPlugin): void;
182
+ /**
183
+ * Unregisters a plugin by name.
184
+ * @param {string} [pluginName] - The name of the plugin to unregister.
185
+ * @throws {LazyError} If the plugin is not found or if other plugins depend on it.
186
+ */
187
+ unregister(pluginName: string): void;
188
+ /**
189
+ * Gets a plugin by name.
190
+ * @param {string} [pluginName] - The name of the plugin.
191
+ * @returns The plugin or undefined if not found.
192
+ */
193
+ get(pluginName: string): ILazyCanvasPlugin | undefined;
194
+ /**
195
+ * Lists all registered plugin names.
196
+ * @returns Array of plugin names.
197
+ */
198
+ list(): string[];
199
+ /**
200
+ * Checks if a plugin is registered.
201
+ * @param {string} [pluginName] - The name of the plugin.
202
+ * @returns True if the plugin is registered, false otherwise.
203
+ */
204
+ has(pluginName: string): boolean;
205
+ /**
206
+ * Executes a hook for all plugins that implement it.
207
+ * @param {keyof IPluginHooks} [hookName] - The name of the hook to execute.
208
+ * @param {any} [args] - Arguments to pass to the hook.
209
+ */
210
+ executeHook(hookName: keyof IPluginHooks, ...args: any[]): void;
211
+ /**
212
+ * Executes the onError hook for all plugins when an error occurs.
213
+ * @param error - The error that occurred.
214
+ */
215
+ private executeErrorHook;
216
+ /**
217
+ * Gets plugin information.
218
+ * @returns Array of plugin information objects.
219
+ */
220
+ getPluginInfo(): Array<{
221
+ name: string;
222
+ version: string;
223
+ description?: string;
224
+ dependencies?: string[];
225
+ }>;
226
+ /**
227
+ * Clears all plugins.
228
+ */
229
+ clear(): void;
230
+ }
@@ -0,0 +1,182 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PluginManager = void 0;
4
+ const LazyUtil_1 = require("../../utils/LazyUtil");
5
+ /**
6
+ * Class representing a manager for handling plugins.
7
+ */
8
+ class PluginManager {
9
+ /**
10
+ * A map storing installed plugins with their names as keys.
11
+ */
12
+ plugins;
13
+ /**
14
+ * Whether debugging is enabled.
15
+ */
16
+ debug;
17
+ /**
18
+ * Reference to the LazyCanvas instance.
19
+ */
20
+ canvas;
21
+ /**
22
+ * Constructs a new PluginManager instance.
23
+ * @param {LazyCanvas} [canvas] - The LazyCanvas instance.
24
+ * @param {Object} [opts] - Optional settings for the PluginManager.
25
+ * @param {boolean} [opts.debug] - Whether debugging is enabled.
26
+ */
27
+ constructor(canvas, opts) {
28
+ this.plugins = new Map();
29
+ this.debug = opts?.debug || false;
30
+ this.canvas = canvas;
31
+ }
32
+ /**
33
+ * Registers a plugin.
34
+ * @param {ILazyCanvasPlugin} [plugin] - The plugin to register.
35
+ * @throws {LazyError} If a plugin with the same name is already registered.
36
+ */
37
+ register(plugin) {
38
+ if (this.plugins.has(plugin.name)) {
39
+ throw new LazyUtil_1.LazyError(`Plugin '${plugin.name}' is already registered`);
40
+ }
41
+ // Check dependencies
42
+ if (plugin.dependencies) {
43
+ for (const dependency of plugin.dependencies) {
44
+ if (!this.plugins.has(dependency)) {
45
+ throw new LazyUtil_1.LazyError(`Plugin '${plugin.name}' requires dependency '${dependency}' which is not installed`);
46
+ }
47
+ }
48
+ }
49
+ try {
50
+ const result = plugin.install(this.canvas);
51
+ this.plugins.set(plugin.name, plugin);
52
+ if (this.debug) {
53
+ LazyUtil_1.LazyLog.log('info', `Plugin '${plugin.name}' v${plugin.version} registered successfully`);
54
+ }
55
+ }
56
+ catch (error) {
57
+ throw new LazyUtil_1.LazyError(`Failed to install plugin '${plugin.name}': ${error}`);
58
+ }
59
+ }
60
+ /**
61
+ * Unregisters a plugin by name.
62
+ * @param {string} [pluginName] - The name of the plugin to unregister.
63
+ * @throws {LazyError} If the plugin is not found or if other plugins depend on it.
64
+ */
65
+ unregister(pluginName) {
66
+ const plugin = this.plugins.get(pluginName);
67
+ if (!plugin) {
68
+ throw new LazyUtil_1.LazyError(`Plugin '${pluginName}' is not registered`);
69
+ }
70
+ // Check if other plugins depend on this one
71
+ this.plugins.forEach((p, name) => {
72
+ if (name !== pluginName && p.dependencies?.includes(pluginName)) {
73
+ throw new LazyUtil_1.LazyError(`Cannot unregister plugin '${pluginName}' because plugin '${name}' depends on it`);
74
+ }
75
+ });
76
+ try {
77
+ if (plugin.uninstall) {
78
+ plugin.uninstall(this.canvas);
79
+ }
80
+ this.plugins.delete(pluginName);
81
+ if (this.debug) {
82
+ LazyUtil_1.LazyLog.log('info', `Plugin '${pluginName}' unregistered successfully`);
83
+ }
84
+ }
85
+ catch (error) {
86
+ throw new LazyUtil_1.LazyError(`Failed to uninstall plugin '${pluginName}': ${error}`);
87
+ }
88
+ }
89
+ /**
90
+ * Gets a plugin by name.
91
+ * @param {string} [pluginName] - The name of the plugin.
92
+ * @returns The plugin or undefined if not found.
93
+ */
94
+ get(pluginName) {
95
+ return this.plugins.get(pluginName);
96
+ }
97
+ /**
98
+ * Lists all registered plugin names.
99
+ * @returns Array of plugin names.
100
+ */
101
+ list() {
102
+ return Array.from(this.plugins.keys());
103
+ }
104
+ /**
105
+ * Checks if a plugin is registered.
106
+ * @param {string} [pluginName] - The name of the plugin.
107
+ * @returns True if the plugin is registered, false otherwise.
108
+ */
109
+ has(pluginName) {
110
+ return this.plugins.has(pluginName);
111
+ }
112
+ /**
113
+ * Executes a hook for all plugins that implement it.
114
+ * @param {keyof IPluginHooks} [hookName] - The name of the hook to execute.
115
+ * @param {any} [args] - Arguments to pass to the hook.
116
+ */
117
+ executeHook(hookName, ...args) {
118
+ this.plugins.forEach(plugin => {
119
+ try {
120
+ const hook = plugin.hooks?.[hookName];
121
+ if (hook) {
122
+ hook(...args);
123
+ }
124
+ }
125
+ catch (error) {
126
+ if (this.debug) {
127
+ LazyUtil_1.LazyLog.log('error', `Error executing hook '${hookName}' for plugin '${plugin.name}': ${error}`);
128
+ }
129
+ // Execute onError hook for all plugins when a hook fails
130
+ this.executeErrorHook(error);
131
+ }
132
+ });
133
+ }
134
+ /**
135
+ * Executes the onError hook for all plugins when an error occurs.
136
+ * @param error - The error that occurred.
137
+ */
138
+ executeErrorHook(error) {
139
+ this.plugins.forEach(plugin => {
140
+ try {
141
+ const errorHook = plugin.hooks?.onError;
142
+ if (errorHook) {
143
+ errorHook(this.canvas, error);
144
+ }
145
+ }
146
+ catch (hookError) {
147
+ if (this.debug) {
148
+ LazyUtil_1.LazyLog.log('error', `Error in onError hook for plugin '${plugin.name}': ${hookError}`);
149
+ }
150
+ }
151
+ });
152
+ }
153
+ /**
154
+ * Gets plugin information.
155
+ * @returns Array of plugin information objects.
156
+ */
157
+ getPluginInfo() {
158
+ return Array.from(this.plugins.values()).map(plugin => ({
159
+ name: plugin.name,
160
+ version: plugin.version,
161
+ description: plugin.description,
162
+ dependencies: plugin.dependencies
163
+ }));
164
+ }
165
+ /**
166
+ * Clears all plugins.
167
+ */
168
+ clear() {
169
+ const pluginNames = this.list();
170
+ for (const name of pluginNames) {
171
+ try {
172
+ this.unregister(name);
173
+ }
174
+ catch (error) {
175
+ if (this.debug) {
176
+ LazyUtil_1.LazyLog.log('error', `Error unregistering plugin '${name}': ${error}`);
177
+ }
178
+ }
179
+ }
180
+ }
181
+ }
182
+ exports.PluginManager = PluginManager;
@@ -1,5 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import { AnyExport } from "../../types";
4
2
  import { LazyCanvas } from "../LazyCanvas";
5
3
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
@@ -30,31 +28,31 @@ export declare class RenderManager implements IRenderManager {
30
28
  debug: boolean;
31
29
  /**
32
30
  * Constructs a new RenderManager instance.
33
- * @param lazyCanvas {LazyCanvas} - The LazyCanvas instance to use for rendering.
34
- * @param opts {Object} - Optional settings for the RenderManager.
35
- * @param opts.debug {boolean} - Whether debugging is enabled.
31
+ * @param {LazyCanvas} [lazyCanvas] - The LazyCanvas instance to use for rendering.
32
+ * @param {Object} [opts] - Optional settings for the RenderManager.
33
+ * @param {boolean} [opts.debug] - Whether debugging is enabled.
36
34
  */
37
35
  constructor(lazyCanvas: LazyCanvas, opts?: {
38
36
  debug?: boolean;
39
37
  });
40
38
  /**
41
39
  * Merges multiple ImageData objects into a single ImageData object.
42
- * @param ctx {SKRSContext2D} - The canvas rendering context.
43
- * @param imageDataList {ImageData[]} - The list of ImageData objects to merge.
44
- * @param width {number} - The width of the resulting ImageData.
45
- * @param height {number} - The height of the resulting ImageData.
40
+ * @param {SKRSContext2D} [ctx] - The canvas rendering context.
41
+ * @param {ImageData[]} [imageDataList] - The list of ImageData objects to merge.
42
+ * @param {number} [width] - The width of the resulting ImageData.
43
+ * @param {number} [height] - The height of the resulting ImageData.
46
44
  * @returns {ImageData} The merged ImageData object.
47
45
  */
48
46
  private mergeImageData;
49
47
  /**
50
48
  * Renders a single layer or group of layers.
51
- * @param layer {AnyLayer | Group} - The layer or group to render.
49
+ * @param {AnyLayer | Group} [layer] - The layer or group to render.
52
50
  * @returns {Promise<SKRSContext2D>} The canvas rendering context after rendering.
53
51
  */
54
52
  private renderLayer;
55
53
  /**
56
54
  * Renders all layers statically and exports the result in the specified format.
57
- * @param exportType {AnyExport} - The export format (e.g., buffer, SVG, or context).
55
+ * @param {AnyExport} [exportType] - The export format (e.g., buffer, SVG, or context).
58
56
  * @returns {Promise<Buffer | SKRSContext2D | string>} The rendered output in the specified format.
59
57
  */
60
58
  private renderStatic;
@@ -65,7 +63,7 @@ export declare class RenderManager implements IRenderManager {
65
63
  private renderAnimation;
66
64
  /**
67
65
  * Renders all layers and exports the result in the specified format.
68
- * @param format {AnyExport} - The export format (e.g., buffer, context, SVG, or canvas).
66
+ * @param {AnyExport} [format] - The export format (e.g., buffer, context, SVG, or canvas).
69
67
  * @returns {Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>} The rendered output in the specified format.
70
68
  */
71
69
  render(format: AnyExport): Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>;