shadcn-svelte
Version:
Add components to your apps.
1 lines • 2.73 kB
JavaScript
import{t as e}from"./magic-string.es-Ze7NMroB.mjs";import{twMerge as t}from"tailwind-merge";import{parse as n}from"svelte/compiler";function r(e,n,r){let i=e;return i=n===`inverted`||n===`inverted-translucent`?i.replace(/cn-menu-target/g,`dark`):i.replace(/cn-menu-target/g,``),i=r?t(i,`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!`).replace(/\s*\bcn-menu-translucent\b\s*/g,` `).trim():i.replace(/cn-menu-translucent/g,``),i=i.replace(/\s{2,}/g,` `).replace(/^\s+|\s+$/g,``),{newText:i}}function i(e,t){if(e)for(let n of e)t(n),i(n.fragment?.nodes??n.nodes,t)}const a=async({content:t,filePath:a,config:o})=>{let s=o.menuColor??`default`,c=s===`default-translucent`||s===`inverted-translucent`;if(!t.includes(`cn-menu-target`)&&!t.includes(`cn-menu-translucent`)||!a.endsWith(`.svelte`))return{content:t};let l;try{l=n(t,{filename:a,modern:!0})}catch{return{content:t}}let u=new e(t);i(l.fragment?.nodes,e=>{for(let n of e.attributes??[]){if(n.name!==`class`)continue;let e=n.value;if(e){if(Array.isArray(e)){let t=e.filter(e=>typeof e==`object`&&!!e&&`data`in e).map(e=>e.data??``).join(``);if(!t.includes(`cn-menu-target`)&&!t.includes(`cn-menu-translucent`))continue;let{newText:n}=r(t,s,c);for(let t of e)if(t.start!=null&&t.end!=null){u.overwrite(t.start,t.end,n);break}continue}if(typeof e==`object`&&e&&`expression`in e){let n=e.expression;if(!n||n.type!==`CallExpression`)continue;let i=n.arguments;if(!i)continue;let a=n.start,o=n.end;if(a==null||o==null)continue;let l=t.slice(a,o);if(!l.includes(`cn-menu-target`)&&!l.includes(`cn-menu-translucent`))continue;let d=[];for(let e of i){if(e.type!==`Literal`||typeof e.value!=`string`)continue;let t=e.value;if(!t.includes(`cn-menu-target`)&&!t.includes(`cn-menu-translucent`))continue;let{newText:n}=r(t,s,c);if(e.start!=null&&e.end!=null){let r=(e.raw??JSON.stringify(t)).startsWith(`'`)?`'`:`"`;d.push({start:e.start,end:e.end,replacement:n===``?`""`:`${r}${n}${r}`})}}for(let e of d)u.overwrite(e.start,e.end,e.replacement)}}}});let d=u.toString();return d=d.replace(/,\s*""\s*,/g,`,`),d=d.replace(/\(\s*""\s*,\s*/g,`(`),d=d.replace(/,\s*""\s*\)/g,`)`),d=d.replace(/cn\s*\(\s*\)/g,`cn()`),{content:d}};export{a as t};