shadcn-svelte 1.7.2 → 1.8.0
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.mjs +4 -4
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -127,10 +127,10 @@ ${t?P(`cyan`,an):``}
|
|
|
127
127
|
`)?`
|
|
128
128
|
`:``;j.writeFileSync(r,JSON.stringify(a,null,o)+s,`utf8`)}function Ys(e){return Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)))}function Xs(e){return e.match(/\n([\t ]+)\S/)?.[1]??` `}async function Zs({cwd:e,pm:t,name:n,version:r}){if(t&&t!==`deno`){let i=await $s(e,Qs(t,n,r));if(i)return i}if(t!==`npm`){let t=await $s(e,{command:`npm`,args:[`view`,`${n}@${r}`,`version`]});if(t)return t}}function Qs(e,t,n){switch(e){case`npm`:return{command:`npm`,args:[`view`,`${t}@${n}`,`version`]};case`pnpm`:case`pnpm@6`:return{command:`pnpm`,args:[`view`,`${t}@${n}`,`version`]};case`yarn`:return{command:`yarn`,args:[`info`,`${t}@${n}`,`version`]};case`yarn@berry`:return{command:`yarn`,args:[`npm`,`info`,`${t}@${n}`,`--fields`,`version`]};case`bun`:return{command:`bun`,args:[`info`,`${t}@${n}`,`version`]};default:return}}async function $s(e,t){if(t)try{return ec((await fo(t.command,t.args,{throwOnError:!0,nodeOptions:{cwd:e}})).stdout)}catch{return}}function ec(e){let t=e.trim();if(!t)return;try{let e=t.split(`
|
|
129
129
|
`).filter(e=>e.trim().startsWith(`{`));for(let t of e){let e=JSON.parse(t),n=e.version??e.data?.version;if(typeof n==`string`&&Y.default.valid(n))return n}}catch{}let n=t.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);for(let e=n.length-1;e>=0;e--){let t=n[e];if(Y.default.valid(t))return t}}function tc(e){let t=e,n=`latest`;if(e.startsWith(`@`)?e.includes(`@`,1)&&([,t,n]=e.split(/(.*)(?:@)(.*)/)):e.includes(`@`,1)&&([t,n]=e.split(`@`)),!t||!n)throw O(`Failed to parse dependency: ${e}`);return{name:t,version:n}}function nc({cwd:e,config:t,skipPreflight:n}){let r=rc({svelte:xo(e,`svelte`),tailwindcss:xo(e,`tailwindcss`)},e,t);if(r.ok)return r.config;if(!n)throw r.error;return nr(`${H.default.red(r.error.message)}\nContinuing with ${H.default.bold(`--skip-preflight`)}.`),r.config}function rc(e,t,n){if(!e.tailwindcss||!e.svelte)return{ok:!1,config:n,error:O(`This CLI requires Tailwind CSS and Svelte to be installed.
|
|
130
|
-
`)};let r=Y.satisfies(Y.coerce(e.tailwindcss)??``,`^3.0.0`),i=Y.satisfies(Y.coerce(e.tailwindcss)??``,`^4.0.0`),a=Y.satisfies(Y.coerce(e.svelte)??``,`^5.0.0`);return i&&a?(n&&new URL(n.registry).host===`next.shadcn-svelte.com`&&(n.$schema=D.$schema,n.registry=D.registry,Xo(t,n),V.step(`Config file ${X(`components.json`)} updated`)),{ok:!0,config:n}):r&&a?n&&(n.style?(n.registry=`${g}/registry/${n.style}`,Xo(t,n),V.step(`Config file ${X(`components.json`)} updated`),{ok:!0,config:n}):{ok:!0,config:n}):{ok:!1,config:n,error:O(`This CLI version requires Tailwind CSS (v3 or v4) and Svelte v5.\n\nIf you are on Svelte v4, use ${X(`shadcn-svelte@0.14 add`)} instead, or consider migrating to Svelte 5: ${_}/docs/migration/svelte-5`)}}const ic=o({components:h().array().optional(),yes:a(),all:a(),overwrite:a(),cwd:h(),deps:a(),depsInstall:a(),proxy:h().optional(),skipPreflight:a()}),ac=new Oe().command(`add`).description(`add components to your project`).argument(`[components...]`,`the components to add or a url to the component`).option(`-c, --cwd <path>`,`the working directory`,k.cwd()).addOption(new ke(`--no-deps`,`skips adding & installing package dependencies`).hideHelp()).option(`--no-deps-install`,`add dependencies to package.json without running install`).option(`--skip-preflight`,`ignore preflight checks and continue`,!1).option(`-a, --all`,`install all components to your project`,!1).option(`-y, --yes`,`skip confirmation prompt`,!1).option(`-o, --overwrite`,`overwrite existing files`,!1).option(`--proxy <proxy>`,`fetch components from registry using a proxy`,Qo()).action(async(e,t)=>{try{Oo();let n=ic.parse({components:e,...t}),r=A.resolve(n.cwd);if(!M(r))throw O(`The path ${H.default.cyan(r)} does not exist. Please try again.`);let i=await Ho(r);if(!i)throw new fe(`Configuration file is missing. Please run ${H.default.green(`init`)} to create a ${X(`components.json`)} file.`);await oc(r,nc({config:i,cwd:r,skipPreflight:n.skipPreflight}),n),Zn(`${H.default.green(`Success!`)} Components added.`)}catch(e){Ao(e)}});async function oc(e,t,n){n.proxy!==void 0&&(k.env.HTTP_PROXY=n.proxy,V.info(`You are using the provided proxy: ${H.default.green(n.proxy)}`));let r=(await ts($o(t))).filter(e=>e.type===`registry:ui`),i=new Set(n.all?r.map(({name:e})=>e):n.components);if(i.size===0){let e=await $n({message:`Which ${X(`components`)} would you like to add?`,maxItems:10,options:r.map(e=>{let t=[...e.registryDependencies??[]];return n.deps&&(t=t.concat(e.dependencies??[]).concat(e.devDependencies??[])),{label:e.name,value:e.name,hint:t.length?`also adds: ${t.join(`, `)}`:void 0}})});R(e)&&Z(),i=new Set(e)}else{let e=ko(Array.from(i));V.step(`Components to install:\n${H.default.gray(e)}`)}if(n.yes===!1){let e=await qn({message:`Ready to install ${X(`components`)}${n.deps?` and ${X(`dependencies`)}?`:`?`}`,initialValue:!0});(R(e)||e===!1)&&Z()}let a=await Ms({config:t,deps:n.deps,overwrite:n.overwrite,selectedItems:Array.from(i)});if(n.deps)await Ks({cwd:e,prompt:n.deps,dependencies:Array.from(a.dependencies),devDependencies:Array.from(a.devDependencies),install:n.depsInstall});else if(a.skippedDeps.size){let e=ko([...a.skippedDeps],7);V.warn(`Components have been installed ${H.default.bold(H.default.red(`without`))} the following ${X(`dependencies`)}:\n${H.default.gray(e)}`)}}function
|
|
130
|
+
`)};let r=Y.satisfies(Y.coerce(e.tailwindcss)??``,`^3.0.0`),i=Y.satisfies(Y.coerce(e.tailwindcss)??``,`^4.0.0`),a=Y.satisfies(Y.coerce(e.svelte)??``,`^5.0.0`);return i&&a?(n&&new URL(n.registry).host===`next.shadcn-svelte.com`&&(n.$schema=D.$schema,n.registry=D.registry,Xo(t,n),V.step(`Config file ${X(`components.json`)} updated`)),{ok:!0,config:n}):r&&a?n&&(n.style?(n.registry=`${g}/registry/${n.style}`,Xo(t,n),V.step(`Config file ${X(`components.json`)} updated`),{ok:!0,config:n}):{ok:!0,config:n}):{ok:!1,config:n,error:O(`This CLI version requires Tailwind CSS (v3 or v4) and Svelte v5.\n\nIf you are on Svelte v4, use ${X(`shadcn-svelte@0.14 add`)} instead, or consider migrating to Svelte 5: ${_}/docs/migration/svelte-5`)}}const ic=o({components:h().array().optional(),yes:a(),all:a(),overwrite:a(),cwd:h(),deps:a(),depsInstall:a(),proxy:h().optional(),skipPreflight:a()}),ac=new Oe().command(`add`).description(`add components to your project`).argument(`[components...]`,`the components to add or a url to the component`).option(`-c, --cwd <path>`,`the working directory`,k.cwd()).addOption(new ke(`--no-deps`,`skips adding & installing package dependencies`).hideHelp()).option(`--no-deps-install`,`add dependencies to package.json without running install`).option(`--skip-preflight`,`ignore preflight checks and continue`,!1).option(`-a, --all`,`install all components to your project`,!1).option(`-y, --yes`,`skip confirmation prompt`,!1).option(`-o, --overwrite`,`overwrite existing files`,!1).option(`--proxy <proxy>`,`fetch components from registry using a proxy`,Qo()).action(async(e,t)=>{try{Oo();let n=ic.parse({components:e,...t}),r=A.resolve(n.cwd);if(!M(r))throw O(`The path ${H.default.cyan(r)} does not exist. Please try again.`);let i=await Ho(r);if(!i)throw new fe(`Configuration file is missing. Please run ${H.default.green(`init`)} to create a ${X(`components.json`)} file.`);await oc(r,nc({config:i,cwd:r,skipPreflight:n.skipPreflight}),n),Zn(`${H.default.green(`Success!`)} Components added.`)}catch(e){Ao(e)}});async function oc(e,t,n){n.proxy!==void 0&&(k.env.HTTP_PROXY=n.proxy,V.info(`You are using the provided proxy: ${H.default.green(n.proxy)}`));let r=(await ts($o(t))).filter(e=>e.type===`registry:ui`),i=new Set(n.all?r.map(({name:e})=>e):n.components);if(i.size===0){let e=await $n({message:`Which ${X(`components`)} would you like to add?`,maxItems:10,options:r.map(e=>{let t=[...e.registryDependencies??[]];return n.deps&&(t=t.concat(e.dependencies??[]).concat(e.devDependencies??[])),{label:e.name,value:e.name,hint:t.length?`also adds: ${t.join(`, `)}`:void 0}})});R(e)&&Z(),i=new Set(e)}else{let e=ko(Array.from(i));V.step(`Components to install:\n${H.default.gray(e)}`)}if(n.yes===!1){let e=await qn({message:`Ready to install ${X(`components`)}${n.deps?` and ${X(`dependencies`)}?`:`?`}`,initialValue:!0});(R(e)||e===!1)&&Z()}let a=await Ms({config:t,deps:n.deps,overwrite:n.overwrite,selectedItems:Array.from(i)});if(n.deps)await Ks({cwd:e,prompt:n.deps,dependencies:Array.from(a.dependencies),devDependencies:Array.from(a.devDependencies),install:n.depsInstall});else if(a.skippedDeps.size){let e=ko([...a.skippedDeps],7);V.warn(`Components have been installed ${H.default.bold(H.default.red(`without`))} the following ${X(`dependencies`)}:\n${H.default.gray(e)}`)}}let sc;function cc(){try{return j.statSync(`/.dockerenv`),!0}catch{return!1}}function lc(){try{return j.readFileSync(`/proc/self/cgroup`,`utf8`).includes(`docker`)}catch{return!1}}function uc(){return sc===void 0&&(sc=cc()||lc()),sc}let dc;const fc=()=>{try{return j.statSync(`/run/.containerenv`),!0}catch{return!1}};function pc(){return dc===void 0&&(dc=fc()||uc()),dc}const mc=()=>{if(k.platform!==`linux`)return!1;if(lt.release().toLowerCase().includes(`microsoft`))return!pc();try{if(j.readFileSync(`/proc/version`,`utf8`).toLowerCase().includes(`microsoft`))return!pc()}catch{}return j.existsSync(`/proc/sys/fs/binfmt_misc/WSLInterop`)||j.existsSync(`/run/WSL`)?!pc():!1};var hc=k.env.__IS_WSL_TEST__?mc:mc();const gc=Ve(Xe.execFile),_c=()=>`${k.env.SYSTEMROOT||k.env.windir||String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`,$=async(e,t={})=>{let{powerShellPath:n,...r}=t,i=$.encodeCommand(e);return gc(n??_c(),[...$.argumentsPrefix,i],{encoding:`utf8`,...r})};$.argumentsPrefix=[`-NoProfile`,`-NonInteractive`,`-ExecutionPolicy`,`Bypass`,`-EncodedCommand`],$.encodeCommand=e=>ut.from(e,`utf16le`).toString(`base64`),$.escapeArgument=e=>`'${String(e).replaceAll(`'`,`''`)}'`;function vc(e){for(let t of e.split(`
|
|
131
|
+
`)){if(/^\s*#/.test(t))continue;let e=/^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(t);if(e)return e.groups.mountPoint.trim().replaceAll(/^["']|["']$/g,``)}}const yc=Ve(Xe.execFile),bc=(()=>{let e=`/mnt/`,t;return async function(){if(t)return t;let n=`/etc/wsl.conf`,r=!1;try{await Je.access(n,Ye.F_OK),r=!0}catch{}if(!r)return e;let i=vc(await Je.readFile(n,{encoding:`utf8`}));return i===void 0?e:(t=i,t=t.endsWith(`/`)?t:`${t}/`,t)}})(),xc=hc?async()=>`${await bc()}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`:_c;let Sc;const Cc=async()=>(Sc??=(async()=>{try{let e=await xc();return await Je.access(e,Ye.X_OK),!0}catch{return!1}})(),Sc),wc=async()=>{let e=await xc(),t=String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`,{stdout:n}=await $(t,{powerShellPath:e});return n.trim()},Tc=async e=>{if(/^[a-z]+:\/\//i.test(e))return e;try{let{stdout:t}=await yc(`wslpath`,[`-aw`,e],{encoding:`utf8`});return t.trim()}catch{return e}};function Ec(e,t,n){let r=n=>Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0});return Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){let e=n();return r(e),e},set(e){r(e)}}),e}const Dc=Ve(Ze);async function Oc(){if(k.platform!==`darwin`)throw Error(`macOS only`);let{stdout:e}=await Dc(`defaults`,[`read`,`com.apple.LaunchServices/com.apple.launchservices.secure`,`LSHandlers`]),t=/LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(e)?.groups.id??`com.apple.Safari`;return t===`com.apple.safari`?`com.apple.Safari`:t}const kc=Ve(Ze);async function Ac(e,{humanReadableOutput:t=!0,signal:n}={}){if(k.platform!==`darwin`)throw Error(`macOS only`);let r=t?[]:[`-ss`],i={};n&&(i.signal=n);let{stdout:a}=await kc(`osascript`,[`-e`,e,r],i);return a.trim()}async function jc(e){return Ac(`tell application "Finder" to set app_path to application file id "${e}" as string\ntell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`)}const Mc=Ve(Ze),Nc={MSEdgeHTM:{name:`Edge`,id:`com.microsoft.edge`},MSEdgeBHTML:{name:`Edge Beta`,id:`com.microsoft.edge.beta`},MSEdgeDHTML:{name:`Edge Dev`,id:`com.microsoft.edge.dev`},AppXq0fevzme2pys62n3e0fbqa7peapykr8v:{name:`Edge`,id:`com.microsoft.edge.old`},ChromeHTML:{name:`Chrome`,id:`com.google.chrome`},ChromeBHTML:{name:`Chrome Beta`,id:`com.google.chrome.beta`},ChromeDHTML:{name:`Chrome Dev`,id:`com.google.chrome.dev`},ChromiumHTM:{name:`Chromium`,id:`org.chromium.Chromium`},BraveHTML:{name:`Brave`,id:`com.brave.Browser`},BraveBHTML:{name:`Brave Beta`,id:`com.brave.Browser.beta`},BraveDHTML:{name:`Brave Dev`,id:`com.brave.Browser.dev`},BraveSSHTM:{name:`Brave Nightly`,id:`com.brave.Browser.nightly`},FirefoxURL:{name:`Firefox`,id:`org.mozilla.firefox`},OperaStable:{name:`Opera`,id:`com.operasoftware.Opera`},VivaldiHTM:{name:`Vivaldi`,id:`com.vivaldi.Vivaldi`},"IE.HTTP":{name:`Internet Explorer`,id:`com.microsoft.ie`}},Pc=new Map(Object.entries(Nc));var Fc=class extends Error{};async function Ic(e=Mc){let{stdout:t}=await e(`reg`,[`QUERY`,` HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice`,`/v`,`ProgId`]),n=/ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(t);if(!n)throw new Fc(`Cannot find Windows browser in stdout: ${JSON.stringify(t)}`);let{id:r}=n.groups,i=r.lastIndexOf(`.`),a=r.lastIndexOf(`-`),o=i===-1?void 0:r.slice(0,i),s=a===-1?void 0:r.slice(0,a);return Nc[r]??Nc[o]??Nc[s]??{name:r,id:r}}const Lc=Ve(Ze),Rc=e=>e.toLowerCase().replaceAll(/(?:^|\s|-)\S/g,e=>e.toUpperCase());async function zc(){if(k.platform===`darwin`){let e=await Oc();return{name:await jc(e),id:e}}if(k.platform===`linux`){let{stdout:e}=await Lc(`xdg-mime`,[`query`,`default`,`x-scheme-handler/http`]),t=e.trim();return{name:Rc(t.replace(/.desktop$/,``).replace(`-`,` `)),id:t}}if(k.platform===`win32`)return Ic();throw Error(`Only macOS, Linux, and Windows are supported`)}const Bc=!!(k.env.SSH_CONNECTION||k.env.SSH_CLIENT||k.env.SSH_TTY),Vc=Symbol(`fallbackAttempt`),Hc=import.meta.url?A.dirname(nt(import.meta.url)):``,Uc=A.join(Hc,`xdg-open`),{platform:Wc,arch:Gc}=k,Kc=async(e,t)=>{if(e.length===0)return;let n=[];for(let r of e)try{return await t(r)}catch(e){n.push(e)}throw AggregateError(n,`Failed to open in all supported apps`)},qc=async e=>{e={wait:!1,background:!1,newInstance:!1,allowNonzeroExitCode:!1,...e};let t=e[Vc]===!0;if(delete e[Vc],Array.isArray(e.app))return Kc(e.app,t=>qc({...e,app:t,[Vc]:!0}));let{name:n,arguments:r=[]}=e.app??{};if(r=[...r],Array.isArray(n))return Kc(n,t=>qc({...e,app:{name:t,arguments:r},[Vc]:!0}));if(n===`browser`||n===`browserPrivate`){let t={"com.google.chrome":`chrome`,"google-chrome.desktop":`chrome`,"com.brave.browser":`brave`,"org.mozilla.firefox":`firefox`,"firefox.desktop":`firefox`,"com.microsoft.msedge":`edge`,"com.microsoft.edge":`edge`,"com.microsoft.edgemac":`edge`,"microsoft-edge.desktop":`edge`,"com.apple.safari":`safari`},i={chrome:`--incognito`,brave:`--incognito`,firefox:`--private-window`,edge:`--inPrivate`},a;if(hc){let e=await wc();a=Pc.get(e)??{}}else a=await zc();if(a.id in t){let o=t[a.id.toLowerCase()];if(n===`browserPrivate`){if(o===`safari`)throw Error(`Safari doesn't support opening in private mode via command line`);r.push(i[o])}return qc({...e,app:{name:Zc[o],arguments:r}})}throw Error(`${a.name} is not supported as a default browser`)}let i,a=[],o={},s=!1;if(hc&&!pc()&&!Bc&&!n&&(s=await Cc()),Wc===`darwin`)i=`open`,e.wait&&a.push(`--wait-apps`),e.background&&a.push(`--background`),e.newInstance&&a.push(`--new`),n&&a.push(`-a`,n);else if(Wc===`win32`||s){i=await xc(),a.push(...$.argumentsPrefix),hc||(o.windowsVerbatimArguments=!0),hc&&e.target&&(e.target=await Tc(e.target));let t=[`$ProgressPreference = 'SilentlyContinue';`,`Start`];e.wait&&t.push(`-Wait`),n?(t.push($.escapeArgument(n)),e.target&&r.push(e.target)):e.target&&t.push($.escapeArgument(e.target)),r.length>0&&(r=r.map(e=>$.escapeArgument(e)),t.push(`-ArgumentList`,r.join(`,`))),e.target=$.encodeCommand(t.join(` `)),e.wait||(o.stdio=`ignore`)}else{if(n)i=n;else{let e=!Hc||Hc===`/`,t=!1;try{await Je.access(Uc,Ye.X_OK),t=!0}catch{}i=k.versions.electron??(Wc===`android`||e||!t)?`xdg-open`:Uc}r.length>0&&a.push(...r),e.wait||(o.stdio=`ignore`,o.detached=!0)}Wc===`darwin`&&r.length>0&&a.push(`--args`,...r),e.target&&a.push(e.target);let c=Xe.spawn(i,a,o);return e.wait?new Promise((t,n)=>{c.once(`error`,n),c.once(`close`,r=>{if(!e.allowNonzeroExitCode&&r!==0){n(Error(`Exited with code ${r}`));return}t(c)})}):t?new Promise((e,t)=>{c.once(`error`,t),c.once(`spawn`,()=>{c.once(`close`,n=>{if(c.off(`error`,t),n!==0){t(Error(`Exited with code ${n}`));return}c.unref(),e(c)})})}):(c.unref(),new Promise((e,t)=>{c.once(`error`,t),c.once(`spawn`,()=>{c.off(`error`,t),e(c)})}))},Jc=(e,t)=>{if(typeof e!=`string`)throw TypeError("Expected a `target`");return qc({...t,target:e})};function Yc(e){if(typeof e==`string`||Array.isArray(e))return e;let{[Gc]:t}=e;if(!t)throw Error(`${Gc} is not supported`);return t}function Xc({[Wc]:e},{wsl:t}={}){if(t&&hc)return Yc(t);if(!e)throw Error(`${Wc} is not supported`);return Yc(e)}const Zc={browser:`browser`,browserPrivate:`browserPrivate`};Ec(Zc,`chrome`,()=>Xc({darwin:`google chrome`,win32:`chrome`,linux:[`google-chrome`,`google-chrome-stable`,`chromium`,`chromium-browser`]},{wsl:{ia32:`/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe`,x64:[`/mnt/c/Program Files/Google/Chrome/Application/chrome.exe`,`/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe`]}})),Ec(Zc,`brave`,()=>Xc({darwin:`brave browser`,win32:`brave`,linux:[`brave-browser`,`brave`]},{wsl:{ia32:`/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe`,x64:[`/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe`,`/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe`]}})),Ec(Zc,`firefox`,()=>Xc({darwin:`firefox`,win32:String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,linux:`firefox`},{wsl:`/mnt/c/Program Files/Mozilla Firefox/firefox.exe`})),Ec(Zc,`edge`,()=>Xc({darwin:`microsoft edge`,win32:`msedge`,linux:[`microsoft-edge`,`microsoft-edge-dev`]},{wsl:`/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe`})),Ec(Zc,`safari`,()=>Xc({darwin:`Safari`}));const Qc={nova:{title:`Nova`,description:`Lucide / Geist`,hint:`Reduced spacing for compact layouts.`,style:`nova`,baseColor:`neutral`,theme:`neutral`,chartColor:`neutral`,iconLibrary:`lucide`,font:`geist`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},vega:{title:`Vega`,description:`Lucide / Inter`,hint:`The classic shadcn/ui look.`,style:`vega`,baseColor:`neutral`,theme:`neutral`,chartColor:`neutral`,iconLibrary:`lucide`,font:`inter`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},maia:{title:`Maia`,description:`Hugeicons / Figtree`,hint:`Soft and rounded, with generous spacing.`,style:`maia`,baseColor:`neutral`,theme:`neutral`,chartColor:`neutral`,iconLibrary:`hugeicons`,font:`figtree`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},lyra:{title:`Lyra`,description:`Phosphor / JetBrains Mono`,hint:`Boxy and sharp. Pairs well with mono fonts.`,style:`lyra`,baseColor:`neutral`,theme:`neutral`,chartColor:`neutral`,iconLibrary:`phosphor`,font:`jetbrains-mono`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},mira:{title:`Mira`,description:`Hugeicons / Inter`,hint:`Compact. Made for dense interfaces.`,style:`mira`,baseColor:`neutral`,theme:`neutral`,chartColor:`neutral`,iconLibrary:`hugeicons`,font:`inter`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},luma:{title:`Luma`,description:`Lucide / Inter`,hint:`Rounded geometry. Soft elevation. Breathable layouts.`,style:`luma`,baseColor:`neutral`,theme:`neutral`,chartColor:`neutral`,iconLibrary:`lucide`,font:`inter`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},sera:{title:`Sera`,description:`Lucide / Noto Sans + Playfair Display`,hint:`Editorial and typographic.`,style:`sera`,baseColor:`taupe`,theme:`taupe`,chartColor:`taupe`,iconLibrary:`lucide`,font:`noto-sans`,fontHeading:`playfair-display`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},rhea:{title:`Rhea`,description:`Lucide / Inter`,hint:`Like Luma but compact.`,style:`rhea`,baseColor:`neutral`,theme:`neutral`,chartColor:`neutral`,iconLibrary:`lucide`,font:`inter`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`}},$c=new Map(Object.entries(Qc));function el(e){return $c.get(e)??te(e)}function tl(e){return`Invalid preset: ${H.default.bold(e)}.\nUse one of the available presets: ${Object.keys(Qc).join(`, `)}\nor build your own at ${H.default.cyan(`${_}/create`)}`}async function nl(e){let t=await or({message:`You didn't provide a preset for the design system, how would you like to continue?`,initialValue:e?.style===void 0?`presets`:`prompt`,options:Object.entries(rl).map(([e,t])=>({label:t.label,value:e}))});return R(t)&&Z(),await rl[t].select(e)}const rl={presets:{label:`Choose from a list of pre-configured presets`,select:e=>al(e)},customize:{label:`Create my own preset at ${H.default.bold(`shadcn-svelte.com/create`)}`,select:e=>il(e)},prompt:{label:`Prompt me for the preset`,select:e=>ol(e)}};async function il(e){let t=es(e??D),n=new URL(`/create`,t).toString(),r=ir();r.start(`Opening ${H.default.bold(n)} in your browser`),await Jc(n),r.stop(`Opened ${H.default.bold(n)} in your browser`);let i=e=>(e.startsWith(`--preset `)&&(e=e.slice(9)),e),a=await ur({message:`When you're done, paste the code back here and we'll use it to configure your project.`,placeholder:"Click on the `--preset <code>` button and paste the code here",validate:e=>{let t=i(e??``);if(!T(t))return`Invalid preset code`}});return R(a)&&Z(),te(i(a))}async function al(e){let t=await or({message:`Choose from a list of pre-configured presets`,initialValue:e?.style??`vega`,options:l(Qc).map(([e,t])=>({label:`${t.title} - ${t.description}`,value:e,hint:t.hint}))});return R(t)&&Z(),Qc[t]}async function ol(e){let t=await Jn({style:()=>or({message:`Choose a style`,initialValue:e?.style??D.style,options:l(Qc).map(([e,t])=>({label:t.title,value:e,hint:t.hint}))}),radius:()=>or({message:`Choose a radius`,initialValue:`default`,options:l(C).map(([e,t])=>({label:`${t.label} ${t.value}`,value:e}))}),baseColor:()=>or({message:`Choose a base color`,initialValue:e?.tailwind.baseColor??D.tailwind.baseColor,options:l(ee).map(([e,t])=>({label:`${Eo(t.color)(`■`)} ${t.name}`,value:e}))}),theme:({results:e})=>or({message:`Choose a theme`,initialValue:e.baseColor,options:l(S).map(([e,t])=>({label:`${Eo(t.color)(`■`)} ${t.name}`,value:e}))}),iconLibrary:()=>or({message:`Choose an icon library`,initialValue:e?.iconLibrary??D.iconLibrary,options:l(p).map(([e,t])=>({label:t.title,value:t.name,hint:t.packages.join(`, `)}))}),font:()=>or({message:`Choose a font`,initialValue:`inter`,options:x.map(e=>({label:s(e),value:e}))})},{onCancel:()=>Z()});return{style:t.style,baseColor:t.baseColor,theme:t.theme,iconLibrary:t.iconLibrary,font:t.font,fontHeading:`inherit`,radius:t.radius,menuColor:e?.menuColor??D.menuColor,menuAccent:e?.menuAccent??D.menuAccent}}function sl(e,t){let n=cl({svelte:xo(e,`svelte`),tailwindcss:xo(e,`tailwindcss`)});if(!n.ok){if(!t.skipPreflight)throw n.error;nr(`${H.default.red(n.error.message)}\nContinuing initialization with ${H.default.bold(`--skip-preflight`)}.`)}}function cl(e){if(!e.tailwindcss||!e.svelte)return{ok:!1,error:O(`This CLI version requires Tailwind CSS v4 and Svelte v5 to initialize a project.
|
|
131
132
|
`)};let t=Y.satisfies(Y.coerce(e.tailwindcss)||``,`^3.0.0`),n=Y.satisfies(Y.coerce(e.tailwindcss)||``,`^4.0.0`),r=Y.satisfies(Y.coerce(e.svelte)||``,`^4.0.0`),i=Y.satisfies(Y.coerce(e.svelte)||``,`^5.0.0`);return t&&i?{ok:!1,error:O(`Initializing a project with Tailwind v3 is not supported.
|
|
132
133
|
|
|
133
134
|
This CLI version requires Tailwind v4 and Svelte v5 for the ${X(`init`)} command.\n\nYou have two options:\n1. Update Tailwind CSS to v4 and try again.\n2. Use ${X(`shadcn-svelte@1.0.0-next.10`)} that supports initializing projects with Tailwind v3.\n\nReferences:\nTailwind v4 Guide: ${H.default.underline(`${_}/docs/migration/tailwind-v4`)}\nLegacy Tailwind v3 Docs: ${H.default.underline(`${g}/docs`)}\n\n`)}:t&&r?{ok:!1,error:O(`Initializing a project with Tailwind v3 and Svelte v4 is not supported.\n\nThis CLI version requires Tailwind v4 and Svelte v5 for the ${X(`init`)} command.\n\nPlease use ${X(`shadcn-svelte@0.14`)} that supports Tailwind v3 + Svelte v4.\n\n`)}:!n||!i?{ok:!1,error:O(`This CLI version requires Tailwind CSS v4 and Svelte v5 to initialize a project.
|
|
134
|
-
`)}:{ok:!0}}const lc=[`font`,`theme`],uc=o({cwd:h(),preset:h().optional(),only:i(c(lc)).optional(),yes:a(),silent:a(),skipPreflight:a(),proxy:h().optional(),depsInstall:a()}),dc=new Oe().command(`apply`).description(`apply a preset to an existing project`).argument(`[preset]`,`the preset to apply`).option(`--preset <preset>`,`the preset to use`).addOption(new ke(`--only <parts...>`,`apply only parts of a preset: theme, font`).choices(lc)).option(`-c, --cwd <path>`,`the working directory`,k.cwd()).option(`-y, --yes`,`skip confirmation prompt`,!1).option(`-s, --silent`,`mute output`,!1).option(`--no-deps-install`,`add dependencies to package.json without running install`).option(`--skip-preflight`,`ignore preflight checks and continue`,!1).option(`--proxy <proxy>`,`fetch items from registry using a proxy`,Qo()).action(async(e,t)=>{t.silent||Oo();let n=uc.parse(t),r=A.resolve(n.cwd);try{if(!M(r))throw O(`The path ${H.default.cyan(r)} does not exist. Please try again.`);let t=n.preset||e;if(t===void 0)throw O(`${H.default.bold(`--preset`)} is required.`);let i=te(t);if(i===null)throw O(`${H.default.bold(`--preset ${t}`)} is not a valid preset.`);sc(r,{skipPreflight:n.skipPreflight});let a=await Ho(r);if(!a)throw new fe(`Configuration file is missing. Please run ${H.default.green(`init`)} to create a ${X(`components.json`)} file.`);await fc({cwd:r,config:a,decidedPresets:i,options:n}),n.silent||Zn(`Preset ${H.default.bold(t)} applied successfully.`)}catch(e){Ao(e)}});async function fc({cwd:e,config:t,decidedPresets:n,options:r}){r.proxy!==void 0&&(k.env.HTTP_PROXY=r.proxy,V.info(`You are using the provided proxy: ${H.default.green(r.proxy)}`));let i=r.only&&r.only.length>0?r.only:void 0,a=i===void 0||i.includes(`theme`),o=i?.includes(`theme`);if(a){t.iconLibrary=n.iconLibrary,t.menuColor=n.menuColor,t.menuAccent=n.menuAccent,t.style=n.style,t.tailwind.baseColor=n.baseColor;let i=ir();r.silent||i.start(`Applying preset ${H.default.bold(r.preset)} to config file`),Xo(e,t),r.silent||i.stop(`Applied preset ${H.default.bold(r.preset)} to config file`)}let s=$o(t),c=w(n),l=await Ms({selectedItems:[new URL(`/init?preset=${c}`,s).toString()],config:t,deps:!0,overwrite:r.yes,silent:r.silent,only:i,skipExisting:!0,forceStylesheet:!0});o||await Ks({cwd:e,prompt:!1,dependencies:Array.from(l.dependencies),devDependencies:Array.from(l.devDependencies),silent:r.silent,install:r.depsInstall})}let pc;function mc(){try{return j.statSync(`/.dockerenv`),!0}catch{return!1}}function hc(){try{return j.readFileSync(`/proc/self/cgroup`,`utf8`).includes(`docker`)}catch{return!1}}function gc(){return pc===void 0&&(pc=mc()||hc()),pc}let _c;const vc=()=>{try{return j.statSync(`/run/.containerenv`),!0}catch{return!1}};function yc(){return _c===void 0&&(_c=vc()||gc()),_c}const bc=()=>{if(k.platform!==`linux`)return!1;if(lt.release().toLowerCase().includes(`microsoft`))return!yc();try{if(j.readFileSync(`/proc/version`,`utf8`).toLowerCase().includes(`microsoft`))return!yc()}catch{}return j.existsSync(`/proc/sys/fs/binfmt_misc/WSLInterop`)||j.existsSync(`/run/WSL`)?!yc():!1};var xc=k.env.__IS_WSL_TEST__?bc:bc();const Sc=Ve(Xe.execFile),Cc=()=>`${k.env.SYSTEMROOT||k.env.windir||String.raw`C:\Windows`}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`,$=async(e,t={})=>{let{powerShellPath:n,...r}=t,i=$.encodeCommand(e);return Sc(n??Cc(),[...$.argumentsPrefix,i],{encoding:`utf8`,...r})};$.argumentsPrefix=[`-NoProfile`,`-NonInteractive`,`-ExecutionPolicy`,`Bypass`,`-EncodedCommand`],$.encodeCommand=e=>ut.from(e,`utf16le`).toString(`base64`),$.escapeArgument=e=>`'${String(e).replaceAll(`'`,`''`)}'`;function wc(e){for(let t of e.split(`
|
|
135
|
-
`)){if(/^\s*#/.test(t))continue;let e=/^\s*root\s*=\s*(?<mountPoint>"[^"]*"|'[^']*'|[^#]*)/.exec(t);if(e)return e.groups.mountPoint.trim().replaceAll(/^["']|["']$/g,``)}}const Tc=Ve(Xe.execFile),Ec=(()=>{let e=`/mnt/`,t;return async function(){if(t)return t;let n=`/etc/wsl.conf`,r=!1;try{await Je.access(n,Ye.F_OK),r=!0}catch{}if(!r)return e;let i=wc(await Je.readFile(n,{encoding:`utf8`}));return i===void 0?e:(t=i,t=t.endsWith(`/`)?t:`${t}/`,t)}})(),Dc=xc?async()=>`${await Ec()}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe`:Cc;let Oc;const kc=async()=>(Oc??=(async()=>{try{let e=await Dc();return await Je.access(e,Ye.X_OK),!0}catch{return!1}})(),Oc),Ac=async()=>{let e=await Dc(),t=String.raw`(Get-ItemProperty -Path "HKCU:\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice").ProgId`,{stdout:n}=await $(t,{powerShellPath:e});return n.trim()},jc=async e=>{if(/^[a-z]+:\/\//i.test(e))return e;try{let{stdout:t}=await Tc(`wslpath`,[`-aw`,e],{encoding:`utf8`});return t.trim()}catch{return e}};function Mc(e,t,n){let r=n=>Object.defineProperty(e,t,{value:n,enumerable:!0,writable:!0});return Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){let e=n();return r(e),e},set(e){r(e)}}),e}const Nc=Ve(Ze);async function Pc(){if(k.platform!==`darwin`)throw Error(`macOS only`);let{stdout:e}=await Nc(`defaults`,[`read`,`com.apple.LaunchServices/com.apple.launchservices.secure`,`LSHandlers`]),t=/LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(e)?.groups.id??`com.apple.Safari`;return t===`com.apple.safari`?`com.apple.Safari`:t}const Fc=Ve(Ze);async function Ic(e,{humanReadableOutput:t=!0,signal:n}={}){if(k.platform!==`darwin`)throw Error(`macOS only`);let r=t?[]:[`-ss`],i={};n&&(i.signal=n);let{stdout:a}=await Fc(`osascript`,[`-e`,e,r],i);return a.trim()}async function Lc(e){return Ic(`tell application "Finder" to set app_path to application file id "${e}" as string\ntell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`)}const Rc=Ve(Ze),zc={MSEdgeHTM:{name:`Edge`,id:`com.microsoft.edge`},MSEdgeBHTML:{name:`Edge Beta`,id:`com.microsoft.edge.beta`},MSEdgeDHTML:{name:`Edge Dev`,id:`com.microsoft.edge.dev`},AppXq0fevzme2pys62n3e0fbqa7peapykr8v:{name:`Edge`,id:`com.microsoft.edge.old`},ChromeHTML:{name:`Chrome`,id:`com.google.chrome`},ChromeBHTML:{name:`Chrome Beta`,id:`com.google.chrome.beta`},ChromeDHTML:{name:`Chrome Dev`,id:`com.google.chrome.dev`},ChromiumHTM:{name:`Chromium`,id:`org.chromium.Chromium`},BraveHTML:{name:`Brave`,id:`com.brave.Browser`},BraveBHTML:{name:`Brave Beta`,id:`com.brave.Browser.beta`},BraveDHTML:{name:`Brave Dev`,id:`com.brave.Browser.dev`},BraveSSHTM:{name:`Brave Nightly`,id:`com.brave.Browser.nightly`},FirefoxURL:{name:`Firefox`,id:`org.mozilla.firefox`},OperaStable:{name:`Opera`,id:`com.operasoftware.Opera`},VivaldiHTM:{name:`Vivaldi`,id:`com.vivaldi.Vivaldi`},"IE.HTTP":{name:`Internet Explorer`,id:`com.microsoft.ie`}},Bc=new Map(Object.entries(zc));var Vc=class extends Error{};async function Hc(e=Rc){let{stdout:t}=await e(`reg`,[`QUERY`,` HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice`,`/v`,`ProgId`]),n=/ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(t);if(!n)throw new Vc(`Cannot find Windows browser in stdout: ${JSON.stringify(t)}`);let{id:r}=n.groups,i=r.lastIndexOf(`.`),a=r.lastIndexOf(`-`),o=i===-1?void 0:r.slice(0,i),s=a===-1?void 0:r.slice(0,a);return zc[r]??zc[o]??zc[s]??{name:r,id:r}}const Uc=Ve(Ze),Wc=e=>e.toLowerCase().replaceAll(/(?:^|\s|-)\S/g,e=>e.toUpperCase());async function Gc(){if(k.platform===`darwin`){let e=await Pc();return{name:await Lc(e),id:e}}if(k.platform===`linux`){let{stdout:e}=await Uc(`xdg-mime`,[`query`,`default`,`x-scheme-handler/http`]),t=e.trim();return{name:Wc(t.replace(/.desktop$/,``).replace(`-`,` `)),id:t}}if(k.platform===`win32`)return Hc();throw Error(`Only macOS, Linux, and Windows are supported`)}const Kc=!!(k.env.SSH_CONNECTION||k.env.SSH_CLIENT||k.env.SSH_TTY),qc=Symbol(`fallbackAttempt`),Jc=import.meta.url?A.dirname(nt(import.meta.url)):``,Yc=A.join(Jc,`xdg-open`),{platform:Xc,arch:Zc}=k,Qc=async(e,t)=>{if(e.length===0)return;let n=[];for(let r of e)try{return await t(r)}catch(e){n.push(e)}throw AggregateError(n,`Failed to open in all supported apps`)},$c=async e=>{e={wait:!1,background:!1,newInstance:!1,allowNonzeroExitCode:!1,...e};let t=e[qc]===!0;if(delete e[qc],Array.isArray(e.app))return Qc(e.app,t=>$c({...e,app:t,[qc]:!0}));let{name:n,arguments:r=[]}=e.app??{};if(r=[...r],Array.isArray(n))return Qc(n,t=>$c({...e,app:{name:t,arguments:r},[qc]:!0}));if(n===`browser`||n===`browserPrivate`){let t={"com.google.chrome":`chrome`,"google-chrome.desktop":`chrome`,"com.brave.browser":`brave`,"org.mozilla.firefox":`firefox`,"firefox.desktop":`firefox`,"com.microsoft.msedge":`edge`,"com.microsoft.edge":`edge`,"com.microsoft.edgemac":`edge`,"microsoft-edge.desktop":`edge`,"com.apple.safari":`safari`},i={chrome:`--incognito`,brave:`--incognito`,firefox:`--private-window`,edge:`--inPrivate`},a;if(xc){let e=await Ac();a=Bc.get(e)??{}}else a=await Gc();if(a.id in t){let o=t[a.id.toLowerCase()];if(n===`browserPrivate`){if(o===`safari`)throw Error(`Safari doesn't support opening in private mode via command line`);r.push(i[o])}return $c({...e,app:{name:rl[o],arguments:r}})}throw Error(`${a.name} is not supported as a default browser`)}let i,a=[],o={},s=!1;if(xc&&!yc()&&!Kc&&!n&&(s=await kc()),Xc===`darwin`)i=`open`,e.wait&&a.push(`--wait-apps`),e.background&&a.push(`--background`),e.newInstance&&a.push(`--new`),n&&a.push(`-a`,n);else if(Xc===`win32`||s){i=await Dc(),a.push(...$.argumentsPrefix),xc||(o.windowsVerbatimArguments=!0),xc&&e.target&&(e.target=await jc(e.target));let t=[`$ProgressPreference = 'SilentlyContinue';`,`Start`];e.wait&&t.push(`-Wait`),n?(t.push($.escapeArgument(n)),e.target&&r.push(e.target)):e.target&&t.push($.escapeArgument(e.target)),r.length>0&&(r=r.map(e=>$.escapeArgument(e)),t.push(`-ArgumentList`,r.join(`,`))),e.target=$.encodeCommand(t.join(` `)),e.wait||(o.stdio=`ignore`)}else{if(n)i=n;else{let e=!Jc||Jc===`/`,t=!1;try{await Je.access(Yc,Ye.X_OK),t=!0}catch{}i=k.versions.electron??(Xc===`android`||e||!t)?`xdg-open`:Yc}r.length>0&&a.push(...r),e.wait||(o.stdio=`ignore`,o.detached=!0)}Xc===`darwin`&&r.length>0&&a.push(`--args`,...r),e.target&&a.push(e.target);let c=Xe.spawn(i,a,o);return e.wait?new Promise((t,n)=>{c.once(`error`,n),c.once(`close`,r=>{if(!e.allowNonzeroExitCode&&r!==0){n(Error(`Exited with code ${r}`));return}t(c)})}):t?new Promise((e,t)=>{c.once(`error`,t),c.once(`spawn`,()=>{c.once(`close`,n=>{if(c.off(`error`,t),n!==0){t(Error(`Exited with code ${n}`));return}c.unref(),e(c)})})}):(c.unref(),new Promise((e,t)=>{c.once(`error`,t),c.once(`spawn`,()=>{c.off(`error`,t),e(c)})}))},el=(e,t)=>{if(typeof e!=`string`)throw TypeError("Expected a `target`");return $c({...t,target:e})};function tl(e){if(typeof e==`string`||Array.isArray(e))return e;let{[Zc]:t}=e;if(!t)throw Error(`${Zc} is not supported`);return t}function nl({[Xc]:e},{wsl:t}={}){if(t&&xc)return tl(t);if(!e)throw Error(`${Xc} is not supported`);return tl(e)}const rl={browser:`browser`,browserPrivate:`browserPrivate`};Mc(rl,`chrome`,()=>nl({darwin:`google chrome`,win32:`chrome`,linux:[`google-chrome`,`google-chrome-stable`,`chromium`,`chromium-browser`]},{wsl:{ia32:`/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe`,x64:[`/mnt/c/Program Files/Google/Chrome/Application/chrome.exe`,`/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe`]}})),Mc(rl,`brave`,()=>nl({darwin:`brave browser`,win32:`brave`,linux:[`brave-browser`,`brave`]},{wsl:{ia32:`/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe`,x64:[`/mnt/c/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe`,`/mnt/c/Program Files (x86)/BraveSoftware/Brave-Browser/Application/brave.exe`]}})),Mc(rl,`firefox`,()=>nl({darwin:`firefox`,win32:String.raw`C:\Program Files\Mozilla Firefox\firefox.exe`,linux:`firefox`},{wsl:`/mnt/c/Program Files/Mozilla Firefox/firefox.exe`})),Mc(rl,`edge`,()=>nl({darwin:`microsoft edge`,win32:`msedge`,linux:[`microsoft-edge`,`microsoft-edge-dev`]},{wsl:`/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe`})),Mc(rl,`safari`,()=>nl({darwin:`Safari`}));const il={nova:{title:`Nova`,description:`Lucide / Geist`,hint:`Reduced spacing for compact layouts.`,style:`nova`,baseColor:`neutral`,theme:`neutral`,iconLibrary:`lucide`,font:`geist`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},vega:{title:`Vega`,description:`Lucide / Inter`,hint:`The classic shadcn/ui look.`,style:`vega`,baseColor:`neutral`,theme:`neutral`,iconLibrary:`lucide`,font:`inter`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},maia:{title:`Maia`,description:`Hugeicons / Figtree`,hint:`Soft and rounded, with generous spacing.`,style:`maia`,baseColor:`neutral`,theme:`neutral`,iconLibrary:`hugeicons`,font:`figtree`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},lyra:{title:`Lyra`,description:`Phosphor / JetBrains Mono`,hint:`Boxy and sharp. Pairs well with mono fonts.`,style:`lyra`,baseColor:`neutral`,theme:`neutral`,iconLibrary:`phosphor`,font:`jetbrains-mono`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},mira:{title:`Mira`,description:`Hugeicons / Inter`,hint:`Compact. Made for dense interfaces.`,style:`mira`,baseColor:`neutral`,theme:`neutral`,iconLibrary:`hugeicons`,font:`inter`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},luma:{title:`Luma`,description:`Lucide / Inter`,hint:`Rounded geometry. Soft elevation. Breathable layouts.`,style:`luma`,baseColor:`neutral`,theme:`neutral`,iconLibrary:`lucide`,font:`inter`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},sera:{title:`Sera`,description:`Lucide / Noto Sans + Playfair Display`,hint:`Editorial and typographic.`,style:`sera`,baseColor:`taupe`,theme:`taupe`,iconLibrary:`lucide`,font:`noto-sans`,fontHeading:`playfair-display`,menuAccent:`subtle`,menuColor:`default`,radius:`default`},rhea:{title:`Rhea`,description:`Lucide / Inter`,hint:`Like Luma but compact.`,style:`rhea`,baseColor:`neutral`,theme:`neutral`,iconLibrary:`lucide`,font:`inter`,fontHeading:`inherit`,menuAccent:`subtle`,menuColor:`default`,radius:`default`}};async function al(e){let t=await or({message:`You didn't provide a preset for the design system, how would you like to continue?`,initialValue:e?.style===void 0?`presets`:`prompt`,options:Object.entries(ol).map(([e,t])=>({label:t.label,value:e}))});return R(t)&&Z(),await ol[t].select(e)}const ol={presets:{label:`Choose from a list of pre-configured presets`,select:e=>cl(e)},customize:{label:`Create my own preset at ${H.default.bold(`shadcn-svelte.com/create`)}`,select:e=>sl(e)},prompt:{label:`Prompt me for the preset`,select:e=>ll(e)}};async function sl(e){let t=es(e??D),n=new URL(`/create`,t).toString(),r=ir();r.start(`Opening ${H.default.bold(n)} in your browser`),await el(n),r.stop(`Opened ${H.default.bold(n)} in your browser`);let i=e=>(e.startsWith(`--preset `)&&(e=e.slice(9)),e),a=await ur({message:`When you're done, paste the code back here and we'll use it to configure your project.`,placeholder:"Click on the `--preset <code>` button and paste the code here",validate:e=>{let t=i(e??``);if(!T(t))return`Invalid preset code`}});return R(a)&&Z(),te(i(a))}async function cl(e){let t=await or({message:`Choose from a list of pre-configured presets`,initialValue:e?.style??`vega`,options:l(il).map(([e,t])=>({label:`${t.title} - ${t.description}`,value:e,hint:t.hint}))});return R(t)&&Z(),il[t]}async function ll(e){let t=await Jn({style:()=>or({message:`Choose a style`,initialValue:e?.style??D.style,options:l(il).map(([e,t])=>({label:t.title,value:e,hint:t.hint}))}),radius:()=>or({message:`Choose a radius`,initialValue:`default`,options:l(C).map(([e,t])=>({label:`${t.label} ${t.value}`,value:e}))}),baseColor:()=>or({message:`Choose a base color`,initialValue:e?.tailwind.baseColor??D.tailwind.baseColor,options:l(ee).map(([e,t])=>({label:`${Eo(t.color)(`■`)} ${t.name}`,value:e}))}),theme:({results:e})=>or({message:`Choose a theme`,initialValue:e.baseColor,options:l(S).map(([e,t])=>({label:`${Eo(t.color)(`■`)} ${t.name}`,value:e}))}),iconLibrary:()=>or({message:`Choose an icon library`,initialValue:e?.iconLibrary??D.iconLibrary,options:l(p).map(([e,t])=>({label:t.title,value:t.name,hint:t.packages.join(`, `)}))}),font:()=>or({message:`Choose a font`,initialValue:`inter`,options:x.map(e=>({label:s(e),value:e}))})},{onCancel:()=>Z()});return{style:t.style,baseColor:t.baseColor,theme:t.theme,iconLibrary:t.iconLibrary,font:t.font,fontHeading:`inherit`,radius:t.radius,menuColor:e?.menuColor??D.menuColor,menuAccent:e?.menuAccent??D.menuAccent}}const ul=ns(),dl=o({cwd:h(),baseColor:h().optional(),preset:h().optional(),css:h().optional(),componentsAlias:h().optional(),utilsAlias:h().optional(),libAlias:h().optional(),hooksAlias:h().optional(),uiAlias:h().optional(),deps:a(),depsInstall:a(),overwrite:a(),proxy:h().optional(),skipPreflight:a(),reinstall:a().optional()}),fl=new Oe().command(`init`).description(`initialize your project and install dependencies`).option(`--preset <preset>`,`the preset to use`).option(`-c, --cwd <path>`,`the working directory`,k.cwd()).addOption(new ke(`-o, --overwrite`,`deprecated: use --reinstall`).default(!1).hideHelp()).addOption(new ke(`--no-deps`,`disable adding & installing dependencies`).hideHelp()).option(`--no-deps-install`,`add dependencies to package.json without running install`).option(`--skip-preflight`,`ignore preflight checks and continue`,!1).option(`--reinstall`,`reinstall existing components when style changes`).option(`--no-reinstall`,`skip reinstalling existing components when style changes`).addOption(new ke(`--base-color <name>`,`the base color for the components`).choices(ul.map(e=>e.name))).option(`--css <path>`,`path to the global CSS file`).option(`--components-alias <path>`,`import alias for components`).option(`--lib-alias <path>`,`import alias for lib`).option(`--utils-alias <path>`,`import alias for utils`).option(`--hooks-alias <path>`,`import alias for hooks`).option(`--ui-alias <path>`,`import alias for ui`).option(`--proxy <proxy>`,`fetch items from registry using a proxy`,Qo()).action(async e=>{Oo();let t=dl.parse(e),n=A.resolve(t.cwd);try{if(!M(n))throw O(`The path ${H.default.cyan(n)} does not exist. Please try again.`);let e=null;t.preset!==void 0&&(e=te(t.preset),e===null&&V.warn(`${H.default.dim(`--preset ${t.preset}`)} is not a valid preset.`)),sc(n,{skipPreflight:t.skipPreflight});let r=Wo(n);r&&=nc({cwd:n,config:r,skipPreflight:t.skipPreflight});let{resolvedConfig:i,decidedPresets:a,styleChanged:o}=await ml({cwd:n,presetConfig:e,existingConfig:r,options:t});await hl({cwd:n,config:i,decidedPresets:a,options:t,styleChanged:o}),Zn(`${H.default.green(`Success!`)} Project initialization completed.`)}catch(e){Ao(e)}}).on(`option:overwrite`,()=>{console.warn(H.default.yellow(`Warning: ${H.default.bold(`--overwrite`)} is deprecated. Use ${H.default.bold(`--reinstall`)} instead.\n`))});function pl(e,t,n){if(t.css&&!M(A.resolve(e,t.css)))throw O(`The provided global CSS file path ${H.default.cyan(t.css)} does not exist. Please enter a valid path.`);for(let[r,i]of Object.entries(t)){if(!r.endsWith(`Alias`))continue;let t=qo({cwd:e,importPath:i,tsconfig:n});if(t)throw O(t)}}async function ml({cwd:e,presetConfig:t,existingConfig:n,options:r}){let i=n??structuredClone(D);await vo(e);let{cssPath:a,tsconfigPath:o,packageImportAlias:s}=zs(e,{relative:!0}),c;if(n)c=Zo(e,n);else{if(o)i.typescript=o.includes(`tsconfig`);else{let t=await ur({message:`Where is your ${X(`tsconfig/jsconfig`)} file?`,placeholder:`tsconfig.json`,validate:t=>{let n=A.resolve(e,t??``);if(!(t&&M(n)))return`"${H.default.bold(t)}" does not exist. Please enter a valid path.`}});R(t)&&Z(),i.typescript={config:t}}c=Zo(e,i)}pl(e,r,c);let l=t??await al(n),u=r.css;if(u===void 0){let t=D.tailwind.css,r=await ur({message:`Where is your ${X(`global CSS`)} file? ${H.default.gray(`(this file will be overwritten)`)}`,initialValue:n?.tailwind.css??a??t,placeholder:a??t,validate:t=>{if(!(t&&M(A.resolve(e,t))))return`"${H.default.bold(t)}" does not exist. Please enter a valid path.`}});R(r)&&Z(),u=r}let{utilsAlias:d,libAlias:f,componentAlias:p,hooksAlias:m,uiAlias:h}=await Jo({...r,libAliasDefault:s,tsconfig:c,cwd:e,existingConfig:n}),g=Go({...i,tailwind:{css:u,baseColor:l.baseColor},aliases:{utils:d,lib:f,components:p,hooks:m,ui:h},style:l.style,iconLibrary:l.iconLibrary,menuColor:l.menuColor,menuAccent:l.menuAccent}),_;return _=n?n.style!==l.style||n.menuColor!==l.menuColor||n.menuAccent!==l.menuAccent:!1,{resolvedConfig:await Uo(e,g),decidedPresets:l,styleChanged:_}}async function hl({cwd:e,config:t,decidedPresets:n,options:r,styleChanged:i}){r.proxy!==void 0&&(k.env.HTTP_PROXY=r.proxy,V.info(`You are using the provided proxy: ${H.default.green(r.proxy)}`));let a=[];a.push({title:`Creating config file`,async task(){return Xo(e,t),`Config file ${X(`components.json`)} created`}}),a.push({title:`Validating alias paths`,async task(){for(let[e,n]of Object.entries(t.resolvedPaths)){let t=A.extname(n)?A.dirname(n):n;e===`utils`&&n.endsWith(`/utils`)&&(t=t.replace(/\/utils$/,``)),!M(t)&&e!==`utils`&&await N.mkdir(t,{recursive:!0})}return`Alias paths validated`}}),await sr(a);let o=$o(t),s=w(n),c=new URL(`/init?preset=${s}`,o).toString(),l=[],u=r.overwrite||r.reinstall===!0;if(i&&r.reinstall!==!1&&(l=(await _o({registryIndex:await ts(o),config:t})).filter(e=>e.name!==`utils`).map(e=>e.name),l.length>0&&!u)){V.warn(`The registry style has changed to ${H.default.bold(H.default.yellow(n.style))}.`);let e=await qn({message:`Would you like to ${H.default.bold(H.default.red(`overwrite`))} your existing components?`,initialValue:!0});R(e)&&Z(),u=e}let d=await Ms({selectedItems:[c,...l],config:t,deps:r.deps,overwrite:u});if(r.deps)await Ks({cwd:e,prompt:r.deps,dependencies:Array.from(d.dependencies),devDependencies:Array.from(d.devDependencies),install:r.depsInstall});else if(d.skippedDeps.size){let e=ko([...d.skippedDeps],7);V.warn(`shadcn-svelte has been initialized ${H.default.bold(H.default.red(`without`))} the following ${X(`dependencies`)}:\n${H.default.gray(e)}`)}}const gl=o({all:a(),components:h().array().optional(),cwd:h(),proxy:h().optional(),yes:a(),skipPreflight:a(),deps:a(),depsInstall:a()}),_l=new Oe().command(`update`,{hidden:!0}).description(`update components in your project`).argument(`[components...]`,`name of components`).option(`-c, --cwd <path>`,`the working directory`,k.cwd()).option(`--skip-preflight`,`ignore preflight checks and continue`,!1).addOption(new ke(`--no-deps`,`skips adding & installing package dependencies`).hideHelp()).option(`--no-deps-install`,`add dependencies to package.json without running install`).option(`-a, --all`,`update all existing components`,!1).option(`-y, --yes`,`skip confirmation prompt`,!1).option(`--proxy <proxy>`,`fetch components from registry using a proxy`,Qo()).action(async(e,t)=>{Oo();try{let n=gl.parse({components:e,...t}),r=A.resolve(n.cwd);if(!M(r))throw O(`The path ${H.default.cyan(r)} does not exist. Please try again.`);let i=await Ho(r);if(!i)throw O(`Configuration file is missing. Please run ${H.default.green(`init`)} to create a ${X(`components.json`)} file.`);await vl(r,nc({config:i,cwd:r,skipPreflight:n.skipPreflight}),n),Zn(`${H.default.green(`Success!`)} Component update completed.`)}catch(e){Ao(e)}});async function vl(e,t,n){n.proxy!==void 0&&(k.env.HTTP_PROXY=n.proxy,V.info(`You are using the provided proxy: ${H.default.green(n.proxy)}`));let r=n.components,i=$o(t),a=await ts(i),o=await _o({registryIndex:a,config:t}),s=n.all?o:[];if(s.length===0&&r!==void 0&&(s=o.filter(e=>r.includes(e.name))),s.length===0){let e=await $n({message:`Which components would you like to update?`,maxItems:10,options:o.map(e=>({label:e.name,value:e,hint:e.registryDependencies?.length?`also updates: ${e.registryDependencies.join(`, `)}`:void 0}))});R(e)&&Z(),s=e}else{let e=ko(s.map(({name:e})=>e));V.step(`Components to update:\n${H.default.gray(e)}`)}if(n.yes===!1){let e=await qn({message:`Ready to update ${X(`components`)}? ${H.default.gray(`(Make sure you have committed your changes before proceeding!)`)}`,initialValue:!0});(R(e)||e===!1)&&Z()}let c=[],l=await is({baseUrl:i,items:await rs({registryUrl:i,registryIndex:a,items:s.map(e=>e.name)})});l.sort((e,t)=>e.name.localeCompare(t.name));let u=[];for(let e of l)e.cssVars&&u.push({cssVars:e.cssVars}),e.type===`registry:font`&&e.font&&u.push({fonts:[{font:e.font}]});let d=ds(u),f={},p=new Set,m=new Set,h=[],g={},_={};for(let e of l){let r=os(t,e.type);e.dependencies?.forEach(e=>p.add(e)),e.devDependencies?.forEach(e=>m.add(e)),e.type===`registry:font`&&h.push({name:e.name,...e.font}),c.push({title:`Updating ${X(e.name)}`,async task(){for(let n of e.files??[]){let r=ss(t,e,n),{content:i,dependencies:a,devDependencies:o,filePath:s}=await Se({content:n.content,filePath:r,config:t,supportedFontMarkers:d},[_e,pe,ve,be,!t.typescript&&ge]);a?.forEach(e=>p.add(e)),o?.forEach(e=>m.add(e));let c=A.parse(s).dir;M(c)||await N.mkdir(c,{recursive:!0}),await N.writeFile(s,i,`utf8`)}e.css&&(_=(0,cs.default)(_,e.css)),e.cssVars&&(g=(0,cs.default)(g,e.cssVars));let i=A.resolve(r,e.name);if(e.files&&e.files?.length>1){let n=e.files.map(n=>{let r=ss(t,e,n);return!t.typescript&&r.endsWith(`.ts`)?r.replace(`.ts`,`.js`):r}),r=(await N.readdir(i,{withFileTypes:!0})).map(e=>A.resolve(e.parentPath,e.name)).filter(e=>!n.includes(e));r.length>0&&(f[e.name]=r)}let a=A.relative(n.cwd,i);return`${X(e.name)} updated at ${H.default.gray(a)}`}})}let{css:v,cssVars:y,dependencies:b}=fs(h);if(_=(0,cs.default)(_,v),g=(0,cs.default)(g,y),b.forEach(e=>m.add(e)),(Object.keys(g).length>0||Object.keys(_).length>0)&&(_=(0,cs.default)(_,me),c.push({title:`Updating stylesheet`,async task(){let n=t.resolvedPaths.tailwindCss,r=As(await N.readFile(n,`utf8`),{css:_,cssVars:g});await N.writeFile(n,r,`utf8`);let i=A.relative(e,n);return`${X(`Stylesheet`)} updated at ${H.default.dim(i)}`}})),await sr(c),n.deps)await Ks({cwd:e,dependencies:Array.from(p),devDependencies:Array.from(m),prompt:!0,install:n.depsInstall});else if(p.size>0||m.size>0){let e=ko([...p,...m],7);V.warn(`Components have been updated ${H.default.bold(H.default.red(`without`))} the following ${X(`dependencies`)}:\n${H.default.gray(e)}`)}for(let[t,n]of Object.entries(f))V.warn(`The ${X(t)} component does not use the following files:\n${n.map(t=>H.default.white(`- ${H.default.gray(A.relative(e,t))}`)).join(`
|
|
136
|
-
`)}`);Object.keys(f).length>0&&V.message(H.default.bold(`You may want to delete them.`))}const yl=ye.extend(xe());function bl(e){let t=wo(e),n=xl({dependencies:wl(t.dependencies,e),devDependencies:wl(t.devDependencies,e)});return n=Sl(n),n}function xl(e){for(let t of Object.values(e))for(let[n,r]of Object.entries(t.versions)){let i=t.deps[r],a=`@types/${n.replace(/^@(.*)\/(.*)/,`$1__$2`)}`;(e.dependencies.versions[a]??e.devDependencies.versions[a])&&i.push(a)}return e}function Sl(e){for(let t of Object.values(e))for(let[n,r]of Object.entries(t.deps))t.deps[n]=r.map(t=>e.dependencies.versions[t]||e.devDependencies.versions[t]).filter(e=>e!==void 0);return e}const Cl=[`svelte`,`@sveltejs/kit`,`tailwindcss`,`vite`,`sv`,`shadcn-svelte`];function wl(e,t){let n={},r={};for(let[i,a]of Object.entries(e??{})){let e=El(i,a,t),o=n[e]??=[];r[i]=e;let s=go(t,i)?.pkg;if(!s)continue;let{peerDependencies:c={},peerDependenciesMeta:l={}}=s;for(let[e]of Object.entries(c))Cl.includes(e)||l[e]?.optional||o.push(e)}return{deps:n,versions:r}}const Tl=new Set([`*`,`^`,`~`]);function El(e,t,n){if(!t)return e;if(t.startsWith(`workspace:`)){let r=t.slice(10);if(!Tl.has(r))return`${e}@${r}`;let i=go(n,e)?.pkg.version;return i?`${e}@${r===`*`?``:r}${i}`:e}return`${e}@${t}`}async function Dl(e){let{filename:t,source:n}=e,r,i;if(t.endsWith(`.svelte`)){let{code:e}=await ct.preprocess(n,[],{filename:t}),a=ct.parse(e,{filename:t});r=a.instance,a.module&&(i=a.module)}else if(t.endsWith(`.ts`)||t.endsWith(`.js`))r=yl.parse(n,{ecmaVersion:`latest`,sourceType:`module`,sourceFile:t});else return{};let a=new Set,o=new Set,s=t=>{if(t.type!==`ImportDeclaration`&&t.type!==`ExportNamedDeclaration`&&t.type!==`ExportAllDeclaration`||!t.source)return;let n=t.source.value;Ol(n,e.dependencies).forEach(e=>a.add(e)),Ol(n,e.devDependencies).forEach(e=>o.add(e))};return he(r,{enter:s}),i&&he(i,{enter:s}),{dependencies:f(a),devDependencies:f(o)}}function Ol(e,t){let n=[],r=(t.versions[e]?e:void 0)??Object.keys(t.versions).find(t=>e===t||e.startsWith(`${t}/`));if(r&&!Cl.includes(r)){let e=t.versions[r],i=t.deps[e];n.push(e),i?.forEach(e=>n.push(e))}return n}const kl=o({registry:h(),cwd:h(),output:h()}),Al=new Oe().command(`build`).description(`build components for a shadcn-svelte registry`).argument(`[registry]`,`path to registry.json file`,`./registry.json`).option(`-c, --cwd <path>`,`the working directory`,k.cwd()).option(`-o, --output <path>`,`destination directory for json files`,`./static/r`).action(async(e,t)=>{try{Oo();let n=kl.parse({registry:e,...t}),r=A.resolve(n.cwd),i=A.resolve(n.cwd,n.output),a=A.resolve(n.cwd,n.registry);for(let[e,t]of Object.entries({cwd:r,registry:a}))if(!M(t))throw O(`The '${e}' path ${H.default.cyan(t)} does not exist.`);await jl({cwd:r,output:i,registry:a}),Zn(`${H.default.green(`Success!`)} Registry build completed.`)}catch(e){Ao(e)}});async function jl(e){let t=ir();t.start(`Parsing registry schema`);let n=await N.readFile(e.registry,`utf8`),r=ue.parse(JSON.parse(n));t.stop(`Parsed registry schema at ${H.default.dim(A.relative(e.cwd,e.registry))}`);let i=r.items.map(e=>({...e,relativeUrl:`${e.name}.json`}));M(e.output)||await N.mkdir(e.output,{recursive:!0});let a=[];a.push({title:`Building registry index`,async task(){let t=A.resolve(e.output,`index.json`),n=ie.parse(i);await N.writeFile(t,JSON.stringify(n,null,` `),`utf8`);let r=A.relative(e.cwd,t);return`Registry index written to ${H.default.dim(r)}`}}),a.push({title:`Building registry items`,async task(t){let n=bl(e.cwd);if(r.overrideDependencies){let e=(e,t)=>{let{name:n}=tc(e),r=t.versions[n];if(r){let i=t.deps[r];delete t.deps[r],t.versions[n]=e,t.deps[e]=i??[]}};for(let t of r.overrideDependencies)e(t,n.dependencies),e(t,n.devDependencies)}for(let i of r.items){t(`Building item ${H.default.cyan(i.name)}`);let a=i.files.length===1,o=[`registry:page`,`registry:ui`,`registry:file`],s=i.files.map(async e=>{let t=await N.readFile(e.path,`utf8`);t=Nl(r.aliases??={},t);let n=A.basename(e.path),s;return s=a?n:o.includes(e.type)?`${i.name}/${n}`:n,{content:t,name:n,target:s,...e}}),c=await Promise.all(s),l=new Set(i.dependencies),u=new Set(i.devDependencies),d=new Set(i.registryDependencies.map(Ml));if(!(l.size>0&&u.size>0))for(let e of c){let t=await Dl({...n,filename:e.name,source:e.content});i.dependencies||t.dependencies?.forEach(e=>{e.startsWith(`@types/`)?u.add(e):l.add(e)}),i.devDependencies||t.devDependencies?.forEach(e=>u.add(e))}let p=se.parse({...i,$schema:`${_}/schema/registry-item.json`,registryDependencies:f(d),dependencies:f(l),devDependencies:f(u),files:c},{jitless:!0}),m=A.resolve(e.output,`${i.name}.json`);await N.writeFile(m,JSON.stringify(p,null,` `),`utf8`)}let i=A.relative(e.cwd,e.output);return`Registry items written to ${H.default.dim(i)}`}}),await sr(a)}function Ml(e){return e.startsWith(`local:`)?e.replace(/^local:(.*)/,`./$1.json`):e}function Nl(e,t){for(let n of b){let r=v[n],i=e[n]??=r.defaultPath;t=t.replaceAll(i,r.placeholder)}return t}const Pl=new Oe().command(`registry`).addCommand(Al);var Fl=e({add:()=>ac,apply:()=>dc,init:()=>fl,registry:()=>Pl,update:()=>_l});k.on(`SIGINT`,()=>k.exit(0)),k.on(`SIGTERM`,()=>k.exit(0));const Il=k.versions.node;Number.parseInt(Il.split(`.`).at(0))<20&&(console.error(`Node.js v${Il} is out of date and unsupported!`),console.error(`Please use Node.js v20 or higher.`),k.exit(1));async function Ll(){let e=po(),t=new Oe().name(`shadcn-svelte`).description(`Add shadcn-svelte components to your project`).version(e.version||`0.0.0`,`-v, --version`,`display the version number`);for(let e of Object.values(Fl))t.addCommand(e);t.parse()}Ll();export{};
|
|
135
|
+
`)}:{ok:!0}}const ll=[`font`,`theme`],ul=o({cwd:h(),preset:h().optional(),only:i(c(ll)).optional(),yes:a(),silent:a(),skipPreflight:a(),proxy:h().optional(),depsInstall:a()}),dl=new Oe().command(`apply`).description(`apply a preset to an existing project`).argument(`[preset]`,`the preset to apply`).option(`--preset <preset>`,`the preset to use`).addOption(new ke(`--only <parts...>`,`apply only parts of a preset: theme, font`).choices(ll)).option(`-c, --cwd <path>`,`the working directory`,k.cwd()).option(`-y, --yes`,`skip confirmation prompt`,!1).option(`-s, --silent`,`mute output`,!1).option(`--no-deps-install`,`add dependencies to package.json without running install`).option(`--skip-preflight`,`ignore preflight checks and continue`,!1).option(`--proxy <proxy>`,`fetch items from registry using a proxy`,Qo()).action(async(e,t)=>{t.silent||Oo();let n=ul.parse(t),r=A.resolve(n.cwd);try{if(!M(r))throw O(`The path ${H.default.cyan(r)} does not exist. Please try again.`);let t=n.preset||e;if(t===void 0)throw O(`${H.default.bold(`--preset`)} is required.`);let i=el(t);if(i===null)throw O(tl(t));sl(r,{skipPreflight:n.skipPreflight});let a=await Ho(r);if(!a)throw new fe(`Configuration file is missing. Please run ${H.default.green(`init`)} to create a ${X(`components.json`)} file.`);await fl({cwd:r,config:a,decidedPresets:i,options:n}),n.silent||Zn(`Preset ${H.default.bold(t)} applied successfully.`)}catch(e){Ao(e)}});async function fl({cwd:e,config:t,decidedPresets:n,options:r}){r.proxy!==void 0&&(k.env.HTTP_PROXY=r.proxy,V.info(`You are using the provided proxy: ${H.default.green(r.proxy)}`));let i=r.only&&r.only.length>0?r.only:void 0,a=i===void 0||i.includes(`theme`),o=i?.includes(`theme`);if(a){t.iconLibrary=n.iconLibrary,t.menuColor=n.menuColor,t.menuAccent=n.menuAccent,t.style=n.style,t.tailwind.baseColor=n.baseColor;let i=ir();r.silent||i.start(`Applying preset ${H.default.bold(r.preset)} to config file`),Xo(e,t),r.silent||i.stop(`Applied preset ${H.default.bold(r.preset)} to config file`)}let s=$o(t),c=w(n),l=await Ms({selectedItems:[new URL(`/init?preset=${c}`,s).toString()],config:t,deps:!0,overwrite:r.yes,silent:r.silent,only:i,skipExisting:!0,forceStylesheet:!0});o||await Ks({cwd:e,prompt:!1,dependencies:Array.from(l.dependencies),devDependencies:Array.from(l.devDependencies),silent:r.silent,install:r.depsInstall})}const pl=ns(),ml=o({cwd:h(),baseColor:h().optional(),preset:h().optional(),css:h().optional(),componentsAlias:h().optional(),utilsAlias:h().optional(),libAlias:h().optional(),hooksAlias:h().optional(),uiAlias:h().optional(),deps:a(),depsInstall:a(),overwrite:a(),proxy:h().optional(),skipPreflight:a(),reinstall:a().optional()}),hl=new Oe().command(`init`).description(`initialize your project and install dependencies`).option(`--preset <preset>`,`the preset to use`).option(`-c, --cwd <path>`,`the working directory`,k.cwd()).addOption(new ke(`-o, --overwrite`,`deprecated: use --reinstall`).default(!1).hideHelp()).addOption(new ke(`--no-deps`,`disable adding & installing dependencies`).hideHelp()).option(`--no-deps-install`,`add dependencies to package.json without running install`).option(`--skip-preflight`,`ignore preflight checks and continue`,!1).option(`--reinstall`,`reinstall existing components when style changes`).option(`--no-reinstall`,`skip reinstalling existing components when style changes`).addOption(new ke(`--base-color <name>`,`the base color for the components`).choices(pl.map(e=>e.name))).option(`--css <path>`,`path to the global CSS file`).option(`--components-alias <path>`,`import alias for components`).option(`--lib-alias <path>`,`import alias for lib`).option(`--utils-alias <path>`,`import alias for utils`).option(`--hooks-alias <path>`,`import alias for hooks`).option(`--ui-alias <path>`,`import alias for ui`).option(`--proxy <proxy>`,`fetch items from registry using a proxy`,Qo()).action(async e=>{Oo();let t=ml.parse(e),n=A.resolve(t.cwd);try{if(!M(n))throw O(`The path ${H.default.cyan(n)} does not exist. Please try again.`);let e=null;if(t.preset!==void 0&&(e=el(t.preset),e===null))throw O(tl(t.preset));sl(n,{skipPreflight:t.skipPreflight});let r=Wo(n);r&&=nc({cwd:n,config:r,skipPreflight:t.skipPreflight});let{resolvedConfig:i,decidedPresets:a,styleChanged:o}=await _l({cwd:n,presetConfig:e,existingConfig:r,options:t});await vl({cwd:n,config:i,decidedPresets:a,options:t,styleChanged:o}),Zn(`${H.default.green(`Success!`)} Project initialization completed.`)}catch(e){Ao(e)}}).on(`option:overwrite`,()=>{console.warn(H.default.yellow(`Warning: ${H.default.bold(`--overwrite`)} is deprecated. Use ${H.default.bold(`--reinstall`)} instead.\n`))});function gl(e,t,n){if(t.css&&!M(A.resolve(e,t.css)))throw O(`The provided global CSS file path ${H.default.cyan(t.css)} does not exist. Please enter a valid path.`);for(let[r,i]of Object.entries(t)){if(!r.endsWith(`Alias`))continue;let t=qo({cwd:e,importPath:i,tsconfig:n});if(t)throw O(t)}}async function _l({cwd:e,presetConfig:t,existingConfig:n,options:r}){let i=n??structuredClone(D);await vo(e);let{cssPath:a,tsconfigPath:o,packageImportAlias:s}=zs(e,{relative:!0}),c;if(n)c=Zo(e,n);else{if(o)i.typescript=o.includes(`tsconfig`);else{let t=await ur({message:`Where is your ${X(`tsconfig/jsconfig`)} file?`,placeholder:`tsconfig.json`,validate:t=>{let n=A.resolve(e,t??``);if(!(t&&M(n)))return`"${H.default.bold(t)}" does not exist. Please enter a valid path.`}});R(t)&&Z(),i.typescript={config:t}}c=Zo(e,i)}gl(e,r,c);let l=t??await nl(n),u=r.css;if(u===void 0){let t=D.tailwind.css,r=await ur({message:`Where is your ${X(`global CSS`)} file? ${H.default.gray(`(this file will be overwritten)`)}`,initialValue:n?.tailwind.css??a??t,placeholder:a??t,validate:t=>{if(!(t&&M(A.resolve(e,t))))return`"${H.default.bold(t)}" does not exist. Please enter a valid path.`}});R(r)&&Z(),u=r}let{utilsAlias:d,libAlias:f,componentAlias:p,hooksAlias:m,uiAlias:h}=await Jo({...r,libAliasDefault:s,tsconfig:c,cwd:e,existingConfig:n}),g=Go({...i,tailwind:{css:u,baseColor:l.baseColor},aliases:{utils:d,lib:f,components:p,hooks:m,ui:h},style:l.style,iconLibrary:l.iconLibrary,menuColor:l.menuColor,menuAccent:l.menuAccent}),_;return _=n?n.style!==l.style||n.menuColor!==l.menuColor||n.menuAccent!==l.menuAccent:!1,{resolvedConfig:await Uo(e,g),decidedPresets:l,styleChanged:_}}async function vl({cwd:e,config:t,decidedPresets:n,options:r,styleChanged:i}){r.proxy!==void 0&&(k.env.HTTP_PROXY=r.proxy,V.info(`You are using the provided proxy: ${H.default.green(r.proxy)}`));let a=[];a.push({title:`Creating config file`,async task(){return Xo(e,t),`Config file ${X(`components.json`)} created`}}),a.push({title:`Validating alias paths`,async task(){for(let[e,n]of Object.entries(t.resolvedPaths)){let t=A.extname(n)?A.dirname(n):n;e===`utils`&&n.endsWith(`/utils`)&&(t=t.replace(/\/utils$/,``)),!M(t)&&e!==`utils`&&await N.mkdir(t,{recursive:!0})}return`Alias paths validated`}}),await sr(a);let o=$o(t),s=w(n),c=new URL(`/init?preset=${s}`,o).toString(),l=[],u=r.overwrite||r.reinstall===!0;if(i&&r.reinstall!==!1&&(l=(await _o({registryIndex:await ts(o),config:t})).filter(e=>e.name!==`utils`).map(e=>e.name),l.length>0&&!u)){V.warn(`The registry style has changed to ${H.default.bold(H.default.yellow(n.style))}.`);let e=await qn({message:`Would you like to ${H.default.bold(H.default.red(`overwrite`))} your existing components?`,initialValue:!0});R(e)&&Z(),u=e}let d=await Ms({selectedItems:[c,...l],config:t,deps:r.deps,overwrite:u});if(r.deps)await Ks({cwd:e,prompt:r.deps,dependencies:Array.from(d.dependencies),devDependencies:Array.from(d.devDependencies),install:r.depsInstall});else if(d.skippedDeps.size){let e=ko([...d.skippedDeps],7);V.warn(`shadcn-svelte has been initialized ${H.default.bold(H.default.red(`without`))} the following ${X(`dependencies`)}:\n${H.default.gray(e)}`)}}const yl=o({all:a(),components:h().array().optional(),cwd:h(),proxy:h().optional(),yes:a(),skipPreflight:a(),deps:a(),depsInstall:a()}),bl=new Oe().command(`update`,{hidden:!0}).description(`update components in your project`).argument(`[components...]`,`name of components`).option(`-c, --cwd <path>`,`the working directory`,k.cwd()).option(`--skip-preflight`,`ignore preflight checks and continue`,!1).addOption(new ke(`--no-deps`,`skips adding & installing package dependencies`).hideHelp()).option(`--no-deps-install`,`add dependencies to package.json without running install`).option(`-a, --all`,`update all existing components`,!1).option(`-y, --yes`,`skip confirmation prompt`,!1).option(`--proxy <proxy>`,`fetch components from registry using a proxy`,Qo()).action(async(e,t)=>{Oo();try{let n=yl.parse({components:e,...t}),r=A.resolve(n.cwd);if(!M(r))throw O(`The path ${H.default.cyan(r)} does not exist. Please try again.`);let i=await Ho(r);if(!i)throw O(`Configuration file is missing. Please run ${H.default.green(`init`)} to create a ${X(`components.json`)} file.`);await xl(r,nc({config:i,cwd:r,skipPreflight:n.skipPreflight}),n),Zn(`${H.default.green(`Success!`)} Component update completed.`)}catch(e){Ao(e)}});async function xl(e,t,n){n.proxy!==void 0&&(k.env.HTTP_PROXY=n.proxy,V.info(`You are using the provided proxy: ${H.default.green(n.proxy)}`));let r=n.components,i=$o(t),a=await ts(i),o=await _o({registryIndex:a,config:t}),s=n.all?o:[];if(s.length===0&&r!==void 0&&(s=o.filter(e=>r.includes(e.name))),s.length===0){let e=await $n({message:`Which components would you like to update?`,maxItems:10,options:o.map(e=>({label:e.name,value:e,hint:e.registryDependencies?.length?`also updates: ${e.registryDependencies.join(`, `)}`:void 0}))});R(e)&&Z(),s=e}else{let e=ko(s.map(({name:e})=>e));V.step(`Components to update:\n${H.default.gray(e)}`)}if(n.yes===!1){let e=await qn({message:`Ready to update ${X(`components`)}? ${H.default.gray(`(Make sure you have committed your changes before proceeding!)`)}`,initialValue:!0});(R(e)||e===!1)&&Z()}let c=[],l=await is({baseUrl:i,items:await rs({registryUrl:i,registryIndex:a,items:s.map(e=>e.name)})});l.sort((e,t)=>e.name.localeCompare(t.name));let u=[];for(let e of l)e.cssVars&&u.push({cssVars:e.cssVars}),e.type===`registry:font`&&e.font&&u.push({fonts:[{font:e.font}]});let d=ds(u),f={},p=new Set,m=new Set,h=[],g={},_={};for(let e of l){let r=os(t,e.type);e.dependencies?.forEach(e=>p.add(e)),e.devDependencies?.forEach(e=>m.add(e)),e.type===`registry:font`&&h.push({name:e.name,...e.font}),c.push({title:`Updating ${X(e.name)}`,async task(){for(let n of e.files??[]){let r=ss(t,e,n),{content:i,dependencies:a,devDependencies:o,filePath:s}=await Se({content:n.content,filePath:r,config:t,supportedFontMarkers:d},[_e,pe,ve,be,!t.typescript&&ge]);a?.forEach(e=>p.add(e)),o?.forEach(e=>m.add(e));let c=A.parse(s).dir;M(c)||await N.mkdir(c,{recursive:!0}),await N.writeFile(s,i,`utf8`)}e.css&&(_=(0,cs.default)(_,e.css)),e.cssVars&&(g=(0,cs.default)(g,e.cssVars));let i=A.resolve(r,e.name);if(e.files&&e.files?.length>1){let n=e.files.map(n=>{let r=ss(t,e,n);return!t.typescript&&r.endsWith(`.ts`)?r.replace(`.ts`,`.js`):r}),r=(await N.readdir(i,{withFileTypes:!0})).map(e=>A.resolve(e.parentPath,e.name)).filter(e=>!n.includes(e));r.length>0&&(f[e.name]=r)}let a=A.relative(n.cwd,i);return`${X(e.name)} updated at ${H.default.gray(a)}`}})}let{css:v,cssVars:y,dependencies:b}=fs(h);if(_=(0,cs.default)(_,v),g=(0,cs.default)(g,y),b.forEach(e=>m.add(e)),(Object.keys(g).length>0||Object.keys(_).length>0)&&(_=(0,cs.default)(_,me),c.push({title:`Updating stylesheet`,async task(){let n=t.resolvedPaths.tailwindCss,r=As(await N.readFile(n,`utf8`),{css:_,cssVars:g});await N.writeFile(n,r,`utf8`);let i=A.relative(e,n);return`${X(`Stylesheet`)} updated at ${H.default.dim(i)}`}})),await sr(c),n.deps)await Ks({cwd:e,dependencies:Array.from(p),devDependencies:Array.from(m),prompt:!0,install:n.depsInstall});else if(p.size>0||m.size>0){let e=ko([...p,...m],7);V.warn(`Components have been updated ${H.default.bold(H.default.red(`without`))} the following ${X(`dependencies`)}:\n${H.default.gray(e)}`)}for(let[t,n]of Object.entries(f))V.warn(`The ${X(t)} component does not use the following files:\n${n.map(t=>H.default.white(`- ${H.default.gray(A.relative(e,t))}`)).join(`
|
|
136
|
+
`)}`);Object.keys(f).length>0&&V.message(H.default.bold(`You may want to delete them.`))}const Sl=ye.extend(xe());function Cl(e){let t=wo(e),n=wl({dependencies:Dl(t.dependencies,e),devDependencies:Dl(t.devDependencies,e)});return n=Tl(n),n}function wl(e){for(let t of Object.values(e))for(let[n,r]of Object.entries(t.versions)){let i=t.deps[r],a=`@types/${n.replace(/^@(.*)\/(.*)/,`$1__$2`)}`;(e.dependencies.versions[a]??e.devDependencies.versions[a])&&i.push(a)}return e}function Tl(e){for(let t of Object.values(e))for(let[n,r]of Object.entries(t.deps))t.deps[n]=r.map(t=>e.dependencies.versions[t]||e.devDependencies.versions[t]).filter(e=>e!==void 0);return e}const El=[`svelte`,`@sveltejs/kit`,`tailwindcss`,`vite`,`sv`,`shadcn-svelte`];function Dl(e,t){let n={},r={};for(let[i,a]of Object.entries(e??{})){let e=kl(i,a,t),o=n[e]??=[];r[i]=e;let s=go(t,i)?.pkg;if(!s)continue;let{peerDependencies:c={},peerDependenciesMeta:l={}}=s;for(let[e]of Object.entries(c))El.includes(e)||l[e]?.optional||o.push(e)}return{deps:n,versions:r}}const Ol=new Set([`*`,`^`,`~`]);function kl(e,t,n){if(!t)return e;if(t.startsWith(`workspace:`)){let r=t.slice(10);if(!Ol.has(r))return`${e}@${r}`;let i=go(n,e)?.pkg.version;return i?`${e}@${r===`*`?``:r}${i}`:e}return`${e}@${t}`}async function Al(e){let{filename:t,source:n}=e,r,i;if(t.endsWith(`.svelte`)){let{code:e}=await ct.preprocess(n,[],{filename:t}),a=ct.parse(e,{filename:t});r=a.instance,a.module&&(i=a.module)}else if(t.endsWith(`.ts`)||t.endsWith(`.js`))r=Sl.parse(n,{ecmaVersion:`latest`,sourceType:`module`,sourceFile:t});else return{};let a=new Set,o=new Set,s=t=>{if(t.type!==`ImportDeclaration`&&t.type!==`ExportNamedDeclaration`&&t.type!==`ExportAllDeclaration`||!t.source)return;let n=t.source.value;jl(n,e.dependencies).forEach(e=>a.add(e)),jl(n,e.devDependencies).forEach(e=>o.add(e))};return he(r,{enter:s}),i&&he(i,{enter:s}),{dependencies:f(a),devDependencies:f(o)}}function jl(e,t){let n=[],r=(t.versions[e]?e:void 0)??Object.keys(t.versions).find(t=>e===t||e.startsWith(`${t}/`));if(r&&!El.includes(r)){let e=t.versions[r],i=t.deps[e];n.push(e),i?.forEach(e=>n.push(e))}return n}const Ml=o({registry:h(),cwd:h(),output:h()}),Nl=new Oe().command(`build`).description(`build components for a shadcn-svelte registry`).argument(`[registry]`,`path to registry.json file`,`./registry.json`).option(`-c, --cwd <path>`,`the working directory`,k.cwd()).option(`-o, --output <path>`,`destination directory for json files`,`./static/r`).action(async(e,t)=>{try{Oo();let n=Ml.parse({registry:e,...t}),r=A.resolve(n.cwd),i=A.resolve(n.cwd,n.output),a=A.resolve(n.cwd,n.registry);for(let[e,t]of Object.entries({cwd:r,registry:a}))if(!M(t))throw O(`The '${e}' path ${H.default.cyan(t)} does not exist.`);await Pl({cwd:r,output:i,registry:a}),Zn(`${H.default.green(`Success!`)} Registry build completed.`)}catch(e){Ao(e)}});async function Pl(e){let t=ir();t.start(`Parsing registry schema`);let n=await N.readFile(e.registry,`utf8`),r=ue.parse(JSON.parse(n));t.stop(`Parsed registry schema at ${H.default.dim(A.relative(e.cwd,e.registry))}`);let i=r.items.map(e=>({...e,relativeUrl:`${e.name}.json`}));M(e.output)||await N.mkdir(e.output,{recursive:!0});let a=[];a.push({title:`Building registry index`,async task(){let t=A.resolve(e.output,`index.json`),n=ie.parse(i);await N.writeFile(t,JSON.stringify(n,null,` `),`utf8`);let r=A.relative(e.cwd,t);return`Registry index written to ${H.default.dim(r)}`}}),a.push({title:`Building registry items`,async task(t){let n=Cl(e.cwd);if(r.overrideDependencies){let e=(e,t)=>{let{name:n}=tc(e),r=t.versions[n];if(r){let i=t.deps[r];delete t.deps[r],t.versions[n]=e,t.deps[e]=i??[]}};for(let t of r.overrideDependencies)e(t,n.dependencies),e(t,n.devDependencies)}for(let i of r.items){t(`Building item ${H.default.cyan(i.name)}`);let a=i.files.length===1,o=[`registry:page`,`registry:ui`,`registry:file`],s=i.files.map(async e=>{let t=await N.readFile(e.path,`utf8`);t=Il(r.aliases??={},t);let n=A.basename(e.path),s;return s=a?n:o.includes(e.type)?`${i.name}/${n}`:n,{content:t,name:n,target:s,...e}}),c=await Promise.all(s),l=new Set(i.dependencies),u=new Set(i.devDependencies),d=new Set(i.registryDependencies.map(Fl));if(!(l.size>0&&u.size>0))for(let e of c){let t=await Al({...n,filename:e.name,source:e.content});i.dependencies||t.dependencies?.forEach(e=>{e.startsWith(`@types/`)?u.add(e):l.add(e)}),i.devDependencies||t.devDependencies?.forEach(e=>u.add(e))}let p=se.parse({...i,$schema:`${_}/schema/registry-item.json`,registryDependencies:f(d),dependencies:f(l),devDependencies:f(u),files:c},{jitless:!0}),m=A.resolve(e.output,`${i.name}.json`);await N.writeFile(m,JSON.stringify(p,null,` `),`utf8`)}let i=A.relative(e.cwd,e.output);return`Registry items written to ${H.default.dim(i)}`}}),await sr(a)}function Fl(e){return e.startsWith(`local:`)?e.replace(/^local:(.*)/,`./$1.json`):e}function Il(e,t){for(let n of b){let r=v[n],i=e[n]??=r.defaultPath;t=t.replaceAll(i,r.placeholder)}return t}const Ll=new Oe().command(`registry`).addCommand(Nl);var Rl=e({add:()=>ac,apply:()=>dl,init:()=>hl,registry:()=>Ll,update:()=>bl});k.on(`SIGINT`,()=>k.exit(0)),k.on(`SIGTERM`,()=>k.exit(0));const zl=k.versions.node;Number.parseInt(zl.split(`.`).at(0))<20&&(console.error(`Node.js v${zl} is out of date and unsupported!`),console.error(`Please use Node.js v20 or higher.`),k.exit(1));async function Bl(){let e=po(),t=new Oe().name(`shadcn-svelte`).description(`Add shadcn-svelte components to your project`).version(e.version||`0.0.0`,`-v, --version`,`display the version number`);for(let e of Object.values(Rl))t.addCommand(e);t.parse()}Bl();export{};
|