@nmmty/lazycanvas 0.6.0-dev.f33019 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers/Utlis.d.ts +28 -0
- package/dist/helpers/Utlis.js +78 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +3 -1
- package/dist/structures/LazyCanvas.d.ts +38 -1
- package/dist/structures/LazyCanvas.js +50 -3
- package/dist/structures/components/BaseLayer.js +1 -1
- package/dist/structures/components/ImageLayer.d.ts +0 -2
- package/dist/structures/components/MorphLayer.d.ts +0 -6
- package/dist/structures/components/MorphLayer.js +1 -9
- package/dist/structures/components/Path2DLayer.d.ts +0 -6
- package/dist/structures/components/Path2DLayer.js +1 -9
- package/dist/structures/components/TextLayer.d.ts +0 -6
- package/dist/structures/components/TextLayer.js +1 -9
- package/dist/structures/helpers/Exporter.d.ts +0 -2
- package/dist/structures/helpers/Exporter.js +40 -23
- package/dist/structures/helpers/Font.d.ts +0 -2
- package/dist/structures/helpers/readers/JSONReader.js +17 -7
- package/dist/structures/helpers/readers/YAMLReader.js +17 -7
- package/dist/structures/managers/LayersManager.d.ts +11 -1
- package/dist/structures/managers/LayersManager.js +16 -1
- package/dist/structures/managers/PluginManager.d.ts +228 -0
- package/dist/structures/managers/PluginManager.js +181 -0
- package/dist/structures/managers/RenderManager.d.ts +0 -2
- package/dist/structures/managers/RenderManager.js +21 -6
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/utils/utils.js +15 -16
- package/package.json +9 -5
|
@@ -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;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,9 +3,11 @@ export { IFontsManager } from "./structures/managers/FontsManager";
|
|
|
3
3
|
export { IAnimationManager, IAnimationOptions } from "./structures/managers/AnimationManager";
|
|
4
4
|
export { IRenderManager } from "./structures/managers/RenderManager";
|
|
5
5
|
export { ILayersManager } from "./structures/managers/LayersManager";
|
|
6
|
+
export { IPluginManager, ILazyCanvasPlugin, IPluginHooks } from "./structures/managers/PluginManager";
|
|
6
7
|
export * from "./structures/components";
|
|
7
8
|
export { LayerType, LayerScaleType, LineCap, LineJoin, TextAlign, TextDirection, TextBaseline, FontWeight, Export, Centring, PatternType, GradientType, LinkType } from "./types";
|
|
8
9
|
export { Font, IFont, IFonts, Gradient, IGradient, GradientPoint, GradientColorStop, Pattern, IPattern, Link, ILink, Exporter, JSONReader, YAMLReader } from "./structures/helpers";
|
|
9
10
|
export { Filters } from "./helpers/Filters";
|
|
10
11
|
export { FontsList } from "./helpers/FontsList";
|
|
11
12
|
export type { AnyLayer, AnyCentring, AnyPatternType, AnyGradientType, AnyTextAlign, AnyTextDirection, AnyTextBaseline, AnyWeight, AnyLineCap, AnyLineJoin, AnyExport, AnyLinkType, AnyGlobalCompositeOperation, AnyColorSpace, ScaleType, ColorType, Point, PointNumber, Transform, Extensions } from "./types";
|
|
13
|
+
export { Utils } from "./helpers/Utlis";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ 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
|
-
exports.FontsList = exports.Filters = exports.YAMLReader = exports.JSONReader = exports.Exporter = exports.Link = exports.Pattern = exports.Gradient = exports.Font = exports.LinkType = exports.GradientType = exports.PatternType = exports.Centring = exports.Export = exports.FontWeight = exports.TextBaseline = exports.TextDirection = exports.TextAlign = exports.LineJoin = exports.LineCap = exports.LayerScaleType = exports.LayerType = exports.LazyCanvas = void 0;
|
|
17
|
+
exports.Utils = exports.FontsList = exports.Filters = exports.YAMLReader = exports.JSONReader = exports.Exporter = exports.Link = exports.Pattern = exports.Gradient = exports.Font = exports.LinkType = exports.GradientType = exports.PatternType = exports.Centring = exports.Export = exports.FontWeight = exports.TextBaseline = exports.TextDirection = exports.TextAlign = exports.LineJoin = exports.LineCap = exports.LayerScaleType = exports.LayerType = exports.LazyCanvas = void 0;
|
|
18
18
|
var LazyCanvas_1 = require("./structures/LazyCanvas");
|
|
19
19
|
Object.defineProperty(exports, "LazyCanvas", { enumerable: true, get: function () { return LazyCanvas_1.LazyCanvas; } });
|
|
20
20
|
__exportStar(require("./structures/components"), exports);
|
|
@@ -44,3 +44,5 @@ var Filters_1 = require("./helpers/Filters");
|
|
|
44
44
|
Object.defineProperty(exports, "Filters", { enumerable: true, get: function () { return Filters_1.Filters; } });
|
|
45
45
|
var FontsList_1 = require("./helpers/FontsList");
|
|
46
46
|
Object.defineProperty(exports, "FontsList", { enumerable: true, get: function () { return FontsList_1.FontsList; } });
|
|
47
|
+
var Utlis_1 = require("./helpers/Utlis");
|
|
48
|
+
Object.defineProperty(exports, "Utils", { enumerable: true, get: function () { return Utlis_1.Utils; } });
|
|
@@ -4,6 +4,7 @@ import { LayersManager } from "./managers/LayersManager";
|
|
|
4
4
|
import { RenderManager } from "./managers/RenderManager";
|
|
5
5
|
import { FontsManager } from "./managers/FontsManager";
|
|
6
6
|
import { AnimationManager, IAnimationOptions } from "./managers/AnimationManager";
|
|
7
|
+
import { PluginManager, ILazyCanvasPlugin } from "./managers/PluginManager";
|
|
7
8
|
import { Group } from "./components";
|
|
8
9
|
/**
|
|
9
10
|
* Interface representing the LazyCanvas structure.
|
|
@@ -18,13 +19,14 @@ export interface ILazyCanvas {
|
|
|
18
19
|
*/
|
|
19
20
|
ctx: SKRSContext2D;
|
|
20
21
|
/**
|
|
21
|
-
* The manager object containing various managers for layers, rendering, fonts, and
|
|
22
|
+
* The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
|
|
22
23
|
*/
|
|
23
24
|
manager: {
|
|
24
25
|
layers: LayersManager;
|
|
25
26
|
render: RenderManager;
|
|
26
27
|
fonts: FontsManager;
|
|
27
28
|
animation: AnimationManager;
|
|
29
|
+
plugins: PluginManager;
|
|
28
30
|
};
|
|
29
31
|
/**
|
|
30
32
|
* The options for configuring the LazyCanvas instance.
|
|
@@ -87,12 +89,14 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
87
89
|
ctx: SKRSContext2D;
|
|
88
90
|
/**
|
|
89
91
|
* The manager object containing various managers for layers, rendering, fonts, and animation.
|
|
92
|
+
* The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
|
|
90
93
|
*/
|
|
91
94
|
manager: {
|
|
92
95
|
layers: LayersManager;
|
|
93
96
|
render: RenderManager;
|
|
94
97
|
fonts: FontsManager;
|
|
95
98
|
animation: AnimationManager;
|
|
99
|
+
plugins: PluginManager;
|
|
96
100
|
};
|
|
97
101
|
/**
|
|
98
102
|
* The options for configuring the LazyCanvas instance.
|
|
@@ -138,4 +142,37 @@ export declare class LazyCanvas implements ILazyCanvas {
|
|
|
138
142
|
* @returns {this} The current instance for chaining.
|
|
139
143
|
*/
|
|
140
144
|
create(width: number, height: number): this;
|
|
145
|
+
/**
|
|
146
|
+
* Installs a plugin to the canvas.
|
|
147
|
+
* @param plugin {ILazyCanvasPlugin} - The plugin to install.
|
|
148
|
+
* @returns {this} The current instance for chaining.
|
|
149
|
+
*/
|
|
150
|
+
use(plugin: ILazyCanvasPlugin): this;
|
|
151
|
+
/**
|
|
152
|
+
* Removes a plugin from the canvas.
|
|
153
|
+
* @param pluginName {string} - The name of the plugin to remove.
|
|
154
|
+
* @returns {this} The current instance for chaining.
|
|
155
|
+
*/
|
|
156
|
+
removePlugin(pluginName: string): this;
|
|
157
|
+
/**
|
|
158
|
+
* Gets a plugin by name.
|
|
159
|
+
* @param pluginName {string} - The name of the plugin.
|
|
160
|
+
* @returns {ILazyCanvasPlugin | undefined} The plugin or undefined if not found.
|
|
161
|
+
*/
|
|
162
|
+
getPlugin(pluginName: string): ILazyCanvasPlugin | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* Lists all installed plugins.
|
|
165
|
+
* @returns {string[]} Array of plugin names.
|
|
166
|
+
*/
|
|
167
|
+
listPlugins(): string[];
|
|
168
|
+
/**
|
|
169
|
+
* Gets information about all installed plugins.
|
|
170
|
+
* @returns Array of plugin information objects.
|
|
171
|
+
*/
|
|
172
|
+
getPluginsInfo(): Array<{
|
|
173
|
+
name: string;
|
|
174
|
+
version: string;
|
|
175
|
+
description?: string;
|
|
176
|
+
dependencies?: string[];
|
|
177
|
+
}>;
|
|
141
178
|
}
|
|
@@ -7,6 +7,7 @@ const LayersManager_1 = require("./managers/LayersManager");
|
|
|
7
7
|
const RenderManager_1 = require("./managers/RenderManager");
|
|
8
8
|
const FontsManager_1 = require("./managers/FontsManager");
|
|
9
9
|
const AnimationManager_1 = require("./managers/AnimationManager");
|
|
10
|
+
const PluginManager_1 = require("./managers/PluginManager");
|
|
10
11
|
const LazyUtil_1 = require("../utils/LazyUtil");
|
|
11
12
|
const utils_1 = require("../utils/utils");
|
|
12
13
|
/**
|
|
@@ -23,6 +24,7 @@ class LazyCanvas {
|
|
|
23
24
|
ctx;
|
|
24
25
|
/**
|
|
25
26
|
* The manager object containing various managers for layers, rendering, fonts, and animation.
|
|
27
|
+
* The manager object containing various managers for layers, rendering, fonts, animation, and plugins.
|
|
26
28
|
*/
|
|
27
29
|
manager;
|
|
28
30
|
/**
|
|
@@ -39,10 +41,11 @@ class LazyCanvas {
|
|
|
39
41
|
this.canvas = new canvas_1.Canvas(0, 0);
|
|
40
42
|
this.ctx = this.canvas.getContext('2d');
|
|
41
43
|
this.manager = {
|
|
42
|
-
layers: new LayersManager_1.LayersManager({ debug: opts?.debug }),
|
|
44
|
+
layers: new LayersManager_1.LayersManager(this, { debug: opts?.debug }),
|
|
43
45
|
render: new RenderManager_1.RenderManager(this, { debug: opts?.debug }),
|
|
44
46
|
fonts: new FontsManager_1.FontsManager({ debug: opts?.debug }),
|
|
45
|
-
animation: new AnimationManager_1.AnimationManager({ debug: opts?.debug, settings: { options: opts?.settings?.animation } })
|
|
47
|
+
animation: new AnimationManager_1.AnimationManager({ debug: opts?.debug, settings: { options: opts?.settings?.animation } }),
|
|
48
|
+
plugins: new PluginManager_1.PluginManager(this, { debug: opts?.debug })
|
|
46
49
|
};
|
|
47
50
|
this.options = {
|
|
48
51
|
width: opts?.settings?.options.width || 0,
|
|
@@ -116,6 +119,8 @@ class LazyCanvas {
|
|
|
116
119
|
this.ctx = this.canvas.getContext('2d');
|
|
117
120
|
const layers = (0, utils_1.resizeLayers)(this.manager.layers.toArray(), ratio);
|
|
118
121
|
this.manager.layers.fromArray(layers);
|
|
122
|
+
// Выполняем хук onResize для всех плагинов
|
|
123
|
+
this.manager.plugins.executeHook('onResize', this, ratio);
|
|
119
124
|
return this;
|
|
120
125
|
}
|
|
121
126
|
/**
|
|
@@ -134,8 +139,50 @@ class LazyCanvas {
|
|
|
134
139
|
this.canvas = new canvas_1.Canvas(width, height);
|
|
135
140
|
}
|
|
136
141
|
this.ctx = this.canvas.getContext('2d');
|
|
137
|
-
this.manager.layers = new LayersManager_1.LayersManager();
|
|
142
|
+
this.manager.layers = new LayersManager_1.LayersManager(this, { debug: this.manager.layers.debug });
|
|
143
|
+
// Выполняем хук onCanvasCreated для всех плагинов
|
|
144
|
+
this.manager.plugins.executeHook('onCanvasCreated', this, width, height);
|
|
138
145
|
return this;
|
|
139
146
|
}
|
|
147
|
+
/**
|
|
148
|
+
* Installs a plugin to the canvas.
|
|
149
|
+
* @param plugin {ILazyCanvasPlugin} - The plugin to install.
|
|
150
|
+
* @returns {this} The current instance for chaining.
|
|
151
|
+
*/
|
|
152
|
+
use(plugin) {
|
|
153
|
+
this.manager.plugins.register(plugin);
|
|
154
|
+
return this;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Removes a plugin from the canvas.
|
|
158
|
+
* @param pluginName {string} - The name of the plugin to remove.
|
|
159
|
+
* @returns {this} The current instance for chaining.
|
|
160
|
+
*/
|
|
161
|
+
removePlugin(pluginName) {
|
|
162
|
+
this.manager.plugins.unregister(pluginName);
|
|
163
|
+
return this;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Gets a plugin by name.
|
|
167
|
+
* @param pluginName {string} - The name of the plugin.
|
|
168
|
+
* @returns {ILazyCanvasPlugin | undefined} The plugin or undefined if not found.
|
|
169
|
+
*/
|
|
170
|
+
getPlugin(pluginName) {
|
|
171
|
+
return this.manager.plugins.get(pluginName);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Lists all installed plugins.
|
|
175
|
+
* @returns {string[]} Array of plugin names.
|
|
176
|
+
*/
|
|
177
|
+
listPlugins() {
|
|
178
|
+
return this.manager.plugins.list();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Gets information about all installed plugins.
|
|
182
|
+
* @returns Array of plugin information objects.
|
|
183
|
+
*/
|
|
184
|
+
getPluginsInfo() {
|
|
185
|
+
return this.manager.plugins.getPluginInfo();
|
|
186
|
+
}
|
|
140
187
|
}
|
|
141
188
|
exports.LazyCanvas = LazyCanvas;
|
|
@@ -206,7 +206,7 @@ class BaseLayer {
|
|
|
206
206
|
centring: data.centring || types_1.Centring.Center,
|
|
207
207
|
filter: data.filter || '',
|
|
208
208
|
opacity: data.opacity || 1,
|
|
209
|
-
filled: data.filled ||
|
|
209
|
+
filled: data.filled || true,
|
|
210
210
|
fillStyle: data.fillStyle || '#000000',
|
|
211
211
|
transform: data.transform || {},
|
|
212
212
|
globalComposite: data.globalComposite || 'source-over',
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
1
|
import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
|
|
4
2
|
import { ScaleType, LayerType, radiusCorner } from "../../types";
|
|
5
3
|
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
|
|
@@ -110,12 +110,6 @@ export declare class MorphLayer extends BaseLayer<IMorphLayerProps> {
|
|
|
110
110
|
* @returns {this} The current instance for chaining.
|
|
111
111
|
*/
|
|
112
112
|
setStroke(width: number, cap?: CanvasLineCap, join?: CanvasLineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
|
|
113
|
-
/**
|
|
114
|
-
* Sets whether the Morph Layer should be filled or stroked.
|
|
115
|
-
* @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
|
|
116
|
-
* @returns {this} The current instance for chaining.
|
|
117
|
-
*/
|
|
118
|
-
setFilled(filled: boolean): this;
|
|
119
113
|
/**
|
|
120
114
|
* Draws the Morph Layer on the canvas.
|
|
121
115
|
* @param ctx {SKRSContext2D} - The canvas rendering context.
|
|
@@ -72,15 +72,7 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
|
72
72
|
dashOffset: dashOffset || 0,
|
|
73
73
|
miterLimit: miterLimit || 10,
|
|
74
74
|
};
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Sets whether the Morph Layer should be filled or stroked.
|
|
79
|
-
* @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
|
|
80
|
-
* @returns {this} The current instance for chaining.
|
|
81
|
-
*/
|
|
82
|
-
setFilled(filled) {
|
|
83
|
-
this.props.filled = filled;
|
|
75
|
+
this.props.filled = false; // Ensure filled is false when stroke is set
|
|
84
76
|
return this;
|
|
85
77
|
}
|
|
86
78
|
/**
|
|
@@ -115,12 +115,6 @@ export declare class Path2DLayer extends BaseLayer<IPath2DLayerProps> {
|
|
|
115
115
|
* @returns {this} The current instance for chaining.
|
|
116
116
|
*/
|
|
117
117
|
setStroke(width: number, cap?: CanvasLineCap, join?: CanvasLineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
|
|
118
|
-
/**
|
|
119
|
-
* Sets whether the Path2D Layer should be filled or stroked.
|
|
120
|
-
* @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
|
|
121
|
-
* @returns {this} The current instance for chaining.
|
|
122
|
-
*/
|
|
123
|
-
setFilled(filled: boolean): this;
|
|
124
118
|
/**
|
|
125
119
|
* Sets the color of the Path2D Layer.
|
|
126
120
|
* @param color {string} - The color of the Path2D Layer.
|
|
@@ -123,15 +123,7 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
123
123
|
dashOffset: dashOffset || 0,
|
|
124
124
|
miterLimit: miterLimit || 10,
|
|
125
125
|
};
|
|
126
|
-
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Sets whether the Path2D Layer should be filled or stroked.
|
|
130
|
-
* @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
|
|
131
|
-
* @returns {this} The current instance for chaining.
|
|
132
|
-
*/
|
|
133
|
-
setFilled(filled) {
|
|
134
|
-
this.props.filled = filled;
|
|
126
|
+
this.props.filled = false; // Ensure filled is false when stroke is set
|
|
135
127
|
return this;
|
|
136
128
|
}
|
|
137
129
|
/**
|
|
@@ -194,12 +194,6 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
|
|
|
194
194
|
* @returns {this} The current instance for chaining.
|
|
195
195
|
*/
|
|
196
196
|
setStroke(width: number, cap?: LineCap, join?: LineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
|
|
197
|
-
/**
|
|
198
|
-
* Sets whether the text layer should be filled or stroked.
|
|
199
|
-
* @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
|
|
200
|
-
* @returns {this} The current instance for chaining.
|
|
201
|
-
*/
|
|
202
|
-
setFilled(filled: boolean): this;
|
|
203
197
|
/**
|
|
204
198
|
* Sets the spacing between words in the text layer.
|
|
205
199
|
* @param wordSpacing {number} - The spacing between words.
|
|
@@ -140,15 +140,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
140
140
|
dashOffset: dashOffset || 0,
|
|
141
141
|
miterLimit: miterLimit || 10,
|
|
142
142
|
};
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Sets whether the text layer should be filled or stroked.
|
|
147
|
-
* @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
|
|
148
|
-
* @returns {this} The current instance for chaining.
|
|
149
|
-
*/
|
|
150
|
-
setFilled(filled) {
|
|
151
|
-
this.props.filled = filled;
|
|
143
|
+
this.props.filled = false; // Ensure filled is false when stroke is set
|
|
152
144
|
return this;
|
|
153
145
|
}
|
|
154
146
|
/**
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.Exporter = void 0;
|
|
27
37
|
const types_1 = require("../../types");
|
|
@@ -80,43 +90,47 @@ class Exporter {
|
|
|
80
90
|
* @throws {LazyError} If the export type is not supported.
|
|
81
91
|
*/
|
|
82
92
|
async export(exportType, opts) {
|
|
93
|
+
// beforeExport hook
|
|
94
|
+
this.canvas.manager.plugins.executeHook('beforeExport', this.canvas);
|
|
95
|
+
let result;
|
|
83
96
|
switch (exportType) {
|
|
84
97
|
case types_1.Export.CTX:
|
|
85
98
|
case "ctx":
|
|
86
|
-
|
|
99
|
+
result = await this.canvas.manager.render.render(exportType);
|
|
100
|
+
break;
|
|
87
101
|
case types_1.Export.SVG:
|
|
88
102
|
case "svg":
|
|
89
|
-
|
|
103
|
+
result = await this.canvas.manager.render.render('svg');
|
|
90
104
|
if (opts?.saveAsFile) {
|
|
91
|
-
await this.saveFile(
|
|
105
|
+
await this.saveFile(result, 'svg', opts.name);
|
|
92
106
|
}
|
|
93
|
-
|
|
107
|
+
break;
|
|
94
108
|
case types_1.Export.BUFFER:
|
|
95
109
|
case "buffer":
|
|
96
|
-
|
|
110
|
+
result = await this.canvas.manager.render.render('buffer');
|
|
97
111
|
if (opts?.saveAsFile) {
|
|
98
|
-
await this.saveFile(
|
|
112
|
+
await this.saveFile(result, 'png', opts.name);
|
|
99
113
|
}
|
|
100
|
-
|
|
114
|
+
break;
|
|
101
115
|
case types_1.Export.GIF:
|
|
102
116
|
case "gif":
|
|
103
|
-
|
|
117
|
+
result = await this.canvas.manager.render.render('buffer');
|
|
104
118
|
if (opts?.saveAsFile) {
|
|
105
|
-
await this.saveFile(
|
|
119
|
+
await this.saveFile(result, 'gif', opts.name);
|
|
106
120
|
}
|
|
107
|
-
|
|
121
|
+
break;
|
|
108
122
|
case types_1.Export.WEBP:
|
|
109
123
|
case "webp":
|
|
110
|
-
|
|
124
|
+
result = await this.canvas.manager.render.render('buffer');
|
|
111
125
|
if (opts?.saveAsFile) {
|
|
112
|
-
await this.saveFile(
|
|
126
|
+
await this.saveFile(result, 'webp', opts.name);
|
|
113
127
|
}
|
|
114
|
-
|
|
128
|
+
break;
|
|
115
129
|
case types_1.Export.JPEG:
|
|
116
130
|
case "jpeg":
|
|
117
|
-
|
|
118
|
-
await this.saveFile(
|
|
119
|
-
|
|
131
|
+
result = await this.canvas.manager.render.render('buffer');
|
|
132
|
+
await this.saveFile(result, 'jpeg', opts?.name);
|
|
133
|
+
break;
|
|
120
134
|
case types_1.Export.JPG:
|
|
121
135
|
case "jpg":
|
|
122
136
|
const jpg = await this.canvas.manager.render.render('buffer');
|
|
@@ -147,6 +161,9 @@ class Exporter {
|
|
|
147
161
|
default:
|
|
148
162
|
throw new LazyUtil_1.LazyError(`Export type ${exportType} is not supported`);
|
|
149
163
|
}
|
|
164
|
+
// afterExport hook
|
|
165
|
+
this.canvas.manager.plugins.executeHook('afterExport', this.canvas, result);
|
|
166
|
+
return result;
|
|
150
167
|
}
|
|
151
168
|
/**
|
|
152
169
|
* Synchronously exports the canvas to the specified format.
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.JSONReader = void 0;
|
|
27
37
|
const types_1 = require("../../../types");
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.YAMLReader = void 0;
|
|
27
37
|
const JSONReader_1 = require("./JSONReader");
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { AnyLayer } from "../../types";
|
|
2
2
|
import { Group } from "../components";
|
|
3
|
+
import { LazyCanvas } from "../LazyCanvas";
|
|
3
4
|
/**
|
|
4
5
|
* Interface representing the LayersManager.
|
|
5
6
|
*/
|
|
6
7
|
export interface ILayersManager {
|
|
8
|
+
/**
|
|
9
|
+
* The LazyCanvas instance associated with this manager.
|
|
10
|
+
*/
|
|
11
|
+
lazycanvas: LazyCanvas;
|
|
7
12
|
/**
|
|
8
13
|
* A map storing layers or groups with their IDs as keys.
|
|
9
14
|
*/
|
|
@@ -17,6 +22,10 @@ export interface ILayersManager {
|
|
|
17
22
|
* Class representing a manager for handling layers and groups.
|
|
18
23
|
*/
|
|
19
24
|
export declare class LayersManager implements ILayersManager {
|
|
25
|
+
/**
|
|
26
|
+
* The LazyCanvas instance associated with this manager.
|
|
27
|
+
*/
|
|
28
|
+
lazycanvas: LazyCanvas;
|
|
20
29
|
/**
|
|
21
30
|
* A map storing layers or groups with their IDs as keys.
|
|
22
31
|
*/
|
|
@@ -27,10 +36,11 @@ export declare class LayersManager implements ILayersManager {
|
|
|
27
36
|
debug: boolean;
|
|
28
37
|
/**
|
|
29
38
|
* Constructs a new LayersManager instance.
|
|
39
|
+
* @param lazycanvas {LazyCanvas} - The LazyCanvas instance to associate with this manager.
|
|
30
40
|
* @param opts {Object} - Optional settings for the LayersManager.
|
|
31
41
|
* @param opts.debug {boolean} - Whether debugging is enabled.
|
|
32
42
|
*/
|
|
33
|
-
constructor(opts?: {
|
|
43
|
+
constructor(lazycanvas: LazyCanvas, opts?: {
|
|
34
44
|
debug?: boolean;
|
|
35
45
|
});
|
|
36
46
|
/**
|