UNPKG

shadcn

Version:

Add components to your apps.

29 lines (27 loc) 23.3 kB
import { z as z$1 } from 'zod'; import w from 'path'; import K from 'fs-extra'; import S from 'fast-glob'; import { loadConfig, createMatchPath } from 'tsconfig-paths'; import { red, yellow, cyan, green } from 'kleur/colors'; import { cosmiconfig } from 'cosmiconfig'; import { promises } from 'fs'; import { tmpdir } from 'os'; import Ae from 'ora'; import E from 'deepmerge'; import $e from 'stringify-object'; import { SyntaxKind, Project, ScriptKind, QuoteKind } from 'ts-morph'; import { HttpsProxyAgent } from 'https-proxy-agent'; import Be from 'node-fetch'; var W=z$1.enum(["registry:lib","registry:block","registry:component","registry:ui","registry:hook","registry:page","registry:file","registry:theme","registry:example","registry:style","registry:internal"]),oe=z$1.discriminatedUnion("type",[z$1.object({path:z$1.string(),content:z$1.string().optional(),type:z$1.enum(["registry:file","registry:page"]),target:z$1.string()}),z$1.object({path:z$1.string(),content:z$1.string().optional(),type:W.exclude(["registry:file","registry:page"]),target:z$1.string().optional()})]),ae=z$1.object({config:z$1.object({content:z$1.array(z$1.string()).optional(),theme:z$1.record(z$1.string(),z$1.any()).optional(),plugins:z$1.array(z$1.string()).optional()}).optional()}),le=z$1.object({light:z$1.record(z$1.string(),z$1.string()).optional(),dark:z$1.record(z$1.string(),z$1.string()).optional()}),k=z$1.object({$schema:z$1.string().optional(),name:z$1.string(),type:W,title:z$1.string().optional(),author:z$1.string().min(2).optional(),description:z$1.string().optional(),dependencies:z$1.array(z$1.string()).optional(),devDependencies:z$1.array(z$1.string()).optional(),registryDependencies:z$1.array(z$1.string()).optional(),files:z$1.array(oe).optional(),tailwind:ae.optional(),cssVars:le.optional(),meta:z$1.record(z$1.string(),z$1.any()).optional(),docs:z$1.string().optional(),categories:z$1.array(z$1.string()).optional()}),nt=z$1.object({name:z$1.string(),homepage:z$1.string(),items:z$1.array(k)}),R=z$1.array(k),N=z$1.array(z$1.object({name:z$1.string(),label:z$1.string()})),M=z$1.record(z$1.string(),z$1.record(z$1.string(),z$1.string())),B=z$1.object({inlineColors:z$1.object({light:z$1.record(z$1.string(),z$1.string()),dark:z$1.record(z$1.string(),z$1.string())}),cssVars:z$1.object({light:z$1.record(z$1.string(),z$1.string()),dark:z$1.record(z$1.string(),z$1.string())}),cssVarsV4:z$1.object({light:z$1.record(z$1.string(),z$1.string()),dark:z$1.record(z$1.string(),z$1.string())}).optional(),inlineColorsTemplate:z$1.string(),cssVarsTemplate:z$1.string()}),G=k.pick({dependencies:!0,devDependencies:!0,files:!0,tailwind:!0,cssVars:!0,docs:!0});var h={"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"}},manual:{name:"manual",label:"Manual",links:{installation:"https://ui.shadcn.com/docs/installation/manual",tailwind:"https://tailwindcss.com/docs/installation"}}};function O(e="",t=!0){let r=w.join(e,"package.json");return K.readJSONSync(r,{throws:t})}var C=["**/node_modules/**",".next","public","dist","build"];z$1.object({compilerOptions:z$1.object({paths:z$1.record(z$1.string().or(z$1.array(z$1.string())))})});async function L(e){let[t,r,i,n,o,l,g,y]=await Promise.all([S.glob("**/{next,vite,astro,app}.config.*|gatsby-config.*|composer.json|react-router.config.*",{cwd:e,deep:3,ignore:C}),K.pathExists(w.resolve(e,"src")),ue(e),de(e),fe(e),J(e),me(e),O(e,!1)]),p=await K.pathExists(w.resolve(e,`${r?"src/":""}app`)),f={framework:h.manual,isSrcDir:r,isRSC:!1,isTsx:i,tailwindConfigFile:n,tailwindCssFile:o,tailwindVersion:l,aliasPrefix:g};return t.find(d=>d.startsWith("next.config."))?.length?(f.framework=p?h["next-app"]:h["next-pages"],f.isRSC=p,f):t.find(d=>d.startsWith("astro.config."))?.length?(f.framework=h.astro,f):t.find(d=>d.startsWith("gatsby-config."))?.length?(f.framework=h.gatsby,f):t.find(d=>d.startsWith("composer.json"))?.length?(f.framework=h.laravel,f):Object.keys(y?.dependencies??{}).find(d=>d.startsWith("@remix-run/"))?(f.framework=h.remix,f):t.find(d=>d.startsWith("app.config."))?.length&&[...Object.keys(y?.dependencies??{}),...Object.keys(y?.devDependencies??{})].find(d=>d.startsWith("@tanstack/start"))?(f.framework=h["tanstack-start"],f):t.find(d=>d.startsWith("react-router.config."))?.length?(f.framework=h["react-router"],f):(t.find(d=>d.startsWith("vite.config."))?.length&&(f.framework=h.vite),f)}async function J(e){let[t,r]=await Promise.all([O(e),j(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 fe(e){let[t,r]=await Promise.all([S.glob(["**/*.css","**/*.scss"],{cwd:e,deep:5,ignore:C}),J(e)]);if(!t.length)return null;for(let n of t){let o=await K.readFile(w.resolve(e,n),"utf8");if(o.includes('@import "tailwindcss"')||o.includes("@import 'tailwindcss'")||o.includes("@tailwind base"))return n}return null}async function de(e){let t=await S.glob("tailwind.config.*",{cwd:e,deep:3,ignore:C});return t.length?t[0]:null}async function me(e){let t=await loadConfig(e);if(t?.resultType==="failed"||!Object.entries(t?.paths).length)return null;for(let[r,i]of Object.entries(t.paths))if(i.includes("./*")||i.includes("./src/*")||i.includes("./app/*")||i.includes("./resources/js/*"))return r.replace(/\/\*$/,"")??null;return Object.keys(t?.paths)?.[0].replace(/\/\*$/,"")??null}async function ue(e){return (await S.glob("tsconfig.*",{cwd:e,deep:1,ignore:C})).length>0}async function kt(e,t=null){let[r,i]=await Promise.all([j(e),t?Promise.resolve(t):L(e)]);if(r)return r;if(!i||!i.tailwindCssFile||i.tailwindVersion==="v3"&&!i.tailwindConfigFile)return null;let n={$schema:"https://ui.shadcn.com/schema.json",rsc:i.isRSC,tsx:i.isTsx,style:"new-york",tailwind:{config:i.tailwindConfigFile??"",baseColor:"zinc",css:i.tailwindCssFile,cssVariables:!0,prefix:""},iconLibrary:"lucide",aliases:{components:`${i.aliasPrefix}/components`,ui:`${i.aliasPrefix}/components/ui`,hooks:`${i.aliasPrefix}/hooks`,lib:`${i.aliasPrefix}/lib`,utils:`${i.aliasPrefix}/lib/utils`}};return await F(e,n)}async function Y(e){if(!e.resolvedPaths?.cwd)return "v3";let t=await L(e.resolvedPaths.cwd);return t?.tailwindVersion?t.tailwindVersion:null}var u={error:red,warn:yellow,info:cyan,success:green};async function x(e,t){return createMatchPath(t.absoluteBaseUrl,t.paths)(e,void 0,()=>!0,[".ts",".tsx"])}var Ft="@/components",Vt="@/lib/utils",zt="app/globals.css",Dt="tailwind.config.js";var ve=cosmiconfig("components",{searchPlaces:["components.json"]}),H=z$1.object({$schema:z$1.string().optional(),style:z$1.string(),rsc:z$1.coerce.boolean().default(!1),tsx:z$1.coerce.boolean().default(!0),tailwind:z$1.object({config:z$1.string().optional(),css:z$1.string(),baseColor:z$1.string(),cssVariables:z$1.boolean().default(!0),prefix:z$1.string().default("").optional()}),aliases:z$1.object({components:z$1.string(),utils:z$1.string(),ui:z$1.string().optional(),lib:z$1.string().optional(),hooks:z$1.string().optional()}),iconLibrary:z$1.string().optional()}).strict(),Q=H.extend({resolvedPaths:z$1.object({cwd:z$1.string(),tailwindConfig:z$1.string(),tailwindCss:z$1.string(),utils:z$1.string(),components:z$1.string(),lib:z$1.string(),hooks:z$1.string(),ui:z$1.string()})}),Ee=z$1.record(Q);async function j(e){let t=await je(e);return t?(t.iconLibrary||(t.iconLibrary=t.style==="new-york"?"radix":"lucide"),await F(e,t)):null}async function F(e,t){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.parse({...t,resolvedPaths:{cwd:e,tailwindConfig:t.tailwind.config?w.resolve(e,t.tailwind.config):"",tailwindCss:w.resolve(e,t.tailwind.css),utils:await x(t.aliases.utils,r),components:await x(t.aliases.components,r),ui:t.aliases.ui?await x(t.aliases.ui,r):w.resolve(await x(t.aliases.components,r)??e,"ui"),lib:t.aliases.lib?await x(t.aliases.lib,r):w.resolve(await x(t.aliases.utils,r)??e,".."),hooks:t.aliases.hooks?await x(t.aliases.hooks,r):w.resolve(await x(t.aliases.components,r)??e,"..","hooks")}})}async function je(e){try{let t=await ve.search(e);return t?H.parse(t.config):null}catch{let r=`${e}/components.json`;throw new Error(`Invalid configuration found in ${u.info(r)}.`)}}async function _t(e){let t={};for(let i of Object.keys(e.aliases)){if(!Ce(i,e))continue;let n=e.resolvedPaths[i],o=await Se(e.resolvedPaths.cwd,n);if(!o){t[i]=e;continue}t[i]=await j(o);}let r=Ee.safeParse(t);return r.success?r.data:null}async function Se(e,t){let r=Le(e,t),i=w.relative(r,t),o=(await S.glob("**/package.json",{cwd:r,deep:3,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/public/**"]})).map(l=>w.dirname(l)).find(l=>i.startsWith(l));return o?w.join(r,o):null}function Ce(e,t){return Object.keys(t.resolvedPaths).filter(r=>r!=="utils").includes(e)}function Le(e,t){let r=e.split(w.sep),i=t.split(w.sep),n=[];for(let o=0;o<Math.min(r.length,i.length)&&r[o]===i[o];o++)n.push(r[o]);return n.join(w.sep)}async function Z(e,t){return (await L(e))?.tailwindVersion==="v4"?"new-york-v4":t}var m={error(...e){console.log(u.error(e.join(" ")));},warn(...e){console.log(u.warn(e.join(" ")));},info(...e){console.log(u.info(e.join(" ")));},success(...e){console.log(u.success(e.join(" ")));},log(...e){console.log(e.join(" "));},break(){console.log("");}};function b(e){if(m.error("Something went wrong. Please check the error below for more details."),m.error("If the problem persists, please open an issue on GitHub."),m.error(""),typeof e=="string"&&(m.error(e),m.break(),process.exit(1)),e instanceof z$1.ZodError){m.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))m.error(`- ${u.info(t)}: ${r}`);m.break(),process.exit(1);}e instanceof Error&&(m.error(e.message),m.break(),process.exit(1)),m.break(),process.exit(1);}function q(e,t){return Ae({text:e,isSilent:t?.silent})}async function lr(e,t,r){if(!e||(r={silent:!1,tailwindVersion:"v3",...r},r.tailwindVersion==="v4"))return;let i=w.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=q(`Updating ${u.info(i)}`,{silent:r.silent}).start(),o=await promises.readFile(t.resolvedPaths.tailwindConfig,"utf8"),l=await Ve(o,e,t);await promises.writeFile(t.resolvedPaths.tailwindConfig,l,"utf8"),n?.succeed();}async function Ve(e,t,r){let i=await ee(e,r),n=i.getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression).find(l=>l.getProperties().some(g=>g.isKind(SyntaxKind.PropertyAssignment)&&g.getName()==="content"));if(!n)return e;let o=Ue(n);return ze(n,{name:"darkMode",value:"class"},{quoteChar:o}),t.plugins?.forEach(l=>{_e(n,l);}),t.theme&&await De(n,t.theme),i.getFullText()}function ze(e,t,{quoteChar:r}){let i=e.getProperty("darkMode");if(!i){let n={name:t.name,initializer:`[${r}${t.value}${r}]`};return t.name==="darkMode"?(e.insertPropertyAssignment(0,n),e):(e.addPropertyAssignment(n),e)}if(i.isKind(SyntaxKind.PropertyAssignment)){let n=i.getInitializer(),o=`${r}${t.value}${r}`;if(n?.isKind(SyntaxKind.StringLiteral)){let l=n.getText();return n.replaceWithText(`[${l}, ${o}]`),e}if(n?.isKind(SyntaxKind.ArrayLiteralExpression)){if(n.getElements().map(l=>l.getText()).includes(o))return e;n.addElement(o);}return e}return e}async function De(e,t){e.getProperty("theme")||e.addPropertyAssignment({name:"theme",initializer:"{}"}),z(e);let i=(e.getPropertyOrThrow("theme")?.asKindOrThrow(SyntaxKind.PropertyAssignment)).getInitializer();if(i?.isKind(SyntaxKind.ObjectLiteralExpression)){let n=i.getText(),o=await We(n),l=E(o,t,{arrayMerge:(y,p)=>p}),g=$e(l).replace(/\'\.\.\.(.*)\'/g,"...$1").replace(/\'\"/g,"'").replace(/\"\'/g,"'").replace(/\'\[/g,"[").replace(/\]\'/g,"]").replace(/\'\\\'/g,"'").replace(/\\\'/g,"'").replace(/\\\'\'/g,"'").replace(/\'\'/g,"'");i.replaceWithText(g);}D(e);}function _e(e,t){let r=e.getProperty("plugins");if(!r)return e.addPropertyAssignment({name:"plugins",initializer:`[${t}]`}),e;if(r.isKind(SyntaxKind.PropertyAssignment)){let i=r.getInitializer();if(i?.isKind(SyntaxKind.ArrayLiteralExpression)){if(i.getElements().map(n=>n.getText().replace(/["']/g,"")).includes(t.replace(/["']/g,"")))return e;i.addElement(t);}return e}return e}async function ee(e,t){let r=await promises.mkdtemp(w.join(tmpdir(),"shadcn-")),i=t?.resolvedPaths?.tailwindConfig||"tailwind.config.ts",n=w.join(r,`shadcn-${w.basename(i)}`);return new Project({compilerOptions:{}}).createSourceFile(n,e,{scriptKind:w.extname(i)===".ts"?ScriptKind.TS:ScriptKind.JS})}function Ue(e){return e.getFirstDescendantByKind(SyntaxKind.StringLiteral)?.getQuoteKind()===QuoteKind.Single?"'":'"'}function z(e){let t=e.getProperties();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(SyntaxKind.SpreadAssignment)){let n=i.asKindOrThrow(SyntaxKind.SpreadAssignment),o=n.getExpression().getText();e.insertPropertyAssignment(r,{name:`"___${o.replace(/^\.\.\./,"")}"`,initializer:`"...${o.replace(/^\.\.\./,"")}"`}),n.remove();}else if(i.isKind(SyntaxKind.PropertyAssignment)){let o=i.asKindOrThrow(SyntaxKind.PropertyAssignment).getInitializer();o&&o.isKind(SyntaxKind.ObjectLiteralExpression)?z(o.asKindOrThrow(SyntaxKind.ObjectLiteralExpression)):o&&o.isKind(SyntaxKind.ArrayLiteralExpression)&&te(o.asKindOrThrow(SyntaxKind.ArrayLiteralExpression));}}}function te(e){let t=e.getElements();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(SyntaxKind.ObjectLiteralExpression))z(i.asKindOrThrow(SyntaxKind.ObjectLiteralExpression));else if(i.isKind(SyntaxKind.ArrayLiteralExpression))te(i.asKindOrThrow(SyntaxKind.ArrayLiteralExpression));else if(i.isKind(SyntaxKind.SpreadElement)){let n=i.getText();e.removeElement(r),e.insertElement(r,`"${n}"`);}}}function D(e){let t=e.getProperties();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(SyntaxKind.PropertyAssignment)){let n=i,o=n.getInitializer();if(o&&o.isKind(SyntaxKind.StringLiteral)){let l=o.asKindOrThrow(SyntaxKind.StringLiteral).getLiteralValue();l.startsWith("...")&&(e.insertSpreadAssignment(r,{expression:l.slice(3)}),n.remove());}else o?.isKind(SyntaxKind.ObjectLiteralExpression)?D(o):o&&o.isKind(SyntaxKind.ArrayLiteralExpression)&&re(o.asKindOrThrow(SyntaxKind.ArrayLiteralExpression));}}}function re(e){let t=e.getElements();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(SyntaxKind.ObjectLiteralExpression))D(i.asKindOrThrow(SyntaxKind.ObjectLiteralExpression));else if(i.isKind(SyntaxKind.ArrayLiteralExpression))re(i.asKindOrThrow(SyntaxKind.ArrayLiteralExpression));else if(i.isKind(SyntaxKind.StringLiteral)){let n=i.getText(),o=/(?:^['"])(\.\.\..*)(?:['"]$)/g;o.test(n)&&(e.removeElement(r),e.insertElement(r,n.replace(o,"$1")));}}}async function We(e){let r=(await ee(`const theme = ${e}`,null)).getStatements()[0];if(r?.getKind()===SyntaxKind.VariableStatement){let n=(r.getDeclarationList()?.getDeclarations()[0]).getInitializer();if(n?.isKind(SyntaxKind.ObjectLiteralExpression))return await I(n)}throw new Error("Invalid input: not an object literal")}function I(e){let t={};for(let r of e.getProperties())if(r.isKind(SyntaxKind.PropertyAssignment)){let i=r.getName().replace(/\'/g,"");r.getInitializer()?.isKind(SyntaxKind.ObjectLiteralExpression)?t[i]=I(r.getInitializer()):r.getInitializer()?.isKind(SyntaxKind.ArrayLiteralExpression)?t[i]=ie(r.getInitializer()):t[i]=_(r.getInitializer());}return t}function ie(e){let t=[];for(let r of e.getElements())r.isKind(SyntaxKind.ObjectLiteralExpression)?t.push(I(r.asKindOrThrow(SyntaxKind.ObjectLiteralExpression))):r.isKind(SyntaxKind.ArrayLiteralExpression)?t.push(ie(r.asKindOrThrow(SyntaxKind.ArrayLiteralExpression))):t.push(_(r));return t}function _(e){switch(e.getKind()){case SyntaxKind.StringLiteral:return e.getText();case SyntaxKind.NumericLiteral:return Number(e.getText());case SyntaxKind.TrueKeyword:return !0;case SyntaxKind.FalseKeyword:return !1;case SyntaxKind.NullKeyword:return null;case SyntaxKind.ArrayLiteralExpression:return e.getElements().map(_);case SyntaxKind.ObjectLiteralExpression:return I(e);default:return e.getText()}}function ne(e){let t={};for(let r of Object.keys(e)){let i=r.split("-"),n=i[0],o=i.slice(1).join("-");o===""?typeof t[n]=="object"?t[n].DEFAULT=`hsl(var(--${r}))`:t[n]=`hsl(var(--${r}))`:(typeof t[n]!="object"&&(t[n]={DEFAULT:`hsl(var(--${n}))`}),t[n][o]=`hsl(var(--${r}))`);}for(let[r,i]of Object.entries(t))typeof i=="object"&&i.DEFAULT===`hsl(var(--${r}))`&&!(r in e)&&delete i.DEFAULT;return t}var Je=process.env.REGISTRY_URL??"https://ui.shadcn.com/r",Ye=process.env.https_proxy?new HttpsProxyAgent(process.env.https_proxy):void 0,A=new Map,He=[{name:"neutral",label:"Neutral"},{name:"gray",label:"Gray"},{name:"zinc",label:"Zinc"},{name:"stone",label:"Stone"},{name:"slate",label:"Slate"}];async function Qe(){try{let[e]=await P(["index.json"]);return R.parse(e)}catch(e){m.error(` `),b(e);}}async function Tr(){try{let[e]=await P(["styles/index.json"]);return N.parse(e)}catch(e){return m.error(` `),b(e),[]}}async function vr(){try{let[e]=await P(["icons/index.json"]);return M.parse(e)}catch(e){return b(e),{}}}async function Er(e,t){try{let[r]=await P([U(e)?e:`styles/${t}/${e}.json`]);return k.parse(r)}catch(r){return m.break(),b(r),null}}async function jr(){return He}async function Ze(e){try{let[t]=await P([`colors/${e}.json`]);return B.parse(t)}catch(t){b(t);}}async function qe(e,t){let r=[];for(let i of t){let n=e.find(o=>o.name===i);if(n&&(r.push(n),n.registryDependencies)){let o=await qe(e,n.registryDependencies);r.push(...o);}}return r.filter((i,n,o)=>o.findIndex(l=>l.name===i.name)===n)}async function Sr(e,t){try{let r=t.map(n=>`styles/${e}/${n.name}.json`),i=await P(r);return R.parse(i)}catch(r){b(r);}}async function Cr(e,t,r){if(r)return r;if(t.type==="registry:ui")return e.resolvedPaths.ui??e.resolvedPaths.components;let[i,n]=t.type?.split(":")??[];return i in e.resolvedPaths?w.join(e.resolvedPaths[i],n):null}async function P(e){try{return await Promise.all(e.map(async r=>{let i=se(r);if(A.has(i))return A.get(i);let n=(async()=>{let o=await Be(i,{agent:Ye});if(!o.ok){let l={400:"Bad request",401:"Unauthorized",403:"Forbidden",404:"Not found",500:"Internal server error"};if(o.status===401)throw new Error(`You are not authorized to access the component at ${u.info(i)}. If this is a remote registry, you may need to authenticate.`);if(o.status===404)throw new Error(`The component at ${u.info(i)} was not found. It may not exist at the registry. Please make sure it is a valid component.`);if(o.status===403)throw new Error(`You do not have access to the component at ${u.info(i)}. If this is a remote registry, you may need to authenticate or a token.`);let g=await o.json(),y=g&&typeof g=="object"&&"error"in g?g.error:o.statusText||l[o.status];throw new Error(`Failed to fetch from ${u.info(i)}. ${y}`)}return o.json()})();return A.set(i,n),n}))}catch(t){return m.error(` `),b(t),[]}}function Lr(){A.clear();}async function Xe(e,t){try{if(!await Qe())return null;e.includes("index")&&e.unshift("index");let i=await rt(e,t),n=await P(i),o=z$1.array(k).parse(n);if(!o)return null;if(e.includes("index")&&t.tailwind.baseColor){let p=await tt(t.tailwind.baseColor,t);p&&o.unshift(p);}let l={};o.forEach(p=>{l=E(l,p.tailwind??{});});let g={};o.forEach(p=>{g=E(g,p.cssVars??{});});let y="";return o.forEach(p=>{p.docs&&(y+=`${p.docs} `);}),G.parse({dependencies:E.all(o.map(p=>p.dependencies??[])),devDependencies:E.all(o.map(p=>p.devDependencies??[])),files:E.all(o.map(p=>p.files??[])),tailwind:l,cssVars:g,docs:y})}catch(r){return b(r),null}}async function et(e,t){let r=new Set,i=[],n=t.resolvedPaths?.cwd?await Z(t.resolvedPaths.cwd,t.style):t.style;async function o(l){let g=se(U(l)?l:`styles/${n}/${l}.json`);if(!r.has(g)){r.add(g);try{let[y]=await P([g]),p=k.parse(y);if(i.push(g),p.registryDependencies)for(let f of p.registryDependencies)await o(f);}catch(y){console.error(`Error fetching or parsing registry item at ${l}:`,y);}}}return await o(e),Array.from(new Set(i))}async function tt(e,t){let[r,i]=await Promise.all([Ze(e),Y(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:{light:{radius:"0.5rem"},dark:{}}};return t.tailwind.cssVariables&&(n.tailwind.config.theme.extend.colors={...n.tailwind.config.theme.extend.colors,...ne(r.cssVars.dark)},n.cssVars={light:{...r.cssVars.light,...n.cssVars.light},dark:{...r.cssVars.dark,...n.cssVars.dark}},i==="v4"&&r.cssVarsV4&&(n.cssVars={light:{radius:"0.625rem",...r.cssVarsV4.light},dark:{...r.cssVarsV4.dark}})),n}function se(e){if(U(e)){let t=new URL(e);return t.pathname.match(/\/chat\/b\//)&&!t.pathname.endsWith("/json")&&(t.pathname=`${t.pathname}/json`),t.toString()}return `${Je}/${e}`}function U(e){try{return new URL(e),!0}catch{return !1}}async function rt(e,t){let r=[];for(let i of e){let n=await et(i,t);r.push(...n);}return Array.from(new Set(r))}function Ir(){return new Map([["registry:ui","ui"],["registry:lib","lib"],["registry:hook","hooks"],["registry:block","components"],["registry:component","components"]])}function Ar(e){let t=new Map;return e.forEach(r=>{r.registryDependencies&&r.registryDependencies.forEach(i=>{t.set(i,r);});}),t} export { nt as A, R as B, N as C, M as D, B as E, G as F, He as G, Qe as H, Tr as I, vr as J, Er as K, jr as L, Ze as M, qe as N, Sr as O, Cr as P, P as Q, Lr as R, Xe as S, tt as T, rt as U, Ir as V, Ar as W, u as a, Ft as b, Vt as c, zt as d, Dt as e, H as f, j as g, F as h, _t as i, Se as j, Le as k, O as l, L as m, kt as n, Y as o, m as p, q, b as r, lr as s, ee as t, Ue as u, W as v, oe as w, ae as x, le as y, k as z }; //# sourceMappingURL=out.js.map //# sourceMappingURL=chunk-7Y6F47JO.js.map