@salty-css/core 0.0.1-alpha.70 → 0.0.1-alpha.72
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/compiler/index.cjs +7 -7
- package/compiler/index.js +22 -22
- package/package.json +1 -1
package/compiler/index.cjs
CHANGED
@@ -1,11 +1,11 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("esbuild"),A=require("child_process"),
|
2
|
-
`),
|
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(`
|
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(
|
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(`
|
6
6
|
`)}
|
7
|
-
${i}`;if(f.importStrategy!=="component"){const r=n.flat().map(
|
8
|
-
`);m+=r}l.writeFileSync(a,m)}catch(s){console.error(s)}},
|
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
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)}},
|
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=
|
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;
|
package/compiler/index.js
CHANGED
@@ -5,7 +5,7 @@ import { join as o } from "path";
|
|
5
5
|
import { writeFileSync as F, existsSync as A, mkdirSync as E, statSync as L, readdirSync as U, readFileSync as M } from "fs";
|
6
6
|
import { writeFile as X } from "fs/promises";
|
7
7
|
import { p as Y, a as Z, b as Q } from "../parse-templates-DUUSaubj.js";
|
8
|
-
const W = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", V = {
|
8
|
+
const W = () => (console.log("current meta url:", import.meta.url), import.meta.url.endsWith(".cjs") ? "cjs" : "esm"), V = {
|
9
9
|
externalModules: []
|
10
10
|
}, H = (t) => {
|
11
11
|
if (V.externalModules.length > 0) return V.externalModules;
|
@@ -24,8 +24,8 @@ const W = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", V = {
|
|
24
24
|
format: a,
|
25
25
|
external: w
|
26
26
|
});
|
27
|
-
const f = Date.now(), { config:
|
28
|
-
return
|
27
|
+
const f = Date.now(), { config: g } = await import(`${s}?t=${f}`);
|
28
|
+
return g;
|
29
29
|
}, nt = async (t) => {
|
30
30
|
const e = await et(t), n = /* @__PURE__ */ new Set(), s = (i, l = []) => i ? Object.entries(i).flatMap(([m, p]) => {
|
31
31
|
if (!p) return;
|
@@ -40,10 +40,10 @@ const W = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", V = {
|
|
40
40
|
}) : [], w = (i) => i ? Object.entries(i).flatMap(([l, m]) => Object.entries(m).flatMap(([p, C]) => {
|
41
41
|
const d = s(C, [l]), h = `.${l}-${p}, [data-${l}="${p}"]`, k = d.join("");
|
42
42
|
return `${h} { ${k} }`;
|
43
|
-
})) : [], f = s(e.variables),
|
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
44
|
F($, D);
|
45
|
-
const
|
46
|
-
F(
|
45
|
+
const y = o(S, "types/css-tokens.d.ts"), u = `type VariableTokens = ${[...n].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
46
|
+
F(y, u);
|
47
47
|
const j = o(S, "css/global.css"), x = Y(e.global, "");
|
48
48
|
F(j, x);
|
49
49
|
const b = o(S, "css/templates.css"), T = Z(e.templates);
|
@@ -61,8 +61,8 @@ const W = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", V = {
|
|
61
61
|
keepNames: !0,
|
62
62
|
external: f
|
63
63
|
});
|
64
|
-
const
|
65
|
-
return await import(`${a}?t=${
|
64
|
+
const g = Date.now();
|
65
|
+
return await import(`${a}?t=${g}`);
|
66
66
|
}, B = async (t) => {
|
67
67
|
const e = N(t), n = o(e, "salty.config.js"), { config: s } = await import(n);
|
68
68
|
return s;
|
@@ -73,12 +73,12 @@ const W = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", V = {
|
|
73
73
|
A(s) && q("rm -rf " + s), E(s), E(o(s, "css")), E(o(s, "types"));
|
74
74
|
})(), await nt(t);
|
75
75
|
const f = await B(t);
|
76
|
-
async function
|
76
|
+
async function g(c, u) {
|
77
77
|
const j = ["node_modules", "saltygen"], x = L(c);
|
78
78
|
if (x.isDirectory()) {
|
79
79
|
const b = U(c);
|
80
80
|
if (j.some((i) => c.includes(i))) return;
|
81
|
-
await Promise.all(b.map((i) =>
|
81
|
+
await Promise.all(b.map((i) => g(o(c, i), o(u, i))));
|
82
82
|
} else if (x.isFile() && O(c)) {
|
83
83
|
const T = await R(t, c, s), i = [];
|
84
84
|
Object.entries(T).forEach(([C, d]) => {
|
@@ -101,10 +101,10 @@ const W = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", V = {
|
|
101
101
|
F(p, l);
|
102
102
|
}
|
103
103
|
}
|
104
|
-
await
|
104
|
+
await g(t, s);
|
105
105
|
const r = e.map((c) => `@import url('./css/${c}');`).join(`
|
106
106
|
`);
|
107
|
-
let
|
107
|
+
let y = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
108
108
|
|
109
109
|
${["variables.css", "global.css", "templates.css"].filter((c) => {
|
110
110
|
try {
|
@@ -118,9 +118,9 @@ ${r}`;
|
|
118
118
|
if (f.importStrategy !== "component") {
|
119
119
|
const c = n.flat().map((u) => `@import url('./css/${u}');`).join(`
|
120
120
|
`);
|
121
|
-
|
121
|
+
y += c;
|
122
122
|
}
|
123
|
-
F(a,
|
123
|
+
F(a, y);
|
124
124
|
} catch (e) {
|
125
125
|
console.error(e);
|
126
126
|
}
|
@@ -128,17 +128,17 @@ ${r}`;
|
|
128
128
|
try {
|
129
129
|
const n = [], s = o(t, "./saltygen"), a = o(s, "index.css");
|
130
130
|
if (O(e)) {
|
131
|
-
const f = await B(t),
|
132
|
-
Object.entries(
|
131
|
+
const f = await B(t), g = await R(t, e, s);
|
132
|
+
Object.entries(g).forEach(([y, c]) => {
|
133
133
|
if (!c.generator) return;
|
134
134
|
const u = c.generator._withBuildContext({
|
135
|
-
name:
|
135
|
+
name: y,
|
136
136
|
config: f
|
137
137
|
}), j = `${u.hash}-${u.priority}.css`, x = `css/${j}`, b = o(s, x);
|
138
138
|
n.push(j), F(b, u.css);
|
139
139
|
});
|
140
140
|
const r = M(a, "utf8").split(`
|
141
|
-
`), S = n.map((
|
141
|
+
`), S = n.map((y) => `@import url('../saltygen/css/${y}');`), D = [.../* @__PURE__ */ new Set([...r, ...S])].join(`
|
142
142
|
`);
|
143
143
|
F(a, D);
|
144
144
|
}
|
@@ -151,12 +151,12 @@ ${r}`;
|
|
151
151
|
if (O(e)) {
|
152
152
|
const a = M(e, "utf8");
|
153
153
|
a.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== a && await X(e, a);
|
154
|
-
const f = await B(t),
|
154
|
+
const f = await B(t), g = await R(t, e, n);
|
155
155
|
let r = a;
|
156
|
-
Object.entries(
|
156
|
+
Object.entries(g).forEach(([$, D]) => {
|
157
157
|
var k;
|
158
158
|
if (D.isKeyframes || !D.generator) return;
|
159
|
-
const
|
159
|
+
const y = D.generator._withBuildContext({
|
160
160
|
name: $,
|
161
161
|
config: f
|
162
162
|
}), c = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
|
@@ -173,7 +173,7 @@ ${r}`;
|
|
173
173
|
}
|
174
174
|
if (!b) clearTimeout(T);
|
175
175
|
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}, "${
|
176
|
+
const p = x + i, C = r.slice(x, p), d = r, h = ` ${$} = styled(${u}, "${y.classNames}", "${y._callerName}", ${JSON.stringify(y.props)});`;
|
177
177
|
r = r.replace(C, h), d === r && console.error("Minimize file failed to change content", { name: $, tagName: u });
|
178
178
|
});
|
179
179
|
const S = v(e, 6);
|