konva 8.4.2 → 9.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 -9
- package/konva.js +17669 -16968
- package/konva.min.js +3 -3
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +11 -7
- package/lib/BezierFunctions.d.ts +6 -0
- package/lib/BezierFunctions.js +791 -0
- package/lib/Canvas.d.ts +2 -1
- package/lib/Canvas.js +26 -18
- package/lib/Container.d.ts +4 -4
- package/lib/Container.js +16 -12
- package/lib/Context.d.ts +16 -13
- package/lib/Context.js +27 -19
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +7 -3
- package/lib/DragAndDrop.d.ts +3 -3
- package/lib/DragAndDrop.js +25 -22
- package/lib/Factory.js +27 -24
- package/lib/FastLayer.d.ts +1 -1
- package/lib/FastLayer.js +10 -6
- package/lib/Global.js +16 -12
- package/lib/Group.d.ts +3 -3
- package/lib/Group.js +10 -6
- package/lib/Layer.d.ts +9 -9
- package/lib/Layer.js +37 -33
- package/lib/Node.d.ts +8 -8
- package/lib/Node.js +95 -90
- package/lib/PointerEvents.d.ts +4 -4
- package/lib/PointerEvents.js +15 -7
- package/lib/Shape.d.ts +6 -4
- package/lib/Shape.js +90 -86
- package/lib/Stage.d.ts +7 -7
- package/lib/Stage.js +51 -47
- package/lib/Tween.d.ts +2 -2
- package/lib/Tween.js +26 -22
- package/lib/Util.d.ts +2 -2
- package/lib/Util.js +29 -25
- package/lib/Validators.js +58 -44
- package/lib/_CoreInternals.d.ts +29 -29
- package/lib/_CoreInternals.js +36 -33
- package/lib/_FullInternals.d.ts +67 -67
- package/lib/_FullInternals.js +78 -75
- package/lib/filters/Blur.d.ts +1 -1
- package/lib/filters/Blur.js +9 -5
- package/lib/filters/Brighten.d.ts +1 -1
- package/lib/filters/Brighten.js +9 -5
- package/lib/filters/Contrast.d.ts +1 -1
- package/lib/filters/Contrast.js +9 -5
- package/lib/filters/Emboss.d.ts +1 -1
- package/lib/filters/Emboss.js +14 -10
- package/lib/filters/Enhance.d.ts +1 -1
- package/lib/filters/Enhance.js +9 -5
- package/lib/filters/Grayscale.d.ts +1 -1
- package/lib/filters/Grayscale.js +5 -1
- package/lib/filters/HSL.d.ts +1 -1
- package/lib/filters/HSL.js +11 -7
- package/lib/filters/HSV.d.ts +1 -1
- package/lib/filters/HSV.js +11 -7
- package/lib/filters/Invert.d.ts +1 -1
- package/lib/filters/Invert.js +5 -1
- package/lib/filters/Kaleidoscope.d.ts +1 -1
- package/lib/filters/Kaleidoscope.js +13 -9
- package/lib/filters/Mask.d.ts +1 -1
- package/lib/filters/Mask.js +9 -5
- package/lib/filters/Noise.d.ts +1 -1
- package/lib/filters/Noise.js +9 -5
- package/lib/filters/Pixelate.d.ts +1 -1
- package/lib/filters/Pixelate.js +11 -7
- package/lib/filters/Posterize.d.ts +1 -1
- package/lib/filters/Posterize.js +9 -5
- package/lib/filters/RGB.d.ts +1 -1
- package/lib/filters/RGB.js +11 -7
- package/lib/filters/RGBA.d.ts +1 -1
- package/lib/filters/RGBA.js +12 -8
- package/lib/filters/Sepia.d.ts +1 -1
- package/lib/filters/Sepia.js +5 -1
- package/lib/filters/Solarize.d.ts +1 -1
- package/lib/filters/Solarize.js +5 -1
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +9 -5
- package/lib/index-node.d.ts +1 -1
- package/lib/index-node.js +7 -5
- package/lib/index-types.d.ts +124 -124
- package/lib/index.d.ts +1 -1
- package/lib/index.js +4 -2
- package/lib/shapes/Arc.d.ts +6 -5
- package/lib/shapes/Arc.js +17 -13
- package/lib/shapes/Arrow.d.ts +5 -4
- package/lib/shapes/Arrow.js +17 -13
- package/lib/shapes/Circle.d.ts +6 -5
- package/lib/shapes/Circle.js +11 -7
- package/lib/shapes/Ellipse.d.ts +6 -5
- package/lib/shapes/Ellipse.js +13 -9
- package/lib/shapes/Image.d.ts +5 -5
- package/lib/shapes/Image.js +21 -17
- package/lib/shapes/Label.d.ts +8 -7
- package/lib/shapes/Label.js +18 -13
- package/lib/shapes/Line.d.ts +3 -3
- package/lib/shapes/Line.js +14 -10
- package/lib/shapes/Path.d.ts +6 -3
- package/lib/shapes/Path.js +44 -43
- package/lib/shapes/Rect.d.ts +3 -3
- package/lib/shapes/Rect.js +13 -9
- package/lib/shapes/RegularPolygon.d.ts +6 -5
- package/lib/shapes/RegularPolygon.js +12 -8
- package/lib/shapes/Ring.d.ts +6 -5
- package/lib/shapes/Ring.js +12 -8
- package/lib/shapes/Sprite.d.ts +7 -6
- package/lib/shapes/Sprite.js +19 -15
- package/lib/shapes/Star.d.ts +6 -5
- package/lib/shapes/Star.js +13 -9
- package/lib/shapes/Text.d.ts +8 -7
- package/lib/shapes/Text.js +31 -26
- package/lib/shapes/TextPath.d.ts +12 -7
- package/lib/shapes/TextPath.js +82 -188
- package/lib/shapes/Transformer.d.ts +10 -10
- package/lib/shapes/Transformer.js +92 -81
- package/lib/shapes/Wedge.d.ts +6 -5
- package/lib/shapes/Wedge.js +16 -12
- package/lib/types.d.ts +6 -0
- package/lib/types.js +5 -2
- package/package.json +13 -42
- package/cmj/Animation.d.ts +0 -24
- package/cmj/Animation.js +0 -145
- package/cmj/Canvas.d.ts +0 -32
- package/cmj/Canvas.js +0 -114
- package/cmj/Container.d.ts +0 -47
- package/cmj/Container.js +0 -325
- package/cmj/Context.d.ts +0 -84
- package/cmj/Context.js +0 -538
- package/cmj/Core.d.ts +0 -3
- package/cmj/Core.js +0 -7
- package/cmj/DragAndDrop.d.ts +0 -17
- package/cmj/DragAndDrop.js +0 -111
- package/cmj/Factory.d.ts +0 -11
- package/cmj/Factory.js +0 -125
- package/cmj/FastLayer.d.ts +0 -4
- package/cmj/FastLayer.js +0 -16
- package/cmj/Global.d.ts +0 -34
- package/cmj/Global.js +0 -61
- package/cmj/Group.d.ts +0 -8
- package/cmj/Group.js +0 -17
- package/cmj/Layer.d.ts +0 -61
- package/cmj/Layer.js +0 -309
- package/cmj/Node.d.ts +0 -328
- package/cmj/Node.js +0 -1420
- package/cmj/PointerEvents.d.ts +0 -11
- package/cmj/PointerEvents.js +0 -45
- package/cmj/Shape.d.ts +0 -184
- package/cmj/Shape.js +0 -521
- package/cmj/Stage.d.ts +0 -85
- package/cmj/Stage.js +0 -692
- package/cmj/Tween.d.ts +0 -86
- package/cmj/Tween.js +0 -520
- package/cmj/Util.d.ts +0 -91
- package/cmj/Util.js +0 -801
- package/cmj/Validators.d.ts +0 -11
- package/cmj/Validators.js +0 -192
- package/cmj/_CoreInternals.d.ts +0 -152
- package/cmj/_CoreInternals.js +0 -37
- package/cmj/_FullInternals.d.ts +0 -196
- package/cmj/_FullInternals.js +0 -81
- package/cmj/filters/Blur.d.ts +0 -2
- package/cmj/filters/Blur.js +0 -701
- package/cmj/filters/Brighten.d.ts +0 -2
- package/cmj/filters/Brighten.js +0 -16
- package/cmj/filters/Contrast.d.ts +0 -2
- package/cmj/filters/Contrast.js +0 -38
- package/cmj/filters/Emboss.d.ts +0 -2
- package/cmj/filters/Emboss.js +0 -106
- package/cmj/filters/Enhance.d.ts +0 -2
- package/cmj/filters/Enhance.js +0 -87
- package/cmj/filters/Grayscale.d.ts +0 -2
- package/cmj/filters/Grayscale.js +0 -13
- package/cmj/filters/HSL.d.ts +0 -2
- package/cmj/filters/HSL.js +0 -28
- package/cmj/filters/HSV.d.ts +0 -2
- package/cmj/filters/HSV.js +0 -28
- package/cmj/filters/Invert.d.ts +0 -2
- package/cmj/filters/Invert.js +0 -12
- package/cmj/filters/Kaleidoscope.d.ts +0 -2
- package/cmj/filters/Kaleidoscope.js +0 -137
- package/cmj/filters/Mask.d.ts +0 -2
- package/cmj/filters/Mask.js +0 -144
- package/cmj/filters/Noise.d.ts +0 -2
- package/cmj/filters/Noise.js +0 -16
- package/cmj/filters/Pixelate.d.ts +0 -2
- package/cmj/filters/Pixelate.js +0 -64
- package/cmj/filters/Posterize.d.ts +0 -2
- package/cmj/filters/Posterize.js +0 -14
- package/cmj/filters/RGB.d.ts +0 -2
- package/cmj/filters/RGB.js +0 -43
- package/cmj/filters/RGBA.d.ts +0 -2
- package/cmj/filters/RGBA.js +0 -53
- package/cmj/filters/Sepia.d.ts +0 -2
- package/cmj/filters/Sepia.js +0 -15
- package/cmj/filters/Solarize.d.ts +0 -2
- package/cmj/filters/Solarize.js +0 -29
- package/cmj/filters/Threshold.d.ts +0 -2
- package/cmj/filters/Threshold.js +0 -14
- package/cmj/index-node.d.ts +0 -2
- package/cmj/index-node.js +0 -21
- package/cmj/index-types.d.ts +0 -181
- package/cmj/index.d.ts +0 -2
- package/cmj/index.js +0 -4
- package/cmj/package.json +0 -6
- package/cmj/shapes/Arc.d.ts +0 -25
- package/cmj/shapes/Arc.js +0 -59
- package/cmj/shapes/Arrow.d.ts +0 -25
- package/cmj/shapes/Arrow.js +0 -103
- package/cmj/shapes/Circle.d.ts +0 -13
- package/cmj/shapes/Circle.js +0 -37
- package/cmj/shapes/Ellipse.d.ts +0 -16
- package/cmj/shapes/Ellipse.js +0 -41
- package/cmj/shapes/Image.d.ts +0 -25
- package/cmj/shapes/Image.js +0 -117
- package/cmj/shapes/Label.d.ts +0 -35
- package/cmj/shapes/Label.js +0 -178
- package/cmj/shapes/Line.d.ts +0 -28
- package/cmj/shapes/Line.js +0 -159
- package/cmj/shapes/Path.d.ts +0 -37
- package/cmj/shapes/Path.js +0 -631
- package/cmj/shapes/Rect.d.ts +0 -10
- package/cmj/shapes/Rect.js +0 -26
- package/cmj/shapes/RegularPolygon.d.ts +0 -22
- package/cmj/shapes/RegularPolygon.js +0 -69
- package/cmj/shapes/Ring.d.ts +0 -15
- package/cmj/shapes/Ring.js +0 -37
- package/cmj/shapes/Sprite.d.ts +0 -30
- package/cmj/shapes/Sprite.js +0 -112
- package/cmj/shapes/Star.d.ts +0 -17
- package/cmj/shapes/Star.js +0 -42
- package/cmj/shapes/Text.d.ts +0 -62
- package/cmj/shapes/Text.js +0 -373
- package/cmj/shapes/TextPath.d.ts +0 -55
- package/cmj/shapes/TextPath.js +0 -351
- package/cmj/shapes/Transformer.d.ts +0 -116
- package/cmj/shapes/Transformer.js +0 -964
- package/cmj/shapes/Wedge.d.ts +0 -17
- package/cmj/shapes/Wedge.js +0 -42
- package/cmj/types.d.ts +0 -50
- package/cmj/types.js +0 -25
package/lib/shapes/Text.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Text = exports.stringToArray = void 0;
|
|
4
|
+
const Util_1 = require("../Util");
|
|
5
|
+
const Factory_1 = require("../Factory");
|
|
6
|
+
const Shape_1 = require("../Shape");
|
|
7
|
+
const Validators_1 = require("../Validators");
|
|
8
|
+
const Global_1 = require("../Global");
|
|
9
|
+
function stringToArray(string) {
|
|
7
10
|
return Array.from(string);
|
|
8
11
|
}
|
|
12
|
+
exports.stringToArray = stringToArray;
|
|
9
13
|
var AUTO = 'auto', CENTER = 'center', JUSTIFY = 'justify', CHANGE_KONVA = 'Change.konva', CONTEXT_2D = '2d', DASH = '-', LEFT = 'left', TEXT = 'text', TEXT_UPPER = 'Text', TOP = 'top', BOTTOM = 'bottom', MIDDLE = 'middle', NORMAL = 'normal', PX_SPACE = 'px ', SPACE = ' ', RIGHT = 'right', WORD = 'word', CHAR = 'char', NONE = 'none', ELLIPSIS = '…', ATTR_CHANGE_LIST = [
|
|
10
14
|
'fontFamily',
|
|
11
15
|
'fontSize',
|
|
@@ -41,7 +45,7 @@ function getDummyContext() {
|
|
|
41
45
|
if (dummyContext) {
|
|
42
46
|
return dummyContext;
|
|
43
47
|
}
|
|
44
|
-
dummyContext = Util.createCanvasElement().getContext(CONTEXT_2D);
|
|
48
|
+
dummyContext = Util_1.Util.createCanvasElement().getContext(CONTEXT_2D);
|
|
45
49
|
return dummyContext;
|
|
46
50
|
}
|
|
47
51
|
function _fillFunc(context) {
|
|
@@ -59,7 +63,7 @@ function checkDefaultFill(config) {
|
|
|
59
63
|
}
|
|
60
64
|
return config;
|
|
61
65
|
}
|
|
62
|
-
|
|
66
|
+
class Text extends Shape_1.Shape {
|
|
63
67
|
constructor(config) {
|
|
64
68
|
super(checkDefaultFill(config));
|
|
65
69
|
this._partialTextX = 0;
|
|
@@ -167,7 +171,7 @@ export class Text extends Shape {
|
|
|
167
171
|
context.fillStrokeShape(this);
|
|
168
172
|
}
|
|
169
173
|
setText(text) {
|
|
170
|
-
var str = Util._isString(text)
|
|
174
|
+
var str = Util_1.Util._isString(text)
|
|
171
175
|
? text
|
|
172
176
|
: text === null || text === undefined
|
|
173
177
|
? ''
|
|
@@ -190,7 +194,7 @@ export class Text extends Shape {
|
|
|
190
194
|
return this.textWidth;
|
|
191
195
|
}
|
|
192
196
|
getTextHeight() {
|
|
193
|
-
Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
|
|
197
|
+
Util_1.Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
|
|
194
198
|
return this.textHeight;
|
|
195
199
|
}
|
|
196
200
|
measureSize(text) {
|
|
@@ -339,6 +343,7 @@ export class Text extends Shape {
|
|
|
339
343
|
return true;
|
|
340
344
|
}
|
|
341
345
|
}
|
|
346
|
+
exports.Text = Text;
|
|
342
347
|
Text.prototype._fillFunc = _fillFunc;
|
|
343
348
|
Text.prototype._strokeFunc = _strokeFunc;
|
|
344
349
|
Text.prototype.className = TEXT_UPPER;
|
|
@@ -350,19 +355,19 @@ Text.prototype._attrsAffectingSize = [
|
|
|
350
355
|
'lineHeight',
|
|
351
356
|
'letterSpacing',
|
|
352
357
|
];
|
|
353
|
-
_registerNode(Text);
|
|
354
|
-
Factory.overWriteSetter(Text, 'width', getNumberOrAutoValidator());
|
|
355
|
-
Factory.overWriteSetter(Text, 'height', getNumberOrAutoValidator());
|
|
356
|
-
Factory.addGetterSetter(Text, 'fontFamily', 'Arial');
|
|
357
|
-
Factory.addGetterSetter(Text, 'fontSize', 12, getNumberValidator());
|
|
358
|
-
Factory.addGetterSetter(Text, 'fontStyle', NORMAL);
|
|
359
|
-
Factory.addGetterSetter(Text, 'fontVariant', NORMAL);
|
|
360
|
-
Factory.addGetterSetter(Text, 'padding', 0, getNumberValidator());
|
|
361
|
-
Factory.addGetterSetter(Text, 'align', LEFT);
|
|
362
|
-
Factory.addGetterSetter(Text, 'verticalAlign', TOP);
|
|
363
|
-
Factory.addGetterSetter(Text, 'lineHeight', 1, getNumberValidator());
|
|
364
|
-
Factory.addGetterSetter(Text, 'wrap', WORD);
|
|
365
|
-
Factory.addGetterSetter(Text, 'ellipsis', false, getBooleanValidator());
|
|
366
|
-
Factory.addGetterSetter(Text, 'letterSpacing', 0, getNumberValidator());
|
|
367
|
-
Factory.addGetterSetter(Text, 'text', '', getStringValidator());
|
|
368
|
-
Factory.addGetterSetter(Text, 'textDecoration', '');
|
|
358
|
+
(0, Global_1._registerNode)(Text);
|
|
359
|
+
Factory_1.Factory.overWriteSetter(Text, 'width', (0, Validators_1.getNumberOrAutoValidator)());
|
|
360
|
+
Factory_1.Factory.overWriteSetter(Text, 'height', (0, Validators_1.getNumberOrAutoValidator)());
|
|
361
|
+
Factory_1.Factory.addGetterSetter(Text, 'fontFamily', 'Arial');
|
|
362
|
+
Factory_1.Factory.addGetterSetter(Text, 'fontSize', 12, (0, Validators_1.getNumberValidator)());
|
|
363
|
+
Factory_1.Factory.addGetterSetter(Text, 'fontStyle', NORMAL);
|
|
364
|
+
Factory_1.Factory.addGetterSetter(Text, 'fontVariant', NORMAL);
|
|
365
|
+
Factory_1.Factory.addGetterSetter(Text, 'padding', 0, (0, Validators_1.getNumberValidator)());
|
|
366
|
+
Factory_1.Factory.addGetterSetter(Text, 'align', LEFT);
|
|
367
|
+
Factory_1.Factory.addGetterSetter(Text, 'verticalAlign', TOP);
|
|
368
|
+
Factory_1.Factory.addGetterSetter(Text, 'lineHeight', 1, (0, Validators_1.getNumberValidator)());
|
|
369
|
+
Factory_1.Factory.addGetterSetter(Text, 'wrap', WORD);
|
|
370
|
+
Factory_1.Factory.addGetterSetter(Text, 'ellipsis', false, (0, Validators_1.getBooleanValidator)());
|
|
371
|
+
Factory_1.Factory.addGetterSetter(Text, 'letterSpacing', 0, (0, Validators_1.getNumberValidator)());
|
|
372
|
+
Factory_1.Factory.addGetterSetter(Text, 'text', '', (0, Validators_1.getStringValidator)());
|
|
373
|
+
Factory_1.Factory.addGetterSetter(Text, 'textDecoration', '');
|
package/lib/shapes/TextPath.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Context } from '../Context.js';
|
|
2
|
+
import { Shape, ShapeConfig } from '../Shape.js';
|
|
3
|
+
import { GetSet, Vector2d } from '../types.js';
|
|
3
4
|
export interface TextPathConfig extends ShapeConfig {
|
|
4
5
|
text?: string;
|
|
5
6
|
data?: string;
|
|
@@ -20,20 +21,24 @@ export declare class TextPath extends Shape<TextPathConfig> {
|
|
|
20
21
|
p1: Vector2d;
|
|
21
22
|
}>;
|
|
22
23
|
partialText: string;
|
|
24
|
+
pathLength: number;
|
|
23
25
|
textWidth: number;
|
|
24
26
|
textHeight: number;
|
|
25
27
|
constructor(config?: TextPathConfig);
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
_getTextPathLength(): number;
|
|
29
|
+
_getPointAtLength(length: number): any;
|
|
30
|
+
_readDataAttribute(): void;
|
|
31
|
+
_sceneFunc(context: Context): void;
|
|
32
|
+
_hitFunc(context: Context): void;
|
|
28
33
|
getTextWidth(): number;
|
|
29
34
|
getTextHeight(): number;
|
|
30
|
-
setText(text:
|
|
35
|
+
setText(text: string): any;
|
|
31
36
|
_getContextFont(): any;
|
|
32
|
-
_getTextSize(text:
|
|
37
|
+
_getTextSize(text: string): {
|
|
33
38
|
width: number;
|
|
34
39
|
height: number;
|
|
35
40
|
};
|
|
36
|
-
_setTextData():
|
|
41
|
+
_setTextData(): any;
|
|
37
42
|
getSelfRect(): {
|
|
38
43
|
x: number;
|
|
39
44
|
y: number;
|
package/lib/shapes/TextPath.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TextPath = void 0;
|
|
4
|
+
const Util_1 = require("../Util");
|
|
5
|
+
const Factory_1 = require("../Factory");
|
|
6
|
+
const Shape_1 = require("../Shape");
|
|
7
|
+
const Path_1 = require("./Path");
|
|
8
|
+
const Text_1 = require("./Text");
|
|
9
|
+
const Validators_1 = require("../Validators");
|
|
10
|
+
const Global_1 = require("../Global");
|
|
8
11
|
var EMPTY_STRING = '', NORMAL = 'normal';
|
|
9
12
|
function _fillFunc(context) {
|
|
10
13
|
context.fillText(this.partialText, 0, 0);
|
|
@@ -12,19 +15,36 @@ function _fillFunc(context) {
|
|
|
12
15
|
function _strokeFunc(context) {
|
|
13
16
|
context.strokeText(this.partialText, 0, 0);
|
|
14
17
|
}
|
|
15
|
-
|
|
18
|
+
class TextPath extends Shape_1.Shape {
|
|
16
19
|
constructor(config) {
|
|
17
20
|
super(config);
|
|
18
|
-
this.dummyCanvas = Util.createCanvasElement();
|
|
21
|
+
this.dummyCanvas = Util_1.Util.createCanvasElement();
|
|
19
22
|
this.dataArray = [];
|
|
20
|
-
this.
|
|
23
|
+
this._readDataAttribute();
|
|
21
24
|
this.on('dataChange.konva', function () {
|
|
22
|
-
this.
|
|
25
|
+
this._readDataAttribute();
|
|
23
26
|
this._setTextData();
|
|
24
27
|
});
|
|
25
28
|
this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData);
|
|
26
29
|
this._setTextData();
|
|
27
30
|
}
|
|
31
|
+
_getTextPathLength() {
|
|
32
|
+
return Path_1.Path.getPathLength(this.dataArray);
|
|
33
|
+
}
|
|
34
|
+
_getPointAtLength(length) {
|
|
35
|
+
if (!this.attrs.data) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const totalLength = this.pathLength;
|
|
39
|
+
if (length - 1 > totalLength) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
return Path_1.Path.getPointAtLengthOfDataArray(length, this.dataArray);
|
|
43
|
+
}
|
|
44
|
+
_readDataAttribute() {
|
|
45
|
+
this.dataArray = Path_1.Path.parsePathData(this.attrs.data);
|
|
46
|
+
this.pathLength = this._getTextPathLength();
|
|
47
|
+
}
|
|
28
48
|
_sceneFunc(context) {
|
|
29
49
|
context.setAttr('font', this._getContextFont());
|
|
30
50
|
context.setAttr('textBaseline', this.textBaseline());
|
|
@@ -78,14 +98,14 @@ export class TextPath extends Shape {
|
|
|
78
98
|
return this.textWidth;
|
|
79
99
|
}
|
|
80
100
|
getTextHeight() {
|
|
81
|
-
Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
|
|
101
|
+
Util_1.Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
|
|
82
102
|
return this.textHeight;
|
|
83
103
|
}
|
|
84
104
|
setText(text) {
|
|
85
|
-
return Text.prototype.setText.call(this, text);
|
|
105
|
+
return Text_1.Text.prototype.setText.call(this, text);
|
|
86
106
|
}
|
|
87
107
|
_getContextFont() {
|
|
88
|
-
return Text.prototype._getContextFont.call(this);
|
|
108
|
+
return Text_1.Text.prototype._getContextFont.call(this);
|
|
89
109
|
}
|
|
90
110
|
_getTextSize(text) {
|
|
91
111
|
var dummyCanvas = this.dummyCanvas;
|
|
@@ -96,171 +116,44 @@ export class TextPath extends Shape {
|
|
|
96
116
|
_context.restore();
|
|
97
117
|
return {
|
|
98
118
|
width: metrics.width,
|
|
99
|
-
height: parseInt(this.
|
|
119
|
+
height: parseInt(`${this.fontSize()}`, 10),
|
|
100
120
|
};
|
|
101
121
|
}
|
|
102
122
|
_setTextData() {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
var align = this.align();
|
|
107
|
-
var kerningFunc = this.kerningFunc();
|
|
108
|
-
this.textWidth = size.width;
|
|
109
|
-
this.textHeight = size.height;
|
|
110
|
-
var textFullWidth = Math.max(this.textWidth + ((this.attrs.text || '').length - 1) * letterSpacing, 0);
|
|
123
|
+
const { width, height } = this._getTextSize(this.attrs.text);
|
|
124
|
+
this.textWidth = width;
|
|
125
|
+
this.textHeight = height;
|
|
111
126
|
this.glyphInfo = [];
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (that.dataArray[l].pathLength > 0) {
|
|
115
|
-
fullPathWidth += that.dataArray[l].pathLength;
|
|
116
|
-
}
|
|
127
|
+
if (!this.attrs.data) {
|
|
128
|
+
return null;
|
|
117
129
|
}
|
|
118
|
-
|
|
130
|
+
const letterSpacing = this.letterSpacing();
|
|
131
|
+
const align = this.align();
|
|
132
|
+
const kerningFunc = this.kerningFunc();
|
|
133
|
+
const textWidth = Math.max(this.textWidth + ((this.attrs.text || '').length - 1) * letterSpacing, 0);
|
|
134
|
+
let offset = 0;
|
|
119
135
|
if (align === 'center') {
|
|
120
|
-
offset = Math.max(0,
|
|
136
|
+
offset = Math.max(0, this.pathLength / 2 - textWidth / 2);
|
|
121
137
|
}
|
|
122
138
|
if (align === 'right') {
|
|
123
|
-
offset = Math.max(0,
|
|
124
|
-
}
|
|
125
|
-
var charArr = stringToArray(this.text());
|
|
126
|
-
var spacesNumber = this.text().split(' ').length - 1;
|
|
127
|
-
var p0, p1, pathCmd;
|
|
128
|
-
var pIndex = -1;
|
|
129
|
-
var currentT = 0;
|
|
130
|
-
var getNextPathSegment = function () {
|
|
131
|
-
currentT = 0;
|
|
132
|
-
var pathData = that.dataArray;
|
|
133
|
-
for (var j = pIndex + 1; j < pathData.length; j++) {
|
|
134
|
-
if (pathData[j].pathLength > 0) {
|
|
135
|
-
pIndex = j;
|
|
136
|
-
return pathData[j];
|
|
137
|
-
}
|
|
138
|
-
else if (pathData[j].command === 'M') {
|
|
139
|
-
p0 = {
|
|
140
|
-
x: pathData[j].points[0],
|
|
141
|
-
y: pathData[j].points[1],
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
return {};
|
|
146
|
-
};
|
|
147
|
-
var findSegmentToFitCharacter = function (c) {
|
|
148
|
-
var glyphWidth = that._getTextSize(c).width + letterSpacing;
|
|
149
|
-
if (c === ' ' && align === 'justify') {
|
|
150
|
-
glyphWidth += (fullPathWidth - textFullWidth) / spacesNumber;
|
|
151
|
-
}
|
|
152
|
-
var currLen = 0;
|
|
153
|
-
var attempts = 0;
|
|
154
|
-
p1 = undefined;
|
|
155
|
-
while (Math.abs(glyphWidth - currLen) / glyphWidth > 0.01 &&
|
|
156
|
-
attempts < 20) {
|
|
157
|
-
attempts++;
|
|
158
|
-
var cumulativePathLength = currLen;
|
|
159
|
-
while (pathCmd === undefined) {
|
|
160
|
-
pathCmd = getNextPathSegment();
|
|
161
|
-
if (pathCmd &&
|
|
162
|
-
cumulativePathLength + pathCmd.pathLength < glyphWidth) {
|
|
163
|
-
cumulativePathLength += pathCmd.pathLength;
|
|
164
|
-
pathCmd = undefined;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
if (Object.keys(pathCmd).length === 0 || p0 === undefined) {
|
|
168
|
-
return undefined;
|
|
169
|
-
}
|
|
170
|
-
var needNewSegment = false;
|
|
171
|
-
switch (pathCmd.command) {
|
|
172
|
-
case 'L':
|
|
173
|
-
if (Path.getLineLength(p0.x, p0.y, pathCmd.points[0], pathCmd.points[1]) > glyphWidth) {
|
|
174
|
-
p1 = Path.getPointOnLine(glyphWidth, p0.x, p0.y, pathCmd.points[0], pathCmd.points[1], p0.x, p0.y);
|
|
175
|
-
}
|
|
176
|
-
else {
|
|
177
|
-
pathCmd = undefined;
|
|
178
|
-
}
|
|
179
|
-
break;
|
|
180
|
-
case 'A':
|
|
181
|
-
var start = pathCmd.points[4];
|
|
182
|
-
var dTheta = pathCmd.points[5];
|
|
183
|
-
var end = pathCmd.points[4] + dTheta;
|
|
184
|
-
if (currentT === 0) {
|
|
185
|
-
currentT = start + 0.00000001;
|
|
186
|
-
}
|
|
187
|
-
else if (glyphWidth > currLen) {
|
|
188
|
-
currentT += ((Math.PI / 180.0) * dTheta) / Math.abs(dTheta);
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
currentT -= ((Math.PI / 360.0) * dTheta) / Math.abs(dTheta);
|
|
192
|
-
}
|
|
193
|
-
if ((dTheta < 0 && currentT < end) ||
|
|
194
|
-
(dTheta >= 0 && currentT > end)) {
|
|
195
|
-
currentT = end;
|
|
196
|
-
needNewSegment = true;
|
|
197
|
-
}
|
|
198
|
-
p1 = Path.getPointOnEllipticalArc(pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3], currentT, pathCmd.points[6]);
|
|
199
|
-
break;
|
|
200
|
-
case 'C':
|
|
201
|
-
if (currentT === 0) {
|
|
202
|
-
if (glyphWidth > pathCmd.pathLength) {
|
|
203
|
-
currentT = 0.00000001;
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
currentT = glyphWidth / pathCmd.pathLength;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
else if (glyphWidth > currLen) {
|
|
210
|
-
currentT += (glyphWidth - currLen) / pathCmd.pathLength / 2;
|
|
211
|
-
}
|
|
212
|
-
else {
|
|
213
|
-
currentT = Math.max(currentT - (currLen - glyphWidth) / pathCmd.pathLength / 2, 0);
|
|
214
|
-
}
|
|
215
|
-
if (currentT > 1.0) {
|
|
216
|
-
currentT = 1.0;
|
|
217
|
-
needNewSegment = true;
|
|
218
|
-
}
|
|
219
|
-
p1 = Path.getPointOnCubicBezier(currentT, pathCmd.start.x, pathCmd.start.y, pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3], pathCmd.points[4], pathCmd.points[5]);
|
|
220
|
-
break;
|
|
221
|
-
case 'Q':
|
|
222
|
-
if (currentT === 0) {
|
|
223
|
-
currentT = glyphWidth / pathCmd.pathLength;
|
|
224
|
-
}
|
|
225
|
-
else if (glyphWidth > currLen) {
|
|
226
|
-
currentT += (glyphWidth - currLen) / pathCmd.pathLength;
|
|
227
|
-
}
|
|
228
|
-
else {
|
|
229
|
-
currentT -= (currLen - glyphWidth) / pathCmd.pathLength;
|
|
230
|
-
}
|
|
231
|
-
if (currentT > 1.0) {
|
|
232
|
-
currentT = 1.0;
|
|
233
|
-
needNewSegment = true;
|
|
234
|
-
}
|
|
235
|
-
p1 = Path.getPointOnQuadraticBezier(currentT, pathCmd.start.x, pathCmd.start.y, pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3]);
|
|
236
|
-
break;
|
|
237
|
-
}
|
|
238
|
-
if (p1 !== undefined) {
|
|
239
|
-
currLen = Path.getLineLength(p0.x, p0.y, p1.x, p1.y);
|
|
240
|
-
}
|
|
241
|
-
if (needNewSegment) {
|
|
242
|
-
needNewSegment = false;
|
|
243
|
-
pathCmd = undefined;
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
};
|
|
247
|
-
var testChar = 'C';
|
|
248
|
-
var glyphWidth = that._getTextSize(testChar).width + letterSpacing;
|
|
249
|
-
var lettersInOffset = offset / glyphWidth - 1;
|
|
250
|
-
for (var k = 0; k < lettersInOffset; k++) {
|
|
251
|
-
findSegmentToFitCharacter(testChar);
|
|
252
|
-
if (p0 === undefined || p1 === undefined) {
|
|
253
|
-
break;
|
|
254
|
-
}
|
|
255
|
-
p0 = p1;
|
|
139
|
+
offset = Math.max(0, this.pathLength - textWidth);
|
|
256
140
|
}
|
|
141
|
+
const charArr = (0, Text_1.stringToArray)(this.text());
|
|
142
|
+
let offsetToGlyph = offset;
|
|
257
143
|
for (var i = 0; i < charArr.length; i++) {
|
|
258
|
-
|
|
259
|
-
if (
|
|
260
|
-
|
|
144
|
+
const charStartPoint = this._getPointAtLength(offsetToGlyph);
|
|
145
|
+
if (!charStartPoint)
|
|
146
|
+
return;
|
|
147
|
+
let glyphWidth = this._getTextSize(charArr[i]).width + letterSpacing;
|
|
148
|
+
if (charArr[i] === ' ' && align === 'justify') {
|
|
149
|
+
const numberOfSpaces = this.text().split(' ').length - 1;
|
|
150
|
+
glyphWidth += (this.pathLength - textWidth) / numberOfSpaces;
|
|
261
151
|
}
|
|
262
|
-
|
|
263
|
-
|
|
152
|
+
const charEndPoint = this._getPointAtLength(offsetToGlyph + glyphWidth);
|
|
153
|
+
if (!charEndPoint)
|
|
154
|
+
return;
|
|
155
|
+
const width = Path_1.Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
|
|
156
|
+
let kern = 0;
|
|
264
157
|
if (kerningFunc) {
|
|
265
158
|
try {
|
|
266
159
|
kern = kerningFunc(charArr[i - 1], charArr[i]) * this.fontSize();
|
|
@@ -269,20 +162,20 @@ export class TextPath extends Shape {
|
|
|
269
162
|
kern = 0;
|
|
270
163
|
}
|
|
271
164
|
}
|
|
272
|
-
|
|
273
|
-
|
|
165
|
+
charStartPoint.x += kern;
|
|
166
|
+
charEndPoint.x += kern;
|
|
274
167
|
this.textWidth += kern;
|
|
275
|
-
|
|
276
|
-
|
|
168
|
+
const midpoint = Path_1.Path.getPointOnLine(kern + width / 2.0, charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
|
|
169
|
+
const rotation = Math.atan2(charEndPoint.y - charStartPoint.y, charEndPoint.x - charStartPoint.x);
|
|
277
170
|
this.glyphInfo.push({
|
|
278
171
|
transposeX: midpoint.x,
|
|
279
172
|
transposeY: midpoint.y,
|
|
280
173
|
text: charArr[i],
|
|
281
174
|
rotation: rotation,
|
|
282
|
-
p0:
|
|
283
|
-
p1:
|
|
175
|
+
p0: charStartPoint,
|
|
176
|
+
p1: charEndPoint,
|
|
284
177
|
});
|
|
285
|
-
|
|
178
|
+
offsetToGlyph += glyphWidth;
|
|
286
179
|
}
|
|
287
180
|
}
|
|
288
181
|
getSelfRect() {
|
|
@@ -323,25 +216,26 @@ export class TextPath extends Shape {
|
|
|
323
216
|
};
|
|
324
217
|
}
|
|
325
218
|
destroy() {
|
|
326
|
-
Util.releaseCanvas(this.dummyCanvas);
|
|
219
|
+
Util_1.Util.releaseCanvas(this.dummyCanvas);
|
|
327
220
|
return super.destroy();
|
|
328
221
|
}
|
|
329
222
|
}
|
|
223
|
+
exports.TextPath = TextPath;
|
|
330
224
|
TextPath.prototype._fillFunc = _fillFunc;
|
|
331
225
|
TextPath.prototype._strokeFunc = _strokeFunc;
|
|
332
226
|
TextPath.prototype._fillFuncHit = _fillFunc;
|
|
333
227
|
TextPath.prototype._strokeFuncHit = _strokeFunc;
|
|
334
228
|
TextPath.prototype.className = 'TextPath';
|
|
335
229
|
TextPath.prototype._attrsAffectingSize = ['text', 'fontSize', 'data'];
|
|
336
|
-
_registerNode(TextPath);
|
|
337
|
-
Factory.addGetterSetter(TextPath, 'data');
|
|
338
|
-
Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial');
|
|
339
|
-
Factory.addGetterSetter(TextPath, 'fontSize', 12, getNumberValidator());
|
|
340
|
-
Factory.addGetterSetter(TextPath, 'fontStyle', NORMAL);
|
|
341
|
-
Factory.addGetterSetter(TextPath, 'align', 'left');
|
|
342
|
-
Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator());
|
|
343
|
-
Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
|
|
344
|
-
Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
|
|
345
|
-
Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
|
|
346
|
-
Factory.addGetterSetter(TextPath, 'textDecoration', null);
|
|
347
|
-
Factory.addGetterSetter(TextPath, 'kerningFunc', null);
|
|
230
|
+
(0, Global_1._registerNode)(TextPath);
|
|
231
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'data');
|
|
232
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial');
|
|
233
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'fontSize', 12, (0, Validators_1.getNumberValidator)());
|
|
234
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'fontStyle', NORMAL);
|
|
235
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'align', 'left');
|
|
236
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'letterSpacing', 0, (0, Validators_1.getNumberValidator)());
|
|
237
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
|
|
238
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
|
|
239
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
|
|
240
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'textDecoration', null);
|
|
241
|
+
Factory_1.Factory.addGetterSetter(TextPath, 'kerningFunc', null);
|
|
@@ -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.js';
|
|
2
|
+
import { Node } from '../Node.js';
|
|
3
|
+
import { Rect } from './Rect.js';
|
|
4
|
+
import { Group } from '../Group.js';
|
|
5
|
+
import { ContainerConfig } from '../Container.js';
|
|
6
|
+
import { GetSet, IRect, Vector2d } from '../types.js';
|
|
7
7
|
export interface Box extends IRect {
|
|
8
8
|
rotation: number;
|
|
9
9
|
}
|
|
@@ -41,13 +41,13 @@ export declare class Transformer extends Group {
|
|
|
41
41
|
cos: number;
|
|
42
42
|
_cursorChange: boolean;
|
|
43
43
|
constructor(config?: TransformerConfig);
|
|
44
|
-
attachTo(node:
|
|
45
|
-
setNode(node:
|
|
46
|
-
getNode(): Node<import("../Node").NodeConfig>;
|
|
44
|
+
attachTo(node: Node): this;
|
|
45
|
+
setNode(node: Node): this;
|
|
46
|
+
getNode(): Node<import("../Node.js").NodeConfig>;
|
|
47
47
|
_getEventNamespace(): string;
|
|
48
48
|
setNodes(nodes?: Array<Node>): this;
|
|
49
49
|
_proxyDrag(node: Node): void;
|
|
50
|
-
getNodes(): Node<import("../Node").NodeConfig>[];
|
|
50
|
+
getNodes(): Node<import("../Node.js").NodeConfig>[];
|
|
51
51
|
getActiveAnchor(): string;
|
|
52
52
|
detach(): void;
|
|
53
53
|
_resetTransformCache(): void;
|