konva 9.1.0 → 9.2.1
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 +273 -682
- package/konva.min.js +3 -3
- package/lib/Animation.d.ts +4 -4
- package/lib/Animation.js +27 -26
- package/lib/Container.d.ts +9 -7
- package/lib/Container.js +5 -5
- package/lib/Context.d.ts +29 -27
- package/lib/Context.js +55 -60
- package/lib/DragAndDrop.d.ts +2 -2
- package/lib/Factory.d.ts +2 -1
- package/lib/Global.d.ts +3 -3
- package/lib/Global.js +2 -2
- package/lib/Layer.d.ts +4 -4
- package/lib/Node.d.ts +15 -15
- package/lib/Node.js +15 -12
- package/lib/PointerEvents.d.ts +1 -1
- package/lib/Shape.d.ts +9 -7
- package/lib/Shape.js +17 -5
- package/lib/Stage.d.ts +10 -10
- package/lib/Stage.js +24 -21
- package/lib/Tween.d.ts +3 -3
- package/lib/Util.d.ts +58 -18
- package/lib/Util.js +7 -3
- package/lib/Validators.d.ts +9 -9
- package/lib/_CoreInternals.d.ts +62 -22
- package/lib/_FullInternals.d.ts +62 -22
- package/lib/filters/Blur.js +49 -512
- package/lib/shapes/Path.d.ts +6 -6
- package/lib/shapes/Path.js +1 -1
- package/lib/shapes/RegularPolygon.d.ts +4 -4
- package/lib/shapes/Text.d.ts +1 -0
- package/lib/shapes/Text.js +9 -0
- package/lib/shapes/TextPath.d.ts +6 -5
- package/lib/shapes/Transformer.d.ts +4 -2
- package/lib/shapes/Transformer.js +21 -14
- package/lib/types.d.ts +1 -1
- package/package.json +11 -11
|
@@ -13,6 +13,7 @@ export interface TransformerConfig extends ContainerConfig {
|
|
|
13
13
|
rotationSnaps?: Array<number>;
|
|
14
14
|
rotationSnapTolerance?: number;
|
|
15
15
|
rotateAnchorOffset?: number;
|
|
16
|
+
rotateAnchorCursor?: string;
|
|
16
17
|
borderEnabled?: boolean;
|
|
17
18
|
borderStroke?: string;
|
|
18
19
|
borderStrokeWidth?: number;
|
|
@@ -35,7 +36,7 @@ export interface TransformerConfig extends ContainerConfig {
|
|
|
35
36
|
}
|
|
36
37
|
export declare class Transformer extends Group {
|
|
37
38
|
_nodes: Array<Node>;
|
|
38
|
-
_movingAnchorName: string;
|
|
39
|
+
_movingAnchorName: string | null;
|
|
39
40
|
_transforming: boolean;
|
|
40
41
|
_anchorDragOffset: Vector2d;
|
|
41
42
|
sin: number;
|
|
@@ -49,7 +50,7 @@ export declare class Transformer extends Group {
|
|
|
49
50
|
setNodes(nodes?: Array<Node>): this;
|
|
50
51
|
_proxyDrag(node: Node): void;
|
|
51
52
|
getNodes(): Node<import("../Node.js").NodeConfig>[];
|
|
52
|
-
getActiveAnchor(): string;
|
|
53
|
+
getActiveAnchor(): string | null;
|
|
53
54
|
detach(): void;
|
|
54
55
|
_resetTransformCache(): void;
|
|
55
56
|
_getNodeRect(): any;
|
|
@@ -97,6 +98,7 @@ export declare class Transformer extends Group {
|
|
|
97
98
|
rotateEnabled: GetSet<boolean, this>;
|
|
98
99
|
rotateAnchorOffset: GetSet<number, this>;
|
|
99
100
|
rotationSnapTolerance: GetSet<number, this>;
|
|
101
|
+
rotateAnchorCursor: GetSet<string, this>;
|
|
100
102
|
padding: GetSet<number, this>;
|
|
101
103
|
borderEnabled: GetSet<boolean, this>;
|
|
102
104
|
borderStroke: GetSet<string, this>;
|
|
@@ -55,9 +55,9 @@ var ANGLES = {
|
|
|
55
55
|
'bottom-right': 135,
|
|
56
56
|
};
|
|
57
57
|
const TOUCH_DEVICE = 'ontouchstart' in Global_1.Konva._global;
|
|
58
|
-
function getCursor(anchorName, rad) {
|
|
58
|
+
function getCursor(anchorName, rad, rotateCursor) {
|
|
59
59
|
if (anchorName === 'rotater') {
|
|
60
|
-
return
|
|
60
|
+
return rotateCursor;
|
|
61
61
|
}
|
|
62
62
|
rad += Util_1.Util.degToRad(ANGLES[anchorName] || 0);
|
|
63
63
|
var angle = ((Util_1.Util.radToDeg(rad) % 360) + 360) % 360;
|
|
@@ -118,8 +118,12 @@ function rotateAroundPoint(shape, angleRad, point) {
|
|
|
118
118
|
const y = point.y +
|
|
119
119
|
(shape.x - point.x) * Math.sin(angleRad) +
|
|
120
120
|
(shape.y - point.y) * Math.cos(angleRad);
|
|
121
|
-
return
|
|
122
|
-
|
|
121
|
+
return {
|
|
122
|
+
...shape,
|
|
123
|
+
rotation: shape.rotation + angleRad,
|
|
124
|
+
x,
|
|
125
|
+
y,
|
|
126
|
+
};
|
|
123
127
|
}
|
|
124
128
|
function rotateAroundCenter(shape, deltaRad) {
|
|
125
129
|
const center = getCenter(shape);
|
|
@@ -140,6 +144,7 @@ function getSnap(snaps, newRotationRad, tol) {
|
|
|
140
144
|
class Transformer extends Group_1.Group {
|
|
141
145
|
constructor(config) {
|
|
142
146
|
super(config);
|
|
147
|
+
this._movingAnchorName = null;
|
|
143
148
|
this._transforming = false;
|
|
144
149
|
this._createElements();
|
|
145
150
|
this._handleMouseMove = this._handleMouseMove.bind(this);
|
|
@@ -318,7 +323,7 @@ class Transformer extends Group_1.Group {
|
|
|
318
323
|
});
|
|
319
324
|
const tr = new Util_1.Transform();
|
|
320
325
|
tr.rotate(-Global_1.Konva.getAngle(this.rotation()));
|
|
321
|
-
var minX, minY, maxX, maxY;
|
|
326
|
+
var minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
|
322
327
|
totalPoints.forEach(function (point) {
|
|
323
328
|
var transformed = tr.point(point);
|
|
324
329
|
if (minX === undefined) {
|
|
@@ -354,9 +359,9 @@ class Transformer extends Group_1.Group {
|
|
|
354
359
|
}
|
|
355
360
|
_createElements() {
|
|
356
361
|
this._createBack();
|
|
357
|
-
ANCHORS_NAMES.forEach(
|
|
362
|
+
ANCHORS_NAMES.forEach((name) => {
|
|
358
363
|
this._createAnchor(name);
|
|
359
|
-
}
|
|
364
|
+
});
|
|
360
365
|
this._createAnchor('rotater');
|
|
361
366
|
}
|
|
362
367
|
_createAnchor(name) {
|
|
@@ -382,7 +387,8 @@ class Transformer extends Group_1.Group {
|
|
|
382
387
|
});
|
|
383
388
|
anchor.on('mouseenter', () => {
|
|
384
389
|
var rad = Global_1.Konva.getAngle(this.rotation());
|
|
385
|
-
var
|
|
390
|
+
var rotateCursor = this.rotateAnchorCursor();
|
|
391
|
+
var cursor = getCursor(name, rad, rotateCursor);
|
|
386
392
|
anchor.getStage().content &&
|
|
387
393
|
(anchor.getStage().content.style.cursor = cursor);
|
|
388
394
|
this._cursorChange = true;
|
|
@@ -400,16 +406,16 @@ class Transformer extends Group_1.Group {
|
|
|
400
406
|
width: 0,
|
|
401
407
|
height: 0,
|
|
402
408
|
draggable: true,
|
|
403
|
-
sceneFunc(ctx) {
|
|
404
|
-
var tr =
|
|
409
|
+
sceneFunc(ctx, shape) {
|
|
410
|
+
var tr = shape.getParent();
|
|
405
411
|
var padding = tr.padding();
|
|
406
412
|
ctx.beginPath();
|
|
407
|
-
ctx.rect(-padding, -padding,
|
|
408
|
-
ctx.moveTo(
|
|
413
|
+
ctx.rect(-padding, -padding, shape.width() + padding * 2, shape.height() + padding * 2);
|
|
414
|
+
ctx.moveTo(shape.width() / 2, -padding);
|
|
409
415
|
if (tr.rotateEnabled()) {
|
|
410
|
-
ctx.lineTo(
|
|
416
|
+
ctx.lineTo(shape.width() / 2, -tr.rotateAnchorOffset() * Util_1.Util._sign(shape.height()) - padding);
|
|
411
417
|
}
|
|
412
|
-
ctx.fillStrokeShape(
|
|
418
|
+
ctx.fillStrokeShape(shape);
|
|
413
419
|
},
|
|
414
420
|
hitFunc: (ctx, shape) => {
|
|
415
421
|
if (!this.shouldOverdrawWholeArea()) {
|
|
@@ -963,6 +969,7 @@ Factory_1.Factory.addGetterSetter(Transformer, 'anchorSize', 10, (0, Validators_
|
|
|
963
969
|
Factory_1.Factory.addGetterSetter(Transformer, 'rotateEnabled', true);
|
|
964
970
|
Factory_1.Factory.addGetterSetter(Transformer, 'rotationSnaps', []);
|
|
965
971
|
Factory_1.Factory.addGetterSetter(Transformer, 'rotateAnchorOffset', 50, (0, Validators_1.getNumberValidator)());
|
|
972
|
+
Factory_1.Factory.addGetterSetter(Transformer, 'rotateAnchorCursor', 'crosshair');
|
|
966
973
|
Factory_1.Factory.addGetterSetter(Transformer, 'rotationSnapTolerance', 5, (0, Validators_1.getNumberValidator)());
|
|
967
974
|
Factory_1.Factory.addGetterSetter(Transformer, 'borderEnabled', true);
|
|
968
975
|
Factory_1.Factory.addGetterSetter(Transformer, 'anchorStroke', 'rgb(0, 161, 255)');
|
package/lib/types.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface Vector2d {
|
|
|
9
9
|
export interface PathSegment {
|
|
10
10
|
command: 'm' | 'M' | 'l' | 'L' | 'v' | 'V' | 'h' | 'H' | 'z' | 'Z' | 'c' | 'C' | 'q' | 'Q' | 't' | 'T' | 's' | 'S' | 'a' | 'A';
|
|
11
11
|
start: Vector2d;
|
|
12
|
-
points:
|
|
12
|
+
points: number[];
|
|
13
13
|
pathLength: number;
|
|
14
14
|
}
|
|
15
15
|
export interface IRect {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "konva",
|
|
3
|
-
"version": "9.1
|
|
3
|
+
"version": "9.2.1",
|
|
4
4
|
"author": "Anton Lavrenov",
|
|
5
5
|
"files": [
|
|
6
6
|
"README.md",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"test": "npm run test:browser && npm run test:node",
|
|
21
21
|
"test:build": "parcel build ./test/unit-tests.html --dist-dir ./test-build --target none --public-url ./ --no-source-maps",
|
|
22
22
|
"test:browser": "npm run test:build && mocha-headless-chrome -f ./test-build/unit-tests.html -a disable-web-security",
|
|
23
|
-
"test:
|
|
24
|
-
"test:
|
|
23
|
+
"test:watch": "rm -rf ./.parcel-cache && parcel serve ./test/unit-tests.html ./test/manual-tests.html ./test/sandbox.html ./test/text-paths.html ./test/bunnies.html",
|
|
24
|
+
"test:node": "ts-mocha -r ./test/node-global-setup.mjs -p ./test/tsconfig.json test/unit/**/*.ts --exit && npm run test:import",
|
|
25
25
|
"tsc": "tsc --removeComments",
|
|
26
26
|
"rollup": "rollup -c --bundleConfigAsCjs",
|
|
27
27
|
"clean": "rm -rf ./lib && rm -rf ./types && rm -rf ./cmj && rm -rf ./test-build",
|
|
@@ -59,11 +59,11 @@
|
|
|
59
59
|
}
|
|
60
60
|
],
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@parcel/transformer-image": "2.
|
|
63
|
-
"@size-limit/preset-big-lib": "^8.2.
|
|
62
|
+
"@parcel/transformer-image": "2.9.3",
|
|
63
|
+
"@size-limit/preset-big-lib": "^8.2.6",
|
|
64
64
|
"@types/mocha": "^10.0.1",
|
|
65
65
|
"canvas": "^2.11.2",
|
|
66
|
-
"chai": "4.3.
|
|
66
|
+
"chai": "4.3.8",
|
|
67
67
|
"filehound": "^1.17.6",
|
|
68
68
|
"gulp": "^4.0.2",
|
|
69
69
|
"gulp-concat": "^2.6.1",
|
|
@@ -78,17 +78,17 @@
|
|
|
78
78
|
"gulp-util": "^3.0.8",
|
|
79
79
|
"mocha": "10.2.0",
|
|
80
80
|
"mocha-headless-chrome": "^4.0.0",
|
|
81
|
-
"parcel": "2.
|
|
81
|
+
"parcel": "2.9.3",
|
|
82
82
|
"process": "^0.11.10",
|
|
83
|
-
"rollup": "^3.
|
|
83
|
+
"rollup": "^3.28.1",
|
|
84
84
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
85
85
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
86
86
|
"rollup-plugin-sourcemaps": "^0.6.3",
|
|
87
|
-
"rollup-plugin-typescript2": "^0.
|
|
88
|
-
"size-limit": "^8.2.
|
|
87
|
+
"rollup-plugin-typescript2": "^0.35.0",
|
|
88
|
+
"size-limit": "^8.2.6",
|
|
89
89
|
"ts-mocha": "^10.0.0",
|
|
90
90
|
"ts-node": "^10.9.1",
|
|
91
|
-
"typescript": "^5.
|
|
91
|
+
"typescript": "^5.2.2"
|
|
92
92
|
},
|
|
93
93
|
"keywords": [
|
|
94
94
|
"canvas",
|