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