@nmmty/lazycanvas 0.6.4 → 1.0.0-dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReadMe.md +1 -1
- package/biome.json +41 -0
- package/dist/core/Interpolation.d.ts +30 -0
- package/dist/core/Interpolation.js +200 -0
- package/dist/core/Scene.d.ts +96 -0
- package/dist/core/Scene.js +172 -0
- package/dist/core/Signal.d.ts +133 -0
- package/dist/core/Signal.js +255 -0
- package/dist/core/SignalUtils.d.ts +133 -0
- package/dist/core/SignalUtils.js +333 -0
- package/dist/core/ThreadScheduler.d.ts +38 -0
- package/dist/core/ThreadScheduler.js +74 -0
- package/dist/helpers/Filters.js +1 -1
- package/dist/helpers/FontsList.js +18 -18
- package/dist/helpers/Utlis.d.ts +3 -3
- package/dist/helpers/Utlis.js +15 -18
- package/dist/helpers/index.d.ts +3 -3
- package/dist/index.d.ts +10 -0
- package/dist/index.js +10 -0
- package/dist/jsx-runtime.d.ts +17 -0
- package/dist/jsx-runtime.js +111 -0
- package/dist/structures/LazyCanvas.d.ts +3 -45
- package/dist/structures/LazyCanvas.js +11 -74
- package/dist/structures/components/BaseLayer.d.ts +34 -12
- package/dist/structures/components/BaseLayer.js +68 -35
- package/dist/structures/components/BezierLayer.d.ts +18 -39
- package/dist/structures/components/BezierLayer.js +85 -48
- package/dist/structures/components/{Group.d.ts → Div.d.ts} +26 -20
- package/dist/structures/components/{Group.js → Div.js} +39 -40
- package/dist/structures/components/ImageLayer.d.ts +2 -2
- package/dist/structures/components/ImageLayer.js +25 -26
- package/dist/structures/components/LineLayer.d.ts +13 -39
- package/dist/structures/components/LineLayer.js +44 -44
- package/dist/structures/components/MorphLayer.d.ts +4 -33
- package/dist/structures/components/MorphLayer.js +33 -47
- package/dist/structures/components/Path2DLayer.d.ts +4 -32
- package/dist/structures/components/Path2DLayer.js +28 -33
- package/dist/structures/components/PolygonLayer.d.ts +95 -0
- package/dist/structures/components/PolygonLayer.js +205 -0
- package/dist/structures/components/QuadraticLayer.d.ts +27 -44
- package/dist/structures/components/QuadraticLayer.js +87 -49
- package/dist/structures/components/TextLayer.d.ts +16 -45
- package/dist/structures/components/TextLayer.js +66 -68
- package/dist/structures/components/index.d.ts +10 -10
- package/dist/structures/components/index.js +2 -2
- package/dist/structures/helpers/Exporter.d.ts +13 -4
- package/dist/structures/helpers/Exporter.js +79 -42
- package/dist/structures/helpers/Font.js +1 -17
- package/dist/structures/helpers/Gradient.js +32 -45
- package/dist/structures/helpers/Link.js +2 -14
- package/dist/structures/helpers/Pattern.js +9 -17
- package/dist/structures/helpers/index.d.ts +7 -7
- package/dist/structures/helpers/readers/JSONReader.d.ts +4 -4
- package/dist/structures/helpers/readers/JSONReader.js +34 -40
- package/dist/structures/helpers/readers/YAMLReader.js +5 -5
- package/dist/structures/managers/FontsManager.js +9 -18
- package/dist/structures/managers/LayersManager.d.ts +18 -28
- package/dist/structures/managers/LayersManager.js +14 -36
- package/dist/structures/managers/RenderManager.d.ts +1 -15
- package/dist/structures/managers/RenderManager.js +17 -110
- package/dist/structures/managers/index.d.ts +3 -5
- package/dist/structures/managers/index.js +0 -2
- package/dist/types/enum.d.ts +4 -3
- package/dist/types/enum.js +3 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/APNGEncoder.d.ts +67 -0
- package/dist/utils/APNGEncoder.js +205 -0
- package/dist/utils/DrawUtils.d.ts +9 -0
- package/dist/utils/DrawUtils.js +42 -0
- package/dist/utils/LazyUtil.js +1 -2
- package/dist/utils/utils.d.ts +5 -9
- package/dist/utils/utils.js +148 -77
- package/package.json +62 -59
- package/dist/structures/components/ClearLayer.d.ts +0 -147
- package/dist/structures/components/ClearLayer.js +0 -158
- package/dist/structures/managers/AnimationManager.d.ts +0 -120
- package/dist/structures/managers/AnimationManager.js +0 -99
- package/dist/structures/managers/PluginManager.d.ts +0 -230
- package/dist/structures/managers/PluginManager.js +0 -182
- package/dist/types/types.d.ts +0 -105
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Canvas, DOMMatrix2DInit, FillType, Path2D, PathOp, SKRSContext2D,
|
|
1
|
+
import { Canvas, DOMMatrix2DInit, FillType, Path2D, PathOp, SKRSContext2D, SvgCanvas, StrokeOptions as SKRSStrokeOptions } from "@napi-rs/canvas";
|
|
2
2
|
import { ColorType, LayerType } from "../../types";
|
|
3
3
|
import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
|
|
4
4
|
import { LayersManager } from "../managers";
|
|
5
|
+
import { StrokeOptions } from "../../types";
|
|
5
6
|
export interface IPath2DLayer extends IBaseLayer {
|
|
6
7
|
/**
|
|
7
8
|
* The type of the layer, which is `Path`.
|
|
@@ -17,10 +18,6 @@ export interface IPath2DLayerProps extends IBaseLayerProps {
|
|
|
17
18
|
* The Path2D object representing the shape of the layer.
|
|
18
19
|
*/
|
|
19
20
|
path2D: Path2D;
|
|
20
|
-
/**
|
|
21
|
-
* Whether the layer is filled.
|
|
22
|
-
*/
|
|
23
|
-
filled: boolean;
|
|
24
21
|
/**
|
|
25
22
|
* The fill style (color or pattern) of the layer.
|
|
26
23
|
*/
|
|
@@ -28,32 +25,7 @@ export interface IPath2DLayerProps extends IBaseLayerProps {
|
|
|
28
25
|
/**
|
|
29
26
|
* The stroke properties of the Path2D.
|
|
30
27
|
*/
|
|
31
|
-
stroke:
|
|
32
|
-
/**
|
|
33
|
-
* The width of the stroke.
|
|
34
|
-
*/
|
|
35
|
-
width: number;
|
|
36
|
-
/**
|
|
37
|
-
* The cap style of the stroke.
|
|
38
|
-
*/
|
|
39
|
-
cap: CanvasLineCap;
|
|
40
|
-
/**
|
|
41
|
-
* The join style of the stroke.
|
|
42
|
-
*/
|
|
43
|
-
join: CanvasLineJoin;
|
|
44
|
-
/**
|
|
45
|
-
* The dash offset of the stroke.
|
|
46
|
-
*/
|
|
47
|
-
dashOffset: number;
|
|
48
|
-
/**
|
|
49
|
-
* The dash pattern of the stroke.
|
|
50
|
-
*/
|
|
51
|
-
dash: number[];
|
|
52
|
-
/**
|
|
53
|
-
* The miter limit of the stroke.
|
|
54
|
-
*/
|
|
55
|
-
miterLimit: number;
|
|
56
|
-
};
|
|
28
|
+
stroke: StrokeOptions;
|
|
57
29
|
loadFromSVG: boolean;
|
|
58
30
|
clipPath: boolean;
|
|
59
31
|
}
|
|
@@ -85,7 +57,7 @@ export declare class Path2DLayer extends BaseLayer<IPath2DLayerProps> {
|
|
|
85
57
|
moveTo(x: number, y: number): this;
|
|
86
58
|
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
|
|
87
59
|
rect(x: number, y: number, width: number, height: number): this;
|
|
88
|
-
stroke(stroke?:
|
|
60
|
+
stroke(stroke?: SKRSStrokeOptions): this;
|
|
89
61
|
op(path: Path2D, op: PathOp): this;
|
|
90
62
|
getFillType(): FillType;
|
|
91
63
|
getFillTypeString(): string;
|
|
@@ -6,14 +6,11 @@ const types_1 = require("../../types");
|
|
|
6
6
|
const utils_1 = require("../../utils/utils");
|
|
7
7
|
const BaseLayer_1 = require("./BaseLayer");
|
|
8
8
|
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
9
|
+
const DrawUtils_1 = require("../../utils/DrawUtils");
|
|
9
10
|
class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
10
|
-
id;
|
|
11
|
-
type = types_1.LayerType.Path;
|
|
12
|
-
zIndex;
|
|
13
|
-
visible;
|
|
14
|
-
props;
|
|
15
11
|
constructor(props, misc) {
|
|
16
12
|
super(types_1.LayerType.Path, props || {}, misc);
|
|
13
|
+
this.type = types_1.LayerType.Path;
|
|
17
14
|
this.id = misc?.id || (0, utils_1.generateID)(types_1.LayerType.Path);
|
|
18
15
|
this.zIndex = misc?.zIndex || 1;
|
|
19
16
|
this.visible = misc?.visible || true;
|
|
@@ -28,9 +25,9 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
28
25
|
*/
|
|
29
26
|
setColor(color) {
|
|
30
27
|
if (!color)
|
|
31
|
-
throw new LazyUtil_1.LazyError(
|
|
28
|
+
throw new LazyUtil_1.LazyError("The color of the layer must be provided");
|
|
32
29
|
if (!(0, utils_1.isColor)(color))
|
|
33
|
-
throw new LazyUtil_1.LazyError(
|
|
30
|
+
throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
|
|
34
31
|
this.props.fillStyle = color;
|
|
35
32
|
return this;
|
|
36
33
|
}
|
|
@@ -139,28 +136,27 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
139
136
|
async draw(ctx, canvas, manager, debug) {
|
|
140
137
|
ctx.beginPath();
|
|
141
138
|
ctx.save();
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
(0, utils_1.filters)(ctx, this.props.filter);
|
|
147
|
-
ctx.globalCompositeOperation = this.props.globalComposite;
|
|
139
|
+
if (this.props.transform) {
|
|
140
|
+
(0, utils_1.transform)(ctx, this.props.transform, { width: 0, height: 0, x: 0, y: 0, type: this.type });
|
|
141
|
+
}
|
|
142
|
+
DrawUtils_1.DrawUtils.opacity(ctx, this.props.opacity);
|
|
148
143
|
if (this.props.clipPath) {
|
|
149
144
|
ctx.clip(this.props.path2D);
|
|
150
145
|
}
|
|
151
|
-
else if (this.props.
|
|
152
|
-
ctx.fillStyle
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
ctx.
|
|
157
|
-
ctx
|
|
158
|
-
ctx
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
146
|
+
else if (this.props.fillStyle) {
|
|
147
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, manager });
|
|
148
|
+
if (this.props.globalComposite) {
|
|
149
|
+
ctx.globalCompositeOperation = this.props.globalComposite;
|
|
150
|
+
}
|
|
151
|
+
DrawUtils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
|
|
152
|
+
DrawUtils_1.DrawUtils.filters(ctx, this.props.filter);
|
|
153
|
+
DrawUtils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
|
|
154
|
+
if (this.props.stroke) {
|
|
155
|
+
ctx.stroke(this.props.path2D);
|
|
156
|
+
}
|
|
157
|
+
else {
|
|
158
|
+
ctx.fill(this.props.path2D);
|
|
159
|
+
}
|
|
164
160
|
}
|
|
165
161
|
ctx.restore();
|
|
166
162
|
ctx.closePath();
|
|
@@ -175,7 +171,7 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
175
171
|
type: this.type,
|
|
176
172
|
zIndex: this.zIndex,
|
|
177
173
|
visible: this.visible,
|
|
178
|
-
props: this.props
|
|
174
|
+
props: this.props,
|
|
179
175
|
};
|
|
180
176
|
}
|
|
181
177
|
/**
|
|
@@ -186,19 +182,18 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
186
182
|
validateProps(data) {
|
|
187
183
|
return {
|
|
188
184
|
...super.validateProps(data),
|
|
189
|
-
|
|
190
|
-
fillStyle: data.fillStyle || '#000000',
|
|
185
|
+
fillStyle: data.fillStyle || "#000000",
|
|
191
186
|
path2D: data.path2D || new canvas_1.Path2D(),
|
|
192
187
|
stroke: {
|
|
193
188
|
width: data.stroke?.width || 1,
|
|
194
|
-
cap: data.stroke?.cap ||
|
|
195
|
-
join: data.stroke?.join ||
|
|
189
|
+
cap: data.stroke?.cap || "butt",
|
|
190
|
+
join: data.stroke?.join || "miter",
|
|
196
191
|
dashOffset: data.stroke?.dashOffset || 0,
|
|
197
192
|
dash: data.stroke?.dash || [],
|
|
198
|
-
miterLimit: data.stroke?.miterLimit || 10
|
|
193
|
+
miterLimit: data.stroke?.miterLimit || 10,
|
|
199
194
|
},
|
|
200
195
|
loadFromSVG: data.loadFromSVG || false,
|
|
201
|
-
clipPath: data.clipPath || false
|
|
196
|
+
clipPath: data.clipPath || false,
|
|
202
197
|
};
|
|
203
198
|
}
|
|
204
199
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
|
|
2
|
+
import { ColorType, LayerType, ScaleType, StrokeOptions } from "../../types";
|
|
3
|
+
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
|
|
4
|
+
import { LayersManager } from "../managers";
|
|
5
|
+
export interface IPolygonLayer extends IBaseLayer {
|
|
6
|
+
/**
|
|
7
|
+
* The type of the layer, which is `Polygon`.
|
|
8
|
+
*/
|
|
9
|
+
type: LayerType.Polygon;
|
|
10
|
+
/**
|
|
11
|
+
* The properties specific to the Polygon Layer.
|
|
12
|
+
*/
|
|
13
|
+
props: IPolygonLayerProps;
|
|
14
|
+
}
|
|
15
|
+
export interface IPolygonLayerProps extends IBaseLayerProps {
|
|
16
|
+
/**
|
|
17
|
+
* The size of the Polygon Layer, including width, height, and radius.
|
|
18
|
+
*/
|
|
19
|
+
size: {
|
|
20
|
+
/**
|
|
21
|
+
* The width of the Polygon Layer.
|
|
22
|
+
*/
|
|
23
|
+
width: ScaleType;
|
|
24
|
+
/**
|
|
25
|
+
* The height of the Polygon Layer.
|
|
26
|
+
*/
|
|
27
|
+
height: ScaleType;
|
|
28
|
+
/**
|
|
29
|
+
* The radius of corners in the Polygon Layer.
|
|
30
|
+
*/
|
|
31
|
+
radius: number;
|
|
32
|
+
/**
|
|
33
|
+
* The number of sides of the polygon.
|
|
34
|
+
*/
|
|
35
|
+
count: number;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The fill style (color or pattern) of the layer.
|
|
39
|
+
*/
|
|
40
|
+
fillStyle: ColorType;
|
|
41
|
+
/**
|
|
42
|
+
* The stroke properties of the polygon.
|
|
43
|
+
*/
|
|
44
|
+
stroke?: StrokeOptions;
|
|
45
|
+
}
|
|
46
|
+
export declare class PolygonLayer extends BaseLayer<IPolygonLayerProps> {
|
|
47
|
+
props: IPolygonLayerProps;
|
|
48
|
+
constructor(props?: IPolygonLayerProps, misc?: IBaseLayerMisc);
|
|
49
|
+
/**
|
|
50
|
+
* Sets the size of the Polygon layer.
|
|
51
|
+
* @param {ScaleType} [width] - The width of the Polygon layer.
|
|
52
|
+
* @param {ScaleType} [height] - The height of the Polygon layer.
|
|
53
|
+
* @param {number} [count] - The number of sides of the polygon.
|
|
54
|
+
* @param {number} [radius] - The radius of the Polygon Layer (optional).
|
|
55
|
+
* @returns {this} The current instance for chaining.
|
|
56
|
+
*/
|
|
57
|
+
setSize(width: ScaleType, height: ScaleType, count: number, radius?: number): this;
|
|
58
|
+
/**
|
|
59
|
+
* Sets the color of the Polygon layer.
|
|
60
|
+
* @param {ColorType} [color] - The color of the layer.
|
|
61
|
+
* @returns {this} The current instance for chaining.
|
|
62
|
+
* @throws {LazyError} If the color is not provided or invalid.
|
|
63
|
+
*/
|
|
64
|
+
setColor(color: ColorType): this;
|
|
65
|
+
/**
|
|
66
|
+
* Sets the stroke properties of the Polygon Layer.
|
|
67
|
+
* @param {number} [width] - The width of the stroke.
|
|
68
|
+
* @param {string} [cap] - The cap style of the stroke.
|
|
69
|
+
* @param {string} [join] - The join style of the stroke.
|
|
70
|
+
* @param {number[]} [dash] - The dash pattern of the stroke.
|
|
71
|
+
* @param {number} [dashOffset] - The dash offset of the stroke.
|
|
72
|
+
* @param {number} [miterLimit] - The miter limit of the stroke.
|
|
73
|
+
* @returns {this} The current instance for chaining.
|
|
74
|
+
*/
|
|
75
|
+
setStroke(width: number, cap?: CanvasLineCap, join?: CanvasLineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
|
|
76
|
+
/**
|
|
77
|
+
* Draws the Polygon layer on the given canvas context.
|
|
78
|
+
* @param {SKRSContext2D} [ctx] - The canvas rendering context.
|
|
79
|
+
* @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
|
|
80
|
+
* @param {LayersManager} [manager] - The layer's manager.
|
|
81
|
+
* @param {boolean} [debug] - Whether to enable debug logging.
|
|
82
|
+
*/
|
|
83
|
+
draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
|
|
84
|
+
/**
|
|
85
|
+
* Converts the Polygon layer to a JSON representation.
|
|
86
|
+
* @returns {IPolygonLayer} The JSON representation of the Polygon layer.
|
|
87
|
+
*/
|
|
88
|
+
toJSON(): IPolygonLayer;
|
|
89
|
+
/**
|
|
90
|
+
* Validates the properties of the Morph Layer.
|
|
91
|
+
* @param {IPolygonLayerProps} [data] - The properties to validate.
|
|
92
|
+
* @returns {IPolygonLayerProps} The validated properties.
|
|
93
|
+
*/
|
|
94
|
+
protected validateProps(data: IPolygonLayerProps): IPolygonLayerProps;
|
|
95
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PolygonLayer = void 0;
|
|
4
|
+
const BaseLayer_1 = require("./BaseLayer");
|
|
5
|
+
const types_1 = require("../../types");
|
|
6
|
+
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
7
|
+
const utils_1 = require("../../utils/utils");
|
|
8
|
+
const DrawUtils_1 = require("../../utils/DrawUtils");
|
|
9
|
+
class PolygonLayer extends BaseLayer_1.BaseLayer {
|
|
10
|
+
constructor(props, misc) {
|
|
11
|
+
super(types_1.LayerType.Polygon, props || {}, misc);
|
|
12
|
+
this.props = props ? props : {};
|
|
13
|
+
this.props = this.validateProps(this.props);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Sets the size of the Polygon layer.
|
|
17
|
+
* @param {ScaleType} [width] - The width of the Polygon layer.
|
|
18
|
+
* @param {ScaleType} [height] - The height of the Polygon layer.
|
|
19
|
+
* @param {number} [count] - The number of sides of the polygon.
|
|
20
|
+
* @param {number} [radius] - The radius of the Polygon Layer (optional).
|
|
21
|
+
* @returns {this} The current instance for chaining.
|
|
22
|
+
*/
|
|
23
|
+
setSize(width, height, count, radius) {
|
|
24
|
+
this.props.size = {
|
|
25
|
+
width: width,
|
|
26
|
+
height: height,
|
|
27
|
+
count: count,
|
|
28
|
+
radius: radius || 0,
|
|
29
|
+
};
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sets the color of the Polygon layer.
|
|
34
|
+
* @param {ColorType} [color] - The color of the layer.
|
|
35
|
+
* @returns {this} The current instance for chaining.
|
|
36
|
+
* @throws {LazyError} If the color is not provided or invalid.
|
|
37
|
+
*/
|
|
38
|
+
setColor(color) {
|
|
39
|
+
if (!color)
|
|
40
|
+
throw new LazyUtil_1.LazyError("The color of the layer must be provided");
|
|
41
|
+
if (!(0, utils_1.isColor)(color))
|
|
42
|
+
throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
|
|
43
|
+
this.props.fillStyle = color;
|
|
44
|
+
return this;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Sets the stroke properties of the Polygon Layer.
|
|
48
|
+
* @param {number} [width] - The width of the stroke.
|
|
49
|
+
* @param {string} [cap] - The cap style of the stroke.
|
|
50
|
+
* @param {string} [join] - The join style of the stroke.
|
|
51
|
+
* @param {number[]} [dash] - The dash pattern of the stroke.
|
|
52
|
+
* @param {number} [dashOffset] - The dash offset of the stroke.
|
|
53
|
+
* @param {number} [miterLimit] - The miter limit of the stroke.
|
|
54
|
+
* @returns {this} The current instance for chaining.
|
|
55
|
+
*/
|
|
56
|
+
setStroke(width, cap, join, dash, dashOffset, miterLimit) {
|
|
57
|
+
this.props.stroke = {
|
|
58
|
+
width,
|
|
59
|
+
cap: cap || "butt",
|
|
60
|
+
join: join || "miter",
|
|
61
|
+
dash: dash || [],
|
|
62
|
+
dashOffset: dashOffset || 0,
|
|
63
|
+
miterLimit: miterLimit || 10,
|
|
64
|
+
};
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Draws the Polygon layer on the given canvas context.
|
|
69
|
+
* @param {SKRSContext2D} [ctx] - The canvas rendering context.
|
|
70
|
+
* @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
|
|
71
|
+
* @param {LayersManager} [manager] - The layer's manager.
|
|
72
|
+
* @param {boolean} [debug] - Whether to enable debug logging.
|
|
73
|
+
*/
|
|
74
|
+
async draw(ctx, canvas, manager, debug) {
|
|
75
|
+
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
76
|
+
const { xs, ys, w } = parcer.parseBatch({
|
|
77
|
+
xs: { v: this.props.position.x },
|
|
78
|
+
ys: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
|
|
79
|
+
w: { v: this.props.size.width },
|
|
80
|
+
});
|
|
81
|
+
const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
|
|
82
|
+
let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
|
|
83
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, {
|
|
84
|
+
debug,
|
|
85
|
+
layer: { width: w, height: h, x: xs, y: ys, align: this.props.centring },
|
|
86
|
+
manager,
|
|
87
|
+
});
|
|
88
|
+
if (debug)
|
|
89
|
+
LazyUtil_1.LazyLog.log("none", `PolygonLayer:`, {
|
|
90
|
+
x,
|
|
91
|
+
y,
|
|
92
|
+
w,
|
|
93
|
+
h,
|
|
94
|
+
count: this.props.size.count,
|
|
95
|
+
radius: this.props.size.radius,
|
|
96
|
+
});
|
|
97
|
+
ctx.save();
|
|
98
|
+
ctx.beginPath();
|
|
99
|
+
// Calculate polygon vertices
|
|
100
|
+
const vertices = [];
|
|
101
|
+
for (let i = 0; i < this.props.size.count; i++) {
|
|
102
|
+
const angle = (i / this.props.size.count) * (2 * Math.PI) - Math.PI / 2;
|
|
103
|
+
vertices.push({
|
|
104
|
+
x: x + w / 2 + (w / 2) * Math.cos(angle),
|
|
105
|
+
y: y + h / 2 + (h / 2) * Math.sin(angle),
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (this.props.size.radius > 0) {
|
|
109
|
+
// Draw polygon with rounded corners
|
|
110
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
111
|
+
const current = vertices[i];
|
|
112
|
+
const next = vertices[(i + 1) % vertices.length];
|
|
113
|
+
const prev = vertices[(i - 1 + vertices.length) % vertices.length];
|
|
114
|
+
// Calculate vectors from current vertex to adjacent vertices
|
|
115
|
+
const dx1 = current.x - prev.x;
|
|
116
|
+
const dy1 = current.y - prev.y;
|
|
117
|
+
const dx2 = next.x - current.x;
|
|
118
|
+
const dy2 = next.y - current.y;
|
|
119
|
+
// Normalize vectors
|
|
120
|
+
const len1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
|
|
121
|
+
const len2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
|
|
122
|
+
const ndx1 = dx1 / len1;
|
|
123
|
+
const ndy1 = dy1 / len1;
|
|
124
|
+
const ndx2 = dx2 / len2;
|
|
125
|
+
const ndy2 = dy2 / len2;
|
|
126
|
+
// Calculate the maximum radius based on edge lengths
|
|
127
|
+
const maxRadius = Math.max(len1 / 2, len2 / 2);
|
|
128
|
+
const cornerRadius = Math.min(this.props.size.radius, maxRadius);
|
|
129
|
+
// Calculate arc start and end points
|
|
130
|
+
const arcStart = {
|
|
131
|
+
x: current.x - ndx1 * cornerRadius,
|
|
132
|
+
y: current.y - ndy1 * cornerRadius,
|
|
133
|
+
};
|
|
134
|
+
const arcEnd = {
|
|
135
|
+
x: current.x + ndx2 * cornerRadius,
|
|
136
|
+
y: current.y + ndy2 * cornerRadius,
|
|
137
|
+
};
|
|
138
|
+
if (i === 0) {
|
|
139
|
+
ctx.moveTo(arcStart.x, arcStart.y);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
ctx.lineTo(arcStart.x, arcStart.y);
|
|
143
|
+
}
|
|
144
|
+
// Draw arc at corner
|
|
145
|
+
ctx.arcTo(current.x, current.y, arcEnd.x, arcEnd.y, cornerRadius);
|
|
146
|
+
}
|
|
147
|
+
ctx.closePath();
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
// Draw polygon without rounded corners (original behavior)
|
|
151
|
+
for (let i = 0; i < vertices.length; i++) {
|
|
152
|
+
if (i === 0) {
|
|
153
|
+
ctx.moveTo(vertices[i].x, vertices[i].y);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
ctx.lineTo(vertices[i].x, vertices[i].y);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
ctx.closePath();
|
|
160
|
+
}
|
|
161
|
+
DrawUtils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
|
|
162
|
+
DrawUtils_1.DrawUtils.opacity(ctx, this.props.opacity);
|
|
163
|
+
DrawUtils_1.DrawUtils.filters(ctx, this.props.filter);
|
|
164
|
+
DrawUtils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
|
|
165
|
+
if (this.props.stroke) {
|
|
166
|
+
ctx.stroke();
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
ctx.fill();
|
|
170
|
+
}
|
|
171
|
+
ctx.restore();
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Converts the Polygon layer to a JSON representation.
|
|
175
|
+
* @returns {IPolygonLayer} The JSON representation of the Polygon layer.
|
|
176
|
+
*/
|
|
177
|
+
toJSON() {
|
|
178
|
+
let data = super.toJSON();
|
|
179
|
+
let copy = { ...this.props };
|
|
180
|
+
for (const key of ["x", "y", "size.width", "size.height", "fillStyle"]) {
|
|
181
|
+
if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
|
|
182
|
+
copy[key] = copy[key].toJSON();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return { ...data, props: copy };
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Validates the properties of the Morph Layer.
|
|
189
|
+
* @param {IPolygonLayerProps} [data] - The properties to validate.
|
|
190
|
+
* @returns {IPolygonLayerProps} The validated properties.
|
|
191
|
+
*/
|
|
192
|
+
validateProps(data) {
|
|
193
|
+
return {
|
|
194
|
+
...super.validateProps(data),
|
|
195
|
+
size: {
|
|
196
|
+
width: data.size?.width || 100,
|
|
197
|
+
height: data.size?.height || 100,
|
|
198
|
+
radius: data.size?.radius || 0,
|
|
199
|
+
count: data.size?.count || 3,
|
|
200
|
+
},
|
|
201
|
+
fillStyle: data.fillStyle || "#000000",
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
exports.PolygonLayer = PolygonLayer;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
|
|
2
|
-
import { ColorType, ScaleType, Point, LayerType } from "../../types";
|
|
2
|
+
import { ColorType, ScaleType, Point, LayerType, StrokeOptions } from "../../types";
|
|
3
3
|
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
|
|
4
4
|
import { LayersManager } from "../managers";
|
|
5
5
|
/**
|
|
6
|
-
* Interface representing a Quadratic
|
|
6
|
+
* Interface representing a Quadratic layer.
|
|
7
7
|
*/
|
|
8
8
|
export interface IQuadraticLayer extends IBaseLayer {
|
|
9
9
|
/**
|
|
@@ -11,22 +11,28 @@ export interface IQuadraticLayer extends IBaseLayer {
|
|
|
11
11
|
*/
|
|
12
12
|
type: LayerType.QuadraticCurve;
|
|
13
13
|
/**
|
|
14
|
-
* The properties specific to the Quadratic
|
|
14
|
+
* The properties specific to the Quadratic layer.
|
|
15
15
|
*/
|
|
16
16
|
props: IQuadraticLayerProps;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
|
-
* Interface representing the properties of a Quadratic
|
|
19
|
+
* Interface representing the properties of a Quadratic layer.
|
|
20
20
|
*/
|
|
21
21
|
export interface IQuadraticLayerProps extends IBaseLayerProps {
|
|
22
|
+
position: IBaseLayerProps["position"] & {
|
|
23
|
+
/**
|
|
24
|
+
* The end x coordinate of the quadratic curve.
|
|
25
|
+
*/
|
|
26
|
+
endX: ScaleType;
|
|
27
|
+
/**
|
|
28
|
+
* The end y coordinate of the quadratic curve.
|
|
29
|
+
*/
|
|
30
|
+
endY: ScaleType;
|
|
31
|
+
};
|
|
22
32
|
/**
|
|
23
33
|
* The control point of the quadratic curve, including x and y coordinates.
|
|
24
34
|
*/
|
|
25
35
|
controlPoints: Array<Point>;
|
|
26
|
-
/**
|
|
27
|
-
* The end point of the quadratic curve, including x and y coordinates.
|
|
28
|
-
*/
|
|
29
|
-
endPoint: Point;
|
|
30
36
|
/**
|
|
31
37
|
* Whether the layer is filled.
|
|
32
38
|
*/
|
|
@@ -38,44 +44,19 @@ export interface IQuadraticLayerProps extends IBaseLayerProps {
|
|
|
38
44
|
/**
|
|
39
45
|
* The stroke properties of the quadratic curve.
|
|
40
46
|
*/
|
|
41
|
-
stroke:
|
|
42
|
-
/**
|
|
43
|
-
* The width of the stroke.
|
|
44
|
-
*/
|
|
45
|
-
width: number;
|
|
46
|
-
/**
|
|
47
|
-
* The cap style of the stroke.
|
|
48
|
-
*/
|
|
49
|
-
cap: CanvasLineCap;
|
|
50
|
-
/**
|
|
51
|
-
* The join style of the stroke.
|
|
52
|
-
*/
|
|
53
|
-
join: CanvasLineJoin;
|
|
54
|
-
/**
|
|
55
|
-
* The dash offset of the stroke.
|
|
56
|
-
*/
|
|
57
|
-
dashOffset: number;
|
|
58
|
-
/**
|
|
59
|
-
* The dash pattern of the stroke.
|
|
60
|
-
*/
|
|
61
|
-
dash: number[];
|
|
62
|
-
/**
|
|
63
|
-
* The miter limit of the stroke.
|
|
64
|
-
*/
|
|
65
|
-
miterLimit: number;
|
|
66
|
-
};
|
|
47
|
+
stroke: StrokeOptions;
|
|
67
48
|
}
|
|
68
49
|
/**
|
|
69
|
-
* Class representing a Quadratic
|
|
50
|
+
* Class representing a Quadratic layer, extending the BaseLayer class.
|
|
70
51
|
*/
|
|
71
52
|
export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
|
|
72
53
|
/**
|
|
73
|
-
* The properties of the Quadratic
|
|
54
|
+
* The properties of the Quadratic layer.
|
|
74
55
|
*/
|
|
75
56
|
props: IQuadraticLayerProps;
|
|
76
57
|
/**
|
|
77
58
|
* Constructs a new QuadraticLayer instance.
|
|
78
|
-
* @param {IQuadraticLayerProps} [props] - The properties of the Quadratic
|
|
59
|
+
* @param {IQuadraticLayerProps} [props] - The properties of the Quadratic layer.
|
|
79
60
|
* @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
|
|
80
61
|
*/
|
|
81
62
|
constructor(props?: IQuadraticLayerProps, misc?: IBaseLayerMisc);
|
|
@@ -87,12 +68,14 @@ export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
|
|
|
87
68
|
*/
|
|
88
69
|
setControlPoint(x: ScaleType, y: ScaleType): this;
|
|
89
70
|
/**
|
|
90
|
-
* Sets the
|
|
71
|
+
* Sets the position of the quadratic layer.
|
|
91
72
|
* @param {ScaleType} [x] - The x-coordinate of the end point.
|
|
92
73
|
* @param {ScaleType} [y] - The y-coordinate of the end point.
|
|
74
|
+
* @param {ScaleType} [endX] - The x-coordinate of the end point.
|
|
75
|
+
* @param {ScaleType} [endY] - The y-coordinate of the end point.
|
|
93
76
|
* @returns {this} The current instance for chaining.
|
|
94
77
|
*/
|
|
95
|
-
|
|
78
|
+
setPosition(x: ScaleType, y: ScaleType, endX?: ScaleType, endY?: ScaleType): this;
|
|
96
79
|
/**
|
|
97
80
|
* Sets the color of the layer.
|
|
98
81
|
* @param {ColorType} [color] - The color of the layer.
|
|
@@ -115,7 +98,7 @@ export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
|
|
|
115
98
|
* Calculates the bounding box of the quadratic curve.
|
|
116
99
|
* @param {SKRSContext2D} [ctx] - The canvas rendering context.
|
|
117
100
|
* @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
|
|
118
|
-
* @param {LayersManager} [manager] - The
|
|
101
|
+
* @param {LayersManager} [manager] - The layer's manager.
|
|
119
102
|
* @returns {Object} The bounding box details including max, min, center, width, and height.
|
|
120
103
|
*/
|
|
121
104
|
getBoundingBox(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager): {
|
|
@@ -138,17 +121,17 @@ export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
|
|
|
138
121
|
* Draws the quadratic curve on the canvas.
|
|
139
122
|
* @param {SKRSContext2D} [ctx] - The canvas rendering context.
|
|
140
123
|
* @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
|
|
141
|
-
* @param {LayersManager} [manager] - The
|
|
124
|
+
* @param {LayersManager} [manager] - The layer's manager.
|
|
142
125
|
* @param {boolean} [debug] - Whether to enable debug logging.
|
|
143
126
|
*/
|
|
144
127
|
draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
|
|
145
128
|
/**
|
|
146
|
-
* Converts the Quadratic
|
|
147
|
-
* @returns {IQuadraticLayer} The JSON representation of the Quadratic
|
|
129
|
+
* Converts the Quadratic layer to a JSON representation.
|
|
130
|
+
* @returns {IQuadraticLayer} The JSON representation of the Quadratic layer.
|
|
148
131
|
*/
|
|
149
132
|
toJSON(): IQuadraticLayer;
|
|
150
133
|
/**
|
|
151
|
-
* Validates the properties of the Quadratic
|
|
134
|
+
* Validates the properties of the Quadratic layer.
|
|
152
135
|
* @param {IQuadraticLayerProps} [data] - The properties to validate.
|
|
153
136
|
* @returns {IQuadraticLayerProps} The validated properties.
|
|
154
137
|
*/
|