@nmmty/lazycanvas 0.6.4 → 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 +18 -39
  27. package/dist/structures/components/BezierLayer.js +85 -48
  28. package/dist/structures/components/{Group.d.ts → Div.d.ts} +26 -20
  29. package/dist/structures/components/{Group.js → Div.js} +39 -40
  30. package/dist/structures/components/ImageLayer.d.ts +2 -2
  31. package/dist/structures/components/ImageLayer.js +25 -26
  32. package/dist/structures/components/LineLayer.d.ts +13 -39
  33. package/dist/structures/components/LineLayer.js +44 -44
  34. package/dist/structures/components/MorphLayer.d.ts +4 -33
  35. package/dist/structures/components/MorphLayer.js +33 -47
  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 +95 -0
  39. package/dist/structures/components/PolygonLayer.js +205 -0
  40. package/dist/structures/components/QuadraticLayer.d.ts +27 -44
  41. package/dist/structures/components/QuadraticLayer.js +87 -49
  42. package/dist/structures/components/TextLayer.d.ts +16 -45
  43. package/dist/structures/components/TextLayer.js +66 -68
  44. package/dist/structures/components/index.d.ts +10 -10
  45. package/dist/structures/components/index.js +2 -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 +34 -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 +4 -3
  64. package/dist/types/enum.js +3 -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 +5 -9
  72. package/dist/utils/utils.js +148 -77
  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 -105
@@ -7,14 +7,11 @@ const canvas_1 = require("@napi-rs/canvas");
7
7
  const utils_1 = require("../../utils/utils");
8
8
  const LazyUtil_1 = require("../../utils/LazyUtil");
9
9
  const helpers_1 = require("../helpers");
10
+ const DrawUtils_1 = require("../../utils/DrawUtils");
10
11
  /**
11
12
  * Class representing an Image Layer, extending the BaseLayer class.
12
13
  */
13
14
  class ImageLayer extends BaseLayer_1.BaseLayer {
14
- /**
15
- * The properties of the Image Layer.
16
- */
17
- props;
18
15
  /**
19
16
  * Constructs a new ImageLayer instance.
20
17
  * @param {IImageLayerProps} [props] - The properties of the Image Layer.
@@ -33,7 +30,7 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
33
30
  */
34
31
  setSrc(src) {
35
32
  if (!(0, utils_1.isImageUrlValid)(src))
36
- throw new LazyUtil_1.LazyError('The src of the image must be a valid URL');
33
+ throw new LazyUtil_1.LazyError("The src of the image must be a valid URL");
37
34
  this.props.src = src;
38
35
  return this;
39
36
  }
@@ -56,45 +53,47 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
56
53
  * Draws the Image Layer on the canvas.
57
54
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
58
55
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
59
- * @param {LayersManager} [manager] - The layers manager.
56
+ * @param {LayersManager} [manager] - The layer's manager.
60
57
  * @param {boolean} [debug] - Whether to enable debug logging.
61
58
  * @throws {LazyError} If the image could not be loaded.
62
59
  */
63
60
  async draw(ctx, canvas, manager, debug) {
64
61
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
65
62
  const { xs, ys, w } = parcer.parseBatch({
66
- xs: { v: this.props.x },
67
- ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
68
- w: { v: this.props.size.width }
63
+ xs: { v: this.props.position.x },
64
+ ys: { v: this.props.position.y, options: LazyUtil_1.defaultArg.vl(true) },
65
+ w: { v: this.props.size.width },
69
66
  });
70
67
  const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
71
68
  let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
72
69
  const rad = {};
73
- if (typeof this.props.size.radius === 'object' && this.props.size.radius !== helpers_1.Link) {
70
+ if (typeof this.props.size.radius === "object" && this.props.size.radius !== helpers_1.Link) {
74
71
  for (const corner in this.props.size.radius) {
75
72
  // @ts-ignore
76
73
  rad[corner] = parcer.parse(this.props.size.radius[corner], LazyUtil_1.defaultArg.wh(w / 2, h / 2), LazyUtil_1.defaultArg.vl(false, true));
77
74
  }
78
75
  }
79
76
  if (debug)
80
- LazyUtil_1.LazyLog.log('none', `ImageLayer:`, { x, y, w, h, rad });
77
+ LazyUtil_1.LazyLog.log("none", `ImageLayer:`, { x, y, w, h, rad });
81
78
  ctx.save();
82
79
  let image = await (0, canvas_1.loadImage)(this.props.src);
83
80
  image.width = w;
84
81
  image.height = h;
85
82
  if (!image)
86
- throw new LazyUtil_1.LazyError('The image could not be loaded');
87
- (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
88
- (0, utils_1.drawShadow)(ctx, this.props.shadow);
89
- (0, utils_1.opacity)(ctx, this.props.opacity);
90
- (0, utils_1.filters)(ctx, this.props.filter);
83
+ throw new LazyUtil_1.LazyError("The image could not be loaded");
84
+ if (this.props.transform) {
85
+ (0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
86
+ }
87
+ DrawUtils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
88
+ DrawUtils_1.DrawUtils.opacity(ctx, this.props.opacity);
89
+ DrawUtils_1.DrawUtils.filters(ctx, this.props.filter);
91
90
  if (Object.keys(rad).length > 0) {
92
91
  ctx.beginPath();
93
- ctx.moveTo(x + (w / 2), y);
94
- ctx.arcTo(x + w, y, x + w, y + (h / 2), rad.rightTop || rad.all || 0);
95
- ctx.arcTo(x + w, y + h, x + (w / 2), y + h, rad.rightBottom || rad.all || 0);
96
- ctx.arcTo(x, y + h, x, y + (h / 2), rad.leftBottom || rad.all || 0);
97
- ctx.arcTo(x, y, x + (w / 2), y, rad.leftTop || rad.all || 0);
92
+ ctx.moveTo(x + w / 2, y);
93
+ ctx.arcTo(x + w, y, x + w, y + h / 2, rad.rightTop || rad.all || 0);
94
+ ctx.arcTo(x + w, y + h, x + w / 2, y + h, rad.rightBottom || rad.all || 0);
95
+ ctx.arcTo(x, y + h, x, y + h / 2, rad.leftBottom || rad.all || 0);
96
+ ctx.arcTo(x, y, x + w / 2, y, rad.leftTop || rad.all || 0);
98
97
  ctx.closePath();
99
98
  ctx.clip();
100
99
  ctx.drawImage(image, x, y, w, h);
@@ -111,8 +110,8 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
111
110
  toJSON() {
112
111
  let data = super.toJSON();
113
112
  let copy = { ...this.props };
114
- for (const key of ['x', 'y', 'size.width', 'size.height', 'size.radius']) {
115
- if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
113
+ for (const key of ["x", "y", "size.width", "size.height", "size.radius"]) {
114
+ if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
116
115
  copy[key] = copy[key].toJSON();
117
116
  }
118
117
  }
@@ -126,12 +125,12 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
126
125
  validateProps(data) {
127
126
  return {
128
127
  ...super.validateProps(data),
129
- src: data.src || '',
128
+ src: data.src || "",
130
129
  size: {
131
130
  width: data.size?.width || 0,
132
131
  height: data.size?.height || 0,
133
- radius: data.size?.radius || { all: 0 }
134
- }
132
+ radius: data.size?.radius || { all: 0 },
133
+ },
135
134
  };
136
135
  }
137
136
  }
@@ -1,5 +1,5 @@
1
1
  import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
- import { ColorType, ScaleType, LayerType } from "../../types";
2
+ import { ColorType, ScaleType, LayerType, StrokeOptions } from "../../types";
3
3
  import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
4
  import { LayersManager } from "../managers";
5
5
  /**
@@ -19,18 +19,15 @@ export interface ILineLayer extends IBaseLayer {
19
19
  * Interface representing the properties of a Line Layer.
20
20
  */
21
21
  export interface ILineLayerProps extends IBaseLayerProps {
22
- /**
23
- * The end point of the line, including x and y coordinates.
24
- */
25
- endPoint: {
22
+ position: IBaseLayerProps["position"] & {
26
23
  /**
27
- * The x-coordinate of the end point.
24
+ * The x-coordinate of the end point of the line.
28
25
  */
29
- x: ScaleType;
26
+ endX: ScaleType;
30
27
  /**
31
- * The y-coordinate of the end point.
28
+ * The y-coordinate of the end point of the line.
32
29
  */
33
- y: ScaleType;
30
+ endY: ScaleType;
34
31
  };
35
32
  /**
36
33
  * Whether the layer is filled.
@@ -43,32 +40,7 @@ export interface ILineLayerProps extends IBaseLayerProps {
43
40
  /**
44
41
  * The stroke properties of the line.
45
42
  */
46
- stroke: {
47
- /**
48
- * The width of the stroke.
49
- */
50
- width: number;
51
- /**
52
- * The cap style of the stroke.
53
- */
54
- cap: CanvasLineCap;
55
- /**
56
- * The join style of the stroke.
57
- */
58
- join: CanvasLineJoin;
59
- /**
60
- * The dash offset of the stroke.
61
- */
62
- dashOffset: number;
63
- /**
64
- * The dash pattern of the stroke.
65
- */
66
- dash: number[];
67
- /**
68
- * The miter limit of the stroke.
69
- */
70
- miterLimit: number;
71
- };
43
+ stroke: StrokeOptions;
72
44
  }
73
45
  /**
74
46
  * Class representing a Line Layer, extending the BaseLayer class.
@@ -85,12 +57,14 @@ export declare class LineLayer extends BaseLayer<ILineLayerProps> {
85
57
  */
86
58
  constructor(props?: ILineLayerProps, misc?: IBaseLayerMisc);
87
59
  /**
88
- * Sets the end position of the line layer.
60
+ * Sets the position of the line layer.
89
61
  * @param {ScaleType} [x] - The x-coordinate of the end point.
90
62
  * @param {ScaleType} [y] - The y-coordinate of the end point.
63
+ * @param {ScaleType} [endX] - The x-coordinate of the end point.
64
+ * @param {ScaleType} [endY] - The y-coordinate of the end point.
91
65
  * @returns {this} The current instance for chaining.
92
66
  */
93
- setEndPosition(x: ScaleType, y: ScaleType): this;
67
+ setPosition(x: ScaleType, y: ScaleType, endX?: ScaleType, endY?: ScaleType): this;
94
68
  /**
95
69
  * Sets the color of the line layer.
96
70
  * @param {ColorType} [color] - The color of the layer.
@@ -113,7 +87,7 @@ export declare class LineLayer extends BaseLayer<ILineLayerProps> {
113
87
  * Calculates the bounding box of the line layer.
114
88
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
115
89
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
116
- * @param {LayersManager} [manager] - The layers manager.
90
+ * @param {LayersManager} [manager] - The layer's manager.
117
91
  * @returns {Object} The bounding box details including start and end points, width, and height.
118
92
  */
119
93
  getBoundingBox(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager): {
@@ -128,7 +102,7 @@ export declare class LineLayer extends BaseLayer<ILineLayerProps> {
128
102
  * Draws the line layer on the canvas.
129
103
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
130
104
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
131
- * @param {LayersManager} [manager] - The layers manager.
105
+ * @param {LayersManager} [manager] - The layer's manager.
132
106
  * @param {boolean} [debug] - Whether to enable debug logging.
133
107
  */
134
108
  draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
@@ -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,
@@ -72,16 +71,16 @@ class LineLayer extends BaseLayer_1.BaseLayer {
72
71
  * Calculates the bounding box of the line layer.
73
72
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
74
73
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
75
- * @param {LayersManager} [manager] - The layers manager.
74
+ * @param {LayersManager} [manager] - The layer's manager.
76
75
  * @returns {Object} The bounding box details including start and end points, width, and height.
77
76
  */
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;
@@ -91,36 +90,36 @@ class LineLayer extends BaseLayer_1.BaseLayer {
91
90
  * Draws the line layer on the canvas.
92
91
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
93
92
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
94
- * @param {LayersManager} [manager] - The layers manager.
93
+ * @param {LayersManager} [manager] - The layer's manager.
95
94
  * @param {boolean} [debug] - Whether to enable debug logging.
96
95
  */
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.
@@ -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>;
@@ -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,71 +63,69 @@ 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
  /**
79
75
  * Draws the Morph Layer on the canvas.
80
76
  * @param {SKRSContext2D} [ctx] - The canvas rendering context.
81
77
  * @param {Canvas | SvgCanvas} [canvas] - The canvas instance.
82
- * @param {LayersManager} [manager] - The layers manager.
78
+ * @param {LayersManager} [manager] - The layer's manager.
83
79
  * @param {boolean} [debug] - Whether to enable debug logging.
84
80
  */
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
  }