konva 8.4.3 → 9.0.1
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 +17691 -16989
- package/konva.min.js +3 -3
- package/lib/Animation.js +11 -7
- package/lib/BezierFunctions.d.ts +6 -0
- package/lib/BezierFunctions.js +791 -0
- package/lib/Canvas.d.ts +1 -0
- package/lib/Canvas.js +26 -18
- package/lib/Container.js +16 -12
- package/lib/Context.d.ts +3 -1
- package/lib/Context.js +18 -10
- package/lib/Core.js +7 -3
- package/lib/DragAndDrop.js +25 -22
- package/lib/Factory.js +27 -24
- package/lib/FastLayer.js +10 -6
- package/lib/Global.js +16 -12
- package/lib/Group.js +10 -6
- package/lib/Layer.js +37 -33
- package/lib/Node.d.ts +1 -0
- package/lib/Node.js +105 -104
- package/lib/PointerEvents.js +15 -7
- package/lib/Shape.js +90 -86
- package/lib/Stage.js +51 -47
- package/lib/Tween.js +26 -22
- package/lib/Util.js +29 -25
- package/lib/Validators.js +58 -44
- package/lib/_CoreInternals.js +36 -33
- package/lib/_FullInternals.js +78 -75
- package/lib/filters/Blur.js +9 -5
- package/lib/filters/Brighten.js +9 -5
- package/lib/filters/Contrast.js +9 -5
- package/lib/filters/Emboss.js +14 -10
- package/lib/filters/Enhance.js +9 -5
- package/lib/filters/Grayscale.js +5 -1
- package/lib/filters/HSL.js +11 -7
- package/lib/filters/HSV.js +11 -7
- package/lib/filters/Invert.js +5 -1
- package/lib/filters/Kaleidoscope.js +13 -9
- package/lib/filters/Mask.js +9 -5
- package/lib/filters/Noise.js +9 -5
- package/lib/filters/Pixelate.js +11 -7
- package/lib/filters/Posterize.js +9 -5
- package/lib/filters/RGB.js +11 -7
- package/lib/filters/RGBA.js +12 -8
- package/lib/filters/Sepia.js +5 -1
- package/lib/filters/Solarize.js +5 -1
- package/lib/filters/Threshold.js +9 -5
- package/lib/index-node.js +7 -5
- package/lib/index.js +4 -2
- package/lib/shapes/Arc.js +17 -13
- package/lib/shapes/Arrow.js +17 -13
- package/lib/shapes/Circle.js +11 -7
- package/lib/shapes/Ellipse.js +13 -9
- package/lib/shapes/Image.js +21 -17
- package/lib/shapes/Label.js +18 -13
- package/lib/shapes/Line.js +14 -10
- package/lib/shapes/Path.d.ts +5 -2
- package/lib/shapes/Path.js +44 -43
- package/lib/shapes/Rect.js +13 -9
- package/lib/shapes/RegularPolygon.js +12 -8
- package/lib/shapes/Ring.js +12 -8
- package/lib/shapes/Sprite.js +19 -15
- package/lib/shapes/Star.js +13 -9
- package/lib/shapes/Text.js +31 -26
- package/lib/shapes/TextPath.d.ts +5 -1
- package/lib/shapes/TextPath.js +82 -188
- package/lib/shapes/Transformer.d.ts +2 -0
- package/lib/shapes/Transformer.js +97 -82
- 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 -85
- 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 -186
- 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 -26
- package/cmj/shapes/Arc.js +0 -59
- package/cmj/shapes/Arrow.d.ts +0 -26
- package/cmj/shapes/Arrow.js +0 -103
- package/cmj/shapes/Circle.d.ts +0 -14
- package/cmj/shapes/Circle.js +0 -37
- package/cmj/shapes/Ellipse.d.ts +0 -17
- 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 -36
- 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 -23
- package/cmj/shapes/RegularPolygon.js +0 -69
- package/cmj/shapes/Ring.d.ts +0 -16
- package/cmj/shapes/Ring.js +0 -37
- package/cmj/shapes/Sprite.d.ts +0 -31
- package/cmj/shapes/Sprite.js +0 -112
- package/cmj/shapes/Star.d.ts +0 -18
- package/cmj/shapes/Star.js +0 -42
- package/cmj/shapes/Text.d.ts +0 -63
- package/cmj/shapes/Text.js +0 -373
- package/cmj/shapes/TextPath.d.ts +0 -56
- package/cmj/shapes/TextPath.js +0 -351
- package/cmj/shapes/Transformer.d.ts +0 -116
- package/cmj/shapes/Transformer.js +0 -971
- package/cmj/shapes/Wedge.d.ts +0 -18
- package/cmj/shapes/Wedge.js +0 -42
- package/cmj/types.d.ts +0 -50
- package/cmj/types.js +0 -25
package/cmj/shapes/TextPath.js
DELETED
|
@@ -1,351 +0,0 @@
|
|
|
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");
|
|
11
|
-
var EMPTY_STRING = '', NORMAL = 'normal';
|
|
12
|
-
function _fillFunc(context) {
|
|
13
|
-
context.fillText(this.partialText, 0, 0);
|
|
14
|
-
}
|
|
15
|
-
function _strokeFunc(context) {
|
|
16
|
-
context.strokeText(this.partialText, 0, 0);
|
|
17
|
-
}
|
|
18
|
-
class TextPath extends Shape_1.Shape {
|
|
19
|
-
constructor(config) {
|
|
20
|
-
super(config);
|
|
21
|
-
this.dummyCanvas = Util_1.Util.createCanvasElement();
|
|
22
|
-
this.dataArray = [];
|
|
23
|
-
this.dataArray = Path_1.Path.parsePathData(this.attrs.data);
|
|
24
|
-
this.on('dataChange.konva', function () {
|
|
25
|
-
this.dataArray = Path_1.Path.parsePathData(this.attrs.data);
|
|
26
|
-
this._setTextData();
|
|
27
|
-
});
|
|
28
|
-
this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData);
|
|
29
|
-
this._setTextData();
|
|
30
|
-
}
|
|
31
|
-
_sceneFunc(context) {
|
|
32
|
-
context.setAttr('font', this._getContextFont());
|
|
33
|
-
context.setAttr('textBaseline', this.textBaseline());
|
|
34
|
-
context.setAttr('textAlign', 'left');
|
|
35
|
-
context.save();
|
|
36
|
-
var textDecoration = this.textDecoration();
|
|
37
|
-
var fill = this.fill();
|
|
38
|
-
var fontSize = this.fontSize();
|
|
39
|
-
var glyphInfo = this.glyphInfo;
|
|
40
|
-
if (textDecoration === 'underline') {
|
|
41
|
-
context.beginPath();
|
|
42
|
-
}
|
|
43
|
-
for (var i = 0; i < glyphInfo.length; i++) {
|
|
44
|
-
context.save();
|
|
45
|
-
var p0 = glyphInfo[i].p0;
|
|
46
|
-
context.translate(p0.x, p0.y);
|
|
47
|
-
context.rotate(glyphInfo[i].rotation);
|
|
48
|
-
this.partialText = glyphInfo[i].text;
|
|
49
|
-
context.fillStrokeShape(this);
|
|
50
|
-
if (textDecoration === 'underline') {
|
|
51
|
-
if (i === 0) {
|
|
52
|
-
context.moveTo(0, fontSize / 2 + 1);
|
|
53
|
-
}
|
|
54
|
-
context.lineTo(fontSize, fontSize / 2 + 1);
|
|
55
|
-
}
|
|
56
|
-
context.restore();
|
|
57
|
-
}
|
|
58
|
-
if (textDecoration === 'underline') {
|
|
59
|
-
context.strokeStyle = fill;
|
|
60
|
-
context.lineWidth = fontSize / 20;
|
|
61
|
-
context.stroke();
|
|
62
|
-
}
|
|
63
|
-
context.restore();
|
|
64
|
-
}
|
|
65
|
-
_hitFunc(context) {
|
|
66
|
-
context.beginPath();
|
|
67
|
-
var glyphInfo = this.glyphInfo;
|
|
68
|
-
if (glyphInfo.length >= 1) {
|
|
69
|
-
var p0 = glyphInfo[0].p0;
|
|
70
|
-
context.moveTo(p0.x, p0.y);
|
|
71
|
-
}
|
|
72
|
-
for (var i = 0; i < glyphInfo.length; i++) {
|
|
73
|
-
var p1 = glyphInfo[i].p1;
|
|
74
|
-
context.lineTo(p1.x, p1.y);
|
|
75
|
-
}
|
|
76
|
-
context.setAttr('lineWidth', this.fontSize());
|
|
77
|
-
context.setAttr('strokeStyle', this.colorKey);
|
|
78
|
-
context.stroke();
|
|
79
|
-
}
|
|
80
|
-
getTextWidth() {
|
|
81
|
-
return this.textWidth;
|
|
82
|
-
}
|
|
83
|
-
getTextHeight() {
|
|
84
|
-
Util_1.Util.warn('text.getTextHeight() method is deprecated. Use text.height() - for full height and text.fontSize() - for one line height.');
|
|
85
|
-
return this.textHeight;
|
|
86
|
-
}
|
|
87
|
-
setText(text) {
|
|
88
|
-
return Text_1.Text.prototype.setText.call(this, text);
|
|
89
|
-
}
|
|
90
|
-
_getContextFont() {
|
|
91
|
-
return Text_1.Text.prototype._getContextFont.call(this);
|
|
92
|
-
}
|
|
93
|
-
_getTextSize(text) {
|
|
94
|
-
var dummyCanvas = this.dummyCanvas;
|
|
95
|
-
var _context = dummyCanvas.getContext('2d');
|
|
96
|
-
_context.save();
|
|
97
|
-
_context.font = this._getContextFont();
|
|
98
|
-
var metrics = _context.measureText(text);
|
|
99
|
-
_context.restore();
|
|
100
|
-
return {
|
|
101
|
-
width: metrics.width,
|
|
102
|
-
height: parseInt(this.attrs.fontSize, 10),
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
_setTextData() {
|
|
106
|
-
var that = this;
|
|
107
|
-
var size = this._getTextSize(this.attrs.text);
|
|
108
|
-
var letterSpacing = this.letterSpacing();
|
|
109
|
-
var align = this.align();
|
|
110
|
-
var kerningFunc = this.kerningFunc();
|
|
111
|
-
this.textWidth = size.width;
|
|
112
|
-
this.textHeight = size.height;
|
|
113
|
-
var textFullWidth = Math.max(this.textWidth + ((this.attrs.text || '').length - 1) * letterSpacing, 0);
|
|
114
|
-
this.glyphInfo = [];
|
|
115
|
-
var fullPathWidth = 0;
|
|
116
|
-
for (var l = 0; l < that.dataArray.length; l++) {
|
|
117
|
-
if (that.dataArray[l].pathLength > 0) {
|
|
118
|
-
fullPathWidth += that.dataArray[l].pathLength;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
var offset = 0;
|
|
122
|
-
if (align === 'center') {
|
|
123
|
-
offset = Math.max(0, fullPathWidth / 2 - textFullWidth / 2);
|
|
124
|
-
}
|
|
125
|
-
if (align === 'right') {
|
|
126
|
-
offset = Math.max(0, fullPathWidth - textFullWidth);
|
|
127
|
-
}
|
|
128
|
-
var charArr = (0, Text_1.stringToArray)(this.text());
|
|
129
|
-
var spacesNumber = this.text().split(' ').length - 1;
|
|
130
|
-
var p0, p1, pathCmd;
|
|
131
|
-
var pIndex = -1;
|
|
132
|
-
var currentT = 0;
|
|
133
|
-
var getNextPathSegment = function () {
|
|
134
|
-
currentT = 0;
|
|
135
|
-
var pathData = that.dataArray;
|
|
136
|
-
for (var j = pIndex + 1; j < pathData.length; j++) {
|
|
137
|
-
if (pathData[j].pathLength > 0) {
|
|
138
|
-
pIndex = j;
|
|
139
|
-
return pathData[j];
|
|
140
|
-
}
|
|
141
|
-
else if (pathData[j].command === 'M') {
|
|
142
|
-
p0 = {
|
|
143
|
-
x: pathData[j].points[0],
|
|
144
|
-
y: pathData[j].points[1],
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
return {};
|
|
149
|
-
};
|
|
150
|
-
var findSegmentToFitCharacter = function (c) {
|
|
151
|
-
var glyphWidth = that._getTextSize(c).width + letterSpacing;
|
|
152
|
-
if (c === ' ' && align === 'justify') {
|
|
153
|
-
glyphWidth += (fullPathWidth - textFullWidth) / spacesNumber;
|
|
154
|
-
}
|
|
155
|
-
var currLen = 0;
|
|
156
|
-
var attempts = 0;
|
|
157
|
-
p1 = undefined;
|
|
158
|
-
while (Math.abs(glyphWidth - currLen) / glyphWidth > 0.01 &&
|
|
159
|
-
attempts < 20) {
|
|
160
|
-
attempts++;
|
|
161
|
-
var cumulativePathLength = currLen;
|
|
162
|
-
while (pathCmd === undefined) {
|
|
163
|
-
pathCmd = getNextPathSegment();
|
|
164
|
-
if (pathCmd &&
|
|
165
|
-
cumulativePathLength + pathCmd.pathLength < glyphWidth) {
|
|
166
|
-
cumulativePathLength += pathCmd.pathLength;
|
|
167
|
-
pathCmd = undefined;
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (Object.keys(pathCmd).length === 0 || p0 === undefined) {
|
|
171
|
-
return undefined;
|
|
172
|
-
}
|
|
173
|
-
var needNewSegment = false;
|
|
174
|
-
switch (pathCmd.command) {
|
|
175
|
-
case 'L':
|
|
176
|
-
if (Path_1.Path.getLineLength(p0.x, p0.y, pathCmd.points[0], pathCmd.points[1]) > glyphWidth) {
|
|
177
|
-
p1 = Path_1.Path.getPointOnLine(glyphWidth, p0.x, p0.y, pathCmd.points[0], pathCmd.points[1], p0.x, p0.y);
|
|
178
|
-
}
|
|
179
|
-
else {
|
|
180
|
-
pathCmd = undefined;
|
|
181
|
-
}
|
|
182
|
-
break;
|
|
183
|
-
case 'A':
|
|
184
|
-
var start = pathCmd.points[4];
|
|
185
|
-
var dTheta = pathCmd.points[5];
|
|
186
|
-
var end = pathCmd.points[4] + dTheta;
|
|
187
|
-
if (currentT === 0) {
|
|
188
|
-
currentT = start + 0.00000001;
|
|
189
|
-
}
|
|
190
|
-
else if (glyphWidth > currLen) {
|
|
191
|
-
currentT += ((Math.PI / 180.0) * dTheta) / Math.abs(dTheta);
|
|
192
|
-
}
|
|
193
|
-
else {
|
|
194
|
-
currentT -= ((Math.PI / 360.0) * dTheta) / Math.abs(dTheta);
|
|
195
|
-
}
|
|
196
|
-
if ((dTheta < 0 && currentT < end) ||
|
|
197
|
-
(dTheta >= 0 && currentT > end)) {
|
|
198
|
-
currentT = end;
|
|
199
|
-
needNewSegment = true;
|
|
200
|
-
}
|
|
201
|
-
p1 = Path_1.Path.getPointOnEllipticalArc(pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3], currentT, pathCmd.points[6]);
|
|
202
|
-
break;
|
|
203
|
-
case 'C':
|
|
204
|
-
if (currentT === 0) {
|
|
205
|
-
if (glyphWidth > pathCmd.pathLength) {
|
|
206
|
-
currentT = 0.00000001;
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
currentT = glyphWidth / pathCmd.pathLength;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
else if (glyphWidth > currLen) {
|
|
213
|
-
currentT += (glyphWidth - currLen) / pathCmd.pathLength / 2;
|
|
214
|
-
}
|
|
215
|
-
else {
|
|
216
|
-
currentT = Math.max(currentT - (currLen - glyphWidth) / pathCmd.pathLength / 2, 0);
|
|
217
|
-
}
|
|
218
|
-
if (currentT > 1.0) {
|
|
219
|
-
currentT = 1.0;
|
|
220
|
-
needNewSegment = true;
|
|
221
|
-
}
|
|
222
|
-
p1 = Path_1.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]);
|
|
223
|
-
break;
|
|
224
|
-
case 'Q':
|
|
225
|
-
if (currentT === 0) {
|
|
226
|
-
currentT = glyphWidth / pathCmd.pathLength;
|
|
227
|
-
}
|
|
228
|
-
else if (glyphWidth > currLen) {
|
|
229
|
-
currentT += (glyphWidth - currLen) / pathCmd.pathLength;
|
|
230
|
-
}
|
|
231
|
-
else {
|
|
232
|
-
currentT -= (currLen - glyphWidth) / pathCmd.pathLength;
|
|
233
|
-
}
|
|
234
|
-
if (currentT > 1.0) {
|
|
235
|
-
currentT = 1.0;
|
|
236
|
-
needNewSegment = true;
|
|
237
|
-
}
|
|
238
|
-
p1 = Path_1.Path.getPointOnQuadraticBezier(currentT, pathCmd.start.x, pathCmd.start.y, pathCmd.points[0], pathCmd.points[1], pathCmd.points[2], pathCmd.points[3]);
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
if (p1 !== undefined) {
|
|
242
|
-
currLen = Path_1.Path.getLineLength(p0.x, p0.y, p1.x, p1.y);
|
|
243
|
-
}
|
|
244
|
-
if (needNewSegment) {
|
|
245
|
-
needNewSegment = false;
|
|
246
|
-
pathCmd = undefined;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
var testChar = 'C';
|
|
251
|
-
var glyphWidth = that._getTextSize(testChar).width + letterSpacing;
|
|
252
|
-
var lettersInOffset = offset / glyphWidth - 1;
|
|
253
|
-
for (var k = 0; k < lettersInOffset; k++) {
|
|
254
|
-
findSegmentToFitCharacter(testChar);
|
|
255
|
-
if (p0 === undefined || p1 === undefined) {
|
|
256
|
-
break;
|
|
257
|
-
}
|
|
258
|
-
p0 = p1;
|
|
259
|
-
}
|
|
260
|
-
for (var i = 0; i < charArr.length; i++) {
|
|
261
|
-
findSegmentToFitCharacter(charArr[i]);
|
|
262
|
-
if (p0 === undefined || p1 === undefined) {
|
|
263
|
-
break;
|
|
264
|
-
}
|
|
265
|
-
var width = Path_1.Path.getLineLength(p0.x, p0.y, p1.x, p1.y);
|
|
266
|
-
var kern = 0;
|
|
267
|
-
if (kerningFunc) {
|
|
268
|
-
try {
|
|
269
|
-
kern = kerningFunc(charArr[i - 1], charArr[i]) * this.fontSize();
|
|
270
|
-
}
|
|
271
|
-
catch (e) {
|
|
272
|
-
kern = 0;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
p0.x += kern;
|
|
276
|
-
p1.x += kern;
|
|
277
|
-
this.textWidth += kern;
|
|
278
|
-
var midpoint = Path_1.Path.getPointOnLine(kern + width / 2.0, p0.x, p0.y, p1.x, p1.y);
|
|
279
|
-
var rotation = Math.atan2(p1.y - p0.y, p1.x - p0.x);
|
|
280
|
-
this.glyphInfo.push({
|
|
281
|
-
transposeX: midpoint.x,
|
|
282
|
-
transposeY: midpoint.y,
|
|
283
|
-
text: charArr[i],
|
|
284
|
-
rotation: rotation,
|
|
285
|
-
p0: p0,
|
|
286
|
-
p1: p1,
|
|
287
|
-
});
|
|
288
|
-
p0 = p1;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
getSelfRect() {
|
|
292
|
-
if (!this.glyphInfo.length) {
|
|
293
|
-
return {
|
|
294
|
-
x: 0,
|
|
295
|
-
y: 0,
|
|
296
|
-
width: 0,
|
|
297
|
-
height: 0,
|
|
298
|
-
};
|
|
299
|
-
}
|
|
300
|
-
var points = [];
|
|
301
|
-
this.glyphInfo.forEach(function (info) {
|
|
302
|
-
points.push(info.p0.x);
|
|
303
|
-
points.push(info.p0.y);
|
|
304
|
-
points.push(info.p1.x);
|
|
305
|
-
points.push(info.p1.y);
|
|
306
|
-
});
|
|
307
|
-
var minX = points[0] || 0;
|
|
308
|
-
var maxX = points[0] || 0;
|
|
309
|
-
var minY = points[1] || 0;
|
|
310
|
-
var maxY = points[1] || 0;
|
|
311
|
-
var x, y;
|
|
312
|
-
for (var i = 0; i < points.length / 2; i++) {
|
|
313
|
-
x = points[i * 2];
|
|
314
|
-
y = points[i * 2 + 1];
|
|
315
|
-
minX = Math.min(minX, x);
|
|
316
|
-
maxX = Math.max(maxX, x);
|
|
317
|
-
minY = Math.min(minY, y);
|
|
318
|
-
maxY = Math.max(maxY, y);
|
|
319
|
-
}
|
|
320
|
-
var fontSize = this.fontSize();
|
|
321
|
-
return {
|
|
322
|
-
x: minX - fontSize / 2,
|
|
323
|
-
y: minY - fontSize / 2,
|
|
324
|
-
width: maxX - minX + fontSize,
|
|
325
|
-
height: maxY - minY + fontSize,
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
destroy() {
|
|
329
|
-
Util_1.Util.releaseCanvas(this.dummyCanvas);
|
|
330
|
-
return super.destroy();
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
exports.TextPath = TextPath;
|
|
334
|
-
TextPath.prototype._fillFunc = _fillFunc;
|
|
335
|
-
TextPath.prototype._strokeFunc = _strokeFunc;
|
|
336
|
-
TextPath.prototype._fillFuncHit = _fillFunc;
|
|
337
|
-
TextPath.prototype._strokeFuncHit = _strokeFunc;
|
|
338
|
-
TextPath.prototype.className = 'TextPath';
|
|
339
|
-
TextPath.prototype._attrsAffectingSize = ['text', 'fontSize', 'data'];
|
|
340
|
-
(0, Global_1._registerNode)(TextPath);
|
|
341
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'data');
|
|
342
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'fontFamily', 'Arial');
|
|
343
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'fontSize', 12, (0, Validators_1.getNumberValidator)());
|
|
344
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'fontStyle', NORMAL);
|
|
345
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'align', 'left');
|
|
346
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'letterSpacing', 0, (0, Validators_1.getNumberValidator)());
|
|
347
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
|
|
348
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'fontVariant', NORMAL);
|
|
349
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'text', EMPTY_STRING);
|
|
350
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'textDecoration', null);
|
|
351
|
-
Factory_1.Factory.addGetterSetter(TextPath, 'kerningFunc', null);
|
|
@@ -1,116 +0,0 @@
|
|
|
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';
|
|
7
|
-
export interface Box extends IRect {
|
|
8
|
-
rotation: number;
|
|
9
|
-
}
|
|
10
|
-
export interface TransformerConfig extends ContainerConfig {
|
|
11
|
-
resizeEnabled?: boolean;
|
|
12
|
-
rotateEnabled?: boolean;
|
|
13
|
-
rotationSnaps?: Array<number>;
|
|
14
|
-
rotationSnapTolerance?: number;
|
|
15
|
-
rotateAnchorOffset?: number;
|
|
16
|
-
borderEnabled?: boolean;
|
|
17
|
-
borderStroke?: string;
|
|
18
|
-
borderStrokeWidth?: number;
|
|
19
|
-
borderDash?: Array<number>;
|
|
20
|
-
anchorFill?: string;
|
|
21
|
-
anchorStroke?: string;
|
|
22
|
-
anchorStrokeWidth?: number;
|
|
23
|
-
anchorSize?: number;
|
|
24
|
-
anchorCornerRadius?: number;
|
|
25
|
-
keepRatio?: boolean;
|
|
26
|
-
centeredScaling?: boolean;
|
|
27
|
-
enabledAnchors?: Array<string>;
|
|
28
|
-
flipEnabled?: boolean;
|
|
29
|
-
node?: Rect;
|
|
30
|
-
ignoreStroke?: boolean;
|
|
31
|
-
boundBoxFunc?: (oldBox: Box, newBox: Box) => Box;
|
|
32
|
-
useSingleNodeRotation?: boolean;
|
|
33
|
-
shouldOverdrawWholeArea?: boolean;
|
|
34
|
-
}
|
|
35
|
-
export declare class Transformer extends Group {
|
|
36
|
-
_nodes: Array<Node>;
|
|
37
|
-
_movingAnchorName: string;
|
|
38
|
-
_transforming: boolean;
|
|
39
|
-
_anchorDragOffset: Vector2d;
|
|
40
|
-
sin: number;
|
|
41
|
-
cos: number;
|
|
42
|
-
_cursorChange: boolean;
|
|
43
|
-
constructor(config?: TransformerConfig);
|
|
44
|
-
attachTo(node: Node): this;
|
|
45
|
-
setNode(node: Node): this;
|
|
46
|
-
getNode(): Node<import("../Node").NodeConfig>;
|
|
47
|
-
_getEventNamespace(): string;
|
|
48
|
-
setNodes(nodes?: Array<Node>): this;
|
|
49
|
-
_proxyDrag(node: Node): void;
|
|
50
|
-
getNodes(): Node<import("../Node").NodeConfig>[];
|
|
51
|
-
getActiveAnchor(): string;
|
|
52
|
-
detach(): void;
|
|
53
|
-
_resetTransformCache(): void;
|
|
54
|
-
_getNodeRect(): any;
|
|
55
|
-
__getNodeShape(node: Node, rot?: number, relative?: Node): {
|
|
56
|
-
rotation: number;
|
|
57
|
-
x: number;
|
|
58
|
-
y: number;
|
|
59
|
-
width: number;
|
|
60
|
-
height: number;
|
|
61
|
-
};
|
|
62
|
-
__getNodeRect(): {
|
|
63
|
-
x: number;
|
|
64
|
-
y: number;
|
|
65
|
-
width: number;
|
|
66
|
-
height: number;
|
|
67
|
-
rotation: number;
|
|
68
|
-
};
|
|
69
|
-
getX(): any;
|
|
70
|
-
getY(): any;
|
|
71
|
-
getWidth(): any;
|
|
72
|
-
getHeight(): any;
|
|
73
|
-
_createElements(): void;
|
|
74
|
-
_createAnchor(name: any): void;
|
|
75
|
-
_createBack(): void;
|
|
76
|
-
_handleMouseDown(e: any): void;
|
|
77
|
-
_handleMouseMove(e: any): void;
|
|
78
|
-
_handleMouseUp(e: any): void;
|
|
79
|
-
getAbsoluteTransform(): Transform;
|
|
80
|
-
_removeEvents(e?: any): void;
|
|
81
|
-
_fitNodesInto(newAttrs: any, evt?: any): void;
|
|
82
|
-
forceUpdate(): void;
|
|
83
|
-
_batchChangeChild(selector: string, attrs: any): void;
|
|
84
|
-
update(): void;
|
|
85
|
-
isTransforming(): boolean;
|
|
86
|
-
stopTransform(): void;
|
|
87
|
-
destroy(): this;
|
|
88
|
-
toObject(): any;
|
|
89
|
-
clone(obj?: any): this;
|
|
90
|
-
getClientRect(): IRect;
|
|
91
|
-
nodes: GetSet<Node[], this>;
|
|
92
|
-
enabledAnchors: GetSet<string[], this>;
|
|
93
|
-
rotationSnaps: GetSet<number[], this>;
|
|
94
|
-
anchorSize: GetSet<number, this>;
|
|
95
|
-
resizeEnabled: GetSet<boolean, this>;
|
|
96
|
-
rotateEnabled: GetSet<boolean, this>;
|
|
97
|
-
rotateAnchorOffset: GetSet<number, this>;
|
|
98
|
-
rotationSnapTolerance: GetSet<number, this>;
|
|
99
|
-
padding: GetSet<number, this>;
|
|
100
|
-
borderEnabled: GetSet<boolean, this>;
|
|
101
|
-
borderStroke: GetSet<string, this>;
|
|
102
|
-
borderStrokeWidth: GetSet<number, this>;
|
|
103
|
-
borderDash: GetSet<number[], this>;
|
|
104
|
-
anchorFill: GetSet<string, this>;
|
|
105
|
-
anchorStroke: GetSet<string, this>;
|
|
106
|
-
anchorCornerRadius: GetSet<number, this>;
|
|
107
|
-
anchorStrokeWidth: GetSet<number, this>;
|
|
108
|
-
keepRatio: GetSet<boolean, this>;
|
|
109
|
-
centeredScaling: GetSet<boolean, this>;
|
|
110
|
-
flipEnabled: GetSet<boolean, this>;
|
|
111
|
-
ignoreStroke: GetSet<boolean, this>;
|
|
112
|
-
boundBoxFunc: GetSet<(oldBox: Box, newBox: Box) => Box, this>;
|
|
113
|
-
anchorDragBoundFunc: GetSet<(oldPos: Vector2d, newPos: Vector2d, e: MouseEvent) => Vector2d, this>;
|
|
114
|
-
shouldOverdrawWholeArea: GetSet<boolean, this>;
|
|
115
|
-
useSingleNodeRotation: GetSet<boolean, this>;
|
|
116
|
-
}
|