@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
|
@@ -38,9 +38,11 @@ const types_1 = require("../../../types");
|
|
|
38
38
|
const components_1 = require("../../components");
|
|
39
39
|
const __1 = require("../");
|
|
40
40
|
const LazyCanvas_1 = require("../../LazyCanvas");
|
|
41
|
-
const fs = __importStar(require("fs"));
|
|
42
|
-
const
|
|
43
|
-
const path = __importStar(require("path"));
|
|
41
|
+
const fs = __importStar(require("node:fs"));
|
|
42
|
+
const utils_1 = require("../../../utils");
|
|
43
|
+
const path = __importStar(require("node:path"));
|
|
44
|
+
const core_1 = require("../../../core");
|
|
45
|
+
const managers_1 = require("../../managers");
|
|
44
46
|
/**
|
|
45
47
|
* Class responsible for reading and parsing JSON data into a LazyCanvas instance.
|
|
46
48
|
*/
|
|
@@ -55,22 +57,21 @@ class JSONReader {
|
|
|
55
57
|
*/
|
|
56
58
|
static read(data, opts) {
|
|
57
59
|
if (data.options.width <= 0 || data.options.height <= 0) {
|
|
58
|
-
throw new
|
|
60
|
+
throw new utils_1.LazyError("Invalid width or height");
|
|
59
61
|
}
|
|
60
62
|
if (data.options.exportType === undefined) {
|
|
61
|
-
throw new
|
|
62
|
-
}
|
|
63
|
-
if (data.options.flag === undefined) {
|
|
64
|
-
throw new LazyUtil_1.LazyError("Invalid export flag");
|
|
63
|
+
throw new utils_1.LazyError("Invalid export type");
|
|
65
64
|
}
|
|
66
65
|
if (data.layers === undefined || data.layers.length === 0) {
|
|
67
|
-
throw new
|
|
66
|
+
throw new utils_1.LazyError("No layers found");
|
|
68
67
|
}
|
|
69
68
|
if (opts?.debug)
|
|
70
|
-
|
|
69
|
+
utils_1.LazyLog.log("info", "Reading JSON...\nOptions:", data.options, "\nLayers Number:", data.layers.length, "\nLayers:", data.layers);
|
|
71
70
|
const layers = JSONReader.layersParse(data.layers, opts);
|
|
72
|
-
const canvas = new LazyCanvas_1.LazyCanvas(
|
|
73
|
-
|
|
71
|
+
const canvas = new LazyCanvas_1.LazyCanvas(managers_1.ClassicRenderPipeline, {
|
|
72
|
+
settings: data,
|
|
73
|
+
debug: opts?.debug,
|
|
74
|
+
}).create(data.options.width, data.options.height);
|
|
74
75
|
canvas.manager.layers.add(...layers);
|
|
75
76
|
return canvas;
|
|
76
77
|
}
|
|
@@ -85,46 +86,40 @@ class JSONReader {
|
|
|
85
86
|
static readFile(file, opts) {
|
|
86
87
|
const filePath = path.resolve(file);
|
|
87
88
|
if (!fs.existsSync(filePath))
|
|
88
|
-
throw new
|
|
89
|
+
throw new utils_1.LazyError("File not found");
|
|
89
90
|
const json = fs.readFileSync(filePath, "utf-8");
|
|
90
91
|
const data = JSON.parse(json);
|
|
91
92
|
if (opts?.debug)
|
|
92
|
-
|
|
93
|
+
utils_1.LazyLog.log("info", "Reading JSON file...\nFile:", filePath, "\nData:", data);
|
|
93
94
|
return JSONReader.read(data, opts);
|
|
94
95
|
}
|
|
95
96
|
/**
|
|
96
97
|
* Parses an array of JSON layers into an array of AnyLayer or Group instances.
|
|
97
|
-
* @param {Array<JSONLayer |
|
|
98
|
+
* @param {Array<JSONLayer | Div>} [data] - The array of JSON layers to parse.
|
|
98
99
|
* @param {Object} [opts] - Optional settings.
|
|
99
100
|
* @param {boolean} [opts.debug] - Whether to enable debug logging.
|
|
100
|
-
* @returns {Array<AnyLayer |
|
|
101
|
+
* @returns {Array<AnyLayer | Div>} The parsed layers.
|
|
101
102
|
*/
|
|
102
103
|
static layersParse(data, opts) {
|
|
103
104
|
return data.map((layer) => {
|
|
104
105
|
if (opts?.debug)
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
utils_1.LazyLog.log("info", `Parsing layer ${layer.id}...\nData:`, layer);
|
|
107
|
+
return this.layerParse(layer, {
|
|
107
108
|
id: layer.id,
|
|
108
109
|
zIndex: layer.zIndex,
|
|
109
110
|
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
|
-
}
|
|
111
|
+
});
|
|
117
112
|
});
|
|
118
113
|
}
|
|
119
114
|
/**
|
|
120
115
|
* Parses a single JSON layer into an AnyLayer or Group instance.
|
|
121
|
-
* @param {JSONLayer |
|
|
116
|
+
* @param {JSONLayer | IDiv | Div} [layer] - The JSON layer to parse.
|
|
122
117
|
* @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
|
|
123
|
-
* @returns {AnyLayer |
|
|
118
|
+
* @returns {AnyLayer | Div} The parsed layer.
|
|
124
119
|
*/
|
|
125
120
|
static layerParse(layer, misc) {
|
|
126
|
-
if (layer instanceof components_1.
|
|
127
|
-
return new components_1.
|
|
121
|
+
if (layer instanceof components_1.Div) {
|
|
122
|
+
return new components_1.Div({}, misc).add(...layer.layers.map((l) => this.layerParse(l)));
|
|
128
123
|
}
|
|
129
124
|
else {
|
|
130
125
|
switch (layer.type) {
|
|
@@ -140,15 +135,12 @@ class JSONReader {
|
|
|
140
135
|
return new components_1.MorphLayer(layer.props, misc).setColor(this.fillParse(layer));
|
|
141
136
|
case types_1.LayerType.Line:
|
|
142
137
|
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
138
|
case types_1.LayerType.Path:
|
|
146
139
|
return new components_1.Path2DLayer(layer.props, misc).setColor(this.fillParse(layer));
|
|
147
140
|
case types_1.LayerType.Polygon:
|
|
148
141
|
return new components_1.PolygonLayer(layer.props, misc).setColor(this.fillParse(layer));
|
|
149
142
|
case types_1.LayerType.Group:
|
|
150
|
-
return new components_1.
|
|
151
|
-
.add(...layer.layers.map((l) => this.layerParse(l)));
|
|
143
|
+
return new components_1.Div({}, misc).add(...layer.layers.map((l) => this.layerParse(l)));
|
|
152
144
|
default:
|
|
153
145
|
return layer;
|
|
154
146
|
}
|
|
@@ -160,24 +152,28 @@ class JSONReader {
|
|
|
160
152
|
* @returns {string | Gradient | Pattern} The parsed fill style.
|
|
161
153
|
*/
|
|
162
154
|
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;
|
|
155
|
+
if ("color" in layer.props) {
|
|
156
|
+
if ((0, core_1.isSignal)(layer.props.color)) {
|
|
157
|
+
throw new utils_1.LazyError("Signals are not supported in JSON fill styles");
|
|
173
158
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
159
|
+
if (typeof layer.props.color === "object") {
|
|
160
|
+
switch (layer.props.color?.fillType) {
|
|
161
|
+
case "gradient":
|
|
162
|
+
return new __1.Gradient({ props: layer.props.color });
|
|
163
|
+
case "pattern":
|
|
164
|
+
return new __1.Pattern()
|
|
165
|
+
.setType(layer.props.color.type)
|
|
166
|
+
.setSrc(typeof layer.props.color.src === "string"
|
|
167
|
+
? layer.props.color.src
|
|
168
|
+
: this.read(layer.props.color.src));
|
|
169
|
+
default:
|
|
170
|
+
return layer.props.color;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return layer.props.color || "#000000";
|
|
178
174
|
}
|
|
179
175
|
else {
|
|
180
|
-
return
|
|
176
|
+
return "#000000";
|
|
181
177
|
}
|
|
182
178
|
}
|
|
183
179
|
}
|
|
@@ -36,9 +36,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
exports.YAMLReader = void 0;
|
|
37
37
|
const JSONReader_1 = require("./JSONReader");
|
|
38
38
|
const _yaml = __importStar(require("js-yaml"));
|
|
39
|
-
const fs = __importStar(require("fs"));
|
|
40
|
-
const
|
|
41
|
-
const path = __importStar(require("path"));
|
|
39
|
+
const fs = __importStar(require("node:fs"));
|
|
40
|
+
const utils_1 = require("../../../utils");
|
|
41
|
+
const path = __importStar(require("node:path"));
|
|
42
42
|
class YAMLReader {
|
|
43
43
|
/**
|
|
44
44
|
* Reads a YAML string and converts it to a LazyCanvas object.
|
|
@@ -49,13 +49,13 @@ class YAMLReader {
|
|
|
49
49
|
static read(data, opts) {
|
|
50
50
|
const yamlContent = _yaml.load(data);
|
|
51
51
|
if (opts?.debug) {
|
|
52
|
-
|
|
52
|
+
utils_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 {
|
|
58
|
-
throw new
|
|
58
|
+
throw new utils_1.LazyError("Invalid YAML content: Expected an object.");
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
@@ -67,15 +67,15 @@ class YAMLReader {
|
|
|
67
67
|
*/
|
|
68
68
|
static readFile(filePath, opts) {
|
|
69
69
|
if (!fs.existsSync(filePath)) {
|
|
70
|
-
throw new
|
|
70
|
+
throw new utils_1.LazyError(`File not found: ${filePath}`);
|
|
71
71
|
}
|
|
72
72
|
const ext = path.extname(filePath).toLowerCase();
|
|
73
|
-
if (ext !==
|
|
74
|
-
throw new
|
|
73
|
+
if (ext !== ".yaml" && ext !== ".yml") {
|
|
74
|
+
throw new utils_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
|
-
|
|
78
|
+
utils_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
|
}
|
|
@@ -7,50 +7,32 @@ const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
|
7
7
|
* Class representing a manager for handling layers and groups.
|
|
8
8
|
*/
|
|
9
9
|
class LayersManager {
|
|
10
|
-
/**
|
|
11
|
-
* The LazyCanvas instance associated with this manager.
|
|
12
|
-
*/
|
|
13
|
-
lazyCanvas;
|
|
14
|
-
/**
|
|
15
|
-
* A map storing layers or groups with their IDs as keys.
|
|
16
|
-
*/
|
|
17
|
-
map;
|
|
18
|
-
/**
|
|
19
|
-
* Whether debugging is enabled.
|
|
20
|
-
*/
|
|
21
|
-
debug;
|
|
22
10
|
/**
|
|
23
11
|
* Constructs a new LayersManager instance.
|
|
24
|
-
* @param {LazyCanvas} [lazyCanvas] - The LazyCanvas instance to associate with this manager.
|
|
25
12
|
* @param {Object} [opts] - Optional settings for the LayersManager.
|
|
26
13
|
* @param {boolean} [opts.debug] - Whether debugging is enabled.
|
|
27
14
|
*/
|
|
28
|
-
constructor(
|
|
29
|
-
this.lazyCanvas = lazyCanvas;
|
|
15
|
+
constructor(opts) {
|
|
30
16
|
this.map = new Map();
|
|
31
17
|
this.debug = opts?.debug || false;
|
|
32
18
|
}
|
|
33
19
|
/**
|
|
34
20
|
* Adds layers or groups to the map.
|
|
35
|
-
* @param {Array<AnyLayer |
|
|
21
|
+
* @param {Array<AnyLayer | Div>} [layers] - The layers or groups to add to the map.
|
|
36
22
|
* @returns {this} The current instance for chaining.
|
|
37
23
|
* @throws {LazyError} If a layer with the same ID already exists.
|
|
38
24
|
*/
|
|
39
25
|
add(...layers) {
|
|
40
26
|
if (this.debug)
|
|
41
|
-
LazyUtil_1.LazyLog.log(
|
|
27
|
+
LazyUtil_1.LazyLog.log("info", `Adding layers...\nlength: ${layers.length}`);
|
|
42
28
|
let layersArray = layers.flat();
|
|
43
|
-
layersArray = layersArray.filter(l => l !== undefined);
|
|
29
|
+
layersArray = layersArray.filter((l) => l !== undefined);
|
|
44
30
|
for (const layer of layersArray) {
|
|
45
31
|
if (this.debug)
|
|
46
|
-
LazyUtil_1.LazyLog.log(
|
|
32
|
+
LazyUtil_1.LazyLog.log("none", `Data:`, "toJSON" in layer ? layer.toJSON() : layer);
|
|
47
33
|
if (this.map.has(layer.id))
|
|
48
34
|
throw new LazyUtil_1.LazyError("Layer already exists");
|
|
49
35
|
this.map.set(layer.id, layer);
|
|
50
|
-
// onLayerAdded hook
|
|
51
|
-
if (this.lazyCanvas && this.lazyCanvas.manager?.plugins) {
|
|
52
|
-
this.lazyCanvas.manager.plugins.executeHook('onLayerAdded', this.lazyCanvas, layer);
|
|
53
|
-
}
|
|
54
36
|
}
|
|
55
37
|
this.sort();
|
|
56
38
|
return this;
|
|
@@ -64,10 +46,6 @@ class LayersManager {
|
|
|
64
46
|
for (const id of ids) {
|
|
65
47
|
const layer = this.map.get(id);
|
|
66
48
|
this.map.delete(id);
|
|
67
|
-
// onLayerRemoved hook
|
|
68
|
-
if (this.lazyCanvas && this.lazyCanvas.manager?.plugins) {
|
|
69
|
-
this.lazyCanvas.manager.plugins.executeHook('onLayerRemoved', this.lazyCanvas, id);
|
|
70
|
-
}
|
|
71
49
|
}
|
|
72
50
|
return this;
|
|
73
51
|
}
|
|
@@ -83,7 +61,7 @@ class LayersManager {
|
|
|
83
61
|
* Retrieves a layer or group from the map by its ID.
|
|
84
62
|
* @param {string} [id] - The ID of the layer or group to retrieve.
|
|
85
63
|
* @param {boolean} [cross] - Whether to search within groups for the ID.
|
|
86
|
-
* @returns {AnyLayer |
|
|
64
|
+
* @returns {AnyLayer | Div | undefined} The retrieved layer or group, or undefined if not found.
|
|
87
65
|
*/
|
|
88
66
|
get(id, cross = false) {
|
|
89
67
|
if (cross)
|
|
@@ -108,7 +86,7 @@ class LayersManager {
|
|
|
108
86
|
}
|
|
109
87
|
/**
|
|
110
88
|
* Retrieves the values (layers and groups) from the map.
|
|
111
|
-
* @returns {IterableIterator<AnyLayer |
|
|
89
|
+
* @returns {IterableIterator<AnyLayer | Div>} An iterator for the map values.
|
|
112
90
|
*/
|
|
113
91
|
values() {
|
|
114
92
|
return this.map.values();
|
|
@@ -122,7 +100,7 @@ class LayersManager {
|
|
|
122
100
|
}
|
|
123
101
|
/**
|
|
124
102
|
* Retrieves the entries (key-value pairs) from the map.
|
|
125
|
-
* @returns {IterableIterator<[string, AnyLayer |
|
|
103
|
+
* @returns {IterableIterator<[string, AnyLayer | Div]>} An iterator for the map entries.
|
|
126
104
|
*/
|
|
127
105
|
entries() {
|
|
128
106
|
return this.map.entries();
|
|
@@ -154,18 +132,18 @@ class LayersManager {
|
|
|
154
132
|
}
|
|
155
133
|
/**
|
|
156
134
|
* Converts the map to an array of layers and groups.
|
|
157
|
-
* @returns {Array<AnyLayer |
|
|
135
|
+
* @returns {Array<AnyLayer | Div>} An array of layers and groups.
|
|
158
136
|
*/
|
|
159
137
|
toArray() {
|
|
160
138
|
return Array.from(this.map.values());
|
|
161
139
|
}
|
|
162
140
|
/**
|
|
163
141
|
* Populates the map from an array of layers and groups.
|
|
164
|
-
* @param {Array<AnyLayer |
|
|
142
|
+
* @param {Array<AnyLayer | Div>} [array] - The array of layers and groups to populate the map from.
|
|
165
143
|
* @returns {this} The current instance for chaining.
|
|
166
144
|
*/
|
|
167
145
|
fromArray(array) {
|
|
168
|
-
this.map = new Map(array.map(l => [l.id, l]));
|
|
146
|
+
this.map = new Map(array.map((l) => [l.id, l]));
|
|
169
147
|
return this;
|
|
170
148
|
}
|
|
171
149
|
/**
|
|
@@ -178,14 +156,14 @@ class LayersManager {
|
|
|
178
156
|
/**
|
|
179
157
|
* Searches for a layer or group by its ID, including within groups.
|
|
180
158
|
* @param {string} [id] - The ID of the layer or group to search for.
|
|
181
|
-
* @returns {AnyLayer |
|
|
159
|
+
* @returns {AnyLayer | Div | undefined} The found layer or group, or undefined if not found.
|
|
182
160
|
*/
|
|
183
161
|
crossSearch(id) {
|
|
184
162
|
for (const layer of Array.from(this.map.values())) {
|
|
185
163
|
if (layer.id === id)
|
|
186
164
|
return layer;
|
|
187
|
-
if (layer instanceof components_1.
|
|
188
|
-
const result = layer.layers.find(l => l.id === id);
|
|
165
|
+
if (layer instanceof components_1.Div) {
|
|
166
|
+
const result = layer.layers.find((l) => l.id === id);
|
|
189
167
|
if (result)
|
|
190
168
|
return result;
|
|
191
169
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Div } from "../components";
|
|
2
|
+
import { AnyLayer } from "../../types";
|
|
3
|
+
import { SKRSContext2D, Canvas, SvgCanvas } from "@napi-rs/canvas";
|
|
4
|
+
export declare class LayoutManager {
|
|
5
|
+
private yoga;
|
|
6
|
+
private debug;
|
|
7
|
+
ready: Promise<void>;
|
|
8
|
+
constructor(opts?: {
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
});
|
|
11
|
+
private init;
|
|
12
|
+
calculateLayout(root: AnyLayer | Div, width: number, height: number, ctx?: SKRSContext2D, canvas?: Canvas | SvgCanvas): void;
|
|
13
|
+
private createNode;
|
|
14
|
+
private applyLayout;
|
|
15
|
+
private freeNode;
|
|
16
|
+
private getFlexDirection;
|
|
17
|
+
private getJustifyContent;
|
|
18
|
+
private getAlignItems;
|
|
19
|
+
private getPositionType;
|
|
20
|
+
private setDimension;
|
|
21
|
+
private setPadding;
|
|
22
|
+
private setMargin;
|
|
23
|
+
}
|