@salty-css/vite 0.0.1-alpha.180 → 0.0.1-alpha.181
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 +17 -17
- package/index.js +157 -156
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,36 +1,36 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const mt=require("esbuild"),St=require("child_process"),l=require("path"),u=require("fs"),G=require("fs/promises"),q=require("winston");var v=typeof document<"u"?document.currentScript:null;function bt(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 ot=bt(mt),et=t=>String.fromCharCode(t+(t>25?39:97)),jt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=et(n%52)+s;return s=et(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},$t=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},L=(t,e=5)=>{const s=$t(5381,JSON.stringify(t))>>>0;return jt(s,e)};function R(t){return t?typeof t!="string"?R(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 wt=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:i,transform:a}=n;t=t.replace(i,c=>{const{value:d,css:r}=a(c);return r&&s.push(r),d})}),{result:t,additionalCss:s}},rt=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${R(n[1].replaceAll(".","-"))})`)}:{result:t},M=(t,e,s)=>{if(!t)return"";const n=[],i=Object.entries(t).reduce((c,[d,r])=>{const o=d.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return c;if(o==="variants")return Object.entries(r).forEach(([P,S])=>{S&&Object.entries(S).forEach(([O,f])=>{if(!f)return;const $=`${e}.${P}-${O}`,b=M(f,$);n.push(b)})}),c;if(o==="defaultVariants")return c;if(o==="compoundVariants")return r.forEach(P=>{const{css:S,...O}=P,f=Object.entries(O).reduce((b,[w,h])=>`${b}.${w}-${h}`,e),$=M(S,f);n.push($)}),c;if(o.startsWith("@")){const P=M(r,e),S=`${o} {
|
2
2
|
${P.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return n.push(
|
6
|
-
`):
|
7
|
-
`)},
|
8
|
-
`)},
|
5
|
+
}`;return n.push(S),c}const j=d.includes("&")?o.replace("&",e):o.startsWith(":")?`${e}${o}`:`${e} ${o}`,F=M(r,j);return n.push(F),c}const g=o.startsWith("-")?o:R(o),p=(j,F=";")=>c=`${c}${j}${F}`,y=j=>p(`${g}:${j}`);if(typeof r=="number")return y(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return c;const{modifiers:x}={},T=function*(){yield rt(r),yield wt(r,x)}();for(const{result:j,additionalCss:F=[]}of T)r=j,F.forEach(P=>{const S=M(P,"");p(S,"")});return y(r)},"");return i?e?[`${e} { ${i} }`,...n].join(`
|
6
|
+
`):i:n.join(`
|
7
|
+
`)},it=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([i,a])=>{if(typeof a=="object"){if(!a)return;const c=i.trim(),d=it(a,[...e,c]);s.push(d)}else n[i]=a}),Object.keys(n).length){const i=e.map(R).join("-"),a=M(n,`.${i}`);s.push(a)}return s.join(`
|
8
|
+
`)},Ft=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=ct(n).map(i=>`"${i}"`).join(" | ")),e),{}):{},ct=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,i])=>{const a=e?`${e}.${n}`:n;return typeof i=="object"?ct(i,a,s):s.add(e)}),[...s]):[],at=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return u.existsSync(e)?e:at(l.join(t,".."))},Ct=async t=>{const e=at(t);return await G.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},kt=async t=>{const e=await Ct(t);if(e)return e.type};let W;const lt=async t=>{if(W)return W;const e=await kt(t);return e==="module"?W="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:v&&v.tagName.toUpperCase()==="SCRIPT"&&v.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(W="cjs"),W||"esm"},Q=q.createLogger({level:"debug",format:q.format.combine(q.format.colorize(),q.format.cli()),transports:[new q.transports.Console({})]});function ft(t){return t?typeof t!="string"?ft(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 xt={"*, *::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"}},z=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),V={externalModules:[],rcFile:void 0,destDir:void 0},ut=t=>{if(V.externalModules.length>0)return V.externalModules;const s=u.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return V.externalModules=n,n},J=async t=>{if(V.destDir)return V.destDir;const e=await X(t),s=l.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return V.destDir=s,s},dt=["salty","css","styles","styled"],Dt=(t=[])=>new RegExp(`\\.(${[...dt,...t].join("|")})\\.`),Z=(t,e=[])=>Dt(e).test(t),pt=async t=>{if(V.rcFile)return V.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=l.join(t,".saltyrc.json"),s=await G.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):pt(l.join(t,".."))},X=async t=>{var n,i;const e=await pt(t),s=(n=e.projects)==null?void 0:n.find(a=>t.endsWith(a.dir||""));return s||((i=e.projects)==null?void 0:i.find(a=>a.dir===e.defaultProject))},Nt=async t=>{const e=await X(t),s=await J(t),n=l.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),i=l.join(s,"salty.config.js"),a=await lt(t),c=ut(n);await ot.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:a,external:c});const d=Date.now(),{config:r}=await import(`${i}?t=${d}`);return r},Pt=async(t,e)=>{const s=await Nt(t),n={...s},i=new Set,a=(D,k=[])=>D?Object.entries(D).flatMap(([E,_])=>{if(!_)return;if(typeof _=="object")return a(_,[...k,E]);const A=ft(E),B=R(E),K=[...k,A].join(".");i.add(`"${K}"`);const U=[...k.map(R),B].join("-"),{result:ht}=rt(_);return`--${U}: ${ht};`}):[],c=D=>D?Object.entries(D).flatMap(([k,E])=>{const _=a(E);return k==="base"?_.join(""):`${k} { ${_.join("")} }`}):[],d=D=>D?Object.entries(D).flatMap(([k,E])=>Object.entries(E).flatMap(([_,A])=>{const B=a(A,[k]),K=`.${k}-${_}, [data-${k}="${_}"]`,U=B.join("");return`${K} { ${U} }`})):[],r=D=>e.variables.map(k=>k._current[D]),o=a(z(s.variables,r("variables"))),g=c(z(s.responsiveVariables,r("responsiveVariables"))),p=d(z(s.conditionalVariables,r("conditionalVariables"))),y=await J(t),x=l.join(y,"css/_variables.css"),N=`:root { ${o.join("")} ${g.join("")} } ${p.join("")}`;u.writeFileSync(x,N);const T=l.join(y,"css/_global.css"),j=z(s.global,e.globalStyles),F=M(j,"");u.writeFileSync(T,`@layer global { ${F} }`);const P=l.join(y,"css/_reset.css"),O=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:xt,f=M(O,"");u.writeFileSync(P,`@layer reset { ${f} }`);const $=l.join(y,"css/_templates.css"),b=z(s.templates,e.templates),w=it(b),h=Ft(b);u.writeFileSync($,w),n.templates=b;const C=l.join(y,"types/css-tokens.d.ts"),I=`
|
9
9
|
// Variable types
|
10
|
-
type VariableTokens = ${[...
|
10
|
+
type VariableTokens = ${[...i].join("|")};
|
11
11
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
12
12
|
|
13
13
|
// Template types
|
14
14
|
type TemplateTokens = {
|
15
|
-
${Object.entries(h).map(([
|
15
|
+
${Object.entries(h).map(([D,k])=>`${D}?: ${k}`).join(`
|
16
16
|
`)}
|
17
17
|
}
|
18
|
-
`;u.writeFileSync(C,
|
19
|
-
`),w=L(f,6),h=l.parse(f),C=R(h.name),m=l.join(
|
18
|
+
`;u.writeFileSync(C,I);const H=l.join(y,"cache/config-cache.json");u.writeFileSync(H,JSON.stringify(n,null,2))},st=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(t))return e;const c=i.exec(t);if(c){const d=c.at(1);if(dt.some(o=>d==null?void 0:d.includes(o)))return e}return"styled('div',"}),Y=async(t,e,s)=>{const n=L(e),i=l.join(s,"./temp");u.existsSync(i)||u.mkdirSync(i);const a=l.parse(e);let c=u.readFileSync(e,"utf8");c=st(c);const d=l.join(s,"js",n+".js"),r=await X(t),o=l.join(t,(r==null?void 0:r.configDir)||"","salty.config.ts"),g=ut(o),p=await lt(t);await ot.build({stdin:{contents:c,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:p,target:["node20"],keepNames:!0,external:g,packages:"external",plugins:[{name:"test",setup:N=>{N.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},T=>{const j=u.readFileSync(T.path,"utf8");return{contents:st(j),loader:"ts"}})}}]});const y=Date.now();return await import(`${d}?t=${y}`)},_t=async t=>{const e=await J(t),s=l.join(e,"cache/config-cache.json"),n=u.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},tt=async t=>{const e=await _t(t),s=await J(t),n=l.join(s,"salty.config.js"),i=Date.now(),{config:a}=await import(`${n}?t=${i}`);return z(a,e)},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Tt=async(t,e=yt(),s=!0)=>{try{const n=Date.now();e?Q.info("Generating CSS in production mode! 🔥"):Q.info("Generating CSS in development mode! 🚀");const i=[],a=[],c=await J(t),d=l.join(c,"index.css");s&&(()=>{u.existsSync(c)&&St.execSync("rm -rf "+c),u.mkdirSync(c,{recursive:!0}),u.mkdirSync(l.join(c,"css")),u.mkdirSync(l.join(c,"types")),u.mkdirSync(l.join(c,"js")),u.mkdirSync(l.join(c,"cache"))})();const o={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[],templates:[]};async function g(f){const $=["node_modules","saltygen"],b=u.statSync(f);if(b.isDirectory()){const w=u.readdirSync(f);if($.some(C=>f.includes(C)))return;await Promise.all(w.map(C=>g(l.join(f,C))))}else if(b.isFile()&&Z(f)){const h=await Y(t,f,c);Object.entries(h).forEach(([C,m])=>{m.isKeyframes?o.keyframes.push({value:m,src:f,name:C}):m.isMedia?o.mediaQueries.push(m):m.isGlobalDefine?o.globalStyles.push(m):m.isDefineVariables?o.variables.push(m):m.isDefineTemplates?o.templates.push(m):m.generator&&o.components.push({value:m.generator,src:f,name:C})})}}await g(t),await Pt(t,o);const p=await tt(t);for(const f of o.keyframes){const{value:$}=f,b=`a_${$.animationName}.css`,w=`css/${b}`,h=l.join(c,w);i.push(b),u.writeFileSync(h,$.css)}const y={};for(const f of o.components){const{value:$,name:b,src:w}=f,h=$._withBuildContext({name:b,config:p,prod:e});a[h.priority]||(a[h.priority]=[]),a[h.priority].push(h.cssFileName),p.importStrategy==="component"&&(y[w]?y[w].push(h.cssFileName):y[w]=[h.cssFileName]);const C=`css/${h.cssFileName}`,m=l.join(c,C);u.writeFileSync(m,h.css)}p.importStrategy==="component"&&Object.entries(y).forEach(([f,$])=>{const b=$.map(I=>`@import url('./${I}');`).join(`
|
19
|
+
`),w=L(f,6),h=l.parse(f),C=R(h.name),m=l.join(c,`css/f_${C}-${w}.css`);u.writeFileSync(m,b)});const x=i.map(f=>`@import url('./css/${f}');`).join(`
|
20
20
|
`);let F=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
21
21
|
|
22
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return u.readFileSync(l.join(
|
22
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return u.readFileSync(l.join(c,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
23
23
|
`)}
|
24
|
-
${x}`;if(p.importStrategy!=="component"){const f=a.reduce(($,
|
24
|
+
${x}`;if(p.importStrategy!=="component"){const f=a.reduce(($,b,w)=>{const h=b.reduce((H,D)=>{var A;const k=l.join(c,"css",D),E=u.readFileSync(k,"utf8"),_=((A=/.*-([^-]+)-\d+.css/.exec(D))==null?void 0:A.at(1))||L(k,6);return H.includes(_)?H:`${H}
|
25
25
|
/*start:${_}*/
|
26
26
|
${E}
|
27
27
|
/*end:${_}*/
|
28
|
-
`},""),C=`l_${w}.css`,m=l.join(
|
29
|
-
}`;return u.writeFileSync(m,
|
30
|
-
@import url('./css/${C}');`},"");F+=f}u.writeFileSync(d,F);const
|
28
|
+
`},""),C=`l_${w}.css`,m=l.join(c,"css",C),I=`@layer l${w} { ${h}
|
29
|
+
}`;return u.writeFileSync(m,I),`${$}
|
30
|
+
@import url('./css/${C}');`},"");F+=f}u.writeFileSync(d,F);const S=Date.now()-n,O=S<200?"🔥":S<500?"🚀":S<1e3?"🎉":S<2e3?"🚗":S<5e3?"🤔":"🥴";Q.info(`Generated CSS in ${S}ms! ${O}`)}catch(n){console.error(n)}},Ot=async(t,e)=>{try{const s=await J(t);if(Z(e)){const i=[],a=await tt(t),c=await Y(t,e,s);Object.entries(c).forEach(([d,r])=>{if(r.isKeyframes&&r.css){const x=`css/${`a_${r.animationName}.css`}`,N=l.join(s,x);u.writeFileSync(N,r.css);return}if(!r.generator)return;const o=r.generator._withBuildContext({name:d,config:a}),g=`css/${o.cssFileName}`,p=l.join(s,g);u.writeFileSync(p,o.css),i[o.priority]||(i[o.priority]=[]),i[o.priority].push(o.cssFileName)}),a.importStrategy!=="component"&&i.forEach((d,r)=>{const o=`l_${r}.css`,g=l.join(s,"css",o);let p=u.readFileSync(g,"utf8");d.forEach(y=>{var j;const x=l.join(s,"css",y),N=((j=/.*-([^-]+)-\d+.css/.exec(y))==null?void 0:j.at(1))||L(x,6);if(!p.includes(N)){const F=u.readFileSync(x,"utf8"),P=`/*start:${N}*/
|
31
31
|
${F}
|
32
|
-
/*end:${
|
32
|
+
/*end:${N}*/
|
33
33
|
`;p=`${p.replace(/\}$/,"")}
|
34
34
|
${P}
|
35
|
-
}`}}),u.writeFileSync(g,p)})}}catch(s){console.error(s)}},
|
36
|
-
${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)}},
|
35
|
+
}`}}),u.writeFileSync(g,p)})}}catch(s){console.error(s)}},Et=async(t,e,s=yt())=>{try{const n=await J(t);if(Z(e)){const a=u.readFileSync(e,"utf8");a.replace(/^(?!export\s)const\s.*/gm,g=>`export ${g}`)!==a&&await G.writeFile(e,a);const d=await tt(t),r=await Y(t,e,n);let o=a;if(Object.entries(r).forEach(([g,p])=>{var C;if(p.isKeyframes||!p.generator)return;const y=p.generator._withBuildContext({name:g,config:d,prod:s}),x=new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!x)return console.error("Could not find the original declaration");const N=(C=x.at(1))==null?void 0:C.trim(),T=new RegExp(`\\s${g}[=\\s]+styled\\(`,"g").exec(o);if(!T)return console.error("Could not find the original declaration");const{index:j}=T;let F=!1;const P=setTimeout(()=>F=!0,5e3);let S=0,O=!1,f=0;for(;!O&&!F;){const m=o[j+S];m==="("&&f++,m===")"&&f--,f===0&&m===")"&&(O=!0),S>o.length&&(F=!0),S++}if(!F)clearTimeout(P);else throw new Error("Failed to find the end of the styled call and timed out");const $=j+S,b=o.slice(j,$),w=o,h=` ${g} = styled(${N}, "${y.classNames}", ${JSON.stringify(y.props)});`;o=o.replace(b,h),w===o&&console.error("Minimize file failed to change content",{name:g,tagName:N})}),d.importStrategy==="component"){const g=L(e,6),p=l.parse(e);o=`import '../../saltygen/css/${`f_${R(p.name)}-${g}.css`}';
|
36
|
+
${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)}},nt=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!Z(t))return!1;const n=await G.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},gt=t=>({name:"stylegen",buildStart:()=>Tt(t),load:async e=>{if(Z(e))return await Et(t,e)},handleHotUpdate:async({file:e,server:s})=>{await nt(e)&&await s.restart()},watchChange:{handler:async e=>{Z(e)&&(await nt(e)||await Ot(t,e))}}});exports.default=gt;exports.saltyPlugin=gt;
|
package/index.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import * as ct from "esbuild";
|
2
2
|
import { execSync as bt } from "child_process";
|
3
3
|
import { join as f, parse as Y } from "path";
|
4
|
-
import { existsSync as v, mkdirSync as
|
4
|
+
import { existsSync as v, mkdirSync as z, statSync as wt, readdirSync as St, writeFileSync as P, readFileSync as M } from "fs";
|
5
5
|
import { readFile as tt, writeFile as jt } from "fs/promises";
|
6
6
|
import { createLogger as Ct, format as U, transports as Ft } from "winston";
|
7
7
|
const ot = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), xt = (t, e) => {
|
@@ -19,86 +19,86 @@ const ot = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), xt = (t, e) => {
|
|
19
19
|
function J(t) {
|
20
20
|
return t ? typeof t != "string" ? J(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 Dt = (t, e) => {
|
23
23
|
if (typeof t != "string") return { result: t };
|
24
24
|
if (!e) return { result: t };
|
25
25
|
const s = [];
|
26
26
|
return Object.values(e).forEach((n) => {
|
27
|
-
const { pattern:
|
28
|
-
t = t.replace(
|
29
|
-
const { value: u, css: r } = a(
|
27
|
+
const { pattern: i, transform: a } = n;
|
28
|
+
t = t.replace(i, (c) => {
|
29
|
+
const { value: u, css: r } = a(c);
|
30
30
|
return r && s.push(r), u;
|
31
31
|
});
|
32
32
|
}), { result: t, additionalCss: s };
|
33
33
|
}, at = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${J(n[1].replaceAll(".", "-"))})`) } : { result: t }, R = (t, e, s) => {
|
34
34
|
if (!t) return "";
|
35
|
-
const n = [],
|
35
|
+
const n = [], i = Object.entries(t).reduce((c, [u, r]) => {
|
36
36
|
const o = u.trim();
|
37
37
|
if (typeof r == "function" && (r = r()), typeof r == "object") {
|
38
|
-
if (!r) return
|
38
|
+
if (!r) return c;
|
39
39
|
if (o === "variants")
|
40
|
-
return Object.entries(r).forEach(([
|
41
|
-
|
40
|
+
return Object.entries(r).forEach(([N, m]) => {
|
41
|
+
m && Object.entries(m).forEach(([O, l]) => {
|
42
42
|
if (!l) return;
|
43
|
-
const
|
44
|
-
n.push(
|
43
|
+
const w = `${e}.${N}-${O}`, $ = R(l, w);
|
44
|
+
n.push($);
|
45
45
|
});
|
46
|
-
}),
|
46
|
+
}), c;
|
47
47
|
if (o === "defaultVariants")
|
48
|
-
return
|
48
|
+
return c;
|
49
49
|
if (o === "compoundVariants")
|
50
|
-
return r.forEach((
|
51
|
-
const { css:
|
52
|
-
n.push(
|
53
|
-
}),
|
50
|
+
return r.forEach((N) => {
|
51
|
+
const { css: m, ...O } = N, l = Object.entries(O).reduce(($, [S, y]) => `${$}.${S}-${y}`, e), w = R(m, l);
|
52
|
+
n.push(w);
|
53
|
+
}), c;
|
54
54
|
if (o.startsWith("@")) {
|
55
|
-
const
|
56
|
-
${
|
55
|
+
const N = R(r, e), m = `${o} {
|
56
|
+
${N.replace(`
|
57
57
|
`, `
|
58
58
|
`)}
|
59
59
|
}`;
|
60
|
-
return n.push(
|
60
|
+
return n.push(m), c;
|
61
61
|
}
|
62
62
|
const b = u.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, j = R(r, b);
|
63
|
-
return n.push(j),
|
63
|
+
return n.push(j), c;
|
64
64
|
}
|
65
|
-
const g = o.startsWith("-") ? o : J(o), p = (b, j = ";") =>
|
65
|
+
const g = o.startsWith("-") ? o : J(o), p = (b, j = ";") => c = `${c}${b}${j}`, d = (b) => p(`${g}:${b}`);
|
66
66
|
if (typeof r == "number") return d(r);
|
67
67
|
if (typeof r != "string")
|
68
68
|
if ("toString" in r) r = r.toString();
|
69
|
-
else return
|
69
|
+
else return c;
|
70
70
|
const { modifiers: x } = {}, T = function* () {
|
71
|
-
yield at(r), yield
|
71
|
+
yield at(r), yield Dt(r, x);
|
72
72
|
}();
|
73
73
|
for (const { result: b, additionalCss: j = [] } of T)
|
74
|
-
r = b, j.forEach((
|
75
|
-
const
|
76
|
-
p(
|
74
|
+
r = b, j.forEach((N) => {
|
75
|
+
const m = R(N, "");
|
76
|
+
p(m, "");
|
77
77
|
});
|
78
78
|
return d(r);
|
79
79
|
}, "");
|
80
|
-
return
|
81
|
-
`) :
|
80
|
+
return i ? e ? [`${e} { ${i} }`, ...n].join(`
|
81
|
+
`) : i : n.join(`
|
82
82
|
`);
|
83
83
|
}, lt = (t, e = []) => {
|
84
84
|
if (!t) return "";
|
85
85
|
const s = [], n = {};
|
86
|
-
if (Object.entries(t).forEach(([
|
86
|
+
if (Object.entries(t).forEach(([i, a]) => {
|
87
87
|
if (typeof a == "object") {
|
88
88
|
if (!a) return;
|
89
|
-
const
|
89
|
+
const c = i.trim(), u = lt(a, [...e, c]);
|
90
90
|
s.push(u);
|
91
91
|
} else
|
92
|
-
n[
|
92
|
+
n[i] = a;
|
93
93
|
}), Object.keys(n).length) {
|
94
|
-
const
|
94
|
+
const i = e.map(J).join("-"), a = R(n, `.${i}`);
|
95
95
|
s.push(a);
|
96
96
|
}
|
97
97
|
return s.join(`
|
98
98
|
`);
|
99
|
-
},
|
99
|
+
}, Nt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = ft(n).map((i) => `"${i}"`).join(" | ")), e), {}) : {}, ft = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, i]) => {
|
100
100
|
const a = e ? `${e}.${n}` : n;
|
101
|
-
return typeof
|
101
|
+
return typeof i == "object" ? ft(i, a, s) : s.add(e);
|
102
102
|
}), [...s]) : [], ut = (t) => {
|
103
103
|
if (!t || t === "/") throw new Error("Could not find package.json file");
|
104
104
|
const e = f(t, "package.json");
|
@@ -112,11 +112,11 @@ const Nt = (t, e) => {
|
|
112
112
|
if (e)
|
113
113
|
return e.type;
|
114
114
|
};
|
115
|
-
let
|
115
|
+
let Z;
|
116
116
|
const pt = async (t) => {
|
117
|
-
if (
|
117
|
+
if (Z) return Z;
|
118
118
|
const e = await Pt(t);
|
119
|
-
return e === "module" ?
|
119
|
+
return e === "module" ? Z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (Z = "cjs"), Z || "esm";
|
120
120
|
}, X = Ct({
|
121
121
|
level: "debug",
|
122
122
|
format: U.combine(U.colorize(), U.cli()),
|
@@ -171,7 +171,7 @@ const Tt = {
|
|
171
171
|
fontSize: "100%",
|
172
172
|
lineHeight: "1.15em"
|
173
173
|
}
|
174
|
-
},
|
174
|
+
}, H = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), _ = {
|
175
175
|
externalModules: [],
|
176
176
|
rcFile: void 0,
|
177
177
|
destDir: void 0
|
@@ -179,93 +179,91 @@ const Tt = {
|
|
179
179
|
if (_.externalModules.length > 0) return _.externalModules;
|
180
180
|
const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
181
181
|
if (!s) return [];
|
182
|
-
const n = s[1].split(",").map((
|
182
|
+
const n = s[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
|
183
183
|
return _.externalModules = n, n;
|
184
|
-
},
|
184
|
+
}, A = async (t) => {
|
185
185
|
if (_.destDir) return _.destDir;
|
186
186
|
const e = await et(t), s = f(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
187
187
|
return _.destDir = s, s;
|
188
|
-
},
|
188
|
+
}, yt = ["salty", "css", "styles", "styled"], Ot = (t = []) => new RegExp(`\\.(${[...yt, ...t].join("|")})\\.`), I = (t, e = []) => Ot(e).test(t), ht = async (t) => {
|
189
189
|
if (_.rcFile) return _.rcFile;
|
190
190
|
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
191
191
|
const e = f(t, ".saltyrc.json"), s = await tt(e, "utf-8").then(JSON.parse).catch(() => {
|
192
192
|
});
|
193
|
-
return s ? (_.rcFile = s, s) :
|
193
|
+
return s ? (_.rcFile = s, s) : ht(f(t, ".."));
|
194
194
|
}, et = async (t) => {
|
195
|
-
var n,
|
196
|
-
const e = await
|
197
|
-
return s || ((
|
195
|
+
var n, i;
|
196
|
+
const e = await ht(t), s = (n = e.projects) == null ? void 0 : n.find((a) => t.endsWith(a.dir || ""));
|
197
|
+
return s || ((i = e.projects) == null ? void 0 : i.find((a) => a.dir === e.defaultProject));
|
198
198
|
}, Vt = async (t) => {
|
199
|
-
const e = await et(t), s = await
|
199
|
+
const e = await et(t), s = await A(t), n = f(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), i = f(s, "salty.config.js"), a = await pt(t), c = gt(n);
|
200
200
|
await ct.build({
|
201
201
|
entryPoints: [n],
|
202
202
|
minify: !0,
|
203
203
|
treeShaking: !0,
|
204
204
|
bundle: !0,
|
205
|
-
outfile:
|
205
|
+
outfile: i,
|
206
206
|
format: a,
|
207
|
-
external:
|
207
|
+
external: c
|
208
208
|
});
|
209
|
-
const u = Date.now(), { config: r } = await import(`${
|
209
|
+
const u = Date.now(), { config: r } = await import(`${i}?t=${u}`);
|
210
210
|
return r;
|
211
211
|
}, _t = async (t, e) => {
|
212
|
-
const s = await Vt(t), n = { ...s },
|
212
|
+
const s = await Vt(t), n = { ...s }, i = /* @__PURE__ */ new Set(), a = (k, F = []) => k ? Object.entries(k).flatMap(([V, E]) => {
|
213
213
|
if (!E) return;
|
214
214
|
if (typeof E == "object") return a(E, [...F, V]);
|
215
|
-
const
|
216
|
-
|
215
|
+
const W = dt(V), K = J(V), q = [...F, W].join(".");
|
216
|
+
i.add(`"${q}"`);
|
217
217
|
const Q = [...F.map(J), K].join("-"), { result: $t } = at(E);
|
218
218
|
return `--${Q}: ${$t};`;
|
219
|
-
}) : [],
|
219
|
+
}) : [], c = (k) => k ? Object.entries(k).flatMap(([F, V]) => {
|
220
220
|
const E = a(V);
|
221
221
|
return F === "base" ? E.join("") : `${F} { ${E.join("")} }`;
|
222
|
-
}) : [], u = (k) => k ? Object.entries(k).flatMap(([F, V]) => Object.entries(V).flatMap(([E,
|
223
|
-
const K = a(
|
222
|
+
}) : [], u = (k) => k ? Object.entries(k).flatMap(([F, V]) => Object.entries(V).flatMap(([E, W]) => {
|
223
|
+
const K = a(W, [F]), q = `.${F}-${E}, [data-${F}="${E}"]`, Q = K.join("");
|
224
224
|
return `${q} { ${Q} }`;
|
225
|
-
})) : [], r = (k) => e.variables.map((F) => F._current[k]), o = a(
|
226
|
-
P(x,
|
227
|
-
const T = f(d, "css/_global.css"), b =
|
225
|
+
})) : [], r = (k) => e.variables.map((F) => F._current[k]), o = a(H(s.variables, r("variables"))), g = c(H(s.responsiveVariables, r("responsiveVariables"))), p = u(H(s.conditionalVariables, r("conditionalVariables"))), d = await A(t), x = f(d, "css/_variables.css"), D = `:root { ${o.join("")} ${g.join("")} } ${p.join("")}`;
|
226
|
+
P(x, D);
|
227
|
+
const T = f(d, "css/_global.css"), b = H(s.global, e.globalStyles), j = R(b, "");
|
228
228
|
P(T, `@layer global { ${j} }`);
|
229
|
-
const
|
230
|
-
P(
|
231
|
-
const
|
232
|
-
|
233
|
-
const
|
234
|
-
P(S, w), n.templates = m;
|
235
|
-
const C = f(d, "types/css-tokens.d.ts"), I = `
|
229
|
+
const N = f(d, "css/_reset.css"), O = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Tt, l = R(O, "");
|
230
|
+
P(N, `@layer reset { ${l} }`);
|
231
|
+
const w = f(d, "css/_templates.css"), $ = H(s.templates, e.templates), S = lt($), y = Nt($);
|
232
|
+
P(w, S), n.templates = $;
|
233
|
+
const C = f(d, "types/css-tokens.d.ts"), G = `
|
236
234
|
// Variable types
|
237
|
-
type VariableTokens = ${[...
|
235
|
+
type VariableTokens = ${[...i].join("|")};
|
238
236
|
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
239
237
|
|
240
238
|
// Template types
|
241
239
|
type TemplateTokens = {
|
242
|
-
${Object.entries(
|
240
|
+
${Object.entries(y).map(([k, F]) => `${k}?: ${F}`).join(`
|
243
241
|
`)}
|
244
242
|
}
|
245
243
|
`;
|
246
|
-
P(C,
|
247
|
-
const
|
248
|
-
P(
|
244
|
+
P(C, G);
|
245
|
+
const L = f(d, "cache/config-cache.json");
|
246
|
+
P(L, JSON.stringify(n, null, 2));
|
249
247
|
}, rt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
250
248
|
if (/^['"`]/.test(s)) return e;
|
251
|
-
const
|
252
|
-
if (!
|
253
|
-
const
|
254
|
-
if (
|
255
|
-
const u =
|
256
|
-
if (
|
249
|
+
const i = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
250
|
+
if (!i.test(t)) return e;
|
251
|
+
const c = i.exec(t);
|
252
|
+
if (c) {
|
253
|
+
const u = c.at(1);
|
254
|
+
if (yt.some((o) => u == null ? void 0 : u.includes(o))) return e;
|
257
255
|
}
|
258
256
|
return "styled('div',";
|
259
257
|
}), st = async (t, e, s) => {
|
260
|
-
const n = B(e),
|
261
|
-
v(
|
258
|
+
const n = B(e), i = f(s, "./temp");
|
259
|
+
v(i) || z(i);
|
262
260
|
const a = Y(e);
|
263
|
-
let
|
264
|
-
|
261
|
+
let c = M(e, "utf8");
|
262
|
+
c = rt(c);
|
265
263
|
const u = f(s, "js", n + ".js"), r = await et(t), o = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), g = gt(o), p = await pt(t);
|
266
264
|
await ct.build({
|
267
265
|
stdin: {
|
268
|
-
contents:
|
266
|
+
contents: c,
|
269
267
|
sourcefile: a.base,
|
270
268
|
resolveDir: a.dir,
|
271
269
|
loader: "tsx"
|
@@ -282,8 +280,8 @@ const Tt = {
|
|
282
280
|
plugins: [
|
283
281
|
{
|
284
282
|
name: "test",
|
285
|
-
setup: (
|
286
|
-
|
283
|
+
setup: (D) => {
|
284
|
+
D.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (T) => {
|
287
285
|
const b = M(T.path, "utf8");
|
288
286
|
return { contents: rt(b), loader: "ts" };
|
289
287
|
});
|
@@ -293,23 +291,26 @@ const Tt = {
|
|
293
291
|
});
|
294
292
|
const d = Date.now();
|
295
293
|
return await import(`${u}?t=${d}`);
|
296
|
-
},
|
297
|
-
const e = await
|
294
|
+
}, Mt = async (t) => {
|
295
|
+
const e = await A(t), s = f(e, "cache/config-cache.json"), n = M(s, "utf8");
|
298
296
|
if (!n) throw new Error("Could not find config cache file");
|
299
297
|
return JSON.parse(n);
|
298
|
+
}, nt = async (t) => {
|
299
|
+
const e = await Mt(t), s = await A(t), n = f(s, "salty.config.js"), i = Date.now(), { config: a } = await import(`${n}?t=${i}`);
|
300
|
+
return H(a, e);
|
300
301
|
}, mt = () => {
|
301
302
|
try {
|
302
303
|
return process.env.NODE_ENV === "production";
|
303
304
|
} catch {
|
304
305
|
return !1;
|
305
306
|
}
|
306
|
-
},
|
307
|
+
}, Rt = async (t, e = mt(), s = !0) => {
|
307
308
|
try {
|
308
309
|
const n = Date.now();
|
309
310
|
e ? X.info("Generating CSS in production mode! 🔥") : X.info("Generating CSS in development mode! 🚀");
|
310
|
-
const
|
311
|
+
const i = [], a = [], c = await A(t), u = f(c, "index.css");
|
311
312
|
s && (() => {
|
312
|
-
v(
|
313
|
+
v(c) && bt("rm -rf " + c), z(c, { recursive: !0 }), z(f(c, "css")), z(f(c, "types")), z(f(c, "js")), z(f(c, "cache"));
|
313
314
|
})();
|
314
315
|
const o = {
|
315
316
|
keyframes: [],
|
@@ -320,20 +321,20 @@ const Tt = {
|
|
320
321
|
templates: []
|
321
322
|
};
|
322
323
|
async function g(l) {
|
323
|
-
const
|
324
|
-
if (
|
325
|
-
const
|
326
|
-
if (
|
327
|
-
await Promise.all(
|
328
|
-
} else if (
|
329
|
-
const
|
330
|
-
Object.entries(
|
331
|
-
|
332
|
-
value:
|
324
|
+
const w = ["node_modules", "saltygen"], $ = wt(l);
|
325
|
+
if ($.isDirectory()) {
|
326
|
+
const S = St(l);
|
327
|
+
if (w.some((C) => l.includes(C))) return;
|
328
|
+
await Promise.all(S.map((C) => g(f(l, C))));
|
329
|
+
} else if ($.isFile() && I(l)) {
|
330
|
+
const y = await st(t, l, c);
|
331
|
+
Object.entries(y).forEach(([C, h]) => {
|
332
|
+
h.isKeyframes ? o.keyframes.push({
|
333
|
+
value: h,
|
333
334
|
src: l,
|
334
335
|
name: C
|
335
|
-
}) :
|
336
|
-
value:
|
336
|
+
}) : h.isMedia ? o.mediaQueries.push(h) : h.isGlobalDefine ? o.globalStyles.push(h) : h.isDefineVariables ? o.variables.push(h) : h.isDefineTemplates ? o.templates.push(h) : h.generator && o.components.push({
|
337
|
+
value: h.generator,
|
337
338
|
src: l,
|
338
339
|
name: C
|
339
340
|
});
|
@@ -343,32 +344,32 @@ const Tt = {
|
|
343
344
|
await g(t), await _t(t, o);
|
344
345
|
const p = await nt(t);
|
345
346
|
for (const l of o.keyframes) {
|
346
|
-
const { value:
|
347
|
-
|
347
|
+
const { value: w } = l, $ = `a_${w.animationName}.css`, S = `css/${$}`, y = f(c, S);
|
348
|
+
i.push($), P(y, w.css);
|
348
349
|
}
|
349
350
|
const d = {};
|
350
351
|
for (const l of o.components) {
|
351
|
-
const { value:
|
352
|
-
name:
|
352
|
+
const { value: w, name: $, src: S } = l, y = w._withBuildContext({
|
353
|
+
name: $,
|
353
354
|
config: p,
|
354
355
|
prod: e
|
355
356
|
});
|
356
|
-
a[
|
357
|
-
const C = `css/${
|
358
|
-
P(
|
357
|
+
a[y.priority] || (a[y.priority] = []), a[y.priority].push(y.cssFileName), p.importStrategy === "component" && (d[S] ? d[S].push(y.cssFileName) : d[S] = [y.cssFileName]);
|
358
|
+
const C = `css/${y.cssFileName}`, h = f(c, C);
|
359
|
+
P(h, y.css);
|
359
360
|
}
|
360
|
-
p.importStrategy === "component" && Object.entries(d).forEach(([l,
|
361
|
-
const
|
362
|
-
`),
|
363
|
-
P(
|
361
|
+
p.importStrategy === "component" && Object.entries(d).forEach(([l, w]) => {
|
362
|
+
const $ = w.map((G) => `@import url('./${G}');`).join(`
|
363
|
+
`), S = B(l, 6), y = Y(l), C = J(y.name), h = f(c, `css/f_${C}-${S}.css`);
|
364
|
+
P(h, $);
|
364
365
|
});
|
365
|
-
const x =
|
366
|
+
const x = i.map((l) => `@import url('./css/${l}');`).join(`
|
366
367
|
`);
|
367
368
|
let j = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
368
369
|
|
369
370
|
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
|
370
371
|
try {
|
371
|
-
return M(f(
|
372
|
+
return M(f(c, "css", l), "utf8").length > 0;
|
372
373
|
} catch {
|
373
374
|
return !1;
|
374
375
|
}
|
@@ -376,37 +377,37 @@ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) =
|
|
376
377
|
`)}
|
377
378
|
${x}`;
|
378
379
|
if (p.importStrategy !== "component") {
|
379
|
-
const l = a.reduce((
|
380
|
-
const
|
381
|
-
var
|
382
|
-
const F = f(
|
383
|
-
return
|
380
|
+
const l = a.reduce((w, $, S) => {
|
381
|
+
const y = $.reduce((L, k) => {
|
382
|
+
var W;
|
383
|
+
const F = f(c, "css", k), V = M(F, "utf8"), E = ((W = /.*-([^-]+)-\d+.css/.exec(k)) == null ? void 0 : W.at(1)) || B(F, 6);
|
384
|
+
return L.includes(E) ? L : `${L}
|
384
385
|
/*start:${E}*/
|
385
386
|
${V}
|
386
387
|
/*end:${E}*/
|
387
388
|
`;
|
388
|
-
}, ""), C = `l_${
|
389
|
+
}, ""), C = `l_${S}.css`, h = f(c, "css", C), G = `@layer l${S} { ${y}
|
389
390
|
}`;
|
390
|
-
return P(
|
391
|
+
return P(h, G), `${w}
|
391
392
|
@import url('./css/${C}');`;
|
392
393
|
}, "");
|
393
394
|
j += l;
|
394
395
|
}
|
395
396
|
P(u, j);
|
396
|
-
const
|
397
|
-
X.info(`Generated CSS in ${
|
397
|
+
const m = Date.now() - n, O = m < 200 ? "🔥" : m < 500 ? "🚀" : m < 1e3 ? "🎉" : m < 2e3 ? "🚗" : m < 5e3 ? "🤔" : "🥴";
|
398
|
+
X.info(`Generated CSS in ${m}ms! ${O}`);
|
398
399
|
} catch (n) {
|
399
400
|
console.error(n);
|
400
401
|
}
|
401
|
-
},
|
402
|
+
}, Jt = async (t, e) => {
|
402
403
|
try {
|
403
|
-
const s = await
|
404
|
-
if (
|
405
|
-
const
|
406
|
-
Object.entries(
|
404
|
+
const s = await A(t);
|
405
|
+
if (I(e)) {
|
406
|
+
const i = [], a = await nt(t), c = await st(t, e, s);
|
407
|
+
Object.entries(c).forEach(([u, r]) => {
|
407
408
|
if (r.isKeyframes && r.css) {
|
408
|
-
const x = `css/${`a_${r.animationName}.css`}`,
|
409
|
-
P(
|
409
|
+
const x = `css/${`a_${r.animationName}.css`}`, D = f(s, x);
|
410
|
+
P(D, r.css);
|
410
411
|
return;
|
411
412
|
}
|
412
413
|
if (!r.generator) return;
|
@@ -414,20 +415,20 @@ ${V}
|
|
414
415
|
name: u,
|
415
416
|
config: a
|
416
417
|
}), g = `css/${o.cssFileName}`, p = f(s, g);
|
417
|
-
P(p, o.css),
|
418
|
-
}), a.importStrategy !== "component" &&
|
418
|
+
P(p, o.css), i[o.priority] || (i[o.priority] = []), i[o.priority].push(o.cssFileName);
|
419
|
+
}), a.importStrategy !== "component" && i.forEach((u, r) => {
|
419
420
|
const o = `l_${r}.css`, g = f(s, "css", o);
|
420
421
|
let p = M(g, "utf8");
|
421
422
|
u.forEach((d) => {
|
422
423
|
var b;
|
423
|
-
const x = f(s, "css", d),
|
424
|
-
if (!p.includes(
|
425
|
-
const j = M(x, "utf8"),
|
424
|
+
const x = f(s, "css", d), D = ((b = /.*-([^-]+)-\d+.css/.exec(d)) == null ? void 0 : b.at(1)) || B(x, 6);
|
425
|
+
if (!p.includes(D)) {
|
426
|
+
const j = M(x, "utf8"), N = `/*start:${D}*/
|
426
427
|
${j}
|
427
|
-
/*end:${
|
428
|
+
/*end:${D}*/
|
428
429
|
`;
|
429
430
|
p = `${p.replace(/\}$/, "")}
|
430
|
-
${
|
431
|
+
${N}
|
431
432
|
}`;
|
432
433
|
}
|
433
434
|
}), P(g, p);
|
@@ -436,10 +437,10 @@ ${D}
|
|
436
437
|
} catch (s) {
|
437
438
|
console.error(s);
|
438
439
|
}
|
439
|
-
},
|
440
|
+
}, At = async (t, e, s = mt()) => {
|
440
441
|
try {
|
441
|
-
const n = await
|
442
|
-
if (
|
442
|
+
const n = await A(t);
|
443
|
+
if (I(e)) {
|
443
444
|
const a = M(e, "utf8");
|
444
445
|
a.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== a && await jt(e, a);
|
445
446
|
const u = await nt(t), r = await st(t, e, n);
|
@@ -453,20 +454,20 @@ ${D}
|
|
453
454
|
prod: s
|
454
455
|
}), x = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
|
455
456
|
if (!x) return console.error("Could not find the original declaration");
|
456
|
-
const
|
457
|
+
const D = (C = x.at(1)) == null ? void 0 : C.trim(), T = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(o);
|
457
458
|
if (!T) return console.error("Could not find the original declaration");
|
458
459
|
const { index: b } = T;
|
459
460
|
let j = !1;
|
460
|
-
const
|
461
|
-
let
|
461
|
+
const N = setTimeout(() => j = !0, 5e3);
|
462
|
+
let m = 0, O = !1, l = 0;
|
462
463
|
for (; !O && !j; ) {
|
463
|
-
const
|
464
|
-
|
464
|
+
const h = o[b + m];
|
465
|
+
h === "(" && l++, h === ")" && l--, l === 0 && h === ")" && (O = !0), m > o.length && (j = !0), m++;
|
465
466
|
}
|
466
|
-
if (!j) clearTimeout(
|
467
|
+
if (!j) clearTimeout(N);
|
467
468
|
else throw new Error("Failed to find the end of the styled call and timed out");
|
468
|
-
const
|
469
|
-
o = o.replace(
|
469
|
+
const w = b + m, $ = o.slice(b, w), S = o, y = ` ${g} = styled(${D}, "${d.classNames}", ${JSON.stringify(d.props)});`;
|
470
|
+
o = o.replace($, y), S === o && console.error("Minimize file failed to change content", { name: g, tagName: D });
|
470
471
|
}), u.importStrategy === "component") {
|
471
472
|
const g = B(e, 6), p = Y(e);
|
472
473
|
o = `import '../../saltygen/css/${`f_${J(p.name)}-${g}.css`}';
|
@@ -480,26 +481,26 @@ ${o}`;
|
|
480
481
|
}, it = async (t) => {
|
481
482
|
if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
|
482
483
|
if (t.includes("salty.config")) return !0;
|
483
|
-
if (!
|
484
|
+
if (!I(t)) return !1;
|
484
485
|
const n = await tt(t, "utf-8");
|
485
486
|
return !!/.+define[A-Z]\w+/.test(n);
|
486
|
-
},
|
487
|
+
}, Gt = (t) => ({
|
487
488
|
name: "stylegen",
|
488
|
-
buildStart: () =>
|
489
|
+
buildStart: () => Rt(t),
|
489
490
|
load: async (e) => {
|
490
|
-
if (
|
491
|
-
return await
|
491
|
+
if (I(e))
|
492
|
+
return await At(t, e);
|
492
493
|
},
|
493
494
|
handleHotUpdate: async ({ file: e, server: s }) => {
|
494
495
|
await it(e) && await s.restart();
|
495
496
|
},
|
496
497
|
watchChange: {
|
497
498
|
handler: async (e) => {
|
498
|
-
|
499
|
+
I(e) && (await it(e) || await Jt(t, e));
|
499
500
|
}
|
500
501
|
}
|
501
502
|
});
|
502
503
|
export {
|
503
|
-
|
504
|
-
|
504
|
+
Gt as default,
|
505
|
+
Gt as saltyPlugin
|
505
506
|
};
|
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.181",
|
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.181"
|
38
38
|
}
|
39
39
|
}
|