@salty-css/vite 0.0.1-alpha.243 → 0.0.1-alpha.244
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 +14 -14
- package/index.js +5 -4
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
"use strict";var Rt=Object.defineProperty;var Mt=(t,e,s)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var st=(t,e,s)=>Mt(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const vt=require("esbuild"),zt=require("child_process"),c=require("path"),d=require("fs"),dt=require("fs/promises"),B=require("winston"),lt=require("typescript");var ft=typeof document<"u"?document.currentScript:null;function Jt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const jt=Jt(vt),$t=t=>String.fromCharCode(t+(t>25?39:97)),Wt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},At=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=At(5381,JSON.stringify(t))>>>0;return Wt(s,e)};function v(t){return t?typeof t!="string"?v(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const qt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:
|
1
|
+
"use strict";var Rt=Object.defineProperty;var Mt=(t,e,s)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var st=(t,e,s)=>Mt(t,typeof e!="symbol"?e+"":e,s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const vt=require("esbuild"),zt=require("child_process"),c=require("path"),d=require("fs"),dt=require("fs/promises"),B=require("winston"),lt=require("typescript");var ft=typeof document<"u"?document.currentScript:null;function Jt(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const jt=Jt(vt),$t=t=>String.fromCharCode(t+(t>25?39:97)),Wt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},At=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=At(5381,JSON.stringify(t))>>>0;return Wt(s,e)};function v(t){return t?typeof t!="string"?v(String(t)):t.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const qt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:i}=o;s=s.replace(r,y=>{const{value:b,css:m}=i(y);return m&&n.push(m),b})}),{transformed:s,additionalCss:n}},Ft=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${v(o[1].replaceAll(".","-"))})`)},It=Ft(),Ht=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Lt=(t,e,s)=>Ht.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,Qt=["Webkit","Moz","ms","O"],Gt=t=>t.startsWith("-")?t:Qt.some(e=>t.startsWith(e))?`-${v(t)}`:v(t),nt=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,r=Object.entries(t),i=async([p,u])=>{const $=p.trim(),P=Gt($),x=(M,k=";")=>`${P}:${M}${k}`,O={scope:e,config:s};if(typeof u=="function")return i([p,u(O)]);if(u instanceof Promise)return i([p,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return x(u.toString());if($==="defaultVariants")return;if($==="variants"){const D=Object.entries(u);for(const[a,g]of D){if(!g)continue;const j=Object.entries(g);for(const[f,C]of j){if(!C)continue;const N=`${e}.${a}-${f}`;(await nt(C,N,s)).forEach(J=>o.add(J))}}return}if($==="compoundVariants"){for(const D of u){const{css:a,...g}=D,j=Object.entries(g).reduce((C,[N,E])=>`${C}.${N}-${E}`,e);(await nt(a,j,s)).forEach(C=>o.add(C))}return}if($.startsWith("@")){const D=$,a=await X(u,e,s),g=`${D} { ${a} }`;o.add(g);return}const M=p.includes("&")?$.replace("&",e):$.startsWith(":")?`${e}${$}`:`${e} ${$}`;(await nt(u,M,s)).forEach(D=>o.add(D));return}if(typeof u=="number"){const M=Lt(P,u);return x(M)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return x(u)},y=r.map(i),{modifiers:b}={},m=[Ft(),qt(b)],w=(await Promise.all(y).then(p=>Promise.all(p.map(u=>m.reduce(async($,P)=>{const x=await $;if(!x)return x;const O=await P(x);if(!O)return x;const{transformed:M,additionalCss:k}=O;let D="";if(k)for(const a of k)D+=await X(a,"");return`${D}${M}`},Promise.resolve(u)))))).filter(p=>p!==void 0).join(`
|
2
2
|
`);if(!w.trim())return Array.from(o);const h=e?`${e} {
|
3
3
|
${w}
|
4
4
|
}`:w;return o.has(h)?Array.from(o):[h,...o]},X=async(t,e,s,n=!1)=>(await nt(t,e,s,n)).join(`
|
5
|
-
`),Ct=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,
|
6
|
-
`)},Kt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Pt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},Pt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const
|
5
|
+
`),Ct=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,r]of Object.entries(t))if(typeof r!="function")if(r&&typeof r=="object"){const i=o.trim(),y=await Ct(r,[...e,i]);s.push(y)}else n[o]=r;if(Object.keys(n).length){const o=e.map(v).join("-"),r="t_"+q(o,4),i=await X(n,`.${o}, .${r}`);s.push(i)}return s.join(`
|
6
|
+
`)},Kt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Pt(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},Pt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?Pt(o,r,s):s.add(e)}),[...s]):[],Nt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return d.existsSync(e)?e:Nt(c.join(t,".."))},Ut=async t=>{const e=Nt(t);return await dt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Zt=async t=>{const e=await Ut(t);if(e)return e.type};let H;const _t=async t=>{if(H)return H;const e=await Zt(t);return e==="module"?H="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ft&&ft.tagName.toUpperCase()==="SCRIPT"&&ft.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},ut=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function xt(t){return t?typeof t!="string"?xt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Bt={"*, *::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"}},L=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Xt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class Yt{constructor(e){st(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class te{constructor(e){st(this,"_path");st(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new Yt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const ee=t=>new te(t),se=(t,e)=>new Promise((s,n)=>{const o=setTimeout(()=>{n(new Error("Timeout"))},100),r=lt.createSourceFile("temp.ts",t,lt.ScriptTarget.Latest,!0);function i(y){if(lt.isVariableDeclaration(y)&&y.name.getText()===e){const b=y.getStart(),m=y.getEnd();clearTimeout(o),s([b,m])}y.forEachChild(i)}i(r)}),z={externalModules:[],rcFile:void 0,destDir:void 0},Tt=t=>{if(z.externalModules.length>0)return z.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await pt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},kt=["salty","css","styles","styled"],ne=(t=[])=>new RegExp(`\\.(${[...kt,...t].join("|")})\\.`),Q=(t,e=[])=>ne(e).test(t),Dt=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await dt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Dt(c.join(t,".."))},pt=async t=>{var n,o;const e=await Dt(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((o=e.projects)==null?void 0:o.find(r=>r.dir===e.defaultProject))},oe=async t=>{const e=await pt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=c.join(s,"salty.config.js"),r=await _t(t),i=Tt(n);await jt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:i});const y=Date.now(),{config:b}=await import(`${o}?t=${y}`);return{config:b,path:o}},ie=async(t,e)=>{var ht,gt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async F=>{const{contents:_,outputFilePath:U}=await ot(t,F,s);Object.entries(_).forEach(([V,T])=>{T.isMedia?n.mediaQueries.push([V,T]):T.isGlobalDefine?n.globalStyles.push(T):T.isDefineVariables?n.variables.push(T):T.isDefineTemplates&&n.templates.push(T._setPath(`${V};;${U}`))})}));const{config:o,path:r}=await oe(t),i={...o},{mediaQueries:y}=n;i.mediaQueries=Object.fromEntries(y.map(([F,_])=>[`@${F}`,_]));const b=y.map(([F])=>`'@${F}'`).join(" | "),m=new Set,l=async(F,_=[])=>{if(!F)return[];const U=Object.entries(F).map(async([T,A])=>{const Z=async R=>{if(!R)return;if(R instanceof Promise)return await Z(await R);if(typeof R=="function")return await Z(await R());if(typeof R=="object")return await l(R,[..._,T]);const rt=xt(T),at=v(T),ct=[..._,rt].join(".");m.add(`"${ct}"`);const et=[..._.map(v),at].join("-"),wt=It(R);return wt?`--${et}: ${wt.transformed};`:`--${et}: ${R};`};return await Z(A)});return(await Promise.all(U)).flat()},w=async F=>{if(!F)return[];const _=Object.entries(F).map(async([V,T])=>{const A=await l(T);return V==="base"?A.join(""):i.mediaQueries[V]?`${i.mediaQueries[V]} { ${A.join("")} }`:`${V} { ${A.join("")} }`});return(await Promise.all(_)).flat()},h=async F=>{if(!F)return[];const _=Object.entries(F).map(async([V,T])=>{const A=Object.entries(T).map(async([R,rt])=>{const at=await l(rt,[V]),ct=`.${V}-${R}, [data-${V}="${R}"]`,et=at.join("");return`${ct} { ${et} }`});return(await Promise.all(A)).flat()});return(await Promise.all(_)).flat()},S=F=>({...F,responsive:void 0,conditional:void 0}),p=F=>n.variables.map(_=>F==="static"?S(_._current):_._current[F]),u=L(S(o.variables),p("static")),$=await l(u),P=L((ht=o.variables)==null?void 0:ht.responsive,p("responsive")),x=await w(P),O=L((gt=o.variables)==null?void 0:gt.conditional,p("conditional")),M=await h(O),k=c.join(s,"css/_variables.css"),D=`:root { ${$.join("")} ${x.join("")} } ${M.join("")}`;d.writeFileSync(k,D),i.staticVariables=u;const a=c.join(s,"css/_global.css"),g=L(o.global,n.globalStyles),j=await X(g,"");d.writeFileSync(a,`@layer global { ${j} }`);const f=c.join(s,"css/_reset.css"),N=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Bt,E=await X(N,"");d.writeFileSync(f,`@layer reset { ${E} }`);const J=c.join(s,"css/_templates.css"),W=L(o.templates,n.templates),G=await Ct(W),Y=Kt(W);d.writeFileSync(J,`@layer templates { ${G} }`),i.templates=W;const it=o.templates?[ee(o.templates)._setPath(`config;;${r}`)]:[],K=Xt(n.templates,it);i.templatePaths=Object.fromEntries(Object.entries(K).map(([F,_])=>[F,_._path]));const tt=c.join(s,"types/css-tokens.d.ts"),Et=`
|
7
7
|
// Variable types
|
8
8
|
type VariableTokens = ${[...m].join("|")};
|
9
9
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
@@ -16,27 +16,27 @@
|
|
16
16
|
|
17
17
|
// Media query types
|
18
18
|
type MediaQueryKeys = ${b||"''"};
|
19
|
-
`;d.writeFileSync(tt,Et);const Vt=c.join(s,"cache/config-cache.json");d.writeFileSync(Vt,JSON.stringify(
|
19
|
+
`;d.writeFileSync(tt,Et);const Vt=c.join(s,"cache/config-cache.json");d.writeFileSync(Vt,JSON.stringify(i,null,2))},bt=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(t))return e;const i=o.exec(t);if(i){const y=i.at(1);if(kt.some(m=>y==null?void 0:y.includes(m)))return e}return"styled('div',"}),re=(t,e)=>{try{const s=d.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
20
20
|
|
21
21
|
${t}`:`globalThis.saltyConfig = {};
|
22
22
|
|
23
|
-
${t}`}catch{return t}},ot=async(t,e,s)=>{const n=q(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const
|
24
|
-
`),f=q(a,6),C=c.parse(a),N=v(C.name),E=c.join(
|
23
|
+
${t}`}catch{return t}},ot=async(t,e,s)=>{const n=q(e),o=c.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=c.parse(e);let i=d.readFileSync(e,"utf8");i=bt(i),i=re(i,t);const y=c.join(s,"js",n+".js"),b=await pt(t),m=c.join(t,(b==null?void 0:b.configDir)||"","salty.config.ts"),l=Tt(m),w=await _t(t);await jt.build({stdin:{contents:i,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:w,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const $=d.readFileSync(u.path,"utf8");return{contents:bt($),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${y}?t=${h}`),outputFilePath:y}},ae=async t=>{const e=await I(t),s=c.join(e,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},mt=async t=>{const e=await ae(t),s=await I(t),n=c.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return L(r,e)},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ce=async(t,e=yt(),s=!0)=>{try{const n=Date.now();e?ut.info("Generating CSS in production mode! 🔥"):ut.info("Generating CSS in development mode! 🚀");const o=[],r=[],i=await I(t),y=c.join(i,"index.css");s&&(()=>{d.existsSync(i)&&zt.execSync("rm -rf "+i),d.mkdirSync(i,{recursive:!0}),d.mkdirSync(c.join(i,"css")),d.mkdirSync(c.join(i,"types")),d.mkdirSync(c.join(i,"js")),d.mkdirSync(c.join(i,"cache"))})();const m=new Set,l=new Set;async function w(a){const g=["node_modules","saltygen"],j=d.statSync(a);if(j.isDirectory()){const f=d.readdirSync(a);if(g.some(N=>a.includes(N)))return;await Promise.all(f.map(N=>w(c.join(a,N))))}else if(j.isFile()&&Q(a)){m.add(a);const C=d.readFileSync(a,"utf8");/define[\w\d]+\(/.test(C)&&l.add(a)}}await w(t),await ie(t,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async a=>{const{contents:g}=await ot(t,a,i);for(let[j,f]of Object.entries(g))f instanceof Promise&&(f=await f),f.isKeyframes?h.keyframes.push({value:f,src:a,name:j}):f.isClassName?h.classNames.push({...f,src:a,name:j}):f.generator&&h.components.push({...f,src:a,name:j})}));const S=await mt(t);for(const a of h.keyframes){const{value:g}=a,j=`a_${g.animationName}.css`,f=`css/${j}`,C=c.join(i,f);o.push(j),d.writeFileSync(C,g.css)}const p={};for(const a of h.components){const{src:g,name:j}=a;p[g]||(p[g]=[]);const f=a.generator._withBuildContext({callerName:j,isProduction:e,config:S});r[f.priority]||(r[f.priority]=[]);const C=await f.css;if(!C)continue;r[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,E=c.join(i,N);d.writeFileSync(E,C),S.importStrategy==="component"&&p[g].push(f.cssFileName)}for(const a of h.classNames){const{src:g,name:j}=a;p[g]||(p[g]=[]);const f=a.generator._withBuildContext({callerName:j,isProduction:e,config:S}),C=await f.css;if(!C)continue;r[f.priority]||(r[f.priority]=[]),r[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,E=c.join(i,N);d.writeFileSync(E,C),S.importStrategy==="component"&&p[g].push(f.cssFileName)}S.importStrategy==="component"&&Object.entries(p).forEach(([a,g])=>{const j=g.map(J=>`@import url('./${J}');`).join(`
|
24
|
+
`),f=q(a,6),C=c.parse(a),N=v(C.name),E=c.join(i,`css/f_${N}-${f}.css`);d.writeFileSync(E,j||"/* Empty file */")});const u=o.map(a=>`@import url('./css/${a}');`).join(`
|
25
25
|
`);let O=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
26
26
|
|
27
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(a=>{try{return d.readFileSync(c.join(
|
27
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(a=>{try{return d.readFileSync(c.join(i,"css",a),"utf8").length>0}catch{return!1}}).map(a=>`@import url('./css/${a}');`).join(`
|
28
28
|
`)}
|
29
|
-
${u}`;if(S.importStrategy!=="component"){const a=
|
29
|
+
${u}`;if(S.importStrategy!=="component"){const a=r.reduce((g,j,f)=>{const C=j.reduce((W,G)=>{var tt;const Y=c.join(i,"css",G),it=d.readFileSync(Y,"utf8"),K=((tt=/.*-([^-]+)-\d+.css/.exec(G))==null?void 0:tt.at(1))||q(Y,6);return W.includes(K)?W:`${W}
|
30
30
|
/*start:${K}-${G}*/
|
31
|
-
${
|
31
|
+
${it}
|
32
32
|
/*end:${K}*/
|
33
|
-
`},""),N=`l_${f}.css`,E=c.join(
|
33
|
+
`},""),N=`l_${f}.css`,E=c.join(i,"css",N),J=`@layer l${f} { ${C}
|
34
34
|
}`;return d.writeFileSync(E,J),`${g}
|
35
|
-
@import url('./css/${N}');`},"");O+=a}d.writeFileSync(y,O);const k=Date.now()-n,D=k<200?"🔥":k<500?"🚀":k<1e3?"🎉":k<2e3?"🚗":k<5e3?"🤔":"🥴";ut.info(`Generated CSS in ${k}ms! ${D}`)}catch(n){console.error(n)}},le=async(t,e,s=yt())=>{try{const n=await I(t);if(Q(e)){const
|
35
|
+
@import url('./css/${N}');`},"");O+=a}d.writeFileSync(y,O);const k=Date.now()-n,D=k<200?"🔥":k<500?"🚀":k<1e3?"🎉":k<2e3?"🚗":k<5e3?"🤔":"🥴";ut.info(`Generated CSS in ${k}ms! ${D}`)}catch(n){console.error(n)}},le=async(t,e,s=yt())=>{try{const n=await I(t);if(Q(e)){const r=[],i=await mt(t),{contents:y}=await ot(t,e,n);for(const[b,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const u=`css/${`a_${m.animationName}.css`}`,$=c.join(n,u);d.writeFileSync($,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:b,isProduction:s,config:i}),u=await p.css;if(!u)continue;r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName);const $=`css/${p.cssFileName}`,P=c.join(n,$);d.writeFileSync(P,u);continue}if(!m.generator)continue;const l=m.generator._withBuildContext({callerName:b,isProduction:s,config:i}),w=await l.css;if(!w)continue;const h=`css/${l.cssFileName}`,S=c.join(n,h);d.writeFileSync(S,w),r[l.priority]||(r[l.priority]=[]),r[l.priority].push(l.cssFileName)}if(i.importStrategy!=="component")r.forEach((b,m)=>{const l=`l_${m}.css`,w=c.join(n,"css",l);let h=d.readFileSync(w,"utf8");b.forEach(S=>{var P;const p=c.join(n,"css",S),u=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||q(p,6);if(!h.includes(u)){const x=d.readFileSync(p,"utf8"),O=`/*start:${u}-${S}*/
|
36
36
|
${x}
|
37
37
|
/*end:${u}*/
|
38
38
|
`;h=`${h.replace(/\}$/,"")}
|
39
39
|
${O}
|
40
|
-
}`}}),d.writeFileSync(w,h)});else{const b=
|
41
|
-
`),m=q(e,6),l=c.parse(e),w=v(l.name),h=c.join(n,`css/f_${w}-${m}.css`);d.writeFileSync(h,b||"/* Empty file */")}}}catch(n){console.error(n)}},fe=async(t,e,s=yt())=>{var n,o;try{const
|
42
|
-
${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(
|
40
|
+
}`}}),d.writeFileSync(w,h)});else{const b=r.flat().map(S=>`@import url('./${S}');`).join(`
|
41
|
+
`),m=q(e,6),l=c.parse(e),w=v(l.name),h=c.join(n,`css/f_${w}-${m}.css`);d.writeFileSync(h,b||"/* Empty file */")}}}catch(n){console.error(n)}},fe=async(t,e,s=yt())=>{var n,o;try{const r=await I(t);if(Q(e)){const y=d.readFileSync(e,"utf8"),b=await mt(t),{contents:m}=await ot(t,e,r);let l=y;for(const[w,h]of Object.entries(m)){if(h.isKeyframes||!h.generator)continue;const S=h.generator._withBuildContext({callerName:w,isProduction:s,config:b}),[p,u]=await se(l,w),$=l.slice(p,u);if(h.isClassName){const P=l,x=` ${w} = className("${S.classNames}")`;l=l.replace($,x),P===l&&console.error("Minimize file failed to change content",{name:w})}if($.includes("styled")){const P=(o=(n=/styled\(([^,]+),/.exec($))==null?void 0:n.at(1))==null?void 0:o.trim(),x=l,O=` ${w} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;l=l.replace($,O),x===l&&console.error("Minimize file failed to change content",{name:w,tagName:P})}}if(b.importStrategy==="component"){const w=q(e,6),h=c.parse(e);l=`import '../../saltygen/css/${`f_${v(h.name)}-${w}.css`}';
|
42
|
+
${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(r){console.error("Error in minimizeFile:",r)}},St=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!Q(t))return!1;const n=await dt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},Ot=t=>({name:"stylegen",buildStart:()=>ce(t),load:async e=>{if(Q(e))return await fe(t,e)},handleHotUpdate:async({file:e,server:s})=>{await St(e)&&s.restart()},watchChange:{handler:async e=>{Q(e)&&(await St(e)||await le(t,e))}}});exports.default=Ot;exports.saltyPlugin=Ot;
|
package/index.js
CHANGED
@@ -68,10 +68,10 @@ const Kt = (e) => (t) => {
|
|
68
68
|
if (w === "variants") {
|
69
69
|
const k = Object.entries(f);
|
70
70
|
for (const [i, y] of k) {
|
71
|
-
if (!y)
|
71
|
+
if (!y) continue;
|
72
72
|
const S = Object.entries(y);
|
73
73
|
for (const [l, j] of S) {
|
74
|
-
if (!j)
|
74
|
+
if (!j) continue;
|
75
75
|
const P = `${t}.${i}-${l}`;
|
76
76
|
(await ot(j, P, s)).forEach((W) => o.add(W));
|
77
77
|
}
|
@@ -585,7 +585,7 @@ ${it}
|
|
585
585
|
if (d.isKeyframes && d.css) {
|
586
586
|
const f = `css/${`a_${d.animationName}.css`}`, w = u(n, f);
|
587
587
|
x(w, await d.css);
|
588
|
-
|
588
|
+
continue;
|
589
589
|
}
|
590
590
|
if (d.isClassName) {
|
591
591
|
const p = d.generator._withBuildContext({
|
@@ -597,8 +597,9 @@ ${it}
|
|
597
597
|
a[p.priority] || (a[p.priority] = []), a[p.priority].push(p.cssFileName);
|
598
598
|
const w = `css/${p.cssFileName}`, F = u(n, w);
|
599
599
|
x(F, f);
|
600
|
+
continue;
|
600
601
|
}
|
601
|
-
if (!d.generator)
|
602
|
+
if (!d.generator) continue;
|
602
603
|
const c = d.generator._withBuildContext({
|
603
604
|
callerName: $,
|
604
605
|
isProduction: s,
|
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.244",
|
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.244"
|
38
38
|
}
|
39
39
|
}
|