@nmmty/lazycanvas 0.6.5 → 1.0.0-dev.10

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 (91) hide show
  1. package/ReadMe.md +1 -1
  2. package/dist/core/Interpolation.d.ts +30 -0
  3. package/dist/core/Interpolation.js +200 -0
  4. package/dist/core/Scene.d.ts +94 -0
  5. package/dist/core/Scene.js +157 -0
  6. package/dist/core/Signal.d.ts +133 -0
  7. package/dist/core/Signal.js +255 -0
  8. package/dist/core/SignalUtils.d.ts +133 -0
  9. package/dist/core/SignalUtils.js +333 -0
  10. package/dist/core/ThreadScheduler.d.ts +38 -0
  11. package/dist/core/ThreadScheduler.js +74 -0
  12. package/dist/core/index.d.ts +5 -0
  13. package/dist/core/index.js +21 -0
  14. package/dist/helpers/Filters.js +1 -1
  15. package/dist/helpers/FontsList.js +18 -18
  16. package/dist/helpers/Utlis.d.ts +3 -3
  17. package/dist/helpers/Utlis.js +25 -36
  18. package/dist/helpers/index.d.ts +3 -3
  19. package/dist/index.d.ts +4 -1
  20. package/dist/index.js +4 -1
  21. package/dist/jsx-runtime.d.ts +17 -0
  22. package/dist/jsx-runtime.js +111 -0
  23. package/dist/structures/LazyCanvas.d.ts +10 -48
  24. package/dist/structures/LazyCanvas.js +17 -78
  25. package/dist/structures/components/BaseLayer.d.ts +78 -32
  26. package/dist/structures/components/BaseLayer.js +106 -37
  27. package/dist/structures/components/BezierLayer.d.ts +25 -38
  28. package/dist/structures/components/BezierLayer.js +88 -53
  29. package/dist/structures/components/{Group.d.ts → Div.d.ts} +37 -18
  30. package/dist/structures/components/Div.js +202 -0
  31. package/dist/structures/components/ImageLayer.d.ts +1 -1
  32. package/dist/structures/components/ImageLayer.js +28 -29
  33. package/dist/structures/components/LineLayer.d.ts +18 -36
  34. package/dist/structures/components/LineLayer.js +43 -45
  35. package/dist/structures/components/MorphLayer.d.ts +4 -33
  36. package/dist/structures/components/MorphLayer.js +37 -51
  37. package/dist/structures/components/Path2DLayer.d.ts +7 -35
  38. package/dist/structures/components/Path2DLayer.js +32 -41
  39. package/dist/structures/components/PolygonLayer.d.ts +3 -32
  40. package/dist/structures/components/PolygonLayer.js +37 -42
  41. package/dist/structures/components/QuadraticLayer.d.ts +25 -34
  42. package/dist/structures/components/QuadraticLayer.js +83 -47
  43. package/dist/structures/components/TextLayer.d.ts +5 -34
  44. package/dist/structures/components/TextLayer.js +88 -71
  45. package/dist/structures/components/index.d.ts +10 -11
  46. package/dist/structures/components/index.js +1 -2
  47. package/dist/structures/helpers/Exporter.d.ts +13 -4
  48. package/dist/structures/helpers/Exporter.js +82 -46
  49. package/dist/structures/helpers/Font.js +1 -17
  50. package/dist/structures/helpers/Gradient.js +35 -49
  51. package/dist/structures/helpers/Link.js +2 -14
  52. package/dist/structures/helpers/Pattern.js +10 -18
  53. package/dist/structures/helpers/index.d.ts +7 -7
  54. package/dist/structures/helpers/readers/JSONReader.d.ts +4 -4
  55. package/dist/structures/helpers/readers/JSONReader.js +44 -48
  56. package/dist/structures/helpers/readers/YAMLReader.js +11 -11
  57. package/dist/structures/managers/FontsManager.js +9 -18
  58. package/dist/structures/managers/LayersManager.d.ts +18 -28
  59. package/dist/structures/managers/LayersManager.js +14 -36
  60. package/dist/structures/managers/LayoutManager.d.ts +23 -0
  61. package/dist/structures/managers/LayoutManager.js +409 -0
  62. package/dist/structures/managers/index.d.ts +3 -5
  63. package/dist/structures/managers/index.js +1 -3
  64. package/dist/structures/managers/{RenderManager.d.ts → piplines/ClassicRenderPipeline.d.ts} +4 -30
  65. package/dist/structures/managers/piplines/ClassicRenderPipeline.js +90 -0
  66. package/dist/structures/managers/piplines/ModernRenderPipeline.d.ts +44 -0
  67. package/dist/structures/managers/piplines/ModernRenderPipeline.js +123 -0
  68. package/dist/structures/managers/piplines/index.d.ts +24 -0
  69. package/dist/structures/managers/piplines/index.js +18 -0
  70. package/dist/types/enum.d.ts +1 -2
  71. package/dist/types/enum.js +1 -2
  72. package/dist/types/index.d.ts +1 -1
  73. package/dist/types/types.d.ts +257 -107
  74. package/dist/utils/APNGEncoder.d.ts +67 -0
  75. package/dist/utils/APNGEncoder.js +205 -0
  76. package/dist/utils/DrawUtils.d.ts +9 -0
  77. package/dist/utils/DrawUtils.js +42 -0
  78. package/dist/utils/LazyUtil.js +1 -2
  79. package/dist/utils/index.d.ts +4 -0
  80. package/dist/utils/index.js +20 -0
  81. package/dist/utils/utils.d.ts +4 -7
  82. package/dist/utils/utils.js +140 -78
  83. package/package.json +61 -59
  84. package/dist/structures/components/ClearLayer.d.ts +0 -147
  85. package/dist/structures/components/ClearLayer.js +0 -158
  86. package/dist/structures/components/Group.js +0 -153
  87. package/dist/structures/managers/AnimationManager.d.ts +0 -120
  88. package/dist/structures/managers/AnimationManager.js +0 -99
  89. package/dist/structures/managers/PluginManager.d.ts +0 -230
  90. package/dist/structures/managers/PluginManager.js +0 -182
  91. package/dist/structures/managers/RenderManager.js +0 -183
@@ -3,17 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.MorphLayer = void 0;
4
4
  const BaseLayer_1 = require("./BaseLayer");
5
5
  const types_1 = require("../../types");
6
- const utils_1 = require("../../utils/utils");
7
- const LazyUtil_1 = require("../../utils/LazyUtil");
6
+ const utils_1 = require("../../utils");
8
7
  const helpers_1 = require("../helpers");
9
8
  /**
10
9
  * Class representing a Morph Layer, extending the BaseLayer class.
11
10
  */
12
11
  class MorphLayer extends BaseLayer_1.BaseLayer {
13
- /**
14
- * The properties of the Morph Layer.
15
- */
16
- props;
17
12
  /**
18
13
  * Constructs a new MorphLayer instance.
19
14
  * @param {IMorphLayerProps} [props] - The properties of the Morph Layer.
@@ -47,10 +42,10 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
47
42
  */
48
43
  setColor(color) {
49
44
  if (!color)
50
- throw new LazyUtil_1.LazyError('The color of the layer must be provided');
45
+ throw new utils_1.LazyError("The color of the layer must be provided");
51
46
  if (!(0, utils_1.isColor)(color))
52
- throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
53
- this.props.fillStyle = color;
47
+ throw new utils_1.LazyError("The color of the layer must be a valid color");
48
+ this.props.color = color;
54
49
  return this;
55
50
  }
56
51
  /**
@@ -66,13 +61,12 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
66
61
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
67
62
  this.props.stroke = {
68
63
  width,
69
- cap: cap || 'butt',
70
- join: join || 'miter',
64
+ cap: cap || "butt",
65
+ join: join || "miter",
71
66
  dash: dash || [],
72
67
  dashOffset: dashOffset || 0,
73
68
  miterLimit: miterLimit || 10,
74
69
  };
75
- this.props.filled = false; // Ensure filled is false when stroke is set
76
70
  return this;
77
71
  }
78
72
  /**
@@ -85,52 +79,53 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
85
79
  async draw(ctx, canvas, manager, debug) {
86
80
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
87
81
  const { xs, ys, w } = parcer.parseBatch({
88
- xs: { v: this.props.x },
89
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
82
+ xs: { v: this.props.position?.x || 0 },
83
+ ys: { v: this.props.position?.y || 0, options: utils_1.defaultArg.vl(true) },
90
84
  w: { v: this.props.size.width },
91
85
  });
92
- const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
86
+ const h = parcer.parse(this.props.size.height, utils_1.defaultArg.wh(w), utils_1.defaultArg.vl(true));
93
87
  const rad = {};
94
- if (typeof this.props.size.radius === 'object' && this.props.size.radius !== helpers_1.Link) {
88
+ if (typeof this.props.size.radius === "object" && this.props.size.radius !== helpers_1.Link) {
95
89
  for (const corner in this.props.size.radius) {
96
90
  // @ts-ignore
97
- rad[corner] = parcer.parse(this.props.size.radius[corner], LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
91
+ rad[corner] = parcer.parse(
92
+ // @ts-ignore
93
+ this.props.size.radius[corner], utils_1.defaultArg.wh(w / 2, h / 2), utils_1.defaultArg.vl(false, true));
98
94
  }
99
95
  }
100
96
  let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
101
- 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 });
97
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, {
98
+ debug,
99
+ layer: { width: w, height: h, x: xs, y: ys, align: this.props.centring },
100
+ manager,
101
+ });
102
102
  if (debug)
103
- LazyUtil_1.LazyLog.log('none', `MorphLayer:`, { x, y, w, h, rad });
103
+ utils_1.LazyLog.log("none", `MorphLayer:`, { x, y, w, h, rad });
104
104
  ctx.save();
105
- (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
105
+ if (this.props.transform) {
106
+ (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
107
+ }
106
108
  ctx.beginPath();
107
109
  if (Object.keys(rad).length > 0) {
108
- ctx.moveTo(x + (w / 2), y);
109
- ctx.arcTo(x + w, y, x + w, y + (h / 2), rad.rightTop || rad.all || 0);
110
- ctx.arcTo(x + w, y + h, x + (w / 2), y + h, rad.rightBottom || rad.all || 0);
111
- ctx.arcTo(x, y + h, x, y + (h / 2), rad.leftBottom || rad.all || 0);
112
- ctx.arcTo(x, y, x + (w / 2), y, rad.leftTop || rad.all || 0);
110
+ ctx.moveTo(x + w / 2, y);
111
+ ctx.arcTo(x + w, y, x + w, y + h / 2, rad.rightTop || rad.all || 0);
112
+ ctx.arcTo(x + w, y + h, x + w / 2, y + h, rad.rightBottom || rad.all || 0);
113
+ ctx.arcTo(x, y + h, x, y + h / 2, rad.leftBottom || rad.all || 0);
114
+ ctx.arcTo(x, y, x + w / 2, y, rad.leftTop || rad.all || 0);
113
115
  }
114
116
  else {
115
117
  ctx.rect(x, y, w, h);
116
118
  }
117
119
  ctx.closePath();
118
- (0, utils_1.drawShadow)(ctx, this.props.shadow);
119
- (0, utils_1.opacity)(ctx, this.props.opacity);
120
- (0, utils_1.filters)(ctx, this.props.filter);
121
- if (this.props.filled) {
122
- ctx.fillStyle = fillStyle;
123
- ctx.fill();
120
+ utils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
121
+ utils_1.DrawUtils.opacity(ctx, this.props.opacity);
122
+ utils_1.DrawUtils.filters(ctx, this.props.filter);
123
+ utils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
124
+ if (this.props.stroke) {
125
+ ctx.stroke();
124
126
  }
125
127
  else {
126
- ctx.strokeStyle = fillStyle;
127
- ctx.lineWidth = this.props.stroke?.width || 1;
128
- ctx.lineCap = this.props.stroke?.cap || 'butt';
129
- ctx.lineJoin = this.props.stroke?.join || 'miter';
130
- ctx.miterLimit = this.props.stroke?.miterLimit || 10;
131
- ctx.lineDashOffset = this.props.stroke?.dashOffset || 0;
132
- ctx.setLineDash(this.props.stroke?.dash || []);
133
- ctx.stroke();
128
+ ctx.fill();
134
129
  }
135
130
  ctx.restore();
136
131
  }
@@ -141,8 +136,8 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
141
136
  toJSON() {
142
137
  let data = super.toJSON();
143
138
  let copy = { ...this.props };
144
- for (const key of ['x', 'y', 'size.width', 'size.height', 'size.radius', 'fillStyle']) {
145
- if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
139
+ for (const key of ["x", "y", "size.width", "size.height", "size.radius", "fillStyle"]) {
140
+ if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
146
141
  copy[key] = copy[key].toJSON();
147
142
  }
148
143
  }
@@ -156,21 +151,12 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
156
151
  validateProps(data) {
157
152
  return {
158
153
  ...super.validateProps(data),
159
- filled: data.filled || true,
160
- fillStyle: data.fillStyle || '#000000',
154
+ color: data.color || "#000000",
161
155
  size: {
162
156
  width: data.size?.width || 100,
163
157
  height: data.size?.height || 100,
164
158
  radius: data.size?.radius || { all: 0 },
165
159
  },
166
- stroke: {
167
- width: data.stroke?.width || 1,
168
- cap: data.stroke?.cap || 'butt',
169
- join: data.stroke?.join || 'miter',
170
- dashOffset: data.stroke?.dashOffset || 0,
171
- dash: data.stroke?.dash || [],
172
- miterLimit: data.stroke?.miterLimit || 10,
173
- },
174
160
  };
175
161
  }
176
162
  }
@@ -1,7 +1,8 @@
1
- import { Canvas, DOMMatrix2DInit, FillType, Path2D, PathOp, SKRSContext2D, StrokeOptions, SvgCanvas } from "@napi-rs/canvas";
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,45 +18,16 @@ 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
  */
27
- fillStyle: ColorType;
24
+ color: ColorType;
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
- };
57
- loadFromSVG: boolean;
58
- clipPath: boolean;
28
+ stroke?: StrokeOptions;
29
+ loadFromSVG?: boolean;
30
+ clipPath?: boolean;
59
31
  }
60
32
  export declare class Path2DLayer extends BaseLayer<IPath2DLayerProps> {
61
33
  id: string;
@@ -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?: StrokeOptions): this;
60
+ stroke(stroke?: SKRSStrokeOptions): this;
89
61
  op(path: Path2D, op: PathOp): this;
90
62
  getFillType(): FillType;
91
63
  getFillTypeString(): string;
@@ -3,17 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Path2DLayer = void 0;
4
4
  const canvas_1 = require("@napi-rs/canvas");
5
5
  const types_1 = require("../../types");
6
- const utils_1 = require("../../utils/utils");
6
+ const utils_1 = require("../../utils");
7
7
  const BaseLayer_1 = require("./BaseLayer");
8
- const LazyUtil_1 = require("../../utils/LazyUtil");
9
8
  class Path2DLayer extends BaseLayer_1.BaseLayer {
10
- id;
11
- type = types_1.LayerType.Path;
12
- zIndex;
13
- visible;
14
- props;
15
9
  constructor(props, misc) {
16
10
  super(types_1.LayerType.Path, props || {}, misc);
11
+ this.type = types_1.LayerType.Path;
17
12
  this.id = misc?.id || (0, utils_1.generateID)(types_1.LayerType.Path);
18
13
  this.zIndex = misc?.zIndex || 1;
19
14
  this.visible = misc?.visible || true;
@@ -28,10 +23,10 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
28
23
  */
29
24
  setColor(color) {
30
25
  if (!color)
31
- throw new LazyUtil_1.LazyError('The color of the layer must be provided');
26
+ throw new utils_1.LazyError("The color of the layer must be provided");
32
27
  if (!(0, utils_1.isColor)(color))
33
- throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
34
- this.props.fillStyle = color;
28
+ throw new utils_1.LazyError("The color of the layer must be a valid color");
29
+ this.props.color = color;
35
30
  return this;
36
31
  }
37
32
  setPath(path) {
@@ -139,28 +134,33 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
139
134
  async draw(ctx, canvas, manager, debug) {
140
135
  ctx.beginPath();
141
136
  ctx.save();
142
- let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, manager });
143
- (0, utils_1.transform)(ctx, this.props.transform, { width: 0, height: 0, x: 0, y: 0, type: this.type });
144
- (0, utils_1.drawShadow)(ctx, this.props.shadow);
145
- (0, utils_1.opacity)(ctx, this.props.opacity);
146
- (0, utils_1.filters)(ctx, this.props.filter);
147
- ctx.globalCompositeOperation = this.props.globalComposite;
137
+ if (debug)
138
+ utils_1.LazyLog.log("none", `Drawing Path2D Layer: `, {
139
+ layerId: this.id,
140
+ type: this.type,
141
+ path: this.props.path2D.toSVGString(),
142
+ });
143
+ if (this.props.transform) {
144
+ (0, utils_1.transform)(ctx, this.props.transform, { width: 0, height: 0, x: 0, y: 0, type: this.type });
145
+ }
146
+ utils_1.DrawUtils.opacity(ctx, this.props.opacity);
148
147
  if (this.props.clipPath) {
149
148
  ctx.clip(this.props.path2D);
150
149
  }
151
- else if (this.props.filled) {
152
- ctx.fillStyle = fillStyle;
153
- ctx.fill(this.props.path2D);
154
- }
155
- else {
156
- ctx.strokeStyle = fillStyle;
157
- ctx.lineWidth = this.props.stroke.width;
158
- ctx.lineCap = this.props.stroke.cap;
159
- ctx.lineJoin = this.props.stroke.join;
160
- ctx.miterLimit = this.props.stroke.miterLimit;
161
- ctx.lineDashOffset = this.props.stroke.dashOffset;
162
- ctx.setLineDash(this.props.stroke.dash);
163
- ctx.stroke(this.props.path2D);
150
+ else if (this.props.color) {
151
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, { debug, manager });
152
+ if (this.props.globalComposite) {
153
+ ctx.globalCompositeOperation = this.props.globalComposite;
154
+ }
155
+ utils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
156
+ utils_1.DrawUtils.filters(ctx, this.props.filter);
157
+ utils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
158
+ if (this.props.stroke) {
159
+ ctx.stroke(this.props.path2D);
160
+ }
161
+ else {
162
+ ctx.fill(this.props.path2D);
163
+ }
164
164
  }
165
165
  ctx.restore();
166
166
  ctx.closePath();
@@ -175,7 +175,7 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
175
175
  type: this.type,
176
176
  zIndex: this.zIndex,
177
177
  visible: this.visible,
178
- props: this.props
178
+ props: this.props,
179
179
  };
180
180
  }
181
181
  /**
@@ -186,19 +186,10 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
186
186
  validateProps(data) {
187
187
  return {
188
188
  ...super.validateProps(data),
189
- filled: data.filled || true,
190
- fillStyle: data.fillStyle || '#000000',
189
+ color: data.color || "#000000",
191
190
  path2D: data.path2D || new canvas_1.Path2D(),
192
- stroke: {
193
- width: data.stroke?.width || 1,
194
- cap: data.stroke?.cap || 'butt',
195
- join: data.stroke?.join || 'miter',
196
- dashOffset: data.stroke?.dashOffset || 0,
197
- dash: data.stroke?.dash || [],
198
- miterLimit: data.stroke?.miterLimit || 10
199
- },
200
191
  loadFromSVG: data.loadFromSVG || false,
201
- clipPath: data.clipPath || false
192
+ clipPath: data.clipPath || false,
202
193
  };
203
194
  }
204
195
  }
@@ -1,5 +1,5 @@
1
1
  import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
- import { ColorType, LayerType, ScaleType } from "../../types";
2
+ import { ColorType, LayerType, ScaleType, StrokeOptions } from "../../types";
3
3
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
4
  import { LayersManager } from "../managers";
5
5
  export interface IPolygonLayer extends IBaseLayer {
@@ -34,43 +34,14 @@ export interface IPolygonLayerProps extends IBaseLayerProps {
34
34
  */
35
35
  count: number;
36
36
  };
37
- /**
38
- * Whether the layer is filled.
39
- */
40
- filled: boolean;
41
37
  /**
42
38
  * The fill style (color or pattern) of the layer.
43
39
  */
44
- fillStyle: ColorType;
40
+ color: ColorType;
45
41
  /**
46
42
  * The stroke properties of the polygon.
47
43
  */
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
- };
44
+ stroke?: StrokeOptions;
74
45
  }
75
46
  export declare class PolygonLayer extends BaseLayer<IPolygonLayerProps> {
76
47
  props: IPolygonLayerProps;
@@ -3,10 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PolygonLayer = void 0;
4
4
  const BaseLayer_1 = require("./BaseLayer");
5
5
  const types_1 = require("../../types");
6
- const LazyUtil_1 = require("../../utils/LazyUtil");
7
- const utils_1 = require("../../utils/utils");
6
+ const utils_1 = require("../../utils");
8
7
  class PolygonLayer extends BaseLayer_1.BaseLayer {
9
- props;
10
8
  constructor(props, misc) {
11
9
  super(types_1.LayerType.Polygon, props || {}, misc);
12
10
  this.props = props ? props : {};
@@ -37,10 +35,10 @@ class PolygonLayer extends BaseLayer_1.BaseLayer {
37
35
  */
38
36
  setColor(color) {
39
37
  if (!color)
40
- throw new LazyUtil_1.LazyError('The color of the layer must be provided');
38
+ throw new utils_1.LazyError("The color of the layer must be provided");
41
39
  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;
40
+ throw new utils_1.LazyError("The color of the layer must be a valid color");
41
+ this.props.color = color;
44
42
  return this;
45
43
  }
46
44
  /**
@@ -56,13 +54,12 @@ class PolygonLayer extends BaseLayer_1.BaseLayer {
56
54
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
57
55
  this.props.stroke = {
58
56
  width,
59
- cap: cap || 'butt',
60
- join: join || 'miter',
57
+ cap: cap || "butt",
58
+ join: join || "miter",
61
59
  dash: dash || [],
62
60
  dashOffset: dashOffset || 0,
63
61
  miterLimit: miterLimit || 10,
64
62
  };
65
- this.props.filled = false; // Ensure filled is false when stroke is set
66
63
  return this;
67
64
  }
68
65
  /**
@@ -75,15 +72,26 @@ class PolygonLayer extends BaseLayer_1.BaseLayer {
75
72
  async draw(ctx, canvas, manager, debug) {
76
73
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
77
74
  const { xs, ys, w } = parcer.parseBatch({
78
- xs: { v: this.props.x },
79
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
75
+ xs: { v: this.props.position?.x || 0 },
76
+ ys: { v: this.props.position?.y || 0, options: utils_1.defaultArg.vl(true) },
80
77
  w: { v: this.props.size.width },
81
78
  });
82
- const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
79
+ const h = parcer.parse(this.props.size.height, utils_1.defaultArg.wh(w), utils_1.defaultArg.vl(true));
83
80
  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 });
81
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, {
82
+ debug,
83
+ layer: { width: w, height: h, x: xs, y: ys, align: this.props.centring },
84
+ manager,
85
+ });
85
86
  if (debug)
86
- LazyUtil_1.LazyLog.log('none', `PolygonLayer:`, { x, y, w, h, count: this.props.size.count, radius: this.props.size.radius });
87
+ utils_1.LazyLog.log("none", `PolygonLayer:`, {
88
+ x,
89
+ y,
90
+ w,
91
+ h,
92
+ count: this.props.size.count,
93
+ radius: this.props.size.radius,
94
+ });
87
95
  ctx.save();
88
96
  ctx.beginPath();
89
97
  // Calculate polygon vertices
@@ -92,7 +100,7 @@ class PolygonLayer extends BaseLayer_1.BaseLayer {
92
100
  const angle = (i / this.props.size.count) * (2 * Math.PI) - Math.PI / 2;
93
101
  vertices.push({
94
102
  x: x + w / 2 + (w / 2) * Math.cos(angle),
95
- y: y + h / 2 + (h / 2) * Math.sin(angle)
103
+ y: y + h / 2 + (h / 2) * Math.sin(angle),
96
104
  });
97
105
  }
98
106
  if (this.props.size.radius > 0) {
@@ -119,11 +127,11 @@ class PolygonLayer extends BaseLayer_1.BaseLayer {
119
127
  // Calculate arc start and end points
120
128
  const arcStart = {
121
129
  x: current.x - ndx1 * cornerRadius,
122
- y: current.y - ndy1 * cornerRadius
130
+ y: current.y - ndy1 * cornerRadius,
123
131
  };
124
132
  const arcEnd = {
125
133
  x: current.x + ndx2 * cornerRadius,
126
- y: current.y + ndy2 * cornerRadius
134
+ y: current.y + ndy2 * cornerRadius,
127
135
  };
128
136
  if (i === 0) {
129
137
  ctx.moveTo(arcStart.x, arcStart.y);
@@ -148,20 +156,16 @@ class PolygonLayer extends BaseLayer_1.BaseLayer {
148
156
  }
149
157
  ctx.closePath();
150
158
  }
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;
159
+ utils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
160
+ utils_1.DrawUtils.opacity(ctx, this.props.opacity);
161
+ utils_1.DrawUtils.filters(ctx, this.props.filter);
162
+ utils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
163
+ if (this.props.stroke) {
163
164
  ctx.stroke();
164
165
  }
166
+ else {
167
+ ctx.fill();
168
+ }
165
169
  ctx.restore();
166
170
  }
167
171
  /**
@@ -171,8 +175,8 @@ class PolygonLayer extends BaseLayer_1.BaseLayer {
171
175
  toJSON() {
172
176
  let data = super.toJSON();
173
177
  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]) {
178
+ for (const key of ["x", "y", "size.width", "size.height", "fillStyle"]) {
179
+ if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
176
180
  copy[key] = copy[key].toJSON();
177
181
  }
178
182
  }
@@ -190,18 +194,9 @@ class PolygonLayer extends BaseLayer_1.BaseLayer {
190
194
  width: data.size?.width || 100,
191
195
  height: data.size?.height || 100,
192
196
  radius: data.size?.radius || 0,
193
- count: data.size?.count || 3
197
+ count: data.size?.count || 3,
194
198
  },
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
- }
199
+ color: data.color || "#000000",
205
200
  };
206
201
  }
207
202
  }
@@ -1,5 +1,5 @@
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
  /**
@@ -19,14 +19,28 @@ export interface IQuadraticLayer extends IBaseLayer {
19
19
  * Interface representing the properties of a Quadratic layer.
20
20
  */
21
21
  export interface IQuadraticLayerProps extends IBaseLayerProps {
22
+ position: {
23
+ /**
24
+ * The x coordinate of the quadratic curve's starting point.
25
+ */
26
+ x: ScaleType;
27
+ /**
28
+ * The y coordinate of the quadratic curve's starting point.
29
+ */
30
+ y: ScaleType;
31
+ /**
32
+ * The end x coordinate of the quadratic curve.
33
+ */
34
+ endX: ScaleType;
35
+ /**
36
+ * The end y coordinate of the quadratic curve.
37
+ */
38
+ endY: ScaleType;
39
+ };
22
40
  /**
23
41
  * The control point of the quadratic curve, including x and y coordinates.
24
42
  */
25
43
  controlPoints: Array<Point>;
26
- /**
27
- * The end point of the quadratic curve, including x and y coordinates.
28
- */
29
- endPoint: Point;
30
44
  /**
31
45
  * Whether the layer is filled.
32
46
  */
@@ -34,36 +48,11 @@ export interface IQuadraticLayerProps extends IBaseLayerProps {
34
48
  /**
35
49
  * The fill style (color or pattern) of the layer.
36
50
  */
37
- fillStyle: ColorType;
51
+ color: ColorType;
38
52
  /**
39
53
  * The stroke properties of the quadratic curve.
40
54
  */
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
- };
55
+ stroke: StrokeOptions;
67
56
  }
68
57
  /**
69
58
  * Class representing a Quadratic layer, extending the BaseLayer class.
@@ -87,12 +76,14 @@ export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
87
76
  */
88
77
  setControlPoint(x: ScaleType, y: ScaleType): this;
89
78
  /**
90
- * Sets the end point of the quadratic layer.
79
+ * Sets the position of the quadratic layer.
91
80
  * @param {ScaleType} [x] - The x-coordinate of the end point.
92
81
  * @param {ScaleType} [y] - The y-coordinate of the end point.
82
+ * @param {ScaleType} [endX] - The x-coordinate of the end point.
83
+ * @param {ScaleType} [endY] - The y-coordinate of the end point.
93
84
  * @returns {this} The current instance for chaining.
94
85
  */
95
- setEndPosition(x: ScaleType, y: ScaleType): this;
86
+ setPosition(x: ScaleType, y: ScaleType, endX?: ScaleType, endY?: ScaleType): this;
96
87
  /**
97
88
  * Sets the color of the layer.
98
89
  * @param {ColorType} [color] - The color of the layer.