@nmmty/lazycanvas 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/ReadMe.md +1 -0
  2. package/dist/helpers/Filters.d.ts +10 -10
  3. package/dist/helpers/Fonts.d.ts +1 -1
  4. package/dist/helpers/FontsList.d.ts +1 -1
  5. package/dist/helpers/FontsList.js +19 -19
  6. package/dist/index.d.ts +11 -20
  7. package/dist/index.js +40 -47
  8. package/dist/structures/LazyCanvas.d.ts +126 -19
  9. package/dist/structures/LazyCanvas.js +100 -35
  10. package/dist/structures/components/BaseLayer.d.ts +188 -38
  11. package/dist/structures/components/BaseLayer.js +89 -43
  12. package/dist/structures/components/BezierLayer.d.ts +111 -33
  13. package/dist/structures/components/BezierLayer.js +72 -32
  14. package/dist/structures/components/ClearLayer.d.ts +120 -17
  15. package/dist/structures/components/ClearLayer.js +83 -22
  16. package/dist/structures/components/Group.d.ts +88 -20
  17. package/dist/structures/components/Group.js +69 -29
  18. package/dist/structures/components/ImageLayer.d.ts +76 -12
  19. package/dist/structures/components/ImageLayer.js +43 -39
  20. package/dist/structures/components/LineLayer.d.ts +111 -18
  21. package/dist/structures/components/LineLayer.js +57 -29
  22. package/dist/structures/components/MorphLayer.d.ts +109 -21
  23. package/dist/structures/components/MorphLayer.js +52 -33
  24. package/dist/structures/components/Path2DLayer.d.ts +164 -0
  25. package/dist/structures/components/Path2DLayer.js +293 -0
  26. package/dist/structures/components/QuadraticLayer.d.ts +108 -22
  27. package/dist/structures/components/QuadraticLayer.js +64 -38
  28. package/dist/structures/components/TextLayer.d.ts +201 -40
  29. package/dist/structures/components/TextLayer.js +98 -55
  30. package/dist/structures/components/index.d.ts +10 -0
  31. package/dist/structures/components/index.js +26 -0
  32. package/dist/structures/helpers/Exporter.d.ts +52 -0
  33. package/dist/structures/helpers/Exporter.js +168 -0
  34. package/dist/structures/helpers/Font.d.ts +64 -10
  35. package/dist/structures/helpers/Font.js +38 -11
  36. package/dist/structures/helpers/Gradient.d.ts +96 -9
  37. package/dist/structures/helpers/Gradient.js +49 -19
  38. package/dist/structures/helpers/Link.d.ts +52 -8
  39. package/dist/structures/helpers/Link.js +42 -11
  40. package/dist/structures/helpers/Pattern.d.ts +52 -7
  41. package/dist/structures/helpers/Pattern.js +48 -42
  42. package/dist/structures/helpers/index.d.ts +6 -0
  43. package/dist/structures/helpers/index.js +22 -0
  44. package/dist/structures/helpers/readers/JSONReader.d.ts +49 -0
  45. package/dist/structures/helpers/readers/JSONReader.js +172 -0
  46. package/dist/structures/helpers/readers/SVGReader.d.ts +20 -0
  47. package/dist/structures/helpers/readers/SVGReader.js +577 -0
  48. package/dist/structures/helpers/readers/YAMLReader.d.ts +0 -0
  49. package/dist/structures/helpers/readers/YAMLReader.js +1 -0
  50. package/dist/structures/managers/AnimationManager.d.ts +96 -20
  51. package/dist/structures/managers/AnimationManager.js +54 -26
  52. package/dist/structures/managers/FontsManager.d.ts +76 -32
  53. package/dist/structures/managers/FontsManager.js +70 -45
  54. package/dist/structures/managers/LayersManager.d.ts +84 -32
  55. package/dist/structures/managers/LayersManager.js +66 -28
  56. package/dist/structures/managers/RenderManager.d.ts +60 -6
  57. package/dist/structures/managers/RenderManager.js +120 -40
  58. package/dist/types/enum.d.ts +11 -6
  59. package/dist/types/enum.js +17 -12
  60. package/dist/types/index.d.ts +2 -19
  61. package/dist/types/index.js +17 -0
  62. package/dist/utils/LazyUtil.js +2 -2
  63. package/dist/utils/utils.d.ts +9 -11
  64. package/dist/utils/utils.js +163 -234
  65. package/package.json +4 -5
@@ -2,27 +2,37 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MorphLayer = void 0;
4
4
  const BaseLayer_1 = require("./BaseLayer");
5
- const enum_1 = require("../../types/enum");
5
+ const types_1 = require("../../types");
6
6
  const utils_1 = require("../../utils/utils");
7
7
  const LazyUtil_1 = require("../../utils/LazyUtil");
8
- const Gradient_1 = require("../helpers/Gradient");
9
- const Pattern_1 = require("../helpers/Pattern");
8
+ /**
9
+ * Class representing a Morph Layer, extending the BaseLayer class.
10
+ */
10
11
  class MorphLayer extends BaseLayer_1.BaseLayer {
12
+ /**
13
+ * The properties of the Morph Layer.
14
+ */
11
15
  props;
12
- constructor(props) {
13
- super(enum_1.LayerType.Morph, props || {});
16
+ /**
17
+ * Constructs a new MorphLayer instance.
18
+ * @param props {IMorphLayerProps} - The properties of the Morph Layer.
19
+ * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
20
+ */
21
+ constructor(props, misc) {
22
+ super(types_1.LayerType.Morph, props || {}, misc);
14
23
  this.props = props ? props : {};
15
24
  if (!this.props.fillStyle)
16
25
  this.props.fillStyle = '#000000';
17
26
  if (!this.props.filled && this.props.filled !== false)
18
27
  this.props.filled = true;
19
- this.props.centring = enum_1.Centring.Center;
28
+ this.props.centring = types_1.Centring.Center;
20
29
  }
21
30
  /**
22
- * @description Sets size of the morph layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
23
- * @param width {ScaleType} - The `width` of the morph layer.
24
- * @param height {ScaleType} - The `height` of the morph layer.
25
- * @param radius {ScaleType} - The `radius` of the morph layer. (optional)
31
+ * Sets the size of the Morph Layer.
32
+ * @param width {ScaleType} - The width of the Morph Layer.
33
+ * @param height {ScaleType} - The height of the Morph Layer.
34
+ * @param radius {ScaleType} - The radius of the Morph Layer (optional).
35
+ * @returns {this} The current instance for chaining.
26
36
  */
27
37
  setSize(width, height, radius) {
28
38
  this.props.size = {
@@ -33,33 +43,28 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
33
43
  return this;
34
44
  }
35
45
  /**
36
- * @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
37
- * @param color {string} - The `color` of the layer.
46
+ * Sets the color of the Morph Layer.
47
+ * @param color {string} - The color of the Morph Layer.
48
+ * @returns {this} The current instance for chaining.
49
+ * @throws {LazyError} If the color is not provided or invalid.
38
50
  */
39
51
  setColor(color) {
40
52
  if (!color)
41
53
  throw new LazyUtil_1.LazyError('The color of the layer must be provided');
42
54
  if (!(0, utils_1.isColor)(color))
43
55
  throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
44
- let fill = (0, utils_1.parseColor)(color);
45
- if (fill instanceof Gradient_1.Gradient || fill instanceof Pattern_1.Pattern) {
46
- this.props.fillStyle = fill;
47
- }
48
- else {
49
- let arr = fill.split(':');
50
- this.props.fillStyle = arr[0];
51
- this.props.opacity = parseFloat(arr[1]) || 1;
52
- }
56
+ this.props.fillStyle = color;
53
57
  return this;
54
58
  }
55
59
  /**
56
- * @description Sets the stroke of the layer.
57
- * @param width {number} - The `width` of the stroke.
58
- * @param cap {string} - The `cap` of the stroke.
59
- * @param join {string} - The `join` of the stroke.
60
- * @param dash {number[]} - The `dash` of the stroke.
61
- * @param dashOffset {number} - The `dashOffset` of the stroke.
62
- * @param miterLimit {number} - The `miterLimit` of the stroke.
60
+ * Sets the stroke properties of the Morph Layer.
61
+ * @param width {number} - The width of the stroke.
62
+ * @param cap {string} - The cap style of the stroke.
63
+ * @param join {string} - The join style of the stroke.
64
+ * @param dash {number[]} - The dash pattern of the stroke.
65
+ * @param dashOffset {number} - The dash offset of the stroke.
66
+ * @param miterLimit {number} - The miter limit of the stroke.
67
+ * @returns {this} The current instance for chaining.
63
68
  */
64
69
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
65
70
  this.props.stroke = {
@@ -73,13 +78,21 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
73
78
  return this;
74
79
  }
75
80
  /**
76
- * @description Sets the fills of the layer. If `true` the layer will be filled, if `false` the layer will be stroked.
77
- * @param filled {boolean} - The `filled` of the layer.
81
+ * Sets whether the Morph Layer should be filled or stroked.
82
+ * @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
83
+ * @returns {this} The current instance for chaining.
78
84
  */
79
85
  setFilled(filled) {
80
86
  this.props.filled = filled;
81
87
  return this;
82
88
  }
89
+ /**
90
+ * Draws the Morph Layer on the canvas.
91
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
92
+ * @param canvas {Canvas | SvgCanvas} - The canvas instance.
93
+ * @param manager {LayersManager} - The layers manager.
94
+ * @param debug {boolean} - Whether to enable debug logging.
95
+ */
83
96
  async draw(ctx, canvas, manager, debug) {
84
97
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
85
98
  const { xs, ys, w } = parcer.parseBatch({
@@ -127,12 +140,18 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
127
140
  ctx.restore();
128
141
  }
129
142
  /**
130
- * @returns {IMorphLayer}
143
+ * Converts the Morph Layer to a JSON representation.
144
+ * @returns {IMorphLayer} The JSON representation of the Morph Layer.
131
145
  */
132
146
  toJSON() {
133
147
  let data = super.toJSON();
134
- data.props = this.props;
135
- return { ...data };
148
+ let copy = { ...this.props };
149
+ for (const key of ['x', 'y', 'size.width', 'size.height', 'size.radius', 'fillStyle']) {
150
+ if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
151
+ copy[key] = copy[key].toJSON();
152
+ }
153
+ }
154
+ return { ...data, props: copy };
136
155
  }
137
156
  }
138
157
  exports.MorphLayer = MorphLayer;
@@ -0,0 +1,164 @@
1
+ import { Canvas, DOMMatrix2DInit, FillType, Path2D, PathOp, SKRSContext2D, StrokeOptions, SvgCanvas } from "@napi-rs/canvas";
2
+ import { AnyFilter, AnyGlobalCompositeOperation, ColorType, LayerType } from "../../types";
3
+ import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
4
+ import { LayersManager } from "../managers/LayersManager";
5
+ export interface IPath2DLayer extends IBaseLayer {
6
+ type: LayerType.Path;
7
+ props: IPath2DLayerProps;
8
+ }
9
+ export interface IPath2DLayerProps extends IBaseLayerProps {
10
+ path2D: Path2D;
11
+ /**
12
+ * The stroke properties of the Path2D.
13
+ */
14
+ stroke: {
15
+ /**
16
+ * The width of the stroke.
17
+ */
18
+ width: number;
19
+ /**
20
+ * The cap style of the stroke.
21
+ */
22
+ cap: CanvasLineCap;
23
+ /**
24
+ * The join style of the stroke.
25
+ */
26
+ join: CanvasLineJoin;
27
+ /**
28
+ * The dash offset of the stroke.
29
+ */
30
+ dashOffset: number;
31
+ /**
32
+ * The dash pattern of the stroke.
33
+ */
34
+ dash: number[];
35
+ /**
36
+ * The miter limit of the stroke.
37
+ */
38
+ miterLimit: number;
39
+ };
40
+ loadFromSVG: boolean;
41
+ clipPath: boolean;
42
+ }
43
+ export declare class Path2DLayer extends BaseLayer<IPath2DLayerProps> {
44
+ id: string;
45
+ type: LayerType.Path;
46
+ zIndex: number;
47
+ visible: boolean;
48
+ props: IPath2DLayerProps;
49
+ constructor(props?: IPath2DLayerProps, misc?: IBaseLayerMisc);
50
+ /**
51
+ * Sets the unique identifier of the layer.
52
+ *
53
+ * @param {string} id - The unique identifier.
54
+ * @returns {this} The current instance for chaining.
55
+ */
56
+ setID(id: string): this;
57
+ /**
58
+ * Sets the visibility of the layer.
59
+ * @param visible {boolean} - The visibility state of the layer.
60
+ * @returns {this} The current instance for chaining.
61
+ */
62
+ setVisible(visible: boolean): this;
63
+ /**
64
+ * Sets the z-index of the layer.
65
+ * @param zIndex {number} - The z-index value of the layer.
66
+ * @returns {this} The current instance for chaining.
67
+ */
68
+ setZIndex(zIndex: number): this;
69
+ /**
70
+ * Sets the global composite operation for the layer.
71
+ * @param {AnyGlobalCompositeOperation} operation - The composite operation.
72
+ * @returns {this} The current instance for chaining.
73
+ */
74
+ setGlobalCompositeOperation(operation: AnyGlobalCompositeOperation): this;
75
+ /**
76
+ * Sets the filter effects for the layer.
77
+ * @param {...AnyFilter} filter - The filter effects to apply.
78
+ * @returns {this} The current instance for chaining.
79
+ */
80
+ setFilters(...filter: AnyFilter[]): this;
81
+ /**
82
+ * Sets the transformation matrix of the layer.
83
+ * @param {DOMMatrix2DInit} matrix - The transformation matrix.
84
+ * @returns {this} The current instance for chaining.
85
+ */
86
+ setMatrix(matrix: DOMMatrix2DInit): this;
87
+ /**
88
+ * Sets the scale of the layer in the x and y directions.
89
+ * @param {number} x - The scale factor in the x direction.
90
+ * @param {number} y - The scale factor in the y direction.
91
+ * @returns {this} The current instance for chaining.
92
+ */
93
+ setScale(x: number, y: number): this;
94
+ /**
95
+ * Sets the translation of the layer in the x and y directions.
96
+ * @param {number} x - The translation in the x direction.
97
+ * @param {number} y - The translation in the y direction.
98
+ * @returns {this} The current instance for chaining.
99
+ */
100
+ setTranslate(x: number, y: number): this;
101
+ /**
102
+ * Sets the opacity of the layer.
103
+ * @param {number} opacity - The opacity value, between 0 and 1.
104
+ * @returns {this} The current instance for chaining.
105
+ */
106
+ setOpacity(opacity: number): this;
107
+ /**
108
+ * Sets the stroke properties of the Path2D Layer.
109
+ * @param width {number} - The width of the stroke.
110
+ * @param cap {string} - The cap style of the stroke.
111
+ * @param join {string} - The join style of the stroke.
112
+ * @param dash {number[]} - The dash pattern of the stroke.
113
+ * @param dashOffset {number} - The dash offset of the stroke.
114
+ * @param miterLimit {number} - The miter limit of the stroke.
115
+ * @returns {this} The current instance for chaining.
116
+ */
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
+ /**
125
+ * Sets the color of the Path2D Layer.
126
+ * @param color {string} - The color of the Path2D Layer.
127
+ * @returns {this} The current instance for chaining.
128
+ * @throws {LazyError} If the color is not provided or invalid.
129
+ */
130
+ setColor(color: ColorType): this;
131
+ setPath(path: Path2D | string): this;
132
+ loadFromSVG(path: true): this;
133
+ setClipPath(clipPath: boolean): this;
134
+ toSVGString(): string;
135
+ addPath(path: Path2D, transform?: DOMMatrix2DInit | undefined): this;
136
+ arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, anticlockwise?: boolean): this;
137
+ arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): this;
138
+ bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): this;
139
+ closePath(): this;
140
+ ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, anticlockwise?: boolean): this;
141
+ lineTo(x: number, y: number): this;
142
+ moveTo(x: number, y: number): this;
143
+ quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
144
+ rect(x: number, y: number, width: number, height: number): this;
145
+ stroke(stroke?: StrokeOptions): this;
146
+ op(path: Path2D, op: PathOp): this;
147
+ getFillType(): FillType;
148
+ getFillTypeString(): string;
149
+ setFillType(fillType: FillType): this;
150
+ simplify(): this;
151
+ asWinding(): this;
152
+ transform(matrix: DOMMatrix2DInit): this;
153
+ getBounds(): [left: number, top: number, right: number, bottom: number];
154
+ computeTightBounds(): [left: number, top: number, right: number, bottom: number];
155
+ trim(start: number, end: number, isComplement?: boolean): this;
156
+ equals(path: Path2DLayer): boolean;
157
+ roundRect(x: number, y: number, width: number, height: number, radius: number): this;
158
+ draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
159
+ /**
160
+ * Converts the Path2D Layer to a JSON representation.
161
+ * @returns {IPath2DLayer} The JSON representation of the Path2D Layer.
162
+ */
163
+ toJSON(): IPath2DLayer;
164
+ }
@@ -0,0 +1,293 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Path2DLayer = void 0;
4
+ const canvas_1 = require("@napi-rs/canvas");
5
+ const types_1 = require("../../types");
6
+ const utils_1 = require("../../utils/utils");
7
+ const BaseLayer_1 = require("./BaseLayer");
8
+ const LazyUtil_1 = require("../../utils/LazyUtil");
9
+ class Path2DLayer extends BaseLayer_1.BaseLayer {
10
+ id;
11
+ type = types_1.LayerType.Path;
12
+ zIndex;
13
+ visible;
14
+ props;
15
+ constructor(props, misc) {
16
+ super(types_1.LayerType.Path, props || {}, misc);
17
+ this.id = misc?.id || (0, utils_1.generateID)(types_1.LayerType.Path);
18
+ this.zIndex = misc?.zIndex || 1;
19
+ this.visible = misc?.visible || true;
20
+ this.props = props ? props : {};
21
+ }
22
+ /**
23
+ * Sets the unique identifier of the layer.
24
+ *
25
+ * @param {string} id - The unique identifier.
26
+ * @returns {this} The current instance for chaining.
27
+ */
28
+ setID(id) {
29
+ this.id = id;
30
+ return this;
31
+ }
32
+ /**
33
+ * Sets the visibility of the layer.
34
+ * @param visible {boolean} - The visibility state of the layer.
35
+ * @returns {this} The current instance for chaining.
36
+ */
37
+ setVisible(visible) {
38
+ this.visible = visible;
39
+ return this;
40
+ }
41
+ /**
42
+ * Sets the z-index of the layer.
43
+ * @param zIndex {number} - The z-index value of the layer.
44
+ * @returns {this} The current instance for chaining.
45
+ */
46
+ setZIndex(zIndex) {
47
+ this.zIndex = zIndex;
48
+ return this;
49
+ }
50
+ /**
51
+ * Sets the global composite operation for the layer.
52
+ * @param {AnyGlobalCompositeOperation} operation - The composite operation.
53
+ * @returns {this} The current instance for chaining.
54
+ */
55
+ setGlobalCompositeOperation(operation) {
56
+ this.props.globalComposite = operation;
57
+ return this;
58
+ }
59
+ /**
60
+ * Sets the filter effects for the layer.
61
+ * @param {...AnyFilter} filter - The filter effects to apply.
62
+ * @returns {this} The current instance for chaining.
63
+ */
64
+ setFilters(...filter) {
65
+ this.props.filter = filter.join(' ');
66
+ return this;
67
+ }
68
+ /**
69
+ * Sets the transformation matrix of the layer.
70
+ * @param {DOMMatrix2DInit} matrix - The transformation matrix.
71
+ * @returns {this} The current instance for chaining.
72
+ */
73
+ setMatrix(matrix) {
74
+ this.props.transform = { ...this.props.transform, matrix };
75
+ return this;
76
+ }
77
+ /**
78
+ * Sets the scale of the layer in the x and y directions.
79
+ * @param {number} x - The scale factor in the x direction.
80
+ * @param {number} y - The scale factor in the y direction.
81
+ * @returns {this} The current instance for chaining.
82
+ */
83
+ setScale(x, y) {
84
+ this.props.transform = { ...this.props.transform, scale: { x, y } };
85
+ return this;
86
+ }
87
+ /**
88
+ * Sets the translation of the layer in the x and y directions.
89
+ * @param {number} x - The translation in the x direction.
90
+ * @param {number} y - The translation in the y direction.
91
+ * @returns {this} The current instance for chaining.
92
+ */
93
+ setTranslate(x, y) {
94
+ this.props.transform = { ...this.props.transform, translate: { x, y } };
95
+ return this;
96
+ }
97
+ /**
98
+ * Sets the opacity of the layer.
99
+ * @param {number} opacity - The opacity value, between 0 and 1.
100
+ * @returns {this} The current instance for chaining.
101
+ */
102
+ setOpacity(opacity) {
103
+ this.props.opacity = opacity;
104
+ return this;
105
+ }
106
+ /**
107
+ * Sets the stroke properties of the Path2D Layer.
108
+ * @param width {number} - The width of the stroke.
109
+ * @param cap {string} - The cap style of the stroke.
110
+ * @param join {string} - The join style of the stroke.
111
+ * @param dash {number[]} - The dash pattern of the stroke.
112
+ * @param dashOffset {number} - The dash offset of the stroke.
113
+ * @param miterLimit {number} - The miter limit of the stroke.
114
+ * @returns {this} The current instance for chaining.
115
+ */
116
+ setStroke(width, cap, join, dash, dashOffset, miterLimit) {
117
+ this.props.stroke = {
118
+ width,
119
+ cap: cap || 'butt',
120
+ join: join || 'miter',
121
+ dash: dash || [],
122
+ dashOffset: dashOffset || 0,
123
+ miterLimit: miterLimit || 10,
124
+ };
125
+ return this;
126
+ }
127
+ /**
128
+ * Sets whether the Path2D Layer should be filled or stroked.
129
+ * @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
130
+ * @returns {this} The current instance for chaining.
131
+ */
132
+ setFilled(filled) {
133
+ this.props.filled = filled;
134
+ return this;
135
+ }
136
+ /**
137
+ * Sets the color of the Path2D Layer.
138
+ * @param color {string} - The color of the Path2D Layer.
139
+ * @returns {this} The current instance for chaining.
140
+ * @throws {LazyError} If the color is not provided or invalid.
141
+ */
142
+ setColor(color) {
143
+ if (!color)
144
+ throw new LazyUtil_1.LazyError('The color of the layer must be provided');
145
+ if (!(0, utils_1.isColor)(color))
146
+ throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
147
+ this.props.fillStyle = color;
148
+ return this;
149
+ }
150
+ setPath(path) {
151
+ this.props.path2D = path instanceof canvas_1.Path2D ? path : new canvas_1.Path2D(path);
152
+ return this;
153
+ }
154
+ loadFromSVG(path) {
155
+ this.props.loadFromSVG = path;
156
+ return this;
157
+ }
158
+ setClipPath(clipPath) {
159
+ this.props.clipPath = clipPath;
160
+ return this;
161
+ }
162
+ toSVGString() {
163
+ return this.props.path2D.toSVGString();
164
+ }
165
+ addPath(path, transform) {
166
+ this.props.path2D.addPath(path, transform);
167
+ return this;
168
+ }
169
+ arc(x, y, radius, startAngle, endAngle, anticlockwise) {
170
+ this.props.path2D.arc(x, y, radius, startAngle, endAngle, anticlockwise);
171
+ return this;
172
+ }
173
+ arcTo(x1, y1, x2, y2, radius) {
174
+ this.props.path2D.arcTo(x1, y1, x2, y2, radius);
175
+ return this;
176
+ }
177
+ bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y) {
178
+ this.props.path2D.bezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y);
179
+ return this;
180
+ }
181
+ closePath() {
182
+ this.props.path2D.closePath();
183
+ return this;
184
+ }
185
+ ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise) {
186
+ this.props.path2D.ellipse(x, y, radiusX, radiusY, rotation, startAngle, endAngle, anticlockwise);
187
+ return this;
188
+ }
189
+ lineTo(x, y) {
190
+ this.props.path2D.lineTo(x, y);
191
+ return this;
192
+ }
193
+ moveTo(x, y) {
194
+ this.props.path2D.moveTo(x, y);
195
+ return this;
196
+ }
197
+ quadraticCurveTo(cpx, cpy, x, y) {
198
+ this.props.path2D.quadraticCurveTo(cpx, cpy, x, y);
199
+ return this;
200
+ }
201
+ rect(x, y, width, height) {
202
+ this.props.path2D.rect(x, y, width, height);
203
+ return this;
204
+ }
205
+ stroke(stroke) {
206
+ this.props.path2D.stroke(stroke);
207
+ return this;
208
+ }
209
+ op(path, op) {
210
+ this.props.path2D.op(path, op);
211
+ return this;
212
+ }
213
+ getFillType() {
214
+ return this.props.path2D.getFillType();
215
+ }
216
+ getFillTypeString() {
217
+ return this.props.path2D.getFillTypeString();
218
+ }
219
+ setFillType(fillType) {
220
+ this.props.path2D.setFillType(fillType);
221
+ return this;
222
+ }
223
+ simplify() {
224
+ this.props.path2D.simplify();
225
+ return this;
226
+ }
227
+ asWinding() {
228
+ this.props.path2D.asWinding();
229
+ return this;
230
+ }
231
+ transform(matrix) {
232
+ this.props.path2D.transform(matrix);
233
+ return this;
234
+ }
235
+ getBounds() {
236
+ return this.props.path2D.getBounds();
237
+ }
238
+ computeTightBounds() {
239
+ return this.props.path2D.computeTightBounds();
240
+ }
241
+ trim(start, end, isComplement) {
242
+ this.props.path2D.trim(start, end, isComplement);
243
+ return this;
244
+ }
245
+ equals(path) {
246
+ return this.props.path2D.equals(path.props.path2D);
247
+ }
248
+ roundRect(x, y, width, height, radius) {
249
+ this.props.path2D.roundRect(x, y, width, height, radius);
250
+ return this;
251
+ }
252
+ async draw(ctx, canvas, manager, debug) {
253
+ ctx.beginPath();
254
+ ctx.save();
255
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
256
+ (0, utils_1.transform)(ctx, this.props.transform, { width: 0, height: 0, x: 0, y: 0, type: this.type });
257
+ (0, utils_1.opacity)(ctx, this.props.opacity);
258
+ ctx.globalCompositeOperation = this.props.globalComposite;
259
+ if (this.props.clipPath) {
260
+ ctx.clip(this.props.path2D);
261
+ }
262
+ else if (this.props.filled) {
263
+ ctx.fillStyle = fillStyle;
264
+ ctx.fill(this.props.path2D);
265
+ }
266
+ else {
267
+ ctx.strokeStyle = fillStyle;
268
+ ctx.lineWidth = this.props.stroke.width;
269
+ ctx.lineCap = this.props.stroke.cap;
270
+ ctx.lineJoin = this.props.stroke.join;
271
+ ctx.miterLimit = this.props.stroke.miterLimit;
272
+ ctx.lineDashOffset = this.props.stroke.dashOffset;
273
+ ctx.setLineDash(this.props.stroke.dash);
274
+ ctx.stroke(this.props.path2D);
275
+ }
276
+ ctx.restore();
277
+ ctx.closePath();
278
+ }
279
+ /**
280
+ * Converts the Path2D Layer to a JSON representation.
281
+ * @returns {IPath2DLayer} The JSON representation of the Path2D Layer.
282
+ */
283
+ toJSON() {
284
+ return {
285
+ id: this.id,
286
+ type: this.type,
287
+ zIndex: this.zIndex,
288
+ visible: this.visible,
289
+ props: this.props
290
+ };
291
+ }
292
+ }
293
+ exports.Path2DLayer = Path2DLayer;