{"version":3,"file":"chunk-Hooks.mjs","names":[],"sources":["../../src/hooks/theme.ts","../../src/hooks/useSafeCollisionPadding.ts","../../src/hooks/usePositioning.ts","../../src/hooks/useVisualViewport.ts","../../src/hooks/Hooks.ts"],"sourcesContent":["//\n// Copyright 2026 DXOS.org\n//\n\nimport { type ThemeMode } from '@dxos/ui-types';\n\nimport { useThemeContext } from './useThemeContext.ts';\n\n// Next styles through `.dx-*` CSS, so these read the existing ThemeProvider's values and never expose its `tx`.\n\n/** The ThemeProvider's light or dark mode. */\nexport const useThemeMode = (): ThemeMode => useThemeContext().themeMode;\n\n/** The ThemeProvider's platform, if the app set one. */\nexport const usePlatform = (): 'mobile' | 'desktop' | undefined => useThemeContext().platform;\n\n/** Whether the device shows an iOS on-screen keyboard (measured once by the ThemeProvider). */\nexport const useIosKeyboard = (): boolean => useThemeContext().hasIosKeyboard;\n","//\n// Copyright 2025 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { type SafeAreaPadding } from './useSafeArea.ts';\nimport { useThemeContext } from './useThemeContext.ts';\n\n/** A uniform inset, or one per side; Zag's `overflowPadding` takes one number, so the widest side wins. */\nexport type CollisionPadding = number | Partial<Record<'top' | 'right' | 'bottom' | 'left', number>>;\n\ntype PaddingProp = CollisionPadding | undefined;\ntype PaddingRecord = Exclude<PaddingProp, number | undefined>;\n\nconst propIsNumber = (prop: PaddingProp): prop is number => Number.isFinite(prop);\nconst propsIsRecord = (prop: PaddingProp): prop is PaddingRecord => !!(prop && typeof prop === 'object');\n\n// The safe area is optional on the theme context, and absent entirely when a consumer resolves the\n// fallback context — which any portalled surface does under the dev server's dual-module split. Its\n// insets are also `NaN` until the first viewport measurement, so every read here is already written\n// to fall back to zero; an absent object is the same case, not a different one.\nconst safePadding = (propsPadding: PaddingProp, safeArea: SafeAreaPadding | undefined, side: keyof SafeAreaPadding) => {\n  const inset = safeArea?.[side];\n  return (\n    (propIsNumber(inset) ? inset : 0) +\n    (propIsNumber(propsPadding) ? propsPadding : propsIsRecord(propsPadding) ? (propsPadding[side] ?? 0) : 0)\n  );\n};\n\nexport const useSafeCollisionPadding = (collisionPadding?: PaddingProp) => {\n  const { safeAreaPadding } = useThemeContext();\n  return useMemo(\n    () => ({\n      top: safePadding(collisionPadding, safeAreaPadding, 'top'),\n      right: safePadding(collisionPadding, safeAreaPadding, 'right'),\n      bottom: safePadding(collisionPadding, safeAreaPadding, 'bottom'),\n      left: safePadding(collisionPadding, safeAreaPadding, 'left'),\n    }),\n    [collisionPadding, safeAreaPadding],\n  );\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\nimport { type PopoverRootProps } from '@ark-ui/react/popover';\nimport { type RefObject, useCallback, useMemo, useState } from 'react';\n\nimport { type CollisionPadding, useSafeCollisionPadding } from './useSafeCollisionPadding.ts';\n\nexport type PositionSide = 'top' | 'right' | 'bottom' | 'left';\nexport type PositionAlign = 'start' | 'center' | 'end';\n\n/** How floating content wants to be placed; the machine, which the root owns, does the placing. */\nexport type PlacementOptions = {\n  side?: PositionSide;\n  align?: PositionAlign;\n  sideOffset?: number;\n  alignOffset?: number;\n  collisionPadding?: CollisionPadding;\n  collisionBoundary?: Element | null | Array<Element | null>;\n  avoidCollisions?: boolean;\n  hideWhenDetached?: boolean;\n};\n\n/** The `positioning` every Zag floating machine takes; the popover's is the shared shape. */\nexport type Positioning = NonNullable<PopoverRootProps['positioning']>;\n\n/** What a Zag machine accepts as the element its floating content is positioned against. */\nexport type AnchorElement = HTMLElement | { getBoundingClientRect: () => DOMRect; contextElement?: Element };\n\n/**\n * Hands a virtual anchor to the machine as its anchor element rather than as a bare rect: the\n * element is what the machine's scroll and resize observers attach to, so the content follows the\n * anchor when an ancestor scrolls.\n */\nexport const toAnchorElement = (element: Element | null): AnchorElement | null => {\n  if (element instanceof HTMLElement) {\n    return element;\n  }\n  return element ? { getBoundingClientRect: () => element.getBoundingClientRect(), contextElement: element } : null;\n};\n\nexport const toPlacement = (side: PositionSide = 'bottom', align: PositionAlign = 'center') =>\n  align === 'center' ? side : (`${side}-${align}` as const);\n\n/** Consumers hand the machine a per-side padding; it takes one number, so the widest side wins. */\nexport const toOverflowPadding = (padding: { top: number; right: number; bottom: number; left: number }) =>\n  Math.max(padding.top, padding.right, padding.bottom, padding.left);\n\nexport type UsePositioningOptions = {\n  open: boolean;\n  /** The element the content is placed at and bounded by, unless a virtual anchor stands in. */\n  triggerRef: RefObject<HTMLElement | null>;\n  placement: PlacementOptions;\n  defaultSide?: PositionSide;\n  defaultAlign?: PositionAlign;\n};\n\n/**\n * Radix-shaped placement props as one Zag `positioning` object, plus a virtual anchor the machine\n * positions at, and observes, in place of its trigger. Shared by every floating root so the\n * collision, offset and anchor semantics are one implementation.\n */\nexport type UsePositioningResult = {\n  positioning: Positioning;\n  /** Registers the element the content is positioned at instead of the trigger; returns the unregister. */\n  setVirtualAnchor: (ref: RefObject<Element | null>) => () => void;\n};\n\nexport const usePositioning = ({\n  open,\n  triggerRef,\n  placement: options,\n  defaultSide = 'bottom',\n  defaultAlign = 'center',\n}: UsePositioningOptions): UsePositioningResult => {\n  const [virtualAnchor, setVirtualAnchorState] = useState<RefObject<Element | null> | null>(null);\n  const setVirtualAnchor = useCallback((ref: RefObject<Element | null>) => {\n    setVirtualAnchorState(ref);\n    return () => setVirtualAnchorState((current) => (current === ref ? null : current));\n  }, []);\n\n  const {\n    side = defaultSide,\n    align = defaultAlign,\n    sideOffset = 0,\n    alignOffset,\n    collisionPadding = 8,\n    collisionBoundary,\n    avoidCollisions = true,\n    hideWhenDetached,\n  } = options;\n  const safeCollisionPadding = useSafeCollisionPadding(collisionPadding);\n  const overflowPadding = toOverflowPadding(safeCollisionPadding);\n\n  // The closest annotated ancestor bounds the content.\n  const boundary = useMemo(() => {\n    const closest = triggerRef.current?.closest<HTMLElement>('[data-popover-collision-boundary]') ?? null;\n    const given = Array.isArray(collisionBoundary) ? collisionBoundary : collisionBoundary ? [collisionBoundary] : [];\n    const elements = [closest, ...given].filter((element): element is Element => !!element);\n    return elements.length ? () => elements : undefined;\n    // The trigger is read when the content opens, which is when the boundary matters.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [open, collisionBoundary]);\n\n  const positioning = useMemo<Positioning>(\n    () => ({\n      strategy: 'fixed',\n      placement: toPlacement(side, align),\n      gutter: sideOffset,\n      ...(alignOffset !== undefined && { offset: { mainAxis: sideOffset, crossAxis: alignOffset } }),\n      overflowPadding,\n      // Keeps the arrow off the rounded corners, where its fill would paint over the curve.\n      arrowPadding: 12,\n      flip: avoidCollisions,\n      hideWhenDetached,\n      boundary,\n      ...(virtualAnchor && { getAnchorElement: () => toAnchorElement(virtualAnchor.current) }),\n    }),\n    [side, align, sideOffset, alignOffset, overflowPadding, avoidCollisions, hideWhenDetached, boundary, virtualAnchor],\n  );\n\n  return { positioning, setVirtualAnchor };\n};\n","//\n// Copyright 2023 DXOS.org\n//\n\nimport { useCallback, useState } from 'react';\n\nimport { useViewportResize } from '@dxos/react-hooks';\n\nexport const useVisualViewport = (deps?: Parameters<typeof useViewportResize>[1]) => {\n  const [width, setWidth] = useState<number | null>(null);\n  const [height, setHeight] = useState<number | null>(null);\n\n  const handleResize = useCallback(() => {\n    if (window.visualViewport) {\n      setWidth(window.visualViewport.width);\n      setHeight(window.visualViewport.height);\n    }\n  }, []);\n\n  useViewportResize(handleResize, deps);\n\n  return { width, height };\n};\n","//\n// Copyright 2026 DXOS.org\n//\n\n// @import-as-namespace\n\n// General-purpose hooks. A hook tied to one component family lives in that family's namespace.\n\n// Named rather than `export *`, so a release of `@dxos/react-hooks` cannot change this package's API.\nexport {\n  type AtomState,\n  type PossibleRef,\n  type UseControllableStateParams,\n  type UseMediaQueryOptions,\n  composeEventHandlers,\n  composeRefs,\n  createContext,\n  makeId,\n  mergeRefs,\n  randomString,\n  setRef,\n  useAsyncEffect,\n  useAsyncState,\n  useAtomState,\n  useComposedRefs,\n  useControllableState,\n  useControlledState,\n  useDebugDeps,\n  useDefaults,\n  useDefaultValue,\n  useDynamicRef,\n  useFileDownload,\n  useForwardedRef,\n  useId,\n  useInterval,\n  useIsFocused,\n  useMediaQuery,\n  useMergeRefs,\n  useMulticastObservable,\n  useOnTransition,\n  useRefCallback,\n  useScroller,\n  useSize,\n  useStable,\n  useStateWithRef,\n  useTimeout,\n  useViewportResize,\n} from '@dxos/react-hooks';\n\nexport { useTranslation } from '../providers/ThemeProvider/TranslationsContext.ts';\nexport * from './theme.ts';\nexport * from '../util/animation.ts';\nexport * from '../util/usePx.ts';\nexport * from './usePositioning.ts';\nexport * from './useSafeArea.ts';\nexport * from './useSafeCollisionPadding.ts';\nexport * from './useVisualViewport.ts';\n"],"mappings":";;;;;;;;;AAWA,IAAa,qBAAgC,gBAAgB,CAAC,CAAC;;AAG/D,IAAa,oBAAsD,gBAAgB,CAAC,CAAC;;AAGrF,IAAa,uBAAgC,gBAAgB,CAAC,CAAC;;;ACF/D,IAAM,gBAAgB,SAAsC,OAAO,SAAS,IAAI;AAChF,IAAM,iBAAiB,SAA6C,CAAC,EAAE,QAAQ,OAAO,SAAS;AAM/F,IAAM,eAAe,cAA2B,UAAuC,SAAgC;CACrH,MAAM,QAAQ,WAAW;CACzB,QACG,aAAa,KAAK,IAAI,QAAQ,MAC9B,aAAa,YAAY,IAAI,eAAe,cAAc,YAAY,IAAK,aAAa,SAAS,IAAK;AAE3G;AAEA,IAAa,2BAA2B,qBAAmC;CACzE,MAAM,EAAE,oBAAoB,gBAAgB;CAC5C,OAAO,eACE;EACL,KAAK,YAAY,kBAAkB,iBAAiB,KAAK;EACzD,OAAO,YAAY,kBAAkB,iBAAiB,OAAO;EAC7D,QAAQ,YAAY,kBAAkB,iBAAiB,QAAQ;EAC/D,MAAM,YAAY,kBAAkB,iBAAiB,MAAM;CAC7D,IACA,CAAC,kBAAkB,eAAe,CACpC;AACF;;;;;;;;ACNA,IAAa,mBAAmB,YAAkD;CAChF,IAAI,mBAAmB,aACrB,OAAO;CAET,OAAO,UAAU;EAAE,6BAA6B,QAAQ,sBAAsB;E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