@nmmty/lazycanvas 1.0.0-dev.5 → 1.0.0-dev.7
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/dist/core/Scene.d.ts +4 -6
- package/dist/core/Scene.js +6 -22
- package/dist/jsx-runtime.js +1 -1
- package/dist/structures/LazyCanvas.d.ts +2 -0
- package/dist/structures/LazyCanvas.js +2 -0
- package/dist/structures/components/BaseLayer.d.ts +37 -25
- package/dist/structures/components/BaseLayer.js +45 -12
- package/dist/structures/components/BezierLayer.d.ts +1 -1
- package/dist/structures/components/BezierLayer.js +3 -3
- package/dist/structures/components/Div.d.ts +10 -7
- package/dist/structures/components/Div.js +18 -3
- package/dist/structures/components/ImageLayer.d.ts +0 -4
- package/dist/structures/components/ImageLayer.js +2 -2
- package/dist/structures/components/LineLayer.d.ts +1 -1
- package/dist/structures/components/LineLayer.js +3 -3
- package/dist/structures/components/MorphLayer.d.ts +1 -5
- package/dist/structures/components/MorphLayer.js +5 -5
- package/dist/structures/components/Path2DLayer.d.ts +1 -1
- package/dist/structures/components/Path2DLayer.js +10 -4
- package/dist/structures/components/PolygonLayer.d.ts +1 -5
- package/dist/structures/components/PolygonLayer.js +5 -5
- package/dist/structures/components/QuadraticLayer.d.ts +1 -1
- package/dist/structures/components/QuadraticLayer.js +3 -3
- package/dist/structures/components/TextLayer.d.ts +1 -5
- package/dist/structures/components/TextLayer.js +33 -12
- package/dist/structures/helpers/readers/JSONReader.js +13 -13
- package/dist/structures/managers/LayoutManager.d.ts +23 -0
- package/dist/structures/managers/LayoutManager.js +409 -0
- package/dist/structures/managers/RenderManager.d.ts +1 -0
- package/dist/structures/managers/RenderManager.js +35 -2
- package/dist/types/types.d.ts +25 -0
- package/dist/utils/utils.js +11 -7
- package/package.json +3 -2
- package/biome.json +0 -41
package/dist/core/Scene.d.ts
CHANGED
|
@@ -15,8 +15,11 @@ export declare class Scene {
|
|
|
15
15
|
* Create a new Scene
|
|
16
16
|
* @param width - Canvas width in pixels
|
|
17
17
|
* @param height - Canvas height in pixels
|
|
18
|
+
* @param opts
|
|
18
19
|
*/
|
|
19
|
-
constructor(width: number, height: number
|
|
20
|
+
constructor(width: number, height: number, opts?: {
|
|
21
|
+
debug?: boolean;
|
|
22
|
+
});
|
|
20
23
|
/**
|
|
21
24
|
* Load a layer tree created via JSX
|
|
22
25
|
* Registers all layers with IDs into the manager
|
|
@@ -47,11 +50,6 @@ export declare class Scene {
|
|
|
47
50
|
* @param time - Current time in seconds
|
|
48
51
|
*/
|
|
49
52
|
private updateAllStates;
|
|
50
|
-
/**
|
|
51
|
-
* Draw a layer or group
|
|
52
|
-
* @param layer - Layer to draw
|
|
53
|
-
*/
|
|
54
|
-
private drawLayer;
|
|
55
53
|
/**
|
|
56
54
|
* Render multiple frames and return as animation
|
|
57
55
|
* @param startTime - Start time in seconds
|
package/dist/core/Scene.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Scene = void 0;
|
|
4
|
+
const types_1 = require("../types");
|
|
4
5
|
const ThreadScheduler_1 = require("./ThreadScheduler");
|
|
5
6
|
const LazyCanvas_1 = require("../structures/LazyCanvas");
|
|
6
7
|
/**
|
|
@@ -11,12 +12,13 @@ class Scene {
|
|
|
11
12
|
* Create a new Scene
|
|
12
13
|
* @param width - Canvas width in pixels
|
|
13
14
|
* @param height - Canvas height in pixels
|
|
15
|
+
* @param opts
|
|
14
16
|
*/
|
|
15
|
-
constructor(width, height) {
|
|
17
|
+
constructor(width, height, opts = {}) {
|
|
16
18
|
this.allLayers = [];
|
|
17
19
|
this.scheduler = new ThreadScheduler_1.ThreadScheduler();
|
|
18
20
|
this.lastFrameTime = 0;
|
|
19
|
-
this.lazyCanvas = new LazyCanvas_1.LazyCanvas().create(width, height);
|
|
21
|
+
this.lazyCanvas = new LazyCanvas_1.LazyCanvas(opts).create(width, height);
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* Load a layer tree created via JSX
|
|
@@ -41,8 +43,8 @@ class Scene {
|
|
|
41
43
|
this.lazyCanvas.ctx.clearRect(0, 0, this.lazyCanvas.canvas.width, this.lazyCanvas.canvas.height);
|
|
42
44
|
// 3. PHASE 1: Update all layer states from signals
|
|
43
45
|
this.updateAllStates(time);
|
|
44
|
-
// 4. PHASE 2: Draw the layer tree
|
|
45
|
-
await this.
|
|
46
|
+
// 4. PHASE 2: Draw the layer tree using RenderManager
|
|
47
|
+
await this.lazyCanvas.manager.render.render(types_1.Export.CTX);
|
|
46
48
|
this.lastFrameTime = time;
|
|
47
49
|
}
|
|
48
50
|
async renderFirstFrame() {
|
|
@@ -81,24 +83,6 @@ class Scene {
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
}
|
|
84
|
-
/**
|
|
85
|
-
* Draw a layer or group
|
|
86
|
-
* @param layer - Layer to draw
|
|
87
|
-
*/
|
|
88
|
-
async drawLayer(layer) {
|
|
89
|
-
if (!layer.visible)
|
|
90
|
-
return;
|
|
91
|
-
// Set global composite operation if present
|
|
92
|
-
if ("props" in layer && layer.props?.globalComposite) {
|
|
93
|
-
this.lazyCanvas.ctx.globalCompositeOperation = layer.props.globalComposite;
|
|
94
|
-
}
|
|
95
|
-
// Draw the layer
|
|
96
|
-
if ("draw" in layer && typeof layer.draw === "function") {
|
|
97
|
-
await layer.draw(this.lazyCanvas.ctx, this.lazyCanvas.canvas, this.lazyCanvas.manager.layers, false);
|
|
98
|
-
}
|
|
99
|
-
// Reset shadow after drawing
|
|
100
|
-
this.lazyCanvas.ctx.shadowColor = "transparent";
|
|
101
|
-
}
|
|
102
86
|
/**
|
|
103
87
|
* Render multiple frames and return as animation
|
|
104
88
|
* @param startTime - Start time in seconds
|
package/dist/jsx-runtime.js
CHANGED
|
@@ -64,7 +64,7 @@ function createElement(type, props, ...children) {
|
|
|
64
64
|
*/
|
|
65
65
|
function createGroupInstance(props, children) {
|
|
66
66
|
const { id, visible, zIndex, ...otherProps } = props;
|
|
67
|
-
const group = new components_1.Div({
|
|
67
|
+
const group = new components_1.Div(otherProps, {
|
|
68
68
|
id,
|
|
69
69
|
visible,
|
|
70
70
|
zIndex,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { AnyExport, JSONLayer } from "../types";
|
|
2
2
|
import { Canvas, SKRSContext2D, SvgCanvas, SvgExportFlag } from "@napi-rs/canvas";
|
|
3
3
|
import { LayersManager, RenderManager, FontsManager } from "./managers";
|
|
4
|
+
import { LayoutManager } from "./managers/LayoutManager";
|
|
4
5
|
import { IDiv } from "./components";
|
|
5
6
|
/**
|
|
6
7
|
* Interface representing the LazyCanvas structure.
|
|
@@ -84,6 +85,7 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
84
85
|
layers: LayersManager;
|
|
85
86
|
render: RenderManager;
|
|
86
87
|
fonts: FontsManager;
|
|
88
|
+
layout: LayoutManager;
|
|
87
89
|
};
|
|
88
90
|
/**
|
|
89
91
|
* The options for configuring the LazyCanvas instance.
|
|
@@ -4,6 +4,7 @@ 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 LayoutManager_1 = require("./managers/LayoutManager");
|
|
7
8
|
const LazyUtil_1 = require("../utils/LazyUtil");
|
|
8
9
|
const utils_1 = require("../utils/utils");
|
|
9
10
|
/**
|
|
@@ -23,6 +24,7 @@ class LazyCanvas {
|
|
|
23
24
|
layers: new managers_1.LayersManager({ debug: opts?.debug }),
|
|
24
25
|
render: new managers_1.RenderManager(this, { debug: opts?.debug }),
|
|
25
26
|
fonts: new managers_1.FontsManager({ debug: opts?.debug }),
|
|
27
|
+
layout: new LayoutManager_1.LayoutManager({ debug: opts?.debug }),
|
|
26
28
|
};
|
|
27
29
|
this.options = {
|
|
28
30
|
width: 0,
|
|
@@ -1,5 +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
2
|
import { Signal } from "../../core/Signal";
|
|
3
|
+
import { Div } from "./Div";
|
|
3
4
|
/**
|
|
4
5
|
* Interface representing the base structure of a layer.
|
|
5
6
|
*/
|
|
@@ -8,6 +9,14 @@ export interface IBaseLayer {
|
|
|
8
9
|
* The unique identifier of the layer.
|
|
9
10
|
*/
|
|
10
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>;
|
|
11
20
|
/**
|
|
12
21
|
* The type of the layer.
|
|
13
22
|
*/
|
|
@@ -39,6 +48,10 @@ export interface IBaseLayerProps {
|
|
|
39
48
|
*/
|
|
40
49
|
y: ScaleType;
|
|
41
50
|
};
|
|
51
|
+
/**
|
|
52
|
+
* The layout properties of the layer.
|
|
53
|
+
*/
|
|
54
|
+
layout?: ILayoutProps;
|
|
42
55
|
/**
|
|
43
56
|
* The centring type of the layer.
|
|
44
57
|
*/
|
|
@@ -104,40 +117,39 @@ export interface IBaseLayerMisc {
|
|
|
104
117
|
*
|
|
105
118
|
* @template T - A type extending `IBaseLayerProps` that defines the properties of the layer.
|
|
106
119
|
*/
|
|
107
|
-
export declare class BaseLayer<T extends IBaseLayerProps> {
|
|
108
|
-
/**
|
|
109
|
-
* The unique identifier of the layer.
|
|
110
|
-
* @type {string}
|
|
111
|
-
*/
|
|
120
|
+
export declare class BaseLayer<T extends IBaseLayerProps> implements IBaseLayer {
|
|
112
121
|
id: string;
|
|
113
|
-
/**
|
|
114
|
-
* The type of the layer.
|
|
115
|
-
* @type {LayerType}
|
|
116
|
-
*/
|
|
117
122
|
type: LayerType;
|
|
123
|
+
zIndex: number;
|
|
124
|
+
visible: boolean;
|
|
125
|
+
props: T;
|
|
126
|
+
parent?: IBaseLayer | any | null;
|
|
127
|
+
children: Array<AnyLayer | Div>;
|
|
128
|
+
private _signals;
|
|
129
|
+
constructor(type: LayerType, props: T, misc?: IBaseLayerMisc);
|
|
118
130
|
/**
|
|
119
|
-
*
|
|
120
|
-
* @
|
|
131
|
+
* Adds components to the layer.
|
|
132
|
+
* @param {AnyLayer[] | Div[]} [components] - The components to add to the layer.
|
|
133
|
+
* @returns {this} The current instance for chaining.
|
|
121
134
|
*/
|
|
122
|
-
|
|
135
|
+
add(...components: Array<AnyLayer | Div>): this;
|
|
123
136
|
/**
|
|
124
|
-
*
|
|
125
|
-
* @
|
|
137
|
+
* Removes a component from the layer by its ID.
|
|
138
|
+
* @param {string} [id] - The unique identifier of the component to remove.
|
|
139
|
+
* @returns {this} The current instance for chaining.
|
|
126
140
|
*/
|
|
127
|
-
|
|
141
|
+
remove(id: string): this;
|
|
128
142
|
/**
|
|
129
|
-
*
|
|
130
|
-
* @
|
|
143
|
+
* Retrieves a component from the layer by its ID.
|
|
144
|
+
* @param {string} [id] - The unique identifier of the component to retrieve.
|
|
145
|
+
* @returns {AnyLayer | Div | undefined} The component with the specified ID, or undefined if not found.
|
|
131
146
|
*/
|
|
132
|
-
|
|
133
|
-
_signals: Map<string, Signal<any>>;
|
|
147
|
+
get(id: string): AnyLayer | Div | undefined;
|
|
134
148
|
/**
|
|
135
|
-
*
|
|
136
|
-
* @
|
|
137
|
-
* @param {T} [props] - The properties of the layer.
|
|
138
|
-
* @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
|
|
149
|
+
* Retrieves all components from the layer.
|
|
150
|
+
* @returns {AnyLayer[] | Div[]} An array of all components in the layer.
|
|
139
151
|
*/
|
|
140
|
-
|
|
152
|
+
getAll(): Array<AnyLayer | Div>;
|
|
141
153
|
/**
|
|
142
154
|
* Recursively extract signals from props and nested objects
|
|
143
155
|
* @param obj - Object to extract signals from
|
|
@@ -13,21 +13,55 @@ const helpers_1 = require("../helpers");
|
|
|
13
13
|
* @template T - A type extending `IBaseLayerProps` that defines the properties of the layer.
|
|
14
14
|
*/
|
|
15
15
|
class BaseLayer {
|
|
16
|
-
/**
|
|
17
|
-
* Constructs a new `BaseLayer` instance.
|
|
18
|
-
* @param {LayerType} [type] - The type of the layer.
|
|
19
|
-
* @param {T} [props] - The properties of the layer.
|
|
20
|
-
* @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
|
|
21
|
-
*/
|
|
22
16
|
constructor(type, props, misc) {
|
|
17
|
+
this.children = [];
|
|
23
18
|
this._signals = new Map();
|
|
24
|
-
this.id = misc?.id || (0, utils_1.generateID)(type
|
|
25
|
-
this.type = type
|
|
19
|
+
this.id = misc?.id || (0, utils_1.generateID)(type);
|
|
20
|
+
this.type = type;
|
|
26
21
|
this.zIndex = misc?.zIndex || 1;
|
|
27
|
-
this.visible = misc?.visible
|
|
28
|
-
this.props = props
|
|
22
|
+
this.visible = misc?.visible || true;
|
|
23
|
+
this.props = props;
|
|
24
|
+
this.parent = null;
|
|
25
|
+
this.children = [];
|
|
29
26
|
this.extractSignals(this.props, "");
|
|
30
|
-
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Adds components to the layer.
|
|
30
|
+
* @param {AnyLayer[] | Div[]} [components] - The components to add to the layer.
|
|
31
|
+
* @returns {this} The current instance for chaining.
|
|
32
|
+
*/
|
|
33
|
+
add(...components) {
|
|
34
|
+
let layersArray = components.filter((l) => l !== undefined);
|
|
35
|
+
layersArray = layersArray.sort((a, b) => a.zIndex - b.zIndex);
|
|
36
|
+
for (const layer of layersArray) {
|
|
37
|
+
layer.parent = this;
|
|
38
|
+
}
|
|
39
|
+
this.children.push(...layersArray);
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Removes a component from the layer by its ID.
|
|
44
|
+
* @param {string} [id] - The unique identifier of the component to remove.
|
|
45
|
+
* @returns {this} The current instance for chaining.
|
|
46
|
+
*/
|
|
47
|
+
remove(id) {
|
|
48
|
+
this.children = this.children.filter((c) => c.id !== id);
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves a component from the layer by its ID.
|
|
53
|
+
* @param {string} [id] - The unique identifier of the component to retrieve.
|
|
54
|
+
* @returns {AnyLayer | Div | undefined} The component with the specified ID, or undefined if not found.
|
|
55
|
+
*/
|
|
56
|
+
get(id) {
|
|
57
|
+
return this.children.find((c) => c.id === id);
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Retrieves all components from the layer.
|
|
61
|
+
* @returns {AnyLayer[] | Div[]} An array of all components in the layer.
|
|
62
|
+
*/
|
|
63
|
+
getAll() {
|
|
64
|
+
return this.children;
|
|
31
65
|
}
|
|
32
66
|
/**
|
|
33
67
|
* Recursively extract signals from props and nested objects
|
|
@@ -235,7 +269,6 @@ class BaseLayer {
|
|
|
235
269
|
validateProps(data) {
|
|
236
270
|
return {
|
|
237
271
|
...data,
|
|
238
|
-
position: data.position || { x: 0, y: 0 },
|
|
239
272
|
centring: data.centring || types_1.Centring.Center,
|
|
240
273
|
filter: data.filter || "",
|
|
241
274
|
opacity: data.opacity || 1,
|
|
@@ -55,7 +55,7 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
55
55
|
throw new LazyUtil_1.LazyError("The color of the layer must be provided");
|
|
56
56
|
if (!(0, utils_1.isColor)(color))
|
|
57
57
|
throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
|
|
58
|
-
this.props.
|
|
58
|
+
this.props.color = color;
|
|
59
59
|
return this;
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
@@ -131,7 +131,7 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
131
131
|
{ x: cp2x, y: cp2y },
|
|
132
132
|
{ x: xe, y: ye },
|
|
133
133
|
]);
|
|
134
|
-
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.
|
|
134
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, {
|
|
135
135
|
debug,
|
|
136
136
|
layer: { width, height, x: min.x, y: min.y, align: "none" },
|
|
137
137
|
manager,
|
|
@@ -215,7 +215,7 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
215
215
|
endX: data.position?.endX || 0,
|
|
216
216
|
endY: data.position?.endY || 0,
|
|
217
217
|
},
|
|
218
|
-
|
|
218
|
+
color: data.color || "#000000",
|
|
219
219
|
centring: data.centring || types_1.Centring.None,
|
|
220
220
|
controlPoints: data.controlPoints || [
|
|
221
221
|
{ x: 0, y: 0 },
|
|
@@ -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 IDiv {
|
|
8
|
+
export interface IDiv extends IBaseLayer {
|
|
8
9
|
/**
|
|
9
10
|
* The unique identifier of the group.
|
|
10
11
|
*/
|
|
@@ -26,11 +27,11 @@ export interface IDiv {
|
|
|
26
27
|
*/
|
|
27
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 IDivProps {
|
|
34
|
+
export interface IDivProps extends IBaseLayerProps {
|
|
34
35
|
/**
|
|
35
36
|
* Don't use, this is just for compatibility.
|
|
36
37
|
*/
|
|
@@ -40,7 +41,7 @@ export interface IDivProps {
|
|
|
40
41
|
/**
|
|
41
42
|
* Class representing a group of layer's.
|
|
42
43
|
*/
|
|
43
|
-
export declare class Div implements IDiv {
|
|
44
|
+
export declare class Div extends BaseLayer<IDivProps> implements IDiv {
|
|
44
45
|
/**
|
|
45
46
|
* The unique identifier of the group.
|
|
46
47
|
*/
|
|
@@ -61,14 +62,16 @@ export declare class Div implements IDiv {
|
|
|
61
62
|
* The layer's contained within the group.
|
|
62
63
|
*/
|
|
63
64
|
layers: Array<AnyLayer | Div>;
|
|
64
|
-
props
|
|
65
|
+
props: IDivProps;
|
|
66
|
+
parent?: IBaseLayer | any | null;
|
|
65
67
|
/**
|
|
66
68
|
* Constructs a new Group instance.
|
|
69
|
+
* @param {IDivProps} [props] - The properties of the Div.
|
|
67
70
|
* @param {string} [opts.id] - The unique identifier of the group.
|
|
68
71
|
* @param {boolean} [opts.visible] - The visibility of the group.
|
|
69
72
|
* @param {number} [opts.zIndex] - The z-index of the group.
|
|
70
73
|
*/
|
|
71
|
-
constructor(opts?: {
|
|
74
|
+
constructor(props?: IDivProps, opts?: {
|
|
72
75
|
id?: string;
|
|
73
76
|
visible?: boolean;
|
|
74
77
|
zIndex?: number;
|
|
@@ -4,17 +4,20 @@ exports.Div = void 0;
|
|
|
4
4
|
const types_1 = require("../../types");
|
|
5
5
|
const utils_1 = require("../../utils/utils");
|
|
6
6
|
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
7
|
+
const BaseLayer_1 = require("./BaseLayer");
|
|
7
8
|
/**
|
|
8
9
|
* Class representing a group of layer's.
|
|
9
10
|
*/
|
|
10
|
-
class Div {
|
|
11
|
+
class Div extends BaseLayer_1.BaseLayer {
|
|
11
12
|
/**
|
|
12
13
|
* Constructs a new Group instance.
|
|
14
|
+
* @param {IDivProps} [props] - The properties of the Div.
|
|
13
15
|
* @param {string} [opts.id] - The unique identifier of the group.
|
|
14
16
|
* @param {boolean} [opts.visible] - The visibility of the group.
|
|
15
17
|
* @param {number} [opts.zIndex] - The z-index of the group.
|
|
16
18
|
*/
|
|
17
|
-
constructor(opts) {
|
|
19
|
+
constructor(props, opts) {
|
|
20
|
+
super(types_1.LayerType.Group, props || {}, opts);
|
|
18
21
|
/**
|
|
19
22
|
* The type of the group, which is `Group`.
|
|
20
23
|
*/
|
|
@@ -23,7 +26,8 @@ class Div {
|
|
|
23
26
|
this.visible = opts?.visible || true;
|
|
24
27
|
this.zIndex = opts?.zIndex || 1;
|
|
25
28
|
this.layers = [];
|
|
26
|
-
this.props = {};
|
|
29
|
+
this.props = props || {};
|
|
30
|
+
this.parent = null;
|
|
27
31
|
}
|
|
28
32
|
/**
|
|
29
33
|
* Sets the ID of the group.
|
|
@@ -60,6 +64,9 @@ class Div {
|
|
|
60
64
|
add(...components) {
|
|
61
65
|
let layersArray = components.filter((l) => l !== undefined);
|
|
62
66
|
layersArray = layersArray.sort((a, b) => a.zIndex - b.zIndex);
|
|
67
|
+
for (const layer of layersArray) {
|
|
68
|
+
layer.parent = this;
|
|
69
|
+
}
|
|
63
70
|
this.layers.push(...layersArray);
|
|
64
71
|
return this;
|
|
65
72
|
}
|
|
@@ -114,6 +121,13 @@ class Div {
|
|
|
114
121
|
}
|
|
115
122
|
}
|
|
116
123
|
async draw(ctx, canvas, manager, debug) {
|
|
124
|
+
ctx.save();
|
|
125
|
+
// Apply position translation if available (from layout)
|
|
126
|
+
if (this.props.position) {
|
|
127
|
+
const x = typeof this.props.position.x === "number" ? this.props.position.x : 0;
|
|
128
|
+
const y = typeof this.props.position.y === "number" ? this.props.position.y : 0;
|
|
129
|
+
ctx.translate(x, y);
|
|
130
|
+
}
|
|
117
131
|
for (const subLayer of this.layers) {
|
|
118
132
|
if (debug)
|
|
119
133
|
LazyUtil_1.LazyLog.log("info", `Rendering ${subLayer.id}...\nData:`, subLayer.toJSON());
|
|
@@ -133,6 +147,7 @@ class Div {
|
|
|
133
147
|
}
|
|
134
148
|
}
|
|
135
149
|
}
|
|
150
|
+
ctx.restore();
|
|
136
151
|
}
|
|
137
152
|
/**
|
|
138
153
|
* Converts the group to a JSON representation.
|
|
@@ -19,10 +19,6 @@ export interface IImageLayer extends IBaseLayer {
|
|
|
19
19
|
* Interface representing the properties of an Image Layer.
|
|
20
20
|
*/
|
|
21
21
|
export interface IImageLayerProps extends IBaseLayerProps {
|
|
22
|
-
position: {
|
|
23
|
-
x: ScaleType;
|
|
24
|
-
y: ScaleType;
|
|
25
|
-
};
|
|
26
22
|
/**
|
|
27
23
|
* The source of the image, which can be a URL or a Buffer.
|
|
28
24
|
*/
|
|
@@ -60,8 +60,8 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
|
|
|
60
60
|
async draw(ctx, canvas, manager, debug) {
|
|
61
61
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
62
62
|
const { xs, ys, w } = parcer.parseBatch({
|
|
63
|
-
xs: { v: this.props.position
|
|
64
|
-
ys: { v: this.props.position
|
|
63
|
+
xs: { v: this.props.position?.x || 0 },
|
|
64
|
+
ys: { v: this.props.position?.y || 0, options: LazyUtil_1.defaultArg.vl(true) },
|
|
65
65
|
w: { v: this.props.size.width },
|
|
66
66
|
});
|
|
67
67
|
const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
|
|
@@ -43,7 +43,7 @@ class LineLayer extends BaseLayer_1.BaseLayer {
|
|
|
43
43
|
throw new LazyUtil_1.LazyError("The color of the layer must be provided");
|
|
44
44
|
if (!(0, utils_1.isColor)(color))
|
|
45
45
|
throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
|
|
46
|
-
this.props.
|
|
46
|
+
this.props.color = color;
|
|
47
47
|
return this;
|
|
48
48
|
}
|
|
49
49
|
/**
|
|
@@ -103,7 +103,7 @@ class LineLayer extends BaseLayer_1.BaseLayer {
|
|
|
103
103
|
});
|
|
104
104
|
let width = Math.abs(xe - xs);
|
|
105
105
|
let height = Math.abs(ye - ys);
|
|
106
|
-
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.
|
|
106
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, {
|
|
107
107
|
debug,
|
|
108
108
|
layer: { width, height, x: Math.min(xs, xe), y: Math.min(ys, ye), align: "none" },
|
|
109
109
|
manager,
|
|
@@ -153,7 +153,7 @@ class LineLayer extends BaseLayer_1.BaseLayer {
|
|
|
153
153
|
endX: data.position?.endX || 0,
|
|
154
154
|
endY: data.position?.endY || 0,
|
|
155
155
|
},
|
|
156
|
-
|
|
156
|
+
color: data.color || "#000000",
|
|
157
157
|
centring: data.centring || types_1.Centring.None,
|
|
158
158
|
stroke: {
|
|
159
159
|
width: data.stroke?.width || 1,
|
|
@@ -19,10 +19,6 @@ export interface IMorphLayer extends IBaseLayer {
|
|
|
19
19
|
* Interface representing the properties of a Morph Layer.
|
|
20
20
|
*/
|
|
21
21
|
export interface IMorphLayerProps extends IBaseLayerProps {
|
|
22
|
-
position: {
|
|
23
|
-
x: ScaleType;
|
|
24
|
-
y: ScaleType;
|
|
25
|
-
};
|
|
26
22
|
/**
|
|
27
23
|
* The size of the Morph Layer, including width, height, and radius.
|
|
28
24
|
*/
|
|
@@ -45,7 +41,7 @@ export interface IMorphLayerProps extends IBaseLayerProps {
|
|
|
45
41
|
/**
|
|
46
42
|
* The fill style (color or pattern) of the layer.
|
|
47
43
|
*/
|
|
48
|
-
|
|
44
|
+
color: ColorType;
|
|
49
45
|
/**
|
|
50
46
|
* The stroke properties of the morph.
|
|
51
47
|
*/
|
|
@@ -47,7 +47,7 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
|
47
47
|
throw new LazyUtil_1.LazyError("The color of the layer must be provided");
|
|
48
48
|
if (!(0, utils_1.isColor)(color))
|
|
49
49
|
throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
|
|
50
|
-
this.props.
|
|
50
|
+
this.props.color = color;
|
|
51
51
|
return this;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
@@ -81,8 +81,8 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
|
81
81
|
async draw(ctx, canvas, manager, debug) {
|
|
82
82
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
83
83
|
const { xs, ys, w } = parcer.parseBatch({
|
|
84
|
-
xs: { v: this.props.position
|
|
85
|
-
ys: { v: this.props.position
|
|
84
|
+
xs: { v: this.props.position?.x || 0 },
|
|
85
|
+
ys: { v: this.props.position?.y || 0, options: LazyUtil_1.defaultArg.vl(true) },
|
|
86
86
|
w: { v: this.props.size.width },
|
|
87
87
|
});
|
|
88
88
|
const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
|
|
@@ -96,7 +96,7 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
|
|
99
|
-
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.
|
|
99
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, {
|
|
100
100
|
debug,
|
|
101
101
|
layer: { width: w, height: h, x: xs, y: ys, align: this.props.centring },
|
|
102
102
|
manager,
|
|
@@ -153,7 +153,7 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
|
153
153
|
validateProps(data) {
|
|
154
154
|
return {
|
|
155
155
|
...super.validateProps(data),
|
|
156
|
-
|
|
156
|
+
color: data.color || "#000000",
|
|
157
157
|
size: {
|
|
158
158
|
width: data.size?.width || 100,
|
|
159
159
|
height: data.size?.height || 100,
|
|
@@ -28,7 +28,7 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
28
28
|
throw new LazyUtil_1.LazyError("The color of the layer must be provided");
|
|
29
29
|
if (!(0, utils_1.isColor)(color))
|
|
30
30
|
throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
|
|
31
|
-
this.props.
|
|
31
|
+
this.props.color = color;
|
|
32
32
|
return this;
|
|
33
33
|
}
|
|
34
34
|
setPath(path) {
|
|
@@ -136,6 +136,12 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
136
136
|
async draw(ctx, canvas, manager, debug) {
|
|
137
137
|
ctx.beginPath();
|
|
138
138
|
ctx.save();
|
|
139
|
+
if (debug)
|
|
140
|
+
LazyUtil_1.LazyLog.log("none", `Drawing Path2D Layer: `, {
|
|
141
|
+
layerId: this.id,
|
|
142
|
+
type: this.type,
|
|
143
|
+
path: this.props.path2D.toSVGString(),
|
|
144
|
+
});
|
|
139
145
|
if (this.props.transform) {
|
|
140
146
|
(0, utils_1.transform)(ctx, this.props.transform, { width: 0, height: 0, x: 0, y: 0, type: this.type });
|
|
141
147
|
}
|
|
@@ -143,8 +149,8 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
143
149
|
if (this.props.clipPath) {
|
|
144
150
|
ctx.clip(this.props.path2D);
|
|
145
151
|
}
|
|
146
|
-
else if (this.props.
|
|
147
|
-
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.
|
|
152
|
+
else if (this.props.color) {
|
|
153
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, { debug, manager });
|
|
148
154
|
if (this.props.globalComposite) {
|
|
149
155
|
ctx.globalCompositeOperation = this.props.globalComposite;
|
|
150
156
|
}
|
|
@@ -182,7 +188,7 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
182
188
|
validateProps(data) {
|
|
183
189
|
return {
|
|
184
190
|
...super.validateProps(data),
|
|
185
|
-
|
|
191
|
+
color: data.color || "#000000",
|
|
186
192
|
path2D: data.path2D || new canvas_1.Path2D(),
|
|
187
193
|
loadFromSVG: data.loadFromSVG || false,
|
|
188
194
|
clipPath: data.clipPath || false,
|
|
@@ -13,10 +13,6 @@ export interface IPolygonLayer extends IBaseLayer {
|
|
|
13
13
|
props: IPolygonLayerProps;
|
|
14
14
|
}
|
|
15
15
|
export interface IPolygonLayerProps extends IBaseLayerProps {
|
|
16
|
-
position: {
|
|
17
|
-
x: ScaleType;
|
|
18
|
-
y: ScaleType;
|
|
19
|
-
};
|
|
20
16
|
/**
|
|
21
17
|
* The size of the Polygon Layer, including width, height, and radius.
|
|
22
18
|
*/
|
|
@@ -41,7 +37,7 @@ export interface IPolygonLayerProps extends IBaseLayerProps {
|
|
|
41
37
|
/**
|
|
42
38
|
* The fill style (color or pattern) of the layer.
|
|
43
39
|
*/
|
|
44
|
-
|
|
40
|
+
color: ColorType;
|
|
45
41
|
/**
|
|
46
42
|
* The stroke properties of the polygon.
|
|
47
43
|
*/
|