@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,39 +1,142 @@
1
- import { IClearLayer, IClearLayerProps, ScaleType } from "../../types";
2
- import { LayerType } from "../../types/enum";
3
- import { Canvas, SKRSContext2D } from "@napi-rs/canvas";
1
+ import { ScaleType, LayerType, AnyCentring } from "../../types";
2
+ import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
4
3
  import { LayersManager } from "../managers/LayersManager";
4
+ import { IBaseLayerMisc } from "./BaseLayer";
5
+ /**
6
+ * Interface representing a Clear Layer.
7
+ */
8
+ export interface IClearLayer {
9
+ /**
10
+ * The unique identifier of the layer.
11
+ */
12
+ id: string;
13
+ /**
14
+ * The type of the layer, which is `Clear`.
15
+ */
16
+ type: LayerType.Clear;
17
+ /**
18
+ * The z-index of the layer, determining its stacking order.
19
+ */
20
+ zIndex: number;
21
+ /**
22
+ * The visibility of the layer.
23
+ */
24
+ visible: boolean;
25
+ /**
26
+ * The properties of the Clear Layer.
27
+ */
28
+ props: IClearLayerProps;
29
+ }
30
+ /**
31
+ * Interface representing the properties of a Clear Layer.
32
+ */
33
+ export interface IClearLayerProps {
34
+ /**
35
+ * The x-coordinate of the layer.
36
+ */
37
+ x: ScaleType;
38
+ /**
39
+ * The y-coordinate of the layer.
40
+ */
41
+ y: ScaleType;
42
+ /**
43
+ * The size of the layer, including width and height.
44
+ */
45
+ size: {
46
+ /**
47
+ * The width of the layer.
48
+ */
49
+ width: ScaleType;
50
+ /**
51
+ * The height of the layer.
52
+ */
53
+ height: ScaleType;
54
+ };
55
+ /**
56
+ * The centring type of the layer.
57
+ */
58
+ centring: AnyCentring;
59
+ }
60
+ /**
61
+ * Class representing a Clear Layer.
62
+ */
5
63
  export declare class ClearLayer implements IClearLayer {
64
+ /**
65
+ * The unique identifier of the layer.
66
+ */
6
67
  id: string;
7
- type: LayerType;
68
+ /**
69
+ * The type of the layer, which is `Clear`.
70
+ */
71
+ type: LayerType.Clear;
72
+ /**
73
+ * The z-index of the layer, determining its stacking order.
74
+ */
8
75
  zIndex: number;
76
+ /**
77
+ * The visibility of the layer.
78
+ */
9
79
  visible: boolean;
80
+ /**
81
+ * The properties of the Clear Layer.
82
+ */
10
83
  props: IClearLayerProps;
11
- constructor(props?: IClearLayerProps);
12
84
  /**
13
- * @description Position of the layer in the 2D plane. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
14
- * @param x {ScaleType} - The `x` position of the layer
15
- * @param y {ScaleType} - The `y` position of the layer
85
+ * Constructs a new ClearLayer instance.
86
+ * @param props {IClearLayerProps} - The properties of the Clear Layer.
87
+ * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
88
+ */
89
+ constructor(props?: IClearLayerProps, misc?: IBaseLayerMisc);
90
+ /**
91
+ * Sets the position of the layer in the 2D plane.
92
+ * @param x {ScaleType} - The x-coordinate of the layer.
93
+ * @param y {ScaleType} - The y-coordinate of the layer.
94
+ * @returns {this} The current instance for chaining.
16
95
  */
17
96
  setPosition(x: ScaleType, y: ScaleType): this;
18
97
  /**
19
- * @description Sets the size of the layer.
20
- * @param width {ScaleType} - The `width` of the layer
21
- * @param height {ScaleType} - The `height` of the
98
+ * Sets the size of the layer.
99
+ * @param width {ScaleType} - The width of the layer.
100
+ * @param height {ScaleType} - The height of the layer.
101
+ * @returns {this} The current instance for chaining.
22
102
  */
23
103
  setSize(width: ScaleType, height: ScaleType): this;
24
104
  /**
25
- * @description Sets the visibility of the layer.
26
- * @param visible {boolean} - The `visibility` of the layer
105
+ * Sets the unique identifier of the layer.
106
+ *
107
+ * @param {string} id - The unique identifier.
108
+ * @returns {this} The current instance for chaining.
109
+ */
110
+ setID(id: string): this;
111
+ /**
112
+ * Sets the centring type of the layer.
113
+ * @param centring {AnyCentring} - The centring type of the layer.
114
+ * @returns {this} The current instance for chaining.
115
+ */
116
+ setCentring(centring: AnyCentring): this;
117
+ /**
118
+ * Sets the visibility of the layer.
119
+ * @param visible {boolean} - The visibility state of the layer.
120
+ * @returns {this} The current instance for chaining.
27
121
  */
28
122
  setVisible(visible: boolean): this;
29
123
  /**
30
- * @description Sets zIndex of the layer.
31
- * @param zIndex {number} - The `zIndex` of the layer
124
+ * Sets the z-index of the layer.
125
+ * @param zIndex {number} - The z-index value of the layer.
126
+ * @returns {this} The current instance for chaining.
32
127
  */
33
128
  setZIndex(zIndex: number): this;
34
- draw(ctx: SKRSContext2D, canvas: Canvas, manager: LayersManager, debug: boolean): Promise<void>;
35
129
  /**
36
- * @returns {IClearLayer}
130
+ * Draws the Clear Layer 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 Clear Layer to a JSON representation.
139
+ * @returns {IClearLayer} The JSON representation of the Clear Layer.
37
140
  */
38
141
  toJSON(): IClearLayer;
39
142
  }
@@ -1,21 +1,44 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ClearLayer = void 0;
4
- const enum_1 = require("../../types/enum");
4
+ const types_1 = require("../../types");
5
5
  const utils_1 = require("../../utils/utils");
6
6
  const LazyUtil_1 = require("../../utils/LazyUtil");
7
7
  const utils_2 = require("../../utils/utils");
8
+ /**
9
+ * Class representing a Clear Layer.
10
+ */
8
11
  class ClearLayer {
12
+ /**
13
+ * The unique identifier of the layer.
14
+ */
9
15
  id;
10
- type;
16
+ /**
17
+ * The type of the layer, which is `Clear`.
18
+ */
19
+ type = types_1.LayerType.Clear;
20
+ /**
21
+ * The z-index of the layer, determining its stacking order.
22
+ */
11
23
  zIndex;
24
+ /**
25
+ * The visibility of the layer.
26
+ */
12
27
  visible;
28
+ /**
29
+ * The properties of the Clear Layer.
30
+ */
13
31
  props;
14
- constructor(props) {
15
- this.id = (0, utils_2.generateID)(enum_1.LayerType.Clear);
16
- this.type = enum_1.LayerType.Clear;
17
- this.zIndex = 1;
18
- this.visible = true;
32
+ /**
33
+ * Constructs a new ClearLayer instance.
34
+ * @param props {IClearLayerProps} - The properties of the Clear Layer.
35
+ * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
36
+ */
37
+ constructor(props, misc) {
38
+ this.id = misc?.id || (0, utils_2.generateID)(types_1.LayerType.Clear);
39
+ this.type = types_1.LayerType.Clear;
40
+ this.zIndex = misc?.zIndex || 1;
41
+ this.visible = misc?.visible || true;
19
42
  this.props = props ? props : {
20
43
  x: 0,
21
44
  y: 0,
@@ -26,9 +49,10 @@ class ClearLayer {
26
49
  };
27
50
  }
28
51
  /**
29
- * @description Position of the layer in the 2D plane. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
30
- * @param x {ScaleType} - The `x` position of the layer
31
- * @param y {ScaleType} - The `y` position of the layer
52
+ * Sets the position of the layer in the 2D plane.
53
+ * @param x {ScaleType} - The x-coordinate of the layer.
54
+ * @param y {ScaleType} - The y-coordinate of the layer.
55
+ * @returns {this} The current instance for chaining.
32
56
  */
33
57
  setPosition(x, y) {
34
58
  this.props.x = x;
@@ -36,9 +60,10 @@ class ClearLayer {
36
60
  return this;
37
61
  }
38
62
  /**
39
- * @description Sets the size of the layer.
40
- * @param width {ScaleType} - The `width` of the layer
41
- * @param height {ScaleType} - The `height` of the
63
+ * Sets the size of the layer.
64
+ * @param width {ScaleType} - The width of the layer.
65
+ * @param height {ScaleType} - The height of the layer.
66
+ * @returns {this} The current instance for chaining.
42
67
  */
43
68
  setSize(width, height) {
44
69
  this.props.size = {
@@ -48,43 +73,79 @@ class ClearLayer {
48
73
  return this;
49
74
  }
50
75
  /**
51
- * @description Sets the visibility of the layer.
52
- * @param visible {boolean} - The `visibility` of the layer
76
+ * Sets the unique identifier of the layer.
77
+ *
78
+ * @param {string} id - The unique identifier.
79
+ * @returns {this} The current instance for chaining.
80
+ */
81
+ setID(id) {
82
+ this.id = id;
83
+ return this;
84
+ }
85
+ /**
86
+ * Sets the centring type of the layer.
87
+ * @param centring {AnyCentring} - The centring type of the layer.
88
+ * @returns {this} The current instance for chaining.
89
+ */
90
+ setCentring(centring) {
91
+ this.props.centring = centring;
92
+ return this;
93
+ }
94
+ /**
95
+ * Sets the visibility of the layer.
96
+ * @param visible {boolean} - The visibility state of the layer.
97
+ * @returns {this} The current instance for chaining.
53
98
  */
54
99
  setVisible(visible) {
55
100
  this.visible = visible;
56
101
  return this;
57
102
  }
58
103
  /**
59
- * @description Sets zIndex of the layer.
60
- * @param zIndex {number} - The `zIndex` of the layer
104
+ * Sets the z-index of the layer.
105
+ * @param zIndex {number} - The z-index value of the layer.
106
+ * @returns {this} The current instance for chaining.
61
107
  */
62
108
  setZIndex(zIndex) {
63
109
  this.zIndex = zIndex;
64
110
  return this;
65
111
  }
112
+ /**
113
+ * Draws the Clear Layer on the canvas.
114
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
115
+ * @param canvas {Canvas | SvgCanvas} - The canvas instance.
116
+ * @param manager {LayersManager} - The layers manager.
117
+ * @param debug {boolean} - Whether to enable debug logging.
118
+ */
66
119
  async draw(ctx, canvas, manager, debug) {
67
120
  const parcer = (0, utils_1.parser)(ctx, canvas, manager);
68
- const { x, y, w } = parcer.parseBatch({
69
- x: { v: this.props.x },
70
- y: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
121
+ const { xs, ys, w } = parcer.parseBatch({
122
+ xs: { v: this.props.x },
123
+ ys: { v: this.props.y, options: LazyUtil_1.defaultArg.vl(true) },
71
124
  w: { v: this.props.size.width },
72
125
  });
73
126
  const h = parcer.parse(this.props.size.height, LazyUtil_1.defaultArg.wh(w), LazyUtil_1.defaultArg.vl(true));
127
+ let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
74
128
  if (debug)
75
129
  LazyUtil_1.LazyLog.log('none', `ClearLayer:`, { x, y, w, h });
76
130
  ctx.clearRect(x, y, w, h);
77
131
  }
78
132
  /**
79
- * @returns {IClearLayer}
133
+ * Converts the Clear Layer to a JSON representation.
134
+ * @returns {IClearLayer} The JSON representation of the Clear Layer.
80
135
  */
81
136
  toJSON() {
137
+ let copy = { ...this.props };
138
+ for (const key of ['x', 'y', 'size.width', 'size.height']) {
139
+ if (copy[key] && typeof copy[key] === 'object' && 'toJSON' in copy[key]) {
140
+ copy[key] = copy[key].toJSON();
141
+ }
142
+ }
82
143
  return {
83
144
  id: this.id,
84
145
  type: this.type,
85
146
  zIndex: this.zIndex,
86
147
  visible: this.visible,
87
- props: this.props,
148
+ props: copy,
88
149
  };
89
150
  }
90
151
  }
@@ -1,51 +1,119 @@
1
- import { AnyLayer, IGroup } from "../../types";
1
+ import { AnyLayer, LayerType } from "../../types";
2
+ /**
3
+ * Interface representing a group of layers.
4
+ */
5
+ export interface IGroup {
6
+ /**
7
+ * The unique identifier of the group.
8
+ */
9
+ id: string;
10
+ /**
11
+ * The type of the group, which is `Group`.
12
+ */
13
+ type: LayerType.Group;
14
+ /**
15
+ * The visibility of the group.
16
+ */
17
+ visible: boolean;
18
+ /**
19
+ * The z-index of the group, determining its stacking order.
20
+ */
21
+ zIndex: number;
22
+ /**
23
+ * The layers contained within the group.
24
+ */
25
+ layers: Array<AnyLayer>;
26
+ }
27
+ /**
28
+ * Class representing a group of layers.
29
+ */
2
30
  export declare class Group implements IGroup {
31
+ /**
32
+ * The unique identifier of the group.
33
+ */
3
34
  id: string;
35
+ /**
36
+ * The type of the group, which is `Group`.
37
+ */
38
+ type: LayerType.Group;
39
+ /**
40
+ * The visibility of the group.
41
+ */
4
42
  visible: boolean;
43
+ /**
44
+ * The z-index of the group, determining its stacking order.
45
+ */
5
46
  zIndex: number;
6
- components: Array<any>;
7
- constructor();
8
47
  /**
9
- * Set the ID of the group
10
- * @param id {string} - The `id` of the group
48
+ * The layers contained within the group.
49
+ */
50
+ layers: Array<any>;
51
+ /**
52
+ * Constructs a new Group instance.
53
+ * @param opts {Object} - Optional parameters for the group.
54
+ * @param opts.id {string} - The unique identifier of the group.
55
+ * @param opts.visible {boolean} - The visibility of the group.
56
+ * @param opts.zIndex {number} - The z-index of the group.
57
+ */
58
+ constructor(opts?: {
59
+ id?: string;
60
+ visible?: boolean;
61
+ zIndex?: number;
62
+ });
63
+ /**
64
+ * Sets the ID of the group.
65
+ * @param id {string} - The unique identifier of the group.
66
+ * @returns {this} The current instance for chaining.
11
67
  */
12
68
  setID(id: string): this;
13
69
  /**
14
- * Set the visibility of the group
15
- * @param visible {boolean} - The `visibility` of the group
70
+ * Sets the visibility of the group.
71
+ * @param visible {boolean} - The visibility state of the group.
72
+ * @returns {this} The current instance for chaining.
16
73
  */
17
74
  setVisible(visible: boolean): this;
18
75
  /**
19
- * Set the zIndex of the group
20
- * @param zIndex {number} - The `zIndex` of the group
76
+ * Sets the z-index of the group.
77
+ * @param zIndex {number} - The z-index value of the group.
78
+ * @returns {this} The current instance for chaining.
21
79
  */
22
80
  setZIndex(zIndex: number): this;
23
81
  /**
24
- * Add a component to the group
25
- * @param components {any[]} - The `components` to add to the group
82
+ * Adds components to the group.
83
+ * @param components {AnyLayer[]} - The components to add to the group.
84
+ * @returns {this} The current instance for chaining.
26
85
  */
27
86
  add(...components: AnyLayer[]): this;
28
87
  /**
29
- * Remove a component from the group
30
- * @param id {any} - The `id` of the component to remove
88
+ * Removes a component from the group by its ID.
89
+ * @param id {string} - The unique identifier of the component to remove.
90
+ * @returns {this} The current instance for chaining.
31
91
  */
32
92
  remove(id: string): this;
33
93
  /**
34
- * ClearLayer all components from the group
94
+ * Clears all components from the group.
95
+ * @returns {this} The current instance for chaining.
35
96
  */
36
97
  clear(): this;
37
98
  /**
38
- * Get a component from the group
39
- * @param id {string} - The `id` of the component to get
99
+ * Retrieves a component from the group by its ID.
100
+ * @param id {string} - The unique identifier of the component to retrieve.
101
+ * @returns {AnyLayer | undefined} The component with the specified ID, or undefined if not found.
40
102
  */
41
- get(id: string): any;
103
+ get(id: string): AnyLayer | undefined;
42
104
  /**
43
- * Get all components from the group
105
+ * Retrieves all components from the group.
106
+ * @returns {AnyLayer[]} An array of all components in the group.
44
107
  */
45
- getAll(): any[];
108
+ getAll(): AnyLayer[];
46
109
  /**
47
- * Get the length of the components
110
+ * Gets the number of components in the group.
111
+ * @returns {number} The number of components in the group.
48
112
  */
49
113
  get length(): number;
114
+ /**
115
+ * Converts the group to a JSON representation.
116
+ * @returns {IGroup} The JSON representation of the group.
117
+ */
50
118
  toJSON(): IGroup;
51
119
  }
@@ -1,94 +1,134 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Group = 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 group of layers.
8
+ */
6
9
  class Group {
10
+ /**
11
+ * The unique identifier of the group.
12
+ */
7
13
  id;
14
+ /**
15
+ * The type of the group, which is `Group`.
16
+ */
17
+ type = types_1.LayerType.Group;
18
+ /**
19
+ * The visibility of the group.
20
+ */
8
21
  visible;
22
+ /**
23
+ * The z-index of the group, determining its stacking order.
24
+ */
9
25
  zIndex;
10
- components;
11
- constructor() {
12
- this.id = (0, utils_1.generateID)(enum_1.LayerType.Group);
13
- this.visible = true;
14
- this.zIndex = 1;
15
- this.components = [];
26
+ /**
27
+ * The layers contained within the group.
28
+ */
29
+ layers;
30
+ /**
31
+ * Constructs a new Group instance.
32
+ * @param opts {Object} - Optional parameters for the group.
33
+ * @param opts.id {string} - The unique identifier of the group.
34
+ * @param opts.visible {boolean} - The visibility of the group.
35
+ * @param opts.zIndex {number} - The z-index of the group.
36
+ */
37
+ constructor(opts) {
38
+ this.id = opts?.id || (0, utils_1.generateID)(types_1.LayerType.Group);
39
+ this.visible = opts?.visible || true;
40
+ this.zIndex = opts?.zIndex || 1;
41
+ this.layers = [];
16
42
  }
17
43
  /**
18
- * Set the ID of the group
19
- * @param id {string} - The `id` of the group
44
+ * Sets the ID of the group.
45
+ * @param id {string} - The unique identifier of the group.
46
+ * @returns {this} The current instance for chaining.
20
47
  */
21
48
  setID(id) {
22
49
  this.id = id;
23
50
  return this;
24
51
  }
25
52
  /**
26
- * Set the visibility of the group
27
- * @param visible {boolean} - The `visibility` of the group
53
+ * Sets the visibility of the group.
54
+ * @param visible {boolean} - The visibility state of the group.
55
+ * @returns {this} The current instance for chaining.
28
56
  */
29
57
  setVisible(visible) {
30
58
  this.visible = visible;
31
59
  return this;
32
60
  }
33
61
  /**
34
- * Set the zIndex of the group
35
- * @param zIndex {number} - The `zIndex` of the group
62
+ * Sets the z-index of the group.
63
+ * @param zIndex {number} - The z-index value of the group.
64
+ * @returns {this} The current instance for chaining.
36
65
  */
37
66
  setZIndex(zIndex) {
38
67
  this.zIndex = zIndex;
39
68
  return this;
40
69
  }
41
70
  /**
42
- * Add a component to the group
43
- * @param components {any[]} - The `components` to add to the group
71
+ * Adds components to the group.
72
+ * @param components {AnyLayer[]} - The components to add to the group.
73
+ * @returns {this} The current instance for chaining.
44
74
  */
45
75
  add(...components) {
46
76
  let layersArray = components.flat();
47
77
  layersArray = layersArray.filter(l => l !== undefined);
48
78
  layersArray = layersArray.sort((a, b) => a.zIndex - b.zIndex);
49
- this.components.push(...layersArray);
79
+ this.layers.push(...layersArray);
50
80
  return this;
51
81
  }
52
82
  /**
53
- * Remove a component from the group
54
- * @param id {any} - The `id` of the component to remove
83
+ * Removes a component from the group by its ID.
84
+ * @param id {string} - The unique identifier of the component to remove.
85
+ * @returns {this} The current instance for chaining.
55
86
  */
56
87
  remove(id) {
57
- this.components = this.components.filter(c => c.id !== id);
88
+ this.layers = this.layers.filter(c => c.id !== id);
58
89
  return this;
59
90
  }
60
91
  /**
61
- * ClearLayer all components from the group
92
+ * Clears all components from the group.
93
+ * @returns {this} The current instance for chaining.
62
94
  */
63
95
  clear() {
64
- this.components = [];
96
+ this.layers = [];
65
97
  return this;
66
98
  }
67
99
  /**
68
- * Get a component from the group
69
- * @param id {string} - The `id` of the component to get
100
+ * Retrieves a component from the group by its ID.
101
+ * @param id {string} - The unique identifier of the component to retrieve.
102
+ * @returns {AnyLayer | undefined} The component with the specified ID, or undefined if not found.
70
103
  */
71
104
  get(id) {
72
- return this.components.find(c => c.id === id);
105
+ return this.layers.find(c => c.id === id);
73
106
  }
74
107
  /**
75
- * Get all components from the group
108
+ * Retrieves all components from the group.
109
+ * @returns {AnyLayer[]} An array of all components in the group.
76
110
  */
77
111
  getAll() {
78
- return this.components;
112
+ return this.layers;
79
113
  }
80
114
  /**
81
- * Get the length of the components
115
+ * Gets the number of components in the group.
116
+ * @returns {number} The number of components in the group.
82
117
  */
83
118
  get length() {
84
- return this.components.length;
119
+ return this.layers.length;
85
120
  }
121
+ /**
122
+ * Converts the group to a JSON representation.
123
+ * @returns {IGroup} The JSON representation of the group.
124
+ */
86
125
  toJSON() {
87
126
  return {
88
127
  id: this.id,
128
+ type: this.type,
89
129
  visible: this.visible,
90
130
  zIndex: this.zIndex,
91
- components: this.components.map(c => c.toJSON())
131
+ layers: this.layers.map(c => c.toJSON())
92
132
  };
93
133
  }
94
134
  }