@nmmty/lazycanvas 0.3.6 → 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 (68) 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 -45
  7. package/dist/structures/LazyCanvas.d.ts +126 -17
  8. package/dist/structures/LazyCanvas.js +101 -33
  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 +142 -0
  14. package/dist/structures/components/ClearLayer.js +152 -0
  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 +55 -42
  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 +55 -27
  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 +101 -49
  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 +120 -0
  50. package/dist/structures/managers/AnimationManager.js +99 -0
  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 +67 -29
  55. package/dist/structures/managers/RenderManager.d.ts +63 -6
  56. package/dist/structures/managers/RenderManager.js +162 -33
  57. package/dist/types/LazyCanvas.d.ts +2 -0
  58. package/dist/types/components/ClearLayer.d.ts +19 -0
  59. package/dist/types/enum.d.ts +20 -7
  60. package/dist/types/enum.js +24 -10
  61. package/dist/types/index.d.ts +2 -17
  62. package/dist/types/index.js +17 -0
  63. package/dist/types/managers/AnimationManager.d.ts +14 -0
  64. package/dist/types/types.d.ts +7 -3
  65. package/dist/utils/LazyUtil.js +2 -2
  66. package/dist/utils/utils.d.ts +10 -9
  67. package/dist/utils/utils.js +159 -164
  68. package/package.json +9 -5
@@ -1,39 +1,70 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Link = void 0;
4
- const enum_1 = require("../../types/enum");
4
+ const types_1 = require("../../types");
5
+ /**
6
+ * Class representing a link between layers with properties and methods to manipulate it.
7
+ */
5
8
  class Link {
9
+ /**
10
+ * The source layer's ID.
11
+ */
6
12
  source;
13
+ /**
14
+ * The type of the link (e.g., width, height, etc.).
15
+ */
7
16
  type;
17
+ /**
18
+ * The additional spacing applied to the link.
19
+ */
8
20
  additionalSpacing;
9
- constructor(props) {
10
- this.source = props?.source || '';
11
- this.type = props?.type || enum_1.LinkType.Width;
12
- this.additionalSpacing = props?.additionalSpacing || 0;
21
+ /**
22
+ * Constructs a new Link instance.
23
+ * @param opts {Object} - Optional properties for the link.
24
+ * @param opts.props {ILink} - The link properties.
25
+ */
26
+ constructor(opts) {
27
+ this.source = opts?.props?.source || '';
28
+ this.type = opts?.props?.type || types_1.LinkType.Width;
29
+ this.additionalSpacing = opts?.props?.additionalSpacing || 0;
13
30
  }
14
31
  /**
15
- * @description Sets the source of the link.
16
- * @param source {string} - The `id` of the layer to link.
32
+ * Sets the source of the link.
33
+ * @param source {string} - The ID of the layer to link.
34
+ * @returns {this} The current instance for chaining.
17
35
  */
18
36
  setSource(source) {
19
37
  this.source = source;
20
38
  return this;
21
39
  }
22
40
  /**
23
- * @description Sets the type of the link.
24
- * @param type {AnyLinkType} - The `type` of the link.
41
+ * Sets the type of the link.
42
+ * @param type {AnyLinkType} - The type of the link.
43
+ * @returns {this} The current instance for chaining.
25
44
  */
26
45
  setType(type) {
27
46
  this.type = type;
28
47
  return this;
29
48
  }
30
49
  /**
31
- * @description Sets the additional spacing of the link.
32
- * @param additionalSpacing {ScaleType} - The `additionalSpacing` of the link.
50
+ * Sets the additional spacing of the link.
51
+ * @param additionalSpacing {ScaleType} - The additional spacing of the link.
52
+ * @returns {this} The current instance for chaining.
33
53
  */
34
54
  setSpacing(additionalSpacing) {
35
55
  this.additionalSpacing = additionalSpacing;
36
56
  return this;
37
57
  }
58
+ /**
59
+ * Converts the Link instance to a JSON representation.
60
+ * @returns {ILink} The JSON representation of the link.
61
+ */
62
+ toJSON() {
63
+ return {
64
+ source: this.source,
65
+ type: this.type,
66
+ additionalSpacing: this.additionalSpacing
67
+ };
68
+ }
38
69
  }
39
70
  exports.Link = Link;
@@ -1,23 +1,68 @@
1
- import { IPattern, AnyPatternType } from "../../types";
1
+ import { FillType, AnyPatternType } from "../../types";
2
2
  import { LazyCanvas } from "../LazyCanvas";
3
3
  import { SKRSContext2D } from "@napi-rs/canvas";
4
+ /**
5
+ * Interface representing a pattern.
6
+ */
7
+ export interface IPattern {
8
+ /**
9
+ * The type of fill, which is always `Pattern` for this interface.
10
+ */
11
+ fillType: FillType;
12
+ /**
13
+ * The type of the pattern (e.g., repeat, no-repeat, etc.).
14
+ */
15
+ type: AnyPatternType;
16
+ /**
17
+ * The source of the pattern, which can be a string (URL or path) or a LazyCanvas instance.
18
+ */
19
+ src: string | LazyCanvas;
20
+ }
21
+ /**
22
+ * Class representing a pattern with properties and methods to manipulate it.
23
+ */
4
24
  export declare class Pattern implements IPattern {
25
+ /**
26
+ * The type of fill, which is always `Pattern`.
27
+ */
28
+ fillType: FillType;
29
+ /**
30
+ * The type of the pattern (e.g., repeat, no-repeat, etc.).
31
+ */
5
32
  type: AnyPatternType;
33
+ /**
34
+ * The source of the pattern, which can be a string (URL or path) or a LazyCanvas instance.
35
+ */
6
36
  src: string | LazyCanvas;
7
- constructor();
8
37
  /**
9
- * Set the type of the pattern
10
- * @param type {AnyPatternType} - The `type` of the pattern
38
+ * Constructs a new Pattern instance.
39
+ * @param opts {Object} - Optional properties for the pattern.
40
+ * @param opts.props {IPattern} - The pattern properties.
41
+ */
42
+ constructor(opts?: {
43
+ props?: IPattern;
44
+ });
45
+ /**
46
+ * Sets the type of the pattern.
47
+ * @param type {AnyPatternType} - The type of the pattern (e.g., repeat, no-repeat).
48
+ * @returns {this} The current instance for chaining.
11
49
  */
12
50
  setType(type: AnyPatternType): this;
13
51
  /**
14
- * Set the source of the pattern
15
- * @param src {string | LazyCanvas} - The `src` of the pattern
52
+ * Sets the source of the pattern.
53
+ * @param src {string | LazyCanvas} - The source of the pattern, which can be a string (URL or path) or a LazyCanvas instance.
54
+ * @returns {this} The current instance for chaining.
16
55
  */
17
56
  setSrc(src: string | LazyCanvas): this;
57
+ /**
58
+ * Draws the pattern on a canvas context.
59
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
60
+ * @returns {Promise<CanvasPattern | null>} The created pattern or null if the pattern could not be created.
61
+ */
18
62
  draw(ctx: SKRSContext2D): Promise<CanvasPattern>;
19
63
  /**
20
- * @returns {IPattern}
64
+ * Converts the Pattern instance to a JSON representation.
65
+ * @returns {IPattern} The JSON representation of the pattern.
21
66
  */
22
67
  toJSON(): IPattern;
23
68
  }
@@ -1,75 +1,80 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
26
3
  exports.Pattern = void 0;
27
- const enum_1 = require("../../types/enum");
4
+ const types_1 = require("../../types");
28
5
  const LazyCanvas_1 = require("../LazyCanvas");
29
6
  const canvas_1 = require("@napi-rs/canvas");
30
- const jimp = __importStar(require("jimp"));
7
+ const Exporter_1 = require("./Exporter");
8
+ /**
9
+ * Class representing a pattern with properties and methods to manipulate it.
10
+ */
31
11
  class Pattern {
12
+ /**
13
+ * The type of fill, which is always `Pattern`.
14
+ */
15
+ fillType = types_1.FillType.Pattern;
16
+ /**
17
+ * The type of the pattern (e.g., repeat, no-repeat, etc.).
18
+ */
32
19
  type;
20
+ /**
21
+ * The source of the pattern, which can be a string (URL or path) or a LazyCanvas instance.
22
+ */
33
23
  src;
34
- constructor() {
35
- this.type = enum_1.PatternType.Repeat;
36
- this.src = '';
24
+ /**
25
+ * Constructs a new Pattern instance.
26
+ * @param opts {Object} - Optional properties for the pattern.
27
+ * @param opts.props {IPattern} - The pattern properties.
28
+ */
29
+ constructor(opts) {
30
+ this.type = opts?.props?.type || types_1.PatternType.Repeat;
31
+ this.src = opts?.props?.src || '';
37
32
  }
38
33
  /**
39
- * Set the type of the pattern
40
- * @param type {AnyPatternType} - The `type` of the pattern
34
+ * Sets the type of the pattern.
35
+ * @param type {AnyPatternType} - The type of the pattern (e.g., repeat, no-repeat).
36
+ * @returns {this} The current instance for chaining.
41
37
  */
42
38
  setType(type) {
43
39
  this.type = type;
44
40
  return this;
45
41
  }
46
42
  /**
47
- * Set the source of the pattern
48
- * @param src {string | LazyCanvas} - The `src` of the pattern
43
+ * Sets the source of the pattern.
44
+ * @param src {string | LazyCanvas} - The source of the pattern, which can be a string (URL or path) or a LazyCanvas instance.
45
+ * @returns {this} The current instance for chaining.
49
46
  */
50
47
  setSrc(src) {
51
48
  this.src = src;
52
49
  return this;
53
50
  }
51
+ /**
52
+ * Draws the pattern on a canvas context.
53
+ * @param ctx {SKRSContext2D} - The canvas rendering context.
54
+ * @returns {Promise<CanvasPattern | null>} The created pattern or null if the pattern could not be created.
55
+ */
54
56
  async draw(ctx) {
55
57
  if (this.src instanceof LazyCanvas_1.LazyCanvas) {
56
- let jmp = await this.src.render.render();
57
- let image = await (0, canvas_1.loadImage)(jmp);
58
- return ctx.createPattern(image, this.type);
58
+ return ctx.createPattern((await this.src.manager.render.render('canvas')), this.type);
59
59
  }
60
60
  else {
61
- let jmp = await jimp.read(this.src);
62
- let image = await (0, canvas_1.loadImage)(await jmp.getBufferAsync('image/png'));
63
- return ctx.createPattern(image, this.type);
61
+ return ctx.createPattern(await (0, canvas_1.loadImage)(this.src), this.type);
64
62
  }
65
63
  }
66
64
  /**
67
- * @returns {IPattern}
65
+ * Converts the Pattern instance to a JSON representation.
66
+ * @returns {IPattern} The JSON representation of the pattern.
68
67
  */
69
68
  toJSON() {
69
+ let src = this.src;
70
+ if (this.src instanceof LazyCanvas_1.LazyCanvas) {
71
+ // @ts-ignore
72
+ src = new Exporter_1.Exporter(this.src).syncExport('json');
73
+ }
70
74
  return {
75
+ fillType: this.fillType,
71
76
  type: this.type,
72
- src: this.src
77
+ src: src
73
78
  };
74
79
  }
75
80
  }
@@ -0,0 +1,6 @@
1
+ export * from "./Exporter";
2
+ export * from "./Font";
3
+ export * from "./Gradient";
4
+ export * from "./Link";
5
+ export * from "./Pattern";
6
+ export * from "./readers/JSONReader";
@@ -0,0 +1,22 @@
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("./Exporter"), exports);
18
+ __exportStar(require("./Font"), exports);
19
+ __exportStar(require("./Gradient"), exports);
20
+ __exportStar(require("./Link"), exports);
21
+ __exportStar(require("./Pattern"), exports);
22
+ __exportStar(require("./readers/JSONReader"), exports);
@@ -0,0 +1,49 @@
1
+ import { IOLazyCanvas, LazyCanvas } from "../../LazyCanvas";
2
+ /**
3
+ * Class responsible for reading and parsing JSON data into a LazyCanvas instance.
4
+ */
5
+ export declare class JSONReader {
6
+ /**
7
+ * Reads JSON data and converts it into a LazyCanvas instance.
8
+ * @param data {IOLazyCanvas} - The JSON data to read.
9
+ * @param opts {Object} - Optional settings.
10
+ * @param opts.debug {boolean} - Whether to enable debug logging.
11
+ * @returns {LazyCanvas} The created LazyCanvas instance.
12
+ * @throws {LazyError} If the data contains invalid options or no layers are found.
13
+ */
14
+ static read(data: IOLazyCanvas, opts?: {
15
+ debug?: boolean;
16
+ }): LazyCanvas;
17
+ /**
18
+ * Reads a JSON file and converts it into a LazyCanvas instance.
19
+ * @param file {string} - The path to the JSON file.
20
+ * @param opts {Object} - Optional settings.
21
+ * @param opts.debug {boolean} - Whether to enable debug logging.
22
+ * @returns {LazyCanvas} The created LazyCanvas instance.
23
+ * @throws {LazyError} If the file does not exist.
24
+ */
25
+ static readFile(file: string, opts?: {
26
+ debug?: boolean;
27
+ }): LazyCanvas;
28
+ /**
29
+ * Parses an array of JSON layers into an array of AnyLayer or Group instances.
30
+ * @param data {Array<JSONLayer | Group>} - The array of JSON layers to parse.
31
+ * @param opts {Object} - Optional settings.
32
+ * @param opts.debug {boolean} - Whether to enable debug logging.
33
+ * @returns {Array<AnyLayer | Group>} The parsed layers.
34
+ */
35
+ private static layersParse;
36
+ /**
37
+ * Parses a single JSON layer into an AnyLayer or Group instance.
38
+ * @param layer {JSONLayer | IGroup | Group} - The JSON layer to parse.
39
+ * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
40
+ * @returns {AnyLayer | Group} The parsed layer.
41
+ */
42
+ private static layerParse;
43
+ /**
44
+ * Parses the fill style of a layer.
45
+ * @param layer {JSONLayer} - The layer whose fill style is to be parsed.
46
+ * @returns {string | Gradient | Pattern} The parsed fill style.
47
+ */
48
+ private static fillParse;
49
+ }
@@ -0,0 +1,172 @@
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.JSONReader = void 0;
27
+ const types_1 = require("../../../types");
28
+ const components_1 = require("../../components");
29
+ const __1 = require("../");
30
+ const LazyCanvas_1 = require("../../LazyCanvas");
31
+ const fs = __importStar(require("fs"));
32
+ const LazyUtil_1 = require("../../../utils/LazyUtil");
33
+ const path = __importStar(require("path"));
34
+ /**
35
+ * Class responsible for reading and parsing JSON data into a LazyCanvas instance.
36
+ */
37
+ class JSONReader {
38
+ /**
39
+ * Reads JSON data and converts it into a LazyCanvas instance.
40
+ * @param data {IOLazyCanvas} - The JSON data to read.
41
+ * @param opts {Object} - Optional settings.
42
+ * @param opts.debug {boolean} - Whether to enable debug logging.
43
+ * @returns {LazyCanvas} The created LazyCanvas instance.
44
+ * @throws {LazyError} If the data contains invalid options or no layers are found.
45
+ */
46
+ static read(data, opts) {
47
+ if (data.options.width <= 0 || data.options.height <= 0) {
48
+ throw new LazyUtil_1.LazyError("Invalid width or height");
49
+ }
50
+ if (data.options.exportType === undefined) {
51
+ throw new LazyUtil_1.LazyError("Invalid export type");
52
+ }
53
+ if (data.options.flag === undefined) {
54
+ throw new LazyUtil_1.LazyError("Invalid export flag");
55
+ }
56
+ if (data.layers === undefined || data.layers.length === 0) {
57
+ throw new LazyUtil_1.LazyError("No layers found");
58
+ }
59
+ if (opts?.debug)
60
+ LazyUtil_1.LazyLog.log("info", "Reading JSON...\nOptions:", data.options, "\nAnimation:", data.animation, "\nLayers Number:", data.layers.length, "\nLayers:", data.layers);
61
+ const layers = JSONReader.layersParse(data.layers);
62
+ const canvas = new LazyCanvas_1.LazyCanvas({ settings: data, debug: opts?.debug })
63
+ .create(data.options.width, data.options.height);
64
+ canvas.manager.layers.add(...layers);
65
+ return canvas;
66
+ }
67
+ /**
68
+ * Reads a JSON file and converts it into a LazyCanvas instance.
69
+ * @param file {string} - The path to the JSON file.
70
+ * @param opts {Object} - Optional settings.
71
+ * @param opts.debug {boolean} - Whether to enable debug logging.
72
+ * @returns {LazyCanvas} The created LazyCanvas instance.
73
+ * @throws {LazyError} If the file does not exist.
74
+ */
75
+ static readFile(file, opts) {
76
+ const filePath = path.resolve(file);
77
+ if (!fs.existsSync(filePath))
78
+ throw new LazyUtil_1.LazyError("File not found");
79
+ const json = fs.readFileSync(filePath, "utf-8");
80
+ const data = JSON.parse(json);
81
+ if (opts?.debug)
82
+ LazyUtil_1.LazyLog.log("info", "Reading JSON file...\nFile:", filePath, "\nData:", data);
83
+ return JSONReader.read(data, opts);
84
+ }
85
+ /**
86
+ * Parses an array of JSON layers into an array of AnyLayer or Group instances.
87
+ * @param data {Array<JSONLayer | Group>} - The array of JSON layers to parse.
88
+ * @param opts {Object} - Optional settings.
89
+ * @param opts.debug {boolean} - Whether to enable debug logging.
90
+ * @returns {Array<AnyLayer | Group>} The parsed layers.
91
+ */
92
+ static layersParse(data, opts) {
93
+ return data.map((layer) => {
94
+ if (opts?.debug)
95
+ LazyUtil_1.LazyLog.log('info', `Parsing layer ${layer.id}...\nData:`, layer);
96
+ const misc = {
97
+ id: layer.id,
98
+ zIndex: layer.zIndex,
99
+ visible: layer.visible,
100
+ };
101
+ if (layer.type === types_1.LayerType.Group) {
102
+ return new components_1.Group(misc).add(...layer.layers.map((l) => this.layerParse(l)));
103
+ }
104
+ else {
105
+ return this.layerParse(layer, misc);
106
+ }
107
+ });
108
+ }
109
+ /**
110
+ * Parses a single JSON layer into an AnyLayer or Group instance.
111
+ * @param layer {JSONLayer | IGroup | Group} - The JSON layer to parse.
112
+ * @param misc {IBaseLayerMisc} - Miscellaneous options for the layer.
113
+ * @returns {AnyLayer | Group} The parsed layer.
114
+ */
115
+ static layerParse(layer, misc) {
116
+ if (layer instanceof components_1.Group) {
117
+ return new components_1.Group(misc).add(...layer.layers.map((l) => this.layerParse(l)));
118
+ }
119
+ else {
120
+ switch (layer.type) {
121
+ case types_1.LayerType.BezierCurve:
122
+ return new components_1.BezierLayer(layer.props, misc).setColor(this.fillParse(layer));
123
+ case types_1.LayerType.QuadraticCurve:
124
+ return new components_1.QuadraticLayer(layer.props, misc).setColor(this.fillParse(layer));
125
+ case types_1.LayerType.Image:
126
+ return new components_1.ImageLayer(layer.props, misc);
127
+ case types_1.LayerType.Text:
128
+ return new components_1.TextLayer(layer.props, misc).setColor(this.fillParse(layer));
129
+ case types_1.LayerType.Morph:
130
+ return new components_1.MorphLayer(layer.props, misc).setColor(this.fillParse(layer));
131
+ case types_1.LayerType.Line:
132
+ return new components_1.LineLayer(layer.props, misc).setColor(this.fillParse(layer));
133
+ case types_1.LayerType.Clear:
134
+ return new components_1.ClearLayer(layer.props, misc);
135
+ case types_1.LayerType.Path:
136
+ return new components_1.Path2DLayer(layer.props, misc).setColor(this.fillParse(layer));
137
+ case types_1.LayerType.Group:
138
+ return new components_1.Group(misc)
139
+ .add(...layer.layers.map((l) => this.layerParse(l)));
140
+ default:
141
+ return layer;
142
+ }
143
+ }
144
+ }
145
+ /**
146
+ * Parses the fill style of a layer.
147
+ * @param layer {JSONLayer} - The layer whose fill style is to be parsed.
148
+ * @returns {string | Gradient | Pattern} The parsed fill style.
149
+ */
150
+ static fillParse(layer) {
151
+ if ('fillStyle' in layer.props && layer.props.fillStyle && typeof layer.props.fillStyle !== 'string') {
152
+ switch (layer.props.fillStyle?.fillType) {
153
+ case 'gradient':
154
+ return new __1.Gradient({ props: layer.props.fillStyle });
155
+ case 'pattern':
156
+ console.log('Pattern:', layer.props.fillStyle);
157
+ return new __1.Pattern()
158
+ .setType(layer.props.fillStyle.type)
159
+ .setSrc(typeof layer.props.fillStyle.src === 'string' ? layer.props.fillStyle.src : this.read(layer.props.fillStyle.src));
160
+ default:
161
+ return layer.props.fillStyle;
162
+ }
163
+ }
164
+ else if ('fillStyle' in layer.props) {
165
+ return layer.props.fillStyle || '#000000';
166
+ }
167
+ else {
168
+ return '#000000';
169
+ }
170
+ }
171
+ }
172
+ exports.JSONReader = JSONReader;
@@ -0,0 +1,20 @@
1
+ export declare class SVGReader {
2
+ private static parseSVG;
3
+ private static createImageLayer;
4
+ private static createEllipseImageLayer;
5
+ private static createRectLayer;
6
+ private static createEllipseLayer;
7
+ private static createCircleLayer;
8
+ private static createLineLayer;
9
+ private static createGradient;
10
+ private static createPattern;
11
+ private static createPath2DLayer;
12
+ private static createClipPathLayer;
13
+ private static createGroupLayer;
14
+ private static applyTransform;
15
+ private static findElementById;
16
+ private static extractIdFromUrl;
17
+ private fillStyle;
18
+ private static handleUseElement;
19
+ static readSVG(svg: string): Promise<any>;
20
+ }