@nmmty/lazycanvas 0.6.3 → 0.6.5

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.
@@ -118,7 +118,7 @@ export declare class BezierLayer extends BaseLayer<IBezierLayerProps> {
118
118
  * Calculates the bounding box of the Bezier layer.
119
119
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
120
120
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
121
- * @param {LayersManager} [manager] - The layers manager.
121
+ * @param {LayersManager} [manager] - The layer's manager.
122
122
  * @returns {Object} The bounding box details including max, min, center, width, and height.
123
123
  */
124
124
  getBoundingBox(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager): {
@@ -132,7 +132,7 @@ export declare class BezierLayer extends BaseLayer<IBezierLayerProps> {
132
132
  * Draws the Bezier layer on the canvas.
133
133
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
134
134
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
135
- * @param {LayersManager} [manager] - The layers manager.
135
+ * @param {LayersManager} [manager] - The layer's manager.
136
136
  * @param {boolean} [debug] - Whether to enable debug logging.
137
137
  */
138
138
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
@@ -84,7 +84,7 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
84
84
  * Calculates the bounding box of the Bezier layer.
85
85
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
86
86
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
87
- * @param {LayersManager} [manager] - The layers manager.
87
+ * @param {LayersManager} [manager] - The layer's manager.
88
88
  * @returns {Object} The bounding box details including max, min, center, width, and height.
89
89
  */
90
90
  getBoundingBox(ctx, canvas, manager) {
@@ -106,7 +106,7 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
106
106
  * Draws the Bezier layer on the canvas.
107
107
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
108
108
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
109
- * @param {LayersManager} [manager] - The layers manager.
109
+ * @param {LayersManager} [manager] - The layer's manager.
110
110
  * @param {boolean} [debug] - Whether to enable debug logging.
111
111
  */
112
112
  async draw(ctx, canvas, manager, debug) {
@@ -134,7 +134,7 @@ export declare class ClearLayer implements IClearLayer {
134
134
  * Draws the Clear Layer on the canvas.
135
135
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
136
136
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
137
- * @param {LayersManager} [manager] - The layers manager.
137
+ * @param {LayersManager} [manager] - The layer's manager.
138
138
  * @param {boolean} [debug] - Whether to enable debug logging.
139
139
  */
140
140
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
@@ -107,7 +107,7 @@ class ClearLayer {
107
107
  * Draws the Clear Layer on the canvas.
108
108
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
109
109
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
110
- * @param {LayersManager} [manager] - The layers manager.
110
+ * @param {LayersManager} [manager] - The layer's manager.
111
111
  * @param {boolean} [debug] - Whether to enable debug logging.
112
112
  */
113
113
  async draw(ctx, canvas, manager, debug) {
@@ -2,7 +2,7 @@ import { AnyGlobalCompositeOperation, AnyLayer, LayerType } from "../../types";
2
2
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
3
3
  import { LayersManager } from "../managers";
4
4
  /**
5
- * Interface representing a group of layers.
5
+ * Interface representing a group of layer's.
6
6
  */
7
7
  export interface IGroup {
8
8
  /**
@@ -22,7 +22,7 @@ export interface IGroup {
22
22
  */
23
23
  zIndex: number;
24
24
  /**
25
- * The layers contained within the group.
25
+ * The layer's contained within the group.
26
26
  */
27
27
  layers: Array<AnyLayer>;
28
28
  /**
@@ -37,7 +37,7 @@ export interface IGroupProps {
37
37
  globalComposite: AnyGlobalCompositeOperation;
38
38
  }
39
39
  /**
40
- * Class representing a group of layers.
40
+ * Class representing a group of layer's.
41
41
  */
42
42
  export declare class Group implements IGroup {
43
43
  /**
@@ -57,7 +57,7 @@ export declare class Group implements IGroup {
57
57
  */
58
58
  zIndex: number;
59
59
  /**
60
- * The layers contained within the group.
60
+ * The layer's contained within the group.
61
61
  */
62
62
  layers: Array<any>;
63
63
  props?: IGroupProps;
@@ -5,7 +5,7 @@ const types_1 = require("../../types");
5
5
  const utils_1 = require("../../utils/utils");
6
6
  const LazyUtil_1 = require("../../utils/LazyUtil");
7
7
  /**
8
- * Class representing a group of layers.
8
+ * Class representing a group of layer's.
9
9
  */
10
10
  class Group {
11
11
  /**
@@ -25,7 +25,7 @@ class Group {
25
25
  */
26
26
  zIndex;
27
27
  /**
28
- * The layers contained within the group.
28
+ * The layer's contained within the group.
29
29
  */
30
30
  layers;
31
31
  props;
@@ -78,7 +78,7 @@ export declare class ImageLayer extends BaseLayer<IImageLayerProps> {
78
78
  * Draws the Image Layer on the canvas.
79
79
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
80
80
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
81
- * @param {LayersManager} [manager] - The layers manager.
81
+ * @param {LayersManager} [manager] - The layer's manager.
82
82
  * @param {boolean} [debug] - Whether to enable debug logging.
83
83
  * @throws {LazyError} If the image could not be loaded.
84
84
  */
@@ -56,7 +56,7 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
56
56
  * Draws the Image Layer on the canvas.
57
57
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
58
58
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
59
- * @param {LayersManager} [manager] - The layers manager.
59
+ * @param {LayersManager} [manager] - The layer's manager.
60
60
  * @param {boolean} [debug] - Whether to enable debug logging.
61
61
  * @throws {LazyError} If the image could not be loaded.
62
62
  */
@@ -113,7 +113,7 @@ export declare class LineLayer extends BaseLayer<ILineLayerProps> {
113
113
  * Calculates the bounding box of the line layer.
114
114
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
115
115
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
116
- * @param {LayersManager} [manager] - The layers manager.
116
+ * @param {LayersManager} [manager] - The layer's manager.
117
117
  * @returns {Object} The bounding box details including start and end points, width, and height.
118
118
  */
119
119
  getBoundingBox(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager): {
@@ -128,7 +128,7 @@ export declare class LineLayer extends BaseLayer<ILineLayerProps> {
128
128
  * Draws the line layer on the canvas.
129
129
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
130
130
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
131
- * @param {LayersManager} [manager] - The layers manager.
131
+ * @param {LayersManager} [manager] - The layer's manager.
132
132
  * @param {boolean} [debug] - Whether to enable debug logging.
133
133
  */
134
134
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
@@ -72,7 +72,7 @@ class LineLayer extends BaseLayer_1.BaseLayer {
72
72
  * Calculates the bounding box of the line layer.
73
73
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
74
74
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
75
- * @param {LayersManager} [manager] - The layers manager.
75
+ * @param {LayersManager} [manager] - The layer's manager.
76
76
  * @returns {Object} The bounding box details including start and end points, width, and height.
77
77
  */
78
78
  getBoundingBox(ctx, canvas, manager) {
@@ -91,7 +91,7 @@ class LineLayer extends BaseLayer_1.BaseLayer {
91
91
  * Draws the line layer on the canvas.
92
92
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
93
93
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
94
- * @param {LayersManager} [manager] - The layers manager.
94
+ * @param {LayersManager} [manager] - The layer's manager.
95
95
  * @param {boolean} [debug] - Whether to enable debug logging.
96
96
  */
97
97
  async draw(ctx, canvas, manager, debug) {
@@ -122,7 +122,7 @@ export declare class MorphLayer extends BaseLayer<IMorphLayerProps> {
122
122
  * Draws the Morph Layer on the canvas.
123
123
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
124
124
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
125
- * @param {LayersManager} [manager] - The layers manager.
125
+ * @param {LayersManager} [manager] - The layer's manager.
126
126
  * @param {boolean} [debug] - Whether to enable debug logging.
127
127
  */
128
128
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
@@ -79,7 +79,7 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
79
79
  * Draws the Morph Layer on the canvas.
80
80
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
81
81
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
82
- * @param {LayersManager} [manager] - The layers manager.
82
+ * @param {LayersManager} [manager] - The layer's manager.
83
83
  * @param {boolean} [debug] - Whether to enable debug logging.
84
84
  */
85
85
  async draw(ctx, canvas, manager, debug) {
@@ -0,0 +1,124 @@
1
+ import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
+ import { ColorType, LayerType, ScaleType } 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
+ * Whether the layer is filled.
39
+ */
40
+ filled: boolean;
41
+ /**
42
+ * The fill style (color or pattern) of the layer.
43
+ */
44
+ fillStyle: ColorType;
45
+ /**
46
+ * The stroke properties of the polygon.
47
+ */
48
+ stroke: {
49
+ /**
50
+ * The width of the stroke.
51
+ */
52
+ width: number;
53
+ /**
54
+ * The cap style of the stroke.
55
+ */
56
+ cap: CanvasLineCap;
57
+ /**
58
+ * The join style of the stroke.
59
+ */
60
+ join: CanvasLineJoin;
61
+ /**
62
+ * The dash offset of the stroke.
63
+ */
64
+ dashOffset: number;
65
+ /**
66
+ * The dash pattern of the stroke.
67
+ */
68
+ dash: number[];
69
+ /**
70
+ * The miter limit of the stroke.
71
+ */
72
+ miterLimit: number;
73
+ };
74
+ }
75
+ export declare class PolygonLayer extends BaseLayer<IPolygonLayerProps> {
76
+ props: IPolygonLayerProps;
77
+ constructor(props?: IPolygonLayerProps, misc?: IBaseLayerMisc);
78
+ /**
79
+ * Sets the size of the Polygon layer.
80
+ * @param {ScaleType} [width] - The width of the Polygon layer.
81
+ * @param {ScaleType} [height] - The height of the Polygon layer.
82
+ * @param {number} [count] - The number of sides of the polygon.
83
+ * @param {number} [radius] - The radius of the Polygon Layer (optional).
84
+ * @returns {this} The current instance for chaining.
85
+ */
86
+ setSize(width: ScaleType, height: ScaleType, count: number, radius?: number): this;
87
+ /**
88
+ * Sets the color of the Polygon layer.
89
+ * @param {ColorType} [color] - The color of the layer.
90
+ * @returns {this} The current instance for chaining.
91
+ * @throws {LazyError} If the color is not provided or invalid.
92
+ */
93
+ setColor(color: ColorType): this;
94
+ /**
95
+ * Sets the stroke properties of the Polygon Layer.
96
+ * @param {number} [width] - The width of the stroke.
97
+ * @param {string} [cap] - The cap style of the stroke.
98
+ * @param {string} [join] - The join style of the stroke.
99
+ * @param {number[]} [dash] - The dash pattern of the stroke.
100
+ * @param {number} [dashOffset] - The dash offset of the stroke.
101
+ * @param {number} [miterLimit] - The miter limit of the stroke.
102
+ * @returns {this} The current instance for chaining.
103
+ */
104
+ setStroke(width: number, cap?: CanvasLineCap, join?: CanvasLineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
105
+ /**
106
+ * Draws the Polygon layer on the given canvas context.
107
+ * @param {SKRSContext2D} [ctx] - The canvas rendering context.
108
+ * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
109
+ * @param {LayersManager} [manager] - The layer's manager.
110
+ * @param {boolean} [debug] - Whether to enable debug logging.
111
+ */
112
+ draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
113
+ /**
114
+ * Converts the Polygon layer to a JSON representation.
115
+ * @returns {IPolygonLayer} The JSON representation of the Polygon layer.
116
+ */
117
+ toJSON(): IPolygonLayer;
118
+ /**
119
+ * Validates the properties of the Morph Layer.
120
+ * @param {IPolygonLayerProps} [data] - The properties to validate.
121
+ * @returns {IPolygonLayerProps} The validated properties.
122
+ */
123
+ protected validateProps(data: IPolygonLayerProps): IPolygonLayerProps;
124
+ }
@@ -0,0 +1,208 @@
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
+ class PolygonLayer extends BaseLayer_1.BaseLayer {
9
+ props;
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
+ this.props.filled = false; // Ensure filled is false when stroke is set
66
+ return this;
67
+ }
68
+ /**
69
+ * Draws the Polygon layer on the given canvas context.
70
+ * @param {SKRSContext2D} [ctx] - The canvas rendering context.
71
+ * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
72
+ * @param {LayersManager} [manager] - The layer's manager.
73
+ * @param {boolean} [debug] - Whether to enable debug logging.
74
+ */
75
+ async draw(ctx, canvas, manager, debug) {
76
+ const parcer = (0, utils_1.parser)(ctx, canvas, manager);
77
+ const { xs, ys, w } = parcer.parseBatch({
78
+ xs: { v: this.props.x },
79
+ ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
80
+ w: { v: this.props.size.width },
81
+ });
82
+ const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
83
+ let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
84
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width: w, height: h, x: xs, y: ys, align: this.props.centring }, manager });
85
+ if (debug)
86
+ LazyUtil_1.LazyLog.log('none', `PolygonLayer:`, { x, y, w, h, count: this.props.size.count, radius: this.props.size.radius });
87
+ ctx.save();
88
+ ctx.beginPath();
89
+ // Calculate polygon vertices
90
+ const vertices = [];
91
+ for (let i = 0; i < this.props.size.count; i++) {
92
+ const angle = (i / this.props.size.count) * (2 * Math.PI) - Math.PI / 2;
93
+ vertices.push({
94
+ x: x + w / 2 + (w / 2) * Math.cos(angle),
95
+ y: y + h / 2 + (h / 2) * Math.sin(angle)
96
+ });
97
+ }
98
+ if (this.props.size.radius > 0) {
99
+ // Draw polygon with rounded corners
100
+ for (let i = 0; i < vertices.length; i++) {
101
+ const current = vertices[i];
102
+ const next = vertices[(i + 1) % vertices.length];
103
+ const prev = vertices[(i - 1 + vertices.length) % vertices.length];
104
+ // Calculate vectors from current vertex to adjacent vertices
105
+ const dx1 = current.x - prev.x;
106
+ const dy1 = current.y - prev.y;
107
+ const dx2 = next.x - current.x;
108
+ const dy2 = next.y - current.y;
109
+ // Normalize vectors
110
+ const len1 = Math.sqrt(dx1 * dx1 + dy1 * dy1);
111
+ const len2 = Math.sqrt(dx2 * dx2 + dy2 * dy2);
112
+ const ndx1 = dx1 / len1;
113
+ const ndy1 = dy1 / len1;
114
+ const ndx2 = dx2 / len2;
115
+ const ndy2 = dy2 / len2;
116
+ // Calculate the maximum radius based on edge lengths
117
+ const maxRadius = Math.max(len1 / 2, len2 / 2);
118
+ const cornerRadius = Math.min(this.props.size.radius, maxRadius);
119
+ // Calculate arc start and end points
120
+ const arcStart = {
121
+ x: current.x - ndx1 * cornerRadius,
122
+ y: current.y - ndy1 * cornerRadius
123
+ };
124
+ const arcEnd = {
125
+ x: current.x + ndx2 * cornerRadius,
126
+ y: current.y + ndy2 * cornerRadius
127
+ };
128
+ if (i === 0) {
129
+ ctx.moveTo(arcStart.x, arcStart.y);
130
+ }
131
+ else {
132
+ ctx.lineTo(arcStart.x, arcStart.y);
133
+ }
134
+ // Draw arc at corner
135
+ ctx.arcTo(current.x, current.y, arcEnd.x, arcEnd.y, cornerRadius);
136
+ }
137
+ ctx.closePath();
138
+ }
139
+ else {
140
+ // Draw polygon without rounded corners (original behavior)
141
+ for (let i = 0; i < vertices.length; i++) {
142
+ if (i === 0) {
143
+ ctx.moveTo(vertices[i].x, vertices[i].y);
144
+ }
145
+ else {
146
+ ctx.lineTo(vertices[i].x, vertices[i].y);
147
+ }
148
+ }
149
+ ctx.closePath();
150
+ }
151
+ if (this.props.filled) {
152
+ ctx.fillStyle = fillStyle;
153
+ ctx.fill();
154
+ }
155
+ if (this.props.stroke && this.props.stroke.width > 0) {
156
+ ctx.lineWidth = this.props.stroke.width;
157
+ ctx.lineCap = this.props.stroke.cap;
158
+ ctx.lineJoin = this.props.stroke.join;
159
+ ctx.setLineDash(this.props.stroke.dash);
160
+ ctx.lineDashOffset = this.props.stroke.dashOffset;
161
+ ctx.miterLimit = this.props.stroke.miterLimit;
162
+ ctx.strokeStyle = fillStyle;
163
+ ctx.stroke();
164
+ }
165
+ ctx.restore();
166
+ }
167
+ /**
168
+ * Converts the Polygon layer to a JSON representation.
169
+ * @returns {IPolygonLayer} The JSON representation of the Polygon layer.
170
+ */
171
+ toJSON() {
172
+ let data = super.toJSON();
173
+ let copy = { ...this.props };
174
+ for (const key of ['x', 'y', 'size.width', 'size.height', 'fillStyle']) {
175
+ if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
176
+ copy[key] = copy[key].toJSON();
177
+ }
178
+ }
179
+ return { ...data, props: copy };
180
+ }
181
+ /**
182
+ * Validates the properties of the Morph Layer.
183
+ * @param {IPolygonLayerProps} [data] - The properties to validate.
184
+ * @returns {IPolygonLayerProps} The validated properties.
185
+ */
186
+ validateProps(data) {
187
+ return {
188
+ ...super.validateProps(data),
189
+ size: {
190
+ width: data.size?.width || 100,
191
+ height: data.size?.height || 100,
192
+ radius: data.size?.radius || 0,
193
+ count: data.size?.count || 3
194
+ },
195
+ filled: data.filled !== undefined ? data.filled : true,
196
+ fillStyle: data.fillStyle || '#000000',
197
+ stroke: {
198
+ width: data.stroke?.width || 1,
199
+ cap: data.stroke?.cap || 'butt',
200
+ join: data.stroke?.join || 'miter',
201
+ dashOffset: data.stroke?.dashOffset || 0,
202
+ dash: data.stroke?.dash || [],
203
+ miterLimit: data.stroke?.miterLimit || 10
204
+ }
205
+ };
206
+ }
207
+ }
208
+ exports.PolygonLayer = PolygonLayer;
@@ -3,7 +3,7 @@ import { ColorType, ScaleType, Point, LayerType } 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 Layer.
6
+ * Interface representing a Quadratic layer.
7
7
  */
8
8
  export interface IQuadraticLayer extends IBaseLayer {
9
9
  /**
@@ -11,12 +11,12 @@ export interface IQuadraticLayer extends IBaseLayer {
11
11
  */
12
12
  type: LayerType.QuadraticCurve;
13
13
  /**
14
- * The properties specific to the Quadratic Layer.
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 Layer.
19
+ * Interface representing the properties of a Quadratic layer.
20
20
  */
21
21
  export interface IQuadraticLayerProps extends IBaseLayerProps {
22
22
  /**
@@ -66,16 +66,16 @@ export interface IQuadraticLayerProps extends IBaseLayerProps {
66
66
  };
67
67
  }
68
68
  /**
69
- * Class representing a Quadratic Layer, extending the BaseLayer class.
69
+ * Class representing a Quadratic layer, extending the BaseLayer class.
70
70
  */
71
71
  export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
72
72
  /**
73
- * The properties of the Quadratic Layer.
73
+ * The properties of the Quadratic layer.
74
74
  */
75
75
  props: IQuadraticLayerProps;
76
76
  /**
77
77
  * Constructs a new QuadraticLayer instance.
78
- * @param {IQuadraticLayerProps} [props] - The properties of the Quadratic Layer.
78
+ * @param {IQuadraticLayerProps} [props] - The properties of the Quadratic layer.
79
79
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
80
80
  */
81
81
  constructor(props?: IQuadraticLayerProps, misc?: IBaseLayerMisc);
@@ -115,7 +115,7 @@ export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
115
115
  * Calculates the bounding box of the quadratic curve.
116
116
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
117
117
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
118
- * @param {LayersManager} [manager] - The layers manager.
118
+ * @param {LayersManager} [manager] - The layer's manager.
119
119
  * @returns {Object} The bounding box details including max, min, center, width, and height.
120
120
  */
121
121
  getBoundingBox(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager): {
@@ -138,17 +138,17 @@ export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
138
138
  * Draws the quadratic curve on the canvas.
139
139
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
140
140
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
141
- * @param {LayersManager} [manager] - The layers manager.
141
+ * @param {LayersManager} [manager] - The layer's manager.
142
142
  * @param {boolean} [debug] - Whether to enable debug logging.
143
143
  */
144
144
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
145
145
  /**
146
- * Converts the Quadratic Layer to a JSON representation.
147
- * @returns {IQuadraticLayer} The JSON representation of the Quadratic Layer.
146
+ * Converts the Quadratic layer to a JSON representation.
147
+ * @returns {IQuadraticLayer} The JSON representation of the Quadratic layer.
148
148
  */
149
149
  toJSON(): IQuadraticLayer;
150
150
  /**
151
- * Validates the properties of the Quadratic Layer.
151
+ * Validates the properties of the Quadratic layer.
152
152
  * @param {IQuadraticLayerProps} [data] - The properties to validate.
153
153
  * @returns {IQuadraticLayerProps} The validated properties.
154
154
  */
@@ -6,16 +6,16 @@ const types_1 = require("../../types");
6
6
  const utils_1 = require("../../utils/utils");
7
7
  const LazyUtil_1 = require("../../utils/LazyUtil");
8
8
  /**
9
- * Class representing a Quadratic Layer, extending the BaseLayer class.
9
+ * Class representing a Quadratic layer, extending the BaseLayer class.
10
10
  */
11
11
  class QuadraticLayer extends BaseLayer_1.BaseLayer {
12
12
  /**
13
- * The properties of the Quadratic Layer.
13
+ * The properties of the Quadratic layer.
14
14
  */
15
15
  props;
16
16
  /**
17
17
  * Constructs a new QuadraticLayer instance.
18
- * @param {IQuadraticLayerProps} [props] - The properties of the Quadratic Layer.
18
+ * @param {IQuadraticLayerProps} [props] - The properties of the Quadratic layer.
19
19
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
20
20
  */
21
21
  constructor(props, misc) {
@@ -82,7 +82,7 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
82
82
  * Calculates the bounding box of the quadratic curve.
83
83
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
84
84
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
85
- * @param {LayersManager} [manager] - The layers manager.
85
+ * @param {LayersManager} [manager] - The layer's manager.
86
86
  * @returns {Object} The bounding box details including max, min, center, width, and height.
87
87
  */
88
88
  getBoundingBox(ctx, canvas, manager) {
@@ -102,7 +102,7 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
102
102
  * Draws the quadratic curve on the canvas.
103
103
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
104
104
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
105
- * @param {LayersManager} [manager] - The layers manager.
105
+ * @param {LayersManager} [manager] - The layer's manager.
106
106
  * @param {boolean} [debug] - Whether to enable debug logging.
107
107
  */
108
108
  async draw(ctx, canvas, manager, debug) {
@@ -139,8 +139,8 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
139
139
  ctx.restore();
140
140
  }
141
141
  /**
142
- * Converts the Quadratic Layer to a JSON representation.
143
- * @returns {IQuadraticLayer} The JSON representation of the Quadratic Layer.
142
+ * Converts the Quadratic layer to a JSON representation.
143
+ * @returns {IQuadraticLayer} The JSON representation of the Quadratic layer.
144
144
  */
145
145
  toJSON() {
146
146
  let data = super.toJSON();
@@ -153,7 +153,7 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
153
153
  return { ...data, props: copy };
154
154
  }
155
155
  /**
156
- * Validates the properties of the Quadratic Layer.
156
+ * Validates the properties of the Quadratic layer.
157
157
  * @param {IQuadraticLayerProps} [data] - The properties to validate.
158
158
  * @returns {IQuadraticLayerProps} The validated properties.
159
159
  */
@@ -1,9 +1,9 @@
1
1
  import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
- import { ScaleType, ColorType, AnyWeight, AnyTextAlign, AnyTextBaseline, AnyTextDirection, LineCap, LineJoin, LayerType, SubStringColor } from "../../types";
2
+ import { AnyTextAlign, AnyTextBaseline, AnyTextDirection, AnyWeight, ColorType, LayerType, LineCap, LineJoin, ScaleType, SubStringColor } from "../../types";
3
3
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
4
  import { LayersManager } from "../managers";
5
5
  /**
6
- * Interface representing a Text Layer.
6
+ * Interface representing a Text layer.
7
7
  */
8
8
  export interface ITextLayer extends IBaseLayer {
9
9
  /**
@@ -11,12 +11,12 @@ export interface ITextLayer extends IBaseLayer {
11
11
  */
12
12
  type: LayerType.Text;
13
13
  /**
14
- * The properties specific to the Text Layer.
14
+ * The properties specific to the Text layer.
15
15
  */
16
16
  props: ITextLayerProps;
17
17
  }
18
18
  /**
19
- * Interface representing the properties of a Text Layer.
19
+ * Interface representing the properties of a Text layer.
20
20
  */
21
21
  export interface ITextLayerProps extends IBaseLayerProps {
22
22
  /**
@@ -66,15 +66,15 @@ export interface ITextLayerProps extends IBaseLayerProps {
66
66
  spacing?: number;
67
67
  };
68
68
  /**
69
- * The size of the text layer, including width and height.
69
+ * The size of the Text layer, including width and height.
70
70
  */
71
71
  size: {
72
72
  /**
73
- * The width of the text layer.
73
+ * The width of the Text layer.
74
74
  */
75
75
  width: ScaleType;
76
76
  /**
77
- * The height of the text layer.
77
+ * The height of the Text layer.
78
78
  */
79
79
  height: ScaleType;
80
80
  };
@@ -129,7 +129,7 @@ export interface ITextLayerProps extends IBaseLayerProps {
129
129
  };
130
130
  }
131
131
  /**
132
- * Class representing a Text Layer, extending the BaseLayer class.
132
+ * Class representing a Text layer, extending the BaseLayer class.
133
133
  */
134
134
  export declare class TextLayer extends BaseLayer<ITextLayerProps> {
135
135
  /**
@@ -138,7 +138,7 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
138
138
  props: ITextLayerProps;
139
139
  /**
140
140
  * Constructs a new TextLayer instance.
141
- * @param {ITextLayerProps} [props] - The properties of the Text Layer.
141
+ * @param {ITextLayerProps} [props] - The properties of the Text layer.
142
142
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
143
143
  */
144
144
  constructor(props?: ITextLayerProps, misc?: IBaseLayerMisc);
@@ -232,7 +232,7 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
232
232
  * Draws the text layer on the canvas.
233
233
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
234
234
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
235
- * @param {LayersManager} [manager] - The layers manager.
235
+ * @param {LayersManager} [manager] - The layer's manager.
236
236
  * @param {boolean} [debug] - Whether to enable debug logging.
237
237
  */
238
238
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
@@ -249,12 +249,12 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
249
249
  */
250
250
  private drawText;
251
251
  /**
252
- * Converts the Text Layer to a JSON representation.
253
- * @returns {ITextLayer} The JSON representation of the Text Layer.
252
+ * Converts the Text layer to a JSON representation.
253
+ * @returns {ITextLayer} The JSON representation of the Text layer.
254
254
  */
255
255
  toJSON(): ITextLayer;
256
256
  /**
257
- * Validates the properties of the Text Layer.
257
+ * Validates the properties of the Text layer.
258
258
  * @param {ITextLayerProps} [data] - The properties to validate.
259
259
  * @returns {ITextLayerProps} The validated properties.
260
260
  */
@@ -6,7 +6,7 @@ const types_1 = require("../../types");
6
6
  const LazyUtil_1 = require("../../utils/LazyUtil");
7
7
  const utils_1 = require("../../utils/utils");
8
8
  /**
9
- * Class representing a Text Layer, extending the BaseLayer class.
9
+ * Class representing a Text layer, extending the BaseLayer class.
10
10
  */
11
11
  class TextLayer extends BaseLayer_1.BaseLayer {
12
12
  /**
@@ -15,7 +15,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
15
15
  props;
16
16
  /**
17
17
  * Constructs a new TextLayer instance.
18
- * @param {ITextLayerProps} [props] - The properties of the Text Layer.
18
+ * @param {ITextLayerProps} [props] - The properties of the Text layer.
19
19
  * @param {IBaseLayerMisc} [misc] - Miscellaneous options for the layer.
20
20
  */
21
21
  constructor(props, misc) {
@@ -186,7 +186,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
186
186
  * Draws the text layer on the canvas.
187
187
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
188
188
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
189
- * @param {LayersManager} [manager] - The layers manager.
189
+ * @param {LayersManager} [manager] - The layer's manager.
190
190
  * @param {boolean} [debug] - Whether to enable debug logging.
191
191
  */
192
192
  async draw(ctx, canvas, manager, debug) {
@@ -214,7 +214,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
214
214
  ctx.textBaseline = this.props.baseline;
215
215
  if (this.props.direction)
216
216
  ctx.direction = this.props.direction;
217
- let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width: w, height: h, x, y, align: 'none' }, manager });
217
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width: w, height: h, x, y, align: 'center' }, manager });
218
218
  if (this.props.multiline.enabled) {
219
219
  const words = this.props.text.split(' ');
220
220
  let lines = [];
@@ -371,8 +371,8 @@ class TextLayer extends BaseLayer_1.BaseLayer {
371
371
  ctx.textAlign = originalAlign;
372
372
  }
373
373
  /**
374
- * Converts the Text Layer to a JSON representation.
375
- * @returns {ITextLayer} The JSON representation of the Text Layer.
374
+ * Converts the Text layer to a JSON representation.
375
+ * @returns {ITextLayer} The JSON representation of the Text layer.
376
376
  */
377
377
  toJSON() {
378
378
  let data = super.toJSON();
@@ -385,7 +385,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
385
385
  return { ...data, props: copy };
386
386
  }
387
387
  /**
388
- * Validates the properties of the Text Layer.
388
+ * Validates the properties of the Text layer.
389
389
  * @param {ITextLayerProps} [data] - The properties to validate.
390
390
  * @returns {ITextLayerProps} The validated properties.
391
391
  */
@@ -8,3 +8,4 @@ export * from './Group';
8
8
  export * from './LineLayer';
9
9
  export * from './QuadraticLayer';
10
10
  export * from './Path2DLayer';
11
+ export * from './PolygonLayer';
@@ -24,3 +24,4 @@ __exportStar(require("./Group"), exports);
24
24
  __exportStar(require("./LineLayer"), exports);
25
25
  __exportStar(require("./QuadraticLayer"), exports);
26
26
  __exportStar(require("./Path2DLayer"), exports);
27
+ __exportStar(require("./PolygonLayer"), exports);
@@ -128,14 +128,20 @@ class Gradient {
128
128
  switch (gradientData.type) {
129
129
  case types_1.GradientType.Linear:
130
130
  case "linear":
131
- if (gradientData.type === "linear" && (gradientData.angle || gradientData.angle === 0) && opts.layer) {
131
+ if (gradientData.type === "linear" && (gradientData.angle || gradientData.angle === 0) && opts.layer && gradientData.points.length < 2) {
132
132
  const { width, height, x, y, align } = opts.layer;
133
133
  const cx = this.getPosition(x, width, align, 'x');
134
134
  const cy = this.getPosition(y, height, align, 'y');
135
+ if (opts.debug)
136
+ LazyUtil_1.LazyLog.log('none', `Center for angle calculation:`, { cx, cy });
135
137
  const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
138
+ if (opts.debug)
139
+ LazyUtil_1.LazyLog.log('none', `Linear Gradient Points from angle:`, { p1, p2 });
136
140
  gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
137
141
  }
138
142
  else {
143
+ if (opts.debug)
144
+ LazyUtil_1.LazyLog.log('none', `Linear Gradient created from points.`);
139
145
  gradient = ctx.createLinearGradient(x0, y0, x1 || x0, y1 || y0);
140
146
  }
141
147
  break;
@@ -144,6 +144,8 @@ class JSONReader {
144
144
  return new components_1.ClearLayer(layer.props, misc);
145
145
  case types_1.LayerType.Path:
146
146
  return new components_1.Path2DLayer(layer.props, misc).setColor(this.fillParse(layer));
147
+ case types_1.LayerType.Polygon:
148
+ return new components_1.PolygonLayer(layer.props, misc).setColor(this.fillParse(layer));
147
149
  case types_1.LayerType.Group:
148
150
  return new components_1.Group(misc)
149
151
  .add(...layer.layers.map((l) => this.layerParse(l)));
@@ -11,7 +11,9 @@ export declare enum LayerType {
11
11
  Morph = "morph",
12
12
  Text = "text",
13
13
  Group = "group",
14
- Clear = "clear"
14
+ Clear = "clear",
15
+ Polygon = "polygon",
16
+ Custom = "custom"
15
17
  }
16
18
  export declare enum LayerScaleType {
17
19
  Pixel = "px",
@@ -16,6 +16,8 @@ var LayerType;
16
16
  LayerType["Text"] = "text";
17
17
  LayerType["Group"] = "group";
18
18
  LayerType["Clear"] = "clear";
19
+ LayerType["Polygon"] = "polygon";
20
+ LayerType["Custom"] = "custom";
19
21
  })(LayerType || (exports.LayerType = LayerType = {}));
20
22
  var LayerScaleType;
21
23
  (function (LayerScaleType) {
@@ -15,7 +15,9 @@ import {
15
15
  ITextLayer,
16
16
  IQuadraticLayer,
17
17
  ILineLayer,
18
- IPath2DLayer
18
+ IPath2DLayer,
19
+ IPolygonLayer,
20
+ PolygonLayer
19
21
  } from "../structures/components";
20
22
  import {
21
23
  FontWeight,
@@ -39,9 +41,9 @@ export type StringColorType = `rgba(${number}, ${number}, ${number}, ${number})`
39
41
 
40
42
  export type ColorType = Gradient | Pattern | StringColorType;
41
43
 
42
- export type JSONLayer = IMorphLayer | IImageLayer | ITextLayer | IBezierLayer | IQuadraticLayer | ILineLayer | IClearLayer | IPath2DLayer;
44
+ export type JSONLayer = IMorphLayer | IImageLayer | ITextLayer | IBezierLayer | IQuadraticLayer | ILineLayer | IClearLayer | IPath2DLayer | IPolygonLayer;
43
45
 
44
- export type AnyLayer = MorphLayer | ImageLayer | TextLayer | BezierLayer | QuadraticLayer | LineLayer | ClearLayer | Path2DLayer;
46
+ export type AnyLayer = MorphLayer | ImageLayer | TextLayer | BezierLayer | QuadraticLayer | LineLayer | ClearLayer | Path2DLayer | PolygonLayer;
45
47
 
46
48
  export type AnyWeight = FontWeight | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | 950;
47
49
 
@@ -1,5 +1,4 @@
1
- import type { AnyCentring, AnyLayer, AnyTextAlign, ColorType, PointNumber, ScaleType, SubStringColor, Transform } from "../types";
2
- import { LayerType } from "../types";
1
+ import { AnyCentring, AnyLayer, AnyTextAlign, ColorType, LayerType, PointNumber, ScaleType, SubStringColor, Transform } from "../types";
3
2
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
3
  import { LayersManager } from "../structures/managers";
5
4
  import { Group } from "../structures/components";
@@ -169,6 +169,7 @@ function transform(ctx, transform, layer = { width: 0, height: 0, x: 0, y: 0, ty
169
169
  case types_1.LayerType.BezierCurve:
170
170
  case types_1.LayerType.QuadraticCurve:
171
171
  case types_1.LayerType.Line:
172
+ case types_1.LayerType.Polygon:
172
173
  ctx.translate(layer.x + (layer.width / 2), layer.y + (layer.height / 2));
173
174
  ctx.rotate((Math.PI / 180) * transform.rotate);
174
175
  ctx.translate(-(layer.x + (layer.width / 2)), -(layer.y + (layer.height / 2)));
@@ -229,6 +230,7 @@ function centring(centring, type, width, height, x, y) {
229
230
  case types_1.LayerType.Image:
230
231
  case types_1.LayerType.Morph:
231
232
  case types_1.LayerType.Clear:
233
+ case types_1.LayerType.Polygon:
232
234
  x -= width / 2;
233
235
  y -= height / 2;
234
236
  break;
@@ -240,6 +242,7 @@ function centring(centring, type, width, height, x, y) {
240
242
  case types_1.LayerType.Image:
241
243
  case types_1.LayerType.Morph:
242
244
  case types_1.LayerType.Clear:
245
+ case types_1.LayerType.Polygon:
243
246
  x -= width / 2;
244
247
  y -= height;
245
248
  break;
@@ -251,6 +254,7 @@ function centring(centring, type, width, height, x, y) {
251
254
  case types_1.LayerType.Image:
252
255
  case types_1.LayerType.Morph:
253
256
  case types_1.LayerType.Clear:
257
+ case types_1.LayerType.Polygon:
254
258
  x -= width / 2;
255
259
  y -= height;
256
260
  break;
@@ -262,6 +266,7 @@ function centring(centring, type, width, height, x, y) {
262
266
  case types_1.LayerType.Image:
263
267
  case types_1.LayerType.Morph:
264
268
  case types_1.LayerType.Clear:
269
+ case types_1.LayerType.Polygon:
265
270
  y -= height / 2;
266
271
  break;
267
272
  }
@@ -272,6 +277,7 @@ function centring(centring, type, width, height, x, y) {
272
277
  case types_1.LayerType.Image:
273
278
  case types_1.LayerType.Morph:
274
279
  case types_1.LayerType.Clear:
280
+ case types_1.LayerType.Polygon:
275
281
  y -= height;
276
282
  break;
277
283
  }
@@ -285,6 +291,7 @@ function centring(centring, type, width, height, x, y) {
285
291
  case types_1.LayerType.Image:
286
292
  case types_1.LayerType.Morph:
287
293
  case types_1.LayerType.Clear:
294
+ case types_1.LayerType.Polygon:
288
295
  x -= width;
289
296
  y -= height / 2;
290
297
  break;
@@ -296,6 +303,7 @@ function centring(centring, type, width, height, x, y) {
296
303
  case types_1.LayerType.Image:
297
304
  case types_1.LayerType.Morph:
298
305
  case types_1.LayerType.Clear:
306
+ case types_1.LayerType.Polygon:
299
307
  x -= width;
300
308
  y -= height;
301
309
  break;
@@ -307,6 +315,7 @@ function centring(centring, type, width, height, x, y) {
307
315
  case types_1.LayerType.Image:
308
316
  case types_1.LayerType.Morph:
309
317
  case types_1.LayerType.Clear:
318
+ case types_1.LayerType.Polygon:
310
319
  x -= width;
311
320
  break;
312
321
  }
@@ -376,9 +385,14 @@ function resizeLayers(layers, ratio) {
376
385
  layer.props.size.width = resize(layer.props.size.width, ratio);
377
386
  layer.props.size.height = resize(layer.props.size.height, ratio);
378
387
  if ('radius' in layer.props.size) {
379
- for (const corner in layer.props.size.radius) {
380
- // @ts-ignore
381
- layer.props.size.radius[corner] = resize(layer.props.size.radius[corner], ratio);
388
+ if (typeof layer.props.size.radius === 'number') {
389
+ layer.props.size.radius = resize(layer.props.size.radius, ratio);
390
+ }
391
+ else if (typeof layer.props.size.radius === 'object') {
392
+ for (const corner in layer.props.size.radius) {
393
+ // @ts-ignore
394
+ layer.props.size.radius[corner] = resize(layer.props.size.radius[corner], ratio);
395
+ }
382
396
  }
383
397
  }
384
398
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nmmty/lazycanvas",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "description": "A simple way to interact with @napi-rs/canvas in an advanced way!",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",