konva 9.3.21 → 10.0.0-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 +1 -1
- package/konva.js +664 -226
- package/konva.min.js +46 -4
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +7 -11
- package/lib/BezierFunctions.js +9 -15
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +14 -20
- package/lib/Container.d.ts +7 -6
- package/lib/Container.js +12 -16
- package/lib/Context.d.ts +7 -5
- package/lib/Context.js +34 -14
- package/lib/Core.d.ts +2 -2
- package/lib/Core.js +3 -7
- package/lib/DragAndDrop.d.ts +3 -3
- package/lib/DragAndDrop.js +24 -27
- package/lib/Factory.d.ts +2 -2
- package/lib/Factory.js +24 -27
- package/lib/FastLayer.d.ts +1 -1
- package/lib/FastLayer.js +6 -10
- package/lib/Global.d.ts +4 -3
- package/lib/Global.js +19 -19
- package/lib/Group.d.ts +4 -3
- package/lib/Group.js +6 -10
- package/lib/Layer.d.ts +10 -9
- package/lib/Layer.js +33 -37
- package/lib/Node.d.ts +16 -13
- package/lib/Node.js +207 -123
- package/lib/PointerEvents.d.ts +4 -4
- package/lib/PointerEvents.js +7 -14
- package/lib/Shape.d.ts +7 -4
- package/lib/Shape.js +91 -91
- package/lib/Stage.d.ts +8 -7
- package/lib/Stage.js +66 -56
- package/lib/Tween.d.ts +3 -2
- package/lib/Tween.js +29 -31
- package/lib/Util.d.ts +3 -2
- package/lib/Util.js +98 -38
- package/lib/Validators.js +44 -57
- package/lib/_CoreInternals.d.ts +49 -23
- package/lib/_CoreInternals.js +33 -36
- package/lib/_FullInternals.d.ts +126 -62
- package/lib/_FullInternals.js +77 -78
- package/lib/canvas-backend.d.ts +2 -0
- package/lib/canvas-backend.js +27 -0
- package/lib/filters/Blur.d.ts +1 -1
- package/lib/filters/Blur.js +5 -9
- package/lib/filters/Brighten.d.ts +1 -1
- package/lib/filters/Brighten.js +5 -9
- package/lib/filters/Brightness.d.ts +2 -0
- package/lib/filters/Brightness.js +8 -0
- package/lib/filters/Contrast.d.ts +1 -1
- package/lib/filters/Contrast.js +5 -9
- package/lib/filters/Emboss.d.ts +1 -1
- package/lib/filters/Emboss.js +95 -101
- package/lib/filters/Enhance.d.ts +1 -1
- package/lib/filters/Enhance.js +5 -9
- package/lib/filters/Grayscale.d.ts +1 -1
- package/lib/filters/Grayscale.js +1 -5
- package/lib/filters/HSL.d.ts +1 -1
- package/lib/filters/HSL.js +7 -11
- package/lib/filters/HSV.d.ts +1 -1
- package/lib/filters/HSV.js +7 -11
- package/lib/filters/Invert.d.ts +1 -1
- package/lib/filters/Invert.js +1 -5
- package/lib/filters/Kaleidoscope.d.ts +1 -1
- package/lib/filters/Kaleidoscope.js +9 -13
- package/lib/filters/Mask.d.ts +1 -1
- package/lib/filters/Mask.js +16 -10
- package/lib/filters/Noise.d.ts +1 -1
- package/lib/filters/Noise.js +5 -9
- package/lib/filters/Pixelate.d.ts +1 -1
- package/lib/filters/Pixelate.js +7 -11
- package/lib/filters/Posterize.d.ts +1 -1
- package/lib/filters/Posterize.js +5 -9
- package/lib/filters/RGB.d.ts +1 -1
- package/lib/filters/RGB.js +7 -11
- package/lib/filters/RGBA.d.ts +1 -1
- package/lib/filters/RGBA.js +8 -12
- package/lib/filters/Sepia.d.ts +1 -1
- package/lib/filters/Sepia.js +1 -5
- package/lib/filters/Solarize.d.ts +1 -1
- package/lib/filters/Solarize.js +13 -29
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +5 -9
- package/lib/index.d.ts +1 -1
- package/lib/index.js +2 -4
- package/lib/shapes/Arc.d.ts +4 -3
- package/lib/shapes/Arc.js +13 -17
- package/lib/shapes/Arrow.d.ts +4 -3
- package/lib/shapes/Arrow.js +13 -17
- package/lib/shapes/Circle.d.ts +4 -3
- package/lib/shapes/Circle.js +7 -11
- package/lib/shapes/Ellipse.d.ts +4 -3
- package/lib/shapes/Ellipse.js +9 -13
- package/lib/shapes/Image.d.ts +4 -3
- package/lib/shapes/Image.js +17 -21
- package/lib/shapes/Label.d.ts +7 -6
- package/lib/shapes/Label.js +13 -18
- package/lib/shapes/Line.d.ts +4 -3
- package/lib/shapes/Line.js +10 -14
- package/lib/shapes/Path.d.ts +3 -2
- package/lib/shapes/Path.js +83 -23
- package/lib/shapes/Rect.d.ts +4 -3
- package/lib/shapes/Rect.js +9 -13
- package/lib/shapes/RegularPolygon.d.ts +6 -3
- package/lib/shapes/RegularPolygon.js +19 -16
- package/lib/shapes/Ring.d.ts +4 -3
- package/lib/shapes/Ring.js +8 -12
- package/lib/shapes/Sprite.d.ts +5 -4
- package/lib/shapes/Sprite.js +15 -19
- package/lib/shapes/Star.d.ts +4 -3
- package/lib/shapes/Star.js +9 -13
- package/lib/shapes/Text.d.ts +16 -3
- package/lib/shapes/Text.js +73 -53
- package/lib/shapes/TextPath.d.ts +5 -4
- package/lib/shapes/TextPath.js +48 -41
- package/lib/shapes/Transformer.d.ts +8 -8
- package/lib/shapes/Transformer.js +90 -90
- package/lib/shapes/Wedge.d.ts +4 -3
- package/lib/shapes/Wedge.js +12 -16
- package/lib/skia-backend.d.ts +2 -0
- package/lib/skia-backend.js +24 -0
- package/lib/types.d.ts +22 -22
- package/lib/types.js +21 -25
- package/package.json +53 -25
- package/lib/index-node.d.ts +0 -2
- package/lib/index-node.js +0 -21
- package/lib/index-types.d.ts +0 -181
package/lib/Animation.d.ts
CHANGED
package/lib/Animation.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.Animation = void 0;
|
|
4
|
-
const Global_1 = require("./Global");
|
|
5
|
-
const Util_1 = require("./Util");
|
|
1
|
+
import { glob } from "./Global.js";
|
|
2
|
+
import { Util } from "./Util.js";
|
|
6
3
|
const now = (function () {
|
|
7
|
-
if (
|
|
4
|
+
if (glob.performance && glob.performance.now) {
|
|
8
5
|
return function () {
|
|
9
|
-
return
|
|
6
|
+
return glob.performance.now();
|
|
10
7
|
};
|
|
11
8
|
}
|
|
12
9
|
return function () {
|
|
13
10
|
return new Date().getTime();
|
|
14
11
|
};
|
|
15
12
|
})();
|
|
16
|
-
class Animation {
|
|
13
|
+
export class Animation {
|
|
17
14
|
constructor(func, layers) {
|
|
18
15
|
this.id = Animation.animIdCounter++;
|
|
19
16
|
this.frame = {
|
|
@@ -127,7 +124,7 @@ class Animation {
|
|
|
127
124
|
const Anim = Animation;
|
|
128
125
|
if (Anim.animations.length) {
|
|
129
126
|
Anim._runFrames();
|
|
130
|
-
|
|
127
|
+
Util.requestAnimFrame(Anim._animationLoop);
|
|
131
128
|
}
|
|
132
129
|
else {
|
|
133
130
|
Anim.animRunning = false;
|
|
@@ -136,11 +133,10 @@ class Animation {
|
|
|
136
133
|
static _handleAnimation() {
|
|
137
134
|
if (!this.animRunning) {
|
|
138
135
|
this.animRunning = true;
|
|
139
|
-
|
|
136
|
+
Util.requestAnimFrame(this._animationLoop);
|
|
140
137
|
}
|
|
141
138
|
}
|
|
142
139
|
}
|
|
143
|
-
exports.Animation = Animation;
|
|
144
140
|
Animation.animations = [];
|
|
145
141
|
Animation.animIdCounter = 0;
|
|
146
142
|
Animation.animRunning = false;
|
package/lib/BezierFunctions.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.t2length = exports.getQuadraticArcLength = exports.getCubicArcLength = exports.binomialCoefficients = exports.cValues = exports.tValues = void 0;
|
|
4
|
-
exports.tValues = [
|
|
1
|
+
export const tValues = [
|
|
5
2
|
[],
|
|
6
3
|
[],
|
|
7
4
|
[
|
|
@@ -339,7 +336,7 @@ exports.tValues = [
|
|
|
339
336
|
0.9951872199970213601799974097007368118745,
|
|
340
337
|
],
|
|
341
338
|
];
|
|
342
|
-
|
|
339
|
+
export const cValues = [
|
|
343
340
|
[],
|
|
344
341
|
[],
|
|
345
342
|
[1.0, 1.0],
|
|
@@ -685,21 +682,20 @@ exports.cValues = [
|
|
|
685
682
|
0.0123412297999871995468056670700372915759,
|
|
686
683
|
],
|
|
687
684
|
];
|
|
688
|
-
|
|
689
|
-
const getCubicArcLength = (xs, ys, t) => {
|
|
685
|
+
export const binomialCoefficients = [[1], [1, 1], [1, 2, 1], [1, 3, 3, 1]];
|
|
686
|
+
export const getCubicArcLength = (xs, ys, t) => {
|
|
690
687
|
let sum;
|
|
691
688
|
let correctedT;
|
|
692
689
|
const n = 20;
|
|
693
690
|
const z = t / 2;
|
|
694
691
|
sum = 0;
|
|
695
692
|
for (let i = 0; i < n; i++) {
|
|
696
|
-
correctedT = z *
|
|
697
|
-
sum +=
|
|
693
|
+
correctedT = z * tValues[n][i] + z;
|
|
694
|
+
sum += cValues[n][i] * BFunc(xs, ys, correctedT);
|
|
698
695
|
}
|
|
699
696
|
return z * sum;
|
|
700
697
|
};
|
|
701
|
-
|
|
702
|
-
const getQuadraticArcLength = (xs, ys, t) => {
|
|
698
|
+
export const getQuadraticArcLength = (xs, ys, t) => {
|
|
703
699
|
if (t === undefined) {
|
|
704
700
|
t = 1;
|
|
705
701
|
}
|
|
@@ -724,7 +720,6 @@ const getQuadraticArcLength = (xs, ys, t) => {
|
|
|
724
720
|
: 0;
|
|
725
721
|
return (Math.sqrt(A) / 2) * (u * uuk - b * bbk + term);
|
|
726
722
|
};
|
|
727
|
-
exports.getQuadraticArcLength = getQuadraticArcLength;
|
|
728
723
|
function BFunc(xs, ys, t) {
|
|
729
724
|
const xbase = getDerivative(1, t, xs);
|
|
730
725
|
const ybase = getDerivative(1, t, ys);
|
|
@@ -742,7 +737,7 @@ const getDerivative = (derivative, t, vs) => {
|
|
|
742
737
|
value = 0;
|
|
743
738
|
for (let k = 0; k <= n; k++) {
|
|
744
739
|
value +=
|
|
745
|
-
|
|
740
|
+
binomialCoefficients[n][k] *
|
|
746
741
|
Math.pow(1 - t, n - k) *
|
|
747
742
|
Math.pow(t, k) *
|
|
748
743
|
vs[k];
|
|
@@ -757,7 +752,7 @@ const getDerivative = (derivative, t, vs) => {
|
|
|
757
752
|
return getDerivative(derivative - 1, t, _vs);
|
|
758
753
|
}
|
|
759
754
|
};
|
|
760
|
-
const t2length = (length, totalLength, func) => {
|
|
755
|
+
export const t2length = (length, totalLength, func) => {
|
|
761
756
|
let error = 1;
|
|
762
757
|
let t = length / totalLength;
|
|
763
758
|
let step = (length - func(t)) / totalLength;
|
|
@@ -787,4 +782,3 @@ const t2length = (length, totalLength, func) => {
|
|
|
787
782
|
}
|
|
788
783
|
return t;
|
|
789
784
|
};
|
|
790
|
-
exports.t2length = t2length;
|
package/lib/Canvas.d.ts
CHANGED
package/lib/Canvas.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const Util_1 = require("./Util");
|
|
5
|
-
const Context_1 = require("./Context");
|
|
6
|
-
const Global_1 = require("./Global");
|
|
1
|
+
import { Util } from "./Util.js";
|
|
2
|
+
import { SceneContext, HitContext } from "./Context.js";
|
|
3
|
+
import { Konva } from "./Global.js";
|
|
7
4
|
let _pixelRatio;
|
|
8
5
|
function getDevicePixelRatio() {
|
|
9
6
|
if (_pixelRatio) {
|
|
10
7
|
return _pixelRatio;
|
|
11
8
|
}
|
|
12
|
-
const canvas =
|
|
9
|
+
const canvas = Util.createCanvasElement();
|
|
13
10
|
const context = canvas.getContext('2d');
|
|
14
11
|
_pixelRatio = (function () {
|
|
15
|
-
const devicePixelRatio =
|
|
12
|
+
const devicePixelRatio = Konva._global.devicePixelRatio || 1, backingStoreRatio = context.webkitBackingStorePixelRatio ||
|
|
16
13
|
context.mozBackingStorePixelRatio ||
|
|
17
14
|
context.msBackingStorePixelRatio ||
|
|
18
15
|
context.oBackingStorePixelRatio ||
|
|
@@ -20,19 +17,19 @@ function getDevicePixelRatio() {
|
|
|
20
17
|
1;
|
|
21
18
|
return devicePixelRatio / backingStoreRatio;
|
|
22
19
|
})();
|
|
23
|
-
|
|
20
|
+
Util.releaseCanvas(canvas);
|
|
24
21
|
return _pixelRatio;
|
|
25
22
|
}
|
|
26
|
-
class Canvas {
|
|
23
|
+
export class Canvas {
|
|
27
24
|
constructor(config) {
|
|
28
25
|
this.pixelRatio = 1;
|
|
29
26
|
this.width = 0;
|
|
30
27
|
this.height = 0;
|
|
31
28
|
this.isCache = false;
|
|
32
29
|
const conf = config || {};
|
|
33
|
-
const pixelRatio = conf.pixelRatio ||
|
|
30
|
+
const pixelRatio = conf.pixelRatio || Konva.pixelRatio || getDevicePixelRatio();
|
|
34
31
|
this.pixelRatio = pixelRatio;
|
|
35
|
-
this._canvas =
|
|
32
|
+
this._canvas = Util.createCanvasElement();
|
|
36
33
|
this._canvas.style.padding = '0';
|
|
37
34
|
this._canvas.style.margin = '0';
|
|
38
35
|
this._canvas.style.border = '0';
|
|
@@ -83,7 +80,7 @@ class Canvas {
|
|
|
83
80
|
return this._canvas.toDataURL();
|
|
84
81
|
}
|
|
85
82
|
catch (err) {
|
|
86
|
-
|
|
83
|
+
Util.error('Unable to get data URL. ' +
|
|
87
84
|
err.message +
|
|
88
85
|
' For more info read https://konvajs.org/docs/posts/Tainted_Canvas.html.');
|
|
89
86
|
return '';
|
|
@@ -91,23 +88,20 @@ class Canvas {
|
|
|
91
88
|
}
|
|
92
89
|
}
|
|
93
90
|
}
|
|
94
|
-
|
|
95
|
-
class SceneCanvas extends Canvas {
|
|
91
|
+
export class SceneCanvas extends Canvas {
|
|
96
92
|
constructor(config = { width: 0, height: 0, willReadFrequently: false }) {
|
|
97
93
|
super(config);
|
|
98
|
-
this.context = new
|
|
94
|
+
this.context = new SceneContext(this, {
|
|
99
95
|
willReadFrequently: config.willReadFrequently,
|
|
100
96
|
});
|
|
101
97
|
this.setSize(config.width, config.height);
|
|
102
98
|
}
|
|
103
99
|
}
|
|
104
|
-
|
|
105
|
-
class HitCanvas extends Canvas {
|
|
100
|
+
export class HitCanvas extends Canvas {
|
|
106
101
|
constructor(config = { width: 0, height: 0 }) {
|
|
107
102
|
super(config);
|
|
108
103
|
this.hitCanvas = true;
|
|
109
|
-
this.context = new
|
|
104
|
+
this.context = new HitContext(this);
|
|
110
105
|
this.setSize(config.width, config.height);
|
|
111
106
|
}
|
|
112
107
|
}
|
|
113
|
-
exports.HitCanvas = HitCanvas;
|
package/lib/Container.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { HitCanvas, SceneCanvas } from './Canvas.
|
|
2
|
-
import { SceneContext } from './Context.
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import type { HitCanvas, SceneCanvas } from './Canvas.ts';
|
|
2
|
+
import type { SceneContext } from './Context.ts';
|
|
3
|
+
import type { NodeConfig } from './Node.ts';
|
|
4
|
+
import { Node } from './Node.ts';
|
|
5
|
+
import type { Shape } from './Shape.ts';
|
|
6
|
+
import type { GetSet, IRect } from './types.ts';
|
|
6
7
|
export type ClipFuncOutput = void | [Path2D | CanvasFillRule] | [Path2D, CanvasFillRule];
|
|
7
8
|
export interface ContainerConfig extends NodeConfig {
|
|
8
9
|
clearBeforeDraw?: boolean;
|
|
@@ -32,7 +33,7 @@ export declare abstract class Container<ChildType extends Node = Node> extends N
|
|
|
32
33
|
};
|
|
33
34
|
isAncestorOf(node: Node): boolean;
|
|
34
35
|
clone(obj?: any): this;
|
|
35
|
-
getAllIntersections(pos: any): Shape<import("./Shape.
|
|
36
|
+
getAllIntersections(pos: any): Shape<import("./Shape.ts").ShapeConfig>[];
|
|
36
37
|
_clearSelfAndDescendantCache(attr?: string): void;
|
|
37
38
|
_setChildrenIndices(): void;
|
|
38
39
|
drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas): this;
|
package/lib/Container.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const Node_1 = require("./Node");
|
|
6
|
-
const Validators_1 = require("./Validators");
|
|
7
|
-
class Container extends Node_1.Node {
|
|
1
|
+
import { Factory } from "./Factory.js";
|
|
2
|
+
import { Node } from "./Node.js";
|
|
3
|
+
import { getNumberValidator } from "./Validators.js";
|
|
4
|
+
export class Container extends Node {
|
|
8
5
|
constructor() {
|
|
9
6
|
super(...arguments);
|
|
10
7
|
this.children = [];
|
|
@@ -112,7 +109,7 @@ class Container extends Node_1.Node {
|
|
|
112
109
|
return false;
|
|
113
110
|
}
|
|
114
111
|
toObject() {
|
|
115
|
-
const obj =
|
|
112
|
+
const obj = Node.prototype.toObject.call(this);
|
|
116
113
|
obj.children = [];
|
|
117
114
|
this.getChildren().forEach((child) => {
|
|
118
115
|
obj.children.push(child.toObject());
|
|
@@ -130,7 +127,7 @@ class Container extends Node_1.Node {
|
|
|
130
127
|
return false;
|
|
131
128
|
}
|
|
132
129
|
clone(obj) {
|
|
133
|
-
const node =
|
|
130
|
+
const node = Node.prototype.clone.call(this, obj);
|
|
134
131
|
this.getChildren().forEach(function (no) {
|
|
135
132
|
node.add(no.clone());
|
|
136
133
|
});
|
|
@@ -306,15 +303,14 @@ class Container extends Node_1.Node {
|
|
|
306
303
|
return selfRect;
|
|
307
304
|
}
|
|
308
305
|
}
|
|
309
|
-
|
|
310
|
-
Factory_1.Factory.addComponentsGetterSetter(Container, 'clip', [
|
|
306
|
+
Factory.addComponentsGetterSetter(Container, 'clip', [
|
|
311
307
|
'x',
|
|
312
308
|
'y',
|
|
313
309
|
'width',
|
|
314
310
|
'height',
|
|
315
311
|
]);
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
312
|
+
Factory.addGetterSetter(Container, 'clipX', undefined, getNumberValidator());
|
|
313
|
+
Factory.addGetterSetter(Container, 'clipY', undefined, getNumberValidator());
|
|
314
|
+
Factory.addGetterSetter(Container, 'clipWidth', undefined, getNumberValidator());
|
|
315
|
+
Factory.addGetterSetter(Container, 'clipHeight', undefined, getNumberValidator());
|
|
316
|
+
Factory.addGetterSetter(Container, 'clipFunc');
|
package/lib/Context.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Canvas } from './Canvas.
|
|
2
|
-
import { Shape } from './Shape.
|
|
3
|
-
import { IRect } from './types.
|
|
4
|
-
import type { Node } from './Node.
|
|
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"];
|
|
1
|
+
import type { Canvas } from './Canvas.ts';
|
|
2
|
+
import type { Shape } from './Shape.ts';
|
|
3
|
+
import type { IRect } from './types.ts';
|
|
4
|
+
import type { Node } from './Node.ts';
|
|
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", "filter"];
|
|
6
|
+
export declare function isCSSFiltersSupported(): boolean;
|
|
6
7
|
interface ExtendedCanvasRenderingContext2D extends CanvasRenderingContext2D {
|
|
7
8
|
letterSpacing: string;
|
|
8
9
|
}
|
|
@@ -25,6 +26,7 @@ export declare class Context {
|
|
|
25
26
|
_applyLineCap(shape: Shape): void;
|
|
26
27
|
_applyOpacity(shape: Node): void;
|
|
27
28
|
_applyLineJoin(shape: Shape): void;
|
|
29
|
+
_applyMiterLimit(shape: Shape): void;
|
|
28
30
|
setAttr(attr: string, val: any): void;
|
|
29
31
|
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterClockwise?: boolean): void;
|
|
30
32
|
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
|
package/lib/Context.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.HitContext = exports.SceneContext = exports.Context = void 0;
|
|
4
|
-
const Util_1 = require("./Util");
|
|
5
|
-
const Global_1 = require("./Global");
|
|
1
|
+
import { Util } from "./Util.js";
|
|
2
|
+
import { Konva } from "./Global.js";
|
|
6
3
|
function simplifyArray(arr) {
|
|
7
|
-
const retArr = [], len = arr.length, util =
|
|
4
|
+
const retArr = [], len = arr.length, util = Util;
|
|
8
5
|
for (let n = 0; n < len; n++) {
|
|
9
6
|
let val = arr[n];
|
|
10
7
|
if (util._isNumber(val)) {
|
|
@@ -71,12 +68,32 @@ const CONTEXT_PROPERTIES = [
|
|
|
71
68
|
'globalAlpha',
|
|
72
69
|
'globalCompositeOperation',
|
|
73
70
|
'imageSmoothingEnabled',
|
|
71
|
+
'filter',
|
|
74
72
|
];
|
|
75
73
|
const traceArrMax = 100;
|
|
76
|
-
|
|
74
|
+
let _cssFiltersSupported = null;
|
|
75
|
+
export function isCSSFiltersSupported() {
|
|
76
|
+
if (_cssFiltersSupported !== null) {
|
|
77
|
+
return _cssFiltersSupported;
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const canvas = Util.createCanvasElement();
|
|
81
|
+
const ctx = canvas.getContext('2d');
|
|
82
|
+
if (!ctx) {
|
|
83
|
+
_cssFiltersSupported = false;
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
return !!ctx && 'filter' in ctx;
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
_cssFiltersSupported = false;
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export class Context {
|
|
77
94
|
constructor(canvas) {
|
|
78
95
|
this.canvas = canvas;
|
|
79
|
-
if (
|
|
96
|
+
if (Konva.enableTrace) {
|
|
80
97
|
this.traceArr = [];
|
|
81
98
|
this._enableTrace();
|
|
82
99
|
}
|
|
@@ -117,7 +134,7 @@ class Context {
|
|
|
117
134
|
str += DOUBLE_PAREN;
|
|
118
135
|
}
|
|
119
136
|
else {
|
|
120
|
-
if (
|
|
137
|
+
if (Util._isArray(args[0])) {
|
|
121
138
|
str += OPEN_PAREN_BRACKET + args.join(COMMA) + CLOSE_BRACKET_PAREN;
|
|
122
139
|
}
|
|
123
140
|
else {
|
|
@@ -183,6 +200,12 @@ class Context {
|
|
|
183
200
|
this.setAttr('lineJoin', lineJoin);
|
|
184
201
|
}
|
|
185
202
|
}
|
|
203
|
+
_applyMiterLimit(shape) {
|
|
204
|
+
const miterLimit = shape.attrs.miterLimit;
|
|
205
|
+
if (miterLimit != null) {
|
|
206
|
+
this.setAttr('miterLimit', miterLimit);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
186
209
|
setAttr(attr, val) {
|
|
187
210
|
this._context[attr] = val;
|
|
188
211
|
}
|
|
@@ -373,7 +396,6 @@ class Context {
|
|
|
373
396
|
}
|
|
374
397
|
}
|
|
375
398
|
}
|
|
376
|
-
exports.Context = Context;
|
|
377
399
|
CONTEXT_PROPERTIES.forEach(function (prop) {
|
|
378
400
|
Object.defineProperty(Context.prototype, prop, {
|
|
379
401
|
get() {
|
|
@@ -384,7 +406,7 @@ CONTEXT_PROPERTIES.forEach(function (prop) {
|
|
|
384
406
|
},
|
|
385
407
|
});
|
|
386
408
|
});
|
|
387
|
-
class SceneContext extends Context {
|
|
409
|
+
export class SceneContext extends Context {
|
|
388
410
|
constructor(canvas, { willReadFrequently = false } = {}) {
|
|
389
411
|
super(canvas);
|
|
390
412
|
this._context = canvas._canvas.getContext('2d', {
|
|
@@ -499,8 +521,7 @@ class SceneContext extends Context {
|
|
|
499
521
|
this.setAttr('shadowOffsetY', offset.y * scaleY);
|
|
500
522
|
}
|
|
501
523
|
}
|
|
502
|
-
|
|
503
|
-
class HitContext extends Context {
|
|
524
|
+
export class HitContext extends Context {
|
|
504
525
|
constructor(canvas) {
|
|
505
526
|
super(canvas);
|
|
506
527
|
this._context = canvas._canvas.getContext('2d', {
|
|
@@ -538,4 +559,3 @@ class HitContext extends Context {
|
|
|
538
559
|
}
|
|
539
560
|
}
|
|
540
561
|
}
|
|
541
|
-
exports.HitContext = HitContext;
|
package/lib/Core.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { Konva } from './_CoreInternals.
|
|
2
|
-
import { Konva } from './_CoreInternals.
|
|
1
|
+
export { Konva } from './_CoreInternals.ts';
|
|
2
|
+
import { Konva } from './_CoreInternals.ts';
|
|
3
3
|
export default Konva;
|
package/lib/Core.js
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var _CoreInternals_1 = require("./_CoreInternals");
|
|
5
|
-
Object.defineProperty(exports, "Konva", { enumerable: true, get: function () { return _CoreInternals_1.Konva; } });
|
|
6
|
-
const _CoreInternals_2 = require("./_CoreInternals");
|
|
7
|
-
module.exports = _CoreInternals_2.Konva;
|
|
1
|
+
export { Konva } from "./_CoreInternals.js";
|
|
2
|
+
import { Konva } from "./_CoreInternals.js";
|
|
3
|
+
export default Konva;
|
package/lib/DragAndDrop.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Node } from './Node.
|
|
2
|
-
import { Vector2d } from './types.
|
|
1
|
+
import type { Node } from './Node.ts';
|
|
2
|
+
import type { Vector2d } from './types.ts';
|
|
3
3
|
export declare const DD: {
|
|
4
4
|
readonly isDragging: boolean;
|
|
5
5
|
justDragged: boolean;
|
|
6
|
-
readonly node: Node<import("./Node.
|
|
6
|
+
readonly node: Node<import("./Node.ts").NodeConfig> | undefined;
|
|
7
7
|
_dragElements: Map<number, {
|
|
8
8
|
node: Node;
|
|
9
9
|
startPointerPos: Vector2d;
|
package/lib/DragAndDrop.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const Global_1 = require("./Global");
|
|
5
|
-
const Util_1 = require("./Util");
|
|
6
|
-
exports.DD = {
|
|
1
|
+
import { Konva } from "./Global.js";
|
|
2
|
+
import { Util } from "./Util.js";
|
|
3
|
+
export const DD = {
|
|
7
4
|
get isDragging() {
|
|
8
5
|
let flag = false;
|
|
9
|
-
|
|
6
|
+
DD._dragElements.forEach((elem) => {
|
|
10
7
|
if (elem.dragStatus === 'dragging') {
|
|
11
8
|
flag = true;
|
|
12
9
|
}
|
|
@@ -16,7 +13,7 @@ exports.DD = {
|
|
|
16
13
|
justDragged: false,
|
|
17
14
|
get node() {
|
|
18
15
|
let node;
|
|
19
|
-
|
|
16
|
+
DD._dragElements.forEach((elem) => {
|
|
20
17
|
node = elem.node;
|
|
21
18
|
});
|
|
22
19
|
return node;
|
|
@@ -24,12 +21,12 @@ exports.DD = {
|
|
|
24
21
|
_dragElements: new Map(),
|
|
25
22
|
_drag(evt) {
|
|
26
23
|
const nodesToFireEvents = [];
|
|
27
|
-
|
|
24
|
+
DD._dragElements.forEach((elem, key) => {
|
|
28
25
|
const { node } = elem;
|
|
29
26
|
const stage = node.getStage();
|
|
30
27
|
stage.setPointersPositions(evt);
|
|
31
28
|
if (elem.pointerId === undefined) {
|
|
32
|
-
elem.pointerId =
|
|
29
|
+
elem.pointerId = Util._getFirstPointerId(evt);
|
|
33
30
|
}
|
|
34
31
|
const pos = stage._changedPointerPositions.find((pos) => pos.id === elem.pointerId);
|
|
35
32
|
if (!pos) {
|
|
@@ -59,7 +56,7 @@ exports.DD = {
|
|
|
59
56
|
},
|
|
60
57
|
_endDragBefore(evt) {
|
|
61
58
|
const drawNodes = [];
|
|
62
|
-
|
|
59
|
+
DD._dragElements.forEach((elem) => {
|
|
63
60
|
const { node } = elem;
|
|
64
61
|
const stage = node.getStage();
|
|
65
62
|
if (evt) {
|
|
@@ -70,14 +67,14 @@ exports.DD = {
|
|
|
70
67
|
return;
|
|
71
68
|
}
|
|
72
69
|
if (elem.dragStatus === 'dragging' || elem.dragStatus === 'stopped') {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
DD.justDragged = true;
|
|
71
|
+
Konva._mouseListenClick = false;
|
|
72
|
+
Konva._touchListenClick = false;
|
|
73
|
+
Konva._pointerListenClick = false;
|
|
77
74
|
elem.dragStatus = 'stopped';
|
|
78
75
|
}
|
|
79
76
|
const drawNode = elem.node.getLayer() ||
|
|
80
|
-
(elem.node instanceof
|
|
77
|
+
(elem.node instanceof Konva['Stage'] && elem.node);
|
|
81
78
|
if (drawNode && drawNodes.indexOf(drawNode) === -1) {
|
|
82
79
|
drawNodes.push(drawNode);
|
|
83
80
|
}
|
|
@@ -87,7 +84,7 @@ exports.DD = {
|
|
|
87
84
|
});
|
|
88
85
|
},
|
|
89
86
|
_endDragAfter(evt) {
|
|
90
|
-
|
|
87
|
+
DD._dragElements.forEach((elem, key) => {
|
|
91
88
|
if (elem.dragStatus === 'stopped') {
|
|
92
89
|
elem.node.fire('dragend', {
|
|
93
90
|
type: 'dragend',
|
|
@@ -96,18 +93,18 @@ exports.DD = {
|
|
|
96
93
|
}, true);
|
|
97
94
|
}
|
|
98
95
|
if (elem.dragStatus !== 'dragging') {
|
|
99
|
-
|
|
96
|
+
DD._dragElements.delete(key);
|
|
100
97
|
}
|
|
101
98
|
});
|
|
102
99
|
},
|
|
103
100
|
};
|
|
104
|
-
if (
|
|
105
|
-
window.addEventListener('mouseup',
|
|
106
|
-
window.addEventListener('touchend',
|
|
107
|
-
window.addEventListener('touchcancel',
|
|
108
|
-
window.addEventListener('mousemove',
|
|
109
|
-
window.addEventListener('touchmove',
|
|
110
|
-
window.addEventListener('mouseup',
|
|
111
|
-
window.addEventListener('touchend',
|
|
112
|
-
window.addEventListener('touchcancel',
|
|
101
|
+
if (Konva.isBrowser) {
|
|
102
|
+
window.addEventListener('mouseup', DD._endDragBefore, true);
|
|
103
|
+
window.addEventListener('touchend', DD._endDragBefore, true);
|
|
104
|
+
window.addEventListener('touchcancel', DD._endDragBefore, true);
|
|
105
|
+
window.addEventListener('mousemove', DD._drag);
|
|
106
|
+
window.addEventListener('touchmove', DD._drag);
|
|
107
|
+
window.addEventListener('mouseup', DD._endDragAfter, false);
|
|
108
|
+
window.addEventListener('touchend', DD._endDragAfter, false);
|
|
109
|
+
window.addEventListener('touchcancel', DD._endDragAfter, false);
|
|
113
110
|
}
|
package/lib/Factory.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Node } from './Node.
|
|
2
|
-
import { GetSet } from './types.
|
|
1
|
+
import type { Node } from './Node.ts';
|
|
2
|
+
import type { GetSet } from './types.ts';
|
|
3
3
|
type EnforceString<T> = T extends string ? T : never;
|
|
4
4
|
type Constructor = abstract new (...args: any) => any;
|
|
5
5
|
type Attr<T extends Constructor> = EnforceString<keyof InstanceType<T>>;
|