infinity-ui-elements 1.14.21 → 1.15.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.js CHANGED
@@ -8,7 +8,7 @@ var reactSpinners = require('react-spinners');
8
8
  var clsx = require('clsx');
9
9
  var tailwindMerge = require('tailwind-merge');
10
10
  var lucideReact = require('lucide-react');
11
- var reactDom = require('react-dom');
11
+ var ReactDOM = require('react-dom');
12
12
  var Calendar = require('react-calendar');
13
13
  require('react-calendar/dist/Calendar.css');
14
14
  var reactTable = require('@tanstack/react-table');
@@ -31,6 +31,7 @@ function _interopNamespaceDefault(e) {
31
31
  }
32
32
 
33
33
  var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
34
+ var ReactDOM__namespace = /*#__PURE__*/_interopNamespaceDefault(ReactDOM);
34
35
 
35
36
  /**
36
37
  * ==============================================
@@ -1270,7 +1271,7 @@ const badgeVariants = classVarianceAuthority.cva("inline-flex items-center white
1270
1271
  size: "medium",
1271
1272
  },
1272
1273
  });
1273
- const Badge = React__namespace.forwardRef(({ className, variant, size, color, showDot = false, children, ...props }, ref) => {
1274
+ const Badge = React__namespace.forwardRef(({ className, variant, size, color, showDot = false, leadingIcon, trailingIcon, children, ...props }, ref) => {
1274
1275
  const getDotColor = () => {
1275
1276
  if (variant === "filled") {
1276
1277
  return "bg-action-ink-on-primary-normal";
@@ -1302,7 +1303,7 @@ const Badge = React__namespace.forwardRef(({ className, variant, size, color, sh
1302
1303
  }
1303
1304
  return "h-3 w-3";
1304
1305
  };
1305
- return (jsxRuntime.jsxs("div", { ref: ref, className: cn(badgeVariants({ variant, size, color }), className), ...props, children: [showDot && (jsxRuntime.jsx("span", { className: cn("rounded-full", getDotColor(), getDotSize()), "aria-hidden": "true" })), children] }));
1306
+ return (jsxRuntime.jsxs("div", { ref: ref, className: cn(badgeVariants({ variant, size, color }), className), ...props, children: [showDot && (jsxRuntime.jsx("span", { className: cn("rounded-full", getDotColor(), getDotSize()), "aria-hidden": "true" })), leadingIcon && jsxRuntime.jsx("span", { className: "inline-flex", children: leadingIcon }), children, trailingIcon && jsxRuntime.jsx("span", { className: "inline-flex", children: trailingIcon })] }));
1306
1307
  });
1307
1308
  Badge.displayName = "Badge";
1308
1309
 
@@ -1964,233 +1965,3403 @@ const Counter = React__namespace.forwardRef(({ value, max, size = "medium", colo
1964
1965
  });
1965
1966
  Counter.displayName = "Counter";
1966
1967
 
1967
- const tooltipVariants = classVarianceAuthority.cva("fixed z-50 bg-popup-fill-intense text-action-ink-on-primary-normal rounded-medium border border-popup-outline-subtle flex flex-col p-4 rounded-xlarge min-w-[200px] max-w-[300px] transition-opacity duration-200", {
1968
- variants: {
1969
- isVisible: {
1970
- true: "opacity-100 pointer-events-auto shadow-[0_4px_20px_rgba(0,0,0,0.15)]",
1971
- false: "opacity-0 pointer-events-none",
1972
- },
1973
- },
1974
- defaultVariants: {
1975
- isVisible: false,
1968
+ // src/primitive.tsx
1969
+ function composeEventHandlers(originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) {
1970
+ return function handleEvent(event) {
1971
+ originalEventHandler?.(event);
1972
+ if (checkForDefaultPrevented === false || !event.defaultPrevented) {
1973
+ return ourEventHandler?.(event);
1974
+ }
1975
+ };
1976
+ }
1977
+
1978
+ // packages/react/context/src/create-context.tsx
1979
+ function createContextScope(scopeName, createContextScopeDeps = []) {
1980
+ let defaultContexts = [];
1981
+ function createContext3(rootComponentName, defaultContext) {
1982
+ const BaseContext = React__namespace.createContext(defaultContext);
1983
+ const index = defaultContexts.length;
1984
+ defaultContexts = [...defaultContexts, defaultContext];
1985
+ const Provider = (props) => {
1986
+ const { scope, children, ...context } = props;
1987
+ const Context = scope?.[scopeName]?.[index] || BaseContext;
1988
+ const value = React__namespace.useMemo(() => context, Object.values(context));
1989
+ return /* @__PURE__ */ jsxRuntime.jsx(Context.Provider, { value, children });
1990
+ };
1991
+ Provider.displayName = rootComponentName + "Provider";
1992
+ function useContext2(consumerName, scope) {
1993
+ const Context = scope?.[scopeName]?.[index] || BaseContext;
1994
+ const context = React__namespace.useContext(Context);
1995
+ if (context) return context;
1996
+ if (defaultContext !== void 0) return defaultContext;
1997
+ throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
1998
+ }
1999
+ return [Provider, useContext2];
2000
+ }
2001
+ const createScope = () => {
2002
+ const scopeContexts = defaultContexts.map((defaultContext) => {
2003
+ return React__namespace.createContext(defaultContext);
2004
+ });
2005
+ return function useScope(scope) {
2006
+ const contexts = scope?.[scopeName] || scopeContexts;
2007
+ return React__namespace.useMemo(
2008
+ () => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),
2009
+ [scope, contexts]
2010
+ );
2011
+ };
2012
+ };
2013
+ createScope.scopeName = scopeName;
2014
+ return [createContext3, composeContextScopes(createScope, ...createContextScopeDeps)];
2015
+ }
2016
+ function composeContextScopes(...scopes) {
2017
+ const baseScope = scopes[0];
2018
+ if (scopes.length === 1) return baseScope;
2019
+ const createScope = () => {
2020
+ const scopeHooks = scopes.map((createScope2) => ({
2021
+ useScope: createScope2(),
2022
+ scopeName: createScope2.scopeName
2023
+ }));
2024
+ return function useComposedScopes(overrideScopes) {
2025
+ const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
2026
+ const scopeProps = useScope(overrideScopes);
2027
+ const currentScope = scopeProps[`__scope${scopeName}`];
2028
+ return { ...nextScopes2, ...currentScope };
2029
+ }, {});
2030
+ return React__namespace.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
2031
+ };
2032
+ };
2033
+ createScope.scopeName = baseScope.scopeName;
2034
+ return createScope;
2035
+ }
2036
+
2037
+ // packages/react/use-layout-effect/src/use-layout-effect.tsx
2038
+ var useLayoutEffect2 = globalThis?.document ? React__namespace.useLayoutEffect : () => {
2039
+ };
2040
+
2041
+ // src/use-controllable-state.tsx
2042
+ var useInsertionEffect = React__namespace[" useInsertionEffect ".trim().toString()] || useLayoutEffect2;
2043
+ function useControllableState({
2044
+ prop,
2045
+ defaultProp,
2046
+ onChange = () => {
2047
+ },
2048
+ caller
2049
+ }) {
2050
+ const [uncontrolledProp, setUncontrolledProp, onChangeRef] = useUncontrolledState({
2051
+ defaultProp,
2052
+ onChange
2053
+ });
2054
+ const isControlled = prop !== void 0;
2055
+ const value = isControlled ? prop : uncontrolledProp;
2056
+ {
2057
+ const isControlledRef = React__namespace.useRef(prop !== void 0);
2058
+ React__namespace.useEffect(() => {
2059
+ const wasControlled = isControlledRef.current;
2060
+ if (wasControlled !== isControlled) {
2061
+ const from = wasControlled ? "controlled" : "uncontrolled";
2062
+ const to = isControlled ? "controlled" : "uncontrolled";
2063
+ console.warn(
2064
+ `${caller} is changing from ${from} to ${to}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`
2065
+ );
2066
+ }
2067
+ isControlledRef.current = isControlled;
2068
+ }, [isControlled, caller]);
2069
+ }
2070
+ const setValue = React__namespace.useCallback(
2071
+ (nextValue) => {
2072
+ if (isControlled) {
2073
+ const value2 = isFunction(nextValue) ? nextValue(prop) : nextValue;
2074
+ if (value2 !== prop) {
2075
+ onChangeRef.current?.(value2);
2076
+ }
2077
+ } else {
2078
+ setUncontrolledProp(nextValue);
2079
+ }
1976
2080
  },
2081
+ [isControlled, prop, setUncontrolledProp, onChangeRef]
2082
+ );
2083
+ return [value, setValue];
2084
+ }
2085
+ function useUncontrolledState({
2086
+ defaultProp,
2087
+ onChange
2088
+ }) {
2089
+ const [value, setValue] = React__namespace.useState(defaultProp);
2090
+ const prevValueRef = React__namespace.useRef(value);
2091
+ const onChangeRef = React__namespace.useRef(onChange);
2092
+ useInsertionEffect(() => {
2093
+ onChangeRef.current = onChange;
2094
+ }, [onChange]);
2095
+ React__namespace.useEffect(() => {
2096
+ if (prevValueRef.current !== value) {
2097
+ onChangeRef.current?.(value);
2098
+ prevValueRef.current = value;
2099
+ }
2100
+ }, [value, prevValueRef]);
2101
+ return [value, setValue, onChangeRef];
2102
+ }
2103
+ function isFunction(value) {
2104
+ return typeof value === "function";
2105
+ }
2106
+
2107
+ // packages/react/compose-refs/src/compose-refs.tsx
2108
+ function setRef(ref, value) {
2109
+ if (typeof ref === "function") {
2110
+ return ref(value);
2111
+ } else if (ref !== null && ref !== void 0) {
2112
+ ref.current = value;
2113
+ }
2114
+ }
2115
+ function composeRefs(...refs) {
2116
+ return (node) => {
2117
+ let hasCleanup = false;
2118
+ const cleanups = refs.map((ref) => {
2119
+ const cleanup = setRef(ref, node);
2120
+ if (!hasCleanup && typeof cleanup == "function") {
2121
+ hasCleanup = true;
2122
+ }
2123
+ return cleanup;
2124
+ });
2125
+ if (hasCleanup) {
2126
+ return () => {
2127
+ for (let i = 0; i < cleanups.length; i++) {
2128
+ const cleanup = cleanups[i];
2129
+ if (typeof cleanup == "function") {
2130
+ cleanup();
2131
+ } else {
2132
+ setRef(refs[i], null);
2133
+ }
2134
+ }
2135
+ };
2136
+ }
2137
+ };
2138
+ }
2139
+ function useComposedRefs(...refs) {
2140
+ return React__namespace.useCallback(composeRefs(...refs), refs);
2141
+ }
2142
+
2143
+ /**
2144
+ * Custom positioning reference element.
2145
+ * @see https://floating-ui.com/docs/virtual-elements
2146
+ */
2147
+
2148
+ const sides = ['top', 'right', 'bottom', 'left'];
2149
+ const min = Math.min;
2150
+ const max = Math.max;
2151
+ const round = Math.round;
2152
+ const floor = Math.floor;
2153
+ const createCoords = v => ({
2154
+ x: v,
2155
+ y: v
1977
2156
  });
1978
- const tooltipArrowVariants = classVarianceAuthority.cva("absolute w-0 h-0 border-solid border-[6px] -translate-x-1/2", {
1979
- variants: {
1980
- placement: {
1981
- "top-start": "top-full border-t-popup-fill-intense border-x-transparent border-b-transparent",
1982
- top: "top-full border-t-popup-fill-intense border-x-transparent border-b-transparent",
1983
- "top-end": "top-full border-t-popup-fill-intense border-x-transparent border-b-transparent",
1984
- "bottom-start": "bottom-full border-b-popup-fill-intense border-x-transparent border-t-transparent",
1985
- bottom: "bottom-full border-b-popup-fill-intense border-x-transparent border-t-transparent",
1986
- "bottom-end": "bottom-full border-b-popup-fill-intense border-x-transparent border-t-transparent",
1987
- },
1988
- },
1989
- defaultVariants: {
1990
- placement: "top",
1991
- },
2157
+ const oppositeSideMap = {
2158
+ left: 'right',
2159
+ right: 'left',
2160
+ bottom: 'top',
2161
+ top: 'bottom'
2162
+ };
2163
+ function clamp(start, value, end) {
2164
+ return max(start, min(value, end));
2165
+ }
2166
+ function evaluate(value, param) {
2167
+ return typeof value === 'function' ? value(param) : value;
2168
+ }
2169
+ function getSide(placement) {
2170
+ return placement.split('-')[0];
2171
+ }
2172
+ function getAlignment(placement) {
2173
+ return placement.split('-')[1];
2174
+ }
2175
+ function getOppositeAxis(axis) {
2176
+ return axis === 'x' ? 'y' : 'x';
2177
+ }
2178
+ function getAxisLength(axis) {
2179
+ return axis === 'y' ? 'height' : 'width';
2180
+ }
2181
+ function getSideAxis(placement) {
2182
+ const firstChar = placement[0];
2183
+ return firstChar === 't' || firstChar === 'b' ? 'y' : 'x';
2184
+ }
2185
+ function getAlignmentAxis(placement) {
2186
+ return getOppositeAxis(getSideAxis(placement));
2187
+ }
2188
+ function getAlignmentSides(placement, rects, rtl) {
2189
+ if (rtl === void 0) {
2190
+ rtl = false;
2191
+ }
2192
+ const alignment = getAlignment(placement);
2193
+ const alignmentAxis = getAlignmentAxis(placement);
2194
+ const length = getAxisLength(alignmentAxis);
2195
+ let mainAlignmentSide = alignmentAxis === 'x' ? alignment === (rtl ? 'end' : 'start') ? 'right' : 'left' : alignment === 'start' ? 'bottom' : 'top';
2196
+ if (rects.reference[length] > rects.floating[length]) {
2197
+ mainAlignmentSide = getOppositePlacement(mainAlignmentSide);
2198
+ }
2199
+ return [mainAlignmentSide, getOppositePlacement(mainAlignmentSide)];
2200
+ }
2201
+ function getExpandedPlacements(placement) {
2202
+ const oppositePlacement = getOppositePlacement(placement);
2203
+ return [getOppositeAlignmentPlacement(placement), oppositePlacement, getOppositeAlignmentPlacement(oppositePlacement)];
2204
+ }
2205
+ function getOppositeAlignmentPlacement(placement) {
2206
+ return placement.includes('start') ? placement.replace('start', 'end') : placement.replace('end', 'start');
2207
+ }
2208
+ const lrPlacement = ['left', 'right'];
2209
+ const rlPlacement = ['right', 'left'];
2210
+ const tbPlacement = ['top', 'bottom'];
2211
+ const btPlacement = ['bottom', 'top'];
2212
+ function getSideList(side, isStart, rtl) {
2213
+ switch (side) {
2214
+ case 'top':
2215
+ case 'bottom':
2216
+ if (rtl) return isStart ? rlPlacement : lrPlacement;
2217
+ return isStart ? lrPlacement : rlPlacement;
2218
+ case 'left':
2219
+ case 'right':
2220
+ return isStart ? tbPlacement : btPlacement;
2221
+ default:
2222
+ return [];
2223
+ }
2224
+ }
2225
+ function getOppositeAxisPlacements(placement, flipAlignment, direction, rtl) {
2226
+ const alignment = getAlignment(placement);
2227
+ let list = getSideList(getSide(placement), direction === 'start', rtl);
2228
+ if (alignment) {
2229
+ list = list.map(side => side + "-" + alignment);
2230
+ if (flipAlignment) {
2231
+ list = list.concat(list.map(getOppositeAlignmentPlacement));
2232
+ }
2233
+ }
2234
+ return list;
2235
+ }
2236
+ function getOppositePlacement(placement) {
2237
+ const side = getSide(placement);
2238
+ return oppositeSideMap[side] + placement.slice(side.length);
2239
+ }
2240
+ function expandPaddingObject(padding) {
2241
+ return {
2242
+ top: 0,
2243
+ right: 0,
2244
+ bottom: 0,
2245
+ left: 0,
2246
+ ...padding
2247
+ };
2248
+ }
2249
+ function getPaddingObject(padding) {
2250
+ return typeof padding !== 'number' ? expandPaddingObject(padding) : {
2251
+ top: padding,
2252
+ right: padding,
2253
+ bottom: padding,
2254
+ left: padding
2255
+ };
2256
+ }
2257
+ function rectToClientRect(rect) {
2258
+ const {
2259
+ x,
2260
+ y,
2261
+ width,
2262
+ height
2263
+ } = rect;
2264
+ return {
2265
+ width,
2266
+ height,
2267
+ top: y,
2268
+ left: x,
2269
+ right: x + width,
2270
+ bottom: y + height,
2271
+ x,
2272
+ y
2273
+ };
2274
+ }
2275
+
2276
+ function computeCoordsFromPlacement(_ref, placement, rtl) {
2277
+ let {
2278
+ reference,
2279
+ floating
2280
+ } = _ref;
2281
+ const sideAxis = getSideAxis(placement);
2282
+ const alignmentAxis = getAlignmentAxis(placement);
2283
+ const alignLength = getAxisLength(alignmentAxis);
2284
+ const side = getSide(placement);
2285
+ const isVertical = sideAxis === 'y';
2286
+ const commonX = reference.x + reference.width / 2 - floating.width / 2;
2287
+ const commonY = reference.y + reference.height / 2 - floating.height / 2;
2288
+ const commonAlign = reference[alignLength] / 2 - floating[alignLength] / 2;
2289
+ let coords;
2290
+ switch (side) {
2291
+ case 'top':
2292
+ coords = {
2293
+ x: commonX,
2294
+ y: reference.y - floating.height
2295
+ };
2296
+ break;
2297
+ case 'bottom':
2298
+ coords = {
2299
+ x: commonX,
2300
+ y: reference.y + reference.height
2301
+ };
2302
+ break;
2303
+ case 'right':
2304
+ coords = {
2305
+ x: reference.x + reference.width,
2306
+ y: commonY
2307
+ };
2308
+ break;
2309
+ case 'left':
2310
+ coords = {
2311
+ x: reference.x - floating.width,
2312
+ y: commonY
2313
+ };
2314
+ break;
2315
+ default:
2316
+ coords = {
2317
+ x: reference.x,
2318
+ y: reference.y
2319
+ };
2320
+ }
2321
+ switch (getAlignment(placement)) {
2322
+ case 'start':
2323
+ coords[alignmentAxis] -= commonAlign * (rtl && isVertical ? -1 : 1);
2324
+ break;
2325
+ case 'end':
2326
+ coords[alignmentAxis] += commonAlign * (rtl && isVertical ? -1 : 1);
2327
+ break;
2328
+ }
2329
+ return coords;
2330
+ }
2331
+
2332
+ /**
2333
+ * Resolves with an object of overflow side offsets that determine how much the
2334
+ * element is overflowing a given clipping boundary on each side.
2335
+ * - positive = overflowing the boundary by that number of pixels
2336
+ * - negative = how many pixels left before it will overflow
2337
+ * - 0 = lies flush with the boundary
2338
+ * @see https://floating-ui.com/docs/detectOverflow
2339
+ */
2340
+ async function detectOverflow(state, options) {
2341
+ var _await$platform$isEle;
2342
+ if (options === void 0) {
2343
+ options = {};
2344
+ }
2345
+ const {
2346
+ x,
2347
+ y,
2348
+ platform,
2349
+ rects,
2350
+ elements,
2351
+ strategy
2352
+ } = state;
2353
+ const {
2354
+ boundary = 'clippingAncestors',
2355
+ rootBoundary = 'viewport',
2356
+ elementContext = 'floating',
2357
+ altBoundary = false,
2358
+ padding = 0
2359
+ } = evaluate(options, state);
2360
+ const paddingObject = getPaddingObject(padding);
2361
+ const altContext = elementContext === 'floating' ? 'reference' : 'floating';
2362
+ const element = elements[altBoundary ? altContext : elementContext];
2363
+ const clippingClientRect = rectToClientRect(await platform.getClippingRect({
2364
+ element: ((_await$platform$isEle = await (platform.isElement == null ? void 0 : platform.isElement(element))) != null ? _await$platform$isEle : true) ? element : element.contextElement || (await (platform.getDocumentElement == null ? void 0 : platform.getDocumentElement(elements.floating))),
2365
+ boundary,
2366
+ rootBoundary,
2367
+ strategy
2368
+ }));
2369
+ const rect = elementContext === 'floating' ? {
2370
+ x,
2371
+ y,
2372
+ width: rects.floating.width,
2373
+ height: rects.floating.height
2374
+ } : rects.reference;
2375
+ const offsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(elements.floating));
2376
+ const offsetScale = (await (platform.isElement == null ? void 0 : platform.isElement(offsetParent))) ? (await (platform.getScale == null ? void 0 : platform.getScale(offsetParent))) || {
2377
+ x: 1,
2378
+ y: 1
2379
+ } : {
2380
+ x: 1,
2381
+ y: 1
2382
+ };
2383
+ const elementClientRect = rectToClientRect(platform.convertOffsetParentRelativeRectToViewportRelativeRect ? await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
2384
+ elements,
2385
+ rect,
2386
+ offsetParent,
2387
+ strategy
2388
+ }) : rect);
2389
+ return {
2390
+ top: (clippingClientRect.top - elementClientRect.top + paddingObject.top) / offsetScale.y,
2391
+ bottom: (elementClientRect.bottom - clippingClientRect.bottom + paddingObject.bottom) / offsetScale.y,
2392
+ left: (clippingClientRect.left - elementClientRect.left + paddingObject.left) / offsetScale.x,
2393
+ right: (elementClientRect.right - clippingClientRect.right + paddingObject.right) / offsetScale.x
2394
+ };
2395
+ }
2396
+
2397
+ // Maximum number of resets that can occur before bailing to avoid infinite reset loops.
2398
+ const MAX_RESET_COUNT = 50;
2399
+
2400
+ /**
2401
+ * Computes the `x` and `y` coordinates that will place the floating element
2402
+ * next to a given reference element.
2403
+ *
2404
+ * This export does not have any `platform` interface logic. You will need to
2405
+ * write one for the platform you are using Floating UI with.
2406
+ */
2407
+ const computePosition$1 = async (reference, floating, config) => {
2408
+ const {
2409
+ placement = 'bottom',
2410
+ strategy = 'absolute',
2411
+ middleware = [],
2412
+ platform
2413
+ } = config;
2414
+ const platformWithDetectOverflow = platform.detectOverflow ? platform : {
2415
+ ...platform,
2416
+ detectOverflow
2417
+ };
2418
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(floating));
2419
+ let rects = await platform.getElementRects({
2420
+ reference,
2421
+ floating,
2422
+ strategy
2423
+ });
2424
+ let {
2425
+ x,
2426
+ y
2427
+ } = computeCoordsFromPlacement(rects, placement, rtl);
2428
+ let statefulPlacement = placement;
2429
+ let resetCount = 0;
2430
+ const middlewareData = {};
2431
+ for (let i = 0; i < middleware.length; i++) {
2432
+ const currentMiddleware = middleware[i];
2433
+ if (!currentMiddleware) {
2434
+ continue;
2435
+ }
2436
+ const {
2437
+ name,
2438
+ fn
2439
+ } = currentMiddleware;
2440
+ const {
2441
+ x: nextX,
2442
+ y: nextY,
2443
+ data,
2444
+ reset
2445
+ } = await fn({
2446
+ x,
2447
+ y,
2448
+ initialPlacement: placement,
2449
+ placement: statefulPlacement,
2450
+ strategy,
2451
+ middlewareData,
2452
+ rects,
2453
+ platform: platformWithDetectOverflow,
2454
+ elements: {
2455
+ reference,
2456
+ floating
2457
+ }
2458
+ });
2459
+ x = nextX != null ? nextX : x;
2460
+ y = nextY != null ? nextY : y;
2461
+ middlewareData[name] = {
2462
+ ...middlewareData[name],
2463
+ ...data
2464
+ };
2465
+ if (reset && resetCount < MAX_RESET_COUNT) {
2466
+ resetCount++;
2467
+ if (typeof reset === 'object') {
2468
+ if (reset.placement) {
2469
+ statefulPlacement = reset.placement;
2470
+ }
2471
+ if (reset.rects) {
2472
+ rects = reset.rects === true ? await platform.getElementRects({
2473
+ reference,
2474
+ floating,
2475
+ strategy
2476
+ }) : reset.rects;
2477
+ }
2478
+ ({
2479
+ x,
2480
+ y
2481
+ } = computeCoordsFromPlacement(rects, statefulPlacement, rtl));
2482
+ }
2483
+ i = -1;
2484
+ }
2485
+ }
2486
+ return {
2487
+ x,
2488
+ y,
2489
+ placement: statefulPlacement,
2490
+ strategy,
2491
+ middlewareData
2492
+ };
2493
+ };
2494
+
2495
+ /**
2496
+ * Provides data to position an inner element of the floating element so that it
2497
+ * appears centered to the reference element.
2498
+ * @see https://floating-ui.com/docs/arrow
2499
+ */
2500
+ const arrow$3 = options => ({
2501
+ name: 'arrow',
2502
+ options,
2503
+ async fn(state) {
2504
+ const {
2505
+ x,
2506
+ y,
2507
+ placement,
2508
+ rects,
2509
+ platform,
2510
+ elements,
2511
+ middlewareData
2512
+ } = state;
2513
+ // Since `element` is required, we don't Partial<> the type.
2514
+ const {
2515
+ element,
2516
+ padding = 0
2517
+ } = evaluate(options, state) || {};
2518
+ if (element == null) {
2519
+ return {};
2520
+ }
2521
+ const paddingObject = getPaddingObject(padding);
2522
+ const coords = {
2523
+ x,
2524
+ y
2525
+ };
2526
+ const axis = getAlignmentAxis(placement);
2527
+ const length = getAxisLength(axis);
2528
+ const arrowDimensions = await platform.getDimensions(element);
2529
+ const isYAxis = axis === 'y';
2530
+ const minProp = isYAxis ? 'top' : 'left';
2531
+ const maxProp = isYAxis ? 'bottom' : 'right';
2532
+ const clientProp = isYAxis ? 'clientHeight' : 'clientWidth';
2533
+ const endDiff = rects.reference[length] + rects.reference[axis] - coords[axis] - rects.floating[length];
2534
+ const startDiff = coords[axis] - rects.reference[axis];
2535
+ const arrowOffsetParent = await (platform.getOffsetParent == null ? void 0 : platform.getOffsetParent(element));
2536
+ let clientSize = arrowOffsetParent ? arrowOffsetParent[clientProp] : 0;
2537
+
2538
+ // DOM platform can return `window` as the `offsetParent`.
2539
+ if (!clientSize || !(await (platform.isElement == null ? void 0 : platform.isElement(arrowOffsetParent)))) {
2540
+ clientSize = elements.floating[clientProp] || rects.floating[length];
2541
+ }
2542
+ const centerToReference = endDiff / 2 - startDiff / 2;
2543
+
2544
+ // If the padding is large enough that it causes the arrow to no longer be
2545
+ // centered, modify the padding so that it is centered.
2546
+ const largestPossiblePadding = clientSize / 2 - arrowDimensions[length] / 2 - 1;
2547
+ const minPadding = min(paddingObject[minProp], largestPossiblePadding);
2548
+ const maxPadding = min(paddingObject[maxProp], largestPossiblePadding);
2549
+
2550
+ // Make sure the arrow doesn't overflow the floating element if the center
2551
+ // point is outside the floating element's bounds.
2552
+ const min$1 = minPadding;
2553
+ const max = clientSize - arrowDimensions[length] - maxPadding;
2554
+ const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
2555
+ const offset = clamp(min$1, center, max);
2556
+
2557
+ // If the reference is small enough that the arrow's padding causes it to
2558
+ // to point to nothing for an aligned placement, adjust the offset of the
2559
+ // floating element itself. To ensure `shift()` continues to take action,
2560
+ // a single reset is performed when this is true.
2561
+ const shouldAddOffset = !middlewareData.arrow && getAlignment(placement) != null && center !== offset && rects.reference[length] / 2 - (center < min$1 ? minPadding : maxPadding) - arrowDimensions[length] / 2 < 0;
2562
+ const alignmentOffset = shouldAddOffset ? center < min$1 ? center - min$1 : center - max : 0;
2563
+ return {
2564
+ [axis]: coords[axis] + alignmentOffset,
2565
+ data: {
2566
+ [axis]: offset,
2567
+ centerOffset: center - offset - alignmentOffset,
2568
+ ...(shouldAddOffset && {
2569
+ alignmentOffset
2570
+ })
2571
+ },
2572
+ reset: shouldAddOffset
2573
+ };
2574
+ }
1992
2575
  });
1993
- const Tooltip = React__namespace.forwardRef(({ children, heading, description, placement = "top", showArrow = true, className, delay = 200, disabled = false, }, ref) => {
1994
- const [isVisible, setIsVisible] = React__namespace.useState(false);
1995
- const [position, setPosition] = React__namespace.useState({ top: 0, left: 0 });
1996
- const [arrowPosition, setArrowPosition] = React__namespace.useState({ left: 0 });
1997
- const [actualPlacement, setActualPlacement] = React__namespace.useState(placement);
1998
- const timeoutRef = React__namespace.useRef(null);
1999
- const triggerRef = React__namespace.useRef(null);
2000
- const tooltipRef = React__namespace.useRef(null);
2001
- const calculatePosition = React__namespace.useCallback(() => {
2002
- if (!triggerRef.current || !tooltipRef.current)
2003
- return;
2004
- const triggerRect = triggerRef.current.getBoundingClientRect();
2005
- const tooltipRect = tooltipRef.current.getBoundingClientRect();
2006
- const gap = 8; // 8px gap between trigger and tooltip
2007
- const arrowSize = 6; // Size of the arrow
2008
- const viewportPadding = 8; // Minimum padding from viewport edges
2009
- let top = 0;
2010
- let left = 0;
2011
- let currentPlacement = placement;
2012
- // Calculate initial position based on placement
2013
- switch (placement) {
2014
- case "top-start":
2015
- top = triggerRect.top - tooltipRect.height - gap - arrowSize;
2016
- left = triggerRect.left;
2017
- break;
2018
- case "top":
2019
- top = triggerRect.top - tooltipRect.height - gap - arrowSize;
2020
- left =
2021
- triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
2022
- break;
2023
- case "top-end":
2024
- top = triggerRect.top - tooltipRect.height - gap - arrowSize;
2025
- left = triggerRect.right - tooltipRect.width;
2026
- break;
2027
- case "bottom-start":
2028
- top = triggerRect.bottom + gap + arrowSize;
2029
- left = triggerRect.left;
2030
- break;
2031
- case "bottom":
2032
- top = triggerRect.bottom + gap + arrowSize;
2033
- left =
2034
- triggerRect.left + triggerRect.width / 2 - tooltipRect.width / 2;
2035
- break;
2036
- case "bottom-end":
2037
- top = triggerRect.bottom + gap + arrowSize;
2038
- left = triggerRect.right - tooltipRect.width;
2039
- break;
2040
- }
2041
- // Get viewport dimensions
2042
- const viewportWidth = window.innerWidth;
2043
- const viewportHeight = window.innerHeight;
2044
- // Adjust horizontal position to keep tooltip within viewport
2045
- if (left < viewportPadding) {
2046
- // Tooltip would overflow on the left
2047
- left = viewportPadding;
2048
- }
2049
- else if (left + tooltipRect.width > viewportWidth - viewportPadding) {
2050
- // Tooltip would overflow on the right
2051
- left = viewportWidth - tooltipRect.width - viewportPadding;
2052
- }
2053
- // Adjust vertical position to keep tooltip within viewport
2054
- if (top < viewportPadding) {
2055
- // Tooltip would overflow at the top
2056
- // Try to flip to bottom if there's more space there
2057
- const spaceBelow = viewportHeight - triggerRect.bottom;
2058
- const spaceAbove = triggerRect.top;
2059
- if (spaceBelow > spaceAbove) {
2060
- // Flip to bottom
2061
- top = triggerRect.bottom + gap + arrowSize;
2062
- // Update placement to reflect the flip
2063
- if (placement === "top-start")
2064
- currentPlacement = "bottom-start";
2065
- else if (placement === "top")
2066
- currentPlacement = "bottom";
2067
- else if (placement === "top-end")
2068
- currentPlacement = "bottom-end";
2069
- }
2070
- else {
2071
- // Keep at top but adjust to stay in viewport
2072
- top = viewportPadding;
2073
- }
2576
+
2577
+ /**
2578
+ * Optimizes the visibility of the floating element by flipping the `placement`
2579
+ * in order to keep it in view when the preferred placement(s) will overflow the
2580
+ * clipping boundary. Alternative to `autoPlacement`.
2581
+ * @see https://floating-ui.com/docs/flip
2582
+ */
2583
+ const flip$2 = function (options) {
2584
+ if (options === void 0) {
2585
+ options = {};
2586
+ }
2587
+ return {
2588
+ name: 'flip',
2589
+ options,
2590
+ async fn(state) {
2591
+ var _middlewareData$arrow, _middlewareData$flip;
2592
+ const {
2593
+ placement,
2594
+ middlewareData,
2595
+ rects,
2596
+ initialPlacement,
2597
+ platform,
2598
+ elements
2599
+ } = state;
2600
+ const {
2601
+ mainAxis: checkMainAxis = true,
2602
+ crossAxis: checkCrossAxis = true,
2603
+ fallbackPlacements: specifiedFallbackPlacements,
2604
+ fallbackStrategy = 'bestFit',
2605
+ fallbackAxisSideDirection = 'none',
2606
+ flipAlignment = true,
2607
+ ...detectOverflowOptions
2608
+ } = evaluate(options, state);
2609
+
2610
+ // If a reset by the arrow was caused due to an alignment offset being
2611
+ // added, we should skip any logic now since `flip()` has already done its
2612
+ // work.
2613
+ // https://github.com/floating-ui/floating-ui/issues/2549#issuecomment-1719601643
2614
+ if ((_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
2615
+ return {};
2616
+ }
2617
+ const side = getSide(placement);
2618
+ const initialSideAxis = getSideAxis(initialPlacement);
2619
+ const isBasePlacement = getSide(initialPlacement) === initialPlacement;
2620
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
2621
+ const fallbackPlacements = specifiedFallbackPlacements || (isBasePlacement || !flipAlignment ? [getOppositePlacement(initialPlacement)] : getExpandedPlacements(initialPlacement));
2622
+ const hasFallbackAxisSideDirection = fallbackAxisSideDirection !== 'none';
2623
+ if (!specifiedFallbackPlacements && hasFallbackAxisSideDirection) {
2624
+ fallbackPlacements.push(...getOppositeAxisPlacements(initialPlacement, flipAlignment, fallbackAxisSideDirection, rtl));
2625
+ }
2626
+ const placements = [initialPlacement, ...fallbackPlacements];
2627
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
2628
+ const overflows = [];
2629
+ let overflowsData = ((_middlewareData$flip = middlewareData.flip) == null ? void 0 : _middlewareData$flip.overflows) || [];
2630
+ if (checkMainAxis) {
2631
+ overflows.push(overflow[side]);
2632
+ }
2633
+ if (checkCrossAxis) {
2634
+ const sides = getAlignmentSides(placement, rects, rtl);
2635
+ overflows.push(overflow[sides[0]], overflow[sides[1]]);
2636
+ }
2637
+ overflowsData = [...overflowsData, {
2638
+ placement,
2639
+ overflows
2640
+ }];
2641
+
2642
+ // One or more sides is overflowing.
2643
+ if (!overflows.every(side => side <= 0)) {
2644
+ var _middlewareData$flip2, _overflowsData$filter;
2645
+ const nextIndex = (((_middlewareData$flip2 = middlewareData.flip) == null ? void 0 : _middlewareData$flip2.index) || 0) + 1;
2646
+ const nextPlacement = placements[nextIndex];
2647
+ if (nextPlacement) {
2648
+ const ignoreCrossAxisOverflow = checkCrossAxis === 'alignment' ? initialSideAxis !== getSideAxis(nextPlacement) : false;
2649
+ if (!ignoreCrossAxisOverflow ||
2650
+ // We leave the current main axis only if every placement on that axis
2651
+ // overflows the main axis.
2652
+ overflowsData.every(d => getSideAxis(d.placement) === initialSideAxis ? d.overflows[0] > 0 : true)) {
2653
+ // Try next placement and re-run the lifecycle.
2654
+ return {
2655
+ data: {
2656
+ index: nextIndex,
2657
+ overflows: overflowsData
2658
+ },
2659
+ reset: {
2660
+ placement: nextPlacement
2661
+ }
2662
+ };
2663
+ }
2074
2664
  }
2075
- else if (top + tooltipRect.height > viewportHeight - viewportPadding) {
2076
- // Tooltip would overflow at the bottom
2077
- // Try to flip to top if there's more space there
2078
- const spaceAbove = triggerRect.top;
2079
- const spaceBelow = viewportHeight - triggerRect.bottom;
2080
- if (spaceAbove > spaceBelow) {
2081
- // Flip to top
2082
- top = triggerRect.top - tooltipRect.height - gap - arrowSize;
2083
- // Update placement to reflect the flip
2084
- if (placement === "bottom-start")
2085
- currentPlacement = "top-start";
2086
- else if (placement === "bottom")
2087
- currentPlacement = "top";
2088
- else if (placement === "bottom-end")
2089
- currentPlacement = "top-end";
2090
- }
2091
- else {
2092
- // Keep at bottom but adjust to stay in viewport
2093
- top = viewportHeight - tooltipRect.height - viewportPadding;
2665
+
2666
+ // First, find the candidates that fit on the mainAxis side of overflow,
2667
+ // then find the placement that fits the best on the main crossAxis side.
2668
+ let resetPlacement = (_overflowsData$filter = overflowsData.filter(d => d.overflows[0] <= 0).sort((a, b) => a.overflows[1] - b.overflows[1])[0]) == null ? void 0 : _overflowsData$filter.placement;
2669
+
2670
+ // Otherwise fallback.
2671
+ if (!resetPlacement) {
2672
+ switch (fallbackStrategy) {
2673
+ case 'bestFit':
2674
+ {
2675
+ var _overflowsData$filter2;
2676
+ const placement = (_overflowsData$filter2 = overflowsData.filter(d => {
2677
+ if (hasFallbackAxisSideDirection) {
2678
+ const currentSideAxis = getSideAxis(d.placement);
2679
+ return currentSideAxis === initialSideAxis ||
2680
+ // Create a bias to the `y` side axis due to horizontal
2681
+ // reading directions favoring greater width.
2682
+ currentSideAxis === 'y';
2683
+ }
2684
+ return true;
2685
+ }).map(d => [d.placement, d.overflows.filter(overflow => overflow > 0).reduce((acc, overflow) => acc + overflow, 0)]).sort((a, b) => a[1] - b[1])[0]) == null ? void 0 : _overflowsData$filter2[0];
2686
+ if (placement) {
2687
+ resetPlacement = placement;
2688
+ }
2689
+ break;
2690
+ }
2691
+ case 'initialPlacement':
2692
+ resetPlacement = initialPlacement;
2693
+ break;
2694
+ }
2695
+ }
2696
+ if (placement !== resetPlacement) {
2697
+ return {
2698
+ reset: {
2699
+ placement: resetPlacement
2094
2700
  }
2701
+ };
2095
2702
  }
2096
- // Calculate arrow position relative to trigger
2097
- // The arrow should point to the center of the trigger element
2098
- const triggerCenterX = triggerRect.left + triggerRect.width / 2;
2099
- const tooltipLeft = left;
2100
- const arrowLeft = triggerCenterX - tooltipLeft;
2101
- // Clamp arrow position to stay within tooltip bounds (with padding)
2102
- const arrowPadding = 16; // Minimum distance from tooltip edges
2103
- const clampedArrowLeft = Math.max(arrowPadding, Math.min(arrowLeft, tooltipRect.width - arrowPadding));
2104
- setPosition({ top, left });
2105
- setArrowPosition({ left: clampedArrowLeft });
2106
- setActualPlacement(currentPlacement);
2107
- }, [placement]);
2108
- const handleMouseEnter = () => {
2109
- if (disabled)
2110
- return;
2111
- if (timeoutRef.current) {
2112
- clearTimeout(timeoutRef.current);
2113
- }
2114
- timeoutRef.current = setTimeout(() => {
2115
- setIsVisible(true);
2116
- }, delay);
2703
+ }
2704
+ return {};
2705
+ }
2706
+ };
2707
+ };
2708
+
2709
+ function getSideOffsets(overflow, rect) {
2710
+ return {
2711
+ top: overflow.top - rect.height,
2712
+ right: overflow.right - rect.width,
2713
+ bottom: overflow.bottom - rect.height,
2714
+ left: overflow.left - rect.width
2715
+ };
2716
+ }
2717
+ function isAnySideFullyClipped(overflow) {
2718
+ return sides.some(side => overflow[side] >= 0);
2719
+ }
2720
+ /**
2721
+ * Provides data to hide the floating element in applicable situations, such as
2722
+ * when it is not in the same clipping context as the reference element.
2723
+ * @see https://floating-ui.com/docs/hide
2724
+ */
2725
+ const hide$2 = function (options) {
2726
+ if (options === void 0) {
2727
+ options = {};
2728
+ }
2729
+ return {
2730
+ name: 'hide',
2731
+ options,
2732
+ async fn(state) {
2733
+ const {
2734
+ rects,
2735
+ platform
2736
+ } = state;
2737
+ const {
2738
+ strategy = 'referenceHidden',
2739
+ ...detectOverflowOptions
2740
+ } = evaluate(options, state);
2741
+ switch (strategy) {
2742
+ case 'referenceHidden':
2743
+ {
2744
+ const overflow = await platform.detectOverflow(state, {
2745
+ ...detectOverflowOptions,
2746
+ elementContext: 'reference'
2747
+ });
2748
+ const offsets = getSideOffsets(overflow, rects.reference);
2749
+ return {
2750
+ data: {
2751
+ referenceHiddenOffsets: offsets,
2752
+ referenceHidden: isAnySideFullyClipped(offsets)
2753
+ }
2754
+ };
2755
+ }
2756
+ case 'escaped':
2757
+ {
2758
+ const overflow = await platform.detectOverflow(state, {
2759
+ ...detectOverflowOptions,
2760
+ altBoundary: true
2761
+ });
2762
+ const offsets = getSideOffsets(overflow, rects.floating);
2763
+ return {
2764
+ data: {
2765
+ escapedOffsets: offsets,
2766
+ escaped: isAnySideFullyClipped(offsets)
2767
+ }
2768
+ };
2769
+ }
2770
+ default:
2771
+ {
2772
+ return {};
2773
+ }
2774
+ }
2775
+ }
2776
+ };
2777
+ };
2778
+
2779
+ const originSides = /*#__PURE__*/new Set(['left', 'top']);
2780
+
2781
+ // For type backwards-compatibility, the `OffsetOptions` type was also
2782
+ // Derivable.
2783
+
2784
+ async function convertValueToCoords(state, options) {
2785
+ const {
2786
+ placement,
2787
+ platform,
2788
+ elements
2789
+ } = state;
2790
+ const rtl = await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating));
2791
+ const side = getSide(placement);
2792
+ const alignment = getAlignment(placement);
2793
+ const isVertical = getSideAxis(placement) === 'y';
2794
+ const mainAxisMulti = originSides.has(side) ? -1 : 1;
2795
+ const crossAxisMulti = rtl && isVertical ? -1 : 1;
2796
+ const rawValue = evaluate(options, state);
2797
+
2798
+ // eslint-disable-next-line prefer-const
2799
+ let {
2800
+ mainAxis,
2801
+ crossAxis,
2802
+ alignmentAxis
2803
+ } = typeof rawValue === 'number' ? {
2804
+ mainAxis: rawValue,
2805
+ crossAxis: 0,
2806
+ alignmentAxis: null
2807
+ } : {
2808
+ mainAxis: rawValue.mainAxis || 0,
2809
+ crossAxis: rawValue.crossAxis || 0,
2810
+ alignmentAxis: rawValue.alignmentAxis
2811
+ };
2812
+ if (alignment && typeof alignmentAxis === 'number') {
2813
+ crossAxis = alignment === 'end' ? alignmentAxis * -1 : alignmentAxis;
2814
+ }
2815
+ return isVertical ? {
2816
+ x: crossAxis * crossAxisMulti,
2817
+ y: mainAxis * mainAxisMulti
2818
+ } : {
2819
+ x: mainAxis * mainAxisMulti,
2820
+ y: crossAxis * crossAxisMulti
2821
+ };
2822
+ }
2823
+
2824
+ /**
2825
+ * Modifies the placement by translating the floating element along the
2826
+ * specified axes.
2827
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
2828
+ * object may be passed.
2829
+ * @see https://floating-ui.com/docs/offset
2830
+ */
2831
+ const offset$2 = function (options) {
2832
+ if (options === void 0) {
2833
+ options = 0;
2834
+ }
2835
+ return {
2836
+ name: 'offset',
2837
+ options,
2838
+ async fn(state) {
2839
+ var _middlewareData$offse, _middlewareData$arrow;
2840
+ const {
2841
+ x,
2842
+ y,
2843
+ placement,
2844
+ middlewareData
2845
+ } = state;
2846
+ const diffCoords = await convertValueToCoords(state, options);
2847
+
2848
+ // If the placement is the same and the arrow caused an alignment offset
2849
+ // then we don't need to change the positioning coordinates.
2850
+ if (placement === ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse.placement) && (_middlewareData$arrow = middlewareData.arrow) != null && _middlewareData$arrow.alignmentOffset) {
2851
+ return {};
2852
+ }
2853
+ return {
2854
+ x: x + diffCoords.x,
2855
+ y: y + diffCoords.y,
2856
+ data: {
2857
+ ...diffCoords,
2858
+ placement
2859
+ }
2860
+ };
2861
+ }
2862
+ };
2863
+ };
2864
+
2865
+ /**
2866
+ * Optimizes the visibility of the floating element by shifting it in order to
2867
+ * keep it in view when it will overflow the clipping boundary.
2868
+ * @see https://floating-ui.com/docs/shift
2869
+ */
2870
+ const shift$2 = function (options) {
2871
+ if (options === void 0) {
2872
+ options = {};
2873
+ }
2874
+ return {
2875
+ name: 'shift',
2876
+ options,
2877
+ async fn(state) {
2878
+ const {
2879
+ x,
2880
+ y,
2881
+ placement,
2882
+ platform
2883
+ } = state;
2884
+ const {
2885
+ mainAxis: checkMainAxis = true,
2886
+ crossAxis: checkCrossAxis = false,
2887
+ limiter = {
2888
+ fn: _ref => {
2889
+ let {
2890
+ x,
2891
+ y
2892
+ } = _ref;
2893
+ return {
2894
+ x,
2895
+ y
2896
+ };
2897
+ }
2898
+ },
2899
+ ...detectOverflowOptions
2900
+ } = evaluate(options, state);
2901
+ const coords = {
2902
+ x,
2903
+ y
2904
+ };
2905
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
2906
+ const crossAxis = getSideAxis(getSide(placement));
2907
+ const mainAxis = getOppositeAxis(crossAxis);
2908
+ let mainAxisCoord = coords[mainAxis];
2909
+ let crossAxisCoord = coords[crossAxis];
2910
+ if (checkMainAxis) {
2911
+ const minSide = mainAxis === 'y' ? 'top' : 'left';
2912
+ const maxSide = mainAxis === 'y' ? 'bottom' : 'right';
2913
+ const min = mainAxisCoord + overflow[minSide];
2914
+ const max = mainAxisCoord - overflow[maxSide];
2915
+ mainAxisCoord = clamp(min, mainAxisCoord, max);
2916
+ }
2917
+ if (checkCrossAxis) {
2918
+ const minSide = crossAxis === 'y' ? 'top' : 'left';
2919
+ const maxSide = crossAxis === 'y' ? 'bottom' : 'right';
2920
+ const min = crossAxisCoord + overflow[minSide];
2921
+ const max = crossAxisCoord - overflow[maxSide];
2922
+ crossAxisCoord = clamp(min, crossAxisCoord, max);
2923
+ }
2924
+ const limitedCoords = limiter.fn({
2925
+ ...state,
2926
+ [mainAxis]: mainAxisCoord,
2927
+ [crossAxis]: crossAxisCoord
2928
+ });
2929
+ return {
2930
+ ...limitedCoords,
2931
+ data: {
2932
+ x: limitedCoords.x - x,
2933
+ y: limitedCoords.y - y,
2934
+ enabled: {
2935
+ [mainAxis]: checkMainAxis,
2936
+ [crossAxis]: checkCrossAxis
2937
+ }
2938
+ }
2939
+ };
2940
+ }
2941
+ };
2942
+ };
2943
+ /**
2944
+ * Built-in `limiter` that will stop `shift()` at a certain point.
2945
+ */
2946
+ const limitShift$2 = function (options) {
2947
+ if (options === void 0) {
2948
+ options = {};
2949
+ }
2950
+ return {
2951
+ options,
2952
+ fn(state) {
2953
+ const {
2954
+ x,
2955
+ y,
2956
+ placement,
2957
+ rects,
2958
+ middlewareData
2959
+ } = state;
2960
+ const {
2961
+ offset = 0,
2962
+ mainAxis: checkMainAxis = true,
2963
+ crossAxis: checkCrossAxis = true
2964
+ } = evaluate(options, state);
2965
+ const coords = {
2966
+ x,
2967
+ y
2968
+ };
2969
+ const crossAxis = getSideAxis(placement);
2970
+ const mainAxis = getOppositeAxis(crossAxis);
2971
+ let mainAxisCoord = coords[mainAxis];
2972
+ let crossAxisCoord = coords[crossAxis];
2973
+ const rawOffset = evaluate(offset, state);
2974
+ const computedOffset = typeof rawOffset === 'number' ? {
2975
+ mainAxis: rawOffset,
2976
+ crossAxis: 0
2977
+ } : {
2978
+ mainAxis: 0,
2979
+ crossAxis: 0,
2980
+ ...rawOffset
2981
+ };
2982
+ if (checkMainAxis) {
2983
+ const len = mainAxis === 'y' ? 'height' : 'width';
2984
+ const limitMin = rects.reference[mainAxis] - rects.floating[len] + computedOffset.mainAxis;
2985
+ const limitMax = rects.reference[mainAxis] + rects.reference[len] - computedOffset.mainAxis;
2986
+ if (mainAxisCoord < limitMin) {
2987
+ mainAxisCoord = limitMin;
2988
+ } else if (mainAxisCoord > limitMax) {
2989
+ mainAxisCoord = limitMax;
2990
+ }
2991
+ }
2992
+ if (checkCrossAxis) {
2993
+ var _middlewareData$offse, _middlewareData$offse2;
2994
+ const len = mainAxis === 'y' ? 'width' : 'height';
2995
+ const isOriginSide = originSides.has(getSide(placement));
2996
+ const limitMin = rects.reference[crossAxis] - rects.floating[len] + (isOriginSide ? ((_middlewareData$offse = middlewareData.offset) == null ? void 0 : _middlewareData$offse[crossAxis]) || 0 : 0) + (isOriginSide ? 0 : computedOffset.crossAxis);
2997
+ const limitMax = rects.reference[crossAxis] + rects.reference[len] + (isOriginSide ? 0 : ((_middlewareData$offse2 = middlewareData.offset) == null ? void 0 : _middlewareData$offse2[crossAxis]) || 0) - (isOriginSide ? computedOffset.crossAxis : 0);
2998
+ if (crossAxisCoord < limitMin) {
2999
+ crossAxisCoord = limitMin;
3000
+ } else if (crossAxisCoord > limitMax) {
3001
+ crossAxisCoord = limitMax;
3002
+ }
3003
+ }
3004
+ return {
3005
+ [mainAxis]: mainAxisCoord,
3006
+ [crossAxis]: crossAxisCoord
3007
+ };
3008
+ }
3009
+ };
3010
+ };
3011
+
3012
+ /**
3013
+ * Provides data that allows you to change the size of the floating element —
3014
+ * for instance, prevent it from overflowing the clipping boundary or match the
3015
+ * width of the reference element.
3016
+ * @see https://floating-ui.com/docs/size
3017
+ */
3018
+ const size$2 = function (options) {
3019
+ if (options === void 0) {
3020
+ options = {};
3021
+ }
3022
+ return {
3023
+ name: 'size',
3024
+ options,
3025
+ async fn(state) {
3026
+ var _state$middlewareData, _state$middlewareData2;
3027
+ const {
3028
+ placement,
3029
+ rects,
3030
+ platform,
3031
+ elements
3032
+ } = state;
3033
+ const {
3034
+ apply = () => {},
3035
+ ...detectOverflowOptions
3036
+ } = evaluate(options, state);
3037
+ const overflow = await platform.detectOverflow(state, detectOverflowOptions);
3038
+ const side = getSide(placement);
3039
+ const alignment = getAlignment(placement);
3040
+ const isYAxis = getSideAxis(placement) === 'y';
3041
+ const {
3042
+ width,
3043
+ height
3044
+ } = rects.floating;
3045
+ let heightSide;
3046
+ let widthSide;
3047
+ if (side === 'top' || side === 'bottom') {
3048
+ heightSide = side;
3049
+ widthSide = alignment === ((await (platform.isRTL == null ? void 0 : platform.isRTL(elements.floating))) ? 'start' : 'end') ? 'left' : 'right';
3050
+ } else {
3051
+ widthSide = side;
3052
+ heightSide = alignment === 'end' ? 'top' : 'bottom';
3053
+ }
3054
+ const maximumClippingHeight = height - overflow.top - overflow.bottom;
3055
+ const maximumClippingWidth = width - overflow.left - overflow.right;
3056
+ const overflowAvailableHeight = min(height - overflow[heightSide], maximumClippingHeight);
3057
+ const overflowAvailableWidth = min(width - overflow[widthSide], maximumClippingWidth);
3058
+ const noShift = !state.middlewareData.shift;
3059
+ let availableHeight = overflowAvailableHeight;
3060
+ let availableWidth = overflowAvailableWidth;
3061
+ if ((_state$middlewareData = state.middlewareData.shift) != null && _state$middlewareData.enabled.x) {
3062
+ availableWidth = maximumClippingWidth;
3063
+ }
3064
+ if ((_state$middlewareData2 = state.middlewareData.shift) != null && _state$middlewareData2.enabled.y) {
3065
+ availableHeight = maximumClippingHeight;
3066
+ }
3067
+ if (noShift && !alignment) {
3068
+ const xMin = max(overflow.left, 0);
3069
+ const xMax = max(overflow.right, 0);
3070
+ const yMin = max(overflow.top, 0);
3071
+ const yMax = max(overflow.bottom, 0);
3072
+ if (isYAxis) {
3073
+ availableWidth = width - 2 * (xMin !== 0 || xMax !== 0 ? xMin + xMax : max(overflow.left, overflow.right));
3074
+ } else {
3075
+ availableHeight = height - 2 * (yMin !== 0 || yMax !== 0 ? yMin + yMax : max(overflow.top, overflow.bottom));
3076
+ }
3077
+ }
3078
+ await apply({
3079
+ ...state,
3080
+ availableWidth,
3081
+ availableHeight
3082
+ });
3083
+ const nextDimensions = await platform.getDimensions(elements.floating);
3084
+ if (width !== nextDimensions.width || height !== nextDimensions.height) {
3085
+ return {
3086
+ reset: {
3087
+ rects: true
3088
+ }
3089
+ };
3090
+ }
3091
+ return {};
3092
+ }
3093
+ };
3094
+ };
3095
+
3096
+ function hasWindow() {
3097
+ return typeof window !== 'undefined';
3098
+ }
3099
+ function getNodeName(node) {
3100
+ if (isNode(node)) {
3101
+ return (node.nodeName || '').toLowerCase();
3102
+ }
3103
+ // Mocked nodes in testing environments may not be instances of Node. By
3104
+ // returning `#document` an infinite loop won't occur.
3105
+ // https://github.com/floating-ui/floating-ui/issues/2317
3106
+ return '#document';
3107
+ }
3108
+ function getWindow(node) {
3109
+ var _node$ownerDocument;
3110
+ return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
3111
+ }
3112
+ function getDocumentElement(node) {
3113
+ var _ref;
3114
+ return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
3115
+ }
3116
+ function isNode(value) {
3117
+ if (!hasWindow()) {
3118
+ return false;
3119
+ }
3120
+ return value instanceof Node || value instanceof getWindow(value).Node;
3121
+ }
3122
+ function isElement(value) {
3123
+ if (!hasWindow()) {
3124
+ return false;
3125
+ }
3126
+ return value instanceof Element || value instanceof getWindow(value).Element;
3127
+ }
3128
+ function isHTMLElement(value) {
3129
+ if (!hasWindow()) {
3130
+ return false;
3131
+ }
3132
+ return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
3133
+ }
3134
+ function isShadowRoot(value) {
3135
+ if (!hasWindow() || typeof ShadowRoot === 'undefined') {
3136
+ return false;
3137
+ }
3138
+ return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
3139
+ }
3140
+ function isOverflowElement(element) {
3141
+ const {
3142
+ overflow,
3143
+ overflowX,
3144
+ overflowY,
3145
+ display
3146
+ } = getComputedStyle$1(element);
3147
+ return /auto|scroll|overlay|hidden|clip/.test(overflow + overflowY + overflowX) && display !== 'inline' && display !== 'contents';
3148
+ }
3149
+ function isTableElement(element) {
3150
+ return /^(table|td|th)$/.test(getNodeName(element));
3151
+ }
3152
+ function isTopLayer(element) {
3153
+ try {
3154
+ if (element.matches(':popover-open')) {
3155
+ return true;
3156
+ }
3157
+ } catch (_e) {
3158
+ // no-op
3159
+ }
3160
+ try {
3161
+ return element.matches(':modal');
3162
+ } catch (_e) {
3163
+ return false;
3164
+ }
3165
+ }
3166
+ const willChangeRe = /transform|translate|scale|rotate|perspective|filter/;
3167
+ const containRe = /paint|layout|strict|content/;
3168
+ const isNotNone = value => !!value && value !== 'none';
3169
+ let isWebKitValue;
3170
+ function isContainingBlock(elementOrCss) {
3171
+ const css = isElement(elementOrCss) ? getComputedStyle$1(elementOrCss) : elementOrCss;
3172
+
3173
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
3174
+ // https://drafts.csswg.org/css-transforms-2/#individual-transforms
3175
+ return isNotNone(css.transform) || isNotNone(css.translate) || isNotNone(css.scale) || isNotNone(css.rotate) || isNotNone(css.perspective) || !isWebKit() && (isNotNone(css.backdropFilter) || isNotNone(css.filter)) || willChangeRe.test(css.willChange || '') || containRe.test(css.contain || '');
3176
+ }
3177
+ function getContainingBlock(element) {
3178
+ let currentNode = getParentNode(element);
3179
+ while (isHTMLElement(currentNode) && !isLastTraversableNode(currentNode)) {
3180
+ if (isContainingBlock(currentNode)) {
3181
+ return currentNode;
3182
+ } else if (isTopLayer(currentNode)) {
3183
+ return null;
3184
+ }
3185
+ currentNode = getParentNode(currentNode);
3186
+ }
3187
+ return null;
3188
+ }
3189
+ function isWebKit() {
3190
+ if (isWebKitValue == null) {
3191
+ isWebKitValue = typeof CSS !== 'undefined' && CSS.supports && CSS.supports('-webkit-backdrop-filter', 'none');
3192
+ }
3193
+ return isWebKitValue;
3194
+ }
3195
+ function isLastTraversableNode(node) {
3196
+ return /^(html|body|#document)$/.test(getNodeName(node));
3197
+ }
3198
+ function getComputedStyle$1(element) {
3199
+ return getWindow(element).getComputedStyle(element);
3200
+ }
3201
+ function getNodeScroll(element) {
3202
+ if (isElement(element)) {
3203
+ return {
3204
+ scrollLeft: element.scrollLeft,
3205
+ scrollTop: element.scrollTop
2117
3206
  };
2118
- const handleMouseLeave = () => {
2119
- if (timeoutRef.current) {
2120
- clearTimeout(timeoutRef.current);
2121
- }
2122
- setIsVisible(false);
3207
+ }
3208
+ return {
3209
+ scrollLeft: element.scrollX,
3210
+ scrollTop: element.scrollY
3211
+ };
3212
+ }
3213
+ function getParentNode(node) {
3214
+ if (getNodeName(node) === 'html') {
3215
+ return node;
3216
+ }
3217
+ const result =
3218
+ // Step into the shadow DOM of the parent of a slotted node.
3219
+ node.assignedSlot ||
3220
+ // DOM Element detected.
3221
+ node.parentNode ||
3222
+ // ShadowRoot detected.
3223
+ isShadowRoot(node) && node.host ||
3224
+ // Fallback.
3225
+ getDocumentElement(node);
3226
+ return isShadowRoot(result) ? result.host : result;
3227
+ }
3228
+ function getNearestOverflowAncestor(node) {
3229
+ const parentNode = getParentNode(node);
3230
+ if (isLastTraversableNode(parentNode)) {
3231
+ return node.ownerDocument ? node.ownerDocument.body : node.body;
3232
+ }
3233
+ if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
3234
+ return parentNode;
3235
+ }
3236
+ return getNearestOverflowAncestor(parentNode);
3237
+ }
3238
+ function getOverflowAncestors(node, list, traverseIframes) {
3239
+ var _node$ownerDocument2;
3240
+ if (list === void 0) {
3241
+ list = [];
3242
+ }
3243
+ if (traverseIframes === void 0) {
3244
+ traverseIframes = true;
3245
+ }
3246
+ const scrollableAncestor = getNearestOverflowAncestor(node);
3247
+ const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
3248
+ const win = getWindow(scrollableAncestor);
3249
+ if (isBody) {
3250
+ const frameElement = getFrameElement(win);
3251
+ return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
3252
+ } else {
3253
+ return list.concat(scrollableAncestor, getOverflowAncestors(scrollableAncestor, [], traverseIframes));
3254
+ }
3255
+ }
3256
+ function getFrameElement(win) {
3257
+ return win.parent && Object.getPrototypeOf(win.parent) ? win.frameElement : null;
3258
+ }
3259
+
3260
+ function getCssDimensions(element) {
3261
+ const css = getComputedStyle$1(element);
3262
+ // In testing environments, the `width` and `height` properties are empty
3263
+ // strings for SVG elements, returning NaN. Fallback to `0` in this case.
3264
+ let width = parseFloat(css.width) || 0;
3265
+ let height = parseFloat(css.height) || 0;
3266
+ const hasOffset = isHTMLElement(element);
3267
+ const offsetWidth = hasOffset ? element.offsetWidth : width;
3268
+ const offsetHeight = hasOffset ? element.offsetHeight : height;
3269
+ const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
3270
+ if (shouldFallback) {
3271
+ width = offsetWidth;
3272
+ height = offsetHeight;
3273
+ }
3274
+ return {
3275
+ width,
3276
+ height,
3277
+ $: shouldFallback
3278
+ };
3279
+ }
3280
+
3281
+ function unwrapElement(element) {
3282
+ return !isElement(element) ? element.contextElement : element;
3283
+ }
3284
+
3285
+ function getScale(element) {
3286
+ const domElement = unwrapElement(element);
3287
+ if (!isHTMLElement(domElement)) {
3288
+ return createCoords(1);
3289
+ }
3290
+ const rect = domElement.getBoundingClientRect();
3291
+ const {
3292
+ width,
3293
+ height,
3294
+ $
3295
+ } = getCssDimensions(domElement);
3296
+ let x = ($ ? round(rect.width) : rect.width) / width;
3297
+ let y = ($ ? round(rect.height) : rect.height) / height;
3298
+
3299
+ // 0, NaN, or Infinity should always fallback to 1.
3300
+
3301
+ if (!x || !Number.isFinite(x)) {
3302
+ x = 1;
3303
+ }
3304
+ if (!y || !Number.isFinite(y)) {
3305
+ y = 1;
3306
+ }
3307
+ return {
3308
+ x,
3309
+ y
3310
+ };
3311
+ }
3312
+
3313
+ const noOffsets = /*#__PURE__*/createCoords(0);
3314
+ function getVisualOffsets(element) {
3315
+ const win = getWindow(element);
3316
+ if (!isWebKit() || !win.visualViewport) {
3317
+ return noOffsets;
3318
+ }
3319
+ return {
3320
+ x: win.visualViewport.offsetLeft,
3321
+ y: win.visualViewport.offsetTop
3322
+ };
3323
+ }
3324
+ function shouldAddVisualOffsets(element, isFixed, floatingOffsetParent) {
3325
+ if (isFixed === void 0) {
3326
+ isFixed = false;
3327
+ }
3328
+ if (!floatingOffsetParent || isFixed && floatingOffsetParent !== getWindow(element)) {
3329
+ return false;
3330
+ }
3331
+ return isFixed;
3332
+ }
3333
+
3334
+ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetParent) {
3335
+ if (includeScale === void 0) {
3336
+ includeScale = false;
3337
+ }
3338
+ if (isFixedStrategy === void 0) {
3339
+ isFixedStrategy = false;
3340
+ }
3341
+ const clientRect = element.getBoundingClientRect();
3342
+ const domElement = unwrapElement(element);
3343
+ let scale = createCoords(1);
3344
+ if (includeScale) {
3345
+ if (offsetParent) {
3346
+ if (isElement(offsetParent)) {
3347
+ scale = getScale(offsetParent);
3348
+ }
3349
+ } else {
3350
+ scale = getScale(element);
3351
+ }
3352
+ }
3353
+ const visualOffsets = shouldAddVisualOffsets(domElement, isFixedStrategy, offsetParent) ? getVisualOffsets(domElement) : createCoords(0);
3354
+ let x = (clientRect.left + visualOffsets.x) / scale.x;
3355
+ let y = (clientRect.top + visualOffsets.y) / scale.y;
3356
+ let width = clientRect.width / scale.x;
3357
+ let height = clientRect.height / scale.y;
3358
+ if (domElement) {
3359
+ const win = getWindow(domElement);
3360
+ const offsetWin = offsetParent && isElement(offsetParent) ? getWindow(offsetParent) : offsetParent;
3361
+ let currentWin = win;
3362
+ let currentIFrame = getFrameElement(currentWin);
3363
+ while (currentIFrame && offsetParent && offsetWin !== currentWin) {
3364
+ const iframeScale = getScale(currentIFrame);
3365
+ const iframeRect = currentIFrame.getBoundingClientRect();
3366
+ const css = getComputedStyle$1(currentIFrame);
3367
+ const left = iframeRect.left + (currentIFrame.clientLeft + parseFloat(css.paddingLeft)) * iframeScale.x;
3368
+ const top = iframeRect.top + (currentIFrame.clientTop + parseFloat(css.paddingTop)) * iframeScale.y;
3369
+ x *= iframeScale.x;
3370
+ y *= iframeScale.y;
3371
+ width *= iframeScale.x;
3372
+ height *= iframeScale.y;
3373
+ x += left;
3374
+ y += top;
3375
+ currentWin = getWindow(currentIFrame);
3376
+ currentIFrame = getFrameElement(currentWin);
3377
+ }
3378
+ }
3379
+ return rectToClientRect({
3380
+ width,
3381
+ height,
3382
+ x,
3383
+ y
3384
+ });
3385
+ }
3386
+
3387
+ // If <html> has a CSS width greater than the viewport, then this will be
3388
+ // incorrect for RTL.
3389
+ function getWindowScrollBarX(element, rect) {
3390
+ const leftScroll = getNodeScroll(element).scrollLeft;
3391
+ if (!rect) {
3392
+ return getBoundingClientRect(getDocumentElement(element)).left + leftScroll;
3393
+ }
3394
+ return rect.left + leftScroll;
3395
+ }
3396
+
3397
+ function getHTMLOffset(documentElement, scroll) {
3398
+ const htmlRect = documentElement.getBoundingClientRect();
3399
+ const x = htmlRect.left + scroll.scrollLeft - getWindowScrollBarX(documentElement, htmlRect);
3400
+ const y = htmlRect.top + scroll.scrollTop;
3401
+ return {
3402
+ x,
3403
+ y
3404
+ };
3405
+ }
3406
+
3407
+ function convertOffsetParentRelativeRectToViewportRelativeRect(_ref) {
3408
+ let {
3409
+ elements,
3410
+ rect,
3411
+ offsetParent,
3412
+ strategy
3413
+ } = _ref;
3414
+ const isFixed = strategy === 'fixed';
3415
+ const documentElement = getDocumentElement(offsetParent);
3416
+ const topLayer = elements ? isTopLayer(elements.floating) : false;
3417
+ if (offsetParent === documentElement || topLayer && isFixed) {
3418
+ return rect;
3419
+ }
3420
+ let scroll = {
3421
+ scrollLeft: 0,
3422
+ scrollTop: 0
3423
+ };
3424
+ let scale = createCoords(1);
3425
+ const offsets = createCoords(0);
3426
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
3427
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
3428
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
3429
+ scroll = getNodeScroll(offsetParent);
3430
+ }
3431
+ if (isOffsetParentAnElement) {
3432
+ const offsetRect = getBoundingClientRect(offsetParent);
3433
+ scale = getScale(offsetParent);
3434
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
3435
+ offsets.y = offsetRect.y + offsetParent.clientTop;
3436
+ }
3437
+ }
3438
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
3439
+ return {
3440
+ width: rect.width * scale.x,
3441
+ height: rect.height * scale.y,
3442
+ x: rect.x * scale.x - scroll.scrollLeft * scale.x + offsets.x + htmlOffset.x,
3443
+ y: rect.y * scale.y - scroll.scrollTop * scale.y + offsets.y + htmlOffset.y
3444
+ };
3445
+ }
3446
+
3447
+ function getClientRects(element) {
3448
+ return Array.from(element.getClientRects());
3449
+ }
3450
+
3451
+ // Gets the entire size of the scrollable document area, even extending outside
3452
+ // of the `<html>` and `<body>` rect bounds if horizontally scrollable.
3453
+ function getDocumentRect(element) {
3454
+ const html = getDocumentElement(element);
3455
+ const scroll = getNodeScroll(element);
3456
+ const body = element.ownerDocument.body;
3457
+ const width = max(html.scrollWidth, html.clientWidth, body.scrollWidth, body.clientWidth);
3458
+ const height = max(html.scrollHeight, html.clientHeight, body.scrollHeight, body.clientHeight);
3459
+ let x = -scroll.scrollLeft + getWindowScrollBarX(element);
3460
+ const y = -scroll.scrollTop;
3461
+ if (getComputedStyle$1(body).direction === 'rtl') {
3462
+ x += max(html.clientWidth, body.clientWidth) - width;
3463
+ }
3464
+ return {
3465
+ width,
3466
+ height,
3467
+ x,
3468
+ y
3469
+ };
3470
+ }
3471
+
3472
+ // Safety check: ensure the scrollbar space is reasonable in case this
3473
+ // calculation is affected by unusual styles.
3474
+ // Most scrollbars leave 15-18px of space.
3475
+ const SCROLLBAR_MAX = 25;
3476
+ function getViewportRect(element, strategy) {
3477
+ const win = getWindow(element);
3478
+ const html = getDocumentElement(element);
3479
+ const visualViewport = win.visualViewport;
3480
+ let width = html.clientWidth;
3481
+ let height = html.clientHeight;
3482
+ let x = 0;
3483
+ let y = 0;
3484
+ if (visualViewport) {
3485
+ width = visualViewport.width;
3486
+ height = visualViewport.height;
3487
+ const visualViewportBased = isWebKit();
3488
+ if (!visualViewportBased || visualViewportBased && strategy === 'fixed') {
3489
+ x = visualViewport.offsetLeft;
3490
+ y = visualViewport.offsetTop;
3491
+ }
3492
+ }
3493
+ const windowScrollbarX = getWindowScrollBarX(html);
3494
+ // <html> `overflow: hidden` + `scrollbar-gutter: stable` reduces the
3495
+ // visual width of the <html> but this is not considered in the size
3496
+ // of `html.clientWidth`.
3497
+ if (windowScrollbarX <= 0) {
3498
+ const doc = html.ownerDocument;
3499
+ const body = doc.body;
3500
+ const bodyStyles = getComputedStyle(body);
3501
+ const bodyMarginInline = doc.compatMode === 'CSS1Compat' ? parseFloat(bodyStyles.marginLeft) + parseFloat(bodyStyles.marginRight) || 0 : 0;
3502
+ const clippingStableScrollbarWidth = Math.abs(html.clientWidth - body.clientWidth - bodyMarginInline);
3503
+ if (clippingStableScrollbarWidth <= SCROLLBAR_MAX) {
3504
+ width -= clippingStableScrollbarWidth;
3505
+ }
3506
+ } else if (windowScrollbarX <= SCROLLBAR_MAX) {
3507
+ // If the <body> scrollbar is on the left, the width needs to be extended
3508
+ // by the scrollbar amount so there isn't extra space on the right.
3509
+ width += windowScrollbarX;
3510
+ }
3511
+ return {
3512
+ width,
3513
+ height,
3514
+ x,
3515
+ y
3516
+ };
3517
+ }
3518
+
3519
+ // Returns the inner client rect, subtracting scrollbars if present.
3520
+ function getInnerBoundingClientRect(element, strategy) {
3521
+ const clientRect = getBoundingClientRect(element, true, strategy === 'fixed');
3522
+ const top = clientRect.top + element.clientTop;
3523
+ const left = clientRect.left + element.clientLeft;
3524
+ const scale = isHTMLElement(element) ? getScale(element) : createCoords(1);
3525
+ const width = element.clientWidth * scale.x;
3526
+ const height = element.clientHeight * scale.y;
3527
+ const x = left * scale.x;
3528
+ const y = top * scale.y;
3529
+ return {
3530
+ width,
3531
+ height,
3532
+ x,
3533
+ y
3534
+ };
3535
+ }
3536
+ function getClientRectFromClippingAncestor(element, clippingAncestor, strategy) {
3537
+ let rect;
3538
+ if (clippingAncestor === 'viewport') {
3539
+ rect = getViewportRect(element, strategy);
3540
+ } else if (clippingAncestor === 'document') {
3541
+ rect = getDocumentRect(getDocumentElement(element));
3542
+ } else if (isElement(clippingAncestor)) {
3543
+ rect = getInnerBoundingClientRect(clippingAncestor, strategy);
3544
+ } else {
3545
+ const visualOffsets = getVisualOffsets(element);
3546
+ rect = {
3547
+ x: clippingAncestor.x - visualOffsets.x,
3548
+ y: clippingAncestor.y - visualOffsets.y,
3549
+ width: clippingAncestor.width,
3550
+ height: clippingAncestor.height
2123
3551
  };
2124
- const handleFocus = () => {
2125
- if (disabled)
2126
- return;
2127
- setIsVisible(true);
3552
+ }
3553
+ return rectToClientRect(rect);
3554
+ }
3555
+ function hasFixedPositionAncestor(element, stopNode) {
3556
+ const parentNode = getParentNode(element);
3557
+ if (parentNode === stopNode || !isElement(parentNode) || isLastTraversableNode(parentNode)) {
3558
+ return false;
3559
+ }
3560
+ return getComputedStyle$1(parentNode).position === 'fixed' || hasFixedPositionAncestor(parentNode, stopNode);
3561
+ }
3562
+
3563
+ // A "clipping ancestor" is an `overflow` element with the characteristic of
3564
+ // clipping (or hiding) child elements. This returns all clipping ancestors
3565
+ // of the given element up the tree.
3566
+ function getClippingElementAncestors(element, cache) {
3567
+ const cachedResult = cache.get(element);
3568
+ if (cachedResult) {
3569
+ return cachedResult;
3570
+ }
3571
+ let result = getOverflowAncestors(element, [], false).filter(el => isElement(el) && getNodeName(el) !== 'body');
3572
+ let currentContainingBlockComputedStyle = null;
3573
+ const elementIsFixed = getComputedStyle$1(element).position === 'fixed';
3574
+ let currentNode = elementIsFixed ? getParentNode(element) : element;
3575
+
3576
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block#identifying_the_containing_block
3577
+ while (isElement(currentNode) && !isLastTraversableNode(currentNode)) {
3578
+ const computedStyle = getComputedStyle$1(currentNode);
3579
+ const currentNodeIsContaining = isContainingBlock(currentNode);
3580
+ if (!currentNodeIsContaining && computedStyle.position === 'fixed') {
3581
+ currentContainingBlockComputedStyle = null;
3582
+ }
3583
+ const shouldDropCurrentNode = elementIsFixed ? !currentNodeIsContaining && !currentContainingBlockComputedStyle : !currentNodeIsContaining && computedStyle.position === 'static' && !!currentContainingBlockComputedStyle && (currentContainingBlockComputedStyle.position === 'absolute' || currentContainingBlockComputedStyle.position === 'fixed') || isOverflowElement(currentNode) && !currentNodeIsContaining && hasFixedPositionAncestor(element, currentNode);
3584
+ if (shouldDropCurrentNode) {
3585
+ // Drop non-containing blocks.
3586
+ result = result.filter(ancestor => ancestor !== currentNode);
3587
+ } else {
3588
+ // Record last containing block for next iteration.
3589
+ currentContainingBlockComputedStyle = computedStyle;
3590
+ }
3591
+ currentNode = getParentNode(currentNode);
3592
+ }
3593
+ cache.set(element, result);
3594
+ return result;
3595
+ }
3596
+
3597
+ // Gets the maximum area that the element is visible in due to any number of
3598
+ // clipping ancestors.
3599
+ function getClippingRect(_ref) {
3600
+ let {
3601
+ element,
3602
+ boundary,
3603
+ rootBoundary,
3604
+ strategy
3605
+ } = _ref;
3606
+ const elementClippingAncestors = boundary === 'clippingAncestors' ? isTopLayer(element) ? [] : getClippingElementAncestors(element, this._c) : [].concat(boundary);
3607
+ const clippingAncestors = [...elementClippingAncestors, rootBoundary];
3608
+ const firstRect = getClientRectFromClippingAncestor(element, clippingAncestors[0], strategy);
3609
+ let top = firstRect.top;
3610
+ let right = firstRect.right;
3611
+ let bottom = firstRect.bottom;
3612
+ let left = firstRect.left;
3613
+ for (let i = 1; i < clippingAncestors.length; i++) {
3614
+ const rect = getClientRectFromClippingAncestor(element, clippingAncestors[i], strategy);
3615
+ top = max(rect.top, top);
3616
+ right = min(rect.right, right);
3617
+ bottom = min(rect.bottom, bottom);
3618
+ left = max(rect.left, left);
3619
+ }
3620
+ return {
3621
+ width: right - left,
3622
+ height: bottom - top,
3623
+ x: left,
3624
+ y: top
3625
+ };
3626
+ }
3627
+
3628
+ function getDimensions(element) {
3629
+ const {
3630
+ width,
3631
+ height
3632
+ } = getCssDimensions(element);
3633
+ return {
3634
+ width,
3635
+ height
3636
+ };
3637
+ }
3638
+
3639
+ function getRectRelativeToOffsetParent(element, offsetParent, strategy) {
3640
+ const isOffsetParentAnElement = isHTMLElement(offsetParent);
3641
+ const documentElement = getDocumentElement(offsetParent);
3642
+ const isFixed = strategy === 'fixed';
3643
+ const rect = getBoundingClientRect(element, true, isFixed, offsetParent);
3644
+ let scroll = {
3645
+ scrollLeft: 0,
3646
+ scrollTop: 0
3647
+ };
3648
+ const offsets = createCoords(0);
3649
+
3650
+ // If the <body> scrollbar appears on the left (e.g. RTL systems). Use
3651
+ // Firefox with layout.scrollbar.side = 3 in about:config to test this.
3652
+ function setLeftRTLScrollbarOffset() {
3653
+ offsets.x = getWindowScrollBarX(documentElement);
3654
+ }
3655
+ if (isOffsetParentAnElement || !isOffsetParentAnElement && !isFixed) {
3656
+ if (getNodeName(offsetParent) !== 'body' || isOverflowElement(documentElement)) {
3657
+ scroll = getNodeScroll(offsetParent);
3658
+ }
3659
+ if (isOffsetParentAnElement) {
3660
+ const offsetRect = getBoundingClientRect(offsetParent, true, isFixed, offsetParent);
3661
+ offsets.x = offsetRect.x + offsetParent.clientLeft;
3662
+ offsets.y = offsetRect.y + offsetParent.clientTop;
3663
+ } else if (documentElement) {
3664
+ setLeftRTLScrollbarOffset();
3665
+ }
3666
+ }
3667
+ if (isFixed && !isOffsetParentAnElement && documentElement) {
3668
+ setLeftRTLScrollbarOffset();
3669
+ }
3670
+ const htmlOffset = documentElement && !isOffsetParentAnElement && !isFixed ? getHTMLOffset(documentElement, scroll) : createCoords(0);
3671
+ const x = rect.left + scroll.scrollLeft - offsets.x - htmlOffset.x;
3672
+ const y = rect.top + scroll.scrollTop - offsets.y - htmlOffset.y;
3673
+ return {
3674
+ x,
3675
+ y,
3676
+ width: rect.width,
3677
+ height: rect.height
3678
+ };
3679
+ }
3680
+
3681
+ function isStaticPositioned(element) {
3682
+ return getComputedStyle$1(element).position === 'static';
3683
+ }
3684
+
3685
+ function getTrueOffsetParent(element, polyfill) {
3686
+ if (!isHTMLElement(element) || getComputedStyle$1(element).position === 'fixed') {
3687
+ return null;
3688
+ }
3689
+ if (polyfill) {
3690
+ return polyfill(element);
3691
+ }
3692
+ let rawOffsetParent = element.offsetParent;
3693
+
3694
+ // Firefox returns the <html> element as the offsetParent if it's non-static,
3695
+ // while Chrome and Safari return the <body> element. The <body> element must
3696
+ // be used to perform the correct calculations even if the <html> element is
3697
+ // non-static.
3698
+ if (getDocumentElement(element) === rawOffsetParent) {
3699
+ rawOffsetParent = rawOffsetParent.ownerDocument.body;
3700
+ }
3701
+ return rawOffsetParent;
3702
+ }
3703
+
3704
+ // Gets the closest ancestor positioned element. Handles some edge cases,
3705
+ // such as table ancestors and cross browser bugs.
3706
+ function getOffsetParent(element, polyfill) {
3707
+ const win = getWindow(element);
3708
+ if (isTopLayer(element)) {
3709
+ return win;
3710
+ }
3711
+ if (!isHTMLElement(element)) {
3712
+ let svgOffsetParent = getParentNode(element);
3713
+ while (svgOffsetParent && !isLastTraversableNode(svgOffsetParent)) {
3714
+ if (isElement(svgOffsetParent) && !isStaticPositioned(svgOffsetParent)) {
3715
+ return svgOffsetParent;
3716
+ }
3717
+ svgOffsetParent = getParentNode(svgOffsetParent);
3718
+ }
3719
+ return win;
3720
+ }
3721
+ let offsetParent = getTrueOffsetParent(element, polyfill);
3722
+ while (offsetParent && isTableElement(offsetParent) && isStaticPositioned(offsetParent)) {
3723
+ offsetParent = getTrueOffsetParent(offsetParent, polyfill);
3724
+ }
3725
+ if (offsetParent && isLastTraversableNode(offsetParent) && isStaticPositioned(offsetParent) && !isContainingBlock(offsetParent)) {
3726
+ return win;
3727
+ }
3728
+ return offsetParent || getContainingBlock(element) || win;
3729
+ }
3730
+
3731
+ const getElementRects = async function (data) {
3732
+ const getOffsetParentFn = this.getOffsetParent || getOffsetParent;
3733
+ const getDimensionsFn = this.getDimensions;
3734
+ const floatingDimensions = await getDimensionsFn(data.floating);
3735
+ return {
3736
+ reference: getRectRelativeToOffsetParent(data.reference, await getOffsetParentFn(data.floating), data.strategy),
3737
+ floating: {
3738
+ x: 0,
3739
+ y: 0,
3740
+ width: floatingDimensions.width,
3741
+ height: floatingDimensions.height
3742
+ }
3743
+ };
3744
+ };
3745
+
3746
+ function isRTL(element) {
3747
+ return getComputedStyle$1(element).direction === 'rtl';
3748
+ }
3749
+
3750
+ const platform = {
3751
+ convertOffsetParentRelativeRectToViewportRelativeRect,
3752
+ getDocumentElement,
3753
+ getClippingRect,
3754
+ getOffsetParent,
3755
+ getElementRects,
3756
+ getClientRects,
3757
+ getDimensions,
3758
+ getScale,
3759
+ isElement,
3760
+ isRTL
3761
+ };
3762
+
3763
+ function rectsAreEqual(a, b) {
3764
+ return a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
3765
+ }
3766
+
3767
+ // https://samthor.au/2021/observing-dom/
3768
+ function observeMove(element, onMove) {
3769
+ let io = null;
3770
+ let timeoutId;
3771
+ const root = getDocumentElement(element);
3772
+ function cleanup() {
3773
+ var _io;
3774
+ clearTimeout(timeoutId);
3775
+ (_io = io) == null || _io.disconnect();
3776
+ io = null;
3777
+ }
3778
+ function refresh(skip, threshold) {
3779
+ if (skip === void 0) {
3780
+ skip = false;
3781
+ }
3782
+ if (threshold === void 0) {
3783
+ threshold = 1;
3784
+ }
3785
+ cleanup();
3786
+ const elementRectForRootMargin = element.getBoundingClientRect();
3787
+ const {
3788
+ left,
3789
+ top,
3790
+ width,
3791
+ height
3792
+ } = elementRectForRootMargin;
3793
+ if (!skip) {
3794
+ onMove();
3795
+ }
3796
+ if (!width || !height) {
3797
+ return;
3798
+ }
3799
+ const insetTop = floor(top);
3800
+ const insetRight = floor(root.clientWidth - (left + width));
3801
+ const insetBottom = floor(root.clientHeight - (top + height));
3802
+ const insetLeft = floor(left);
3803
+ const rootMargin = -insetTop + "px " + -insetRight + "px " + -insetBottom + "px " + -insetLeft + "px";
3804
+ const options = {
3805
+ rootMargin,
3806
+ threshold: max(0, min(1, threshold)) || 1
2128
3807
  };
2129
- const handleBlur = () => {
2130
- setIsVisible(false);
3808
+ let isFirstUpdate = true;
3809
+ function handleObserve(entries) {
3810
+ const ratio = entries[0].intersectionRatio;
3811
+ if (ratio !== threshold) {
3812
+ if (!isFirstUpdate) {
3813
+ return refresh();
3814
+ }
3815
+ if (!ratio) {
3816
+ // If the reference is clipped, the ratio is 0. Throttle the refresh
3817
+ // to prevent an infinite loop of updates.
3818
+ timeoutId = setTimeout(() => {
3819
+ refresh(false, 1e-7);
3820
+ }, 1000);
3821
+ } else {
3822
+ refresh(false, ratio);
3823
+ }
3824
+ }
3825
+ if (ratio === 1 && !rectsAreEqual(elementRectForRootMargin, element.getBoundingClientRect())) {
3826
+ // It's possible that even though the ratio is reported as 1, the
3827
+ // element is not actually fully within the IntersectionObserver's root
3828
+ // area anymore. This can happen under performance constraints. This may
3829
+ // be a bug in the browser's IntersectionObserver implementation. To
3830
+ // work around this, we compare the element's bounding rect now with
3831
+ // what it was at the time we created the IntersectionObserver. If they
3832
+ // are not equal then the element moved, so we refresh.
3833
+ refresh();
3834
+ }
3835
+ isFirstUpdate = false;
3836
+ }
3837
+
3838
+ // Older browsers don't support a `document` as the root and will throw an
3839
+ // error.
3840
+ try {
3841
+ io = new IntersectionObserver(handleObserve, {
3842
+ ...options,
3843
+ // Handle <iframe>s
3844
+ root: root.ownerDocument
3845
+ });
3846
+ } catch (_e) {
3847
+ io = new IntersectionObserver(handleObserve, options);
3848
+ }
3849
+ io.observe(element);
3850
+ }
3851
+ refresh(true);
3852
+ return cleanup;
3853
+ }
3854
+
3855
+ /**
3856
+ * Automatically updates the position of the floating element when necessary.
3857
+ * Should only be called when the floating element is mounted on the DOM or
3858
+ * visible on the screen.
3859
+ * @returns cleanup function that should be invoked when the floating element is
3860
+ * removed from the DOM or hidden from the screen.
3861
+ * @see https://floating-ui.com/docs/autoUpdate
3862
+ */
3863
+ function autoUpdate(reference, floating, update, options) {
3864
+ if (options === void 0) {
3865
+ options = {};
3866
+ }
3867
+ const {
3868
+ ancestorScroll = true,
3869
+ ancestorResize = true,
3870
+ elementResize = typeof ResizeObserver === 'function',
3871
+ layoutShift = typeof IntersectionObserver === 'function',
3872
+ animationFrame = false
3873
+ } = options;
3874
+ const referenceEl = unwrapElement(reference);
3875
+ const ancestors = ancestorScroll || ancestorResize ? [...(referenceEl ? getOverflowAncestors(referenceEl) : []), ...(floating ? getOverflowAncestors(floating) : [])] : [];
3876
+ ancestors.forEach(ancestor => {
3877
+ ancestorScroll && ancestor.addEventListener('scroll', update, {
3878
+ passive: true
3879
+ });
3880
+ ancestorResize && ancestor.addEventListener('resize', update);
3881
+ });
3882
+ const cleanupIo = referenceEl && layoutShift ? observeMove(referenceEl, update) : null;
3883
+ let reobserveFrame = -1;
3884
+ let resizeObserver = null;
3885
+ if (elementResize) {
3886
+ resizeObserver = new ResizeObserver(_ref => {
3887
+ let [firstEntry] = _ref;
3888
+ if (firstEntry && firstEntry.target === referenceEl && resizeObserver && floating) {
3889
+ // Prevent update loops when using the `size` middleware.
3890
+ // https://github.com/floating-ui/floating-ui/issues/1740
3891
+ resizeObserver.unobserve(floating);
3892
+ cancelAnimationFrame(reobserveFrame);
3893
+ reobserveFrame = requestAnimationFrame(() => {
3894
+ var _resizeObserver;
3895
+ (_resizeObserver = resizeObserver) == null || _resizeObserver.observe(floating);
3896
+ });
3897
+ }
3898
+ update();
3899
+ });
3900
+ if (referenceEl && !animationFrame) {
3901
+ resizeObserver.observe(referenceEl);
3902
+ }
3903
+ if (floating) {
3904
+ resizeObserver.observe(floating);
3905
+ }
3906
+ }
3907
+ let frameId;
3908
+ let prevRefRect = animationFrame ? getBoundingClientRect(reference) : null;
3909
+ if (animationFrame) {
3910
+ frameLoop();
3911
+ }
3912
+ function frameLoop() {
3913
+ const nextRefRect = getBoundingClientRect(reference);
3914
+ if (prevRefRect && !rectsAreEqual(prevRefRect, nextRefRect)) {
3915
+ update();
3916
+ }
3917
+ prevRefRect = nextRefRect;
3918
+ frameId = requestAnimationFrame(frameLoop);
3919
+ }
3920
+ update();
3921
+ return () => {
3922
+ var _resizeObserver2;
3923
+ ancestors.forEach(ancestor => {
3924
+ ancestorScroll && ancestor.removeEventListener('scroll', update);
3925
+ ancestorResize && ancestor.removeEventListener('resize', update);
3926
+ });
3927
+ cleanupIo == null || cleanupIo();
3928
+ (_resizeObserver2 = resizeObserver) == null || _resizeObserver2.disconnect();
3929
+ resizeObserver = null;
3930
+ if (animationFrame) {
3931
+ cancelAnimationFrame(frameId);
3932
+ }
3933
+ };
3934
+ }
3935
+
3936
+ /**
3937
+ * Modifies the placement by translating the floating element along the
3938
+ * specified axes.
3939
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
3940
+ * object may be passed.
3941
+ * @see https://floating-ui.com/docs/offset
3942
+ */
3943
+ const offset$1 = offset$2;
3944
+
3945
+ /**
3946
+ * Optimizes the visibility of the floating element by shifting it in order to
3947
+ * keep it in view when it will overflow the clipping boundary.
3948
+ * @see https://floating-ui.com/docs/shift
3949
+ */
3950
+ const shift$1 = shift$2;
3951
+
3952
+ /**
3953
+ * Optimizes the visibility of the floating element by flipping the `placement`
3954
+ * in order to keep it in view when the preferred placement(s) will overflow the
3955
+ * clipping boundary. Alternative to `autoPlacement`.
3956
+ * @see https://floating-ui.com/docs/flip
3957
+ */
3958
+ const flip$1 = flip$2;
3959
+
3960
+ /**
3961
+ * Provides data that allows you to change the size of the floating element —
3962
+ * for instance, prevent it from overflowing the clipping boundary or match the
3963
+ * width of the reference element.
3964
+ * @see https://floating-ui.com/docs/size
3965
+ */
3966
+ const size$1 = size$2;
3967
+
3968
+ /**
3969
+ * Provides data to hide the floating element in applicable situations, such as
3970
+ * when it is not in the same clipping context as the reference element.
3971
+ * @see https://floating-ui.com/docs/hide
3972
+ */
3973
+ const hide$1 = hide$2;
3974
+
3975
+ /**
3976
+ * Provides data to position an inner element of the floating element so that it
3977
+ * appears centered to the reference element.
3978
+ * @see https://floating-ui.com/docs/arrow
3979
+ */
3980
+ const arrow$2 = arrow$3;
3981
+
3982
+ /**
3983
+ * Built-in `limiter` that will stop `shift()` at a certain point.
3984
+ */
3985
+ const limitShift$1 = limitShift$2;
3986
+
3987
+ /**
3988
+ * Computes the `x` and `y` coordinates that will place the floating element
3989
+ * next to a given reference element.
3990
+ */
3991
+ const computePosition = (reference, floating, options) => {
3992
+ // This caches the expensive `getClippingElementAncestors` function so that
3993
+ // multiple lifecycle resets re-use the same result. It only lives for a
3994
+ // single call. If other functions become expensive, we can add them as well.
3995
+ const cache = new Map();
3996
+ const mergedOptions = {
3997
+ platform,
3998
+ ...options
3999
+ };
4000
+ const platformWithCache = {
4001
+ ...mergedOptions.platform,
4002
+ _c: cache
4003
+ };
4004
+ return computePosition$1(reference, floating, {
4005
+ ...mergedOptions,
4006
+ platform: platformWithCache
4007
+ });
4008
+ };
4009
+
4010
+ var isClient = typeof document !== 'undefined';
4011
+
4012
+ var noop = function noop() {};
4013
+ var index = isClient ? React.useLayoutEffect : noop;
4014
+
4015
+ // Fork of `fast-deep-equal` that only does the comparisons we need and compares
4016
+ // functions
4017
+ function deepEqual(a, b) {
4018
+ if (a === b) {
4019
+ return true;
4020
+ }
4021
+ if (typeof a !== typeof b) {
4022
+ return false;
4023
+ }
4024
+ if (typeof a === 'function' && a.toString() === b.toString()) {
4025
+ return true;
4026
+ }
4027
+ let length;
4028
+ let i;
4029
+ let keys;
4030
+ if (a && b && typeof a === 'object') {
4031
+ if (Array.isArray(a)) {
4032
+ length = a.length;
4033
+ if (length !== b.length) return false;
4034
+ for (i = length; i-- !== 0;) {
4035
+ if (!deepEqual(a[i], b[i])) {
4036
+ return false;
4037
+ }
4038
+ }
4039
+ return true;
4040
+ }
4041
+ keys = Object.keys(a);
4042
+ length = keys.length;
4043
+ if (length !== Object.keys(b).length) {
4044
+ return false;
4045
+ }
4046
+ for (i = length; i-- !== 0;) {
4047
+ if (!{}.hasOwnProperty.call(b, keys[i])) {
4048
+ return false;
4049
+ }
4050
+ }
4051
+ for (i = length; i-- !== 0;) {
4052
+ const key = keys[i];
4053
+ if (key === '_owner' && a.$$typeof) {
4054
+ continue;
4055
+ }
4056
+ if (!deepEqual(a[key], b[key])) {
4057
+ return false;
4058
+ }
4059
+ }
4060
+ return true;
4061
+ }
4062
+ return a !== a && b !== b;
4063
+ }
4064
+
4065
+ function getDPR(element) {
4066
+ if (typeof window === 'undefined') {
4067
+ return 1;
4068
+ }
4069
+ const win = element.ownerDocument.defaultView || window;
4070
+ return win.devicePixelRatio || 1;
4071
+ }
4072
+
4073
+ function roundByDPR(element, value) {
4074
+ const dpr = getDPR(element);
4075
+ return Math.round(value * dpr) / dpr;
4076
+ }
4077
+
4078
+ function useLatestRef(value) {
4079
+ const ref = React__namespace.useRef(value);
4080
+ index(() => {
4081
+ ref.current = value;
4082
+ });
4083
+ return ref;
4084
+ }
4085
+
4086
+ /**
4087
+ * Provides data to position a floating element.
4088
+ * @see https://floating-ui.com/docs/useFloating
4089
+ */
4090
+ function useFloating(options) {
4091
+ if (options === void 0) {
4092
+ options = {};
4093
+ }
4094
+ const {
4095
+ placement = 'bottom',
4096
+ strategy = 'absolute',
4097
+ middleware = [],
4098
+ platform,
4099
+ elements: {
4100
+ reference: externalReference,
4101
+ floating: externalFloating
4102
+ } = {},
4103
+ transform = true,
4104
+ whileElementsMounted,
4105
+ open
4106
+ } = options;
4107
+ const [data, setData] = React__namespace.useState({
4108
+ x: 0,
4109
+ y: 0,
4110
+ strategy,
4111
+ placement,
4112
+ middlewareData: {},
4113
+ isPositioned: false
4114
+ });
4115
+ const [latestMiddleware, setLatestMiddleware] = React__namespace.useState(middleware);
4116
+ if (!deepEqual(latestMiddleware, middleware)) {
4117
+ setLatestMiddleware(middleware);
4118
+ }
4119
+ const [_reference, _setReference] = React__namespace.useState(null);
4120
+ const [_floating, _setFloating] = React__namespace.useState(null);
4121
+ const setReference = React__namespace.useCallback(node => {
4122
+ if (node !== referenceRef.current) {
4123
+ referenceRef.current = node;
4124
+ _setReference(node);
4125
+ }
4126
+ }, []);
4127
+ const setFloating = React__namespace.useCallback(node => {
4128
+ if (node !== floatingRef.current) {
4129
+ floatingRef.current = node;
4130
+ _setFloating(node);
4131
+ }
4132
+ }, []);
4133
+ const referenceEl = externalReference || _reference;
4134
+ const floatingEl = externalFloating || _floating;
4135
+ const referenceRef = React__namespace.useRef(null);
4136
+ const floatingRef = React__namespace.useRef(null);
4137
+ const dataRef = React__namespace.useRef(data);
4138
+ const hasWhileElementsMounted = whileElementsMounted != null;
4139
+ const whileElementsMountedRef = useLatestRef(whileElementsMounted);
4140
+ const platformRef = useLatestRef(platform);
4141
+ const openRef = useLatestRef(open);
4142
+ const update = React__namespace.useCallback(() => {
4143
+ if (!referenceRef.current || !floatingRef.current) {
4144
+ return;
4145
+ }
4146
+ const config = {
4147
+ placement,
4148
+ strategy,
4149
+ middleware: latestMiddleware
2131
4150
  };
4151
+ if (platformRef.current) {
4152
+ config.platform = platformRef.current;
4153
+ }
4154
+ computePosition(referenceRef.current, floatingRef.current, config).then(data => {
4155
+ const fullData = {
4156
+ ...data,
4157
+ // The floating element's position may be recomputed while it's closed
4158
+ // but still mounted (such as when transitioning out). To ensure
4159
+ // `isPositioned` will be `false` initially on the next open, avoid
4160
+ // setting it to `true` when `open === false` (must be specified).
4161
+ isPositioned: openRef.current !== false
4162
+ };
4163
+ if (isMountedRef.current && !deepEqual(dataRef.current, fullData)) {
4164
+ dataRef.current = fullData;
4165
+ ReactDOM__namespace.flushSync(() => {
4166
+ setData(fullData);
4167
+ });
4168
+ }
4169
+ });
4170
+ }, [latestMiddleware, placement, strategy, platformRef, openRef]);
4171
+ index(() => {
4172
+ if (open === false && dataRef.current.isPositioned) {
4173
+ dataRef.current.isPositioned = false;
4174
+ setData(data => ({
4175
+ ...data,
4176
+ isPositioned: false
4177
+ }));
4178
+ }
4179
+ }, [open]);
4180
+ const isMountedRef = React__namespace.useRef(false);
4181
+ index(() => {
4182
+ isMountedRef.current = true;
4183
+ return () => {
4184
+ isMountedRef.current = false;
4185
+ };
4186
+ }, []);
4187
+ index(() => {
4188
+ if (referenceEl) referenceRef.current = referenceEl;
4189
+ if (floatingEl) floatingRef.current = floatingEl;
4190
+ if (referenceEl && floatingEl) {
4191
+ if (whileElementsMountedRef.current) {
4192
+ return whileElementsMountedRef.current(referenceEl, floatingEl, update);
4193
+ }
4194
+ update();
4195
+ }
4196
+ }, [referenceEl, floatingEl, update, whileElementsMountedRef, hasWhileElementsMounted]);
4197
+ const refs = React__namespace.useMemo(() => ({
4198
+ reference: referenceRef,
4199
+ floating: floatingRef,
4200
+ setReference,
4201
+ setFloating
4202
+ }), [setReference, setFloating]);
4203
+ const elements = React__namespace.useMemo(() => ({
4204
+ reference: referenceEl,
4205
+ floating: floatingEl
4206
+ }), [referenceEl, floatingEl]);
4207
+ const floatingStyles = React__namespace.useMemo(() => {
4208
+ const initialStyles = {
4209
+ position: strategy,
4210
+ left: 0,
4211
+ top: 0
4212
+ };
4213
+ if (!elements.floating) {
4214
+ return initialStyles;
4215
+ }
4216
+ const x = roundByDPR(elements.floating, data.x);
4217
+ const y = roundByDPR(elements.floating, data.y);
4218
+ if (transform) {
4219
+ return {
4220
+ ...initialStyles,
4221
+ transform: "translate(" + x + "px, " + y + "px)",
4222
+ ...(getDPR(elements.floating) >= 1.5 && {
4223
+ willChange: 'transform'
4224
+ })
4225
+ };
4226
+ }
4227
+ return {
4228
+ position: strategy,
4229
+ left: x,
4230
+ top: y
4231
+ };
4232
+ }, [strategy, transform, elements.floating, data.x, data.y]);
4233
+ return React__namespace.useMemo(() => ({
4234
+ ...data,
4235
+ update,
4236
+ refs,
4237
+ elements,
4238
+ floatingStyles
4239
+ }), [data, update, refs, elements, floatingStyles]);
4240
+ }
4241
+
4242
+ /**
4243
+ * Provides data to position an inner element of the floating element so that it
4244
+ * appears centered to the reference element.
4245
+ * This wraps the core `arrow` middleware to allow React refs as the element.
4246
+ * @see https://floating-ui.com/docs/arrow
4247
+ */
4248
+ const arrow$1 = options => {
4249
+ function isRef(value) {
4250
+ return {}.hasOwnProperty.call(value, 'current');
4251
+ }
4252
+ return {
4253
+ name: 'arrow',
4254
+ options,
4255
+ fn(state) {
4256
+ const {
4257
+ element,
4258
+ padding
4259
+ } = typeof options === 'function' ? options(state) : options;
4260
+ if (element && isRef(element)) {
4261
+ if (element.current != null) {
4262
+ return arrow$2({
4263
+ element: element.current,
4264
+ padding
4265
+ }).fn(state);
4266
+ }
4267
+ return {};
4268
+ }
4269
+ if (element) {
4270
+ return arrow$2({
4271
+ element,
4272
+ padding
4273
+ }).fn(state);
4274
+ }
4275
+ return {};
4276
+ }
4277
+ };
4278
+ };
4279
+
4280
+ /**
4281
+ * Modifies the placement by translating the floating element along the
4282
+ * specified axes.
4283
+ * A number (shorthand for `mainAxis` or distance), or an axes configuration
4284
+ * object may be passed.
4285
+ * @see https://floating-ui.com/docs/offset
4286
+ */
4287
+ const offset = (options, deps) => {
4288
+ const result = offset$1(options);
4289
+ return {
4290
+ name: result.name,
4291
+ fn: result.fn,
4292
+ options: [options, deps]
4293
+ };
4294
+ };
4295
+
4296
+ /**
4297
+ * Optimizes the visibility of the floating element by shifting it in order to
4298
+ * keep it in view when it will overflow the clipping boundary.
4299
+ * @see https://floating-ui.com/docs/shift
4300
+ */
4301
+ const shift = (options, deps) => {
4302
+ const result = shift$1(options);
4303
+ return {
4304
+ name: result.name,
4305
+ fn: result.fn,
4306
+ options: [options, deps]
4307
+ };
4308
+ };
4309
+
4310
+ /**
4311
+ * Built-in `limiter` that will stop `shift()` at a certain point.
4312
+ */
4313
+ const limitShift = (options, deps) => {
4314
+ const result = limitShift$1(options);
4315
+ return {
4316
+ fn: result.fn,
4317
+ options: [options, deps]
4318
+ };
4319
+ };
4320
+
4321
+ /**
4322
+ * Optimizes the visibility of the floating element by flipping the `placement`
4323
+ * in order to keep it in view when the preferred placement(s) will overflow the
4324
+ * clipping boundary. Alternative to `autoPlacement`.
4325
+ * @see https://floating-ui.com/docs/flip
4326
+ */
4327
+ const flip = (options, deps) => {
4328
+ const result = flip$1(options);
4329
+ return {
4330
+ name: result.name,
4331
+ fn: result.fn,
4332
+ options: [options, deps]
4333
+ };
4334
+ };
4335
+
4336
+ /**
4337
+ * Provides data that allows you to change the size of the floating element —
4338
+ * for instance, prevent it from overflowing the clipping boundary or match the
4339
+ * width of the reference element.
4340
+ * @see https://floating-ui.com/docs/size
4341
+ */
4342
+ const size = (options, deps) => {
4343
+ const result = size$1(options);
4344
+ return {
4345
+ name: result.name,
4346
+ fn: result.fn,
4347
+ options: [options, deps]
4348
+ };
4349
+ };
4350
+
4351
+ /**
4352
+ * Provides data to hide the floating element in applicable situations, such as
4353
+ * when it is not in the same clipping context as the reference element.
4354
+ * @see https://floating-ui.com/docs/hide
4355
+ */
4356
+ const hide = (options, deps) => {
4357
+ const result = hide$1(options);
4358
+ return {
4359
+ name: result.name,
4360
+ fn: result.fn,
4361
+ options: [options, deps]
4362
+ };
4363
+ };
4364
+
4365
+ /**
4366
+ * Provides data to position an inner element of the floating element so that it
4367
+ * appears centered to the reference element.
4368
+ * This wraps the core `arrow` middleware to allow React refs as the element.
4369
+ * @see https://floating-ui.com/docs/arrow
4370
+ */
4371
+ const arrow = (options, deps) => {
4372
+ const result = arrow$1(options);
4373
+ return {
4374
+ name: result.name,
4375
+ fn: result.fn,
4376
+ options: [options, deps]
4377
+ };
4378
+ };
4379
+
4380
+ // src/primitive.tsx
4381
+ var NODES = [
4382
+ "a",
4383
+ "button",
4384
+ "div",
4385
+ "form",
4386
+ "h2",
4387
+ "h3",
4388
+ "img",
4389
+ "input",
4390
+ "label",
4391
+ "li",
4392
+ "nav",
4393
+ "ol",
4394
+ "p",
4395
+ "select",
4396
+ "span",
4397
+ "svg",
4398
+ "ul"
4399
+ ];
4400
+ var Primitive = NODES.reduce((primitive, node) => {
4401
+ const Slot = reactSlot.createSlot(`Primitive.${node}`);
4402
+ const Node = React__namespace.forwardRef((props, forwardedRef) => {
4403
+ const { asChild, ...primitiveProps } = props;
4404
+ const Comp = asChild ? Slot : node;
4405
+ if (typeof window !== "undefined") {
4406
+ window[Symbol.for("radix-ui")] = true;
4407
+ }
4408
+ return /* @__PURE__ */ jsxRuntime.jsx(Comp, { ...primitiveProps, ref: forwardedRef });
4409
+ });
4410
+ Node.displayName = `Primitive.${node}`;
4411
+ return { ...primitive, [node]: Node };
4412
+ }, {});
4413
+ function dispatchDiscreteCustomEvent(target, event) {
4414
+ if (target) ReactDOM__namespace.flushSync(() => target.dispatchEvent(event));
4415
+ }
4416
+
4417
+ // src/arrow.tsx
4418
+ var NAME = "Arrow";
4419
+ var Arrow$1 = React__namespace.forwardRef((props, forwardedRef) => {
4420
+ const { children, width = 10, height = 5, ...arrowProps } = props;
4421
+ return /* @__PURE__ */ jsxRuntime.jsx(
4422
+ Primitive.svg,
4423
+ {
4424
+ ...arrowProps,
4425
+ ref: forwardedRef,
4426
+ width,
4427
+ height,
4428
+ viewBox: "0 0 30 10",
4429
+ preserveAspectRatio: "none",
4430
+ children: props.asChild ? children : /* @__PURE__ */ jsxRuntime.jsx("polygon", { points: "0,0 30,0 15,10" })
4431
+ }
4432
+ );
4433
+ });
4434
+ Arrow$1.displayName = NAME;
4435
+ var Root = Arrow$1;
4436
+
4437
+ // packages/react/use-callback-ref/src/use-callback-ref.tsx
4438
+ function useCallbackRef(callback) {
4439
+ const callbackRef = React__namespace.useRef(callback);
4440
+ React__namespace.useEffect(() => {
4441
+ callbackRef.current = callback;
4442
+ });
4443
+ return React__namespace.useMemo(() => (...args) => callbackRef.current?.(...args), []);
4444
+ }
4445
+
4446
+ // packages/react/use-size/src/use-size.tsx
4447
+ function useSize(element) {
4448
+ const [size, setSize] = React__namespace.useState(void 0);
4449
+ useLayoutEffect2(() => {
4450
+ if (element) {
4451
+ setSize({ width: element.offsetWidth, height: element.offsetHeight });
4452
+ const resizeObserver = new ResizeObserver((entries) => {
4453
+ if (!Array.isArray(entries)) {
4454
+ return;
4455
+ }
4456
+ if (!entries.length) {
4457
+ return;
4458
+ }
4459
+ const entry = entries[0];
4460
+ let width;
4461
+ let height;
4462
+ if ("borderBoxSize" in entry) {
4463
+ const borderSizeEntry = entry["borderBoxSize"];
4464
+ const borderSize = Array.isArray(borderSizeEntry) ? borderSizeEntry[0] : borderSizeEntry;
4465
+ width = borderSize["inlineSize"];
4466
+ height = borderSize["blockSize"];
4467
+ } else {
4468
+ width = element.offsetWidth;
4469
+ height = element.offsetHeight;
4470
+ }
4471
+ setSize({ width, height });
4472
+ });
4473
+ resizeObserver.observe(element, { box: "border-box" });
4474
+ return () => resizeObserver.unobserve(element);
4475
+ } else {
4476
+ setSize(void 0);
4477
+ }
4478
+ }, [element]);
4479
+ return size;
4480
+ }
4481
+
4482
+ var POPPER_NAME = "Popper";
4483
+ var [createPopperContext, createPopperScope] = createContextScope(POPPER_NAME);
4484
+ var [PopperProvider, usePopperContext] = createPopperContext(POPPER_NAME);
4485
+ var Popper = (props) => {
4486
+ const { __scopePopper, children } = props;
4487
+ const [anchor, setAnchor] = React__namespace.useState(null);
4488
+ return /* @__PURE__ */ jsxRuntime.jsx(PopperProvider, { scope: __scopePopper, anchor, onAnchorChange: setAnchor, children });
4489
+ };
4490
+ Popper.displayName = POPPER_NAME;
4491
+ var ANCHOR_NAME = "PopperAnchor";
4492
+ var PopperAnchor = React__namespace.forwardRef(
4493
+ (props, forwardedRef) => {
4494
+ const { __scopePopper, virtualRef, ...anchorProps } = props;
4495
+ const context = usePopperContext(ANCHOR_NAME, __scopePopper);
4496
+ const ref = React__namespace.useRef(null);
4497
+ const composedRefs = useComposedRefs(forwardedRef, ref);
4498
+ const anchorRef = React__namespace.useRef(null);
2132
4499
  React__namespace.useEffect(() => {
2133
- if (isVisible) {
2134
- calculatePosition();
2135
- window.addEventListener("scroll", calculatePosition, true);
2136
- window.addEventListener("resize", calculatePosition);
2137
- }
2138
- return () => {
2139
- window.removeEventListener("scroll", calculatePosition, true);
2140
- window.removeEventListener("resize", calculatePosition);
2141
- };
2142
- }, [isVisible, calculatePosition]);
4500
+ const previousAnchor = anchorRef.current;
4501
+ anchorRef.current = virtualRef?.current || ref.current;
4502
+ if (previousAnchor !== anchorRef.current) {
4503
+ context.onAnchorChange(anchorRef.current);
4504
+ }
4505
+ });
4506
+ return virtualRef ? null : /* @__PURE__ */ jsxRuntime.jsx(Primitive.div, { ...anchorProps, ref: composedRefs });
4507
+ }
4508
+ );
4509
+ PopperAnchor.displayName = ANCHOR_NAME;
4510
+ var CONTENT_NAME$1 = "PopperContent";
4511
+ var [PopperContentProvider, useContentContext] = createPopperContext(CONTENT_NAME$1);
4512
+ var PopperContent = React__namespace.forwardRef(
4513
+ (props, forwardedRef) => {
4514
+ const {
4515
+ __scopePopper,
4516
+ side = "bottom",
4517
+ sideOffset = 0,
4518
+ align = "center",
4519
+ alignOffset = 0,
4520
+ arrowPadding = 0,
4521
+ avoidCollisions = true,
4522
+ collisionBoundary = [],
4523
+ collisionPadding: collisionPaddingProp = 0,
4524
+ sticky = "partial",
4525
+ hideWhenDetached = false,
4526
+ updatePositionStrategy = "optimized",
4527
+ onPlaced,
4528
+ ...contentProps
4529
+ } = props;
4530
+ const context = usePopperContext(CONTENT_NAME$1, __scopePopper);
4531
+ const [content, setContent] = React__namespace.useState(null);
4532
+ const composedRefs = useComposedRefs(forwardedRef, (node) => setContent(node));
4533
+ const [arrow$1, setArrow] = React__namespace.useState(null);
4534
+ const arrowSize = useSize(arrow$1);
4535
+ const arrowWidth = arrowSize?.width ?? 0;
4536
+ const arrowHeight = arrowSize?.height ?? 0;
4537
+ const desiredPlacement = side + (align !== "center" ? "-" + align : "");
4538
+ const collisionPadding = typeof collisionPaddingProp === "number" ? collisionPaddingProp : { top: 0, right: 0, bottom: 0, left: 0, ...collisionPaddingProp };
4539
+ const boundary = Array.isArray(collisionBoundary) ? collisionBoundary : [collisionBoundary];
4540
+ const hasExplicitBoundaries = boundary.length > 0;
4541
+ const detectOverflowOptions = {
4542
+ padding: collisionPadding,
4543
+ boundary: boundary.filter(isNotNull),
4544
+ // with `strategy: 'fixed'`, this is the only way to get it to respect boundaries
4545
+ altBoundary: hasExplicitBoundaries
4546
+ };
4547
+ const { refs, floatingStyles, placement, isPositioned, middlewareData } = useFloating({
4548
+ // default to `fixed` strategy so users don't have to pick and we also avoid focus scroll issues
4549
+ strategy: "fixed",
4550
+ placement: desiredPlacement,
4551
+ whileElementsMounted: (...args) => {
4552
+ const cleanup = autoUpdate(...args, {
4553
+ animationFrame: updatePositionStrategy === "always"
4554
+ });
4555
+ return cleanup;
4556
+ },
4557
+ elements: {
4558
+ reference: context.anchor
4559
+ },
4560
+ middleware: [
4561
+ offset({ mainAxis: sideOffset + arrowHeight, alignmentAxis: alignOffset }),
4562
+ avoidCollisions && shift({
4563
+ mainAxis: true,
4564
+ crossAxis: false,
4565
+ limiter: sticky === "partial" ? limitShift() : void 0,
4566
+ ...detectOverflowOptions
4567
+ }),
4568
+ avoidCollisions && flip({ ...detectOverflowOptions }),
4569
+ size({
4570
+ ...detectOverflowOptions,
4571
+ apply: ({ elements, rects, availableWidth, availableHeight }) => {
4572
+ const { width: anchorWidth, height: anchorHeight } = rects.reference;
4573
+ const contentStyle = elements.floating.style;
4574
+ contentStyle.setProperty("--radix-popper-available-width", `${availableWidth}px`);
4575
+ contentStyle.setProperty("--radix-popper-available-height", `${availableHeight}px`);
4576
+ contentStyle.setProperty("--radix-popper-anchor-width", `${anchorWidth}px`);
4577
+ contentStyle.setProperty("--radix-popper-anchor-height", `${anchorHeight}px`);
4578
+ }
4579
+ }),
4580
+ arrow$1 && arrow({ element: arrow$1, padding: arrowPadding }),
4581
+ transformOrigin({ arrowWidth, arrowHeight }),
4582
+ hideWhenDetached && hide({ strategy: "referenceHidden", ...detectOverflowOptions })
4583
+ ]
4584
+ });
4585
+ const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
4586
+ const handlePlaced = useCallbackRef(onPlaced);
4587
+ useLayoutEffect2(() => {
4588
+ if (isPositioned) {
4589
+ handlePlaced?.();
4590
+ }
4591
+ }, [isPositioned, handlePlaced]);
4592
+ const arrowX = middlewareData.arrow?.x;
4593
+ const arrowY = middlewareData.arrow?.y;
4594
+ const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
4595
+ const [contentZIndex, setContentZIndex] = React__namespace.useState();
4596
+ useLayoutEffect2(() => {
4597
+ if (content) setContentZIndex(window.getComputedStyle(content).zIndex);
4598
+ }, [content]);
4599
+ return /* @__PURE__ */ jsxRuntime.jsx(
4600
+ "div",
4601
+ {
4602
+ ref: refs.setFloating,
4603
+ "data-radix-popper-content-wrapper": "",
4604
+ style: {
4605
+ ...floatingStyles,
4606
+ transform: isPositioned ? floatingStyles.transform : "translate(0, -200%)",
4607
+ // keep off the page when measuring
4608
+ minWidth: "max-content",
4609
+ zIndex: contentZIndex,
4610
+ ["--radix-popper-transform-origin"]: [
4611
+ middlewareData.transformOrigin?.x,
4612
+ middlewareData.transformOrigin?.y
4613
+ ].join(" "),
4614
+ // hide the content if using the hide middleware and should be hidden
4615
+ // set visibility to hidden and disable pointer events so the UI behaves
4616
+ // as if the PopperContent isn't there at all
4617
+ ...middlewareData.hide?.referenceHidden && {
4618
+ visibility: "hidden",
4619
+ pointerEvents: "none"
4620
+ }
4621
+ },
4622
+ dir: props.dir,
4623
+ children: /* @__PURE__ */ jsxRuntime.jsx(
4624
+ PopperContentProvider,
4625
+ {
4626
+ scope: __scopePopper,
4627
+ placedSide,
4628
+ onArrowChange: setArrow,
4629
+ arrowX,
4630
+ arrowY,
4631
+ shouldHideArrow: cannotCenterArrow,
4632
+ children: /* @__PURE__ */ jsxRuntime.jsx(
4633
+ Primitive.div,
4634
+ {
4635
+ "data-side": placedSide,
4636
+ "data-align": placedAlign,
4637
+ ...contentProps,
4638
+ ref: composedRefs,
4639
+ style: {
4640
+ ...contentProps.style,
4641
+ // if the PopperContent hasn't been placed yet (not all measurements done)
4642
+ // we prevent animations so that users's animation don't kick in too early referring wrong sides
4643
+ animation: !isPositioned ? "none" : void 0
4644
+ }
4645
+ }
4646
+ )
4647
+ }
4648
+ )
4649
+ }
4650
+ );
4651
+ }
4652
+ );
4653
+ PopperContent.displayName = CONTENT_NAME$1;
4654
+ var ARROW_NAME$1 = "PopperArrow";
4655
+ var OPPOSITE_SIDE = {
4656
+ top: "bottom",
4657
+ right: "left",
4658
+ bottom: "top",
4659
+ left: "right"
4660
+ };
4661
+ var PopperArrow = React__namespace.forwardRef(function PopperArrow2(props, forwardedRef) {
4662
+ const { __scopePopper, ...arrowProps } = props;
4663
+ const contentContext = useContentContext(ARROW_NAME$1, __scopePopper);
4664
+ const baseSide = OPPOSITE_SIDE[contentContext.placedSide];
4665
+ return (
4666
+ // we have to use an extra wrapper because `ResizeObserver` (used by `useSize`)
4667
+ // doesn't report size as we'd expect on SVG elements.
4668
+ // it reports their bounding box which is effectively the largest path inside the SVG.
4669
+ /* @__PURE__ */ jsxRuntime.jsx(
4670
+ "span",
4671
+ {
4672
+ ref: contentContext.onArrowChange,
4673
+ style: {
4674
+ position: "absolute",
4675
+ left: contentContext.arrowX,
4676
+ top: contentContext.arrowY,
4677
+ [baseSide]: 0,
4678
+ transformOrigin: {
4679
+ top: "",
4680
+ right: "0 0",
4681
+ bottom: "center 0",
4682
+ left: "100% 0"
4683
+ }[contentContext.placedSide],
4684
+ transform: {
4685
+ top: "translateY(100%)",
4686
+ right: "translateY(50%) rotate(90deg) translateX(-50%)",
4687
+ bottom: `rotate(180deg)`,
4688
+ left: "translateY(50%) rotate(-90deg) translateX(50%)"
4689
+ }[contentContext.placedSide],
4690
+ visibility: contentContext.shouldHideArrow ? "hidden" : void 0
4691
+ },
4692
+ children: /* @__PURE__ */ jsxRuntime.jsx(
4693
+ Root,
4694
+ {
4695
+ ...arrowProps,
4696
+ ref: forwardedRef,
4697
+ style: {
4698
+ ...arrowProps.style,
4699
+ // ensures the element can be measured correctly (mostly for if SVG)
4700
+ display: "block"
4701
+ }
4702
+ }
4703
+ )
4704
+ }
4705
+ )
4706
+ );
4707
+ });
4708
+ PopperArrow.displayName = ARROW_NAME$1;
4709
+ function isNotNull(value) {
4710
+ return value !== null;
4711
+ }
4712
+ var transformOrigin = (options) => ({
4713
+ name: "transformOrigin",
4714
+ options,
4715
+ fn(data) {
4716
+ const { placement, rects, middlewareData } = data;
4717
+ const cannotCenterArrow = middlewareData.arrow?.centerOffset !== 0;
4718
+ const isArrowHidden = cannotCenterArrow;
4719
+ const arrowWidth = isArrowHidden ? 0 : options.arrowWidth;
4720
+ const arrowHeight = isArrowHidden ? 0 : options.arrowHeight;
4721
+ const [placedSide, placedAlign] = getSideAndAlignFromPlacement(placement);
4722
+ const noArrowAlign = { start: "0%", center: "50%", end: "100%" }[placedAlign];
4723
+ const arrowXCenter = (middlewareData.arrow?.x ?? 0) + arrowWidth / 2;
4724
+ const arrowYCenter = (middlewareData.arrow?.y ?? 0) + arrowHeight / 2;
4725
+ let x = "";
4726
+ let y = "";
4727
+ if (placedSide === "bottom") {
4728
+ x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
4729
+ y = `${-arrowHeight}px`;
4730
+ } else if (placedSide === "top") {
4731
+ x = isArrowHidden ? noArrowAlign : `${arrowXCenter}px`;
4732
+ y = `${rects.floating.height + arrowHeight}px`;
4733
+ } else if (placedSide === "right") {
4734
+ x = `${-arrowHeight}px`;
4735
+ y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
4736
+ } else if (placedSide === "left") {
4737
+ x = `${rects.floating.width + arrowHeight}px`;
4738
+ y = isArrowHidden ? noArrowAlign : `${arrowYCenter}px`;
4739
+ }
4740
+ return { data: { x, y } };
4741
+ }
4742
+ });
4743
+ function getSideAndAlignFromPlacement(placement) {
4744
+ const [side, align = "center"] = placement.split("-");
4745
+ return [side, align];
4746
+ }
4747
+ var Root2$1 = Popper;
4748
+ var Anchor = PopperAnchor;
4749
+ var Content = PopperContent;
4750
+ var Arrow = PopperArrow;
4751
+
4752
+ var PORTAL_NAME$1 = "Portal";
4753
+ var Portal$1 = React__namespace.forwardRef((props, forwardedRef) => {
4754
+ const { container: containerProp, ...portalProps } = props;
4755
+ const [mounted, setMounted] = React__namespace.useState(false);
4756
+ useLayoutEffect2(() => setMounted(true), []);
4757
+ const container = containerProp || mounted && globalThis?.document?.body;
4758
+ return container ? ReactDOM.createPortal(/* @__PURE__ */ jsxRuntime.jsx(Primitive.div, { ...portalProps, ref: forwardedRef }), container) : null;
4759
+ });
4760
+ Portal$1.displayName = PORTAL_NAME$1;
4761
+
4762
+ function useStateMachine(initialState, machine) {
4763
+ return React__namespace.useReducer((state, event) => {
4764
+ const nextState = machine[state][event];
4765
+ return nextState ?? state;
4766
+ }, initialState);
4767
+ }
4768
+
4769
+ // src/presence.tsx
4770
+ var Presence = (props) => {
4771
+ const { present, children } = props;
4772
+ const presence = usePresence(present);
4773
+ const child = typeof children === "function" ? children({ present: presence.isPresent }) : React__namespace.Children.only(children);
4774
+ const ref = useComposedRefs(presence.ref, getElementRef(child));
4775
+ const forceMount = typeof children === "function";
4776
+ return forceMount || presence.isPresent ? React__namespace.cloneElement(child, { ref }) : null;
4777
+ };
4778
+ Presence.displayName = "Presence";
4779
+ function usePresence(present) {
4780
+ const [node, setNode] = React__namespace.useState();
4781
+ const stylesRef = React__namespace.useRef(null);
4782
+ const prevPresentRef = React__namespace.useRef(present);
4783
+ const prevAnimationNameRef = React__namespace.useRef("none");
4784
+ const initialState = present ? "mounted" : "unmounted";
4785
+ const [state, send] = useStateMachine(initialState, {
4786
+ mounted: {
4787
+ UNMOUNT: "unmounted",
4788
+ ANIMATION_OUT: "unmountSuspended"
4789
+ },
4790
+ unmountSuspended: {
4791
+ MOUNT: "mounted",
4792
+ ANIMATION_END: "unmounted"
4793
+ },
4794
+ unmounted: {
4795
+ MOUNT: "mounted"
4796
+ }
4797
+ });
4798
+ React__namespace.useEffect(() => {
4799
+ const currentAnimationName = getAnimationName(stylesRef.current);
4800
+ prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
4801
+ }, [state]);
4802
+ useLayoutEffect2(() => {
4803
+ const styles = stylesRef.current;
4804
+ const wasPresent = prevPresentRef.current;
4805
+ const hasPresentChanged = wasPresent !== present;
4806
+ if (hasPresentChanged) {
4807
+ const prevAnimationName = prevAnimationNameRef.current;
4808
+ const currentAnimationName = getAnimationName(styles);
4809
+ if (present) {
4810
+ send("MOUNT");
4811
+ } else if (currentAnimationName === "none" || styles?.display === "none") {
4812
+ send("UNMOUNT");
4813
+ } else {
4814
+ const isAnimating = prevAnimationName !== currentAnimationName;
4815
+ if (wasPresent && isAnimating) {
4816
+ send("ANIMATION_OUT");
4817
+ } else {
4818
+ send("UNMOUNT");
4819
+ }
4820
+ }
4821
+ prevPresentRef.current = present;
4822
+ }
4823
+ }, [present, send]);
4824
+ useLayoutEffect2(() => {
4825
+ if (node) {
4826
+ let timeoutId;
4827
+ const ownerWindow = node.ownerDocument.defaultView ?? window;
4828
+ const handleAnimationEnd = (event) => {
4829
+ const currentAnimationName = getAnimationName(stylesRef.current);
4830
+ const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
4831
+ if (event.target === node && isCurrentAnimation) {
4832
+ send("ANIMATION_END");
4833
+ if (!prevPresentRef.current) {
4834
+ const currentFillMode = node.style.animationFillMode;
4835
+ node.style.animationFillMode = "forwards";
4836
+ timeoutId = ownerWindow.setTimeout(() => {
4837
+ if (node.style.animationFillMode === "forwards") {
4838
+ node.style.animationFillMode = currentFillMode;
4839
+ }
4840
+ });
4841
+ }
4842
+ }
4843
+ };
4844
+ const handleAnimationStart = (event) => {
4845
+ if (event.target === node) {
4846
+ prevAnimationNameRef.current = getAnimationName(stylesRef.current);
4847
+ }
4848
+ };
4849
+ node.addEventListener("animationstart", handleAnimationStart);
4850
+ node.addEventListener("animationcancel", handleAnimationEnd);
4851
+ node.addEventListener("animationend", handleAnimationEnd);
4852
+ return () => {
4853
+ ownerWindow.clearTimeout(timeoutId);
4854
+ node.removeEventListener("animationstart", handleAnimationStart);
4855
+ node.removeEventListener("animationcancel", handleAnimationEnd);
4856
+ node.removeEventListener("animationend", handleAnimationEnd);
4857
+ };
4858
+ } else {
4859
+ send("ANIMATION_END");
4860
+ }
4861
+ }, [node, send]);
4862
+ return {
4863
+ isPresent: ["mounted", "unmountSuspended"].includes(state),
4864
+ ref: React__namespace.useCallback((node2) => {
4865
+ stylesRef.current = node2 ? getComputedStyle(node2) : null;
4866
+ setNode(node2);
4867
+ }, [])
4868
+ };
4869
+ }
4870
+ function getAnimationName(styles) {
4871
+ return styles?.animationName || "none";
4872
+ }
4873
+ function getElementRef(element) {
4874
+ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
4875
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
4876
+ if (mayWarn) {
4877
+ return element.ref;
4878
+ }
4879
+ getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
4880
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
4881
+ if (mayWarn) {
4882
+ return element.props.ref;
4883
+ }
4884
+ return element.props.ref || element.ref;
4885
+ }
4886
+
4887
+ // packages/react/use-escape-keydown/src/use-escape-keydown.tsx
4888
+ function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = globalThis?.document) {
4889
+ const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);
4890
+ React__namespace.useEffect(() => {
4891
+ const handleKeyDown = (event) => {
4892
+ if (event.key === "Escape") {
4893
+ onEscapeKeyDown(event);
4894
+ }
4895
+ };
4896
+ ownerDocument.addEventListener("keydown", handleKeyDown, { capture: true });
4897
+ return () => ownerDocument.removeEventListener("keydown", handleKeyDown, { capture: true });
4898
+ }, [onEscapeKeyDown, ownerDocument]);
4899
+ }
4900
+
4901
+ var DISMISSABLE_LAYER_NAME = "DismissableLayer";
4902
+ var CONTEXT_UPDATE = "dismissableLayer.update";
4903
+ var POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside";
4904
+ var FOCUS_OUTSIDE = "dismissableLayer.focusOutside";
4905
+ var originalBodyPointerEvents;
4906
+ var DismissableLayerContext = React__namespace.createContext({
4907
+ layers: /* @__PURE__ */ new Set(),
4908
+ layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
4909
+ branches: /* @__PURE__ */ new Set()
4910
+ });
4911
+ var DismissableLayer = React__namespace.forwardRef(
4912
+ (props, forwardedRef) => {
4913
+ const {
4914
+ disableOutsidePointerEvents = false,
4915
+ onEscapeKeyDown,
4916
+ onPointerDownOutside,
4917
+ onFocusOutside,
4918
+ onInteractOutside,
4919
+ onDismiss,
4920
+ ...layerProps
4921
+ } = props;
4922
+ const context = React__namespace.useContext(DismissableLayerContext);
4923
+ const [node, setNode] = React__namespace.useState(null);
4924
+ const ownerDocument = node?.ownerDocument ?? globalThis?.document;
4925
+ const [, force] = React__namespace.useState({});
4926
+ const composedRefs = useComposedRefs(forwardedRef, (node2) => setNode(node2));
4927
+ const layers = Array.from(context.layers);
4928
+ const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1);
4929
+ const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
4930
+ const index = node ? layers.indexOf(node) : -1;
4931
+ const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
4932
+ const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
4933
+ const pointerDownOutside = usePointerDownOutside((event) => {
4934
+ const target = event.target;
4935
+ const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));
4936
+ if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
4937
+ onPointerDownOutside?.(event);
4938
+ onInteractOutside?.(event);
4939
+ if (!event.defaultPrevented) onDismiss?.();
4940
+ }, ownerDocument);
4941
+ const focusOutside = useFocusOutside((event) => {
4942
+ const target = event.target;
4943
+ const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));
4944
+ if (isFocusInBranch) return;
4945
+ onFocusOutside?.(event);
4946
+ onInteractOutside?.(event);
4947
+ if (!event.defaultPrevented) onDismiss?.();
4948
+ }, ownerDocument);
4949
+ useEscapeKeydown((event) => {
4950
+ const isHighestLayer = index === context.layers.size - 1;
4951
+ if (!isHighestLayer) return;
4952
+ onEscapeKeyDown?.(event);
4953
+ if (!event.defaultPrevented && onDismiss) {
4954
+ event.preventDefault();
4955
+ onDismiss();
4956
+ }
4957
+ }, ownerDocument);
2143
4958
  React__namespace.useEffect(() => {
2144
- // Reset actualPlacement when placement prop changes
2145
- setActualPlacement(placement);
2146
- }, [placement]);
4959
+ if (!node) return;
4960
+ if (disableOutsidePointerEvents) {
4961
+ if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
4962
+ originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
4963
+ ownerDocument.body.style.pointerEvents = "none";
4964
+ }
4965
+ context.layersWithOutsidePointerEventsDisabled.add(node);
4966
+ }
4967
+ context.layers.add(node);
4968
+ dispatchUpdate();
4969
+ return () => {
4970
+ if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) {
4971
+ ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
4972
+ }
4973
+ };
4974
+ }, [node, ownerDocument, disableOutsidePointerEvents, context]);
2147
4975
  React__namespace.useEffect(() => {
2148
- return () => {
2149
- if (timeoutRef.current) {
2150
- clearTimeout(timeoutRef.current);
2151
- }
2152
- };
4976
+ return () => {
4977
+ if (!node) return;
4978
+ context.layers.delete(node);
4979
+ context.layersWithOutsidePointerEventsDisabled.delete(node);
4980
+ dispatchUpdate();
4981
+ };
4982
+ }, [node, context]);
4983
+ React__namespace.useEffect(() => {
4984
+ const handleUpdate = () => force({});
4985
+ document.addEventListener(CONTEXT_UPDATE, handleUpdate);
4986
+ return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
2153
4987
  }, []);
2154
- // Merge refs function
2155
- const mergeRefs = (...refs) => {
2156
- return (node) => {
2157
- refs.forEach((ref) => {
2158
- if (typeof ref === "function") {
2159
- ref(node);
2160
- }
2161
- else if (ref && typeof ref === "object" && "current" in ref) {
2162
- ref.current = node;
2163
- }
2164
- });
4988
+ return /* @__PURE__ */ jsxRuntime.jsx(
4989
+ Primitive.div,
4990
+ {
4991
+ ...layerProps,
4992
+ ref: composedRefs,
4993
+ style: {
4994
+ pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
4995
+ ...props.style
4996
+ },
4997
+ onFocusCapture: composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
4998
+ onBlurCapture: composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
4999
+ onPointerDownCapture: composeEventHandlers(
5000
+ props.onPointerDownCapture,
5001
+ pointerDownOutside.onPointerDownCapture
5002
+ )
5003
+ }
5004
+ );
5005
+ }
5006
+ );
5007
+ DismissableLayer.displayName = DISMISSABLE_LAYER_NAME;
5008
+ var BRANCH_NAME = "DismissableLayerBranch";
5009
+ var DismissableLayerBranch = React__namespace.forwardRef((props, forwardedRef) => {
5010
+ const context = React__namespace.useContext(DismissableLayerContext);
5011
+ const ref = React__namespace.useRef(null);
5012
+ const composedRefs = useComposedRefs(forwardedRef, ref);
5013
+ React__namespace.useEffect(() => {
5014
+ const node = ref.current;
5015
+ if (node) {
5016
+ context.branches.add(node);
5017
+ return () => {
5018
+ context.branches.delete(node);
5019
+ };
5020
+ }
5021
+ }, [context.branches]);
5022
+ return /* @__PURE__ */ jsxRuntime.jsx(Primitive.div, { ...props, ref: composedRefs });
5023
+ });
5024
+ DismissableLayerBranch.displayName = BRANCH_NAME;
5025
+ function usePointerDownOutside(onPointerDownOutside, ownerDocument = globalThis?.document) {
5026
+ const handlePointerDownOutside = useCallbackRef(onPointerDownOutside);
5027
+ const isPointerInsideReactTreeRef = React__namespace.useRef(false);
5028
+ const handleClickRef = React__namespace.useRef(() => {
5029
+ });
5030
+ React__namespace.useEffect(() => {
5031
+ const handlePointerDown = (event) => {
5032
+ if (event.target && !isPointerInsideReactTreeRef.current) {
5033
+ let handleAndDispatchPointerDownOutsideEvent2 = function() {
5034
+ handleAndDispatchCustomEvent(
5035
+ POINTER_DOWN_OUTSIDE,
5036
+ handlePointerDownOutside,
5037
+ eventDetail,
5038
+ { discrete: true }
5039
+ );
2165
5040
  };
5041
+ const eventDetail = { originalEvent: event };
5042
+ if (event.pointerType === "touch") {
5043
+ ownerDocument.removeEventListener("click", handleClickRef.current);
5044
+ handleClickRef.current = handleAndDispatchPointerDownOutsideEvent2;
5045
+ ownerDocument.addEventListener("click", handleClickRef.current, { once: true });
5046
+ } else {
5047
+ handleAndDispatchPointerDownOutsideEvent2();
5048
+ }
5049
+ } else {
5050
+ ownerDocument.removeEventListener("click", handleClickRef.current);
5051
+ }
5052
+ isPointerInsideReactTreeRef.current = false;
2166
5053
  };
2167
- // Clone the child element and add event handlers
2168
- const trigger = React__namespace.cloneElement(children, {
2169
- ref: mergeRefs(triggerRef, children.ref),
2170
- onMouseEnter: (e) => {
2171
- handleMouseEnter();
2172
- children.props.onMouseEnter?.(e);
2173
- },
2174
- onMouseLeave: (e) => {
2175
- handleMouseLeave();
2176
- children.props.onMouseLeave?.(e);
2177
- },
2178
- onFocus: (e) => {
2179
- handleFocus();
2180
- children.props.onFocus?.(e);
2181
- },
2182
- onBlur: (e) => {
2183
- handleBlur();
2184
- children.props.onBlur?.(e);
2185
- },
2186
- "aria-describedby": isVisible ? "tooltip-content" : undefined,
2187
- });
2188
- return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [trigger, jsxRuntime.jsxs("div", { ref: mergeRefs(tooltipRef, ref), id: "tooltip-content", role: "tooltip", className: cn(tooltipVariants({ isVisible }), className), style: {
2189
- top: `${position.top}px`,
2190
- left: `${position.left}px`,
2191
- }, "aria-hidden": !isVisible, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, children: [showArrow && (jsxRuntime.jsx("div", { className: cn(tooltipArrowVariants({ placement: actualPlacement })), style: {
2192
- left: `${arrowPosition.left}px`,
2193
- } })), jsxRuntime.jsxs("div", { className: "relative flex flex-col gap-2", children: [heading && (jsxRuntime.jsx(Text, { variant: "body", size: "medium", weight: "semibold", color: "onPrimary", children: heading })), jsxRuntime.jsx(Text, { variant: "body", size: "small", weight: "regular", color: "onPrimary", children: description })] })] })] }));
5054
+ const timerId = window.setTimeout(() => {
5055
+ ownerDocument.addEventListener("pointerdown", handlePointerDown);
5056
+ }, 0);
5057
+ return () => {
5058
+ window.clearTimeout(timerId);
5059
+ ownerDocument.removeEventListener("pointerdown", handlePointerDown);
5060
+ ownerDocument.removeEventListener("click", handleClickRef.current);
5061
+ };
5062
+ }, [ownerDocument, handlePointerDownOutside]);
5063
+ return {
5064
+ // ensures we check React component tree (not just DOM tree)
5065
+ onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
5066
+ };
5067
+ }
5068
+ function useFocusOutside(onFocusOutside, ownerDocument = globalThis?.document) {
5069
+ const handleFocusOutside = useCallbackRef(onFocusOutside);
5070
+ const isFocusInsideReactTreeRef = React__namespace.useRef(false);
5071
+ React__namespace.useEffect(() => {
5072
+ const handleFocus = (event) => {
5073
+ if (event.target && !isFocusInsideReactTreeRef.current) {
5074
+ const eventDetail = { originalEvent: event };
5075
+ handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
5076
+ discrete: false
5077
+ });
5078
+ }
5079
+ };
5080
+ ownerDocument.addEventListener("focusin", handleFocus);
5081
+ return () => ownerDocument.removeEventListener("focusin", handleFocus);
5082
+ }, [ownerDocument, handleFocusOutside]);
5083
+ return {
5084
+ onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
5085
+ onBlurCapture: () => isFocusInsideReactTreeRef.current = false
5086
+ };
5087
+ }
5088
+ function dispatchUpdate() {
5089
+ const event = new CustomEvent(CONTEXT_UPDATE);
5090
+ document.dispatchEvent(event);
5091
+ }
5092
+ function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
5093
+ const target = detail.originalEvent.target;
5094
+ const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });
5095
+ if (handler) target.addEventListener(name, handler, { once: true });
5096
+ if (discrete) {
5097
+ dispatchDiscreteCustomEvent(target, event);
5098
+ } else {
5099
+ target.dispatchEvent(event);
5100
+ }
5101
+ }
5102
+
5103
+ var originalBodyUserSelect;
5104
+ var HOVERCARD_NAME = "HoverCard";
5105
+ var [createHoverCardContext] = createContextScope(HOVERCARD_NAME, [
5106
+ createPopperScope
5107
+ ]);
5108
+ var usePopperScope = createPopperScope();
5109
+ var [HoverCardProvider, useHoverCardContext] = createHoverCardContext(HOVERCARD_NAME);
5110
+ var HoverCard = (props) => {
5111
+ const {
5112
+ __scopeHoverCard,
5113
+ children,
5114
+ open: openProp,
5115
+ defaultOpen,
5116
+ onOpenChange,
5117
+ openDelay = 700,
5118
+ closeDelay = 300
5119
+ } = props;
5120
+ const popperScope = usePopperScope(__scopeHoverCard);
5121
+ const openTimerRef = React__namespace.useRef(0);
5122
+ const closeTimerRef = React__namespace.useRef(0);
5123
+ const hasSelectionRef = React__namespace.useRef(false);
5124
+ const isPointerDownOnContentRef = React__namespace.useRef(false);
5125
+ const [open, setOpen] = useControllableState({
5126
+ prop: openProp,
5127
+ defaultProp: defaultOpen ?? false,
5128
+ onChange: onOpenChange,
5129
+ caller: HOVERCARD_NAME
5130
+ });
5131
+ const handleOpen = React__namespace.useCallback(() => {
5132
+ clearTimeout(closeTimerRef.current);
5133
+ openTimerRef.current = window.setTimeout(() => setOpen(true), openDelay);
5134
+ }, [openDelay, setOpen]);
5135
+ const handleClose = React__namespace.useCallback(() => {
5136
+ clearTimeout(openTimerRef.current);
5137
+ if (!hasSelectionRef.current && !isPointerDownOnContentRef.current) {
5138
+ closeTimerRef.current = window.setTimeout(() => setOpen(false), closeDelay);
5139
+ }
5140
+ }, [closeDelay, setOpen]);
5141
+ const handleDismiss = React__namespace.useCallback(() => setOpen(false), [setOpen]);
5142
+ React__namespace.useEffect(() => {
5143
+ return () => {
5144
+ clearTimeout(openTimerRef.current);
5145
+ clearTimeout(closeTimerRef.current);
5146
+ };
5147
+ }, []);
5148
+ return /* @__PURE__ */ jsxRuntime.jsx(
5149
+ HoverCardProvider,
5150
+ {
5151
+ scope: __scopeHoverCard,
5152
+ open,
5153
+ onOpenChange: setOpen,
5154
+ onOpen: handleOpen,
5155
+ onClose: handleClose,
5156
+ onDismiss: handleDismiss,
5157
+ hasSelectionRef,
5158
+ isPointerDownOnContentRef,
5159
+ children: /* @__PURE__ */ jsxRuntime.jsx(Root2$1, { ...popperScope, children })
5160
+ }
5161
+ );
5162
+ };
5163
+ HoverCard.displayName = HOVERCARD_NAME;
5164
+ var TRIGGER_NAME = "HoverCardTrigger";
5165
+ var HoverCardTrigger = React__namespace.forwardRef(
5166
+ (props, forwardedRef) => {
5167
+ const { __scopeHoverCard, ...triggerProps } = props;
5168
+ const context = useHoverCardContext(TRIGGER_NAME, __scopeHoverCard);
5169
+ const popperScope = usePopperScope(__scopeHoverCard);
5170
+ return /* @__PURE__ */ jsxRuntime.jsx(Anchor, { asChild: true, ...popperScope, children: /* @__PURE__ */ jsxRuntime.jsx(
5171
+ Primitive.a,
5172
+ {
5173
+ "data-state": context.open ? "open" : "closed",
5174
+ ...triggerProps,
5175
+ ref: forwardedRef,
5176
+ onPointerEnter: composeEventHandlers(props.onPointerEnter, excludeTouch(context.onOpen)),
5177
+ onPointerLeave: composeEventHandlers(props.onPointerLeave, excludeTouch(context.onClose)),
5178
+ onFocus: composeEventHandlers(props.onFocus, context.onOpen),
5179
+ onBlur: composeEventHandlers(props.onBlur, context.onClose),
5180
+ onTouchStart: composeEventHandlers(props.onTouchStart, (event) => event.preventDefault())
5181
+ }
5182
+ ) });
5183
+ }
5184
+ );
5185
+ HoverCardTrigger.displayName = TRIGGER_NAME;
5186
+ var PORTAL_NAME = "HoverCardPortal";
5187
+ var [PortalProvider, usePortalContext] = createHoverCardContext(PORTAL_NAME, {
5188
+ forceMount: void 0
5189
+ });
5190
+ var HoverCardPortal = (props) => {
5191
+ const { __scopeHoverCard, forceMount, children, container } = props;
5192
+ const context = useHoverCardContext(PORTAL_NAME, __scopeHoverCard);
5193
+ return /* @__PURE__ */ jsxRuntime.jsx(PortalProvider, { scope: __scopeHoverCard, forceMount, children: /* @__PURE__ */ jsxRuntime.jsx(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsxRuntime.jsx(Portal$1, { asChild: true, container, children }) }) });
5194
+ };
5195
+ HoverCardPortal.displayName = PORTAL_NAME;
5196
+ var CONTENT_NAME = "HoverCardContent";
5197
+ var HoverCardContent = React__namespace.forwardRef(
5198
+ (props, forwardedRef) => {
5199
+ const portalContext = usePortalContext(CONTENT_NAME, props.__scopeHoverCard);
5200
+ const { forceMount = portalContext.forceMount, ...contentProps } = props;
5201
+ const context = useHoverCardContext(CONTENT_NAME, props.__scopeHoverCard);
5202
+ return /* @__PURE__ */ jsxRuntime.jsx(Presence, { present: forceMount || context.open, children: /* @__PURE__ */ jsxRuntime.jsx(
5203
+ HoverCardContentImpl,
5204
+ {
5205
+ "data-state": context.open ? "open" : "closed",
5206
+ ...contentProps,
5207
+ onPointerEnter: composeEventHandlers(props.onPointerEnter, excludeTouch(context.onOpen)),
5208
+ onPointerLeave: composeEventHandlers(props.onPointerLeave, excludeTouch(context.onClose)),
5209
+ ref: forwardedRef
5210
+ }
5211
+ ) });
5212
+ }
5213
+ );
5214
+ HoverCardContent.displayName = CONTENT_NAME;
5215
+ var HoverCardContentImpl = React__namespace.forwardRef((props, forwardedRef) => {
5216
+ const {
5217
+ __scopeHoverCard,
5218
+ onEscapeKeyDown,
5219
+ onPointerDownOutside,
5220
+ onFocusOutside,
5221
+ onInteractOutside,
5222
+ ...contentProps
5223
+ } = props;
5224
+ const context = useHoverCardContext(CONTENT_NAME, __scopeHoverCard);
5225
+ const popperScope = usePopperScope(__scopeHoverCard);
5226
+ const ref = React__namespace.useRef(null);
5227
+ const composedRefs = useComposedRefs(forwardedRef, ref);
5228
+ const [containSelection, setContainSelection] = React__namespace.useState(false);
5229
+ React__namespace.useEffect(() => {
5230
+ if (containSelection) {
5231
+ const body = document.body;
5232
+ originalBodyUserSelect = body.style.userSelect || body.style.webkitUserSelect;
5233
+ body.style.userSelect = "none";
5234
+ body.style.webkitUserSelect = "none";
5235
+ return () => {
5236
+ body.style.userSelect = originalBodyUserSelect;
5237
+ body.style.webkitUserSelect = originalBodyUserSelect;
5238
+ };
5239
+ }
5240
+ }, [containSelection]);
5241
+ React__namespace.useEffect(() => {
5242
+ if (ref.current) {
5243
+ const handlePointerUp = () => {
5244
+ setContainSelection(false);
5245
+ context.isPointerDownOnContentRef.current = false;
5246
+ setTimeout(() => {
5247
+ const hasSelection = document.getSelection()?.toString() !== "";
5248
+ if (hasSelection) context.hasSelectionRef.current = true;
5249
+ });
5250
+ };
5251
+ document.addEventListener("pointerup", handlePointerUp);
5252
+ return () => {
5253
+ document.removeEventListener("pointerup", handlePointerUp);
5254
+ context.hasSelectionRef.current = false;
5255
+ context.isPointerDownOnContentRef.current = false;
5256
+ };
5257
+ }
5258
+ }, [context.isPointerDownOnContentRef, context.hasSelectionRef]);
5259
+ React__namespace.useEffect(() => {
5260
+ if (ref.current) {
5261
+ const tabbables = getTabbableNodes(ref.current);
5262
+ tabbables.forEach((tabbable) => tabbable.setAttribute("tabindex", "-1"));
5263
+ }
5264
+ });
5265
+ return /* @__PURE__ */ jsxRuntime.jsx(
5266
+ DismissableLayer,
5267
+ {
5268
+ asChild: true,
5269
+ disableOutsidePointerEvents: false,
5270
+ onInteractOutside,
5271
+ onEscapeKeyDown,
5272
+ onPointerDownOutside,
5273
+ onFocusOutside: composeEventHandlers(onFocusOutside, (event) => {
5274
+ event.preventDefault();
5275
+ }),
5276
+ onDismiss: context.onDismiss,
5277
+ children: /* @__PURE__ */ jsxRuntime.jsx(
5278
+ Content,
5279
+ {
5280
+ ...popperScope,
5281
+ ...contentProps,
5282
+ onPointerDown: composeEventHandlers(contentProps.onPointerDown, (event) => {
5283
+ if (event.currentTarget.contains(event.target)) {
5284
+ setContainSelection(true);
5285
+ }
5286
+ context.hasSelectionRef.current = false;
5287
+ context.isPointerDownOnContentRef.current = true;
5288
+ }),
5289
+ ref: composedRefs,
5290
+ style: {
5291
+ ...contentProps.style,
5292
+ userSelect: containSelection ? "text" : void 0,
5293
+ // Safari requires prefix
5294
+ WebkitUserSelect: containSelection ? "text" : void 0,
5295
+ // re-namespace exposed content custom properties
5296
+ ...{
5297
+ "--radix-hover-card-content-transform-origin": "var(--radix-popper-transform-origin)",
5298
+ "--radix-hover-card-content-available-width": "var(--radix-popper-available-width)",
5299
+ "--radix-hover-card-content-available-height": "var(--radix-popper-available-height)",
5300
+ "--radix-hover-card-trigger-width": "var(--radix-popper-anchor-width)",
5301
+ "--radix-hover-card-trigger-height": "var(--radix-popper-anchor-height)"
5302
+ }
5303
+ }
5304
+ }
5305
+ )
5306
+ }
5307
+ );
5308
+ });
5309
+ var ARROW_NAME = "HoverCardArrow";
5310
+ var HoverCardArrow = React__namespace.forwardRef(
5311
+ (props, forwardedRef) => {
5312
+ const { __scopeHoverCard, ...arrowProps } = props;
5313
+ const popperScope = usePopperScope(__scopeHoverCard);
5314
+ return /* @__PURE__ */ jsxRuntime.jsx(Arrow, { ...popperScope, ...arrowProps, ref: forwardedRef });
5315
+ }
5316
+ );
5317
+ HoverCardArrow.displayName = ARROW_NAME;
5318
+ function excludeTouch(eventHandler) {
5319
+ return (event) => event.pointerType === "touch" ? void 0 : eventHandler();
5320
+ }
5321
+ function getTabbableNodes(container) {
5322
+ const nodes = [];
5323
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
5324
+ acceptNode: (node) => {
5325
+ return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
5326
+ }
5327
+ });
5328
+ while (walker.nextNode()) nodes.push(walker.currentNode);
5329
+ return nodes;
5330
+ }
5331
+ var Root2 = HoverCard;
5332
+ var Trigger = HoverCardTrigger;
5333
+ var Portal = HoverCardPortal;
5334
+ var Content2 = HoverCardContent;
5335
+ var Arrow2 = HoverCardArrow;
5336
+
5337
+ const tooltipVariants = classVarianceAuthority.cva("z-[9998] bg-popup-fill-intense text-action-ink-on-primary-normal border border-popup-outline-subtle flex flex-col p-4 rounded-xlarge min-w-[200px] max-w-[300px] shadow-[0_4px_20px_rgba(0,0,0,0.15)]");
5338
+ const Tooltip = React__namespace.forwardRef(({ children, heading, description, placement = "top", showArrow = true, className, delay = 200, disabled = false, }, ref) => {
5339
+ const [open, setOpen] = React__namespace.useState(false);
5340
+ const { side, align } = React__namespace.useMemo(() => {
5341
+ switch (placement) {
5342
+ case "top-start":
5343
+ return { side: "top", align: "start" };
5344
+ case "top-end":
5345
+ return { side: "top", align: "end" };
5346
+ case "bottom-start":
5347
+ return { side: "bottom", align: "start" };
5348
+ case "bottom-end":
5349
+ return { side: "bottom", align: "end" };
5350
+ case "bottom":
5351
+ return { side: "bottom", align: "center" };
5352
+ case "top":
5353
+ default:
5354
+ return { side: "top", align: "center" };
5355
+ }
5356
+ }, [placement]);
5357
+ const handleOpenChange = (nextOpen) => {
5358
+ if (disabled) {
5359
+ setOpen(false);
5360
+ return;
5361
+ }
5362
+ setOpen(nextOpen);
5363
+ };
5364
+ return (jsxRuntime.jsxs(Root2, { open: disabled ? false : open, onOpenChange: handleOpenChange, openDelay: delay, closeDelay: 100, children: [jsxRuntime.jsx(Trigger, { asChild: true, children: children }), jsxRuntime.jsx(Portal, { children: jsxRuntime.jsxs(Content2, { ref: ref, role: "tooltip", side: side, align: align, sideOffset: 14, collisionPadding: 8, className: cn(tooltipVariants(), className), children: [showArrow && (jsxRuntime.jsx(Arrow2, { width: 12, height: 6, className: "fill-popup-fill-intense" })), jsxRuntime.jsxs("div", { className: "relative flex flex-col gap-2", children: [heading && (jsxRuntime.jsx(Text, { variant: "body", size: "medium", weight: "semibold", color: "onPrimary", children: heading })), jsxRuntime.jsx(Text, { variant: "body", size: "small", weight: "regular", color: "onPrimary", children: description })] })] }) })] }));
2194
5365
  });
2195
5366
  Tooltip.displayName = "Tooltip";
2196
5367
 
@@ -2632,7 +5803,7 @@ const DatePicker = React__namespace.forwardRef(({ className, value: controlledVa
2632
5803
  ];
2633
5804
  return weekdayNames[date.getDay()];
2634
5805
  } }) }) }));
2635
- return reactDom.createPortal(calendarPopup, document.body);
5806
+ return ReactDOM.createPortal(calendarPopup, document.body);
2636
5807
  })()] }));
2637
5808
  });
2638
5809
  DatePicker.displayName = "DatePicker";
@@ -3128,7 +6299,7 @@ const DateRangePicker = React__namespace.forwardRef(({ className, value: control
3128
6299
  : tempValue.endDate
3129
6300
  ? `Until ${formatDate(tempValue.endDate)}`
3130
6301
  : "No selection" })] }), jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [jsxRuntime.jsx(Button, { variant: "secondary", color: "neutral", size: "small", onClick: handleCancel, children: "Cancel" }), jsxRuntime.jsx(Button, { variant: "primary", color: "primary", size: "small", onClick: handleApply, children: "Apply date range" })] })] })] })] }) }));
3131
- return reactDom.createPortal(calendarPopup, document.body);
6302
+ return ReactDOM.createPortal(calendarPopup, document.body);
3132
6303
  })()] }));
3133
6304
  });
3134
6305
  DateRangePicker.displayName = "DateRangePicker";
@@ -4653,7 +7824,7 @@ const SearchableDropdown = React__namespace.forwardRef(({ className, items = [],
4653
7824
  }
4654
7825
  }, onClick: () => setIsOpen(true), readOnly: true, containerClassName: "mb-0", ...textFieldProps }))] }), typeof document !== "undefined" &&
4655
7826
  dropdownMenu &&
4656
- reactDom.createPortal(dropdownMenu, document.body)] }));
7827
+ ReactDOM.createPortal(dropdownMenu, document.body)] }));
4657
7828
  });
4658
7829
  SearchableDropdown.displayName = "SearchableDropdown";
4659
7830