konva 9.3.19 → 9.3.21
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 +705 -663
- package/konva.min.js +3 -3
- package/lib/Container.d.ts +3 -3
- package/lib/Container.js +4 -10
- package/lib/Factory.js +4 -4
- package/lib/Global.js +1 -1
- package/lib/Layer.d.ts +2 -2
- package/lib/Layer.js +2 -2
- package/lib/Node.d.ts +9 -9
- package/lib/Node.js +39 -22
- package/lib/PointerEvents.d.ts +1 -1
- package/lib/Shape.d.ts +1 -1
- package/lib/Shape.js +7 -6
- package/lib/Stage.js +2 -1
- package/lib/Tween.js +9 -0
- package/lib/Validators.js +3 -3
- package/lib/filters/Blur.js +11 -11
- package/lib/filters/Enhance.js +4 -4
- package/lib/filters/HSV.js +4 -5
- package/lib/filters/Pixelate.js +18 -18
- package/lib/shapes/Line.d.ts +2 -2
- package/lib/shapes/Line.js +4 -3
- package/lib/shapes/Path.d.ts +3 -3
- package/lib/shapes/Path.js +33 -29
- package/lib/shapes/Text.js +14 -16
- package/lib/shapes/Transformer.js +14 -14
- package/package.json +3 -2
package/lib/Container.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { Node, NodeConfig } from './Node.js';
|
|
2
|
-
import { GetSet, IRect } from './types.js';
|
|
3
|
-
import { Shape } from './Shape.js';
|
|
4
1
|
import { HitCanvas, SceneCanvas } from './Canvas.js';
|
|
5
2
|
import { SceneContext } from './Context.js';
|
|
3
|
+
import { Node, NodeConfig } from './Node.js';
|
|
4
|
+
import { Shape } from './Shape.js';
|
|
5
|
+
import { GetSet, IRect } from './types.js';
|
|
6
6
|
export type ClipFuncOutput = void | [Path2D | CanvasFillRule] | [Path2D, CanvasFillRule];
|
|
7
7
|
export interface ContainerConfig extends NodeConfig {
|
|
8
8
|
clearBeforeDraw?: boolean;
|
package/lib/Container.js
CHANGED
|
@@ -10,17 +10,11 @@ class Container extends Node_1.Node {
|
|
|
10
10
|
this.children = [];
|
|
11
11
|
}
|
|
12
12
|
getChildren(filterFunc) {
|
|
13
|
-
if (!filterFunc) {
|
|
14
|
-
return this.children || [];
|
|
15
|
-
}
|
|
16
13
|
const children = this.children || [];
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
return results;
|
|
14
|
+
if (filterFunc) {
|
|
15
|
+
return children.filter(filterFunc);
|
|
16
|
+
}
|
|
17
|
+
return children;
|
|
24
18
|
}
|
|
25
19
|
hasChildren() {
|
|
26
20
|
return this.getChildren().length > 0;
|
package/lib/Factory.js
CHANGED
|
@@ -12,7 +12,7 @@ exports.Factory = {
|
|
|
12
12
|
exports.Factory.addOverloadedGetterSetter(constructor, attr);
|
|
13
13
|
},
|
|
14
14
|
addGetter(constructor, attr, def) {
|
|
15
|
-
|
|
15
|
+
const method = GET + Util_1.Util._capitalize(attr);
|
|
16
16
|
constructor.prototype[method] =
|
|
17
17
|
constructor.prototype[method] ||
|
|
18
18
|
function () {
|
|
@@ -21,13 +21,13 @@ exports.Factory = {
|
|
|
21
21
|
};
|
|
22
22
|
},
|
|
23
23
|
addSetter(constructor, attr, validator, after) {
|
|
24
|
-
|
|
24
|
+
const method = SET + Util_1.Util._capitalize(attr);
|
|
25
25
|
if (!constructor.prototype[method]) {
|
|
26
26
|
exports.Factory.overWriteSetter(constructor, attr, validator, after);
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
overWriteSetter(constructor, attr, validator, after) {
|
|
30
|
-
|
|
30
|
+
const method = SET + Util_1.Util._capitalize(attr);
|
|
31
31
|
constructor.prototype[method] = function (val) {
|
|
32
32
|
if (validator && val !== undefined && val !== null) {
|
|
33
33
|
val = validator.call(this, val, attr);
|
|
@@ -78,7 +78,7 @@ exports.Factory = {
|
|
|
78
78
|
exports.Factory.addOverloadedGetterSetter(constructor, attr);
|
|
79
79
|
},
|
|
80
80
|
addOverloadedGetterSetter(constructor, attr) {
|
|
81
|
-
|
|
81
|
+
const capitalizedAttr = Util_1.Util._capitalize(attr), setter = SET + capitalizedAttr, getter = GET + capitalizedAttr;
|
|
82
82
|
constructor.prototype[attr] = function () {
|
|
83
83
|
if (arguments.length) {
|
|
84
84
|
this[setter](arguments[0]);
|
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.21',
|
|
20
20
|
isBrowser: detectBrowser(),
|
|
21
21
|
isUnminified: /param/.test(function (param) { }.toString()),
|
|
22
22
|
dblClickWindow: 400,
|
package/lib/Layer.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare class Layer extends Container<Group | Shape> {
|
|
|
21
21
|
getHitCanvas(): HitCanvas;
|
|
22
22
|
getContext(): import("./Context.js").Context;
|
|
23
23
|
clear(bounds?: any): this;
|
|
24
|
-
setZIndex(index:
|
|
24
|
+
setZIndex(index: number): this;
|
|
25
25
|
moveToTop(): boolean;
|
|
26
26
|
moveUp(): boolean;
|
|
27
27
|
moveDown(): boolean;
|
|
@@ -47,7 +47,7 @@ export declare class Layer extends Container<Group | Shape> {
|
|
|
47
47
|
shape?: Shape;
|
|
48
48
|
antialiased?: boolean;
|
|
49
49
|
};
|
|
50
|
-
drawScene(can?: SceneCanvas, top?: Node): this;
|
|
50
|
+
drawScene(can?: SceneCanvas, top?: Node, bufferCanvas?: SceneCanvas): this;
|
|
51
51
|
drawHit(can?: HitCanvas, top?: Node): this;
|
|
52
52
|
enableHitGraph(): this;
|
|
53
53
|
disableHitGraph(): this;
|
package/lib/Layer.js
CHANGED
|
@@ -245,7 +245,7 @@ class Layer extends Container_1.Container {
|
|
|
245
245
|
}
|
|
246
246
|
return {};
|
|
247
247
|
}
|
|
248
|
-
drawScene(can, top) {
|
|
248
|
+
drawScene(can, top, bufferCanvas) {
|
|
249
249
|
const layer = this.getLayer(), canvas = can || (layer && layer.getCanvas());
|
|
250
250
|
this._fire(BEFORE_DRAW, {
|
|
251
251
|
node: this,
|
|
@@ -253,7 +253,7 @@ class Layer extends Container_1.Container {
|
|
|
253
253
|
if (this.clearBeforeDraw()) {
|
|
254
254
|
canvas.getContext().clear();
|
|
255
255
|
}
|
|
256
|
-
Container_1.Container.prototype.drawScene.call(this, canvas, top);
|
|
256
|
+
Container_1.Container.prototype.drawScene.call(this, canvas, top, bufferCanvas);
|
|
257
257
|
this._fire(DRAW, {
|
|
258
258
|
node: this,
|
|
259
259
|
});
|
package/lib/Node.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { SceneCanvas, Canvas } from './Canvas.js';
|
|
1
|
+
import { Canvas, SceneCanvas } from './Canvas.js';
|
|
3
2
|
import { Container } from './Container.js';
|
|
4
|
-
import { GetSet, Vector2d, IRect } from './types.js';
|
|
5
|
-
import { Stage } from './Stage.js';
|
|
6
3
|
import { Context } from './Context.js';
|
|
7
|
-
import { Shape } from './Shape.js';
|
|
8
4
|
import { Layer } from './Layer.js';
|
|
5
|
+
import { Shape } from './Shape.js';
|
|
6
|
+
import { Stage } from './Stage.js';
|
|
7
|
+
import { GetSet, IRect, Vector2d } from './types.js';
|
|
8
|
+
import { Transform } from './Util.js';
|
|
9
9
|
export type Filter = (this: Node, imageData: ImageData) => void;
|
|
10
10
|
type globalCompositeOperationType = '' | 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity';
|
|
11
11
|
export interface NodeConfig {
|
|
@@ -125,7 +125,7 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
125
125
|
_clearCaches(): void;
|
|
126
126
|
_remove(): void;
|
|
127
127
|
destroy(): this;
|
|
128
|
-
getAttr(attr: string): any;
|
|
128
|
+
getAttr<T>(attr: string): any;
|
|
129
129
|
getAncestors(): Node<NodeConfig>[];
|
|
130
130
|
getAttrs(): Config & Record<string, any>;
|
|
131
131
|
setAttrs(config: any): this;
|
|
@@ -244,12 +244,12 @@ export declare abstract class Node<Config extends NodeConfig = NodeConfig> {
|
|
|
244
244
|
getDragDistance(): number;
|
|
245
245
|
_off(type: any, name?: any, callback?: any): void;
|
|
246
246
|
_fireChangeEvent(attr: any, oldVal: any, newVal: any): void;
|
|
247
|
-
addName(name:
|
|
247
|
+
addName(name: string): this;
|
|
248
248
|
hasName(name: any): boolean;
|
|
249
249
|
removeName(name: any): this;
|
|
250
|
-
setAttr(attr:
|
|
250
|
+
setAttr(attr: string, val: any): this;
|
|
251
251
|
_requestDraw(): void;
|
|
252
|
-
_setAttr(key:
|
|
252
|
+
_setAttr(key: string, val: any): void;
|
|
253
253
|
_setComponentAttr(key: any, component: any, val: any): void;
|
|
254
254
|
_fireAndBubble(eventType: any, evt: any, compareShape?: any): void;
|
|
255
255
|
_getProtoListeners(eventType: any): any;
|
package/lib/Node.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Node = void 0;
|
|
4
|
-
const Util_1 = require("./Util");
|
|
5
|
-
const Factory_1 = require("./Factory");
|
|
6
4
|
const Canvas_1 = require("./Canvas");
|
|
7
|
-
const Global_1 = require("./Global");
|
|
8
5
|
const DragAndDrop_1 = require("./DragAndDrop");
|
|
6
|
+
const Factory_1 = require("./Factory");
|
|
7
|
+
const Global_1 = require("./Global");
|
|
8
|
+
const Util_1 = require("./Util");
|
|
9
9
|
const Validators_1 = require("./Validators");
|
|
10
|
-
const ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER = 'mouseenter', MOUSELEAVE = 'mouseleave', NAME = 'name', SET = 'set', SHAPE = 'Shape', SPACE = ' ', STAGE = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR = [
|
|
10
|
+
const ABSOLUTE_OPACITY = 'absoluteOpacity', ALL_LISTENERS = 'allEventListeners', ABSOLUTE_TRANSFORM = 'absoluteTransform', ABSOLUTE_SCALE = 'absoluteScale', CANVAS = 'canvas', CHANGE = 'Change', CHILDREN = 'children', KONVA = 'konva', LISTENING = 'listening', MOUSEENTER = 'mouseenter', MOUSELEAVE = 'mouseleave', POINTERENTER = 'pointerenter', POINTERLEAVE = 'pointerleave', TOUCHENTER = 'touchenter', TOUCHLEAVE = 'touchleave', NAME = 'name', SET = 'set', SHAPE = 'Shape', SPACE = ' ', STAGE = 'stage', TRANSFORM = 'transform', UPPER_STAGE = 'Stage', VISIBLE = 'visible', TRANSFORM_CHANGE_STR = [
|
|
11
11
|
'xChange.konva',
|
|
12
12
|
'yChange.konva',
|
|
13
13
|
'scaleXChange.konva',
|
|
@@ -86,8 +86,8 @@ class Node {
|
|
|
86
86
|
}
|
|
87
87
|
clearCache() {
|
|
88
88
|
if (this._cache.has(CANVAS)) {
|
|
89
|
-
const { scene, filter, hit } = this._cache.get(CANVAS);
|
|
90
|
-
Util_1.Util.releaseCanvas(scene, filter, hit);
|
|
89
|
+
const { scene, filter, hit, buffer } = this._cache.get(CANVAS);
|
|
90
|
+
Util_1.Util.releaseCanvas(scene, filter, hit, buffer);
|
|
91
91
|
this._cache.delete(CANVAS);
|
|
92
92
|
}
|
|
93
93
|
this._clearSelfAndDescendantCache();
|
|
@@ -131,6 +131,11 @@ class Node {
|
|
|
131
131
|
width: width,
|
|
132
132
|
height: height,
|
|
133
133
|
}), sceneContext = cachedSceneCanvas.getContext(), hitContext = cachedHitCanvas.getContext();
|
|
134
|
+
const bufferCanvas = new Canvas_1.SceneCanvas({
|
|
135
|
+
width: cachedSceneCanvas.width / cachedSceneCanvas.pixelRatio + Math.abs(x),
|
|
136
|
+
height: cachedSceneCanvas.height / cachedSceneCanvas.pixelRatio + Math.abs(y),
|
|
137
|
+
pixelRatio: cachedSceneCanvas.pixelRatio,
|
|
138
|
+
}), bufferContext = bufferCanvas.getContext();
|
|
134
139
|
cachedHitCanvas.isCache = true;
|
|
135
140
|
cachedSceneCanvas.isCache = true;
|
|
136
141
|
this._cache.delete(CANVAS);
|
|
@@ -141,12 +146,16 @@ class Node {
|
|
|
141
146
|
}
|
|
142
147
|
sceneContext.save();
|
|
143
148
|
hitContext.save();
|
|
149
|
+
bufferContext.save();
|
|
144
150
|
sceneContext.translate(-x, -y);
|
|
145
151
|
hitContext.translate(-x, -y);
|
|
152
|
+
bufferContext.translate(-x, -y);
|
|
153
|
+
bufferCanvas.x = x;
|
|
154
|
+
bufferCanvas.y = y;
|
|
146
155
|
this._isUnderCache = true;
|
|
147
156
|
this._clearSelfAndDescendantCache(ABSOLUTE_OPACITY);
|
|
148
157
|
this._clearSelfAndDescendantCache(ABSOLUTE_SCALE);
|
|
149
|
-
this.drawScene(cachedSceneCanvas, this);
|
|
158
|
+
this.drawScene(cachedSceneCanvas, this, bufferCanvas);
|
|
150
159
|
this.drawHit(cachedHitCanvas, this);
|
|
151
160
|
this._isUnderCache = false;
|
|
152
161
|
sceneContext.restore();
|
|
@@ -165,6 +174,7 @@ class Node {
|
|
|
165
174
|
scene: cachedSceneCanvas,
|
|
166
175
|
filter: cachedFilterCanvas,
|
|
167
176
|
hit: cachedHitCanvas,
|
|
177
|
+
buffer: bufferCanvas,
|
|
168
178
|
x: x,
|
|
169
179
|
y: y,
|
|
170
180
|
});
|
|
@@ -257,23 +267,22 @@ class Node {
|
|
|
257
267
|
return sceneCanvas;
|
|
258
268
|
}
|
|
259
269
|
on(evtStr, handler) {
|
|
260
|
-
|
|
270
|
+
if (this._cache) {
|
|
271
|
+
this._cache.delete(ALL_LISTENERS);
|
|
272
|
+
}
|
|
261
273
|
if (arguments.length === 3) {
|
|
262
274
|
return this._delegate.apply(this, arguments);
|
|
263
275
|
}
|
|
264
|
-
|
|
265
|
-
for (n = 0; n <
|
|
266
|
-
event = events[n];
|
|
267
|
-
parts = event.split('.');
|
|
268
|
-
baseEvent = parts[0];
|
|
269
|
-
name = parts[1] || '';
|
|
276
|
+
const events = evtStr.split(SPACE);
|
|
277
|
+
for (let n = 0; n < events.length; n++) {
|
|
278
|
+
const event = events[n];
|
|
279
|
+
const parts = event.split('.');
|
|
280
|
+
const baseEvent = parts[0];
|
|
281
|
+
const name = parts[1] || '';
|
|
270
282
|
if (!this.eventListeners[baseEvent]) {
|
|
271
283
|
this.eventListeners[baseEvent] = [];
|
|
272
284
|
}
|
|
273
|
-
this.eventListeners[baseEvent].push({
|
|
274
|
-
name: name,
|
|
275
|
-
handler: handler,
|
|
276
|
-
});
|
|
285
|
+
this.eventListeners[baseEvent].push({ name, handler });
|
|
277
286
|
}
|
|
278
287
|
return this;
|
|
279
288
|
}
|
|
@@ -1141,14 +1150,22 @@ class Node {
|
|
|
1141
1150
|
if (evt && this.nodeType === SHAPE) {
|
|
1142
1151
|
evt.target = this;
|
|
1143
1152
|
}
|
|
1144
|
-
const
|
|
1153
|
+
const nonBubbling = [
|
|
1154
|
+
MOUSEENTER,
|
|
1155
|
+
MOUSELEAVE,
|
|
1156
|
+
POINTERENTER,
|
|
1157
|
+
POINTERLEAVE,
|
|
1158
|
+
TOUCHENTER,
|
|
1159
|
+
TOUCHLEAVE,
|
|
1160
|
+
];
|
|
1161
|
+
const shouldStop = nonBubbling.indexOf(eventType) !== -1 &&
|
|
1145
1162
|
((compareShape &&
|
|
1146
1163
|
(this === compareShape ||
|
|
1147
1164
|
(this.isAncestorOf && this.isAncestorOf(compareShape)))) ||
|
|
1148
1165
|
(this.nodeType === 'Stage' && !compareShape));
|
|
1149
1166
|
if (!shouldStop) {
|
|
1150
1167
|
this._fire(eventType, evt);
|
|
1151
|
-
const stopBubble = (eventType
|
|
1168
|
+
const stopBubble = nonBubbling.indexOf(eventType) !== -1 &&
|
|
1152
1169
|
compareShape &&
|
|
1153
1170
|
compareShape.isAncestorOf &&
|
|
1154
1171
|
compareShape.isAncestorOf(this) &&
|
|
@@ -1189,13 +1206,13 @@ class Node {
|
|
|
1189
1206
|
evt.type = eventType;
|
|
1190
1207
|
const topListeners = this._getProtoListeners(eventType);
|
|
1191
1208
|
if (topListeners) {
|
|
1192
|
-
for (
|
|
1209
|
+
for (let i = 0; i < topListeners.length; i++) {
|
|
1193
1210
|
topListeners[i].handler.call(this, evt);
|
|
1194
1211
|
}
|
|
1195
1212
|
}
|
|
1196
1213
|
const selfListeners = this.eventListeners[eventType];
|
|
1197
1214
|
if (selfListeners) {
|
|
1198
|
-
for (
|
|
1215
|
+
for (let i = 0; i < selfListeners.length; i++) {
|
|
1199
1216
|
selfListeners[i].handler.call(this, evt);
|
|
1200
1217
|
}
|
|
1201
1218
|
}
|
package/lib/PointerEvents.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { Stage } from './Stage.js';
|
|
|
4
4
|
export interface KonvaPointerEvent extends KonvaEventObject<PointerEvent> {
|
|
5
5
|
pointerId: number;
|
|
6
6
|
}
|
|
7
|
-
export declare function getCapturedShape(pointerId: number):
|
|
7
|
+
export declare function getCapturedShape(pointerId: number): Shape<import("./Shape.js").ShapeConfig> | Stage | undefined;
|
|
8
8
|
export declare function createEvent(evt: PointerEvent): KonvaPointerEvent;
|
|
9
9
|
export declare function hasPointerCapture(pointerId: number, shape: Shape | Stage): boolean;
|
|
10
10
|
export declare function setPointerCapture(pointerId: number, shape: Shape | Stage): void;
|
package/lib/Shape.d.ts
CHANGED
|
@@ -98,7 +98,7 @@ export declare class Shape<Config extends ShapeConfig = ShapeConfig> extends Nod
|
|
|
98
98
|
hasFill(): any;
|
|
99
99
|
hasStroke(): any;
|
|
100
100
|
hasHitStroke(): any;
|
|
101
|
-
intersects(point:
|
|
101
|
+
intersects(point: Vector2d): boolean;
|
|
102
102
|
destroy(): this;
|
|
103
103
|
_useBufferCanvas(forceFill?: boolean): boolean;
|
|
104
104
|
setStrokeHitEnabled(val: number): void;
|
package/lib/Shape.js
CHANGED
|
@@ -318,8 +318,9 @@ class Shape extends Node_1.Node {
|
|
|
318
318
|
}
|
|
319
319
|
drawScene(can, top, bufferCanvas) {
|
|
320
320
|
const layer = this.getLayer();
|
|
321
|
-
|
|
322
|
-
|
|
321
|
+
const canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow();
|
|
322
|
+
let stage;
|
|
323
|
+
const skipBuffer = false;
|
|
323
324
|
const cachingSelf = top === this;
|
|
324
325
|
if (!this.isVisible() && !cachingSelf) {
|
|
325
326
|
return this;
|
|
@@ -339,11 +340,11 @@ class Shape extends Node_1.Node {
|
|
|
339
340
|
if (this._useBufferCanvas() && !skipBuffer) {
|
|
340
341
|
stage = this.getStage();
|
|
341
342
|
const bc = bufferCanvas || stage.bufferCanvas;
|
|
342
|
-
bufferContext = bc.getContext();
|
|
343
|
+
const bufferContext = bc.getContext();
|
|
343
344
|
bufferContext.clear();
|
|
344
345
|
bufferContext.save();
|
|
345
346
|
bufferContext._applyLineJoin(this);
|
|
346
|
-
|
|
347
|
+
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
347
348
|
bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
348
349
|
drawFunc.call(this, bufferContext, this);
|
|
349
350
|
bufferContext.restore();
|
|
@@ -353,12 +354,12 @@ class Shape extends Node_1.Node {
|
|
|
353
354
|
}
|
|
354
355
|
context._applyOpacity(this);
|
|
355
356
|
context._applyGlobalCompositeOperation(this);
|
|
356
|
-
context.drawImage(bc._canvas, 0, 0, bc.width / ratio, bc.height / ratio);
|
|
357
|
+
context.drawImage(bc._canvas, bc.x || 0, bc.y || 0, bc.width / ratio, bc.height / ratio);
|
|
357
358
|
}
|
|
358
359
|
else {
|
|
359
360
|
context._applyLineJoin(this);
|
|
360
361
|
if (!cachingSelf) {
|
|
361
|
-
|
|
362
|
+
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
362
363
|
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
363
364
|
context._applyOpacity(this);
|
|
364
365
|
context._applyGlobalCompositeOperation(this);
|
package/lib/Stage.js
CHANGED
|
@@ -26,6 +26,7 @@ const STAGE = 'Stage', STRING = 'string', PX = 'px', MOUSEOUT = 'mouseout', MOUS
|
|
|
26
26
|
[POINTERMOVE, '_pointermove'],
|
|
27
27
|
[POINTERUP, '_pointerup'],
|
|
28
28
|
[POINTERCANCEL, '_pointercancel'],
|
|
29
|
+
[POINTERLEAVE, '_pointerleave'],
|
|
29
30
|
[LOSTPOINTERCAPTURE, '_lostpointercapture'],
|
|
30
31
|
];
|
|
31
32
|
const EVENTS_MAP = {
|
|
@@ -127,12 +128,12 @@ class Stage extends Container_1.Container {
|
|
|
127
128
|
}
|
|
128
129
|
setContainer(container) {
|
|
129
130
|
if (typeof container === STRING) {
|
|
131
|
+
let id;
|
|
130
132
|
if (container.charAt(0) === '.') {
|
|
131
133
|
const className = container.slice(1);
|
|
132
134
|
container = document.getElementsByClassName(className)[0];
|
|
133
135
|
}
|
|
134
136
|
else {
|
|
135
|
-
var id;
|
|
136
137
|
if (container.charAt(0) !== '#') {
|
|
137
138
|
id = container;
|
|
138
139
|
}
|
package/lib/Tween.js
CHANGED
|
@@ -356,10 +356,19 @@ class Tween {
|
|
|
356
356
|
destroy() {
|
|
357
357
|
const nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId];
|
|
358
358
|
this.pause();
|
|
359
|
+
if (this.anim) {
|
|
360
|
+
this.anim.stop();
|
|
361
|
+
}
|
|
359
362
|
for (const key in attrs) {
|
|
360
363
|
delete Tween.tweens[nodeId][key];
|
|
361
364
|
}
|
|
362
365
|
delete Tween.attrs[nodeId][thisId];
|
|
366
|
+
if (Object.keys(Tween.tweens[nodeId]).length === 0) {
|
|
367
|
+
delete Tween.tweens[nodeId];
|
|
368
|
+
}
|
|
369
|
+
if (Object.keys(Tween.attrs[nodeId]).length === 0) {
|
|
370
|
+
delete Tween.attrs[nodeId];
|
|
371
|
+
}
|
|
363
372
|
}
|
|
364
373
|
}
|
|
365
374
|
exports.Tween = Tween;
|
package/lib/Validators.js
CHANGED
|
@@ -76,8 +76,8 @@ function getNumberOrArrayOfNumbersValidator(noOfElements) {
|
|
|
76
76
|
function getNumberOrAutoValidator() {
|
|
77
77
|
if (Global_1.Konva.isUnminified) {
|
|
78
78
|
return function (val, attr) {
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const isNumber = Util_1.Util._isNumber(val);
|
|
80
|
+
const isAuto = val === 'auto';
|
|
81
81
|
if (!(isNumber || isAuto)) {
|
|
82
82
|
Util_1.Util.warn(_formatValue(val) +
|
|
83
83
|
' is a not valid value for "' +
|
|
@@ -161,7 +161,7 @@ function getNumberArrayValidator() {
|
|
|
161
161
|
function getBooleanValidator() {
|
|
162
162
|
if (Global_1.Konva.isUnminified) {
|
|
163
163
|
return function (val, attr) {
|
|
164
|
-
|
|
164
|
+
const isBool = val === true || val === false;
|
|
165
165
|
if (!isBool) {
|
|
166
166
|
Util_1.Util.warn(_formatValue(val) +
|
|
167
167
|
' is a not valid value for "' +
|
package/lib/filters/Blur.js
CHANGED
|
@@ -48,10 +48,10 @@ const shg_table = [
|
|
|
48
48
|
];
|
|
49
49
|
function filterGaussBlurRGBA(imageData, radius) {
|
|
50
50
|
const pixels = imageData.data, width = imageData.width, height = imageData.height;
|
|
51
|
-
let
|
|
51
|
+
let p, yi, yw, r_sum, g_sum, b_sum, a_sum, r_out_sum, g_out_sum, b_out_sum, a_out_sum, r_in_sum, g_in_sum, b_in_sum, a_in_sum, pr, pg, pb, pa, rbs;
|
|
52
52
|
const div = radius + radius + 1, widthMinus1 = width - 1, heightMinus1 = height - 1, radiusPlus1 = radius + 1, sumFactor = (radiusPlus1 * (radiusPlus1 + 1)) / 2, stackStart = new BlurStack(), mul_sum = mul_table[radius], shg_sum = shg_table[radius];
|
|
53
53
|
let stackEnd = null, stack = stackStart, stackIn = null, stackOut = null;
|
|
54
|
-
for (i = 1; i < div; i++) {
|
|
54
|
+
for (let i = 1; i < div; i++) {
|
|
55
55
|
stack = stack.next = new BlurStack();
|
|
56
56
|
if (i === radiusPlus1) {
|
|
57
57
|
stackEnd = stack;
|
|
@@ -59,7 +59,7 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
59
59
|
}
|
|
60
60
|
stack.next = stackStart;
|
|
61
61
|
yw = yi = 0;
|
|
62
|
-
for (y = 0; y < height; y++) {
|
|
62
|
+
for (let y = 0; y < height; y++) {
|
|
63
63
|
r_in_sum =
|
|
64
64
|
g_in_sum =
|
|
65
65
|
b_in_sum =
|
|
@@ -78,14 +78,14 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
78
78
|
b_sum += sumFactor * pb;
|
|
79
79
|
a_sum += sumFactor * pa;
|
|
80
80
|
stack = stackStart;
|
|
81
|
-
for (i = 0; i < radiusPlus1; i++) {
|
|
81
|
+
for (let i = 0; i < radiusPlus1; i++) {
|
|
82
82
|
stack.r = pr;
|
|
83
83
|
stack.g = pg;
|
|
84
84
|
stack.b = pb;
|
|
85
85
|
stack.a = pa;
|
|
86
86
|
stack = stack.next;
|
|
87
87
|
}
|
|
88
|
-
for (i = 1; i < radiusPlus1; i++) {
|
|
88
|
+
for (let i = 1; i < radiusPlus1; i++) {
|
|
89
89
|
p = yi + ((widthMinus1 < i ? widthMinus1 : i) << 2);
|
|
90
90
|
r_sum += (stack.r = pr = pixels[p]) * (rbs = radiusPlus1 - i);
|
|
91
91
|
g_sum += (stack.g = pg = pixels[p + 1]) * rbs;
|
|
@@ -99,7 +99,7 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
99
99
|
}
|
|
100
100
|
stackIn = stackStart;
|
|
101
101
|
stackOut = stackEnd;
|
|
102
|
-
for (x = 0; x < width; x++) {
|
|
102
|
+
for (let x = 0; x < width; x++) {
|
|
103
103
|
pixels[yi + 3] = pa = (a_sum * mul_sum) >> shg_sum;
|
|
104
104
|
if (pa !== 0) {
|
|
105
105
|
pa = 255 / pa;
|
|
@@ -141,7 +141,7 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
141
141
|
}
|
|
142
142
|
yw += width;
|
|
143
143
|
}
|
|
144
|
-
for (x = 0; x < width; x++) {
|
|
144
|
+
for (let x = 0; x < width; x++) {
|
|
145
145
|
g_in_sum =
|
|
146
146
|
b_in_sum =
|
|
147
147
|
a_in_sum =
|
|
@@ -161,15 +161,15 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
161
161
|
b_sum += sumFactor * pb;
|
|
162
162
|
a_sum += sumFactor * pa;
|
|
163
163
|
stack = stackStart;
|
|
164
|
-
for (i = 0; i < radiusPlus1; i++) {
|
|
164
|
+
for (let i = 0; i < radiusPlus1; i++) {
|
|
165
165
|
stack.r = pr;
|
|
166
166
|
stack.g = pg;
|
|
167
167
|
stack.b = pb;
|
|
168
168
|
stack.a = pa;
|
|
169
169
|
stack = stack.next;
|
|
170
170
|
}
|
|
171
|
-
yp = width;
|
|
172
|
-
for (i = 1; i <= radius; i++) {
|
|
171
|
+
let yp = width;
|
|
172
|
+
for (let i = 1; i <= radius; i++) {
|
|
173
173
|
yi = (yp + x) << 2;
|
|
174
174
|
r_sum += (stack.r = pr = pixels[yi]) * (rbs = radiusPlus1 - i);
|
|
175
175
|
g_sum += (stack.g = pg = pixels[yi + 1]) * rbs;
|
|
@@ -187,7 +187,7 @@ function filterGaussBlurRGBA(imageData, radius) {
|
|
|
187
187
|
yi = x;
|
|
188
188
|
stackIn = stackStart;
|
|
189
189
|
stackOut = stackEnd;
|
|
190
|
-
for (y = 0; y < height; y++) {
|
|
190
|
+
for (let y = 0; y < height; y++) {
|
|
191
191
|
p = yi << 2;
|
|
192
192
|
pixels[p + 3] = pa = (a_sum * mul_sum) >> shg_sum;
|
|
193
193
|
if (pa > 0) {
|
package/lib/filters/Enhance.js
CHANGED
|
@@ -58,7 +58,7 @@ const Enhance = function (imageData) {
|
|
|
58
58
|
bMax = 255;
|
|
59
59
|
bMin = 0;
|
|
60
60
|
}
|
|
61
|
-
let
|
|
61
|
+
let rGoalMax, rGoalMin, gGoalMax, gGoalMin, bGoalMax, bGoalMin;
|
|
62
62
|
if (enhanceAmount > 0) {
|
|
63
63
|
rGoalMax = rMax + enhanceAmount * (255 - rMax);
|
|
64
64
|
rGoalMin = rMin - enhanceAmount * (rMin - 0);
|
|
@@ -68,13 +68,13 @@ const Enhance = function (imageData) {
|
|
|
68
68
|
bGoalMin = bMin - enhanceAmount * (bMin - 0);
|
|
69
69
|
}
|
|
70
70
|
else {
|
|
71
|
-
rMid = (rMax + rMin) * 0.5;
|
|
71
|
+
const rMid = (rMax + rMin) * 0.5;
|
|
72
72
|
rGoalMax = rMax + enhanceAmount * (rMax - rMid);
|
|
73
73
|
rGoalMin = rMin + enhanceAmount * (rMin - rMid);
|
|
74
|
-
gMid = (gMax + gMin) * 0.5;
|
|
74
|
+
const gMid = (gMax + gMin) * 0.5;
|
|
75
75
|
gGoalMax = gMax + enhanceAmount * (gMax - gMid);
|
|
76
76
|
gGoalMin = gMin + enhanceAmount * (gMin - gMid);
|
|
77
|
-
bMid = (bMax + bMin) * 0.5;
|
|
77
|
+
const bMid = (bMax + bMin) * 0.5;
|
|
78
78
|
bGoalMax = bMax + enhanceAmount * (bMax - bMid);
|
|
79
79
|
bGoalMin = bMin + enhanceAmount * (bMin - bMid);
|
|
80
80
|
}
|
package/lib/filters/HSV.js
CHANGED
|
@@ -10,12 +10,11 @@ const HSV = function (imageData) {
|
|
|
10
10
|
const rr = 0.299 * v + 0.701 * vsu + 0.167 * vsw, rg = 0.587 * v - 0.587 * vsu + 0.33 * vsw, rb = 0.114 * v - 0.114 * vsu - 0.497 * vsw;
|
|
11
11
|
const gr = 0.299 * v - 0.299 * vsu - 0.328 * vsw, gg = 0.587 * v + 0.413 * vsu + 0.035 * vsw, gb = 0.114 * v - 0.114 * vsu + 0.293 * vsw;
|
|
12
12
|
const br = 0.299 * v - 0.3 * vsu + 1.25 * vsw, bg = 0.587 * v - 0.586 * vsu - 1.05 * vsw, bb = 0.114 * v + 0.886 * vsu - 0.2 * vsw;
|
|
13
|
-
let r, g, b, a;
|
|
14
13
|
for (let i = 0; i < nPixels; i += 4) {
|
|
15
|
-
r = data[i + 0];
|
|
16
|
-
g = data[i + 1];
|
|
17
|
-
b = data[i + 2];
|
|
18
|
-
a = data[i + 3];
|
|
14
|
+
const r = data[i + 0];
|
|
15
|
+
const g = data[i + 1];
|
|
16
|
+
const b = data[i + 2];
|
|
17
|
+
const a = data[i + 3];
|
|
19
18
|
data[i + 0] = rr * r + rg * g + rb * b;
|
|
20
19
|
data[i + 1] = gr * r + gg * g + gb * b;
|
|
21
20
|
data[i + 2] = br * r + bg * g + bb * b;
|
package/lib/filters/Pixelate.js
CHANGED
|
@@ -6,31 +6,31 @@ const Util_1 = require("../Util");
|
|
|
6
6
|
const Node_1 = require("../Node");
|
|
7
7
|
const Validators_1 = require("../Validators");
|
|
8
8
|
const Pixelate = function (imageData) {
|
|
9
|
-
let pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height,
|
|
9
|
+
let pixelSize = Math.ceil(this.pixelSize()), width = imageData.width, height = imageData.height, nBinsX = Math.ceil(width / pixelSize), nBinsY = Math.ceil(height / pixelSize), data = imageData.data;
|
|
10
10
|
if (pixelSize <= 0) {
|
|
11
11
|
Util_1.Util.error('pixelSize value can not be <= 0');
|
|
12
12
|
return;
|
|
13
13
|
}
|
|
14
|
-
for (xBin = 0; xBin < nBinsX; xBin += 1) {
|
|
15
|
-
for (yBin = 0; yBin < nBinsY; yBin += 1) {
|
|
16
|
-
red = 0;
|
|
17
|
-
green = 0;
|
|
18
|
-
blue = 0;
|
|
19
|
-
alpha = 0;
|
|
20
|
-
xBinStart = xBin * pixelSize;
|
|
21
|
-
xBinEnd = xBinStart + pixelSize;
|
|
22
|
-
yBinStart = yBin * pixelSize;
|
|
23
|
-
yBinEnd = yBinStart + pixelSize;
|
|
24
|
-
pixelsInBin = 0;
|
|
25
|
-
for (x = xBinStart; x < xBinEnd; x += 1) {
|
|
14
|
+
for (let xBin = 0; xBin < nBinsX; xBin += 1) {
|
|
15
|
+
for (let yBin = 0; yBin < nBinsY; yBin += 1) {
|
|
16
|
+
let red = 0;
|
|
17
|
+
let green = 0;
|
|
18
|
+
let blue = 0;
|
|
19
|
+
let alpha = 0;
|
|
20
|
+
const xBinStart = xBin * pixelSize;
|
|
21
|
+
const xBinEnd = xBinStart + pixelSize;
|
|
22
|
+
const yBinStart = yBin * pixelSize;
|
|
23
|
+
const yBinEnd = yBinStart + pixelSize;
|
|
24
|
+
let pixelsInBin = 0;
|
|
25
|
+
for (let x = xBinStart; x < xBinEnd; x += 1) {
|
|
26
26
|
if (x >= width) {
|
|
27
27
|
continue;
|
|
28
28
|
}
|
|
29
|
-
for (y = yBinStart; y < yBinEnd; y += 1) {
|
|
29
|
+
for (let y = yBinStart; y < yBinEnd; y += 1) {
|
|
30
30
|
if (y >= height) {
|
|
31
31
|
continue;
|
|
32
32
|
}
|
|
33
|
-
i = (width * y + x) * 4;
|
|
33
|
+
const i = (width * y + x) * 4;
|
|
34
34
|
red += data[i + 0];
|
|
35
35
|
green += data[i + 1];
|
|
36
36
|
blue += data[i + 2];
|
|
@@ -42,15 +42,15 @@ const Pixelate = function (imageData) {
|
|
|
42
42
|
green = green / pixelsInBin;
|
|
43
43
|
blue = blue / pixelsInBin;
|
|
44
44
|
alpha = alpha / pixelsInBin;
|
|
45
|
-
for (x = xBinStart; x < xBinEnd; x += 1) {
|
|
45
|
+
for (let x = xBinStart; x < xBinEnd; x += 1) {
|
|
46
46
|
if (x >= width) {
|
|
47
47
|
continue;
|
|
48
48
|
}
|
|
49
|
-
for (y = yBinStart; y < yBinEnd; y += 1) {
|
|
49
|
+
for (let y = yBinStart; y < yBinEnd; y += 1) {
|
|
50
50
|
if (y >= height) {
|
|
51
51
|
continue;
|
|
52
52
|
}
|
|
53
|
-
i = (width * y + x) * 4;
|
|
53
|
+
const i = (width * y + x) * 4;
|
|
54
54
|
data[i + 0] = red;
|
|
55
55
|
data[i + 1] = green;
|
|
56
56
|
data[i + 2] = blue;
|
package/lib/shapes/Line.d.ts
CHANGED
|
@@ -11,8 +11,8 @@ export declare class Line<Config extends LineConfig = LineConfig> extends Shape<
|
|
|
11
11
|
constructor(config?: Config);
|
|
12
12
|
_sceneFunc(context: Context): void;
|
|
13
13
|
getTensionPoints(): any;
|
|
14
|
-
_getTensionPoints():
|
|
15
|
-
_getTensionPointsClosed():
|
|
14
|
+
_getTensionPoints(): number[];
|
|
15
|
+
_getTensionPointsClosed(): number[];
|
|
16
16
|
getWidth(): number;
|
|
17
17
|
getHeight(): number;
|
|
18
18
|
getSelfRect(): {
|
package/lib/shapes/Line.js
CHANGED
|
@@ -33,15 +33,16 @@ class Line extends Shape_1.Shape {
|
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
35
|
_sceneFunc(context) {
|
|
36
|
-
|
|
36
|
+
const points = this.points(), length = points.length, tension = this.tension(), closed = this.closed(), bezier = this.bezier();
|
|
37
37
|
if (!length) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
+
let n = 0;
|
|
40
41
|
context.beginPath();
|
|
41
42
|
context.moveTo(points[0], points[1]);
|
|
42
43
|
if (tension !== 0 && length > 4) {
|
|
43
|
-
tp = this.getTensionPoints();
|
|
44
|
-
len = tp.length;
|
|
44
|
+
const tp = this.getTensionPoints();
|
|
45
|
+
const len = tp.length;
|
|
45
46
|
n = closed ? 0 : 4;
|
|
46
47
|
if (!closed) {
|
|
47
48
|
context.quadraticCurveTo(tp[0], tp[1], tp[2], tp[3]);
|