@nmmty/lazycanvas 0.4.0 → 0.5.0

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 (64) hide show
  1. package/dist/helpers/Filters.d.ts +10 -10
  2. package/dist/helpers/Fonts.d.ts +1 -1
  3. package/dist/helpers/FontsList.d.ts +1 -1
  4. package/dist/helpers/FontsList.js +19 -19
  5. package/dist/index.d.ts +11 -20
  6. package/dist/index.js +40 -47
  7. package/dist/structures/LazyCanvas.d.ts +126 -19
  8. package/dist/structures/LazyCanvas.js +100 -35
  9. package/dist/structures/components/BaseLayer.d.ts +188 -38
  10. package/dist/structures/components/BaseLayer.js +88 -41
  11. package/dist/structures/components/BezierLayer.d.ts +108 -21
  12. package/dist/structures/components/BezierLayer.js +73 -24
  13. package/dist/structures/components/ClearLayer.d.ts +120 -17
  14. package/dist/structures/components/ClearLayer.js +83 -22
  15. package/dist/structures/components/Group.d.ts +86 -18
  16. package/dist/structures/components/Group.js +69 -29
  17. package/dist/structures/components/ImageLayer.d.ts +85 -12
  18. package/dist/structures/components/ImageLayer.js +52 -39
  19. package/dist/structures/components/LineLayer.d.ts +111 -18
  20. package/dist/structures/components/LineLayer.js +58 -21
  21. package/dist/structures/components/MorphLayer.d.ts +109 -21
  22. package/dist/structures/components/MorphLayer.js +53 -25
  23. package/dist/structures/components/Path2DLayer.d.ts +191 -0
  24. package/dist/structures/components/Path2DLayer.js +318 -0
  25. package/dist/structures/components/QuadraticLayer.d.ts +108 -22
  26. package/dist/structures/components/QuadraticLayer.js +65 -30
  27. package/dist/structures/components/TextLayer.d.ts +201 -40
  28. package/dist/structures/components/TextLayer.js +99 -47
  29. package/dist/structures/components/index.d.ts +10 -0
  30. package/dist/structures/components/index.js +26 -0
  31. package/dist/structures/helpers/Exporter.d.ts +52 -0
  32. package/dist/structures/helpers/Exporter.js +168 -0
  33. package/dist/structures/helpers/Font.d.ts +64 -10
  34. package/dist/structures/helpers/Font.js +38 -11
  35. package/dist/structures/helpers/Gradient.d.ts +96 -9
  36. package/dist/structures/helpers/Gradient.js +48 -17
  37. package/dist/structures/helpers/Link.d.ts +52 -8
  38. package/dist/structures/helpers/Link.js +42 -11
  39. package/dist/structures/helpers/Pattern.d.ts +52 -7
  40. package/dist/structures/helpers/Pattern.js +45 -40
  41. package/dist/structures/helpers/index.d.ts +6 -0
  42. package/dist/structures/helpers/index.js +22 -0
  43. package/dist/structures/helpers/readers/JSONReader.d.ts +49 -0
  44. package/dist/structures/helpers/readers/JSONReader.js +172 -0
  45. package/dist/structures/helpers/readers/SVGReader.d.ts +20 -0
  46. package/dist/structures/helpers/readers/SVGReader.js +577 -0
  47. package/dist/structures/helpers/readers/YAMLReader.d.ts +0 -0
  48. package/dist/structures/helpers/readers/YAMLReader.js +1 -0
  49. package/dist/structures/managers/AnimationManager.d.ts +96 -20
  50. package/dist/structures/managers/AnimationManager.js +54 -26
  51. package/dist/structures/managers/FontsManager.d.ts +76 -32
  52. package/dist/structures/managers/FontsManager.js +70 -45
  53. package/dist/structures/managers/LayersManager.d.ts +84 -32
  54. package/dist/structures/managers/LayersManager.js +66 -28
  55. package/dist/structures/managers/RenderManager.d.ts +60 -6
  56. package/dist/structures/managers/RenderManager.js +120 -40
  57. package/dist/types/enum.d.ts +11 -6
  58. package/dist/types/enum.js +17 -12
  59. package/dist/types/index.d.ts +2 -19
  60. package/dist/types/index.js +17 -0
  61. package/dist/utils/LazyUtil.js +2 -2
  62. package/dist/utils/utils.d.ts +10 -9
  63. package/dist/utils/utils.js +159 -164
  64. package/package.json +4 -5
@@ -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
  }
@@ -2,21 +2,31 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TextLayer = 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 LazyUtil_1 = require("../../utils/LazyUtil");
7
- const Gradient_1 = require("../helpers/Gradient");
7
+ const helpers_1 = require("../helpers");
8
8
  const utils_1 = require("../../utils/utils");
9
- const Pattern_1 = require("../helpers/Pattern");
9
+ /**
10
+ * Class representing a Text Layer, extending the BaseLayer class.
11
+ */
10
12
  class TextLayer extends BaseLayer_1.BaseLayer {
13
+ /**
14
+ * The properties of the Text Layer.
15
+ */
11
16
  props;
12
- constructor(props) {
13
- super(enum_1.LayerType.Text, props || {});
17
+ /**
18
+ * Constructs a new TextLayer instance.
19
+ * @param props {ITextLayerProps} - The properties of the Text Layer.
20
+ * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
21
+ */
22
+ constructor(props, misc) {
23
+ super(types_1.LayerType.Text, props || {}, misc);
14
24
  this.props = props ? props : {};
15
- this.props.align = enum_1.TextAlign.Left;
25
+ this.props.align = types_1.TextAlign.Left;
16
26
  this.props.font = {
17
27
  family: 'Geist',
18
28
  size: 16,
19
- weight: enum_1.FontWeight.Regular,
29
+ weight: types_1.FontWeight.Regular,
20
30
  };
21
31
  this.props.fillStyle = '#ffffff';
22
32
  this.props.filled = true;
@@ -28,23 +38,26 @@ class TextLayer extends BaseLayer_1.BaseLayer {
28
38
  width: 'vw',
29
39
  height: 0,
30
40
  };
31
- this.props.centring = enum_1.Centring.Center;
41
+ this.props.centring = types_1.Centring.Center;
32
42
  this.props.wordSpacing = 0;
33
43
  this.props.letterSpacing = 0;
34
44
  }
35
45
  /**
36
- * @description Sets the text of the text layer.
37
- * @param text {string} - The `text` of the text layer.
46
+ * Sets the text of the text layer.
47
+ * @param text {string} - The text content of the layer.
48
+ * @returns {this} The current instance for chaining.
38
49
  */
39
50
  setText(text) {
40
51
  this.props.text = text;
41
52
  return this;
42
53
  }
43
54
  /**
44
- * @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.
45
- * @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.
46
- * @param size {number} - The `size` of the font.
47
- * @param weight {AnyWeight} - The `weight` of the font.
55
+ * Sets the font of the text layer.
56
+ * @param familyOrConfig {string | { family: string; size: number; weight: AnyWeight }} - The font family or configuration object.
57
+ * @param size {number} - The font size (required if `familyOrConfig` is a string).
58
+ * @param weight {AnyWeight} - The font weight (required if `familyOrConfig` is a string).
59
+ * @returns {this} The current instance for chaining.
60
+ * @throws {LazyError} If size or weight is not provided when `familyOrConfig` is a string.
48
61
  */
49
62
  setFont(familyOrConfig, size, weight) {
50
63
  if (typeof familyOrConfig === "string") {
@@ -68,11 +81,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
68
81
  return this;
69
82
  }
70
83
  /**
71
- * @description Set the multiline of the text layer. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
72
- * @param enabled {boolean} - Whether the text is multiline.
73
- * @param width {ScaleType} - width of "window" the multiline text. Can be used in one line text for text max width.
74
- * @param height {ScaleType} - height of "window" the multiline text.
75
- * @param spacing {number} - The space between the lines.
84
+ * Configures the multiline properties of the text layer.
85
+ * @param enabled {boolean} - Whether multiline is enabled.
86
+ * @param width {ScaleType} - The width of the multiline text area.
87
+ * @param height {ScaleType} - The height of the multiline text area.
88
+ * @param spacing {number} - The spacing between lines (optional).
89
+ * @returns {this} The current instance for chaining.
76
90
  */
77
91
  setMultiline(enabled, width, height, spacing) {
78
92
  this.props.multiline = {
@@ -86,8 +100,10 @@ class TextLayer extends BaseLayer_1.BaseLayer {
86
100
  return this;
87
101
  }
88
102
  /**
89
- * @description Sets the color of the layer. You can use `hex`, `rgb`, `rgba`, `hsl`, `hsla`, and `Gradient`color.
90
- * @param color {string} - The `color` of the layer.
103
+ * Sets the color of the text layer.
104
+ * @param color {ColorType} - The color of the text.
105
+ * @returns {this} The current instance for chaining.
106
+ * @throws {LazyError} If the color is not provided or invalid.
91
107
  */
92
108
  setColor(color) {
93
109
  if (!color)
@@ -95,7 +111,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
95
111
  if (!(0, utils_1.isColor)(color))
96
112
  throw new LazyUtil_1.LazyError('The color of the layer must be a valid color');
97
113
  let fill = (0, utils_1.parseColor)(color);
98
- if (fill instanceof Gradient_1.Gradient || fill instanceof Pattern_1.Pattern) {
114
+ if (fill instanceof helpers_1.Gradient || fill instanceof helpers_1.Pattern) {
99
115
  this.props.fillStyle = fill;
100
116
  }
101
117
  else {
@@ -106,37 +122,41 @@ class TextLayer extends BaseLayer_1.BaseLayer {
106
122
  return this;
107
123
  }
108
124
  /**
109
- * @description Set the align of the text layer.
110
- * @param align {AnyTextAlign} - The `align` of the text layer.
125
+ * Sets the alignment of the text layer.
126
+ * @param align {AnyTextAlign} - The alignment of the text.
127
+ * @returns {this} The current instance for chaining.
111
128
  */
112
129
  setAlign(align) {
113
130
  this.props.align = align;
114
131
  return this;
115
132
  }
116
133
  /**
117
- * @description Set the baseline of the text layer.
118
- * @param baseline {AnyTextBaseline} - The `baseline` of the text layer.
134
+ * Sets the baseline of the text layer.
135
+ * @param baseline {AnyTextBaseline} - The baseline of the text.
136
+ * @returns {this} The current instance for chaining.
119
137
  */
120
138
  setBaseline(baseline) {
121
139
  this.props.baseline = baseline;
122
140
  return this;
123
141
  }
124
142
  /**
125
- * @description Set the direction of the text layer.
126
- * @param direction {AnyTextDirection} - The `direction` of the text layer.
143
+ * Sets the direction of the text layer.
144
+ * @param direction {AnyTextDirection} - The direction of the text.
145
+ * @returns {this} The current instance for chaining.
127
146
  */
128
147
  setDirection(direction) {
129
148
  this.props.direction = direction;
130
149
  return this;
131
150
  }
132
151
  /**
133
- * @description Set the stroke of the layer.
134
- * @param width {number} - The `width` of the stroke.
135
- * @param cap {string} - The `cap` of the stroke.
136
- * @param join {string} - The `join` of the stroke.
137
- * @param dash {number[]} - The `dash` of the stroke.
138
- * @param dashOffset {number} - The `dashOffset` of the stroke.
139
- * @param miterLimit {number} - The `miterLimit` of the stroke.
152
+ * Configures the stroke properties of the text layer.
153
+ * @param width {number} - The width of the stroke.
154
+ * @param cap {string} - The cap style of the stroke (optional).
155
+ * @param join {string} - The join style of the stroke (optional).
156
+ * @param dash {number[]} - The dash pattern of the stroke (optional).
157
+ * @param dashOffset {number} - The dash offset of the stroke (optional).
158
+ * @param miterLimit {number} - The miter limit of the stroke (optional).
159
+ * @returns {this} The current instance for chaining.
140
160
  */
141
161
  setStroke(width, cap, join, dash, dashOffset, miterLimit) {
142
162
  this.props.stroke = {
@@ -150,29 +170,38 @@ class TextLayer extends BaseLayer_1.BaseLayer {
150
170
  return this;
151
171
  }
152
172
  /**
153
- * @description Sets the fills of the layer. If `true` the layer will be filled, if `false` the layer will be stroked.
154
- * @param filled {boolean} - The `filled` of the layer.
173
+ * Sets whether the text layer should be filled or stroked.
174
+ * @param filled {boolean} - If true, the layer will be filled; otherwise, it will be stroked.
175
+ * @returns {this} The current instance for chaining.
155
176
  */
156
177
  setFilled(filled) {
157
178
  this.props.filled = filled;
158
179
  return this;
159
180
  }
160
181
  /**
161
- * @description Sets the spacing between the words.
162
- * @param wordSpacing {number} - The `wordSpacing` of the text layer.
182
+ * Sets the spacing between words in the text layer.
183
+ * @param wordSpacing {number} - The spacing between words.
184
+ * @returns {this} The current instance for chaining.
163
185
  */
164
186
  setWordSpacing(wordSpacing) {
165
187
  this.props.wordSpacing = wordSpacing;
166
188
  return this;
167
189
  }
168
190
  /**
169
- * @description Sets the letter spacing.
170
- * @param letterSpacing {number} - The `letterSpacing` of the text layer.
191
+ * Sets the spacing between letters in the text layer.
192
+ * @param letterSpacing {number} - The spacing between letters.
193
+ * @returns {this} The current instance for chaining.
171
194
  */
172
195
  setLetterSpacing(letterSpacing) {
173
196
  this.props.letterSpacing = letterSpacing;
174
197
  return this;
175
198
  }
199
+ /**
200
+ * Measures the dimensions of the text.
201
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
202
+ * @param canvas {Canvas | SvgCanvas} - The canvas instance.
203
+ * @returns {Object} The width and height of the text.
204
+ */
176
205
  measureText(ctx, canvas) {
177
206
  const w = (0, utils_1.parseToNormal)(this.props.size?.width, ctx, canvas);
178
207
  const h = (0, utils_1.parseToNormal)(this.props.size?.height, ctx, canvas, { width: w, height: 0 }, { vertical: true });
@@ -185,6 +214,13 @@ class TextLayer extends BaseLayer_1.BaseLayer {
185
214
  return { width: data.width, height: this.props.font.size };
186
215
  }
187
216
  }
217
+ /**
218
+ * Draws the text layer on the canvas.
219
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
220
+ * @param canvas {Canvas | SvgCanvas} - The canvas instance.
221
+ * @param manager {LayersManager} - The layers manager.
222
+ * @param debug {boolean} - Whether to enable debug logging.
223
+ */
188
224
  async draw(ctx, canvas, manager, debug) {
189
225
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
190
226
  const { x, y, w } = parcer.parseBatch({
@@ -234,17 +270,27 @@ class TextLayer extends BaseLayer_1.BaseLayer {
234
270
  break;
235
271
  }
236
272
  for (let line of lines) {
237
- this.drawText(this.props, ctx, await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle), line.text, line.x, line.y, w, h);
273
+ this.drawText(this.props, ctx, await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle), line.text, line.x, line.y, w);
238
274
  }
239
275
  }
240
276
  else {
241
277
  ctx.font = `${this.props.font.weight} ${this.props.font.size}px ${this.props.font.family}`;
242
- this.drawText(this.props, ctx, await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle), this.props.text, x, y, w, h);
278
+ this.drawText(this.props, ctx, await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle), this.props.text, x, y, w);
243
279
  }
244
280
  ctx.closePath();
245
281
  ctx.restore();
246
282
  }
247
- drawText(props, ctx, fillStyle, text, x, y, w, h) {
283
+ /**
284
+ * Draws the text on the canvas.
285
+ * @param props {ITextLayerProps} - The properties of the text layer.
286
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
287
+ * @param fillStyle {string | CanvasGradient | CanvasPattern} - The fill style for the text.
288
+ * @param text {string} - The text content.
289
+ * @param x {number} - The x-coordinate of the text.
290
+ * @param y {number} - The y-coordinate of the text.
291
+ * @param w {number} - The width of the text area.
292
+ */
293
+ drawText(props, ctx, fillStyle, text, x, y, w) {
248
294
  if (props.filled) {
249
295
  ctx.fillStyle = fillStyle;
250
296
  ctx.fillText(text, x, y, w);
@@ -261,12 +307,18 @@ class TextLayer extends BaseLayer_1.BaseLayer {
261
307
  }
262
308
  }
263
309
  /**
264
- * @returns {ITextLayer}
310
+ * Converts the Text Layer to a JSON representation.
311
+ * @returns {ITextLayer} The JSON representation of the Text Layer.
265
312
  */
266
313
  toJSON() {
267
314
  let data = super.toJSON();
268
- data.props = this.props;
269
- return { ...data };
315
+ let copy = { ...this.props };
316
+ for (const key of ['x', 'y', 'size.width', 'size.height', 'fillStyle']) {
317
+ if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
318
+ copy[key] = copy[key].toJSON();
319
+ }
320
+ }
321
+ return { ...data, props: copy };
270
322
  }
271
323
  }
272
324
  exports.TextLayer = TextLayer;
@@ -0,0 +1,10 @@
1
+ export * from './BaseLayer';
2
+ export * from './BezierLayer';
3
+ export * from './ClearLayer';
4
+ export * from './ImageLayer';
5
+ export * from './TextLayer';
6
+ export * from './MorphLayer';
7
+ export * from './Group';
8
+ export * from './LineLayer';
9
+ export * from './QuadraticLayer';
10
+ export * from './Path2DLayer';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./BaseLayer"), exports);
18
+ __exportStar(require("./BezierLayer"), exports);
19
+ __exportStar(require("./ClearLayer"), exports);
20
+ __exportStar(require("./ImageLayer"), exports);
21
+ __exportStar(require("./TextLayer"), exports);
22
+ __exportStar(require("./MorphLayer"), exports);
23
+ __exportStar(require("./Group"), exports);
24
+ __exportStar(require("./LineLayer"), exports);
25
+ __exportStar(require("./QuadraticLayer"), exports);
26
+ __exportStar(require("./Path2DLayer"), exports);
@@ -0,0 +1,52 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { IOLazyCanvas, LazyCanvas } from "../LazyCanvas";
4
+ import { AnyExport } from "../../types";
5
+ import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
6
+ /**
7
+ * Class responsible for exporting a LazyCanvas instance to various formats.
8
+ */
9
+ export declare class Exporter {
10
+ /**
11
+ * The LazyCanvas instance to be exported.
12
+ */
13
+ canvas: LazyCanvas;
14
+ /**
15
+ * Constructs a new Exporter instance.
16
+ * @param canvas {LazyCanvas} - The LazyCanvas instance to be exported.
17
+ */
18
+ constructor(canvas: LazyCanvas);
19
+ /**
20
+ * Saves a file to the filesystem.
21
+ * @param buffer {any} - The data to be saved.
22
+ * @param extension {Extensions} - The file extension.
23
+ * @param name {string} - The name of the file (optional).
24
+ * @throws {LazyError} If the buffer or extension is not provided.
25
+ */
26
+ private saveFile;
27
+ /**
28
+ * Exports all layers from the LayersManager as an array of JSON objects.
29
+ * @param manager {LayersManager} - The LayersManager instance.
30
+ * @returns {any[]} An array of JSON representations of the layers.
31
+ */
32
+ private exportLayers;
33
+ /**
34
+ * Exports the canvas to the specified format.
35
+ * @param exportType {AnyExport} - The type of export (e.g., "png", "json").
36
+ * @param opts {Object} - Optional settings.
37
+ * @param opts.name {string} - The name of the file (optional).
38
+ * @param opts.saveAsFile {boolean} - Whether to save the export as a file (optional).
39
+ * @returns {Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>} The exported data.
40
+ * @throws {LazyError} If the export type is not supported.
41
+ */
42
+ export(exportType: AnyExport, opts?: {
43
+ name?: string;
44
+ saveAsFile?: boolean;
45
+ }): Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>;
46
+ /**
47
+ * Synchronously exports the canvas to the specified format.
48
+ * @param exportType {AnyExport} - The type of export (e.g., "json").
49
+ * @returns {IOLazyCanvas | void} The exported data or void if the export type is unsupported.
50
+ */
51
+ syncExport(exportType: AnyExport): IOLazyCanvas | void;
52
+ }