@nmmty/lazycanvas 0.6.5 → 1.0.0-dev.10
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/ReadMe.md +1 -1
- package/dist/core/Interpolation.d.ts +30 -0
- package/dist/core/Interpolation.js +200 -0
- package/dist/core/Scene.d.ts +94 -0
- package/dist/core/Scene.js +157 -0
- package/dist/core/Signal.d.ts +133 -0
- package/dist/core/Signal.js +255 -0
- package/dist/core/SignalUtils.d.ts +133 -0
- package/dist/core/SignalUtils.js +333 -0
- package/dist/core/ThreadScheduler.d.ts +38 -0
- package/dist/core/ThreadScheduler.js +74 -0
- package/dist/core/index.d.ts +5 -0
- package/dist/core/index.js +21 -0
- package/dist/helpers/Filters.js +1 -1
- package/dist/helpers/FontsList.js +18 -18
- package/dist/helpers/Utlis.d.ts +3 -3
- package/dist/helpers/Utlis.js +25 -36
- package/dist/helpers/index.d.ts +3 -3
- package/dist/index.d.ts +4 -1
- package/dist/index.js +4 -1
- package/dist/jsx-runtime.d.ts +17 -0
- package/dist/jsx-runtime.js +111 -0
- package/dist/structures/LazyCanvas.d.ts +10 -48
- package/dist/structures/LazyCanvas.js +17 -78
- package/dist/structures/components/BaseLayer.d.ts +78 -32
- package/dist/structures/components/BaseLayer.js +106 -37
- package/dist/structures/components/BezierLayer.d.ts +25 -38
- package/dist/structures/components/BezierLayer.js +88 -53
- package/dist/structures/components/{Group.d.ts → Div.d.ts} +37 -18
- package/dist/structures/components/Div.js +202 -0
- package/dist/structures/components/ImageLayer.d.ts +1 -1
- package/dist/structures/components/ImageLayer.js +28 -29
- package/dist/structures/components/LineLayer.d.ts +18 -36
- package/dist/structures/components/LineLayer.js +43 -45
- package/dist/structures/components/MorphLayer.d.ts +4 -33
- package/dist/structures/components/MorphLayer.js +37 -51
- package/dist/structures/components/Path2DLayer.d.ts +7 -35
- package/dist/structures/components/Path2DLayer.js +32 -41
- package/dist/structures/components/PolygonLayer.d.ts +3 -32
- package/dist/structures/components/PolygonLayer.js +37 -42
- package/dist/structures/components/QuadraticLayer.d.ts +25 -34
- package/dist/structures/components/QuadraticLayer.js +83 -47
- package/dist/structures/components/TextLayer.d.ts +5 -34
- package/dist/structures/components/TextLayer.js +88 -71
- package/dist/structures/components/index.d.ts +10 -11
- package/dist/structures/components/index.js +1 -2
- package/dist/structures/helpers/Exporter.d.ts +13 -4
- package/dist/structures/helpers/Exporter.js +82 -46
- package/dist/structures/helpers/Font.js +1 -17
- package/dist/structures/helpers/Gradient.js +35 -49
- package/dist/structures/helpers/Link.js +2 -14
- package/dist/structures/helpers/Pattern.js +10 -18
- package/dist/structures/helpers/index.d.ts +7 -7
- package/dist/structures/helpers/readers/JSONReader.d.ts +4 -4
- package/dist/structures/helpers/readers/JSONReader.js +44 -48
- package/dist/structures/helpers/readers/YAMLReader.js +11 -11
- package/dist/structures/managers/FontsManager.js +9 -18
- package/dist/structures/managers/LayersManager.d.ts +18 -28
- package/dist/structures/managers/LayersManager.js +14 -36
- package/dist/structures/managers/LayoutManager.d.ts +23 -0
- package/dist/structures/managers/LayoutManager.js +409 -0
- package/dist/structures/managers/index.d.ts +3 -5
- package/dist/structures/managers/index.js +1 -3
- package/dist/structures/managers/{RenderManager.d.ts → piplines/ClassicRenderPipeline.d.ts} +4 -30
- package/dist/structures/managers/piplines/ClassicRenderPipeline.js +90 -0
- package/dist/structures/managers/piplines/ModernRenderPipeline.d.ts +44 -0
- package/dist/structures/managers/piplines/ModernRenderPipeline.js +123 -0
- package/dist/structures/managers/piplines/index.d.ts +24 -0
- package/dist/structures/managers/piplines/index.js +18 -0
- package/dist/types/enum.d.ts +1 -2
- package/dist/types/enum.js +1 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/types.d.ts +257 -107
- package/dist/utils/APNGEncoder.d.ts +67 -0
- package/dist/utils/APNGEncoder.js +205 -0
- package/dist/utils/DrawUtils.d.ts +9 -0
- package/dist/utils/DrawUtils.js +42 -0
- package/dist/utils/LazyUtil.js +1 -2
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/utils.d.ts +4 -7
- package/dist/utils/utils.js +140 -78
- package/package.json +61 -59
- package/dist/structures/components/ClearLayer.d.ts +0 -147
- package/dist/structures/components/ClearLayer.js +0 -158
- package/dist/structures/components/Group.js +0 -153
- package/dist/structures/managers/AnimationManager.d.ts +0 -120
- package/dist/structures/managers/AnimationManager.js +0 -99
- package/dist/structures/managers/PluginManager.d.ts +0 -230
- package/dist/structures/managers/PluginManager.js +0 -182
- package/dist/structures/managers/RenderManager.js +0 -183
|
@@ -3,16 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.QuadraticLayer = void 0;
|
|
4
4
|
const BaseLayer_1 = require("./BaseLayer");
|
|
5
5
|
const types_1 = require("../../types");
|
|
6
|
-
const utils_1 = require("../../utils
|
|
7
|
-
const LazyUtil_1 = require("../../utils/LazyUtil");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
8
7
|
/**
|
|
9
8
|
* Class representing a Quadratic layer, extending the BaseLayer class.
|
|
10
9
|
*/
|
|
11
10
|
class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
12
|
-
/**
|
|
13
|
-
* The properties of the Quadratic layer.
|
|
14
|
-
*/
|
|
15
|
-
props;
|
|
16
11
|
/**
|
|
17
12
|
* Constructs a new QuadraticLayer instance.
|
|
18
13
|
* @param {IQuadraticLayerProps} [props] - The properties of the Quadratic layer.
|
|
@@ -34,13 +29,15 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
34
29
|
return this;
|
|
35
30
|
}
|
|
36
31
|
/**
|
|
37
|
-
* Sets the
|
|
32
|
+
* Sets the position of the quadratic layer.
|
|
38
33
|
* @param {ScaleType} [x] - The x-coordinate of the end point.
|
|
39
34
|
* @param {ScaleType} [y] - The y-coordinate of the end point.
|
|
35
|
+
* @param {ScaleType} [endX] - The x-coordinate of the end point.
|
|
36
|
+
* @param {ScaleType} [endY] - The y-coordinate of the end point.
|
|
40
37
|
* @returns {this} The current instance for chaining.
|
|
41
38
|
*/
|
|
42
|
-
|
|
43
|
-
this.props.
|
|
39
|
+
setPosition(x, y, endX, endY) {
|
|
40
|
+
this.props.position = { x, y, endX: endX || 0, endY: endY || 0 };
|
|
44
41
|
return this;
|
|
45
42
|
}
|
|
46
43
|
/**
|
|
@@ -51,10 +48,10 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
51
48
|
*/
|
|
52
49
|
setColor(color) {
|
|
53
50
|
if (!color)
|
|
54
|
-
throw new
|
|
51
|
+
throw new utils_1.LazyError("The color of the layer must be provided");
|
|
55
52
|
if (!(0, utils_1.isColor)(color))
|
|
56
|
-
throw new
|
|
57
|
-
this.props.
|
|
53
|
+
throw new utils_1.LazyError("The color of the layer must be a valid color");
|
|
54
|
+
this.props.color = color;
|
|
58
55
|
return this;
|
|
59
56
|
}
|
|
60
57
|
/**
|
|
@@ -70,8 +67,8 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
70
67
|
setStroke(width, cap, join, dash, dashOffset, miterLimit) {
|
|
71
68
|
this.props.stroke = {
|
|
72
69
|
width,
|
|
73
|
-
cap: cap ||
|
|
74
|
-
join: join ||
|
|
70
|
+
cap: cap || "butt",
|
|
71
|
+
join: join || "miter",
|
|
75
72
|
dash: dash || [],
|
|
76
73
|
dashOffset: dashOffset || 0,
|
|
77
74
|
miterLimit: miterLimit || 10,
|
|
@@ -88,14 +85,18 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
88
85
|
getBoundingBox(ctx, canvas, manager) {
|
|
89
86
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
90
87
|
const { xs, ys, cx, cy, xe, ye } = parcer.parseBatch({
|
|
91
|
-
xs: { v: this.props.x },
|
|
92
|
-
ys: { v: this.props.y, options:
|
|
88
|
+
xs: { v: this.props.position.x },
|
|
89
|
+
ys: { v: this.props.position.y, options: utils_1.defaultArg.vl(true) },
|
|
93
90
|
cx: { v: this.props.controlPoints[0].x },
|
|
94
|
-
cy: { v: this.props.controlPoints[0].y, options:
|
|
95
|
-
xe: { v: this.props.
|
|
96
|
-
ye: { v: this.props.
|
|
91
|
+
cy: { v: this.props.controlPoints[0].y, options: utils_1.defaultArg.vl(true) },
|
|
92
|
+
xe: { v: this.props.position.endX },
|
|
93
|
+
ye: { v: this.props.position.endY, options: utils_1.defaultArg.vl(true) },
|
|
97
94
|
});
|
|
98
|
-
const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([
|
|
95
|
+
const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([
|
|
96
|
+
{ x: xs, y: ys },
|
|
97
|
+
{ x: cx, y: cy },
|
|
98
|
+
{ x: xe, y: ye },
|
|
99
|
+
]);
|
|
99
100
|
return { max, min, center, width, height };
|
|
100
101
|
}
|
|
101
102
|
/**
|
|
@@ -108,31 +109,54 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
108
109
|
async draw(ctx, canvas, manager, debug) {
|
|
109
110
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
110
111
|
const { xs, ys, cx, cy, xe, ye } = parcer.parseBatch({
|
|
111
|
-
xs: { v: this.props.x },
|
|
112
|
-
ys: { v: this.props.y, options:
|
|
112
|
+
xs: { v: this.props.position.x },
|
|
113
|
+
ys: { v: this.props.position.y, options: utils_1.defaultArg.vl(true) },
|
|
113
114
|
cx: { v: this.props.controlPoints[0].x },
|
|
114
|
-
cy: { v: this.props.controlPoints[0].y, options:
|
|
115
|
-
xe: { v: this.props.
|
|
116
|
-
ye: { v: this.props.
|
|
115
|
+
cy: { v: this.props.controlPoints[0].y, options: utils_1.defaultArg.vl(true) },
|
|
116
|
+
xe: { v: this.props.position.endX },
|
|
117
|
+
ye: { v: this.props.position.endY, options: utils_1.defaultArg.vl(true) },
|
|
118
|
+
});
|
|
119
|
+
const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([
|
|
120
|
+
{ x: xs, y: ys },
|
|
121
|
+
{ x: cx, y: cy },
|
|
122
|
+
{ x: xe, y: ye },
|
|
123
|
+
]);
|
|
124
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, {
|
|
125
|
+
debug,
|
|
126
|
+
layer: { width, height, x: min.x, y: min.y, align: "none" },
|
|
127
|
+
manager,
|
|
117
128
|
});
|
|
118
|
-
const { max, min, center, width, height } = (0, utils_1.getBoundingBoxBezier)([{ x: xs, y: ys }, { x: cx, y: cy }, { x: xe, y: ye }]);
|
|
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 });
|
|
120
129
|
if (debug)
|
|
121
|
-
|
|
130
|
+
utils_1.LazyLog.log("none", `BezierLayer:`, {
|
|
131
|
+
xs,
|
|
132
|
+
ys,
|
|
133
|
+
cx,
|
|
134
|
+
cy,
|
|
135
|
+
xe,
|
|
136
|
+
ye,
|
|
137
|
+
max,
|
|
138
|
+
min,
|
|
139
|
+
center,
|
|
140
|
+
width,
|
|
141
|
+
height,
|
|
142
|
+
fillStyle,
|
|
143
|
+
});
|
|
122
144
|
ctx.save();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
145
|
+
if (this.props.transform) {
|
|
146
|
+
(0, utils_1.transform)(ctx, this.props.transform, {
|
|
147
|
+
x: center.x,
|
|
148
|
+
y: center.y,
|
|
149
|
+
width,
|
|
150
|
+
height,
|
|
151
|
+
type: this.type,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
utils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
|
|
155
|
+
utils_1.DrawUtils.opacity(ctx, this.props.opacity);
|
|
156
|
+
utils_1.DrawUtils.filters(ctx, this.props.filter);
|
|
157
|
+
utils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
|
|
127
158
|
ctx.beginPath();
|
|
128
159
|
ctx.moveTo(xs, ys);
|
|
129
|
-
ctx.strokeStyle = fillStyle;
|
|
130
|
-
ctx.lineWidth = this.props.stroke?.width || 1;
|
|
131
|
-
ctx.lineCap = this.props.stroke?.cap || 'butt';
|
|
132
|
-
ctx.lineJoin = this.props.stroke?.join || 'miter';
|
|
133
|
-
ctx.miterLimit = this.props.stroke?.miterLimit || 10;
|
|
134
|
-
ctx.lineDashOffset = this.props.stroke?.dashOffset || 0;
|
|
135
|
-
ctx.setLineDash(this.props.stroke?.dash || []);
|
|
136
160
|
ctx.quadraticCurveTo(cx, cy, xe, ye);
|
|
137
161
|
ctx.stroke();
|
|
138
162
|
ctx.closePath();
|
|
@@ -145,8 +169,16 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
145
169
|
toJSON() {
|
|
146
170
|
let data = super.toJSON();
|
|
147
171
|
let copy = { ...this.props };
|
|
148
|
-
for (const key of [
|
|
149
|
-
|
|
172
|
+
for (const key of [
|
|
173
|
+
"x",
|
|
174
|
+
"y",
|
|
175
|
+
"endPoint.x",
|
|
176
|
+
"endPoint.y",
|
|
177
|
+
"controlPoint.x",
|
|
178
|
+
"controlPoint.y",
|
|
179
|
+
"fillStyle",
|
|
180
|
+
]) {
|
|
181
|
+
if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
|
|
150
182
|
copy[key] = copy[key].toJSON();
|
|
151
183
|
}
|
|
152
184
|
}
|
|
@@ -160,19 +192,23 @@ class QuadraticLayer extends BaseLayer_1.BaseLayer {
|
|
|
160
192
|
validateProps(data) {
|
|
161
193
|
return {
|
|
162
194
|
...super.validateProps(data),
|
|
163
|
-
|
|
164
|
-
|
|
195
|
+
position: {
|
|
196
|
+
x: data.position?.x || 0,
|
|
197
|
+
y: data.position?.y || 0,
|
|
198
|
+
endX: data.position?.endX || 0,
|
|
199
|
+
endY: data.position?.endY || 0,
|
|
200
|
+
},
|
|
201
|
+
color: data.color || "#000000",
|
|
165
202
|
centring: data.centring || types_1.Centring.None,
|
|
166
203
|
controlPoints: data.controlPoints || [{ x: 0, y: 0 }],
|
|
167
|
-
endPoint: data.endPoint || { x: 0, y: 0 },
|
|
168
204
|
stroke: {
|
|
169
205
|
width: data.stroke?.width || 1,
|
|
170
|
-
cap: data.stroke?.cap ||
|
|
171
|
-
join: data.stroke?.join ||
|
|
206
|
+
cap: data.stroke?.cap || "butt",
|
|
207
|
+
join: data.stroke?.join || "miter",
|
|
172
208
|
dashOffset: data.stroke?.dashOffset || 0,
|
|
173
209
|
dash: data.stroke?.dash || [],
|
|
174
210
|
miterLimit: data.stroke?.miterLimit || 10,
|
|
175
|
-
}
|
|
211
|
+
},
|
|
176
212
|
};
|
|
177
213
|
}
|
|
178
214
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseLayer, IBaseLayer, IBaseLayerMisc, IBaseLayerProps } from "./BaseLayer";
|
|
2
|
-
import { AnyTextAlign, AnyTextBaseline, AnyTextDirection, AnyWeight, ColorType, LayerType, LineCap, LineJoin, ScaleType, SubStringColor } from "../../types";
|
|
2
|
+
import { AnyTextAlign, AnyTextBaseline, AnyTextDirection, AnyWeight, ColorType, LayerType, LineCap, LineJoin, ScaleType, StrokeOptions, SubStringColor } from "../../types";
|
|
3
3
|
import { Canvas, SKRSContext2D, SvgCanvas } from "@napi-rs/canvas";
|
|
4
4
|
import { LayersManager } from "../managers";
|
|
5
5
|
/**
|
|
@@ -23,14 +23,10 @@ export interface ITextLayerProps extends IBaseLayerProps {
|
|
|
23
23
|
* The text content of the layer.
|
|
24
24
|
*/
|
|
25
25
|
text: string;
|
|
26
|
-
/**
|
|
27
|
-
* Whether the layer is filled.
|
|
28
|
-
*/
|
|
29
|
-
filled: boolean;
|
|
30
26
|
/**
|
|
31
27
|
* The fill style (color or pattern) of the layer.
|
|
32
28
|
*/
|
|
33
|
-
|
|
29
|
+
color: ColorType;
|
|
34
30
|
/**
|
|
35
31
|
* Array of substring color configurations for partial text coloring.
|
|
36
32
|
*/
|
|
@@ -55,7 +51,7 @@ export interface ITextLayerProps extends IBaseLayerProps {
|
|
|
55
51
|
/**
|
|
56
52
|
* Configuration for multiline text.
|
|
57
53
|
*/
|
|
58
|
-
multiline
|
|
54
|
+
multiline?: {
|
|
59
55
|
/**
|
|
60
56
|
* Whether multiline is enabled.
|
|
61
57
|
*/
|
|
@@ -68,7 +64,7 @@ export interface ITextLayerProps extends IBaseLayerProps {
|
|
|
68
64
|
/**
|
|
69
65
|
* The size of the Text layer, including width and height.
|
|
70
66
|
*/
|
|
71
|
-
size
|
|
67
|
+
size?: {
|
|
72
68
|
/**
|
|
73
69
|
* The width of the Text layer.
|
|
74
70
|
*/
|
|
@@ -101,32 +97,7 @@ export interface ITextLayerProps extends IBaseLayerProps {
|
|
|
101
97
|
/**
|
|
102
98
|
* The stroke properties of the text.
|
|
103
99
|
*/
|
|
104
|
-
stroke?:
|
|
105
|
-
/**
|
|
106
|
-
* The width of the stroke.
|
|
107
|
-
*/
|
|
108
|
-
width: number;
|
|
109
|
-
/**
|
|
110
|
-
* The cap style of the stroke.
|
|
111
|
-
*/
|
|
112
|
-
cap: CanvasLineCap;
|
|
113
|
-
/**
|
|
114
|
-
* The join style of the stroke.
|
|
115
|
-
*/
|
|
116
|
-
join: CanvasLineJoin;
|
|
117
|
-
/**
|
|
118
|
-
* The dash offset of the stroke.
|
|
119
|
-
*/
|
|
120
|
-
dashOffset: number;
|
|
121
|
-
/**
|
|
122
|
-
* The dash pattern of the stroke.
|
|
123
|
-
*/
|
|
124
|
-
dash: number[];
|
|
125
|
-
/**
|
|
126
|
-
* The miter limit of the stroke.
|
|
127
|
-
*/
|
|
128
|
-
miterLimit: number;
|
|
129
|
-
};
|
|
100
|
+
stroke?: StrokeOptions;
|
|
130
101
|
}
|
|
131
102
|
/**
|
|
132
103
|
* Class representing a Text layer, extending the BaseLayer class.
|
|
@@ -3,16 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.TextLayer = void 0;
|
|
4
4
|
const BaseLayer_1 = require("./BaseLayer");
|
|
5
5
|
const types_1 = require("../../types");
|
|
6
|
-
const
|
|
7
|
-
const utils_1 = require("../../utils/utils");
|
|
6
|
+
const utils_1 = require("../../utils");
|
|
8
7
|
/**
|
|
9
8
|
* Class representing a Text layer, extending the BaseLayer class.
|
|
10
9
|
*/
|
|
11
10
|
class TextLayer extends BaseLayer_1.BaseLayer {
|
|
12
|
-
/**
|
|
13
|
-
* The properties of the Text Layer.
|
|
14
|
-
*/
|
|
15
|
-
props;
|
|
16
11
|
/**
|
|
17
12
|
* Constructs a new TextLayer instance.
|
|
18
13
|
* @param {ITextLayerProps} [props] - The properties of the Text layer.
|
|
@@ -43,9 +38,9 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
43
38
|
setFont(familyOrConfig, size, weight) {
|
|
44
39
|
if (typeof familyOrConfig === "string") {
|
|
45
40
|
if (!size)
|
|
46
|
-
throw new
|
|
41
|
+
throw new utils_1.LazyError("The size of the font must be provided");
|
|
47
42
|
if (!weight)
|
|
48
|
-
throw new
|
|
43
|
+
throw new utils_1.LazyError("The weight of the font must be provided");
|
|
49
44
|
this.props.font = {
|
|
50
45
|
family: familyOrConfig,
|
|
51
46
|
size,
|
|
@@ -88,10 +83,10 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
88
83
|
*/
|
|
89
84
|
setColor(color, ...sub) {
|
|
90
85
|
if (!color)
|
|
91
|
-
throw new
|
|
86
|
+
throw new utils_1.LazyError("The color of the layer must be provided");
|
|
92
87
|
if (!(0, utils_1.isColor)(color))
|
|
93
|
-
throw new
|
|
94
|
-
this.props.
|
|
88
|
+
throw new utils_1.LazyError("The color of the layer must be a valid color");
|
|
89
|
+
this.props.color = color;
|
|
95
90
|
if (sub && sub.length > 0) {
|
|
96
91
|
this.props.subStringColors = sub;
|
|
97
92
|
}
|
|
@@ -137,13 +132,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
137
132
|
setStroke(width, cap, join, dash, dashOffset, miterLimit) {
|
|
138
133
|
this.props.stroke = {
|
|
139
134
|
width,
|
|
140
|
-
cap: cap ||
|
|
141
|
-
join: join ||
|
|
135
|
+
cap: cap || "butt",
|
|
136
|
+
join: join || "miter",
|
|
142
137
|
dash: dash || [],
|
|
143
138
|
dashOffset: dashOffset || 0,
|
|
144
139
|
miterLimit: miterLimit || 10,
|
|
145
140
|
};
|
|
146
|
-
this.props.filled = false; // Ensure filled is false when stroke is set
|
|
147
141
|
return this;
|
|
148
142
|
}
|
|
149
143
|
/**
|
|
@@ -171,13 +165,32 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
171
165
|
* @returns {Object} The width and height of the text.
|
|
172
166
|
*/
|
|
173
167
|
measureText(ctx, canvas) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
168
|
+
ctx.font = `${this.props.font.weight} ${this.props.font.size}px ${this.props.font.family}`;
|
|
169
|
+
if (this.props?.multiline?.enabled) {
|
|
170
|
+
const w = (0, utils_1.parseToNormal)(this.props.size?.width || "vw", ctx, canvas);
|
|
171
|
+
// Calculate actual height based on text wrapping
|
|
172
|
+
const words = this.props.text.split(" ");
|
|
173
|
+
let line = "";
|
|
174
|
+
let linesCount = 1;
|
|
175
|
+
for (let word of words) {
|
|
176
|
+
let linePlus = line + word + " ";
|
|
177
|
+
if (ctx.measureText(linePlus).width > w) {
|
|
178
|
+
linesCount++;
|
|
179
|
+
line = word + " ";
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
line = linePlus;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
const lineHeight = this.props.font.size * (this.props.multiline.spacing || 1.1);
|
|
186
|
+
const calculatedHeight = linesCount * lineHeight;
|
|
187
|
+
// If height is fixed in props, use it, otherwise use calculated height
|
|
188
|
+
const fixedHeight = this.props.size?.height
|
|
189
|
+
? (0, utils_1.parseToNormal)(this.props.size.height, ctx, canvas, { width: w, height: 0 }, { vertical: true })
|
|
190
|
+
: 0;
|
|
191
|
+
return { width: w, height: fixedHeight || calculatedHeight };
|
|
178
192
|
}
|
|
179
193
|
else {
|
|
180
|
-
ctx.font = `${this.props.font.weight} ${this.props.font.size}px ${this.props.font.family}`;
|
|
181
194
|
let data = ctx.measureText(this.props.text);
|
|
182
195
|
return { width: data.width, height: this.props.font.size };
|
|
183
196
|
}
|
|
@@ -192,31 +205,44 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
192
205
|
async draw(ctx, canvas, manager, debug) {
|
|
193
206
|
const parcer = (0, utils_1.parser)(ctx, canvas, manager);
|
|
194
207
|
const { x, y, w } = parcer.parseBatch({
|
|
195
|
-
x: { v: this.props.x },
|
|
196
|
-
y: { v: this.props.y, options:
|
|
197
|
-
w: { v: this.props.size?.width },
|
|
208
|
+
x: { v: this.props.position?.x || 0 },
|
|
209
|
+
y: { v: this.props.position?.y || 0, options: utils_1.defaultArg.vl(true) },
|
|
210
|
+
w: { v: this.props.size?.width || "vw" },
|
|
198
211
|
});
|
|
199
|
-
const h = parcer.parse(this.props.size?.height,
|
|
212
|
+
const h = parcer.parse(this.props.size?.height || 0, utils_1.defaultArg.wh(w), utils_1.defaultArg.vl(true));
|
|
200
213
|
if (debug)
|
|
201
|
-
|
|
214
|
+
utils_1.LazyLog.log("none", `TextLayer:`, { x, y, w, h });
|
|
202
215
|
ctx.save();
|
|
203
|
-
|
|
216
|
+
if (this.props.transform) {
|
|
217
|
+
(0, utils_1.transform)(ctx, this.props.transform, { width: w, height: h, x, y, type: this.type }, {
|
|
218
|
+
text: this.props.text,
|
|
219
|
+
textAlign: this.props.align,
|
|
220
|
+
fontSize: this.props.font.size,
|
|
221
|
+
multiline: this.props?.multiline?.enabled || false,
|
|
222
|
+
});
|
|
223
|
+
}
|
|
204
224
|
ctx.beginPath();
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
225
|
+
utils_1.DrawUtils.drawShadow(ctx, this.props.shadow);
|
|
226
|
+
utils_1.DrawUtils.opacity(ctx, this.props.opacity);
|
|
227
|
+
utils_1.DrawUtils.filters(ctx, this.props.filter);
|
|
228
|
+
// When layout is managed by Yoga, always use top-left alignment
|
|
229
|
+
// since Yoga calculates position as top-left corner
|
|
230
|
+
const useLayoutAlignment = this.props._computedLayout === true;
|
|
231
|
+
ctx.textAlign = useLayoutAlignment ? "left" : this.props.align;
|
|
209
232
|
if (this.props.letterSpacing)
|
|
210
233
|
ctx.letterSpacing = `${this.props.letterSpacing}px`;
|
|
211
234
|
if (this.props.wordSpacing)
|
|
212
235
|
ctx.wordSpacing = `${this.props.wordSpacing}px`;
|
|
213
|
-
|
|
214
|
-
ctx.textBaseline = this.props.baseline;
|
|
236
|
+
ctx.textBaseline = useLayoutAlignment ? "top" : this.props.baseline || "alphabetic";
|
|
215
237
|
if (this.props.direction)
|
|
216
238
|
ctx.direction = this.props.direction;
|
|
217
|
-
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.
|
|
218
|
-
|
|
219
|
-
|
|
239
|
+
let fillStyle = await (0, utils_1.parseFillStyle)(ctx, this.props.color, {
|
|
240
|
+
debug,
|
|
241
|
+
layer: { width: w, height: h, x, y, align: "center" },
|
|
242
|
+
manager,
|
|
243
|
+
});
|
|
244
|
+
if (this.props?.multiline?.enabled) {
|
|
245
|
+
const words = this.props.text.split(" ");
|
|
220
246
|
let lines = [];
|
|
221
247
|
for (let fontSize = 1; fontSize <= this.props.font.size; fontSize++) {
|
|
222
248
|
let lineHeight = fontSize * (this.props.multiline.spacing || 1.1);
|
|
@@ -224,14 +250,14 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
224
250
|
let xm = x;
|
|
225
251
|
let ym = y;
|
|
226
252
|
lines = [];
|
|
227
|
-
let line =
|
|
253
|
+
let line = "";
|
|
228
254
|
let charOffset = 0; // Track position in original text
|
|
229
255
|
for (let word of words) {
|
|
230
|
-
let linePlus = line + word +
|
|
256
|
+
let linePlus = line + word + " ";
|
|
231
257
|
if (ctx.measureText(linePlus).width > w) {
|
|
232
258
|
lines.push({ text: line, x: xm, y: ym, startOffset: charOffset });
|
|
233
259
|
charOffset += line.length;
|
|
234
|
-
line = word +
|
|
260
|
+
line = word + " ";
|
|
235
261
|
ym += lineHeight;
|
|
236
262
|
}
|
|
237
263
|
else {
|
|
@@ -267,19 +293,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
267
293
|
drawText(props, ctx, fillStyle, text, x, y, w, textOffset = 0) {
|
|
268
294
|
// If no substring colors are defined, draw normally
|
|
269
295
|
if (!props.subStringColors || props.subStringColors.length === 0) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
ctx.
|
|
296
|
+
utils_1.DrawUtils.fillStyle(ctx, fillStyle, this.props.stroke);
|
|
297
|
+
if (props.stroke) {
|
|
298
|
+
ctx.strokeText(text, x, y, w);
|
|
273
299
|
}
|
|
274
300
|
else {
|
|
275
|
-
ctx.
|
|
276
|
-
ctx.lineWidth = props.stroke?.width || 1;
|
|
277
|
-
ctx.lineCap = props.stroke?.cap || 'butt';
|
|
278
|
-
ctx.lineJoin = props.stroke?.join || 'miter';
|
|
279
|
-
ctx.miterLimit = props.stroke?.miterLimit || 10;
|
|
280
|
-
ctx.lineDashOffset = props.stroke?.dashOffset || 0;
|
|
281
|
-
ctx.setLineDash(props.stroke?.dash || []);
|
|
282
|
-
ctx.strokeText(text, x, y, w);
|
|
301
|
+
ctx.fillText(text, x, y, w);
|
|
283
302
|
}
|
|
284
303
|
return;
|
|
285
304
|
}
|
|
@@ -288,14 +307,17 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
288
307
|
let currentX = x;
|
|
289
308
|
// Save original text alignment and set to left for manual positioning
|
|
290
309
|
const originalAlign = ctx.textAlign;
|
|
291
|
-
ctx.textAlign =
|
|
310
|
+
ctx.textAlign = "left";
|
|
292
311
|
// Adjust starting X based on text alignment
|
|
293
312
|
const alignValue = props.align;
|
|
294
|
-
if (alignValue === types_1.TextAlign.Center || alignValue ===
|
|
313
|
+
if (alignValue === types_1.TextAlign.Center || alignValue === "center") {
|
|
295
314
|
const totalWidth = ctx.measureText(text).width;
|
|
296
315
|
currentX = x - totalWidth / 2;
|
|
297
316
|
}
|
|
298
|
-
else if (alignValue === types_1.TextAlign.Right ||
|
|
317
|
+
else if (alignValue === types_1.TextAlign.Right ||
|
|
318
|
+
alignValue === "right" ||
|
|
319
|
+
alignValue === types_1.TextAlign.End ||
|
|
320
|
+
alignValue === "end") {
|
|
299
321
|
const totalWidth = ctx.measureText(text).width;
|
|
300
322
|
currentX = x - totalWidth;
|
|
301
323
|
}
|
|
@@ -323,16 +345,19 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
323
345
|
text: text.substring(currentIndex, localStart),
|
|
324
346
|
color: fillStyle,
|
|
325
347
|
start: currentIndex,
|
|
326
|
-
end: localStart
|
|
348
|
+
end: localStart,
|
|
327
349
|
});
|
|
328
350
|
}
|
|
329
351
|
// Add colored substring
|
|
330
352
|
if (localStart < localEnd) {
|
|
331
353
|
segments.push({
|
|
332
354
|
text: text.substring(localStart, localEnd),
|
|
333
|
-
color: subColor.color,
|
|
355
|
+
color: (0, utils_1.parseFillStyle)(ctx, subColor.color, {
|
|
356
|
+
debug: false,
|
|
357
|
+
layer: { width: w, height: 0, x: 0, y: 0, align: "center" },
|
|
358
|
+
}),
|
|
334
359
|
start: localStart,
|
|
335
|
-
end: localEnd
|
|
360
|
+
end: localEnd,
|
|
336
361
|
});
|
|
337
362
|
currentIndex = localEnd;
|
|
338
363
|
}
|
|
@@ -343,7 +368,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
343
368
|
text: text.substring(currentIndex),
|
|
344
369
|
color: fillStyle,
|
|
345
370
|
start: currentIndex,
|
|
346
|
-
end: textLength
|
|
371
|
+
end: textLength,
|
|
347
372
|
});
|
|
348
373
|
}
|
|
349
374
|
// Draw each segment
|
|
@@ -351,19 +376,12 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
351
376
|
if (segment.text.length === 0)
|
|
352
377
|
continue;
|
|
353
378
|
const segmentWidth = ctx.measureText(segment.text).width;
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
ctx.
|
|
379
|
+
utils_1.DrawUtils.fillStyle(ctx, segment.color, this.props.stroke);
|
|
380
|
+
if (props.stroke) {
|
|
381
|
+
ctx.strokeText(segment.text, currentX, y);
|
|
357
382
|
}
|
|
358
383
|
else {
|
|
359
|
-
ctx.
|
|
360
|
-
ctx.lineWidth = props.stroke?.width || 1;
|
|
361
|
-
ctx.lineCap = props.stroke?.cap || 'butt';
|
|
362
|
-
ctx.lineJoin = props.stroke?.join || 'miter';
|
|
363
|
-
ctx.miterLimit = props.stroke?.miterLimit || 10;
|
|
364
|
-
ctx.lineDashOffset = props.stroke?.dashOffset || 0;
|
|
365
|
-
ctx.setLineDash(props.stroke?.dash || []);
|
|
366
|
-
ctx.strokeText(segment.text, currentX, y);
|
|
384
|
+
ctx.fillText(segment.text, currentX, y);
|
|
367
385
|
}
|
|
368
386
|
currentX += segmentWidth;
|
|
369
387
|
}
|
|
@@ -377,8 +395,8 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
377
395
|
toJSON() {
|
|
378
396
|
let data = super.toJSON();
|
|
379
397
|
let copy = { ...this.props };
|
|
380
|
-
for (const key of [
|
|
381
|
-
if (copy[key] && typeof copy[key] ===
|
|
398
|
+
for (const key of ["x", "y", "size.width", "size.height", "fillStyle"]) {
|
|
399
|
+
if (copy[key] && typeof copy[key] === "object" && "toJSON" in copy[key]) {
|
|
382
400
|
copy[key] = copy[key].toJSON();
|
|
383
401
|
}
|
|
384
402
|
}
|
|
@@ -392,8 +410,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
392
410
|
validateProps(data) {
|
|
393
411
|
return {
|
|
394
412
|
...super.validateProps(data),
|
|
395
|
-
|
|
396
|
-
fillStyle: data.fillStyle || '#000000',
|
|
413
|
+
color: data.color || "#000000",
|
|
397
414
|
text: data.text || "",
|
|
398
415
|
font: {
|
|
399
416
|
family: data.font?.family || "Arial",
|
|
@@ -405,7 +422,7 @@ class TextLayer extends BaseLayer_1.BaseLayer {
|
|
|
405
422
|
spacing: data.multiline?.spacing || 1.1,
|
|
406
423
|
},
|
|
407
424
|
size: {
|
|
408
|
-
width: data.size?.width ||
|
|
425
|
+
width: data.size?.width || 0,
|
|
409
426
|
height: data.size?.height || 0,
|
|
410
427
|
},
|
|
411
428
|
align: data.align || types_1.TextAlign.Left,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
5
|
-
export * from
|
|
6
|
-
export * from
|
|
7
|
-
export * from
|
|
8
|
-
export * from
|
|
9
|
-
export * from
|
|
10
|
-
export * from
|
|
11
|
-
export * from './PolygonLayer';
|
|
1
|
+
export * from "./BaseLayer";
|
|
2
|
+
export * from "./BezierLayer";
|
|
3
|
+
export * from "./ImageLayer";
|
|
4
|
+
export * from "./TextLayer";
|
|
5
|
+
export * from "./MorphLayer";
|
|
6
|
+
export * from "./Div";
|
|
7
|
+
export * from "./LineLayer";
|
|
8
|
+
export * from "./QuadraticLayer";
|
|
9
|
+
export * from "./Path2DLayer";
|
|
10
|
+
export * from "./PolygonLayer";
|
|
@@ -16,11 +16,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./BaseLayer"), exports);
|
|
18
18
|
__exportStar(require("./BezierLayer"), exports);
|
|
19
|
-
__exportStar(require("./ClearLayer"), exports);
|
|
20
19
|
__exportStar(require("./ImageLayer"), exports);
|
|
21
20
|
__exportStar(require("./TextLayer"), exports);
|
|
22
21
|
__exportStar(require("./MorphLayer"), exports);
|
|
23
|
-
__exportStar(require("./
|
|
22
|
+
__exportStar(require("./Div"), exports);
|
|
24
23
|
__exportStar(require("./LineLayer"), exports);
|
|
25
24
|
__exportStar(require("./QuadraticLayer"), exports);
|
|
26
25
|
__exportStar(require("./Path2DLayer"), exports);
|