1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
6 |
|
7 | var _objectWithoutPropertiesLoose = _interopDefault(require('@babel/runtime/helpers/esm/objectWithoutPropertiesLoose'));
|
8 | var _extends = _interopDefault(require('@babel/runtime/helpers/esm/extends'));
|
9 | var React = require('react');
|
10 | var React__default = _interopDefault(React);
|
11 | var ReactDOM = _interopDefault(require('react-dom'));
|
12 |
|
13 | let bugfixes = undefined;
|
14 | let applyAnimatedValues = undefined;
|
15 | let colorNames = [];
|
16 | let requestFrame = cb => typeof window !== 'undefined' && window.requestAnimationFrame(cb);
|
17 | let cancelFrame = cb => typeof window !== 'undefined' && window.cancelAnimationFrame(cb);
|
18 | let interpolation = undefined;
|
19 | let now = () => Date.now();
|
20 | let defaultElement = undefined;
|
21 | let createAnimatedStyle = undefined;
|
22 | const injectApplyAnimatedValues = (fn, transform) => applyAnimatedValues = {
|
23 | fn,
|
24 | transform
|
25 | };
|
26 | const injectColorNames = names => colorNames = names;
|
27 | const injectBugfixes = fn => bugfixes = fn;
|
28 | const injectInterpolation = cls => interpolation = cls;
|
29 | const injectFrame = (raf, caf) => {
|
30 | var _ref = [raf, caf];
|
31 | requestFrame = _ref[0];
|
32 | cancelFrame = _ref[1];
|
33 | return _ref;
|
34 | };
|
35 | const injectNow = nowFn => now = nowFn;
|
36 | const injectDefaultElement = el => defaultElement = el;
|
37 | const injectCreateAnimatedStyle = factory => createAnimatedStyle = factory;
|
38 |
|
39 | var Globals = Object.freeze({
|
40 | get bugfixes () { return bugfixes; },
|
41 | get applyAnimatedValues () { return applyAnimatedValues; },
|
42 | get colorNames () { return colorNames; },
|
43 | get requestFrame () { return requestFrame; },
|
44 | get cancelFrame () { return cancelFrame; },
|
45 | get interpolation () { return interpolation; },
|
46 | get now () { return now; },
|
47 | get defaultElement () { return defaultElement; },
|
48 | get createAnimatedStyle () { return createAnimatedStyle; },
|
49 | injectApplyAnimatedValues: injectApplyAnimatedValues,
|
50 | injectColorNames: injectColorNames,
|
51 | injectBugfixes: injectBugfixes,
|
52 | injectInterpolation: injectInterpolation,
|
53 | injectFrame: injectFrame,
|
54 | injectNow: injectNow,
|
55 | injectDefaultElement: injectDefaultElement,
|
56 | injectCreateAnimatedStyle: injectCreateAnimatedStyle
|
57 | });
|
58 |
|
59 | class Animated {
|
60 | attach() {}
|
61 |
|
62 | detach() {}
|
63 |
|
64 | getValue() {}
|
65 |
|
66 | getAnimatedValue() {
|
67 | return this.getValue();
|
68 | }
|
69 |
|
70 | addChild(child) {}
|
71 |
|
72 | removeChild(child) {}
|
73 |
|
74 | getChildren() {
|
75 | return [];
|
76 | }
|
77 |
|
78 | }
|
79 |
|
80 | const getValues = object => Object.keys(object).map(k => object[k]);
|
81 |
|
82 | class AnimatedWithChildren extends Animated {
|
83 | constructor() {
|
84 | var _this;
|
85 |
|
86 | super(...arguments);
|
87 | _this = this;
|
88 | this.children = [];
|
89 |
|
90 | this.getChildren = () => this.children;
|
91 |
|
92 | this.getPayload = function (index) {
|
93 | if (index === void 0) {
|
94 | index = undefined;
|
95 | }
|
96 |
|
97 | return index !== void 0 && _this.payload ? _this.payload[index] : _this.payload || _this;
|
98 | };
|
99 | }
|
100 |
|
101 | addChild(child) {
|
102 | if (this.children.length === 0) this.attach();
|
103 | this.children.push(child);
|
104 | }
|
105 |
|
106 | removeChild(child) {
|
107 | const index = this.children.indexOf(child);
|
108 | this.children.splice(index, 1);
|
109 | if (this.children.length === 0) this.detach();
|
110 | }
|
111 |
|
112 | }
|
113 | class AnimatedArrayWithChildren extends AnimatedWithChildren {
|
114 | constructor() {
|
115 | super(...arguments);
|
116 | this.payload = [];
|
117 |
|
118 | this.getAnimatedValue = () => this.getValue();
|
119 |
|
120 | this.attach = () => this.payload.forEach(p => p instanceof Animated && p.addChild(this));
|
121 |
|
122 | this.detach = () => this.payload.forEach(p => p instanceof Animated && p.removeChild(this));
|
123 | }
|
124 |
|
125 | }
|
126 | class AnimatedObjectWithChildren extends AnimatedWithChildren {
|
127 | constructor() {
|
128 | super(...arguments);
|
129 | this.payload = {};
|
130 |
|
131 | this.getAnimatedValue = () => this.getValue(true);
|
132 |
|
133 | this.attach = () => getValues(this.payload).forEach(s => s instanceof Animated && s.addChild(this));
|
134 |
|
135 | this.detach = () => getValues(this.payload).forEach(s => s instanceof Animated && s.removeChild(this));
|
136 | }
|
137 |
|
138 | getValue(animated) {
|
139 | if (animated === void 0) {
|
140 | animated = false;
|
141 | }
|
142 |
|
143 | const payload = {};
|
144 |
|
145 | for (const key in this.payload) {
|
146 | const value = this.payload[key];
|
147 | if (animated && !(value instanceof Animated)) continue;
|
148 | payload[key] = value instanceof Animated ? value[animated ? 'getAnimatedValue' : 'getValue']() : value;
|
149 | }
|
150 |
|
151 | return payload;
|
152 | }
|
153 |
|
154 | }
|
155 |
|
156 | class AnimatedStyle extends AnimatedObjectWithChildren {
|
157 | constructor(style) {
|
158 | super();
|
159 | style = style || {};
|
160 | if (style.transform && !(style.transform instanceof Animated)) style = applyAnimatedValues.transform(style);
|
161 | this.payload = style;
|
162 | }
|
163 |
|
164 | }
|
165 |
|
166 |
|
167 | const colors = {
|
168 | transparent: 0x00000000,
|
169 | aliceblue: 0xf0f8ffff,
|
170 | antiquewhite: 0xfaebd7ff,
|
171 | aqua: 0x00ffffff,
|
172 | aquamarine: 0x7fffd4ff,
|
173 | azure: 0xf0ffffff,
|
174 | beige: 0xf5f5dcff,
|
175 | bisque: 0xffe4c4ff,
|
176 | black: 0x000000ff,
|
177 | blanchedalmond: 0xffebcdff,
|
178 | blue: 0x0000ffff,
|
179 | blueviolet: 0x8a2be2ff,
|
180 | brown: 0xa52a2aff,
|
181 | burlywood: 0xdeb887ff,
|
182 | burntsienna: 0xea7e5dff,
|
183 | cadetblue: 0x5f9ea0ff,
|
184 | chartreuse: 0x7fff00ff,
|
185 | chocolate: 0xd2691eff,
|
186 | coral: 0xff7f50ff,
|
187 | cornflowerblue: 0x6495edff,
|
188 | cornsilk: 0xfff8dcff,
|
189 | crimson: 0xdc143cff,
|
190 | cyan: 0x00ffffff,
|
191 | darkblue: 0x00008bff,
|
192 | darkcyan: 0x008b8bff,
|
193 | darkgoldenrod: 0xb8860bff,
|
194 | darkgray: 0xa9a9a9ff,
|
195 | darkgreen: 0x006400ff,
|
196 | darkgrey: 0xa9a9a9ff,
|
197 | darkkhaki: 0xbdb76bff,
|
198 | darkmagenta: 0x8b008bff,
|
199 | darkolivegreen: 0x556b2fff,
|
200 | darkorange: 0xff8c00ff,
|
201 | darkorchid: 0x9932ccff,
|
202 | darkred: 0x8b0000ff,
|
203 | darksalmon: 0xe9967aff,
|
204 | darkseagreen: 0x8fbc8fff,
|
205 | darkslateblue: 0x483d8bff,
|
206 | darkslategray: 0x2f4f4fff,
|
207 | darkslategrey: 0x2f4f4fff,
|
208 | darkturquoise: 0x00ced1ff,
|
209 | darkviolet: 0x9400d3ff,
|
210 | deeppink: 0xff1493ff,
|
211 | deepskyblue: 0x00bfffff,
|
212 | dimgray: 0x696969ff,
|
213 | dimgrey: 0x696969ff,
|
214 | dodgerblue: 0x1e90ffff,
|
215 | firebrick: 0xb22222ff,
|
216 | floralwhite: 0xfffaf0ff,
|
217 | forestgreen: 0x228b22ff,
|
218 | fuchsia: 0xff00ffff,
|
219 | gainsboro: 0xdcdcdcff,
|
220 | ghostwhite: 0xf8f8ffff,
|
221 | gold: 0xffd700ff,
|
222 | goldenrod: 0xdaa520ff,
|
223 | gray: 0x808080ff,
|
224 | green: 0x008000ff,
|
225 | greenyellow: 0xadff2fff,
|
226 | grey: 0x808080ff,
|
227 | honeydew: 0xf0fff0ff,
|
228 | hotpink: 0xff69b4ff,
|
229 | indianred: 0xcd5c5cff,
|
230 | indigo: 0x4b0082ff,
|
231 | ivory: 0xfffff0ff,
|
232 | khaki: 0xf0e68cff,
|
233 | lavender: 0xe6e6faff,
|
234 | lavenderblush: 0xfff0f5ff,
|
235 | lawngreen: 0x7cfc00ff,
|
236 | lemonchiffon: 0xfffacdff,
|
237 | lightblue: 0xadd8e6ff,
|
238 | lightcoral: 0xf08080ff,
|
239 | lightcyan: 0xe0ffffff,
|
240 | lightgoldenrodyellow: 0xfafad2ff,
|
241 | lightgray: 0xd3d3d3ff,
|
242 | lightgreen: 0x90ee90ff,
|
243 | lightgrey: 0xd3d3d3ff,
|
244 | lightpink: 0xffb6c1ff,
|
245 | lightsalmon: 0xffa07aff,
|
246 | lightseagreen: 0x20b2aaff,
|
247 | lightskyblue: 0x87cefaff,
|
248 | lightslategray: 0x778899ff,
|
249 | lightslategrey: 0x778899ff,
|
250 | lightsteelblue: 0xb0c4deff,
|
251 | lightyellow: 0xffffe0ff,
|
252 | lime: 0x00ff00ff,
|
253 | limegreen: 0x32cd32ff,
|
254 | linen: 0xfaf0e6ff,
|
255 | magenta: 0xff00ffff,
|
256 | maroon: 0x800000ff,
|
257 | mediumaquamarine: 0x66cdaaff,
|
258 | mediumblue: 0x0000cdff,
|
259 | mediumorchid: 0xba55d3ff,
|
260 | mediumpurple: 0x9370dbff,
|
261 | mediumseagreen: 0x3cb371ff,
|
262 | mediumslateblue: 0x7b68eeff,
|
263 | mediumspringgreen: 0x00fa9aff,
|
264 | mediumturquoise: 0x48d1ccff,
|
265 | mediumvioletred: 0xc71585ff,
|
266 | midnightblue: 0x191970ff,
|
267 | mintcream: 0xf5fffaff,
|
268 | mistyrose: 0xffe4e1ff,
|
269 | moccasin: 0xffe4b5ff,
|
270 | navajowhite: 0xffdeadff,
|
271 | navy: 0x000080ff,
|
272 | oldlace: 0xfdf5e6ff,
|
273 | olive: 0x808000ff,
|
274 | olivedrab: 0x6b8e23ff,
|
275 | orange: 0xffa500ff,
|
276 | orangered: 0xff4500ff,
|
277 | orchid: 0xda70d6ff,
|
278 | palegoldenrod: 0xeee8aaff,
|
279 | palegreen: 0x98fb98ff,
|
280 | paleturquoise: 0xafeeeeff,
|
281 | palevioletred: 0xdb7093ff,
|
282 | papayawhip: 0xffefd5ff,
|
283 | peachpuff: 0xffdab9ff,
|
284 | peru: 0xcd853fff,
|
285 | pink: 0xffc0cbff,
|
286 | plum: 0xdda0ddff,
|
287 | powderblue: 0xb0e0e6ff,
|
288 | purple: 0x800080ff,
|
289 | rebeccapurple: 0x663399ff,
|
290 | red: 0xff0000ff,
|
291 | rosybrown: 0xbc8f8fff,
|
292 | royalblue: 0x4169e1ff,
|
293 | saddlebrown: 0x8b4513ff,
|
294 | salmon: 0xfa8072ff,
|
295 | sandybrown: 0xf4a460ff,
|
296 | seagreen: 0x2e8b57ff,
|
297 | seashell: 0xfff5eeff,
|
298 | sienna: 0xa0522dff,
|
299 | silver: 0xc0c0c0ff,
|
300 | skyblue: 0x87ceebff,
|
301 | slateblue: 0x6a5acdff,
|
302 | slategray: 0x708090ff,
|
303 | slategrey: 0x708090ff,
|
304 | snow: 0xfffafaff,
|
305 | springgreen: 0x00ff7fff,
|
306 | steelblue: 0x4682b4ff,
|
307 | tan: 0xd2b48cff,
|
308 | teal: 0x008080ff,
|
309 | thistle: 0xd8bfd8ff,
|
310 | tomato: 0xff6347ff,
|
311 | turquoise: 0x40e0d0ff,
|
312 | violet: 0xee82eeff,
|
313 | wheat: 0xf5deb3ff,
|
314 | white: 0xffffffff,
|
315 | whitesmoke: 0xf5f5f5ff,
|
316 | yellow: 0xffff00ff,
|
317 | yellowgreen: 0x9acd32ff
|
318 | };
|
319 |
|
320 | class Interpolation {
|
321 |
|
322 |
|
323 | static create(config, output, extra) {
|
324 | if (typeof config === 'function') return config;else if (interpolation && config.output && typeof config.output[0] === 'string') return interpolation(config);else if (Array.isArray(config)) return Interpolation.create({
|
325 | range: config,
|
326 | output,
|
327 | extrapolate: extra || 'extend'
|
328 | });
|
329 | let outputRange = config.output;
|
330 | let inputRange = config.range || [0, 1];
|
331 |
|
332 | let easing = config.easing || (t => t);
|
333 |
|
334 | let extrapolateLeft = 'extend';
|
335 | let map = config.map;
|
336 | if (config.extrapolateLeft !== undefined) extrapolateLeft = config.extrapolateLeft;else if (config.extrapolate !== undefined) extrapolateLeft = config.extrapolate;
|
337 | let extrapolateRight = 'extend';
|
338 | if (config.extrapolateRight !== undefined) extrapolateRight = config.extrapolateRight;else if (config.extrapolate !== undefined) extrapolateRight = config.extrapolate;
|
339 | return input => {
|
340 | let range = findRange(input, inputRange);
|
341 | return interpolate(input, inputRange[range], inputRange[range + 1], outputRange[range], outputRange[range + 1], easing, extrapolateLeft, extrapolateRight, map);
|
342 | };
|
343 | }
|
344 |
|
345 | }
|
346 |
|
347 | function interpolate(input, inputMin, inputMax, outputMin, outputMax, easing, extrapolateLeft, extrapolateRight, map) {
|
348 | let result = map ? map(input) : input;
|
349 |
|
350 | if (result < inputMin) {
|
351 | if (extrapolateLeft === 'identity') return result;else if (extrapolateLeft === 'clamp') result = inputMin;
|
352 | }
|
353 |
|
354 | if (result > inputMax) {
|
355 | if (extrapolateRight === 'identity') return result;else if (extrapolateRight === 'clamp') result = inputMax;
|
356 | }
|
357 |
|
358 | if (outputMin === outputMax) return outputMin;
|
359 | if (inputMin === inputMax) return input <= inputMin ? outputMin : outputMax;
|
360 |
|
361 | if (inputMin === -Infinity) result = -result;else if (inputMax === Infinity) result = result - inputMin;else result = (result - inputMin) / (inputMax - inputMin);
|
362 |
|
363 | result = easing(result);
|
364 |
|
365 | if (outputMin === -Infinity) result = -result;else if (outputMax === Infinity) result = result + outputMin;else result = result * (outputMax - outputMin) + outputMin;
|
366 | return result;
|
367 | }
|
368 |
|
369 | function findRange(input, inputRange) {
|
370 | for (var i = 1; i < inputRange.length - 1; ++i) if (inputRange[i] >= input) break;
|
371 |
|
372 | return i - 1;
|
373 | }
|
374 |
|
375 |
|
376 | const NUMBER = '[-+]?\\d*\\.?\\d+';
|
377 | const PERCENTAGE = NUMBER + '%';
|
378 |
|
379 | function call() {
|
380 | return '\\(\\s*(' + Array.prototype.slice.call(arguments).join(')\\s*,\\s*(') + ')\\s*\\)';
|
381 | }
|
382 |
|
383 | const rgb = new RegExp('rgb' + call(NUMBER, NUMBER, NUMBER));
|
384 | const rgba = new RegExp('rgba' + call(NUMBER, NUMBER, NUMBER, NUMBER));
|
385 | const hsl = new RegExp('hsl' + call(NUMBER, PERCENTAGE, PERCENTAGE));
|
386 | const hsla = new RegExp('hsla' + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER));
|
387 | const hex3 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
|
388 | const hex4 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
|
389 | const hex6 = /^#([0-9a-fA-F]{6})$/;
|
390 | const hex8 = /^#([0-9a-fA-F]{8})$/;
|
391 |
|
392 |
|
393 |
|
394 |
|
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
|
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 |
|
418 |
|
419 |
|
420 |
|
421 |
|
422 |
|
423 |
|
424 |
|
425 | function normalizeColor(color) {
|
426 | let match;
|
427 |
|
428 | if (typeof color === 'number') {
|
429 | return color >>> 0 === color && color >= 0 && color <= 0xffffffff ? color : null;
|
430 | }
|
431 |
|
432 |
|
433 | if (match = hex6.exec(color)) return parseInt(match[1] + 'ff', 16) >>> 0;
|
434 | if (colors.hasOwnProperty(color)) return colors[color];
|
435 |
|
436 | if (match = rgb.exec(color)) {
|
437 | return (parse255(match[1]) << 24 |
|
438 | parse255(match[2]) << 16 |
|
439 | parse255(match[3]) << 8 |
|
440 | 0x000000ff) >>>
|
441 | 0;
|
442 | }
|
443 |
|
444 | if (match = rgba.exec(color)) {
|
445 | return (parse255(match[1]) << 24 |
|
446 | parse255(match[2]) << 16 |
|
447 | parse255(match[3]) << 8 |
|
448 | parse1(match[4])) >>>
|
449 | 0;
|
450 | }
|
451 |
|
452 | if (match = hex3.exec(color)) {
|
453 | return parseInt(match[1] + match[1] +
|
454 | match[2] + match[2] +
|
455 | match[3] + match[3] +
|
456 | 'ff',
|
457 | 16) >>> 0;
|
458 | }
|
459 |
|
460 |
|
461 | if (match = hex8.exec(color)) return parseInt(match[1], 16) >>> 0;
|
462 |
|
463 | if (match = hex4.exec(color)) {
|
464 | return parseInt(match[1] + match[1] +
|
465 | match[2] + match[2] +
|
466 | match[3] + match[3] +
|
467 | match[4] + match[4],
|
468 | 16) >>> 0;
|
469 | }
|
470 |
|
471 | if (match = hsl.exec(color)) {
|
472 | return (hslToRgb(parse360(match[1]),
|
473 | parsePercentage(match[2]),
|
474 | parsePercentage(match[3])
|
475 | ) | 0x000000ff) >>>
|
476 | 0;
|
477 | }
|
478 |
|
479 | if (match = hsla.exec(color)) {
|
480 | return (hslToRgb(parse360(match[1]),
|
481 | parsePercentage(match[2]),
|
482 | parsePercentage(match[3])
|
483 | ) | parse1(match[4])) >>>
|
484 | 0;
|
485 | }
|
486 |
|
487 | return null;
|
488 | }
|
489 |
|
490 | function hue2rgb(p, q, t) {
|
491 | if (t < 0) t += 1;
|
492 | if (t > 1) t -= 1;
|
493 | if (t < 1 / 6) return p + (q - p) * 6 * t;
|
494 | if (t < 1 / 2) return q;
|
495 | if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
|
496 | return p;
|
497 | }
|
498 |
|
499 | function hslToRgb(h, s, l) {
|
500 | const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
501 | const p = 2 * l - q;
|
502 | const r = hue2rgb(p, q, h + 1 / 3);
|
503 | const g = hue2rgb(p, q, h);
|
504 | const b = hue2rgb(p, q, h - 1 / 3);
|
505 | return Math.round(r * 255) << 24 | Math.round(g * 255) << 16 | Math.round(b * 255) << 8;
|
506 | }
|
507 |
|
508 | function parse255(str) {
|
509 | const int = parseInt(str, 10);
|
510 | if (int < 0) return 0;
|
511 | if (int > 255) return 255;
|
512 | return int;
|
513 | }
|
514 |
|
515 | function parse360(str) {
|
516 | const int = parseFloat(str);
|
517 | return (int % 360 + 360) % 360 / 360;
|
518 | }
|
519 |
|
520 | function parse1(str) {
|
521 | const num = parseFloat(str);
|
522 | if (num < 0) return 0;
|
523 | if (num > 1) return 255;
|
524 | return Math.round(num * 255);
|
525 | }
|
526 |
|
527 | function parsePercentage(str) {
|
528 |
|
529 | const int = parseFloat(str);
|
530 | if (int < 0) return 0;
|
531 | if (int > 100) return 1;
|
532 | return int / 100;
|
533 | }
|
534 |
|
535 | function colorToRgba(input) {
|
536 | let int32Color = normalizeColor(input);
|
537 | if (int32Color === null) return input;
|
538 | int32Color = int32Color || 0;
|
539 | let r = (int32Color & 0xff000000) >>> 24;
|
540 | let g = (int32Color & 0x00ff0000) >>> 16;
|
541 | let b = (int32Color & 0x0000ff00) >>> 8;
|
542 | let a = (int32Color & 0x000000ff) / 255;
|
543 | return `rgba(${r}, ${g}, ${b}, ${a})`;
|
544 | }
|
545 |
|
546 |
|
547 |
|
548 | const stringShapeRegex = /[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
|
549 |
|
550 |
|
551 | const colorRegex = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))/gi;
|
552 |
|
553 | const colorNamesRegex = new RegExp(`(${Object.keys(colors).join('|')})`, 'g');
|
554 |
|
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 |
|
561 |
|
562 |
|
563 |
|
564 | function createInterpolation(config) {
|
565 |
|
566 | const outputRange = config.output.map(rangeValue => rangeValue.replace(colorRegex, colorToRgba)).map(rangeValue => rangeValue.replace(colorNamesRegex, colorToRgba));
|
567 |
|
568 |
|
569 |
|
570 |
|
571 |
|
572 |
|
573 |
|
574 | const outputRanges = outputRange[0].match(stringShapeRegex).map(() => []);
|
575 | outputRange.forEach(value => {
|
576 | value.match(stringShapeRegex).forEach((number, i) => outputRanges[i].push(+number));
|
577 | });
|
578 | const interpolations = outputRange[0].match(stringShapeRegex).map((value, i) => {
|
579 | return Interpolation.create(_extends({}, config, {
|
580 | output: outputRanges[i]
|
581 | }));
|
582 | });
|
583 | return input => {
|
584 | let i = 0;
|
585 | return outputRange[0]
|
586 |
|
587 |
|
588 | .replace(stringShapeRegex, () => interpolations[i++](input))
|
589 |
|
590 | .replace(/rgba\(([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+)\)/gi, (_, p1, p2, p3, p4) => `rgba(${Math.round(p1)}, ${Math.round(p2)}, ${Math.round(p3)}, ${p4})`);
|
591 | };
|
592 | }
|
593 |
|
594 | class AnimatedInterpolation extends AnimatedArrayWithChildren {
|
595 | constructor(parents, _config, _arg) {
|
596 | super();
|
597 |
|
598 | this.getValue = () => this.calc(...this.payload.map(value => value.getValue()));
|
599 |
|
600 | this.updateConfig = (config, arg) => this.calc = Interpolation.create(config, arg);
|
601 |
|
602 | this.interpolate = (config, arg) => new AnimatedInterpolation(this, config, arg);
|
603 |
|
604 | this.payload =
|
605 | parents instanceof AnimatedArrayWithChildren && !parents.updateConfig ? parents.payload : Array.isArray(parents) ? parents : [parents];
|
606 | this.calc = Interpolation.create(_config, _arg);
|
607 | }
|
608 |
|
609 | }
|
610 | const interpolate$1 = (parents, config, arg) => parents && new AnimatedInterpolation(parents, config, arg);
|
611 |
|
612 |
|
613 |
|
614 |
|
615 |
|
616 |
|
617 |
|
618 |
|
619 |
|
620 |
|
621 |
|
622 |
|
623 |
|
624 |
|
625 |
|
626 |
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 |
|
634 |
|
635 | function findAnimatedStyles(node, styles) {
|
636 | if (typeof node.update === 'function') styles.add(node);else node.getChildren().forEach(child => findAnimatedStyles(child, styles));
|
637 | }
|
638 |
|
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 | class AnimatedValue extends AnimatedWithChildren {
|
647 | constructor(_value) {
|
648 | var _this;
|
649 |
|
650 | super();
|
651 | _this = this;
|
652 |
|
653 | this.setValue = function (value, flush) {
|
654 | if (flush === void 0) {
|
655 | flush = true;
|
656 | }
|
657 |
|
658 | _this.value = value;
|
659 | if (flush) _this.flush();
|
660 | };
|
661 |
|
662 | this.getValue = () => this.value;
|
663 |
|
664 | this.updateStyles = () => findAnimatedStyles(this, this.animatedStyles);
|
665 |
|
666 | this.updateValue = value => this.flush(this.value = value);
|
667 |
|
668 | this.interpolate = (config, arg) => new AnimatedInterpolation(this, config, arg);
|
669 |
|
670 | this.value = _value;
|
671 | this.animatedStyles = new Set();
|
672 | this.done = false;
|
673 | this.startPosition = _value;
|
674 | this.lastPosition = _value;
|
675 | this.lastVelocity = undefined;
|
676 | this.lastTime = undefined;
|
677 | this.controller = undefined;
|
678 | }
|
679 |
|
680 | flush() {
|
681 | if (this.animatedStyles.size === 0) this.updateStyles();
|
682 | this.animatedStyles.forEach(animatedStyle => animatedStyle.update());
|
683 | }
|
684 |
|
685 | prepare(controller) {
|
686 |
|
687 |
|
688 | if (this.controller === undefined) this.controller = controller;
|
689 |
|
690 | if (this.controller === controller) {
|
691 | this.startPosition = this.value;
|
692 | this.lastPosition = this.value;
|
693 | this.lastVelocity = controller.isActive ? this.lastVelocity : undefined;
|
694 | this.lastTime = controller.isActive ? this.lastTime : undefined;
|
695 | this.done = false;
|
696 | this.animatedStyles.clear();
|
697 | }
|
698 | }
|
699 |
|
700 | }
|
701 |
|
702 | class AnimatedArray extends AnimatedArrayWithChildren {
|
703 | constructor(array) {
|
704 | var _this;
|
705 |
|
706 | super();
|
707 | _this = this;
|
708 |
|
709 | this.setValue = function (value, flush) {
|
710 | if (flush === void 0) {
|
711 | flush = true;
|
712 | }
|
713 |
|
714 | if (Array.isArray(value)) {
|
715 | if (value.length === _this.payload.length) value.forEach((v, i) => _this.payload[i].setValue(v, flush));
|
716 | } else _this.payload.forEach((v, i) => _this.payload[i].setValue(value, flush));
|
717 | };
|
718 |
|
719 | this.getValue = () => this.payload.map(v => v.getValue());
|
720 |
|
721 | this.interpolate = (config, arg) => new AnimatedInterpolation(this, config, arg);
|
722 |
|
723 | this.payload = array.map(n => new AnimatedValue(n));
|
724 | }
|
725 |
|
726 | }
|
727 |
|
728 | function withDefault(value, defaultValue) {
|
729 | return value === undefined || value === null ? defaultValue : value;
|
730 | }
|
731 | function toArray(a) {
|
732 | return a !== void 0 ? Array.isArray(a) ? a : [a] : [];
|
733 | }
|
734 | function shallowEqual(a, b) {
|
735 | if (typeof a !== typeof b) return false;
|
736 | if (typeof a === 'string' || typeof a === 'number') return a === b;
|
737 | let i;
|
738 |
|
739 | for (i in a) if (!(i in b)) return false;
|
740 |
|
741 | for (i in b) if (a[i] !== b[i]) return false;
|
742 |
|
743 | return i === void 0 ? a === b : true;
|
744 | }
|
745 | function callProp(obj) {
|
746 | for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
747 | args[_key - 1] = arguments[_key];
|
748 | }
|
749 |
|
750 | return typeof obj === 'function' ? obj(...args) : obj;
|
751 | }
|
752 | function getValues$1(object) {
|
753 | return Object.keys(object).map(k => object[k]);
|
754 | }
|
755 | function getForwardProps(props) {
|
756 | const to = props.to,
|
757 | from = props.from,
|
758 | config = props.config,
|
759 | native = props.native,
|
760 | onStart = props.onStart,
|
761 | onRest = props.onRest,
|
762 | onFrame = props.onFrame,
|
763 | children = props.children,
|
764 | reset = props.reset,
|
765 | reverse = props.reverse,
|
766 | force = props.force,
|
767 | immediate = props.immediate,
|
768 | impl = props.impl,
|
769 | inject = props.inject,
|
770 | delay = props.delay,
|
771 | attach = props.attach,
|
772 | destroyed = props.destroyed,
|
773 | interpolateTo = props.interpolateTo,
|
774 | autoStart = props.autoStart,
|
775 | ref = props.ref,
|
776 | forward = _objectWithoutPropertiesLoose(props, ["to", "from", "config", "native", "onStart", "onRest", "onFrame", "children", "reset", "reverse", "force", "immediate", "impl", "inject", "delay", "attach", "destroyed", "interpolateTo", "autoStart", "ref"]);
|
777 |
|
778 | return forward;
|
779 | }
|
780 | function interpolateTo(props) {
|
781 | const forward = getForwardProps(props);
|
782 | const rest = Object.keys(props).reduce((a, k) => forward[k] !== void 0 ? a : _extends({}, a, {
|
783 | [k]: props[k]
|
784 | }), {});
|
785 | return _extends({
|
786 | to: forward
|
787 | }, rest);
|
788 | }
|
789 | function convertToAnimatedValue(acc, _ref) {
|
790 | let name = _ref[0],
|
791 | value = _ref[1];
|
792 | return _extends({}, acc, {
|
793 | [name]: new (Array.isArray(value) ? AnimatedArray : AnimatedValue)(value)
|
794 | });
|
795 | }
|
796 | function convertValues(props) {
|
797 | const from = props.from,
|
798 | to = props.to,
|
799 | native = props.native;
|
800 | const allProps = Object.entries(_extends({}, from, to));
|
801 | return native ? allProps.reduce(convertToAnimatedValue, {}) : _extends({}, from, to);
|
802 | }
|
803 | function handleRef(ref, forward) {
|
804 | if (forward) {
|
805 |
|
806 | if (typeof forward === 'function') forward(ref);else if (typeof forward === 'object') {
|
807 |
|
808 | forward.current = ref;
|
809 | }
|
810 | }
|
811 |
|
812 | return ref;
|
813 | }
|
814 |
|
815 | const check = value => value === 'auto';
|
816 |
|
817 | const overwrite = (width, height) => (acc, _ref) => {
|
818 | let name = _ref[0],
|
819 | value = _ref[1];
|
820 | return _extends({}, acc, {
|
821 | [name]: value === 'auto' ? ~name.indexOf('height') ? height : width : value
|
822 | });
|
823 | };
|
824 |
|
825 | function fixAuto(props, callback) {
|
826 | const from = props.from,
|
827 | to = props.to,
|
828 | children = props.children;
|
829 |
|
830 |
|
831 | if (!(getValues$1(to).some(check) || getValues$1(from).some(check))) return;
|
832 |
|
833 | let element = children(convertValues(props));
|
834 |
|
835 | if (!element) return;
|
836 |
|
837 | if (Array.isArray(element)) element = {
|
838 | type: 'div',
|
839 | props: {
|
840 | children: element
|
841 | }
|
842 |
|
843 | };
|
844 | const elementStyles = element.props.style;
|
845 |
|
846 | return React__default.createElement(element.type, _extends({
|
847 | key: element.key ? element.key : undefined
|
848 | }, element.props, {
|
849 | style: _extends({}, elementStyles, {
|
850 | position: 'absolute',
|
851 | visibility: 'hidden'
|
852 | }),
|
853 | ref: _ref2 => {
|
854 | if (_ref2) {
|
855 |
|
856 | let node = ReactDOM.findDOMNode(_ref2);
|
857 | let width, height;
|
858 | let cs = getComputedStyle(node);
|
859 |
|
860 | if (cs.boxSizing === 'border-box') {
|
861 | width = node.offsetWidth;
|
862 | height = node.offsetHeight;
|
863 | } else {
|
864 | const paddingX = parseFloat(cs.paddingLeft || 0) + parseFloat(cs.paddingRight || 0);
|
865 | const paddingY = parseFloat(cs.paddingTop || 0) + parseFloat(cs.paddingBottom || 0);
|
866 | const borderX = parseFloat(cs.borderLeftWidth || 0) + parseFloat(cs.borderRightWidth || 0);
|
867 | const borderY = parseFloat(cs.borderTopWidth || 0) + parseFloat(cs.borderBottomWidth || 0);
|
868 | width = node.offsetWidth - paddingX - borderX;
|
869 | height = node.offsetHeight - paddingY - borderY;
|
870 | }
|
871 |
|
872 | const convert = overwrite(width, height);
|
873 | callback(_extends({}, props, {
|
874 | from: Object.entries(from).reduce(convert, from),
|
875 | to: Object.entries(to).reduce(convert, to)
|
876 | }));
|
877 | }
|
878 | }
|
879 | }));
|
880 | }
|
881 |
|
882 | let isUnitlessNumber = {
|
883 | animationIterationCount: true,
|
884 | borderImageOutset: true,
|
885 | borderImageSlice: true,
|
886 | borderImageWidth: true,
|
887 | boxFlex: true,
|
888 | boxFlexGroup: true,
|
889 | boxOrdinalGroup: true,
|
890 | columnCount: true,
|
891 | columns: true,
|
892 | flex: true,
|
893 | flexGrow: true,
|
894 | flexPositive: true,
|
895 | flexShrink: true,
|
896 | flexNegative: true,
|
897 | flexOrder: true,
|
898 | gridRow: true,
|
899 | gridRowEnd: true,
|
900 | gridRowSpan: true,
|
901 | gridRowStart: true,
|
902 | gridColumn: true,
|
903 | gridColumnEnd: true,
|
904 | gridColumnSpan: true,
|
905 | gridColumnStart: true,
|
906 | fontWeight: true,
|
907 | lineClamp: true,
|
908 | lineHeight: true,
|
909 | opacity: true,
|
910 | order: true,
|
911 | orphans: true,
|
912 | tabSize: true,
|
913 | widows: true,
|
914 | zIndex: true,
|
915 | zoom: true,
|
916 |
|
917 | fillOpacity: true,
|
918 | floodOpacity: true,
|
919 | stopOpacity: true,
|
920 | strokeDasharray: true,
|
921 | strokeDashoffset: true,
|
922 | strokeMiterlimit: true,
|
923 | strokeOpacity: true,
|
924 | strokeWidth: true
|
925 | };
|
926 |
|
927 | const prefixKey = (prefix, key) => prefix + key.charAt(0).toUpperCase() + key.substring(1);
|
928 |
|
929 | const prefixes = ['Webkit', 'Ms', 'Moz', 'O'];
|
930 | isUnitlessNumber = Object.keys(isUnitlessNumber).reduce((acc, prop) => {
|
931 | prefixes.forEach(prefix => acc[prefixKey(prefix, prop)] = acc[prop]);
|
932 | return acc;
|
933 | }, isUnitlessNumber);
|
934 |
|
935 | function dangerousStyleValue(name, value, isCustomProperty) {
|
936 | if (value == null || typeof value === 'boolean' || value === '') return '';
|
937 | if (!isCustomProperty && typeof value === 'number' && value !== 0 && !(isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name])) return value + 'px';
|
938 |
|
939 | return ('' + value).trim();
|
940 | }
|
941 |
|
942 | const attributeCache = {};
|
943 | injectCreateAnimatedStyle(style => new AnimatedStyle(style));
|
944 | injectDefaultElement('div');
|
945 | injectInterpolation(createInterpolation);
|
946 | injectColorNames(colors);
|
947 | injectBugfixes(fixAuto);
|
948 | injectApplyAnimatedValues((instance, props) => {
|
949 | if (instance.nodeType && instance.setAttribute !== undefined) {
|
950 | const style = props.style,
|
951 | children = props.children,
|
952 | scrollTop = props.scrollTop,
|
953 | scrollLeft = props.scrollLeft,
|
954 | attributes = _objectWithoutPropertiesLoose(props, ["style", "children", "scrollTop", "scrollLeft"]);
|
955 |
|
956 | if (scrollTop !== void 0) instance.scrollTop = scrollTop;
|
957 | if (scrollLeft !== void 0) instance.scrollLeft = scrollLeft;
|
958 |
|
959 | if (children !== void 0) instance.textContent = children;
|
960 |
|
961 | for (let styleName in style) {
|
962 | if (!style.hasOwnProperty(styleName)) continue;
|
963 | var isCustomProperty = styleName.indexOf('--') === 0;
|
964 | var styleValue = dangerousStyleValue(styleName, style[styleName], isCustomProperty);
|
965 | if (styleName === 'float') styleName = 'cssFloat';
|
966 | if (isCustomProperty) instance.style.setProperty(styleName, styleValue);else instance.style[styleName] = styleValue;
|
967 | }
|
968 |
|
969 |
|
970 | for (let name in attributes) {
|
971 |
|
972 | const dashCase = attributeCache[name] || (attributeCache[name] = name.replace(/([A-Z])/g, n => '-' + n.toLowerCase()));
|
973 | if (typeof instance.getAttribute(dashCase) !== 'undefined') instance.setAttribute(dashCase, attributes[name]);
|
974 | }
|
975 | } else return false;
|
976 | }, style => style);
|
977 |
|
978 | let active = false;
|
979 | const controllers = new Set();
|
980 |
|
981 | const frameLoop = () => {
|
982 | let time = now();
|
983 |
|
984 | for (let controller of controllers) {
|
985 | let isDone = true;
|
986 | let noChange = true;
|
987 |
|
988 | for (let configIdx = 0; configIdx < controller.configs.length; configIdx++) {
|
989 | let config = controller.configs[configIdx];
|
990 | let endOfAnimation, lastTime;
|
991 |
|
992 | for (let valIdx = 0; valIdx < config.animatedValues.length; valIdx++) {
|
993 | let animation = config.animatedValues[valIdx];
|
994 |
|
995 | if (animation.done) continue;
|
996 | let from = config.fromValues[valIdx];
|
997 | let to = config.toValues[valIdx];
|
998 | let position = animation.lastPosition;
|
999 | let isAnimated = to instanceof Animated;
|
1000 | let velocity = Array.isArray(config.initialVelocity) ? config.initialVelocity[valIdx] : config.initialVelocity;
|
1001 | if (isAnimated) to = to.getValue();
|
1002 |
|
1003 | if (config.immediate || !isAnimated && !config.decay && from === to) {
|
1004 | animation.updateValue(to);
|
1005 | animation.done = true;
|
1006 | continue;
|
1007 | }
|
1008 |
|
1009 |
|
1010 | if (config.delay && time - controller.startTime < config.delay) {
|
1011 | isDone = false;
|
1012 | continue;
|
1013 | }
|
1014 |
|
1015 |
|
1016 | noChange = false;
|
1017 |
|
1018 | if (typeof from === 'string' || typeof to === 'string') {
|
1019 | animation.updateValue(to);
|
1020 | animation.done = true;
|
1021 | continue;
|
1022 | }
|
1023 |
|
1024 | if (config.duration !== void 0) {
|
1025 |
|
1026 | position = from + config.easing((time - controller.startTime - config.delay) / config.duration) * (to - from);
|
1027 | endOfAnimation = time >= controller.startTime + config.delay + config.duration;
|
1028 | } else if (config.decay) {
|
1029 |
|
1030 | position = from + velocity / (1 - 0.998) * (1 - Math.exp(-(1 - 0.998) * (time - controller.startTime)));
|
1031 | endOfAnimation = Math.abs(animation.lastPosition - position) < 0.1;
|
1032 | if (endOfAnimation) to = position;
|
1033 | } else {
|
1034 |
|
1035 | lastTime = animation.lastTime !== void 0 ? animation.lastTime : time;
|
1036 | velocity = animation.lastVelocity !== void 0 ? animation.lastVelocity : config.initialVelocity;
|
1037 |
|
1038 | if (time > lastTime + 64) lastTime = time;
|
1039 |
|
1040 | let numSteps = Math.floor(time - lastTime);
|
1041 |
|
1042 | for (let i = 0; i < numSteps; ++i) {
|
1043 | let force = -config.tension * (position - to);
|
1044 | let damping = -config.friction * velocity;
|
1045 | let acceleration = (force + damping) / config.mass;
|
1046 | velocity = velocity + acceleration * 1 / 1000;
|
1047 | position = position + velocity * 1 / 1000;
|
1048 | }
|
1049 |
|
1050 |
|
1051 | let isOvershooting = config.clamp && config.tension !== 0 ? from < to ? position > to : position < to : false;
|
1052 | let isVelocity = Math.abs(velocity) <= config.precision;
|
1053 | let isDisplacement = config.tension !== 0 ? Math.abs(to - position) <= config.precision : true;
|
1054 | endOfAnimation = isOvershooting || isVelocity && isDisplacement;
|
1055 | animation.lastVelocity = velocity;
|
1056 | animation.lastTime = time;
|
1057 | }
|
1058 |
|
1059 |
|
1060 | if (isAnimated && !config.toValues[valIdx].done) endOfAnimation = false;
|
1061 |
|
1062 | if (endOfAnimation) {
|
1063 |
|
1064 | if (animation.value !== to) position = to;
|
1065 | animation.done = true;
|
1066 | } else isDone = false;
|
1067 |
|
1068 | animation.updateValue(position);
|
1069 | animation.lastPosition = position;
|
1070 | }
|
1071 |
|
1072 |
|
1073 | if (controller.props.onFrame || !controller.props.native) controller.animatedProps[config.name] = config.interpolation.getValue();
|
1074 | }
|
1075 |
|
1076 |
|
1077 | if (controller.props.onFrame || !controller.props.native) {
|
1078 | if (!controller.props.native && controller.onUpdate) controller.onUpdate();
|
1079 | if (controller.props.onFrame) controller.props.onFrame(controller.animatedProps);
|
1080 | }
|
1081 |
|
1082 |
|
1083 | if (isDone) {
|
1084 | controllers.delete(controller);
|
1085 | controller.debouncedOnEnd({
|
1086 | finished: true,
|
1087 | noChange
|
1088 | });
|
1089 | }
|
1090 | }
|
1091 |
|
1092 |
|
1093 | if (controllers.size) requestFrame(frameLoop);else active = false;
|
1094 | };
|
1095 |
|
1096 | const addController = controller => {
|
1097 | if (!controllers.has(controller)) {
|
1098 | controllers.add(controller);
|
1099 | if (!active) requestFrame(frameLoop);
|
1100 | active = true;
|
1101 | }
|
1102 | };
|
1103 |
|
1104 | const removeController = controller => {
|
1105 | if (controllers.has(controller)) {
|
1106 | controllers.delete(controller);
|
1107 | }
|
1108 | };
|
1109 |
|
1110 | class Controller {
|
1111 | constructor(props, config) {
|
1112 | if (config === void 0) {
|
1113 | config = {
|
1114 | native: true,
|
1115 | interpolateTo: true,
|
1116 | autoStart: true
|
1117 | };
|
1118 | }
|
1119 |
|
1120 | this.getValues = () => this.props.native ? this.interpolations : this.animatedProps;
|
1121 |
|
1122 | this.dependents = new Set();
|
1123 | this.isActive = false;
|
1124 | this.hasChanged = false;
|
1125 | this.props = {};
|
1126 | this.merged = {};
|
1127 | this.animations = {};
|
1128 | this.interpolations = {};
|
1129 | this.animatedProps = {};
|
1130 | this.configs = [];
|
1131 | this.frame = undefined;
|
1132 | this.startTime = undefined;
|
1133 | this.lastTime = undefined;
|
1134 | this.update(_extends({}, props, config));
|
1135 | }
|
1136 |
|
1137 | update(props) {
|
1138 | this.props = _extends({}, this.props, props);
|
1139 |
|
1140 | let _ref = this.props.interpolateTo ? interpolateTo(this.props) : this.props,
|
1141 | _ref$from = _ref.from,
|
1142 | from = _ref$from === void 0 ? {} : _ref$from,
|
1143 | _ref$to = _ref.to,
|
1144 | to = _ref$to === void 0 ? {} : _ref$to,
|
1145 | _ref$config = _ref.config,
|
1146 | config = _ref$config === void 0 ? {} : _ref$config,
|
1147 | _ref$delay = _ref.delay,
|
1148 | delay = _ref$delay === void 0 ? 0 : _ref$delay,
|
1149 | reverse = _ref.reverse,
|
1150 | attach = _ref.attach,
|
1151 | reset = _ref.reset,
|
1152 | immediate = _ref.immediate,
|
1153 | autoStart = _ref.autoStart,
|
1154 | ref = _ref.ref;
|
1155 |
|
1156 |
|
1157 | if (reverse) {
|
1158 | var _ref2 = [to, from];
|
1159 | from = _ref2[0];
|
1160 | to = _ref2[1];
|
1161 | }
|
1162 |
|
1163 | this.hasChanged = false;
|
1164 |
|
1165 | let target = attach && attach(this);
|
1166 |
|
1167 | let extra = reset ? {} : this.merged;
|
1168 |
|
1169 | this.merged = _extends({}, from, extra, to);
|
1170 |
|
1171 | this.animations = Object.entries(this.merged).reduce((acc, _ref3, i) => {
|
1172 | let name = _ref3[0],
|
1173 | value = _ref3[1];
|
1174 |
|
1175 | let entry = !reset && acc[name] || {};
|
1176 |
|
1177 | const isNumber = typeof value === 'number';
|
1178 | const isString = typeof value === 'string' && !value.startsWith('#') && !/\d/.test(value) && !colorNames[value];
|
1179 | const isArray = !isNumber && !isString && Array.isArray(value);
|
1180 | let fromValue = from[name] !== undefined ? from[name] : value;
|
1181 | let toValue = isNumber || isArray ? value : isString ? value : 1;
|
1182 | let toConfig = callProp(config, name);
|
1183 | if (target) toValue = target.animations[name].parent;
|
1184 |
|
1185 | if (toConfig.decay !== void 0 || !shallowEqual(entry.changes, value)) {
|
1186 | this.hasChanged = true;
|
1187 | let parent, interpolation$$1;
|
1188 | if (isNumber || isString) parent = interpolation$$1 = entry.parent || new AnimatedValue(fromValue);else if (isArray) parent = interpolation$$1 = entry.parent || new AnimatedArray(fromValue);else {
|
1189 | const prev = entry.interpolation && entry.interpolation.calc(entry.parent.value);
|
1190 |
|
1191 | if (entry.parent) {
|
1192 | parent = entry.parent;
|
1193 | parent.setValue(0, false);
|
1194 | } else parent = new AnimatedValue(0);
|
1195 |
|
1196 | const range = {
|
1197 | output: [prev !== void 0 ? prev : fromValue, value]
|
1198 | };
|
1199 |
|
1200 | if (entry.interpolation) {
|
1201 | interpolation$$1 = entry.interpolation;
|
1202 | entry.interpolation.updateConfig(range);
|
1203 | } else interpolation$$1 = parent.interpolate(range);
|
1204 | }
|
1205 |
|
1206 | if (callProp(immediate, name)) parent.setValue(value, false);
|
1207 |
|
1208 | const animatedValues = toArray(parent.getPayload());
|
1209 | animatedValues.forEach(value => value.prepare(this));
|
1210 | return _extends({}, acc, {
|
1211 | [name]: _extends({}, entry, {
|
1212 | name,
|
1213 | parent,
|
1214 | interpolation: interpolation$$1,
|
1215 | animatedValues,
|
1216 | changes: value,
|
1217 | fromValues: toArray(parent.getValue()),
|
1218 | toValues: toArray(target ? toValue.getPayload() : toValue),
|
1219 | immediate: callProp(immediate, name),
|
1220 | delay: withDefault(toConfig.delay, delay || 0),
|
1221 | initialVelocity: withDefault(toConfig.velocity, 0),
|
1222 | clamp: withDefault(toConfig.clamp, false),
|
1223 | precision: withDefault(toConfig.precision, 0.01),
|
1224 | tension: withDefault(toConfig.tension, 170),
|
1225 | friction: withDefault(toConfig.friction, 26),
|
1226 | mass: withDefault(toConfig.mass, 1),
|
1227 | duration: toConfig.duration,
|
1228 | easing: withDefault(toConfig.easing, t => t),
|
1229 | decay: toConfig.decay
|
1230 | })
|
1231 | });
|
1232 | } else return acc;
|
1233 | }, this.animations);
|
1234 |
|
1235 | if (this.hasChanged) {
|
1236 | this.configs = getValues$1(this.animations);
|
1237 | this.animatedProps = {};
|
1238 | this.interpolations = {};
|
1239 |
|
1240 | for (let key in this.animations) {
|
1241 | this.interpolations[key] = this.animations[key].interpolation;
|
1242 | this.animatedProps[key] = this.animations[key].interpolation.getValue();
|
1243 | }
|
1244 | }
|
1245 |
|
1246 |
|
1247 | for (var _len = arguments.length, start = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
1248 | start[_key - 1] = arguments[_key];
|
1249 | }
|
1250 |
|
1251 | if (!ref && (autoStart || start.length)) this.start(...start);
|
1252 | const onEnd = start[0],
|
1253 | onUpdate = start[1];
|
1254 | this.onEnd = typeof onEnd === 'function' && onEnd;
|
1255 | this.onUpdate = onUpdate;
|
1256 | return this.getValues();
|
1257 | }
|
1258 |
|
1259 | start(onEnd, onUpdate) {
|
1260 | this.startTime = now();
|
1261 | if (this.isActive) this.stop();
|
1262 | this.isActive = true;
|
1263 | this.onEnd = typeof onEnd === 'function' && onEnd;
|
1264 | this.onUpdate = onUpdate;
|
1265 | if (this.props.onStart) this.props.onStart();
|
1266 | addController(this);
|
1267 | return new Promise(res => this.resolve = res);
|
1268 | }
|
1269 |
|
1270 | stop(finished) {
|
1271 | if (finished === void 0) {
|
1272 | finished = false;
|
1273 | }
|
1274 |
|
1275 |
|
1276 | if (finished) getValues$1(this.animations).forEach(a => a.changes = undefined);
|
1277 | this.debouncedOnEnd({
|
1278 | finished
|
1279 | });
|
1280 | }
|
1281 |
|
1282 | destroy() {
|
1283 | removeController(this);
|
1284 | this.props = {};
|
1285 | this.merged = {};
|
1286 | this.animations = {};
|
1287 | this.interpolations = {};
|
1288 | this.animatedProps = {};
|
1289 | this.configs = [];
|
1290 | }
|
1291 |
|
1292 | debouncedOnEnd(result) {
|
1293 | removeController(this);
|
1294 | this.isActive = false;
|
1295 | const onEnd = this.onEnd;
|
1296 | this.onEnd = null;
|
1297 | if (onEnd) onEnd(result);
|
1298 | if (this.resolve) this.resolve();
|
1299 | this.resolve = null;
|
1300 | }
|
1301 |
|
1302 | }
|
1303 |
|
1304 | class AnimatedProps extends AnimatedObjectWithChildren {
|
1305 | constructor(props, callback) {
|
1306 | super();
|
1307 | if (props.style) props = _extends({}, props, {
|
1308 | style: createAnimatedStyle(props.style)
|
1309 | });
|
1310 | this.payload = props;
|
1311 | this.update = callback;
|
1312 | this.attach();
|
1313 | }
|
1314 |
|
1315 | }
|
1316 |
|
1317 | function createAnimatedComponent(Component) {
|
1318 | class AnimatedComponent extends React__default.Component {
|
1319 | constructor(props) {
|
1320 | super();
|
1321 |
|
1322 | this.callback = () => {
|
1323 | if (this.node) {
|
1324 | const didUpdate = applyAnimatedValues.fn(this.node, this.propsAnimated.getAnimatedValue(), this);
|
1325 | if (didUpdate === false) this.forceUpdate();
|
1326 | }
|
1327 | };
|
1328 |
|
1329 | this.attachProps(props);
|
1330 | }
|
1331 |
|
1332 | componentWillUnmount() {
|
1333 | this.propsAnimated && this.propsAnimated.detach();
|
1334 | }
|
1335 |
|
1336 | setNativeProps(props) {
|
1337 | const didUpdate = applyAnimatedValues.fn(this.node, props, this);
|
1338 | if (didUpdate === false) this.forceUpdate();
|
1339 | }
|
1340 |
|
1341 |
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 | attachProps(_ref) {
|
1348 | let forwardRef = _ref.forwardRef,
|
1349 | nextProps = _objectWithoutPropertiesLoose(_ref, ["forwardRef"]);
|
1350 |
|
1351 | const oldPropsAnimated = this.propsAnimated;
|
1352 | this.propsAnimated = new AnimatedProps(nextProps, this.callback);
|
1353 |
|
1354 |
|
1355 |
|
1356 |
|
1357 |
|
1358 |
|
1359 |
|
1360 |
|
1361 | oldPropsAnimated && oldPropsAnimated.detach();
|
1362 | }
|
1363 |
|
1364 | shouldComponentUpdate(props) {
|
1365 | const style = props.style,
|
1366 | nextProps = _objectWithoutPropertiesLoose(props, ["style"]);
|
1367 |
|
1368 | const _this$props = this.props,
|
1369 | currentStyle = _this$props.style,
|
1370 | currentProps = _objectWithoutPropertiesLoose(_this$props, ["style"]);
|
1371 |
|
1372 | if (!shallowEqual(currentProps, nextProps) || !shallowEqual(currentStyle, style)) {
|
1373 | this.attachProps(props);
|
1374 | return true;
|
1375 | }
|
1376 |
|
1377 | return false;
|
1378 | }
|
1379 |
|
1380 | render() {
|
1381 | const _this$propsAnimated$g = this.propsAnimated.getValue(),
|
1382 | scrollTop = _this$propsAnimated$g.scrollTop,
|
1383 | scrollLeft = _this$propsAnimated$g.scrollLeft,
|
1384 | animatedProps = _objectWithoutPropertiesLoose(_this$propsAnimated$g, ["scrollTop", "scrollLeft"]);
|
1385 |
|
1386 | return React__default.createElement(Component, _extends({}, animatedProps, {
|
1387 | ref: node => this.node = handleRef(node, this.props.forwardRef)
|
1388 | }));
|
1389 | }
|
1390 |
|
1391 | }
|
1392 |
|
1393 | return React__default.forwardRef((props, ref) => React__default.createElement(AnimatedComponent, _extends({}, props, {
|
1394 | forwardRef: ref
|
1395 | })));
|
1396 | }
|
1397 |
|
1398 | const config = {
|
1399 | default: {
|
1400 | tension: 170,
|
1401 | friction: 26
|
1402 | },
|
1403 | gentle: {
|
1404 | tension: 120,
|
1405 | friction: 14
|
1406 | },
|
1407 | wobbly: {
|
1408 | tension: 180,
|
1409 | friction: 12
|
1410 | },
|
1411 | stiff: {
|
1412 | tension: 210,
|
1413 | friction: 20
|
1414 | },
|
1415 | slow: {
|
1416 | tension: 280,
|
1417 | friction: 60
|
1418 | },
|
1419 | molasses: {
|
1420 | tension: 280,
|
1421 | friction: 120
|
1422 | }
|
1423 | };
|
1424 |
|
1425 | class Spring extends React__default.Component {
|
1426 | constructor() {
|
1427 | super(...arguments);
|
1428 | this.state = {
|
1429 | lastProps: {
|
1430 | from: {},
|
1431 | to: {}
|
1432 | },
|
1433 | propsChanged: false,
|
1434 | internal: false
|
1435 | };
|
1436 | this.controller = new Controller(null, null);
|
1437 | this.didUpdate = false;
|
1438 | this.didInject = false;
|
1439 | this.finished = true;
|
1440 |
|
1441 | this.start = () => {
|
1442 | this.finished = false;
|
1443 | let wasMounted = this.mounted;
|
1444 | this.controller.start(props => this.finish(_extends({}, props, {
|
1445 | wasMounted
|
1446 | })), this.update);
|
1447 | };
|
1448 |
|
1449 | this.stop = () => this.controller.stop(true);
|
1450 |
|
1451 | this.update = () => this.mounted && this.setState({
|
1452 | internal: true
|
1453 | });
|
1454 |
|
1455 | this.finish = (_ref) => {
|
1456 | let finished = _ref.finished,
|
1457 | noChange = _ref.noChange,
|
1458 | wasMounted = _ref.wasMounted;
|
1459 | this.finished = true;
|
1460 |
|
1461 | if (this.mounted && finished) {
|
1462 |
|
1463 | if (this.props.onRest && (wasMounted || !noChange)) this.props.onRest(this.controller.merged);
|
1464 |
|
1465 | if (this.mounted && this.didInject) {
|
1466 | this.afterInject = convertValues(this.props);
|
1467 | this.setState({
|
1468 | internal: true
|
1469 | });
|
1470 | }
|
1471 |
|
1472 |
|
1473 | if (this.mounted && (this.didInject || this.props.after)) this.setState({
|
1474 | internal: true
|
1475 | });
|
1476 | this.didInject = false;
|
1477 | }
|
1478 | };
|
1479 | }
|
1480 |
|
1481 | componentDidMount() {
|
1482 |
|
1483 | this.componentDidUpdate();
|
1484 | this.mounted = true;
|
1485 | }
|
1486 |
|
1487 | componentWillUnmount() {
|
1488 |
|
1489 | this.mounted = false;
|
1490 | this.stop();
|
1491 | }
|
1492 |
|
1493 | static getDerivedStateFromProps(props, _ref2) {
|
1494 | let internal = _ref2.internal,
|
1495 | lastProps = _ref2.lastProps;
|
1496 |
|
1497 | const from = props.from,
|
1498 | to = props.to,
|
1499 | reset = props.reset,
|
1500 | force = props.force;
|
1501 | const propsChanged = !shallowEqual(to, lastProps.to) || !shallowEqual(from, lastProps.from) || reset && !internal || force && !internal;
|
1502 | return {
|
1503 | propsChanged,
|
1504 | lastProps: props,
|
1505 | internal: false
|
1506 | };
|
1507 | }
|
1508 |
|
1509 | render() {
|
1510 | const children = this.props.children;
|
1511 | const propsChanged = this.state.propsChanged;
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 | if (this.props.inject && propsChanged && !this.injectProps) {
|
1517 | const frame = this.props.inject(this.props, injectProps => {
|
1518 |
|
1519 | this.injectProps = injectProps;
|
1520 | this.setState({
|
1521 | internal: true
|
1522 | });
|
1523 | });
|
1524 |
|
1525 | if (frame) return frame;
|
1526 | }
|
1527 |
|
1528 |
|
1529 | if (this.injectProps || propsChanged) {
|
1530 |
|
1531 | this.didInject = false;
|
1532 |
|
1533 |
|
1534 | if (this.injectProps) {
|
1535 | this.controller.update(this.injectProps);
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 | this.didInject = true;
|
1541 | } else if (propsChanged) this.controller.update(this.props);
|
1542 |
|
1543 |
|
1544 | this.didUpdate = true;
|
1545 | this.afterInject = undefined;
|
1546 | this.injectProps = undefined;
|
1547 | }
|
1548 |
|
1549 |
|
1550 |
|
1551 | let values = _extends({}, this.controller.getValues(), this.afterInject);
|
1552 |
|
1553 | if (this.finished) values = _extends({}, values, this.props.after);
|
1554 | return Object.keys(values).length ? children(values) : null;
|
1555 | }
|
1556 |
|
1557 | componentDidUpdate() {
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 | if (this.didUpdate) this.start();
|
1563 | this.didUpdate = false;
|
1564 | }
|
1565 |
|
1566 | }
|
1567 | Spring.defaultProps = {
|
1568 | from: {},
|
1569 | to: {},
|
1570 | config: config.default,
|
1571 | native: false,
|
1572 | immediate: false,
|
1573 | reset: false,
|
1574 | force: false,
|
1575 | inject: bugfixes
|
1576 | };
|
1577 |
|
1578 | class Trail extends React__default.PureComponent {
|
1579 | constructor() {
|
1580 | super(...arguments);
|
1581 | this.first = true;
|
1582 | this.instances = new Set();
|
1583 |
|
1584 | this.hook = (instance, index, length, reverse) => {
|
1585 |
|
1586 | this.instances.add(instance);
|
1587 |
|
1588 | if (reverse ? index === length - 1 : index === 0) return undefined;else return Array.from(this.instances)[reverse ? index + 1 : index - 1];
|
1589 | };
|
1590 | }
|
1591 |
|
1592 | render() {
|
1593 | const _this$props = this.props,
|
1594 | items = _this$props.items,
|
1595 | _children = _this$props.children,
|
1596 | _this$props$from = _this$props.from,
|
1597 | from = _this$props$from === void 0 ? {} : _this$props$from,
|
1598 | initial = _this$props.initial,
|
1599 | reverse = _this$props.reverse,
|
1600 | keys = _this$props.keys,
|
1601 | delay = _this$props.delay,
|
1602 | onRest = _this$props.onRest,
|
1603 | props = _objectWithoutPropertiesLoose(_this$props, ["items", "children", "from", "initial", "reverse", "keys", "delay", "onRest"]);
|
1604 |
|
1605 | const array = toArray(items);
|
1606 | return toArray(array).map((item, i) => React__default.createElement(Spring, _extends({
|
1607 | onRest: i === 0 ? onRest : null,
|
1608 | key: typeof keys === 'function' ? keys(item) : toArray(keys)[i],
|
1609 | from: this.first && initial !== void 0 ? initial || {} : from
|
1610 | }, props, {
|
1611 | delay: i === 0 && delay || undefined,
|
1612 | attach: instance => this.hook(instance, i, array.length, reverse),
|
1613 | children: props => {
|
1614 | const child = _children(item, i);
|
1615 |
|
1616 | return child ? child(props) : null;
|
1617 | }
|
1618 | })));
|
1619 | }
|
1620 |
|
1621 | componentDidUpdate(prevProps) {
|
1622 | this.first = false;
|
1623 | if (prevProps.items !== this.props.items) this.instances.clear();
|
1624 | }
|
1625 |
|
1626 | }
|
1627 | Trail.defaultProps = {
|
1628 | keys: item => item
|
1629 | };
|
1630 |
|
1631 | const DEFAULT = '__default';
|
1632 |
|
1633 | class KeyframesImpl extends React__default.PureComponent {
|
1634 | constructor() {
|
1635 | var _this;
|
1636 |
|
1637 | super(...arguments);
|
1638 | _this = this;
|
1639 | this.guid = 0;
|
1640 | this.state = {
|
1641 | props: {},
|
1642 | resolve: () => null,
|
1643 | last: true,
|
1644 | index: 0
|
1645 | };
|
1646 |
|
1647 | this.next = function (props, last, index) {
|
1648 | if (last === void 0) {
|
1649 | last = true;
|
1650 | }
|
1651 |
|
1652 | if (index === void 0) {
|
1653 | index = 0;
|
1654 | }
|
1655 |
|
1656 | _this.running = true;
|
1657 | return new Promise(resolve => {
|
1658 | _this.mounted && _this.setState(state => ({
|
1659 | props,
|
1660 | resolve,
|
1661 | last,
|
1662 | index
|
1663 | }), () => _this.running = false);
|
1664 | });
|
1665 | };
|
1666 | }
|
1667 |
|
1668 | componentDidMount() {
|
1669 | this.mounted = true;
|
1670 | this.componentDidUpdate({});
|
1671 | }
|
1672 |
|
1673 | componentWillUnmount() {
|
1674 | this.mounted = false;
|
1675 | }
|
1676 |
|
1677 | componentDidUpdate(previous) {
|
1678 | var _this2 = this;
|
1679 |
|
1680 | const _this$props = this.props,
|
1681 | states = _this$props.states,
|
1682 | f = _this$props.filter,
|
1683 | state = _this$props.state;
|
1684 |
|
1685 | if (previous.state !== this.props.state || this.props.reset && !this.running || !shallowEqual(states[state], previous.states[previous.state])) {
|
1686 | if (states && state && states[state]) {
|
1687 | const localId = ++this.guid;
|
1688 | const slots = states[state];
|
1689 |
|
1690 | if (slots) {
|
1691 | if (Array.isArray(slots)) {
|
1692 | let q = Promise.resolve();
|
1693 |
|
1694 | for (let i = 0; i < slots.length; i++) {
|
1695 | let index = i;
|
1696 | let slot = slots[index];
|
1697 | let last = index === slots.length - 1;
|
1698 | q = q.then(() => localId === this.guid && this.next(f(slot), last, index));
|
1699 | }
|
1700 | } else if (typeof slots === 'function') {
|
1701 | let index = 0;
|
1702 | slots(
|
1703 | function (props, last) {
|
1704 | if (last === void 0) {
|
1705 | last = false;
|
1706 | }
|
1707 |
|
1708 | return localId === _this2.guid && _this2.next(f(props), last, index++);
|
1709 | },
|
1710 | () => requestFrame(() => this.instance && this.instance.stop()),
|
1711 | this.props);
|
1712 | } else {
|
1713 | this.next(f(states[state]));
|
1714 | }
|
1715 | }
|
1716 | }
|
1717 | }
|
1718 | }
|
1719 |
|
1720 | render() {
|
1721 | const _this$state = this.state,
|
1722 | props = _this$state.props,
|
1723 | resolve = _this$state.resolve,
|
1724 | last = _this$state.last,
|
1725 | index = _this$state.index;
|
1726 | if (!props || Object.keys(props).length === 0) return null;
|
1727 |
|
1728 | let _this$props2 = this.props,
|
1729 | state = _this$props2.state,
|
1730 | filter = _this$props2.filter,
|
1731 | states = _this$props2.states,
|
1732 | config = _this$props2.config,
|
1733 | Component = _this$props2.primitive,
|
1734 | _onRest = _this$props2.onRest,
|
1735 | forwardRef = _this$props2.forwardRef,
|
1736 | rest = _objectWithoutPropertiesLoose(_this$props2, ["state", "filter", "states", "config", "primitive", "onRest", "forwardRef"]);
|
1737 |
|
1738 |
|
1739 | if (Array.isArray(config)) config = config[index];
|
1740 | return React__default.createElement(Component, _extends({
|
1741 | ref: _ref => this.instance = handleRef(_ref, forwardRef),
|
1742 | config: config
|
1743 | }, rest, props, {
|
1744 | onRest: args => {
|
1745 | resolve(args);
|
1746 | if (_onRest && last) _onRest(args);
|
1747 | }
|
1748 | }));
|
1749 | }
|
1750 |
|
1751 | }
|
1752 |
|
1753 | KeyframesImpl.defaultProps = {
|
1754 | state: DEFAULT
|
1755 | };
|
1756 | const Keyframes = React__default.forwardRef((props, ref) => React__default.createElement(KeyframesImpl, _extends({}, props, {
|
1757 | forwardRef: ref
|
1758 | })));
|
1759 |
|
1760 | Keyframes.create = primitive => function (states, filter) {
|
1761 | if (filter === void 0) {
|
1762 | filter = states => states;
|
1763 | }
|
1764 |
|
1765 | if (typeof states === 'function' || Array.isArray(states)) states = {
|
1766 | [DEFAULT]: states
|
1767 | };
|
1768 | return props => React__default.createElement(KeyframesImpl, _extends({
|
1769 | primitive: primitive,
|
1770 | states: states,
|
1771 | filter: filter
|
1772 | }, props));
|
1773 | };
|
1774 |
|
1775 | Keyframes.Spring = states => Keyframes.create(Spring)(states, interpolateTo);
|
1776 |
|
1777 | Keyframes.Trail = states => Keyframes.create(Trail)(states, interpolateTo);
|
1778 |
|
1779 | let guid = 0;
|
1780 |
|
1781 | let get = props => {
|
1782 | let items = props.items,
|
1783 | keys = props.keys,
|
1784 | rest = _objectWithoutPropertiesLoose(props, ["items", "keys"]);
|
1785 |
|
1786 | items = toArray(items !== void 0 ? items : null);
|
1787 | keys = typeof keys === 'function' ? items.map(keys) : toArray(keys);
|
1788 |
|
1789 | return _extends({
|
1790 | items,
|
1791 | keys: keys.map(key => String(key))
|
1792 | }, rest);
|
1793 | };
|
1794 |
|
1795 | class Transition extends React__default.PureComponent {
|
1796 | componentDidMount() {
|
1797 | this.mounted = true;
|
1798 | }
|
1799 |
|
1800 | componentWillUnmount() {
|
1801 | this.mounted = false;
|
1802 | }
|
1803 |
|
1804 | constructor(prevProps) {
|
1805 | super(prevProps);
|
1806 |
|
1807 | this.destroyItem = (item, key, state) => values => {
|
1808 | const _this$props = this.props,
|
1809 | onRest = _this$props.onRest,
|
1810 | onDestroyed = _this$props.onDestroyed;
|
1811 |
|
1812 | if (this.mounted) {
|
1813 | onDestroyed && onDestroyed(item);
|
1814 | this.setState((_ref) => {
|
1815 | let deleted = _ref.deleted;
|
1816 | return {
|
1817 | deleted: deleted.filter(t => t.key !== key)
|
1818 | };
|
1819 | });
|
1820 | onRest && onRest(item, state, values);
|
1821 | }
|
1822 | };
|
1823 |
|
1824 | this.state = {
|
1825 | first: true,
|
1826 | transitions: [],
|
1827 | current: {},
|
1828 | deleted: [],
|
1829 | prevProps
|
1830 | };
|
1831 | }
|
1832 |
|
1833 | static getDerivedStateFromProps(props, _ref2) {
|
1834 | let first = _ref2.first,
|
1835 | prevProps = _ref2.prevProps,
|
1836 | state = _objectWithoutPropertiesLoose(_ref2, ["first", "prevProps"]);
|
1837 |
|
1838 | let _get = get(props),
|
1839 | items = _get.items,
|
1840 | keys = _get.keys,
|
1841 | initial = _get.initial,
|
1842 | from = _get.from,
|
1843 | enter = _get.enter,
|
1844 | leave = _get.leave,
|
1845 | update = _get.update,
|
1846 | _get$trail = _get.trail,
|
1847 | trail = _get$trail === void 0 ? 0 : _get$trail,
|
1848 | unique = _get.unique,
|
1849 | config = _get.config;
|
1850 |
|
1851 | let _get2 = get(prevProps),
|
1852 | _keys = _get2.keys,
|
1853 | _items = _get2.items;
|
1854 |
|
1855 | let current = _extends({}, state.current);
|
1856 |
|
1857 | let deleted = [...state.deleted];
|
1858 |
|
1859 | let currentKeys = Object.keys(current);
|
1860 | let currentSet = new Set(currentKeys);
|
1861 | let nextSet = new Set(keys);
|
1862 | let added = keys.filter(item => !currentSet.has(item));
|
1863 | let removed = state.transitions.filter(item => !item.destroyed && !nextSet.has(item.originalKey)).map(i => i.originalKey);
|
1864 | let updated = keys.filter(item => currentSet.has(item));
|
1865 | let delay = 0;
|
1866 | added.forEach(key => {
|
1867 |
|
1868 | if (unique && deleted.find(d => d.originalKey === key)) deleted = deleted.filter(t => t.originalKey !== key);
|
1869 | const keyIndex = keys.indexOf(key);
|
1870 | const item = items[keyIndex];
|
1871 | const state = 'enter';
|
1872 | current[key] = {
|
1873 | state,
|
1874 | originalKey: key,
|
1875 | key: unique ? String(key) : guid++,
|
1876 | item,
|
1877 | trail: delay = delay + trail,
|
1878 | config: callProp(config, item, state),
|
1879 | from: callProp(first ? initial !== void 0 ? initial || {} : from : from, item),
|
1880 | to: callProp(enter, item)
|
1881 | };
|
1882 | });
|
1883 | removed.forEach(key => {
|
1884 | const keyIndex = _keys.indexOf(key);
|
1885 |
|
1886 | const item = _items[keyIndex];
|
1887 | const state = 'leave';
|
1888 | deleted.push(_extends({}, current[key], {
|
1889 | state,
|
1890 | destroyed: true,
|
1891 | left: _keys[Math.max(0, keyIndex - 1)],
|
1892 | right: _keys[Math.min(_keys.length, keyIndex + 1)],
|
1893 | trail: delay = delay + trail,
|
1894 | config: callProp(config, item, state),
|
1895 | to: callProp(leave, item)
|
1896 | }));
|
1897 | delete current[key];
|
1898 | });
|
1899 | updated.forEach(key => {
|
1900 | const keyIndex = keys.indexOf(key);
|
1901 | const item = items[keyIndex];
|
1902 | const state = 'update';
|
1903 | current[key] = _extends({}, current[key], {
|
1904 | item,
|
1905 | state,
|
1906 | trail: delay = delay + trail,
|
1907 | config: callProp(config, item, state),
|
1908 | to: callProp(update, item)
|
1909 | });
|
1910 | });
|
1911 |
|
1912 | let out = keys.map(key => current[key]);
|
1913 | deleted.forEach((_ref3) => {
|
1914 | let left = _ref3.left,
|
1915 | right = _ref3.right,
|
1916 | transition = _objectWithoutPropertiesLoose(_ref3, ["left", "right"]);
|
1917 |
|
1918 | let pos;
|
1919 |
|
1920 | if ((pos = out.findIndex(t => t.originalKey === left)) !== -1) pos += 1;
|
1921 |
|
1922 | if (pos === -1) pos = out.findIndex(t => t.originalKey === right);
|
1923 |
|
1924 | if (pos === -1) pos = deleted.findIndex(t => t.originalKey === left);
|
1925 |
|
1926 | if (pos === -1) pos = deleted.findIndex(t => t.originalKey === right);
|
1927 |
|
1928 | pos = Math.max(0, pos);
|
1929 | out = [...out.slice(0, pos), transition, ...out.slice(pos)];
|
1930 | });
|
1931 | return {
|
1932 | first: first && added.length === 0,
|
1933 | transitions: out,
|
1934 | current,
|
1935 | deleted,
|
1936 | prevProps: props
|
1937 | };
|
1938 | }
|
1939 |
|
1940 | render() {
|
1941 | const _this$props2 = this.props,
|
1942 | initial = _this$props2.initial,
|
1943 | _this$props2$from = _this$props2.from,
|
1944 | _this$props2$enter = _this$props2.enter,
|
1945 | _this$props2$leave = _this$props2.leave,
|
1946 | _this$props2$update = _this$props2.update,
|
1947 | onDestroyed = _this$props2.onDestroyed,
|
1948 | keys = _this$props2.keys,
|
1949 | items = _this$props2.items,
|
1950 | onFrame = _this$props2.onFrame,
|
1951 | onRest = _this$props2.onRest,
|
1952 | onStart = _this$props2.onStart,
|
1953 | trail = _this$props2.trail,
|
1954 | config = _this$props2.config,
|
1955 | _children = _this$props2.children,
|
1956 | unique = _this$props2.unique,
|
1957 | reset = _this$props2.reset,
|
1958 | extra = _objectWithoutPropertiesLoose(_this$props2, ["initial", "from", "enter", "leave", "update", "onDestroyed", "keys", "items", "onFrame", "onRest", "onStart", "trail", "config", "children", "unique", "reset"]);
|
1959 |
|
1960 | return this.state.transitions.map((_ref4, i) => {
|
1961 | let state = _ref4.state,
|
1962 | key = _ref4.key,
|
1963 | item = _ref4.item,
|
1964 | from = _ref4.from,
|
1965 | to = _ref4.to,
|
1966 | trail = _ref4.trail,
|
1967 | config = _ref4.config,
|
1968 | destroyed = _ref4.destroyed;
|
1969 | return React__default.createElement(Keyframes, _extends({
|
1970 | reset: reset && state === 'enter',
|
1971 | primitive: Spring,
|
1972 | state: state,
|
1973 | filter: interpolateTo,
|
1974 | states: {
|
1975 | [state]: to
|
1976 | },
|
1977 | key: key,
|
1978 | onRest: destroyed ? this.destroyItem(item, key, state) : onRest && (values => onRest(item, state, values)),
|
1979 | onStart: onStart && (() => onStart(item, state)),
|
1980 | onFrame: onFrame && (values => onFrame(item, state, values)),
|
1981 | delay: trail,
|
1982 | config: config
|
1983 | }, extra, {
|
1984 | from: from,
|
1985 | children: props => {
|
1986 | const child = _children(item, state, i);
|
1987 |
|
1988 | return child ? child(props) : null;
|
1989 | }
|
1990 | }));
|
1991 | });
|
1992 | }
|
1993 |
|
1994 | }
|
1995 | Transition.defaultProps = {
|
1996 | keys: item => item,
|
1997 | unique: false,
|
1998 | reset: false
|
1999 | };
|
2000 |
|
2001 | const domElements = ['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'big', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'marquee', 'menu', 'menuitem', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr',
|
2002 | 'circle', 'clipPath', 'defs', 'ellipse', 'foreignObject', 'g', 'image', 'line', 'linearGradient', 'mask', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'stop', 'svg', 'text', 'tspan'];
|
2003 | const extendedAnimated = domElements.reduce((acc, element) => {
|
2004 | acc[element] = createAnimatedComponent(element);
|
2005 | return acc;
|
2006 | }, createAnimatedComponent);
|
2007 |
|
2008 | exports.Spring = Spring;
|
2009 | exports.Keyframes = Keyframes;
|
2010 | exports.Transition = Transition;
|
2011 | exports.Trail = Trail;
|
2012 | exports.Controller = Controller;
|
2013 | exports.config = config;
|
2014 | exports.animated = extendedAnimated;
|
2015 | exports.interpolate = interpolate$1;
|
2016 | exports.Globals = Globals;
|