shadcn 0.0.0-beta.90e6dc1 → 0.0.0-beta.9df4b2e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ import { z } from 'zod';
11
11
  import U from 'fs-extra';
12
12
  import Ar from 'ora';
13
13
  import Ji, { tmpdir } from 'os';
14
- import X from 'deepmerge';
14
+ import Z from 'deepmerge';
15
15
  import _r from 'stringify-object';
16
16
  import { Project, ScriptKind, SyntaxKind, QuoteKind } from 'ts-morph';
17
17
  import { HttpsProxyAgent } from 'https-proxy-agent';
@@ -26,51 +26,51 @@ import { parse } from '@babel/parser';
26
26
  import Ti from '@babel/plugin-transform-typescript';
27
27
  import * as ue from 'recast';
28
28
  import { Command } from 'commander';
29
- import * as re from 'fs/promises';
30
- import re__default from 'fs/promises';
29
+ import * as ie from 'fs/promises';
30
+ import ie__default from 'fs/promises';
31
31
  import { diffLines } from 'diff';
32
32
  import { randomBytes } from 'crypto';
33
33
 
34
- var C="1";var D="3";var ne="5",je="6",dt="7";var Oe="13";var $={"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"}},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"}},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"}}};var l={error:red,warn:yellow,info:cyan,success:green};async function N(e,t){return createMatchPath(t.absoluteBaseUrl,t.paths)(e,void 0,()=>!0,[".ts",".tsx"])}var ut="@/components",gt="@/lib/utils",ht="app/globals.css",yt="tailwind.config.js";var Rr=cosmiconfig("components",{searchPlaces:["components.json"]}),Y=z.object({$schema:z.string().optional(),style:z.string(),rsc:z.coerce.boolean().default(!1),tsx:z.coerce.boolean().default(!0),tailwind:z.object({config:z.string().optional(),css:z.string(),baseColor:z.string(),cssVariables:z.boolean().default(!0),prefix:z.string().default("").optional()}),aliases:z.object({components:z.string(),utils:z.string(),ui:z.string().optional(),lib:z.string().optional(),hooks:z.string().optional()}),iconLibrary:z.string().optional()}).strict(),wt=Y.extend({resolvedPaths:z.object({cwd:z.string(),tailwindConfig:z.string(),tailwindCss:z.string(),utils:z.string(),components:z.string(),lib:z.string(),hooks:z.string(),ui:z.string()})}),Cr=z.record(wt);async function R(e){let t=await Ir(e);return t?(t.iconLibrary||(t.iconLibrary=t.style==="new-york"?"radix":"lucide"),await H(e,t)):null}async function H(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 wt.parse({...t,resolvedPaths:{cwd:e,tailwindConfig:t.tailwind.config?T__default.resolve(e,t.tailwind.config):"",tailwindCss:T__default.resolve(e,t.tailwind.css),utils:await N(t.aliases.utils,r),components:await N(t.aliases.components,r),ui:t.aliases.ui?await N(t.aliases.ui,r):T__default.resolve(await N(t.aliases.components,r)??e,"ui"),lib:t.aliases.lib?await N(t.aliases.lib,r):T__default.resolve(await N(t.aliases.utils,r)??e,".."),hooks:t.aliases.hooks?await N(t.aliases.hooks,r):T__default.resolve(await N(t.aliases.components,r)??e,"..","hooks")}})}async function Ir(e){try{let t=await Rr.search(e);return t?Y.parse(t.config):null}catch{let r=`${e}/components.json`;throw new Error(`Invalid configuration found in ${l.info(r)}.`)}}async function xt(e){let t={};for(let i of Object.keys(e.aliases)){if(!Pr(i,e))continue;let n=e.resolvedPaths[i],o=await $e(e.resolvedPaths.cwd,n);if(!o){t[i]=e;continue}t[i]=await R(o);}let r=Cr.safeParse(t);return r.success?r.data:null}async function $e(e,t){let r=Ne(e,t),i=T__default.relative(r,t),o=(await oe.glob("**/package.json",{cwd:r,deep:3,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/public/**"]})).map(s=>T__default.dirname(s)).find(s=>i.startsWith(s));return o?T__default.join(r,o):null}function Pr(e,t){return Object.keys(t.resolvedPaths).filter(r=>r!=="utils").includes(e)}function Ne(e,t){let r=e.split(T__default.sep),i=t.split(T__default.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(T__default.sep)}function q(e="",t=!0){let r=T__default.join(e,"package.json");return U.readJSONSync(r,{throws:t})}var se=["**/node_modules/**",".next","public","dist","build"];z.object({compilerOptions:z.object({paths:z.record(z.string().or(z.array(z.string())))})});async function j(e){let[t,r,i,n,o,s,a,m]=await Promise.all([oe.glob("**/{next,vite,astro}.config.*|gatsby-config.*|composer.json",{cwd:e,deep:3,ignore:se}),U.pathExists(T__default.resolve(e,"src")),Nr(e),Or(e),jr(e),bt(e),$r(e),q(e,!1)]),p=await U.pathExists(T__default.resolve(e,`${r?"src/":""}app`)),f={framework:$.manual,isSrcDir:r,isRSC:!1,isTsx:i,tailwindConfigFile:n,tailwindCssFile:o,tailwindVersion:s,aliasPrefix:a};return t.find(d=>d.startsWith("next.config."))?.length?(f.framework=p?$["next-app"]:$["next-pages"],f.isRSC=p,f):t.find(d=>d.startsWith("astro.config."))?.length?(f.framework=$.astro,f):t.find(d=>d.startsWith("gatsby-config."))?.length?(f.framework=$.gatsby,f):t.find(d=>d.startsWith("composer.json"))?.length?(f.framework=$.laravel,f):Object.keys(m?.dependencies??{}).find(d=>d.startsWith("@remix-run/"))?(f.framework=$.remix,f):(t.find(d=>d.startsWith("vite.config."))?.length&&(f.framework=$.vite),f)}async function bt(e){let t=q(e);return !t?.dependencies?.tailwindcss&&!t?.devDependencies?.tailwindcss?null:/^(?:\^|~)?3(?:\.\d+)*(?:-.*)?$/.test(t?.dependencies?.tailwindcss||t?.devDependencies?.tailwindcss||"")?"v3":"v4"}async function jr(e){let[t,r]=await Promise.all([oe.glob(["**/*.css","**/*.scss"],{cwd:e,deep:5,ignore:se}),bt(e)]);if(!t.length)return null;for(let i of t){let n=await U.readFile(T__default.resolve(e,i),"utf8");if(n.includes('@import "tailwindcss"')||n.includes("@import 'tailwindcss'")||n.includes("@tailwind base"))return i}return null}async function Or(e){let t=await oe.glob("tailwind.config.*",{cwd:e,deep:3,ignore:se});return t.length?t[0]:null}async function $r(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 Nr(e){return (await oe.glob("tsconfig.*",{cwd:e,deep:1,ignore:se})).length>0}async function St(e,t=null){let[r,i]=await Promise.all([R(e),t?Promise.resolve(t):j(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 H(e,n)}async function De(e){if(!e.resolvedPaths.cwd)return "v3";let t=await j(e.resolvedPaths.cwd);return t?.tailwindVersion?t.tailwindVersion:null}var c={error(...e){console.log(l.error(e.join(" ")));},warn(...e){console.log(l.warn(e.join(" ")));},info(...e){console.log(l.info(e.join(" ")));},success(...e){console.log(l.success(e.join(" ")));},log(...e){console.log(e.join(" "));},break(){console.log("");}};function g(e,t){return Ar({text:e,isSilent:t?.silent})}async function Rt(e){let t={};if(!U.existsSync(e.cwd)||!U.existsSync(T__default.resolve(e.cwd,"package.json")))return t[C]=!0,{errors:t,projectInfo:null};let r=g("Preflight checks.",{silent:e.silent}).start();U.existsSync(T__default.resolve(e.cwd,"components.json"))&&!e.force&&(r?.fail(),c.break(),c.error(`A ${l.info("components.json")} file already exists at ${l.info(e.cwd)}.
35
- To start over, remove the ${l.info("components.json")} file and run ${l.info("init")} again.`),c.break(),process.exit(1)),r?.succeed();let i=g("Verifying framework.",{silent:e.silent}).start(),n=await j(e.cwd);(!n||n?.framework.name==="manual")&&(t[dt]=!0,i?.fail(),c.break(),n?.framework.links.installation&&c.error(`We could not detect a supported framework at ${l.info(e.cwd)}.
34
+ var C="1";var D="3";var Y="5",je="6",dt="7";var Oe="13";var j={"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"}},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"}}};var l={error:red,warn:yellow,info:cyan,success:green};async function N(e,t){return createMatchPath(t.absoluteBaseUrl,t.paths)(e,void 0,()=>!0,[".ts",".tsx"])}var ut="@/components",gt="@/lib/utils",ht="app/globals.css",yt="tailwind.config.js";var Rr=cosmiconfig("components",{searchPlaces:["components.json"]}),H=z.object({$schema:z.string().optional(),style:z.string(),rsc:z.coerce.boolean().default(!1),tsx:z.coerce.boolean().default(!0),tailwind:z.object({config:z.string().optional(),css:z.string(),baseColor:z.string(),cssVariables:z.boolean().default(!0),prefix:z.string().default("").optional()}),aliases:z.object({components:z.string(),utils:z.string(),ui:z.string().optional(),lib:z.string().optional(),hooks:z.string().optional()}),iconLibrary:z.string().optional()}).strict(),wt=H.extend({resolvedPaths:z.object({cwd:z.string(),tailwindConfig:z.string(),tailwindCss:z.string(),utils:z.string(),components:z.string(),lib:z.string(),hooks:z.string(),ui:z.string()})}),Cr=z.record(wt);async function R(e){let t=await Ir(e);return t?(t.iconLibrary||(t.iconLibrary=t.style==="new-york"?"radix":"lucide"),await q(e,t)):null}async function q(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 wt.parse({...t,resolvedPaths:{cwd:e,tailwindConfig:t.tailwind.config?T__default.resolve(e,t.tailwind.config):"",tailwindCss:T__default.resolve(e,t.tailwind.css),utils:await N(t.aliases.utils,r),components:await N(t.aliases.components,r),ui:t.aliases.ui?await N(t.aliases.ui,r):T__default.resolve(await N(t.aliases.components,r)??e,"ui"),lib:t.aliases.lib?await N(t.aliases.lib,r):T__default.resolve(await N(t.aliases.utils,r)??e,".."),hooks:t.aliases.hooks?await N(t.aliases.hooks,r):T__default.resolve(await N(t.aliases.components,r)??e,"..","hooks")}})}async function Ir(e){try{let t=await Rr.search(e);return t?H.parse(t.config):null}catch{let r=`${e}/components.json`;throw new Error(`Invalid configuration found in ${l.info(r)}.`)}}async function xt(e){let t={};for(let i of Object.keys(e.aliases)){if(!Pr(i,e))continue;let n=e.resolvedPaths[i],o=await $e(e.resolvedPaths.cwd,n);if(!o){t[i]=e;continue}t[i]=await R(o);}let r=Cr.safeParse(t);return r.success?r.data:null}async function $e(e,t){let r=Ne(e,t),i=T__default.relative(r,t),o=(await oe.glob("**/package.json",{cwd:r,deep:3,ignore:["**/node_modules/**","**/dist/**","**/build/**","**/public/**"]})).map(s=>T__default.dirname(s)).find(s=>i.startsWith(s));return o?T__default.join(r,o):null}function Pr(e,t){return Object.keys(t.resolvedPaths).filter(r=>r!=="utils").includes(e)}function Ne(e,t){let r=e.split(T__default.sep),i=t.split(T__default.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(T__default.sep)}function Q(e="",t=!0){let r=T__default.join(e,"package.json");return U.readJSONSync(r,{throws:t})}var se=["**/node_modules/**",".next","public","dist","build"];z.object({compilerOptions:z.object({paths:z.record(z.string().or(z.array(z.string())))})});async function O(e){let[t,r,i,n,o,s,a,f]=await Promise.all([oe.glob("**/{next,vite,astro,app}.config.*|gatsby-config.*|composer.json",{cwd:e,deep:3,ignore:se}),U.pathExists(T__default.resolve(e,"src")),Nr(e),Or(e),jr(e),bt(e),$r(e),Q(e,!1)]),p=await U.pathExists(T__default.resolve(e,`${r?"src/":""}app`)),m={framework:j.manual,isSrcDir:r,isRSC:!1,isTsx:i,tailwindConfigFile:n,tailwindCssFile:o,tailwindVersion:s,aliasPrefix:a};return t.find(d=>d.startsWith("next.config."))?.length?(m.framework=p?j["next-app"]:j["next-pages"],m.isRSC=p,m):t.find(d=>d.startsWith("astro.config."))?.length?(m.framework=j.astro,m):t.find(d=>d.startsWith("gatsby-config."))?.length?(m.framework=j.gatsby,m):t.find(d=>d.startsWith("composer.json"))?.length?(m.framework=j.laravel,m):Object.keys(f?.dependencies??{}).find(d=>d.startsWith("@remix-run/"))?(m.framework=j.remix,m):t.find(d=>d.startsWith("app.config."))?.length&&Object.keys(f?.dependencies??{}).find(d=>d.startsWith("@tanstack/start"))?(m.framework=j["tanstack-start"],m):(t.find(d=>d.startsWith("vite.config."))?.length&&(m.framework=j.vite),m)}async function bt(e){let t=Q(e);return !t?.dependencies?.tailwindcss&&!t?.devDependencies?.tailwindcss?null:/^(?:\^|~)?3(?:\.\d+)*(?:-.*)?$/.test(t?.dependencies?.tailwindcss||t?.devDependencies?.tailwindcss||"")?"v3":"v4"}async function jr(e){let[t,r]=await Promise.all([oe.glob(["**/*.css","**/*.scss"],{cwd:e,deep:5,ignore:se}),bt(e)]);if(!t.length)return null;for(let n of t){let o=await U.readFile(T__default.resolve(e,n),"utf8");if(o.includes('@import "tailwindcss"')||o.includes("@import 'tailwindcss'")||o.includes("@tailwind base"))return n}return null}async function Or(e){let t=await oe.glob("tailwind.config.*",{cwd:e,deep:3,ignore:se});return t.length?t[0]:null}async function $r(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 Nr(e){return (await oe.glob("tsconfig.*",{cwd:e,deep:1,ignore:se})).length>0}async function St(e,t=null){let[r,i]=await Promise.all([R(e),t?Promise.resolve(t):O(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 q(e,n)}async function De(e){if(!e.resolvedPaths.cwd)return "v3";let t=await O(e.resolvedPaths.cwd);return t?.tailwindVersion?t.tailwindVersion:null}var c={error(...e){console.log(l.error(e.join(" ")));},warn(...e){console.log(l.warn(e.join(" ")));},info(...e){console.log(l.info(e.join(" ")));},success(...e){console.log(l.success(e.join(" ")));},log(...e){console.log(e.join(" "));},break(){console.log("");}};function g(e,t){return Ar({text:e,isSilent:t?.silent})}async function Rt(e){let t={};if(!U.existsSync(e.cwd)||!U.existsSync(T__default.resolve(e.cwd,"package.json")))return t[C]=!0,{errors:t,projectInfo:null};let r=g("Preflight checks.",{silent:e.silent}).start();U.existsSync(T__default.resolve(e.cwd,"components.json"))&&!e.force&&(r?.fail(),c.break(),c.error(`A ${l.info("components.json")} file already exists at ${l.info(e.cwd)}.
35
+ To start over, remove the ${l.info("components.json")} file and run ${l.info("init")} again.`),c.break(),process.exit(1)),r?.succeed();let i=g("Verifying framework.",{silent:e.silent}).start(),n=await O(e.cwd);(!n||n?.framework.name==="manual")&&(t[dt]=!0,i?.fail(),c.break(),n?.framework.links.installation&&c.error(`We could not detect a supported framework at ${l.info(e.cwd)}.
36
36
  Visit ${l.info(n?.framework.links.installation)} to manually configure your project.
37
- Once configured, you can use the cli to add components.`),c.break(),process.exit(1)),i?.succeed(`Verifying framework. Found ${l.info(n.framework.label)}.`);let o="Validating Tailwind CSS.";n.tailwindVersion==="v4"&&(o=`Validating Tailwind CSS config. Found ${l.info("v4")}.`);let s=g(o,{silent:e.silent}).start();n.tailwindVersion==="v3"&&(!n?.tailwindConfigFile||!n?.tailwindCssFile)?(t[ne]=!0,s?.fail()):n.tailwindVersion==="v4"&&!n?.tailwindCssFile?(t[ne]=!0,s?.fail()):s?.succeed();let a=g("Validating import alias.",{silent:e.silent}).start();return n?.aliasPrefix?a?.succeed():(t[je]=!0,a?.fail()),Object.keys(t).length>0&&(t[ne]&&(c.break(),c.error(`No Tailwind CSS configuration found at ${l.info(e.cwd)}.`),c.error("It is likely you do not have Tailwind CSS installed or have an invalid configuration."),c.error("Install Tailwind CSS then try again."),n?.framework.links.tailwind&&c.error(`Visit ${l.info(n?.framework.links.tailwind)} to get started.`)),t[je]&&(c.break(),c.error("No import alias found in your tsconfig.json file."),n?.framework.links.installation&&c.error(`Visit ${l.info(n?.framework.links.installation)} to learn how to set an import alias.`)),c.break(),process.exit(1)),{errors:t,projectInfo:n}}function y(e){if(c.error("Something went wrong. Please check the error below for more details."),c.error("If the problem persists, please open an issue on GitHub."),c.error(""),typeof e=="string"&&(c.error(e),c.break(),process.exit(1)),e instanceof z.ZodError){c.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))c.error(`- ${l.info(t)}: ${r}`);c.break(),process.exit(1);}e instanceof Error&&(c.error(e.message),c.break(),process.exit(1)),c.break(),process.exit(1);}async function Ve(e,t,r){if(!e||(r={silent:!1,tailwindVersion:"v3",...r},r.tailwindVersion==="v4"))return;let i=T__default.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=g(`Updating ${l.info(i)}`,{silent:r.silent}).start(),o=await promises.readFile(t.resolvedPaths.tailwindConfig,"utf8"),s=await Kr(o,e,t);await promises.writeFile(t.resolvedPaths.tailwindConfig,s,"utf8"),n?.succeed();}async function Kr(e,t,r){let i=await ae(e,r),n=i.getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression).find(s=>s.getProperties().some(a=>a.isKind(SyntaxKind.PropertyAssignment)&&a.getName()==="content"));if(!n)return e;let o=ze(n);return Mr(n,{name:"darkMode",value:"class"},{quoteChar:o}),t.plugins?.forEach(s=>{Ur(n,s);}),t.theme&&await Wr(n,t.theme),i.getFullText()}function Mr(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 s=n.getText();return n.replaceWithText(`[${s}, ${o}]`),e}if(n?.isKind(SyntaxKind.ArrayLiteralExpression)){if(n.getElements().map(s=>s.getText()).includes(o))return e;n.addElement(o);}return e}return e}async function Wr(e,t){e.getProperty("theme")||e.addPropertyAssignment({name:"theme",initializer:"{}"}),Ke(e);let i=(e.getPropertyOrThrow("theme")?.asKindOrThrow(SyntaxKind.PropertyAssignment)).getInitializer();if(i?.isKind(SyntaxKind.ObjectLiteralExpression)){let n=i.getText(),o=await Br(n),s=X(o,t,{arrayMerge:(m,p)=>p}),a=_r(s).replace(/\'\.\.\.(.*)\'/g,"...$1").replace(/\'\"/g,"'").replace(/\"\'/g,"'").replace(/\'\[/g,"[").replace(/\]\'/g,"]").replace(/\'\\\'/g,"'").replace(/\\\'/g,"'").replace(/\\\'\'/g,"'").replace(/\'\'/g,"'");i.replaceWithText(a);}Me(e);}function Ur(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 ae(e,t){let r=await promises.mkdtemp(T__default.join(tmpdir(),"shadcn-")),i=t?.resolvedPaths?.tailwindConfig||"tailwind.config.ts",n=T__default.join(r,`shadcn-${T__default.basename(i)}`);return new Project({compilerOptions:{}}).createSourceFile(n,e,{scriptKind:T__default.extname(i)===".ts"?ScriptKind.TS:ScriptKind.JS})}function ze(e){return e.getFirstDescendantByKind(SyntaxKind.StringLiteral)?.getQuoteKind()===QuoteKind.Single?"'":'"'}function Ke(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)?Ke(o.asKindOrThrow(SyntaxKind.ObjectLiteralExpression)):o&&o.isKind(SyntaxKind.ArrayLiteralExpression)&&It(o.asKindOrThrow(SyntaxKind.ArrayLiteralExpression));}}}function It(e){let t=e.getElements();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(SyntaxKind.ObjectLiteralExpression))Ke(i.asKindOrThrow(SyntaxKind.ObjectLiteralExpression));else if(i.isKind(SyntaxKind.ArrayLiteralExpression))It(i.asKindOrThrow(SyntaxKind.ArrayLiteralExpression));else if(i.isKind(SyntaxKind.SpreadElement)){let n=i.getText();e.removeElement(r),e.insertElement(r,`"${n}"`);}}}function Me(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 s=o.asKindOrThrow(SyntaxKind.StringLiteral).getLiteralValue();s.startsWith("...")&&(e.insertSpreadAssignment(r,{expression:s.slice(3)}),n.remove());}else o?.isKind(SyntaxKind.ObjectLiteralExpression)?Me(o):o&&o.isKind(SyntaxKind.ArrayLiteralExpression)&&Pt(o.asKindOrThrow(SyntaxKind.ArrayLiteralExpression));}}}function Pt(e){let t=e.getElements();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(SyntaxKind.ObjectLiteralExpression))Me(i.asKindOrThrow(SyntaxKind.ObjectLiteralExpression));else if(i.isKind(SyntaxKind.ArrayLiteralExpression))Pt(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 Br(e){let r=(await ae(`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 ce(n)}throw new Error("Invalid input: not an object literal")}function ce(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]=ce(r.getInitializer()):r.getInitializer()?.isKind(SyntaxKind.ArrayLiteralExpression)?t[i]=kt(r.getInitializer()):t[i]=We(r.getInitializer());}return t}function kt(e){let t=[];for(let r of e.getElements())r.isKind(SyntaxKind.ObjectLiteralExpression)?t.push(ce(r.asKindOrThrow(SyntaxKind.ObjectLiteralExpression))):r.isKind(SyntaxKind.ArrayLiteralExpression)?t.push(kt(r.asKindOrThrow(SyntaxKind.ArrayLiteralExpression))):t.push(We(r));return t}function We(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(We);case SyntaxKind.ObjectLiteralExpression:return ce(e);default:return e.getText()}}function Tt(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 qr=process.env.REGISTRY_URL??"https://ui.shadcn.com/r",Qr=process.env.https_proxy?new HttpsProxyAgent(process.env.https_proxy):void 0;async function Z(){try{let[e]=await I(["index.json"]);return g$1.parse(e)}catch(e){c.error(`
37
+ Once configured, you can use the cli to add components.`),c.break(),process.exit(1)),i?.succeed(`Verifying framework. Found ${l.info(n.framework.label)}.`);let o="Validating Tailwind CSS.";n.tailwindVersion==="v4"&&(o=`Validating Tailwind CSS config. Found ${l.info("v4")}.`);let s=g(o,{silent:e.silent}).start();n.tailwindVersion==="v3"&&(!n?.tailwindConfigFile||!n?.tailwindCssFile)?(t[Y]=!0,s?.fail()):n.tailwindVersion==="v4"&&!n?.tailwindCssFile?(t[Y]=!0,s?.fail()):n.tailwindVersion?s?.succeed():(t[Y]=!0,s?.fail());let a=g("Validating import alias.",{silent:e.silent}).start();return n?.aliasPrefix?a?.succeed():(t[je]=!0,a?.fail()),Object.keys(t).length>0&&(t[Y]&&(c.break(),c.error(`No Tailwind CSS configuration found at ${l.info(e.cwd)}.`),c.error("It is likely you do not have Tailwind CSS installed or have an invalid configuration."),c.error("Install Tailwind CSS then try again."),n?.framework.links.tailwind&&c.error(`Visit ${l.info(n?.framework.links.tailwind)} to get started.`)),t[je]&&(c.break(),c.error("No import alias found in your tsconfig.json file."),n?.framework.links.installation&&c.error(`Visit ${l.info(n?.framework.links.installation)} to learn how to set an import alias.`)),c.break(),process.exit(1)),{errors:t,projectInfo:n}}function y(e){if(c.error("Something went wrong. Please check the error below for more details."),c.error("If the problem persists, please open an issue on GitHub."),c.error(""),typeof e=="string"&&(c.error(e),c.break(),process.exit(1)),e instanceof z.ZodError){c.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))c.error(`- ${l.info(t)}: ${r}`);c.break(),process.exit(1);}e instanceof Error&&(c.error(e.message),c.break(),process.exit(1)),c.break(),process.exit(1);}async function Ve(e,t,r){if(!e||(r={silent:!1,tailwindVersion:"v3",...r},r.tailwindVersion==="v4"))return;let i=T__default.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=g(`Updating ${l.info(i)}`,{silent:r.silent}).start(),o=await promises.readFile(t.resolvedPaths.tailwindConfig,"utf8"),s=await Kr(o,e,t);await promises.writeFile(t.resolvedPaths.tailwindConfig,s,"utf8"),n?.succeed();}async function Kr(e,t,r){let i=await ae(e,r),n=i.getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression).find(s=>s.getProperties().some(a=>a.isKind(SyntaxKind.PropertyAssignment)&&a.getName()==="content"));if(!n)return e;let o=ze(n);return Mr(n,{name:"darkMode",value:"class"},{quoteChar:o}),t.plugins?.forEach(s=>{Ur(n,s);}),t.theme&&await Wr(n,t.theme),i.getFullText()}function Mr(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 s=n.getText();return n.replaceWithText(`[${s}, ${o}]`),e}if(n?.isKind(SyntaxKind.ArrayLiteralExpression)){if(n.getElements().map(s=>s.getText()).includes(o))return e;n.addElement(o);}return e}return e}async function Wr(e,t){e.getProperty("theme")||e.addPropertyAssignment({name:"theme",initializer:"{}"}),Ke(e);let i=(e.getPropertyOrThrow("theme")?.asKindOrThrow(SyntaxKind.PropertyAssignment)).getInitializer();if(i?.isKind(SyntaxKind.ObjectLiteralExpression)){let n=i.getText(),o=await Br(n),s=Z(o,t,{arrayMerge:(f,p)=>p}),a=_r(s).replace(/\'\.\.\.(.*)\'/g,"...$1").replace(/\'\"/g,"'").replace(/\"\'/g,"'").replace(/\'\[/g,"[").replace(/\]\'/g,"]").replace(/\'\\\'/g,"'").replace(/\\\'/g,"'").replace(/\\\'\'/g,"'").replace(/\'\'/g,"'");i.replaceWithText(a);}Me(e);}function Ur(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 ae(e,t){let r=await promises.mkdtemp(T__default.join(tmpdir(),"shadcn-")),i=t?.resolvedPaths?.tailwindConfig||"tailwind.config.ts",n=T__default.join(r,`shadcn-${T__default.basename(i)}`);return new Project({compilerOptions:{}}).createSourceFile(n,e,{scriptKind:T__default.extname(i)===".ts"?ScriptKind.TS:ScriptKind.JS})}function ze(e){return e.getFirstDescendantByKind(SyntaxKind.StringLiteral)?.getQuoteKind()===QuoteKind.Single?"'":'"'}function Ke(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)?Ke(o.asKindOrThrow(SyntaxKind.ObjectLiteralExpression)):o&&o.isKind(SyntaxKind.ArrayLiteralExpression)&&It(o.asKindOrThrow(SyntaxKind.ArrayLiteralExpression));}}}function It(e){let t=e.getElements();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(SyntaxKind.ObjectLiteralExpression))Ke(i.asKindOrThrow(SyntaxKind.ObjectLiteralExpression));else if(i.isKind(SyntaxKind.ArrayLiteralExpression))It(i.asKindOrThrow(SyntaxKind.ArrayLiteralExpression));else if(i.isKind(SyntaxKind.SpreadElement)){let n=i.getText();e.removeElement(r),e.insertElement(r,`"${n}"`);}}}function Me(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 s=o.asKindOrThrow(SyntaxKind.StringLiteral).getLiteralValue();s.startsWith("...")&&(e.insertSpreadAssignment(r,{expression:s.slice(3)}),n.remove());}else o?.isKind(SyntaxKind.ObjectLiteralExpression)?Me(o):o&&o.isKind(SyntaxKind.ArrayLiteralExpression)&&Pt(o.asKindOrThrow(SyntaxKind.ArrayLiteralExpression));}}}function Pt(e){let t=e.getElements();for(let r=0;r<t.length;r++){let i=t[r];if(i.isKind(SyntaxKind.ObjectLiteralExpression))Me(i.asKindOrThrow(SyntaxKind.ObjectLiteralExpression));else if(i.isKind(SyntaxKind.ArrayLiteralExpression))Pt(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 Br(e){let r=(await ae(`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 ce(n)}throw new Error("Invalid input: not an object literal")}function ce(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]=ce(r.getInitializer()):r.getInitializer()?.isKind(SyntaxKind.ArrayLiteralExpression)?t[i]=kt(r.getInitializer()):t[i]=We(r.getInitializer());}return t}function kt(e){let t=[];for(let r of e.getElements())r.isKind(SyntaxKind.ObjectLiteralExpression)?t.push(ce(r.asKindOrThrow(SyntaxKind.ObjectLiteralExpression))):r.isKind(SyntaxKind.ArrayLiteralExpression)?t.push(kt(r.asKindOrThrow(SyntaxKind.ArrayLiteralExpression))):t.push(We(r));return t}function We(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(We);case SyntaxKind.ObjectLiteralExpression:return ce(e);default:return e.getText()}}function Tt(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 qr=process.env.REGISTRY_URL??"https://ui.shadcn.com/r",Qr=process.env.https_proxy?new HttpsProxyAgent(process.env.https_proxy):void 0;async function ee(){try{let[e]=await I(["index.json"]);return g$1.parse(e)}catch(e){c.error(`
38
38
  `),y(e);}}async function Ue(){try{let[e]=await I(["styles/index.json"]);return h.parse(e)}catch(e){return c.error(`
39
- `),y(e),[]}}async function le(){try{let[e]=await I(["icons/index.json"]);return i.parse(e)}catch(e){return y(e),{}}}async function Et(e$1,t){try{let[r]=await I([Ge(e$1)?e$1:`styles/${t}/${e$1}.json`]);return e.parse(r)}catch(r){return c.break(),y(r),null}}async function Be(){return [{name:"neutral",label:"Neutral"},{name:"gray",label:"Gray"},{name:"zinc",label:"Zinc"},{name:"stone",label:"Stone"},{name:"slate",label:"Slate"}]}async function ee(e){try{let[t]=await I([`colors/${e}.json`]);return j$1.parse(t)}catch(t){y(t);}}async function Xr(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 Xr(e,n.registryDependencies);r.push(...o);}}return r.filter((i,n,o)=>o.findIndex(s=>s.name===i.name)===n)}async function jt(e,t){try{let r=t.map(n=>`styles/${e}/${n.name}.json`),i=await I(r);return g$1.parse(i)}catch(r){y(r);}}async function Ot(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?T__default.join(e.resolvedPaths[i],n):null}async function I(e){try{return await Promise.all(e.map(async r=>{let i=Nt(r),n=await Yr(i,{agent:Qr});if(!n.ok){let o={400:"Bad request",401:"Unauthorized",403:"Forbidden",404:"Not found",500:"Internal server error"};if(n.status===401)throw new Error(`You are not authorized to access the component at ${l.info(i)}.
39
+ `),y(e),[]}}async function le(){try{let[e]=await I(["icons/index.json"]);return i.parse(e)}catch(e){return y(e),{}}}async function Et(e$1,t){try{let[r]=await I([Ge(e$1)?e$1:`styles/${t}/${e$1}.json`]);return e.parse(r)}catch(r){return c.break(),y(r),null}}async function Be(){return [{name:"neutral",label:"Neutral"},{name:"gray",label:"Gray"},{name:"zinc",label:"Zinc"},{name:"stone",label:"Stone"},{name:"slate",label:"Slate"}]}async function te(e){try{let[t]=await I([`colors/${e}.json`]);return j$1.parse(t)}catch(t){y(t);}}async function Xr(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 Xr(e,n.registryDependencies);r.push(...o);}}return r.filter((i,n,o)=>o.findIndex(s=>s.name===i.name)===n)}async function jt(e,t){try{let r=t.map(n=>`styles/${e}/${n.name}.json`),i=await I(r);return g$1.parse(i)}catch(r){y(r);}}async function Ot(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?T__default.join(e.resolvedPaths[i],n):null}async function I(e){try{return await Promise.all(e.map(async r=>{let i=Nt(r),n=await Yr(i,{agent:Qr});if(!n.ok){let o={400:"Bad request",401:"Unauthorized",403:"Forbidden",404:"Not found",500:"Internal server error"};if(n.status===401)throw new Error(`You are not authorized to access the component at ${l.info(i)}.
40
40
  If this is a remote registry, you may need to authenticate.`);if(n.status===404)throw new Error(`The component at ${l.info(i)} was not found.
41
41
  It may not exist at the registry. Please make sure it is a valid component.`);if(n.status===403)throw new Error(`You do not have access to the component at ${l.info(i)}.
42
42
  If this is a remote registry, you may need to authenticate or a token.`);let s=await n.json(),a=s&&typeof s=="object"&&"error"in s?s.error:n.statusText||o[n.status];throw new Error(`Failed to fetch from ${l.info(i)}.
43
43
  ${a}`)}return n.json()}))}catch(t){return c.error(`
44
- `),y(t),[]}}async function $t(e$1,t){try{if(!await Z())return null;e$1.includes("index")&&e$1.unshift("index");let i=await Je(e$1,t),n=await I(i),o=z.array(e).parse(n);if(!o)return null;if(e$1.includes("index")&&t.tailwind.baseColor){let p=await ei(t.tailwind.baseColor,t);p&&o.unshift(p);}let s={};o.forEach(p=>{s=X(s,p.tailwind??{});});let a={};o.forEach(p=>{a=X(a,p.cssVars??{});});let m="";return o.forEach(p=>{p.docs&&(m+=`${p.docs}
45
- `);}),k.parse({dependencies:X.all(o.map(p=>p.dependencies??[])),devDependencies:X.all(o.map(p=>p.devDependencies??[])),files:X.all(o.map(p=>p.files??[])),tailwind:s,cssVars:a,docs:m})}catch(r){return y(r),null}}async function Zr(e$1,t){let r=new Set,i=[];async function n(o){let s=Nt(Ge(o)?o:`styles/${t.style}/${o}.json`);if(!r.has(s)){r.add(s);try{let[a]=await I([s]),m=e.parse(a);if(i.push(s),m.registryDependencies)for(let p of m.registryDependencies)await n(p);}catch(a){console.error(`Error fetching or parsing registry item at ${o}:`,a);}}}return await n(e$1),Array.from(new Set(i))}async function ei(e,t){let r=await ee(e);if(!r)return null;let i={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&&(i.tailwind.config.theme.extend.colors={...i.tailwind.config.theme.extend.colors,...Tt(r.cssVars.dark)},i.cssVars={light:{...r.cssVars.light,...i.cssVars.light},dark:{...r.cssVars.dark,...i.cssVars.dark}}),i}function Nt(e){if(Ge(e)){let t=new URL(e);return t.pathname.match(/\/chat\/b\//)&&!t.pathname.endsWith("/json")&&(t.pathname=`${t.pathname}/json`),t.toString()}return `${qr}/${e}`}function Ge(e){try{return new URL(e),!0}catch{return !1}}async function Je(e,t){let r=[];for(let i of e){let n=await Zr(i,t);r.push(...n);}return Array.from(new Set(r))}function At(){return new Map([["registry:ui","ui"],["registry:lib","lib"],["registry:hook","hooks"],["registry:block","components"],["registry:component","components"]])}function Lt(e){let t=new Map;return e.forEach(r=>{r.registryDependencies&&r.registryDependencies.forEach(i=>{t.set(i,r);});}),t}async function Ye(e,t,r){if(!t.resolvedPaths.tailwindCss)return;r={cleanupDefaultNextStyles:!1,silent:!1,tailwindVersion:"v3",...r};let i=t.resolvedPaths.tailwindCss,n=T__default.relative(t.resolvedPaths.cwd,i),o=g(`Updating ${l.info(n)}`,{silent:r.silent}).start(),s=await promises.readFile(i,"utf8"),a=await ii(s,e??{},t,{cleanupDefaultNextStyles:r.cleanupDefaultNextStyles,tailwindVersion:r.tailwindVersion,tailwindConfig:r.tailwindConfig});await promises.writeFile(i,a,"utf8"),o.succeed();}async function ii(e,t,r,i={cleanupDefaultNextStyles:!1,tailwindVersion:"v3",tailwindConfig:void 0}){i={cleanupDefaultNextStyles:!1,tailwindVersion:"v3",tailwindConfig:void 0,...i};let n=[oi(t)];i.tailwindVersion==="v4"&&(n=[pi({params:"dark (&:is(.dark *))"}),ci(t),li(t)],i.tailwindConfig&&(n.push(mi(i.tailwindConfig)),n.push(di(i.tailwindConfig)),n.push(fi(i.tailwindConfig)))),i.cleanupDefaultNextStyles&&n.push(si()),r.tailwind.cssVariables&&n.push(ni());let s=(await x(n).process(e,{from:void 0})).css.replace(/\/\* ---break--- \*\//g,"");return i.tailwindVersion==="v4"&&(s=s.replace(/(\n\s*\n)+/g,`
44
+ `),y(t),[]}}async function $t(e$1,t){try{if(!await ee())return null;e$1.includes("index")&&e$1.unshift("index");let i=await Je(e$1,t),n=await I(i),o=z.array(e).parse(n);if(!o)return null;if(e$1.includes("index")&&t.tailwind.baseColor){let p=await ei(t.tailwind.baseColor,t);p&&o.unshift(p);}let s={};o.forEach(p=>{s=Z(s,p.tailwind??{});});let a={};o.forEach(p=>{a=Z(a,p.cssVars??{});});let f="";return o.forEach(p=>{p.docs&&(f+=`${p.docs}
45
+ `);}),k.parse({dependencies:Z.all(o.map(p=>p.dependencies??[])),devDependencies:Z.all(o.map(p=>p.devDependencies??[])),files:Z.all(o.map(p=>p.files??[])),tailwind:s,cssVars:a,docs:f})}catch(r){return y(r),null}}async function Zr(e$1,t){let r=new Set,i=[];async function n(o){let s=Nt(Ge(o)?o:`styles/${t.style}/${o}.json`);if(!r.has(s)){r.add(s);try{let[a]=await I([s]),f=e.parse(a);if(i.push(s),f.registryDependencies)for(let p of f.registryDependencies)await n(p);}catch(a){console.error(`Error fetching or parsing registry item at ${o}:`,a);}}}return await n(e$1),Array.from(new Set(i))}async function ei(e,t){let r=await te(e);if(!r)return null;let i={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&&(i.tailwind.config.theme.extend.colors={...i.tailwind.config.theme.extend.colors,...Tt(r.cssVars.dark)},i.cssVars={light:{...r.cssVars.light,...i.cssVars.light},dark:{...r.cssVars.dark,...i.cssVars.dark}}),i}function Nt(e){if(Ge(e)){let t=new URL(e);return t.pathname.match(/\/chat\/b\//)&&!t.pathname.endsWith("/json")&&(t.pathname=`${t.pathname}/json`),t.toString()}return `${qr}/${e}`}function Ge(e){try{return new URL(e),!0}catch{return !1}}async function Je(e,t){let r=[];for(let i of e){let n=await Zr(i,t);r.push(...n);}return Array.from(new Set(r))}function At(){return new Map([["registry:ui","ui"],["registry:lib","lib"],["registry:hook","hooks"],["registry:block","components"],["registry:component","components"]])}function Lt(e){let t=new Map;return e.forEach(r=>{r.registryDependencies&&r.registryDependencies.forEach(i=>{t.set(i,r);});}),t}async function Ye(e,t,r){if(!t.resolvedPaths.tailwindCss)return;r={cleanupDefaultNextStyles:!1,silent:!1,tailwindVersion:"v3",...r};let i=t.resolvedPaths.tailwindCss,n=T__default.relative(t.resolvedPaths.cwd,i),o=g(`Updating ${l.info(n)}`,{silent:r.silent}).start(),s=await promises.readFile(i,"utf8"),a=await ii(s,e??{},t,{cleanupDefaultNextStyles:r.cleanupDefaultNextStyles,tailwindVersion:r.tailwindVersion,tailwindConfig:r.tailwindConfig});await promises.writeFile(i,a,"utf8"),o.succeed();}async function ii(e,t,r,i={cleanupDefaultNextStyles:!1,tailwindVersion:"v3",tailwindConfig:void 0}){i={cleanupDefaultNextStyles:!1,tailwindVersion:"v3",tailwindConfig:void 0,...i};let n=[oi(t)];i.tailwindVersion==="v4"&&(n=[pi({params:"dark (&:is(.dark *))"}),ci(t),li(t)],i.tailwindConfig&&(n.push(fi(i.tailwindConfig)),n.push(di(i.tailwindConfig)),n.push(mi(i.tailwindConfig)))),i.cleanupDefaultNextStyles&&n.push(si()),r.tailwind.cssVariables&&n.push(ni());let s=(await x(n).process(e,{from:void 0})).css.replace(/\/\* ---break--- \*\//g,"");return i.tailwindVersion==="v4"&&(s=s.replace(/(\n\s*\n)+/g,`
46
46
 
47
47
  `)),s}function ni(){return {postcssPlugin:"update-base-layer",Once(e){let t=[{selector:"*",apply:"border-border"},{selector:"body",apply:"bg-background text-foreground"}],r=e.nodes.find(i=>i.type==="atrule"&&i.name==="layer"&&i.params==="base"&&t.every(({selector:n,apply:o})=>i.nodes?.some(s=>s.type==="rule"&&s.selector===n&&s.nodes.some(a=>a.type==="atrule"&&a.name==="apply"&&a.params===o))));r||(r=x.atRule({name:"layer",params:"base",raws:{semicolon:!0,between:" ",before:`
48
48
  `}}),e.append(r),e.insertBefore(r,x.comment({text:"---break---"}))),t.forEach(({selector:i,apply:n})=>{r?.nodes?.find(s=>s.type==="rule"&&s.selector===i)||r?.append(x.rule({selector:i,nodes:[x.atRule({name:"apply",params:n,raws:{semicolon:!0,before:`
49
49
  `}})],raws:{semicolon:!0,between:" ",before:`
50
50
  `}}));});}}}function oi(e){return {postcssPlugin:"update-css-vars",Once(t){let r=t.nodes.find(i=>i.type==="atrule"&&i.name==="layer"&&i.params==="base");r instanceof ri||(r=x.atRule({name:"layer",params:"base",nodes:[],raws:{semicolon:!0,before:`
51
51
  `,between:" "}}),t.append(r),t.insertBefore(r,x.comment({text:"---break---"}))),r!==void 0&&Object.entries(e).forEach(([i,n])=>{let o=i==="light"?":root":`.${i}`;ai(r,o,n);});}}}function Ft(e){let t=e.nodes.find(r=>r.type==="rule"&&r.selector===":root");if(t){let r=["--background","--foreground"];t.nodes.filter(i=>i.type==="decl"&&r.includes(i.prop)).forEach(i=>i.remove()),t.nodes.length===0&&t.remove();}}function si(){return {postcssPlugin:"cleanup-default-next-styles",Once(e){let t=e.nodes.find(i=>i.type==="rule"&&i.selector==="body");t&&(t.nodes.find(i=>i.type==="decl"&&i.prop==="color"&&["rgb(var(--foreground-rgb))","var(--foreground)"].includes(i.value))?.remove(),t.nodes.find(i=>i.type==="decl"&&i.prop==="background"&&(i.value.startsWith("linear-gradient")||i.value==="var(--background)"))?.remove(),t.nodes.find(i=>i.type==="decl"&&i.prop==="font-family"&&i.value==="Arial, Helvetica, sans-serif")?.remove(),t.nodes.length===0&&t.remove()),Ft(e);let r=e.nodes.find(i=>i.type==="atrule"&&i.params==="(prefers-color-scheme: dark)");r&&(Ft(r),r.nodes.length===0&&r.remove());}}}function ai(e,t,r){let i=e.nodes?.find(n=>n.type==="rule"&&n.selector===t);i||Object.keys(r).length>0&&(i=x.rule({selector:t,raws:{between:" ",before:`
52
- `}}),e.append(i)),Object.entries(r).forEach(([n,o])=>{let s=`--${n.replace(/^--/,"")}`,a=x.decl({prop:s,value:o,raws:{semicolon:!0}}),m=i?.nodes.find(p=>p.type==="decl"&&p.prop===s);m?m.replaceWith(a):i?.append(a);});}function ci(e){return {postcssPlugin:"update-css-vars-v4",Once(t){Object.entries(e).forEach(([r,i])=>{let n=r==="light"?":root":`.${r}`,o=t.nodes?.find(s=>s.type==="rule"&&s.selector===n);o||(o=x.rule({selector:n,nodes:[],raws:{semicolon:!0,between:" ",before:`
53
- `}}),t.append(o),t.insertBefore(o,x.comment({text:"---break---"}))),Object.entries(i).forEach(([s,a])=>{let m=`--${s.replace(/^--/,"")}`;_t(a)&&(a=`hsl(${a})`);let p=x.decl({prop:m,value:a,raws:{semicolon:!0}}),f=o?.nodes.find(d=>d.type==="decl"&&d.prop===m);f?f.replaceWith(p):o?.append(p);});});}}}function li(e){return {postcssPlugin:"update-theme",Once(t){let r=Array.from(new Set(Object.keys(e).flatMap(o=>Object.keys(e[o]||{}))));if(!r.length)return;let i=He(t),n=i.nodes?.filter(o=>o.type==="decl"&&o.prop.startsWith("--"));for(let o of r){let s=Object.values(e).find(p=>p[o])?.[o];if(!s)continue;if(o==="radius"){let p={sm:"calc(var(--radius) - 4px)",md:"calc(var(--radius) - 2px)",lg:"var(--radius)",xl:"calc(var(--radius) + 4px)"};for(let[f,d]of Object.entries(p)){let w=x.decl({prop:`--radius-${f}`,value:d,raws:{semicolon:!0}});i?.nodes?.find(v=>v.type==="decl"&&v.prop===w.prop)||i?.append(w);}break}let a=x.decl({prop:_t(s)||gi(s)?`--color-${o.replace(/^--/,"")}`:`--${o.replace(/^--/,"")}`,value:`var(--${o})`,raws:{semicolon:!0}});i?.nodes?.find(p=>p.type==="decl"&&p.prop===a.prop)||(n?.length?i?.insertAfter(n[n.length-1],a):i?.append(a));}}}}function He(e){let t=e.nodes.find(r=>r.type==="atrule"&&r.name==="theme"&&r.params==="inline");return t||(t=x.atRule({name:"theme",params:"inline",nodes:[],raws:{semicolon:!0,between:" ",before:`
52
+ `}}),e.append(i)),Object.entries(r).forEach(([n,o])=>{let s=`--${n.replace(/^--/,"")}`,a=x.decl({prop:s,value:o,raws:{semicolon:!0}}),f=i?.nodes.find(p=>p.type==="decl"&&p.prop===s);f?f.replaceWith(a):i?.append(a);});}function ci(e){return {postcssPlugin:"update-css-vars-v4",Once(t){Object.entries(e).forEach(([r,i])=>{let n=r==="light"?":root":`.${r}`,o=t.nodes?.find(s=>s.type==="rule"&&s.selector===n);o||(o=x.rule({selector:n,nodes:[],raws:{semicolon:!0,between:" ",before:`
53
+ `}}),t.append(o),t.insertBefore(o,x.comment({text:"---break---"}))),Object.entries(i).forEach(([s,a])=>{let f=`--${s.replace(/^--/,"")}`;_t(a)&&(a=`hsl(${a})`);let p=x.decl({prop:f,value:a,raws:{semicolon:!0}}),m=o?.nodes.find(d=>d.type==="decl"&&d.prop===f);m?m.replaceWith(p):o?.append(p);});});}}}function li(e){return {postcssPlugin:"update-theme",Once(t){let r=Array.from(new Set(Object.keys(e).flatMap(o=>Object.keys(e[o]||{}))));if(!r.length)return;let i=He(t),n=i.nodes?.filter(o=>o.type==="decl"&&o.prop.startsWith("--"));for(let o of r){let s=Object.values(e).find(p=>p[o])?.[o];if(!s)continue;if(o==="radius"){let p={sm:"calc(var(--radius) - 4px)",md:"calc(var(--radius) - 2px)",lg:"var(--radius)",xl:"calc(var(--radius) + 4px)"};for(let[m,d]of Object.entries(p)){let w=x.decl({prop:`--radius-${m}`,value:d,raws:{semicolon:!0}});i?.nodes?.find(v=>v.type==="decl"&&v.prop===w.prop)||i?.append(w);}break}let a=x.decl({prop:_t(s)||gi(s)?`--color-${o.replace(/^--/,"")}`:`--${o.replace(/^--/,"")}`,value:`var(--${o})`,raws:{semicolon:!0}});i?.nodes?.find(p=>p.type==="decl"&&p.prop===a.prop)||(n?.length?i?.insertAfter(n[n.length-1],a):i?.append(a));}}}}function He(e){let t=e.nodes.find(r=>r.type==="atrule"&&r.name==="theme"&&r.params==="inline");return t||(t=x.atRule({name:"theme",params:"inline",nodes:[],raws:{semicolon:!0,between:" ",before:`
54
54
  `}}),e.append(t),e.insertBefore(t,x.comment({text:"---break---"}))),t}function pi({params:e}){return {postcssPlugin:"add-custom-variant",Once(t){if(!t.nodes.find(i=>i.type==="atrule"&&i.name==="custom-variant")){let i=x.atRule({name:"custom-variant",params:e,raws:{semicolon:!0,before:`
55
- `}});t.insertAfter(t.nodes[0],i),t.insertBefore(i,x.comment({text:"---break---"}));}}}}function mi(e){return {postcssPlugin:"update-tailwind-config",Once(t){if(!e?.plugins)return;let i=ui(t)==="single"?"'":'"',n=t.nodes.filter(s=>s.type==="atrule"&&s.name==="plugin"),o=n[n.length-1]||t.nodes[0];for(let s of e.plugins){let a=s.replace(/^require\(["']|["']\)$/g,"");if(n.some(p=>p.params.replace(/["']/g,"")===a))continue;let m=x.atRule({name:"plugin",params:`${i}${a}${i}`,raws:{semicolon:!0,before:`
56
- `}});t.insertAfter(o,m),t.insertBefore(m,x.comment({text:"---break---"}));}}}}function fi(e){return {postcssPlugin:"update-tailwind-config-keyframes",Once(t){if(!e?.theme?.extend?.keyframes)return;let r=He(t),i=r.nodes?.filter(o=>o.type==="atrule"&&o.name==="keyframes"),n=z.record(z.string(),z.record(z.string(),z.string()));for(let[o,s]of Object.entries(e.theme.extend.keyframes)){if(typeof o!="string")continue;let a=n.safeParse(s);if(!a.success||i?.find(p=>p.type==="atrule"&&p.name==="keyframes"&&p.params===o))continue;let m=x.atRule({name:"keyframes",params:o,nodes:[],raws:{semicolon:!0,between:" ",before:`
57
- `}});for(let[p,f]of Object.entries(a.data)){let d=x.rule({selector:p,nodes:Object.entries(f).map(([w,v])=>x.decl({prop:w,value:v,raws:{semicolon:!0,before:`
55
+ `}});t.insertAfter(t.nodes[0],i),t.insertBefore(i,x.comment({text:"---break---"}));}}}}function fi(e){return {postcssPlugin:"update-tailwind-config",Once(t){if(!e?.plugins)return;let i=ui(t)==="single"?"'":'"',n=t.nodes.filter(s=>s.type==="atrule"&&s.name==="plugin"),o=n[n.length-1]||t.nodes[0];for(let s of e.plugins){let a=s.replace(/^require\(["']|["']\)$/g,"");if(n.some(p=>p.params.replace(/["']/g,"")===a))continue;let f=x.atRule({name:"plugin",params:`${i}${a}${i}`,raws:{semicolon:!0,before:`
56
+ `}});t.insertAfter(o,f),t.insertBefore(f,x.comment({text:"---break---"}));}}}}function mi(e){return {postcssPlugin:"update-tailwind-config-keyframes",Once(t){if(!e?.theme?.extend?.keyframes)return;let r=He(t),i=r.nodes?.filter(o=>o.type==="atrule"&&o.name==="keyframes"),n=z.record(z.string(),z.record(z.string(),z.string()));for(let[o,s]of Object.entries(e.theme.extend.keyframes)){if(typeof o!="string")continue;let a=n.safeParse(s);if(!a.success||i?.find(p=>p.type==="atrule"&&p.name==="keyframes"&&p.params===o))continue;let f=x.atRule({name:"keyframes",params:o,nodes:[],raws:{semicolon:!0,between:" ",before:`
57
+ `}});for(let[p,m]of Object.entries(a.data)){let d=x.rule({selector:p,nodes:Object.entries(m).map(([w,v])=>x.decl({prop:w,value:v,raws:{semicolon:!0,before:`
58
58
  `,between:": "}})),raws:{semicolon:!0,between:" ",before:`
59
- `}});m.append(d);}r.append(m),r.insertBefore(m,x.comment({text:"---break---"}));}}}}function di(e){return {postcssPlugin:"update-tailwind-config-animation",Once(t){if(!e?.theme?.extend?.animation)return;let r=He(t),i=r.nodes?.filter(o=>o.type==="decl"&&o.prop.startsWith("--animate-")),n=z.record(z.string(),z.string()).safeParse(e.theme.extend.animation);if(n.success)for(let[o,s]of Object.entries(n.data)){let a=`--animate-${o}`;if(i?.find(p=>p.prop===a))continue;let m=x.decl({prop:a,value:s,raws:{semicolon:!0,between:": ",before:`
60
- `}});r.append(m);}}}}function ui(e){return e.nodes[0].toString().includes("'")?"single":"double"}function _t(e){if(e.startsWith("hsl")||e.startsWith("rgb")||e.startsWith("#")||e.startsWith("oklch"))return !1;let t=e.split(" ");return t.length===3&&t.slice(1,3).every(r=>r.includes("%"))}function gi(e){return e.startsWith("hsl")||e.startsWith("rgb")||e.startsWith("#")||e.startsWith("oklch")}async function pe(e,{withFallback:t}={withFallback:!1}){let r=await detect({programmatic:!0,cwd:e});if(r==="yarn@berry")return "yarn";if(r==="pnpm@6")return "pnpm";if(r==="bun")return "bun";if(!t)return r??"npm";let i=process.env.npm_config_user_agent||"";return i.startsWith("yarn")?"yarn":i.startsWith("pnpm")?"pnpm":i.startsWith("bun")?"bun":"npm"}async function te(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let i=g("Installing dependencies.",{silent:r.silent})?.start(),n=await pe(t.resolvedPaths.cwd),o="";if(xi(t)&&n==="npm"){i.stopAndPersist(),c.warn(`
59
+ `}});f.append(d);}r.append(f),r.insertBefore(f,x.comment({text:"---break---"}));}}}}function di(e){return {postcssPlugin:"update-tailwind-config-animation",Once(t){if(!e?.theme?.extend?.animation)return;let r=He(t),i=r.nodes?.filter(o=>o.type==="decl"&&o.prop.startsWith("--animate-")),n=z.record(z.string(),z.string()).safeParse(e.theme.extend.animation);if(n.success)for(let[o,s]of Object.entries(n.data)){let a=`--animate-${o}`;if(i?.find(p=>p.prop===a))continue;let f=x.decl({prop:a,value:s,raws:{semicolon:!0,between:": ",before:`
60
+ `}});r.append(f);}}}}function ui(e){return e.nodes[0].toString().includes("'")?"single":"double"}function _t(e){if(e.startsWith("hsl")||e.startsWith("rgb")||e.startsWith("#")||e.startsWith("oklch"))return !1;let t=e.split(" ");return t.length===3&&t.slice(1,3).every(r=>r.includes("%"))}function gi(e){return e.startsWith("hsl")||e.startsWith("rgb")||e.startsWith("#")||e.startsWith("oklch")}async function pe(e,{withFallback:t}={withFallback:!1}){let r=await detect({programmatic:!0,cwd:e});if(r==="yarn@berry")return "yarn";if(r==="pnpm@6")return "pnpm";if(r==="bun")return "bun";if(!t)return r??"npm";let i=process.env.npm_config_user_agent||"";return i.startsWith("yarn")?"yarn":i.startsWith("pnpm")?"pnpm":i.startsWith("bun")?"bun":"npm"}async function re(e,t,r){if(e=Array.from(new Set(e)),!e?.length)return;r={silent:!1,...r};let i=g("Installing dependencies.",{silent:r.silent})?.start(),n=await pe(t.resolvedPaths.cwd),o="";if(xi(t)&&n==="npm"){i.stopAndPersist(),c.warn(`
61
61
  It looks like you are using React 19.
62
62
  Some packages may fail to install due to peer dependency issues in npm (see https://ui.shadcn.com/react-19).
63
- `);let s=await et([{type:"select",name:"flag",message:"How would you like to proceed?",choices:[{title:"Use --force",value:"force"},{title:"Use --legacy-peer-deps",value:"legacy-peer-deps"}]}]);s&&(o=s.flag);}i?.start(),await execa(n,[n==="npm"?"install":"add",...n==="npm"&&o?[`--${o}`]:[],...e],{cwd:t.resolvedPaths.cwd}),i?.succeed();}function xi(e){let t=q(e.resolvedPaths.cwd);return t?.dependencies?.react?/^(?:\^|~)?19(?:\.\d+)*(?:-.*)?$/.test(t.dependencies.react):!1}var me=async({sourceFile:e,config:t,baseColor:r})=>(t.tailwind?.cssVariables||!r?.inlineColors||e.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach(i=>{let n=i.getText();if(n){let o=vi(n.replace(/"/g,""),r.inlineColors);i.replaceWithText(`"${o.trim()}"`);}}),e);function qe(e){if(!e.includes("/")&&!e.includes(":"))return [null,e,null];let t=[],[r,i]=e.split("/");if(!r.includes(":"))return [null,r,i];let n=r.split(":"),o=n.pop(),s=n.join(":");return t.push(s??null,o??null,i??null),t}var Si=["bg-","text-","border-","ring-offset-","ring-"];function vi(e,t){e.includes(" border ")&&(e=e.replace(" border "," border border-border "));let r=e.split(" "),i=new Set,n=new Set;for(let o of r){let[s,a,m]=qe(o),p=Si.find(d=>a?.startsWith(d));if(!p){i.has(o)||i.add(o);continue}let f=a?.replace(p,"");if(f&&f in t.light){i.add([s,`${p}${t.light[f]}`].filter(Boolean).join(":")+(m?`/${m}`:"")),n.add(["dark",s,`${p}${t.dark[f]}`].filter(Boolean).join(":")+(m?`/${m}`:""));continue}i.has(o)||i.add(o);}return [...Array.from(i),...Array.from(n)].join(" ").trim()}var P={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 Vt="lucide",fe=async({sourceFile:e,config:t})=>{if(!t.iconLibrary||!(t.iconLibrary in P))return e;let r=await le(),i=Vt,n=t.iconLibrary;if(i===n)return e;let o=[];for(let s of e.getImportDeclarations()??[])if(s.getModuleSpecifier()?.getText()===`"${P[Vt].import}"`){for(let a of s.getNamedImports()??[]){let m=a.getName(),p=r[m]?.[n];!p||o.includes(p)||(o.push(p),a.remove(),e.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).filter(f=>f.getTagNameNode()?.getText()===m).forEach(f=>f.getTagNameNode()?.replaceWithText(p)));}s.getNamedImports()?.length===0&&s.remove();}if(o.length>0){let s=e.addImportDeclaration({moduleSpecifier:P[n]?.import,namedImports:o.map(a=>({name:a}))});Ci(e)||s.replaceWithText(s.getText().replace(";",""));}return e};function Ci(e){return e.getImportDeclarations()?.[0]?.getText().endsWith(";")??!1}var zt={"@/lib/utils":/^@\/lib\/utils/,"@workspace/lib/utils":/^@workspace\/lib\/utils/},de=async({sourceFile:e,config:t,isRemote:r})=>{let i=e.getImportDeclarations();for(let n of i){let o=Ii(n.getModuleSpecifierValue(),t,r);n.setModuleSpecifier(o),zt[o]&&n.getNamedImports().find(m=>m.getName()==="cn")&&n.setModuleSpecifier(o.replace(zt[o],t.aliases.utils));}return e};function Ii(e,t,r=!1){if(!e.startsWith("@/")&&!r)return e;if(r&&e.startsWith("@/")&&(e=e.replace(/^@\//,"@/registry/new-york/")),!e.startsWith("@/registry/")){let i=t.aliases.components.split("/")[0];return e.replace(/^@\//,`${i}/`)}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 Ei={sourceType:"module",allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,startLine:1,tokens:!0,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"]},Kt=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let i=ue.parse(r,{parser:{parse:o=>parse(o,Ei)}}),n=transformFromAstSync(i,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[Ti],configFile:!1});if(!n||!n.ast)throw new Error("Failed to transform JSX");return ue.print(n.ast).code};var Oi=/^["']use client["']$/g,ge=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(SyntaxKind.ExpressionStatement);return r&&Oi.test(r.getText())&&r.remove(),e};var he=async({sourceFile:e,config:t})=>(t.tailwind?.prefix&&(e.getDescendantsOfKind(SyntaxKind.CallExpression).filter(r=>r.getExpression().getText()==="cva").forEach(r=>{if(r.getArguments()[0]?.isKind(SyntaxKind.StringLiteral)){let i=r.getArguments()[0];i&&i.replaceWithText(`"${_(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);}r.getArguments()[1]?.isKind(SyntaxKind.ObjectLiteralExpression)&&r.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(`"${_(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);});});}),e.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach(r=>{if(r.getName()==="className"){if(r.getInitializer()?.isKind(SyntaxKind.StringLiteral)){let i=r.getInitializer();i&&i.replaceWithText(`"${_(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);}if(r.getInitializer()?.isKind(SyntaxKind.JsxExpression)){let i=r.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(`"${_(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);}),n.isKind(SyntaxKind.StringLiteral)&&n.replaceWithText(`"${_(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);});}}r.getName()==="classNames"&&r.getInitializer()?.isKind(SyntaxKind.JsxExpression)&&r.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(s=>{s.replaceWithText(`"${_(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);}),o.isKind(SyntaxKind.StringLiteral)&&o.replaceWithText(`"${_(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);});}if(i.getInitializer()?.isKind(SyntaxKind.StringLiteral)&&i.getName()!=="variant"){let n=i.getInitializer();n&&n.replaceWithText(`"${_(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);}});})),e);function _(e,t=""){let r=e.split(" "),i=[];for(let n of r){let[o,s,a]=qe(n);o?a?i.push(`${o}:${t}${s}/${a}`):i.push(`${o}:${t}${s}`):a?i.push(`${t}${s}/${a}`):i.push(`${t}${s}`);}return i.join(" ")}var Di=new Project({compilerOptions:{}});async function Fi(e){let t=await promises.mkdtemp(T__default.join(tmpdir(),"shadcn-"));return T__default.join(t,e)}async function ye(e,t=[de,ge,me,he,fe]){let r=await Fi(e.filename),i=Di.createSourceFile(r,e.raw,{scriptKind:ScriptKind.TSX});for(let n of t)await n({sourceFile:i,...e});return e.transformJsx?await Kt({sourceFile:i,...e}):i.getText()}async function Qe(e,t,r){if(!e?.length)return {filesCreated:[],filesUpdated:[],filesSkipped:[]};r={overwrite:!1,force:!1,silent:!1,isRemote:!1,...r};let i=g("Updating files.",{silent:r.silent})?.start(),[n,o]=await Promise.all([j(t.resolvedPaths.cwd),ee(t.tailwind.baseColor)]),s=[],a=[],m=[];for(let f of e){if(!f.content)continue;let d=zi(f,t,{isSrcDir:n?.isSrcDir,commonRoot:Mi(e.map(M=>M.path),f.path)}),w=basename(f.path),v=T__default.dirname(d);t.tsx||(d=d.replace(/\.tsx?$/,M=>M===".tsx"?".jsx":".js"));let A=existsSync(d);if(A&&!r.overwrite){i.stop(),r.rootSpinner&&r.rootSpinner.stop();let{overwrite:M}=await et({type:"confirm",name:"overwrite",message:`The file ${l.info(w)} already exists. Would you like to overwrite?`,initial:!1});if(!M){m.push(T__default.relative(t.resolvedPaths.cwd,d)),r.rootSpinner&&r.rootSpinner.start();continue}i?.start(),r.rootSpinner&&r.rootSpinner.start();}existsSync(v)||await promises.mkdir(v,{recursive:!0});let b=await ye({filename:f.path,raw:f.content,config:t,baseColor:o,transformJsx:!t.tsx,isRemote:r.isRemote},[de,ge,me,he,fe]);await promises.writeFile(d,b,"utf-8"),A?a.push(T__default.relative(t.resolvedPaths.cwd,d)):s.push(T__default.relative(t.resolvedPaths.cwd,d));}if(!(s.length||a.length)&&!m.length&&i?.info("No files updated."),s.length){if(i?.succeed(`Created ${s.length} ${s.length===1?"file":"files"}:`),!r.silent)for(let f of s)c.log(` - ${f}`);}else i?.stop();if(a.length&&(g(`Updated ${a.length} ${a.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let f of a)c.log(` - ${f}`);if(m.length&&(g(`Skipped ${m.length} ${a.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:r.silent})?.info(),!r.silent))for(let f of m)c.log(` - ${f}`);return r.silent||c.break(),{filesCreated:s,filesUpdated:a,filesSkipped:m}}function zi(e,t,r){if(e.target)return e.target.startsWith("~/")?T__default.join(t.resolvedPaths.cwd,e.target.replace("~/","")):r.isSrcDir?T__default.join(t.resolvedPaths.cwd,"src",e.target.replace("src/","")):T__default.join(t.resolvedPaths.cwd,e.target.replace("src/",""));let i=Ki(e,t),n=Wi(e.path,i);return T__default.join(i,n)}function Ki(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 Mi(e,t){let r=e.map(s=>s.replace(/^\//,"")),i=t.replace(/^\//,""),n=i.split("/").slice(0,-1).join("/");if(!n)return "";let o=n.split("/");for(let s=o.length;s>0;s--){let a=o.slice(0,s).join("/");if(r.some(p=>p!==i&&p.startsWith(a+"/")))return "/"+a}return "/"+n}function Wi(e,t){let r=e.replace(/^\/|\/$/g,""),i=t.replace(/^\/|\/$/g,""),n=r.split("/"),o=i.split("/"),s=o[o.length-1],a=n.findIndex(m=>m===s);return a===-1?n[n.length-1]:n.slice(a+1).join("/")}async function we(e,t,r){r={overwrite:!1,silent:!1,isNewProject:!1,...r};let i=await xt(t);return i&&i?.ui.resolvedPaths.cwd!==t.resolvedPaths.cwd?await Gi(e,t,i,{...r,isRemote:e?.length===1&&!!e[0].match(/\/chat\/b\//)}):await Bi(e,t,r)}async function Bi(e,t,r){let i=g("Checking registry.",{silent:r.silent})?.start(),n=await $t(e,t);if(!n)return i?.fail(),y(new Error("Failed to fetch components from registry."));i?.succeed();let o=await De(t);await Ve(n.tailwind?.config,t,{silent:r.silent,tailwindVersion:o}),await Ye(n.cssVars,t,{cleanupDefaultNextStyles:r.isNewProject,silent:r.silent,tailwindVersion:o,tailwindConfig:n.tailwind?.config}),await te(n.dependencies,t,{silent:r.silent}),await Qe(n.files,t,{overwrite:r.overwrite,silent:r.silent}),n.docs&&c.info(n.docs);}async function Gi(e$1,t,r,i){let n=g("Checking registry.",{silent:i.silent})?.start(),o=await Je(e$1,t),s=await I(o),a=z.array(e).parse(s);if(!a)return n?.fail(),y(new Error("Failed to fetch components from registry."));n?.succeed();let m=Lt(a),p=At(),f=[],d=[],w=[],v=g("Installing components.")?.start();for(let b of a){let M=p.get(b.type),ur=m.get(b.name);if(!M)continue;let E=b.type==="registry:ui"||ur?.type==="registry:ui"?r.ui:t,at=await De(E),B=Ne(t.resolvedPaths.cwd,E.resolvedPaths.ui),ke=await $e(B,E.resolvedPaths.cwd)??E.resolvedPaths.cwd;b.tailwind?.config&&(await Ve(b.tailwind?.config,E,{silent:!0,tailwindVersion:at}),d.push(T__default.relative(B,E.resolvedPaths.tailwindConfig))),b.cssVars&&(await Ye(b.cssVars,E,{silent:!0,tailwindVersion:at,tailwindConfig:b.tailwind?.config}),d.push(T__default.relative(B,E.resolvedPaths.tailwindCss))),await te(b.dependencies,E,{silent:!0});let Te=await Qe(b.files,E,{overwrite:i.overwrite,silent:!0,rootSpinner:v,isRemote:i.isRemote});f.push(...Te.filesCreated.map(J=>T__default.relative(B,T__default.join(ke,J)))),d.push(...Te.filesUpdated.map(J=>T__default.relative(B,T__default.join(ke,J)))),w.push(...Te.filesSkipped.map(J=>T__default.relative(B,T__default.join(ke,J))));}if(v?.succeed(),f.sort(),d.sort(),w.sort(),!(f.length||d.length)&&!w.length&&g("No files updated.",{silent:i.silent})?.info(),f.length){g(`Created ${f.length} ${f.length===1?"file":"files"}:`,{silent:i.silent})?.succeed();for(let b of f)c.log(` - ${b}`);}if(d.length){g(`Updated ${d.length} ${d.length===1?"file":"files"}:`,{silent:i.silent})?.info();for(let b of d)c.log(` - ${b}`);}if(w.length){g(`Skipped ${w.length} ${d.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:i.silent})?.info();for(let b of w)c.log(` - ${b}`);}}var Hi="https://codeload.github.com/shadcn-ui/ui/tar.gz/main";async function be(e){e={srcDir:!1,...e};let t="next",r="my-app",i="15.1.0",n=e.components?.length===1&&!!e.components[0].match(/\/chat\/b\//);if(e.components&&n)try{let[a]=await I(e.components),{meta:m}=z.object({meta:z.object({nextVersion:z.string()})}).parse(a);i=m.nextVersion;}catch(a){c.break(),y(a);}if(!e.force){let{type:a,name:m}=await et([{type:"select",name:"type",message:`The path ${l.info(e.cwd)} does not contain a package.json file.
64
- Would you like to start a new project?`,choices:[{title:"Next.js",value:"next"},{title:"Next.js (Monorepo)",value:"monorepo"}],initial:0},{type:"text",name:"name",message:"What is your project named?",initial:r,format:p=>p.trim(),validate:p=>p.length>128?"Name should be less than 128 characters.":!0}]);t=a,r=m;}let o=await pe(e.cwd,{withFallback:!0}),s=`${e.cwd}/${r}`;try{await U.access(e.cwd,U.constants.W_OK);}catch{c.break(),c.error(`The path ${l.info(e.cwd)} is not writable.`),c.error(`It is likely you do not have write permissions for this folder or the path ${l.info(e.cwd)} does not exist.`),c.break(),process.exit(1);}return U.existsSync(T__default.resolve(e.cwd,r,"package.json"))&&(c.break(),c.error(`A project with the name ${l.info(r)} already exists.`),c.error("Please choose a different name and try again."),c.break(),process.exit(1)),t==="next"&&await qi(s,{version:i,cwd:e.cwd,packageManager:o,srcDir:!!e.srcDir}),t==="monorepo"&&await Qi(s,{packageManager:o}),{projectPath:s,projectName:r,projectType:t}}async function qi(e,t){let r=g("Creating a new Next.js project. This may take a few minutes.").start(),i=["--tailwind","--eslint","--typescript","--app",t.srcDir?"--src-dir":"--no-src-dir","--no-import-alias",`--use-${t.packageManager}`];t.version.startsWith("15")&&i.push("--turbopack");try{await execa("npx",[`create-next-app@${t.version}`,e,"--silent",...i],{cwd:t.cwd});}catch{c.break(),c.error("Something went wrong creating a new Next.js project. Please try again."),process.exit(1);}r?.succeed("Creating a new Next.js project.");}async function Qi(e,t){let r=g("Creating a new Next.js monorepo. This may take a few minutes.").start();try{let i=T__default.join(Ji.tmpdir(),`shadcn-template-${Date.now()}`);await U.ensureDir(i);let n=await fetch(Hi);if(!n.ok)throw new Error(`Failed to download template: ${n.statusText}`);let o=T__default.resolve(i,"template.tar.gz");await U.writeFile(o,Buffer.from(await n.arrayBuffer())),await execa("tar",["-xzf",o,"-C",i,"--strip-components=2","ui-main/templates/monorepo-next"]);let s=T__default.resolve(i,"monorepo-next");await U.move(s,e),await U.remove(i),await execa(t.packageManager,["install"],{cwd:e});let a=process.cwd();await execa("git",["--version"],{cwd:e}),await execa("git",["init"],{cwd:e}),await execa("git",["add","-A"],{cwd:e}),await execa("git",["commit","-m","Initial commit"],{cwd:e}),await execa("cd",[a]),r?.succeed("Creating a new Next.js monorepo.");}catch(i){r?.fail("Something went wrong creating a new Next.js monorepo."),y(i);}}async function Gt(e,t,r){if(!e)return;r={silent:!1,...r};let i=T__default.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=g(`Updating ${l.info(i)}`,{silent:r.silent}).start(),o=await promises.readFile(t.resolvedPaths.tailwindConfig,"utf8"),s=await Zi(o,e,t);await promises.writeFile(t.resolvedPaths.tailwindConfig,s,"utf8"),n?.succeed();}async function Zi(e,t,r){let i=await ae(e,r),n=i.getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression).find(o=>o.getProperties().some(s=>s.isKind(SyntaxKind.PropertyAssignment)&&s.getName()==="content"));return n?(en(n,t),i.getFullText()):e}async function en(e,t){let r=ze(e),i=e.getProperty("content");if(!i){let n={name:"content",initializer:`[${r}${t.join(`${r}, ${r}`)}${r}]`};return e.addPropertyAssignment(n),e}if(i.isKind(SyntaxKind.PropertyAssignment)){let n=i.getInitializer();if(n?.isKind(SyntaxKind.ArrayLiteralExpression))for(let o of t){let s=`${r}${o}${r}`;n.getElements().map(a=>a.getText()).includes(s)||n.addElement(s);}return e}return e}var nn=z.object({cwd:z.string(),components:z.array(z.string()).optional(),yes:z.boolean(),defaults:z.boolean(),force:z.boolean(),silent:z.boolean(),isNewProject:z.boolean(),srcDir:z.boolean().optional()}),Jt=new Command().name("init").description("initialize your project and install dependencies").argument("[components...]","the components to add or a url to the component.").option("-y, --yes","skip confirmation prompt.",!0).option("-d, --defaults,","use default configuration.",!1).option("-f, --force","force overwrite of existing configuration.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",!1).option("--src-dir","use the src directory when creating a new project.",!1).action(async(e,t)=>{try{let r=nn.parse({cwd:T__default.resolve(t.cwd),isNewProject:!1,components:e,...t});await ve(r),c.log(`${l.success("Success!")} Project initialization completed.
65
- You may now add components.`),c.break();}catch(r){c.break(),y(r);}});async function ve(e){let t,r;if(e.skipPreflight)t=await j(e.cwd);else {let p=await Rt(e);if(p.errors[C]){let{projectPath:f,projectType:d}=await be(e);f||process.exit(1),e.cwd=f,e.isNewProject=!0,r=d;}t=p.projectInfo;}if(r==="monorepo")return e.cwd=T__default.resolve(e.cwd,"apps/web"),await R(e.cwd);let i=await St(e.cwd,t),n=i?await sn(i,e):await on(await R(e.cwd));if(!e.yes){let{proceed:p}=await et({type:"confirm",name:"proceed",message:`Write configuration to ${l.info("components.json")}. Proceed?`,initial:!0});p||process.exit(0);}let o=g("Writing components.json.").start(),s=T__default.resolve(e.cwd,"components.json");await promises.writeFile(s,JSON.stringify(n,null,2),"utf8"),o.succeed();let a=await H(e.cwd,n),m=["index",...e.components||[]];return await we(m,a,{overwrite:!0,silent:e.silent,isNewProject:e.isNewProject||t?.framework.name==="next-app"}),e.isNewProject&&e.srcDir&&await Gt(["./src/**/*.{js,ts,jsx,tsx,mdx}"],a,{silent:e.silent}),a}async function on(e=null){let[t,r]=await Promise.all([Ue(),Be()]);c.info("");let i=await et([{type:"toggle",name:"typescript",message:`Would you like to use ${l.info("TypeScript")} (recommended)?`,initial:e?.tsx??!0,active:"yes",inactive:"no"},{type:"select",name:"style",message:`Which ${l.info("style")} would you like to use?`,choices:t.map(n=>({title:n.label,value:n.name}))},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${l.info("base color")}?`,choices:r.map(n=>({title:n.label,value:n.name}))},{type:"text",name:"tailwindCss",message:`Where is your ${l.info("global CSS")} file?`,initial:e?.tailwind.css??ht},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${l.info("CSS variables")} for theming?`,initial:e?.tailwind.cssVariables??!0,active:"yes",inactive:"no"},{type:"text",name:"tailwindPrefix",message:`Are you using a custom ${l.info("tailwind prefix eg. tw-")}? (Leave blank if not)`,initial:""},{type:"text",name:"tailwindConfig",message:`Where is your ${l.info("tailwind.config.js")} located?`,initial:e?.tailwind.config??yt},{type:"text",name:"components",message:`Configure the import alias for ${l.info("components")}:`,initial:e?.aliases.components??ut},{type:"text",name:"utils",message:`Configure the import alias for ${l.info("utils")}:`,initial:e?.aliases.utils??gt},{type:"toggle",name:"rsc",message:`Are you using ${l.info("React Server Components")}?`,initial:e?.rsc??!0,active:"yes",inactive:"no"}]);return Y.parse({$schema:"https://ui.shadcn.com/schema.json",style:i.style,tailwind:{config:i.tailwindConfig,css:i.tailwindCss,baseColor:i.tailwindBaseColor,cssVariables:i.tailwindCssVariables,prefix:i.tailwindPrefix},rsc:i.rsc,tsx:i.typescript,aliases:{utils:i.utils,components:i.components,lib:i.components.replace(/\/components$/,"lib"),hooks:i.components.replace(/\/components$/,"hooks")}})}async function sn(e,t){let r=e.style,i=e.tailwind.baseColor,n=e.tailwind.cssVariables;if(!t.defaults){let[o,s]=await Promise.all([Ue(),Be()]),a=await et([{type:"select",name:"style",message:`Which ${l.info("style")} would you like to use?`,choices:o.map(m=>({title:m.label,value:m.name})),initial:o.findIndex(m=>m.name===r)},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${l.info("base color")}?`,choices:s.map(m=>({title:m.label,value:m.name}))},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${l.info("CSS variables")} for theming?`,initial:e?.tailwind.cssVariables,active:"yes",inactive:"no"}]);r=a.style,i=a.tailwindBaseColor,n=a.tailwindCssVariables;}return Y.parse({$schema:e?.$schema,style:r,tailwind:{...e?.tailwind,baseColor:i,cssVariables:n},rsc:e?.rsc,tsx:e?.tsx,aliases:e?.aliases,iconLibrary:e?.iconLibrary})}async function Ht(e){let t={};if(!U.existsSync(e.cwd)||!U.existsSync(T__default.resolve(e.cwd,"package.json")))return t[C]=!0,{errors:t,config:null};if(!U.existsSync(T__default.resolve(e.cwd,"components.json")))return t[D]=!0,{errors:t,config:null};try{let r=await R(e.cwd);return {errors:t,config:r}}catch{c.break(),c.error(`An invalid ${l.info("components.json")} file was found at ${l.info(e.cwd)}.
66
- Before you can add components, you must create a valid ${l.info("components.json")} file by running the ${l.info("init")} command.`),c.error(`Learn more at ${l.info("https://ui.shadcn.com/docs/components-json")}.`),c.break(),process.exit(1);}}async function Qt(e,t){let r=T__default.join(t.resolvedPaths.cwd,"app/page.tsx");if(!(await re__default.stat(r)).isFile())return;let i=await Et(e,t.style);if(!i?.meta?.importSpecifier||!i?.meta?.moduleSpecifier)return;let n=`import { ${i?.meta?.importSpecifier} } from "${i.meta.moduleSpecifier}"
63
+ `);let s=await et([{type:"select",name:"flag",message:"How would you like to proceed?",choices:[{title:"Use --force",value:"force"},{title:"Use --legacy-peer-deps",value:"legacy-peer-deps"}]}]);s&&(o=s.flag);}i?.start(),await execa(n,[n==="npm"?"install":"add",...n==="npm"&&o?[`--${o}`]:[],...e],{cwd:t.resolvedPaths.cwd}),i?.succeed();}function xi(e){let t=Q(e.resolvedPaths.cwd);return t?.dependencies?.react?/^(?:\^|~)?19(?:\.\d+)*(?:-.*)?$/.test(t.dependencies.react):!1}var fe=async({sourceFile:e,config:t,baseColor:r})=>(t.tailwind?.cssVariables||!r?.inlineColors||e.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach(i=>{let n=i.getText();if(n){let o=vi(n.replace(/"/g,""),r.inlineColors);i.replaceWithText(`"${o.trim()}"`);}}),e);function qe(e){if(!e.includes("/")&&!e.includes(":"))return [null,e,null];let t=[],[r,i]=e.split("/");if(!r.includes(":"))return [null,r,i];let n=r.split(":"),o=n.pop(),s=n.join(":");return t.push(s??null,o??null,i??null),t}var Si=["bg-","text-","border-","ring-offset-","ring-"];function vi(e,t){e.includes(" border ")&&(e=e.replace(" border "," border border-border "));let r=e.split(" "),i=new Set,n=new Set;for(let o of r){let[s,a,f]=qe(o),p=Si.find(d=>a?.startsWith(d));if(!p){i.has(o)||i.add(o);continue}let m=a?.replace(p,"");if(m&&m in t.light){i.add([s,`${p}${t.light[m]}`].filter(Boolean).join(":")+(f?`/${f}`:"")),n.add(["dark",s,`${p}${t.dark[m]}`].filter(Boolean).join(":")+(f?`/${f}`:""));continue}i.has(o)||i.add(o);}return [...Array.from(i),...Array.from(n)].join(" ").trim()}var P={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 Vt="lucide",me=async({sourceFile:e,config:t})=>{if(!t.iconLibrary||!(t.iconLibrary in P))return e;let r=await le(),i=Vt,n=t.iconLibrary;if(i===n)return e;let o=[];for(let s of e.getImportDeclarations()??[])if(s.getModuleSpecifier()?.getText()===`"${P[Vt].import}"`){for(let a of s.getNamedImports()??[]){let f=a.getName(),p=r[f]?.[n];!p||o.includes(p)||(o.push(p),a.remove(),e.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).filter(m=>m.getTagNameNode()?.getText()===f).forEach(m=>m.getTagNameNode()?.replaceWithText(p)));}s.getNamedImports()?.length===0&&s.remove();}if(o.length>0){let s=e.addImportDeclaration({moduleSpecifier:P[n]?.import,namedImports:o.map(a=>({name:a}))});Ci(e)||s.replaceWithText(s.getText().replace(";",""));}return e};function Ci(e){return e.getImportDeclarations()?.[0]?.getText().endsWith(";")??!1}var zt={"@/lib/utils":/^@\/lib\/utils/,"@workspace/lib/utils":/^@workspace\/lib\/utils/},de=async({sourceFile:e,config:t,isRemote:r})=>{let i=e.getImportDeclarations();for(let n of i){let o=Ii(n.getModuleSpecifierValue(),t,r);n.setModuleSpecifier(o),zt[o]&&n.getNamedImports().find(f=>f.getName()==="cn")&&n.setModuleSpecifier(o.replace(zt[o],t.aliases.utils));}return e};function Ii(e,t,r=!1){if(!e.startsWith("@/")&&!r)return e;if(r&&e.startsWith("@/")&&(e=e.replace(/^@\//,"@/registry/new-york/")),!e.startsWith("@/registry/")){let i=t.aliases.components.split("/")[0];return e.replace(/^@\//,`${i}/`)}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 Ei={sourceType:"module",allowImportExportEverywhere:!0,allowReturnOutsideFunction:!0,startLine:1,tokens:!0,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"]},Kt=async({sourceFile:e,config:t})=>{let r=e.getFullText();if(t.tsx)return r;let i=ue.parse(r,{parser:{parse:o=>parse(o,Ei)}}),n=transformFromAstSync(i,r,{cloneInputAst:!1,code:!1,ast:!0,plugins:[Ti],configFile:!1});if(!n||!n.ast)throw new Error("Failed to transform JSX");return ue.print(n.ast).code};var Oi=/^["']use client["']$/g,ge=async({sourceFile:e,config:t})=>{if(t.rsc)return e;let r=e.getFirstChildByKind(SyntaxKind.ExpressionStatement);return r&&Oi.test(r.getText())&&r.remove(),e};var he=async({sourceFile:e,config:t})=>(t.tailwind?.prefix&&(e.getDescendantsOfKind(SyntaxKind.CallExpression).filter(r=>r.getExpression().getText()==="cva").forEach(r=>{if(r.getArguments()[0]?.isKind(SyntaxKind.StringLiteral)){let i=r.getArguments()[0];i&&i.replaceWithText(`"${_(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);}r.getArguments()[1]?.isKind(SyntaxKind.ObjectLiteralExpression)&&r.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(`"${_(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);});});}),e.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach(r=>{if(r.getName()==="className"){if(r.getInitializer()?.isKind(SyntaxKind.StringLiteral)){let i=r.getInitializer();i&&i.replaceWithText(`"${_(i.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);}if(r.getInitializer()?.isKind(SyntaxKind.JsxExpression)){let i=r.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(`"${_(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);}),n.isKind(SyntaxKind.StringLiteral)&&n.replaceWithText(`"${_(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);});}}r.getName()==="classNames"&&r.getInitializer()?.isKind(SyntaxKind.JsxExpression)&&r.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(s=>{s.replaceWithText(`"${_(s.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);}),o.isKind(SyntaxKind.StringLiteral)&&o.replaceWithText(`"${_(o.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);});}if(i.getInitializer()?.isKind(SyntaxKind.StringLiteral)&&i.getName()!=="variant"){let n=i.getInitializer();n&&n.replaceWithText(`"${_(n.getText()?.replace(/"|'/g,""),t.tailwind.prefix)}"`);}});})),e);function _(e,t=""){let r=e.split(" "),i=[];for(let n of r){let[o,s,a]=qe(n);o?a?i.push(`${o}:${t}${s}/${a}`):i.push(`${o}:${t}${s}`):a?i.push(`${t}${s}/${a}`):i.push(`${t}${s}`);}return i.join(" ")}var Di=new Project({compilerOptions:{}});async function Fi(e){let t=await promises.mkdtemp(T__default.join(tmpdir(),"shadcn-"));return T__default.join(t,e)}async function ye(e,t=[de,ge,fe,he,me]){let r=await Fi(e.filename),i=Di.createSourceFile(r,e.raw,{scriptKind:ScriptKind.TSX});for(let n of t)await n({sourceFile:i,...e});return e.transformJsx?await Kt({sourceFile:i,...e}):i.getText()}async function Qe(e,t,r){if(!e?.length)return {filesCreated:[],filesUpdated:[],filesSkipped:[]};r={overwrite:!1,force:!1,silent:!1,isRemote:!1,...r};let i=g("Updating files.",{silent:r.silent})?.start(),[n,o]=await Promise.all([O(t.resolvedPaths.cwd),te(t.tailwind.baseColor)]),s=[],a=[],f=[];for(let m of e){if(!m.content)continue;let d=zi(m,t,{isSrcDir:n?.isSrcDir,commonRoot:Mi(e.map(M=>M.path),m.path)}),w=basename(m.path),v=T__default.dirname(d);t.tsx||(d=d.replace(/\.tsx?$/,M=>M===".tsx"?".jsx":".js"));let A=existsSync(d);if(A&&!r.overwrite){i.stop(),r.rootSpinner&&r.rootSpinner.stop();let{overwrite:M}=await et({type:"confirm",name:"overwrite",message:`The file ${l.info(w)} already exists. Would you like to overwrite?`,initial:!1});if(!M){f.push(T__default.relative(t.resolvedPaths.cwd,d)),r.rootSpinner&&r.rootSpinner.start();continue}i?.start(),r.rootSpinner&&r.rootSpinner.start();}existsSync(v)||await promises.mkdir(v,{recursive:!0});let b=await ye({filename:m.path,raw:m.content,config:t,baseColor:o,transformJsx:!t.tsx,isRemote:r.isRemote},[de,ge,fe,he,me]);await promises.writeFile(d,b,"utf-8"),A?a.push(T__default.relative(t.resolvedPaths.cwd,d)):s.push(T__default.relative(t.resolvedPaths.cwd,d));}if(!(s.length||a.length)&&!f.length&&i?.info("No files updated."),s.length){if(i?.succeed(`Created ${s.length} ${s.length===1?"file":"files"}:`),!r.silent)for(let m of s)c.log(` - ${m}`);}else i?.stop();if(a.length&&(g(`Updated ${a.length} ${a.length===1?"file":"files"}:`,{silent:r.silent})?.info(),!r.silent))for(let m of a)c.log(` - ${m}`);if(f.length&&(g(`Skipped ${f.length} ${a.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:r.silent})?.info(),!r.silent))for(let m of f)c.log(` - ${m}`);return r.silent||c.break(),{filesCreated:s,filesUpdated:a,filesSkipped:f}}function zi(e,t,r){if(e.target)return e.target.startsWith("~/")?T__default.join(t.resolvedPaths.cwd,e.target.replace("~/","")):r.isSrcDir?T__default.join(t.resolvedPaths.cwd,"src",e.target.replace("src/","")):T__default.join(t.resolvedPaths.cwd,e.target.replace("src/",""));let i=Ki(e,t),n=Wi(e.path,i);return T__default.join(i,n)}function Ki(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 Mi(e,t){let r=e.map(s=>s.replace(/^\//,"")),i=t.replace(/^\//,""),n=i.split("/").slice(0,-1).join("/");if(!n)return "";let o=n.split("/");for(let s=o.length;s>0;s--){let a=o.slice(0,s).join("/");if(r.some(p=>p!==i&&p.startsWith(a+"/")))return "/"+a}return "/"+n}function Wi(e,t){let r=e.replace(/^\/|\/$/g,""),i=t.replace(/^\/|\/$/g,""),n=r.split("/"),o=i.split("/"),s=o[o.length-1],a=n.findIndex(f=>f===s);return a===-1?n[n.length-1]:n.slice(a+1).join("/")}async function we(e,t,r){r={overwrite:!1,silent:!1,isNewProject:!1,...r};let i=await xt(t);return i&&i?.ui.resolvedPaths.cwd!==t.resolvedPaths.cwd?await Gi(e,t,i,{...r,isRemote:e?.length===1&&!!e[0].match(/\/chat\/b\//)}):await Bi(e,t,r)}async function Bi(e,t,r){let i=g("Checking registry.",{silent:r.silent})?.start(),n=await $t(e,t);if(!n)return i?.fail(),y(new Error("Failed to fetch components from registry."));i?.succeed();let o=await De(t);await Ve(n.tailwind?.config,t,{silent:r.silent,tailwindVersion:o}),await Ye(n.cssVars,t,{cleanupDefaultNextStyles:r.isNewProject,silent:r.silent,tailwindVersion:o,tailwindConfig:n.tailwind?.config}),await re(n.dependencies,t,{silent:r.silent}),await Qe(n.files,t,{overwrite:r.overwrite,silent:r.silent}),n.docs&&c.info(n.docs);}async function Gi(e$1,t,r,i){let n=g("Checking registry.",{silent:i.silent})?.start(),o=await Je(e$1,t),s=await I(o),a=z.array(e).parse(s);if(!a)return n?.fail(),y(new Error("Failed to fetch components from registry."));n?.succeed();let f=Lt(a),p=At(),m=[],d=[],w=[],v=g("Installing components.")?.start();for(let b of a){let M=p.get(b.type),ur=f.get(b.name);if(!M)continue;let E=b.type==="registry:ui"||ur?.type==="registry:ui"?r.ui:t,at=await De(E),B=Ne(t.resolvedPaths.cwd,E.resolvedPaths.ui),ke=await $e(B,E.resolvedPaths.cwd)??E.resolvedPaths.cwd;b.tailwind?.config&&(await Ve(b.tailwind?.config,E,{silent:!0,tailwindVersion:at}),d.push(T__default.relative(B,E.resolvedPaths.tailwindConfig))),b.cssVars&&(await Ye(b.cssVars,E,{silent:!0,tailwindVersion:at,tailwindConfig:b.tailwind?.config}),d.push(T__default.relative(B,E.resolvedPaths.tailwindCss))),await re(b.dependencies,E,{silent:!0});let Te=await Qe(b.files,E,{overwrite:i.overwrite,silent:!0,rootSpinner:v,isRemote:i.isRemote});m.push(...Te.filesCreated.map(J=>T__default.relative(B,T__default.join(ke,J)))),d.push(...Te.filesUpdated.map(J=>T__default.relative(B,T__default.join(ke,J)))),w.push(...Te.filesSkipped.map(J=>T__default.relative(B,T__default.join(ke,J))));}if(v?.succeed(),m.sort(),d.sort(),w.sort(),!(m.length||d.length)&&!w.length&&g("No files updated.",{silent:i.silent})?.info(),m.length){g(`Created ${m.length} ${m.length===1?"file":"files"}:`,{silent:i.silent})?.succeed();for(let b of m)c.log(` - ${b}`);}if(d.length){g(`Updated ${d.length} ${d.length===1?"file":"files"}:`,{silent:i.silent})?.info();for(let b of d)c.log(` - ${b}`);}if(w.length){g(`Skipped ${w.length} ${d.length===1?"file":"files"}: (use --overwrite to overwrite)`,{silent:i.silent})?.info();for(let b of w)c.log(` - ${b}`);}}var Hi="https://codeload.github.com/shadcn-ui/ui/tar.gz/main";async function be(e){e={srcDir:!1,...e};let t="next",r="my-app",i="15.1.0",n=e.components?.length===1&&!!e.components[0].match(/\/chat\/b\//);if(e.components&&n)try{let[a]=await I(e.components),{meta:f}=z.object({meta:z.object({nextVersion:z.string()})}).parse(a);i=f.nextVersion;}catch(a){c.break(),y(a);}if(!e.force){let{type:a,name:f}=await et([{type:"select",name:"type",message:`The path ${l.info(e.cwd)} does not contain a package.json file.
64
+ Would you like to start a new project?`,choices:[{title:"Next.js",value:"next"},{title:"Next.js (Monorepo)",value:"monorepo"}],initial:0},{type:"text",name:"name",message:"What is your project named?",initial:r,format:p=>p.trim(),validate:p=>p.length>128?"Name should be less than 128 characters.":!0}]);t=a,r=f;}let o=await pe(e.cwd,{withFallback:!0}),s=`${e.cwd}/${r}`;try{await U.access(e.cwd,U.constants.W_OK);}catch{c.break(),c.error(`The path ${l.info(e.cwd)} is not writable.`),c.error(`It is likely you do not have write permissions for this folder or the path ${l.info(e.cwd)} does not exist.`),c.break(),process.exit(1);}return U.existsSync(T__default.resolve(e.cwd,r,"package.json"))&&(c.break(),c.error(`A project with the name ${l.info(r)} already exists.`),c.error("Please choose a different name and try again."),c.break(),process.exit(1)),t==="next"&&await qi(s,{version:i,cwd:e.cwd,packageManager:o,srcDir:!!e.srcDir}),t==="monorepo"&&await Qi(s,{packageManager:o}),{projectPath:s,projectName:r,projectType:t}}async function qi(e,t){let r=g("Creating a new Next.js project. This may take a few minutes.").start(),i=["--tailwind","--eslint","--typescript","--app",t.srcDir?"--src-dir":"--no-src-dir","--no-import-alias",`--use-${t.packageManager}`];t.version.startsWith("15")&&i.push("--turbopack");try{await execa("npx",[`create-next-app@${t.version}`,e,"--silent",...i],{cwd:t.cwd});}catch{c.break(),c.error("Something went wrong creating a new Next.js project. Please try again."),process.exit(1);}r?.succeed("Creating a new Next.js project.");}async function Qi(e,t){let r=g("Creating a new Next.js monorepo. This may take a few minutes.").start();try{let i=T__default.join(Ji.tmpdir(),`shadcn-template-${Date.now()}`);await U.ensureDir(i);let n=await fetch(Hi);if(!n.ok)throw new Error(`Failed to download template: ${n.statusText}`);let o=T__default.resolve(i,"template.tar.gz");await U.writeFile(o,Buffer.from(await n.arrayBuffer())),await execa("tar",["-xzf",o,"-C",i,"--strip-components=2","ui-main/templates/monorepo-next"]);let s=T__default.resolve(i,"monorepo-next");await U.move(s,e),await U.remove(i),await execa(t.packageManager,["install"],{cwd:e});let a=process.cwd();await execa("git",["--version"],{cwd:e}),await execa("git",["init"],{cwd:e}),await execa("git",["add","-A"],{cwd:e}),await execa("git",["commit","-m","Initial commit"],{cwd:e}),await execa("cd",[a]),r?.succeed("Creating a new Next.js monorepo.");}catch(i){r?.fail("Something went wrong creating a new Next.js monorepo."),y(i);}}async function Gt(e,t,r){if(!e)return;r={silent:!1,...r};let i=T__default.relative(t.resolvedPaths.cwd,t.resolvedPaths.tailwindConfig),n=g(`Updating ${l.info(i)}`,{silent:r.silent}).start(),o=await promises.readFile(t.resolvedPaths.tailwindConfig,"utf8"),s=await Zi(o,e,t);await promises.writeFile(t.resolvedPaths.tailwindConfig,s,"utf8"),n?.succeed();}async function Zi(e,t,r){let i=await ae(e,r),n=i.getDescendantsOfKind(SyntaxKind.ObjectLiteralExpression).find(o=>o.getProperties().some(s=>s.isKind(SyntaxKind.PropertyAssignment)&&s.getName()==="content"));return n?(en(n,t),i.getFullText()):e}async function en(e,t){let r=ze(e),i=e.getProperty("content");if(!i){let n={name:"content",initializer:`[${r}${t.join(`${r}, ${r}`)}${r}]`};return e.addPropertyAssignment(n),e}if(i.isKind(SyntaxKind.PropertyAssignment)){let n=i.getInitializer();if(n?.isKind(SyntaxKind.ArrayLiteralExpression))for(let o of t){let s=`${r}${o}${r}`;n.getElements().map(a=>a.getText()).includes(s)||n.addElement(s);}return e}return e}var nn=z.object({cwd:z.string(),components:z.array(z.string()).optional(),yes:z.boolean(),defaults:z.boolean(),force:z.boolean(),silent:z.boolean(),isNewProject:z.boolean(),srcDir:z.boolean().optional()}),Jt=new Command().name("init").description("initialize your project and install dependencies").argument("[components...]","the components to add or a url to the component.").option("-y, --yes","skip confirmation prompt.",!0).option("-d, --defaults,","use default configuration.",!1).option("-f, --force","force overwrite of existing configuration.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-s, --silent","mute output.",!1).option("--src-dir","use the src directory when creating a new project.",!1).action(async(e,t)=>{try{let r=nn.parse({cwd:T__default.resolve(t.cwd),isNewProject:!1,components:e,...t});await ve(r),c.log(`${l.success("Success!")} Project initialization completed.
65
+ You may now add components.`),c.break();}catch(r){c.break(),y(r);}});async function ve(e){let t,r;if(e.skipPreflight)t=await O(e.cwd);else {let p=await Rt(e);if(p.errors[C]){let{projectPath:m,projectType:d}=await be(e);m||process.exit(1),e.cwd=m,e.isNewProject=!0,r=d;}t=p.projectInfo;}if(r==="monorepo")return e.cwd=T__default.resolve(e.cwd,"apps/web"),await R(e.cwd);let i=await St(e.cwd,t),n=i?await sn(i,e):await on(await R(e.cwd));if(!e.yes){let{proceed:p}=await et({type:"confirm",name:"proceed",message:`Write configuration to ${l.info("components.json")}. Proceed?`,initial:!0});p||process.exit(0);}let o=g("Writing components.json.").start(),s=T__default.resolve(e.cwd,"components.json");await promises.writeFile(s,JSON.stringify(n,null,2),"utf8"),o.succeed();let a=await q(e.cwd,n),f=["index",...e.components||[]];return await we(f,a,{overwrite:!0,silent:e.silent,isNewProject:e.isNewProject||t?.framework.name==="next-app"}),e.isNewProject&&e.srcDir&&await Gt(["./src/**/*.{js,ts,jsx,tsx,mdx}"],a,{silent:e.silent}),a}async function on(e=null){let[t,r]=await Promise.all([Ue(),Be()]);c.info("");let i=await et([{type:"toggle",name:"typescript",message:`Would you like to use ${l.info("TypeScript")} (recommended)?`,initial:e?.tsx??!0,active:"yes",inactive:"no"},{type:"select",name:"style",message:`Which ${l.info("style")} would you like to use?`,choices:t.map(n=>({title:n.label,value:n.name}))},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${l.info("base color")}?`,choices:r.map(n=>({title:n.label,value:n.name}))},{type:"text",name:"tailwindCss",message:`Where is your ${l.info("global CSS")} file?`,initial:e?.tailwind.css??ht},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${l.info("CSS variables")} for theming?`,initial:e?.tailwind.cssVariables??!0,active:"yes",inactive:"no"},{type:"text",name:"tailwindPrefix",message:`Are you using a custom ${l.info("tailwind prefix eg. tw-")}? (Leave blank if not)`,initial:""},{type:"text",name:"tailwindConfig",message:`Where is your ${l.info("tailwind.config.js")} located?`,initial:e?.tailwind.config??yt},{type:"text",name:"components",message:`Configure the import alias for ${l.info("components")}:`,initial:e?.aliases.components??ut},{type:"text",name:"utils",message:`Configure the import alias for ${l.info("utils")}:`,initial:e?.aliases.utils??gt},{type:"toggle",name:"rsc",message:`Are you using ${l.info("React Server Components")}?`,initial:e?.rsc??!0,active:"yes",inactive:"no"}]);return H.parse({$schema:"https://ui.shadcn.com/schema.json",style:i.style,tailwind:{config:i.tailwindConfig,css:i.tailwindCss,baseColor:i.tailwindBaseColor,cssVariables:i.tailwindCssVariables,prefix:i.tailwindPrefix},rsc:i.rsc,tsx:i.typescript,aliases:{utils:i.utils,components:i.components,lib:i.components.replace(/\/components$/,"lib"),hooks:i.components.replace(/\/components$/,"hooks")}})}async function sn(e,t){let r=e.style,i=e.tailwind.baseColor,n=e.tailwind.cssVariables;if(!t.defaults){let[o,s]=await Promise.all([Ue(),Be()]),a=await et([{type:"select",name:"style",message:`Which ${l.info("style")} would you like to use?`,choices:o.map(f=>({title:f.label,value:f.name})),initial:o.findIndex(f=>f.name===r)},{type:"select",name:"tailwindBaseColor",message:`Which color would you like to use as the ${l.info("base color")}?`,choices:s.map(f=>({title:f.label,value:f.name}))},{type:"toggle",name:"tailwindCssVariables",message:`Would you like to use ${l.info("CSS variables")} for theming?`,initial:e?.tailwind.cssVariables,active:"yes",inactive:"no"}]);r=a.style,i=a.tailwindBaseColor,n=a.tailwindCssVariables;}return H.parse({$schema:e?.$schema,style:r,tailwind:{...e?.tailwind,baseColor:i,cssVariables:n},rsc:e?.rsc,tsx:e?.tsx,aliases:e?.aliases,iconLibrary:e?.iconLibrary})}async function Ht(e){let t={};if(!U.existsSync(e.cwd)||!U.existsSync(T__default.resolve(e.cwd,"package.json")))return t[C]=!0,{errors:t,config:null};if(!U.existsSync(T__default.resolve(e.cwd,"components.json")))return t[D]=!0,{errors:t,config:null};try{let r=await R(e.cwd);return {errors:t,config:r}}catch{c.break(),c.error(`An invalid ${l.info("components.json")} file was found at ${l.info(e.cwd)}.
66
+ Before you can add components, you must create a valid ${l.info("components.json")} file by running the ${l.info("init")} command.`),c.error(`Learn more at ${l.info("https://ui.shadcn.com/docs/components-json")}.`),c.break(),process.exit(1);}}async function Qt(e,t){let r=T__default.join(t.resolvedPaths.cwd,"app/page.tsx");if(!(await ie__default.stat(r)).isFile())return;let i=await Et(e,t.style);if(!i?.meta?.importSpecifier||!i?.meta?.moduleSpecifier)return;let n=`import { ${i?.meta?.importSpecifier} } from "${i.meta.moduleSpecifier}"
67
67
 
68
68
  export default function Page() {
69
69
  return <${i?.meta?.importSpecifier} />
70
- }`;await re__default.writeFile(r,n,"utf8");}var ln=z.object({components:z.array(z.string()).optional(),yes:z.boolean(),overwrite:z.boolean(),cwd:z.string(),all:z.boolean(),path:z.string().optional(),silent:z.boolean(),srcDir:z.boolean().optional()}),Zt=new Command().name("add").description("add a component to your project").argument("[components...]","the components to add or a url to the component.").option("-y, --yes","skip confirmation prompt.",!1).option("-o, --overwrite","overwrite existing files.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-a, --all","add all available components",!1).option("-p, --path <path>","the path to add the component to.").option("-s, --silent","mute output.",!1).option("--src-dir","use the src directory when creating a new project.",!1).action(async(e,t)=>{try{let r=ln.parse({components:e,cwd:T__default.resolve(t.cwd),...t}),i=r.components?.some(a=>a.includes("theme-"));if(!r.yes&&i){c.break();let{confirm:a}=await et({type:"confirm",name:"confirm",message:l.warn(`You are about to install a new theme.
71
- Existing CSS variables will be overwritten. Continue?`)});a||(c.break(),c.log("Theme installation cancelled."),c.break(),process.exit(1));}r.components?.length||(r.components=await pn(r));let{errors:n,config:o}=await Ht(r);if(n[D]){let{proceed:a}=await et({type:"confirm",name:"proceed",message:`You need to create a ${l.info("components.json")} file to add components. Proceed?`,initial:!0});a||(c.break(),process.exit(1)),o=await ve({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!1,silent:!0,isNewProject:!1,srcDir:r.srcDir});}let s=!1;if(n[C]){let{projectPath:a,projectType:m}=await be({cwd:r.cwd,force:r.overwrite,srcDir:r.srcDir,components:r.components});a||(c.break(),process.exit(1)),r.cwd=a,m==="monorepo"?(r.cwd=T__default.resolve(r.cwd,"apps/web"),o=await R(r.cwd)):(o=await ve({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!0,silent:!0,isNewProject:!0,srcDir:r.srcDir}),s=r.components?.length===1&&!!r.components[0].match(/\/chat\/b\//));}if(!o)throw new Error(`Failed to read config at ${l.info(r.cwd)}.`);await we(r.components,o,r),s&&await Qt(r.components[0],o);}catch(r){c.break(),y(r);}});async function pn(e){let t=await Z();if(!t)return c.break(),y(new Error("Failed to fetch registry index.")),[];if(e.all)return t.map(n=>n.name);if(e.components?.length)return e.components;let{components:r}=await et({type:"multiselect",name:"components",message:"Which components would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:!1,choices:t.filter(n=>n.type==="registry:ui").map(n=>({title:n.name,value:n.name,selected:e.all?!0:e.components?.includes(n.name)}))});r?.length||(c.warn("No components selected. Exiting."),c.info(""),process.exit(1));let i=z.array(z.string()).safeParse(r);return i.success?i.data:(c.error(""),y(new Error("Something went wrong. Please try again.")),[])}async function rr(e){let t={},r={cwd:e.cwd,registryFile:T__default.resolve(e.cwd,e.registryFile),outputDir:T__default.resolve(e.cwd,e.outputDir)};return U.existsSync(r.registryFile)||(t[Oe]=!0),await U.mkdir(r.outputDir,{recursive:!0}),Object.keys(t).length>0&&(t[Oe]&&(c.break(),c.error(`The path ${l.info(r.registryFile)} does not exist.`)),c.break(),process.exit(1)),{errors:t,resolvePaths:r}}var fn=z.object({cwd:z.string(),registryFile:z.string(),outputDir:z.string()}),ir=new Command().name("build").description("build components for a shadcn registry").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e$1,t)=>{try{let r=fn.parse({cwd:T.resolve(t.cwd),registryFile:e$1,outputDir:t.output}),{resolvePaths:i}=await rr(r),n=await re.readFile(i.registryFile,"utf-8"),o=f.safeParse(JSON.parse(n));o.success||(c.error(`Invalid registry file found at ${l.info(i.registryFile)}.`),process.exit(1));let s=g("Building registry...");for(let a of o.data.items){if(!a.files)continue;s.start(`Building ${a.name}...`),a.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let p of a.files)p.content=await re.readFile(T.resolve(i.cwd,p.path),"utf-8");let m=e.safeParse(a);if(!m.success){c.error(`Invalid registry item found for ${l.info(a.name)}.`);continue}await re.writeFile(T.resolve(i.outputDir,`${m.data.name}.json`),JSON.stringify(m.data,null,2));}s.succeed("Building registry.");}catch(r){c.break(),y(r);}});var hn=z.object({component:z.string().optional(),yes:z.boolean(),cwd:z.string(),path:z.string().optional()}),or=new Command().name("diff").description("check for updates against the registry").argument("[component]","the component name").option("-y, --yes","skip confirmation prompt.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t)=>{try{let r=hn.parse({component:e,...t}),i=T__default.resolve(r.cwd);existsSync(i)||(c.error(`The path ${i} does not exist. Please try again.`),process.exit(1));let n=await R(i);n||(c.warn(`Configuration is missing. Please run ${l.success("init")} to create a components.json file.`),process.exit(1));let o=await Z();if(o||(y(new Error("Failed to fetch registry index.")),process.exit(1)),!r.component){let m=n.resolvedPaths.components,p=o.filter(d=>{for(let w of d.files??[]){let v=T__default.resolve(m,typeof w=="string"?w:w.path);if(existsSync(v))return !0}return !1}),f=[];for(let d of p){let w=await nr(d,n);w.length&&f.push({name:d.name,changes:w});}f.length||(c.info("No updates found."),process.exit(0)),c.info("The following components have updates available:");for(let d of f){c.info(`- ${d.name}`);for(let w of d.changes)c.info(` - ${w.filePath}`);}c.break(),c.info(`Run ${l.success("diff <component>")} to see the changes.`),process.exit(0);}let s=o.find(m=>m.name===r.component);s||(c.error(`The component ${l.success(r.component)} does not exist.`),process.exit(1));let a=await nr(s,n);a.length||(c.info(`No updates found for ${r.component}.`),process.exit(0));for(let m of a)c.info(`- ${m.filePath}`),await yn(m.patch),c.info("");}catch(r){y(r);}});async function nr(e,t){let r=await jt(t.style,[e]),i=await ee(t.tailwind.baseColor);if(!r)return [];let n=[];for(let o of r){let s=await Ot(t,o);if(s)for(let a of o.files??[]){let m=T__default.resolve(s,typeof a=="string"?a:a.path);if(!existsSync(m))continue;let p=await promises.readFile(m,"utf8");if(typeof a=="string"||!a.content)continue;let f=await ye({filename:a.path,raw:a.content,config:t,baseColor:i}),d=diffLines(f,p);d.length>1&&n.push({filePath:m,patch:d});}}return n}async function yn(e){e.forEach(t=>{if(t)return t.added?process.stdout.write(l.success(t.value)):t.removed?process.stdout.write(l.error(t.value)):process.stdout.write(t.value)});}var sr=new Command().name("info").description("get information about your project").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async e=>{c.info("> project info"),console.log(await j(e.cwd)),c.break(),c.info("> components.json"),console.log(await R(e.cwd));});async function cr(e){if(!e.resolvedPaths.ui)throw new Error("We could not find a valid `ui` path in your `components.json` file. Please ensure you have a valid `ui` path in your `components.json` file.");let t=e.resolvedPaths.ui,[r,i]=await Promise.all([oe("**/*.{js,ts,jsx,tsx}",{cwd:t}),le()]);if(Object.keys(i).length===0)throw new Error("Something went wrong fetching the registry icons.");let n=Object.entries(P).map(([f,d])=>({title:d.name,value:f})),o=await et([{type:"select",name:"sourceLibrary",message:`Which icon library would you like to ${l.info("migrate from")}?`,choices:n},{type:"select",name:"targetLibrary",message:`Which icon library would you like to ${l.info("migrate to")}?`,choices:n}]);if(o.sourceLibrary===o.targetLibrary)throw new Error("You cannot migrate to the same icon library. Please choose a different icon library.");if(!(o.sourceLibrary in P&&o.targetLibrary in P))throw new Error("Invalid icon library. Please choose a valid icon library.");let s=P[o.sourceLibrary],a=P[o.targetLibrary],{confirm:m}=await et({type:"confirm",name:"confirm",initial:!0,message:`We will migrate ${l.info(r.length)} files in ${l.info(`./${T__default.relative(e.resolvedPaths.cwd,t)}`)} from ${l.info(s.name)} to ${l.info(a.name)}. Continue?`});m||(c.info("Migration cancelled."),process.exit(0)),a.package&&await te([a.package],e,{silent:!1});let p=g("Migrating icons...")?.start();await Promise.all(r.map(async f=>{p.text=`Migrating ${f}...`;let d=T__default.join(t,f),w=await promises.readFile(d,"utf-8"),v=await In(w,o.sourceLibrary,o.targetLibrary,i);await promises.writeFile(d,v);})),p.succeed("Migration complete.");}async function In(e,t,r,i){let n=P[t]?.import,o=P[r]?.import,s=await promises.mkdtemp(T__default.join(tmpdir(),"shadcn-")),a=new Project({compilerOptions:{}}),m=T__default.join(s,`shadcn-icons-${randomBytes(4).toString("hex")}.tsx`),p=a.createSourceFile(m,e,{scriptKind:ScriptKind.TSX}),f=[];for(let d of p.getImportDeclarations()??[])if(d.getModuleSpecifier()?.getText()===`"${n}"`){for(let w of d.getNamedImports()??[]){let v=w.getName(),A=Object.values(i).find(b=>b[t]===v)?.[r];!A||f.includes(A)||(f.push(A),w.remove(),p.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).filter(b=>b.getTagNameNode()?.getText()===v).forEach(b=>b.getTagNameNode()?.replaceWithText(A)));}d.getNamedImports()?.length===0&&d.remove();}return f.length>0&&p.addImportDeclaration({moduleSpecifier:o,namedImports:f.map(d=>({name:d}))}),await p.getText()}async function pr(e){let t={};if(!U.existsSync(e.cwd)||!U.existsSync(T__default.resolve(e.cwd,"package.json")))return t[C]=!0,{errors:t,config:null};if(!U.existsSync(T__default.resolve(e.cwd,"components.json")))return t[D]=!0,{errors:t,config:null};try{let r=await R(e.cwd);return {errors:t,config:r}}catch{c.break(),c.error(`An invalid ${l.info("components.json")} file was found at ${l.info(e.cwd)}.
72
- Before you can run a migration, you must create a valid ${l.info("components.json")} file by running the ${l.info("init")} command.`),c.error(`Learn more at ${l.info("https://ui.shadcn.com/docs/components-json")}.`),c.break(),process.exit(1);}}var mr=[{name:"icons",description:"migrate your ui components to a different icon library."}],Tn=z.object({cwd:z.string(),list:z.boolean(),migration:z.string().refine(e=>e&&mr.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional()}),fr=new Command().name("migrate").description("run a migration.").argument("[migration]","the migration to run.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-l, --list","list all migrations.",!1).action(async(e,t)=>{try{let r=Tn.parse({cwd:T__default.resolve(t.cwd),migration:e,list:t.list});if(r.list||!r.migration){c.info("Available migrations:");for(let o of mr)c.info(`- ${o.name}: ${o.description}`);return}if(!r.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:i,config:n}=await pr(r);if(i[C]||i[D])throw new Error("No `components.json` file found. Ensure you are at the root of your project.");if(!n)throw new Error("Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.");r.migration==="icons"&&await cr(n);}catch(r){c.break(),y(r);}});var dr={name:"shadcn",version:"0.0.0-beta.90e6dc1",description:"Add components to your apps.",publishConfig:{access:"public"},license:"MIT",author:{name:"shadcn",url:"https://twitter.com/shadcn"},repository:{type:"git",url:"https://github.com/shadcn/ui.git",directory:"packages/shadcn"},files:["dist"],keywords:["components","ui","tailwind","radix-ui","shadcn"],type:"module",exports:{".":{types:"./dist/index.d.ts",default:"./dist/index.js"},"./registry":{types:"./dist/registry/index.d.ts",default:"./dist/registry/index.js"}},bin:"./dist/index.js",scripts:{dev:"tsup --watch",build:"tsup",typecheck:"tsc --noEmit",clean:"rimraf dist && rimraf components","start:dev":"cross-env REGISTRY_URL=http://localhost:3333/r node dist/index.js","start:prod":"cross-env REGISTRY_URL=https://ui.shadcn.com/r node dist/index.js",start:"node dist/index.js","format:write":'prettier --write "**/*.{ts,tsx,mdx}" --cache',"format:check":'prettier --check "**/*.{ts,tsx,mdx}" --cache',release:"changeset version","pub:beta":"pnpm build && pnpm publish --no-git-checks --access public --tag beta","pub:next":"pnpm build && pnpm publish --no-git-checks --access public --tag next","pub:release":"pnpm build && pnpm publish --access public",test:"vitest run","test:dev":"REGISTRY_URL=http://localhost:3333/r vitest run"},dependencies:{"@antfu/ni":"^0.21.4","@babel/core":"^7.22.1","@babel/parser":"^7.22.6","@babel/plugin-transform-typescript":"^7.22.5",commander:"^10.0.0",cosmiconfig:"^8.1.3",deepmerge:"^4.3.1",diff:"^5.1.0",execa:"^7.0.0","fast-glob":"^3.3.2","fs-extra":"^11.1.0","https-proxy-agent":"^6.2.0",kleur:"^4.1.5","node-fetch":"^3.3.0",ora:"^6.1.2",postcss:"^8.4.24",prompts:"^2.4.2",recast:"^0.23.2","stringify-object":"^5.0.0","ts-morph":"^18.0.0","tsconfig-paths":"^4.2.0",zod:"^3.20.2"},devDependencies:{"@types/babel__core":"^7.20.1","@types/diff":"^5.0.3","@types/fs-extra":"^11.0.1","@types/prompts":"^2.4.2","@types/stringify-object":"^4.0.5",rimraf:"^6.0.1",tsup:"^6.6.3","type-fest":"^3.8.0",typescript:"^4.9.3"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function On(){let e=new Command().name("shadcn").description("add components and dependencies to your project").version(dr.version,"-v, --version","display the version number");e.addCommand(Jt).addCommand(Zt).addCommand(or).addCommand(fr).addCommand(sr).addCommand(ir),e.parse();}On();
70
+ }`;await ie__default.writeFile(r,n,"utf8");}var ln=z.object({components:z.array(z.string()).optional(),yes:z.boolean(),overwrite:z.boolean(),cwd:z.string(),all:z.boolean(),path:z.string().optional(),silent:z.boolean(),srcDir:z.boolean().optional()}),Zt=new Command().name("add").description("add a component to your project").argument("[components...]","the components to add or a url to the component.").option("-y, --yes","skip confirmation prompt.",!1).option("-o, --overwrite","overwrite existing files.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-a, --all","add all available components",!1).option("-p, --path <path>","the path to add the component to.").option("-s, --silent","mute output.",!1).option("--src-dir","use the src directory when creating a new project.",!1).action(async(e,t)=>{try{let r=ln.parse({components:e,cwd:T__default.resolve(t.cwd),...t}),i=r.components?.some(a=>a.includes("theme-"));if(!r.yes&&i){c.break();let{confirm:a}=await et({type:"confirm",name:"confirm",message:l.warn(`You are about to install a new theme.
71
+ Existing CSS variables will be overwritten. Continue?`)});a||(c.break(),c.log("Theme installation cancelled."),c.break(),process.exit(1));}r.components?.length||(r.components=await pn(r));let{errors:n,config:o}=await Ht(r);if(n[D]){let{proceed:a}=await et({type:"confirm",name:"proceed",message:`You need to create a ${l.info("components.json")} file to add components. Proceed?`,initial:!0});a||(c.break(),process.exit(1)),o=await ve({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!1,silent:!0,isNewProject:!1,srcDir:r.srcDir});}let s=!1;if(n[C]){let{projectPath:a,projectType:f}=await be({cwd:r.cwd,force:r.overwrite,srcDir:r.srcDir,components:r.components});a||(c.break(),process.exit(1)),r.cwd=a,f==="monorepo"?(r.cwd=T__default.resolve(r.cwd,"apps/web"),o=await R(r.cwd)):(o=await ve({cwd:r.cwd,yes:!0,force:!0,defaults:!1,skipPreflight:!0,silent:!0,isNewProject:!0,srcDir:r.srcDir}),s=r.components?.length===1&&!!r.components[0].match(/\/chat\/b\//));}if(!o)throw new Error(`Failed to read config at ${l.info(r.cwd)}.`);await we(r.components,o,r),s&&await Qt(r.components[0],o);}catch(r){c.break(),y(r);}});async function pn(e){let t=await ee();if(!t)return c.break(),y(new Error("Failed to fetch registry index.")),[];if(e.all)return t.map(n=>n.name);if(e.components?.length)return e.components;let{components:r}=await et({type:"multiselect",name:"components",message:"Which components would you like to add?",hint:"Space to select. A to toggle all. Enter to submit.",instructions:!1,choices:t.filter(n=>n.type==="registry:ui").map(n=>({title:n.name,value:n.name,selected:e.all?!0:e.components?.includes(n.name)}))});r?.length||(c.warn("No components selected. Exiting."),c.info(""),process.exit(1));let i=z.array(z.string()).safeParse(r);return i.success?i.data:(c.error(""),y(new Error("Something went wrong. Please try again.")),[])}async function rr(e){let t={},r={cwd:e.cwd,registryFile:T__default.resolve(e.cwd,e.registryFile),outputDir:T__default.resolve(e.cwd,e.outputDir)};return U.existsSync(r.registryFile)||(t[Oe]=!0),await U.mkdir(r.outputDir,{recursive:!0}),Object.keys(t).length>0&&(t[Oe]&&(c.break(),c.error(`The path ${l.info(r.registryFile)} does not exist.`)),c.break(),process.exit(1)),{errors:t,resolvePaths:r}}var mn=z.object({cwd:z.string(),registryFile:z.string(),outputDir:z.string()}),ir=new Command().name("build").description("build components for a shadcn registry").argument("[registry]","path to registry.json file","./registry.json").option("-o, --output <path>","destination directory for json files","./public/r").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e$1,t)=>{try{let r=mn.parse({cwd:T.resolve(t.cwd),registryFile:e$1,outputDir:t.output}),{resolvePaths:i}=await rr(r),n=await ie.readFile(i.registryFile,"utf-8"),o=f.safeParse(JSON.parse(n));o.success||(c.error(`Invalid registry file found at ${l.info(i.registryFile)}.`),process.exit(1));let s=g("Building registry...");for(let a of o.data.items){if(!a.files)continue;s.start(`Building ${a.name}...`),a.$schema="https://ui.shadcn.com/schema/registry-item.json";for(let p of a.files)p.content=await ie.readFile(T.resolve(i.cwd,p.path),"utf-8");let f=e.safeParse(a);if(!f.success){c.error(`Invalid registry item found for ${l.info(a.name)}.`);continue}await ie.writeFile(T.resolve(i.outputDir,`${f.data.name}.json`),JSON.stringify(f.data,null,2));}s.succeed("Building registry.");}catch(r){c.break(),y(r);}});var hn=z.object({component:z.string().optional(),yes:z.boolean(),cwd:z.string(),path:z.string().optional()}),or=new Command().name("diff").description("check for updates against the registry").argument("[component]","the component name").option("-y, --yes","skip confirmation prompt.",!1).option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async(e,t)=>{try{let r=hn.parse({component:e,...t}),i=T__default.resolve(r.cwd);existsSync(i)||(c.error(`The path ${i} does not exist. Please try again.`),process.exit(1));let n=await R(i);n||(c.warn(`Configuration is missing. Please run ${l.success("init")} to create a components.json file.`),process.exit(1));let o=await ee();if(o||(y(new Error("Failed to fetch registry index.")),process.exit(1)),!r.component){let f=n.resolvedPaths.components,p=o.filter(d=>{for(let w of d.files??[]){let v=T__default.resolve(f,typeof w=="string"?w:w.path);if(existsSync(v))return !0}return !1}),m=[];for(let d of p){let w=await nr(d,n);w.length&&m.push({name:d.name,changes:w});}m.length||(c.info("No updates found."),process.exit(0)),c.info("The following components have updates available:");for(let d of m){c.info(`- ${d.name}`);for(let w of d.changes)c.info(` - ${w.filePath}`);}c.break(),c.info(`Run ${l.success("diff <component>")} to see the changes.`),process.exit(0);}let s=o.find(f=>f.name===r.component);s||(c.error(`The component ${l.success(r.component)} does not exist.`),process.exit(1));let a=await nr(s,n);a.length||(c.info(`No updates found for ${r.component}.`),process.exit(0));for(let f of a)c.info(`- ${f.filePath}`),await yn(f.patch),c.info("");}catch(r){y(r);}});async function nr(e,t){let r=await jt(t.style,[e]),i=await te(t.tailwind.baseColor);if(!r)return [];let n=[];for(let o of r){let s=await Ot(t,o);if(s)for(let a of o.files??[]){let f=T__default.resolve(s,typeof a=="string"?a:a.path);if(!existsSync(f))continue;let p=await promises.readFile(f,"utf8");if(typeof a=="string"||!a.content)continue;let m=await ye({filename:a.path,raw:a.content,config:t,baseColor:i}),d=diffLines(m,p);d.length>1&&n.push({filePath:f,patch:d});}}return n}async function yn(e){e.forEach(t=>{if(t)return t.added?process.stdout.write(l.success(t.value)):t.removed?process.stdout.write(l.error(t.value)):process.stdout.write(t.value)});}var sr=new Command().name("info").description("get information about your project").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).action(async e=>{c.info("> project info"),console.log(await O(e.cwd)),c.break(),c.info("> components.json"),console.log(await R(e.cwd));});async function cr(e){if(!e.resolvedPaths.ui)throw new Error("We could not find a valid `ui` path in your `components.json` file. Please ensure you have a valid `ui` path in your `components.json` file.");let t=e.resolvedPaths.ui,[r,i]=await Promise.all([oe("**/*.{js,ts,jsx,tsx}",{cwd:t}),le()]);if(Object.keys(i).length===0)throw new Error("Something went wrong fetching the registry icons.");let n=Object.entries(P).map(([m,d])=>({title:d.name,value:m})),o=await et([{type:"select",name:"sourceLibrary",message:`Which icon library would you like to ${l.info("migrate from")}?`,choices:n},{type:"select",name:"targetLibrary",message:`Which icon library would you like to ${l.info("migrate to")}?`,choices:n}]);if(o.sourceLibrary===o.targetLibrary)throw new Error("You cannot migrate to the same icon library. Please choose a different icon library.");if(!(o.sourceLibrary in P&&o.targetLibrary in P))throw new Error("Invalid icon library. Please choose a valid icon library.");let s=P[o.sourceLibrary],a=P[o.targetLibrary],{confirm:f}=await et({type:"confirm",name:"confirm",initial:!0,message:`We will migrate ${l.info(r.length)} files in ${l.info(`./${T__default.relative(e.resolvedPaths.cwd,t)}`)} from ${l.info(s.name)} to ${l.info(a.name)}. Continue?`});f||(c.info("Migration cancelled."),process.exit(0)),a.package&&await re([a.package],e,{silent:!1});let p=g("Migrating icons...")?.start();await Promise.all(r.map(async m=>{p.text=`Migrating ${m}...`;let d=T__default.join(t,m),w=await promises.readFile(d,"utf-8"),v=await In(w,o.sourceLibrary,o.targetLibrary,i);await promises.writeFile(d,v);})),p.succeed("Migration complete.");}async function In(e,t,r,i){let n=P[t]?.import,o=P[r]?.import,s=await promises.mkdtemp(T__default.join(tmpdir(),"shadcn-")),a=new Project({compilerOptions:{}}),f=T__default.join(s,`shadcn-icons-${randomBytes(4).toString("hex")}.tsx`),p=a.createSourceFile(f,e,{scriptKind:ScriptKind.TSX}),m=[];for(let d of p.getImportDeclarations()??[])if(d.getModuleSpecifier()?.getText()===`"${n}"`){for(let w of d.getNamedImports()??[]){let v=w.getName(),A=Object.values(i).find(b=>b[t]===v)?.[r];!A||m.includes(A)||(m.push(A),w.remove(),p.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement).filter(b=>b.getTagNameNode()?.getText()===v).forEach(b=>b.getTagNameNode()?.replaceWithText(A)));}d.getNamedImports()?.length===0&&d.remove();}return m.length>0&&p.addImportDeclaration({moduleSpecifier:o,namedImports:m.map(d=>({name:d}))}),await p.getText()}async function pr(e){let t={};if(!U.existsSync(e.cwd)||!U.existsSync(T__default.resolve(e.cwd,"package.json")))return t[C]=!0,{errors:t,config:null};if(!U.existsSync(T__default.resolve(e.cwd,"components.json")))return t[D]=!0,{errors:t,config:null};try{let r=await R(e.cwd);return {errors:t,config:r}}catch{c.break(),c.error(`An invalid ${l.info("components.json")} file was found at ${l.info(e.cwd)}.
72
+ Before you can run a migration, you must create a valid ${l.info("components.json")} file by running the ${l.info("init")} command.`),c.error(`Learn more at ${l.info("https://ui.shadcn.com/docs/components-json")}.`),c.break(),process.exit(1);}}var fr=[{name:"icons",description:"migrate your ui components to a different icon library."}],Tn=z.object({cwd:z.string(),list:z.boolean(),migration:z.string().refine(e=>e&&fr.some(t=>t.name===e),{message:"You must specify a valid migration. Run `shadcn migrate --list` to see available migrations."}).optional()}),mr=new Command().name("migrate").description("run a migration.").argument("[migration]","the migration to run.").option("-c, --cwd <cwd>","the working directory. defaults to the current directory.",process.cwd()).option("-l, --list","list all migrations.",!1).action(async(e,t)=>{try{let r=Tn.parse({cwd:T__default.resolve(t.cwd),migration:e,list:t.list});if(r.list||!r.migration){c.info("Available migrations:");for(let o of fr)c.info(`- ${o.name}: ${o.description}`);return}if(!r.migration)throw new Error("You must specify a migration. Run `shadcn migrate --list` to see available migrations.");let{errors:i,config:n}=await pr(r);if(i[C]||i[D])throw new Error("No `components.json` file found. Ensure you are at the root of your project.");if(!n)throw new Error("Something went wrong reading your `components.json` file. Please ensure you have a valid `components.json` file.");r.migration==="icons"&&await cr(n);}catch(r){c.break(),y(r);}});var dr={name:"shadcn",version:"0.0.0-beta.9df4b2e",description:"Add components to your apps.",publishConfig:{access:"public"},license:"MIT",author:{name:"shadcn",url:"https://twitter.com/shadcn"},repository:{type:"git",url:"https://github.com/shadcn/ui.git",directory:"packages/shadcn"},files:["dist"],keywords:["components","ui","tailwind","radix-ui","shadcn"],type:"module",exports:{".":{types:"./dist/index.d.ts",default:"./dist/index.js"},"./registry":{types:"./dist/registry/index.d.ts",default:"./dist/registry/index.js"}},bin:"./dist/index.js",scripts:{dev:"tsup --watch",build:"tsup",typecheck:"tsc --noEmit",clean:"rimraf dist && rimraf components","start:dev":"cross-env REGISTRY_URL=http://localhost:3333/r node dist/index.js","start:prod":"cross-env REGISTRY_URL=https://ui.shadcn.com/r node dist/index.js",start:"node dist/index.js","format:write":'prettier --write "**/*.{ts,tsx,mdx}" --cache',"format:check":'prettier --check "**/*.{ts,tsx,mdx}" --cache',release:"changeset version","pub:beta":"pnpm build && pnpm publish --no-git-checks --access public --tag beta","pub:next":"pnpm build && pnpm publish --no-git-checks --access public --tag next","pub:release":"pnpm build && pnpm publish --access public",test:"vitest run","test:dev":"REGISTRY_URL=http://localhost:3333/r vitest run"},dependencies:{"@antfu/ni":"^0.21.4","@babel/core":"^7.22.1","@babel/parser":"^7.22.6","@babel/plugin-transform-typescript":"^7.22.5",commander:"^10.0.0",cosmiconfig:"^8.1.3",deepmerge:"^4.3.1",diff:"^5.1.0",execa:"^7.0.0","fast-glob":"^3.3.2","fs-extra":"^11.1.0","https-proxy-agent":"^6.2.0",kleur:"^4.1.5","node-fetch":"^3.3.0",ora:"^6.1.2",postcss:"^8.4.24",prompts:"^2.4.2",recast:"^0.23.2","stringify-object":"^5.0.0","ts-morph":"^18.0.0","tsconfig-paths":"^4.2.0",zod:"^3.20.2"},devDependencies:{"@types/babel__core":"^7.20.1","@types/diff":"^5.0.3","@types/fs-extra":"^11.0.1","@types/prompts":"^2.4.2","@types/stringify-object":"^4.0.5",rimraf:"^6.0.1",tsup:"^6.6.3","type-fest":"^3.8.0",typescript:"^4.9.3"}};process.on("SIGINT",()=>process.exit(0));process.on("SIGTERM",()=>process.exit(0));async function On(){let e=new Command().name("shadcn").description("add components and dependencies to your project").version(dr.version,"-v, --version","display the version number");e.addCommand(Jt).addCommand(Zt).addCommand(or).addCommand(mr).addCommand(sr).addCommand(ir),e.parse();}On();
73
73
 
74
- export { I as fetchRegistry, jt as fetchTree, Ot as getItemTargetPath, ee as getRegistryBaseColor, Be as getRegistryBaseColors, le as getRegistryIcons, Z as getRegistryIndex, Et as getRegistryItem, Lt as getRegistryParentMap, Ue as getRegistryStyles, At as getRegistryTypeAliasMap, ei as registryGetTheme, $t as registryResolveItemsTree, Je as resolveRegistryItems, Xr as resolveTree };
74
+ export { I as fetchRegistry, jt as fetchTree, Ot as getItemTargetPath, te as getRegistryBaseColor, Be as getRegistryBaseColors, le as getRegistryIcons, ee as getRegistryIndex, Et as getRegistryItem, Lt as getRegistryParentMap, Ue as getRegistryStyles, At as getRegistryTypeAliasMap, ei as registryGetTheme, $t as registryResolveItemsTree, Je as resolveRegistryItems, Xr as resolveTree };
75
75
  //# sourceMappingURL=out.js.map
76
76
  //# sourceMappingURL=index.js.map