@salty-css/vite 0.0.1-alpha.191 → 0.0.1-alpha.192
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/index.cjs +9 -9
- package/index.js +40 -39
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const $e=require("esbuild"),be=require("child_process"),l=require("path"),u=require("fs"),K=require("fs/promises"),q=require("winston");var v=typeof document<"u"?document.currentScript:null;function we(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ce=we($e),oe=e=>String.fromCharCode(e+(e>25?39:97)),Fe=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=oe(n%52)+s;return s=oe(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Ce=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},z=(e,t=5)=>{const s=Ce(5381,JSON.stringify(e))>>>0;return Fe(s,t)};function M(e){return e?typeof e!="string"?M(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const Ne=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:i,transform:a}=n;e=e.replace(i,c=>{const{value:p,css:r}=a(c);return r&&s.push(r),p})}),{result:e,additionalCss:s}},ae=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${M(n[1].replaceAll(".","-"))})`)}:{result:e},R=(e,t,s)=>{if(!e)return"";const n=[],i=Object.entries(e).reduce((c,[p,r])=>{const o=p.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return c;if(o==="variants")return Object.entries(r).forEach(([_,$])=>{$&&Object.entries($).forEach(([O,f])=>{if(!f)return;const m=`${t}.${_}-${O}`,b=R(f,m);n.push(b)})}),c;if(o==="defaultVariants")return c;if(o==="compoundVariants")return r.forEach(_=>{const{css:$,...O}=_,f=Object.entries(O).reduce((b,[d,x])=>`${b}.${d}-${x}`,t),m=R($,f);n.push(m)}),c;if(o.startsWith("@")){const _=R(r,t),$=`${o} {
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const $e=require("esbuild"),be=require("child_process"),l=require("path"),u=require("fs"),K=require("fs/promises"),q=require("winston");var v=typeof document<"u"?document.currentScript:null;function we(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const ce=we($e),oe=e=>String.fromCharCode(e+(e>25?39:97)),Fe=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=oe(n%52)+s;return s=oe(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Ce=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},z=(e,t=5)=>{const s=Ce(5381,JSON.stringify(e))>>>0;return Fe(s,t)};function M(e){return e?typeof e!="string"?M(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const Ne=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:i,transform:a}=n;e=e.replace(i,c=>{const{value:p,css:r}=a(c);return r&&s.push(r),p})}),{result:e,additionalCss:s}},ae=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${M(n[1].replaceAll(".","-"))})`)}:{result:e},R=(e,t,s)=>{if(!e)return"";const n=[],i=Object.entries(e).reduce((c,[p,r])=>{const o=p.trim(),h=o.startsWith("-")?o:M(o),g=(F,N=";")=>c=`${c}${F}${N}`,y=F=>g(`${h}:${F}`);if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return c;if(r.isColor)return y(r.toString()),c;if(o==="variants")return Object.entries(r).forEach(([_,$])=>{$&&Object.entries($).forEach(([O,f])=>{if(!f)return;const m=`${t}.${_}-${O}`,b=R(f,m);n.push(b)})}),c;if(o==="defaultVariants")return c;if(o==="compoundVariants")return r.forEach(_=>{const{css:$,...O}=_,f=Object.entries(O).reduce((b,[d,x])=>`${b}.${d}-${x}`,t),m=R($,f);n.push(m)}),c;if(o.startsWith("@")){const _=R(r,t),$=`${o} {
|
2
2
|
${_.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return n.push($),c}const F=p.includes("&")?o.replace("&",t):o.startsWith(":")?`${t}${o}`:`${t} ${o}`,N=R(r,F);return n.push(N),c}
|
5
|
+
}`;return n.push($),c}const F=p.includes("&")?o.replace("&",t):o.startsWith(":")?`${t}${o}`:`${t} ${o}`,N=R(r,F);return n.push(N),c}if(typeof r=="number")return y(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return c;const{modifiers:j}={},D=function*(){yield ae(r),yield Ne(r,j)}();for(const{result:F,additionalCss:N=[]}of D)r=F,N.forEach(_=>{const $=R(_,"");g($,"")});return y(r)},"");return i?t?[`${t} { ${i} }`,...n].join(`
|
6
6
|
`):i:n.join(`
|
7
7
|
`)},le=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([i,a])=>{if(typeof a=="object"){if(!a)return;const c=i.trim(),p=le(a,[...t,c]);s.push(p)}else n[i]=a}),Object.keys(n).length){const i=t.map(M).join("-"),a=R(n,`.${i}`);s.push(a)}return s.join(`
|
8
|
-
`)},xe=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=fe(n).map(i=>`"${i}"`).join(" | ")),t),{}):{},fe=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const a=t?`${t}.${n}`:n;return typeof i=="object"?fe(i,a,s):s.add(t)}),[...s]):[],ue=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=l.join(e,"package.json");return u.existsSync(t)?t:ue(l.join(e,".."))},ke=async e=>{const t=ue(e);return await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Pe=async e=>{const t=await ke(e);if(t)return t.type};let A;const de=async e=>{if(A)return A;const t=await Pe(e);return t==="module"?A="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:v&&v.tagName.toUpperCase()==="SCRIPT"&&v.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},ee=q.createLogger({level:"debug",format:q.format.combine(q.format.colorize(),q.format.cli()),transports:[new q.transports.Console({})]});function pe(e){return e?typeof e!="string"?pe(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const _e={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},W=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),E={externalModules:[],rcFile:void 0,destDir:void 0},ye=e=>{if(E.externalModules.length>0)return E.externalModules;const s=u.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return E.externalModules=n,n},J=async e=>{if(E.destDir)return E.destDir;const t=await te(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},ge=["salty","css","styles","styled"],De=(e=[])=>new RegExp(`\\.(${[...ge,...e].join("|")})\\.`),Z=(e,t=[])=>De(t).test(e),he=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=l.join(e,".saltyrc.json"),s=await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):he(l.join(e,".."))},te=async e=>{var n,i;const t=await he(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((i=t.projects)==null?void 0:i.find(a=>a.dir===t.defaultProject))},Te=async e=>{const t=await te(e),s=await J(e),n=l.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),i=l.join(s,"salty.config.js"),a=await de(e),c=ye(n);await ce.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:a,external:c});const p=Date.now(),{config:r}=await import(`${i}?t=${p}`);return r},Oe=async(e,t)=>{var H,G;const s=await Te(e),n={...s},i=new Set,a=(C,k=[])=>C?Object.entries(C).flatMap(([V,T])=>{if(!T)return;if(typeof T=="object")return a(T,[...k,V]);const U=pe(V),Q=M(V),X=[...k,U].join(".");i.add(`"${X}"`);const Y=[...k.map(M),Q].join("-"),{result:je}=ae(T);return`--${Y}: ${je};`}):[],c=C=>C?Object.entries(C).flatMap(([k,V])=>{const T=a(V);return k==="base"?T.join(""):`${k} { ${T.join("")} }`}):[],p=C=>C?Object.entries(C).flatMap(([k,V])=>Object.entries(V).flatMap(([T,U])=>{const Q=a(U,[k]),X=`.${k}-${T}, [data-${k}="${T}"]`,Y=Q.join("");return`${X} { ${Y} }`})):[],r=C=>({...C,responsive:void 0,conditional:void 0}),o=C=>t.variables.map(k=>C==="static"?r(k._current):k._current[C]),h=a(W(r(s.variables),o("static"))),
|
8
|
+
`)},xe=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=fe(n).map(i=>`"${i}"`).join(" | ")),t),{}):{},fe=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const a=t?`${t}.${n}`:n;return typeof i=="object"?fe(i,a,s):s.add(t)}),[...s]):[],ue=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=l.join(e,"package.json");return u.existsSync(t)?t:ue(l.join(e,".."))},ke=async e=>{const t=ue(e);return await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Pe=async e=>{const t=await ke(e);if(t)return t.type};let A;const de=async e=>{if(A)return A;const t=await Pe(e);return t==="module"?A="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:v&&v.tagName.toUpperCase()==="SCRIPT"&&v.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},ee=q.createLogger({level:"debug",format:q.format.combine(q.format.colorize(),q.format.cli()),transports:[new q.transports.Console({})]});function pe(e){return e?typeof e!="string"?pe(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const _e={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},W=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),E={externalModules:[],rcFile:void 0,destDir:void 0},ye=e=>{if(E.externalModules.length>0)return E.externalModules;const s=u.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return E.externalModules=n,n},J=async e=>{if(E.destDir)return E.destDir;const t=await te(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},ge=["salty","css","styles","styled"],De=(e=[])=>new RegExp(`\\.(${[...ge,...e].join("|")})\\.`),Z=(e,t=[])=>De(t).test(e),he=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=l.join(e,".saltyrc.json"),s=await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):he(l.join(e,".."))},te=async e=>{var n,i;const t=await he(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((i=t.projects)==null?void 0:i.find(a=>a.dir===t.defaultProject))},Te=async e=>{const t=await te(e),s=await J(e),n=l.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),i=l.join(s,"salty.config.js"),a=await de(e),c=ye(n);await ce.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:a,external:c});const p=Date.now(),{config:r}=await import(`${i}?t=${p}`);return r},Oe=async(e,t)=>{var H,G;const s=await Te(e),n={...s},i=new Set,a=(C,k=[])=>C?Object.entries(C).flatMap(([V,T])=>{if(!T)return;if(typeof T=="object")return a(T,[...k,V]);const U=pe(V),Q=M(V),X=[...k,U].join(".");i.add(`"${X}"`);const Y=[...k.map(M),Q].join("-"),{result:je}=ae(T);return`--${Y}: ${je};`}):[],c=C=>C?Object.entries(C).flatMap(([k,V])=>{const T=a(V);return k==="base"?T.join(""):`${k} { ${T.join("")} }`}):[],p=C=>C?Object.entries(C).flatMap(([k,V])=>Object.entries(V).flatMap(([T,U])=>{const Q=a(U,[k]),X=`.${k}-${T}, [data-${k}="${T}"]`,Y=Q.join("");return`${X} { ${Y} }`})):[],r=C=>({...C,responsive:void 0,conditional:void 0}),o=C=>t.variables.map(k=>C==="static"?r(k._current):k._current[C]),h=a(W(r(s.variables),o("static"))),g=c(W((H=s.variables)==null?void 0:H.responsive,o("responsive"))),y=p(W((G=s.variables)==null?void 0:G.conditional,o("conditional"))),j=await J(e),P=l.join(j,"css/_variables.css"),D=`:root { ${h.join("")} ${g.join("")} } ${y.join("")}`;u.writeFileSync(P,D);const F=l.join(j,"css/_global.css"),N=W(s.global,t.globalStyles),_=R(N,"");u.writeFileSync(F,`@layer global { ${_} }`);const $=l.join(j,"css/_reset.css"),f=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:_e,m=R(f,"");u.writeFileSync($,`@layer reset { ${m} }`);const b=l.join(j,"css/_templates.css"),d=W(s.templates,t.templates),x=le(d),w=xe(d);u.writeFileSync(b,x),n.templates=d;const S=l.join(j,"types/css-tokens.d.ts"),I=`
|
9
9
|
// Variable types
|
10
10
|
type VariableTokens = ${[...i].join("|")};
|
11
11
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
@@ -15,23 +15,23 @@
|
|
15
15
|
${Object.entries(w).map(([C,k])=>`${C}?: ${k}`).join(`
|
16
16
|
`)}
|
17
17
|
}
|
18
|
-
`;u.writeFileSync(S,I);const B=l.join(j,"cache/config-cache.json");u.writeFileSync(B,JSON.stringify(n,null,2))},re=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(e))return t;const c=i.exec(e);if(c){const p=c.at(1);if(ge.some(o=>p==null?void 0:p.includes(o)))return t}return"styled('div',"}),se=async(e,t,s)=>{const n=z(t),i=l.join(s,"./temp");u.existsSync(i)||u.mkdirSync(i);const a=l.parse(t);let c=u.readFileSync(t,"utf8");c=re(c);const p=l.join(s,"js",n+".js"),r=await te(e),o=l.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),h=ye(o),
|
18
|
+
`;u.writeFileSync(S,I);const B=l.join(j,"cache/config-cache.json");u.writeFileSync(B,JSON.stringify(n,null,2))},re=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(e))return t;const c=i.exec(e);if(c){const p=c.at(1);if(ge.some(o=>p==null?void 0:p.includes(o)))return t}return"styled('div',"}),se=async(e,t,s)=>{const n=z(t),i=l.join(s,"./temp");u.existsSync(i)||u.mkdirSync(i);const a=l.parse(t);let c=u.readFileSync(t,"utf8");c=re(c);const p=l.join(s,"js",n+".js"),r=await te(e),o=l.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),h=ye(o),g=await de(e);await ce.build({stdin:{contents:c,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:g,target:["node20"],keepNames:!0,external:h,packages:"external",plugins:[{name:"test",setup:P=>{P.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},D=>{const F=u.readFileSync(D.path,"utf8");return{contents:re(F),loader:"ts"}})}}]});const y=Date.now();return await import(`${p}?t=${y}`)},Ee=async e=>{const t=await J(e),s=l.join(t,"cache/config-cache.json"),n=u.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ne=async e=>{const t=await Ee(e),s=await J(e),n=l.join(s,"salty.config.js"),i=Date.now(),{config:a}=await import(`${n}?t=${i}`);return W(a,t)},me=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Me=async(e,t=me(),s=!0)=>{try{const n=Date.now();t?ee.info("Generating CSS in production mode! 🔥"):ee.info("Generating CSS in development mode! 🚀");const i=[],a=[],c=await J(e),p=l.join(c,"index.css");s&&(()=>{u.existsSync(c)&&be.execSync("rm -rf "+c),u.mkdirSync(c,{recursive:!0}),u.mkdirSync(l.join(c,"css")),u.mkdirSync(l.join(c,"types")),u.mkdirSync(l.join(c,"js")),u.mkdirSync(l.join(c,"cache"))})();const o={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],templates:[],components:[],classNames:[]};async function h(f){const m=["node_modules","saltygen"],b=u.statSync(f);if(b.isDirectory()){const d=u.readdirSync(f);if(m.some(w=>f.includes(w)))return;await Promise.all(d.map(w=>h(l.join(f,w))))}else if(b.isFile()&&Z(f)){const x=await se(e,f,c);Object.entries(x).forEach(([w,S])=>{S.isKeyframes?o.keyframes.push({value:S,src:f,name:w}):S.isMedia?o.mediaQueries.push(S):S.isGlobalDefine?o.globalStyles.push(S):S.isDefineVariables?o.variables.push(S):S.isDefineTemplates?o.templates.push(S):S.isClassName?o.classNames.push({...S,src:f,name:w}):S.generator&&o.components.push({...S,src:f,name:w})})}}await h(e),await Oe(e,o);const g=await ne(e);for(const f of o.keyframes){const{value:m}=f,b=`a_${m.animationName}.css`,d=`css/${b}`,x=l.join(c,d);i.push(b),u.writeFileSync(x,m.css)}const y={};for(const f of o.components){const{src:m,name:b}=f,d=f.generator._withBuildContext({callerName:b,isProduction:t,config:g});a[d.priority]||(a[d.priority]=[]),a[d.priority].push(d.cssFileName);const x=`css/${d.cssFileName}`,w=l.join(c,x);u.writeFileSync(w,d.css),g.importStrategy==="component"&&(y[m]?y[m].push(d.cssFileName):y[m]=[d.cssFileName])}for(const f of o.classNames){const{src:m,name:b}=f,d=f.generator._withBuildContext({callerName:b,isProduction:t,config:g});a[0].push(d.cssFileName);const x=`css/${d.cssFileName}`,w=l.join(c,x);u.writeFileSync(w,d.css),g.importStrategy==="component"&&(y[m]?y[m].push(d.cssFileName):y[m]=[d.cssFileName])}g.importStrategy==="component"&&Object.entries(y).forEach(([f,m])=>{const b=m.map(L=>`@import url('./${L}');`).join(`
|
19
19
|
`),d=z(f,6),x=l.parse(f),w=M(x.name),S=l.join(c,`css/f_${w}-${d}.css`);u.writeFileSync(S,b)});const j=i.map(f=>`@import url('./css/${f}');`).join(`
|
20
20
|
`);let N=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
21
21
|
|
22
22
|
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return u.readFileSync(l.join(c,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
23
23
|
`)}
|
24
|
-
${j}`;if(
|
24
|
+
${j}`;if(g.importStrategy!=="component"){const f=a.reduce((m,b,d)=>{const x=b.reduce((I,B)=>{var k;const H=l.join(c,"css",B),G=u.readFileSync(H,"utf8"),C=((k=/.*-([^-]+)-\d+.css/.exec(B))==null?void 0:k.at(1))||z(H,6);return I.includes(C)?I:`${I}
|
25
25
|
/*start:${C}*/
|
26
26
|
${G}
|
27
27
|
/*end:${C}*/
|
28
28
|
`},""),w=`l_${d}.css`,S=l.join(c,"css",w),L=`@layer l${d} { ${x}
|
29
29
|
}`;return u.writeFileSync(S,L),`${m}
|
30
|
-
@import url('./css/${w}');`},"");N+=f}u.writeFileSync(p,N);const $=Date.now()-n,O=$<200?"🔥":$<500?"🚀":$<1e3?"🎉":$<2e3?"🚗":$<5e3?"🤔":"🥴";ee.info(`Generated CSS in ${$}ms! ${O}`)}catch(n){console.error(n)}},Re=async(e,t)=>{try{const s=await J(e);if(Z(t)){const i=[],a=await ne(e),c=await se(e,t,s);if(Object.entries(c).forEach(([p,r])=>{if(r.isKeyframes&&r.css){const j=`css/${`a_${r.animationName}.css`}`,P=l.join(s,j);u.writeFileSync(P,r.css);return}if(r.isClassName){const
|
30
|
+
@import url('./css/${w}');`},"");N+=f}u.writeFileSync(p,N);const $=Date.now()-n,O=$<200?"🔥":$<500?"🚀":$<1e3?"🎉":$<2e3?"🚗":$<5e3?"🤔":"🥴";ee.info(`Generated CSS in ${$}ms! ${O}`)}catch(n){console.error(n)}},Re=async(e,t)=>{try{const s=await J(e);if(Z(t)){const i=[],a=await ne(e),c=await se(e,t,s);if(Object.entries(c).forEach(([p,r])=>{if(r.isKeyframes&&r.css){const j=`css/${`a_${r.animationName}.css`}`,P=l.join(s,j);u.writeFileSync(P,r.css);return}if(r.isClassName){const y=r.factory._withBuildContext({name:p});i[0].push(y.cssFileName);const j=`css/${y.cssFileName}`,P=l.join(s,j);u.writeFileSync(P,y.css)}if(!r.generator)return;const o=r.generator._withBuildContext({name:p,config:a}),h=`css/${o.cssFileName}`,g=l.join(s,h);u.writeFileSync(g,o.css),i[o.priority]||(i[o.priority]=[]),i[o.priority].push(o.cssFileName)}),a.importStrategy!=="component")i.forEach((p,r)=>{const o=`l_${r}.css`,h=l.join(s,"css",o);let g=u.readFileSync(h,"utf8");p.forEach(y=>{var F;const j=l.join(s,"css",y),P=((F=/.*-([^-]+)-\d+.css/.exec(y))==null?void 0:F.at(1))||z(j,6);if(!g.includes(P)){const N=u.readFileSync(j,"utf8"),_=`/*start:${P}*/
|
31
31
|
${N}
|
32
32
|
/*end:${P}*/
|
33
|
-
`;
|
33
|
+
`;g=`${g.replace(/\}$/,"")}
|
34
34
|
${_}
|
35
|
-
}`}}),u.writeFileSync(h,
|
36
|
-
`),r=z(t,6),o=l.parse(t),h=M(o.name),
|
35
|
+
}`}}),u.writeFileSync(h,g)});else{const p=i.flat().map(y=>`@import url('./${y}');`).join(`
|
36
|
+
`),r=z(t,6),o=l.parse(t),h=M(o.name),g=l.join(s,`css/f_${h}-${r}.css`);u.writeFileSync(g,p)}}}catch(s){console.error(s)}},Ve=async(e,t,s=me())=>{try{const n=await J(e);if(Z(t)){const a=u.readFileSync(t,"utf8");a.replace(/^(?!export\s)const\s.*/gm,h=>`export ${h}`)!==a&&await K.writeFile(t,a);const p=await ne(e),r=await se(e,t,n);let o=a;if(Object.entries(r).forEach(([h,g])=>{var w;if(g.isKeyframes||!g.generator)return;const y=g.generator._withBuildContext({name:h,config:p,prod:s}),j=new RegExp(`\\s${h}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!j)return console.error("Could not find the original declaration");const P=(w=j.at(1))==null?void 0:w.trim(),D=new RegExp(`\\s${h}[=\\s]+styled\\(`,"g").exec(o);if(!D)return console.error("Could not find the original declaration");const{index:F}=D;let N=!1;const _=setTimeout(()=>N=!0,5e3);let $=0,O=!1,f=0;for(;!O&&!N;){const S=o[F+$];S==="("&&f++,S===")"&&f--,f===0&&S===")"&&(O=!0),$>o.length&&(N=!0),$++}if(!N)clearTimeout(_);else throw new Error("Failed to find the end of the styled call and timed out");const m=F+$,b=o.slice(F,m),d=o,x=` ${h} = styled(${P}, "${y.classNames}", ${JSON.stringify(y.clientProps)});`;o=o.replace(b,x),d===o&&console.error("Minimize file failed to change content",{name:h,tagName:P})}),p.importStrategy==="component"){const h=z(t,6),g=l.parse(t);o=`import '../../saltygen/css/${`f_${M(g.name)}-${h}.css`}';
|
37
37
|
${o}`}return o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}},ie=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!Z(e))return!1;const n=await K.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Se=e=>({name:"stylegen",buildStart:()=>Me(e),load:async t=>{if(Z(t))return await Ve(e,t)},handleHotUpdate:async({file:t,server:s})=>{await ie(t)&&await s.restart()},watchChange:{handler:async t=>{Z(t)&&(await ie(t)||await Re(e,t))}}});exports.default=Se;exports.saltyPlugin=Se;
|
package/index.js
CHANGED
@@ -33,9 +33,11 @@ const Et = (t, e) => {
|
|
33
33
|
}, ut = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${M(n[1].replaceAll(".", "-"))})`) } : { result: t }, R = (t, e, s) => {
|
34
34
|
if (!t) return "";
|
35
35
|
const n = [], i = Object.entries(t).reduce((c, [p, r]) => {
|
36
|
-
const o = p.trim();
|
36
|
+
const o = p.trim(), h = o.startsWith("-") ? o : M(o), g = (C, F = ";") => c = `${c}${C}${F}`, d = (C) => g(`${h}:${C}`);
|
37
37
|
if (typeof r == "function" && (r = r()), typeof r == "object") {
|
38
38
|
if (!r) return c;
|
39
|
+
if (r.isColor)
|
40
|
+
return d(r.toString()), c;
|
39
41
|
if (o === "variants")
|
40
42
|
return Object.entries(r).forEach(([D, b]) => {
|
41
43
|
b && Object.entries(b).forEach(([T, l]) => {
|
@@ -62,8 +64,7 @@ const Et = (t, e) => {
|
|
62
64
|
const C = p.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, F = R(r, C);
|
63
65
|
return n.push(F), c;
|
64
66
|
}
|
65
|
-
|
66
|
-
if (typeof r == "number") return g(r);
|
67
|
+
if (typeof r == "number") return d(r);
|
67
68
|
if (typeof r != "string")
|
68
69
|
if ("toString" in r) r = r.toString();
|
69
70
|
else return c;
|
@@ -73,9 +74,9 @@ const Et = (t, e) => {
|
|
73
74
|
for (const { result: C, additionalCss: F = [] } of E)
|
74
75
|
r = C, F.forEach((D) => {
|
75
76
|
const b = R(D, "");
|
76
|
-
|
77
|
+
g(b, "");
|
77
78
|
});
|
78
|
-
return
|
79
|
+
return d(r);
|
79
80
|
}, "");
|
80
81
|
return i ? e ? [`${e} { ${i} }`, ...n].join(`
|
81
82
|
`) : i : n.join(`
|
@@ -223,7 +224,7 @@ const Vt = {
|
|
223
224
|
}) : [], p = (j) => j ? Object.entries(j).flatMap(([x, J]) => Object.entries(J).flatMap(([_, U]) => {
|
224
225
|
const X = a(U, [x]), Y = `.${x}-${_}, [data-${x}="${_}"]`, v = X.join("");
|
225
226
|
return `${Y} { ${v} }`;
|
226
|
-
})) : [], r = (j) => ({ ...j, responsive: void 0, conditional: void 0 }), o = (j) => e.variables.map((x) => j === "static" ? r(x._current) : x._current[j]), h = a(Z(r(s.variables), o("static"))),
|
227
|
+
})) : [], r = (j) => ({ ...j, responsive: void 0, conditional: void 0 }), o = (j) => e.variables.map((x) => j === "static" ? r(x._current) : x._current[j]), h = a(Z(r(s.variables), o("static"))), g = c(Z((G = s.variables) == null ? void 0 : G.responsive, o("responsive"))), d = p(Z((q = s.variables) == null ? void 0 : q.conditional, o("conditional"))), $ = await A(t), P = f($, "css/_variables.css"), E = `:root { ${h.join("")} ${g.join("")} } ${d.join("")}`;
|
227
228
|
k(P, E);
|
228
229
|
const C = f($, "css/_global.css"), F = Z(s.global, e.globalStyles), D = R(F, "");
|
229
230
|
k(C, `@layer global { ${D} }`);
|
@@ -261,7 +262,7 @@ const Vt = {
|
|
261
262
|
const a = Q(e);
|
262
263
|
let c = V(e, "utf8");
|
263
264
|
c = at(c);
|
264
|
-
const p = f(s, "js", n + ".js"), r = await ot(t), o = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), h = yt(o),
|
265
|
+
const p = f(s, "js", n + ".js"), r = await ot(t), o = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), h = yt(o), g = await ht(t);
|
265
266
|
await ft.build({
|
266
267
|
stdin: {
|
267
268
|
contents: c,
|
@@ -273,7 +274,7 @@ const Vt = {
|
|
273
274
|
treeShaking: !0,
|
274
275
|
bundle: !0,
|
275
276
|
outfile: p,
|
276
|
-
format:
|
277
|
+
format: g,
|
277
278
|
target: ["node20"],
|
278
279
|
keepNames: !0,
|
279
280
|
external: h,
|
@@ -290,8 +291,8 @@ const Vt = {
|
|
290
291
|
}
|
291
292
|
]
|
292
293
|
});
|
293
|
-
const
|
294
|
-
return await import(`${p}?t=${
|
294
|
+
const d = Date.now();
|
295
|
+
return await import(`${p}?t=${d}`);
|
295
296
|
}, At = async (t) => {
|
296
297
|
const e = await A(t), s = f(e, "cache/config-cache.json"), n = V(s, "utf8");
|
297
298
|
if (!n) throw new Error("Could not find config cache file");
|
@@ -348,33 +349,33 @@ const Vt = {
|
|
348
349
|
}
|
349
350
|
}
|
350
351
|
await h(t), await Jt(t, o);
|
351
|
-
const
|
352
|
+
const g = await it(t);
|
352
353
|
for (const l of o.keyframes) {
|
353
354
|
const { value: m } = l, w = `a_${m.animationName}.css`, u = `css/${w}`, N = f(c, u);
|
354
355
|
i.push(w), k(N, m.css);
|
355
356
|
}
|
356
|
-
const
|
357
|
+
const d = {};
|
357
358
|
for (const l of o.components) {
|
358
359
|
const { src: m, name: w } = l, u = l.generator._withBuildContext({
|
359
360
|
callerName: w,
|
360
361
|
isProduction: e,
|
361
|
-
config:
|
362
|
+
config: g
|
362
363
|
});
|
363
364
|
a[u.priority] || (a[u.priority] = []), a[u.priority].push(u.cssFileName);
|
364
365
|
const N = `css/${u.cssFileName}`, S = f(c, N);
|
365
|
-
k(S, u.css),
|
366
|
+
k(S, u.css), g.importStrategy === "component" && (d[m] ? d[m].push(u.cssFileName) : d[m] = [u.cssFileName]);
|
366
367
|
}
|
367
368
|
for (const l of o.classNames) {
|
368
369
|
const { src: m, name: w } = l, u = l.generator._withBuildContext({
|
369
370
|
callerName: w,
|
370
371
|
isProduction: e,
|
371
|
-
config:
|
372
|
+
config: g
|
372
373
|
});
|
373
374
|
a[0].push(u.cssFileName);
|
374
375
|
const N = `css/${u.cssFileName}`, S = f(c, N);
|
375
|
-
k(S, u.css),
|
376
|
+
k(S, u.css), g.importStrategy === "component" && (d[m] ? d[m].push(u.cssFileName) : d[m] = [u.cssFileName]);
|
376
377
|
}
|
377
|
-
|
378
|
+
g.importStrategy === "component" && Object.entries(d).forEach(([l, m]) => {
|
378
379
|
const w = m.map((L) => `@import url('./${L}');`).join(`
|
379
380
|
`), u = H(l, 6), N = Q(l), S = M(N.name), y = f(c, `css/f_${S}-${u}.css`);
|
380
381
|
k(y, w);
|
@@ -392,7 +393,7 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) =
|
|
392
393
|
}).map((l) => `@import url('./css/${l}');`).join(`
|
393
394
|
`)}
|
394
395
|
${$}`;
|
395
|
-
if (
|
396
|
+
if (g.importStrategy !== "component") {
|
396
397
|
const l = a.reduce((m, w, u) => {
|
397
398
|
const N = w.reduce((B, K) => {
|
398
399
|
var x;
|
@@ -427,41 +428,41 @@ ${q}
|
|
427
428
|
return;
|
428
429
|
}
|
429
430
|
if (r.isClassName) {
|
430
|
-
const
|
431
|
+
const d = r.factory._withBuildContext({
|
431
432
|
name: p
|
432
433
|
});
|
433
|
-
i[0].push(
|
434
|
-
const $ = `css/${
|
435
|
-
k(P,
|
434
|
+
i[0].push(d.cssFileName);
|
435
|
+
const $ = `css/${d.cssFileName}`, P = f(s, $);
|
436
|
+
k(P, d.css);
|
436
437
|
}
|
437
438
|
if (!r.generator) return;
|
438
439
|
const o = r.generator._withBuildContext({
|
439
440
|
name: p,
|
440
441
|
config: a
|
441
|
-
}), h = `css/${o.cssFileName}`,
|
442
|
-
k(
|
442
|
+
}), h = `css/${o.cssFileName}`, g = f(s, h);
|
443
|
+
k(g, o.css), i[o.priority] || (i[o.priority] = []), i[o.priority].push(o.cssFileName);
|
443
444
|
}), a.importStrategy !== "component")
|
444
445
|
i.forEach((p, r) => {
|
445
446
|
const o = `l_${r}.css`, h = f(s, "css", o);
|
446
|
-
let
|
447
|
-
p.forEach((
|
447
|
+
let g = V(h, "utf8");
|
448
|
+
p.forEach((d) => {
|
448
449
|
var C;
|
449
|
-
const $ = f(s, "css",
|
450
|
-
if (!
|
450
|
+
const $ = f(s, "css", d), P = ((C = /.*-([^-]+)-\d+.css/.exec(d)) == null ? void 0 : C.at(1)) || H($, 6);
|
451
|
+
if (!g.includes(P)) {
|
451
452
|
const F = V($, "utf8"), D = `/*start:${P}*/
|
452
453
|
${F}
|
453
454
|
/*end:${P}*/
|
454
455
|
`;
|
455
|
-
|
456
|
+
g = `${g.replace(/\}$/, "")}
|
456
457
|
${D}
|
457
458
|
}`;
|
458
459
|
}
|
459
|
-
}), k(h,
|
460
|
+
}), k(h, g);
|
460
461
|
});
|
461
462
|
else {
|
462
|
-
const p = i.flat().map((
|
463
|
-
`), r = H(e, 6), o = Q(e), h = M(o.name),
|
464
|
-
k(
|
463
|
+
const p = i.flat().map((d) => `@import url('./${d}');`).join(`
|
464
|
+
`), r = H(e, 6), o = Q(e), h = M(o.name), g = f(s, `css/f_${h}-${r}.css`);
|
465
|
+
k(g, p);
|
465
466
|
}
|
466
467
|
}
|
467
468
|
} catch (s) {
|
@@ -475,10 +476,10 @@ ${D}
|
|
475
476
|
a.replace(/^(?!export\s)const\s.*/gm, (h) => `export ${h}`) !== a && await Nt(e, a);
|
476
477
|
const p = await it(t), r = await rt(t, e, n);
|
477
478
|
let o = a;
|
478
|
-
if (Object.entries(r).forEach(([h,
|
479
|
+
if (Object.entries(r).forEach(([h, g]) => {
|
479
480
|
var S;
|
480
|
-
if (
|
481
|
-
const
|
481
|
+
if (g.isKeyframes || !g.generator) return;
|
482
|
+
const d = g.generator._withBuildContext({
|
482
483
|
name: h,
|
483
484
|
config: p,
|
484
485
|
prod: s
|
@@ -496,11 +497,11 @@ ${D}
|
|
496
497
|
}
|
497
498
|
if (!F) clearTimeout(D);
|
498
499
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
499
|
-
const m = C + b, w = o.slice(C, m), u = o, N = ` ${h} = styled(${P}, "${
|
500
|
+
const m = C + b, w = o.slice(C, m), u = o, N = ` ${h} = styled(${P}, "${d.classNames}", ${JSON.stringify(d.clientProps)});`;
|
500
501
|
o = o.replace(w, N), u === o && console.error("Minimize file failed to change content", { name: h, tagName: P });
|
501
502
|
}), p.importStrategy === "component") {
|
502
|
-
const h = H(e, 6),
|
503
|
-
o = `import '../../saltygen/css/${`f_${M(
|
503
|
+
const h = H(e, 6), g = Q(e);
|
504
|
+
o = `import '../../saltygen/css/${`f_${M(g.name)}-${h}.css`}';
|
504
505
|
${o}`;
|
505
506
|
}
|
506
507
|
return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/vite",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.192",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -34,6 +34,6 @@
|
|
34
34
|
}
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@salty-css/core": "^0.0.1-alpha.
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.192"
|
38
38
|
}
|
39
39
|
}
|