UNPKG

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