@nmmty/lazycanvas 0.5.3 → 0.6.0-dev.f33019

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 (32) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +2 -1
  3. package/dist/structures/components/BaseLayer.d.ts +3 -2
  4. package/dist/structures/components/BaseLayer.js +15 -10
  5. package/dist/structures/components/BezierLayer.d.ts +6 -0
  6. package/dist/structures/components/BezierLayer.js +23 -4
  7. package/dist/structures/components/ClearLayer.d.ts +1 -0
  8. package/dist/structures/components/ClearLayer.js +14 -8
  9. package/dist/structures/components/ImageLayer.d.ts +6 -0
  10. package/dist/structures/components/ImageLayer.js +21 -5
  11. package/dist/structures/components/LineLayer.d.ts +6 -0
  12. package/dist/structures/components/LineLayer.js +27 -6
  13. package/dist/structures/components/MorphLayer.d.ts +6 -0
  14. package/dist/structures/components/MorphLayer.js +25 -6
  15. package/dist/structures/components/Path2DLayer.d.ts +6 -0
  16. package/dist/structures/components/Path2DLayer.js +23 -1
  17. package/dist/structures/components/QuadraticLayer.d.ts +6 -0
  18. package/dist/structures/components/QuadraticLayer.js +23 -4
  19. package/dist/structures/components/TextLayer.d.ts +11 -5
  20. package/dist/structures/components/TextLayer.js +35 -23
  21. package/dist/structures/helpers/Gradient.d.ts +48 -11
  22. package/dist/structures/helpers/Gradient.js +133 -8
  23. package/dist/structures/helpers/index.d.ts +1 -0
  24. package/dist/structures/helpers/index.js +1 -0
  25. package/dist/structures/helpers/readers/JSONReader.js +3 -3
  26. package/dist/structures/helpers/readers/YAMLReader.d.ts +22 -0
  27. package/dist/structures/helpers/readers/YAMLReader.js +73 -0
  28. package/dist/utils/utils.d.ts +13 -3
  29. package/dist/utils/utils.js +59 -92
  30. package/package.json +3 -2
  31. package/animation.gif +0 -0
  32. package/test.png +0 -0
@@ -1,5 +1,6 @@
1
- import { AnyGradientType, FillType, StringColorType } from "../../types";
1
+ import { AnyCentring, AnyGradientType, FillType, StringColorType, ScaleType } from "../../types";
2
2
  import { SKRSContext2D } from "@napi-rs/canvas";
3
+ import { LayersManager } from "../managers/LayersManager";
3
4
  /**
4
5
  * Interface representing a gradient.
5
6
  */
@@ -20,6 +21,10 @@ export interface IGradient {
20
21
  * The color stops for the gradient.
21
22
  */
22
23
  stops: Array<GradientColorStop>;
24
+ /**
25
+ * The angle of the gradient (optional, used for linear gradients).
26
+ */
27
+ angle?: number;
23
28
  }
24
29
  /**
25
30
  * Interface representing a color stop in a gradient.
@@ -41,19 +46,15 @@ export interface GradientPoint {
41
46
  /**
42
47
  * The x-coordinate of the point.
43
48
  */
44
- x: number;
49
+ x: ScaleType;
45
50
  /**
46
51
  * The y-coordinate of the point.
47
52
  */
48
- y: number;
53
+ y: ScaleType;
49
54
  /**
50
55
  * The radius of the point (optional, used for radial gradients).
51
56
  */
52
57
  r?: number;
53
- /**
54
- * The starting angle of the point (optional, used for conic gradients).
55
- */
56
- startAngle?: number;
57
58
  }
58
59
  /**
59
60
  * Class representing a gradient with properties and methods to manipulate it.
@@ -75,6 +76,10 @@ export declare class Gradient implements IGradient {
75
76
  * The color stops for the gradient.
76
77
  */
77
78
  stops: Array<GradientColorStop>;
79
+ /**
80
+ * The angle of the gradient (optional, used for linear gradients).
81
+ */
82
+ angle?: number;
78
83
  /**
79
84
  * Constructs a new Gradient instance.
80
85
  * @param opts {Object} - Optional properties for the gradient.
@@ -95,6 +100,18 @@ export declare class Gradient implements IGradient {
95
100
  * @returns {this} The current instance for chaining.
96
101
  */
97
102
  addPoints(...points: GradientPoint[]): this;
103
+ /**
104
+ * Sets the points of the gradient.
105
+ * @param points {GradientPoint[]} - The points to set for the gradient.
106
+ * @returns {this} The current instance for chaining.
107
+ */
108
+ setPoints(...points: GradientPoint[]): this;
109
+ /**
110
+ * Removes points from the gradient by their indexes.
111
+ * @param indexes {number[]} - The indexes of the points to remove.
112
+ * @returns {this} The current instance for chaining.
113
+ */
114
+ removePoints(...indexes: number[]): this;
98
115
  /**
99
116
  * Adds color stops to the gradient.
100
117
  * @param stops {GradientColorStop[]} - The color stops to add to the gradient.
@@ -102,14 +119,34 @@ export declare class Gradient implements IGradient {
102
119
  */
103
120
  addStops(...stops: GradientColorStop[]): this;
104
121
  /**
105
- * Draws the gradient on a canvas context.
106
- * @param ctx {SKRSContext2D} - The canvas rendering context.
107
- * @returns {CanvasGradient} The created gradient.
122
+ * Sets the color stops of the gradient.
123
+ * @param stops {GradientColorStop[]} - The color stops to set for the gradient.
124
+ * @returns {this} The current instance for chaining.
125
+ */
126
+ setStops(...stops: GradientColorStop[]): this;
127
+ /**
128
+ * Removes color stops from the gradient by their indexes.
129
+ * @param indexes {number[]} - The indexes of the color stops to remove.
130
+ * @returns {this} The current instance for chaining.
108
131
  */
109
- draw(ctx: SKRSContext2D): CanvasGradient;
132
+ removeStops(...indexes: number[]): this;
133
+ setAngle(angle: number): this;
134
+ draw(ctx: SKRSContext2D, opts?: {
135
+ debug?: boolean;
136
+ layer?: {
137
+ width: number;
138
+ height: number;
139
+ x: number;
140
+ y: number;
141
+ align: AnyCentring;
142
+ };
143
+ manager?: LayersManager;
144
+ }): CanvasGradient;
110
145
  /**
111
146
  * Converts the gradient to a JSON representation.
112
147
  * @returns {IGradient} The JSON representation of the gradient.
113
148
  */
114
149
  toJSON(): IGradient;
150
+ private getLinearGradientPoints;
151
+ private getPosition;
115
152
  }
@@ -2,6 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Gradient = void 0;
4
4
  const types_1 = require("../../types");
5
+ const LazyUtil_1 = require("../../utils/LazyUtil");
6
+ const utils_1 = require("../../utils/utils");
5
7
  /**
6
8
  * Class representing a gradient with properties and methods to manipulate it.
7
9
  */
@@ -22,6 +24,10 @@ class Gradient {
22
24
  * The color stops for the gradient.
23
25
  */
24
26
  stops;
27
+ /**
28
+ * The angle of the gradient (optional, used for linear gradients).
29
+ */
30
+ angle;
25
31
  /**
26
32
  * Constructs a new Gradient instance.
27
33
  * @param opts {Object} - Optional properties for the gradient.
@@ -31,6 +37,7 @@ class Gradient {
31
37
  this.type = opts?.props?.type || types_1.GradientType.Linear;
32
38
  this.points = opts?.props?.points || [];
33
39
  this.stops = opts?.props?.stops || [];
40
+ this.angle = opts?.props?.angle || 0;
34
41
  }
35
42
  /**
36
43
  * Sets the type of the gradient.
@@ -50,6 +57,24 @@ class Gradient {
50
57
  this.points.push(...points);
51
58
  return this;
52
59
  }
60
+ /**
61
+ * Sets the points of the gradient.
62
+ * @param points {GradientPoint[]} - The points to set for the gradient.
63
+ * @returns {this} The current instance for chaining.
64
+ */
65
+ setPoints(...points) {
66
+ this.points = points;
67
+ return this;
68
+ }
69
+ /**
70
+ * Removes points from the gradient by their indexes.
71
+ * @param indexes {number[]} - The indexes of the points to remove.
72
+ * @returns {this} The current instance for chaining.
73
+ */
74
+ removePoints(...indexes) {
75
+ this.points = this.points.filter((_, index) => !indexes.includes(index));
76
+ return this;
77
+ }
53
78
  /**
54
79
  * Adds color stops to the gradient.
55
80
  * @param stops {GradientColorStop[]} - The color stops to add to the gradient.
@@ -60,28 +85,74 @@ class Gradient {
60
85
  return this;
61
86
  }
62
87
  /**
63
- * Draws the gradient on a canvas context.
64
- * @param ctx {SKRSContext2D} - The canvas rendering context.
65
- * @returns {CanvasGradient} The created gradient.
88
+ * Sets the color stops of the gradient.
89
+ * @param stops {GradientColorStop[]} - The color stops to set for the gradient.
90
+ * @returns {this} The current instance for chaining.
91
+ */
92
+ setStops(...stops) {
93
+ this.stops = stops;
94
+ return this;
95
+ }
96
+ /**
97
+ * Removes color stops from the gradient by their indexes.
98
+ * @param indexes {number[]} - The indexes of the color stops to remove.
99
+ * @returns {this} The current instance for chaining.
66
100
  */
67
- draw(ctx) {
101
+ removeStops(...indexes) {
102
+ this.stops = this.stops.filter((_, index) => !indexes.includes(index));
103
+ return this;
104
+ }
105
+ setAngle(angle) {
106
+ this.angle = angle;
107
+ return this;
108
+ }
109
+ draw(ctx, opts = { debug: false }) {
68
110
  let gradientData = this.toJSON();
69
111
  let gradient;
112
+ if (opts.debug)
113
+ LazyUtil_1.LazyLog.log('none', `Gradient:`, gradientData);
114
+ const parse = (0, utils_1.parser)(ctx, ctx.canvas, opts.manager);
115
+ const { x0, y0, x1, y1 } = parse.parseBatch({
116
+ x0: { v: gradientData.points[0]?.x || 0 },
117
+ y0: { v: gradientData.points[0]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) },
118
+ x1: { v: gradientData.points[1]?.x || 0 },
119
+ y1: { v: gradientData.points[1]?.y || 0, options: LazyUtil_1.defaultArg.vl(true) }
120
+ });
121
+ if (opts.debug)
122
+ LazyUtil_1.LazyLog.log('none', `Gradient points:`, { x0, y0, x1, y1 });
70
123
  switch (gradientData.type) {
71
124
  case types_1.GradientType.Linear:
72
125
  case "linear":
73
- gradient = ctx.createLinearGradient(gradientData.points[0].x, gradientData.points[0].y, gradientData.points[1].x, gradientData.points[1].y);
126
+ if (gradientData.type === "linear" && (gradientData.angle || gradientData.angle === 0) && opts.layer) {
127
+ const { width, height, x, y, align } = opts.layer;
128
+ const cx = this.getPosition(x, width, align, 'x');
129
+ const cy = this.getPosition(y, height, align, 'y');
130
+ const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
131
+ gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
132
+ }
133
+ else {
134
+ gradient = ctx.createLinearGradient(x0, y0, x1 || x0, y1 || y0);
135
+ }
74
136
  break;
75
137
  case types_1.GradientType.Radial:
76
138
  case "radial":
77
- 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);
139
+ gradient = ctx.createRadialGradient(x0, y0, gradientData.points[0].r || 0, x1 || x0, y1 || y0, gradientData.points[1].r || 0);
78
140
  break;
79
141
  case types_1.GradientType.Conic:
80
142
  case "conic":
81
- gradient = ctx.createConicGradient(gradientData.points[0].startAngle || 0, gradientData.points[0].x, gradientData.points[0].y);
143
+ gradient = ctx.createConicGradient((gradientData.angle || 0) * (Math.PI / 180), x0, y0);
82
144
  break;
83
145
  default:
84
- gradient = ctx.createLinearGradient(gradientData.points[0].x, gradientData.points[0].y, gradientData.points[1].x, gradientData.points[1].y);
146
+ if ((gradientData.angle || gradientData.angle === 0) && opts.layer) {
147
+ const { width, height, x, y, align } = opts.layer;
148
+ const cx = this.getPosition(x, width, align, 'x');
149
+ const cy = this.getPosition(y, height, align, 'y');
150
+ const [p1, p2] = this.getLinearGradientPoints(cx, cy, width, height, gradientData.angle);
151
+ gradient = ctx.createLinearGradient(p1.x, p1.y, p2.x, p2.y);
152
+ }
153
+ else {
154
+ gradient = ctx.createLinearGradient(x0, y0, x1 || x0, y1 || y0);
155
+ }
85
156
  break;
86
157
  }
87
158
  for (let stop of gradientData.stops) {
@@ -99,7 +170,61 @@ class Gradient {
99
170
  type: this.type,
100
171
  points: this.points,
101
172
  stops: this.stops,
173
+ angle: this.angle
102
174
  };
103
175
  }
176
+ getLinearGradientPoints(cx, cy, w, h, angleInDegrees) {
177
+ const angle = angleInDegrees * (Math.PI / 180);
178
+ const x1 = cx;
179
+ const y1 = cy - h / 2;
180
+ const x2 = cx;
181
+ const y2 = cy + h / 2;
182
+ const cos = Math.cos(angle);
183
+ const sin = Math.sin(angle);
184
+ const x1r = cx + (x1 - cx) * cos - (y1 - cy) * sin;
185
+ const y1r = cy + (x1 - cx) * sin + (y1 - cy) * cos;
186
+ const x2r = cx + (x2 - cx) * cos - (y2 - cy) * sin;
187
+ const y2r = cy + (x2 - cx) * sin + (y2 - cy) * cos;
188
+ return [
189
+ { x: x1r, y: y1r },
190
+ { x: x2r, y: y2r }
191
+ ];
192
+ }
193
+ getPosition(pos, side, align, type = 'x') {
194
+ switch (align) {
195
+ case types_1.Centring.StartTop:
196
+ case "start-top":
197
+ return type === 'x' ? pos + (side / 2) : pos + (side / 2);
198
+ case types_1.Centring.Start:
199
+ case "start":
200
+ return type === 'x' ? pos + (side / 2) : pos;
201
+ case types_1.Centring.StartBottom:
202
+ case "start-bottom":
203
+ return type === 'x' ? pos + (side / 2) : pos - (side / 2);
204
+ case types_1.Centring.CenterTop:
205
+ case "center-top":
206
+ return type === 'x' ? pos : pos - (side / 2);
207
+ case types_1.Centring.Center:
208
+ case "center":
209
+ return type === 'x' ? pos : pos;
210
+ case types_1.Centring.CenterBottom:
211
+ case "center-bottom":
212
+ return type === 'x' ? pos : pos - (side / 2);
213
+ case types_1.Centring.EndTop:
214
+ case "end-top":
215
+ return type === 'x' ? pos - (side / 2) : pos + (side / 2);
216
+ case types_1.Centring.End:
217
+ case "end":
218
+ return type === 'x' ? pos - (side / 2) : pos;
219
+ case types_1.Centring.EndBottom:
220
+ case "end-bottom":
221
+ return type === 'x' ? pos - (side / 2) : pos - (side / 2);
222
+ case types_1.Centring.None:
223
+ case "none":
224
+ return type === 'x' ? pos + (side / 2) : pos + (side / 2);
225
+ default:
226
+ throw new LazyUtil_1.LazyError(`Invalid centring type: ${align}`);
227
+ }
228
+ }
104
229
  }
105
230
  exports.Gradient = Gradient;
@@ -4,3 +4,4 @@ export * from "./Gradient";
4
4
  export * from "./Link";
5
5
  export * from "./Pattern";
6
6
  export * from "./readers/JSONReader";
7
+ export * from "./readers/YAMLReader";
@@ -20,3 +20,4 @@ __exportStar(require("./Gradient"), exports);
20
20
  __exportStar(require("./Link"), exports);
21
21
  __exportStar(require("./Pattern"), exports);
22
22
  __exportStar(require("./readers/JSONReader"), exports);
23
+ __exportStar(require("./readers/YAMLReader"), exports);
@@ -58,7 +58,7 @@ class JSONReader {
58
58
  }
59
59
  if (opts?.debug)
60
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);
61
+ const layers = JSONReader.layersParse(data.layers, opts);
62
62
  const canvas = new LazyCanvas_1.LazyCanvas({ settings: data, debug: opts?.debug })
63
63
  .create(data.options.width, data.options.height);
64
64
  canvas.manager.layers.add(...layers);
@@ -99,7 +99,7 @@ class JSONReader {
99
99
  visible: layer.visible,
100
100
  };
101
101
  if (layer.type === types_1.LayerType.Group) {
102
- return new components_1.Group(misc).add(...layer.layers.map((l) => this.layerParse(l)));
102
+ return new components_1.Group(misc).add(...layer.layers.map((l) => this.layerParse(l, { id: l.id, zIndex: l.zIndex, visible: l.visible })));
103
103
  }
104
104
  else {
105
105
  return this.layerParse(layer, misc);
@@ -153,7 +153,6 @@ class JSONReader {
153
153
  case 'gradient':
154
154
  return new __1.Gradient({ props: layer.props.fillStyle });
155
155
  case 'pattern':
156
- console.log('Pattern:', layer.props.fillStyle);
157
156
  return new __1.Pattern()
158
157
  .setType(layer.props.fillStyle.type)
159
158
  .setSrc(typeof layer.props.fillStyle.src === 'string' ? layer.props.fillStyle.src : this.read(layer.props.fillStyle.src));
@@ -162,6 +161,7 @@ class JSONReader {
162
161
  }
163
162
  }
164
163
  else if ('fillStyle' in layer.props) {
164
+ console.log(layer.type, layer);
165
165
  return layer.props.fillStyle || '#000000';
166
166
  }
167
167
  else {
@@ -0,0 +1,22 @@
1
+ import { LazyCanvas } from "../../LazyCanvas";
2
+ export declare class YAMLReader {
3
+ /**
4
+ * Reads a YAML string and converts it to a LazyCanvas object.
5
+ * @param data - The YAML string to read.
6
+ * @param opts - Optional parameters for debugging.
7
+ * @returns A Promise that resolves to a LazyCanvas object.
8
+ */
9
+ static read(data: string, opts?: {
10
+ debug?: boolean;
11
+ }): LazyCanvas;
12
+ /**
13
+ * Reads a YAML file and converts it to a LazyCanvas object.
14
+ * @param filePath - The path to the YAML file.
15
+ * @param opts - Optional parameters for debugging.
16
+ * @returns A Promise that resolves to a LazyCanvas object.
17
+ * @throws LazyError if the file does not exist or has an invalid extension.
18
+ */
19
+ static readFile(filePath: string, opts?: {
20
+ debug?: boolean;
21
+ }): LazyCanvas;
22
+ }
@@ -0,0 +1,73 @@
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.YAMLReader = void 0;
27
+ const JSONReader_1 = require("./JSONReader");
28
+ const _yaml = __importStar(require("js-yaml"));
29
+ const fs = __importStar(require("fs"));
30
+ const LazyUtil_1 = require("../../../utils/LazyUtil");
31
+ const path = __importStar(require("path"));
32
+ class YAMLReader {
33
+ /**
34
+ * Reads a YAML string and converts it to a LazyCanvas object.
35
+ * @param data - The YAML string to read.
36
+ * @param opts - Optional parameters for debugging.
37
+ * @returns A Promise that resolves to a LazyCanvas object.
38
+ */
39
+ static read(data, opts) {
40
+ const yamlContent = _yaml.load(data);
41
+ if (opts?.debug) {
42
+ LazyUtil_1.LazyLog.log('info', 'YAML content loaded:', yamlContent);
43
+ }
44
+ if (typeof yamlContent === 'object' && yamlContent !== null) {
45
+ return JSONReader_1.JSONReader.read(yamlContent, opts);
46
+ }
47
+ else {
48
+ throw new LazyUtil_1.LazyError("Invalid YAML content: Expected an object.");
49
+ }
50
+ }
51
+ /**
52
+ * Reads a YAML file and converts it to a LazyCanvas object.
53
+ * @param filePath - The path to the YAML file.
54
+ * @param opts - Optional parameters for debugging.
55
+ * @returns A Promise that resolves to a LazyCanvas object.
56
+ * @throws LazyError if the file does not exist or has an invalid extension.
57
+ */
58
+ static readFile(filePath, opts) {
59
+ if (!fs.existsSync(filePath)) {
60
+ throw new LazyUtil_1.LazyError(`File not found: ${filePath}`);
61
+ }
62
+ const ext = path.extname(filePath).toLowerCase();
63
+ if (ext !== '.yaml' && ext !== '.yml') {
64
+ throw new LazyUtil_1.LazyError(`Invalid file extension: ${ext}. Expected .yaml or .yml.`);
65
+ }
66
+ const data = fs.readFileSync(filePath, 'utf8');
67
+ if (opts?.debug) {
68
+ LazyUtil_1.LazyLog.log('info', `Reading YAML file: ${filePath}`);
69
+ }
70
+ return this.read(data, opts);
71
+ }
72
+ }
73
+ exports.YAMLReader = YAMLReader;
@@ -33,9 +33,19 @@ export declare function parser(ctx: SKRSContext2D, canvas: Canvas | SvgCanvas, m
33
33
  }>): Record<string, number>;
34
34
  };
35
35
  export declare function drawShadow(ctx: SKRSContext2D, shadow: any): void;
36
- export declare function opacity(ctx: SKRSContext2D, opacity: number): void;
37
- export declare function filters(ctx: SKRSContext2D, filters: string): void;
38
- export declare function parseFillStyle(ctx: SKRSContext2D, color: ColorType): string | CanvasGradient | Promise<CanvasPattern>;
36
+ export declare function opacity(ctx: SKRSContext2D, opacity?: number): void;
37
+ export declare function filters(ctx: SKRSContext2D, filters: string | null | undefined): void;
38
+ export declare function parseFillStyle(ctx: SKRSContext2D, color: ColorType, opts: {
39
+ debug?: boolean;
40
+ layer?: {
41
+ width: number;
42
+ height: number;
43
+ x: number;
44
+ y: number;
45
+ align: AnyCentring;
46
+ };
47
+ manager?: LayersManager;
48
+ }): string | Promise<CanvasPattern> | CanvasGradient;
39
49
  export declare function transform(ctx: SKRSContext2D, transform: Transform, layer?: {
40
50
  width: number;
41
51
  height: number;