@salty-css/core 0.0.1-alpha.226 → 0.0.1-alpha.227

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