@nmmty/lazycanvas 0.6.4 → 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 +27 -40
  28. package/dist/structures/components/BezierLayer.js +90 -55
  29. package/dist/structures/components/{Group.d.ts → Div.d.ts} +41 -22
  30. package/dist/structures/components/Div.js +202 -0
  31. package/dist/structures/components/ImageLayer.d.ts +2 -2
  32. package/dist/structures/components/ImageLayer.js +29 -30
  33. package/dist/structures/components/LineLayer.d.ts +20 -38
  34. package/dist/structures/components/LineLayer.js +45 -47
  35. package/dist/structures/components/MorphLayer.d.ts +5 -34
  36. package/dist/structures/components/MorphLayer.js +38 -52
  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 +95 -0
  40. package/dist/structures/components/PolygonLayer.js +203 -0
  41. package/dist/structures/components/QuadraticLayer.d.ts +36 -45
  42. package/dist/structures/components/QuadraticLayer.js +90 -54
  43. package/dist/structures/components/TextLayer.d.ts +17 -46
  44. package/dist/structures/components/TextLayer.js +94 -77
  45. package/dist/structures/components/index.d.ts +10 -10
  46. package/dist/structures/components/index.js +2 -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 +46 -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 +4 -3
  71. package/dist/types/enum.js +3 -2
  72. package/dist/types/index.d.ts +1 -1
  73. package/dist/types/types.d.ts +257 -105
  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 +5 -9
  82. package/dist/utils/utils.js +154 -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,16 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LineLayer = 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
  /**
9
8
  * Class representing a Line Layer, extending the BaseLayer class.
10
9
  */
11
10
  class LineLayer extends BaseLayer_1.BaseLayer {
12
- /**
13
- * The properties of the Line Layer.
14
- */
15
- props;
16
11
  /**
17
12
  * Constructs a new LineLayer instance.
18
13
  * @param {ILineLayerProps} [props] - The properties of the Line Layer.
@@ -24,13 +19,15 @@ class LineLayer extends BaseLayer_1.BaseLayer {
24
19
  this.props = this.validateProps(this.props);
25
20
  }
26
21
  /**
27
- * Sets the end position of the line layer.
22
+ * Sets the position of the line layer.
28
23
  * @param {ScaleType} [x] - The x-coordinate of the end point.
29
24
  * @param {ScaleType} [y] - The y-coordinate of the end point.
25
+ * @param {ScaleType} [endX] - The x-coordinate of the end point.
26
+ * @param {ScaleType} [endY] - The y-coordinate of the end point.
30
27
  * @returns {this} The current instance for chaining.
31
28
  */
32
- setEndPosition(x, y) {
33
- this.props.endPoint = { x, y };
29
+ setPosition(x, y, endX, endY) {
30
+ this.props.position = { x, y, endX: endX || 0, endY: endY || 0 };
34
31
  return this;
35
32
  }
36
33
  /**
@@ -41,10 +38,10 @@ class LineLayer extends BaseLayer_1.BaseLayer {
41
38
  */
42
39
  setColor(color) {
43
40
  if (!color)
44
- throw new LazyUtil_1.LazyError('The color of the layer must be provided');
41
+ throw new utils_1.LazyError("The color of the layer must be provided");
45
42
  if (!(0, utils_1.isColor)(color))
46
- throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
47
- this.props.fillStyle = color;
43
+ throw new utils_1.LazyError("The color of the layer must be a valid color");
44
+ this.props.color = color;
48
45
  return this;
49
46
  }
50
47
  /**
@@ -60,8 +57,8 @@ class LineLayer extends BaseLayer_1.BaseLayer {
60
57
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
61
58
  this.props.stroke = {
62
59
  width,
63
- cap: cap || 'butt',
64
- join: join || 'miter',
60
+ cap: cap || "butt",
61
+ join: join || "miter",
65
62
  dash: dash || [],
66
63
  dashOffset: dashOffset || 0,
67
64
  miterLimit: miterLimit || 10,
@@ -72,16 +69,16 @@ class LineLayer extends BaseLayer_1.BaseLayer {
72
69
  * Calculates the bounding box of the line layer.
73
70
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
74
71
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
75
- * @param {LayersManager} [manager] - The layers manager.
72
+ * @param {LayersManager} [manager] - The layer's manager.
76
73
  * @returns {Object} The bounding box details including start and end points, width, and height.
77
74
  */
78
75
  getBoundingBox(ctx, canvas, manager) {
79
76
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
80
77
  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) },
78
+ xs: { v: this.props.position.x },
79
+ ys: { v: this.props.position.y, options: utils_1.defaultArg.vl(true) },
80
+ xe: { v: this.props.position.endX },
81
+ ye: { v: this.props.position.endY, options: utils_1.defaultArg.vl(true) },
85
82
  });
86
83
  let width = xe - xs;
87
84
  let height = ye - ys;
@@ -91,36 +88,36 @@ class LineLayer extends BaseLayer_1.BaseLayer {
91
88
  * Draws the line layer on the canvas.
92
89
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
93
90
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
94
- * @param {LayersManager} [manager] - The layers manager.
91
+ * @param {LayersManager} [manager] - The layer's manager.
95
92
  * @param {boolean} [debug] - Whether to enable debug logging.
96
93
  */
97
94
  async draw(ctx, canvas, manager, debug) {
98
95
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
99
96
  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) },
97
+ xs: { v: this.props.position.x },
98
+ ys: { v: this.props.position.y, options: utils_1.defaultArg.vl(true) },
99
+ xe: { v: this.props.position.endX },
100
+ ye: { v: this.props.position.endY, options: utils_1.defaultArg.vl(true) },
104
101
  });
105
102
  let width = Math.abs(xe - xs);
106
103
  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 });
104
+ let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, {
105
+ debug,
106
+ layer: { width, height, x: Math.min(xs, xe), y: Math.min(ys, ye), align: "none" },
107
+ manager,
108
+ });
108
109
  if (debug)
109
- LazyUtil_1.LazyLog.log('none', `LineLayer:`, { xs, ys, xe, ye, width, height });
110
+ utils_1.LazyLog.log("none", `LineLayer:`, { xs, ys, xe, ye, width, height });
110
111
  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);
112
+ if (this.props.transform) {
113
+ (0, utils_1.transform)(ctx, this.props.transform, { x: xs, y: ys, width, height, type: this.type });
114
+ }
115
+ utils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
116
+ utils_1.DrawUtils.opacity(ctx, this.props.opacity);
117
+ utils_1.DrawUtils.filters(ctx, this.props.filter);
118
+ utils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
115
119
  ctx.beginPath();
116
120
  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
121
  ctx.lineTo(xe, ye);
125
122
  ctx.stroke();
126
123
  ctx.closePath();
@@ -133,8 +130,8 @@ class LineLayer extends BaseLayer_1.BaseLayer {
133
130
  toJSON() {
134
131
  let data = super.toJSON();
135
132
  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]) {
133
+ for (const key of ["x", "y", "endPoint.x", "endPoint.y", "fillStyle"]) {
134
+ if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
138
135
  copy[key] = copy[key].toJSON();
139
136
  }
140
137
  }
@@ -148,17 +145,18 @@ class LineLayer extends BaseLayer_1.BaseLayer {
148
145
  validateProps(data) {
149
146
  return {
150
147
  ...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,
148
+ position: {
149
+ x: data.position?.x || 0,
150
+ y: data.position?.y || 0,
151
+ endX: data.position?.endX || 0,
152
+ endY: data.position?.endY || 0,
157
153
  },
154
+ color: data.color || "#000000",
155
+ centring: data.centring || types_1.Centring.None,
158
156
  stroke: {
159
157
  width: data.stroke?.width || 1,
160
- cap: data.stroke?.cap || 'butt',
161
- join: data.stroke?.join || 'miter',
158
+ cap: data.stroke?.cap || "butt",
159
+ join: data.stroke?.join || "miter",
162
160
  dashOffset: data.stroke?.dashOffset || 0,
163
161
  dash: data.stroke?.dash || [],
164
162
  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,47 +34,18 @@ 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
  */
48
- fillStyle: ColorType;
44
+ color: ColorType;
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.
@@ -122,7 +93,7 @@ export declare class MorphLayer extends BaseLayer<IMorphLayerProps> {
122
93
  * Draws the Morph Layer on the canvas.
123
94
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
124
95
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
125
- * @param {LayersManager} [manager] - The layers manager.
96
+ * @param {LayersManager} [manager] - The layer's manager.
126
97
  * @param {boolean} [debug] - Whether to enable debug logging.
127
98
  */
128
99
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
@@ -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,71 +61,71 @@ 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
  /**
79
73
  * Draws the Morph Layer on the canvas.
80
74
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
81
75
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
82
- * @param {LayersManager} [manager] - The layers manager.
76
+ * @param {LayersManager} [manager] - The layer's manager.
83
77
  * @param {boolean} [debug] - Whether to enable debug logging.
84
78
  */
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
  }