{"version":3,"file":"SelectViewport.js","names":[],"sources":["jsx/SelectViewport.js"],"sourcesContent":["import { AdaptPortalContents, useAdaptIsActive } from \"@tamagui/adapt\";\nimport { AnimatePresence } from \"@tamagui/animate-presence\";\nimport { useComposedRefs } from \"@tamagui/compose-refs\";\nimport { isWeb, useIsomorphicLayoutEffect } from \"@tamagui/constants\";\nimport { createStyledHOC, splitStyleProps, styled, View } from \"@tamagui/core\";\nimport { needsPortalRepropagation } from \"@tamagui/portal\";\nimport { YStack } from \"@tamagui/stacks\";\nimport * as React from \"react\";\nimport { VIEWPORT_NAME } from \"./constants\";\nimport {\n  ForwardSelectContext,\n  useSelectContext,\n  useSelectItemParentContext\n} from \"./context\";\nimport { getSelectListboxProps } from \"./selectionController\";\nimport { Fragment, jsx, jsxs } from \"react/jsx-runtime\";\nconst SelectViewportFrame = styled(View, {\n  displayName: VIEWPORT_NAME,\n  position: \"relative\"\n});\nconst needsRepropagation = needsPortalRepropagation();\nconst getSheetFrameProps = (props) => {\n  const { className, style, \"data-tamagui-hoc-class\": _hocClassNames, ...rest } = props;\n  return splitStyleProps(rest)[1];\n};\nconst SelectViewport = createStyledHOC(\n  SelectViewportFrame,\n  function SelectViewport2(propsIn, forwardedRef) {\n    const props = propsIn;\n    const { scope, children, disableScroll, ...viewportProps } = props;\n    const context = useSelectContext(scope);\n    const itemContext = useSelectItemParentContext(scope);\n    const isAdapted = useAdaptIsActive(context.adaptScope);\n    const viewportRef = React.useRef(null);\n    const registeredItemCount = itemContext.registry.getItems().length;\n    const hasOpenedRef = React.useRef(!context.lazyMount);\n    if (context.open) hasOpenedRef.current = true;\n    const lazyMounted = hasOpenedRef.current;\n    React.useEffect(() => {\n      if (!isWeb || !isAdapted || !context.open) return;\n      const frame = requestAnimationFrame(() => {\n        const index = context.activeIndexRef.current ?? itemContext.registry.firstEnabledIndex();\n        const activeItem = viewportRef.current?.querySelector(\n          '[role=\"option\"][tabindex=\"0\"]'\n        ) ?? (index >= 0 ? itemContext.listRef?.current[index] : null);\n        activeItem?.focus();\n      });\n      return () => cancelAnimationFrame(frame);\n    }, [context.open, isAdapted, registeredItemCount]);\n    const composedRefs = useComposedRefs(\n      // @ts-ignore react 19 ref type mismatch\n      forwardedRef,\n      viewportRef,\n      context.floatingContext?.refs.setFloating\n    );\n    useIsomorphicLayoutEffect(() => {\n      if (context.update) {\n        context.update();\n      }\n    }, [isAdapted]);\n    React.useEffect(() => {\n      if (context.lazyMount && context.open && context.update) {\n        const frame = requestAnimationFrame(context.update);\n        return () => cancelAnimationFrame(frame);\n      }\n    }, [context.open, registeredItemCount]);\n    if (itemContext.shouldRenderWebNative) {\n      return /* @__PURE__ */ jsx(YStack, { position: \"relative\", children });\n    }\n    if (isAdapted || !isWeb) {\n      const frameProps = isAdapted ? getSheetFrameProps(viewportProps) : viewportProps;\n      let content = /* @__PURE__ */ jsx(\n        SelectViewportFrame,\n        {\n          ...frameProps,\n          ...isWeb ? getSelectListboxProps(itemContext.mode) : {},\n          \"data-select-viewport\": \"\",\n          ref: composedRefs,\n          children: lazyMounted ? children : null\n        }\n      );\n      if (needsRepropagation) {\n        content = /* @__PURE__ */ jsx(ForwardSelectContext, { itemContext, context, children: content });\n      }\n      return /* @__PURE__ */ jsx(AdaptPortalContents, { scope: context.adaptScope, children: content });\n    }\n    if (!context.interactions) {\n      return null;\n    }\n    const floatingProps = context.interactions.getFloatingProps();\n    return /* @__PURE__ */ jsxs(Fragment, { children: [\n      !disableScroll && /* @__PURE__ */ jsx(\n        \"style\",\n        {\n          dangerouslySetInnerHTML: {\n            __html: selectViewportCSS\n          }\n        }\n      ),\n      /* @__PURE__ */ jsx(AnimatePresence, { presenceAffectsLayout: false, children: context.open ? /* @__PURE__ */ jsx(\n        SelectViewportFrame,\n        {\n          \"data-select-viewport\": \"\",\n          ...isWeb && {\n            \"data-state\": context.open ? \"open\" : \"closed\"\n          },\n          ...viewportProps,\n          ...context.floatingPosition,\n          outlineWidth: 0,\n          ...floatingProps,\n          ...getSelectListboxProps(itemContext.mode),\n          overflowY: disableScroll ? void 0 : \"auto\",\n          ref: composedRefs,\n          children: lazyMounted ? children : null\n        },\n        \"select-viewport\"\n      ) : null }),\n      !context.open && !(context.lazyMount && context.renderValue) && lazyMounted && /* @__PURE__ */ jsx(\"div\", { style: { display: \"none\" }, children })\n    ] });\n  }\n);\nconst selectViewportCSS = `\n[data-select-viewport] {\n  scrollbar-width: none;\n  -webkit-overflow-scrolling: touch;\n  overscroll-behavior: none;\n}\n\n[data-select-viewport]::-webkit-scrollbar{\n  display:none\n}\n`;\nexport {\n  SelectViewport,\n  SelectViewportFrame\n};\n//# sourceMappingURL=SelectViewport.js.map\n"],"mappings":";;;;;;;;;;;;;;AAgBA,MAAM,sBAAsB,OAAO,MAAM;CACvC,aAAa;CACb,UAAU;AACZ,CAAC;AACD,MAAM,qBAAqB,yBAAyB;AACpD,MAAM,sBAAsB,UAAU;CACpC,MAAM,EAAE,WAAW,OAAO,0BAA0B,gBAAgB,GAAG,SAAS;CAChF,OAAO,gBAAgB,IAAI,CAAC,CAAC;AAC/B;AACA,MAAM,iBAAiB,gBACrB,qBACA,SAAS,gBAAgB,SAAS,cAAc;CAC9C,MAAM,QAAQ;CACd,MAAM,EAAE,OAAO,UAAU,eAAe,GAAG,kBAAkB;CAC7D,MAAM,UAAU,iBAAiB,KAAK;CACtC,MAAM,cAAc,2BAA2B,KAAK;CACpD,MAAM,YAAY,iBAAiB,QAAQ,UAAU;CACrD,MAAM,cAAc,MAAM,OAAO,IAAI;CACrC,MAAM,sBAAsB,YAAY,SAAS,SAAS,CAAC,CAAC;CAC5D,MAAM,eAAe,MAAM,OAAO,CAAC,QAAQ,SAAS;CACpD,IAAI,QAAQ,MAAM,aAAa,UAAU;CACzC,MAAM,cAAc,aAAa;CACjC,MAAM,gBAAgB;EACpB,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,QAAQ,MAAM;EAC3C,MAAM,QAAQ,4BAA4B;GACxC,MAAM,QAAQ,QAAQ,eAAe,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