@salty-css/vite 0.0.1-alpha.59 → 0.0.1-alpha.60
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 +6 -6
- package/index.js +21 -21
- 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 G=require("esbuild"),X=require("child_process"),p=require("path"),h=require("fs"),Y=require("fs/promises");var _=typeof document<"u"?document.currentScript:null;function Q(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=Q(G),I=t=>String.fromCharCode(t+(t>25?39:97)),v=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=I(n%52)+s;return s=I(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},tt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},M=(t,e=3)=>{const s=tt(5381,JSON.stringify(t))>>>0;return v(s,e)};function
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const G=require("esbuild"),X=require("child_process"),p=require("path"),h=require("fs"),Y=require("fs/promises");var _=typeof document<"u"?document.currentScript:null;function Q(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=Q(G),I=t=>String.fromCharCode(t+(t>25?39:97)),v=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=I(n%52)+s;return s=I(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},tt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},M=(t,e=3)=>{const s=tt(5381,JSON.stringify(t))>>>0;return v(s,e)};function P(t){return t?typeof t!="string"?P(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 et=(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:y}=n;t=t.replace(o,d=>{const{value:u,css:c}=y(d);return c&&s.push(c),u})}),{result:t,additionalCss:s}},B=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${P(n[1].replaceAll(".","-"))})`)}:{result:t},D=(t,e,s,n)=>{if(!t)return"";const o=[],y=Object.entries(t).reduce((u,[c,r])=>{const l=c.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return u;if(l==="variants")return Object.entries(r).forEach(([i,f])=>{f&&Object.entries(f).forEach(([$,m])=>{if(!m)return;const F=`${e}.${i}-${$}`,b=D(m,F);o.push(b)})}),u;if(l==="defaultVariants")return u;if(l==="compoundVariants")return r.forEach(i=>{const{css:f,...$}=i,m=Object.entries($).reduce((b,[w,O])=>`${b}.${w}-${O}`,e),F=D(f,m);o.push(F)}),u;if(l.startsWith("@")){const i=D(r,e),f=`${l} {
|
2
2
|
${i.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return o.push(f),u}const g=c.includes("&")?l.replace("&",e):l.startsWith(":")?`${e}${l}`:`${e} ${l}`,k=
|
5
|
+
}`;return o.push(f),u}const g=c.includes("&")?l.replace("&",e):l.startsWith(":")?`${e}${l}`:`${e} ${l}`,k=D(r,g);return o.push(k),u}const T=l.startsWith("-")?l:P(l),j=(g,k=";")=>u=`${u}${g}${k}`,a=g=>j(`${T}:${g}`);if(typeof r=="number")return a(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return u;const{modifiers:S}={},C=function*(){yield B(r),yield et(r,S)}();for(const{result:g,additionalCss:k=[]}of C)r=g,k.forEach(i=>{const f=D(i,"");j(f,"")});return a(r)},"");if(!y)return o.join(`
|
6
6
|
`);if(!e)return y;let d="";return d=`${e} { ${y} }`,[d,...o].join(`
|
7
|
-
`)},Z=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,y])=>{if(typeof y=="object"){if(!y)return;const d=o.trim(),u=Z(y,[...e,d]);s.push(u)}else n[o]=y}),Object.keys(n).length){const o=e.map(
|
8
|
-
`)},z=()=>(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs")?"cjs":"esm",V=t=>p.join(t,"./saltygen"),st=["salty","css","styles","styled"],nt=(t=[])=>new RegExp(`\\.(${[...st,...t].join("|")})\\.`),E=(t,e=[])=>nt(e).test(t),ot=async t=>{const e=V(t),s=p.join(t,"salty.config.ts"),n=p.join(e,"salty.config.js"),o=z();console.log("Module type:",o),await W.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o});const y=Date.now(),{config:d}=await import(`${n}?t=${y}`);return d},U=async t=>{const e=await ot(t),s=new Set,n=(i,f=[])=>i?Object.entries(i).flatMap(([$,m])=>{if(!m)return;if(typeof m=="object")return n(m,[...f,$]);const F=[...f,$].join(".");s.add(`"${F}"`);const b=[...f.map(
|
7
|
+
`)},Z=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,y])=>{if(typeof y=="object"){if(!y)return;const d=o.trim(),u=Z(y,[...e,d]);s.push(u)}else n[o]=y}),Object.keys(n).length){const o=e.map(P).join("-"),y=D(n,`.${o}`);s.push(y)}return s.join(`
|
8
|
+
`)},z=()=>(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs")?"cjs":"esm",V=t=>p.join(t,"./saltygen"),st=["salty","css","styles","styled"],nt=(t=[])=>new RegExp(`\\.(${[...st,...t].join("|")})\\.`),E=(t,e=[])=>nt(e).test(t),ot=async t=>{const e=V(t),s=p.join(t,"salty.config.ts"),n=p.join(e,"salty.config.js"),o=z();console.log("Module type:",o),await W.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o,external:["react"]});const y=Date.now(),{config:d}=await import(`${n}?t=${y}`);return d},U=async t=>{const e=await ot(t),s=new Set,n=(i,f=[])=>i?Object.entries(i).flatMap(([$,m])=>{if(!m)return;if(typeof m=="object")return n(m,[...f,$]);const F=[...f,$].join(".");s.add(`"${F}"`);const b=[...f.map(P),P($)].join("-"),{result:w}=B(m);return`--${b}: ${w};`}):[],o=i=>i?Object.entries(i).flatMap(([f,$])=>{const m=n($);return f==="base"?m.join(""):`${f} { ${m.join("")} }`}):[],y=i=>i?Object.entries(i).flatMap(([f,$])=>Object.entries($).flatMap(([m,F])=>{const b=n(F,[f]),w=`.${f}-${m}, [data-${f}="${m}"]`,O=b.join("");return`${w} { ${O} }`})):[],d=n(e.variables),u=o(e.responsiveVariables),c=y(e.conditionalVariables),r=V(t),l=p.join(r,"css/variables.css"),T=`:root { ${d.join("")} ${u.join("")} } ${c.join("")}`;h.writeFileSync(l,T);const j=p.join(r,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;h.writeFileSync(j,S);const x=p.join(r,"css/global.css"),C=D(e.global,"");h.writeFileSync(x,C);const g=p.join(r,"css/templates.css"),k=Z(e.templates);h.writeFileSync(g,k)},R=async(t,e)=>{const s=M(t),n=p.join(e,"js",s+".js"),o=z();console.log("Module type:",o),await W.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o,target:["es2022"],keepNames:!0,external:["react"]});const y=Date.now();return await import(`${n}?t=${y}`)},A=async t=>{const e=V(t),s=p.join(e,"salty.config.js"),{config:n}=await import(s);return n},rt=async t=>{try{const e=[],s=[],n=V(t),o=p.join(n,"index.css");(()=>{h.existsSync(n)&&X.execSync("rm -rf "+n),h.mkdirSync(n),h.mkdirSync(p.join(n,"css")),h.mkdirSync(p.join(n,"types"))})(),await U(t);const d=await A(t);async function u(a,S){const x=["node_modules","saltygen"],C=h.statSync(a);if(C.isDirectory()){const g=h.readdirSync(a);if(x.some(i=>a.includes(i)))return;await Promise.all(g.map(i=>u(p.join(a,i),p.join(S,i))))}else if(C.isFile()&&E(a)){const k=await R(a,n),i=[];Object.entries(k).forEach(([F,b])=>{if(b.isKeyframes&&b.css){const q=`${b.animationName}.css`,J=`css/${q}`,K=p.join(n,J);e.push(q),h.writeFileSync(K,b.css);return}if(!b.generator)return;const w=b.generator._withBuildContext({name:F,config:d}),O=`${w.hash}-${w.priority}.css`;s[w.priority]||(s[w.priority]=[]),s[w.priority].push(O),i.push(O);const N=`css/${O}`,L=p.join(n,N);h.writeFileSync(L,w.css)});const f=i.map(F=>`@import url('./${F}');`).join(`
|
9
9
|
`),$=M(a,6),m=p.join(n,`css/${$}.css`);h.writeFileSync(m,f)}}await u(t,n);const c=e.map(a=>`@import url('./css/${a}');`).join(`
|
10
10
|
`);let j=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
11
11
|
|
12
12
|
${["variables.css","global.css","templates.css"].filter(a=>{try{return h.readFileSync(p.join(n,"css",a),"utf8").length>0}catch{return!1}}).map(a=>`@import url('./css/${a}');`).join(`
|
13
13
|
`)}
|
14
14
|
${c}`;if(d.importStrategy!=="component"){const a=s.flat().map(S=>`@import url('./css/${S}');`).join(`
|
15
|
-
`);j+=a}h.writeFileSync(o,j)}catch(e){console.error(e)}},it=async(t,e)=>{try{const s=[],n=p.join(t,"./saltygen"),o=p.join(n,"index.css");if(E(e)){const d=await A(t),u=await R(e,n);Object.entries(u).forEach(([j,a])=>{if(!a.generator)return;const S=a.generator._withBuildContext({name:j,config:d}),
|
15
|
+
`);j+=a}h.writeFileSync(o,j)}catch(e){console.error(e)}},it=async(t,e)=>{try{const s=[],n=p.join(t,"./saltygen"),o=p.join(n,"index.css");if(E(e)){const d=await A(t),u=await R(e,n);Object.entries(u).forEach(([j,a])=>{if(!a.generator)return;const S=a.generator._withBuildContext({name:j,config:d}),x=`${S.hash}-${S.priority}.css`,C=`css/${x}`,g=p.join(n,C);s.push(x),h.writeFileSync(g,S.css)});const c=h.readFileSync(o,"utf8").split(`
|
16
16
|
`),r=s.map(j=>`@import url('../saltygen/css/${j}');`),T=[...new Set([...c,...r])].join(`
|
17
|
-
`);h.writeFileSync(o,T)}}catch(s){console.error(s)}},ct=async(t,e)=>{try{const s=p.join(t,"./saltygen");if(E(e)){const o=h.readFileSync(e,"utf8");o.replace(/^(?!export\s)const\s.*/gm,l=>`export ${l}`)!==o&&await Y.writeFile(e,o);const d=await A(t),u=await R(e,s);let c=o;Object.entries(u).forEach(([l,T])=>{var
|
17
|
+
`);h.writeFileSync(o,T)}}catch(s){console.error(s)}},ct=async(t,e)=>{try{const s=p.join(t,"./saltygen");if(E(e)){const o=h.readFileSync(e,"utf8");o.replace(/^(?!export\s)const\s.*/gm,l=>`export ${l}`)!==o&&await Y.writeFile(e,o);const d=await A(t),u=await R(e,s);let c=o;Object.entries(u).forEach(([l,T])=>{var O;if(T.isKeyframes||!T.generator)return;const j=T.generator._withBuildContext({name:l,config:d}),a=new RegExp(`\\s${l}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!a)return console.error("Could not find the original declaration");const S=(O=a.at(1))==null?void 0:O.trim(),x=new RegExp(`\\s${l}[=\\s]+styled\\(`,"g").exec(c);if(!x)return console.error("Could not find the original declaration");const{index:C}=x;let g=!1;const k=setTimeout(()=>g=!0,5e3);let i=0,f=!1,$=0;for(;!f&&!g;){const N=c[C+i];N==="("&&$++,N===")"&&$--,$===0&&N===")"&&(f=!0),i>c.length&&(g=!0),i++}if(!g)clearTimeout(k);else throw new Error("Failed to find the end of the styled call and timed out");const m=C+i,F=c.slice(C,m),b=c,w=` ${l} = styled(${S}, "${j.classNames}", "${j._callerName}", ${JSON.stringify(j.props)});`;c=c.replace(F,w),b===c&&console.error("Minimize file failed to change content",{name:l,tagName:S})});const r=M(e,6);return d.importStrategy==="component"&&(c=`import '../../saltygen/css/${r}.css';
|
18
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)}},H=t=>({name:"stylegen",buildStart:()=>rt(t),load:async e=>{if(E(e))return await ct(t,e)},watchChange:{handler:async e=>{E(e)&&await it(t,e),e.includes("salty.config")&&await U(t)}}});exports.default=H;exports.saltyPlugin=H;
|
package/index.js
CHANGED
@@ -61,7 +61,7 @@ const et = (t, s) => {
|
|
61
61
|
const d = c.includes("&") ? l.replace("&", s) : l.startsWith(":") ? `${s}${l}` : `${s} ${l}`, C = E(r, d);
|
62
62
|
return o.push(C), p;
|
63
63
|
}
|
64
|
-
const
|
64
|
+
const x = l.startsWith("-") ? l : N(l), b = (d, C = ";") => p = `${p}${d}${C}`, a = (d) => b(`${x}:${d}`);
|
65
65
|
if (typeof r == "number") return a(r);
|
66
66
|
if (typeof r != "string")
|
67
67
|
if ("toString" in r) r = r.toString();
|
@@ -106,8 +106,8 @@ const et = (t, s) => {
|
|
106
106
|
treeShaking: !0,
|
107
107
|
bundle: !0,
|
108
108
|
outfile: n,
|
109
|
-
format: o
|
110
|
-
|
109
|
+
format: o,
|
110
|
+
external: ["react"]
|
111
111
|
});
|
112
112
|
const y = Date.now(), { config: g } = await import(`${n}?t=${y}`);
|
113
113
|
return g;
|
@@ -125,12 +125,12 @@ const et = (t, s) => {
|
|
125
125
|
}) : [], y = (i) => i ? Object.entries(i).flatMap(([f, h]) => Object.entries(h).flatMap(([m, S]) => {
|
126
126
|
const $ = n(S, [f]), w = `.${f}-${m}, [data-${f}="${m}"]`, D = $.join("");
|
127
127
|
return `${w} { ${D} }`;
|
128
|
-
})) : [], g = n(s.variables), p = o(s.responsiveVariables), c = y(s.conditionalVariables), r = V(t), l = u(r, "css/variables.css"),
|
129
|
-
T(l,
|
128
|
+
})) : [], g = n(s.variables), p = o(s.responsiveVariables), c = y(s.conditionalVariables), r = V(t), l = u(r, "css/variables.css"), x = `:root { ${g.join("")} ${p.join("")} } ${c.join("")}`;
|
129
|
+
T(l, x);
|
130
130
|
const b = u(r, "types/css-tokens.d.ts"), j = `type VariableTokens = ${[...e].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
131
131
|
T(b, j);
|
132
|
-
const
|
133
|
-
T(
|
132
|
+
const k = u(r, "css/global.css"), F = E(s.global, "");
|
133
|
+
T(k, F);
|
134
134
|
const d = u(r, "css/templates.css"), C = H(s.templates);
|
135
135
|
T(d, C);
|
136
136
|
}, _ = async (t, s) => {
|
@@ -143,8 +143,8 @@ const et = (t, s) => {
|
|
143
143
|
outfile: n,
|
144
144
|
format: o,
|
145
145
|
target: ["es2022"],
|
146
|
-
keepNames: !0
|
147
|
-
|
146
|
+
keepNames: !0,
|
147
|
+
external: ["react"]
|
148
148
|
});
|
149
149
|
const y = Date.now();
|
150
150
|
return await import(`${n}?t=${y}`);
|
@@ -159,10 +159,10 @@ const et = (t, s) => {
|
|
159
159
|
})(), await K(t);
|
160
160
|
const g = await W(t);
|
161
161
|
async function p(a, j) {
|
162
|
-
const
|
162
|
+
const k = ["node_modules", "saltygen"], F = Y(a);
|
163
163
|
if (F.isDirectory()) {
|
164
164
|
const d = Q(a);
|
165
|
-
if (
|
165
|
+
if (k.some((i) => a.includes(i))) return;
|
166
166
|
await Promise.all(d.map((i) => p(u(a, i), u(j, i))));
|
167
167
|
} else if (F.isFile() && P(a)) {
|
168
168
|
const C = await _(a, n), i = [];
|
@@ -219,13 +219,13 @@ ${c}`;
|
|
219
219
|
const j = a.generator._withBuildContext({
|
220
220
|
name: b,
|
221
221
|
config: g
|
222
|
-
}),
|
223
|
-
e.push(
|
222
|
+
}), k = `${j.hash}-${j.priority}.css`, F = `css/${k}`, d = u(n, F);
|
223
|
+
e.push(k), T(d, j.css);
|
224
224
|
});
|
225
225
|
const c = A(o, "utf8").split(`
|
226
|
-
`), r = e.map((b) => `@import url('../saltygen/css/${b}');`),
|
226
|
+
`), r = e.map((b) => `@import url('../saltygen/css/${b}');`), x = [.../* @__PURE__ */ new Set([...c, ...r])].join(`
|
227
227
|
`);
|
228
|
-
T(o,
|
228
|
+
T(o, x);
|
229
229
|
}
|
230
230
|
} catch (e) {
|
231
231
|
console.error(e);
|
@@ -238,17 +238,17 @@ ${c}`;
|
|
238
238
|
o.replace(/^(?!export\s)const\s.*/gm, (l) => `export ${l}`) !== o && await v(s, o);
|
239
239
|
const g = await W(t), p = await _(s, e);
|
240
240
|
let c = o;
|
241
|
-
Object.entries(p).forEach(([l,
|
241
|
+
Object.entries(p).forEach(([l, x]) => {
|
242
242
|
var D;
|
243
|
-
if (
|
244
|
-
const b =
|
243
|
+
if (x.isKeyframes || !x.generator) return;
|
244
|
+
const b = x.generator._withBuildContext({
|
245
245
|
name: l,
|
246
246
|
config: g
|
247
247
|
}), a = new RegExp(`\\s${l}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
|
248
248
|
if (!a) return console.error("Could not find the original declaration");
|
249
|
-
const j = (D = a.at(1)) == null ? void 0 : D.trim(),
|
250
|
-
if (!
|
251
|
-
const { index: F } =
|
249
|
+
const j = (D = a.at(1)) == null ? void 0 : D.trim(), k = new RegExp(`\\s${l}[=\\s]+styled\\(`, "g").exec(c);
|
250
|
+
if (!k) return console.error("Could not find the original declaration");
|
251
|
+
const { index: F } = k;
|
252
252
|
let d = !1;
|
253
253
|
const C = setTimeout(() => d = !0, 5e3);
|
254
254
|
let i = 0, f = !1, h = 0;
|
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.60",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -29,6 +29,6 @@
|
|
29
29
|
}
|
30
30
|
},
|
31
31
|
"dependencies": {
|
32
|
-
"@salty-css/core": "^0.0.1-alpha.
|
32
|
+
"@salty-css/core": "^0.0.1-alpha.60"
|
33
33
|
}
|
34
34
|
}
|