@nation-a/ui 0.4.0 → 0.5.0

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.
package/dist/index.cjs CHANGED
@@ -3,6 +3,23 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const jsxRuntime = require("react/jsx-runtime");
4
4
  const React = require("react");
5
5
  const reactDom = require("react-dom");
6
+ function _interopNamespaceDefault(e) {
7
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
8
+ if (e) {
9
+ for (const k in e) {
10
+ if (k !== "default") {
11
+ const d = Object.getOwnPropertyDescriptor(e, k);
12
+ Object.defineProperty(n, k, d.get ? d : {
13
+ enumerable: true,
14
+ get: () => e[k]
15
+ });
16
+ }
17
+ }
18
+ }
19
+ n.default = e;
20
+ return Object.freeze(n);
21
+ }
22
+ const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
6
23
  function isObject$1(value) {
7
24
  return typeof value === "object" && value != null && !Array.isArray(value);
8
25
  }
@@ -74,14 +91,14 @@ function mergeProps$1(...sources) {
74
91
  }
75
92
  var isNotNullish = (element) => element != null;
76
93
  function walkObject(target, predicate, options = {}) {
77
- const { stop, getKey } = options;
94
+ const { stop: stop2, getKey } = options;
78
95
  function inner(value, path = []) {
79
96
  if (isObjectOrArray(value)) {
80
97
  const result = {};
81
98
  for (const [prop, child] of Object.entries(value)) {
82
99
  const key = (getKey == null ? void 0 : getKey(prop, child)) ?? prop;
83
100
  const childPath = [...path, key];
84
- if (stop == null ? void 0 : stop(value, childPath)) {
101
+ if (stop2 == null ? void 0 : stop2(value, childPath)) {
85
102
  return predicate(value, path);
86
103
  }
87
104
  const next = inner(child, childPath);
@@ -344,15 +361,15 @@ function cx() {
344
361
  }
345
362
  return str;
346
363
  }
347
- const defaults = (conf) => ({
364
+ const defaults$1 = (conf) => ({
348
365
  base: {},
349
366
  variants: {},
350
367
  defaultVariants: {},
351
368
  compoundVariants: [],
352
369
  ...conf
353
370
  });
354
- function cva(config) {
355
- const { base, variants, defaultVariants, compoundVariants } = defaults(config);
371
+ function cva(config2) {
372
+ const { base, variants, defaultVariants, compoundVariants } = defaults$1(config2);
356
373
  const getVariantProps = (variants2) => ({ ...defaultVariants, ...compact$1(variants2) });
357
374
  function resolve(props = {}) {
358
375
  var _a;
@@ -367,7 +384,7 @@ function cva(config) {
367
384
  return mergeCss(variantCss, compoundVariantCss);
368
385
  }
369
386
  function merge(__cva) {
370
- const override = defaults(__cva.config);
387
+ const override = defaults$1(__cva.config);
371
388
  const variantKeys2 = uniq(__cva.variantKeys, Object.keys(variants));
372
389
  return cva({
373
390
  base: mergeCss(base, override.base),
@@ -391,7 +408,7 @@ function cva(config) {
391
408
  variantMap,
392
409
  variantKeys,
393
410
  raw: resolve,
394
- config,
411
+ config: config2,
395
412
  merge,
396
413
  splitVariantProps,
397
414
  getVariantProps
@@ -412,18 +429,18 @@ function getCompoundVariantCss(compoundVariants, variantMap) {
412
429
  return result;
413
430
  }
414
431
  const slotClass = (className, slot) => className + "__" + slot;
415
- function sva(config) {
416
- const slots = Object.entries(getSlotRecipes(config)).map(([slot, slotCva]) => [slot, cva(slotCva)]);
417
- const defaultVariants = config.defaultVariants ?? {};
432
+ function sva(config2) {
433
+ const slots = Object.entries(getSlotRecipes(config2)).map(([slot, slotCva]) => [slot, cva(slotCva)]);
434
+ const defaultVariants = config2.defaultVariants ?? {};
418
435
  function svaFn(props) {
419
- const result = slots.map(([slot, cvaFn]) => [slot, cx(cvaFn(props), config.className && slotClass(config.className, slot))]);
436
+ const result = slots.map(([slot, cvaFn]) => [slot, cx(cvaFn(props), config2.className && slotClass(config2.className, slot))]);
420
437
  return Object.fromEntries(result);
421
438
  }
422
439
  function raw(props) {
423
440
  const result = slots.map(([slot, cvaFn]) => [slot, cvaFn.raw(props)]);
424
441
  return Object.fromEntries(result);
425
442
  }
426
- const variants = config.variants ?? {};
443
+ const variants = config2.variants ?? {};
427
444
  const variantKeys = Object.keys(variants);
428
445
  function splitVariantProps(props) {
429
446
  return splitProps(props, variantKeys);
@@ -461,7 +478,7 @@ const composeCvaFn = (cvaA, cvaB) => {
461
478
  (_a = TypeError.captureStackTrace) == null ? void 0 : _a.call(TypeError, error);
462
479
  throw error;
463
480
  };
464
- const getDisplayName = (Component) => {
481
+ const getDisplayName$1 = (Component) => {
465
482
  if (typeof Component === "string") return Component;
466
483
  return (Component == null ? void 0 : Component.displayName) || (Component == null ? void 0 : Component.name) || "Component";
467
484
  };
@@ -502,7 +519,7 @@ function styledFn(Dynamic, configOrCva = {}, options = {}) {
502
519
  className: classes()
503
520
  }, combinedProps.children ?? children);
504
521
  });
505
- const name = getDisplayName(__base__);
522
+ const name = getDisplayName$1(__base__);
506
523
  StyledComponent.displayName = `styled.${name}`;
507
524
  StyledComponent.__cva__ = __cvaFn__;
508
525
  StyledComponent.__base__ = __base__;
@@ -572,7 +589,7 @@ function createContext(options = {}) {
572
589
  }
573
590
  return [Context.Provider, useContext$1, Context];
574
591
  }
575
- function toArray(v2) {
592
+ function toArray$1(v2) {
576
593
  if (!v2) return [];
577
594
  return Array.isArray(v2) ? v2 : [v2];
578
595
  }
@@ -780,7 +797,7 @@ function nextTick(fn) {
780
797
  set2.forEach((fn2) => fn2());
781
798
  };
782
799
  }
783
- function raf$1(fn) {
800
+ function raf$2(fn) {
784
801
  let cleanup;
785
802
  const id = globalThis.requestAnimationFrame(() => {
786
803
  cleanup = fn();
@@ -918,8 +935,8 @@ function mergeProps(...args) {
918
935
  }
919
936
  return result;
920
937
  }
921
- function createMachine(config) {
922
- return config;
938
+ function createMachine(config2) {
939
+ return config2;
923
940
  }
924
941
  function createScope(props) {
925
942
  const getRootNode = () => {
@@ -1041,16 +1058,16 @@ function useMachine(machine2, userProps = {}) {
1041
1058
  prop,
1042
1059
  bindable: useBindable,
1043
1060
  scope,
1044
- flush,
1061
+ flush: flush$1,
1045
1062
  getContext() {
1046
- return ctx;
1063
+ return ctx2;
1047
1064
  },
1048
1065
  getComputed() {
1049
1066
  return computed;
1050
1067
  }
1051
1068
  });
1052
1069
  const contextRef = useLiveRef(context2);
1053
- const ctx = {
1070
+ const ctx2 = {
1054
1071
  get(key) {
1055
1072
  var _a2;
1056
1073
  return (_a2 = contextRef.current) == null ? void 0 : _a2[key].ref.current;
@@ -1092,10 +1109,10 @@ function useMachine(machine2, userProps = {}) {
1092
1109
  return !!((_b2 = (_a2 = machine2.states[state.ref.current]) == null ? void 0 : _a2.tags) == null ? void 0 : _b2.includes(tag));
1093
1110
  }
1094
1111
  });
1095
- const refs = useRefs(((_c = machine2.refs) == null ? void 0 : _c.call(machine2, { prop, context: ctx })) ?? {});
1112
+ const refs = useRefs(((_c = machine2.refs) == null ? void 0 : _c.call(machine2, { prop, context: ctx2 })) ?? {});
1096
1113
  const getParams = () => ({
1097
1114
  state: getState(),
1098
- context: ctx,
1115
+ context: ctx2,
1099
1116
  event: getEvent(),
1100
1117
  prop,
1101
1118
  send,
@@ -1104,7 +1121,7 @@ function useMachine(machine2, userProps = {}) {
1104
1121
  track: useTrack,
1105
1122
  refs,
1106
1123
  computed,
1107
- flush,
1124
+ flush: flush$1,
1108
1125
  scope,
1109
1126
  choose
1110
1127
  });
@@ -1143,7 +1160,7 @@ function useMachine(machine2, userProps = {}) {
1143
1160
  return () => cleanups2.forEach((fn) => fn == null ? void 0 : fn());
1144
1161
  };
1145
1162
  const choose = (transitions) => {
1146
- return toArray(transitions).find((t) => {
1163
+ return toArray$1(transitions).find((t) => {
1147
1164
  let result = !t.guard;
1148
1165
  if (isString(t.guard)) result = !!guard(t.guard);
1149
1166
  else if (isFunction(t.guard)) result = t.guard(getParams());
@@ -1154,7 +1171,7 @@ function useMachine(machine2, userProps = {}) {
1154
1171
  ensure(machine2.computed, `[zag-js] No computed object found on machine`);
1155
1172
  const fn = machine2.computed[key];
1156
1173
  return fn({
1157
- context: ctx,
1174
+ context: ctx2,
1158
1175
  event: getEvent(),
1159
1176
  prop,
1160
1177
  refs,
@@ -1237,7 +1254,7 @@ function useMachine(machine2, userProps = {}) {
1237
1254
  return {
1238
1255
  state: getState(),
1239
1256
  send,
1240
- context: ctx,
1257
+ context: ctx2,
1241
1258
  prop,
1242
1259
  scope,
1243
1260
  refs,
@@ -1256,7 +1273,7 @@ function useProp(value) {
1256
1273
  return ref.current[key];
1257
1274
  };
1258
1275
  }
1259
- function flush(fn) {
1276
+ function flush$1(fn) {
1260
1277
  queueMicrotask(() => {
1261
1278
  reactDom.flushSync(() => fn());
1262
1279
  });
@@ -1510,7 +1527,7 @@ function trackInteractOutsideImpl(node, options) {
1510
1527
  function onPointerDown(event) {
1511
1528
  function handler() {
1512
1529
  var _a;
1513
- const func = defer ? raf$1 : (v2) => v2();
1530
+ const func = defer ? raf$2 : (v2) => v2();
1514
1531
  const composedPath = ((_a = event.composedPath) == null ? void 0 : _a.call(event)) ?? [event.target];
1515
1532
  func(() => {
1516
1533
  if (!node || !isEventOutside(event)) return;
@@ -1545,7 +1562,7 @@ function trackInteractOutsideImpl(node, options) {
1545
1562
  cleanups2.add(frames.addEventListener("pointerdown", onPointerDown, true));
1546
1563
  }, 0);
1547
1564
  function onFocusin(event) {
1548
- const func = defer ? raf$1 : (v2) => v2();
1565
+ const func = defer ? raf$2 : (v2) => v2();
1549
1566
  func(() => {
1550
1567
  if (!node || !isEventOutside(event)) return;
1551
1568
  if (onFocusOutside || onInteractOutside) {
@@ -1574,7 +1591,7 @@ function trackInteractOutsideImpl(node, options) {
1574
1591
  }
1575
1592
  function trackInteractOutside(nodeOrFn, options) {
1576
1593
  const { defer } = options;
1577
- const func = defer ? raf$1 : (v2) => v2();
1594
+ const func = defer ? raf$2 : (v2) => v2();
1578
1595
  const cleanups2 = [];
1579
1596
  cleanups2.push(
1580
1597
  func(() => {
@@ -1769,7 +1786,7 @@ function trackDismissableElementImpl(node, options) {
1769
1786
  }
1770
1787
  function trackDismissableElement(nodeOrFn, options) {
1771
1788
  const { defer } = options;
1772
- const func = defer ? raf$1 : (v2) => v2();
1789
+ const func = defer ? raf$2 : (v2) => v2();
1773
1790
  const cleanups2 = [];
1774
1791
  cleanups2.push(
1775
1792
  func(() => {
@@ -1788,19 +1805,19 @@ const [RenderStrategyPropsProvider, useRenderStrategyPropsContext] = createConte
1788
1805
  });
1789
1806
  const splitRenderStrategyProps = (props) => createSplitProps()(props, ["lazyMount", "unmountOnExit"]);
1790
1807
  function useEvent(callback, opts = {}) {
1791
- const { sync = false } = opts;
1808
+ const { sync: sync2 = false } = opts;
1792
1809
  const callbackRef = useLatestRef(callback);
1793
1810
  return React.useCallback(
1794
1811
  // biome-ignore lint/suspicious/noExplicitAny: <explanation>
1795
1812
  (...args) => {
1796
1813
  var _a;
1797
- if (sync) return queueMicrotask(() => {
1814
+ if (sync2) return queueMicrotask(() => {
1798
1815
  var _a2;
1799
1816
  return (_a2 = callbackRef.current) == null ? void 0 : _a2.call(callbackRef, ...args);
1800
1817
  });
1801
1818
  return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
1802
1819
  },
1803
- [sync, callbackRef]
1820
+ [sync2, callbackRef]
1804
1821
  );
1805
1822
  }
1806
1823
  function useLatestRef(value) {
@@ -1932,7 +1949,7 @@ var machine$1 = createMachine({
1932
1949
  if (!presentProp && (node == null ? void 0 : node.ownerDocument.visibilityState) === "hidden") {
1933
1950
  return send({ type: "UNMOUNT", src: "visibilitychange" });
1934
1951
  }
1935
- raf$1(() => {
1952
+ raf$2(() => {
1936
1953
  var _a, _b;
1937
1954
  const animationName = getAnimationName(refs.get("styles"));
1938
1955
  context2.set("unmountAnimationName", animationName);
@@ -1944,7 +1961,7 @@ var machine$1 = createMachine({
1944
1961
  });
1945
1962
  },
1946
1963
  setPrevAnimationName: ({ context: context2, refs }) => {
1947
- raf$1(() => {
1964
+ raf$2(() => {
1948
1965
  context2.set("prevAnimationName", getAnimationName(refs.get("styles")));
1949
1966
  });
1950
1967
  },
@@ -2119,13 +2136,13 @@ var hideOthers = (originalTarget, parentNode = getParentNode(originalTarget), ma
2119
2136
  controlAttribute: "aria-hidden"
2120
2137
  });
2121
2138
  };
2122
- var raf = (fn) => {
2139
+ var raf$1 = (fn) => {
2123
2140
  const frameId = requestAnimationFrame(() => fn());
2124
2141
  return () => cancelAnimationFrame(frameId);
2125
2142
  };
2126
2143
  function ariaHidden(targetsOrFn, options = {}) {
2127
2144
  const { defer = true } = options;
2128
- const func = defer ? raf : (v2) => v2();
2145
+ const func = defer ? raf$1 : (v2) => v2();
2129
2146
  const cleanups2 = [];
2130
2147
  cleanups2.push(
2131
2148
  func(() => {
@@ -2181,8 +2198,8 @@ const DialogPositioner = React.forwardRef((props, ref) => {
2181
2198
  return /* @__PURE__ */ jsxRuntime.jsx(ark.div, { ...mergedProps, ref });
2182
2199
  });
2183
2200
  DialogPositioner.displayName = "DialogPositioner";
2184
- var __defProp = Object.defineProperty;
2185
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2201
+ var __defProp$1 = Object.defineProperty;
2202
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
2186
2203
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
2187
2204
  var activeFocusTraps = {
2188
2205
  activateTrap(trapStack, trap) {
@@ -2547,7 +2564,7 @@ var FocusTrap = class {
2547
2564
  return destinationNode;
2548
2565
  });
2549
2566
  this.trapStack = options.trapStack || sharedTrapStack;
2550
- const config = {
2567
+ const config2 = {
2551
2568
  returnFocusOnDeactivate: true,
2552
2569
  escapeDeactivates: true,
2553
2570
  delayInitialFocus: true,
@@ -2559,8 +2576,8 @@ var FocusTrap = class {
2559
2576
  },
2560
2577
  ...options
2561
2578
  };
2562
- this.doc = config.document || getDocument(Array.isArray(elements) ? elements[0] : elements);
2563
- this.config = config;
2579
+ this.doc = config2.document || getDocument(Array.isArray(elements) ? elements[0] : elements);
2580
+ this.config = config2;
2564
2581
  this.updateContainerElements(elements);
2565
2582
  this.setupMutationObserver();
2566
2583
  }
@@ -2678,7 +2695,7 @@ var delay = (fn) => setTimeout(fn, 0);
2678
2695
  var isSelectableInput = (node) => node.localName === "input" && "select" in node && typeof node.select === "function";
2679
2696
  function trapFocus(el, options = {}) {
2680
2697
  let trap;
2681
- const cleanup = raf$1(() => {
2698
+ const cleanup = raf$2(() => {
2682
2699
  const contentEl = typeof el === "function" ? el() : el;
2683
2700
  if (!contentEl) return;
2684
2701
  trap = new FocusTrap(contentEl, {
@@ -2780,41 +2797,41 @@ var anatomy = createAnatomy("dialog").parts(
2780
2797
  "closeTrigger"
2781
2798
  );
2782
2799
  var parts = anatomy.build();
2783
- var getPositionerId = (ctx) => {
2800
+ var getPositionerId = (ctx2) => {
2784
2801
  var _a;
2785
- return ((_a = ctx.ids) == null ? void 0 : _a.positioner) ?? `dialog:${ctx.id}:positioner`;
2802
+ return ((_a = ctx2.ids) == null ? void 0 : _a.positioner) ?? `dialog:${ctx2.id}:positioner`;
2786
2803
  };
2787
- var getBackdropId = (ctx) => {
2804
+ var getBackdropId = (ctx2) => {
2788
2805
  var _a;
2789
- return ((_a = ctx.ids) == null ? void 0 : _a.backdrop) ?? `dialog:${ctx.id}:backdrop`;
2806
+ return ((_a = ctx2.ids) == null ? void 0 : _a.backdrop) ?? `dialog:${ctx2.id}:backdrop`;
2790
2807
  };
2791
- var getContentId = (ctx) => {
2808
+ var getContentId = (ctx2) => {
2792
2809
  var _a;
2793
- return ((_a = ctx.ids) == null ? void 0 : _a.content) ?? `dialog:${ctx.id}:content`;
2810
+ return ((_a = ctx2.ids) == null ? void 0 : _a.content) ?? `dialog:${ctx2.id}:content`;
2794
2811
  };
2795
- var getTriggerId = (ctx) => {
2812
+ var getTriggerId = (ctx2) => {
2796
2813
  var _a;
2797
- return ((_a = ctx.ids) == null ? void 0 : _a.trigger) ?? `dialog:${ctx.id}:trigger`;
2814
+ return ((_a = ctx2.ids) == null ? void 0 : _a.trigger) ?? `dialog:${ctx2.id}:trigger`;
2798
2815
  };
2799
- var getTitleId = (ctx) => {
2816
+ var getTitleId = (ctx2) => {
2800
2817
  var _a;
2801
- return ((_a = ctx.ids) == null ? void 0 : _a.title) ?? `dialog:${ctx.id}:title`;
2818
+ return ((_a = ctx2.ids) == null ? void 0 : _a.title) ?? `dialog:${ctx2.id}:title`;
2802
2819
  };
2803
- var getDescriptionId = (ctx) => {
2820
+ var getDescriptionId = (ctx2) => {
2804
2821
  var _a;
2805
- return ((_a = ctx.ids) == null ? void 0 : _a.description) ?? `dialog:${ctx.id}:description`;
2822
+ return ((_a = ctx2.ids) == null ? void 0 : _a.description) ?? `dialog:${ctx2.id}:description`;
2806
2823
  };
2807
- var getCloseTriggerId = (ctx) => {
2824
+ var getCloseTriggerId = (ctx2) => {
2808
2825
  var _a;
2809
- return ((_a = ctx.ids) == null ? void 0 : _a.closeTrigger) ?? `dialog:${ctx.id}:close`;
2826
+ return ((_a = ctx2.ids) == null ? void 0 : _a.closeTrigger) ?? `dialog:${ctx2.id}:close`;
2810
2827
  };
2811
- var getContentEl = (ctx) => ctx.getById(getContentId(ctx));
2812
- var getPositionerEl = (ctx) => ctx.getById(getPositionerId(ctx));
2813
- var getBackdropEl = (ctx) => ctx.getById(getBackdropId(ctx));
2814
- var getTriggerEl = (ctx) => ctx.getById(getTriggerId(ctx));
2815
- var getTitleEl = (ctx) => ctx.getById(getTitleId(ctx));
2816
- var getDescriptionEl = (ctx) => ctx.getById(getDescriptionId(ctx));
2817
- var getCloseTriggerEl = (ctx) => ctx.getById(getCloseTriggerId(ctx));
2828
+ var getContentEl = (ctx2) => ctx2.getById(getContentId(ctx2));
2829
+ var getPositionerEl = (ctx2) => ctx2.getById(getPositionerId(ctx2));
2830
+ var getBackdropEl = (ctx2) => ctx2.getById(getBackdropId(ctx2));
2831
+ var getTriggerEl = (ctx2) => ctx2.getById(getTriggerId(ctx2));
2832
+ var getTitleEl = (ctx2) => ctx2.getById(getTitleId(ctx2));
2833
+ var getDescriptionEl = (ctx2) => ctx2.getById(getDescriptionId(ctx2));
2834
+ var getCloseTriggerEl = (ctx2) => ctx2.getById(getCloseTriggerId(ctx2));
2818
2835
  function connect(service, normalize) {
2819
2836
  const { state, send, context: context2, prop, scope } = service;
2820
2837
  const ariaLabel = prop("aria-label");
@@ -3054,7 +3071,7 @@ var machine = createMachine({
3054
3071
  },
3055
3072
  actions: {
3056
3073
  checkRenderedElements({ context: context2, scope }) {
3057
- raf$1(() => {
3074
+ raf$2(() => {
3058
3075
  context2.set("rendered", {
3059
3076
  title: !!getTitleEl(scope),
3060
3077
  description: !!getDescriptionEl(scope)
@@ -3062,7 +3079,7 @@ var machine = createMachine({
3062
3079
  });
3063
3080
  },
3064
3081
  syncZIndex({ scope }) {
3065
- raf$1(() => {
3082
+ raf$2(() => {
3066
3083
  const contentEl = getContentEl(scope);
3067
3084
  if (!contentEl) return;
3068
3085
  const styles = getComputedStyle(contentEl);
@@ -3856,7 +3873,7 @@ const dialogRecipe = sva({
3856
3873
  });
3857
3874
  const { withRootProvider, withContext } = createStyleContext(dialogRecipe);
3858
3875
  const Root = withRootProvider(DialogRoot);
3859
- const Backdrop = withContext(DialogBackdrop, "backdrop");
3876
+ const Backdrop$1 = withContext(DialogBackdrop, "backdrop");
3860
3877
  const Trigger = withContext(DialogTrigger, "trigger");
3861
3878
  const Content = withContext(DialogContent, "content");
3862
3879
  const Title = withContext(DialogTitle, "title");
@@ -3864,7 +3881,7 @@ const Description = withContext(DialogDescription, "description");
3864
3881
  const Positioner = withContext(DialogPositioner, "positioner");
3865
3882
  const Dialog = {
3866
3883
  Root,
3867
- Backdrop,
3884
+ Backdrop: Backdrop$1,
3868
3885
  Trigger,
3869
3886
  Content,
3870
3887
  Title,
@@ -4046,6 +4063,3622 @@ const IconButton = React.forwardRef(
4046
4063
  }
4047
4064
  );
4048
4065
  IconButton.displayName = "IconButton";
4066
+ var updateQueue = makeQueue();
4067
+ var raf = (fn) => schedule(fn, updateQueue);
4068
+ var writeQueue = makeQueue();
4069
+ raf.write = (fn) => schedule(fn, writeQueue);
4070
+ var onStartQueue = makeQueue();
4071
+ raf.onStart = (fn) => schedule(fn, onStartQueue);
4072
+ var onFrameQueue = makeQueue();
4073
+ raf.onFrame = (fn) => schedule(fn, onFrameQueue);
4074
+ var onFinishQueue = makeQueue();
4075
+ raf.onFinish = (fn) => schedule(fn, onFinishQueue);
4076
+ var timeouts = [];
4077
+ raf.setTimeout = (handler, ms) => {
4078
+ const time = raf.now() + ms;
4079
+ const cancel = () => {
4080
+ const i = timeouts.findIndex((t) => t.cancel == cancel);
4081
+ if (~i)
4082
+ timeouts.splice(i, 1);
4083
+ pendingCount -= ~i ? 1 : 0;
4084
+ };
4085
+ const timeout = { time, handler, cancel };
4086
+ timeouts.splice(findTimeout(time), 0, timeout);
4087
+ pendingCount += 1;
4088
+ start();
4089
+ return timeout;
4090
+ };
4091
+ var findTimeout = (time) => ~(~timeouts.findIndex((t) => t.time > time) || ~timeouts.length);
4092
+ raf.cancel = (fn) => {
4093
+ onStartQueue.delete(fn);
4094
+ onFrameQueue.delete(fn);
4095
+ onFinishQueue.delete(fn);
4096
+ updateQueue.delete(fn);
4097
+ writeQueue.delete(fn);
4098
+ };
4099
+ raf.sync = (fn) => {
4100
+ sync = true;
4101
+ raf.batchedUpdates(fn);
4102
+ sync = false;
4103
+ };
4104
+ raf.throttle = (fn) => {
4105
+ let lastArgs;
4106
+ function queuedFn() {
4107
+ try {
4108
+ fn(...lastArgs);
4109
+ } finally {
4110
+ lastArgs = null;
4111
+ }
4112
+ }
4113
+ function throttled(...args) {
4114
+ lastArgs = args;
4115
+ raf.onStart(queuedFn);
4116
+ }
4117
+ throttled.handler = fn;
4118
+ throttled.cancel = () => {
4119
+ onStartQueue.delete(queuedFn);
4120
+ lastArgs = null;
4121
+ };
4122
+ return throttled;
4123
+ };
4124
+ var nativeRaf = typeof window != "undefined" ? window.requestAnimationFrame : (
4125
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
4126
+ () => {
4127
+ }
4128
+ );
4129
+ raf.use = (impl) => nativeRaf = impl;
4130
+ raf.now = typeof performance != "undefined" ? () => performance.now() : Date.now;
4131
+ raf.batchedUpdates = (fn) => fn();
4132
+ raf.catch = console.error;
4133
+ raf.frameLoop = "always";
4134
+ raf.advance = () => {
4135
+ if (raf.frameLoop !== "demand") {
4136
+ console.warn(
4137
+ "Cannot call the manual advancement of rafz whilst frameLoop is not set as demand"
4138
+ );
4139
+ } else {
4140
+ update();
4141
+ }
4142
+ };
4143
+ var ts = -1;
4144
+ var pendingCount = 0;
4145
+ var sync = false;
4146
+ function schedule(fn, queue) {
4147
+ if (sync) {
4148
+ queue.delete(fn);
4149
+ fn(0);
4150
+ } else {
4151
+ queue.add(fn);
4152
+ start();
4153
+ }
4154
+ }
4155
+ function start() {
4156
+ if (ts < 0) {
4157
+ ts = 0;
4158
+ if (raf.frameLoop !== "demand") {
4159
+ nativeRaf(loop);
4160
+ }
4161
+ }
4162
+ }
4163
+ function stop() {
4164
+ ts = -1;
4165
+ }
4166
+ function loop() {
4167
+ if (~ts) {
4168
+ nativeRaf(loop);
4169
+ raf.batchedUpdates(update);
4170
+ }
4171
+ }
4172
+ function update() {
4173
+ const prevTs = ts;
4174
+ ts = raf.now();
4175
+ const count = findTimeout(ts);
4176
+ if (count) {
4177
+ eachSafely(timeouts.splice(0, count), (t) => t.handler());
4178
+ pendingCount -= count;
4179
+ }
4180
+ if (!pendingCount) {
4181
+ stop();
4182
+ return;
4183
+ }
4184
+ onStartQueue.flush();
4185
+ updateQueue.flush(prevTs ? Math.min(64, ts - prevTs) : 16.667);
4186
+ onFrameQueue.flush();
4187
+ writeQueue.flush();
4188
+ onFinishQueue.flush();
4189
+ }
4190
+ function makeQueue() {
4191
+ let next = /* @__PURE__ */ new Set();
4192
+ let current = next;
4193
+ return {
4194
+ add(fn) {
4195
+ pendingCount += current == next && !next.has(fn) ? 1 : 0;
4196
+ next.add(fn);
4197
+ },
4198
+ delete(fn) {
4199
+ pendingCount -= current == next && next.has(fn) ? 1 : 0;
4200
+ return next.delete(fn);
4201
+ },
4202
+ flush(arg) {
4203
+ if (current.size) {
4204
+ next = /* @__PURE__ */ new Set();
4205
+ pendingCount -= current.size;
4206
+ eachSafely(current, (fn) => fn(arg) && next.add(fn));
4207
+ pendingCount += next.size;
4208
+ current = next;
4209
+ }
4210
+ }
4211
+ };
4212
+ }
4213
+ function eachSafely(values, each2) {
4214
+ values.forEach((value) => {
4215
+ try {
4216
+ each2(value);
4217
+ } catch (e) {
4218
+ raf.catch(e);
4219
+ }
4220
+ });
4221
+ }
4222
+ var __defProp = Object.defineProperty;
4223
+ var __export = (target, all) => {
4224
+ for (var name in all)
4225
+ __defProp(target, name, { get: all[name], enumerable: true });
4226
+ };
4227
+ var globals_exports = {};
4228
+ __export(globals_exports, {
4229
+ assign: () => assign,
4230
+ colors: () => colors,
4231
+ createStringInterpolator: () => createStringInterpolator,
4232
+ skipAnimation: () => skipAnimation,
4233
+ to: () => to,
4234
+ willAdvance: () => willAdvance
4235
+ });
4236
+ function noop() {
4237
+ }
4238
+ var defineHidden = (obj, key, value) => Object.defineProperty(obj, key, { value, writable: true, configurable: true });
4239
+ var is = {
4240
+ arr: Array.isArray,
4241
+ obj: (a) => !!a && a.constructor.name === "Object",
4242
+ fun: (a) => typeof a === "function",
4243
+ str: (a) => typeof a === "string",
4244
+ num: (a) => typeof a === "number",
4245
+ und: (a) => a === void 0
4246
+ };
4247
+ function isEqual(a, b) {
4248
+ if (is.arr(a)) {
4249
+ if (!is.arr(b) || a.length !== b.length)
4250
+ return false;
4251
+ for (let i = 0; i < a.length; i++) {
4252
+ if (a[i] !== b[i])
4253
+ return false;
4254
+ }
4255
+ return true;
4256
+ }
4257
+ return a === b;
4258
+ }
4259
+ var each = (obj, fn) => obj.forEach(fn);
4260
+ function eachProp(obj, fn, ctx2) {
4261
+ if (is.arr(obj)) {
4262
+ for (let i = 0; i < obj.length; i++) {
4263
+ fn.call(ctx2, obj[i], `${i}`);
4264
+ }
4265
+ return;
4266
+ }
4267
+ for (const key in obj) {
4268
+ if (obj.hasOwnProperty(key)) {
4269
+ fn.call(ctx2, obj[key], key);
4270
+ }
4271
+ }
4272
+ }
4273
+ var toArray = (a) => is.und(a) ? [] : is.arr(a) ? a : [a];
4274
+ function flush(queue, iterator) {
4275
+ if (queue.size) {
4276
+ const items = Array.from(queue);
4277
+ queue.clear();
4278
+ each(items, iterator);
4279
+ }
4280
+ }
4281
+ var flushCalls = (queue, ...args) => flush(queue, (fn) => fn(...args));
4282
+ var isSSR = () => typeof window === "undefined" || !window.navigator || /ServerSideRendering|^Deno\//.test(window.navigator.userAgent);
4283
+ var createStringInterpolator;
4284
+ var to;
4285
+ var colors = null;
4286
+ var skipAnimation = false;
4287
+ var willAdvance = noop;
4288
+ var assign = (globals) => {
4289
+ if (globals.to)
4290
+ to = globals.to;
4291
+ if (globals.now)
4292
+ raf.now = globals.now;
4293
+ if (globals.colors !== void 0)
4294
+ colors = globals.colors;
4295
+ if (globals.skipAnimation != null)
4296
+ skipAnimation = globals.skipAnimation;
4297
+ if (globals.createStringInterpolator)
4298
+ createStringInterpolator = globals.createStringInterpolator;
4299
+ if (globals.requestAnimationFrame)
4300
+ raf.use(globals.requestAnimationFrame);
4301
+ if (globals.batchedUpdates)
4302
+ raf.batchedUpdates = globals.batchedUpdates;
4303
+ if (globals.willAdvance)
4304
+ willAdvance = globals.willAdvance;
4305
+ if (globals.frameLoop)
4306
+ raf.frameLoop = globals.frameLoop;
4307
+ };
4308
+ var startQueue = /* @__PURE__ */ new Set();
4309
+ var currentFrame = [];
4310
+ var prevFrame = [];
4311
+ var priority = 0;
4312
+ var frameLoop = {
4313
+ get idle() {
4314
+ return !startQueue.size && !currentFrame.length;
4315
+ },
4316
+ /** Advance the given animation on every frame until idle. */
4317
+ start(animation) {
4318
+ if (priority > animation.priority) {
4319
+ startQueue.add(animation);
4320
+ raf.onStart(flushStartQueue);
4321
+ } else {
4322
+ startSafely(animation);
4323
+ raf(advance);
4324
+ }
4325
+ },
4326
+ /** Advance all animations by the given time. */
4327
+ advance,
4328
+ /** Call this when an animation's priority changes. */
4329
+ sort(animation) {
4330
+ if (priority) {
4331
+ raf.onFrame(() => frameLoop.sort(animation));
4332
+ } else {
4333
+ const prevIndex = currentFrame.indexOf(animation);
4334
+ if (~prevIndex) {
4335
+ currentFrame.splice(prevIndex, 1);
4336
+ startUnsafely(animation);
4337
+ }
4338
+ }
4339
+ },
4340
+ /**
4341
+ * Clear all animations. For testing purposes.
4342
+ *
4343
+ * ☠️ Never call this from within the frameloop.
4344
+ */
4345
+ clear() {
4346
+ currentFrame = [];
4347
+ startQueue.clear();
4348
+ }
4349
+ };
4350
+ function flushStartQueue() {
4351
+ startQueue.forEach(startSafely);
4352
+ startQueue.clear();
4353
+ raf(advance);
4354
+ }
4355
+ function startSafely(animation) {
4356
+ if (!currentFrame.includes(animation))
4357
+ startUnsafely(animation);
4358
+ }
4359
+ function startUnsafely(animation) {
4360
+ currentFrame.splice(
4361
+ findIndex(currentFrame, (other) => other.priority > animation.priority),
4362
+ 0,
4363
+ animation
4364
+ );
4365
+ }
4366
+ function advance(dt) {
4367
+ const nextFrame = prevFrame;
4368
+ for (let i = 0; i < currentFrame.length; i++) {
4369
+ const animation = currentFrame[i];
4370
+ priority = animation.priority;
4371
+ if (!animation.idle) {
4372
+ willAdvance(animation);
4373
+ animation.advance(dt);
4374
+ if (!animation.idle) {
4375
+ nextFrame.push(animation);
4376
+ }
4377
+ }
4378
+ }
4379
+ priority = 0;
4380
+ prevFrame = currentFrame;
4381
+ prevFrame.length = 0;
4382
+ currentFrame = nextFrame;
4383
+ return currentFrame.length > 0;
4384
+ }
4385
+ function findIndex(arr, test) {
4386
+ const index = arr.findIndex(test);
4387
+ return index < 0 ? arr.length : index;
4388
+ }
4389
+ var colors2 = {
4390
+ transparent: 0,
4391
+ aliceblue: 4042850303,
4392
+ antiquewhite: 4209760255,
4393
+ aqua: 16777215,
4394
+ aquamarine: 2147472639,
4395
+ azure: 4043309055,
4396
+ beige: 4126530815,
4397
+ bisque: 4293182719,
4398
+ black: 255,
4399
+ blanchedalmond: 4293643775,
4400
+ blue: 65535,
4401
+ blueviolet: 2318131967,
4402
+ brown: 2771004159,
4403
+ burlywood: 3736635391,
4404
+ burntsienna: 3934150143,
4405
+ cadetblue: 1604231423,
4406
+ chartreuse: 2147418367,
4407
+ chocolate: 3530104575,
4408
+ coral: 4286533887,
4409
+ cornflowerblue: 1687547391,
4410
+ cornsilk: 4294499583,
4411
+ crimson: 3692313855,
4412
+ cyan: 16777215,
4413
+ darkblue: 35839,
4414
+ darkcyan: 9145343,
4415
+ darkgoldenrod: 3095792639,
4416
+ darkgray: 2846468607,
4417
+ darkgreen: 6553855,
4418
+ darkgrey: 2846468607,
4419
+ darkkhaki: 3182914559,
4420
+ darkmagenta: 2332068863,
4421
+ darkolivegreen: 1433087999,
4422
+ darkorange: 4287365375,
4423
+ darkorchid: 2570243327,
4424
+ darkred: 2332033279,
4425
+ darksalmon: 3918953215,
4426
+ darkseagreen: 2411499519,
4427
+ darkslateblue: 1211993087,
4428
+ darkslategray: 793726975,
4429
+ darkslategrey: 793726975,
4430
+ darkturquoise: 13554175,
4431
+ darkviolet: 2483082239,
4432
+ deeppink: 4279538687,
4433
+ deepskyblue: 12582911,
4434
+ dimgray: 1768516095,
4435
+ dimgrey: 1768516095,
4436
+ dodgerblue: 512819199,
4437
+ firebrick: 2988581631,
4438
+ floralwhite: 4294635775,
4439
+ forestgreen: 579543807,
4440
+ fuchsia: 4278255615,
4441
+ gainsboro: 3705462015,
4442
+ ghostwhite: 4177068031,
4443
+ gold: 4292280575,
4444
+ goldenrod: 3668254975,
4445
+ gray: 2155905279,
4446
+ green: 8388863,
4447
+ greenyellow: 2919182335,
4448
+ grey: 2155905279,
4449
+ honeydew: 4043305215,
4450
+ hotpink: 4285117695,
4451
+ indianred: 3445382399,
4452
+ indigo: 1258324735,
4453
+ ivory: 4294963455,
4454
+ khaki: 4041641215,
4455
+ lavender: 3873897215,
4456
+ lavenderblush: 4293981695,
4457
+ lawngreen: 2096890111,
4458
+ lemonchiffon: 4294626815,
4459
+ lightblue: 2916673279,
4460
+ lightcoral: 4034953471,
4461
+ lightcyan: 3774873599,
4462
+ lightgoldenrodyellow: 4210742015,
4463
+ lightgray: 3553874943,
4464
+ lightgreen: 2431553791,
4465
+ lightgrey: 3553874943,
4466
+ lightpink: 4290167295,
4467
+ lightsalmon: 4288707327,
4468
+ lightseagreen: 548580095,
4469
+ lightskyblue: 2278488831,
4470
+ lightslategray: 2005441023,
4471
+ lightslategrey: 2005441023,
4472
+ lightsteelblue: 2965692159,
4473
+ lightyellow: 4294959359,
4474
+ lime: 16711935,
4475
+ limegreen: 852308735,
4476
+ linen: 4210091775,
4477
+ magenta: 4278255615,
4478
+ maroon: 2147483903,
4479
+ mediumaquamarine: 1724754687,
4480
+ mediumblue: 52735,
4481
+ mediumorchid: 3126187007,
4482
+ mediumpurple: 2473647103,
4483
+ mediumseagreen: 1018393087,
4484
+ mediumslateblue: 2070474495,
4485
+ mediumspringgreen: 16423679,
4486
+ mediumturquoise: 1221709055,
4487
+ mediumvioletred: 3340076543,
4488
+ midnightblue: 421097727,
4489
+ mintcream: 4127193855,
4490
+ mistyrose: 4293190143,
4491
+ moccasin: 4293178879,
4492
+ navajowhite: 4292783615,
4493
+ navy: 33023,
4494
+ oldlace: 4260751103,
4495
+ olive: 2155872511,
4496
+ olivedrab: 1804477439,
4497
+ orange: 4289003775,
4498
+ orangered: 4282712319,
4499
+ orchid: 3664828159,
4500
+ palegoldenrod: 4008225535,
4501
+ palegreen: 2566625535,
4502
+ paleturquoise: 2951671551,
4503
+ palevioletred: 3681588223,
4504
+ papayawhip: 4293907967,
4505
+ peachpuff: 4292524543,
4506
+ peru: 3448061951,
4507
+ pink: 4290825215,
4508
+ plum: 3718307327,
4509
+ powderblue: 2967529215,
4510
+ purple: 2147516671,
4511
+ rebeccapurple: 1714657791,
4512
+ red: 4278190335,
4513
+ rosybrown: 3163525119,
4514
+ royalblue: 1097458175,
4515
+ saddlebrown: 2336560127,
4516
+ salmon: 4202722047,
4517
+ sandybrown: 4104413439,
4518
+ seagreen: 780883967,
4519
+ seashell: 4294307583,
4520
+ sienna: 2689740287,
4521
+ silver: 3233857791,
4522
+ skyblue: 2278484991,
4523
+ slateblue: 1784335871,
4524
+ slategray: 1887473919,
4525
+ slategrey: 1887473919,
4526
+ snow: 4294638335,
4527
+ springgreen: 16744447,
4528
+ steelblue: 1182971135,
4529
+ tan: 3535047935,
4530
+ teal: 8421631,
4531
+ thistle: 3636451583,
4532
+ tomato: 4284696575,
4533
+ turquoise: 1088475391,
4534
+ violet: 4001558271,
4535
+ wheat: 4125012991,
4536
+ white: 4294967295,
4537
+ whitesmoke: 4126537215,
4538
+ yellow: 4294902015,
4539
+ yellowgreen: 2597139199
4540
+ };
4541
+ var NUMBER = "[-+]?\\d*\\.?\\d+";
4542
+ var PERCENTAGE = NUMBER + "%";
4543
+ function call(...parts2) {
4544
+ return "\\(\\s*(" + parts2.join(")\\s*,\\s*(") + ")\\s*\\)";
4545
+ }
4546
+ var rgb = new RegExp("rgb" + call(NUMBER, NUMBER, NUMBER));
4547
+ var rgba = new RegExp("rgba" + call(NUMBER, NUMBER, NUMBER, NUMBER));
4548
+ var hsl = new RegExp("hsl" + call(NUMBER, PERCENTAGE, PERCENTAGE));
4549
+ var hsla = new RegExp(
4550
+ "hsla" + call(NUMBER, PERCENTAGE, PERCENTAGE, NUMBER)
4551
+ );
4552
+ var hex3 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
4553
+ var hex4 = /^#([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/;
4554
+ var hex6 = /^#([0-9a-fA-F]{6})$/;
4555
+ var hex8 = /^#([0-9a-fA-F]{8})$/;
4556
+ function normalizeColor(color) {
4557
+ let match;
4558
+ if (typeof color === "number") {
4559
+ return color >>> 0 === color && color >= 0 && color <= 4294967295 ? color : null;
4560
+ }
4561
+ if (match = hex6.exec(color))
4562
+ return parseInt(match[1] + "ff", 16) >>> 0;
4563
+ if (colors && colors[color] !== void 0) {
4564
+ return colors[color];
4565
+ }
4566
+ if (match = rgb.exec(color)) {
4567
+ return (parse255(match[1]) << 24 | // r
4568
+ parse255(match[2]) << 16 | // g
4569
+ parse255(match[3]) << 8 | // b
4570
+ 255) >>> // a
4571
+ 0;
4572
+ }
4573
+ if (match = rgba.exec(color)) {
4574
+ return (parse255(match[1]) << 24 | // r
4575
+ parse255(match[2]) << 16 | // g
4576
+ parse255(match[3]) << 8 | // b
4577
+ parse1(match[4])) >>> // a
4578
+ 0;
4579
+ }
4580
+ if (match = hex3.exec(color)) {
4581
+ return parseInt(
4582
+ match[1] + match[1] + // r
4583
+ match[2] + match[2] + // g
4584
+ match[3] + match[3] + // b
4585
+ "ff",
4586
+ // a
4587
+ 16
4588
+ ) >>> 0;
4589
+ }
4590
+ if (match = hex8.exec(color))
4591
+ return parseInt(match[1], 16) >>> 0;
4592
+ if (match = hex4.exec(color)) {
4593
+ return parseInt(
4594
+ match[1] + match[1] + // r
4595
+ match[2] + match[2] + // g
4596
+ match[3] + match[3] + // b
4597
+ match[4] + match[4],
4598
+ // a
4599
+ 16
4600
+ ) >>> 0;
4601
+ }
4602
+ if (match = hsl.exec(color)) {
4603
+ return (hslToRgb(
4604
+ parse360(match[1]),
4605
+ // h
4606
+ parsePercentage(match[2]),
4607
+ // s
4608
+ parsePercentage(match[3])
4609
+ // l
4610
+ ) | 255) >>> // a
4611
+ 0;
4612
+ }
4613
+ if (match = hsla.exec(color)) {
4614
+ return (hslToRgb(
4615
+ parse360(match[1]),
4616
+ // h
4617
+ parsePercentage(match[2]),
4618
+ // s
4619
+ parsePercentage(match[3])
4620
+ // l
4621
+ ) | parse1(match[4])) >>> // a
4622
+ 0;
4623
+ }
4624
+ return null;
4625
+ }
4626
+ function hue2rgb(p, q, t) {
4627
+ if (t < 0)
4628
+ t += 1;
4629
+ if (t > 1)
4630
+ t -= 1;
4631
+ if (t < 1 / 6)
4632
+ return p + (q - p) * 6 * t;
4633
+ if (t < 1 / 2)
4634
+ return q;
4635
+ if (t < 2 / 3)
4636
+ return p + (q - p) * (2 / 3 - t) * 6;
4637
+ return p;
4638
+ }
4639
+ function hslToRgb(h, s, l) {
4640
+ const q = l < 0.5 ? l * (1 + s) : l + s - l * s;
4641
+ const p = 2 * l - q;
4642
+ const r = hue2rgb(p, q, h + 1 / 3);
4643
+ const g2 = hue2rgb(p, q, h);
4644
+ const b = hue2rgb(p, q, h - 1 / 3);
4645
+ return Math.round(r * 255) << 24 | Math.round(g2 * 255) << 16 | Math.round(b * 255) << 8;
4646
+ }
4647
+ function parse255(str) {
4648
+ const int = parseInt(str, 10);
4649
+ if (int < 0)
4650
+ return 0;
4651
+ if (int > 255)
4652
+ return 255;
4653
+ return int;
4654
+ }
4655
+ function parse360(str) {
4656
+ const int = parseFloat(str);
4657
+ return (int % 360 + 360) % 360 / 360;
4658
+ }
4659
+ function parse1(str) {
4660
+ const num = parseFloat(str);
4661
+ if (num < 0)
4662
+ return 0;
4663
+ if (num > 1)
4664
+ return 255;
4665
+ return Math.round(num * 255);
4666
+ }
4667
+ function parsePercentage(str) {
4668
+ const int = parseFloat(str);
4669
+ if (int < 0)
4670
+ return 0;
4671
+ if (int > 100)
4672
+ return 1;
4673
+ return int / 100;
4674
+ }
4675
+ function colorToRgba(input) {
4676
+ let int32Color = normalizeColor(input);
4677
+ if (int32Color === null)
4678
+ return input;
4679
+ int32Color = int32Color || 0;
4680
+ const r = (int32Color & 4278190080) >>> 24;
4681
+ const g2 = (int32Color & 16711680) >>> 16;
4682
+ const b = (int32Color & 65280) >>> 8;
4683
+ const a = (int32Color & 255) / 255;
4684
+ return `rgba(${r}, ${g2}, ${b}, ${a})`;
4685
+ }
4686
+ var createInterpolator = (range, output, extrapolate) => {
4687
+ if (is.fun(range)) {
4688
+ return range;
4689
+ }
4690
+ if (is.arr(range)) {
4691
+ return createInterpolator({
4692
+ range,
4693
+ output,
4694
+ extrapolate
4695
+ });
4696
+ }
4697
+ if (is.str(range.output[0])) {
4698
+ return createStringInterpolator(range);
4699
+ }
4700
+ const config2 = range;
4701
+ const outputRange = config2.output;
4702
+ const inputRange = config2.range || [0, 1];
4703
+ const extrapolateLeft = config2.extrapolateLeft || config2.extrapolate || "extend";
4704
+ const extrapolateRight = config2.extrapolateRight || config2.extrapolate || "extend";
4705
+ const easing = config2.easing || ((t) => t);
4706
+ return (input) => {
4707
+ const range2 = findRange(input, inputRange);
4708
+ return interpolate(
4709
+ input,
4710
+ inputRange[range2],
4711
+ inputRange[range2 + 1],
4712
+ outputRange[range2],
4713
+ outputRange[range2 + 1],
4714
+ easing,
4715
+ extrapolateLeft,
4716
+ extrapolateRight,
4717
+ config2.map
4718
+ );
4719
+ };
4720
+ };
4721
+ function interpolate(input, inputMin, inputMax, outputMin, outputMax, easing, extrapolateLeft, extrapolateRight, map) {
4722
+ let result = map ? map(input) : input;
4723
+ if (result < inputMin) {
4724
+ if (extrapolateLeft === "identity")
4725
+ return result;
4726
+ else if (extrapolateLeft === "clamp")
4727
+ result = inputMin;
4728
+ }
4729
+ if (result > inputMax) {
4730
+ if (extrapolateRight === "identity")
4731
+ return result;
4732
+ else if (extrapolateRight === "clamp")
4733
+ result = inputMax;
4734
+ }
4735
+ if (outputMin === outputMax)
4736
+ return outputMin;
4737
+ if (inputMin === inputMax)
4738
+ return input <= inputMin ? outputMin : outputMax;
4739
+ if (inputMin === -Infinity)
4740
+ result = -result;
4741
+ else if (inputMax === Infinity)
4742
+ result = result - inputMin;
4743
+ else
4744
+ result = (result - inputMin) / (inputMax - inputMin);
4745
+ result = easing(result);
4746
+ if (outputMin === -Infinity)
4747
+ result = -result;
4748
+ else if (outputMax === Infinity)
4749
+ result = result + outputMin;
4750
+ else
4751
+ result = result * (outputMax - outputMin) + outputMin;
4752
+ return result;
4753
+ }
4754
+ function findRange(input, inputRange) {
4755
+ for (var i = 1; i < inputRange.length - 1; ++i)
4756
+ if (inputRange[i] >= input)
4757
+ break;
4758
+ return i - 1;
4759
+ }
4760
+ var easings$1 = {
4761
+ linear: (x) => x
4762
+ };
4763
+ var $get = Symbol.for("FluidValue.get");
4764
+ var $observers = Symbol.for("FluidValue.observers");
4765
+ var hasFluidValue = (arg) => Boolean(arg && arg[$get]);
4766
+ var getFluidValue = (arg) => arg && arg[$get] ? arg[$get]() : arg;
4767
+ var getFluidObservers = (target) => target[$observers] || null;
4768
+ function callFluidObserver(observer2, event) {
4769
+ if (observer2.eventObserved) {
4770
+ observer2.eventObserved(event);
4771
+ } else {
4772
+ observer2(event);
4773
+ }
4774
+ }
4775
+ function callFluidObservers(target, event) {
4776
+ const observers = target[$observers];
4777
+ if (observers) {
4778
+ observers.forEach((observer2) => {
4779
+ callFluidObserver(observer2, event);
4780
+ });
4781
+ }
4782
+ }
4783
+ var FluidValue = class {
4784
+ constructor(get) {
4785
+ if (!get && !(get = this.get)) {
4786
+ throw Error("Unknown getter");
4787
+ }
4788
+ setFluidGetter(this, get);
4789
+ }
4790
+ };
4791
+ var setFluidGetter = (target, get) => setHidden(target, $get, get);
4792
+ function addFluidObserver(target, observer2) {
4793
+ if (target[$get]) {
4794
+ let observers = target[$observers];
4795
+ if (!observers) {
4796
+ setHidden(target, $observers, observers = /* @__PURE__ */ new Set());
4797
+ }
4798
+ if (!observers.has(observer2)) {
4799
+ observers.add(observer2);
4800
+ if (target.observerAdded) {
4801
+ target.observerAdded(observers.size, observer2);
4802
+ }
4803
+ }
4804
+ }
4805
+ return observer2;
4806
+ }
4807
+ function removeFluidObserver(target, observer2) {
4808
+ const observers = target[$observers];
4809
+ if (observers && observers.has(observer2)) {
4810
+ const count = observers.size - 1;
4811
+ if (count) {
4812
+ observers.delete(observer2);
4813
+ } else {
4814
+ target[$observers] = null;
4815
+ }
4816
+ if (target.observerRemoved) {
4817
+ target.observerRemoved(count, observer2);
4818
+ }
4819
+ }
4820
+ }
4821
+ var setHidden = (target, key, value) => Object.defineProperty(target, key, {
4822
+ value,
4823
+ writable: true,
4824
+ configurable: true
4825
+ });
4826
+ var numberRegex = /[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
4827
+ var colorRegex = /(#(?:[0-9a-f]{2}){2,4}|(#[0-9a-f]{3})|(rgb|hsl)a?\((-?\d+%?[,\s]+){2,3}\s*[\d\.]+%?\))/gi;
4828
+ var unitRegex = new RegExp(`(${numberRegex.source})(%|[a-z]+)`, "i");
4829
+ var rgbaRegex = /rgba\(([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+), ([0-9\.-]+)\)/gi;
4830
+ var cssVariableRegex = /var\((--[a-zA-Z0-9-_]+),? ?([a-zA-Z0-9 ()%#.,-]+)?\)/;
4831
+ var variableToRgba = (input) => {
4832
+ const [token, fallback] = parseCSSVariable(input);
4833
+ if (!token || isSSR()) {
4834
+ return input;
4835
+ }
4836
+ const value = window.getComputedStyle(document.documentElement).getPropertyValue(token);
4837
+ if (value) {
4838
+ return value.trim();
4839
+ } else if (fallback && fallback.startsWith("--")) {
4840
+ const value2 = window.getComputedStyle(document.documentElement).getPropertyValue(fallback);
4841
+ if (value2) {
4842
+ return value2;
4843
+ } else {
4844
+ return input;
4845
+ }
4846
+ } else if (fallback && cssVariableRegex.test(fallback)) {
4847
+ return variableToRgba(fallback);
4848
+ } else if (fallback) {
4849
+ return fallback;
4850
+ }
4851
+ return input;
4852
+ };
4853
+ var parseCSSVariable = (current) => {
4854
+ const match = cssVariableRegex.exec(current);
4855
+ if (!match)
4856
+ return [,];
4857
+ const [, token, fallback] = match;
4858
+ return [token, fallback];
4859
+ };
4860
+ var namedColorRegex;
4861
+ var rgbaRound = (_, p1, p2, p3, p4) => `rgba(${Math.round(p1)}, ${Math.round(p2)}, ${Math.round(p3)}, ${p4})`;
4862
+ var createStringInterpolator2 = (config2) => {
4863
+ if (!namedColorRegex)
4864
+ namedColorRegex = colors ? (
4865
+ // match color names, ignore partial matches
4866
+ new RegExp(`(${Object.keys(colors).join("|")})(?!\\w)`, "g")
4867
+ ) : (
4868
+ // never match
4869
+ /^\b$/
4870
+ );
4871
+ const output = config2.output.map((value) => {
4872
+ return getFluidValue(value).replace(cssVariableRegex, variableToRgba).replace(colorRegex, colorToRgba).replace(namedColorRegex, colorToRgba);
4873
+ });
4874
+ const keyframes2 = output.map((value) => value.match(numberRegex).map(Number));
4875
+ const outputRanges = keyframes2[0].map(
4876
+ (_, i) => keyframes2.map((values) => {
4877
+ if (!(i in values)) {
4878
+ throw Error('The arity of each "output" value must be equal');
4879
+ }
4880
+ return values[i];
4881
+ })
4882
+ );
4883
+ const interpolators = outputRanges.map(
4884
+ (output2) => createInterpolator({ ...config2, output: output2 })
4885
+ );
4886
+ return (input) => {
4887
+ var _a;
4888
+ const missingUnit = !unitRegex.test(output[0]) && ((_a = output.find((value) => unitRegex.test(value))) == null ? void 0 : _a.replace(numberRegex, ""));
4889
+ let i = 0;
4890
+ return output[0].replace(
4891
+ numberRegex,
4892
+ () => `${interpolators[i++](input)}${missingUnit || ""}`
4893
+ ).replace(rgbaRegex, rgbaRound);
4894
+ };
4895
+ };
4896
+ var prefix = "react-spring: ";
4897
+ var once = (fn) => {
4898
+ const func = fn;
4899
+ let called = false;
4900
+ if (typeof func != "function") {
4901
+ throw new TypeError(`${prefix}once requires a function parameter`);
4902
+ }
4903
+ return (...args) => {
4904
+ if (!called) {
4905
+ func(...args);
4906
+ called = true;
4907
+ }
4908
+ };
4909
+ };
4910
+ var warnInterpolate = once(console.warn);
4911
+ function deprecateInterpolate() {
4912
+ warnInterpolate(
4913
+ `${prefix}The "interpolate" function is deprecated in v9 (use "to" instead)`
4914
+ );
4915
+ }
4916
+ var warnDirectCall = once(console.warn);
4917
+ function deprecateDirectCall() {
4918
+ warnDirectCall(
4919
+ `${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`
4920
+ );
4921
+ }
4922
+ function isAnimatedString(value) {
4923
+ return is.str(value) && (value[0] == "#" || /\d/.test(value) || // Do not identify a CSS variable as an AnimatedString if its SSR
4924
+ !isSSR() && cssVariableRegex.test(value) || value in (colors || {}));
4925
+ }
4926
+ var useIsomorphicLayoutEffect = isSSR() ? React.useEffect : React.useLayoutEffect;
4927
+ var useIsMounted = () => {
4928
+ const isMounted = React.useRef(false);
4929
+ useIsomorphicLayoutEffect(() => {
4930
+ isMounted.current = true;
4931
+ return () => {
4932
+ isMounted.current = false;
4933
+ };
4934
+ }, []);
4935
+ return isMounted;
4936
+ };
4937
+ function useForceUpdate() {
4938
+ const update2 = React.useState()[1];
4939
+ const isMounted = useIsMounted();
4940
+ return () => {
4941
+ if (isMounted.current) {
4942
+ update2(Math.random());
4943
+ }
4944
+ };
4945
+ }
4946
+ function useMemoOne(getResult, inputs) {
4947
+ const [initial] = React.useState(
4948
+ () => ({
4949
+ inputs,
4950
+ result: getResult()
4951
+ })
4952
+ );
4953
+ const committed = React.useRef();
4954
+ const prevCache = committed.current;
4955
+ let cache = prevCache;
4956
+ if (cache) {
4957
+ const useCache = Boolean(
4958
+ inputs && cache.inputs && areInputsEqual(inputs, cache.inputs)
4959
+ );
4960
+ if (!useCache) {
4961
+ cache = {
4962
+ inputs,
4963
+ result: getResult()
4964
+ };
4965
+ }
4966
+ } else {
4967
+ cache = initial;
4968
+ }
4969
+ React.useEffect(() => {
4970
+ committed.current = cache;
4971
+ if (prevCache == initial) {
4972
+ initial.inputs = initial.result = void 0;
4973
+ }
4974
+ }, [cache]);
4975
+ return cache.result;
4976
+ }
4977
+ function areInputsEqual(next, prev) {
4978
+ if (next.length !== prev.length) {
4979
+ return false;
4980
+ }
4981
+ for (let i = 0; i < next.length; i++) {
4982
+ if (next[i] !== prev[i]) {
4983
+ return false;
4984
+ }
4985
+ }
4986
+ return true;
4987
+ }
4988
+ var useOnce = (effect) => React.useEffect(effect, emptyDeps);
4989
+ var emptyDeps = [];
4990
+ function usePrev(value) {
4991
+ const prevRef = React.useRef();
4992
+ React.useEffect(() => {
4993
+ prevRef.current = value;
4994
+ });
4995
+ return prevRef.current;
4996
+ }
4997
+ var $node = Symbol.for("Animated:node");
4998
+ var isAnimated = (value) => !!value && value[$node] === value;
4999
+ var getAnimated = (owner) => owner && owner[$node];
5000
+ var setAnimated = (owner, node) => defineHidden(owner, $node, node);
5001
+ var getPayload = (owner) => owner && owner[$node] && owner[$node].getPayload();
5002
+ var Animated = class {
5003
+ constructor() {
5004
+ setAnimated(this, this);
5005
+ }
5006
+ /** Get every `AnimatedValue` used by this node. */
5007
+ getPayload() {
5008
+ return this.payload || [];
5009
+ }
5010
+ };
5011
+ var AnimatedValue = class extends Animated {
5012
+ constructor(_value) {
5013
+ super();
5014
+ this._value = _value;
5015
+ this.done = true;
5016
+ this.durationProgress = 0;
5017
+ if (is.num(this._value)) {
5018
+ this.lastPosition = this._value;
5019
+ }
5020
+ }
5021
+ /** @internal */
5022
+ static create(value) {
5023
+ return new AnimatedValue(value);
5024
+ }
5025
+ getPayload() {
5026
+ return [this];
5027
+ }
5028
+ getValue() {
5029
+ return this._value;
5030
+ }
5031
+ setValue(value, step) {
5032
+ if (is.num(value)) {
5033
+ this.lastPosition = value;
5034
+ if (step) {
5035
+ value = Math.round(value / step) * step;
5036
+ if (this.done) {
5037
+ this.lastPosition = value;
5038
+ }
5039
+ }
5040
+ }
5041
+ if (this._value === value) {
5042
+ return false;
5043
+ }
5044
+ this._value = value;
5045
+ return true;
5046
+ }
5047
+ reset() {
5048
+ const { done } = this;
5049
+ this.done = false;
5050
+ if (is.num(this._value)) {
5051
+ this.elapsedTime = 0;
5052
+ this.durationProgress = 0;
5053
+ this.lastPosition = this._value;
5054
+ if (done)
5055
+ this.lastVelocity = null;
5056
+ this.v0 = null;
5057
+ }
5058
+ }
5059
+ };
5060
+ var AnimatedString = class extends AnimatedValue {
5061
+ constructor(value) {
5062
+ super(0);
5063
+ this._string = null;
5064
+ this._toString = createInterpolator({
5065
+ output: [value, value]
5066
+ });
5067
+ }
5068
+ /** @internal */
5069
+ static create(value) {
5070
+ return new AnimatedString(value);
5071
+ }
5072
+ getValue() {
5073
+ const value = this._string;
5074
+ return value == null ? this._string = this._toString(this._value) : value;
5075
+ }
5076
+ setValue(value) {
5077
+ if (is.str(value)) {
5078
+ if (value == this._string) {
5079
+ return false;
5080
+ }
5081
+ this._string = value;
5082
+ this._value = 1;
5083
+ } else if (super.setValue(value)) {
5084
+ this._string = null;
5085
+ } else {
5086
+ return false;
5087
+ }
5088
+ return true;
5089
+ }
5090
+ reset(goal) {
5091
+ if (goal) {
5092
+ this._toString = createInterpolator({
5093
+ output: [this.getValue(), goal]
5094
+ });
5095
+ }
5096
+ this._value = 0;
5097
+ super.reset();
5098
+ }
5099
+ };
5100
+ var TreeContext = { dependencies: null };
5101
+ var AnimatedObject = class extends Animated {
5102
+ constructor(source) {
5103
+ super();
5104
+ this.source = source;
5105
+ this.setValue(source);
5106
+ }
5107
+ getValue(animated2) {
5108
+ const values = {};
5109
+ eachProp(this.source, (source, key) => {
5110
+ if (isAnimated(source)) {
5111
+ values[key] = source.getValue(animated2);
5112
+ } else if (hasFluidValue(source)) {
5113
+ values[key] = getFluidValue(source);
5114
+ } else if (!animated2) {
5115
+ values[key] = source;
5116
+ }
5117
+ });
5118
+ return values;
5119
+ }
5120
+ /** Replace the raw object data */
5121
+ setValue(source) {
5122
+ this.source = source;
5123
+ this.payload = this._makePayload(source);
5124
+ }
5125
+ reset() {
5126
+ if (this.payload) {
5127
+ each(this.payload, (node) => node.reset());
5128
+ }
5129
+ }
5130
+ /** Create a payload set. */
5131
+ _makePayload(source) {
5132
+ if (source) {
5133
+ const payload = /* @__PURE__ */ new Set();
5134
+ eachProp(source, this._addToPayload, payload);
5135
+ return Array.from(payload);
5136
+ }
5137
+ }
5138
+ /** Add to a payload set. */
5139
+ _addToPayload(source) {
5140
+ if (TreeContext.dependencies && hasFluidValue(source)) {
5141
+ TreeContext.dependencies.add(source);
5142
+ }
5143
+ const payload = getPayload(source);
5144
+ if (payload) {
5145
+ each(payload, (node) => this.add(node));
5146
+ }
5147
+ }
5148
+ };
5149
+ var AnimatedArray = class extends AnimatedObject {
5150
+ constructor(source) {
5151
+ super(source);
5152
+ }
5153
+ /** @internal */
5154
+ static create(source) {
5155
+ return new AnimatedArray(source);
5156
+ }
5157
+ getValue() {
5158
+ return this.source.map((node) => node.getValue());
5159
+ }
5160
+ setValue(source) {
5161
+ const payload = this.getPayload();
5162
+ if (source.length == payload.length) {
5163
+ return payload.map((node, i) => node.setValue(source[i])).some(Boolean);
5164
+ }
5165
+ super.setValue(source.map(makeAnimated));
5166
+ return true;
5167
+ }
5168
+ };
5169
+ function makeAnimated(value) {
5170
+ const nodeType = isAnimatedString(value) ? AnimatedString : AnimatedValue;
5171
+ return nodeType.create(value);
5172
+ }
5173
+ function getAnimatedType(value) {
5174
+ const parentNode = getAnimated(value);
5175
+ return parentNode ? parentNode.constructor : is.arr(value) ? AnimatedArray : isAnimatedString(value) ? AnimatedString : AnimatedValue;
5176
+ }
5177
+ var withAnimated = (Component, host2) => {
5178
+ const hasInstance = (
5179
+ // Function components must use "forwardRef" to avoid being
5180
+ // re-rendered on every animation frame.
5181
+ !is.fun(Component) || Component.prototype && Component.prototype.isReactComponent
5182
+ );
5183
+ return React.forwardRef((givenProps, givenRef) => {
5184
+ const instanceRef = React.useRef(null);
5185
+ const ref = hasInstance && // eslint-disable-next-line react-hooks/rules-of-hooks
5186
+ React.useCallback(
5187
+ (value) => {
5188
+ instanceRef.current = updateRef(givenRef, value);
5189
+ },
5190
+ [givenRef]
5191
+ );
5192
+ const [props, deps] = getAnimatedState(givenProps, host2);
5193
+ const forceUpdate = useForceUpdate();
5194
+ const callback = () => {
5195
+ const instance = instanceRef.current;
5196
+ if (hasInstance && !instance) {
5197
+ return;
5198
+ }
5199
+ const didUpdate = instance ? host2.applyAnimatedValues(instance, props.getValue(true)) : false;
5200
+ if (didUpdate === false) {
5201
+ forceUpdate();
5202
+ }
5203
+ };
5204
+ const observer = new PropsObserver(callback, deps);
5205
+ const observerRef = React.useRef();
5206
+ useIsomorphicLayoutEffect(() => {
5207
+ observerRef.current = observer;
5208
+ each(deps, (dep) => addFluidObserver(dep, observer));
5209
+ return () => {
5210
+ if (observerRef.current) {
5211
+ each(
5212
+ observerRef.current.deps,
5213
+ (dep) => removeFluidObserver(dep, observerRef.current)
5214
+ );
5215
+ raf.cancel(observerRef.current.update);
5216
+ }
5217
+ };
5218
+ });
5219
+ React.useEffect(callback, []);
5220
+ useOnce(() => () => {
5221
+ const observer2 = observerRef.current;
5222
+ each(observer2.deps, (dep) => removeFluidObserver(dep, observer2));
5223
+ });
5224
+ const usedProps = host2.getComponentProps(props.getValue());
5225
+ return /* @__PURE__ */ React__namespace.createElement(Component, { ...usedProps, ref });
5226
+ });
5227
+ };
5228
+ var PropsObserver = class {
5229
+ constructor(update2, deps) {
5230
+ this.update = update2;
5231
+ this.deps = deps;
5232
+ }
5233
+ eventObserved(event) {
5234
+ if (event.type == "change") {
5235
+ raf.write(this.update);
5236
+ }
5237
+ }
5238
+ };
5239
+ function getAnimatedState(props, host2) {
5240
+ const dependencies = /* @__PURE__ */ new Set();
5241
+ TreeContext.dependencies = dependencies;
5242
+ if (props.style)
5243
+ props = {
5244
+ ...props,
5245
+ style: host2.createAnimatedStyle(props.style)
5246
+ };
5247
+ props = new AnimatedObject(props);
5248
+ TreeContext.dependencies = null;
5249
+ return [props, dependencies];
5250
+ }
5251
+ function updateRef(ref, value) {
5252
+ if (ref) {
5253
+ if (is.fun(ref))
5254
+ ref(value);
5255
+ else
5256
+ ref.current = value;
5257
+ }
5258
+ return value;
5259
+ }
5260
+ var cacheKey = Symbol.for("AnimatedComponent");
5261
+ var createHost = (components, {
5262
+ applyAnimatedValues: applyAnimatedValues2 = () => false,
5263
+ createAnimatedStyle = (style) => new AnimatedObject(style),
5264
+ getComponentProps = (props) => props
5265
+ } = {}) => {
5266
+ const hostConfig = {
5267
+ applyAnimatedValues: applyAnimatedValues2,
5268
+ createAnimatedStyle,
5269
+ getComponentProps
5270
+ };
5271
+ const animated2 = (Component) => {
5272
+ const displayName = getDisplayName(Component) || "Anonymous";
5273
+ if (is.str(Component)) {
5274
+ Component = animated2[Component] || (animated2[Component] = withAnimated(Component, hostConfig));
5275
+ } else {
5276
+ Component = Component[cacheKey] || (Component[cacheKey] = withAnimated(Component, hostConfig));
5277
+ }
5278
+ Component.displayName = `Animated(${displayName})`;
5279
+ return Component;
5280
+ };
5281
+ eachProp(components, (Component, key) => {
5282
+ if (is.arr(components)) {
5283
+ key = getDisplayName(Component);
5284
+ }
5285
+ animated2[key] = animated2(Component);
5286
+ });
5287
+ return {
5288
+ animated: animated2
5289
+ };
5290
+ };
5291
+ var getDisplayName = (arg) => is.str(arg) ? arg : arg && is.str(arg.displayName) ? arg.displayName : is.fun(arg) && arg.name || null;
5292
+ function callProp(value, ...args) {
5293
+ return is.fun(value) ? value(...args) : value;
5294
+ }
5295
+ var matchProp = (value, key) => value === true || !!(key && value && (is.fun(value) ? value(key) : toArray(value).includes(key)));
5296
+ var resolveProp = (prop, key) => is.obj(prop) ? key && prop[key] : prop;
5297
+ var getDefaultProp = (props, key) => props.default === true ? props[key] : props.default ? props.default[key] : void 0;
5298
+ var noopTransform = (value) => value;
5299
+ var getDefaultProps = (props, transform = noopTransform) => {
5300
+ let keys = DEFAULT_PROPS;
5301
+ if (props.default && props.default !== true) {
5302
+ props = props.default;
5303
+ keys = Object.keys(props);
5304
+ }
5305
+ const defaults2 = {};
5306
+ for (const key of keys) {
5307
+ const value = transform(props[key], key);
5308
+ if (!is.und(value)) {
5309
+ defaults2[key] = value;
5310
+ }
5311
+ }
5312
+ return defaults2;
5313
+ };
5314
+ var DEFAULT_PROPS = [
5315
+ "config",
5316
+ "onProps",
5317
+ "onStart",
5318
+ "onChange",
5319
+ "onPause",
5320
+ "onResume",
5321
+ "onRest"
5322
+ ];
5323
+ var RESERVED_PROPS = {
5324
+ config: 1,
5325
+ from: 1,
5326
+ to: 1,
5327
+ ref: 1,
5328
+ loop: 1,
5329
+ reset: 1,
5330
+ pause: 1,
5331
+ cancel: 1,
5332
+ reverse: 1,
5333
+ immediate: 1,
5334
+ default: 1,
5335
+ delay: 1,
5336
+ onProps: 1,
5337
+ onStart: 1,
5338
+ onChange: 1,
5339
+ onPause: 1,
5340
+ onResume: 1,
5341
+ onRest: 1,
5342
+ onResolve: 1,
5343
+ // Transition props
5344
+ items: 1,
5345
+ trail: 1,
5346
+ sort: 1,
5347
+ expires: 1,
5348
+ initial: 1,
5349
+ enter: 1,
5350
+ update: 1,
5351
+ leave: 1,
5352
+ children: 1,
5353
+ onDestroyed: 1,
5354
+ // Internal props
5355
+ keys: 1,
5356
+ callId: 1,
5357
+ parentId: 1
5358
+ };
5359
+ function getForwardProps(props) {
5360
+ const forward = {};
5361
+ let count = 0;
5362
+ eachProp(props, (value, prop) => {
5363
+ if (!RESERVED_PROPS[prop]) {
5364
+ forward[prop] = value;
5365
+ count++;
5366
+ }
5367
+ });
5368
+ if (count) {
5369
+ return forward;
5370
+ }
5371
+ }
5372
+ function inferTo(props) {
5373
+ const to2 = getForwardProps(props);
5374
+ if (to2) {
5375
+ const out = { to: to2 };
5376
+ eachProp(props, (val, key) => key in to2 || (out[key] = val));
5377
+ return out;
5378
+ }
5379
+ return { ...props };
5380
+ }
5381
+ function computeGoal(value) {
5382
+ value = getFluidValue(value);
5383
+ return is.arr(value) ? value.map(computeGoal) : isAnimatedString(value) ? globals_exports.createStringInterpolator({
5384
+ range: [0, 1],
5385
+ output: [value, value]
5386
+ })(1) : value;
5387
+ }
5388
+ function hasProps(props) {
5389
+ for (const _ in props)
5390
+ return true;
5391
+ return false;
5392
+ }
5393
+ function isAsyncTo(to2) {
5394
+ return is.fun(to2) || is.arr(to2) && is.obj(to2[0]);
5395
+ }
5396
+ function detachRefs(ctrl, ref) {
5397
+ var _a;
5398
+ (_a = ctrl.ref) == null ? void 0 : _a.delete(ctrl);
5399
+ ref == null ? void 0 : ref.delete(ctrl);
5400
+ }
5401
+ function replaceRef(ctrl, ref) {
5402
+ var _a;
5403
+ if (ref && ctrl.ref !== ref) {
5404
+ (_a = ctrl.ref) == null ? void 0 : _a.delete(ctrl);
5405
+ ref.add(ctrl);
5406
+ ctrl.ref = ref;
5407
+ }
5408
+ }
5409
+ var config = {
5410
+ default: { tension: 170, friction: 26 }
5411
+ };
5412
+ var defaults = {
5413
+ ...config.default,
5414
+ mass: 1,
5415
+ damping: 1,
5416
+ easing: easings$1.linear,
5417
+ clamp: false
5418
+ };
5419
+ var AnimationConfig = class {
5420
+ constructor() {
5421
+ this.velocity = 0;
5422
+ Object.assign(this, defaults);
5423
+ }
5424
+ };
5425
+ function mergeConfig(config2, newConfig, defaultConfig) {
5426
+ if (defaultConfig) {
5427
+ defaultConfig = { ...defaultConfig };
5428
+ sanitizeConfig(defaultConfig, newConfig);
5429
+ newConfig = { ...defaultConfig, ...newConfig };
5430
+ }
5431
+ sanitizeConfig(config2, newConfig);
5432
+ Object.assign(config2, newConfig);
5433
+ for (const key in defaults) {
5434
+ if (config2[key] == null) {
5435
+ config2[key] = defaults[key];
5436
+ }
5437
+ }
5438
+ let { frequency, damping } = config2;
5439
+ const { mass } = config2;
5440
+ if (!is.und(frequency)) {
5441
+ if (frequency < 0.01)
5442
+ frequency = 0.01;
5443
+ if (damping < 0)
5444
+ damping = 0;
5445
+ config2.tension = Math.pow(2 * Math.PI / frequency, 2) * mass;
5446
+ config2.friction = 4 * Math.PI * damping * mass / frequency;
5447
+ }
5448
+ return config2;
5449
+ }
5450
+ function sanitizeConfig(config2, props) {
5451
+ if (!is.und(props.decay)) {
5452
+ config2.duration = void 0;
5453
+ } else {
5454
+ const isTensionConfig = !is.und(props.tension) || !is.und(props.friction);
5455
+ if (isTensionConfig || !is.und(props.frequency) || !is.und(props.damping) || !is.und(props.mass)) {
5456
+ config2.duration = void 0;
5457
+ config2.decay = void 0;
5458
+ }
5459
+ if (isTensionConfig) {
5460
+ config2.frequency = void 0;
5461
+ }
5462
+ }
5463
+ }
5464
+ var emptyArray = [];
5465
+ var Animation = class {
5466
+ constructor() {
5467
+ this.changed = false;
5468
+ this.values = emptyArray;
5469
+ this.toValues = null;
5470
+ this.fromValues = emptyArray;
5471
+ this.config = new AnimationConfig();
5472
+ this.immediate = false;
5473
+ }
5474
+ };
5475
+ function scheduleProps(callId, { key, props, defaultProps, state, actions }) {
5476
+ return new Promise((resolve, reject) => {
5477
+ let delay2;
5478
+ let timeout;
5479
+ let cancel = matchProp(props.cancel ?? (defaultProps == null ? void 0 : defaultProps.cancel), key);
5480
+ if (cancel) {
5481
+ onStart();
5482
+ } else {
5483
+ if (!is.und(props.pause)) {
5484
+ state.paused = matchProp(props.pause, key);
5485
+ }
5486
+ let pause = defaultProps == null ? void 0 : defaultProps.pause;
5487
+ if (pause !== true) {
5488
+ pause = state.paused || matchProp(pause, key);
5489
+ }
5490
+ delay2 = callProp(props.delay || 0, key);
5491
+ if (pause) {
5492
+ state.resumeQueue.add(onResume);
5493
+ actions.pause();
5494
+ } else {
5495
+ actions.resume();
5496
+ onResume();
5497
+ }
5498
+ }
5499
+ function onPause() {
5500
+ state.resumeQueue.add(onResume);
5501
+ state.timeouts.delete(timeout);
5502
+ timeout.cancel();
5503
+ delay2 = timeout.time - raf.now();
5504
+ }
5505
+ function onResume() {
5506
+ if (delay2 > 0 && !globals_exports.skipAnimation) {
5507
+ state.delayed = true;
5508
+ timeout = raf.setTimeout(onStart, delay2);
5509
+ state.pauseQueue.add(onPause);
5510
+ state.timeouts.add(timeout);
5511
+ } else {
5512
+ onStart();
5513
+ }
5514
+ }
5515
+ function onStart() {
5516
+ if (state.delayed) {
5517
+ state.delayed = false;
5518
+ }
5519
+ state.pauseQueue.delete(onPause);
5520
+ state.timeouts.delete(timeout);
5521
+ if (callId <= (state.cancelId || 0)) {
5522
+ cancel = true;
5523
+ }
5524
+ try {
5525
+ actions.start({ ...props, callId, cancel }, resolve);
5526
+ } catch (err) {
5527
+ reject(err);
5528
+ }
5529
+ }
5530
+ });
5531
+ }
5532
+ var 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(
5533
+ target.get(),
5534
+ results.every((result) => result.finished)
5535
+ );
5536
+ var getNoopResult = (value) => ({
5537
+ value,
5538
+ noop: true,
5539
+ finished: true,
5540
+ cancelled: false
5541
+ });
5542
+ var getFinishedResult = (value, finished, cancelled = false) => ({
5543
+ value,
5544
+ finished,
5545
+ cancelled
5546
+ });
5547
+ var getCancelledResult = (value) => ({
5548
+ value,
5549
+ cancelled: true,
5550
+ finished: false
5551
+ });
5552
+ function runAsync(to2, props, state, target) {
5553
+ const { callId, parentId, onRest } = props;
5554
+ const { asyncTo: prevTo, promise: prevPromise } = state;
5555
+ if (!parentId && to2 === prevTo && !props.reset) {
5556
+ return prevPromise;
5557
+ }
5558
+ return state.promise = (async () => {
5559
+ state.asyncId = callId;
5560
+ state.asyncTo = to2;
5561
+ const defaultProps = getDefaultProps(
5562
+ props,
5563
+ (value, key) => (
5564
+ // The `onRest` prop is only called when the `runAsync` promise is resolved.
5565
+ key === "onRest" ? void 0 : value
5566
+ )
5567
+ );
5568
+ let preventBail;
5569
+ let bail;
5570
+ const bailPromise = new Promise(
5571
+ (resolve, reject) => (preventBail = resolve, bail = reject)
5572
+ );
5573
+ const bailIfEnded = (bailSignal) => {
5574
+ const bailResult = (
5575
+ // The `cancel` prop or `stop` method was used.
5576
+ callId <= (state.cancelId || 0) && getCancelledResult(target) || // The async `to` prop was replaced.
5577
+ callId !== state.asyncId && getFinishedResult(target, false)
5578
+ );
5579
+ if (bailResult) {
5580
+ bailSignal.result = bailResult;
5581
+ bail(bailSignal);
5582
+ throw bailSignal;
5583
+ }
5584
+ };
5585
+ const animate = (arg1, arg2) => {
5586
+ const bailSignal = new BailSignal();
5587
+ const skipAnimationSignal = new SkipAnimationSignal();
5588
+ return (async () => {
5589
+ if (globals_exports.skipAnimation) {
5590
+ stopAsync(state);
5591
+ skipAnimationSignal.result = getFinishedResult(target, false);
5592
+ bail(skipAnimationSignal);
5593
+ throw skipAnimationSignal;
5594
+ }
5595
+ bailIfEnded(bailSignal);
5596
+ const props2 = is.obj(arg1) ? { ...arg1 } : { ...arg2, to: arg1 };
5597
+ props2.parentId = callId;
5598
+ eachProp(defaultProps, (value, key) => {
5599
+ if (is.und(props2[key])) {
5600
+ props2[key] = value;
5601
+ }
5602
+ });
5603
+ const result2 = await target.start(props2);
5604
+ bailIfEnded(bailSignal);
5605
+ if (state.paused) {
5606
+ await new Promise((resume) => {
5607
+ state.resumeQueue.add(resume);
5608
+ });
5609
+ }
5610
+ return result2;
5611
+ })();
5612
+ };
5613
+ let result;
5614
+ if (globals_exports.skipAnimation) {
5615
+ stopAsync(state);
5616
+ return getFinishedResult(target, false);
5617
+ }
5618
+ try {
5619
+ let animating;
5620
+ if (is.arr(to2)) {
5621
+ animating = (async (queue) => {
5622
+ for (const props2 of queue) {
5623
+ await animate(props2);
5624
+ }
5625
+ })(to2);
5626
+ } else {
5627
+ animating = Promise.resolve(to2(animate, target.stop.bind(target)));
5628
+ }
5629
+ await Promise.all([animating.then(preventBail), bailPromise]);
5630
+ result = getFinishedResult(target.get(), true, false);
5631
+ } catch (err) {
5632
+ if (err instanceof BailSignal) {
5633
+ result = err.result;
5634
+ } else if (err instanceof SkipAnimationSignal) {
5635
+ result = err.result;
5636
+ } else {
5637
+ throw err;
5638
+ }
5639
+ } finally {
5640
+ if (callId == state.asyncId) {
5641
+ state.asyncId = parentId;
5642
+ state.asyncTo = parentId ? prevTo : void 0;
5643
+ state.promise = parentId ? prevPromise : void 0;
5644
+ }
5645
+ }
5646
+ if (is.fun(onRest)) {
5647
+ raf.batchedUpdates(() => {
5648
+ onRest(result, target, target.item);
5649
+ });
5650
+ }
5651
+ return result;
5652
+ })();
5653
+ }
5654
+ function stopAsync(state, cancelId) {
5655
+ flush(state.timeouts, (t) => t.cancel());
5656
+ state.pauseQueue.clear();
5657
+ state.resumeQueue.clear();
5658
+ state.asyncId = state.asyncTo = state.promise = void 0;
5659
+ if (cancelId)
5660
+ state.cancelId = cancelId;
5661
+ }
5662
+ var BailSignal = class extends Error {
5663
+ constructor() {
5664
+ super(
5665
+ "An async animation has been interrupted. You see this error because you forgot to use `await` or `.catch(...)` on its returned promise."
5666
+ );
5667
+ }
5668
+ };
5669
+ var SkipAnimationSignal = class extends Error {
5670
+ constructor() {
5671
+ super("SkipAnimationSignal");
5672
+ }
5673
+ };
5674
+ var isFrameValue = (value) => value instanceof FrameValue;
5675
+ var nextId = 1;
5676
+ var FrameValue = class extends FluidValue {
5677
+ constructor() {
5678
+ super(...arguments);
5679
+ this.id = nextId++;
5680
+ this._priority = 0;
5681
+ }
5682
+ get priority() {
5683
+ return this._priority;
5684
+ }
5685
+ set priority(priority2) {
5686
+ if (this._priority != priority2) {
5687
+ this._priority = priority2;
5688
+ this._onPriorityChange(priority2);
5689
+ }
5690
+ }
5691
+ /** Get the current value */
5692
+ get() {
5693
+ const node = getAnimated(this);
5694
+ return node && node.getValue();
5695
+ }
5696
+ /** Create a spring that maps our value to another value */
5697
+ to(...args) {
5698
+ return globals_exports.to(this, args);
5699
+ }
5700
+ /** @deprecated Use the `to` method instead. */
5701
+ interpolate(...args) {
5702
+ deprecateInterpolate();
5703
+ return globals_exports.to(this, args);
5704
+ }
5705
+ toJSON() {
5706
+ return this.get();
5707
+ }
5708
+ observerAdded(count) {
5709
+ if (count == 1)
5710
+ this._attach();
5711
+ }
5712
+ observerRemoved(count) {
5713
+ if (count == 0)
5714
+ this._detach();
5715
+ }
5716
+ /** Called when the first child is added. */
5717
+ _attach() {
5718
+ }
5719
+ /** Called when the last child is removed. */
5720
+ _detach() {
5721
+ }
5722
+ /** Tell our children about our new value */
5723
+ _onChange(value, idle = false) {
5724
+ callFluidObservers(this, {
5725
+ type: "change",
5726
+ parent: this,
5727
+ value,
5728
+ idle
5729
+ });
5730
+ }
5731
+ /** Tell our children about our new priority */
5732
+ _onPriorityChange(priority2) {
5733
+ if (!this.idle) {
5734
+ frameLoop.sort(this);
5735
+ }
5736
+ callFluidObservers(this, {
5737
+ type: "priority",
5738
+ parent: this,
5739
+ priority: priority2
5740
+ });
5741
+ }
5742
+ };
5743
+ var $P = Symbol.for("SpringPhase");
5744
+ var HAS_ANIMATED = 1;
5745
+ var IS_ANIMATING = 2;
5746
+ var IS_PAUSED = 4;
5747
+ var hasAnimated = (target) => (target[$P] & HAS_ANIMATED) > 0;
5748
+ var isAnimating = (target) => (target[$P] & IS_ANIMATING) > 0;
5749
+ var isPaused = (target) => (target[$P] & IS_PAUSED) > 0;
5750
+ var setActiveBit = (target, active) => active ? target[$P] |= IS_ANIMATING | HAS_ANIMATED : target[$P] &= -3;
5751
+ var setPausedBit = (target, paused) => paused ? target[$P] |= IS_PAUSED : target[$P] &= -5;
5752
+ var SpringValue = class extends FrameValue {
5753
+ constructor(arg1, arg2) {
5754
+ super();
5755
+ this.animation = new Animation();
5756
+ this.defaultProps = {};
5757
+ this._state = {
5758
+ paused: false,
5759
+ delayed: false,
5760
+ pauseQueue: /* @__PURE__ */ new Set(),
5761
+ resumeQueue: /* @__PURE__ */ new Set(),
5762
+ timeouts: /* @__PURE__ */ new Set()
5763
+ };
5764
+ this._pendingCalls = /* @__PURE__ */ new Set();
5765
+ this._lastCallId = 0;
5766
+ this._lastToId = 0;
5767
+ this._memoizedDuration = 0;
5768
+ if (!is.und(arg1) || !is.und(arg2)) {
5769
+ const props = is.obj(arg1) ? { ...arg1 } : { ...arg2, from: arg1 };
5770
+ if (is.und(props.default)) {
5771
+ props.default = true;
5772
+ }
5773
+ this.start(props);
5774
+ }
5775
+ }
5776
+ /** Equals true when not advancing on each frame. */
5777
+ get idle() {
5778
+ return !(isAnimating(this) || this._state.asyncTo) || isPaused(this);
5779
+ }
5780
+ get goal() {
5781
+ return getFluidValue(this.animation.to);
5782
+ }
5783
+ get velocity() {
5784
+ const node = getAnimated(this);
5785
+ return node instanceof AnimatedValue ? node.lastVelocity || 0 : node.getPayload().map((node2) => node2.lastVelocity || 0);
5786
+ }
5787
+ /**
5788
+ * When true, this value has been animated at least once.
5789
+ */
5790
+ get hasAnimated() {
5791
+ return hasAnimated(this);
5792
+ }
5793
+ /**
5794
+ * When true, this value has an unfinished animation,
5795
+ * which is either active or paused.
5796
+ */
5797
+ get isAnimating() {
5798
+ return isAnimating(this);
5799
+ }
5800
+ /**
5801
+ * When true, all current and future animations are paused.
5802
+ */
5803
+ get isPaused() {
5804
+ return isPaused(this);
5805
+ }
5806
+ /**
5807
+ *
5808
+ *
5809
+ */
5810
+ get isDelayed() {
5811
+ return this._state.delayed;
5812
+ }
5813
+ /** Advance the current animation by a number of milliseconds */
5814
+ advance(dt) {
5815
+ let idle = true;
5816
+ let changed = false;
5817
+ const anim = this.animation;
5818
+ let { toValues } = anim;
5819
+ const { config: config2 } = anim;
5820
+ const payload = getPayload(anim.to);
5821
+ if (!payload && hasFluidValue(anim.to)) {
5822
+ toValues = toArray(getFluidValue(anim.to));
5823
+ }
5824
+ anim.values.forEach((node2, i) => {
5825
+ if (node2.done)
5826
+ return;
5827
+ const to2 = (
5828
+ // Animated strings always go from 0 to 1.
5829
+ node2.constructor == AnimatedString ? 1 : payload ? payload[i].lastPosition : toValues[i]
5830
+ );
5831
+ let finished = anim.immediate;
5832
+ let position = to2;
5833
+ if (!finished) {
5834
+ position = node2.lastPosition;
5835
+ if (config2.tension <= 0) {
5836
+ node2.done = true;
5837
+ return;
5838
+ }
5839
+ let elapsed = node2.elapsedTime += dt;
5840
+ const from = anim.fromValues[i];
5841
+ const v0 = node2.v0 != null ? node2.v0 : node2.v0 = is.arr(config2.velocity) ? config2.velocity[i] : config2.velocity;
5842
+ let velocity;
5843
+ const precision = config2.precision || (from == to2 ? 5e-3 : Math.min(1, Math.abs(to2 - from) * 1e-3));
5844
+ if (!is.und(config2.duration)) {
5845
+ let p = 1;
5846
+ if (config2.duration > 0) {
5847
+ if (this._memoizedDuration !== config2.duration) {
5848
+ this._memoizedDuration = config2.duration;
5849
+ if (node2.durationProgress > 0) {
5850
+ node2.elapsedTime = config2.duration * node2.durationProgress;
5851
+ elapsed = node2.elapsedTime += dt;
5852
+ }
5853
+ }
5854
+ p = (config2.progress || 0) + elapsed / this._memoizedDuration;
5855
+ p = p > 1 ? 1 : p < 0 ? 0 : p;
5856
+ node2.durationProgress = p;
5857
+ }
5858
+ position = from + config2.easing(p) * (to2 - from);
5859
+ velocity = (position - node2.lastPosition) / dt;
5860
+ finished = p == 1;
5861
+ } else if (config2.decay) {
5862
+ const decay = config2.decay === true ? 0.998 : config2.decay;
5863
+ const e = Math.exp(-(1 - decay) * elapsed);
5864
+ position = from + v0 / (1 - decay) * (1 - e);
5865
+ finished = Math.abs(node2.lastPosition - position) <= precision;
5866
+ velocity = v0 * e;
5867
+ } else {
5868
+ velocity = node2.lastVelocity == null ? v0 : node2.lastVelocity;
5869
+ const restVelocity = config2.restVelocity || precision / 10;
5870
+ const bounceFactor = config2.clamp ? 0 : config2.bounce;
5871
+ const canBounce = !is.und(bounceFactor);
5872
+ const isGrowing = from == to2 ? node2.v0 > 0 : from < to2;
5873
+ let isMoving;
5874
+ let isBouncing = false;
5875
+ const step = 1;
5876
+ const numSteps = Math.ceil(dt / step);
5877
+ for (let n = 0; n < numSteps; ++n) {
5878
+ isMoving = Math.abs(velocity) > restVelocity;
5879
+ if (!isMoving) {
5880
+ finished = Math.abs(to2 - position) <= precision;
5881
+ if (finished) {
5882
+ break;
5883
+ }
5884
+ }
5885
+ if (canBounce) {
5886
+ isBouncing = position == to2 || position > to2 == isGrowing;
5887
+ if (isBouncing) {
5888
+ velocity = -velocity * bounceFactor;
5889
+ position = to2;
5890
+ }
5891
+ }
5892
+ const springForce = -config2.tension * 1e-6 * (position - to2);
5893
+ const dampingForce = -config2.friction * 1e-3 * velocity;
5894
+ const acceleration = (springForce + dampingForce) / config2.mass;
5895
+ velocity = velocity + acceleration * step;
5896
+ position = position + velocity * step;
5897
+ }
5898
+ }
5899
+ node2.lastVelocity = velocity;
5900
+ if (Number.isNaN(position)) {
5901
+ console.warn(`Got NaN while animating:`, this);
5902
+ finished = true;
5903
+ }
5904
+ }
5905
+ if (payload && !payload[i].done) {
5906
+ finished = false;
5907
+ }
5908
+ if (finished) {
5909
+ node2.done = true;
5910
+ } else {
5911
+ idle = false;
5912
+ }
5913
+ if (node2.setValue(position, config2.round)) {
5914
+ changed = true;
5915
+ }
5916
+ });
5917
+ const node = getAnimated(this);
5918
+ const currVal = node.getValue();
5919
+ if (idle) {
5920
+ const finalVal = getFluidValue(anim.to);
5921
+ if ((currVal !== finalVal || changed) && !config2.decay) {
5922
+ node.setValue(finalVal);
5923
+ this._onChange(finalVal);
5924
+ } else if (changed && config2.decay) {
5925
+ this._onChange(currVal);
5926
+ }
5927
+ this._stop();
5928
+ } else if (changed) {
5929
+ this._onChange(currVal);
5930
+ }
5931
+ }
5932
+ /** Set the current value, while stopping the current animation */
5933
+ set(value) {
5934
+ raf.batchedUpdates(() => {
5935
+ this._stop();
5936
+ this._focus(value);
5937
+ this._set(value);
5938
+ });
5939
+ return this;
5940
+ }
5941
+ /**
5942
+ * Freeze the active animation in time, as well as any updates merged
5943
+ * before `resume` is called.
5944
+ */
5945
+ pause() {
5946
+ this._update({ pause: true });
5947
+ }
5948
+ /** Resume the animation if paused. */
5949
+ resume() {
5950
+ this._update({ pause: false });
5951
+ }
5952
+ /** Skip to the end of the current animation. */
5953
+ finish() {
5954
+ if (isAnimating(this)) {
5955
+ const { to: to2, config: config2 } = this.animation;
5956
+ raf.batchedUpdates(() => {
5957
+ this._onStart();
5958
+ if (!config2.decay) {
5959
+ this._set(to2, false);
5960
+ }
5961
+ this._stop();
5962
+ });
5963
+ }
5964
+ return this;
5965
+ }
5966
+ /** Push props into the pending queue. */
5967
+ update(props) {
5968
+ const queue = this.queue || (this.queue = []);
5969
+ queue.push(props);
5970
+ return this;
5971
+ }
5972
+ start(to2, arg2) {
5973
+ let queue;
5974
+ if (!is.und(to2)) {
5975
+ queue = [is.obj(to2) ? to2 : { ...arg2, to: to2 }];
5976
+ } else {
5977
+ queue = this.queue || [];
5978
+ this.queue = [];
5979
+ }
5980
+ return Promise.all(
5981
+ queue.map((props) => {
5982
+ const up = this._update(props);
5983
+ return up;
5984
+ })
5985
+ ).then((results) => getCombinedResult(this, results));
5986
+ }
5987
+ /**
5988
+ * Stop the current animation, and cancel any delayed updates.
5989
+ *
5990
+ * Pass `true` to call `onRest` with `cancelled: true`.
5991
+ */
5992
+ stop(cancel) {
5993
+ const { to: to2 } = this.animation;
5994
+ this._focus(this.get());
5995
+ stopAsync(this._state, cancel && this._lastCallId);
5996
+ raf.batchedUpdates(() => this._stop(to2, cancel));
5997
+ return this;
5998
+ }
5999
+ /** Restart the animation. */
6000
+ reset() {
6001
+ this._update({ reset: true });
6002
+ }
6003
+ /** @internal */
6004
+ eventObserved(event) {
6005
+ if (event.type == "change") {
6006
+ this._start();
6007
+ } else if (event.type == "priority") {
6008
+ this.priority = event.priority + 1;
6009
+ }
6010
+ }
6011
+ /**
6012
+ * Parse the `to` and `from` range from the given `props` object.
6013
+ *
6014
+ * This also ensures the initial value is available to animated components
6015
+ * during the render phase.
6016
+ */
6017
+ _prepareNode(props) {
6018
+ const key = this.key || "";
6019
+ let { to: to2, from } = props;
6020
+ to2 = is.obj(to2) ? to2[key] : to2;
6021
+ if (to2 == null || isAsyncTo(to2)) {
6022
+ to2 = void 0;
6023
+ }
6024
+ from = is.obj(from) ? from[key] : from;
6025
+ if (from == null) {
6026
+ from = void 0;
6027
+ }
6028
+ const range = { to: to2, from };
6029
+ if (!hasAnimated(this)) {
6030
+ if (props.reverse)
6031
+ [to2, from] = [from, to2];
6032
+ from = getFluidValue(from);
6033
+ if (!is.und(from)) {
6034
+ this._set(from);
6035
+ } else if (!getAnimated(this)) {
6036
+ this._set(to2);
6037
+ }
6038
+ }
6039
+ return range;
6040
+ }
6041
+ /** Every update is processed by this method before merging. */
6042
+ _update({ ...props }, isLoop) {
6043
+ const { key, defaultProps } = this;
6044
+ if (props.default)
6045
+ Object.assign(
6046
+ defaultProps,
6047
+ getDefaultProps(
6048
+ props,
6049
+ (value, prop) => /^on/.test(prop) ? resolveProp(value, key) : value
6050
+ )
6051
+ );
6052
+ mergeActiveFn(this, props, "onProps");
6053
+ sendEvent(this, "onProps", props, this);
6054
+ const range = this._prepareNode(props);
6055
+ if (Object.isFrozen(this)) {
6056
+ throw Error(
6057
+ "Cannot animate a `SpringValue` object that is frozen. Did you forget to pass your component to `animated(...)` before animating its props?"
6058
+ );
6059
+ }
6060
+ const state = this._state;
6061
+ return scheduleProps(++this._lastCallId, {
6062
+ key,
6063
+ props,
6064
+ defaultProps,
6065
+ state,
6066
+ actions: {
6067
+ pause: () => {
6068
+ if (!isPaused(this)) {
6069
+ setPausedBit(this, true);
6070
+ flushCalls(state.pauseQueue);
6071
+ sendEvent(
6072
+ this,
6073
+ "onPause",
6074
+ getFinishedResult(this, checkFinished(this, this.animation.to)),
6075
+ this
6076
+ );
6077
+ }
6078
+ },
6079
+ resume: () => {
6080
+ if (isPaused(this)) {
6081
+ setPausedBit(this, false);
6082
+ if (isAnimating(this)) {
6083
+ this._resume();
6084
+ }
6085
+ flushCalls(state.resumeQueue);
6086
+ sendEvent(
6087
+ this,
6088
+ "onResume",
6089
+ getFinishedResult(this, checkFinished(this, this.animation.to)),
6090
+ this
6091
+ );
6092
+ }
6093
+ },
6094
+ start: this._merge.bind(this, range)
6095
+ }
6096
+ }).then((result) => {
6097
+ if (props.loop && result.finished && !(isLoop && result.noop)) {
6098
+ const nextProps = createLoopUpdate(props);
6099
+ if (nextProps) {
6100
+ return this._update(nextProps, true);
6101
+ }
6102
+ }
6103
+ return result;
6104
+ });
6105
+ }
6106
+ /** Merge props into the current animation */
6107
+ _merge(range, props, resolve) {
6108
+ if (props.cancel) {
6109
+ this.stop(true);
6110
+ return resolve(getCancelledResult(this));
6111
+ }
6112
+ const hasToProp = !is.und(range.to);
6113
+ const hasFromProp = !is.und(range.from);
6114
+ if (hasToProp || hasFromProp) {
6115
+ if (props.callId > this._lastToId) {
6116
+ this._lastToId = props.callId;
6117
+ } else {
6118
+ return resolve(getCancelledResult(this));
6119
+ }
6120
+ }
6121
+ const { key, defaultProps, animation: anim } = this;
6122
+ const { to: prevTo, from: prevFrom } = anim;
6123
+ let { to: to2 = prevTo, from = prevFrom } = range;
6124
+ if (hasFromProp && !hasToProp && (!props.default || is.und(to2))) {
6125
+ to2 = from;
6126
+ }
6127
+ if (props.reverse)
6128
+ [to2, from] = [from, to2];
6129
+ const hasFromChanged = !isEqual(from, prevFrom);
6130
+ if (hasFromChanged) {
6131
+ anim.from = from;
6132
+ }
6133
+ from = getFluidValue(from);
6134
+ const hasToChanged = !isEqual(to2, prevTo);
6135
+ if (hasToChanged) {
6136
+ this._focus(to2);
6137
+ }
6138
+ const hasAsyncTo = isAsyncTo(props.to);
6139
+ const { config: config2 } = anim;
6140
+ const { decay, velocity } = config2;
6141
+ if (hasToProp || hasFromProp) {
6142
+ config2.velocity = 0;
6143
+ }
6144
+ if (props.config && !hasAsyncTo) {
6145
+ mergeConfig(
6146
+ config2,
6147
+ callProp(props.config, key),
6148
+ // Avoid calling the same "config" prop twice.
6149
+ props.config !== defaultProps.config ? callProp(defaultProps.config, key) : void 0
6150
+ );
6151
+ }
6152
+ let node = getAnimated(this);
6153
+ if (!node || is.und(to2)) {
6154
+ return resolve(getFinishedResult(this, true));
6155
+ }
6156
+ const reset = (
6157
+ // When `reset` is undefined, the `from` prop implies `reset: true`,
6158
+ // except for declarative updates. When `reset` is defined, there
6159
+ // must exist a value to animate from.
6160
+ is.und(props.reset) ? hasFromProp && !props.default : !is.und(from) && matchProp(props.reset, key)
6161
+ );
6162
+ const value = reset ? from : this.get();
6163
+ const goal = computeGoal(to2);
6164
+ const isAnimatable = is.num(goal) || is.arr(goal) || isAnimatedString(goal);
6165
+ const immediate = !hasAsyncTo && (!isAnimatable || matchProp(defaultProps.immediate || props.immediate, key));
6166
+ if (hasToChanged) {
6167
+ const nodeType = getAnimatedType(to2);
6168
+ if (nodeType !== node.constructor) {
6169
+ if (immediate) {
6170
+ node = this._set(goal);
6171
+ } else
6172
+ throw Error(
6173
+ `Cannot animate between ${node.constructor.name} and ${nodeType.name}, as the "to" prop suggests`
6174
+ );
6175
+ }
6176
+ }
6177
+ const goalType = node.constructor;
6178
+ let started = hasFluidValue(to2);
6179
+ let finished = false;
6180
+ if (!started) {
6181
+ const hasValueChanged = reset || !hasAnimated(this) && hasFromChanged;
6182
+ if (hasToChanged || hasValueChanged) {
6183
+ finished = isEqual(computeGoal(value), goal);
6184
+ started = !finished;
6185
+ }
6186
+ if (!isEqual(anim.immediate, immediate) && !immediate || !isEqual(config2.decay, decay) || !isEqual(config2.velocity, velocity)) {
6187
+ started = true;
6188
+ }
6189
+ }
6190
+ if (finished && isAnimating(this)) {
6191
+ if (anim.changed && !reset) {
6192
+ started = true;
6193
+ } else if (!started) {
6194
+ this._stop(prevTo);
6195
+ }
6196
+ }
6197
+ if (!hasAsyncTo) {
6198
+ if (started || hasFluidValue(prevTo)) {
6199
+ anim.values = node.getPayload();
6200
+ anim.toValues = hasFluidValue(to2) ? null : goalType == AnimatedString ? [1] : toArray(goal);
6201
+ }
6202
+ if (anim.immediate != immediate) {
6203
+ anim.immediate = immediate;
6204
+ if (!immediate && !reset) {
6205
+ this._set(prevTo);
6206
+ }
6207
+ }
6208
+ if (started) {
6209
+ const { onRest } = anim;
6210
+ each(ACTIVE_EVENTS, (type) => mergeActiveFn(this, props, type));
6211
+ const result = getFinishedResult(this, checkFinished(this, prevTo));
6212
+ flushCalls(this._pendingCalls, result);
6213
+ this._pendingCalls.add(resolve);
6214
+ if (anim.changed)
6215
+ raf.batchedUpdates(() => {
6216
+ var _a;
6217
+ anim.changed = !reset;
6218
+ onRest == null ? void 0 : onRest(result, this);
6219
+ if (reset) {
6220
+ callProp(defaultProps.onRest, result);
6221
+ } else {
6222
+ (_a = anim.onStart) == null ? void 0 : _a.call(anim, result, this);
6223
+ }
6224
+ });
6225
+ }
6226
+ }
6227
+ if (reset) {
6228
+ this._set(value);
6229
+ }
6230
+ if (hasAsyncTo) {
6231
+ resolve(runAsync(props.to, props, this._state, this));
6232
+ } else if (started) {
6233
+ this._start();
6234
+ } else if (isAnimating(this) && !hasToChanged) {
6235
+ this._pendingCalls.add(resolve);
6236
+ } else {
6237
+ resolve(getNoopResult(value));
6238
+ }
6239
+ }
6240
+ /** Update the `animation.to` value, which might be a `FluidValue` */
6241
+ _focus(value) {
6242
+ const anim = this.animation;
6243
+ if (value !== anim.to) {
6244
+ if (getFluidObservers(this)) {
6245
+ this._detach();
6246
+ }
6247
+ anim.to = value;
6248
+ if (getFluidObservers(this)) {
6249
+ this._attach();
6250
+ }
6251
+ }
6252
+ }
6253
+ _attach() {
6254
+ let priority2 = 0;
6255
+ const { to: to2 } = this.animation;
6256
+ if (hasFluidValue(to2)) {
6257
+ addFluidObserver(to2, this);
6258
+ if (isFrameValue(to2)) {
6259
+ priority2 = to2.priority + 1;
6260
+ }
6261
+ }
6262
+ this.priority = priority2;
6263
+ }
6264
+ _detach() {
6265
+ const { to: to2 } = this.animation;
6266
+ if (hasFluidValue(to2)) {
6267
+ removeFluidObserver(to2, this);
6268
+ }
6269
+ }
6270
+ /**
6271
+ * Update the current value from outside the frameloop,
6272
+ * and return the `Animated` node.
6273
+ */
6274
+ _set(arg, idle = true) {
6275
+ const value = getFluidValue(arg);
6276
+ if (!is.und(value)) {
6277
+ const oldNode = getAnimated(this);
6278
+ if (!oldNode || !isEqual(value, oldNode.getValue())) {
6279
+ const nodeType = getAnimatedType(value);
6280
+ if (!oldNode || oldNode.constructor != nodeType) {
6281
+ setAnimated(this, nodeType.create(value));
6282
+ } else {
6283
+ oldNode.setValue(value);
6284
+ }
6285
+ if (oldNode) {
6286
+ raf.batchedUpdates(() => {
6287
+ this._onChange(value, idle);
6288
+ });
6289
+ }
6290
+ }
6291
+ }
6292
+ return getAnimated(this);
6293
+ }
6294
+ _onStart() {
6295
+ const anim = this.animation;
6296
+ if (!anim.changed) {
6297
+ anim.changed = true;
6298
+ sendEvent(
6299
+ this,
6300
+ "onStart",
6301
+ getFinishedResult(this, checkFinished(this, anim.to)),
6302
+ this
6303
+ );
6304
+ }
6305
+ }
6306
+ _onChange(value, idle) {
6307
+ if (!idle) {
6308
+ this._onStart();
6309
+ callProp(this.animation.onChange, value, this);
6310
+ }
6311
+ callProp(this.defaultProps.onChange, value, this);
6312
+ super._onChange(value, idle);
6313
+ }
6314
+ // This method resets the animation state (even if already animating) to
6315
+ // ensure the latest from/to range is used, and it also ensures this spring
6316
+ // is added to the frameloop.
6317
+ _start() {
6318
+ const anim = this.animation;
6319
+ getAnimated(this).reset(getFluidValue(anim.to));
6320
+ if (!anim.immediate) {
6321
+ anim.fromValues = anim.values.map((node) => node.lastPosition);
6322
+ }
6323
+ if (!isAnimating(this)) {
6324
+ setActiveBit(this, true);
6325
+ if (!isPaused(this)) {
6326
+ this._resume();
6327
+ }
6328
+ }
6329
+ }
6330
+ _resume() {
6331
+ if (globals_exports.skipAnimation) {
6332
+ this.finish();
6333
+ } else {
6334
+ frameLoop.start(this);
6335
+ }
6336
+ }
6337
+ /**
6338
+ * Exit the frameloop and notify `onRest` listeners.
6339
+ *
6340
+ * Always wrap `_stop` calls with `batchedUpdates`.
6341
+ */
6342
+ _stop(goal, cancel) {
6343
+ if (isAnimating(this)) {
6344
+ setActiveBit(this, false);
6345
+ const anim = this.animation;
6346
+ each(anim.values, (node) => {
6347
+ node.done = true;
6348
+ });
6349
+ if (anim.toValues) {
6350
+ anim.onChange = anim.onPause = anim.onResume = void 0;
6351
+ }
6352
+ callFluidObservers(this, {
6353
+ type: "idle",
6354
+ parent: this
6355
+ });
6356
+ const result = cancel ? getCancelledResult(this.get()) : getFinishedResult(this.get(), checkFinished(this, goal ?? anim.to));
6357
+ flushCalls(this._pendingCalls, result);
6358
+ if (anim.changed) {
6359
+ anim.changed = false;
6360
+ sendEvent(this, "onRest", result, this);
6361
+ }
6362
+ }
6363
+ }
6364
+ };
6365
+ function checkFinished(target, to2) {
6366
+ const goal = computeGoal(to2);
6367
+ const value = computeGoal(target.get());
6368
+ return isEqual(value, goal);
6369
+ }
6370
+ function createLoopUpdate(props, loop2 = props.loop, to2 = props.to) {
6371
+ const loopRet = callProp(loop2);
6372
+ if (loopRet) {
6373
+ const overrides = loopRet !== true && inferTo(loopRet);
6374
+ const reverse = (overrides || props).reverse;
6375
+ const reset = !overrides || overrides.reset;
6376
+ return createUpdate({
6377
+ ...props,
6378
+ loop: loop2,
6379
+ // Avoid updating default props when looping.
6380
+ default: false,
6381
+ // Never loop the `pause` prop.
6382
+ pause: void 0,
6383
+ // For the "reverse" prop to loop as expected, the "to" prop
6384
+ // must be undefined. The "reverse" prop is ignored when the
6385
+ // "to" prop is an array or function.
6386
+ to: !reverse || isAsyncTo(to2) ? to2 : void 0,
6387
+ // Ignore the "from" prop except on reset.
6388
+ from: reset ? props.from : void 0,
6389
+ reset,
6390
+ // The "loop" prop can return a "useSpring" props object to
6391
+ // override any of the original props.
6392
+ ...overrides
6393
+ });
6394
+ }
6395
+ }
6396
+ function createUpdate(props) {
6397
+ const { to: to2, from } = props = inferTo(props);
6398
+ const keys = /* @__PURE__ */ new Set();
6399
+ if (is.obj(to2))
6400
+ findDefined(to2, keys);
6401
+ if (is.obj(from))
6402
+ findDefined(from, keys);
6403
+ props.keys = keys.size ? Array.from(keys) : null;
6404
+ return props;
6405
+ }
6406
+ function declareUpdate(props) {
6407
+ const update2 = createUpdate(props);
6408
+ if (is.und(update2.default)) {
6409
+ update2.default = getDefaultProps(update2);
6410
+ }
6411
+ return update2;
6412
+ }
6413
+ function findDefined(values, keys) {
6414
+ eachProp(values, (value, key) => value != null && keys.add(key));
6415
+ }
6416
+ var ACTIVE_EVENTS = [
6417
+ "onStart",
6418
+ "onRest",
6419
+ "onChange",
6420
+ "onPause",
6421
+ "onResume"
6422
+ ];
6423
+ function mergeActiveFn(target, props, type) {
6424
+ target.animation[type] = props[type] !== getDefaultProp(props, type) ? resolveProp(props[type], target.key) : void 0;
6425
+ }
6426
+ function sendEvent(target, type, ...args) {
6427
+ var _a, _b, _c, _d;
6428
+ (_b = (_a = target.animation)[type]) == null ? void 0 : _b.call(_a, ...args);
6429
+ (_d = (_c = target.defaultProps)[type]) == null ? void 0 : _d.call(_c, ...args);
6430
+ }
6431
+ var BATCHED_EVENTS = ["onStart", "onChange", "onRest"];
6432
+ var nextId2 = 1;
6433
+ var Controller = class {
6434
+ constructor(props, flush3) {
6435
+ this.id = nextId2++;
6436
+ this.springs = {};
6437
+ this.queue = [];
6438
+ this._lastAsyncId = 0;
6439
+ this._active = /* @__PURE__ */ new Set();
6440
+ this._changed = /* @__PURE__ */ new Set();
6441
+ this._started = false;
6442
+ this._state = {
6443
+ paused: false,
6444
+ pauseQueue: /* @__PURE__ */ new Set(),
6445
+ resumeQueue: /* @__PURE__ */ new Set(),
6446
+ timeouts: /* @__PURE__ */ new Set()
6447
+ };
6448
+ this._events = {
6449
+ onStart: /* @__PURE__ */ new Map(),
6450
+ onChange: /* @__PURE__ */ new Map(),
6451
+ onRest: /* @__PURE__ */ new Map()
6452
+ };
6453
+ this._onFrame = this._onFrame.bind(this);
6454
+ if (flush3) {
6455
+ this._flush = flush3;
6456
+ }
6457
+ if (props) {
6458
+ this.start({ default: true, ...props });
6459
+ }
6460
+ }
6461
+ /**
6462
+ * Equals `true` when no spring values are in the frameloop, and
6463
+ * no async animation is currently active.
6464
+ */
6465
+ get idle() {
6466
+ return !this._state.asyncTo && Object.values(this.springs).every((spring) => {
6467
+ return spring.idle && !spring.isDelayed && !spring.isPaused;
6468
+ });
6469
+ }
6470
+ get item() {
6471
+ return this._item;
6472
+ }
6473
+ set item(item) {
6474
+ this._item = item;
6475
+ }
6476
+ /** Get the current values of our springs */
6477
+ get() {
6478
+ const values = {};
6479
+ this.each((spring, key) => values[key] = spring.get());
6480
+ return values;
6481
+ }
6482
+ /** Set the current values without animating. */
6483
+ set(values) {
6484
+ for (const key in values) {
6485
+ const value = values[key];
6486
+ if (!is.und(value)) {
6487
+ this.springs[key].set(value);
6488
+ }
6489
+ }
6490
+ }
6491
+ /** Push an update onto the queue of each value. */
6492
+ update(props) {
6493
+ if (props) {
6494
+ this.queue.push(createUpdate(props));
6495
+ }
6496
+ return this;
6497
+ }
6498
+ /**
6499
+ * Start the queued animations for every spring, and resolve the returned
6500
+ * promise once all queued animations have finished or been cancelled.
6501
+ *
6502
+ * When you pass a queue (instead of nothing), that queue is used instead of
6503
+ * the queued animations added with the `update` method, which are left alone.
6504
+ */
6505
+ start(props) {
6506
+ let { queue } = this;
6507
+ if (props) {
6508
+ queue = toArray(props).map(createUpdate);
6509
+ } else {
6510
+ this.queue = [];
6511
+ }
6512
+ if (this._flush) {
6513
+ return this._flush(this, queue);
6514
+ }
6515
+ prepareKeys(this, queue);
6516
+ return flushUpdateQueue(this, queue);
6517
+ }
6518
+ /** @internal */
6519
+ stop(arg, keys) {
6520
+ if (arg !== !!arg) {
6521
+ keys = arg;
6522
+ }
6523
+ if (keys) {
6524
+ const springs = this.springs;
6525
+ each(toArray(keys), (key) => springs[key].stop(!!arg));
6526
+ } else {
6527
+ stopAsync(this._state, this._lastAsyncId);
6528
+ this.each((spring) => spring.stop(!!arg));
6529
+ }
6530
+ return this;
6531
+ }
6532
+ /** Freeze the active animation in time */
6533
+ pause(keys) {
6534
+ if (is.und(keys)) {
6535
+ this.start({ pause: true });
6536
+ } else {
6537
+ const springs = this.springs;
6538
+ each(toArray(keys), (key) => springs[key].pause());
6539
+ }
6540
+ return this;
6541
+ }
6542
+ /** Resume the animation if paused. */
6543
+ resume(keys) {
6544
+ if (is.und(keys)) {
6545
+ this.start({ pause: false });
6546
+ } else {
6547
+ const springs = this.springs;
6548
+ each(toArray(keys), (key) => springs[key].resume());
6549
+ }
6550
+ return this;
6551
+ }
6552
+ /** Call a function once per spring value */
6553
+ each(iterator) {
6554
+ eachProp(this.springs, iterator);
6555
+ }
6556
+ /** @internal Called at the end of every animation frame */
6557
+ _onFrame() {
6558
+ const { onStart, onChange, onRest } = this._events;
6559
+ const active = this._active.size > 0;
6560
+ const changed = this._changed.size > 0;
6561
+ if (active && !this._started || changed && !this._started) {
6562
+ this._started = true;
6563
+ flush(onStart, ([onStart2, result]) => {
6564
+ result.value = this.get();
6565
+ onStart2(result, this, this._item);
6566
+ });
6567
+ }
6568
+ const idle = !active && this._started;
6569
+ const values = changed || idle && onRest.size ? this.get() : null;
6570
+ if (changed && onChange.size) {
6571
+ flush(onChange, ([onChange2, result]) => {
6572
+ result.value = values;
6573
+ onChange2(result, this, this._item);
6574
+ });
6575
+ }
6576
+ if (idle) {
6577
+ this._started = false;
6578
+ flush(onRest, ([onRest2, result]) => {
6579
+ result.value = values;
6580
+ onRest2(result, this, this._item);
6581
+ });
6582
+ }
6583
+ }
6584
+ /** @internal */
6585
+ eventObserved(event) {
6586
+ if (event.type == "change") {
6587
+ this._changed.add(event.parent);
6588
+ if (!event.idle) {
6589
+ this._active.add(event.parent);
6590
+ }
6591
+ } else if (event.type == "idle") {
6592
+ this._active.delete(event.parent);
6593
+ } else
6594
+ return;
6595
+ raf.onFrame(this._onFrame);
6596
+ }
6597
+ };
6598
+ function flushUpdateQueue(ctrl, queue) {
6599
+ return Promise.all(queue.map((props) => flushUpdate(ctrl, props))).then(
6600
+ (results) => getCombinedResult(ctrl, results)
6601
+ );
6602
+ }
6603
+ async function flushUpdate(ctrl, props, isLoop) {
6604
+ const { keys, to: to2, from, loop: loop2, onRest, onResolve } = props;
6605
+ const defaults2 = is.obj(props.default) && props.default;
6606
+ if (loop2) {
6607
+ props.loop = false;
6608
+ }
6609
+ if (to2 === false)
6610
+ props.to = null;
6611
+ if (from === false)
6612
+ props.from = null;
6613
+ const asyncTo = is.arr(to2) || is.fun(to2) ? to2 : void 0;
6614
+ if (asyncTo) {
6615
+ props.to = void 0;
6616
+ props.onRest = void 0;
6617
+ if (defaults2) {
6618
+ defaults2.onRest = void 0;
6619
+ }
6620
+ } else {
6621
+ each(BATCHED_EVENTS, (key) => {
6622
+ const handler = props[key];
6623
+ if (is.fun(handler)) {
6624
+ const queue = ctrl["_events"][key];
6625
+ props[key] = ({ finished, cancelled }) => {
6626
+ const result2 = queue.get(handler);
6627
+ if (result2) {
6628
+ if (!finished)
6629
+ result2.finished = false;
6630
+ if (cancelled)
6631
+ result2.cancelled = true;
6632
+ } else {
6633
+ queue.set(handler, {
6634
+ value: null,
6635
+ finished: finished || false,
6636
+ cancelled: cancelled || false
6637
+ });
6638
+ }
6639
+ };
6640
+ if (defaults2) {
6641
+ defaults2[key] = props[key];
6642
+ }
6643
+ }
6644
+ });
6645
+ }
6646
+ const state = ctrl["_state"];
6647
+ if (props.pause === !state.paused) {
6648
+ state.paused = props.pause;
6649
+ flushCalls(props.pause ? state.pauseQueue : state.resumeQueue);
6650
+ } else if (state.paused) {
6651
+ props.pause = true;
6652
+ }
6653
+ const promises = (keys || Object.keys(ctrl.springs)).map(
6654
+ (key) => ctrl.springs[key].start(props)
6655
+ );
6656
+ const cancel = props.cancel === true || getDefaultProp(props, "cancel") === true;
6657
+ if (asyncTo || cancel && state.asyncId) {
6658
+ promises.push(
6659
+ scheduleProps(++ctrl["_lastAsyncId"], {
6660
+ props,
6661
+ state,
6662
+ actions: {
6663
+ pause: noop,
6664
+ resume: noop,
6665
+ start(props2, resolve) {
6666
+ if (cancel) {
6667
+ stopAsync(state, ctrl["_lastAsyncId"]);
6668
+ resolve(getCancelledResult(ctrl));
6669
+ } else {
6670
+ props2.onRest = onRest;
6671
+ resolve(
6672
+ runAsync(
6673
+ asyncTo,
6674
+ props2,
6675
+ state,
6676
+ ctrl
6677
+ )
6678
+ );
6679
+ }
6680
+ }
6681
+ }
6682
+ })
6683
+ );
6684
+ }
6685
+ if (state.paused) {
6686
+ await new Promise((resume) => {
6687
+ state.resumeQueue.add(resume);
6688
+ });
6689
+ }
6690
+ const result = getCombinedResult(ctrl, await Promise.all(promises));
6691
+ if (loop2 && result.finished && !(isLoop && result.noop)) {
6692
+ const nextProps = createLoopUpdate(props, loop2, to2);
6693
+ if (nextProps) {
6694
+ prepareKeys(ctrl, [nextProps]);
6695
+ return flushUpdate(ctrl, nextProps, true);
6696
+ }
6697
+ }
6698
+ if (onResolve) {
6699
+ raf.batchedUpdates(() => onResolve(result, ctrl, ctrl.item));
6700
+ }
6701
+ return result;
6702
+ }
6703
+ function getSprings(ctrl, props) {
6704
+ const springs = { ...ctrl.springs };
6705
+ if (props) {
6706
+ each(toArray(props), (props2) => {
6707
+ if (is.und(props2.keys)) {
6708
+ props2 = createUpdate(props2);
6709
+ }
6710
+ if (!is.obj(props2.to)) {
6711
+ props2 = { ...props2, to: void 0 };
6712
+ }
6713
+ prepareSprings(springs, props2, (key) => {
6714
+ return createSpring(key);
6715
+ });
6716
+ });
6717
+ }
6718
+ setSprings(ctrl, springs);
6719
+ return springs;
6720
+ }
6721
+ function setSprings(ctrl, springs) {
6722
+ eachProp(springs, (spring, key) => {
6723
+ if (!ctrl.springs[key]) {
6724
+ ctrl.springs[key] = spring;
6725
+ addFluidObserver(spring, ctrl);
6726
+ }
6727
+ });
6728
+ }
6729
+ function createSpring(key, observer) {
6730
+ const spring = new SpringValue();
6731
+ spring.key = key;
6732
+ if (observer) {
6733
+ addFluidObserver(spring, observer);
6734
+ }
6735
+ return spring;
6736
+ }
6737
+ function prepareSprings(springs, props, create) {
6738
+ if (props.keys) {
6739
+ each(props.keys, (key) => {
6740
+ const spring = springs[key] || (springs[key] = create(key));
6741
+ spring["_prepareNode"](props);
6742
+ });
6743
+ }
6744
+ }
6745
+ function prepareKeys(ctrl, queue) {
6746
+ each(queue, (props) => {
6747
+ prepareSprings(ctrl.springs, props, (key) => {
6748
+ return createSpring(key, ctrl);
6749
+ });
6750
+ });
6751
+ }
6752
+ var SpringContext = ({
6753
+ children,
6754
+ ...props
6755
+ }) => {
6756
+ const inherited = React.useContext(ctx);
6757
+ const pause = props.pause || !!inherited.pause, immediate = props.immediate || !!inherited.immediate;
6758
+ props = useMemoOne(() => ({ pause, immediate }), [pause, immediate]);
6759
+ const { Provider } = ctx;
6760
+ return /* @__PURE__ */ React__namespace.createElement(Provider, { value: props }, children);
6761
+ };
6762
+ var ctx = makeContext(SpringContext, {});
6763
+ SpringContext.Provider = ctx.Provider;
6764
+ SpringContext.Consumer = ctx.Consumer;
6765
+ function makeContext(target, init) {
6766
+ Object.assign(target, React__namespace.createContext(init));
6767
+ target.Provider._context = target;
6768
+ target.Consumer._context = target;
6769
+ return target;
6770
+ }
6771
+ var SpringRef = () => {
6772
+ const current = [];
6773
+ const SpringRef2 = function(props) {
6774
+ deprecateDirectCall();
6775
+ const results = [];
6776
+ each(current, (ctrl, i) => {
6777
+ if (is.und(props)) {
6778
+ results.push(ctrl.start());
6779
+ } else {
6780
+ const update2 = _getProps(props, ctrl, i);
6781
+ if (update2) {
6782
+ results.push(ctrl.start(update2));
6783
+ }
6784
+ }
6785
+ });
6786
+ return results;
6787
+ };
6788
+ SpringRef2.current = current;
6789
+ SpringRef2.add = function(ctrl) {
6790
+ if (!current.includes(ctrl)) {
6791
+ current.push(ctrl);
6792
+ }
6793
+ };
6794
+ SpringRef2.delete = function(ctrl) {
6795
+ const i = current.indexOf(ctrl);
6796
+ if (~i)
6797
+ current.splice(i, 1);
6798
+ };
6799
+ SpringRef2.pause = function() {
6800
+ each(current, (ctrl) => ctrl.pause(...arguments));
6801
+ return this;
6802
+ };
6803
+ SpringRef2.resume = function() {
6804
+ each(current, (ctrl) => ctrl.resume(...arguments));
6805
+ return this;
6806
+ };
6807
+ SpringRef2.set = function(values) {
6808
+ each(current, (ctrl, i) => {
6809
+ const update2 = is.fun(values) ? values(i, ctrl) : values;
6810
+ if (update2) {
6811
+ ctrl.set(update2);
6812
+ }
6813
+ });
6814
+ };
6815
+ SpringRef2.start = function(props) {
6816
+ const results = [];
6817
+ each(current, (ctrl, i) => {
6818
+ if (is.und(props)) {
6819
+ results.push(ctrl.start());
6820
+ } else {
6821
+ const update2 = this._getProps(props, ctrl, i);
6822
+ if (update2) {
6823
+ results.push(ctrl.start(update2));
6824
+ }
6825
+ }
6826
+ });
6827
+ return results;
6828
+ };
6829
+ SpringRef2.stop = function() {
6830
+ each(current, (ctrl) => ctrl.stop(...arguments));
6831
+ return this;
6832
+ };
6833
+ SpringRef2.update = function(props) {
6834
+ each(current, (ctrl, i) => ctrl.update(this._getProps(props, ctrl, i)));
6835
+ return this;
6836
+ };
6837
+ const _getProps = function(arg, ctrl, index) {
6838
+ return is.fun(arg) ? arg(index, ctrl) : arg;
6839
+ };
6840
+ SpringRef2._getProps = _getProps;
6841
+ return SpringRef2;
6842
+ };
6843
+ function useSprings(length, props, deps) {
6844
+ const propsFn = is.fun(props) && props;
6845
+ if (propsFn && !deps)
6846
+ deps = [];
6847
+ const ref = React.useMemo(
6848
+ () => propsFn || arguments.length == 3 ? SpringRef() : void 0,
6849
+ []
6850
+ );
6851
+ const layoutId = React.useRef(0);
6852
+ const forceUpdate = useForceUpdate();
6853
+ const state = React.useMemo(
6854
+ () => ({
6855
+ ctrls: [],
6856
+ queue: [],
6857
+ flush(ctrl, updates2) {
6858
+ const springs2 = getSprings(ctrl, updates2);
6859
+ const canFlushSync = layoutId.current > 0 && !state.queue.length && !Object.keys(springs2).some((key) => !ctrl.springs[key]);
6860
+ return canFlushSync ? flushUpdateQueue(ctrl, updates2) : new Promise((resolve) => {
6861
+ setSprings(ctrl, springs2);
6862
+ state.queue.push(() => {
6863
+ resolve(flushUpdateQueue(ctrl, updates2));
6864
+ });
6865
+ forceUpdate();
6866
+ });
6867
+ }
6868
+ }),
6869
+ []
6870
+ );
6871
+ const ctrls = React.useRef([...state.ctrls]);
6872
+ const updates = [];
6873
+ const prevLength = usePrev(length) || 0;
6874
+ React.useMemo(() => {
6875
+ each(ctrls.current.slice(length, prevLength), (ctrl) => {
6876
+ detachRefs(ctrl, ref);
6877
+ ctrl.stop(true);
6878
+ });
6879
+ ctrls.current.length = length;
6880
+ declareUpdates(prevLength, length);
6881
+ }, [length]);
6882
+ React.useMemo(() => {
6883
+ declareUpdates(0, Math.min(prevLength, length));
6884
+ }, deps);
6885
+ function declareUpdates(startIndex, endIndex) {
6886
+ for (let i = startIndex; i < endIndex; i++) {
6887
+ const ctrl = ctrls.current[i] || (ctrls.current[i] = new Controller(null, state.flush));
6888
+ const update2 = propsFn ? propsFn(i, ctrl) : props[i];
6889
+ if (update2) {
6890
+ updates[i] = declareUpdate(update2);
6891
+ }
6892
+ }
6893
+ }
6894
+ const springs = ctrls.current.map((ctrl, i) => getSprings(ctrl, updates[i]));
6895
+ const context2 = React.useContext(SpringContext);
6896
+ const prevContext = usePrev(context2);
6897
+ const hasContext = context2 !== prevContext && hasProps(context2);
6898
+ useIsomorphicLayoutEffect(() => {
6899
+ layoutId.current++;
6900
+ state.ctrls = ctrls.current;
6901
+ const { queue } = state;
6902
+ if (queue.length) {
6903
+ state.queue = [];
6904
+ each(queue, (cb) => cb());
6905
+ }
6906
+ each(ctrls.current, (ctrl, i) => {
6907
+ ref == null ? void 0 : ref.add(ctrl);
6908
+ if (hasContext) {
6909
+ ctrl.start({ default: context2 });
6910
+ }
6911
+ const update2 = updates[i];
6912
+ if (update2) {
6913
+ replaceRef(ctrl, update2.ref);
6914
+ if (ctrl.ref) {
6915
+ ctrl.queue.push(update2);
6916
+ } else {
6917
+ ctrl.start(update2);
6918
+ }
6919
+ }
6920
+ });
6921
+ });
6922
+ useOnce(() => () => {
6923
+ each(state.ctrls, (ctrl) => ctrl.stop(true));
6924
+ });
6925
+ const values = springs.map((x) => ({ ...x }));
6926
+ return ref ? [values, ref] : values;
6927
+ }
6928
+ function useSpring(props, deps) {
6929
+ const isFn = is.fun(props);
6930
+ const [[values], ref] = useSprings(
6931
+ 1,
6932
+ isFn ? props : [props],
6933
+ isFn ? deps || [] : deps
6934
+ );
6935
+ return isFn || arguments.length == 2 ? [values, ref] : values;
6936
+ }
6937
+ var Interpolation = class extends FrameValue {
6938
+ constructor(source, args) {
6939
+ super();
6940
+ this.source = source;
6941
+ this.idle = true;
6942
+ this._active = /* @__PURE__ */ new Set();
6943
+ this.calc = createInterpolator(...args);
6944
+ const value = this._get();
6945
+ const nodeType = getAnimatedType(value);
6946
+ setAnimated(this, nodeType.create(value));
6947
+ }
6948
+ advance(_dt) {
6949
+ const value = this._get();
6950
+ const oldValue = this.get();
6951
+ if (!isEqual(value, oldValue)) {
6952
+ getAnimated(this).setValue(value);
6953
+ this._onChange(value, this.idle);
6954
+ }
6955
+ if (!this.idle && checkIdle(this._active)) {
6956
+ becomeIdle(this);
6957
+ }
6958
+ }
6959
+ _get() {
6960
+ const inputs = is.arr(this.source) ? this.source.map(getFluidValue) : toArray(getFluidValue(this.source));
6961
+ return this.calc(...inputs);
6962
+ }
6963
+ _start() {
6964
+ if (this.idle && !checkIdle(this._active)) {
6965
+ this.idle = false;
6966
+ each(getPayload(this), (node) => {
6967
+ node.done = false;
6968
+ });
6969
+ if (globals_exports.skipAnimation) {
6970
+ raf.batchedUpdates(() => this.advance());
6971
+ becomeIdle(this);
6972
+ } else {
6973
+ frameLoop.start(this);
6974
+ }
6975
+ }
6976
+ }
6977
+ // Observe our sources only when we're observed.
6978
+ _attach() {
6979
+ let priority2 = 1;
6980
+ each(toArray(this.source), (source) => {
6981
+ if (hasFluidValue(source)) {
6982
+ addFluidObserver(source, this);
6983
+ }
6984
+ if (isFrameValue(source)) {
6985
+ if (!source.idle) {
6986
+ this._active.add(source);
6987
+ }
6988
+ priority2 = Math.max(priority2, source.priority + 1);
6989
+ }
6990
+ });
6991
+ this.priority = priority2;
6992
+ this._start();
6993
+ }
6994
+ // Stop observing our sources once we have no observers.
6995
+ _detach() {
6996
+ each(toArray(this.source), (source) => {
6997
+ if (hasFluidValue(source)) {
6998
+ removeFluidObserver(source, this);
6999
+ }
7000
+ });
7001
+ this._active.clear();
7002
+ becomeIdle(this);
7003
+ }
7004
+ /** @internal */
7005
+ eventObserved(event) {
7006
+ if (event.type == "change") {
7007
+ if (event.idle) {
7008
+ this.advance();
7009
+ } else {
7010
+ this._active.add(event.parent);
7011
+ this._start();
7012
+ }
7013
+ } else if (event.type == "idle") {
7014
+ this._active.delete(event.parent);
7015
+ } else if (event.type == "priority") {
7016
+ this.priority = toArray(this.source).reduce(
7017
+ (highest, parent) => Math.max(highest, (isFrameValue(parent) ? parent.priority : 0) + 1),
7018
+ 0
7019
+ );
7020
+ }
7021
+ }
7022
+ };
7023
+ function isIdle(source) {
7024
+ return source.idle !== false;
7025
+ }
7026
+ function checkIdle(active) {
7027
+ return !active.size || Array.from(active).every(isIdle);
7028
+ }
7029
+ function becomeIdle(self) {
7030
+ if (!self.idle) {
7031
+ self.idle = true;
7032
+ each(getPayload(self), (node) => {
7033
+ node.done = true;
7034
+ });
7035
+ callFluidObservers(self, {
7036
+ type: "idle",
7037
+ parent: self
7038
+ });
7039
+ }
7040
+ }
7041
+ globals_exports.assign({
7042
+ createStringInterpolator: createStringInterpolator2,
7043
+ to: (source, args) => new Interpolation(source, args)
7044
+ });
7045
+ var isCustomPropRE = /^--/;
7046
+ function dangerousStyleValue(name, value) {
7047
+ if (value == null || typeof value === "boolean" || value === "")
7048
+ return "";
7049
+ if (typeof value === "number" && value !== 0 && !isCustomPropRE.test(name) && !(isUnitlessNumber.hasOwnProperty(name) && isUnitlessNumber[name]))
7050
+ return value + "px";
7051
+ return ("" + value).trim();
7052
+ }
7053
+ var attributeCache = {};
7054
+ function applyAnimatedValues(instance, props) {
7055
+ if (!instance.nodeType || !instance.setAttribute) {
7056
+ return false;
7057
+ }
7058
+ const isFilterElement = instance.nodeName === "filter" || instance.parentNode && instance.parentNode.nodeName === "filter";
7059
+ const {
7060
+ className,
7061
+ style,
7062
+ children,
7063
+ scrollTop,
7064
+ scrollLeft,
7065
+ viewBox,
7066
+ ...attributes
7067
+ } = props;
7068
+ const values = Object.values(attributes);
7069
+ const names = Object.keys(attributes).map(
7070
+ (name) => isFilterElement || instance.hasAttribute(name) ? name : attributeCache[name] || (attributeCache[name] = name.replace(
7071
+ /([A-Z])/g,
7072
+ // Attributes are written in dash case
7073
+ (n) => "-" + n.toLowerCase()
7074
+ ))
7075
+ );
7076
+ if (children !== void 0) {
7077
+ instance.textContent = children;
7078
+ }
7079
+ for (const name in style) {
7080
+ if (style.hasOwnProperty(name)) {
7081
+ const value = dangerousStyleValue(name, style[name]);
7082
+ if (isCustomPropRE.test(name)) {
7083
+ instance.style.setProperty(name, value);
7084
+ } else {
7085
+ instance.style[name] = value;
7086
+ }
7087
+ }
7088
+ }
7089
+ names.forEach((name, i) => {
7090
+ instance.setAttribute(name, values[i]);
7091
+ });
7092
+ if (className !== void 0) {
7093
+ instance.className = className;
7094
+ }
7095
+ if (scrollTop !== void 0) {
7096
+ instance.scrollTop = scrollTop;
7097
+ }
7098
+ if (scrollLeft !== void 0) {
7099
+ instance.scrollLeft = scrollLeft;
7100
+ }
7101
+ if (viewBox !== void 0) {
7102
+ instance.setAttribute("viewBox", viewBox);
7103
+ }
7104
+ }
7105
+ var isUnitlessNumber = {
7106
+ animationIterationCount: true,
7107
+ borderImageOutset: true,
7108
+ borderImageSlice: true,
7109
+ borderImageWidth: true,
7110
+ boxFlex: true,
7111
+ boxFlexGroup: true,
7112
+ boxOrdinalGroup: true,
7113
+ columnCount: true,
7114
+ columns: true,
7115
+ flex: true,
7116
+ flexGrow: true,
7117
+ flexPositive: true,
7118
+ flexShrink: true,
7119
+ flexNegative: true,
7120
+ flexOrder: true,
7121
+ gridRow: true,
7122
+ gridRowEnd: true,
7123
+ gridRowSpan: true,
7124
+ gridRowStart: true,
7125
+ gridColumn: true,
7126
+ gridColumnEnd: true,
7127
+ gridColumnSpan: true,
7128
+ gridColumnStart: true,
7129
+ fontWeight: true,
7130
+ lineClamp: true,
7131
+ lineHeight: true,
7132
+ opacity: true,
7133
+ order: true,
7134
+ orphans: true,
7135
+ tabSize: true,
7136
+ widows: true,
7137
+ zIndex: true,
7138
+ zoom: true,
7139
+ // SVG-related properties
7140
+ fillOpacity: true,
7141
+ floodOpacity: true,
7142
+ stopOpacity: true,
7143
+ strokeDasharray: true,
7144
+ strokeDashoffset: true,
7145
+ strokeMiterlimit: true,
7146
+ strokeOpacity: true,
7147
+ strokeWidth: true
7148
+ };
7149
+ var prefixKey = (prefix2, key) => prefix2 + key.charAt(0).toUpperCase() + key.substring(1);
7150
+ var prefixes = ["Webkit", "Ms", "Moz", "O"];
7151
+ isUnitlessNumber = Object.keys(isUnitlessNumber).reduce((acc, prop) => {
7152
+ prefixes.forEach((prefix2) => acc[prefixKey(prefix2, prop)] = acc[prop]);
7153
+ return acc;
7154
+ }, isUnitlessNumber);
7155
+ var domTransforms = /^(matrix|translate|scale|rotate|skew)/;
7156
+ var pxTransforms = /^(translate)/;
7157
+ var degTransforms = /^(rotate|skew)/;
7158
+ var addUnit = (value, unit) => is.num(value) && value !== 0 ? value + unit : value;
7159
+ var isValueIdentity = (value, id) => is.arr(value) ? value.every((v2) => isValueIdentity(v2, id)) : is.num(value) ? value === id : parseFloat(value) === id;
7160
+ var AnimatedStyle = class extends AnimatedObject {
7161
+ constructor({ x, y, z, ...style }) {
7162
+ const inputs = [];
7163
+ const transforms = [];
7164
+ if (x || y || z) {
7165
+ inputs.push([x || 0, y || 0, z || 0]);
7166
+ transforms.push((xyz) => [
7167
+ `translate3d(${xyz.map((v2) => addUnit(v2, "px")).join(",")})`,
7168
+ // prettier-ignore
7169
+ isValueIdentity(xyz, 0)
7170
+ ]);
7171
+ }
7172
+ eachProp(style, (value, key) => {
7173
+ if (key === "transform") {
7174
+ inputs.push([value || ""]);
7175
+ transforms.push((transform) => [transform, transform === ""]);
7176
+ } else if (domTransforms.test(key)) {
7177
+ delete style[key];
7178
+ if (is.und(value))
7179
+ return;
7180
+ const unit = pxTransforms.test(key) ? "px" : degTransforms.test(key) ? "deg" : "";
7181
+ inputs.push(toArray(value));
7182
+ transforms.push(
7183
+ key === "rotate3d" ? ([x2, y2, z2, deg]) => [
7184
+ `rotate3d(${x2},${y2},${z2},${addUnit(deg, unit)})`,
7185
+ isValueIdentity(deg, 0)
7186
+ ] : (input) => [
7187
+ `${key}(${input.map((v2) => addUnit(v2, unit)).join(",")})`,
7188
+ isValueIdentity(input, key.startsWith("scale") ? 1 : 0)
7189
+ ]
7190
+ );
7191
+ }
7192
+ });
7193
+ if (inputs.length) {
7194
+ style.transform = new FluidTransform(inputs, transforms);
7195
+ }
7196
+ super(style);
7197
+ }
7198
+ };
7199
+ var FluidTransform = class extends FluidValue {
7200
+ constructor(inputs, transforms) {
7201
+ super();
7202
+ this.inputs = inputs;
7203
+ this.transforms = transforms;
7204
+ this._value = null;
7205
+ }
7206
+ get() {
7207
+ return this._value || (this._value = this._get());
7208
+ }
7209
+ _get() {
7210
+ let transform = "";
7211
+ let identity2 = true;
7212
+ each(this.inputs, (input, i) => {
7213
+ const arg1 = getFluidValue(input[0]);
7214
+ const [t, id] = this.transforms[i](
7215
+ is.arr(arg1) ? arg1 : input.map(getFluidValue)
7216
+ );
7217
+ transform += " " + t;
7218
+ identity2 = identity2 && id;
7219
+ });
7220
+ return identity2 ? "none" : transform;
7221
+ }
7222
+ // Start observing our inputs once we have an observer.
7223
+ observerAdded(count) {
7224
+ if (count == 1)
7225
+ each(
7226
+ this.inputs,
7227
+ (input) => each(
7228
+ input,
7229
+ (value) => hasFluidValue(value) && addFluidObserver(value, this)
7230
+ )
7231
+ );
7232
+ }
7233
+ // Stop observing our inputs once we have no observers.
7234
+ observerRemoved(count) {
7235
+ if (count == 0)
7236
+ each(
7237
+ this.inputs,
7238
+ (input) => each(
7239
+ input,
7240
+ (value) => hasFluidValue(value) && removeFluidObserver(value, this)
7241
+ )
7242
+ );
7243
+ }
7244
+ eventObserved(event) {
7245
+ if (event.type == "change") {
7246
+ this._value = null;
7247
+ }
7248
+ callFluidObservers(this, event);
7249
+ }
7250
+ };
7251
+ var primitives = [
7252
+ "a",
7253
+ "abbr",
7254
+ "address",
7255
+ "area",
7256
+ "article",
7257
+ "aside",
7258
+ "audio",
7259
+ "b",
7260
+ "base",
7261
+ "bdi",
7262
+ "bdo",
7263
+ "big",
7264
+ "blockquote",
7265
+ "body",
7266
+ "br",
7267
+ "button",
7268
+ "canvas",
7269
+ "caption",
7270
+ "cite",
7271
+ "code",
7272
+ "col",
7273
+ "colgroup",
7274
+ "data",
7275
+ "datalist",
7276
+ "dd",
7277
+ "del",
7278
+ "details",
7279
+ "dfn",
7280
+ "dialog",
7281
+ "div",
7282
+ "dl",
7283
+ "dt",
7284
+ "em",
7285
+ "embed",
7286
+ "fieldset",
7287
+ "figcaption",
7288
+ "figure",
7289
+ "footer",
7290
+ "form",
7291
+ "h1",
7292
+ "h2",
7293
+ "h3",
7294
+ "h4",
7295
+ "h5",
7296
+ "h6",
7297
+ "head",
7298
+ "header",
7299
+ "hgroup",
7300
+ "hr",
7301
+ "html",
7302
+ "i",
7303
+ "iframe",
7304
+ "img",
7305
+ "input",
7306
+ "ins",
7307
+ "kbd",
7308
+ "keygen",
7309
+ "label",
7310
+ "legend",
7311
+ "li",
7312
+ "link",
7313
+ "main",
7314
+ "map",
7315
+ "mark",
7316
+ "menu",
7317
+ "menuitem",
7318
+ "meta",
7319
+ "meter",
7320
+ "nav",
7321
+ "noscript",
7322
+ "object",
7323
+ "ol",
7324
+ "optgroup",
7325
+ "option",
7326
+ "output",
7327
+ "p",
7328
+ "param",
7329
+ "picture",
7330
+ "pre",
7331
+ "progress",
7332
+ "q",
7333
+ "rp",
7334
+ "rt",
7335
+ "ruby",
7336
+ "s",
7337
+ "samp",
7338
+ "script",
7339
+ "section",
7340
+ "select",
7341
+ "small",
7342
+ "source",
7343
+ "span",
7344
+ "strong",
7345
+ "style",
7346
+ "sub",
7347
+ "summary",
7348
+ "sup",
7349
+ "table",
7350
+ "tbody",
7351
+ "td",
7352
+ "textarea",
7353
+ "tfoot",
7354
+ "th",
7355
+ "thead",
7356
+ "time",
7357
+ "title",
7358
+ "tr",
7359
+ "track",
7360
+ "u",
7361
+ "ul",
7362
+ "var",
7363
+ "video",
7364
+ "wbr",
7365
+ // SVG
7366
+ "circle",
7367
+ "clipPath",
7368
+ "defs",
7369
+ "ellipse",
7370
+ "foreignObject",
7371
+ "g",
7372
+ "image",
7373
+ "line",
7374
+ "linearGradient",
7375
+ "mask",
7376
+ "path",
7377
+ "pattern",
7378
+ "polygon",
7379
+ "polyline",
7380
+ "radialGradient",
7381
+ "rect",
7382
+ "stop",
7383
+ "svg",
7384
+ "text",
7385
+ "tspan"
7386
+ ];
7387
+ globals_exports.assign({
7388
+ batchedUpdates: reactDom.unstable_batchedUpdates,
7389
+ createStringInterpolator: createStringInterpolator2,
7390
+ colors: colors2
7391
+ });
7392
+ var host = createHost(primitives, {
7393
+ applyAnimatedValues,
7394
+ createAnimatedStyle: (style) => new AnimatedStyle(style),
7395
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
7396
+ getComponentProps: ({ scrollTop, scrollLeft, ...props }) => props
7397
+ });
7398
+ var animated = host.animated;
7399
+ const SNAP_TO_MAX_THRESHOLD = 5;
7400
+ const SNAP_TO_MIN_THRESHOLD = 100;
7401
+ const BOTTOM_SHEET_HANDLE_HEIGHT = 45;
7402
+ const INTERACTIVE_ELEMENTS = 'input, button, a, textarea, select, label, [role="button"], [onClick]';
7403
+ const SPRING_CONFIG = {
7404
+ up: {
7405
+ tension: 80,
7406
+ // 튕기기
7407
+ friction: 10,
7408
+ // 묵직함
7409
+ mass: 0.1,
7410
+ velocity: 0
7411
+ },
7412
+ down: {
7413
+ tension: 70,
7414
+ friction: 10,
7415
+ mass: 0.1,
7416
+ velocity: 0
7417
+ },
7418
+ moving: {
7419
+ tension: 600,
7420
+ friction: 30,
7421
+ mass: 0.1,
7422
+ velocity: 0.1
7423
+ }
7424
+ };
7425
+ const useBottomSheet = (props) => {
7426
+ const { isOpen, onOpen, onClose, snapPercent, expendOnContentDrag } = props;
7427
+ const bottomSheetRef = React.useRef(null);
7428
+ const contentRef = React.useRef(null);
7429
+ const metrics = React.useRef({
7430
+ initTouchPosition: null,
7431
+ initTransformValue: 0,
7432
+ canDragRef: true,
7433
+ maxTransformValue: 0,
7434
+ initialOpenHeightPx: 0
7435
+ });
7436
+ const [springs, api] = useSpring(() => ({
7437
+ transform: "translateY(0px)",
7438
+ config: SPRING_CONFIG.down
7439
+ }));
7440
+ const snapToMax = () => {
7441
+ const { maxTransformValue } = metrics.current;
7442
+ api.start({
7443
+ transform: `translateY(${maxTransformValue}px)`,
7444
+ config: SPRING_CONFIG.up
7445
+ });
7446
+ if (onOpen) onOpen();
7447
+ };
7448
+ const snapToMin = () => {
7449
+ api.start({
7450
+ transform: "translateY(0px)",
7451
+ config: SPRING_CONFIG.down
7452
+ });
7453
+ if (onClose) onClose();
7454
+ };
7455
+ const handleContentTouch = (e) => {
7456
+ const target = e.target;
7457
+ if (!target.matches(INTERACTIVE_ELEMENTS) && expendOnContentDrag) {
7458
+ metrics.current.canDragRef = true;
7459
+ } else {
7460
+ metrics.current.canDragRef = false;
7461
+ }
7462
+ };
7463
+ const handleStart = (clientY, e) => {
7464
+ if (!bottomSheetRef.current) {
7465
+ return;
7466
+ }
7467
+ const contentElement = contentRef.current;
7468
+ const target = e.target;
7469
+ if ((contentElement == null ? void 0 : contentElement.scrollTop) !== 0 && target.matches(INTERACTIVE_ELEMENTS)) {
7470
+ return;
7471
+ }
7472
+ const currentTransform = springs.transform.get();
7473
+ const initTransformValue = Number(
7474
+ currentTransform.replace("translateY(", "").replace("px)", "") || 0
7475
+ );
7476
+ metrics.current.initTransformValue = initTransformValue;
7477
+ metrics.current.initTouchPosition = clientY;
7478
+ };
7479
+ const handleMove = (clientY, e) => {
7480
+ var _a;
7481
+ const { initTouchPosition, initTransformValue, canDragRef, initialOpenHeightPx } = metrics.current;
7482
+ if (!initTouchPosition || !bottomSheetRef.current) return;
7483
+ const currTouchPosition = clientY;
7484
+ const yDiff = (initTouchPosition - currTouchPosition) * -1 + initTransformValue;
7485
+ const isMovingDown = initTransformValue < yDiff;
7486
+ if (!canDragRef && !(isMovingDown && ((_a = contentRef.current) == null ? void 0 : _a.scrollTop) === 0)) return;
7487
+ e.preventDefault();
7488
+ const currTopYOffset = yDiff * -1 + initialOpenHeightPx;
7489
+ const translateYOffset = window.innerHeight < currTopYOffset ? window.innerHeight * -1 + initialOpenHeightPx : yDiff;
7490
+ api.start({
7491
+ transform: `translateY(${translateYOffset}px)`,
7492
+ config: SPRING_CONFIG.moving
7493
+ });
7494
+ };
7495
+ const handleEnd = () => {
7496
+ const { initTouchPosition, initTransformValue } = metrics.current;
7497
+ if (!initTouchPosition || !bottomSheetRef.current) {
7498
+ return;
7499
+ }
7500
+ const currentTransform = springs.transform.get();
7501
+ const finalTransformValue = Number(
7502
+ currentTransform.replace("translateY(", "").replace("px)", "") || 0
7503
+ );
7504
+ const transformedDistance = initTransformValue - finalTransformValue;
7505
+ if (transformedDistance < 0 && SNAP_TO_MIN_THRESHOLD < Math.abs(transformedDistance)) {
7506
+ snapToMin();
7507
+ } else if (transformedDistance > 0 && SNAP_TO_MAX_THRESHOLD < Math.abs(transformedDistance)) {
7508
+ snapToMax();
7509
+ } else {
7510
+ const isMovingUp = finalTransformValue > initTransformValue;
7511
+ api.start({
7512
+ transform: `translateY(${initTransformValue}px)`,
7513
+ config: isMovingUp ? SPRING_CONFIG.up : SPRING_CONFIG.down
7514
+ });
7515
+ }
7516
+ metrics.current.canDragRef = true;
7517
+ metrics.current.initTouchPosition = null;
7518
+ };
7519
+ const handleTouch = {
7520
+ start: (e) => handleStart(e.touches[0].clientY, e),
7521
+ move: (e) => handleMove(e.touches[0].clientY, e),
7522
+ end: handleEnd
7523
+ };
7524
+ const handleMouse = {
7525
+ down: (e) => handleStart(e.clientY, e),
7526
+ move: (e) => handleMove(e.clientY, e),
7527
+ up: handleEnd,
7528
+ leave: handleEnd
7529
+ };
7530
+ React.useEffect(() => {
7531
+ if (isOpen) snapToMax();
7532
+ else snapToMin();
7533
+ const handleTouchMove = (e) => {
7534
+ if (bottomSheetRef.current && !bottomSheetRef.current.contains(e.target)) {
7535
+ e.preventDefault();
7536
+ }
7537
+ };
7538
+ if (isOpen) {
7539
+ document.addEventListener("touchmove", handleTouchMove, { passive: false });
7540
+ } else {
7541
+ document.removeEventListener("touchmove", handleTouchMove);
7542
+ }
7543
+ return () => {
7544
+ document.removeEventListener("touchmove", handleTouchMove);
7545
+ };
7546
+ }, [isOpen]);
7547
+ React.useEffect(() => {
7548
+ const bottomSheetElement = bottomSheetRef.current;
7549
+ const contentElement = contentRef.current;
7550
+ metrics.current.initialOpenHeightPx = window.innerHeight * (snapPercent.min > 1 ? 1 : snapPercent.min);
7551
+ if (snapPercent.max === "INNER_HEIGHT" && contentElement) {
7552
+ metrics.current.maxTransformValue = (contentElement.clientHeight - BOTTOM_SHEET_HANDLE_HEIGHT) * -1;
7553
+ } else if (typeof snapPercent.max === "number") {
7554
+ metrics.current.maxTransformValue = (window.innerHeight - metrics.current.initialOpenHeightPx) * (snapPercent.max > 1 ? 1 : snapPercent.max) * -1;
7555
+ }
7556
+ bottomSheetElement == null ? void 0 : bottomSheetElement.addEventListener("touchstart", handleTouch.start);
7557
+ bottomSheetElement == null ? void 0 : bottomSheetElement.addEventListener("touchmove", handleTouch.move);
7558
+ bottomSheetElement == null ? void 0 : bottomSheetElement.addEventListener("touchend", handleTouch.end);
7559
+ bottomSheetElement == null ? void 0 : bottomSheetElement.addEventListener("mousedown", handleMouse.down);
7560
+ bottomSheetElement == null ? void 0 : bottomSheetElement.addEventListener("mousemove", handleMouse.move);
7561
+ bottomSheetElement == null ? void 0 : bottomSheetElement.addEventListener("mouseup", handleMouse.up);
7562
+ bottomSheetElement == null ? void 0 : bottomSheetElement.addEventListener("mouseleave", handleMouse.leave);
7563
+ contentElement == null ? void 0 : contentElement.addEventListener("touchstart", handleContentTouch);
7564
+ contentElement == null ? void 0 : contentElement.addEventListener("mousedown", handleContentTouch);
7565
+ return () => {
7566
+ bottomSheetElement == null ? void 0 : bottomSheetElement.removeEventListener("touchstart", handleTouch.start);
7567
+ bottomSheetElement == null ? void 0 : bottomSheetElement.removeEventListener("touchmove", handleTouch.move);
7568
+ bottomSheetElement == null ? void 0 : bottomSheetElement.removeEventListener("touchend", handleTouch.end);
7569
+ bottomSheetElement == null ? void 0 : bottomSheetElement.removeEventListener("mousedown", handleMouse.down);
7570
+ bottomSheetElement == null ? void 0 : bottomSheetElement.removeEventListener("mousemove", handleMouse.move);
7571
+ bottomSheetElement == null ? void 0 : bottomSheetElement.removeEventListener("mouseup", handleMouse.up);
7572
+ bottomSheetElement == null ? void 0 : bottomSheetElement.removeEventListener("mouseleave", handleMouse.leave);
7573
+ contentElement == null ? void 0 : contentElement.removeEventListener("touchstart", handleContentTouch);
7574
+ contentElement == null ? void 0 : contentElement.removeEventListener("mousedown", handleContentTouch);
7575
+ };
7576
+ }, []);
7577
+ return { bottomSheetRef, contentRef, snapToMax, snapToMin, springs };
7578
+ };
7579
+ const DEFAULT_MIN_SNAP = 0;
7580
+ const DEFAULT_MAX_SNAP = "INNER_HEIGHT";
7581
+ const DEFAULT_BACKDROP_OPACITY = 0.5;
7582
+ const BottomSheetFrame = React.forwardRef(
7583
+ ({ children, className, initialOpenHeightPx, springs }, ref) => {
7584
+ return /* @__PURE__ */ jsxRuntime.jsx(
7585
+ animated.section,
7586
+ {
7587
+ ref,
7588
+ className: cx(css$1({
7589
+ position: "fixed",
7590
+ touchAction: "pan-y",
7591
+ display: "flex",
7592
+ flexDirection: "column",
7593
+ width: "100%",
7594
+ pointerEvents: "auto",
7595
+ // 제스처 이벤트 허용
7596
+ overflow: "hidden",
7597
+ borderRadius: "40px 40px 0 0",
7598
+ height: "100%",
7599
+ zIndex: 999,
7600
+ backgroundColor: "#ffffff",
7601
+ shadow: "0 -15px 15px 0px rgba(0, 0, 0, 0.05)",
7602
+ willChange: "auto"
7603
+ }), className),
7604
+ style: {
7605
+ bottom: `calc(${initialOpenHeightPx}px - 100dvh)`,
7606
+ transform: springs.transform
7607
+ },
7608
+ children
7609
+ }
7610
+ );
7611
+ }
7612
+ );
7613
+ const Backdrop = React.forwardRef(({ onBackdropClick, isBackdropOpen, opacity: bgOpacity }, ref) => {
7614
+ const [springs] = useSpring(() => ({
7615
+ from: { opacity: 0 },
7616
+ to: { opacity: isBackdropOpen ? 1 : 0 },
7617
+ config: {
7618
+ tension: 200,
7619
+ friction: 25,
7620
+ mass: 0.8
7621
+ }
7622
+ }), [isBackdropOpen]);
7623
+ return /* @__PURE__ */ jsxRuntime.jsx(
7624
+ animated.div,
7625
+ {
7626
+ className: css$1({
7627
+ zIndex: 99,
7628
+ position: "fixed",
7629
+ top: 0,
7630
+ width: "100%",
7631
+ height: "100dvh",
7632
+ willChange: "opacity",
7633
+ overflow: "hidden",
7634
+ touchAction: "none"
7635
+ }),
7636
+ style: {
7637
+ backgroundColor: springs.opacity.to((o) => `rgba(0, 0, 0, ${o * bgOpacity})`),
7638
+ opacity: springs.opacity,
7639
+ visibility: isBackdropOpen ? "visible" : "hidden"
7640
+ },
7641
+ onClick: () => onBackdropClick(),
7642
+ ref
7643
+ }
7644
+ );
7645
+ });
7646
+ const BottomSheetHandle = () => /* @__PURE__ */ jsxRuntime.jsx("div", { className: css$1({ margin: "22px auto", height: 1.5, minHeight: 1.5, width: "45px", borderRadius: 999, background: "#bebebe" }) });
7647
+ const BottomSheet = (props) => {
7648
+ const { isOpen = true, onClose, onOpen, children, className = "", snapPercent, bgBlocking = true, backdropOpacity = DEFAULT_BACKDROP_OPACITY, hideHandle = false, expendOnContentDrag = false } = props;
7649
+ const { bottomSheetRef, contentRef, snapToMin, springs } = useBottomSheet({
7650
+ isOpen,
7651
+ onOpen,
7652
+ onClose,
7653
+ snapPercent: {
7654
+ min: (snapPercent == null ? void 0 : snapPercent.min) ?? DEFAULT_MIN_SNAP,
7655
+ max: (snapPercent == null ? void 0 : snapPercent.max) ?? DEFAULT_MAX_SNAP
7656
+ },
7657
+ expendOnContentDrag
7658
+ });
7659
+ const [initialOpenHeightPx, setInitialOpenHeightPx] = React.useState(DEFAULT_MIN_SNAP);
7660
+ React.useEffect(() => {
7661
+ if (snapPercent == null ? void 0 : snapPercent.min) setInitialOpenHeightPx(window.innerHeight * (snapPercent == null ? void 0 : snapPercent.min));
7662
+ }, [snapPercent == null ? void 0 : snapPercent.min]);
7663
+ return /* @__PURE__ */ jsxRuntime.jsxs(animated.div, { children: [
7664
+ bgBlocking && /* @__PURE__ */ jsxRuntime.jsx(Backdrop, { isBackdropOpen: isOpen, opacity: backdropOpacity, onBackdropClick: () => snapToMin() }),
7665
+ /* @__PURE__ */ jsxRuntime.jsxs(
7666
+ BottomSheetFrame,
7667
+ {
7668
+ ref: bottomSheetRef,
7669
+ className,
7670
+ springs,
7671
+ initialOpenHeightPx,
7672
+ children: [
7673
+ !hideHandle && /* @__PURE__ */ jsxRuntime.jsx(BottomSheetHandle, {}),
7674
+ /* @__PURE__ */ jsxRuntime.jsx("section", { ref: contentRef, className: css$1({ overflowY: "auto" }), children })
7675
+ ]
7676
+ }
7677
+ )
7678
+ ] });
7679
+ };
7680
+ BottomSheetFrame.displayName = "BottomSheetFrame";
7681
+ Backdrop.displayName = "Backdrop";
4049
7682
  function definePreset(preset2) {
4050
7683
  return preset2;
4051
7684
  }
@@ -4346,6 +7979,7 @@ const preset = definePreset({
4346
7979
  }
4347
7980
  }
4348
7981
  });
7982
+ exports.BottomSheet = BottomSheet;
4349
7983
  exports.Button = Button;
4350
7984
  exports.Dialog = Dialog;
4351
7985
  exports.IconButton = IconButton;