@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.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/structures/components/BaseLayer.d.ts +3 -2
- package/dist/structures/components/BaseLayer.js +15 -10
- package/dist/structures/components/BezierLayer.d.ts +6 -0
- package/dist/structures/components/BezierLayer.js +23 -4
- package/dist/structures/components/ClearLayer.d.ts +1 -0
- package/dist/structures/components/ClearLayer.js +14 -8
- package/dist/structures/components/ImageLayer.d.ts +6 -0
- package/dist/structures/components/ImageLayer.js +21 -5
- package/dist/structures/components/LineLayer.d.ts +6 -0
- package/dist/structures/components/LineLayer.js +27 -6
- package/dist/structures/components/MorphLayer.d.ts +6 -0
- package/dist/structures/components/MorphLayer.js +25 -6
- package/dist/structures/components/Path2DLayer.d.ts +6 -0
- package/dist/structures/components/Path2DLayer.js +23 -1
- package/dist/structures/components/QuadraticLayer.d.ts +6 -0
- package/dist/structures/components/QuadraticLayer.js +23 -4
- package/dist/structures/components/TextLayer.d.ts +11 -5
- package/dist/structures/components/TextLayer.js +35 -23
- package/dist/structures/helpers/Gradient.d.ts +48 -11
- package/dist/structures/helpers/Gradient.js +133 -8
- package/dist/structures/helpers/index.d.ts +1 -0
- package/dist/structures/helpers/index.js +1 -0
- package/dist/structures/helpers/readers/JSONReader.js +3 -3
- package/dist/structures/helpers/readers/YAMLReader.d.ts +22 -0
- package/dist/structures/helpers/readers/YAMLReader.js +73 -0
- package/dist/utils/utils.d.ts +13 -3
- package/dist/utils/utils.js +59 -92
- package/package.json +3 -2
- package/animation.gif +0 -0
- package/test.png +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { IRenderManager } from "./structures/managers/RenderManager";
|
|
|
5
5
|
export { ILayersManager } from "./structures/managers/LayersManager";
|
|
6
6
|
export * from "./structures/components";
|
|
7
7
|
export { LayerType, LayerScaleType, LineCap, LineJoin, TextAlign, TextDirection, TextBaseline, FontWeight, Export, Centring, PatternType, GradientType, LinkType } from "./types";
|
|
8
|
-
export { Font, IFont, IFonts, Gradient, IGradient, GradientPoint, GradientColorStop, Pattern, IPattern, Link, ILink, Exporter, JSONReader } from "./structures/helpers";
|
|
8
|
+
export { Font, IFont, IFonts, Gradient, IGradient, GradientPoint, GradientColorStop, Pattern, IPattern, Link, ILink, Exporter, JSONReader, YAMLReader } from "./structures/helpers";
|
|
9
9
|
export { Filters } from "./helpers/Filters";
|
|
10
10
|
export { FontsList } from "./helpers/FontsList";
|
|
11
11
|
export type { AnyLayer, AnyCentring, AnyPatternType, AnyGradientType, AnyTextAlign, AnyTextDirection, AnyTextBaseline, AnyWeight, AnyLineCap, AnyLineJoin, AnyExport, AnyLinkType, AnyGlobalCompositeOperation, AnyColorSpace, ScaleType, ColorType, Point, PointNumber, Transform, Extensions } from "./types";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.FontsList = exports.Filters = exports.JSONReader = exports.Exporter = exports.Link = exports.Pattern = exports.Gradient = exports.Font = exports.LinkType = exports.GradientType = exports.PatternType = exports.Centring = exports.Export = exports.FontWeight = exports.TextBaseline = exports.TextDirection = exports.TextAlign = exports.LineJoin = exports.LineCap = exports.LayerScaleType = exports.LayerType = exports.LazyCanvas = void 0;
|
|
17
|
+
exports.FontsList = exports.Filters = exports.YAMLReader = exports.JSONReader = exports.Exporter = exports.Link = exports.Pattern = exports.Gradient = exports.Font = exports.LinkType = exports.GradientType = exports.PatternType = exports.Centring = exports.Export = exports.FontWeight = exports.TextBaseline = exports.TextDirection = exports.TextAlign = exports.LineJoin = exports.LineCap = exports.LayerScaleType = exports.LayerType = exports.LazyCanvas = void 0;
|
|
18
18
|
var LazyCanvas_1 = require("./structures/LazyCanvas");
|
|
19
19
|
Object.defineProperty(exports, "LazyCanvas", { enumerable: true, get: function () { return LazyCanvas_1.LazyCanvas; } });
|
|
20
20
|
__exportStar(require("./structures/components"), exports);
|
|
@@ -39,6 +39,7 @@ Object.defineProperty(exports, "Pattern", { enumerable: true, get: function () {
|
|
|
39
39
|
Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return helpers_1.Link; } });
|
|
40
40
|
Object.defineProperty(exports, "Exporter", { enumerable: true, get: function () { return helpers_1.Exporter; } });
|
|
41
41
|
Object.defineProperty(exports, "JSONReader", { enumerable: true, get: function () { return helpers_1.JSONReader; } });
|
|
42
|
+
Object.defineProperty(exports, "YAMLReader", { enumerable: true, get: function () { return helpers_1.YAMLReader; } });
|
|
42
43
|
var Filters_1 = require("./helpers/Filters");
|
|
43
44
|
Object.defineProperty(exports, "Filters", { enumerable: true, get: function () { return Filters_1.Filters; } });
|
|
44
45
|
var FontsList_1 = require("./helpers/FontsList");
|
|
@@ -43,7 +43,7 @@ export interface IBaseLayerProps {
|
|
|
43
43
|
/**
|
|
44
44
|
* The filter effects applied to the layer.
|
|
45
45
|
*/
|
|
46
|
-
filter
|
|
46
|
+
filter?: string;
|
|
47
47
|
/**
|
|
48
48
|
* The opacity of the layer, ranging from 0 to 1.
|
|
49
49
|
*/
|
|
@@ -59,7 +59,7 @@ export interface IBaseLayerProps {
|
|
|
59
59
|
/**
|
|
60
60
|
* The shadow properties of the layer.
|
|
61
61
|
*/
|
|
62
|
-
shadow
|
|
62
|
+
shadow?: {
|
|
63
63
|
/**
|
|
64
64
|
* The color of the shadow.
|
|
65
65
|
*/
|
|
@@ -233,4 +233,5 @@ export declare class BaseLayer<T extends IBaseLayerProps> {
|
|
|
233
233
|
* @returns {IBaseLayer} The JSON representation of the layer.
|
|
234
234
|
*/
|
|
235
235
|
toJSON(): IBaseLayer;
|
|
236
|
+
protected validateProps(data: T): T;
|
|
236
237
|
}
|
|
@@ -48,16 +48,7 @@ class BaseLayer {
|
|
|
48
48
|
this.zIndex = misc?.zIndex || 1;
|
|
49
49
|
this.visible = misc?.visible || true;
|
|
50
50
|
this.props = props ? props : {};
|
|
51
|
-
|
|
52
|
-
this.props.x = 0;
|
|
53
|
-
if (!this.props.y)
|
|
54
|
-
this.props.y = 0;
|
|
55
|
-
if (!this.props.opacity)
|
|
56
|
-
this.props.opacity = 1;
|
|
57
|
-
if (!this.props.centring)
|
|
58
|
-
this.props.centring = types_1.Centring.Center;
|
|
59
|
-
if (!this.props.transform)
|
|
60
|
-
this.props.transform = {};
|
|
51
|
+
this.props = this.validateProps(this.props);
|
|
61
52
|
}
|
|
62
53
|
/**
|
|
63
54
|
* Sets the position of the layer in the 2D plane.
|
|
@@ -207,5 +198,19 @@ class BaseLayer {
|
|
|
207
198
|
props: this.props,
|
|
208
199
|
};
|
|
209
200
|
}
|
|
201
|
+
validateProps(data) {
|
|
202
|
+
return {
|
|
203
|
+
...data,
|
|
204
|
+
x: data.x || 0,
|
|
205
|
+
y: data.y || 0,
|
|
206
|
+
centring: data.centring || types_1.Centring.Center,
|
|
207
|
+
filter: data.filter || '',
|
|
208
|
+
opacity: data.opacity || 1,
|
|
209
|
+
filled: data.filled || false,
|
|
210
|
+
fillStyle: data.fillStyle || '#000000',
|
|
211
|
+
transform: data.transform || {},
|
|
212
|
+
globalComposite: data.globalComposite || 'source-over',
|
|
213
|
+
};
|
|
214
|
+
}
|
|
210
215
|
}
|
|
211
216
|
exports.BaseLayer = BaseLayer;
|
|
@@ -133,4 +133,10 @@ export declare class BezierLayer extends BaseLayer<IBezierLayerProps> {
|
|
|
133
133
|
* @returns {IBezierLayer} The JSON representation of the Bezier layer.
|
|
134
134
|
*/
|
|
135
135
|
toJSON(): IBezierLayer;
|
|
136
|
+
/**
|
|
137
|
+
* Validates the properties of the Bezier layer.
|
|
138
|
+
* @param data {IBezierLayerProps} - The properties to validate.
|
|
139
|
+
* @returns {IBezierLayerProps} The validated properties.
|
|
140
|
+
*/
|
|
141
|
+
protected validateProps(data: IBezierLayerProps): IBezierLayerProps;
|
|
136
142
|
}
|
|
@@ -21,9 +21,7 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
21
21
|
constructor(props, misc) {
|
|
22
22
|
super(types_1.LayerType.BezierCurve, props || {}, misc);
|
|
23
23
|
this.props = props ? props : {};
|
|
24
|
-
|
|
25
|
-
this.props.fillStyle = '#000000';
|
|
26
|
-
this.props.centring = types_1.Centring.None;
|
|
24
|
+
this.props = this.validateProps(this.props);
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* Sets the control points of the Bezier layer.
|
|
@@ -124,7 +122,7 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
124
122
|
ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
|
|
125
123
|
});
|
|
126
124
|
const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cp1x, y: cp1y }, { x: cp2x, y: cp2y }, { x: xe, y: ye }]);
|
|
127
|
-
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
|
|
125
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width, height, x: min.x, y: min.y, align: 'none' }, manager });
|
|
128
126
|
if (debug)
|
|
129
127
|
LazyUtil_1.LazyLog.log('none', `BezierLayer:`, { xs, ys, cp1x, cp1y, cp2x, cp2y, xe, ye, max, min, center, width, height, fillStyle });
|
|
130
128
|
ctx.save();
|
|
@@ -173,5 +171,26 @@ class BezierLayer extends BaseLayer_1.BaseLayer {
|
|
|
173
171
|
}
|
|
174
172
|
return { ...data, props: copy };
|
|
175
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Validates the properties of the Bezier layer.
|
|
176
|
+
* @param data {IBezierLayerProps} - The properties to validate.
|
|
177
|
+
* @returns {IBezierLayerProps} The validated properties.
|
|
178
|
+
*/
|
|
179
|
+
validateProps(data) {
|
|
180
|
+
return {
|
|
181
|
+
...super.validateProps(data),
|
|
182
|
+
centring: data.centring || types_1.Centring.None,
|
|
183
|
+
controlPoints: data.controlPoints || [{ x: 0, y: 0 }, { x: 0, y: 0 }],
|
|
184
|
+
endPoint: data.endPoint || { x: 0, y: 0 },
|
|
185
|
+
stroke: {
|
|
186
|
+
width: data.stroke?.width || 1,
|
|
187
|
+
cap: data.stroke?.cap || 'butt',
|
|
188
|
+
join: data.stroke?.join || 'miter',
|
|
189
|
+
dashOffset: data.stroke?.dashOffset || 0,
|
|
190
|
+
dash: data.stroke?.dash || [],
|
|
191
|
+
miterLimit: data.stroke?.miterLimit || 10,
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
}
|
|
176
195
|
}
|
|
177
196
|
exports.BezierLayer = BezierLayer;
|
|
@@ -39,14 +39,8 @@ class ClearLayer {
|
|
|
39
39
|
this.type = types_1.LayerType.Clear;
|
|
40
40
|
this.zIndex = misc?.zIndex || 1;
|
|
41
41
|
this.visible = misc?.visible || true;
|
|
42
|
-
this.props = props ? props : {
|
|
43
|
-
|
|
44
|
-
y: 0,
|
|
45
|
-
size: {
|
|
46
|
-
width: 0,
|
|
47
|
-
height: 0
|
|
48
|
-
}
|
|
49
|
-
};
|
|
42
|
+
this.props = props ? props : {};
|
|
43
|
+
this.props = this.validateProps(this.props);
|
|
50
44
|
}
|
|
51
45
|
/**
|
|
52
46
|
* Sets the position of the layer in the 2D plane.
|
|
@@ -148,5 +142,17 @@ class ClearLayer {
|
|
|
148
142
|
props: copy,
|
|
149
143
|
};
|
|
150
144
|
}
|
|
145
|
+
validateProps(props) {
|
|
146
|
+
return {
|
|
147
|
+
x: props.x || 0,
|
|
148
|
+
y: props.y || 0,
|
|
149
|
+
size: {
|
|
150
|
+
width: props.size?.width || 0,
|
|
151
|
+
height: props.size?.height || 0
|
|
152
|
+
},
|
|
153
|
+
centring: props.centring || 'none',
|
|
154
|
+
globalComposite: props.globalComposite || 'source-over'
|
|
155
|
+
};
|
|
156
|
+
}
|
|
151
157
|
}
|
|
152
158
|
exports.ClearLayer = ClearLayer;
|
|
@@ -90,4 +90,10 @@ export declare class ImageLayer extends BaseLayer<IImageLayerProps> {
|
|
|
90
90
|
* @returns {IImageLayer} The JSON representation of the Image Layer.
|
|
91
91
|
*/
|
|
92
92
|
toJSON(): IImageLayer;
|
|
93
|
+
/**
|
|
94
|
+
* Validates the properties of the Image Layer.
|
|
95
|
+
* @param data {IImageLayerProps} - The properties to validate.
|
|
96
|
+
* @returns {IImageLayerProps} The validated properties.
|
|
97
|
+
*/
|
|
98
|
+
protected validateProps(data: IImageLayerProps): IImageLayerProps;
|
|
93
99
|
}
|
|
@@ -23,7 +23,7 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
|
|
|
23
23
|
constructor(props, misc) {
|
|
24
24
|
super(types_1.LayerType.Image, props || {}, misc);
|
|
25
25
|
this.props = props ? props : {};
|
|
26
|
-
this.props
|
|
26
|
+
this.props = this.validateProps(this.props);
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* Sets the source of the image.
|
|
@@ -79,15 +79,15 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
|
|
|
79
79
|
if (debug)
|
|
80
80
|
LazyUtil_1.LazyLog.log('none', `ImageLayer:`, { x, y, w, h, rad });
|
|
81
81
|
ctx.save();
|
|
82
|
-
(0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
|
|
83
|
-
(0, utils_1.drawShadow)(ctx, this.props.shadow);
|
|
84
|
-
(0, utils_1.opacity)(ctx, this.props.opacity);
|
|
85
|
-
(0, utils_1.filters)(ctx, this.props.filter);
|
|
86
82
|
let image = await (0, canvas_1.loadImage)(this.props.src);
|
|
87
83
|
image.width = w;
|
|
88
84
|
image.height = h;
|
|
89
85
|
if (!image)
|
|
90
86
|
throw new LazyUtil_1.LazyError('The image could not be loaded');
|
|
87
|
+
(0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type });
|
|
88
|
+
(0, utils_1.drawShadow)(ctx, this.props.shadow);
|
|
89
|
+
(0, utils_1.opacity)(ctx, this.props.opacity);
|
|
90
|
+
(0, utils_1.filters)(ctx, this.props.filter);
|
|
91
91
|
if (Object.keys(rad).length > 0) {
|
|
92
92
|
ctx.beginPath();
|
|
93
93
|
ctx.moveTo(x + (w / 2), y);
|
|
@@ -118,5 +118,21 @@ class ImageLayer extends BaseLayer_1.BaseLayer {
|
|
|
118
118
|
}
|
|
119
119
|
return { ...data };
|
|
120
120
|
}
|
|
121
|
+
/**
|
|
122
|
+
* Validates the properties of the Image Layer.
|
|
123
|
+
* @param data {IImageLayerProps} - The properties to validate.
|
|
124
|
+
* @returns {IImageLayerProps} The validated properties.
|
|
125
|
+
*/
|
|
126
|
+
validateProps(data) {
|
|
127
|
+
return {
|
|
128
|
+
...super.validateProps(data),
|
|
129
|
+
src: data.src || '',
|
|
130
|
+
size: {
|
|
131
|
+
width: data.size?.width || 0,
|
|
132
|
+
height: data.size?.height || 0,
|
|
133
|
+
radius: data.size?.radius || { all: 0 }
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
121
137
|
}
|
|
122
138
|
exports.ImageLayer = ImageLayer;
|
|
@@ -129,4 +129,10 @@ export declare class LineLayer extends BaseLayer<ILineLayerProps> {
|
|
|
129
129
|
* @returns {ILineLayer} The JSON representation of the Line Layer.
|
|
130
130
|
*/
|
|
131
131
|
toJSON(): ILineLayer;
|
|
132
|
+
/**
|
|
133
|
+
* Validates the properties of the Line Layer.
|
|
134
|
+
* @param data {ILineLayerProps} - The properties to validate.
|
|
135
|
+
* @returns {ILineLayerProps} The validated properties.
|
|
136
|
+
*/
|
|
137
|
+
protected validateProps(data: ILineLayerProps): ILineLayerProps;
|
|
132
138
|
}
|
|
@@ -21,9 +21,7 @@ class LineLayer extends BaseLayer_1.BaseLayer {
|
|
|
21
21
|
constructor(props, misc) {
|
|
22
22
|
super(types_1.LayerType.Line, props || {}, misc);
|
|
23
23
|
this.props = props ? props : {};
|
|
24
|
-
|
|
25
|
-
this.props.fillStyle = '#000000';
|
|
26
|
-
this.props.centring = types_1.Centring.None;
|
|
24
|
+
this.props = this.validateProps(this.props);
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* Sets the end position of the line layer.
|
|
@@ -104,9 +102,9 @@ class LineLayer extends BaseLayer_1.BaseLayer {
|
|
|
104
102
|
xe: { v: this.props.endPoint.x },
|
|
105
103
|
ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) },
|
|
106
104
|
});
|
|
107
|
-
let width = xe - xs;
|
|
108
|
-
let height = ye - ys;
|
|
109
|
-
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
|
|
105
|
+
let width = Math.abs(xe - xs);
|
|
106
|
+
let height = Math.abs(ye - ys);
|
|
107
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width, height, x: Math.min(xs, xe), y: Math.min(ys, ye), align: 'none' }, manager });
|
|
110
108
|
if (debug)
|
|
111
109
|
LazyUtil_1.LazyLog.log('none', `LineLayer:`, { xs, ys, xe, ye, width, height });
|
|
112
110
|
ctx.save();
|
|
@@ -142,5 +140,28 @@ class LineLayer extends BaseLayer_1.BaseLayer {
|
|
|
142
140
|
}
|
|
143
141
|
return { ...data, props: copy };
|
|
144
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Validates the properties of the Line Layer.
|
|
145
|
+
* @param data {ILineLayerProps} - The properties to validate.
|
|
146
|
+
* @returns {ILineLayerProps} The validated properties.
|
|
147
|
+
*/
|
|
148
|
+
validateProps(data) {
|
|
149
|
+
return {
|
|
150
|
+
...super.validateProps(data),
|
|
151
|
+
centring: data.centring || types_1.Centring.None,
|
|
152
|
+
endPoint: {
|
|
153
|
+
x: data.endPoint?.x || 0,
|
|
154
|
+
y: data.endPoint?.y || 0,
|
|
155
|
+
},
|
|
156
|
+
stroke: {
|
|
157
|
+
width: data.stroke?.width || 1,
|
|
158
|
+
cap: data.stroke?.cap || 'butt',
|
|
159
|
+
join: data.stroke?.join || 'miter',
|
|
160
|
+
dashOffset: data.stroke?.dashOffset || 0,
|
|
161
|
+
dash: data.stroke?.dash || [],
|
|
162
|
+
miterLimit: data.stroke?.miterLimit || 10,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
145
166
|
}
|
|
146
167
|
exports.LineLayer = LineLayer;
|
|
@@ -129,4 +129,10 @@ export declare class MorphLayer extends BaseLayer<IMorphLayerProps> {
|
|
|
129
129
|
* @returns {IMorphLayer} The JSON representation of the Morph Layer.
|
|
130
130
|
*/
|
|
131
131
|
toJSON(): IMorphLayer;
|
|
132
|
+
/**
|
|
133
|
+
* Validates the properties of the Morph Layer.
|
|
134
|
+
* @param data {IMorphLayerProps} - The properties to validate.
|
|
135
|
+
* @returns {IMorphLayerProps} The validated properties.
|
|
136
|
+
*/
|
|
137
|
+
protected validateProps(data: IMorphLayerProps): IMorphLayerProps;
|
|
132
138
|
}
|
|
@@ -22,11 +22,7 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
|
22
22
|
constructor(props, misc) {
|
|
23
23
|
super(types_1.LayerType.Morph, props || {}, misc);
|
|
24
24
|
this.props = props ? props : {};
|
|
25
|
-
|
|
26
|
-
this.props.fillStyle = '#000000';
|
|
27
|
-
if (!this.props.filled && this.props.filled !== false)
|
|
28
|
-
this.props.filled = true;
|
|
29
|
-
this.props.centring = types_1.Centring.Center;
|
|
25
|
+
this.props = this.validateProps(this.props);
|
|
30
26
|
}
|
|
31
27
|
/**
|
|
32
28
|
* Sets the size of the Morph Layer.
|
|
@@ -110,7 +106,7 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
|
110
106
|
}
|
|
111
107
|
}
|
|
112
108
|
let { x, y } = (0, utils_1.centring)(this.props.centring, this.type, w, h, xs, ys);
|
|
113
|
-
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
|
|
109
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width: w, height: h, x: xs, y: ys, align: this.props.centring }, manager });
|
|
114
110
|
if (debug)
|
|
115
111
|
LazyUtil_1.LazyLog.log('none', `MorphLayer:`, { x, y, w, h, rad });
|
|
116
112
|
ctx.save();
|
|
@@ -160,5 +156,28 @@ class MorphLayer extends BaseLayer_1.BaseLayer {
|
|
|
160
156
|
}
|
|
161
157
|
return { ...data, props: copy };
|
|
162
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Validates the properties of the Morph Layer.
|
|
161
|
+
* @param data {IMorphLayerProps} - The properties to validate.
|
|
162
|
+
* @returns {IMorphLayerProps} The validated properties.
|
|
163
|
+
*/
|
|
164
|
+
validateProps(data) {
|
|
165
|
+
return {
|
|
166
|
+
...super.validateProps(data),
|
|
167
|
+
size: {
|
|
168
|
+
width: data.size?.width || 100,
|
|
169
|
+
height: data.size?.height || 100,
|
|
170
|
+
radius: data.size?.radius || { all: 0 },
|
|
171
|
+
},
|
|
172
|
+
stroke: {
|
|
173
|
+
width: data.stroke?.width || 1,
|
|
174
|
+
cap: data.stroke?.cap || 'butt',
|
|
175
|
+
join: data.stroke?.join || 'miter',
|
|
176
|
+
dashOffset: data.stroke?.dashOffset || 0,
|
|
177
|
+
dash: data.stroke?.dash || [],
|
|
178
|
+
miterLimit: data.stroke?.miterLimit || 10,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
163
182
|
}
|
|
164
183
|
exports.MorphLayer = MorphLayer;
|
|
@@ -161,4 +161,10 @@ export declare class Path2DLayer extends BaseLayer<IPath2DLayerProps> {
|
|
|
161
161
|
* @returns {IPath2DLayer} The JSON representation of the Path2D Layer.
|
|
162
162
|
*/
|
|
163
163
|
toJSON(): IPath2DLayer;
|
|
164
|
+
/**
|
|
165
|
+
* Validates the properties of the Path2D Layer.
|
|
166
|
+
* @param data {IPath2DLayerProps} - The properties to validate.
|
|
167
|
+
* @returns {IPath2DLayerProps} The validated properties.
|
|
168
|
+
*/
|
|
169
|
+
protected validateProps(data: IPath2DLayerProps): IPath2DLayerProps;
|
|
164
170
|
}
|
|
@@ -18,6 +18,7 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
18
18
|
this.zIndex = misc?.zIndex || 1;
|
|
19
19
|
this.visible = misc?.visible || true;
|
|
20
20
|
this.props = props ? props : {};
|
|
21
|
+
this.props = this.validateProps(this.props);
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* Sets the unique identifier of the layer.
|
|
@@ -252,7 +253,7 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
252
253
|
async draw(ctx, canvas, manager, debug) {
|
|
253
254
|
ctx.beginPath();
|
|
254
255
|
ctx.save();
|
|
255
|
-
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
|
|
256
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, manager });
|
|
256
257
|
(0, utils_1.transform)(ctx, this.props.transform, { width: 0, height: 0, x: 0, y: 0, type: this.type });
|
|
257
258
|
(0, utils_1.opacity)(ctx, this.props.opacity);
|
|
258
259
|
ctx.globalCompositeOperation = this.props.globalComposite;
|
|
@@ -289,5 +290,26 @@ class Path2DLayer extends BaseLayer_1.BaseLayer {
|
|
|
289
290
|
props: this.props
|
|
290
291
|
};
|
|
291
292
|
}
|
|
293
|
+
/**
|
|
294
|
+
* Validates the properties of the Path2D Layer.
|
|
295
|
+
* @param data {IPath2DLayerProps} - The properties to validate.
|
|
296
|
+
* @returns {IPath2DLayerProps} The validated properties.
|
|
297
|
+
*/
|
|
298
|
+
validateProps(data) {
|
|
299
|
+
return {
|
|
300
|
+
...super.validateProps(data),
|
|
301
|
+
path2D: data.path2D || new canvas_1.Path2D(),
|
|
302
|
+
stroke: {
|
|
303
|
+
width: data.stroke?.width || 1,
|
|
304
|
+
cap: data.stroke?.cap || 'butt',
|
|
305
|
+
join: data.stroke?.join || 'miter',
|
|
306
|
+
dashOffset: data.stroke?.dashOffset || 0,
|
|
307
|
+
dash: data.stroke?.dash || [],
|
|
308
|
+
miterLimit: data.stroke?.miterLimit || 10
|
|
309
|
+
},
|
|
310
|
+
loadFromSVG: data.loadFromSVG || false,
|
|
311
|
+
clipPath: data.clipPath || false
|
|
312
|
+
};
|
|
313
|
+
}
|
|
292
314
|
}
|
|
293
315
|
exports.Path2DLayer = Path2DLayer;
|
|
@@ -139,4 +139,10 @@ export declare class QuadraticLayer extends BaseLayer<IQuadraticLayerProps> {
|
|
|
139
139
|
* @returns {IQuadraticLayer} The JSON representation of the Quadratic Layer.
|
|
140
140
|
*/
|
|
141
141
|
toJSON(): IQuadraticLayer;
|
|
142
|
+
/**
|
|
143
|
+
* Validates the properties of the Quadratic Layer.
|
|
144
|
+
* @param data {IQuadraticLayerProps} - The properties to validate.
|
|
145
|
+
* @returns {IQuadraticLayerProps} The validated properties.
|
|
146
|
+
*/
|
|
147
|
+
protected validateProps(data: IQuadraticLayerProps): IQuadraticLayerProps;
|
|
142
148
|
}
|
|
@@ -21,9 +21,7 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
21
21
|
constructor(props, misc) {
|
|
22
22
|
super(types_1.LayerType.QuadraticCurve, props || {}, misc);
|
|
23
23
|
this.props = props ? props : {};
|
|
24
|
-
|
|
25
|
-
this.props.fillStyle = '#000000';
|
|
26
|
-
this.props.centring = types_1.Centring.None;
|
|
24
|
+
this.props = this.validateProps(this.props);
|
|
27
25
|
}
|
|
28
26
|
/**
|
|
29
27
|
* Sets the control point of the quadratic layer.
|
|
@@ -118,7 +116,7 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
118
116
|
ye: { v: this.props.endPoint.y, options: LazyUtil_1.defaultArg.vl(true) }
|
|
119
117
|
});
|
|
120
118
|
const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cx, y: cy }, { x: xe, y: ye }]);
|
|
121
|
-
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle);
|
|
119
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width, height, x: min.x, y: min.y, align: 'none' }, manager });
|
|
122
120
|
if (debug)
|
|
123
121
|
LazyUtil_1.LazyLog.log('none', `BezierLayer:`, { xs, ys, cx, cy, xe, ye, max, min, center, width, height, fillStyle });
|
|
124
122
|
ctx.save();
|
|
@@ -154,5 +152,26 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
154
152
|
}
|
|
155
153
|
return { ...data, props: copy };
|
|
156
154
|
}
|
|
155
|
+
/**
|
|
156
|
+
* Validates the properties of the Quadratic Layer.
|
|
157
|
+
* @param data {IQuadraticLayerProps} - The properties to validate.
|
|
158
|
+
* @returns {IQuadraticLayerProps} The validated properties.
|
|
159
|
+
*/
|
|
160
|
+
validateProps(data) {
|
|
161
|
+
return {
|
|
162
|
+
...super.validateProps(data),
|
|
163
|
+
centring: data.centring || types_1.Centring.None,
|
|
164
|
+
controlPoints: data.controlPoints || [{ x: 0, y: 0 }],
|
|
165
|
+
endPoint: data.endPoint || { x: 0, y: 0 },
|
|
166
|
+
stroke: {
|
|
167
|
+
width: data.stroke?.width || 1,
|
|
168
|
+
cap: data.stroke?.cap || 'butt',
|
|
169
|
+
join: data.stroke?.join || 'miter',
|
|
170
|
+
dashOffset: data.stroke?.dashOffset || 0,
|
|
171
|
+
dash: data.stroke?.dash || [],
|
|
172
|
+
miterLimit: data.stroke?.miterLimit || 10,
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
157
176
|
}
|
|
158
177
|
exports.QuadraticLayer = QuadraticLayer;
|
|
@@ -73,23 +73,23 @@ export interface ITextLayerProps extends IBaseLayerProps {
|
|
|
73
73
|
/**
|
|
74
74
|
* The baseline of the text.
|
|
75
75
|
*/
|
|
76
|
-
baseline
|
|
76
|
+
baseline?: AnyTextBaseline;
|
|
77
77
|
/**
|
|
78
78
|
* The direction of the text.
|
|
79
79
|
*/
|
|
80
|
-
direction
|
|
80
|
+
direction?: AnyTextDirection;
|
|
81
81
|
/**
|
|
82
82
|
* The spacing between letters.
|
|
83
83
|
*/
|
|
84
|
-
letterSpacing
|
|
84
|
+
letterSpacing?: number;
|
|
85
85
|
/**
|
|
86
86
|
* The spacing between words.
|
|
87
87
|
*/
|
|
88
|
-
wordSpacing
|
|
88
|
+
wordSpacing?: number;
|
|
89
89
|
/**
|
|
90
90
|
* The stroke properties of the text.
|
|
91
91
|
*/
|
|
92
|
-
stroke
|
|
92
|
+
stroke?: {
|
|
93
93
|
/**
|
|
94
94
|
* The width of the stroke.
|
|
95
95
|
*/
|
|
@@ -246,4 +246,10 @@ export declare class TextLayer extends BaseLayer<ITextLayerProps> {
|
|
|
246
246
|
* @returns {ITextLayer} The JSON representation of the Text Layer.
|
|
247
247
|
*/
|
|
248
248
|
toJSON(): ITextLayer;
|
|
249
|
+
/**
|
|
250
|
+
* Validates the properties of the Text Layer.
|
|
251
|
+
* @param props {ITextLayerProps} - The properties to validate.
|
|
252
|
+
* @returns {ITextLayerProps} The validated properties.
|
|
253
|
+
*/
|
|
254
|
+
protected validateProps(props: ITextLayerProps): ITextLayerProps;
|
|
249
255
|
}
|
|
@@ -21,25 +21,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
21
21
|
constructor(props, misc) {
|
|
22
22
|
super(types_1.LayerType.Text, props || {}, misc);
|
|
23
23
|
this.props = props ? props : {};
|
|
24
|
-
this.props
|
|
25
|
-
this.props.font = {
|
|
26
|
-
family: 'Geist',
|
|
27
|
-
size: 16,
|
|
28
|
-
weight: types_1.FontWeight.Regular,
|
|
29
|
-
};
|
|
30
|
-
this.props.fillStyle = '#ffffff';
|
|
31
|
-
this.props.filled = true;
|
|
32
|
-
this.props.multiline = {
|
|
33
|
-
enabled: false,
|
|
34
|
-
spacing: 1.1,
|
|
35
|
-
};
|
|
36
|
-
this.props.size = {
|
|
37
|
-
width: 'vw',
|
|
38
|
-
height: 0,
|
|
39
|
-
};
|
|
40
|
-
this.props.centring = types_1.Centring.Center;
|
|
41
|
-
this.props.wordSpacing = 0;
|
|
42
|
-
this.props.letterSpacing = 0;
|
|
24
|
+
this.props = this.validateProps(this.props);
|
|
43
25
|
}
|
|
44
26
|
/**
|
|
45
27
|
* Sets the text of the text layer.
|
|
@@ -229,12 +211,15 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
229
211
|
(0, utils_1.opacity)(ctx, this.props.opacity);
|
|
230
212
|
(0, utils_1.filters)(ctx, this.props.filter);
|
|
231
213
|
ctx.textAlign = this.props.align;
|
|
232
|
-
|
|
233
|
-
|
|
214
|
+
if (this.props.letterSpacing)
|
|
215
|
+
ctx.letterSpacing = `${this.props.letterSpacing}px`;
|
|
216
|
+
if (this.props.wordSpacing)
|
|
217
|
+
ctx.wordSpacing = `${this.props.wordSpacing}px`;
|
|
234
218
|
if (this.props.baseline)
|
|
235
219
|
ctx.textBaseline = this.props.baseline;
|
|
236
220
|
if (this.props.direction)
|
|
237
221
|
ctx.direction = this.props.direction;
|
|
222
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.fillStyle, { debug, layer: { width: w, height: h, x, y, align: 'none' }, manager });
|
|
238
223
|
if (this.props.multiline.enabled) {
|
|
239
224
|
const words = this.props.text.split(' ');
|
|
240
225
|
let lines = [];
|
|
@@ -261,12 +246,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
261
246
|
break;
|
|
262
247
|
}
|
|
263
248
|
for (let line of lines) {
|
|
264
|
-
this.drawText(this.props, ctx,
|
|
249
|
+
this.drawText(this.props, ctx, fillStyle, line.text, line.x, line.y, w);
|
|
265
250
|
}
|
|
266
251
|
}
|
|
267
252
|
else {
|
|
268
253
|
ctx.font = `${this.props.font.weight} ${this.props.font.size}px ${this.props.font.family}`;
|
|
269
|
-
this.drawText(this.props, ctx,
|
|
254
|
+
this.drawText(this.props, ctx, fillStyle, this.props.text, x, y, w);
|
|
270
255
|
}
|
|
271
256
|
ctx.closePath();
|
|
272
257
|
ctx.restore();
|
|
@@ -311,5 +296,32 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
311
296
|
}
|
|
312
297
|
return { ...data, props: copy };
|
|
313
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Validates the properties of the Text Layer.
|
|
301
|
+
* @param props {ITextLayerProps} - The properties to validate.
|
|
302
|
+
* @returns {ITextLayerProps} The validated properties.
|
|
303
|
+
*/
|
|
304
|
+
validateProps(props) {
|
|
305
|
+
return {
|
|
306
|
+
...super.validateProps(props),
|
|
307
|
+
text: props.text || "",
|
|
308
|
+
font: {
|
|
309
|
+
family: props.font?.family || "Arial",
|
|
310
|
+
size: props.font?.size || 16,
|
|
311
|
+
weight: props.font?.weight || types_1.FontWeight.Regular,
|
|
312
|
+
},
|
|
313
|
+
multiline: {
|
|
314
|
+
enabled: props.multiline?.enabled || false,
|
|
315
|
+
spacing: props.multiline?.spacing || 1.1,
|
|
316
|
+
},
|
|
317
|
+
size: {
|
|
318
|
+
width: props.size?.width || "vw",
|
|
319
|
+
height: props.size?.height || 0,
|
|
320
|
+
},
|
|
321
|
+
align: props.align || types_1.TextAlign.Left,
|
|
322
|
+
fillStyle: props.fillStyle || "#000000",
|
|
323
|
+
filled: props.filled !== undefined ? props.filled : true,
|
|
324
|
+
};
|
|
325
|
+
}
|
|
314
326
|
}
|
|
315
327
|
exports.TextLayer = TextLayer;
|