UNPKG

69.1 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, '__esModule', { value: true });
4
5function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
7var _extends = _interopDefault(require('@babel/runtime/helpers/extends'));
8var reactNative = require('react-native');
9var _inheritsLoose = _interopDefault(require('@babel/runtime/helpers/inheritsLoose'));
10var _assertThisInitialized = _interopDefault(require('@babel/runtime/helpers/assertThisInitialized'));
11var _objectWithoutPropertiesLoose = _interopDefault(require('@babel/runtime/helpers/objectWithoutPropertiesLoose'));
12var React = require('react');
13var React__default = _interopDefault(React);
14
15var Animated =
16/*#__PURE__*/
17function () {
18 function Animated() {
19 this.payload = void 0;
20 this.children = [];
21 }
22
23 var _proto = Animated.prototype;
24
25 _proto.getAnimatedValue = function getAnimatedValue() {
26 return this.getValue();
27 };
28
29 _proto.getPayload = function getPayload() {
30 return this.payload || this;
31 };
32
33 _proto.attach = function attach() {};
34
35 _proto.detach = function detach() {};
36
37 _proto.getChildren = function getChildren() {
38 return this.children;
39 };
40
41 _proto.addChild = function addChild(child) {
42 if (this.children.length === 0) this.attach();
43 this.children.push(child);
44 };
45
46 _proto.removeChild = function removeChild(child) {
47 var index = this.children.indexOf(child);
48 this.children.splice(index, 1);
49 if (this.children.length === 0) this.detach();
50 };
51
52 return Animated;
53}();
54var AnimatedArray =
55/*#__PURE__*/
56function (_Animated) {
57 _inheritsLoose(AnimatedArray, _Animated);
58
59 function AnimatedArray() {
60 var _this;
61
62 for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
63 args[_key] = arguments[_key];
64 }
65
66 _this = _Animated.call.apply(_Animated, [this].concat(args)) || this;
67 _this.payload = [];
68
69 _this.attach = function () {
70 return _this.payload.forEach(function (p) {
71 return p instanceof Animated && p.addChild(_assertThisInitialized(_assertThisInitialized(_this)));
72 });
73 };
74
75 _this.detach = function () {
76 return _this.payload.forEach(function (p) {
77 return p instanceof Animated && p.removeChild(_assertThisInitialized(_assertThisInitialized(_this)));
78 });
79 };
80
81 return _this;
82 }
83
84 return AnimatedArray;
85}(Animated);
86var AnimatedObject =
87/*#__PURE__*/
88function (_Animated2) {
89 _inheritsLoose(AnimatedObject, _Animated2);
90
91 function AnimatedObject() {
92 var _this2;
93
94 for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
95 args[_key3] = arguments[_key3];
96 }
97
98 _this2 = _Animated2.call.apply(_Animated2, [this].concat(args)) || this;
99 _this2.payload = {};
100
101 _this2.attach = function () {
102 return Object.values(_this2.payload).forEach(function (s) {
103 return s instanceof Animated && s.addChild(_assertThisInitialized(_assertThisInitialized(_this2)));
104 });
105 };
106
107 _this2.detach = function () {
108 return Object.values(_this2.payload).forEach(function (s) {
109 return s instanceof Animated && s.removeChild(_assertThisInitialized(_assertThisInitialized(_this2)));
110 });
111 };
112
113 return _this2;
114 }
115
116 var _proto2 = AnimatedObject.prototype;
117
118 _proto2.getValue = function getValue(animated) {
119 if (animated === void 0) {
120 animated = false;
121 }
122
123 var payload = {};
124
125 for (var _key4 in this.payload) {
126 var value = this.payload[_key4];
127 if (animated && !(value instanceof Animated)) continue;
128 payload[_key4] = value instanceof Animated ? value[animated ? 'getAnimatedValue' : 'getValue']() : value;
129 }
130
131 return payload;
132 };
133
134 _proto2.getAnimatedValue = function getAnimatedValue() {
135 return this.getValue(true);
136 };
137
138 return AnimatedObject;
139}(Animated);
140
141var applyAnimatedValues;
142function injectApplyAnimatedValues(fn, transform) {
143 applyAnimatedValues = {
144 fn: fn,
145 transform: transform
146 };
147}
148var colorNames;
149function injectColorNames(names) {
150 colorNames = names;
151}
152var requestFrame = function requestFrame(cb) {
153 return typeof window !== 'undefined' ? window.requestAnimationFrame(cb) : -1;
154};
155var cancelFrame = function cancelFrame(id) {
156 typeof window !== 'undefined' && window.cancelAnimationFrame(id);
157};
158function injectFrame(raf, caf) {
159 requestFrame = raf;
160 cancelFrame = caf;
161}
162var interpolation;
163function injectStringInterpolator(fn) {
164 interpolation = fn;
165}
166var now = function now() {
167 return Date.now();
168};
169function injectNow(nowFn) {
170 now = nowFn;
171}
172var defaultElement;
173function injectDefaultElement(el) {
174 defaultElement = el;
175}
176var animatedApi = function animatedApi(node) {
177 return node.current;
178};
179function injectAnimatedApi(fn) {
180 animatedApi = fn;
181}
182var createAnimatedStyle;
183function injectCreateAnimatedStyle(factory) {
184 createAnimatedStyle = factory;
185}
186var manualFrameloop = false;
187function injectManualFrameloop(manual) {
188 manualFrameloop = manual;
189}
190
191var Globals = /*#__PURE__*/Object.freeze({
192 get applyAnimatedValues () { return applyAnimatedValues; },
193 injectApplyAnimatedValues: injectApplyAnimatedValues,
194 get colorNames () { return colorNames; },
195 injectColorNames: injectColorNames,
196 get requestFrame () { return requestFrame; },
197 get cancelFrame () { return cancelFrame; },
198 injectFrame: injectFrame,
199 get interpolation () { return interpolation; },
200 injectStringInterpolator: injectStringInterpolator,
201 get now () { return now; },
202 injectNow: injectNow,
203 get defaultElement () { return defaultElement; },
204 injectDefaultElement: injectDefaultElement,
205 get animatedApi () { return animatedApi; },
206 injectAnimatedApi: injectAnimatedApi,
207 get createAnimatedStyle () { return createAnimatedStyle; },
208 injectCreateAnimatedStyle: injectCreateAnimatedStyle,
209 get manualFrameloop () { return manualFrameloop; },
210 injectManualFrameloop: injectManualFrameloop
211});
212
213var AnimatedStyle =
214/*#__PURE__*/
215function (_AnimatedObject) {
216 _inheritsLoose(AnimatedStyle, _AnimatedObject);
217
218 function AnimatedStyle(style) {
219 var _this;
220
221 if (style === void 0) {
222 style = {};
223 }
224
225 _this = _AnimatedObject.call(this) || this;
226
227 if (style.transform && !(style.transform instanceof Animated)) {
228 style = applyAnimatedValues.transform(style);
229 }
230
231 _this.payload = style;
232 return _this;
233 }
234
235 return AnimatedStyle;
236}(AnimatedObject);
237
238var is = {
239 arr: Array.isArray,
240 obj: function obj(a) {
241 return Object.prototype.toString.call(a) === '[object Object]';
242 },
243 fun: function fun(a) {
244 return typeof a === 'function';
245 },
246 str: function str(a) {
247 return typeof a === 'string';
248 },
249 num: function num(a) {
250 return typeof a === 'number';
251 },
252 und: function und(a) {
253 return a === void 0;
254 },
255 nul: function nul(a) {
256 return a === null;
257 },
258 set: function set(a) {
259 return a instanceof Set;
260 },
261 map: function map(a) {
262 return a instanceof Map;
263 },
264 equ: function equ(a, b) {
265 if (typeof a !== typeof b) return false;
266 if (is.str(a) || is.num(a)) return a === b;
267 if (is.obj(a) && is.obj(b) && Object.keys(a).length + Object.keys(b).length === 0) return true;
268 var i;
269
270 for (i in a) {
271 if (!(i in b)) return false;
272 }
273
274 for (i in b) {
275 if (a[i] !== b[i]) return false;
276 }
277
278 return is.und(i) ? a === b : true;
279 }
280};
281function merge(target, lowercase) {
282 if (lowercase === void 0) {
283 lowercase = true;
284 }
285
286 return function (object) {
287 return (is.arr(object) ? object : Object.keys(object)).reduce(function (acc, element) {
288 var key = lowercase ? element[0].toLowerCase() + element.substring(1) : element;
289 acc[key] = target(key);
290 return acc;
291 }, target);
292 };
293}
294function useForceUpdate() {
295 var _useState = React.useState(false),
296 f = _useState[1];
297
298 var forceUpdate = React.useCallback(function () {
299 return f(function (v) {
300 return !v;
301 });
302 }, []);
303 return forceUpdate;
304}
305function withDefault(value, defaultValue) {
306 return is.und(value) || is.nul(value) ? defaultValue : value;
307}
308function toArray(a) {
309 return !is.und(a) ? is.arr(a) ? a : [a] : [];
310}
311function callProp(obj) {
312 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
313 args[_key - 1] = arguments[_key];
314 }
315
316 return is.fun(obj) ? obj.apply(void 0, args) : obj;
317}
318
319function getForwardProps(props) {
320 var to = props.to,
321 from = props.from,
322 config = props.config,
323 onStart = props.onStart,
324 onRest = props.onRest,
325 onFrame = props.onFrame,
326 children = props.children,
327 reset = props.reset,
328 reverse = props.reverse,
329 force = props.force,
330 immediate = props.immediate,
331 delay = props.delay,
332 attach = props.attach,
333 destroyed = props.destroyed,
334 interpolateTo = props.interpolateTo,
335 ref = props.ref,
336 lazy = props.lazy,
337 forward = _objectWithoutPropertiesLoose(props, ["to", "from", "config", "onStart", "onRest", "onFrame", "children", "reset", "reverse", "force", "immediate", "delay", "attach", "destroyed", "interpolateTo", "ref", "lazy"]);
338
339 return forward;
340}
341
342function interpolateTo(props) {
343 var forward = getForwardProps(props);
344 if (is.und(forward)) return _extends({
345 to: forward
346 }, props);
347 var rest = Object.keys(props).reduce(function (a, k) {
348 var _extends2;
349
350 return !is.und(forward[k]) ? a : _extends({}, a, (_extends2 = {}, _extends2[k] = props[k], _extends2));
351 }, {});
352 return _extends({
353 to: forward
354 }, rest);
355}
356function handleRef(ref, forward) {
357 if (forward) {
358 // If it's a function, assume it's a ref callback
359 if (is.fun(forward)) forward(ref);else if (is.obj(forward)) {
360 forward.current = ref;
361 }
362 }
363
364 return ref;
365}
366
367/**
368 * Wraps the `style` property with `AnimatedStyle`.
369 */
370
371var AnimatedProps =
372/*#__PURE__*/
373function (_AnimatedObject) {
374 _inheritsLoose(AnimatedProps, _AnimatedObject);
375
376 function AnimatedProps(props, callback) {
377 var _this;
378
379 _this = _AnimatedObject.call(this) || this;
380 _this.update = void 0;
381 _this.payload = !props.style ? props : _extends({}, props, {
382 style: createAnimatedStyle(props.style)
383 });
384 _this.update = callback;
385
386 _this.attach();
387
388 return _this;
389 }
390
391 return AnimatedProps;
392}(AnimatedObject);
393
394var createAnimatedComponent = function createAnimatedComponent(Component) {
395 var AnimatedComponent = React.forwardRef(function (props, _ref) {
396 var forceUpdate = useForceUpdate();
397 var mounted = React.useRef(true);
398 var propsAnimated = React.useRef(null);
399 var node = React.useRef(null);
400 var attachProps = React.useCallback(function (props) {
401 var oldPropsAnimated = propsAnimated.current;
402
403 var callback = function callback() {
404 if (node.current) {
405 var didUpdate = applyAnimatedValues.fn(node.current, propsAnimated.current.getAnimatedValue());
406 if (didUpdate === false) forceUpdate();
407 }
408 };
409
410 propsAnimated.current = new AnimatedProps(props, callback);
411 oldPropsAnimated && oldPropsAnimated.detach();
412 }, []);
413 React.useEffect(function () {
414 return function () {
415 mounted.current = false;
416 propsAnimated.current && propsAnimated.current.detach();
417 };
418 }, []);
419 React.useImperativeHandle(_ref, function () {
420 return animatedApi(node, mounted, forceUpdate);
421 });
422 attachProps(props);
423
424 var _getValue = propsAnimated.current.getValue(),
425 scrollTop = _getValue.scrollTop,
426 scrollLeft = _getValue.scrollLeft,
427 animatedProps = _objectWithoutPropertiesLoose(_getValue, ["scrollTop", "scrollLeft"]);
428
429 return React__default.createElement(Component, _extends({}, animatedProps, {
430 ref: function ref(childRef) {
431 return node.current = handleRef(childRef, _ref);
432 }
433 }));
434 });
435 return AnimatedComponent;
436};
437
438function createInterpolator(range, output, extrapolate) {
439 if (typeof range === 'function') {
440 return range;
441 }
442
443 if (Array.isArray(range)) {
444 return createInterpolator({
445 range: range,
446 output: output,
447 extrapolate: extrapolate
448 });
449 }
450
451 if (interpolation && typeof range.output[0] === 'string') {
452 return interpolation(range);
453 }
454
455 var config = range;
456 var outputRange = config.output;
457 var inputRange = config.range || [0, 1];
458 var extrapolateLeft = config.extrapolateLeft || config.extrapolate || 'extend';
459 var extrapolateRight = config.extrapolateRight || config.extrapolate || 'extend';
460
461 var easing = config.easing || function (t) {
462 return t;
463 };
464
465 return function (input) {
466 var range = findRange(input, inputRange);
467 return interpolate(input, inputRange[range], inputRange[range + 1], outputRange[range], outputRange[range + 1], easing, extrapolateLeft, extrapolateRight, config.map);
468 };
469}
470
471function interpolate(input, inputMin, inputMax, outputMin, outputMax, easing, extrapolateLeft, extrapolateRight, map) {
472 var result = map ? map(input) : input; // Extrapolate
473
474 if (result < inputMin) {
475 if (extrapolateLeft === 'identity') return result;else if (extrapolateLeft === 'clamp') result = inputMin;
476 }
477
478 if (result > inputMax) {
479 if (extrapolateRight === 'identity') return result;else if (extrapolateRight === 'clamp') result = inputMax;
480 }
481
482 if (outputMin === outputMax) return outputMin;
483 if (inputMin === inputMax) return input <= inputMin ? outputMin : outputMax; // Input Range
484
485 if (inputMin === -Infinity) result = -result;else if (inputMax === Infinity) result = result - inputMin;else result = (result - inputMin) / (inputMax - inputMin); // Easing
486
487 result = easing(result); // Output Range
488
489 if (outputMin === -Infinity) result = -result;else if (outputMax === Infinity) result = result + outputMin;else result = result * (outputMax - outputMin) + outputMin;
490 return result;
491}
492
493function findRange(input, inputRange) {
494 for (var i = 1; i < inputRange.length - 1; ++i) {
495 if (inputRange[i] >= input) break;
496 }
497
498 return i - 1;
499}
500
501var AnimatedInterpolation =
502/*#__PURE__*/
503function (_AnimatedArray) {
504 _inheritsLoose(AnimatedInterpolation, _AnimatedArray);
505
506 function AnimatedInterpolation(parents, range, output) {
507 var _this;
508
509 _this = _AnimatedArray.call(this) || this;
510 _this.calc = void 0;
511 _this.payload = parents instanceof AnimatedArray && !(parents instanceof AnimatedInterpolation) ? parents.getPayload() : Array.isArray(parents) ? parents : [parents];
512 _this.calc = createInterpolator(range, output);
513 return _this;
514 }
515
516 var _proto = AnimatedInterpolation.prototype;
517
518 _proto.getValue = function getValue() {
519 return this.calc.apply(this, this.payload.map(function (value) {
520 return value.getValue();
521 }));
522 };
523
524 _proto.updateConfig = function updateConfig(range, output) {
525 this.calc = createInterpolator(range, output);
526 };
527
528 _proto.interpolate = function interpolate(range, output) {
529 return new AnimatedInterpolation(this, range, output);
530 };
531
532 return AnimatedInterpolation;
533}(AnimatedArray);
534
535var interpolate$1 = function interpolate(parents, range, output) {
536 return parents && new AnimatedInterpolation(parents, range, output);
537};
538
539// http://www.w3.org/TR/css3-color/#svg-color
540var colors = {
541 transparent: 0x00000000,
542 aliceblue: 0xf0f8ffff,
543 antiquewhite: 0xfaebd7ff,
544 aqua: 0x00ffffff,
545 aquamarine: 0x7fffd4ff,
546 azure: 0xf0ffffff,
547 beige: 0xf5f5dcff,
548 bisque: 0xffe4c4ff,
549 black: 0x000000ff,
550 blanchedalmond: 0xffebcdff,
551 blue: 0x0000ffff,
552 blueviolet: 0x8a2be2ff,
553 brown: 0xa52a2aff,
554 burlywood: 0xdeb887ff,
555 burntsienna: 0xea7e5dff,
556 cadetblue: 0x5f9ea0ff,
557 chartreuse: 0x7fff00ff,
558 chocolate: 0xd2691eff,
559 coral: 0xff7f50ff,
560 cornflowerblue: 0x6495edff,
561 cornsilk: 0xfff8dcff,
562 crimson: 0xdc143cff,
563 cyan: 0x00ffffff,
564 darkblue: 0x00008bff,
565 darkcyan: 0x008b8bff,
566 darkgoldenrod: 0xb8860bff,
567 darkgray: 0xa9a9a9ff,
568 darkgreen: 0x006400ff,
569 darkgrey: 0xa9a9a9ff,
570 darkkhaki: 0xbdb76bff,
571 darkmagenta: 0x8b008bff,
572 darkolivegreen: 0x556b2fff,
573 darkorange: 0xff8c00ff,
574 darkorchid: 0x9932ccff,
575 darkred: 0x8b0000ff,
576 darksalmon: 0xe9967aff,
577 darkseagreen: 0x8fbc8fff,
578 darkslateblue: 0x483d8bff,
579 darkslategray: 0x2f4f4fff,
580 darkslategrey: 0x2f4f4fff,
581 darkturquoise: 0x00ced1ff,
582 darkviolet: 0x9400d3ff,
583 deeppink: 0xff1493ff,
584 deepskyblue: 0x00bfffff,
585 dimgray: 0x696969ff,
586 dimgrey: 0x696969ff,
587 dodgerblue: 0x1e90ffff,
588 firebrick: 0xb22222ff,
589 floralwhite: 0xfffaf0ff,
590 forestgreen: 0x228b22ff,
591 fuchsia: 0xff00ffff,
592 gainsboro: 0xdcdcdcff,
593 ghostwhite: 0xf8f8ffff,
594 gold: 0xffd700ff,
595 goldenrod: 0xdaa520ff,
596 gray: 0x808080ff,
597 green: 0x008000ff,
598 greenyellow: 0xadff2fff,
599 grey: 0x808080ff,
600 honeydew: 0xf0fff0ff,
601 hotpink: 0xff69b4ff,
602 indianred: 0xcd5c5cff,
603 indigo: 0x4b0082ff,
604 ivory: 0xfffff0ff,
605 khaki: 0xf0e68cff,
606 lavender: 0xe6e6faff,
607 lavenderblush: 0xfff0f5ff,
608 lawngreen: 0x7cfc00ff,
609 lemonchiffon: 0xfffacdff,
610 lightblue: 0xadd8e6ff,
611 lightcoral: 0xf08080ff,
612 lightcyan: 0xe0ffffff,
613 lightgoldenrodyellow: 0xfafad2ff,
614 lightgray: 0xd3d3d3ff,
615 lightgreen: 0x90ee90ff,
616 lightgrey: 0xd3d3d3ff,
617 lightpink: 0xffb6c1ff,
618 lightsalmon: 0xffa07aff,
619 lightseagreen: 0x20b2aaff,
620 lightskyblue: 0x87cefaff,
621 lightslategray: 0x778899ff,
622 lightslategrey: 0x778899ff,
623 lightsteelblue: 0xb0c4deff,
624 lightyellow: 0xffffe0ff,
625 lime: 0x00ff00ff,
626 limegreen: 0x32cd32ff,
627 linen: 0xfaf0e6ff,
628 magenta: 0xff00ffff,
629 maroon: 0x800000ff,
630 mediumaquamarine: 0x66cdaaff,
631 mediumblue: 0x0000cdff,
632 mediumorchid: 0xba55d3ff,
633 mediumpurple: 0x9370dbff,
634 mediumseagreen: 0x3cb371ff,
635 mediumslateblue: 0x7b68eeff,
636 mediumspringgreen: 0x00fa9aff,
637 mediumturquoise: 0x48d1ccff,
638 mediumvioletred: 0xc71585ff,
639 midnightblue: 0x191970ff,
640 mintcream: 0xf5fffaff,
641 mistyrose: 0xffe4e1ff,
642 moccasin: 0xffe4b5ff,
643 navajowhite: 0xffdeadff,
644 navy: 0x000080ff,
645 oldlace: 0xfdf5e6ff,
646 olive: 0x808000ff,
647 olivedrab: 0x6b8e23ff,
648 orange: 0xffa500ff,
649 orangered: 0xff4500ff,
650 orchid: 0xda70d6ff,
651 palegoldenrod: 0xeee8aaff,
652 palegreen: 0x98fb98ff,
653 paleturquoise: 0xafeeeeff,
654 palevioletred: 0xdb7093ff,
655 papayawhip: 0xffefd5ff,
656 peachpuff: 0xffdab9ff,
657 peru: 0xcd853fff,
658 pink: 0xffc0cbff,
659 plum: 0xdda0ddff,
660 powderblue: 0xb0e0e6ff,
661 purple: 0x800080ff,
662 rebeccapurple: 0x663399ff,
663 red: 0xff0000ff,
664 rosybrown: 0xbc8f8fff,
665 royalblue: 0x4169e1ff,
666 saddlebrown: 0x8b4513ff,
667 salmon: 0xfa8072ff,
668 sandybrown: 0xf4a460ff,
669 seagreen: 0x2e8b57ff,
670 seashell: 0xfff5eeff,
671 sienna: 0xa0522dff,
672 silver: 0xc0c0c0ff,
673 skyblue: 0x87ceebff,
674 slateblue: 0x6a5acdff,
675 slategray: 0x708090ff,
676 slategrey: 0x708090ff,
677 snow: 0xfffafaff,
678 springgreen: 0x00ff7fff,
679 steelblue: 0x4682b4ff,
680 tan: 0xd2b48cff,
681 teal: 0x008080ff,
682 thistle: 0xd8bfd8ff,
683 tomato: 0xff6347ff,
684 turquoise: 0x40e0d0ff,
685 violet: 0xee82eeff,
686 wheat: 0xf5deb3ff,
687 white: 0xffffffff,
688 whitesmoke: 0xf5f5f5ff,
689 yellow: 0xffff00ff,
690 yellowgreen: 0x9acd32ff
691};
692
693var config = {
694 default: {
695 tension: 170,
696 friction: 26
697 },
698 gentle: {
699 tension: 120,
700 friction: 14
701 },
702 wobbly: {
703 tension: 180,
704 friction: 12
705 },
706 stiff: {
707 tension: 210,
708 friction: 20
709 },
710 slow: {
711 tension: 280,
712 friction: 60
713 },
714 molasses: {
715 tension: 280,
716 friction: 120
717 }
718};
719
720// const INTEGER = '[-+]?\\d+';
721var NUMBER = '[-+]?\\d*\\.?\\d+';
722var PERCENTAGE = NUMBER + '%';
723
724function call() {
725 for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
726 parts[_key] = arguments[_key];
727 }
728
729 return '\\(\\s*(' + parts.join(')\\s*,\\s*(') + ')\\s*\\)';
730}
731
732var rgb = new RegExp('rgb' + call(NUMBER, NUMBER, NUMBER));
733var rgba = new RegExp('rgba' + call(NUMBER, NUMBER, NUMBER, NUMBER));
734var hsl = new RegExp('hsl' + call(NUMBER, PERCENTAGE, PERCENTAGE));
735var hsla = new RegExp('hsla' + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER));
736var hex3 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
737var hex4 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
738var hex6 = /^#([0-9a-fA-F]{6})$/;
739var hex8 = /^#([0-9a-fA-F]{8})$/;
740
741/*
742https://github.com/react-community/normalize-css-color
743
744BSD 3-Clause License
745
746Copyright (c) 2016, React Community
747All rights reserved.
748
749Redistribution and use in source and binary forms, with or without
750modification, are permitted provided that the following conditions are met:
751
752* Redistributions of source code must retain the above copyright notice, this
753 list of conditions and the following disclaimer.
754
755* Redistributions in binary form must reproduce the above copyright notice,
756 this list of conditions and the following disclaimer in the documentation
757 and/or other materials provided with the distribution.
758
759* Neither the name of the copyright holder nor the names of its
760 contributors may be used to endorse or promote products derived from
761 this software without specific prior written permission.
762
763THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
764AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
765IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
766DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
767FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
768DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
769SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
770CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
771OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
772OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
773*/
774function normalizeColor(color) {
775 var match;
776
777 if (typeof color === 'number') {
778 return color >>> 0 === color && color >= 0 && color <= 0xffffffff ? color : null;
779 } // Ordered based on occurrences on Facebook codebase
780
781
782 if (match = hex6.exec(color)) return parseInt(match[1] + 'ff', 16) >>> 0;
783 if (colors.hasOwnProperty(color)) return colors[color];
784
785 if (match = rgb.exec(color)) {
786 return (parse255(match[1]) << 24 | // r
787 parse255(match[2]) << 16 | // g
788 parse255(match[3]) << 8 | // b
789 0x000000ff) >>> // a
790 0;
791 }
792
793 if (match = rgba.exec(color)) {
794 return (parse255(match[1]) << 24 | // r
795 parse255(match[2]) << 16 | // g
796 parse255(match[3]) << 8 | // b
797 parse1(match[4])) >>> // a
798 0;
799 }
800
801 if (match = hex3.exec(color)) {
802 return parseInt(match[1] + match[1] + // r
803 match[2] + match[2] + // g
804 match[3] + match[3] + // b
805 'ff', // a
806 16) >>> 0;
807 } // https://drafts.csswg.org/css-color-4/#hex-notation
808
809
810 if (match = hex8.exec(color)) return parseInt(match[1], 16) >>> 0;
811
812 if (match = hex4.exec(color)) {
813 return parseInt(match[1] + match[1] + // r
814 match[2] + match[2] + // g
815 match[3] + match[3] + // b
816 match[4] + match[4], // a
817 16) >>> 0;
818 }
819
820 if (match = hsl.exec(color)) {
821 return (hslToRgb(parse360(match[1]), // h
822 parsePercentage(match[2]), // s
823 parsePercentage(match[3]) // l
824 ) | 0x000000ff) >>> // a
825 0;
826 }
827
828 if (match = hsla.exec(color)) {
829 return (hslToRgb(parse360(match[1]), // h
830 parsePercentage(match[2]), // s
831 parsePercentage(match[3]) // l
832 ) | parse1(match[4])) >>> // a
833 0;
834 }
835
836 return null;
837}
838
839function hue2rgb(p, q, t) {
840 if (t < 0) t += 1;
841 if (t > 1) t -= 1;
842 if (t < 1 / 6) return p + (q - p) * 6 * t;
843 if (t < 1 / 2) return q;
844 if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
845 return p;
846}
847
848function hslToRgb(h, s, l) {
849 var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
850 var p = 2 * l - q;
851 var r = hue2rgb(p, q, h + 1 / 3);
852 var g = hue2rgb(p, q, h);
853 var b = hue2rgb(p, q, h - 1 / 3);
854 return Math.round(r * 255) << 24 | Math.round(g * 255) << 16 | Math.round(b * 255) << 8;
855}
856
857function parse255(str) {
858 var int = parseInt(str, 10);
859 if (int < 0) return 0;
860 if (int > 255) return 255;
861 return int;
862}
863
864function parse360(str) {
865 var int = parseFloat(str);
866 return (int % 360 + 360) % 360 / 360;
867}
868
869function parse1(str) {
870 var num = parseFloat(str);
871 if (num < 0) return 0;
872 if (num > 1) return 255;
873 return Math.round(num * 255);
874}
875
876function parsePercentage(str) {
877 // parseFloat conveniently ignores the final %
878 var int = parseFloat(str);
879 if (int < 0) return 0;
880 if (int > 100) return 1;
881 return int / 100;
882}
883
884function colorToRgba(input) {
885 var int32Color = normalizeColor(input);
886 if (int32Color === null) return input;
887 int32Color = int32Color || 0;
888 var r = (int32Color & 0xff000000) >>> 24;
889 var g = (int32Color & 0x00ff0000) >>> 16;
890 var b = (int32Color & 0x0000ff00) >>> 8;
891 var a = (int32Color & 0x000000ff) / 255;
892 return "rgba(" + r + ", " + g + ", " + b + ", " + a + ")";
893} // Problem: https://github.com/animatedjs/animated/pull/102
894// Solution: https://stackoverflow.com/questions/638565/parsing-scientific-notation-sensibly/658662
895
896
897var stringShapeRegex = /[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/g; // Covers rgb, rgba, hsl, hsla
898// Taken from https://gist.github.com/olmokramer/82ccce673f86db7cda5e
899
900var colorRegex = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))/gi; // Covers color names (transparent, blue, etc.)
901
902var colorNamesRegex = new RegExp("(" + Object.keys(colors).join('|') + ")", 'g');
903/**
904 * Supports string shapes by extracting numbers so new values can be computed,
905 * and recombines those values into new strings of the same shape. Supports
906 * things like:
907 *
908 * rgba(123, 42, 99, 0.36) // colors
909 * -45deg // values with units
910 * 0 2px 2px 0px rgba(0, 0, 0, 0.12) // box shadows
911 */
912
913var createStringInterpolator = function createStringInterpolator(config) {
914 // Replace colors with rgba
915 var outputRange = config.output.map(function (rangeValue) {
916 return rangeValue.replace(colorRegex, colorToRgba);
917 }).map(function (rangeValue) {
918 return rangeValue.replace(colorNamesRegex, colorToRgba);
919 });
920 var outputRanges = outputRange[0].match(stringShapeRegex).map(function () {
921 return [];
922 });
923 outputRange.forEach(function (value) {
924 value.match(stringShapeRegex).forEach(function (number, i) {
925 return outputRanges[i].push(+number);
926 });
927 });
928 var interpolations = outputRange[0].match(stringShapeRegex).map(function (_value, i) {
929 return createInterpolator(_extends({}, config, {
930 output: outputRanges[i]
931 }));
932 });
933 return function (input) {
934 var i = 0;
935 return outputRange[0] // 'rgba(0, 100, 200, 0)'
936 // ->
937 // 'rgba(${interpolations[0](input)}, ${interpolations[1](input)}, ...'
938 .replace(stringShapeRegex, function () {
939 return interpolations[i++](input);
940 }) // rgba requires that the r,g,b are integers.... so we want to round them, but we *dont* want to
941 // round the opacity (4th column).
942 .replace(/rgba\(([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+)\)/gi, function (_, p1, p2, p3, p4) {
943 return "rgba(" + Math.round(p1) + ", " + Math.round(p2) + ", " + Math.round(p3) + ", " + p4 + ")";
944 });
945 };
946};
947
948/** API
949 * useChain(references, timeSteps, timeFrame)
950 */
951
952function useChain(refs, timeSteps, timeFrame) {
953 if (timeFrame === void 0) {
954 timeFrame = 1000;
955 }
956
957 var previous = React.useRef();
958 React.useEffect(function () {
959 if (is.equ(refs, previous.current)) refs.forEach(function (_ref) {
960 var current = _ref.current;
961 return current && current.start();
962 });else if (timeSteps) {
963 refs.forEach(function (_ref2, index) {
964 var current = _ref2.current;
965
966 if (current) {
967 var ctrls = current.controllers;
968
969 if (ctrls.length) {
970 var t = timeFrame * timeSteps[index];
971 ctrls.forEach(function (ctrl) {
972 ctrl.queue = ctrl.queue.map(function (e) {
973 return _extends({}, e, {
974 delay: e.delay + t
975 });
976 });
977 ctrl.start();
978 });
979 }
980 }
981 });
982 } else refs.reduce(function (q, _ref3, rI) {
983 var current = _ref3.current;
984 return q = q.then(function () {
985 return current.start();
986 });
987 }, Promise.resolve());
988 previous.current = refs;
989 });
990}
991
992/**
993 * Animated works by building a directed acyclic graph of dependencies
994 * transparently when you render your Animated components.
995 *
996 * new Animated.Value(0)
997 * .interpolate() .interpolate() new Animated.Value(1)
998 * opacity translateY scale
999 * style transform
1000 * View#234 style
1001 * View#123
1002 *
1003 * A) Top Down phase
1004 * When an AnimatedValue is updated, we recursively go down through this
1005 * graph in order to find leaf nodes: the views that we flag as needing
1006 * an update.
1007 *
1008 * B) Bottom Up phase
1009 * When a view is flagged as needing an update, we recursively go back up
1010 * in order to build the new value that it needs. The reason why we need
1011 * this two-phases process is to deal with composite props such as
1012 * transform which can receive values from multiple parents.
1013 */
1014function addAnimatedStyles(node, styles) {
1015 if ('update' in node) {
1016 styles.add(node);
1017 } else {
1018 node.getChildren().forEach(function (child) {
1019 return addAnimatedStyles(child, styles);
1020 });
1021 }
1022}
1023
1024var AnimatedValue =
1025/*#__PURE__*/
1026function (_Animated) {
1027 _inheritsLoose(AnimatedValue, _Animated);
1028
1029 function AnimatedValue(_value) {
1030 var _this;
1031
1032 _this = _Animated.call(this) || this;
1033 _this.animatedStyles = new Set();
1034 _this.value = void 0;
1035 _this.startPosition = void 0;
1036 _this.lastPosition = void 0;
1037 _this.lastVelocity = void 0;
1038 _this.startTime = void 0;
1039 _this.lastTime = void 0;
1040 _this.done = false;
1041
1042 _this.setValue = function (value, flush) {
1043 if (flush === void 0) {
1044 flush = true;
1045 }
1046
1047 _this.value = value;
1048 if (flush) _this.flush();
1049 };
1050
1051 _this.value = _value;
1052 _this.startPosition = _value;
1053 _this.lastPosition = _value;
1054 return _this;
1055 }
1056
1057 var _proto = AnimatedValue.prototype;
1058
1059 _proto.flush = function flush() {
1060 if (this.animatedStyles.size === 0) {
1061 addAnimatedStyles(this, this.animatedStyles);
1062 }
1063
1064 this.animatedStyles.forEach(function (animatedStyle) {
1065 return animatedStyle.update();
1066 });
1067 };
1068
1069 _proto.clearStyles = function clearStyles() {
1070 this.animatedStyles.clear();
1071 };
1072
1073 _proto.getValue = function getValue() {
1074 return this.value;
1075 };
1076
1077 _proto.interpolate = function interpolate(range, output) {
1078 return new AnimatedInterpolation(this, range, output);
1079 };
1080
1081 return AnimatedValue;
1082}(Animated);
1083
1084var AnimatedValueArray =
1085/*#__PURE__*/
1086function (_AnimatedArray) {
1087 _inheritsLoose(AnimatedValueArray, _AnimatedArray);
1088
1089 function AnimatedValueArray(values) {
1090 var _this;
1091
1092 _this = _AnimatedArray.call(this) || this;
1093 _this.payload = values.map(function (n) {
1094 return new AnimatedValue(n);
1095 });
1096 return _this;
1097 }
1098
1099 var _proto = AnimatedValueArray.prototype;
1100
1101 _proto.setValue = function setValue(value, flush) {
1102 var _this2 = this;
1103
1104 if (flush === void 0) {
1105 flush = true;
1106 }
1107
1108 if (Array.isArray(value)) {
1109 if (value.length === this.payload.length) {
1110 value.forEach(function (v, i) {
1111 return _this2.payload[i].setValue(v, flush);
1112 });
1113 }
1114 } else {
1115 this.payload.forEach(function (p) {
1116 return p.setValue(value, flush);
1117 });
1118 }
1119 };
1120
1121 _proto.getValue = function getValue() {
1122 return this.payload.map(function (v) {
1123 return v.getValue();
1124 });
1125 };
1126
1127 _proto.interpolate = function interpolate(range, output) {
1128 return new AnimatedInterpolation(this, range, output);
1129 };
1130
1131 return AnimatedValueArray;
1132}(AnimatedArray);
1133
1134var active = false;
1135var controllers = new Set();
1136
1137var update = function update() {
1138 if (!active) return;
1139 var time = now();
1140
1141 for (var _iterator = controllers, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
1142 var _ref;
1143
1144 if (_isArray) {
1145 if (_i >= _iterator.length) break;
1146 _ref = _iterator[_i++];
1147 } else {
1148 _i = _iterator.next();
1149 if (_i.done) break;
1150 _ref = _i.value;
1151 }
1152
1153 var controller = _ref;
1154 var isActive = false;
1155
1156 for (var configIdx = 0; configIdx < controller.configs.length; configIdx++) {
1157 var config = controller.configs[configIdx];
1158 var endOfAnimation = void 0,
1159 lastTime = void 0;
1160
1161 for (var valIdx = 0; valIdx < config.animatedValues.length; valIdx++) {
1162 var animation = config.animatedValues[valIdx]; // If an animation is done, skip, until all of them conclude
1163
1164 if (animation.done) continue;
1165 var from = config.fromValues[valIdx];
1166 var to = config.toValues[valIdx];
1167 var position = animation.lastPosition;
1168 var isAnimated = to instanceof Animated;
1169 var velocity = Array.isArray(config.initialVelocity) ? config.initialVelocity[valIdx] : config.initialVelocity;
1170 if (isAnimated) to = to.getValue(); // Conclude animation if it's either immediate, or from-values match end-state
1171
1172 if (config.immediate) {
1173 animation.setValue(to);
1174 animation.done = true;
1175 continue;
1176 } // Break animation when string values are involved
1177
1178
1179 if (typeof from === 'string' || typeof to === 'string') {
1180 animation.setValue(to);
1181 animation.done = true;
1182 continue;
1183 }
1184
1185 if (config.duration !== void 0) {
1186 /** Duration easing */
1187 position = from + config.easing((time - animation.startTime) / config.duration) * (to - from);
1188 endOfAnimation = time >= animation.startTime + config.duration;
1189 } else if (config.decay) {
1190 /** Decay easing */
1191 position = from + velocity / (1 - 0.998) * (1 - Math.exp(-(1 - 0.998) * (time - controller.startTime)));
1192 endOfAnimation = Math.abs(animation.lastPosition - position) < 0.1;
1193 if (endOfAnimation) to = position;
1194 } else {
1195 /** Spring easing */
1196 lastTime = animation.lastTime !== void 0 ? animation.lastTime : time;
1197 velocity = animation.lastVelocity !== void 0 ? animation.lastVelocity : config.initialVelocity; // If we lost a lot of frames just jump to the end.
1198
1199 if (time > lastTime + 64) lastTime = time; // http://gafferongames.com/game-physics/fix-your-timestep/
1200
1201 var numSteps = Math.floor(time - lastTime);
1202
1203 for (var i = 0; i < numSteps; ++i) {
1204 var force = -config.tension * (position - to);
1205 var damping = -config.friction * velocity;
1206 var acceleration = (force + damping) / config.mass;
1207 velocity = velocity + acceleration * 1 / 1000;
1208 position = position + velocity * 1 / 1000;
1209 } // Conditions for stopping the spring animation
1210
1211
1212 var isOvershooting = config.clamp && config.tension !== 0 ? from < to ? position > to : position < to : false;
1213 var isVelocity = Math.abs(velocity) <= config.precision;
1214 var isDisplacement = config.tension !== 0 ? Math.abs(to - position) <= config.precision : true;
1215 endOfAnimation = isOvershooting || isVelocity && isDisplacement;
1216 animation.lastVelocity = velocity;
1217 animation.lastTime = time;
1218 } // Trails aren't done until their parents conclude
1219
1220
1221 if (isAnimated && !config.toValues[valIdx].done) endOfAnimation = false;
1222
1223 if (endOfAnimation) {
1224 // Ensure that we end up with a round value
1225 if (animation.value !== to) position = to;
1226 animation.done = true;
1227 } else isActive = true;
1228
1229 animation.setValue(position);
1230 animation.lastPosition = position;
1231 } // Keep track of updated values only when necessary
1232
1233
1234 if (controller.props.onFrame) controller.values[config.name] = config.interpolation.getValue();
1235 } // Update callbacks in the end of the frame
1236
1237
1238 if (controller.props.onFrame) controller.props.onFrame(controller.values); // Either call onEnd or next frame
1239
1240 if (!isActive) {
1241 controllers.delete(controller);
1242 controller.stop(true);
1243 }
1244 } // Loop over as long as there are controllers ...
1245
1246
1247 if (controllers.size) {
1248 if (!manualFrameloop) requestFrame(update);
1249 } else active = false;
1250};
1251
1252var start = function start(controller) {
1253 if (!controllers.has(controller)) {
1254 controllers.add(controller);
1255 if (!active && !manualFrameloop) requestFrame(update);
1256 active = true;
1257 }
1258};
1259
1260var stop = function stop(controller) {
1261 if (controllers.has(controller)) controllers.delete(controller);
1262};
1263
1264var G = 0;
1265
1266var Controller =
1267/*#__PURE__*/
1268function () {
1269 function Controller() {
1270 var _this = this;
1271
1272 this.id = void 0;
1273 this.idle = true;
1274 this.hasChanged = false;
1275 this.guid = 0;
1276 this.local = 0;
1277 this.props = {};
1278 this.merged = {};
1279 this.animations = {};
1280 this.interpolations = {};
1281 this.values = {};
1282 this.configs = [];
1283 this.listeners = [];
1284 this.queue = [];
1285 this.localQueue = void 0;
1286
1287 this.getValues = function () {
1288 return _this.interpolations;
1289 };
1290
1291 this.id = G++;
1292 }
1293 /** update(props)
1294 * This function filters input props and creates an array of tasks which are executed in .start()
1295 * Each task is allowed to carry a delay, which means it can execute asnychroneously */
1296
1297
1298 var _proto = Controller.prototype;
1299
1300 _proto.update = function update$$1(args) {
1301 var _this2 = this;
1302
1303 //this._id = n + this.id
1304 if (!args) return this; // Extract delay and the to-prop from props
1305
1306 var _ref = interpolateTo(args),
1307 _ref$delay = _ref.delay,
1308 delay = _ref$delay === void 0 ? 0 : _ref$delay,
1309 to = _ref.to,
1310 props = _objectWithoutPropertiesLoose(_ref, ["delay", "to"]);
1311
1312 if (is.arr(to) || is.fun(to)) {
1313 // If config is either a function or an array queue it up as is
1314 this.queue.push(_extends({}, props, {
1315 delay: delay,
1316 to: to
1317 }));
1318 } else if (to) {
1319 // Otherwise go through each key since it could be delayed individually
1320 var merge$$1 = {};
1321 Object.entries(to).forEach(function (_ref2) {
1322 var _to;
1323
1324 var k = _ref2[0],
1325 v = _ref2[1];
1326
1327 // Fetch delay and create an entry, consisting of the to-props, the delay, and basic props
1328 var entry = _extends({
1329 to: (_to = {}, _to[k] = v, _to),
1330 delay: callProp(delay, k)
1331 }, props); // If it doesn't have a delay, merge it, otherwise add it to the queue
1332
1333
1334 if (!entry.delay) merge$$1 = _extends({}, merge$$1, entry, {
1335 to: _extends({}, merge$$1.to, entry.to)
1336 });else _this2.queue = [].concat(_this2.queue, [entry]);
1337 }); // Append merged props, if present
1338
1339 if (Object.keys(merge$$1).length > 0) this.queue = [].concat(this.queue, [merge$$1]);
1340 } // Sort queue, so that async calls go last
1341
1342
1343 this.queue = this.queue.sort(function (a, b) {
1344 return a.delay - b.delay;
1345 }); // Diff the reduced props immediately (they'll contain the from-prop and some config)
1346
1347 this.diff(props);
1348 return this;
1349 }
1350 /** start(onEnd)
1351 * This function either executes a queue, if present, or starts the frameloop, which animates */
1352 ;
1353
1354 _proto.start = function start$$1(onEnd) {
1355 var _this3 = this;
1356
1357 // If a queue is present we must excecute it
1358 if (this.queue.length) {
1359 this.idle = false; // Updates can interrupt trailing queues, in that case we just merge values
1360
1361 if (this.localQueue) {
1362 this.localQueue.forEach(function (_ref3) {
1363 var _ref3$from = _ref3.from,
1364 from = _ref3$from === void 0 ? {} : _ref3$from,
1365 _ref3$to = _ref3.to,
1366 to = _ref3$to === void 0 ? {} : _ref3$to;
1367 if (is.obj(from)) _this3.merged = _extends({}, from, _this3.merged);
1368 if (is.obj(to)) _this3.merged = _extends({}, _this3.merged, to);
1369 });
1370 } // The guid helps us tracking frames, a new queue over an old one means an override
1371 // We discard async calls in that caseÍ
1372
1373
1374 var local = this.local = ++this.guid;
1375 var queue = this.localQueue = this.queue;
1376 this.queue = []; // Go through each entry and execute it
1377
1378 queue.forEach(function (_ref4, index) {
1379 var delay = _ref4.delay,
1380 props = _objectWithoutPropertiesLoose(_ref4, ["delay"]);
1381
1382 var cb = function cb(finished) {
1383 if (index === queue.length - 1 && local === _this3.guid && finished) {
1384 _this3.idle = true;
1385 if (_this3.props.onRest) _this3.props.onRest(_this3.merged);
1386 }
1387
1388 if (onEnd) onEnd();
1389 }; // Entries can be delayed, ansyc or immediate
1390
1391
1392 var async = is.arr(props.to) || is.fun(props.to);
1393
1394 if (delay) {
1395 setTimeout(function () {
1396 if (local === _this3.guid) {
1397 if (async) _this3.runAsync(props, cb);else _this3.diff(props).start(cb);
1398 }
1399 }, delay);
1400 } else if (async) _this3.runAsync(props, cb);else _this3.diff(props).start(cb);
1401 });
1402 } // Otherwise we kick of the frameloop
1403 else {
1404 if (is.fun(onEnd)) this.listeners.push(onEnd);
1405 if (this.props.onStart) this.props.onStart();
1406
1407 start(this);
1408 }
1409
1410 return this;
1411 };
1412
1413 _proto.stop = function stop$$1(finished) {
1414 this.listeners.forEach(function (onEnd) {
1415 return onEnd(finished);
1416 });
1417 this.listeners = [];
1418 return this;
1419 }
1420 /** Pause sets onEnd listeners free, but also removes the controller from the frameloop */
1421 ;
1422
1423 _proto.pause = function pause(finished) {
1424 this.stop(true);
1425 if (finished) stop(this);
1426 return this;
1427 };
1428
1429 _proto.runAsync = function runAsync(_ref5, onEnd) {
1430 var _this4 = this;
1431
1432 var delay = _ref5.delay,
1433 props = _objectWithoutPropertiesLoose(_ref5, ["delay"]);
1434
1435 var local = this.local; // If "to" is either a function or an array it will be processed async, therefor "to" should be empty right now
1436 // If the view relies on certain values "from" has to be present
1437
1438 var queue = Promise.resolve(undefined);
1439
1440 if (is.arr(props.to)) {
1441 var _loop = function _loop(i) {
1442 var index = i;
1443
1444 var fresh = _extends({}, props, {
1445 to: props.to[index]
1446 });
1447
1448 if (is.arr(fresh.config)) fresh.config = fresh.config[index];
1449 queue = queue.then(function () {
1450 //this.stop()
1451 if (local === _this4.guid) return new Promise(function (r) {
1452 return _this4.diff(interpolateTo(fresh)).start(r);
1453 });
1454 });
1455 };
1456
1457 for (var i = 0; i < props.to.length; i++) {
1458 _loop(i);
1459 }
1460 } else if (is.fun(props.to)) {
1461 var index = 0;
1462 var last;
1463 queue = queue.then(function () {
1464 return props.to( // next(props)
1465 function (p) {
1466 var fresh = _extends({}, props, interpolateTo(p));
1467
1468 if (is.arr(fresh.config)) fresh.config = fresh.config[index];
1469 index++; //this.stop()
1470
1471 if (local === _this4.guid) return last = new Promise(function (r) {
1472 return _this4.diff(fresh).start(r);
1473 });
1474 return;
1475 }, // cancel()
1476 function (finished) {
1477 if (finished === void 0) {
1478 finished = true;
1479 }
1480
1481 return _this4.stop(finished);
1482 }).then(function () {
1483 return last;
1484 });
1485 });
1486 }
1487
1488 queue.then(onEnd);
1489 };
1490
1491 _proto.diff = function diff(props) {
1492 var _this5 = this;
1493
1494 this.props = _extends({}, this.props, props);
1495 var _this$props = this.props,
1496 _this$props$from = _this$props.from,
1497 from = _this$props$from === void 0 ? {} : _this$props$from,
1498 _this$props$to = _this$props.to,
1499 to = _this$props$to === void 0 ? {} : _this$props$to,
1500 _this$props$config = _this$props.config,
1501 config = _this$props$config === void 0 ? {} : _this$props$config,
1502 reverse = _this$props.reverse,
1503 attach = _this$props.attach,
1504 reset = _this$props.reset,
1505 immediate = _this$props.immediate; // Reverse values when requested
1506
1507 if (reverse) {
1508 var _ref6 = [to, from];
1509 from = _ref6[0];
1510 to = _ref6[1];
1511 } // This will collect all props that were ever set, reset merged props when necessary
1512
1513
1514 this.merged = _extends({}, from, this.merged, to);
1515 this.hasChanged = false; // Attachment handling, trailed springs can "attach" themselves to a previous spring
1516
1517 var target = attach && attach(this); // Reduces input { name: value } pairs into animated values
1518
1519 this.animations = Object.entries(this.merged).reduce(function (acc, _ref7) {
1520 var name = _ref7[0],
1521 value = _ref7[1];
1522 // Issue cached entries, except on reset
1523 var entry = acc[name] || {}; // Figure out what the value is supposed to be
1524
1525 var isNumber = is.num(value);
1526 var isString = is.str(value) && !value.startsWith('#') && !/\d/.test(value) && !colorNames[value];
1527 var isArray = is.arr(value);
1528 var isInterpolation = !isNumber && !isArray && !isString;
1529 var fromValue = !is.und(from[name]) ? from[name] : value;
1530 var toValue = isNumber || isArray ? value : isString ? value : 1;
1531 var toConfig = callProp(config, name);
1532 if (target) toValue = target.animations[name].parent;
1533 var parent = entry.parent,
1534 interpolation$$1 = entry.interpolation,
1535 toValues = toArray(target ? toValue.getPayload() : toValue),
1536 animatedValues;
1537 var newValue = value;
1538 if (isInterpolation) newValue = interpolation({
1539 range: [0, 1],
1540 output: [value, value]
1541 })(1);
1542 var currentValue = interpolation$$1 && interpolation$$1.getValue(); // Change detection flags
1543
1544 var isFirst = is.und(parent);
1545 var isActive = !isFirst && entry.animatedValues.some(function (v) {
1546 return !v.done;
1547 });
1548 var currentValueDiffersFromGoal = !is.equ(newValue, currentValue);
1549 var hasNewGoal = !is.equ(newValue, entry.previous);
1550 var hasNewConfig = !is.equ(toConfig, entry.config); // Change animation props when props indicate a new goal (new value differs from previous one)
1551 // and current values differ from it. Config changes trigger a new update as well (though probably shouldn't?)
1552
1553 if (reset || hasNewGoal && currentValueDiffersFromGoal || hasNewConfig) {
1554 var _extends2;
1555
1556 // Convert regular values into animated values, ALWAYS re-use if possible
1557 if (isNumber || isString) parent = interpolation$$1 = entry.parent || new AnimatedValue(fromValue);else if (isArray) parent = interpolation$$1 = entry.parent || new AnimatedValueArray(fromValue);else if (isInterpolation) {
1558 var prev = entry.interpolation && entry.interpolation.calc(entry.parent.value);
1559 prev = prev !== void 0 && !reset ? prev : fromValue;
1560
1561 if (entry.parent) {
1562 parent = entry.parent;
1563 parent.setValue(0, false);
1564 } else parent = new AnimatedValue(0);
1565
1566 var range = {
1567 output: [prev, value]
1568 };
1569
1570 if (entry.interpolation) {
1571 interpolation$$1 = entry.interpolation;
1572 entry.interpolation.updateConfig(range);
1573 } else interpolation$$1 = parent.interpolate(range);
1574 }
1575 toValues = toArray(target ? toValue.getPayload() : toValue);
1576 animatedValues = toArray(parent.getPayload());
1577 if (reset && !isInterpolation) parent.setValue(fromValue, false);
1578 _this5.hasChanged = true; // Reset animated values
1579
1580 animatedValues.forEach(function (value) {
1581 value.startPosition = value.value;
1582 value.lastPosition = value.value;
1583 value.lastVelocity = isActive ? value.lastVelocity : undefined;
1584 value.lastTime = isActive ? value.lastTime : undefined;
1585 value.startTime = now();
1586 value.done = false;
1587 value.animatedStyles.clear();
1588 }); // Set immediate values
1589
1590 if (callProp(immediate, name)) parent.setValue(value, false);
1591 return _extends({}, acc, (_extends2 = {}, _extends2[name] = _extends({}, entry, {
1592 name: name,
1593 parent: parent,
1594 interpolation: interpolation$$1,
1595 animatedValues: animatedValues,
1596 toValues: toValues,
1597 previous: newValue,
1598 config: toConfig,
1599 fromValues: toArray(parent.getValue()),
1600 immediate: callProp(immediate, name),
1601 initialVelocity: withDefault(toConfig.velocity, 0),
1602 clamp: withDefault(toConfig.clamp, false),
1603 precision: withDefault(toConfig.precision, 0.01),
1604 tension: withDefault(toConfig.tension, 170),
1605 friction: withDefault(toConfig.friction, 26),
1606 mass: withDefault(toConfig.mass, 1),
1607 duration: toConfig.duration,
1608 easing: withDefault(toConfig.easing, function (t) {
1609 return t;
1610 }),
1611 decay: toConfig.decay
1612 }), _extends2));
1613 } else {
1614 if (!currentValueDiffersFromGoal) {
1615 var _extends3;
1616
1617 // So ... the current target value (newValue) appears to be different from the previous value,
1618 // which normally constitutes an update, but the actual value (currentValue) matches the target!
1619 // In order to resolve this without causing an animation update we silently flag the animation as done,
1620 // which it technically is. Interpolations also needs a config update with their target set to 1.
1621 if (isInterpolation) {
1622 parent.setValue(1, false);
1623 interpolation$$1.updateConfig({
1624 output: [newValue, newValue]
1625 });
1626 }
1627
1628 parent.done = true;
1629 _this5.hasChanged = true;
1630 return _extends({}, acc, (_extends3 = {}, _extends3[name] = _extends({}, acc[name], {
1631 previous: newValue
1632 }), _extends3));
1633 }
1634
1635 return acc;
1636 }
1637 }, this.animations);
1638
1639 if (this.hasChanged) {
1640 // Make animations available to frameloop
1641 this.configs = Object.values(this.animations);
1642 this.values = {};
1643 this.interpolations = {};
1644
1645 for (var key in this.animations) {
1646 this.interpolations[key] = this.animations[key].interpolation;
1647 this.values[key] = this.animations[key].interpolation.getValue();
1648 }
1649 }
1650
1651 return this;
1652 };
1653
1654 _proto.destroy = function destroy() {
1655 this.stop();
1656 this.props = {};
1657 this.merged = {};
1658 this.animations = {};
1659 this.interpolations = {};
1660 this.values = {};
1661 this.configs = [];
1662 this.local = 0;
1663 };
1664
1665 return Controller;
1666}();
1667
1668/** API
1669 * const props = useSprings(number, [{ ... }, { ... }, ...])
1670 * const [props, set] = useSprings(number, (i, controller) => ({ ... }))
1671 */
1672
1673var useSprings = function useSprings(length, props) {
1674 var mounted = React.useRef(false);
1675 var ctrl = React.useRef();
1676 var isFn = is.fun(props); // The controller maintains the animation values, starts and stops animations
1677
1678 var _useMemo = React.useMemo(function () {
1679 // Remove old controllers
1680 if (ctrl.current) {
1681 ctrl.current.map(function (c) {
1682 return c.destroy();
1683 });
1684 ctrl.current = undefined;
1685 }
1686
1687 var ref;
1688 return [new Array(length).fill().map(function (_, i) {
1689 var ctrl = new Controller();
1690 var newProps = isFn ? callProp(props, i, ctrl) : props[i];
1691 if (i === 0) ref = newProps.ref;
1692 ctrl.update(newProps);
1693 if (!ref) ctrl.start();
1694 return ctrl;
1695 }), ref];
1696 }, [length]),
1697 controllers = _useMemo[0],
1698 ref = _useMemo[1];
1699
1700 ctrl.current = controllers; // The hooks reference api gets defined here ...
1701
1702 var api = React.useImperativeHandle(ref, function () {
1703 return {
1704 start: function start() {
1705 return Promise.all(ctrl.current.map(function (c) {
1706 return new Promise(function (r) {
1707 return c.start(r);
1708 });
1709 }));
1710 },
1711 stop: function stop(finished) {
1712 return ctrl.current.forEach(function (c) {
1713 return c.stop(finished);
1714 });
1715 },
1716
1717 get controllers() {
1718 return ctrl.current;
1719 }
1720
1721 };
1722 }); // This function updates the controllers
1723
1724 var updateCtrl = React.useMemo(function () {
1725 return function (updateProps) {
1726 return ctrl.current.map(function (c, i) {
1727 c.update(isFn ? callProp(updateProps, i, c) : updateProps[i]);
1728 if (!ref) c.start();
1729 });
1730 };
1731 }, [length]); // Update controller if props aren't functional
1732
1733 React.useEffect(function () {
1734 if (mounted.current) {
1735 if (!isFn) updateCtrl(props);
1736 } else if (!ref) ctrl.current.forEach(function (c) {
1737 return c.start();
1738 });
1739 }); // Update mounted flag and destroy controller on unmount
1740
1741 React.useEffect(function () {
1742 return mounted.current = true, function () {
1743 return ctrl.current.forEach(function (c) {
1744 return c.destroy();
1745 });
1746 };
1747 }, []); // Return animated props, or, anim-props + the update-setter above
1748
1749 var propValues = ctrl.current.map(function (c) {
1750 return c.getValues();
1751 });
1752 return isFn ? [propValues, updateCtrl, function (finished) {
1753 return ctrl.current.forEach(function (c) {
1754 return c.pause(finished);
1755 });
1756 }] : propValues;
1757};
1758
1759/** API
1760 * const props = useSpring({ ... })
1761 * const [props, set] = useSpring(() => ({ ... }))
1762 */
1763
1764var useSpring = function useSpring(props) {
1765 var isFn = is.fun(props);
1766
1767 var _useSprings = useSprings(1, isFn ? props : [props]),
1768 result = _useSprings[0],
1769 set = _useSprings[1],
1770 pause = _useSprings[2];
1771
1772 return isFn ? [result[0], set, pause] : result;
1773};
1774
1775/** API
1776 * const trails = useTrail(number, { ... })
1777 * const [trails, set] = useTrail(number, () => ({ ... }))
1778 */
1779
1780var useTrail = function useTrail(length, props) {
1781 var mounted = React.useRef(false);
1782 var isFn = is.fun(props);
1783 var updateProps = callProp(props);
1784 var instances = React.useRef();
1785
1786 var _useSprings = useSprings(length, function (i, ctrl) {
1787 if (i === 0) instances.current = [];
1788 instances.current.push(ctrl);
1789 return _extends({}, updateProps, {
1790 config: callProp(updateProps.config, i),
1791 attach: i > 0 && function () {
1792 return instances.current[i - 1];
1793 }
1794 });
1795 }),
1796 result = _useSprings[0],
1797 set = _useSprings[1],
1798 pause = _useSprings[2]; // Set up function to update controller
1799
1800
1801 var updateCtrl = React.useMemo(function () {
1802 return function (props) {
1803 return set(function (i, ctrl) {
1804 var last = props.reverse ? i === 0 : length - 1 === i;
1805 var attachIdx = props.reverse ? i + 1 : i - 1;
1806 var attachController = instances.current[attachIdx];
1807 return _extends({}, props, {
1808 config: callProp(props.config || updateProps.config, i),
1809 attach: attachController && function () {
1810 return attachController;
1811 }
1812 });
1813 });
1814 };
1815 }, [length, updateProps.reverse]); // Update controller if props aren't functional
1816
1817 React.useEffect(function () {
1818 return void (mounted.current && !isFn && updateCtrl(props));
1819 }); // Update mounted flag and destroy controller on unmount
1820
1821 React.useEffect(function () {
1822 return void (mounted.current = true);
1823 }, []);
1824 return isFn ? [result, updateCtrl, pause] : result;
1825};
1826
1827/** API
1828 * const transitions = useTransition(items, itemKeys, { ... })
1829 * const [transitions, update] = useTransition(items, itemKeys, () => ({ ... }))
1830 */
1831
1832var guid = 0;
1833var ENTER = 'enter';
1834var LEAVE = 'leave';
1835var UPDATE = 'update';
1836
1837var mapKeys = function mapKeys(items, keys) {
1838 return (typeof keys === 'function' ? items.map(keys) : toArray(keys)).map(String);
1839};
1840
1841var get = function get(props) {
1842 var items = props.items,
1843 _props$keys = props.keys,
1844 keys = _props$keys === void 0 ? function (item) {
1845 return item;
1846 } : _props$keys,
1847 rest = _objectWithoutPropertiesLoose(props, ["items", "keys"]);
1848
1849 items = toArray(items !== void 0 ? items : null);
1850 return _extends({
1851 items: items,
1852 keys: mapKeys(items, keys)
1853 }, rest);
1854};
1855
1856function useTransition(input, keyTransform, config) {
1857 var props = _extends({
1858 items: input,
1859 keys: keyTransform || function (i) {
1860 return i;
1861 }
1862 }, config);
1863
1864 var _get = get(props),
1865 _get$lazy = _get.lazy,
1866 lazy = _get$lazy === void 0 ? false : _get$lazy,
1867 _get$unique = _get.unique,
1868 _get$reset = _get.reset,
1869 reset = _get$reset === void 0 ? false : _get$reset,
1870 enter = _get.enter,
1871 leave = _get.leave,
1872 update = _get.update,
1873 onDestroyed = _get.onDestroyed,
1874 keys = _get.keys,
1875 items = _get.items,
1876 onFrame = _get.onFrame,
1877 _onRest = _get.onRest,
1878 onStart = _get.onStart,
1879 ref = _get.ref,
1880 extra = _objectWithoutPropertiesLoose(_get, ["lazy", "unique", "reset", "enter", "leave", "update", "onDestroyed", "keys", "items", "onFrame", "onRest", "onStart", "ref"]);
1881
1882 var forceUpdate = useForceUpdate();
1883 var mounted = React.useRef(false);
1884 var state = React.useRef({
1885 mounted: false,
1886 first: true,
1887 deleted: [],
1888 current: {},
1889 transitions: [],
1890 prevProps: {},
1891 paused: !!props.ref,
1892 instances: !mounted.current && new Map(),
1893 forceUpdate: forceUpdate
1894 });
1895 React.useImperativeHandle(props.ref, function () {
1896 return {
1897 start: function start() {
1898 return Promise.all(Array.from(state.current.instances).map(function (_ref) {
1899 var c = _ref[1];
1900 return new Promise(function (r) {
1901 return c.start(r);
1902 });
1903 }));
1904 },
1905 stop: function stop(finished) {
1906 return Array.from(state.current.instances).forEach(function (_ref2) {
1907 var c = _ref2[1];
1908 return c.stop(finished);
1909 });
1910 },
1911
1912 get controllers() {
1913 return Array.from(state.current.instances).map(function (_ref3) {
1914 var c = _ref3[1];
1915 return c;
1916 });
1917 }
1918
1919 };
1920 }); // Update state
1921
1922 state.current = diffItems(state.current, props);
1923
1924 if (state.current.changed) {
1925 // Update state
1926 state.current.transitions.forEach(function (transition) {
1927 var slot = transition.slot,
1928 from = transition.from,
1929 to = transition.to,
1930 config = transition.config,
1931 trail = transition.trail,
1932 key = transition.key,
1933 item = transition.item;
1934 if (!state.current.instances.has(key)) state.current.instances.set(key, new Controller()); // update the map object
1935
1936 var ctrl = state.current.instances.get(key);
1937
1938 var newProps = _extends({}, extra, {
1939 to: to,
1940 from: from,
1941 config: config,
1942 ref: ref,
1943 onRest: function onRest(values) {
1944 if (state.current.mounted) {
1945 if (transition.destroyed) {
1946 // If no ref is given delete destroyed items immediately
1947 if (!ref && !lazy) cleanUp(state, key);
1948 if (onDestroyed) onDestroyed(item);
1949 } // A transition comes to rest once all its springs conclude
1950
1951
1952 var curInstances = Array.from(state.current.instances);
1953 var active = curInstances.some(function (_ref4) {
1954 var c = _ref4[1];
1955 return !c.idle;
1956 });
1957 if (!active && (ref || lazy) && state.current.deleted.length > 0) cleanUp(state);
1958 if (_onRest) _onRest(item, slot, values);
1959 }
1960 },
1961 onStart: onStart && function () {
1962 return onStart(item, slot);
1963 },
1964 onFrame: onFrame && function (values) {
1965 return onFrame(item, slot, values);
1966 },
1967 delay: trail,
1968 reset: reset && slot === ENTER // Update controller
1969
1970 });
1971
1972 ctrl.update(newProps);
1973 if (!state.current.paused) ctrl.start();
1974 });
1975 }
1976
1977 React.useEffect(function () {
1978 state.current.mounted = mounted.current = true;
1979 return function () {
1980 state.current.mounted = mounted.current = false;
1981 Array.from(state.current.instances).map(function (_ref5) {
1982 var c = _ref5[1];
1983 return c.destroy();
1984 });
1985 state.current.instances.clear();
1986 };
1987 }, []);
1988 return state.current.transitions.map(function (_ref6) {
1989 var item = _ref6.item,
1990 slot = _ref6.slot,
1991 key = _ref6.key;
1992 return {
1993 item: item,
1994 key: key,
1995 state: slot,
1996 props: state.current.instances.get(key).getValues()
1997 };
1998 });
1999}
2000
2001function cleanUp(state, filterKey) {
2002 var deleted = state.current.deleted;
2003
2004 var _loop = function _loop() {
2005 if (_isArray) {
2006 if (_i >= _iterator.length) return "break";
2007 _ref8 = _iterator[_i++];
2008 } else {
2009 _i = _iterator.next();
2010 if (_i.done) return "break";
2011 _ref8 = _i.value;
2012 }
2013
2014 var _ref7 = _ref8;
2015 var key = _ref7.key;
2016
2017 var filter = function filter(t) {
2018 return t.key !== key;
2019 };
2020
2021 if (is.und(filterKey) || filterKey === key) {
2022 state.current.instances.delete(key);
2023 state.current.transitions = state.current.transitions.filter(filter);
2024 state.current.deleted = state.current.deleted.filter(filter);
2025 }
2026 };
2027
2028 for (var _iterator = deleted, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
2029 var _ref8;
2030
2031 var _ret = _loop();
2032
2033 if (_ret === "break") break;
2034 }
2035
2036 state.current.forceUpdate();
2037}
2038
2039function diffItems(_ref9, props) {
2040 var first = _ref9.first,
2041 prevProps = _ref9.prevProps,
2042 state = _objectWithoutPropertiesLoose(_ref9, ["first", "prevProps"]);
2043
2044 var _get2 = get(props),
2045 items = _get2.items,
2046 keys = _get2.keys,
2047 initial = _get2.initial,
2048 from = _get2.from,
2049 enter = _get2.enter,
2050 leave = _get2.leave,
2051 update = _get2.update,
2052 _get2$trail = _get2.trail,
2053 trail = _get2$trail === void 0 ? 0 : _get2$trail,
2054 unique = _get2.unique,
2055 config = _get2.config,
2056 _get2$order = _get2.order,
2057 order = _get2$order === void 0 ? [ENTER, LEAVE, UPDATE] : _get2$order;
2058
2059 var _get3 = get(prevProps),
2060 _keys = _get3.keys,
2061 _items = _get3.items;
2062
2063 var current = _extends({}, state.current);
2064
2065 var deleted = [].concat(state.deleted); // Compare next keys with current keys
2066
2067 var currentKeys = Object.keys(current);
2068 var currentSet = new Set(currentKeys);
2069 var nextSet = new Set(keys);
2070 var added = keys.filter(function (item) {
2071 return !currentSet.has(item);
2072 });
2073 var removed = state.transitions.filter(function (item) {
2074 return !item.destroyed && !nextSet.has(item.originalKey);
2075 }).map(function (i) {
2076 return i.originalKey;
2077 });
2078 var updated = keys.filter(function (item) {
2079 return currentSet.has(item);
2080 });
2081 var delay = -trail;
2082
2083 while (order.length) {
2084 var changeType = order.shift();
2085
2086 switch (changeType) {
2087 case ENTER:
2088 {
2089 added.forEach(function (key, index) {
2090 // In unique mode, remove fading out transitions if their key comes in again
2091 if (unique && deleted.find(function (d) {
2092 return d.originalKey === key;
2093 })) deleted = deleted.filter(function (t) {
2094 return t.originalKey !== key;
2095 });
2096 var keyIndex = keys.indexOf(key);
2097 var item = items[keyIndex];
2098 var slot = first && initial !== void 0 ? 'initial' : ENTER;
2099 current[key] = {
2100 slot: slot,
2101 originalKey: key,
2102 key: unique ? String(key) : guid++,
2103 item: item,
2104 trail: delay = delay + trail,
2105 config: callProp(config, item, slot),
2106 from: callProp(first ? initial !== void 0 ? initial || {} : from : from, item),
2107 to: callProp(enter, item)
2108 };
2109 });
2110 break;
2111 }
2112
2113 case LEAVE:
2114 {
2115 removed.forEach(function (key) {
2116 var keyIndex = _keys.indexOf(key);
2117
2118 var item = _items[keyIndex];
2119 var slot = LEAVE;
2120 deleted.unshift(_extends({}, current[key], {
2121 slot: slot,
2122 destroyed: true,
2123 left: _keys[Math.max(0, keyIndex - 1)],
2124 right: _keys[Math.min(_keys.length, keyIndex + 1)],
2125 trail: delay = delay + trail,
2126 config: callProp(config, item, slot),
2127 to: callProp(leave, item)
2128 }));
2129 delete current[key];
2130 });
2131 break;
2132 }
2133
2134 case UPDATE:
2135 {
2136 updated.forEach(function (key) {
2137 var keyIndex = keys.indexOf(key);
2138 var item = items[keyIndex];
2139 var slot = UPDATE;
2140 current[key] = _extends({}, current[key], {
2141 item: item,
2142 slot: slot,
2143 trail: delay = delay + trail,
2144 config: callProp(config, item, slot),
2145 to: callProp(update, item)
2146 });
2147 });
2148 break;
2149 }
2150 }
2151 }
2152
2153 var out = keys.map(function (key) {
2154 return current[key];
2155 }); // This tries to restore order for deleted items by finding their last known siblings
2156 // only using the left sibling to keep order placement consistent for all deleted items
2157
2158 deleted.forEach(function (_ref10) {
2159 var left = _ref10.left,
2160 right = _ref10.right,
2161 item = _objectWithoutPropertiesLoose(_ref10, ["left", "right"]);
2162
2163 var pos; // Was it the element on the left, if yes, move there ...
2164
2165 if ((pos = out.findIndex(function (t) {
2166 return t.originalKey === left;
2167 })) !== -1) pos += 1; // And if nothing else helps, move it to the start ¯\_(ツ)_/¯
2168
2169 pos = Math.max(0, pos);
2170 out = [].concat(out.slice(0, pos), [item], out.slice(pos));
2171 });
2172 return _extends({}, state, {
2173 changed: added.length || removed.length || updated.length,
2174 first: first && added.length === 0,
2175 transitions: out,
2176 current: current,
2177 deleted: deleted,
2178 prevProps: props
2179 });
2180}
2181
2182var AnimatedTransform =
2183/*#__PURE__*/
2184function (_Animated) {
2185 _inheritsLoose(AnimatedTransform, _Animated);
2186
2187 function AnimatedTransform(transforms) {
2188 var _this;
2189
2190 _this = _Animated.call(this) || this;
2191 _this._transforms = void 0;
2192 _this._transforms = transforms;
2193 return _this;
2194 }
2195
2196 var _proto = AnimatedTransform.prototype;
2197
2198 _proto.getValue = function getValue() {
2199 return this._transforms.map(function (transform) {
2200 var result = {};
2201
2202 for (var key in transform) {
2203 var value = transform[key];
2204 result[key] = value instanceof Animated ? value.getValue() : value;
2205 }
2206
2207 return result;
2208 });
2209 };
2210
2211 _proto.getAnimatedValue = function getAnimatedValue() {
2212 return this._transforms.map(function (transform) {
2213 var result = {};
2214
2215 for (var key in transform) {
2216 var value = transform[key];
2217 result[key] = value instanceof Animated ? value.getAnimatedValue() : value;
2218 }
2219
2220 return result;
2221 });
2222 };
2223
2224 _proto.attach = function attach() {
2225 var _this2 = this;
2226
2227 this._transforms.forEach(function (transform) {
2228 for (var key in transform) {
2229 var value = transform[key];
2230 if (value instanceof Animated) value.addChild(_this2);
2231 }
2232 });
2233 };
2234
2235 _proto.detach = function detach() {
2236 var _this3 = this;
2237
2238 this._transforms.forEach(function (transform) {
2239 for (var key in transform) {
2240 var value = transform[key];
2241 if (value instanceof Animated) value.removeChild(_this3);
2242 }
2243 });
2244 };
2245
2246 return AnimatedTransform;
2247}(Animated);
2248
2249injectDefaultElement(reactNative.View);
2250injectStringInterpolator(createStringInterpolator);
2251injectColorNames(colors);
2252injectApplyAnimatedValues(function (instance, props) {
2253 return instance.setNativeProps ? instance.setNativeProps(props) : false;
2254}, function (style) {
2255 return _extends({}, style, {
2256 transform: new AnimatedTransform(style.transform)
2257 });
2258});
2259injectCreateAnimatedStyle(function (styles) {
2260 return new AnimatedStyle(reactNative.StyleSheet.flatten(styles));
2261});
2262injectAnimatedApi(function (node, mounted, forceUpdate) {
2263 return {
2264 setNativeProps: function setNativeProps(props) {
2265 var didUpdate = applyAnimatedValues.fn(node.current, props);
2266 if (!didUpdate) mounted.current && forceUpdate();
2267 },
2268 getNode: function getNode() {
2269 return node.current;
2270 }
2271 };
2272});
2273var apply = merge(createAnimatedComponent);
2274
2275exports.apply = apply;
2276exports.config = config;
2277exports.animated = createAnimatedComponent;
2278exports.interpolate = interpolate$1;
2279exports.Globals = Globals;
2280exports.useSpring = useSpring;
2281exports.useTrail = useTrail;
2282exports.useTransition = useTransition;
2283exports.useChain = useChain;
2284exports.useSprings = useSprings;