konva 9.3.21 → 10.0.0-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.
- package/README.md +1 -1
- package/konva.js +664 -226
- package/konva.min.js +46 -4
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +7 -11
- package/lib/BezierFunctions.js +9 -15
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +14 -20
- package/lib/Container.d.ts +7 -6
- package/lib/Container.js +12 -16
- package/lib/Context.d.ts +7 -5
- package/lib/Context.js +34 -14
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +3 -7
- package/lib/DragAndDrop.d.ts +3 -3
- package/lib/DragAndDrop.js +24 -27
- package/lib/Factory.d.ts +2 -2
- package/lib/Factory.js +24 -27
- package/lib/FastLayer.d.ts +1 -1
- package/lib/FastLayer.js +6 -10
- package/lib/Global.d.ts +4 -3
- package/lib/Global.js +19 -19
- package/lib/Group.d.ts +4 -3
- package/lib/Group.js +6 -10
- package/lib/Layer.d.ts +10 -9
- package/lib/Layer.js +33 -37
- package/lib/Node.d.ts +16 -13
- package/lib/Node.js +207 -123
- package/lib/PointerEvents.d.ts +4 -4
- package/lib/PointerEvents.js +7 -14
- package/lib/Shape.d.ts +7 -4
- package/lib/Shape.js +91 -91
- package/lib/Stage.d.ts +8 -7
- package/lib/Stage.js +66 -56
- package/lib/Tween.d.ts +3 -2
- package/lib/Tween.js +29 -31
- package/lib/Util.d.ts +3 -2
- package/lib/Util.js +98 -38
- package/lib/Validators.js +44 -57
- package/lib/_CoreInternals.d.ts +49 -23
- package/lib/_CoreInternals.js +33 -36
- package/lib/_FullInternals.d.ts +126 -62
- package/lib/_FullInternals.js +77 -78
- package/lib/canvas-backend.d.ts +2 -0
- package/lib/canvas-backend.js +27 -0
- package/lib/filters/Blur.d.ts +1 -1
- package/lib/filters/Blur.js +5 -9
- package/lib/filters/Brighten.d.ts +1 -1
- package/lib/filters/Brighten.js +5 -9
- package/lib/filters/Brightness.d.ts +2 -0
- package/lib/filters/Brightness.js +8 -0
- package/lib/filters/Contrast.d.ts +1 -1
- package/lib/filters/Contrast.js +5 -9
- package/lib/filters/Emboss.d.ts +1 -1
- package/lib/filters/Emboss.js +95 -101
- package/lib/filters/Enhance.d.ts +1 -1
- package/lib/filters/Enhance.js +5 -9
- package/lib/filters/Grayscale.d.ts +1 -1
- package/lib/filters/Grayscale.js +1 -5
- package/lib/filters/HSL.d.ts +1 -1
- package/lib/filters/HSL.js +7 -11
- package/lib/filters/HSV.d.ts +1 -1
- package/lib/filters/HSV.js +7 -11
- package/lib/filters/Invert.d.ts +1 -1
- package/lib/filters/Invert.js +1 -5
- package/lib/filters/Kaleidoscope.d.ts +1 -1
- package/lib/filters/Kaleidoscope.js +9 -13
- package/lib/filters/Mask.d.ts +1 -1
- package/lib/filters/Mask.js +16 -10
- package/lib/filters/Noise.d.ts +1 -1
- package/lib/filters/Noise.js +5 -9
- package/lib/filters/Pixelate.d.ts +1 -1
- package/lib/filters/Pixelate.js +7 -11
- package/lib/filters/Posterize.d.ts +1 -1
- package/lib/filters/Posterize.js +5 -9
- package/lib/filters/RGB.d.ts +1 -1
- package/lib/filters/RGB.js +7 -11
- package/lib/filters/RGBA.d.ts +1 -1
- package/lib/filters/RGBA.js +8 -12
- package/lib/filters/Sepia.d.ts +1 -1
- package/lib/filters/Sepia.js +1 -5
- package/lib/filters/Solarize.d.ts +1 -1
- package/lib/filters/Solarize.js +13 -29
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +5 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -4
- package/lib/shapes/Arc.d.ts +4 -3
- package/lib/shapes/Arc.js +13 -17
- package/lib/shapes/Arrow.d.ts +4 -3
- package/lib/shapes/Arrow.js +13 -17
- package/lib/shapes/Circle.d.ts +4 -3
- package/lib/shapes/Circle.js +7 -11
- package/lib/shapes/Ellipse.d.ts +4 -3
- package/lib/shapes/Ellipse.js +9 -13
- package/lib/shapes/Image.d.ts +4 -3
- package/lib/shapes/Image.js +17 -21
- package/lib/shapes/Label.d.ts +7 -6
- package/lib/shapes/Label.js +13 -18
- package/lib/shapes/Line.d.ts +4 -3
- package/lib/shapes/Line.js +10 -14
- package/lib/shapes/Path.d.ts +3 -2
- package/lib/shapes/Path.js +83 -23
- package/lib/shapes/Rect.d.ts +4 -3
- package/lib/shapes/Rect.js +9 -13
- package/lib/shapes/RegularPolygon.d.ts +6 -3
- package/lib/shapes/RegularPolygon.js +19 -16
- package/lib/shapes/Ring.d.ts +4 -3
- package/lib/shapes/Ring.js +8 -12
- package/lib/shapes/Sprite.d.ts +5 -4
- package/lib/shapes/Sprite.js +15 -19
- package/lib/shapes/Star.d.ts +4 -3
- package/lib/shapes/Star.js +9 -13
- package/lib/shapes/Text.d.ts +16 -3
- package/lib/shapes/Text.js +73 -53
- package/lib/shapes/TextPath.d.ts +5 -4
- package/lib/shapes/TextPath.js +48 -41
- package/lib/shapes/Transformer.d.ts +8 -8
- package/lib/shapes/Transformer.js +90 -90
- package/lib/shapes/Wedge.d.ts +4 -3
- package/lib/shapes/Wedge.js +12 -16
- package/lib/skia-backend.d.ts +2 -0
- package/lib/skia-backend.js +24 -0
- package/lib/types.d.ts +22 -22
- package/lib/types.js +21 -25
- package/package.json +53 -25
- package/lib/index-node.d.ts +0 -2
- package/lib/index-node.js +0 -21
- package/lib/index-types.d.ts +0 -181
package/lib/shapes/Text.js
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const Global_1 = require("../Global");
|
|
9
|
-
const Validators_1 = require("../Validators");
|
|
10
|
-
const Global_2 = require("../Global");
|
|
11
|
-
function stringToArray(string) {
|
|
1
|
+
import { Util } from "../Util.js";
|
|
2
|
+
import { Factory } from "../Factory.js";
|
|
3
|
+
import { Shape } from "../Shape.js";
|
|
4
|
+
import { Konva } from "../Global.js";
|
|
5
|
+
import { getNumberValidator, getStringValidator, getNumberOrAutoValidator, getBooleanValidator, } from "../Validators.js";
|
|
6
|
+
import { _registerNode } from "../Global.js";
|
|
7
|
+
export function stringToArray(string) {
|
|
12
8
|
return [...string].reduce((acc, char, index, array) => {
|
|
13
9
|
if (/\p{Emoji}/u.test(char)) {
|
|
14
10
|
const nextChar = array[index + 1];
|
|
@@ -68,7 +64,7 @@ function getDummyContext() {
|
|
|
68
64
|
if (dummyContext) {
|
|
69
65
|
return dummyContext;
|
|
70
66
|
}
|
|
71
|
-
dummyContext =
|
|
67
|
+
dummyContext = Util.createCanvasElement().getContext(CONTEXT_2D);
|
|
72
68
|
return dummyContext;
|
|
73
69
|
}
|
|
74
70
|
function _fillFunc(context) {
|
|
@@ -87,7 +83,7 @@ function checkDefaultFill(config) {
|
|
|
87
83
|
}
|
|
88
84
|
return config;
|
|
89
85
|
}
|
|
90
|
-
class Text extends
|
|
86
|
+
export class Text extends Shape {
|
|
91
87
|
constructor(config) {
|
|
92
88
|
super(checkDefaultFill(config));
|
|
93
89
|
this._partialTextX = 0;
|
|
@@ -98,20 +94,21 @@ class Text extends Shape_1.Shape {
|
|
|
98
94
|
this._setTextData();
|
|
99
95
|
}
|
|
100
96
|
_sceneFunc(context) {
|
|
97
|
+
var _a, _b;
|
|
101
98
|
const textArr = this.textArr, textArrLen = textArr.length;
|
|
102
99
|
if (!this.text()) {
|
|
103
100
|
return;
|
|
104
101
|
}
|
|
105
|
-
let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
|
|
102
|
+
let padding = this.padding(), fontSize = this.fontSize(), lineHeightPx = this.lineHeight() * fontSize, verticalAlign = this.verticalAlign(), direction = this.direction(), alignY = 0, align = this.align(), totalWidth = this.getWidth(), letterSpacing = this.letterSpacing(), charRenderFunc = this.charRenderFunc(), fill = this.fill(), textDecoration = this.textDecoration(), shouldUnderline = textDecoration.indexOf('underline') !== -1, shouldLineThrough = textDecoration.indexOf('line-through') !== -1, n;
|
|
106
103
|
direction = direction === INHERIT ? context.direction : direction;
|
|
107
104
|
let translateY = lineHeightPx / 2;
|
|
108
105
|
let baseline = MIDDLE;
|
|
109
|
-
if (
|
|
106
|
+
if (!Konva.legacyTextRendering) {
|
|
110
107
|
const metrics = this.measureSize('M');
|
|
111
108
|
baseline = 'alphabetic';
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
const ascent = (_a = metrics.fontBoundingBoxAscent) !== null && _a !== void 0 ? _a : metrics.actualBoundingBoxAscent;
|
|
110
|
+
const descent = (_b = metrics.fontBoundingBoxDescent) !== null && _b !== void 0 ? _b : metrics.actualBoundingBoxDescent;
|
|
111
|
+
translateY = (ascent - descent) / 2 + lineHeightPx / 2;
|
|
115
112
|
}
|
|
116
113
|
if (direction === RTL) {
|
|
117
114
|
context.setAttr('direction', direction);
|
|
@@ -140,7 +137,7 @@ class Text extends Shape_1.Shape {
|
|
|
140
137
|
if (shouldUnderline) {
|
|
141
138
|
context.save();
|
|
142
139
|
context.beginPath();
|
|
143
|
-
const yOffset =
|
|
140
|
+
const yOffset = !Konva.legacyTextRendering
|
|
144
141
|
? Math.round(fontSize / 4)
|
|
145
142
|
: Math.round(fontSize / 2);
|
|
146
143
|
const x = lineTranslateX;
|
|
@@ -154,20 +151,8 @@ class Text extends Shape_1.Shape {
|
|
|
154
151
|
context.stroke();
|
|
155
152
|
context.restore();
|
|
156
153
|
}
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
context.beginPath();
|
|
160
|
-
const yOffset = Global_1.Konva._fixTextRendering ? -Math.round(fontSize / 4) : 0;
|
|
161
|
-
context.moveTo(lineTranslateX, translateY + lineTranslateY + yOffset);
|
|
162
|
-
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
163
|
-
context.lineTo(lineTranslateX + Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
164
|
-
context.lineWidth = fontSize / 15;
|
|
165
|
-
const gradient = this._getLinearGradient();
|
|
166
|
-
context.strokeStyle = gradient || fill;
|
|
167
|
-
context.stroke();
|
|
168
|
-
context.restore();
|
|
169
|
-
}
|
|
170
|
-
if (direction !== RTL && (letterSpacing !== 0 || align === JUSTIFY)) {
|
|
154
|
+
if (direction !== RTL &&
|
|
155
|
+
(letterSpacing !== 0 || align === JUSTIFY || charRenderFunc)) {
|
|
171
156
|
const spacesNumber = text.split(' ').length - 1;
|
|
172
157
|
const array = stringToArray(text);
|
|
173
158
|
for (let li = 0; li < array.length; li++) {
|
|
@@ -178,7 +163,27 @@ class Text extends Shape_1.Shape {
|
|
|
178
163
|
this._partialTextX = lineTranslateX;
|
|
179
164
|
this._partialTextY = translateY + lineTranslateY;
|
|
180
165
|
this._partialText = letter;
|
|
166
|
+
if (charRenderFunc) {
|
|
167
|
+
context.save();
|
|
168
|
+
const previousLines = textArr.slice(0, n);
|
|
169
|
+
const previousGraphemes = previousLines.reduce((acc, line) => acc + stringToArray(line.text).length, 0);
|
|
170
|
+
const charIndex = li + previousGraphemes;
|
|
171
|
+
charRenderFunc({
|
|
172
|
+
char: letter,
|
|
173
|
+
index: charIndex,
|
|
174
|
+
x: lineTranslateX,
|
|
175
|
+
y: translateY + lineTranslateY,
|
|
176
|
+
lineIndex: n,
|
|
177
|
+
column: li,
|
|
178
|
+
isLastInLine: lastLine,
|
|
179
|
+
width: this.measureSize(letter).width,
|
|
180
|
+
context,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
181
183
|
context.fillStrokeShape(this);
|
|
184
|
+
if (charRenderFunc) {
|
|
185
|
+
context.restore();
|
|
186
|
+
}
|
|
182
187
|
lineTranslateX += this.measureSize(letter).width + letterSpacing;
|
|
183
188
|
}
|
|
184
189
|
}
|
|
@@ -191,6 +196,21 @@ class Text extends Shape_1.Shape {
|
|
|
191
196
|
this._partialText = text;
|
|
192
197
|
context.fillStrokeShape(this);
|
|
193
198
|
}
|
|
199
|
+
if (shouldLineThrough) {
|
|
200
|
+
context.save();
|
|
201
|
+
context.beginPath();
|
|
202
|
+
const yOffset = !Konva.legacyTextRendering
|
|
203
|
+
? -Math.round(fontSize / 4)
|
|
204
|
+
: 0;
|
|
205
|
+
context.moveTo(0, translateY + lineTranslateY + yOffset);
|
|
206
|
+
const lineWidth = align === JUSTIFY && !lastLine ? totalWidth - padding * 2 : width;
|
|
207
|
+
context.lineTo(Math.round(lineWidth), translateY + lineTranslateY + yOffset);
|
|
208
|
+
context.lineWidth = fontSize / 15;
|
|
209
|
+
const gradient = this._getLinearGradient();
|
|
210
|
+
context.strokeStyle = gradient || fill;
|
|
211
|
+
context.stroke();
|
|
212
|
+
context.restore();
|
|
213
|
+
}
|
|
194
214
|
context.restore();
|
|
195
215
|
if (textArrLen > 1) {
|
|
196
216
|
translateY += lineHeightPx;
|
|
@@ -205,7 +225,7 @@ class Text extends Shape_1.Shape {
|
|
|
205
225
|
context.fillStrokeShape(this);
|
|
206
226
|
}
|
|
207
227
|
setText(text) {
|
|
208
|
-
const str =
|
|
228
|
+
const str = Util._isString(text)
|
|
209
229
|
? text
|
|
210
230
|
: text === null || text === undefined
|
|
211
231
|
? ''
|
|
@@ -228,7 +248,7 @@ class Text extends Shape_1.Shape {
|
|
|
228
248
|
return this.textWidth;
|
|
229
249
|
}
|
|
230
250
|
getTextHeight() {
|
|
231
|
-
|
|
251
|
+
Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
|
|
232
252
|
return this.textHeight;
|
|
233
253
|
}
|
|
234
254
|
measureSize(text) {
|
|
@@ -408,7 +428,6 @@ class Text extends Shape_1.Shape {
|
|
|
408
428
|
return super._useBufferCanvas();
|
|
409
429
|
}
|
|
410
430
|
}
|
|
411
|
-
exports.Text = Text;
|
|
412
431
|
Text.prototype._fillFunc = _fillFunc;
|
|
413
432
|
Text.prototype._strokeFunc = _strokeFunc;
|
|
414
433
|
Text.prototype.className = TEXT_UPPER;
|
|
@@ -420,20 +439,21 @@ Text.prototype._attrsAffectingSize = [
|
|
|
420
439
|
'lineHeight',
|
|
421
440
|
'letterSpacing',
|
|
422
441
|
];
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
442
|
+
_registerNode(Text);
|
|
443
|
+
Factory.overWriteSetter(Text, 'width', getNumberOrAutoValidator());
|
|
444
|
+
Factory.overWriteSetter(Text, 'height', getNumberOrAutoValidator());
|
|
445
|
+
Factory.addGetterSetter(Text, 'direction', INHERIT);
|
|
446
|
+
Factory.addGetterSetter(Text, 'fontFamily', 'Arial');
|
|
447
|
+
Factory.addGetterSetter(Text, 'fontSize', 12, getNumberValidator());
|
|
448
|
+
Factory.addGetterSetter(Text, 'fontStyle', NORMAL);
|
|
449
|
+
Factory.addGetterSetter(Text, 'fontVariant', NORMAL);
|
|
450
|
+
Factory.addGetterSetter(Text, 'padding', 0, getNumberValidator());
|
|
451
|
+
Factory.addGetterSetter(Text, 'align', LEFT);
|
|
452
|
+
Factory.addGetterSetter(Text, 'verticalAlign', TOP);
|
|
453
|
+
Factory.addGetterSetter(Text, 'lineHeight', 1, getNumberValidator());
|
|
454
|
+
Factory.addGetterSetter(Text, 'wrap', WORD);
|
|
455
|
+
Factory.addGetterSetter(Text, 'ellipsis', false, getBooleanValidator());
|
|
456
|
+
Factory.addGetterSetter(Text, 'letterSpacing', 0, getNumberValidator());
|
|
457
|
+
Factory.addGetterSetter(Text, 'text', '', getStringValidator());
|
|
458
|
+
Factory.addGetterSetter(Text, 'textDecoration', '');
|
|
459
|
+
Factory.addGetterSetter(Text, 'charRenderFunc', undefined);
|
package/lib/shapes/TextPath.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { Context } from '../Context.
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { Context } from '../Context.ts';
|
|
2
|
+
import type { ShapeConfig } from '../Shape.ts';
|
|
3
|
+
import { Shape } from '../Shape.ts';
|
|
4
|
+
import { Text } from './Text.ts';
|
|
5
|
+
import type { GetSet, PathSegment, Vector2d } from '../types.ts';
|
|
5
6
|
export interface TextPathConfig extends ShapeConfig {
|
|
6
7
|
text?: string;
|
|
7
8
|
data?: string;
|
package/lib/shapes/TextPath.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const Text_1 = require("./Text");
|
|
9
|
-
const Validators_1 = require("../Validators");
|
|
10
|
-
const Global_1 = require("../Global");
|
|
1
|
+
import { Util } from "../Util.js";
|
|
2
|
+
import { Factory } from "../Factory.js";
|
|
3
|
+
import { Shape } from "../Shape.js";
|
|
4
|
+
import { Path } from "./Path.js";
|
|
5
|
+
import { Text, stringToArray } from "./Text.js";
|
|
6
|
+
import { getNumberValidator } from "../Validators.js";
|
|
7
|
+
import { _registerNode } from "../Global.js";
|
|
11
8
|
const EMPTY_STRING = '', NORMAL = 'normal';
|
|
12
9
|
function _fillFunc(context) {
|
|
13
10
|
context.fillText(this.partialText, 0, 0);
|
|
@@ -15,10 +12,10 @@ function _fillFunc(context) {
|
|
|
15
12
|
function _strokeFunc(context) {
|
|
16
13
|
context.strokeText(this.partialText, 0, 0);
|
|
17
14
|
}
|
|
18
|
-
class TextPath extends
|
|
15
|
+
export class TextPath extends Shape {
|
|
19
16
|
constructor(config) {
|
|
20
17
|
super(config);
|
|
21
|
-
this.dummyCanvas =
|
|
18
|
+
this.dummyCanvas = Util.createCanvasElement();
|
|
22
19
|
this.dataArray = [];
|
|
23
20
|
this._readDataAttribute();
|
|
24
21
|
this.on('dataChange.konva', function () {
|
|
@@ -29,7 +26,7 @@ class TextPath extends Shape_1.Shape {
|
|
|
29
26
|
this._setTextData();
|
|
30
27
|
}
|
|
31
28
|
_getTextPathLength() {
|
|
32
|
-
return
|
|
29
|
+
return Path.getPathLength(this.dataArray);
|
|
33
30
|
}
|
|
34
31
|
_getPointAtLength(length) {
|
|
35
32
|
if (!this.attrs.data) {
|
|
@@ -39,10 +36,10 @@ class TextPath extends Shape_1.Shape {
|
|
|
39
36
|
if (length - 1 > totalLength) {
|
|
40
37
|
return null;
|
|
41
38
|
}
|
|
42
|
-
return
|
|
39
|
+
return Path.getPointAtLengthOfDataArray(length, this.dataArray);
|
|
43
40
|
}
|
|
44
41
|
_readDataAttribute() {
|
|
45
|
-
this.dataArray =
|
|
42
|
+
this.dataArray = Path.parsePathData(this.attrs.data);
|
|
46
43
|
this.pathLength = this._getTextPathLength();
|
|
47
44
|
}
|
|
48
45
|
_sceneFunc(context) {
|
|
@@ -98,14 +95,14 @@ class TextPath extends Shape_1.Shape {
|
|
|
98
95
|
return this.textWidth;
|
|
99
96
|
}
|
|
100
97
|
getTextHeight() {
|
|
101
|
-
|
|
98
|
+
Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
|
|
102
99
|
return this.textHeight;
|
|
103
100
|
}
|
|
104
101
|
setText(text) {
|
|
105
|
-
return
|
|
102
|
+
return Text.prototype.setText.call(this, text);
|
|
106
103
|
}
|
|
107
104
|
_getContextFont() {
|
|
108
|
-
return
|
|
105
|
+
return Text.prototype._getContextFont.call(this);
|
|
109
106
|
}
|
|
110
107
|
_getTextSize(text) {
|
|
111
108
|
const dummyCanvas = this.dummyCanvas;
|
|
@@ -120,7 +117,17 @@ class TextPath extends Shape_1.Shape {
|
|
|
120
117
|
};
|
|
121
118
|
}
|
|
122
119
|
_setTextData() {
|
|
123
|
-
const
|
|
120
|
+
const charArr = stringToArray(this.text());
|
|
121
|
+
const chars = [];
|
|
122
|
+
let width = 0;
|
|
123
|
+
for (let i = 0; i < charArr.length; i++) {
|
|
124
|
+
chars.push({
|
|
125
|
+
char: charArr[i],
|
|
126
|
+
width: this._getTextSize(charArr[i]).width,
|
|
127
|
+
});
|
|
128
|
+
width += chars[i].width;
|
|
129
|
+
}
|
|
130
|
+
const { height } = this._getTextSize(this.attrs.text);
|
|
124
131
|
this.textWidth = width;
|
|
125
132
|
this.textHeight = height;
|
|
126
133
|
this.glyphInfo = [];
|
|
@@ -138,25 +145,26 @@ class TextPath extends Shape_1.Shape {
|
|
|
138
145
|
if (align === 'right') {
|
|
139
146
|
offset = Math.max(0, this.pathLength - textWidth);
|
|
140
147
|
}
|
|
141
|
-
const charArr = (0, Text_1.stringToArray)(this.text());
|
|
142
148
|
let offsetToGlyph = offset;
|
|
143
|
-
for (let i = 0; i <
|
|
149
|
+
for (let i = 0; i < chars.length; i++) {
|
|
144
150
|
const charStartPoint = this._getPointAtLength(offsetToGlyph);
|
|
145
151
|
if (!charStartPoint)
|
|
146
152
|
return;
|
|
147
|
-
|
|
148
|
-
|
|
153
|
+
const char = chars[i].char;
|
|
154
|
+
let glyphWidth = chars[i].width + letterSpacing;
|
|
155
|
+
if (char === ' ' && align === 'justify') {
|
|
149
156
|
const numberOfSpaces = this.text().split(' ').length - 1;
|
|
150
157
|
glyphWidth += (this.pathLength - textWidth) / numberOfSpaces;
|
|
151
158
|
}
|
|
152
159
|
const charEndPoint = this._getPointAtLength(offsetToGlyph + glyphWidth);
|
|
153
|
-
if (!charEndPoint)
|
|
160
|
+
if (!charEndPoint) {
|
|
154
161
|
return;
|
|
155
|
-
|
|
162
|
+
}
|
|
163
|
+
const width = Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
|
|
156
164
|
let kern = 0;
|
|
157
165
|
if (kerningFunc) {
|
|
158
166
|
try {
|
|
159
|
-
kern = kerningFunc(
|
|
167
|
+
kern = kerningFunc(chars[i - 1].char, char) * this.fontSize();
|
|
160
168
|
}
|
|
161
169
|
catch (e) {
|
|
162
170
|
kern = 0;
|
|
@@ -165,7 +173,7 @@ class TextPath extends Shape_1.Shape {
|
|
|
165
173
|
charStartPoint.x += kern;
|
|
166
174
|
charEndPoint.x += kern;
|
|
167
175
|
this.textWidth += kern;
|
|
168
|
-
const midpoint =
|
|
176
|
+
const midpoint = Path.getPointOnLine(kern + width / 2.0, charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
|
|
169
177
|
const rotation = Math.atan2(charEndPoint.y - charStartPoint.y, charEndPoint.x - charStartPoint.x);
|
|
170
178
|
this.glyphInfo.push({
|
|
171
179
|
transposeX: midpoint.x,
|
|
@@ -216,26 +224,25 @@ class TextPath extends Shape_1.Shape {
|
|
|
216
224
|
};
|
|
217
225
|
}
|
|
218
226
|
destroy() {
|
|
219
|
-
|
|
227
|
+
Util.releaseCanvas(this.dummyCanvas);
|
|
220
228
|
return super.destroy();
|
|
221
229
|
}
|
|
222
230
|
}
|
|
223
|
-
exports.TextPath = TextPath;
|
|
224
231
|
TextPath.prototype._fillFunc = _fillFunc;
|
|
225
232
|
TextPath.prototype._strokeFunc = _strokeFunc;
|
|
226
233
|
TextPath.prototype._fillFuncHit = _fillFunc;
|
|
227
234
|
TextPath.prototype._strokeFuncHit = _strokeFunc;
|
|
228
235
|
TextPath.prototype.className = 'TextPath';
|
|
229
236
|
TextPath.prototype._attrsAffectingSize = ['text', 'fontSize', 'data'];
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
237
|
+
_registerNode(TextPath);
|
|
238
|
+
Factory.addGetterSetter(TextPath, 'data');
|
|
239
|
+
Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial');
|
|
240
|
+
Factory.addGetterSetter(TextPath, 'fontSize', 12, getNumberValidator());
|
|
241
|
+
Factory.addGetterSetter(TextPath, 'fontStyle', NORMAL);
|
|
242
|
+
Factory.addGetterSetter(TextPath, 'align', 'left');
|
|
243
|
+
Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator());
|
|
244
|
+
Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
|
|
245
|
+
Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
|
|
246
|
+
Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
|
|
247
|
+
Factory.addGetterSetter(TextPath, 'textDecoration', '');
|
|
248
|
+
Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Transform } from '../Util.
|
|
2
|
-
import { Node } from '../Node.
|
|
3
|
-
import { Rect } from './Rect.
|
|
4
|
-
import { Group } from '../Group.
|
|
5
|
-
import { ContainerConfig } from '../Container.
|
|
6
|
-
import { GetSet, IRect, Vector2d } from '../types.
|
|
1
|
+
import { Transform } from '../Util.ts';
|
|
2
|
+
import { Node } from '../Node.ts';
|
|
3
|
+
import { Rect } from './Rect.ts';
|
|
4
|
+
import { Group } from '../Group.ts';
|
|
5
|
+
import type { ContainerConfig } from '../Container.ts';
|
|
6
|
+
import type { GetSet, IRect, Vector2d } from '../types.ts';
|
|
7
7
|
export interface Box extends IRect {
|
|
8
8
|
rotation: number;
|
|
9
9
|
}
|
|
@@ -49,11 +49,11 @@ export declare class Transformer extends Group {
|
|
|
49
49
|
constructor(config?: TransformerConfig);
|
|
50
50
|
attachTo(node: Node): this;
|
|
51
51
|
setNode(node: Node): this;
|
|
52
|
-
getNode(): Node<import("../Node.
|
|
52
|
+
getNode(): Node<import("../Node.ts").NodeConfig>;
|
|
53
53
|
_getEventNamespace(): string;
|
|
54
54
|
setNodes(nodes?: Array<Node>): this;
|
|
55
55
|
_proxyDrag(node: Node): void;
|
|
56
|
-
getNodes(): Node<import("../Node.
|
|
56
|
+
getNodes(): Node<import("../Node.ts").NodeConfig>[];
|
|
57
57
|
getActiveAnchor(): string | null;
|
|
58
58
|
detach(): void;
|
|
59
59
|
_resetTransformCache(): void;
|