konva 9.3.15 → 9.3.17
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 +821 -801
- 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 +28 -28
- package/lib/DragAndDrop.d.ts +2 -2
- package/lib/DragAndDrop.js +6 -4
- package/lib/Factory.d.ts +18 -8
- package/lib/Factory.js +17 -16
- package/lib/Global.js +1 -1
- package/lib/Group.js +1 -1
- package/lib/Layer.js +17 -17
- package/lib/Node.d.ts +2 -2
- package/lib/Node.js +89 -89
- package/lib/PointerEvents.js +5 -6
- package/lib/Shape.d.ts +5 -0
- package/lib/Shape.js +37 -37
- package/lib/Stage.d.ts +2 -2
- package/lib/Stage.js +32 -31
- package/lib/Tween.js +31 -27
- package/lib/Util.d.ts +4 -4
- package/lib/Util.js +66 -65
- package/lib/Validators.d.ts +9 -9
- package/lib/Validators.js +12 -13
- package/lib/_CoreInternals.d.ts +8 -8
- package/lib/_FullInternals.d.ts +8 -8
- package/lib/filters/Blur.js +7 -6
- package/lib/filters/Brighten.js +2 -2
- package/lib/filters/Contrast.js +4 -3
- package/lib/filters/Emboss.js +22 -21
- package/lib/filters/Enhance.js +8 -7
- package/lib/filters/Grayscale.js +3 -3
- package/lib/filters/HSL.js +7 -7
- package/lib/filters/HSV.js +7 -7
- package/lib/filters/Invert.js +2 -2
- package/lib/filters/Kaleidoscope.js +44 -44
- package/lib/filters/Mask.js +58 -57
- package/lib/filters/Noise.js +2 -2
- package/lib/filters/Pixelate.js +1 -1
- package/lib/filters/Posterize.js +2 -2
- package/lib/filters/RGB.js +3 -4
- package/lib/filters/RGBA.js +3 -3
- package/lib/filters/Sepia.js +5 -5
- 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 +12 -12
- package/lib/shapes/Ellipse.js +1 -1
- package/lib/shapes/Image.js +3 -3
- package/lib/shapes/Label.d.ts +3 -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 +48 -44
- package/lib/shapes/TextPath.js +25 -25
- package/lib/shapes/Transformer.d.ts +1 -1
- package/lib/shapes/Transformer.js +64 -64
- package/package.json +15 -17
package/lib/Shape.js
CHANGED
|
@@ -8,11 +8,11 @@ const Node_1 = require("./Node");
|
|
|
8
8
|
const Validators_1 = require("./Validators");
|
|
9
9
|
const Global_2 = require("./Global");
|
|
10
10
|
const PointerEvents = require("./PointerEvents");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const HAS_SHADOW = 'hasShadow';
|
|
12
|
+
const SHADOW_RGBA = 'shadowRGBA';
|
|
13
|
+
const patternImage = 'patternImage';
|
|
14
|
+
const linearGradient = 'linearGradient';
|
|
15
|
+
const radialGradient = 'radialGradient';
|
|
16
16
|
let dummyContext;
|
|
17
17
|
function getDummyContext() {
|
|
18
18
|
if (dummyContext) {
|
|
@@ -104,7 +104,7 @@ class Shape extends Node_1.Node {
|
|
|
104
104
|
}
|
|
105
105
|
__getFillPattern() {
|
|
106
106
|
if (this.fillPatternImage()) {
|
|
107
|
-
|
|
107
|
+
const ctx = getDummyContext();
|
|
108
108
|
const pattern = ctx.createPattern(this.fillPatternImage(), this.fillPatternRepeat() || 'repeat');
|
|
109
109
|
if (pattern && pattern.setTransform) {
|
|
110
110
|
const tr = new Util_1.Transform();
|
|
@@ -132,13 +132,13 @@ class Shape extends Node_1.Node {
|
|
|
132
132
|
return this._getCache(linearGradient, this.__getLinearGradient);
|
|
133
133
|
}
|
|
134
134
|
__getLinearGradient() {
|
|
135
|
-
|
|
135
|
+
const colorStops = this.fillLinearGradientColorStops();
|
|
136
136
|
if (colorStops) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
for (
|
|
137
|
+
const ctx = getDummyContext();
|
|
138
|
+
const start = this.fillLinearGradientStartPoint();
|
|
139
|
+
const end = this.fillLinearGradientEndPoint();
|
|
140
|
+
const grd = ctx.createLinearGradient(start.x, start.y, end.x, end.y);
|
|
141
|
+
for (let n = 0; n < colorStops.length; n += 2) {
|
|
142
142
|
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
|
143
143
|
}
|
|
144
144
|
return grd;
|
|
@@ -148,13 +148,13 @@ class Shape extends Node_1.Node {
|
|
|
148
148
|
return this._getCache(radialGradient, this.__getRadialGradient);
|
|
149
149
|
}
|
|
150
150
|
__getRadialGradient() {
|
|
151
|
-
|
|
151
|
+
const colorStops = this.fillRadialGradientColorStops();
|
|
152
152
|
if (colorStops) {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
for (
|
|
153
|
+
const ctx = getDummyContext();
|
|
154
|
+
const start = this.fillRadialGradientStartPoint();
|
|
155
|
+
const end = this.fillRadialGradientEndPoint();
|
|
156
|
+
const grd = ctx.createRadialGradient(start.x, start.y, this.fillRadialGradientStartRadius(), end.x, end.y, this.fillRadialGradientEndRadius());
|
|
157
|
+
for (let n = 0; n < colorStops.length; n += 2) {
|
|
158
158
|
grd.addColorStop(colorStops[n], colorStops[n + 1]);
|
|
159
159
|
}
|
|
160
160
|
return grd;
|
|
@@ -167,7 +167,7 @@ class Shape extends Node_1.Node {
|
|
|
167
167
|
if (!this.hasShadow()) {
|
|
168
168
|
return;
|
|
169
169
|
}
|
|
170
|
-
|
|
170
|
+
const rgba = Util_1.Util.colorToRGBA(this.shadowColor());
|
|
171
171
|
if (rgba) {
|
|
172
172
|
return ('rgba(' +
|
|
173
173
|
rgba.r +
|
|
@@ -215,7 +215,7 @@ class Shape extends Node_1.Node {
|
|
|
215
215
|
return this.strokeEnabled() && !!width;
|
|
216
216
|
}
|
|
217
217
|
intersects(point) {
|
|
218
|
-
|
|
218
|
+
const stage = this.getStage();
|
|
219
219
|
if (!stage) {
|
|
220
220
|
return false;
|
|
221
221
|
}
|
|
@@ -268,7 +268,7 @@ class Shape extends Node_1.Node {
|
|
|
268
268
|
}
|
|
269
269
|
}
|
|
270
270
|
getSelfRect() {
|
|
271
|
-
|
|
271
|
+
const size = this.size();
|
|
272
272
|
return {
|
|
273
273
|
x: this._centroid ? -size.width / 2 : 0,
|
|
274
274
|
y: this._centroid ? -size.height / 2 : 0,
|
|
@@ -317,16 +317,16 @@ class Shape extends Node_1.Node {
|
|
|
317
317
|
return rect;
|
|
318
318
|
}
|
|
319
319
|
drawScene(can, top, bufferCanvas) {
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
320
|
+
const layer = this.getLayer();
|
|
321
|
+
let canvas = can || layer.getCanvas(), context = canvas.getContext(), cachedCanvas = this._getCanvasCache(), drawFunc = this.getSceneFunc(), hasShadow = this.hasShadow(), stage, bufferContext;
|
|
322
|
+
const skipBuffer = canvas.isCache;
|
|
323
|
+
const cachingSelf = top === this;
|
|
324
324
|
if (!this.isVisible() && !cachingSelf) {
|
|
325
325
|
return this;
|
|
326
326
|
}
|
|
327
327
|
if (cachedCanvas) {
|
|
328
328
|
context.save();
|
|
329
|
-
|
|
329
|
+
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
330
330
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
331
331
|
this._drawCachedSceneCanvas(context);
|
|
332
332
|
context.restore();
|
|
@@ -347,7 +347,7 @@ class Shape extends Node_1.Node {
|
|
|
347
347
|
bufferContext.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
348
348
|
drawFunc.call(this, bufferContext, this);
|
|
349
349
|
bufferContext.restore();
|
|
350
|
-
|
|
350
|
+
const ratio = bc.pixelRatio;
|
|
351
351
|
if (hasShadow) {
|
|
352
352
|
context._applyShadow(this);
|
|
353
353
|
}
|
|
@@ -375,13 +375,13 @@ class Shape extends Node_1.Node {
|
|
|
375
375
|
if (!this.shouldDrawHit(top, skipDragCheck)) {
|
|
376
376
|
return this;
|
|
377
377
|
}
|
|
378
|
-
|
|
378
|
+
const layer = this.getLayer(), canvas = can || layer.hitCanvas, context = canvas && canvas.getContext(), drawFunc = this.hitFunc() || this.sceneFunc(), cachedCanvas = this._getCanvasCache(), cachedHitCanvas = cachedCanvas && cachedCanvas.hit;
|
|
379
379
|
if (!this.colorKey) {
|
|
380
380
|
Util_1.Util.warn('Looks like your canvas has a destroyed shape in it. Do not reuse shape after you destroyed it. If you want to reuse shape you should call remove() instead of destroy()');
|
|
381
381
|
}
|
|
382
382
|
if (cachedHitCanvas) {
|
|
383
383
|
context.save();
|
|
384
|
-
|
|
384
|
+
const m = this.getAbsoluteTransform(top).getMatrix();
|
|
385
385
|
context.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
386
386
|
this._drawCachedHitCanvas(context);
|
|
387
387
|
context.restore();
|
|
@@ -394,7 +394,7 @@ class Shape extends Node_1.Node {
|
|
|
394
394
|
context._applyLineJoin(this);
|
|
395
395
|
const selfCache = this === top;
|
|
396
396
|
if (!selfCache) {
|
|
397
|
-
|
|
397
|
+
const o = this.getAbsoluteTransform(top).getMatrix();
|
|
398
398
|
context.transform(o[0], o[1], o[2], o[3], o[4], o[5]);
|
|
399
399
|
}
|
|
400
400
|
drawFunc.call(this, context, this);
|
|
@@ -402,16 +402,16 @@ class Shape extends Node_1.Node {
|
|
|
402
402
|
return this;
|
|
403
403
|
}
|
|
404
404
|
drawHitFromCache(alphaThreshold = 0) {
|
|
405
|
-
|
|
405
|
+
const cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight();
|
|
406
406
|
hitContext.clear();
|
|
407
407
|
hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight);
|
|
408
408
|
try {
|
|
409
|
-
hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
|
|
410
|
-
hitData = hitImageData.data;
|
|
411
|
-
len = hitData.length;
|
|
412
|
-
rgbColorKey = Util_1.Util._hexToRgb(this.colorKey);
|
|
413
|
-
for (i = 0; i < len; i += 4) {
|
|
414
|
-
alpha = hitData[i + 3];
|
|
409
|
+
const hitImageData = hitContext.getImageData(0, 0, hitWidth, hitHeight);
|
|
410
|
+
const hitData = hitImageData.data;
|
|
411
|
+
const len = hitData.length;
|
|
412
|
+
const rgbColorKey = Util_1.Util._hexToRgb(this.colorKey);
|
|
413
|
+
for (let i = 0; i < len; i += 4) {
|
|
414
|
+
const alpha = hitData[i + 3];
|
|
415
415
|
if (alpha > alphaThreshold) {
|
|
416
416
|
hitData[i] = rgbColorKey.r;
|
|
417
417
|
hitData[i + 1] = rgbColorKey.g;
|
package/lib/Stage.d.ts
CHANGED
|
@@ -40,10 +40,10 @@ export declare class Stage extends Container<Layer> {
|
|
|
40
40
|
destroy(): this;
|
|
41
41
|
getPointerPosition(): Vector2d | null;
|
|
42
42
|
_getPointerById(id?: number): (Vector2d & {
|
|
43
|
-
id?: number
|
|
43
|
+
id?: number;
|
|
44
44
|
}) | undefined;
|
|
45
45
|
getPointersPositions(): (Vector2d & {
|
|
46
|
-
id?: number
|
|
46
|
+
id?: number;
|
|
47
47
|
})[];
|
|
48
48
|
getStage(): this;
|
|
49
49
|
getContent(): HTMLDivElement;
|
package/lib/Stage.js
CHANGED
|
@@ -9,7 +9,7 @@ const Canvas_1 = require("./Canvas");
|
|
|
9
9
|
const DragAndDrop_1 = require("./DragAndDrop");
|
|
10
10
|
const Global_2 = require("./Global");
|
|
11
11
|
const PointerEvents = require("./PointerEvents");
|
|
12
|
-
|
|
12
|
+
const STAGE = 'Stage', STRING = 'string', PX = 'px', MOUSEOUT = 'mouseout', MOUSELEAVE = 'mouseleave', MOUSEOVER = 'mouseover', MOUSEENTER = 'mouseenter', MOUSEMOVE = 'mousemove', MOUSEDOWN = 'mousedown', MOUSEUP = 'mouseup', POINTERMOVE = 'pointermove', POINTERDOWN = 'pointerdown', POINTERUP = 'pointerup', POINTERCANCEL = 'pointercancel', LOSTPOINTERCAPTURE = 'lostpointercapture', POINTEROUT = 'pointerout', POINTERLEAVE = 'pointerleave', POINTEROVER = 'pointerover', POINTERENTER = 'pointerenter', CONTEXTMENU = 'contextmenu', TOUCHSTART = 'touchstart', TOUCHEND = 'touchend', TOUCHMOVE = 'touchmove', TOUCHCANCEL = 'touchcancel', WHEEL = 'wheel', MAX_LAYERS_NUMBER = 5, EVENTS = [
|
|
13
13
|
[MOUSEENTER, '_pointerenter'],
|
|
14
14
|
[MOUSEDOWN, '_pointerdown'],
|
|
15
15
|
[MOUSEMOVE, '_pointermove'],
|
|
@@ -128,7 +128,7 @@ class Stage extends Container_1.Container {
|
|
|
128
128
|
setContainer(container) {
|
|
129
129
|
if (typeof container === STRING) {
|
|
130
130
|
if (container.charAt(0) === '.') {
|
|
131
|
-
|
|
131
|
+
const className = container.slice(1);
|
|
132
132
|
container = document.getElementsByClassName(className)[0];
|
|
133
133
|
}
|
|
134
134
|
else {
|
|
@@ -158,8 +158,8 @@ class Stage extends Container_1.Container {
|
|
|
158
158
|
return true;
|
|
159
159
|
}
|
|
160
160
|
clear() {
|
|
161
|
-
|
|
162
|
-
for (n = 0; n < len; n++) {
|
|
161
|
+
const layers = this.children, len = layers.length;
|
|
162
|
+
for (let n = 0; n < len; n++) {
|
|
163
163
|
layers[n].clear();
|
|
164
164
|
}
|
|
165
165
|
return this;
|
|
@@ -174,11 +174,11 @@ class Stage extends Container_1.Container {
|
|
|
174
174
|
}
|
|
175
175
|
destroy() {
|
|
176
176
|
super.destroy();
|
|
177
|
-
|
|
177
|
+
const content = this.content;
|
|
178
178
|
if (content && Util_1.Util._isInDocument(content)) {
|
|
179
179
|
this.container().removeChild(content);
|
|
180
180
|
}
|
|
181
|
-
|
|
181
|
+
const index = exports.stages.indexOf(this);
|
|
182
182
|
if (index > -1) {
|
|
183
183
|
exports.stages.splice(index, 1);
|
|
184
184
|
}
|
|
@@ -214,13 +214,13 @@ class Stage extends Container_1.Container {
|
|
|
214
214
|
config.y = config.y || 0;
|
|
215
215
|
config.width = config.width || this.width();
|
|
216
216
|
config.height = config.height || this.height();
|
|
217
|
-
|
|
217
|
+
const canvas = new Canvas_1.SceneCanvas({
|
|
218
218
|
width: config.width,
|
|
219
219
|
height: config.height,
|
|
220
220
|
pixelRatio: config.pixelRatio || 1,
|
|
221
221
|
});
|
|
222
|
-
|
|
223
|
-
|
|
222
|
+
const _context = canvas.getContext()._context;
|
|
223
|
+
const layers = this.children;
|
|
224
224
|
if (config.x || config.y) {
|
|
225
225
|
_context.translate(-1 * config.x, -1 * config.y);
|
|
226
226
|
}
|
|
@@ -228,7 +228,7 @@ class Stage extends Container_1.Container {
|
|
|
228
228
|
if (!layer.isVisible()) {
|
|
229
229
|
return;
|
|
230
230
|
}
|
|
231
|
-
|
|
231
|
+
const layerCanvas = layer._toKonvaCanvas(config);
|
|
232
232
|
_context.drawImage(layerCanvas._canvas, config.x, config.y, layerCanvas.getWidth() / layerCanvas.getPixelRatio(), layerCanvas.getHeight() / layerCanvas.getPixelRatio());
|
|
233
233
|
});
|
|
234
234
|
return canvas;
|
|
@@ -237,8 +237,8 @@ class Stage extends Container_1.Container {
|
|
|
237
237
|
if (!pos) {
|
|
238
238
|
return null;
|
|
239
239
|
}
|
|
240
|
-
|
|
241
|
-
for (n = end; n >= 0; n--) {
|
|
240
|
+
const layers = this.children, len = layers.length, end = len - 1;
|
|
241
|
+
for (let n = end; n >= 0; n--) {
|
|
242
242
|
const shape = layers[n].getIntersection(pos);
|
|
243
243
|
if (shape) {
|
|
244
244
|
return shape;
|
|
@@ -247,8 +247,8 @@ class Stage extends Container_1.Container {
|
|
|
247
247
|
return null;
|
|
248
248
|
}
|
|
249
249
|
_resizeDOM() {
|
|
250
|
-
|
|
251
|
-
|
|
250
|
+
const width = this.width();
|
|
251
|
+
const height = this.height();
|
|
252
252
|
if (this.content) {
|
|
253
253
|
this.content.style.width = width + PX;
|
|
254
254
|
this.content.style.height = height + PX;
|
|
@@ -262,13 +262,13 @@ class Stage extends Container_1.Container {
|
|
|
262
262
|
}
|
|
263
263
|
add(layer, ...rest) {
|
|
264
264
|
if (arguments.length > 1) {
|
|
265
|
-
for (
|
|
265
|
+
for (let i = 0; i < arguments.length; i++) {
|
|
266
266
|
this.add(arguments[i]);
|
|
267
267
|
}
|
|
268
268
|
return this;
|
|
269
269
|
}
|
|
270
270
|
super.add(layer);
|
|
271
|
-
|
|
271
|
+
const length = this.children.length;
|
|
272
272
|
if (length > MAX_LAYERS_NUMBER) {
|
|
273
273
|
Util_1.Util.warn('The stage has ' +
|
|
274
274
|
length +
|
|
@@ -345,8 +345,8 @@ class Stage extends Container_1.Container {
|
|
|
345
345
|
return;
|
|
346
346
|
}
|
|
347
347
|
this.setPointersPositions(evt);
|
|
348
|
-
|
|
349
|
-
|
|
348
|
+
const targetShape = this._getTargetShape(eventType);
|
|
349
|
+
const eventsEnabled = !(Global_1.Konva.isDragging() || Global_1.Konva.isTransforming()) || Global_1.Konva.hitOnDragEnabled;
|
|
350
350
|
if (targetShape && eventsEnabled) {
|
|
351
351
|
targetShape._fireAndBubble(events.pointerout, { evt: evt });
|
|
352
352
|
targetShape._fireAndBubble(events.pointerleave, { evt: evt });
|
|
@@ -379,9 +379,9 @@ class Stage extends Container_1.Container {
|
|
|
379
379
|
return;
|
|
380
380
|
}
|
|
381
381
|
this.setPointersPositions(evt);
|
|
382
|
-
|
|
382
|
+
let triggeredOnShape = false;
|
|
383
383
|
this._changedPointerPositions.forEach((pos) => {
|
|
384
|
-
|
|
384
|
+
const shape = this.getIntersection(pos);
|
|
385
385
|
DragAndDrop_1.DD.justDragged = false;
|
|
386
386
|
Global_1.Konva['_' + eventType + 'ListenClick'] = true;
|
|
387
387
|
if (!shape || !shape.isListening()) {
|
|
@@ -421,19 +421,19 @@ class Stage extends Container_1.Container {
|
|
|
421
421
|
evt.preventDefault();
|
|
422
422
|
}
|
|
423
423
|
this.setPointersPositions(evt);
|
|
424
|
-
|
|
424
|
+
const eventsEnabled = !(Global_1.Konva.isDragging() || Global_1.Konva.isTransforming()) || Global_1.Konva.hitOnDragEnabled;
|
|
425
425
|
if (!eventsEnabled) {
|
|
426
426
|
return;
|
|
427
427
|
}
|
|
428
|
-
|
|
428
|
+
const processedShapesIds = {};
|
|
429
429
|
let triggeredOnShape = false;
|
|
430
|
-
|
|
430
|
+
const targetShape = this._getTargetShape(eventType);
|
|
431
431
|
this._changedPointerPositions.forEach((pos) => {
|
|
432
432
|
const shape = (PointerEvents.getCapturedShape(pos.id) ||
|
|
433
433
|
this.getIntersection(pos));
|
|
434
434
|
const pointerId = pos.id;
|
|
435
435
|
const event = { evt: evt, pointerId };
|
|
436
|
-
|
|
436
|
+
const differentTarget = targetShape !== shape;
|
|
437
437
|
if (differentTarget && targetShape) {
|
|
438
438
|
targetShape._fireAndBubble(events.pointerout, { ...event }, shape);
|
|
439
439
|
targetShape._fireAndBubble(events.pointerleave, { ...event }, shape);
|
|
@@ -483,7 +483,7 @@ class Stage extends Container_1.Container {
|
|
|
483
483
|
this.setPointersPositions(evt);
|
|
484
484
|
const clickStartShape = this[eventType + 'ClickStartShape'];
|
|
485
485
|
const clickEndShape = this[eventType + 'ClickEndShape'];
|
|
486
|
-
|
|
486
|
+
const processedShapesIds = {};
|
|
487
487
|
let triggeredOnShape = false;
|
|
488
488
|
this._changedPointerPositions.forEach((pos) => {
|
|
489
489
|
const shape = (PointerEvents.getCapturedShape(pos.id) ||
|
|
@@ -551,13 +551,13 @@ class Stage extends Container_1.Container {
|
|
|
551
551
|
});
|
|
552
552
|
}
|
|
553
553
|
Global_1.Konva['_' + eventType + 'ListenClick'] = false;
|
|
554
|
-
if (evt.cancelable && eventType !== 'touch') {
|
|
554
|
+
if (evt.cancelable && eventType !== 'touch' && eventType !== 'pointer') {
|
|
555
555
|
evt.preventDefault();
|
|
556
556
|
}
|
|
557
557
|
}
|
|
558
558
|
_contextmenu(evt) {
|
|
559
559
|
this.setPointersPositions(evt);
|
|
560
|
-
|
|
560
|
+
const shape = this.getIntersection(this.getPointerPosition());
|
|
561
561
|
if (shape && shape.isListening()) {
|
|
562
562
|
shape._fireAndBubble(CONTEXTMENU, { evt: evt });
|
|
563
563
|
}
|
|
@@ -571,7 +571,7 @@ class Stage extends Container_1.Container {
|
|
|
571
571
|
}
|
|
572
572
|
_wheel(evt) {
|
|
573
573
|
this.setPointersPositions(evt);
|
|
574
|
-
|
|
574
|
+
const shape = this.getIntersection(this.getPointerPosition());
|
|
575
575
|
if (shape && shape.isListening()) {
|
|
576
576
|
shape._fireAndBubble(WHEEL, { evt: evt });
|
|
577
577
|
}
|
|
@@ -596,7 +596,8 @@ class Stage extends Container_1.Container {
|
|
|
596
596
|
PointerEvents.releaseCapture(evt.pointerId);
|
|
597
597
|
}
|
|
598
598
|
setPointersPositions(evt) {
|
|
599
|
-
|
|
599
|
+
const contentPosition = this._getContentPosition();
|
|
600
|
+
let x = null, y = null;
|
|
600
601
|
evt = evt ? evt : window.event;
|
|
601
602
|
if (evt.touches !== undefined) {
|
|
602
603
|
this._pointerPositions = [];
|
|
@@ -642,7 +643,7 @@ class Stage extends Container_1.Container {
|
|
|
642
643
|
scaleY: 1,
|
|
643
644
|
};
|
|
644
645
|
}
|
|
645
|
-
|
|
646
|
+
const rect = this.content.getBoundingClientRect();
|
|
646
647
|
return {
|
|
647
648
|
top: rect.top,
|
|
648
649
|
left: rect.left,
|
|
@@ -663,7 +664,7 @@ class Stage extends Container_1.Container {
|
|
|
663
664
|
if (!Global_1.Konva.isBrowser) {
|
|
664
665
|
return;
|
|
665
666
|
}
|
|
666
|
-
|
|
667
|
+
const container = this.container();
|
|
667
668
|
if (!container) {
|
|
668
669
|
throw 'Stage has no container. A container is required.';
|
|
669
670
|
}
|
package/lib/Tween.js
CHANGED
|
@@ -5,13 +5,14 @@ const Util_1 = require("./Util");
|
|
|
5
5
|
const Animation_1 = require("./Animation");
|
|
6
6
|
const Node_1 = require("./Node");
|
|
7
7
|
const Global_1 = require("./Global");
|
|
8
|
-
|
|
8
|
+
const blacklist = {
|
|
9
9
|
node: 1,
|
|
10
10
|
duration: 1,
|
|
11
11
|
easing: 1,
|
|
12
12
|
onFinish: 1,
|
|
13
13
|
yoyo: 1,
|
|
14
|
-
}, PAUSED = 1, PLAYING = 2, REVERSING = 3,
|
|
14
|
+
}, PAUSED = 1, PLAYING = 2, REVERSING = 3, colorAttrs = ['fill', 'stroke', 'shadowColor'];
|
|
15
|
+
let idCounter = 0;
|
|
15
16
|
class TweenEngine {
|
|
16
17
|
constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
|
|
17
18
|
this.prop = prop;
|
|
@@ -31,7 +32,7 @@ class TweenEngine {
|
|
|
31
32
|
this.pause();
|
|
32
33
|
}
|
|
33
34
|
fire(str) {
|
|
34
|
-
|
|
35
|
+
const handler = this[str];
|
|
35
36
|
if (handler) {
|
|
36
37
|
handler();
|
|
37
38
|
}
|
|
@@ -110,7 +111,7 @@ class TweenEngine {
|
|
|
110
111
|
this.fire('onUpdate');
|
|
111
112
|
}
|
|
112
113
|
onEnterFrame() {
|
|
113
|
-
|
|
114
|
+
const t = this.getTimer() - this._startTime;
|
|
114
115
|
if (this.state === PLAYING) {
|
|
115
116
|
this.setTime(t);
|
|
116
117
|
}
|
|
@@ -128,7 +129,8 @@ class TweenEngine {
|
|
|
128
129
|
}
|
|
129
130
|
class Tween {
|
|
130
131
|
constructor(config) {
|
|
131
|
-
|
|
132
|
+
const that = this, node = config.node, nodeId = node._id, easing = config.easing || exports.Easings.Linear, yoyo = !!config.yoyo;
|
|
133
|
+
let duration, key;
|
|
132
134
|
if (typeof config.duration === 'undefined') {
|
|
133
135
|
duration = 0.3;
|
|
134
136
|
}
|
|
@@ -140,7 +142,7 @@ class Tween {
|
|
|
140
142
|
}
|
|
141
143
|
this.node = node;
|
|
142
144
|
this._id = idCounter++;
|
|
143
|
-
|
|
145
|
+
const layers = node.getLayer() ||
|
|
144
146
|
(node instanceof Global_1.Konva['Stage'] ? node.getLayers() : null);
|
|
145
147
|
if (!layers) {
|
|
146
148
|
Util_1.Util.error('Tween constructor have `node` that is not in a layer. Please add node into layer first.');
|
|
@@ -172,12 +174,13 @@ class Tween {
|
|
|
172
174
|
this.onUpdate = config.onUpdate;
|
|
173
175
|
}
|
|
174
176
|
_addAttr(key, end) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
const node = this.node, nodeId = node._id;
|
|
178
|
+
let diff, len, trueEnd, trueStart, endRGBA;
|
|
179
|
+
const tweenId = Tween.tweens[nodeId][key];
|
|
177
180
|
if (tweenId) {
|
|
178
181
|
delete Tween.attrs[nodeId][tweenId][key];
|
|
179
182
|
}
|
|
180
|
-
start = node.getAttr(key);
|
|
183
|
+
let start = node.getAttr(key);
|
|
181
184
|
if (Util_1.Util._isArray(end)) {
|
|
182
185
|
diff = [];
|
|
183
186
|
len = Math.max(end.length, start.length);
|
|
@@ -192,12 +195,12 @@ class Tween {
|
|
|
192
195
|
}
|
|
193
196
|
}
|
|
194
197
|
if (key.indexOf('fill') === 0) {
|
|
195
|
-
for (n = 0; n < len; n++) {
|
|
198
|
+
for (let n = 0; n < len; n++) {
|
|
196
199
|
if (n % 2 === 0) {
|
|
197
200
|
diff.push(end[n] - start[n]);
|
|
198
201
|
}
|
|
199
202
|
else {
|
|
200
|
-
|
|
203
|
+
const startRGBA = Util_1.Util.colorToRGBA(start[n]);
|
|
201
204
|
endRGBA = Util_1.Util.colorToRGBA(end[n]);
|
|
202
205
|
start[n] = startRGBA;
|
|
203
206
|
diff.push({
|
|
@@ -210,7 +213,7 @@ class Tween {
|
|
|
210
213
|
}
|
|
211
214
|
}
|
|
212
215
|
else {
|
|
213
|
-
for (n = 0; n < len; n++) {
|
|
216
|
+
for (let n = 0; n < len; n++) {
|
|
214
217
|
diff.push(end[n] - start[n]);
|
|
215
218
|
}
|
|
216
219
|
}
|
|
@@ -238,7 +241,8 @@ class Tween {
|
|
|
238
241
|
Tween.tweens[nodeId][key] = this._id;
|
|
239
242
|
}
|
|
240
243
|
_tweenFunc(i) {
|
|
241
|
-
|
|
244
|
+
const node = this.node, attrs = Tween.attrs[node._id][this._id];
|
|
245
|
+
let key, attr, start, diff, newVal, n, len, end;
|
|
242
246
|
for (key in attrs) {
|
|
243
247
|
attr = attrs[key];
|
|
244
248
|
start = attr.start;
|
|
@@ -300,8 +304,8 @@ class Tween {
|
|
|
300
304
|
this.anim.stop();
|
|
301
305
|
};
|
|
302
306
|
this.tween.onFinish = () => {
|
|
303
|
-
|
|
304
|
-
|
|
307
|
+
const node = this.node;
|
|
308
|
+
const attrs = Tween.attrs[node._id][this._id];
|
|
305
309
|
if (attrs.points && attrs.points.trueEnd) {
|
|
306
310
|
node.setAttr('points', attrs.points.trueEnd);
|
|
307
311
|
}
|
|
@@ -310,8 +314,8 @@ class Tween {
|
|
|
310
314
|
}
|
|
311
315
|
};
|
|
312
316
|
this.tween.onReset = () => {
|
|
313
|
-
|
|
314
|
-
|
|
317
|
+
const node = this.node;
|
|
318
|
+
const attrs = Tween.attrs[node._id][this._id];
|
|
315
319
|
if (attrs.points && attrs.points.trueStart) {
|
|
316
320
|
node.points(attrs.points.trueStart);
|
|
317
321
|
}
|
|
@@ -350,9 +354,9 @@ class Tween {
|
|
|
350
354
|
return this;
|
|
351
355
|
}
|
|
352
356
|
destroy() {
|
|
353
|
-
|
|
357
|
+
const nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId];
|
|
354
358
|
this.pause();
|
|
355
|
-
for (key in attrs) {
|
|
359
|
+
for (const key in attrs) {
|
|
356
360
|
delete Tween.tweens[nodeId][key];
|
|
357
361
|
}
|
|
358
362
|
delete Tween.attrs[nodeId][thisId];
|
|
@@ -362,7 +366,7 @@ exports.Tween = Tween;
|
|
|
362
366
|
Tween.attrs = {};
|
|
363
367
|
Tween.tweens = {};
|
|
364
368
|
Node_1.Node.prototype.to = function (params) {
|
|
365
|
-
|
|
369
|
+
const onFinish = params.onFinish;
|
|
366
370
|
params.node = this;
|
|
367
371
|
params.onFinish = function () {
|
|
368
372
|
this.destroy();
|
|
@@ -370,27 +374,27 @@ Node_1.Node.prototype.to = function (params) {
|
|
|
370
374
|
onFinish();
|
|
371
375
|
}
|
|
372
376
|
};
|
|
373
|
-
|
|
377
|
+
const tween = new Tween(params);
|
|
374
378
|
tween.play();
|
|
375
379
|
};
|
|
376
380
|
exports.Easings = {
|
|
377
381
|
BackEaseIn(t, b, c, d) {
|
|
378
|
-
|
|
382
|
+
const s = 1.70158;
|
|
379
383
|
return c * (t /= d) * t * ((s + 1) * t - s) + b;
|
|
380
384
|
},
|
|
381
385
|
BackEaseOut(t, b, c, d) {
|
|
382
|
-
|
|
386
|
+
const s = 1.70158;
|
|
383
387
|
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
|
|
384
388
|
},
|
|
385
389
|
BackEaseInOut(t, b, c, d) {
|
|
386
|
-
|
|
390
|
+
let s = 1.70158;
|
|
387
391
|
if ((t /= d / 2) < 1) {
|
|
388
392
|
return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
|
|
389
393
|
}
|
|
390
394
|
return (c / 2) * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
|
|
391
395
|
},
|
|
392
396
|
ElasticEaseIn(t, b, c, d, a, p) {
|
|
393
|
-
|
|
397
|
+
let s = 0;
|
|
394
398
|
if (t === 0) {
|
|
395
399
|
return b;
|
|
396
400
|
}
|
|
@@ -412,7 +416,7 @@ exports.Easings = {
|
|
|
412
416
|
Math.sin(((t * d - s) * (2 * Math.PI)) / p)) + b);
|
|
413
417
|
},
|
|
414
418
|
ElasticEaseOut(t, b, c, d, a, p) {
|
|
415
|
-
|
|
419
|
+
let s = 0;
|
|
416
420
|
if (t === 0) {
|
|
417
421
|
return b;
|
|
418
422
|
}
|
|
@@ -434,7 +438,7 @@ exports.Easings = {
|
|
|
434
438
|
b);
|
|
435
439
|
},
|
|
436
440
|
ElasticEaseInOut(t, b, c, d, a, p) {
|
|
437
|
-
|
|
441
|
+
let s = 0;
|
|
438
442
|
if (t === 0) {
|
|
439
443
|
return b;
|
|
440
444
|
}
|
package/lib/Util.d.ts
CHANGED
|
@@ -36,11 +36,11 @@ export declare const Util: {
|
|
|
36
36
|
_isElement(obj: any): obj is Element;
|
|
37
37
|
_isFunction(obj: any): boolean;
|
|
38
38
|
_isPlainObject(obj: any): boolean;
|
|
39
|
-
_isArray(obj: any): obj is any
|
|
39
|
+
_isArray(obj: any): obj is Array<any>;
|
|
40
40
|
_isNumber(obj: any): obj is number;
|
|
41
41
|
_isString(obj: any): obj is string;
|
|
42
42
|
_isBoolean(obj: any): obj is boolean;
|
|
43
|
-
isObject(val: any): val is
|
|
43
|
+
isObject(val: any): val is object;
|
|
44
44
|
isValidSelector(selector: any): boolean;
|
|
45
45
|
_sign(number: number): 1 | -1;
|
|
46
46
|
requestAnimFrame(callback: Function): void;
|
|
@@ -118,13 +118,13 @@ export declare const Util: {
|
|
|
118
118
|
throw(str: string): never;
|
|
119
119
|
error(str: string): void;
|
|
120
120
|
warn(str: string): void;
|
|
121
|
-
each(obj:
|
|
121
|
+
each(obj: object, func: Function): void;
|
|
122
122
|
_inRange(val: number, left: number, right: number): boolean;
|
|
123
123
|
_getProjectionToSegment(x1: any, y1: any, x2: any, y2: any, x3: any, y3: any): any[];
|
|
124
124
|
_getProjectionToLine(pt: Vector2d, line: Array<Vector2d>, isClosed: boolean): Vector2d;
|
|
125
125
|
_prepareArrayForTween(startArray: any, endArray: any, isClosed: any): number[];
|
|
126
126
|
_prepareToStringify<T>(obj: any): T | null;
|
|
127
|
-
_assign<
|
|
127
|
+
_assign<T, U>(target: T, source: U): T & U;
|
|
128
128
|
_getFirstPointerId(evt: any): any;
|
|
129
129
|
releaseCanvas(...canvases: HTMLCanvasElement[]): void;
|
|
130
130
|
drawRoundedRectPath(context: Context, width: number, height: number, cornerRadius: number | number[]): void;
|