shadcn
Version:
Add components to your apps.
34 lines (33 loc) • 169 kB
JavaScript
import {m,f,l,d as d$1,c as c$1,e,n,u,p,b as b$1,q as q$1,r,s,t,z as z$2,B as B$1,x,o,g as g$1}from'./chunk-MTWZIHEW.js';import {a,d,c,b,g,f as f$1}from'./chunk-7SBJAAAY.js';import*as R from'path';import R__default,{join,basename,normalize,delimiter,resolve,dirname}from'path';import {z as z$1}from'zod';import Zn,{promises,existsSync,statSync}from'fs';import {green,cyan,yellow,red}from'kleur/colors';import K from'fs-extra';import Ct from'fast-glob';import {loadConfig,createMatchPath}from'tsconfig-paths';import {cosmiconfig}from'cosmiconfig';import ou,{tmpdir,homedir}from'os';import ga from'ora';import {Project,SyntaxKind,ScriptKind,QuoteKind}from'ts-morph';import {transformFromAstSync}from'@babel/core';import {parse}from'@babel/parser';import Ia from'@babel/plugin-transform-typescript';import*as Pt from'recast';import Da from'prompts';import _e from'deepmerge';import {EnvHttpProxyAgent}from'undici';import {execa}from'execa';import {createHash}from'crypto';import Zc from'stringify-object';import Z,{cwd}from'process';import Jl from'readline';import nu from'events';import*as Qi from'fs/promises';import Qi__default from'fs/promises';import {createRequire}from'module';import {spawn}from'child_process';import {PassThrough}from'stream';import au from'tty';import hh from'fuzzysort';var xe=process.env.REGISTRY_URL??"https://ui.shadcn.com/r",F=xe.replace(/\/r\/?$/,""),dt="new-york-v4",As=[{name:"neutral",label:"Neutral"},{name:"zinc",label:"Zinc"},{name:"stone",label:"Stone"},{name:"mauve",label:"Mauve"},{name:"olive",label:"Olive"},{name:"mist",label:"Mist"},{name:"taupe",label:"Taupe"}],D={"@shadcn":`${xe}/styles/{style}/{name}.json`};var Mh=[{name:"toast",deprecatedBy:"sonner",message:"The toast component is deprecated. Use the sonner component instead."},{name:"toaster",deprecatedBy:"sonner",message:"The toaster component is deprecated. Use the sonner component instead."}];var N={NETWORK_ERROR:"NETWORK_ERROR",NOT_FOUND:"NOT_FOUND",GONE:"GONE",UNAUTHORIZED:"UNAUTHORIZED",FORBIDDEN:"FORBIDDEN",FETCH_ERROR:"FETCH_ERROR",NOT_CONFIGURED:"NOT_CONFIGURED",INVALID_CONFIG:"INVALID_CONFIG",MISSING_ENV_VARS:"MISSING_ENV_VARS",LOCAL_FILE_ERROR:"LOCAL_FILE_ERROR",PARSE_ERROR:"PARSE_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",UNKNOWN_ERROR:"UNKNOWN_ERROR"},j=class extends Error{code;statusCode;context;suggestion;timestamp;cause;constructor(t,r={}){super(t),this.name="RegistryError",this.code=r.code||N.UNKNOWN_ERROR,this.statusCode=r.statusCode,this.cause=r.cause,this.context=r.context,this.suggestion=r.suggestion,this.timestamp=new Date,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);}toJSON(){return {name:this.name,message:this.message,code:this.code,statusCode:this.statusCode,context:this.context,suggestion:this.suggestion,timestamp:this.timestamp,stack:this.stack}}},ve=class extends j{constructor(r,s){let i=`The item at ${r} was not found. It may not exist at the registry.`;super(i,{code:N.NOT_FOUND,statusCode:404,cause:s,context:{url:r},suggestion:"Check if the item name is correct and the registry URL is accessible."});this.url=r;this.name="RegistryNotFoundError";}},pt=class extends j{constructor(r,s){let i=`The item at ${r} is no longer available. It may have been removed or expired.`;super(i,{code:N.GONE,statusCode:410,cause:s,context:{url:r},suggestion:"This resource was previously available but has been permanently removed. Check if a newer version exists or contact the registry maintainer."});this.url=r;this.name="RegistryGoneError";}},We=class extends j{constructor(r,s){let i=`You are not authorized to access the item at ${r}. If this is a remote registry, you may need to authenticate.`;super(i,{code:N.UNAUTHORIZED,statusCode:401,cause:s,context:{url:r},suggestion:"Check your authentication credentials and environment variables."});this.url=r;this.name="RegistryUnauthorizedError";}},He=class extends j{constructor(r,s){let i=`You are not authorized to access the item at ${r}. If this is a remote registry, you may need to authenticate.`;super(i,{code:N.FORBIDDEN,statusCode:403,cause:s,context:{url:r},suggestion:"Check your authentication credentials and environment variables."});this.url=r;this.name="RegistryForbiddenError";}},ze=class extends j{constructor(r,s,i,n){let o=s?`Failed to fetch from registry (${s}): ${r}`:`Failed to fetch from registry: ${r}`,c=typeof n=="string"&&n?`${o} - ${n}`:o,a="Check your network connection and try again.";s===404?a="The requested resource was not found. Check the URL or item name.":s===500?a="The registry server encountered an error. Try again later.":s&&s>=400&&s<500&&(a="There was a client error. Check your request parameters.");super(c,{code:N.FETCH_ERROR,statusCode:s,cause:n,context:{url:r,responseBody:i},suggestion:a});this.url=r;this.responseBody=i;this.name="RegistryFetchError";}},ae=class extends j{constructor(r){let s=r?`Unknown registry "${r}". Make sure it is defined in components.json as follows:
{
"registries": {
"${r}": "[URL_TO_REGISTRY]"
}
}`:'Unknown registry. Make sure it is defined in components.json under "registries".';super(s,{code:N.NOT_CONFIGURED,context:{registryName:r},suggestion:"Add the registry configuration to your components.json file. Consult the registry documentation for the correct format."});this.registryName=r;this.name="RegistryNotConfiguredError";}},ee=class extends j{constructor(r,s,i={}){super(i.message??`Failed to read local registry file: ${r}`,{code:N.LOCAL_FILE_ERROR,cause:s,context:{filePath:r,...i.context},suggestion:i.suggestion??"Check if the file exists and you have read permissions."});this.filePath=r;this.name="RegistryLocalFileError";}},H=class extends j{constructor(r,s,i={}){super(i.message??`Failed to read registry source file: ${r}`,{code:N.FETCH_ERROR,cause:s,context:{filePath:r,...i.context},suggestion:i.suggestion??"Check if the source file exists and is accessible."});this.filePath=r;this.name="RegistrySourceFileError";}},M=class extends j{constructor(r,s,i={}){let n=i.subject??"registry item",o=`Failed to parse ${n}: ${r}`;s instanceof z$1.ZodError&&(o=`Failed to parse ${n}: ${r}
${s.errors.map(c=>` - ${c.path.join(".")}: ${c.message}`).join(`
`)}`);super(o,{code:N.PARSE_ERROR,cause:s,context:{item:r,...i.context},suggestion:i.suggestion??`The registry item may be corrupted or have an invalid format. Please make sure it returns a valid JSON object. See ${F}/schema/registry-item.json.`});this.item=r;this.parseError=s,this.name="RegistryParseError";}parseError},C=class extends j{constructor(t,r={}){super(t,{code:N.VALIDATION_ERROR,cause:r.cause,context:{...r.registryFile?{registryFile:r.registryFile}:{},...r.context},suggestion:r.suggestion??"Update the registry.json file and try running the command again."}),this.name="RegistryValidationError";}},be=class extends j{constructor(r){super(`Registry item "${r}" was not found.`,{code:N.NOT_FOUND,statusCode:404,context:{itemName:r},suggestion:"Check that the item name exists in the resolved registry catalog."});this.itemName=r;this.name="RegistryItemNotFoundError";}},Ve=class extends j{constructor(r,s){let i=`Registry "${r}" requires the following environment variables:
`+s.map(n=>` \u2022 ${n}`).join(`
`);super(i,{code:N.MISSING_ENV_VARS,context:{registryName:r,missingVars:s},suggestion:"Set the required environment variables to your .env or .env.local file."});this.registryName=r;this.missingVars=s;this.name="RegistryMissingEnvironmentVariablesError";}},Ge=class extends j{constructor(r){let s=`Invalid registry namespace: "${r}". Registry names must start with @ (e.g., @shadcn, @v0).`;super(s,{code:N.VALIDATION_ERROR,context:{name:r},suggestion:"Use a valid registry name starting with @ or provide a direct URL to the registry."});this.name=r;this.name="RegistryInvalidNamespaceError";}};var mt=class extends j{constructor(r,s){let i=`Invalid components.json configuration in ${r}.`;s instanceof z$1.ZodError&&(i=`Invalid components.json configuration in ${r}:
${s.errors.map(n=>` - ${n.path.join(".")}: ${n.message}`).join(`
`)}`);super(i,{code:N.INVALID_CONFIG,cause:s,context:{cwd:r},suggestion:"Check your components.json file for syntax errors or invalid configuration. Run 'npx shadcn@latest init' to regenerate a valid configuration."});this.cwd=r;this.name="ConfigParseError";}},Ue=class extends j{parseError;constructor(t){let r="Failed to parse registries index";if(t instanceof z$1.ZodError){let s=t.errors.filter(i=>i.path.length>0).map(i=>`"${i.path[0]}"`).filter((i,n,o)=>o.indexOf(i)===n);s.length>0?r=`Failed to parse registries index. Invalid registry namespace(s): ${s.join(", ")}
${t.errors.map(i=>` - ${i.path.join(".")}: ${i.message}`).join(`
`)}`:r=`Failed to parse registries index:
${t.errors.map(i=>` - ${i.path.join(".")}: ${i.message}`).join(`
`)}`;}super(r,{code:N.PARSE_ERROR,cause:t,context:{parseError:t},suggestion:"The registries index may be corrupted or have invalid registry namespace format. Registry names must start with @ (e.g., @shadcn, @example)."}),this.parseError=t,this.name="RegistriesIndexParseError";}};var Ro=/^(@[a-zA-Z0-9](?:[a-zA-Z0-9-_]*[a-zA-Z0-9])?)\/(.+)$/;function ce(e){if(!e.startsWith("@"))return {registry:null,item:e};let t=e.match(Ro);return t?{registry:t[1],item:t[2]}:{registry:null,item:e}}var z={"next-app":{name:"next-app",label:"Next.js",links:{installation:`${F}/docs/installation/next`,tailwind:"https://tailwindcss.com/docs/guides/nextjs"}},"next-pages":{name:"next-pages",label:"Next.js",links:{installation:`${F}/docs/installation/next`,tailwind:"https://tailwindcss.com/docs/guides/nextjs"}},remix:{name:"remix",label:"Remix",links:{installation:`${F}/docs/installation/remix`,tailwind:"https://tailwindcss.com/docs/guides/remix"}},"react-router":{name:"react-router",label:"React Router",links:{installation:`${F}/docs/installation/react-router`,tailwind:"https://tailwindcss.com/docs/installation/framework-guides/react-router"}},vite:{name:"vite",label:"Vite",links:{installation:`${F}/docs/installation/vite`,tailwind:"https://tailwindcss.com/docs/guides/vite"}},astro:{name:"astro",label:"Astro",links:{installation:`${F}/docs/installation/astro`,tailwind:"https://tailwindcss.com/docs/guides/astro"}},laravel:{name:"laravel",label:"Laravel",links:{installation:`${F}/docs/installation/laravel`,tailwind:"https://tailwindcss.com/docs/guides/laravel"}},"tanstack-start":{name:"tanstack-start",label:"TanStack Start",links:{installation:`${F}/docs/installation/tanstack`,tailwind:"https://tailwindcss.com/docs/installation/using-postcss"}},gatsby:{name:"gatsby",label:"Gatsby",links:{installation:`${F}/docs/installation/gatsby`,tailwind:"https://tailwindcss.com/docs/guides/gatsby"}},expo:{name:"expo",label:"Expo",links:{installation:`${F}/docs/installation/expo`,tailwind:"https://www.nativewind.dev/docs/getting-started/installation"}},manual:{name:"manual",label:"Manual",links:{installation:`${F}/docs/installation/manual`,tailwind:"https://tailwindcss.com/docs/installation"}}};var T={error:red,warn:yellow,info:cyan,success:green};function gt(e){let t=[e];for(;t.length;){let r=t.shift();if(typeof r=="string"){if(r.startsWith("./"))return r;continue}if(Array.isArray(r)){t.unshift(...r);continue}r&&typeof r=="object"&&t.unshift(...Object.values(r));}return null}function yt(e){if(!e.includes("*"))return "strip_extension";let t=e.slice(e.indexOf("*")+1);return t&&/^\.[^/]+$/.test(t)?"strip_extension":"preserve_extension"}function wt(e,t){let r=t.find(i=>!i.hasWildcard&&i.key===e);if(r)return {path:R__default.resolve(r.rootDir,r.target),matchedAlias:r.key,matchedTarget:r.target,emitMode:r.emitMode};let s=t.filter(i=>i.hasWildcard).sort((i,n)=>n.key.length-i.key.length);for(let i of s){let n=Bt(e,i.key,{allowBareAliasBase:true});if(n!==null)return {path:R__default.resolve(i.rootDir,$o(i.target,n)),matchedAlias:i.key,matchedTarget:i.target,emitMode:i.emitMode}}return null}function Bt(e,t,r={}){if(!t.includes("*"))return e===t?"":null;let[s,i=""]=t.split("*");return e.startsWith(s)&&e.endsWith(i)?i?e.slice(s.length,-i.length):e.slice(s.length):r.allowBareAliasBase&&i===""&&s.endsWith("/")&&e===s.slice(0,-1)?"":null}function $o(e,t){if(!e.includes("*"))return e;let[r,s=""]=e.split("*");return t?`${r}${t}${s}`:r.replace(/\/$/,"")}function le(e="",t=true){let r=R__default.join(e,"package.json");return K.readJSONSync(r,{throws:t})}var Jt=new Map;function Yt(e){let t=R__default.resolve(e),r=Jt.get(t);if(r)return r;let i=le(e,false)?.imports;if(!i||typeof i!="object"||Array.isArray(i))return Jt.set(t,[]),[];let n=[];for(let[o,c]of Object.entries(i)){if(!o.startsWith("#"))continue;let a=gt(c);a&&n.push({key:o,aliasBase:o==="#*"?"#":o.endsWith("/*")?o.slice(0,-2):o,target:a,emitMode:yt(a),hasWildcard:o.includes("*"),rootDir:t});}return Jt.set(t,n),n}function js(e){let t=Yt(e).map(r=>r.aliasBase);return t.length?jo(t):null}function qe(e,t){return wt(e,Yt(t))}function _s(e){let t=Yt(e),r=t.some(s=>s.key==="#*")?{components:"#components",ui:"#components/ui",lib:"#lib",hooks:"#hooks",utils:"#lib/utils"}:null;return {components:Ke(t,"components")??r?.components,ui:Ke(t,"ui")??r?.ui,lib:Ke(t,"lib")??r?.lib,hooks:Ke(t,"hooks")??r?.hooks,utils:Ke(t,"utils")??r?.utils}}function Ke(e,t){return e.map(s=>({entry:s,score:Ao(s,t)})).filter(s=>s.score>0).sort((s,i)=>i.score-s.score||i.entry.aliasBase.length-s.entry.aliasBase.length)[0]?.entry.aliasBase}function Ao(e,t){let r=e.aliasBase.toLowerCase(),s=Oo(e.target).toLowerCase();switch(t){case "components":return r.endsWith("/ui")||s.includes("/components/ui")?0:xt(r,"components")?4:xt(s,"components")?3:0;case "ui":return r.endsWith("/ui")||r==="#ui"?5:s.includes("/components/ui")?4:s.endsWith("/ui")?3:0;case "lib":return r==="#lib"||r.endsWith("/lib")?5:s.endsWith("/lib")?4:xt(s,"lib")?3:0;case "hooks":return r==="#hooks"||r.endsWith("/hooks")?5:s.endsWith("/hooks")?4:xt(s,"hooks")?3:0;case "utils":return r==="#utils"||r.endsWith("/utils")?5:s.endsWith("/lib/utils")?4:s.endsWith("/utils")?3:0}}function Oo(e){return e.replace(/\/\*$/,"").replace(/\*$/,"").replace(/\/index\.[^/]+$/,"")}function xt(e,t){return e===t||e.includes(`/${t}`)||e.includes(`${t}/`)}function jo(e){let t=e.map(r=>r.slice(1).split("/").filter(Boolean)).reduce((r,s,i)=>i?r.filter((n,o)=>s[o]===n):s,[]);return t.length?`#${t.join("/")}`:"#"}var S={error(...e){console.log(T.error(e.join(" ")));},warn(...e){console.log(T.warn(e.join(" ")));},info(...e){console.log(T.info(e.join(" ")));},success(...e){console.log(T.success(e.join(" ")));},log(...e){console.log(e.join(" "));},break(){console.log("");}};var _o=["next.config.*","vite.config.*","astro.config.*","remix.config.*","nuxt.config.*","svelte.config.*","gatsby-config.*","angular.json"];async function lf(e){if(K.existsSync(R__default.resolve(e,"pnpm-workspace.yaml")))return true;let t=R__default.resolve(e,"package.json");if(K.existsSync(t))try{if((await K.readJson(t)).workspaces)return !0}catch{}return !!(K.existsSync(R__default.resolve(e,"lerna.json"))||K.existsSync(R__default.resolve(e,"nx.json")))}async function uf(e){let t=await vt(e);if(!t.length)return [];let r=await Ct(t,{cwd:e,onlyDirectories:true,ignore:["**/node_modules/**"]}),s=[];for(let i of r){let n=R__default.resolve(e,i);if(!K.existsSync(R__default.resolve(n,"package.json")))continue;let o=K.existsSync(R__default.resolve(n,"components.json")),c=_o.some(a=>Ct.sync(a,{cwd:n,dot:true}).length>0);(o||c)&&s.push({name:i,hasConfig:o});}return s}function hf(e,t,r){let s=r?.cwdFlag??"-c";S.break(),S.log(`It looks like you are running ${T.info(e)} from a monorepo root.`),S.log(`To use shadcn in a specific workspace, use the ${T.info(s)} flag:`),S.break();for(let i of t)S.log(` shadcn ${e} ${s} ${i.name}`);S.break();}async function vt(e){let t=[],r=R__default.resolve(e,"pnpm-workspace.yaml");if(K.existsSync(r)){let i=await K.readFile(r,"utf8");t.push(...No(i));}let s=R__default.resolve(e,"package.json");if(K.existsSync(s))try{let i=await K.readJson(s),n=Array.isArray(i.workspaces)?i.workspaces:i.workspaces?.packages;Array.isArray(n)&&t.push(...n.filter(o=>!o.startsWith("!")));}catch{}return Array.from(new Set(t))}function No(e){let t=[],r=false,s=0;for(let i of e.split(`
`)){let n=i.trim();if(!n||n.startsWith("#"))continue;let o=i.match(/^(\s*)([A-Za-z0-9_-]+)\s*:/);if(o){s=o[1].length,r=o[2]==="packages";continue}if(!r)continue;let c=i.match(/^(\s*)-\s*(.+?)\s*(?:#.*)?$/);!c||c[1].length<=s||t.push(c[2].trim().replace(/^["']|["']$/g,""));}return t}var Ms=new Map,Zt=new Map,bt=new Map;async function Ls(e,t){let r=Vo(e);if(!r)return null;let s=await Do(t,r.packageName);return s?wt(e,Fo(s)):null}function Fo(e){let t=`${e.packageRoot}:${e.packageName}`,r=Zt.get(t);if(r)return r;let i=le(e.packageRoot,false)?.exports;if(!i||typeof i!="object"||Array.isArray(i))return Zt.set(t,[]),[];let n=[];for(let[o,c]of Object.entries(i)){if(o!=="."&&!o.startsWith("./"))continue;let a=gt(c);if(!a)continue;let h=Go(e.packageName,o);n.push({key:o.includes("*")?`${h}/*`:h,aliasBase:h,target:a,emitMode:yt(a),hasWildcard:o.includes("*"),rootDir:e.packageRoot});}return Zt.set(t,n),n}async function Do(e,t){let r=await Ho(e);if(!r)return null;let s=Ms.get(r);if(s?.has(t))return s.get(t)??null;let i=await Wo(r);return Ms.set(r,i),i.get(t)??null}async function Wo(e){let t=await vt(e),r=new Map;if(!t.length)return r;let s=await Ct(t.map(i=>R__default.posix.join(i.split(R__default.sep).join("/"),"package.json")),{cwd:e,ignore:["**/node_modules/**"]});for(let i of s){let n=R__default.resolve(e,R__default.dirname(i)),c=le(n,false)?.name;c&&r.set(c,{packageName:c,packageRoot:n});}return r}async function Ho(e){let t=R__default.resolve(e),r=bt.get(t);if(r!==void 0)return r;let s=t,i=await zo(t);for(;;){if((await vt(s)).length)return bt.set(t,s),s;if(i&&s===i)return bt.set(t,null),null;let o=R__default.dirname(s);if(o===s)return bt.set(t,null),null;s=o;}}async function zo(e){let t=R__default.resolve(e);for(;;){if(K.existsSync(R__default.resolve(t,".git")))return t;let r=R__default.dirname(t);if(r===t)return null;t=r;}}function Vo(e){if(e.startsWith("#")||e.startsWith(".")||R__default.isAbsolute(e))return null;let t=e.split("/");return e.startsWith("@")?t.length<2?null:{packageName:`${t[0]}/${t[1]}`}:{packageName:t[0]}}function Go(e,t){if(t===".")return e;let r=t.slice(2).replace(/\/\*$/,"");return r?`${e}/${r}`:e}async function Rt(e,t){let r=t.cwd??t.absoluteBaseUrl;if(e.startsWith("#")){let i=qe(e,r);if(i)return {path:i.path,source:"package_imports",matchedAlias:i.matchedAlias,matchedTarget:i.matchedTarget,emitMode:i.emitMode}}let s=await Ls(e,r);return s?{path:s.path,source:"workspace_package_exports",matchedAlias:s.matchedAlias,matchedTarget:s.matchedTarget,emitMode:s.emitMode}:qo(e,t)}function Fs(e,t){return e.startsWith("#")?true:t?e.startsWith(`${t}/`):false}function Ko(e){return /^@[^/]+\/[^/]+(?:\/.*)?$/.test(e)}function qo(e,t){let r=createMatchPath(t.absoluteBaseUrl,t.paths)(e,void 0,()=>true,[".ts",".tsx",".jsx",".js",".css"]);if(!r)return null;let s=Bo(e,t.paths);return !s&&Ko(e)?null:{path:r,source:"tsconfig_paths",matchedAlias:s?.key??e,matchedTarget:s?.target??r,emitMode:"strip_extension"}}function Bo(e,t){for(let[r,s]of Object.entries(t)){let i=Array.isArray(s)?s:[s],n=Bt(e,r);if(n!==null)return {key:r,target:i[0]?.includes("*")&&n!==null?i[0].replace(/\*/g,n):i[0]}}return null}var _f="@/components",Nf="@/lib/utils",Mf="app/globals.css",Lf="tailwind.config.js";var Et=cosmiconfig("components",{searchPlaces:["components.json"]});async function Je(e){let t=await Qo(e);return t?(t.iconLibrary||(t.iconLibrary=t.style==="new-york"?"radix":"lucide"),await It(e,t)):null}async function It(e,t){t.registries={...D,...t.registries||{}};let r=await loadConfig(e);if(r.resultType==="failed")throw new Error(`Failed to load ${t.tsx?"tsconfig":"jsconfig"}.json. ${r.message??""}`.trim());let s=await Be("utils",t.aliases.utils,e,r),i=await Be("components",t.aliases.components,e,r),n=t.aliases.ui?await Be("ui",t.aliases.ui,e,r):R__default.resolve(i??e,"ui"),o=t.aliases.lib?await Be("lib",t.aliases.lib,e,r):R__default.resolve(s??e,".."),c=t.aliases.hooks?await Be("hooks",t.aliases.hooks,e,r):R__default.resolve(i??e,"..","hooks");return Xo(e,{components:i,utils:s,ui:n,lib:o,hooks:c}),d$1.parse({...t,resolvedPaths:{cwd:e,tailwindConfig:t.tailwind.config?R__default.resolve(e,t.tailwind.config):"",tailwindCss:R__default.resolve(e,t.tailwind.css),utils:s,components:i,ui:n,lib:o,hooks:c}})}async function Be(e,t,r,s){let i=await Rt(t,{...s,cwd:r});if(!i?.path||t.startsWith("#")&&i.path===R__default.resolve(r,t))return null;if(e!=="utils"&&(i.source==="package_imports"||i.source==="workspace_package_exports")){if(!i.matchedAlias.includes("*")&&/\/index\.[^/]+$/.test(i.path))return R__default.dirname(i.path);if(i.matchedAlias.includes("*")&&/\.[^/]+$/.test(i.path))return i.path.replace(/\.[^/]+$/,"")}return i.path}function Xo(e,t){let r=["components","ui","lib","hooks","utils"].filter(s=>!t[s]);if(r.length)throw new Error([`Could not resolve the following aliases in ${T.info(e)}: ${T.info(r.join(", "))}.`,`Configure path aliases in ${T.info("tsconfig.json")} or imports in ${T.info("package.json")} for this workspace and try again.`].join(`
`))}async function Qo(e){try{let t=await Et.search(e);if(!t)return null;let r=c$1.parse(t.config);if(r.registries){for(let s of Object.keys(r.registries))if(s in D)throw new Error(`"${s}" is a built-in registry and cannot be overridden.`)}return r}catch(t){let r=`${e}/components.json`;throw t instanceof Error&&t.message.includes("reserved registry")?t:new Error(`Invalid configuration found in ${T.info(r)}.`)}}async function Ff(e$1){let t={};for(let s of Object.keys(e$1.aliases)){if(!ta(s,e$1))continue;let i=e$1.resolvedPaths[s],n=await ea(e$1.resolvedPaths.cwd,i);if(!n){t[s]=e$1;continue}let o=await Je(n);if(!o)throw new Error([`Could not load the workspace config in ${T.info(n)}.`,`Add ${T.info("components.json")} to this workspace and configure its path aliases or package imports, then try again.`].join(`
`));t[s]=o;}let r=e.safeParse(t);return r.success?r.data:null}async function ea(e,t){let r=ra(e,t),s=R__default.relative(r,t),n=(await Ct.glob("**/package.json",{cwd:r,deep:3,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/public/**"]})).map(o=>R__default.dirname(o)).find(o=>s.startsWith(o));return n?R__default.join(r,n):null}function ta(e,t){return Object.keys(t.resolvedPaths).filter(r=>r!=="utils").includes(e)}function ra(e,t){let r=e.split(R__default.sep),s=t.split(R__default.sep),i=[];for(let n=0;n<Math.min(r.length,s.length)&&r[n]===s[n];n++)i.push(r[n]);return i.join(R__default.sep)}async function Ds(e,t){return (await re(e))?.tailwindVersion==="v4"?"new-york-v4":t}function Df(e){return e===void 0||e.startsWith("base-")?"base":"radix"}function Ws(e){let t={resolvedPaths:{cwd:process.cwd(),tailwindConfig:"",tailwindCss:"",utils:"",components:"",ui:"",lib:"",hooks:""},style:"",tailwind:{config:"",css:"",baseColor:"",cssVariables:false},rsc:false,tsx:true,aliases:{components:"",utils:""},registries:{...D}};return e?{...t,...e,resolvedPaths:{...t.resolvedPaths,...e.resolvedPaths||{}},tailwind:{...t.tailwind,...e.tailwind||{}},aliases:{...t.aliases,...e.aliases||{}},registries:{...t.registries,...e.registries||{}}}:t}var $t=["**/node_modules/**",".next","public","dist","build"],na=z$1.object({compilerOptions:z$1.object({paths:z$1.record(z$1.string().or(z$1.array(z$1.string())))})});async function re(e,t){let[r,s,i,n,o,c,a,h]=await Promise.all([Ct.glob("**/{next,vite,astro,app}.config.*|gatsby-config.*|composer.json|react-router.config.*",{cwd:e,deep:3,ignore:$t}),K.pathExists(R__default.resolve(e,"src")),ua(e),ca(e),aa(e,t?.configCssFile),Hs(e),zs(e),le(e,false)]),l=await K.pathExists(R__default.resolve(e,`${s?"src/":""}app`)),u={framework:z.manual,isSrcDir:s,isRSC:false,isTsx:i,tailwindConfigFile:n,tailwindCssFile:o,tailwindVersion:c,frameworkVersion:null,aliasPrefix:a.prefix};if(r.find(f=>f.startsWith("next.config."))?.length)return u.framework=l?z["next-app"]:z["next-pages"],u.isRSC=l,u.frameworkVersion=await oa(u.framework,h),u;if(r.find(f=>f.startsWith("astro.config."))?.length)return u.framework=z.astro,u;if(r.find(f=>f.startsWith("gatsby-config."))?.length)return u.framework=z.gatsby,u;if(r.find(f=>f.startsWith("composer.json"))?.length)return u.framework=z.laravel,u;if(Object.keys(h?.dependencies??{}).find(f=>f.startsWith("@remix-run/")))return u.framework=z.remix,u;if([...Object.keys(h?.dependencies??{}),...Object.keys(h?.devDependencies??{})].find(f=>f.startsWith("@tanstack/react-start")))return u.framework=z["tanstack-start"],u;if(r.find(f=>f.startsWith("react-router.config."))?.length)return u.framework=z["react-router"],u;if(r.find(f=>f.startsWith("vite.config."))?.length)return u.framework=z.vite,u;let d=r.find(f=>f.startsWith("app.config"));return d?.length&&(await K.readFile(R__default.resolve(e,d),"utf8")).includes("defineConfig")?(u.framework=z.vite,u):(h?.dependencies?.expo&&(u.framework=z.expo),u)}async function oa(e,t){if(!t||!["next-app","next-pages"].includes(e.name))return null;let r=t.dependencies?.next||t.devDependencies?.next;if(!r)return null;let s=r.match(/^[\^~]?(\d+\.\d+\.\d+)/);if(s)return s[1];let i=r.match(/(\d+\.\d+\.\d+)/);return i?i[1]:r}async function Hs(e){let[t,r]=await Promise.all([le(e,false),Je(e)]);return r?.tailwind?.config===""?"v4":!t?.dependencies?.tailwindcss&&!t?.devDependencies?.tailwindcss?null:/^(?:\^|~)?3(?:\.\d+)*(?:-.*)?$/.test(t?.dependencies?.tailwindcss||t?.devDependencies?.tailwindcss||"")?"v3":"v4"}async function aa(e,t){if(t){let n=R__default.resolve(e,t);if(await K.pathExists(n))return t}let[r,s]=await Promise.all([Ct.glob(["**/*.css","**/*.scss"],{cwd:e,deep:5,ignore:$t}),Hs(e)]);if(!r.length)return null;for(let n of r){let o=await K.readFile(R__default.resolve(e,n),"utf8");if(o.includes('@import "tailwindcss"')||o.includes("@import 'tailwindcss'")||o.includes("@tailwind base"))return n}return null}async function ca(e){let t=await Ct.glob("tailwind.config.*",{cwd:e,deep:3,ignore:$t});return t.length?t[0]:null}async function la(e){let t=await loadConfig(e),r=t?.resultType==="success"&&Object.entries(t.paths).length?t.paths:(await ha(e))?.compilerOptions.paths;if(!r||!Object.entries(r).length)return null;for(let[s,i]of Object.entries(r)){let n=Array.isArray(i)?i:[i];if(n.includes("./*")||n.includes("./src/*")||n.includes("./app/*")||n.includes("./resources/js/*"))return s.replace(/\/\*$/,"")??null}return Object.keys(r)?.[0].replace(/\/\*$/,"")??null}async function zs(e){let t=await la(e),r=js(e);return r&&t?.startsWith("#")?{prefix:r,source:"package_imports"}:t?{prefix:t,source:"tsconfig_paths"}:r?{prefix:r,source:"package_imports"}:{prefix:null,source:null}}async function ua(e){return (await Ct.glob("tsconfig.*",{cwd:e,deep:1,ignore:$t})).length>0}async function ha(e){for(let t of ["tsconfig.json","tsconfig.web.json","tsconfig.app.json"]){let r=R__default.resolve(e,t);if(!await K.pathExists(r))continue;let s=await K.readFile(r,"utf8"),i;try{i=JSON.parse(fa(s));}catch{continue}let n=na.safeParse(i);if(!n.error)return n.data}return null}function fa(e){let t="",r=false,s=false;for(let i=0;i<e.length;i++){let n=e[i],o=e[i+1];if(r){if(t+=n,s){s=false;continue}if(n==="\\"){s=true;continue}n==='"'&&(r=false);continue}if(n==='"'){r=true,t+=n;continue}if(n==="/"&&o==="/"){for(;i<e.length&&e[i]!==`
`;)i++;i<e.length&&(t+=e[i]);continue}if(n==="/"&&o==="*"){for(i+=2;i<e.length;){if(e[i]==="*"&&e[i+1]==="/"){i++;break}e[i]===`
`&&(t+=`
`),i++;}continue}if(n===","){let c=i+1;for(;c<e.length;){for(;/\s/.test(e[c]??"");)c++;if(e[c]==="/"&&e[c+1]==="/"){for(c+=2;c<e.length&&e[c]!==`
`&&e[c]!=="\r";)c++;continue}if(e[c]==="/"&&e[c+1]==="*"){for(c+=2;c<e.length&&!(e[c]==="*"&&e[c+1]==="/");)c++;c+=2;continue}break}if(e[c]==="}"||e[c]==="]")continue}t+=n;}return t}async function ed(e,t=null){let[r,s,i]=await Promise.all([Je(e),t?Promise.resolve(t):re(e),zs(e)]);if(r)return r;if(!s||!s.tailwindCssFile||s.tailwindVersion==="v3"&&!s.tailwindConfigFile)return null;let n=i.source==="package_imports"?_s(e):null;if(!s.aliasPrefix)return null;let o=da(s.aliasPrefix,i.source==="package_imports"),c=i.source==="package_imports"&&n?pa({...o,components:n.components??o.components,ui:n.ui??o.ui,hooks:n.hooks??o.hooks,lib:n.lib??o.lib,utils:n.utils??o.utils}):o;if(!c.components||!c.utils)return null;let a={$schema:"https://ui.shadcn.com/schema.json",rsc:s.isRSC,tsx:s.isTsx,style:"new-york",tailwind:{config:s.tailwindConfigFile??"",baseColor:"zinc",css:s.tailwindCssFile,cssVariables:true,prefix:""},iconLibrary:"lucide",aliases:c};return await It(e,a)}function da(e,t=false){return t&&e==="#"?{components:"",ui:void 0,hooks:void 0,lib:void 0,utils:""}:{components:`${e}/components`,ui:`${e}/components/ui`,hooks:`${e}/hooks`,lib:`${e}/lib`,utils:`${e}/lib/utils`}}function pa(e){let t={...e};return !t.ui&&t.components&&(t.ui=`${t.components}/ui`),!t.lib&&t.utils.endsWith("/utils")&&(t.lib=t.utils.slice(0,-6)),!t.utils&&t.lib&&(t.utils=`${t.lib}/utils`),t}async function kt(e){if(!e.resolvedPaths?.cwd)return "v3";let t=await re(e.resolvedPaths.cwd);return t?.tailwindVersion?t.tailwindVersion:null}async function td(e){let t=await Je(e);if(!t)return [];let s=(await It(e,t)).resolvedPaths.ui;if(!K.existsSync(s))return [];let i=await St(),n=new Set(i?.map(c=>c.name)??[]);return (await promises.readdir(s)).filter(c=>/\.(tsx|jsx)$/.test(c)).map(c=>R__default.basename(c,R__default.extname(c))).filter(c=>n.has(c))}function Vs(e,t,r={}){let{ignoreImports:s=false}=r,i=e.replace(/\r\n/g,`
`).trim(),n=t.replace(/\r\n/g,`
`).trim();if(i===n)return true;if(!s)return false;let o=/^(import\s+(?:type\s+)?(?:\*\s+as\s+\w+|\{[^}]*\}|\w+)?(?:\s*,\s*(?:\{[^}]*\}|\w+))?\s+from\s+["'])([^"']+)(["'])/gm,c=l=>l.replace(o,(u,d,f,p)=>{if(f.startsWith("."))return `${d}${f}${p}`;let y=f.split("/"),m=y[y.length-1];return `${d}@normalized/${m}${p}`}),a=c(i),h=c(n);return a===h}function Re(e){let t=R__default.basename(e);return /^\.env(\.|$)/.test(t)}function Us(e){let t=[".env.local",".env",".env.development.local",".env.development"];for(let r of t){let s=R__default.join(e,r);if(existsSync(s))return s}return null}function Pe(e){let t=e.split(`
`),r={};for(let s of t){let i=s.trim();if(!i||i.startsWith("#"))continue;let n=i.indexOf("=");if(n===-1)continue;let o=i.substring(0,n).trim(),c=i.substring(n+1).trim();o&&(r[o]=c.replace(/^["']|["']$/g,""));}return r}function Ks(e,t){let r=Pe(e),s=Pe(t),i=[];for(let n of Object.keys(s))n in r||i.push(n);return i}function qs(e,t){let r=Pe(e),s=Pe(t),i=e.trimEnd();i&&!i.endsWith(`
`)&&(i+=`
`);let n=[];for(let[o,c]of Object.entries(s))o in r||n.push(`${o}=${c}`);return n.length>0?(i&&(i+=`
`),i+=n.join(`
`),i+`
`):i&&!i.endsWith(`
`)?i+`
`:i}function Ee(e,t){return ga({text:e,isSilent:t?.silent})}var Tt=async({sourceFile:e,config:t,isRemote:r})=>{let s=t.aliases?.utils,i=typeof s=="string"?xa(s):"@",n=i?`${i}/lib/utils`:"@/lib/utils";if(![".tsx",".ts",".jsx",".js"].includes(e.getExtension()))return e;for(let o of e.getImportStringLiterals()){let c=wa(o.getLiteralValue(),t,r);if(o.setLiteralValue(c),n===c||c==="@/lib/utils"){if(!o.getFirstAncestorByKind(SyntaxKind.ImportDeclaration)?.getNamedImports().some(l=>l.getName()==="cn")||!t.aliases.utils)continue;o.setLiteralValue(n===c?c.replace(n,t.aliases.utils):t.aliases.utils);}}return e};function wa(e,t,r=false){if(e=va(e,t),!e.startsWith("@/")&&!r)return e;if(r&&e.startsWith("@/")&&(e=e.replace(/^@\//,"@/registry/new-york/")),e==="@/registry")return t.aliases.components;if(!e.startsWith("@/registry/")){if(e==="@/lib/utils"&&t.aliases.utils)return t.aliases.utils;if(t.aliases.ui&&e.match(/^@\/components\/ui(?=\/|$)/))return e.replace(/^@\/components\/ui/,t.aliases.ui);if(t.aliases.components&&e.match(/^@\/components(?=\/|$)/))return e.replace(/^@\/components/,t.aliases.components);if(t.aliases.hooks&&e.match(/^@\/hooks(?=\/|$)/))return e.replace(/^@\/hooks/,t.aliases.hooks);if(t.aliases.lib&&e.match(/^@\/lib(?=\/|$)/))return e.replace(/^@\/lib/,t.aliases.lib);let s=t.aliases.components.split("/")[0];return e.replace(/^@\//,`${s}/`)}return e.match(/^@\/registry\/(.+)\/ui/)?e.replace(/^@\/registry\/(.+)\/ui/,t.aliases.ui??`${t.aliases.components}/ui`):t.aliases.utils&&e.match(/^@\/registry\/(.+)\/lib\/utils$/)?t.aliases.utils:t.aliases.components&&e.match(/^@\/registry\/(.+)\/components/)?e.replace(/^@\/registry\/(.+)\/components/,t.aliases.components):t.aliases.lib&&e.match(/^@\/registry\/(.+)\/lib/)?e.replace(/^@\/registry\/(.+)\/lib/,t.aliases.lib):t.aliases.hooks&&e.match(/^@\/registry\/(.+)\/hooks/)?e.replace(/^@\/registry\/(.+)\/hooks/,t.aliases.hooks):e.replace(/^@\/registry\/[^/]+/,t.aliases.components)}function xa(e){if(e.startsWith("#"))return "";if(e.endsWith("/lib/utils"))return e.slice(0,-10);if(e.startsWith("@")){let[r,s]=e.split("/");return r&&s?`${r}/${s}`:e}let t=e.indexOf("/");return t===-1?e:e.slice(0,t)}function va(e,t){if(e==="#registry")return "@/registry";if(e.startsWith("#/"))return e.replace(/^#\//,"@/");if(e.startsWith("#registry/"))return e.replace(/^#registry\//,"@/registry/");for(let{alias:r,normalized:s}of ba(t)){if(e===r)return s;if(e.startsWith(`${r}/`))return `${s}${e.slice(r.length)}`}return e}function ba(e){return e.aliases?[{alias:e.aliases.ui,normalized:"@/components/ui"},{alias:e.aliases.components,normalized:"@/components"},{alias:e.aliases.hooks,normalized:"@/hooks"},{alias:e.aliases.lib,normalized:"@/lib"},{alias:e.aliases.utils,normalized:"@/lib/utils"}].filter(t=>typeof t.alias=="string"&&t.alias.startsWith("#")).sort((t,r)=>r.alias.length-t.alias.length):[]}var Sa={sourceType:"module",allowImportExportEverywhere:true,allowReturnOutsideFunction:true,startLine:1,tokens:true,plugins:["asyncGenerators","bigInt","classPrivateMethods","classPrivateProperties","classProperties","classStaticBlock","decimal","decorators-legacy","doExpressions","dynamicImport","exportDefaultFrom","exportNamespaceFrom","functionBind","functionSent","importAssertions","importMeta","nullishCoalescingOperator","numericSeparator","objectRestSpread","optionalCatchBinding","optionalChaining",["pipelineOperator",{proposal:"minimal"}],["recordAndTuple",{syntaxType:"hash"}],"throwExpressions","topLevelAwait","v8intrinsic","typescript","jsx"]},Bs=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let s=Pt.parse(r,{parser:{parse:n=>parse(n,Sa)}}),i=transformFromAstSync(s,r,{cloneInputAst:false,code:false,ast:true,plugins:[Ia],configFile:false});if(!i||!i.ast)throw new Error("Failed to transform JSX");return Pt.print(i.ast).code};var $a=/^["']use client["']$/g,At=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(SyntaxKind.ExpressionStatement);return r&&$a.test(r.getText())&&r.remove(),e};var ka=new Set(["cn-font-heading"]),Ta=/\bcn-[a-z-]+\b/;function Js(e){return Ta.test(e)&&!ka.has(e)}function Ys(e){return e.split(/\s+/).filter(t=>t.length>0&&!Js(t)).join(" ")}function Zs(e){return e.split(/\s+/).some(Js)}function Ot(e){let t=e.getLiteralValue();if(!Zs(t))return;let r=Ys(t);r!==t&&e.setLiteralValue(r);}function Xt(e){for(let t of e.getDescendantsOfKind(SyntaxKind.StringLiteral))Ot(t);for(let t of e.getDescendantsOfKind(SyntaxKind.NoSubstitutionTemplateLiteral))Ot(t);}function Pa(e){let t=[];for(let r of e.getDescendantsOfKind(SyntaxKind.JsxAttribute)){let s=r.getNameNode().getText();if(s!=="className"&&s!=="classNames")continue;let i=r.getInitializer();if(i?.isKind(SyntaxKind.StringLiteral)){let n=i.getLiteralValue();if(Zs(n)){let o=Ys(n);o===""?t.push(r):o!==n&&i.setLiteralValue(o);}}i?.isKind(SyntaxKind.JsxExpression)&&Xt(i);}for(let r of t)r.remove();for(let r of e.getDescendantsOfKind(SyntaxKind.CallExpression))if(r.getExpression().getText()==="cva")for(let s of r.getArguments()){if(s.isKind(SyntaxKind.StringLiteral)){Ot(s);continue}if(s.isKind(SyntaxKind.NoSubstitutionTemplateLiteral)){Ot(s);continue}Xt(s);}for(let r of e.getDescendantsOfKind(SyntaxKind.CallExpression))r.getExpression().getText()==="mergeProps"&&Xt(r);}var jt=async({sourceFile:e})=>(Pa(e),e);var _t=async({sourceFile:e,config:t})=>{if(!t.tailwind?.prefix)return e;let r=await kt(t);return e.getDescendantsOfKind(SyntaxKind.CallExpression).filter(s=>s.getExpression().getText()==="cva").forEach(s=>{if(s.getArguments()[0]?.isKind(SyntaxKind.StringLiteral)){let i=s.getArguments()[0];i&&i.replaceWithText(`"${fe(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}s.getArguments()[1]?.isKind(SyntaxKind.ObjectLiteralExpression)&&s.getArguments()[1]?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).find(i=>i.getName()==="variants")?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(i=>{i.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(n=>{let o=n.getInitializerIfKind(SyntaxKind.StringLiteral);o&&o?.replaceWithText(`"${fe(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});});}),e.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach(s=>{if(s.getNameNode().getText()==="className"){if(s.getInitializer()?.isKind(SyntaxKind.StringLiteral)){let i=s.getInitializer();i&&i.replaceWithText(`"${fe(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}if(s.getInitializer()?.isKind(SyntaxKind.JsxExpression)){let i=s.getInitializer()?.getDescendantsOfKind(SyntaxKind.CallExpression).find(n=>n.getExpression().getText()==="cn");i&&i.getArguments().forEach(n=>{(n.isKind(SyntaxKind.ConditionalExpression)||n.isKind(SyntaxKind.BinaryExpression))&&n.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(o=>{o.replaceWithText(`"${fe(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}),n.isKind(SyntaxKind.StringLiteral)&&n.replaceWithText(`"${fe(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});}}s.getNameNode().getText()==="classNames"&&s.getInitializer()?.isKind(SyntaxKind.JsxExpression)&&s.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(i=>{if(i.getInitializer()?.isKind(SyntaxKind.CallExpression)){let n=i.getInitializerIfKind(SyntaxKind.CallExpression);n&&n.getArguments().forEach(o=>{o.isKind(SyntaxKind.ConditionalExpression)&&o.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(c=>{c.replaceWithText(`"${fe(c.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}),o.isKind(SyntaxKind.StringLiteral)&&o.replaceWithText(`"${fe(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});}if(i.getInitializer()?.isKind(SyntaxKind.StringLiteral)&&i.getNameNode().getText()!=="variant"){let n=i.getInitializer();n&&n.replaceWithText(`"${fe(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}});}),e};function fe(e,t="",r){return r==="v3"?e.split(" ").map(s=>{let[i,n,o]=b(s);return i?o?`${i}:${t}${n}/${o}`:`${i}:${t}${n}`:o?`${t}${n}/${o}`:`${t}${n}`}).join(" "):e.split(" ").map(s=>s.indexOf(`${t}:`)===0?s:`${t}:${s.trim()}`).join(" ")}var Na=new Project({compilerOptions:{}});async function Ma(e){let t=await promises.mkdtemp(R__default.join(tmpdir(),"shadcn-"));return R__default.join(t,e)}async function Qs(e,t=[Tt,At,a,_t,d,c,jt]){let r=await Ma(e.filename),s=Na.createSourceFile(r,e.raw,{scriptKind:ScriptKind.TSX});for(let i of t)await i({sourceFile:s,...e});return e.transformJsx?await Bs({sourceFile:s,...e}):s.getText()}var La=["a","span","div","Link","label","Label"],ei=async({sourceFile:e,config:t})=>{if(!t.style?.startsWith("base-"))return e;let r=10;for(let s=0;s<r;s++){let n=e.getDescendantsOfKind(SyntaxKind.JsxElement).filter(a=>a.getOpeningElement().getAttribute("asChild"));if(n.length===0)break;let o=n.filter(a=>!a.getDescendantsOfKind(SyntaxKind.JsxElement).some(l=>l.getOpeningElement().getAttribute("asChild"))),c=[];for(let a of o){let h=a.getOpeningElement(),l=h.getAttribute("asChild");if(!l)continue;let u=h.getTagNameNode().getText(),f=a.getJsxChildren().find(g=>g.getKind()===SyntaxKind.JsxElement||g.getKind()===SyntaxKind.JsxSelfClosingElement);if(!f){l.remove();continue}let p,y,m;if(f.getKind()===SyntaxKind.JsxSelfClosingElement){let g=f.asKindOrThrow(SyntaxKind.JsxSelfClosingElement);p=g.getTagNameNode().getText(),y=g.getAttributes().map(w=>w.getText()).join(" "),m="";}else {let g=f.asKindOrThrow(SyntaxKind.JsxElement),w=g.getOpeningElement();p=w.getTagNameNode().getText(),y=w.getAttributes().map(v=>v.getText()).join(" "),m=g.getJsxChildren().map(v=>v.getText()).join("");}let x=u==="Button"&&La.includes(p);c.push({parentElement:a,parentTagName:u,childTagName:p,childProps:y,childChildren:m,needsNativeButton:x});}for(let a of c.reverse()){let l=a.parentElement.getOpeningElement().getAttributes().filter(y=>y.getKind()===SyntaxKind.JsxAttribute?y.asKindOrThrow(SyntaxKind.JsxAttribute).getNameNode().getText()!=="asChild":true).map(y=>y.getText()).join(" "),u=a.childProps?`{<${a.childTagName} ${a.childProps} />}`:`{<${a.childTagName} />}`,d=l?`${l} `:"";d+=`render=${u}`,a.needsNativeButton&&(d+=" nativeButton={false}");let f=a.childChildren.trim()?`${a.childChildren}`:"",p=`<${a.parentTagName} ${d}>${f}</${a.parentTagName}>`;a.parentElement.replaceWithText(p);}}return e};var ti=async({sourceFile:e})=>(e.getFunctions().forEach(t=>{t.getName()==="middleware"&&t.rename("proxy");}),e.getVariableDeclarations().forEach(t=>{t.getName()==="middleware"&&t.rename("proxy");}),e.getExportDeclarations().forEach(t=>{t.getNamedExports().forEach(s=>{s.getName()==="middleware"&&s.setName("proxy"),s.getAliasNode()?.getText()==="middleware"&&s.setAlias("proxy");});}),e);var er=[".ts",".tsx",".js",".jsx"],Wa=new Set(["tailwindConfig","tailwindCss"]),Ha=["components","ui","lib","hooks"];async function Rp(e,t,r){if(!e?.length)return {filesCreated:[],filesUpdated:[],filesSkipped:[]};r={overwrite:false,force:false,silent:false,isRemote:false,isWorkspace:false,...r};let s=Ee("Updating files.",{silent:r.silent})?.start(),[i,n]=await Promise.all([re(t.resolvedPaths.cwd),t.tailwind.baseColor?Lt(t.tailwind.baseColor):Promise.resolve(void 0)]),o=loadConfig(t.resolvedPaths.cwd),c$1=Ba(r.plannedFiles??e,t,{isSrcDir:i?.isSrcDir,framework:i?.framework.name,path:r.path}),a$1=new Project({compilerOptions:{}}),h=[],l=[],u=[],d$1=[],f=null;for(let x=0;x<e.length;x++){let g$1=e[x];if(!g$1.content)continue;let w=Nt(g$1,t,{isSrcDir:i?.isSrcDir,framework:i?.framework.name,commonRoot:Mt(e.map($=>$.path),g$1.path),path:r.path,fileIndex:x});if(!w)continue;let v=basename(g$1.path),b=R__default.dirname(w);if(t.tsx||(w=w.replace(/\.tsx?$/,$=>$===".tsx"?".jsx":".js")),Re(w)&&!existsSync(w)){let $=Us(b);$&&(w=$);}let E=existsSync(w);if(g$1.type==="registry:lib"&&basename(g$1.path)==="utils.ts"&&i?.framework.name==="laravel"&&E){u.push(R__default.relative(t.resolvedPaths.cwd,w));continue}if(E&&statSync(w).isDirectory())throw new Error(`Cannot write to ${w}: path exists and is a directory. Please provide a file path instead.`);let P=g$1.type==="registry:file"||g$1.type==="registry:item",k=Re(w)||P?g$1.content:await Qs({filename:g$1.path,raw:g$1.content,config:t,baseColor:n,transformJsx:!t.tsx,isRemote:r.isRemote,supportedFontMarkers:r.supportedFontMarkers},[Tt,At,a,_t,c,g,ei,d,...ri(w,i,t)?[ti]:[],f$1,jt]);if(E&&!Re(w)){let $=await ai({config:t,content:k,filePaths:c$1,project:a$1,projectInfo:i,resolvedPath:w,tsConfig:o}),Q=await promises.readFile(w,"utf-8");if(Vs(Q,$,{ignoreImports:r.isWorkspace})){u.push(R__default.relative(t.resolvedPaths.cwd,w));continue}}if(E&&!r.overwrite&&!Re(w)){s.stop(),r.rootSpinner&&r.rootSpinner.stop();let{overwrite:$}=await Da({type:"confirm",name:"overwrite",message:`The file ${T.info(v)} already exists. Would you like to overwrite?`,initial:false});if(!$){u.push(R__default.relative(t.resolvedPaths.cwd,w)),r.rootSpinner&&r.rootSpinner.start();continue}s?.start(),r.rootSpinner&&r.rootSpinner.start();}if(ri(w,i,t)&&(w=w.replace(/middleware\.(ts|js)$/,"proxy.$1")),existsSync(b)||await promises.mkdir(b,{recursive:true}),Re(w)&&E){let $=await promises.readFile(w,"utf-8"),Q=qs($,k);if(d$1=Ks($,k),f=R__default.relative(t.resolvedPaths.cwd,w),!d$1.length){u.push(R__default.relative(t.resolvedPaths.cwd,w));continue}await promises.writeFile(w,Q,"utf-8"),l.push(R__default.relative(t.resolvedPaths.cwd,w));continue}await promises.writeFile(w,k,"utf-8"),E?l.push(R__default.relative(t.resolvedPaths.cwd,w)):(h.push(R__default.relative(t.resolvedPaths.cwd,w)),Re(w)&&(d$1=Object.keys(Pe(k)),f=R__default.relative(t.resolvedPaths.cwd,w)));}let p=[...h,...l,...u],y=await qa(p,t,c$1);if(l.push(...y),h=Array.from(new Set(h)),l=Array.from(new Set(l.filter(x=>!h.includes(x)))),u=Array.from(new Set(u)),!(h.length||l.length)&&!u.length&&s?.info("No files updated."),h.length){if(s?.succeed(`Created ${h.length} ${h.length===1?"file":"files"}:`),!r.silent)for(let x of h)S.log(` - ${x}`);}else s?.stop();if(l.length&&(Ee(`Updated ${l.length} ${l.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let x of l)S.log(` - ${x}`);if(u.length&&(Ee(`Skipped ${u.length} ${u.length===1?"file":"files"}: (files might be identical, use --overwrite to overwrite)`,{silent:r.silent})?.info(),!r.silent))for(let x of u)S.log(` - ${x}`);if(d$1.length&&f&&(Ee(`Added the following variables to ${T.info(f)}:`)?.info(),!r.silent))for(let x of d$1)S.log(` ${T.success("+")} ${x}`);return {filesCreated:h,filesUpdated:l,filesSkipped:u}}function Nt(e,t,r){if(r.path){let n=R__default.isAbsolute(r.path)?r.path:R__default.join(t.resolvedPaths.cwd,r.path);if(/\.[^/\\]+$/.test(n)){if(r.fileIndex===0)return n}else {let c=R__default.basename(e.path);return R__default.join(n,c)}}if(e.target){if(e.target.startsWith("~/"))return R__default.join(t.resolvedPaths.cwd,e.target.replace("~/",""));let n=e.target,o=za(n,t);return o?.resolvedPath?o.resolvedPath:(o?.target&&(n=o.target),e.type==="registry:page"&&(n=Ka(n,r.framework),!n)?"":r.isSrcDir?R__default.join(t.resolvedPaths.cwd,"src",n.replace("src/","")):R__default.join(t.resolvedPaths.cwd,n.replace("src/","")))}let s=Ga(e,t),i=Ua(e.path,s);return R__default.join(s,i)}function za(e,t){let r=e.match(/^@([^/]+)\/(.+)$/);if(!r)return null;let[,s,i]=r;if(!Va(s))return {target:`${s}/${i}`};let n=R__default.resolve(t.resolvedPaths[s]),o=R__default.resolve(n,i);if(o!==n&&!o.startsWith(`${n}${R__default.sep}`))throw new Error(`Invalid target path "${e}". Target paths using @${s}/ must stay within the ${s} alias root.`);return {resolvedPath:o}}function Va(e){return Ha.includes(e)}function Ga(e,t){return e.type==="registry:ui"?t.resolvedPaths.ui:e.type==="registry:lib"?t.resolvedPaths.lib:e.type==="registry:block"||e.type==="registry:component"?t.resolvedPaths.components:e.type==="registry:hook"?t.resolvedPaths.hooks:t.resolvedPaths.components}function Mt(e,t){let r=e.map(o=>o.replace(/^\//,"")),s=t.replace(/^\//,""),i=s.split("/").slice(0,-1).join("/");if(!i)return "";let n=i.split("/");for(let o=n.length;o>0;o--){let c=n.slice(0,o).join("/");if(r.some(h=>h!==s&&h.startsWith(c+"/")))return "/"+c}return "/"+i}function Ua(e,t){let r=e.replace(/^\/|\/$/g,""),s=t.replace(/^\/|\/$/g,""),i=r.split("/"),n=s.split("/"),o=n[n.length-1],c=i.findIndex(a=>a===o);return c===-1?i[i.length-1]:i.slice(c+1).join("/")}function Ka(e,t){if(!t)return "";if(t==="next-app")return e;if(t==="next-pages"){let r=e.replace(/^app\//,"pages/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}if(t==="react-router"){let r=e.replace(/^app\//,"app/routes/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}if(t==="laravel"){let r=e.replace(/^app\//,"resources/js/pages/");return r=r.replace(/\/page(\.[jt]sx?)$/,"$1"),r}return ""}async function qa(e,t,r=e){let s=new Project({compilerOptions:{}}),i=await re(t.resolvedPaths.cwd),n=loadConfig(t.resolvedPaths.cwd),o=[];if(!i||n.resultType==="failed")return [];for(let c of e){let a=R__default.resolve(t.resolvedPaths.cwd,c);if(!existsSync(a))continue;let h=await promises.readFile(a,"utf-8"),l=await promises.mkdtemp(R__default.join(tmpdir(),"shadcn-")),u=s.createSourceFile(R__default.join(l,basename(a)),h,{scriptKind:ScriptKind.TSX});if(![".tsx",".ts",".jsx",".js"].includes(u.getExtension()))continue;let d=await ai({config:t,content:h,filePaths:r,project:s,projectInfo:i,resolvedPath:a,sourceFile:u,tsConfig:n});d!==h&&(await promises.writeFile(a,d,"utf-8"),o.push(c));}return o}function Ba(e,t,r){return (e??[])?.filter(s=>!!s?.content).map((s,i)=>{let n=Nt(s,t,{isSrcDir:r.isSrcDir,framework:r.framework,commonRoot:Mt((e??[]).map(o=>o.path),s.path),path:r.path,fileIndex:i});return n?(t.tsx||(n=n.replace(/\.tsx?$/,o=>o===".tsx"?".jsx":".js")),R__default.relative(t.resolvedPaths.cwd,n)):null}).filter(s=>!!s)}async function ai({content:e,resolvedPath:t,filePaths:r,config:s,projectInfo:i,tsConfig:n,project:o,sourceFile:c}){if(!i||n.resultType==="failed")return e;let a=R__default.extname(t);if(![".tsx",".ts",".jsx",".js"].includes(a))return e;let h=c===void 0?o.createSourceFile(R__default.join(tmpdir(),`shadcn-${Math.random().toString(36).slice(2)}${a||".tsx"}`),e,{scriptKind:ScriptKind.TSX,overwrite:true}):null,l=c??h;try{let u=!1;for(let d of l.getImportDeclarations()){let f=d.getModuleSpecifierValue();if(!Fs(f,i.aliasPrefix??null))continue;let p=await Ja(f,r,s,n);if(!p)continue;let y=Za(p,s,i,t);!y||y===f||(d.setModuleSpecifier(y),u=!0);}return u?l.getFullText():e}finally{h&&o.removeSourceFile(h);}}async function Ja(e,t,r,s){let i=(await Rt(e,{...s,cwd:r.resolvedPaths.cwd}))?.path,n=!i&&!e.startsWith(".")?Qa(e,r):null;return !i&&!n?null:Ya(i??n,t,r)}function Ya(e,t,r,s=[".tsx",".ts",".js",".jsx",".css"]){let i=R__default.normalize(r.resolvedPaths.cwd),n=t.map(m=>m.split(R__default.sep).join(R__default.posix.sep)),o=new Set(n),c=R__default.extname(e),a=c!=="",h=a?e.slice(0,-c.length):e,u=R__default.relative(i,h).split(R__default.sep).join(R__default.posix.sep),d=a?[c]:s,f=new Set;for(let m of d){let x=h+m,g=R__default.posix.normalize(R__default.relative(i,x));(o.has(g)||existsSync(x))&&f.add(g);let w=R__default.join(h,`index${m}`),v=R__default.posix.normalize(R__default.relative(i,w));(o.has(v)||existsSync(w))&&f.add(v);}let p=R__default.basename(h);for(let m of n)d.some(x=>m.endsWith(`/${p}${x}`))&&f.add(m);return f.size==