@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
@@ -0,0 +1,168 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.Exporter = void 0;
27
+ const types_1 = require("../../types");
28
+ const LazyUtil_1 = require("../../utils/LazyUtil");
29
+ const fs = __importStar(require("fs"));
30
+ const utils_1 = require("../../utils/utils");
31
+ const _yaml = __importStar(require("js-yaml"));
32
+ /**
33
+ * Class responsible for exporting a LazyCanvas instance to various formats.
34
+ */
35
+ class Exporter {
36
+ /**
37
+ * The LazyCanvas instance to be exported.
38
+ */
39
+ canvas;
40
+ /**
41
+ * Constructs a new Exporter instance.
42
+ * @param canvas {LazyCanvas} - The LazyCanvas instance to be exported.
43
+ */
44
+ constructor(canvas) {
45
+ this.canvas = canvas;
46
+ }
47
+ /**
48
+ * Saves a file to the filesystem.
49
+ * @param buffer {any} - The data to be saved.
50
+ * @param extension {Extensions} - The file extension.
51
+ * @param name {string} - The name of the file (optional).
52
+ * @throws {LazyError} If the buffer or extension is not provided.
53
+ */
54
+ async saveFile(buffer, extension, name) {
55
+ if (!buffer)
56
+ throw new LazyUtil_1.LazyError('Buffer must be provided');
57
+ if (!extension)
58
+ throw new LazyUtil_1.LazyError('Extension must be provided');
59
+ fs.writeFileSync(`${name === undefined ? (0, utils_1.generateRandomName)() : name}.${extension}`, buffer);
60
+ }
61
+ /**
62
+ * Exports all layers from the LayersManager as an array of JSON objects.
63
+ * @param manager {LayersManager} - The LayersManager instance.
64
+ * @returns {any[]} An array of JSON representations of the layers.
65
+ */
66
+ exportLayers(manager) {
67
+ let arr = [];
68
+ for (const layer of Array.from(manager.map.values())) {
69
+ arr.push(layer.toJSON());
70
+ }
71
+ return arr;
72
+ }
73
+ /**
74
+ * Exports the canvas to the specified format.
75
+ * @param exportType {AnyExport} - The type of export (e.g., "png", "json").
76
+ * @param opts {Object} - Optional settings.
77
+ * @param opts.name {string} - The name of the file (optional).
78
+ * @param opts.saveAsFile {boolean} - Whether to save the export as a file (optional).
79
+ * @returns {Promise<Buffer | SKRSContext2D | Canvas | SvgCanvas | string>} The exported data.
80
+ * @throws {LazyError} If the export type is not supported.
81
+ */
82
+ async export(exportType, opts) {
83
+ switch (exportType) {
84
+ case types_1.Export.CTX:
85
+ case "ctx":
86
+ return await this.canvas.manager.render.render(exportType);
87
+ case types_1.Export.SVG:
88
+ case "svg":
89
+ const svg = await this.canvas.manager.render.render('svg');
90
+ if (opts?.saveAsFile) {
91
+ await this.saveFile(svg, 'svg', opts.name);
92
+ }
93
+ return svg;
94
+ case types_1.Export.BUFFER:
95
+ case "buffer":
96
+ const buffer = await this.canvas.manager.render.render('buffer');
97
+ if (opts?.saveAsFile) {
98
+ await this.saveFile(buffer, 'png', opts.name);
99
+ }
100
+ return buffer;
101
+ case types_1.Export.GIF:
102
+ case "gif":
103
+ const gif = await this.canvas.manager.render.render('buffer');
104
+ if (opts?.saveAsFile) {
105
+ await this.saveFile(gif, 'gif', opts.name);
106
+ }
107
+ return gif;
108
+ case types_1.Export.WEBP:
109
+ case "webp":
110
+ const webp = await this.canvas.manager.render.render('buffer');
111
+ if (opts?.saveAsFile) {
112
+ await this.saveFile(webp, 'webp', opts.name);
113
+ }
114
+ return webp;
115
+ case types_1.Export.JPEG:
116
+ case "jpeg":
117
+ const jpeg = await this.canvas.manager.render.render('buffer');
118
+ await this.saveFile(jpeg, 'jpeg', opts?.name);
119
+ return jpeg;
120
+ case types_1.Export.JPG:
121
+ case "jpg":
122
+ const jpg = await this.canvas.manager.render.render('buffer');
123
+ await this.saveFile(jpg, 'jpg', opts?.name);
124
+ return jpg;
125
+ case types_1.Export.PNG:
126
+ case "png":
127
+ const png = await this.canvas.manager.render.render('buffer');
128
+ await this.saveFile(png, 'png', opts?.name);
129
+ return png;
130
+ case types_1.Export.JSON:
131
+ case "json":
132
+ const json = this.syncExport(exportType);
133
+ if (opts?.saveAsFile) {
134
+ await this.saveFile(JSON.stringify(json), 'json', opts.name);
135
+ }
136
+ return JSON.stringify(json);
137
+ case types_1.Export.CANVAS:
138
+ case "canvas":
139
+ return await this.canvas.manager.render.render(exportType);
140
+ case types_1.Export.YAML:
141
+ case "yaml":
142
+ const yaml = _yaml.dump(this.syncExport(types_1.Export.JSON));
143
+ if (opts?.saveAsFile) {
144
+ await this.saveFile(yaml, 'yaml', opts.name);
145
+ }
146
+ return yaml;
147
+ default:
148
+ throw new LazyUtil_1.LazyError(`Export type ${exportType} is not supported`);
149
+ }
150
+ }
151
+ /**
152
+ * Synchronously exports the canvas to the specified format.
153
+ * @param exportType {AnyExport} - The type of export (e.g., "json").
154
+ * @returns {IOLazyCanvas | void} The exported data or void if the export type is unsupported.
155
+ */
156
+ syncExport(exportType) {
157
+ switch (exportType) {
158
+ case types_1.Export.JSON:
159
+ case "json":
160
+ return {
161
+ options: this.canvas.options,
162
+ animation: this.canvas.manager.animation.options,
163
+ layers: this.exportLayers(this.canvas.manager.layers)
164
+ };
165
+ }
166
+ }
167
+ }
168
+ exports.Exporter = Exporter;
@@ -1,35 +1,89 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { AnyWeight } from "../../types";
4
- import { IFont } from "../../types";
4
+ /**
5
+ * Interface representing a font.
6
+ */
7
+ export interface IFont {
8
+ /**
9
+ * The font family.
10
+ */
11
+ family: string;
12
+ /**
13
+ * The weight of the font.
14
+ */
15
+ weight: AnyWeight;
16
+ /**
17
+ * The file path of the font (optional).
18
+ */
19
+ path?: string;
20
+ /**
21
+ * The base64 representation of the font (optional).
22
+ */
23
+ base64?: Buffer;
24
+ }
25
+ /**
26
+ * Interface representing a collection of fonts.
27
+ * Each font family maps to a record of font weights and their corresponding buffers.
28
+ */
29
+ export interface IFonts {
30
+ [family: string]: Record<number, Buffer>;
31
+ }
32
+ /**
33
+ * Class representing a font with properties such as family, weight, path, and base64.
34
+ */
5
35
  export declare class Font implements IFont {
36
+ /**
37
+ * The font family.
38
+ */
6
39
  family: string;
40
+ /**
41
+ * The weight of the font.
42
+ */
7
43
  weight: AnyWeight;
44
+ /**
45
+ * The file path of the font (optional).
46
+ */
8
47
  path?: string;
48
+ /**
49
+ * The base64 representation of the font (optional).
50
+ */
9
51
  base64?: Buffer;
52
+ /**
53
+ * Constructs a new Font instance with default values.
54
+ */
10
55
  constructor();
11
56
  /**
12
- * Set the font family
13
- * @param family {string} - The `family` of the font
57
+ * Sets the font family.
58
+ * @param family {string} - The `family` of the font.
59
+ * @returns {this} The current instance for chaining.
60
+ * @throws {Error} If the family is not provided.
14
61
  */
15
62
  setFamily(family: string): this;
16
63
  /**
17
- * Set the font weight
18
- * @param weight {AnyWeight} - The `weight` of the font
64
+ * Sets the font weight.
65
+ * @param weight {AnyWeight} - The `weight` of the font.
66
+ * @returns {this} The current instance for chaining.
67
+ * @throws {Error} If the weight is not provided.
19
68
  */
20
69
  setWeight(weight: AnyWeight): this;
21
70
  /**
22
- * Set the path of the font
23
- * @param path {string} - The `path` of the font
71
+ * Sets the file path of the font.
72
+ * @param path {string} - The `path` of the font.
73
+ * @returns {this} The current instance for chaining.
74
+ * @throws {Error} If the path is not provided.
24
75
  */
25
76
  setPath(path: string): this;
26
77
  /**
27
- * Set the base64 of the font
28
- * @param base64 {string} - The `base64` of the font
78
+ * Sets the base64 representation of the font.
79
+ * @param base64 {Buffer} - The `base64` of the font.
80
+ * @returns {this} The current instance for chaining.
81
+ * @throws {Error} If the base64 is not provided.
29
82
  */
30
83
  setBase64(base64: Buffer): this;
31
84
  /**
32
- * @returns {IFont}
85
+ * Converts the Font instance to a JSON representation.
86
+ * @returns {IFont} The JSON representation of the font.
33
87
  */
34
88
  toJSON(): IFont;
35
89
  }
@@ -1,19 +1,39 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Font = void 0;
4
- const enum_1 = require("../../types/enum");
4
+ const types_1 = require("../../types");
5
+ /**
6
+ * Class representing a font with properties such as family, weight, path, and base64.
7
+ */
5
8
  class Font {
9
+ /**
10
+ * The font family.
11
+ */
6
12
  family;
13
+ /**
14
+ * The weight of the font.
15
+ */
7
16
  weight;
17
+ /**
18
+ * The file path of the font (optional).
19
+ */
8
20
  path;
21
+ /**
22
+ * The base64 representation of the font (optional).
23
+ */
9
24
  base64;
25
+ /**
26
+ * Constructs a new Font instance with default values.
27
+ */
10
28
  constructor() {
11
29
  this.family = "Arial";
12
- this.weight = enum_1.FontWeight.Regular;
30
+ this.weight = types_1.FontWeight.Regular;
13
31
  }
14
32
  /**
15
- * Set the font family
16
- * @param family {string} - The `family` of the font
33
+ * Sets the font family.
34
+ * @param family {string} - The `family` of the font.
35
+ * @returns {this} The current instance for chaining.
36
+ * @throws {Error} If the family is not provided.
17
37
  */
18
38
  setFamily(family) {
19
39
  if (!family)
@@ -22,8 +42,10 @@ class Font {
22
42
  return this;
23
43
  }
24
44
  /**
25
- * Set the font weight
26
- * @param weight {AnyWeight} - The `weight` of the font
45
+ * Sets the font weight.
46
+ * @param weight {AnyWeight} - The `weight` of the font.
47
+ * @returns {this} The current instance for chaining.
48
+ * @throws {Error} If the weight is not provided.
27
49
  */
28
50
  setWeight(weight) {
29
51
  if (!weight)
@@ -32,8 +54,10 @@ class Font {
32
54
  return this;
33
55
  }
34
56
  /**
35
- * Set the path of the font
36
- * @param path {string} - The `path` of the font
57
+ * Sets the file path of the font.
58
+ * @param path {string} - The `path` of the font.
59
+ * @returns {this} The current instance for chaining.
60
+ * @throws {Error} If the path is not provided.
37
61
  */
38
62
  setPath(path) {
39
63
  if (!path)
@@ -42,8 +66,10 @@ class Font {
42
66
  return this;
43
67
  }
44
68
  /**
45
- * Set the base64 of the font
46
- * @param base64 {string} - The `base64` of the font
69
+ * Sets the base64 representation of the font.
70
+ * @param base64 {Buffer} - The `base64` of the font.
71
+ * @returns {this} The current instance for chaining.
72
+ * @throws {Error} If the base64 is not provided.
47
73
  */
48
74
  setBase64(base64) {
49
75
  if (!base64)
@@ -52,7 +78,8 @@ class Font {
52
78
  return this;
53
79
  }
54
80
  /**
55
- * @returns {IFont}
81
+ * Converts the Font instance to a JSON representation.
82
+ * @returns {IFont} The JSON representation of the font.
56
83
  */
57
84
  toJSON() {
58
85
  return {
@@ -1,28 +1,115 @@
1
- import { IGradient, GradientPoint, GradientColorStop, AnyGradientType } from "../../types";
1
+ import { AnyGradientType, FillType } from "../../types";
2
2
  import { SKRSContext2D } from "@napi-rs/canvas";
3
+ /**
4
+ * Interface representing a gradient.
5
+ */
6
+ export interface IGradient {
7
+ /**
8
+ * The type of fill, which is always `Gradient` for this interface.
9
+ */
10
+ fillType: FillType;
11
+ /**
12
+ * The type of gradient (e.g., linear, radial, conic).
13
+ */
14
+ type: AnyGradientType;
15
+ /**
16
+ * The points defining the gradient.
17
+ */
18
+ points: Array<GradientPoint>;
19
+ /**
20
+ * The color stops for the gradient.
21
+ */
22
+ stops: Array<GradientColorStop>;
23
+ }
24
+ /**
25
+ * Interface representing a color stop in a gradient.
26
+ */
27
+ export interface GradientColorStop {
28
+ /**
29
+ * The color of the stop in hexadecimal format.
30
+ */
31
+ color: string;
32
+ /**
33
+ * The offset of the stop, ranging from 0 to 1.
34
+ */
35
+ offset: number;
36
+ }
37
+ /**
38
+ * Interface representing a point in a gradient.
39
+ */
40
+ export interface GradientPoint {
41
+ /**
42
+ * The x-coordinate of the point.
43
+ */
44
+ x: number;
45
+ /**
46
+ * The y-coordinate of the point.
47
+ */
48
+ y: number;
49
+ /**
50
+ * The radius of the point (optional, used for radial gradients).
51
+ */
52
+ r?: number;
53
+ /**
54
+ * The starting angle of the point (optional, used for conic gradients).
55
+ */
56
+ startAngle?: number;
57
+ }
58
+ /**
59
+ * Class representing a gradient with properties and methods to manipulate it.
60
+ */
3
61
  export declare class Gradient implements IGradient {
62
+ /**
63
+ * The type of fill, which is always `Gradient`.
64
+ */
65
+ fillType: FillType;
66
+ /**
67
+ * The type of gradient (e.g., linear, radial, conic).
68
+ */
4
69
  type: AnyGradientType;
70
+ /**
71
+ * The points defining the gradient.
72
+ */
5
73
  points: Array<GradientPoint>;
74
+ /**
75
+ * The color stops for the gradient.
76
+ */
6
77
  stops: Array<GradientColorStop>;
7
- constructor();
8
78
  /**
9
- * Set the type of the gradient
10
- * @param type {AnyGradientType} - The `type` of the gradient. Can be `linear`, `radial`, or `conic`
79
+ * Constructs a new Gradient instance.
80
+ * @param opts {Object} - Optional properties for the gradient.
81
+ * @param opts.props {IGradient} - The gradient properties.
82
+ */
83
+ constructor(opts?: {
84
+ props?: IGradient;
85
+ });
86
+ /**
87
+ * Sets the type of the gradient.
88
+ * @param type {AnyGradientType} - The type of the gradient (e.g., linear, radial, conic).
89
+ * @returns {this} The current instance for chaining.
11
90
  */
12
91
  setType(type: AnyGradientType): this;
13
92
  /**
14
- * Add a point to the gradient
15
- * @param points {GradientPoint[]} - The `points` to add to the gradient. `{ x: number, y: number }`
93
+ * Adds points to the gradient.
94
+ * @param points {GradientPoint[]} - The points to add to the gradient.
95
+ * @returns {this} The current instance for chaining.
16
96
  */
17
97
  addPoints(...points: GradientPoint[]): this;
18
98
  /**
19
- * Add a stop to the gradient
20
- * @param stops {GradientColorStop[]} - The `stops` to add to the gradient. `{ color: string, position: number }`
99
+ * Adds color stops to the gradient.
100
+ * @param stops {GradientColorStop[]} - The color stops to add to the gradient.
101
+ * @returns {this} The current instance for chaining.
21
102
  */
22
103
  addStops(...stops: GradientColorStop[]): this;
104
+ /**
105
+ * Draws the gradient on a canvas context.
106
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
107
+ * @returns {CanvasGradient} The created gradient.
108
+ */
23
109
  draw(ctx: SKRSContext2D): CanvasGradient;
24
110
  /**
25
- * @returns {IGradient}
111
+ * Converts the gradient to a JSON representation.
112
+ * @returns {IGradient} The JSON representation of the gradient.
26
113
  */
27
114
  toJSON(): IGradient;
28
115
  }
@@ -1,56 +1,85 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Gradient = void 0;
4
- const enum_1 = require("../../types/enum");
4
+ const types_1 = require("../../types");
5
5
  const utils_1 = require("../../utils/utils");
6
+ /**
7
+ * Class representing a gradient with properties and methods to manipulate it.
8
+ */
6
9
  class Gradient {
10
+ /**
11
+ * The type of fill, which is always `Gradient`.
12
+ */
13
+ fillType = types_1.FillType.Gradient;
14
+ /**
15
+ * The type of gradient (e.g., linear, radial, conic).
16
+ */
7
17
  type;
18
+ /**
19
+ * The points defining the gradient.
20
+ */
8
21
  points;
22
+ /**
23
+ * The color stops for the gradient.
24
+ */
9
25
  stops;
10
- constructor() {
11
- this.type = enum_1.GradientType.Linear;
12
- this.points = [];
13
- this.stops = [];
26
+ /**
27
+ * Constructs a new Gradient instance.
28
+ * @param opts {Object} - Optional properties for the gradient.
29
+ * @param opts.props {IGradient} - The gradient properties.
30
+ */
31
+ constructor(opts) {
32
+ this.type = opts?.props?.type || types_1.GradientType.Linear;
33
+ this.points = opts?.props?.points || [];
34
+ this.stops = opts?.props?.stops || [];
14
35
  }
15
36
  /**
16
- * Set the type of the gradient
17
- * @param type {AnyGradientType} - The `type` of the gradient. Can be `linear`, `radial`, or `conic`
37
+ * Sets the type of the gradient.
38
+ * @param type {AnyGradientType} - The type of the gradient (e.g., linear, radial, conic).
39
+ * @returns {this} The current instance for chaining.
18
40
  */
19
41
  setType(type) {
20
42
  this.type = type;
21
43
  return this;
22
44
  }
23
45
  /**
24
- * Add a point to the gradient
25
- * @param points {GradientPoint[]} - The `points` to add to the gradient. `{ x: number, y: number }`
46
+ * Adds points to the gradient.
47
+ * @param points {GradientPoint[]} - The points to add to the gradient.
48
+ * @returns {this} The current instance for chaining.
26
49
  */
27
50
  addPoints(...points) {
28
51
  this.points.push(...points);
29
52
  return this;
30
53
  }
31
54
  /**
32
- * Add a stop to the gradient
33
- * @param stops {GradientColorStop[]} - The `stops` to add to the gradient. `{ color: string, position: number }`
55
+ * Adds color stops to the gradient.
56
+ * @param stops {GradientColorStop[]} - The color stops to add to the gradient.
57
+ * @returns {this} The current instance for chaining.
34
58
  */
35
59
  addStops(...stops) {
36
60
  this.stops.push(...stops);
37
61
  return this;
38
62
  }
63
+ /**
64
+ * Draws the gradient on a canvas context.
65
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
66
+ * @returns {CanvasGradient} The created gradient.
67
+ */
39
68
  draw(ctx) {
40
69
  let gradientData = this.toJSON();
41
70
  let gradient;
42
71
  switch (gradientData.type) {
43
- case enum_1.GradientType.Linear:
72
+ case types_1.GradientType.Linear:
44
73
  case "linear":
45
74
  gradient = ctx.createLinearGradient(gradientData.points[0].x, gradientData.points[0].y, gradientData.points[1].x, gradientData.points[1].y);
46
75
  break;
47
- case enum_1.GradientType.Radial:
76
+ case types_1.GradientType.Radial:
48
77
  case "radial":
49
- gradient = ctx.createRadialGradient(gradientData.points[0].x, gradientData.points[0].y, (gradientData.points[0].r || 0), (gradientData.points[1].x || gradientData.points[0].x), (gradientData.points[1].y || gradientData.points[0].y), (gradientData.points[1].r || 0));
78
+ gradient = ctx.createRadialGradient(gradientData.points[0].x, gradientData.points[0].y, gradientData.points[0].r || 0, gradientData.points[1].x || gradientData.points[0].x, gradientData.points[1].y || gradientData.points[0].y, gradientData.points[1].r || 0);
50
79
  break;
51
- case enum_1.GradientType.Conic:
80
+ case types_1.GradientType.Conic:
52
81
  case "conic":
53
- gradient = ctx.createConicGradient((gradientData.points[0].startAngle || 0), gradientData.points[0].x, gradientData.points[0].y);
82
+ gradient = ctx.createConicGradient(gradientData.points[0].startAngle || 0, gradientData.points[0].x, gradientData.points[0].y);
54
83
  break;
55
84
  default:
56
85
  gradient = ctx.createLinearGradient(gradientData.points[0].x, gradientData.points[0].y, gradientData.points[1].x, gradientData.points[1].y);
@@ -62,10 +91,12 @@ class Gradient {
62
91
  return gradient;
63
92
  }
64
93
  /**
65
- * @returns {IGradient}
94
+ * Converts the gradient to a JSON representation.
95
+ * @returns {IGradient} The JSON representation of the gradient.
66
96
  */
67
97
  toJSON() {
68
98
  return {
99
+ fillType: this.fillType,
69
100
  type: this.type,
70
101
  points: this.points,
71
102
  stops: this.stops,
@@ -1,22 +1,66 @@
1
- import { AnyLinkType, ILink, ScaleType } from "../../types";
1
+ import { AnyLinkType, ScaleType } from "../../types";
2
+ /**
3
+ * Interface representing a link between layers.
4
+ */
5
+ export interface ILink {
6
+ /**
7
+ * The source layer's ID.
8
+ */
9
+ source: string;
10
+ /**
11
+ * The type of the link (e.g., width, height, etc.).
12
+ */
13
+ type: AnyLinkType;
14
+ /**
15
+ * The additional spacing applied to the link.
16
+ */
17
+ additionalSpacing: ScaleType;
18
+ }
19
+ /**
20
+ * Class representing a link between layers with properties and methods to manipulate it.
21
+ */
2
22
  export declare class Link {
23
+ /**
24
+ * The source layer's ID.
25
+ */
3
26
  source: string;
27
+ /**
28
+ * The type of the link (e.g., width, height, etc.).
29
+ */
4
30
  type: AnyLinkType;
31
+ /**
32
+ * The additional spacing applied to the link.
33
+ */
5
34
  additionalSpacing: ScaleType;
6
- constructor(props?: ILink);
7
35
  /**
8
- * @description Sets the source of the link.
9
- * @param source {string} - The `id` of the layer to link.
36
+ * Constructs a new Link instance.
37
+ * @param opts {Object} - Optional properties for the link.
38
+ * @param opts.props {ILink} - The link properties.
39
+ */
40
+ constructor(opts?: {
41
+ props?: ILink;
42
+ });
43
+ /**
44
+ * Sets the source of the link.
45
+ * @param source {string} - The ID of the layer to link.
46
+ * @returns {this} The current instance for chaining.
10
47
  */
11
48
  setSource(source: string): this;
12
49
  /**
13
- * @description Sets the type of the link.
14
- * @param type {AnyLinkType} - The `type` of the link.
50
+ * Sets the type of the link.
51
+ * @param type {AnyLinkType} - The type of the link.
52
+ * @returns {this} The current instance for chaining.
15
53
  */
16
54
  setType(type: AnyLinkType): this;
17
55
  /**
18
- * @description Sets the additional spacing of the link.
19
- * @param additionalSpacing {ScaleType} - The `additionalSpacing` of the link.
56
+ * Sets the additional spacing of the link.
57
+ * @param additionalSpacing {ScaleType} - The additional spacing of the link.
58
+ * @returns {this} The current instance for chaining.
20
59
  */
21
60
  setSpacing(additionalSpacing: ScaleType): this;
61
+ /**
62
+ * Converts the Link instance to a JSON representation.
63
+ * @returns {ILink} The JSON representation of the link.
64
+ */
65
+ toJSON(): ILink;
22
66
  }