konva 10.3.3 → 10.4.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 +1327 -1572
- package/konva.min.js +4 -4
- package/lib/Animation.d.ts +63 -3
- package/lib/Animation.js +86 -65
- package/lib/BezierFunctions.d.ts +10 -0
- package/lib/BezierFunctions.js +32 -0
- package/lib/Canvas.d.ts +53 -0
- package/lib/Canvas.js +93 -34
- package/lib/Container.d.ts +156 -9
- package/lib/Container.js +260 -25
- package/lib/Context.d.ts +247 -0
- package/lib/Context.js +312 -74
- package/lib/Core.js +1 -0
- package/lib/DragAndDrop.d.ts +1 -0
- package/lib/DragAndDrop.js +66 -17
- package/lib/Factory.d.ts +24 -1
- package/lib/Factory.js +14 -20
- package/lib/FastLayer.d.ts +14 -1
- package/lib/FastLayer.js +14 -1
- package/lib/Global.d.ts +114 -3
- package/lib/Global.js +134 -5
- package/lib/Group.d.ts +11 -0
- package/lib/Group.js +11 -0
- package/lib/Layer.d.ts +128 -3
- package/lib/Layer.js +260 -49
- package/lib/Node.d.ts +692 -30
- package/lib/Node.js +1534 -202
- package/lib/PointerEvents.d.ts +2 -1
- package/lib/PointerEvents.js +19 -1
- package/lib/Shape.d.ts +99 -14
- package/lib/Shape.js +1101 -67
- package/lib/Stage.d.ts +81 -1
- package/lib/Stage.js +166 -7
- package/lib/Tween.d.ts +159 -4
- package/lib/Tween.js +243 -24
- package/lib/Util.d.ts +147 -4
- package/lib/Util.js +332 -82
- package/lib/Validators.d.ts +0 -2
- package/lib/Validators.js +3 -25
- package/lib/_CoreInternals.d.ts +10 -6
- package/lib/_CoreInternals.js +1 -0
- package/lib/_FullInternals.d.ts +15 -6
- package/lib/_FullInternals.js +7 -0
- package/lib/canvas-backend.js +6 -0
- package/lib/filters/Blur.d.ts +18 -0
- package/lib/filters/Blur.js +97 -24
- package/lib/filters/Brighten.d.ts +21 -0
- package/lib/filters/Brighten.js +24 -0
- package/lib/filters/Brightness.d.ts +11 -0
- package/lib/filters/Brightness.js +16 -0
- package/lib/filters/Contrast.d.ts +10 -0
- package/lib/filters/Contrast.js +21 -0
- package/lib/filters/Emboss.d.ts +20 -0
- package/lib/filters/Emboss.js +68 -8
- package/lib/filters/Enhance.d.ts +14 -0
- package/lib/filters/Enhance.js +34 -0
- package/lib/filters/Grayscale.d.ts +9 -0
- package/lib/filters/Grayscale.js +12 -0
- package/lib/filters/HSL.d.ts +17 -0
- package/lib/filters/HSL.js +48 -5
- package/lib/filters/HSV.d.ts +18 -0
- package/lib/filters/HSV.js +49 -5
- package/lib/filters/Invert.d.ts +9 -0
- package/lib/filters/Invert.js +12 -0
- package/lib/filters/Kaleidoscope.d.ts +12 -0
- package/lib/filters/Kaleidoscope.js +83 -0
- package/lib/filters/Mask.d.ts +11 -0
- package/lib/filters/Mask.js +18 -0
- package/lib/filters/Noise.d.ts +19 -0
- package/lib/filters/Noise.js +19 -0
- package/lib/filters/Pixelate.d.ts +20 -0
- package/lib/filters/Pixelate.js +28 -1
- package/lib/filters/Posterize.d.ts +21 -0
- package/lib/filters/Posterize.js +22 -0
- package/lib/filters/RGB.d.ts +21 -0
- package/lib/filters/RGB.js +43 -28
- package/lib/filters/RGBA.d.ts +23 -0
- package/lib/filters/RGBA.js +28 -41
- package/lib/filters/Sepia.d.ts +9 -0
- package/lib/filters/Sepia.js +10 -0
- package/lib/filters/Solarize.d.ts +10 -0
- package/lib/filters/Solarize.js +11 -0
- package/lib/filters/Threshold.d.ts +22 -0
- package/lib/filters/Threshold.js +22 -0
- package/lib/shapes/Arc.d.ts +40 -0
- package/lib/shapes/Arc.js +89 -6
- package/lib/shapes/Arrow.d.ts +24 -1
- package/lib/shapes/Arrow.js +83 -0
- package/lib/shapes/Circle.d.ts +18 -0
- package/lib/shapes/Circle.js +36 -9
- package/lib/shapes/Ellipse.d.ts +34 -2
- package/lib/shapes/Ellipse.js +67 -9
- package/lib/shapes/Image.d.ts +49 -0
- package/lib/shapes/Image.js +151 -22
- package/lib/shapes/Label.d.ts +65 -1
- package/lib/shapes/Label.js +113 -20
- package/lib/shapes/Line.d.ts +50 -8
- package/lib/shapes/Line.js +116 -20
- package/lib/shapes/Path.d.ts +40 -6
- package/lib/shapes/Path.js +187 -128
- package/lib/shapes/Rect.d.ts +18 -0
- package/lib/shapes/Rect.js +36 -0
- package/lib/shapes/RegularPolygon.d.ts +22 -0
- package/lib/shapes/RegularPolygon.js +70 -0
- package/lib/shapes/Ring.d.ts +19 -0
- package/lib/shapes/Ring.js +51 -5
- package/lib/shapes/Sprite.d.ts +78 -0
- package/lib/shapes/Sprite.js +238 -25
- package/lib/shapes/Star.d.ts +23 -0
- package/lib/shapes/Star.js +62 -0
- package/lib/shapes/Text.d.ts +59 -1
- package/lib/shapes/Text.js +481 -97
- package/lib/shapes/TextPath.d.ts +49 -3
- package/lib/shapes/TextPath.js +278 -34
- package/lib/shapes/Transformer.d.ts +108 -11
- package/lib/shapes/Transformer.js +744 -102
- package/lib/shapes/Wedge.d.ts +22 -0
- package/lib/shapes/Wedge.js +67 -3
- package/lib/skia-backend.js +9 -0
- package/lib/types.d.ts +2 -23
- package/lib/types.js +1 -21
- package/package.json +12 -16
package/lib/shapes/TextPath.d.ts
CHANGED
|
@@ -16,10 +16,52 @@ export interface TextPathConfig extends ShapeConfig {
|
|
|
16
16
|
textDecoration?: string;
|
|
17
17
|
direction?: string;
|
|
18
18
|
kerningFunc?: (leftChar: string, rightChar: string) => number;
|
|
19
|
-
lineHeight?: number;
|
|
20
19
|
}
|
|
20
|
+
/**
|
|
21
|
+
* Path constructor.
|
|
22
|
+
* @author Jason Follas
|
|
23
|
+
* @constructor
|
|
24
|
+
* @memberof Konva
|
|
25
|
+
* @augments Konva.Shape
|
|
26
|
+
* @param {Object} config
|
|
27
|
+
* @param {String} [config.fontFamily] default is Arial
|
|
28
|
+
* @param {Number} [config.fontSize] default is 12
|
|
29
|
+
* @param {String} [config.fontStyle] Can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
|
|
30
|
+
* @param {String} [config.fontVariant] can be normal or small-caps. Default is normal
|
|
31
|
+
* @param {String} [config.textBaseline] Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'. Default is middle
|
|
32
|
+
* @param {String} config.text
|
|
33
|
+
* @param {String} config.data SVG data string
|
|
34
|
+
* @param {Function} config.kerningFunc a getter for kerning values for the specified characters
|
|
35
|
+
* @@shapeParams
|
|
36
|
+
* @@nodeParams
|
|
37
|
+
* @example
|
|
38
|
+
* var kerningPairs = {
|
|
39
|
+
* 'A': {
|
|
40
|
+
* ' ': -0.05517578125,
|
|
41
|
+
* 'T': -0.07421875,
|
|
42
|
+
* 'V': -0.07421875
|
|
43
|
+
* }
|
|
44
|
+
* 'V': {
|
|
45
|
+
* ',': -0.091796875,
|
|
46
|
+
* ":": -0.037109375,
|
|
47
|
+
* ";": -0.037109375,
|
|
48
|
+
* "A": -0.07421875
|
|
49
|
+
* }
|
|
50
|
+
* }
|
|
51
|
+
* var textpath = new Konva.TextPath({
|
|
52
|
+
* x: 100,
|
|
53
|
+
* y: 50,
|
|
54
|
+
* fill: '#333',
|
|
55
|
+
* fontSize: '24',
|
|
56
|
+
* fontFamily: 'Arial',
|
|
57
|
+
* text: 'All the world\'s a stage, and all the men and women merely players.',
|
|
58
|
+
* data: 'M10,10 C0,0 10,150 100,100 S300,150 400,50',
|
|
59
|
+
* kerningFunc(leftChar, rightChar) {
|
|
60
|
+
* return kerningPairs.hasOwnProperty(leftChar) ? pairs[leftChar][rightChar] || 0 : 0
|
|
61
|
+
* }
|
|
62
|
+
* });
|
|
63
|
+
*/
|
|
21
64
|
export declare class TextPath extends Shape<TextPathConfig> {
|
|
22
|
-
dummyCanvas: HTMLCanvasElement;
|
|
23
65
|
dataArray: PathSegment[];
|
|
24
66
|
glyphInfo: Array<{
|
|
25
67
|
transposeX: number;
|
|
@@ -43,6 +85,11 @@ export declare class TextPath extends Shape<TextPathConfig> {
|
|
|
43
85
|
_readDataAttribute(): void;
|
|
44
86
|
_sceneFunc(context: Context): void;
|
|
45
87
|
_hitFunc(context: Context): void;
|
|
88
|
+
/**
|
|
89
|
+
* get text width in pixels
|
|
90
|
+
* @method
|
|
91
|
+
* @name Konva.TextPath#getTextWidth
|
|
92
|
+
*/
|
|
46
93
|
getTextWidth(): number;
|
|
47
94
|
getTextHeight(): number;
|
|
48
95
|
setText(text: string): Text;
|
|
@@ -58,7 +105,6 @@ export declare class TextPath extends Shape<TextPathConfig> {
|
|
|
58
105
|
width: number;
|
|
59
106
|
height: number;
|
|
60
107
|
};
|
|
61
|
-
destroy(): this;
|
|
62
108
|
fontFamily: GetSet<string, this>;
|
|
63
109
|
fontSize: GetSet<number, this>;
|
|
64
110
|
fontStyle: GetSet<string, this>;
|
package/lib/shapes/TextPath.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Util } from "../Util.js";
|
|
|
2
2
|
import { Factory } from "../Factory.js";
|
|
3
3
|
import { Shape } from "../Shape.js";
|
|
4
4
|
import { Path } from "./Path.js";
|
|
5
|
-
import { Text, stringToArray } from "./Text.js";
|
|
5
|
+
import { Text, getDecorationLineWidth, getDummyContext, stringToArray, } from "./Text.js";
|
|
6
6
|
import { getNumberValidator } from "../Validators.js";
|
|
7
7
|
import { _registerNode } from "../Global.js";
|
|
8
8
|
const EMPTY_STRING = '', NORMAL = 'normal';
|
|
@@ -12,23 +12,63 @@ function _fillFunc(context) {
|
|
|
12
12
|
function _strokeFunc(context) {
|
|
13
13
|
context.strokeText(this.partialText, 0, 0);
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Path constructor.
|
|
17
|
+
* @author Jason Follas
|
|
18
|
+
* @constructor
|
|
19
|
+
* @memberof Konva
|
|
20
|
+
* @augments Konva.Shape
|
|
21
|
+
* @param {Object} config
|
|
22
|
+
* @param {String} [config.fontFamily] default is Arial
|
|
23
|
+
* @param {Number} [config.fontSize] default is 12
|
|
24
|
+
* @param {String} [config.fontStyle] Can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
|
|
25
|
+
* @param {String} [config.fontVariant] can be normal or small-caps. Default is normal
|
|
26
|
+
* @param {String} [config.textBaseline] Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'. Default is middle
|
|
27
|
+
* @param {String} config.text
|
|
28
|
+
* @param {String} config.data SVG data string
|
|
29
|
+
* @param {Function} config.kerningFunc a getter for kerning values for the specified characters
|
|
30
|
+
* @@shapeParams
|
|
31
|
+
* @@nodeParams
|
|
32
|
+
* @example
|
|
33
|
+
* var kerningPairs = {
|
|
34
|
+
* 'A': {
|
|
35
|
+
* ' ': -0.05517578125,
|
|
36
|
+
* 'T': -0.07421875,
|
|
37
|
+
* 'V': -0.07421875
|
|
38
|
+
* }
|
|
39
|
+
* 'V': {
|
|
40
|
+
* ',': -0.091796875,
|
|
41
|
+
* ":": -0.037109375,
|
|
42
|
+
* ";": -0.037109375,
|
|
43
|
+
* "A": -0.07421875
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* var textpath = new Konva.TextPath({
|
|
47
|
+
* x: 100,
|
|
48
|
+
* y: 50,
|
|
49
|
+
* fill: '#333',
|
|
50
|
+
* fontSize: '24',
|
|
51
|
+
* fontFamily: 'Arial',
|
|
52
|
+
* text: 'All the world\'s a stage, and all the men and women merely players.',
|
|
53
|
+
* data: 'M10,10 C0,0 10,150 100,100 S300,150 400,50',
|
|
54
|
+
* kerningFunc(leftChar, rightChar) {
|
|
55
|
+
* return kerningPairs.hasOwnProperty(leftChar) ? pairs[leftChar][rightChar] || 0 : 0
|
|
56
|
+
* }
|
|
57
|
+
* });
|
|
58
|
+
*/
|
|
15
59
|
export class TextPath extends Shape {
|
|
16
60
|
constructor(config) {
|
|
61
|
+
// call super constructor
|
|
17
62
|
super(config);
|
|
18
|
-
this.dummyCanvas = Util.createCanvasElement();
|
|
19
63
|
this.dataArray = [];
|
|
20
64
|
this._readDataAttribute();
|
|
21
|
-
this.on('dataChange.konva', function () {
|
|
22
|
-
this._readDataAttribute();
|
|
23
|
-
this._setTextData();
|
|
24
|
-
});
|
|
25
|
-
this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva directionChange.konva', this._setTextData);
|
|
26
65
|
this._setTextData();
|
|
27
66
|
}
|
|
28
67
|
_getTextPathLength() {
|
|
29
68
|
return Path.getPathLength(this.dataArray);
|
|
30
69
|
}
|
|
31
70
|
_getPointAtLength(length) {
|
|
71
|
+
// if path is not defined yet, do nothing
|
|
32
72
|
if (!this.attrs.data) {
|
|
33
73
|
return null;
|
|
34
74
|
}
|
|
@@ -70,10 +110,18 @@ export class TextPath extends Shape {
|
|
|
70
110
|
context.lineTo(glyphInfo[i].width, fontSize / 2 + 1);
|
|
71
111
|
}
|
|
72
112
|
context.restore();
|
|
113
|
+
//// To assist with debugging visually, uncomment following
|
|
114
|
+
//
|
|
115
|
+
// if (i % 2) context.strokeStyle = 'cyan';
|
|
116
|
+
// else context.strokeStyle = 'green';
|
|
117
|
+
// var p1 = glyphInfo[i].p1;
|
|
118
|
+
// context.moveTo(p0.x, p0.y);
|
|
119
|
+
// context.lineTo(p1.x, p1.y);
|
|
120
|
+
// context.stroke();
|
|
73
121
|
}
|
|
74
122
|
if (hasUnderline) {
|
|
75
123
|
context.strokeStyle = fill;
|
|
76
|
-
context.lineWidth = fontSize
|
|
124
|
+
context.lineWidth = getDecorationLineWidth(fontSize);
|
|
77
125
|
context.stroke();
|
|
78
126
|
}
|
|
79
127
|
if (hasLineThrough) {
|
|
@@ -90,7 +138,7 @@ export class TextPath extends Shape {
|
|
|
90
138
|
context.restore();
|
|
91
139
|
}
|
|
92
140
|
context.strokeStyle = fill;
|
|
93
|
-
context.lineWidth = fontSize
|
|
141
|
+
context.lineWidth = getDecorationLineWidth(fontSize);
|
|
94
142
|
context.stroke();
|
|
95
143
|
}
|
|
96
144
|
context.restore();
|
|
@@ -110,6 +158,11 @@ export class TextPath extends Shape {
|
|
|
110
158
|
context.setAttr('strokeStyle', this.colorKey);
|
|
111
159
|
context.stroke();
|
|
112
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* get text width in pixels
|
|
163
|
+
* @method
|
|
164
|
+
* @name Konva.TextPath#getTextWidth
|
|
165
|
+
*/
|
|
113
166
|
getTextWidth() {
|
|
114
167
|
return this.textWidth;
|
|
115
168
|
}
|
|
@@ -124,8 +177,7 @@ export class TextPath extends Shape {
|
|
|
124
177
|
return Text.prototype._getContextFont.call(this);
|
|
125
178
|
}
|
|
126
179
|
_getTextSize(text) {
|
|
127
|
-
const
|
|
128
|
-
const _context = dummyCanvas.getContext('2d');
|
|
180
|
+
const _context = getDummyContext();
|
|
129
181
|
_context.save();
|
|
130
182
|
_context.font = this._getContextFont();
|
|
131
183
|
const metrics = _context.measureText(text);
|
|
@@ -137,6 +189,12 @@ export class TextPath extends Shape {
|
|
|
137
189
|
}
|
|
138
190
|
_setTextData() {
|
|
139
191
|
const charArr = stringToArray(this.text());
|
|
192
|
+
// For RTL scripts (Hebrew, Arabic, …) the path is still walked left to
|
|
193
|
+
// right by glyph index, so we lay glyphs out in reversed logical order.
|
|
194
|
+
// A reader scanning the path right-to-left then sees the text in its
|
|
195
|
+
// intended reading order. This does not perform full Unicode bidi or
|
|
196
|
+
// Arabic cursive shaping — those need a real shaping engine — but it
|
|
197
|
+
// makes pure RTL strings render in the right direction.
|
|
140
198
|
if (this.direction() === 'rtl') {
|
|
141
199
|
charArr.reverse();
|
|
142
200
|
}
|
|
@@ -159,8 +217,14 @@ export class TextPath extends Shape {
|
|
|
159
217
|
const letterSpacing = this.letterSpacing();
|
|
160
218
|
const align = this.align();
|
|
161
219
|
const kerningFunc = this.kerningFunc();
|
|
220
|
+
// The sum of individual character widths can exceed the whole-string width
|
|
221
|
+
// due to kerning (browsers place adjacent glyphs closer together than the
|
|
222
|
+
// individual measurements suggest). This difference is the maximum amount
|
|
223
|
+
// by which the accumulated glyph offset can legitimately overshoot the
|
|
224
|
+
// path length when the path is sized to match the visually-measured text.
|
|
162
225
|
const kerningAdjustment = Math.max(0, width - fullTextWidth);
|
|
163
|
-
|
|
226
|
+
// defines the width of the text on a straight line
|
|
227
|
+
const textWidth = Math.max(this.textWidth + (charArr.length - 1) * letterSpacing, 0);
|
|
164
228
|
let offset = 0;
|
|
165
229
|
if (align === 'center') {
|
|
166
230
|
offset = Math.max(0, this.pathLength / 2 - textWidth / 2);
|
|
@@ -168,6 +232,11 @@ export class TextPath extends Shape {
|
|
|
168
232
|
if (align === 'right') {
|
|
169
233
|
offset = Math.max(0, this.pathLength - textWidth);
|
|
170
234
|
}
|
|
235
|
+
// Algorithm for calculating glyph positions:
|
|
236
|
+
// 1. Get the begging point of the glyph on the path using the offsetToGlyph,
|
|
237
|
+
// 2. Get the ending point of the glyph on the path using the offsetToGlyph plus glyph width,
|
|
238
|
+
// 3. Calculate the rotation, width, and midpoint of the glyph using the start and end points,
|
|
239
|
+
// 4. Add glyph width to the offsetToGlyph and repeat
|
|
171
240
|
let offsetToGlyph = offset;
|
|
172
241
|
for (let i = 0; i < chars.length; i++) {
|
|
173
242
|
const charStartPoint = this._getPointAtLength(offsetToGlyph);
|
|
@@ -180,6 +249,10 @@ export class TextPath extends Shape {
|
|
|
180
249
|
glyphWidth += (this.pathLength - textWidth) / numberOfSpaces;
|
|
181
250
|
}
|
|
182
251
|
const charEndLength = offsetToGlyph + glyphWidth;
|
|
252
|
+
// When the path length is sized to match the visually-measured (kerned)
|
|
253
|
+
// text width, the accumulated per-glyph offset can exceed pathLength by
|
|
254
|
+
// up to kerningAdjustment pixels. Clamp to pathLength in that case so
|
|
255
|
+
// the last character is not silently dropped.
|
|
183
256
|
const charEndPoint = this._getPointAtLength(charEndLength > this.pathLength &&
|
|
184
257
|
charEndLength - this.pathLength <= kerningAdjustment
|
|
185
258
|
? this.pathLength
|
|
@@ -189,8 +262,9 @@ export class TextPath extends Shape {
|
|
|
189
262
|
}
|
|
190
263
|
const width = Path.getLineLength(charStartPoint.x, charStartPoint.y, charEndPoint.x, charEndPoint.y);
|
|
191
264
|
let kern = 0;
|
|
192
|
-
if (kerningFunc) {
|
|
265
|
+
if (kerningFunc && i > 0) {
|
|
193
266
|
try {
|
|
267
|
+
// getKerning is a user provided getter. Make sure it never breaks our logic
|
|
194
268
|
kern = kerningFunc(chars[i - 1].char, char) * this.fontSize();
|
|
195
269
|
}
|
|
196
270
|
catch (e) {
|
|
@@ -230,31 +304,15 @@ export class TextPath extends Shape {
|
|
|
230
304
|
points.push(info.p1.x);
|
|
231
305
|
points.push(info.p1.y);
|
|
232
306
|
});
|
|
233
|
-
|
|
234
|
-
let maxX = points[0] || 0;
|
|
235
|
-
let minY = points[1] || 0;
|
|
236
|
-
let maxY = points[1] || 0;
|
|
237
|
-
let x, y;
|
|
238
|
-
for (let i = 0; i < points.length / 2; i++) {
|
|
239
|
-
x = points[i * 2];
|
|
240
|
-
y = points[i * 2 + 1];
|
|
241
|
-
minX = Math.min(minX, x);
|
|
242
|
-
maxX = Math.max(maxX, x);
|
|
243
|
-
minY = Math.min(minY, y);
|
|
244
|
-
maxY = Math.max(maxY, y);
|
|
245
|
-
}
|
|
307
|
+
const rect = Util._getPointsRect(points);
|
|
246
308
|
const fontSize = this.fontSize();
|
|
247
309
|
return {
|
|
248
|
-
x:
|
|
249
|
-
y:
|
|
250
|
-
width:
|
|
251
|
-
height:
|
|
310
|
+
x: rect.x - fontSize / 2,
|
|
311
|
+
y: rect.y - fontSize / 2,
|
|
312
|
+
width: rect.width + fontSize,
|
|
313
|
+
height: rect.height + fontSize,
|
|
252
314
|
};
|
|
253
315
|
}
|
|
254
|
-
destroy() {
|
|
255
|
-
Util.releaseCanvas(this.dummyCanvas);
|
|
256
|
-
return super.destroy();
|
|
257
|
-
}
|
|
258
316
|
}
|
|
259
317
|
TextPath.prototype._fillFunc = _fillFunc;
|
|
260
318
|
TextPath.prototype._strokeFunc = _strokeFunc;
|
|
@@ -263,15 +321,201 @@ TextPath.prototype._strokeFuncHit = _strokeFunc;
|
|
|
263
321
|
TextPath.prototype.className = 'TextPath';
|
|
264
322
|
TextPath.prototype._attrsAffectingSize = ['text', 'fontSize', 'data'];
|
|
265
323
|
_registerNode(TextPath);
|
|
324
|
+
TextPath.prototype.on('dataChange.konva', function () {
|
|
325
|
+
this._readDataAttribute();
|
|
326
|
+
this._setTextData();
|
|
327
|
+
});
|
|
328
|
+
// update text data for certain attr changes
|
|
329
|
+
TextPath.prototype.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva fontStyleChange.konva fontVariantChange.konva directionChange.konva', function () {
|
|
330
|
+
this._setTextData();
|
|
331
|
+
});
|
|
332
|
+
/**
|
|
333
|
+
* get/set SVG path data string. This method
|
|
334
|
+
* also automatically parses the data string
|
|
335
|
+
* into a data array. Currently supported SVG data:
|
|
336
|
+
* M, m, L, l, H, h, V, v, Q, q, T, t, C, c, S, s, A, a, Z, z
|
|
337
|
+
* @name Konva.TextPath#data
|
|
338
|
+
* @method
|
|
339
|
+
* @param {String} data svg path string
|
|
340
|
+
* @returns {String}
|
|
341
|
+
* @example
|
|
342
|
+
* // get data
|
|
343
|
+
* var data = shape.data();
|
|
344
|
+
*
|
|
345
|
+
* // set data
|
|
346
|
+
* shape.data('M200,100h100v50z');
|
|
347
|
+
*/
|
|
266
348
|
Factory.addGetterSetter(TextPath, 'data');
|
|
349
|
+
/**
|
|
350
|
+
* get/set font family
|
|
351
|
+
* @name Konva.TextPath#fontFamily
|
|
352
|
+
* @method
|
|
353
|
+
* @param {String} fontFamily
|
|
354
|
+
* @returns {String}
|
|
355
|
+
* @example
|
|
356
|
+
* // get font family
|
|
357
|
+
* var fontFamily = shape.fontFamily();
|
|
358
|
+
*
|
|
359
|
+
* // set font family
|
|
360
|
+
* shape.fontFamily('Arial');
|
|
361
|
+
*/
|
|
267
362
|
Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial');
|
|
363
|
+
/**
|
|
364
|
+
* get/set font size in pixels
|
|
365
|
+
* @name Konva.TextPath#fontSize
|
|
366
|
+
* @method
|
|
367
|
+
* @param {Number} fontSize
|
|
368
|
+
* @returns {Number}
|
|
369
|
+
* @example
|
|
370
|
+
* // get font size
|
|
371
|
+
* var fontSize = shape.fontSize();
|
|
372
|
+
*
|
|
373
|
+
* // set font size to 22px
|
|
374
|
+
* shape.fontSize(22);
|
|
375
|
+
*/
|
|
268
376
|
Factory.addGetterSetter(TextPath, 'fontSize', 12, getNumberValidator());
|
|
377
|
+
/**
|
|
378
|
+
* get/set font style. Can be 'normal', 'italic', or 'bold', '500' or even 'italic bold'. 'normal' is the default.
|
|
379
|
+
* @name Konva.TextPath#fontStyle
|
|
380
|
+
* @method
|
|
381
|
+
* @param {String} fontStyle
|
|
382
|
+
* @returns {String}
|
|
383
|
+
* @example
|
|
384
|
+
* // get font style
|
|
385
|
+
* var fontStyle = shape.fontStyle();
|
|
386
|
+
*
|
|
387
|
+
* // set font style
|
|
388
|
+
* shape.fontStyle('bold');
|
|
389
|
+
*/
|
|
269
390
|
Factory.addGetterSetter(TextPath, 'fontStyle', NORMAL);
|
|
391
|
+
/**
|
|
392
|
+
* get/set horizontal align of text. Can be 'left', 'center', 'right' or 'justify'
|
|
393
|
+
* @name Konva.TextPath#align
|
|
394
|
+
* @method
|
|
395
|
+
* @param {String} align
|
|
396
|
+
* @returns {String}
|
|
397
|
+
* @example
|
|
398
|
+
* // get text align
|
|
399
|
+
* var align = text.align();
|
|
400
|
+
*
|
|
401
|
+
* // center text
|
|
402
|
+
* text.align('center');
|
|
403
|
+
*
|
|
404
|
+
* // align text to right
|
|
405
|
+
* text.align('right');
|
|
406
|
+
*/
|
|
270
407
|
Factory.addGetterSetter(TextPath, 'align', 'left');
|
|
408
|
+
/**
|
|
409
|
+
* get/set letter spacing. The default is 0.
|
|
410
|
+
* @name Konva.TextPath#letterSpacing
|
|
411
|
+
* @method
|
|
412
|
+
* @param {Number} letterSpacing
|
|
413
|
+
* @returns {Number}
|
|
414
|
+
* @example
|
|
415
|
+
* // get letter spacing value
|
|
416
|
+
* var letterSpacing = shape.letterSpacing();
|
|
417
|
+
*
|
|
418
|
+
* // set the letter spacing value
|
|
419
|
+
* shape.letterSpacing(2);
|
|
420
|
+
*/
|
|
271
421
|
Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator());
|
|
422
|
+
/**
|
|
423
|
+
* get/set text baseline. The default is 'middle'. Can be 'top', 'bottom', 'middle', 'alphabetic', 'hanging'
|
|
424
|
+
* @name Konva.TextPath#textBaseline
|
|
425
|
+
* @method
|
|
426
|
+
* @param {String} textBaseline
|
|
427
|
+
* @returns {String}
|
|
428
|
+
* @example
|
|
429
|
+
* // get current text baseline
|
|
430
|
+
* var textBaseline = shape.textBaseline();
|
|
431
|
+
*
|
|
432
|
+
* // set new text baseline
|
|
433
|
+
* shape.textBaseline('top');
|
|
434
|
+
*/
|
|
272
435
|
Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
|
|
436
|
+
/**
|
|
437
|
+
* get/set font variant. Can be 'normal' or 'small-caps'. 'normal' is the default.
|
|
438
|
+
* @name Konva.TextPath#fontVariant
|
|
439
|
+
* @method
|
|
440
|
+
* @param {String} fontVariant
|
|
441
|
+
* @returns {String}
|
|
442
|
+
* @example
|
|
443
|
+
* // get font variant
|
|
444
|
+
* var fontVariant = shape.fontVariant();
|
|
445
|
+
*
|
|
446
|
+
* // set font variant
|
|
447
|
+
* shape.fontVariant('small-caps');
|
|
448
|
+
*/
|
|
273
449
|
Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
|
|
450
|
+
/**
|
|
451
|
+
* get/set text
|
|
452
|
+
* @name Konva.TextPath#getText
|
|
453
|
+
* @method
|
|
454
|
+
* @param {String} text
|
|
455
|
+
* @returns {String}
|
|
456
|
+
* @example
|
|
457
|
+
* // get text
|
|
458
|
+
* var text = text.text();
|
|
459
|
+
*
|
|
460
|
+
* // set text
|
|
461
|
+
* text.text('Hello world!');
|
|
462
|
+
*/
|
|
274
463
|
Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
|
|
464
|
+
/**
|
|
465
|
+
* get/set text decoration of a text. Can be '', 'underline', 'line-through', or a combination like 'underline line-through'.
|
|
466
|
+
* @name Konva.TextPath#textDecoration
|
|
467
|
+
* @method
|
|
468
|
+
* @param {String} textDecoration
|
|
469
|
+
* @returns {String}
|
|
470
|
+
* @example
|
|
471
|
+
* // get text decoration
|
|
472
|
+
* var textDecoration = shape.textDecoration();
|
|
473
|
+
*
|
|
474
|
+
* // underline text
|
|
475
|
+
* shape.textDecoration('underline');
|
|
476
|
+
*
|
|
477
|
+
* // line-through text
|
|
478
|
+
* shape.textDecoration('line-through');
|
|
479
|
+
*
|
|
480
|
+
* // combine both
|
|
481
|
+
* shape.textDecoration('underline line-through');
|
|
482
|
+
*/
|
|
275
483
|
Factory.addGetterSetter(TextPath, 'textDecoration', '');
|
|
484
|
+
/**
|
|
485
|
+
* get/set kerning function.
|
|
486
|
+
* @name Konva.TextPath#kerningFunc
|
|
487
|
+
* @method
|
|
488
|
+
* @param {String} kerningFunc
|
|
489
|
+
* @returns {String}
|
|
490
|
+
* @example
|
|
491
|
+
* // get text decoration
|
|
492
|
+
* var kerningFunc = text.kerningFunc();
|
|
493
|
+
*
|
|
494
|
+
* // center text
|
|
495
|
+
* text.kerningFunc(function(leftChar, rightChar) {
|
|
496
|
+
* return 1;
|
|
497
|
+
* });
|
|
498
|
+
*/
|
|
276
499
|
Factory.addGetterSetter(TextPath, 'kerningFunc', undefined);
|
|
500
|
+
/**
|
|
501
|
+
* get/set text direction. Can be 'inherit', 'ltr' or 'rtl'. Default is 'inherit'.
|
|
502
|
+
*
|
|
503
|
+
* Setting `'rtl'` reverses the per-glyph layout order along the path, so
|
|
504
|
+
* Hebrew/Arabic strings read correctly when scanned right-to-left. This is a
|
|
505
|
+
* pragmatic fix limited by canvas TextPath rendering: each glyph is still
|
|
506
|
+
* drawn independently, so Arabic cursive joining and full Unicode bidi
|
|
507
|
+
* reordering of mixed-direction text are not supported. For best results,
|
|
508
|
+
* pair `direction: 'rtl'` with `align: 'right'` so the text starts at the
|
|
509
|
+
* end of the path.
|
|
510
|
+
* @name Konva.TextPath#direction
|
|
511
|
+
* @method
|
|
512
|
+
* @param {String} direction
|
|
513
|
+
* @returns {String}
|
|
514
|
+
* @example
|
|
515
|
+
* // get direction
|
|
516
|
+
* var direction = textpath.direction();
|
|
517
|
+
*
|
|
518
|
+
* // set direction
|
|
519
|
+
* textpath.direction('rtl');
|
|
520
|
+
*/
|
|
277
521
|
Factory.addGetterSetter(TextPath, 'direction', 'inherit');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Transform } from '../Util.ts';
|
|
2
2
|
import { Node } from '../Node.ts';
|
|
3
|
+
import { Shape } from '../Shape.ts';
|
|
3
4
|
import { Rect } from './Rect.ts';
|
|
4
5
|
import { Group } from '../Group.ts';
|
|
5
6
|
import type { ContainerConfig } from '../Container.ts';
|
|
@@ -38,10 +39,58 @@ export interface TransformerConfig extends ContainerConfig {
|
|
|
38
39
|
anchorDragBoundFunc?: (oldPos: Vector2d, newPos: Vector2d, evt: any) => Vector2d;
|
|
39
40
|
anchorStyleFunc?: (anchor: Rect) => void;
|
|
40
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Transformer constructor. Transformer is a special type of group that allow you transform Konva
|
|
44
|
+
* primitives and shapes. Transforming tool is not changing `width` and `height` properties of nodes
|
|
45
|
+
* when you resize them. Instead it changes `scaleX` and `scaleY` properties.
|
|
46
|
+
* @constructor
|
|
47
|
+
* @memberof Konva
|
|
48
|
+
* @param {Object} config
|
|
49
|
+
* @param {Boolean} [config.resizeEnabled] Default is true
|
|
50
|
+
* @param {Boolean} [config.rotateEnabled] Default is true
|
|
51
|
+
* @param {Boolean} [config.rotateLineVisible] Default is true
|
|
52
|
+
* @param {Array} [config.rotationSnaps] Array of angles for rotation snaps. Default is []
|
|
53
|
+
* @param {Number} [config.rotationSnapTolerance] Snapping tolerance. If closer than this it will snap. Default is 5
|
|
54
|
+
* @param {Number} [config.rotateAnchorOffset] Default is 50
|
|
55
|
+
* @param {Number} [config.rotateAnchorAngle] Angle of the rotate anchor around the box, in degrees. Default is 0 (top)
|
|
56
|
+
* @param {String} [config.rotateAnchorCursor] Default is crosshair
|
|
57
|
+
* @param {Number} [config.padding] Default is 0
|
|
58
|
+
* @param {Boolean} [config.borderEnabled] Should we draw border? Default is true
|
|
59
|
+
* @param {String} [config.borderStroke] Border stroke color
|
|
60
|
+
* @param {Number} [config.borderStrokeWidth] Border stroke size
|
|
61
|
+
* @param {Array} [config.borderDash] Array for border dash.
|
|
62
|
+
* @param {String} [config.anchorFill] Anchor fill color
|
|
63
|
+
* @param {String} [config.anchorStroke] Anchor stroke color
|
|
64
|
+
* @param {Number} [config.anchorCornerRadius] Anchor corner radius
|
|
65
|
+
* @param {Number} [config.anchorStrokeWidth] Anchor stroke size
|
|
66
|
+
* @param {Number} [config.anchorSize] Default is 10
|
|
67
|
+
* @param {Boolean} [config.keepRatio] Should we keep ratio when we are moving edges? Default is true
|
|
68
|
+
* @param {String} [config.shiftBehavior] How does transformer react on shift key press when we are moving edges? Default is 'default'
|
|
69
|
+
* @param {Boolean} [config.centeredScaling] Should we resize relative to node's center? Default is false
|
|
70
|
+
* @param {Array} [config.enabledAnchors] Array of names of enabled handles
|
|
71
|
+
* @param {Boolean} [config.flipEnabled] Can we flip/mirror shape on transform?. True by default
|
|
72
|
+
* @param {Function} [config.boundBoxFunc] Bounding box function, see {@link Konva.Transformer#boundBoxFunc}
|
|
73
|
+
* @param {Function} [config.anchorDragBoundFunc] Function bounding the position of a dragged anchor, see {@link Konva.Transformer#anchorDragBoundFunc}
|
|
74
|
+
* @param {Function} [config.anchorStyleFunc] Function styling every anchor, see {@link Konva.Transformer#anchorStyleFunc}
|
|
75
|
+
* @param {Boolean} [config.ignoreStroke] Should we ignore stroke size? Default is false
|
|
76
|
+
* @param {Boolean} [config.useSingleNodeRotation] When just one node attached, should we use its rotation for transformer?
|
|
77
|
+
* @param {Boolean} [config.shouldOverdrawWholeArea] Should we fill whole transformer area with fake transparent shape to enable dragging from empty spaces?
|
|
78
|
+
* @example
|
|
79
|
+
* var transformer = new Konva.Transformer({
|
|
80
|
+
* nodes: [rectangle],
|
|
81
|
+
* rotateAnchorOffset: 60,
|
|
82
|
+
* enabledAnchors: ['top-left', 'top-right', 'bottom-left', 'bottom-right']
|
|
83
|
+
* });
|
|
84
|
+
* layer.add(transformer);
|
|
85
|
+
*/
|
|
41
86
|
export declare class Transformer extends Group {
|
|
42
87
|
_nodes: Array<Node>;
|
|
43
88
|
_movingAnchorName: string | null;
|
|
89
|
+
_pointerId?: number;
|
|
90
|
+
_anchors: Record<string, Rect>;
|
|
91
|
+
_back: Shape;
|
|
44
92
|
_transforming: boolean;
|
|
93
|
+
_fitting: boolean;
|
|
45
94
|
_transformWindow: Window | null;
|
|
46
95
|
_anchorDragOffset: Vector2d;
|
|
47
96
|
sin: number;
|
|
@@ -50,7 +99,16 @@ export declare class Transformer extends Group {
|
|
|
50
99
|
_elementsCreated: boolean;
|
|
51
100
|
_updateScheduled: boolean;
|
|
52
101
|
static isTransforming: () => boolean;
|
|
102
|
+
static _isLayerTransforming(layer: Node): boolean;
|
|
53
103
|
constructor(config?: TransformerConfig);
|
|
104
|
+
/**
|
|
105
|
+
* alias to `tr.nodes([shape])`/ This method is deprecated and will be removed soon.
|
|
106
|
+
* @method
|
|
107
|
+
* @name Konva.Transformer#attachTo
|
|
108
|
+
* @returns {Konva.Transformer}
|
|
109
|
+
* @example
|
|
110
|
+
* transformer.attachTo(shape);
|
|
111
|
+
*/
|
|
54
112
|
attachTo(node: Node): this;
|
|
55
113
|
setNode(node: Node): this;
|
|
56
114
|
getNode(): Node<import("../Node.ts").NodeConfig>;
|
|
@@ -58,17 +116,39 @@ export declare class Transformer extends Group {
|
|
|
58
116
|
setNodes(nodes?: Array<Node>): this;
|
|
59
117
|
_proxyDrag(node: Node): void;
|
|
60
118
|
getNodes(): Node<import("../Node.ts").NodeConfig>[];
|
|
119
|
+
/**
|
|
120
|
+
* return the name of current active anchor
|
|
121
|
+
* @method
|
|
122
|
+
* @name Konva.Transformer#getActiveAnchor
|
|
123
|
+
* @returns {String | Null}
|
|
124
|
+
* @example
|
|
125
|
+
* transformer.getActiveAnchor();
|
|
126
|
+
*/
|
|
61
127
|
getActiveAnchor(): string | null;
|
|
128
|
+
/**
|
|
129
|
+
* detach transformer from an attached node
|
|
130
|
+
* @method
|
|
131
|
+
* @name Konva.Transformer#detach
|
|
132
|
+
* @returns {Konva.Transformer}
|
|
133
|
+
* @example
|
|
134
|
+
* transformer.detach();
|
|
135
|
+
*/
|
|
62
136
|
detach(): void;
|
|
137
|
+
/**
|
|
138
|
+
* bind events to the Transformer. You can use events: `transform`, `transformstart`, `transformend`, `dragstart`, `dragmove`, `dragend`
|
|
139
|
+
* @method
|
|
140
|
+
* @name Konva.Transformer#on
|
|
141
|
+
* @param {String} evtStr e.g. 'transform'
|
|
142
|
+
* @param {Function} handler The handler function. The first argument of that function is event object. Event object has `target` as main target of the event, `currentTarget` as current node listener and `evt` as native browser event.
|
|
143
|
+
* @returns {Konva.Transformer}
|
|
144
|
+
* @example
|
|
145
|
+
* // add click listener
|
|
146
|
+
* tr.on('transformstart', function() {
|
|
147
|
+
* console.log('transform started');
|
|
148
|
+
* });
|
|
149
|
+
*/
|
|
63
150
|
_resetTransformCache(): void;
|
|
64
151
|
_getNodeRect(): any;
|
|
65
|
-
__getNodeShape(node: Node, rot?: number, relative?: Node): {
|
|
66
|
-
rotation: number;
|
|
67
|
-
x: number;
|
|
68
|
-
y: number;
|
|
69
|
-
width: number;
|
|
70
|
-
height: number;
|
|
71
|
-
};
|
|
72
152
|
__getNodeRect(): {
|
|
73
153
|
x: number;
|
|
74
154
|
y: number;
|
|
@@ -86,15 +166,32 @@ export declare class Transformer extends Group {
|
|
|
86
166
|
_handleMouseDown(e: any): void;
|
|
87
167
|
_handleMouseMove(e: any): void;
|
|
88
168
|
_handleMouseUp(e: any): void;
|
|
89
|
-
getAbsoluteTransform(): Transform;
|
|
169
|
+
getAbsoluteTransform(top?: Node | null): Transform;
|
|
90
170
|
_removeEvents(e?: any): void;
|
|
91
171
|
_fitNodesInto(newAttrs: any, evt?: any, anchorProjected?: boolean): void;
|
|
92
172
|
_doFitNodesInto(newAttrs: any, evt?: any, anchorProjected?: boolean): void;
|
|
93
173
|
_scheduleUpdate(): void;
|
|
174
|
+
/**
|
|
175
|
+
* force update of Konva.Transformer.
|
|
176
|
+
* Use it when you updated attached Konva.Group and now you need to reset transformer size
|
|
177
|
+
* @method
|
|
178
|
+
* @name Konva.Transformer#forceUpdate
|
|
179
|
+
*/
|
|
94
180
|
forceUpdate(): void;
|
|
95
|
-
_batchChangeChild(selector: string, attrs: any): void;
|
|
96
181
|
update(): void;
|
|
182
|
+
/**
|
|
183
|
+
* determine if transformer is in active transform
|
|
184
|
+
* @method
|
|
185
|
+
* @name Konva.Transformer#isTransforming
|
|
186
|
+
* @returns {Boolean}
|
|
187
|
+
*/
|
|
97
188
|
isTransforming(): boolean;
|
|
189
|
+
/**
|
|
190
|
+
* Stop active transform action
|
|
191
|
+
* @method
|
|
192
|
+
* @name Konva.Transformer#stopTransform
|
|
193
|
+
* @returns {Boolean}
|
|
194
|
+
*/
|
|
98
195
|
stopTransform(): void;
|
|
99
196
|
destroy(): this;
|
|
100
197
|
add(...children: any[]): this;
|
|
@@ -104,7 +201,7 @@ export declare class Transformer extends Group {
|
|
|
104
201
|
children?: Array<any>;
|
|
105
202
|
};
|
|
106
203
|
clone(obj?: any): this;
|
|
107
|
-
getClientRect(): IRect;
|
|
204
|
+
getClientRect(config?: Parameters<Group['getClientRect']>[0]): IRect;
|
|
108
205
|
nodes: GetSet<Node[], this>;
|
|
109
206
|
enabledAnchors: GetSet<string[], this>;
|
|
110
207
|
rotationSnaps: GetSet<number[], this>;
|
|
@@ -131,7 +228,7 @@ export declare class Transformer extends Group {
|
|
|
131
228
|
flipEnabled: GetSet<boolean, this>;
|
|
132
229
|
ignoreStroke: GetSet<boolean, this>;
|
|
133
230
|
boundBoxFunc: GetSet<(oldBox: Box, newBox: Box) => Box, this>;
|
|
134
|
-
anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d,
|
|
231
|
+
anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d, evt: any) => Vector2d, this>;
|
|
135
232
|
anchorStyleFunc: GetSet<null | ((Node: Rect) => void), this>;
|
|
136
233
|
shouldOverdrawWholeArea: GetSet<boolean, this>;
|
|
137
234
|
useSingleNodeRotation: GetSet<boolean, this>;
|