@salty-css/core 0.0.1-alpha.71 → 0.0.1-alpha.73

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.
@@ -0,0 +1,3 @@
1
+ export declare const getSaltyRcPath: (dirname: string) => string;
2
+ export declare const getPackageJsonPath: (dirname: string) => string;
3
+ export declare const getPackageJson: (dirname: string) => Promise<any>;
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("esbuild"),A=require("child_process"),N=require("../dash-case-DKzpenwY.cjs"),o=require("path"),l=require("fs"),X=require("fs/promises"),_=require("../parse-templates-DVK3iZIl.cjs");var k=typeof document<"u"?document.currentScript:null;function Y(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const t=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(s,n,t.get?t:{enumerable:!0,get:()=>e[n]})}}return s.default=e,Object.freeze(s)}const I=Y(J),U=()=>(console.log("current meta url:",typeof document>"u"?require("url").pathToFileURL(__filename).href:k&&k.tagName.toUpperCase()==="SCRIPT"&&k.src||new URL("compiler/index.cjs",document.baseURI).href),(typeof document>"u"?require("url").pathToFileURL(__filename).href:k&&k.tagName.toUpperCase()==="SCRIPT"&&k.src||new URL("compiler/index.cjs",document.baseURI).href).endsWith(".cjs")?"cjs":"esm"),v={externalModules:[]},z=e=>{if(v.externalModules.length>0)return v.externalModules;const s=o.join(e,"salty.config.ts"),t=l.readFileSync(s,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!t)return[];const a=t[1].split(",").map(F=>F.replace(/['"`]/g,"").trim());return v.externalModules=a,a},R=e=>o.join(e,"./saltygen"),B=["salty","css","styles","styled"],H=(e=[])=>new RegExp(`\\.(${[...B,...e].join("|")})\\.`),E=(e,s=[])=>H(s).test(e),Z=async e=>{const s=R(e),n=o.join(e,"salty.config.ts"),t=o.join(s,"salty.config.js"),a=U(),F=z(e);await I.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:t,format:a,external:F});const f=Date.now(),{config:g}=await import(`${t}?t=${f}`);return g},L=async e=>{const s=await Z(e),n=new Set,t=(c,u=[])=>c?Object.entries(c).flatMap(([y,p])=>{if(!p)return;if(typeof p=="object")return t(p,[...u,y]);const x=[...u,y].join(".");n.add(`"${x}"`);const h=[...u.map(N.dashCase),N.dashCase(y)].join("-"),{result:j}=_.parseValueTokens(p);return`--${h}: ${j};`}):[],a=c=>c?Object.entries(c).flatMap(([u,y])=>{const p=t(y);return u==="base"?p.join(""):`${u} { ${p.join("")} }`}):[],F=c=>c?Object.entries(c).flatMap(([u,y])=>Object.entries(y).flatMap(([p,x])=>{const h=t(x,[u]),j=`.${u}-${p}, [data-${u}="${p}"]`,D=h.join("");return`${j} { ${D} }`})):[],f=t(s.variables),g=a(s.responsiveVariables),i=F(s.conditionalVariables),w=R(e),S=o.join(w,"css/variables.css"),T=`:root { ${f.join("")} ${g.join("")} } ${i.join("")}`;l.writeFileSync(S,T);const m=o.join(w,"types/css-tokens.d.ts"),d=`type VariableTokens = ${[...n].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;l.writeFileSync(m,d);const C=o.join(w,"css/global.css"),$=_.parseStyles(s.global,"");l.writeFileSync(C,$);const b=o.join(w,"css/templates.css"),P=_.parseTemplates(s.templates);l.writeFileSync(b,P)},O=async(e,s,n)=>{const t=N.toHash(s),a=o.join(n,"js",t+".js"),F=U(),f=z(e);await I.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:a,format:F,target:["es2022"],keepNames:!0,external:f});const g=Date.now();return await import(`${a}?t=${g}`)},V=async e=>{const s=R(e),n=o.join(s,"salty.config.js"),{config:t}=await import(n);return t},Q=async e=>{try{const s=[],n=[],t=R(e),a=o.join(t,"index.css");(()=>{l.existsSync(t)&&A.execSync("rm -rf "+t),l.mkdirSync(t),l.mkdirSync(o.join(t,"css")),l.mkdirSync(o.join(t,"types"))})(),await L(e);const f=await V(e);async function g(r,d){const C=["node_modules","saltygen"],$=l.statSync(r);if($.isDirectory()){const b=l.readdirSync(r);if(C.some(c=>r.includes(c)))return;await Promise.all(b.map(c=>g(o.join(r,c),o.join(d,c))))}else if($.isFile()&&E(r)){const P=await O(e,r,t),c=[];Object.entries(P).forEach(([x,h])=>{if(h.isKeyframes&&h.css){const q=`${h.animationName}.css`,K=`css/${q}`,G=o.join(t,K);s.push(q),l.writeFileSync(G,h.css);return}if(!h.generator)return;const j=h.generator._withBuildContext({name:x,config:f}),D=`${j.hash}-${j.priority}.css`;n[j.priority]||(n[j.priority]=[]),n[j.priority].push(D),c.push(D);const M=`css/${D}`,W=o.join(t,M);l.writeFileSync(W,j.css)});const u=c.map(x=>`@import url('./${x}');`).join(`
2
- `),y=N.toHash(r,6),p=o.join(t,`css/${y}.css`);l.writeFileSync(p,u)}}await g(e,t);const i=s.map(r=>`@import url('./css/${r}');`).join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const Y=require("esbuild"),Z=require("child_process"),N=require("../dash-case-DKzpenwY.cjs"),o=require("path"),a=require("fs"),I=require("fs/promises"),R=require("../parse-templates-DVK3iZIl.cjs");var V=typeof document<"u"?document.currentScript:null;function Q(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(e,n,s.get?s:{enumerable:!0,get:()=>t[n]})}}return e.default=t,Object.freeze(e)}const z=Q(Y),B=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=o.join(t,"package.json");return a.existsSync(e)?e:B(o.join(t,".."))},tt=async t=>{const e=B(t);return await I.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},et=async t=>{const e=await tt(t);if(e)return e.type};let D;const H=async t=>{if(D)return D;const e=await et(t);return e==="module"?D="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:V&&V.tagName.toUpperCase()==="SCRIPT"&&V.src||new URL("compiler/index.cjs",document.baseURI).href).endsWith(".cjs"))&&(D="cjs"),D||"esm"},_={externalModules:[]},U=t=>{if(_.externalModules.length>0)return _.externalModules;const e=o.join(t,"salty.config.ts"),s=a.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const l=s[1].split(",").map(w=>w.replace(/['"`]/g,"").trim());return _.externalModules=l,l},v=t=>o.join(t,"./saltygen"),W=["salty","css","styles","styled"],K=(t=[])=>new RegExp(`\\.(${[...W,...t].join("|")})\\.`),E=(t,e=[])=>K(e).test(t),st=async t=>{const e=v(t),n=o.join(t,"salty.config.ts"),s=o.join(e,"salty.config.js"),l=await H(t),w=U(t);await z.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:l,external:w});const f=Date.now(),{config:g}=await import(`${s}?t=${f}`);return g},L=async t=>{const e=await st(t),n=new Set,s=(r,u=[])=>r?Object.entries(r).flatMap(([d,p])=>{if(!p)return;if(typeof p=="object")return s(p,[...u,d]);const x=[...u,d].join(".");n.add(`"${x}"`);const h=[...u.map(N.dashCase),N.dashCase(d)].join("-"),{result:j}=R.parseValueTokens(p);return`--${h}: ${j};`}):[],l=r=>r?Object.entries(r).flatMap(([u,d])=>{const p=s(d);return u==="base"?p.join(""):`${u} { ${p.join("")} }`}):[],w=r=>r?Object.entries(r).flatMap(([u,d])=>Object.entries(d).flatMap(([p,x])=>{const h=s(x,[u]),j=`.${u}-${p}, [data-${u}="${p}"]`,P=h.join("");return`${j} { ${P} }`})):[],f=s(e.variables),g=l(e.responsiveVariables),i=w(e.conditionalVariables),$=v(t),S=o.join($,"css/variables.css"),k=`:root { ${f.join("")} ${g.join("")} } ${i.join("")}`;a.writeFileSync(S,k);const m=o.join($,"types/css-tokens.d.ts"),y=`type VariableTokens = ${[...n].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;a.writeFileSync(m,y);const C=o.join($,"css/global.css"),F=R.parseStyles(e.global,"");a.writeFileSync(C,F);const b=o.join($,"css/templates.css"),T=R.parseTemplates(e.templates);a.writeFileSync(b,T)},O=async(t,e,n)=>{const s=N.toHash(e),l=o.join(n,"js",s+".js"),w=await H(t),f=U(t);await z.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:l,format:w,target:["es2022"],keepNames:!0,external:f});const g=Date.now();return await import(`${l}?t=${g}`)},J=async t=>{const e=v(t),n=o.join(e,"salty.config.js"),{config:s}=await import(n);return s},nt=async t=>{try{const e=[],n=[],s=v(t),l=o.join(s,"index.css");(()=>{a.existsSync(s)&&Z.execSync("rm -rf "+s),a.mkdirSync(s),a.mkdirSync(o.join(s,"css")),a.mkdirSync(o.join(s,"types"))})(),await L(t);const f=await J(t);async function g(c,y){const C=["node_modules","saltygen"],F=a.statSync(c);if(F.isDirectory()){const b=a.readdirSync(c);if(C.some(r=>c.includes(r)))return;await Promise.all(b.map(r=>g(o.join(c,r),o.join(y,r))))}else if(F.isFile()&&E(c)){const T=await O(t,c,s),r=[];Object.entries(T).forEach(([x,h])=>{if(h.isKeyframes&&h.css){const q=`${h.animationName}.css`,A=`css/${q}`,X=o.join(s,A);e.push(q),a.writeFileSync(X,h.css);return}if(!h.generator)return;const j=h.generator._withBuildContext({name:x,config:f}),P=`${j.hash}-${j.priority}.css`;n[j.priority]||(n[j.priority]=[]),n[j.priority].push(P),r.push(P);const M=`css/${P}`,G=o.join(s,M);a.writeFileSync(G,j.css)});const u=r.map(x=>`@import url('./${x}');`).join(`
2
+ `),d=N.toHash(c,6),p=o.join(s,`css/${d}.css`);a.writeFileSync(p,u)}}await g(t,s);const i=e.map(c=>`@import url('./css/${c}');`).join(`
3
3
  `);let m=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
4
4
 
5
- ${["variables.css","global.css","templates.css"].filter(r=>{try{return l.readFileSync(o.join(t,"css",r),"utf8").length>0}catch{return!1}}).map(r=>`@import url('./css/${r}');`).join(`
5
+ ${["variables.css","global.css","templates.css"].filter(c=>{try{return a.readFileSync(o.join(s,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
6
6
  `)}
7
- ${i}`;if(f.importStrategy!=="component"){const r=n.flat().map(d=>`@import url('./css/${d}');`).join(`
8
- `);m+=r}l.writeFileSync(a,m)}catch(s){console.error(s)}},ee=async(e,s)=>{try{const n=[],t=o.join(e,"./saltygen"),a=o.join(t,"index.css");if(E(s)){const f=await V(e),g=await O(e,s,t);Object.entries(g).forEach(([m,r])=>{if(!r.generator)return;const d=r.generator._withBuildContext({name:m,config:f}),C=`${d.hash}-${d.priority}.css`,$=`css/${C}`,b=o.join(t,$);n.push(C),l.writeFileSync(b,d.css)});const i=l.readFileSync(a,"utf8").split(`
9
- `),w=n.map(m=>`@import url('../saltygen/css/${m}');`),T=[...new Set([...i,...w])].join(`
10
- `);l.writeFileSync(a,T)}}catch(n){console.error(n)}},te=async(e,s)=>{try{const n=o.join(e,"./saltygen");if(E(s)){const a=l.readFileSync(s,"utf8");a.replace(/^(?!export\s)const\s.*/gm,S=>`export ${S}`)!==a&&await X.writeFile(s,a);const f=await V(e),g=await O(e,s,n);let i=a;Object.entries(g).forEach(([S,T])=>{var D;if(T.isKeyframes||!T.generator)return;const m=T.generator._withBuildContext({name:S,config:f}),r=new RegExp(`\\s${S}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!r)return console.error("Could not find the original declaration");const d=(D=r.at(1))==null?void 0:D.trim(),C=new RegExp(`\\s${S}[=\\s]+styled\\(`,"g").exec(i);if(!C)return console.error("Could not find the original declaration");const{index:$}=C;let b=!1;const P=setTimeout(()=>b=!0,5e3);let c=0,u=!1,y=0;for(;!u&&!b;){const M=i[$+c];M==="("&&y++,M===")"&&y--,y===0&&M===")"&&(u=!0),c>i.length&&(b=!0),c++}if(!b)clearTimeout(P);else throw new Error("Failed to find the end of the styled call and timed out");const p=$+c,x=i.slice($,p),h=i,j=` ${S} = styled(${d}, "${m.classNames}", "${m._callerName}", ${JSON.stringify(m.props)});`;i=i.replace(x,j),h===i&&console.error("Minimize file failed to change content",{name:S,tagName:d})});const w=N.toHash(s,6);return f.importStrategy==="component"&&(i=`import '../../saltygen/css/${w}.css';
11
- ${i}`),i=i.replace("{ styled }","{ styledClient as styled }"),i=i.replace("@salty-css/react/styled","@salty-css/react/styled-client"),i}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=O;exports.generateConfigStyles=L;exports.generateCss=Q;exports.generateFile=ee;exports.isSaltyFile=E;exports.minimizeFile=te;exports.saltyFileExtensions=B;exports.saltyFileRegExp=H;
7
+ ${i}`;if(f.importStrategy!=="component"){const c=n.flat().map(y=>`@import url('./css/${y}');`).join(`
8
+ `);m+=c}a.writeFileSync(l,m)}catch(e){console.error(e)}},ot=async(t,e)=>{try{const n=[],s=o.join(t,"./saltygen"),l=o.join(s,"index.css");if(E(e)){const f=await J(t),g=await O(t,e,s);Object.entries(g).forEach(([m,c])=>{if(!c.generator)return;const y=c.generator._withBuildContext({name:m,config:f}),C=`${y.hash}-${y.priority}.css`,F=`css/${C}`,b=o.join(s,F);n.push(C),a.writeFileSync(b,y.css)});const i=a.readFileSync(l,"utf8").split(`
9
+ `),$=n.map(m=>`@import url('../saltygen/css/${m}');`),k=[...new Set([...i,...$])].join(`
10
+ `);a.writeFileSync(l,k)}}catch(n){console.error(n)}},it=async(t,e)=>{try{const n=o.join(t,"./saltygen");if(E(e)){const l=a.readFileSync(e,"utf8");l.replace(/^(?!export\s)const\s.*/gm,S=>`export ${S}`)!==l&&await I.writeFile(e,l);const f=await J(t),g=await O(t,e,n);let i=l;Object.entries(g).forEach(([S,k])=>{var P;if(k.isKeyframes||!k.generator)return;const m=k.generator._withBuildContext({name:S,config:f}),c=new RegExp(`\\s${S}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(l);if(!c)return console.error("Could not find the original declaration");const y=(P=c.at(1))==null?void 0:P.trim(),C=new RegExp(`\\s${S}[=\\s]+styled\\(`,"g").exec(i);if(!C)return console.error("Could not find the original declaration");const{index:F}=C;let b=!1;const T=setTimeout(()=>b=!0,5e3);let r=0,u=!1,d=0;for(;!u&&!b;){const M=i[F+r];M==="("&&d++,M===")"&&d--,d===0&&M===")"&&(u=!0),r>i.length&&(b=!0),r++}if(!b)clearTimeout(T);else throw new Error("Failed to find the end of the styled call and timed out");const p=F+r,x=i.slice(F,p),h=i,j=` ${S} = styled(${y}, "${m.classNames}", "${m._callerName}", ${JSON.stringify(m.props)});`;i=i.replace(x,j),h===i&&console.error("Minimize file failed to change content",{name:S,tagName:y})});const $=N.toHash(e,6);return f.importStrategy==="component"&&(i=`import '../../saltygen/css/${$}.css';
11
+ ${i}`),i=i.replace("{ styled }","{ styledClient as styled }"),i=i.replace("@salty-css/react/styled","@salty-css/react/styled-client"),i}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=O;exports.generateConfigStyles=L;exports.generateCss=nt;exports.generateFile=ot;exports.isSaltyFile=E;exports.minimizeFile=it;exports.saltyFileExtensions=W;exports.saltyFileRegExp=K;
package/compiler/index.js CHANGED
@@ -1,196 +1,214 @@
1
1
  import * as z from "esbuild";
2
- import { execSync as q } from "child_process";
3
- import { t as v, d as _ } from "../dash-case-DMQMcCO6.js";
4
- import { join as o } from "path";
5
- import { writeFileSync as F, existsSync as A, mkdirSync as E, statSync as L, readdirSync as U, readFileSync as M } from "fs";
6
- import { writeFile as X } from "fs/promises";
7
- import { p as Y, a as Z, b as Q } from "../parse-templates-DUUSaubj.js";
8
- const W = () => (console.log("current meta url:", import.meta.url), import.meta.url.endsWith(".cjs") ? "cjs" : "esm"), V = {
2
+ import { execSync as U } from "child_process";
3
+ import { t as J, d as _ } from "../dash-case-DMQMcCO6.js";
4
+ import { join as n } from "path";
5
+ import { existsSync as W, writeFileSync as j, mkdirSync as v, statSync as X, readdirSync as Y, readFileSync as N } from "fs";
6
+ import { readFile as Z, writeFile as Q } from "fs/promises";
7
+ import { p as tt, a as st, b as et } from "../parse-templates-DUUSaubj.js";
8
+ const H = (t) => {
9
+ if (!t || t === "/") throw new Error("Could not find package.json file");
10
+ const s = n(t, "package.json");
11
+ return W(s) ? s : H(n(t, ".."));
12
+ }, nt = async (t) => {
13
+ const s = H(t);
14
+ return await Z(s, "utf-8").then(JSON.parse).catch(() => {
15
+ });
16
+ }, ot = async (t) => {
17
+ const s = await nt(t);
18
+ if (s)
19
+ return s.type;
20
+ };
21
+ let M;
22
+ const K = async (t) => {
23
+ if (M) return M;
24
+ const s = await ot(t);
25
+ return s === "module" ? M = "esm" : (s === "commonjs" || import.meta.url.endsWith(".cjs")) && (M = "cjs"), M || "esm";
26
+ }, V = {
9
27
  externalModules: []
10
- }, H = (t) => {
28
+ }, G = (t) => {
11
29
  if (V.externalModules.length > 0) return V.externalModules;
12
- const e = o(t, "salty.config.ts"), s = M(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
13
- if (!s) return [];
14
- const a = s[1].split(",").map((w) => w.replace(/['"`]/g, "").trim());
15
- return V.externalModules = a, a;
16
- }, N = (t) => o(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"], st = (t = []) => new RegExp(`\\.(${[...tt, ...t].join("|")})\\.`), O = (t, e = []) => st(e).test(t), et = async (t) => {
17
- const e = N(t), n = o(t, "salty.config.ts"), s = o(e, "salty.config.js"), a = W(), w = H(t);
30
+ const s = n(t, "salty.config.ts"), e = N(s, "utf8").match(/externalModules:\s?\[(.*)\]/);
31
+ if (!e) return [];
32
+ const i = e[1].split(",").map((w) => w.replace(/['"`]/g, "").trim());
33
+ return V.externalModules = i, i;
34
+ }, E = (t) => n(t, "./saltygen"), ct = ["salty", "css", "styles", "styled"], rt = (t = []) => new RegExp(`\\.(${[...ct, ...t].join("|")})\\.`), O = (t, s = []) => rt(s).test(t), at = async (t) => {
35
+ const s = E(t), o = n(t, "salty.config.ts"), e = n(s, "salty.config.js"), i = await K(t), w = G(t);
18
36
  await z.build({
19
- entryPoints: [n],
37
+ entryPoints: [o],
20
38
  minify: !0,
21
39
  treeShaking: !0,
22
40
  bundle: !0,
23
- outfile: s,
24
- format: a,
41
+ outfile: e,
42
+ format: i,
25
43
  external: w
26
44
  });
27
- const f = Date.now(), { config: g } = await import(`${s}?t=${f}`);
28
- return g;
29
- }, nt = async (t) => {
30
- const e = await et(t), n = /* @__PURE__ */ new Set(), s = (i, l = []) => i ? Object.entries(i).flatMap(([m, p]) => {
45
+ const f = Date.now(), { config: y } = await import(`${e}?t=${f}`);
46
+ return y;
47
+ }, it = async (t) => {
48
+ const s = await at(t), o = /* @__PURE__ */ new Set(), e = (a, l = []) => a ? Object.entries(a).flatMap(([g, p]) => {
31
49
  if (!p) return;
32
- if (typeof p == "object") return s(p, [...l, m]);
33
- const C = [...l, m].join(".");
34
- n.add(`"${C}"`);
35
- const d = [...l.map(_), _(m)].join("-"), { result: h } = Q(p);
36
- return `--${d}: ${h};`;
37
- }) : [], a = (i) => i ? Object.entries(i).flatMap(([l, m]) => {
38
- const p = s(m);
50
+ if (typeof p == "object") return e(p, [...l, g]);
51
+ const C = [...l, g].join(".");
52
+ o.add(`"${C}"`);
53
+ const m = [...l.map(_), _(g)].join("-"), { result: h } = et(p);
54
+ return `--${m}: ${h};`;
55
+ }) : [], i = (a) => a ? Object.entries(a).flatMap(([l, g]) => {
56
+ const p = e(g);
39
57
  return l === "base" ? p.join("") : `${l} { ${p.join("")} }`;
40
- }) : [], w = (i) => i ? Object.entries(i).flatMap(([l, m]) => Object.entries(m).flatMap(([p, C]) => {
41
- const d = s(C, [l]), h = `.${l}-${p}, [data-${l}="${p}"]`, k = d.join("");
42
- return `${h} { ${k} }`;
43
- })) : [], f = s(e.variables), g = a(e.responsiveVariables), r = w(e.conditionalVariables), S = N(t), $ = o(S, "css/variables.css"), D = `:root { ${f.join("")} ${g.join("")} } ${r.join("")}`;
44
- F($, D);
45
- const y = o(S, "types/css-tokens.d.ts"), u = `type VariableTokens = ${[...n].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
46
- F(y, u);
47
- const j = o(S, "css/global.css"), x = Y(e.global, "");
48
- F(j, x);
49
- const b = o(S, "css/templates.css"), T = Z(e.templates);
50
- F(b, T);
51
- }, R = async (t, e, n) => {
52
- const s = v(e), a = o(n, "js", s + ".js"), w = W(), f = H(t);
58
+ }) : [], w = (a) => a ? Object.entries(a).flatMap(([l, g]) => Object.entries(g).flatMap(([p, C]) => {
59
+ const m = e(C, [l]), h = `.${l}-${p}, [data-${l}="${p}"]`, P = m.join("");
60
+ return `${h} { ${P} }`;
61
+ })) : [], f = e(s.variables), y = i(s.responsiveVariables), c = w(s.conditionalVariables), x = E(t), $ = n(x, "css/variables.css"), k = `:root { ${f.join("")} ${y.join("")} } ${c.join("")}`;
62
+ j($, k);
63
+ const d = n(x, "types/css-tokens.d.ts"), u = `type VariableTokens = ${[...o].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
64
+ j(d, u);
65
+ const S = n(x, "css/global.css"), F = tt(s.global, "");
66
+ j(S, F);
67
+ const b = n(x, "css/templates.css"), D = st(s.templates);
68
+ j(b, D);
69
+ }, R = async (t, s, o) => {
70
+ const e = J(s), i = n(o, "js", e + ".js"), w = await K(t), f = G(t);
53
71
  await z.build({
54
- entryPoints: [e],
72
+ entryPoints: [s],
55
73
  minify: !0,
56
74
  treeShaking: !0,
57
75
  bundle: !0,
58
- outfile: a,
76
+ outfile: i,
59
77
  format: w,
60
78
  target: ["es2022"],
61
79
  keepNames: !0,
62
80
  external: f
63
81
  });
64
- const g = Date.now();
65
- return await import(`${a}?t=${g}`);
82
+ const y = Date.now();
83
+ return await import(`${i}?t=${y}`);
66
84
  }, B = async (t) => {
67
- const e = N(t), n = o(e, "salty.config.js"), { config: s } = await import(n);
68
- return s;
69
- }, pt = async (t) => {
85
+ const s = E(t), o = n(s, "salty.config.js"), { config: e } = await import(o);
86
+ return e;
87
+ }, dt = async (t) => {
70
88
  try {
71
- const e = [], n = [], s = N(t), a = o(s, "index.css");
89
+ const s = [], o = [], e = E(t), i = n(e, "index.css");
72
90
  (() => {
73
- A(s) && q("rm -rf " + s), E(s), E(o(s, "css")), E(o(s, "types"));
74
- })(), await nt(t);
91
+ W(e) && U("rm -rf " + e), v(e), v(n(e, "css")), v(n(e, "types"));
92
+ })(), await it(t);
75
93
  const f = await B(t);
76
- async function g(c, u) {
77
- const j = ["node_modules", "saltygen"], x = L(c);
78
- if (x.isDirectory()) {
79
- const b = U(c);
80
- if (j.some((i) => c.includes(i))) return;
81
- await Promise.all(b.map((i) => g(o(c, i), o(u, i))));
82
- } else if (x.isFile() && O(c)) {
83
- const T = await R(t, c, s), i = [];
84
- Object.entries(T).forEach(([C, d]) => {
85
- if (d.isKeyframes && d.css) {
86
- const I = `${d.animationName}.css`, G = `css/${I}`, J = o(s, G);
87
- e.push(I), F(J, d.css);
94
+ async function y(r, u) {
95
+ const S = ["node_modules", "saltygen"], F = X(r);
96
+ if (F.isDirectory()) {
97
+ const b = Y(r);
98
+ if (S.some((a) => r.includes(a))) return;
99
+ await Promise.all(b.map((a) => y(n(r, a), n(u, a))));
100
+ } else if (F.isFile() && O(r)) {
101
+ const D = await R(t, r, e), a = [];
102
+ Object.entries(D).forEach(([C, m]) => {
103
+ if (m.isKeyframes && m.css) {
104
+ const I = `${m.animationName}.css`, A = `css/${I}`, L = n(e, A);
105
+ s.push(I), j(L, m.css);
88
106
  return;
89
107
  }
90
- if (!d.generator) return;
91
- const h = d.generator._withBuildContext({
108
+ if (!m.generator) return;
109
+ const h = m.generator._withBuildContext({
92
110
  name: C,
93
111
  config: f
94
- }), k = `${h.hash}-${h.priority}.css`;
95
- n[h.priority] || (n[h.priority] = []), n[h.priority].push(k), i.push(k);
96
- const P = `css/${k}`, K = o(s, P);
97
- F(K, h.css);
112
+ }), P = `${h.hash}-${h.priority}.css`;
113
+ o[h.priority] || (o[h.priority] = []), o[h.priority].push(P), a.push(P);
114
+ const T = `css/${P}`, q = n(e, T);
115
+ j(q, h.css);
98
116
  });
99
- const l = i.map((C) => `@import url('./${C}');`).join(`
100
- `), m = v(c, 6), p = o(s, `css/${m}.css`);
101
- F(p, l);
117
+ const l = a.map((C) => `@import url('./${C}');`).join(`
118
+ `), g = J(r, 6), p = n(e, `css/${g}.css`);
119
+ j(p, l);
102
120
  }
103
121
  }
104
- await g(t, s);
105
- const r = e.map((c) => `@import url('./css/${c}');`).join(`
122
+ await y(t, e);
123
+ const c = s.map((r) => `@import url('./css/${r}');`).join(`
106
124
  `);
107
- let y = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
125
+ let d = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
108
126
 
109
- ${["variables.css", "global.css", "templates.css"].filter((c) => {
127
+ ${["variables.css", "global.css", "templates.css"].filter((r) => {
110
128
  try {
111
- return M(o(s, "css", c), "utf8").length > 0;
129
+ return N(n(e, "css", r), "utf8").length > 0;
112
130
  } catch {
113
131
  return !1;
114
132
  }
115
- }).map((c) => `@import url('./css/${c}');`).join(`
133
+ }).map((r) => `@import url('./css/${r}');`).join(`
116
134
  `)}
117
- ${r}`;
135
+ ${c}`;
118
136
  if (f.importStrategy !== "component") {
119
- const c = n.flat().map((u) => `@import url('./css/${u}');`).join(`
137
+ const r = o.flat().map((u) => `@import url('./css/${u}');`).join(`
120
138
  `);
121
- y += c;
139
+ d += r;
122
140
  }
123
- F(a, y);
124
- } catch (e) {
125
- console.error(e);
141
+ j(i, d);
142
+ } catch (s) {
143
+ console.error(s);
126
144
  }
127
- }, ft = async (t, e) => {
145
+ }, mt = async (t, s) => {
128
146
  try {
129
- const n = [], s = o(t, "./saltygen"), a = o(s, "index.css");
130
- if (O(e)) {
131
- const f = await B(t), g = await R(t, e, s);
132
- Object.entries(g).forEach(([y, c]) => {
133
- if (!c.generator) return;
134
- const u = c.generator._withBuildContext({
135
- name: y,
147
+ const o = [], e = n(t, "./saltygen"), i = n(e, "index.css");
148
+ if (O(s)) {
149
+ const f = await B(t), y = await R(t, s, e);
150
+ Object.entries(y).forEach(([d, r]) => {
151
+ if (!r.generator) return;
152
+ const u = r.generator._withBuildContext({
153
+ name: d,
136
154
  config: f
137
- }), j = `${u.hash}-${u.priority}.css`, x = `css/${j}`, b = o(s, x);
138
- n.push(j), F(b, u.css);
155
+ }), S = `${u.hash}-${u.priority}.css`, F = `css/${S}`, b = n(e, F);
156
+ o.push(S), j(b, u.css);
139
157
  });
140
- const r = M(a, "utf8").split(`
141
- `), S = n.map((y) => `@import url('../saltygen/css/${y}');`), D = [.../* @__PURE__ */ new Set([...r, ...S])].join(`
158
+ const c = N(i, "utf8").split(`
159
+ `), x = o.map((d) => `@import url('../saltygen/css/${d}');`), k = [.../* @__PURE__ */ new Set([...c, ...x])].join(`
142
160
  `);
143
- F(a, D);
161
+ j(i, k);
144
162
  }
145
- } catch (n) {
146
- console.error(n);
163
+ } catch (o) {
164
+ console.error(o);
147
165
  }
148
- }, ut = async (t, e) => {
166
+ }, ht = async (t, s) => {
149
167
  try {
150
- const n = o(t, "./saltygen");
151
- if (O(e)) {
152
- const a = M(e, "utf8");
153
- a.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== a && await X(e, a);
154
- const f = await B(t), g = await R(t, e, n);
155
- let r = a;
156
- Object.entries(g).forEach(([$, D]) => {
157
- var k;
158
- if (D.isKeyframes || !D.generator) return;
159
- const y = D.generator._withBuildContext({
168
+ const o = n(t, "./saltygen");
169
+ if (O(s)) {
170
+ const i = N(s, "utf8");
171
+ i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await Q(s, i);
172
+ const f = await B(t), y = await R(t, s, o);
173
+ let c = i;
174
+ Object.entries(y).forEach(([$, k]) => {
175
+ var P;
176
+ if (k.isKeyframes || !k.generator) return;
177
+ const d = k.generator._withBuildContext({
160
178
  name: $,
161
179
  config: f
162
- }), c = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
163
- if (!c) return console.error("Could not find the original declaration");
164
- const u = (k = c.at(1)) == null ? void 0 : k.trim(), j = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(r);
165
- if (!j) return console.error("Could not find the original declaration");
166
- const { index: x } = j;
180
+ }), r = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
181
+ if (!r) return console.error("Could not find the original declaration");
182
+ const u = (P = r.at(1)) == null ? void 0 : P.trim(), S = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(c);
183
+ if (!S) return console.error("Could not find the original declaration");
184
+ const { index: F } = S;
167
185
  let b = !1;
168
- const T = setTimeout(() => b = !0, 5e3);
169
- let i = 0, l = !1, m = 0;
186
+ const D = setTimeout(() => b = !0, 5e3);
187
+ let a = 0, l = !1, g = 0;
170
188
  for (; !l && !b; ) {
171
- const P = r[x + i];
172
- P === "(" && m++, P === ")" && m--, m === 0 && P === ")" && (l = !0), i > r.length && (b = !0), i++;
189
+ const T = c[F + a];
190
+ T === "(" && g++, T === ")" && g--, g === 0 && T === ")" && (l = !0), a > c.length && (b = !0), a++;
173
191
  }
174
- if (!b) clearTimeout(T);
192
+ if (!b) clearTimeout(D);
175
193
  else throw new Error("Failed to find the end of the styled call and timed out");
176
- const p = x + i, C = r.slice(x, p), d = r, h = ` ${$} = styled(${u}, "${y.classNames}", "${y._callerName}", ${JSON.stringify(y.props)});`;
177
- r = r.replace(C, h), d === r && console.error("Minimize file failed to change content", { name: $, tagName: u });
194
+ const p = F + a, C = c.slice(F, p), m = c, h = ` ${$} = styled(${u}, "${d.classNames}", "${d._callerName}", ${JSON.stringify(d.props)});`;
195
+ c = c.replace(C, h), m === c && console.error("Minimize file failed to change content", { name: $, tagName: u });
178
196
  });
179
- const S = v(e, 6);
180
- return f.importStrategy === "component" && (r = `import '../../saltygen/css/${S}.css';
181
- ${r}`), r = r.replace("{ styled }", "{ styledClient as styled }"), r = r.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), r;
197
+ const x = J(s, 6);
198
+ return f.importStrategy === "component" && (c = `import '../../saltygen/css/${x}.css';
199
+ ${c}`), c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
182
200
  }
183
- } catch (n) {
184
- console.error("Error in minimizeFile:", n);
201
+ } catch (o) {
202
+ console.error("Error in minimizeFile:", o);
185
203
  }
186
204
  };
187
205
  export {
188
206
  R as compileSaltyFile,
189
- nt as generateConfigStyles,
190
- pt as generateCss,
191
- ft as generateFile,
207
+ it as generateConfigStyles,
208
+ dt as generateCss,
209
+ mt as generateFile,
192
210
  O as isSaltyFile,
193
- ut as minimizeFile,
194
- tt as saltyFileExtensions,
195
- st as saltyFileRegExp
211
+ ht as minimizeFile,
212
+ ct as saltyFileExtensions,
213
+ rt as saltyFileRegExp
196
214
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.71",
3
+ "version": "0.0.1-alpha.73",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -1 +1 @@
1
- export declare const detectCurrentModuleType: () => "cjs" | "esm";
1
+ export declare const detectCurrentModuleType: (dirname: string) => Promise<"esm" | "cjs">;