@salty-css/vite 0.0.1-alpha.14 → 0.0.1-alpha.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. package/README.md +1 -1
  2. package/index.cjs +11 -11
  3. package/index.js +112 -117
  4. package/package.json +4 -1
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  ### Initial requirements
6
6
 
7
7
  1. Add `saltyPlugin` to vite or webpack config from `@salty-css/vite` or `@salty-css/webpack`
8
- 2. Create `salty-config.ts` to the root of your project
8
+ 2. Create `salty.config.ts` to the root of your project
9
9
  3. Import global styles to any regular .css file from `saltygen/index.css` (does not exist during first run, cli command coming later)
10
10
  4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
11
11
 
package/index.cjs CHANGED
@@ -1,18 +1,18 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const J=require("esbuild"),K=require("winston"),L=require("child_process"),u=require("path"),d=require("fs"),G=require("fs/promises");function R(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(s,e,n.get?n:{enumerable:!0,get:()=>t[e]})}}return s.default=t,Object.freeze(s)}const Z=R(J),N=R(K),q=t=>String.fromCharCode(t+(t>25?39:97)),U=(t,s)=>{let e="",n;for(n=Math.abs(t);n>52;n=n/52|0)e=q(n%52)+e;return e=q(n%52)+e,e.length<s?e=e.padStart(s,"a"):e.length>s&&(e=e.slice(-s)),e},X=(t,s)=>{let e=s.length;for(;e;)t=t*33^s.charCodeAt(--e);return t},_=(t,s=3)=>{const e=X(5381,JSON.stringify(t))>>>0;return U(e,s)};function V(t){return t?typeof t!="string"?String(t):t.replace(/\s/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(s,e)=>(e>0?"-":"")+s.toLowerCase()):""}const Y=(t,s)=>{if(typeof t!="string")return{result:t};if(!s)return{result:t};const e=[];return Object.values(s).forEach(n=>{const{pattern:o,transform:y}=n;t=t.replace(o,$=>{const{value:a,css:f}=y($);return f&&e.push(f),a})}),{result:t,additionalCss:e}},I=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${V(n[1].replaceAll(".","-"))})`)}:{result:t},D=(t,s,e,n)=>{const o=[],y=Object.entries(t).reduce((a,[f,r])=>{const i=f.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(i==="variants")return Object.entries(r).forEach(([g,c])=>{c&&Object.entries(c).forEach(([m,l])=>{if(!l)return;const F=`${s}.${g}-${m}`,P=D(l,F);o.push(P)})}),a;if(i==="defaultVariants")return a;if(i==="compoundVariants")return r.forEach(g=>{const{css:c,...m}=g,l=Object.entries(m).reduce((P,[x,k])=>`${P}.${x}-${k}`,s),F=D(c,l);o.push(F)}),a;if(i.startsWith("@")){const g=D(r,s),c=`${i} {
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("esbuild"),z=require("child_process"),u=require("path"),m=require("fs"),J=require("fs/promises");function K(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const e in t)if(e!=="default"){const n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(s,e,n.get?n:{enumerable:!0,get:()=>t[e]})}}return s.default=t,Object.freeze(s)}const R=K(W),M=t=>String.fromCharCode(t+(t>25?39:97)),G=(t,s)=>{let e="",n;for(n=Math.abs(t);n>52;n=n/52|0)e=M(n%52)+e;return e=M(n%52)+e,e.length<s?e=e.padStart(s,"a"):e.length>s&&(e=e.slice(-s)),e},L=(t,s)=>{let e=s.length;for(;e;)t=t*33^s.charCodeAt(--e);return t},E=(t,s=3)=>{const e=L(5381,JSON.stringify(t))>>>0;return G(e,s)};function N(t){return t?typeof t!="string"?N(String(t)):t.replace(/\s/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(s,e)=>(e>0?"-":"")+s.toLowerCase()):""}const U=(t,s)=>{if(typeof t!="string")return{result:t};if(!s)return{result:t};const e=[];return Object.values(s).forEach(n=>{const{pattern:r,transform:y}=n;t=t.replace(r,$=>{const{value:a,css:f}=y($);return f&&e.push(f),a})}),{result:t,additionalCss:e}},q=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${N(n[1].replaceAll(".","-"))})`)}:{result:t},D=(t,s,e,n)=>{if(!t)return"";const r=[],y=Object.entries(t).reduce((a,[f,o])=>{const i=f.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return a;if(i==="variants")return Object.entries(o).forEach(([g,c])=>{c&&Object.entries(c).forEach(([d,l])=>{if(!l)return;const F=`${s}.${g}-${d}`,P=D(l,F);r.push(P)})}),a;if(i==="defaultVariants")return a;if(i==="compoundVariants")return o.forEach(g=>{const{css:c,...d}=g,l=Object.entries(d).reduce((P,[x,k])=>`${P}.${x}-${k}`,s),F=D(c,l);r.push(F)}),a;if(i.startsWith("@")){const g=D(o,s),c=`${i} {
2
2
  ${g.replace(`
3
3
  `,`
4
4
  `)}
5
- }`;return o.push(c),a}const h=f.includes("&")?i.replace("&",s):i.startsWith(":")?`${s}${i}`:`${s} ${i}`,C=D(r,h);return o.push(C),a}const p=i.startsWith("-")?i:V(i),b=(h,C=";")=>a=`${a}${h}${C}`,j=h=>b(`${p}:${h}`);if(typeof r=="number")return j(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:w}={},O=function*(){yield I(r),yield Y(r,w)}();for(const{result:h,additionalCss:C=[]}of O)r=h,C.forEach(g=>{const c=D(g,"");b(c,"")});return j(r)},"");if(!y)return o.join(`
6
- `);if(!s)return y;let $="";return $=`${s} { ${y} }`,[$,...o].join(`
7
- `)},z=(t,s=[])=>{const e=[],n={};if(Object.entries(t).forEach(([o,y])=>{if(typeof y=="object"){if(!y)return;const $=o.trim(),a=z(y,[...s,$]);e.push(a)}else n[o]=y}),Object.keys(n).length){const o=s.map(V).join("-"),y=D(n,`.${o}`);e.push(y)}return e.join(`
8
- `)};N.createLogger({level:"info",format:N.format.combine(N.format.colorize(),N.format.cli()),transports:[new N.transports.Console({})]});const E=t=>u.join(t,"./saltygen"),Q=["salty","css","styles","styled"],v=(t=[])=>new RegExp(`\\.(${[...Q,...t].join("|")})\\.`),T=(t,s=[])=>v(s).test(t),tt=async t=>{const s=E(t),e=u.join(t,"salty-config.ts"),n=u.join(s,"salty-config.js");await Z.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const o=Date.now(),{config:y}=await import(`${n}?t=${o}`);return y},B=async t=>{const s=await tt(t),e=new Set,n=(g,c=[])=>g?Object.entries(g).flatMap(([m,l])=>{if(!l)return;if(typeof l=="object")return n(l,[...c,m]);const F=[...c,m].join(".");e.add(`"${F}"`);const P=[...c.map(V),V(m)].join("-"),{result:x}=I(l);return`--${P}: ${x};`}):[],o=g=>g?Object.entries(g).flatMap(([c,m])=>{const l=n(m);return c==="base"?l.join(""):`${c} { ${l.join("")} }`}):[],y=g=>g?Object.entries(g).flatMap(([c,m])=>Object.entries(m).flatMap(([l,F])=>{const P=n(F,[c]),x=`.${c}-${l}, [data-${c}="${l}"]`,k=P.join("");return`${x} { ${k} }`})):[],$=n(s.variables),a=o(s.responsiveVariables),f=y(s.conditionalVariables),r=E(t),i=u.join(r,"css/variables.css"),p=`:root { ${$.join("")} ${a.join("")} } ${f.join("")}`;d.writeFileSync(i,p);const b=u.join(r,"types/css-tokens.d.ts"),w=`type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;d.writeFileSync(b,w);const S=u.join(r,"css/global.css"),O=D(s.global,"");d.writeFileSync(S,O);const h=u.join(r,"css/templates.css"),C=z(s.templates);d.writeFileSync(h,C)},A=async(t,s)=>{const e=_(t),n=u.join(s,"js",e+".js");await Z.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const o=Date.now();return await import(`${n}?t=${o}`)},M=async t=>{const s=E(t),e=u.join(s,"salty-config.js"),{config:n}=await import(e);return n},st=async t=>{try{const s=[],e=[],n=E(t),o=u.join(n,"index.css");(()=>{d.existsSync(n)&&L.execSync("rm -rf "+n),d.mkdirSync(n),d.mkdirSync(u.join(n,"css")),d.mkdirSync(u.join(n,"types"))})(),await B(t);const $=await M(t);async function a(p,b){const j=d.statSync(p);if(j.isDirectory()){const w=d.readdirSync(p);await Promise.all(w.map(S=>a(u.join(p,S),u.join(b,S))))}else if(j.isFile()&&T(p)){const S=await A(p,n),O=[];Object.entries(S).forEach(([c,m])=>{if(m.isKeyframes&&m.css){const k=`${m.animationName}.css`,H=`css/${k}`,W=u.join(n,H);s.push(k),d.writeFileSync(W,m.css);return}if(!m.generator)return;const l=m.generator._withBuildContext({name:c,config:$}),F=`${l.hash}-${l.priority}.css`;e[l.priority]||(e[l.priority]=[]),e[l.priority].push(F),O.push(F);const P=`css/${F}`,x=u.join(n,P);d.writeFileSync(x,l.css)});const h=O.map(c=>`@import url('./${c}');`).join(`
9
- `),C=_(p,6),g=u.join(n,`css/${C}.css`);d.writeFileSync(g,h)}}await a(t,n);const f=s.map(p=>`@import url('./css/${p}');`).join(`
5
+ }`;return r.push(c),a}const b=f.includes("&")?i.replace("&",s):i.startsWith(":")?`${s}${i}`:`${s} ${i}`,C=D(o,b);return r.push(C),a}const p=i.startsWith("-")?i:N(i),h=(b,C=";")=>a=`${a}${b}${C}`,j=b=>h(`${p}:${b}`);if(typeof o=="number")return j(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return a;const{modifiers:S}={},O=function*(){yield q(o),yield U(o,S)}();for(const{result:b,additionalCss:C=[]}of O)o=b,C.forEach(g=>{const c=D(g,"");h(c,"")});return j(o)},"");if(!y)return r.join(`
6
+ `);if(!s)return y;let $="";return $=`${s} { ${y} }`,[$,...r].join(`
7
+ `)},Z=(t,s=[])=>{if(!t)return"";const e=[],n={};if(Object.entries(t).forEach(([r,y])=>{if(typeof y=="object"){if(!y)return;const $=r.trim(),a=Z(y,[...s,$]);e.push(a)}else n[r]=y}),Object.keys(n).length){const r=s.map(N).join("-"),y=D(n,`.${r}`);e.push(y)}return e.join(`
8
+ `)},T=t=>u.join(t,"./saltygen"),X=["salty","css","styles","styled"],Y=(t=[])=>new RegExp(`\\.(${[...X,...t].join("|")})\\.`),V=(t,s=[])=>Y(s).test(t),Q=async t=>{const s=T(t),e=u.join(t,"salty.config.ts"),n=u.join(s,"salty.config.js");await R.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const r=Date.now(),{config:y}=await import(`${n}?t=${r}`);return y},I=async t=>{const s=await Q(t),e=new Set,n=(g,c=[])=>g?Object.entries(g).flatMap(([d,l])=>{if(!l)return;if(typeof l=="object")return n(l,[...c,d]);const F=[...c,d].join(".");e.add(`"${F}"`);const P=[...c.map(N),N(d)].join("-"),{result:x}=q(l);return`--${P}: ${x};`}):[],r=g=>g?Object.entries(g).flatMap(([c,d])=>{const l=n(d);return c==="base"?l.join(""):`${c} { ${l.join("")} }`}):[],y=g=>g?Object.entries(g).flatMap(([c,d])=>Object.entries(d).flatMap(([l,F])=>{const P=n(F,[c]),x=`.${c}-${l}, [data-${c}="${l}"]`,k=P.join("");return`${x} { ${k} }`})):[],$=n(s.variables),a=r(s.responsiveVariables),f=y(s.conditionalVariables),o=T(t),i=u.join(o,"css/variables.css"),p=`:root { ${$.join("")} ${a.join("")} } ${f.join("")}`;m.writeFileSync(i,p);const h=u.join(o,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;m.writeFileSync(h,S);const w=u.join(o,"css/global.css"),O=D(s.global,"");m.writeFileSync(w,O);const b=u.join(o,"css/templates.css"),C=Z(s.templates);m.writeFileSync(b,C)},_=async(t,s)=>{const e=E(t),n=u.join(s,"js",e+".js");await R.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const r=Date.now();return await import(`${n}?t=${r}`)},A=async t=>{const s=T(t),e=u.join(s,"salty.config.js"),{config:n}=await import(e);return n},v=async t=>{try{const s=[],e=[],n=T(t),r=u.join(n,"index.css");(()=>{m.existsSync(n)&&z.execSync("rm -rf "+n),m.mkdirSync(n),m.mkdirSync(u.join(n,"css")),m.mkdirSync(u.join(n,"types"))})(),await I(t);const $=await A(t);async function a(p,h){const j=m.statSync(p);if(j.isDirectory()){const S=m.readdirSync(p);await Promise.all(S.map(w=>a(u.join(p,w),u.join(h,w))))}else if(j.isFile()&&V(p)){const w=await _(p,n),O=[];Object.entries(w).forEach(([c,d])=>{if(d.isKeyframes&&d.css){const k=`${d.animationName}.css`,B=`css/${k}`,H=u.join(n,B);s.push(k),m.writeFileSync(H,d.css);return}if(!d.generator)return;const l=d.generator._withBuildContext({name:c,config:$}),F=`${l.hash}-${l.priority}.css`;e[l.priority]||(e[l.priority]=[]),e[l.priority].push(F),O.push(F);const P=`css/${F}`,x=u.join(n,P);m.writeFileSync(x,l.css)});const b=O.map(c=>`@import url('./${c}');`).join(`
9
+ `),C=E(p,6),g=u.join(n,`css/${C}.css`);m.writeFileSync(g,b)}}await a(t,n);const f=s.map(p=>`@import url('./css/${p}');`).join(`
10
10
  `);let i=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
11
11
 
12
12
  ${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
13
13
  `)}
14
- ${f}`;if($.importStrategy!=="component"){const p=e.flat().map(b=>`@import url('./css/${b}');`).join(`
15
- `);i+=p}d.writeFileSync(o,i)}catch(s){console.error(s)}},et=async(t,s)=>{try{const e=[],n=u.join(t,"./saltygen"),o=u.join(n,"index.css");if(T(s)){const $=await M(t),a=await A(s,n);Object.entries(a).forEach(([b,j])=>{if(!j.generator)return;const w=j.generator._withBuildContext({name:b,config:$}),S=`${w.hash}-${w.priority}.css`,O=`css/${S}`,h=u.join(n,O);e.push(S),d.writeFileSync(h,w.css)});const f=d.readFileSync(o,"utf8").split(`
16
- `),r=e.map(b=>`@import url('../saltygen/css/${b}');`),p=[...new Set([...f,...r])].join(`
17
- `);d.writeFileSync(o,p)}}catch(e){console.error(e)}},nt=async(t,s)=>{try{const e=u.join(t,"./saltygen");if(T(s)){const o=d.readFileSync(s,"utf8");o.replace(/^(?!export\s)const\s.*/gm,i=>`export ${i}`)!==o&&await G.writeFile(s,o);const $=await M(t),a=await A(s,e);let f=o;Object.entries(a).forEach(([i,p])=>{var h;if(p.isKeyframes){console.log("value",p);return}if(!p.generator)return;const b=p.generator._withBuildContext({name:i,config:$}),j=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!j)return console.error("Could not find the original declaration");const w=(h=j.at(1))==null?void 0:h.trim(),S=`${i} = styled(${w}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`,O=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");f=f.replace(O,S)});const r=_(s,6);return $.importStrategy==="component"&&(f=`import '../../saltygen/css/${r}.css';
18
- ${f}`),f=f.replace("{ styled }","{ styledClient as styled }"),f=f.replace("@salty-css/react/styled","@salty-css/react/styled-client"),f}}catch(e){console.error(e)}},ot=t=>({name:"stylegen",buildStart:()=>st(t),load:async s=>{if(T(s))return await nt(t,s)},watchChange:{handler:async s=>{T(s)&&await et(t,s),s.includes("salty-config")&&await B(t)}}});exports.saltyPlugin=ot;
14
+ ${f}`;if($.importStrategy!=="component"){const p=e.flat().map(h=>`@import url('./css/${h}');`).join(`
15
+ `);i+=p}m.writeFileSync(r,i)}catch(s){console.error(s)}},tt=async(t,s)=>{try{const e=[],n=u.join(t,"./saltygen"),r=u.join(n,"index.css");if(V(s)){const $=await A(t),a=await _(s,n);Object.entries(a).forEach(([h,j])=>{if(!j.generator)return;const S=j.generator._withBuildContext({name:h,config:$}),w=`${S.hash}-${S.priority}.css`,O=`css/${w}`,b=u.join(n,O);e.push(w),m.writeFileSync(b,S.css)});const f=m.readFileSync(r,"utf8").split(`
16
+ `),o=e.map(h=>`@import url('../saltygen/css/${h}');`),p=[...new Set([...f,...o])].join(`
17
+ `);m.writeFileSync(r,p)}}catch(e){console.error(e)}},st=async(t,s)=>{try{const e=u.join(t,"./saltygen");if(V(s)){const r=m.readFileSync(s,"utf8");r.replace(/^(?!export\s)const\s.*/gm,i=>`export ${i}`)!==r&&await J.writeFile(s,r);const $=await A(t),a=await _(s,e);let f=r;Object.entries(a).forEach(([i,p])=>{var b;if(p.isKeyframes){console.log("value",p);return}if(!p.generator)return;const h=p.generator._withBuildContext({name:i,config:$}),j=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!j)return console.error("Could not find the original declaration");const S=(b=j.at(1))==null?void 0:b.trim(),w=`${i} = styled(${S}, "${h.classNames}", "${h._callerName}", ${JSON.stringify(h.props)});`,O=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");f=f.replace(O,w)});const o=E(s,6);return $.importStrategy==="component"&&(f=`import '../../saltygen/css/${o}.css';
18
+ ${f}`),f=f.replace("{ styled }","{ styledClient as styled }"),f=f.replace("@salty-css/react/styled","@salty-css/react/styled-client"),f}}catch(e){console.error(e)}},et=t=>({name:"stylegen",buildStart:()=>v(t),load:async s=>{if(V(s))return await st(t,s)},watchChange:{handler:async s=>{V(s)&&await tt(t,s),s.includes("salty.config")&&await I(t)}}});exports.saltyPlugin=et;
package/index.js CHANGED
@@ -1,111 +1,106 @@
1
- import * as I from "esbuild";
2
- import * as P from "winston";
3
- import { execSync as L } from "child_process";
4
- import { join as y } from "path";
5
- import { writeFileSync as C, existsSync as q, mkdirSync as A, statSync as G, readdirSync as U, readFileSync as B } from "fs";
6
- import { writeFile as X } from "fs/promises";
7
- const Z = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Y = (t, s) => {
1
+ import * as Z from "esbuild";
2
+ import { execSync as q } from "child_process";
3
+ import { join as u } from "path";
4
+ import { writeFileSync as C, existsSync as z, mkdirSync as T, statSync as G, readdirSync as L, readFileSync as I } from "fs";
5
+ import { writeFile as U } from "fs/promises";
6
+ const _ = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), X = (t, s) => {
8
7
  let e = "", n;
9
- for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = Z(n % 52) + e;
10
- return e = Z(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
11
- }, Q = (t, s) => {
8
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = _(n % 52) + e;
9
+ return e = _(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
10
+ }, Y = (t, s) => {
12
11
  let e = s.length;
13
12
  for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
14
13
  return t;
15
- }, R = (t, s = 3) => {
16
- const e = Q(5381, JSON.stringify(t)) >>> 0;
17
- return Y(e, s);
14
+ }, A = (t, s = 3) => {
15
+ const e = Y(5381, JSON.stringify(t)) >>> 0;
16
+ return X(e, s);
18
17
  };
19
- function k(t) {
20
- return t ? typeof t != "string" ? String(t) : t.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (s, e) => (e > 0 ? "-" : "") + s.toLowerCase()) : "";
18
+ function V(t) {
19
+ return t ? typeof t != "string" ? V(String(t)) : t.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (s, e) => (e > 0 ? "-" : "") + s.toLowerCase()) : "";
21
20
  }
22
- const v = (t, s) => {
21
+ const Q = (t, s) => {
23
22
  if (typeof t != "string") return { result: t };
24
23
  if (!s) return { result: t };
25
24
  const e = [];
26
25
  return Object.values(s).forEach((n) => {
27
- const { pattern: o, transform: u } = n;
28
- t = t.replace(o, ($) => {
29
- const { value: a, css: f } = u($);
26
+ const { pattern: r, transform: y } = n;
27
+ t = t.replace(r, ($) => {
28
+ const { value: a, css: f } = y($);
30
29
  return f && e.push(f), a;
31
30
  });
32
31
  }), { result: t, additionalCss: e };
33
- }, H = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${k(n[1].replaceAll(".", "-"))})`) } : { result: t }, V = (t, s, e, n) => {
34
- const o = [], u = Object.entries(t).reduce((a, [f, r]) => {
32
+ }, B = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${V(n[1].replaceAll(".", "-"))})`) } : { result: t }, O = (t, s, e, n) => {
33
+ if (!t) return "";
34
+ const r = [], y = Object.entries(t).reduce((a, [f, o]) => {
35
35
  const i = f.trim();
36
- if (typeof r == "function" && (r = r()), typeof r == "object") {
37
- if (!r) return a;
36
+ if (typeof o == "function" && (o = o()), typeof o == "object") {
37
+ if (!o) return a;
38
38
  if (i === "variants")
39
- return Object.entries(r).forEach(([g, c]) => {
39
+ return Object.entries(o).forEach(([g, c]) => {
40
40
  c && Object.entries(c).forEach(([m, l]) => {
41
41
  if (!l) return;
42
- const S = `${s}.${g}-${m}`, D = V(l, S);
43
- o.push(D);
42
+ const S = `${s}.${g}-${m}`, D = O(l, S);
43
+ r.push(D);
44
44
  });
45
45
  }), a;
46
46
  if (i === "defaultVariants")
47
47
  return a;
48
48
  if (i === "compoundVariants")
49
- return r.forEach((g) => {
50
- const { css: c, ...m } = g, l = Object.entries(m).reduce((D, [N, O]) => `${D}.${N}-${O}`, s), S = V(c, l);
51
- o.push(S);
49
+ return o.forEach((g) => {
50
+ const { css: c, ...m } = g, l = Object.entries(m).reduce((D, [N, P]) => `${D}.${N}-${P}`, s), S = O(c, l);
51
+ r.push(S);
52
52
  }), a;
53
53
  if (i.startsWith("@")) {
54
- const g = V(r, s), c = `${i} {
54
+ const g = O(o, s), c = `${i} {
55
55
  ${g.replace(`
56
56
  `, `
57
57
  `)}
58
58
  }`;
59
- return o.push(c), a;
59
+ return r.push(c), a;
60
60
  }
61
- const d = f.includes("&") ? i.replace("&", s) : i.startsWith(":") ? `${s}${i}` : `${s} ${i}`, x = V(r, d);
62
- return o.push(x), a;
61
+ const d = f.includes("&") ? i.replace("&", s) : i.startsWith(":") ? `${s}${i}` : `${s} ${i}`, x = O(o, d);
62
+ return r.push(x), a;
63
63
  }
64
- const p = i.startsWith("-") ? i : k(i), h = (d, x = ";") => a = `${a}${d}${x}`, b = (d) => h(`${p}:${d}`);
65
- if (typeof r == "number") return b(r);
66
- if (typeof r != "string")
67
- if ("toString" in r) r = r.toString();
64
+ const p = i.startsWith("-") ? i : V(i), h = (d, x = ";") => a = `${a}${d}${x}`, b = (d) => h(`${p}:${d}`);
65
+ if (typeof o == "number") return b(o);
66
+ if (typeof o != "string")
67
+ if ("toString" in o) o = o.toString();
68
68
  else return a;
69
69
  const { modifiers: j } = {}, F = function* () {
70
- yield H(r), yield v(r, j);
70
+ yield B(o), yield Q(o, j);
71
71
  }();
72
72
  for (const { result: d, additionalCss: x = [] } of F)
73
- r = d, x.forEach((g) => {
74
- const c = V(g, "");
73
+ o = d, x.forEach((g) => {
74
+ const c = O(g, "");
75
75
  h(c, "");
76
76
  });
77
- return b(r);
77
+ return b(o);
78
78
  }, "");
79
- if (!u) return o.join(`
79
+ if (!y) return r.join(`
80
80
  `);
81
- if (!s) return u;
81
+ if (!s) return y;
82
82
  let $ = "";
83
- return $ = `${s} { ${u} }`, [$, ...o].join(`
83
+ return $ = `${s} { ${y} }`, [$, ...r].join(`
84
84
  `);
85
- }, W = (t, s = []) => {
85
+ }, H = (t, s = []) => {
86
+ if (!t) return "";
86
87
  const e = [], n = {};
87
- if (Object.entries(t).forEach(([o, u]) => {
88
- if (typeof u == "object") {
89
- if (!u) return;
90
- const $ = o.trim(), a = W(u, [...s, $]);
88
+ if (Object.entries(t).forEach(([r, y]) => {
89
+ if (typeof y == "object") {
90
+ if (!y) return;
91
+ const $ = r.trim(), a = H(y, [...s, $]);
91
92
  e.push(a);
92
93
  } else
93
- n[o] = u;
94
+ n[r] = y;
94
95
  }), Object.keys(n).length) {
95
- const o = s.map(k).join("-"), u = V(n, `.${o}`);
96
- e.push(u);
96
+ const r = s.map(V).join("-"), y = O(n, `.${r}`);
97
+ e.push(y);
97
98
  }
98
99
  return e.join(`
99
100
  `);
100
- };
101
- P.createLogger({
102
- level: "info",
103
- format: P.format.combine(P.format.colorize(), P.format.cli()),
104
- transports: [new P.transports.Console({})]
105
- });
106
- const T = (t) => y(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"], st = (t = []) => new RegExp(`\\.(${[...tt, ...t].join("|")})\\.`), E = (t, s = []) => st(s).test(t), et = async (t) => {
107
- const s = T(t), e = y(t, "salty-config.ts"), n = y(s, "salty-config.js");
108
- await I.build({
101
+ }, E = (t) => u(t, "./saltygen"), v = ["salty", "css", "styles", "styled"], tt = (t = []) => new RegExp(`\\.(${[...v, ...t].join("|")})\\.`), k = (t, s = []) => tt(s).test(t), st = async (t) => {
102
+ const s = E(t), e = u(t, "salty.config.ts"), n = u(s, "salty.config.js");
103
+ await Z.build({
109
104
  entryPoints: [e],
110
105
  minify: !0,
111
106
  treeShaking: !0,
@@ -114,33 +109,33 @@ const T = (t) => y(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"],
114
109
  format: "esm",
115
110
  external: ["react"]
116
111
  });
117
- const o = Date.now(), { config: u } = await import(`${n}?t=${o}`);
118
- return u;
119
- }, z = async (t) => {
120
- const s = await et(t), e = /* @__PURE__ */ new Set(), n = (g, c = []) => g ? Object.entries(g).flatMap(([m, l]) => {
112
+ const r = Date.now(), { config: y } = await import(`${n}?t=${r}`);
113
+ return y;
114
+ }, W = async (t) => {
115
+ const s = await st(t), e = /* @__PURE__ */ new Set(), n = (g, c = []) => g ? Object.entries(g).flatMap(([m, l]) => {
121
116
  if (!l) return;
122
117
  if (typeof l == "object") return n(l, [...c, m]);
123
118
  const S = [...c, m].join(".");
124
119
  e.add(`"${S}"`);
125
- const D = [...c.map(k), k(m)].join("-"), { result: N } = H(l);
120
+ const D = [...c.map(V), V(m)].join("-"), { result: N } = B(l);
126
121
  return `--${D}: ${N};`;
127
- }) : [], o = (g) => g ? Object.entries(g).flatMap(([c, m]) => {
122
+ }) : [], r = (g) => g ? Object.entries(g).flatMap(([c, m]) => {
128
123
  const l = n(m);
129
124
  return c === "base" ? l.join("") : `${c} { ${l.join("")} }`;
130
- }) : [], u = (g) => g ? Object.entries(g).flatMap(([c, m]) => Object.entries(m).flatMap(([l, S]) => {
131
- const D = n(S, [c]), N = `.${c}-${l}, [data-${c}="${l}"]`, O = D.join("");
132
- return `${N} { ${O} }`;
133
- })) : [], $ = n(s.variables), a = o(s.responsiveVariables), f = u(s.conditionalVariables), r = T(t), i = y(r, "css/variables.css"), p = `:root { ${$.join("")} ${a.join("")} } ${f.join("")}`;
125
+ }) : [], y = (g) => g ? Object.entries(g).flatMap(([c, m]) => Object.entries(m).flatMap(([l, S]) => {
126
+ const D = n(S, [c]), N = `.${c}-${l}, [data-${c}="${l}"]`, P = D.join("");
127
+ return `${N} { ${P} }`;
128
+ })) : [], $ = n(s.variables), a = r(s.responsiveVariables), f = y(s.conditionalVariables), o = E(t), i = u(o, "css/variables.css"), p = `:root { ${$.join("")} ${a.join("")} } ${f.join("")}`;
134
129
  C(i, p);
135
- const h = y(r, "types/css-tokens.d.ts"), j = `type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
130
+ const h = u(o, "types/css-tokens.d.ts"), j = `type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
136
131
  C(h, j);
137
- const w = y(r, "css/global.css"), F = V(s.global, "");
132
+ const w = u(o, "css/global.css"), F = O(s.global, "");
138
133
  C(w, F);
139
- const d = y(r, "css/templates.css"), x = W(s.templates);
134
+ const d = u(o, "css/templates.css"), x = H(s.templates);
140
135
  C(d, x);
141
- }, M = async (t, s) => {
142
- const e = R(t), n = y(s, "js", e + ".js");
143
- await I.build({
136
+ }, R = async (t, s) => {
137
+ const e = A(t), n = u(s, "js", e + ".js");
138
+ await Z.build({
144
139
  entryPoints: [t],
145
140
  minify: !0,
146
141
  treeShaking: !0,
@@ -151,29 +146,29 @@ const T = (t) => y(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"],
151
146
  keepNames: !0,
152
147
  external: ["react"]
153
148
  });
154
- const o = Date.now();
155
- return await import(`${n}?t=${o}`);
156
- }, _ = async (t) => {
157
- const s = T(t), e = y(s, "salty-config.js"), { config: n } = await import(e);
149
+ const r = Date.now();
150
+ return await import(`${n}?t=${r}`);
151
+ }, M = async (t) => {
152
+ const s = E(t), e = u(s, "salty.config.js"), { config: n } = await import(e);
158
153
  return n;
159
- }, nt = async (t) => {
154
+ }, et = async (t) => {
160
155
  try {
161
- const s = [], e = [], n = T(t), o = y(n, "index.css");
156
+ const s = [], e = [], n = E(t), r = u(n, "index.css");
162
157
  (() => {
163
- q(n) && L("rm -rf " + n), A(n), A(y(n, "css")), A(y(n, "types"));
164
- })(), await z(t);
165
- const $ = await _(t);
158
+ z(n) && q("rm -rf " + n), T(n), T(u(n, "css")), T(u(n, "types"));
159
+ })(), await W(t);
160
+ const $ = await M(t);
166
161
  async function a(p, h) {
167
162
  const b = G(p);
168
163
  if (b.isDirectory()) {
169
- const j = U(p);
170
- await Promise.all(j.map((w) => a(y(p, w), y(h, w))));
171
- } else if (b.isFile() && E(p)) {
172
- const w = await M(p, n), F = [];
164
+ const j = L(p);
165
+ await Promise.all(j.map((w) => a(u(p, w), u(h, w))));
166
+ } else if (b.isFile() && k(p)) {
167
+ const w = await R(p, n), F = [];
173
168
  Object.entries(w).forEach(([c, m]) => {
174
169
  if (m.isKeyframes && m.css) {
175
- const O = `${m.animationName}.css`, J = `css/${O}`, K = y(n, J);
176
- s.push(O), C(K, m.css);
170
+ const P = `${m.animationName}.css`, J = `css/${P}`, K = u(n, J);
171
+ s.push(P), C(K, m.css);
177
172
  return;
178
173
  }
179
174
  if (!m.generator) return;
@@ -182,11 +177,11 @@ const T = (t) => y(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"],
182
177
  config: $
183
178
  }), S = `${l.hash}-${l.priority}.css`;
184
179
  e[l.priority] || (e[l.priority] = []), e[l.priority].push(S), F.push(S);
185
- const D = `css/${S}`, N = y(n, D);
180
+ const D = `css/${S}`, N = u(n, D);
186
181
  C(N, l.css);
187
182
  });
188
183
  const d = F.map((c) => `@import url('./${c}');`).join(`
189
- `), x = R(p, 6), g = y(n, `css/${x}.css`);
184
+ `), x = A(p, 6), g = u(n, `css/${x}.css`);
190
185
  C(g, d);
191
186
  }
192
187
  }
@@ -203,39 +198,39 @@ ${f}`;
203
198
  `);
204
199
  i += p;
205
200
  }
206
- C(o, i);
201
+ C(r, i);
207
202
  } catch (s) {
208
203
  console.error(s);
209
204
  }
210
- }, ot = async (t, s) => {
205
+ }, nt = async (t, s) => {
211
206
  try {
212
- const e = [], n = y(t, "./saltygen"), o = y(n, "index.css");
213
- if (E(s)) {
214
- const $ = await _(t), a = await M(s, n);
207
+ const e = [], n = u(t, "./saltygen"), r = u(n, "index.css");
208
+ if (k(s)) {
209
+ const $ = await M(t), a = await R(s, n);
215
210
  Object.entries(a).forEach(([h, b]) => {
216
211
  if (!b.generator) return;
217
212
  const j = b.generator._withBuildContext({
218
213
  name: h,
219
214
  config: $
220
- }), w = `${j.hash}-${j.priority}.css`, F = `css/${w}`, d = y(n, F);
215
+ }), w = `${j.hash}-${j.priority}.css`, F = `css/${w}`, d = u(n, F);
221
216
  e.push(w), C(d, j.css);
222
217
  });
223
- const f = B(o, "utf8").split(`
224
- `), r = e.map((h) => `@import url('../saltygen/css/${h}');`), p = [.../* @__PURE__ */ new Set([...f, ...r])].join(`
218
+ const f = I(r, "utf8").split(`
219
+ `), o = e.map((h) => `@import url('../saltygen/css/${h}');`), p = [.../* @__PURE__ */ new Set([...f, ...o])].join(`
225
220
  `);
226
- C(o, p);
221
+ C(r, p);
227
222
  }
228
223
  } catch (e) {
229
224
  console.error(e);
230
225
  }
231
226
  }, rt = async (t, s) => {
232
227
  try {
233
- const e = y(t, "./saltygen");
234
- if (E(s)) {
235
- const o = B(s, "utf8");
236
- o.replace(/^(?!export\s)const\s.*/gm, (i) => `export ${i}`) !== o && await X(s, o);
237
- const $ = await _(t), a = await M(s, e);
238
- let f = o;
228
+ const e = u(t, "./saltygen");
229
+ if (k(s)) {
230
+ const r = I(s, "utf8");
231
+ r.replace(/^(?!export\s)const\s.*/gm, (i) => `export ${i}`) !== r && await U(s, r);
232
+ const $ = await M(t), a = await R(s, e);
233
+ let f = r;
239
234
  Object.entries(a).forEach(([i, p]) => {
240
235
  var d;
241
236
  if (p.isKeyframes) {
@@ -246,32 +241,32 @@ ${f}`;
246
241
  const h = p.generator._withBuildContext({
247
242
  name: i,
248
243
  config: $
249
- }), b = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
244
+ }), b = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
250
245
  if (!b)
251
246
  return console.error("Could not find the original declaration");
252
247
  const j = (d = b.at(1)) == null ? void 0 : d.trim(), w = `${i} = styled(${j}, "${h.classNames}", "${h._callerName}", ${JSON.stringify(h.props)});`, F = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
253
248
  f = f.replace(F, w);
254
249
  });
255
- const r = R(s, 6);
256
- return $.importStrategy === "component" && (f = `import '../../saltygen/css/${r}.css';
250
+ const o = A(s, 6);
251
+ return $.importStrategy === "component" && (f = `import '../../saltygen/css/${o}.css';
257
252
  ${f}`), f = f.replace("{ styled }", "{ styledClient as styled }"), f = f.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), f;
258
253
  }
259
254
  } catch (e) {
260
255
  console.error(e);
261
256
  }
262
- }, ft = (t) => ({
257
+ }, lt = (t) => ({
263
258
  name: "stylegen",
264
- buildStart: () => nt(t),
259
+ buildStart: () => et(t),
265
260
  load: async (s) => {
266
- if (E(s))
261
+ if (k(s))
267
262
  return await rt(t, s);
268
263
  },
269
264
  watchChange: {
270
265
  handler: async (s) => {
271
- E(s) && await ot(t, s), s.includes("salty-config") && await z(t);
266
+ k(s) && await nt(t, s), s.includes("salty.config") && await W(t);
272
267
  }
273
268
  }
274
269
  });
275
270
  export {
276
- ft as saltyPlugin
271
+ lt as saltyPlugin
277
272
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.14",
3
+ "version": "0.0.1-alpha.15",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -27,5 +27,8 @@
27
27
  "import": "./index.js",
28
28
  "require": "./index.cjs"
29
29
  }
30
+ },
31
+ "peerDependencies": {
32
+ "@salty-css/core": ">=0.0.1-alpha.14"
30
33
  }
31
34
  }