@salty-css/vite 0.0.1-alpha.70 → 0.0.1-alpha.72
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 +12 -12
- package/index.js +1 -1
- package/package.json +2 -2
package/index.cjs
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Y=require("esbuild"),Q=require("child_process"),
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const Y=require("esbuild"),Q=require("child_process"),d=require("path"),g=require("fs"),v=require("fs/promises");var D=typeof document<"u"?document.currentScript:null;function tt(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 W=tt(Y),U=t=>String.fromCharCode(t+(t>25?39:97)),et=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=U(n%52)+s;return s=U(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},st=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},R=(t,e=3)=>{const s=st(5381,JSON.stringify(t))>>>0;return et(s,e)};function M(t){return t?typeof t!="string"?M(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 nt=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:o,transform:p}=n;t=t.replace(o,y=>{const{value:a,css:c}=p(y);return c&&s.push(c),a})}),{result:t,additionalCss:s}},B=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${M(n[1].replaceAll(".","-"))})`)}:{result:t},O=(t,e,s,n)=>{if(!t)return"";const o=[],p=Object.entries(t).reduce((a,[c,r])=>{const u=c.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(u==="variants")return Object.entries(r).forEach(([i,f])=>{f&&Object.entries(f).forEach(([$,h])=>{if(!h)return;const F=`${e}.${i}-${$}`,j=O(h,F);o.push(j)})}),a;if(u==="defaultVariants")return a;if(u==="compoundVariants")return r.forEach(i=>{const{css:f,...$}=i,h=Object.entries($).reduce((j,[w,P])=>`${j}.${w}-${P}`,e),F=O(f,h);o.push(F)}),a;if(u.startsWith("@")){const i=O(r,e),f=`${u} {
|
2
2
|
${i.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return o.push(f),a}const m=c.includes("&")?u.replace("&",e):u.startsWith(":")?`${e}${u}`:`${e} ${u}`,C=
|
6
|
-
`);if(!e)return p;let
|
7
|
-
`)},
|
8
|
-
`)},
|
9
|
-
`),$=R(l,6),h=
|
5
|
+
}`;return o.push(f),a}const m=c.includes("&")?u.replace("&",e):u.startsWith(":")?`${e}${u}`:`${e} ${u}`,C=O(r,m);return o.push(C),a}const T=u.startsWith("-")?u:M(u),b=(m,C=";")=>a=`${a}${m}${C}`,l=m=>b(`${T}:${m}`);if(typeof r=="number")return l(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:S}={},x=function*(){yield B(r),yield nt(r,S)}();for(const{result:m,additionalCss:C=[]}of x)r=m,C.forEach(i=>{const f=O(i,"");b(f,"")});return l(r)},"");if(!p)return o.join(`
|
6
|
+
`);if(!e)return p;let y="";return y=`${e} { ${p} }`,[y,...o].join(`
|
7
|
+
`)},L=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,p])=>{if(typeof p=="object"){if(!p)return;const y=o.trim(),a=L(p,[...e,y]);s.push(a)}else n[o]=p}),Object.keys(n).length){const o=e.map(M).join("-"),p=O(n,`.${o}`);s.push(p)}return s.join(`
|
8
|
+
`)},Z=()=>(console.log("current meta url:",typeof document>"u"?require("url").pathToFileURL(__filename).href:D&&D.tagName.toUpperCase()==="SCRIPT"&&D.src||new URL("index.cjs",document.baseURI).href),(typeof document>"u"?require("url").pathToFileURL(__filename).href:D&&D.tagName.toUpperCase()==="SCRIPT"&&D.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs")?"cjs":"esm"),V={externalModules:[]},z=t=>{if(V.externalModules.length>0)return V.externalModules;const e=d.join(t,"salty.config.ts"),n=g.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const o=n[1].split(",").map(p=>p.replace(/['"`]/g,"").trim());return V.externalModules=o,o},_=t=>d.join(t,"./saltygen"),ot=["salty","css","styles","styled"],rt=(t=[])=>new RegExp(`\\.(${[...ot,...t].join("|")})\\.`),E=(t,e=[])=>rt(e).test(t),it=async t=>{const e=_(t),s=d.join(t,"salty.config.ts"),n=d.join(e,"salty.config.js"),o=Z(),p=z(t);await W.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o,external:p});const y=Date.now(),{config:a}=await import(`${n}?t=${y}`);return a},H=async t=>{const e=await it(t),s=new Set,n=(i,f=[])=>i?Object.entries(i).flatMap(([$,h])=>{if(!h)return;if(typeof h=="object")return n(h,[...f,$]);const F=[...f,$].join(".");s.add(`"${F}"`);const j=[...f.map(M),M($)].join("-"),{result:w}=B(h);return`--${j}: ${w};`}):[],o=i=>i?Object.entries(i).flatMap(([f,$])=>{const h=n($);return f==="base"?h.join(""):`${f} { ${h.join("")} }`}):[],p=i=>i?Object.entries(i).flatMap(([f,$])=>Object.entries($).flatMap(([h,F])=>{const j=n(F,[f]),w=`.${f}-${h}, [data-${f}="${h}"]`,P=j.join("");return`${w} { ${P} }`})):[],y=n(e.variables),a=o(e.responsiveVariables),c=p(e.conditionalVariables),r=_(t),u=d.join(r,"css/variables.css"),T=`:root { ${y.join("")} ${a.join("")} } ${c.join("")}`;g.writeFileSync(u,T);const b=d.join(r,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;g.writeFileSync(b,S);const k=d.join(r,"css/global.css"),x=O(e.global,"");g.writeFileSync(k,x);const m=d.join(r,"css/templates.css"),C=L(e.templates);g.writeFileSync(m,C)},A=async(t,e,s)=>{const n=R(e),o=d.join(s,"js",n+".js"),p=Z(),y=z(t);await W.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:p,target:["es2022"],keepNames:!0,external:y});const a=Date.now();return await import(`${o}?t=${a}`)},I=async t=>{const e=_(t),s=d.join(e,"salty.config.js"),{config:n}=await import(s);return n},ct=async t=>{try{const e=[],s=[],n=_(t),o=d.join(n,"index.css");(()=>{g.existsSync(n)&&Q.execSync("rm -rf "+n),g.mkdirSync(n),g.mkdirSync(d.join(n,"css")),g.mkdirSync(d.join(n,"types"))})(),await H(t);const y=await I(t);async function a(l,S){const k=["node_modules","saltygen"],x=g.statSync(l);if(x.isDirectory()){const m=g.readdirSync(l);if(k.some(i=>l.includes(i)))return;await Promise.all(m.map(i=>a(d.join(l,i),d.join(S,i))))}else if(x.isFile()&&E(l)){const C=await A(t,l,n),i=[];Object.entries(C).forEach(([F,j])=>{if(j.isKeyframes&&j.css){const q=`${j.animationName}.css`,G=`css/${q}`,X=d.join(n,G);e.push(q),g.writeFileSync(X,j.css);return}if(!j.generator)return;const w=j.generator._withBuildContext({name:F,config:y}),P=`${w.hash}-${w.priority}.css`;s[w.priority]||(s[w.priority]=[]),s[w.priority].push(P),i.push(P);const N=`css/${P}`,K=d.join(n,N);g.writeFileSync(K,w.css)});const f=i.map(F=>`@import url('./${F}');`).join(`
|
9
|
+
`),$=R(l,6),h=d.join(n,`css/${$}.css`);g.writeFileSync(h,f)}}await a(t,n);const c=e.map(l=>`@import url('./css/${l}');`).join(`
|
10
10
|
`);let b=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
11
11
|
|
12
|
-
${["variables.css","global.css","templates.css"].filter(l=>{try{return g.readFileSync(
|
12
|
+
${["variables.css","global.css","templates.css"].filter(l=>{try{return g.readFileSync(d.join(n,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
13
13
|
`)}
|
14
|
-
${c}`;if(
|
15
|
-
`);b+=l}g.writeFileSync(o,b)}catch(e){console.error(e)}},at=async(t,e)=>{try{const s=[],n=
|
16
|
-
`),r=s.map(b=>`@import url('../saltygen/css/${b}');`),
|
17
|
-
`);g.writeFileSync(o,
|
18
|
-
${c}`),c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(s){console.error("Error in minimizeFile:",s)}},J=t=>({name:"stylegen",buildStart:()=>ct(t),load:async e=>{if(
|
14
|
+
${c}`;if(y.importStrategy!=="component"){const l=s.flat().map(S=>`@import url('./css/${S}');`).join(`
|
15
|
+
`);b+=l}g.writeFileSync(o,b)}catch(e){console.error(e)}},at=async(t,e)=>{try{const s=[],n=d.join(t,"./saltygen"),o=d.join(n,"index.css");if(E(e)){const y=await I(t),a=await A(t,e,n);Object.entries(a).forEach(([b,l])=>{if(!l.generator)return;const S=l.generator._withBuildContext({name:b,config:y}),k=`${S.hash}-${S.priority}.css`,x=`css/${k}`,m=d.join(n,x);s.push(k),g.writeFileSync(m,S.css)});const c=g.readFileSync(o,"utf8").split(`
|
16
|
+
`),r=s.map(b=>`@import url('../saltygen/css/${b}');`),T=[...new Set([...c,...r])].join(`
|
17
|
+
`);g.writeFileSync(o,T)}}catch(s){console.error(s)}},lt=async(t,e)=>{try{const s=d.join(t,"./saltygen");if(E(e)){const o=g.readFileSync(e,"utf8");o.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==o&&await v.writeFile(e,o);const y=await I(t),a=await A(t,e,s);let c=o;Object.entries(a).forEach(([u,T])=>{var P;if(T.isKeyframes||!T.generator)return;const b=T.generator._withBuildContext({name:u,config:y}),l=new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!l)return console.error("Could not find the original declaration");const S=(P=l.at(1))==null?void 0:P.trim(),k=new RegExp(`\\s${u}[=\\s]+styled\\(`,"g").exec(c);if(!k)return console.error("Could not find the original declaration");const{index:x}=k;let m=!1;const C=setTimeout(()=>m=!0,5e3);let i=0,f=!1,$=0;for(;!f&&!m;){const N=c[x+i];N==="("&&$++,N===")"&&$--,$===0&&N===")"&&(f=!0),i>c.length&&(m=!0),i++}if(!m)clearTimeout(C);else throw new Error("Failed to find the end of the styled call and timed out");const h=x+i,F=c.slice(x,h),j=c,w=` ${u} = styled(${S}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;c=c.replace(F,w),j===c&&console.error("Minimize file failed to change content",{name:u,tagName:S})});const r=R(e,6);return y.importStrategy==="component"&&(c=`import '../../saltygen/css/${r}.css';
|
18
|
+
${c}`),c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(s){console.error("Error in minimizeFile:",s)}},J=t=>({name:"stylegen",buildStart:()=>ct(t),load:async e=>{if(E(e))return await lt(t,e)},watchChange:{handler:async e=>{E(e)&&await at(t,e),e.includes("salty.config")&&await H(t)}}});exports.default=J;exports.saltyPlugin=J;
|
package/index.js
CHANGED
@@ -98,7 +98,7 @@ const ot = (t, s) => {
|
|
98
98
|
}
|
99
99
|
return e.join(`
|
100
100
|
`);
|
101
|
-
}, K = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", R = {
|
101
|
+
}, K = () => (console.log("current meta url:", import.meta.url), import.meta.url.endsWith(".cjs") ? "cjs" : "esm"), R = {
|
102
102
|
externalModules: []
|
103
103
|
}, q = (t) => {
|
104
104
|
if (R.externalModules.length > 0) return R.externalModules;
|
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.72",
|
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.72"
|
38
38
|
}
|
39
39
|
}
|