@radix-ui/react-navigation-menu 0.1.3-rc.5 → 0.1.3-rc.50

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.
@@ -1,2 +1,827 @@
1
- import*as e from"@radix-ui/react-visually-hidden";import{useCallbackRef as t}from"@radix-ui/react-use-callback-ref";import{useLayoutEffect as n}from"@radix-ui/react-use-layout-effect";import{usePrevious as o}from"@radix-ui/react-use-previous";import{DismissableLayer as r}from"@radix-ui/react-dismissable-layer";import{createCollection as a}from"@radix-ui/react-collection";import{useId as i}from"@radix-ui/react-id";import{Presence as u}from"@radix-ui/react-presence";import{useDirection as s}from"@radix-ui/react-direction";import{composeRefs as c,useComposedRefs as l}from"@radix-ui/react-compose-refs";import{useControllableState as d}from"@radix-ui/react-use-controllable-state";import{Primitive as v}from"@radix-ui/react-primitive";import{composeEventHandlers as f}from"@radix-ui/primitive";import{createContextScope as m}from"@radix-ui/react-context";import p from"react-dom";import*as g from"react";import M from"@babel/runtime/helpers/esm/extends";const[E,w,N]=a("NavigationMenu"),[x,R,h]=a("NavigationMenu"),[C,b]=m("NavigationMenu",[N,h]);export{b as createNavigationMenuScope};const[_,y]=C("NavigationMenu"),[I,P]=C("NavigationMenu");export const NavigationMenu=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,value:o,onValueChange:r,defaultValue:a,orientation:i="horizontal",dir:u,...c}=e,[d,f]=g.useState(null),m=l(t,(e=>f(e))),p=s(u);/*#__PURE__*/return g.createElement(T,{scope:n,isRootMenu:!0,value:o,onValueChange:r,defaultValue:a,dir:p,orientation:i,rootNavigationMenu:d},/*#__PURE__*/g.createElement(v.nav,M({"aria-label":"Main","data-orientation":i,dir:p},c,{ref:m})))}));/*#__PURE__*/export const NavigationMenuSub=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,value:o,onValueChange:r,defaultValue:a,orientation:i="horizontal",...u}=e,s=y("NavigationMenuSub",n);/*#__PURE__*/return g.createElement(T,{scope:n,isRootMenu:!1,value:o,onValueChange:r,defaultValue:a,dir:s.dir,orientation:i,rootNavigationMenu:s.rootNavigationMenu},/*#__PURE__*/g.createElement(v.div,M({"data-orientation":i},u,{ref:t})))}));/*#__PURE__*/const T=e=>{const{scope:t,isRootMenu:n,rootNavigationMenu:r,value:a,onValueChange:u,defaultValue:s,dir:c,orientation:l,children:v}=e,[f,m]=g.useState(null),[p,M]=g.useState(new Map),[w,N]=g.useState(null),x=g.useRef(0),[R="",h]=d({prop:a,onChange:u,defaultProp:s});return g.useEffect((()=>()=>window.clearTimeout(x.current)),[x]),/*#__PURE__*/g.createElement(_,{scope:t,isRootMenu:n,rootNavigationMenu:r,value:R,previousValue:o(R),baseId:i(),dir:c,orientation:l,viewport:f,onViewportChange:m,indicatorTrack:w,onIndicatorTrackChange:N,onItemOver:g.useCallback((e=>{n&&window.clearTimeout(x.current),h(e)}),[h,n]),onItemLeave:g.useCallback((()=>{n&&(window.clearTimeout(x.current),x.current=window.setTimeout((()=>h("")),150))}),[h,n]),onItemSelect:g.useCallback((e=>{h((t=>n&&t===e?"":e))}),[h,n]),onItemDismiss:g.useCallback((()=>h("")),[h]),onViewportContentChange:g.useCallback(((e,t)=>{M((n=>(n.set(e,t),new Map(n))))}),[]),onViewportContentRemove:g.useCallback((e=>{M((t=>t.has(e)?(t.delete(e),new Map(t)):t))}),[])},/*#__PURE__*/g.createElement(E.Provider,{scope:t},/*#__PURE__*/g.createElement(I,{scope:t,items:p},v)))};export const NavigationMenuList=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,...o}=e,r=y("NavigationMenuList",n),a=/*#__PURE__*/g.createElement(v.ul,M({"data-orientation":r.orientation},o,{ref:t}));/*#__PURE__*/return g.createElement(v.div,{style:{position:"relative"},ref:r.onIndicatorTrackChange},/*#__PURE__*/g.createElement(E.Slot,{scope:n},r.isRootMenu?/*#__PURE__*/g.createElement(S,{asChild:!0},a):a))}));/*#__PURE__*/const[L,k]=C("NavigationMenuItem");export const NavigationMenuItem=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,value:o,...r}=e,a=i(),u=o||a||"LEGACY_REACT_AUTO_VALUE",s=g.useRef(null),c=g.useRef(null),l=g.useRef(null),d=g.useRef((()=>{})),f=g.useCallback(((e="start")=>{if(s.current){d.current();const t=z(s.current);t.length&&$("start"===e?t:t.reverse())}}),[]),m=g.useCallback((()=>{if(s.current){const e=z(s.current);e.length&&(d.current=function(e){return e.forEach((e=>{e.dataset.tabindex=e.getAttribute("tabindex")||"",e.setAttribute("tabindex","-1")})),()=>{e.forEach((e=>{const t=e.dataset.tabindex;e.setAttribute("tabindex",t)}))}}(e))}}),[]);/*#__PURE__*/return g.createElement(L,{scope:n,value:u,triggerRef:c,contentRef:s,focusProxyRef:l,onEntryKeyDown:f,onFocusProxyEnter:f,onRootContentClose:m,onContentFocusOutside:m},/*#__PURE__*/g.createElement(v.li,M({},r,{ref:t})))}));/*#__PURE__*/export const NavigationMenuTrigger=/*#__PURE__*/g.forwardRef(((t,n)=>{const{__scopeNavigationMenu:o,disabled:r,...a}=t,i=y("NavigationMenuTrigger",t.__scopeNavigationMenu),u=k("NavigationMenuTrigger",t.__scopeNavigationMenu),s=g.useRef(null),c=l(s,u.triggerRef,n),d=H(i.baseId,u.value),m=W(i.baseId,u.value),p=g.useRef(!1),w=u.value===i.value;/*#__PURE__*/return g.createElement(g.Fragment,null,/*#__PURE__*/g.createElement(E.ItemSlot,{scope:o,value:u.value},/*#__PURE__*/g.createElement(K,{asChild:!0},/*#__PURE__*/g.createElement(v.button,M({id:d,disabled:r,"data-disabled":r?"":void 0,"data-state":B(w),"aria-expanded":w,"aria-controls":m},a,{ref:c,onPointerEnter:f(t.onPointerEnter,(()=>{p.current=!1})),onPointerMove:f(t.onPointerMove,G((()=>{r||p.current||i.onItemOver(u.value)}))),onPointerLeave:f(t.onPointerLeave,G((()=>{r||i.onItemLeave()}))),onClick:f(t.onClick,(()=>{i.onItemSelect(u.value),p.current=w})),onKeyDown:f(t.onKeyDown,(e=>{const t={horizontal:"ArrowDown",vertical:"rtl"===i.dir?"ArrowLeft":"ArrowRight"}[i.orientation];w&&e.key===t&&(u.onEntryKeyDown(),e.preventDefault())}))})))),w&&/*#__PURE__*/g.createElement(g.Fragment,null,/*#__PURE__*/g.createElement(e.Root,{"aria-hidden":!0,tabIndex:0,ref:u.focusProxyRef,onFocus:e=>{const t=u.contentRef.current,n=e.relatedTarget,o=n===s.current,r=null==t?void 0:t.contains(n);!o&&r||u.onFocusProxyEnter(o?"start":"end")}}),i.viewport&&/*#__PURE__*/g.createElement("span",{"aria-owns":m})))}));/*#__PURE__*/export const NavigationMenuLink=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,active:o,...r}=e;/*#__PURE__*/return g.createElement(K,{asChild:!0},/*#__PURE__*/g.createElement(v.a,M({"data-active":o?"":void 0,"aria-current":o?"page":void 0},r,{ref:t})))}));/*#__PURE__*/export const NavigationMenuIndicator=/*#__PURE__*/g.forwardRef(((e,t)=>{const{forceMount:n,...o}=e,r=y("NavigationMenuIndicator",e.__scopeNavigationMenu),a=Boolean(r.value);return r.indicatorTrack?/*#__PURE__*/p.createPortal(/*#__PURE__*/g.createElement(u,{present:n||a},/*#__PURE__*/g.createElement(V,M({},o,{ref:t}))),r.indicatorTrack):null}));/*#__PURE__*/const V=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,...o}=e,r=y("NavigationMenuIndicator",n),a=w(n),[i,u]=g.useState(null),[s,c]=g.useState(null),l="horizontal"===r.orientation,d=Boolean(r.value);g.useEffect((()=>{var e;const t=null===(e=a().find((e=>e.value===r.value)))||void 0===e?void 0:e.ref.current;t&&u(t)}),[a,r.value]);const f=()=>{i&&c({size:l?i.offsetWidth:i.offsetHeight,offset:l?i.offsetLeft:i.offsetTop})};return U(i,f),U(r.indicatorTrack,f),s?/*#__PURE__*/g.createElement(v.div,M({"aria-hidden":!0,"data-state":d?"visible":"hidden","data-orientation":r.orientation},o,{ref:t,style:{position:"absolute",...l?{left:0,width:s.size+"px",transform:`translateX(${s.offset}px)`}:{top:0,height:s.size+"px",transform:`translateY(${s.offset}px)`},...o.style}})):null}));export const NavigationMenuContent=/*#__PURE__*/g.forwardRef(((e,t)=>{const{forceMount:n,...o}=e,r=y("NavigationMenuContent",e.__scopeNavigationMenu),a=k("NavigationMenuContent",e.__scopeNavigationMenu),i=l(a.contentRef,t),s=a.value===r.value,c={value:a.value,triggerRef:a.triggerRef,focusProxyRef:a.focusProxyRef,onContentFocusOutside:a.onContentFocusOutside,onRootContentClose:a.onRootContentClose,...o};return r.viewport?/*#__PURE__*/g.createElement(D,M({forceMount:n},c,{ref:i})):/*#__PURE__*/g.createElement(u,{present:n||s},/*#__PURE__*/g.createElement(F,M({"data-state":B(s)},c,{ref:i,onPointerEnter:f(e.onPointerEnter,(()=>{r.onItemOver(a.value)})),onPointerLeave:f(e.onPointerLeave,G(r.onItemLeave)),style:{pointerEvents:!s&&r.isRootMenu?"none":void 0,...c.style}})))}));/*#__PURE__*/const D=/*#__PURE__*/g.forwardRef(((e,t)=>{const o=y("NavigationMenuContent",e.__scopeNavigationMenu),{onViewportContentChange:r,onViewportContentRemove:a}=o;return n((()=>{r(e.value,{ref:t,...e})}),[e,t,r]),n((()=>()=>a(e.value)),[e.value,a]),null})),F=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,value:o,triggerRef:a,focusProxyRef:i,onRootContentClose:u,onContentFocusOutside:s,...c}=e,d=y("NavigationMenuContent",n),v=g.useRef(null),m=l(v,t),p=H(d.baseId,o),E=W(d.baseId,o),N=w(n),x=g.useRef(null),{onItemDismiss:R}=d;g.useEffect((()=>{const e=v.current;if(d.isRootMenu&&e){const t=()=>{var t;R(),u(),e.contains(document.activeElement)&&(null===(t=a.current)||void 0===t||t.focus())};return e.addEventListener("navigationMenu.contentDismiss",t),()=>e.removeEventListener("navigationMenu.contentDismiss",t)}}),[d.isRootMenu,e.value,a,R,u]);const h=g.useMemo((()=>{const e=N().map((e=>e.value));"rtl"===d.dir&&e.reverse();const t=e.indexOf(d.value),n=e.indexOf(d.previousValue),r=o===d.value,a=n===e.indexOf(o);if(!r&&!a)return x.current;const i=(()=>{if(t!==n){if(r&&-1!==n)return t>n?"from-end":"from-start";if(a&&-1!==t)return t>n?"to-start":"to-end"}return null})();return x.current=i,i}),[d.previousValue,d.value,d.dir,N,o]);/*#__PURE__*/return g.createElement(S,{asChild:!0},/*#__PURE__*/g.createElement(r,M({id:E,"aria-labelledby":p,"data-motion":h,"data-orientation":d.orientation},c,{ref:m,onDismiss:()=>{var e;const t=new Event("navigationMenu.contentDismiss",{bubbles:!0,cancelable:!0});null===(e=v.current)||void 0===e||e.dispatchEvent(t)},onFocusOutside:f(e.onFocusOutside,(e=>{var t;s();const n=e.target;null!==(t=d.rootNavigationMenu)&&void 0!==t&&t.contains(n)&&e.preventDefault()})),onPointerDownOutside:f(e.onPointerDownOutside,(e=>{var t;const n=e.target,o=N().some((e=>{var t;return null===(t=e.ref.current)||void 0===t?void 0:t.contains(n)})),r=d.isRootMenu&&(null===(t=d.viewport)||void 0===t?void 0:t.contains(n));(o||r||!d.isRootMenu)&&e.preventDefault()})),onKeyDown:f(e.onKeyDown,(e=>{const t=e.altKey||e.ctrlKey||e.metaKey;if("Tab"===e.key&&!t){const t=z(e.currentTarget),o=document.activeElement,r=t.findIndex((e=>e===o));var n;if($(e.shiftKey?t.slice(0,r).reverse():t.slice(r+1,t.length)))e.preventDefault();else null===(n=i.current)||void 0===n||n.focus()}}))})))}));export const NavigationMenuViewport=/*#__PURE__*/g.forwardRef(((e,t)=>{const{forceMount:n,...o}=e,r=y("NavigationMenuViewport",e.__scopeNavigationMenu),a=Boolean(r.value);/*#__PURE__*/return g.createElement(u,{present:n||a},/*#__PURE__*/g.createElement(A,M({},o,{ref:t})))}));/*#__PURE__*/const A=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,children:o,...r}=e,a=y("NavigationMenuViewport",n),i=l(t,a.onViewportChange),s=P("NavigationMenuContent",e.__scopeNavigationMenu),[d,m]=g.useState(null),[p,E]=g.useState(null),w=d?(null==d?void 0:d.width)+"px":void 0,N=d?(null==d?void 0:d.height)+"px":void 0,x=Boolean(a.value),R=x?a.value:a.previousValue;return U(p,(()=>{p&&m({width:p.offsetWidth,height:p.offsetHeight})})),/*#__PURE__*/g.createElement(v.div,M({"data-state":B(x),"data-orientation":a.orientation},r,{ref:i,style:{pointerEvents:!x&&a.isRootMenu?"none":void 0,"--radix-navigation-menu-viewport-width":w,"--radix-navigation-menu-viewport-height":N,...r.style},onPointerEnter:f(e.onPointerEnter,(()=>{a.onItemOver(R)})),onPointerLeave:f(e.onPointerLeave,G(a.onItemLeave))}),Array.from(s.items).map((([e,{ref:t,forceMount:n,...o}])=>{const r=R===e;/*#__PURE__*/return g.createElement(u,{key:e,present:n||r},/*#__PURE__*/g.createElement(F,M({},o,{ref:c(t,(e=>{r&&e&&E(e)}))})))})))})),S=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,...o}=e,r=y("FocusGroup",n);/*#__PURE__*/return g.createElement(x.Provider,{scope:n},/*#__PURE__*/g.createElement(x.Slot,{scope:n},/*#__PURE__*/g.createElement(v.div,M({dir:r.dir},o,{ref:t}))))})),O=["ArrowRight","ArrowLeft","ArrowUp","ArrowDown"],K=/*#__PURE__*/g.forwardRef(((e,t)=>{const{__scopeNavigationMenu:n,...o}=e,r=R(n),a=y("FocusGroupItem",n);/*#__PURE__*/return g.createElement(x.ItemSlot,{scope:n},/*#__PURE__*/g.createElement(v.button,M({},o,{ref:t,onKeyDown:f(e.onKeyDown,(e=>{if(["Home","End",...O].includes(e.key)){let t=r().map((e=>e.ref.current));if(["rtl"===a.dir?"ArrowRight":"ArrowLeft","ArrowUp","End"].includes(e.key)&&t.reverse(),O.includes(e.key)){const n=t.indexOf(e.currentTarget);t=t.slice(n+1)}setTimeout((()=>$(t))),e.preventDefault()}}))})))}));function z(e){const t=[],n=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT,{acceptNode:e=>{const t="INPUT"===e.tagName&&"hidden"===e.type;return e.disabled||e.hidden||t?NodeFilter.FILTER_SKIP:e.tabIndex>=0?NodeFilter.FILTER_ACCEPT:NodeFilter.FILTER_SKIP}});for(;n.nextNode();)t.push(n.currentNode);return t}function $(e){const t=document.activeElement;return e.some((e=>e===t||(e.focus(),document.activeElement!==t)))}function U(e,o){const r=t(o);n((()=>{let t=0;if(e){const n=new ResizeObserver((()=>{cancelAnimationFrame(t),t=window.requestAnimationFrame(r)}));return n.observe(e),()=>{window.cancelAnimationFrame(t),n.unobserve(e)}}}),[e,r])}function B(e){return e?"open":"closed"}function H(e,t){return`${e}-trigger-${t}`}function W(e,t){return`${e}-content-${t}`}function G(e){return t=>"mouse"===t.pointerType?e(t):void 0}export const Root=NavigationMenu;export const Sub=NavigationMenuSub;export const List=NavigationMenuList;export const Item=NavigationMenuItem;export const Trigger=NavigationMenuTrigger;export const Link=NavigationMenuLink;export const Indicator=NavigationMenuIndicator;export const Content=NavigationMenuContent;export const Viewport=NavigationMenuViewport;
1
+ import $yHMN2$babelruntimehelpersesmextends from "@babel/runtime/helpers/esm/extends";
2
+ import {forwardRef as $yHMN2$forwardRef, useState as $yHMN2$useState, createElement as $yHMN2$createElement, useRef as $yHMN2$useRef, useEffect as $yHMN2$useEffect, useCallback as $yHMN2$useCallback, Fragment as $yHMN2$Fragment, useMemo as $yHMN2$useMemo} from "react";
3
+ import $yHMN2$reactdom from "react-dom";
4
+ import {createContextScope as $yHMN2$createContextScope} from "@radix-ui/react-context";
5
+ import {composeEventHandlers as $yHMN2$composeEventHandlers} from "@radix-ui/primitive";
6
+ import {Primitive as $yHMN2$Primitive, dispatchDiscreteCustomEvent as $yHMN2$dispatchDiscreteCustomEvent} from "@radix-ui/react-primitive";
7
+ import {useControllableState as $yHMN2$useControllableState} from "@radix-ui/react-use-controllable-state";
8
+ import {useComposedRefs as $yHMN2$useComposedRefs, composeRefs as $yHMN2$composeRefs} from "@radix-ui/react-compose-refs";
9
+ import {useDirection as $yHMN2$useDirection} from "@radix-ui/react-direction";
10
+ import {Presence as $yHMN2$Presence} from "@radix-ui/react-presence";
11
+ import {useId as $yHMN2$useId} from "@radix-ui/react-id";
12
+ import {createCollection as $yHMN2$createCollection} from "@radix-ui/react-collection";
13
+ import {DismissableLayer as $yHMN2$DismissableLayer} from "@radix-ui/react-dismissable-layer";
14
+ import {usePrevious as $yHMN2$usePrevious} from "@radix-ui/react-use-previous";
15
+ import {useLayoutEffect as $yHMN2$useLayoutEffect} from "@radix-ui/react-use-layout-effect";
16
+ import {useCallbackRef as $yHMN2$useCallbackRef} from "@radix-ui/react-use-callback-ref";
17
+ import {Root as $yHMN2$Root} from "@radix-ui/react-visually-hidden";
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+ /* -------------------------------------------------------------------------------------------------
37
+ * NavigationMenu
38
+ * -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$NAVIGATION_MENU_NAME = 'NavigationMenu';
39
+ const [$322c88a641701f3b$var$Collection, $322c88a641701f3b$var$useCollection, $322c88a641701f3b$var$createCollectionScope] = $yHMN2$createCollection($322c88a641701f3b$var$NAVIGATION_MENU_NAME);
40
+ const [$322c88a641701f3b$var$FocusGroupCollection, $322c88a641701f3b$var$useFocusGroupCollection, $322c88a641701f3b$var$createFocusGroupCollectionScope] = $yHMN2$createCollection($322c88a641701f3b$var$NAVIGATION_MENU_NAME);
41
+ const [$322c88a641701f3b$var$createNavigationMenuContext, $322c88a641701f3b$export$fb8ea5af8c9fcdf0] = $yHMN2$createContextScope($322c88a641701f3b$var$NAVIGATION_MENU_NAME, [
42
+ $322c88a641701f3b$var$createCollectionScope,
43
+ $322c88a641701f3b$var$createFocusGroupCollectionScope
44
+ ]);
45
+ const [$322c88a641701f3b$var$NavigationMenuProviderImpl, $322c88a641701f3b$var$useNavigationMenuContext] = $322c88a641701f3b$var$createNavigationMenuContext($322c88a641701f3b$var$NAVIGATION_MENU_NAME);
46
+ const [$322c88a641701f3b$var$ViewportContentProvider, $322c88a641701f3b$var$useViewportContentContext] = $322c88a641701f3b$var$createNavigationMenuContext($322c88a641701f3b$var$NAVIGATION_MENU_NAME);
47
+ const $322c88a641701f3b$export$5b2278cf1e8bcae2 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
48
+ const { __scopeNavigationMenu: __scopeNavigationMenu , value: value , onValueChange: onValueChange , defaultValue: defaultValue , orientation: orientation = 'horizontal' , dir: dir , ...NavigationMenuProps } = props;
49
+ const [navigationMenu, setNavigationMenu] = $yHMN2$useState(null);
50
+ const composedRef = $yHMN2$useComposedRefs(forwardedRef, (node)=>setNavigationMenu(node)
51
+ );
52
+ const direction = $yHMN2$useDirection(dir);
53
+ return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuProvider, {
54
+ scope: __scopeNavigationMenu,
55
+ isRootMenu: true,
56
+ value: value,
57
+ onValueChange: onValueChange,
58
+ defaultValue: defaultValue,
59
+ dir: direction,
60
+ orientation: orientation,
61
+ rootNavigationMenu: navigationMenu
62
+ }, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.nav, $yHMN2$babelruntimehelpersesmextends({
63
+ "aria-label": "Main",
64
+ "data-orientation": orientation,
65
+ dir: direction
66
+ }, NavigationMenuProps, {
67
+ ref: composedRef
68
+ })));
69
+ });
70
+ /*#__PURE__*/ Object.assign($322c88a641701f3b$export$5b2278cf1e8bcae2, {
71
+ displayName: $322c88a641701f3b$var$NAVIGATION_MENU_NAME
72
+ });
73
+ /* -------------------------------------------------------------------------------------------------
74
+ * NavigationMenuSub
75
+ * -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$SUB_NAME = 'NavigationMenuSub';
76
+ const $322c88a641701f3b$export$5958edd6c4ee7c79 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
77
+ const { __scopeNavigationMenu: __scopeNavigationMenu , value: value , onValueChange: onValueChange , defaultValue: defaultValue , orientation: orientation = 'horizontal' , ...subProps } = props;
78
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$SUB_NAME, __scopeNavigationMenu);
79
+ return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuProvider, {
80
+ scope: __scopeNavigationMenu,
81
+ isRootMenu: false,
82
+ value: value,
83
+ onValueChange: onValueChange,
84
+ defaultValue: defaultValue,
85
+ dir: context.dir,
86
+ orientation: orientation,
87
+ rootNavigationMenu: context.rootNavigationMenu
88
+ }, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.div, $yHMN2$babelruntimehelpersesmextends({
89
+ "data-orientation": orientation
90
+ }, subProps, {
91
+ ref: forwardedRef
92
+ })));
93
+ });
94
+ /*#__PURE__*/ Object.assign($322c88a641701f3b$export$5958edd6c4ee7c79, {
95
+ displayName: $322c88a641701f3b$var$SUB_NAME
96
+ });
97
+ /* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$NavigationMenuProvider = (props)=>{
98
+ const { scope: scope , isRootMenu: isRootMenu , rootNavigationMenu: rootNavigationMenu , value: valueProp , onValueChange: onValueChange , defaultValue: defaultValue , dir: dir , orientation: orientation , children: children } = props;
99
+ const [viewport, setViewport] = $yHMN2$useState(null);
100
+ const [viewportContent, setViewportContent] = $yHMN2$useState(new Map());
101
+ const [indicatorTrack, setIndicatorTrack] = $yHMN2$useState(null);
102
+ const closeTimerRef = $yHMN2$useRef(0);
103
+ const [value = '', setValue] = $yHMN2$useControllableState({
104
+ prop: valueProp,
105
+ onChange: onValueChange,
106
+ defaultProp: defaultValue
107
+ });
108
+ $yHMN2$useEffect(()=>{
109
+ return ()=>window.clearTimeout(closeTimerRef.current)
110
+ ;
111
+ }, [
112
+ closeTimerRef
113
+ ]);
114
+ return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuProviderImpl, {
115
+ scope: scope,
116
+ isRootMenu: isRootMenu,
117
+ rootNavigationMenu: rootNavigationMenu,
118
+ value: value,
119
+ previousValue: $yHMN2$usePrevious(value),
120
+ baseId: $yHMN2$useId(),
121
+ dir: dir,
122
+ orientation: orientation,
123
+ viewport: viewport,
124
+ onViewportChange: setViewport,
125
+ indicatorTrack: indicatorTrack,
126
+ onIndicatorTrackChange: setIndicatorTrack,
127
+ onItemOver: $yHMN2$useCallback((itemValue)=>{
128
+ if (isRootMenu) window.clearTimeout(closeTimerRef.current);
129
+ setValue(itemValue);
130
+ }, [
131
+ setValue,
132
+ isRootMenu
133
+ ]),
134
+ onItemLeave: $yHMN2$useCallback(()=>{
135
+ if (isRootMenu) {
136
+ window.clearTimeout(closeTimerRef.current);
137
+ closeTimerRef.current = window.setTimeout(()=>setValue('')
138
+ , 150);
139
+ }
140
+ }, [
141
+ setValue,
142
+ isRootMenu
143
+ ]),
144
+ onItemSelect: $yHMN2$useCallback((itemValue)=>{
145
+ setValue((prevValue)=>{
146
+ return isRootMenu ? prevValue === itemValue ? '' : itemValue : itemValue;
147
+ });
148
+ }, [
149
+ setValue,
150
+ isRootMenu
151
+ ]),
152
+ onItemDismiss: $yHMN2$useCallback(()=>setValue('')
153
+ , [
154
+ setValue
155
+ ]),
156
+ onViewportContentChange: $yHMN2$useCallback((contentValue, contentData)=>{
157
+ setViewportContent((prevContent)=>{
158
+ prevContent.set(contentValue, contentData);
159
+ return new Map(prevContent);
160
+ });
161
+ }, []),
162
+ onViewportContentRemove: $yHMN2$useCallback((contentValue)=>{
163
+ setViewportContent((prevContent)=>{
164
+ if (!prevContent.has(contentValue)) return prevContent;
165
+ prevContent.delete(contentValue);
166
+ return new Map(prevContent);
167
+ });
168
+ }, [])
169
+ }, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$Collection.Provider, {
170
+ scope: scope
171
+ }, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$ViewportContentProvider, {
172
+ scope: scope,
173
+ items: viewportContent
174
+ }, children)));
175
+ };
176
+ /* -------------------------------------------------------------------------------------------------
177
+ * NavigationMenuList
178
+ * -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$LIST_NAME = 'NavigationMenuList';
179
+ const $322c88a641701f3b$export$c361068a95fd2286 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
180
+ const { __scopeNavigationMenu: __scopeNavigationMenu , ...listProps } = props;
181
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$LIST_NAME, __scopeNavigationMenu);
182
+ const list = /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.ul, $yHMN2$babelruntimehelpersesmextends({
183
+ "data-orientation": context.orientation
184
+ }, listProps, {
185
+ ref: forwardedRef
186
+ }));
187
+ return /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.div, {
188
+ style: {
189
+ position: 'relative'
190
+ },
191
+ ref: context.onIndicatorTrackChange
192
+ }, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$Collection.Slot, {
193
+ scope: __scopeNavigationMenu
194
+ }, context.isRootMenu ? /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroup, {
195
+ asChild: true
196
+ }, list) : list));
197
+ });
198
+ /*#__PURE__*/ Object.assign($322c88a641701f3b$export$c361068a95fd2286, {
199
+ displayName: $322c88a641701f3b$var$LIST_NAME
200
+ });
201
+ /* -------------------------------------------------------------------------------------------------
202
+ * NavigationMenuItem
203
+ * -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$ITEM_NAME = 'NavigationMenuItem';
204
+ const [$322c88a641701f3b$var$NavigationMenuItemContextProvider, $322c88a641701f3b$var$useNavigationMenuItemContext] = $322c88a641701f3b$var$createNavigationMenuContext($322c88a641701f3b$var$ITEM_NAME);
205
+ const $322c88a641701f3b$export$ffdbb83a2de845c2 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
206
+ const { __scopeNavigationMenu: __scopeNavigationMenu , value: valueProp , ...itemProps } = props;
207
+ const autoValue = $yHMN2$useId(); // We need to provide an initial deterministic value as `useId` will return
208
+ // empty string on the first render and we don't want to match our internal "closed" value.
209
+ const value = valueProp || autoValue || 'LEGACY_REACT_AUTO_VALUE';
210
+ const contentRef = $yHMN2$useRef(null);
211
+ const triggerRef = $yHMN2$useRef(null);
212
+ const focusProxyRef = $yHMN2$useRef(null);
213
+ const restoreContentTabOrderRef = $yHMN2$useRef(()=>{});
214
+ const handleContentEntry = $yHMN2$useCallback((side = 'start')=>{
215
+ if (contentRef.current) {
216
+ restoreContentTabOrderRef.current();
217
+ const candidates = $322c88a641701f3b$var$getTabbableCandidates(contentRef.current);
218
+ if (candidates.length) $322c88a641701f3b$var$focusFirst(side === 'start' ? candidates : candidates.reverse());
219
+ }
220
+ }, []);
221
+ const handleContentExit = $yHMN2$useCallback(()=>{
222
+ if (contentRef.current) {
223
+ const candidates = $322c88a641701f3b$var$getTabbableCandidates(contentRef.current);
224
+ if (candidates.length) restoreContentTabOrderRef.current = $322c88a641701f3b$var$removeFromTabOrder(candidates);
225
+ }
226
+ }, []);
227
+ return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuItemContextProvider, {
228
+ scope: __scopeNavigationMenu,
229
+ value: value,
230
+ triggerRef: triggerRef,
231
+ contentRef: contentRef,
232
+ focusProxyRef: focusProxyRef,
233
+ onEntryKeyDown: handleContentEntry,
234
+ onFocusProxyEnter: handleContentEntry,
235
+ onRootContentClose: handleContentExit,
236
+ onContentFocusOutside: handleContentExit
237
+ }, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.li, $yHMN2$babelruntimehelpersesmextends({}, itemProps, {
238
+ ref: forwardedRef
239
+ })));
240
+ });
241
+ /*#__PURE__*/ Object.assign($322c88a641701f3b$export$ffdbb83a2de845c2, {
242
+ displayName: $322c88a641701f3b$var$ITEM_NAME
243
+ });
244
+ /* -------------------------------------------------------------------------------------------------
245
+ * NavigationMenuTrigger
246
+ * -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$TRIGGER_NAME = 'NavigationMenuTrigger';
247
+ const $322c88a641701f3b$export$37fe8002734d8f2 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
248
+ const { __scopeNavigationMenu: __scopeNavigationMenu , disabled: disabled , ...triggerProps } = props;
249
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$TRIGGER_NAME, props.__scopeNavigationMenu);
250
+ const itemContext = $322c88a641701f3b$var$useNavigationMenuItemContext($322c88a641701f3b$var$TRIGGER_NAME, props.__scopeNavigationMenu);
251
+ const ref = $yHMN2$useRef(null);
252
+ const composedRefs = $yHMN2$useComposedRefs(ref, itemContext.triggerRef, forwardedRef);
253
+ const triggerId = $322c88a641701f3b$var$makeTriggerId(context.baseId, itemContext.value);
254
+ const contentId = $322c88a641701f3b$var$makeContentId(context.baseId, itemContext.value);
255
+ const wasClickCloseRef = $yHMN2$useRef(false);
256
+ const open = itemContext.value === context.value;
257
+ return /*#__PURE__*/ $yHMN2$createElement($yHMN2$Fragment, null, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$Collection.ItemSlot, {
258
+ scope: __scopeNavigationMenu,
259
+ value: itemContext.value
260
+ }, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroupItem, {
261
+ asChild: true
262
+ }, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.button, $yHMN2$babelruntimehelpersesmextends({
263
+ id: triggerId,
264
+ disabled: disabled,
265
+ "data-disabled": disabled ? '' : undefined,
266
+ "data-state": $322c88a641701f3b$var$getOpenState(open),
267
+ "aria-expanded": open,
268
+ "aria-controls": contentId
269
+ }, triggerProps, {
270
+ ref: composedRefs,
271
+ onPointerEnter: $yHMN2$composeEventHandlers(props.onPointerEnter, ()=>{
272
+ wasClickCloseRef.current = false;
273
+ }),
274
+ onPointerMove: $yHMN2$composeEventHandlers(props.onPointerMove, $322c88a641701f3b$var$whenMouse(()=>{
275
+ if (disabled || wasClickCloseRef.current) return;
276
+ context.onItemOver(itemContext.value);
277
+ })),
278
+ onPointerLeave: $yHMN2$composeEventHandlers(props.onPointerLeave, $322c88a641701f3b$var$whenMouse(()=>{
279
+ if (disabled) return;
280
+ context.onItemLeave();
281
+ })),
282
+ onClick: $yHMN2$composeEventHandlers(props.onClick, ()=>{
283
+ context.onItemSelect(itemContext.value);
284
+ wasClickCloseRef.current = open;
285
+ }),
286
+ onKeyDown: $yHMN2$composeEventHandlers(props.onKeyDown, (event)=>{
287
+ const verticalEntryKey = context.dir === 'rtl' ? 'ArrowLeft' : 'ArrowRight';
288
+ const entryKey = {
289
+ horizontal: 'ArrowDown',
290
+ vertical: verticalEntryKey
291
+ }[context.orientation];
292
+ if (open && event.key === entryKey) {
293
+ itemContext.onEntryKeyDown(); // Prevent FocusGroupItem from handling the event
294
+ event.preventDefault();
295
+ }
296
+ })
297
+ })))), open && /*#__PURE__*/ $yHMN2$createElement($yHMN2$Fragment, null, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Root, {
298
+ "aria-hidden": true,
299
+ tabIndex: 0,
300
+ ref: itemContext.focusProxyRef,
301
+ onFocus: (event)=>{
302
+ const content = itemContext.contentRef.current;
303
+ const prevFocusedElement = event.relatedTarget;
304
+ const wasTriggerFocused = prevFocusedElement === ref.current;
305
+ const wasFocusFromContent = content === null || content === void 0 ? void 0 : content.contains(prevFocusedElement);
306
+ if (wasTriggerFocused || !wasFocusFromContent) itemContext.onFocusProxyEnter(wasTriggerFocused ? 'start' : 'end');
307
+ }
308
+ }), context.viewport && /*#__PURE__*/ $yHMN2$createElement("span", {
309
+ "aria-owns": contentId
310
+ })));
311
+ });
312
+ /*#__PURE__*/ Object.assign($322c88a641701f3b$export$37fe8002734d8f2, {
313
+ displayName: $322c88a641701f3b$var$TRIGGER_NAME
314
+ });
315
+ /* -------------------------------------------------------------------------------------------------
316
+ * NavigationMenuLink
317
+ * -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$LINK_NAME = 'NavigationMenuLink';
318
+ const $322c88a641701f3b$var$LINK_SELECT = 'navigationMenu.linkSelect';
319
+ const $322c88a641701f3b$export$6893bf21536567da = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
320
+ const { __scopeNavigationMenu: __scopeNavigationMenu , active: active , onSelect: onSelect , ...linkProps } = props;
321
+ return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroupItem, {
322
+ asChild: true
323
+ }, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.a, $yHMN2$babelruntimehelpersesmextends({
324
+ "data-active": active ? '' : undefined,
325
+ "aria-current": active ? 'page' : undefined
326
+ }, linkProps, {
327
+ ref: forwardedRef,
328
+ onClick: $yHMN2$composeEventHandlers(props.onClick, (event1)=>{
329
+ const target = event1.target;
330
+ const linkSelectEvent = new CustomEvent($322c88a641701f3b$var$LINK_SELECT, {
331
+ bubbles: true,
332
+ cancelable: true
333
+ });
334
+ target.addEventListener($322c88a641701f3b$var$LINK_SELECT, (event)=>onSelect === null || onSelect === void 0 ? void 0 : onSelect(event)
335
+ , {
336
+ once: true
337
+ });
338
+ $yHMN2$dispatchDiscreteCustomEvent(target, linkSelectEvent);
339
+ if (!linkSelectEvent.defaultPrevented) {
340
+ const rootContentDismissEvent = new CustomEvent($322c88a641701f3b$var$ROOT_CONTENT_DISMISS, {
341
+ bubbles: true,
342
+ cancelable: true
343
+ });
344
+ $yHMN2$dispatchDiscreteCustomEvent(target, rootContentDismissEvent);
345
+ }
346
+ }, {
347
+ checkForDefaultPrevented: false
348
+ })
349
+ })));
350
+ });
351
+ /*#__PURE__*/ Object.assign($322c88a641701f3b$export$6893bf21536567da, {
352
+ displayName: $322c88a641701f3b$var$LINK_NAME
353
+ });
354
+ /* -------------------------------------------------------------------------------------------------
355
+ * NavigationMenuIndicator
356
+ * -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$INDICATOR_NAME = 'NavigationMenuIndicator';
357
+ const $322c88a641701f3b$export$8ddb526647c0d8fb = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
358
+ const { forceMount: forceMount , ...indicatorProps } = props;
359
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$INDICATOR_NAME, props.__scopeNavigationMenu);
360
+ const isVisible = Boolean(context.value);
361
+ return context.indicatorTrack ? /*#__PURE__*/ $yHMN2$reactdom.createPortal(/*#__PURE__*/ $yHMN2$createElement($yHMN2$Presence, {
362
+ present: forceMount || isVisible
363
+ }, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuIndicatorImpl, $yHMN2$babelruntimehelpersesmextends({}, indicatorProps, {
364
+ ref: forwardedRef
365
+ }))), context.indicatorTrack) : null;
366
+ });
367
+ /*#__PURE__*/ Object.assign($322c88a641701f3b$export$8ddb526647c0d8fb, {
368
+ displayName: $322c88a641701f3b$var$INDICATOR_NAME
369
+ });
370
+ const $322c88a641701f3b$var$NavigationMenuIndicatorImpl = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
371
+ const { __scopeNavigationMenu: __scopeNavigationMenu , ...indicatorProps } = props;
372
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$INDICATOR_NAME, __scopeNavigationMenu);
373
+ const getItems = $322c88a641701f3b$var$useCollection(__scopeNavigationMenu);
374
+ const [activeTrigger, setActiveTrigger] = $yHMN2$useState(null);
375
+ const [position, setPosition] = $yHMN2$useState(null);
376
+ const isHorizontal = context.orientation === 'horizontal';
377
+ const isVisible = Boolean(context.value);
378
+ $yHMN2$useEffect(()=>{
379
+ var _items$find;
380
+ const items = getItems();
381
+ const triggerNode = (_items$find = items.find((item)=>item.value === context.value
382
+ )) === null || _items$find === void 0 ? void 0 : _items$find.ref.current;
383
+ if (triggerNode) setActiveTrigger(triggerNode);
384
+ }, [
385
+ getItems,
386
+ context.value
387
+ ]);
388
+ /**
389
+ * Update position when the indicator or parent track size changes
390
+ */ const handlePositionChange = ()=>{
391
+ if (activeTrigger) setPosition({
392
+ size: isHorizontal ? activeTrigger.offsetWidth : activeTrigger.offsetHeight,
393
+ offset: isHorizontal ? activeTrigger.offsetLeft : activeTrigger.offsetTop
394
+ });
395
+ };
396
+ $322c88a641701f3b$var$useResizeObserver(activeTrigger, handlePositionChange);
397
+ $322c88a641701f3b$var$useResizeObserver(context.indicatorTrack, handlePositionChange); // We need to wait for the indicator position to be available before rendering to
398
+ // snap immediately into position rather than transitioning from initial
399
+ return position ? /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.div, $yHMN2$babelruntimehelpersesmextends({
400
+ "aria-hidden": true,
401
+ "data-state": isVisible ? 'visible' : 'hidden',
402
+ "data-orientation": context.orientation
403
+ }, indicatorProps, {
404
+ ref: forwardedRef,
405
+ style: {
406
+ position: 'absolute',
407
+ ...isHorizontal ? {
408
+ left: 0,
409
+ width: position.size + 'px',
410
+ transform: `translateX(${position.offset}px)`
411
+ } : {
412
+ top: 0,
413
+ height: position.size + 'px',
414
+ transform: `translateY(${position.offset}px)`
415
+ },
416
+ ...indicatorProps.style
417
+ }
418
+ })) : null;
419
+ });
420
+ /* -------------------------------------------------------------------------------------------------
421
+ * NavigationMenuContent
422
+ * -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$CONTENT_NAME = 'NavigationMenuContent';
423
+ const $322c88a641701f3b$export$38e00e996c2f93f7 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
424
+ const { forceMount: forceMount , ...contentProps } = props;
425
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$CONTENT_NAME, props.__scopeNavigationMenu);
426
+ const itemContext = $322c88a641701f3b$var$useNavigationMenuItemContext($322c88a641701f3b$var$CONTENT_NAME, props.__scopeNavigationMenu);
427
+ const composedRefs = $yHMN2$useComposedRefs(itemContext.contentRef, forwardedRef);
428
+ const open = itemContext.value === context.value;
429
+ const commonProps = {
430
+ value: itemContext.value,
431
+ triggerRef: itemContext.triggerRef,
432
+ focusProxyRef: itemContext.focusProxyRef,
433
+ onContentFocusOutside: itemContext.onContentFocusOutside,
434
+ onRootContentClose: itemContext.onRootContentClose,
435
+ ...contentProps
436
+ };
437
+ return !context.viewport ? /*#__PURE__*/ $yHMN2$createElement($yHMN2$Presence, {
438
+ present: forceMount || open
439
+ }, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuContentImpl, $yHMN2$babelruntimehelpersesmextends({
440
+ "data-state": $322c88a641701f3b$var$getOpenState(open)
441
+ }, commonProps, {
442
+ ref: composedRefs,
443
+ onPointerEnter: $yHMN2$composeEventHandlers(props.onPointerEnter, ()=>{
444
+ context.onItemOver(itemContext.value);
445
+ }),
446
+ onPointerLeave: $yHMN2$composeEventHandlers(props.onPointerLeave, $322c88a641701f3b$var$whenMouse(context.onItemLeave)),
447
+ style: {
448
+ // Prevent interaction when animating out
449
+ pointerEvents: !open && context.isRootMenu ? 'none' : undefined,
450
+ ...commonProps.style
451
+ }
452
+ }))) : /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$ViewportContentMounter, $yHMN2$babelruntimehelpersesmextends({
453
+ forceMount: forceMount
454
+ }, commonProps, {
455
+ ref: composedRefs
456
+ }));
457
+ });
458
+ /*#__PURE__*/ Object.assign($322c88a641701f3b$export$38e00e996c2f93f7, {
459
+ displayName: $322c88a641701f3b$var$CONTENT_NAME
460
+ });
461
+ /* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$ViewportContentMounter = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
462
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$CONTENT_NAME, props.__scopeNavigationMenu);
463
+ const { onViewportContentChange: onViewportContentChange , onViewportContentRemove: onViewportContentRemove } = context;
464
+ $yHMN2$useLayoutEffect(()=>{
465
+ onViewportContentChange(props.value, {
466
+ ref: forwardedRef,
467
+ ...props
468
+ });
469
+ }, [
470
+ props,
471
+ forwardedRef,
472
+ onViewportContentChange
473
+ ]);
474
+ $yHMN2$useLayoutEffect(()=>{
475
+ return ()=>onViewportContentRemove(props.value)
476
+ ;
477
+ }, [
478
+ props.value,
479
+ onViewportContentRemove
480
+ ]); // Content is proxied into the viewport
481
+ return null;
482
+ });
483
+ /* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$ROOT_CONTENT_DISMISS = 'navigationMenu.rootContentDismiss';
484
+ const $322c88a641701f3b$var$NavigationMenuContentImpl = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
485
+ const { __scopeNavigationMenu: __scopeNavigationMenu , value: value , triggerRef: triggerRef , focusProxyRef: focusProxyRef , onRootContentClose: onRootContentClose , onContentFocusOutside: onContentFocusOutside , ...contentProps } = props;
486
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$CONTENT_NAME, __scopeNavigationMenu);
487
+ const ref = $yHMN2$useRef(null);
488
+ const composedRefs = $yHMN2$useComposedRefs(ref, forwardedRef);
489
+ const triggerId = $322c88a641701f3b$var$makeTriggerId(context.baseId, value);
490
+ const contentId = $322c88a641701f3b$var$makeContentId(context.baseId, value);
491
+ const getItems = $322c88a641701f3b$var$useCollection(__scopeNavigationMenu);
492
+ const prevMotionAttributeRef = $yHMN2$useRef(null);
493
+ const { onItemDismiss: onItemDismiss } = context;
494
+ $yHMN2$useEffect(()=>{
495
+ const content = ref.current; // Bubble dismiss to the root content node and focus its trigger
496
+ if (context.isRootMenu && content) {
497
+ const handleClose = ()=>{
498
+ var _triggerRef$current;
499
+ onItemDismiss();
500
+ onRootContentClose();
501
+ if (content.contains(document.activeElement)) (_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 || _triggerRef$current.focus();
502
+ };
503
+ content.addEventListener($322c88a641701f3b$var$ROOT_CONTENT_DISMISS, handleClose);
504
+ return ()=>content.removeEventListener($322c88a641701f3b$var$ROOT_CONTENT_DISMISS, handleClose)
505
+ ;
506
+ }
507
+ }, [
508
+ context.isRootMenu,
509
+ props.value,
510
+ triggerRef,
511
+ onItemDismiss,
512
+ onRootContentClose
513
+ ]);
514
+ const motionAttribute = $yHMN2$useMemo(()=>{
515
+ const items = getItems();
516
+ const values = items.map((item)=>item.value
517
+ );
518
+ if (context.dir === 'rtl') values.reverse();
519
+ const index = values.indexOf(context.value);
520
+ const prevIndex = values.indexOf(context.previousValue);
521
+ const isSelected = value === context.value;
522
+ const wasSelected = prevIndex === values.indexOf(value); // We only want to update selected and the last selected content
523
+ // this avoids animations being interrupted outside of that range
524
+ if (!isSelected && !wasSelected) return prevMotionAttributeRef.current;
525
+ const attribute = (()=>{
526
+ // Don't provide a direction on the initial open
527
+ if (index !== prevIndex) {
528
+ // If we're moving to this item from another
529
+ if (isSelected && prevIndex !== -1) return index > prevIndex ? 'from-end' : 'from-start'; // If we're leaving this item for another
530
+ if (wasSelected && index !== -1) return index > prevIndex ? 'to-start' : 'to-end';
531
+ } // Otherwise we're entering from closed or leaving the list
532
+ // entirely and should not animate in any direction
533
+ return null;
534
+ })();
535
+ prevMotionAttributeRef.current = attribute;
536
+ return attribute;
537
+ }, [
538
+ context.previousValue,
539
+ context.value,
540
+ context.dir,
541
+ getItems,
542
+ value
543
+ ]);
544
+ return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroup, {
545
+ asChild: true
546
+ }, /*#__PURE__*/ $yHMN2$createElement($yHMN2$DismissableLayer, $yHMN2$babelruntimehelpersesmextends({
547
+ id: contentId,
548
+ "aria-labelledby": triggerId,
549
+ "data-motion": motionAttribute,
550
+ "data-orientation": context.orientation
551
+ }, contentProps, {
552
+ ref: composedRefs,
553
+ onDismiss: ()=>{
554
+ var _ref$current;
555
+ const rootContentDismissEvent = new Event($322c88a641701f3b$var$ROOT_CONTENT_DISMISS, {
556
+ bubbles: true,
557
+ cancelable: true
558
+ });
559
+ (_ref$current = ref.current) === null || _ref$current === void 0 || _ref$current.dispatchEvent(rootContentDismissEvent);
560
+ },
561
+ onFocusOutside: $yHMN2$composeEventHandlers(props.onFocusOutside, (event)=>{
562
+ var _context$rootNavigati;
563
+ onContentFocusOutside();
564
+ const target = event.target; // Only dismiss content when focus moves outside of the menu
565
+ if ((_context$rootNavigati = context.rootNavigationMenu) !== null && _context$rootNavigati !== void 0 && _context$rootNavigati.contains(target)) event.preventDefault();
566
+ }),
567
+ onPointerDownOutside: $yHMN2$composeEventHandlers(props.onPointerDownOutside, (event)=>{
568
+ var _context$viewport;
569
+ const target = event.target;
570
+ const isTrigger = getItems().some((item)=>{
571
+ var _item$ref$current;
572
+ return (_item$ref$current = item.ref.current) === null || _item$ref$current === void 0 ? void 0 : _item$ref$current.contains(target);
573
+ });
574
+ const isRootViewport = context.isRootMenu && ((_context$viewport = context.viewport) === null || _context$viewport === void 0 ? void 0 : _context$viewport.contains(target));
575
+ if (isTrigger || isRootViewport || !context.isRootMenu) event.preventDefault();
576
+ }),
577
+ onKeyDown: $yHMN2$composeEventHandlers(props.onKeyDown, (event)=>{
578
+ const isMetaKey = event.altKey || event.ctrlKey || event.metaKey;
579
+ const isTabKey = event.key === 'Tab' && !isMetaKey;
580
+ if (isTabKey) {
581
+ const candidates = $322c88a641701f3b$var$getTabbableCandidates(event.currentTarget);
582
+ const focusedElement = document.activeElement;
583
+ const index = candidates.findIndex((candidate)=>candidate === focusedElement
584
+ );
585
+ const isMovingBackwards = event.shiftKey;
586
+ const nextCandidates = isMovingBackwards ? candidates.slice(0, index).reverse() : candidates.slice(index + 1, candidates.length);
587
+ if ($322c88a641701f3b$var$focusFirst(nextCandidates)) // prevent browser tab keydown because we've handled focus
588
+ event.preventDefault();
589
+ else {
590
+ var _focusProxyRef$curren;
591
+ // If we can't focus that means we're at the edges
592
+ // so focus the proxy and let browser handle
593
+ // tab/shift+tab keypress on the proxy instead
594
+ (_focusProxyRef$curren = focusProxyRef.current) === null || _focusProxyRef$curren === void 0 || _focusProxyRef$curren.focus();
595
+ }
596
+ }
597
+ })
598
+ })));
599
+ });
600
+ /* -------------------------------------------------------------------------------------------------
601
+ * NavigationMenuViewport
602
+ * -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$VIEWPORT_NAME = 'NavigationMenuViewport';
603
+ const $322c88a641701f3b$export$ee880b97cc6d44a5 = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
604
+ const { forceMount: forceMount , ...viewportProps } = props;
605
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$VIEWPORT_NAME, props.__scopeNavigationMenu);
606
+ const open = Boolean(context.value);
607
+ return /*#__PURE__*/ $yHMN2$createElement($yHMN2$Presence, {
608
+ present: forceMount || open
609
+ }, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuViewportImpl, $yHMN2$babelruntimehelpersesmextends({}, viewportProps, {
610
+ ref: forwardedRef
611
+ })));
612
+ });
613
+ /*#__PURE__*/ Object.assign($322c88a641701f3b$export$ee880b97cc6d44a5, {
614
+ displayName: $322c88a641701f3b$var$VIEWPORT_NAME
615
+ });
616
+ /* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$NavigationMenuViewportImpl = /*#__PURE__*/ $yHMN2$forwardRef((props1, forwardedRef)=>{
617
+ const { __scopeNavigationMenu: __scopeNavigationMenu , children: children , ...viewportImplProps } = props1;
618
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$VIEWPORT_NAME, __scopeNavigationMenu);
619
+ const composedRefs = $yHMN2$useComposedRefs(forwardedRef, context.onViewportChange);
620
+ const viewportContentContext = $322c88a641701f3b$var$useViewportContentContext($322c88a641701f3b$var$CONTENT_NAME, props1.__scopeNavigationMenu);
621
+ const [size, setSize] = $yHMN2$useState(null);
622
+ const [content, setContent] = $yHMN2$useState(null);
623
+ const viewportWidth = size ? (size === null || size === void 0 ? void 0 : size.width) + 'px' : undefined;
624
+ const viewportHeight = size ? (size === null || size === void 0 ? void 0 : size.height) + 'px' : undefined;
625
+ const open = Boolean(context.value); // We persist the last active content value as the viewport may be animating out
626
+ // and we want the content to remain mounted for the lifecycle of the viewport.
627
+ const activeContentValue = open ? context.value : context.previousValue;
628
+ /**
629
+ * Update viewport size to match the active content node.
630
+ * We prefer offset dimensions over `getBoundingClientRect` as the latter respects CSS transform.
631
+ * For example, if content animates in from `scale(0.5)` the dimensions would be anything
632
+ * from `0.5` to `1` of the intended size.
633
+ */ const handleSizeChange = ()=>{
634
+ if (content) setSize({
635
+ width: content.offsetWidth,
636
+ height: content.offsetHeight
637
+ });
638
+ };
639
+ $322c88a641701f3b$var$useResizeObserver(content, handleSizeChange);
640
+ return /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.div, $yHMN2$babelruntimehelpersesmextends({
641
+ "data-state": $322c88a641701f3b$var$getOpenState(open),
642
+ "data-orientation": context.orientation
643
+ }, viewportImplProps, {
644
+ ref: composedRefs,
645
+ style: {
646
+ // Prevent interaction when animating out
647
+ pointerEvents: !open && context.isRootMenu ? 'none' : undefined,
648
+ ['--radix-navigation-menu-viewport-width']: viewportWidth,
649
+ ['--radix-navigation-menu-viewport-height']: viewportHeight,
650
+ ...viewportImplProps.style
651
+ },
652
+ onPointerEnter: $yHMN2$composeEventHandlers(props1.onPointerEnter, ()=>{
653
+ context.onItemOver(activeContentValue);
654
+ }),
655
+ onPointerLeave: $yHMN2$composeEventHandlers(props1.onPointerLeave, $322c88a641701f3b$var$whenMouse(context.onItemLeave))
656
+ }), Array.from(viewportContentContext.items).map(([value, { ref: ref , forceMount: forceMount , ...props }])=>{
657
+ const isActive = activeContentValue === value;
658
+ return /*#__PURE__*/ $yHMN2$createElement($yHMN2$Presence, {
659
+ key: value,
660
+ present: forceMount || isActive
661
+ }, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$NavigationMenuContentImpl, $yHMN2$babelruntimehelpersesmextends({}, props, {
662
+ ref: $yHMN2$composeRefs(ref, (node)=>{
663
+ // We only want to update the stored node when another is available
664
+ // as we need to smoothly transition between them.
665
+ if (isActive && node) setContent(node);
666
+ })
667
+ })));
668
+ }));
669
+ });
670
+ /* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$FOCUS_GROUP_NAME = 'FocusGroup';
671
+ const $322c88a641701f3b$var$FocusGroup = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
672
+ const { __scopeNavigationMenu: __scopeNavigationMenu , ...groupProps } = props;
673
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$FOCUS_GROUP_NAME, __scopeNavigationMenu);
674
+ return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroupCollection.Provider, {
675
+ scope: __scopeNavigationMenu
676
+ }, /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroupCollection.Slot, {
677
+ scope: __scopeNavigationMenu
678
+ }, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.div, $yHMN2$babelruntimehelpersesmextends({
679
+ dir: context.dir
680
+ }, groupProps, {
681
+ ref: forwardedRef
682
+ }))));
683
+ });
684
+ /* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$var$ARROW_KEYS = [
685
+ 'ArrowRight',
686
+ 'ArrowLeft',
687
+ 'ArrowUp',
688
+ 'ArrowDown'
689
+ ];
690
+ const $322c88a641701f3b$var$FOCUS_GROUP_ITEM_NAME = 'FocusGroupItem';
691
+ const $322c88a641701f3b$var$FocusGroupItem = /*#__PURE__*/ $yHMN2$forwardRef((props, forwardedRef)=>{
692
+ const { __scopeNavigationMenu: __scopeNavigationMenu , ...groupProps } = props;
693
+ const getItems = $322c88a641701f3b$var$useFocusGroupCollection(__scopeNavigationMenu);
694
+ const context = $322c88a641701f3b$var$useNavigationMenuContext($322c88a641701f3b$var$FOCUS_GROUP_ITEM_NAME, __scopeNavigationMenu);
695
+ return /*#__PURE__*/ $yHMN2$createElement($322c88a641701f3b$var$FocusGroupCollection.ItemSlot, {
696
+ scope: __scopeNavigationMenu
697
+ }, /*#__PURE__*/ $yHMN2$createElement($yHMN2$Primitive.button, $yHMN2$babelruntimehelpersesmextends({}, groupProps, {
698
+ ref: forwardedRef,
699
+ onKeyDown: $yHMN2$composeEventHandlers(props.onKeyDown, (event)=>{
700
+ const isFocusNavigationKey = [
701
+ 'Home',
702
+ 'End',
703
+ ...$322c88a641701f3b$var$ARROW_KEYS
704
+ ].includes(event.key);
705
+ if (isFocusNavigationKey) {
706
+ let candidateNodes = getItems().map((item)=>item.ref.current
707
+ );
708
+ const prevItemKey = context.dir === 'rtl' ? 'ArrowRight' : 'ArrowLeft';
709
+ const prevKeys = [
710
+ prevItemKey,
711
+ 'ArrowUp',
712
+ 'End'
713
+ ];
714
+ if (prevKeys.includes(event.key)) candidateNodes.reverse();
715
+ if ($322c88a641701f3b$var$ARROW_KEYS.includes(event.key)) {
716
+ const currentIndex = candidateNodes.indexOf(event.currentTarget);
717
+ candidateNodes = candidateNodes.slice(currentIndex + 1);
718
+ }
719
+ /**
720
+ * Imperative focus during keydown is risky so we prevent React's batching updates
721
+ * to avoid potential bugs. See: https://github.com/facebook/react/issues/20332
722
+ */ setTimeout(()=>$322c88a641701f3b$var$focusFirst(candidateNodes)
723
+ ); // Prevent page scroll while navigating
724
+ event.preventDefault();
725
+ }
726
+ })
727
+ })));
728
+ });
729
+ /**
730
+ * Returns a list of potential tabbable candidates.
731
+ *
732
+ * NOTE: This is only a close approximation. For example it doesn't take into account cases like when
733
+ * elements are not visible. This cannot be worked out easily by just reading a property, but rather
734
+ * necessitate runtime knowledge (computed styles, etc). We deal with these cases separately.
735
+ *
736
+ * See: https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
737
+ * Credit: https://github.com/discord/focus-layers/blob/master/src/util/wrapFocus.tsx#L1
738
+ */ function $322c88a641701f3b$var$getTabbableCandidates(container) {
739
+ const nodes = [];
740
+ const walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
741
+ acceptNode: (node)=>{
742
+ const isHiddenInput = node.tagName === 'INPUT' && node.type === 'hidden';
743
+ if (node.disabled || node.hidden || isHiddenInput) return NodeFilter.FILTER_SKIP; // `.tabIndex` is not the same as the `tabindex` attribute. It works on the
744
+ // runtime's understanding of tabbability, so this automatically accounts
745
+ // for any kind of element that could be tabbed to.
746
+ return node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
747
+ }
748
+ });
749
+ while(walker.nextNode())nodes.push(walker.currentNode); // we do not take into account the order of nodes with positive `tabIndex` as it
750
+ // hinders accessibility to have tab order different from visual order.
751
+ return nodes;
752
+ }
753
+ function $322c88a641701f3b$var$focusFirst(candidates) {
754
+ const previouslyFocusedElement = document.activeElement;
755
+ return candidates.some((candidate)=>{
756
+ // if focus is already where we want to go, we don't want to keep going through the candidates
757
+ if (candidate === previouslyFocusedElement) return true;
758
+ candidate.focus();
759
+ return document.activeElement !== previouslyFocusedElement;
760
+ });
761
+ }
762
+ function $322c88a641701f3b$var$removeFromTabOrder(candidates) {
763
+ candidates.forEach((candidate)=>{
764
+ candidate.dataset.tabindex = candidate.getAttribute('tabindex') || '';
765
+ candidate.setAttribute('tabindex', '-1');
766
+ });
767
+ return ()=>{
768
+ candidates.forEach((candidate)=>{
769
+ const prevTabIndex = candidate.dataset.tabindex;
770
+ candidate.setAttribute('tabindex', prevTabIndex);
771
+ });
772
+ };
773
+ }
774
+ function $322c88a641701f3b$var$useResizeObserver(element, onResize) {
775
+ const handleResize = $yHMN2$useCallbackRef(onResize);
776
+ $yHMN2$useLayoutEffect(()=>{
777
+ let rAF = 0;
778
+ if (element) {
779
+ /**
780
+ * Resize Observer will throw an often benign error that says `ResizeObserver loop
781
+ * completed with undelivered notifications`. This means that ResizeObserver was not
782
+ * able to deliver all observations within a single animation frame, so we use
783
+ * `requestAnimationFrame` to ensure we don't deliver unnecessary observations.
784
+ * Further reading: https://github.com/WICG/resize-observer/issues/38
785
+ */ const resizeObserver = new ResizeObserver(()=>{
786
+ cancelAnimationFrame(rAF);
787
+ rAF = window.requestAnimationFrame(handleResize);
788
+ });
789
+ resizeObserver.observe(element);
790
+ return ()=>{
791
+ window.cancelAnimationFrame(rAF);
792
+ resizeObserver.unobserve(element);
793
+ };
794
+ }
795
+ }, [
796
+ element,
797
+ handleResize
798
+ ]);
799
+ }
800
+ function $322c88a641701f3b$var$getOpenState(open) {
801
+ return open ? 'open' : 'closed';
802
+ }
803
+ function $322c88a641701f3b$var$makeTriggerId(baseId, value) {
804
+ return `${baseId}-trigger-${value}`;
805
+ }
806
+ function $322c88a641701f3b$var$makeContentId(baseId, value) {
807
+ return `${baseId}-content-${value}`;
808
+ }
809
+ function $322c88a641701f3b$var$whenMouse(handler) {
810
+ return (event)=>event.pointerType === 'mouse' ? handler(event) : undefined
811
+ ;
812
+ }
813
+ /* -----------------------------------------------------------------------------------------------*/ const $322c88a641701f3b$export$be92b6f5f03c0fe9 = $322c88a641701f3b$export$5b2278cf1e8bcae2;
814
+ const $322c88a641701f3b$export$d7a01e11500dfb6f = $322c88a641701f3b$export$5958edd6c4ee7c79;
815
+ const $322c88a641701f3b$export$54c2e3dc7acea9f5 = $322c88a641701f3b$export$c361068a95fd2286;
816
+ const $322c88a641701f3b$export$6d08773d2e66f8f2 = $322c88a641701f3b$export$ffdbb83a2de845c2;
817
+ const $322c88a641701f3b$export$41fb9f06171c75f4 = $322c88a641701f3b$export$37fe8002734d8f2;
818
+ const $322c88a641701f3b$export$a6c7ac8248d6e38a = $322c88a641701f3b$export$6893bf21536567da;
819
+ const $322c88a641701f3b$export$adb584737d712b70 = $322c88a641701f3b$export$8ddb526647c0d8fb;
820
+ const $322c88a641701f3b$export$7c6e2c02157bb7d2 = $322c88a641701f3b$export$38e00e996c2f93f7;
821
+ const $322c88a641701f3b$export$d5c6c08dc2d3ca7 = $322c88a641701f3b$export$ee880b97cc6d44a5;
822
+
823
+
824
+
825
+
826
+ export {$322c88a641701f3b$export$fb8ea5af8c9fcdf0 as createNavigationMenuScope, $322c88a641701f3b$export$5b2278cf1e8bcae2 as NavigationMenu, $322c88a641701f3b$export$5958edd6c4ee7c79 as NavigationMenuSub, $322c88a641701f3b$export$c361068a95fd2286 as NavigationMenuList, $322c88a641701f3b$export$ffdbb83a2de845c2 as NavigationMenuItem, $322c88a641701f3b$export$37fe8002734d8f2 as NavigationMenuTrigger, $322c88a641701f3b$export$6893bf21536567da as NavigationMenuLink, $322c88a641701f3b$export$8ddb526647c0d8fb as NavigationMenuIndicator, $322c88a641701f3b$export$38e00e996c2f93f7 as NavigationMenuContent, $322c88a641701f3b$export$ee880b97cc6d44a5 as NavigationMenuViewport, $322c88a641701f3b$export$be92b6f5f03c0fe9 as Root, $322c88a641701f3b$export$d7a01e11500dfb6f as Sub, $322c88a641701f3b$export$54c2e3dc7acea9f5 as List, $322c88a641701f3b$export$6d08773d2e66f8f2 as Item, $322c88a641701f3b$export$41fb9f06171c75f4 as Trigger, $322c88a641701f3b$export$a6c7ac8248d6e38a as Link, $322c88a641701f3b$export$adb584737d712b70 as Indicator, $322c88a641701f3b$export$7c6e2c02157bb7d2 as Content, $322c88a641701f3b$export$d5c6c08dc2d3ca7 as Viewport};
2
827
  //# sourceMappingURL=index.module.js.map