@salty-css/vite 0.0.1-alpha.176 → 0.0.1-alpha.178
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 +1 -1
- 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 ye=require("esbuild"),ge=require("child_process"),a=require("path"),f=require("fs"),L=require("fs/promises"),I=require("winston");var B=typeof document<"u"?document.currentScript:null;function
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const ye=require("esbuild"),ge=require("child_process"),a=require("path"),f=require("fs"),L=require("fs/promises"),I=require("winston");var B=typeof document<"u"?document.currentScript:null;function he(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 te=he(ye),Y=e=>String.fromCharCode(e+(e>25?39:97)),me=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=Y(n%52)+s;return s=Y(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Se=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},H=(e,t=5)=>{const s=Se(5381,JSON.stringify(e))>>>0;return me(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 be=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:o,transform:i}=n;e=e.replace(o,u=>{const{value:p,css:r}=i(u);return r&&s.push(r),p})}),{result:e,additionalCss:s}},se=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${M(n[1].replaceAll(".","-"))})`)}:{result:e},V=(e,t,s)=>{if(!e)return"";const n=[],o=Object.entries(e).reduce((u,[p,r])=>{const c=p.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return u;if(c==="variants")return Object.entries(r).forEach(([j,x])=>{x&&Object.entries(x).forEach(([l,h])=>{if(!h)return;const w=`${t}.${j}-${l}`,S=V(h,w);n.push(S)})}),u;if(c==="defaultVariants")return u;if(c==="compoundVariants")return r.forEach(j=>{const{css:x,...l}=j,h=Object.entries(l).reduce((S,[g,F])=>`${S}.${g}-${F}`,t),w=V(x,h);n.push(w)}),u;if(c.startsWith("@")){const j=V(r,t),x=`${c} {
|
2
2
|
${j.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return n.push(x),u}const
|
5
|
+
}`;return n.push(x),u}const m=p.includes("&")?c.replace("&",t):c.startsWith(":")?`${t}${c}`:`${t} ${c}`,D=V(r,m);return n.push(D),u}const y=c.startsWith("-")?c:M(c),d=(m,D=";")=>u=`${u}${m}${D}`,k=m=>d(`${y}:${m}`);if(typeof r=="number")return k(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return u;const{modifiers:_}={},T=function*(){yield se(r),yield be(r,_)}();for(const{result:m,additionalCss:D=[]}of T)r=m,D.forEach(j=>{const x=V(j,"");d(x,"")});return k(r)},"");return o?t?[`${t} { ${o} }`,...n].join(`
|
6
6
|
`):o:n.join(`
|
7
7
|
`)},ne=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([o,i])=>{if(typeof i=="object"){if(!i)return;const u=o.trim(),p=ne(i,[...t,u]);s.push(p)}else n[o]=i}),Object.keys(n).length){const o=t.map(M).join("-"),i=V(n,`.${o}`);s.push(i)}return s.join(`
|
8
|
-
`)},$e=e=>Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=re(n).map(o=>`"${o}"`).join(" | ")),t),{}),re=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const i=t?`${t}.${n}`:n;return typeof o=="object"?re(o,i,s):s.add(t)}),[...s]):[],oe=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=a.join(e,"package.json");return f.existsSync(t)?t:oe(a.join(e,".."))},je=async e=>{const t=oe(e);return await L.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},we=async e=>{const t=await je(e);if(t)return t.type};let J;const ie=async e=>{if(J)return J;const t=await we(e);return t==="module"?J="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:B&&B.tagName.toUpperCase()==="SCRIPT"&&B.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(J="cjs"),J||"esm"},K=I.createLogger({level:"debug",format:I.format.combine(I.format.colorize(),I.format.cli()),transports:[new I.transports.Console({})]});function ce(e){return e?typeof e!="string"?ce(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 Fe={"*, *::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"}},q=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),E={externalModules:[],rcFile:void 0,destDir:void 0},ae=e=>{if(E.externalModules.length>0)return E.externalModules;const s=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return E.externalModules=n,n},z=async e=>{if(E.destDir)return E.destDir;const t=await U(e),s=a.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},le=["salty","css","styles","styled"],Ce=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),W=(e,t=[])=>Ce(t).test(e),fe=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=a.join(e,".saltyrc.json"),s=await L.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):fe(a.join(e,".."))},U=async e=>{var n,o;const t=await fe(e),s=(n=t.projects)==null?void 0:n.find(i=>e.endsWith(i.dir||""));return s||((o=t.projects)==null?void 0:o.find(i=>i.dir===t.defaultProject))},xe=async e=>{const t=await U(e),s=await z(e),n=a.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=a.join(s,"salty.config.js"),i=await ie(e),u=ae(n);await te.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:u});const p=Date.now(),{config:r}=await import(`${o}?t=${p}`);return r},ke=async(e,t)=>{const s=await xe(e),n=new Set,o=($,C=[])=>$?Object.entries($).flatMap(([O,P])=>{if(!P)return;if(typeof P=="object")return o(P,[...C,O]);const Z=ce(O),R=M(O),A=[...C,Z].join(".");n.add(`"${A}"`);const G=[...C.map(M),R].join("-"),{result:pe}=se(P);return`--${G}: ${pe};`}):[],i=$=>$?Object.entries($).flatMap(([C,O])=>{const P=o(O);return C==="base"?P.join(""):`${C} { ${P.join("")} }`}):[],u=$=>$?Object.entries($).flatMap(([C,O])=>Object.entries(O).flatMap(([P,Z])=>{const R=o(Z,[C]),A=`.${C}-${P}, [data-${C}="${P}"]`,G=R.join("");return`${A} { ${G} }`})):[],p=$=>t.variables.map(C=>C._current[$]),r=o(q(s.variables,p("variables"))),c=i(q(s.responsiveVariables,p("responsiveVariables"))),y=u(q(s.conditionalVariables,p("conditionalVariables"))),d=await z(e),k=a.join(d,"css/_variables.css"),_=`:root { ${r.join("")} ${c.join("")} } ${y.join("")}`;f.writeFileSync(k,_);const N=a.join(d,"css/_global.css"),T=q(s.global,t.globalStyles),
|
8
|
+
`)},$e=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=re(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},re=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const i=t?`${t}.${n}`:n;return typeof o=="object"?re(o,i,s):s.add(t)}),[...s]):[],oe=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=a.join(e,"package.json");return f.existsSync(t)?t:oe(a.join(e,".."))},je=async e=>{const t=oe(e);return await L.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},we=async e=>{const t=await je(e);if(t)return t.type};let J;const ie=async e=>{if(J)return J;const t=await we(e);return t==="module"?J="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:B&&B.tagName.toUpperCase()==="SCRIPT"&&B.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(J="cjs"),J||"esm"},K=I.createLogger({level:"debug",format:I.format.combine(I.format.colorize(),I.format.cli()),transports:[new I.transports.Console({})]});function ce(e){return e?typeof e!="string"?ce(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 Fe={"*, *::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"}},q=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),E={externalModules:[],rcFile:void 0,destDir:void 0},ae=e=>{if(E.externalModules.length>0)return E.externalModules;const s=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return E.externalModules=n,n},z=async e=>{if(E.destDir)return E.destDir;const t=await U(e),s=a.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},le=["salty","css","styles","styled"],Ce=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),W=(e,t=[])=>Ce(t).test(e),fe=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=a.join(e,".saltyrc.json"),s=await L.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):fe(a.join(e,".."))},U=async e=>{var n,o;const t=await fe(e),s=(n=t.projects)==null?void 0:n.find(i=>e.endsWith(i.dir||""));return s||((o=t.projects)==null?void 0:o.find(i=>i.dir===t.defaultProject))},xe=async e=>{const t=await U(e),s=await z(e),n=a.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=a.join(s,"salty.config.js"),i=await ie(e),u=ae(n);await te.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:u});const p=Date.now(),{config:r}=await import(`${o}?t=${p}`);return r},ke=async(e,t)=>{const s=await xe(e),n=new Set,o=($,C=[])=>$?Object.entries($).flatMap(([O,P])=>{if(!P)return;if(typeof P=="object")return o(P,[...C,O]);const Z=ce(O),R=M(O),A=[...C,Z].join(".");n.add(`"${A}"`);const G=[...C.map(M),R].join("-"),{result:pe}=se(P);return`--${G}: ${pe};`}):[],i=$=>$?Object.entries($).flatMap(([C,O])=>{const P=o(O);return C==="base"?P.join(""):`${C} { ${P.join("")} }`}):[],u=$=>$?Object.entries($).flatMap(([C,O])=>Object.entries(O).flatMap(([P,Z])=>{const R=o(Z,[C]),A=`.${C}-${P}, [data-${C}="${P}"]`,G=R.join("");return`${A} { ${G} }`})):[],p=$=>t.variables.map(C=>C._current[$]),r=o(q(s.variables,p("variables"))),c=i(q(s.responsiveVariables,p("responsiveVariables"))),y=u(q(s.conditionalVariables,p("conditionalVariables"))),d=await z(e),k=a.join(d,"css/_variables.css"),_=`:root { ${r.join("")} ${c.join("")} } ${y.join("")}`;f.writeFileSync(k,_);const N=a.join(d,"css/_global.css"),T=q(s.global,t.globalStyles),m=V(T,"");f.writeFileSync(N,`@layer global { ${m} }`);const D=a.join(d,"css/_reset.css"),x=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:Fe,l=V(x,"");f.writeFileSync(D,`@layer reset { ${l} }`);const h=a.join(d,"css/_templates.css"),w=ne(s.templates),S=$e(s.templates);f.writeFileSync(h,w);const g=a.join(d,"types/css-tokens.d.ts"),b=`
|
9
9
|
// Variable types
|
10
10
|
type VariableTokens = ${[...n].join("|")};
|
11
11
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
@@ -15,22 +15,22 @@
|
|
15
15
|
${Object.entries(S).map(([$,C])=>`${$}?: ${C}`).join(`
|
16
16
|
`)}
|
17
17
|
}
|
18
|
-
`;f.writeFileSync(g,b)},v=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const u=o.exec(e);if(u){const p=u.at(1);if(le.some(c=>p==null?void 0:p.includes(c)))return t}return"styled('div',"}),Q=async(e,t,s)=>{const n=H(t),o=a.join(s,"./temp");f.existsSync(o)||f.mkdirSync(o);const i=a.parse(t);let u=f.readFileSync(t,"utf8");u=v(u);const p=a.join(s,"js",n+".js"),r=await U(e),c=a.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),y=ae(c),d=await ie(e);await te.build({stdin:{contents:u,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:d,target:["node20"],keepNames:!0,external:y,packages:"external",plugins:[{name:"test",setup:N=>{N.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},T=>{const
|
18
|
+
`;f.writeFileSync(g,b)},v=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const u=o.exec(e);if(u){const p=u.at(1);if(le.some(c=>p==null?void 0:p.includes(c)))return t}return"styled('div',"}),Q=async(e,t,s)=>{const n=H(t),o=a.join(s,"./temp");f.existsSync(o)||f.mkdirSync(o);const i=a.parse(t);let u=f.readFileSync(t,"utf8");u=v(u);const p=a.join(s,"js",n+".js"),r=await U(e),c=a.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),y=ae(c),d=await ie(e);await te.build({stdin:{contents:u,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:d,target:["node20"],keepNames:!0,external:y,packages:"external",plugins:[{name:"test",setup:N=>{N.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},T=>{const m=f.readFileSync(T.path,"utf8");return{contents:v(m),loader:"ts"}})}}]});const k=Date.now();return await import(`${p}?t=${k}`)},X=async e=>{const t=await z(e),s=a.join(t,"salty.config.js"),n=Date.now(),{config:o}=await import(`${s}?t=${n}`);return o},ue=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},De=async(e,t=ue())=>{try{const s=Date.now();t?K.info("Generating CSS in production mode! 🔥"):K.info("Generating CSS in development mode! 🚀");const n=[],o=[],i=await z(e),u=a.join(i,"index.css");(()=>{f.existsSync(i)&&ge.execSync("rm -rf "+i),f.mkdirSync(i,{recursive:!0}),f.mkdirSync(a.join(i,"css")),f.mkdirSync(a.join(i,"types"))})();const r={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[]};async function c(l){const h=["node_modules","saltygen"],w=f.statSync(l);if(w.isDirectory()){const S=f.readdirSync(l);if(h.some(F=>l.includes(F)))return;await Promise.all(S.map(F=>c(a.join(l,F))))}else if(w.isFile()&&W(l)){const g=await Q(e,l,i);Object.entries(g).forEach(([F,b])=>{b.isKeyframes?r.keyframes.push({value:b,src:l,name:F}):b.isMedia?r.mediaQueries.push(b):b.isGlobalDefine?r.globalStyles.push(b):b.isDefineVariables?r.variables.push(b):b.generator&&r.components.push({value:b.generator,src:l,name:F})})}}await c(e),await ke(e,r);const y=await X(e);for(const l of r.keyframes){const{value:h}=l,w=`a_${h.animationName}.css`,S=`css/${w}`,g=a.join(i,S);n.push(w),f.writeFileSync(g,h.css)}const d={};for(const l of r.components){const{value:h,name:w,src:S}=l,g=h._withBuildContext({name:w,config:y,prod:t});o[g.priority]||(o[g.priority]=[]),o[g.priority].push(g.cssFileName),y.importStrategy==="component"&&(d[S]?d[S].push(g.cssFileName):d[S]=[g.cssFileName]);const F=`css/${g.cssFileName}`,b=a.join(i,F);f.writeFileSync(b,g.css)}y.importStrategy==="component"&&Object.entries(d).forEach(([l,h])=>{const w=h.map($=>`@import url('./${$}');`).join(`
|
19
19
|
`),S=H(l,6),g=a.parse(l),F=M(g.name),b=a.join(i,`css/f_${F}-${S}.css`);f.writeFileSync(b,w)});const k=n.map(l=>`@import url('./css/${l}');`).join(`
|
20
|
-
`);let
|
20
|
+
`);let m=`@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(l=>{try{return f.readFileSync(a.join(i,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
23
23
|
`)}
|
24
|
-
${k}`;if(y.importStrategy!=="component"){const l=o.reduce((
|
24
|
+
${k}`;if(y.importStrategy!=="component"){const l=o.reduce((h,w,S)=>{const g=w.reduce((C,O)=>{var A;const P=a.join(i,"css",O),Z=f.readFileSync(P,"utf8"),R=((A=/.*-([^-]+)-\d+.css/.exec(O))==null?void 0:A.at(1))||H(P,6);return C.includes(R)?C:`${C}
|
25
25
|
/*start:${R}*/
|
26
26
|
${Z}
|
27
27
|
/*end:${R}*/
|
28
28
|
`},""),F=`l_${S}.css`,b=a.join(i,"css",F),$=`@layer l${S} { ${g}
|
29
|
-
}`;return f.writeFileSync(b,$),`${
|
30
|
-
@import url('./css/${F}');`},"");
|
29
|
+
}`;return f.writeFileSync(b,$),`${h}
|
30
|
+
@import url('./css/${F}');`},"");m+=l}f.writeFileSync(u,m);const j=Date.now()-s,x=j<200?"🔥":j<500?"🚀":j<1e3?"🎉":j<2e3?"🚗":j<5e3?"🤔":"🥴";K.info(`Generated CSS in ${j}ms! ${x}`)}catch(s){console.error(s)}},_e=async(e,t)=>{try{const s=await z(e);if(W(t)){const o=[],i=await X(e),u=await Q(e,t,s);Object.entries(u).forEach(([p,r])=>{if(r.isKeyframes&&r.css){const _=`css/${`a_${r.animationName}.css`}`,N=a.join(s,_);f.writeFileSync(N,r.css);return}if(!r.generator)return;const c=r.generator._withBuildContext({name:p,config:i}),y=`css/${c.cssFileName}`,d=a.join(s,y);f.writeFileSync(d,c.css),o[c.priority]||(o[c.priority]=[]),o[c.priority].push(c.cssFileName)}),i.importStrategy!=="component"&&o.forEach((p,r)=>{const c=`l_${r}.css`,y=a.join(s,"css",c);let d=f.readFileSync(y,"utf8");p.forEach(k=>{var m;const _=a.join(s,"css",k),N=((m=/.*-([^-]+)-\d+.css/.exec(k))==null?void 0:m.at(1))||H(_,6);if(!d.includes(N)){const D=f.readFileSync(_,"utf8"),j=`/*start:${N}*/
|
31
31
|
${D}
|
32
32
|
/*end:${N}*/
|
33
33
|
`;d=`${d.replace(/\}$/,"")}
|
34
34
|
${j}
|
35
|
-
}`}}),f.writeFileSync(y,d)})}}catch(s){console.error(s)}},Ne=async(e,t,s=ue())=>{try{const n=await z(e);if(W(t)){const i=f.readFileSync(t,"utf8");i.replace(/^(?!export\s)const\s.*/gm,y=>`export ${y}`)!==i&&await L.writeFile(t,i);const p=await X(e),r=await Q(e,t,n);let c=i;if(Object.entries(r).forEach(([y,d])=>{var b;if(d.isKeyframes||!d.generator)return;const k=d.generator._withBuildContext({name:y,config:p,prod:s}),_=new RegExp(`\\s${y}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!_)return console.error("Could not find the original declaration");const N=(b=_.at(1))==null?void 0:b.trim(),T=new RegExp(`\\s${y}[=\\s]+styled\\(`,"g").exec(c);if(!T)return console.error("Could not find the original declaration");const{index:
|
35
|
+
}`}}),f.writeFileSync(y,d)})}}catch(s){console.error(s)}},Ne=async(e,t,s=ue())=>{try{const n=await z(e);if(W(t)){const i=f.readFileSync(t,"utf8");i.replace(/^(?!export\s)const\s.*/gm,y=>`export ${y}`)!==i&&await L.writeFile(t,i);const p=await X(e),r=await Q(e,t,n);let c=i;if(Object.entries(r).forEach(([y,d])=>{var b;if(d.isKeyframes||!d.generator)return;const k=d.generator._withBuildContext({name:y,config:p,prod:s}),_=new RegExp(`\\s${y}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!_)return console.error("Could not find the original declaration");const N=(b=_.at(1))==null?void 0:b.trim(),T=new RegExp(`\\s${y}[=\\s]+styled\\(`,"g").exec(c);if(!T)return console.error("Could not find the original declaration");const{index:m}=T;let D=!1;const j=setTimeout(()=>D=!0,5e3);let x=0,l=!1,h=0;for(;!l&&!D;){const $=c[m+x];$==="("&&h++,$===")"&&h--,h===0&&$===")"&&(l=!0),x>c.length&&(D=!0),x++}if(!D)clearTimeout(j);else throw new Error("Failed to find the end of the styled call and timed out");const w=m+x,S=c.slice(m,w),g=c,F=` ${y} = styled(${N}, "${k.classNames}", ${JSON.stringify(k.props)});`;c=c.replace(S,F),g===c&&console.error("Minimize file failed to change content",{name:y,tagName:N})}),p.importStrategy==="component"){const y=H(t,6),d=a.parse(t);c=`import '../../saltygen/css/${`f_${M(d.name)}-${y}.css`}';
|
36
36
|
${c}`}return c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(n){console.error("Error in minimizeFile:",n)}},ee=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!W(e))return!1;const n=await L.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},de=e=>({name:"stylegen",buildStart:()=>De(e),load:async t=>{if(W(t))return await Ne(e,t)},handleHotUpdate:async({file:t,server:s})=>{await ee(t)&&await s.restart()},watchChange:{handler:async t=>{W(t)&&(await ee(t)||await _e(e,t))}}});exports.default=de;exports.saltyPlugin=de;
|
package/index.js
CHANGED
@@ -96,7 +96,7 @@ const Ct = (t, e) => {
|
|
96
96
|
}
|
97
97
|
return s.join(`
|
98
98
|
`);
|
99
|
-
}, xt = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = ct(n).map((r) => `"${r}"`).join(" | ")), e), {}), ct = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, r]) => {
|
99
|
+
}, xt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = ct(n).map((r) => `"${r}"`).join(" | ")), e), {}) : {}, ct = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, r]) => {
|
100
100
|
const i = e ? `${e}.${n}` : n;
|
101
101
|
return typeof r == "object" ? ct(r, i, s) : s.add(e);
|
102
102
|
}), [...s]) : [], at = (t) => {
|
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.178",
|
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.178"
|
38
38
|
}
|
39
39
|
}
|