@nmmty/lazycanvas 0.6.5 → 1.0.0-dev.3
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/biome.json +41 -0
- package/dist/core/Interpolation.d.ts +30 -0
- package/dist/core/Interpolation.js +200 -0
- package/dist/core/Scene.d.ts +96 -0
- package/dist/core/Scene.js +172 -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/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 +15 -18
- package/dist/helpers/index.d.ts +3 -3
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/jsx-runtime.d.ts +17 -0
- package/dist/jsx-runtime.js +111 -0
- package/dist/structures/LazyCanvas.d.ts +3 -45
- package/dist/structures/LazyCanvas.js +11 -74
- package/dist/structures/components/BaseLayer.d.ts +34 -12
- package/dist/structures/components/BaseLayer.js +68 -35
- package/dist/structures/components/BezierLayer.d.ts +16 -37
- package/dist/structures/components/BezierLayer.js +83 -46
- package/dist/structures/components/{Group.d.ts → Div.d.ts} +22 -16
- package/dist/structures/components/{Group.js → Div.js} +38 -39
- package/dist/structures/components/ImageLayer.d.ts +1 -1
- package/dist/structures/components/ImageLayer.js +24 -25
- package/dist/structures/components/LineLayer.d.ts +11 -37
- package/dist/structures/components/LineLayer.js +42 -42
- package/dist/structures/components/MorphLayer.d.ts +3 -32
- package/dist/structures/components/MorphLayer.js +32 -46
- package/dist/structures/components/Path2DLayer.d.ts +4 -32
- package/dist/structures/components/Path2DLayer.js +28 -33
- package/dist/structures/components/PolygonLayer.d.ts +2 -31
- package/dist/structures/components/PolygonLayer.js +35 -38
- package/dist/structures/components/QuadraticLayer.d.ts +16 -33
- package/dist/structures/components/QuadraticLayer.js +80 -42
- package/dist/structures/components/TextLayer.d.ts +4 -33
- package/dist/structures/components/TextLayer.js +60 -62
- 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 +79 -42
- package/dist/structures/helpers/Font.js +1 -17
- package/dist/structures/helpers/Gradient.js +32 -45
- package/dist/structures/helpers/Link.js +2 -14
- package/dist/structures/helpers/Pattern.js +9 -17
- 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 +32 -40
- package/dist/structures/helpers/readers/YAMLReader.js +5 -5
- 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/RenderManager.d.ts +1 -15
- package/dist/structures/managers/RenderManager.js +17 -110
- package/dist/structures/managers/index.d.ts +3 -5
- package/dist/structures/managers/index.js +0 -2
- 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/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/utils.d.ts +4 -7
- package/dist/utils/utils.js +133 -76
- package/package.json +62 -59
- package/dist/structures/components/ClearLayer.d.ts +0 -147
- package/dist/structures/components/ClearLayer.js +0 -158
- 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/types/types.d.ts +0 -107
|
@@ -8,32 +8,16 @@ const utils_1 = require("../../utils/utils");
|
|
|
8
8
|
* Class representing a gradient with properties and methods to manipulate it.
|
|
9
9
|
*/
|
|
10
10
|
class Gradient {
|
|
11
|
-
/**
|
|
12
|
-
* The type of fill, which is always `Gradient`.
|
|
13
|
-
*/
|
|
14
|
-
fillType = types_1.FillType.Gradient;
|
|
15
|
-
/**
|
|
16
|
-
* The type of gradient (e.g., linear, radial, conic).
|
|
17
|
-
*/
|
|
18
|
-
type;
|
|
19
|
-
/**
|
|
20
|
-
* The points defining the gradient.
|
|
21
|
-
*/
|
|
22
|
-
points;
|
|
23
|
-
/**
|
|
24
|
-
* The color stops for the gradient.
|
|
25
|
-
*/
|
|
26
|
-
stops;
|
|
27
|
-
/**
|
|
28
|
-
* The angle of the gradient (optional, used for linear gradients).
|
|
29
|
-
*/
|
|
30
|
-
angle;
|
|
31
11
|
/**
|
|
32
12
|
* Constructs a new Gradient instance.
|
|
33
13
|
* @param {Object} [opts] - Optional properties for the gradient.
|
|
34
14
|
* @param {IGradient} [opts.props] - The gradient properties.
|
|
35
15
|
*/
|
|
36
16
|
constructor(opts) {
|
|
17
|
+
/**
|
|
18
|
+
* The type of fill, which is always `Gradient`.
|
|
19
|
+
*/
|
|
20
|
+
this.fillType = types_1.FillType.Gradient;
|
|
37
21
|
this.type = opts?.props?.type || types_1.GradientType.Linear;
|
|
38
22
|
this.points = opts?.props?.points || [];
|
|
39
23
|
this.stops = opts?.props?.stops || [];
|
|
@@ -115,33 +99,36 @@ class Gradient {
|
|
|
115
99
|
let gradientData = this.toJSON();
|
|
116
100
|
let gradient;
|
|
117
101
|
if (opts.debug)
|
|
118
|
-
LazyUtil_1.LazyLog.log(
|
|
102
|
+
LazyUtil_1.LazyLog.log("none", `Gradient:`, gradientData);
|
|
119
103
|
const parse = (0, utils_1.parser)(ctx, ctx.canvas, opts.manager);
|
|
120
104
|
const { x0, y0, x1, y1 } = parse.parseBatch({
|
|
121
105
|
x0: { v: gradientData.points[0]?.x || 0 },
|
|
122
106
|
y0: { v: gradientData.points[0]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) },
|
|
123
107
|
x1: { v: gradientData.points[1]?.x || 0 },
|
|
124
|
-
y1: { v: gradientData.points[1]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) }
|
|
108
|
+
y1: { v: gradientData.points[1]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) },
|
|
125
109
|
});
|
|
126
110
|
if (opts.debug)
|
|
127
|
-
LazyUtil_1.LazyLog.log(
|
|
111
|
+
LazyUtil_1.LazyLog.log("none", `Gradient points:`, { x0, y0, x1, y1 });
|
|
128
112
|
switch (gradientData.type) {
|
|
129
113
|
case types_1.GradientType.Linear:
|
|
130
114
|
case "linear":
|
|
131
|
-
if (gradientData.type === "linear" &&
|
|
115
|
+
if (gradientData.type === "linear" &&
|
|
116
|
+
(gradientData.angle || gradientData.angle === 0) &&
|
|
117
|
+
opts.layer &&
|
|
118
|
+
gradientData.points.length < 2) {
|
|
132
119
|
const { width, height, x, y, align } = opts.layer;
|
|
133
|
-
const cx = this.getPosition(x, width, align,
|
|
134
|
-
const cy = this.getPosition(y, height, align,
|
|
120
|
+
const cx = this.getPosition(x, width, align, "x");
|
|
121
|
+
const cy = this.getPosition(y, height, align, "y");
|
|
135
122
|
if (opts.debug)
|
|
136
|
-
LazyUtil_1.LazyLog.log(
|
|
123
|
+
LazyUtil_1.LazyLog.log("none", `Center for angle calculation:`, { cx, cy });
|
|
137
124
|
const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
|
|
138
125
|
if (opts.debug)
|
|
139
|
-
LazyUtil_1.LazyLog.log(
|
|
126
|
+
LazyUtil_1.LazyLog.log("none", `Linear Gradient Points from angle:`, { p1, p2 });
|
|
140
127
|
gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
|
|
141
128
|
}
|
|
142
129
|
else {
|
|
143
130
|
if (opts.debug)
|
|
144
|
-
LazyUtil_1.LazyLog.log(
|
|
131
|
+
LazyUtil_1.LazyLog.log("none", `Linear Gradient created from points.`);
|
|
145
132
|
gradient = ctx.createLinearGradient(x0, y0, x1 || x0, y1 || y0);
|
|
146
133
|
}
|
|
147
134
|
break;
|
|
@@ -156,8 +143,8 @@ class Gradient {
|
|
|
156
143
|
default:
|
|
157
144
|
if ((gradientData.angle || gradientData.angle === 0) && opts.layer) {
|
|
158
145
|
const { width, height, x, y, align } = opts.layer;
|
|
159
|
-
const cx = this.getPosition(x, width, align,
|
|
160
|
-
const cy = this.getPosition(y, height, align,
|
|
146
|
+
const cx = this.getPosition(x, width, align, "x");
|
|
147
|
+
const cy = this.getPosition(y, height, align, "y");
|
|
161
148
|
const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
|
|
162
149
|
gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
|
|
163
150
|
}
|
|
@@ -167,7 +154,7 @@ class Gradient {
|
|
|
167
154
|
break;
|
|
168
155
|
}
|
|
169
156
|
for (let stop of gradientData.stops) {
|
|
170
|
-
gradient.addColorStop(stop.offset, stop.color);
|
|
157
|
+
gradient.addColorStop(stop.offset, (0, utils_1.parseFillStyle)(ctx, stop.color, opts));
|
|
171
158
|
}
|
|
172
159
|
return gradient;
|
|
173
160
|
}
|
|
@@ -181,7 +168,7 @@ class Gradient {
|
|
|
181
168
|
type: this.type,
|
|
182
169
|
points: this.points,
|
|
183
170
|
stops: this.stops,
|
|
184
|
-
angle: this.angle
|
|
171
|
+
angle: this.angle,
|
|
185
172
|
};
|
|
186
173
|
}
|
|
187
174
|
getLinearGradientPoints(cx, cy, w, h, angleInDegrees) {
|
|
@@ -198,41 +185,41 @@ class Gradient {
|
|
|
198
185
|
const y2r = cy + (x2 - cx) * sin + (y2 - cy) * cos;
|
|
199
186
|
return [
|
|
200
187
|
{ x: x1r, y: y1r },
|
|
201
|
-
{ x: x2r, y: y2r }
|
|
188
|
+
{ x: x2r, y: y2r },
|
|
202
189
|
];
|
|
203
190
|
}
|
|
204
|
-
getPosition(pos, side, align, type =
|
|
191
|
+
getPosition(pos, side, align, type = "x") {
|
|
205
192
|
switch (align) {
|
|
206
193
|
case types_1.Centring.StartTop:
|
|
207
194
|
case "start-top":
|
|
208
|
-
return type ===
|
|
195
|
+
return type === "x" ? pos + side / 2 : pos + side / 2;
|
|
209
196
|
case types_1.Centring.Start:
|
|
210
197
|
case "start":
|
|
211
|
-
return type ===
|
|
198
|
+
return type === "x" ? pos + side / 2 : pos;
|
|
212
199
|
case types_1.Centring.StartBottom:
|
|
213
200
|
case "start-bottom":
|
|
214
|
-
return type ===
|
|
201
|
+
return type === "x" ? pos + side / 2 : pos - side / 2;
|
|
215
202
|
case types_1.Centring.CenterTop:
|
|
216
203
|
case "center-top":
|
|
217
|
-
return type ===
|
|
204
|
+
return type === "x" ? pos : pos - side / 2;
|
|
218
205
|
case types_1.Centring.Center:
|
|
219
206
|
case "center":
|
|
220
|
-
return type ===
|
|
207
|
+
return type === "x" ? pos : pos;
|
|
221
208
|
case types_1.Centring.CenterBottom:
|
|
222
209
|
case "center-bottom":
|
|
223
|
-
return type ===
|
|
210
|
+
return type === "x" ? pos : pos - side / 2;
|
|
224
211
|
case types_1.Centring.EndTop:
|
|
225
212
|
case "end-top":
|
|
226
|
-
return type ===
|
|
213
|
+
return type === "x" ? pos - side / 2 : pos + side / 2;
|
|
227
214
|
case types_1.Centring.End:
|
|
228
215
|
case "end":
|
|
229
|
-
return type ===
|
|
216
|
+
return type === "x" ? pos - side / 2 : pos;
|
|
230
217
|
case types_1.Centring.EndBottom:
|
|
231
218
|
case "end-bottom":
|
|
232
|
-
return type ===
|
|
219
|
+
return type === "x" ? pos - side / 2 : pos - side / 2;
|
|
233
220
|
case types_1.Centring.None:
|
|
234
221
|
case "none":
|
|
235
|
-
return type ===
|
|
222
|
+
return type === "x" ? pos + side / 2 : pos + side / 2;
|
|
236
223
|
default:
|
|
237
224
|
throw new LazyUtil_1.LazyError(`Invalid centring type: ${align}`);
|
|
238
225
|
}
|
|
@@ -6,25 +6,13 @@ const types_1 = require("../../types");
|
|
|
6
6
|
* Class representing a link between layers with properties and methods to manipulate it.
|
|
7
7
|
*/
|
|
8
8
|
class Link {
|
|
9
|
-
/**
|
|
10
|
-
* The source layers ID.
|
|
11
|
-
*/
|
|
12
|
-
source;
|
|
13
|
-
/**
|
|
14
|
-
* The type of the link (e.g., width, height, etc.).
|
|
15
|
-
*/
|
|
16
|
-
type;
|
|
17
|
-
/**
|
|
18
|
-
* The additional spacing applied to the link.
|
|
19
|
-
*/
|
|
20
|
-
additionalSpacing;
|
|
21
9
|
/**
|
|
22
10
|
* Constructs a new Link instance.
|
|
23
11
|
* @param {Object} [opts] - Optional properties for the link.
|
|
24
12
|
* @param {ILink} [opts.props] - The link properties.
|
|
25
13
|
*/
|
|
26
14
|
constructor(opts) {
|
|
27
|
-
this.source = opts?.props?.source ||
|
|
15
|
+
this.source = opts?.props?.source || "";
|
|
28
16
|
this.type = opts?.props?.type || types_1.LinkType.Width;
|
|
29
17
|
this.additionalSpacing = opts?.props?.additionalSpacing || 0;
|
|
30
18
|
}
|
|
@@ -63,7 +51,7 @@ class Link {
|
|
|
63
51
|
return {
|
|
64
52
|
source: this.source,
|
|
65
53
|
type: this.type,
|
|
66
|
-
additionalSpacing: this.additionalSpacing
|
|
54
|
+
additionalSpacing: this.additionalSpacing,
|
|
67
55
|
};
|
|
68
56
|
}
|
|
69
57
|
}
|
|
@@ -10,26 +10,18 @@ const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
|
10
10
|
* Class representing a pattern with properties and methods to manipulate it.
|
|
11
11
|
*/
|
|
12
12
|
class Pattern {
|
|
13
|
-
/**
|
|
14
|
-
* The type of fill, which is always `Pattern`.
|
|
15
|
-
*/
|
|
16
|
-
fillType = types_1.FillType.Pattern;
|
|
17
|
-
/**
|
|
18
|
-
* The type of the pattern (e.g., repeat, no-repeat, etc.).
|
|
19
|
-
*/
|
|
20
|
-
type;
|
|
21
|
-
/**
|
|
22
|
-
* The source of the pattern, which can be a string (URL or path) or a LazyCanvas instance.
|
|
23
|
-
*/
|
|
24
|
-
src;
|
|
25
13
|
/**
|
|
26
14
|
* Constructs a new Pattern instance.
|
|
27
15
|
* @param {Object} [opts] - Optional properties for the pattern.
|
|
28
16
|
* @param {IPattern} [opts.props] - The pattern properties.
|
|
29
17
|
*/
|
|
30
18
|
constructor(opts) {
|
|
19
|
+
/**
|
|
20
|
+
* The type of fill, which is always `Pattern`.
|
|
21
|
+
*/
|
|
22
|
+
this.fillType = types_1.FillType.Pattern;
|
|
31
23
|
this.type = opts?.props?.type || types_1.PatternType.Repeat;
|
|
32
|
-
this.src = opts?.props?.src ||
|
|
24
|
+
this.src = opts?.props?.src || "";
|
|
33
25
|
}
|
|
34
26
|
/**
|
|
35
27
|
* Sets the type of the pattern.
|
|
@@ -56,9 +48,9 @@ class Pattern {
|
|
|
56
48
|
*/
|
|
57
49
|
async draw(ctx) {
|
|
58
50
|
if (!this.src)
|
|
59
|
-
throw new LazyUtil_1.LazyError(
|
|
51
|
+
throw new LazyUtil_1.LazyError("Pattern source is not set");
|
|
60
52
|
if (this.src instanceof LazyCanvas_1.LazyCanvas) {
|
|
61
|
-
return ctx.createPattern((await this.src.manager.render.render(
|
|
53
|
+
return ctx.createPattern((await this.src.manager.render.render("canvas")), this.type);
|
|
62
54
|
}
|
|
63
55
|
return ctx.createPattern(await (0, canvas_1.loadImage)(this.src), this.type);
|
|
64
56
|
}
|
|
@@ -70,12 +62,12 @@ class Pattern {
|
|
|
70
62
|
let src = this.src;
|
|
71
63
|
if (this.src instanceof LazyCanvas_1.LazyCanvas) {
|
|
72
64
|
// @ts-ignore
|
|
73
|
-
src = new Exporter_1.Exporter(this.src).syncExport(
|
|
65
|
+
src = new Exporter_1.Exporter(this.src).syncExport("json");
|
|
74
66
|
}
|
|
75
67
|
return {
|
|
76
68
|
fillType: this.fillType,
|
|
77
69
|
type: this.type,
|
|
78
|
-
src: src
|
|
70
|
+
src: src,
|
|
79
71
|
};
|
|
80
72
|
}
|
|
81
73
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
1
|
+
export * from "./Exporter";
|
|
2
|
+
export * from "./Font";
|
|
3
|
+
export * from "./Gradient";
|
|
4
|
+
export * from "./Link";
|
|
5
|
+
export * from "./Pattern";
|
|
6
|
+
export * from "./readers/JSONReader";
|
|
7
|
+
export * from "./readers/YAMLReader";
|
|
@@ -27,17 +27,17 @@ export declare class JSONReader {
|
|
|
27
27
|
}): LazyCanvas;
|
|
28
28
|
/**
|
|
29
29
|
* Parses an array of JSON layers into an array of AnyLayer or Group instances.
|
|
30
|
-
* @param {Array<JSONLayer |
|
|
30
|
+
* @param {Array<JSONLayer | Div>} [data] - The array of JSON layers to parse.
|
|
31
31
|
* @param {Object} [opts] - Optional settings.
|
|
32
32
|
* @param {boolean} [opts.debug] - Whether to enable debug logging.
|
|
33
|
-
* @returns {Array<AnyLayer |
|
|
33
|
+
* @returns {Array<AnyLayer | Div>} The parsed layers.
|
|
34
34
|
*/
|
|
35
35
|
private static layersParse;
|
|
36
36
|
/**
|
|
37
37
|
* Parses a single JSON layer into an AnyLayer or Group instance.
|
|
38
|
-
* @param {JSONLayer |
|
|
38
|
+
* @param {JSONLayer | IDiv | Div} [layer] - The JSON layer to parse.
|
|
39
39
|
* @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
|
|
40
|
-
* @returns {AnyLayer |
|
|
40
|
+
* @returns {AnyLayer | Div} The parsed layer.
|
|
41
41
|
*/
|
|
42
42
|
private static layerParse;
|
|
43
43
|
/**
|
|
@@ -41,6 +41,7 @@ const LazyCanvas_1 = require("../../LazyCanvas");
|
|
|
41
41
|
const fs = __importStar(require("fs"));
|
|
42
42
|
const LazyUtil_1 = require("../../../utils/LazyUtil");
|
|
43
43
|
const path = __importStar(require("path"));
|
|
44
|
+
const Signal_1 = require("../../../core/Signal");
|
|
44
45
|
/**
|
|
45
46
|
* Class responsible for reading and parsing JSON data into a LazyCanvas instance.
|
|
46
47
|
*/
|
|
@@ -60,17 +61,13 @@ class JSONReader {
|
|
|
60
61
|
if (data.options.exportType === undefined) {
|
|
61
62
|
throw new LazyUtil_1.LazyError("Invalid export type");
|
|
62
63
|
}
|
|
63
|
-
if (data.options.flag === undefined) {
|
|
64
|
-
throw new LazyUtil_1.LazyError("Invalid export flag");
|
|
65
|
-
}
|
|
66
64
|
if (data.layers === undefined || data.layers.length === 0) {
|
|
67
65
|
throw new LazyUtil_1.LazyError("No layers found");
|
|
68
66
|
}
|
|
69
67
|
if (opts?.debug)
|
|
70
|
-
LazyUtil_1.LazyLog.log("info", "Reading JSON...\nOptions:", data.options, "\
|
|
68
|
+
LazyUtil_1.LazyLog.log("info", "Reading JSON...\nOptions:", data.options, "\nLayers Number:", data.layers.length, "\nLayers:", data.layers);
|
|
71
69
|
const layers = JSONReader.layersParse(data.layers, opts);
|
|
72
|
-
const canvas = new LazyCanvas_1.LazyCanvas({ settings: data, debug: opts?.debug })
|
|
73
|
-
.create(data.options.width, data.options.height);
|
|
70
|
+
const canvas = new LazyCanvas_1.LazyCanvas({ settings: data, debug: opts?.debug }).create(data.options.width, data.options.height);
|
|
74
71
|
canvas.manager.layers.add(...layers);
|
|
75
72
|
return canvas;
|
|
76
73
|
}
|
|
@@ -94,37 +91,31 @@ class JSONReader {
|
|
|
94
91
|
}
|
|
95
92
|
/**
|
|
96
93
|
* Parses an array of JSON layers into an array of AnyLayer or Group instances.
|
|
97
|
-
* @param {Array<JSONLayer |
|
|
94
|
+
* @param {Array<JSONLayer | Div>} [data] - The array of JSON layers to parse.
|
|
98
95
|
* @param {Object} [opts] - Optional settings.
|
|
99
96
|
* @param {boolean} [opts.debug] - Whether to enable debug logging.
|
|
100
|
-
* @returns {Array<AnyLayer |
|
|
97
|
+
* @returns {Array<AnyLayer | Div>} The parsed layers.
|
|
101
98
|
*/
|
|
102
99
|
static layersParse(data, opts) {
|
|
103
100
|
return data.map((layer) => {
|
|
104
101
|
if (opts?.debug)
|
|
105
|
-
LazyUtil_1.LazyLog.log(
|
|
106
|
-
|
|
102
|
+
LazyUtil_1.LazyLog.log("info", `Parsing layer ${layer.id}...\nData:`, layer);
|
|
103
|
+
return this.layerParse(layer, {
|
|
107
104
|
id: layer.id,
|
|
108
105
|
zIndex: layer.zIndex,
|
|
109
106
|
visible: layer.visible,
|
|
110
|
-
};
|
|
111
|
-
if (layer.type === types_1.LayerType.Group) {
|
|
112
|
-
return new components_1.Group(misc).add(...layer.layers.map((l) => this.layerParse(l, { id: l.id, zIndex: l.zIndex, visible: l.visible })));
|
|
113
|
-
}
|
|
114
|
-
else {
|
|
115
|
-
return this.layerParse(layer, misc);
|
|
116
|
-
}
|
|
107
|
+
});
|
|
117
108
|
});
|
|
118
109
|
}
|
|
119
110
|
/**
|
|
120
111
|
* Parses a single JSON layer into an AnyLayer or Group instance.
|
|
121
|
-
* @param {JSONLayer |
|
|
112
|
+
* @param {JSONLayer | IDiv | Div} [layer] - The JSON layer to parse.
|
|
122
113
|
* @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
|
|
123
|
-
* @returns {AnyLayer |
|
|
114
|
+
* @returns {AnyLayer | Div} The parsed layer.
|
|
124
115
|
*/
|
|
125
116
|
static layerParse(layer, misc) {
|
|
126
|
-
if (layer instanceof components_1.
|
|
127
|
-
return new components_1.
|
|
117
|
+
if (layer instanceof components_1.Div) {
|
|
118
|
+
return new components_1.Div(misc).add(...layer.layers.map((l) => this.layerParse(l)));
|
|
128
119
|
}
|
|
129
120
|
else {
|
|
130
121
|
switch (layer.type) {
|
|
@@ -140,15 +131,12 @@ class JSONReader {
|
|
|
140
131
|
return new components_1.MorphLayer(layer.props, misc).setColor(this.fillParse(layer));
|
|
141
132
|
case types_1.LayerType.Line:
|
|
142
133
|
return new components_1.LineLayer(layer.props, misc).setColor(this.fillParse(layer));
|
|
143
|
-
case types_1.LayerType.Clear:
|
|
144
|
-
return new components_1.ClearLayer(layer.props, misc);
|
|
145
134
|
case types_1.LayerType.Path:
|
|
146
135
|
return new components_1.Path2DLayer(layer.props, misc).setColor(this.fillParse(layer));
|
|
147
136
|
case types_1.LayerType.Polygon:
|
|
148
137
|
return new components_1.PolygonLayer(layer.props, misc).setColor(this.fillParse(layer));
|
|
149
138
|
case types_1.LayerType.Group:
|
|
150
|
-
return new components_1.
|
|
151
|
-
.add(...layer.layers.map((l) => this.layerParse(l)));
|
|
139
|
+
return new components_1.Div(misc).add(...layer.layers.map((l) => this.layerParse(l)));
|
|
152
140
|
default:
|
|
153
141
|
return layer;
|
|
154
142
|
}
|
|
@@ -160,24 +148,28 @@ class JSONReader {
|
|
|
160
148
|
* @returns {string | Gradient | Pattern} The parsed fill style.
|
|
161
149
|
*/
|
|
162
150
|
static fillParse(layer) {
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
return new __1.Gradient({ props: layer.props.fillStyle });
|
|
167
|
-
case 'pattern':
|
|
168
|
-
return new __1.Pattern()
|
|
169
|
-
.setType(layer.props.fillStyle.type)
|
|
170
|
-
.setSrc(typeof layer.props.fillStyle.src === 'string' ? layer.props.fillStyle.src : this.read(layer.props.fillStyle.src));
|
|
171
|
-
default:
|
|
172
|
-
return layer.props.fillStyle;
|
|
151
|
+
if ("fillStyle" in layer.props) {
|
|
152
|
+
if ((0, Signal_1.isSignal)(layer.props.fillStyle)) {
|
|
153
|
+
throw new LazyUtil_1.LazyError("Signals are not supported in JSON fill styles");
|
|
173
154
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
155
|
+
if (typeof layer.props.fillStyle === "object") {
|
|
156
|
+
switch (layer.props.fillStyle?.fillType) {
|
|
157
|
+
case "gradient":
|
|
158
|
+
return new __1.Gradient({ props: layer.props.fillStyle });
|
|
159
|
+
case "pattern":
|
|
160
|
+
return new __1.Pattern()
|
|
161
|
+
.setType(layer.props.fillStyle.type)
|
|
162
|
+
.setSrc(typeof layer.props.fillStyle.src === "string"
|
|
163
|
+
? layer.props.fillStyle.src
|
|
164
|
+
: this.read(layer.props.fillStyle.src));
|
|
165
|
+
default:
|
|
166
|
+
return layer.props.fillStyle;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return layer.props.fillStyle || "#000000";
|
|
178
170
|
}
|
|
179
171
|
else {
|
|
180
|
-
return
|
|
172
|
+
return "#000000";
|
|
181
173
|
}
|
|
182
174
|
}
|
|
183
175
|
}
|
|
@@ -49,9 +49,9 @@ class YAMLReader {
|
|
|
49
49
|
static read(data, opts) {
|
|
50
50
|
const yamlContent = _yaml.load(data);
|
|
51
51
|
if (opts?.debug) {
|
|
52
|
-
LazyUtil_1.LazyLog.log(
|
|
52
|
+
LazyUtil_1.LazyLog.log("info", "YAML content loaded:", yamlContent);
|
|
53
53
|
}
|
|
54
|
-
if (typeof yamlContent ===
|
|
54
|
+
if (typeof yamlContent === "object" && yamlContent !== null) {
|
|
55
55
|
return JSONReader_1.JSONReader.read(yamlContent, opts);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
@@ -70,12 +70,12 @@ class YAMLReader {
|
|
|
70
70
|
throw new LazyUtil_1.LazyError(`File not found: ${filePath}`);
|
|
71
71
|
}
|
|
72
72
|
const ext = path.extname(filePath).toLowerCase();
|
|
73
|
-
if (ext !==
|
|
73
|
+
if (ext !== ".yaml" && ext !== ".yml") {
|
|
74
74
|
throw new LazyUtil_1.LazyError(`Invalid file extension: ${ext}. Expected .yaml or .yml.`);
|
|
75
75
|
}
|
|
76
|
-
const data = fs.readFileSync(filePath,
|
|
76
|
+
const data = fs.readFileSync(filePath, "utf8");
|
|
77
77
|
if (opts?.debug) {
|
|
78
|
-
LazyUtil_1.LazyLog.log(
|
|
78
|
+
LazyUtil_1.LazyLog.log("info", `Reading YAML file: ${filePath}`);
|
|
79
79
|
}
|
|
80
80
|
return this.read(data, opts);
|
|
81
81
|
}
|
|
@@ -9,14 +9,6 @@ const canvas_1 = require("@napi-rs/canvas");
|
|
|
9
9
|
* Class representing a manager for handling fonts.
|
|
10
10
|
*/
|
|
11
11
|
class FontsManager {
|
|
12
|
-
/**
|
|
13
|
-
* A map storing fonts with their family and weight as the key.
|
|
14
|
-
*/
|
|
15
|
-
map;
|
|
16
|
-
/**
|
|
17
|
-
* Whether debugging is enabled.
|
|
18
|
-
*/
|
|
19
|
-
debug;
|
|
20
12
|
/**
|
|
21
13
|
* Constructs a new FontsManager instance.
|
|
22
14
|
* @param {Object} [opts] - Optional settings for the FontsManager.
|
|
@@ -33,14 +25,13 @@ class FontsManager {
|
|
|
33
25
|
* @returns {this} The current instance for chaining.
|
|
34
26
|
*/
|
|
35
27
|
loadFonts(fontList) {
|
|
36
|
-
this.add(...Object.entries(fontList)
|
|
28
|
+
this.add(...Object.entries(fontList)
|
|
29
|
+
.map(([fontFamily, fontWeights]) => {
|
|
37
30
|
return Object.entries(fontWeights).map(([weight, base64]) => {
|
|
38
|
-
return new helpers_1.Font()
|
|
39
|
-
.setFamily(fontFamily)
|
|
40
|
-
.setWeight(Number(weight))
|
|
41
|
-
.setBase64(base64);
|
|
31
|
+
return new helpers_1.Font().setFamily(fontFamily).setWeight(Number(weight)).setBase64(base64);
|
|
42
32
|
});
|
|
43
|
-
})
|
|
33
|
+
})
|
|
34
|
+
.flat());
|
|
44
35
|
return this;
|
|
45
36
|
}
|
|
46
37
|
/**
|
|
@@ -53,10 +44,10 @@ class FontsManager {
|
|
|
53
44
|
*/
|
|
54
45
|
add(...fonts) {
|
|
55
46
|
if (this.debug)
|
|
56
|
-
LazyUtil_1.LazyLog.log(
|
|
47
|
+
LazyUtil_1.LazyLog.log("info", `Adding fonts...\nlength: ${fonts.length}`);
|
|
57
48
|
for (const font of fonts) {
|
|
58
49
|
if (this.debug)
|
|
59
|
-
LazyUtil_1.LazyLog.log(
|
|
50
|
+
LazyUtil_1.LazyLog.log("none", `Data:`, font.toJSON());
|
|
60
51
|
if (!font.family)
|
|
61
52
|
throw new LazyUtil_1.LazyError("Family must be provided");
|
|
62
53
|
if (!font.weight)
|
|
@@ -101,7 +92,7 @@ class FontsManager {
|
|
|
101
92
|
get(family, weight) {
|
|
102
93
|
if (weight)
|
|
103
94
|
return this.map.get(`${family}_${weight}`);
|
|
104
|
-
return Array.from(this.map.values()).filter(font => font.family === family);
|
|
95
|
+
return Array.from(this.map.values()).filter((font) => font.family === family);
|
|
105
96
|
}
|
|
106
97
|
/**
|
|
107
98
|
* Checks if a font exists in the manager.
|
|
@@ -112,7 +103,7 @@ class FontsManager {
|
|
|
112
103
|
has(family, weight) {
|
|
113
104
|
if (weight)
|
|
114
105
|
return this.map.has(`${family}_${weight}`);
|
|
115
|
-
return Array.from(this.map.values()).some(font => font.family === family);
|
|
106
|
+
return Array.from(this.map.values()).some((font) => font.family === family);
|
|
116
107
|
}
|
|
117
108
|
/**
|
|
118
109
|
* Retrieves the number of fonts in the manager.
|
|
@@ -1,18 +1,13 @@
|
|
|
1
1
|
import { AnyLayer } from "../../types";
|
|
2
|
-
import {
|
|
3
|
-
import { LazyCanvas } from "../LazyCanvas";
|
|
2
|
+
import { Div } from "../components";
|
|
4
3
|
/**
|
|
5
4
|
* Interface representing the LayersManager.
|
|
6
5
|
*/
|
|
7
6
|
export interface ILayersManager {
|
|
8
|
-
/**
|
|
9
|
-
* The LazyCanvas instance associated with this manager.
|
|
10
|
-
*/
|
|
11
|
-
lazyCanvas: LazyCanvas;
|
|
12
7
|
/**
|
|
13
8
|
* A map storing layers or groups with their IDs as keys.
|
|
14
9
|
*/
|
|
15
|
-
map: Map<string, AnyLayer |
|
|
10
|
+
map: Map<string, AnyLayer | Div>;
|
|
16
11
|
/**
|
|
17
12
|
* Whether debugging is enabled.
|
|
18
13
|
*/
|
|
@@ -22,34 +17,29 @@ export interface ILayersManager {
|
|
|
22
17
|
* Class representing a manager for handling layers and groups.
|
|
23
18
|
*/
|
|
24
19
|
export declare class LayersManager implements ILayersManager {
|
|
25
|
-
/**
|
|
26
|
-
* The LazyCanvas instance associated with this manager.
|
|
27
|
-
*/
|
|
28
|
-
lazyCanvas: LazyCanvas;
|
|
29
20
|
/**
|
|
30
21
|
* A map storing layers or groups with their IDs as keys.
|
|
31
22
|
*/
|
|
32
|
-
map: Map<string, AnyLayer |
|
|
23
|
+
map: Map<string, AnyLayer | Div>;
|
|
33
24
|
/**
|
|
34
25
|
* Whether debugging is enabled.
|
|
35
26
|
*/
|
|
36
27
|
debug: boolean;
|
|
37
28
|
/**
|
|
38
29
|
* Constructs a new LayersManager instance.
|
|
39
|
-
* @param {LazyCanvas} [lazyCanvas] - The LazyCanvas instance to associate with this manager.
|
|
40
30
|
* @param {Object} [opts] - Optional settings for the LayersManager.
|
|
41
31
|
* @param {boolean} [opts.debug] - Whether debugging is enabled.
|
|
42
32
|
*/
|
|
43
|
-
constructor(
|
|
33
|
+
constructor(opts?: {
|
|
44
34
|
debug?: boolean;
|
|
45
35
|
});
|
|
46
36
|
/**
|
|
47
37
|
* Adds layers or groups to the map.
|
|
48
|
-
* @param {Array<AnyLayer |
|
|
38
|
+
* @param {Array<AnyLayer | Div>} [layers] - The layers or groups to add to the map.
|
|
49
39
|
* @returns {this} The current instance for chaining.
|
|
50
40
|
* @throws {LazyError} If a layer with the same ID already exists.
|
|
51
41
|
*/
|
|
52
|
-
add(...layers: Array<AnyLayer |
|
|
42
|
+
add(...layers: Array<AnyLayer | Div>): this;
|
|
53
43
|
/**
|
|
54
44
|
* Removes layers or groups from the map by their IDs.
|
|
55
45
|
* @param {string[]} [ids] - The IDs of the layers or groups to remove.
|
|
@@ -65,9 +55,9 @@ export declare class LayersManager implements ILayersManager {
|
|
|
65
55
|
* Retrieves a layer or group from the map by its ID.
|
|
66
56
|
* @param {string} [id] - The ID of the layer or group to retrieve.
|
|
67
57
|
* @param {boolean} [cross] - Whether to search within groups for the ID.
|
|
68
|
-
* @returns {AnyLayer |
|
|
58
|
+
* @returns {AnyLayer | Div | undefined} The retrieved layer or group, or undefined if not found.
|
|
69
59
|
*/
|
|
70
|
-
get(id: string, cross?: boolean): AnyLayer |
|
|
60
|
+
get(id: string, cross?: boolean): AnyLayer | Div | undefined;
|
|
71
61
|
/**
|
|
72
62
|
* Checks if a layer or group exists in the map by its ID.
|
|
73
63
|
* @param {string} [id] - The ID of the layer or group to check.
|
|
@@ -81,9 +71,9 @@ export declare class LayersManager implements ILayersManager {
|
|
|
81
71
|
size(): number;
|
|
82
72
|
/**
|
|
83
73
|
* Retrieves the values (layers and groups) from the map.
|
|
84
|
-
* @returns {IterableIterator<AnyLayer |
|
|
74
|
+
* @returns {IterableIterator<AnyLayer | Div>} An iterator for the map values.
|
|
85
75
|
*/
|
|
86
|
-
values(): IterableIterator<AnyLayer |
|
|
76
|
+
values(): IterableIterator<AnyLayer | Div>;
|
|
87
77
|
/**
|
|
88
78
|
* Retrieves the keys (IDs) from the map.
|
|
89
79
|
* @returns {IterableIterator<string>} An iterator for the map keys.
|
|
@@ -91,15 +81,15 @@ export declare class LayersManager implements ILayersManager {
|
|
|
91
81
|
keys(): IterableIterator<string>;
|
|
92
82
|
/**
|
|
93
83
|
* Retrieves the entries (key-value pairs) from the map.
|
|
94
|
-
* @returns {IterableIterator<[string, AnyLayer |
|
|
84
|
+
* @returns {IterableIterator<[string, AnyLayer | Div]>} An iterator for the map entries.
|
|
95
85
|
*/
|
|
96
|
-
entries(): IterableIterator<[string, AnyLayer |
|
|
86
|
+
entries(): IterableIterator<[string, AnyLayer | Div]>;
|
|
97
87
|
/**
|
|
98
88
|
* Executes a callback function for each layer or group in the map.
|
|
99
89
|
* @param {Function} [callbackfn] - The callback function to execute.
|
|
100
90
|
* @returns {this} The current instance for chaining.
|
|
101
91
|
*/
|
|
102
|
-
forEach(callbackfn: (value: AnyLayer |
|
|
92
|
+
forEach(callbackfn: (value: AnyLayer | Div, key: string, map: Map<string, AnyLayer | Div>) => void): this;
|
|
103
93
|
/**
|
|
104
94
|
* Converts the map to a JSON object.
|
|
105
95
|
* @returns {object} The JSON representation of the map.
|
|
@@ -113,15 +103,15 @@ export declare class LayersManager implements ILayersManager {
|
|
|
113
103
|
fromJSON(json: object): this;
|
|
114
104
|
/**
|
|
115
105
|
* Converts the map to an array of layers and groups.
|
|
116
|
-
* @returns {Array<AnyLayer |
|
|
106
|
+
* @returns {Array<AnyLayer | Div>} An array of layers and groups.
|
|
117
107
|
*/
|
|
118
|
-
toArray(): Array<AnyLayer |
|
|
108
|
+
toArray(): Array<AnyLayer | Div>;
|
|
119
109
|
/**
|
|
120
110
|
* Populates the map from an array of layers and groups.
|
|
121
|
-
* @param {Array<AnyLayer |
|
|
111
|
+
* @param {Array<AnyLayer | Div>} [array] - The array of layers and groups to populate the map from.
|
|
122
112
|
* @returns {this} The current instance for chaining.
|
|
123
113
|
*/
|
|
124
|
-
fromArray(array: Array<AnyLayer |
|
|
114
|
+
fromArray(array: Array<AnyLayer | Div>): this;
|
|
125
115
|
/**
|
|
126
116
|
* Sorts the layers and groups in the map by their zIndex property.
|
|
127
117
|
* @returns {void}
|
|
@@ -130,7 +120,7 @@ export declare class LayersManager implements ILayersManager {
|
|
|
130
120
|
/**
|
|
131
121
|
* Searches for a layer or group by its ID, including within groups.
|
|
132
122
|
* @param {string} [id] - The ID of the layer or group to search for.
|
|
133
|
-
* @returns {AnyLayer |
|
|
123
|
+
* @returns {AnyLayer | Div | undefined} The found layer or group, or undefined if not found.
|
|
134
124
|
*/
|
|
135
125
|
private crossSearch;
|
|
136
126
|
}
|