konva 10.4.0 → 10.6.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 +4 -4
- package/konva.js +3432 -3746
- package/konva.min.js +4 -4
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +2 -2
- package/lib/BezierFunctions.d.ts +1 -1
- package/lib/BezierFunctions.js +76 -116
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +8 -5
- package/lib/Container.js +9 -6
- package/lib/Context.d.ts +4 -5
- package/lib/Context.js +77 -72
- package/lib/DragAndDrop.d.ts +5 -3
- package/lib/DragAndDrop.js +65 -29
- package/lib/Factory.d.ts +3 -2
- package/lib/Factory.js +10 -9
- package/lib/Global.d.ts +0 -6
- package/lib/Global.js +2 -8
- package/lib/Layer.js +9 -6
- package/lib/Node.d.ts +33 -15
- package/lib/Node.js +179 -135
- package/lib/PointerEvents.d.ts +1 -2
- package/lib/PointerEvents.js +20 -18
- package/lib/Shape.d.ts +2 -2
- package/lib/Shape.js +51 -7
- package/lib/Stage.d.ts +23 -14
- package/lib/Stage.js +221 -93
- package/lib/Tween.js +59 -66
- package/lib/Util.d.ts +3 -2
- package/lib/Util.js +43 -16
- package/lib/_CoreInternals.d.ts +25 -11
- package/lib/_FullInternals.d.ts +25 -11
- package/lib/filters/Blur.js +16 -12
- package/lib/filters/Brighten.d.ts +1 -0
- package/lib/filters/Brighten.js +1 -0
- package/lib/filters/Brightness.d.ts +2 -1
- package/lib/filters/Brightness.js +4 -4
- package/lib/filters/Emboss.js +16 -58
- package/lib/filters/Kaleidoscope.js +8 -15
- package/lib/filters/Mask.js +8 -8
- package/lib/filters/Pixelate.js +16 -29
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +1 -1
- package/lib/shapes/Arc.js +5 -3
- package/lib/shapes/Arrow.d.ts +2 -6
- package/lib/shapes/Arrow.js +68 -46
- package/lib/shapes/Image.js +16 -19
- package/lib/shapes/Label.d.ts +2 -3
- package/lib/shapes/Label.js +7 -21
- package/lib/shapes/Line.d.ts +1 -1
- package/lib/shapes/Line.js +1 -1
- package/lib/shapes/Path.d.ts +27 -2
- package/lib/shapes/Path.js +148 -142
- package/lib/shapes/RegularPolygon.js +1 -1
- package/lib/shapes/Sprite.js +2 -6
- package/lib/shapes/Text.d.ts +12 -4
- package/lib/shapes/Text.js +96 -54
- package/lib/shapes/TextPath.d.ts +4 -3
- package/lib/shapes/TextPath.js +40 -26
- package/lib/shapes/Transformer.d.ts +16 -1
- package/lib/shapes/Transformer.js +209 -130
- package/lib/types.d.ts +2 -2
- package/package.json +4 -3
package/lib/shapes/Line.js
CHANGED
|
@@ -203,7 +203,7 @@ export class Line extends Shape {
|
|
|
203
203
|
}
|
|
204
204
|
}
|
|
205
205
|
Line.prototype.className = 'Line';
|
|
206
|
-
Line.prototype._attrsAffectingSize = ['points', 'bezier', 'tension'];
|
|
206
|
+
Line.prototype._attrsAffectingSize = ['points', 'bezier', 'tension', 'closed'];
|
|
207
207
|
_registerNode(Line);
|
|
208
208
|
// add getters setters
|
|
209
209
|
Factory.addGetterSetter(Line, 'closed', false);
|
package/lib/shapes/Path.d.ts
CHANGED
|
@@ -58,7 +58,10 @@ export declare class Path extends Shape<PathConfig> {
|
|
|
58
58
|
data: GetSet<string, this>;
|
|
59
59
|
static getLineLength(x1: any, y1: any, x2: any, y2: any): number;
|
|
60
60
|
static getPathLength(dataArray: PathSegment[]): number;
|
|
61
|
-
static getPointAtLengthOfDataArray(length: number, dataArray: PathSegment[]
|
|
61
|
+
static getPointAtLengthOfDataArray(length: number, dataArray: PathSegment[], cursor?: {
|
|
62
|
+
index: number;
|
|
63
|
+
offset: number;
|
|
64
|
+
}): {
|
|
62
65
|
x: number;
|
|
63
66
|
y: number;
|
|
64
67
|
} | null;
|
|
@@ -79,6 +82,28 @@ export declare class Path extends Shape<PathConfig> {
|
|
|
79
82
|
y: number;
|
|
80
83
|
};
|
|
81
84
|
static parsePathData(data: any): PathSegment[];
|
|
82
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Walks an arc in one degree steps, accumulating its length. Returns the
|
|
87
|
+
* angle `length` along the arc, or its end angle and total length when
|
|
88
|
+
* `length` is past the end.
|
|
89
|
+
*/
|
|
90
|
+
private static _walkArc;
|
|
91
|
+
static calcLength(x: any, y: any, cmd: any, points: any): number;
|
|
83
92
|
static convertEndpointToCenterParameterization(x1: number, y1: number, x2: number, y2: number, fa: number, fs: number, rx: number, ry: number, psiDeg: number): number[];
|
|
84
93
|
}
|
|
94
|
+
/**
|
|
95
|
+
* get width of the path. It is computed from the path data and cannot be set
|
|
96
|
+
* @name Konva.Path#width
|
|
97
|
+
* @method
|
|
98
|
+
* @returns {Number}
|
|
99
|
+
* @example
|
|
100
|
+
* var width = path.width();
|
|
101
|
+
*/
|
|
102
|
+
/**
|
|
103
|
+
* get height of the path. It is computed from the path data and cannot be set
|
|
104
|
+
* @name Konva.Path#height
|
|
105
|
+
* @method
|
|
106
|
+
* @returns {Number}
|
|
107
|
+
* @example
|
|
108
|
+
* var height = path.height();
|
|
109
|
+
*/
|
package/lib/shapes/Path.js
CHANGED
|
@@ -16,6 +16,7 @@ const PARAM_COUNT = {
|
|
|
16
16
|
a: 7,
|
|
17
17
|
z: 0,
|
|
18
18
|
};
|
|
19
|
+
const TAU = Math.PI * 2;
|
|
19
20
|
/**
|
|
20
21
|
* Path constructor.
|
|
21
22
|
* @author Jason Follas
|
|
@@ -72,17 +73,7 @@ export class Path extends Shape {
|
|
|
72
73
|
context.quadraticCurveTo(p[0], p[1], p[2], p[3]);
|
|
73
74
|
break;
|
|
74
75
|
case 'A':
|
|
75
|
-
|
|
76
|
-
const r = rx > ry ? rx : ry;
|
|
77
|
-
const scaleX = rx > ry ? 1 : rx / ry;
|
|
78
|
-
const scaleY = rx > ry ? ry / rx : 1;
|
|
79
|
-
context.translate(cx, cy);
|
|
80
|
-
context.rotate(psi);
|
|
81
|
-
context.scale(scaleX, scaleY);
|
|
82
|
-
context.arc(0, 0, r, theta, theta + dTheta, 1 - fs);
|
|
83
|
-
context.scale(1 / scaleX, 1 / scaleY);
|
|
84
|
-
context.rotate(-psi);
|
|
85
|
-
context.translate(-cx, -cy);
|
|
76
|
+
context.ellipse(p[0], p[1], p[2], p[3], p[6], p[4], p[4] + p[5], !p[7]);
|
|
86
77
|
break;
|
|
87
78
|
case 'z':
|
|
88
79
|
isClosed = true;
|
|
@@ -104,34 +95,26 @@ export class Path extends Shape {
|
|
|
104
95
|
return this.getSelfRect().height;
|
|
105
96
|
}
|
|
106
97
|
getSelfRect() {
|
|
107
|
-
|
|
98
|
+
const points = [];
|
|
108
99
|
this.dataArray.forEach(function (data) {
|
|
109
100
|
if (data.command === 'A') {
|
|
110
|
-
//
|
|
111
|
-
|
|
112
|
-
//
|
|
113
|
-
const dTheta = data.points
|
|
114
|
-
|
|
115
|
-
const end =
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const point = Path.getPointOnEllipticalArc(data.points[0], data.points[1], data.points[2], data.points[3], t, data.points[6]);
|
|
125
|
-
points.push(point.x, point.y);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
// counter-clockwise
|
|
130
|
-
for (let t = start + inc; t < end; t += inc) {
|
|
131
|
-
const point = Path.getPointOnEllipticalArc(data.points[0], data.points[1], data.points[2], data.points[3], t, data.points[6]);
|
|
101
|
+
// the two end points, plus the angles where the ellipse turns back on
|
|
102
|
+
// either axis, when they fall inside the sweep. Together they are the
|
|
103
|
+
// exact bounds of the segment
|
|
104
|
+
const [cx, cy, rx, ry, start, dTheta, psi] = data.points;
|
|
105
|
+
const cos = Math.cos(psi), sin = Math.sin(psi);
|
|
106
|
+
const end = Path.getPointOnEllipticalArc(cx, cy, rx, ry, start + dTheta, psi);
|
|
107
|
+
points.push(data.start.x, data.start.y, end.x, end.y);
|
|
108
|
+
const tx = Math.atan2(-ry * sin, rx * cos);
|
|
109
|
+
const ty = Math.atan2(ry * cos, rx * sin);
|
|
110
|
+
[tx, tx + Math.PI, ty, ty + Math.PI].forEach((t) => {
|
|
111
|
+
// how far into the sweep t is, in the direction of the sweep
|
|
112
|
+
const k = ((((t - start) * Math.sign(dTheta)) % TAU) + TAU) % TAU;
|
|
113
|
+
if (k < Math.abs(dTheta)) {
|
|
114
|
+
const point = Path.getPointOnEllipticalArc(cx, cy, rx, ry, t, psi);
|
|
132
115
|
points.push(point.x, point.y);
|
|
133
116
|
}
|
|
134
|
-
}
|
|
117
|
+
});
|
|
135
118
|
}
|
|
136
119
|
else if (data.command === 'C') {
|
|
137
120
|
// the two end points, plus the points where the curve turns back on
|
|
@@ -144,7 +127,7 @@ export class Path extends Shape {
|
|
|
144
127
|
points.push(data.start.x, data.start.y, data.points[2], data.points[3], ...getQuadraticExtremaPoints(data.start.x, data.start.y, data.points[0], data.points[1], data.points[2], data.points[3]));
|
|
145
128
|
}
|
|
146
129
|
else {
|
|
147
|
-
points
|
|
130
|
+
points.push(...data.points);
|
|
148
131
|
}
|
|
149
132
|
});
|
|
150
133
|
return Util._getPointsRect(points);
|
|
@@ -182,21 +165,31 @@ export class Path extends Shape {
|
|
|
182
165
|
}
|
|
183
166
|
return pathLength;
|
|
184
167
|
}
|
|
185
|
-
|
|
186
|
-
|
|
168
|
+
// The optional cursor is for sequential lookups within one continuous subpath.
|
|
169
|
+
static getPointAtLengthOfDataArray(length, dataArray, cursor) {
|
|
170
|
+
var _a, _b;
|
|
171
|
+
let points, i = (_a = cursor === null || cursor === void 0 ? void 0 : cursor.index) !== null && _a !== void 0 ? _a : 0, offset = (_b = cursor === null || cursor === void 0 ? void 0 : cursor.offset) !== null && _b !== void 0 ? _b : 0, ii = dataArray.length;
|
|
187
172
|
if (!ii) {
|
|
188
173
|
return null;
|
|
189
174
|
}
|
|
175
|
+
// Negative spacing can move a text glyph back into an earlier segment.
|
|
176
|
+
while (i > 0 && length <= offset) {
|
|
177
|
+
offset -= dataArray[--i].pathLength;
|
|
178
|
+
}
|
|
179
|
+
length -= offset;
|
|
190
180
|
while (i < ii && length > dataArray[i].pathLength) {
|
|
191
|
-
|
|
181
|
+
const segmentLength = dataArray[i].pathLength;
|
|
182
|
+
length -= segmentLength;
|
|
183
|
+
offset += segmentLength;
|
|
192
184
|
++i;
|
|
193
185
|
}
|
|
186
|
+
if (cursor && i < ii) {
|
|
187
|
+
cursor.index = i;
|
|
188
|
+
cursor.offset = offset;
|
|
189
|
+
}
|
|
194
190
|
if (i === ii) {
|
|
195
191
|
// past the end: the end of the last segment
|
|
196
192
|
i--;
|
|
197
|
-
while (i > 0 && dataArray[i].points.length < 2) {
|
|
198
|
-
i--;
|
|
199
|
-
}
|
|
200
193
|
length = dataArray[i].pathLength;
|
|
201
194
|
}
|
|
202
195
|
if (length < 0.01) {
|
|
@@ -219,6 +212,7 @@ export class Path extends Shape {
|
|
|
219
212
|
const p = cp.points;
|
|
220
213
|
switch (cp.command) {
|
|
221
214
|
case 'L':
|
|
215
|
+
case 'z':
|
|
222
216
|
return Path.getPointOnLine(length, cp.start.x, cp.start.y, p[0], p[1]);
|
|
223
217
|
case 'C':
|
|
224
218
|
return Path.getPointOnCubicBezier(t2length(length, cp.pathLength, (i) => {
|
|
@@ -229,10 +223,12 @@ export class Path extends Shape {
|
|
|
229
223
|
return getQuadraticArcLength([cp.start.x, p[0], p[2]], [cp.start.y, p[1], p[3]], i);
|
|
230
224
|
}), cp.start.x, cp.start.y, p[0], p[1], p[2], p[3]);
|
|
231
225
|
case 'A':
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
226
|
+
return Path.getPointOnEllipticalArc(p[0], p[1], p[2], p[3],
|
|
227
|
+
// on a circle angle is proportional to distance, so the walk is only
|
|
228
|
+
// needed for a real ellipse
|
|
229
|
+
p[2] === p[3]
|
|
230
|
+
? p[4] + (p[5] * length) / cp.pathLength
|
|
231
|
+
: Path._walkArc(p, length).theta, p[6]);
|
|
236
232
|
}
|
|
237
233
|
return null;
|
|
238
234
|
}
|
|
@@ -374,6 +370,9 @@ export class Path extends Shape {
|
|
|
374
370
|
// init context point
|
|
375
371
|
let cpx = 0;
|
|
376
372
|
let cpy = 0;
|
|
373
|
+
// start of the current subpath: where z draws back to
|
|
374
|
+
let spx = 0;
|
|
375
|
+
let spy = 0;
|
|
377
376
|
const re = /([-+]?((\d+\.\d+)|((\d+)|(\.\d+)))(?:e[-+]?\d+)?)/gi;
|
|
378
377
|
let match;
|
|
379
378
|
for (let n = 1; n < arr.length; n++) {
|
|
@@ -384,7 +383,7 @@ export class Path extends Shape {
|
|
|
384
383
|
while ((match = re.exec(str))) {
|
|
385
384
|
coords.push(match[0]);
|
|
386
385
|
}
|
|
387
|
-
|
|
386
|
+
const p = [];
|
|
388
387
|
// Track param position for A/a commands: 0..6 => rx, ry, psi, fa, fs, x, y
|
|
389
388
|
let arcParamIndex = c === 'A' || c === 'a' ? 0 : -1;
|
|
390
389
|
for (let j = 0, jlen = coords.length; j < jlen; j++) {
|
|
@@ -404,10 +403,13 @@ export class Path extends Shape {
|
|
|
404
403
|
arcParamIndex = (arcParamIndex + 1) % 7;
|
|
405
404
|
}
|
|
406
405
|
}
|
|
407
|
-
|
|
406
|
+
let pIndex = 0;
|
|
407
|
+
while (pIndex < p.length) {
|
|
408
408
|
// z takes no numbers, and a command with too few of them ("L20"
|
|
409
409
|
// with no y) is dropped rather than parsed into a NaN segment
|
|
410
|
-
if (p.length < PARAM_COUNT[c.toLowerCase()] ||
|
|
410
|
+
if (p.length - pIndex < PARAM_COUNT[c.toLowerCase()] ||
|
|
411
|
+
c === 'z' ||
|
|
412
|
+
c === 'Z') {
|
|
411
413
|
break;
|
|
412
414
|
}
|
|
413
415
|
let cmd = '';
|
|
@@ -420,76 +422,67 @@ export class Path extends Shape {
|
|
|
420
422
|
switch (c) {
|
|
421
423
|
// Note: Keep the lineTo's above the moveTo's in this switch
|
|
422
424
|
case 'l':
|
|
423
|
-
cpx += p
|
|
424
|
-
cpy += p
|
|
425
|
+
cpx += p[pIndex++];
|
|
426
|
+
cpy += p[pIndex++];
|
|
425
427
|
cmd = 'L';
|
|
426
428
|
points.push(cpx, cpy);
|
|
427
429
|
break;
|
|
428
430
|
case 'L':
|
|
429
|
-
cpx = p
|
|
430
|
-
cpy = p
|
|
431
|
+
cpx = p[pIndex++];
|
|
432
|
+
cpy = p[pIndex++];
|
|
431
433
|
points.push(cpx, cpy);
|
|
432
434
|
break;
|
|
433
435
|
// Note: lineTo handlers need to be above this point
|
|
434
436
|
case 'm':
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
cpx += dx;
|
|
438
|
-
cpy += dy;
|
|
437
|
+
cpx += p[pIndex++];
|
|
438
|
+
cpy += p[pIndex++];
|
|
439
439
|
cmd = 'M';
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (ca.length > 2 && ca[ca.length - 1].command === 'z') {
|
|
443
|
-
for (let idx = ca.length - 2; idx >= 0; idx--) {
|
|
444
|
-
if (ca[idx].command === 'M') {
|
|
445
|
-
cpx = ca[idx].points[0] + dx;
|
|
446
|
-
cpy = ca[idx].points[1] + dy;
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
440
|
+
spx = cpx;
|
|
441
|
+
spy = cpy;
|
|
451
442
|
points.push(cpx, cpy);
|
|
452
443
|
c = 'l';
|
|
453
444
|
// subsequent points are treated as relative lineTo
|
|
454
445
|
break;
|
|
455
446
|
case 'M':
|
|
456
|
-
cpx = p
|
|
457
|
-
cpy = p
|
|
447
|
+
cpx = p[pIndex++];
|
|
448
|
+
cpy = p[pIndex++];
|
|
458
449
|
cmd = 'M';
|
|
450
|
+
spx = cpx;
|
|
451
|
+
spy = cpy;
|
|
459
452
|
points.push(cpx, cpy);
|
|
460
453
|
c = 'L';
|
|
461
454
|
// subsequent points are treated as absolute lineTo
|
|
462
455
|
break;
|
|
463
456
|
case 'h':
|
|
464
|
-
cpx += p
|
|
457
|
+
cpx += p[pIndex++];
|
|
465
458
|
cmd = 'L';
|
|
466
459
|
points.push(cpx, cpy);
|
|
467
460
|
break;
|
|
468
461
|
case 'H':
|
|
469
|
-
cpx = p
|
|
462
|
+
cpx = p[pIndex++];
|
|
470
463
|
cmd = 'L';
|
|
471
464
|
points.push(cpx, cpy);
|
|
472
465
|
break;
|
|
473
466
|
case 'v':
|
|
474
|
-
cpy += p
|
|
467
|
+
cpy += p[pIndex++];
|
|
475
468
|
cmd = 'L';
|
|
476
469
|
points.push(cpx, cpy);
|
|
477
470
|
break;
|
|
478
471
|
case 'V':
|
|
479
|
-
cpy = p
|
|
472
|
+
cpy = p[pIndex++];
|
|
480
473
|
cmd = 'L';
|
|
481
474
|
points.push(cpx, cpy);
|
|
482
475
|
break;
|
|
483
476
|
case 'C':
|
|
484
|
-
points.push(p
|
|
485
|
-
cpx = p
|
|
486
|
-
cpy = p
|
|
477
|
+
points.push(p[pIndex++], p[pIndex++], p[pIndex++], p[pIndex++]);
|
|
478
|
+
cpx = p[pIndex++];
|
|
479
|
+
cpy = p[pIndex++];
|
|
487
480
|
points.push(cpx, cpy);
|
|
488
481
|
break;
|
|
489
482
|
case 'c':
|
|
490
|
-
points.push(cpx + p
|
|
491
|
-
cpx += p
|
|
492
|
-
cpy += p
|
|
483
|
+
points.push(cpx + p[pIndex++], cpy + p[pIndex++], cpx + p[pIndex++], cpy + p[pIndex++]);
|
|
484
|
+
cpx += p[pIndex++];
|
|
485
|
+
cpy += p[pIndex++];
|
|
493
486
|
cmd = 'C';
|
|
494
487
|
points.push(cpx, cpy);
|
|
495
488
|
break;
|
|
@@ -501,9 +494,9 @@ export class Path extends Shape {
|
|
|
501
494
|
ctlPtx = cpx + (cpx - prevCmd.points[2]);
|
|
502
495
|
ctlPty = cpy + (cpy - prevCmd.points[3]);
|
|
503
496
|
}
|
|
504
|
-
points.push(ctlPtx, ctlPty, p
|
|
505
|
-
cpx = p
|
|
506
|
-
cpy = p
|
|
497
|
+
points.push(ctlPtx, ctlPty, p[pIndex++], p[pIndex++]);
|
|
498
|
+
cpx = p[pIndex++];
|
|
499
|
+
cpy = p[pIndex++];
|
|
507
500
|
cmd = 'C';
|
|
508
501
|
points.push(cpx, cpy);
|
|
509
502
|
break;
|
|
@@ -515,22 +508,22 @@ export class Path extends Shape {
|
|
|
515
508
|
ctlPtx = cpx + (cpx - prevCmd.points[2]);
|
|
516
509
|
ctlPty = cpy + (cpy - prevCmd.points[3]);
|
|
517
510
|
}
|
|
518
|
-
points.push(ctlPtx, ctlPty, cpx + p
|
|
519
|
-
cpx += p
|
|
520
|
-
cpy += p
|
|
511
|
+
points.push(ctlPtx, ctlPty, cpx + p[pIndex++], cpy + p[pIndex++]);
|
|
512
|
+
cpx += p[pIndex++];
|
|
513
|
+
cpy += p[pIndex++];
|
|
521
514
|
cmd = 'C';
|
|
522
515
|
points.push(cpx, cpy);
|
|
523
516
|
break;
|
|
524
517
|
case 'Q':
|
|
525
|
-
points.push(p
|
|
526
|
-
cpx = p
|
|
527
|
-
cpy = p
|
|
518
|
+
points.push(p[pIndex++], p[pIndex++]);
|
|
519
|
+
cpx = p[pIndex++];
|
|
520
|
+
cpy = p[pIndex++];
|
|
528
521
|
points.push(cpx, cpy);
|
|
529
522
|
break;
|
|
530
523
|
case 'q':
|
|
531
|
-
points.push(cpx + p
|
|
532
|
-
cpx += p
|
|
533
|
-
cpy += p
|
|
524
|
+
points.push(cpx + p[pIndex++], cpy + p[pIndex++]);
|
|
525
|
+
cpx += p[pIndex++];
|
|
526
|
+
cpy += p[pIndex++];
|
|
534
527
|
cmd = 'Q';
|
|
535
528
|
points.push(cpx, cpy);
|
|
536
529
|
break;
|
|
@@ -542,8 +535,8 @@ export class Path extends Shape {
|
|
|
542
535
|
ctlPtx = cpx + (cpx - prevCmd.points[0]);
|
|
543
536
|
ctlPty = cpy + (cpy - prevCmd.points[1]);
|
|
544
537
|
}
|
|
545
|
-
cpx = p
|
|
546
|
-
cpy = p
|
|
538
|
+
cpx = p[pIndex++];
|
|
539
|
+
cpy = p[pIndex++];
|
|
547
540
|
cmd = 'Q';
|
|
548
541
|
points.push(ctlPtx, ctlPty, cpx, cpy);
|
|
549
542
|
break;
|
|
@@ -555,27 +548,28 @@ export class Path extends Shape {
|
|
|
555
548
|
ctlPtx = cpx + (cpx - prevCmd.points[0]);
|
|
556
549
|
ctlPty = cpy + (cpy - prevCmd.points[1]);
|
|
557
550
|
}
|
|
558
|
-
cpx += p
|
|
559
|
-
cpy += p
|
|
551
|
+
cpx += p[pIndex++];
|
|
552
|
+
cpy += p[pIndex++];
|
|
560
553
|
cmd = 'Q';
|
|
561
554
|
points.push(ctlPtx, ctlPty, cpx, cpy);
|
|
562
555
|
break;
|
|
563
556
|
case 'A':
|
|
564
557
|
case 'a':
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
558
|
+
// per SVG, the radii are used as absolute values
|
|
559
|
+
rx = Math.abs(p[pIndex++]);
|
|
560
|
+
ry = Math.abs(p[pIndex++]);
|
|
561
|
+
psi = p[pIndex++];
|
|
562
|
+
fa = p[pIndex++];
|
|
563
|
+
fs = p[pIndex++];
|
|
570
564
|
x1 = cpx;
|
|
571
565
|
y1 = cpy;
|
|
572
566
|
if (c === 'a') {
|
|
573
|
-
cpx += p
|
|
574
|
-
cpy += p
|
|
567
|
+
cpx += p[pIndex++];
|
|
568
|
+
cpy += p[pIndex++];
|
|
575
569
|
}
|
|
576
570
|
else {
|
|
577
|
-
cpx = p
|
|
578
|
-
cpy = p
|
|
571
|
+
cpx = p[pIndex++];
|
|
572
|
+
cpy = p[pIndex++];
|
|
579
573
|
}
|
|
580
574
|
cmd = 'A';
|
|
581
575
|
// per SVG, an arc between coincident end points is omitted
|
|
@@ -603,18 +597,46 @@ export class Path extends Shape {
|
|
|
603
597
|
});
|
|
604
598
|
}
|
|
605
599
|
if (c === 'z' || c === 'Z') {
|
|
600
|
+
// per SVG, z is a line back to the start of the subpath, which then
|
|
601
|
+
// becomes the current point
|
|
606
602
|
ca.push({
|
|
607
603
|
command: 'z',
|
|
608
|
-
points: [],
|
|
609
|
-
start:
|
|
610
|
-
pathLength:
|
|
604
|
+
points: [spx, spy],
|
|
605
|
+
start: { x: cpx, y: cpy },
|
|
606
|
+
pathLength: this.getLineLength(cpx, cpy, spx, spy),
|
|
611
607
|
});
|
|
608
|
+
cpx = spx;
|
|
609
|
+
cpy = spy;
|
|
612
610
|
}
|
|
613
611
|
}
|
|
614
612
|
return ca;
|
|
615
613
|
}
|
|
614
|
+
/**
|
|
615
|
+
* Walks an arc in one degree steps, accumulating its length. Returns the
|
|
616
|
+
* angle `length` along the arc, or its end angle and total length when
|
|
617
|
+
* `length` is past the end.
|
|
618
|
+
*/
|
|
619
|
+
static _walkArc(points, length) {
|
|
620
|
+
const [cx, cy, rx, ry, start, dTheta] = points;
|
|
621
|
+
const steps = Math.max(1, Math.ceil(Math.abs(dTheta) / (Math.PI / 180)));
|
|
622
|
+
// the arc length does not depend on the x-axis rotation psi, so it is left out
|
|
623
|
+
let p1 = Path.getPointOnEllipticalArc(cx, cy, rx, ry, start, 0);
|
|
624
|
+
let prev = start;
|
|
625
|
+
let len = 0;
|
|
626
|
+
for (let i = 1; i <= steps; i++) {
|
|
627
|
+
const t = start + (dTheta * i) / steps;
|
|
628
|
+
const p2 = Path.getPointOnEllipticalArc(cx, cy, rx, ry, t, 0);
|
|
629
|
+
const d = Path.getLineLength(p1.x, p1.y, p2.x, p2.y);
|
|
630
|
+
if (len + d >= length) {
|
|
631
|
+
return { theta: prev + (t - prev) * ((length - len) / d), length };
|
|
632
|
+
}
|
|
633
|
+
len += d;
|
|
634
|
+
p1 = p2;
|
|
635
|
+
prev = t;
|
|
636
|
+
}
|
|
637
|
+
return { theta: prev, length: len };
|
|
638
|
+
}
|
|
616
639
|
static calcLength(x, y, cmd, points) {
|
|
617
|
-
let len, p1, p2, t;
|
|
618
640
|
const path = Path;
|
|
619
641
|
switch (cmd) {
|
|
620
642
|
case 'L':
|
|
@@ -624,39 +646,7 @@ export class Path extends Shape {
|
|
|
624
646
|
case 'Q':
|
|
625
647
|
return getQuadraticArcLength([x, points[0], points[2]], [y, points[1], points[3]], 1);
|
|
626
648
|
case 'A':
|
|
627
|
-
|
|
628
|
-
len = 0.0;
|
|
629
|
-
const start = points[4];
|
|
630
|
-
// 4 = theta
|
|
631
|
-
const dTheta = points[5];
|
|
632
|
-
// 5 = dTheta
|
|
633
|
-
const end = points[4] + dTheta;
|
|
634
|
-
let inc = Math.PI / 180.0;
|
|
635
|
-
// 1 degree resolution
|
|
636
|
-
if (Math.abs(start - end) < inc) {
|
|
637
|
-
inc = Math.abs(start - end);
|
|
638
|
-
}
|
|
639
|
-
// the arc length does not depend on the x-axis rotation psi, so it is left out
|
|
640
|
-
p1 = path.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], start, 0);
|
|
641
|
-
if (dTheta < 0) {
|
|
642
|
-
// clockwise
|
|
643
|
-
for (t = start - inc; t > end; t -= inc) {
|
|
644
|
-
p2 = path.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], t, 0);
|
|
645
|
-
len += path.getLineLength(p1.x, p1.y, p2.x, p2.y);
|
|
646
|
-
p1 = p2;
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
else {
|
|
650
|
-
// counter-clockwise
|
|
651
|
-
for (t = start + inc; t < end; t += inc) {
|
|
652
|
-
p2 = path.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], t, 0);
|
|
653
|
-
len += path.getLineLength(p1.x, p1.y, p2.x, p2.y);
|
|
654
|
-
p1 = p2;
|
|
655
|
-
}
|
|
656
|
-
}
|
|
657
|
-
p2 = path.getPointOnEllipticalArc(points[0], points[1], points[2], points[3], end, 0);
|
|
658
|
-
len += path.getLineLength(p1.x, p1.y, p2.x, p2.y);
|
|
659
|
-
return len;
|
|
649
|
+
return path._walkArc(points, Infinity).length;
|
|
660
650
|
}
|
|
661
651
|
return 0;
|
|
662
652
|
}
|
|
@@ -731,3 +721,19 @@ _registerNode(Path);
|
|
|
731
721
|
* path.data('M200,100h100v50z');
|
|
732
722
|
*/
|
|
733
723
|
Factory.addGetterSetter(Path, 'data');
|
|
724
|
+
/**
|
|
725
|
+
* get width of the path. It is computed from the path data and cannot be set
|
|
726
|
+
* @name Konva.Path#width
|
|
727
|
+
* @method
|
|
728
|
+
* @returns {Number}
|
|
729
|
+
* @example
|
|
730
|
+
* var width = path.width();
|
|
731
|
+
*/
|
|
732
|
+
/**
|
|
733
|
+
* get height of the path. It is computed from the path data and cannot be set
|
|
734
|
+
* @name Konva.Path#height
|
|
735
|
+
* @method
|
|
736
|
+
* @returns {Number}
|
|
737
|
+
* @example
|
|
738
|
+
* var height = path.height();
|
|
739
|
+
*/
|
|
@@ -93,7 +93,7 @@ export class RegularPolygon extends Shape {
|
|
|
93
93
|
}
|
|
94
94
|
RegularPolygon.prototype.className = 'RegularPolygon';
|
|
95
95
|
RegularPolygon.prototype._centroid = true;
|
|
96
|
-
RegularPolygon.prototype._attrsAffectingSize = ['radius'];
|
|
96
|
+
RegularPolygon.prototype._attrsAffectingSize = ['radius', 'sides'];
|
|
97
97
|
_registerNode(RegularPolygon);
|
|
98
98
|
/**
|
|
99
99
|
* get/set radius
|
package/lib/shapes/Sprite.js
CHANGED
|
@@ -149,12 +149,8 @@ export class Sprite extends Shape {
|
|
|
149
149
|
return;
|
|
150
150
|
}
|
|
151
151
|
const layer = this.getLayer();
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
* the updates are done with a fixed FPS with the setInterval
|
|
155
|
-
* below. The anim object only needs the layer reference for
|
|
156
|
-
* redraw
|
|
157
|
-
*/
|
|
152
|
+
// The interval advances frames; the animation callback requests a redraw
|
|
153
|
+
// only when a frame has changed.
|
|
158
154
|
this.anim.setLayers(layer);
|
|
159
155
|
this._setInterval();
|
|
160
156
|
this.anim.start();
|
package/lib/shapes/Text.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Context } from '../Context.ts';
|
|
1
|
+
import type { Context, SceneContext } from '../Context.ts';
|
|
2
2
|
import type { ShapeConfig } from '../Shape.ts';
|
|
3
3
|
import { Shape } from '../Shape.ts';
|
|
4
4
|
import type { GetSet } from '../types.ts';
|
|
@@ -79,8 +79,16 @@ export declare class Text extends Shape<TextConfig> {
|
|
|
79
79
|
_partialStrokeStyle?: string | CanvasGradient | CanvasPattern;
|
|
80
80
|
textWidth: number;
|
|
81
81
|
textHeight: number;
|
|
82
|
+
_baselineShift: number;
|
|
82
83
|
constructor(config?: TextConfig);
|
|
83
|
-
_sceneFunc(context:
|
|
84
|
+
_sceneFunc(context: SceneContext): void;
|
|
85
|
+
_getUnderlineOffset(): number;
|
|
86
|
+
getSelfRect(): {
|
|
87
|
+
x: number;
|
|
88
|
+
y: number;
|
|
89
|
+
width: number;
|
|
90
|
+
height: number;
|
|
91
|
+
};
|
|
84
92
|
_hitFunc(context: Context): void;
|
|
85
93
|
setText(text: string): this;
|
|
86
94
|
getWidth(): any;
|
|
@@ -147,6 +155,6 @@ export declare class Text extends Shape<TextConfig> {
|
|
|
147
155
|
wrap: GetSet<string, this>;
|
|
148
156
|
ellipsis: GetSet<boolean, this>;
|
|
149
157
|
charRenderFunc: GetSet<null | ((props: CharRenderProps) => void), this>;
|
|
150
|
-
width: GetSet<number, this, number | 'auto'>;
|
|
151
|
-
height: GetSet<number, this, number | 'auto'>;
|
|
158
|
+
width: GetSet<number, this, number | 'auto' | null | undefined>;
|
|
159
|
+
height: GetSet<number, this, number | 'auto' | null | undefined>;
|
|
152
160
|
}
|