konva 9.3.15 → 9.3.16
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 +726 -724
- 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 +26 -26
- package/lib/DragAndDrop.d.ts +2 -2
- package/lib/DragAndDrop.js +6 -4
- package/lib/Factory.js +16 -16
- package/lib/Global.js +1 -1
- package/lib/Group.js +1 -1
- package/lib/Layer.js +17 -17
- package/lib/Node.d.ts +1 -1
- package/lib/Node.js +87 -87
- package/lib/PointerEvents.js +5 -6
- package/lib/Shape.js +31 -31
- package/lib/Stage.d.ts +2 -2
- package/lib/Stage.js +28 -28
- package/lib/Tween.js +21 -21
- package/lib/Util.d.ts +4 -4
- package/lib/Util.js +62 -62
- package/lib/Validators.js +16 -17
- package/lib/_CoreInternals.d.ts +8 -8
- package/lib/_FullInternals.d.ts +8 -8
- package/lib/filters/Blur.js +6 -6
- package/lib/filters/Brighten.js +1 -1
- package/lib/filters/Contrast.js +2 -2
- package/lib/filters/Emboss.js +19 -19
- package/lib/filters/Enhance.js +4 -4
- package/lib/filters/Grayscale.js +1 -1
- package/lib/filters/HSL.js +6 -6
- package/lib/filters/HSV.js +7 -7
- package/lib/filters/Invert.js +1 -1
- package/lib/filters/Kaleidoscope.js +20 -20
- package/lib/filters/Mask.js +57 -57
- package/lib/filters/Noise.js +2 -2
- package/lib/filters/Pixelate.js +1 -1
- package/lib/filters/Posterize.js +1 -1
- package/lib/filters/RGB.js +1 -1
- package/lib/filters/RGBA.js +3 -3
- package/lib/filters/Sepia.js +1 -1
- 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 +10 -10
- package/lib/shapes/Ellipse.js +1 -1
- package/lib/shapes/Image.js +3 -3
- package/lib/shapes/Label.d.ts +1 -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 +37 -37
- package/lib/shapes/TextPath.js +23 -23
- package/lib/shapes/Transformer.d.ts +1 -1
- package/lib/shapes/Transformer.js +63 -63
- package/package.json +2 -5
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,7 +402,7 @@ class Shape extends Node_1.Node {
|
|
|
402
402
|
return this;
|
|
403
403
|
}
|
|
404
404
|
drawHitFromCache(alphaThreshold = 0) {
|
|
405
|
-
|
|
405
|
+
let cachedCanvas = this._getCanvasCache(), sceneCanvas = this._getCachedSceneCanvas(), hitCanvas = cachedCanvas.hit, hitContext = hitCanvas.getContext(), hitWidth = hitCanvas.getWidth(), hitHeight = hitCanvas.getHeight(), hitImageData, hitData, len, rgbColorKey, i, alpha;
|
|
406
406
|
hitContext.clear();
|
|
407
407
|
hitContext.drawImage(sceneCanvas._canvas, 0, 0, hitWidth, hitHeight);
|
|
408
408
|
try {
|
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,7 +158,7 @@ class Stage extends Container_1.Container {
|
|
|
158
158
|
return true;
|
|
159
159
|
}
|
|
160
160
|
clear() {
|
|
161
|
-
|
|
161
|
+
let layers = this.children, len = layers.length, n;
|
|
162
162
|
for (n = 0; n < len; n++) {
|
|
163
163
|
layers[n].clear();
|
|
164
164
|
}
|
|
@@ -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,7 +237,7 @@ class Stage extends Container_1.Container {
|
|
|
237
237
|
if (!pos) {
|
|
238
238
|
return null;
|
|
239
239
|
}
|
|
240
|
-
|
|
240
|
+
let layers = this.children, len = layers.length, end = len - 1, n;
|
|
241
241
|
for (n = end; n >= 0; n--) {
|
|
242
242
|
const shape = layers[n].getIntersection(pos);
|
|
243
243
|
if (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) ||
|
|
@@ -557,7 +557,7 @@ class Stage extends Container_1.Container {
|
|
|
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,7 @@ class Stage extends Container_1.Container {
|
|
|
596
596
|
PointerEvents.releaseCapture(evt.pointerId);
|
|
597
597
|
}
|
|
598
598
|
setPointersPositions(evt) {
|
|
599
|
-
|
|
599
|
+
let contentPosition = this._getContentPosition(), x = null, y = null;
|
|
600
600
|
evt = evt ? evt : window.event;
|
|
601
601
|
if (evt.touches !== undefined) {
|
|
602
602
|
this._pointerPositions = [];
|
|
@@ -642,7 +642,7 @@ class Stage extends Container_1.Container {
|
|
|
642
642
|
scaleY: 1,
|
|
643
643
|
};
|
|
644
644
|
}
|
|
645
|
-
|
|
645
|
+
const rect = this.content.getBoundingClientRect();
|
|
646
646
|
return {
|
|
647
647
|
top: rect.top,
|
|
648
648
|
left: rect.left,
|
|
@@ -663,7 +663,7 @@ class Stage extends Container_1.Container {
|
|
|
663
663
|
if (!Global_1.Konva.isBrowser) {
|
|
664
664
|
return;
|
|
665
665
|
}
|
|
666
|
-
|
|
666
|
+
const container = this.container();
|
|
667
667
|
if (!container) {
|
|
668
668
|
throw 'Stage has no container. A container is required.';
|
|
669
669
|
}
|
package/lib/Tween.js
CHANGED
|
@@ -5,7 +5,7 @@ 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
|
+
let blacklist = {
|
|
9
9
|
node: 1,
|
|
10
10
|
duration: 1,
|
|
11
11
|
easing: 1,
|
|
@@ -31,7 +31,7 @@ class TweenEngine {
|
|
|
31
31
|
this.pause();
|
|
32
32
|
}
|
|
33
33
|
fire(str) {
|
|
34
|
-
|
|
34
|
+
const handler = this[str];
|
|
35
35
|
if (handler) {
|
|
36
36
|
handler();
|
|
37
37
|
}
|
|
@@ -110,7 +110,7 @@ class TweenEngine {
|
|
|
110
110
|
this.fire('onUpdate');
|
|
111
111
|
}
|
|
112
112
|
onEnterFrame() {
|
|
113
|
-
|
|
113
|
+
const t = this.getTimer() - this._startTime;
|
|
114
114
|
if (this.state === PLAYING) {
|
|
115
115
|
this.setTime(t);
|
|
116
116
|
}
|
|
@@ -128,7 +128,7 @@ class TweenEngine {
|
|
|
128
128
|
}
|
|
129
129
|
class Tween {
|
|
130
130
|
constructor(config) {
|
|
131
|
-
|
|
131
|
+
let that = this, node = config.node, nodeId = node._id, duration, easing = config.easing || exports.Easings.Linear, yoyo = !!config.yoyo, key;
|
|
132
132
|
if (typeof config.duration === 'undefined') {
|
|
133
133
|
duration = 0.3;
|
|
134
134
|
}
|
|
@@ -140,7 +140,7 @@ class Tween {
|
|
|
140
140
|
}
|
|
141
141
|
this.node = node;
|
|
142
142
|
this._id = idCounter++;
|
|
143
|
-
|
|
143
|
+
const layers = node.getLayer() ||
|
|
144
144
|
(node instanceof Global_1.Konva['Stage'] ? node.getLayers() : null);
|
|
145
145
|
if (!layers) {
|
|
146
146
|
Util_1.Util.error('Tween constructor have `node` that is not in a layer. Please add node into layer first.');
|
|
@@ -172,7 +172,7 @@ class Tween {
|
|
|
172
172
|
this.onUpdate = config.onUpdate;
|
|
173
173
|
}
|
|
174
174
|
_addAttr(key, end) {
|
|
175
|
-
|
|
175
|
+
let node = this.node, nodeId = node._id, start, diff, tweenId, n, len, trueEnd, trueStart, endRGBA;
|
|
176
176
|
tweenId = Tween.tweens[nodeId][key];
|
|
177
177
|
if (tweenId) {
|
|
178
178
|
delete Tween.attrs[nodeId][tweenId][key];
|
|
@@ -197,7 +197,7 @@ class Tween {
|
|
|
197
197
|
diff.push(end[n] - start[n]);
|
|
198
198
|
}
|
|
199
199
|
else {
|
|
200
|
-
|
|
200
|
+
const startRGBA = Util_1.Util.colorToRGBA(start[n]);
|
|
201
201
|
endRGBA = Util_1.Util.colorToRGBA(end[n]);
|
|
202
202
|
start[n] = startRGBA;
|
|
203
203
|
diff.push({
|
|
@@ -238,7 +238,7 @@ class Tween {
|
|
|
238
238
|
Tween.tweens[nodeId][key] = this._id;
|
|
239
239
|
}
|
|
240
240
|
_tweenFunc(i) {
|
|
241
|
-
|
|
241
|
+
let node = this.node, attrs = Tween.attrs[node._id][this._id], key, attr, start, diff, newVal, n, len, end;
|
|
242
242
|
for (key in attrs) {
|
|
243
243
|
attr = attrs[key];
|
|
244
244
|
start = attr.start;
|
|
@@ -300,8 +300,8 @@ class Tween {
|
|
|
300
300
|
this.anim.stop();
|
|
301
301
|
};
|
|
302
302
|
this.tween.onFinish = () => {
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
const node = this.node;
|
|
304
|
+
const attrs = Tween.attrs[node._id][this._id];
|
|
305
305
|
if (attrs.points && attrs.points.trueEnd) {
|
|
306
306
|
node.setAttr('points', attrs.points.trueEnd);
|
|
307
307
|
}
|
|
@@ -310,8 +310,8 @@ class Tween {
|
|
|
310
310
|
}
|
|
311
311
|
};
|
|
312
312
|
this.tween.onReset = () => {
|
|
313
|
-
|
|
314
|
-
|
|
313
|
+
const node = this.node;
|
|
314
|
+
const attrs = Tween.attrs[node._id][this._id];
|
|
315
315
|
if (attrs.points && attrs.points.trueStart) {
|
|
316
316
|
node.points(attrs.points.trueStart);
|
|
317
317
|
}
|
|
@@ -350,7 +350,7 @@ class Tween {
|
|
|
350
350
|
return this;
|
|
351
351
|
}
|
|
352
352
|
destroy() {
|
|
353
|
-
|
|
353
|
+
let nodeId = this.node._id, thisId = this._id, attrs = Tween.tweens[nodeId], key;
|
|
354
354
|
this.pause();
|
|
355
355
|
for (key in attrs) {
|
|
356
356
|
delete Tween.tweens[nodeId][key];
|
|
@@ -362,7 +362,7 @@ exports.Tween = Tween;
|
|
|
362
362
|
Tween.attrs = {};
|
|
363
363
|
Tween.tweens = {};
|
|
364
364
|
Node_1.Node.prototype.to = function (params) {
|
|
365
|
-
|
|
365
|
+
const onFinish = params.onFinish;
|
|
366
366
|
params.node = this;
|
|
367
367
|
params.onFinish = function () {
|
|
368
368
|
this.destroy();
|
|
@@ -370,27 +370,27 @@ Node_1.Node.prototype.to = function (params) {
|
|
|
370
370
|
onFinish();
|
|
371
371
|
}
|
|
372
372
|
};
|
|
373
|
-
|
|
373
|
+
const tween = new Tween(params);
|
|
374
374
|
tween.play();
|
|
375
375
|
};
|
|
376
376
|
exports.Easings = {
|
|
377
377
|
BackEaseIn(t, b, c, d) {
|
|
378
|
-
|
|
378
|
+
const s = 1.70158;
|
|
379
379
|
return c * (t /= d) * t * ((s + 1) * t - s) + b;
|
|
380
380
|
},
|
|
381
381
|
BackEaseOut(t, b, c, d) {
|
|
382
|
-
|
|
382
|
+
const s = 1.70158;
|
|
383
383
|
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
|
|
384
384
|
},
|
|
385
385
|
BackEaseInOut(t, b, c, d) {
|
|
386
|
-
|
|
386
|
+
let s = 1.70158;
|
|
387
387
|
if ((t /= d / 2) < 1) {
|
|
388
388
|
return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
|
|
389
389
|
}
|
|
390
390
|
return (c / 2) * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
|
|
391
391
|
},
|
|
392
392
|
ElasticEaseIn(t, b, c, d, a, p) {
|
|
393
|
-
|
|
393
|
+
let s = 0;
|
|
394
394
|
if (t === 0) {
|
|
395
395
|
return b;
|
|
396
396
|
}
|
|
@@ -412,7 +412,7 @@ exports.Easings = {
|
|
|
412
412
|
Math.sin(((t * d - s) * (2 * Math.PI)) / p)) + b);
|
|
413
413
|
},
|
|
414
414
|
ElasticEaseOut(t, b, c, d, a, p) {
|
|
415
|
-
|
|
415
|
+
let s = 0;
|
|
416
416
|
if (t === 0) {
|
|
417
417
|
return b;
|
|
418
418
|
}
|
|
@@ -434,7 +434,7 @@ exports.Easings = {
|
|
|
434
434
|
b);
|
|
435
435
|
},
|
|
436
436
|
ElasticEaseInOut(t, b, c, d, a, p) {
|
|
437
|
-
|
|
437
|
+
let s = 0;
|
|
438
438
|
if (t === 0) {
|
|
439
439
|
return b;
|
|
440
440
|
}
|
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;
|