@salty-css/vite 0.0.1-alpha.131 → 0.0.1-alpha.132
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 +16 -16
- package/index.d.ts +2 -8
- package/index.js +195 -187
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,28 +1,28 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const fe=require("esbuild"),
|
2
|
-
${
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const fe=require("esbuild"),ue=require("child_process"),c=require("path"),u=require("fs"),G=require("fs/promises"),J=require("winston");var Z=typeof document<"u"?document.currentScript:null;function pe(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 X=pe(fe),U=e=>String.fromCharCode(e+(e>25?39:97)),de=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=U(n%52)+s;return s=U(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},ye=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},I=(e,t=5)=>{const s=ye(5381,JSON.stringify(e))>>>0;return de(s,t)};function D(e){return e?typeof e!="string"?D(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 ge=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:i,transform:r}=n;e=e.replace(i,y=>{const{value:f,css:h}=r(y);return h&&s.push(h),f})}),{result:e,additionalCss:s}},Y=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${D(n[1].replaceAll(".","-"))})`)}:{result:e},O=(e,t,s,n)=>{if(!e)return"";const i=[],r=Object.entries(e).reduce((f,[h,o])=>{const a=h.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return f;if(a==="variants")return Object.entries(o).forEach(([d,$])=>{$&&Object.entries($).forEach(([C,P])=>{if(!P)return;const T=`${t}.${d}-${C}`,p=O(P,T);i.push(p)})}),f;if(a==="defaultVariants")return f;if(a==="compoundVariants")return o.forEach(d=>{const{css:$,...C}=d,P=Object.entries(C).reduce((p,[g,w])=>`${p}.${g}-${w}`,t),T=O($,P);i.push(T)}),f;if(a.startsWith("@")){const d=O(o,t),$=`${a} {
|
2
|
+
${d.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return i.push(
|
6
|
-
`);if(!t)return r;let
|
7
|
-
`)},Q=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([i,r])=>{if(typeof r=="object"){if(!r)return;const
|
8
|
-
`)},
|
5
|
+
}`;return i.push($),f}const m=h.includes("&")?a.replace("&",t):a.startsWith(":")?`${t}${a}`:`${t} ${a}`,l=O(o,m);return i.push(l),f}const F=a.startsWith("-")?a:D(a),x=(m,l=";")=>f=`${f}${m}${l}`,b=m=>x(`${F}:${m}`);if(typeof o=="number")return b(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return f;const{modifiers:k}={},j=function*(){yield Y(o),yield ge(o,k)}();for(const{result:m,additionalCss:l=[]}of j)o=m,l.forEach(d=>{const $=O(d,"");x($,"")});return b(o)},"");if(!r)return i.join(`
|
6
|
+
`);if(!t)return r;let y="";return y=`${t} { ${r} }`,[y,...i].join(`
|
7
|
+
`)},Q=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([i,r])=>{if(typeof r=="object"){if(!r)return;const y=i.trim(),f=Q(r,[...t,y]);s.push(f)}else n[i]=r}),Object.keys(n).length){const i=t.map(D).join("-"),r=O(n,`.${i}`);s.push(r)}return s.join(`
|
8
|
+
`)},me=e=>Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=v(n).map(i=>`"${i}"`).join(" | ")),t),{}),v=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,i])=>{const r=t?`${t}.${n}`:n;return typeof i=="object"?v(i,r,s):s.add(t)}),[...s]):[],ee=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=c.join(e,"package.json");return u.existsSync(t)?t:ee(c.join(e,".."))},he=async e=>{const t=ee(e);return await G.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},be=async e=>{const t=await he(e);if(t)return t.type};let V;const te=async e=>{if(V)return V;const t=await be(e);return t==="module"?V="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:Z&&Z.tagName.toUpperCase()==="SCRIPT"&&Z.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(V="cjs"),V||"esm"},q=J.createLogger({level:"debug",format:J.format.combine(J.format.colorize(),J.format.cli()),transports:[new J.transports.Console({})]});function se(e){return e?typeof e!="string"?se(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 je={"*, *::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"},button:{lineHeight:"1em"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},H={externalModules:[]},ne=e=>{if(H.externalModules.length>0)return H.externalModules;const t=c.join(e,"salty.config.ts"),n=u.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const i=n[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return H.externalModules=i,i},W=e=>c.join(e,"./saltygen"),Se=["salty","css","styles","styled"],$e=(e=[])=>new RegExp(`\\.(${[...Se,...e].join("|")})\\.`),z=(e,t=[])=>$e(t).test(e),we=async e=>{const t=W(e),s=c.join(e,"salty.config.ts"),n=c.join(t,"salty.config.js"),i=await te(e),r=ne(e);await X.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:i,external:r});const y=Date.now(),{config:f}=await import(`${n}?t=${y}`);return f},Fe=async e=>{const t=await we(e),s=new Set,n=(p,g=[])=>p?Object.entries(p).flatMap(([w,S])=>{if(!S)return;if(typeof S=="object")return n(S,[...g,w]);const A=se(w),R=D(w),E=[...g,A].join(".");s.add(`"${E}"`);const N=[...g.map(D),R].join("-"),{result:_}=Y(S);return`--${N}: ${_};`}):[],i=p=>p?Object.entries(p).flatMap(([g,w])=>{const S=n(w);return g==="base"?S.join(""):`${g} { ${S.join("")} }`}):[],r=p=>p?Object.entries(p).flatMap(([g,w])=>Object.entries(w).flatMap(([S,A])=>{const R=n(A,[g]),E=`.${g}-${S}, [data-${g}="${S}"]`,N=R.join("");return`${E} { ${N} }`})):[],y=n(t.variables),f=i(t.responsiveVariables),h=r(t.conditionalVariables),o=W(e),a=c.join(o,"css/_variables.css"),F=`:root { ${y.join("")} ${f.join("")} } ${h.join("")}`;u.writeFileSync(a,F);const x=c.join(o,"css/_global.css"),b=O(t.global,"");u.writeFileSync(x,`@layer global { ${b} }`);const k=c.join(o,"css/_reset.css"),j=t.reset==="none"?{}:typeof t.reset=="object"?t.reset:je,m=O(j,"");u.writeFileSync(k,`@layer reset { ${m} }`);const l=c.join(o,"css/_templates.css"),d=Q(t.templates),$=me(t.templates);u.writeFileSync(l,d);const C=c.join(o,"types/css-tokens.d.ts"),T=`
|
9
9
|
// Variable types
|
10
10
|
type VariableTokens = ${[...s].join("|")};
|
11
11
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
12
12
|
|
13
13
|
// Template types
|
14
14
|
type TemplateTokens = {
|
15
|
-
${Object.entries(
|
15
|
+
${Object.entries($).map(([p,g])=>`${p}?: ${g}`).join(`
|
16
16
|
`)}
|
17
17
|
}
|
18
|
-
`;
|
19
|
-
`)
|
20
|
-
`);let
|
18
|
+
`;u.writeFileSync(C,T)},B=async(e,t,s)=>{const n=I(t),i=c.join(s,"./temp");u.existsSync(i)||u.mkdirSync(i);const r=c.parse(t);let y=u.readFileSync(t,"utf8");y=y.replace(/styled\([^"'`{,]+,/g,"styled('div',");const f=c.join(s,"js",n+".js"),h=ne(e),o=await te(e);await X.build({stdin:{contents:y,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:f,format:o,target:["node20"],keepNames:!0,external:h,packages:"external"});const a=Date.now();return await import(`${f}?t=${a}`)},K=async e=>{const t=W(e),s=c.join(t,"salty.config.js"),n=Date.now(),{config:i}=await import(`${s}?t=${n}`);return i},oe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},xe=async(e,t=oe())=>{try{const s=Date.now();t?q.info("Generating CSS in production mode! 🔥"):q.info("Generating CSS in development mode! 🚀");const n=[],i=[],r=W(e),y=c.join(r,"index.css");(()=>{u.existsSync(r)&&ue.execSync("rm -rf "+r),u.mkdirSync(r),u.mkdirSync(c.join(r,"css")),u.mkdirSync(c.join(r,"types"))})(),await Fe(e);const h=await K(e);async function o(l,d){const $=["node_modules","saltygen"],C=u.statSync(l);if(C.isDirectory()){const P=u.readdirSync(l);if($.some(p=>l.includes(p)))return;await Promise.all(P.map(p=>o(c.join(l,p),c.join(d,p))))}else if(C.isFile()&&z(l)){const T=await B(e,l,r),p=[];Object.entries(T).forEach(([E,N])=>{if(N.isKeyframes&&N.css){const L=`a_${N.animationName}.css`,ae=`css/${L}`,le=c.join(r,ae);n.push(L),u.writeFileSync(le,N.css);return}if(!N.generator)return;const _=N.generator._withBuildContext({name:E,config:h,prod:t});i[_.priority]||(i[_.priority]=[]),i[_.priority].push(_.cssFileName),p.push(_.cssFileName);const ie=`css/${_.cssFileName}`,ce=c.join(r,ie);u.writeFileSync(ce,_.css)});const g=p.map(E=>`@import url('./${E}');`).join(`
|
19
|
+
`),w=I(l,6),S=c.parse(l),A=D(S.name),R=c.join(r,`css/f_${A}-${w}.css`);u.writeFileSync(R,g)}}await o(e,r);const a=n.map(l=>`@import url('./css/${l}');`).join(`
|
20
|
+
`);let k=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
21
21
|
|
22
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(
|
22
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return u.readFileSync(c.join(r,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
23
23
|
`)}
|
24
|
-
${a}`;if(
|
25
|
-
`);
|
26
|
-
`),o=s.map(
|
27
|
-
`);
|
28
|
-
${o}`}return o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}},
|
24
|
+
${a}`;if(h.importStrategy!=="component"){const l=i.flat().map(d=>`@import url('./css/${d}');`).join(`
|
25
|
+
`);k+=l}u.writeFileSync(y,k);const j=Date.now()-s,m=j<200?"🔥":j<500?"🚀":j<1e3?"🎉":j<2e3?"🚗":j<5e3?"🤔":"🥴";q.info(`Generated CSS in ${j}ms! ${m}`)}catch(s){console.error(s)}},ke=async(e,t)=>{try{const s=[],n=c.join(e,"./saltygen"),i=c.join(n,"index.css");if(z(t)){const y=await K(e),f=await B(e,t,n);Object.entries(f).forEach(([x,b])=>{if(b.isKeyframes&&b.css){const l=`css/${`a_${b.animationName}.css`}`,d=c.join(n,l);u.writeFileSync(d,b.css);return}if(!b.generator)return;const k=b.generator._withBuildContext({name:x,config:y}),M=`css/${k.cssFileName}`,j=c.join(n,M);s.push(k.cssFileName),u.writeFileSync(j,k.css)});const h=u.readFileSync(i,"utf8").split(`
|
26
|
+
`),o=s.map(x=>`@import url('../saltygen/css/${x}');`),F=[...new Set([...h,...o])].join(`
|
27
|
+
`);u.writeFileSync(i,F)}}catch(s){console.error(s)}},Ce=async(e,t,s=oe())=>{try{const n=c.join(e,"./saltygen");if(z(t)){const r=u.readFileSync(t,"utf8");r.replace(/^(?!export\s)const\s.*/gm,a=>`export ${a}`)!==r&&await G.writeFile(t,r);const f=await K(e),h=await B(e,t,n);let o=r;if(Object.entries(h).forEach(([a,F])=>{var w;if(F.isKeyframes||!F.generator)return;const x=F.generator._withBuildContext({name:a,config:f,prod:s}),b=new RegExp(`\\s${a}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!b)return console.error("Could not find the original declaration");const k=(w=b.at(1))==null?void 0:w.trim(),M=new RegExp(`\\s${a}[=\\s]+styled\\(`,"g").exec(o);if(!M)return console.error("Could not find the original declaration");const{index:j}=M;let m=!1;const l=setTimeout(()=>m=!0,5e3);let d=0,$=!1,C=0;for(;!$&&!m;){const S=o[j+d];S==="("&&C++,S===")"&&C--,C===0&&S===")"&&($=!0),d>o.length&&(m=!0),d++}if(!m)clearTimeout(l);else throw new Error("Failed to find the end of the styled call and timed out");const P=j+d,T=o.slice(j,P),p=o,g=` ${a} = styled(${k}, "${x.classNames}", ${JSON.stringify(x.props)});`;o=o.replace(T,g),p===o&&console.error("Minimize file failed to change content",{name:a,tagName:k})}),f.importStrategy==="component"){const a=I(t,6),F=c.parse(t);o=`import '../../saltygen/css/${`f_${D(F.name)}-${a}.css`}';
|
28
|
+
${o}`}return o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}},re=e=>({name:"stylegen",buildStart:()=>xe(e),load:async t=>{if(z(t))return await Ce(e,t)},handleHotUpdate:async({file:t,server:s})=>{t.includes("salty.config")&&await s.restart()},watchChange:{handler:async t=>{z(t)&&await ke(e,t)}}});exports.default=re;exports.saltyPlugin=re;
|
package/index.d.ts
CHANGED
@@ -1,9 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
buildStart: () => Promise<void>;
|
4
|
-
load: (filePath: string) => Promise<string | undefined>;
|
5
|
-
watchChange: {
|
6
|
-
handler: (filePath: string) => Promise<void>;
|
7
|
-
};
|
8
|
-
};
|
1
|
+
import { PluginOption } from 'vite';
|
2
|
+
export declare const saltyPlugin: (dir: string) => PluginOption;
|
9
3
|
export default saltyPlugin;
|
package/index.js
CHANGED
@@ -1,134 +1,134 @@
|
|
1
1
|
import * as Q from "esbuild";
|
2
|
-
import { execSync as
|
3
|
-
import { join as
|
4
|
-
import { existsSync as
|
5
|
-
import { readFile as
|
6
|
-
import { createLogger as
|
2
|
+
import { execSync as pt } from "child_process";
|
3
|
+
import { join as l, parse as K } from "path";
|
4
|
+
import { existsSync as G, mkdirSync as R, statSync as ut, readdirSync as dt, writeFileSync as k, readFileSync as z } from "fs";
|
5
|
+
import { readFile as gt, writeFile as yt } from "fs/promises";
|
6
|
+
import { createLogger as mt, format as H, transports as ht } from "winston";
|
7
7
|
const Y = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), $t = (t, e) => {
|
8
|
-
let s = "",
|
9
|
-
for (
|
10
|
-
return s = Y(
|
11
|
-
},
|
8
|
+
let s = "", n;
|
9
|
+
for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = Y(n % 52) + s;
|
10
|
+
return s = Y(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
+
}, bt = (t, e) => {
|
12
12
|
let s = e.length;
|
13
13
|
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
14
14
|
return t;
|
15
15
|
}, L = (t, e = 5) => {
|
16
|
-
const s =
|
16
|
+
const s = bt(5381, JSON.stringify(t)) >>> 0;
|
17
17
|
return $t(s, e);
|
18
18
|
};
|
19
19
|
function O(t) {
|
20
20
|
return t ? typeof t != "string" ? O(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 St = (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: i, transform: r } =
|
28
|
-
t = t.replace(i, (
|
29
|
-
const { value:
|
30
|
-
return
|
26
|
+
return Object.values(e).forEach((n) => {
|
27
|
+
const { pattern: i, transform: r } = n;
|
28
|
+
t = t.replace(i, (d) => {
|
29
|
+
const { value: f, css: m } = r(d);
|
30
|
+
return m && s.push(m), f;
|
31
31
|
});
|
32
32
|
}), { result: t, additionalCss: s };
|
33
|
-
}, v = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...
|
33
|
+
}, v = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${O(n[1].replaceAll(".", "-"))})`) } : { result: t }, E = (t, e, s, n) => {
|
34
34
|
if (!t) return "";
|
35
|
-
const i = [], r = Object.entries(t).reduce((
|
36
|
-
const c =
|
37
|
-
if (typeof
|
38
|
-
if (!
|
35
|
+
const i = [], r = Object.entries(t).reduce((f, [m, o]) => {
|
36
|
+
const c = m.trim();
|
37
|
+
if (typeof o == "function" && (o = o()), typeof o == "object") {
|
38
|
+
if (!o) return f;
|
39
39
|
if (c === "variants")
|
40
|
-
return Object.entries(
|
41
|
-
|
42
|
-
if (!
|
43
|
-
const
|
40
|
+
return Object.entries(o).forEach(([u, S]) => {
|
41
|
+
S && Object.entries(S).forEach(([C, N]) => {
|
42
|
+
if (!N) return;
|
43
|
+
const P = `${e}.${u}-${C}`, p = E(N, P);
|
44
44
|
i.push(p);
|
45
45
|
});
|
46
|
-
}),
|
46
|
+
}), f;
|
47
47
|
if (c === "defaultVariants")
|
48
|
-
return
|
48
|
+
return f;
|
49
49
|
if (c === "compoundVariants")
|
50
|
-
return
|
51
|
-
const { css:
|
52
|
-
i.push(
|
53
|
-
}),
|
50
|
+
return o.forEach((u) => {
|
51
|
+
const { css: S, ...C } = u, N = Object.entries(C).reduce((p, [g, w]) => `${p}.${g}-${w}`, e), P = E(S, N);
|
52
|
+
i.push(P);
|
53
|
+
}), f;
|
54
54
|
if (c.startsWith("@")) {
|
55
|
-
const
|
56
|
-
${
|
55
|
+
const u = E(o, e), S = `${c} {
|
56
|
+
${u.replace(`
|
57
57
|
`, `
|
58
58
|
`)}
|
59
59
|
}`;
|
60
|
-
return i.push(
|
60
|
+
return i.push(S), f;
|
61
61
|
}
|
62
|
-
const
|
63
|
-
return i.push(
|
62
|
+
const y = m.includes("&") ? c.replace("&", e) : c.startsWith(":") ? `${e}${c}` : `${e} ${c}`, a = E(o, y);
|
63
|
+
return i.push(a), f;
|
64
64
|
}
|
65
|
-
const j = c.startsWith("-") ? c : O(c),
|
66
|
-
if (typeof
|
67
|
-
if (typeof
|
68
|
-
if ("toString" in
|
69
|
-
else return
|
70
|
-
const { modifiers:
|
71
|
-
yield v(
|
65
|
+
const j = c.startsWith("-") ? c : O(c), F = (y, a = ";") => f = `${f}${y}${a}`, h = (y) => F(`${j}:${y}`);
|
66
|
+
if (typeof o == "number") return h(o);
|
67
|
+
if (typeof o != "string")
|
68
|
+
if ("toString" in o) o = o.toString();
|
69
|
+
else return f;
|
70
|
+
const { modifiers: x } = {}, $ = function* () {
|
71
|
+
yield v(o), yield St(o, x);
|
72
72
|
}();
|
73
|
-
for (const { result:
|
74
|
-
|
75
|
-
const
|
76
|
-
|
73
|
+
for (const { result: y, additionalCss: a = [] } of $)
|
74
|
+
o = y, a.forEach((u) => {
|
75
|
+
const S = E(u, "");
|
76
|
+
F(S, "");
|
77
77
|
});
|
78
|
-
return
|
78
|
+
return h(o);
|
79
79
|
}, "");
|
80
80
|
if (!r) return i.join(`
|
81
81
|
`);
|
82
82
|
if (!e) return r;
|
83
|
-
let
|
84
|
-
return
|
83
|
+
let d = "";
|
84
|
+
return d = `${e} { ${r} }`, [d, ...i].join(`
|
85
85
|
`);
|
86
86
|
}, tt = (t, e = []) => {
|
87
87
|
if (!t) return "";
|
88
|
-
const s = [],
|
88
|
+
const s = [], n = {};
|
89
89
|
if (Object.entries(t).forEach(([i, r]) => {
|
90
90
|
if (typeof r == "object") {
|
91
91
|
if (!r) return;
|
92
|
-
const
|
93
|
-
s.push(
|
92
|
+
const d = i.trim(), f = tt(r, [...e, d]);
|
93
|
+
s.push(f);
|
94
94
|
} else
|
95
|
-
|
96
|
-
}), Object.keys(
|
97
|
-
const i = e.map(O).join("-"), r = E(
|
95
|
+
n[i] = r;
|
96
|
+
}), Object.keys(n).length) {
|
97
|
+
const i = e.map(O).join("-"), r = E(n, `.${i}`);
|
98
98
|
s.push(r);
|
99
99
|
}
|
100
100
|
return s.join(`
|
101
101
|
`);
|
102
|
-
}, wt = (t) => Object.entries(t).reduce((e, [s,
|
103
|
-
const r = e ? `${e}.${
|
102
|
+
}, wt = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = et(n).map((i) => `"${i}"`).join(" | ")), e), {}), et = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, i]) => {
|
103
|
+
const r = e ? `${e}.${n}` : n;
|
104
104
|
return typeof i == "object" ? et(i, r, s) : s.add(e);
|
105
105
|
}), [...s]) : [], st = (t) => {
|
106
106
|
if (!t || t === "/") throw new Error("Could not find package.json file");
|
107
|
-
const e =
|
108
|
-
return
|
109
|
-
},
|
107
|
+
const e = l(t, "package.json");
|
108
|
+
return G(e) ? e : st(l(t, ".."));
|
109
|
+
}, jt = async (t) => {
|
110
110
|
const e = st(t);
|
111
|
-
return await
|
111
|
+
return await gt(e, "utf-8").then(JSON.parse).catch(() => {
|
112
112
|
});
|
113
|
-
},
|
114
|
-
const e = await
|
113
|
+
}, Ft = async (t) => {
|
114
|
+
const e = await jt(t);
|
115
115
|
if (e)
|
116
116
|
return e.type;
|
117
117
|
};
|
118
118
|
let _;
|
119
119
|
const nt = async (t) => {
|
120
120
|
if (_) return _;
|
121
|
-
const e = await
|
121
|
+
const e = await Ft(t);
|
122
122
|
return e === "module" ? _ = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (_ = "cjs"), _ || "esm";
|
123
|
-
}, B =
|
123
|
+
}, B = mt({
|
124
124
|
level: "debug",
|
125
125
|
format: H.combine(H.colorize(), H.cli()),
|
126
|
-
transports: [new
|
126
|
+
transports: [new ht.Console({})]
|
127
127
|
});
|
128
128
|
function ot(t) {
|
129
129
|
return t ? typeof t != "string" ? ot(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
|
130
130
|
}
|
131
|
-
const
|
131
|
+
const xt = {
|
132
132
|
/** Set box model to border-box */
|
133
133
|
"*, *::before, *::after": {
|
134
134
|
boxSizing: "border-box"
|
@@ -173,67 +173,67 @@ const Ct = {
|
|
173
173
|
externalModules: []
|
174
174
|
}, rt = (t) => {
|
175
175
|
if (I.externalModules.length > 0) return I.externalModules;
|
176
|
-
const e =
|
177
|
-
if (!
|
178
|
-
const i =
|
176
|
+
const e = l(t, "salty.config.ts"), n = z(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
177
|
+
if (!n) return [];
|
178
|
+
const i = n[1].split(",").map((r) => r.replace(/['"`]/g, "").trim());
|
179
179
|
return I.externalModules = i, i;
|
180
|
-
}, Z = (t) =>
|
181
|
-
const e = Z(t), s =
|
180
|
+
}, Z = (t) => l(t, "./saltygen"), Ct = ["salty", "css", "styles", "styled"], kt = (t = []) => new RegExp(`\\.(${[...Ct, ...t].join("|")})\\.`), W = (t, e = []) => kt(e).test(t), Nt = async (t) => {
|
181
|
+
const e = Z(t), s = l(t, "salty.config.ts"), n = l(e, "salty.config.js"), i = await nt(t), r = rt(t);
|
182
182
|
await Q.build({
|
183
183
|
entryPoints: [s],
|
184
184
|
minify: !0,
|
185
185
|
treeShaking: !0,
|
186
186
|
bundle: !0,
|
187
|
-
outfile:
|
187
|
+
outfile: n,
|
188
188
|
format: i,
|
189
189
|
external: r
|
190
190
|
});
|
191
|
-
const
|
192
|
-
return
|
193
|
-
},
|
194
|
-
const e = await Nt(t), s = /* @__PURE__ */ new Set(),
|
191
|
+
const d = Date.now(), { config: f } = await import(`${n}?t=${d}`);
|
192
|
+
return f;
|
193
|
+
}, Pt = async (t) => {
|
194
|
+
const e = await Nt(t), s = /* @__PURE__ */ new Set(), n = (p, g = []) => p ? Object.entries(p).flatMap(([w, b]) => {
|
195
195
|
if (!b) return;
|
196
|
-
if (typeof b == "object") return
|
197
|
-
const A = ot(
|
196
|
+
if (typeof b == "object") return n(b, [...g, w]);
|
197
|
+
const A = ot(w), J = O(w), M = [...g, A].join(".");
|
198
198
|
s.add(`"${M}"`);
|
199
|
-
const
|
200
|
-
return `--${
|
201
|
-
}) : [], i = (p) => p ? Object.entries(p).flatMap(([g,
|
202
|
-
const b =
|
199
|
+
const T = [...g.map(O), J].join("-"), { result: D } = v(b);
|
200
|
+
return `--${T}: ${D};`;
|
201
|
+
}) : [], i = (p) => p ? Object.entries(p).flatMap(([g, w]) => {
|
202
|
+
const b = n(w);
|
203
203
|
return g === "base" ? b.join("") : `${g} { ${b.join("")} }`;
|
204
|
-
}) : [], r = (p) => p ? Object.entries(p).flatMap(([g,
|
205
|
-
const J =
|
206
|
-
return `${M} { ${
|
207
|
-
})) : [],
|
204
|
+
}) : [], r = (p) => p ? Object.entries(p).flatMap(([g, w]) => Object.entries(w).flatMap(([b, A]) => {
|
205
|
+
const J = n(A, [g]), M = `.${g}-${b}, [data-${g}="${b}"]`, T = J.join("");
|
206
|
+
return `${M} { ${T} }`;
|
207
|
+
})) : [], d = n(e.variables), f = i(e.responsiveVariables), m = r(e.conditionalVariables), o = Z(t), c = l(o, "css/_variables.css"), j = `:root { ${d.join("")} ${f.join("")} } ${m.join("")}`;
|
208
208
|
k(c, j);
|
209
|
-
const
|
210
|
-
k(
|
211
|
-
const
|
212
|
-
k(
|
213
|
-
const
|
214
|
-
k(
|
215
|
-
const C =
|
209
|
+
const F = l(o, "css/_global.css"), h = E(e.global, "");
|
210
|
+
k(F, `@layer global { ${h} }`);
|
211
|
+
const x = l(o, "css/_reset.css"), $ = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : xt, y = E($, "");
|
212
|
+
k(x, `@layer reset { ${y} }`);
|
213
|
+
const a = l(o, "css/_templates.css"), u = tt(e.templates), S = wt(e.templates);
|
214
|
+
k(a, u);
|
215
|
+
const C = l(o, "types/css-tokens.d.ts"), P = `
|
216
216
|
// Variable types
|
217
217
|
type VariableTokens = ${[...s].join("|")};
|
218
218
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
219
219
|
|
220
220
|
// Template types
|
221
221
|
type TemplateTokens = {
|
222
|
-
${Object.entries(
|
222
|
+
${Object.entries(S).map(([p, g]) => `${p}?: ${g}`).join(`
|
223
223
|
`)}
|
224
224
|
}
|
225
225
|
`;
|
226
|
-
k(C,
|
226
|
+
k(C, P);
|
227
227
|
}, q = async (t, e, s) => {
|
228
|
-
const
|
229
|
-
|
230
|
-
const r =
|
231
|
-
let
|
232
|
-
|
233
|
-
const
|
228
|
+
const n = L(e), i = l(s, "./temp");
|
229
|
+
G(i) || R(i);
|
230
|
+
const r = K(e);
|
231
|
+
let d = z(e, "utf8");
|
232
|
+
d = d.replace(/styled\([^"'`{,]+,/g, "styled('div',");
|
233
|
+
const f = l(s, "js", n + ".js"), m = rt(t), o = await nt(t);
|
234
234
|
await Q.build({
|
235
235
|
stdin: {
|
236
|
-
contents:
|
236
|
+
contents: d,
|
237
237
|
sourcefile: r.base,
|
238
238
|
resolveDir: r.dir,
|
239
239
|
loader: "tsx"
|
@@ -241,159 +241,167 @@ const Ct = {
|
|
241
241
|
minify: !1,
|
242
242
|
treeShaking: !0,
|
243
243
|
bundle: !0,
|
244
|
-
outfile:
|
245
|
-
format:
|
244
|
+
outfile: f,
|
245
|
+
format: o,
|
246
246
|
target: ["node20"],
|
247
247
|
keepNames: !0,
|
248
|
-
external:
|
248
|
+
external: m,
|
249
249
|
packages: "external"
|
250
250
|
});
|
251
251
|
const c = Date.now();
|
252
|
-
return await import(`${
|
252
|
+
return await import(`${f}?t=${c}`);
|
253
253
|
}, U = async (t) => {
|
254
|
-
const e = Z(t), s =
|
255
|
-
return
|
256
|
-
},
|
254
|
+
const e = Z(t), s = l(e, "salty.config.js"), n = Date.now(), { config: i } = await import(`${s}?t=${n}`);
|
255
|
+
return i;
|
256
|
+
}, it = () => {
|
257
257
|
try {
|
258
258
|
return process.env.NODE_ENV === "production";
|
259
259
|
} catch {
|
260
260
|
return !1;
|
261
261
|
}
|
262
|
-
},
|
262
|
+
}, Tt = async (t, e = it()) => {
|
263
263
|
try {
|
264
264
|
const s = Date.now();
|
265
265
|
e ? B.info("Generating CSS in production mode! 🔥") : B.info("Generating CSS in development mode! 🚀");
|
266
|
-
const
|
266
|
+
const n = [], i = [], r = Z(t), d = l(r, "index.css");
|
267
267
|
(() => {
|
268
|
-
|
269
|
-
})(), await
|
270
|
-
const
|
271
|
-
async function
|
272
|
-
const
|
268
|
+
G(r) && pt("rm -rf " + r), R(r), R(l(r, "css")), R(l(r, "types"));
|
269
|
+
})(), await Pt(t);
|
270
|
+
const m = await U(t);
|
271
|
+
async function o(a, u) {
|
272
|
+
const S = ["node_modules", "saltygen"], C = ut(a);
|
273
273
|
if (C.isDirectory()) {
|
274
|
-
const
|
275
|
-
if (
|
276
|
-
await Promise.all(
|
277
|
-
} else if (C.isFile() && W(
|
278
|
-
const
|
279
|
-
Object.entries(
|
280
|
-
if (
|
281
|
-
const X = `a_${
|
282
|
-
|
274
|
+
const N = dt(a);
|
275
|
+
if (S.some((p) => a.includes(p))) return;
|
276
|
+
await Promise.all(N.map((p) => o(l(a, p), l(u, p))));
|
277
|
+
} else if (C.isFile() && W(a)) {
|
278
|
+
const P = await q(t, a, r), p = [];
|
279
|
+
Object.entries(P).forEach(([M, T]) => {
|
280
|
+
if (T.isKeyframes && T.css) {
|
281
|
+
const X = `a_${T.animationName}.css`, lt = `css/${X}`, ft = l(r, lt);
|
282
|
+
n.push(X), k(ft, T.css);
|
283
283
|
return;
|
284
284
|
}
|
285
|
-
if (!
|
286
|
-
const D =
|
285
|
+
if (!T.generator) return;
|
286
|
+
const D = T.generator._withBuildContext({
|
287
287
|
name: M,
|
288
|
-
config:
|
288
|
+
config: m,
|
289
289
|
prod: e
|
290
290
|
});
|
291
291
|
i[D.priority] || (i[D.priority] = []), i[D.priority].push(D.cssFileName), p.push(D.cssFileName);
|
292
|
-
const
|
293
|
-
k(
|
292
|
+
const ct = `css/${D.cssFileName}`, at = l(r, ct);
|
293
|
+
k(at, D.css);
|
294
294
|
});
|
295
295
|
const g = p.map((M) => `@import url('./${M}');`).join(`
|
296
|
-
`),
|
296
|
+
`), w = L(a, 6), b = K(a), A = O(b.name), J = l(r, `css/f_${A}-${w}.css`);
|
297
297
|
k(J, g);
|
298
298
|
}
|
299
299
|
}
|
300
|
-
await
|
301
|
-
const c =
|
300
|
+
await o(t, r);
|
301
|
+
const c = n.map((a) => `@import url('./css/${a}');`).join(`
|
302
302
|
`);
|
303
|
-
let
|
303
|
+
let x = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
304
304
|
|
305
|
-
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((
|
305
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((a) => {
|
306
306
|
try {
|
307
|
-
return z(
|
307
|
+
return z(l(r, "css", a), "utf8").length > 0;
|
308
308
|
} catch {
|
309
309
|
return !1;
|
310
310
|
}
|
311
|
-
}).map((
|
311
|
+
}).map((a) => `@import url('./css/${a}');`).join(`
|
312
312
|
`)}
|
313
313
|
${c}`;
|
314
|
-
if (
|
315
|
-
const
|
314
|
+
if (m.importStrategy !== "component") {
|
315
|
+
const a = i.flat().map((u) => `@import url('./css/${u}');`).join(`
|
316
316
|
`);
|
317
|
-
|
317
|
+
x += a;
|
318
318
|
}
|
319
|
-
k(
|
320
|
-
const
|
321
|
-
B.info(`Generated CSS in ${
|
319
|
+
k(d, x);
|
320
|
+
const $ = Date.now() - s, y = $ < 200 ? "🔥" : $ < 500 ? "🚀" : $ < 1e3 ? "🎉" : $ < 2e3 ? "🚗" : $ < 5e3 ? "🤔" : "🥴";
|
321
|
+
B.info(`Generated CSS in ${$}ms! ${y}`);
|
322
322
|
} catch (s) {
|
323
323
|
console.error(s);
|
324
324
|
}
|
325
325
|
}, Dt = async (t, e) => {
|
326
326
|
try {
|
327
|
-
const s = [],
|
327
|
+
const s = [], n = l(t, "./saltygen"), i = l(n, "index.css");
|
328
328
|
if (W(e)) {
|
329
|
-
const
|
330
|
-
Object.entries(
|
331
|
-
if (
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
}
|
336
|
-
|
329
|
+
const d = await U(t), f = await q(t, e, n);
|
330
|
+
Object.entries(f).forEach(([F, h]) => {
|
331
|
+
if (h.isKeyframes && h.css) {
|
332
|
+
const a = `css/${`a_${h.animationName}.css`}`, u = l(n, a);
|
333
|
+
k(u, h.css);
|
334
|
+
return;
|
335
|
+
}
|
336
|
+
if (!h.generator) return;
|
337
|
+
const x = h.generator._withBuildContext({
|
338
|
+
name: F,
|
339
|
+
config: d
|
340
|
+
}), V = `css/${x.cssFileName}`, $ = l(n, V);
|
341
|
+
s.push(x.cssFileName), k($, x.css);
|
337
342
|
});
|
338
|
-
const
|
339
|
-
`),
|
343
|
+
const m = z(i, "utf8").split(`
|
344
|
+
`), o = s.map((F) => `@import url('../saltygen/css/${F}');`), j = [.../* @__PURE__ */ new Set([...m, ...o])].join(`
|
340
345
|
`);
|
341
346
|
k(i, j);
|
342
347
|
}
|
343
348
|
} catch (s) {
|
344
349
|
console.error(s);
|
345
350
|
}
|
346
|
-
}, Et = async (t, e, s =
|
351
|
+
}, Et = async (t, e, s = it()) => {
|
347
352
|
try {
|
348
|
-
const
|
353
|
+
const n = l(t, "./saltygen");
|
349
354
|
if (W(e)) {
|
350
355
|
const r = z(e, "utf8");
|
351
|
-
r.replace(/^(?!export\s)const\s.*/gm, (c) => `export ${c}`) !== r && await
|
352
|
-
const
|
353
|
-
let
|
354
|
-
if (Object.entries(
|
355
|
-
var
|
356
|
+
r.replace(/^(?!export\s)const\s.*/gm, (c) => `export ${c}`) !== r && await yt(e, r);
|
357
|
+
const f = await U(t), m = await q(t, e, n);
|
358
|
+
let o = r;
|
359
|
+
if (Object.entries(m).forEach(([c, j]) => {
|
360
|
+
var w;
|
356
361
|
if (j.isKeyframes || !j.generator) return;
|
357
|
-
const
|
362
|
+
const F = j.generator._withBuildContext({
|
358
363
|
name: c,
|
359
|
-
config:
|
364
|
+
config: f,
|
360
365
|
prod: s
|
361
|
-
}),
|
362
|
-
if (!
|
363
|
-
const
|
366
|
+
}), h = new RegExp(`\\s${c}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
367
|
+
if (!h) return console.error("Could not find the original declaration");
|
368
|
+
const x = (w = h.at(1)) == null ? void 0 : w.trim(), V = new RegExp(`\\s${c}[=\\s]+styled\\(`, "g").exec(o);
|
364
369
|
if (!V) return console.error("Could not find the original declaration");
|
365
|
-
const { index:
|
366
|
-
let
|
367
|
-
const
|
368
|
-
let
|
369
|
-
for (;
|
370
|
-
const b =
|
371
|
-
b === "(" && C++, b === ")" && C--, C === 0 && b === ")" && (
|
370
|
+
const { index: $ } = V;
|
371
|
+
let y = !1;
|
372
|
+
const a = setTimeout(() => y = !0, 5e3);
|
373
|
+
let u = 0, S = !1, C = 0;
|
374
|
+
for (; !S && !y; ) {
|
375
|
+
const b = o[$ + u];
|
376
|
+
b === "(" && C++, b === ")" && C--, C === 0 && b === ")" && (S = !0), u > o.length && (y = !0), u++;
|
372
377
|
}
|
373
|
-
if (!
|
378
|
+
if (!y) clearTimeout(a);
|
374
379
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
375
|
-
const
|
376
|
-
|
377
|
-
}),
|
378
|
-
const c = L(e, 6), j =
|
379
|
-
|
380
|
-
${
|
380
|
+
const N = $ + u, P = o.slice($, N), p = o, g = ` ${c} = styled(${x}, "${F.classNames}", ${JSON.stringify(F.props)});`;
|
381
|
+
o = o.replace(P, g), p === o && console.error("Minimize file failed to change content", { name: c, tagName: x });
|
382
|
+
}), f.importStrategy === "component") {
|
383
|
+
const c = L(e, 6), j = K(e);
|
384
|
+
o = `import '../../saltygen/css/${`f_${O(j.name)}-${c}.css`}';
|
385
|
+
${o}`;
|
381
386
|
}
|
382
|
-
return
|
387
|
+
return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
|
383
388
|
}
|
384
|
-
} catch (
|
385
|
-
console.error("Error in minimizeFile:",
|
389
|
+
} catch (n) {
|
390
|
+
console.error("Error in minimizeFile:", n);
|
386
391
|
}
|
387
392
|
}, Jt = (t) => ({
|
388
393
|
name: "stylegen",
|
389
|
-
buildStart: () =>
|
394
|
+
buildStart: () => Tt(t),
|
390
395
|
load: async (e) => {
|
391
396
|
if (W(e))
|
392
397
|
return await Et(t, e);
|
393
398
|
},
|
399
|
+
handleHotUpdate: async ({ file: e, server: s }) => {
|
400
|
+
e.includes("salty.config") && await s.restart();
|
401
|
+
},
|
394
402
|
watchChange: {
|
395
403
|
handler: async (e) => {
|
396
|
-
W(e) && await Dt(t, e)
|
404
|
+
W(e) && await Dt(t, e);
|
397
405
|
}
|
398
406
|
}
|
399
407
|
});
|
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.132",
|
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.132"
|
38
38
|
}
|
39
39
|
}
|