@nasser-sw/fabric 7.0.1-beta8 → 7.0.1-beta9
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/debug/konva-master/CHANGELOG.md +1475 -0
- package/debug/konva-master/LICENSE +22 -0
- package/debug/konva-master/README.md +209 -0
- package/debug/konva-master/gulpfile.mjs +110 -0
- package/debug/konva-master/package.json +139 -0
- package/debug/konva-master/release.sh +62 -0
- package/debug/konva-master/resources/doc-includes/ContainerParams.txt +6 -0
- package/debug/konva-master/resources/doc-includes/NodeParams.txt +20 -0
- package/debug/konva-master/resources/doc-includes/ShapeParams.txt +53 -0
- package/debug/konva-master/resources/jsdoc.conf.json +28 -0
- package/debug/konva-master/rollup.config.mjs +32 -0
- package/debug/konva-master/src/Animation.ts +237 -0
- package/debug/konva-master/src/BezierFunctions.ts +826 -0
- package/debug/konva-master/src/Canvas.ts +230 -0
- package/debug/konva-master/src/Container.ts +649 -0
- package/debug/konva-master/src/Context.ts +1017 -0
- package/debug/konva-master/src/Core.ts +5 -0
- package/debug/konva-master/src/DragAndDrop.ts +173 -0
- package/debug/konva-master/src/Factory.ts +246 -0
- package/debug/konva-master/src/FastLayer.ts +29 -0
- package/debug/konva-master/src/Global.ts +210 -0
- package/debug/konva-master/src/Group.ts +31 -0
- package/debug/konva-master/src/Layer.ts +546 -0
- package/debug/konva-master/src/Node.ts +3477 -0
- package/debug/konva-master/src/PointerEvents.ts +67 -0
- package/debug/konva-master/src/Shape.ts +2081 -0
- package/debug/konva-master/src/Stage.ts +1000 -0
- package/debug/konva-master/src/Tween.ts +811 -0
- package/debug/konva-master/src/Util.ts +1123 -0
- package/debug/konva-master/src/Validators.ts +210 -0
- package/debug/konva-master/src/_CoreInternals.ts +85 -0
- package/debug/konva-master/src/_FullInternals.ts +171 -0
- package/debug/konva-master/src/canvas-backend.ts +36 -0
- package/debug/konva-master/src/filters/Blur.ts +388 -0
- package/debug/konva-master/src/filters/Brighten.ts +48 -0
- package/debug/konva-master/src/filters/Brightness.ts +30 -0
- package/debug/konva-master/src/filters/Contrast.ts +75 -0
- package/debug/konva-master/src/filters/Emboss.ts +207 -0
- package/debug/konva-master/src/filters/Enhance.ts +154 -0
- package/debug/konva-master/src/filters/Grayscale.ts +25 -0
- package/debug/konva-master/src/filters/HSL.ts +108 -0
- package/debug/konva-master/src/filters/HSV.ts +106 -0
- package/debug/konva-master/src/filters/Invert.ts +23 -0
- package/debug/konva-master/src/filters/Kaleidoscope.ts +274 -0
- package/debug/konva-master/src/filters/Mask.ts +220 -0
- package/debug/konva-master/src/filters/Noise.ts +44 -0
- package/debug/konva-master/src/filters/Pixelate.ts +107 -0
- package/debug/konva-master/src/filters/Posterize.ts +46 -0
- package/debug/konva-master/src/filters/RGB.ts +82 -0
- package/debug/konva-master/src/filters/RGBA.ts +103 -0
- package/debug/konva-master/src/filters/Sepia.ts +27 -0
- package/debug/konva-master/src/filters/Solarize.ts +29 -0
- package/debug/konva-master/src/filters/Threshold.ts +44 -0
- package/debug/konva-master/src/index.ts +3 -0
- package/debug/konva-master/src/shapes/Arc.ts +176 -0
- package/debug/konva-master/src/shapes/Arrow.ts +231 -0
- package/debug/konva-master/src/shapes/Circle.ts +76 -0
- package/debug/konva-master/src/shapes/Ellipse.ts +121 -0
- package/debug/konva-master/src/shapes/Image.ts +319 -0
- package/debug/konva-master/src/shapes/Label.ts +386 -0
- package/debug/konva-master/src/shapes/Line.ts +364 -0
- package/debug/konva-master/src/shapes/Path.ts +1013 -0
- package/debug/konva-master/src/shapes/Rect.ts +79 -0
- package/debug/konva-master/src/shapes/RegularPolygon.ts +167 -0
- package/debug/konva-master/src/shapes/Ring.ts +94 -0
- package/debug/konva-master/src/shapes/Sprite.ts +370 -0
- package/debug/konva-master/src/shapes/Star.ts +125 -0
- package/debug/konva-master/src/shapes/Text.ts +1065 -0
- package/debug/konva-master/src/shapes/TextPath.ts +583 -0
- package/debug/konva-master/src/shapes/Transformer.ts +1889 -0
- package/debug/konva-master/src/shapes/Wedge.ts +129 -0
- package/debug/konva-master/src/skia-backend.ts +35 -0
- package/debug/konva-master/src/types.ts +84 -0
- package/debug/konva-master/tsconfig.json +31 -0
- package/debug/konva-master/tsconfig.test.json +7 -0
- package/dist/index.js +915 -23
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.min.mjs +1 -1
- package/dist/index.min.mjs.map +1 -1
- package/dist/index.mjs +915 -23
- package/dist/index.mjs.map +1 -1
- package/dist/index.node.cjs +915 -23
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.mjs +915 -23
- package/dist/index.node.mjs.map +1 -1
- package/dist/package.json.min.mjs +1 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/shapes/Text/Text.d.ts +19 -0
- package/dist/src/shapes/Text/Text.d.ts.map +1 -1
- package/dist/src/shapes/Text/Text.min.mjs +1 -1
- package/dist/src/shapes/Text/Text.min.mjs.map +1 -1
- package/dist/src/shapes/Text/Text.mjs +238 -4
- package/dist/src/shapes/Text/Text.mjs.map +1 -1
- package/dist/src/shapes/Textbox.d.ts +38 -1
- package/dist/src/shapes/Textbox.d.ts.map +1 -1
- package/dist/src/shapes/Textbox.min.mjs +1 -1
- package/dist/src/shapes/Textbox.min.mjs.map +1 -1
- package/dist/src/shapes/Textbox.mjs +497 -15
- package/dist/src/shapes/Textbox.mjs.map +1 -1
- package/dist/src/text/examples/arabicTextExample.d.ts +60 -0
- package/dist/src/text/examples/arabicTextExample.d.ts.map +1 -0
- package/dist/src/text/measure.d.ts +9 -0
- package/dist/src/text/measure.d.ts.map +1 -1
- package/dist/src/text/measure.min.mjs +1 -1
- package/dist/src/text/measure.min.mjs.map +1 -1
- package/dist/src/text/measure.mjs +175 -4
- package/dist/src/text/measure.mjs.map +1 -1
- package/dist/src/text/overlayEditor.d.ts.map +1 -1
- package/dist/src/text/overlayEditor.min.mjs +1 -1
- package/dist/src/text/overlayEditor.min.mjs.map +1 -1
- package/dist/src/text/overlayEditor.mjs +7 -0
- package/dist/src/text/overlayEditor.mjs.map +1 -1
- package/dist/src/text/scriptUtils.d.ts +142 -0
- package/dist/src/text/scriptUtils.d.ts.map +1 -0
- package/dist/src/text/scriptUtils.min.mjs +2 -0
- package/dist/src/text/scriptUtils.min.mjs.map +1 -0
- package/dist/src/text/scriptUtils.mjs +212 -0
- package/dist/src/text/scriptUtils.mjs.map +1 -0
- package/dist-extensions/src/shapes/Text/Text.d.ts +19 -0
- package/dist-extensions/src/shapes/Text/Text.d.ts.map +1 -1
- package/dist-extensions/src/shapes/Textbox.d.ts +38 -1
- package/dist-extensions/src/shapes/Textbox.d.ts.map +1 -1
- package/dist-extensions/src/text/measure.d.ts +9 -0
- package/dist-extensions/src/text/measure.d.ts.map +1 -1
- package/dist-extensions/src/text/overlayEditor.d.ts.map +1 -1
- package/dist-extensions/src/text/scriptUtils.d.ts +142 -0
- package/dist-extensions/src/text/scriptUtils.d.ts.map +1 -0
- package/fabric-test-editor.html +2401 -46
- package/fonts/STV Bold.ttf +0 -0
- package/fonts/STV Light.ttf +0 -0
- package/fonts/STV Regular.ttf +0 -0
- package/package.json +1 -1
- package/src/shapes/Text/Text.ts +238 -5
- package/src/shapes/Textbox.ts +521 -11
- package/src/text/measure.ts +200 -50
- package/src/text/overlayEditor.ts +7 -0
|
@@ -0,0 +1,811 @@
|
|
|
1
|
+
import { Util } from './Util.ts';
|
|
2
|
+
import { Animation } from './Animation.ts';
|
|
3
|
+
import type { NodeConfig } from './Node.ts';
|
|
4
|
+
import { Node } from './Node.ts';
|
|
5
|
+
import { Konva } from './Global.ts';
|
|
6
|
+
import type { Line } from './shapes/Line.ts';
|
|
7
|
+
|
|
8
|
+
const blacklist = {
|
|
9
|
+
node: 1,
|
|
10
|
+
duration: 1,
|
|
11
|
+
easing: 1,
|
|
12
|
+
onFinish: 1,
|
|
13
|
+
yoyo: 1,
|
|
14
|
+
},
|
|
15
|
+
PAUSED = 1,
|
|
16
|
+
PLAYING = 2,
|
|
17
|
+
REVERSING = 3,
|
|
18
|
+
colorAttrs = ['fill', 'stroke', 'shadowColor'];
|
|
19
|
+
let idCounter = 0;
|
|
20
|
+
|
|
21
|
+
class TweenEngine {
|
|
22
|
+
prop: string;
|
|
23
|
+
propFunc: Function;
|
|
24
|
+
begin: number;
|
|
25
|
+
_pos: number;
|
|
26
|
+
duration: number;
|
|
27
|
+
prevPos: number;
|
|
28
|
+
yoyo: boolean;
|
|
29
|
+
_time: number;
|
|
30
|
+
_position: number;
|
|
31
|
+
_startTime: number;
|
|
32
|
+
_finish: number;
|
|
33
|
+
func: Function;
|
|
34
|
+
_change: number;
|
|
35
|
+
state: number;
|
|
36
|
+
|
|
37
|
+
onPlay: Function;
|
|
38
|
+
onReverse: Function;
|
|
39
|
+
onPause: Function;
|
|
40
|
+
onReset: Function;
|
|
41
|
+
onFinish: Function;
|
|
42
|
+
onUpdate: Function;
|
|
43
|
+
|
|
44
|
+
constructor(prop, propFunc, func, begin, finish, duration, yoyo) {
|
|
45
|
+
this.prop = prop;
|
|
46
|
+
this.propFunc = propFunc;
|
|
47
|
+
this.begin = begin;
|
|
48
|
+
this._pos = begin;
|
|
49
|
+
this.duration = duration;
|
|
50
|
+
this._change = 0;
|
|
51
|
+
this.prevPos = 0;
|
|
52
|
+
this.yoyo = yoyo;
|
|
53
|
+
this._time = 0;
|
|
54
|
+
this._position = 0;
|
|
55
|
+
this._startTime = 0;
|
|
56
|
+
this._finish = 0;
|
|
57
|
+
this.func = func;
|
|
58
|
+
this._change = finish - this.begin;
|
|
59
|
+
this.pause();
|
|
60
|
+
}
|
|
61
|
+
fire(str) {
|
|
62
|
+
const handler = this[str];
|
|
63
|
+
if (handler) {
|
|
64
|
+
handler();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
setTime(t) {
|
|
68
|
+
if (t > this.duration) {
|
|
69
|
+
if (this.yoyo) {
|
|
70
|
+
this._time = this.duration;
|
|
71
|
+
this.reverse();
|
|
72
|
+
} else {
|
|
73
|
+
this.finish();
|
|
74
|
+
}
|
|
75
|
+
} else if (t < 0) {
|
|
76
|
+
if (this.yoyo) {
|
|
77
|
+
this._time = 0;
|
|
78
|
+
this.play();
|
|
79
|
+
} else {
|
|
80
|
+
this.reset();
|
|
81
|
+
}
|
|
82
|
+
} else {
|
|
83
|
+
this._time = t;
|
|
84
|
+
this.update();
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
getTime() {
|
|
88
|
+
return this._time;
|
|
89
|
+
}
|
|
90
|
+
setPosition(p) {
|
|
91
|
+
this.prevPos = this._pos;
|
|
92
|
+
this.propFunc(p);
|
|
93
|
+
this._pos = p;
|
|
94
|
+
}
|
|
95
|
+
getPosition(t) {
|
|
96
|
+
if (t === undefined) {
|
|
97
|
+
t = this._time;
|
|
98
|
+
}
|
|
99
|
+
return this.func(t, this.begin, this._change, this.duration);
|
|
100
|
+
}
|
|
101
|
+
play() {
|
|
102
|
+
this.state = PLAYING;
|
|
103
|
+
this._startTime = this.getTimer() - this._time;
|
|
104
|
+
this.onEnterFrame();
|
|
105
|
+
this.fire('onPlay');
|
|
106
|
+
}
|
|
107
|
+
reverse() {
|
|
108
|
+
this.state = REVERSING;
|
|
109
|
+
this._time = this.duration - this._time;
|
|
110
|
+
this._startTime = this.getTimer() - this._time;
|
|
111
|
+
this.onEnterFrame();
|
|
112
|
+
this.fire('onReverse');
|
|
113
|
+
}
|
|
114
|
+
seek(t) {
|
|
115
|
+
this.pause();
|
|
116
|
+
this._time = t;
|
|
117
|
+
this.update();
|
|
118
|
+
this.fire('onSeek');
|
|
119
|
+
}
|
|
120
|
+
reset() {
|
|
121
|
+
this.pause();
|
|
122
|
+
this._time = 0;
|
|
123
|
+
this.update();
|
|
124
|
+
this.fire('onReset');
|
|
125
|
+
}
|
|
126
|
+
finish() {
|
|
127
|
+
this.pause();
|
|
128
|
+
this._time = this.duration;
|
|
129
|
+
this.update();
|
|
130
|
+
this.fire('onFinish');
|
|
131
|
+
}
|
|
132
|
+
update() {
|
|
133
|
+
this.setPosition(this.getPosition(this._time));
|
|
134
|
+
this.fire('onUpdate');
|
|
135
|
+
}
|
|
136
|
+
onEnterFrame() {
|
|
137
|
+
const t = this.getTimer() - this._startTime;
|
|
138
|
+
if (this.state === PLAYING) {
|
|
139
|
+
this.setTime(t);
|
|
140
|
+
} else if (this.state === REVERSING) {
|
|
141
|
+
this.setTime(this.duration - t);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
pause() {
|
|
145
|
+
this.state = PAUSED;
|
|
146
|
+
this.fire('onPause');
|
|
147
|
+
}
|
|
148
|
+
getTimer() {
|
|
149
|
+
return new Date().getTime();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export interface TweenConfig extends NodeConfig {
|
|
154
|
+
onFinish?: Function;
|
|
155
|
+
onUpdate?: Function;
|
|
156
|
+
duration?: number;
|
|
157
|
+
node: Node;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Tween constructor. Tweens enable you to animate a node between the current state and a new state.
|
|
162
|
+
* You can play, pause, reverse, seek, reset, and finish tweens. By default, tweens are animated using
|
|
163
|
+
* a linear easing. For more tweening options, check out {@link Konva.Easings}
|
|
164
|
+
* @constructor
|
|
165
|
+
* @memberof Konva
|
|
166
|
+
* @example
|
|
167
|
+
* // instantiate new tween which fully rotates a node in 1 second
|
|
168
|
+
* var tween = new Konva.Tween({
|
|
169
|
+
* // list of tween specific properties
|
|
170
|
+
* node: node,
|
|
171
|
+
* duration: 1,
|
|
172
|
+
* easing: Konva.Easings.EaseInOut,
|
|
173
|
+
* onUpdate: () => console.log('node attrs updated')
|
|
174
|
+
* onFinish: () => console.log('finished'),
|
|
175
|
+
* // set new values for any attributes of a passed node
|
|
176
|
+
* rotation: 360,
|
|
177
|
+
* fill: 'red'
|
|
178
|
+
* });
|
|
179
|
+
*
|
|
180
|
+
* // play tween
|
|
181
|
+
* tween.play();
|
|
182
|
+
*
|
|
183
|
+
* // pause tween
|
|
184
|
+
* tween.pause();
|
|
185
|
+
*/
|
|
186
|
+
export class Tween {
|
|
187
|
+
static attrs = {};
|
|
188
|
+
static tweens = {};
|
|
189
|
+
|
|
190
|
+
node: Node;
|
|
191
|
+
anim: Animation;
|
|
192
|
+
tween: TweenEngine;
|
|
193
|
+
_id: number;
|
|
194
|
+
onFinish: Function | undefined;
|
|
195
|
+
onReset: Function | undefined;
|
|
196
|
+
onUpdate: Function | undefined;
|
|
197
|
+
|
|
198
|
+
constructor(config: TweenConfig) {
|
|
199
|
+
const that = this,
|
|
200
|
+
node = config.node as any,
|
|
201
|
+
nodeId = node._id,
|
|
202
|
+
easing = config.easing || Easings.Linear,
|
|
203
|
+
yoyo = !!config.yoyo;
|
|
204
|
+
let duration, key;
|
|
205
|
+
|
|
206
|
+
if (typeof config.duration === 'undefined') {
|
|
207
|
+
duration = 0.3;
|
|
208
|
+
} else if (config.duration === 0) {
|
|
209
|
+
// zero is bad value for duration
|
|
210
|
+
duration = 0.001;
|
|
211
|
+
} else {
|
|
212
|
+
duration = config.duration;
|
|
213
|
+
}
|
|
214
|
+
this.node = node;
|
|
215
|
+
this._id = idCounter++;
|
|
216
|
+
|
|
217
|
+
const layers =
|
|
218
|
+
node.getLayer() ||
|
|
219
|
+
(node instanceof Konva['Stage'] ? node.getLayers() : null);
|
|
220
|
+
if (!layers) {
|
|
221
|
+
Util.error(
|
|
222
|
+
'Tween constructor have `node` that is not in a layer. Please add node into layer first.'
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
this.anim = new Animation(function () {
|
|
226
|
+
that.tween.onEnterFrame();
|
|
227
|
+
}, layers);
|
|
228
|
+
|
|
229
|
+
this.tween = new TweenEngine(
|
|
230
|
+
key,
|
|
231
|
+
function (i) {
|
|
232
|
+
that._tweenFunc(i);
|
|
233
|
+
},
|
|
234
|
+
easing,
|
|
235
|
+
0,
|
|
236
|
+
1,
|
|
237
|
+
duration * 1000,
|
|
238
|
+
yoyo
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
this._addListeners();
|
|
242
|
+
|
|
243
|
+
// init attrs map
|
|
244
|
+
if (!Tween.attrs[nodeId]) {
|
|
245
|
+
Tween.attrs[nodeId] = {};
|
|
246
|
+
}
|
|
247
|
+
if (!Tween.attrs[nodeId][this._id]) {
|
|
248
|
+
Tween.attrs[nodeId][this._id] = {};
|
|
249
|
+
}
|
|
250
|
+
// init tweens map
|
|
251
|
+
if (!Tween.tweens[nodeId]) {
|
|
252
|
+
Tween.tweens[nodeId] = {};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
for (key in config) {
|
|
256
|
+
if (blacklist[key] === undefined) {
|
|
257
|
+
this._addAttr(key, config[key]);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
this.reset();
|
|
262
|
+
|
|
263
|
+
// callbacks
|
|
264
|
+
this.onFinish = config.onFinish;
|
|
265
|
+
this.onReset = config.onReset;
|
|
266
|
+
this.onUpdate = config.onUpdate;
|
|
267
|
+
}
|
|
268
|
+
_addAttr(key, end) {
|
|
269
|
+
const node = this.node,
|
|
270
|
+
nodeId = node._id;
|
|
271
|
+
let diff, len, trueEnd, trueStart, endRGBA;
|
|
272
|
+
|
|
273
|
+
// remove conflict from tween map if it exists
|
|
274
|
+
const tweenId = Tween.tweens[nodeId][key];
|
|
275
|
+
|
|
276
|
+
if (tweenId) {
|
|
277
|
+
delete Tween.attrs[nodeId][tweenId][key];
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// add to tween map
|
|
281
|
+
let start = node.getAttr(key);
|
|
282
|
+
|
|
283
|
+
if (Util._isArray(end)) {
|
|
284
|
+
diff = [];
|
|
285
|
+
len = Math.max(end.length, start.length);
|
|
286
|
+
|
|
287
|
+
if (key === 'points' && end.length !== start.length) {
|
|
288
|
+
// before tweening points we need to make sure that start.length === end.length
|
|
289
|
+
// Util._prepareArrayForTween thinking that end.length > start.length
|
|
290
|
+
if (end.length > start.length) {
|
|
291
|
+
// so in this case we will increase number of starting points
|
|
292
|
+
trueStart = start;
|
|
293
|
+
start = Util._prepareArrayForTween(
|
|
294
|
+
start,
|
|
295
|
+
end,
|
|
296
|
+
(node as Line).closed()
|
|
297
|
+
);
|
|
298
|
+
} else {
|
|
299
|
+
// in this case we will increase number of eding points
|
|
300
|
+
trueEnd = end;
|
|
301
|
+
end = Util._prepareArrayForTween(end, start, (node as Line).closed());
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (key.indexOf('fill') === 0) {
|
|
306
|
+
for (let n = 0; n < len; n++) {
|
|
307
|
+
if (n % 2 === 0) {
|
|
308
|
+
diff.push(end[n] - start[n]);
|
|
309
|
+
} else {
|
|
310
|
+
const startRGBA = Util.colorToRGBA(start[n])!;
|
|
311
|
+
endRGBA = Util.colorToRGBA(end[n]);
|
|
312
|
+
start[n] = startRGBA;
|
|
313
|
+
diff.push({
|
|
314
|
+
r: endRGBA.r - startRGBA.r,
|
|
315
|
+
g: endRGBA.g - startRGBA.g,
|
|
316
|
+
b: endRGBA.b - startRGBA.b,
|
|
317
|
+
a: endRGBA.a - startRGBA.a,
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
} else {
|
|
322
|
+
for (let n = 0; n < len; n++) {
|
|
323
|
+
diff.push(end[n] - start[n]);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
} else if (colorAttrs.indexOf(key) !== -1) {
|
|
327
|
+
start = Util.colorToRGBA(start);
|
|
328
|
+
endRGBA = Util.colorToRGBA(end);
|
|
329
|
+
diff = {
|
|
330
|
+
r: endRGBA.r - start.r,
|
|
331
|
+
g: endRGBA.g - start.g,
|
|
332
|
+
b: endRGBA.b - start.b,
|
|
333
|
+
a: endRGBA.a - start.a,
|
|
334
|
+
};
|
|
335
|
+
} else {
|
|
336
|
+
diff = end - start;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
Tween.attrs[nodeId][this._id][key] = {
|
|
340
|
+
start: start,
|
|
341
|
+
diff: diff,
|
|
342
|
+
end: end,
|
|
343
|
+
trueEnd: trueEnd,
|
|
344
|
+
trueStart: trueStart,
|
|
345
|
+
};
|
|
346
|
+
Tween.tweens[nodeId][key] = this._id;
|
|
347
|
+
}
|
|
348
|
+
_tweenFunc(i) {
|
|
349
|
+
const node = this.node,
|
|
350
|
+
attrs = Tween.attrs[node._id][this._id];
|
|
351
|
+
let key, attr, start, diff, newVal, n, len, end;
|
|
352
|
+
|
|
353
|
+
for (key in attrs) {
|
|
354
|
+
attr = attrs[key];
|
|
355
|
+
start = attr.start;
|
|
356
|
+
diff = attr.diff;
|
|
357
|
+
end = attr.end;
|
|
358
|
+
|
|
359
|
+
if (Util._isArray(start)) {
|
|
360
|
+
newVal = [];
|
|
361
|
+
len = Math.max(start.length, end.length);
|
|
362
|
+
if (key.indexOf('fill') === 0) {
|
|
363
|
+
for (n = 0; n < len; n++) {
|
|
364
|
+
if (n % 2 === 0) {
|
|
365
|
+
newVal.push((start[n] || 0) + diff[n] * i);
|
|
366
|
+
} else {
|
|
367
|
+
newVal.push(
|
|
368
|
+
'rgba(' +
|
|
369
|
+
Math.round(start[n].r + diff[n].r * i) +
|
|
370
|
+
',' +
|
|
371
|
+
Math.round(start[n].g + diff[n].g * i) +
|
|
372
|
+
',' +
|
|
373
|
+
Math.round(start[n].b + diff[n].b * i) +
|
|
374
|
+
',' +
|
|
375
|
+
(start[n].a + diff[n].a * i) +
|
|
376
|
+
')'
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
} else {
|
|
381
|
+
for (n = 0; n < len; n++) {
|
|
382
|
+
newVal.push((start[n] || 0) + diff[n] * i);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
} else if (colorAttrs.indexOf(key) !== -1) {
|
|
386
|
+
newVal =
|
|
387
|
+
'rgba(' +
|
|
388
|
+
Math.round(start.r + diff.r * i) +
|
|
389
|
+
',' +
|
|
390
|
+
Math.round(start.g + diff.g * i) +
|
|
391
|
+
',' +
|
|
392
|
+
Math.round(start.b + diff.b * i) +
|
|
393
|
+
',' +
|
|
394
|
+
(start.a + diff.a * i) +
|
|
395
|
+
')';
|
|
396
|
+
} else {
|
|
397
|
+
newVal = start + diff * i;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
node.setAttr(key, newVal);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
_addListeners() {
|
|
404
|
+
// start listeners
|
|
405
|
+
this.tween.onPlay = () => {
|
|
406
|
+
this.anim.start();
|
|
407
|
+
};
|
|
408
|
+
this.tween.onReverse = () => {
|
|
409
|
+
this.anim.start();
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// stop listeners
|
|
413
|
+
this.tween.onPause = () => {
|
|
414
|
+
this.anim.stop();
|
|
415
|
+
};
|
|
416
|
+
this.tween.onFinish = () => {
|
|
417
|
+
const node = this.node as Node;
|
|
418
|
+
|
|
419
|
+
// after tweening points of line we need to set original end
|
|
420
|
+
const attrs = Tween.attrs[node._id][this._id];
|
|
421
|
+
if (attrs.points && attrs.points.trueEnd) {
|
|
422
|
+
node.setAttr('points', attrs.points.trueEnd);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
if (this.onFinish) {
|
|
426
|
+
this.onFinish.call(this);
|
|
427
|
+
}
|
|
428
|
+
};
|
|
429
|
+
this.tween.onReset = () => {
|
|
430
|
+
const node = this.node as any;
|
|
431
|
+
// after tweening points of line we need to set original start
|
|
432
|
+
const attrs = Tween.attrs[node._id][this._id];
|
|
433
|
+
if (attrs.points && attrs.points.trueStart) {
|
|
434
|
+
node.points(attrs.points.trueStart);
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
if (this.onReset) {
|
|
438
|
+
this.onReset();
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
this.tween.onUpdate = () => {
|
|
442
|
+
if (this.onUpdate) {
|
|
443
|
+
this.onUpdate.call(this);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* play
|
|
449
|
+
* @method
|
|
450
|
+
* @name Konva.Tween#play
|
|
451
|
+
* @returns {Tween}
|
|
452
|
+
*/
|
|
453
|
+
play() {
|
|
454
|
+
this.tween.play();
|
|
455
|
+
return this;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* reverse
|
|
459
|
+
* @method
|
|
460
|
+
* @name Konva.Tween#reverse
|
|
461
|
+
* @returns {Tween}
|
|
462
|
+
*/
|
|
463
|
+
reverse() {
|
|
464
|
+
this.tween.reverse();
|
|
465
|
+
return this;
|
|
466
|
+
}
|
|
467
|
+
/**
|
|
468
|
+
* reset
|
|
469
|
+
* @method
|
|
470
|
+
* @name Konva.Tween#reset
|
|
471
|
+
* @returns {Tween}
|
|
472
|
+
*/
|
|
473
|
+
reset() {
|
|
474
|
+
this.tween.reset();
|
|
475
|
+
return this;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* seek
|
|
479
|
+
* @method
|
|
480
|
+
* @name Konva.Tween#seek(
|
|
481
|
+
* @param {Integer} t time in seconds between 0 and the duration
|
|
482
|
+
* @returns {Tween}
|
|
483
|
+
*/
|
|
484
|
+
seek(t) {
|
|
485
|
+
this.tween.seek(t * 1000);
|
|
486
|
+
return this;
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* pause
|
|
490
|
+
* @method
|
|
491
|
+
* @name Konva.Tween#pause
|
|
492
|
+
* @returns {Tween}
|
|
493
|
+
*/
|
|
494
|
+
pause() {
|
|
495
|
+
this.tween.pause();
|
|
496
|
+
return this;
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* finish
|
|
500
|
+
* @method
|
|
501
|
+
* @name Konva.Tween#finish
|
|
502
|
+
* @returns {Tween}
|
|
503
|
+
*/
|
|
504
|
+
finish() {
|
|
505
|
+
this.tween.finish();
|
|
506
|
+
return this;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* destroy
|
|
510
|
+
* @method
|
|
511
|
+
* @name Konva.Tween#destroy
|
|
512
|
+
*/
|
|
513
|
+
destroy() {
|
|
514
|
+
const nodeId = this.node._id,
|
|
515
|
+
thisId = this._id,
|
|
516
|
+
attrs = Tween.tweens[nodeId];
|
|
517
|
+
|
|
518
|
+
this.pause();
|
|
519
|
+
|
|
520
|
+
// Clean up animation
|
|
521
|
+
if (this.anim) {
|
|
522
|
+
this.anim.stop();
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
// Clean up tween entries
|
|
526
|
+
for (const key in attrs) {
|
|
527
|
+
delete Tween.tweens[nodeId][key];
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// Clean up attrs entry
|
|
531
|
+
delete Tween.attrs[nodeId][thisId];
|
|
532
|
+
|
|
533
|
+
// Clean up parent objects if empty
|
|
534
|
+
if (Tween.tweens[nodeId]) {
|
|
535
|
+
if (Object.keys(Tween.tweens[nodeId]).length === 0) {
|
|
536
|
+
delete Tween.tweens[nodeId];
|
|
537
|
+
}
|
|
538
|
+
if (Object.keys(Tween.attrs[nodeId]).length === 0) {
|
|
539
|
+
delete Tween.attrs[nodeId];
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* Tween node properties. Shorter usage of {@link Konva.Tween} object.
|
|
547
|
+
*
|
|
548
|
+
* @method Konva.Node#to
|
|
549
|
+
* @param {Object} [params] tween params
|
|
550
|
+
* @example
|
|
551
|
+
*
|
|
552
|
+
* circle.to({
|
|
553
|
+
* x : 50,
|
|
554
|
+
* duration : 0.5,
|
|
555
|
+
* onUpdate: () => console.log('props updated'),
|
|
556
|
+
* onFinish: () => console.log('finished'),
|
|
557
|
+
* });
|
|
558
|
+
*/
|
|
559
|
+
Node.prototype.to = function (params) {
|
|
560
|
+
const onFinish = params.onFinish;
|
|
561
|
+
params.node = this;
|
|
562
|
+
params.onFinish = function () {
|
|
563
|
+
this.destroy();
|
|
564
|
+
if (onFinish) {
|
|
565
|
+
onFinish();
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
const tween = new Tween(params as any);
|
|
569
|
+
tween.play();
|
|
570
|
+
};
|
|
571
|
+
|
|
572
|
+
/*
|
|
573
|
+
* These eases were ported from an Adobe Flash tweening library to JavaScript
|
|
574
|
+
* by Xaric
|
|
575
|
+
*/
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* @namespace Easings
|
|
579
|
+
* @memberof Konva
|
|
580
|
+
*/
|
|
581
|
+
export const Easings = {
|
|
582
|
+
/**
|
|
583
|
+
* back ease in
|
|
584
|
+
* @function
|
|
585
|
+
* @memberof Konva.Easings
|
|
586
|
+
*/
|
|
587
|
+
BackEaseIn(t, b, c, d) {
|
|
588
|
+
const s = 1.70158;
|
|
589
|
+
return c * (t /= d) * t * ((s + 1) * t - s) + b;
|
|
590
|
+
},
|
|
591
|
+
/**
|
|
592
|
+
* back ease out
|
|
593
|
+
* @function
|
|
594
|
+
* @memberof Konva.Easings
|
|
595
|
+
*/
|
|
596
|
+
BackEaseOut(t, b, c, d) {
|
|
597
|
+
const s = 1.70158;
|
|
598
|
+
return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
|
|
599
|
+
},
|
|
600
|
+
/**
|
|
601
|
+
* back ease in out
|
|
602
|
+
* @function
|
|
603
|
+
* @memberof Konva.Easings
|
|
604
|
+
*/
|
|
605
|
+
BackEaseInOut(t, b, c, d) {
|
|
606
|
+
let s = 1.70158;
|
|
607
|
+
if ((t /= d / 2) < 1) {
|
|
608
|
+
return (c / 2) * (t * t * (((s *= 1.525) + 1) * t - s)) + b;
|
|
609
|
+
}
|
|
610
|
+
return (c / 2) * ((t -= 2) * t * (((s *= 1.525) + 1) * t + s) + 2) + b;
|
|
611
|
+
},
|
|
612
|
+
/**
|
|
613
|
+
* elastic ease in
|
|
614
|
+
* @function
|
|
615
|
+
* @memberof Konva.Easings
|
|
616
|
+
*/
|
|
617
|
+
ElasticEaseIn(t, b, c, d, a, p) {
|
|
618
|
+
// added s = 0
|
|
619
|
+
let s = 0;
|
|
620
|
+
if (t === 0) {
|
|
621
|
+
return b;
|
|
622
|
+
}
|
|
623
|
+
if ((t /= d) === 1) {
|
|
624
|
+
return b + c;
|
|
625
|
+
}
|
|
626
|
+
if (!p) {
|
|
627
|
+
p = d * 0.3;
|
|
628
|
+
}
|
|
629
|
+
if (!a || a < Math.abs(c)) {
|
|
630
|
+
a = c;
|
|
631
|
+
s = p / 4;
|
|
632
|
+
} else {
|
|
633
|
+
s = (p / (2 * Math.PI)) * Math.asin(c / a);
|
|
634
|
+
}
|
|
635
|
+
return (
|
|
636
|
+
-(
|
|
637
|
+
a *
|
|
638
|
+
Math.pow(2, 10 * (t -= 1)) *
|
|
639
|
+
Math.sin(((t * d - s) * (2 * Math.PI)) / p)
|
|
640
|
+
) + b
|
|
641
|
+
);
|
|
642
|
+
},
|
|
643
|
+
/**
|
|
644
|
+
* elastic ease out
|
|
645
|
+
* @function
|
|
646
|
+
* @memberof Konva.Easings
|
|
647
|
+
*/
|
|
648
|
+
ElasticEaseOut(t, b, c, d, a, p) {
|
|
649
|
+
// added s = 0
|
|
650
|
+
let s = 0;
|
|
651
|
+
if (t === 0) {
|
|
652
|
+
return b;
|
|
653
|
+
}
|
|
654
|
+
if ((t /= d) === 1) {
|
|
655
|
+
return b + c;
|
|
656
|
+
}
|
|
657
|
+
if (!p) {
|
|
658
|
+
p = d * 0.3;
|
|
659
|
+
}
|
|
660
|
+
if (!a || a < Math.abs(c)) {
|
|
661
|
+
a = c;
|
|
662
|
+
s = p / 4;
|
|
663
|
+
} else {
|
|
664
|
+
s = (p / (2 * Math.PI)) * Math.asin(c / a);
|
|
665
|
+
}
|
|
666
|
+
return (
|
|
667
|
+
a * Math.pow(2, -10 * t) * Math.sin(((t * d - s) * (2 * Math.PI)) / p) +
|
|
668
|
+
c +
|
|
669
|
+
b
|
|
670
|
+
);
|
|
671
|
+
},
|
|
672
|
+
/**
|
|
673
|
+
* elastic ease in out
|
|
674
|
+
* @function
|
|
675
|
+
* @memberof Konva.Easings
|
|
676
|
+
*/
|
|
677
|
+
ElasticEaseInOut(t, b, c, d, a, p) {
|
|
678
|
+
// added s = 0
|
|
679
|
+
let s = 0;
|
|
680
|
+
if (t === 0) {
|
|
681
|
+
return b;
|
|
682
|
+
}
|
|
683
|
+
if ((t /= d / 2) === 2) {
|
|
684
|
+
return b + c;
|
|
685
|
+
}
|
|
686
|
+
if (!p) {
|
|
687
|
+
p = d * (0.3 * 1.5);
|
|
688
|
+
}
|
|
689
|
+
if (!a || a < Math.abs(c)) {
|
|
690
|
+
a = c;
|
|
691
|
+
s = p / 4;
|
|
692
|
+
} else {
|
|
693
|
+
s = (p / (2 * Math.PI)) * Math.asin(c / a);
|
|
694
|
+
}
|
|
695
|
+
if (t < 1) {
|
|
696
|
+
return (
|
|
697
|
+
-0.5 *
|
|
698
|
+
(a *
|
|
699
|
+
Math.pow(2, 10 * (t -= 1)) *
|
|
700
|
+
Math.sin(((t * d - s) * (2 * Math.PI)) / p)) +
|
|
701
|
+
b
|
|
702
|
+
);
|
|
703
|
+
}
|
|
704
|
+
return (
|
|
705
|
+
a *
|
|
706
|
+
Math.pow(2, -10 * (t -= 1)) *
|
|
707
|
+
Math.sin(((t * d - s) * (2 * Math.PI)) / p) *
|
|
708
|
+
0.5 +
|
|
709
|
+
c +
|
|
710
|
+
b
|
|
711
|
+
);
|
|
712
|
+
},
|
|
713
|
+
/**
|
|
714
|
+
* bounce ease out
|
|
715
|
+
* @function
|
|
716
|
+
* @memberof Konva.Easings
|
|
717
|
+
*/
|
|
718
|
+
BounceEaseOut(t, b, c, d) {
|
|
719
|
+
if ((t /= d) < 1 / 2.75) {
|
|
720
|
+
return c * (7.5625 * t * t) + b;
|
|
721
|
+
} else if (t < 2 / 2.75) {
|
|
722
|
+
return c * (7.5625 * (t -= 1.5 / 2.75) * t + 0.75) + b;
|
|
723
|
+
} else if (t < 2.5 / 2.75) {
|
|
724
|
+
return c * (7.5625 * (t -= 2.25 / 2.75) * t + 0.9375) + b;
|
|
725
|
+
} else {
|
|
726
|
+
return c * (7.5625 * (t -= 2.625 / 2.75) * t + 0.984375) + b;
|
|
727
|
+
}
|
|
728
|
+
},
|
|
729
|
+
/**
|
|
730
|
+
* bounce ease in
|
|
731
|
+
* @function
|
|
732
|
+
* @memberof Konva.Easings
|
|
733
|
+
*/
|
|
734
|
+
BounceEaseIn(t, b, c, d) {
|
|
735
|
+
return c - Easings.BounceEaseOut(d - t, 0, c, d) + b;
|
|
736
|
+
},
|
|
737
|
+
/**
|
|
738
|
+
* bounce ease in out
|
|
739
|
+
* @function
|
|
740
|
+
* @memberof Konva.Easings
|
|
741
|
+
*/
|
|
742
|
+
BounceEaseInOut(t, b, c, d) {
|
|
743
|
+
if (t < d / 2) {
|
|
744
|
+
return Easings.BounceEaseIn(t * 2, 0, c, d) * 0.5 + b;
|
|
745
|
+
} else {
|
|
746
|
+
return Easings.BounceEaseOut(t * 2 - d, 0, c, d) * 0.5 + c * 0.5 + b;
|
|
747
|
+
}
|
|
748
|
+
},
|
|
749
|
+
/**
|
|
750
|
+
* ease in
|
|
751
|
+
* @function
|
|
752
|
+
* @memberof Konva.Easings
|
|
753
|
+
*/
|
|
754
|
+
EaseIn(t, b, c, d) {
|
|
755
|
+
return c * (t /= d) * t + b;
|
|
756
|
+
},
|
|
757
|
+
/**
|
|
758
|
+
* ease out
|
|
759
|
+
* @function
|
|
760
|
+
* @memberof Konva.Easings
|
|
761
|
+
*/
|
|
762
|
+
EaseOut(t, b, c, d) {
|
|
763
|
+
return -c * (t /= d) * (t - 2) + b;
|
|
764
|
+
},
|
|
765
|
+
/**
|
|
766
|
+
* ease in out
|
|
767
|
+
* @function
|
|
768
|
+
* @memberof Konva.Easings
|
|
769
|
+
*/
|
|
770
|
+
EaseInOut(t, b, c, d) {
|
|
771
|
+
if ((t /= d / 2) < 1) {
|
|
772
|
+
return (c / 2) * t * t + b;
|
|
773
|
+
}
|
|
774
|
+
return (-c / 2) * (--t * (t - 2) - 1) + b;
|
|
775
|
+
},
|
|
776
|
+
/**
|
|
777
|
+
* strong ease in
|
|
778
|
+
* @function
|
|
779
|
+
* @memberof Konva.Easings
|
|
780
|
+
*/
|
|
781
|
+
StrongEaseIn(t, b, c, d) {
|
|
782
|
+
return c * (t /= d) * t * t * t * t + b;
|
|
783
|
+
},
|
|
784
|
+
/**
|
|
785
|
+
* strong ease out
|
|
786
|
+
* @function
|
|
787
|
+
* @memberof Konva.Easings
|
|
788
|
+
*/
|
|
789
|
+
StrongEaseOut(t, b, c, d) {
|
|
790
|
+
return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
|
|
791
|
+
},
|
|
792
|
+
/**
|
|
793
|
+
* strong ease in out
|
|
794
|
+
* @function
|
|
795
|
+
* @memberof Konva.Easings
|
|
796
|
+
*/
|
|
797
|
+
StrongEaseInOut(t, b, c, d) {
|
|
798
|
+
if ((t /= d / 2) < 1) {
|
|
799
|
+
return (c / 2) * t * t * t * t * t + b;
|
|
800
|
+
}
|
|
801
|
+
return (c / 2) * ((t -= 2) * t * t * t * t + 2) + b;
|
|
802
|
+
},
|
|
803
|
+
/**
|
|
804
|
+
* linear
|
|
805
|
+
* @function
|
|
806
|
+
* @memberof Konva.Easings
|
|
807
|
+
*/
|
|
808
|
+
Linear(t, b, c, d) {
|
|
809
|
+
return (c * t) / d + b;
|
|
810
|
+
},
|
|
811
|
+
};
|