import {g,q as q$1,p,r,m,h,o,i,j,k as k$1,l,u,t,b}from'./chunk-OG5VNDVA.js';import*as y from'path';import y__default,{basename}from'path';import {z}from'zod';import*as B from'fs/promises';import {tmpdir,homedir}from'os';import {green,cyan,yellow,red}from'kleur/colors';import {loadConfig,createMatchPath}from'tsconfig-paths';import {cosmiconfig}from'cosmiconfig';import Ae from'fast-glob';import Oe from'fs-extra';import {existsSync,promises}from'fs';import Sr from'ora';import {Project,SyntaxKind,ScriptKind,QuoteKind}from'ts-morph';import {transformFromAstSync}from'@babel/core';import {parse}from'@babel/parser';import Lr from'@babel/plugin-transform-typescript';import*as Ke from'recast';import Hr from'prompts';import oe from'deepmerge';import {HttpsProxyAgent}from'https-proxy-agent';import Cs from'node-fetch';import {createHash}from'crypto';import Ps from'stringify-object';import Gs from'fuzzysort';var ce=process.env.REGISTRY_URL??"https://ui.shadcn.com/r",Pe="new-york-v4",Et=[{name:"neutral",label:"Neutral"},{name:"gray",label:"Gray"},{name:"zinc",label:"Zinc"},{name:"stone",label:"Stone"},{name:"slate",label:"Slate"}],K={"@shadcn":`${ce}/styles/{style}/{name}.json`};var Xs=[{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."}];function pe(e){return e.replace(/\${(\w+)}/g,(t,r)=>process.env[r]||"")}function fe(e){let t=[],r=/\${(\w+)}/g,s;for(;(s=r.exec(e))!==null;)t.push(s[1]);return t}var F={NOT_FOUND:"NOT_FOUND",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"},S=class extends Error{code;statusCode;context;suggestion;timestamp;cause;constructor(t,r={}){super(t),this.name="RegistryError",this.code=r.code||F.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}}},q=class extends S{constructor(r,s){let n=`The item at ${r} was not found. It may not exist at the registry.`;super(n,{code:F.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";}},me=class extends S{constructor(r,s){let n=`You are not authorized to access the item at ${r}. If this is a remote registry, you may need to authenticate.`;super(n,{code:F.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 S{constructor(r,s){let n=`You are not authorized to access the item at ${r}. If this is a remote registry, you may need to authenticate.`;super(n,{code:F.FORBIDDEN,statusCode:403,cause:s,context:{url:r},suggestion:"Check your authentication credentials and environment variables."});this.url=r;this.name="RegistryForbiddenError";}},ge=class extends S{constructor(r,s,n,i){let o=s?`Failed to fetch from registry (${s}): ${r}`:`Failed to fetch from registry: ${r}`,a=typeof i=="string"&&i?`${o} - ${i}`:o,c="Check your network connection and try again.";s===404?c="The requested resource was not found. Check the URL or item name.":s===500?c="The registry server encountered an error. Try again later.":s&&s>=400&&s<500&&(c="There was a client error. Check your request parameters.");super(a,{code:F.FETCH_ERROR,statusCode:s,cause:i,context:{url:r,responseBody:n},suggestion:c});this.url=r;this.responseBody=n;this.name="RegistryFetchError";}},W=class extends S{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:F.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";}},X=class extends S{constructor(r,s){super(`Failed to read local registry file: ${r}`,{code:F.LOCAL_FILE_ERROR,cause:s,context:{filePath:r},suggestion:"Check if the file exists and you have read permissions."});this.filePath=r;this.name="RegistryLocalFileError";}},$=class extends S{constructor(r,s){let n=`Failed to parse registry item: ${r}`;s instanceof z.ZodError&&(n=`Failed to parse registry item: ${r} ${s.errors.map(i=>` - ${i.path.join(".")}: ${i.message}`).join(` `)}`);super(n,{code:F.PARSE_ERROR,cause:s,context:{item:r},suggestion:"The registry item may be corrupted or have an invalid format. Please make sure it returns a valid JSON object. See https://ui.shadcn.com/schema/registry-item.json."});this.item=r;this.parseError=s,this.name="RegistryParseError";}parseError},ue=class extends S{constructor(r,s){let n=`Registry "${r}" requires the following environment variables: `+s.map(i=>` \u2022 ${i}`).join(` `);super(n,{code:F.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";}},he=class extends S{constructor(r){let s=`Invalid registry namespace: "${r}". Registry names must start with @ (e.g., @shadcn, @v0).`;super(s,{code:F.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 Te=class extends S{constructor(r,s){let n=`Invalid components.json configuration in ${r}.`;s instanceof z.ZodError&&(n=`Invalid components.json configuration in ${r}: ${s.errors.map(i=>` - ${i.path.join(".")}: ${i.message}`).join(` `)}`);super(n,{code:F.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";}},ye=class extends S{parseError;constructor(t){let r="Failed to parse registries index";if(t instanceof z.ZodError){let s=t.errors.filter(n=>n.path.length>0).map(n=>`"${n.path[0]}"`).filter((n,i,o)=>o.indexOf(n)===i);s.length>0?r=`Failed to parse registries index. Invalid registry namespace(s): ${s.join(", ")} ${t.errors.map(n=>` - ${n.path.join(".")}: ${n.message}`).join(` `)}`:r=`Failed to parse registries index: ${t.errors.map(n=>` - ${n.path.join(".")}: ${n.message}`).join(` `)}`;}super(r,{code:F.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 nr=/^(@[a-zA-Z0-9](?:[a-zA-Z0-9-_]*[a-zA-Z0-9])?)\/(.+)$/;function ee(e){if(!e.startsWith("@"))return {registry:null,item:e};let t=e.match(nr);return t?{registry:t[1],item:t[2]}:{registry:null,item:e}}var O={"next-app":{name:"next-app",label:"Next.js",links:{installation:"https://ui.shadcn.com/docs/installation/next",tailwind:"https://tailwindcss.com/docs/guides/nextjs"}},"next-pages":{name:"next-pages",label:"Next.js",links:{installation:"https://ui.shadcn.com/docs/installation/next",tailwind:"https://tailwindcss.com/docs/guides/nextjs"}},remix:{name:"remix",label:"Remix",links:{installation:"https://ui.shadcn.com/docs/installation/remix",tailwind:"https://tailwindcss.com/docs/guides/remix"}},"react-router":{name:"react-router",label:"React Router",links:{installation:"https://ui.shadcn.com/docs/installation/react-router",tailwind:"https://tailwindcss.com/docs/installation/framework-guides/react-router"}},vite:{name:"vite",label:"Vite",links:{installation:"https://ui.shadcn.com/docs/installation/vite",tailwind:"https://tailwindcss.com/docs/guides/vite"}},astro:{name:"astro",label:"Astro",links:{installation:"https://ui.shadcn.com/docs/installation/astro",tailwind:"https://tailwindcss.com/docs/guides/astro"}},laravel:{name:"laravel",label:"Laravel",links:{installation:"https://ui.shadcn.com/docs/installation/laravel",tailwind:"https://tailwindcss.com/docs/guides/laravel"}},"tanstack-start":{name:"tanstack-start",label:"TanStack Start",links:{installation:"https://ui.shadcn.com/docs/installation/tanstack",tailwind:"https://tailwindcss.com/docs/installation/using-postcss"}},gatsby:{name:"gatsby",label:"Gatsby",links:{installation:"https://ui.shadcn.com/docs/installation/gatsby",tailwind:"https://tailwindcss.com/docs/guides/gatsby"}},expo:{name:"expo",label:"Expo",links:{installation:"https://ui.shadcn.com/docs/installation/expo",tailwind:"https://www.nativewind.dev/docs/getting-started/installation"}},manual:{name:"manual",label:"Manual",links:{installation:"https://ui.shadcn.com/docs/installation/manual",tailwind:"https://tailwindcss.com/docs/installation"}}};var P={error:red,warn:yellow,info:cyan,success:green};async function A(e,t){return createMatchPath(t.absoluteBaseUrl,t.paths)(e,void 0,()=>true,[".ts",".tsx",".jsx",".js",".css"])}var En="@/components",Rn="@/lib/utils",vn="app/globals.css",Cn="tailwind.config.js";var ke=cosmiconfig("components",{searchPlaces:["components.json"]});async function je(e){let t=await dr(e);return t?(t.iconLibrary||(t.iconLibrary=t.style==="new-york"?"radix":"lucide"),await Qe(e,t)):null}async function Qe(e,t){t.registries={...K,...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());return q$1.parse({...t,resolvedPaths:{cwd:e,tailwindConfig:t.tailwind.config?y__default.resolve(e,t.tailwind.config):"",tailwindCss:y__default.resolve(e,t.tailwind.css),utils:await A(t.aliases.utils,r),components:await A(t.aliases.components,r),ui:t.aliases.ui?await A(t.aliases.ui,r):y__default.resolve(await A(t.aliases.components,r)??e,"ui"),lib:t.aliases.lib?await A(t.aliases.lib,r):y__default.resolve(await A(t.aliases.utils,r)??e,".."),hooks:t.aliases.hooks?await A(t.aliases.hooks,r):y__default.resolve(await A(t.aliases.components,r)??e,"..","hooks")}})}async function dr(e){try{let t=await ke.search(e);if(!t)return null;let r=p.parse(t.config);if(r.registries){for(let s of Object.keys(r.registries))if(s in K)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 In(e){let t={};for(let s of Object.keys(e.aliases)){if(!ur(s,e))continue;let n=e.resolvedPaths[s],i=await gr(e.resolvedPaths.cwd,n);if(!i){t[s]=e;continue}t[s]=await je(i);}let r$1=r.safeParse(t);return r$1.success?r$1.data:null}async function gr(e,t){let r=hr(e,t),s=y__default.relative(r,t),i=(await Ae.glob("**/package.json",{cwd:r,deep:3,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/public/**"]})).map(o=>y__default.dirname(o)).find(o=>s.startsWith(o));return i?y__default.join(r,i):null}function ur(e,t){return Object.keys(t.resolvedPaths).filter(r=>r!=="utils").includes(e)}function hr(e,t){let r=e.split(y__default.sep),s=t.split(y__default.sep),n=[];for(let i=0;if.startsWith("next.config."))?.length)return l.framework=p?O["next-app"]:O["next-pages"],l.isRSC=p,l;if(t.find(f=>f.startsWith("astro.config."))?.length)return l.framework=O.astro,l;if(t.find(f=>f.startsWith("gatsby-config."))?.length)return l.framework=O.gatsby,l;if(t.find(f=>f.startsWith("composer.json"))?.length)return l.framework=O.laravel,l;if(Object.keys(c?.dependencies??{}).find(f=>f.startsWith("@remix-run/")))return l.framework=O.remix,l;if([...Object.keys(c?.dependencies??{}),...Object.keys(c?.devDependencies??{})].find(f=>f.startsWith("@tanstack/react-start")))return l.framework=O["tanstack-start"],l;if(t.find(f=>f.startsWith("react-router.config."))?.length)return l.framework=O["react-router"],l;if(t.find(f=>f.startsWith("vite.config."))?.length)return l.framework=O.vite,l;let m=t.find(f=>f.startsWith("app.config"));return m?.length&&(await Oe.readFile(y__default.resolve(e,m),"utf8")).includes("defineConfig")?(l.framework=O.vite,l):(c?.dependencies?.expo&&(l.framework=O.expo),l)}async function Ct(e){let[t,r]=await Promise.all([Xe(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 Er(e){let[t,r]=await Promise.all([Ae.glob(["**/*.css","**/*.scss"],{cwd:e,deep:5,ignore:Fe}),Ct(e)]);if(!t.length)return null;for(let n of t){let i=await Oe.readFile(y__default.resolve(e,n),"utf8");if(i.includes('@import "tailwindcss"')||i.includes("@import 'tailwindcss'")||i.includes("@tailwind base"))return n}return null}async function Rr(e){let t=await Ae.glob("tailwind.config.*",{cwd:e,deep:3,ignore:Fe});return t.length?t[0]:null}async function vr(e){let t=await loadConfig(e);if(t?.resultType==="failed"||!Object.entries(t?.paths).length)return null;for(let[r,s]of Object.entries(t.paths))if(s.includes("./*")||s.includes("./src/*")||s.includes("./app/*")||s.includes("./resources/js/*"))return r.replace(/\/\*$/,"")??null;return Object.keys(t?.paths)?.[0].replace(/\/\*$/,"")??null}async function Cr(e){return (await Ae.glob("tsconfig.*",{cwd:e,deep:1,ignore:Fe})).length>0}async function Kn(e,t=null){let[r,s]=await Promise.all([je(e),t?Promise.resolve(t):V(e)]);if(r)return r;if(!s||!s.tailwindCssFile||s.tailwindVersion==="v3"&&!s.tailwindConfigFile)return null;let n={$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:{components:`${s.aliasPrefix}/components`,ui:`${s.aliasPrefix}/components/ui`,hooks:`${s.aliasPrefix}/hooks`,lib:`${s.aliasPrefix}/lib`,utils:`${s.aliasPrefix}/lib/utils`}};return await Qe(e,n)}async function Le(e){if(!e.resolvedPaths?.cwd)return "v3";let t=await V(e.resolvedPaths.cwd);return t?.tailwindVersion?t.tailwindVersion:null}function It(e,t,r={}){let{ignoreImports:s=false}=r,n=e.replace(/\r\n/g,` `).trim(),i=t.replace(/\r\n/g,` `).trim();if(n===i)return true;if(!s)return false;let o=/^(import\s+(?:type\s+)?(?:\*\s+as\s+\w+|\{[^}]*\}|\w+)?(?:\s*,\s*(?:\{[^}]*\}|\w+))?\s+from\s+["'])([^"']+)(["'])/gm,a=l=>l.replace(o,(m,f,x,h)=>{if(x.startsWith("."))return `${f}${x}${h}`;let u=x.split("/"),v=u[u.length-1];return `${f}@normalized/${v}${h}`}),c=a(n),p=a(i);return c===p}function J(e){let t=y__default.basename(e);return /^\.env(\.|$)/.test(t)}function bt(e){let t=[".env.local",".env",".env.development.local",".env.development"];for(let r of t){let s=y__default.join(e,r);if(existsSync(s))return s}return null}function re(e){let t=e.split(` `),r={};for(let s of t){let n=s.trim();if(!n||n.startsWith("#"))continue;let i=n.indexOf("=");if(i===-1)continue;let o=n.substring(0,i).trim(),a=n.substring(i+1).trim();o&&(r[o]=a.replace(/^["']|["']$/g,""));}return r}function Pt(e,t){let r=re(e),s=re(t),n=[];for(let i of Object.keys(s))i in r||n.push(i);return n}function Tt(e,t){let r=re(e),s=re(t),n=e.trimEnd();n&&!n.endsWith(` `)&&(n+=` `);let i=[];for(let[o,a]of Object.entries(s))o in r||i.push(`${o}=${a}`);return i.length>0?(n&&(n+=` `),n+=i.join(` `),n+` `):n&&!n.endsWith(` `)?n+` `:n}var R={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("");}};function Y(e,t){return Sr({text:e,isSilent:t?.silent})}var Ne=async({sourceFile:e,config:t,baseColor:r})=>(t.tailwind?.cssVariables||!r?.inlineColors||e.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach(s=>{let n=s.getLiteralText(),i=Tr(n,r.inlineColors).trim();i!==n&&s.setLiteralValue(i);}),e);function et(e){if(!e.includes("/")&&!e.includes(":"))return [null,e,null];let t=[],[r,s]=e.split("/");if(!r.includes(":"))return [null,r,s];let n=r.split(":"),i=n.pop(),o=n.join(":");return t.push(o??null,i??null,s??null),t}var Pr=["bg-","text-","border-","ring-offset-","ring-"];function Tr(e,t){e.includes(" border ")&&(e=e.replace(" border "," border border-border "));let r=e.split(" "),s=new Set,n=new Set;for(let i of r){let[o,a,c]=et(i),p=Pr.find(m=>a?.startsWith(m));if(!p){s.has(i)||s.add(i);continue}let l=a?.replace(p,"");if(l&&l in t.light){s.add([o,`${p}${t.light[l]}`].filter(Boolean).join(":")+(c?`/${c}`:"")),n.add(["dark",o,`${p}${t.dark[l]}`].filter(Boolean).join(":")+(c?`/${c}`:""));continue}s.has(i)||s.add(i);}return [...Array.from(s),...Array.from(n)].join(" ").trim()}var De={lucide:{name:"lucide-react",package:"lucide-react",import:"lucide-react"},radix:{name:"@radix-ui/react-icons",package:"@radix-ui/react-icons",import:"@radix-ui/react-icons"}};var kt="lucide",ze=async({sourceFile:e,config:t})=>{if(!t.iconLibrary||!(t.iconLibrary in De))return e;let r=await jt(),s=kt,n=t.iconLibrary;if(s===n)return e;let i=[];for(let o of e.getImportDeclarations()??[])if(o.getModuleSpecifier()?.getText()===`"${De[kt].import}"`){for(let a of o.getNamedImports()??[]){let c=a.getName(),p=r[c]?.[n];!p||i.includes(p)||(i.push(p),a.remove(),e.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).filter(l=>l.getTagNameNode()?.getText()===c).forEach(l=>l.getTagNameNode()?.replaceWithText(p)));}o.getNamedImports()?.length===0&&o.remove();}if(i.length>0){let o=e.addImportDeclaration({moduleSpecifier:De[n]?.import,namedImports:i.map(a=>({name:a}))});jr(e)||o.replaceWithText(o.getText().replace(";",""));}return e};function jr(e){return e.getImportDeclarations()?.[0]?.getText().endsWith(";")??false}var _e=async({sourceFile:e,config:t,isRemote:r})=>{let n=`@${t.aliases?.utils?.split("/")[0]?.slice(1)}/lib/utils`;if(![".tsx",".ts",".jsx",".js"].includes(e.getExtension()))return e;for(let i of e.getImportStringLiterals()){let o=Or(i.getLiteralValue(),t,r);if(i.setLiteralValue(o),n===o||o==="@/lib/utils"){if(!i.getFirstAncestorByKind(SyntaxKind.ImportDeclaration)?.getNamedImports().some(p=>p.getName()==="cn"))continue;i.setLiteralValue(n===o?o.replace(n,t.aliases.utils):t.aliases.utils);}}return e};function Or(e,t,r=false){if(!e.startsWith("@/")&&!r)return e;if(r&&e.startsWith("@/")&&(e=e.replace(/^@\//,"@/registry/new-york/")),!e.startsWith("@/registry/")){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.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)}var Nr={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"]},$t=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let s=Ke.parse(r,{parser:{parse:i=>parse(i,Nr)}}),n=transformFromAstSync(s,r,{cloneInputAst:false,code:false,ast:true,plugins:[Lr],configFile:false});if(!n||!n.ast)throw new Error("Failed to transform JSX");return Ke.print(n.ast).code};var zr=/^["']use client["']$/g,Ve=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(SyntaxKind.ExpressionStatement);return r&&zr.test(r.getText())&&r.remove(),e};var We=async({sourceFile:e,config:t})=>{if(!t.tailwind?.prefix)return e;let r=await Le(t);return e.getDescendantsOfKind(SyntaxKind.CallExpression).filter(s=>s.getExpression().getText()==="cva").forEach(s=>{if(s.getArguments()[0]?.isKind(SyntaxKind.StringLiteral)){let n=s.getArguments()[0];n&&n.replaceWithText(`"${U(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}s.getArguments()[1]?.isKind(SyntaxKind.ObjectLiteralExpression)&&s.getArguments()[1]?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).find(n=>n.getName()==="variants")?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(n=>{n.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(i=>{let o=i.getInitializerIfKind(SyntaxKind.StringLiteral);o&&o?.replaceWithText(`"${U(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 n=s.getInitializer();n&&n.replaceWithText(`"${U(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}if(s.getInitializer()?.isKind(SyntaxKind.JsxExpression)){let n=s.getInitializer()?.getDescendantsOfKind(SyntaxKind.CallExpression).find(i=>i.getExpression().getText()==="cn");n&&n.getArguments().forEach(i=>{(i.isKind(SyntaxKind.ConditionalExpression)||i.isKind(SyntaxKind.BinaryExpression))&&i.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(o=>{o.replaceWithText(`"${U(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}),i.isKind(SyntaxKind.StringLiteral)&&i.replaceWithText(`"${U(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});}}s.getNameNode().getText()==="classNames"&&s.getInitializer()?.isKind(SyntaxKind.JsxExpression)&&s.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(n=>{if(n.getInitializer()?.isKind(SyntaxKind.CallExpression)){let i=n.getInitializerIfKind(SyntaxKind.CallExpression);i&&i.getArguments().forEach(o=>{o.isKind(SyntaxKind.ConditionalExpression)&&o.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(a=>{a.replaceWithText(`"${U(a.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}),o.isKind(SyntaxKind.StringLiteral)&&o.replaceWithText(`"${U(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);});}if(n.getInitializer()?.isKind(SyntaxKind.StringLiteral)&&n.getNameNode().getText()!=="variant"){let i=n.getInitializer();i&&i.replaceWithText(`"${U(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix,r)}"`);}});}),e};function U(e,t="",r){return r==="v3"?e.split(" ").map(s=>{let[n,i,o]=et(s);return n?o?`${n}:${t}${i}/${o}`:`${n}:${t}${i}`:o?`${t}${i}/${o}`:`${t}${i}`}).join(" "):e.split(" ").map(s=>s.indexOf(`${t}:`)===0?s:`${t}:${s.trim()}`).join(" ")}var Ur=new Project({compilerOptions:{}});async function Mr(e){let t=await promises.mkdtemp(y__default.join(tmpdir(),"shadcn-"));return y__default.join(t,e)}async function At(e,t=[_e,Ve,Ne,We,ze]){let r=await Mr(e.filename),s=Ur.createSourceFile(r,e.raw,{scriptKind:ScriptKind.TSX});for(let n of t)await n({sourceFile:s,...e});return e.transformJsx?await $t({sourceFile:s,...e}):s.getText()}async function Zi(e,t,r){if(!e?.length)return {filesCreated:[],filesUpdated:[],filesSkipped:[]};r={overwrite:false,force:false,silent:false,isRemote:false,isWorkspace:false,...r};let s=Y("Updating files.",{silent:r.silent})?.start(),[n,i]=await Promise.all([V(t.resolvedPaths.cwd),t.tailwind.baseColor?Ue(t.tailwind.baseColor):Promise.resolve(void 0)]),o=[],a=[],c=[],p=[],l=null;for(let h of e){if(!h.content)continue;let u=tt(h,t,{isSrcDir:n?.isSrcDir,framework:n?.framework.name,commonRoot:rt(e.map(w=>w.path),h.path)});if(!u)continue;let v=basename(h.path),d=y__default.dirname(u);if(t.tsx||(u=u.replace(/\.tsx?$/,w=>w===".tsx"?".jsx":".js")),J(u)&&!existsSync(u)){let w=bt(d);w&&(u=w);}let E=existsSync(u),C=J(u)?h.content:await At({filename:h.path,raw:h.content,config:t,baseColor:i,transformJsx:!t.tsx,isRemote:r.isRemote},[_e,Ve,Ne,We,ze]);if(E&&!J(u)){let w=await promises.readFile(u,"utf-8");if(It(w,C,{ignoreImports:r.isWorkspace})){c.push(y__default.relative(t.resolvedPaths.cwd,u));continue}}if(E&&!r.overwrite&&!J(u)){s.stop(),r.rootSpinner&&r.rootSpinner.stop();let{overwrite:w}=await Hr({type:"confirm",name:"overwrite",message:`The file ${P.info(v)} already exists. Would you like to overwrite?`,initial:false});if(!w){c.push(y__default.relative(t.resolvedPaths.cwd,u)),r.rootSpinner&&r.rootSpinner.start();continue}s?.start(),r.rootSpinner&&r.rootSpinner.start();}if(existsSync(d)||await promises.mkdir(d,{recursive:true}),J(u)&&E){let w=await promises.readFile(u,"utf-8"),T=Tt(w,C);if(p=Pt(w,C),l=y__default.relative(t.resolvedPaths.cwd,u),!p.length){c.push(y__default.relative(t.resolvedPaths.cwd,u));continue}await promises.writeFile(u,T,"utf-8"),a.push(y__default.relative(t.resolvedPaths.cwd,u));continue}await promises.writeFile(u,C,"utf-8"),E?a.push(y__default.relative(t.resolvedPaths.cwd,u)):(o.push(y__default.relative(t.resolvedPaths.cwd,u)),J(u)&&(p=Object.keys(re(C)),l=y__default.relative(t.resolvedPaths.cwd,u)));}let m=[...o,...a,...c],f=await Xr(m,t);if(a.push(...f),a=a.filter(h=>!o.includes(h)),!(o.length||a.length)&&!c.length&&s?.info("No files updated."),o=Array.from(new Set(o)),a=Array.from(new Set(a)),c=Array.from(new Set(c)),o.length){if(s?.succeed(`Created ${o.length} ${o.length===1?"file":"files"}:`),!r.silent)for(let h of o)R.log(` - ${h}`);}else s?.stop();if(a.length&&(Y(`Updated ${a.length} ${a.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let h of a)R.log(` - ${h}`);if(c.length&&(Y(`Skipped ${c.length} ${a.length===1?"file":"files"}: (files might be identical, use --overwrite to overwrite)`,{silent:r.silent})?.info(),!r.silent))for(let h of c)R.log(` - ${h}`);if(p.length&&l&&(Y(`Added the following variables to ${P.info(l)}:`)?.info(),!r.silent))for(let h of p)R.log(` ${P.success("+")} ${h}`);return r.silent||R.break(),{filesCreated:o,filesUpdated:a,filesSkipped:c}}function tt(e,t,r){if(e.target){if(e.target.startsWith("~/"))return y__default.join(t.resolvedPaths.cwd,e.target.replace("~/",""));let i=e.target;return e.type==="registry:page"&&(i=Qr(i,r.framework),!i)?"":r.isSrcDir?y__default.join(t.resolvedPaths.cwd,"src",i.replace("src/","")):y__default.join(t.resolvedPaths.cwd,i.replace("src/",""))}let s=Yr(e,t),n=Zr(e.path,s);return y__default.join(s,n)}function Yr(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 rt(e,t){let r=e.map(o=>o.replace(/^\//,"")),s=t.replace(/^\//,""),n=s.split("/").slice(0,-1).join("/");if(!n)return "";let i=n.split("/");for(let o=i.length;o>0;o--){let a=i.slice(0,o).join("/");if(r.some(p=>p!==s&&p.startsWith(a+"/")))return "/"+a}return "/"+n}function Zr(e,t){let r=e.replace(/^\/|\/$/g,""),s=t.replace(/^\/|\/$/g,""),n=r.split("/"),i=s.split("/"),o=i[i.length-1],a=n.findIndex(c=>c===o);return a===-1?n[n.length-1]:n.slice(a+1).join("/")}function Qr(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 Xr(e,t){let r=new Project({compilerOptions:{}}),s=await V(t.resolvedPaths.cwd),n=loadConfig(t.resolvedPaths.cwd),i=[];if(!s||n.resultType==="failed")return [];for(let o of e){let a=y__default.resolve(t.resolvedPaths.cwd,o);if(!existsSync(a))continue;let c=await promises.readFile(a,"utf-8"),p=await promises.mkdtemp(y__default.join(tmpdir(),"shadcn-")),l=r.createSourceFile(y__default.join(p,basename(a)),c,{scriptKind:ScriptKind.TSX});if(![".tsx",".ts",".jsx",".js"].includes(l.getExtension()))continue;let m=l.getImportDeclarations();for(let f of m){let x=f.getModuleSpecifierValue();if(s?.aliasPrefix&&!x.startsWith(`${s.aliasPrefix}/`))continue;let h=await A(x,n);if(!h)continue;let u=es(h,e,t);if(!u)continue;let v=ts(u,t,s);!v||v===x||(f.setModuleSpecifier(v),await promises.writeFile(a,l.getFullText(),"utf-8"),i.push(o));}}return i}function es(e,t,r,s=[".tsx",".ts",".js",".jsx",".css"]){let n=y__default.normalize(r.resolvedPaths.cwd),i=t.map(v=>v.split(y__default.sep).join(y__default.posix.sep)),o=new Set(i),a=y__default.extname(e),c=a!=="",p=c?e.slice(0,-a.length):e,m=y__default.relative(n,p).split(y__default.sep).join(y__default.posix.sep),f=c?[a]:s,x=new Set;for(let v of f){let d=p+v,E=y__default.posix.normalize(y__default.relative(n,d));(o.has(E)||existsSync(d))&&x.add(E);let C=y__default.join(p,`index${v}`),w=y__default.posix.normalize(y__default.relative(n,C));(o.has(w)||existsSync(C))&&x.add(w);}let h=y__default.basename(p);for(let v of i)f.some(d=>v.endsWith(`/${h}${d}`))&&x.add(v);return x.size===0?null:Array.from(x).sort((v,d)=>{let E=y__default.posix.extname(v),C=y__default.posix.extname(d),w=f.indexOf(E)-f.indexOf(C);if(w!==0)return w;let T=m&&v.startsWith(m)?-1:1,j=m&&d.startsWith(m)?-1:1;return T-j})[0]}function ts(e,t,r){let s=y__default.normalize(y__default.join(t.resolvedPaths.cwd,e)),n=Object.entries(t.resolvedPaths).filter(([,h])=>h&&s.startsWith(y__default.normalize(h+y__default.sep))).sort((h,u)=>u[1].length-h[1].length);if(n.length===0)return null;let[i,o]=n[0],a=y__default.relative(o,s);a=a.split(y__default.sep).join("/");let c=y__default.posix.extname(a),l=[".ts",".tsx",".js",".jsx"].includes(c)?"":c,m=a.slice(0,a.length-c.length);m.endsWith("/index")&&(m=m.slice(0,-6));let f=i==="cwd"?r.aliasPrefix:t.aliases[i];if(!f)return null;let x=m===""?"":`/${m}`;return x=x.replace("/src",""),`${f}${x}${l}`}var Nt=[".tsx",".ts",".jsx",".js",".css"],Dt=["lib/utils.ts"],os=[/^(react|react-dom|next)(\/.*)?$/,/^(node|jsr|npm):.*$/],as=new Project({compilerOptions:{}});function ls(e){if(os.some(t=>t.test(e)))return null;if(!e.startsWith("@")&&e.includes("/")&&(e=e.split("/")[0]),e.startsWith("@")){let t=e.split("/");t.length>2&&(e=t.slice(0,2).join("/"));}return e}async function cs(e,t,r,s=new Set){let n=y.resolve(t.resolvedPaths.cwd,e),i=y.relative(t.resolvedPaths.cwd,n);if(Dt.includes(i))return {dependencies:[],files:[]};let o=y.extname(e);if(!Nt.includes(o))return {dependencies:[],files:[]};if(s.has(i))return {dependencies:[],files:[]};if(s.add(i),!(await B.stat(n)).isFile())return {dependencies:[],files:[]};let c=await B.readFile(n,"utf-8"),p=await ps(y.basename(n)),l=as.createSourceFile(p,c,{scriptKind:ScriptKind.TSX}),m=await loadConfig(t.resolvedPaths.cwd);if(m.resultType==="failed")return {dependencies:[],files:[]};let f=[],x=new Set,h=zt(e),u={path:i,type:h,target:""};f.push(u);let v=l.getImportDeclarations();for(let E of v){let C=E.getModuleSpecifierValue(),w=C.startsWith(".");if(!C.startsWith(`${r.aliasPrefix}/`)&&!w){let z=ls(C);z&&x.add(z);continue}let j=await A(C,m);if(w&&(j=y.resolve(y.dirname(n),C)),!j)continue;if(!y.extname(j))for(let z of Nt){let ct=`${j}${z}`;try{await B.access(ct),j=ct;break}catch{continue}}let D=y.relative(t.resolvedPaths.cwd,j);if(s.has(D)||Dt.includes(D))continue;let le=zt(C),Ie={path:D,type:le,target:""};(le==="registry:page"||le==="registry:file")&&(Ie.target=C),f.push(Ie);let Se=await cs(D,t,r,s);if(Se.files)for(let z of Se.files)s.has(z.path)||(s.add(z.path),f.push(z));Se.dependencies&&Se.dependencies.forEach(z=>x.add(z));}let d=Array.from(new Map(f.map(E=>[E.path,E])).values());return {dependencies:Array.from(x),files:d}}async function ps(e){let t=await B.mkdtemp(y.join(tmpdir(),"shadcn-"));return y.join(t,e)}function zt(e){return e.includes("/ui/")?"registry:ui":e.includes("/lib/")?"registry:lib":e.includes("/hooks/")?"registry:hook":(e.includes("/components/"),"registry:component")}function N(e){try{return new URL(e),!0}catch{return false}}function Me(e){return e.endsWith(".json")&&!N(e)}function po(e){return !!e?.files?.length&&e.files.every(t=>!!t.target&&(t.type==="registry:file"||t.type==="registry:item"))}async function _t(e,t){if(!fs(t))return z.array(b).parse(e.flat().filter(Boolean));let r=await V(t.resolvedPaths.cwd),s=new Map,n=z.array(b).parse(e.flat().filter(Boolean));return n.forEach(i=>{let o=tt(i,t,{isSrcDir:r?.isSrcDir,framework:r?.framework.name,commonRoot:rt(n.map(a=>a.path),i.path)});o&&s.set(o,i);}),Array.from(s.values())}function fs(e){return !!(e?.resolvedPaths?.cwd&&(e?.resolvedPaths?.ui||e?.resolvedPaths?.lib||e?.resolvedPaths?.components||e?.resolvedPaths?.hooks))}function ds(e){return e.style?e.style==="new-york"&&e.tailwind?.config===""?Pe:e.style:Pe}function ne(e){let t=vt({style:Pe,registries:K});return e?q$1.parse(oe(t,{...e,style:ds(e),registries:{...K,...e.registries}})):t}var Be={headers:{}};function xe(e){Be.headers={...Be.headers,...e};}function Kt(e){return Be.headers[e]||{}}function we(){Be.headers={};}function gs(e){let t=new Set;return typeof e=="string"?fe(e).forEach(r=>t.add(r)):(fe(e.url).forEach(r=>t.add(r)),e.params&&Object.values(e.params).forEach(r=>{fe(r).forEach(s=>t.add(s));}),e.headers&&Object.values(e.headers).forEach(r=>{fe(r).forEach(s=>t.add(s));})),Array.from(t)}function Vt(e,t){let s=gs(t).filter(n=>!process.env[n]);if(s.length>0)throw new ue(e,s)}function So(e,t){for(let r of e)ie(r,ne(t));we();}var Wt="{name}",He="{style}",Ut=/\${(\w+)}/g,Mt="?",us="&";function ie(e,t){let{registry:r,item:s}=ee(e);if(!r)return null;let i=(t?.registries||{})[r];if(!i)throw new W(r);return Vt(r,i),{url:hs(s,i,t),headers:ys(i)}}function hs(e,t,r){if(typeof t=="string"){let n=t.replace(Wt,e);return r?.style&&n.includes(He)&&(n=n.replace(He,r.style)),pe(n)}let s=t.url.replace(Wt,e);return r?.style&&s.includes(He)&&(s=s.replace(He,r.style)),s=pe(s),t.params?xs(s,t.params):s}function ys(e){if(typeof e=="string"||!e.headers)return {};let t={};for(let[r,s]of Object.entries(e.headers)){let n=pe(s);ws(s,n)&&(t[r]=n);}return t}function xs(e,t){let r=new URLSearchParams;for(let[i,o]of Object.entries(t)){let a=pe(o);a&&r.append(i,a);}let s=r.toString();if(!s)return e;let n=e.includes(Mt)?us:Mt;return `${e}${n}${s}`}function ws(e,t){let r=t.trim();if(!r)return false;if(e.includes("${")&&e.match(Ut)){let n=e.replace(Ut,"").trim();return r!==n}return true}function Ge(e){if(N(e)){let t=new URL(e);return t.pathname.match(/\/chat\/b\//)&&!t.pathname.endsWith("/json")&&(t.pathname=`${t.pathname}/json`),t.toString()}return `${ce}/${e}`}var Is=process.env.https_proxy?new HttpsProxyAgent(process.env.https_proxy):void 0,st=new Map;async function k(e,t={}){t={useCache:true,...t};try{return await Promise.all(e.map(async s=>{let n=Ge(s);if(t.useCache&&st.has(n))return st.get(n);let i=(async()=>{let o=Kt(n),a=await Cs(n,{agent:Is,headers:{...o}});if(!a.ok){let c;if(a.headers.get("content-type")?.includes("application/json")){let p=await a.json(),l=z.object({detail:z.string().optional(),title:z.string().optional(),message:z.string().optional(),error:z.string().optional()}).safeParse(p);l.success&&(c=l.data.detail||l.data.message,l.data.error&&(c=`[${l.data.error}] ${c}`));}throw a.status===401?new me(n,c):a.status===404?new q(n,c):a.status===403?new de(n,c):new ge(n,a.status,c)}return a.json()})();return t.useCache&&st.set(n,i),i}))}catch(r){throw r}}async function Ht(e){try{let t=e;e.startsWith("~/")&&(t=y__default.join(homedir(),e.slice(2)));let r=y__default.resolve(t),s=await promises.readFile(r,"utf8"),n=JSON.parse(s);try{return g.parse(n)}catch(i){throw new $(e,i)}}catch(t){throw t instanceof Error&&(t.message.includes("ENOENT")||t.message.includes("no such file"))?new X(e,t):t instanceof $?t:new X(e,t)}}async function sa(e,t,r){if(!e||(r={silent:false,tailwindVersion:"v3",...r},r.tailwindVersion==="v4"))return;let s=y__default.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=Y(`Updating ${P.info(s)}`,{silent:r.silent}).start(),i=await promises.readFile(t.resolvedPaths.tailwindConfig,"utf8"),o=await js(i,e,t);await promises.writeFile(t.resolvedPaths.tailwindConfig,o,"utf8"),n?.succeed();}async function js(e,t,r){let s=await qt(e,r),n=s.getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression).find(o=>o.getProperties().some(a=>a.isKind(SyntaxKind.PropertyAssignment)&&a.getName()==="content"));if(!n)return e;let i=Fs(n);return $s(n,{name:"darkMode",value:"class"},{quoteChar:i}),t.plugins?.forEach(o=>{As(n,o);}),t.theme&&await Os(n,t.theme),s.getFullText()}function $s(e,t,{quoteChar:r}){let s=e.getProperty("darkMode");if(!s){let n={name:t.name,initializer:`[${r}${t.value}${r}]`};return t.name==="darkMode"?(e.insertPropertyAssignment(0,n),e):(e.addPropertyAssignment(n),e)}if(s.isKind(SyntaxKind.PropertyAssignment)){let n=s.getInitializer(),i=`${r}${t.value}${r}`;if(n?.isKind(SyntaxKind.StringLiteral)){let o=n.getText();return n.replaceWithText(`[${o}, ${i}]`),e}if(n?.isKind(SyntaxKind.ArrayLiteralExpression)){if(n.getElements().map(o=>o.getText()).includes(i))return e;n.addElement(i);}return e}return e}async function Os(e,t){e.getProperty("theme")||e.addPropertyAssignment({name:"theme",initializer:"{}"}),it(e);let s=(e.getPropertyOrThrow("theme")?.asKindOrThrow(SyntaxKind.PropertyAssignment)).getInitializer();if(s?.isKind(SyntaxKind.ObjectLiteralExpression)){let n=s.getText(),i=await Ls(n),o=oe(i,t,{arrayMerge:(c,p)=>p}),a=Ps(o).replace(/\'\.\.\.(.*)\'/g,"...$1").replace(/\'\"/g,"'").replace(/\"\'/g,"'").replace(/\'\[/g,"[").replace(/\]\'/g,"]").replace(/\'\\\'/g,"'").replace(/\\\'/g,"'").replace(/\\\'\'/g,"'").replace(/\'\'/g,"'");s.replaceWithText(a);}ot(e);}function As(e,t){let r=e.getProperty("plugins");if(!r)return e.addPropertyAssignment({name:"plugins",initializer:`[${t}]`}),e;if(r.isKind(SyntaxKind.PropertyAssignment)){let s=r.getInitializer();if(s?.isKind(SyntaxKind.ArrayLiteralExpression)){if(s.getElements().map(n=>n.getText().replace(/["']/g,"")).includes(t.replace(/["']/g,"")))return e;s.addElement(t);}return e}return e}async function qt(e,t){let r=await promises.mkdtemp(y__default.join(tmpdir(),"shadcn-")),s=t?.resolvedPaths?.tailwindConfig||"tailwind.config.ts",n=y__default.join(r,`shadcn-${y__default.basename(s)}`);return new Project({compilerOptions:{}}).createSourceFile(n,e,{scriptKind:y__default.extname(s)===".ts"?ScriptKind.TS:ScriptKind.JS})}function Fs(e){return e.getFirstDescendantByKind(SyntaxKind.StringLiteral)?.getQuoteKind()===QuoteKind.Single?"'":'"'}function it(e){let t=e.getProperties();for(let r=0;r0&&(r[i.url]=i.headers));}return xe(r),s}async function Z(e,t,r={}){return await Promise.all(e.map(async n=>{if(Me(n))return Ht(n);if(N(n)){let[a]=await k([n],r);try{return g.parse(a)}catch(c){throw new $(n,c)}}if(n.startsWith("@")&&t?.registries){let a=ve([n],t),[c]=await k(a,r);try{return g.parse(c)}catch(p){throw new $(n,p)}}let i=`styles/${t?.style??"new-york-v4"}/${n}.json`,[o]=await k([i],r);try{return g.parse(o)}catch(a){throw new $(n,a)}}))}g.extend({_source:z.string().optional()});async function tr(e,t,r={}){r={useCache:true,...r};let s=[],n=[],i=[],o=Array.from(new Set(e)),a=await Z(o,t,r),c=new Map;for(let d=0;dD.startsWith("@"));if(G.length>0){let{registry:D}=ee(G[0]);throw new W(D)}}let{items:T,registryNames:j}=await Ce(w,t,r,new Set(o));n.push(...T),i.push(...j);}}if(s.push(...n),i.length>0){let d=Array.from(new Set(i)),E=d.filter(w=>!w.startsWith("@")),C=d.filter(w=>w.startsWith("@"));if(C.length>0){let w=await Z(C,t,r);for(let T=0;T0){let w=await rr();if(!w&&s.length===0)return null;if(w){E.includes("index")&&E.unshift("index");let T=[];for(let le of E){let Ie=await Ds(le,t,r);T.push(...Ie);}let j=Array.from(new Set(T)),G=await k(j,r),D=z.array(g).parse(G);s.push(...D);}}}if(!s.length)return null;if((o.includes("index")||i.includes("index"))&&t.tailwind.baseColor){let d=await zs(t.tailwind.baseColor,t);d&&s.unshift(d);}let p=new Map;s.forEach(d=>{let E=d._source||d.name;p.set(d,E);}),s=Ks(s,p),s.sort((d,E)=>d.type==="registry:theme"&&E.type!=="registry:theme"?-1:d.type!=="registry:theme"&&E.type==="registry:theme"?1:0);let l={};s.forEach(d=>{l=oe(l,d.tailwind??{});});let m$1={};s.forEach(d=>{m$1=oe(m$1,d.cssVars??{});});let f={};s.forEach(d=>{f=oe(f,d.css??{});});let x="";s.forEach(d=>{d.docs&&(x+=`${d.docs} `);});let h={};s.forEach(d=>{h=oe(h,d.envVars??{});});let u=await _t(s.map(d=>d.files??[]),t),v=m.parse({dependencies:oe.all(s.map(d=>d.dependencies??[])),devDependencies:oe.all(s.map(d=>d.devDependencies??[])),files:u,tailwind:l,cssVars:m$1,css:f,docs:x});return Object.keys(h).length>0&&(v.envVars=h),v}async function Ce(e,t,r={},s=new Set){let n=[],i=[];for(let o of e)if(!s.has(o)){if(s.add(o),N(o)||Me(o)){let[a]=await Z([o],t,r);if(a&&(n.push(a),a.registryDependencies)){let c=t?.registries?ve(a.registryDependencies,t):a.registryDependencies,p=await Ce(c,t,r,s);n.push(...p.items),i.push(...p.registryNames);}}else if(o.startsWith("@")&&t?.registries){let{registry:a}=ee(o);if(a&&!(a in t.registries))throw new W(a);let[c]=await Z([o],t,r);if(c&&(n.push(c),c.registryDependencies)){let p=t?.registries?ve(c.registryDependencies,t):c.registryDependencies,l=await Ce(p,t,r,s);n.push(...l.items),i.push(...l.registryNames);}}else if(i.push(o),t)try{let[a]=await Z([o],t,r);if(a&&a.registryDependencies){let c=t?.registries?ve(a.registryDependencies,t):a.registryDependencies,p=await Ce(c,t,r,s);n.push(...p.items),i.push(...p.registryNames);}}catch{}}return {items:n,registryNames:i}}async function Ds(e,t,r={}){if(N(e))return [e];let{registryNames:s}=await Ce([e],t,r,new Set),n=t.resolvedPaths?.cwd?await Rt(t.resolvedPaths.cwd,t.style):t.style,i=s.map(o=>Ge(N(o)?o:`styles/${n}/${o}.json`));return Array.from(new Set(i))}async function zs(e,t){let[r,s]=await Promise.all([Ue(e),Le(t)]);if(!r)return null;let n={name:e,type:"registry:theme",tailwind:{config:{theme:{extend:{borderRadius:{lg:"var(--radius)",md:"calc(var(--radius) - 2px)",sm:"calc(var(--radius) - 4px)"},colors:{}}}}},cssVars:{theme:{},light:{radius:"0.5rem"},dark:{}}};return t.tailwind.cssVariables&&(n.tailwind.config.theme.extend.colors={...n.tailwind.config.theme.extend.colors,...Qt(r.cssVars.dark??{})},n.cssVars={theme:{...r.cssVars.theme,...n.cssVars.theme},light:{...r.cssVars.light,...n.cssVars.light},dark:{...r.cssVars.dark,...n.cssVars.dark}},s==="v4"&&r.cssVarsV4&&(n.cssVars={theme:{...r.cssVarsV4.theme,...n.cssVars.theme},light:{radius:"0.625rem",...r.cssVarsV4.light},dark:{...r.cssVarsV4.dark}})),n}function H(e,t){let r=t||e.name,s=createHash("sha256").update(r).digest("hex").substring(0,8);return `${e.name}::${s}`}function _s(e){if(N(e)){let s=new URL(e).pathname,n=s.match(/\/([^/]+)\.json$/),i=n?n[1]:y__default.basename(s,".json");return {name:i,hash:H({name:i},e)}}if(Me(e)){let r=e.match(/\/([^/]+)\.json$/),s=r?r[1]:y__default.basename(e,".json");return {name:s,hash:H({name:s},e)}}let{item:t}=ee(e);return {name:t,hash:H({name:t},e)}}function Ks(e,t){let r=new Map,s=new Map,n=new Map,i=new Map;e.forEach(p=>{let l=t.get(p)||p.name,m=H(p,l);r.set(m,p),s.set(m,p),n.set(m,0),i.set(m,[]);});let o=new Map;e.forEach(p=>{let l=t.get(p)||p.name,m=H(p,l);o.has(p.name)||o.set(p.name,[]),o.get(p.name).push(m),l!==p.name&&(o.has(l)||o.set(l,[]),o.get(l).push(m));}),e.forEach(p=>{let l=t.get(p)||p.name,m=H(p,l);p.registryDependencies&&p.registryDependencies.forEach(f=>{let x,h=o.get(f)||[];if(h.length===1)x=h[0];else if(h.length>1)x=h[0];else {let{name:u}=_s(f),v=o.get(u)||[];v.length>0&&(x=v[0]);}x&&r.has(x)&&(i.get(x).push(m),n.set(m,n.get(m)+1));});});let a=[],c=[];for(n.forEach((p,l)=>{p===0&&a.push(l);});a.length>0;){let p=a.shift(),l=r.get(p);c.push(l),i.get(p).forEach(m=>{let f=n.get(m)-1;n.set(m,f),f===0&&a.push(m);});}if(c.length!==e.length){console.warn("Circular dependency detected in registry items");let p=new Set(c.map(l=>{let m=t.get(l)||l.name;return H(l,m)}));e.forEach(l=>{let m=t.get(l)||l.name,f=H(l,m);p.has(f)||c.push(l);});}return c}function ae(e){if(R.break(),R.error("Something went wrong. Please check the error below for more details."),R.error("If the problem persists, please open an issue on GitHub."),R.error(""),typeof e=="string"&&(R.error(e),R.break(),process.exit(1)),e instanceof S&&(e.message&&(R.error(e.cause?"Error:":"Message:"),R.error(e.message)),e.cause&&(R.error(` Message:`),R.error(e.cause)),e.suggestion&&(R.error(` Suggestion:`),R.error(e.suggestion)),R.break(),process.exit(1)),e instanceof z.ZodError){R.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))R.error(`- ${P.info(t)}: ${r}`);R.break(),process.exit(1);}e instanceof Error&&(R.error(e.message),R.break(),process.exit(1)),R.break(),process.exit(1);}async function lt(e,t){let{config:r,useCache:s}=t||{};if(N(e)){let[a]=await k([e],{useCache:s});try{return h.parse(a)}catch(c){throw new $(e,c)}}if(!e.startsWith("@"))throw new he(e);let n=e;n.endsWith("/registry")||(n=`${n}/registry`);let i=ie(n,ne(r));if(!i?.url)throw new q(n);i.headers&&Object.keys(i.headers).length>0&&xe({[i.url]:i.headers});let[o]=await k([i.url],{useCache:s});try{return h.parse(o)}catch(a){throw new $(n,a)}}async function Us(e,t){let{config:r,useCache:s=false}=t||{};return we(),Z(e,ne(r),{useCache:s})}async function Ms(e,t){let{config:r,useCache:s=false}=t||{};return we(),tr(e,ne(r),{useCache:s})}async function Ua(e,t){let{useCache:r=true}=t||{};r||ke.clearCaches();let s=await ke.search(e);if(!s)return {registries:K};let n=z.object({registries:o.optional()}).safeParse(s.config);if(!n.success)throw new Te(e,n.error);return {registries:{...K,...n.data.registries||{}}}}async function rr(){try{let[e]=await k(["index.json"]);return i.parse(e)}catch(e){R.error(` `),ae(e);}}async function Ma(){try{let[e]=await k(["styles/index.json"]);return j.parse(e)}catch(e){return R.error(` `),ae(e),[]}}async function jt(){try{let[e]=await k(["icons/index.json"]);return k$1.parse(e)}catch(e){return ae(e),{}}}async function Ba(){return Et}async function Ue(e){try{let[t]=await k([`colors/${e}.json`]);return l.parse(t)}catch(t){ae(t);}}async function Bs(e,t){let r=[];for(let s of t){let n=e.find(i=>i.name===s);if(n&&(r.push(n),n.registryDependencies)){let i=await Bs(e,n.registryDependencies);r.push(...i);}}return r.filter((s,n,i)=>i.findIndex(o=>o.name===s.name)===n)}async function Ha(e,t){try{let r=t.map(n=>`styles/${e}/${n.name}.json`);return (await k(r)).map(n=>g.parse(n))}catch(r){return ae(r),[]}}async function Ga(e,t,r){if(r)return r;if(t.type==="registry:ui")return e.resolvedPaths.ui??e.resolvedPaths.components;let[s,n]=t.type?.split(":")??[];return s in e.resolvedPaths?y__default.join(e.resolvedPaths[s],n):null}async function Hs(e){e={useCache:true,...e};let t=`${ce}/registries.json`,[r]=await k([t],{useCache:e.useCache});try{return u.parse(r)}catch(s){throw s instanceof z.ZodError?new ye(s):s}}async function qs(e,t$1){let{query:r,limit:s,offset:n,config:i,useCache:o}=t$1||{},a=[];for(let f of e){let h=((await lt(f,{config:i,useCache:o})).items||[]).map(u=>({name:u.name,type:u.type,description:u.description,registry:f,addCommandArgument:Qs(u.name,f)}));a=a.concat(h);}r&&(a=Ys(a,{query:r,limit:a.length,keys:["name","description"]}));let c=n||0,p=s||a.length,l=a.length,m={pagination:{total:l,offset:c,limit:p,hasMore:c+pn.obj);return z.array(Js).parse(s)}function Zs(e){try{return new URL(e),!0}catch{return false}}function Qs(e,t){if(!Zs(t))return `${t}/${e}`;let r=t.indexOf("://")+3,s=t.indexOf("/",r);if(s===-1){let f=t.indexOf("?",r);if(f!==-1){let x=t.substring(0,f),u=t.substring(f).replace(/\bregistry\b/g,e);return x+u}return t}let n=t.substring(0,s),i=t.substring(s),o=i.indexOf("?")!==-1?i.indexOf("?"):i.length,a=i.substring(0,o),c=i.substring(o),p=a.lastIndexOf("registry"),l=a;p!==-1&&(l=a.substring(0,p)+e+a.substring(p+8));let m=c.replace(/\bregistry\b/g,e);return n+l+m} export{Ms as $,X as A,$ as B,ue as C,he as D,ye as E,ee as F,bt as G,Pt as H,Tt as I,De as J,At as K,Zi as L,cs as M,po as N,ne as O,we as P,So as Q,ie as R,k as S,sa as T,qt as U,Fs as V,Z as W,tr as X,ae as Y,lt as Z,Us as _,Et as a,Ua as aa,K as b,rr as ba,Xs as c,Ma as ca,P as d,jt as da,En as e,Ba as ea,Rn as f,Ue as fa,vn as g,Bs as ga,Cn as h,Ha as ha,je as i,Ga as ia,Qe as j,Hs as ja,In as k,qs as ka,gr as l,hr as m,vt as n,Xe as o,V as p,Kn as q,Le as r,R as s,Y as t,S as u,q as v,me as w,de as x,ge as y,W as z};//# sourceMappingURL=chunk-WFZDKYBJ.js.map //# sourceMappingURL=chunk-WFZDKYBJ.js.map