@nmmty/lazycanvas 0.2.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 (53) hide show
  1. package/LICENSE +21 -0
  2. package/ReadMe.md +20 -0
  3. package/dist/helpers/Fonts.d.ts +7 -0
  4. package/dist/helpers/Fonts.js +32 -0
  5. package/dist/helpers/filters.d.ts +68 -0
  6. package/dist/helpers/filters.js +91 -0
  7. package/dist/index.d.ts +14 -0
  8. package/dist/index.js +39 -0
  9. package/dist/structures/LazyCanvas.d.ts +41 -0
  10. package/dist/structures/LazyCanvas.js +84 -0
  11. package/dist/structures/components/BaseLayer.d.ts +81 -0
  12. package/dist/structures/components/BaseLayer.js +157 -0
  13. package/dist/structures/components/Group.d.ts +50 -0
  14. package/dist/structures/components/Group.js +87 -0
  15. package/dist/structures/components/ImageLayer.d.ts +24 -0
  16. package/dist/structures/components/ImageLayer.js +106 -0
  17. package/dist/structures/components/MorphLayer.d.ts +39 -0
  18. package/dist/structures/components/MorphLayer.js +140 -0
  19. package/dist/structures/components/TextLayer.d.ts +69 -0
  20. package/dist/structures/components/TextLayer.js +225 -0
  21. package/dist/structures/helpers/Font.d.ts +35 -0
  22. package/dist/structures/helpers/Font.js +65 -0
  23. package/dist/structures/helpers/Gradient.d.ts +29 -0
  24. package/dist/structures/helpers/Gradient.js +72 -0
  25. package/dist/structures/helpers/Pattern.d.ts +24 -0
  26. package/dist/structures/helpers/Pattern.js +76 -0
  27. package/dist/structures/managers/FontsManager.d.ts +75 -0
  28. package/dist/structures/managers/FontsManager.js +150 -0
  29. package/dist/structures/managers/LayersManager.d.ts +71 -0
  30. package/dist/structures/managers/LayersManager.js +119 -0
  31. package/dist/structures/managers/RenderManager.d.ts +14 -0
  32. package/dist/structures/managers/RenderManager.js +44 -0
  33. package/dist/types/LazyCanvas.d.ts +16 -0
  34. package/dist/types/components/BaseLayer.d.ts +48 -0
  35. package/dist/types/components/Group.d.ts +6 -0
  36. package/dist/types/components/ImageLayer.d.ts +15 -0
  37. package/dist/types/components/MorphLayer.d.ts +14 -0
  38. package/dist/types/components/TextLayer.d.ts +26 -0
  39. package/dist/types/enum.d.ts +88 -0
  40. package/dist/types/enum.js +104 -0
  41. package/dist/types/helpers/Font.d.ts +12 -0
  42. package/dist/types/helpers/Gradient.d.ts +19 -0
  43. package/dist/types/helpers/Pattern.d.ts +7 -0
  44. package/dist/types/index.d.ts +13 -0
  45. package/dist/types/managers/FontsManager.d.ts +5 -0
  46. package/dist/types/managers/LayersManager.d.ts +6 -0
  47. package/dist/types/managers/RenderManager.d.ts +5 -0
  48. package/dist/types/types.d.ts +12 -0
  49. package/dist/utils/LazyUtil.d.ts +7 -0
  50. package/dist/utils/LazyUtil.js +27 -0
  51. package/dist/utils/utils.d.ts +39 -0
  52. package/dist/utils/utils.js +261 -0
  53. package/package.json +51 -0
@@ -0,0 +1,68 @@
1
+ /**
2
+ * List of CSS [`filters`](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) that can be used with the `filter` property. Use this functions to `setFilter` on the layer.
3
+ */
4
+ export declare const Filters: {
5
+ /**
6
+ * @description Applies a Gaussian blur to the input image. The value of `radius` defines the value of the standard deviation to the Gaussian function, or how many pixels on the screen blend into each other, so a larger value will create more blur. If no value is specified, it defaults to 0.
7
+ * @param radius {number} - The `radius` of the blur.
8
+ * @returns {string}
9
+ */
10
+ blur(radius: number): string;
11
+ /**
12
+ * @description Adjusts the brightness of the input image. A value of `0%` will create an image that is completely black, while a value of `100%` leaves the input unchanged. If no value is specified, it defaults to `100%`.
13
+ * @param amount {number} - The `amount` of the brightness.
14
+ * @returns {string}
15
+ */
16
+ brightness(amount: number): string;
17
+ /**
18
+ * @description Adjusts the contrast of the input image. A value of `0%` will create an image that is completely black, while a value of `100%` leaves the input unchanged. If no value is specified, it defaults to `100%`.
19
+ * @param amount {number} - The `amount` of the contrast.
20
+ * @returns {string}
21
+ */
22
+ contrast(amount: number): string;
23
+ /**
24
+ * @description Applies a drop shadow effect to the input image. The value of `color` is the color of the shadow. The `offsetX` and `offsetY` values are the horizontal and vertical distances of the shadow, and the `blurRadius` is the amount of blur. If no value is specified, it defaults to `0`.
25
+ * @param color {string} - The `color` of the shadow.
26
+ * @param offsetX {number} - The `offsetX` of the shadow.
27
+ * @param offsetY {number} - The `offsetY` of the shadow.
28
+ * @param blurRadius {number} - The `blurRadius` of the shadow.
29
+ * @returns {string}
30
+ */
31
+ dropShadow(color: string, offsetX: number, offsetY: number, blurRadius: number): string;
32
+ /**
33
+ * @description Converts the input image to grayscale. A value of `0%` is completely unmodified, while a value of `100%` will make the image completely grayscale.
34
+ * @param amount {number} - The `amount` of the grayscale.
35
+ * @returns {string}
36
+ */
37
+ grayscale(amount: number): string;
38
+ /**
39
+ * @description Applies a hue rotation to the input image. The value of `angle` defines the number of degrees around the color circle the input samples will be adjusted. A value of `0deg` leaves the input unchanged.
40
+ * @param angle {number} - The `angle` of the hue rotation.
41
+ * @returns {string}
42
+ */
43
+ hueRotate(angle: number): string;
44
+ /**
45
+ * @description Inverts the samples in the input image. A value of `0%` leaves the input unchanged, while a value of `100%` is completely inverted.
46
+ * @param amount {number} - The `amount` of the invert.
47
+ * @returns {string}
48
+ */
49
+ invert(amount: number): string;
50
+ /**
51
+ * @description Sets the opacity of the input image. A value of `0%` is completely transparent, while a value of `100%` is completely opaque.
52
+ * @param amount {number} - The `amount` of the opacity.
53
+ * @returns {string}
54
+ */
55
+ opacity(amount: number): string;
56
+ /**
57
+ * @description Saturates the input image. A value of `0%` is completely unmodified, while a value of `100%` is completely saturated.
58
+ * @param amount {number} - The `amount` of the saturation.
59
+ * @returns {string}
60
+ */
61
+ saturate(amount: number): string;
62
+ /**
63
+ * @description Converts the input image to sepia. A value of `0%` is completely unmodified, while a value of `100%` is completely sepia.
64
+ * @param amount {number} - The `amount` of the sepia.
65
+ * @returns {string}
66
+ */
67
+ sepia(amount: number): string;
68
+ };
@@ -0,0 +1,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Filters = void 0;
4
+ /**
5
+ * List of CSS [`filters`](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) that can be used with the `filter` property. Use this functions to `setFilter` on the layer.
6
+ */
7
+ exports.Filters = {
8
+ /**
9
+ * @description Applies a Gaussian blur to the input image. The value of `radius` defines the value of the standard deviation to the Gaussian function, or how many pixels on the screen blend into each other, so a larger value will create more blur. If no value is specified, it defaults to 0.
10
+ * @param radius {number} - The `radius` of the blur.
11
+ * @returns {string}
12
+ */
13
+ blur(radius) {
14
+ return `blur(${radius}px)`;
15
+ },
16
+ /**
17
+ * @description Adjusts the brightness of the input image. A value of `0%` will create an image that is completely black, while a value of `100%` leaves the input unchanged. If no value is specified, it defaults to `100%`.
18
+ * @param amount {number} - The `amount` of the brightness.
19
+ * @returns {string}
20
+ */
21
+ brightness(amount) {
22
+ return `brightness(${amount}%)`;
23
+ },
24
+ /**
25
+ * @description Adjusts the contrast of the input image. A value of `0%` will create an image that is completely black, while a value of `100%` leaves the input unchanged. If no value is specified, it defaults to `100%`.
26
+ * @param amount {number} - The `amount` of the contrast.
27
+ * @returns {string}
28
+ */
29
+ contrast(amount) {
30
+ return `contrast(${amount}%)`;
31
+ },
32
+ /**
33
+ * @description Applies a drop shadow effect to the input image. The value of `color` is the color of the shadow. The `offsetX` and `offsetY` values are the horizontal and vertical distances of the shadow, and the `blurRadius` is the amount of blur. If no value is specified, it defaults to `0`.
34
+ * @param color {string} - The `color` of the shadow.
35
+ * @param offsetX {number} - The `offsetX` of the shadow.
36
+ * @param offsetY {number} - The `offsetY` of the shadow.
37
+ * @param blurRadius {number} - The `blurRadius` of the shadow.
38
+ * @returns {string}
39
+ */
40
+ dropShadow(color, offsetX, offsetY, blurRadius) {
41
+ return `drop-shadow(${offsetX}px ${offsetY}px ${blurRadius}px ${color})`;
42
+ },
43
+ /**
44
+ * @description Converts the input image to grayscale. A value of `0%` is completely unmodified, while a value of `100%` will make the image completely grayscale.
45
+ * @param amount {number} - The `amount` of the grayscale.
46
+ * @returns {string}
47
+ */
48
+ grayscale(amount) {
49
+ return `grayscale(${amount}%)`;
50
+ },
51
+ /**
52
+ * @description Applies a hue rotation to the input image. The value of `angle` defines the number of degrees around the color circle the input samples will be adjusted. A value of `0deg` leaves the input unchanged.
53
+ * @param angle {number} - The `angle` of the hue rotation.
54
+ * @returns {string}
55
+ */
56
+ hueRotate(angle) {
57
+ return `hue-rotate(${angle}deg)`;
58
+ },
59
+ /**
60
+ * @description Inverts the samples in the input image. A value of `0%` leaves the input unchanged, while a value of `100%` is completely inverted.
61
+ * @param amount {number} - The `amount` of the invert.
62
+ * @returns {string}
63
+ */
64
+ invert(amount) {
65
+ return `invert(${amount}%)`;
66
+ },
67
+ /**
68
+ * @description Sets the opacity of the input image. A value of `0%` is completely transparent, while a value of `100%` is completely opaque.
69
+ * @param amount {number} - The `amount` of the opacity.
70
+ * @returns {string}
71
+ */
72
+ opacity(amount) {
73
+ return `opacity(${amount}%)`;
74
+ },
75
+ /**
76
+ * @description Saturates the input image. A value of `0%` is completely unmodified, while a value of `100%` is completely saturated.
77
+ * @param amount {number} - The `amount` of the saturation.
78
+ * @returns {string}
79
+ */
80
+ saturate(amount) {
81
+ return `saturate(${amount}%)`;
82
+ },
83
+ /**
84
+ * @description Converts the input image to sepia. A value of `0%` is completely unmodified, while a value of `100%` is completely sepia.
85
+ * @param amount {number} - The `amount` of the sepia.
86
+ * @returns {string}
87
+ */
88
+ sepia(amount) {
89
+ return `sepia(${amount}%)`;
90
+ }
91
+ };
@@ -0,0 +1,14 @@
1
+ import { LazyCanvas } from "./structures/LazyCanvas";
2
+ import { ImageLayer } from "./structures/components/ImageLayer";
3
+ import { MorphLayer } from "./structures/components/MorphLayer";
4
+ import { TextLayer } from "./structures/components/TextLayer";
5
+ import { BaseLayer } from "./structures/components/BaseLayer";
6
+ import { Group } from "./structures/components/Group";
7
+ import { LayerType, LayerScaleType, LineCap, LineJoin, TextAlign, TextDirection, TextBaseline, FontWeight, Export, Centring, PatternType, SaveFormat, GradientType } from "./types/enum";
8
+ import type { AnyLayer, ScaleType, ColorType, IFont, IFonts, IGradient, IPattern, IImageLayer, IImageLayerProps, IMorphLayer, IMorphLayerProps, ITextLayer, ITextLayerProps, IBaseLayer, IBaseLayerProps, IGroup } from "./types";
9
+ import { Font } from "./structures/helpers/Font";
10
+ import { Gradient } from "./structures/helpers/Gradient";
11
+ import { Pattern } from "./structures/helpers/Pattern";
12
+ import { saveFile } from "./utils/utils";
13
+ import { Filters } from "./helpers/filters";
14
+ export { LazyCanvas, ImageLayer, MorphLayer, TextLayer, BaseLayer, Group, Font, Gradient, Pattern, LayerScaleType, LayerType, FontWeight, GradientType, Export, LineCap, LineJoin, TextAlign, TextDirection, TextBaseline, SaveFormat, Centring, PatternType, saveFile, Filters, IFont, IFonts, IGradient, IPattern, IImageLayer, IImageLayerProps, IMorphLayer, IMorphLayerProps, ITextLayer, ITextLayerProps, IBaseLayer, IBaseLayerProps, IGroup, AnyLayer, ScaleType, ColorType, };
package/dist/index.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Filters = exports.saveFile = exports.PatternType = exports.Centring = exports.SaveFormat = exports.TextBaseline = exports.TextDirection = exports.TextAlign = exports.LineJoin = exports.LineCap = exports.Export = exports.GradientType = exports.FontWeight = exports.LayerType = exports.LayerScaleType = exports.Pattern = exports.Gradient = exports.Font = exports.Group = exports.BaseLayer = exports.TextLayer = exports.MorphLayer = exports.ImageLayer = exports.LazyCanvas = void 0;
4
+ const LazyCanvas_1 = require("./structures/LazyCanvas");
5
+ Object.defineProperty(exports, "LazyCanvas", { enumerable: true, get: function () { return LazyCanvas_1.LazyCanvas; } });
6
+ const ImageLayer_1 = require("./structures/components/ImageLayer");
7
+ Object.defineProperty(exports, "ImageLayer", { enumerable: true, get: function () { return ImageLayer_1.ImageLayer; } });
8
+ const MorphLayer_1 = require("./structures/components/MorphLayer");
9
+ Object.defineProperty(exports, "MorphLayer", { enumerable: true, get: function () { return MorphLayer_1.MorphLayer; } });
10
+ const TextLayer_1 = require("./structures/components/TextLayer");
11
+ Object.defineProperty(exports, "TextLayer", { enumerable: true, get: function () { return TextLayer_1.TextLayer; } });
12
+ const BaseLayer_1 = require("./structures/components/BaseLayer");
13
+ Object.defineProperty(exports, "BaseLayer", { enumerable: true, get: function () { return BaseLayer_1.BaseLayer; } });
14
+ const Group_1 = require("./structures/components/Group");
15
+ Object.defineProperty(exports, "Group", { enumerable: true, get: function () { return Group_1.Group; } });
16
+ const enum_1 = require("./types/enum");
17
+ Object.defineProperty(exports, "LayerType", { enumerable: true, get: function () { return enum_1.LayerType; } });
18
+ Object.defineProperty(exports, "LayerScaleType", { enumerable: true, get: function () { return enum_1.LayerScaleType; } });
19
+ Object.defineProperty(exports, "LineCap", { enumerable: true, get: function () { return enum_1.LineCap; } });
20
+ Object.defineProperty(exports, "LineJoin", { enumerable: true, get: function () { return enum_1.LineJoin; } });
21
+ Object.defineProperty(exports, "TextAlign", { enumerable: true, get: function () { return enum_1.TextAlign; } });
22
+ Object.defineProperty(exports, "TextDirection", { enumerable: true, get: function () { return enum_1.TextDirection; } });
23
+ Object.defineProperty(exports, "TextBaseline", { enumerable: true, get: function () { return enum_1.TextBaseline; } });
24
+ Object.defineProperty(exports, "FontWeight", { enumerable: true, get: function () { return enum_1.FontWeight; } });
25
+ Object.defineProperty(exports, "Export", { enumerable: true, get: function () { return enum_1.Export; } });
26
+ Object.defineProperty(exports, "Centring", { enumerable: true, get: function () { return enum_1.Centring; } });
27
+ Object.defineProperty(exports, "PatternType", { enumerable: true, get: function () { return enum_1.PatternType; } });
28
+ Object.defineProperty(exports, "SaveFormat", { enumerable: true, get: function () { return enum_1.SaveFormat; } });
29
+ Object.defineProperty(exports, "GradientType", { enumerable: true, get: function () { return enum_1.GradientType; } });
30
+ const Font_1 = require("./structures/helpers/Font");
31
+ Object.defineProperty(exports, "Font", { enumerable: true, get: function () { return Font_1.Font; } });
32
+ const Gradient_1 = require("./structures/helpers/Gradient");
33
+ Object.defineProperty(exports, "Gradient", { enumerable: true, get: function () { return Gradient_1.Gradient; } });
34
+ const Pattern_1 = require("./structures/helpers/Pattern");
35
+ Object.defineProperty(exports, "Pattern", { enumerable: true, get: function () { return Pattern_1.Pattern; } });
36
+ const utils_1 = require("./utils/utils");
37
+ Object.defineProperty(exports, "saveFile", { enumerable: true, get: function () { return utils_1.saveFile; } });
38
+ const filters_1 = require("./helpers/filters");
39
+ Object.defineProperty(exports, "Filters", { enumerable: true, get: function () { return filters_1.Filters; } });
@@ -0,0 +1,41 @@
1
+ import { Export } from "../types/enum";
2
+ import { IFonts, ILazyCanvas } from "../types";
3
+ import { Canvas, SKRSContext2D, SvgExportFlag } from "@napi-rs/canvas";
4
+ import { LayersManager } from "./managers/LayersManager";
5
+ import { RenderManager } from "./managers/RenderManager";
6
+ import { FontsManager } from "./managers/FontsManager";
7
+ export declare class LazyCanvas implements ILazyCanvas {
8
+ width: number | 0;
9
+ height: number | 0;
10
+ canvas: Canvas;
11
+ ctx: SKRSContext2D;
12
+ layers: LayersManager;
13
+ render: RenderManager;
14
+ fonts: FontsManager;
15
+ exportType: Export;
16
+ constructor();
17
+ /**
18
+ * Set the export type
19
+ * @param type {Export} - The `export` type
20
+ */
21
+ setExportType(type: Export): this;
22
+ /**
23
+ * Replace base fonts with custom fonts by special file.
24
+ * Use this method before loading fonts by `FontManager`.
25
+ * The file should be generated by the following instructions:
26
+ * @see https://github.com/NMMTY/LazyCanvas/blob/main/scripts/FontsGenerate.md
27
+ * @param fonts {IFonts[]} - The `fonts` to set
28
+ */
29
+ setFonts(fonts: IFonts): this;
30
+ /**
31
+ * Set the SVG export flag. This method should be called after `setExportType` method.
32
+ * @param flag {SvgExportFlag} - The `flag` of the SVG export
33
+ */
34
+ setSvgExportFlag(flag: SvgExportFlag): this;
35
+ /**
36
+ * Create a new canvas. This method should be called before any other methods.
37
+ * @param width {number} - The `width` of the canvas
38
+ * @param height {number} - The `height` of the canvas
39
+ */
40
+ create(width: number, height: number): this;
41
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LazyCanvas = void 0;
4
+ const enum_1 = require("../types/enum");
5
+ const canvas_1 = require("@napi-rs/canvas");
6
+ const LayersManager_1 = require("./managers/LayersManager");
7
+ const RenderManager_1 = require("./managers/RenderManager");
8
+ const FontsManager_1 = require("./managers/FontsManager");
9
+ class LazyCanvas {
10
+ width;
11
+ height;
12
+ canvas;
13
+ ctx;
14
+ layers;
15
+ render;
16
+ fonts;
17
+ exportType;
18
+ constructor() {
19
+ this.width = 0;
20
+ this.height = 0;
21
+ this.canvas = new canvas_1.Canvas(0, 0);
22
+ this.ctx = this.canvas.getContext('2d');
23
+ this.layers = new LayersManager_1.LayersManager();
24
+ this.render = new RenderManager_1.RenderManager(this);
25
+ this.fonts = new FontsManager_1.FontsManager();
26
+ this.exportType = enum_1.Export.Buffer;
27
+ }
28
+ /**
29
+ * Set the export type
30
+ * @param type {Export} - The `export` type
31
+ */
32
+ setExportType(type) {
33
+ this.exportType = type;
34
+ switch (type) {
35
+ case enum_1.Export.Buffer:
36
+ this.canvas = new canvas_1.Canvas(this.width, this.height);
37
+ this.ctx = this.canvas.getContext('2d');
38
+ break;
39
+ case enum_1.Export.CTX:
40
+ break;
41
+ case enum_1.Export.SVG:
42
+ this.canvas = new canvas_1.Canvas(this.width, this.height, canvas_1.SvgExportFlag.RelativePathEncoding);
43
+ this.ctx = this.canvas.getContext('2d');
44
+ break;
45
+ }
46
+ return this;
47
+ }
48
+ /**
49
+ * Replace base fonts with custom fonts by special file.
50
+ * Use this method before loading fonts by `FontManager`.
51
+ * The file should be generated by the following instructions:
52
+ * @see https://github.com/NMMTY/LazyCanvas/blob/main/scripts/FontsGenerate.md
53
+ * @param fonts {IFonts[]} - The `fonts` to set
54
+ */
55
+ setFonts(fonts) {
56
+ this.fonts = new FontsManager_1.FontsManager(fonts);
57
+ return this;
58
+ }
59
+ /**
60
+ * Set the SVG export flag. This method should be called after `setExportType` method.
61
+ * @param flag {SvgExportFlag} - The `flag` of the SVG export
62
+ */
63
+ setSvgExportFlag(flag) {
64
+ if (this.exportType === enum_1.Export.SVG) {
65
+ this.canvas = new canvas_1.Canvas(this.width, this.height, flag);
66
+ this.ctx = this.canvas.getContext('2d');
67
+ }
68
+ return this;
69
+ }
70
+ /**
71
+ * Create a new canvas. This method should be called before any other methods.
72
+ * @param width {number} - The `width` of the canvas
73
+ * @param height {number} - The `height` of the canvas
74
+ */
75
+ create(width, height) {
76
+ this.width = width;
77
+ this.height = height;
78
+ this.canvas = new canvas_1.Canvas(width, height);
79
+ this.ctx = this.canvas.getContext('2d');
80
+ this.layers = new LayersManager_1.LayersManager();
81
+ return this;
82
+ }
83
+ }
84
+ exports.LazyCanvas = LazyCanvas;
@@ -0,0 +1,81 @@
1
+ import { ScaleType, IBaseLayer, IBaseLayerProps } from "../../types";
2
+ import { Centring, LayerType } from "../../types/enum";
3
+ export declare class BaseLayer<T extends IBaseLayerProps> {
4
+ id: string;
5
+ type: LayerType;
6
+ zIndex: number;
7
+ visible: boolean;
8
+ props: T;
9
+ constructor(type?: LayerType, props?: T);
10
+ /**
11
+ * @description Position of the layer in the 2D plane. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
12
+ * @param x {ScaleType} - The `x` position of the layer
13
+ * @param y {ScaleType} - The `y` position of the layer
14
+ */
15
+ setPosition(x: ScaleType, y: ScaleType): this;
16
+ /**
17
+ * @description Opacity of the layer. The value must be between `0` and `1`.
18
+ * @param opacity {number} - The `opacity` of the layer
19
+ */
20
+ setOpacity(opacity: number): this;
21
+ /**
22
+ * @description Sets the `id` of the layer.
23
+ * @param id {string} - The `id` of the layer
24
+ */
25
+ setID(id: string): this;
26
+ /**
27
+ * @description Sets shadow of layer.
28
+ * @param color {string} - The `color` of the filter
29
+ * @param blur {number} - The `blur` of the filter
30
+ * @param offsetX {number} - The `offsetX` of the filter
31
+ * @param offsetY {number} - The `offsetY` of the filter
32
+ */
33
+ setShadow(color: string, blur?: number, offsetX?: number, offsetY?: number): this;
34
+ /**
35
+ * @description Matrix of the layer in the 2D plane.
36
+ * @param matrix {DOMMatrix2DInit} - The `matrix` of the layer
37
+ */
38
+ setMatrix(matrix: DOMMatrix2DInit): this;
39
+ /**
40
+ * @description Scale of the layer in the x and y direction by the given amount from their current position.
41
+ * @param x {number} - The `x` scale of the layer
42
+ * @param y {number} - The `y` scale of the layer
43
+ */
44
+ setScale(x: number, y: number): this;
45
+ /**
46
+ * @description Rotate of the layer in the clockwise direction by the given amount from its current position.
47
+ * @param rotate {number} - The `rotate` of the layer
48
+ */
49
+ setRotate(rotate: number): this;
50
+ /**
51
+ * @description Translate of the layer in the x and y direction by the given amount from their current position.
52
+ * @param x {number} - The `x` translation of the layer
53
+ * @param y {number} - The `y` translation of the layer
54
+ */
55
+ setTranslate(x: number, y: number): this;
56
+ /**
57
+ * @description The **`CanvasRenderingContext2D`**. filter property of the Canvas 2D API provides filter effects such as blurring and grayscaling.
58
+ * It is similar to the CSS [`filter`](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) property and accepts the same values.
59
+ * @param filter {string} - The `filter` of the layer. Not support multiple filters.
60
+ */
61
+ setFilter(filter: string): this;
62
+ /**
63
+ * @description Sets type of centring of the layer.
64
+ * @param centring {Centring} - The `centring` of the layer
65
+ */
66
+ setCentring(centring: Centring): this;
67
+ /**
68
+ * @description Sets the visibility of the layer.
69
+ * @param visible {boolean} - The `visibility` of the layer
70
+ */
71
+ setVisible(visible: boolean): this;
72
+ /**
73
+ * @description Sets zIndex of the layer.
74
+ * @param zIndex {number} - The `zIndex` of the layer
75
+ */
76
+ setZIndex(zIndex: number): this;
77
+ /**
78
+ * @returns {IBaseLayer}
79
+ */
80
+ toJSON(): IBaseLayer;
81
+ }
@@ -0,0 +1,157 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseLayer = void 0;
4
+ const enum_1 = require("../../types/enum");
5
+ const utils_1 = require("../../utils/utils");
6
+ const LazyUtil_1 = require("../../utils/LazyUtil");
7
+ class BaseLayer {
8
+ id;
9
+ type;
10
+ zIndex;
11
+ visible;
12
+ props;
13
+ constructor(type, props) {
14
+ this.id = (0, utils_1.generateID)(type ? type : enum_1.LayerType.Base);
15
+ this.type = type ? type : enum_1.LayerType.Base;
16
+ this.zIndex = 1;
17
+ this.visible = true;
18
+ this.props = props ? props : {};
19
+ if (!this.props.x)
20
+ this.props.x = 0;
21
+ if (!this.props.y)
22
+ this.props.y = 0;
23
+ if (!this.props.opacity)
24
+ this.props.opacity = 1;
25
+ if (!this.props.centring)
26
+ this.props.centring = enum_1.Centring.Center;
27
+ if (!this.props.transform)
28
+ this.props.transform = {};
29
+ }
30
+ /**
31
+ * @description Position of the layer in the 2D plane. You can use `numbers`, `percentages`, `px`, `vw`, `vh`, `vmin`, `vmax`.
32
+ * @param x {ScaleType} - The `x` position of the layer
33
+ * @param y {ScaleType} - The `y` position of the layer
34
+ */
35
+ setPosition(x, y) {
36
+ this.props.x = x;
37
+ this.props.y = y;
38
+ return this;
39
+ }
40
+ /**
41
+ * @description Opacity of the layer. The value must be between `0` and `1`.
42
+ * @param opacity {number} - The `opacity` of the layer
43
+ */
44
+ setOpacity(opacity) {
45
+ this.props.opacity = opacity;
46
+ return this;
47
+ }
48
+ /**
49
+ * @description Sets the `id` of the layer.
50
+ * @param id {string} - The `id` of the layer
51
+ */
52
+ setID(id) {
53
+ this.id = id;
54
+ return this;
55
+ }
56
+ /**
57
+ * @description Sets shadow of layer.
58
+ * @param color {string} - The `color` of the filter
59
+ * @param blur {number} - The `blur` of the filter
60
+ * @param offsetX {number} - The `offsetX` of the filter
61
+ * @param offsetY {number} - The `offsetY` of the filter
62
+ */
63
+ setShadow(color, blur, offsetX, offsetY) {
64
+ if (!color)
65
+ throw new LazyUtil_1.LazyError('The color of the shadow must be provided');
66
+ if (!(0, utils_1.isColor)(color))
67
+ throw new LazyUtil_1.LazyError('The color of the shadow must be a valid color');
68
+ let parse = (0, utils_1.parseColor)(color);
69
+ this.props.shadow = {
70
+ color: parse,
71
+ blur: blur || 0,
72
+ offsetX: offsetX || 0,
73
+ offsetY: offsetY || 0,
74
+ };
75
+ return this;
76
+ }
77
+ /**
78
+ * @description Matrix of the layer in the 2D plane.
79
+ * @param matrix {DOMMatrix2DInit} - The `matrix` of the layer
80
+ */
81
+ setMatrix(matrix) {
82
+ this.props.transform = { ...this.props.transform, matrix };
83
+ return this;
84
+ }
85
+ /**
86
+ * @description Scale of the layer in the x and y direction by the given amount from their current position.
87
+ * @param x {number} - The `x` scale of the layer
88
+ * @param y {number} - The `y` scale of the layer
89
+ */
90
+ setScale(x, y) {
91
+ this.props.transform = { ...this.props.transform, scale: { x, y } };
92
+ return this;
93
+ }
94
+ /**
95
+ * @description Rotate of the layer in the clockwise direction by the given amount from its current position.
96
+ * @param rotate {number} - The `rotate` of the layer
97
+ */
98
+ setRotate(rotate) {
99
+ this.props.transform = { ...this.props.transform, rotate };
100
+ return this;
101
+ }
102
+ /**
103
+ * @description Translate of the layer in the x and y direction by the given amount from their current position.
104
+ * @param x {number} - The `x` translation of the layer
105
+ * @param y {number} - The `y` translation of the layer
106
+ */
107
+ setTranslate(x, y) {
108
+ this.props.transform = { ...this.props.transform, translate: { x, y } };
109
+ return this;
110
+ }
111
+ /**
112
+ * @description The **`CanvasRenderingContext2D`**. filter property of the Canvas 2D API provides filter effects such as blurring and grayscaling.
113
+ * It is similar to the CSS [`filter`](https://developer.mozilla.org/en-US/docs/Web/CSS/filter) property and accepts the same values.
114
+ * @param filter {string} - The `filter` of the layer. Not support multiple filters.
115
+ */
116
+ setFilter(filter) {
117
+ this.props.filter = filter;
118
+ return this;
119
+ }
120
+ /**
121
+ * @description Sets type of centring of the layer.
122
+ * @param centring {Centring} - The `centring` of the layer
123
+ */
124
+ setCentring(centring) {
125
+ this.props.centring = centring;
126
+ return this;
127
+ }
128
+ /**
129
+ * @description Sets the visibility of the layer.
130
+ * @param visible {boolean} - The `visibility` of the layer
131
+ */
132
+ setVisible(visible) {
133
+ this.visible = visible;
134
+ return this;
135
+ }
136
+ /**
137
+ * @description Sets zIndex of the layer.
138
+ * @param zIndex {number} - The `zIndex` of the layer
139
+ */
140
+ setZIndex(zIndex) {
141
+ this.zIndex = zIndex;
142
+ return this;
143
+ }
144
+ /**
145
+ * @returns {IBaseLayer}
146
+ */
147
+ toJSON() {
148
+ return {
149
+ id: this.id,
150
+ type: this.type,
151
+ zIndex: this.zIndex,
152
+ visible: this.visible,
153
+ props: this.props,
154
+ };
155
+ }
156
+ }
157
+ exports.BaseLayer = BaseLayer;
@@ -0,0 +1,50 @@
1
+ import { AnyLayer, IGroup } from "../../types";
2
+ export declare class Group implements IGroup {
3
+ id: string;
4
+ visible: boolean;
5
+ zIndex: number;
6
+ components: Array<any>;
7
+ constructor();
8
+ /**
9
+ * Set the ID of the group
10
+ * @param id {string} - The `id` of the group
11
+ */
12
+ setID(id: string): this;
13
+ /**
14
+ * Set the visibility of the group
15
+ * @param visible {boolean} - The `visibility` of the group
16
+ */
17
+ setVisible(visible: boolean): this;
18
+ /**
19
+ * Set the zIndex of the group
20
+ * @param zIndex {number} - The `zIndex` of the group
21
+ */
22
+ setZIndex(zIndex: number): this;
23
+ /**
24
+ * Add a component to the group
25
+ * @param components {any[]} - The `components` to add to the group
26
+ */
27
+ add(...components: AnyLayer[]): this;
28
+ /**
29
+ * Remove a component from the group
30
+ * @param id {any} - The `id` of the component to remove
31
+ */
32
+ remove(id: string): this;
33
+ /**
34
+ * Clear all components from the group
35
+ */
36
+ clear(): this;
37
+ /**
38
+ * Get a component from the group
39
+ * @param id {string} - The `id` of the component to get
40
+ */
41
+ get(id: string): any;
42
+ /**
43
+ * Get all components from the group
44
+ */
45
+ getAll(): any[];
46
+ /**
47
+ * Get the length of the components
48
+ */
49
+ get length(): number;
50
+ }