konva 9.3.15 → 9.3.16
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/konva.js +726 -724
- package/konva.min.js +3 -3
- package/lib/Animation.js +1 -1
- package/lib/BezierFunctions.js +1 -2
- package/lib/Canvas.js +9 -9
- package/lib/Container.d.ts +1 -1
- package/lib/Container.js +29 -29
- package/lib/Context.d.ts +2 -2
- package/lib/Context.js +26 -26
- package/lib/DragAndDrop.d.ts +2 -2
- package/lib/DragAndDrop.js +6 -4
- package/lib/Factory.js +16 -16
- package/lib/Global.js +1 -1
- package/lib/Group.js +1 -1
- package/lib/Layer.js +17 -17
- package/lib/Node.d.ts +1 -1
- package/lib/Node.js +87 -87
- package/lib/PointerEvents.js +5 -6
- package/lib/Shape.js +31 -31
- package/lib/Stage.d.ts +2 -2
- package/lib/Stage.js +28 -28
- package/lib/Tween.js +21 -21
- package/lib/Util.d.ts +4 -4
- package/lib/Util.js +62 -62
- package/lib/Validators.js +16 -17
- package/lib/_CoreInternals.d.ts +8 -8
- package/lib/_FullInternals.d.ts +8 -8
- package/lib/filters/Blur.js +6 -6
- package/lib/filters/Brighten.js +1 -1
- package/lib/filters/Contrast.js +2 -2
- package/lib/filters/Emboss.js +19 -19
- package/lib/filters/Enhance.js +4 -4
- package/lib/filters/Grayscale.js +1 -1
- package/lib/filters/HSL.js +6 -6
- package/lib/filters/HSV.js +7 -7
- package/lib/filters/Invert.js +1 -1
- package/lib/filters/Kaleidoscope.js +20 -20
- package/lib/filters/Mask.js +57 -57
- package/lib/filters/Noise.js +2 -2
- package/lib/filters/Pixelate.js +1 -1
- package/lib/filters/Posterize.js +1 -1
- package/lib/filters/RGB.js +1 -1
- package/lib/filters/RGBA.js +3 -3
- package/lib/filters/Sepia.js +1 -1
- package/lib/filters/Solarize.js +8 -7
- package/lib/filters/Threshold.js +2 -2
- package/lib/shapes/Arc.js +1 -1
- package/lib/shapes/Arrow.js +10 -10
- package/lib/shapes/Ellipse.js +1 -1
- package/lib/shapes/Image.js +3 -3
- package/lib/shapes/Label.d.ts +1 -1
- package/lib/shapes/Label.js +6 -6
- package/lib/shapes/Line.d.ts +1 -1
- package/lib/shapes/Line.js +14 -14
- package/lib/shapes/Path.js +62 -62
- package/lib/shapes/Rect.js +1 -1
- package/lib/shapes/RegularPolygon.js +6 -6
- package/lib/shapes/Ring.js +1 -1
- package/lib/shapes/Sprite.js +9 -9
- package/lib/shapes/Star.js +5 -5
- package/lib/shapes/Text.js +37 -37
- package/lib/shapes/TextPath.js +23 -23
- package/lib/shapes/Transformer.d.ts +1 -1
- package/lib/shapes/Transformer.js +63 -63
- package/package.json +2 -5
package/lib/Animation.js
CHANGED
package/lib/BezierFunctions.js
CHANGED
|
@@ -687,11 +687,10 @@ exports.cValues = [
|
|
|
687
687
|
];
|
|
688
688
|
exports.binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]];
|
|
689
689
|
const getCubicArcLength = (xs, ys, t) => {
|
|
690
|
-
let z;
|
|
691
690
|
let sum;
|
|
692
691
|
let correctedT;
|
|
693
692
|
const n = 20;
|
|
694
|
-
z = t / 2;
|
|
693
|
+
const z = t / 2;
|
|
695
694
|
sum = 0;
|
|
696
695
|
for (let i = 0; i < n; i++) {
|
|
697
696
|
correctedT = z * exports.tValues[n][i] + z;
|
package/lib/Canvas.js
CHANGED
|
@@ -6,15 +6,15 @@ const Context_1 = require("./Context");
|
|
|
6
6
|
const Global_1 = require("./Global");
|
|
7
7
|
const Factory_1 = require("./Factory");
|
|
8
8
|
const Validators_1 = require("./Validators");
|
|
9
|
-
|
|
9
|
+
let _pixelRatio;
|
|
10
10
|
function getDevicePixelRatio() {
|
|
11
11
|
if (_pixelRatio) {
|
|
12
12
|
return _pixelRatio;
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
const canvas = Util_1.Util.createCanvasElement();
|
|
15
|
+
const context = canvas.getContext('2d');
|
|
16
16
|
_pixelRatio = (function () {
|
|
17
|
-
|
|
17
|
+
const devicePixelRatio = Global_1.Konva._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||
|
|
18
18
|
context.mozBackingStorePixelRatio ||
|
|
19
19
|
context.msBackingStorePixelRatio ||
|
|
20
20
|
context.oBackingStorePixelRatio ||
|
|
@@ -31,8 +31,8 @@ class Canvas {
|
|
|
31
31
|
this.width = 0;
|
|
32
32
|
this.height = 0;
|
|
33
33
|
this.isCache = false;
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
const conf = config || {};
|
|
35
|
+
const pixelRatio = conf.pixelRatio || Global_1.Konva.pixelRatio || getDevicePixelRatio();
|
|
36
36
|
this.pixelRatio = pixelRatio;
|
|
37
37
|
this._canvas = Util_1.Util.createCanvasElement();
|
|
38
38
|
this._canvas.style.padding = '0';
|
|
@@ -50,20 +50,20 @@ class Canvas {
|
|
|
50
50
|
return this.pixelRatio;
|
|
51
51
|
}
|
|
52
52
|
setPixelRatio(pixelRatio) {
|
|
53
|
-
|
|
53
|
+
const previousRatio = this.pixelRatio;
|
|
54
54
|
this.pixelRatio = pixelRatio;
|
|
55
55
|
this.setSize(this.getWidth() / previousRatio, this.getHeight() / previousRatio);
|
|
56
56
|
}
|
|
57
57
|
setWidth(width) {
|
|
58
58
|
this.width = this._canvas.width = width * this.pixelRatio;
|
|
59
59
|
this._canvas.style.width = width + 'px';
|
|
60
|
-
|
|
60
|
+
const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
|
|
61
61
|
_context.scale(pixelRatio, pixelRatio);
|
|
62
62
|
}
|
|
63
63
|
setHeight(height) {
|
|
64
64
|
this.height = this._canvas.height = height * this.pixelRatio;
|
|
65
65
|
this._canvas.style.height = height + 'px';
|
|
66
|
-
|
|
66
|
+
const pixelRatio = this.pixelRatio, _context = this.getContext()._context;
|
|
67
67
|
_context.scale(pixelRatio, pixelRatio);
|
|
68
68
|
}
|
|
69
69
|
getWidth() {
|
package/lib/Container.d.ts
CHANGED
|
@@ -28,7 +28,7 @@ export declare abstract class Container<ChildType extends Node = Node> extends N
|
|
|
28
28
|
toObject(): {
|
|
29
29
|
attrs: any;
|
|
30
30
|
className: string;
|
|
31
|
-
children?: any
|
|
31
|
+
children?: Array<any>;
|
|
32
32
|
};
|
|
33
33
|
isAncestorOf(node: Node): boolean;
|
|
34
34
|
clone(obj?: any): this;
|
package/lib/Container.js
CHANGED
|
@@ -14,7 +14,7 @@ class Container extends Node_1.Node {
|
|
|
14
14
|
return this.children || [];
|
|
15
15
|
}
|
|
16
16
|
const children = this.children || [];
|
|
17
|
-
|
|
17
|
+
const results = [];
|
|
18
18
|
children.forEach(function (child) {
|
|
19
19
|
if (filterFunc(child)) {
|
|
20
20
|
results.push(child);
|
|
@@ -50,7 +50,7 @@ class Container extends Node_1.Node {
|
|
|
50
50
|
return this;
|
|
51
51
|
}
|
|
52
52
|
if (children.length > 1) {
|
|
53
|
-
for (
|
|
53
|
+
for (let i = 0; i < children.length; i++) {
|
|
54
54
|
this.add(children[i]);
|
|
55
55
|
}
|
|
56
56
|
return this;
|
|
@@ -82,11 +82,11 @@ class Container extends Node_1.Node {
|
|
|
82
82
|
return this._generalFind(selector, false);
|
|
83
83
|
}
|
|
84
84
|
findOne(selector) {
|
|
85
|
-
|
|
85
|
+
const result = this._generalFind(selector, true);
|
|
86
86
|
return result.length > 0 ? result[0] : undefined;
|
|
87
87
|
}
|
|
88
88
|
_generalFind(selector, findOne) {
|
|
89
|
-
|
|
89
|
+
const retArr = [];
|
|
90
90
|
this._descendants((node) => {
|
|
91
91
|
const valid = node._isMatch(selector);
|
|
92
92
|
if (valid) {
|
|
@@ -118,7 +118,7 @@ class Container extends Node_1.Node {
|
|
|
118
118
|
return false;
|
|
119
119
|
}
|
|
120
120
|
toObject() {
|
|
121
|
-
|
|
121
|
+
const obj = Node_1.Node.prototype.toObject.call(this);
|
|
122
122
|
obj.children = [];
|
|
123
123
|
this.getChildren().forEach((child) => {
|
|
124
124
|
obj.children.push(child.toObject());
|
|
@@ -126,7 +126,7 @@ class Container extends Node_1.Node {
|
|
|
126
126
|
return obj;
|
|
127
127
|
}
|
|
128
128
|
isAncestorOf(node) {
|
|
129
|
-
|
|
129
|
+
let parent = node.getParent();
|
|
130
130
|
while (parent) {
|
|
131
131
|
if (parent._id === this._id) {
|
|
132
132
|
return true;
|
|
@@ -136,14 +136,14 @@ class Container extends Node_1.Node {
|
|
|
136
136
|
return false;
|
|
137
137
|
}
|
|
138
138
|
clone(obj) {
|
|
139
|
-
|
|
139
|
+
const node = Node_1.Node.prototype.clone.call(this, obj);
|
|
140
140
|
this.getChildren().forEach(function (no) {
|
|
141
141
|
node.add(no.clone());
|
|
142
142
|
});
|
|
143
143
|
return node;
|
|
144
144
|
}
|
|
145
145
|
getAllIntersections(pos) {
|
|
146
|
-
|
|
146
|
+
const arr = [];
|
|
147
147
|
this.find('Shape').forEach((shape) => {
|
|
148
148
|
if (shape.isVisible() && shape.intersects(pos)) {
|
|
149
149
|
arr.push(shape);
|
|
@@ -169,14 +169,14 @@ class Container extends Node_1.Node {
|
|
|
169
169
|
this._requestDraw();
|
|
170
170
|
}
|
|
171
171
|
drawScene(can, top, bufferCanvas) {
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas()), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedSceneCanvas = cachedCanvas && cachedCanvas.scene;
|
|
173
|
+
const caching = canvas && canvas.isCache;
|
|
174
174
|
if (!this.isVisible() && !caching) {
|
|
175
175
|
return this;
|
|
176
176
|
}
|
|
177
177
|
if (cachedSceneCanvas) {
|
|
178
178
|
context.save();
|
|
179
|
-
|
|
179
|
+
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
180
180
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
181
181
|
this._drawCachedSceneCanvas(context);
|
|
182
182
|
context.restore();
|
|
@@ -190,10 +190,10 @@ class Container extends Node_1.Node {
|
|
|
190
190
|
if (!this.shouldDrawHit(top)) {
|
|
191
191
|
return this;
|
|
192
192
|
}
|
|
193
|
-
|
|
193
|
+
const layer = this.getLayer(), canvas = can || (layer && layer.hitCanvas), context = canvas && canvas.getContext(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
|
194
194
|
if (cachedHitCanvas) {
|
|
195
195
|
context.save();
|
|
196
|
-
|
|
196
|
+
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
197
197
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
198
198
|
this._drawCachedHitCanvas(context);
|
|
199
199
|
context.restore();
|
|
@@ -205,13 +205,13 @@ class Container extends Node_1.Node {
|
|
|
205
205
|
}
|
|
206
206
|
_drawChildren(drawMethod, canvas, top, bufferCanvas) {
|
|
207
207
|
var _a;
|
|
208
|
-
|
|
208
|
+
const context = canvas && canvas.getContext(), clipWidth = this.clipWidth(), clipHeight = this.clipHeight(), clipFunc = this.clipFunc(), hasClip = (typeof clipWidth === 'number' && typeof clipHeight === 'number') ||
|
|
209
209
|
clipFunc;
|
|
210
210
|
const selfCache = top === this;
|
|
211
211
|
if (hasClip) {
|
|
212
212
|
context.save();
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
const transform = this.getAbsoluteTransform(top);
|
|
214
|
+
let m = transform.getMatrix();
|
|
215
215
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
216
216
|
context.beginPath();
|
|
217
217
|
let clipArgs;
|
|
@@ -219,15 +219,15 @@ class Container extends Node_1.Node {
|
|
|
219
219
|
clipArgs = clipFunc.call(this, context, this);
|
|
220
220
|
}
|
|
221
221
|
else {
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
const clipX = this.clipX();
|
|
223
|
+
const clipY = this.clipY();
|
|
224
224
|
context.rect(clipX || 0, clipY || 0, clipWidth, clipHeight);
|
|
225
225
|
}
|
|
226
226
|
context.clip.apply(context, clipArgs);
|
|
227
227
|
m = transform.copy().invert().getMatrix();
|
|
228
228
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
229
229
|
}
|
|
230
|
-
|
|
230
|
+
const hasComposition = !selfCache &&
|
|
231
231
|
this.globalCompositeOperation() !== 'source-over' &&
|
|
232
232
|
drawMethod === 'drawScene';
|
|
233
233
|
if (hasComposition) {
|
|
@@ -246,21 +246,21 @@ class Container extends Node_1.Node {
|
|
|
246
246
|
}
|
|
247
247
|
getClientRect(config = {}) {
|
|
248
248
|
var _a;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
249
|
+
const skipTransform = config.skipTransform;
|
|
250
|
+
const relativeTo = config.relativeTo;
|
|
251
|
+
let minX, minY, maxX, maxY;
|
|
252
|
+
let selfRect = {
|
|
253
253
|
x: Infinity,
|
|
254
254
|
y: Infinity,
|
|
255
255
|
width: 0,
|
|
256
256
|
height: 0,
|
|
257
257
|
};
|
|
258
|
-
|
|
258
|
+
const that = this;
|
|
259
259
|
(_a = this.children) === null || _a === void 0 ? void 0 : _a.forEach(function (child) {
|
|
260
260
|
if (!child.visible()) {
|
|
261
261
|
return;
|
|
262
262
|
}
|
|
263
|
-
|
|
263
|
+
const rect = child.getClientRect({
|
|
264
264
|
relativeTo: that,
|
|
265
265
|
skipShadow: config.skipShadow,
|
|
266
266
|
skipStroke: config.skipStroke,
|
|
@@ -281,10 +281,10 @@ class Container extends Node_1.Node {
|
|
|
281
281
|
maxY = Math.max(maxY, rect.y + rect.height);
|
|
282
282
|
}
|
|
283
283
|
});
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
for (
|
|
287
|
-
|
|
284
|
+
const shapes = this.find('Shape');
|
|
285
|
+
let hasVisible = false;
|
|
286
|
+
for (let i = 0; i < shapes.length; i++) {
|
|
287
|
+
const shape = shapes[i];
|
|
288
288
|
if (shape._isVisible(this)) {
|
|
289
289
|
hasVisible = true;
|
|
290
290
|
break;
|
package/lib/Context.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import { Canvas } from './Canvas.js';
|
|
|
2
2
|
import { Shape } from './Shape.js';
|
|
3
3
|
import { IRect } from './types.js';
|
|
4
4
|
import type { Node } from './Node.js';
|
|
5
|
-
declare
|
|
5
|
+
declare const CONTEXT_PROPERTIES: readonly ["fillStyle", "strokeStyle", "shadowColor", "shadowBlur", "shadowOffsetX", "shadowOffsetY", "letterSpacing", "lineCap", "lineDashOffset", "lineJoin", "lineWidth", "miterLimit", "direction", "font", "textAlign", "textBaseline", "globalAlpha", "globalCompositeOperation", "imageSmoothingEnabled"];
|
|
6
6
|
interface ExtendedCanvasRenderingContext2D extends CanvasRenderingContext2D {
|
|
7
7
|
letterSpacing: string;
|
|
8
8
|
}
|
|
9
9
|
export declare class Context {
|
|
10
10
|
canvas: Canvas;
|
|
11
11
|
_context: CanvasRenderingContext2D;
|
|
12
|
-
traceArr: Array<
|
|
12
|
+
traceArr: Array<string>;
|
|
13
13
|
constructor(canvas: Canvas);
|
|
14
14
|
fillShape(shape: Shape): void;
|
|
15
15
|
_fill(shape: Shape): void;
|
package/lib/Context.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.HitContext = exports.SceneContext = exports.Context = void 0;
|
|
|
4
4
|
const Util_1 = require("./Util");
|
|
5
5
|
const Global_1 = require("./Global");
|
|
6
6
|
function simplifyArray(arr) {
|
|
7
|
-
|
|
7
|
+
let retArr = [], len = arr.length, util = Util_1.Util, n, val;
|
|
8
8
|
for (n = 0; n < len; n++) {
|
|
9
9
|
val = arr[n];
|
|
10
10
|
if (util._isNumber(val)) {
|
|
@@ -17,7 +17,7 @@ function simplifyArray(arr) {
|
|
|
17
17
|
}
|
|
18
18
|
return retArr;
|
|
19
19
|
}
|
|
20
|
-
|
|
20
|
+
const COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([', CLOSE_BRACKET_PAREN = '])', SEMICOLON = ';', DOUBLE_PAREN = '()', EQUALS = '=', CONTEXT_METHODS = [
|
|
21
21
|
'arc',
|
|
22
22
|
'arcTo',
|
|
23
23
|
'beginPath',
|
|
@@ -51,7 +51,7 @@ var COMMA = ',', OPEN_PAREN = '(', CLOSE_PAREN = ')', OPEN_PAREN_BRACKET = '([',
|
|
|
51
51
|
'transform',
|
|
52
52
|
'translate',
|
|
53
53
|
];
|
|
54
|
-
|
|
54
|
+
const CONTEXT_PROPERTIES = [
|
|
55
55
|
'fillStyle',
|
|
56
56
|
'strokeStyle',
|
|
57
57
|
'shadowColor',
|
|
@@ -106,7 +106,7 @@ class Context {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
getTrace(relaxed, rounded) {
|
|
109
|
-
|
|
109
|
+
let traceArr = this.traceArr, len = traceArr.length, str = '', n, trace, method, args;
|
|
110
110
|
for (n = 0; n < len; n++) {
|
|
111
111
|
trace = traceArr[n];
|
|
112
112
|
method = trace.method;
|
|
@@ -142,7 +142,7 @@ class Context {
|
|
|
142
142
|
this.traceArr = [];
|
|
143
143
|
}
|
|
144
144
|
_trace(str) {
|
|
145
|
-
|
|
145
|
+
let traceArr = this.traceArr, len;
|
|
146
146
|
traceArr.push(str);
|
|
147
147
|
len = traceArr.length;
|
|
148
148
|
if (len >= traceArrMax) {
|
|
@@ -150,14 +150,14 @@ class Context {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
reset() {
|
|
153
|
-
|
|
153
|
+
const pixelRatio = this.getCanvas().getPixelRatio();
|
|
154
154
|
this.setTransform(1 * pixelRatio, 0, 0, 1 * pixelRatio, 0, 0);
|
|
155
155
|
}
|
|
156
156
|
getCanvas() {
|
|
157
157
|
return this.canvas;
|
|
158
158
|
}
|
|
159
159
|
clear(bounds) {
|
|
160
|
-
|
|
160
|
+
const canvas = this.getCanvas();
|
|
161
161
|
if (bounds) {
|
|
162
162
|
this.clearRect(bounds.x || 0, bounds.y || 0, bounds.width || 0, bounds.height || 0);
|
|
163
163
|
}
|
|
@@ -172,7 +172,7 @@ class Context {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
_applyOpacity(shape) {
|
|
175
|
-
|
|
175
|
+
const absOpacity = shape.getAbsoluteOpacity();
|
|
176
176
|
if (absOpacity !== 1) {
|
|
177
177
|
this.setAttr('globalAlpha', absOpacity);
|
|
178
178
|
}
|
|
@@ -208,7 +208,7 @@ class Context {
|
|
|
208
208
|
this._context.closePath();
|
|
209
209
|
}
|
|
210
210
|
createImageData(width, height) {
|
|
211
|
-
|
|
211
|
+
const a = arguments;
|
|
212
212
|
if (a.length === 2) {
|
|
213
213
|
return this._context.createImageData(width, height);
|
|
214
214
|
}
|
|
@@ -226,7 +226,7 @@ class Context {
|
|
|
226
226
|
return this._context.createRadialGradient(x0, y0, r0, x1, y1, r1);
|
|
227
227
|
}
|
|
228
228
|
drawImage(image, sx, sy, sWidth, sHeight, dx, dy, dWidth, dHeight) {
|
|
229
|
-
|
|
229
|
+
const a = arguments, _context = this._context;
|
|
230
230
|
if (a.length === 3) {
|
|
231
231
|
_context.drawImage(image, sx, sy);
|
|
232
232
|
}
|
|
@@ -334,9 +334,9 @@ class Context {
|
|
|
334
334
|
this._context.translate(x, y);
|
|
335
335
|
}
|
|
336
336
|
_enableTrace() {
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
337
|
+
let that = this, len = CONTEXT_METHODS.length, origSetter = this.setAttr, n, args;
|
|
338
|
+
const func = function (methodName) {
|
|
339
|
+
let origMethod = that[methodName], ret;
|
|
340
340
|
that[methodName] = function () {
|
|
341
341
|
args = simplifyArray(Array.prototype.slice.call(arguments, 0));
|
|
342
342
|
ret = origMethod.apply(that, arguments);
|
|
@@ -352,8 +352,8 @@ class Context {
|
|
|
352
352
|
}
|
|
353
353
|
that.setAttr = function () {
|
|
354
354
|
origSetter.apply(that, arguments);
|
|
355
|
-
|
|
356
|
-
|
|
355
|
+
const prop = arguments[0];
|
|
356
|
+
let val = arguments[1];
|
|
357
357
|
if (prop === 'shadowOffsetX' ||
|
|
358
358
|
prop === 'shadowOffsetY' ||
|
|
359
359
|
prop === 'shadowBlur') {
|
|
@@ -367,7 +367,7 @@ class Context {
|
|
|
367
367
|
}
|
|
368
368
|
_applyGlobalCompositeOperation(node) {
|
|
369
369
|
const op = node.attrs.globalCompositeOperation;
|
|
370
|
-
|
|
370
|
+
const def = !op || op === 'source-over';
|
|
371
371
|
if (!def) {
|
|
372
372
|
this.setAttr('globalCompositeOperation', op);
|
|
373
373
|
}
|
|
@@ -392,7 +392,7 @@ class SceneContext extends Context {
|
|
|
392
392
|
});
|
|
393
393
|
}
|
|
394
394
|
_fillColor(shape) {
|
|
395
|
-
|
|
395
|
+
const fill = shape.fill();
|
|
396
396
|
this.setAttr('fillStyle', fill);
|
|
397
397
|
shape._fillFunc(this);
|
|
398
398
|
}
|
|
@@ -401,7 +401,7 @@ class SceneContext extends Context {
|
|
|
401
401
|
shape._fillFunc(this);
|
|
402
402
|
}
|
|
403
403
|
_fillLinearGradient(shape) {
|
|
404
|
-
|
|
404
|
+
const grd = shape._getLinearGradient();
|
|
405
405
|
if (grd) {
|
|
406
406
|
this.setAttr('fillStyle', grd);
|
|
407
407
|
shape._fillFunc(this);
|
|
@@ -451,18 +451,18 @@ class SceneContext extends Context {
|
|
|
451
451
|
_strokeLinearGradient(shape) {
|
|
452
452
|
const start = shape.getStrokeLinearGradientStartPoint(), end = shape.getStrokeLinearGradientEndPoint(), colorStops = shape.getStrokeLinearGradientColorStops(), grd = this.createLinearGradient(start.x, start.y, end.x, end.y);
|
|
453
453
|
if (colorStops) {
|
|
454
|
-
for (
|
|
454
|
+
for (let n = 0; n < colorStops.length; n += 2) {
|
|
455
455
|
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
|
456
456
|
}
|
|
457
457
|
this.setAttr('strokeStyle', grd);
|
|
458
458
|
}
|
|
459
459
|
}
|
|
460
460
|
_stroke(shape) {
|
|
461
|
-
|
|
461
|
+
const dash = shape.dash(), strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
|
462
462
|
if (shape.hasStroke()) {
|
|
463
463
|
if (!strokeScaleEnabled) {
|
|
464
464
|
this.save();
|
|
465
|
-
|
|
465
|
+
const pixelRatio = this.getCanvas().getPixelRatio();
|
|
466
466
|
this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
467
467
|
}
|
|
468
468
|
this._applyLineCap(shape);
|
|
@@ -474,7 +474,7 @@ class SceneContext extends Context {
|
|
|
474
474
|
if (!shape.getShadowForStrokeEnabled()) {
|
|
475
475
|
this.setAttr('shadowColor', 'rgba(0,0,0,0)');
|
|
476
476
|
}
|
|
477
|
-
|
|
477
|
+
const hasLinearGradient = shape.getStrokeLinearGradientColorStops();
|
|
478
478
|
if (hasLinearGradient) {
|
|
479
479
|
this._strokeLinearGradient(shape);
|
|
480
480
|
}
|
|
@@ -489,7 +489,7 @@ class SceneContext extends Context {
|
|
|
489
489
|
}
|
|
490
490
|
_applyShadow(shape) {
|
|
491
491
|
var _a, _b, _c;
|
|
492
|
-
|
|
492
|
+
const color = (_a = shape.getShadowRGBA()) !== null && _a !== void 0 ? _a : 'black', blur = (_b = shape.getShadowBlur()) !== null && _b !== void 0 ? _b : 5, offset = (_c = shape.getShadowOffset()) !== null && _c !== void 0 ? _c : {
|
|
493
493
|
x: 0,
|
|
494
494
|
y: 0,
|
|
495
495
|
}, scale = shape.getAbsoluteScale(), ratio = this.canvas.getPixelRatio(), scaleX = scale.x * ratio, scaleY = scale.y * ratio;
|
|
@@ -523,12 +523,12 @@ class HitContext extends Context {
|
|
|
523
523
|
const strokeScaleEnabled = shape.getStrokeScaleEnabled();
|
|
524
524
|
if (!strokeScaleEnabled) {
|
|
525
525
|
this.save();
|
|
526
|
-
|
|
526
|
+
const pixelRatio = this.getCanvas().getPixelRatio();
|
|
527
527
|
this.setTransform(pixelRatio, 0, 0, pixelRatio, 0, 0);
|
|
528
528
|
}
|
|
529
529
|
this._applyLineCap(shape);
|
|
530
|
-
|
|
531
|
-
|
|
530
|
+
const hitStrokeWidth = shape.hitStrokeWidth();
|
|
531
|
+
const strokeWidth = hitStrokeWidth === 'auto' ? shape.strokeWidth() : hitStrokeWidth;
|
|
532
532
|
this.setAttr('lineWidth', strokeWidth);
|
|
533
533
|
this.setAttr('strokeStyle', shape.colorKey);
|
|
534
534
|
shape._strokeFuncHit(this);
|
package/lib/DragAndDrop.d.ts
CHANGED
|
@@ -8,8 +8,8 @@ export declare const DD: {
|
|
|
8
8
|
node: Node;
|
|
9
9
|
startPointerPos: Vector2d;
|
|
10
10
|
offset: Vector2d;
|
|
11
|
-
pointerId?: number
|
|
12
|
-
dragStatus:
|
|
11
|
+
pointerId?: number;
|
|
12
|
+
dragStatus: "ready" | "dragging" | "stopped";
|
|
13
13
|
}>;
|
|
14
14
|
_drag(evt: any): void;
|
|
15
15
|
_endDragBefore(evt?: any): void;
|
package/lib/DragAndDrop.js
CHANGED
|
@@ -5,7 +5,7 @@ const Global_1 = require("./Global");
|
|
|
5
5
|
const Util_1 = require("./Util");
|
|
6
6
|
exports.DD = {
|
|
7
7
|
get isDragging() {
|
|
8
|
-
|
|
8
|
+
let flag = false;
|
|
9
9
|
exports.DD._dragElements.forEach((elem) => {
|
|
10
10
|
if (elem.dragStatus === 'dragging') {
|
|
11
11
|
flag = true;
|
|
@@ -15,7 +15,7 @@ exports.DD = {
|
|
|
15
15
|
},
|
|
16
16
|
justDragged: false,
|
|
17
17
|
get node() {
|
|
18
|
-
|
|
18
|
+
let node;
|
|
19
19
|
exports.DD._dragElements.forEach((elem) => {
|
|
20
20
|
node = elem.node;
|
|
21
21
|
});
|
|
@@ -36,8 +36,8 @@ exports.DD = {
|
|
|
36
36
|
return;
|
|
37
37
|
}
|
|
38
38
|
if (elem.dragStatus !== 'dragging') {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const dragDistance = node.dragDistance();
|
|
40
|
+
const distance = Math.max(Math.abs(pos.x - elem.startPointerPos.x), Math.abs(pos.y - elem.startPointerPos.y));
|
|
41
41
|
if (distance < dragDistance) {
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
@@ -104,8 +104,10 @@ exports.DD = {
|
|
|
104
104
|
if (Global_1.Konva.isBrowser) {
|
|
105
105
|
window.addEventListener('mouseup', exports.DD._endDragBefore, true);
|
|
106
106
|
window.addEventListener('touchend', exports.DD._endDragBefore, true);
|
|
107
|
+
window.addEventListener('touchcancel', exports.DD._endDragBefore, true);
|
|
107
108
|
window.addEventListener('mousemove', exports.DD._drag);
|
|
108
109
|
window.addEventListener('touchmove', exports.DD._drag);
|
|
109
110
|
window.addEventListener('mouseup', exports.DD._endDragAfter, false);
|
|
110
111
|
window.addEventListener('touchend', exports.DD._endDragAfter, false);
|
|
112
|
+
window.addEventListener('touchcancel', exports.DD._endDragAfter, false);
|
|
111
113
|
}
|
package/lib/Factory.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Factory = void 0;
|
|
4
4
|
const Util_1 = require("./Util");
|
|
5
5
|
const Validators_1 = require("./Validators");
|
|
6
|
-
|
|
6
|
+
const GET = 'get', SET = 'set';
|
|
7
7
|
exports.Factory = {
|
|
8
8
|
addGetterSetter(constructor, attr, def, validator, after) {
|
|
9
9
|
exports.Factory.addGetter(constructor, attr, def);
|
|
@@ -11,22 +11,22 @@ exports.Factory = {
|
|
|
11
11
|
exports.Factory.addOverloadedGetterSetter(constructor, attr);
|
|
12
12
|
},
|
|
13
13
|
addGetter(constructor, attr, def) {
|
|
14
|
-
|
|
14
|
+
const method = GET + Util_1.Util._capitalize(attr);
|
|
15
15
|
constructor.prototype[method] =
|
|
16
16
|
constructor.prototype[method] ||
|
|
17
17
|
function () {
|
|
18
|
-
|
|
18
|
+
const val = this.attrs[attr];
|
|
19
19
|
return val === undefined ? def : val;
|
|
20
20
|
};
|
|
21
21
|
},
|
|
22
22
|
addSetter(constructor, attr, validator, after) {
|
|
23
|
-
|
|
23
|
+
const method = SET + Util_1.Util._capitalize(attr);
|
|
24
24
|
if (!constructor.prototype[method]) {
|
|
25
25
|
exports.Factory.overWriteSetter(constructor, attr, validator, after);
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
overWriteSetter(constructor, attr, validator, after) {
|
|
29
|
-
|
|
29
|
+
const method = SET + Util_1.Util._capitalize(attr);
|
|
30
30
|
constructor.prototype[method] = function (val) {
|
|
31
31
|
if (validator && val !== undefined && val !== null) {
|
|
32
32
|
val = validator.call(this, val, attr);
|
|
@@ -39,18 +39,18 @@ exports.Factory = {
|
|
|
39
39
|
};
|
|
40
40
|
},
|
|
41
41
|
addComponentsGetterSetter(constructor, attr, components, validator, after) {
|
|
42
|
-
|
|
42
|
+
let len = components.length, capitalize = Util_1.Util._capitalize, getter = GET + capitalize(attr), setter = SET + capitalize(attr), n, component;
|
|
43
43
|
constructor.prototype[getter] = function () {
|
|
44
|
-
|
|
44
|
+
const ret = {};
|
|
45
45
|
for (n = 0; n < len; n++) {
|
|
46
46
|
component = components[n];
|
|
47
47
|
ret[component] = this.getAttr(attr + capitalize(component));
|
|
48
48
|
}
|
|
49
49
|
return ret;
|
|
50
50
|
};
|
|
51
|
-
|
|
51
|
+
const basicValidator = (0, Validators_1.getComponentValidator)(components);
|
|
52
52
|
constructor.prototype[setter] = function (val) {
|
|
53
|
-
|
|
53
|
+
let oldVal = this.attrs[attr], key;
|
|
54
54
|
if (validator) {
|
|
55
55
|
val = validator.call(this, val);
|
|
56
56
|
}
|
|
@@ -77,7 +77,7 @@ exports.Factory = {
|
|
|
77
77
|
exports.Factory.addOverloadedGetterSetter(constructor, attr);
|
|
78
78
|
},
|
|
79
79
|
addOverloadedGetterSetter(constructor, attr) {
|
|
80
|
-
|
|
80
|
+
const capitalizedAttr = Util_1.Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr;
|
|
81
81
|
constructor.prototype[attr] = function () {
|
|
82
82
|
if (arguments.length) {
|
|
83
83
|
this[setter](arguments[0]);
|
|
@@ -88,12 +88,12 @@ exports.Factory = {
|
|
|
88
88
|
},
|
|
89
89
|
addDeprecatedGetterSetter(constructor, attr, def, validator) {
|
|
90
90
|
Util_1.Util.error('Adding deprecated ' + attr);
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
const method = GET + Util_1.Util._capitalize(attr);
|
|
92
|
+
const message = attr +
|
|
93
93
|
' property is deprecated and will be removed soon. Look at Konva change log for more information.';
|
|
94
94
|
constructor.prototype[method] = function () {
|
|
95
95
|
Util_1.Util.error(message);
|
|
96
|
-
|
|
96
|
+
const val = this.attrs[attr];
|
|
97
97
|
return val === undefined ? def : val;
|
|
98
98
|
};
|
|
99
99
|
exports.Factory.addSetter(constructor, attr, validator, function () {
|
|
@@ -103,9 +103,9 @@ exports.Factory = {
|
|
|
103
103
|
},
|
|
104
104
|
backCompat(constructor, methods) {
|
|
105
105
|
Util_1.Util.each(methods, function (oldMethodName, newMethodName) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
const method = constructor.prototype[newMethodName];
|
|
107
|
+
const oldGetter = GET + Util_1.Util._capitalize(oldMethodName);
|
|
108
|
+
const oldSetter = SET + Util_1.Util._capitalize(oldMethodName);
|
|
109
109
|
function deprecated() {
|
|
110
110
|
method.apply(this, arguments);
|
|
111
111
|
Util_1.Util.error('"' +
|
package/lib/Global.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.glob = typeof global !== 'undefined'
|
|
|
16
16
|
: {};
|
|
17
17
|
exports.Konva = {
|
|
18
18
|
_global: exports.glob,
|
|
19
|
-
version: '9.3.
|
|
19
|
+
version: '9.3.16',
|
|
20
20
|
isBrowser: detectBrowser(),
|
|
21
21
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
22
22
|
dblClickWindow: 400,
|
package/lib/Group.js
CHANGED
|
@@ -6,7 +6,7 @@ const Container_1 = require("./Container");
|
|
|
6
6
|
const Global_1 = require("./Global");
|
|
7
7
|
class Group extends Container_1.Container {
|
|
8
8
|
_validateAdd(child) {
|
|
9
|
-
|
|
9
|
+
const type = child.getType();
|
|
10
10
|
if (type !== 'Group' && type !== 'Shape') {
|
|
11
11
|
Util_1.Util.throw('You may only add groups and shapes to groups.');
|
|
12
12
|
}
|