@nmmty/lazycanvas 0.4.0 → 0.5.0
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/helpers/Filters.d.ts +10 -10
- package/dist/helpers/Fonts.d.ts +1 -1
- package/dist/helpers/FontsList.d.ts +1 -1
- package/dist/helpers/FontsList.js +19 -19
- package/dist/index.d.ts +11 -20
- package/dist/index.js +40 -47
- package/dist/structures/LazyCanvas.d.ts +126 -19
- package/dist/structures/LazyCanvas.js +100 -35
- package/dist/structures/components/BaseLayer.d.ts +188 -38
- package/dist/structures/components/BaseLayer.js +88 -41
- package/dist/structures/components/BezierLayer.d.ts +108 -21
- package/dist/structures/components/BezierLayer.js +73 -24
- package/dist/structures/components/ClearLayer.d.ts +120 -17
- package/dist/structures/components/ClearLayer.js +83 -22
- package/dist/structures/components/Group.d.ts +86 -18
- package/dist/structures/components/Group.js +69 -29
- package/dist/structures/components/ImageLayer.d.ts +85 -12
- package/dist/structures/components/ImageLayer.js +52 -39
- package/dist/structures/components/LineLayer.d.ts +111 -18
- package/dist/structures/components/LineLayer.js +58 -21
- package/dist/structures/components/MorphLayer.d.ts +109 -21
- package/dist/structures/components/MorphLayer.js +53 -25
- package/dist/structures/components/Path2DLayer.d.ts +191 -0
- package/dist/structures/components/Path2DLayer.js +318 -0
- package/dist/structures/components/QuadraticLayer.d.ts +108 -22
- package/dist/structures/components/QuadraticLayer.js +65 -30
- package/dist/structures/components/TextLayer.d.ts +201 -40
- package/dist/structures/components/TextLayer.js +99 -47
- package/dist/structures/components/index.d.ts +10 -0
- package/dist/structures/components/index.js +26 -0
- package/dist/structures/helpers/Exporter.d.ts +52 -0
- package/dist/structures/helpers/Exporter.js +168 -0
- package/dist/structures/helpers/Font.d.ts +64 -10
- package/dist/structures/helpers/Font.js +38 -11
- package/dist/structures/helpers/Gradient.d.ts +96 -9
- package/dist/structures/helpers/Gradient.js +48 -17
- package/dist/structures/helpers/Link.d.ts +52 -8
- package/dist/structures/helpers/Link.js +42 -11
- package/dist/structures/helpers/Pattern.d.ts +52 -7
- package/dist/structures/helpers/Pattern.js +45 -40
- package/dist/structures/helpers/index.d.ts +6 -0
- package/dist/structures/helpers/index.js +22 -0
- package/dist/structures/helpers/readers/JSONReader.d.ts +49 -0
- package/dist/structures/helpers/readers/JSONReader.js +172 -0
- package/dist/structures/helpers/readers/SVGReader.d.ts +20 -0
- package/dist/structures/helpers/readers/SVGReader.js +577 -0
- package/dist/structures/helpers/readers/YAMLReader.d.ts +0 -0
- package/dist/structures/helpers/readers/YAMLReader.js +1 -0
- package/dist/structures/managers/AnimationManager.d.ts +96 -20
- package/dist/structures/managers/AnimationManager.js +54 -26
- package/dist/structures/managers/FontsManager.d.ts +76 -32
- package/dist/structures/managers/FontsManager.js +70 -45
- package/dist/structures/managers/LayersManager.d.ts +84 -32
- package/dist/structures/managers/LayersManager.js +66 -28
- package/dist/structures/managers/RenderManager.d.ts +60 -6
- package/dist/structures/managers/RenderManager.js +120 -40
- package/dist/types/enum.d.ts +11 -6
- package/dist/types/enum.js +17 -12
- package/dist/types/index.d.ts +2 -19
- package/dist/types/index.js +17 -0
- package/dist/utils/LazyUtil.js +2 -2
- package/dist/utils/utils.d.ts +10 -9
- package/dist/utils/utils.js +159 -164
- package/package.json +4 -5
|
@@ -2,23 +2,35 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BezierLayer = void 0;
|
|
4
4
|
const BaseLayer_1 = require("./BaseLayer");
|
|
5
|
-
const
|
|
5
|
+
const types_1 = require("../../types");
|
|
6
6
|
const utils_1 = require("../../utils/utils");
|
|
7
7
|
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
8
|
-
const
|
|
9
|
-
|
|
8
|
+
const helpers_1 = require("../helpers");
|
|
9
|
+
/**
|
|
10
|
+
* Class representing a Bezier layer, extending the BaseLayer class.
|
|
11
|
+
*/
|
|
10
12
|
class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
13
|
+
/**
|
|
14
|
+
* The properties of the Bezier layer.
|
|
15
|
+
*/
|
|
11
16
|
props;
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Constructs a new BezierLayer instance.
|
|
19
|
+
* @param props {IBezierLayerProps} - The properties of the Bezier layer.
|
|
20
|
+
* @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
|
|
21
|
+
*/
|
|
22
|
+
constructor(props, misc) {
|
|
23
|
+
super(types_1.LayerType.BezierCurve, props || {}, misc);
|
|
14
24
|
this.props = props ? props : {};
|
|
15
25
|
if (!this.props.fillStyle)
|
|
16
26
|
this.props.fillStyle = '#000000';
|
|
17
|
-
this.props.centring =
|
|
27
|
+
this.props.centring = types_1.Centring.None;
|
|
18
28
|
}
|
|
19
29
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param controlPoints {Array<{ x: ScaleType, y: ScaleType }>} - The
|
|
30
|
+
* Sets the control points of the Bezier layer.
|
|
31
|
+
* @param controlPoints {Array<{ x: ScaleType, y: ScaleType }>} - The control points of the Bezier layer.
|
|
32
|
+
* @returns {this} The current instance for chaining.
|
|
33
|
+
* @throws {LazyError} If the number of control points is not exactly 2.
|
|
22
34
|
*/
|
|
23
35
|
setControlPoints(...controlPoints) {
|
|
24
36
|
if (controlPoints.length !== 2)
|
|
@@ -27,17 +39,20 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
27
39
|
return this;
|
|
28
40
|
}
|
|
29
41
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param x {ScaleType} - The
|
|
32
|
-
* @param y {ScaleType} - The
|
|
42
|
+
* Sets the end position of the Bezier layer.
|
|
43
|
+
* @param x {ScaleType} - The x-coordinate of the end point.
|
|
44
|
+
* @param y {ScaleType} - The y-coordinate of the end point.
|
|
45
|
+
* @returns {this} The current instance for chaining.
|
|
33
46
|
*/
|
|
34
47
|
setEndPosition(x, y) {
|
|
35
48
|
this.props.endPoint = { x, y };
|
|
36
49
|
return this;
|
|
37
50
|
}
|
|
38
51
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @param color {
|
|
52
|
+
* Sets the color of the Bezier layer.
|
|
53
|
+
* @param color {ColorType} - The color of the layer.
|
|
54
|
+
* @returns {this} The current instance for chaining.
|
|
55
|
+
* @throws {LazyError} If the color is not provided or invalid.
|
|
41
56
|
*/
|
|
42
57
|
setColor(color) {
|
|
43
58
|
if (!color)
|
|
@@ -45,7 +60,7 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
45
60
|
if (!(0, utils_1.isColor)(color))
|
|
46
61
|
throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
|
|
47
62
|
let fill = (0, utils_1.parseColor)(color);
|
|
48
|
-
if (fill instanceof
|
|
63
|
+
if (fill instanceof helpers_1.Gradient || fill instanceof helpers_1.Pattern) {
|
|
49
64
|
this.props.fillStyle = fill;
|
|
50
65
|
}
|
|
51
66
|
else {
|
|
@@ -56,13 +71,14 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
56
71
|
return this;
|
|
57
72
|
}
|
|
58
73
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @param width {number} - The
|
|
61
|
-
* @param cap {string} - The
|
|
62
|
-
* @param join {string} - The
|
|
63
|
-
* @param dash {number[]} - The
|
|
64
|
-
* @param dashOffset {number} - The
|
|
65
|
-
* @param miterLimit {number} - The
|
|
74
|
+
* Sets the stroke properties of the Bezier layer.
|
|
75
|
+
* @param width {number} - The width of the stroke.
|
|
76
|
+
* @param cap {string} - The cap style of the stroke.
|
|
77
|
+
* @param join {string} - The join style of the stroke.
|
|
78
|
+
* @param dash {number[]} - The dash pattern of the stroke.
|
|
79
|
+
* @param dashOffset {number} - The dash offset of the stroke.
|
|
80
|
+
* @param miterLimit {number} - The miter limit of the stroke.
|
|
81
|
+
* @returns {this} The current instance for chaining.
|
|
66
82
|
*/
|
|
67
83
|
setStroke(width, cap, join, dash, dashOffset, miterLimit) {
|
|
68
84
|
this.props.stroke = {
|
|
@@ -75,6 +91,13 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
75
91
|
};
|
|
76
92
|
return this;
|
|
77
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* Calculates the bounding box of the Bezier layer.
|
|
96
|
+
* @param ctx {SKRSContext2D} - The canvas rendering context.
|
|
97
|
+
* @param canvas {Canvas | SvgCanvas} - The canvas instance.
|
|
98
|
+
* @param manager {LayersManager} - The layers manager.
|
|
99
|
+
* @returns {Object} The bounding box details including max, min, center, width, and height.
|
|
100
|
+
*/
|
|
78
101
|
getBoundingBox(ctx, canvas, manager) {
|
|
79
102
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
80
103
|
const { xs, ys, cp1x, cp1y, cp2x, cp2y, xe, ye } = parcer.parseBatch({
|
|
@@ -90,6 +113,13 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
90
113
|
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 }]);
|
|
91
114
|
return { max, min, center, width, height };
|
|
92
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Draws the Bezier layer on the canvas.
|
|
118
|
+
* @param ctx {SKRSContext2D} - The canvas rendering context.
|
|
119
|
+
* @param canvas {Canvas | SvgCanvas} - The canvas instance.
|
|
120
|
+
* @param manager {LayersManager} - The layers manager.
|
|
121
|
+
* @param debug {boolean} - Whether to enable debug logging.
|
|
122
|
+
*/
|
|
93
123
|
async draw(ctx, canvas, manager, debug) {
|
|
94
124
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
95
125
|
const { xs, ys, cp1x, cp1y, cp2x, cp2y, xe, ye } = parcer.parseBatch({
|
|
@@ -126,12 +156,31 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
126
156
|
ctx.restore();
|
|
127
157
|
}
|
|
128
158
|
/**
|
|
129
|
-
*
|
|
159
|
+
* Converts the Bezier layer to a JSON representation.
|
|
160
|
+
* @returns {IBezierLayer} The JSON representation of the Bezier layer.
|
|
130
161
|
*/
|
|
131
162
|
toJSON() {
|
|
132
163
|
let data = super.toJSON();
|
|
133
|
-
|
|
134
|
-
|
|
164
|
+
let copy = { ...this.props };
|
|
165
|
+
for (const key of ['x', 'y', 'endPoint.x', 'endPoint.y', 'fillStyle']) {
|
|
166
|
+
if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
|
|
167
|
+
copy[key] = copy[key].toJSON();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
if (copy.controlPoints) {
|
|
171
|
+
copy.controlPoints = copy.controlPoints.map((point) => {
|
|
172
|
+
if (point.x && typeof point.x === 'object' && 'toJSON' in point.x) {
|
|
173
|
+
// @ts-ignore
|
|
174
|
+
point.x = point.x.toJSON();
|
|
175
|
+
}
|
|
176
|
+
if (point.y && typeof point.y === 'object' && 'toJSON' in point.y) {
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
point.y = point.y.toJSON();
|
|
179
|
+
}
|
|
180
|
+
return point;
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
return { ...data, props: copy };
|
|
135
184
|
}
|
|
136
185
|
}
|
|
137
186
|
exports.BezierLayer = BezierLayer;
|
|
@@ -1,39 +1,142 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
|
|
1
|
+
import { ScaleType, LayerType, AnyCentring } from "../../types";
|
|
2
|
+
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
|
|
4
3
|
import { LayersManager } from "../managers/LayersManager";
|
|
4
|
+
import { IBaseLayerMisc } from "./BaseLayer";
|
|
5
|
+
/**
|
|
6
|
+
* Interface representing a Clear Layer.
|
|
7
|
+
*/
|
|
8
|
+
export interface IClearLayer {
|
|
9
|
+
/**
|
|
10
|
+
* The unique identifier of the layer.
|
|
11
|
+
*/
|
|
12
|
+
id: string;
|
|
13
|
+
/**
|
|
14
|
+
* The type of the layer, which is `Clear`.
|
|
15
|
+
*/
|
|
16
|
+
type: LayerType.Clear;
|
|
17
|
+
/**
|
|
18
|
+
* The z-index of the layer, determining its stacking order.
|
|
19
|
+
*/
|
|
20
|
+
zIndex: number;
|
|
21
|
+
/**
|
|
22
|
+
* The visibility of the layer.
|
|
23
|
+
*/
|
|
24
|
+
visible: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* The properties of the Clear Layer.
|
|
27
|
+
*/
|
|
28
|
+
props: IClearLayerProps;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Interface representing the properties of a Clear Layer.
|
|
32
|
+
*/
|
|
33
|
+
export interface IClearLayerProps {
|
|
34
|
+
/**
|
|
35
|
+
* The x-coordinate of the layer.
|
|
36
|
+
*/
|
|
37
|
+
x: ScaleType;
|
|
38
|
+
/**
|
|
39
|
+
* The y-coordinate of the layer.
|
|
40
|
+
*/
|
|
41
|
+
y: ScaleType;
|
|
42
|
+
/**
|
|
43
|
+
* The size of the layer, including width and height.
|
|
44
|
+
*/
|
|
45
|
+
size: {
|
|
46
|
+
/**
|
|
47
|
+
* The width of the layer.
|
|
48
|
+
*/
|
|
49
|
+
width: ScaleType;
|
|
50
|
+
/**
|
|
51
|
+
* The height of the layer.
|
|
52
|
+
*/
|
|
53
|
+
height: ScaleType;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The centring type of the layer.
|
|
57
|
+
*/
|
|
58
|
+
centring: AnyCentring;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Class representing a Clear Layer.
|
|
62
|
+
*/
|
|
5
63
|
export declare class ClearLayer implements IClearLayer {
|
|
64
|
+
/**
|
|
65
|
+
* The unique identifier of the layer.
|
|
66
|
+
*/
|
|
6
67
|
id: string;
|
|
7
|
-
|
|
68
|
+
/**
|
|
69
|
+
* The type of the layer, which is `Clear`.
|
|
70
|
+
*/
|
|
71
|
+
type: LayerType.Clear;
|
|
72
|
+
/**
|
|
73
|
+
* The z-index of the layer, determining its stacking order.
|
|
74
|
+
*/
|
|
8
75
|
zIndex: number;
|
|
76
|
+
/**
|
|
77
|
+
* The visibility of the layer.
|
|
78
|
+
*/
|
|
9
79
|
visible: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* The properties of the Clear Layer.
|
|
82
|
+
*/
|
|
10
83
|
props: IClearLayerProps;
|
|
11
|
-
constructor(props?: IClearLayerProps);
|
|
12
84
|
/**
|
|
13
|
-
*
|
|
14
|
-
* @param
|
|
15
|
-
* @param
|
|
85
|
+
* Constructs a new ClearLayer instance.
|
|
86
|
+
* @param props {IClearLayerProps} - The properties of the Clear Layer.
|
|
87
|
+
* @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
|
|
88
|
+
*/
|
|
89
|
+
constructor(props?: IClearLayerProps, misc?: IBaseLayerMisc);
|
|
90
|
+
/**
|
|
91
|
+
* Sets the position of the layer in the 2D plane.
|
|
92
|
+
* @param x {ScaleType} - The x-coordinate of the layer.
|
|
93
|
+
* @param y {ScaleType} - The y-coordinate of the layer.
|
|
94
|
+
* @returns {this} The current instance for chaining.
|
|
16
95
|
*/
|
|
17
96
|
setPosition(x: ScaleType, y: ScaleType): this;
|
|
18
97
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @param width {ScaleType} - The
|
|
21
|
-
* @param height {ScaleType} - The
|
|
98
|
+
* Sets the size of the layer.
|
|
99
|
+
* @param width {ScaleType} - The width of the layer.
|
|
100
|
+
* @param height {ScaleType} - The height of the layer.
|
|
101
|
+
* @returns {this} The current instance for chaining.
|
|
22
102
|
*/
|
|
23
103
|
setSize(width: ScaleType, height: ScaleType): this;
|
|
24
104
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
105
|
+
* Sets the unique identifier of the layer.
|
|
106
|
+
*
|
|
107
|
+
* @param {string} id - The unique identifier.
|
|
108
|
+
* @returns {this} The current instance for chaining.
|
|
109
|
+
*/
|
|
110
|
+
setID(id: string): this;
|
|
111
|
+
/**
|
|
112
|
+
* Sets the centring type of the layer.
|
|
113
|
+
* @param centring {AnyCentring} - The centring type of the layer.
|
|
114
|
+
* @returns {this} The current instance for chaining.
|
|
115
|
+
*/
|
|
116
|
+
setCentring(centring: AnyCentring): this;
|
|
117
|
+
/**
|
|
118
|
+
* Sets the visibility of the layer.
|
|
119
|
+
* @param visible {boolean} - The visibility state of the layer.
|
|
120
|
+
* @returns {this} The current instance for chaining.
|
|
27
121
|
*/
|
|
28
122
|
setVisible(visible: boolean): this;
|
|
29
123
|
/**
|
|
30
|
-
*
|
|
31
|
-
* @param zIndex {number} - The
|
|
124
|
+
* Sets the z-index of the layer.
|
|
125
|
+
* @param zIndex {number} - The z-index value of the layer.
|
|
126
|
+
* @returns {this} The current instance for chaining.
|
|
32
127
|
*/
|
|
33
128
|
setZIndex(zIndex: number): this;
|
|
34
|
-
draw(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager, debug: boolean): Promise<void>;
|
|
35
129
|
/**
|
|
36
|
-
*
|
|
130
|
+
* Draws the Clear Layer on the canvas.
|
|
131
|
+
* @param ctx {SKRSContext2D} - The canvas rendering context.
|
|
132
|
+
* @param canvas {Canvas | SvgCanvas} - The canvas instance.
|
|
133
|
+
* @param manager {LayersManager} - The layers manager.
|
|
134
|
+
* @param debug {boolean} - Whether to enable debug logging.
|
|
135
|
+
*/
|
|
136
|
+
draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
|
|
137
|
+
/**
|
|
138
|
+
* Converts the Clear Layer to a JSON representation.
|
|
139
|
+
* @returns {IClearLayer} The JSON representation of the Clear Layer.
|
|
37
140
|
*/
|
|
38
141
|
toJSON(): IClearLayer;
|
|
39
142
|
}
|
|
@@ -1,21 +1,44 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ClearLayer = void 0;
|
|
4
|
-
const
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
5
|
const utils_1 = require("../../utils/utils");
|
|
6
6
|
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
7
7
|
const utils_2 = require("../../utils/utils");
|
|
8
|
+
/**
|
|
9
|
+
* Class representing a Clear Layer.
|
|
10
|
+
*/
|
|
8
11
|
class ClearLayer {
|
|
12
|
+
/**
|
|
13
|
+
* The unique identifier of the layer.
|
|
14
|
+
*/
|
|
9
15
|
id;
|
|
10
|
-
|
|
16
|
+
/**
|
|
17
|
+
* The type of the layer, which is `Clear`.
|
|
18
|
+
*/
|
|
19
|
+
type = types_1.LayerType.Clear;
|
|
20
|
+
/**
|
|
21
|
+
* The z-index of the layer, determining its stacking order.
|
|
22
|
+
*/
|
|
11
23
|
zIndex;
|
|
24
|
+
/**
|
|
25
|
+
* The visibility of the layer.
|
|
26
|
+
*/
|
|
12
27
|
visible;
|
|
28
|
+
/**
|
|
29
|
+
* The properties of the Clear Layer.
|
|
30
|
+
*/
|
|
13
31
|
props;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Constructs a new ClearLayer instance.
|
|
34
|
+
* @param props {IClearLayerProps} - The properties of the Clear Layer.
|
|
35
|
+
* @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
|
|
36
|
+
*/
|
|
37
|
+
constructor(props, misc) {
|
|
38
|
+
this.id = misc?.id || (0, utils_2.generateID)(types_1.LayerType.Clear);
|
|
39
|
+
this.type = types_1.LayerType.Clear;
|
|
40
|
+
this.zIndex = misc?.zIndex || 1;
|
|
41
|
+
this.visible = misc?.visible || true;
|
|
19
42
|
this.props = props ? props : {
|
|
20
43
|
x: 0,
|
|
21
44
|
y: 0,
|
|
@@ -26,9 +49,10 @@ class ClearLayer {
|
|
|
26
49
|
};
|
|
27
50
|
}
|
|
28
51
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @param x {ScaleType} - The
|
|
31
|
-
* @param y {ScaleType} - The
|
|
52
|
+
* Sets the position of the layer in the 2D plane.
|
|
53
|
+
* @param x {ScaleType} - The x-coordinate of the layer.
|
|
54
|
+
* @param y {ScaleType} - The y-coordinate of the layer.
|
|
55
|
+
* @returns {this} The current instance for chaining.
|
|
32
56
|
*/
|
|
33
57
|
setPosition(x, y) {
|
|
34
58
|
this.props.x = x;
|
|
@@ -36,9 +60,10 @@ class ClearLayer {
|
|
|
36
60
|
return this;
|
|
37
61
|
}
|
|
38
62
|
/**
|
|
39
|
-
*
|
|
40
|
-
* @param width {ScaleType} - The
|
|
41
|
-
* @param height {ScaleType} - The
|
|
63
|
+
* Sets the size of the layer.
|
|
64
|
+
* @param width {ScaleType} - The width of the layer.
|
|
65
|
+
* @param height {ScaleType} - The height of the layer.
|
|
66
|
+
* @returns {this} The current instance for chaining.
|
|
42
67
|
*/
|
|
43
68
|
setSize(width, height) {
|
|
44
69
|
this.props.size = {
|
|
@@ -48,43 +73,79 @@ class ClearLayer {
|
|
|
48
73
|
return this;
|
|
49
74
|
}
|
|
50
75
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
76
|
+
* Sets the unique identifier of the layer.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} id - The unique identifier.
|
|
79
|
+
* @returns {this} The current instance for chaining.
|
|
80
|
+
*/
|
|
81
|
+
setID(id) {
|
|
82
|
+
this.id = id;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Sets the centring type of the layer.
|
|
87
|
+
* @param centring {AnyCentring} - The centring type of the layer.
|
|
88
|
+
* @returns {this} The current instance for chaining.
|
|
89
|
+
*/
|
|
90
|
+
setCentring(centring) {
|
|
91
|
+
this.props.centring = centring;
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Sets the visibility of the layer.
|
|
96
|
+
* @param visible {boolean} - The visibility state of the layer.
|
|
97
|
+
* @returns {this} The current instance for chaining.
|
|
53
98
|
*/
|
|
54
99
|
setVisible(visible) {
|
|
55
100
|
this.visible = visible;
|
|
56
101
|
return this;
|
|
57
102
|
}
|
|
58
103
|
/**
|
|
59
|
-
*
|
|
60
|
-
* @param zIndex {number} - The
|
|
104
|
+
* Sets the z-index of the layer.
|
|
105
|
+
* @param zIndex {number} - The z-index value of the layer.
|
|
106
|
+
* @returns {this} The current instance for chaining.
|
|
61
107
|
*/
|
|
62
108
|
setZIndex(zIndex) {
|
|
63
109
|
this.zIndex = zIndex;
|
|
64
110
|
return this;
|
|
65
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Draws the Clear Layer on the canvas.
|
|
114
|
+
* @param ctx {SKRSContext2D} - The canvas rendering context.
|
|
115
|
+
* @param canvas {Canvas | SvgCanvas} - The canvas instance.
|
|
116
|
+
* @param manager {LayersManager} - The layers manager.
|
|
117
|
+
* @param debug {boolean} - Whether to enable debug logging.
|
|
118
|
+
*/
|
|
66
119
|
async draw(ctx, canvas, manager, debug) {
|
|
67
120
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
68
|
-
const {
|
|
69
|
-
|
|
70
|
-
|
|
121
|
+
const { xs, ys, w } = parcer.parseBatch({
|
|
122
|
+
xs: { v: this.props.x },
|
|
123
|
+
ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
|
|
71
124
|
w: { v: this.props.size.width },
|
|
72
125
|
});
|
|
73
126
|
const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
|
|
127
|
+
let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
|
|
74
128
|
if (debug)
|
|
75
129
|
LazyUtil_1.LazyLog.log('none', `ClearLayer:`, { x, y, w, h });
|
|
76
130
|
ctx.clearRect(x, y, w, h);
|
|
77
131
|
}
|
|
78
132
|
/**
|
|
79
|
-
*
|
|
133
|
+
* Converts the Clear Layer to a JSON representation.
|
|
134
|
+
* @returns {IClearLayer} The JSON representation of the Clear Layer.
|
|
80
135
|
*/
|
|
81
136
|
toJSON() {
|
|
137
|
+
let copy = { ...this.props };
|
|
138
|
+
for (const key of ['x', 'y', 'size.width', 'size.height']) {
|
|
139
|
+
if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
|
|
140
|
+
copy[key] = copy[key].toJSON();
|
|
141
|
+
}
|
|
142
|
+
}
|
|
82
143
|
return {
|
|
83
144
|
id: this.id,
|
|
84
145
|
type: this.type,
|
|
85
146
|
zIndex: this.zIndex,
|
|
86
147
|
visible: this.visible,
|
|
87
|
-
props:
|
|
148
|
+
props: copy,
|
|
88
149
|
};
|
|
89
150
|
}
|
|
90
151
|
}
|
|
@@ -1,51 +1,119 @@
|
|
|
1
|
-
import { AnyLayer,
|
|
1
|
+
import { AnyLayer, LayerType } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Interface representing a group of layers.
|
|
4
|
+
*/
|
|
5
|
+
export interface IGroup {
|
|
6
|
+
/**
|
|
7
|
+
* The unique identifier of the group.
|
|
8
|
+
*/
|
|
9
|
+
id: string;
|
|
10
|
+
/**
|
|
11
|
+
* The type of the group, which is `Group`.
|
|
12
|
+
*/
|
|
13
|
+
type: LayerType.Group;
|
|
14
|
+
/**
|
|
15
|
+
* The visibility of the group.
|
|
16
|
+
*/
|
|
17
|
+
visible: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The z-index of the group, determining its stacking order.
|
|
20
|
+
*/
|
|
21
|
+
zIndex: number;
|
|
22
|
+
/**
|
|
23
|
+
* The layers contained within the group.
|
|
24
|
+
*/
|
|
25
|
+
layers: Array<AnyLayer>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Class representing a group of layers.
|
|
29
|
+
*/
|
|
2
30
|
export declare class Group implements IGroup {
|
|
31
|
+
/**
|
|
32
|
+
* The unique identifier of the group.
|
|
33
|
+
*/
|
|
3
34
|
id: string;
|
|
35
|
+
/**
|
|
36
|
+
* The type of the group, which is `Group`.
|
|
37
|
+
*/
|
|
38
|
+
type: LayerType.Group;
|
|
39
|
+
/**
|
|
40
|
+
* The visibility of the group.
|
|
41
|
+
*/
|
|
4
42
|
visible: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* The z-index of the group, determining its stacking order.
|
|
45
|
+
*/
|
|
5
46
|
zIndex: number;
|
|
6
|
-
components: Array<any>;
|
|
7
|
-
constructor();
|
|
8
47
|
/**
|
|
9
|
-
*
|
|
10
|
-
|
|
48
|
+
* The layers contained within the group.
|
|
49
|
+
*/
|
|
50
|
+
layers: Array<any>;
|
|
51
|
+
/**
|
|
52
|
+
* Constructs a new Group instance.
|
|
53
|
+
* @param opts {Object} - Optional parameters for the group.
|
|
54
|
+
* @param opts.id {string} - The unique identifier of the group.
|
|
55
|
+
* @param opts.visible {boolean} - The visibility of the group.
|
|
56
|
+
* @param opts.zIndex {number} - The z-index of the group.
|
|
57
|
+
*/
|
|
58
|
+
constructor(opts?: {
|
|
59
|
+
id?: string;
|
|
60
|
+
visible?: boolean;
|
|
61
|
+
zIndex?: number;
|
|
62
|
+
});
|
|
63
|
+
/**
|
|
64
|
+
* Sets the ID of the group.
|
|
65
|
+
* @param id {string} - The unique identifier of the group.
|
|
66
|
+
* @returns {this} The current instance for chaining.
|
|
11
67
|
*/
|
|
12
68
|
setID(id: string): this;
|
|
13
69
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @param visible {boolean} - The
|
|
70
|
+
* Sets the visibility of the group.
|
|
71
|
+
* @param visible {boolean} - The visibility state of the group.
|
|
72
|
+
* @returns {this} The current instance for chaining.
|
|
16
73
|
*/
|
|
17
74
|
setVisible(visible: boolean): this;
|
|
18
75
|
/**
|
|
19
|
-
*
|
|
20
|
-
* @param zIndex {number} - The
|
|
76
|
+
* Sets the z-index of the group.
|
|
77
|
+
* @param zIndex {number} - The z-index value of the group.
|
|
78
|
+
* @returns {this} The current instance for chaining.
|
|
21
79
|
*/
|
|
22
80
|
setZIndex(zIndex: number): this;
|
|
23
81
|
/**
|
|
24
|
-
*
|
|
25
|
-
* @param components {
|
|
82
|
+
* Adds components to the group.
|
|
83
|
+
* @param components {AnyLayer[]} - The components to add to the group.
|
|
84
|
+
* @returns {this} The current instance for chaining.
|
|
26
85
|
*/
|
|
27
86
|
add(...components: AnyLayer[]): this;
|
|
28
87
|
/**
|
|
29
|
-
*
|
|
30
|
-
* @param id {
|
|
88
|
+
* Removes a component from the group by its ID.
|
|
89
|
+
* @param id {string} - The unique identifier of the component to remove.
|
|
90
|
+
* @returns {this} The current instance for chaining.
|
|
31
91
|
*/
|
|
32
92
|
remove(id: string): this;
|
|
33
93
|
/**
|
|
34
|
-
*
|
|
94
|
+
* Clears all components from the group.
|
|
95
|
+
* @returns {this} The current instance for chaining.
|
|
35
96
|
*/
|
|
36
97
|
clear(): this;
|
|
37
98
|
/**
|
|
38
|
-
*
|
|
39
|
-
* @param id {string} - The
|
|
99
|
+
* Retrieves a component from the group by its ID.
|
|
100
|
+
* @param id {string} - The unique identifier of the component to retrieve.
|
|
101
|
+
* @returns {AnyLayer | undefined} The component with the specified ID, or undefined if not found.
|
|
40
102
|
*/
|
|
41
103
|
get(id: string): any;
|
|
42
104
|
/**
|
|
43
|
-
*
|
|
105
|
+
* Retrieves all components from the group.
|
|
106
|
+
* @returns {AnyLayer[]} An array of all components in the group.
|
|
44
107
|
*/
|
|
45
108
|
getAll(): any[];
|
|
46
109
|
/**
|
|
47
|
-
*
|
|
110
|
+
* Gets the number of components in the group.
|
|
111
|
+
* @returns {number} The number of components in the group.
|
|
48
112
|
*/
|
|
49
113
|
get length(): number;
|
|
114
|
+
/**
|
|
115
|
+
* Converts the group to a JSON representation.
|
|
116
|
+
* @returns {IGroup} The JSON representation of the group.
|
|
117
|
+
*/
|
|
50
118
|
toJSON(): IGroup;
|
|
51
119
|
}
|