@salty-css/vite 0.0.1-alpha.104 → 0.0.1-alpha.106
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/index.cjs +24 -14
- package/index.js +206 -193
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,18 +1,28 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
2
|
-
${
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const rt=require("esbuild"),it=require("child_process"),l=require("path"),f=require("fs"),L=require("fs/promises"),V=require("winston");var R=typeof document<"u"?document.currentScript:null;function ct(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const U=ct(rt),B=t=>String.fromCharCode(t+(t>25?39:97)),at=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=B(n%52)+s;return s=B(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},lt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=3)=>{const s=lt(5381,JSON.stringify(t))>>>0;return at(s,e)};function E(t){return t?typeof t!="string"?E(String(t)):t.replace(/\s/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const ut=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:o,transform:i}=n;t=t.replace(o,y=>{const{value:a,css:j}=i(y);return j&&s.push(j),a})}),{result:t,additionalCss:s}},G=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${E(n[1].replaceAll(".","-"))})`)}:{result:t},D=(t,e,s,n)=>{if(!t)return"";const o=[],i=Object.entries(t).reduce((a,[j,r])=>{const d=j.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(d==="variants")return Object.entries(r).forEach(([S,c])=>{c&&Object.entries(c).forEach(([p,m])=>{if(!m)return;const h=`${e}.${S}-${p}`,T=D(m,h);o.push(T)})}),a;if(d==="defaultVariants")return a;if(d==="compoundVariants")return r.forEach(S=>{const{css:c,...p}=S,m=Object.entries(p).reduce((T,[w,F])=>`${T}.${w}-${F}`,e),h=D(c,m);o.push(h)}),a;if(d.startsWith("@")){const S=D(r,e),c=`${d} {
|
2
|
+
${S.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return
|
6
|
-
`);if(!e)return
|
7
|
-
`)},H=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([
|
8
|
-
`)},K=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return f.existsSync(e)?e:
|
9
|
-
|
10
|
-
|
5
|
+
}`;return o.push(c),a}const g=j.includes("&")?d.replace("&",e):d.startsWith(":")?`${e}${d}`:`${e} ${d}`,$=D(r,g);return o.push($),a}const b=d.startsWith("-")?d:E(d),k=(g,$=";")=>a=`${a}${g}${$}`,C=g=>k(`${b}:${g}`);if(typeof r=="number")return C(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:u}={},O=function*(){yield G(r),yield ut(r,u)}();for(const{result:g,additionalCss:$=[]}of O)r=g,$.forEach(S=>{const c=D(S,"");k(c,"")});return C(r)},"");if(!i)return o.join(`
|
6
|
+
`);if(!e)return i;let y="";return y=`${e} { ${i} }`,[y,...o].join(`
|
7
|
+
`)},H=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,i])=>{if(typeof i=="object"){if(!i)return;const y=o.trim(),a=H(i,[...e,y]);s.push(a)}else n[o]=i}),Object.keys(n).length){const o=e.map(E).join("-"),i=D(n,`.${o}`);s.push(i)}return s.join(`
|
8
|
+
`)},ft=t=>Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=K(n).map(o=>`"${o}"`).join(" | ")),e),{}),K=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const i=e?`${e}.${n}`:n;return typeof o=="object"?K(o,i,s):s.add(e)}),[...s]):[],X=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return f.existsSync(e)?e:X(l.join(t,".."))},pt=async t=>{const e=X(t);return await L.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},dt=async t=>{const e=await pt(t);if(e)return e.type};let M;const Y=async t=>{if(M)return M;const e=await dt(t);return e==="module"?M="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:R&&R.tagName.toUpperCase()==="SCRIPT"&&R.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(M="cjs"),M||"esm"},Z=V.createLogger({level:"debug",format:V.format.combine(V.format.colorize(),V.format.cli()),transports:[new V.transports.Console({})]}),A={externalModules:[]},Q=t=>{if(A.externalModules.length>0)return A.externalModules;const e=l.join(t,"salty.config.ts"),n=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const o=n[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return A.externalModules=o,o},J=t=>l.join(t,"./saltygen"),yt=["salty","css","styles","styled"],gt=(t=[])=>new RegExp(`\\.(${[...yt,...t].join("|")})\\.`),_=(t,e=[])=>gt(e).test(t),mt=async t=>{const e=J(t),s=l.join(t,"salty.config.ts"),n=l.join(e,"salty.config.js"),o=await Y(t),i=Q(t);await U.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o,external:i});const y=Date.now(),{config:a}=await import(`${n}?t=${y}`);return a},v=async t=>{const e=await mt(t),s=new Set,n=(c,p=[])=>c?Object.entries(c).flatMap(([m,h])=>{if(!h)return;if(typeof h=="object")return n(h,[...p,m]);const T=[...p,m].join(".");s.add(`"${T}"`);const w=[...p.map(E),E(m)].join("-"),{result:F}=G(h);return`--${w}: ${F};`}):[],o=c=>c?Object.entries(c).flatMap(([p,m])=>{const h=n(m);return p==="base"?h.join(""):`${p} { ${h.join("")} }`}):[],i=c=>c?Object.entries(c).flatMap(([p,m])=>Object.entries(m).flatMap(([h,T])=>{const w=n(T,[p]),F=`.${p}-${h}, [data-${p}="${h}"]`,P=w.join("");return`${F} { ${P} }`})):[],y=n(e.variables),a=o(e.responsiveVariables),j=i(e.conditionalVariables),r=J(t),d=l.join(r,"css/variables.css"),b=`:root { ${y.join("")} ${a.join("")} } ${j.join("")}`;f.writeFileSync(d,b);const k=l.join(r,"css/global.css"),C=D(e.global,"");f.writeFileSync(k,C);const u=l.join(r,"css/templates.css"),x=H(e.templates),O=ft(e.templates);console.log(O),f.writeFileSync(u,x);const g=l.join(r,"types/css-tokens.d.ts"),S=`
|
9
|
+
// Variable types
|
10
|
+
type VariableTokens = ${[...s].join("|")};
|
11
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
11
12
|
|
12
|
-
|
13
|
+
// Template types
|
14
|
+
type TemplateTokens = {
|
15
|
+
${Object.entries(O).map(([c,p])=>`${c}?: ${p}`).join(`
|
13
16
|
`)}
|
14
|
-
|
15
|
-
|
16
|
-
`),o=s.map(
|
17
|
-
`);
|
18
|
-
|
17
|
+
}
|
18
|
+
`;f.writeFileSync(g,S)},I=async(t,e,s)=>{const n=q(e),o=l.join(s,"./temp");f.existsSync(o)||f.mkdirSync(o);const i=l.parse(e);let y=f.readFileSync(e,"utf8");y=y.replace(/styled\([^"'`{,]+,/g,"styled('div',");const a=l.join(s,"js",n+".js"),j=Q(t),r=await Y(t);await U.build({stdin:{contents:y,sourcefile:i.base,resolveDir:i.dir,loader:"ts"},minify:!1,treeShaking:!0,bundle:!0,outfile:a,format:r,target:["node20"],keepNames:!0,external:j,packages:"external"});const d=Date.now();return await import(`${a}?t=${d}`)},W=async t=>{const e=J(t),s=l.join(e,"salty.config.js"),{config:n}=await import(s);return n},tt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ht=async(t,e=tt())=>{try{e?Z.info("Generating CSS in production mode! 🔥"):Z.info("Generating CSS in development mode! 🚀");const s=[],n=[],o=J(t),i=l.join(o,"index.css");(()=>{f.existsSync(o)&&it.execSync("rm -rf "+o),f.mkdirSync(o),f.mkdirSync(l.join(o,"css")),f.mkdirSync(l.join(o,"types"))})(),await v(t);const a=await W(t);async function j(u,x){const O=["node_modules","saltygen"],g=f.statSync(u);if(g.isDirectory()){const $=f.readdirSync(u);if(O.some(c=>u.includes(c)))return;await Promise.all($.map(c=>j(l.join(u,c),l.join(x,c))))}else if(g.isFile()&&_(u)){const S=await I(t,u,o),c=[];Object.entries(S).forEach(([T,w])=>{if(w.isKeyframes&&w.css){const z=`${w.animationName}.css`,nt=`css/${z}`,ot=l.join(o,nt);s.push(z),f.writeFileSync(ot,w.css);return}if(!w.generator)return;const F=w.generator._withBuildContext({name:T,config:a,prod:e}),P=`${F.hash}-${F.priority}.css`;n[F.priority]||(n[F.priority]=[]),n[F.priority].push(P),c.push(P);const N=`css/${P}`,st=l.join(o,N);f.writeFileSync(st,F.css)});const p=c.map(T=>`@import url('./${T}');`).join(`
|
19
|
+
`),m=q(u,6),h=l.join(o,`css/${m}.css`);f.writeFileSync(h,p)}}await j(t,o);const r=s.map(u=>`@import url('./css/${u}');`).join(`
|
20
|
+
`);let C=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
21
|
+
|
22
|
+
${["variables.css","global.css","templates.css"].filter(u=>{try{return f.readFileSync(l.join(o,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
|
23
|
+
`)}
|
24
|
+
${r}`;if(a.importStrategy!=="component"){const u=n.flat().map(x=>`@import url('./css/${x}');`).join(`
|
25
|
+
`);C+=u}f.writeFileSync(i,C)}catch(s){console.error(s)}},jt=async(t,e)=>{try{const s=[],n=l.join(t,"./saltygen"),o=l.join(n,"index.css");if(_(e)){const y=await W(t),a=await I(t,e,n);Object.entries(a).forEach(([k,C])=>{if(!C.generator)return;const u=C.generator._withBuildContext({name:k,config:y}),x=`${u.hash}-${u.priority}.css`,O=`css/${x}`,g=l.join(n,O);s.push(x),f.writeFileSync(g,u.css)});const j=f.readFileSync(o,"utf8").split(`
|
26
|
+
`),r=s.map(k=>`@import url('../saltygen/css/${k}');`),b=[...new Set([...j,...r])].join(`
|
27
|
+
`);f.writeFileSync(o,b)}}catch(s){console.error(s)}},bt=async(t,e,s=tt())=>{try{const n=l.join(t,"./saltygen");if(_(e)){const i=f.readFileSync(e,"utf8");i.replace(/^(?!export\s)const\s.*/gm,b=>`export ${b}`)!==i&&await L.writeFile(e,i);const a=await W(t),j=await I(t,e,n);let r=i;Object.entries(j).forEach(([b,k])=>{var P;if(k.isKeyframes||!k.generator)return;const C=k.generator._withBuildContext({name:b,config:a,prod:s}),u=new RegExp(`\\s${b}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!u)return console.error("Could not find the original declaration");const x=(P=u.at(1))==null?void 0:P.trim(),O=new RegExp(`\\s${b}[=\\s]+styled\\(`,"g").exec(r);if(!O)return console.error("Could not find the original declaration");const{index:g}=O;let $=!1;const S=setTimeout(()=>$=!0,5e3);let c=0,p=!1,m=0;for(;!p&&!$;){const N=r[g+c];N==="("&&m++,N===")"&&m--,m===0&&N===")"&&(p=!0),c>r.length&&($=!0),c++}if(!$)clearTimeout(S);else throw new Error("Failed to find the end of the styled call and timed out");const h=g+c,T=r.slice(g,h),w=r,F=` ${b} = styled(${x}, "${C.classNames}", ${JSON.stringify(C.props)});`;r=r.replace(T,F),w===r&&console.error("Minimize file failed to change content",{name:b,tagName:x})});const d=q(e,6);return a.importStrategy==="component"&&(r=`import '../../saltygen/css/${d}.css';
|
28
|
+
${r}`),r=r.replace("{ styled }","{ styledClient as styled }"),r=r.replace("@salty-css/react/styled","@salty-css/react/styled-client"),r}}catch(n){console.error("Error in minimizeFile:",n)}},et=t=>({name:"stylegen",buildStart:()=>ht(t),load:async e=>{if(_(e))return await bt(t,e)},watchChange:{handler:async e=>{_(e)&&await jt(t,e),e.includes("salty.config")&&await v(t)}}});exports.default=et;exports.saltyPlugin=et;
|
package/index.js
CHANGED
@@ -1,179 +1,192 @@
|
|
1
1
|
import * as L from "esbuild";
|
2
|
-
import { execSync as
|
3
|
-
import { join as f, parse as
|
4
|
-
import { existsSync as B, writeFileSync as
|
5
|
-
import { readFile as
|
6
|
-
import { createLogger as
|
7
|
-
const H = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)),
|
8
|
-
let s = "",
|
9
|
-
for (
|
10
|
-
return s = H(
|
11
|
-
},
|
2
|
+
import { execSync as rt } from "child_process";
|
3
|
+
import { join as f, parse as it } from "path";
|
4
|
+
import { existsSync as B, writeFileSync as E, mkdirSync as A, statSync as ct, readdirSync as at, readFileSync as J } from "fs";
|
5
|
+
import { readFile as lt, writeFile as ft } from "fs/promises";
|
6
|
+
import { createLogger as pt, format as _, transports as ut } from "winston";
|
7
|
+
const H = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), gt = (t, e) => {
|
8
|
+
let s = "", n;
|
9
|
+
for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = H(n % 52) + s;
|
10
|
+
return s = H(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
+
}, dt = (t, e) => {
|
12
12
|
let s = e.length;
|
13
13
|
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
14
14
|
return t;
|
15
15
|
}, I = (t, e = 3) => {
|
16
|
-
const s =
|
17
|
-
return
|
16
|
+
const s = dt(5381, JSON.stringify(t)) >>> 0;
|
17
|
+
return gt(s, e);
|
18
18
|
};
|
19
|
-
function
|
20
|
-
return t ? typeof t != "string" ?
|
19
|
+
function V(t) {
|
20
|
+
return t ? typeof t != "string" ? V(String(t)) : t.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
|
21
21
|
}
|
22
|
-
const
|
22
|
+
const yt = (t, e) => {
|
23
23
|
if (typeof t != "string") return { result: t };
|
24
24
|
if (!e) return { result: t };
|
25
25
|
const s = [];
|
26
|
-
return Object.values(e).forEach((
|
27
|
-
const { pattern:
|
28
|
-
t = t.replace(
|
29
|
-
const { value: a, css:
|
30
|
-
return
|
26
|
+
return Object.values(e).forEach((n) => {
|
27
|
+
const { pattern: o, transform: i } = n;
|
28
|
+
t = t.replace(o, (g) => {
|
29
|
+
const { value: a, css: h } = i(g);
|
30
|
+
return h && s.push(h), a;
|
31
31
|
});
|
32
32
|
}), { result: t, additionalCss: s };
|
33
|
-
}, q = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...
|
33
|
+
}, q = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${V(n[1].replaceAll(".", "-"))})`) } : { result: t }, D = (t, e, s, n) => {
|
34
34
|
if (!t) return "";
|
35
|
-
const
|
36
|
-
const
|
37
|
-
if (typeof
|
38
|
-
if (!
|
39
|
-
if (
|
40
|
-
return Object.entries(
|
41
|
-
c && Object.entries(c).forEach(([
|
42
|
-
if (!
|
43
|
-
const
|
44
|
-
|
35
|
+
const o = [], i = Object.entries(t).reduce((a, [h, r]) => {
|
36
|
+
const u = h.trim();
|
37
|
+
if (typeof r == "function" && (r = r()), typeof r == "object") {
|
38
|
+
if (!r) return a;
|
39
|
+
if (u === "variants")
|
40
|
+
return Object.entries(r).forEach(([j, c]) => {
|
41
|
+
c && Object.entries(c).forEach(([p, y]) => {
|
42
|
+
if (!y) return;
|
43
|
+
const m = `${e}.${j}-${p}`, x = D(y, m);
|
44
|
+
o.push(x);
|
45
45
|
});
|
46
46
|
}), a;
|
47
|
-
if (
|
47
|
+
if (u === "defaultVariants")
|
48
48
|
return a;
|
49
|
-
if (
|
50
|
-
return
|
51
|
-
const { css: c, ...
|
52
|
-
|
49
|
+
if (u === "compoundVariants")
|
50
|
+
return r.forEach((j) => {
|
51
|
+
const { css: c, ...p } = j, y = Object.entries(p).reduce((x, [w, S]) => `${x}.${w}-${S}`, e), m = D(c, y);
|
52
|
+
o.push(m);
|
53
53
|
}), a;
|
54
|
-
if (
|
55
|
-
const
|
56
|
-
${
|
54
|
+
if (u.startsWith("@")) {
|
55
|
+
const j = D(r, e), c = `${u} {
|
56
|
+
${j.replace(`
|
57
57
|
`, `
|
58
58
|
`)}
|
59
59
|
}`;
|
60
|
-
return
|
60
|
+
return o.push(c), a;
|
61
61
|
}
|
62
|
-
const
|
63
|
-
return
|
62
|
+
const d = h.includes("&") ? u.replace("&", e) : u.startsWith(":") ? `${e}${u}` : `${e} ${u}`, b = D(r, d);
|
63
|
+
return o.push(b), a;
|
64
64
|
}
|
65
|
-
const $ =
|
66
|
-
if (typeof
|
67
|
-
if (typeof
|
68
|
-
if ("toString" in
|
65
|
+
const $ = u.startsWith("-") ? u : V(u), F = (d, b = ";") => a = `${a}${d}${b}`, C = (d) => F(`${$}:${d}`);
|
66
|
+
if (typeof r == "number") return C(r);
|
67
|
+
if (typeof r != "string")
|
68
|
+
if ("toString" in r) r = r.toString();
|
69
69
|
else return a;
|
70
|
-
const { modifiers: l } = {},
|
71
|
-
yield q(
|
70
|
+
const { modifiers: l } = {}, T = function* () {
|
71
|
+
yield q(r), yield yt(r, l);
|
72
72
|
}();
|
73
|
-
for (const { result:
|
74
|
-
|
75
|
-
const c =
|
76
|
-
|
73
|
+
for (const { result: d, additionalCss: b = [] } of T)
|
74
|
+
r = d, b.forEach((j) => {
|
75
|
+
const c = D(j, "");
|
76
|
+
F(c, "");
|
77
77
|
});
|
78
|
-
return C(
|
78
|
+
return C(r);
|
79
79
|
}, "");
|
80
|
-
if (!i) return
|
80
|
+
if (!i) return o.join(`
|
81
81
|
`);
|
82
82
|
if (!e) return i;
|
83
|
-
let
|
84
|
-
return
|
83
|
+
let g = "";
|
84
|
+
return g = `${e} { ${i} }`, [g, ...o].join(`
|
85
85
|
`);
|
86
86
|
}, U = (t, e = []) => {
|
87
87
|
if (!t) return "";
|
88
|
-
const s = [],
|
89
|
-
if (Object.entries(t).forEach(([
|
88
|
+
const s = [], n = {};
|
89
|
+
if (Object.entries(t).forEach(([o, i]) => {
|
90
90
|
if (typeof i == "object") {
|
91
91
|
if (!i) return;
|
92
|
-
const
|
92
|
+
const g = o.trim(), a = U(i, [...e, g]);
|
93
93
|
s.push(a);
|
94
94
|
} else
|
95
|
-
o
|
96
|
-
}), Object.keys(
|
97
|
-
const
|
95
|
+
n[o] = i;
|
96
|
+
}), Object.keys(n).length) {
|
97
|
+
const o = e.map(V).join("-"), i = D(n, `.${o}`);
|
98
98
|
s.push(i);
|
99
99
|
}
|
100
100
|
return s.join(`
|
101
101
|
`);
|
102
|
-
}, X = (t) => {
|
102
|
+
}, mt = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = X(n).map((o) => `"${o}"`).join(" | ")), e), {}), X = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
|
103
|
+
const i = e ? `${e}.${n}` : n;
|
104
|
+
return typeof o == "object" ? X(o, i, s) : s.add(e);
|
105
|
+
}), [...s]) : [], Y = (t) => {
|
103
106
|
if (!t || t === "/") throw new Error("Could not find package.json file");
|
104
107
|
const e = f(t, "package.json");
|
105
|
-
return B(e) ? e :
|
106
|
-
},
|
107
|
-
const e =
|
108
|
-
return await
|
108
|
+
return B(e) ? e : Y(f(t, ".."));
|
109
|
+
}, ht = async (t) => {
|
110
|
+
const e = Y(t);
|
111
|
+
return await lt(e, "utf-8").then(JSON.parse).catch(() => {
|
109
112
|
});
|
110
|
-
},
|
111
|
-
const e = await
|
113
|
+
}, $t = async (t) => {
|
114
|
+
const e = await ht(t);
|
112
115
|
if (e)
|
113
116
|
return e.type;
|
114
117
|
};
|
115
|
-
let
|
116
|
-
const
|
117
|
-
if (
|
118
|
-
const e = await
|
119
|
-
return e === "module" ?
|
120
|
-
}, K =
|
118
|
+
let O;
|
119
|
+
const Q = async (t) => {
|
120
|
+
if (O) return O;
|
121
|
+
const e = await $t(t);
|
122
|
+
return e === "module" ? O = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (O = "cjs"), O || "esm";
|
123
|
+
}, K = pt({
|
121
124
|
level: "debug",
|
122
125
|
format: _.combine(_.colorize(), _.cli()),
|
123
|
-
transports: [new
|
126
|
+
transports: [new ut.Console({})]
|
124
127
|
}), W = {
|
125
128
|
externalModules: []
|
126
|
-
},
|
129
|
+
}, v = (t) => {
|
127
130
|
if (W.externalModules.length > 0) return W.externalModules;
|
128
|
-
const e = f(t, "salty.config.ts"),
|
129
|
-
if (!
|
130
|
-
const
|
131
|
-
return W.externalModules =
|
132
|
-
}, R = (t) => f(t, "./saltygen"),
|
133
|
-
const e = R(t), s = f(t, "salty.config.ts"),
|
131
|
+
const e = f(t, "salty.config.ts"), n = J(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
132
|
+
if (!n) return [];
|
133
|
+
const o = n[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
|
134
|
+
return W.externalModules = o, o;
|
135
|
+
}, R = (t) => f(t, "./saltygen"), bt = ["salty", "css", "styles", "styled"], jt = (t = []) => new RegExp(`\\.(${[...bt, ...t].join("|")})\\.`), N = (t, e = []) => jt(e).test(t), wt = async (t) => {
|
136
|
+
const e = R(t), s = f(t, "salty.config.ts"), n = f(e, "salty.config.js"), o = await Q(t), i = v(t);
|
134
137
|
await L.build({
|
135
138
|
entryPoints: [s],
|
136
139
|
minify: !0,
|
137
140
|
treeShaking: !0,
|
138
141
|
bundle: !0,
|
139
|
-
outfile:
|
140
|
-
format:
|
142
|
+
outfile: n,
|
143
|
+
format: o,
|
141
144
|
external: i
|
142
145
|
});
|
143
|
-
const
|
146
|
+
const g = Date.now(), { config: a } = await import(`${n}?t=${g}`);
|
144
147
|
return a;
|
145
|
-
},
|
146
|
-
const e = await
|
147
|
-
if (!
|
148
|
-
if (typeof
|
149
|
-
const x = [...
|
148
|
+
}, tt = async (t) => {
|
149
|
+
const e = await wt(t), s = /* @__PURE__ */ new Set(), n = (c, p = []) => c ? Object.entries(c).flatMap(([y, m]) => {
|
150
|
+
if (!m) return;
|
151
|
+
if (typeof m == "object") return n(m, [...p, y]);
|
152
|
+
const x = [...p, y].join(".");
|
150
153
|
s.add(`"${x}"`);
|
151
|
-
const
|
152
|
-
return `--${
|
153
|
-
}) : [],
|
154
|
-
const
|
155
|
-
return
|
156
|
-
}) : [], i = (
|
157
|
-
const
|
158
|
-
return `${
|
159
|
-
})) : [],
|
160
|
-
|
161
|
-
const
|
162
|
-
|
163
|
-
const
|
164
|
-
|
165
|
-
const
|
166
|
-
|
154
|
+
const w = [...p.map(V), V(y)].join("-"), { result: S } = q(m);
|
155
|
+
return `--${w}: ${S};`;
|
156
|
+
}) : [], o = (c) => c ? Object.entries(c).flatMap(([p, y]) => {
|
157
|
+
const m = n(y);
|
158
|
+
return p === "base" ? m.join("") : `${p} { ${m.join("")} }`;
|
159
|
+
}) : [], i = (c) => c ? Object.entries(c).flatMap(([p, y]) => Object.entries(y).flatMap(([m, x]) => {
|
160
|
+
const w = n(x, [p]), S = `.${p}-${m}, [data-${p}="${m}"]`, P = w.join("");
|
161
|
+
return `${S} { ${P} }`;
|
162
|
+
})) : [], g = n(e.variables), a = o(e.responsiveVariables), h = i(e.conditionalVariables), r = R(t), u = f(r, "css/variables.css"), $ = `:root { ${g.join("")} ${a.join("")} } ${h.join("")}`;
|
163
|
+
E(u, $);
|
164
|
+
const F = f(r, "css/global.css"), C = D(e.global, "");
|
165
|
+
E(F, C);
|
166
|
+
const l = f(r, "css/templates.css"), k = U(e.templates), T = mt(e.templates);
|
167
|
+
console.log(T), E(l, k);
|
168
|
+
const d = f(r, "types/css-tokens.d.ts"), j = `
|
169
|
+
// Variable types
|
170
|
+
type VariableTokens = ${[...s].join("|")};
|
171
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
172
|
+
|
173
|
+
// Template types
|
174
|
+
type TemplateTokens = {
|
175
|
+
${Object.entries(T).map(([c, p]) => `${c}?: ${p}`).join(`
|
176
|
+
`)}
|
177
|
+
}
|
178
|
+
`;
|
179
|
+
E(d, j);
|
167
180
|
}, Z = async (t, e, s) => {
|
168
|
-
const
|
169
|
-
B(
|
170
|
-
const i =
|
171
|
-
let
|
172
|
-
|
173
|
-
const a = f(s, "js",
|
181
|
+
const n = I(e), o = f(s, "./temp");
|
182
|
+
B(o) || A(o);
|
183
|
+
const i = it(e);
|
184
|
+
let g = J(e, "utf8");
|
185
|
+
g = g.replace(/styled\([^"'`{,]+,/g, "styled('div',");
|
186
|
+
const a = f(s, "js", n + ".js"), h = v(t), r = await Q(t);
|
174
187
|
await L.build({
|
175
188
|
stdin: {
|
176
|
-
contents:
|
189
|
+
contents: g,
|
177
190
|
sourcefile: i.base,
|
178
191
|
resolveDir: i.dir,
|
179
192
|
loader: "ts"
|
@@ -182,153 +195,153 @@ const Y = async (t) => {
|
|
182
195
|
treeShaking: !0,
|
183
196
|
bundle: !0,
|
184
197
|
outfile: a,
|
185
|
-
format:
|
198
|
+
format: r,
|
186
199
|
target: ["node20"],
|
187
200
|
keepNames: !0,
|
188
|
-
external:
|
201
|
+
external: h,
|
189
202
|
packages: "external"
|
190
203
|
});
|
191
|
-
const
|
192
|
-
return await import(`${a}?t=${
|
204
|
+
const u = Date.now();
|
205
|
+
return await import(`${a}?t=${u}`);
|
193
206
|
}, z = async (t) => {
|
194
|
-
const e = R(t), s = f(e, "salty.config.js"), { config:
|
195
|
-
return
|
196
|
-
},
|
207
|
+
const e = R(t), s = f(e, "salty.config.js"), { config: n } = await import(s);
|
208
|
+
return n;
|
209
|
+
}, et = () => {
|
197
210
|
try {
|
198
211
|
return process.env.NODE_ENV === "production";
|
199
212
|
} catch {
|
200
213
|
return !1;
|
201
214
|
}
|
202
|
-
},
|
215
|
+
}, St = async (t, e = et()) => {
|
203
216
|
try {
|
204
217
|
e ? K.info("Generating CSS in production mode! 🔥") : K.info("Generating CSS in development mode! 🚀");
|
205
|
-
const s = [],
|
218
|
+
const s = [], n = [], o = R(t), i = f(o, "index.css");
|
206
219
|
(() => {
|
207
|
-
B(
|
208
|
-
})(), await
|
220
|
+
B(o) && rt("rm -rf " + o), A(o), A(f(o, "css")), A(f(o, "types"));
|
221
|
+
})(), await tt(t);
|
209
222
|
const a = await z(t);
|
210
|
-
async function
|
211
|
-
const
|
212
|
-
if (
|
213
|
-
const b =
|
214
|
-
if (
|
215
|
-
await Promise.all(b.map((c) =>
|
216
|
-
} else if (
|
217
|
-
const
|
218
|
-
Object.entries(
|
223
|
+
async function h(l, k) {
|
224
|
+
const T = ["node_modules", "saltygen"], d = ct(l);
|
225
|
+
if (d.isDirectory()) {
|
226
|
+
const b = at(l);
|
227
|
+
if (T.some((c) => l.includes(c))) return;
|
228
|
+
await Promise.all(b.map((c) => h(f(l, c), f(k, c))));
|
229
|
+
} else if (d.isFile() && N(l)) {
|
230
|
+
const j = await Z(t, l, o), c = [];
|
231
|
+
Object.entries(j).forEach(([x, w]) => {
|
219
232
|
if (w.isKeyframes && w.css) {
|
220
|
-
const G = `${w.animationName}.css`,
|
221
|
-
s.push(G),
|
233
|
+
const G = `${w.animationName}.css`, nt = `css/${G}`, ot = f(o, nt);
|
234
|
+
s.push(G), E(ot, w.css);
|
222
235
|
return;
|
223
236
|
}
|
224
237
|
if (!w.generator) return;
|
225
|
-
const
|
226
|
-
name:
|
238
|
+
const S = w.generator._withBuildContext({
|
239
|
+
name: x,
|
227
240
|
config: a,
|
228
241
|
prod: e
|
229
|
-
}),
|
230
|
-
|
231
|
-
const
|
232
|
-
|
242
|
+
}), P = `${S.hash}-${S.priority}.css`;
|
243
|
+
n[S.priority] || (n[S.priority] = []), n[S.priority].push(P), c.push(P);
|
244
|
+
const M = `css/${P}`, st = f(o, M);
|
245
|
+
E(st, S.css);
|
233
246
|
});
|
234
|
-
const
|
235
|
-
`),
|
236
|
-
|
247
|
+
const p = c.map((x) => `@import url('./${x}');`).join(`
|
248
|
+
`), y = I(l, 6), m = f(o, `css/${y}.css`);
|
249
|
+
E(m, p);
|
237
250
|
}
|
238
251
|
}
|
239
|
-
await
|
240
|
-
const
|
252
|
+
await h(t, o);
|
253
|
+
const r = s.map((l) => `@import url('./css/${l}');`).join(`
|
241
254
|
`);
|
242
255
|
let C = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
243
256
|
|
244
257
|
${["variables.css", "global.css", "templates.css"].filter((l) => {
|
245
258
|
try {
|
246
|
-
return J(f(
|
259
|
+
return J(f(o, "css", l), "utf8").length > 0;
|
247
260
|
} catch {
|
248
261
|
return !1;
|
249
262
|
}
|
250
263
|
}).map((l) => `@import url('./css/${l}');`).join(`
|
251
264
|
`)}
|
252
|
-
${
|
265
|
+
${r}`;
|
253
266
|
if (a.importStrategy !== "component") {
|
254
|
-
const l =
|
267
|
+
const l = n.flat().map((k) => `@import url('./css/${k}');`).join(`
|
255
268
|
`);
|
256
269
|
C += l;
|
257
270
|
}
|
258
|
-
|
271
|
+
E(i, C);
|
259
272
|
} catch (s) {
|
260
273
|
console.error(s);
|
261
274
|
}
|
262
|
-
},
|
275
|
+
}, Ft = async (t, e) => {
|
263
276
|
try {
|
264
|
-
const s = [],
|
265
|
-
if (
|
266
|
-
const
|
267
|
-
Object.entries(a).forEach(([
|
277
|
+
const s = [], n = f(t, "./saltygen"), o = f(n, "index.css");
|
278
|
+
if (N(e)) {
|
279
|
+
const g = await z(t), a = await Z(t, e, n);
|
280
|
+
Object.entries(a).forEach(([F, C]) => {
|
268
281
|
if (!C.generator) return;
|
269
282
|
const l = C.generator._withBuildContext({
|
270
|
-
name:
|
271
|
-
config:
|
272
|
-
}),
|
273
|
-
s.push(
|
283
|
+
name: F,
|
284
|
+
config: g
|
285
|
+
}), k = `${l.hash}-${l.priority}.css`, T = `css/${k}`, d = f(n, T);
|
286
|
+
s.push(k), E(d, l.css);
|
274
287
|
});
|
275
|
-
const
|
276
|
-
`),
|
288
|
+
const h = J(o, "utf8").split(`
|
289
|
+
`), r = s.map((F) => `@import url('../saltygen/css/${F}');`), $ = [.../* @__PURE__ */ new Set([...h, ...r])].join(`
|
277
290
|
`);
|
278
|
-
|
291
|
+
E(o, $);
|
279
292
|
}
|
280
293
|
} catch (s) {
|
281
294
|
console.error(s);
|
282
295
|
}
|
283
|
-
},
|
296
|
+
}, Ct = async (t, e, s = et()) => {
|
284
297
|
try {
|
285
|
-
const
|
286
|
-
if (
|
298
|
+
const n = f(t, "./saltygen");
|
299
|
+
if (N(e)) {
|
287
300
|
const i = J(e, "utf8");
|
288
|
-
i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await
|
289
|
-
const a = await z(t),
|
290
|
-
let
|
291
|
-
Object.entries(
|
292
|
-
var
|
293
|
-
if (
|
294
|
-
const C =
|
301
|
+
i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await ft(e, i);
|
302
|
+
const a = await z(t), h = await Z(t, e, n);
|
303
|
+
let r = i;
|
304
|
+
Object.entries(h).forEach(([$, F]) => {
|
305
|
+
var P;
|
306
|
+
if (F.isKeyframes || !F.generator) return;
|
307
|
+
const C = F.generator._withBuildContext({
|
295
308
|
name: $,
|
296
309
|
config: a,
|
297
310
|
prod: s
|
298
311
|
}), l = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
|
299
312
|
if (!l) return console.error("Could not find the original declaration");
|
300
|
-
const
|
301
|
-
if (!
|
302
|
-
const { index:
|
313
|
+
const k = (P = l.at(1)) == null ? void 0 : P.trim(), T = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(r);
|
314
|
+
if (!T) return console.error("Could not find the original declaration");
|
315
|
+
const { index: d } = T;
|
303
316
|
let b = !1;
|
304
|
-
const
|
305
|
-
let c = 0,
|
306
|
-
for (; !
|
307
|
-
const
|
308
|
-
|
317
|
+
const j = setTimeout(() => b = !0, 5e3);
|
318
|
+
let c = 0, p = !1, y = 0;
|
319
|
+
for (; !p && !b; ) {
|
320
|
+
const M = r[d + c];
|
321
|
+
M === "(" && y++, M === ")" && y--, y === 0 && M === ")" && (p = !0), c > r.length && (b = !0), c++;
|
309
322
|
}
|
310
|
-
if (!b) clearTimeout(
|
323
|
+
if (!b) clearTimeout(j);
|
311
324
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
312
|
-
const
|
313
|
-
|
325
|
+
const m = d + c, x = r.slice(d, m), w = r, S = ` ${$} = styled(${k}, "${C.classNames}", ${JSON.stringify(C.props)});`;
|
326
|
+
r = r.replace(x, S), w === r && console.error("Minimize file failed to change content", { name: $, tagName: k });
|
314
327
|
});
|
315
|
-
const
|
316
|
-
return a.importStrategy === "component" && (
|
317
|
-
${
|
328
|
+
const u = I(e, 6);
|
329
|
+
return a.importStrategy === "component" && (r = `import '../../saltygen/css/${u}.css';
|
330
|
+
${r}`), r = r.replace("{ styled }", "{ styledClient as styled }"), r = r.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), r;
|
318
331
|
}
|
319
|
-
} catch (
|
320
|
-
console.error("Error in minimizeFile:",
|
332
|
+
} catch (n) {
|
333
|
+
console.error("Error in minimizeFile:", n);
|
321
334
|
}
|
322
335
|
}, Dt = (t) => ({
|
323
336
|
name: "stylegen",
|
324
|
-
buildStart: () =>
|
337
|
+
buildStart: () => St(t),
|
325
338
|
load: async (e) => {
|
326
|
-
if (
|
327
|
-
return await
|
339
|
+
if (N(e))
|
340
|
+
return await Ct(t, e);
|
328
341
|
},
|
329
342
|
watchChange: {
|
330
343
|
handler: async (e) => {
|
331
|
-
|
344
|
+
N(e) && await Ft(t, e), e.includes("salty.config") && await tt(t);
|
332
345
|
}
|
333
346
|
}
|
334
347
|
});
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/vite",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.106",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -34,6 +34,6 @@
|
|
34
34
|
}
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
|
-
"@salty-css/core": "^0.0.1-alpha.
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.106"
|
38
38
|
}
|
39
39
|
}
|