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