konva 9.3.11 → 9.3.13
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 -0
- package/konva.js +59 -67
- package/konva.min.js +3 -3
- package/lib/Global.js +1 -1
- package/lib/Shape.d.ts +3 -3
- package/lib/Shape.js +10 -1
- package/lib/shapes/Path.d.ts +12 -3
- package/lib/shapes/Path.js +21 -43
- package/lib/shapes/Text.js +13 -11
- package/lib/shapes/TextPath.d.ts +4 -1
- package/lib/shapes/Transformer.js +3 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,6 +64,10 @@ Konva works in all modern mobile and desktop browsers. A browser need to be capa
|
|
|
64
64
|
|
|
65
65
|
At the current moment `Konva` doesn't work in IE11 directly. To make it work you just need to provide some polyfills such as `Array.prototype.find`, `String.prototype.trimLeft`, `String.prototype.trimRight`, `Array.from`.
|
|
66
66
|
|
|
67
|
+
# Debugging
|
|
68
|
+
|
|
69
|
+
The Chrome inspector simply shows the canvas element. To see the Konva objects and their details, install the konva-dev extension at https://github.com/konvajs/konva-devtool.
|
|
70
|
+
|
|
67
71
|
# Loading and installing Konva
|
|
68
72
|
|
|
69
73
|
Konva supports UMD loading. So you can use all possible variants to load the framework into your project:
|
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v9.3.
|
|
8
|
+
* Konva JavaScript Framework v9.3.13
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Fri Jul 05 2024
|
|
12
12
|
*
|
|
13
13
|
* Original work Copyright (C) 2011 - 2013 by Eric Rowell (KineticJS)
|
|
14
14
|
* Modified work Copyright (C) 2014 - present by Anton Lavrenov (Konva)
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
: {};
|
|
36
36
|
const Konva$2 = {
|
|
37
37
|
_global: glob,
|
|
38
|
-
version: '9.3.
|
|
38
|
+
version: '9.3.13',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -7147,8 +7147,20 @@
|
|
|
7147
7147
|
};
|
|
7148
7148
|
}
|
|
7149
7149
|
getClientRect(config = {}) {
|
|
7150
|
+
// if we have a cached parent, it will use cached transform matrix
|
|
7151
|
+
// but we don't want to that
|
|
7152
|
+
let hasCachedParent = false;
|
|
7153
|
+
let parent = this.getParent();
|
|
7154
|
+
while (parent) {
|
|
7155
|
+
if (parent.isCached()) {
|
|
7156
|
+
hasCachedParent = true;
|
|
7157
|
+
break;
|
|
7158
|
+
}
|
|
7159
|
+
parent = parent.getParent();
|
|
7160
|
+
}
|
|
7150
7161
|
const skipTransform = config.skipTransform;
|
|
7151
|
-
|
|
7162
|
+
// force relative to stage if we have a cached parent
|
|
7163
|
+
const relativeTo = config.relativeTo || (hasCachedParent && this.getStage()) || undefined;
|
|
7152
7164
|
const fillRect = this.getSelfRect();
|
|
7153
7165
|
const applyStroke = !config.skipStroke && this.hasStroke();
|
|
7154
7166
|
const strokeWidth = (applyStroke && this.strokeWidth()) || 0;
|
|
@@ -11458,58 +11470,30 @@
|
|
|
11458
11470
|
return null;
|
|
11459
11471
|
}
|
|
11460
11472
|
static getPointOnLine(dist, P1x, P1y, P2x, P2y, fromX, fromY) {
|
|
11461
|
-
|
|
11462
|
-
|
|
11463
|
-
|
|
11464
|
-
if (
|
|
11465
|
-
|
|
11466
|
-
}
|
|
11467
|
-
var m = (P2y - P1y) / (P2x - P1x + 0.00000001);
|
|
11468
|
-
var run = Math.sqrt((dist * dist) / (1 + m * m));
|
|
11469
|
-
if (P2x < P1x) {
|
|
11470
|
-
run *= -1;
|
|
11473
|
+
fromX = fromX !== null && fromX !== void 0 ? fromX : P1x;
|
|
11474
|
+
fromY = fromY !== null && fromY !== void 0 ? fromY : P1y;
|
|
11475
|
+
const len = this.getLineLength(P1x, P1y, P2x, P2y);
|
|
11476
|
+
if (len < 1e-10) {
|
|
11477
|
+
return { x: P1x, y: P1y };
|
|
11471
11478
|
}
|
|
11472
|
-
var rise = m * run;
|
|
11473
|
-
var pt;
|
|
11474
11479
|
if (P2x === P1x) {
|
|
11475
|
-
//
|
|
11476
|
-
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
11480
|
-
|
|
11481
|
-
|
|
11482
|
-
|
|
11483
|
-
|
|
11484
|
-
|
|
11485
|
-
|
|
11486
|
-
|
|
11487
|
-
|
|
11488
|
-
|
|
11489
|
-
|
|
11490
|
-
|
|
11491
|
-
|
|
11492
|
-
// x: P1x,
|
|
11493
|
-
// y: P1y,
|
|
11494
|
-
// };
|
|
11495
|
-
// }
|
|
11496
|
-
var u = (fromX - P1x) * (P2x - P1x) + (fromY - P1y) * (P2y - P1y);
|
|
11497
|
-
u = u / (len * len);
|
|
11498
|
-
ix = P1x + u * (P2x - P1x);
|
|
11499
|
-
iy = P1y + u * (P2y - P1y);
|
|
11500
|
-
var pRise = this.getLineLength(fromX, fromY, ix, iy);
|
|
11501
|
-
var pRun = Math.sqrt(dist * dist - pRise * pRise);
|
|
11502
|
-
run = Math.sqrt((pRun * pRun) / (1 + m * m));
|
|
11503
|
-
if (P2x < P1x) {
|
|
11504
|
-
run *= -1;
|
|
11505
|
-
}
|
|
11506
|
-
rise = m * run;
|
|
11507
|
-
pt = {
|
|
11508
|
-
x: ix + run,
|
|
11509
|
-
y: iy + rise,
|
|
11510
|
-
};
|
|
11511
|
-
}
|
|
11512
|
-
return pt;
|
|
11480
|
+
// Vertical line
|
|
11481
|
+
return { x: fromX, y: fromY + (P2y > P1y ? dist : -dist) };
|
|
11482
|
+
}
|
|
11483
|
+
const m = (P2y - P1y) / (P2x - P1x);
|
|
11484
|
+
const run = Math.sqrt((dist * dist) / (1 + m * m)) * (P2x < P1x ? -1 : 1);
|
|
11485
|
+
const rise = m * run;
|
|
11486
|
+
if (Math.abs(fromY - P1y - m * (fromX - P1x)) < 1e-10) {
|
|
11487
|
+
return { x: fromX + run, y: fromY + rise };
|
|
11488
|
+
}
|
|
11489
|
+
const u = ((fromX - P1x) * (P2x - P1x) + (fromY - P1y) * (P2y - P1y)) / (len * len);
|
|
11490
|
+
const ix = P1x + u * (P2x - P1x);
|
|
11491
|
+
const iy = P1y + u * (P2y - P1y);
|
|
11492
|
+
const pRise = this.getLineLength(fromX, fromY, ix, iy);
|
|
11493
|
+
const pRun = Math.sqrt(dist * dist - pRise * pRise);
|
|
11494
|
+
const adjustedRun = Math.sqrt((pRun * pRun) / (1 + m * m)) * (P2x < P1x ? -1 : 1);
|
|
11495
|
+
const adjustedRise = m * adjustedRun;
|
|
11496
|
+
return { x: ix + adjustedRun, y: iy + adjustedRise };
|
|
11513
11497
|
}
|
|
11514
11498
|
static getPointOnCubicBezier(pct, P1x, P1y, P2x, P2y, P3x, P3y, P4x, P4y) {
|
|
11515
11499
|
function CB1(t) {
|
|
@@ -14498,26 +14482,29 @@
|
|
|
14498
14482
|
* @returns {Object} { width , height} of measured text
|
|
14499
14483
|
*/
|
|
14500
14484
|
measureSize(text) {
|
|
14485
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
14501
14486
|
var _context = getDummyContext(), fontSize = this.fontSize(), metrics;
|
|
14502
14487
|
_context.save();
|
|
14503
14488
|
_context.font = this._getContextFont();
|
|
14504
14489
|
metrics = _context.measureText(text);
|
|
14505
14490
|
_context.restore();
|
|
14491
|
+
// Scale the fallback values based on the provided fontSize compared to the sample size (100 in your new case)
|
|
14492
|
+
const scaleFactor = fontSize / 100;
|
|
14493
|
+
// Note, fallback values are from chrome browser with 100px font size and font-family "Arial"
|
|
14506
14494
|
return {
|
|
14507
|
-
|
|
14508
|
-
|
|
14509
|
-
|
|
14510
|
-
|
|
14511
|
-
|
|
14512
|
-
|
|
14513
|
-
|
|
14514
|
-
|
|
14515
|
-
|
|
14516
|
-
|
|
14517
|
-
|
|
14518
|
-
ideographicBaseline: metrics.ideographicBaseline,
|
|
14495
|
+
actualBoundingBoxAscent: (_a = metrics.actualBoundingBoxAscent) !== null && _a !== void 0 ? _a : 71.58203125 * scaleFactor,
|
|
14496
|
+
actualBoundingBoxDescent: (_b = metrics.actualBoundingBoxDescent) !== null && _b !== void 0 ? _b : 0, // Remains zero as there is no descent in the provided metrics
|
|
14497
|
+
actualBoundingBoxLeft: (_c = metrics.actualBoundingBoxLeft) !== null && _c !== void 0 ? _c : -7.421875 * scaleFactor,
|
|
14498
|
+
actualBoundingBoxRight: (_d = metrics.actualBoundingBoxRight) !== null && _d !== void 0 ? _d : 75.732421875 * scaleFactor,
|
|
14499
|
+
alphabeticBaseline: (_e = metrics.alphabeticBaseline) !== null && _e !== void 0 ? _e : 0, // Remains zero as it's typically relative to the baseline itself
|
|
14500
|
+
emHeightAscent: (_f = metrics.emHeightAscent) !== null && _f !== void 0 ? _f : 100 * scaleFactor,
|
|
14501
|
+
emHeightDescent: (_g = metrics.emHeightDescent) !== null && _g !== void 0 ? _g : -20 * scaleFactor,
|
|
14502
|
+
fontBoundingBoxAscent: (_h = metrics.fontBoundingBoxAscent) !== null && _h !== void 0 ? _h : 91 * scaleFactor,
|
|
14503
|
+
fontBoundingBoxDescent: (_j = metrics.fontBoundingBoxDescent) !== null && _j !== void 0 ? _j : 21 * scaleFactor,
|
|
14504
|
+
hangingBaseline: (_k = metrics.hangingBaseline) !== null && _k !== void 0 ? _k : 72.80000305175781 * scaleFactor,
|
|
14505
|
+
ideographicBaseline: (_l = metrics.ideographicBaseline) !== null && _l !== void 0 ? _l : -21 * scaleFactor,
|
|
14519
14506
|
width: metrics.width,
|
|
14520
|
-
height: fontSize,
|
|
14507
|
+
height: fontSize, // Typically set to the font size
|
|
14521
14508
|
};
|
|
14522
14509
|
}
|
|
14523
14510
|
_getContextFont() {
|
|
@@ -16027,6 +16014,11 @@
|
|
|
16027
16014
|
});
|
|
16028
16015
|
}
|
|
16029
16016
|
_handleMouseDown(e) {
|
|
16017
|
+
// do nothing if we already transforming
|
|
16018
|
+
// that is possible to trigger with multitouch
|
|
16019
|
+
if (this._transforming) {
|
|
16020
|
+
return;
|
|
16021
|
+
}
|
|
16030
16022
|
this._movingAnchorName = e.target.name().split(' ')[0];
|
|
16031
16023
|
var attrs = this._getNodeRect();
|
|
16032
16024
|
var width = attrs.width;
|