UNPKG

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