shadcn 4.0.2 → 4.0.3
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/chunk-BFLSSWBX.js +1 -0
- package/dist/{chunk-GCGM5V6Q.js → chunk-IBHWVXMI.js} +4 -4
- package/dist/chunk-ISTYEIAA.js +1 -0
- package/dist/chunk-JPE2JKEP.js +2 -0
- package/dist/{chunk-G3IK4LWV.js → chunk-TVMYBJXJ.js} +2 -2
- package/dist/index.d.ts +7 -7
- package/dist/index.js +75 -75
- package/dist/mcp/index.js +1 -1
- package/dist/preset/index.d.ts +1 -1
- package/dist/preset/index.js +1 -1
- package/dist/registry/index.js +1 -1
- package/dist/schema/index.d.ts +34 -34
- package/dist/schema/index.js +1 -1
- package/dist/utils/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-FFSLICO3.js +0 -1
- package/dist/chunk-IMJ4D25X.js +0 -2
- package/dist/chunk-K3VKXMEA.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import {z as z$1}from'zod';var c=z$1.union([z$1.string().refine(e=>e.includes("{name}"),{message:"Registry URL must include {name} placeholder"}),z$1.object({url:z$1.string().refine(e=>e.includes("{name}"),{message:"Registry URL must include {name} placeholder"}),params:z$1.record(z$1.string(),z$1.string()).optional(),headers:z$1.record(z$1.string(),z$1.string()).optional()})]),l=z$1.record(z$1.string().refine(e=>e.startsWith("@"),{message:"Registry names must start with @ (e.g., @v0, @acme)"}),c),i=z$1.object({$schema:z$1.string().optional(),style:z$1.string(),rsc:z$1.coerce.boolean().default(false),tsx:z$1.coerce.boolean().default(true),tailwind:z$1.object({config:z$1.string().optional(),css:z$1.string(),baseColor:z$1.string(),cssVariables:z$1.boolean().default(true),prefix:z$1.string().default("").optional()}),iconLibrary:z$1.string().optional(),rtl:z$1.coerce.boolean().default(false).optional(),menuColor:z$1.enum(["default","inverted","default-translucent","inverted-translucent"]).default("default").optional(),menuAccent:z$1.enum(["subtle","bold"]).default("subtle").optional(),aliases:z$1.object({components:z$1.string(),utils:z$1.string(),ui:z$1.string().optional(),lib:z$1.string().optional(),hooks:z$1.string().optional()}),registries:l.optional()}).strict(),p=i.extend({resolvedPaths:z$1.object({cwd:z$1.string(),tailwindConfig:z$1.string(),tailwindCss:z$1.string(),utils:z$1.string(),components:z$1.string(),lib:z$1.string(),hooks:z$1.string(),ui:z$1.string()})}),x=z$1.record(p),s=z$1.enum(["registry:lib","registry:block","registry:component","registry:ui","registry:hook","registry:page","registry:file","registry:theme","registry:style","registry:item","registry:base","registry:font","registry:example","registry:internal"]),m=z$1.discriminatedUnion("type",[z$1.object({path:z$1.string(),content:z$1.string().optional(),type:z$1.enum(["registry:file","registry:page"]),target:z$1.string()}),z$1.object({path:z$1.string(),content:z$1.string().optional(),type:s.exclude(["registry:file","registry:page"]),target:z$1.string().optional()})]),y=z$1.object({config:z$1.object({content:z$1.array(z$1.string()).optional(),theme:z$1.record(z$1.string(),z$1.any()).optional(),plugins:z$1.array(z$1.string()).optional()}).optional()}),n=z$1.object({theme:z$1.record(z$1.string(),z$1.string()).optional(),light:z$1.record(z$1.string(),z$1.string()).optional(),dark:z$1.record(z$1.string(),z$1.string()).optional()}),o=z$1.lazy(()=>z$1.union([z$1.string(),z$1.array(z$1.union([z$1.string(),z$1.record(z$1.string(),z$1.string())])),z$1.record(z$1.string(),o)])),d=z$1.record(z$1.string(),o),u=z$1.record(z$1.string(),z$1.string()),a=z$1.object({family:z$1.string(),provider:z$1.literal("google"),import:z$1.string(),variable:z$1.string(),weight:z$1.array(z$1.string()).optional(),subsets:z$1.array(z$1.string()).optional(),selector:z$1.string().optional()}),r=z$1.object({$schema:z$1.string().optional(),extends:z$1.string().optional(),name:z$1.string(),title:z$1.string().optional(),author:z$1.string().min(2).optional(),description:z$1.string().optional(),dependencies:z$1.array(z$1.string()).optional(),devDependencies:z$1.array(z$1.string()).optional(),registryDependencies:z$1.array(z$1.string()).optional(),files:z$1.array(m).optional(),tailwind:y.optional(),cssVars:n.optional(),css:d.optional(),envVars:u.optional(),meta:z$1.record(z$1.string(),z$1.any()).optional(),docs:z$1.string().optional(),categories:z$1.array(z$1.string()).optional()}),g=z$1.discriminatedUnion("type",[r.extend({type:z$1.literal("registry:base"),config:i.deepPartial().optional()}),r.extend({type:z$1.literal("registry:font"),font:a}),r.extend({type:s.exclude(["registry:base","registry:font"])})]),S=z$1.object({name:z$1.string(),homepage:z$1.string(),items:z$1.array(g)}),j=z$1.array(g),I=z$1.array(z$1.object({name:z$1.string(),label:z$1.string()})),C=z$1.record(z$1.string(),z$1.record(z$1.string(),z$1.string())),v=z$1.object({inlineColors:z$1.object({light:z$1.record(z$1.string(),z$1.string()),dark:z$1.record(z$1.string(),z$1.string())}),cssVars:n,cssVarsV4:n.optional(),inlineColorsTemplate:z$1.string(),cssVarsTemplate:z$1.string()}),R=r.pick({dependencies:true,devDependencies:true,files:true,tailwind:true,cssVars:true,css:true,envVars:true,docs:true}).extend({fonts:z$1.array(r.extend({type:z$1.literal("registry:font"),font:a})).optional()}),f=z$1.object({name:z$1.string(),type:z$1.string().optional(),description:z$1.string().optional(),registry:z$1.string(),addCommandArgument:z$1.string()}),V=z$1.object({pagination:z$1.object({total:z$1.number(),offset:z$1.number(),limit:z$1.number(),hasMore:z$1.boolean()}),items:z$1.array(f)}),w=z$1.record(z$1.string().regex(/^@[a-zA-Z0-9][a-zA-Z0-9-_]*$/),z$1.string()),z=z$1.array(z$1.object({name:z$1.string(),homepage:z$1.string().optional(),url:z$1.string(),description:z$1.string().optional()})),h=z$1.object({name:z$1.string(),title:z$1.string(),description:z$1.string(),base:z$1.string(),style:z$1.string(),baseColor:z$1.string(),theme:z$1.string(),iconLibrary:z$1.string(),font:z$1.string(),rtl:z$1.coerce.boolean().default(false),menuAccent:z$1.enum(["subtle","bold"]),menuColor:z$1.enum(["default","inverted","default-translucent","inverted-translucent"]),radius:z$1.string()}),k=z$1.object({presets:z$1.array(h)});export{c as a,l as b,i as c,p as d,x as e,s as f,m as g,y as h,n as i,d as j,u as k,a as l,r as m,g as n,S as o,j as p,I as q,C as r,v as s,R as t,f as u,V as v,w,z as x,h as y,k as z};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {va,ba,f,da}from'./chunk-TVMYBJXJ.js';import {Server}from'@modelcontextprotocol/sdk/server/index.js';import {ListToolsRequestSchema,CallToolRequestSchema}from'@modelcontextprotocol/sdk/types.js';import a from'dedent';import {z}from'zod';import {zodToJsonSchema}from'zod-to-json-schema';import {detect}from'@antfu/ni';async function k(n,{withFallback:e}={withFallback:false}){let r=await detect({programmatic:true,cwd:n});if(r==="yarn@berry")return "yarn";if(r==="pnpm@6")return "pnpm";if(r==="bun")return "bun";if(r==="deno")return "deno";if(!e)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 b(n){let e=await k(n);return e==="pnpm"?"pnpm dlx":e==="bun"?"bunx":"npx"}var C="shadcn@latest";async function g(n){return `${await b(process.cwd())} ${C} ${n}`}async function u(n=process.cwd()){return {registries:(await da(n,{useCache:false})).registries}}function y(n,e){let{query:r,registries:i}=e||{},s=n.items.map(c=>{let f=[`- ${c.name}`];return c.type&&f.push(`(${c.type})`),c.description&&f.push(`- ${c.description}`),c.registry&&f.push(`[${c.registry}]`),f.push(`
|
|
2
2
|
Add command: \`${g(`add ${c.addCommandArgument}`)}\``),f.join(" ")}),o=`Found ${n.pagination.total} items`;r&&(o+=` matching "${r}"`),i&&i.length>0&&(o+=` in registries ${i.join(", ")}`),o+=":";let m=`Showing items ${n.pagination.offset+1}-${Math.min(n.pagination.offset+n.pagination.limit,n.pagination.total)} of ${n.pagination.total}:`,d=`${o}
|
|
3
3
|
|
|
4
4
|
${m}
|
|
@@ -34,7 +34,7 @@ Found ${n.length} example${n.length>1?"s":""} matching "${e}":
|
|
|
34
34
|
|
|
35
35
|
To fix this:
|
|
36
36
|
1. Use the \`init\` command to create a components.json file
|
|
37
|
-
2. Or manually create components.json with a registries section`}]}}case "search_items_in_registries":{let r=z.object({registries:z.array(z.string()),query:z.string(),limit:z.number().optional(),offset:z.number().optional()}).parse(n.params.arguments),i=await
|
|
37
|
+
2. Or manually create components.json with a registries section`}]}}case "search_items_in_registries":{let r=z.object({registries:z.array(z.string()),query:z.string(),limit:z.number().optional(),offset:z.number().optional()}).parse(n.params.arguments),i=await va(r.registries,{query:r.query,limit:r.limit,offset:r.offset,config:await u(process.cwd()),useCache:!1});return i.items.length===0?{content:[{type:"text",text:a`No items found matching "${r.query}" in registries ${r.registries.join(", ")}, Try searching with a different query or registry.`}]}:{content:[{type:"text",text:y(i,{query:r.query,registries:r.registries})}]}}case "list_items_in_registries":{let r=z.object({registries:z.array(z.string()),limit:z.number().optional(),offset:z.number().optional(),cwd:z.string().optional()}).parse(n.params.arguments),i=await va(r.registries,{limit:r.limit,offset:r.offset,config:await u(process.cwd()),useCache:!1});return i.items.length===0?{content:[{type:"text",text:a`No items found in registries ${r.registries.join(", ")}.`}]}:{content:[{type:"text",text:y(i,{registries:r.registries})}]}}case "view_items_in_registries":{let r=z.object({items:z.array(z.string())}).parse(n.params.arguments),i=await ba(r.items,{config:await u(process.cwd()),useCache:!1});if(i?.length===0)return {content:[{type:"text",text:a`No items found for: ${r.items.join(", ")}
|
|
38
38
|
|
|
39
39
|
Make sure the item names are correct and include the registry prefix (e.g., @shadcn/button).`}]};let s=w(i);return {content:[{type:"text",text:a`Item Details:
|
|
40
40
|
|
|
@@ -42,7 +42,7 @@ Found ${n.length} example${n.length>1?"s":""} matching "${e}":
|
|
|
42
42
|
|
|
43
43
|
---
|
|
44
44
|
|
|
45
|
-
`)}`}]}}case "get_item_examples_from_registries":{let r=z.object({query:z.string(),registries:z.array(z.string())}).parse(n.params.arguments),i=await u(),s=await
|
|
45
|
+
`)}`}]}}case "get_item_examples_from_registries":{let r=z.object({query:z.string(),registries:z.array(z.string())}).parse(n.params.arguments),i=await u(),s=await va(r.registries,{query:r.query,config:i,useCache:!1});if(s.items.length===0)return {content:[{type:"text",text:a`No examples found for query "${r.query}".
|
|
46
46
|
|
|
47
47
|
Try searching with patterns like:
|
|
48
48
|
- "accordion-demo" for accordion examples
|
|
@@ -51,7 +51,7 @@ Found ${n.length} example${n.length>1?"s":""} matching "${e}":
|
|
|
51
51
|
|
|
52
52
|
You can also:
|
|
53
53
|
1. Use search_items_in_registries to find all items matching your query
|
|
54
|
-
2. View the main component with view_items_in_registries for inline usage documentation`}]};let o=s.items.map(d=>d.addCommandArgument),m=await
|
|
54
|
+
2. View the main component with view_items_in_registries for inline usage documentation`}]};let o=s.items.map(d=>d.addCommandArgument),m=await ba(o,{config:i,useCache:!1});return {content:[{type:"text",text:$(m,r.query)}]}}case "get_add_command_for_items":{let e=z.object({items:z.array(z.string())}).parse(n.params.arguments);return {content:[{type:"text",text:await g(`add ${e.items.join(" ")}`)}]}}case "get_audit_checklist":return {content:[{type:"text",text:a`## Component Audit Checklist
|
|
55
55
|
|
|
56
56
|
After adding or generating components, check the following common issues:
|
|
57
57
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var _=["radix","base"],u=["nova","vega","maia","lyra","mira"],f=["neutral","stone","zinc","gray","mauve","olive","mist","taupe"],E=["neutral","stone","zinc","gray","amber","blue","cyan","emerald","fuchsia","green","indigo","lime","orange","pink","purple","red","rose","sky","teal","violet","yellow","mauve","olive","mist","taupe"],c=["lucide","hugeicons","tabler","phosphor","remixicon"],S=["inter","noto-sans","nunito-sans","figtree","roboto","raleway","dm-sans","public-sans","outfit","jetbrains-mono","geist","geist-mono","lora","merriweather","playfair-display","noto-serif","roboto-slab"],p=["default","none","small","medium","large"],m=["subtle","bold"],b=["default","inverted","default-translucent","inverted-translucent"],i=[{key:"menuColor",values:b,bits:3},{key:"menuAccent",values:m,bits:3},{key:"radius",values:p,bits:4},{key:"font",values:S,bits:6},{key:"iconLibrary",values:c,bits:6},{key:"theme",values:E,bits:6},{key:"baseColor",values:f,bits:6},{key:"style",values:u,bits:6}],g=Object.fromEntries(i.map(e=>[e.key,e.values[0]])),a="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",l="a";function y(e){if(e===0)return "0";let t="",n=e;for(;n>0;)t=a[n%62]+t,n=Math.floor(n/62);return t}function P(e){let t=0;for(let n=0;n<e.length;n++){let r=a.indexOf(e[n]);if(r===-1)return -1;t=t*62+r;}return t}function R(e){let t={...g,...e},n=0,r=0;for(let o of i){let s=o.values.indexOf(t[o.key]);n+=(s===-1?0:s)*2**r,r+=o.bits;}return l+y(n)}function d(e){if(!e||e.length<2||e[0]!==l)return null;let t=P(e.slice(1));if(t<0)return null;let n={},r=0;for(let o of i){let s=Math.floor(t/2**r)%2**o.bits;n[o.key]=s<o.values.length?o.values[s]:o.values[0],r+=o.bits;}return n}function x(e){if(!e||e.length<2||e.length>10||e[0]!==l)return false;for(let t=1;t<e.length;t++)if(a.indexOf(e[t])===-1)return false;return true}function C(e){return d(e)!==null}function T(){let e=t=>t[Math.floor(Math.random()*t.length)];return Object.fromEntries(i.map(t=>[t.key,e(t.values)]))}function h(){return R(T())}export{_ as a,u as b,f as c,E as d,c as e,S as f,p as g,m as h,b as i,g as j,y as k,P as l,R as m,d as n,x as o,C as p,T as q,h as r};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import {a}from'./chunk-CHWMSXYA.js';import {SyntaxKind,Project,ScriptKind}from'ts-morph';import {twMerge}from'tailwind-merge';var Y=async({sourceFile:n,config:r})=>{let i=r.iconLibrary;if(!i||!(i in a))return n;let s=i,t=a[s],a$1=[];for(let c of n.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)){if(c.getTagNameNode()?.getText()!=="IconPlaceholder")continue;let d=c.getAttributes().find(g=>g.getKind()!==SyntaxKind.JsxAttribute?false:g.asKindOrThrow(SyntaxKind.JsxAttribute).getNameNode().getText()===s);if(!d)continue;let e=d.asKindOrThrow(SyntaxKind.JsxAttribute),l=e.getInitializer()?.getText().replace(/^["']|["']$/g,"");if(!l)continue;a$1.includes(l)||a$1.push(l);let u=t.usage.match(/<(\w+)([^>]*)\s*\/>/);e.remove();for(let g of c.getAttributes()){if(g.getKind()!==SyntaxKind.JsxAttribute)continue;let x=g.asKindOrThrow(SyntaxKind.JsxAttribute);x.getNameNode().getText()in a&&x.remove();}if(!u){c.getTagNameNode()?.replaceWithText(l);continue}let[,b,S]=u;if(b==="ICON"){let g=c.getAttributes().filter(x=>x.getKind()!==SyntaxKind.JsxAttribute?true:!(x.asKindOrThrow(SyntaxKind.JsxAttribute).getNameNode().getText()in a)).map(x=>x.getText()).join(" ");g.trim()?c.replaceWithText(`<${l} ${g} />`):c.getTagNameNode()?.replaceWithText(l);}else {let g=new Set(c.getAttributes().filter(m=>m.getKind()===SyntaxKind.JsxAttribute).map(m=>m.asKindOrThrow(SyntaxKind.JsxAttribute).getNameNode().getText())),N=S.replace(/\{ICON\}/g,`{${l}}`).trim().split(/\s+(?=\w+=)/).filter(m=>m).map(m=>{let A=m.split("=")[0];return A&&!g.has(A)?m:null}).filter(Boolean),E=c.getAttributes().filter(m=>m.getKind()!==SyntaxKind.JsxAttribute?true:!(m.asKindOrThrow(SyntaxKind.JsxAttribute).getNameNode().getText()in a)).map(m=>m.getText()).join(" "),y=[...N,E].filter(Boolean).join(" ");c.replaceWithText(`<${b} ${y} />`);}}for(let c of n.getImportDeclarations()??[])if(c.getModuleSpecifier()?.getText()?.includes("icon-placeholder")){let l=(c.getNamedImports()??[]).find(f=>f.getName()==="IconPlaceholder");l&&l.remove(),c.getNamedImports()?.length===0&&c.remove();}if(a$1.length>0){let c=t.import.split(`
|
|
2
|
+
`),d=[];for(let e of c){let l=e.match(/import\s+{([^}]+)}\s+from\s+['"]([^'"]+)['"]/);if(!l)continue;let[,f,u]=l,b=f.split(",").map(g=>g.trim()).map(g=>g==="ICON"?a$1.map(x=>({name:x})):{name:g}).flat(),S=n.addImportDeclaration({moduleSpecifier:u,namedImports:b});d.push(S);}if(!L(n))for(let e of d)e.replaceWithText(e.getText().replace(";",""));}return n};function L(n){return n.getImportDeclarations()?.[0]?.getText().endsWith(";")??false}var et=async({sourceFile:n,config:r,baseColor:i})=>(r.tailwind?.cssVariables||!i?.inlineColors||n.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach(s=>{let t=s.getLiteralText(),a=D(t,i.inlineColors).trim();a!==t&&s.setLiteralValue(a);}),n);function K(n){if(!n.includes("/")&&!n.includes(":"))return [null,n,null];let r=-1,i=0;for(let e=n.length-1;e>=0;e--){let l=n[e];if(l==="]")i++;else if(l==="[")i--;else if(l===":"&&i===0){r=e;break}}let s=null,t;r===-1?t=n:(s=n.slice(0,r),t=n.slice(r+1));let a=t.lastIndexOf("/");if(a===-1)return [s,t,null];let c=t.slice(0,a),d=t.slice(a+1);return [s,c,d]}var v=["bg-","text-","border-","ring-offset-","ring-"];function D(n,r){n.includes(" border ")&&(n=n.replace(" border "," border border-border "));let i=n.split(" "),s=new Set,t=new Set;for(let a of i){let[c,d,e]=K(a),l=v.find(u=>d?.startsWith(u));if(!l){s.has(a)||s.add(a);continue}let f=d?.replace(l,"");if(f&&f in r.light){s.add([c,`${l}${r.light[f]}`].filter(Boolean).join(":")+(e?`/${e}`:"")),t.add(["dark",c,`${l}${r.dark[f]}`].filter(Boolean).join(":")+(e?`/${e}`:""));continue}s.has(a)||s.add(a);}return [...Array.from(s),...Array.from(t)].join(" ").trim()}var W=[["-ml-","-ms-"],["-mr-","-me-"],["ml-","ms-"],["mr-","me-"],["pl-","ps-"],["pr-","pe-"],["-left-","-start-"],["-right-","-end-"],["left-","start-"],["right-","end-"],["inset-l-","inset-inline-start-"],["inset-r-","inset-inline-end-"],["rounded-tl-","rounded-ss-"],["rounded-tr-","rounded-se-"],["rounded-bl-","rounded-es-"],["rounded-br-","rounded-ee-"],["rounded-l-","rounded-s-"],["rounded-r-","rounded-e-"],["border-l-","border-s-"],["border-r-","border-e-"],["border-l","border-s"],["border-r","border-e"],["text-left","text-start"],["text-right","text-end"],["scroll-ml-","scroll-ms-"],["scroll-mr-","scroll-me-"],["scroll-pl-","scroll-ps-"],["scroll-pr-","scroll-pe-"],["float-left","float-start"],["float-right","float-end"],["clear-left","clear-start"],["clear-right","clear-end"],["origin-top-left","origin-top-start"],["origin-top-right","origin-top-end"],["origin-bottom-left","origin-bottom-start"],["origin-bottom-right","origin-bottom-end"],["origin-left","origin-start"],["origin-right","origin-end"]],w=[["-translate-x-","translate-x-"],["translate-x-","-translate-x-"]],M=[["space-x-","space-x-reverse"],["divide-x-","divide-x-reverse"]],R=[["cursor-w-resize","cursor-e-resize"],["cursor-e-resize","cursor-w-resize"]],j=[["data-[side=inline-start]","slide-in-from-right","slide-in-from-end"],["data-[side=inline-start]","slide-out-to-right","slide-out-to-end"],["data-[side=inline-end]","slide-in-from-left","slide-in-from-start"],["data-[side=inline-end]","slide-out-to-left","slide-out-to-start"]],J="cn-rtl-flip",$=["ContextMenuContent","ContextMenuSubContent","DropdownMenuSubContent"],P={right:"inline-end",left:"inline-start"},V=["-left-","-right-","left-","right-"],ot=async({sourceFile:n,config:r})=>(r.rtl&&C(n),n);async function at(n,r){if(!r)return n;let s=new Project({useInMemoryFileSystem:true}).createSourceFile("component.tsx",n,{scriptKind:ScriptKind.TSX,overwrite:true});return C(s),s.getText()}function I(n){return n.replace(/^["']|["']$/g,"")}function h(n){let r=I(n.getText()??"");n.replaceWithText(`"${B(r)}"`);}function B(n){return n.split(" ").flatMap(r=>{if(r.startsWith("rtl:")||r.startsWith("ltr:"))return [r];if(r===J)return ["rtl:rotate-180"];let[i,s,t]=K(r);if(!s)return [r];for(let[e,l]of w)if(s.startsWith(e)){let f=s.replace(e,l),u=i?`rtl:${i}:${f}${t?`/${t}`:""}`:`rtl:${f}${t?`/${t}`:""}`;return [r,u]}for(let[e,l]of M)if(s.startsWith(e)){let f=i?`rtl:${i}:${l}`:`rtl:${l}`;return [r,f]}for(let[e,l]of R)if(s===e){let f=i?`rtl:${i}:${l}`:`rtl:${l}`;return [r,f]}for(let[e,l,f]of j)if(i?.includes(e)&&s.startsWith(l)){let u=s.replace(l,f);return [t?`${i}:${u}/${t}`:`${i}:${u}`]}let a=i?.includes("data-[side=left]")||i?.includes("data-[side=right]"),c=s;for(let[e,l]of W)if(!(a&&V.some(f=>e.startsWith(f)))&&s.startsWith(e)){if(!e.endsWith("-")&&s!==e)continue;c=s.replace(e,l);break}let d;return i?d=t?`${i}:${c}/${t}`:`${i}:${c}`:d=t?`${c}/${t}`:c,[d]}).join(" ")}function C(n){n.getDescendantsOfKind(SyntaxKind.CallExpression).filter(r=>r.getExpression().getText()==="cva").forEach(r=>{let i=r.getArguments()[0];i?.isKind(SyntaxKind.StringLiteral)&&h(i),r.getArguments()[1]?.isKind(SyntaxKind.ObjectLiteralExpression)&&r.getArguments()[1]?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).find(s=>s.getName()==="variants")?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(s=>{s.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(t=>{let a=t.getInitializerIfKind(SyntaxKind.StringLiteral);a&&h(a);});});}),n.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach(r=>{if(r.getNameNode().getText()==="className"){let i=r.getInitializer();if(i?.isKind(SyntaxKind.StringLiteral)&&h(i),r.getInitializer()?.isKind(SyntaxKind.JsxExpression)){let s=r.getInitializer()?.getDescendantsOfKind(SyntaxKind.CallExpression).find(t=>t.getExpression().getText()==="cn");s&&s.getArguments().forEach(t=>{(t.isKind(SyntaxKind.ConditionalExpression)||t.isKind(SyntaxKind.BinaryExpression))&&t.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(h),t.isKind(SyntaxKind.StringLiteral)&&h(t);});}}r.getNameNode().getText()==="classNames"&&r.getInitializer()?.isKind(SyntaxKind.JsxExpression)&&r.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(i=>{if(i.getInitializer()?.isKind(SyntaxKind.CallExpression)){let t=i.getInitializerIfKind(SyntaxKind.CallExpression);t&&t.getArguments().forEach(a=>{a.isKind(SyntaxKind.ConditionalExpression)&&a.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(h),a.isKind(SyntaxKind.StringLiteral)&&h(a);});}let s=i.getInitializer();s?.isKind(SyntaxKind.StringLiteral)&&i.getNameNode().getText()!=="variant"&&h(s);});}),n.getDescendantsOfKind(SyntaxKind.CallExpression).filter(r=>r.getExpression().getText()==="mergeProps").forEach(r=>{let i=r.getArguments()[0];if(i?.isKind(SyntaxKind.ObjectLiteralExpression)){let s=i.getProperties().find(t=>t.isKind(SyntaxKind.PropertyAssignment)&&t.getName()==="className");if(s?.isKind(SyntaxKind.PropertyAssignment)){let t=s.getInitializer();t?.isKind(SyntaxKind.CallExpression)&&t.getExpression().getText()==="cn"&&t.getArguments().forEach(a=>{a.isKind(SyntaxKind.StringLiteral)&&h(a),(a.isKind(SyntaxKind.ConditionalExpression)||a.isKind(SyntaxKind.BinaryExpression))&&a.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(h);}),t?.isKind(SyntaxKind.StringLiteral)&&h(t);}}}),[...n.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement),...n.getDescendantsOfKind(SyntaxKind.JsxOpeningElement)].forEach(r=>{let i=r.getTagNameNode().getText();if(!$.includes(i))return;let s=r.getAttributes().find(d=>d.isKind(SyntaxKind.JsxAttribute)&&d.getNameNode().getText()==="side");if(!s?.isKind(SyntaxKind.JsxAttribute))return;let t=s.getInitializer();if(!t?.isKind(SyntaxKind.StringLiteral))return;let a=I(t.getText()??""),c=P[a];c&&t.replaceWithText(`"${c}"`);}),n.getDescendantsOfKind(SyntaxKind.BindingElement).forEach(r=>{if(r.getNameNode().getText()!=="side")return;let t=r.getFirstAncestorByKind(SyntaxKind.FunctionDeclaration)?.getName();if(!t||!$.includes(t))return;let a=r.getInitializer();if(!a?.isKind(SyntaxKind.StringLiteral))return;let c=I(a.getText()??""),d=P[c];d&&a.replaceWithText(`"${d}"`);});}var X="animate-none! relative bg-popover/70 before:pointer-events-none before:absolute before:inset-0 before:-z-1 before:rounded-[inherit] before:backdrop-blur-2xl before:backdrop-saturate-150 **:data-[slot$=-item]:focus:bg-foreground/10 **:data-[slot$=-item]:data-highlighted:bg-foreground/10 **:data-[slot$=-separator]:bg-foreground/5 **:data-[slot$=-trigger]:focus:bg-foreground/10 **:data-[slot$=-trigger]:aria-expanded:bg-foreground/10! **:data-[variant=destructive]:focus:bg-foreground/10! **:data-[variant=destructive]:text-accent-foreground! **:data-[variant=destructive]:**:text-accent-foreground!",ft=async({sourceFile:n,config:r})=>{let i=r.menuColor,s=i==="default-translucent"||i==="inverted-translucent";for(let t of n.getDescendantsOfKind(SyntaxKind.JsxAttribute)){if(t.getNameNode().getText()!=="className")continue;let c=t.getInitializer();if(!c)continue;let d=c.getText();if(!d.includes("cn-menu-target")&&!d.includes("cn-menu-translucent"))continue;let e=d,l=false;i==="inverted"||i==="inverted-translucent"?e=e.replace(/cn-menu-target/g,"dark"):(e=e.replace(/cn-menu-target/g,""),l=true),s?e=e.replace(/"([^"]*cn-menu-translucent[^"]*)"/g,(f,u)=>`"${twMerge(u,X).replace(/\s*\bcn-menu-translucent\b\s*/g," ").trim()}"`):e.includes("cn-menu-translucent")&&(e=e.replace(/cn-menu-translucent/g,""),l=true),l&&(e=e.replace(/\s{2,}/g," "),e=e.replace(/"\s+/g,'"'),e=e.replace(/\s+"/g,'"'),e=e.replace(/,\s*""\s*,/g,","),e=e.replace(/\(\s*""\s*,/g,"("),e=e.replace(/,\s*""\s*\)/g,")")),t.setInitializer(e);}return n};export{et as a,K as b,Y as c,ot as d,at as e,ft as f};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {m,l,f,d as d$1,c as c$1,e,n,t,o,b as b$1,p,q as q$1,r,s,x,z as z$1,v as v$1,g}from'./chunk-
|
|
1
|
+
import {m,l,f,d as d$1,c as c$1,e,n,t,o,b as b$1,p,q as q$1,r,s,x,z as z$1,v as v$1,g}from'./chunk-BFLSSWBX.js';import {a,d,c,b,f as f$1}from'./chunk-JPE2JKEP.js';import y,{basename}from'path';import {z}from'zod';import {promises,existsSync,statSync}from'fs';import {green,cyan,yellow,red}from'kleur/colors';import {loadConfig,createMatchPath}from'tsconfig-paths';import {cosmiconfig}from'cosmiconfig';import Ke from'fast-glob';import ne from'fs-extra';import {tmpdir,homedir}from'os';import Fr from'ora';import {Project,SyntaxKind,ScriptKind,QuoteKind}from'ts-morph';import {transformFromAstSync}from'@babel/core';import {parse}from'@babel/parser';import Vr from'@babel/plugin-transform-typescript';import*as We from'recast';import rs from'prompts';import pe from'deepmerge';import {HttpsProxyAgent}from'https-proxy-agent';import Is from'node-fetch';import {createHash}from'crypto';import ks from'stringify-object';import Zs from'fuzzysort';var G=process.env.REGISTRY_URL??"https://ui.shadcn.com/r",k=G.replace(/\/r\/?$/,""),Ae="new-york-v4",jt=[{name:"neutral",label:"Neutral"},{name:"zinc",label:"Zinc"},{name:"stone",label:"Stone"},{name:"mauve",label:"Mauve"},{name:"olive",label:"Olive"},{name:"mist",label:"Mist"},{name:"taupe",label:"Taupe"}],N={"@shadcn":`${G}/styles/{style}/{name}.json`};var sn=[{name:"toast",deprecatedBy:"sonner",message:"The toast component is deprecated. Use the sonner component instead."},{name:"toaster",deprecatedBy:"sonner",message:"The toaster component is deprecated. Use the sonner component instead."}];function ge(e){return e.replace(/\${(\w+)}/g,(t,r)=>process.env[r]||"")}function de(e){let t=[],r=/\${(\w+)}/g,s;for(;(s=r.exec(e))!==null;)t.push(s[1]);return t}var A={NOT_FOUND:"NOT_FOUND",GONE:"GONE",UNAUTHORIZED:"UNAUTHORIZED",FORBIDDEN:"FORBIDDEN",FETCH_ERROR:"FETCH_ERROR",NOT_CONFIGURED:"NOT_CONFIGURED",INVALID_CONFIG:"INVALID_CONFIG",MISSING_ENV_VARS:"MISSING_ENV_VARS",LOCAL_FILE_ERROR:"LOCAL_FILE_ERROR",PARSE_ERROR:"PARSE_ERROR",VALIDATION_ERROR:"VALIDATION_ERROR",UNKNOWN_ERROR:"UNKNOWN_ERROR"},I=class extends Error{code;statusCode;context;suggestion;timestamp;cause;constructor(t,r={}){super(t),this.name="RegistryError",this.code=r.code||A.UNKNOWN_ERROR,this.statusCode=r.statusCode,this.cause=r.cause,this.context=r.context,this.suggestion=r.suggestion,this.timestamp=new Date,Error.captureStackTrace&&Error.captureStackTrace(this,this.constructor);}toJSON(){return {name:this.name,message:this.message,code:this.code,statusCode:this.statusCode,context:this.context,suggestion:this.suggestion,timestamp:this.timestamp,stack:this.stack}}},J=class extends I{constructor(r,s){let n=`The item at ${r} was not found. It may not exist at the registry.`;super(n,{code:A.NOT_FOUND,statusCode:404,cause:s,context:{url:r},suggestion:"Check if the item name is correct and the registry URL is accessible."});this.url=r;this.name="RegistryNotFoundError";}},Oe=class extends I{constructor(r,s){let n=`The item at ${r} is no longer available. It may have been removed or expired.`;super(n,{code:A.GONE,statusCode:410,cause:s,context:{url:r},suggestion:"This resource was previously available but has been permanently removed. Check if a newer version exists or contact the registry maintainer."});this.url=r;this.name="RegistryGoneError";}},ue=class extends I{constructor(r,s){let n=`You are not authorized to access the item at ${r}. If this is a remote registry, you may need to authenticate.`;super(n,{code:A.UNAUTHORIZED,statusCode:401,cause:s,context:{url:r},suggestion:"Check your authentication credentials and environment variables."});this.url=r;this.name="RegistryUnauthorizedError";}},he=class extends I{constructor(r,s){let n=`You are not authorized to access the item at ${r}. If this is a remote registry, you may need to authenticate.`;super(n,{code:A.FORBIDDEN,statusCode:403,cause:s,context:{url:r},suggestion:"Check your authentication credentials and environment variables."});this.url=r;this.name="RegistryForbiddenError";}},ye=class extends I{constructor(r,s,n,i){let o=s?`Failed to fetch from registry (${s}): ${r}`:`Failed to fetch from registry: ${r}`,a=typeof i=="string"&&i?`${o} - ${i}`:o,l="Check your network connection and try again.";s===404?l="The requested resource was not found. Check the URL or item name.":s===500?l="The registry server encountered an error. Try again later.":s&&s>=400&&s<500&&(l="There was a client error. Check your request parameters.");super(a,{code:A.FETCH_ERROR,statusCode:s,cause:i,context:{url:r,responseBody:n},suggestion:l});this.url=r;this.responseBody=n;this.name="RegistryFetchError";}},W=class extends I{constructor(r){let s=r?`Unknown registry "${r}". Make sure it is defined in components.json as follows:
|
|
2
2
|
{
|
|
3
3
|
"registries": {
|
|
4
4
|
"${r}": "[URL_TO_REGISTRY]"
|
|
@@ -30,4 +30,4 @@ Message:`),v.error(e.cause)),e.suggestion&&(v.error(`
|
|
|
30
30
|
Suggestion:`),v.error(e.suggestion)),v.break(),process.exit(1)),e instanceof z.ZodError){v.error("Validation failed:");for(let[t,r]of Object.entries(e.flatten().fieldErrors))v.error(`- ${T.info(t)}: ${r}`);v.break(),process.exit(1);}e instanceof Error&&(v.error(e.message),v.break(),process.exit(1)),v.break(),process.exit(1);}async function mt(e,t){let{config:r,useCache:s}=t||{};if(F(e)){let[a]=await P([e],{useCache:s});try{return o.parse(a)}catch(l){throw new $(e,l)}}if(!e.startsWith("@"))throw new we(e);let n=e;n.endsWith("/registry")||(n=`${n}/registry`);let i=ce(n,le(r));if(!i?.url)throw new J(n);i.headers&&Object.keys(i.headers).length>0&&Re({[i.url]:i.headers});let[o$1]=await P([i.url],{useCache:s});try{return o.parse(o$1)}catch(a){throw new $(n,a)}}async function Gs(e,t){let{config:r,useCache:s=false}=t||{};return Ce(),Z(e,le(r),{useCache:s})}async function Js(e,t){let{config:r,useCache:s=false}=t||{};return Ce(),lr(e,le(r),{useCache:s})}async function dl(e,t){let{useCache:r=true}=t||{};r||Le.clearCaches();let s=await Le.search(e);if(!s)return {registries:N};let n=z.object({registries:b$1.optional()}).safeParse(s.config);if(!n.success)throw new Ne(e,n.error);return {registries:{...N,...n.data.registries||{}}}}async function De(){try{let[e]=await P(["index.json"]);return p.parse(e)}catch(e){v.error(`
|
|
31
31
|
`),fe(e);}}async function ul(){try{let[e]=await P(["styles/index.json"]);return q$1.parse(e)}catch(e){return v.error(`
|
|
32
32
|
`),fe(e),[]}}async function hl(){try{let[e]=await P(["icons/index.json"]);return r.parse(e)}catch(e){return fe(e),{}}}async function yl(){return jt}async function Je(e){try{let[t]=await P([`colors/${e}.json`]);return s.parse(t)}catch(t){fe(t);}}async function Hs(e,t){let r=[];for(let s of t){let n=e.find(i=>i.name===s);if(n&&(r.push(n),n.registryDependencies)){let i=await Hs(e,n.registryDependencies);r.push(...i);}}return r.filter((s,n,i)=>i.findIndex(o=>o.name===s.name)===n)}async function xl(e,t){try{let r=t.map(n=>`styles/${e}/${n.name}.json`);return (await P(r)).map(n$1=>n.parse(n$1))}catch(r){return fe(r),[]}}async function wl(e,t,r){if(r)return r;if(t.type==="registry:ui")return e.resolvedPaths.ui??e.resolvedPaths.components;let[s,n]=t.type?.split(":")??[];return s in e.resolvedPaths?y.join(e.resolvedPaths[s],n):null}async function pr(e){e={useCache:true,...e};let t=`${G}/registries.json`,[r]=await P([t],{useCache:e.useCache});try{return x.parse(r)}catch(s){throw s instanceof z.ZodError?new Ee(s):s}}async function qs(e){let t=await pr(e);return t?Object.fromEntries(t.map(r=>[r.name,r.url])):null}async function Ys(e){e={useCache:true,...e};let t=`${G}/config.json`,[r]=await P([t],{useCache:e.useCache});return z$1.parse(r).presets}async function El(e,t){return (await Ys(t)).find(s=>s.name.toLowerCase()===e.toLowerCase())??null}async function Qs(e,t){let{query:r,limit:s,offset:n,config:i,useCache:o}=t||{},a=[];for(let x of e){let h=((await mt(x,{config:i,useCache:o})).items||[]).map(w=>({name:w.name,type:w.type,description:w.description,registry:x,addCommandArgument:rn(w.name,x)}));a=a.concat(h);}r&&(a=en(a,{query:r,limit:a.length,keys:["name","description"]}));let l=n||0,c=s||a.length,f=a.length,p={pagination:{total:f,offset:l,limit:c,hasMore:l+c<f},items:a.slice(l,l+c)};return v$1.parse(p)}var Xs=z.object({name:z.string(),type:z.string().optional(),description:z.string().optional(),registry:z.string().optional(),addCommandArgument:z.string().optional()}).passthrough();function en(e,t){t={limit:100,threshold:-1e4,...t};let s=Zs.go(t.query,e,{keys:t.keys,threshold:t.threshold,limit:t.limit}).map(n=>n.obj);return z.array(Xs).parse(s)}function tn(e){try{return new URL(e),!0}catch{return false}}function rn(e,t){if(!tn(t))return `${t}/${e}`;let r=t.indexOf("://")+3,s=t.indexOf("/",r);if(s===-1){let x=t.indexOf("?",r);if(x!==-1){let d=t.substring(0,x),w=t.substring(x).replace(/\bregistry\b/g,e);return d+w}return t}let n=t.substring(0,s),i=t.substring(s),o=i.indexOf("?")!==-1?i.indexOf("?"):i.length,a=i.substring(0,o),l=i.substring(o),c=a.lastIndexOf("registry"),f=a;c!==-1&&(f=a.substring(0,c)+e+a.substring(c+8));let p=l.replace(/\bregistry\b/g,e);return n+f+p}
|
|
33
|
-
export{
|
|
33
|
+
export{fe as $,Ge as A,Wt as B,Ut as C,xo as D,nt as E,it as F,F as G,Oo as H,In as I,Tn as J,Pn as K,jn as L,Le as M,ve as N,Fe as O,kn as P,Cr as Q,br as R,$n as S,$t as T,le as U,Ce as V,Ho as W,ce as X,Ia as Y,Z,lr as _,T as a,mt as aa,v as b,Gs as ba,k as c,Js as ca,N as d,dl as da,sn as e,De as ea,I as f,ul as fa,J as g,hl as ga,ue as h,yl as ha,he as i,Je as ia,ye as j,Hs as ja,W as k,xl as ka,te as l,wl as la,$ as m,pr as ma,xe as n,qs as na,we as o,Ys as oa,Ee as p,El as pa,re as q,tt as qa,Ot as r,_ as ra,q as s,qn as sa,Lt as t,ze as ta,Ft as u,Yn as ua,Dt as v,Qs as va,Y as w,Ve as x,Ue as y,Be as z};
|
package/dist/index.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ declare function getRegistry(name: string, options?: {
|
|
|
35
35
|
tsx?: boolean | undefined;
|
|
36
36
|
iconLibrary?: string | undefined;
|
|
37
37
|
rtl?: boolean | undefined;
|
|
38
|
-
menuColor?: "default" | "inverted" | undefined;
|
|
38
|
+
menuColor?: "default" | "inverted" | "default-translucent" | "inverted-translucent" | undefined;
|
|
39
39
|
menuAccent?: "bold" | "subtle" | undefined;
|
|
40
40
|
aliases?: {
|
|
41
41
|
components?: string | undefined;
|
|
@@ -195,7 +195,7 @@ declare function getRegistryItems(items: string[], options?: {
|
|
|
195
195
|
tsx?: boolean | undefined;
|
|
196
196
|
iconLibrary?: string | undefined;
|
|
197
197
|
rtl?: boolean | undefined;
|
|
198
|
-
menuColor?: "default" | "inverted" | undefined;
|
|
198
|
+
menuColor?: "default" | "inverted" | "default-translucent" | "inverted-translucent" | undefined;
|
|
199
199
|
menuAccent?: "bold" | "subtle" | undefined;
|
|
200
200
|
aliases?: {
|
|
201
201
|
components?: string | undefined;
|
|
@@ -442,7 +442,7 @@ declare function getShadcnRegistryIndex(): Promise<({
|
|
|
442
442
|
tsx?: boolean | undefined;
|
|
443
443
|
iconLibrary?: string | undefined;
|
|
444
444
|
rtl?: boolean | undefined;
|
|
445
|
-
menuColor?: "default" | "inverted" | undefined;
|
|
445
|
+
menuColor?: "default" | "inverted" | "default-translucent" | "inverted-translucent" | undefined;
|
|
446
446
|
menuAccent?: "bold" | "subtle" | undefined;
|
|
447
447
|
aliases?: {
|
|
448
448
|
components?: string | undefined;
|
|
@@ -646,7 +646,7 @@ declare function resolveTree(index: z.infer<typeof registryIndexSchema>, names:
|
|
|
646
646
|
tsx?: boolean | undefined;
|
|
647
647
|
iconLibrary?: string | undefined;
|
|
648
648
|
rtl?: boolean | undefined;
|
|
649
|
-
menuColor?: "default" | "inverted" | undefined;
|
|
649
|
+
menuColor?: "default" | "inverted" | "default-translucent" | "inverted-translucent" | undefined;
|
|
650
650
|
menuAccent?: "bold" | "subtle" | undefined;
|
|
651
651
|
aliases?: {
|
|
652
652
|
components?: string | undefined;
|
|
@@ -805,7 +805,7 @@ declare function fetchTree(style: string, tree: z.infer<typeof registryIndexSche
|
|
|
805
805
|
tsx?: boolean | undefined;
|
|
806
806
|
iconLibrary?: string | undefined;
|
|
807
807
|
rtl?: boolean | undefined;
|
|
808
|
-
menuColor?: "default" | "inverted" | undefined;
|
|
808
|
+
menuColor?: "default" | "inverted" | "default-translucent" | "inverted-translucent" | undefined;
|
|
809
809
|
menuAccent?: "bold" | "subtle" | undefined;
|
|
810
810
|
aliases?: {
|
|
811
811
|
components?: string | undefined;
|
|
@@ -960,7 +960,7 @@ declare function getPresets(options?: {
|
|
|
960
960
|
baseColor: string;
|
|
961
961
|
iconLibrary: string;
|
|
962
962
|
rtl: boolean;
|
|
963
|
-
menuColor: "default" | "inverted";
|
|
963
|
+
menuColor: "default" | "inverted" | "default-translucent" | "inverted-translucent";
|
|
964
964
|
menuAccent: "bold" | "subtle";
|
|
965
965
|
theme: string;
|
|
966
966
|
name: string;
|
|
@@ -977,7 +977,7 @@ declare function getPreset(name: string, options?: {
|
|
|
977
977
|
baseColor: string;
|
|
978
978
|
iconLibrary: string;
|
|
979
979
|
rtl: boolean;
|
|
980
|
-
menuColor: "default" | "inverted";
|
|
980
|
+
menuColor: "default" | "inverted" | "default-translucent" | "inverted-translucent";
|
|
981
981
|
menuAccent: "bold" | "subtle";
|
|
982
982
|
theme: string;
|
|
983
983
|
name: string;
|