@nmmty/lazycanvas 0.6.5 → 1.0.0-dev.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/ReadMe.md +1 -1
  2. package/biome.json +41 -0
  3. package/dist/core/Interpolation.d.ts +30 -0
  4. package/dist/core/Interpolation.js +200 -0
  5. package/dist/core/Scene.d.ts +96 -0
  6. package/dist/core/Scene.js +172 -0
  7. package/dist/core/Signal.d.ts +133 -0
  8. package/dist/core/Signal.js +255 -0
  9. package/dist/core/SignalUtils.d.ts +133 -0
  10. package/dist/core/SignalUtils.js +333 -0
  11. package/dist/core/ThreadScheduler.d.ts +38 -0
  12. package/dist/core/ThreadScheduler.js +74 -0
  13. package/dist/helpers/Filters.js +1 -1
  14. package/dist/helpers/FontsList.js +18 -18
  15. package/dist/helpers/Utlis.d.ts +3 -3
  16. package/dist/helpers/Utlis.js +15 -18
  17. package/dist/helpers/index.d.ts +3 -3
  18. package/dist/index.d.ts +10 -0
  19. package/dist/index.js +10 -0
  20. package/dist/jsx-runtime.d.ts +17 -0
  21. package/dist/jsx-runtime.js +111 -0
  22. package/dist/structures/LazyCanvas.d.ts +3 -45
  23. package/dist/structures/LazyCanvas.js +11 -74
  24. package/dist/structures/components/BaseLayer.d.ts +34 -12
  25. package/dist/structures/components/BaseLayer.js +68 -35
  26. package/dist/structures/components/BezierLayer.d.ts +16 -37
  27. package/dist/structures/components/BezierLayer.js +83 -46
  28. package/dist/structures/components/{Group.d.ts → Div.d.ts} +22 -16
  29. package/dist/structures/components/{Group.js → Div.js} +38 -39
  30. package/dist/structures/components/ImageLayer.d.ts +1 -1
  31. package/dist/structures/components/ImageLayer.js +24 -25
  32. package/dist/structures/components/LineLayer.d.ts +11 -37
  33. package/dist/structures/components/LineLayer.js +42 -42
  34. package/dist/structures/components/MorphLayer.d.ts +3 -32
  35. package/dist/structures/components/MorphLayer.js +32 -46
  36. package/dist/structures/components/Path2DLayer.d.ts +4 -32
  37. package/dist/structures/components/Path2DLayer.js +28 -33
  38. package/dist/structures/components/PolygonLayer.d.ts +2 -31
  39. package/dist/structures/components/PolygonLayer.js +35 -38
  40. package/dist/structures/components/QuadraticLayer.d.ts +16 -33
  41. package/dist/structures/components/QuadraticLayer.js +80 -42
  42. package/dist/structures/components/TextLayer.d.ts +4 -33
  43. package/dist/structures/components/TextLayer.js +60 -62
  44. package/dist/structures/components/index.d.ts +10 -11
  45. package/dist/structures/components/index.js +1 -2
  46. package/dist/structures/helpers/Exporter.d.ts +13 -4
  47. package/dist/structures/helpers/Exporter.js +79 -42
  48. package/dist/structures/helpers/Font.js +1 -17
  49. package/dist/structures/helpers/Gradient.js +32 -45
  50. package/dist/structures/helpers/Link.js +2 -14
  51. package/dist/structures/helpers/Pattern.js +9 -17
  52. package/dist/structures/helpers/index.d.ts +7 -7
  53. package/dist/structures/helpers/readers/JSONReader.d.ts +4 -4
  54. package/dist/structures/helpers/readers/JSONReader.js +32 -40
  55. package/dist/structures/helpers/readers/YAMLReader.js +5 -5
  56. package/dist/structures/managers/FontsManager.js +9 -18
  57. package/dist/structures/managers/LayersManager.d.ts +18 -28
  58. package/dist/structures/managers/LayersManager.js +14 -36
  59. package/dist/structures/managers/RenderManager.d.ts +1 -15
  60. package/dist/structures/managers/RenderManager.js +17 -110
  61. package/dist/structures/managers/index.d.ts +3 -5
  62. package/dist/structures/managers/index.js +0 -2
  63. package/dist/types/enum.d.ts +1 -2
  64. package/dist/types/enum.js +1 -2
  65. package/dist/types/index.d.ts +1 -1
  66. package/dist/utils/APNGEncoder.d.ts +67 -0
  67. package/dist/utils/APNGEncoder.js +205 -0
  68. package/dist/utils/DrawUtils.d.ts +9 -0
  69. package/dist/utils/DrawUtils.js +42 -0
  70. package/dist/utils/LazyUtil.js +1 -2
  71. package/dist/utils/utils.d.ts +4 -7
  72. package/dist/utils/utils.js +133 -76
  73. package/package.json +62 -59
  74. package/dist/structures/components/ClearLayer.d.ts +0 -147
  75. package/dist/structures/components/ClearLayer.js +0 -158
  76. package/dist/structures/managers/AnimationManager.d.ts +0 -120
  77. package/dist/structures/managers/AnimationManager.js +0 -99
  78. package/dist/structures/managers/PluginManager.d.ts +0 -230
  79. package/dist/structures/managers/PluginManager.js +0 -182
  80. package/dist/types/types.d.ts +0 -107
@@ -5,14 +5,11 @@ const BaseLayer_1 = require("./BaseLayer");
5
5
  const types_1 = require("../../types");
6
6
  const LazyUtil_1 = require("../../utils/LazyUtil");
7
7
  const utils_1 = require("../../utils/utils");
8
+ const DrawUtils_1 = require("../../utils/DrawUtils");
8
9
  /**
9
10
  * Class representing a Line Layer, extending the BaseLayer class.
10
11
  */
11
12
  class LineLayer extends BaseLayer_1.BaseLayer {
12
- /**
13
- * The properties of the Line Layer.
14
- */
15
- props;
16
13
  /**
17
14
  * Constructs a new LineLayer instance.
18
15
  * @param {ILineLayerProps} [props] - The properties of the Line Layer.
@@ -24,13 +21,15 @@ class LineLayer extends BaseLayer_1.BaseLayer {
24
21
  this.props = this.validateProps(this.props);
25
22
  }
26
23
  /**
27
- * Sets the end position of the line layer.
24
+ * Sets the position of the line layer.
28
25
  * @param {ScaleType} [x] - The x-coordinate of the end point.
29
26
  * @param {ScaleType} [y] - The y-coordinate of the end point.
27
+ * @param {ScaleType} [endX] - The x-coordinate of the end point.
28
+ * @param {ScaleType} [endY] - The y-coordinate of the end point.
30
29
  * @returns {this} The current instance for chaining.
31
30
  */
32
- setEndPosition(x, y) {
33
- this.props.endPoint = { x, y };
31
+ setPosition(x, y, endX, endY) {
32
+ this.props.position = { x, y, endX: endX || 0, endY: endY || 0 };
34
33
  return this;
35
34
  }
36
35
  /**
@@ -41,9 +40,9 @@ class LineLayer extends BaseLayer_1.BaseLayer {
41
40
  */
42
41
  setColor(color) {
43
42
  if (!color)
44
- throw new LazyUtil_1.LazyError('The color of the layer must be provided');
43
+ throw new LazyUtil_1.LazyError("The color of the layer must be provided");
45
44
  if (!(0, utils_1.isColor)(color))
46
- throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
45
+ throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
47
46
  this.props.fillStyle = color;
48
47
  return this;
49
48
  }
@@ -60,8 +59,8 @@ class LineLayer extends BaseLayer_1.BaseLayer {
60
59
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
61
60
  this.props.stroke = {
62
61
  width,
63
- cap: cap || 'butt',
64
- join: join || 'miter',
62
+ cap: cap || "butt",
63
+ join: join || "miter",
65
64
  dash: dash || [],
66
65
  dashOffset: dashOffset || 0,
67
66
  miterLimit: miterLimit || 10,
@@ -78,10 +77,10 @@ class LineLayer extends BaseLayer_1.BaseLayer {
78
77
  getBoundingBox(ctx, canvas, manager) {
79
78
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
80
79
  const { xs, ys, xe, ye } = parcer.parseBatch({
81
- xs: { v: this.props.x },
82
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
83
- xe: { v: this.props.endPoint.x },
84
- ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) },
80
+ xs: { v: this.props.position.x },
81
+ ys: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
82
+ xe: { v: this.props.position.endX },
83
+ ye: { v: this.props.position.endY, options: LazyUtil_1.defaultArg.vl(true) },
85
84
  });
86
85
  let width = xe - xs;
87
86
  let height = ye - ys;
@@ -97,30 +96,30 @@ class LineLayer extends BaseLayer_1.BaseLayer {
97
96
  async draw(ctx, canvas, manager, debug) {
98
97
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
99
98
  const { xs, ys, xe, ye } = parcer.parseBatch({
100
- xs: { v: this.props.x },
101
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
102
- xe: { v: this.props.endPoint.x },
103
- ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) },
99
+ xs: { v: this.props.position.x },
100
+ ys: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
101
+ xe: { v: this.props.position.endX },
102
+ ye: { v: this.props.position.endY, options: LazyUtil_1.defaultArg.vl(true) },
104
103
  });
105
104
  let width = Math.abs(xe - xs);
106
105
  let height = Math.abs(ye - ys);
107
- let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width, height, x: Math.min(xs, xe), y: Math.min(ys, ye), align: 'none' }, manager });
106
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, {
107
+ debug,
108
+ layer: { width, height, x: Math.min(xs, xe), y: Math.min(ys, ye), align: "none" },
109
+ manager,
110
+ });
108
111
  if (debug)
109
- LazyUtil_1.LazyLog.log('none', `LineLayer:`, { xs, ys, xe, ye, width, height });
112
+ LazyUtil_1.LazyLog.log("none", `LineLayer:`, { xs, ys, xe, ye, width, height });
110
113
  ctx.save();
111
- (0, utils_1.transform)(ctx, this.props.transform, { x: xs, y: ys, width, height, type: this.type });
112
- (0, utils_1.drawShadow)(ctx, this.props.shadow);
113
- (0, utils_1.opacity)(ctx, this.props.opacity);
114
- (0, utils_1.filters)(ctx, this.props.filter);
114
+ if (this.props.transform) {
115
+ (0, utils_1.transform)(ctx, this.props.transform, { x: xs, y: ys, width, height, type: this.type });
116
+ }
117
+ DrawUtils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
118
+ DrawUtils_1.DrawUtils.opacity(ctx, this.props.opacity);
119
+ DrawUtils_1.DrawUtils.filters(ctx, this.props.filter);
120
+ DrawUtils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
115
121
  ctx.beginPath();
116
122
  ctx.moveTo(xs, ys);
117
- ctx.strokeStyle = fillStyle;
118
- ctx.lineWidth = this.props.stroke?.width || 1;
119
- ctx.lineCap = this.props.stroke?.cap || 'butt';
120
- ctx.lineJoin = this.props.stroke?.join || 'miter';
121
- ctx.miterLimit = this.props.stroke?.miterLimit || 10;
122
- ctx.lineDashOffset = this.props.stroke?.dashOffset || 0;
123
- ctx.setLineDash(this.props.stroke?.dash || []);
124
123
  ctx.lineTo(xe, ye);
125
124
  ctx.stroke();
126
125
  ctx.closePath();
@@ -133,8 +132,8 @@ class LineLayer extends BaseLayer_1.BaseLayer {
133
132
  toJSON() {
134
133
  let data = super.toJSON();
135
134
  let copy = { ...this.props };
136
- for (const key of ['x', 'y', 'endPoint.x', 'endPoint.y', 'fillStyle']) {
137
- if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
135
+ for (const key of ["x", "y", "endPoint.x", "endPoint.y", "fillStyle"]) {
136
+ if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
138
137
  copy[key] = copy[key].toJSON();
139
138
  }
140
139
  }
@@ -148,17 +147,18 @@ class LineLayer extends BaseLayer_1.BaseLayer {
148
147
  validateProps(data) {
149
148
  return {
150
149
  ...super.validateProps(data),
151
- filled: data.filled || false,
152
- fillStyle: data.fillStyle || '#000000',
153
- centring: data.centring || types_1.Centring.None,
154
- endPoint: {
155
- x: data.endPoint?.x || 0,
156
- y: data.endPoint?.y || 0,
150
+ position: {
151
+ x: data.position?.x || 0,
152
+ y: data.position?.y || 0,
153
+ endX: data.position?.endX || 0,
154
+ endY: data.position?.endY || 0,
157
155
  },
156
+ fillStyle: data.fillStyle || "#000000",
157
+ centring: data.centring || types_1.Centring.None,
158
158
  stroke: {
159
159
  width: data.stroke?.width || 1,
160
- cap: data.stroke?.cap || 'butt',
161
- join: data.stroke?.join || 'miter',
160
+ cap: data.stroke?.cap || "butt",
161
+ join: data.stroke?.join || "miter",
162
162
  dashOffset: data.stroke?.dashOffset || 0,
163
163
  dash: data.stroke?.dash || [],
164
164
  miterLimit: data.stroke?.miterLimit || 10,
@@ -1,5 +1,5 @@
1
1
  import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
- import { ColorType, ScaleType, LayerType, RadiusCorner } from "../../types";
2
+ import { ColorType, ScaleType, LayerType, RadiusCorner, StrokeOptions } from "../../types";
3
3
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
4
  import { LayersManager } from "../managers";
5
5
  /**
@@ -34,14 +34,10 @@ export interface IMorphLayerProps extends IBaseLayerProps {
34
34
  /**
35
35
  * The radius of the Morph Layer.
36
36
  */
37
- radius: {
37
+ radius?: {
38
38
  [corner in RadiusCorner]?: ScaleType;
39
39
  };
40
40
  };
41
- /**
42
- * Whether the layer is filled.
43
- */
44
- filled: boolean;
45
41
  /**
46
42
  * The fill style (color or pattern) of the layer.
47
43
  */
@@ -49,32 +45,7 @@ export interface IMorphLayerProps extends IBaseLayerProps {
49
45
  /**
50
46
  * The stroke properties of the morph.
51
47
  */
52
- stroke: {
53
- /**
54
- * The width of the stroke.
55
- */
56
- width: number;
57
- /**
58
- * The cap style of the stroke.
59
- */
60
- cap: CanvasLineCap;
61
- /**
62
- * The join style of the stroke.
63
- */
64
- join: CanvasLineJoin;
65
- /**
66
- * The dash offset of the stroke.
67
- */
68
- dashOffset: number;
69
- /**
70
- * The dash pattern of the stroke.
71
- */
72
- dash: number[];
73
- /**
74
- * The miter limit of the stroke.
75
- */
76
- miterLimit: number;
77
- };
48
+ stroke?: StrokeOptions;
78
49
  }
79
50
  /**
80
51
  * Class representing a Morph Layer, extending the BaseLayer class.
@@ -6,14 +6,11 @@ const types_1 = require("../../types");
6
6
  const utils_1 = require("../../utils/utils");
7
7
  const LazyUtil_1 = require("../../utils/LazyUtil");
8
8
  const helpers_1 = require("../helpers");
9
+ const DrawUtils_1 = require("../../utils/DrawUtils");
9
10
  /**
10
11
  * Class representing a Morph Layer, extending the BaseLayer class.
11
12
  */
12
13
  class MorphLayer extends BaseLayer_1.BaseLayer {
13
- /**
14
- * The properties of the Morph Layer.
15
- */
16
- props;
17
14
  /**
18
15
  * Constructs a new MorphLayer instance.
19
16
  * @param {IMorphLayerProps} [props] - The properties of the Morph Layer.
@@ -47,9 +44,9 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
47
44
  */
48
45
  setColor(color) {
49
46
  if (!color)
50
- throw new LazyUtil_1.LazyError('The color of the layer must be provided');
47
+ throw new LazyUtil_1.LazyError("The color of the layer must be provided");
51
48
  if (!(0, utils_1.isColor)(color))
52
- throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
49
+ throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
53
50
  this.props.fillStyle = color;
54
51
  return this;
55
52
  }
@@ -66,13 +63,12 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
66
63
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
67
64
  this.props.stroke = {
68
65
  width,
69
- cap: cap || 'butt',
70
- join: join || 'miter',
66
+ cap: cap || "butt",
67
+ join: join || "miter",
71
68
  dash: dash || [],
72
69
  dashOffset: dashOffset || 0,
73
70
  miterLimit: miterLimit || 10,
74
71
  };
75
- this.props.filled = false; // Ensure filled is false when stroke is set
76
72
  return this;
77
73
  }
78
74
  /**
@@ -85,52 +81,51 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
85
81
  async draw(ctx, canvas, manager, debug) {
86
82
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
87
83
  const { xs, ys, w } = parcer.parseBatch({
88
- xs: { v: this.props.x },
89
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
84
+ xs: { v: this.props.position.x },
85
+ ys: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
90
86
  w: { v: this.props.size.width },
91
87
  });
92
88
  const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
93
89
  const rad = {};
94
- if (typeof this.props.size.radius === 'object' && this.props.size.radius !== helpers_1.Link) {
90
+ if (typeof this.props.size.radius === "object" && this.props.size.radius !== helpers_1.Link) {
95
91
  for (const corner in this.props.size.radius) {
96
92
  // @ts-ignore
97
93
  rad[corner] = parcer.parse(this.props.size.radius[corner], LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_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.fillStyle, {
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
+ LazyUtil_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
+ DrawUtils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
121
+ DrawUtils_1.DrawUtils.opacity(ctx, this.props.opacity);
122
+ DrawUtils_1.DrawUtils.filters(ctx, this.props.filter);
123
+ DrawUtils_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
+ fillStyle: data.fillStyle || "#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,10 +18,6 @@ export interface IPath2DLayerProps extends IBaseLayerProps {
17
18
  * The Path2D object representing the shape of the layer.
18
19
  */
19
20
  path2D: Path2D;
20
- /**
21
- * Whether the layer is filled.
22
- */
23
- filled: boolean;
24
21
  /**
25
22
  * The fill style (color or pattern) of the layer.
26
23
  */
@@ -28,32 +25,7 @@ export interface IPath2DLayerProps extends IBaseLayerProps {
28
25
  /**
29
26
  * The stroke properties of the Path2D.
30
27
  */
31
- stroke: {
32
- /**
33
- * The width of the stroke.
34
- */
35
- width: number;
36
- /**
37
- * The cap style of the stroke.
38
- */
39
- cap: CanvasLineCap;
40
- /**
41
- * The join style of the stroke.
42
- */
43
- join: CanvasLineJoin;
44
- /**
45
- * The dash offset of the stroke.
46
- */
47
- dashOffset: number;
48
- /**
49
- * The dash pattern of the stroke.
50
- */
51
- dash: number[];
52
- /**
53
- * The miter limit of the stroke.
54
- */
55
- miterLimit: number;
56
- };
28
+ stroke: StrokeOptions;
57
29
  loadFromSVG: boolean;
58
30
  clipPath: boolean;
59
31
  }
@@ -85,7 +57,7 @@ export declare class Path2DLayer extends BaseLayer<IPath2DLayerProps> {
85
57
  moveTo(x: number, y: number): this;
86
58
  quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): this;
87
59
  rect(x: number, y: number, width: number, height: number): this;
88
- stroke(stroke?: StrokeOptions): this;
60
+ stroke(stroke?: SKRSStrokeOptions): this;
89
61
  op(path: Path2D, op: PathOp): this;
90
62
  getFillType(): FillType;
91
63
  getFillTypeString(): string;
@@ -6,14 +6,11 @@ const types_1 = require("../../types");
6
6
  const utils_1 = require("../../utils/utils");
7
7
  const BaseLayer_1 = require("./BaseLayer");
8
8
  const LazyUtil_1 = require("../../utils/LazyUtil");
9
+ const DrawUtils_1 = require("../../utils/DrawUtils");
9
10
  class Path2DLayer extends BaseLayer_1.BaseLayer {
10
- id;
11
- type = types_1.LayerType.Path;
12
- zIndex;
13
- visible;
14
- props;
15
11
  constructor(props, misc) {
16
12
  super(types_1.LayerType.Path, props || {}, misc);
13
+ this.type = types_1.LayerType.Path;
17
14
  this.id = misc?.id || (0, utils_1.generateID)(types_1.LayerType.Path);
18
15
  this.zIndex = misc?.zIndex || 1;
19
16
  this.visible = misc?.visible || true;
@@ -28,9 +25,9 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
28
25
  */
29
26
  setColor(color) {
30
27
  if (!color)
31
- throw new LazyUtil_1.LazyError('The color of the layer must be provided');
28
+ throw new LazyUtil_1.LazyError("The color of the layer must be provided");
32
29
  if (!(0, utils_1.isColor)(color))
33
- throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
30
+ throw new LazyUtil_1.LazyError("The color of the layer must be a valid color");
34
31
  this.props.fillStyle = color;
35
32
  return this;
36
33
  }
@@ -139,28 +136,27 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
139
136
  async draw(ctx, canvas, manager, debug) {
140
137
  ctx.beginPath();
141
138
  ctx.save();
142
- 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;
139
+ if (this.props.transform) {
140
+ (0, utils_1.transform)(ctx, this.props.transform, { width: 0, height: 0, x: 0, y: 0, type: this.type });
141
+ }
142
+ DrawUtils_1.DrawUtils.opacity(ctx, this.props.opacity);
148
143
  if (this.props.clipPath) {
149
144
  ctx.clip(this.props.path2D);
150
145
  }
151
- else if (this.props.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);
146
+ else if (this.props.fillStyle) {
147
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, manager });
148
+ if (this.props.globalComposite) {
149
+ ctx.globalCompositeOperation = this.props.globalComposite;
150
+ }
151
+ DrawUtils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
152
+ DrawUtils_1.DrawUtils.filters(ctx, this.props.filter);
153
+ DrawUtils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
154
+ if (this.props.stroke) {
155
+ ctx.stroke(this.props.path2D);
156
+ }
157
+ else {
158
+ ctx.fill(this.props.path2D);
159
+ }
164
160
  }
165
161
  ctx.restore();
166
162
  ctx.closePath();
@@ -175,7 +171,7 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
175
171
  type: this.type,
176
172
  zIndex: this.zIndex,
177
173
  visible: this.visible,
178
- props: this.props
174
+ props: this.props,
179
175
  };
180
176
  }
181
177
  /**
@@ -186,19 +182,18 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
186
182
  validateProps(data) {
187
183
  return {
188
184
  ...super.validateProps(data),
189
- filled: data.filled || true,
190
- fillStyle: data.fillStyle || '#000000',
185
+ fillStyle: data.fillStyle || "#000000",
191
186
  path2D: data.path2D || new canvas_1.Path2D(),
192
187
  stroke: {
193
188
  width: data.stroke?.width || 1,
194
- cap: data.stroke?.cap || 'butt',
195
- join: data.stroke?.join || 'miter',
189
+ cap: data.stroke?.cap || "butt",
190
+ join: data.stroke?.join || "miter",
196
191
  dashOffset: data.stroke?.dashOffset || 0,
197
192
  dash: data.stroke?.dash || [],
198
- miterLimit: data.stroke?.miterLimit || 10
193
+ miterLimit: data.stroke?.miterLimit || 10,
199
194
  },
200
195
  loadFromSVG: data.loadFromSVG || false,
201
- clipPath: data.clipPath || false
196
+ clipPath: data.clipPath || false,
202
197
  };
203
198
  }
204
199
  }
@@ -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,10 +34,6 @@ 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
  */
@@ -45,32 +41,7 @@ export interface IPolygonLayerProps extends IBaseLayerProps {
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;