konva 10.4.0 → 10.6.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 +4 -4
- package/konva.js +3432 -3746
- package/konva.min.js +4 -4
- package/lib/Animation.d.ts +2 -2
- package/lib/Animation.js +2 -2
- package/lib/BezierFunctions.d.ts +1 -1
- package/lib/BezierFunctions.js +76 -116
- package/lib/Canvas.d.ts +1 -1
- package/lib/Canvas.js +8 -5
- package/lib/Container.js +9 -6
- package/lib/Context.d.ts +4 -5
- package/lib/Context.js +77 -72
- package/lib/DragAndDrop.d.ts +5 -3
- package/lib/DragAndDrop.js +65 -29
- package/lib/Factory.d.ts +3 -2
- package/lib/Factory.js +10 -9
- package/lib/Global.d.ts +0 -6
- package/lib/Global.js +2 -8
- package/lib/Layer.js +9 -6
- package/lib/Node.d.ts +33 -15
- package/lib/Node.js +179 -135
- package/lib/PointerEvents.d.ts +1 -2
- package/lib/PointerEvents.js +20 -18
- package/lib/Shape.d.ts +2 -2
- package/lib/Shape.js +51 -7
- package/lib/Stage.d.ts +23 -14
- package/lib/Stage.js +221 -93
- package/lib/Tween.js +59 -66
- package/lib/Util.d.ts +3 -2
- package/lib/Util.js +43 -16
- package/lib/_CoreInternals.d.ts +25 -11
- package/lib/_FullInternals.d.ts +25 -11
- package/lib/filters/Blur.js +16 -12
- package/lib/filters/Brighten.d.ts +1 -0
- package/lib/filters/Brighten.js +1 -0
- package/lib/filters/Brightness.d.ts +2 -1
- package/lib/filters/Brightness.js +4 -4
- package/lib/filters/Emboss.js +16 -58
- package/lib/filters/Kaleidoscope.js +8 -15
- package/lib/filters/Mask.js +8 -8
- package/lib/filters/Pixelate.js +16 -29
- package/lib/filters/Threshold.d.ts +1 -1
- package/lib/filters/Threshold.js +1 -1
- package/lib/shapes/Arc.js +5 -3
- package/lib/shapes/Arrow.d.ts +2 -6
- package/lib/shapes/Arrow.js +68 -46
- package/lib/shapes/Image.js +16 -19
- package/lib/shapes/Label.d.ts +2 -3
- package/lib/shapes/Label.js +7 -21
- package/lib/shapes/Line.d.ts +1 -1
- package/lib/shapes/Line.js +1 -1
- package/lib/shapes/Path.d.ts +27 -2
- package/lib/shapes/Path.js +148 -142
- package/lib/shapes/RegularPolygon.js +1 -1
- package/lib/shapes/Sprite.js +2 -6
- package/lib/shapes/Text.d.ts +12 -4
- package/lib/shapes/Text.js +96 -54
- package/lib/shapes/TextPath.d.ts +4 -3
- package/lib/shapes/TextPath.js +40 -26
- package/lib/shapes/Transformer.d.ts +16 -1
- package/lib/shapes/Transformer.js +209 -130
- package/lib/types.d.ts +2 -2
- package/package.json +4 -3
package/lib/PointerEvents.js
CHANGED
|
@@ -3,17 +3,18 @@ const Captures = new Map();
|
|
|
3
3
|
// we may use this module for capturing touch events too
|
|
4
4
|
// so make sure we don't do something super specific to pointer
|
|
5
5
|
const SUPPORT_POINTER_EVENTS = Konva._global['PointerEvent'] !== undefined;
|
|
6
|
-
export function getCapturedShape(pointerId) {
|
|
7
|
-
|
|
6
|
+
export function getCapturedShape(pointerId, stage) {
|
|
7
|
+
const capture = Captures.get(pointerId);
|
|
8
|
+
return capture && (!stage || capture.stage === stage)
|
|
9
|
+
? capture.shape
|
|
10
|
+
: undefined;
|
|
8
11
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
evt,
|
|
12
|
-
pointerId: evt.pointerId,
|
|
13
|
-
};
|
|
12
|
+
function fireCapture(shape, type, pointerId) {
|
|
13
|
+
shape._fire(type, { evt: new PointerEvent(type, { pointerId }), pointerId });
|
|
14
14
|
}
|
|
15
15
|
export function hasPointerCapture(pointerId, shape) {
|
|
16
|
-
|
|
16
|
+
var _a;
|
|
17
|
+
return ((_a = Captures.get(pointerId)) === null || _a === void 0 ? void 0 : _a.shape) === shape;
|
|
17
18
|
}
|
|
18
19
|
export function setPointerCapture(pointerId, shape) {
|
|
19
20
|
var _a;
|
|
@@ -21,7 +22,8 @@ export function setPointerCapture(pointerId, shape) {
|
|
|
21
22
|
const stage = shape.getStage();
|
|
22
23
|
if (!stage)
|
|
23
24
|
return;
|
|
24
|
-
|
|
25
|
+
// Native capture belongs to this stage even if the shape is reparented.
|
|
26
|
+
Captures.set(pointerId, { shape, stage });
|
|
25
27
|
if (SUPPORT_POINTER_EVENTS) {
|
|
26
28
|
// capture on the DOM level too, so the stage keeps receiving the events
|
|
27
29
|
// of that pointer even when it moves outside of the stage container
|
|
@@ -34,32 +36,32 @@ export function setPointerCapture(pointerId, shape) {
|
|
|
34
36
|
// ids of mouse and touch events (999 and touch identifiers) and
|
|
35
37
|
// programmatic calls outside of a pointer event land here
|
|
36
38
|
}
|
|
37
|
-
shape
|
|
39
|
+
fireCapture(shape, 'gotpointercapture', pointerId);
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
|
-
//
|
|
42
|
+
// Destroying either the captured node or its native stage ends capture.
|
|
41
43
|
export function releaseCapturesOf(node) {
|
|
42
|
-
Captures.forEach((shape, pointerId) => {
|
|
43
|
-
if (shape === node) {
|
|
44
|
+
Captures.forEach(({ shape, stage }, pointerId) => {
|
|
45
|
+
if (shape === node || stage === node) {
|
|
44
46
|
releaseCapture(pointerId);
|
|
45
47
|
}
|
|
46
48
|
});
|
|
47
49
|
}
|
|
48
50
|
export function releaseCapture(pointerId, target) {
|
|
49
51
|
var _a;
|
|
50
|
-
const
|
|
52
|
+
const capture = Captures.get(pointerId);
|
|
51
53
|
// a node can only release its own capture
|
|
52
|
-
if (!
|
|
54
|
+
if (!capture || (target && capture.shape !== target))
|
|
53
55
|
return;
|
|
54
|
-
const stage =
|
|
56
|
+
const { shape, stage } = capture;
|
|
55
57
|
Captures.delete(pointerId);
|
|
56
58
|
if (SUPPORT_POINTER_EVENTS) {
|
|
57
59
|
try {
|
|
58
|
-
(_a = stage
|
|
60
|
+
(_a = stage.content) === null || _a === void 0 ? void 0 : _a.releasePointerCapture(pointerId);
|
|
59
61
|
}
|
|
60
62
|
catch (e) {
|
|
61
63
|
// same as in setPointerCapture: the pointer may not be active
|
|
62
64
|
}
|
|
63
|
-
shape
|
|
65
|
+
fireCapture(shape, 'lostpointercapture', pointerId);
|
|
64
66
|
}
|
|
65
67
|
}
|
package/lib/Shape.d.ts
CHANGED
|
@@ -191,10 +191,10 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
|
|
|
191
191
|
height: number;
|
|
192
192
|
};
|
|
193
193
|
getClientRect(config?: ShapeGetClientRectConfig): {
|
|
194
|
-
width: number;
|
|
195
|
-
height: number;
|
|
196
194
|
x: number;
|
|
197
195
|
y: number;
|
|
196
|
+
width: number;
|
|
197
|
+
height: number;
|
|
198
198
|
};
|
|
199
199
|
drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas): this;
|
|
200
200
|
drawHit(can?: HitCanvas, top?: Node): this;
|
package/lib/Shape.js
CHANGED
|
@@ -306,7 +306,7 @@ export class Shape extends Node {
|
|
|
306
306
|
}
|
|
307
307
|
const hasFill = forceFill || this.hasFill();
|
|
308
308
|
const hasStroke = this.hasStroke();
|
|
309
|
-
const isTransparent = this.getAbsoluteOpacity() !== 1;
|
|
309
|
+
const isTransparent = !this._isUnderCache && this.getAbsoluteOpacity() !== 1;
|
|
310
310
|
if (hasFill && hasStroke && isTransparent) {
|
|
311
311
|
return true;
|
|
312
312
|
}
|
|
@@ -361,8 +361,42 @@ export class Shape extends Node {
|
|
|
361
361
|
const fillRect = this.getSelfRect();
|
|
362
362
|
const applyStroke = !config.skipStroke && this.hasStroke();
|
|
363
363
|
const strokeWidth = (applyStroke && this.strokeWidth()) || 0;
|
|
364
|
-
|
|
365
|
-
|
|
364
|
+
let strokeWidthX = strokeWidth;
|
|
365
|
+
let strokeWidthY = strokeWidth;
|
|
366
|
+
let collapsedStroke;
|
|
367
|
+
if (strokeWidth && !this.strokeScaleEnabled()) {
|
|
368
|
+
// Strokes are constant in the canvas they are drawn into. A cached
|
|
369
|
+
// ancestor supplies that coordinate space until its bitmap is rebuilt.
|
|
370
|
+
let top = this;
|
|
371
|
+
while (top && !top.isCached() && !top._isUnderCache)
|
|
372
|
+
top = top.parent;
|
|
373
|
+
const [a, b, c, d] = this.getAbsoluteTransform(top).getMatrix();
|
|
374
|
+
const determinant = Math.abs(a * d - b * c);
|
|
375
|
+
if (determinant) {
|
|
376
|
+
strokeWidthX *= Math.hypot(c, d) / determinant;
|
|
377
|
+
strokeWidthY *= Math.hypot(a, b) / determinant;
|
|
378
|
+
}
|
|
379
|
+
else if (!skipTransform) {
|
|
380
|
+
// A collapsed path can still draw a stroke after the context resets
|
|
381
|
+
// its transform. Expand in the destination space in this case.
|
|
382
|
+
strokeWidthX = strokeWidthY = 0;
|
|
383
|
+
collapsedStroke = top
|
|
384
|
+
? top.getAbsoluteTransform().copy()
|
|
385
|
+
: new Transform();
|
|
386
|
+
if (relativeTo) {
|
|
387
|
+
const relativeTransform = relativeTo.getAbsoluteTransform();
|
|
388
|
+
const [a, b, c, d] = relativeTransform.getMatrix();
|
|
389
|
+
// A collapsed ancestor has no inverse. Its local bounds can only
|
|
390
|
+
// describe the uncollapsed stroke; world bounds are measured directly.
|
|
391
|
+
collapsedStroke =
|
|
392
|
+
a * d - b * c
|
|
393
|
+
? relativeTransform.copy().invert().multiply(collapsedStroke)
|
|
394
|
+
: new Transform();
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
const fillAndStrokeWidth = fillRect.width + strokeWidthX;
|
|
399
|
+
const fillAndStrokeHeight = fillRect.height + strokeWidthY;
|
|
366
400
|
const applyShadow = !config.skipShadow && this.hasShadow();
|
|
367
401
|
const shadowOffsetX = applyShadow ? this.shadowOffsetX() : 0;
|
|
368
402
|
const shadowOffsetY = applyShadow ? this.shadowOffsetY() : 0;
|
|
@@ -374,15 +408,25 @@ export class Shape extends Node {
|
|
|
374
408
|
const rect = {
|
|
375
409
|
width: width,
|
|
376
410
|
height: height,
|
|
377
|
-
x: -(
|
|
411
|
+
x: -(strokeWidthX / 2 + blurRadius) +
|
|
378
412
|
Math.min(shadowOffsetX, 0) +
|
|
379
413
|
fillRect.x,
|
|
380
|
-
y: -(
|
|
414
|
+
y: -(strokeWidthY / 2 + blurRadius) +
|
|
381
415
|
Math.min(shadowOffsetY, 0) +
|
|
382
416
|
fillRect.y,
|
|
383
417
|
};
|
|
384
418
|
if (!skipTransform) {
|
|
385
|
-
|
|
419
|
+
const transformed = this._transformedRect(rect, relativeTo);
|
|
420
|
+
if (collapsedStroke) {
|
|
421
|
+
const [a, b, c, d] = collapsedStroke.getMatrix();
|
|
422
|
+
const x = (strokeWidth * Math.hypot(a, c)) / 2;
|
|
423
|
+
const y = (strokeWidth * Math.hypot(b, d)) / 2;
|
|
424
|
+
transformed.x -= x;
|
|
425
|
+
transformed.y -= y;
|
|
426
|
+
transformed.width += x * 2;
|
|
427
|
+
transformed.height += y * 2;
|
|
428
|
+
}
|
|
429
|
+
return transformed;
|
|
386
430
|
}
|
|
387
431
|
return rect;
|
|
388
432
|
}
|
|
@@ -395,7 +439,7 @@ export class Shape extends Node {
|
|
|
395
439
|
const canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow();
|
|
396
440
|
let stage;
|
|
397
441
|
const cachingSelf = top === this;
|
|
398
|
-
if (!this.isVisible() && !cachingSelf) {
|
|
442
|
+
if (!(top ? this._isVisible(top) : this.isVisible()) && !cachingSelf) {
|
|
399
443
|
return this;
|
|
400
444
|
}
|
|
401
445
|
// if node is cached we just need to draw from cache
|
package/lib/Stage.d.ts
CHANGED
|
@@ -6,7 +6,21 @@ import type { Shape } from './Shape.ts';
|
|
|
6
6
|
import type { Layer } from './Layer.ts';
|
|
7
7
|
export interface StageConfig extends ContainerConfig {
|
|
8
8
|
container?: HTMLDivElement | string;
|
|
9
|
+
eventBatchFunc?: (callback: () => void) => void;
|
|
9
10
|
}
|
|
11
|
+
type Click = {
|
|
12
|
+
shape: Shape | null;
|
|
13
|
+
time: number;
|
|
14
|
+
};
|
|
15
|
+
type EventType = 'mouse' | 'touch' | 'pointer';
|
|
16
|
+
type PointerState = {
|
|
17
|
+
targetShape?: Shape;
|
|
18
|
+
downPosition?: Vector2d;
|
|
19
|
+
pointerType?: string;
|
|
20
|
+
relatedPointer?: PointerState;
|
|
21
|
+
clickStartShape?: Shape | null;
|
|
22
|
+
lastClick?: Click;
|
|
23
|
+
};
|
|
10
24
|
export declare const stages: Stage[];
|
|
11
25
|
/**
|
|
12
26
|
* Stage constructor. A stage is used to contain multiple layers
|
|
@@ -32,20 +46,11 @@ export declare class Stage extends Container<Layer, StageConfig> {
|
|
|
32
46
|
_changedPointerPositions: (Vector2d & {
|
|
33
47
|
id: number;
|
|
34
48
|
})[];
|
|
49
|
+
_pointerEventType?: EventType;
|
|
50
|
+
_pointerStates: Map<string, PointerState>;
|
|
51
|
+
_lastClicks: Partial<Record<EventType, Click>>;
|
|
35
52
|
bufferCanvas: SceneCanvas;
|
|
36
53
|
bufferHitCanvas: HitCanvas;
|
|
37
|
-
_mouseTargetShape: Shape;
|
|
38
|
-
_touchTargetShape: Shape;
|
|
39
|
-
_pointerTargetShape: Shape;
|
|
40
|
-
_mouseClickStartShape: Shape;
|
|
41
|
-
_touchClickStartShape: Shape;
|
|
42
|
-
_pointerClickStartShape: Shape;
|
|
43
|
-
_mouseClickEndShape: Shape;
|
|
44
|
-
_touchClickEndShape: Shape;
|
|
45
|
-
_pointerClickEndShape: Shape;
|
|
46
|
-
_mouseDblTimeout: any;
|
|
47
|
-
_touchDblTimeout: any;
|
|
48
|
-
_pointerDblTimeout: any;
|
|
49
54
|
constructor(config: StageConfig);
|
|
50
55
|
_validateAdd(child: any): void;
|
|
51
56
|
_checkVisibility(): void;
|
|
@@ -121,16 +126,18 @@ export declare class Stage extends Container<Layer, StageConfig> {
|
|
|
121
126
|
*/
|
|
122
127
|
getLayers(): Layer[];
|
|
123
128
|
_bindContentEvents(): void;
|
|
129
|
+
_batchEvents(callback: () => void): void;
|
|
124
130
|
_pointerenter(evt: PointerEvent): void;
|
|
125
131
|
_pointerover(evt: any): void;
|
|
126
|
-
|
|
132
|
+
_pointerEventsEnabled(): boolean;
|
|
133
|
+
_cancelClick(pointerId: number | undefined, eventType?: EventType): void;
|
|
127
134
|
_pointerleave(evt: any): void;
|
|
128
135
|
_pointerdown(evt: TouchEvent | MouseEvent | PointerEvent): void;
|
|
129
136
|
_pointermove(evt: TouchEvent | MouseEvent | PointerEvent): void;
|
|
130
137
|
_pointerup(evt: any): void;
|
|
131
138
|
_contextmenu(evt: any): void;
|
|
132
139
|
_wheel(evt: any): void;
|
|
133
|
-
_pointercancel(evt: PointerEvent): void;
|
|
140
|
+
_pointercancel(evt: PointerEvent | TouchEvent): void;
|
|
134
141
|
_lostpointercapture(evt: PointerEvent): void;
|
|
135
142
|
/**
|
|
136
143
|
* manually register pointers positions (mouse/touch) in the stage.
|
|
@@ -165,4 +172,6 @@ export declare class Stage extends Container<Layer, StageConfig> {
|
|
|
165
172
|
*/
|
|
166
173
|
batchDraw(): this;
|
|
167
174
|
container: GetSet<HTMLDivElement, this, HTMLDivElement | string>;
|
|
175
|
+
eventBatchFunc: GetSet<((callback: () => void) => void) | undefined, this>;
|
|
168
176
|
}
|
|
177
|
+
export {};
|