react-spring-carousel 3.0.0-beta003 → 3.0.0-beta005

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3863 @@
1
+ import * as React from 'react';
2
+ import { useEffect, useLayoutEffect, useState, useRef, forwardRef, useCallback, useContext, useMemo } from 'react';
3
+ import screenfull from 'screenfull';
4
+ import { jsx } from 'react/jsx-runtime';
5
+ import { unstable_batchedUpdates } from 'react-dom';
6
+
7
+ let updateQueue = makeQueue();
8
+ const raf = fn => schedule(fn, updateQueue);
9
+ let writeQueue = makeQueue();
10
+
11
+ raf.write = fn => schedule(fn, writeQueue);
12
+
13
+ let onStartQueue = makeQueue();
14
+
15
+ raf.onStart = fn => schedule(fn, onStartQueue);
16
+
17
+ let onFrameQueue = makeQueue();
18
+
19
+ raf.onFrame = fn => schedule(fn, onFrameQueue);
20
+
21
+ let onFinishQueue = makeQueue();
22
+
23
+ raf.onFinish = fn => schedule(fn, onFinishQueue);
24
+
25
+ let timeouts = [];
26
+
27
+ raf.setTimeout = (handler, ms) => {
28
+ let time = raf.now() + ms;
29
+
30
+ let cancel = () => {
31
+ let i = timeouts.findIndex(t => t.cancel == cancel);
32
+ if (~i) timeouts.splice(i, 1);
33
+ pendingCount -= ~i ? 1 : 0;
34
+ };
35
+
36
+ let timeout = {
37
+ time,
38
+ handler,
39
+ cancel
40
+ };
41
+ timeouts.splice(findTimeout(time), 0, timeout);
42
+ pendingCount += 1;
43
+ start();
44
+ return timeout;
45
+ };
46
+
47
+ let findTimeout = time => ~(~timeouts.findIndex(t => t.time > time) || ~timeouts.length);
48
+
49
+ raf.cancel = fn => {
50
+ onStartQueue.delete(fn);
51
+ onFrameQueue.delete(fn);
52
+ onFinishQueue.delete(fn);
53
+ updateQueue.delete(fn);
54
+ writeQueue.delete(fn);
55
+ };
56
+
57
+ raf.sync = fn => {
58
+ sync = true;
59
+ raf.batchedUpdates(fn);
60
+ sync = false;
61
+ };
62
+
63
+ raf.throttle = fn => {
64
+ let lastArgs;
65
+
66
+ function queuedFn() {
67
+ try {
68
+ fn(...lastArgs);
69
+ } finally {
70
+ lastArgs = null;
71
+ }
72
+ }
73
+
74
+ function throttled(...args) {
75
+ lastArgs = args;
76
+ raf.onStart(queuedFn);
77
+ }
78
+
79
+ throttled.handler = fn;
80
+
81
+ throttled.cancel = () => {
82
+ onStartQueue.delete(queuedFn);
83
+ lastArgs = null;
84
+ };
85
+
86
+ return throttled;
87
+ };
88
+
89
+ let nativeRaf = typeof window != 'undefined' ? window.requestAnimationFrame : () => {};
90
+
91
+ raf.use = impl => nativeRaf = impl;
92
+
93
+ raf.now = typeof performance != 'undefined' ? () => performance.now() : Date.now;
94
+
95
+ raf.batchedUpdates = fn => fn();
96
+
97
+ raf.catch = console.error;
98
+ raf.frameLoop = 'always';
99
+
100
+ raf.advance = () => {
101
+ if (raf.frameLoop !== 'demand') {
102
+ console.warn('Cannot call the manual advancement of rafz whilst frameLoop is not set as demand');
103
+ } else {
104
+ update();
105
+ }
106
+ };
107
+
108
+ let ts = -1;
109
+ let pendingCount = 0;
110
+ let sync = false;
111
+
112
+ function schedule(fn, queue) {
113
+ if (sync) {
114
+ queue.delete(fn);
115
+ fn(0);
116
+ } else {
117
+ queue.add(fn);
118
+ start();
119
+ }
120
+ }
121
+
122
+ function start() {
123
+ if (ts < 0) {
124
+ ts = 0;
125
+
126
+ if (raf.frameLoop !== 'demand') {
127
+ nativeRaf(loop);
128
+ }
129
+ }
130
+ }
131
+
132
+ function stop() {
133
+ ts = -1;
134
+ }
135
+
136
+ function loop() {
137
+ if (~ts) {
138
+ nativeRaf(loop);
139
+ raf.batchedUpdates(update);
140
+ }
141
+ }
142
+
143
+ function update() {
144
+ let prevTs = ts;
145
+ ts = raf.now();
146
+ let count = findTimeout(ts);
147
+
148
+ if (count) {
149
+ eachSafely(timeouts.splice(0, count), t => t.handler());
150
+ pendingCount -= count;
151
+ }
152
+
153
+ if (!pendingCount) {
154
+ stop();
155
+ return;
156
+ }
157
+
158
+ onStartQueue.flush();
159
+ updateQueue.flush(prevTs ? Math.min(64, ts - prevTs) : 16.667);
160
+ onFrameQueue.flush();
161
+ writeQueue.flush();
162
+ onFinishQueue.flush();
163
+ }
164
+
165
+ function makeQueue() {
166
+ let next = new Set();
167
+ let current = next;
168
+ return {
169
+ add(fn) {
170
+ pendingCount += current == next && !next.has(fn) ? 1 : 0;
171
+ next.add(fn);
172
+ },
173
+
174
+ delete(fn) {
175
+ pendingCount -= current == next && next.has(fn) ? 1 : 0;
176
+ return next.delete(fn);
177
+ },
178
+
179
+ flush(arg) {
180
+ if (current.size) {
181
+ next = new Set();
182
+ pendingCount -= current.size;
183
+ eachSafely(current, fn => fn(arg) && next.add(fn));
184
+ pendingCount += next.size;
185
+ current = next;
186
+ }
187
+ }
188
+
189
+ };
190
+ }
191
+
192
+ function eachSafely(values, each) {
193
+ values.forEach(value => {
194
+ try {
195
+ each(value);
196
+ } catch (e) {
197
+ raf.catch(e);
198
+ }
199
+ });
200
+ }
201
+
202
+ function noop() {}
203
+ const defineHidden = (obj, key, value) => Object.defineProperty(obj, key, {
204
+ value,
205
+ writable: true,
206
+ configurable: true
207
+ });
208
+ const is = {
209
+ arr: Array.isArray,
210
+ obj: a => !!a && a.constructor.name === 'Object',
211
+ fun: a => typeof a === 'function',
212
+ str: a => typeof a === 'string',
213
+ num: a => typeof a === 'number',
214
+ und: a => a === undefined
215
+ };
216
+ function isEqual(a, b) {
217
+ if (is.arr(a)) {
218
+ if (!is.arr(b) || a.length !== b.length) return false;
219
+
220
+ for (let i = 0; i < a.length; i++) {
221
+ if (a[i] !== b[i]) return false;
222
+ }
223
+
224
+ return true;
225
+ }
226
+
227
+ return a === b;
228
+ }
229
+ const each = (obj, fn) => obj.forEach(fn);
230
+ function eachProp(obj, fn, ctx) {
231
+ if (is.arr(obj)) {
232
+ for (let i = 0; i < obj.length; i++) {
233
+ fn.call(ctx, obj[i], `${i}`);
234
+ }
235
+
236
+ return;
237
+ }
238
+
239
+ for (const key in obj) {
240
+ if (obj.hasOwnProperty(key)) {
241
+ fn.call(ctx, obj[key], key);
242
+ }
243
+ }
244
+ }
245
+ const toArray = a => is.und(a) ? [] : is.arr(a) ? a : [a];
246
+ function flush(queue, iterator) {
247
+ if (queue.size) {
248
+ const items = Array.from(queue);
249
+ queue.clear();
250
+ each(items, iterator);
251
+ }
252
+ }
253
+ const flushCalls = (queue, ...args) => flush(queue, fn => fn(...args));
254
+ const isSSR = () => typeof window === 'undefined' || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
255
+
256
+ let createStringInterpolator$1;
257
+ let to;
258
+ let colors$1 = null;
259
+ let skipAnimation = false;
260
+ let willAdvance = noop;
261
+ const assign = globals => {
262
+ if (globals.to) to = globals.to;
263
+ if (globals.now) raf.now = globals.now;
264
+ if (globals.colors !== undefined) colors$1 = globals.colors;
265
+ if (globals.skipAnimation != null) skipAnimation = globals.skipAnimation;
266
+ if (globals.createStringInterpolator) createStringInterpolator$1 = globals.createStringInterpolator;
267
+ if (globals.requestAnimationFrame) raf.use(globals.requestAnimationFrame);
268
+ if (globals.batchedUpdates) raf.batchedUpdates = globals.batchedUpdates;
269
+ if (globals.willAdvance) willAdvance = globals.willAdvance;
270
+ if (globals.frameLoop) raf.frameLoop = globals.frameLoop;
271
+ };
272
+
273
+ var globals = /*#__PURE__*/Object.freeze({
274
+ __proto__: null,
275
+ get createStringInterpolator () { return createStringInterpolator$1; },
276
+ get to () { return to; },
277
+ get colors () { return colors$1; },
278
+ get skipAnimation () { return skipAnimation; },
279
+ get willAdvance () { return willAdvance; },
280
+ assign: assign
281
+ });
282
+
283
+ const startQueue = new Set();
284
+ let currentFrame = [];
285
+ let prevFrame = [];
286
+ let priority = 0;
287
+ const frameLoop = {
288
+ get idle() {
289
+ return !startQueue.size && !currentFrame.length;
290
+ },
291
+
292
+ start(animation) {
293
+ if (priority > animation.priority) {
294
+ startQueue.add(animation);
295
+ raf.onStart(flushStartQueue);
296
+ } else {
297
+ startSafely(animation);
298
+ raf(advance);
299
+ }
300
+ },
301
+
302
+ advance,
303
+
304
+ sort(animation) {
305
+ if (priority) {
306
+ raf.onFrame(() => frameLoop.sort(animation));
307
+ } else {
308
+ const prevIndex = currentFrame.indexOf(animation);
309
+
310
+ if (~prevIndex) {
311
+ currentFrame.splice(prevIndex, 1);
312
+ startUnsafely(animation);
313
+ }
314
+ }
315
+ },
316
+
317
+ clear() {
318
+ currentFrame = [];
319
+ startQueue.clear();
320
+ }
321
+
322
+ };
323
+
324
+ function flushStartQueue() {
325
+ startQueue.forEach(startSafely);
326
+ startQueue.clear();
327
+ raf(advance);
328
+ }
329
+
330
+ function startSafely(animation) {
331
+ if (!currentFrame.includes(animation)) startUnsafely(animation);
332
+ }
333
+
334
+ function startUnsafely(animation) {
335
+ currentFrame.splice(findIndex(currentFrame, other => other.priority > animation.priority), 0, animation);
336
+ }
337
+
338
+ function advance(dt) {
339
+ const nextFrame = prevFrame;
340
+
341
+ for (let i = 0; i < currentFrame.length; i++) {
342
+ const animation = currentFrame[i];
343
+ priority = animation.priority;
344
+
345
+ if (!animation.idle) {
346
+ willAdvance(animation);
347
+ animation.advance(dt);
348
+
349
+ if (!animation.idle) {
350
+ nextFrame.push(animation);
351
+ }
352
+ }
353
+ }
354
+
355
+ priority = 0;
356
+ prevFrame = currentFrame;
357
+ prevFrame.length = 0;
358
+ currentFrame = nextFrame;
359
+ return currentFrame.length > 0;
360
+ }
361
+
362
+ function findIndex(arr, test) {
363
+ const index = arr.findIndex(test);
364
+ return index < 0 ? arr.length : index;
365
+ }
366
+
367
+ const colors = {
368
+ transparent: 0x00000000,
369
+ aliceblue: 0xf0f8ffff,
370
+ antiquewhite: 0xfaebd7ff,
371
+ aqua: 0x00ffffff,
372
+ aquamarine: 0x7fffd4ff,
373
+ azure: 0xf0ffffff,
374
+ beige: 0xf5f5dcff,
375
+ bisque: 0xffe4c4ff,
376
+ black: 0x000000ff,
377
+ blanchedalmond: 0xffebcdff,
378
+ blue: 0x0000ffff,
379
+ blueviolet: 0x8a2be2ff,
380
+ brown: 0xa52a2aff,
381
+ burlywood: 0xdeb887ff,
382
+ burntsienna: 0xea7e5dff,
383
+ cadetblue: 0x5f9ea0ff,
384
+ chartreuse: 0x7fff00ff,
385
+ chocolate: 0xd2691eff,
386
+ coral: 0xff7f50ff,
387
+ cornflowerblue: 0x6495edff,
388
+ cornsilk: 0xfff8dcff,
389
+ crimson: 0xdc143cff,
390
+ cyan: 0x00ffffff,
391
+ darkblue: 0x00008bff,
392
+ darkcyan: 0x008b8bff,
393
+ darkgoldenrod: 0xb8860bff,
394
+ darkgray: 0xa9a9a9ff,
395
+ darkgreen: 0x006400ff,
396
+ darkgrey: 0xa9a9a9ff,
397
+ darkkhaki: 0xbdb76bff,
398
+ darkmagenta: 0x8b008bff,
399
+ darkolivegreen: 0x556b2fff,
400
+ darkorange: 0xff8c00ff,
401
+ darkorchid: 0x9932ccff,
402
+ darkred: 0x8b0000ff,
403
+ darksalmon: 0xe9967aff,
404
+ darkseagreen: 0x8fbc8fff,
405
+ darkslateblue: 0x483d8bff,
406
+ darkslategray: 0x2f4f4fff,
407
+ darkslategrey: 0x2f4f4fff,
408
+ darkturquoise: 0x00ced1ff,
409
+ darkviolet: 0x9400d3ff,
410
+ deeppink: 0xff1493ff,
411
+ deepskyblue: 0x00bfffff,
412
+ dimgray: 0x696969ff,
413
+ dimgrey: 0x696969ff,
414
+ dodgerblue: 0x1e90ffff,
415
+ firebrick: 0xb22222ff,
416
+ floralwhite: 0xfffaf0ff,
417
+ forestgreen: 0x228b22ff,
418
+ fuchsia: 0xff00ffff,
419
+ gainsboro: 0xdcdcdcff,
420
+ ghostwhite: 0xf8f8ffff,
421
+ gold: 0xffd700ff,
422
+ goldenrod: 0xdaa520ff,
423
+ gray: 0x808080ff,
424
+ green: 0x008000ff,
425
+ greenyellow: 0xadff2fff,
426
+ grey: 0x808080ff,
427
+ honeydew: 0xf0fff0ff,
428
+ hotpink: 0xff69b4ff,
429
+ indianred: 0xcd5c5cff,
430
+ indigo: 0x4b0082ff,
431
+ ivory: 0xfffff0ff,
432
+ khaki: 0xf0e68cff,
433
+ lavender: 0xe6e6faff,
434
+ lavenderblush: 0xfff0f5ff,
435
+ lawngreen: 0x7cfc00ff,
436
+ lemonchiffon: 0xfffacdff,
437
+ lightblue: 0xadd8e6ff,
438
+ lightcoral: 0xf08080ff,
439
+ lightcyan: 0xe0ffffff,
440
+ lightgoldenrodyellow: 0xfafad2ff,
441
+ lightgray: 0xd3d3d3ff,
442
+ lightgreen: 0x90ee90ff,
443
+ lightgrey: 0xd3d3d3ff,
444
+ lightpink: 0xffb6c1ff,
445
+ lightsalmon: 0xffa07aff,
446
+ lightseagreen: 0x20b2aaff,
447
+ lightskyblue: 0x87cefaff,
448
+ lightslategray: 0x778899ff,
449
+ lightslategrey: 0x778899ff,
450
+ lightsteelblue: 0xb0c4deff,
451
+ lightyellow: 0xffffe0ff,
452
+ lime: 0x00ff00ff,
453
+ limegreen: 0x32cd32ff,
454
+ linen: 0xfaf0e6ff,
455
+ magenta: 0xff00ffff,
456
+ maroon: 0x800000ff,
457
+ mediumaquamarine: 0x66cdaaff,
458
+ mediumblue: 0x0000cdff,
459
+ mediumorchid: 0xba55d3ff,
460
+ mediumpurple: 0x9370dbff,
461
+ mediumseagreen: 0x3cb371ff,
462
+ mediumslateblue: 0x7b68eeff,
463
+ mediumspringgreen: 0x00fa9aff,
464
+ mediumturquoise: 0x48d1ccff,
465
+ mediumvioletred: 0xc71585ff,
466
+ midnightblue: 0x191970ff,
467
+ mintcream: 0xf5fffaff,
468
+ mistyrose: 0xffe4e1ff,
469
+ moccasin: 0xffe4b5ff,
470
+ navajowhite: 0xffdeadff,
471
+ navy: 0x000080ff,
472
+ oldlace: 0xfdf5e6ff,
473
+ olive: 0x808000ff,
474
+ olivedrab: 0x6b8e23ff,
475
+ orange: 0xffa500ff,
476
+ orangered: 0xff4500ff,
477
+ orchid: 0xda70d6ff,
478
+ palegoldenrod: 0xeee8aaff,
479
+ palegreen: 0x98fb98ff,
480
+ paleturquoise: 0xafeeeeff,
481
+ palevioletred: 0xdb7093ff,
482
+ papayawhip: 0xffefd5ff,
483
+ peachpuff: 0xffdab9ff,
484
+ peru: 0xcd853fff,
485
+ pink: 0xffc0cbff,
486
+ plum: 0xdda0ddff,
487
+ powderblue: 0xb0e0e6ff,
488
+ purple: 0x800080ff,
489
+ rebeccapurple: 0x663399ff,
490
+ red: 0xff0000ff,
491
+ rosybrown: 0xbc8f8fff,
492
+ royalblue: 0x4169e1ff,
493
+ saddlebrown: 0x8b4513ff,
494
+ salmon: 0xfa8072ff,
495
+ sandybrown: 0xf4a460ff,
496
+ seagreen: 0x2e8b57ff,
497
+ seashell: 0xfff5eeff,
498
+ sienna: 0xa0522dff,
499
+ silver: 0xc0c0c0ff,
500
+ skyblue: 0x87ceebff,
501
+ slateblue: 0x6a5acdff,
502
+ slategray: 0x708090ff,
503
+ slategrey: 0x708090ff,
504
+ snow: 0xfffafaff,
505
+ springgreen: 0x00ff7fff,
506
+ steelblue: 0x4682b4ff,
507
+ tan: 0xd2b48cff,
508
+ teal: 0x008080ff,
509
+ thistle: 0xd8bfd8ff,
510
+ tomato: 0xff6347ff,
511
+ turquoise: 0x40e0d0ff,
512
+ violet: 0xee82eeff,
513
+ wheat: 0xf5deb3ff,
514
+ white: 0xffffffff,
515
+ whitesmoke: 0xf5f5f5ff,
516
+ yellow: 0xffff00ff,
517
+ yellowgreen: 0x9acd32ff
518
+ };
519
+
520
+ const NUMBER = '[-+]?\\d*\\.?\\d+';
521
+ const PERCENTAGE = NUMBER + '%';
522
+
523
+ function call(...parts) {
524
+ return '\\(\\s*(' + parts.join(')\\s*,\\s*(') + ')\\s*\\)';
525
+ }
526
+
527
+ const rgb = new RegExp('rgb' + call(NUMBER, NUMBER, NUMBER));
528
+ const rgba = new RegExp('rgba' + call(NUMBER, NUMBER, NUMBER, NUMBER));
529
+ const hsl = new RegExp('hsl' + call(NUMBER, PERCENTAGE, PERCENTAGE));
530
+ const hsla = new RegExp('hsla' + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER));
531
+ const hex3 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
532
+ const hex4 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
533
+ const hex6 = /^#([0-9a-fA-F]{6})$/;
534
+ const hex8 = /^#([0-9a-fA-F]{8})$/;
535
+
536
+ function normalizeColor(color) {
537
+ let match;
538
+
539
+ if (typeof color === 'number') {
540
+ return color >>> 0 === color && color >= 0 && color <= 0xffffffff ? color : null;
541
+ }
542
+
543
+ if (match = hex6.exec(color)) return parseInt(match[1] + 'ff', 16) >>> 0;
544
+
545
+ if (colors$1 && colors$1[color] !== undefined) {
546
+ return colors$1[color];
547
+ }
548
+
549
+ if (match = rgb.exec(color)) {
550
+ return (parse255(match[1]) << 24 | parse255(match[2]) << 16 | parse255(match[3]) << 8 | 0x000000ff) >>> 0;
551
+ }
552
+
553
+ if (match = rgba.exec(color)) {
554
+ return (parse255(match[1]) << 24 | parse255(match[2]) << 16 | parse255(match[3]) << 8 | parse1(match[4])) >>> 0;
555
+ }
556
+
557
+ if (match = hex3.exec(color)) {
558
+ return parseInt(match[1] + match[1] + match[2] + match[2] + match[3] + match[3] + 'ff', 16) >>> 0;
559
+ }
560
+
561
+ if (match = hex8.exec(color)) return parseInt(match[1], 16) >>> 0;
562
+
563
+ if (match = hex4.exec(color)) {
564
+ return parseInt(match[1] + match[1] + match[2] + match[2] + match[3] + match[3] + match[4] + match[4], 16) >>> 0;
565
+ }
566
+
567
+ if (match = hsl.exec(color)) {
568
+ return (hslToRgb(parse360(match[1]), parsePercentage(match[2]), parsePercentage(match[3])) | 0x000000ff) >>> 0;
569
+ }
570
+
571
+ if (match = hsla.exec(color)) {
572
+ return (hslToRgb(parse360(match[1]), parsePercentage(match[2]), parsePercentage(match[3])) | parse1(match[4])) >>> 0;
573
+ }
574
+
575
+ return null;
576
+ }
577
+
578
+ function hue2rgb(p, q, t) {
579
+ if (t < 0) t += 1;
580
+ if (t > 1) t -= 1;
581
+ if (t < 1 / 6) return p + (q - p) * 6 * t;
582
+ if (t < 1 / 2) return q;
583
+ if (t < 2 / 3) return p + (q - p) * (2 / 3 - t) * 6;
584
+ return p;
585
+ }
586
+
587
+ function hslToRgb(h, s, l) {
588
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
589
+ const p = 2 * l - q;
590
+ const r = hue2rgb(p, q, h + 1 / 3);
591
+ const g = hue2rgb(p, q, h);
592
+ const b = hue2rgb(p, q, h - 1 / 3);
593
+ return Math.round(r * 255) << 24 | Math.round(g * 255) << 16 | Math.round(b * 255) << 8;
594
+ }
595
+
596
+ function parse255(str) {
597
+ const int = parseInt(str, 10);
598
+ if (int < 0) return 0;
599
+ if (int > 255) return 255;
600
+ return int;
601
+ }
602
+
603
+ function parse360(str) {
604
+ const int = parseFloat(str);
605
+ return (int % 360 + 360) % 360 / 360;
606
+ }
607
+
608
+ function parse1(str) {
609
+ const num = parseFloat(str);
610
+ if (num < 0) return 0;
611
+ if (num > 1) return 255;
612
+ return Math.round(num * 255);
613
+ }
614
+
615
+ function parsePercentage(str) {
616
+ const int = parseFloat(str);
617
+ if (int < 0) return 0;
618
+ if (int > 100) return 1;
619
+ return int / 100;
620
+ }
621
+
622
+ function colorToRgba(input) {
623
+ let int32Color = normalizeColor(input);
624
+ if (int32Color === null) return input;
625
+ int32Color = int32Color || 0;
626
+ let r = (int32Color & 0xff000000) >>> 24;
627
+ let g = (int32Color & 0x00ff0000) >>> 16;
628
+ let b = (int32Color & 0x0000ff00) >>> 8;
629
+ let a = (int32Color & 0x000000ff) / 255;
630
+ return `rgba(${r}, ${g}, ${b}, ${a})`;
631
+ }
632
+
633
+ const createInterpolator = (range, output, extrapolate) => {
634
+ if (is.fun(range)) {
635
+ return range;
636
+ }
637
+
638
+ if (is.arr(range)) {
639
+ return createInterpolator({
640
+ range,
641
+ output: output,
642
+ extrapolate
643
+ });
644
+ }
645
+
646
+ if (is.str(range.output[0])) {
647
+ return createStringInterpolator$1(range);
648
+ }
649
+
650
+ const config = range;
651
+ const outputRange = config.output;
652
+ const inputRange = config.range || [0, 1];
653
+ const extrapolateLeft = config.extrapolateLeft || config.extrapolate || 'extend';
654
+ const extrapolateRight = config.extrapolateRight || config.extrapolate || 'extend';
655
+
656
+ const easing = config.easing || (t => t);
657
+
658
+ return input => {
659
+ const range = findRange(input, inputRange);
660
+ return interpolate(input, inputRange[range], inputRange[range + 1], outputRange[range], outputRange[range + 1], easing, extrapolateLeft, extrapolateRight, config.map);
661
+ };
662
+ };
663
+
664
+ function interpolate(input, inputMin, inputMax, outputMin, outputMax, easing, extrapolateLeft, extrapolateRight, map) {
665
+ let result = map ? map(input) : input;
666
+
667
+ if (result < inputMin) {
668
+ if (extrapolateLeft === 'identity') return result;else if (extrapolateLeft === 'clamp') result = inputMin;
669
+ }
670
+
671
+ if (result > inputMax) {
672
+ if (extrapolateRight === 'identity') return result;else if (extrapolateRight === 'clamp') result = inputMax;
673
+ }
674
+
675
+ if (outputMin === outputMax) return outputMin;
676
+ if (inputMin === inputMax) return input <= inputMin ? outputMin : outputMax;
677
+ if (inputMin === -Infinity) result = -result;else if (inputMax === Infinity) result = result - inputMin;else result = (result - inputMin) / (inputMax - inputMin);
678
+ result = easing(result);
679
+ if (outputMin === -Infinity) result = -result;else if (outputMax === Infinity) result = result + outputMin;else result = result * (outputMax - outputMin) + outputMin;
680
+ return result;
681
+ }
682
+
683
+ function findRange(input, inputRange) {
684
+ for (var i = 1; i < inputRange.length - 1; ++i) if (inputRange[i] >= input) break;
685
+
686
+ return i - 1;
687
+ }
688
+
689
+ function _extends$2() {
690
+ _extends$2 = Object.assign ? Object.assign.bind() : function (target) {
691
+ for (var i = 1; i < arguments.length; i++) {
692
+ var source = arguments[i];
693
+
694
+ for (var key in source) {
695
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
696
+ target[key] = source[key];
697
+ }
698
+ }
699
+ }
700
+
701
+ return target;
702
+ };
703
+ return _extends$2.apply(this, arguments);
704
+ }
705
+
706
+ const $get = Symbol.for('FluidValue.get');
707
+ const $observers = Symbol.for('FluidValue.observers');
708
+
709
+ const hasFluidValue = arg => Boolean(arg && arg[$get]);
710
+
711
+ const getFluidValue = arg => arg && arg[$get] ? arg[$get]() : arg;
712
+
713
+ const getFluidObservers = target => target[$observers] || null;
714
+
715
+ function callFluidObserver(observer, event) {
716
+ if (observer.eventObserved) {
717
+ observer.eventObserved(event);
718
+ } else {
719
+ observer(event);
720
+ }
721
+ }
722
+
723
+ function callFluidObservers(target, event) {
724
+ let observers = target[$observers];
725
+
726
+ if (observers) {
727
+ observers.forEach(observer => {
728
+ callFluidObserver(observer, event);
729
+ });
730
+ }
731
+ }
732
+
733
+ class FluidValue {
734
+ constructor(get) {
735
+ this[$get] = void 0;
736
+ this[$observers] = void 0;
737
+
738
+ if (!get && !(get = this.get)) {
739
+ throw Error('Unknown getter');
740
+ }
741
+
742
+ setFluidGetter(this, get);
743
+ }
744
+
745
+ }
746
+
747
+ const setFluidGetter = (target, get) => setHidden(target, $get, get);
748
+
749
+ function addFluidObserver(target, observer) {
750
+ if (target[$get]) {
751
+ let observers = target[$observers];
752
+
753
+ if (!observers) {
754
+ setHidden(target, $observers, observers = new Set());
755
+ }
756
+
757
+ if (!observers.has(observer)) {
758
+ observers.add(observer);
759
+
760
+ if (target.observerAdded) {
761
+ target.observerAdded(observers.size, observer);
762
+ }
763
+ }
764
+ }
765
+
766
+ return observer;
767
+ }
768
+
769
+ function removeFluidObserver(target, observer) {
770
+ let observers = target[$observers];
771
+
772
+ if (observers && observers.has(observer)) {
773
+ const count = observers.size - 1;
774
+
775
+ if (count) {
776
+ observers.delete(observer);
777
+ } else {
778
+ target[$observers] = null;
779
+ }
780
+
781
+ if (target.observerRemoved) {
782
+ target.observerRemoved(count, observer);
783
+ }
784
+ }
785
+ }
786
+
787
+ const setHidden = (target, key, value) => Object.defineProperty(target, key, {
788
+ value,
789
+ writable: true,
790
+ configurable: true
791
+ });
792
+
793
+ const numberRegex = /[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
794
+ const colorRegex = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))/gi;
795
+ const unitRegex = new RegExp(`(${numberRegex.source})(%|[a-z]+)`, 'i');
796
+ const rgbaRegex = /rgba\(([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+)\)/gi;
797
+ const cssVariableRegex = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
798
+
799
+ const variableToRgba = input => {
800
+ const [token, fallback] = parseCSSVariable(input);
801
+
802
+ if (!token || isSSR()) {
803
+ return input;
804
+ }
805
+
806
+ const value = window.getComputedStyle(document.documentElement).getPropertyValue(token);
807
+
808
+ if (value) {
809
+ return value.trim();
810
+ } else if (fallback && fallback.startsWith('--')) {
811
+ const _value = window.getComputedStyle(document.documentElement).getPropertyValue(fallback);
812
+
813
+ if (_value) {
814
+ return _value;
815
+ } else {
816
+ return input;
817
+ }
818
+ } else if (fallback && cssVariableRegex.test(fallback)) {
819
+ return variableToRgba(fallback);
820
+ } else if (fallback) {
821
+ return fallback;
822
+ }
823
+
824
+ return input;
825
+ };
826
+
827
+ const parseCSSVariable = current => {
828
+ const match = cssVariableRegex.exec(current);
829
+ if (!match) return [,];
830
+ const [, token, fallback] = match;
831
+ return [token, fallback];
832
+ };
833
+
834
+ let namedColorRegex;
835
+
836
+ const rgbaRound = (_, p1, p2, p3, p4) => `rgba(${Math.round(p1)}, ${Math.round(p2)}, ${Math.round(p3)}, ${p4})`;
837
+
838
+ const createStringInterpolator = config => {
839
+ if (!namedColorRegex) namedColorRegex = colors$1 ? new RegExp(`(${Object.keys(colors$1).join('|')})(?!\\w)`, 'g') : /^\b$/;
840
+ const output = config.output.map(value => {
841
+ return getFluidValue(value).replace(cssVariableRegex, variableToRgba).replace(colorRegex, colorToRgba).replace(namedColorRegex, colorToRgba);
842
+ });
843
+ const keyframes = output.map(value => value.match(numberRegex).map(Number));
844
+ const outputRanges = keyframes[0].map((_, i) => keyframes.map(values => {
845
+ if (!(i in values)) {
846
+ throw Error('The arity of each "output" value must be equal');
847
+ }
848
+
849
+ return values[i];
850
+ }));
851
+ const interpolators = outputRanges.map(output => createInterpolator(_extends$2({}, config, {
852
+ output
853
+ })));
854
+ return input => {
855
+ var _output$find;
856
+
857
+ const missingUnit = !unitRegex.test(output[0]) && ((_output$find = output.find(value => unitRegex.test(value))) == null ? void 0 : _output$find.replace(numberRegex, ''));
858
+ let i = 0;
859
+ return output[0].replace(numberRegex, () => `${interpolators[i++](input)}${missingUnit || ''}`).replace(rgbaRegex, rgbaRound);
860
+ };
861
+ };
862
+
863
+ const prefix = 'react-spring: ';
864
+
865
+ const once = fn => {
866
+ const func = fn;
867
+ let called = false;
868
+
869
+ if (typeof func != 'function') {
870
+ throw new TypeError(`${prefix}once requires a function parameter`);
871
+ }
872
+
873
+ return (...args) => {
874
+ if (!called) {
875
+ func(...args);
876
+ called = true;
877
+ }
878
+ };
879
+ };
880
+
881
+ const warnInterpolate = once(console.warn);
882
+ function deprecateInterpolate() {
883
+ warnInterpolate(`${prefix}The "interpolate" function is deprecated in v9 (use "to" instead)`);
884
+ }
885
+ const warnDirectCall = once(console.warn);
886
+ function deprecateDirectCall() {
887
+ warnDirectCall(`${prefix}Directly calling start instead of using the api object is deprecated in v9 (use ".start" instead), this will be removed in later 0.X.0 versions`);
888
+ }
889
+
890
+ function isAnimatedString(value) {
891
+ return is.str(value) && (value[0] == '#' || /\d/.test(value) || !isSSR() && cssVariableRegex.test(value) || value in (colors$1 || {}));
892
+ }
893
+
894
+ const useIsomorphicLayoutEffect = isSSR() ? useEffect : useLayoutEffect;
895
+
896
+ const useIsMounted = () => {
897
+ const isMounted = useRef(false);
898
+ useIsomorphicLayoutEffect(() => {
899
+ isMounted.current = true;
900
+ return () => {
901
+ isMounted.current = false;
902
+ };
903
+ }, []);
904
+ return isMounted;
905
+ };
906
+
907
+ function useForceUpdate() {
908
+ const update = useState()[1];
909
+ const isMounted = useIsMounted();
910
+ return () => {
911
+ if (isMounted.current) {
912
+ update(Math.random());
913
+ }
914
+ };
915
+ }
916
+
917
+ function useMemoOne(getResult, inputs) {
918
+ const [initial] = useState(() => ({
919
+ inputs,
920
+ result: getResult()
921
+ }));
922
+ const committed = useRef();
923
+ const prevCache = committed.current;
924
+ let cache = prevCache;
925
+
926
+ if (cache) {
927
+ const useCache = Boolean(inputs && cache.inputs && areInputsEqual(inputs, cache.inputs));
928
+
929
+ if (!useCache) {
930
+ cache = {
931
+ inputs,
932
+ result: getResult()
933
+ };
934
+ }
935
+ } else {
936
+ cache = initial;
937
+ }
938
+
939
+ useEffect(() => {
940
+ committed.current = cache;
941
+
942
+ if (prevCache == initial) {
943
+ initial.inputs = initial.result = undefined;
944
+ }
945
+ }, [cache]);
946
+ return cache.result;
947
+ }
948
+
949
+ function areInputsEqual(next, prev) {
950
+ if (next.length !== prev.length) {
951
+ return false;
952
+ }
953
+
954
+ for (let i = 0; i < next.length; i++) {
955
+ if (next[i] !== prev[i]) {
956
+ return false;
957
+ }
958
+ }
959
+
960
+ return true;
961
+ }
962
+
963
+ const useOnce = effect => useEffect(effect, emptyDeps);
964
+ const emptyDeps = [];
965
+
966
+ function usePrev(value) {
967
+ const prevRef = useRef();
968
+ useEffect(() => {
969
+ prevRef.current = value;
970
+ });
971
+ return prevRef.current;
972
+ }
973
+
974
+ const $node = Symbol.for('Animated:node');
975
+ const isAnimated = value => !!value && value[$node] === value;
976
+ const getAnimated = owner => owner && owner[$node];
977
+ const setAnimated = (owner, node) => defineHidden(owner, $node, node);
978
+ const getPayload = owner => owner && owner[$node] && owner[$node].getPayload();
979
+ class Animated {
980
+ constructor() {
981
+ this.payload = void 0;
982
+ setAnimated(this, this);
983
+ }
984
+
985
+ getPayload() {
986
+ return this.payload || [];
987
+ }
988
+
989
+ }
990
+
991
+ class AnimatedValue extends Animated {
992
+ constructor(_value) {
993
+ super();
994
+ this.done = true;
995
+ this.elapsedTime = void 0;
996
+ this.lastPosition = void 0;
997
+ this.lastVelocity = void 0;
998
+ this.v0 = void 0;
999
+ this.durationProgress = 0;
1000
+ this._value = _value;
1001
+
1002
+ if (is.num(this._value)) {
1003
+ this.lastPosition = this._value;
1004
+ }
1005
+ }
1006
+
1007
+ static create(value) {
1008
+ return new AnimatedValue(value);
1009
+ }
1010
+
1011
+ getPayload() {
1012
+ return [this];
1013
+ }
1014
+
1015
+ getValue() {
1016
+ return this._value;
1017
+ }
1018
+
1019
+ setValue(value, step) {
1020
+ if (is.num(value)) {
1021
+ this.lastPosition = value;
1022
+
1023
+ if (step) {
1024
+ value = Math.round(value / step) * step;
1025
+
1026
+ if (this.done) {
1027
+ this.lastPosition = value;
1028
+ }
1029
+ }
1030
+ }
1031
+
1032
+ if (this._value === value) {
1033
+ return false;
1034
+ }
1035
+
1036
+ this._value = value;
1037
+ return true;
1038
+ }
1039
+
1040
+ reset() {
1041
+ const {
1042
+ done
1043
+ } = this;
1044
+ this.done = false;
1045
+
1046
+ if (is.num(this._value)) {
1047
+ this.elapsedTime = 0;
1048
+ this.durationProgress = 0;
1049
+ this.lastPosition = this._value;
1050
+ if (done) this.lastVelocity = null;
1051
+ this.v0 = null;
1052
+ }
1053
+ }
1054
+
1055
+ }
1056
+
1057
+ class AnimatedString extends AnimatedValue {
1058
+ constructor(value) {
1059
+ super(0);
1060
+ this._string = null;
1061
+ this._toString = void 0;
1062
+ this._toString = createInterpolator({
1063
+ output: [value, value]
1064
+ });
1065
+ }
1066
+
1067
+ static create(value) {
1068
+ return new AnimatedString(value);
1069
+ }
1070
+
1071
+ getValue() {
1072
+ let value = this._string;
1073
+ return value == null ? this._string = this._toString(this._value) : value;
1074
+ }
1075
+
1076
+ setValue(value) {
1077
+ if (is.str(value)) {
1078
+ if (value == this._string) {
1079
+ return false;
1080
+ }
1081
+
1082
+ this._string = value;
1083
+ this._value = 1;
1084
+ } else if (super.setValue(value)) {
1085
+ this._string = null;
1086
+ } else {
1087
+ return false;
1088
+ }
1089
+
1090
+ return true;
1091
+ }
1092
+
1093
+ reset(goal) {
1094
+ if (goal) {
1095
+ this._toString = createInterpolator({
1096
+ output: [this.getValue(), goal]
1097
+ });
1098
+ }
1099
+
1100
+ this._value = 0;
1101
+ super.reset();
1102
+ }
1103
+
1104
+ }
1105
+
1106
+ const TreeContext = {
1107
+ dependencies: null
1108
+ };
1109
+
1110
+ class AnimatedObject extends Animated {
1111
+ constructor(source) {
1112
+ super();
1113
+ this.source = source;
1114
+ this.setValue(source);
1115
+ }
1116
+
1117
+ getValue(animated) {
1118
+ const values = {};
1119
+ eachProp(this.source, (source, key) => {
1120
+ if (isAnimated(source)) {
1121
+ values[key] = source.getValue(animated);
1122
+ } else if (hasFluidValue(source)) {
1123
+ values[key] = getFluidValue(source);
1124
+ } else if (!animated) {
1125
+ values[key] = source;
1126
+ }
1127
+ });
1128
+ return values;
1129
+ }
1130
+
1131
+ setValue(source) {
1132
+ this.source = source;
1133
+ this.payload = this._makePayload(source);
1134
+ }
1135
+
1136
+ reset() {
1137
+ if (this.payload) {
1138
+ each(this.payload, node => node.reset());
1139
+ }
1140
+ }
1141
+
1142
+ _makePayload(source) {
1143
+ if (source) {
1144
+ const payload = new Set();
1145
+ eachProp(source, this._addToPayload, payload);
1146
+ return Array.from(payload);
1147
+ }
1148
+ }
1149
+
1150
+ _addToPayload(source) {
1151
+ if (TreeContext.dependencies && hasFluidValue(source)) {
1152
+ TreeContext.dependencies.add(source);
1153
+ }
1154
+
1155
+ const payload = getPayload(source);
1156
+
1157
+ if (payload) {
1158
+ each(payload, node => this.add(node));
1159
+ }
1160
+ }
1161
+
1162
+ }
1163
+
1164
+ class AnimatedArray extends AnimatedObject {
1165
+ constructor(source) {
1166
+ super(source);
1167
+ }
1168
+
1169
+ static create(source) {
1170
+ return new AnimatedArray(source);
1171
+ }
1172
+
1173
+ getValue() {
1174
+ return this.source.map(node => node.getValue());
1175
+ }
1176
+
1177
+ setValue(source) {
1178
+ const payload = this.getPayload();
1179
+
1180
+ if (source.length == payload.length) {
1181
+ return payload.map((node, i) => node.setValue(source[i])).some(Boolean);
1182
+ }
1183
+
1184
+ super.setValue(source.map(makeAnimated));
1185
+ return true;
1186
+ }
1187
+
1188
+ }
1189
+
1190
+ function makeAnimated(value) {
1191
+ const nodeType = isAnimatedString(value) ? AnimatedString : AnimatedValue;
1192
+ return nodeType.create(value);
1193
+ }
1194
+
1195
+ function getAnimatedType(value) {
1196
+ const parentNode = getAnimated(value);
1197
+ return parentNode ? parentNode.constructor : is.arr(value) ? AnimatedArray : isAnimatedString(value) ? AnimatedString : AnimatedValue;
1198
+ }
1199
+
1200
+ function _extends$1() {
1201
+ _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
1202
+ for (var i = 1; i < arguments.length; i++) {
1203
+ var source = arguments[i];
1204
+
1205
+ for (var key in source) {
1206
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1207
+ target[key] = source[key];
1208
+ }
1209
+ }
1210
+ }
1211
+
1212
+ return target;
1213
+ };
1214
+ return _extends$1.apply(this, arguments);
1215
+ }
1216
+
1217
+ const withAnimated = (Component, host) => {
1218
+ const hasInstance = !is.fun(Component) || Component.prototype && Component.prototype.isReactComponent;
1219
+ return forwardRef((givenProps, givenRef) => {
1220
+ const instanceRef = useRef(null);
1221
+ const ref = hasInstance && useCallback(value => {
1222
+ instanceRef.current = updateRef(givenRef, value);
1223
+ }, [givenRef]);
1224
+ const [props, deps] = getAnimatedState(givenProps, host);
1225
+ const forceUpdate = useForceUpdate();
1226
+
1227
+ const callback = () => {
1228
+ const instance = instanceRef.current;
1229
+
1230
+ if (hasInstance && !instance) {
1231
+ return;
1232
+ }
1233
+
1234
+ const didUpdate = instance ? host.applyAnimatedValues(instance, props.getValue(true)) : false;
1235
+
1236
+ if (didUpdate === false) {
1237
+ forceUpdate();
1238
+ }
1239
+ };
1240
+
1241
+ const observer = new PropsObserver(callback, deps);
1242
+ const observerRef = useRef();
1243
+ useIsomorphicLayoutEffect(() => {
1244
+ observerRef.current = observer;
1245
+ each(deps, dep => addFluidObserver(dep, observer));
1246
+ return () => {
1247
+ if (observerRef.current) {
1248
+ each(observerRef.current.deps, dep => removeFluidObserver(dep, observerRef.current));
1249
+ raf.cancel(observerRef.current.update);
1250
+ }
1251
+ };
1252
+ });
1253
+ useEffect(callback, []);
1254
+ useOnce(() => () => {
1255
+ const observer = observerRef.current;
1256
+ each(observer.deps, dep => removeFluidObserver(dep, observer));
1257
+ });
1258
+ const usedProps = host.getComponentProps(props.getValue());
1259
+ return React.createElement(Component, _extends$1({}, usedProps, {
1260
+ ref: ref
1261
+ }));
1262
+ });
1263
+ };
1264
+
1265
+ class PropsObserver {
1266
+ constructor(update, deps) {
1267
+ this.update = update;
1268
+ this.deps = deps;
1269
+ }
1270
+
1271
+ eventObserved(event) {
1272
+ if (event.type == 'change') {
1273
+ raf.write(this.update);
1274
+ }
1275
+ }
1276
+
1277
+ }
1278
+
1279
+ function getAnimatedState(props, host) {
1280
+ const dependencies = new Set();
1281
+ TreeContext.dependencies = dependencies;
1282
+ if (props.style) props = _extends$1({}, props, {
1283
+ style: host.createAnimatedStyle(props.style)
1284
+ });
1285
+ props = new AnimatedObject(props);
1286
+ TreeContext.dependencies = null;
1287
+ return [props, dependencies];
1288
+ }
1289
+
1290
+ function updateRef(ref, value) {
1291
+ if (ref) {
1292
+ if (is.fun(ref)) ref(value);else ref.current = value;
1293
+ }
1294
+
1295
+ return value;
1296
+ }
1297
+
1298
+ const cacheKey = Symbol.for('AnimatedComponent');
1299
+ const createHost = (components, {
1300
+ applyAnimatedValues: _applyAnimatedValues = () => false,
1301
+ createAnimatedStyle: _createAnimatedStyle = style => new AnimatedObject(style),
1302
+ getComponentProps: _getComponentProps = props => props
1303
+ } = {}) => {
1304
+ const hostConfig = {
1305
+ applyAnimatedValues: _applyAnimatedValues,
1306
+ createAnimatedStyle: _createAnimatedStyle,
1307
+ getComponentProps: _getComponentProps
1308
+ };
1309
+
1310
+ const animated = Component => {
1311
+ const displayName = getDisplayName(Component) || 'Anonymous';
1312
+
1313
+ if (is.str(Component)) {
1314
+ Component = animated[Component] || (animated[Component] = withAnimated(Component, hostConfig));
1315
+ } else {
1316
+ Component = Component[cacheKey] || (Component[cacheKey] = withAnimated(Component, hostConfig));
1317
+ }
1318
+
1319
+ Component.displayName = `Animated(${displayName})`;
1320
+ return Component;
1321
+ };
1322
+
1323
+ eachProp(components, (Component, key) => {
1324
+ if (is.arr(components)) {
1325
+ key = getDisplayName(Component);
1326
+ }
1327
+
1328
+ animated[key] = animated(Component);
1329
+ });
1330
+ return {
1331
+ animated
1332
+ };
1333
+ };
1334
+
1335
+ const getDisplayName = arg => is.str(arg) ? arg : arg && is.str(arg.displayName) ? arg.displayName : is.fun(arg) && arg.name || null;
1336
+
1337
+ function _extends() {
1338
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
1339
+ for (var i = 1; i < arguments.length; i++) {
1340
+ var source = arguments[i];
1341
+
1342
+ for (var key in source) {
1343
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
1344
+ target[key] = source[key];
1345
+ }
1346
+ }
1347
+ }
1348
+
1349
+ return target;
1350
+ };
1351
+ return _extends.apply(this, arguments);
1352
+ }
1353
+
1354
+ function callProp(value, ...args) {
1355
+ return is.fun(value) ? value(...args) : value;
1356
+ }
1357
+ const matchProp = (value, key) => value === true || !!(key && value && (is.fun(value) ? value(key) : toArray(value).includes(key)));
1358
+ const resolveProp = (prop, key) => is.obj(prop) ? key && prop[key] : prop;
1359
+ const getDefaultProp = (props, key) => props.default === true ? props[key] : props.default ? props.default[key] : undefined;
1360
+
1361
+ const noopTransform = value => value;
1362
+
1363
+ const getDefaultProps = (props, transform = noopTransform) => {
1364
+ let keys = DEFAULT_PROPS;
1365
+
1366
+ if (props.default && props.default !== true) {
1367
+ props = props.default;
1368
+ keys = Object.keys(props);
1369
+ }
1370
+
1371
+ const defaults = {};
1372
+
1373
+ for (const key of keys) {
1374
+ const value = transform(props[key], key);
1375
+
1376
+ if (!is.und(value)) {
1377
+ defaults[key] = value;
1378
+ }
1379
+ }
1380
+
1381
+ return defaults;
1382
+ };
1383
+ const DEFAULT_PROPS = ['config', 'onProps', 'onStart', 'onChange', 'onPause', 'onResume', 'onRest'];
1384
+ const RESERVED_PROPS = {
1385
+ config: 1,
1386
+ from: 1,
1387
+ to: 1,
1388
+ ref: 1,
1389
+ loop: 1,
1390
+ reset: 1,
1391
+ pause: 1,
1392
+ cancel: 1,
1393
+ reverse: 1,
1394
+ immediate: 1,
1395
+ default: 1,
1396
+ delay: 1,
1397
+ onProps: 1,
1398
+ onStart: 1,
1399
+ onChange: 1,
1400
+ onPause: 1,
1401
+ onResume: 1,
1402
+ onRest: 1,
1403
+ onResolve: 1,
1404
+ items: 1,
1405
+ trail: 1,
1406
+ sort: 1,
1407
+ expires: 1,
1408
+ initial: 1,
1409
+ enter: 1,
1410
+ update: 1,
1411
+ leave: 1,
1412
+ children: 1,
1413
+ onDestroyed: 1,
1414
+ keys: 1,
1415
+ callId: 1,
1416
+ parentId: 1
1417
+ };
1418
+
1419
+ function getForwardProps(props) {
1420
+ const forward = {};
1421
+ let count = 0;
1422
+ eachProp(props, (value, prop) => {
1423
+ if (!RESERVED_PROPS[prop]) {
1424
+ forward[prop] = value;
1425
+ count++;
1426
+ }
1427
+ });
1428
+
1429
+ if (count) {
1430
+ return forward;
1431
+ }
1432
+ }
1433
+
1434
+ function inferTo(props) {
1435
+ const to = getForwardProps(props);
1436
+
1437
+ if (to) {
1438
+ const out = {
1439
+ to
1440
+ };
1441
+ eachProp(props, (val, key) => key in to || (out[key] = val));
1442
+ return out;
1443
+ }
1444
+
1445
+ return _extends({}, props);
1446
+ }
1447
+ function computeGoal(value) {
1448
+ value = getFluidValue(value);
1449
+ return is.arr(value) ? value.map(computeGoal) : isAnimatedString(value) ? globals.createStringInterpolator({
1450
+ range: [0, 1],
1451
+ output: [value, value]
1452
+ })(1) : value;
1453
+ }
1454
+ function hasProps(props) {
1455
+ for (const _ in props) return true;
1456
+
1457
+ return false;
1458
+ }
1459
+ function isAsyncTo(to) {
1460
+ return is.fun(to) || is.arr(to) && is.obj(to[0]);
1461
+ }
1462
+ function detachRefs(ctrl, ref) {
1463
+ var _ctrl$ref;
1464
+
1465
+ (_ctrl$ref = ctrl.ref) == null ? void 0 : _ctrl$ref.delete(ctrl);
1466
+ ref == null ? void 0 : ref.delete(ctrl);
1467
+ }
1468
+ function replaceRef(ctrl, ref) {
1469
+ if (ref && ctrl.ref !== ref) {
1470
+ var _ctrl$ref2;
1471
+
1472
+ (_ctrl$ref2 = ctrl.ref) == null ? void 0 : _ctrl$ref2.delete(ctrl);
1473
+ ref.add(ctrl);
1474
+ ctrl.ref = ref;
1475
+ }
1476
+ }
1477
+
1478
+ const config = {
1479
+ default: {
1480
+ tension: 170,
1481
+ friction: 26
1482
+ },
1483
+ gentle: {
1484
+ tension: 120,
1485
+ friction: 14
1486
+ },
1487
+ wobbly: {
1488
+ tension: 180,
1489
+ friction: 12
1490
+ },
1491
+ stiff: {
1492
+ tension: 210,
1493
+ friction: 20
1494
+ },
1495
+ slow: {
1496
+ tension: 280,
1497
+ friction: 60
1498
+ },
1499
+ molasses: {
1500
+ tension: 280,
1501
+ friction: 120
1502
+ }
1503
+ };
1504
+ const c1 = 1.70158;
1505
+ const c2 = c1 * 1.525;
1506
+ const c3 = c1 + 1;
1507
+ const c4 = 2 * Math.PI / 3;
1508
+ const c5 = 2 * Math.PI / 4.5;
1509
+
1510
+ const bounceOut = x => {
1511
+ const n1 = 7.5625;
1512
+ const d1 = 2.75;
1513
+
1514
+ if (x < 1 / d1) {
1515
+ return n1 * x * x;
1516
+ } else if (x < 2 / d1) {
1517
+ return n1 * (x -= 1.5 / d1) * x + 0.75;
1518
+ } else if (x < 2.5 / d1) {
1519
+ return n1 * (x -= 2.25 / d1) * x + 0.9375;
1520
+ } else {
1521
+ return n1 * (x -= 2.625 / d1) * x + 0.984375;
1522
+ }
1523
+ };
1524
+
1525
+ const easings = {
1526
+ linear: x => x,
1527
+ easeInQuad: x => x * x,
1528
+ easeOutQuad: x => 1 - (1 - x) * (1 - x),
1529
+ easeInOutQuad: x => x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2,
1530
+ easeInCubic: x => x * x * x,
1531
+ easeOutCubic: x => 1 - Math.pow(1 - x, 3),
1532
+ easeInOutCubic: x => x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2,
1533
+ easeInQuart: x => x * x * x * x,
1534
+ easeOutQuart: x => 1 - Math.pow(1 - x, 4),
1535
+ easeInOutQuart: x => x < 0.5 ? 8 * x * x * x * x : 1 - Math.pow(-2 * x + 2, 4) / 2,
1536
+ easeInQuint: x => x * x * x * x * x,
1537
+ easeOutQuint: x => 1 - Math.pow(1 - x, 5),
1538
+ easeInOutQuint: x => x < 0.5 ? 16 * x * x * x * x * x : 1 - Math.pow(-2 * x + 2, 5) / 2,
1539
+ easeInSine: x => 1 - Math.cos(x * Math.PI / 2),
1540
+ easeOutSine: x => Math.sin(x * Math.PI / 2),
1541
+ easeInOutSine: x => -(Math.cos(Math.PI * x) - 1) / 2,
1542
+ easeInExpo: x => x === 0 ? 0 : Math.pow(2, 10 * x - 10),
1543
+ easeOutExpo: x => x === 1 ? 1 : 1 - Math.pow(2, -10 * x),
1544
+ easeInOutExpo: x => x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? Math.pow(2, 20 * x - 10) / 2 : (2 - Math.pow(2, -20 * x + 10)) / 2,
1545
+ easeInCirc: x => 1 - Math.sqrt(1 - Math.pow(x, 2)),
1546
+ easeOutCirc: x => Math.sqrt(1 - Math.pow(x - 1, 2)),
1547
+ easeInOutCirc: x => x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2,
1548
+ easeInBack: x => c3 * x * x * x - c1 * x * x,
1549
+ easeOutBack: x => 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2),
1550
+ easeInOutBack: x => x < 0.5 ? Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2) / 2 : (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2,
1551
+ easeInElastic: x => x === 0 ? 0 : x === 1 ? 1 : -Math.pow(2, 10 * x - 10) * Math.sin((x * 10 - 10.75) * c4),
1552
+ easeOutElastic: x => x === 0 ? 0 : x === 1 ? 1 : Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * c4) + 1,
1553
+ easeInOutElastic: x => x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? -(Math.pow(2, 20 * x - 10) * Math.sin((20 * x - 11.125) * c5)) / 2 : Math.pow(2, -20 * x + 10) * Math.sin((20 * x - 11.125) * c5) / 2 + 1,
1554
+ easeInBounce: x => 1 - bounceOut(1 - x),
1555
+ easeOutBounce: bounceOut,
1556
+ easeInOutBounce: x => x < 0.5 ? (1 - bounceOut(1 - 2 * x)) / 2 : (1 + bounceOut(2 * x - 1)) / 2
1557
+ };
1558
+
1559
+ const defaults = _extends({}, config.default, {
1560
+ mass: 1,
1561
+ damping: 1,
1562
+ easing: easings.linear,
1563
+ clamp: false
1564
+ });
1565
+
1566
+ class AnimationConfig {
1567
+ constructor() {
1568
+ this.tension = void 0;
1569
+ this.friction = void 0;
1570
+ this.frequency = void 0;
1571
+ this.damping = void 0;
1572
+ this.mass = void 0;
1573
+ this.velocity = 0;
1574
+ this.restVelocity = void 0;
1575
+ this.precision = void 0;
1576
+ this.progress = void 0;
1577
+ this.duration = void 0;
1578
+ this.easing = void 0;
1579
+ this.clamp = void 0;
1580
+ this.bounce = void 0;
1581
+ this.decay = void 0;
1582
+ this.round = void 0;
1583
+ Object.assign(this, defaults);
1584
+ }
1585
+
1586
+ }
1587
+ function mergeConfig(config, newConfig, defaultConfig) {
1588
+ if (defaultConfig) {
1589
+ defaultConfig = _extends({}, defaultConfig);
1590
+ sanitizeConfig(defaultConfig, newConfig);
1591
+ newConfig = _extends({}, defaultConfig, newConfig);
1592
+ }
1593
+
1594
+ sanitizeConfig(config, newConfig);
1595
+ Object.assign(config, newConfig);
1596
+
1597
+ for (const key in defaults) {
1598
+ if (config[key] == null) {
1599
+ config[key] = defaults[key];
1600
+ }
1601
+ }
1602
+
1603
+ let {
1604
+ mass,
1605
+ frequency,
1606
+ damping
1607
+ } = config;
1608
+
1609
+ if (!is.und(frequency)) {
1610
+ if (frequency < 0.01) frequency = 0.01;
1611
+ if (damping < 0) damping = 0;
1612
+ config.tension = Math.pow(2 * Math.PI / frequency, 2) * mass;
1613
+ config.friction = 4 * Math.PI * damping * mass / frequency;
1614
+ }
1615
+
1616
+ return config;
1617
+ }
1618
+
1619
+ function sanitizeConfig(config, props) {
1620
+ if (!is.und(props.decay)) {
1621
+ config.duration = undefined;
1622
+ } else {
1623
+ const isTensionConfig = !is.und(props.tension) || !is.und(props.friction);
1624
+
1625
+ if (isTensionConfig || !is.und(props.frequency) || !is.und(props.damping) || !is.und(props.mass)) {
1626
+ config.duration = undefined;
1627
+ config.decay = undefined;
1628
+ }
1629
+
1630
+ if (isTensionConfig) {
1631
+ config.frequency = undefined;
1632
+ }
1633
+ }
1634
+ }
1635
+
1636
+ const emptyArray = [];
1637
+ class Animation {
1638
+ constructor() {
1639
+ this.changed = false;
1640
+ this.values = emptyArray;
1641
+ this.toValues = null;
1642
+ this.fromValues = emptyArray;
1643
+ this.to = void 0;
1644
+ this.from = void 0;
1645
+ this.config = new AnimationConfig();
1646
+ this.immediate = false;
1647
+ }
1648
+
1649
+ }
1650
+
1651
+ function scheduleProps(callId, {
1652
+ key,
1653
+ props,
1654
+ defaultProps,
1655
+ state,
1656
+ actions
1657
+ }) {
1658
+ return new Promise((resolve, reject) => {
1659
+ var _props$cancel;
1660
+
1661
+ let delay;
1662
+ let timeout;
1663
+ let cancel = matchProp((_props$cancel = props.cancel) != null ? _props$cancel : defaultProps == null ? void 0 : defaultProps.cancel, key);
1664
+
1665
+ if (cancel) {
1666
+ onStart();
1667
+ } else {
1668
+ if (!is.und(props.pause)) {
1669
+ state.paused = matchProp(props.pause, key);
1670
+ }
1671
+
1672
+ let pause = defaultProps == null ? void 0 : defaultProps.pause;
1673
+
1674
+ if (pause !== true) {
1675
+ pause = state.paused || matchProp(pause, key);
1676
+ }
1677
+
1678
+ delay = callProp(props.delay || 0, key);
1679
+
1680
+ if (pause) {
1681
+ state.resumeQueue.add(onResume);
1682
+ actions.pause();
1683
+ } else {
1684
+ actions.resume();
1685
+ onResume();
1686
+ }
1687
+ }
1688
+
1689
+ function onPause() {
1690
+ state.resumeQueue.add(onResume);
1691
+ state.timeouts.delete(timeout);
1692
+ timeout.cancel();
1693
+ delay = timeout.time - raf.now();
1694
+ }
1695
+
1696
+ function onResume() {
1697
+ if (delay > 0 && !globals.skipAnimation) {
1698
+ state.delayed = true;
1699
+ timeout = raf.setTimeout(onStart, delay);
1700
+ state.pauseQueue.add(onPause);
1701
+ state.timeouts.add(timeout);
1702
+ } else {
1703
+ onStart();
1704
+ }
1705
+ }
1706
+
1707
+ function onStart() {
1708
+ if (state.delayed) {
1709
+ state.delayed = false;
1710
+ }
1711
+
1712
+ state.pauseQueue.delete(onPause);
1713
+ state.timeouts.delete(timeout);
1714
+
1715
+ if (callId <= (state.cancelId || 0)) {
1716
+ cancel = true;
1717
+ }
1718
+
1719
+ try {
1720
+ actions.start(_extends({}, props, {
1721
+ callId,
1722
+ cancel
1723
+ }), resolve);
1724
+ } catch (err) {
1725
+ reject(err);
1726
+ }
1727
+ }
1728
+ });
1729
+ }
1730
+
1731
+ const getCombinedResult = (target, results) => results.length == 1 ? results[0] : results.some(result => result.cancelled) ? getCancelledResult(target.get()) : results.every(result => result.noop) ? getNoopResult(target.get()) : getFinishedResult(target.get(), results.every(result => result.finished));
1732
+ const getNoopResult = value => ({
1733
+ value,
1734
+ noop: true,
1735
+ finished: true,
1736
+ cancelled: false
1737
+ });
1738
+ const getFinishedResult = (value, finished, cancelled = false) => ({
1739
+ value,
1740
+ finished,
1741
+ cancelled
1742
+ });
1743
+ const getCancelledResult = value => ({
1744
+ value,
1745
+ cancelled: true,
1746
+ finished: false
1747
+ });
1748
+
1749
+ function runAsync(to, props, state, target) {
1750
+ const {
1751
+ callId,
1752
+ parentId,
1753
+ onRest
1754
+ } = props;
1755
+ const {
1756
+ asyncTo: prevTo,
1757
+ promise: prevPromise
1758
+ } = state;
1759
+
1760
+ if (!parentId && to === prevTo && !props.reset) {
1761
+ return prevPromise;
1762
+ }
1763
+
1764
+ return state.promise = (async () => {
1765
+ state.asyncId = callId;
1766
+ state.asyncTo = to;
1767
+ const defaultProps = getDefaultProps(props, (value, key) => key === 'onRest' ? undefined : value);
1768
+ let preventBail;
1769
+ let bail;
1770
+ const bailPromise = new Promise((resolve, reject) => (preventBail = resolve, bail = reject));
1771
+
1772
+ const bailIfEnded = bailSignal => {
1773
+ const bailResult = callId <= (state.cancelId || 0) && getCancelledResult(target) || callId !== state.asyncId && getFinishedResult(target, false);
1774
+
1775
+ if (bailResult) {
1776
+ bailSignal.result = bailResult;
1777
+ bail(bailSignal);
1778
+ throw bailSignal;
1779
+ }
1780
+ };
1781
+
1782
+ const animate = (arg1, arg2) => {
1783
+ const bailSignal = new BailSignal();
1784
+ const skipAnimationSignal = new SkipAniamtionSignal();
1785
+ return (async () => {
1786
+ if (globals.skipAnimation) {
1787
+ stopAsync(state);
1788
+ skipAnimationSignal.result = getFinishedResult(target, false);
1789
+ bail(skipAnimationSignal);
1790
+ throw skipAnimationSignal;
1791
+ }
1792
+
1793
+ bailIfEnded(bailSignal);
1794
+ const props = is.obj(arg1) ? _extends({}, arg1) : _extends({}, arg2, {
1795
+ to: arg1
1796
+ });
1797
+ props.parentId = callId;
1798
+ eachProp(defaultProps, (value, key) => {
1799
+ if (is.und(props[key])) {
1800
+ props[key] = value;
1801
+ }
1802
+ });
1803
+ const result = await target.start(props);
1804
+ bailIfEnded(bailSignal);
1805
+
1806
+ if (state.paused) {
1807
+ await new Promise(resume => {
1808
+ state.resumeQueue.add(resume);
1809
+ });
1810
+ }
1811
+
1812
+ return result;
1813
+ })();
1814
+ };
1815
+
1816
+ let result;
1817
+
1818
+ if (globals.skipAnimation) {
1819
+ stopAsync(state);
1820
+ return getFinishedResult(target, false);
1821
+ }
1822
+
1823
+ try {
1824
+ let animating;
1825
+
1826
+ if (is.arr(to)) {
1827
+ animating = (async queue => {
1828
+ for (const props of queue) {
1829
+ await animate(props);
1830
+ }
1831
+ })(to);
1832
+ } else {
1833
+ animating = Promise.resolve(to(animate, target.stop.bind(target)));
1834
+ }
1835
+
1836
+ await Promise.all([animating.then(preventBail), bailPromise]);
1837
+ result = getFinishedResult(target.get(), true, false);
1838
+ } catch (err) {
1839
+ if (err instanceof BailSignal) {
1840
+ result = err.result;
1841
+ } else if (err instanceof SkipAniamtionSignal) {
1842
+ result = err.result;
1843
+ } else {
1844
+ throw err;
1845
+ }
1846
+ } finally {
1847
+ if (callId == state.asyncId) {
1848
+ state.asyncId = parentId;
1849
+ state.asyncTo = parentId ? prevTo : undefined;
1850
+ state.promise = parentId ? prevPromise : undefined;
1851
+ }
1852
+ }
1853
+
1854
+ if (is.fun(onRest)) {
1855
+ raf.batchedUpdates(() => {
1856
+ onRest(result, target, target.item);
1857
+ });
1858
+ }
1859
+
1860
+ return result;
1861
+ })();
1862
+ }
1863
+ function stopAsync(state, cancelId) {
1864
+ flush(state.timeouts, t => t.cancel());
1865
+ state.pauseQueue.clear();
1866
+ state.resumeQueue.clear();
1867
+ state.asyncId = state.asyncTo = state.promise = undefined;
1868
+ if (cancelId) state.cancelId = cancelId;
1869
+ }
1870
+ class BailSignal extends Error {
1871
+ constructor() {
1872
+ super('An async animation has been interrupted. You see this error because you ' + 'forgot to use `await` or `.catch(...)` on its returned promise.');
1873
+ this.result = void 0;
1874
+ }
1875
+
1876
+ }
1877
+ class SkipAniamtionSignal extends Error {
1878
+ constructor() {
1879
+ super('SkipAnimationSignal');
1880
+ this.result = void 0;
1881
+ }
1882
+
1883
+ }
1884
+
1885
+ const isFrameValue = value => value instanceof FrameValue;
1886
+ let nextId$1 = 1;
1887
+ class FrameValue extends FluidValue {
1888
+ constructor(...args) {
1889
+ super(...args);
1890
+ this.id = nextId$1++;
1891
+ this.key = void 0;
1892
+ this._priority = 0;
1893
+ }
1894
+
1895
+ get priority() {
1896
+ return this._priority;
1897
+ }
1898
+
1899
+ set priority(priority) {
1900
+ if (this._priority != priority) {
1901
+ this._priority = priority;
1902
+
1903
+ this._onPriorityChange(priority);
1904
+ }
1905
+ }
1906
+
1907
+ get() {
1908
+ const node = getAnimated(this);
1909
+ return node && node.getValue();
1910
+ }
1911
+
1912
+ to(...args) {
1913
+ return globals.to(this, args);
1914
+ }
1915
+
1916
+ interpolate(...args) {
1917
+ deprecateInterpolate();
1918
+ return globals.to(this, args);
1919
+ }
1920
+
1921
+ toJSON() {
1922
+ return this.get();
1923
+ }
1924
+
1925
+ observerAdded(count) {
1926
+ if (count == 1) this._attach();
1927
+ }
1928
+
1929
+ observerRemoved(count) {
1930
+ if (count == 0) this._detach();
1931
+ }
1932
+
1933
+ _attach() {}
1934
+
1935
+ _detach() {}
1936
+
1937
+ _onChange(value, idle = false) {
1938
+ callFluidObservers(this, {
1939
+ type: 'change',
1940
+ parent: this,
1941
+ value,
1942
+ idle
1943
+ });
1944
+ }
1945
+
1946
+ _onPriorityChange(priority) {
1947
+ if (!this.idle) {
1948
+ frameLoop.sort(this);
1949
+ }
1950
+
1951
+ callFluidObservers(this, {
1952
+ type: 'priority',
1953
+ parent: this,
1954
+ priority
1955
+ });
1956
+ }
1957
+
1958
+ }
1959
+
1960
+ const $P = Symbol.for('SpringPhase');
1961
+ const HAS_ANIMATED = 1;
1962
+ const IS_ANIMATING = 2;
1963
+ const IS_PAUSED = 4;
1964
+ const hasAnimated = target => (target[$P] & HAS_ANIMATED) > 0;
1965
+ const isAnimating = target => (target[$P] & IS_ANIMATING) > 0;
1966
+ const isPaused = target => (target[$P] & IS_PAUSED) > 0;
1967
+ const setActiveBit = (target, active) => active ? target[$P] |= IS_ANIMATING | HAS_ANIMATED : target[$P] &= ~IS_ANIMATING;
1968
+ const setPausedBit = (target, paused) => paused ? target[$P] |= IS_PAUSED : target[$P] &= ~IS_PAUSED;
1969
+
1970
+ class SpringValue extends FrameValue {
1971
+ constructor(arg1, arg2) {
1972
+ super();
1973
+ this.key = void 0;
1974
+ this.animation = new Animation();
1975
+ this.queue = void 0;
1976
+ this.defaultProps = {};
1977
+ this._state = {
1978
+ paused: false,
1979
+ delayed: false,
1980
+ pauseQueue: new Set(),
1981
+ resumeQueue: new Set(),
1982
+ timeouts: new Set()
1983
+ };
1984
+ this._pendingCalls = new Set();
1985
+ this._lastCallId = 0;
1986
+ this._lastToId = 0;
1987
+ this._memoizedDuration = 0;
1988
+
1989
+ if (!is.und(arg1) || !is.und(arg2)) {
1990
+ const props = is.obj(arg1) ? _extends({}, arg1) : _extends({}, arg2, {
1991
+ from: arg1
1992
+ });
1993
+
1994
+ if (is.und(props.default)) {
1995
+ props.default = true;
1996
+ }
1997
+
1998
+ this.start(props);
1999
+ }
2000
+ }
2001
+
2002
+ get idle() {
2003
+ return !(isAnimating(this) || this._state.asyncTo) || isPaused(this);
2004
+ }
2005
+
2006
+ get goal() {
2007
+ return getFluidValue(this.animation.to);
2008
+ }
2009
+
2010
+ get velocity() {
2011
+ const node = getAnimated(this);
2012
+ return node instanceof AnimatedValue ? node.lastVelocity || 0 : node.getPayload().map(node => node.lastVelocity || 0);
2013
+ }
2014
+
2015
+ get hasAnimated() {
2016
+ return hasAnimated(this);
2017
+ }
2018
+
2019
+ get isAnimating() {
2020
+ return isAnimating(this);
2021
+ }
2022
+
2023
+ get isPaused() {
2024
+ return isPaused(this);
2025
+ }
2026
+
2027
+ get isDelayed() {
2028
+ return this._state.delayed;
2029
+ }
2030
+
2031
+ advance(dt) {
2032
+ let idle = true;
2033
+ let changed = false;
2034
+ const anim = this.animation;
2035
+ let {
2036
+ config,
2037
+ toValues
2038
+ } = anim;
2039
+ const payload = getPayload(anim.to);
2040
+
2041
+ if (!payload && hasFluidValue(anim.to)) {
2042
+ toValues = toArray(getFluidValue(anim.to));
2043
+ }
2044
+
2045
+ anim.values.forEach((node, i) => {
2046
+ if (node.done) return;
2047
+ const to = node.constructor == AnimatedString ? 1 : payload ? payload[i].lastPosition : toValues[i];
2048
+ let finished = anim.immediate;
2049
+ let position = to;
2050
+
2051
+ if (!finished) {
2052
+ position = node.lastPosition;
2053
+
2054
+ if (config.tension <= 0) {
2055
+ node.done = true;
2056
+ return;
2057
+ }
2058
+
2059
+ let elapsed = node.elapsedTime += dt;
2060
+ const from = anim.fromValues[i];
2061
+ const v0 = node.v0 != null ? node.v0 : node.v0 = is.arr(config.velocity) ? config.velocity[i] : config.velocity;
2062
+ let velocity;
2063
+ const precision = config.precision || (from == to ? 0.005 : Math.min(1, Math.abs(to - from) * 0.001));
2064
+
2065
+ if (!is.und(config.duration)) {
2066
+ let p = 1;
2067
+
2068
+ if (config.duration > 0) {
2069
+ if (this._memoizedDuration !== config.duration) {
2070
+ this._memoizedDuration = config.duration;
2071
+
2072
+ if (node.durationProgress > 0) {
2073
+ node.elapsedTime = config.duration * node.durationProgress;
2074
+ elapsed = node.elapsedTime += dt;
2075
+ }
2076
+ }
2077
+
2078
+ p = (config.progress || 0) + elapsed / this._memoizedDuration;
2079
+ p = p > 1 ? 1 : p < 0 ? 0 : p;
2080
+ node.durationProgress = p;
2081
+ }
2082
+
2083
+ position = from + config.easing(p) * (to - from);
2084
+ velocity = (position - node.lastPosition) / dt;
2085
+ finished = p == 1;
2086
+ } else if (config.decay) {
2087
+ const decay = config.decay === true ? 0.998 : config.decay;
2088
+ const e = Math.exp(-(1 - decay) * elapsed);
2089
+ position = from + v0 / (1 - decay) * (1 - e);
2090
+ finished = Math.abs(node.lastPosition - position) <= precision;
2091
+ velocity = v0 * e;
2092
+ } else {
2093
+ velocity = node.lastVelocity == null ? v0 : node.lastVelocity;
2094
+ const restVelocity = config.restVelocity || precision / 10;
2095
+ const bounceFactor = config.clamp ? 0 : config.bounce;
2096
+ const canBounce = !is.und(bounceFactor);
2097
+ const isGrowing = from == to ? node.v0 > 0 : from < to;
2098
+ let isMoving;
2099
+ let isBouncing = false;
2100
+ const step = 1;
2101
+ const numSteps = Math.ceil(dt / step);
2102
+
2103
+ for (let n = 0; n < numSteps; ++n) {
2104
+ isMoving = Math.abs(velocity) > restVelocity;
2105
+
2106
+ if (!isMoving) {
2107
+ finished = Math.abs(to - position) <= precision;
2108
+
2109
+ if (finished) {
2110
+ break;
2111
+ }
2112
+ }
2113
+
2114
+ if (canBounce) {
2115
+ isBouncing = position == to || position > to == isGrowing;
2116
+
2117
+ if (isBouncing) {
2118
+ velocity = -velocity * bounceFactor;
2119
+ position = to;
2120
+ }
2121
+ }
2122
+
2123
+ const springForce = -config.tension * 0.000001 * (position - to);
2124
+ const dampingForce = -config.friction * 0.001 * velocity;
2125
+ const acceleration = (springForce + dampingForce) / config.mass;
2126
+ velocity = velocity + acceleration * step;
2127
+ position = position + velocity * step;
2128
+ }
2129
+ }
2130
+
2131
+ node.lastVelocity = velocity;
2132
+
2133
+ if (Number.isNaN(position)) {
2134
+ console.warn(`Got NaN while animating:`, this);
2135
+ finished = true;
2136
+ }
2137
+ }
2138
+
2139
+ if (payload && !payload[i].done) {
2140
+ finished = false;
2141
+ }
2142
+
2143
+ if (finished) {
2144
+ node.done = true;
2145
+ } else {
2146
+ idle = false;
2147
+ }
2148
+
2149
+ if (node.setValue(position, config.round)) {
2150
+ changed = true;
2151
+ }
2152
+ });
2153
+ const node = getAnimated(this);
2154
+ const currVal = node.getValue();
2155
+
2156
+ if (idle) {
2157
+ const finalVal = getFluidValue(anim.to);
2158
+
2159
+ if ((currVal !== finalVal || changed) && !config.decay) {
2160
+ node.setValue(finalVal);
2161
+
2162
+ this._onChange(finalVal);
2163
+ } else if (changed && config.decay) {
2164
+ this._onChange(currVal);
2165
+ }
2166
+
2167
+ this._stop();
2168
+ } else if (changed) {
2169
+ this._onChange(currVal);
2170
+ }
2171
+ }
2172
+
2173
+ set(value) {
2174
+ raf.batchedUpdates(() => {
2175
+ this._stop();
2176
+
2177
+ this._focus(value);
2178
+
2179
+ this._set(value);
2180
+ });
2181
+ return this;
2182
+ }
2183
+
2184
+ pause() {
2185
+ this._update({
2186
+ pause: true
2187
+ });
2188
+ }
2189
+
2190
+ resume() {
2191
+ this._update({
2192
+ pause: false
2193
+ });
2194
+ }
2195
+
2196
+ finish() {
2197
+ if (isAnimating(this)) {
2198
+ const {
2199
+ to,
2200
+ config
2201
+ } = this.animation;
2202
+ raf.batchedUpdates(() => {
2203
+ this._onStart();
2204
+
2205
+ if (!config.decay) {
2206
+ this._set(to, false);
2207
+ }
2208
+
2209
+ this._stop();
2210
+ });
2211
+ }
2212
+
2213
+ return this;
2214
+ }
2215
+
2216
+ update(props) {
2217
+ const queue = this.queue || (this.queue = []);
2218
+ queue.push(props);
2219
+ return this;
2220
+ }
2221
+
2222
+ start(to, arg2) {
2223
+ let queue;
2224
+
2225
+ if (!is.und(to)) {
2226
+ queue = [is.obj(to) ? to : _extends({}, arg2, {
2227
+ to
2228
+ })];
2229
+ } else {
2230
+ queue = this.queue || [];
2231
+ this.queue = [];
2232
+ }
2233
+
2234
+ return Promise.all(queue.map(props => {
2235
+ const up = this._update(props);
2236
+
2237
+ return up;
2238
+ })).then(results => getCombinedResult(this, results));
2239
+ }
2240
+
2241
+ stop(cancel) {
2242
+ const {
2243
+ to
2244
+ } = this.animation;
2245
+
2246
+ this._focus(this.get());
2247
+
2248
+ stopAsync(this._state, cancel && this._lastCallId);
2249
+ raf.batchedUpdates(() => this._stop(to, cancel));
2250
+ return this;
2251
+ }
2252
+
2253
+ reset() {
2254
+ this._update({
2255
+ reset: true
2256
+ });
2257
+ }
2258
+
2259
+ eventObserved(event) {
2260
+ if (event.type == 'change') {
2261
+ this._start();
2262
+ } else if (event.type == 'priority') {
2263
+ this.priority = event.priority + 1;
2264
+ }
2265
+ }
2266
+
2267
+ _prepareNode(props) {
2268
+ const key = this.key || '';
2269
+ let {
2270
+ to,
2271
+ from
2272
+ } = props;
2273
+ to = is.obj(to) ? to[key] : to;
2274
+
2275
+ if (to == null || isAsyncTo(to)) {
2276
+ to = undefined;
2277
+ }
2278
+
2279
+ from = is.obj(from) ? from[key] : from;
2280
+
2281
+ if (from == null) {
2282
+ from = undefined;
2283
+ }
2284
+
2285
+ const range = {
2286
+ to,
2287
+ from
2288
+ };
2289
+
2290
+ if (!hasAnimated(this)) {
2291
+ if (props.reverse) [to, from] = [from, to];
2292
+ from = getFluidValue(from);
2293
+
2294
+ if (!is.und(from)) {
2295
+ this._set(from);
2296
+ } else if (!getAnimated(this)) {
2297
+ this._set(to);
2298
+ }
2299
+ }
2300
+
2301
+ return range;
2302
+ }
2303
+
2304
+ _update(_ref, isLoop) {
2305
+ let props = _extends({}, _ref);
2306
+
2307
+ const {
2308
+ key,
2309
+ defaultProps
2310
+ } = this;
2311
+ if (props.default) Object.assign(defaultProps, getDefaultProps(props, (value, prop) => /^on/.test(prop) ? resolveProp(value, key) : value));
2312
+ mergeActiveFn(this, props, 'onProps');
2313
+ sendEvent(this, 'onProps', props, this);
2314
+
2315
+ const range = this._prepareNode(props);
2316
+
2317
+ if (Object.isFrozen(this)) {
2318
+ throw Error('Cannot animate a `SpringValue` object that is frozen. ' + 'Did you forget to pass your component to `animated(...)` before animating its props?');
2319
+ }
2320
+
2321
+ const state = this._state;
2322
+ return scheduleProps(++this._lastCallId, {
2323
+ key,
2324
+ props,
2325
+ defaultProps,
2326
+ state,
2327
+ actions: {
2328
+ pause: () => {
2329
+ if (!isPaused(this)) {
2330
+ setPausedBit(this, true);
2331
+ flushCalls(state.pauseQueue);
2332
+ sendEvent(this, 'onPause', getFinishedResult(this, checkFinished(this, this.animation.to)), this);
2333
+ }
2334
+ },
2335
+ resume: () => {
2336
+ if (isPaused(this)) {
2337
+ setPausedBit(this, false);
2338
+
2339
+ if (isAnimating(this)) {
2340
+ this._resume();
2341
+ }
2342
+
2343
+ flushCalls(state.resumeQueue);
2344
+ sendEvent(this, 'onResume', getFinishedResult(this, checkFinished(this, this.animation.to)), this);
2345
+ }
2346
+ },
2347
+ start: this._merge.bind(this, range)
2348
+ }
2349
+ }).then(result => {
2350
+ if (props.loop && result.finished && !(isLoop && result.noop)) {
2351
+ const nextProps = createLoopUpdate(props);
2352
+
2353
+ if (nextProps) {
2354
+ return this._update(nextProps, true);
2355
+ }
2356
+ }
2357
+
2358
+ return result;
2359
+ });
2360
+ }
2361
+
2362
+ _merge(range, props, resolve) {
2363
+ if (props.cancel) {
2364
+ this.stop(true);
2365
+ return resolve(getCancelledResult(this));
2366
+ }
2367
+
2368
+ const hasToProp = !is.und(range.to);
2369
+ const hasFromProp = !is.und(range.from);
2370
+
2371
+ if (hasToProp || hasFromProp) {
2372
+ if (props.callId > this._lastToId) {
2373
+ this._lastToId = props.callId;
2374
+ } else {
2375
+ return resolve(getCancelledResult(this));
2376
+ }
2377
+ }
2378
+
2379
+ const {
2380
+ key,
2381
+ defaultProps,
2382
+ animation: anim
2383
+ } = this;
2384
+ const {
2385
+ to: prevTo,
2386
+ from: prevFrom
2387
+ } = anim;
2388
+ let {
2389
+ to = prevTo,
2390
+ from = prevFrom
2391
+ } = range;
2392
+
2393
+ if (hasFromProp && !hasToProp && (!props.default || is.und(to))) {
2394
+ to = from;
2395
+ }
2396
+
2397
+ if (props.reverse) [to, from] = [from, to];
2398
+ const hasFromChanged = !isEqual(from, prevFrom);
2399
+
2400
+ if (hasFromChanged) {
2401
+ anim.from = from;
2402
+ }
2403
+
2404
+ from = getFluidValue(from);
2405
+ const hasToChanged = !isEqual(to, prevTo);
2406
+
2407
+ if (hasToChanged) {
2408
+ this._focus(to);
2409
+ }
2410
+
2411
+ const hasAsyncTo = isAsyncTo(props.to);
2412
+ const {
2413
+ config
2414
+ } = anim;
2415
+ const {
2416
+ decay,
2417
+ velocity
2418
+ } = config;
2419
+
2420
+ if (hasToProp || hasFromProp) {
2421
+ config.velocity = 0;
2422
+ }
2423
+
2424
+ if (props.config && !hasAsyncTo) {
2425
+ mergeConfig(config, callProp(props.config, key), props.config !== defaultProps.config ? callProp(defaultProps.config, key) : void 0);
2426
+ }
2427
+
2428
+ let node = getAnimated(this);
2429
+
2430
+ if (!node || is.und(to)) {
2431
+ return resolve(getFinishedResult(this, true));
2432
+ }
2433
+
2434
+ const reset = is.und(props.reset) ? hasFromProp && !props.default : !is.und(from) && matchProp(props.reset, key);
2435
+ const value = reset ? from : this.get();
2436
+ const goal = computeGoal(to);
2437
+ const isAnimatable = is.num(goal) || is.arr(goal) || isAnimatedString(goal);
2438
+ const immediate = !hasAsyncTo && (!isAnimatable || matchProp(defaultProps.immediate || props.immediate, key));
2439
+
2440
+ if (hasToChanged) {
2441
+ const nodeType = getAnimatedType(to);
2442
+
2443
+ if (nodeType !== node.constructor) {
2444
+ if (immediate) {
2445
+ node = this._set(goal);
2446
+ } else throw Error(`Cannot animate between ${node.constructor.name} and ${nodeType.name}, as the "to" prop suggests`);
2447
+ }
2448
+ }
2449
+
2450
+ const goalType = node.constructor;
2451
+ let started = hasFluidValue(to);
2452
+ let finished = false;
2453
+
2454
+ if (!started) {
2455
+ const hasValueChanged = reset || !hasAnimated(this) && hasFromChanged;
2456
+
2457
+ if (hasToChanged || hasValueChanged) {
2458
+ finished = isEqual(computeGoal(value), goal);
2459
+ started = !finished;
2460
+ }
2461
+
2462
+ if (!isEqual(anim.immediate, immediate) && !immediate || !isEqual(config.decay, decay) || !isEqual(config.velocity, velocity)) {
2463
+ started = true;
2464
+ }
2465
+ }
2466
+
2467
+ if (finished && isAnimating(this)) {
2468
+ if (anim.changed && !reset) {
2469
+ started = true;
2470
+ } else if (!started) {
2471
+ this._stop(prevTo);
2472
+ }
2473
+ }
2474
+
2475
+ if (!hasAsyncTo) {
2476
+ if (started || hasFluidValue(prevTo)) {
2477
+ anim.values = node.getPayload();
2478
+ anim.toValues = hasFluidValue(to) ? null : goalType == AnimatedString ? [1] : toArray(goal);
2479
+ }
2480
+
2481
+ if (anim.immediate != immediate) {
2482
+ anim.immediate = immediate;
2483
+
2484
+ if (!immediate && !reset) {
2485
+ this._set(prevTo);
2486
+ }
2487
+ }
2488
+
2489
+ if (started) {
2490
+ const {
2491
+ onRest
2492
+ } = anim;
2493
+ each(ACTIVE_EVENTS, type => mergeActiveFn(this, props, type));
2494
+ const result = getFinishedResult(this, checkFinished(this, prevTo));
2495
+ flushCalls(this._pendingCalls, result);
2496
+
2497
+ this._pendingCalls.add(resolve);
2498
+
2499
+ if (anim.changed) raf.batchedUpdates(() => {
2500
+ anim.changed = !reset;
2501
+ onRest == null ? void 0 : onRest(result, this);
2502
+
2503
+ if (reset) {
2504
+ callProp(defaultProps.onRest, result);
2505
+ } else {
2506
+ anim.onStart == null ? void 0 : anim.onStart(result, this);
2507
+ }
2508
+ });
2509
+ }
2510
+ }
2511
+
2512
+ if (reset) {
2513
+ this._set(value);
2514
+ }
2515
+
2516
+ if (hasAsyncTo) {
2517
+ resolve(runAsync(props.to, props, this._state, this));
2518
+ } else if (started) {
2519
+ this._start();
2520
+ } else if (isAnimating(this) && !hasToChanged) {
2521
+ this._pendingCalls.add(resolve);
2522
+ } else {
2523
+ resolve(getNoopResult(value));
2524
+ }
2525
+ }
2526
+
2527
+ _focus(value) {
2528
+ const anim = this.animation;
2529
+
2530
+ if (value !== anim.to) {
2531
+ if (getFluidObservers(this)) {
2532
+ this._detach();
2533
+ }
2534
+
2535
+ anim.to = value;
2536
+
2537
+ if (getFluidObservers(this)) {
2538
+ this._attach();
2539
+ }
2540
+ }
2541
+ }
2542
+
2543
+ _attach() {
2544
+ let priority = 0;
2545
+ const {
2546
+ to
2547
+ } = this.animation;
2548
+
2549
+ if (hasFluidValue(to)) {
2550
+ addFluidObserver(to, this);
2551
+
2552
+ if (isFrameValue(to)) {
2553
+ priority = to.priority + 1;
2554
+ }
2555
+ }
2556
+
2557
+ this.priority = priority;
2558
+ }
2559
+
2560
+ _detach() {
2561
+ const {
2562
+ to
2563
+ } = this.animation;
2564
+
2565
+ if (hasFluidValue(to)) {
2566
+ removeFluidObserver(to, this);
2567
+ }
2568
+ }
2569
+
2570
+ _set(arg, idle = true) {
2571
+ const value = getFluidValue(arg);
2572
+
2573
+ if (!is.und(value)) {
2574
+ const oldNode = getAnimated(this);
2575
+
2576
+ if (!oldNode || !isEqual(value, oldNode.getValue())) {
2577
+ const nodeType = getAnimatedType(value);
2578
+
2579
+ if (!oldNode || oldNode.constructor != nodeType) {
2580
+ setAnimated(this, nodeType.create(value));
2581
+ } else {
2582
+ oldNode.setValue(value);
2583
+ }
2584
+
2585
+ if (oldNode) {
2586
+ raf.batchedUpdates(() => {
2587
+ this._onChange(value, idle);
2588
+ });
2589
+ }
2590
+ }
2591
+ }
2592
+
2593
+ return getAnimated(this);
2594
+ }
2595
+
2596
+ _onStart() {
2597
+ const anim = this.animation;
2598
+
2599
+ if (!anim.changed) {
2600
+ anim.changed = true;
2601
+ sendEvent(this, 'onStart', getFinishedResult(this, checkFinished(this, anim.to)), this);
2602
+ }
2603
+ }
2604
+
2605
+ _onChange(value, idle) {
2606
+ if (!idle) {
2607
+ this._onStart();
2608
+
2609
+ callProp(this.animation.onChange, value, this);
2610
+ }
2611
+
2612
+ callProp(this.defaultProps.onChange, value, this);
2613
+
2614
+ super._onChange(value, idle);
2615
+ }
2616
+
2617
+ _start() {
2618
+ const anim = this.animation;
2619
+ getAnimated(this).reset(getFluidValue(anim.to));
2620
+
2621
+ if (!anim.immediate) {
2622
+ anim.fromValues = anim.values.map(node => node.lastPosition);
2623
+ }
2624
+
2625
+ if (!isAnimating(this)) {
2626
+ setActiveBit(this, true);
2627
+
2628
+ if (!isPaused(this)) {
2629
+ this._resume();
2630
+ }
2631
+ }
2632
+ }
2633
+
2634
+ _resume() {
2635
+ if (globals.skipAnimation) {
2636
+ this.finish();
2637
+ } else {
2638
+ frameLoop.start(this);
2639
+ }
2640
+ }
2641
+
2642
+ _stop(goal, cancel) {
2643
+ if (isAnimating(this)) {
2644
+ setActiveBit(this, false);
2645
+ const anim = this.animation;
2646
+ each(anim.values, node => {
2647
+ node.done = true;
2648
+ });
2649
+
2650
+ if (anim.toValues) {
2651
+ anim.onChange = anim.onPause = anim.onResume = undefined;
2652
+ }
2653
+
2654
+ callFluidObservers(this, {
2655
+ type: 'idle',
2656
+ parent: this
2657
+ });
2658
+ const result = cancel ? getCancelledResult(this.get()) : getFinishedResult(this.get(), checkFinished(this, goal != null ? goal : anim.to));
2659
+ flushCalls(this._pendingCalls, result);
2660
+
2661
+ if (anim.changed) {
2662
+ anim.changed = false;
2663
+ sendEvent(this, 'onRest', result, this);
2664
+ }
2665
+ }
2666
+ }
2667
+
2668
+ }
2669
+
2670
+ function checkFinished(target, to) {
2671
+ const goal = computeGoal(to);
2672
+ const value = computeGoal(target.get());
2673
+ return isEqual(value, goal);
2674
+ }
2675
+
2676
+ function createLoopUpdate(props, loop = props.loop, to = props.to) {
2677
+ let loopRet = callProp(loop);
2678
+
2679
+ if (loopRet) {
2680
+ const overrides = loopRet !== true && inferTo(loopRet);
2681
+ const reverse = (overrides || props).reverse;
2682
+ const reset = !overrides || overrides.reset;
2683
+ return createUpdate(_extends({}, props, {
2684
+ loop,
2685
+ default: false,
2686
+ pause: undefined,
2687
+ to: !reverse || isAsyncTo(to) ? to : undefined,
2688
+ from: reset ? props.from : undefined,
2689
+ reset
2690
+ }, overrides));
2691
+ }
2692
+ }
2693
+ function createUpdate(props) {
2694
+ const {
2695
+ to,
2696
+ from
2697
+ } = props = inferTo(props);
2698
+ const keys = new Set();
2699
+ if (is.obj(to)) findDefined(to, keys);
2700
+ if (is.obj(from)) findDefined(from, keys);
2701
+ props.keys = keys.size ? Array.from(keys) : null;
2702
+ return props;
2703
+ }
2704
+ function declareUpdate(props) {
2705
+ const update = createUpdate(props);
2706
+
2707
+ if (is.und(update.default)) {
2708
+ update.default = getDefaultProps(update);
2709
+ }
2710
+
2711
+ return update;
2712
+ }
2713
+
2714
+ function findDefined(values, keys) {
2715
+ eachProp(values, (value, key) => value != null && keys.add(key));
2716
+ }
2717
+
2718
+ const ACTIVE_EVENTS = ['onStart', 'onRest', 'onChange', 'onPause', 'onResume'];
2719
+
2720
+ function mergeActiveFn(target, props, type) {
2721
+ target.animation[type] = props[type] !== getDefaultProp(props, type) ? resolveProp(props[type], target.key) : undefined;
2722
+ }
2723
+
2724
+ function sendEvent(target, type, ...args) {
2725
+ var _target$animation$typ, _target$animation, _target$defaultProps$, _target$defaultProps;
2726
+
2727
+ (_target$animation$typ = (_target$animation = target.animation)[type]) == null ? void 0 : _target$animation$typ.call(_target$animation, ...args);
2728
+ (_target$defaultProps$ = (_target$defaultProps = target.defaultProps)[type]) == null ? void 0 : _target$defaultProps$.call(_target$defaultProps, ...args);
2729
+ }
2730
+
2731
+ const BATCHED_EVENTS = ['onStart', 'onChange', 'onRest'];
2732
+ let nextId = 1;
2733
+ class Controller {
2734
+ constructor(props, flush) {
2735
+ this.id = nextId++;
2736
+ this.springs = {};
2737
+ this.queue = [];
2738
+ this.ref = void 0;
2739
+ this._flush = void 0;
2740
+ this._initialProps = void 0;
2741
+ this._lastAsyncId = 0;
2742
+ this._active = new Set();
2743
+ this._changed = new Set();
2744
+ this._started = false;
2745
+ this._item = void 0;
2746
+ this._state = {
2747
+ paused: false,
2748
+ pauseQueue: new Set(),
2749
+ resumeQueue: new Set(),
2750
+ timeouts: new Set()
2751
+ };
2752
+ this._events = {
2753
+ onStart: new Map(),
2754
+ onChange: new Map(),
2755
+ onRest: new Map()
2756
+ };
2757
+ this._onFrame = this._onFrame.bind(this);
2758
+
2759
+ if (flush) {
2760
+ this._flush = flush;
2761
+ }
2762
+
2763
+ if (props) {
2764
+ this.start(_extends({
2765
+ default: true
2766
+ }, props));
2767
+ }
2768
+ }
2769
+
2770
+ get idle() {
2771
+ return !this._state.asyncTo && Object.values(this.springs).every(spring => {
2772
+ return spring.idle && !spring.isDelayed && !spring.isPaused;
2773
+ });
2774
+ }
2775
+
2776
+ get item() {
2777
+ return this._item;
2778
+ }
2779
+
2780
+ set item(item) {
2781
+ this._item = item;
2782
+ }
2783
+
2784
+ get() {
2785
+ const values = {};
2786
+ this.each((spring, key) => values[key] = spring.get());
2787
+ return values;
2788
+ }
2789
+
2790
+ set(values) {
2791
+ for (const key in values) {
2792
+ const value = values[key];
2793
+
2794
+ if (!is.und(value)) {
2795
+ this.springs[key].set(value);
2796
+ }
2797
+ }
2798
+ }
2799
+
2800
+ update(props) {
2801
+ if (props) {
2802
+ this.queue.push(createUpdate(props));
2803
+ }
2804
+
2805
+ return this;
2806
+ }
2807
+
2808
+ start(props) {
2809
+ let {
2810
+ queue
2811
+ } = this;
2812
+
2813
+ if (props) {
2814
+ queue = toArray(props).map(createUpdate);
2815
+ } else {
2816
+ this.queue = [];
2817
+ }
2818
+
2819
+ if (this._flush) {
2820
+ return this._flush(this, queue);
2821
+ }
2822
+
2823
+ prepareKeys(this, queue);
2824
+ return flushUpdateQueue(this, queue);
2825
+ }
2826
+
2827
+ stop(arg, keys) {
2828
+ if (arg !== !!arg) {
2829
+ keys = arg;
2830
+ }
2831
+
2832
+ if (keys) {
2833
+ const springs = this.springs;
2834
+ each(toArray(keys), key => springs[key].stop(!!arg));
2835
+ } else {
2836
+ stopAsync(this._state, this._lastAsyncId);
2837
+ this.each(spring => spring.stop(!!arg));
2838
+ }
2839
+
2840
+ return this;
2841
+ }
2842
+
2843
+ pause(keys) {
2844
+ if (is.und(keys)) {
2845
+ this.start({
2846
+ pause: true
2847
+ });
2848
+ } else {
2849
+ const springs = this.springs;
2850
+ each(toArray(keys), key => springs[key].pause());
2851
+ }
2852
+
2853
+ return this;
2854
+ }
2855
+
2856
+ resume(keys) {
2857
+ if (is.und(keys)) {
2858
+ this.start({
2859
+ pause: false
2860
+ });
2861
+ } else {
2862
+ const springs = this.springs;
2863
+ each(toArray(keys), key => springs[key].resume());
2864
+ }
2865
+
2866
+ return this;
2867
+ }
2868
+
2869
+ each(iterator) {
2870
+ eachProp(this.springs, iterator);
2871
+ }
2872
+
2873
+ _onFrame() {
2874
+ const {
2875
+ onStart,
2876
+ onChange,
2877
+ onRest
2878
+ } = this._events;
2879
+ const active = this._active.size > 0;
2880
+ const changed = this._changed.size > 0;
2881
+
2882
+ if (active && !this._started || changed && !this._started) {
2883
+ this._started = true;
2884
+ flush(onStart, ([onStart, result]) => {
2885
+ result.value = this.get();
2886
+ onStart(result, this, this._item);
2887
+ });
2888
+ }
2889
+
2890
+ const idle = !active && this._started;
2891
+ const values = changed || idle && onRest.size ? this.get() : null;
2892
+
2893
+ if (changed && onChange.size) {
2894
+ flush(onChange, ([onChange, result]) => {
2895
+ result.value = values;
2896
+ onChange(result, this, this._item);
2897
+ });
2898
+ }
2899
+
2900
+ if (idle) {
2901
+ this._started = false;
2902
+ flush(onRest, ([onRest, result]) => {
2903
+ result.value = values;
2904
+ onRest(result, this, this._item);
2905
+ });
2906
+ }
2907
+ }
2908
+
2909
+ eventObserved(event) {
2910
+ if (event.type == 'change') {
2911
+ this._changed.add(event.parent);
2912
+
2913
+ if (!event.idle) {
2914
+ this._active.add(event.parent);
2915
+ }
2916
+ } else if (event.type == 'idle') {
2917
+ this._active.delete(event.parent);
2918
+ } else return;
2919
+
2920
+ raf.onFrame(this._onFrame);
2921
+ }
2922
+
2923
+ }
2924
+ function flushUpdateQueue(ctrl, queue) {
2925
+ return Promise.all(queue.map(props => flushUpdate(ctrl, props))).then(results => getCombinedResult(ctrl, results));
2926
+ }
2927
+ async function flushUpdate(ctrl, props, isLoop) {
2928
+ const {
2929
+ keys,
2930
+ to,
2931
+ from,
2932
+ loop,
2933
+ onRest,
2934
+ onResolve
2935
+ } = props;
2936
+ const defaults = is.obj(props.default) && props.default;
2937
+
2938
+ if (loop) {
2939
+ props.loop = false;
2940
+ }
2941
+
2942
+ if (to === false) props.to = null;
2943
+ if (from === false) props.from = null;
2944
+ const asyncTo = is.arr(to) || is.fun(to) ? to : undefined;
2945
+
2946
+ if (asyncTo) {
2947
+ props.to = undefined;
2948
+ props.onRest = undefined;
2949
+
2950
+ if (defaults) {
2951
+ defaults.onRest = undefined;
2952
+ }
2953
+ } else {
2954
+ each(BATCHED_EVENTS, key => {
2955
+ const handler = props[key];
2956
+
2957
+ if (is.fun(handler)) {
2958
+ const queue = ctrl['_events'][key];
2959
+
2960
+ props[key] = ({
2961
+ finished,
2962
+ cancelled
2963
+ }) => {
2964
+ const result = queue.get(handler);
2965
+
2966
+ if (result) {
2967
+ if (!finished) result.finished = false;
2968
+ if (cancelled) result.cancelled = true;
2969
+ } else {
2970
+ queue.set(handler, {
2971
+ value: null,
2972
+ finished: finished || false,
2973
+ cancelled: cancelled || false
2974
+ });
2975
+ }
2976
+ };
2977
+
2978
+ if (defaults) {
2979
+ defaults[key] = props[key];
2980
+ }
2981
+ }
2982
+ });
2983
+ }
2984
+
2985
+ const state = ctrl['_state'];
2986
+
2987
+ if (props.pause === !state.paused) {
2988
+ state.paused = props.pause;
2989
+ flushCalls(props.pause ? state.pauseQueue : state.resumeQueue);
2990
+ } else if (state.paused) {
2991
+ props.pause = true;
2992
+ }
2993
+
2994
+ const promises = (keys || Object.keys(ctrl.springs)).map(key => ctrl.springs[key].start(props));
2995
+ const cancel = props.cancel === true || getDefaultProp(props, 'cancel') === true;
2996
+
2997
+ if (asyncTo || cancel && state.asyncId) {
2998
+ promises.push(scheduleProps(++ctrl['_lastAsyncId'], {
2999
+ props,
3000
+ state,
3001
+ actions: {
3002
+ pause: noop,
3003
+ resume: noop,
3004
+
3005
+ start(props, resolve) {
3006
+ if (cancel) {
3007
+ stopAsync(state, ctrl['_lastAsyncId']);
3008
+ resolve(getCancelledResult(ctrl));
3009
+ } else {
3010
+ props.onRest = onRest;
3011
+ resolve(runAsync(asyncTo, props, state, ctrl));
3012
+ }
3013
+ }
3014
+
3015
+ }
3016
+ }));
3017
+ }
3018
+
3019
+ if (state.paused) {
3020
+ await new Promise(resume => {
3021
+ state.resumeQueue.add(resume);
3022
+ });
3023
+ }
3024
+
3025
+ const result = getCombinedResult(ctrl, await Promise.all(promises));
3026
+
3027
+ if (loop && result.finished && !(isLoop && result.noop)) {
3028
+ const nextProps = createLoopUpdate(props, loop, to);
3029
+
3030
+ if (nextProps) {
3031
+ prepareKeys(ctrl, [nextProps]);
3032
+ return flushUpdate(ctrl, nextProps, true);
3033
+ }
3034
+ }
3035
+
3036
+ if (onResolve) {
3037
+ raf.batchedUpdates(() => onResolve(result, ctrl, ctrl.item));
3038
+ }
3039
+
3040
+ return result;
3041
+ }
3042
+ function getSprings(ctrl, props) {
3043
+ const springs = _extends({}, ctrl.springs);
3044
+
3045
+ if (props) {
3046
+ each(toArray(props), props => {
3047
+ if (is.und(props.keys)) {
3048
+ props = createUpdate(props);
3049
+ }
3050
+
3051
+ if (!is.obj(props.to)) {
3052
+ props = _extends({}, props, {
3053
+ to: undefined
3054
+ });
3055
+ }
3056
+
3057
+ prepareSprings(springs, props, key => {
3058
+ return createSpring(key);
3059
+ });
3060
+ });
3061
+ }
3062
+
3063
+ setSprings(ctrl, springs);
3064
+ return springs;
3065
+ }
3066
+ function setSprings(ctrl, springs) {
3067
+ eachProp(springs, (spring, key) => {
3068
+ if (!ctrl.springs[key]) {
3069
+ ctrl.springs[key] = spring;
3070
+ addFluidObserver(spring, ctrl);
3071
+ }
3072
+ });
3073
+ }
3074
+
3075
+ function createSpring(key, observer) {
3076
+ const spring = new SpringValue();
3077
+ spring.key = key;
3078
+
3079
+ if (observer) {
3080
+ addFluidObserver(spring, observer);
3081
+ }
3082
+
3083
+ return spring;
3084
+ }
3085
+
3086
+ function prepareSprings(springs, props, create) {
3087
+ if (props.keys) {
3088
+ each(props.keys, key => {
3089
+ const spring = springs[key] || (springs[key] = create(key));
3090
+ spring['_prepareNode'](props);
3091
+ });
3092
+ }
3093
+ }
3094
+
3095
+ function prepareKeys(ctrl, queue) {
3096
+ each(queue, props => {
3097
+ prepareSprings(ctrl.springs, props, key => {
3098
+ return createSpring(key, ctrl);
3099
+ });
3100
+ });
3101
+ }
3102
+
3103
+ function _objectWithoutPropertiesLoose$1(source, excluded) {
3104
+ if (source == null) return {};
3105
+ var target = {};
3106
+ var sourceKeys = Object.keys(source);
3107
+ var key, i;
3108
+
3109
+ for (i = 0; i < sourceKeys.length; i++) {
3110
+ key = sourceKeys[i];
3111
+ if (excluded.indexOf(key) >= 0) continue;
3112
+ target[key] = source[key];
3113
+ }
3114
+
3115
+ return target;
3116
+ }
3117
+
3118
+ const _excluded$3 = ["children"];
3119
+ const SpringContext = _ref => {
3120
+ let {
3121
+ children
3122
+ } = _ref,
3123
+ props = _objectWithoutPropertiesLoose$1(_ref, _excluded$3);
3124
+
3125
+ const inherited = useContext(ctx);
3126
+ const pause = props.pause || !!inherited.pause,
3127
+ immediate = props.immediate || !!inherited.immediate;
3128
+ props = useMemoOne(() => ({
3129
+ pause,
3130
+ immediate
3131
+ }), [pause, immediate]);
3132
+ const {
3133
+ Provider
3134
+ } = ctx;
3135
+ return React.createElement(Provider, {
3136
+ value: props
3137
+ }, children);
3138
+ };
3139
+ const ctx = makeContext(SpringContext, {});
3140
+ SpringContext.Provider = ctx.Provider;
3141
+ SpringContext.Consumer = ctx.Consumer;
3142
+
3143
+ function makeContext(target, init) {
3144
+ Object.assign(target, React.createContext(init));
3145
+ target.Provider._context = target;
3146
+ target.Consumer._context = target;
3147
+ return target;
3148
+ }
3149
+
3150
+ const SpringRef = () => {
3151
+ const current = [];
3152
+
3153
+ const SpringRef = function SpringRef(props) {
3154
+ deprecateDirectCall();
3155
+ const results = [];
3156
+ each(current, (ctrl, i) => {
3157
+ if (is.und(props)) {
3158
+ results.push(ctrl.start());
3159
+ } else {
3160
+ const update = _getProps(props, ctrl, i);
3161
+
3162
+ if (update) {
3163
+ results.push(ctrl.start(update));
3164
+ }
3165
+ }
3166
+ });
3167
+ return results;
3168
+ };
3169
+
3170
+ SpringRef.current = current;
3171
+
3172
+ SpringRef.add = function (ctrl) {
3173
+ if (!current.includes(ctrl)) {
3174
+ current.push(ctrl);
3175
+ }
3176
+ };
3177
+
3178
+ SpringRef.delete = function (ctrl) {
3179
+ const i = current.indexOf(ctrl);
3180
+ if (~i) current.splice(i, 1);
3181
+ };
3182
+
3183
+ SpringRef.pause = function () {
3184
+ each(current, ctrl => ctrl.pause(...arguments));
3185
+ return this;
3186
+ };
3187
+
3188
+ SpringRef.resume = function () {
3189
+ each(current, ctrl => ctrl.resume(...arguments));
3190
+ return this;
3191
+ };
3192
+
3193
+ SpringRef.set = function (values) {
3194
+ each(current, ctrl => ctrl.set(values));
3195
+ };
3196
+
3197
+ SpringRef.start = function (props) {
3198
+ const results = [];
3199
+ each(current, (ctrl, i) => {
3200
+ if (is.und(props)) {
3201
+ results.push(ctrl.start());
3202
+ } else {
3203
+ const update = this._getProps(props, ctrl, i);
3204
+
3205
+ if (update) {
3206
+ results.push(ctrl.start(update));
3207
+ }
3208
+ }
3209
+ });
3210
+ return results;
3211
+ };
3212
+
3213
+ SpringRef.stop = function () {
3214
+ each(current, ctrl => ctrl.stop(...arguments));
3215
+ return this;
3216
+ };
3217
+
3218
+ SpringRef.update = function (props) {
3219
+ each(current, (ctrl, i) => ctrl.update(this._getProps(props, ctrl, i)));
3220
+ return this;
3221
+ };
3222
+
3223
+ const _getProps = function _getProps(arg, ctrl, index) {
3224
+ return is.fun(arg) ? arg(index, ctrl) : arg;
3225
+ };
3226
+
3227
+ SpringRef._getProps = _getProps;
3228
+ return SpringRef;
3229
+ };
3230
+
3231
+ function useSprings(length, props, deps) {
3232
+ const propsFn = is.fun(props) && props;
3233
+ if (propsFn && !deps) deps = [];
3234
+ const ref = useMemo(() => propsFn || arguments.length == 3 ? SpringRef() : void 0, []);
3235
+ const layoutId = useRef(0);
3236
+ const forceUpdate = useForceUpdate();
3237
+ const state = useMemo(() => ({
3238
+ ctrls: [],
3239
+ queue: [],
3240
+
3241
+ flush(ctrl, updates) {
3242
+ const springs = getSprings(ctrl, updates);
3243
+ const canFlushSync = layoutId.current > 0 && !state.queue.length && !Object.keys(springs).some(key => !ctrl.springs[key]);
3244
+ return canFlushSync ? flushUpdateQueue(ctrl, updates) : new Promise(resolve => {
3245
+ setSprings(ctrl, springs);
3246
+ state.queue.push(() => {
3247
+ resolve(flushUpdateQueue(ctrl, updates));
3248
+ });
3249
+ forceUpdate();
3250
+ });
3251
+ }
3252
+
3253
+ }), []);
3254
+ const ctrls = useRef([...state.ctrls]);
3255
+ const updates = [];
3256
+ const prevLength = usePrev(length) || 0;
3257
+ useMemo(() => {
3258
+ each(ctrls.current.slice(length, prevLength), ctrl => {
3259
+ detachRefs(ctrl, ref);
3260
+ ctrl.stop(true);
3261
+ });
3262
+ ctrls.current.length = length;
3263
+ declareUpdates(prevLength, length);
3264
+ }, [length]);
3265
+ useMemo(() => {
3266
+ declareUpdates(0, Math.min(prevLength, length));
3267
+ }, deps);
3268
+
3269
+ function declareUpdates(startIndex, endIndex) {
3270
+ for (let i = startIndex; i < endIndex; i++) {
3271
+ const ctrl = ctrls.current[i] || (ctrls.current[i] = new Controller(null, state.flush));
3272
+ const update = propsFn ? propsFn(i, ctrl) : props[i];
3273
+
3274
+ if (update) {
3275
+ updates[i] = declareUpdate(update);
3276
+ }
3277
+ }
3278
+ }
3279
+
3280
+ const springs = ctrls.current.map((ctrl, i) => getSprings(ctrl, updates[i]));
3281
+ const context = useContext(SpringContext);
3282
+ const prevContext = usePrev(context);
3283
+ const hasContext = context !== prevContext && hasProps(context);
3284
+ useIsomorphicLayoutEffect(() => {
3285
+ layoutId.current++;
3286
+ state.ctrls = ctrls.current;
3287
+ const {
3288
+ queue
3289
+ } = state;
3290
+
3291
+ if (queue.length) {
3292
+ state.queue = [];
3293
+ each(queue, cb => cb());
3294
+ }
3295
+
3296
+ each(ctrls.current, (ctrl, i) => {
3297
+ ref == null ? void 0 : ref.add(ctrl);
3298
+
3299
+ if (hasContext) {
3300
+ ctrl.start({
3301
+ default: context
3302
+ });
3303
+ }
3304
+
3305
+ const update = updates[i];
3306
+
3307
+ if (update) {
3308
+ replaceRef(ctrl, update.ref);
3309
+
3310
+ if (ctrl.ref) {
3311
+ ctrl.queue.push(update);
3312
+ } else {
3313
+ ctrl.start(update);
3314
+ }
3315
+ }
3316
+ });
3317
+ });
3318
+ useOnce(() => () => {
3319
+ each(state.ctrls, ctrl => ctrl.stop(true));
3320
+ });
3321
+ const values = springs.map(x => _extends({}, x));
3322
+ return ref ? [values, ref] : values;
3323
+ }
3324
+
3325
+ function useSpring(props, deps) {
3326
+ const isFn = is.fun(props);
3327
+ const [[values], ref] = useSprings(1, isFn ? props : [props], isFn ? deps || [] : deps);
3328
+ return isFn || arguments.length == 2 ? [values, ref] : values;
3329
+ }
3330
+
3331
+ let TransitionPhase;
3332
+
3333
+ (function (TransitionPhase) {
3334
+ TransitionPhase["MOUNT"] = "mount";
3335
+ TransitionPhase["ENTER"] = "enter";
3336
+ TransitionPhase["UPDATE"] = "update";
3337
+ TransitionPhase["LEAVE"] = "leave";
3338
+ })(TransitionPhase || (TransitionPhase = {}));
3339
+
3340
+ class Interpolation extends FrameValue {
3341
+ constructor(source, args) {
3342
+ super();
3343
+ this.key = void 0;
3344
+ this.idle = true;
3345
+ this.calc = void 0;
3346
+ this._active = new Set();
3347
+ this.source = source;
3348
+ this.calc = createInterpolator(...args);
3349
+
3350
+ const value = this._get();
3351
+
3352
+ const nodeType = getAnimatedType(value);
3353
+ setAnimated(this, nodeType.create(value));
3354
+ }
3355
+
3356
+ advance(_dt) {
3357
+ const value = this._get();
3358
+
3359
+ const oldValue = this.get();
3360
+
3361
+ if (!isEqual(value, oldValue)) {
3362
+ getAnimated(this).setValue(value);
3363
+
3364
+ this._onChange(value, this.idle);
3365
+ }
3366
+
3367
+ if (!this.idle && checkIdle(this._active)) {
3368
+ becomeIdle(this);
3369
+ }
3370
+ }
3371
+
3372
+ _get() {
3373
+ const inputs = is.arr(this.source) ? this.source.map(getFluidValue) : toArray(getFluidValue(this.source));
3374
+ return this.calc(...inputs);
3375
+ }
3376
+
3377
+ _start() {
3378
+ if (this.idle && !checkIdle(this._active)) {
3379
+ this.idle = false;
3380
+ each(getPayload(this), node => {
3381
+ node.done = false;
3382
+ });
3383
+
3384
+ if (globals.skipAnimation) {
3385
+ raf.batchedUpdates(() => this.advance());
3386
+ becomeIdle(this);
3387
+ } else {
3388
+ frameLoop.start(this);
3389
+ }
3390
+ }
3391
+ }
3392
+
3393
+ _attach() {
3394
+ let priority = 1;
3395
+ each(toArray(this.source), source => {
3396
+ if (hasFluidValue(source)) {
3397
+ addFluidObserver(source, this);
3398
+ }
3399
+
3400
+ if (isFrameValue(source)) {
3401
+ if (!source.idle) {
3402
+ this._active.add(source);
3403
+ }
3404
+
3405
+ priority = Math.max(priority, source.priority + 1);
3406
+ }
3407
+ });
3408
+ this.priority = priority;
3409
+
3410
+ this._start();
3411
+ }
3412
+
3413
+ _detach() {
3414
+ each(toArray(this.source), source => {
3415
+ if (hasFluidValue(source)) {
3416
+ removeFluidObserver(source, this);
3417
+ }
3418
+ });
3419
+
3420
+ this._active.clear();
3421
+
3422
+ becomeIdle(this);
3423
+ }
3424
+
3425
+ eventObserved(event) {
3426
+ if (event.type == 'change') {
3427
+ if (event.idle) {
3428
+ this.advance();
3429
+ } else {
3430
+ this._active.add(event.parent);
3431
+
3432
+ this._start();
3433
+ }
3434
+ } else if (event.type == 'idle') {
3435
+ this._active.delete(event.parent);
3436
+ } else if (event.type == 'priority') {
3437
+ this.priority = toArray(this.source).reduce((highest, parent) => Math.max(highest, (isFrameValue(parent) ? parent.priority : 0) + 1), 0);
3438
+ }
3439
+ }
3440
+
3441
+ }
3442
+
3443
+ function isIdle(source) {
3444
+ return source.idle !== false;
3445
+ }
3446
+
3447
+ function checkIdle(active) {
3448
+ return !active.size || Array.from(active).every(isIdle);
3449
+ }
3450
+
3451
+ function becomeIdle(self) {
3452
+ if (!self.idle) {
3453
+ self.idle = true;
3454
+ each(getPayload(self), node => {
3455
+ node.done = true;
3456
+ });
3457
+ callFluidObservers(self, {
3458
+ type: 'idle',
3459
+ parent: self
3460
+ });
3461
+ }
3462
+ }
3463
+
3464
+ globals.assign({
3465
+ createStringInterpolator,
3466
+ to: (source, args) => new Interpolation(source, args)
3467
+ });
3468
+
3469
+ function _objectWithoutPropertiesLoose(source, excluded) {
3470
+ if (source == null) return {};
3471
+ var target = {};
3472
+ var sourceKeys = Object.keys(source);
3473
+ var key, i;
3474
+
3475
+ for (i = 0; i < sourceKeys.length; i++) {
3476
+ key = sourceKeys[i];
3477
+ if (excluded.indexOf(key) >= 0) continue;
3478
+ target[key] = source[key];
3479
+ }
3480
+
3481
+ return target;
3482
+ }
3483
+
3484
+ const _excluded$2 = ["style", "children", "scrollTop", "scrollLeft"];
3485
+ const isCustomPropRE = /^--/;
3486
+
3487
+ function dangerousStyleValue(name, value) {
3488
+ if (value == null || typeof value === 'boolean' || value === '') return '';
3489
+ if (typeof value === 'number' && value !== 0 && !isCustomPropRE.test(name) && !(isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name])) return value + 'px';
3490
+ return ('' + value).trim();
3491
+ }
3492
+
3493
+ const attributeCache = {};
3494
+ function applyAnimatedValues(instance, props) {
3495
+ if (!instance.nodeType || !instance.setAttribute) {
3496
+ return false;
3497
+ }
3498
+
3499
+ const isFilterElement = instance.nodeName === 'filter' || instance.parentNode && instance.parentNode.nodeName === 'filter';
3500
+
3501
+ const _ref = props,
3502
+ {
3503
+ style,
3504
+ children,
3505
+ scrollTop,
3506
+ scrollLeft
3507
+ } = _ref,
3508
+ attributes = _objectWithoutPropertiesLoose(_ref, _excluded$2);
3509
+
3510
+ const values = Object.values(attributes);
3511
+ const names = Object.keys(attributes).map(name => isFilterElement || instance.hasAttribute(name) ? name : attributeCache[name] || (attributeCache[name] = name.replace(/([A-Z])/g, n => '-' + n.toLowerCase())));
3512
+
3513
+ if (children !== void 0) {
3514
+ instance.textContent = children;
3515
+ }
3516
+
3517
+ for (let name in style) {
3518
+ if (style.hasOwnProperty(name)) {
3519
+ const value = dangerousStyleValue(name, style[name]);
3520
+
3521
+ if (isCustomPropRE.test(name)) {
3522
+ instance.style.setProperty(name, value);
3523
+ } else {
3524
+ instance.style[name] = value;
3525
+ }
3526
+ }
3527
+ }
3528
+
3529
+ names.forEach((name, i) => {
3530
+ instance.setAttribute(name, values[i]);
3531
+ });
3532
+
3533
+ if (scrollTop !== void 0) {
3534
+ instance.scrollTop = scrollTop;
3535
+ }
3536
+
3537
+ if (scrollLeft !== void 0) {
3538
+ instance.scrollLeft = scrollLeft;
3539
+ }
3540
+ }
3541
+ let isUnitlessNumber = {
3542
+ animationIterationCount: true,
3543
+ borderImageOutset: true,
3544
+ borderImageSlice: true,
3545
+ borderImageWidth: true,
3546
+ boxFlex: true,
3547
+ boxFlexGroup: true,
3548
+ boxOrdinalGroup: true,
3549
+ columnCount: true,
3550
+ columns: true,
3551
+ flex: true,
3552
+ flexGrow: true,
3553
+ flexPositive: true,
3554
+ flexShrink: true,
3555
+ flexNegative: true,
3556
+ flexOrder: true,
3557
+ gridRow: true,
3558
+ gridRowEnd: true,
3559
+ gridRowSpan: true,
3560
+ gridRowStart: true,
3561
+ gridColumn: true,
3562
+ gridColumnEnd: true,
3563
+ gridColumnSpan: true,
3564
+ gridColumnStart: true,
3565
+ fontWeight: true,
3566
+ lineClamp: true,
3567
+ lineHeight: true,
3568
+ opacity: true,
3569
+ order: true,
3570
+ orphans: true,
3571
+ tabSize: true,
3572
+ widows: true,
3573
+ zIndex: true,
3574
+ zoom: true,
3575
+ fillOpacity: true,
3576
+ floodOpacity: true,
3577
+ stopOpacity: true,
3578
+ strokeDasharray: true,
3579
+ strokeDashoffset: true,
3580
+ strokeMiterlimit: true,
3581
+ strokeOpacity: true,
3582
+ strokeWidth: true
3583
+ };
3584
+
3585
+ const prefixKey = (prefix, key) => prefix + key.charAt(0).toUpperCase() + key.substring(1);
3586
+
3587
+ const prefixes = ['Webkit', 'Ms', 'Moz', 'O'];
3588
+ isUnitlessNumber = Object.keys(isUnitlessNumber).reduce((acc, prop) => {
3589
+ prefixes.forEach(prefix => acc[prefixKey(prefix, prop)] = acc[prop]);
3590
+ return acc;
3591
+ }, isUnitlessNumber);
3592
+
3593
+ const _excluded$1 = ["x", "y", "z"];
3594
+ const domTransforms = /^(matrix|translate|scale|rotate|skew)/;
3595
+ const pxTransforms = /^(translate)/;
3596
+ const degTransforms = /^(rotate|skew)/;
3597
+
3598
+ const addUnit = (value, unit) => is.num(value) && value !== 0 ? value + unit : value;
3599
+
3600
+ const isValueIdentity = (value, id) => is.arr(value) ? value.every(v => isValueIdentity(v, id)) : is.num(value) ? value === id : parseFloat(value) === id;
3601
+
3602
+ class AnimatedStyle extends AnimatedObject {
3603
+ constructor(_ref) {
3604
+ let {
3605
+ x,
3606
+ y,
3607
+ z
3608
+ } = _ref,
3609
+ style = _objectWithoutPropertiesLoose(_ref, _excluded$1);
3610
+
3611
+ const inputs = [];
3612
+ const transforms = [];
3613
+
3614
+ if (x || y || z) {
3615
+ inputs.push([x || 0, y || 0, z || 0]);
3616
+ transforms.push(xyz => [`translate3d(${xyz.map(v => addUnit(v, 'px')).join(',')})`, isValueIdentity(xyz, 0)]);
3617
+ }
3618
+
3619
+ eachProp(style, (value, key) => {
3620
+ if (key === 'transform') {
3621
+ inputs.push([value || '']);
3622
+ transforms.push(transform => [transform, transform === '']);
3623
+ } else if (domTransforms.test(key)) {
3624
+ delete style[key];
3625
+ if (is.und(value)) return;
3626
+ const unit = pxTransforms.test(key) ? 'px' : degTransforms.test(key) ? 'deg' : '';
3627
+ inputs.push(toArray(value));
3628
+ transforms.push(key === 'rotate3d' ? ([x, y, z, deg]) => [`rotate3d(${x},${y},${z},${addUnit(deg, unit)})`, isValueIdentity(deg, 0)] : input => [`${key}(${input.map(v => addUnit(v, unit)).join(',')})`, isValueIdentity(input, key.startsWith('scale') ? 1 : 0)]);
3629
+ }
3630
+ });
3631
+
3632
+ if (inputs.length) {
3633
+ style.transform = new FluidTransform(inputs, transforms);
3634
+ }
3635
+
3636
+ super(style);
3637
+ }
3638
+
3639
+ }
3640
+
3641
+ class FluidTransform extends FluidValue {
3642
+ constructor(inputs, transforms) {
3643
+ super();
3644
+ this._value = null;
3645
+ this.inputs = inputs;
3646
+ this.transforms = transforms;
3647
+ }
3648
+
3649
+ get() {
3650
+ return this._value || (this._value = this._get());
3651
+ }
3652
+
3653
+ _get() {
3654
+ let transform = '';
3655
+ let identity = true;
3656
+ each(this.inputs, (input, i) => {
3657
+ const arg1 = getFluidValue(input[0]);
3658
+ const [t, id] = this.transforms[i](is.arr(arg1) ? arg1 : input.map(getFluidValue));
3659
+ transform += ' ' + t;
3660
+ identity = identity && id;
3661
+ });
3662
+ return identity ? 'none' : transform;
3663
+ }
3664
+
3665
+ observerAdded(count) {
3666
+ if (count == 1) each(this.inputs, input => each(input, value => hasFluidValue(value) && addFluidObserver(value, this)));
3667
+ }
3668
+
3669
+ observerRemoved(count) {
3670
+ if (count == 0) each(this.inputs, input => each(input, value => hasFluidValue(value) && removeFluidObserver(value, this)));
3671
+ }
3672
+
3673
+ eventObserved(event) {
3674
+ if (event.type == 'change') {
3675
+ this._value = null;
3676
+ }
3677
+
3678
+ callFluidObservers(this, event);
3679
+ }
3680
+
3681
+ }
3682
+
3683
+ const primitives = ['a', 'abbr', 'address', 'area', 'article', 'aside', 'audio', 'b', 'base', 'bdi', 'bdo', 'big', 'blockquote', 'body', 'br', 'button', 'canvas', 'caption', 'cite', 'code', 'col', 'colgroup', 'data', 'datalist', 'dd', 'del', 'details', 'dfn', 'dialog', 'div', 'dl', 'dt', 'em', 'embed', 'fieldset', 'figcaption', 'figure', 'footer', 'form', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'head', 'header', 'hgroup', 'hr', 'html', 'i', 'iframe', 'img', 'input', 'ins', 'kbd', 'keygen', 'label', 'legend', 'li', 'link', 'main', 'map', 'mark', 'menu', 'menuitem', 'meta', 'meter', 'nav', 'noscript', 'object', 'ol', 'optgroup', 'option', 'output', 'p', 'param', 'picture', 'pre', 'progress', 'q', 'rp', 'rt', 'ruby', 's', 'samp', 'script', 'section', 'select', 'small', 'source', 'span', 'strong', 'style', 'sub', 'summary', 'sup', 'table', 'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'time', 'title', 'tr', 'track', 'u', 'ul', 'var', 'video', 'wbr', 'circle', 'clipPath', 'defs', 'ellipse', 'foreignObject', 'g', 'image', 'line', 'linearGradient', 'mask', 'path', 'pattern', 'polygon', 'polyline', 'radialGradient', 'rect', 'stop', 'svg', 'text', 'tspan'];
3684
+
3685
+ const _excluded = ["scrollTop", "scrollLeft"];
3686
+ globals.assign({
3687
+ batchedUpdates: unstable_batchedUpdates,
3688
+ createStringInterpolator,
3689
+ colors
3690
+ });
3691
+ createHost(primitives, {
3692
+ applyAnimatedValues,
3693
+ createAnimatedStyle: style => new AnimatedStyle(style),
3694
+ getComponentProps: _ref => {
3695
+ let props = _objectWithoutPropertiesLoose(_ref, _excluded);
3696
+
3697
+ return props;
3698
+ }
3699
+ });
3700
+
3701
+ const eventLabel = 'RSC::Event';
3702
+ function useEventsModule() {
3703
+ const targetEvent = useRef(null);
3704
+ useEffect(() => {
3705
+ targetEvent.current = document.createElement('div');
3706
+ }, []);
3707
+ function useListenToCustomEvent(eventHandler) {
3708
+ useEffect(() => {
3709
+ function handleEvent(event) {
3710
+ eventHandler(event.detail);
3711
+ }
3712
+ if (targetEvent.current) {
3713
+ // @ts-ignore
3714
+ targetEvent.current.addEventListener(eventLabel, handleEvent, false);
3715
+ return () => {
3716
+ var _a;
3717
+ // @ts-ignore
3718
+ (_a = targetEvent.current) === null || _a === void 0 ? void 0 : _a.removeEventListener(eventLabel, handleEvent, false);
3719
+ };
3720
+ }
3721
+ }, []);
3722
+ }
3723
+ function emitEvent(event) {
3724
+ if (targetEvent.current) {
3725
+ const newEvent = new CustomEvent(eventLabel, {
3726
+ detail: event,
3727
+ });
3728
+ targetEvent.current.dispatchEvent(newEvent);
3729
+ }
3730
+ }
3731
+ return {
3732
+ useListenToCustomEvent,
3733
+ emitEvent,
3734
+ };
3735
+ }
3736
+
3737
+ function useFullscreenModule({ mainCarouselWrapperRef, emitEvent, handleResize, }) {
3738
+ const isFullscreen = useRef(false);
3739
+ useEffect(() => {
3740
+ function handleFullscreenChange() {
3741
+ if (document.fullscreenElement) {
3742
+ setIsFullscreen(true);
3743
+ emitEvent({
3744
+ eventName: 'onFullscreenChange',
3745
+ isFullscreen: true,
3746
+ });
3747
+ handleResize && handleResize();
3748
+ }
3749
+ if (!document.fullscreenElement) {
3750
+ setIsFullscreen(false);
3751
+ emitEvent({
3752
+ eventName: 'onFullscreenChange',
3753
+ isFullscreen: false,
3754
+ });
3755
+ handleResize && handleResize();
3756
+ }
3757
+ }
3758
+ if (screenfull.isEnabled) {
3759
+ screenfull.on('change', handleFullscreenChange);
3760
+ return () => {
3761
+ if (screenfull.isEnabled) {
3762
+ screenfull.off('change', handleFullscreenChange);
3763
+ }
3764
+ };
3765
+ }
3766
+ }, []);
3767
+ function setIsFullscreen(_isFullscreen) {
3768
+ isFullscreen.current = _isFullscreen;
3769
+ }
3770
+ function getIsFullscreen() {
3771
+ return isFullscreen.current;
3772
+ }
3773
+ function enterFullscreen(elementRef) {
3774
+ if (screenfull.isEnabled) {
3775
+ screenfull.request((elementRef || mainCarouselWrapperRef.current));
3776
+ }
3777
+ }
3778
+ function exitFullscreen() {
3779
+ screenfull.isEnabled && screenfull.exit();
3780
+ }
3781
+ return {
3782
+ enterFullscreen,
3783
+ exitFullscreen,
3784
+ getIsFullscreen,
3785
+ };
3786
+ }
3787
+
3788
+ function isInViewport(el) {
3789
+ const rect = el.getBoundingClientRect();
3790
+ return (rect.top >= 0 &&
3791
+ rect.left >= 0 &&
3792
+ rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
3793
+ rect.right <= (window.innerWidth || document.documentElement.clientWidth));
3794
+ }
3795
+ function useThumbsModule({ thumbsSlideAxis = 'x', withThumbs = false, prepareThumbsData, items, }) {
3796
+ const wrapperRef = useRef(null);
3797
+ const [spring, setSpring] = useSpring(() => ({
3798
+ val: 0,
3799
+ }));
3800
+ function getTotalScrollValue() {
3801
+ var _a;
3802
+ return Math.round(Number((_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a[thumbsSlideAxis === 'x' ? 'scrollWidth' : 'scrollHeight']) -
3803
+ wrapperRef.current.getBoundingClientRect()[thumbsSlideAxis === 'x' ? 'width' : 'height']);
3804
+ }
3805
+ function handleScroll(activeItem) {
3806
+ var _a, _b;
3807
+ function getThumbNode() {
3808
+ if (wrapperRef.current) {
3809
+ return wrapperRef.current.querySelector(`#thumb-item-${items[activeItem].id}`);
3810
+ }
3811
+ return null;
3812
+ }
3813
+ const thumbNode = getThumbNode();
3814
+ if (thumbNode && wrapperRef.current) {
3815
+ if (!isInViewport(thumbNode)) {
3816
+ const offset = thumbNode.offsetLeft;
3817
+ const val = offset > getTotalScrollValue() ? getTotalScrollValue() : offset;
3818
+ setSpring.start({
3819
+ from: {
3820
+ val: (_b = (_a = wrapperRef.current) === null || _a === void 0 ? void 0 : _a[thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop']) !== null && _b !== void 0 ? _b : 0,
3821
+ },
3822
+ to: {
3823
+ val,
3824
+ },
3825
+ onChange: ({ value }) => {
3826
+ if (wrapperRef.current) {
3827
+ wrapperRef.current[thumbsSlideAxis === 'x' ? 'scrollLeft' : 'scrollTop'] =
3828
+ Math.abs(value.val);
3829
+ }
3830
+ },
3831
+ });
3832
+ }
3833
+ }
3834
+ }
3835
+ function handlePrepareThumbsData() {
3836
+ function getPreparedItems(_items) {
3837
+ return _items.map(i => ({
3838
+ id: i.id,
3839
+ renderThumb: i.renderThumb,
3840
+ }));
3841
+ }
3842
+ if (prepareThumbsData) {
3843
+ return prepareThumbsData(getPreparedItems(items));
3844
+ }
3845
+ return getPreparedItems(items);
3846
+ }
3847
+ const thumbsFragment = withThumbs ? (jsx("div", Object.assign({ className: "use-spring-carousel-thumbs-wrapper", ref: wrapperRef, onWheel: () => spring.val.stop(), style: Object.assign({ display: 'flex', flex: '1', position: 'relative', width: '100%', height: '100%', flexDirection: thumbsSlideAxis === 'x' ? 'row' : 'column' }, (thumbsSlideAxis === 'x'
3848
+ ? { overflowX: 'auto' }
3849
+ : {
3850
+ overflowY: 'auto',
3851
+ maxHeight: '100%',
3852
+ })) }, { children: handlePrepareThumbsData().map(({ id, renderThumb }) => {
3853
+ const thumbId = `thumb-item-${id}`;
3854
+ return (jsx("div", Object.assign({ id: thumbId, className: "thumb-item" }, { children: renderThumb }), thumbId));
3855
+ }) }))) : null;
3856
+ return {
3857
+ thumbsFragment,
3858
+ handleScroll,
3859
+ };
3860
+ }
3861
+
3862
+ export { useEventsModule as a, useThumbsModule as b, useFullscreenModule as c, config as d, useSpring as u };
3863
+ //# sourceMappingURL=useThumbsModule-dc12dd34.js.map