@nmmty/lazycanvas 0.6.0-dev.f33019 → 0.6.1
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/Utlis.d.ts +28 -0
- package/dist/helpers/Utlis.js +78 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.js +19 -0
- package/dist/index.d.ts +5 -10
- package/dist/index.js +5 -29
- package/dist/structures/LazyCanvas.d.ts +46 -13
- package/dist/structures/LazyCanvas.js +66 -22
- package/dist/structures/components/BaseLayer.d.ts +16 -16
- package/dist/structures/components/BaseLayer.js +17 -17
- package/dist/structures/components/BezierLayer.d.ts +21 -21
- package/dist/structures/components/BezierLayer.js +20 -20
- package/dist/structures/components/ClearLayer.d.ts +15 -15
- package/dist/structures/components/ClearLayer.js +14 -14
- package/dist/structures/components/Group.d.ts +10 -11
- package/dist/structures/components/Group.js +9 -10
- package/dist/structures/components/ImageLayer.d.ts +12 -14
- package/dist/structures/components/ImageLayer.js +11 -11
- package/dist/structures/components/LineLayer.d.ts +20 -20
- package/dist/structures/components/LineLayer.js +19 -19
- package/dist/structures/components/MorphLayer.d.ts +18 -24
- package/dist/structures/components/MorphLayer.js +18 -26
- package/dist/structures/components/Path2DLayer.d.ts +4 -78
- package/dist/structures/components/Path2DLayer.js +2 -116
- package/dist/structures/components/QuadraticLayer.d.ts +22 -22
- package/dist/structures/components/QuadraticLayer.js +21 -21
- package/dist/structures/components/TextLayer.d.ts +37 -43
- package/dist/structures/components/TextLayer.js +37 -45
- package/dist/structures/helpers/Exporter.d.ts +9 -11
- package/dist/structures/helpers/Exporter.js +49 -32
- package/dist/structures/helpers/Font.d.ts +4 -6
- package/dist/structures/helpers/Font.js +4 -4
- package/dist/structures/helpers/Gradient.d.ts +15 -10
- package/dist/structures/helpers/Gradient.js +14 -9
- package/dist/structures/helpers/Link.d.ts +5 -5
- package/dist/structures/helpers/Link.js +5 -5
- package/dist/structures/helpers/Pattern.d.ts +5 -5
- package/dist/structures/helpers/Pattern.js +5 -5
- package/dist/structures/helpers/index.d.ts +7 -7
- package/dist/structures/helpers/readers/JSONReader.d.ts +12 -12
- package/dist/structures/helpers/readers/JSONReader.js +29 -19
- package/dist/structures/helpers/readers/YAMLReader.d.ts +4 -4
- package/dist/structures/helpers/readers/YAMLReader.js +21 -11
- package/dist/structures/managers/AnimationManager.d.ts +11 -11
- package/dist/structures/managers/AnimationManager.js +11 -11
- package/dist/structures/managers/FontsManager.d.ts +14 -15
- package/dist/structures/managers/FontsManager.js +14 -15
- package/dist/structures/managers/LayersManager.d.ts +22 -12
- package/dist/structures/managers/LayersManager.js +27 -12
- package/dist/structures/managers/PluginManager.d.ts +230 -0
- package/dist/structures/managers/PluginManager.js +182 -0
- package/dist/structures/managers/RenderManager.d.ts +10 -12
- package/dist/structures/managers/RenderManager.js +31 -16
- package/dist/structures/managers/index.d.ts +5 -0
- package/dist/structures/managers/index.js +21 -0
- package/dist/utils/utils.d.ts +1 -1
- package/dist/utils/utils.js +15 -16
- package/package.json +59 -56
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Group } from "../structures/components";
|
|
2
|
+
import { ColorType } from "../types";
|
|
3
|
+
declare const Utils: {
|
|
4
|
+
grid(size: {
|
|
5
|
+
x: number;
|
|
6
|
+
y: number;
|
|
7
|
+
}, opts?: gridOptions): Group;
|
|
8
|
+
box(start: {
|
|
9
|
+
x: number;
|
|
10
|
+
y: number;
|
|
11
|
+
}, end: {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}, opts?: options): Group;
|
|
15
|
+
};
|
|
16
|
+
interface options {
|
|
17
|
+
color?: ColorType;
|
|
18
|
+
lineWidth?: number;
|
|
19
|
+
}
|
|
20
|
+
interface gridOptions extends options {
|
|
21
|
+
cellWith?: number;
|
|
22
|
+
cellHeight?: number;
|
|
23
|
+
startX?: number;
|
|
24
|
+
startY?: number;
|
|
25
|
+
endX?: number;
|
|
26
|
+
endY?: number;
|
|
27
|
+
}
|
|
28
|
+
export { Utils };
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Utils = void 0;
|
|
4
|
+
const components_1 = require("../structures/components");
|
|
5
|
+
const Utils = {
|
|
6
|
+
grid(size, opts) {
|
|
7
|
+
if (size.x === undefined || size.y === undefined) {
|
|
8
|
+
throw new Error("Size must have x and y properties");
|
|
9
|
+
}
|
|
10
|
+
if (opts === undefined)
|
|
11
|
+
opts = {};
|
|
12
|
+
if (opts.cellWith === undefined)
|
|
13
|
+
opts.cellWith = 10;
|
|
14
|
+
if (opts.cellHeight === undefined)
|
|
15
|
+
opts.cellHeight = 10;
|
|
16
|
+
if (opts.startX === undefined)
|
|
17
|
+
opts.startX = 0;
|
|
18
|
+
if (opts.startY === undefined)
|
|
19
|
+
opts.startY = 0;
|
|
20
|
+
if (opts.endX === undefined)
|
|
21
|
+
opts.endX = size.x;
|
|
22
|
+
if (opts.endY === undefined)
|
|
23
|
+
opts.endY = size.y;
|
|
24
|
+
if (opts.color === undefined)
|
|
25
|
+
opts.color = 'rgba(0, 0, 0, 0.5)';
|
|
26
|
+
if (opts.lineWidth === undefined)
|
|
27
|
+
opts.lineWidth = 1;
|
|
28
|
+
const options = { ...opts };
|
|
29
|
+
return new components_1.Group()
|
|
30
|
+
.setID(`grid-${options.cellWith}-${options.cellHeight}-${options.startX}-${options.startY}-${options.endX}-${options.endY}`)
|
|
31
|
+
.add(...Array.from({ length: Math.ceil((options.endX - options.startX) / options.cellWith) }, (_, i) => {
|
|
32
|
+
const x = options.startX + i * options.cellWith;
|
|
33
|
+
return new components_1.LineLayer()
|
|
34
|
+
.setPosition(x, options.startY)
|
|
35
|
+
.setEndPosition(x, options.endY)
|
|
36
|
+
.setColor(options.color)
|
|
37
|
+
.setStroke(options.lineWidth);
|
|
38
|
+
}), ...Array.from({ length: Math.ceil((options.endY - options.startY) / options.cellHeight) }, (_, i) => {
|
|
39
|
+
const y = options.startY + i * options.cellHeight;
|
|
40
|
+
return new components_1.LineLayer()
|
|
41
|
+
.setPosition(options.startX, y)
|
|
42
|
+
.setEndPosition(options.endX, y)
|
|
43
|
+
.setColor(options.color)
|
|
44
|
+
.setStroke(options.lineWidth);
|
|
45
|
+
}));
|
|
46
|
+
},
|
|
47
|
+
box(start, end, opts) {
|
|
48
|
+
if (start.x === undefined || start.y === undefined || end.x === undefined || end.y === undefined) {
|
|
49
|
+
throw new Error("Start and end must have x and y properties");
|
|
50
|
+
}
|
|
51
|
+
if (opts === undefined)
|
|
52
|
+
opts = {};
|
|
53
|
+
if (opts.color === undefined)
|
|
54
|
+
opts.color = 'rgba(0, 0, 0, 0.5)';
|
|
55
|
+
if (opts.lineWidth === undefined)
|
|
56
|
+
opts.lineWidth = 1;
|
|
57
|
+
return new components_1.Group()
|
|
58
|
+
.setID(`box-${start.x}-${start.y}-${end.x}-${end.y}`)
|
|
59
|
+
.add(new components_1.LineLayer()
|
|
60
|
+
.setPosition(start.x, start.y)
|
|
61
|
+
.setEndPosition(end.x, start.y)
|
|
62
|
+
.setColor(opts.color)
|
|
63
|
+
.setStroke(opts.lineWidth), new components_1.LineLayer()
|
|
64
|
+
.setPosition(end.x, start.y)
|
|
65
|
+
.setEndPosition(end.x, end.y)
|
|
66
|
+
.setColor(opts.color)
|
|
67
|
+
.setStroke(opts.lineWidth), new components_1.LineLayer()
|
|
68
|
+
.setPosition(end.x, end.y)
|
|
69
|
+
.setEndPosition(start.x, end.y)
|
|
70
|
+
.setColor(opts.color)
|
|
71
|
+
.setStroke(opts.lineWidth), new components_1.LineLayer()
|
|
72
|
+
.setPosition(start.x, end.y)
|
|
73
|
+
.setEndPosition(start.x, start.y)
|
|
74
|
+
.setColor(opts.color)
|
|
75
|
+
.setStroke(opts.lineWidth));
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
exports.Utils = Utils;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./Utlis"), exports);
|
|
18
|
+
__exportStar(require("./Filters"), exports);
|
|
19
|
+
__exportStar(require("./FontsList"), exports);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export { IAnimationManager, IAnimationOptions } from "./structures/managers/AnimationManager";
|
|
4
|
-
export { IRenderManager } from "./structures/managers/RenderManager";
|
|
5
|
-
export { ILayersManager } from "./structures/managers/LayersManager";
|
|
1
|
+
export * from "./structures/LazyCanvas";
|
|
2
|
+
export * from "./structures/managers";
|
|
6
3
|
export * from "./structures/components";
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export { FontsList } from "./helpers/FontsList";
|
|
11
|
-
export type { AnyLayer, AnyCentring, AnyPatternType, AnyGradientType, AnyTextAlign, AnyTextDirection, AnyTextBaseline, AnyWeight, AnyLineCap, AnyLineJoin, AnyExport, AnyLinkType, AnyGlobalCompositeOperation, AnyColorSpace, ScaleType, ColorType, Point, PointNumber, Transform, Extensions } from "./types";
|
|
4
|
+
export * from "./types";
|
|
5
|
+
export * from "./structures/helpers";
|
|
6
|
+
export * from "./helpers";
|
package/dist/index.js
CHANGED
|
@@ -14,33 +14,9 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(exports, "LazyCanvas", { enumerable: true, get: function () { return LazyCanvas_1.LazyCanvas; } });
|
|
17
|
+
__exportStar(require("./structures/LazyCanvas"), exports);
|
|
18
|
+
__exportStar(require("./structures/managers"), exports);
|
|
20
19
|
__exportStar(require("./structures/components"), exports);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
Object.defineProperty(exports, "LineCap", { enumerable: true, get: function () { return types_1.LineCap; } });
|
|
25
|
-
Object.defineProperty(exports, "LineJoin", { enumerable: true, get: function () { return types_1.LineJoin; } });
|
|
26
|
-
Object.defineProperty(exports, "TextAlign", { enumerable: true, get: function () { return types_1.TextAlign; } });
|
|
27
|
-
Object.defineProperty(exports, "TextDirection", { enumerable: true, get: function () { return types_1.TextDirection; } });
|
|
28
|
-
Object.defineProperty(exports, "TextBaseline", { enumerable: true, get: function () { return types_1.TextBaseline; } });
|
|
29
|
-
Object.defineProperty(exports, "FontWeight", { enumerable: true, get: function () { return types_1.FontWeight; } });
|
|
30
|
-
Object.defineProperty(exports, "Export", { enumerable: true, get: function () { return types_1.Export; } });
|
|
31
|
-
Object.defineProperty(exports, "Centring", { enumerable: true, get: function () { return types_1.Centring; } });
|
|
32
|
-
Object.defineProperty(exports, "PatternType", { enumerable: true, get: function () { return types_1.PatternType; } });
|
|
33
|
-
Object.defineProperty(exports, "GradientType", { enumerable: true, get: function () { return types_1.GradientType; } });
|
|
34
|
-
Object.defineProperty(exports, "LinkType", { enumerable: true, get: function () { return types_1.LinkType; } });
|
|
35
|
-
var helpers_1 = require("./structures/helpers");
|
|
36
|
-
Object.defineProperty(exports, "Font", { enumerable: true, get: function () { return helpers_1.Font; } });
|
|
37
|
-
Object.defineProperty(exports, "Gradient", { enumerable: true, get: function () { return helpers_1.Gradient; } });
|
|
38
|
-
Object.defineProperty(exports, "Pattern", { enumerable: true, get: function () { return helpers_1.Pattern; } });
|
|
39
|
-
Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return helpers_1.Link; } });
|
|
40
|
-
Object.defineProperty(exports, "Exporter", { enumerable: true, get: function () { return helpers_1.Exporter; } });
|
|
41
|
-
Object.defineProperty(exports, "JSONReader", { enumerable: true, get: function () { return helpers_1.JSONReader; } });
|
|
42
|
-
Object.defineProperty(exports, "YAMLReader", { enumerable: true, get: function () { return helpers_1.YAMLReader; } });
|
|
43
|
-
var Filters_1 = require("./helpers/Filters");
|
|
44
|
-
Object.defineProperty(exports, "Filters", { enumerable: true, get: function () { return Filters_1.Filters; } });
|
|
45
|
-
var FontsList_1 = require("./helpers/FontsList");
|
|
46
|
-
Object.defineProperty(exports, "FontsList", { enumerable: true, get: function () { return FontsList_1.FontsList; } });
|
|
20
|
+
__exportStar(require("./types"), exports);
|
|
21
|
+
__exportStar(require("./structures/helpers"), exports);
|
|
22
|
+
__exportStar(require("./helpers"), exports);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { AnyExport, JSONLayer } from "../types";
|
|
2
2
|
import { Canvas, SKRSContext2D, SvgCanvas, SvgExportFlag } from "@napi-rs/canvas";
|
|
3
|
-
import { LayersManager } from "./managers
|
|
4
|
-
import { RenderManager } from "./managers/RenderManager";
|
|
5
|
-
import { FontsManager } from "./managers/FontsManager";
|
|
6
|
-
import { AnimationManager, IAnimationOptions } from "./managers/AnimationManager";
|
|
3
|
+
import { LayersManager, RenderManager, FontsManager, AnimationManager, IAnimationOptions, PluginManager, ILazyCanvasPlugin } from "./managers";
|
|
7
4
|
import { Group } from "./components";
|
|
8
5
|
/**
|
|
9
6
|
* Interface representing the LazyCanvas structure.
|
|
@@ -18,13 +15,14 @@ export interface ILazyCanvas {
|
|
|
18
15
|
*/
|
|
19
16
|
ctx: SKRSContext2D;
|
|
20
17
|
/**
|
|
21
|
-
* The manager object containing various managers for layers, rendering, fonts, and
|
|
18
|
+
* The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
|
|
22
19
|
*/
|
|
23
20
|
manager: {
|
|
24
21
|
layers: LayersManager;
|
|
25
22
|
render: RenderManager;
|
|
26
23
|
fonts: FontsManager;
|
|
27
24
|
animation: AnimationManager;
|
|
25
|
+
plugins: PluginManager;
|
|
28
26
|
};
|
|
29
27
|
/**
|
|
30
28
|
* The options for configuring the LazyCanvas instance.
|
|
@@ -87,12 +85,14 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
87
85
|
ctx: SKRSContext2D;
|
|
88
86
|
/**
|
|
89
87
|
* The manager object containing various managers for layers, rendering, fonts, and animation.
|
|
88
|
+
* The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
|
|
90
89
|
*/
|
|
91
90
|
manager: {
|
|
92
91
|
layers: LayersManager;
|
|
93
92
|
render: RenderManager;
|
|
94
93
|
fonts: FontsManager;
|
|
95
94
|
animation: AnimationManager;
|
|
95
|
+
plugins: PluginManager;
|
|
96
96
|
};
|
|
97
97
|
/**
|
|
98
98
|
* The options for configuring the LazyCanvas instance.
|
|
@@ -100,9 +100,9 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
100
100
|
options: ILazyCanvasOptions;
|
|
101
101
|
/**
|
|
102
102
|
* Constructs a new LazyCanvas instance.
|
|
103
|
-
* @param
|
|
104
|
-
* @param opts.debug
|
|
105
|
-
* @param opts.settings
|
|
103
|
+
* @param {Object} [opts] - Optional settings for the LazyCanvas instance.
|
|
104
|
+
* @param {boolean} [opts.debug] - Whether debugging is enabled.
|
|
105
|
+
* @param {IOLazyCanvas} [opts.settings] - The input settings for the LazyCanvas instance.
|
|
106
106
|
*/
|
|
107
107
|
constructor(opts?: {
|
|
108
108
|
debug?: boolean;
|
|
@@ -110,13 +110,13 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
110
110
|
});
|
|
111
111
|
/**
|
|
112
112
|
* Sets the export type for the canvas.
|
|
113
|
-
* @param
|
|
113
|
+
* @param {AnyExport} [type] - The export type (e.g., buffer, SVG, etc.).
|
|
114
114
|
* @returns {this} The current instance for chaining.
|
|
115
115
|
*/
|
|
116
116
|
setExportType(type: AnyExport): this;
|
|
117
117
|
/**
|
|
118
118
|
* Sets the SVG export flag. This method should be called after `setExportType`.
|
|
119
|
-
* @param
|
|
119
|
+
* @param {SvgExportFlag} [flag] - The SVG export flag.
|
|
120
120
|
* @returns {this} The current instance for chaining.
|
|
121
121
|
*/
|
|
122
122
|
setSvgExportFlag(flag: SvgExportFlag): this;
|
|
@@ -127,15 +127,48 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
127
127
|
animated(): this;
|
|
128
128
|
/**
|
|
129
129
|
* Resizes the canvas to the specified dimensions.
|
|
130
|
-
* @param
|
|
130
|
+
* @param {number} [ratio] - The ratio to resize the canvas.
|
|
131
131
|
* @returns {this} The current instance for chaining.
|
|
132
132
|
*/
|
|
133
133
|
resize(ratio: number): this;
|
|
134
134
|
/**
|
|
135
135
|
* Creates a new canvas with the specified dimensions.
|
|
136
|
-
* @param
|
|
137
|
-
* @param
|
|
136
|
+
* @param {number} [width] - The width of the canvas.
|
|
137
|
+
* @param {number} [height] - The height of the canvas.
|
|
138
138
|
* @returns {this} The current instance for chaining.
|
|
139
139
|
*/
|
|
140
140
|
create(width: number, height: number): this;
|
|
141
|
+
/**
|
|
142
|
+
* Installs a plugin to the canvas.
|
|
143
|
+
* @param {ILazyCanvasPlugin} [plugin] - The plugin to install.
|
|
144
|
+
* @returns {this} The current instance for chaining.
|
|
145
|
+
*/
|
|
146
|
+
use(plugin: ILazyCanvasPlugin): this;
|
|
147
|
+
/**
|
|
148
|
+
* Removes a plugin from the canvas.
|
|
149
|
+
* @param {string} [pluginName] - The name of the plugin to remove.
|
|
150
|
+
* @returns {this} The current instance for chaining.
|
|
151
|
+
*/
|
|
152
|
+
removePlugin(pluginName: string): this;
|
|
153
|
+
/**
|
|
154
|
+
* Gets a plugin by name.
|
|
155
|
+
* @param {string} [pluginName] - The name of the plugin.
|
|
156
|
+
* @returns {ILazyCanvasPlugin | undefined} The plugin or undefined if not found.
|
|
157
|
+
*/
|
|
158
|
+
getPlugin(pluginName: string): ILazyCanvasPlugin | undefined;
|
|
159
|
+
/**
|
|
160
|
+
* Lists all installed plugins.
|
|
161
|
+
* @returns {string[]} Array of plugin names.
|
|
162
|
+
*/
|
|
163
|
+
listPlugins(): string[];
|
|
164
|
+
/**
|
|
165
|
+
* Gets information about all installed plugins.
|
|
166
|
+
* @returns Array of plugin information objects.
|
|
167
|
+
*/
|
|
168
|
+
getPluginsInfo(): Array<{
|
|
169
|
+
name: string;
|
|
170
|
+
version: string;
|
|
171
|
+
description?: string;
|
|
172
|
+
dependencies?: string[];
|
|
173
|
+
}>;
|
|
141
174
|
}
|
|
@@ -3,10 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.LazyCanvas = void 0;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const canvas_1 = require("@napi-rs/canvas");
|
|
6
|
-
const
|
|
7
|
-
const RenderManager_1 = require("./managers/RenderManager");
|
|
8
|
-
const FontsManager_1 = require("./managers/FontsManager");
|
|
9
|
-
const AnimationManager_1 = require("./managers/AnimationManager");
|
|
6
|
+
const managers_1 = require("./managers");
|
|
10
7
|
const LazyUtil_1 = require("../utils/LazyUtil");
|
|
11
8
|
const utils_1 = require("../utils/utils");
|
|
12
9
|
/**
|
|
@@ -23,6 +20,7 @@ class LazyCanvas {
|
|
|
23
20
|
ctx;
|
|
24
21
|
/**
|
|
25
22
|
* The manager object containing various managers for layers, rendering, fonts, and animation.
|
|
23
|
+
* The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
|
|
26
24
|
*/
|
|
27
25
|
manager;
|
|
28
26
|
/**
|
|
@@ -31,32 +29,34 @@ class LazyCanvas {
|
|
|
31
29
|
options;
|
|
32
30
|
/**
|
|
33
31
|
* Constructs a new LazyCanvas instance.
|
|
34
|
-
* @param
|
|
35
|
-
* @param opts.debug
|
|
36
|
-
* @param opts.settings
|
|
32
|
+
* @param {Object} [opts] - Optional settings for the LazyCanvas instance.
|
|
33
|
+
* @param {boolean} [opts.debug] - Whether debugging is enabled.
|
|
34
|
+
* @param {IOLazyCanvas} [opts.settings] - The input settings for the LazyCanvas instance.
|
|
37
35
|
*/
|
|
38
36
|
constructor(opts) {
|
|
39
37
|
this.canvas = new canvas_1.Canvas(0, 0);
|
|
40
38
|
this.ctx = this.canvas.getContext('2d');
|
|
41
39
|
this.manager = {
|
|
42
|
-
layers: new
|
|
43
|
-
render: new
|
|
44
|
-
fonts: new
|
|
45
|
-
animation: new
|
|
40
|
+
layers: new managers_1.LayersManager(this, { debug: opts?.debug }),
|
|
41
|
+
render: new managers_1.RenderManager(this, { debug: opts?.debug }),
|
|
42
|
+
fonts: new managers_1.FontsManager({ debug: opts?.debug }),
|
|
43
|
+
animation: new managers_1.AnimationManager({ debug: opts?.debug, settings: { options: opts?.settings?.animation } }),
|
|
44
|
+
plugins: new managers_1.PluginManager(this, { debug: opts?.debug })
|
|
46
45
|
};
|
|
47
46
|
this.options = {
|
|
48
|
-
width:
|
|
49
|
-
height:
|
|
50
|
-
animated:
|
|
51
|
-
exportType:
|
|
52
|
-
flag:
|
|
47
|
+
width: 0,
|
|
48
|
+
height: 0,
|
|
49
|
+
animated: false,
|
|
50
|
+
exportType: types_1.Export.BUFFER,
|
|
51
|
+
flag: canvas_1.SvgExportFlag.RelativePathEncoding,
|
|
52
|
+
...opts?.settings?.options
|
|
53
53
|
};
|
|
54
54
|
if (opts?.debug)
|
|
55
55
|
LazyUtil_1.LazyLog.log('info', 'LazyCanvas initialized with settings:', opts.settings);
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
58
58
|
* Sets the export type for the canvas.
|
|
59
|
-
* @param
|
|
59
|
+
* @param {AnyExport} [type] - The export type (e.g., buffer, SVG, etc.).
|
|
60
60
|
* @returns {this} The current instance for chaining.
|
|
61
61
|
*/
|
|
62
62
|
setExportType(type) {
|
|
@@ -77,7 +77,7 @@ class LazyCanvas {
|
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
79
|
* Sets the SVG export flag. This method should be called after `setExportType`.
|
|
80
|
-
* @param
|
|
80
|
+
* @param {SvgExportFlag} [flag] - The SVG export flag.
|
|
81
81
|
* @returns {this} The current instance for chaining.
|
|
82
82
|
*/
|
|
83
83
|
setSvgExportFlag(flag) {
|
|
@@ -98,7 +98,7 @@ class LazyCanvas {
|
|
|
98
98
|
}
|
|
99
99
|
/**
|
|
100
100
|
* Resizes the canvas to the specified dimensions.
|
|
101
|
-
* @param
|
|
101
|
+
* @param {number} [ratio] - The ratio to resize the canvas.
|
|
102
102
|
* @returns {this} The current instance for chaining.
|
|
103
103
|
*/
|
|
104
104
|
resize(ratio) {
|
|
@@ -116,12 +116,14 @@ class LazyCanvas {
|
|
|
116
116
|
this.ctx = this.canvas.getContext('2d');
|
|
117
117
|
const layers = (0, utils_1.resizeLayers)(this.manager.layers.toArray(), ratio);
|
|
118
118
|
this.manager.layers.fromArray(layers);
|
|
119
|
+
// Выполняем хук onResize для всех плагинов
|
|
120
|
+
this.manager.plugins.executeHook('onResize', this, ratio);
|
|
119
121
|
return this;
|
|
120
122
|
}
|
|
121
123
|
/**
|
|
122
124
|
* Creates a new canvas with the specified dimensions.
|
|
123
|
-
* @param
|
|
124
|
-
* @param
|
|
125
|
+
* @param {number} [width] - The width of the canvas.
|
|
126
|
+
* @param {number} [height] - The height of the canvas.
|
|
125
127
|
* @returns {this} The current instance for chaining.
|
|
126
128
|
*/
|
|
127
129
|
create(width, height) {
|
|
@@ -134,8 +136,50 @@ class LazyCanvas {
|
|
|
134
136
|
this.canvas = new canvas_1.Canvas(width, height);
|
|
135
137
|
}
|
|
136
138
|
this.ctx = this.canvas.getContext('2d');
|
|
137
|
-
this.manager.layers = new
|
|
139
|
+
this.manager.layers = new managers_1.LayersManager(this, { debug: this.manager.layers.debug });
|
|
140
|
+
// Выполняем хук onCanvasCreated для всех плагинов
|
|
141
|
+
this.manager.plugins.executeHook('onCanvasCreated', this, width, height);
|
|
138
142
|
return this;
|
|
139
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Installs a plugin to the canvas.
|
|
146
|
+
* @param {ILazyCanvasPlugin} [plugin] - The plugin to install.
|
|
147
|
+
* @returns {this} The current instance for chaining.
|
|
148
|
+
*/
|
|
149
|
+
use(plugin) {
|
|
150
|
+
this.manager.plugins.register(plugin);
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Removes a plugin from the canvas.
|
|
155
|
+
* @param {string} [pluginName] - The name of the plugin to remove.
|
|
156
|
+
* @returns {this} The current instance for chaining.
|
|
157
|
+
*/
|
|
158
|
+
removePlugin(pluginName) {
|
|
159
|
+
this.manager.plugins.unregister(pluginName);
|
|
160
|
+
return this;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Gets a plugin by name.
|
|
164
|
+
* @param {string} [pluginName] - The name of the plugin.
|
|
165
|
+
* @returns {ILazyCanvasPlugin | undefined} The plugin or undefined if not found.
|
|
166
|
+
*/
|
|
167
|
+
getPlugin(pluginName) {
|
|
168
|
+
return this.manager.plugins.get(pluginName);
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Lists all installed plugins.
|
|
172
|
+
* @returns {string[]} Array of plugin names.
|
|
173
|
+
*/
|
|
174
|
+
listPlugins() {
|
|
175
|
+
return this.manager.plugins.list();
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Gets information about all installed plugins.
|
|
179
|
+
* @returns Array of plugin information objects.
|
|
180
|
+
*/
|
|
181
|
+
getPluginsInfo() {
|
|
182
|
+
return this.manager.plugins.getPluginInfo();
|
|
183
|
+
}
|
|
140
184
|
}
|
|
141
185
|
exports.LazyCanvas = LazyCanvas;
|
|
@@ -144,27 +144,27 @@ export declare class BaseLayer<T extends IBaseLayerProps> {
|
|
|
144
144
|
constructor(type?: LayerType, props?: T, misc?: IBaseLayerMisc);
|
|
145
145
|
/**
|
|
146
146
|
* Sets the position of the layer in the 2D plane.
|
|
147
|
-
* @param {ScaleType} x - The x-coordinate of the layer.
|
|
148
|
-
* @param {ScaleType} y - The y-coordinate of the layer.
|
|
147
|
+
* @param {ScaleType} [x] - The x-coordinate of the layer.
|
|
148
|
+
* @param {ScaleType} [y] - The y-coordinate of the layer.
|
|
149
149
|
* @returns {this} The current instance for chaining.
|
|
150
150
|
*/
|
|
151
151
|
setPosition(x: ScaleType, y: ScaleType): this;
|
|
152
152
|
/**
|
|
153
153
|
* Sets the opacity of the layer.
|
|
154
|
-
* @param {number} opacity - The opacity value, between 0 and 1.
|
|
154
|
+
* @param {number} [opacity] - The opacity value, between 0 and 1.
|
|
155
155
|
* @returns {this} The current instance for chaining.
|
|
156
156
|
*/
|
|
157
157
|
setOpacity(opacity: number): this;
|
|
158
158
|
/**
|
|
159
159
|
* Sets the unique identifier of the layer.
|
|
160
160
|
*
|
|
161
|
-
* @param {string} id - The unique identifier.
|
|
161
|
+
* @param {string} [id] - The unique identifier.
|
|
162
162
|
* @returns {this} The current instance for chaining.
|
|
163
163
|
*/
|
|
164
164
|
setID(id: string): this;
|
|
165
165
|
/**
|
|
166
166
|
* Sets the shadow properties of the layer.
|
|
167
|
-
* @param {string} color - The color of the shadow.
|
|
167
|
+
* @param {string} [color] - The color of the shadow.
|
|
168
168
|
* @param {number} [blur] - The blur radius of the shadow.
|
|
169
169
|
* @param {number} [offsetX] - The horizontal offset of the shadow.
|
|
170
170
|
* @param {number} [offsetY] - The vertical offset of the shadow.
|
|
@@ -174,57 +174,57 @@ export declare class BaseLayer<T extends IBaseLayerProps> {
|
|
|
174
174
|
setShadow(color: string, blur?: number, offsetX?: number, offsetY?: number): this;
|
|
175
175
|
/**
|
|
176
176
|
* Sets the transformation matrix of the layer.
|
|
177
|
-
* @param {DOMMatrix2DInit} matrix - The transformation matrix.
|
|
177
|
+
* @param {DOMMatrix2DInit} [matrix] - The transformation matrix.
|
|
178
178
|
* @returns {this} The current instance for chaining.
|
|
179
179
|
*/
|
|
180
180
|
setMatrix(matrix: DOMMatrix2DInit): this;
|
|
181
181
|
/**
|
|
182
182
|
* Sets the scale of the layer in the x and y directions.
|
|
183
|
-
* @param {number} x - The scale factor in the x direction.
|
|
184
|
-
* @param {number} y - The scale factor in the y direction.
|
|
183
|
+
* @param {number} [x] - The scale factor in the x direction.
|
|
184
|
+
* @param {number} [y] - The scale factor in the y direction.
|
|
185
185
|
* @returns {this} The current instance for chaining.
|
|
186
186
|
*/
|
|
187
187
|
setScale(x: number, y: number): this;
|
|
188
188
|
/**
|
|
189
189
|
* Sets the rotation of the layer.
|
|
190
|
-
* @param {number} rotate - The rotation angle in degrees.
|
|
190
|
+
* @param {number} [rotate] - The rotation angle in degrees.
|
|
191
191
|
* @returns {this} The current instance for chaining.
|
|
192
192
|
*/
|
|
193
193
|
setRotate(rotate: number): this;
|
|
194
194
|
/**
|
|
195
195
|
* Sets the translation of the layer in the x and y directions.
|
|
196
|
-
* @param {number} x - The translation in the x direction.
|
|
197
|
-
* @param {number} y - The translation in the y direction.
|
|
196
|
+
* @param {number} [x] - The translation in the x direction.
|
|
197
|
+
* @param {number} [y] - The translation in the y direction.
|
|
198
198
|
* @returns {this} The current instance for chaining.
|
|
199
199
|
*/
|
|
200
200
|
setTranslate(x: number, y: number): this;
|
|
201
201
|
/**
|
|
202
202
|
* Sets the filter effects for the layer.
|
|
203
|
-
* @param {...AnyFilter} filter - The filter effects to apply.
|
|
203
|
+
* @param {...AnyFilter} [filter] - The filter effects to apply.
|
|
204
204
|
* @returns {this} The current instance for chaining.
|
|
205
205
|
*/
|
|
206
206
|
setFilters(...filter: AnyFilter[]): this;
|
|
207
207
|
/**
|
|
208
208
|
* Sets the centring type of the layer. **Don't affect on Bezier, Line, Quadratic and Text layers**.
|
|
209
|
-
* @param {AnyCentring} centring - The centring type.
|
|
209
|
+
* @param {AnyCentring} [centring] - The centring type.
|
|
210
210
|
* @returns {this} The current instance for chaining.
|
|
211
211
|
*/
|
|
212
212
|
setCentring(centring: AnyCentring): this;
|
|
213
213
|
/**
|
|
214
214
|
* Sets the visibility of the layer.
|
|
215
|
-
* @param {boolean} visible - The visibility state.
|
|
215
|
+
* @param {boolean} [visible] - The visibility state.
|
|
216
216
|
* @returns {this} The current instance for chaining.
|
|
217
217
|
*/
|
|
218
218
|
setVisible(visible: boolean): this;
|
|
219
219
|
/**
|
|
220
220
|
* Sets the z-index of the layer.
|
|
221
|
-
* @param {number} zIndex - The z-index value.
|
|
221
|
+
* @param {number} [zIndex] - The z-index value.
|
|
222
222
|
* @returns {this} The current instance for chaining.
|
|
223
223
|
*/
|
|
224
224
|
setZIndex(zIndex: number): this;
|
|
225
225
|
/**
|
|
226
226
|
* Sets the global composite operation for the layer.
|
|
227
|
-
* @param {AnyGlobalCompositeOperation} operation - The composite operation.
|
|
227
|
+
* @param {AnyGlobalCompositeOperation} [operation] - The composite operation.
|
|
228
228
|
* @returns {this} The current instance for chaining.
|
|
229
229
|
*/
|
|
230
230
|
setGlobalCompositeOperation(operation: AnyGlobalCompositeOperation): this;
|