@salty-css/core 0.0.1-alpha.288 → 0.0.1-alpha.289

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.
@@ -1,41 +0,0 @@
1
- "use strict";const Oe=require("esbuild"),Ve=require("child_process"),T=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),we=require("fs/promises"),ae=require("./parse-styles-DZYIEhB4.cjs"),he=require("./parsers/index.cjs"),Q=require("winston"),J=require("./css/merge.cjs"),Ee=require("./define-templates-Cunsb_Tr.cjs"),ce=require("typescript"),je=require("./helpers-DER54FsO.cjs");var re=typeof document<"u"?document.currentScript:null;function Re(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 be=Re(Oe),Fe=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=i.join(e,"package.json");return c.existsSync(t)?t:Fe(i.join(e,".."))},Me=async e=>{const t=Fe(e);return await we.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Je=async e=>{const t=await Me(e);if(t)return t.type};let H;const $e=async e=>{if(H)return H;const t=await Je(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:re&&re.tagName.toUpperCase()==="SCRIPT"&&re.src||new URL("index-DA5ISFwd.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},B=Q.createLogger({level:"debug",format:Q.format.combine(Q.format.colorize(),Q.format.cli()),transports:[new Q.transports.Console({})]}),qe=e=>{B.error(e)};function Ce(e){return e?typeof e!="string"?Ce(String(e)):e.replace(/[^\d\w]/g,"."):""}const ze={"*, *::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"}},He=(e,t)=>new Promise((s,n)=>{const r=setTimeout(()=>{n(new Error("Timeout"))},100),l=ce.createSourceFile("temp.ts",e,ce.ScriptTarget.Latest,!0);function o(y){if(ce.isVariableDeclaration(y)&&y.name.getText()===t){const w=y.getStart(),m=y.getEnd();clearTimeout(r),s([w,m])}y.forEachChild(o)}o(l)}),O={externalModules:[],rcFile:void 0,destDir:void 0},Pe=e=>{if(O.externalModules.length>0)return O.externalModules;const s=c.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return O.externalModules=n,n},q=async e=>{if(O.destDir)return O.destDir;const t=await fe(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return O.destDir=s,s},le=["salty","css","styles","styled"],Ne=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),Z=(e,t=[])=>Ne(t).test(e),xe=async e=>{if(O.rcFile)return O.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=i.join(e,".saltyrc.json"),s=await we.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(O.rcFile=s,s):xe(i.join(e,".."))},fe=async e=>{var n,r;const t=await xe(e),s=(n=t.projects)==null?void 0:n.find(l=>e.endsWith(l.dir||""));return s||((r=t.projects)==null?void 0:r.find(l=>l.dir===t.defaultProject))},We=async e=>{const t=await fe(e),s=await q(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=i.join(s,"salty.config.js"),l=await $e(e),o=Pe(n);await be.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:l,external:o});const y=Date.now(),{config:w}=await import(`${r}?t=${y}`);return{config:w,path:r}},ke=async(e,t)=>{var de,ye;const s=await q(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async S=>{const{contents:$,outputFilePath:K}=await U(e,S,s);Object.entries($).forEach(([D,P])=>{P.isMedia?n.mediaQueries.push([D,P]):P.isGlobalDefine?n.globalStyles.push(P):P.isDefineVariables?n.variables.push(P):P.isDefineTemplates&&n.templates.push(P._setPath(`${D};;${K}`))})}));const{config:r,path:l}=await We(e),o={...r},{mediaQueries:y}=n;o.mediaQueries=Object.fromEntries(y.map(([S,$])=>[`@${S}`,$]));const w=y.map(([S])=>`'@${S}'`).join(" | "),m=new Set,a=async(S,$=[])=>{if(!S)return[];const K=Object.entries(S).map(async([P,M])=>{const L=async v=>{if(!v)return;if(v instanceof Promise)return await L(await v);if(typeof v=="function")return await L(await v());if(typeof v=="object")return await a(v,[...$,P]);const ne=Ce(P),oe=T.dashCase(P),ie=[...$,ne].join(".");m.add(`"${ie}"`);const Y=[...$.map(T.dashCase),oe].join("-"),ge=ae.parseVariableTokens(v);return ge?`--${Y}: ${ge.transformed};`:`--${Y}: ${v};`};return await L(M)});return(await Promise.all(K)).flat()},g=async S=>{if(!S)return[];const $=Object.entries(S).map(async([D,P])=>{const M=await a(P);return D==="base"?M.join(""):o.mediaQueries[D]?`${o.mediaQueries[D]} { ${M.join("")} }`:`${D} { ${M.join("")} }`});return(await Promise.all($)).flat()},d=async S=>{if(!S)return[];const $=Object.entries(S).map(async([D,P])=>{const M=Object.entries(P).map(async([v,ne])=>{const oe=await a(ne,[D]),ie=`.${D}-${v}, [data-${D}="${v}"]`,Y=oe.join("");return`${ie} { ${Y} }`});return(await Promise.all(M)).flat()});return(await Promise.all($)).flat()},h=S=>({...S,responsive:void 0,conditional:void 0}),p=S=>n.variables.map($=>S==="static"?h($._current):$._current[S]),C=J.mergeObjects(h(r.variables),p("static")),x=await a(C),k=J.mergeObjects((de=r.variables)==null?void 0:de.responsive,p("responsive")),V=await g(k),z=J.mergeObjects((ye=r.variables)==null?void 0:ye.conditional,p("conditional")),A=await d(z),me=i.join(s,"css/_variables.css"),E=`:root { ${x.join("")} ${V.join("")} } ${A.join("")}`;c.writeFileSync(me,E),o.staticVariables=C;const ee=i.join(s,"css/_global.css"),f=J.mergeObjects(r.global,n.globalStyles),j=await ae.parseAndJoinStyles(f,"");c.writeFileSync(ee,`@layer global { ${j} }`);const F=i.join(s,"css/_reset.css"),b=r.reset==="none"?{}:typeof r.reset=="object"?r.reset:ze,N=await ae.parseAndJoinStyles(b,"");c.writeFileSync(F,`@layer reset { ${N} }`);const _=i.join(s,"css/_templates.css"),R=J.mergeObjects(r.templates,n.templates),W=await he.parseTemplates(R),I=he.getTemplateTypes(R);c.writeFileSync(_,`@layer templates { ${W} }`),o.templates=R;const X=r.templates?[Ee.defineTemplates(r.templates)._setPath(`config;;${l}`)]:[],te=J.mergeFactories(n.templates,X);o.templatePaths=Object.fromEntries(Object.entries(te).map(([S,$])=>[S,$._path]));const G=i.join(s,"types/css-tokens.d.ts"),De=`
2
- // Variable types
3
- type VariableTokens = ${[...m].join("|")};
4
- type PropertyValueToken = \`{\${VariableTokens}}\`;
5
-
6
- // Template types
7
- type TemplateTokens = {
8
- ${Object.entries(I).map(([S,$])=>`${S}?: ${$}`).join(`
9
- `)}
10
- }
11
-
12
- // Media query types
13
- type MediaQueryKeys = ${w||"''"};
14
- `;c.writeFileSync(G,De);const ve=i.join(s,"cache/config-cache.json");c.writeFileSync(ve,JSON.stringify(o,null,2));const Te=je.getCorePackageRoot(),_e=i.join(Te,"cache/config-cache.json");c.writeFileSync(_e,JSON.stringify(o,null,2))},Se=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const r=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!r.test(e))return t;const o=r.exec(e);if(o){const y=o.at(1);if(le.some(m=>y==null?void 0:y.includes(m)))return t}return"styled('div',"}),Ie=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
15
-
16
- ${e}`:`globalThis.saltyConfig = {};
17
-
18
- ${e}`}catch{return e}},U=async(e,t,s)=>{const n=T.toHash(t),r=i.join(s,"./temp");c.existsSync(r)||c.mkdirSync(r);const l=i.parse(t);let o=c.readFileSync(t,"utf8");o=Se(o),o=Ie(o,e);const y=i.join(s,"js",n+".js"),w=await fe(e),m=i.join(e,(w==null?void 0:w.configDir)||"","salty.config.ts"),a=Pe(m),g=await $e(e);await be.build({stdin:{contents:o,sourcefile:l.base,resolveDir:l.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:a,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},C=>{const x=c.readFileSync(C.path,"utf8");return{contents:Se(x),loader:"ts"}})}}]});const d=Date.now();return{contents:await import(`${y}?t=${d}`),outputFilePath:y}},Ge=async e=>{const t=await q(e),s=i.join(t,"cache/config-cache.json"),n=c.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ue=async e=>{const t=await Ge(e),s=await q(e),n=i.join(s,"salty.config.js"),r=Date.now(),{config:l}=await import(`${n}?t=${r}`);return J.mergeObjects(l,t)},pe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ke=async(e,t=pe(),s=!0)=>{try{const n=Date.now();t?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const r=[],l=[],o=await q(e),y=i.join(o,"index.css");s&&(()=>{c.existsSync(o)&&Ve.execSync("rm -rf "+o),c.mkdirSync(o,{recursive:!0}),c.mkdirSync(i.join(o,"css")),c.mkdirSync(i.join(o,"types")),c.mkdirSync(i.join(o,"js")),c.mkdirSync(i.join(o,"cache"))})();const m=new Set,a=new Set;async function g(f){const j=["node_modules","saltygen"],F=c.statSync(f);if(F.isDirectory()){const u=c.readdirSync(f);if(j.some(N=>f.includes(N)))return;await Promise.all(u.map(N=>g(i.join(f,N))))}else if(F.isFile()&&Z(f)){m.add(f);const b=c.readFileSync(f,"utf8");/define[\w\d]+\(/.test(b)&&a.add(f)}}await g(e),await ke(e,a);const d={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async f=>{const{contents:j}=await U(e,f,o);for(let[F,u]of Object.entries(j)){const b=await je.resolveValue(u,1);b.isKeyframes?d.keyframes.push({value:b,src:f,name:F}):b.isClassName?d.classNames.push({...u,src:f,name:F}):b.generator&&d.components.push({...u,src:f,name:F})}}));const h=await ue(e);for(const f of d.keyframes){const{value:j}=f,F=`a_${j.animationName}.css`,u=`css/${F}`,b=i.join(o,u);r.push(F),c.writeFileSync(b,j.css)}const p={};for(const f of d.components){const{src:j,name:F}=f;p[j]||(p[j]=[]);const u=f.generator._withBuildContext({callerName:F,isProduction:t,config:h});l[u.priority]||(l[u.priority]=[]);const b=await u.css;if(!b)continue;l[u.priority].push(u.cssFileName);const N=`css/${u.cssFileName}`,_=i.join(o,N);c.writeFileSync(_,b),h.importStrategy==="component"&&p[j].push(u.cssFileName)}for(const f of d.classNames){const{src:j,name:F}=f;p[j]||(p[j]=[]);const u=f.generator._withBuildContext({callerName:F,isProduction:t,config:h}),b=await u.css;if(!b)continue;l[u.priority]||(l[u.priority]=[]),l[u.priority].push(u.cssFileName);const N=`css/${u.cssFileName}`,_=i.join(o,N);c.writeFileSync(_,b),h.importStrategy==="component"&&p[j].push(u.cssFileName)}h.importStrategy==="component"&&Object.entries(p).forEach(([f,j])=>{const F=j.map(R=>`@import url('./${R}');`).join(`
19
- `),u=T.toHash(f,6),b=i.parse(f),N=T.dashCase(b.name),_=i.join(o,`css/f_${N}-${u}.css`);c.writeFileSync(_,F||"/* Empty file */")});const C=r.map(f=>`@import url('./css/${f}');`).join(`
20
- `);let A=`/*!
21
- * Generated with Salty CSS (https://salty-css.dev)
22
- * Do not edit this file directly
23
- */
24
- @layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
25
-
26
- ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return c.readFileSync(i.join(o,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
27
- `)}
28
- ${C}`;if(h.importStrategy!=="component"){const f=l.reduce((j,F,u)=>{const b=F.reduce((W,I)=>{var se;const X=i.join(o,"css",I),te=c.readFileSync(X,"utf8"),G=((se=/.*-([^-]+)-\d+.css/.exec(I))==null?void 0:se.at(1))||T.toHash(X,6);return W.includes(G)?W:`${W}
29
- /*start:${G}-${I}*/
30
- ${te}
31
- /*end:${G}*/
32
- `},""),N=`l_${u}.css`,_=i.join(o,"css",N),R=`@layer l${u} { ${b}
33
- }`;return c.writeFileSync(_,R),`${j}
34
- @import url('./css/${N}');`},"");A+=f}c.writeFileSync(y,A);const E=Date.now()-n,ee=E<200?"🔥":E<500?"🚀":E<1e3?"🎉":E<2e3?"🚗":E<5e3?"🤔":"🥴";B.info(`Generated CSS in ${E}ms! ${ee}`)}catch(n){console.error(n)}},Le=async(e,t,s=pe())=>{try{const n=await q(e);if(Z(t)){const l=[],o=await ue(e),{contents:y}=await U(e,t,n);for(const[w,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const C=`css/${`a_${m.animationName}.css`}`,x=i.join(n,C);c.writeFileSync(x,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:w,isProduction:s,config:o}),C=await p.css;if(!C)continue;l[p.priority]||(l[p.priority]=[]),l[p.priority].push(p.cssFileName);const x=`css/${p.cssFileName}`,k=i.join(n,x);c.writeFileSync(k,C);continue}if(!m.generator)continue;const a=m.generator._withBuildContext({callerName:w,isProduction:s,config:o}),g=await a.css;if(!g)continue;const d=`css/${a.cssFileName}`,h=i.join(n,d);c.writeFileSync(h,g),l[a.priority]||(l[a.priority]=[]),l[a.priority].push(a.cssFileName)}if(o.importStrategy!=="component")l.forEach((w,m)=>{const a=`l_${m}.css`,g=i.join(n,"css",a);let d=c.readFileSync(g,"utf8");w.forEach(h=>{var k;const p=i.join(n,"css",h),C=((k=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:k.at(1))||T.toHash(p,6);if(!d.includes(C)){const V=c.readFileSync(p,"utf8"),z=`/*start:${C}-${h}*/
35
- ${V}
36
- /*end:${C}*/
37
- `;d=`${d.replace(/\}$/,"")}
38
- ${z}
39
- }`}}),c.writeFileSync(g,d)});else{const w=l.flat().map(h=>`@import url('./${h}');`).join(`
40
- `),m=T.toHash(t,6),a=i.parse(t),g=T.dashCase(a.name),d=i.join(n,`css/f_${g}-${m}.css`);c.writeFileSync(d,w||"/* Empty file */")}}}catch(n){console.error(n)}},Qe=async(e,t,s=pe())=>{var n,r;try{const l=await q(e);if(Z(t)){const y=c.readFileSync(t,"utf8"),w=await ue(e),{contents:m}=await U(e,t,l);let a=y;for(const[g,d]of Object.entries(m)){if(d.isKeyframes||!d.generator)continue;const h=d.generator._withBuildContext({callerName:g,isProduction:s,config:w}),[p,C]=await He(a,g),x=a.slice(p,C);if(d.isClassName){const k=a,V=` ${g} = className("${h.classNames}")`;a=a.replace(x,V),k===a&&console.error("Minimize file failed to change content",{name:g})}if(x.includes("styled")){const k=(r=(n=/styled\(([^,]+),/.exec(x))==null?void 0:n.at(1))==null?void 0:r.trim(),V=a,z=` ${g} = styled(${k}, "${h.classNames}", ${JSON.stringify(h.clientProps)})`;a=a.replace(x,z),V===a&&console.error("Minimize file failed to change content",{name:g,tagName:k})}}if(w.importStrategy==="component"){const g=T.toHash(t,6),d=i.parse(t);a=`import '../../saltygen/css/${`f_${T.dashCase(d.name)}-${g}.css`}';
41
- ${a}`}return a=a.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),a=a.replace("{ styled }","{ styledClient as styled }"),a=a.replace("@salty-css/react/styled","@salty-css/react/styled-client"),a}}catch(l){console.error("Error in minimizeFile:",l)}};exports.compileSaltyFile=U;exports.generateConfigStyles=ke;exports.generateCss=Ke;exports.generateFile=Le;exports.isSaltyFile=Z;exports.logError=qe;exports.logger=B;exports.minimizeFile=Qe;exports.saltyFileExtensions=le;exports.saltyFileRegExp=Ne;
package/index-NweiKqJ2.js DELETED
@@ -1,522 +0,0 @@
1
- import * as St from "esbuild";
2
- import { execSync as Vt } from "child_process";
3
- import { t as I, d as A } from "./dash-case-DBThphLm.js";
4
- import { join as i, parse as tt } from "path";
5
- import { existsSync as ft, mkdirSync as G, statSync as Et, readdirSync as Ot, readFileSync as T, writeFileSync as F } from "fs";
6
- import { readFile as Ct } from "fs/promises";
7
- import { p as $t, a as Mt } from "./parse-styles-DLPgVsVQ.js";
8
- import { parseTemplates as Rt, getTemplateTypes as Jt } from "./parsers/index.js";
9
- import { createLogger as zt, transports as Wt, format as rt } from "winston";
10
- import { mergeObjects as H, mergeFactories as Gt } from "./css/merge.js";
11
- import { d as Ht } from "./define-templates-4A2yHcMF.js";
12
- import lt from "typescript";
13
- import { r as It, g as Kt } from "./helpers-f73tgqcY.js";
14
- const Ft = (t) => {
15
- if (!t || t === "/") throw new Error("Could not find package.json file");
16
- const e = i(t, "package.json");
17
- return ft(e) ? e : Ft(i(t, ".."));
18
- }, Qt = async (t) => {
19
- const e = Ft(t);
20
- return await Ct(e, "utf-8").then(JSON.parse).catch(() => {
21
- });
22
- }, Bt = async (t) => {
23
- const e = await Qt(t);
24
- if (e)
25
- return e.type;
26
- };
27
- let W;
28
- const Pt = async (t) => {
29
- if (W) return W;
30
- const e = await Bt(t);
31
- return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
32
- }, Z = zt({
33
- level: "debug",
34
- format: rt.combine(rt.colorize(), rt.cli()),
35
- transports: [new Wt.Console({})]
36
- }), pe = (t) => {
37
- Z.error(t);
38
- };
39
- function jt(t) {
40
- return t ? typeof t != "string" ? jt(String(t)) : t.replace(/[^\d\w]/g, ".") : "";
41
- }
42
- const Lt = {
43
- /** Set box model to border-box */
44
- "*, *::before, *::after": {
45
- boxSizing: "border-box"
46
- },
47
- /** Remove default margin and padding */
48
- "*": {
49
- margin: 0
50
- },
51
- /** Remove adjust font properties */
52
- html: {
53
- lineHeight: 1.15,
54
- textSizeAdjust: "100%",
55
- WebkitFontSmoothing: "antialiased"
56
- },
57
- /** Make media elements responsive */
58
- "img, picture, video, canvas, svg": {
59
- display: "block",
60
- maxWidth: "100%"
61
- },
62
- /** Avoid overflow of text */
63
- "p, h1, h2, h3, h4, h5, h6": {
64
- overflowWrap: "break-word"
65
- },
66
- /** Improve text wrapping */
67
- p: {
68
- textWrap: "pretty"
69
- },
70
- "h1, h2, h3, h4, h5, h6": {
71
- textWrap: "balance"
72
- },
73
- /** Improve link color */
74
- a: {
75
- color: "currentColor"
76
- },
77
- /** Improve button line height */
78
- button: {
79
- lineHeight: "1em",
80
- color: "currentColor"
81
- },
82
- /** Improve form elements */
83
- "input, optgroup, select, textarea": {
84
- fontFamily: "inherit",
85
- fontSize: "100%",
86
- lineHeight: "1.15em"
87
- }
88
- }, qt = (t, e) => new Promise((s, n) => {
89
- const c = setTimeout(() => {
90
- n(new Error("Timeout"));
91
- }, 100), r = lt.createSourceFile("temp.ts", t, lt.ScriptTarget.Latest, !0);
92
- function o(d) {
93
- if (lt.isVariableDeclaration(d) && d.name.getText() === e) {
94
- const w = d.getStart(), p = d.getEnd();
95
- clearTimeout(c), s([w, p]);
96
- }
97
- d.forEachChild(o);
98
- }
99
- o(r);
100
- }), V = {
101
- externalModules: [],
102
- rcFile: void 0,
103
- destDir: void 0
104
- }, Nt = (t) => {
105
- if (V.externalModules.length > 0) return V.externalModules;
106
- const s = T(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
107
- if (!s) return [];
108
- const n = s[1].split(",").map((c) => c.replace(/['"`]/g, "").trim());
109
- return V.externalModules = n, n;
110
- }, J = async (t) => {
111
- if (V.destDir) return V.destDir;
112
- const e = await pt(t), s = i(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
113
- return V.destDir = s, s;
114
- }, xt = ["salty", "css", "styles", "styled"], At = (t = []) => new RegExp(`\\.(${[...xt, ...t].join("|")})\\.`), mt = (t, e = []) => At(e).test(t), Dt = async (t) => {
115
- if (V.rcFile) return V.rcFile;
116
- if (t === "/") throw new Error("Could not find .saltyrc.json file");
117
- const e = i(t, ".saltyrc.json"), s = await Ct(e, "utf-8").then(JSON.parse).catch(() => {
118
- });
119
- return s ? (V.rcFile = s, s) : Dt(i(t, ".."));
120
- }, pt = async (t) => {
121
- var n, c;
122
- const e = await Dt(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
123
- return s || ((c = e.projects) == null ? void 0 : c.find((r) => r.dir === e.defaultProject));
124
- }, Ut = async (t) => {
125
- const e = await pt(t), s = await J(t), n = i(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), c = i(s, "salty.config.js"), r = await Pt(t), o = Nt(n);
126
- await St.build({
127
- entryPoints: [n],
128
- minify: !0,
129
- treeShaking: !0,
130
- bundle: !0,
131
- outfile: c,
132
- format: r,
133
- external: o
134
- });
135
- const d = Date.now(), { config: w } = await import(`${c}?t=${d}`);
136
- return { config: w, path: c };
137
- }, Xt = async (t, e) => {
138
- var yt, ht;
139
- const s = await J(t), n = {
140
- mediaQueries: [],
141
- globalStyles: [],
142
- variables: [],
143
- templates: []
144
- };
145
- await Promise.all(
146
- [...e].map(async (h) => {
147
- const { contents: C, outputFilePath: L } = await et(t, h, s);
148
- Object.entries(C).forEach(([k, j]) => {
149
- j.isMedia ? n.mediaQueries.push([k, j]) : j.isGlobalDefine ? n.globalStyles.push(j) : j.isDefineVariables ? n.variables.push(j) : j.isDefineTemplates && n.templates.push(j._setPath(`${k};;${L}`));
150
- });
151
- })
152
- );
153
- const { config: c, path: r } = await Ut(t), o = { ...c }, { mediaQueries: d } = n;
154
- o.mediaQueries = Object.fromEntries(d.map(([h, C]) => [`@${h}`, C]));
155
- const w = d.map(([h]) => `'@${h}'`).join(" | "), p = /* @__PURE__ */ new Set(), a = async (h, C = []) => {
156
- if (!h) return [];
157
- const L = Object.entries(h).map(async ([j, R]) => {
158
- const q = async (v) => {
159
- if (!v) return;
160
- if (v instanceof Promise) return await q(await v);
161
- if (typeof v == "function") return await q(await v());
162
- if (typeof v == "object") return await a(v, [...C, j]);
163
- const at = jt(j), it = A(j), ct = [...C, at].join(".");
164
- p.add(`"${ct}"`);
165
- const Y = [...C.map(A), it].join("-"), wt = Mt(v);
166
- return wt ? `--${Y}: ${wt.transformed};` : `--${Y}: ${v};`;
167
- };
168
- return await q(R);
169
- });
170
- return (await Promise.all(L)).flat();
171
- }, g = async (h) => {
172
- if (!h) return [];
173
- const C = Object.entries(h).map(async ([k, j]) => {
174
- const R = await a(j);
175
- return k === "base" ? R.join("") : o.mediaQueries[k] ? `${o.mediaQueries[k]} { ${R.join("")} }` : `${k} { ${R.join("")} }`;
176
- });
177
- return (await Promise.all(C)).flat();
178
- }, u = async (h) => {
179
- if (!h) return [];
180
- const C = Object.entries(h).map(async ([k, j]) => {
181
- const R = Object.entries(j).map(async ([v, at]) => {
182
- const it = await a(at, [k]), ct = `.${k}-${v}, [data-${k}="${v}"]`, Y = it.join("");
183
- return `${ct} { ${Y} }`;
184
- });
185
- return (await Promise.all(R)).flat();
186
- });
187
- return (await Promise.all(C)).flat();
188
- }, y = (h) => ({ ...h, responsive: void 0, conditional: void 0 }), m = (h) => n.variables.map((C) => h === "static" ? y(C._current) : C._current[h]), P = H(y(c.variables), m("static")), x = await a(P), D = H((yt = c.variables) == null ? void 0 : yt.responsive, m("responsive")), E = await g(D), z = H((ht = c.variables) == null ? void 0 : ht.conditional, m("conditional")), U = await u(z), gt = i(s, "css/_variables.css"), O = `:root { ${x.join("")} ${E.join("")} } ${U.join("")}`;
189
- F(gt, O), o.staticVariables = P;
190
- const st = i(s, "css/_global.css"), l = H(c.global, n.globalStyles), $ = await $t(l, "");
191
- F(st, `@layer global { ${$} }`);
192
- const S = i(s, "css/_reset.css"), b = c.reset === "none" ? {} : typeof c.reset == "object" ? c.reset : Lt, N = await $t(b, "");
193
- F(S, `@layer reset { ${N} }`);
194
- const _ = i(s, "css/_templates.css"), M = H(c.templates, n.templates), K = await Rt(M), Q = Jt(M);
195
- F(_, `@layer templates { ${K} }`), o.templates = M;
196
- const X = c.templates ? [Ht(c.templates)._setPath(`config;;${r}`)] : [], nt = Gt(n.templates, X);
197
- o.templatePaths = Object.fromEntries(Object.entries(nt).map(([h, C]) => [h, C._path]));
198
- const B = i(s, "types/css-tokens.d.ts"), kt = `
199
- // Variable types
200
- type VariableTokens = ${[...p].join("|")};
201
- type PropertyValueToken = \`{\${VariableTokens}}\`;
202
-
203
- // Template types
204
- type TemplateTokens = {
205
- ${Object.entries(Q).map(([h, C]) => `${h}?: ${C}`).join(`
206
- `)}
207
- }
208
-
209
- // Media query types
210
- type MediaQueryKeys = ${w || "''"};
211
- `;
212
- F(B, kt);
213
- const vt = i(s, "cache/config-cache.json");
214
- F(vt, JSON.stringify(o, null, 2));
215
- const Tt = Kt(), _t = i(Tt, "cache/config-cache.json");
216
- F(_t, JSON.stringify(o, null, 2));
217
- }, bt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
218
- if (/^['"`]/.test(s)) return e;
219
- const c = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
220
- if (!c.test(t)) return e;
221
- const o = c.exec(t);
222
- if (o) {
223
- const d = o.at(1);
224
- if (xt.some((p) => d == null ? void 0 : d.includes(p))) return e;
225
- }
226
- return "styled('div',";
227
- }), Yt = (t, e) => {
228
- try {
229
- const s = T(i(e, "saltygen/cache/config-cache.json"), "utf8");
230
- return s ? `globalThis.saltyConfig = ${s};
231
-
232
- ${t}` : `globalThis.saltyConfig = {};
233
-
234
- ${t}`;
235
- } catch {
236
- return t;
237
- }
238
- }, et = async (t, e, s) => {
239
- const n = I(e), c = i(s, "./temp");
240
- ft(c) || G(c);
241
- const r = tt(e);
242
- let o = T(e, "utf8");
243
- o = bt(o), o = Yt(o, t);
244
- const d = i(s, "js", n + ".js"), w = await pt(t), p = i(t, (w == null ? void 0 : w.configDir) || "", "salty.config.ts"), a = Nt(p), g = await Pt(t);
245
- await St.build({
246
- stdin: {
247
- contents: o,
248
- sourcefile: r.base,
249
- resolveDir: r.dir,
250
- loader: "tsx"
251
- },
252
- minify: !1,
253
- treeShaking: !0,
254
- bundle: !0,
255
- outfile: d,
256
- format: g,
257
- target: ["node20"],
258
- keepNames: !0,
259
- external: a,
260
- packages: "external",
261
- plugins: [
262
- {
263
- name: "test",
264
- setup: (m) => {
265
- m.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (P) => {
266
- const x = T(P.path, "utf8");
267
- return { contents: bt(x), loader: "ts" };
268
- });
269
- }
270
- }
271
- ]
272
- });
273
- const u = Date.now();
274
- return { contents: await import(`${d}?t=${u}`), outputFilePath: d };
275
- }, Zt = async (t) => {
276
- const e = await J(t), s = i(e, "cache/config-cache.json"), n = T(s, "utf8");
277
- if (!n) throw new Error("Could not find config cache file");
278
- return JSON.parse(n);
279
- }, ut = async (t) => {
280
- const e = await Zt(t), s = await J(t), n = i(s, "salty.config.js"), c = Date.now(), { config: r } = await import(`${n}?t=${c}`);
281
- return H(r, e);
282
- }, dt = () => {
283
- try {
284
- return process.env.NODE_ENV === "production";
285
- } catch {
286
- return !1;
287
- }
288
- }, ue = async (t, e = dt(), s = !0) => {
289
- try {
290
- const n = Date.now();
291
- e ? Z.info("Generating CSS in production mode! 🔥") : Z.info("Generating CSS in development mode! 🚀");
292
- const c = [], r = [], o = await J(t), d = i(o, "index.css");
293
- s && (() => {
294
- ft(o) && Vt("rm -rf " + o), G(o, { recursive: !0 }), G(i(o, "css")), G(i(o, "types")), G(i(o, "js")), G(i(o, "cache"));
295
- })();
296
- const p = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Set();
297
- async function g(l) {
298
- const $ = ["node_modules", "saltygen"], S = Et(l);
299
- if (S.isDirectory()) {
300
- const f = Ot(l);
301
- if ($.some((N) => l.includes(N))) return;
302
- await Promise.all(f.map((N) => g(i(l, N))));
303
- } else if (S.isFile() && mt(l)) {
304
- p.add(l);
305
- const b = T(l, "utf8");
306
- /define[\w\d]+\(/.test(b) && a.add(l);
307
- }
308
- }
309
- await g(t), await Xt(t, a);
310
- const u = {
311
- keyframes: [],
312
- components: [],
313
- classNames: []
314
- };
315
- await Promise.all(
316
- [...p].map(async (l) => {
317
- const { contents: $ } = await et(t, l, o);
318
- for (let [S, f] of Object.entries($)) {
319
- const b = await It(f, 1);
320
- b.isKeyframes ? u.keyframes.push({
321
- value: b,
322
- src: l,
323
- name: S
324
- }) : b.isClassName ? u.classNames.push({
325
- ...f,
326
- src: l,
327
- name: S
328
- }) : b.generator && u.components.push({
329
- ...f,
330
- src: l,
331
- name: S
332
- });
333
- }
334
- })
335
- );
336
- const y = await ut(t);
337
- for (const l of u.keyframes) {
338
- const { value: $ } = l, S = `a_${$.animationName}.css`, f = `css/${S}`, b = i(o, f);
339
- c.push(S), F(b, $.css);
340
- }
341
- const m = {};
342
- for (const l of u.components) {
343
- const { src: $, name: S } = l;
344
- m[$] || (m[$] = []);
345
- const f = l.generator._withBuildContext({
346
- callerName: S,
347
- isProduction: e,
348
- config: y
349
- });
350
- r[f.priority] || (r[f.priority] = []);
351
- const b = await f.css;
352
- if (!b) continue;
353
- r[f.priority].push(f.cssFileName);
354
- const N = `css/${f.cssFileName}`, _ = i(o, N);
355
- F(_, b), y.importStrategy === "component" && m[$].push(f.cssFileName);
356
- }
357
- for (const l of u.classNames) {
358
- const { src: $, name: S } = l;
359
- m[$] || (m[$] = []);
360
- const f = l.generator._withBuildContext({
361
- callerName: S,
362
- isProduction: e,
363
- config: y
364
- }), b = await f.css;
365
- if (!b) continue;
366
- r[f.priority] || (r[f.priority] = []), r[f.priority].push(f.cssFileName);
367
- const N = `css/${f.cssFileName}`, _ = i(o, N);
368
- F(_, b), y.importStrategy === "component" && m[$].push(f.cssFileName);
369
- }
370
- y.importStrategy === "component" && Object.entries(m).forEach(([l, $]) => {
371
- const S = $.map((M) => `@import url('./${M}');`).join(`
372
- `), f = I(l, 6), b = tt(l), N = A(b.name), _ = i(o, `css/f_${N}-${f}.css`);
373
- F(_, S || "/* Empty file */");
374
- });
375
- const P = c.map((l) => `@import url('./css/${l}');`).join(`
376
- `);
377
- let U = `/*!
378
- * Generated with Salty CSS (https://salty-css.dev)
379
- * Do not edit this file directly
380
- */
381
- @layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
382
-
383
- ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
384
- try {
385
- return T(i(o, "css", l), "utf8").length > 0;
386
- } catch {
387
- return !1;
388
- }
389
- }).map((l) => `@import url('./css/${l}');`).join(
390
- `
391
- `
392
- )}
393
- ${P}`;
394
- if (y.importStrategy !== "component") {
395
- const l = r.reduce(($, S, f) => {
396
- const b = S.reduce((K, Q) => {
397
- var ot;
398
- const X = i(o, "css", Q), nt = T(X, "utf8"), B = ((ot = /.*-([^-]+)-\d+.css/.exec(Q)) == null ? void 0 : ot.at(1)) || I(X, 6);
399
- return K.includes(B) ? K : `${K}
400
- /*start:${B}-${Q}*/
401
- ${nt}
402
- /*end:${B}*/
403
- `;
404
- }, ""), N = `l_${f}.css`, _ = i(o, "css", N), M = `@layer l${f} { ${b}
405
- }`;
406
- return F(_, M), `${$}
407
- @import url('./css/${N}');`;
408
- }, "");
409
- U += l;
410
- }
411
- F(d, U);
412
- const O = Date.now() - n, st = O < 200 ? "🔥" : O < 500 ? "🚀" : O < 1e3 ? "🎉" : O < 2e3 ? "🚗" : O < 5e3 ? "🤔" : "🥴";
413
- Z.info(`Generated CSS in ${O}ms! ${st}`);
414
- } catch (n) {
415
- console.error(n);
416
- }
417
- }, de = async (t, e, s = dt()) => {
418
- try {
419
- const n = await J(t);
420
- if (mt(e)) {
421
- const r = [], o = await ut(t), { contents: d } = await et(t, e, n);
422
- for (const [w, p] of Object.entries(d)) {
423
- if (p.isKeyframes && p.css) {
424
- const P = `css/${`a_${p.animationName}.css`}`, x = i(n, P);
425
- F(x, await p.css);
426
- continue;
427
- }
428
- if (p.isClassName) {
429
- const m = p.generator._withBuildContext({
430
- callerName: w,
431
- isProduction: s,
432
- config: o
433
- }), P = await m.css;
434
- if (!P) continue;
435
- r[m.priority] || (r[m.priority] = []), r[m.priority].push(m.cssFileName);
436
- const x = `css/${m.cssFileName}`, D = i(n, x);
437
- F(D, P);
438
- continue;
439
- }
440
- if (!p.generator) continue;
441
- const a = p.generator._withBuildContext({
442
- callerName: w,
443
- isProduction: s,
444
- config: o
445
- }), g = await a.css;
446
- if (!g) continue;
447
- const u = `css/${a.cssFileName}`, y = i(n, u);
448
- F(y, g), r[a.priority] || (r[a.priority] = []), r[a.priority].push(a.cssFileName);
449
- }
450
- if (o.importStrategy !== "component")
451
- r.forEach((w, p) => {
452
- const a = `l_${p}.css`, g = i(n, "css", a);
453
- let u = T(g, "utf8");
454
- w.forEach((y) => {
455
- var D;
456
- const m = i(n, "css", y), P = ((D = /.*-([^-]+)-\d+.css/.exec(y)) == null ? void 0 : D.at(1)) || I(m, 6);
457
- if (!u.includes(P)) {
458
- const E = T(m, "utf8"), z = `/*start:${P}-${y}*/
459
- ${E}
460
- /*end:${P}*/
461
- `;
462
- u = `${u.replace(/\}$/, "")}
463
- ${z}
464
- }`;
465
- }
466
- }), F(g, u);
467
- });
468
- else {
469
- const w = r.flat().map((y) => `@import url('./${y}');`).join(`
470
- `), p = I(e, 6), a = tt(e), g = A(a.name), u = i(n, `css/f_${g}-${p}.css`);
471
- F(u, w || "/* Empty file */");
472
- }
473
- }
474
- } catch (n) {
475
- console.error(n);
476
- }
477
- }, ge = async (t, e, s = dt()) => {
478
- var n, c;
479
- try {
480
- const r = await J(t);
481
- if (mt(e)) {
482
- const d = T(e, "utf8"), w = await ut(t), { contents: p } = await et(t, e, r);
483
- let a = d;
484
- for (const [g, u] of Object.entries(p)) {
485
- if (u.isKeyframes || !u.generator) continue;
486
- const y = u.generator._withBuildContext({
487
- callerName: g,
488
- isProduction: s,
489
- config: w
490
- }), [m, P] = await qt(a, g), x = a.slice(m, P);
491
- if (u.isClassName) {
492
- const D = a, E = ` ${g} = className("${y.classNames}")`;
493
- a = a.replace(x, E), D === a && console.error("Minimize file failed to change content", { name: g });
494
- }
495
- if (x.includes("styled")) {
496
- const D = (c = (n = /styled\(([^,]+),/.exec(x)) == null ? void 0 : n.at(1)) == null ? void 0 : c.trim(), E = a, z = ` ${g} = styled(${D}, "${y.classNames}", ${JSON.stringify(y.clientProps)})`;
497
- a = a.replace(x, z), E === a && console.error("Minimize file failed to change content", { name: g, tagName: D });
498
- }
499
- }
500
- if (w.importStrategy === "component") {
501
- const g = I(e, 6), u = tt(e);
502
- a = `import '../../saltygen/css/${`f_${A(u.name)}-${g}.css`}';
503
- ${a}`;
504
- }
505
- return a = a.replace("@salty-css/react/class-name", "@salty-css/react/class-name-client"), a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
506
- }
507
- } catch (r) {
508
- console.error("Error in minimizeFile:", r);
509
- }
510
- };
511
- export {
512
- pe as a,
513
- de as b,
514
- At as c,
515
- Xt as d,
516
- et as e,
517
- ue as g,
518
- mt as i,
519
- Z as l,
520
- ge as m,
521
- xt as s
522
- };