@nmmty/lazycanvas 0.6.5 → 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 +25 -38
- package/dist/structures/components/BezierLayer.js +88 -53
- package/dist/structures/components/{Group.d.ts → Div.d.ts} +37 -18
- package/dist/structures/components/Div.js +202 -0
- package/dist/structures/components/ImageLayer.d.ts +1 -1
- package/dist/structures/components/ImageLayer.js +28 -29
- package/dist/structures/components/LineLayer.d.ts +18 -36
- package/dist/structures/components/LineLayer.js +43 -45
- package/dist/structures/components/MorphLayer.d.ts +4 -33
- package/dist/structures/components/MorphLayer.js +37 -51
- package/dist/structures/components/Path2DLayer.d.ts +7 -35
- package/dist/structures/components/Path2DLayer.js +32 -41
- package/dist/structures/components/PolygonLayer.d.ts +3 -32
- package/dist/structures/components/PolygonLayer.js +37 -42
- package/dist/structures/components/QuadraticLayer.d.ts +25 -34
- package/dist/structures/components/QuadraticLayer.js +83 -47
- package/dist/structures/components/TextLayer.d.ts +5 -34
- package/dist/structures/components/TextLayer.js +88 -71
- package/dist/structures/components/index.d.ts +10 -11
- package/dist/structures/components/index.js +1 -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 +44 -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 +1 -2
- package/dist/types/enum.js +1 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +257 -107
- 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 +4 -7
- package/dist/utils/utils.js +140 -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
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseLayer = void 0;
|
|
4
4
|
const types_1 = require("../../types");
|
|
5
|
-
const utils_1 = require("../../utils
|
|
6
|
-
const
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
const Signal_1 = require("../../core/Signal");
|
|
7
|
+
const helpers_1 = require("../helpers");
|
|
7
8
|
/**
|
|
8
9
|
* Represents a base layer with generic properties and methods for managing
|
|
9
10
|
* its position, visibility, transformations, and other attributes.
|
|
@@ -11,44 +12,115 @@ const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
|
11
12
|
* @template T - A type extending `IBaseLayerProps` that defines the properties of the layer.
|
|
12
13
|
*/
|
|
13
14
|
class BaseLayer {
|
|
15
|
+
constructor(type, props, misc) {
|
|
16
|
+
this.children = [];
|
|
17
|
+
this._signals = new Map();
|
|
18
|
+
// Extract id, visible, zIndex from props if provided (for JSX support)
|
|
19
|
+
const propsId = props.id;
|
|
20
|
+
const propsVisible = props.visible;
|
|
21
|
+
const propsZIndex = props.zIndex;
|
|
22
|
+
this.id = misc?.id || propsId || (0, utils_1.generateID)(type);
|
|
23
|
+
this.type = type;
|
|
24
|
+
this.zIndex = misc?.zIndex ?? propsZIndex ?? 1;
|
|
25
|
+
this.visible = misc?.visible ?? propsVisible ?? true;
|
|
26
|
+
this.props = props;
|
|
27
|
+
this.parent = null;
|
|
28
|
+
this.children = [];
|
|
29
|
+
this.extractSignals(this.props, "");
|
|
30
|
+
}
|
|
14
31
|
/**
|
|
15
|
-
*
|
|
16
|
-
* @
|
|
32
|
+
* Adds components to the layer.
|
|
33
|
+
* @param {AnyLayer[] | Div[]} [components] - The components to add to the layer.
|
|
34
|
+
* @returns {this} The current instance for chaining.
|
|
17
35
|
*/
|
|
18
|
-
|
|
36
|
+
add(...components) {
|
|
37
|
+
let layersArray = components.filter((l) => l !== undefined);
|
|
38
|
+
layersArray = layersArray.sort((a, b) => a.zIndex - b.zIndex);
|
|
39
|
+
for (const layer of layersArray) {
|
|
40
|
+
layer.parent = this;
|
|
41
|
+
}
|
|
42
|
+
this.children.push(...layersArray);
|
|
43
|
+
return this;
|
|
44
|
+
}
|
|
19
45
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @
|
|
46
|
+
* Removes a component from the layer by its ID.
|
|
47
|
+
* @param {string} [id] - The unique identifier of the component to remove.
|
|
48
|
+
* @returns {this} The current instance for chaining.
|
|
22
49
|
*/
|
|
23
|
-
|
|
50
|
+
remove(id) {
|
|
51
|
+
this.children = this.children.filter((c) => c.id !== id);
|
|
52
|
+
return this;
|
|
53
|
+
}
|
|
24
54
|
/**
|
|
25
|
-
*
|
|
26
|
-
* @
|
|
55
|
+
* Retrieves a component from the layer by its ID.
|
|
56
|
+
* @param {string} [id] - The unique identifier of the component to retrieve.
|
|
57
|
+
* @returns {AnyLayer | Div | undefined} The component with the specified ID, or undefined if not found.
|
|
27
58
|
*/
|
|
28
|
-
|
|
59
|
+
get(id) {
|
|
60
|
+
return this.children.find((c) => c.id === id);
|
|
61
|
+
}
|
|
29
62
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @
|
|
63
|
+
* Retrieves all components from the layer.
|
|
64
|
+
* @returns {AnyLayer[] | Div[]} An array of all components in the layer.
|
|
32
65
|
*/
|
|
33
|
-
|
|
66
|
+
getAll() {
|
|
67
|
+
return this.children;
|
|
68
|
+
}
|
|
34
69
|
/**
|
|
35
|
-
*
|
|
36
|
-
* @
|
|
70
|
+
* Recursively extract signals from props and nested objects
|
|
71
|
+
* @param obj - Object to extract signals from
|
|
72
|
+
* @param path - Current property path (e.g., "size.width")
|
|
37
73
|
*/
|
|
38
|
-
|
|
74
|
+
extractSignals(obj, path) {
|
|
75
|
+
if (!obj || typeof obj !== "object")
|
|
76
|
+
return;
|
|
77
|
+
for (const key in obj) {
|
|
78
|
+
const value = obj[key];
|
|
79
|
+
const currentPath = path ? `${path}.${key}` : key;
|
|
80
|
+
if (value instanceof Signal_1.Signal) {
|
|
81
|
+
// Store signal with its path
|
|
82
|
+
this._signals.set(currentPath, value);
|
|
83
|
+
// Replace signal with its initial value (at time 0)
|
|
84
|
+
obj[key] = value.get(0);
|
|
85
|
+
}
|
|
86
|
+
else if (value &&
|
|
87
|
+
typeof value === "object" &&
|
|
88
|
+
!Array.isArray(value) &&
|
|
89
|
+
!(value instanceof helpers_1.Gradient) &&
|
|
90
|
+
!(value instanceof helpers_1.Pattern) &&
|
|
91
|
+
!(value instanceof helpers_1.Link)) {
|
|
92
|
+
// Recursively process nested objects (but not arrays or special types)
|
|
93
|
+
this.extractSignals(value, currentPath);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
39
97
|
/**
|
|
40
|
-
*
|
|
41
|
-
* @param
|
|
42
|
-
* @param {T} [props] - The properties of the layer.
|
|
43
|
-
* @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
|
|
98
|
+
* Update layer properties from signals at given time
|
|
99
|
+
* @param time - Current time in seconds
|
|
44
100
|
*/
|
|
45
|
-
|
|
46
|
-
this.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
101
|
+
updateState(time) {
|
|
102
|
+
this._signals.forEach((signal, path) => {
|
|
103
|
+
// Just read the current value - signals are updated by the scheduler
|
|
104
|
+
const value = signal.value ? signal.value() : signal.get(time);
|
|
105
|
+
this.setNestedProperty(this.props, path, value);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Set a nested property value using dot notation path
|
|
110
|
+
* @param obj - Object to set property on
|
|
111
|
+
* @param path - Property path (e.g., "size.width")
|
|
112
|
+
* @param value - Value to set
|
|
113
|
+
*/
|
|
114
|
+
setNestedProperty(obj, path, value) {
|
|
115
|
+
const keys = path.split(".");
|
|
116
|
+
let current = obj;
|
|
117
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
118
|
+
if (!current[keys[i]] || typeof current[keys[i]] !== "object") {
|
|
119
|
+
current[keys[i]] = {};
|
|
120
|
+
}
|
|
121
|
+
current = current[keys[i]];
|
|
122
|
+
}
|
|
123
|
+
current[keys[keys.length - 1]] = value;
|
|
52
124
|
}
|
|
53
125
|
/**
|
|
54
126
|
* Sets the position of the layer in the 2D plane.
|
|
@@ -57,8 +129,7 @@ class BaseLayer {
|
|
|
57
129
|
* @returns {this} The current instance for chaining.
|
|
58
130
|
*/
|
|
59
131
|
setPosition(x, y) {
|
|
60
|
-
this.props.
|
|
61
|
-
this.props.y = y;
|
|
132
|
+
this.props.position = { x, y };
|
|
62
133
|
return this;
|
|
63
134
|
}
|
|
64
135
|
/**
|
|
@@ -91,9 +162,9 @@ class BaseLayer {
|
|
|
91
162
|
*/
|
|
92
163
|
setShadow(color, blur, offsetX, offsetY) {
|
|
93
164
|
if (!color)
|
|
94
|
-
throw new
|
|
165
|
+
throw new utils_1.LazyError("The color of the shadow must be provided");
|
|
95
166
|
if (!(0, utils_1.isColor)(color))
|
|
96
|
-
throw new
|
|
167
|
+
throw new utils_1.LazyError("The color of the shadow must be a valid color");
|
|
97
168
|
this.props.shadow = {
|
|
98
169
|
color: color,
|
|
99
170
|
blur: blur || 0,
|
|
@@ -146,7 +217,7 @@ class BaseLayer {
|
|
|
146
217
|
* @returns {this} The current instance for chaining.
|
|
147
218
|
*/
|
|
148
219
|
setFilters(...filter) {
|
|
149
|
-
this.props.filter = filter.join(
|
|
220
|
+
this.props.filter = filter.join(" ");
|
|
150
221
|
return this;
|
|
151
222
|
}
|
|
152
223
|
/**
|
|
@@ -201,13 +272,11 @@ class BaseLayer {
|
|
|
201
272
|
validateProps(data) {
|
|
202
273
|
return {
|
|
203
274
|
...data,
|
|
204
|
-
x: data.x || 0,
|
|
205
|
-
y: data.y || 0,
|
|
206
275
|
centring: data.centring || types_1.Centring.Center,
|
|
207
|
-
filter: data.filter ||
|
|
276
|
+
filter: data.filter || "",
|
|
208
277
|
opacity: data.opacity || 1,
|
|
209
278
|
transform: data.transform || {},
|
|
210
|
-
globalComposite: data.globalComposite ||
|
|
279
|
+
globalComposite: data.globalComposite || "source-over",
|
|
211
280
|
};
|
|
212
281
|
}
|
|
213
282
|
}
|
|
@@ -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,51 +19,36 @@ 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: {
|
|
23
|
+
/**
|
|
24
|
+
* The start x of the Bézier curve.
|
|
25
|
+
*/
|
|
26
|
+
x: ScaleType;
|
|
27
|
+
/**
|
|
28
|
+
* The start y of the Bézier curve.
|
|
29
|
+
*/
|
|
30
|
+
y: ScaleType;
|
|
31
|
+
/**
|
|
32
|
+
* The end x of the Bézier curve.
|
|
33
|
+
*/
|
|
34
|
+
endX: ScaleType;
|
|
35
|
+
/**
|
|
36
|
+
* The end y of the Bézier curve.
|
|
37
|
+
*/
|
|
38
|
+
endY: ScaleType;
|
|
39
|
+
};
|
|
22
40
|
/**
|
|
23
41
|
* The control points of the Bézier curve.
|
|
24
42
|
*/
|
|
25
43
|
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
44
|
/**
|
|
35
45
|
* The fill style (color or pattern) of the layer.
|
|
36
46
|
*/
|
|
37
|
-
|
|
47
|
+
color: ColorType;
|
|
38
48
|
/**
|
|
39
49
|
* The stroke properties of the Bézier curve.
|
|
40
50
|
*/
|
|
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
|
-
};
|
|
51
|
+
stroke: StrokeOptions;
|
|
67
52
|
}
|
|
68
53
|
/**
|
|
69
54
|
* Class representing a Bezier layer, extending the BaseLayer class.
|
|
@@ -90,12 +75,14 @@ export declare class BezierLayer extends BaseLayer<IBezierLayerProps> {
|
|
|
90
75
|
y: ScaleType;
|
|
91
76
|
}[]): this;
|
|
92
77
|
/**
|
|
93
|
-
* Sets the
|
|
78
|
+
* Sets the position of the Bezier layer.
|
|
94
79
|
* @param {ScaleType} [x] - The x-coordinate of the end point.
|
|
95
80
|
* @param {ScaleType} [y] - The y-coordinate of the end point.
|
|
81
|
+
* @param {ScaleType} [endX] - The x-coordinate of the end point.
|
|
82
|
+
* @param {ScaleType} [endY] - The y-coordinate of the end point.
|
|
96
83
|
* @returns {this} The current instance for chaining.
|
|
97
84
|
*/
|
|
98
|
-
|
|
85
|
+
setPosition(x: ScaleType, y: ScaleType, endX?: ScaleType, endY?: ScaleType): this;
|
|
99
86
|
/**
|
|
100
87
|
* Sets the color of the Bezier layer.
|
|
101
88
|
* @param {ColorType} [color] - The color of the layer.
|
|
@@ -3,16 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.BezierLayer = void 0;
|
|
4
4
|
const BaseLayer_1 = require("./BaseLayer");
|
|
5
5
|
const types_1 = require("../../types");
|
|
6
|
-
const utils_1 = require("../../utils
|
|
7
|
-
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
8
7
|
/**
|
|
9
8
|
* Class representing a Bezier layer, extending the BaseLayer class.
|
|
10
9
|
*/
|
|
11
10
|
class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
12
|
-
/**
|
|
13
|
-
* The properties of the Bezier layer.
|
|
14
|
-
*/
|
|
15
|
-
props;
|
|
16
11
|
/**
|
|
17
12
|
* Constructs a new BezierLayer instance.
|
|
18
13
|
* @param {IBezierLayerProps} [props] - The properties of the Bezier layer.
|
|
@@ -31,18 +26,20 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
31
26
|
*/
|
|
32
27
|
setControlPoints(...controlPoints) {
|
|
33
28
|
if (controlPoints.length !== 2)
|
|
34
|
-
throw new
|
|
29
|
+
throw new utils_1.LazyError("The control points of the layer must be provided");
|
|
35
30
|
this.props.controlPoints = controlPoints.flat();
|
|
36
31
|
return this;
|
|
37
32
|
}
|
|
38
33
|
/**
|
|
39
|
-
* Sets the
|
|
34
|
+
* Sets the position of the Bezier layer.
|
|
40
35
|
* @param {ScaleType} [x] - The x-coordinate of the end point.
|
|
41
36
|
* @param {ScaleType} [y] - The y-coordinate of the end point.
|
|
37
|
+
* @param {ScaleType} [endX] - The x-coordinate of the end point.
|
|
38
|
+
* @param {ScaleType} [endY] - The y-coordinate of the end point.
|
|
42
39
|
* @returns {this} The current instance for chaining.
|
|
43
40
|
*/
|
|
44
|
-
|
|
45
|
-
this.props.
|
|
41
|
+
setPosition(x, y, endX, endY) {
|
|
42
|
+
this.props.position = { x, y, endX: endX || 0, endY: endY || 0 };
|
|
46
43
|
return this;
|
|
47
44
|
}
|
|
48
45
|
/**
|
|
@@ -53,10 +50,10 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
53
50
|
*/
|
|
54
51
|
setColor(color) {
|
|
55
52
|
if (!color)
|
|
56
|
-
throw new
|
|
53
|
+
throw new utils_1.LazyError("The color of the layer must be provided");
|
|
57
54
|
if (!(0, utils_1.isColor)(color))
|
|
58
|
-
throw new
|
|
59
|
-
this.props.
|
|
55
|
+
throw new utils_1.LazyError("The color of the layer must be a valid color");
|
|
56
|
+
this.props.color = color;
|
|
60
57
|
return this;
|
|
61
58
|
}
|
|
62
59
|
/**
|
|
@@ -72,8 +69,8 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
72
69
|
setStroke(width, cap, join, dash, dashOffset, miterLimit) {
|
|
73
70
|
this.props.stroke = {
|
|
74
71
|
width,
|
|
75
|
-
cap: cap ||
|
|
76
|
-
join: join ||
|
|
72
|
+
cap: cap || "butt",
|
|
73
|
+
join: join || "miter",
|
|
77
74
|
dash: dash || [],
|
|
78
75
|
dashOffset: dashOffset || 0,
|
|
79
76
|
miterLimit: miterLimit || 10,
|
|
@@ -90,16 +87,21 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
90
87
|
getBoundingBox(ctx, canvas, manager) {
|
|
91
88
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
92
89
|
const { xs, ys, cp1x, cp1y, cp2x, cp2y, xe, ye } = parcer.parseBatch({
|
|
93
|
-
xs: { v: this.props.x },
|
|
94
|
-
ys: { v: this.props.y, options:
|
|
90
|
+
xs: { v: this.props.position.x },
|
|
91
|
+
ys: { v: this.props.position.y, options: utils_1.defaultArg.vl(true) },
|
|
95
92
|
cp1x: { v: this.props.controlPoints[0].x },
|
|
96
|
-
cp1y: { v: this.props.controlPoints[0].y, options:
|
|
93
|
+
cp1y: { v: this.props.controlPoints[0].y, options: utils_1.defaultArg.vl(true) },
|
|
97
94
|
cp2x: { v: this.props.controlPoints[1].x },
|
|
98
|
-
cp2y: { v: this.props.controlPoints[1].y, options:
|
|
99
|
-
xe: { v: this.props.
|
|
100
|
-
ye: { v: this.props.
|
|
95
|
+
cp2y: { v: this.props.controlPoints[1].y, options: utils_1.defaultArg.vl(true) },
|
|
96
|
+
xe: { v: this.props.position.endX },
|
|
97
|
+
ye: { v: this.props.position.endY, options: utils_1.defaultArg.vl(true) },
|
|
101
98
|
});
|
|
102
|
-
const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([
|
|
99
|
+
const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([
|
|
100
|
+
{ x: xs, y: ys },
|
|
101
|
+
{ x: cp1x, y: cp1y },
|
|
102
|
+
{ x: cp2x, y: cp2y },
|
|
103
|
+
{ x: xe, y: ye },
|
|
104
|
+
]);
|
|
103
105
|
return { max, min, center, width, height };
|
|
104
106
|
}
|
|
105
107
|
/**
|
|
@@ -112,33 +114,59 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
112
114
|
async draw(ctx, canvas, manager, debug) {
|
|
113
115
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
114
116
|
const { xs, ys, cp1x, cp1y, cp2x, cp2y, xe, ye } = parcer.parseBatch({
|
|
115
|
-
xs: { v: this.props.x },
|
|
116
|
-
ys: { v: this.props.y, options:
|
|
117
|
+
xs: { v: this.props.position.x },
|
|
118
|
+
ys: { v: this.props.position.y, options: utils_1.defaultArg.vl(true) },
|
|
117
119
|
cp1x: { v: this.props.controlPoints[0].x },
|
|
118
|
-
cp1y: { v: this.props.controlPoints[0].y, options:
|
|
120
|
+
cp1y: { v: this.props.controlPoints[0].y, options: utils_1.defaultArg.vl(true) },
|
|
119
121
|
cp2x: { v: this.props.controlPoints[1].x },
|
|
120
|
-
cp2y: { v: this.props.controlPoints[1].y, options:
|
|
121
|
-
xe: { v: this.props.
|
|
122
|
-
ye: { v: this.props.
|
|
122
|
+
cp2y: { v: this.props.controlPoints[1].y, options: utils_1.defaultArg.vl(true) },
|
|
123
|
+
xe: { v: this.props.position.endX },
|
|
124
|
+
ye: { v: this.props.position.endY, options: utils_1.defaultArg.vl(true) },
|
|
125
|
+
});
|
|
126
|
+
const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([
|
|
127
|
+
{ x: xs, y: ys },
|
|
128
|
+
{ x: cp1x, y: cp1y },
|
|
129
|
+
{ x: cp2x, y: cp2y },
|
|
130
|
+
{ x: xe, y: ye },
|
|
131
|
+
]);
|
|
132
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, {
|
|
133
|
+
debug,
|
|
134
|
+
layer: { width, height, x: min.x, y: min.y, align: "none" },
|
|
135
|
+
manager,
|
|
123
136
|
});
|
|
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
137
|
if (debug)
|
|
127
|
-
|
|
138
|
+
utils_1.LazyLog.log("none", `BezierLayer:`, {
|
|
139
|
+
xs,
|
|
140
|
+
ys,
|
|
141
|
+
cp1x,
|
|
142
|
+
cp1y,
|
|
143
|
+
cp2x,
|
|
144
|
+
cp2y,
|
|
145
|
+
xe,
|
|
146
|
+
ye,
|
|
147
|
+
max,
|
|
148
|
+
min,
|
|
149
|
+
center,
|
|
150
|
+
width,
|
|
151
|
+
height,
|
|
152
|
+
fillStyle,
|
|
153
|
+
});
|
|
128
154
|
ctx.save();
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
155
|
+
if (this.props.transform) {
|
|
156
|
+
(0, utils_1.transform)(ctx, this.props.transform, {
|
|
157
|
+
x: center.x,
|
|
158
|
+
y: center.y,
|
|
159
|
+
width,
|
|
160
|
+
height,
|
|
161
|
+
type: this.type,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
utils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
|
|
165
|
+
utils_1.DrawUtils.opacity(ctx, this.props.opacity);
|
|
166
|
+
utils_1.DrawUtils.filters(ctx, this.props.filter);
|
|
167
|
+
utils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
|
|
133
168
|
ctx.beginPath();
|
|
134
169
|
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
170
|
ctx.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, xe, ye);
|
|
143
171
|
ctx.stroke();
|
|
144
172
|
ctx.closePath();
|
|
@@ -151,18 +179,18 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
151
179
|
toJSON() {
|
|
152
180
|
let data = super.toJSON();
|
|
153
181
|
let copy = { ...this.props };
|
|
154
|
-
for (const key of [
|
|
155
|
-
if (copy[key] && typeof copy[key] ===
|
|
182
|
+
for (const key of ["x", "y", "endPoint.x", "endPoint.y", "fillStyle"]) {
|
|
183
|
+
if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
|
|
156
184
|
copy[key] = copy[key].toJSON();
|
|
157
185
|
}
|
|
158
186
|
}
|
|
159
187
|
if (copy.controlPoints) {
|
|
160
188
|
copy.controlPoints = copy.controlPoints.map((point) => {
|
|
161
|
-
if (point.x && typeof point.x ===
|
|
189
|
+
if (point.x && typeof point.x === "object" && "toJSON" in point.x) {
|
|
162
190
|
// @ts-ignore
|
|
163
191
|
point.x = point.x.toJSON();
|
|
164
192
|
}
|
|
165
|
-
if (point.y && typeof point.y ===
|
|
193
|
+
if (point.y && typeof point.y === "object" && "toJSON" in point.y) {
|
|
166
194
|
// @ts-ignore
|
|
167
195
|
point.y = point.y.toJSON();
|
|
168
196
|
}
|
|
@@ -179,19 +207,26 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
179
207
|
validateProps(data) {
|
|
180
208
|
return {
|
|
181
209
|
...super.validateProps(data),
|
|
182
|
-
|
|
183
|
-
|
|
210
|
+
position: {
|
|
211
|
+
x: data.position?.x || 0,
|
|
212
|
+
y: data.position?.y || 0,
|
|
213
|
+
endX: data.position?.endX || 0,
|
|
214
|
+
endY: data.position?.endY || 0,
|
|
215
|
+
},
|
|
216
|
+
color: data.color || "#000000",
|
|
184
217
|
centring: data.centring || types_1.Centring.None,
|
|
185
|
-
controlPoints: data.controlPoints || [
|
|
186
|
-
|
|
218
|
+
controlPoints: data.controlPoints || [
|
|
219
|
+
{ x: 0, y: 0 },
|
|
220
|
+
{ x: 0, y: 0 },
|
|
221
|
+
],
|
|
187
222
|
stroke: {
|
|
188
223
|
width: data.stroke?.width || 1,
|
|
189
|
-
cap: data.stroke?.cap ||
|
|
190
|
-
join: data.stroke?.join ||
|
|
224
|
+
cap: data.stroke?.cap || "butt",
|
|
225
|
+
join: data.stroke?.join || "miter",
|
|
191
226
|
dashOffset: data.stroke?.dashOffset || 0,
|
|
192
227
|
dash: data.stroke?.dash || [],
|
|
193
228
|
miterLimit: data.stroke?.miterLimit || 10,
|
|
194
|
-
}
|
|
229
|
+
},
|
|
195
230
|
};
|
|
196
231
|
}
|
|
197
232
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { AnyGlobalCompositeOperation, AnyLayer, LayerType } from "../../types";
|
|
2
2
|
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
|
|
3
3
|
import { LayersManager } from "../managers";
|
|
4
|
+
import { BaseLayer, IBaseLayer, IBaseLayerProps } from "./BaseLayer";
|
|
4
5
|
/**
|
|
5
6
|
* Interface representing a group of layer's.
|
|
6
7
|
*/
|
|
7
|
-
export interface
|
|
8
|
+
export interface IDiv extends IBaseLayer {
|
|
8
9
|
/**
|
|
9
10
|
* The unique identifier of the group.
|
|
10
11
|
*/
|
|
@@ -24,22 +25,23 @@ export interface IGroup {
|
|
|
24
25
|
/**
|
|
25
26
|
* The layer's contained within the group.
|
|
26
27
|
*/
|
|
27
|
-
layers: Array<AnyLayer>;
|
|
28
|
+
layers: Array<AnyLayer | Div>;
|
|
28
29
|
/**
|
|
29
|
-
*
|
|
30
|
+
* The properties specific to the Div group.
|
|
30
31
|
*/
|
|
31
|
-
props
|
|
32
|
+
props: IDivProps;
|
|
32
33
|
}
|
|
33
|
-
export interface
|
|
34
|
+
export interface IDivProps extends IBaseLayerProps {
|
|
34
35
|
/**
|
|
35
36
|
* Don't use, this is just for compatibility.
|
|
36
37
|
*/
|
|
37
|
-
globalComposite
|
|
38
|
+
globalComposite?: AnyGlobalCompositeOperation;
|
|
39
|
+
children?: Array<any>;
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* Class representing a group of layer's.
|
|
41
43
|
*/
|
|
42
|
-
export declare class
|
|
44
|
+
export declare class Div extends BaseLayer<IDivProps> implements IDiv {
|
|
43
45
|
/**
|
|
44
46
|
* The unique identifier of the group.
|
|
45
47
|
*/
|
|
@@ -59,15 +61,17 @@ export declare class Group implements IGroup {
|
|
|
59
61
|
/**
|
|
60
62
|
* The layer's contained within the group.
|
|
61
63
|
*/
|
|
62
|
-
layers: Array<
|
|
63
|
-
props
|
|
64
|
+
layers: Array<AnyLayer | Div>;
|
|
65
|
+
props: IDivProps;
|
|
66
|
+
parent?: IBaseLayer | any | null;
|
|
64
67
|
/**
|
|
65
68
|
* Constructs a new Group instance.
|
|
69
|
+
* @param {IDivProps} [props] - The properties of the Div.
|
|
66
70
|
* @param {string} [opts.id] - The unique identifier of the group.
|
|
67
71
|
* @param {boolean} [opts.visible] - The visibility of the group.
|
|
68
72
|
* @param {number} [opts.zIndex] - The z-index of the group.
|
|
69
73
|
*/
|
|
70
|
-
constructor(opts?: {
|
|
74
|
+
constructor(props?: IDivProps, opts?: {
|
|
71
75
|
id?: string;
|
|
72
76
|
visible?: boolean;
|
|
73
77
|
zIndex?: number;
|
|
@@ -92,10 +96,10 @@ export declare class Group implements IGroup {
|
|
|
92
96
|
setZIndex(zIndex: number): this;
|
|
93
97
|
/**
|
|
94
98
|
* Adds components to the group.
|
|
95
|
-
* @param {AnyLayer[]} [components] - The components to add to the group.
|
|
99
|
+
* @param {AnyLayer[] | Div[]} [components] - The components to add to the group.
|
|
96
100
|
* @returns {this} The current instance for chaining.
|
|
97
101
|
*/
|
|
98
|
-
add(...components: AnyLayer
|
|
102
|
+
add(...components: Array<AnyLayer | Div>): this;
|
|
99
103
|
/**
|
|
100
104
|
* Removes a component from the group by its ID.
|
|
101
105
|
* @param {string} [id] - The unique identifier of the component to remove.
|
|
@@ -110,23 +114,38 @@ export declare class Group implements IGroup {
|
|
|
110
114
|
/**
|
|
111
115
|
* Retrieves a component from the group by its ID.
|
|
112
116
|
* @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.
|
|
117
|
+
* @returns {AnyLayer | Div | undefined} The component with the specified ID, or undefined if not found.
|
|
114
118
|
*/
|
|
115
|
-
get(id: string): AnyLayer | undefined;
|
|
119
|
+
get(id: string): AnyLayer | Div | undefined;
|
|
116
120
|
/**
|
|
117
121
|
* Retrieves all components from the group.
|
|
118
|
-
* @returns {AnyLayer[]} An array of all components in the group.
|
|
122
|
+
* @returns {AnyLayer[] | Div[]} An array of all components in the group.
|
|
119
123
|
*/
|
|
120
|
-
getAll(): AnyLayer
|
|
124
|
+
getAll(): Array<AnyLayer | Div>;
|
|
121
125
|
/**
|
|
122
126
|
* Gets the number of components in the group.
|
|
123
127
|
* @returns {number} The number of components in the group.
|
|
124
128
|
*/
|
|
125
129
|
get length(): number;
|
|
130
|
+
/**
|
|
131
|
+
* Update state for all child layers (for animation support)
|
|
132
|
+
* @param {number} time - Current time in seconds
|
|
133
|
+
*/
|
|
134
|
+
updateState(time: number): void;
|
|
135
|
+
/**
|
|
136
|
+
* Renders a single layer or group of layers.
|
|
137
|
+
* @param {AnyLayer | Div} [layer] - The layer or group to render.
|
|
138
|
+
* @param {SKRSContext2D} [ctx] - The canvas rendering context.
|
|
139
|
+
* @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
|
|
140
|
+
* @param {LayersManager} [manager] - The layer's manager.
|
|
141
|
+
* @param {boolean} [debug] - Whether to enable debug logging.
|
|
142
|
+
* @returns {Promise<SKRSContext2D>} The canvas rendering context after rendering.
|
|
143
|
+
*/
|
|
144
|
+
private renderLayer;
|
|
126
145
|
draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
|
|
127
146
|
/**
|
|
128
147
|
* Converts the group to a JSON representation.
|
|
129
|
-
* @returns {
|
|
148
|
+
* @returns {IDiv} The JSON representation of the group.
|
|
130
149
|
*/
|
|
131
|
-
toJSON():
|
|
150
|
+
toJSON(): IDiv;
|
|
132
151
|
}
|