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