konva 8.3.1 → 8.3.4
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 +3 -0
- package/cmj/Node.js +5 -5
- package/cmj/Shape.js +15 -16
- package/cmj/Util.js +6 -1
- package/cmj/index-node.js +1 -0
- package/cmj/shapes/Arc.js +16 -24
- package/cmj/shapes/Image.d.ts +1 -1
- package/cmj/shapes/Image.js +2 -1
- package/cmj/shapes/Path.d.ts +2 -2
- package/cmj/shapes/Path.js +4 -4
- package/cmj/shapes/Text.d.ts +1 -0
- package/cmj/shapes/Text.js +10 -3
- package/cmj/shapes/TextPath.js +1 -1
- package/cmj/shapes/Transformer.js +2 -2
- package/konva.js +80 -65
- package/konva.min.js +3 -3
- package/lib/Animation.js +0 -1
- package/lib/Canvas.js +0 -1
- package/lib/Container.js +0 -1
- package/lib/Context.js +0 -1
- package/lib/Core.js +0 -1
- package/lib/DragAndDrop.js +0 -1
- package/lib/Factory.js +0 -1
- package/lib/FastLayer.js +0 -1
- package/lib/Global.js +1 -2
- package/lib/Group.js +0 -1
- package/lib/Layer.js +0 -1
- package/lib/Node.js +5 -6
- package/lib/PointerEvents.js +0 -1
- package/lib/Shape.js +15 -17
- package/lib/Stage.js +0 -1
- package/lib/Tween.js +0 -1
- package/lib/Util.js +6 -2
- package/lib/Validators.js +0 -1
- package/lib/_CoreInternals.js +0 -1
- package/lib/_FullInternals.js +0 -1
- package/lib/filters/Blur.js +0 -1
- package/lib/filters/Brighten.js +0 -1
- package/lib/filters/Contrast.js +0 -1
- package/lib/filters/Emboss.js +0 -1
- package/lib/filters/Enhance.js +0 -1
- package/lib/filters/Grayscale.js +0 -1
- package/lib/filters/HSL.js +0 -1
- package/lib/filters/HSV.js +0 -1
- package/lib/filters/Invert.js +0 -1
- package/lib/filters/Kaleidoscope.js +0 -1
- package/lib/filters/Mask.js +0 -1
- package/lib/filters/Noise.js +0 -1
- package/lib/filters/Pixelate.js +0 -1
- package/lib/filters/Posterize.js +0 -1
- package/lib/filters/RGB.js +0 -1
- package/lib/filters/RGBA.js +0 -1
- package/lib/filters/Sepia.js +0 -1
- package/lib/filters/Solarize.js +0 -1
- package/lib/filters/Threshold.js +0 -1
- package/lib/index-node.js +1 -1
- package/lib/index.js +0 -1
- package/lib/shapes/Arc.js +16 -25
- package/lib/shapes/Arrow.js +0 -1
- package/lib/shapes/Circle.js +0 -1
- package/lib/shapes/Ellipse.js +0 -1
- package/lib/shapes/Image.d.ts +1 -1
- package/lib/shapes/Image.js +2 -2
- package/lib/shapes/Label.js +0 -1
- package/lib/shapes/Line.js +0 -1
- package/lib/shapes/Path.d.ts +2 -2
- package/lib/shapes/Path.js +4 -5
- package/lib/shapes/Rect.js +0 -1
- package/lib/shapes/RegularPolygon.js +0 -1
- package/lib/shapes/Ring.js +0 -1
- package/lib/shapes/Sprite.js +0 -1
- package/lib/shapes/Star.js +0 -1
- package/lib/shapes/Text.d.ts +1 -0
- package/lib/shapes/Text.js +10 -4
- package/lib/shapes/TextPath.js +1 -2
- package/lib/shapes/Transformer.js +2 -3
- package/lib/shapes/Wedge.js +0 -1
- package/lib/types.js +0 -1
- package/package.json +15 -14
- package/lib/Animation.js.map +0 -1
- package/lib/Canvas.js.map +0 -1
- package/lib/Container.js.map +0 -1
- package/lib/Context.js.map +0 -1
- package/lib/Core.js.map +0 -1
- package/lib/DragAndDrop.js.map +0 -1
- package/lib/Factory.js.map +0 -1
- package/lib/FastLayer.js.map +0 -1
- package/lib/Global.js.map +0 -1
- package/lib/Group.js.map +0 -1
- package/lib/Layer.js.map +0 -1
- package/lib/Node.js.map +0 -1
- package/lib/PointerEvents.js.map +0 -1
- package/lib/Shape.js.map +0 -1
- package/lib/Stage.js.map +0 -1
- package/lib/Tween.js.map +0 -1
- package/lib/Util.js.map +0 -1
- package/lib/Validators.js.map +0 -1
- package/lib/_CoreInternals.js.map +0 -1
- package/lib/_FullInternals.js.map +0 -1
- package/lib/filters/Blur.js.map +0 -1
- package/lib/filters/Brighten.js.map +0 -1
- package/lib/filters/Contrast.js.map +0 -1
- package/lib/filters/Emboss.js.map +0 -1
- package/lib/filters/Enhance.js.map +0 -1
- package/lib/filters/Grayscale.js.map +0 -1
- package/lib/filters/HSL.js.map +0 -1
- package/lib/filters/HSV.js.map +0 -1
- package/lib/filters/Invert.js.map +0 -1
- package/lib/filters/Kaleidoscope.js.map +0 -1
- package/lib/filters/Mask.js.map +0 -1
- package/lib/filters/Noise.js.map +0 -1
- package/lib/filters/Pixelate.js.map +0 -1
- package/lib/filters/Posterize.js.map +0 -1
- package/lib/filters/RGB.js.map +0 -1
- package/lib/filters/RGBA.js.map +0 -1
- package/lib/filters/Sepia.js.map +0 -1
- package/lib/filters/Solarize.js.map +0 -1
- package/lib/filters/Threshold.js.map +0 -1
- package/lib/index-node.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/shapes/Arc.js.map +0 -1
- package/lib/shapes/Arrow.js.map +0 -1
- package/lib/shapes/Circle.js.map +0 -1
- package/lib/shapes/Ellipse.js.map +0 -1
- package/lib/shapes/Image.js.map +0 -1
- package/lib/shapes/Label.js.map +0 -1
- package/lib/shapes/Line.js.map +0 -1
- package/lib/shapes/Path.js.map +0 -1
- package/lib/shapes/Rect.js.map +0 -1
- package/lib/shapes/RegularPolygon.js.map +0 -1
- package/lib/shapes/Ring.js.map +0 -1
- package/lib/shapes/Sprite.js.map +0 -1
- package/lib/shapes/Star.js.map +0 -1
- package/lib/shapes/Text.js.map +0 -1
- package/lib/shapes/TextPath.js.map +0 -1
- package/lib/shapes/Transformer.js.map +0 -1
- package/lib/shapes/Wedge.js.map +0 -1
- package/lib/types.js.map +0 -1
package/README.md
CHANGED
|
@@ -150,6 +150,9 @@ const Konva = require('konva/cmj').default;
|
|
|
150
150
|
|
|
151
151
|
# Backers
|
|
152
152
|
|
|
153
|
+

|
|
154
|
+

|
|
155
|
+
|
|
153
156
|
- [myposter GmbH](https://www.myposter.de/)
|
|
154
157
|
- [queue.gg](https://queue.gg/)
|
|
155
158
|
|
package/cmj/Node.js
CHANGED
|
@@ -102,13 +102,13 @@ class Node {
|
|
|
102
102
|
relativeTo: this.getParent(),
|
|
103
103
|
});
|
|
104
104
|
}
|
|
105
|
-
var width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? rect.x : conf.x, y = conf.y === undefined ? rect.y : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
|
|
105
|
+
var width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? Math.floor(rect.x) : conf.x, y = conf.y === undefined ? Math.floor(rect.y) : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
|
|
106
106
|
if (!width || !height) {
|
|
107
107
|
Util_1.Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
|
|
108
108
|
return;
|
|
109
109
|
}
|
|
110
|
-
width += offset * 2;
|
|
111
|
-
height += offset * 2;
|
|
110
|
+
width += offset * 2 + 1;
|
|
111
|
+
height += offset * 2 + 1;
|
|
112
112
|
x -= offset;
|
|
113
113
|
y -= offset;
|
|
114
114
|
var cachedSceneCanvas = new Canvas_1.SceneCanvas({
|
|
@@ -1293,8 +1293,8 @@ class Node {
|
|
|
1293
1293
|
const screenRect = {
|
|
1294
1294
|
x: -margin.x,
|
|
1295
1295
|
y: -margin.y,
|
|
1296
|
-
width: stage.width() + margin.x,
|
|
1297
|
-
height: stage.height() + margin.y,
|
|
1296
|
+
width: stage.width() + 2 * margin.x,
|
|
1297
|
+
height: stage.height() + 2 * margin.y,
|
|
1298
1298
|
};
|
|
1299
1299
|
return Util_1.Util.haveIntersection(screenRect, this.getClientRect());
|
|
1300
1300
|
}
|
package/cmj/Shape.js
CHANGED
|
@@ -101,14 +101,17 @@ class Shape extends Node_1.Node {
|
|
|
101
101
|
tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
|
|
102
102
|
tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
|
|
103
103
|
const m = tr.getMatrix();
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
104
|
+
const matrix = typeof DOMMatrix === 'undefined'
|
|
105
|
+
? {
|
|
106
|
+
a: m[0],
|
|
107
|
+
b: m[1],
|
|
108
|
+
c: m[2],
|
|
109
|
+
d: m[3],
|
|
110
|
+
e: m[4],
|
|
111
|
+
f: m[5],
|
|
112
|
+
}
|
|
113
|
+
: new DOMMatrix(m);
|
|
114
|
+
pattern.setTransform(matrix);
|
|
112
115
|
}
|
|
113
116
|
return pattern;
|
|
114
117
|
}
|
|
@@ -273,17 +276,13 @@ class Shape extends Node_1.Node {
|
|
|
273
276
|
const blurRadius = (applyShadow && this.shadowBlur()) || 0;
|
|
274
277
|
const width = preWidth + blurRadius * 2;
|
|
275
278
|
const height = preHeight + blurRadius * 2;
|
|
276
|
-
let roundingOffset = 0;
|
|
277
|
-
if (Math.round(strokeWidth / 2) !== strokeWidth / 2) {
|
|
278
|
-
roundingOffset = 1;
|
|
279
|
-
}
|
|
280
279
|
const rect = {
|
|
281
|
-
width: width
|
|
282
|
-
height: height
|
|
283
|
-
x: -
|
|
280
|
+
width: width,
|
|
281
|
+
height: height,
|
|
282
|
+
x: -(strokeWidth / 2 + blurRadius) +
|
|
284
283
|
Math.min(shadowOffsetX, 0) +
|
|
285
284
|
fillRect.x,
|
|
286
|
-
y: -
|
|
285
|
+
y: -(strokeWidth / 2 + blurRadius) +
|
|
287
286
|
Math.min(shadowOffsetY, 0) +
|
|
288
287
|
fillRect.y,
|
|
289
288
|
};
|
package/cmj/Util.js
CHANGED
|
@@ -478,7 +478,12 @@ exports.Util = {
|
|
|
478
478
|
_rgbaColorToRGBA(str) {
|
|
479
479
|
if (str.indexOf('rgba(') === 0) {
|
|
480
480
|
str = str.match(/rgba\(([^)]+)\)/)[1];
|
|
481
|
-
var parts = str.split(/ *, */).map(
|
|
481
|
+
var parts = str.split(/ *, */).map((n, index) => {
|
|
482
|
+
if (n.slice(-1) === '%') {
|
|
483
|
+
return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
|
|
484
|
+
}
|
|
485
|
+
return Number(n);
|
|
486
|
+
});
|
|
482
487
|
return {
|
|
483
488
|
r: parts[0],
|
|
484
489
|
g: parts[1],
|
package/cmj/index-node.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const _FullInternals_1 = require("./_FullInternals");
|
|
4
4
|
const Canvas = require("canvas");
|
|
5
5
|
const canvas = Canvas['default'] || Canvas;
|
|
6
|
+
global.DOMMatrix = canvas.DOMMatrix;
|
|
6
7
|
const isNode = typeof global.document === 'undefined';
|
|
7
8
|
if (isNode) {
|
|
8
9
|
_FullInternals_1.Konva.Util['createCanvasElement'] = () => {
|
package/cmj/shapes/Arc.js
CHANGED
|
@@ -28,31 +28,23 @@ class Arc extends Shape_1.Shape {
|
|
|
28
28
|
this.outerRadius(height / 2);
|
|
29
29
|
}
|
|
30
30
|
getSelfRect() {
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
for (let i = 0; i < end; i += inc) {
|
|
44
|
-
xs.push(Math.cos(i));
|
|
45
|
-
ys.push(Math.sin(i));
|
|
46
|
-
}
|
|
47
|
-
const minX = Math.round(radius * Math.min(...xs));
|
|
48
|
-
const maxX = Math.round(radius * Math.max(...xs));
|
|
49
|
-
const minY = Math.round(radius * Math.min(...ys));
|
|
50
|
-
const maxY = Math.round(radius * Math.max(...ys));
|
|
31
|
+
const innerRadius = this.innerRadius();
|
|
32
|
+
const outerRadius = this.outerRadius();
|
|
33
|
+
const clockwise = this.clockwise();
|
|
34
|
+
const angle = Global_1.Konva.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
|
35
|
+
const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
|
|
36
|
+
const boundRightRatio = 1;
|
|
37
|
+
const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), (3 * Math.PI) / 2));
|
|
38
|
+
const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
|
|
39
|
+
const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
|
|
40
|
+
const boundRight = boundRightRatio * (boundRightRatio > 0 ? outerRadius : innerRadius);
|
|
41
|
+
const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
|
|
42
|
+
const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
|
|
51
43
|
return {
|
|
52
|
-
x:
|
|
53
|
-
y:
|
|
54
|
-
width:
|
|
55
|
-
height:
|
|
44
|
+
x: boundLeft,
|
|
45
|
+
y: clockwise ? -1 * boundBottom : boundTop,
|
|
46
|
+
width: boundRight - boundLeft,
|
|
47
|
+
height: boundBottom - boundTop,
|
|
56
48
|
};
|
|
57
49
|
}
|
|
58
50
|
}
|
package/cmj/shapes/Image.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ export declare class Image extends Shape<ImageConfig> {
|
|
|
13
13
|
_hitFunc(context: any): void;
|
|
14
14
|
getWidth(): any;
|
|
15
15
|
getHeight(): any;
|
|
16
|
-
static fromURL(url: any, callback: any): void;
|
|
16
|
+
static fromURL(url: any, callback: any, onError?: any): void;
|
|
17
17
|
image: GetSet<CanvasImageSource | undefined, this>;
|
|
18
18
|
crop: GetSet<IRect, this>;
|
|
19
19
|
cropX: GetSet<number, this>;
|
package/cmj/shapes/Image.js
CHANGED
|
@@ -81,7 +81,7 @@ class Image extends Shape_1.Shape {
|
|
|
81
81
|
var _a, _b;
|
|
82
82
|
return (_a = this.attrs.height) !== null && _a !== void 0 ? _a : (_b = this.image()) === null || _b === void 0 ? void 0 : _b.height;
|
|
83
83
|
}
|
|
84
|
-
static fromURL(url, callback) {
|
|
84
|
+
static fromURL(url, callback, onError = null) {
|
|
85
85
|
var img = Util_1.Util.createImageElement();
|
|
86
86
|
img.onload = function () {
|
|
87
87
|
var image = new Image({
|
|
@@ -89,6 +89,7 @@ class Image extends Shape_1.Shape {
|
|
|
89
89
|
});
|
|
90
90
|
callback(image);
|
|
91
91
|
};
|
|
92
|
+
img.onerror = onError;
|
|
92
93
|
img.crossOrigin = 'Anonymous';
|
|
93
94
|
img.src = url;
|
|
94
95
|
}
|
package/cmj/shapes/Path.d.ts
CHANGED
package/cmj/shapes/Path.js
CHANGED
|
@@ -120,10 +120,10 @@ class Path extends Shape_1.Shape {
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
return {
|
|
123
|
-
x:
|
|
124
|
-
y:
|
|
125
|
-
width:
|
|
126
|
-
height:
|
|
123
|
+
x: minX,
|
|
124
|
+
y: minY,
|
|
125
|
+
width: maxX - minX,
|
|
126
|
+
height: maxY - minY,
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
129
|
getLength() {
|
package/cmj/shapes/Text.d.ts
CHANGED
package/cmj/shapes/Text.js
CHANGED
|
@@ -96,7 +96,7 @@ class Text extends Shape_1.Shape {
|
|
|
96
96
|
for (n = 0; n < textArrLen; n++) {
|
|
97
97
|
var lineTranslateX = 0;
|
|
98
98
|
var lineTranslateY = 0;
|
|
99
|
-
var obj = textArr[n], text = obj.text, width = obj.width, lastLine =
|
|
99
|
+
var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, oneWord, lineWidth;
|
|
100
100
|
context.save();
|
|
101
101
|
if (align === RIGHT) {
|
|
102
102
|
lineTranslateX += totalWidth - width - padding * 2;
|
|
@@ -141,7 +141,7 @@ class Text extends Shape_1.Shape {
|
|
|
141
141
|
var array = stringToArray(text);
|
|
142
142
|
for (var li = 0; li < array.length; li++) {
|
|
143
143
|
var letter = array[li];
|
|
144
|
-
if (letter === ' ' &&
|
|
144
|
+
if (letter === ' ' && !lastLine && align === JUSTIFY) {
|
|
145
145
|
lineTranslateX += (totalWidth - padding * 2 - width) / spacesNumber;
|
|
146
146
|
}
|
|
147
147
|
this._partialTextX = lineTranslateX;
|
|
@@ -221,7 +221,11 @@ class Text extends Shape_1.Shape {
|
|
|
221
221
|
line = line.trim();
|
|
222
222
|
}
|
|
223
223
|
var width = this._getTextWidth(line);
|
|
224
|
-
return this.textArr.push({
|
|
224
|
+
return this.textArr.push({
|
|
225
|
+
text: line,
|
|
226
|
+
width: width,
|
|
227
|
+
lastInParagraph: false,
|
|
228
|
+
});
|
|
225
229
|
}
|
|
226
230
|
_getTextWidth(text) {
|
|
227
231
|
var letterSpacing = this.letterSpacing();
|
|
@@ -314,6 +318,9 @@ class Text extends Shape_1.Shape {
|
|
|
314
318
|
if (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx) {
|
|
315
319
|
break;
|
|
316
320
|
}
|
|
321
|
+
if (this.textArr[this.textArr.length - 1]) {
|
|
322
|
+
this.textArr[this.textArr.length - 1].lastInParagraph = true;
|
|
323
|
+
}
|
|
317
324
|
}
|
|
318
325
|
this.textHeight = fontSize;
|
|
319
326
|
this.textWidth = textWidth;
|
package/cmj/shapes/TextPath.js
CHANGED
|
@@ -25,7 +25,7 @@ class TextPath extends Shape_1.Shape {
|
|
|
25
25
|
this.dataArray = Path_1.Path.parsePathData(this.attrs.data);
|
|
26
26
|
this._setTextData();
|
|
27
27
|
});
|
|
28
|
-
this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva', this._setTextData);
|
|
28
|
+
this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData);
|
|
29
29
|
this._setTextData();
|
|
30
30
|
}
|
|
31
31
|
_sceneFunc(context) {
|
|
@@ -449,9 +449,9 @@ class Transformer extends Group_1.Group {
|
|
|
449
449
|
x: pos.x - ap.x,
|
|
450
450
|
y: pos.y - ap.y,
|
|
451
451
|
};
|
|
452
|
-
this._fire('transformstart', { evt: e, target: this.getNode() });
|
|
452
|
+
this._fire('transformstart', { evt: e.evt, target: this.getNode() });
|
|
453
453
|
this._nodes.forEach((target) => {
|
|
454
|
-
target._fire('transformstart', { evt: e, target });
|
|
454
|
+
target._fire('transformstart', { evt: e.evt, target });
|
|
455
455
|
});
|
|
456
456
|
}
|
|
457
457
|
_handleMouseMove(e) {
|
package/konva.js
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
})(this, (function () { 'use strict';
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
|
-
* Konva JavaScript Framework v8.3.
|
|
8
|
+
* Konva JavaScript Framework v8.3.4
|
|
9
9
|
* http://konvajs.org/
|
|
10
10
|
* Licensed under the MIT
|
|
11
|
-
* Date:
|
|
11
|
+
* Date: Sun Mar 13 2022
|
|
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: '8.3.
|
|
38
|
+
version: '8.3.4',
|
|
39
39
|
isBrowser: detectBrowser(),
|
|
40
40
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
41
41
|
dblClickWindow: 400,
|
|
@@ -794,7 +794,12 @@
|
|
|
794
794
|
_rgbaColorToRGBA(str) {
|
|
795
795
|
if (str.indexOf('rgba(') === 0) {
|
|
796
796
|
str = str.match(/rgba\(([^)]+)\)/)[1];
|
|
797
|
-
var parts = str.split(/ *, */).map(
|
|
797
|
+
var parts = str.split(/ *, */).map((n, index) => {
|
|
798
|
+
if (n.slice(-1) === '%') {
|
|
799
|
+
return index === 3 ? parseInt(n) / 100 : (parseInt(n) / 100) * 255;
|
|
800
|
+
}
|
|
801
|
+
return Number(n);
|
|
802
|
+
});
|
|
798
803
|
return {
|
|
799
804
|
r: parts[0],
|
|
800
805
|
g: parts[1],
|
|
@@ -2594,15 +2599,26 @@
|
|
|
2594
2599
|
relativeTo: this.getParent(),
|
|
2595
2600
|
});
|
|
2596
2601
|
}
|
|
2597
|
-
var width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? rect.x : conf.x, y = conf.y === undefined ? rect.y : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
|
|
2602
|
+
var width = Math.ceil(conf.width || rect.width), height = Math.ceil(conf.height || rect.height), pixelRatio = conf.pixelRatio, x = conf.x === undefined ? Math.floor(rect.x) : conf.x, y = conf.y === undefined ? Math.floor(rect.y) : conf.y, offset = conf.offset || 0, drawBorder = conf.drawBorder || false, hitCanvasPixelRatio = conf.hitCanvasPixelRatio || 1;
|
|
2598
2603
|
if (!width || !height) {
|
|
2599
2604
|
Util.error('Can not cache the node. Width or height of the node equals 0. Caching is skipped.');
|
|
2600
2605
|
return;
|
|
2601
2606
|
}
|
|
2602
|
-
|
|
2603
|
-
|
|
2607
|
+
// let's just add 1 pixel extra,
|
|
2608
|
+
// because using Math.floor on x, y position may shift drawing
|
|
2609
|
+
width += offset * 2 + 1;
|
|
2610
|
+
height += offset * 2 + 1;
|
|
2604
2611
|
x -= offset;
|
|
2605
2612
|
y -= offset;
|
|
2613
|
+
// if (Math.floor(x) < x) {
|
|
2614
|
+
// x = Math.floor(x);
|
|
2615
|
+
// // width += 1;
|
|
2616
|
+
// }
|
|
2617
|
+
// if (Math.floor(y) < y) {
|
|
2618
|
+
// y = Math.floor(y);
|
|
2619
|
+
// // height += 1;
|
|
2620
|
+
// }
|
|
2621
|
+
// console.log({ x, y, width, height }, rect);
|
|
2606
2622
|
var cachedSceneCanvas = new SceneCanvas({
|
|
2607
2623
|
pixelRatio: pixelRatio,
|
|
2608
2624
|
width: width,
|
|
@@ -4499,8 +4515,8 @@
|
|
|
4499
4515
|
const screenRect = {
|
|
4500
4516
|
x: -margin.x,
|
|
4501
4517
|
y: -margin.y,
|
|
4502
|
-
width: stage.width() + margin.x,
|
|
4503
|
-
height: stage.height() + margin.y,
|
|
4518
|
+
width: stage.width() + 2 * margin.x,
|
|
4519
|
+
height: stage.height() + 2 * margin.y,
|
|
4504
4520
|
};
|
|
4505
4521
|
return Util.haveIntersection(screenRect, this.getClientRect());
|
|
4506
4522
|
}
|
|
@@ -6699,14 +6715,17 @@
|
|
|
6699
6715
|
tr.scale(this.fillPatternScaleX(), this.fillPatternScaleY());
|
|
6700
6716
|
tr.translate(-1 * this.fillPatternOffsetX(), -1 * this.fillPatternOffsetY());
|
|
6701
6717
|
const m = tr.getMatrix();
|
|
6702
|
-
|
|
6703
|
-
|
|
6704
|
-
|
|
6705
|
-
|
|
6706
|
-
|
|
6707
|
-
|
|
6708
|
-
|
|
6709
|
-
|
|
6718
|
+
const matrix = typeof DOMMatrix === 'undefined'
|
|
6719
|
+
? {
|
|
6720
|
+
a: m[0],
|
|
6721
|
+
b: m[1],
|
|
6722
|
+
c: m[2],
|
|
6723
|
+
d: m[3],
|
|
6724
|
+
e: m[4],
|
|
6725
|
+
f: m[5], // Vertical translation (moving).
|
|
6726
|
+
}
|
|
6727
|
+
: new DOMMatrix(m);
|
|
6728
|
+
pattern.setTransform(matrix);
|
|
6710
6729
|
}
|
|
6711
6730
|
return pattern;
|
|
6712
6731
|
}
|
|
@@ -6928,20 +6947,13 @@
|
|
|
6928
6947
|
const blurRadius = (applyShadow && this.shadowBlur()) || 0;
|
|
6929
6948
|
const width = preWidth + blurRadius * 2;
|
|
6930
6949
|
const height = preHeight + blurRadius * 2;
|
|
6931
|
-
// if stroke, for example = 3
|
|
6932
|
-
// we need to set x to 1.5, but after Math.round it will be 2
|
|
6933
|
-
// as we have additional offset we need to increase width and height by 1 pixel
|
|
6934
|
-
let roundingOffset = 0;
|
|
6935
|
-
if (Math.round(strokeWidth / 2) !== strokeWidth / 2) {
|
|
6936
|
-
roundingOffset = 1;
|
|
6937
|
-
}
|
|
6938
6950
|
const rect = {
|
|
6939
|
-
width: width
|
|
6940
|
-
height: height
|
|
6941
|
-
x: -
|
|
6951
|
+
width: width,
|
|
6952
|
+
height: height,
|
|
6953
|
+
x: -(strokeWidth / 2 + blurRadius) +
|
|
6942
6954
|
Math.min(shadowOffsetX, 0) +
|
|
6943
6955
|
fillRect.x,
|
|
6944
|
-
y: -
|
|
6956
|
+
y: -(strokeWidth / 2 + blurRadius) +
|
|
6945
6957
|
Math.min(shadowOffsetY, 0) +
|
|
6946
6958
|
fillRect.y,
|
|
6947
6959
|
};
|
|
@@ -9721,29 +9733,23 @@
|
|
|
9721
9733
|
this.outerRadius(height / 2);
|
|
9722
9734
|
}
|
|
9723
9735
|
getSelfRect() {
|
|
9724
|
-
const
|
|
9725
|
-
const
|
|
9726
|
-
const
|
|
9727
|
-
const
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
const
|
|
9733
|
-
const
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
ys.push(Math.sin(i));
|
|
9737
|
-
}
|
|
9738
|
-
const minX = Math.round(radius * Math.min(...xs));
|
|
9739
|
-
const maxX = Math.round(radius * Math.max(...xs));
|
|
9740
|
-
const minY = Math.round(radius * Math.min(...ys));
|
|
9741
|
-
const maxY = Math.round(radius * Math.max(...ys));
|
|
9736
|
+
const innerRadius = this.innerRadius();
|
|
9737
|
+
const outerRadius = this.outerRadius();
|
|
9738
|
+
const clockwise = this.clockwise();
|
|
9739
|
+
const angle = Konva$2.getAngle(clockwise ? 360 - this.angle() : this.angle());
|
|
9740
|
+
const boundLeftRatio = Math.cos(Math.min(angle, Math.PI));
|
|
9741
|
+
const boundRightRatio = 1;
|
|
9742
|
+
const boundTopRatio = Math.sin(Math.min(Math.max(Math.PI, angle), (3 * Math.PI) / 2));
|
|
9743
|
+
const boundBottomRatio = Math.sin(Math.min(angle, Math.PI / 2));
|
|
9744
|
+
const boundLeft = boundLeftRatio * (boundLeftRatio > 0 ? innerRadius : outerRadius);
|
|
9745
|
+
const boundRight = boundRightRatio * (outerRadius );
|
|
9746
|
+
const boundTop = boundTopRatio * (boundTopRatio > 0 ? innerRadius : outerRadius);
|
|
9747
|
+
const boundBottom = boundBottomRatio * (boundBottomRatio > 0 ? outerRadius : innerRadius);
|
|
9742
9748
|
return {
|
|
9743
|
-
x:
|
|
9744
|
-
y:
|
|
9745
|
-
width:
|
|
9746
|
-
height:
|
|
9749
|
+
x: boundLeft,
|
|
9750
|
+
y: clockwise ? -1 * boundBottom : boundTop,
|
|
9751
|
+
width: boundRight - boundLeft,
|
|
9752
|
+
height: boundBottom - boundTop,
|
|
9747
9753
|
};
|
|
9748
9754
|
}
|
|
9749
9755
|
}
|
|
@@ -10342,10 +10348,10 @@
|
|
|
10342
10348
|
}
|
|
10343
10349
|
}
|
|
10344
10350
|
return {
|
|
10345
|
-
x:
|
|
10346
|
-
y:
|
|
10347
|
-
width:
|
|
10348
|
-
height:
|
|
10351
|
+
x: minX,
|
|
10352
|
+
y: minY,
|
|
10353
|
+
width: maxX - minX,
|
|
10354
|
+
height: maxY - minY,
|
|
10349
10355
|
};
|
|
10350
10356
|
}
|
|
10351
10357
|
/**
|
|
@@ -11678,6 +11684,7 @@
|
|
|
11678
11684
|
* @memberof Konva.Image
|
|
11679
11685
|
* @param {String} url image source
|
|
11680
11686
|
* @param {Function} callback with Konva.Image instance as first argument
|
|
11687
|
+
* @param {Function} onError optional error handler
|
|
11681
11688
|
* @example
|
|
11682
11689
|
* Konva.Image.fromURL(imageURL, function(image){
|
|
11683
11690
|
* // image is Konva.Image instance
|
|
@@ -11685,7 +11692,7 @@
|
|
|
11685
11692
|
* layer.draw();
|
|
11686
11693
|
* });
|
|
11687
11694
|
*/
|
|
11688
|
-
static fromURL(url, callback) {
|
|
11695
|
+
static fromURL(url, callback, onError = null) {
|
|
11689
11696
|
var img = Util.createImageElement();
|
|
11690
11697
|
img.onload = function () {
|
|
11691
11698
|
var image = new Image({
|
|
@@ -11693,6 +11700,7 @@
|
|
|
11693
11700
|
});
|
|
11694
11701
|
callback(image);
|
|
11695
11702
|
};
|
|
11703
|
+
img.onerror = onError;
|
|
11696
11704
|
img.crossOrigin = 'Anonymous';
|
|
11697
11705
|
img.src = url;
|
|
11698
11706
|
}
|
|
@@ -13299,7 +13307,7 @@
|
|
|
13299
13307
|
for (n = 0; n < textArrLen; n++) {
|
|
13300
13308
|
var lineTranslateX = 0;
|
|
13301
13309
|
var lineTranslateY = 0;
|
|
13302
|
-
var obj = textArr[n], text = obj.text, width = obj.width, lastLine =
|
|
13310
|
+
var obj = textArr[n], text = obj.text, width = obj.width, lastLine = obj.lastInParagraph, spacesNumber, oneWord, lineWidth;
|
|
13303
13311
|
// horizontal alignment
|
|
13304
13312
|
context.save();
|
|
13305
13313
|
if (align === RIGHT) {
|
|
@@ -13349,7 +13357,7 @@
|
|
|
13349
13357
|
for (var li = 0; li < array.length; li++) {
|
|
13350
13358
|
var letter = array[li];
|
|
13351
13359
|
// skip justify for the last line
|
|
13352
|
-
if (letter === ' ' &&
|
|
13360
|
+
if (letter === ' ' && !lastLine && align === JUSTIFY) {
|
|
13353
13361
|
lineTranslateX += (totalWidth - padding * 2 - width) / spacesNumber;
|
|
13354
13362
|
// context.translate(
|
|
13355
13363
|
// Math.floor((totalWidth - padding * 2 - width) / spacesNumber),
|
|
@@ -13448,7 +13456,11 @@
|
|
|
13448
13456
|
line = line.trim();
|
|
13449
13457
|
}
|
|
13450
13458
|
var width = this._getTextWidth(line);
|
|
13451
|
-
return this.textArr.push({
|
|
13459
|
+
return this.textArr.push({
|
|
13460
|
+
text: line,
|
|
13461
|
+
width: width,
|
|
13462
|
+
lastInParagraph: false,
|
|
13463
|
+
});
|
|
13452
13464
|
}
|
|
13453
13465
|
_getTextWidth(text) {
|
|
13454
13466
|
var letterSpacing = this.letterSpacing();
|
|
@@ -13570,6 +13582,9 @@
|
|
|
13570
13582
|
if (fixedHeight && currentHeightPx + lineHeightPx > maxHeightPx) {
|
|
13571
13583
|
break;
|
|
13572
13584
|
}
|
|
13585
|
+
if (this.textArr[this.textArr.length - 1]) {
|
|
13586
|
+
this.textArr[this.textArr.length - 1].lastInParagraph = true;
|
|
13587
|
+
}
|
|
13573
13588
|
}
|
|
13574
13589
|
this.textHeight = fontSize;
|
|
13575
13590
|
// var maxTextWidth = 0;
|
|
@@ -13956,7 +13971,7 @@
|
|
|
13956
13971
|
this._setTextData();
|
|
13957
13972
|
});
|
|
13958
13973
|
// update text data for certain attr changes
|
|
13959
|
-
this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva', this._setTextData);
|
|
13974
|
+
this.on('textChange.konva alignChange.konva letterSpacingChange.konva kerningFuncChange.konva fontSizeChange.konva fontFamilyChange.konva', this._setTextData);
|
|
13960
13975
|
this._setTextData();
|
|
13961
13976
|
}
|
|
13962
13977
|
_sceneFunc(context) {
|
|
@@ -14378,10 +14393,10 @@
|
|
|
14378
14393
|
* @param {Number} letterSpacing
|
|
14379
14394
|
* @returns {Number}
|
|
14380
14395
|
* @example
|
|
14381
|
-
* // get
|
|
14396
|
+
* // get letter spacing value
|
|
14382
14397
|
* var letterSpacing = shape.letterSpacing();
|
|
14383
14398
|
*
|
|
14384
|
-
* // set the
|
|
14399
|
+
* // set the letter spacing value
|
|
14385
14400
|
* shape.letterSpacing(2);
|
|
14386
14401
|
*/
|
|
14387
14402
|
Factory.addGetterSetter(TextPath, 'letterSpacing', 0, getNumberValidator());
|
|
@@ -14392,10 +14407,10 @@
|
|
|
14392
14407
|
* @param {String} textBaseline
|
|
14393
14408
|
* @returns {String}
|
|
14394
14409
|
* @example
|
|
14395
|
-
* // get
|
|
14410
|
+
* // get current text baseline
|
|
14396
14411
|
* var textBaseline = shape.textBaseline();
|
|
14397
14412
|
*
|
|
14398
|
-
* // set
|
|
14413
|
+
* // set new text baseline
|
|
14399
14414
|
* shape.textBaseline('top');
|
|
14400
14415
|
*/
|
|
14401
14416
|
Factory.addGetterSetter(TextPath, 'textBaseline', 'middle');
|
|
@@ -14993,9 +15008,9 @@
|
|
|
14993
15008
|
x: pos.x - ap.x,
|
|
14994
15009
|
y: pos.y - ap.y,
|
|
14995
15010
|
};
|
|
14996
|
-
this._fire('transformstart', { evt: e, target: this.getNode() });
|
|
15011
|
+
this._fire('transformstart', { evt: e.evt, target: this.getNode() });
|
|
14997
15012
|
this._nodes.forEach((target) => {
|
|
14998
|
-
target._fire('transformstart', { evt: e, target });
|
|
15013
|
+
target._fire('transformstart', { evt: e.evt, target });
|
|
14999
15014
|
});
|
|
15000
15015
|
}
|
|
15001
15016
|
_handleMouseMove(e) {
|