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