@nmmty/lazycanvas 0.6.4 → 1.0.0-dev.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReadMe.md +1 -1
- package/dist/core/Interpolation.d.ts +30 -0
- package/dist/core/Interpolation.js +200 -0
- package/dist/core/Scene.d.ts +94 -0
- package/dist/core/Scene.js +157 -0
- package/dist/core/Signal.d.ts +133 -0
- package/dist/core/Signal.js +255 -0
- package/dist/core/SignalUtils.d.ts +133 -0
- package/dist/core/SignalUtils.js +333 -0
- package/dist/core/ThreadScheduler.d.ts +38 -0
- package/dist/core/ThreadScheduler.js +74 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +21 -0
- package/dist/helpers/Filters.js +1 -1
- package/dist/helpers/FontsList.js +18 -18
- package/dist/helpers/Utlis.d.ts +3 -3
- package/dist/helpers/Utlis.js +25 -36
- package/dist/helpers/index.d.ts +3 -3
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/jsx-runtime.d.ts +17 -0
- package/dist/jsx-runtime.js +111 -0
- package/dist/structures/LazyCanvas.d.ts +10 -48
- package/dist/structures/LazyCanvas.js +17 -78
- package/dist/structures/components/BaseLayer.d.ts +78 -32
- package/dist/structures/components/BaseLayer.js +106 -37
- package/dist/structures/components/BezierLayer.d.ts +27 -40
- package/dist/structures/components/BezierLayer.js +90 -55
- package/dist/structures/components/{Group.d.ts → Div.d.ts} +41 -22
- package/dist/structures/components/Div.js +202 -0
- package/dist/structures/components/ImageLayer.d.ts +2 -2
- package/dist/structures/components/ImageLayer.js +29 -30
- package/dist/structures/components/LineLayer.d.ts +20 -38
- package/dist/structures/components/LineLayer.js +45 -47
- package/dist/structures/components/MorphLayer.d.ts +5 -34
- package/dist/structures/components/MorphLayer.js +38 -52
- package/dist/structures/components/Path2DLayer.d.ts +7 -35
- package/dist/structures/components/Path2DLayer.js +32 -41
- package/dist/structures/components/PolygonLayer.d.ts +95 -0
- package/dist/structures/components/PolygonLayer.js +203 -0
- package/dist/structures/components/QuadraticLayer.d.ts +36 -45
- package/dist/structures/components/QuadraticLayer.js +90 -54
- package/dist/structures/components/TextLayer.d.ts +17 -46
- package/dist/structures/components/TextLayer.js +94 -77
- package/dist/structures/components/index.d.ts +10 -10
- package/dist/structures/components/index.js +2 -2
- package/dist/structures/helpers/Exporter.d.ts +13 -4
- package/dist/structures/helpers/Exporter.js +82 -46
- package/dist/structures/helpers/Font.js +1 -17
- package/dist/structures/helpers/Gradient.js +35 -49
- package/dist/structures/helpers/Link.js +2 -14
- package/dist/structures/helpers/Pattern.js +10 -18
- package/dist/structures/helpers/index.d.ts +7 -7
- package/dist/structures/helpers/readers/JSONReader.d.ts +4 -4
- package/dist/structures/helpers/readers/JSONReader.js +46 -48
- package/dist/structures/helpers/readers/YAMLReader.js +11 -11
- package/dist/structures/managers/FontsManager.js +9 -18
- package/dist/structures/managers/LayersManager.d.ts +18 -28
- package/dist/structures/managers/LayersManager.js +14 -36
- package/dist/structures/managers/LayoutManager.d.ts +23 -0
- package/dist/structures/managers/LayoutManager.js +409 -0
- package/dist/structures/managers/index.d.ts +3 -5
- package/dist/structures/managers/index.js +1 -3
- package/dist/structures/managers/{RenderManager.d.ts → piplines/ClassicRenderPipeline.d.ts} +4 -30
- package/dist/structures/managers/piplines/ClassicRenderPipeline.js +90 -0
- package/dist/structures/managers/piplines/ModernRenderPipeline.d.ts +44 -0
- package/dist/structures/managers/piplines/ModernRenderPipeline.js +123 -0
- package/dist/structures/managers/piplines/index.d.ts +24 -0
- package/dist/structures/managers/piplines/index.js +18 -0
- package/dist/types/enum.d.ts +4 -3
- package/dist/types/enum.js +3 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +257 -105
- package/dist/utils/APNGEncoder.d.ts +67 -0
- package/dist/utils/APNGEncoder.js +205 -0
- package/dist/utils/DrawUtils.d.ts +9 -0
- package/dist/utils/DrawUtils.js +42 -0
- package/dist/utils/LazyUtil.js +1 -2
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/utils.d.ts +5 -9
- package/dist/utils/utils.js +154 -78
- package/package.json +61 -59
- package/dist/structures/components/ClearLayer.d.ts +0 -147
- package/dist/structures/components/ClearLayer.js +0 -158
- package/dist/structures/components/Group.js +0 -153
- package/dist/structures/managers/AnimationManager.d.ts +0 -120
- package/dist/structures/managers/AnimationManager.js +0 -99
- package/dist/structures/managers/PluginManager.d.ts +0 -230
- package/dist/structures/managers/PluginManager.js +0 -182
- package/dist/structures/managers/RenderManager.js +0 -183
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export * from "./structures/LazyCanvas";
|
|
2
2
|
export * from "./structures/managers";
|
|
3
3
|
export * from "./structures/components";
|
|
4
|
-
export * from "./types";
|
|
5
4
|
export * from "./structures/helpers";
|
|
5
|
+
export * from "./types";
|
|
6
6
|
export * from "./helpers";
|
|
7
|
+
export * from "./core";
|
|
8
|
+
export * from "./utils";
|
|
9
|
+
export * from "./jsx-runtime";
|
package/dist/index.js
CHANGED
|
@@ -17,6 +17,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
__exportStar(require("./structures/LazyCanvas"), exports);
|
|
18
18
|
__exportStar(require("./structures/managers"), exports);
|
|
19
19
|
__exportStar(require("./structures/components"), exports);
|
|
20
|
-
__exportStar(require("./types"), exports);
|
|
21
20
|
__exportStar(require("./structures/helpers"), exports);
|
|
21
|
+
__exportStar(require("./types"), exports);
|
|
22
22
|
__exportStar(require("./helpers"), exports);
|
|
23
|
+
__exportStar(require("./core"), exports);
|
|
24
|
+
__exportStar(require("./utils"), exports);
|
|
25
|
+
__exportStar(require("./jsx-runtime"), exports);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSX createElement factory for LazyCanvas components
|
|
3
|
+
* Compatible with "jsx": "react" in tsconfig.json
|
|
4
|
+
*/
|
|
5
|
+
export declare function createElement(type: any, props: any | null, ...children: any[]): any;
|
|
6
|
+
/**
|
|
7
|
+
* Fragment component for grouping elements without creating a Group layer
|
|
8
|
+
*/
|
|
9
|
+
export declare function Fragment(props: {
|
|
10
|
+
children: any[];
|
|
11
|
+
}): any[];
|
|
12
|
+
/**
|
|
13
|
+
* Export for compatibility with some JSX runtimes
|
|
14
|
+
*/
|
|
15
|
+
export declare const jsx: typeof createElement;
|
|
16
|
+
export declare const jsxs: typeof createElement;
|
|
17
|
+
export declare const jsxDEV: typeof createElement;
|
|
@@ -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(otherProps, {
|
|
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,8 @@
|
|
|
1
1
|
import { AnyExport, JSONLayer } from "../types";
|
|
2
2
|
import { Canvas, SKRSContext2D, SvgCanvas, SvgExportFlag } from "@napi-rs/canvas";
|
|
3
|
-
import { LayersManager,
|
|
4
|
-
import {
|
|
3
|
+
import { LayersManager, IRenderManager, FontsManager, RenderManagerConstructor } from "./managers";
|
|
4
|
+
import { LayoutManager } from "./managers/LayoutManager";
|
|
5
|
+
import { IDiv } from "./components";
|
|
5
6
|
/**
|
|
6
7
|
* Interface representing the LazyCanvas structure.
|
|
7
8
|
*/
|
|
@@ -19,10 +20,9 @@ export interface ILazyCanvas {
|
|
|
19
20
|
*/
|
|
20
21
|
manager: {
|
|
21
22
|
layers: LayersManager;
|
|
22
|
-
render:
|
|
23
|
+
render: IRenderManager;
|
|
23
24
|
fonts: FontsManager;
|
|
24
|
-
|
|
25
|
-
plugins: PluginManager;
|
|
25
|
+
layout: LayoutManager;
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
28
|
* The options for configuring the LazyCanvas instance.
|
|
@@ -62,14 +62,10 @@ export interface IOLazyCanvas {
|
|
|
62
62
|
* The options for configuring the LazyCanvas instance.
|
|
63
63
|
*/
|
|
64
64
|
options: ILazyCanvasOptions;
|
|
65
|
-
/**
|
|
66
|
-
* The animation options for the LazyCanvas instance.
|
|
67
|
-
*/
|
|
68
|
-
animation: IAnimationOptions;
|
|
69
65
|
/**
|
|
70
66
|
* The layers to be added to the LazyCanvas instance.
|
|
71
67
|
*/
|
|
72
|
-
layers: Array<JSONLayer |
|
|
68
|
+
layers: Array<JSONLayer | IDiv>;
|
|
73
69
|
}
|
|
74
70
|
/**
|
|
75
71
|
* Class representing a LazyCanvas, which provides a structured way to manage canvas rendering.
|
|
@@ -84,15 +80,13 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
84
80
|
*/
|
|
85
81
|
ctx: SKRSContext2D;
|
|
86
82
|
/**
|
|
87
|
-
* The manager object containing various managers for layers, rendering, fonts, and animation.
|
|
88
83
|
* The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
|
|
89
84
|
*/
|
|
90
85
|
manager: {
|
|
91
86
|
layers: LayersManager;
|
|
92
|
-
render:
|
|
87
|
+
render: IRenderManager;
|
|
93
88
|
fonts: FontsManager;
|
|
94
|
-
|
|
95
|
-
plugins: PluginManager;
|
|
89
|
+
layout: LayoutManager;
|
|
96
90
|
};
|
|
97
91
|
/**
|
|
98
92
|
* The options for configuring the LazyCanvas instance.
|
|
@@ -100,11 +94,12 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
100
94
|
options: ILazyCanvasOptions;
|
|
101
95
|
/**
|
|
102
96
|
* Constructs a new LazyCanvas instance.
|
|
97
|
+
* @param {RenderManagerConstructor} [renderPipline] - The constructor for the render pipeline to be used (default is ClassicRenderPipeline).
|
|
103
98
|
* @param {Object} [opts] - Optional settings for the LazyCanvas instance.
|
|
104
99
|
* @param {boolean} [opts.debug] - Whether debugging is enabled.
|
|
105
100
|
* @param {IOLazyCanvas} [opts.settings] - The input settings for the LazyCanvas instance.
|
|
106
101
|
*/
|
|
107
|
-
constructor(opts?: {
|
|
102
|
+
constructor(renderPipline?: RenderManagerConstructor, opts?: {
|
|
108
103
|
debug?: boolean;
|
|
109
104
|
settings?: IOLazyCanvas;
|
|
110
105
|
});
|
|
@@ -138,37 +133,4 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
138
133
|
* @returns {this} The current instance for chaining.
|
|
139
134
|
*/
|
|
140
135
|
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
136
|
}
|
|
@@ -4,44 +4,27 @@ exports.LazyCanvas = void 0;
|
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const canvas_1 = require("@napi-rs/canvas");
|
|
6
6
|
const managers_1 = require("./managers");
|
|
7
|
-
const
|
|
8
|
-
const utils_1 = require("../utils
|
|
7
|
+
const LayoutManager_1 = require("./managers/LayoutManager");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
9
|
/**
|
|
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.
|
|
15
|
+
* @param {RenderManagerConstructor} [renderPipline] - The constructor for the render pipeline to be used (default is ClassicRenderPipeline).
|
|
32
16
|
* @param {Object} [opts] - Optional settings for the LazyCanvas instance.
|
|
33
17
|
* @param {boolean} [opts.debug] - Whether debugging is enabled.
|
|
34
18
|
* @param {IOLazyCanvas} [opts.settings] - The input settings for the LazyCanvas instance.
|
|
35
19
|
*/
|
|
36
|
-
constructor(opts) {
|
|
20
|
+
constructor(renderPipline = managers_1.ClassicRenderPipeline, opts) {
|
|
37
21
|
this.canvas = new canvas_1.Canvas(0, 0);
|
|
38
|
-
this.ctx = this.canvas.getContext(
|
|
22
|
+
this.ctx = this.canvas.getContext("2d");
|
|
39
23
|
this.manager = {
|
|
40
|
-
layers: new managers_1.LayersManager(
|
|
41
|
-
render: new
|
|
24
|
+
layers: new managers_1.LayersManager({ debug: opts?.debug }),
|
|
25
|
+
render: new renderPipline(this, { debug: opts?.debug }),
|
|
42
26
|
fonts: new managers_1.FontsManager({ debug: opts?.debug }),
|
|
43
|
-
|
|
44
|
-
plugins: new managers_1.PluginManager(this, { debug: opts?.debug })
|
|
27
|
+
layout: new LayoutManager_1.LayoutManager({ debug: opts?.debug }),
|
|
45
28
|
};
|
|
46
29
|
this.options = {
|
|
47
30
|
width: 0,
|
|
@@ -49,10 +32,10 @@ class LazyCanvas {
|
|
|
49
32
|
animated: false,
|
|
50
33
|
exportType: types_1.Export.BUFFER,
|
|
51
34
|
flag: canvas_1.SvgExportFlag.RelativePathEncoding,
|
|
52
|
-
...opts?.settings?.options
|
|
35
|
+
...opts?.settings?.options,
|
|
53
36
|
};
|
|
54
37
|
if (opts?.debug)
|
|
55
|
-
|
|
38
|
+
utils_1.LazyLog.log("info", "LazyCanvas initialized with settings:", opts.settings);
|
|
56
39
|
}
|
|
57
40
|
/**
|
|
58
41
|
* Sets the export type for the canvas.
|
|
@@ -64,13 +47,13 @@ class LazyCanvas {
|
|
|
64
47
|
switch (type) {
|
|
65
48
|
case types_1.Export.BUFFER:
|
|
66
49
|
this.canvas = new canvas_1.Canvas(this.options.width, this.options.height);
|
|
67
|
-
this.ctx = this.canvas.getContext(
|
|
50
|
+
this.ctx = this.canvas.getContext("2d");
|
|
68
51
|
break;
|
|
69
52
|
case types_1.Export.CTX:
|
|
70
53
|
break;
|
|
71
54
|
case types_1.Export.SVG:
|
|
72
55
|
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(
|
|
56
|
+
this.ctx = this.canvas.getContext("2d");
|
|
74
57
|
break;
|
|
75
58
|
}
|
|
76
59
|
return this;
|
|
@@ -83,7 +66,7 @@ class LazyCanvas {
|
|
|
83
66
|
setSvgExportFlag(flag) {
|
|
84
67
|
if (this.options.exportType === types_1.Export.SVG) {
|
|
85
68
|
this.canvas = new canvas_1.Canvas(this.options.width, this.options.height, flag);
|
|
86
|
-
this.ctx = this.canvas.getContext(
|
|
69
|
+
this.ctx = this.canvas.getContext("2d");
|
|
87
70
|
this.options.flag = flag;
|
|
88
71
|
}
|
|
89
72
|
return this;
|
|
@@ -103,7 +86,7 @@ class LazyCanvas {
|
|
|
103
86
|
*/
|
|
104
87
|
resize(ratio) {
|
|
105
88
|
if (this.options.width <= 0 || this.options.height <= 0) {
|
|
106
|
-
throw new Error(
|
|
89
|
+
throw new Error("Canvas dimensions are not set.");
|
|
107
90
|
}
|
|
108
91
|
this.options.width = (0, utils_1.resize)(this.options.width, ratio);
|
|
109
92
|
this.options.height = (0, utils_1.resize)(this.options.height, ratio);
|
|
@@ -113,11 +96,9 @@ class LazyCanvas {
|
|
|
113
96
|
else {
|
|
114
97
|
this.canvas = new canvas_1.Canvas(this.options.width, this.options.height);
|
|
115
98
|
}
|
|
116
|
-
this.ctx = this.canvas.getContext(
|
|
99
|
+
this.ctx = this.canvas.getContext("2d");
|
|
117
100
|
const layers = (0, utils_1.resizeLayers)(this.manager.layers.toArray(), ratio);
|
|
118
101
|
this.manager.layers.fromArray(layers);
|
|
119
|
-
// Выполняем хук onResize для всех плагинов
|
|
120
|
-
this.manager.plugins.executeHook('onResize', this, ratio);
|
|
121
102
|
return this;
|
|
122
103
|
}
|
|
123
104
|
/**
|
|
@@ -135,51 +116,9 @@ class LazyCanvas {
|
|
|
135
116
|
else {
|
|
136
117
|
this.canvas = new canvas_1.Canvas(width, height);
|
|
137
118
|
}
|
|
138
|
-
this.ctx = this.canvas.getContext(
|
|
139
|
-
this.manager.layers = new managers_1.LayersManager(
|
|
140
|
-
// Выполняем хук onCanvasCreated для всех плагинов
|
|
141
|
-
this.manager.plugins.executeHook('onCanvasCreated', this, width, height);
|
|
119
|
+
this.ctx = this.canvas.getContext("2d");
|
|
120
|
+
this.manager.layers = new managers_1.LayersManager({ debug: this.manager.layers.debug });
|
|
142
121
|
return this;
|
|
143
122
|
}
|
|
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
123
|
}
|
|
185
124
|
exports.LazyCanvas = LazyCanvas;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { ScaleType, AnyCentring, AnyGlobalCompositeOperation, Transform, AnyFilter, LayerType } from "../../types";
|
|
1
|
+
import { ScaleType, AnyCentring, AnyGlobalCompositeOperation, Transform, AnyFilter, LayerType, ILayoutProps, AnyLayer } from "../../types";
|
|
2
|
+
import { Signal } from "../../core/Signal";
|
|
3
|
+
import { Div } from "./Div";
|
|
2
4
|
/**
|
|
3
5
|
* Interface representing the base structure of a layer.
|
|
4
6
|
*/
|
|
@@ -7,6 +9,14 @@ export interface IBaseLayer {
|
|
|
7
9
|
* The unique identifier of the layer.
|
|
8
10
|
*/
|
|
9
11
|
id: string;
|
|
12
|
+
/**
|
|
13
|
+
* The parent of the layer.
|
|
14
|
+
*/
|
|
15
|
+
parent?: IBaseLayer | any | null;
|
|
16
|
+
/**
|
|
17
|
+
* The children of the layer.
|
|
18
|
+
*/
|
|
19
|
+
children?: Array<AnyLayer | Div>;
|
|
10
20
|
/**
|
|
11
21
|
* The type of the layer.
|
|
12
22
|
*/
|
|
@@ -29,17 +39,35 @@ export interface IBaseLayer {
|
|
|
29
39
|
*/
|
|
30
40
|
export interface IBaseLayerProps {
|
|
31
41
|
/**
|
|
32
|
-
* The
|
|
42
|
+
* The unique identifier of the layer (optional, for JSX support).
|
|
33
43
|
*/
|
|
34
|
-
|
|
44
|
+
id?: string;
|
|
35
45
|
/**
|
|
36
|
-
*
|
|
46
|
+
* Whether the layer is visible (optional, for JSX support).
|
|
37
47
|
*/
|
|
38
|
-
|
|
48
|
+
visible?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* The z-index of the layer (optional, for JSX support).
|
|
51
|
+
*/
|
|
52
|
+
zIndex?: number;
|
|
53
|
+
position?: {
|
|
54
|
+
/**
|
|
55
|
+
* The x-coordinate of the layer.
|
|
56
|
+
*/
|
|
57
|
+
x: ScaleType;
|
|
58
|
+
/**
|
|
59
|
+
* The y-coordinate of the layer.
|
|
60
|
+
*/
|
|
61
|
+
y: ScaleType;
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* The layout properties of the layer.
|
|
65
|
+
*/
|
|
66
|
+
layout?: ILayoutProps;
|
|
39
67
|
/**
|
|
40
68
|
* The centring type of the layer.
|
|
41
69
|
*/
|
|
42
|
-
centring
|
|
70
|
+
centring?: AnyCentring;
|
|
43
71
|
/**
|
|
44
72
|
* The filter effects applied to the layer.
|
|
45
73
|
*/
|
|
@@ -47,7 +75,7 @@ export interface IBaseLayerProps {
|
|
|
47
75
|
/**
|
|
48
76
|
* The opacity of the layer, ranging from 0 to 1.
|
|
49
77
|
*/
|
|
50
|
-
opacity
|
|
78
|
+
opacity?: number | Signal<number>;
|
|
51
79
|
/**
|
|
52
80
|
* The shadow properties of the layer.
|
|
53
81
|
*/
|
|
@@ -63,20 +91,20 @@ export interface IBaseLayerProps {
|
|
|
63
91
|
/**
|
|
64
92
|
* The horizontal offset of the shadow.
|
|
65
93
|
*/
|
|
66
|
-
offsetX
|
|
94
|
+
offsetX?: number;
|
|
67
95
|
/**
|
|
68
96
|
* The vertical offset of the shadow.
|
|
69
97
|
*/
|
|
70
|
-
offsetY
|
|
98
|
+
offsetY?: number;
|
|
71
99
|
};
|
|
72
100
|
/**
|
|
73
101
|
* The transformation properties of the layer.
|
|
74
102
|
*/
|
|
75
|
-
transform
|
|
103
|
+
transform?: Transform;
|
|
76
104
|
/**
|
|
77
105
|
* The global composite operation applied to the layer.
|
|
78
106
|
*/
|
|
79
|
-
globalComposite
|
|
107
|
+
globalComposite?: AnyGlobalCompositeOperation;
|
|
80
108
|
}
|
|
81
109
|
/**
|
|
82
110
|
* Interface representing miscellaneous options for a base layer.
|
|
@@ -101,39 +129,57 @@ export interface IBaseLayerMisc {
|
|
|
101
129
|
*
|
|
102
130
|
* @template T - A type extending `IBaseLayerProps` that defines the properties of the layer.
|
|
103
131
|
*/
|
|
104
|
-
export declare class BaseLayer<T extends IBaseLayerProps> {
|
|
132
|
+
export declare class BaseLayer<T extends IBaseLayerProps> implements IBaseLayer {
|
|
133
|
+
id: string;
|
|
134
|
+
type: LayerType;
|
|
135
|
+
zIndex: number;
|
|
136
|
+
visible: boolean;
|
|
137
|
+
props: T;
|
|
138
|
+
parent?: IBaseLayer | any | null;
|
|
139
|
+
children: Array<AnyLayer | Div>;
|
|
140
|
+
private _signals;
|
|
141
|
+
constructor(type: LayerType, props: T, misc?: IBaseLayerMisc);
|
|
105
142
|
/**
|
|
106
|
-
*
|
|
107
|
-
* @
|
|
143
|
+
* Adds components to the layer.
|
|
144
|
+
* @param {AnyLayer[] | Div[]} [components] - The components to add to the layer.
|
|
145
|
+
* @returns {this} The current instance for chaining.
|
|
108
146
|
*/
|
|
109
|
-
|
|
147
|
+
add(...components: Array<AnyLayer | Div>): this;
|
|
110
148
|
/**
|
|
111
|
-
*
|
|
112
|
-
* @
|
|
149
|
+
* Removes a component from the layer by its ID.
|
|
150
|
+
* @param {string} [id] - The unique identifier of the component to remove.
|
|
151
|
+
* @returns {this} The current instance for chaining.
|
|
113
152
|
*/
|
|
114
|
-
|
|
153
|
+
remove(id: string): this;
|
|
115
154
|
/**
|
|
116
|
-
*
|
|
117
|
-
* @
|
|
155
|
+
* Retrieves a component from the layer by its ID.
|
|
156
|
+
* @param {string} [id] - The unique identifier of the component to retrieve.
|
|
157
|
+
* @returns {AnyLayer | Div | undefined} The component with the specified ID, or undefined if not found.
|
|
118
158
|
*/
|
|
119
|
-
|
|
159
|
+
get(id: string): AnyLayer | Div | undefined;
|
|
120
160
|
/**
|
|
121
|
-
*
|
|
122
|
-
* @
|
|
161
|
+
* Retrieves all components from the layer.
|
|
162
|
+
* @returns {AnyLayer[] | Div[]} An array of all components in the layer.
|
|
123
163
|
*/
|
|
124
|
-
|
|
164
|
+
getAll(): Array<AnyLayer | Div>;
|
|
125
165
|
/**
|
|
126
|
-
*
|
|
127
|
-
* @
|
|
166
|
+
* Recursively extract signals from props and nested objects
|
|
167
|
+
* @param obj - Object to extract signals from
|
|
168
|
+
* @param path - Current property path (e.g., "size.width")
|
|
128
169
|
*/
|
|
129
|
-
|
|
170
|
+
private extractSignals;
|
|
171
|
+
/**
|
|
172
|
+
* Update layer properties from signals at given time
|
|
173
|
+
* @param time - Current time in seconds
|
|
174
|
+
*/
|
|
175
|
+
updateState(time: number): void;
|
|
130
176
|
/**
|
|
131
|
-
*
|
|
132
|
-
* @param
|
|
133
|
-
* @param
|
|
134
|
-
* @param
|
|
177
|
+
* Set a nested property value using dot notation path
|
|
178
|
+
* @param obj - Object to set property on
|
|
179
|
+
* @param path - Property path (e.g., "size.width")
|
|
180
|
+
* @param value - Value to set
|
|
135
181
|
*/
|
|
136
|
-
|
|
182
|
+
private setNestedProperty;
|
|
137
183
|
/**
|
|
138
184
|
* Sets the position of the layer in the 2D plane.
|
|
139
185
|
* @param {ScaleType} [x] - The x-coordinate of the layer.
|