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