@salty-css/core 0.0.1-alpha.205 → 0.0.1-alpha.207

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