@salty-css/core 0.0.1-alpha.36 → 0.0.1-alpha.37
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 +3 -3
- package/compiler/index.js +19 -23
- package/package.json +1 -1
package/compiler/index.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const I=require("esbuild"),B=require("child_process"),P=require("../dash-case-DKzpenwY.cjs"),o=require("path"),r=require("fs"),K=require("fs/promises"),V=require("../parse-templates-W0YfTmOT.cjs");function G(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 R=G(I),N=t=>o.join(t,"./saltygen"),_=["salty","css","styles","styled"],q=(t=[])=>new RegExp(`\\.(${[..._,...t].join("|")})\\.`),O=(t,e=[])=>q(e).test(t),J=async t=>{const e=N(t),n=o.join(t,"salty.config.ts"),s=o.join(e,"salty.config.js");await R.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:"esm",external:["react"]});const a=Date.now(),{config:w}=await import(`${s}?t=${a}`);return w},M=async t=>{const e=await J(t),n=new Set,s=(d,y=[])=>d?Object.entries(d).flatMap(([p,c])=>{if(!c)return;if(typeof c=="object")return s(c,[...y,p]);const C=[...y,p].join(".");n.add(`"${C}"`);const x=[...y.map(P.dashCase),P.dashCase(p)].join("-"),{result:D}=V.parseValueTokens(c);return`--${x}: ${D};`}):[],a=d=>d?Object.entries(d).flatMap(([y,p])=>{const c=s(p);return y==="base"?c.join(""):`${y} { ${c.join("")} }`}):[],w=d=>d?Object.entries(d).flatMap(([y,p])=>Object.entries(p).flatMap(([c,C])=>{const x=s(C,[y]),D=`.${y}-${c}, [data-${y}="${c}"]`,k=x.join("");return`${D} { ${k} }`})):[],j=s(e.variables),S=a(e.responsiveVariables),l=w(e.conditionalVariables),b=N(t),f=o.join(b,"css/variables.css"),i=`:root { ${j.join("")} ${S.join("")} } ${l.join("")}`;r.writeFileSync(f,i);const g=o.join(b,"types/css-tokens.d.ts"),m=`type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;r.writeFileSync(g,m);const u=o.join(b,"css/global.css"),h=V.parseStyles(e.global,"");r.writeFileSync(u,h);const F=o.join(b,"css/templates.css"),v=V.parseTemplates(e.templates);r.writeFileSync(F,v)},T=async(t,e)=>{const n=P.toHash(t),s=o.join(e,"js",n+".js");await R.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:s,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const a=Date.now();return await import(`${s}?t=${a}`)},E=async t=>{const e=N(t),n=o.join(e,"salty.config.js"),{config:s}=await import(n);return s},A=async t=>{try{const e=[],n=[],s=N(t),a=o.join(s,"index.css");(()=>{r.existsSync(s)&&B.execSync("rm -rf "+s),r.mkdirSync(s),r.mkdirSync(o.join(s,"css")),r.mkdirSync(o.join(s,"types"))})(),await M(t);const j=await E(t);async function S(i,g){const $=r.statSync(i);if($.isDirectory()){const m=r.readdirSync(i);await Promise.all(m.map(u=>S(o.join(i,u),o.join(g,u))))}else if($.isFile()&&O(i)){const u=await T(i,s),h=[];Object.entries(u).forEach(([y,p])=>{if(p.isKeyframes&&p.css){const k=`${p.animationName}.css`,z=`css/${k}`,H=o.join(s,z);e.push(k),r.writeFileSync(H,p.css);return}if(!p.generator)return;const c=p.generator._withBuildContext({name:y,config:j}),C=`${c.hash}-${c.priority}.css`;n[c.priority]||(n[c.priority]=[]),n[c.priority].push(C),h.push(C);const x=`css/${C}`,D=o.join(s,x);r.writeFileSync(D,c.css)});const F=h.map(y=>`@import url('./${y}');`).join(`
|
2
2
|
`),v=P.toHash(i,6),d=o.join(s,`css/${v}.css`);r.writeFileSync(d,F)}}await S(t,s);const l=e.map(i=>`@import url('./css/${i}');`).join(`
|
3
3
|
`);let f=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
4
4
|
|
@@ -7,5 +7,5 @@ ${["@import url('./css/variables.css');","@import url('./css/global.css');","@im
|
|
7
7
|
${l}`;if(j.importStrategy!=="component"){const i=n.flat().map(g=>`@import url('./css/${g}');`).join(`
|
8
8
|
`);f+=i}r.writeFileSync(a,f)}catch(e){console.error(e)}},L=async(t,e)=>{try{const n=[],s=o.join(t,"./saltygen"),a=o.join(s,"index.css");if(O(e)){const j=await E(t),S=await T(e,s);Object.entries(S).forEach(([g,$])=>{if(!$.generator)return;const m=$.generator._withBuildContext({name:g,config:j}),u=`${m.hash}-${m.priority}.css`,h=`css/${u}`,F=o.join(s,h);n.push(u),r.writeFileSync(F,m.css)});const l=r.readFileSync(a,"utf8").split(`
|
9
9
|
`),b=n.map(g=>`@import url('../saltygen/css/${g}');`),i=[...new Set([...l,...b])].join(`
|
10
|
-
`);r.writeFileSync(a,i)}}catch(n){console.error(n)}},U=async(t,e)=>{try{const n=o.join(t,"./saltygen");if(O(e)){const a=r.readFileSync(e,"utf8");a.replace(/^(?!export\s)const\s.*/gm,f=>`export ${f}`)!==a&&await K.writeFile(e,a);const j=await E(t),S=await T(e,n);let l=a;Object.entries(S).forEach(([f,i])=>{var F;if(i.isKeyframes
|
11
|
-
${l}`),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error(n)}};exports.compileSaltyFile=T;exports.generateConfigStyles=M;exports.generateCss=A;exports.generateFile=L;exports.isSaltyFile=O;exports.minimizeFile=U;exports.saltyFileExtensions=_;exports.saltyFileRegExp=q;
|
10
|
+
`);r.writeFileSync(a,i)}}catch(n){console.error(n)}},U=async(t,e)=>{try{const n=o.join(t,"./saltygen");if(O(e)){const a=r.readFileSync(e,"utf8");a.replace(/^(?!export\s)const\s.*/gm,f=>`export ${f}`)!==a&&await K.writeFile(e,a);const j=await E(t),S=await T(e,n);let l=a;Object.entries(S).forEach(([f,i])=>{var F;if(i.isKeyframes||!i.generator)return;const g=i.generator._withBuildContext({name:f,config:j}),$=new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!$)return console.error("Could not find the original declaration");const m=(F=$.at(1))==null?void 0:F.trim(),u=`${f} = styled(${m}, "${g.classNames}", "${g._callerName}", ${JSON.stringify(g.props)});`,h=new RegExp(`${f}[=\\s]+[^()]+styled\\(([^)]|\\n|\\(.*\\){1})+\\)$`,"gm");l=l.replace(h,u)});const b=P.toHash(e,6);return j.importStrategy==="component"&&(l=`import '../../saltygen/css/${b}.css';
|
11
|
+
${l}`),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error("Error in minimizeFile",n)}};exports.compileSaltyFile=T;exports.generateConfigStyles=M;exports.generateCss=A;exports.generateFile=L;exports.isSaltyFile=O;exports.minimizeFile=U;exports.saltyFileExtensions=_;exports.saltyFileRegExp=q;
|
package/compiler/index.js
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import * as I from "esbuild";
|
2
|
-
import { execSync as
|
2
|
+
import { execSync as z } from "child_process";
|
3
3
|
import { t as T, d as R } from "../dash-case-DMQMcCO6.js";
|
4
4
|
import { join as o } from "path";
|
5
|
-
import { writeFileSync as $, existsSync as
|
5
|
+
import { writeFileSync as $, existsSync as H, mkdirSync as V, statSync as K, readdirSync as G, readFileSync as M } from "fs";
|
6
6
|
import { writeFile as J } from "fs/promises";
|
7
7
|
import { p as q, a as A, b as L } from "../parse-templates-D4p3pgQR.js";
|
8
8
|
const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W = (s = []) => new RegExp(`\\.(${[...U, ...s].join("|")})\\.`), v = (s, e = []) => W(e).test(s), X = async (s) => {
|
@@ -34,10 +34,10 @@ const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W
|
|
34
34
|
return `${D} { ${P} }`;
|
35
35
|
})) : [], d = t(e.variables), w = c(e.responsiveVariables), a = S(e.conditionalVariables), b = N(s), f = o(b, "css/variables.css"), i = `:root { ${d.join("")} ${w.join("")} } ${a.join("")}`;
|
36
36
|
$(f, i);
|
37
|
-
const y = o(b, "types/css-tokens.d.ts"),
|
38
|
-
$(y,
|
39
|
-
const
|
40
|
-
$(
|
37
|
+
const y = o(b, "types/css-tokens.d.ts"), g = `type VariableTokens = ${[...n].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
38
|
+
$(y, g);
|
39
|
+
const m = o(b, "css/global.css"), F = q(e.global, "");
|
40
|
+
$(m, F);
|
41
41
|
const j = o(b, "css/templates.css"), k = A(e.templates);
|
42
42
|
$(j, k);
|
43
43
|
}, E = async (s, e) => {
|
@@ -62,17 +62,17 @@ const N = (s) => o(s, "./saltygen"), U = ["salty", "css", "styles", "styled"], W
|
|
62
62
|
try {
|
63
63
|
const e = [], n = [], t = N(s), c = o(t, "index.css");
|
64
64
|
(() => {
|
65
|
-
|
65
|
+
H(t) && z("rm -rf " + t), V(t), V(o(t, "css")), V(o(t, "types"));
|
66
66
|
})(), await Y(s);
|
67
67
|
const d = await O(s);
|
68
68
|
async function w(i, y) {
|
69
|
-
const h =
|
69
|
+
const h = K(i);
|
70
70
|
if (h.isDirectory()) {
|
71
|
-
const
|
72
|
-
await Promise.all(
|
71
|
+
const g = G(i);
|
72
|
+
await Promise.all(g.map((m) => w(o(i, m), o(y, m))));
|
73
73
|
} else if (h.isFile() && v(i)) {
|
74
|
-
const
|
75
|
-
Object.entries(
|
74
|
+
const m = await E(i, t), F = [];
|
75
|
+
Object.entries(m).forEach(([l, p]) => {
|
76
76
|
if (p.isKeyframes && p.css) {
|
77
77
|
const P = `${p.animationName}.css`, _ = `css/${P}`, B = o(t, _);
|
78
78
|
e.push(P), $(B, p.css);
|
@@ -116,11 +116,11 @@ ${a}`;
|
|
116
116
|
const d = await O(s), w = await E(e, t);
|
117
117
|
Object.entries(w).forEach(([y, h]) => {
|
118
118
|
if (!h.generator) return;
|
119
|
-
const
|
119
|
+
const g = h.generator._withBuildContext({
|
120
120
|
name: y,
|
121
121
|
config: d
|
122
|
-
}),
|
123
|
-
n.push(
|
122
|
+
}), m = `${g.hash}-${g.priority}.css`, F = `css/${m}`, j = o(t, F);
|
123
|
+
n.push(m), $(j, g.css);
|
124
124
|
});
|
125
125
|
const a = M(c, "utf8").split(`
|
126
126
|
`), b = n.map((y) => `@import url('../saltygen/css/${y}');`), i = [.../* @__PURE__ */ new Set([...a, ...b])].join(`
|
@@ -140,26 +140,22 @@ ${a}`;
|
|
140
140
|
let a = c;
|
141
141
|
Object.entries(w).forEach(([f, i]) => {
|
142
142
|
var j;
|
143
|
-
if (i.isKeyframes)
|
144
|
-
console.log("value", i);
|
145
|
-
return;
|
146
|
-
}
|
147
|
-
if (!i.generator) return;
|
143
|
+
if (i.isKeyframes || !i.generator) return;
|
148
144
|
const y = i.generator._withBuildContext({
|
149
145
|
name: f,
|
150
146
|
config: d
|
151
147
|
}), h = new RegExp(`${f}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(c);
|
152
148
|
if (!h)
|
153
149
|
return console.error("Could not find the original declaration");
|
154
|
-
const
|
155
|
-
a = a.replace(F,
|
150
|
+
const g = (j = h.at(1)) == null ? void 0 : j.trim(), m = `${f} = styled(${g}, "${y.classNames}", "${y._callerName}", ${JSON.stringify(y.props)});`, F = new RegExp(`${f}[=\\s]+[^()]+styled\\(([^)]|\\n|\\(.*\\){1})+\\)$`, "gm");
|
151
|
+
a = a.replace(F, m);
|
156
152
|
});
|
157
153
|
const b = T(e, 6);
|
158
154
|
return d.importStrategy === "component" && (a = `import '../../saltygen/css/${b}.css';
|
159
155
|
${a}`), a = a.replace("{ styled }", "{ styledClient as styled }"), a = a.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), a;
|
160
156
|
}
|
161
157
|
} catch (n) {
|
162
|
-
console.error(n);
|
158
|
+
console.error("Error in minimizeFile", n);
|
163
159
|
}
|
164
160
|
};
|
165
161
|
export {
|