@splenddev/kreativ-ui 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,12 +1,4054 @@
1
- 'use strict';var react=require('react'),framerMotion=require('framer-motion'),clsx=require('clsx'),tailwindMerge=require('tailwind-merge'),jsxRuntime=require('react/jsx-runtime'),lucideReact=require('lucide-react'),classVarianceAuthority=require('class-variance-authority');var _documentCurrentScript=typeof document!=='undefined'?document.currentScript:null;var ao=Object.defineProperty;var i=(e,n)=>ao(e,"name",{value:n,configurable:true});function u(...e){return tailwindMerge.twMerge(clsx.clsx(e))}i(u,"cn");var ye=react.createContext(null);function X(){let e=react.useContext(ye);if(!e)throw new Error("useTheme() was called outside <UIProvider>. Wrap your app in <UIProvider> from 'kreativ-ui'.");return e}i(X,"useTheme");function re(e,n=false,t="button",o={}){let{includeHeight:s=true}=o,{theme:r,fallbackSize:l}=X();return react.useMemo(()=>{let a=r.sizes,d=a[e]??a[l]??Object.values(a)[0]??{},c={};if(s&&d.height&&(c.height=d.height),d.width?c.width=d.width:n&&s&&d.height&&(c.width=d.height),!n&&d.paddingX&&(c.paddingLeft=d.paddingX,c.paddingRight=d.paddingX),d.paddingY&&(c.paddingTop=d.paddingY,c.paddingBottom=d.paddingY),d.fontSize&&(c.fontSize=d.fontSize),d.gap&&(c.gap=n?0:d.gap),d.radius){let m=`--kui-${t}-radius`;c[m]=d.radius;}return {style:c,iconSize:d.iconSize}},[r.sizes,e,l,n,s,t])}i(re,"useSizeStyle");function fo(e,n){return {...e,base:n.base??e.base,variants:{...e.variants,...n.variants},defaultVariants:{...e.defaultVariants,...n.defaultVariants},compoundVariants:n.compoundVariants??e.compoundVariants}}i(fo,"mergeRecipeDefinition");function Ft(e,n){if(!n)return e;let t={...e};for(let[o,s]of Object.entries(n)){let r=e[o];if(!r){t[o]=s;continue}t[o]=fo(r,s);}return t}i(Ft,"mergeRecipes");function bo(e,n){return Object.entries(e).every(([t,o])=>n[t]===o)}i(bo,"matchesConditions");function te(e,n={}){if(!e)return "";let t={...e.defaultVariants,...n},o=[];if(e.base&&o.push(e.base),e.variants)for(let[s,r]of Object.entries(e.variants)){let l=t[s];if(l===void 0)continue;let a=r[String(l)];a&&o.push(a);}if(e.compoundVariants)for(let s of e.compoundVariants)bo(s.conditions,t)&&o.push(s.className);return u(...o)}i(te,"resolveRecipe");var go="inline-flex items-center justify-center rounded-[var(--kui-button-radius,var(--kui-radius))] font-medium transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-2 focus-visible:ring-offset-surface disabled:opacity-60 disabled:pointer-events-none",xo={solid:"",outline:"border bg-transparent",ghost:"bg-transparent",soft:"",link:"bg-transparent p-0 h-auto hover:underline"},Dt={brand:{solid:"bg-brand text-brand-fg hover:bg-brand-hover",outline:"border-brand text-brand hover:bg-brand/10",ghost:"text-brand hover:bg-brand/10",soft:"bg-brand/10 text-brand hover:bg-brand/20",link:"text-brand"},destructive:{solid:"bg-destructive text-destructive-fg hover:bg-destructive-hover",outline:"border-destructive text-destructive hover:bg-destructive/10",ghost:"text-destructive hover:bg-destructive/10",soft:"bg-destructive/10 text-destructive hover:bg-destructive/20",link:"text-destructive"},success:{solid:"bg-success text-success-fg hover:bg-success-hover",outline:"border-success text-success hover:bg-success/10",ghost:"text-success hover:bg-success/10",soft:"bg-success/10 text-success hover:bg-success/20",link:"text-success"},warning:{solid:"bg-warning text-warning-fg hover:bg-warning-hover",outline:"border-warning text-warning hover:bg-warning/10",ghost:"text-warning hover:bg-warning/10",soft:"bg-warning/10 text-warning hover:bg-warning/20",link:"text-warning"},info:{solid:"bg-info text-info-fg hover:bg-info-hover",outline:"border-info text-info hover:bg-info/10",ghost:"text-info hover:bg-info/10",soft:"bg-info/10 text-info hover:bg-info/20",link:"text-info"},white:{solid:"bg-white text-black hover:bg-gray-50",outline:"border-white/30 text-white hover:bg-white/10",ghost:"text-white hover:bg-white/10",soft:"bg-white/10 text-white hover:bg-white/20",link:"text-white"},neutral:{solid:"bg-surface-raised text-text hover:bg-surface-sunken",outline:"border-border text-text hover:bg-surface-raised",ghost:"text-text hover:bg-surface-raised",soft:"bg-surface-raised text-text hover:bg-surface-sunken",link:"text-text"}},ho=i(()=>{let e=[];for(let[n,t]of Object.entries(Dt))for(let[o,s]of Object.entries(t))e.push({conditions:{color:n,variant:o},className:s});return e},"buildCompoundVariants"),Lt={base:go,variants:{variant:xo,color:Object.fromEntries(Object.keys(Dt).map(e=>[e,""]))},defaultVariants:{variant:"solid",color:"brand"},compoundVariants:ho()};var vo="flex min-w-0 flex-1 font-sans bg-transparent border-0 outline-none transition-colors duration-[var(--kui-duration-fast)] placeholder:text-text-muted disabled:pointer-events-none disabled:cursor-not-allowed",Pt={base:vo,variants:{variant:{outline:"",filled:"",ghost:""}},defaultVariants:{variant:"outline"}};var yo="group relative inline-flex items-center rounded-[var(--kui-radii-md)] transition-colors duration-[var(--kui-duration-fast)] focus-within:outline-none focus-within:ring-2 ",So={outline:"border border-border bg-transparent text-text hover:border-brand",filled:"border border-transparent bg-surface-raised text-text hover:bg-surface",ghost:"border border-transparent bg-transparent text-text hover:bg-surface-raised"},wo={none:"focus-within:ring-brand/20",error:"border-destructive focus-within:ring-destructive/20",success:"border-success focus-within:ring-success/20"},Bt={base:yo,variants:{variant:So,state:wo,rounded:{true:"rounded-full",false:""},fullWidth:{true:"w-full",false:""},disabled:{true:"pointer-events-none cursor-not-allowed opacity-50",false:""},hasAdornment:{true:"px-2",false:""}},defaultVariants:{variant:"outline",state:"none",rounded:false,fullWidth:true,disabled:false,hasAdornment:false}};var Ht=new Set(["Enter"," "]),Se=react.forwardRef(({variant:e="solid",color:n="brand",size:t="md",isLoading:o=false,leftIcon:s,rightIcon:r,fullWidth:l=false,disabled:a,className:d,style:c,iconOnly:m,children:g,render:x,onKeyDown:f,onKeyUp:p,...b},E)=>{let{theme:v}=X(),{style:I,iconSize:y}=re(t,m,"button"),D=framerMotion.useReducedMotion(),R=!a&&!o,[S,T]=react.useState(false);function P(k){f?.(k),R&&Ht.has(k.key)&&T(true);}i(P,"handleKeyDown");function L(k){p?.(k),Ht.has(k.key)&&T(false);}i(L,"handleKeyUp");let h=te(v.recipes.Button,{variant:e,color:n}),N=u(h,l&&"w-full",o&&"animate-kui-pulse",d),M={...I,...c},F=jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[o&&jsxRuntime.jsx("span",{className:"animate-kui-spin rounded-full border-2 border-current border-t-transparent",style:{width:y,height:y},"aria-hidden":"true"}),!o&&s,m&&o?null:g,!o&&r]});return x?x({className:N,style:M,disabled:a||o,"aria-busy":o||void 0,children:F}):jsxRuntime.jsx(framerMotion.motion.button,{ref:E,disabled:a||o,className:N,style:M,"aria-busy":o||void 0,animate:{scale:S?.975:1},whileHover:R?{scale:1.015}:void 0,whileTap:R?{scale:.975}:void 0,transition:D?{duration:0}:{type:"spring",stiffness:500,damping:30},onKeyDown:P,onKeyUp:L,...b,children:F})});Se.displayName="Button";var At=/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;function Us(e){let n=e.trim();if(At.test(n))return n.length===4?("#"+[...n.slice(1)].map(o=>o+o).join("")).toUpperCase():n.toUpperCase();let t=n.replace(/[^\d,]/g,"").split(",").map(Number);return t.length!==3||t.some(Number.isNaN)?"#000000":"#"+t.map(o=>o.toString(16).padStart(2,"0")).join("").toUpperCase()}i(Us,"rgbToHex");function Xs(e){if(!At.test(e))return null;let n=e.length===4?"#"+[...e.slice(1)].map(r=>r+r).join(""):e,t=parseInt(n.slice(1,3),16),o=parseInt(n.slice(3,5),16),s=parseInt(n.slice(5,7),16);return `${t} ${o} ${s}`}i(Xs,"hexToRgbString");var Lo={type:"none",duration:300,delay:0,easing:"ease-in-out"},Po=i(e=>{switch(e){case "fade":return {initial:{opacity:0},animate:{opacity:1},exit:{opacity:0}};case "slide":return {initial:{opacity:0,x:-20},animate:{opacity:1,x:0},exit:{opacity:0,x:20}};case "scale":return {initial:{opacity:0,scale:.5},animate:{opacity:1,scale:1},exit:{opacity:0,scale:1.5}};case "rotate":return {initial:{opacity:0,rotate:-90},animate:{opacity:1,rotate:0},exit:{opacity:0,rotate:90}};default:return {initial:{opacity:1},animate:{opacity:1},exit:{opacity:1}}}},"getIconVariants");function Bo({variant:e="ghost",activeVariant:n="solid",color:t="neutral",activeColor:o="brand",size:s="sm",iconOnly:r=false,allowSystem:l=false,orientation:a="horizontal",rounded:d=false,unstyled:c=false,labels:m,icons:g,className:x,buttonProps:f={},display:p="buttons",transition:b=Lo}){let{mode:E,setMode:v,resolvedMode:I}=X(),y=l?E:I,D=[{key:"light",label:m?.light??"Light",icon:g?.light??jsxRuntime.jsx(lucideReact.Sun,{size:16})},{key:"dark",label:m?.dark??"Dark",icon:g?.dark??jsxRuntime.jsx(lucideReact.Moon,{size:16})},...l?[{key:"system",label:m?.system??"System",icon:g?.system??jsxRuntime.jsx(lucideReact.Monitor,{size:16})}]:[]],R=D.map(V=>V.key),S=D.find(({key:V})=>V===y)??D[0],T=d&&!(a==="vertical"&&!r);react.useEffect(()=>{d&&!T&&console.warn("[kreativ-ui/ThemeToggler] `rounded` is ignored when orientation='vertical' and iconOnly={false}.");},[d,T]);let P=i(()=>{let V=R.indexOf(y);v(R[(V+1)%R.length]);},"handleCycle"),L=i(V=>V==="system"?E==="system":y===V,"isActive"),h=u("inline-flex gap-1",a==="vertical"&&"flex-col",!c&&["border border-border bg-surface p-1",T?"rounded-full":"rounded-lg"],x),N=T?"rounded-full":"rounded-lg",M=p==="cycle"&&b.type!=="none",F=Po(b.type||"none"),k={duration:(b.duration||300)/1e3,delay:(b.delay||0)/1e3,ease:b.easing||"ease-in-out"};if(p==="cycle")return jsxRuntime.jsxs(Se,{size:s,variant:e,color:t,onClick:P,"aria-label":`Current theme: ${S.label}`,className:u(T&&"rounded-full",f.className),...f,children:[jsxRuntime.jsx(framerMotion.AnimatePresence,{mode:"wait",children:jsxRuntime.jsx(framerMotion.motion.span,{initial:M?F.initial:void 0,animate:M?F.animate:void 0,exit:M?F.exit:void 0,transition:k,children:S.icon},S.key)}),!r&&S.label]});let O=D.map(({key:V,label:B,icon:Y})=>{let A=L(V);return jsxRuntime.jsx(Se,{size:s,variant:A?n:e,color:A?o:t,onClick:()=>v(V),className:u(N,f.className),leftIcon:Y,"aria-pressed":A,...f,children:!r&&B},V)});return c?jsxRuntime.jsx("div",{role:"group","aria-label":"Theme selector",className:u("inline-flex gap-1",a==="vertical"&&"flex-col",x),children:O}):jsxRuntime.jsx("div",{role:"group","aria-label":"Theme selector",className:h,children:O})}i(Bo,"ThemeToggler");var $o={sm:640,md:768,lg:1024,xl:1280,"2xl":1536};function ua(e){let n=`(min-width: ${$o[e]}px)`,[t,o]=react.useState(()=>typeof window<"u"&&window.matchMedia(n).matches);return react.useEffect(()=>{let s=window.matchMedia(n),r=i(l=>o(l.matches),"listener");return s.addEventListener("change",r),o(s.matches),()=>s.removeEventListener("change",r)},[n]),t}i(ua,"useBreakpoint");var qt={email:lucideReact.Mail,tel:lucideReact.Phone,url:lucideReact.Link2,search:lucideReact.Search,numeric:lucideReact.Hash,"password-current":lucideReact.Lock,"password-new":lucideReact.Lock};function Gt({size:e=14}){return jsxRuntime.jsx("span",{className:"animate-kui-spin rounded-full border-2 border-inherit border-t-transparent shrink-0",style:{width:e,height:e},"aria-hidden":"true"})}i(Gt,"Spinner");var jt={text:{placeholder:"Type something..."},email:{type:"email",inputMode:"email",autoComplete:"email",placeholder:"you@company.com"},tel:{type:"tel",inputMode:"tel",autoComplete:"tel",placeholder:"+234 800 000 0000"},url:{type:"url",inputMode:"url",autoComplete:"url",placeholder:"https://company.com"},search:{type:"search",inputMode:"search",autoComplete:"off",placeholder:"Search..."},numeric:{type:"text",inputMode:"numeric",autoComplete:"off",placeholder:"Enter a number"},"password-current":{type:"password",autoComplete:"current-password",placeholder:"\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"},"password-new":{type:"password",autoComplete:"new-password",placeholder:"Create a password"},number:{type:"number",inputMode:"decimal",autoComplete:"off",placeholder:"0.00"},date:{type:"date",inputMode:"none",placeholder:"YYYY-MM-DD"},time:{type:"time",inputMode:"none",placeholder:"HH:MM"},"datetime-local":{type:"datetime-local",inputMode:"none",placeholder:"YYYY-MM-DDTHH:MM"},month:{type:"month",inputMode:"none",placeholder:"YYYY-MM"},week:{type:"week",inputMode:"none",placeholder:"YYYY-Www"}};var Jo=1500;function Yt(e){let n=react.useRef(e),[t,o]=react.useState();return react.useEffect(()=>{if(e===n.current)return;if(n.current=e,e==="none"){o(void 0);return}o(e);let s=window.setTimeout(()=>{o(void 0);},Jo);return ()=>window.clearTimeout(s)},[e]),t}i(Yt,"useStateTransition");var De=react.createContext(null);function me(){let e=react.useContext(De);if(!e)throw new Error("FormField components must be used inside <FormField />");return e}i(me,"useFormField");function G(){return react.useContext(De)}i(G,"useOptionalFormField");function nr(...e){return n=>{e.forEach(t=>{t&&(typeof t=="function"?t(n):t.current=n);});}}i(nr,"mergeRefs");var Jt=react.forwardRef(({className:e,inputClassName:n,variant:t="outline",size:o="md",error:s,success:r,startIcon:l,endIcon:a,fullWidth:d=true,disabled:c,rounded:m=false,isLoading:g=false,clearable:x=false,onClear:f,kind:p="text",hideKindIcon:b=false,id:E,type:v,inputMode:I,autoComplete:y,placeholder:D,onChange:R,readOnly:S,value:T,defaultValue:P,style:L,...h},N)=>{let M=react.useId(),{theme:F}=X(),k=G(),O=E??k?.id??M,V=s||k?.invalid||false,B=k?.describedBy??void 0,Y=k?.required??h.required,A=react.useRef(null),{style:w,iconSize:z}=re(o,false,"input"),[C,$]=react.useState(()=>!!(T??P??"")),[K,Z]=react.useState(false);react.useEffect(()=>{T!==void 0&&$(!!T);},[T]);let ee=jt[p],oe=v??ee.type,ce=oe==="password",W=ce?K?"text":"password":oe,_=qt[p],de=!b&&_?jsxRuntime.jsx(_,{size:Number(z)||15}):void 0,Me=l||de?jsxRuntime.jsx("span",{className:"flex shrink-0 items-center justify-center",children:l??de}):null,ue=[];ce&&ue.push(jsxRuntime.jsx("button",{type:"button",tabIndex:-1,onClick:()=>Z(j=>!j),"aria-label":K?"Hide password":"Show password",className:"flex items-center justify-center text-text-muted transition-colors hover:text-text",children:K?jsxRuntime.jsx(lucideReact.EyeOff,{size:16}):jsxRuntime.jsx(lucideReact.Eye,{size:16})},"toggle-visibility")),x&&C&&!c&&ue.push(jsxRuntime.jsx("button",{type:"button",tabIndex:-1,onClick:U,"aria-label":"Clear input",className:"flex items-center justify-center text-text-muted transition-colors hover:text-text",children:jsxRuntime.jsx(lucideReact.X,{size:14})},"clear"));let xe=g?jsxRuntime.jsx(Gt,{size:Number(z)||14}):a||(ue.length?jsxRuntime.jsx("div",{className:"flex shrink-0 items-center gap-1.5",children:ue}):null),Ee=!!(Me||xe),he=s?"error":r?"success":"none",Ve=Yt(he),ze=u(te(F.recipes.FormControl,{variant:t,state:he,rounded:m,fullWidth:d,disabled:!!(c||g),hasIcon:Ee}),e),Ne=u(te(F.recipes.Input,{variant:t}),n),H={...w,...L};function q(j){$(!!j.target.value),R?.(j);}i(q,"handleChange");function U(){let j=A.current;if(!j)return;Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype,"value")?.set?.call(j,""),j.dispatchEvent(new Event("input",{bubbles:true})),j.focus(),$(false),f?.();}return i(U,"handleClear"),react.useEffect(()=>{if(!s)return;let j=A.current;j&&j.scrollIntoView({behavior:"smooth",block:"center"});},[s]),jsxRuntime.jsxs("div",{className:ze,style:H,"data-state":he,"data-state-transition":Ve,children:[Me,jsxRuntime.jsx("input",{...h,ref:nr(A,N),id:O,type:W,inputMode:I??ee.inputMode,autoComplete:y??ee.autoComplete,placeholder:D??ee.placeholder,value:T,defaultValue:P,onChange:q,readOnly:g||S,disabled:g||c,"aria-busy":g||void 0,"aria-invalid":V||void 0,"aria-describedby":B,"aria-required":Y||void 0,className:Ne,"data-variant":t,"data-size":o,"data-success":r||void 0,"data-disabled":c||void 0,"data-loading":g||void 0}),xe]},Ve??"idle")});Jt.displayName="Input";function we({id:e,error:n,required:t=false,className:o,children:s}){let r=react.useId(),l=e??r,a=`${l}-label`,d=`${l}-description`,c=`${l}-message`,[m,g]=react.useState(void 0),[x,f]=react.useState(0),p=react.useCallback(y=>{n===void 0&&g(y?.invalid?y.message:void 0);},[n]),b=react.useCallback(()=>(f(y=>y+1),()=>f(y=>y-1)),[]),E=x>0,v=n??m,I=v?"error":"none";return jsxRuntime.jsx(De.Provider,{value:{id:l,labelId:a,descriptionId:d,messageId:c,state:I,describedBy:[d,v?c:void 0].filter(Boolean).join(" ")||void 0,invalid:!!v,required:t,reportValidity:p,registerLabel:b,hasExternalLabel:E},children:jsxRuntime.jsxs("div",{className:u("flex flex-col gap-2",o),children:[s,v&&jsxRuntime.jsx(Le,{children:v})]})})}i(we,"FormField");we.Label=tt;we.Control=ot;we.Description=nt;we.Message=Le;function tt({children:e,className:n}){let t=me();return react.useEffect(()=>t.registerLabel(),[t]),jsxRuntime.jsxs("label",{id:t.labelId,htmlFor:t.id,className:u("text-sm font-medium text-text",n),children:[e,t.required&&jsxRuntime.jsx("span",{"aria-hidden":true,className:"ml-1 text-destructive",children:"*"})]})}i(tt,"FormFieldLabel");function nt({children:e}){let{descriptionId:n}=me();return jsxRuntime.jsx("p",{id:n,className:"text-sm text-text-muted",children:e})}i(nt,"FormFieldDescription");function Le({children:e}){let{messageId:n}=me();return jsxRuntime.jsx("p",{id:n,role:"alert",className:`\r
2
- animate-kui-shake [animation-delay:500ms]\r
3
- text-sm text-destructive\r
4
- `,children:e})}i(Le,"FormFieldMessage");function ot({children:e}){return jsxRuntime.jsx(jsxRuntime.Fragment,{children:e})}i(ot,"FormFieldControl");var rt=react.createContext(null);function se(e){let n=react.useContext(rt);if(!n)throw new Error(`<${e} /> must be rendered inside <Select>.`);return n}i(se,"useSelectContext");var Pe=react.createContext(null);function it(e){return [...e.entries()].filter(([,n])=>!n.disabled).map(([n])=>n)}i(it,"orderedEnabledValues");var He=react.forwardRef(({className:e,children:n,onKeyDown:t,...o},s)=>{let r=se("SelectTrigger"),{theme:l}=X(),{style:a,iconSize:d}=re(r.size,false,"select"),c=r.isInvalid?"error":r.isSuccess?"success":"none",m=u(te(l.recipes.FormControl,{variant:r.variant,state:c,rounded:!!r.rounded,fullWidth:true,disabled:r.disabled,hasAdornment:true}),e),g=r.clearable&&r.value!==void 0&&!r.disabled,x=react.useCallback(p=>{let b=it(r.items);if(!b.length)return;let E=r.activeValue?b.indexOf(r.activeValue):-1,v=E===-1?p===1?0:b.length-1:(E+p+b.length)%b.length;r.setActiveValue(b[v]);},[r]),f=react.useCallback(p=>{if(t?.(p),!p.defaultPrevented)switch(p.key){case "ArrowDown":p.preventDefault(),r.open?x(1):r.setOpen(true);break;case "ArrowUp":p.preventDefault(),r.open?x(-1):r.setOpen(true);break;case "Home":{if(!r.open)break;p.preventDefault();let b=it(r.items);b.length&&r.setActiveValue(b[0]);break}case "End":{if(!r.open)break;p.preventDefault();let b=it(r.items);b.length&&r.setActiveValue(b[b.length-1]);break}case "Enter":case " ":p.preventDefault(),r.open?r.activeValue!==void 0&&r.onValueChange(r.activeValue):r.setOpen(true);break;case "Escape":r.open&&(p.preventDefault(),r.setOpen(false));break;case "Backspace":case "Delete":r.clearable&&r.value!==void 0&&!r.open&&(p.preventDefault(),r.onClear());break;}},[r,x,t]);return jsxRuntime.jsxs("div",{ref:r.triggerRef,className:m,style:a,children:[jsxRuntime.jsxs("button",{ref:s,type:"button",id:r.triggerId,role:"combobox","aria-haspopup":"listbox","aria-expanded":r.open,"aria-labelledby":r.labelId,"aria-controls":r.contentId,"aria-activedescendant":r.open&&r.activeValue?r.optionId(r.activeValue):void 0,tabIndex:r.tabIndex,"aria-invalid":r.isInvalid||void 0,"aria-describedby":r.describedBy,"aria-required":r.required||void 0,disabled:r.disabled,"data-state":r.open?"open":"closed",onClick:()=>!r.disabled&&r.setOpen(!r.open),onKeyDown:f,className:"relative min-w-0 flex-1 bg-transparent cursor-pointer text-left outline-none disabled:cursor-not-allowed h-full",...o,children:[n,jsxRuntime.jsx("span",{"aria-hidden":true,className:"pointer-events-none absolute right-0 top-1/2 flex -translate-y-1/2 items-center gap-1.5 text-text-muted",children:jsxRuntime.jsx(lucideReact.ChevronDown,{size:14,className:u("transition-transform duration-200",r.open&&"rotate-180")})})]}),g&&jsxRuntime.jsx("button",{type:"button",tabIndex:-1,"aria-label":"Clear selection",onClick:p=>{p.preventDefault(),p.stopPropagation(),r.onClear();},onMouseDown:p=>{p.preventDefault(),p.stopPropagation();},className:"flex h-4 w-4 items-center justify-center text-text-muted transition-colors hover:text-text",children:jsxRuntime.jsx(lucideReact.X,{size:Number(d)||14})})]})});He.displayName="SelectTrigger";var rn=8;function st({className:e,children:n,...t}){let o=se("SelectContent"),s=react.useRef(null),[r,l]=react.useState("bottom");return react.useLayoutEffect(()=>{if(!o.open)return;let a=o.triggerRef.current,d=s.current;if(!a||!d)return;function c(){let m=a.getBoundingClientRect(),g=d?.offsetHeight,x=window.innerHeight-m.bottom-rn,f=m.top-rn;l(g&&g>x&&f>x?"top":"bottom");}return i(c,"measure"),c(),window.addEventListener("resize",c),window.addEventListener("scroll",c,true),()=>{window.removeEventListener("resize",c),window.removeEventListener("scroll",c,true);}},[o.open,o.triggerRef]),o.open?jsxRuntime.jsx("div",{ref:s,id:o.contentId,role:"listbox","aria-labelledby":o.triggerId,"data-state":o.open?"open":"closed","data-side":r,className:u("animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-(--kui-radii-md) border border-border bg-surface p-1 shadow-lg",r==="bottom"?"top-full mt-1":"bottom-full mb-1",e),...t,children:n}):null}i(st,"SelectContent");function at({value:e,disabled:n=false,children:t,className:o,...s}){let r=se("SelectItem"),l=r.value===e,a=r.activeValue===e,d=react.useRef(null);return react.useLayoutEffect(()=>r.registerItem(e,{label:t,disabled:n}),[e,n,t]),react.useEffect(()=>{a&&d.current?.scrollIntoView({block:"nearest"});},[a]),jsxRuntime.jsx("div",{ref:d,id:r.optionId(e),role:"option","aria-selected":l,"aria-disabled":n||void 0,"data-state":l?"selected":void 0,"data-active":a||void 0,"data-disabled":n||void 0,onMouseEnter:()=>!n&&r.setActiveValue(e),onClick:()=>!n&&r.onValueChange(e),className:u("flex cursor-pointer items-center rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",a&&"bg-brand/15 text-brand",l&&!a&&"bg-surface-raised",n&&"pointer-events-none cursor-not-allowed opacity-50",o),...s,children:t})}i(at,"SelectItem");function lt({placeholder:e,className:n}){let t=se("SelectValue"),o=t.selectedLabel??e??t.placeholder;return jsxRuntime.jsx("span",{className:u("min-w-0 truncate",n),children:o})}i(lt,"SelectValue");function ct({children:e,className:n}){let t=react.useId(),[o,s]=react.useState(void 0);return jsxRuntime.jsx(Pe.Provider,{value:{labelId:o??t,setHasLabel:s},children:jsxRuntime.jsx("div",{role:"group","aria-labelledby":o,className:u("py-1",n),children:e})})}i(ct,"SelectGroup");function an({children:e,className:n}){let t=react.useId(),o=react.useContext(Pe);return react.useEffect(()=>{o?.setHasLabel(t);},[o,t]),jsxRuntime.jsx("div",{id:t,className:u("px-2.5 py-1.5 font-mono text-[11px] text-text-muted",n),children:e})}i(an,"SelectLabel");function le({value:e,defaultValue:n,onValueChange:t,disabled:o=false,required:s,name:r,variant:l="outline",size:a="md",className:d,placeholder:c,"aria-describedby":m,clearable:g=false,error:x,success:f,tabIndex:p,rounded:b,children:E}){let v=react.useId(),I=G(),y=I?.id??v,D=react.useRef(null),R=`${y}-listbox`,S=I?.labelId,[T,P]=react.useState(n),L=e!==void 0?e:T,h=x||I?.invalid||false,N=!!(f&&!h),M=I?.describedBy??m,F=I?.required??s,[k,O]=react.useState(false),[V,B]=react.useState(L),[Y,A]=react.useState(),w=react.useRef(new Map),[z,C]=react.useState(new Map),$=react.useCallback((W,_)=>(w.current.set(W,_),C(new Map(w.current)),()=>{w.current.delete(W),C(new Map(w.current));}),[]),K=react.useCallback(W=>{let _=w.current.get(W)?.label??W;A(_),e===void 0&&P(W),t?.(W),O(false);},[e,t]),Z=react.useCallback(()=>{B(void 0),P(void 0),t?.(void 0),A(void 0);},[e,t]),ee=react.useCallback(W=>`${R}-option-${W}`,[R]);react.useEffect(()=>{k&&B(L);},[k,L]),react.useEffect(()=>{if(L!==void 0){let W=w.current.get(L)?.label;W!==void 0&&A(W);}},[L,z]);let oe=react.useRef(null);react.useEffect(()=>{if(!k)return;function W(_){oe.current&&!oe.current.contains(_.target)&&O(false);}return i(W,"handlePointerDown"),document.addEventListener("mousedown",W),()=>document.removeEventListener("mousedown",W)},[k]);let ce=react.useMemo(()=>({value:L,selectedLabel:Y,onValueChange:K,disabled:o,variant:l,size:a,open:k,setOpen:O,triggerId:y,contentId:R,labelId:S,isInvalid:h,isSuccess:N,describedBy:M,required:F,activeValue:V,setActiveValue:B,items:z,registerItem:$,optionId:ee,placeholder:c,clearable:g,onClear:Z,triggerRef:D,rounded:b,tabIndex:p}),[L,z,Y,K,o,l,a,k,y,R,h,N,M,F,V,$,ee,c,g,Z,D,b,S,p]);return jsxRuntime.jsx(rt.Provider,{value:ce,children:jsxRuntime.jsxs("div",{ref:oe,className:u("relative inline-block w-full",d),children:[E,r&&jsxRuntime.jsx("input",{type:"hidden",name:r,value:L??"",disabled:o,required:F})]})})}i(le,"Select");le.Trigger=He;le.Content=st;le.Item=at;le.Value=lt;le.Group=ct;le.Label=an;var cn=u("flex w-full min-w-0 bg-transparent font-sans outline-none border-0","text-text placeholder:text-text-muted","transition-colors duration-[var(--kui-duration-fast)]","disabled:opacity-50 disabled:pointer-events-none disabled:cursor-not-allowed"),dn={none:"resize-none",both:"resize",horizontal:"resize-x",vertical:"resize-y"};function Br(...e){return n=>{e.forEach(t=>{t&&(typeof t=="function"?t(n):t.current=n);});}}i(Br,"mergeRefs");var ke=react.forwardRef(({className:e,value:n,defaultValue:t,size:o="md",fullWidth:s=true,resize:r="vertical",autoResize:l=false,minRows:a,maxRows:d,clearable:c=false,onClear:m,characterCounter:g=false,debounceDelay:x=0,trimOnBlur:f=false,error:p,success:b,onValidate:E,disabled:v,id:I,maxLength:y,variant:D="outline",onValueChange:R,onChange:S,onBlur:T,rows:P,...L},h)=>{let N=react.useId(),M=G(),F=M?.id??I??N,{theme:k}=X(),O=react.useRef(null),V=react.useRef(null),[B,Y]=react.useState(()=>n??t??"");react.useEffect(()=>{n!==void 0&&Y(n);},[n]);let[A,w]=react.useState({}),z=p??M?.invalid??A.invalid??false,C=b??(E?A.invalid===false:false),$=z?"error":C?"success":"none";react.useEffect(()=>()=>{V.current&&clearTimeout(V.current);},[]);function K(H,{immediate:q=false}={}){Y(H),V.current&&clearTimeout(V.current),x>0&&!q?V.current=setTimeout(()=>{R?.(H);},x):R?.(H);}i(K,"commitValue");function Z(H){K(H.target.value),S?.(H);}i(Z,"handleChange");function ee(H){if(!E||p!==void 0||b!==void 0)return;let q=E(H),U=q===true?{invalid:false,message:void 0}:q===false?{invalid:true,message:void 0}:{invalid:true,message:q};w(U),M?.reportValidity(U.invalid?U:null);}i(ee,"runValidation");function oe(H){let q=B;if(f){let U=B.trim();U!==B&&(K(U,{immediate:true}),q=U);}ee(q),T?.(H);}i(oe,"handleBlur");function ce(){K("",{immediate:true}),O.current?.focus(),w({}),M?.reportValidity(null),m?.();}i(ce,"handleClear"),react.useLayoutEffect(()=>{if(!l)return;let H=O.current;if(!H)return;let q=window.getComputedStyle(H),U=parseFloat(q.lineHeight)||parseFloat(q.fontSize)*1.2,j=parseFloat(q.paddingTop)+parseFloat(q.paddingBottom),et=parseFloat(q.borderTopWidth)+parseFloat(q.borderBottomWidth),Nt=a?U*a+j+et:void 0,Fe=d?U*d+j+et:void 0;H.style.height="auto";let ve=H.scrollHeight;Nt&&(ve=Math.max(ve,Nt)),Fe&&(ve=Math.min(ve,Fe)),H.style.height=`${ve}px`,H.style.overflowY=Fe&&H.scrollHeight>Fe?"auto":"hidden";},[l,B,a,d]);let W=B.length>0,_=c&&W&&!v,de=g,Me=y?B.length>=y*.9:false,ue=_||de,xe=!M?.describedBy&&(z||C)?`${F}-message`:void 0,Ee=de?`${F}-counter`:void 0,he=u(M?.describedBy,xe,Ee).trim()||void 0,Ve=u(te(k.recipes.FormControl,{variant:D,state:$,fullWidth:s,disabled:!!v}),"items-start",e),{style:ze}=re(o,false,"textarea",{includeHeight:false}),Ne={...ze};if(ue){let H=ze.paddingBottom;Ne.paddingBottom=H?`calc(${H} + 1.25rem)`:"1.5rem";}return jsxRuntime.jsxs("div",{className:Ve,children:[jsxRuntime.jsx("textarea",{ref:Br(O,h),id:F,value:B,onChange:Z,onBlur:oe,disabled:v,maxLength:y,rows:l?void 0:P??a,"aria-invalid":z||void 0,"aria-describedby":he,style:Ne,className:u(cn,!l&&dn[r],l&&"resize-none overflow-hidden"),"data-size":o,"data-invalid":z||void 0,"data-success":C||void 0,"data-disabled":v||void 0,"data-autoresize":l||void 0,...L}),_&&jsxRuntime.jsx("button",{type:"button","aria-label":"Clear textarea",onClick:ce,className:"absolute right-2 top-2 flex items-center justify-center text-text-muted transition-colors hover:text-text",children:jsxRuntime.jsx(lucideReact.X,{size:14})}),de&&jsxRuntime.jsxs("div",{id:Ee,className:u("pointer-events-none absolute bottom-1.5 right-2.5 font-mono text-[11px]",Me?"text-danger":"text-text-muted"),children:[B.length,y?`/${y}`:""]}),A.message&&!M&&jsxRuntime.jsx("p",{id:xe,role:"alert",className:"mt-1.5 px-0.5 text-xs text-danger",children:A.message})]})});ke.displayName="TextareaCore";function bn(e,n){let t=e.lastIndexOf(`
5
- `,n-1)+1,o=e.indexOf(`
6
- `,n),s=o===-1?e.length:o;return {start:t,end:s}}i(bn,"lineBounds");function gn(e,n,t){let o=bn(e,n),s=bn(e,Math.max(t-1,n));return {from:o.start,to:s.end}}i(gn,"selectedLineRange");function $e(e,n,t,o){let s=e.slice(Math.max(0,n-o.length),n),r=e.slice(t,t+o.length);if(s===o&&r===o)return {value:e.slice(0,n-o.length)+e.slice(n,t)+e.slice(t+o.length),selectionStart:n-o.length,selectionEnd:t-o.length};let l=e.slice(n,t),a=e.slice(0,n)+o+l+o+e.slice(t);return l.length===0?{value:a,selectionStart:n+o.length,selectionEnd:n+o.length}:{value:a,selectionStart:n,selectionEnd:t+o.length*2}}i($e,"toggleWrap");function xn(e,n,t,o){let{from:s,to:r}=gn(e,n,t),l=e.slice(s,r),a=l.startsWith(o)?e.slice(0,s)+l.slice(o.length)+e.slice(r):e.slice(0,s)+o+l+e.slice(r),d=(l.startsWith(o)?-1:1)*o.length;return {value:a,selectionStart:n+d,selectionEnd:t+d}}i(xn,"toggleLinePrefix");function mt(e,n,t,o){let{from:s,to:r}=gn(e,n,t),l=e.slice(s,r),a=l.split(`
7
- `),d=a.every(x=>x.startsWith(o(0))||/^\d+\.\s/.test(x)),c=a.map((x,f)=>d?x.replace(/^(\d+\.\s|-\s\[ \]\s|-\s)/,""):o(f)+x),m=e.slice(0,s)+c.join(`
8
- `)+e.slice(r),g=c.join(`
9
- `).length-l.length;return {value:m,selectionStart:s,selectionEnd:r+g}}i(mt,"toggleListPrefix");function hn(e,n,t){let o=e.slice(n,t);return o.includes(`
10
- `)?{value:e.slice(0,n)+"```\n"+o+"\n```"+e.slice(t),selectionStart:n+4,selectionEnd:t+4}:$e(e,n,t,"`")}i(hn,"toggleCode");function vn(e,n,t){let s=e.slice(n,t)||"text",r=`[${s}](url)`,l=e.slice(0,n)+r+e.slice(t),a=n+s.length+3;return {value:l,selectionStart:a,selectionEnd:a+3}}i(vn,"insertLink");function Hr(){try{return typeof process<"u"?process.env?.NODE_ENV:void 0}catch{return}}i(Hr,"readProcessEnv");function Or(){try{return typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) })<"u"?undefined?.MODE:void 0}catch{return}}i(Or,"readImportMetaEnv");function We(){let e=Hr()??Or();return e!==void 0&&e!=="production"}i(We,"isDev");var Qr=[{label:"Heading",icon:lucideReact.Heading,action:i((e,n,t)=>xn(e,n,t,"### "),"action")},{label:"Bold",icon:lucideReact.Bold,action:i((e,n,t)=>$e(e,n,t,"**"),"action")},{label:"Italic",icon:lucideReact.Italic,action:i((e,n,t)=>$e(e,n,t,"_"),"action")},{label:"Ordered list",icon:lucideReact.ListOrdered,action:i((e,n,t)=>mt(e,n,t,o=>`${o+1}. `),"action")},{label:"Checklist",icon:lucideReact.ClipboardList,action:i((e,n,t)=>mt(e,n,t,()=>"- [ ] "),"action")},{label:"Code",icon:lucideReact.Code,action:hn},{label:"Link",icon:lucideReact.Link,action:vn}],pt=react.forwardRef(({renderMarkdown:e,tab:n,defaultTab:t="write",onTabChange:o,hint:s="Markdown is supported",value:r,defaultValue:l,onValueChange:a,className:d,...c},m)=>{let g=react.useId(),x=react.useRef(null),[f,p]=react.useState(t),b=n??f,[E,v]=react.useState(()=>r??l??""),I=r??E;function y(h){n===void 0&&p(h),o?.(h);}i(y,"setTab");function D(h){v(h),a?.(h);}i(D,"commit");function R(h){let N=x.current;if(!N)return;let{selectionStart:M,selectionEnd:F}=N,k=h(I,M??I.length,F??I.length);D(k.value),N.focus(),requestAnimationFrame(()=>{N.setSelectionRange(k.selectionStart,k.selectionEnd);});}i(R,"runAction");let S=`${g}-tablist`,T=`${g}-write-panel`,P=`${g}-preview-panel`,L=react.useMemo(()=>e?e(I):null,[e,I]);return react.useEffect(()=>{We()&&!e&&console.warn("[kreativ-ui/MarkdownEditor]: no `renderMarkdown` prop was provided, so the Preview tab is just showing plain text with no markdown formatting applied. Pass a `renderMarkdown={(value) => ReactNode}` function \u2014 e.g. using react-markdown \u2014 to enable a real preview:\n\n import ReactMarkdown from 'react-markdown';\n <Textarea allowMarkdown renderMarkdown={(v) => <ReactMarkdown>{v}</ReactMarkdown>} />");},[e]),jsxRuntime.jsxs("div",{className:u("rounded-(--kui-radii-md) border border-border",d),children:[jsxRuntime.jsxs("div",{role:"tablist","aria-label":"Markdown editor mode",id:S,className:"flex items-center gap-4 border-b border-border px-3",children:[["write","preview"].map(h=>jsxRuntime.jsx("button",{type:"button",role:"tab",id:`${g}-${h}-tab`,"aria-selected":b===h,"aria-controls":h==="write"?T:P,onClick:()=>y(h),className:u("border-b-2 py-2.5 text-sm capitalize transition-colors",b===h?"border-brand text-text":"border-transparent text-text-muted hover:text-text"),children:h},h)),b==="write"&&jsxRuntime.jsx("div",{className:"ml-auto flex items-center gap-1 py-1.5",children:Qr.map(({label:h,icon:N,action:M})=>jsxRuntime.jsx("button",{type:"button","aria-label":h,onClick:()=>R(M),className:"rounded-(--kui-radii-sm) p-1.5 text-text-muted transition-colors hover:bg-surface-raised hover:text-text",children:jsxRuntime.jsx(N,{size:15})},h))})]}),jsxRuntime.jsx("div",{id:T,role:"tabpanel","aria-labelledby":`${g}-write-tab`,hidden:b!=="write",children:jsxRuntime.jsx(ke,{ref:h=>{x.current=h,typeof m=="function"?m(h):m&&(m.current=h);},value:I,onValueChange:D,resize:"vertical",variant:"ghost",className:"rounded-none border-0",...c})}),jsxRuntime.jsx("div",{id:P,role:"tabpanel","aria-labelledby":`${g}-preview-tab`,hidden:b!=="preview",className:"min-h-32 p-3 text-sm text-text",children:e?L:jsxRuntime.jsx("span",{className:"text-text-muted",children:"No renderMarkdown provided \u2014 showing raw text."})}),jsxRuntime.jsx("div",{className:"flex items-center gap-2 border-t border-border px-3 py-2 text-xs text-text-muted",children:s})]})});pt.displayName="MarkdownEditor";var ei=react.forwardRef(({allowMarkdown:e,...n},t)=>e?jsxRuntime.jsx(pt,{ref:t,...n}):jsxRuntime.jsx(ke,{ref:t,...n}));ei.displayName="Textarea";var Cn=classVarianceAuthority.cva("flex shrink-0 items-center justify-center rounded-[calc(var(--kui-radii-md)-2px)] border transition-colors duration-[var(--kui-duration-fast)]",{variants:{size:{sm:"h-4 w-4",md:"h-5 w-5",lg:"h-6 w-6"},state:{none:"",error:"border-danger",success:"border-success"},checked:{true:"bg-brand border-brand text-brand-fg",false:"border-border bg-transparent"},disabled:{true:"cursor-not-allowed",false:"cursor-pointer"}},defaultVariants:{size:"md",state:"none",checked:false,disabled:false},compoundVariants:[{checked:false,state:"error",class:"border-danger"},{checked:false,state:"success",class:"border-success"}]}),ft={sm:10,md:12,lg:14};function In({size:e}){return jsxRuntime.jsx("svg",{width:e,height:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:3,strokeLinecap:"round","aria-hidden":"true",children:jsxRuntime.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})}i(In,"DashIcon");function si(...e){return n=>{e.forEach(t=>{t&&(typeof t=="function"?t(n):t.current=n);});}}i(si,"mergeRefs");var Mn=react.forwardRef(({className:e,checked:n,defaultChecked:t,onCheckedChange:o,indeterminate:s=false,size:r="md",error:l,success:a,disabled:d,label:c,description:m,id:g,onChange:x,required:f,...p},b)=>{let E=react.useId(),v=G(),I=v?.id??g??E,y=react.useRef(null),[D,R]=react.useState(t??false),S=n!==void 0?n:D,T=react.useRef(false);react.useEffect(()=>{process.env?.NODE_ENV!=="production"&&(T.current||c&&v?.hasExternalLabel&&(console.warn("[kreativ-ui/Checkbox] This checkbox has both a `label` prop and a <FormField.Label> ancestor. That renders two <label> elements pointing at the same input, which double-announces in screen readers. Use Checkbox's `label` prop instead of <FormField.Label> when the control is a checkbox."),T.current=true));},[c,v?.hasExternalLabel]),react.useEffect(()=>{y.current&&(y.current.indeterminate=s);},[s]);let P=l??v?.invalid??false,h=P?"error":a??false?"success":"none";function N(k){let O=k.target.checked;n===void 0&&R(O),o?.(O),x?.(k);}i(N,"handleChange");let M=m?`${I}-description`:void 0,F=v?.describedBy??M;return jsxRuntime.jsxs("div",{className:u("flex gap-2.5",d&&"cursor-not-allowed opacity-50",e),children:[jsxRuntime.jsxs("div",{className:"relative mt-0.5 inline-flex",children:[jsxRuntime.jsx("input",{ref:si(y,b),type:"checkbox",id:I,checked:S,disabled:d,required:f??v?.required,onChange:N,"aria-invalid":P||void 0,"aria-describedby":F,className:"peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed","data-invalid":P||void 0,...p}),jsxRuntime.jsx("div",{"aria-hidden":"true",className:u(Cn({size:r,state:h,checked:S||s,disabled:!!d}),"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"),children:s?jsxRuntime.jsx(In,{size:ft[r]}):S?jsxRuntime.jsx(lucideReact.Check,{size:ft[r]}):null})]}),(c||m)&&jsxRuntime.jsxs("div",{className:"flex flex-col gap-0.5",children:[c&&jsxRuntime.jsx("label",{htmlFor:I,className:u("text-sm text-text",!d&&"cursor-pointer"),children:c}),m&&jsxRuntime.jsx("p",{id:M,className:"text-xs text-text-muted",children:m})]})]})});Mn.displayName="Checkbox";var gt=react.createContext(null);function En(){let e=react.useContext(gt);if(!e)throw new Error("<Radio /> must be rendered inside <RadioGroup>.");return e}i(En,"useRadioGroupContext");function mi({value:e,defaultValue:n,onValueChange:t,name:o,disabled:s=false,required:r=false,orientation:l="vertical",size:a="md",error:d,success:c,className:m,children:g}){let x=react.useId(),f=o??x,p=G(),[b,E]=react.useState(n),v=e!==void 0?e:b,I=react.useCallback(T=>{e===void 0&&E(T),t?.(T);},[e,t]),y=d??p?.invalid??false,R=y?"error":c??false?"success":"none",S=r||!!p?.required;return jsxRuntime.jsx(gt.Provider,{value:{name:f,value:v,onValueChange:I,disabled:s,size:a,state:R,groupRequired:S},children:jsxRuntime.jsx("div",{role:"radiogroup","aria-labelledby":p?.hasExternalLabel?`${p.id}-label`:void 0,"aria-describedby":p?.describedBy,"aria-required":S||void 0,"aria-invalid":y||void 0,className:u("flex gap-3",l==="horizontal"?"flex-row flex-wrap":"flex-col",m),children:g})})}i(mi,"RadioGroup");var zn=classVarianceAuthority.cva("flex shrink-0 items-center justify-center rounded-full border transition-colors duration-[var(--kui-duration-fast)]",{variants:{size:{sm:"h-4 w-4",md:"h-5 w-5",lg:"h-6 w-6"},state:{none:"",error:"border-danger",success:"border-success"},checked:{true:"border-brand",false:"border-border bg-transparent"},disabled:{true:"cursor-not-allowed",false:"cursor-pointer"}},defaultVariants:{size:"md",state:"none",checked:false,disabled:false},compoundVariants:[{checked:false,state:"error",class:"border-danger"},{checked:false,state:"success",class:"border-success"}]}),Nn={sm:"h-1.5 w-1.5",md:"h-2 w-2",lg:"h-2.5 w-2.5"};function fi({value:e,disabled:n,label:t,description:o,className:s,...r}){let l=En(),a=`${l.name}-${e}`,d=l.value===e,c=n||l.disabled,m=o?`${a}-description`:void 0;return jsxRuntime.jsxs("div",{className:u("flex gap-2.5",c&&"cursor-not-allowed opacity-50",s),children:[jsxRuntime.jsxs("div",{className:"relative mt-0.5 inline-flex",children:[jsxRuntime.jsx("input",{type:"radio",id:a,name:l.name,value:e,checked:d,disabled:c,onChange:()=>l.onValueChange(e),"aria-describedby":m,className:"peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed","data-invalid":l.state==="error"||void 0,...r}),jsxRuntime.jsx("div",{"aria-hidden":"true",className:u(zn({size:l.size,state:l.state,checked:d,disabled:c}),"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"),children:d&&jsxRuntime.jsx("div",{className:u("rounded-full bg-brand",Nn[l.size])})})]}),(t||o)&&jsxRuntime.jsxs("div",{className:"flex flex-col gap-0.5",children:[t&&jsxRuntime.jsx("label",{htmlFor:a,className:u("text-sm text-text",!c&&"cursor-pointer",l.size==="sm"&&"text-xs"),children:t}),o&&jsxRuntime.jsx("p",{id:m,className:u("text-xs text-text-muted",l.size==="sm"&&"text-[10px]"),children:o})]})]})}i(fi,"Radio");var Fn=classVarianceAuthority.cva("relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-colors duration-[var(--kui-duration-fast)]",{variants:{size:{sm:"h-4 w-7",md:"h-5 w-9",lg:"h-6 w-11"},checked:{true:"bg-brand",false:"bg-surface-raised"},disabled:{true:"cursor-not-allowed",false:"cursor-pointer"}},defaultVariants:{size:"md",checked:false,disabled:false}}),Dn={sm:{thumb:"h-3 w-3",translate:"translate-x-3"},md:{thumb:"h-4 w-4",translate:"translate-x-4"},lg:{thumb:"h-5 w-5",translate:"translate-x-5"}};function hi({checked:e,defaultChecked:n,onCheckedChange:t,size:o="md",disabled:s,label:r,description:l,className:a,id:d,onChange:c,...m}){let g=react.useId(),x=G(),f=x?.id??d??g,[p,b]=react.useState(n??false),E=e!==void 0?e:p;function v(R){let S=R.target.checked;e===void 0&&b(S),t?.(S),c?.(R);}i(v,"handleChange");let I=l?`${f}-description`:void 0,{thumb:y,translate:D}=Dn[o];return jsxRuntime.jsxs("div",{className:u("flex gap-2.5",s&&"cursor-not-allowed opacity-50",a),children:[jsxRuntime.jsxs("div",{className:"relative inline-flex",children:[jsxRuntime.jsx("input",{type:"checkbox",role:"switch",id:f,checked:E,disabled:s,onChange:v,"aria-describedby":x?.describedBy??I,className:"peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",...m}),jsxRuntime.jsx("div",{"aria-hidden":"true",className:u(Fn({size:o,checked:E,disabled:!!s}),"peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"),children:jsxRuntime.jsx("div",{className:u("absolute left-0.5 rounded-full bg-white shadow transition-transform duration-[var(--kui-duration-fast)]",y,E&&D)})})]}),(r||l)&&jsxRuntime.jsxs("div",{className:"flex flex-col gap-0.5",children:[r&&jsxRuntime.jsx("label",{htmlFor:f,className:u("text-sm text-text",!s&&"cursor-pointer"),children:r}),l&&jsxRuntime.jsx("p",{id:I,className:"text-xs text-text-muted",children:l})]})]})}i(hi,"Switch");var vt=react.createContext(null);function ae(e){let n=react.useContext(vt);if(!n)throw new Error(`<${e} /> must be rendered inside <Combobox>.`);return n}i(ae,"useComboboxContext");var Ln=["flex","items-center","font-sans","transition-colors","duration-[var(--kui-duration-fast)]","outline-none","placeholder:text-text-muted","disabled:opacity-50","disabled:pointer-events-none","disabled:cursor-not-allowed"].join(" "),Ke=classVarianceAuthority.cva("group relative inline-flex items-center gap-2 transition-colors",{variants:{variant:{outline:"border border-border bg-transparent text-text hover:border-brand",filled:"border border-transparent bg-surface-raised text-text hover:bg-surface",ghost:"border border-transparent bg-transparent text-text hover:bg-surface-raised"},state:{none:"focus-within:ring-2 focus-within:ring-brand/20",error:"border-danger focus-within:ring-2 focus-within:ring-danger/20",success:"border-success focus-within:ring-2 focus-within:ring-success/20"},rounded:{true:"rounded-full",false:"rounded-[var(--kui-radii-md)]"},fullWidth:{true:"w-full",false:""},hasIcon:{true:"px-2",false:""},disabled:{true:"pointer-events-none cursor-not-allowed opacity-50",false:""}},defaultVariants:{variant:"outline",state:"none",rounded:false,fullWidth:true,hasIcon:false,disabled:false}}),Pn={sm:"h-8 px-2 text-xs",md:"h-10 px-3 text-sm",lg:"h-12 px-4 text-base"};function ki(e,n){let t=n.trim().toLowerCase();return [...e.items.entries()].filter(([,o])=>!o.disabled).filter(([,o])=>!t||String(o.label).toLowerCase().includes(t)).map(([o])=>o)}i(ki,"orderedFilteredValues");var qe=react.forwardRef(({variant:e="outline",size:n="md",placeholder:t,clearable:o=false,allowFreeText:s=false,className:r},l)=>{let a=ae("ComboboxInput"),d=a.isInvalid?"error":a.isSuccess?"success":"none",c=o&&a.inputValue.length>0&&!a.disabled;react.useEffect(()=>{if(console.log(a),a.value===void 0)return;let f=a.items.get(a.value);f&&!a.open&&a.setInputValue(String(f.label));},[a.value,a.open,a.items]);function m(f){a.setInputValue(f.target.value),a.open||a.setOpen(true),a.setActiveValue(void 0),s&&a.onValueChange(f.target.value||void 0);}i(m,"handleChange");function g(f){let p=ki(a,a.inputValue);switch(f.key){case "ArrowDown":{if(f.preventDefault(),!a.open){a.setOpen(true);return}let b=a.activeValue?p.indexOf(a.activeValue):-1;a.setActiveValue(p[(b+1)%p.length]);break}case "ArrowUp":{if(f.preventDefault(),!a.open){a.setOpen(true);return}let b=a.activeValue?p.indexOf(a.activeValue):-1;a.setActiveValue(p[(b-1+p.length)%p.length]);break}case "Enter":f.preventDefault(),a.activeValue!==void 0?a.onValueChange(a.activeValue):s&&a.setOpen(false);break;case "Escape":a.open&&(f.preventDefault(),a.setOpen(false));break;}}i(g,"handleKeyDown");function x(){!s&&a.value===void 0&&a.setInputValue(""),setTimeout(()=>a.setOpen(false),120);}return i(x,"handleBlur"),jsxRuntime.jsxs("div",{className:u(Ke({variant:e,state:d,fullWidth:true,disabled:a.disabled,rounded:a.rounded}),"px-2",r),children:[jsxRuntime.jsx("input",{ref:f=>{a.triggerRef.current=f,typeof l=="function"?l(f):l&&(l.current=f);},id:a.triggerId,role:"combobox","aria-autocomplete":"list","aria-haspopup":"listbox","aria-expanded":a.open,"aria-controls":a.contentId,"aria-activedescendant":a.open&&a.activeValue?a.optionId(a.activeValue):void 0,"aria-invalid":a.isInvalid||void 0,"aria-describedby":a.describedBy,disabled:a.disabled,value:a.inputValue,placeholder:t,onChange:m,onFocus:()=>a.setOpen(true),onKeyDown:g,onBlur:x,"data-state":a.open?"open":"closed",className:u(Ln,"flex-1 border-0 bg-transparent outline-none",Pn[n],"px-0")}),c&&jsxRuntime.jsx("button",{type:"button",tabIndex:-1,"aria-label":"Clear",onMouseDown:f=>f.preventDefault(),onClick:()=>{a.setInputValue(""),a.onValueChange(void 0);},className:"flex items-center justify-center text-text-muted transition-colors hover:text-text",children:jsxRuntime.jsx(lucideReact.X,{size:14})})]})});qe.displayName="ComboboxInput";function wt({value:e,disabled:n=false,children:t,className:o}){let s=ae("ComboboxItem"),r=react.useRef(null),l=s.activeValue===e,a=s.value===e;react.useEffect(()=>s.registerItem(e,{label:t,disabled:n,visible:true}),[e,n,t]),react.useEffect(()=>{l&&r.current?.scrollIntoView({block:"nearest"});},[l]);let d=s.inputValue.trim().toLowerCase(),c=!d||String(t).toLowerCase().includes(d);return react.useEffect(()=>{s.setItemVisibility(e,c);},[c,e]),c?jsxRuntime.jsx("div",{ref:r,id:s.optionId(e),role:"option","aria-selected":a,"aria-disabled":n||void 0,onMouseEnter:()=>!n&&s.setActiveValue(e),onMouseDown:m=>m.preventDefault(),onClick:()=>!n&&s.onValueChange(e),className:u("flex cursor-pointer items-center rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",l&&"bg-brand/15 text-brand",a&&!l&&"bg-surface-raised",n&&"pointer-events-none cursor-not-allowed opacity-50",o),children:t}):null}i(wt,"ComboboxItem");var Bn=8;function Ge(e,n){let t=react.useRef(null),[o,s]=react.useState("bottom");return react.useLayoutEffect(()=>{if(!n)return;let r=e.current,l=t.current;if(!r||!l)return;function a(){let d=r.getBoundingClientRect(),c=l.offsetHeight,m=window.innerHeight-d.bottom-Bn,g=d.top-Bn;s(c>m&&g>m?"top":"bottom");}return i(a,"measure"),a(),window.addEventListener("resize",a),window.addEventListener("scroll",a,true),()=>{window.removeEventListener("resize",a),window.removeEventListener("scroll",a,true);}},[n,e]),{contentRef:t,side:o}}i(Ge,"useFloatingSide");function Ct({className:e,children:n}){let t=ae("ComboboxContent"),{contentRef:o,side:s}=Ge(t.triggerRef,t.open);return t.open?jsxRuntime.jsx("div",{ref:o,id:t.contentId,role:"listbox","aria-labelledby":t.triggerId,"data-side":s,className:u("animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-[var(--kui-radii-md)] border border-border bg-surface p-1 shadow-lg",s==="bottom"?"top-full mt-1":"bottom-full mb-1",e),children:n}):null}i(Ct,"ComboboxContent");function Hn({children:e}){return [...ae("ComboboxEmpty").items.values()].filter(o=>o.visible&&!o.disabled).length>0?null:jsxRuntime.jsx("div",{className:"px-2 py-3 text-center text-sm text-text-muted",children:e??"No results found"})}i(Hn,"ComboboxEmpty");function On({children:e="Loading...",className:n}){return jsxRuntime.jsx("div",{role:"status","aria-live":"polite",className:u("px-2 py-3 text-center text-sm text-text-muted",n),children:e})}i(On,"ComboboxLoading");function fe({value:e,onValueChange:n,inputValue:t,defaultInputValue:o="",onInputChange:s,disabled:r=false,name:l,error:a,success:d,rounded:c,className:m,children:g}){let x=react.useId(),f=G(),p=f?.id??x,b=`${p}-listbox`,E=a||f?.invalid||false,v=!!(d&&!E),[I,y]=react.useState(o),D=t!==void 0?t:I;function R(w){t===void 0&&y(w),s?.(w);}i(R,"setInputValue");let[S,T]=react.useState(false),[P,L]=react.useState(void 0),h=react.useRef(new Map),[N,M]=react.useState(new Map),F=react.useCallback((w,z)=>{let C={...z,visible:true};return h.current.set(w,C),M($=>{let K=new Map($);return K.set(w,C),K}),()=>O(w)},[]);function k(w,z){M($=>{let K=$.get(w);if(!K||K.visible===z)return $;let Z=new Map($);return Z.set(w,{...K,visible:z}),Z});let C=h.current.get(w);C&&h.current.set(w,{...C,visible:z});}i(k,"setItemVisibility");function O(w){M(z=>{if(!z.has(w))return z;let C=new Map(z);return C.delete(w),C}),h.current.delete(w);}i(O,"unregisterItem");let V=react.useRef(null),B=react.useRef(null);react.useEffect(()=>{if(!S)return;function w(z){B.current&&!B.current.contains(z.target)&&T(false);}return i(w,"handlePointerDown"),document.addEventListener("mousedown",w),()=>document.removeEventListener("mousedown",w)},[S]);let Y=react.useCallback(w=>`${b}-option-${w}`,[b]);react.useEffect(()=>{if(!e){R("");return}let w=h.current.get(e);w&&!S&&R(String(w.label));},[e,S]);let A=react.useMemo(()=>({value:e,inputValue:D,setInputValue:R,onValueChange:i(w=>{n?.(w);let z=w?h.current.get(w):void 0;z&&R(String(z.label)),T(false);},"onValueChange"),disabled:r,open:S,setOpen:T,triggerId:p,contentId:b,triggerRef:V,isInvalid:E,isSuccess:v,describedBy:f?.describedBy,activeValue:P,setActiveValue:L,items:N,registerItem:F,rounded:c,optionId:Y,setItemVisibility:k,unregisterItem:O}),[e,D,n,r,S,p,b,f?.invalid,f?.describedBy,P,F,Y,d,c,N,k,O]);return jsxRuntime.jsx(vt.Provider,{value:A,children:jsxRuntime.jsxs("div",{ref:B,className:m??"relative w-full",children:[g,l&&jsxRuntime.jsx("input",{type:"hidden",name:l,value:e??"",disabled:r})]})})}i(fe,"Combobox");fe.Input=qe;fe.Item=wt;fe.Content=Ct;fe.Empty=Hn;fe.Loading=On;var It=react.createContext(null);function be(e){let n=react.useContext(It);if(!n)throw new Error(`<${e} /> must be rendered inside <MultiSelect>.`);return n}i(be,"useMultiSelectContext");var qn=classVarianceAuthority.cva("",{variants:{size:{sm:"min-h-[2.25rem] py-1 px-2 text-xs gap-1",md:"min-h-[2.75rem] py-1.5 px-3 text-sm gap-1.5",lg:"min-h-[3.25rem] py-2 px-4 text-base gap-2"}},defaultVariants:{size:"md"}}),Gn=classVarianceAuthority.cva("inline-flex items-center rounded-full",{variants:{size:{sm:"text-[10px] px-1.5 py-0.5 gap-0.5",md:"text-xs px-2 py-0.5 gap-1",lg:"text-sm px-2.5 py-1 gap-1.5"}},defaultVariants:{size:"md"}});function Ai(e){return [...e.entries()].filter(([,n])=>!n.disabled).map(([n])=>n)}i(Ai,"orderedEnabledValues");var Ue=react.forwardRef(({className:e},n)=>{let t=be("MultiSelectTrigger"),o=t.isInvalid?"error":t.isSuccess?"success":"none",s=t.clearable&&t.value.length>0&&!t.disabled,r=t.maxVisibleChips?t.value.slice(0,t.maxVisibleChips):t.value,l=t.value.length-r.length;function a(c){let m=Ai(t.items);if(!m.length)return;let g=t.activeValue?m.indexOf(t.activeValue):-1;t.setActiveValue(m[(g+c+m.length)%m.length]);}i(a,"move");function d(c){switch(c.key){case "ArrowDown":c.preventDefault(),t.open?a(1):t.setOpen(true);break;case "ArrowUp":c.preventDefault(),t.open?a(-1):t.setOpen(true);break;case "Enter":case " ":c.preventDefault(),t.open?t.activeValue&&t.toggleValue(t.activeValue):t.setOpen(true);break;case "Escape":t.open&&(c.preventDefault(),t.setOpen(false));break;}}return i(d,"handleKeyDown"),jsxRuntime.jsxs("div",{ref:t.triggerRef,className:u(Ke({variant:t.variant,state:o,fullWidth:true,disabled:t.disabled,rounded:t.rounded}),qn({size:t.size}),"flex flex-wrap items-center gap-1",e),children:[jsxRuntime.jsxs("button",{ref:n,type:"button",id:t.triggerId,role:"combobox","aria-haspopup":"listbox","aria-expanded":t.open,"aria-controls":t.contentId,"aria-invalid":t.isInvalid||void 0,"aria-describedby":t.describedBy,"aria-required":t.required||void 0,disabled:t.disabled,onClick:()=>!t.disabled&&t.setOpen(!t.open),onKeyDown:d,className:"flex flex-1 flex-wrap items-center gap-1 bg-transparent text-left outline-none cursor-pointer disabled:cursor-not-allowed",children:[t.value.length===0&&jsxRuntime.jsx("span",{className:"text-text-muted",children:t.placeholder}),r.map(c=>{let m=t.items.get(c);return jsxRuntime.jsxs("span",{className:u(Gn({size:t.size}),"bg-brand/15 text-brand"),children:[m?.label??c,jsxRuntime.jsx("span",{role:"button",tabIndex:-1,"aria-label":`Remove ${m?.label??c}`,onClick:g=>{g.stopPropagation(),t.removeValue(c);},className:"hover:opacity-70",children:jsxRuntime.jsx(lucideReact.X,{size:t.size==="sm"?8:t.size==="md"?10:12})})]},c)}),l>0&&jsxRuntime.jsxs("span",{className:u("text-text-muted",t.size==="sm"?"text-[10px]":t.size==="md"?"text-xs":"text-sm"),children:["+",l," more"]})]}),s&&jsxRuntime.jsx("button",{type:"button",tabIndex:-1,"aria-label":"Clear selection",onClick:c=>{c.preventDefault(),c.stopPropagation(),t.onClear();},className:"flex h-4 w-4 shrink-0 items-center justify-center text-text-muted transition-colors hover:text-text",children:jsxRuntime.jsx(lucideReact.X,{size:14})})]})});Ue.displayName="MultiSelectTrigger";function Tt({className:e,children:n,...t}){let o=be("MultiSelectContent"),{side:s,contentRef:r}=Ge(o.triggerRef,o.open);return o.open?jsxRuntime.jsx("div",{ref:r,id:o.contentId,role:"listbox","aria-labelledby":o.triggerId,"data-state":o.open?"open":"closed","data-side":s,className:u("animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-[var(--kui-radii-md)] border border-border bg-surface p-1 shadow-lg",s==="bottom"?"top-full mt-1":"bottom-full mb-1",e),...t,children:n}):null}i(Tt,"MultiSelectContent");function Ki(){return jsxRuntime.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:3,strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("polyline",{points:"20 6 9 17 4 12"})})}i(Ki,"CheckIcon");function Rt({value:e,disabled:n=false,children:t,className:o}){let s=be("MultiSelectItem"),r=react.useRef(null),l=s.value.includes(e),a=s.activeValue===e;return react.useEffect(()=>s.registerItem(e,{label:t,disabled:n}),[e,n,t]),react.useEffect(()=>{a&&r.current?.scrollIntoView({block:"nearest"});},[a]),jsxRuntime.jsxs("div",{ref:r,id:s.optionId(e),role:"option","aria-selected":l,"aria-disabled":n||void 0,onMouseEnter:()=>!n&&s.setActiveValue(e),onClick:()=>!n&&s.toggleValue(e),className:u("flex cursor-pointer items-center justify-between rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",a&&"bg-brand/15 text-brand",n&&"pointer-events-none cursor-not-allowed opacity-50",o),children:[jsxRuntime.jsx("span",{children:t}),l&&jsxRuntime.jsx(Ki,{})]})}i(Rt,"MultiSelectItem");function _e({value:e,defaultValue:n=[],onValueChange:t,disabled:o=false,required:s,name:r,variant:l="outline",size:a="md",placeholder:d,maxVisibleChips:c,className:m,children:g,error:x,success:f,rounded:p,clearable:b}){let E=react.useId(),v=G(),I=v?.id??E,y=`${I}-listbox`,[D,R]=react.useState(n),S=e!==void 0?e:D,[T,P]=react.useState(false),[L,h]=react.useState(void 0),N=react.useRef(new Map),[,M]=react.useReducer(C=>C+1,0),F=react.useCallback((C,$)=>(N.current.set(C,$),M(),()=>{N.current.delete(C),M();}),[]),k=react.useCallback(C=>{e===void 0&&R(C),t?.(C);},[e,t]),O=react.useCallback(C=>k(S.includes(C)?S.filter($=>$!==C):[...S,C]),[S,k]),V=react.useCallback(C=>k(S.filter($=>$!==C)),[S,k]),B=react.useCallback(()=>{k([]);},[k]),Y=react.useRef(null),A=react.useRef(null);react.useEffect(()=>{if(!T)return;function C($){A.current&&!A.current.contains($.target)&&P(false);}return i(C,"handlePointerDown"),document.addEventListener("mousedown",C),()=>document.removeEventListener("mousedown",C)},[T]);let w=react.useCallback(C=>`${y}-option-${C}`,[y]),z=react.useMemo(()=>({value:S,toggleValue:O,removeValue:V,disabled:o,variant:l,size:a,open:T,setOpen:P,triggerId:I,contentId:y,triggerRef:Y,isInvalid:v?.invalid??x??false,describedBy:v?.describedBy,required:v?.required??s,placeholder:d,maxVisibleChips:c,activeValue:L,setActiveValue:h,items:N.current,registerItem:F,optionId:w,isSuccess:f,rounded:p,clearable:b,onClear:B}),[S,O,V,o,l,a,T,I,y,v?.invalid,v?.describedBy,v?.required,s,d,c,L,F,w,x,f,p,b,B]);return jsxRuntime.jsx(It.Provider,{value:z,children:jsxRuntime.jsxs("div",{ref:A,className:m??"relative w-full",children:[g,r&&S.map(C=>jsxRuntime.jsx("input",{type:"hidden",name:`${r}[]`,value:C,disabled:o},C))]})})}i(_e,"MultiSelect");_e.Trigger=Ue;_e.Content=Tt;_e.Item=Rt;var Un={colors:{blue:{300:{value:"#5EA6ED"},400:{value:"#4799EB"},500:{value:"#1A80E6"},600:{value:"#1773CF"}},red:{300:{value:"#EB4747"},400:{value:"#E83030"},500:{value:"#E61A1A"},600:{value:"#CF1717"}},green:{300:{value:"#26D997"},400:{value:"#22C388"},500:{value:"#16A249"},600:{value:"#12875C"}},amber:{300:{value:"#F7B23B"},400:{value:"#F6A823"},500:{value:"#F59F0A"},600:{value:"#D38909"}},cyan:{300:{value:"#6CC3EF"},400:{value:"#47B4EB"},500:{value:"#1791CF"},600:{value:"#137BAE"}},gray:{50:{value:"#FAFAFA"},100:{value:"#EBEBEB"},200:{value:"#D9D9D9"},300:{value:"#BDBDBD"},400:{value:"#999999"},500:{value:"#666666"},600:{value:"#4D4D4D"},700:{value:"#333333"},800:{value:"#2E2E2E"},900:{value:"#1F1F1F"},950:{value:"#141414"},1e3:{value:"#0A0A0A"}},white:{value:"#FFFFFF"},black:{value:"#000000"}},spacing:{1:{value:"0.25rem"},2:{value:"0.5rem"},3:{value:"0.75rem"},4:{value:"1rem"},5:{value:"1.25rem"},6:{value:"1.5rem"},8:{value:"2rem"},10:{value:"2.5rem"},12:{value:"3rem"},16:{value:"4rem"}},radii:{none:{value:"0"},sm:{value:"0.25rem"},md:{value:"0.5rem"},lg:{value:"0.75rem"},xl:{value:"1rem"},full:{value:"9999px"}},fonts:{body:{value:"Inter, sans-serif"},heading:{value:"Inter, sans-serif"},mono:{value:"ui-monospace, SFMono-Regular, Menlo, monospace"}},fontSizes:{xs:{value:"0.75rem"},sm:{value:"0.875rem"},md:{value:"1rem"},lg:{value:"1.125rem"},xl:{value:"1.25rem"},"2xl":{value:"1.5rem"},"3xl":{value:"1.875rem"},"4xl":{value:"2.25rem"}},fontWeights:{normal:{value:"400"},medium:{value:"500"},semibold:{value:"600"},bold:{value:"700"}},lineHeights:{tight:{value:"1.25"},normal:{value:"1.5"},relaxed:{value:"1.75"}},letterSpacings:{tighter:{value:"-0.025em"},tight:{value:"-0.01em"},normal:{value:"0"},wide:{value:"0.025em"}},animations:{"slide-in-right":{value:"slide-in-right 0.5s ease-in-out"}}};var Xn={colors:{brand:{value:{light:"{colors.blue.500}",dark:"{colors.blue.400}"}},brandHover:{value:{light:"{colors.blue.600}",dark:"{colors.blue.300}"}},brandFg:{value:"{colors.white}"},surface:{value:{light:"{colors.gray.50}",dark:"{colors.gray.900}"}},surfaceRaised:{value:{light:"{colors.white}",dark:"{colors.gray.800}"}},surfaceSunken:{value:{light:"{colors.gray.100}",dark:"{colors.gray.950}"}},border:{value:{light:"{colors.gray.200}",dark:"{colors.gray.600}"}},text:{value:{light:"{colors.gray.900}",dark:"{colors.gray.50}"}},textMuted:{value:{light:"{colors.gray.500}",dark:"{colors.gray.400}"}},destructive:{value:{light:"{colors.red.500}",dark:"{colors.red.400}"}},destructiveFg:{value:"{colors.white}"},destructiveHover:{value:{light:"{colors.red.600}",dark:"{colors.red.300}"}},success:{value:{light:"{colors.green.500}",dark:"{colors.green.400}"}},successFg:{value:"{colors.white}"},successHover:{value:{light:"{colors.green.600}",dark:"{colors.green.300}"}},warning:{value:{light:"{colors.amber.500}",dark:"{colors.amber.400}"}},warningFg:{value:"{colors.black}"},warningHover:{value:{light:"{colors.amber.600}",dark:"{colors.amber.300}"}},info:{value:{light:"{colors.cyan.500}",dark:"{colors.cyan.400}"}},infoFg:{value:"{colors.white}"},infoHover:{value:{light:"{colors.cyan.600}",dark:"{colors.cyan.300}"}}}};var _i={xs:{height:"1.75rem",paddingX:"0.5rem",fontSize:"0.75rem",gap:"0.25rem",iconSize:"0.875rem",radius:"0.65rem"},sm:{height:"2rem",paddingX:"0.75rem",fontSize:"0.8125rem",gap:"0.375rem",iconSize:"1rem",radius:"0.8rem"},md:{height:"2.5rem",paddingX:"1rem",fontSize:"0.875rem",gap:"0.5rem",iconSize:"1.125rem",radius:"1rem"},lg:{height:"3rem",paddingX:"1.5rem",fontSize:"1rem",gap:"0.625rem",iconSize:"1.25rem",radius:"1.15rem"}},Ji={body:{fontFamily:"{fonts.body}",fontSize:"{fontSizes.md}",fontWeight:"{fontWeights.normal}",lineHeight:"{lineHeights.normal}"},bodySmall:{fontFamily:"{fonts.body}",fontSize:"{fontSizes.sm}",fontWeight:"{fontWeights.normal}",lineHeight:"{lineHeights.normal}"},heading:{fontFamily:"{fonts.heading}",fontSize:"{fontSizes.2xl}",fontWeight:"{fontWeights.bold}",lineHeight:"{lineHeights.tight}"},headingSmall:{fontFamily:"{fonts.heading}",fontSize:"{fontSizes.xl}",fontWeight:"{fontWeights.semibold}",lineHeight:"{lineHeights.tight}"},caption:{fontFamily:"{fonts.body}",fontSize:"{fontSizes.xs}",fontWeight:"{fontWeights.normal}",lineHeight:"{lineHeights.normal}"}},Qi={Button:Lt,FormControl:Bt,Input:Pt},_n={tokens:Un,semanticTokens:Xn,textStyles:Ji,recipes:Qi,intensity:50,sizes:_i};function Jn(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}i(Jn,"toKebabCase");function Zi(e){let n=e.trim(),t=n.match(/^rgba?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(?:\s*[/,]\s*[\d.]+%?)?\s*\)$/i);if(t)return `${t[1]} ${t[2]} ${t[3]}`;if(n.startsWith("#")){let o=n.slice(1);if(o.length===3){let s=parseInt(o[0]+o[0],16),r=parseInt(o[1]+o[1],16),l=parseInt(o[2]+o[2],16);return `${s} ${r} ${l}`}if(o.length===6){let s=parseInt(o.slice(0,2),16),r=parseInt(o.slice(2,4),16),l=parseInt(o.slice(4,6),16);return `${s} ${r} ${l}`}}return /^\d+(?:\.\d+)?\s+\d+(?:\.\d+)?\s+\d+(?:\.\d+)?$/.test(n)?n:e}i(Zi,"colorToRgbChannels");function es(e,n){let t=e.replace(/^\{/,"").replace(/\}$/,"").split("."),o=n;for(let s of t){if(typeof o!="object"||o===null||!(s in o))return;o=o[s];}if(typeof o=="object"&&o!==null&&"value"in o){let s=o.value;if(typeof s=="string"||typeof s=="number")return s}}i(es,"getTokenValue");function Qn(e,n,t=new Set){if(t.has(e)){console.error(`[kreativ-ui] Circular token reference detected: ${e}`);return}let o=new Set(t);o.add(e);let s=es(e,n);if(s===void 0){console.warn(`[kreativ-ui] Unable to resolve token reference: ${e}`);return}return typeof s=="number"?String(s):s.startsWith("{")&&s.endsWith("}")?Qn(s,n,o):s}i(Qn,"resolveReference");function Vt(e,n){if(typeof e=="number")return String(e);if(typeof e=="string")return e.startsWith("{")&&e.endsWith("}")?Qn(e,n):e}i(Vt,"resolveValue");function Zn(e,n,t,o){if(!(typeof e!="object"||e===null)){if("value"in e){let s=e.value,r=Vt(s,o);r!==void 0&&(t[n.join(".")]=r);return}for(let[s,r]of Object.entries(e))Zn(r,[...n,s],t,o);}}i(Zn,"flattenTokens");function ts(e,n,t){if(typeof e=="object"&&e!==null&&"light"in e&&"dark"in e){let o=e[n];return Vt(o,t)}return Vt(e,t)}i(ts,"resolveSemanticValue");function ns(e,n,t){let o={};function s(r,l){if(!(typeof r!="object"||r===null)){if("value"in r){let a=r.value,d=ts(a,t,n);d!==void 0&&(o[l.join(".")]=d);return}for(let[a,d]of Object.entries(r))s(d,[...l,a]);}}return i(s,"walk"),s(e,[]),o}i(ns,"resolveSemanticTokens");function eo(e,n,t){let o={};Zn(e,[],o,e);let s=ns(n,e,t);return {...o,...s}}i(eo,"resolveTokens");function zt(e,n,t){let o={};for(let[s,r]of Object.entries(e)){let l=s.split("."),a=l.length===2&&l[0]==="colors",d=l.length>=3&&l[0]==="colors",c=a?`--kui-${Jn(l[1])}`:`--kui-${l.map(Jn).join("-")}`,m=a||d?Zi(r):r;o[c]=m;}return {...o,"--kui-mode":n,"--kui-intensity":String(t)}}i(zt,"tokensToCssVars");var os=/^-?\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|fr)$|^(auto|min-content|max-content|fit-content)$/,rs=new Set(["auto","min-content","max-content","fit-content"]),is=["height","width","paddingX","paddingY","fontSize","gap","iconSize","radius"];function no(e){return rs.has(e)}i(no,"isCssKeyword");function to(e){if(no(e))return;let n=parseFloat(e);if(!Number.isNaN(n)){if(e.endsWith("px"))return n;if(e.endsWith("rem")||e.endsWith("em"))return n*16}}i(to,"toPx");function ss(e,n){if(is.forEach(t=>{let o=n[t];if(o===void 0)return;if(!os.test(o)){console.error(`[kreativ-ui] Invalid size "${e}.${t}": "${o}" is not a valid CSS size.`);return}if(no(o))return;parseFloat(o)<0&&console.error(`[kreativ-ui] Invalid size "${e}.${t}": "${o}" is negative.`);}),n.height&&n.fontSize){let t=to(n.height),o=to(n.fontSize);t!==void 0&&o!==void 0&&o>=t&&console.warn(`[kreativ-ui] Size "${e}" has conflicting dimensions: height=${n.height} (${t}px), fontSize=${n.fontSize} (${o}px).
11
- Font size meets or exceeds the box height \u2014 text may clip or overflow.`);}}i(ss,"validateSizeToken");function Je(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}i(Je,"isPlainObject");function Qe(e,n){if(n===void 0)return e;if(!Je(e)||!Je(n))return n;let t={...e};for(let[o,s]of Object.entries(n)){let r=t[o];Je(r)&&Je(s)?t[o]=Qe(r,s):t[o]=s;}return t}i(Qe,"deepMerge");function as(e,n){return Qe(e,n)}i(as,"mergeDesignTokens");function ls(e,n){return Qe(e,n)}i(ls,"mergeSemanticTokens");function cs(e,n){return Qe(e,n)}i(cs,"mergeTextStyles");function ds(e,n){if(!n)return e;let t={...e};for(let[o,s]of Object.entries(n)){let r={...t[o],...s};ss(o,r),t[o]=r;}return t}i(ds,"mergeSizes");function oo(e,n){return n?{tokens:as(e.tokens,n.tokens),semanticTokens:ls(e.semanticTokens,n.semanticTokens),textStyles:cs(e.textStyles,n.textStyles),recipes:Ft(e.recipes,n.recipes),intensity:n.intensity??e.intensity,sizes:ds(e.sizes,n.sizes)}:e}i(oo,"mergeTheme");function us(){let[e,n]=react.useState(()=>typeof window<"u"&&window.matchMedia("(prefers-color-scheme: dark)").matches);return react.useEffect(()=>{let t=window.matchMedia("(prefers-color-scheme: dark)"),o=i(s=>{n(s.matches);},"handleChange");return t.addEventListener("change",o),()=>{t.removeEventListener("change",o);}},[]),e}i(us,"useSystemPrefersDark");function ms({children:e,theme:n,defaultMode:t="system",as:o="div",fallbackSize:s="md"}){let[r,l]=react.useState(t),a=us(),d=r==="system"?a?"dark":"light":r,c=react.useMemo(()=>oo(_n,n),[n]),m=react.useMemo(()=>eo(c.tokens,c.semanticTokens,d),[c.tokens,c.semanticTokens,d]),g=react.useMemo(()=>zt(m,d,c.intensity),[m,d,c.intensity]);react.useEffect(()=>{We()&&!c.sizes[s]&&console.error(`[kreativ-ui] fallbackSize="${s}" is not a registered size in theme.sizes. Components requesting an unknown size may render without size styles.`);},[c.sizes,s]);let x=react.useMemo(()=>({theme:c,mode:r,resolvedMode:d,setMode:l,fallbackSize:s,tokens:m}),[c,r,d,s,m]),f=o;return jsxRuntime.jsx(ye.Provider,{value:x,children:jsxRuntime.jsx(f,{"data-kreativ-theme":d,className:d==="dark"?"dark":void 0,style:g,children:e})})}i(ms,"UIProvider");exports.Button=Se;exports.Checkbox=Mn;exports.Combobox=fe;exports.ComboboxContent=Ct;exports.ComboboxInput=qe;exports.ComboboxItem=wt;exports.FormField=we;exports.FormFieldControl=ot;exports.FormFieldDescription=nt;exports.FormFieldLabel=tt;exports.FormFieldMessage=Le;exports.Input=Jt;exports.MarkdownEditor=pt;exports.MultiSelect=_e;exports.MultiSelectContent=Tt;exports.MultiSelectContext=It;exports.MultiSelectItem=Rt;exports.MultiSelectTrigger=Ue;exports.Radio=fi;exports.RadioGroup=mi;exports.Select=le;exports.SelectContent=st;exports.SelectContext=rt;exports.SelectGroup=ct;exports.SelectGroupContext=Pe;exports.SelectItem=at;exports.SelectTrigger=He;exports.SelectValue=lt;exports.Switch=hi;exports.Textarea=ei;exports.TextareaCore=ke;exports.ThemeContext=ye;exports.ThemeToggler=Bo;exports.UIProvider=ms;exports.cn=u;exports.defaultRecipes=Qi;exports.defaultSizes=_i;exports.defaultTextStyles=Ji;exports.defaultTheme=_n;exports.hexToRgbString=Xs;exports.inputKindDefaults=jt;exports.rgbToHex=Us;exports.tokensToCssVars=zt;exports.useBreakpoint=ua;exports.useMultiSelectContext=be;exports.useSelectContext=se;exports.useSizeStyle=re;exports.useTheme=X;//# sourceMappingURL=index.cjs.map
1
+ "use client";
2
+ 'use strict';
3
+
4
+ var react = require('react');
5
+ var framerMotion = require('framer-motion');
6
+ var clsx = require('clsx');
7
+ var tailwindMerge = require('tailwind-merge');
8
+ var jsxRuntime = require('react/jsx-runtime');
9
+ var lucideReact = require('lucide-react');
10
+ var classVarianceAuthority = require('class-variance-authority');
11
+
12
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
13
+ console.log("BANNER TEST");
14
+ var __defProp = Object.defineProperty;
15
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
16
+ function cn(...inputs) {
17
+ return tailwindMerge.twMerge(clsx.clsx(inputs));
18
+ }
19
+ __name(cn, "cn");
20
+ var ThemeContext = react.createContext(null);
21
+
22
+ // src/hooks/useTheme.ts
23
+ function useTheme() {
24
+ const ctx = react.useContext(ThemeContext);
25
+ if (!ctx) {
26
+ throw new Error(
27
+ "useTheme() was called outside <UIProvider>. Wrap your app in <UIProvider> from 'kreativ-ui'."
28
+ );
29
+ }
30
+ return ctx;
31
+ }
32
+ __name(useTheme, "useTheme");
33
+ function useSizeStyle(size, iconOnly = false, component = "button", options = {}) {
34
+ const { includeHeight = true } = options;
35
+ const { theme, fallbackSize } = useTheme();
36
+ return react.useMemo(() => {
37
+ const scale = theme.sizes;
38
+ const token = scale[size] ?? scale[fallbackSize] ?? Object.values(scale)[0] ?? {};
39
+ const style = {};
40
+ if (includeHeight && token.height) {
41
+ style.height = token.height;
42
+ }
43
+ if (token.width) {
44
+ style.width = token.width;
45
+ } else if (iconOnly && includeHeight && token.height) {
46
+ style.width = token.height;
47
+ }
48
+ if (!iconOnly && token.paddingX) {
49
+ style.paddingLeft = token.paddingX;
50
+ style.paddingRight = token.paddingX;
51
+ }
52
+ if (token.paddingY) {
53
+ style.paddingTop = token.paddingY;
54
+ style.paddingBottom = token.paddingY;
55
+ }
56
+ if (token.fontSize) {
57
+ style.fontSize = token.fontSize;
58
+ }
59
+ if (token.gap) {
60
+ style.gap = iconOnly ? 0 : token.gap;
61
+ }
62
+ if (token.radius) {
63
+ const varName = `--kui-${component}-radius`;
64
+ style[varName] = token.radius;
65
+ }
66
+ return {
67
+ style,
68
+ iconSize: token.iconSize
69
+ };
70
+ }, [theme.sizes, size, fallbackSize, iconOnly, includeHeight, component]);
71
+ }
72
+ __name(useSizeStyle, "useSizeStyle");
73
+
74
+ // src/theme/recipes/defineRecipe.ts
75
+ function defineRecipe(recipe) {
76
+ return recipe;
77
+ }
78
+ __name(defineRecipe, "defineRecipe");
79
+
80
+ // src/theme/recipes/mergeRecipes.ts
81
+ function mergeRecipeDefinition(base, override) {
82
+ return {
83
+ ...base,
84
+ base: override.base ?? base.base,
85
+ variants: {
86
+ ...base.variants,
87
+ ...override.variants
88
+ },
89
+ defaultVariants: {
90
+ ...base.defaultVariants,
91
+ ...override.defaultVariants
92
+ },
93
+ compoundVariants: override.compoundVariants ?? base.compoundVariants
94
+ };
95
+ }
96
+ __name(mergeRecipeDefinition, "mergeRecipeDefinition");
97
+ function mergeRecipes(base, override) {
98
+ if (!override) {
99
+ return base;
100
+ }
101
+ const result = {
102
+ ...base
103
+ };
104
+ for (const [name, recipeOverride] of Object.entries(override)) {
105
+ const baseRecipe = base[name];
106
+ if (!baseRecipe) {
107
+ result[name] = recipeOverride;
108
+ continue;
109
+ }
110
+ result[name] = mergeRecipeDefinition(
111
+ baseRecipe,
112
+ recipeOverride
113
+ );
114
+ }
115
+ return result;
116
+ }
117
+ __name(mergeRecipes, "mergeRecipes");
118
+
119
+ // src/theme/recipes/resolveRecipe.ts
120
+ function matchesConditions(conditions, props) {
121
+ return Object.entries(conditions).every(
122
+ ([key, expected]) => props[key] === expected
123
+ );
124
+ }
125
+ __name(matchesConditions, "matchesConditions");
126
+ function resolveRecipe(recipe, props = {}) {
127
+ if (!recipe) return "";
128
+ const resolvedProps = {
129
+ ...recipe.defaultVariants,
130
+ ...props
131
+ };
132
+ const classes = [];
133
+ if (recipe.base) {
134
+ classes.push(recipe.base);
135
+ }
136
+ if (recipe.variants) {
137
+ for (const [variantName, variantValues] of Object.entries(
138
+ recipe.variants
139
+ )) {
140
+ const value = resolvedProps[variantName];
141
+ if (value === void 0) continue;
142
+ const variantClass = variantValues[String(value)];
143
+ if (variantClass) {
144
+ classes.push(variantClass);
145
+ }
146
+ }
147
+ }
148
+ if (recipe.compoundVariants) {
149
+ for (const compound of recipe.compoundVariants) {
150
+ if (matchesConditions(compound.conditions, resolvedProps)) {
151
+ classes.push(compound.className);
152
+ }
153
+ }
154
+ }
155
+ return cn(...classes);
156
+ }
157
+ __name(resolveRecipe, "resolveRecipe");
158
+
159
+ // src/theme/defaults/recipes/button.ts
160
+ var buttonBase = "inline-flex items-center justify-center rounded-[var(--kui-button-radius,var(--kui-radius))] font-medium transition-colors duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-brand focus-visible:ring-offset-2 focus-visible:ring-offset-surface disabled:opacity-60 disabled:pointer-events-none";
161
+ var buttonVariants = {
162
+ solid: "",
163
+ outline: "border bg-transparent",
164
+ ghost: "bg-transparent",
165
+ soft: "",
166
+ link: "bg-transparent p-0 h-auto hover:underline"
167
+ };
168
+ var buttonColors = {
169
+ brand: {
170
+ solid: "bg-brand text-brand-fg hover:bg-brand-hover",
171
+ outline: "border-brand text-brand hover:bg-brand/10",
172
+ ghost: "text-brand hover:bg-brand/10",
173
+ soft: "bg-brand/10 text-brand hover:bg-brand/20",
174
+ link: "text-brand"
175
+ },
176
+ destructive: {
177
+ solid: "bg-destructive text-destructive-fg hover:bg-destructive-hover",
178
+ outline: "border-destructive text-destructive hover:bg-destructive/10",
179
+ ghost: "text-destructive hover:bg-destructive/10",
180
+ soft: "bg-destructive/10 text-destructive hover:bg-destructive/20",
181
+ link: "text-destructive"
182
+ },
183
+ success: {
184
+ solid: "bg-success text-success-fg hover:bg-success-hover",
185
+ outline: "border-success text-success hover:bg-success/10",
186
+ ghost: "text-success hover:bg-success/10",
187
+ soft: "bg-success/10 text-success hover:bg-success/20",
188
+ link: "text-success"
189
+ },
190
+ warning: {
191
+ solid: "bg-warning text-warning-fg hover:bg-warning-hover",
192
+ outline: "border-warning text-warning hover:bg-warning/10",
193
+ ghost: "text-warning hover:bg-warning/10",
194
+ soft: "bg-warning/10 text-warning hover:bg-warning/20",
195
+ link: "text-warning"
196
+ },
197
+ info: {
198
+ solid: "bg-info text-info-fg hover:bg-info-hover",
199
+ outline: "border-info text-info hover:bg-info/10",
200
+ ghost: "text-info hover:bg-info/10",
201
+ soft: "bg-info/10 text-info hover:bg-info/20",
202
+ link: "text-info"
203
+ },
204
+ white: {
205
+ solid: "bg-white text-black hover:bg-gray-50",
206
+ outline: "border-white/30 text-white hover:bg-white/10",
207
+ ghost: "text-white hover:bg-white/10",
208
+ soft: "bg-white/10 text-white hover:bg-white/20",
209
+ link: "text-white"
210
+ },
211
+ neutral: {
212
+ solid: "bg-surface-raised text-text hover:bg-surface-sunken",
213
+ outline: "border-border text-text hover:bg-surface-raised",
214
+ ghost: "text-text hover:bg-surface-raised",
215
+ soft: "bg-surface-raised text-text hover:bg-surface-sunken",
216
+ link: "text-text"
217
+ }
218
+ };
219
+ var buildCompoundVariants = /* @__PURE__ */ __name(() => {
220
+ const compounds = [];
221
+ for (const [color, variantMap] of Object.entries(buttonColors)) {
222
+ for (const [variant, className] of Object.entries(variantMap)) {
223
+ compounds.push({
224
+ conditions: { color, variant },
225
+ className
226
+ });
227
+ }
228
+ }
229
+ return compounds;
230
+ }, "buildCompoundVariants");
231
+ var buttonRecipe = defineRecipe({
232
+ base: buttonBase,
233
+ variants: {
234
+ variant: buttonVariants,
235
+ color: Object.fromEntries(
236
+ Object.keys(buttonColors).map((color) => [color, ""])
237
+ )
238
+ },
239
+ defaultVariants: {
240
+ variant: "solid",
241
+ color: "brand"
242
+ },
243
+ compoundVariants: buildCompoundVariants()
244
+ });
245
+
246
+ // src/theme/defaults/recipes/input.ts
247
+ var inputBase = "flex min-w-0 flex-1 font-sans bg-transparent border-0 outline-none transition-colors duration-[var(--kui-duration-fast)] placeholder:text-text-muted disabled:pointer-events-none disabled:cursor-not-allowed";
248
+ var inputRecipe = defineRecipe({
249
+ base: inputBase,
250
+ variants: {
251
+ variant: {
252
+ outline: "",
253
+ filled: "",
254
+ ghost: ""
255
+ }
256
+ },
257
+ defaultVariants: {
258
+ variant: "outline"
259
+ }
260
+ });
261
+
262
+ // src/theme/defaults/recipes/formControl.ts
263
+ var formControlBase = "group relative inline-flex items-center rounded-[var(--kui-radii-md)] transition-colors duration-[var(--kui-duration-fast)] focus-within:outline-none focus-within:ring-2 ";
264
+ var formControlVariants = {
265
+ outline: "border border-border bg-transparent text-text hover:border-brand",
266
+ filled: "border border-transparent bg-surface-raised text-text hover:bg-surface",
267
+ ghost: "border border-transparent bg-transparent text-text hover:bg-surface-raised"
268
+ };
269
+ var formControlStates = {
270
+ none: "focus-within:ring-brand/20",
271
+ error: "border-destructive focus-within:ring-destructive/20",
272
+ success: "border-success focus-within:ring-success/20"
273
+ };
274
+ var formControlRecipe = defineRecipe({
275
+ base: formControlBase,
276
+ variants: {
277
+ variant: formControlVariants,
278
+ state: formControlStates,
279
+ rounded: {
280
+ true: "rounded-full",
281
+ false: ""
282
+ },
283
+ fullWidth: {
284
+ true: "w-full",
285
+ false: ""
286
+ },
287
+ disabled: {
288
+ true: "pointer-events-none cursor-not-allowed opacity-50",
289
+ false: ""
290
+ },
291
+ hasAdornment: {
292
+ true: "px-2",
293
+ false: ""
294
+ }
295
+ },
296
+ defaultVariants: {
297
+ variant: "outline",
298
+ state: "none",
299
+ rounded: false,
300
+ fullWidth: true,
301
+ disabled: false,
302
+ hasAdornment: false
303
+ }
304
+ });
305
+ var ACTIVATION_KEYS = /* @__PURE__ */ new Set(["Enter", " "]);
306
+ var Button = react.forwardRef(
307
+ ({
308
+ variant = "solid",
309
+ color = "brand",
310
+ size = "md",
311
+ isLoading = false,
312
+ leftIcon,
313
+ rightIcon,
314
+ fullWidth = false,
315
+ disabled,
316
+ className,
317
+ style,
318
+ iconOnly,
319
+ children,
320
+ render,
321
+ onKeyDown,
322
+ onKeyUp,
323
+ ...rest
324
+ }, ref) => {
325
+ const { theme } = useTheme();
326
+ const { style: sizeStyle, iconSize } = useSizeStyle(
327
+ size,
328
+ iconOnly,
329
+ "button"
330
+ );
331
+ const prefersReducedMotion = framerMotion.useReducedMotion();
332
+ const isInteractive = !disabled && !isLoading;
333
+ const [isKeyboardPressed, setIsKeyboardPressed] = react.useState(false);
334
+ function handleKeyDown(e) {
335
+ onKeyDown?.(e);
336
+ if (isInteractive && ACTIVATION_KEYS.has(e.key)) {
337
+ setIsKeyboardPressed(true);
338
+ }
339
+ }
340
+ __name(handleKeyDown, "handleKeyDown");
341
+ function handleKeyUp(e) {
342
+ onKeyUp?.(e);
343
+ if (ACTIVATION_KEYS.has(e.key)) {
344
+ setIsKeyboardPressed(false);
345
+ }
346
+ }
347
+ __name(handleKeyUp, "handleKeyUp");
348
+ const recipeClasses = resolveRecipe(theme.recipes.Button, {
349
+ variant,
350
+ color
351
+ });
352
+ const resolvedClassName = cn(
353
+ recipeClasses,
354
+ fullWidth && "w-full",
355
+ isLoading && "animate-kui-pulse",
356
+ className
357
+ );
358
+ const resolvedStyle = {
359
+ ...sizeStyle,
360
+ ...style
361
+ };
362
+ const content = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
363
+ isLoading && /* @__PURE__ */ jsxRuntime.jsx(
364
+ "span",
365
+ {
366
+ className: "animate-kui-spin rounded-full border-2 border-current border-t-transparent",
367
+ style: {
368
+ width: iconSize,
369
+ height: iconSize
370
+ },
371
+ "aria-hidden": "true"
372
+ }
373
+ ),
374
+ !isLoading && leftIcon,
375
+ iconOnly && isLoading ? null : children,
376
+ !isLoading && rightIcon
377
+ ] });
378
+ if (render) {
379
+ return render({
380
+ className: resolvedClassName,
381
+ style: resolvedStyle,
382
+ disabled: disabled || isLoading,
383
+ "aria-busy": isLoading || void 0,
384
+ children: content
385
+ });
386
+ }
387
+ return /* @__PURE__ */ jsxRuntime.jsx(
388
+ framerMotion.motion.button,
389
+ {
390
+ ref,
391
+ disabled: disabled || isLoading,
392
+ className: resolvedClassName,
393
+ style: resolvedStyle,
394
+ "aria-busy": isLoading || void 0,
395
+ animate: {
396
+ scale: isKeyboardPressed ? 0.975 : 1
397
+ },
398
+ whileHover: isInteractive ? { scale: 1.015 } : void 0,
399
+ whileTap: isInteractive ? { scale: 0.975 } : void 0,
400
+ transition: prefersReducedMotion ? { duration: 0 } : {
401
+ type: "spring",
402
+ stiffness: 500,
403
+ damping: 30
404
+ },
405
+ onKeyDown: handleKeyDown,
406
+ onKeyUp: handleKeyUp,
407
+ ...rest,
408
+ children: content
409
+ }
410
+ );
411
+ }
412
+ );
413
+ Button.displayName = "Button";
414
+
415
+ // src/utils/color.ts
416
+ var HEX_RE = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
417
+ function rgbToHex(value) {
418
+ const trimmed = value.trim();
419
+ if (HEX_RE.test(trimmed)) {
420
+ if (trimmed.length === 4) {
421
+ return ("#" + [...trimmed.slice(1)].map((char) => char + char).join("")).toUpperCase();
422
+ }
423
+ return trimmed.toUpperCase();
424
+ }
425
+ const values = trimmed.replace(/[^\d,]/g, "").split(",").map(Number);
426
+ if (values.length !== 3 || values.some(Number.isNaN)) {
427
+ return "#000000";
428
+ }
429
+ return "#" + values.map((x) => x.toString(16).padStart(2, "0")).join("").toUpperCase();
430
+ }
431
+ __name(rgbToHex, "rgbToHex");
432
+ function hexToRgbString(hex) {
433
+ if (!HEX_RE.test(hex)) return null;
434
+ const full = hex.length === 4 ? "#" + [...hex.slice(1)].map((c) => c + c).join("") : hex;
435
+ const r = parseInt(full.slice(1, 3), 16);
436
+ const g = parseInt(full.slice(3, 5), 16);
437
+ const b = parseInt(full.slice(5, 7), 16);
438
+ return `${r} ${g} ${b}`;
439
+ }
440
+ __name(hexToRgbString, "hexToRgbString");
441
+ var defaultTransition = {
442
+ type: "none",
443
+ duration: 300,
444
+ delay: 0,
445
+ easing: "ease-in-out"
446
+ };
447
+ var getIconVariants = /* @__PURE__ */ __name((type) => {
448
+ switch (type) {
449
+ case "fade":
450
+ return {
451
+ initial: { opacity: 0 },
452
+ animate: { opacity: 1 },
453
+ exit: { opacity: 0 }
454
+ };
455
+ case "slide":
456
+ return {
457
+ initial: { opacity: 0, x: -20 },
458
+ animate: { opacity: 1, x: 0 },
459
+ exit: { opacity: 0, x: 20 }
460
+ };
461
+ case "scale":
462
+ return {
463
+ initial: { opacity: 0, scale: 0.5 },
464
+ animate: { opacity: 1, scale: 1 },
465
+ exit: { opacity: 0, scale: 1.5 }
466
+ };
467
+ case "rotate":
468
+ return {
469
+ initial: { opacity: 0, rotate: -90 },
470
+ animate: { opacity: 1, rotate: 0 },
471
+ exit: { opacity: 0, rotate: 90 }
472
+ };
473
+ case "none":
474
+ default:
475
+ return {
476
+ initial: { opacity: 1 },
477
+ animate: { opacity: 1 },
478
+ exit: { opacity: 1 }
479
+ };
480
+ }
481
+ }, "getIconVariants");
482
+ function ThemeToggler({
483
+ variant = "ghost",
484
+ activeVariant = "solid",
485
+ color = "neutral",
486
+ activeColor = "brand",
487
+ size = "sm",
488
+ iconOnly = false,
489
+ allowSystem = false,
490
+ orientation = "horizontal",
491
+ rounded = false,
492
+ unstyled = false,
493
+ labels,
494
+ icons,
495
+ className,
496
+ buttonProps = {},
497
+ display = "buttons",
498
+ transition = defaultTransition
499
+ }) {
500
+ const { mode, setMode, resolvedMode } = useTheme();
501
+ const activeMode = allowSystem ? mode : resolvedMode;
502
+ const modes = [
503
+ {
504
+ key: "light",
505
+ label: labels?.light ?? "Light",
506
+ icon: icons?.light ?? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Sun, { size: 16 })
507
+ },
508
+ {
509
+ key: "dark",
510
+ label: labels?.dark ?? "Dark",
511
+ icon: icons?.dark ?? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Moon, { size: 16 })
512
+ },
513
+ ...allowSystem ? [
514
+ {
515
+ key: "system",
516
+ label: labels?.system ?? "System",
517
+ icon: icons?.system ?? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Monitor, { size: 16 })
518
+ }
519
+ ] : []
520
+ ];
521
+ const allowedModes = modes.map((item) => item.key);
522
+ const currentMode = modes.find(({ key }) => key === activeMode) ?? modes[0];
523
+ const effectiveRounded = rounded && !(orientation === "vertical" && !iconOnly);
524
+ react.useEffect(() => {
525
+ if (rounded && !effectiveRounded) {
526
+ console.warn(
527
+ "[kreativ-ui/ThemeToggler] `rounded` is ignored when orientation='vertical' and iconOnly={false}."
528
+ );
529
+ }
530
+ }, [rounded, effectiveRounded]);
531
+ const handleCycle = /* @__PURE__ */ __name(() => {
532
+ const index = allowedModes.indexOf(
533
+ activeMode
534
+ );
535
+ setMode(allowedModes[(index + 1) % allowedModes.length]);
536
+ }, "handleCycle");
537
+ const isActive = /* @__PURE__ */ __name((key) => key === "system" ? mode === "system" : activeMode === key, "isActive");
538
+ const containerClasses = cn(
539
+ "inline-flex gap-1",
540
+ orientation === "vertical" && "flex-col",
541
+ !unstyled && [
542
+ "border border-border bg-surface p-1",
543
+ effectiveRounded ? "rounded-full" : "rounded-lg"
544
+ ],
545
+ className
546
+ );
547
+ const buttonRadius = effectiveRounded ? "rounded-full" : "rounded-lg";
548
+ const animateIcon = display === "cycle" && transition.type !== "none";
549
+ const iconVariants = getIconVariants(transition.type || "none");
550
+ const motionTransition = {
551
+ duration: (transition.duration || 300) / 1e3,
552
+ delay: (transition.delay || 0) / 1e3,
553
+ ease: transition.easing || "ease-in-out"
554
+ };
555
+ if (display === "cycle") {
556
+ return /* @__PURE__ */ jsxRuntime.jsxs(
557
+ Button,
558
+ {
559
+ size,
560
+ variant,
561
+ color,
562
+ onClick: handleCycle,
563
+ "aria-label": `Current theme: ${currentMode.label}`,
564
+ className: cn(
565
+ effectiveRounded && "rounded-full",
566
+ buttonProps.className
567
+ ),
568
+ ...buttonProps,
569
+ children: [
570
+ /* @__PURE__ */ jsxRuntime.jsx(framerMotion.AnimatePresence, { mode: "wait", children: /* @__PURE__ */ jsxRuntime.jsx(
571
+ framerMotion.motion.span,
572
+ {
573
+ initial: animateIcon ? iconVariants.initial : void 0,
574
+ animate: animateIcon ? iconVariants.animate : void 0,
575
+ exit: animateIcon ? iconVariants.exit : void 0,
576
+ transition: motionTransition,
577
+ children: currentMode.icon
578
+ },
579
+ currentMode.key
580
+ ) }),
581
+ !iconOnly && currentMode.label
582
+ ]
583
+ }
584
+ );
585
+ }
586
+ const buttons = modes.map(({ key, label, icon }) => {
587
+ const active = isActive(key);
588
+ return /* @__PURE__ */ jsxRuntime.jsx(
589
+ Button,
590
+ {
591
+ size,
592
+ variant: active ? activeVariant : variant,
593
+ color: active ? activeColor : color,
594
+ onClick: () => setMode(key),
595
+ className: cn(buttonRadius, buttonProps.className),
596
+ leftIcon: icon,
597
+ "aria-pressed": active,
598
+ ...buttonProps,
599
+ children: !iconOnly && label
600
+ },
601
+ key
602
+ );
603
+ });
604
+ if (unstyled) {
605
+ return /* @__PURE__ */ jsxRuntime.jsx(
606
+ "div",
607
+ {
608
+ role: "group",
609
+ "aria-label": "Theme selector",
610
+ className: cn(
611
+ "inline-flex gap-1",
612
+ orientation === "vertical" && "flex-col",
613
+ className
614
+ ),
615
+ children: buttons
616
+ }
617
+ );
618
+ }
619
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { role: "group", "aria-label": "Theme selector", className: containerClasses, children: buttons });
620
+ }
621
+ __name(ThemeToggler, "ThemeToggler");
622
+ var BREAKPOINTS = {
623
+ sm: 640,
624
+ md: 768,
625
+ lg: 1024,
626
+ xl: 1280,
627
+ "2xl": 1536
628
+ };
629
+ function useBreakpoint(breakpoint) {
630
+ const query = `(min-width: ${BREAKPOINTS[breakpoint]}px)`;
631
+ const [matches, setMatches] = react.useState(
632
+ () => typeof window !== "undefined" && window.matchMedia(query).matches
633
+ );
634
+ react.useEffect(() => {
635
+ const mql = window.matchMedia(query);
636
+ const listener = /* @__PURE__ */ __name((e) => setMatches(e.matches), "listener");
637
+ mql.addEventListener("change", listener);
638
+ setMatches(mql.matches);
639
+ return () => mql.removeEventListener("change", listener);
640
+ }, [query]);
641
+ return matches;
642
+ }
643
+ __name(useBreakpoint, "useBreakpoint");
644
+ var inputKindIcons = {
645
+ email: lucideReact.Mail,
646
+ tel: lucideReact.Phone,
647
+ url: lucideReact.Link2,
648
+ search: lucideReact.Search,
649
+ numeric: lucideReact.Hash,
650
+ "password-current": lucideReact.Lock,
651
+ "password-new": lucideReact.Lock
652
+ };
653
+ function Spinner({ size = 14 }) {
654
+ return /* @__PURE__ */ jsxRuntime.jsx(
655
+ "span",
656
+ {
657
+ className: "animate-kui-spin rounded-full border-2 border-inherit border-t-transparent shrink-0",
658
+ style: { width: size, height: size },
659
+ "aria-hidden": "true"
660
+ }
661
+ );
662
+ }
663
+ __name(Spinner, "Spinner");
664
+
665
+ // src/components/Input/Input.constants.ts
666
+ var inputKindDefaults = {
667
+ text: { placeholder: "Type something..." },
668
+ email: {
669
+ type: "email",
670
+ inputMode: "email",
671
+ autoComplete: "email",
672
+ placeholder: "you@company.com"
673
+ },
674
+ tel: {
675
+ type: "tel",
676
+ inputMode: "tel",
677
+ autoComplete: "tel",
678
+ placeholder: "+234 800 000 0000"
679
+ },
680
+ url: {
681
+ type: "url",
682
+ inputMode: "url",
683
+ autoComplete: "url",
684
+ placeholder: "https://company.com"
685
+ },
686
+ search: {
687
+ type: "search",
688
+ inputMode: "search",
689
+ autoComplete: "off",
690
+ placeholder: "Search..."
691
+ },
692
+ numeric: {
693
+ type: "text",
694
+ inputMode: "numeric",
695
+ autoComplete: "off",
696
+ placeholder: "Enter a number"
697
+ },
698
+ "password-current": {
699
+ type: "password",
700
+ autoComplete: "current-password",
701
+ placeholder: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022"
702
+ },
703
+ "password-new": {
704
+ type: "password",
705
+ autoComplete: "new-password",
706
+ placeholder: "Create a password"
707
+ },
708
+ number: {
709
+ type: "number",
710
+ inputMode: "decimal",
711
+ autoComplete: "off",
712
+ placeholder: "0.00"
713
+ },
714
+ date: {
715
+ type: "date",
716
+ inputMode: "none",
717
+ placeholder: "YYYY-MM-DD"
718
+ },
719
+ time: {
720
+ type: "time",
721
+ inputMode: "none",
722
+ placeholder: "HH:MM"
723
+ },
724
+ "datetime-local": {
725
+ type: "datetime-local",
726
+ inputMode: "none",
727
+ placeholder: "YYYY-MM-DDTHH:MM"
728
+ },
729
+ month: {
730
+ type: "month",
731
+ inputMode: "none",
732
+ placeholder: "YYYY-MM"
733
+ },
734
+ week: {
735
+ type: "week",
736
+ inputMode: "none",
737
+ placeholder: "YYYY-Www"
738
+ }
739
+ };
740
+ var TRANSITION_DURATION = 1500;
741
+ function useStateTransition(state) {
742
+ const previousState = react.useRef(state);
743
+ const [transitionState, setTransitionState] = react.useState();
744
+ react.useEffect(() => {
745
+ if (state === previousState.current) {
746
+ return;
747
+ }
748
+ previousState.current = state;
749
+ if (state === "none") {
750
+ setTransitionState(void 0);
751
+ return;
752
+ }
753
+ setTransitionState(state);
754
+ const timeout = window.setTimeout(() => {
755
+ setTransitionState(void 0);
756
+ }, TRANSITION_DURATION);
757
+ return () => window.clearTimeout(timeout);
758
+ }, [state]);
759
+ return transitionState;
760
+ }
761
+ __name(useStateTransition, "useStateTransition");
762
+ var FormFieldContext = react.createContext(
763
+ null
764
+ );
765
+ function useFormField() {
766
+ const context = react.useContext(FormFieldContext);
767
+ if (!context) {
768
+ throw new Error("FormField components must be used inside <FormField />");
769
+ }
770
+ return context;
771
+ }
772
+ __name(useFormField, "useFormField");
773
+ function useOptionalFormField() {
774
+ return react.useContext(FormFieldContext);
775
+ }
776
+ __name(useOptionalFormField, "useOptionalFormField");
777
+ function mergeRefs(...refs) {
778
+ return (node) => {
779
+ refs.forEach((ref) => {
780
+ if (!ref) return;
781
+ if (typeof ref === "function") {
782
+ ref(node);
783
+ } else {
784
+ ref.current = node;
785
+ }
786
+ });
787
+ };
788
+ }
789
+ __name(mergeRefs, "mergeRefs");
790
+ var Input = react.forwardRef(
791
+ ({
792
+ className,
793
+ inputClassName,
794
+ variant = "outline",
795
+ size = "md",
796
+ error,
797
+ success,
798
+ startIcon,
799
+ endIcon,
800
+ fullWidth = true,
801
+ disabled,
802
+ rounded = false,
803
+ isLoading = false,
804
+ clearable = false,
805
+ onClear,
806
+ kind = "text",
807
+ hideKindIcon = false,
808
+ id: externalId,
809
+ type: typeProp,
810
+ inputMode: inputModeProp,
811
+ autoComplete: autoCompleteProp,
812
+ placeholder: placeholderProp,
813
+ onChange: onChangeProp,
814
+ readOnly: readOnlyProp,
815
+ value,
816
+ defaultValue,
817
+ style,
818
+ ...props
819
+ }, ref) => {
820
+ const autoId = react.useId();
821
+ const { theme } = useTheme();
822
+ const field = useOptionalFormField();
823
+ const id = externalId ?? field?.id ?? autoId;
824
+ const isInvalid = error || field?.invalid || false;
825
+ const describedBy = field?.describedBy ?? void 0;
826
+ const isRequired = field?.required ?? props.required;
827
+ const internalRef = react.useRef(null);
828
+ const { style: sizeStyle, iconSize } = useSizeStyle(size, false, "input");
829
+ const [hasValue, setHasValue] = react.useState(
830
+ () => Boolean(value ?? defaultValue ?? "")
831
+ );
832
+ const [visible, setVisible] = react.useState(false);
833
+ react.useEffect(() => {
834
+ if (value !== void 0) {
835
+ setHasValue(Boolean(value));
836
+ }
837
+ }, [value]);
838
+ const kindDefaults = inputKindDefaults[kind];
839
+ const resolvedType = typeProp ?? kindDefaults.type;
840
+ const isPasswordField = resolvedType === "password";
841
+ const effectiveType = isPasswordField ? visible ? "text" : "password" : resolvedType;
842
+ const KindIcon = inputKindIcons[kind];
843
+ const defaultStartIcon = !hideKindIcon && KindIcon ? /* @__PURE__ */ jsxRuntime.jsx(KindIcon, { size: Number(iconSize) || 15 }) : void 0;
844
+ const startSlot = startIcon || defaultStartIcon ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex shrink-0 items-center justify-center", children: startIcon ?? defaultStartIcon }) : null;
845
+ const builtInEnd = [];
846
+ if (isPasswordField) {
847
+ builtInEnd.push(
848
+ /* @__PURE__ */ jsxRuntime.jsx(
849
+ "button",
850
+ {
851
+ type: "button",
852
+ tabIndex: -1,
853
+ onClick: () => setVisible((current) => !current),
854
+ "aria-label": visible ? "Hide password" : "Show password",
855
+ className: "flex items-center justify-center text-text-muted transition-colors hover:text-text",
856
+ children: visible ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.EyeOff, { size: 16 }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Eye, { size: 16 })
857
+ },
858
+ "toggle-visibility"
859
+ )
860
+ );
861
+ }
862
+ if (clearable && hasValue && !disabled) {
863
+ builtInEnd.push(
864
+ /* @__PURE__ */ jsxRuntime.jsx(
865
+ "button",
866
+ {
867
+ type: "button",
868
+ tabIndex: -1,
869
+ onClick: handleClear,
870
+ "aria-label": "Clear input",
871
+ className: "flex items-center justify-center text-text-muted transition-colors hover:text-text",
872
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 14 })
873
+ },
874
+ "clear"
875
+ )
876
+ );
877
+ }
878
+ const endSlot = isLoading ? /* @__PURE__ */ jsxRuntime.jsx(Spinner, { size: Number(iconSize) || 14 }) : endIcon ? endIcon : builtInEnd.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex shrink-0 items-center gap-1.5", children: builtInEnd }) : null;
879
+ const hasIcon = Boolean(startSlot || endSlot);
880
+ const state = error ? "error" : success ? "success" : "none";
881
+ const stateTransition = useStateTransition(state);
882
+ const wrapperClasses = cn(
883
+ resolveRecipe(theme.recipes.FormControl, {
884
+ variant,
885
+ state,
886
+ rounded,
887
+ fullWidth,
888
+ disabled: Boolean(disabled || isLoading),
889
+ hasIcon
890
+ }),
891
+ className
892
+ );
893
+ const inputClasses = cn(
894
+ resolveRecipe(theme.recipes.Input, {
895
+ variant
896
+ }),
897
+ inputClassName
898
+ );
899
+ const resolvedStyle = {
900
+ ...sizeStyle,
901
+ ...style
902
+ };
903
+ function handleChange(event) {
904
+ setHasValue(Boolean(event.target.value));
905
+ onChangeProp?.(event);
906
+ }
907
+ __name(handleChange, "handleChange");
908
+ function handleClear() {
909
+ const element = internalRef.current;
910
+ if (!element) return;
911
+ const setter = Object.getOwnPropertyDescriptor(
912
+ window.HTMLInputElement.prototype,
913
+ "value"
914
+ )?.set;
915
+ setter?.call(element, "");
916
+ element.dispatchEvent(
917
+ new Event("input", {
918
+ bubbles: true
919
+ })
920
+ );
921
+ element.focus();
922
+ setHasValue(false);
923
+ onClear?.();
924
+ }
925
+ __name(handleClear, "handleClear");
926
+ react.useEffect(() => {
927
+ if (!error) return;
928
+ const element = internalRef.current;
929
+ if (!element) return;
930
+ element.scrollIntoView({
931
+ behavior: "smooth",
932
+ block: "center"
933
+ });
934
+ }, [error]);
935
+ return /* @__PURE__ */ jsxRuntime.jsxs(
936
+ "div",
937
+ {
938
+ className: wrapperClasses,
939
+ style: resolvedStyle,
940
+ "data-state": state,
941
+ "data-state-transition": stateTransition,
942
+ children: [
943
+ startSlot,
944
+ /* @__PURE__ */ jsxRuntime.jsx(
945
+ "input",
946
+ {
947
+ ...props,
948
+ ref: mergeRefs(internalRef, ref),
949
+ id,
950
+ type: effectiveType,
951
+ inputMode: inputModeProp ?? kindDefaults.inputMode,
952
+ autoComplete: autoCompleteProp ?? kindDefaults.autoComplete,
953
+ placeholder: placeholderProp ?? kindDefaults.placeholder,
954
+ value,
955
+ defaultValue,
956
+ onChange: handleChange,
957
+ readOnly: isLoading || readOnlyProp,
958
+ disabled: isLoading || disabled,
959
+ "aria-busy": isLoading || void 0,
960
+ "aria-invalid": isInvalid || void 0,
961
+ "aria-describedby": describedBy,
962
+ "aria-required": isRequired || void 0,
963
+ className: inputClasses,
964
+ "data-variant": variant,
965
+ "data-size": size,
966
+ "data-success": success || void 0,
967
+ "data-disabled": disabled || void 0,
968
+ "data-loading": isLoading || void 0
969
+ }
970
+ ),
971
+ endSlot
972
+ ]
973
+ },
974
+ stateTransition ?? "idle"
975
+ );
976
+ }
977
+ );
978
+ Input.displayName = "Input";
979
+ function FormField({
980
+ id: externalId,
981
+ error,
982
+ required = false,
983
+ className,
984
+ children
985
+ }) {
986
+ const generatedId = react.useId();
987
+ const id = externalId ?? generatedId;
988
+ const labelId = `${id}-label`;
989
+ const descriptionId = `${id}-description`;
990
+ const messageId = `${id}-message`;
991
+ const [reportedMessage, setReportedMessage] = react.useState(
992
+ void 0
993
+ );
994
+ const [labelCount, setLabelCount] = react.useState(0);
995
+ const reportValidity = react.useCallback(
996
+ (result) => {
997
+ if (error !== void 0) return;
998
+ setReportedMessage(result?.invalid ? result.message : void 0);
999
+ },
1000
+ [error]
1001
+ );
1002
+ const registerLabel = react.useCallback(() => {
1003
+ setLabelCount((n) => n + 1);
1004
+ return () => setLabelCount((n) => n - 1);
1005
+ }, []);
1006
+ const hasExternalLabel = labelCount > 0;
1007
+ const displayedMessage = error ?? reportedMessage;
1008
+ const state = displayedMessage ? "error" : "none";
1009
+ return /* @__PURE__ */ jsxRuntime.jsx(
1010
+ FormFieldContext.Provider,
1011
+ {
1012
+ value: {
1013
+ id,
1014
+ labelId,
1015
+ descriptionId,
1016
+ messageId,
1017
+ state,
1018
+ describedBy: [descriptionId, displayedMessage ? messageId : void 0].filter(Boolean).join(" ") || void 0,
1019
+ invalid: Boolean(displayedMessage),
1020
+ required,
1021
+ reportValidity,
1022
+ registerLabel,
1023
+ hasExternalLabel
1024
+ },
1025
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex flex-col gap-2", className), children: [
1026
+ children,
1027
+ displayedMessage && /* @__PURE__ */ jsxRuntime.jsx(FormFieldMessage, { children: displayedMessage })
1028
+ ] })
1029
+ }
1030
+ );
1031
+ }
1032
+ __name(FormField, "FormField");
1033
+ FormField.Label = FormFieldLabel;
1034
+ FormField.Control = FormFieldControl;
1035
+ FormField.Description = FormFieldDescription;
1036
+ FormField.Message = FormFieldMessage;
1037
+ function FormFieldLabel({
1038
+ children,
1039
+ className
1040
+ }) {
1041
+ const field = useFormField();
1042
+ react.useEffect(() => {
1043
+ return field.registerLabel();
1044
+ }, [field]);
1045
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1046
+ "label",
1047
+ {
1048
+ id: field.labelId,
1049
+ htmlFor: field.id,
1050
+ className: cn("text-sm font-medium text-text", className),
1051
+ children: [
1052
+ children,
1053
+ field.required && /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": true, className: "ml-1 text-destructive", children: "*" })
1054
+ ]
1055
+ }
1056
+ );
1057
+ }
1058
+ __name(FormFieldLabel, "FormFieldLabel");
1059
+ function FormFieldDescription({
1060
+ children
1061
+ }) {
1062
+ const {
1063
+ descriptionId
1064
+ } = useFormField();
1065
+ return /* @__PURE__ */ jsxRuntime.jsx(
1066
+ "p",
1067
+ {
1068
+ id: descriptionId,
1069
+ className: "text-sm text-text-muted",
1070
+ children
1071
+ }
1072
+ );
1073
+ }
1074
+ __name(FormFieldDescription, "FormFieldDescription");
1075
+ function FormFieldMessage({ children }) {
1076
+ const { messageId } = useFormField();
1077
+ return /* @__PURE__ */ jsxRuntime.jsx(
1078
+ "p",
1079
+ {
1080
+ id: messageId,
1081
+ role: "alert",
1082
+ className: "\r\n animate-kui-shake [animation-delay:500ms]\r\n text-sm text-destructive\r\n ",
1083
+ children
1084
+ }
1085
+ );
1086
+ }
1087
+ __name(FormFieldMessage, "FormFieldMessage");
1088
+ function FormFieldControl({
1089
+ children
1090
+ }) {
1091
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
1092
+ }
1093
+ __name(FormFieldControl, "FormFieldControl");
1094
+ var SelectContext = react.createContext(null);
1095
+ function useSelectContext(componentName) {
1096
+ const ctx = react.useContext(SelectContext);
1097
+ if (!ctx) {
1098
+ throw new Error(`<${componentName} /> must be rendered inside <Select>.`);
1099
+ }
1100
+ return ctx;
1101
+ }
1102
+ __name(useSelectContext, "useSelectContext");
1103
+ var SelectGroupContext = react.createContext(null);
1104
+ function orderedEnabledValues(items) {
1105
+ return [...items.entries()].filter(([, meta]) => !meta.disabled).map(([value]) => value);
1106
+ }
1107
+ __name(orderedEnabledValues, "orderedEnabledValues");
1108
+ var SelectTrigger = react.forwardRef(
1109
+ ({ className, children, onKeyDown, ...props }, ref) => {
1110
+ const ctx = useSelectContext("SelectTrigger");
1111
+ const { theme } = useTheme();
1112
+ const { style: sizeStyle, iconSize } = useSizeStyle(
1113
+ ctx.size,
1114
+ false,
1115
+ "select"
1116
+ );
1117
+ const state = ctx.isInvalid ? "error" : ctx.isSuccess ? "success" : "none";
1118
+ const wrapperClasses = cn(
1119
+ resolveRecipe(theme.recipes.FormControl, {
1120
+ variant: ctx.variant,
1121
+ state,
1122
+ rounded: Boolean(ctx.rounded),
1123
+ fullWidth: true,
1124
+ disabled: ctx.disabled,
1125
+ hasAdornment: true
1126
+ }),
1127
+ className
1128
+ );
1129
+ const showClear = ctx.clearable && ctx.value !== void 0 && !ctx.disabled;
1130
+ const move = react.useCallback(
1131
+ (delta) => {
1132
+ const values = orderedEnabledValues(ctx.items);
1133
+ if (!values.length) return;
1134
+ const currentIndex = ctx.activeValue ? values.indexOf(ctx.activeValue) : -1;
1135
+ const nextIndex = currentIndex === -1 ? delta === 1 ? 0 : values.length - 1 : (currentIndex + delta + values.length) % values.length;
1136
+ ctx.setActiveValue(values[nextIndex]);
1137
+ },
1138
+ [ctx]
1139
+ );
1140
+ const handleKeyDown = react.useCallback(
1141
+ (e) => {
1142
+ onKeyDown?.(e);
1143
+ if (e.defaultPrevented) return;
1144
+ switch (e.key) {
1145
+ case "ArrowDown":
1146
+ e.preventDefault();
1147
+ if (!ctx.open) ctx.setOpen(true);
1148
+ else move(1);
1149
+ break;
1150
+ case "ArrowUp":
1151
+ e.preventDefault();
1152
+ if (!ctx.open) ctx.setOpen(true);
1153
+ else move(-1);
1154
+ break;
1155
+ case "Home": {
1156
+ if (!ctx.open) break;
1157
+ e.preventDefault();
1158
+ const values = orderedEnabledValues(ctx.items);
1159
+ if (values.length) ctx.setActiveValue(values[0]);
1160
+ break;
1161
+ }
1162
+ case "End": {
1163
+ if (!ctx.open) break;
1164
+ e.preventDefault();
1165
+ const values = orderedEnabledValues(ctx.items);
1166
+ if (values.length) ctx.setActiveValue(values[values.length - 1]);
1167
+ break;
1168
+ }
1169
+ case "Enter":
1170
+ case " ":
1171
+ e.preventDefault();
1172
+ if (!ctx.open) ctx.setOpen(true);
1173
+ else if (ctx.activeValue !== void 0)
1174
+ ctx.onValueChange(ctx.activeValue);
1175
+ break;
1176
+ case "Escape":
1177
+ if (ctx.open) {
1178
+ e.preventDefault();
1179
+ ctx.setOpen(false);
1180
+ }
1181
+ break;
1182
+ case "Backspace":
1183
+ case "Delete":
1184
+ if (ctx.clearable && ctx.value !== void 0 && !ctx.open) {
1185
+ e.preventDefault();
1186
+ ctx.onClear();
1187
+ }
1188
+ break;
1189
+ }
1190
+ },
1191
+ [ctx, move, onKeyDown]
1192
+ );
1193
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: ctx.triggerRef, className: wrapperClasses, style: sizeStyle, children: [
1194
+ /* @__PURE__ */ jsxRuntime.jsxs(
1195
+ "button",
1196
+ {
1197
+ ref,
1198
+ type: "button",
1199
+ id: ctx.triggerId,
1200
+ role: "combobox",
1201
+ "aria-haspopup": "listbox",
1202
+ "aria-expanded": ctx.open,
1203
+ "aria-labelledby": ctx.labelId,
1204
+ "aria-controls": ctx.contentId,
1205
+ "aria-activedescendant": ctx.open && ctx.activeValue ? ctx.optionId(ctx.activeValue) : void 0,
1206
+ tabIndex: ctx.tabIndex,
1207
+ "aria-invalid": ctx.isInvalid || void 0,
1208
+ "aria-describedby": ctx.describedBy,
1209
+ "aria-required": ctx.required || void 0,
1210
+ disabled: ctx.disabled,
1211
+ "data-state": ctx.open ? "open" : "closed",
1212
+ onClick: () => !ctx.disabled && ctx.setOpen(!ctx.open),
1213
+ onKeyDown: handleKeyDown,
1214
+ className: "relative min-w-0 flex-1 bg-transparent cursor-pointer text-left outline-none disabled:cursor-not-allowed h-full",
1215
+ ...props,
1216
+ children: [
1217
+ children,
1218
+ /* @__PURE__ */ jsxRuntime.jsx(
1219
+ "span",
1220
+ {
1221
+ "aria-hidden": true,
1222
+ className: "pointer-events-none absolute right-0 top-1/2 flex -translate-y-1/2 items-center gap-1.5 text-text-muted",
1223
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1224
+ lucideReact.ChevronDown,
1225
+ {
1226
+ size: 14,
1227
+ className: cn(
1228
+ "transition-transform duration-200",
1229
+ ctx.open && "rotate-180"
1230
+ )
1231
+ }
1232
+ )
1233
+ }
1234
+ )
1235
+ ]
1236
+ }
1237
+ ),
1238
+ showClear && /* @__PURE__ */ jsxRuntime.jsx(
1239
+ "button",
1240
+ {
1241
+ type: "button",
1242
+ tabIndex: -1,
1243
+ "aria-label": "Clear selection",
1244
+ onClick: (e) => {
1245
+ e.preventDefault();
1246
+ e.stopPropagation();
1247
+ ctx.onClear();
1248
+ },
1249
+ onMouseDown: (e) => {
1250
+ e.preventDefault();
1251
+ e.stopPropagation();
1252
+ },
1253
+ className: "flex h-4 w-4 items-center justify-center text-text-muted transition-colors hover:text-text",
1254
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: Number(iconSize) || 14 })
1255
+ }
1256
+ )
1257
+ ] });
1258
+ }
1259
+ );
1260
+ SelectTrigger.displayName = "SelectTrigger";
1261
+ var VIEWPORT_PADDING = 8;
1262
+ function SelectContent({
1263
+ className,
1264
+ children,
1265
+ ...props
1266
+ }) {
1267
+ const ctx = useSelectContext("SelectContent");
1268
+ const contentRef = react.useRef(null);
1269
+ const [side, setSide] = react.useState("bottom");
1270
+ react.useLayoutEffect(() => {
1271
+ if (!ctx.open) return;
1272
+ const trigger = ctx.triggerRef.current;
1273
+ const content = contentRef.current;
1274
+ if (!trigger || !content) return;
1275
+ function measure() {
1276
+ const triggerRect = trigger.getBoundingClientRect();
1277
+ const contentHeight = content?.offsetHeight;
1278
+ const spaceBelow = window.innerHeight - triggerRect.bottom - VIEWPORT_PADDING;
1279
+ const spaceAbove = triggerRect.top - VIEWPORT_PADDING;
1280
+ setSide(
1281
+ contentHeight && contentHeight > spaceBelow && spaceAbove > spaceBelow ? "top" : "bottom"
1282
+ );
1283
+ }
1284
+ __name(measure, "measure");
1285
+ measure();
1286
+ window.addEventListener("resize", measure);
1287
+ window.addEventListener("scroll", measure, true);
1288
+ return () => {
1289
+ window.removeEventListener("resize", measure);
1290
+ window.removeEventListener("scroll", measure, true);
1291
+ };
1292
+ }, [ctx.open, ctx.triggerRef]);
1293
+ if (!ctx.open) return null;
1294
+ return /* @__PURE__ */ jsxRuntime.jsx(
1295
+ "div",
1296
+ {
1297
+ ref: contentRef,
1298
+ id: ctx.contentId,
1299
+ role: "listbox",
1300
+ "aria-labelledby": ctx.triggerId,
1301
+ "data-state": ctx.open ? "open" : "closed",
1302
+ "data-side": side,
1303
+ className: cn(
1304
+ "animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-(--kui-radii-md) border border-border bg-surface p-1 shadow-lg",
1305
+ side === "bottom" ? "top-full mt-1" : "bottom-full mb-1",
1306
+ className
1307
+ ),
1308
+ ...props,
1309
+ children
1310
+ }
1311
+ );
1312
+ }
1313
+ __name(SelectContent, "SelectContent");
1314
+ function SelectItem({
1315
+ value,
1316
+ disabled = false,
1317
+ children,
1318
+ className,
1319
+ ...props
1320
+ }) {
1321
+ const ctx = useSelectContext("SelectItem");
1322
+ const selected = ctx.value === value;
1323
+ const active = ctx.activeValue === value;
1324
+ const ref = react.useRef(null);
1325
+ react.useLayoutEffect(() => {
1326
+ return ctx.registerItem(value, { label: children, disabled });
1327
+ }, [value, disabled, children]);
1328
+ react.useEffect(() => {
1329
+ if (active) ref.current?.scrollIntoView({ block: "nearest" });
1330
+ }, [active]);
1331
+ return /* @__PURE__ */ jsxRuntime.jsx(
1332
+ "div",
1333
+ {
1334
+ ref,
1335
+ id: ctx.optionId(value),
1336
+ role: "option",
1337
+ "aria-selected": selected,
1338
+ "aria-disabled": disabled || void 0,
1339
+ "data-state": selected ? "selected" : void 0,
1340
+ "data-active": active || void 0,
1341
+ "data-disabled": disabled || void 0,
1342
+ onMouseEnter: () => !disabled && ctx.setActiveValue(value),
1343
+ onClick: () => !disabled && ctx.onValueChange(value),
1344
+ className: cn(
1345
+ "flex cursor-pointer items-center rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",
1346
+ active && "bg-brand/15 text-brand",
1347
+ selected && !active && "bg-surface-raised",
1348
+ disabled && "pointer-events-none cursor-not-allowed opacity-50",
1349
+ className
1350
+ ),
1351
+ ...props,
1352
+ children
1353
+ }
1354
+ );
1355
+ }
1356
+ __name(SelectItem, "SelectItem");
1357
+ function SelectValue({ placeholder, className }) {
1358
+ const ctx = useSelectContext("SelectValue");
1359
+ const displayLabel = ctx.selectedLabel ?? placeholder ?? ctx.placeholder;
1360
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("min-w-0 truncate", className), children: displayLabel });
1361
+ }
1362
+ __name(SelectValue, "SelectValue");
1363
+ function SelectGroup({ children, className }) {
1364
+ const fallbackId = react.useId();
1365
+ const [labelId, setLabelId] = react.useState(void 0);
1366
+ return /* @__PURE__ */ jsxRuntime.jsx(SelectGroupContext.Provider, { value: { labelId: labelId ?? fallbackId, setHasLabel: setLabelId }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { role: "group", "aria-labelledby": labelId, className: cn("py-1", className), children }) });
1367
+ }
1368
+ __name(SelectGroup, "SelectGroup");
1369
+ function SelectLabel({ children, className }) {
1370
+ const id = react.useId();
1371
+ const group = react.useContext(SelectGroupContext);
1372
+ react.useEffect(() => {
1373
+ group?.setHasLabel(id);
1374
+ }, [group, id]);
1375
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { id, className: cn("px-2.5 py-1.5 font-mono text-[11px] text-text-muted", className), children });
1376
+ }
1377
+ __name(SelectLabel, "SelectLabel");
1378
+ function Select({
1379
+ value: valueProp,
1380
+ defaultValue,
1381
+ onValueChange,
1382
+ disabled = false,
1383
+ required,
1384
+ name,
1385
+ variant = "outline",
1386
+ size = "md",
1387
+ className,
1388
+ placeholder,
1389
+ "aria-describedby": ariaDescribedBy,
1390
+ clearable = false,
1391
+ error,
1392
+ success,
1393
+ tabIndex,
1394
+ rounded,
1395
+ children
1396
+ }) {
1397
+ const autoId = react.useId();
1398
+ const field = useOptionalFormField();
1399
+ const triggerId = field?.id ?? autoId;
1400
+ const triggerRef = react.useRef(null);
1401
+ const contentId = `${triggerId}-listbox`;
1402
+ const labelId = field?.labelId;
1403
+ const [internalValue, setInternalValue] = react.useState(defaultValue);
1404
+ const value = valueProp !== void 0 ? valueProp : internalValue;
1405
+ const isInvalid = error || field?.invalid || false;
1406
+ const isSuccess = success && !isInvalid ? true : false;
1407
+ const describedBy = field?.describedBy ?? ariaDescribedBy;
1408
+ const isRequired = field?.required ?? required;
1409
+ const [open, setOpen] = react.useState(false);
1410
+ const [activeValue, setActiveValue] = react.useState(value);
1411
+ const [selectedLabel, setSelectedLabel] = react.useState();
1412
+ const itemsRef = react.useRef(/* @__PURE__ */ new Map());
1413
+ const [items, setItems] = react.useState(/* @__PURE__ */ new Map());
1414
+ const registerItem = react.useCallback(
1415
+ (val, meta) => {
1416
+ itemsRef.current.set(val, meta);
1417
+ setItems(new Map(itemsRef.current));
1418
+ return () => {
1419
+ itemsRef.current.delete(val);
1420
+ setItems(new Map(itemsRef.current));
1421
+ };
1422
+ },
1423
+ []
1424
+ );
1425
+ const handleValueChange = react.useCallback(
1426
+ (val) => {
1427
+ const label = itemsRef.current.get(val)?.label ?? val;
1428
+ setSelectedLabel(label);
1429
+ if (valueProp === void 0) {
1430
+ setInternalValue(val);
1431
+ }
1432
+ onValueChange?.(val);
1433
+ setOpen(false);
1434
+ },
1435
+ [valueProp, onValueChange]
1436
+ );
1437
+ const handleClear = react.useCallback(() => {
1438
+ setActiveValue(void 0);
1439
+ setInternalValue(void 0);
1440
+ onValueChange?.(void 0);
1441
+ setSelectedLabel(void 0);
1442
+ }, [valueProp, onValueChange]);
1443
+ const optionId = react.useCallback(
1444
+ (val) => `${contentId}-option-${val}`,
1445
+ [contentId]
1446
+ );
1447
+ react.useEffect(() => {
1448
+ if (open) setActiveValue(value);
1449
+ }, [open, value]);
1450
+ react.useEffect(() => {
1451
+ if (value !== void 0) {
1452
+ const label = itemsRef.current.get(value)?.label;
1453
+ if (label !== void 0) setSelectedLabel(label);
1454
+ }
1455
+ }, [value, items]);
1456
+ const rootRef = react.useRef(null);
1457
+ react.useEffect(() => {
1458
+ if (!open) return;
1459
+ function handlePointerDown(e) {
1460
+ if (rootRef.current && !rootRef.current.contains(e.target)) {
1461
+ setOpen(false);
1462
+ }
1463
+ }
1464
+ __name(handlePointerDown, "handlePointerDown");
1465
+ document.addEventListener("mousedown", handlePointerDown);
1466
+ return () => document.removeEventListener("mousedown", handlePointerDown);
1467
+ }, [open]);
1468
+ const ctxValue = react.useMemo(
1469
+ () => ({
1470
+ value,
1471
+ selectedLabel,
1472
+ onValueChange: handleValueChange,
1473
+ disabled,
1474
+ variant,
1475
+ size,
1476
+ open,
1477
+ setOpen,
1478
+ triggerId,
1479
+ contentId,
1480
+ labelId,
1481
+ isInvalid,
1482
+ isSuccess,
1483
+ describedBy,
1484
+ required: isRequired,
1485
+ activeValue,
1486
+ setActiveValue,
1487
+ items,
1488
+ registerItem,
1489
+ optionId,
1490
+ placeholder,
1491
+ clearable,
1492
+ onClear: handleClear,
1493
+ triggerRef,
1494
+ rounded,
1495
+ tabIndex
1496
+ }),
1497
+ [
1498
+ value,
1499
+ items,
1500
+ selectedLabel,
1501
+ handleValueChange,
1502
+ disabled,
1503
+ variant,
1504
+ size,
1505
+ open,
1506
+ triggerId,
1507
+ contentId,
1508
+ isInvalid,
1509
+ isSuccess,
1510
+ describedBy,
1511
+ isRequired,
1512
+ activeValue,
1513
+ registerItem,
1514
+ optionId,
1515
+ placeholder,
1516
+ clearable,
1517
+ handleClear,
1518
+ triggerRef,
1519
+ rounded,
1520
+ labelId,
1521
+ tabIndex
1522
+ ]
1523
+ );
1524
+ return /* @__PURE__ */ jsxRuntime.jsx(SelectContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsxRuntime.jsxs(
1525
+ "div",
1526
+ {
1527
+ ref: rootRef,
1528
+ className: cn("relative inline-block w-full", className),
1529
+ children: [
1530
+ children,
1531
+ name && /* @__PURE__ */ jsxRuntime.jsx(
1532
+ "input",
1533
+ {
1534
+ type: "hidden",
1535
+ name,
1536
+ value: value ?? "",
1537
+ disabled,
1538
+ required: isRequired
1539
+ }
1540
+ )
1541
+ ]
1542
+ }
1543
+ ) });
1544
+ }
1545
+ __name(Select, "Select");
1546
+ Select.Trigger = SelectTrigger;
1547
+ Select.Content = SelectContent;
1548
+ Select.Item = SelectItem;
1549
+ Select.Value = SelectValue;
1550
+ Select.Group = SelectGroup;
1551
+ Select.Label = SelectLabel;
1552
+
1553
+ // src/components/Textarea/Textarea.styles.ts
1554
+ var textareaBase = cn(
1555
+ "flex w-full min-w-0 bg-transparent font-sans outline-none border-0",
1556
+ "text-text placeholder:text-text-muted",
1557
+ "transition-colors duration-[var(--kui-duration-fast)]",
1558
+ "disabled:opacity-50 disabled:pointer-events-none disabled:cursor-not-allowed"
1559
+ );
1560
+ var textareaResizeVariants = {
1561
+ none: "resize-none",
1562
+ both: "resize",
1563
+ horizontal: "resize-x",
1564
+ vertical: "resize-y"
1565
+ };
1566
+ function mergeRefs2(...refs) {
1567
+ return (node) => {
1568
+ refs.forEach((r) => {
1569
+ if (!r) return;
1570
+ if (typeof r === "function") r(node);
1571
+ else r.current = node;
1572
+ });
1573
+ };
1574
+ }
1575
+ __name(mergeRefs2, "mergeRefs");
1576
+ var TextareaCore = react.forwardRef(
1577
+ ({
1578
+ className,
1579
+ value: valueProp,
1580
+ defaultValue,
1581
+ size = "md",
1582
+ fullWidth = true,
1583
+ resize = "vertical",
1584
+ autoResize = false,
1585
+ minRows,
1586
+ maxRows,
1587
+ clearable = false,
1588
+ onClear,
1589
+ characterCounter = false,
1590
+ debounceDelay = 0,
1591
+ trimOnBlur = false,
1592
+ error,
1593
+ success,
1594
+ onValidate,
1595
+ disabled,
1596
+ id: externalId,
1597
+ maxLength,
1598
+ variant = "outline",
1599
+ onValueChange: onValueChangeProp,
1600
+ onChange: onChangeProp,
1601
+ onBlur: onBlurProp,
1602
+ rows,
1603
+ ...props
1604
+ }, ref) => {
1605
+ const autoId = react.useId();
1606
+ const field = useOptionalFormField();
1607
+ const id = field?.id ?? externalId ?? autoId;
1608
+ const { theme } = useTheme();
1609
+ const internalRef = react.useRef(null);
1610
+ const debounceTimer = react.useRef(null);
1611
+ const [draft, setDraft] = react.useState(() => valueProp ?? defaultValue ?? "");
1612
+ react.useEffect(() => {
1613
+ if (valueProp !== void 0) setDraft(valueProp);
1614
+ }, [valueProp]);
1615
+ const [internalValidation, setInternalValidation] = react.useState({});
1616
+ const isInvalid = error ?? field?.invalid ?? internalValidation.invalid ?? false;
1617
+ const isSuccess = success ?? (onValidate ? internalValidation.invalid === false : false);
1618
+ const state = isInvalid ? "error" : isSuccess ? "success" : "none";
1619
+ react.useEffect(
1620
+ () => () => {
1621
+ if (debounceTimer.current) clearTimeout(debounceTimer.current);
1622
+ },
1623
+ []
1624
+ );
1625
+ function commitValue(next, { immediate = false } = {}) {
1626
+ setDraft(next);
1627
+ if (debounceTimer.current) clearTimeout(debounceTimer.current);
1628
+ if (debounceDelay > 0 && !immediate) {
1629
+ debounceTimer.current = setTimeout(() => {
1630
+ onValueChangeProp?.(next);
1631
+ }, debounceDelay);
1632
+ } else {
1633
+ onValueChangeProp?.(next);
1634
+ }
1635
+ }
1636
+ __name(commitValue, "commitValue");
1637
+ function handleChange(e) {
1638
+ commitValue(e.target.value);
1639
+ onChangeProp?.(e);
1640
+ }
1641
+ __name(handleChange, "handleChange");
1642
+ function runValidation(next) {
1643
+ if (!onValidate || error !== void 0 || success !== void 0) return;
1644
+ const result = onValidate(next);
1645
+ const parsed = result === true ? { invalid: false, message: void 0 } : result === false ? { invalid: true, message: void 0 } : { invalid: true, message: result };
1646
+ setInternalValidation(parsed);
1647
+ field?.reportValidity(parsed.invalid ? parsed : null);
1648
+ }
1649
+ __name(runValidation, "runValidation");
1650
+ function handleBlur(e) {
1651
+ let finalValue = draft;
1652
+ if (trimOnBlur) {
1653
+ const trimmed = draft.trim();
1654
+ if (trimmed !== draft) {
1655
+ commitValue(trimmed, { immediate: true });
1656
+ finalValue = trimmed;
1657
+ }
1658
+ }
1659
+ runValidation(finalValue);
1660
+ onBlurProp?.(e);
1661
+ }
1662
+ __name(handleBlur, "handleBlur");
1663
+ function handleClear() {
1664
+ commitValue("", { immediate: true });
1665
+ internalRef.current?.focus();
1666
+ setInternalValidation({});
1667
+ field?.reportValidity(null);
1668
+ onClear?.();
1669
+ }
1670
+ __name(handleClear, "handleClear");
1671
+ react.useLayoutEffect(() => {
1672
+ if (!autoResize) return;
1673
+ const el = internalRef.current;
1674
+ if (!el) return;
1675
+ const computed = window.getComputedStyle(el);
1676
+ const lineHeight = parseFloat(computed.lineHeight) || parseFloat(computed.fontSize) * 1.2;
1677
+ const paddingY = parseFloat(computed.paddingTop) + parseFloat(computed.paddingBottom);
1678
+ const borderY = parseFloat(computed.borderTopWidth) + parseFloat(computed.borderBottomWidth);
1679
+ const minHeight = minRows ? lineHeight * minRows + paddingY + borderY : void 0;
1680
+ const maxHeight = maxRows ? lineHeight * maxRows + paddingY + borderY : void 0;
1681
+ el.style.height = "auto";
1682
+ let next = el.scrollHeight;
1683
+ if (minHeight) next = Math.max(next, minHeight);
1684
+ if (maxHeight) next = Math.min(next, maxHeight);
1685
+ el.style.height = `${next}px`;
1686
+ el.style.overflowY = maxHeight && el.scrollHeight > maxHeight ? "auto" : "hidden";
1687
+ }, [autoResize, draft, minRows, maxRows]);
1688
+ const hasValue = draft.length > 0;
1689
+ const showClear = clearable && hasValue && !disabled;
1690
+ const showCounter = characterCounter;
1691
+ const nearLimit = maxLength ? draft.length >= maxLength * 0.9 : false;
1692
+ const needsBottomSpace = showClear || showCounter;
1693
+ const messageId = !field?.describedBy && (isInvalid || isSuccess) ? `${id}-message` : void 0;
1694
+ const counterId = showCounter ? `${id}-counter` : void 0;
1695
+ const describedBy = cn(field?.describedBy, messageId, counterId).trim() || void 0;
1696
+ const wrapperClassName = cn(
1697
+ resolveRecipe(theme.recipes.FormControl, {
1698
+ variant,
1699
+ state,
1700
+ fullWidth,
1701
+ disabled: !!disabled
1702
+ }),
1703
+ "items-start",
1704
+ className
1705
+ );
1706
+ const { style: sizeStyle } = useSizeStyle(size, false, "textarea", {
1707
+ includeHeight: false
1708
+ });
1709
+ const textareaStyle = { ...sizeStyle };
1710
+ if (needsBottomSpace) {
1711
+ const existingBottom = sizeStyle.paddingBottom;
1712
+ textareaStyle.paddingBottom = existingBottom ? `calc(${existingBottom} + 1.25rem)` : "1.5rem";
1713
+ }
1714
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: wrapperClassName, children: [
1715
+ /* @__PURE__ */ jsxRuntime.jsx(
1716
+ "textarea",
1717
+ {
1718
+ ref: mergeRefs2(internalRef, ref),
1719
+ id,
1720
+ value: draft,
1721
+ onChange: handleChange,
1722
+ onBlur: handleBlur,
1723
+ disabled,
1724
+ maxLength,
1725
+ rows: autoResize ? void 0 : rows ?? minRows,
1726
+ "aria-invalid": isInvalid || void 0,
1727
+ "aria-describedby": describedBy,
1728
+ style: textareaStyle,
1729
+ className: cn(
1730
+ textareaBase,
1731
+ !autoResize && textareaResizeVariants[resize],
1732
+ autoResize && "resize-none overflow-hidden"
1733
+ ),
1734
+ "data-size": size,
1735
+ "data-invalid": isInvalid || void 0,
1736
+ "data-success": isSuccess || void 0,
1737
+ "data-disabled": disabled || void 0,
1738
+ "data-autoresize": autoResize || void 0,
1739
+ ...props
1740
+ }
1741
+ ),
1742
+ showClear && /* @__PURE__ */ jsxRuntime.jsx(
1743
+ "button",
1744
+ {
1745
+ type: "button",
1746
+ "aria-label": "Clear textarea",
1747
+ onClick: handleClear,
1748
+ className: "absolute right-2 top-2 flex items-center justify-center text-text-muted transition-colors hover:text-text",
1749
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 14 })
1750
+ }
1751
+ ),
1752
+ showCounter && /* @__PURE__ */ jsxRuntime.jsxs(
1753
+ "div",
1754
+ {
1755
+ id: counterId,
1756
+ className: cn(
1757
+ "pointer-events-none absolute bottom-1.5 right-2.5 font-mono text-[11px]",
1758
+ nearLimit ? "text-danger" : "text-text-muted"
1759
+ ),
1760
+ children: [
1761
+ draft.length,
1762
+ maxLength ? `/${maxLength}` : ""
1763
+ ]
1764
+ }
1765
+ ),
1766
+ internalValidation.message && !field && /* @__PURE__ */ jsxRuntime.jsx(
1767
+ "p",
1768
+ {
1769
+ id: messageId,
1770
+ role: "alert",
1771
+ className: "mt-1.5 px-0.5 text-xs text-danger",
1772
+ children: internalValidation.message
1773
+ }
1774
+ )
1775
+ ] });
1776
+ }
1777
+ );
1778
+ TextareaCore.displayName = "TextareaCore";
1779
+
1780
+ // src/components/MarkdownEditor/markdownActions.ts
1781
+ function lineBounds(value, index) {
1782
+ const start = value.lastIndexOf("\n", index - 1) + 1;
1783
+ const nextBreak = value.indexOf("\n", index);
1784
+ const end = nextBreak === -1 ? value.length : nextBreak;
1785
+ return { start, end };
1786
+ }
1787
+ __name(lineBounds, "lineBounds");
1788
+ function selectedLineRange(value, start, end) {
1789
+ const first = lineBounds(value, start);
1790
+ const last = lineBounds(value, Math.max(end - 1, start));
1791
+ return { from: first.start, to: last.end };
1792
+ }
1793
+ __name(selectedLineRange, "selectedLineRange");
1794
+ function toggleWrap(value, start, end, marker) {
1795
+ const before = value.slice(Math.max(0, start - marker.length), start);
1796
+ const after = value.slice(end, end + marker.length);
1797
+ if (before === marker && after === marker) {
1798
+ const next2 = value.slice(0, start - marker.length) + value.slice(start, end) + value.slice(end + marker.length);
1799
+ return {
1800
+ value: next2,
1801
+ selectionStart: start - marker.length,
1802
+ selectionEnd: end - marker.length
1803
+ };
1804
+ }
1805
+ const selected = value.slice(start, end);
1806
+ const next = value.slice(0, start) + marker + selected + marker + value.slice(end);
1807
+ return selected.length === 0 ? {
1808
+ value: next,
1809
+ selectionStart: start + marker.length,
1810
+ selectionEnd: start + marker.length
1811
+ } : {
1812
+ value: next,
1813
+ selectionStart: start,
1814
+ selectionEnd: end + marker.length * 2
1815
+ };
1816
+ }
1817
+ __name(toggleWrap, "toggleWrap");
1818
+ function toggleLinePrefix(value, start, end, prefix) {
1819
+ const { from, to } = selectedLineRange(value, start, end);
1820
+ const line = value.slice(from, to);
1821
+ const next = line.startsWith(prefix) ? value.slice(0, from) + line.slice(prefix.length) + value.slice(to) : value.slice(0, from) + prefix + line + value.slice(to);
1822
+ const delta = (line.startsWith(prefix) ? -1 : 1) * prefix.length;
1823
+ return {
1824
+ value: next,
1825
+ selectionStart: start + delta,
1826
+ selectionEnd: end + delta
1827
+ };
1828
+ }
1829
+ __name(toggleLinePrefix, "toggleLinePrefix");
1830
+ function toggleListPrefix(value, start, end, makePrefix) {
1831
+ const { from, to } = selectedLineRange(value, start, end);
1832
+ const block = value.slice(from, to);
1833
+ const lines = block.split("\n");
1834
+ const alreadyListed = lines.every(
1835
+ (l) => l.startsWith(makePrefix(0)) || /^\d+\.\s/.test(l)
1836
+ );
1837
+ const nextLines = lines.map(
1838
+ (l, i) => alreadyListed ? l.replace(/^(\d+\.\s|-\s\[ \]\s|-\s)/, "") : makePrefix(i) + l
1839
+ );
1840
+ const next = value.slice(0, from) + nextLines.join("\n") + value.slice(to);
1841
+ const delta = nextLines.join("\n").length - block.length;
1842
+ return { value: next, selectionStart: from, selectionEnd: to + delta };
1843
+ }
1844
+ __name(toggleListPrefix, "toggleListPrefix");
1845
+ function toggleCode(value, start, end) {
1846
+ const selected = value.slice(start, end);
1847
+ if (selected.includes("\n")) {
1848
+ const next = value.slice(0, start) + "```\n" + selected + "\n```" + value.slice(end);
1849
+ return { value: next, selectionStart: start + 4, selectionEnd: end + 4 };
1850
+ }
1851
+ return toggleWrap(value, start, end, "`");
1852
+ }
1853
+ __name(toggleCode, "toggleCode");
1854
+ function insertLink(value, start, end) {
1855
+ const selected = value.slice(start, end);
1856
+ const label = selected || "text";
1857
+ const snippet = `[${label}](url)`;
1858
+ const next = value.slice(0, start) + snippet + value.slice(end);
1859
+ const urlStart = start + label.length + 3;
1860
+ return { value: next, selectionStart: urlStart, selectionEnd: urlStart + 3 };
1861
+ }
1862
+ __name(insertLink, "insertLink");
1863
+
1864
+ // src/utils/env.ts
1865
+ function readProcessEnv() {
1866
+ try {
1867
+ return typeof process !== "undefined" ? process.env?.NODE_ENV : void 0;
1868
+ } catch {
1869
+ return void 0;
1870
+ }
1871
+ }
1872
+ __name(readProcessEnv, "readProcessEnv");
1873
+ function readImportMetaEnv() {
1874
+ try {
1875
+ return typeof ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) }) !== "undefined" ? undefined?.MODE : void 0;
1876
+ } catch {
1877
+ return void 0;
1878
+ }
1879
+ }
1880
+ __name(readImportMetaEnv, "readImportMetaEnv");
1881
+ function isDev() {
1882
+ const mode = readProcessEnv() ?? readImportMetaEnv();
1883
+ return mode !== void 0 && mode !== "production";
1884
+ }
1885
+ __name(isDev, "isDev");
1886
+ var TOOLBAR = [
1887
+ {
1888
+ label: "Heading",
1889
+ icon: lucideReact.Heading,
1890
+ action: /* @__PURE__ */ __name((v, s, e) => toggleLinePrefix(v, s, e, "### "), "action")
1891
+ },
1892
+ {
1893
+ label: "Bold",
1894
+ icon: lucideReact.Bold,
1895
+ action: /* @__PURE__ */ __name((v, s, e) => toggleWrap(v, s, e, "**"), "action")
1896
+ },
1897
+ {
1898
+ label: "Italic",
1899
+ icon: lucideReact.Italic,
1900
+ action: /* @__PURE__ */ __name((v, s, e) => toggleWrap(v, s, e, "_"), "action")
1901
+ },
1902
+ {
1903
+ label: "Ordered list",
1904
+ icon: lucideReact.ListOrdered,
1905
+ action: /* @__PURE__ */ __name((v, s, e) => toggleListPrefix(v, s, e, (i) => `${i + 1}. `), "action")
1906
+ },
1907
+ {
1908
+ label: "Checklist",
1909
+ icon: lucideReact.ClipboardList,
1910
+ action: /* @__PURE__ */ __name((v, s, e) => toggleListPrefix(v, s, e, () => "- [ ] "), "action")
1911
+ },
1912
+ { label: "Code", icon: lucideReact.Code, action: toggleCode },
1913
+ { label: "Link", icon: lucideReact.Link, action: insertLink }
1914
+ ];
1915
+ var MarkdownEditor = react.forwardRef(
1916
+ ({
1917
+ renderMarkdown,
1918
+ tab: tabProp,
1919
+ defaultTab = "write",
1920
+ onTabChange,
1921
+ hint = "Markdown is supported",
1922
+ value: valueProp,
1923
+ defaultValue,
1924
+ onValueChange,
1925
+ className,
1926
+ ...textareaProps
1927
+ }, ref) => {
1928
+ const baseId = react.useId();
1929
+ const textareaRef = react.useRef(null);
1930
+ const [uncontrolledTab, setUncontrolledTab] = react.useState(
1931
+ defaultTab
1932
+ );
1933
+ const tab = tabProp ?? uncontrolledTab;
1934
+ const [draft, setDraft] = react.useState(() => valueProp ?? defaultValue ?? "");
1935
+ const value = valueProp ?? draft;
1936
+ function setTab(next) {
1937
+ if (tabProp === void 0) setUncontrolledTab(next);
1938
+ onTabChange?.(next);
1939
+ }
1940
+ __name(setTab, "setTab");
1941
+ function commit(next) {
1942
+ setDraft(next);
1943
+ onValueChange?.(next);
1944
+ }
1945
+ __name(commit, "commit");
1946
+ function runAction(action) {
1947
+ const el = textareaRef.current;
1948
+ if (!el) return;
1949
+ const { selectionStart, selectionEnd } = el;
1950
+ const edit = action(
1951
+ value,
1952
+ selectionStart ?? value.length,
1953
+ selectionEnd ?? value.length
1954
+ );
1955
+ commit(edit.value);
1956
+ el.focus();
1957
+ requestAnimationFrame(() => {
1958
+ el.setSelectionRange(edit.selectionStart, edit.selectionEnd);
1959
+ });
1960
+ }
1961
+ __name(runAction, "runAction");
1962
+ const tablistId = `${baseId}-tablist`;
1963
+ const writePanelId = `${baseId}-write-panel`;
1964
+ const previewPanelId = `${baseId}-preview-panel`;
1965
+ const renderedPreview = react.useMemo(
1966
+ () => renderMarkdown ? renderMarkdown(value) : null,
1967
+ [renderMarkdown, value]
1968
+ );
1969
+ react.useEffect(() => {
1970
+ if (isDev() && !renderMarkdown) {
1971
+ console.warn(
1972
+ "[kreativ-ui/MarkdownEditor]: no `renderMarkdown` prop was provided, so the Preview tab is just showing plain text with no markdown formatting applied. Pass a `renderMarkdown={(value) => ReactNode}` function \u2014 e.g. using react-markdown \u2014 to enable a real preview:\n\n import ReactMarkdown from 'react-markdown';\n <Textarea allowMarkdown renderMarkdown={(v) => <ReactMarkdown>{v}</ReactMarkdown>} />"
1973
+ );
1974
+ }
1975
+ }, [renderMarkdown]);
1976
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1977
+ "div",
1978
+ {
1979
+ className: cn(
1980
+ "rounded-(--kui-radii-md) border border-border",
1981
+ className
1982
+ ),
1983
+ children: [
1984
+ /* @__PURE__ */ jsxRuntime.jsxs(
1985
+ "div",
1986
+ {
1987
+ role: "tablist",
1988
+ "aria-label": "Markdown editor mode",
1989
+ id: tablistId,
1990
+ className: "flex items-center gap-4 border-b border-border px-3",
1991
+ children: [
1992
+ ["write", "preview"].map((t) => /* @__PURE__ */ jsxRuntime.jsx(
1993
+ "button",
1994
+ {
1995
+ type: "button",
1996
+ role: "tab",
1997
+ id: `${baseId}-${t}-tab`,
1998
+ "aria-selected": tab === t,
1999
+ "aria-controls": t === "write" ? writePanelId : previewPanelId,
2000
+ onClick: () => setTab(t),
2001
+ className: cn(
2002
+ "border-b-2 py-2.5 text-sm capitalize transition-colors",
2003
+ tab === t ? "border-brand text-text" : "border-transparent text-text-muted hover:text-text"
2004
+ ),
2005
+ children: t
2006
+ },
2007
+ t
2008
+ )),
2009
+ tab === "write" && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ml-auto flex items-center gap-1 py-1.5", children: TOOLBAR.map(({ label, icon: Icon, action }) => /* @__PURE__ */ jsxRuntime.jsx(
2010
+ "button",
2011
+ {
2012
+ type: "button",
2013
+ "aria-label": label,
2014
+ onClick: () => runAction(action),
2015
+ className: "rounded-(--kui-radii-sm) p-1.5 text-text-muted transition-colors hover:bg-surface-raised hover:text-text",
2016
+ children: /* @__PURE__ */ jsxRuntime.jsx(Icon, { size: 15 })
2017
+ },
2018
+ label
2019
+ )) })
2020
+ ]
2021
+ }
2022
+ ),
2023
+ /* @__PURE__ */ jsxRuntime.jsx(
2024
+ "div",
2025
+ {
2026
+ id: writePanelId,
2027
+ role: "tabpanel",
2028
+ "aria-labelledby": `${baseId}-write-tab`,
2029
+ hidden: tab !== "write",
2030
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2031
+ TextareaCore,
2032
+ {
2033
+ ref: (node) => {
2034
+ textareaRef.current = node;
2035
+ if (typeof ref === "function") ref(node);
2036
+ else if (ref)
2037
+ ref.current = node;
2038
+ },
2039
+ value,
2040
+ onValueChange: commit,
2041
+ resize: "vertical",
2042
+ variant: "ghost",
2043
+ className: "rounded-none border-0",
2044
+ ...textareaProps
2045
+ }
2046
+ )
2047
+ }
2048
+ ),
2049
+ /* @__PURE__ */ jsxRuntime.jsx(
2050
+ "div",
2051
+ {
2052
+ id: previewPanelId,
2053
+ role: "tabpanel",
2054
+ "aria-labelledby": `${baseId}-preview-tab`,
2055
+ hidden: tab !== "preview",
2056
+ className: "min-h-32 p-3 text-sm text-text",
2057
+ children: renderMarkdown ? renderedPreview : /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-text-muted", children: "No renderMarkdown provided \u2014 showing raw text." })
2058
+ }
2059
+ ),
2060
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center gap-2 border-t border-border px-3 py-2 text-xs text-text-muted", children: hint })
2061
+ ]
2062
+ }
2063
+ );
2064
+ }
2065
+ );
2066
+ MarkdownEditor.displayName = "MarkdownEditor";
2067
+ var Textarea = react.forwardRef(
2068
+ ({ allowMarkdown, ...props }, ref) => {
2069
+ if (allowMarkdown) {
2070
+ return /* @__PURE__ */ jsxRuntime.jsx(MarkdownEditor, { ref, ...props });
2071
+ }
2072
+ return /* @__PURE__ */ jsxRuntime.jsx(TextareaCore, { ref, ...props });
2073
+ }
2074
+ );
2075
+ Textarea.displayName = "Textarea";
2076
+ var checkboxBoxVariants = classVarianceAuthority.cva(
2077
+ "flex shrink-0 items-center justify-center rounded-[calc(var(--kui-radii-md)-2px)] border transition-colors duration-[var(--kui-duration-fast)]",
2078
+ {
2079
+ variants: {
2080
+ size: {
2081
+ sm: "h-4 w-4",
2082
+ md: "h-5 w-5",
2083
+ lg: "h-6 w-6"
2084
+ },
2085
+ state: {
2086
+ none: "",
2087
+ error: "border-danger",
2088
+ success: "border-success"
2089
+ },
2090
+ checked: {
2091
+ true: "bg-brand border-brand text-brand-fg",
2092
+ false: "border-border bg-transparent"
2093
+ },
2094
+ disabled: {
2095
+ true: "cursor-not-allowed",
2096
+ false: "cursor-pointer"
2097
+ }
2098
+ },
2099
+ defaultVariants: {
2100
+ size: "md",
2101
+ state: "none",
2102
+ checked: false,
2103
+ disabled: false
2104
+ },
2105
+ compoundVariants: [
2106
+ { checked: false, state: "error", class: "border-danger" },
2107
+ { checked: false, state: "success", class: "border-success" }
2108
+ ]
2109
+ }
2110
+ );
2111
+ var checkboxIconSizes = {
2112
+ sm: 10,
2113
+ md: 12,
2114
+ lg: 14
2115
+ };
2116
+ function DashIcon({ size }) {
2117
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 3, strokeLinecap: "round", "aria-hidden": "true", children: /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "5", y1: "12", x2: "19", y2: "12" }) });
2118
+ }
2119
+ __name(DashIcon, "DashIcon");
2120
+ function mergeRefs3(...refs) {
2121
+ return (node) => {
2122
+ refs.forEach((r) => {
2123
+ if (!r) return;
2124
+ if (typeof r === "function") r(node);
2125
+ else r.current = node;
2126
+ });
2127
+ };
2128
+ }
2129
+ __name(mergeRefs3, "mergeRefs");
2130
+ var Checkbox = react.forwardRef(
2131
+ ({
2132
+ className,
2133
+ checked: checkedProp,
2134
+ defaultChecked,
2135
+ onCheckedChange,
2136
+ indeterminate = false,
2137
+ size = "md",
2138
+ error,
2139
+ success,
2140
+ disabled,
2141
+ label,
2142
+ description,
2143
+ id: externalId,
2144
+ onChange: onChangeProp,
2145
+ required,
2146
+ ...props
2147
+ }, ref) => {
2148
+ const autoId = react.useId();
2149
+ const field = useOptionalFormField();
2150
+ const id = field?.id ?? externalId ?? autoId;
2151
+ const internalRef = react.useRef(null);
2152
+ const [internalChecked, setInternalChecked] = react.useState(
2153
+ defaultChecked ?? false
2154
+ );
2155
+ const checked = checkedProp !== void 0 ? checkedProp : internalChecked;
2156
+ const hasWarned = react.useRef(false);
2157
+ react.useEffect(() => {
2158
+ if (process.env?.NODE_ENV === "production") return;
2159
+ if (hasWarned.current) return;
2160
+ if (label && field?.hasExternalLabel) {
2161
+ console.warn(
2162
+ "[kreativ-ui/Checkbox] This checkbox has both a `label` prop and a <FormField.Label> ancestor. That renders two <label> elements pointing at the same input, which double-announces in screen readers. Use Checkbox's `label` prop instead of <FormField.Label> when the control is a checkbox."
2163
+ );
2164
+ hasWarned.current = true;
2165
+ }
2166
+ }, [label, field?.hasExternalLabel]);
2167
+ react.useEffect(() => {
2168
+ if (internalRef.current)
2169
+ internalRef.current.indeterminate = indeterminate;
2170
+ }, [indeterminate]);
2171
+ const isInvalid = error ?? field?.invalid ?? false;
2172
+ const isSuccess = success ?? false;
2173
+ const state = isInvalid ? "error" : isSuccess ? "success" : "none";
2174
+ function handleChange(e) {
2175
+ const next = e.target.checked;
2176
+ if (checkedProp === void 0) setInternalChecked(next);
2177
+ onCheckedChange?.(next);
2178
+ onChangeProp?.(e);
2179
+ }
2180
+ __name(handleChange, "handleChange");
2181
+ const descriptionId = description ? `${id}-description` : void 0;
2182
+ const describedBy = field?.describedBy ?? descriptionId;
2183
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2184
+ "div",
2185
+ {
2186
+ className: cn(
2187
+ "flex gap-2.5",
2188
+ disabled && "cursor-not-allowed opacity-50",
2189
+ className
2190
+ ),
2191
+ children: [
2192
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative mt-0.5 inline-flex", children: [
2193
+ /* @__PURE__ */ jsxRuntime.jsx(
2194
+ "input",
2195
+ {
2196
+ ref: mergeRefs3(internalRef, ref),
2197
+ type: "checkbox",
2198
+ id,
2199
+ checked,
2200
+ disabled,
2201
+ required: required ?? field?.required,
2202
+ onChange: handleChange,
2203
+ "aria-invalid": isInvalid || void 0,
2204
+ "aria-describedby": describedBy,
2205
+ className: "peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",
2206
+ "data-invalid": isInvalid || void 0,
2207
+ ...props
2208
+ }
2209
+ ),
2210
+ /* @__PURE__ */ jsxRuntime.jsx(
2211
+ "div",
2212
+ {
2213
+ "aria-hidden": "true",
2214
+ className: cn(
2215
+ checkboxBoxVariants({
2216
+ size,
2217
+ state,
2218
+ checked: checked || indeterminate,
2219
+ disabled: !!disabled
2220
+ }),
2221
+ "peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"
2222
+ ),
2223
+ children: indeterminate ? /* @__PURE__ */ jsxRuntime.jsx(DashIcon, { size: checkboxIconSizes[size] }) : checked ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Check, { size: checkboxIconSizes[size] }) : null
2224
+ }
2225
+ )
2226
+ ] }),
2227
+ (label || description) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-0.5", children: [
2228
+ label && /* @__PURE__ */ jsxRuntime.jsx(
2229
+ "label",
2230
+ {
2231
+ htmlFor: id,
2232
+ className: cn(
2233
+ "text-sm text-text",
2234
+ !disabled && "cursor-pointer"
2235
+ ),
2236
+ children: label
2237
+ }
2238
+ ),
2239
+ description && /* @__PURE__ */ jsxRuntime.jsx("p", { id: descriptionId, className: "text-xs text-text-muted", children: description })
2240
+ ] })
2241
+ ]
2242
+ }
2243
+ );
2244
+ }
2245
+ );
2246
+ Checkbox.displayName = "Checkbox";
2247
+ var RadioGroupContext = react.createContext(null);
2248
+ function useRadioGroupContext() {
2249
+ const ctx = react.useContext(RadioGroupContext);
2250
+ if (!ctx) {
2251
+ throw new Error("<Radio /> must be rendered inside <RadioGroup>.");
2252
+ }
2253
+ return ctx;
2254
+ }
2255
+ __name(useRadioGroupContext, "useRadioGroupContext");
2256
+ function RadioGroup({
2257
+ value: valueProp,
2258
+ defaultValue,
2259
+ onValueChange,
2260
+ name: nameProp,
2261
+ disabled = false,
2262
+ required = false,
2263
+ orientation = "vertical",
2264
+ size = "md",
2265
+ error,
2266
+ success,
2267
+ className,
2268
+ children
2269
+ }) {
2270
+ const autoName = react.useId();
2271
+ const name = nameProp ?? autoName;
2272
+ const field = useOptionalFormField();
2273
+ const [internalValue, setInternalValue] = react.useState(defaultValue);
2274
+ const value = valueProp !== void 0 ? valueProp : internalValue;
2275
+ const handleValueChange = react.useCallback(
2276
+ (next) => {
2277
+ if (valueProp === void 0) setInternalValue(next);
2278
+ onValueChange?.(next);
2279
+ },
2280
+ [valueProp, onValueChange]
2281
+ );
2282
+ const isInvalid = error ?? field?.invalid ?? false;
2283
+ const isSuccess = success ?? false;
2284
+ const state = isInvalid ? "error" : isSuccess ? "success" : "none";
2285
+ const groupRequired = required || !!field?.required;
2286
+ return /* @__PURE__ */ jsxRuntime.jsx(
2287
+ RadioGroupContext.Provider,
2288
+ {
2289
+ value: { name, value, onValueChange: handleValueChange, disabled, size, state, groupRequired },
2290
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2291
+ "div",
2292
+ {
2293
+ role: "radiogroup",
2294
+ "aria-labelledby": field?.hasExternalLabel ? `${field.id}-label` : void 0,
2295
+ "aria-describedby": field?.describedBy,
2296
+ "aria-required": groupRequired || void 0,
2297
+ "aria-invalid": isInvalid || void 0,
2298
+ className: cn(
2299
+ "flex gap-3",
2300
+ orientation === "horizontal" ? "flex-row flex-wrap" : "flex-col",
2301
+ className
2302
+ ),
2303
+ children
2304
+ }
2305
+ )
2306
+ }
2307
+ );
2308
+ }
2309
+ __name(RadioGroup, "RadioGroup");
2310
+ var radioBubbleVariants = classVarianceAuthority.cva(
2311
+ "flex shrink-0 items-center justify-center rounded-full border transition-colors duration-[var(--kui-duration-fast)]",
2312
+ {
2313
+ variants: {
2314
+ size: {
2315
+ sm: "h-4 w-4",
2316
+ md: "h-5 w-5",
2317
+ lg: "h-6 w-6"
2318
+ },
2319
+ state: {
2320
+ none: "",
2321
+ error: "border-danger",
2322
+ success: "border-success"
2323
+ },
2324
+ checked: {
2325
+ true: "border-brand",
2326
+ false: "border-border bg-transparent"
2327
+ },
2328
+ disabled: {
2329
+ true: "cursor-not-allowed",
2330
+ false: "cursor-pointer"
2331
+ }
2332
+ },
2333
+ defaultVariants: { size: "md", state: "none", checked: false, disabled: false },
2334
+ compoundVariants: [
2335
+ { checked: false, state: "error", class: "border-danger" },
2336
+ { checked: false, state: "success", class: "border-success" }
2337
+ ]
2338
+ }
2339
+ );
2340
+ var radioDotSizes = {
2341
+ sm: "h-1.5 w-1.5",
2342
+ md: "h-2 w-2",
2343
+ lg: "h-2.5 w-2.5"
2344
+ };
2345
+ function Radio({
2346
+ value,
2347
+ disabled: itemDisabled,
2348
+ label,
2349
+ description,
2350
+ className,
2351
+ ...props
2352
+ }) {
2353
+ const group = useRadioGroupContext();
2354
+ const id = `${group.name}-${value}`;
2355
+ const checked = group.value === value;
2356
+ const disabled = itemDisabled || group.disabled;
2357
+ const descriptionId = description ? `${id}-description` : void 0;
2358
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex gap-2.5", disabled && "cursor-not-allowed opacity-50", className), children: [
2359
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative mt-0.5 inline-flex", children: [
2360
+ /* @__PURE__ */ jsxRuntime.jsx(
2361
+ "input",
2362
+ {
2363
+ type: "radio",
2364
+ id,
2365
+ name: group.name,
2366
+ value,
2367
+ checked,
2368
+ disabled,
2369
+ onChange: () => group.onValueChange(value),
2370
+ "aria-describedby": descriptionId,
2371
+ className: "peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",
2372
+ "data-invalid": group.state === "error" || void 0,
2373
+ ...props
2374
+ }
2375
+ ),
2376
+ /* @__PURE__ */ jsxRuntime.jsx(
2377
+ "div",
2378
+ {
2379
+ "aria-hidden": "true",
2380
+ className: cn(
2381
+ radioBubbleVariants({ size: group.size, state: group.state, checked, disabled }),
2382
+ "peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"
2383
+ ),
2384
+ children: checked && /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("rounded-full bg-brand", radioDotSizes[group.size]) })
2385
+ }
2386
+ )
2387
+ ] }),
2388
+ (label || description) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-0.5", children: [
2389
+ label && /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: cn("text-sm text-text", !disabled && "cursor-pointer", group.size === "sm" && "text-xs"), children: label }),
2390
+ description && /* @__PURE__ */ jsxRuntime.jsx("p", { id: descriptionId, className: cn("text-xs text-text-muted", group.size === "sm" && "text-[10px]"), children: description })
2391
+ ] })
2392
+ ] });
2393
+ }
2394
+ __name(Radio, "Radio");
2395
+ var switchTrackVariants = classVarianceAuthority.cva(
2396
+ "relative inline-flex shrink-0 items-center rounded-full border border-transparent transition-colors duration-[var(--kui-duration-fast)]",
2397
+ {
2398
+ variants: {
2399
+ size: {
2400
+ sm: "h-4 w-7",
2401
+ md: "h-5 w-9",
2402
+ lg: "h-6 w-11"
2403
+ },
2404
+ checked: {
2405
+ true: "bg-brand",
2406
+ false: "bg-surface-raised"
2407
+ },
2408
+ disabled: {
2409
+ true: "cursor-not-allowed",
2410
+ false: "cursor-pointer"
2411
+ }
2412
+ },
2413
+ defaultVariants: { size: "md", checked: false, disabled: false }
2414
+ }
2415
+ );
2416
+ var switchThumbConfig = {
2417
+ sm: { thumb: "h-3 w-3", translate: "translate-x-3" },
2418
+ md: { thumb: "h-4 w-4", translate: "translate-x-4" },
2419
+ lg: { thumb: "h-5 w-5", translate: "translate-x-5" }
2420
+ };
2421
+ function Switch({
2422
+ checked: checkedProp,
2423
+ defaultChecked,
2424
+ onCheckedChange,
2425
+ size = "md",
2426
+ disabled,
2427
+ label,
2428
+ description,
2429
+ className,
2430
+ id: externalId,
2431
+ onChange: onChangeProp,
2432
+ ...props
2433
+ }) {
2434
+ const autoId = react.useId();
2435
+ const field = useOptionalFormField();
2436
+ const id = field?.id ?? externalId ?? autoId;
2437
+ const [internalChecked, setInternalChecked] = react.useState(defaultChecked ?? false);
2438
+ const checked = checkedProp !== void 0 ? checkedProp : internalChecked;
2439
+ function handleChange(e) {
2440
+ const next = e.target.checked;
2441
+ if (checkedProp === void 0) setInternalChecked(next);
2442
+ onCheckedChange?.(next);
2443
+ onChangeProp?.(e);
2444
+ }
2445
+ __name(handleChange, "handleChange");
2446
+ const descriptionId = description ? `${id}-description` : void 0;
2447
+ const { thumb, translate } = switchThumbConfig[size];
2448
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("flex gap-2.5", disabled && "cursor-not-allowed opacity-50", className), children: [
2449
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative inline-flex", children: [
2450
+ /* @__PURE__ */ jsxRuntime.jsx(
2451
+ "input",
2452
+ {
2453
+ type: "checkbox",
2454
+ role: "switch",
2455
+ id,
2456
+ checked,
2457
+ disabled,
2458
+ onChange: handleChange,
2459
+ "aria-describedby": field?.describedBy ?? descriptionId,
2460
+ className: "peer absolute inset-0 z-10 m-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-not-allowed",
2461
+ ...props
2462
+ }
2463
+ ),
2464
+ /* @__PURE__ */ jsxRuntime.jsx(
2465
+ "div",
2466
+ {
2467
+ "aria-hidden": "true",
2468
+ className: cn(
2469
+ switchTrackVariants({ size, checked, disabled: !!disabled }),
2470
+ "peer-focus-visible:ring-2 peer-focus-visible:ring-brand peer-focus-visible:ring-offset-1"
2471
+ ),
2472
+ children: /* @__PURE__ */ jsxRuntime.jsx(
2473
+ "div",
2474
+ {
2475
+ className: cn(
2476
+ "absolute left-0.5 rounded-full bg-white shadow transition-transform duration-[var(--kui-duration-fast)]",
2477
+ thumb,
2478
+ checked && translate
2479
+ )
2480
+ }
2481
+ )
2482
+ }
2483
+ )
2484
+ ] }),
2485
+ (label || description) && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-0.5", children: [
2486
+ label && /* @__PURE__ */ jsxRuntime.jsx("label", { htmlFor: id, className: cn("text-sm text-text", !disabled && "cursor-pointer"), children: label }),
2487
+ description && /* @__PURE__ */ jsxRuntime.jsx("p", { id: descriptionId, className: "text-xs text-text-muted", children: description })
2488
+ ] })
2489
+ ] });
2490
+ }
2491
+ __name(Switch, "Switch");
2492
+ var ComboboxContext = react.createContext(null);
2493
+ function useComboboxContext(componentName) {
2494
+ const ctx = react.useContext(ComboboxContext);
2495
+ if (!ctx) throw new Error(`<${componentName} /> must be rendered inside <Combobox>.`);
2496
+ return ctx;
2497
+ }
2498
+ __name(useComboboxContext, "useComboboxContext");
2499
+ var inputBase2 = [
2500
+ "flex",
2501
+ "items-center",
2502
+ "font-sans",
2503
+ "transition-colors",
2504
+ "duration-[var(--kui-duration-fast)]",
2505
+ "outline-none",
2506
+ "placeholder:text-text-muted",
2507
+ "disabled:opacity-50",
2508
+ "disabled:pointer-events-none",
2509
+ "disabled:cursor-not-allowed"
2510
+ ].join(" ");
2511
+ var inputWrapperVariants = classVarianceAuthority.cva(
2512
+ "group relative inline-flex items-center gap-2 transition-colors",
2513
+ {
2514
+ variants: {
2515
+ variant: {
2516
+ outline: "border border-border bg-transparent text-text hover:border-brand",
2517
+ filled: "border border-transparent bg-surface-raised text-text hover:bg-surface",
2518
+ ghost: "border border-transparent bg-transparent text-text hover:bg-surface-raised"
2519
+ },
2520
+ state: {
2521
+ none: "focus-within:ring-2 focus-within:ring-brand/20",
2522
+ error: "border-danger focus-within:ring-2 focus-within:ring-danger/20",
2523
+ success: "border-success focus-within:ring-2 focus-within:ring-success/20"
2524
+ },
2525
+ rounded: {
2526
+ true: "rounded-full",
2527
+ false: "rounded-[var(--kui-radii-md)]"
2528
+ },
2529
+ fullWidth: {
2530
+ true: "w-full",
2531
+ false: ""
2532
+ },
2533
+ hasIcon: {
2534
+ true: "px-2",
2535
+ false: ""
2536
+ },
2537
+ disabled: {
2538
+ true: "pointer-events-none cursor-not-allowed opacity-50",
2539
+ false: ""
2540
+ }
2541
+ },
2542
+ defaultVariants: {
2543
+ variant: "outline",
2544
+ state: "none",
2545
+ rounded: false,
2546
+ fullWidth: true,
2547
+ hasIcon: false,
2548
+ disabled: false
2549
+ }
2550
+ }
2551
+ );
2552
+ var inputSizeVariants = {
2553
+ sm: "h-8 px-2 text-xs",
2554
+ md: "h-10 px-3 text-sm",
2555
+ lg: "h-12 px-4 text-base"
2556
+ };
2557
+ function orderedFilteredValues(ctx, query) {
2558
+ const q = query.trim().toLowerCase();
2559
+ return [...ctx.items.entries()].filter(([, meta]) => !meta.disabled).filter(([, meta]) => !q || String(meta.label).toLowerCase().includes(q)).map(([val]) => val);
2560
+ }
2561
+ __name(orderedFilteredValues, "orderedFilteredValues");
2562
+ var ComboboxInput = react.forwardRef(
2563
+ ({ variant = "outline", size = "md", placeholder, clearable = false, allowFreeText = false, className }, ref) => {
2564
+ const ctx = useComboboxContext("ComboboxInput");
2565
+ const state = ctx.isInvalid ? "error" : ctx.isSuccess ? "success" : "none";
2566
+ const showClear = clearable && ctx.inputValue.length > 0 && !ctx.disabled;
2567
+ react.useEffect(() => {
2568
+ console.log(ctx);
2569
+ if (ctx.value === void 0) return;
2570
+ const meta = ctx.items.get(ctx.value);
2571
+ if (meta && !ctx.open) {
2572
+ ctx.setInputValue(String(meta.label));
2573
+ }
2574
+ }, [ctx.value, ctx.open, ctx.items]);
2575
+ function handleChange(e) {
2576
+ ctx.setInputValue(e.target.value);
2577
+ if (!ctx.open) ctx.setOpen(true);
2578
+ ctx.setActiveValue(void 0);
2579
+ if (allowFreeText) ctx.onValueChange(e.target.value || void 0);
2580
+ }
2581
+ __name(handleChange, "handleChange");
2582
+ function handleKeyDown(e) {
2583
+ const order = orderedFilteredValues(ctx, ctx.inputValue);
2584
+ switch (e.key) {
2585
+ case "ArrowDown": {
2586
+ e.preventDefault();
2587
+ if (!ctx.open) {
2588
+ ctx.setOpen(true);
2589
+ return;
2590
+ }
2591
+ const i = ctx.activeValue ? order.indexOf(ctx.activeValue) : -1;
2592
+ ctx.setActiveValue(order[(i + 1) % order.length]);
2593
+ break;
2594
+ }
2595
+ case "ArrowUp": {
2596
+ e.preventDefault();
2597
+ if (!ctx.open) {
2598
+ ctx.setOpen(true);
2599
+ return;
2600
+ }
2601
+ const i = ctx.activeValue ? order.indexOf(ctx.activeValue) : -1;
2602
+ ctx.setActiveValue(order[(i - 1 + order.length) % order.length]);
2603
+ break;
2604
+ }
2605
+ case "Enter":
2606
+ e.preventDefault();
2607
+ if (ctx.activeValue !== void 0) ctx.onValueChange(ctx.activeValue);
2608
+ else if (allowFreeText) ctx.setOpen(false);
2609
+ break;
2610
+ case "Escape":
2611
+ if (ctx.open) {
2612
+ e.preventDefault();
2613
+ ctx.setOpen(false);
2614
+ }
2615
+ break;
2616
+ }
2617
+ }
2618
+ __name(handleKeyDown, "handleKeyDown");
2619
+ function handleBlur() {
2620
+ if (!allowFreeText && ctx.value === void 0) ctx.setInputValue("");
2621
+ setTimeout(() => ctx.setOpen(false), 120);
2622
+ }
2623
+ __name(handleBlur, "handleBlur");
2624
+ return /* @__PURE__ */ jsxRuntime.jsxs(
2625
+ "div",
2626
+ {
2627
+ className: cn(
2628
+ inputWrapperVariants({ variant, state, fullWidth: true, disabled: ctx.disabled, rounded: ctx.rounded }),
2629
+ "px-2",
2630
+ className
2631
+ ),
2632
+ children: [
2633
+ /* @__PURE__ */ jsxRuntime.jsx(
2634
+ "input",
2635
+ {
2636
+ ref: (node) => {
2637
+ ctx.triggerRef.current = node;
2638
+ if (typeof ref === "function") ref(node);
2639
+ else if (ref) ref.current = node;
2640
+ },
2641
+ id: ctx.triggerId,
2642
+ role: "combobox",
2643
+ "aria-autocomplete": "list",
2644
+ "aria-haspopup": "listbox",
2645
+ "aria-expanded": ctx.open,
2646
+ "aria-controls": ctx.contentId,
2647
+ "aria-activedescendant": ctx.open && ctx.activeValue ? ctx.optionId(ctx.activeValue) : void 0,
2648
+ "aria-invalid": ctx.isInvalid || void 0,
2649
+ "aria-describedby": ctx.describedBy,
2650
+ disabled: ctx.disabled,
2651
+ value: ctx.inputValue,
2652
+ placeholder,
2653
+ onChange: handleChange,
2654
+ onFocus: () => ctx.setOpen(true),
2655
+ onKeyDown: handleKeyDown,
2656
+ onBlur: handleBlur,
2657
+ "data-state": ctx.open ? "open" : "closed",
2658
+ className: cn(inputBase2, "flex-1 border-0 bg-transparent outline-none", inputSizeVariants[size], "px-0")
2659
+ }
2660
+ ),
2661
+ showClear && /* @__PURE__ */ jsxRuntime.jsx(
2662
+ "button",
2663
+ {
2664
+ type: "button",
2665
+ tabIndex: -1,
2666
+ "aria-label": "Clear",
2667
+ onMouseDown: (e) => e.preventDefault(),
2668
+ onClick: () => {
2669
+ ctx.setInputValue("");
2670
+ ctx.onValueChange(void 0);
2671
+ },
2672
+ className: "flex items-center justify-center text-text-muted transition-colors hover:text-text",
2673
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 14 })
2674
+ }
2675
+ )
2676
+ ]
2677
+ }
2678
+ );
2679
+ }
2680
+ );
2681
+ ComboboxInput.displayName = "ComboboxInput";
2682
+ function ComboboxItem({
2683
+ value,
2684
+ disabled = false,
2685
+ children,
2686
+ className
2687
+ }) {
2688
+ const ctx = useComboboxContext("ComboboxItem");
2689
+ const ref = react.useRef(null);
2690
+ const active = ctx.activeValue === value;
2691
+ const selected = ctx.value === value;
2692
+ react.useEffect(
2693
+ () => ctx.registerItem(value, { label: children, disabled, visible: true }),
2694
+ [value, disabled, children]
2695
+ );
2696
+ react.useEffect(() => {
2697
+ if (active) ref.current?.scrollIntoView({ block: "nearest" });
2698
+ }, [active]);
2699
+ const query = ctx.inputValue.trim().toLowerCase();
2700
+ const matches = !query || String(children).toLowerCase().includes(query);
2701
+ react.useEffect(() => {
2702
+ ctx.setItemVisibility(value, matches);
2703
+ }, [matches, value]);
2704
+ if (!matches) return null;
2705
+ return /* @__PURE__ */ jsxRuntime.jsx(
2706
+ "div",
2707
+ {
2708
+ ref,
2709
+ id: ctx.optionId(value),
2710
+ role: "option",
2711
+ "aria-selected": selected,
2712
+ "aria-disabled": disabled || void 0,
2713
+ onMouseEnter: () => !disabled && ctx.setActiveValue(value),
2714
+ onMouseDown: (e) => e.preventDefault(),
2715
+ onClick: () => !disabled && ctx.onValueChange(value),
2716
+ className: cn(
2717
+ "flex cursor-pointer items-center rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",
2718
+ active && "bg-brand/15 text-brand",
2719
+ selected && !active && "bg-surface-raised",
2720
+ disabled && "pointer-events-none cursor-not-allowed opacity-50",
2721
+ className
2722
+ ),
2723
+ children
2724
+ }
2725
+ );
2726
+ }
2727
+ __name(ComboboxItem, "ComboboxItem");
2728
+ var VIEWPORT_PADDING2 = 8;
2729
+ function useFloatingSide(triggerRef, open) {
2730
+ const contentRef = react.useRef(null);
2731
+ const [side, setSide] = react.useState("bottom");
2732
+ react.useLayoutEffect(() => {
2733
+ if (!open) return;
2734
+ const trigger = triggerRef.current;
2735
+ const content = contentRef.current;
2736
+ if (!trigger || !content) return;
2737
+ function measure() {
2738
+ const triggerRect = trigger.getBoundingClientRect();
2739
+ const contentHeight = content.offsetHeight;
2740
+ const spaceBelow = window.innerHeight - triggerRect.bottom - VIEWPORT_PADDING2;
2741
+ const spaceAbove = triggerRect.top - VIEWPORT_PADDING2;
2742
+ setSide(contentHeight > spaceBelow && spaceAbove > spaceBelow ? "top" : "bottom");
2743
+ }
2744
+ __name(measure, "measure");
2745
+ measure();
2746
+ window.addEventListener("resize", measure);
2747
+ window.addEventListener("scroll", measure, true);
2748
+ return () => {
2749
+ window.removeEventListener("resize", measure);
2750
+ window.removeEventListener("scroll", measure, true);
2751
+ };
2752
+ }, [open, triggerRef]);
2753
+ return { contentRef, side };
2754
+ }
2755
+ __name(useFloatingSide, "useFloatingSide");
2756
+ function ComboboxContent({
2757
+ className,
2758
+ children
2759
+ }) {
2760
+ const ctx = useComboboxContext("ComboboxContent");
2761
+ const { contentRef, side } = useFloatingSide(ctx.triggerRef, ctx.open);
2762
+ if (!ctx.open) return null;
2763
+ return /* @__PURE__ */ jsxRuntime.jsx(
2764
+ "div",
2765
+ {
2766
+ ref: contentRef,
2767
+ id: ctx.contentId,
2768
+ role: "listbox",
2769
+ "aria-labelledby": ctx.triggerId,
2770
+ "data-side": side,
2771
+ className: cn(
2772
+ "animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-[var(--kui-radii-md)] border border-border bg-surface p-1 shadow-lg",
2773
+ side === "bottom" ? "top-full mt-1" : "bottom-full mb-1",
2774
+ className
2775
+ ),
2776
+ children
2777
+ }
2778
+ );
2779
+ }
2780
+ __name(ComboboxContent, "ComboboxContent");
2781
+ function ComboboxEmpty({ children }) {
2782
+ const ctx = useComboboxContext("ComboboxEmpty");
2783
+ const visibleCount = [...ctx.items.values()].filter((item) => item.visible && !item.disabled).length;
2784
+ if (visibleCount > 0) return null;
2785
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-2 py-3 text-center text-sm text-text-muted", children: children ?? "No results found" });
2786
+ }
2787
+ __name(ComboboxEmpty, "ComboboxEmpty");
2788
+ function ComboboxLoading({
2789
+ children = "Loading...",
2790
+ className
2791
+ }) {
2792
+ return /* @__PURE__ */ jsxRuntime.jsx(
2793
+ "div",
2794
+ {
2795
+ role: "status",
2796
+ "aria-live": "polite",
2797
+ className: cn(
2798
+ "px-2 py-3 text-center text-sm text-text-muted",
2799
+ className
2800
+ ),
2801
+ children
2802
+ }
2803
+ );
2804
+ }
2805
+ __name(ComboboxLoading, "ComboboxLoading");
2806
+ function Combobox({
2807
+ value,
2808
+ onValueChange,
2809
+ inputValue: inputValueProp,
2810
+ defaultInputValue = "",
2811
+ onInputChange,
2812
+ disabled = false,
2813
+ name,
2814
+ error,
2815
+ success,
2816
+ rounded,
2817
+ className,
2818
+ children
2819
+ }) {
2820
+ const autoId = react.useId();
2821
+ const field = useOptionalFormField();
2822
+ const triggerId = field?.id ?? autoId;
2823
+ const contentId = `${triggerId}-listbox`;
2824
+ const isInvalid = error || field?.invalid || false;
2825
+ const isSuccess = success && !isInvalid ? true : false;
2826
+ const [internalInput, setInternalInput] = react.useState(defaultInputValue);
2827
+ const inputValue = inputValueProp !== void 0 ? inputValueProp : internalInput;
2828
+ function setInputValue(v) {
2829
+ if (inputValueProp === void 0) setInternalInput(v);
2830
+ onInputChange?.(v);
2831
+ }
2832
+ __name(setInputValue, "setInputValue");
2833
+ const [open, setOpen] = react.useState(false);
2834
+ const [activeValue, setActiveValue] = react.useState(void 0);
2835
+ const itemsRef = react.useRef(/* @__PURE__ */ new Map());
2836
+ const [items, setItems] = react.useState(/* @__PURE__ */ new Map());
2837
+ const registerItem = react.useCallback(
2838
+ (value2, meta) => {
2839
+ const item = {
2840
+ ...meta,
2841
+ visible: true
2842
+ };
2843
+ itemsRef.current.set(value2, item);
2844
+ setItems((prev) => {
2845
+ const next = new Map(prev);
2846
+ next.set(value2, item);
2847
+ return next;
2848
+ });
2849
+ return () => unregisterItem(value2);
2850
+ },
2851
+ []
2852
+ );
2853
+ function setItemVisibility(value2, visible) {
2854
+ setItems((prev) => {
2855
+ const item2 = prev.get(value2);
2856
+ if (!item2 || item2.visible === visible) {
2857
+ return prev;
2858
+ }
2859
+ const next = new Map(prev);
2860
+ next.set(value2, {
2861
+ ...item2,
2862
+ visible
2863
+ });
2864
+ return next;
2865
+ });
2866
+ const item = itemsRef.current.get(value2);
2867
+ if (item) {
2868
+ itemsRef.current.set(value2, {
2869
+ ...item,
2870
+ visible
2871
+ });
2872
+ }
2873
+ }
2874
+ __name(setItemVisibility, "setItemVisibility");
2875
+ function unregisterItem(value2) {
2876
+ setItems((prev) => {
2877
+ if (!prev.has(value2)) return prev;
2878
+ const next = new Map(prev);
2879
+ next.delete(value2);
2880
+ return next;
2881
+ });
2882
+ itemsRef.current.delete(value2);
2883
+ }
2884
+ __name(unregisterItem, "unregisterItem");
2885
+ const triggerRef = react.useRef(null);
2886
+ const rootRef = react.useRef(null);
2887
+ react.useEffect(() => {
2888
+ if (!open) return;
2889
+ function handlePointerDown(e) {
2890
+ if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
2891
+ }
2892
+ __name(handlePointerDown, "handlePointerDown");
2893
+ document.addEventListener("mousedown", handlePointerDown);
2894
+ return () => document.removeEventListener("mousedown", handlePointerDown);
2895
+ }, [open]);
2896
+ const optionId = react.useCallback((val) => `${contentId}-option-${val}`, [contentId]);
2897
+ react.useEffect(() => {
2898
+ if (!value) {
2899
+ setInputValue("");
2900
+ return;
2901
+ }
2902
+ const item = itemsRef.current.get(value);
2903
+ if (item && !open) {
2904
+ setInputValue(String(item.label));
2905
+ }
2906
+ }, [value, open]);
2907
+ const ctxValue = react.useMemo(
2908
+ () => ({
2909
+ value,
2910
+ inputValue,
2911
+ setInputValue,
2912
+ onValueChange: /* @__PURE__ */ __name((v) => {
2913
+ onValueChange?.(v);
2914
+ const item = v ? itemsRef.current.get(v) : void 0;
2915
+ if (item) {
2916
+ setInputValue(String(item.label));
2917
+ }
2918
+ setOpen(false);
2919
+ }, "onValueChange"),
2920
+ disabled,
2921
+ open,
2922
+ setOpen,
2923
+ triggerId,
2924
+ contentId,
2925
+ triggerRef,
2926
+ isInvalid,
2927
+ isSuccess,
2928
+ describedBy: field?.describedBy,
2929
+ activeValue,
2930
+ setActiveValue,
2931
+ items,
2932
+ registerItem,
2933
+ rounded,
2934
+ optionId,
2935
+ setItemVisibility,
2936
+ unregisterItem
2937
+ }),
2938
+ [value, inputValue, onValueChange, disabled, open, triggerId, contentId, field?.invalid, field?.describedBy, activeValue, registerItem, optionId, success, rounded, items, setItemVisibility, unregisterItem]
2939
+ );
2940
+ return /* @__PURE__ */ jsxRuntime.jsx(ComboboxContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: rootRef, className: className ?? "relative w-full", children: [
2941
+ children,
2942
+ name && /* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name, value: value ?? "", disabled })
2943
+ ] }) });
2944
+ }
2945
+ __name(Combobox, "Combobox");
2946
+ Combobox.Input = ComboboxInput;
2947
+ Combobox.Item = ComboboxItem;
2948
+ Combobox.Content = ComboboxContent;
2949
+ Combobox.Empty = ComboboxEmpty;
2950
+ Combobox.Loading = ComboboxLoading;
2951
+ var MultiSelectContext = react.createContext(null);
2952
+ function useMultiSelectContext(componentName) {
2953
+ const ctx = react.useContext(MultiSelectContext);
2954
+ if (!ctx) throw new Error(`<${componentName} /> must be rendered inside <MultiSelect>.`);
2955
+ return ctx;
2956
+ }
2957
+ __name(useMultiSelectContext, "useMultiSelectContext");
2958
+ var multiSelectSizeVariants = classVarianceAuthority.cva("", {
2959
+ variants: {
2960
+ size: {
2961
+ sm: "min-h-[2.25rem] py-1 px-2 text-xs gap-1",
2962
+ md: "min-h-[2.75rem] py-1.5 px-3 text-sm gap-1.5",
2963
+ lg: "min-h-[3.25rem] py-2 px-4 text-base gap-2"
2964
+ }
2965
+ },
2966
+ defaultVariants: {
2967
+ size: "md"
2968
+ }
2969
+ });
2970
+ var chipSizeVariants = classVarianceAuthority.cva("inline-flex items-center rounded-full", {
2971
+ variants: {
2972
+ size: {
2973
+ sm: "text-[10px] px-1.5 py-0.5 gap-0.5",
2974
+ md: "text-xs px-2 py-0.5 gap-1",
2975
+ lg: "text-sm px-2.5 py-1 gap-1.5"
2976
+ }
2977
+ },
2978
+ defaultVariants: {
2979
+ size: "md"
2980
+ }
2981
+ });
2982
+ function orderedEnabledValues2(items) {
2983
+ return [...items.entries()].filter(([, meta]) => !meta.disabled).map(([val]) => val);
2984
+ }
2985
+ __name(orderedEnabledValues2, "orderedEnabledValues");
2986
+ var MultiSelectTrigger = react.forwardRef(
2987
+ ({ className }, ref) => {
2988
+ const ctx = useMultiSelectContext("MultiSelectTrigger");
2989
+ const state = ctx.isInvalid ? "error" : ctx.isSuccess ? "success" : "none";
2990
+ const showClear = ctx.clearable && ctx.value.length > 0 && !ctx.disabled;
2991
+ const visible = ctx.maxVisibleChips ? ctx.value.slice(0, ctx.maxVisibleChips) : ctx.value;
2992
+ const overflow = ctx.value.length - visible.length;
2993
+ function move(delta) {
2994
+ const order = orderedEnabledValues2(ctx.items);
2995
+ if (!order.length) return;
2996
+ const i = ctx.activeValue ? order.indexOf(ctx.activeValue) : -1;
2997
+ ctx.setActiveValue(order[(i + delta + order.length) % order.length]);
2998
+ }
2999
+ __name(move, "move");
3000
+ function handleKeyDown(e) {
3001
+ switch (e.key) {
3002
+ case "ArrowDown":
3003
+ e.preventDefault();
3004
+ ctx.open ? move(1) : ctx.setOpen(true);
3005
+ break;
3006
+ case "ArrowUp":
3007
+ e.preventDefault();
3008
+ ctx.open ? move(-1) : ctx.setOpen(true);
3009
+ break;
3010
+ case "Enter":
3011
+ case " ":
3012
+ e.preventDefault();
3013
+ if (!ctx.open) ctx.setOpen(true);
3014
+ else if (ctx.activeValue) ctx.toggleValue(ctx.activeValue);
3015
+ break;
3016
+ case "Escape":
3017
+ if (ctx.open) {
3018
+ e.preventDefault();
3019
+ ctx.setOpen(false);
3020
+ }
3021
+ break;
3022
+ }
3023
+ }
3024
+ __name(handleKeyDown, "handleKeyDown");
3025
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3026
+ "div",
3027
+ {
3028
+ ref: ctx.triggerRef,
3029
+ className: cn(
3030
+ inputWrapperVariants({ variant: ctx.variant, state, fullWidth: true, disabled: ctx.disabled, rounded: ctx.rounded }),
3031
+ multiSelectSizeVariants({ size: ctx.size }),
3032
+ "flex flex-wrap items-center gap-1",
3033
+ className
3034
+ ),
3035
+ children: [
3036
+ /* @__PURE__ */ jsxRuntime.jsxs(
3037
+ "button",
3038
+ {
3039
+ ref,
3040
+ type: "button",
3041
+ id: ctx.triggerId,
3042
+ role: "combobox",
3043
+ "aria-haspopup": "listbox",
3044
+ "aria-expanded": ctx.open,
3045
+ "aria-controls": ctx.contentId,
3046
+ "aria-invalid": ctx.isInvalid || void 0,
3047
+ "aria-describedby": ctx.describedBy,
3048
+ "aria-required": ctx.required || void 0,
3049
+ disabled: ctx.disabled,
3050
+ onClick: () => !ctx.disabled && ctx.setOpen(!ctx.open),
3051
+ onKeyDown: handleKeyDown,
3052
+ className: "flex flex-1 flex-wrap items-center gap-1 bg-transparent text-left outline-none cursor-pointer disabled:cursor-not-allowed",
3053
+ children: [
3054
+ ctx.value.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-text-muted", children: ctx.placeholder }),
3055
+ visible.map((v) => {
3056
+ const meta = ctx.items.get(v);
3057
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3058
+ "span",
3059
+ {
3060
+ className: cn(
3061
+ chipSizeVariants({ size: ctx.size }),
3062
+ "bg-brand/15 text-brand"
3063
+ ),
3064
+ children: [
3065
+ meta?.label ?? v,
3066
+ /* @__PURE__ */ jsxRuntime.jsx(
3067
+ "span",
3068
+ {
3069
+ role: "button",
3070
+ tabIndex: -1,
3071
+ "aria-label": `Remove ${meta?.label ?? v}`,
3072
+ onClick: (e) => {
3073
+ e.stopPropagation();
3074
+ ctx.removeValue(v);
3075
+ },
3076
+ className: "hover:opacity-70",
3077
+ children: /* @__PURE__ */ jsxRuntime.jsx(
3078
+ lucideReact.X,
3079
+ {
3080
+ size: ctx.size === "sm" ? 8 : ctx.size === "md" ? 10 : 12
3081
+ }
3082
+ )
3083
+ }
3084
+ )
3085
+ ]
3086
+ },
3087
+ v
3088
+ );
3089
+ }),
3090
+ overflow > 0 && /* @__PURE__ */ jsxRuntime.jsxs("span", { className: cn(
3091
+ "text-text-muted",
3092
+ ctx.size === "sm" ? "text-[10px]" : ctx.size === "md" ? "text-xs" : "text-sm"
3093
+ ), children: [
3094
+ "+",
3095
+ overflow,
3096
+ " more"
3097
+ ] })
3098
+ ]
3099
+ }
3100
+ ),
3101
+ showClear && /* @__PURE__ */ jsxRuntime.jsx(
3102
+ "button",
3103
+ {
3104
+ type: "button",
3105
+ tabIndex: -1,
3106
+ "aria-label": "Clear selection",
3107
+ onClick: (e) => {
3108
+ e.preventDefault();
3109
+ e.stopPropagation();
3110
+ ctx.onClear();
3111
+ },
3112
+ className: "flex h-4 w-4 shrink-0 items-center justify-center text-text-muted transition-colors hover:text-text",
3113
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 14 })
3114
+ }
3115
+ )
3116
+ ]
3117
+ }
3118
+ );
3119
+ }
3120
+ );
3121
+ MultiSelectTrigger.displayName = "MultiSelectTrigger";
3122
+ function MultiSelectContent({
3123
+ className,
3124
+ children,
3125
+ ...props
3126
+ }) {
3127
+ const ctx = useMultiSelectContext("MultiSelectContent");
3128
+ const { side, contentRef } = useFloatingSide(ctx.triggerRef, ctx.open);
3129
+ if (!ctx.open) return null;
3130
+ return /* @__PURE__ */ jsxRuntime.jsx(
3131
+ "div",
3132
+ {
3133
+ ref: contentRef,
3134
+ id: ctx.contentId,
3135
+ role: "listbox",
3136
+ "aria-labelledby": ctx.triggerId,
3137
+ "data-state": ctx.open ? "open" : "closed",
3138
+ "data-side": side,
3139
+ className: cn(
3140
+ "animate-kui-scale-in absolute z-50 max-h-64 w-full overflow-auto rounded-[var(--kui-radii-md)] border border-border bg-surface p-1 shadow-lg",
3141
+ side === "bottom" ? "top-full mt-1" : "bottom-full mb-1",
3142
+ className
3143
+ ),
3144
+ ...props,
3145
+ children
3146
+ }
3147
+ );
3148
+ }
3149
+ __name(MultiSelectContent, "MultiSelectContent");
3150
+ function CheckIcon() {
3151
+ return /* @__PURE__ */ jsxRuntime.jsx(
3152
+ "svg",
3153
+ {
3154
+ width: "12",
3155
+ height: "12",
3156
+ viewBox: "0 0 24 24",
3157
+ fill: "none",
3158
+ stroke: "currentColor",
3159
+ strokeWidth: 3,
3160
+ strokeLinecap: "round",
3161
+ strokeLinejoin: "round",
3162
+ children: /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "20 6 9 17 4 12" })
3163
+ }
3164
+ );
3165
+ }
3166
+ __name(CheckIcon, "CheckIcon");
3167
+ function MultiSelectItem({
3168
+ value,
3169
+ disabled = false,
3170
+ children,
3171
+ className
3172
+ }) {
3173
+ const ctx = useMultiSelectContext("MultiSelectItem");
3174
+ const ref = react.useRef(null);
3175
+ const selected = ctx.value.includes(value);
3176
+ const active = ctx.activeValue === value;
3177
+ react.useEffect(
3178
+ () => ctx.registerItem(value, { label: children, disabled }),
3179
+ [value, disabled, children]
3180
+ );
3181
+ react.useEffect(() => {
3182
+ if (active) ref.current?.scrollIntoView({ block: "nearest" });
3183
+ }, [active]);
3184
+ return /* @__PURE__ */ jsxRuntime.jsxs(
3185
+ "div",
3186
+ {
3187
+ ref,
3188
+ id: ctx.optionId(value),
3189
+ role: "option",
3190
+ "aria-selected": selected,
3191
+ "aria-disabled": disabled || void 0,
3192
+ onMouseEnter: () => !disabled && ctx.setActiveValue(value),
3193
+ onClick: () => !disabled && ctx.toggleValue(value),
3194
+ className: cn(
3195
+ "flex cursor-pointer items-center justify-between rounded-[calc(var(--kui-radii-md)-2px)] px-2.5 py-1.5 text-sm text-text transition-colors",
3196
+ active && "bg-brand/15 text-brand",
3197
+ disabled && "pointer-events-none cursor-not-allowed opacity-50",
3198
+ className
3199
+ ),
3200
+ children: [
3201
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children }),
3202
+ selected && /* @__PURE__ */ jsxRuntime.jsx(CheckIcon, {})
3203
+ ]
3204
+ }
3205
+ );
3206
+ }
3207
+ __name(MultiSelectItem, "MultiSelectItem");
3208
+ function MultiSelect({
3209
+ value: valueProp,
3210
+ defaultValue = [],
3211
+ onValueChange,
3212
+ disabled = false,
3213
+ required,
3214
+ name,
3215
+ variant = "outline",
3216
+ size = "md",
3217
+ placeholder,
3218
+ maxVisibleChips,
3219
+ className,
3220
+ children,
3221
+ error,
3222
+ success,
3223
+ rounded,
3224
+ clearable
3225
+ }) {
3226
+ const autoId = react.useId();
3227
+ const field = useOptionalFormField();
3228
+ const triggerId = field?.id ?? autoId;
3229
+ const contentId = `${triggerId}-listbox`;
3230
+ const [internalValue, setInternalValue] = react.useState(defaultValue);
3231
+ const value = valueProp !== void 0 ? valueProp : internalValue;
3232
+ const [open, setOpen] = react.useState(false);
3233
+ const [activeValue, setActiveValue] = react.useState(void 0);
3234
+ const itemsRef = react.useRef(/* @__PURE__ */ new Map());
3235
+ const [, forceUpdate] = react.useReducer((n) => n + 1, 0);
3236
+ const registerItem = react.useCallback((val, meta) => {
3237
+ itemsRef.current.set(val, meta);
3238
+ forceUpdate();
3239
+ return () => {
3240
+ itemsRef.current.delete(val);
3241
+ forceUpdate();
3242
+ };
3243
+ }, []);
3244
+ const commit = react.useCallback(
3245
+ (next) => {
3246
+ if (valueProp === void 0) setInternalValue(next);
3247
+ onValueChange?.(next);
3248
+ },
3249
+ [valueProp, onValueChange]
3250
+ );
3251
+ const toggleValue = react.useCallback(
3252
+ (v) => commit(value.includes(v) ? value.filter((x) => x !== v) : [...value, v]),
3253
+ [value, commit]
3254
+ );
3255
+ const removeValue = react.useCallback((v) => commit(value.filter((x) => x !== v)), [value, commit]);
3256
+ const handleClear = react.useCallback(() => {
3257
+ commit([]);
3258
+ }, [commit]);
3259
+ const triggerRef = react.useRef(null);
3260
+ const rootRef = react.useRef(null);
3261
+ react.useEffect(() => {
3262
+ if (!open) return;
3263
+ function handlePointerDown(e) {
3264
+ if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
3265
+ }
3266
+ __name(handlePointerDown, "handlePointerDown");
3267
+ document.addEventListener("mousedown", handlePointerDown);
3268
+ return () => document.removeEventListener("mousedown", handlePointerDown);
3269
+ }, [open]);
3270
+ const optionId = react.useCallback((val) => `${contentId}-option-${val}`, [contentId]);
3271
+ const ctxValue = react.useMemo(
3272
+ () => ({
3273
+ value,
3274
+ toggleValue,
3275
+ removeValue,
3276
+ disabled,
3277
+ variant,
3278
+ size,
3279
+ open,
3280
+ setOpen,
3281
+ triggerId,
3282
+ contentId,
3283
+ triggerRef,
3284
+ isInvalid: field?.invalid ?? error ?? false,
3285
+ describedBy: field?.describedBy,
3286
+ required: field?.required ?? required,
3287
+ placeholder,
3288
+ maxVisibleChips,
3289
+ activeValue,
3290
+ setActiveValue,
3291
+ items: itemsRef.current,
3292
+ registerItem,
3293
+ optionId,
3294
+ isSuccess: success,
3295
+ rounded,
3296
+ clearable,
3297
+ onClear: handleClear
3298
+ }),
3299
+ [value, toggleValue, removeValue, disabled, variant, size, open, triggerId, contentId, field?.invalid, field?.describedBy, field?.required, required, placeholder, maxVisibleChips, activeValue, registerItem, optionId, error, success, rounded, clearable, handleClear]
3300
+ );
3301
+ return /* @__PURE__ */ jsxRuntime.jsx(MultiSelectContext.Provider, { value: ctxValue, children: /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: rootRef, className: className ?? "relative w-full", children: [
3302
+ children,
3303
+ name && value.map((v) => /* @__PURE__ */ jsxRuntime.jsx("input", { type: "hidden", name: `${name}[]`, value: v, disabled }, v))
3304
+ ] }) });
3305
+ }
3306
+ __name(MultiSelect, "MultiSelect");
3307
+ MultiSelect.Trigger = MultiSelectTrigger;
3308
+ MultiSelect.Content = MultiSelectContent;
3309
+ MultiSelect.Item = MultiSelectItem;
3310
+
3311
+ // src/theme/defaults/tokens.ts
3312
+ var defaultTokens = {
3313
+ colors: {
3314
+ blue: {
3315
+ 300: { value: "#5EA6ED" },
3316
+ 400: { value: "#4799EB" },
3317
+ 500: { value: "#1A80E6" },
3318
+ 600: { value: "#1773CF" }
3319
+ },
3320
+ red: {
3321
+ 300: { value: "#EB4747" },
3322
+ 400: { value: "#E83030" },
3323
+ 500: { value: "#E61A1A" },
3324
+ 600: { value: "#CF1717" }
3325
+ },
3326
+ green: {
3327
+ 300: { value: "#26D997" },
3328
+ 400: { value: "#22C388" },
3329
+ 500: { value: "#16A249" },
3330
+ 600: { value: "#12875C" }
3331
+ },
3332
+ amber: {
3333
+ 300: { value: "#F7B23B" },
3334
+ 400: { value: "#F6A823" },
3335
+ 500: { value: "#F59F0A" },
3336
+ 600: { value: "#D38909" }
3337
+ },
3338
+ cyan: {
3339
+ 300: { value: "#6CC3EF" },
3340
+ 400: { value: "#47B4EB" },
3341
+ 500: { value: "#1791CF" },
3342
+ 600: { value: "#137BAE" }
3343
+ },
3344
+ gray: {
3345
+ 50: { value: "#FAFAFA" },
3346
+ 100: { value: "#EBEBEB" },
3347
+ 200: { value: "#D9D9D9" },
3348
+ 300: { value: "#BDBDBD" },
3349
+ 400: { value: "#999999" },
3350
+ 500: { value: "#666666" },
3351
+ 600: { value: "#4D4D4D" },
3352
+ 700: { value: "#333333" },
3353
+ 800: { value: "#2E2E2E" },
3354
+ 900: { value: "#1F1F1F" },
3355
+ 950: { value: "#141414" },
3356
+ 1e3: { value: "#0A0A0A" }
3357
+ },
3358
+ white: {
3359
+ value: "#FFFFFF"
3360
+ },
3361
+ black: {
3362
+ value: "#000000"
3363
+ }
3364
+ },
3365
+ spacing: {
3366
+ 1: { value: "0.25rem" },
3367
+ 2: { value: "0.5rem" },
3368
+ 3: { value: "0.75rem" },
3369
+ 4: { value: "1rem" },
3370
+ 5: { value: "1.25rem" },
3371
+ 6: { value: "1.5rem" },
3372
+ 8: { value: "2rem" },
3373
+ 10: { value: "2.5rem" },
3374
+ 12: { value: "3rem" },
3375
+ 16: { value: "4rem" }
3376
+ },
3377
+ radii: {
3378
+ none: { value: "0" },
3379
+ sm: { value: "0.25rem" },
3380
+ md: { value: "0.5rem" },
3381
+ lg: { value: "0.75rem" },
3382
+ xl: { value: "1rem" },
3383
+ full: { value: "9999px" }
3384
+ },
3385
+ fonts: {
3386
+ body: {
3387
+ value: "Inter, sans-serif"
3388
+ },
3389
+ heading: {
3390
+ value: "Inter, sans-serif"
3391
+ },
3392
+ mono: {
3393
+ value: "ui-monospace, SFMono-Regular, Menlo, monospace"
3394
+ }
3395
+ },
3396
+ fontSizes: {
3397
+ xs: { value: "0.75rem" },
3398
+ sm: { value: "0.875rem" },
3399
+ md: { value: "1rem" },
3400
+ lg: { value: "1.125rem" },
3401
+ xl: { value: "1.25rem" },
3402
+ "2xl": { value: "1.5rem" },
3403
+ "3xl": { value: "1.875rem" },
3404
+ "4xl": { value: "2.25rem" }
3405
+ },
3406
+ fontWeights: {
3407
+ normal: { value: "400" },
3408
+ medium: { value: "500" },
3409
+ semibold: { value: "600" },
3410
+ bold: { value: "700" }
3411
+ },
3412
+ lineHeights: {
3413
+ tight: { value: "1.25" },
3414
+ normal: { value: "1.5" },
3415
+ relaxed: { value: "1.75" }
3416
+ },
3417
+ letterSpacings: {
3418
+ tighter: { value: "-0.025em" },
3419
+ tight: { value: "-0.01em" },
3420
+ normal: { value: "0" },
3421
+ wide: { value: "0.025em" }
3422
+ },
3423
+ animations: {
3424
+ "slide-in-right": {
3425
+ value: "slide-in-right 0.5s ease-in-out"
3426
+ }
3427
+ }
3428
+ };
3429
+
3430
+ // src/theme/defaults/semanticTokens.ts
3431
+ var defaultSemanticTokens = {
3432
+ colors: {
3433
+ brand: {
3434
+ value: {
3435
+ light: "{colors.blue.500}",
3436
+ dark: "{colors.blue.400}"
3437
+ }
3438
+ },
3439
+ brandHover: {
3440
+ value: {
3441
+ light: "{colors.blue.600}",
3442
+ dark: "{colors.blue.300}"
3443
+ }
3444
+ },
3445
+ brandFg: {
3446
+ value: "{colors.white}"
3447
+ },
3448
+ surface: {
3449
+ value: {
3450
+ light: "{colors.gray.50}",
3451
+ dark: "{colors.gray.900}"
3452
+ }
3453
+ },
3454
+ surfaceRaised: {
3455
+ value: {
3456
+ light: "{colors.white}",
3457
+ dark: "{colors.gray.800}"
3458
+ }
3459
+ },
3460
+ surfaceSunken: {
3461
+ value: {
3462
+ light: "{colors.gray.100}",
3463
+ dark: "{colors.gray.950}"
3464
+ }
3465
+ },
3466
+ border: {
3467
+ value: {
3468
+ light: "{colors.gray.200}",
3469
+ dark: "{colors.gray.600}"
3470
+ }
3471
+ },
3472
+ text: {
3473
+ value: {
3474
+ light: "{colors.gray.900}",
3475
+ dark: "{colors.gray.50}"
3476
+ }
3477
+ },
3478
+ textMuted: {
3479
+ value: {
3480
+ light: "{colors.gray.500}",
3481
+ dark: "{colors.gray.400}"
3482
+ }
3483
+ },
3484
+ destructive: {
3485
+ value: {
3486
+ light: "{colors.red.500}",
3487
+ dark: "{colors.red.400}"
3488
+ }
3489
+ },
3490
+ destructiveFg: {
3491
+ value: "{colors.white}"
3492
+ },
3493
+ destructiveHover: {
3494
+ value: {
3495
+ light: "{colors.red.600}",
3496
+ dark: "{colors.red.300}"
3497
+ }
3498
+ },
3499
+ success: {
3500
+ value: {
3501
+ light: "{colors.green.500}",
3502
+ dark: "{colors.green.400}"
3503
+ }
3504
+ },
3505
+ successFg: {
3506
+ value: "{colors.white}"
3507
+ },
3508
+ successHover: {
3509
+ value: {
3510
+ light: "{colors.green.600}",
3511
+ dark: "{colors.green.300}"
3512
+ }
3513
+ },
3514
+ warning: {
3515
+ value: {
3516
+ light: "{colors.amber.500}",
3517
+ dark: "{colors.amber.400}"
3518
+ }
3519
+ },
3520
+ warningFg: {
3521
+ value: "{colors.black}"
3522
+ },
3523
+ warningHover: {
3524
+ value: {
3525
+ light: "{colors.amber.600}",
3526
+ dark: "{colors.amber.300}"
3527
+ }
3528
+ },
3529
+ info: {
3530
+ value: {
3531
+ light: "{colors.cyan.500}",
3532
+ dark: "{colors.cyan.400}"
3533
+ }
3534
+ },
3535
+ infoFg: {
3536
+ value: "{colors.white}"
3537
+ },
3538
+ infoHover: {
3539
+ value: {
3540
+ light: "{colors.cyan.600}",
3541
+ dark: "{colors.cyan.300}"
3542
+ }
3543
+ }
3544
+ }
3545
+ };
3546
+
3547
+ // src/theme/defaults/theme.ts
3548
+ var defaultSizes = {
3549
+ xs: {
3550
+ height: "1.75rem",
3551
+ paddingX: "0.5rem",
3552
+ fontSize: "0.75rem",
3553
+ gap: "0.25rem",
3554
+ iconSize: "0.875rem",
3555
+ radius: "0.65rem"
3556
+ },
3557
+ sm: {
3558
+ height: "2rem",
3559
+ paddingX: "0.75rem",
3560
+ fontSize: "0.8125rem",
3561
+ gap: "0.375rem",
3562
+ iconSize: "1rem",
3563
+ radius: "0.8rem"
3564
+ },
3565
+ md: {
3566
+ height: "2.5rem",
3567
+ paddingX: "1rem",
3568
+ fontSize: "0.875rem",
3569
+ gap: "0.5rem",
3570
+ iconSize: "1.125rem",
3571
+ radius: "1rem"
3572
+ },
3573
+ lg: {
3574
+ height: "3rem",
3575
+ paddingX: "1.5rem",
3576
+ fontSize: "1rem",
3577
+ gap: "0.625rem",
3578
+ iconSize: "1.25rem",
3579
+ radius: "1.15rem"
3580
+ }
3581
+ };
3582
+ var defaultTextStyles = {
3583
+ body: {
3584
+ fontFamily: "{fonts.body}",
3585
+ fontSize: "{fontSizes.md}",
3586
+ fontWeight: "{fontWeights.normal}",
3587
+ lineHeight: "{lineHeights.normal}"
3588
+ },
3589
+ bodySmall: {
3590
+ fontFamily: "{fonts.body}",
3591
+ fontSize: "{fontSizes.sm}",
3592
+ fontWeight: "{fontWeights.normal}",
3593
+ lineHeight: "{lineHeights.normal}"
3594
+ },
3595
+ heading: {
3596
+ fontFamily: "{fonts.heading}",
3597
+ fontSize: "{fontSizes.2xl}",
3598
+ fontWeight: "{fontWeights.bold}",
3599
+ lineHeight: "{lineHeights.tight}"
3600
+ },
3601
+ headingSmall: {
3602
+ fontFamily: "{fonts.heading}",
3603
+ fontSize: "{fontSizes.xl}",
3604
+ fontWeight: "{fontWeights.semibold}",
3605
+ lineHeight: "{lineHeights.tight}"
3606
+ },
3607
+ caption: {
3608
+ fontFamily: "{fonts.body}",
3609
+ fontSize: "{fontSizes.xs}",
3610
+ fontWeight: "{fontWeights.normal}",
3611
+ lineHeight: "{lineHeights.normal}"
3612
+ }
3613
+ };
3614
+ var defaultRecipes = {
3615
+ Button: buttonRecipe,
3616
+ FormControl: formControlRecipe,
3617
+ Input: inputRecipe
3618
+ };
3619
+ var defaultTheme = {
3620
+ tokens: defaultTokens,
3621
+ semanticTokens: defaultSemanticTokens,
3622
+ textStyles: defaultTextStyles,
3623
+ recipes: defaultRecipes,
3624
+ intensity: 50,
3625
+ sizes: defaultSizes
3626
+ };
3627
+
3628
+ // src/provider/cssVariables.ts
3629
+ function toKebabCase(str) {
3630
+ return str.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
3631
+ }
3632
+ __name(toKebabCase, "toKebabCase");
3633
+ function colorToRgbChannels(value) {
3634
+ const trimmed = value.trim();
3635
+ const rgbMatch = trimmed.match(
3636
+ /^rgba?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(?:\s*[/,]\s*[\d.]+%?)?\s*\)$/i
3637
+ );
3638
+ if (rgbMatch) {
3639
+ return `${rgbMatch[1]} ${rgbMatch[2]} ${rgbMatch[3]}`;
3640
+ }
3641
+ if (trimmed.startsWith("#")) {
3642
+ const hex = trimmed.slice(1);
3643
+ if (hex.length === 3) {
3644
+ const r = parseInt(hex[0] + hex[0], 16);
3645
+ const g = parseInt(hex[1] + hex[1], 16);
3646
+ const b = parseInt(hex[2] + hex[2], 16);
3647
+ return `${r} ${g} ${b}`;
3648
+ }
3649
+ if (hex.length === 6) {
3650
+ const r = parseInt(hex.slice(0, 2), 16);
3651
+ const g = parseInt(hex.slice(2, 4), 16);
3652
+ const b = parseInt(hex.slice(4, 6), 16);
3653
+ return `${r} ${g} ${b}`;
3654
+ }
3655
+ }
3656
+ if (/^\d+(?:\.\d+)?\s+\d+(?:\.\d+)?\s+\d+(?:\.\d+)?$/.test(trimmed)) {
3657
+ return trimmed;
3658
+ }
3659
+ return value;
3660
+ }
3661
+ __name(colorToRgbChannels, "colorToRgbChannels");
3662
+ function getTokenValue(reference, tokens) {
3663
+ const path = reference.replace(/^\{/, "").replace(/\}$/, "").split(".");
3664
+ let current = tokens;
3665
+ for (const segment of path) {
3666
+ if (typeof current !== "object" || current === null || !(segment in current)) {
3667
+ return void 0;
3668
+ }
3669
+ current = current[segment];
3670
+ }
3671
+ if (typeof current === "object" && current !== null && "value" in current) {
3672
+ const value = current.value;
3673
+ if (typeof value === "string" || typeof value === "number") {
3674
+ return value;
3675
+ }
3676
+ }
3677
+ return void 0;
3678
+ }
3679
+ __name(getTokenValue, "getTokenValue");
3680
+ function resolveReference(reference, tokens, seen = /* @__PURE__ */ new Set()) {
3681
+ if (seen.has(reference)) {
3682
+ console.error(
3683
+ `[kreativ-ui] Circular token reference detected: ${reference}`
3684
+ );
3685
+ return void 0;
3686
+ }
3687
+ const nextSeen = new Set(seen);
3688
+ nextSeen.add(reference);
3689
+ const value = getTokenValue(reference, tokens);
3690
+ if (value === void 0) {
3691
+ console.warn(
3692
+ `[kreativ-ui] Unable to resolve token reference: ${reference}`
3693
+ );
3694
+ return void 0;
3695
+ }
3696
+ if (typeof value === "number") {
3697
+ return String(value);
3698
+ }
3699
+ if (value.startsWith("{") && value.endsWith("}")) {
3700
+ return resolveReference(value, tokens, nextSeen);
3701
+ }
3702
+ return value;
3703
+ }
3704
+ __name(resolveReference, "resolveReference");
3705
+ function resolveValue(value, tokens) {
3706
+ if (typeof value === "number") {
3707
+ return String(value);
3708
+ }
3709
+ if (typeof value !== "string") {
3710
+ return void 0;
3711
+ }
3712
+ if (value.startsWith("{") && value.endsWith("}")) {
3713
+ return resolveReference(value, tokens);
3714
+ }
3715
+ return value;
3716
+ }
3717
+ __name(resolveValue, "resolveValue");
3718
+ function flattenTokens(value, path, result, tokens) {
3719
+ if (typeof value !== "object" || value === null) {
3720
+ return;
3721
+ }
3722
+ if ("value" in value) {
3723
+ const tokenValue = value.value;
3724
+ const resolved = resolveValue(tokenValue, tokens);
3725
+ if (resolved !== void 0) {
3726
+ result[path.join(".")] = resolved;
3727
+ }
3728
+ return;
3729
+ }
3730
+ for (const [key, child] of Object.entries(value)) {
3731
+ flattenTokens(child, [...path, key], result, tokens);
3732
+ }
3733
+ }
3734
+ __name(flattenTokens, "flattenTokens");
3735
+ function resolveSemanticValue(value, mode, tokens) {
3736
+ if (typeof value === "object" && value !== null && "light" in value && "dark" in value) {
3737
+ const modeValue = value[mode];
3738
+ return resolveValue(modeValue, tokens);
3739
+ }
3740
+ return resolveValue(value, tokens);
3741
+ }
3742
+ __name(resolveSemanticValue, "resolveSemanticValue");
3743
+ function resolveSemanticTokens(semanticTokens, tokens, mode) {
3744
+ const result = {};
3745
+ function walk(value, path) {
3746
+ if (typeof value !== "object" || value === null) {
3747
+ return;
3748
+ }
3749
+ if ("value" in value) {
3750
+ const semanticValue = value.value;
3751
+ const resolved = resolveSemanticValue(semanticValue, mode, tokens);
3752
+ if (resolved !== void 0) {
3753
+ result[path.join(".")] = resolved;
3754
+ }
3755
+ return;
3756
+ }
3757
+ for (const [key, child] of Object.entries(
3758
+ value
3759
+ )) {
3760
+ walk(child, [...path, key]);
3761
+ }
3762
+ }
3763
+ __name(walk, "walk");
3764
+ walk(semanticTokens, []);
3765
+ return result;
3766
+ }
3767
+ __name(resolveSemanticTokens, "resolveSemanticTokens");
3768
+ function resolveTokens(tokens, semanticTokens, mode) {
3769
+ const primitiveTokens = {};
3770
+ flattenTokens(tokens, [], primitiveTokens, tokens);
3771
+ const resolvedSemanticTokens = resolveSemanticTokens(
3772
+ semanticTokens,
3773
+ tokens,
3774
+ mode
3775
+ );
3776
+ return {
3777
+ ...primitiveTokens,
3778
+ ...resolvedSemanticTokens
3779
+ };
3780
+ }
3781
+ __name(resolveTokens, "resolveTokens");
3782
+ function tokensToCssVars(tokens, mode, intensity) {
3783
+ const cssVars = {};
3784
+ for (const [path, value] of Object.entries(tokens)) {
3785
+ const parts = path.split(".");
3786
+ const isSemanticColor = parts.length === 2 && parts[0] === "colors";
3787
+ const isPrimitiveColor = parts.length >= 3 && parts[0] === "colors";
3788
+ const varName = isSemanticColor ? `--kui-${toKebabCase(parts[1])}` : `--kui-${parts.map(toKebabCase).join("-")}`;
3789
+ const outputValue = isSemanticColor || isPrimitiveColor ? colorToRgbChannels(value) : value;
3790
+ cssVars[varName] = outputValue;
3791
+ }
3792
+ return {
3793
+ ...cssVars,
3794
+ "--kui-mode": mode,
3795
+ "--kui-intensity": String(intensity)
3796
+ };
3797
+ }
3798
+ __name(tokensToCssVars, "tokensToCssVars");
3799
+
3800
+ // src/theme/mergeTheme.ts
3801
+ var CSS_SIZE = /^-?\d*\.?\d+(px|rem|em|%|vh|vw|vmin|vmax|ch|ex|cm|mm|in|pt|pc|fr)$|^(auto|min-content|max-content|fit-content)$/;
3802
+ var CSS_KEYWORDS = /* @__PURE__ */ new Set([
3803
+ "auto",
3804
+ "min-content",
3805
+ "max-content",
3806
+ "fit-content"
3807
+ ]);
3808
+ var SIZE_FIELDS = [
3809
+ "height",
3810
+ "width",
3811
+ "paddingX",
3812
+ "paddingY",
3813
+ "fontSize",
3814
+ "gap",
3815
+ "iconSize",
3816
+ "radius"
3817
+ ];
3818
+ function isCssKeyword(value) {
3819
+ return CSS_KEYWORDS.has(value);
3820
+ }
3821
+ __name(isCssKeyword, "isCssKeyword");
3822
+ function toPx(value) {
3823
+ if (isCssKeyword(value)) return void 0;
3824
+ const num = parseFloat(value);
3825
+ if (Number.isNaN(num)) return void 0;
3826
+ if (value.endsWith("px")) return num;
3827
+ if (value.endsWith("rem") || value.endsWith("em")) {
3828
+ return num * 16;
3829
+ }
3830
+ return void 0;
3831
+ }
3832
+ __name(toPx, "toPx");
3833
+ function validateSizeToken(key, token) {
3834
+ SIZE_FIELDS.forEach((field) => {
3835
+ const value = token[field];
3836
+ if (value === void 0) return;
3837
+ if (!CSS_SIZE.test(value)) {
3838
+ console.error(
3839
+ `[kreativ-ui] Invalid size "${key}.${field}": "${value}" is not a valid CSS size.`
3840
+ );
3841
+ return;
3842
+ }
3843
+ if (isCssKeyword(value)) return;
3844
+ const num = parseFloat(value);
3845
+ if (num < 0) {
3846
+ console.error(
3847
+ `[kreativ-ui] Invalid size "${key}.${field}": "${value}" is negative.`
3848
+ );
3849
+ }
3850
+ });
3851
+ if (token.height && token.fontSize) {
3852
+ const heightPx = toPx(token.height);
3853
+ const fontSizePx = toPx(token.fontSize);
3854
+ if (heightPx !== void 0 && fontSizePx !== void 0 && fontSizePx >= heightPx) {
3855
+ console.warn(
3856
+ `[kreativ-ui] Size "${key}" has conflicting dimensions: height=${token.height} (${heightPx}px), fontSize=${token.fontSize} (${fontSizePx}px).
3857
+ Font size meets or exceeds the box height \u2014 text may clip or overflow.`
3858
+ );
3859
+ }
3860
+ }
3861
+ }
3862
+ __name(validateSizeToken, "validateSizeToken");
3863
+ function isPlainObject(value) {
3864
+ return typeof value === "object" && value !== null && !Array.isArray(value);
3865
+ }
3866
+ __name(isPlainObject, "isPlainObject");
3867
+ function deepMerge(base, override) {
3868
+ if (override === void 0) {
3869
+ return base;
3870
+ }
3871
+ if (!isPlainObject(base) || !isPlainObject(override)) {
3872
+ return override;
3873
+ }
3874
+ const result = {
3875
+ ...base
3876
+ };
3877
+ for (const [key, value] of Object.entries(override)) {
3878
+ const existing = result[key];
3879
+ if (isPlainObject(existing) && isPlainObject(value)) {
3880
+ result[key] = deepMerge(existing, value);
3881
+ } else {
3882
+ result[key] = value;
3883
+ }
3884
+ }
3885
+ return result;
3886
+ }
3887
+ __name(deepMerge, "deepMerge");
3888
+ function mergeDesignTokens(base, override) {
3889
+ return deepMerge(base, override);
3890
+ }
3891
+ __name(mergeDesignTokens, "mergeDesignTokens");
3892
+ function mergeSemanticTokens(base, override) {
3893
+ return deepMerge(base, override);
3894
+ }
3895
+ __name(mergeSemanticTokens, "mergeSemanticTokens");
3896
+ function mergeTextStyles(base, override) {
3897
+ return deepMerge(base, override);
3898
+ }
3899
+ __name(mergeTextStyles, "mergeTextStyles");
3900
+ function mergeSizes(base, override) {
3901
+ if (!override) {
3902
+ return base;
3903
+ }
3904
+ const merged = {
3905
+ ...base
3906
+ };
3907
+ for (const [key, overrideToken] of Object.entries(override)) {
3908
+ const next = {
3909
+ ...merged[key],
3910
+ ...overrideToken
3911
+ };
3912
+ validateSizeToken(key, next);
3913
+ merged[key] = next;
3914
+ }
3915
+ return merged;
3916
+ }
3917
+ __name(mergeSizes, "mergeSizes");
3918
+ function mergeTheme(base, override) {
3919
+ if (!override) {
3920
+ return base;
3921
+ }
3922
+ return {
3923
+ tokens: mergeDesignTokens(base.tokens, override.tokens),
3924
+ semanticTokens: mergeSemanticTokens(
3925
+ base.semanticTokens,
3926
+ override.semanticTokens
3927
+ ),
3928
+ textStyles: mergeTextStyles(base.textStyles, override.textStyles),
3929
+ recipes: mergeRecipes(base.recipes, override.recipes),
3930
+ intensity: override.intensity ?? base.intensity,
3931
+ sizes: mergeSizes(base.sizes, override.sizes)
3932
+ };
3933
+ }
3934
+ __name(mergeTheme, "mergeTheme");
3935
+ function useSystemPrefersDark() {
3936
+ const [prefersDark, setPrefersDark] = react.useState(
3937
+ () => typeof window !== "undefined" && window.matchMedia("(prefers-color-scheme: dark)").matches
3938
+ );
3939
+ react.useEffect(() => {
3940
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
3941
+ const handleChange = /* @__PURE__ */ __name((event) => {
3942
+ setPrefersDark(event.matches);
3943
+ }, "handleChange");
3944
+ mediaQuery.addEventListener("change", handleChange);
3945
+ return () => {
3946
+ mediaQuery.removeEventListener("change", handleChange);
3947
+ };
3948
+ }, []);
3949
+ return prefersDark;
3950
+ }
3951
+ __name(useSystemPrefersDark, "useSystemPrefersDark");
3952
+ function UIProvider({
3953
+ children,
3954
+ theme: themeOverride,
3955
+ defaultMode = "system",
3956
+ as = "div",
3957
+ fallbackSize = "md"
3958
+ }) {
3959
+ const [mode, setMode] = react.useState(defaultMode);
3960
+ const systemPrefersDark = useSystemPrefersDark();
3961
+ const resolvedMode = mode === "system" ? systemPrefersDark ? "dark" : "light" : mode;
3962
+ const theme = react.useMemo(
3963
+ () => mergeTheme(defaultTheme, themeOverride),
3964
+ [themeOverride]
3965
+ );
3966
+ const resolvedTokens = react.useMemo(
3967
+ () => resolveTokens(theme.tokens, theme.semanticTokens, resolvedMode),
3968
+ [theme.tokens, theme.semanticTokens, resolvedMode]
3969
+ );
3970
+ const cssVars = react.useMemo(
3971
+ () => tokensToCssVars(resolvedTokens, resolvedMode, theme.intensity),
3972
+ [resolvedTokens, resolvedMode, theme.intensity]
3973
+ );
3974
+ react.useEffect(() => {
3975
+ if (isDev() && !theme.sizes[fallbackSize]) {
3976
+ console.error(
3977
+ `[kreativ-ui] fallbackSize="${fallbackSize}" is not a registered size in theme.sizes. Components requesting an unknown size may render without size styles.`
3978
+ );
3979
+ }
3980
+ }, [theme.sizes, fallbackSize]);
3981
+ const contextValue = react.useMemo(
3982
+ () => ({
3983
+ theme,
3984
+ mode,
3985
+ resolvedMode,
3986
+ setMode,
3987
+ fallbackSize,
3988
+ tokens: resolvedTokens
3989
+ }),
3990
+ [theme, mode, resolvedMode, fallbackSize, resolvedTokens]
3991
+ );
3992
+ const Tag = as;
3993
+ return /* @__PURE__ */ jsxRuntime.jsx(ThemeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(
3994
+ Tag,
3995
+ {
3996
+ "data-kreativ-theme": resolvedMode,
3997
+ className: resolvedMode === "dark" ? "dark" : void 0,
3998
+ style: cssVars,
3999
+ children
4000
+ }
4001
+ ) });
4002
+ }
4003
+ __name(UIProvider, "UIProvider");
4004
+
4005
+ exports.Button = Button;
4006
+ exports.Checkbox = Checkbox;
4007
+ exports.Combobox = Combobox;
4008
+ exports.ComboboxContent = ComboboxContent;
4009
+ exports.ComboboxInput = ComboboxInput;
4010
+ exports.ComboboxItem = ComboboxItem;
4011
+ exports.FormField = FormField;
4012
+ exports.FormFieldControl = FormFieldControl;
4013
+ exports.FormFieldDescription = FormFieldDescription;
4014
+ exports.FormFieldLabel = FormFieldLabel;
4015
+ exports.FormFieldMessage = FormFieldMessage;
4016
+ exports.Input = Input;
4017
+ exports.MarkdownEditor = MarkdownEditor;
4018
+ exports.MultiSelect = MultiSelect;
4019
+ exports.MultiSelectContent = MultiSelectContent;
4020
+ exports.MultiSelectContext = MultiSelectContext;
4021
+ exports.MultiSelectItem = MultiSelectItem;
4022
+ exports.MultiSelectTrigger = MultiSelectTrigger;
4023
+ exports.Radio = Radio;
4024
+ exports.RadioGroup = RadioGroup;
4025
+ exports.Select = Select;
4026
+ exports.SelectContent = SelectContent;
4027
+ exports.SelectContext = SelectContext;
4028
+ exports.SelectGroup = SelectGroup;
4029
+ exports.SelectGroupContext = SelectGroupContext;
4030
+ exports.SelectItem = SelectItem;
4031
+ exports.SelectTrigger = SelectTrigger;
4032
+ exports.SelectValue = SelectValue;
4033
+ exports.Switch = Switch;
4034
+ exports.Textarea = Textarea;
4035
+ exports.TextareaCore = TextareaCore;
4036
+ exports.ThemeContext = ThemeContext;
4037
+ exports.ThemeToggler = ThemeToggler;
4038
+ exports.UIProvider = UIProvider;
4039
+ exports.cn = cn;
4040
+ exports.defaultRecipes = defaultRecipes;
4041
+ exports.defaultSizes = defaultSizes;
4042
+ exports.defaultTextStyles = defaultTextStyles;
4043
+ exports.defaultTheme = defaultTheme;
4044
+ exports.hexToRgbString = hexToRgbString;
4045
+ exports.inputKindDefaults = inputKindDefaults;
4046
+ exports.rgbToHex = rgbToHex;
4047
+ exports.tokensToCssVars = tokensToCssVars;
4048
+ exports.useBreakpoint = useBreakpoint;
4049
+ exports.useMultiSelectContext = useMultiSelectContext;
4050
+ exports.useSelectContext = useSelectContext;
4051
+ exports.useSizeStyle = useSizeStyle;
4052
+ exports.useTheme = useTheme;
4053
+ //# sourceMappingURL=index.cjs.map
12
4054
  //# sourceMappingURL=index.cjs.map