shadcn
Version:
Add components to your apps.
34 lines (33 loc) • 166 kB
JavaScript
import {m,l,f,d as d$1,c as c$1,e,n,u,p,b as b$1,q as q$1,r,s,t,y,A,w,o,g as g$1}from'./chunk-3ORLOMOE.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}from'zod';import qn,{promises,existsSync,statSync}from'fs';import {green,cyan,yellow,red}from'kleur/colors';import K from'fs-extra';import Et from'fast-glob';import {loadConfig,createMatchPath}from'tsconfig-paths';import {cosmiconfig}from'cosmiconfig';import cu,{tmpdir,homedir}from'os';import da from'ora';import {Project,SyntaxKind,ScriptKind,QuoteKind}from'ts-morph';import {transformFromAstSync}from'@babel/core';import {parse}from'@babel/parser';import va from'@babel/plugin-transform-typescript';import*as $t from'recast';import Na from'prompts';import je from'deepmerge';import {HttpsProxyAgent}from'https-proxy-agent';import xc,{Headers}from'node-fetch';import {execa}from'execa';import {createHash}from'crypto';import Qc from'stringify-object';import Z,{cwd}from'process';import Zl from'readline';import au from'events';import*as Yi from'fs/promises';import Yi__default from'fs/promises';import {createRequire}from'module';import {spawn}from'child_process';import {PassThrough}from'stream';import lu from'tty';import fh from'fuzzysort';var xe=process.env.REGISTRY_URL??"https://ui.shadcn.com/r",F=xe.replace(/\/r\/?$/,""),dt="new-york-v4",Ps=[{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"}],G={"@shadcn":`${xe}/styles/{style}/{name}.json`};var Ah=[{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";}},ft=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";}},Fe=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";}},De=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";}},We=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";}},W=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.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},S=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";}},He=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";}},ze=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 pt=class extends j{constructor(r,s){let i=`Invalid components.json configuration in ${r}.`;s instanceof z.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";}},Ve=class extends j{parseError;constructor(t){let r="Failed to parse registries index";if(t instanceof z.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 wo=/^(@[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(wo);return t?{registry:t[1],item:t[2]}:{registry:null,item:e}}var H={"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 P={error:red,warn:yellow,info:cyan,success:green};function mt(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 gt(e){if(!e.includes("*"))return "strip_extension";let t=e.slice(e.indexOf("*")+1);return t&&/^\.[^/]+$/.test(t)?"strip_extension":"preserve_extension"}function yt(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=Ut(e,i.key,{allowBareAliasBase:true});if(n!==null)return {path:R__default.resolve(i.rootDir,Io(i.target,n)),matchedAlias:i.key,matchedTarget:i.target,emitMode:i.emitMode}}return null}function Ut(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 Io(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 Kt=new Map;function Bt(e){let t=R__default.resolve(e),r=Kt.get(t);if(r)return r;let i=le(e,false)?.imports;if(!i||typeof i!="object"||Array.isArray(i))return Kt.set(t,[]),[];let n=[];for(let[o,c]of Object.entries(i)){if(!o.startsWith("#"))continue;let a=mt(c);a&&n.push({key:o,aliasBase:o==="#*"?"#":o.endsWith("/*")?o.slice(0,-2):o,target:a,emitMode:gt(a),hasWildcard:o.includes("*"),rootDir:t});}return Kt.set(t,n),n}function Os(e){let t=Bt(e).map(r=>r.aliasBase);return t.length?To(t):null}function Ue(e,t){return yt(e,Bt(t))}function js(e){let t=Bt(e),r=t.some(s=>s.key==="#*")?{components:"#components",ui:"#components/ui",lib:"#lib",hooks:"#hooks",utils:"#lib/utils"}:null;return {components:Ge(t,"components")??r?.components,ui:Ge(t,"ui")??r?.ui,lib:Ge(t,"lib")??r?.lib,hooks:Ge(t,"hooks")??r?.hooks,utils:Ge(t,"utils")??r?.utils}}function Ge(e,t){return e.map(s=>({entry:s,score:ko(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 ko(e,t){let r=e.aliasBase.toLowerCase(),s=$o(e.target).toLowerCase();switch(t){case "components":return r.endsWith("/ui")||s.includes("/components/ui")?0:wt(r,"components")?4:wt(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:wt(s,"lib")?3:0;case "hooks":return r==="#hooks"||r.endsWith("/hooks")?5:s.endsWith("/hooks")?4:wt(s,"hooks")?3:0;case "utils":return r==="#utils"||r.endsWith("/utils")?5:s.endsWith("/lib/utils")?4:s.endsWith("/utils")?3:0}}function $o(e){return e.replace(/\/\*$/,"").replace(/\*$/,"").replace(/\/index\.[^/]+$/,"")}function wt(e,t){return e===t||e.includes(`/${t}`)||e.includes(`${t}/`)}function To(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 C={error(...e){console.log(P.error(e.join(" ")));},warn(...e){console.log(P.warn(e.join(" ")));},info(...e){console.log(P.info(e.join(" ")));},success(...e){console.log(P.success(e.join(" ")));},log(...e){console.log(e.join(" "));},break(){console.log("");}};var Po=["next.config.*","vite.config.*","astro.config.*","remix.config.*","nuxt.config.*","svelte.config.*","gatsby-config.*","angular.json"];async function sd(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 id(e){let t=await xt(e);if(!t.length)return [];let r=await Et(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=Po.some(a=>Et.sync(a,{cwd:n,dot:true}).length>0);(o||c)&&s.push({name:i,hasConfig:o});}return s}function nd(e,t,r){let s=r?.cwdFlag??"-c";C.break(),C.log(`It looks like you are running ${P.info(e)} from a monorepo root.`),C.log(`To use shadcn in a specific workspace, use the ${P.info(s)} flag:`),C.break();for(let i of t)C.log(` shadcn ${e} ${s} ${i.name}`);C.break();}async function xt(e){let t=[],r=R__default.resolve(e,"pnpm-workspace.yaml");if(K.existsSync(r)){let i=await K.readFile(r,"utf8");t.push(...Ao(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 Ao(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 Ns=new Map,qt=new Map,vt=new Map;async function Ms(e,t){let r=Do(e);if(!r)return null;let s=await No(t,r.packageName);return s?yt(e,_o(s)):null}function _o(e){let t=`${e.packageRoot}:${e.packageName}`,r=qt.get(t);if(r)return r;let i=le(e.packageRoot,false)?.exports;if(!i||typeof i!="object"||Array.isArray(i))return qt.set(t,[]),[];let n=[];for(let[o,c]of Object.entries(i)){if(o!=="."&&!o.startsWith("./"))continue;let a=mt(c);if(!a)continue;let h=Wo(e.packageName,o);n.push({key:o.includes("*")?`${h}/*`:h,aliasBase:h,target:a,emitMode:gt(a),hasWildcard:o.includes("*"),rootDir:e.packageRoot});}return qt.set(t,n),n}async function No(e,t){let r=await Lo(e);if(!r)return null;let s=Ns.get(r);if(s?.has(t))return s.get(t)??null;let i=await Mo(r);return Ns.set(r,i),i.get(t)??null}async function Mo(e){let t=await xt(e),r=new Map;if(!t.length)return r;let s=await Et(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 Lo(e){let t=R__default.resolve(e),r=vt.get(t);if(r!==void 0)return r;let s=t,i=await Fo(t);for(;;){if((await xt(s)).length)return vt.set(t,s),s;if(i&&s===i)return vt.set(t,null),null;let o=R__default.dirname(s);if(o===s)return vt.set(t,null),null;s=o;}}async function Fo(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 Do(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 Wo(e,t){if(t===".")return e;let r=t.slice(2).replace(/\/\*$/,"");return r?`${e}/${r}`:e}async function Ke(e,t){let r=t.cwd??t.absoluteBaseUrl;if(e.startsWith("#")){let i=Ue(e,r);if(i)return {path:i.path,source:"package_imports",matchedAlias:i.matchedAlias,matchedTarget:i.matchedTarget,emitMode:i.emitMode}}let s=await Ms(e,r);return s?{path:s.path,source:"workspace_package_exports",matchedAlias:s.matchedAlias,matchedTarget:s.matchedTarget,emitMode:s.emitMode}:Vo(e,t)}function Jt(e,t){return e.startsWith("#")?true:t?e.startsWith(`${t}/`):false}function zo(e){return /^@[^/]+\/[^/]+(?:\/.*)?$/.test(e)}function Vo(e,t){let r=createMatchPath(t.absoluteBaseUrl,t.paths)(e,void 0,()=>true,[".ts",".tsx",".jsx",".js",".css"]);if(!r)return null;let s=Go(e,t.paths);return !s&&zo(e)?null:{path:r,source:"tsconfig_paths",matchedAlias:s?.key??e,matchedTarget:s?.target??r,emitMode:"strip_extension"}}function Go(e,t){for(let[r,s]of Object.entries(t)){let i=Array.isArray(s)?s:[s],n=Ut(e,r);if(n!==null)return {key:r,target:i[0]?.includes("*")&&n!==null?i[0].replace(/\*/g,n):i[0]}}return null}var $d="@/components",Td="@/lib/utils",Pd="app/globals.css",Ad="tailwind.config.js";var bt=cosmiconfig("components",{searchPlaces:["components.json"]});async function qe(e){let t=await Jo(e);return t?(t.iconLibrary||(t.iconLibrary=t.style==="new-york"?"radix":"lucide"),await Rt(e,t)):null}async function Rt(e,t){t.registries={...G,...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 qo(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 Ke(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 qo(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 ${P.info(e)}: ${P.info(r.join(", "))}.`,`Configure path aliases in ${P.info("tsconfig.json")} or imports in ${P.info("package.json")} for this workspace and try again.`].join(`
`))}async function Jo(e){try{let t=await bt.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 G)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 ${P.info(r)}.`)}}async function Od(e$1){let t={};for(let s of Object.keys(e$1.aliases)){if(!Zo(s,e$1))continue;let i=e$1.resolvedPaths[s],n=await Yo(e$1.resolvedPaths.cwd,i);if(!n){t[s]=e$1;continue}let o=await qe(n);if(!o)throw new Error([`Could not load the workspace config in ${P.info(n)}.`,`Add ${P.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 Yo(e,t){let r=Xo(e,t),s=R__default.relative(r,t),n=(await Et.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 Zo(e,t){return Object.keys(t.resolvedPaths).filter(r=>r!=="utils").includes(e)}function Xo(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 Ls(e,t){return (await re(e))?.tailwindVersion==="v4"?"new-york-v4":t}function jd(e){return e?.startsWith("base-")?"base":"radix"}function Fs(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:{...G}};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 St=["**/node_modules/**",".next","public","dist","build"],ta=z.object({compilerOptions:z.object({paths:z.record(z.string().or(z.array(z.string())))})});async function re(e,t){let[r,s,i,n,o,c,a,h]=await Promise.all([Et.glob("**/{next,vite,astro,app}.config.*|gatsby-config.*|composer.json|react-router.config.*",{cwd:e,deep:3,ignore:St}),K.pathExists(R__default.resolve(e,"src")),oa(e),ia(e),sa(e,t?.configCssFile),Ds(e),Ws(e),le(e,false)]),l=await K.pathExists(R__default.resolve(e,`${s?"src/":""}app`)),u={framework:H.manual,isSrcDir:s,isRSC:false,isTsx:i,tailwindConfigFile:n,tailwindCssFile:o,tailwindVersion:c,frameworkVersion:null,aliasPrefix:a.prefix};if(r.find(d=>d.startsWith("next.config."))?.length)return u.framework=l?H["next-app"]:H["next-pages"],u.isRSC=l,u.frameworkVersion=await ra(u.framework,h),u;if(r.find(d=>d.startsWith("astro.config."))?.length)return u.framework=H.astro,u;if(r.find(d=>d.startsWith("gatsby-config."))?.length)return u.framework=H.gatsby,u;if(r.find(d=>d.startsWith("composer.json"))?.length)return u.framework=H.laravel,u;if(Object.keys(h?.dependencies??{}).find(d=>d.startsWith("@remix-run/")))return u.framework=H.remix,u;if([...Object.keys(h?.dependencies??{}),...Object.keys(h?.devDependencies??{})].find(d=>d.startsWith("@tanstack/react-start")))return u.framework=H["tanstack-start"],u;if(r.find(d=>d.startsWith("react-router.config."))?.length)return u.framework=H["react-router"],u;if(r.find(d=>d.startsWith("vite.config."))?.length)return u.framework=H.vite,u;let f=r.find(d=>d.startsWith("app.config"));return f?.length&&(await K.readFile(R__default.resolve(e,f),"utf8")).includes("defineConfig")?(u.framework=H.vite,u):(h?.dependencies?.expo&&(u.framework=H.expo),u)}async function ra(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 Ds(e){let[t,r]=await Promise.all([le(e,false),qe(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 sa(e,t){if(t){let n=R__default.resolve(e,t);if(await K.pathExists(n))return t}let[r,s]=await Promise.all([Et.glob(["**/*.css","**/*.scss"],{cwd:e,deep:5,ignore:St}),Ds(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 ia(e){let t=await Et.glob("tailwind.config.*",{cwd:e,deep:3,ignore:St});return t.length?t[0]:null}async function na(e){let t=await loadConfig(e),r=t?.resultType==="success"&&Object.entries(t.paths).length?t.paths:(await aa(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 Ws(e){let t=await na(e),r=Os(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 oa(e){return (await Et.glob("tsconfig.*",{cwd:e,deep:1,ignore:St})).length>0}async function aa(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(ca(s));}catch{continue}let n=ta.safeParse(i);if(!n.error)return n.data}return null}function ca(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 qd(e,t=null){let[r,s,i]=await Promise.all([qe(e),t?Promise.resolve(t):re(e),Ws(e)]);if(r)return r;if(!s||!s.tailwindCssFile||s.tailwindVersion==="v3"&&!s.tailwindConfigFile)return null;let n=i.source==="package_imports"?js(e):null;if(!s.aliasPrefix)return null;let o=la(s.aliasPrefix,i.source==="package_imports"),c=i.source==="package_imports"&&n?ua({...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 Rt(e,a)}function la(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 ua(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 Ct(e){if(!e.resolvedPaths?.cwd)return "v3";let t=await re(e.resolvedPaths.cwd);return t?.tailwindVersion?t.tailwindVersion:null}async function Jd(e){let t=await qe(e);if(!t)return [];let s=(await Rt(e,t)).resolvedPaths.ui;if(!K.existsSync(s))return [];let i=await It(),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 Hs(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,f,d,p)=>{if(d.startsWith("."))return `${f}${d}${p}`;let m=d.split("/"),g=m[m.length-1];return `${f}@normalized/${g}${p}`}),a=c(i),h=c(n);return a===h}function Re(e){let t=R__default.basename(e);return /^\.env(\.|$)/.test(t)}function Vs(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 Te(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 Gs(e,t){let r=Te(e),s=Te(t),i=[];for(let n of Object.keys(s))n in r||i.push(n);return i}function Us(e,t){let r=Te(e),s=Te(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 Ie(e,t){return da({text:e,isSilent:t?.silent})}var kt=async({sourceFile:e,config:t,isRemote:r})=>{let s=t.aliases?.utils,i=typeof s=="string"?ma(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=pa(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 pa(e,t,r=false){if(e=ga(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 ma(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 ga(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 ya(t)){if(e===r)return s;if(e.startsWith(`${r}/`))return `${s}${e.slice(r.length)}`}return e}function ya(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 ba={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"]},Ks=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let s=$t.parse(r,{parser:{parse:n=>parse(n,ba)}}),i=transformFromAstSync(s,r,{cloneInputAst:false,code:false,ast:true,plugins:[va],configFile:false});if(!i||!i.ast)throw new Error("Failed to transform JSX");return $t.print(i.ast).code};var Ia=/^["']use client["']$/g,Tt=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(SyntaxKind.ExpressionStatement);return r&&Ia.test(r.getText())&&r.remove(),e};var Ea=new Set(["cn-font-heading"]),Sa=/\bcn-[a-z-]+\b/;function Bs(e){return Sa.test(e)&&!Ea.has(e)}function qs(e){return e.split(/\s+/).filter(t=>t.length>0&&!Bs(t)).join(" ")}function Js(e){return e.split(/\s+/).some(Bs)}function Pt(e){let t=e.getLiteralValue();if(!Js(t))return;let r=qs(t);r!==t&&e.setLiteralValue(r);}function Yt(e){for(let t of e.getDescendantsOfKind(SyntaxKind.StringLiteral))Pt(t);for(let t of e.getDescendantsOfKind(SyntaxKind.NoSubstitutionTemplateLiteral))Pt(t);}function Ca(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(Js(n)){let o=qs(n);o===""?t.push(r):o!==n&&i.setLiteralValue(o);}}i?.isKind(SyntaxKind.JsxExpression)&&Yt(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)){Pt(s);continue}if(s.isKind(SyntaxKind.NoSubstitutionTemplateLiteral)){Pt(s);continue}Yt(s);}for(let r of e.getDescendantsOfKind(SyntaxKind.CallExpression))r.getExpression().getText()==="mergeProps"&&Yt(r);}var At=async({sourceFile:e})=>(Ca(e),e);var Ot=async({sourceFile:e,config:t})=>{if(!t.tailwind?.prefix)return e;let r=await Ct(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(`"${de(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(`"${de(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(`"${de(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(`"${de(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}),n.isKind(SyntaxKind.StringLiteral)&&n.replaceWithText(`"${de(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(`"${de(c.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}),o.isKind(SyntaxKind.StringLiteral)&&o.replaceWithText(`"${de(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(`"${de(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}});}),e};function de(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 Aa=new Project({compilerOptions:{}});async function Oa(e){let t=await promises.mkdtemp(R__default.join(tmpdir(),"shadcn-"));return R__default.join(t,e)}async function Zs(e,t=[kt,Tt,a,Ot,d,c,At]){let r=await Oa(e.filename),s=Aa.createSourceFile(r,e.raw,{scriptKind:ScriptKind.TSX});for(let i of t)await i({sourceFile:s,...e});return e.transformJsx?await Ks({sourceFile:s,...e}):s.getText()}var ja=["a","span","div","Link","label","Label"],Xs=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(),d=a.getJsxChildren().find(y=>y.getKind()===SyntaxKind.JsxElement||y.getKind()===SyntaxKind.JsxSelfClosingElement);if(!d){l.remove();continue}let p,m,g;if(d.getKind()===SyntaxKind.JsxSelfClosingElement){let y=d.asKindOrThrow(SyntaxKind.JsxSelfClosingElement);p=y.getTagNameNode().getText(),m=y.getAttributes().map(w=>w.getText()).join(" "),g="";}else {let y=d.asKindOrThrow(SyntaxKind.JsxElement),w=y.getOpeningElement();p=w.getTagNameNode().getText(),m=w.getAttributes().map(v=>v.getText()).join(" "),g=y.getJsxChildren().map(v=>v.getText()).join("");}let x=u==="Button"&&ja.includes(p);c.push({parentElement:a,parentTagName:u,childTagName:p,childProps:m,childChildren:g,needsNativeButton:x});}for(let a of c.reverse()){let l=a.parentElement.getOpeningElement().getAttributes().filter(m=>m.getKind()===SyntaxKind.JsxAttribute?m.asKindOrThrow(SyntaxKind.JsxAttribute).getNameNode().getText()!=="asChild":true).map(m=>m.getText()).join(" "),u=a.childProps?`{<${a.childTagName} ${a.childProps} />}`:`{<${a.childTagName} />}`,f=l?`${l} `:"";f+=`render=${u}`,a.needsNativeButton&&(f+=" nativeButton={false}");let d=a.childChildren.trim()?`${a.childChildren}`:"",p=`<${a.parentTagName} ${f}>${d}</${a.parentTagName}>`;a.parentElement.replaceWithText(p);}}return e};var Qs=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 Xt=[".ts",".tsx",".js",".jsx"],Ma=new Set(["tailwindConfig","tailwindCss"]),La=["components","ui","lib","hooks"];async function yp(e,t,r){if(!e?.length)return {filesCreated:[],filesUpdated:[],filesSkipped:[]};r={overwrite:false,force:false,silent:false,isRemote:false,isWorkspace:false,...r};let s=Ie("Updating files.",{silent:r.silent})?.start(),[i,n]=await Promise.all([re(t.resolvedPaths.cwd),t.tailwind.baseColor?Nt(t.tailwind.baseColor):Promise.resolve(void 0)]),o=loadConfig(t.resolvedPaths.cwd),c$1=Ga(r.plannedFiles??e,t,{isSrcDir:i?.isSrcDir,framework:i?.framework.name,path:r.path}),a$1=new Project({compilerOptions:{}}),h=[],l=[],u=[],f=[],d$1=null;for(let x=0;x<e.length;x++){let y=e[x];if(!y.content)continue;let w=jt(y,t,{isSrcDir:i?.isSrcDir,framework:i?.framework.name,commonRoot:_t(e.map(k=>k.path),y.path),path:r.path,fileIndex:x});if(!w)continue;let v=basename(y.path),b=R__default.dirname(w);if(t.tsx||(w=w.replace(/\.tsx?$/,k=>k===".tsx"?".jsx":".js")),Re(w)&&!existsSync(w)){let k=Vs(b);k&&(w=k);}let I=existsSync(w);if(y.type==="registry:lib"&&basename(y.path)==="utils.ts"&&i?.framework.name==="laravel"&&I){u.push(R__default.relative(t.resolvedPaths.cwd,w));continue}if(I&&statSync(w).isDirectory())throw new Error(`Cannot write to ${w}: path exists and is a directory. Please provide a file path instead.`);let T=y.type==="registry:file"||y.type==="registry:item",$=Re(w)||T?y.content:await Zs({filename:y.path,raw:y.content,config:t,baseColor:n,transformJsx:!t.tsx,isRemote:r.isRemote,supportedFontMarkers:r.supportedFontMarkers},[kt,Tt,a,Ot,c,g,Xs,d,...ei(w,i,t)?[Qs]:[],f$1,At]);if(I&&!Re(w)){let k=await ni({config:t,content:$,filePaths:c$1,project:a$1,projectInfo:i,resolvedPath:w,tsConfig:o}),Q=await promises.readFile(w,"utf-8");if(Hs(Q,k,{ignoreImports:r.isWorkspace})){u.push(R__default.relative(t.resolvedPaths.cwd,w));continue}}if(I&&!r.overwrite&&!Re(w)){s.stop(),r.rootSpinner&&r.rootSpinner.stop();let{overwrite:k}=await Na({type:"confirm",name:"overwrite",message:`The file ${P.info(v)} already exists. Would you like to overwrite?`,initial:false});if(!k){u.push(R__default.relative(t.resolvedPaths.cwd,w)),r.rootSpinner&&r.rootSpinner.start();continue}s?.start(),r.rootSpinner&&r.rootSpinner.start();}if(ei(w,i,t)&&(w=w.replace(/middleware\.(ts|js)$/,"proxy.$1")),existsSync(b)||await promises.mkdir(b,{recursive:true}),Re(w)&&I){let k=await promises.readFile(w,"utf-8"),Q=Us(k,$);if(f=Gs(k,$),d$1=R__default.relative(t.resolvedPaths.cwd,w),!f.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,$,"utf-8"),I?l.push(R__default.relative(t.resolvedPaths.cwd,w)):(h.push(R__default.relative(t.resolvedPaths.cwd,w)),Re(w)&&(f=Object.keys(Te($)),d$1=R__default.relative(t.resolvedPaths.cwd,w)));}let p=[...h,...l,...u],m=await Va(p,t,c$1);if(l.push(...m),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)C.log(` - ${x}`);}else s?.stop();if(l.length&&(Ie(`Updated ${l.length} ${l.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let x of l)C.log(` - ${x}`);if(u.length&&(Ie(`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)C.log(` - ${x}`);if(f.length&&d$1&&(Ie(`Added the following variables to ${P.info(d$1)}:`)?.info(),!r.silent))for(let x of f)C.log(` ${P.success("+")} ${x}`);return {filesCreated:h,filesUpdated:l,filesSkipped:u}}function jt(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=Fa(n,t);return o?.resolvedPath?o.resolvedPath:(o?.target&&(n=o.target),e.type==="registry:page"&&(n=za(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=Wa(e,t),i=Ha(e.path,s);return R__default.join(s,i)}function Fa(e,t){let r=e.match(/^@([^/]+)\/(.+)$/);if(!r)return null;let[,s,i]=r;if(!Da(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 Da(e){return La.includes(e)}function Wa(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 _t(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 Ha(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 za(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 Va(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 f=await ni({config:t,content:h,filePaths:r,project:s,projectInfo:i,resolvedPath:a,sourceFile:u,tsConfig:n});f!==h&&(await promises.writeFile(a,f,"utf-8"),o.push(c));}return o}function Ga(e,t,r){return (e??[])?.filter(s=>!!s?.content).map((s,i)=>{let n=jt(s,t,{isSrcDir:r.isSrcDir,framework:r.framework,commonRoot:_t((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 ni({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 f of l.getImportDeclarations()){let d=f.getModuleSpecifierValue();if(!Jt(d,i.aliasPrefix??null))continue;let p=await Ua(d,r,s,n);if(!p)continue;let m=Ba(p,s,i,t);!m||m===d||(f.setModuleSpecifier(m),u=!0);}return u?l.getFullText():e}finally{h&&o.removeSourceFile(h);}}async function Ua(e,t,r,s){let i=(await Ke(e,{...s,cwd:r.resolvedPaths.cwd}))?.path,n=!i&&!e.startsWith(".")?Ja(e,r):null;return !i&&!n?null:Ka(i??n,t,r)}function Ka(e,t,r,s=[".tsx",".ts",".js",".jsx",".css"]){let i=R__default.normalize(r.resolvedPaths.cwd),n=t.map(g=>g.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),f=a?[c]:s,d=new Set;for(let g of f){let x=h+g,y=R__default.posix.normalize(R__default.relative(i,x));(o.has(y)||existsSync(x))&&d.add(y);let w=R__default.join(h,`index${g}`),v=R__default.posix.normalize(R__default.relative(i,w));(o.has(v)||existsSync(w))&&d.add(v);}let p=R__default.basename(h);for(let g of n)f.some(x=>g.endsWith(`/${p}${x}`))&&d.add(g);return d.size===0?null:Array.from(d).sort((g,x