@nmmty/lazycanvas 0.4.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/ReadMe.md +1 -0
  2. package/dist/helpers/Filters.d.ts +10 -10
  3. package/dist/helpers/Fonts.d.ts +1 -1
  4. package/dist/helpers/FontsList.d.ts +1 -1
  5. package/dist/helpers/FontsList.js +19 -19
  6. package/dist/index.d.ts +11 -20
  7. package/dist/index.js +40 -47
  8. package/dist/structures/LazyCanvas.d.ts +126 -19
  9. package/dist/structures/LazyCanvas.js +100 -35
  10. package/dist/structures/components/BaseLayer.d.ts +188 -38
  11. package/dist/structures/components/BaseLayer.js +89 -43
  12. package/dist/structures/components/BezierLayer.d.ts +111 -33
  13. package/dist/structures/components/BezierLayer.js +72 -32
  14. package/dist/structures/components/ClearLayer.d.ts +120 -17
  15. package/dist/structures/components/ClearLayer.js +83 -22
  16. package/dist/structures/components/Group.d.ts +88 -20
  17. package/dist/structures/components/Group.js +69 -29
  18. package/dist/structures/components/ImageLayer.d.ts +76 -12
  19. package/dist/structures/components/ImageLayer.js +43 -39
  20. package/dist/structures/components/LineLayer.d.ts +111 -18
  21. package/dist/structures/components/LineLayer.js +57 -29
  22. package/dist/structures/components/MorphLayer.d.ts +109 -21
  23. package/dist/structures/components/MorphLayer.js +52 -33
  24. package/dist/structures/components/Path2DLayer.d.ts +164 -0
  25. package/dist/structures/components/Path2DLayer.js +293 -0
  26. package/dist/structures/components/QuadraticLayer.d.ts +108 -22
  27. package/dist/structures/components/QuadraticLayer.js +64 -38
  28. package/dist/structures/components/TextLayer.d.ts +201 -40
  29. package/dist/structures/components/TextLayer.js +98 -55
  30. package/dist/structures/components/index.d.ts +10 -0
  31. package/dist/structures/components/index.js +26 -0
  32. package/dist/structures/helpers/Exporter.d.ts +52 -0
  33. package/dist/structures/helpers/Exporter.js +168 -0
  34. package/dist/structures/helpers/Font.d.ts +64 -10
  35. package/dist/structures/helpers/Font.js +38 -11
  36. package/dist/structures/helpers/Gradient.d.ts +96 -9
  37. package/dist/structures/helpers/Gradient.js +49 -19
  38. package/dist/structures/helpers/Link.d.ts +52 -8
  39. package/dist/structures/helpers/Link.js +42 -11
  40. package/dist/structures/helpers/Pattern.d.ts +52 -7
  41. package/dist/structures/helpers/Pattern.js +48 -42
  42. package/dist/structures/helpers/index.d.ts +6 -0
  43. package/dist/structures/helpers/index.js +22 -0
  44. package/dist/structures/helpers/readers/JSONReader.d.ts +49 -0
  45. package/dist/structures/helpers/readers/JSONReader.js +172 -0
  46. package/dist/structures/helpers/readers/SVGReader.d.ts +20 -0
  47. package/dist/structures/helpers/readers/SVGReader.js +577 -0
  48. package/dist/structures/helpers/readers/YAMLReader.d.ts +0 -0
  49. package/dist/structures/helpers/readers/YAMLReader.js +1 -0
  50. package/dist/structures/managers/AnimationManager.d.ts +96 -20
  51. package/dist/structures/managers/AnimationManager.js +54 -26
  52. package/dist/structures/managers/FontsManager.d.ts +76 -32
  53. package/dist/structures/managers/FontsManager.js +70 -45
  54. package/dist/structures/managers/LayersManager.d.ts +84 -32
  55. package/dist/structures/managers/LayersManager.js +66 -28
  56. package/dist/structures/managers/RenderManager.d.ts +60 -6
  57. package/dist/structures/managers/RenderManager.js +120 -40
  58. package/dist/types/enum.d.ts +11 -6
  59. package/dist/types/enum.js +17 -12
  60. package/dist/types/index.d.ts +2 -19
  61. package/dist/types/index.js +17 -0
  62. package/dist/utils/LazyUtil.js +2 -2
  63. package/dist/utils/utils.d.ts +9 -11
  64. package/dist/utils/utils.js +163 -234
  65. package/package.json +4 -5
@@ -1,38 +1,116 @@
1
- import { BaseLayer } from "./BaseLayer";
2
- import { IQuadraticLayerProps, IQuadraticLayer, ColorType, ScaleType } from "../../types";
3
- import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
1
+ import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
+ import { ColorType, ScaleType, Point, LayerType } from "../../types";
3
+ import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
4
  import { LayersManager } from "../managers/LayersManager";
5
+ /**
6
+ * Interface representing a Quadratic Layer.
7
+ */
8
+ export interface IQuadraticLayer extends IBaseLayer {
9
+ /**
10
+ * The type of the layer, which is `QuadraticCurve`.
11
+ */
12
+ type: LayerType.QuadraticCurve;
13
+ /**
14
+ * The properties specific to the Quadratic Layer.
15
+ */
16
+ props: IQuadraticLayerProps;
17
+ }
18
+ /**
19
+ * Interface representing the properties of a Quadratic Layer.
20
+ */
21
+ export interface IQuadraticLayerProps extends IBaseLayerProps {
22
+ /**
23
+ * The control point of the quadratic curve, including x and y coordinates.
24
+ */
25
+ controlPoints: Array<Point>;
26
+ /**
27
+ * The end point of the quadratic curve, including x and y coordinates.
28
+ */
29
+ endPoint: Point;
30
+ /**
31
+ * The stroke properties of the quadratic curve.
32
+ */
33
+ stroke: {
34
+ /**
35
+ * The width of the stroke.
36
+ */
37
+ width: number;
38
+ /**
39
+ * The cap style of the stroke.
40
+ */
41
+ cap: CanvasLineCap;
42
+ /**
43
+ * The join style of the stroke.
44
+ */
45
+ join: CanvasLineJoin;
46
+ /**
47
+ * The dash offset of the stroke.
48
+ */
49
+ dashOffset: number;
50
+ /**
51
+ * The dash pattern of the stroke.
52
+ */
53
+ dash: number[];
54
+ /**
55
+ * The miter limit of the stroke.
56
+ */
57
+ miterLimit: number;
58
+ };
59
+ }
60
+ /**
61
+ * Class representing a Quadratic Layer, extending the BaseLayer class.
62
+ */
5
63
  export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
64
+ /**
65
+ * The properties of the Quadratic Layer.
66
+ */
6
67
  props: IQuadraticLayerProps;
7
- constructor(props?: IQuadraticLayerProps);
8
68
  /**
9
- * @description Sets the control point of the quadratic layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
10
- * @param x {ScaleType} - The control `x` of the quadratic layer.
11
- * @param y {ScaleType} - The control `y` of the quadratic layer.
69
+ * Constructs a new QuadraticLayer instance.
70
+ * @param props {IQuadraticLayerProps} - The properties of the Quadratic Layer.
71
+ * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
72
+ */
73
+ constructor(props?: IQuadraticLayerProps, misc?: IBaseLayerMisc);
74
+ /**
75
+ * Sets the control point of the quadratic layer.
76
+ * @param x {ScaleType} - The x-coordinate of the control point.
77
+ * @param y {ScaleType} - The y-coordinate of the control point.
78
+ * @returns {this} The current instance for chaining.
12
79
  */
13
80
  setControlPoint(x: ScaleType, y: ScaleType): this;
14
81
  /**
15
- * @description Sets the end point of the quadratic layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
16
- * @param x {ScaleType} - The end `x` of the quadratic layer.
17
- * @param y {ScaleType} - The end `y` of the quadratic layer.
82
+ * Sets the end point of the quadratic layer.
83
+ * @param x {ScaleType} - The x-coordinate of the end point.
84
+ * @param y {ScaleType} - The y-coordinate of the end point.
85
+ * @returns {this} The current instance for chaining.
18
86
  */
19
87
  setEndPosition(x: ScaleType, y: ScaleType): this;
20
88
  /**
21
- * @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
22
- * @param color {string} - The `color` of the layer.
89
+ * Sets the color of the layer.
90
+ * @param color {ColorType} - The color of the layer.
91
+ * @returns {this} The current instance for chaining.
92
+ * @throws {LazyError} If the color is not provided or invalid.
23
93
  */
24
94
  setColor(color: ColorType): this;
25
95
  /**
26
- * @description Sets the stroke of the layer.
27
- * @param width {number} - The `width` of the stroke.
28
- * @param cap {string} - The `cap` of the stroke.
29
- * @param join {string} - The `join` of the stroke.
30
- * @param dash {number[]} - The `dash` of the stroke.
31
- * @param dashOffset {number} - The `dashOffset` of the stroke.
32
- * @param miterLimit {number} - The `miterLimit` of the stroke.
96
+ * Sets the stroke properties of the layer.
97
+ * @param width {number} - The width of the stroke.
98
+ * @param cap {CanvasLineCap} - The cap style of the stroke.
99
+ * @param join {CanvasLineJoin} - The join style of the stroke.
100
+ * @param dash {number[]} - The dash pattern of the stroke.
101
+ * @param dashOffset {number} - The dash offset of the stroke.
102
+ * @param miterLimit {number} - The miter limit of the stroke.
103
+ * @returns {this} The current instance for chaining.
33
104
  */
34
105
  setStroke(width: number, cap?: CanvasLineCap, join?: CanvasLineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
35
- getBoundingBox(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager): {
106
+ /**
107
+ * Calculates the bounding box of the quadratic curve.
108
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
109
+ * @param canvas {Canvas | SvgCanvas} - The canvas instance.
110
+ * @param manager {LayersManager} - The layers manager.
111
+ * @returns {Object} The bounding box details including max, min, center, width, and height.
112
+ */
113
+ getBoundingBox(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager): {
36
114
  max: {
37
115
  x: number;
38
116
  y: number;
@@ -48,9 +126,17 @@ export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
48
126
  width: number;
49
127
  height: number;
50
128
  };
51
- draw(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager, debug: boolean): Promise<void>;
52
129
  /**
53
- * @returns {IQuadraticLayer}
130
+ * Draws the quadratic curve on the canvas.
131
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
132
+ * @param canvas {Canvas | SvgCanvas} - The canvas instance.
133
+ * @param manager {LayersManager} - The layers manager.
134
+ * @param debug {boolean} - Whether to enable debug logging.
135
+ */
136
+ draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
137
+ /**
138
+ * Converts the Quadratic Layer to a JSON representation.
139
+ * @returns {IQuadraticLayer} The JSON representation of the Quadratic Layer.
54
140
  */
55
141
  toJSON(): IQuadraticLayer;
56
142
  }
@@ -2,66 +2,72 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.QuadraticLayer = void 0;
4
4
  const BaseLayer_1 = require("./BaseLayer");
5
- const enum_1 = require("../../types/enum");
5
+ const types_1 = require("../../types");
6
6
  const utils_1 = require("../../utils/utils");
7
7
  const LazyUtil_1 = require("../../utils/LazyUtil");
8
- const Gradient_1 = require("../helpers/Gradient");
9
- const Pattern_1 = require("../helpers/Pattern");
8
+ /**
9
+ * Class representing a Quadratic Layer, extending the BaseLayer class.
10
+ */
10
11
  class QuadraticLayer extends BaseLayer_1.BaseLayer {
12
+ /**
13
+ * The properties of the Quadratic Layer.
14
+ */
11
15
  props;
12
- constructor(props) {
13
- super(enum_1.LayerType.QuadraticCurve, props || {});
16
+ /**
17
+ * Constructs a new QuadraticLayer instance.
18
+ * @param props {IQuadraticLayerProps} - The properties of the Quadratic Layer.
19
+ * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
20
+ */
21
+ constructor(props, misc) {
22
+ super(types_1.LayerType.QuadraticCurve, props || {}, misc);
14
23
  this.props = props ? props : {};
15
24
  if (!this.props.fillStyle)
16
25
  this.props.fillStyle = '#000000';
17
- this.props.centring = enum_1.Centring.None;
26
+ this.props.centring = types_1.Centring.None;
18
27
  }
19
28
  /**
20
- * @description Sets the control point of the quadratic layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
21
- * @param x {ScaleType} - The control `x` of the quadratic layer.
22
- * @param y {ScaleType} - The control `y` of the quadratic layer.
29
+ * Sets the control point of the quadratic layer.
30
+ * @param x {ScaleType} - The x-coordinate of the control point.
31
+ * @param y {ScaleType} - The y-coordinate of the control point.
32
+ * @returns {this} The current instance for chaining.
23
33
  */
24
34
  setControlPoint(x, y) {
25
- this.props.controlPoint = { x, y };
35
+ this.props.controlPoints = [{ x, y }];
26
36
  return this;
27
37
  }
28
38
  /**
29
- * @description Sets the end point of the quadratic layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
30
- * @param x {ScaleType} - The end `x` of the quadratic layer.
31
- * @param y {ScaleType} - The end `y` of the quadratic layer.
39
+ * Sets the end point of the quadratic layer.
40
+ * @param x {ScaleType} - The x-coordinate of the end point.
41
+ * @param y {ScaleType} - The y-coordinate of the end point.
42
+ * @returns {this} The current instance for chaining.
32
43
  */
33
44
  setEndPosition(x, y) {
34
45
  this.props.endPoint = { x, y };
35
46
  return this;
36
47
  }
37
48
  /**
38
- * @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
39
- * @param color {string} - The `color` of the layer.
49
+ * Sets the color of the layer.
50
+ * @param color {ColorType} - The color of the layer.
51
+ * @returns {this} The current instance for chaining.
52
+ * @throws {LazyError} If the color is not provided or invalid.
40
53
  */
41
54
  setColor(color) {
42
55
  if (!color)
43
56
  throw new LazyUtil_1.LazyError('The color of the layer must be provided');
44
57
  if (!(0, utils_1.isColor)(color))
45
58
  throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
46
- let fill = (0, utils_1.parseColor)(color);
47
- if (fill instanceof Gradient_1.Gradient || fill instanceof Pattern_1.Pattern) {
48
- this.props.fillStyle = fill;
49
- }
50
- else {
51
- let arr = fill.split(':');
52
- this.props.fillStyle = arr[0];
53
- this.props.opacity = parseFloat(arr[1]) || 1;
54
- }
59
+ this.props.fillStyle = color;
55
60
  return this;
56
61
  }
57
62
  /**
58
- * @description Sets the stroke of the layer.
59
- * @param width {number} - The `width` of the stroke.
60
- * @param cap {string} - The `cap` of the stroke.
61
- * @param join {string} - The `join` of the stroke.
62
- * @param dash {number[]} - The `dash` of the stroke.
63
- * @param dashOffset {number} - The `dashOffset` of the stroke.
64
- * @param miterLimit {number} - The `miterLimit` of the stroke.
63
+ * Sets the stroke properties of the layer.
64
+ * @param width {number} - The width of the stroke.
65
+ * @param cap {CanvasLineCap} - The cap style of the stroke.
66
+ * @param join {CanvasLineJoin} - The join style of the stroke.
67
+ * @param dash {number[]} - The dash pattern of the stroke.
68
+ * @param dashOffset {number} - The dash offset of the stroke.
69
+ * @param miterLimit {number} - The miter limit of the stroke.
70
+ * @returns {this} The current instance for chaining.
65
71
  */
66
72
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
67
73
  this.props.stroke = {
@@ -74,26 +80,40 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
74
80
  };
75
81
  return this;
76
82
  }
83
+ /**
84
+ * Calculates the bounding box of the quadratic curve.
85
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
86
+ * @param canvas {Canvas | SvgCanvas} - The canvas instance.
87
+ * @param manager {LayersManager} - The layers manager.
88
+ * @returns {Object} The bounding box details including max, min, center, width, and height.
89
+ */
77
90
  getBoundingBox(ctx, canvas, manager) {
78
91
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
79
92
  const { xs, ys, cx, cy, xe, ye } = parcer.parseBatch({
80
93
  xs: { v: this.props.x },
81
94
  ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
82
- cx: { v: this.props.controlPoint.x },
83
- cy: { v: this.props.controlPoint.y, options: LazyUtil_1.defaultArg.vl(true) },
95
+ cx: { v: this.props.controlPoints[0].x },
96
+ cy: { v: this.props.controlPoints[0].y, options: LazyUtil_1.defaultArg.vl(true) },
84
97
  xe: { v: this.props.endPoint.x },
85
98
  ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
86
99
  });
87
100
  const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cx, y: cy }, { x: xe, y: ye }]);
88
101
  return { max, min, center, width, height };
89
102
  }
103
+ /**
104
+ * Draws the quadratic curve on the canvas.
105
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
106
+ * @param canvas {Canvas | SvgCanvas} - The canvas instance.
107
+ * @param manager {LayersManager} - The layers manager.
108
+ * @param debug {boolean} - Whether to enable debug logging.
109
+ */
90
110
  async draw(ctx, canvas, manager, debug) {
91
111
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
92
112
  const { xs, ys, cx, cy, xe, ye } = parcer.parseBatch({
93
113
  xs: { v: this.props.x },
94
114
  ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
95
- cx: { v: this.props.controlPoint.x },
96
- cy: { v: this.props.controlPoint.y, options: LazyUtil_1.defaultArg.vl(true) },
115
+ cx: { v: this.props.controlPoints[0].x },
116
+ cy: { v: this.props.controlPoints[0].y, options: LazyUtil_1.defaultArg.vl(true) },
97
117
  xe: { v: this.props.endPoint.x },
98
118
  ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
99
119
  });
@@ -121,12 +141,18 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
121
141
  ctx.restore();
122
142
  }
123
143
  /**
124
- * @returns {IQuadraticLayer}
144
+ * Converts the Quadratic Layer to a JSON representation.
145
+ * @returns {IQuadraticLayer} The JSON representation of the Quadratic Layer.
125
146
  */
126
147
  toJSON() {
127
148
  let data = super.toJSON();
128
- data.props = this.props;
129
- return { ...data };
149
+ let copy = { ...this.props };
150
+ for (const key of ['x', 'y', 'endPoint.x', 'endPoint.y', 'controlPoint.x', 'controlPoint.y', 'fillStyle']) {
151
+ if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
152
+ copy[key] = copy[key].toJSON();
153
+ }
154
+ }
155
+ return { ...data, props: copy };
130
156
  }
131
157
  }
132
158
  exports.QuadraticLayer = QuadraticLayer;
@@ -1,21 +1,148 @@
1
- import { BaseLayer } from "./BaseLayer";
2
- import { LineCap, LineJoin } from "../../types/enum";
3
- import { ITextLayer, ITextLayerProps, ScaleType, ColorType, AnyWeight, AnyTextAlign, AnyTextBaseline, AnyTextDirection } from "../../types";
4
- import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
1
+ import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
2
+ import { ScaleType, ColorType, AnyWeight, AnyTextAlign, AnyTextBaseline, AnyTextDirection, LineCap, LineJoin, LayerType } from "../../types";
3
+ import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
5
4
  import { LayersManager } from "../managers/LayersManager";
5
+ /**
6
+ * Interface representing a Text Layer.
7
+ */
8
+ export interface ITextLayer extends IBaseLayer {
9
+ /**
10
+ * The type of the layer, which is `Text`.
11
+ */
12
+ type: LayerType.Text;
13
+ /**
14
+ * The properties specific to the Text Layer.
15
+ */
16
+ props: ITextLayerProps;
17
+ }
18
+ /**
19
+ * Interface representing the properties of a Text Layer.
20
+ */
21
+ export interface ITextLayerProps extends IBaseLayerProps {
22
+ /**
23
+ * The text content of the layer.
24
+ */
25
+ text: string;
26
+ /**
27
+ * The font configuration for the text.
28
+ */
29
+ font: {
30
+ /**
31
+ * The font family.
32
+ */
33
+ family: string;
34
+ /**
35
+ * The font size.
36
+ */
37
+ size: number;
38
+ /**
39
+ * The font weight.
40
+ */
41
+ weight: AnyWeight;
42
+ };
43
+ /**
44
+ * Configuration for multiline text.
45
+ */
46
+ multiline: {
47
+ /**
48
+ * Whether multiline is enabled.
49
+ */
50
+ enabled: boolean;
51
+ /**
52
+ * The spacing between lines (optional).
53
+ */
54
+ spacing?: number;
55
+ };
56
+ /**
57
+ * The size of the text layer, including width and height.
58
+ */
59
+ size: {
60
+ /**
61
+ * The width of the text layer.
62
+ */
63
+ width: ScaleType;
64
+ /**
65
+ * The height of the text layer.
66
+ */
67
+ height: ScaleType;
68
+ };
69
+ /**
70
+ * The alignment of the text.
71
+ */
72
+ align: AnyTextAlign;
73
+ /**
74
+ * The baseline of the text.
75
+ */
76
+ baseline: AnyTextBaseline;
77
+ /**
78
+ * The direction of the text.
79
+ */
80
+ direction: AnyTextDirection;
81
+ /**
82
+ * The spacing between letters.
83
+ */
84
+ letterSpacing: number;
85
+ /**
86
+ * The spacing between words.
87
+ */
88
+ wordSpacing: number;
89
+ /**
90
+ * The stroke properties of the text.
91
+ */
92
+ stroke: {
93
+ /**
94
+ * The width of the stroke.
95
+ */
96
+ width: number;
97
+ /**
98
+ * The cap style of the stroke.
99
+ */
100
+ cap: CanvasLineCap;
101
+ /**
102
+ * The join style of the stroke.
103
+ */
104
+ join: CanvasLineJoin;
105
+ /**
106
+ * The dash offset of the stroke.
107
+ */
108
+ dashOffset: number;
109
+ /**
110
+ * The dash pattern of the stroke.
111
+ */
112
+ dash: number[];
113
+ /**
114
+ * The miter limit of the stroke.
115
+ */
116
+ miterLimit: number;
117
+ };
118
+ }
119
+ /**
120
+ * Class representing a Text Layer, extending the BaseLayer class.
121
+ */
6
122
  export declare class TextLayer extends BaseLayer<ITextLayerProps> {
123
+ /**
124
+ * The properties of the Text Layer.
125
+ */
7
126
  props: ITextLayerProps;
8
- constructor(props?: ITextLayerProps);
9
127
  /**
10
- * @description Sets the text of the text layer.
11
- * @param text {string} - The `text` of the text layer.
128
+ * Constructs a new TextLayer instance.
129
+ * @param props {ITextLayerProps} - The properties of the Text Layer.
130
+ * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
131
+ */
132
+ constructor(props?: ITextLayerProps, misc?: IBaseLayerMisc);
133
+ /**
134
+ * Sets the text of the text layer.
135
+ * @param text {string} - The text content of the layer.
136
+ * @returns {this} The current instance for chaining.
12
137
  */
13
138
  setText(text: string): this;
14
139
  /**
15
- * @description Set the font of the text layer. You can use `Geist` and `GeistMono`, or you can upload your own font from file/base64 buffer.
16
- * @param familyOrConfig {string | { font: string; size: number; weight: AnyWeight }} - The `family` of the font. If you want to use FontsList, you can use the object config.
17
- * @param size {number} - The `size` of the font.
18
- * @param weight {AnyWeight} - The `weight` of the font.
140
+ * Sets the font of the text layer.
141
+ * @param familyOrConfig {string | { family: string; size: number; weight: AnyWeight }} - The font family or configuration object.
142
+ * @param size {number} - The font size (required if `familyOrConfig` is a string).
143
+ * @param weight {AnyWeight} - The font weight (required if `familyOrConfig` is a string).
144
+ * @returns {this} The current instance for chaining.
145
+ * @throws {LazyError} If size or weight is not provided when `familyOrConfig` is a string.
19
146
  */
20
147
  setFont(familyOrConfig: string | {
21
148
  family: string;
@@ -23,66 +150,100 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
23
150
  weight: AnyWeight;
24
151
  }, size?: number, weight?: AnyWeight): this;
25
152
  /**
26
- * @description Set the multiline of the text layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
27
- * @param enabled {boolean} - Whether the text is multiline.
28
- * @param width {ScaleType} - width of "window" the multiline text. Can be used in one line text for text max width.
29
- * @param height {ScaleType} - height of "window" the multiline text.
30
- * @param spacing {number} - The space between the lines.
153
+ * Configures the multiline properties of the text layer.
154
+ * @param enabled {boolean} - Whether multiline is enabled.
155
+ * @param width {ScaleType} - The width of the multiline text area.
156
+ * @param height {ScaleType} - The height of the multiline text area.
157
+ * @param spacing {number} - The spacing between lines (optional).
158
+ * @returns {this} The current instance for chaining.
31
159
  */
32
160
  setMultiline(enabled: boolean, width: ScaleType, height: ScaleType, spacing?: number): this;
33
161
  /**
34
- * @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
35
- * @param color {string} - The `color` of the layer.
162
+ * Sets the color of the text layer.
163
+ * @param color {ColorType} - The color of the text.
164
+ * @returns {this} The current instance for chaining.
165
+ * @throws {LazyError} If the color is not provided or invalid.
36
166
  */
37
167
  setColor(color: ColorType): this;
38
168
  /**
39
- * @description Set the align of the text layer.
40
- * @param align {AnyTextAlign} - The `align` of the text layer.
169
+ * Sets the alignment of the text layer.
170
+ * @param align {AnyTextAlign} - The alignment of the text.
171
+ * @returns {this} The current instance for chaining.
41
172
  */
42
173
  setAlign(align: AnyTextAlign): this;
43
174
  /**
44
- * @description Set the baseline of the text layer.
45
- * @param baseline {AnyTextBaseline} - The `baseline` of the text layer.
175
+ * Sets the baseline of the text layer.
176
+ * @param baseline {AnyTextBaseline} - The baseline of the text.
177
+ * @returns {this} The current instance for chaining.
46
178
  */
47
179
  setBaseline(baseline: AnyTextBaseline): this;
48
180
  /**
49
- * @description Set the direction of the text layer.
50
- * @param direction {AnyTextDirection} - The `direction` of the text layer.
181
+ * Sets the direction of the text layer.
182
+ * @param direction {AnyTextDirection} - The direction of the text.
183
+ * @returns {this} The current instance for chaining.
51
184
  */
52
185
  setDirection(direction: AnyTextDirection): this;
53
186
  /**
54
- * @description Set the stroke of the layer.
55
- * @param width {number} - The `width` of the stroke.
56
- * @param cap {string} - The `cap` of the stroke.
57
- * @param join {string} - The `join` of the stroke.
58
- * @param dash {number[]} - The `dash` of the stroke.
59
- * @param dashOffset {number} - The `dashOffset` of the stroke.
60
- * @param miterLimit {number} - The `miterLimit` of the stroke.
187
+ * Configures the stroke properties of the text layer.
188
+ * @param width {number} - The width of the stroke.
189
+ * @param cap {string} - The cap style of the stroke (optional).
190
+ * @param join {string} - The join style of the stroke (optional).
191
+ * @param dash {number[]} - The dash pattern of the stroke (optional).
192
+ * @param dashOffset {number} - The dash offset of the stroke (optional).
193
+ * @param miterLimit {number} - The miter limit of the stroke (optional).
194
+ * @returns {this} The current instance for chaining.
61
195
  */
62
196
  setStroke(width: number, cap?: LineCap, join?: LineJoin, dash?: number[], dashOffset?: number, miterLimit?: number): this;
63
197
  /**
64
- * @description Sets the fills of the layer. If `true` the layer will be filled, if `false` the layer will be stroked.
65
- * @param filled {boolean} - The `filled` of the layer.
198
+ * Sets whether the text layer should be filled or stroked.
199
+ * @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
200
+ * @returns {this} The current instance for chaining.
66
201
  */
67
202
  setFilled(filled: boolean): this;
68
203
  /**
69
- * @description Sets the spacing between the words.
70
- * @param wordSpacing {number} - The `wordSpacing` of the text layer.
204
+ * Sets the spacing between words in the text layer.
205
+ * @param wordSpacing {number} - The spacing between words.
206
+ * @returns {this} The current instance for chaining.
71
207
  */
72
208
  setWordSpacing(wordSpacing: number): this;
73
209
  /**
74
- * @description Sets the letter spacing.
75
- * @param letterSpacing {number} - The `letterSpacing` of the text layer.
210
+ * Sets the spacing between letters in the text layer.
211
+ * @param letterSpacing {number} - The spacing between letters.
212
+ * @returns {this} The current instance for chaining.
76
213
  */
77
214
  setLetterSpacing(letterSpacing: number): this;
78
- measureText(ctx: SKRSContext2D, canvas: Canvas): {
215
+ /**
216
+ * Measures the dimensions of the text.
217
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
218
+ * @param canvas {Canvas | SvgCanvas} - The canvas instance.
219
+ * @returns {Object} The width and height of the text.
220
+ */
221
+ measureText(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas): {
79
222
  width: number;
80
223
  height: number;
81
224
  };
82
- draw(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager, debug: boolean): Promise<void>;
225
+ /**
226
+ * Draws the text layer on the canvas.
227
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
228
+ * @param canvas {Canvas | SvgCanvas} - The canvas instance.
229
+ * @param manager {LayersManager} - The layers manager.
230
+ * @param debug {boolean} - Whether to enable debug logging.
231
+ */
232
+ draw(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, manager: LayersManager, debug: boolean): Promise<void>;
233
+ /**
234
+ * Draws the text on the canvas.
235
+ * @param props {ITextLayerProps} - The properties of the text layer.
236
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
237
+ * @param fillStyle {string | CanvasGradient | CanvasPattern} - The fill style for the text.
238
+ * @param text {string} - The text content.
239
+ * @param x {number} - The x-coordinate of the text.
240
+ * @param y {number} - The y-coordinate of the text.
241
+ * @param w {number} - The width of the text area.
242
+ */
83
243
  private drawText;
84
244
  /**
85
- * @returns {ITextLayer}
245
+ * Converts the Text Layer to a JSON representation.
246
+ * @returns {ITextLayer} The JSON representation of the Text Layer.
86
247
  */
87
248
  toJSON(): ITextLayer;
88
249
  }