Files
my_site/node_modules/shadcn/dist/chunk-WLJDV6SE.js
2026-03-24 14:30:59 +08:00

2 lines
13 KiB
JavaScript

import {a}from'./chunk-CHWMSXYA.js';import {SyntaxKind,Project,ScriptKind}from'ts-morph';import {promises}from'fs';import {twMerge}from'tailwind-merge';var ot=async({sourceFile:r,config:n})=>{let e=n.iconLibrary;if(!e||!(e in a))return r;let t=e,i=a[t],o=[];for(let a$1 of r.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement)){if(a$1.getTagNameNode()?.getText()!=="IconPlaceholder")continue;let f=a$1.getAttributes().find(g=>g.getKind()!==SyntaxKind.JsxAttribute?false:g.asKindOrThrow(SyntaxKind.JsxAttribute).getNameNode().getText()===t);if(!f)continue;let s=f.asKindOrThrow(SyntaxKind.JsxAttribute),l=s.getInitializer()?.getText().replace(/^["']|["']$/g,"");if(!l)continue;o.includes(l)||o.push(l);let u=i.usage.match(/<(\w+)([^>]*)\s*\/>/);s.remove();for(let g of a$1.getAttributes()){if(g.getKind()!==SyntaxKind.JsxAttribute)continue;let x=g.asKindOrThrow(SyntaxKind.JsxAttribute);x.getNameNode().getText()in a&&x.remove();}if(!u){a$1.getTagNameNode()?.replaceWithText(l);continue}let[,b,K]=u;if(b==="ICON"){let g=a$1.getAttributes().filter(x=>x.getKind()!==SyntaxKind.JsxAttribute?true:!(x.asKindOrThrow(SyntaxKind.JsxAttribute).getNameNode().getText()in a)).map(x=>x.getText()).join(" ");g.trim()?a$1.replaceWithText(`<${l} ${g} />`):a$1.getTagNameNode()?.replaceWithText(l);}else {let g=new Set(a$1.getAttributes().filter(m=>m.getKind()===SyntaxKind.JsxAttribute).map(m=>m.asKindOrThrow(SyntaxKind.JsxAttribute).getNameNode().getText())),A=K.replace(/\{ICON\}/g,`{${l}}`).trim().split(/\s+(?=\w+=)/).filter(m=>m).map(m=>{let E=m.split("=")[0];return E&&!g.has(E)?m:null}).filter(Boolean),$=a$1.getAttributes().filter(m=>m.getKind()!==SyntaxKind.JsxAttribute?true:!(m.asKindOrThrow(SyntaxKind.JsxAttribute).getNameNode().getText()in a)).map(m=>m.getText()).join(" "),M=[...A,$].filter(Boolean).join(" ");a$1.replaceWithText(`<${b} ${M} />`);}}for(let a of r.getImportDeclarations()??[])if(a.getModuleSpecifier()?.getText()?.includes("icon-placeholder")){let l=(a.getNamedImports()??[]).find(d=>d.getName()==="IconPlaceholder");l&&l.remove(),a.getNamedImports()?.length===0&&a.remove();}if(o.length>0){let a=i.import.split(`
`),f=[];for(let s of a){let l=s.match(/import\s+{([^}]+)}\s+from\s+['"]([^'"]+)['"]/);if(!l)continue;let[,d,u]=l,b=d.split(",").map(g=>g.trim()).map(g=>g==="ICON"?o.map(x=>({name:x})):{name:g}).flat(),K=r.addImportDeclaration({moduleSpecifier:u,namedImports:b});f.push(K);}if(!z(r))for(let s of f)s.replaceWithText(s.getText().replace(";",""));}return r};function z(r){return r.getImportDeclarations()?.[0]?.getText().endsWith(";")??false}var ft=async({sourceFile:r,config:n,baseColor:e})=>(n.tailwind?.cssVariables||!e?.inlineColors||r.getDescendantsOfKind(SyntaxKind.StringLiteral).forEach(t=>{let i=t.getLiteralText(),o=J(i,e.inlineColors).trim();o!==i&&t.setLiteralValue(o);}),r);function I(r){if(!r.includes("/")&&!r.includes(":"))return [null,r,null];let n=-1,e=0;for(let s=r.length-1;s>=0;s--){let l=r[s];if(l==="]")e++;else if(l==="[")e--;else if(l===":"&&e===0){n=s;break}}let t=null,i;n===-1?i=r:(t=r.slice(0,n),i=r.slice(n+1));let o=i.lastIndexOf("/");if(o===-1)return [t,i,null];let a=i.slice(0,o),f=i.slice(o+1);return [t,a,f]}var k=["bg-","text-","border-","ring-offset-","ring-"];function J(r,n){r.includes(" border ")&&(r=r.replace(" border "," border border-border "));let e=r.split(" "),t=new Set,i=new Set;for(let o of e){let[a,f,s]=I(o),l=k.find(u=>f?.startsWith(u));if(!l){t.has(o)||t.add(o);continue}let d=f?.replace(l,"");if(d&&d in n.light){t.add([a,`${l}${n.light[d]}`].filter(Boolean).join(":")+(s?`/${s}`:"")),i.add(["dark",a,`${l}${n.dark[d]}`].filter(Boolean).join(":")+(s?`/${s}`:""));continue}t.has(o)||t.add(o);}return [...Array.from(t),...Array.from(i)].join(" ").trim()}var V=[["-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"]],B=[["-translate-x-","translate-x-"],["translate-x-","-translate-x-"]],G=[["space-x-","space-x-reverse"],["divide-x-","divide-x-reverse"]],X=[["cursor-w-resize","cursor-e-resize"],["cursor-e-resize","cursor-w-resize"]],F=[["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"]],Q="cn-rtl-flip",P=["ContextMenuContent","ContextMenuSubContent","DropdownMenuSubContent"],C={right:"inline-end",left:"inline-start"},U=["-left-","-right-","left-","right-"],pt=async({sourceFile:r,config:n})=>(n.rtl&&O(r),r);async function xt(r,n){if(!n)return r;let t=new Project({useInMemoryFileSystem:true}).createSourceFile("component.tsx",r,{scriptKind:ScriptKind.TSX,overwrite:true});return O(t),t.getText()}function L(r){return r.replace(/^["']|["']$/g,"")}function h(r){let n=L(r.getText()??"");r.replaceWithText(`"${q(n)}"`);}function q(r){return r.split(" ").flatMap(n=>{if(n.startsWith("rtl:")||n.startsWith("ltr:"))return [n];if(n===Q)return ["rtl:rotate-180"];let[e,t,i]=I(n);if(!t)return [n];for(let[s,l]of B)if(t.startsWith(s)){let d=t.replace(s,l),u=e?`rtl:${e}:${d}${i?`/${i}`:""}`:`rtl:${d}${i?`/${i}`:""}`;return [n,u]}for(let[s,l]of G)if(t.startsWith(s)){let d=e?`rtl:${e}:${l}`:`rtl:${l}`;return [n,d]}for(let[s,l]of X)if(t===s){let d=e?`rtl:${e}:${l}`:`rtl:${l}`;return [n,d]}for(let[s,l,d]of F)if(e?.includes(s)&&t.startsWith(l)){let u=t.replace(l,d);return [i?`${e}:${u}/${i}`:`${e}:${u}`]}let o=e?.includes("data-[side=left]")||e?.includes("data-[side=right]"),a=t;for(let[s,l]of V)if(!(o&&U.some(d=>s.startsWith(d)))&&t.startsWith(s)){if(!s.endsWith("-")&&t!==s)continue;a=t.replace(s,l);break}let f;return e?f=i?`${e}:${a}/${i}`:`${e}:${a}`:f=i?`${a}/${i}`:a,[f]}).join(" ")}function O(r){r.getDescendantsOfKind(SyntaxKind.CallExpression).filter(n=>n.getExpression().getText()==="cva").forEach(n=>{let e=n.getArguments()[0];e?.isKind(SyntaxKind.StringLiteral)&&h(e),n.getArguments()[1]?.isKind(SyntaxKind.ObjectLiteralExpression)&&n.getArguments()[1]?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).find(t=>t.getName()==="variants")?.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(t=>{t.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(i=>{let o=i.getInitializerIfKind(SyntaxKind.StringLiteral);o&&h(o);});});}),r.getDescendantsOfKind(SyntaxKind.JsxAttribute).forEach(n=>{if(n.getNameNode().getText()==="className"){let e=n.getInitializer();if(e?.isKind(SyntaxKind.StringLiteral)&&h(e),n.getInitializer()?.isKind(SyntaxKind.JsxExpression)){let t=n.getInitializer()?.getDescendantsOfKind(SyntaxKind.CallExpression).find(i=>i.getExpression().getText()==="cn");t&&t.getArguments().forEach(i=>{(i.isKind(SyntaxKind.ConditionalExpression)||i.isKind(SyntaxKind.BinaryExpression))&&i.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(h),i.isKind(SyntaxKind.StringLiteral)&&h(i);});}}n.getNameNode().getText()==="classNames"&&n.getInitializer()?.isKind(SyntaxKind.JsxExpression)&&n.getDescendantsOfKind(SyntaxKind.PropertyAssignment).forEach(e=>{if(e.getInitializer()?.isKind(SyntaxKind.CallExpression)){let i=e.getInitializerIfKind(SyntaxKind.CallExpression);i&&i.getArguments().forEach(o=>{o.isKind(SyntaxKind.ConditionalExpression)&&o.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(h),o.isKind(SyntaxKind.StringLiteral)&&h(o);});}let t=e.getInitializer();t?.isKind(SyntaxKind.StringLiteral)&&e.getNameNode().getText()!=="variant"&&h(t);});}),r.getDescendantsOfKind(SyntaxKind.CallExpression).filter(n=>n.getExpression().getText()==="mergeProps").forEach(n=>{let e=n.getArguments()[0];if(e?.isKind(SyntaxKind.ObjectLiteralExpression)){let t=e.getProperties().find(i=>i.isKind(SyntaxKind.PropertyAssignment)&&i.getName()==="className");if(t?.isKind(SyntaxKind.PropertyAssignment)){let i=t.getInitializer();i?.isKind(SyntaxKind.CallExpression)&&i.getExpression().getText()==="cn"&&i.getArguments().forEach(o=>{o.isKind(SyntaxKind.StringLiteral)&&h(o),(o.isKind(SyntaxKind.ConditionalExpression)||o.isKind(SyntaxKind.BinaryExpression))&&o.getChildrenOfKind(SyntaxKind.StringLiteral).forEach(h);}),i?.isKind(SyntaxKind.StringLiteral)&&h(i);}}}),[...r.getDescendantsOfKind(SyntaxKind.JsxSelfClosingElement),...r.getDescendantsOfKind(SyntaxKind.JsxOpeningElement)].forEach(n=>{let e=n.getTagNameNode().getText();if(!P.includes(e))return;let t=n.getAttributes().find(f=>f.isKind(SyntaxKind.JsxAttribute)&&f.getNameNode().getText()==="side");if(!t?.isKind(SyntaxKind.JsxAttribute))return;let i=t.getInitializer();if(!i?.isKind(SyntaxKind.StringLiteral))return;let o=L(i.getText()??""),a=C[o];a&&i.replaceWithText(`"${a}"`);}),r.getDescendantsOfKind(SyntaxKind.BindingElement).forEach(n=>{if(n.getNameNode().getText()!=="side")return;let i=n.getFirstAncestorByKind(SyntaxKind.FunctionDeclaration)?.getName();if(!i||!P.includes(i))return;let o=n.getInitializer();if(!o?.isKind(SyntaxKind.StringLiteral))return;let a=L(o.getText()??""),f=C[a];f&&o.replaceWithText(`"${f}"`);});}var D=[{marker:"cn-font-heading",utility:"font-heading",supportToken:"--font-heading:"}],w=/\bcn-font-heading\b/,v=new Map;async function Y(r,n=[]){let e=new Set(n);if(!r)return e;let t=v.get(r);return t||(t=promises.readFile(r,"utf8").then(i=>{let o=new Set;for(let a of D)i.includes(a.supportToken)&&o.add(a.marker);return o}).catch(()=>new Set),v.set(r,t)),(await t).forEach(i=>{e.add(i);}),e}function R(r,n){let e=r;for(let t of D)e.includes(t.marker)&&(e=e.replace(new RegExp(`\\b${t.marker}\\b`,"g"),n.has(t.marker)?t.utility:""));return e.replace(/\s+/g," ").trim()}function N(r,n){let e=r.getLiteralValue();if(!w.test(e))return;let t=R(e,n);t!==e&&r.setLiteralValue(t);}function y(r,n){for(let e of r.getDescendantsOfKind(SyntaxKind.StringLiteral))N(e,n);for(let e of r.getDescendantsOfKind(SyntaxKind.NoSubstitutionTemplateLiteral))N(e,n);}var At=async({sourceFile:r,config:n,supportedFontMarkers:e})=>{let t=await Y(n.resolvedPaths.tailwindCss,e),i=[];for(let o of r.getDescendantsOfKind(SyntaxKind.JsxAttribute)){let a=o.getNameNode().getText();if(a!=="className"&&a!=="classNames")continue;let f=o.getInitializer();if(f?.isKind(SyntaxKind.StringLiteral)){let s=f.getLiteralValue();if(w.test(s)){let l=R(s,t);l===""?i.push(o):l!==s&&f.setLiteralValue(l);}}f?.isKind(SyntaxKind.JsxExpression)&&y(f,t);}for(let o of i)o.remove();for(let o of r.getDescendantsOfKind(SyntaxKind.CallExpression)){if(o.getExpression().getText()==="cva"){for(let a of o.getArguments()){if(a.isKind(SyntaxKind.StringLiteral)){N(a,t);continue}if(a.isKind(SyntaxKind.NoSubstitutionTemplateLiteral)){N(a,t);continue}y(a,t);}continue}o.getExpression().getText()==="mergeProps"&&y(o,t);}return r};var et="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!",yt=async({sourceFile:r,config:n})=>{let e=n.menuColor,t=e==="default-translucent"||e==="inverted-translucent";for(let i of r.getDescendantsOfKind(SyntaxKind.JsxAttribute)){if(i.getNameNode().getText()!=="className")continue;let a=i.getInitializer();if(!a)continue;let f=a.getText();if(!f.includes("cn-menu-target")&&!f.includes("cn-menu-translucent"))continue;let s=f,l=false;e==="inverted"||e==="inverted-translucent"?s=s.replace(/cn-menu-target/g,"dark"):(s=s.replace(/cn-menu-target/g,""),l=true),t?s=s.replace(/"([^"]*cn-menu-translucent[^"]*)"/g,(d,u)=>`"${twMerge(u,et).replace(/\s*\bcn-menu-translucent\b\s*/g," ").trim()}"`):s.includes("cn-menu-translucent")&&(s=s.replace(/cn-menu-translucent/g,""),l=true),l&&(s=s.replace(/\s{2,}/g," "),s=s.replace(/"\s+/g,'"'),s=s.replace(/\s+"/g,'"'),s=s.replace(/,\s*""\s*,/g,","),s=s.replace(/\(\s*""\s*,/g,"("),s=s.replace(/,\s*""\s*\)/g,")")),i.setInitializer(s);}return r};export{ft as a,I as b,ot as c,pt as d,xt as e,At as f,yt as g};