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