@salty-css/vite 0.0.1-alpha.183 → 0.0.1-alpha.186
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 +20 -19
- package/index.js +229 -200
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,36 +1,37 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
2
|
-
${
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const me=require("esbuild"),Se=require("child_process"),l=require("path"),u=require("fs"),B=require("fs/promises"),L=require("winston");var Q=typeof document<"u"?document.currentScript:null;function be(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 oe=be(me),te=e=>String.fromCharCode(e+(e>25?39:97)),je=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=te(n%52)+s;return s=te(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},$e=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},Z=(e,t=5)=>{const s=$e(5381,JSON.stringify(e))>>>0;return je(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 we=(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}},re=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(([D,b])=>{b&&Object.entries(b).forEach(([O,f])=>{if(!f)return;const j=`${t}.${D}-${O}`,S=R(f,j);n.push(S)})}),c;if(o==="defaultVariants")return c;if(o==="compoundVariants")return r.forEach(D=>{const{css:b,...O}=D,f=Object.entries(O).reduce((S,[$,y])=>`${S}.${$}-${y}`,t),j=R(b,f);n.push(j)}),c;if(o.startsWith("@")){const D=R(r,t),b=`${o} {
|
2
|
+
${D.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return n.push(
|
5
|
+
}`;return n.push(b),c}const F=p.includes("&")?o.replace("&",t):o.startsWith(":")?`${t}${o}`:`${t} ${o}`,C=R(r,F);return n.push(C),c}const m=o.startsWith("-")?o:M(o),g=(F,C=";")=>c=`${c}${F}${C}`,d=F=>g(`${m}:${F}`);if(typeof r=="number")return d(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return c;const{modifiers:N}={},T=function*(){yield re(r),yield we(r,N)}();for(const{result:F,additionalCss:C=[]}of T)r=F,C.forEach(D=>{const b=R(D,"");g(b,"")});return d(r)},"");return i?t?[`${t} { ${i} }`,...n].join(`
|
6
6
|
`):i:n.join(`
|
7
|
-
`)},
|
8
|
-
`)},
|
7
|
+
`)},ie=(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=ie(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
|
+
`)},Fe=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=ce(n).map(i=>`"${i}"`).join(" | ")),t),{}):{},ce=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const a=t?`${t}.${n}`:n;return typeof i=="object"?ce(i,a,s):s.add(t)}),[...s]):[],ae=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:ae(l.join(e,".."))},Ce=async e=>{const t=ae(e);return await B.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Ne=async e=>{const t=await Ce(e);if(t)return t.type};let W;const le=async e=>{if(W)return W;const t=await Ne(e);return t==="module"?W="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:Q&&Q.tagName.toUpperCase()==="SCRIPT"&&Q.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(W="cjs"),W||"esm"},X=L.createLogger({level:"debug",format:L.format.combine(L.format.colorize(),L.format.cli()),transports:[new L.transports.Console({})]});function fe(e){return e?typeof e!="string"?fe(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 xe={"*, *::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"}},z=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),V={externalModules:[],rcFile:void 0,destDir:void 0},ue=e=>{if(V.externalModules.length>0)return V.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 V.externalModules=n,n},J=async e=>{if(V.destDir)return V.destDir;const t=await Y(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},de=["salty","css","styles","styled"],ke=(e=[])=>new RegExp(`\\.(${[...de,...e].join("|")})\\.`),I=(e,t=[])=>ke(t).test(e),pe=async e=>{if(V.rcFile)return V.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=l.join(e,".saltyrc.json"),s=await B.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):pe(l.join(e,".."))},Y=async e=>{var n,i;const t=await pe(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))},Pe=async e=>{const t=await Y(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 le(e),c=ue(n);await oe.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},De=async(e,t)=>{const s=await Pe(e),n={...s},i=new Set,a=(P,k=[])=>P?Object.entries(P).flatMap(([E,_])=>{if(!_)return;if(typeof _=="object")return a(_,[...k,E]);const A=fe(E),G=M(E),K=[...k,A].join(".");i.add(`"${K}"`);const U=[...k.map(M),G].join("-"),{result:he}=re(_);return`--${U}: ${he};`}):[],c=P=>P?Object.entries(P).flatMap(([k,E])=>{const _=a(E);return k==="base"?_.join(""):`${k} { ${_.join("")} }`}):[],p=P=>P?Object.entries(P).flatMap(([k,E])=>Object.entries(E).flatMap(([_,A])=>{const G=a(A,[k]),K=`.${k}-${_}, [data-${k}="${_}"]`,U=G.join("");return`${K} { ${U} }`})):[],r=P=>t.variables.map(k=>k._current[P]),o=a(z(s.variables,r("variables"))),m=c(z(s.responsiveVariables,r("responsiveVariables"))),g=p(z(s.conditionalVariables,r("conditionalVariables"))),d=await J(e),N=l.join(d,"css/_variables.css"),x=`:root { ${o.join("")} ${m.join("")} } ${g.join("")}`;u.writeFileSync(N,x);const T=l.join(d,"css/_global.css"),F=z(s.global,t.globalStyles),C=R(F,"");u.writeFileSync(T,`@layer global { ${C} }`);const D=l.join(d,"css/_reset.css"),O=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:xe,f=R(O,"");u.writeFileSync(D,`@layer reset { ${f} }`);const j=l.join(d,"css/_templates.css"),S=z(s.templates,t.templates),$=ie(S),y=Fe(S);u.writeFileSync(j,$),n.templates=S;const w=l.join(d,"types/css-tokens.d.ts"),H=`
|
9
9
|
// Variable types
|
10
10
|
type VariableTokens = ${[...i].join("|")};
|
11
11
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
12
12
|
|
13
13
|
// Template types
|
14
14
|
type TemplateTokens = {
|
15
|
-
${Object.entries(
|
15
|
+
${Object.entries(y).map(([P,k])=>`${P}?: ${k}`).join(`
|
16
16
|
`)}
|
17
17
|
}
|
18
|
-
`;u.writeFileSync(
|
19
|
-
`)
|
20
|
-
`);let
|
18
|
+
`;u.writeFileSync(w,H);const q=l.join(d,"cache/config-cache.json");u.writeFileSync(q,JSON.stringify(n,null,2))},se=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(de.some(o=>p==null?void 0:p.includes(o)))return t}return"styled('div',"}),v=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=se(c);const p=l.join(s,"js",n+".js"),r=await Y(e),o=l.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),m=ue(o),g=await le(e);await oe.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:m,packages:"external",plugins:[{name:"test",setup:x=>{x.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},T=>{const F=u.readFileSync(T.path,"utf8");return{contents:se(F),loader:"ts"}})}}]});const d=Date.now();return await import(`${p}?t=${d}`)},_e=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)},ee=async e=>{const t=await _e(e),s=await J(e),n=l.join(s,"salty.config.js"),i=Date.now(),{config:a}=await import(`${n}?t=${i}`);return z(a,t)},ye=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Te=async(e,t=ye(),s=!0)=>{try{const n=Date.now();t?X.info("Generating CSS in production mode! 🔥"):X.info("Generating CSS in development mode! 🚀");const i=[],a=[],c=await J(e),p=l.join(c,"index.css");s&&(()=>{u.existsSync(c)&&Se.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 m(f){const j=["node_modules","saltygen"],S=u.statSync(f);if(S.isDirectory()){const $=u.readdirSync(f);if(j.some(w=>f.includes(w)))return;await Promise.all($.map(w=>m(l.join(f,w))))}else if(S.isFile()&&I(f)){const y=await v(e,f,c);Object.entries(y).forEach(([w,h])=>{h.isKeyframes?o.keyframes.push({value:h,src:f,name:w}):h.isMedia?o.mediaQueries.push(h):h.isGlobalDefine?o.globalStyles.push(h):h.isDefineVariables?o.variables.push(h):h.isDefineTemplates?o.templates.push(h):h.isClassName?o.classNames.push({value:h.factory,src:f,name:w}):h.generator&&o.components.push({value:h.generator,src:f,name:w})})}}await m(e),await De(e,o);const g=await ee(e);for(const f of o.keyframes){const{value:j}=f,S=`a_${j.animationName}.css`,$=`css/${S}`,y=l.join(c,$);i.push(S),u.writeFileSync(y,j.css)}const d={};for(const f of o.components){const{value:j,name:S,src:$}=f,y=j._withBuildContext({name:S,config:g,prod:t});a[y.priority]||(a[y.priority]=[]),a[y.priority].push(y.cssFileName);const w=`css/${y.cssFileName}`,h=l.join(c,w);u.writeFileSync(h,y.css),g.importStrategy==="component"&&(d[$]?d[$].push(y.cssFileName):d[$]=[y.cssFileName])}for(const f of o.classNames){const{value:j,src:S,name:$}=f,y=j._withBuildContext({name:$,prod:t});a[0].push(y.cssFileName);const w=`css/${y.cssFileName}`,h=l.join(c,w);u.writeFileSync(h,y.css),g.importStrategy==="component"&&(d[S]?d[S].push(y.cssFileName):d[S]=[y.cssFileName])}g.importStrategy==="component"&&Object.entries(d).forEach(([f,j])=>{const S=j.map(H=>`@import url('./${H}');`).join(`
|
19
|
+
`),$=Z(f,6),y=l.parse(f),w=M(y.name),h=l.join(c,`css/f_${w}-${$}.css`);u.writeFileSync(h,S)});const N=i.map(f=>`@import url('./css/${f}');`).join(`
|
20
|
+
`);let C=`@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
|
-
${
|
24
|
+
${N}`;if(g.importStrategy!=="component"){const f=a.reduce((j,S,$)=>{const y=S.reduce((q,P)=>{var A;const k=l.join(c,"css",P),E=u.readFileSync(k,"utf8"),_=((A=/.*-([^-]+)-\d+.css/.exec(P))==null?void 0:A.at(1))||Z(k,6);return q.includes(_)?q:`${q}
|
25
25
|
/*start:${_}*/
|
26
26
|
${E}
|
27
27
|
/*end:${_}*/
|
28
|
-
`},""),
|
29
|
-
}`;return u.writeFileSync(
|
30
|
-
@import url('./css/${
|
31
|
-
${
|
32
|
-
/*end:${
|
33
|
-
`;
|
34
|
-
${
|
35
|
-
}`}}),u.writeFileSync(g
|
36
|
-
|
28
|
+
`},""),w=`l_${$}.css`,h=l.join(c,"css",w),H=`@layer l${$} { ${y}
|
29
|
+
}`;return u.writeFileSync(h,H),`${j}
|
30
|
+
@import url('./css/${w}');`},"");C+=f}u.writeFileSync(p,C);const b=Date.now()-n,O=b<200?"🔥":b<500?"🚀":b<1e3?"🎉":b<2e3?"🚗":b<5e3?"🤔":"🥴";X.info(`Generated CSS in ${b}ms! ${O}`)}catch(n){console.error(n)}},Oe=async(e,t)=>{try{const s=await J(e);if(I(t)){const i=[],a=await ee(e),c=await v(e,t,s);if(Object.entries(c).forEach(([p,r])=>{if(r.isKeyframes&&r.css){const N=`css/${`a_${r.animationName}.css`}`,x=l.join(s,N);u.writeFileSync(x,r.css);return}if(r.isClassName){console.log("found className value",r);const d=r.factory._withBuildContext({name:p});i[0].push(d.cssFileName);const N=`css/${d.cssFileName}`,x=l.join(s,N);u.writeFileSync(x,d.css),console.log(x,d.css)}if(!r.generator)return;const o=r.generator._withBuildContext({name:p,config:a}),m=`css/${o.cssFileName}`,g=l.join(s,m);u.writeFileSync(g,o.css),i[o.priority]||(i[o.priority]=[]),i[o.priority].push(o.cssFileName)}),console.log(i),a.importStrategy!=="component")i.forEach((p,r)=>{const o=`l_${r}.css`,m=l.join(s,"css",o);let g=u.readFileSync(m,"utf8");p.forEach(d=>{var F;const N=l.join(s,"css",d),x=((F=/.*-([^-]+)-\d+.css/.exec(d))==null?void 0:F.at(1))||Z(N,6);if(!g.includes(x)){const C=u.readFileSync(N,"utf8"),D=`/*start:${x}*/
|
31
|
+
${C}
|
32
|
+
/*end:${x}*/
|
33
|
+
`;g=`${g.replace(/\}$/,"")}
|
34
|
+
${D}
|
35
|
+
}`}}),u.writeFileSync(m,g)});else{const p=i.flat().map(d=>`@import url('./${d}');`).join(`
|
36
|
+
`),r=Z(t,6),o=l.parse(t),m=M(o.name),g=l.join(s,`css/f_${m}-${r}.css`);u.writeFileSync(g,p)}}}catch(s){console.error(s)}},Ee=async(e,t,s=ye())=>{try{const n=await J(e);if(I(t)){const a=u.readFileSync(t,"utf8");a.replace(/^(?!export\s)const\s.*/gm,m=>`export ${m}`)!==a&&await B.writeFile(t,a);const p=await ee(e),r=await v(e,t,n);let o=a;if(Object.entries(r).forEach(([m,g])=>{var w;if(g.isKeyframes||!g.generator)return;const d=g.generator._withBuildContext({name:m,config:p,prod:s}),N=new RegExp(`\\s${m}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!N)return console.error("Could not find the original declaration");const x=(w=N.at(1))==null?void 0:w.trim(),T=new RegExp(`\\s${m}[=\\s]+styled\\(`,"g").exec(o);if(!T)return console.error("Could not find the original declaration");const{index:F}=T;let C=!1;const D=setTimeout(()=>C=!0,5e3);let b=0,O=!1,f=0;for(;!O&&!C;){const h=o[F+b];h==="("&&f++,h===")"&&f--,f===0&&h===")"&&(O=!0),b>o.length&&(C=!0),b++}if(!C)clearTimeout(D);else throw new Error("Failed to find the end of the styled call and timed out");const j=F+b,S=o.slice(F,j),$=o,y=` ${m} = styled(${x}, "${d.classNames}", ${JSON.stringify(d.props)});`;o=o.replace(S,y),$===o&&console.error("Minimize file failed to change content",{name:m,tagName:x})}),p.importStrategy==="component"){const m=Z(t,6),g=l.parse(t);o=`import '../../saltygen/css/${`f_${M(g.name)}-${m}.css`}';
|
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)}},ne=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!I(e))return!1;const n=await B.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},ge=e=>({name:"stylegen",buildStart:()=>Te(e),load:async t=>{if(I(t))return await Ee(e,t)},handleHotUpdate:async({file:t,server:s})=>{await ne(t)&&await s.restart()},watchChange:{handler:async t=>{I(t)&&(await ne(t)||await Oe(e,t))}}});exports.default=ge;exports.saltyPlugin=ge;
|
package/index.js
CHANGED
@@ -1,81 +1,81 @@
|
|
1
1
|
import * as ct from "esbuild";
|
2
2
|
import { execSync as bt } from "child_process";
|
3
|
-
import { join as f, parse as
|
4
|
-
import { existsSync as v, mkdirSync as
|
5
|
-
import { readFile as tt, writeFile as
|
6
|
-
import { createLogger as
|
7
|
-
const ot = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)),
|
3
|
+
import { join as f, parse as K } from "path";
|
4
|
+
import { existsSync as v, mkdirSync as Z, statSync as wt, readdirSync as St, writeFileSync as k, readFileSync as M } from "fs";
|
5
|
+
import { readFile as tt, writeFile as Ct } from "fs/promises";
|
6
|
+
import { createLogger as jt, format as X, transports as Ft } from "winston";
|
7
|
+
const ot = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Nt = (t, e) => {
|
8
8
|
let s = "", n;
|
9
9
|
for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = ot(n % 52) + s;
|
10
10
|
return s = ot(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
-
},
|
11
|
+
}, xt = (t, e) => {
|
12
12
|
let s = e.length;
|
13
13
|
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
14
14
|
return t;
|
15
|
-
},
|
16
|
-
const s =
|
17
|
-
return
|
15
|
+
}, I = (t, e = 5) => {
|
16
|
+
const s = xt(5381, JSON.stringify(t)) >>> 0;
|
17
|
+
return Nt(s, e);
|
18
18
|
};
|
19
|
-
function
|
20
|
-
return t ? typeof t != "string" ?
|
19
|
+
function R(t) {
|
20
|
+
return t ? typeof t != "string" ? R(String(t)) : t.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
|
21
21
|
}
|
22
|
-
const
|
22
|
+
const kt = (t, e) => {
|
23
23
|
if (typeof t != "string") return { result: t };
|
24
24
|
if (!e) return { result: t };
|
25
25
|
const s = [];
|
26
26
|
return Object.values(e).forEach((n) => {
|
27
27
|
const { pattern: i, transform: a } = n;
|
28
28
|
t = t.replace(i, (c) => {
|
29
|
-
const { value:
|
30
|
-
return r && s.push(r),
|
29
|
+
const { value: p, css: r } = a(c);
|
30
|
+
return r && s.push(r), p;
|
31
31
|
});
|
32
32
|
}), { result: t, additionalCss: s };
|
33
|
-
}, at = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${
|
33
|
+
}, at = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${R(n[1].replaceAll(".", "-"))})`) } : { result: t }, J = (t, e, s) => {
|
34
34
|
if (!t) return "";
|
35
|
-
const n = [], i = Object.entries(t).reduce((c, [
|
36
|
-
const o =
|
35
|
+
const n = [], i = Object.entries(t).reduce((c, [p, r]) => {
|
36
|
+
const o = p.trim();
|
37
37
|
if (typeof r == "function" && (r = r()), typeof r == "object") {
|
38
38
|
if (!r) return c;
|
39
39
|
if (o === "variants")
|
40
|
-
return Object.entries(r).forEach(([
|
41
|
-
|
40
|
+
return Object.entries(r).forEach(([P, $]) => {
|
41
|
+
$ && Object.entries($).forEach(([_, l]) => {
|
42
42
|
if (!l) return;
|
43
|
-
const
|
44
|
-
n.push(
|
43
|
+
const b = `${e}.${P}-${_}`, y = J(l, b);
|
44
|
+
n.push(y);
|
45
45
|
});
|
46
46
|
}), c;
|
47
47
|
if (o === "defaultVariants")
|
48
48
|
return c;
|
49
49
|
if (o === "compoundVariants")
|
50
|
-
return r.forEach((
|
51
|
-
const { css:
|
52
|
-
n.push(
|
50
|
+
return r.forEach((P) => {
|
51
|
+
const { css: $, ..._ } = P, l = Object.entries(_).reduce((y, [w, d]) => `${y}.${w}-${d}`, e), b = J($, l);
|
52
|
+
n.push(b);
|
53
53
|
}), c;
|
54
54
|
if (o.startsWith("@")) {
|
55
|
-
const
|
56
|
-
${
|
55
|
+
const P = J(r, e), $ = `${o} {
|
56
|
+
${P.replace(`
|
57
57
|
`, `
|
58
58
|
`)}
|
59
59
|
}`;
|
60
|
-
return n.push(
|
60
|
+
return n.push($), c;
|
61
61
|
}
|
62
|
-
const
|
62
|
+
const C = p.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, j = J(r, C);
|
63
63
|
return n.push(j), c;
|
64
64
|
}
|
65
|
-
const
|
66
|
-
if (typeof r == "number") return
|
65
|
+
const m = o.startsWith("-") ? o : R(o), g = (C, j = ";") => c = `${c}${C}${j}`, u = (C) => g(`${m}:${C}`);
|
66
|
+
if (typeof r == "number") return u(r);
|
67
67
|
if (typeof r != "string")
|
68
68
|
if ("toString" in r) r = r.toString();
|
69
69
|
else return c;
|
70
|
-
const { modifiers:
|
71
|
-
yield at(r), yield
|
70
|
+
const { modifiers: F } = {}, T = function* () {
|
71
|
+
yield at(r), yield kt(r, F);
|
72
72
|
}();
|
73
|
-
for (const { result:
|
74
|
-
r =
|
75
|
-
const
|
76
|
-
|
73
|
+
for (const { result: C, additionalCss: j = [] } of T)
|
74
|
+
r = C, j.forEach((P) => {
|
75
|
+
const $ = J(P, "");
|
76
|
+
g($, "");
|
77
77
|
});
|
78
|
-
return
|
78
|
+
return u(r);
|
79
79
|
}, "");
|
80
80
|
return i ? e ? [`${e} { ${i} }`, ...n].join(`
|
81
81
|
`) : i : n.join(`
|
@@ -86,40 +86,40 @@ const Dt = (t, e) => {
|
|
86
86
|
if (Object.entries(t).forEach(([i, a]) => {
|
87
87
|
if (typeof a == "object") {
|
88
88
|
if (!a) return;
|
89
|
-
const c = i.trim(),
|
90
|
-
s.push(
|
89
|
+
const c = i.trim(), p = lt(a, [...e, c]);
|
90
|
+
s.push(p);
|
91
91
|
} else
|
92
92
|
n[i] = a;
|
93
93
|
}), Object.keys(n).length) {
|
94
|
-
const i = e.map(
|
94
|
+
const i = e.map(R).join("-"), a = J(n, `.${i}`);
|
95
95
|
s.push(a);
|
96
96
|
}
|
97
97
|
return s.join(`
|
98
98
|
`);
|
99
|
-
},
|
99
|
+
}, Dt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = ft(n).map((i) => `"${i}"`).join(" | ")), e), {}) : {}, ft = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, i]) => {
|
100
100
|
const a = e ? `${e}.${n}` : n;
|
101
101
|
return typeof i == "object" ? ft(i, a, s) : s.add(e);
|
102
102
|
}), [...s]) : [], ut = (t) => {
|
103
103
|
if (!t || t === "/") throw new Error("Could not find package.json file");
|
104
104
|
const e = f(t, "package.json");
|
105
105
|
return v(e) ? e : ut(f(t, ".."));
|
106
|
-
},
|
106
|
+
}, Pt = async (t) => {
|
107
107
|
const e = ut(t);
|
108
108
|
return await tt(e, "utf-8").then(JSON.parse).catch(() => {
|
109
109
|
});
|
110
|
-
},
|
111
|
-
const e = await
|
110
|
+
}, Et = async (t) => {
|
111
|
+
const e = await Pt(t);
|
112
112
|
if (e)
|
113
113
|
return e.type;
|
114
114
|
};
|
115
|
-
let
|
115
|
+
let z;
|
116
116
|
const pt = async (t) => {
|
117
|
-
if (
|
118
|
-
const e = await
|
119
|
-
return e === "module" ?
|
120
|
-
},
|
117
|
+
if (z) return z;
|
118
|
+
const e = await Et(t);
|
119
|
+
return e === "module" ? z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (z = "cjs"), z || "esm";
|
120
|
+
}, Y = jt({
|
121
121
|
level: "debug",
|
122
|
-
format:
|
122
|
+
format: X.combine(X.colorize(), X.cli()),
|
123
123
|
transports: [new Ft.Console({})]
|
124
124
|
});
|
125
125
|
function dt(t) {
|
@@ -171,31 +171,31 @@ const Tt = {
|
|
171
171
|
fontSize: "100%",
|
172
172
|
lineHeight: "1.15em"
|
173
173
|
}
|
174
|
-
}, H = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}),
|
174
|
+
}, H = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), V = {
|
175
175
|
externalModules: [],
|
176
176
|
rcFile: void 0,
|
177
177
|
destDir: void 0
|
178
178
|
}, gt = (t) => {
|
179
|
-
if (
|
179
|
+
if (V.externalModules.length > 0) return V.externalModules;
|
180
180
|
const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
181
181
|
if (!s) return [];
|
182
182
|
const n = s[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
|
183
|
-
return
|
183
|
+
return V.externalModules = n, n;
|
184
184
|
}, A = async (t) => {
|
185
|
-
if (
|
185
|
+
if (V.destDir) return V.destDir;
|
186
186
|
const e = await et(t), s = f(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
187
|
-
return
|
188
|
-
},
|
189
|
-
if (
|
187
|
+
return V.destDir = s, s;
|
188
|
+
}, ht = ["salty", "css", "styles", "styled"], _t = (t = []) => new RegExp(`\\.(${[...ht, ...t].join("|")})\\.`), B = (t, e = []) => _t(e).test(t), mt = async (t) => {
|
189
|
+
if (V.rcFile) return V.rcFile;
|
190
190
|
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
191
191
|
const e = f(t, ".saltyrc.json"), s = await tt(e, "utf-8").then(JSON.parse).catch(() => {
|
192
192
|
});
|
193
|
-
return s ? (
|
193
|
+
return s ? (V.rcFile = s, s) : mt(f(t, ".."));
|
194
194
|
}, et = async (t) => {
|
195
195
|
var n, i;
|
196
|
-
const e = await
|
196
|
+
const e = await mt(t), s = (n = e.projects) == null ? void 0 : n.find((a) => t.endsWith(a.dir || ""));
|
197
197
|
return s || ((i = e.projects) == null ? void 0 : i.find((a) => a.dir === e.defaultProject));
|
198
|
-
},
|
198
|
+
}, Ot = async (t) => {
|
199
199
|
const e = await et(t), s = await A(t), n = f(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), i = f(s, "salty.config.js"), a = await pt(t), c = gt(n);
|
200
200
|
await ct.build({
|
201
201
|
entryPoints: [n],
|
@@ -206,61 +206,61 @@ const Tt = {
|
|
206
206
|
format: a,
|
207
207
|
external: c
|
208
208
|
});
|
209
|
-
const
|
209
|
+
const p = Date.now(), { config: r } = await import(`${i}?t=${p}`);
|
210
210
|
return r;
|
211
|
-
},
|
212
|
-
const s = await
|
211
|
+
}, Vt = async (t, e) => {
|
212
|
+
const s = await Ot(t), n = { ...s }, i = /* @__PURE__ */ new Set(), a = (D, x = []) => D ? Object.entries(D).flatMap(([O, E]) => {
|
213
213
|
if (!E) return;
|
214
|
-
if (typeof E == "object") return a(E, [...
|
215
|
-
const W = dt(
|
216
|
-
i.add(`"${
|
217
|
-
const
|
218
|
-
return `--${
|
219
|
-
}) : [], c = (
|
220
|
-
const E = a(
|
221
|
-
return
|
222
|
-
}) : [],
|
223
|
-
const
|
224
|
-
return `${
|
225
|
-
})) : [], r = (
|
226
|
-
|
227
|
-
const T = f(
|
228
|
-
|
229
|
-
const
|
230
|
-
P
|
231
|
-
const
|
232
|
-
|
233
|
-
const
|
214
|
+
if (typeof E == "object") return a(E, [...x, O]);
|
215
|
+
const W = dt(O), q = R(O), Q = [...x, W].join(".");
|
216
|
+
i.add(`"${Q}"`);
|
217
|
+
const U = [...x.map(R), q].join("-"), { result: $t } = at(E);
|
218
|
+
return `--${U}: ${$t};`;
|
219
|
+
}) : [], c = (D) => D ? Object.entries(D).flatMap(([x, O]) => {
|
220
|
+
const E = a(O);
|
221
|
+
return x === "base" ? E.join("") : `${x} { ${E.join("")} }`;
|
222
|
+
}) : [], p = (D) => D ? Object.entries(D).flatMap(([x, O]) => Object.entries(O).flatMap(([E, W]) => {
|
223
|
+
const q = a(W, [x]), Q = `.${x}-${E}, [data-${x}="${E}"]`, U = q.join("");
|
224
|
+
return `${Q} { ${U} }`;
|
225
|
+
})) : [], r = (D) => e.variables.map((x) => x._current[D]), o = a(H(s.variables, r("variables"))), m = c(H(s.responsiveVariables, r("responsiveVariables"))), g = p(H(s.conditionalVariables, r("conditionalVariables"))), u = await A(t), F = f(u, "css/_variables.css"), N = `:root { ${o.join("")} ${m.join("")} } ${g.join("")}`;
|
226
|
+
k(F, N);
|
227
|
+
const T = f(u, "css/_global.css"), C = H(s.global, e.globalStyles), j = J(C, "");
|
228
|
+
k(T, `@layer global { ${j} }`);
|
229
|
+
const P = f(u, "css/_reset.css"), _ = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Tt, l = J(_, "");
|
230
|
+
k(P, `@layer reset { ${l} }`);
|
231
|
+
const b = f(u, "css/_templates.css"), y = H(s.templates, e.templates), w = lt(y), d = Dt(y);
|
232
|
+
k(b, w), n.templates = y;
|
233
|
+
const S = f(u, "types/css-tokens.d.ts"), G = `
|
234
234
|
// Variable types
|
235
235
|
type VariableTokens = ${[...i].join("|")};
|
236
236
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
237
237
|
|
238
238
|
// Template types
|
239
239
|
type TemplateTokens = {
|
240
|
-
${Object.entries(
|
240
|
+
${Object.entries(d).map(([D, x]) => `${D}?: ${x}`).join(`
|
241
241
|
`)}
|
242
242
|
}
|
243
243
|
`;
|
244
|
-
|
245
|
-
const L = f(
|
246
|
-
|
244
|
+
k(S, G);
|
245
|
+
const L = f(u, "cache/config-cache.json");
|
246
|
+
k(L, JSON.stringify(n, null, 2));
|
247
247
|
}, rt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
248
248
|
if (/^['"`]/.test(s)) return e;
|
249
249
|
const i = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
250
250
|
if (!i.test(t)) return e;
|
251
251
|
const c = i.exec(t);
|
252
252
|
if (c) {
|
253
|
-
const
|
254
|
-
if (
|
253
|
+
const p = c.at(1);
|
254
|
+
if (ht.some((o) => p == null ? void 0 : p.includes(o))) return e;
|
255
255
|
}
|
256
256
|
return "styled('div',";
|
257
257
|
}), st = async (t, e, s) => {
|
258
|
-
const n =
|
259
|
-
v(i) ||
|
260
|
-
const a =
|
258
|
+
const n = I(e), i = f(s, "./temp");
|
259
|
+
v(i) || Z(i);
|
260
|
+
const a = K(e);
|
261
261
|
let c = M(e, "utf8");
|
262
262
|
c = rt(c);
|
263
|
-
const
|
263
|
+
const p = f(s, "js", n + ".js"), r = await et(t), o = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), m = gt(o), g = await pt(t);
|
264
264
|
await ct.build({
|
265
265
|
stdin: {
|
266
266
|
contents: c,
|
@@ -271,26 +271,26 @@ const Tt = {
|
|
271
271
|
minify: !1,
|
272
272
|
treeShaking: !0,
|
273
273
|
bundle: !0,
|
274
|
-
outfile:
|
275
|
-
format:
|
274
|
+
outfile: p,
|
275
|
+
format: g,
|
276
276
|
target: ["node20"],
|
277
277
|
keepNames: !0,
|
278
|
-
external:
|
278
|
+
external: m,
|
279
279
|
packages: "external",
|
280
280
|
plugins: [
|
281
281
|
{
|
282
282
|
name: "test",
|
283
|
-
setup: (
|
284
|
-
|
285
|
-
const
|
286
|
-
return { contents: rt(
|
283
|
+
setup: (N) => {
|
284
|
+
N.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (T) => {
|
285
|
+
const C = M(T.path, "utf8");
|
286
|
+
return { contents: rt(C), loader: "ts" };
|
287
287
|
});
|
288
288
|
}
|
289
289
|
}
|
290
290
|
]
|
291
291
|
});
|
292
|
-
const
|
293
|
-
return await import(`${
|
292
|
+
const u = Date.now();
|
293
|
+
return await import(`${p}?t=${u}`);
|
294
294
|
}, Mt = async (t) => {
|
295
295
|
const e = await A(t), s = f(e, "cache/config-cache.json"), n = M(s, "utf8");
|
296
296
|
if (!n) throw new Error("Could not find config cache file");
|
@@ -298,72 +298,86 @@ const Tt = {
|
|
298
298
|
}, nt = async (t) => {
|
299
299
|
const e = await Mt(t), s = await A(t), n = f(s, "salty.config.js"), i = Date.now(), { config: a } = await import(`${n}?t=${i}`);
|
300
300
|
return H(a, e);
|
301
|
-
},
|
301
|
+
}, yt = () => {
|
302
302
|
try {
|
303
303
|
return process.env.NODE_ENV === "production";
|
304
304
|
} catch {
|
305
305
|
return !1;
|
306
306
|
}
|
307
|
-
}, Rt = async (t, e =
|
307
|
+
}, Rt = async (t, e = yt(), s = !0) => {
|
308
308
|
try {
|
309
309
|
const n = Date.now();
|
310
|
-
e ?
|
311
|
-
const i = [], a = [], c = await A(t),
|
310
|
+
e ? Y.info("Generating CSS in production mode! 🔥") : Y.info("Generating CSS in development mode! 🚀");
|
311
|
+
const i = [], a = [], c = await A(t), p = f(c, "index.css");
|
312
312
|
s && (() => {
|
313
|
-
v(c) && bt("rm -rf " + c),
|
313
|
+
v(c) && bt("rm -rf " + c), Z(c, { recursive: !0 }), Z(f(c, "css")), Z(f(c, "types")), Z(f(c, "js")), Z(f(c, "cache"));
|
314
314
|
})();
|
315
315
|
const o = {
|
316
316
|
keyframes: [],
|
317
317
|
mediaQueries: [],
|
318
318
|
globalStyles: [],
|
319
319
|
variables: [],
|
320
|
+
templates: [],
|
320
321
|
components: [],
|
321
|
-
|
322
|
+
classNames: []
|
322
323
|
};
|
323
|
-
async function
|
324
|
-
const
|
325
|
-
if (
|
326
|
-
const
|
327
|
-
if (
|
328
|
-
await Promise.all(
|
329
|
-
} else if (
|
330
|
-
const
|
331
|
-
Object.entries(
|
324
|
+
async function m(l) {
|
325
|
+
const b = ["node_modules", "saltygen"], y = wt(l);
|
326
|
+
if (y.isDirectory()) {
|
327
|
+
const w = St(l);
|
328
|
+
if (b.some((S) => l.includes(S))) return;
|
329
|
+
await Promise.all(w.map((S) => m(f(l, S))));
|
330
|
+
} else if (y.isFile() && B(l)) {
|
331
|
+
const d = await st(t, l, c);
|
332
|
+
Object.entries(d).forEach(([S, h]) => {
|
332
333
|
h.isKeyframes ? o.keyframes.push({
|
333
334
|
value: h,
|
334
335
|
src: l,
|
335
|
-
name:
|
336
|
-
}) : h.isMedia ? o.mediaQueries.push(h) : h.isGlobalDefine ? o.globalStyles.push(h) : h.isDefineVariables ? o.variables.push(h) : h.isDefineTemplates ? o.templates.push(h) : h.
|
336
|
+
name: S
|
337
|
+
}) : h.isMedia ? o.mediaQueries.push(h) : h.isGlobalDefine ? o.globalStyles.push(h) : h.isDefineVariables ? o.variables.push(h) : h.isDefineTemplates ? o.templates.push(h) : h.isClassName ? o.classNames.push({
|
338
|
+
value: h.factory,
|
339
|
+
src: l,
|
340
|
+
name: S
|
341
|
+
}) : h.generator && o.components.push({
|
337
342
|
value: h.generator,
|
338
343
|
src: l,
|
339
|
-
name:
|
344
|
+
name: S
|
340
345
|
});
|
341
346
|
});
|
342
347
|
}
|
343
348
|
}
|
344
|
-
await
|
345
|
-
const
|
349
|
+
await m(t), await Vt(t, o);
|
350
|
+
const g = await nt(t);
|
346
351
|
for (const l of o.keyframes) {
|
347
|
-
const { value:
|
348
|
-
i.push(
|
352
|
+
const { value: b } = l, y = `a_${b.animationName}.css`, w = `css/${y}`, d = f(c, w);
|
353
|
+
i.push(y), k(d, b.css);
|
349
354
|
}
|
350
|
-
const
|
355
|
+
const u = {};
|
351
356
|
for (const l of o.components) {
|
352
|
-
const { value:
|
353
|
-
name:
|
354
|
-
config:
|
357
|
+
const { value: b, name: y, src: w } = l, d = b._withBuildContext({
|
358
|
+
name: y,
|
359
|
+
config: g,
|
355
360
|
prod: e
|
356
361
|
});
|
357
|
-
a[
|
358
|
-
const
|
359
|
-
|
362
|
+
a[d.priority] || (a[d.priority] = []), a[d.priority].push(d.cssFileName);
|
363
|
+
const S = `css/${d.cssFileName}`, h = f(c, S);
|
364
|
+
k(h, d.css), g.importStrategy === "component" && (u[w] ? u[w].push(d.cssFileName) : u[w] = [d.cssFileName]);
|
360
365
|
}
|
361
|
-
|
362
|
-
const
|
363
|
-
|
364
|
-
|
366
|
+
for (const l of o.classNames) {
|
367
|
+
const { value: b, src: y, name: w } = l, d = b._withBuildContext({
|
368
|
+
name: w,
|
369
|
+
prod: e
|
370
|
+
});
|
371
|
+
a[0].push(d.cssFileName);
|
372
|
+
const S = `css/${d.cssFileName}`, h = f(c, S);
|
373
|
+
k(h, d.css), g.importStrategy === "component" && (u[y] ? u[y].push(d.cssFileName) : u[y] = [d.cssFileName]);
|
374
|
+
}
|
375
|
+
g.importStrategy === "component" && Object.entries(u).forEach(([l, b]) => {
|
376
|
+
const y = b.map((G) => `@import url('./${G}');`).join(`
|
377
|
+
`), w = I(l, 6), d = K(l), S = R(d.name), h = f(c, `css/f_${S}-${w}.css`);
|
378
|
+
k(h, y);
|
365
379
|
});
|
366
|
-
const
|
380
|
+
const F = i.map((l) => `@import url('./css/${l}');`).join(`
|
367
381
|
`);
|
368
382
|
let j = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
369
383
|
|
@@ -375,102 +389,117 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) =
|
|
375
389
|
}
|
376
390
|
}).map((l) => `@import url('./css/${l}');`).join(`
|
377
391
|
`)}
|
378
|
-
${
|
379
|
-
if (
|
380
|
-
const l = a.reduce((
|
381
|
-
const
|
392
|
+
${F}`;
|
393
|
+
if (g.importStrategy !== "component") {
|
394
|
+
const l = a.reduce((b, y, w) => {
|
395
|
+
const d = y.reduce((L, D) => {
|
382
396
|
var W;
|
383
|
-
const
|
397
|
+
const x = f(c, "css", D), O = M(x, "utf8"), E = ((W = /.*-([^-]+)-\d+.css/.exec(D)) == null ? void 0 : W.at(1)) || I(x, 6);
|
384
398
|
return L.includes(E) ? L : `${L}
|
385
399
|
/*start:${E}*/
|
386
|
-
${
|
400
|
+
${O}
|
387
401
|
/*end:${E}*/
|
388
402
|
`;
|
389
|
-
}, ""),
|
403
|
+
}, ""), S = `l_${w}.css`, h = f(c, "css", S), G = `@layer l${w} { ${d}
|
390
404
|
}`;
|
391
|
-
return
|
392
|
-
@import url('./css/${
|
405
|
+
return k(h, G), `${b}
|
406
|
+
@import url('./css/${S}');`;
|
393
407
|
}, "");
|
394
408
|
j += l;
|
395
409
|
}
|
396
|
-
|
397
|
-
const
|
398
|
-
|
410
|
+
k(p, j);
|
411
|
+
const $ = Date.now() - n, _ = $ < 200 ? "🔥" : $ < 500 ? "🚀" : $ < 1e3 ? "🎉" : $ < 2e3 ? "🚗" : $ < 5e3 ? "🤔" : "🥴";
|
412
|
+
Y.info(`Generated CSS in ${$}ms! ${_}`);
|
399
413
|
} catch (n) {
|
400
414
|
console.error(n);
|
401
415
|
}
|
402
416
|
}, Jt = async (t, e) => {
|
403
417
|
try {
|
404
418
|
const s = await A(t);
|
405
|
-
if (
|
419
|
+
if (B(e)) {
|
406
420
|
const i = [], a = await nt(t), c = await st(t, e, s);
|
407
|
-
Object.entries(c).forEach(([
|
421
|
+
if (Object.entries(c).forEach(([p, r]) => {
|
408
422
|
if (r.isKeyframes && r.css) {
|
409
|
-
const
|
410
|
-
|
423
|
+
const F = `css/${`a_${r.animationName}.css`}`, N = f(s, F);
|
424
|
+
k(N, r.css);
|
411
425
|
return;
|
412
426
|
}
|
427
|
+
if (r.isClassName) {
|
428
|
+
console.log("found className value", r);
|
429
|
+
const u = r.factory._withBuildContext({
|
430
|
+
name: p
|
431
|
+
});
|
432
|
+
i[0].push(u.cssFileName);
|
433
|
+
const F = `css/${u.cssFileName}`, N = f(s, F);
|
434
|
+
k(N, u.css), console.log(N, u.css);
|
435
|
+
}
|
413
436
|
if (!r.generator) return;
|
414
437
|
const o = r.generator._withBuildContext({
|
415
|
-
name:
|
438
|
+
name: p,
|
416
439
|
config: a
|
417
|
-
}),
|
418
|
-
|
419
|
-
}), a.importStrategy !== "component"
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
440
|
+
}), m = `css/${o.cssFileName}`, g = f(s, m);
|
441
|
+
k(g, o.css), i[o.priority] || (i[o.priority] = []), i[o.priority].push(o.cssFileName);
|
442
|
+
}), console.log(i), a.importStrategy !== "component")
|
443
|
+
i.forEach((p, r) => {
|
444
|
+
const o = `l_${r}.css`, m = f(s, "css", o);
|
445
|
+
let g = M(m, "utf8");
|
446
|
+
p.forEach((u) => {
|
447
|
+
var C;
|
448
|
+
const F = f(s, "css", u), N = ((C = /.*-([^-]+)-\d+.css/.exec(u)) == null ? void 0 : C.at(1)) || I(F, 6);
|
449
|
+
if (!g.includes(N)) {
|
450
|
+
const j = M(F, "utf8"), P = `/*start:${N}*/
|
427
451
|
${j}
|
428
|
-
/*end:${
|
452
|
+
/*end:${N}*/
|
429
453
|
`;
|
430
|
-
|
431
|
-
${
|
454
|
+
g = `${g.replace(/\}$/, "")}
|
455
|
+
${P}
|
432
456
|
}`;
|
433
|
-
|
434
|
-
|
435
|
-
|
457
|
+
}
|
458
|
+
}), k(m, g);
|
459
|
+
});
|
460
|
+
else {
|
461
|
+
const p = i.flat().map((u) => `@import url('./${u}');`).join(`
|
462
|
+
`), r = I(e, 6), o = K(e), m = R(o.name), g = f(s, `css/f_${m}-${r}.css`);
|
463
|
+
k(g, p);
|
464
|
+
}
|
436
465
|
}
|
437
466
|
} catch (s) {
|
438
467
|
console.error(s);
|
439
468
|
}
|
440
|
-
}, At = async (t, e, s =
|
469
|
+
}, At = async (t, e, s = yt()) => {
|
441
470
|
try {
|
442
471
|
const n = await A(t);
|
443
|
-
if (
|
472
|
+
if (B(e)) {
|
444
473
|
const a = M(e, "utf8");
|
445
|
-
a.replace(/^(?!export\s)const\s.*/gm, (
|
446
|
-
const
|
474
|
+
a.replace(/^(?!export\s)const\s.*/gm, (m) => `export ${m}`) !== a && await Ct(e, a);
|
475
|
+
const p = await nt(t), r = await st(t, e, n);
|
447
476
|
let o = a;
|
448
|
-
if (Object.entries(r).forEach(([
|
449
|
-
var
|
450
|
-
if (
|
451
|
-
const
|
452
|
-
name:
|
453
|
-
config:
|
477
|
+
if (Object.entries(r).forEach(([m, g]) => {
|
478
|
+
var S;
|
479
|
+
if (g.isKeyframes || !g.generator) return;
|
480
|
+
const u = g.generator._withBuildContext({
|
481
|
+
name: m,
|
482
|
+
config: p,
|
454
483
|
prod: s
|
455
|
-
}),
|
456
|
-
if (!
|
457
|
-
const
|
484
|
+
}), F = new RegExp(`\\s${m}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
|
485
|
+
if (!F) return console.error("Could not find the original declaration");
|
486
|
+
const N = (S = F.at(1)) == null ? void 0 : S.trim(), T = new RegExp(`\\s${m}[=\\s]+styled\\(`, "g").exec(o);
|
458
487
|
if (!T) return console.error("Could not find the original declaration");
|
459
|
-
const { index:
|
488
|
+
const { index: C } = T;
|
460
489
|
let j = !1;
|
461
|
-
const
|
462
|
-
let
|
463
|
-
for (; !
|
464
|
-
const h = o[
|
465
|
-
h === "(" && l++, h === ")" && l--, l === 0 && h === ")" && (
|
490
|
+
const P = setTimeout(() => j = !0, 5e3);
|
491
|
+
let $ = 0, _ = !1, l = 0;
|
492
|
+
for (; !_ && !j; ) {
|
493
|
+
const h = o[C + $];
|
494
|
+
h === "(" && l++, h === ")" && l--, l === 0 && h === ")" && (_ = !0), $ > o.length && (j = !0), $++;
|
466
495
|
}
|
467
|
-
if (!j) clearTimeout(
|
496
|
+
if (!j) clearTimeout(P);
|
468
497
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
469
|
-
const
|
470
|
-
o = o.replace(
|
471
|
-
}),
|
472
|
-
const
|
473
|
-
o = `import '../../saltygen/css/${`f_${
|
498
|
+
const b = C + $, y = o.slice(C, b), w = o, d = ` ${m} = styled(${N}, "${u.classNames}", ${JSON.stringify(u.props)});`;
|
499
|
+
o = o.replace(y, d), w === o && console.error("Minimize file failed to change content", { name: m, tagName: N });
|
500
|
+
}), p.importStrategy === "component") {
|
501
|
+
const m = I(e, 6), g = K(e);
|
502
|
+
o = `import '../../saltygen/css/${`f_${R(g.name)}-${m}.css`}';
|
474
503
|
${o}`;
|
475
504
|
}
|
476
505
|
return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
@@ -481,14 +510,14 @@ ${o}`;
|
|
481
510
|
}, it = async (t) => {
|
482
511
|
if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
|
483
512
|
if (t.includes("salty.config")) return !0;
|
484
|
-
if (!
|
513
|
+
if (!B(t)) return !1;
|
485
514
|
const n = await tt(t, "utf-8");
|
486
515
|
return !!/.+define[A-Z]\w+/.test(n);
|
487
|
-
},
|
516
|
+
}, Bt = (t) => ({
|
488
517
|
name: "stylegen",
|
489
518
|
buildStart: () => Rt(t),
|
490
519
|
load: async (e) => {
|
491
|
-
if (
|
520
|
+
if (B(e))
|
492
521
|
return await At(t, e);
|
493
522
|
},
|
494
523
|
handleHotUpdate: async ({ file: e, server: s }) => {
|
@@ -496,11 +525,11 @@ ${o}`;
|
|
496
525
|
},
|
497
526
|
watchChange: {
|
498
527
|
handler: async (e) => {
|
499
|
-
|
528
|
+
B(e) && (await it(e) || await Jt(t, e));
|
500
529
|
}
|
501
530
|
}
|
502
531
|
});
|
503
532
|
export {
|
504
|
-
|
505
|
-
|
533
|
+
Bt as default,
|
534
|
+
Bt as saltyPlugin
|
506
535
|
};
|
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.186",
|
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.186"
|
38
38
|
}
|
39
39
|
}
|