@salty-css/webpack 0.0.1-alpha.13 → 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 +7 -7
  3. package/index.js +105 -110
  4. package/package.json +5 -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,15 +1,15 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("path"),z=require("esbuild"),H=require("winston"),L=require("child_process"),m=require("fs");require("fs/promises");function A(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 _=A(z),T=A(H),x=t=>String.fromCharCode(t+(t>25?39:97)),B=(t,s)=>{let e="",n;for(n=Math.abs(t);n>52;n=n/52|0)e=x(n%52)+e;return e=x(n%52)+e,e.length<s?e=e.padStart(s,"a"):e.length>s&&(e=e.slice(-s)),e},G=(t,s)=>{let e=s.length;for(;e;)t=t*33^s.charCodeAt(--e);return t},M=(t,s=3)=>{const e=G(5381,JSON.stringify(t))>>>0;return B(e,s)};function N(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 J=(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:a}=n;t=t.replace(o,b=>{const{value:l,css:$}=a(b);return $&&e.push($),l})}),{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},k=(t,s,e,n)=>{const o=[],a=Object.entries(t).reduce((l,[$,r])=>{const y=$.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return l;if(y==="variants")return Object.entries(r).forEach(([f,i])=>{i&&Object.entries(i).forEach(([p,c])=>{if(!c)return;const h=`${s}.${f}-${p}`,S=k(c,h);o.push(S)})}),l;if(y==="defaultVariants")return l;if(y==="compoundVariants")return r.forEach(f=>{const{css:i,...p}=f,c=Object.entries(p).reduce((S,[P,V])=>`${S}.${P}-${V}`,s),h=k(i,c);o.push(h)}),l;if(y.startsWith("@")){const f=k(r,s),i=`${y} {
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("path"),I=require("esbuild"),W=require("child_process"),m=require("fs");require("fs/promises");function H(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 x=H(I),E=t=>String.fromCharCode(t+(t>25?39:97)),z=(t,s)=>{let e="",n;for(n=Math.abs(t);n>52;n=n/52|0)e=E(n%52)+e;return e=E(n%52)+e,e.length<s?e=e.padStart(s,"a"):e.length>s&&(e=e.slice(-s)),e},B=(t,s)=>{let e=s.length;for(;e;)t=t*33^s.charCodeAt(--e);return t},A=(t,s=3)=>{const e=B(5381,JSON.stringify(t))>>>0;return z(e,s)};function V(t){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()):""}const G=(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:a}=n;t=t.replace(r,b=>{const{value:l,css:$}=a(b);return $&&e.push($),l})}),{result:t,additionalCss:e}},M=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${V(n[1].replaceAll(".","-"))})`)}:{result:t},k=(t,s,e,n)=>{if(!t)return"";const r=[],a=Object.entries(t).reduce((l,[$,o])=>{const y=$.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return l;if(y==="variants")return Object.entries(o).forEach(([f,i])=>{i&&Object.entries(i).forEach(([p,c])=>{if(!c)return;const h=`${s}.${f}-${p}`,S=k(c,h);r.push(S)})}),l;if(y==="defaultVariants")return l;if(y==="compoundVariants")return o.forEach(f=>{const{css:i,...p}=f,c=Object.entries(p).reduce((S,[P,T])=>`${S}.${P}-${T}`,s),h=k(i,c);r.push(h)}),l;if(y.startsWith("@")){const f=k(o,s),i=`${y} {
2
2
  ${f.replace(`
3
3
  `,`
4
4
  `)}
5
- }`;return o.push(i),l}const j=$.includes("&")?y.replace("&",s):y.startsWith(":")?`${s}${y}`:`${s} ${y}`,d=k(r,j);return o.push(d),l}const g=y.startsWith("-")?y:N(y),w=(j,d=";")=>l=`${l}${j}${d}`,O=j=>w(`${g}:${j}`);if(typeof r=="number")return O(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return l;const{modifiers:C}={},D=function*(){yield q(r),yield J(r,C)}();for(const{result:j,additionalCss:d=[]}of D)r=j,d.forEach(f=>{const i=k(f,"");w(i,"")});return O(r)},"");if(!a)return o.join(`
6
- `);if(!s)return a;let b="";return b=`${s} { ${a} }`,[b,...o].join(`
7
- `)},Z=(t,s=[])=>{const e=[],n={};if(Object.entries(t).forEach(([o,a])=>{if(typeof a=="object"){if(!a)return;const b=o.trim(),l=Z(a,[...s,b]);e.push(l)}else n[o]=a}),Object.keys(n).length){const o=s.map(N).join("-"),a=k(n,`.${o}`);e.push(a)}return e.join(`
8
- `)};T.createLogger({level:"info",format:T.format.combine(T.format.colorize(),T.format.cli()),transports:[new T.transports.Console({})]});const E=t=>u.join(t,"./saltygen"),K=["salty","css","styles","styled"],R=(t=[])=>new RegExp(`\\.(${[...K,...t].join("|")})\\.`),U=(t,s=[])=>R(s).test(t),X=async t=>{const s=E(t),e=u.join(t,"salty-config.ts"),n=u.join(s,"salty-config.js");await _.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const o=Date.now(),{config:a}=await import(`${n}?t=${o}`);return a},Y=async t=>{const s=await X(t),e=new Set,n=(f,i=[])=>f?Object.entries(f).flatMap(([p,c])=>{if(!c)return;if(typeof c=="object")return n(c,[...i,p]);const h=[...i,p].join(".");e.add(`"${h}"`);const S=[...i.map(N),N(p)].join("-"),{result:P}=q(c);return`--${S}: ${P};`}):[],o=f=>f?Object.entries(f).flatMap(([i,p])=>{const c=n(p);return i==="base"?c.join(""):`${i} { ${c.join("")} }`}):[],a=f=>f?Object.entries(f).flatMap(([i,p])=>Object.entries(p).flatMap(([c,h])=>{const S=n(h,[i]),P=`.${i}-${c}, [data-${i}="${c}"]`,V=S.join("");return`${P} { ${V} }`})):[],b=n(s.variables),l=o(s.responsiveVariables),$=a(s.conditionalVariables),r=E(t),y=u.join(r,"css/variables.css"),g=`:root { ${b.join("")} ${l.join("")} } ${$.join("")}`;m.writeFileSync(y,g);const w=u.join(r,"types/css-tokens.d.ts"),C=`type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;m.writeFileSync(w,C);const F=u.join(r,"css/global.css"),D=k(s.global,"");m.writeFileSync(F,D);const j=u.join(r,"css/templates.css"),d=Z(s.templates);m.writeFileSync(j,d)},Q=async(t,s)=>{const e=M(t),n=u.join(s,"js",e+".js");await _.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}`)},v=async t=>{const s=E(t),e=u.join(s,"salty-config.js"),{config:n}=await import(e);return n},tt=async t=>{try{const s=[],e=[],n=E(t),o=u.join(n,"index.css");(()=>{m.existsSync(n)&&L.execSync("rm -rf "+n),m.mkdirSync(n),m.mkdirSync(u.join(n,"css")),m.mkdirSync(u.join(n,"types"))})(),await Y(t);const b=await v(t);async function l(g,w){const O=m.statSync(g);if(O.isDirectory()){const C=m.readdirSync(g);await Promise.all(C.map(F=>l(u.join(g,F),u.join(w,F))))}else if(O.isFile()&&U(g)){const F=await Q(g,n),D=[];Object.entries(F).forEach(([i,p])=>{if(p.isKeyframes&&p.css){const V=`${p.animationName}.css`,I=`css/${V}`,W=u.join(n,I);s.push(V),m.writeFileSync(W,p.css);return}if(!p.generator)return;const c=p.generator._withBuildContext({name:i,config:b}),h=`${c.hash}-${c.priority}.css`;e[c.priority]||(e[c.priority]=[]),e[c.priority].push(h),D.push(h);const S=`css/${h}`,P=u.join(n,S);m.writeFileSync(P,c.css)});const j=D.map(i=>`@import url('./${i}');`).join(`
9
- `),d=M(g,6),f=u.join(n,`css/${d}.css`);m.writeFileSync(f,j)}}await l(t,n);const $=s.map(g=>`@import url('./css/${g}');`).join(`
5
+ }`;return r.push(i),l}const j=$.includes("&")?y.replace("&",s):y.startsWith(":")?`${s}${y}`:`${s} ${y}`,d=k(o,j);return r.push(d),l}const g=y.startsWith("-")?y:V(y),w=(j,d=";")=>l=`${l}${j}${d}`,O=j=>w(`${g}:${j}`);if(typeof o=="number")return O(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return l;const{modifiers:C}={},D=function*(){yield M(o),yield G(o,C)}();for(const{result:j,additionalCss:d=[]}of D)o=j,d.forEach(f=>{const i=k(f,"");w(i,"")});return O(o)},"");if(!a)return r.join(`
6
+ `);if(!s)return a;let b="";return b=`${s} { ${a} }`,[b,...r].join(`
7
+ `)},_=(t,s=[])=>{if(!t)return"";const e=[],n={};if(Object.entries(t).forEach(([r,a])=>{if(typeof a=="object"){if(!a)return;const b=r.trim(),l=_(a,[...s,b]);e.push(l)}else n[r]=a}),Object.keys(n).length){const r=s.map(V).join("-"),a=k(n,`.${r}`);e.push(a)}return e.join(`
8
+ `)},N=t=>u.join(t,"./saltygen"),J=["salty","css","styles","styled"],q=(t=[])=>new RegExp(`\\.(${[...J,...t].join("|")})\\.`),K=(t,s=[])=>q(s).test(t),L=async t=>{const s=N(t),e=u.join(t,"salty.config.ts"),n=u.join(s,"salty.config.js");await x.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const r=Date.now(),{config:a}=await import(`${n}?t=${r}`);return a},U=async t=>{const s=await L(t),e=new Set,n=(f,i=[])=>f?Object.entries(f).flatMap(([p,c])=>{if(!c)return;if(typeof c=="object")return n(c,[...i,p]);const h=[...i,p].join(".");e.add(`"${h}"`);const S=[...i.map(V),V(p)].join("-"),{result:P}=M(c);return`--${S}: ${P};`}):[],r=f=>f?Object.entries(f).flatMap(([i,p])=>{const c=n(p);return i==="base"?c.join(""):`${i} { ${c.join("")} }`}):[],a=f=>f?Object.entries(f).flatMap(([i,p])=>Object.entries(p).flatMap(([c,h])=>{const S=n(h,[i]),P=`.${i}-${c}, [data-${i}="${c}"]`,T=S.join("");return`${P} { ${T} }`})):[],b=n(s.variables),l=r(s.responsiveVariables),$=a(s.conditionalVariables),o=N(t),y=u.join(o,"css/variables.css"),g=`:root { ${b.join("")} ${l.join("")} } ${$.join("")}`;m.writeFileSync(y,g);const w=u.join(o,"types/css-tokens.d.ts"),C=`type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;m.writeFileSync(w,C);const F=u.join(o,"css/global.css"),D=k(s.global,"");m.writeFileSync(F,D);const j=u.join(o,"css/templates.css"),d=_(s.templates);m.writeFileSync(j,d)},X=async(t,s)=>{const e=A(t),n=u.join(s,"js",e+".js");await x.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}`)},Y=async t=>{const s=N(t),e=u.join(s,"salty.config.js"),{config:n}=await import(e);return n},Q=async t=>{try{const s=[],e=[],n=N(t),r=u.join(n,"index.css");(()=>{m.existsSync(n)&&W.execSync("rm -rf "+n),m.mkdirSync(n),m.mkdirSync(u.join(n,"css")),m.mkdirSync(u.join(n,"types"))})(),await U(t);const b=await Y(t);async function l(g,w){const O=m.statSync(g);if(O.isDirectory()){const C=m.readdirSync(g);await Promise.all(C.map(F=>l(u.join(g,F),u.join(w,F))))}else if(O.isFile()&&K(g)){const F=await X(g,n),D=[];Object.entries(F).forEach(([i,p])=>{if(p.isKeyframes&&p.css){const T=`${p.animationName}.css`,Z=`css/${T}`,R=u.join(n,Z);s.push(T),m.writeFileSync(R,p.css);return}if(!p.generator)return;const c=p.generator._withBuildContext({name:i,config:b}),h=`${c.hash}-${c.priority}.css`;e[c.priority]||(e[c.priority]=[]),e[c.priority].push(h),D.push(h);const S=`css/${h}`,P=u.join(n,S);m.writeFileSync(P,c.css)});const j=D.map(i=>`@import url('./${i}');`).join(`
9
+ `),d=A(g,6),f=u.join(n,`css/${d}.css`);m.writeFileSync(f,j)}}await l(t,n);const $=s.map(g=>`@import url('./css/${g}');`).join(`
10
10
  `);let y=`@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
14
  ${$}`;if(b.importStrategy!=="component"){const g=e.flat().map(w=>`@import url('./css/${w}');`).join(`
15
- `);y+=g}m.writeFileSync(o,y)}catch(s){console.error(s)}},st=(t,s)=>{var e,n,o;(n=(e=t.module)==null?void 0:e.rules)==null||n.push({test:R(),use:[{loader:u.resolve("./loader.js"),options:{dir:s}}]}),(o=t.plugins)==null||o.push({apply:a=>{a.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await tt(s)})}})};exports.saltyPlugin=st;
15
+ `);y+=g}m.writeFileSync(r,y)}catch(s){console.error(s)}},v=(t,s)=>{var e,n,r;(n=(e=t.module)==null?void 0:e.rules)==null||n.push({test:q(),use:[{loader:u.resolve("./loader.js"),options:{dir:s}}]}),(r=t.plugins)==null||r.push({apply:a=>{a.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await Q(s)})}})};exports.saltyPlugin=v;
package/index.js CHANGED
@@ -1,111 +1,106 @@
1
- import { join as m, resolve as L } from "path";
2
- import * as M from "esbuild";
3
- import * as T from "winston";
1
+ import { join as m, resolve as H } from "path";
2
+ import * as A from "esbuild";
4
3
  import { execSync as q } from "child_process";
5
- import { existsSync as z, mkdirSync as E, statSync as B, readdirSync as G, writeFileSync as w } from "fs";
4
+ import { existsSync as B, mkdirSync as x, statSync as G, readdirSync as J, writeFileSync as w } from "fs";
6
5
  import "fs/promises";
7
- const A = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), J = (t, s) => {
6
+ const E = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), K = (t, s) => {
8
7
  let e = "", n;
9
- for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = A(n % 52) + e;
10
- return e = A(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
11
- }, K = (t, s) => {
8
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = E(n % 52) + e;
9
+ return e = E(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
10
+ }, L = (t, s) => {
12
11
  let e = s.length;
13
12
  for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
14
13
  return t;
15
- }, Z = (t, s = 3) => {
16
- const e = K(5381, JSON.stringify(t)) >>> 0;
17
- return J(e, s);
14
+ }, M = (t, s = 3) => {
15
+ const e = L(5381, JSON.stringify(t)) >>> 0;
16
+ return K(e, s);
18
17
  };
19
- function N(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 T(t) {
19
+ return t ? typeof t != "string" ? T(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 U = (t, s) => {
21
+ const z = (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: a } = n;
28
- t = t.replace(o, (g) => {
29
- const { value: l, css: h } = a(g);
30
- return h && e.push(h), l;
26
+ const { pattern: r, transform: a } = n;
27
+ t = t.replace(r, (g) => {
28
+ const { value: l, css: b } = a(g);
29
+ return b && e.push(b), l;
31
30
  });
32
31
  }), { result: t, additionalCss: e };
33
- }, R = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${N(n[1].replaceAll(".", "-"))})`) } : { result: t }, k = (t, s, e, n) => {
34
- const o = [], a = Object.entries(t).reduce((l, [h, r]) => {
35
- const u = h.trim();
36
- if (typeof r == "function" && (r = r()), typeof r == "object") {
37
- if (!r) return l;
32
+ }, Z = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${T(n[1].replaceAll(".", "-"))})`) } : { result: t }, k = (t, s, e, n) => {
33
+ if (!t) return "";
34
+ const r = [], a = Object.entries(t).reduce((l, [b, o]) => {
35
+ const u = b.trim();
36
+ if (typeof o == "function" && (o = o()), typeof o == "object") {
37
+ if (!o) return l;
38
38
  if (u === "variants")
39
- return Object.entries(r).forEach(([f, i]) => {
39
+ return Object.entries(o).forEach(([f, i]) => {
40
40
  i && Object.entries(i).forEach(([p, c]) => {
41
41
  if (!c) return;
42
- const $ = `${s}.${f}-${p}`, j = k(c, $);
43
- o.push(j);
42
+ const h = `${s}.${f}-${p}`, j = k(c, h);
43
+ r.push(j);
44
44
  });
45
45
  }), l;
46
46
  if (u === "defaultVariants")
47
47
  return l;
48
48
  if (u === "compoundVariants")
49
- return r.forEach((f) => {
50
- const { css: i, ...p } = f, c = Object.entries(p).reduce((j, [C, O]) => `${j}.${C}-${O}`, s), $ = k(i, c);
51
- o.push($);
49
+ return o.forEach((f) => {
50
+ const { css: i, ...p } = f, c = Object.entries(p).reduce((j, [C, O]) => `${j}.${C}-${O}`, s), h = k(i, c);
51
+ r.push(h);
52
52
  }), l;
53
53
  if (u.startsWith("@")) {
54
- const f = k(r, s), i = `${u} {
54
+ const f = k(o, s), i = `${u} {
55
55
  ${f.replace(`
56
56
  `, `
57
57
  `)}
58
58
  }`;
59
- return o.push(i), l;
59
+ return r.push(i), l;
60
60
  }
61
- const b = h.includes("&") ? u.replace("&", s) : u.startsWith(":") ? `${s}${u}` : `${s} ${u}`, d = k(r, b);
62
- return o.push(d), l;
61
+ const $ = b.includes("&") ? u.replace("&", s) : u.startsWith(":") ? `${s}${u}` : `${s} ${u}`, d = k(o, $);
62
+ return r.push(d), l;
63
63
  }
64
- const y = u.startsWith("-") ? u : N(u), S = (b, d = ";") => l = `${l}${b}${d}`, V = (b) => S(`${y}:${b}`);
65
- if (typeof r == "number") return V(r);
66
- if (typeof r != "string")
67
- if ("toString" in r) r = r.toString();
64
+ const y = u.startsWith("-") ? u : T(u), S = ($, d = ";") => l = `${l}${$}${d}`, D = ($) => S(`${y}:${$}`);
65
+ if (typeof o == "number") return D(o);
66
+ if (typeof o != "string")
67
+ if ("toString" in o) o = o.toString();
68
68
  else return l;
69
- const { modifiers: D } = {}, F = function* () {
70
- yield R(r), yield U(r, D);
69
+ const { modifiers: F } = {}, V = function* () {
70
+ yield Z(o), yield z(o, F);
71
71
  }();
72
- for (const { result: b, additionalCss: d = [] } of F)
73
- r = b, d.forEach((f) => {
72
+ for (const { result: $, additionalCss: d = [] } of V)
73
+ o = $, d.forEach((f) => {
74
74
  const i = k(f, "");
75
75
  S(i, "");
76
76
  });
77
- return V(r);
77
+ return D(o);
78
78
  }, "");
79
- if (!a) return o.join(`
79
+ if (!a) return r.join(`
80
80
  `);
81
81
  if (!s) return a;
82
82
  let g = "";
83
- return g = `${s} { ${a} }`, [g, ...o].join(`
83
+ return g = `${s} { ${a} }`, [g, ...r].join(`
84
84
  `);
85
- }, I = (t, s = []) => {
85
+ }, R = (t, s = []) => {
86
+ if (!t) return "";
86
87
  const e = [], n = {};
87
- if (Object.entries(t).forEach(([o, a]) => {
88
+ if (Object.entries(t).forEach(([r, a]) => {
88
89
  if (typeof a == "object") {
89
90
  if (!a) return;
90
- const g = o.trim(), l = I(a, [...s, g]);
91
+ const g = r.trim(), l = R(a, [...s, g]);
91
92
  e.push(l);
92
93
  } else
93
- n[o] = a;
94
+ n[r] = a;
94
95
  }), Object.keys(n).length) {
95
- const o = s.map(N).join("-"), a = k(n, `.${o}`);
96
+ const r = s.map(T).join("-"), a = k(n, `.${r}`);
96
97
  e.push(a);
97
98
  }
98
99
  return e.join(`
99
100
  `);
100
- };
101
- T.createLogger({
102
- level: "info",
103
- format: T.format.combine(T.format.colorize(), T.format.cli()),
104
- transports: [new T.transports.Console({})]
105
- });
106
- const x = (t) => m(t, "./saltygen"), X = ["salty", "css", "styles", "styled"], W = (t = []) => new RegExp(`\\.(${[...X, ...t].join("|")})\\.`), Y = (t, s = []) => W(s).test(t), Q = async (t) => {
107
- const s = x(t), e = m(t, "salty-config.ts"), n = m(s, "salty-config.js");
108
- await M.build({
101
+ }, N = (t) => m(t, "./saltygen"), U = ["salty", "css", "styles", "styled"], I = (t = []) => new RegExp(`\\.(${[...U, ...t].join("|")})\\.`), X = (t, s = []) => I(s).test(t), Y = async (t) => {
102
+ const s = N(t), e = m(t, "salty.config.ts"), n = m(s, "salty.config.js");
103
+ await A.build({
109
104
  entryPoints: [e],
110
105
  minify: !0,
111
106
  treeShaking: !0,
@@ -114,33 +109,33 @@ const x = (t) => m(t, "./saltygen"), X = ["salty", "css", "styles", "styled"], W
114
109
  format: "esm",
115
110
  external: ["react"]
116
111
  });
117
- const o = Date.now(), { config: a } = await import(`${n}?t=${o}`);
112
+ const r = Date.now(), { config: a } = await import(`${n}?t=${r}`);
118
113
  return a;
119
- }, v = async (t) => {
120
- const s = await Q(t), e = /* @__PURE__ */ new Set(), n = (f, i = []) => f ? Object.entries(f).flatMap(([p, c]) => {
114
+ }, Q = async (t) => {
115
+ const s = await Y(t), e = /* @__PURE__ */ new Set(), n = (f, i = []) => f ? Object.entries(f).flatMap(([p, c]) => {
121
116
  if (!c) return;
122
117
  if (typeof c == "object") return n(c, [...i, p]);
123
- const $ = [...i, p].join(".");
124
- e.add(`"${$}"`);
125
- const j = [...i.map(N), N(p)].join("-"), { result: C } = R(c);
118
+ const h = [...i, p].join(".");
119
+ e.add(`"${h}"`);
120
+ const j = [...i.map(T), T(p)].join("-"), { result: C } = Z(c);
126
121
  return `--${j}: ${C};`;
127
- }) : [], o = (f) => f ? Object.entries(f).flatMap(([i, p]) => {
122
+ }) : [], r = (f) => f ? Object.entries(f).flatMap(([i, p]) => {
128
123
  const c = n(p);
129
124
  return i === "base" ? c.join("") : `${i} { ${c.join("")} }`;
130
- }) : [], a = (f) => f ? Object.entries(f).flatMap(([i, p]) => Object.entries(p).flatMap(([c, $]) => {
131
- const j = n($, [i]), C = `.${i}-${c}, [data-${i}="${c}"]`, O = j.join("");
125
+ }) : [], a = (f) => f ? Object.entries(f).flatMap(([i, p]) => Object.entries(p).flatMap(([c, h]) => {
126
+ const j = n(h, [i]), C = `.${i}-${c}, [data-${i}="${c}"]`, O = j.join("");
132
127
  return `${C} { ${O} }`;
133
- })) : [], g = n(s.variables), l = o(s.responsiveVariables), h = a(s.conditionalVariables), r = x(t), u = m(r, "css/variables.css"), y = `:root { ${g.join("")} ${l.join("")} } ${h.join("")}`;
128
+ })) : [], g = n(s.variables), l = r(s.responsiveVariables), b = a(s.conditionalVariables), o = N(t), u = m(o, "css/variables.css"), y = `:root { ${g.join("")} ${l.join("")} } ${b.join("")}`;
134
129
  w(u, y);
135
- const S = m(r, "types/css-tokens.d.ts"), D = `type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
136
- w(S, D);
137
- const P = m(r, "css/global.css"), F = k(s.global, "");
138
- w(P, F);
139
- const b = m(r, "css/templates.css"), d = I(s.templates);
140
- w(b, d);
141
- }, tt = async (t, s) => {
142
- const e = Z(t), n = m(s, "js", e + ".js");
143
- await M.build({
130
+ const S = m(o, "types/css-tokens.d.ts"), F = `type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
131
+ w(S, F);
132
+ const P = m(o, "css/global.css"), V = k(s.global, "");
133
+ w(P, V);
134
+ const $ = m(o, "css/templates.css"), d = R(s.templates);
135
+ w($, d);
136
+ }, v = async (t, s) => {
137
+ const e = M(t), n = m(s, "js", e + ".js");
138
+ await A.build({
144
139
  entryPoints: [t],
145
140
  minify: !0,
146
141
  treeShaking: !0,
@@ -151,80 +146,80 @@ const x = (t) => m(t, "./saltygen"), X = ["salty", "css", "styles", "styled"], W
151
146
  keepNames: !0,
152
147
  external: ["react"]
153
148
  });
154
- const o = Date.now();
155
- return await import(`${n}?t=${o}`);
156
- }, st = async (t) => {
157
- const s = x(t), e = m(s, "salty-config.js"), { config: n } = await import(e);
149
+ const r = Date.now();
150
+ return await import(`${n}?t=${r}`);
151
+ }, tt = async (t) => {
152
+ const s = N(t), e = m(s, "salty.config.js"), { config: n } = await import(e);
158
153
  return n;
159
- }, et = async (t) => {
154
+ }, st = async (t) => {
160
155
  try {
161
- const s = [], e = [], n = x(t), o = m(n, "index.css");
156
+ const s = [], e = [], n = N(t), r = m(n, "index.css");
162
157
  (() => {
163
- z(n) && q("rm -rf " + n), E(n), E(m(n, "css")), E(m(n, "types"));
164
- })(), await v(t);
165
- const g = await st(t);
158
+ B(n) && q("rm -rf " + n), x(n), x(m(n, "css")), x(m(n, "types"));
159
+ })(), await Q(t);
160
+ const g = await tt(t);
166
161
  async function l(y, S) {
167
- const V = B(y);
168
- if (V.isDirectory()) {
169
- const D = G(y);
170
- await Promise.all(D.map((P) => l(m(y, P), m(S, P))));
171
- } else if (V.isFile() && Y(y)) {
172
- const P = await tt(y, n), F = [];
162
+ const D = G(y);
163
+ if (D.isDirectory()) {
164
+ const F = J(y);
165
+ await Promise.all(F.map((P) => l(m(y, P), m(S, P))));
166
+ } else if (D.isFile() && X(y)) {
167
+ const P = await v(y, n), V = [];
173
168
  Object.entries(P).forEach(([i, p]) => {
174
169
  if (p.isKeyframes && p.css) {
175
- const O = `${p.animationName}.css`, _ = `css/${O}`, H = m(n, _);
176
- s.push(O), w(H, p.css);
170
+ const O = `${p.animationName}.css`, W = `css/${O}`, _ = m(n, W);
171
+ s.push(O), w(_, p.css);
177
172
  return;
178
173
  }
179
174
  if (!p.generator) return;
180
175
  const c = p.generator._withBuildContext({
181
176
  name: i,
182
177
  config: g
183
- }), $ = `${c.hash}-${c.priority}.css`;
184
- e[c.priority] || (e[c.priority] = []), e[c.priority].push($), F.push($);
185
- const j = `css/${$}`, C = m(n, j);
178
+ }), h = `${c.hash}-${c.priority}.css`;
179
+ e[c.priority] || (e[c.priority] = []), e[c.priority].push(h), V.push(h);
180
+ const j = `css/${h}`, C = m(n, j);
186
181
  w(C, c.css);
187
182
  });
188
- const b = F.map((i) => `@import url('./${i}');`).join(`
189
- `), d = Z(y, 6), f = m(n, `css/${d}.css`);
190
- w(f, b);
183
+ const $ = V.map((i) => `@import url('./${i}');`).join(`
184
+ `), d = M(y, 6), f = m(n, `css/${d}.css`);
185
+ w(f, $);
191
186
  }
192
187
  }
193
188
  await l(t, n);
194
- const h = s.map((y) => `@import url('./css/${y}');`).join(`
189
+ const b = s.map((y) => `@import url('./css/${y}');`).join(`
195
190
  `);
196
191
  let u = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
197
192
 
198
193
  ${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
199
194
  `)}
200
- ${h}`;
195
+ ${b}`;
201
196
  if (g.importStrategy !== "component") {
202
197
  const y = e.flat().map((S) => `@import url('./css/${S}');`).join(`
203
198
  `);
204
199
  u += y;
205
200
  }
206
- w(o, u);
201
+ w(r, u);
207
202
  } catch (s) {
208
203
  console.error(s);
209
204
  }
210
- }, ct = (t, s) => {
211
- var e, n, o;
205
+ }, it = (t, s) => {
206
+ var e, n, r;
212
207
  (n = (e = t.module) == null ? void 0 : e.rules) == null || n.push({
213
- test: W(),
208
+ test: I(),
214
209
  use: [
215
210
  {
216
- loader: L("./loader.js"),
211
+ loader: H("./loader.js"),
217
212
  options: { dir: s }
218
213
  }
219
214
  ]
220
- }), (o = t.plugins) == null || o.push({
215
+ }), (r = t.plugins) == null || r.push({
221
216
  apply: (a) => {
222
217
  a.hooks.afterPlugins.tap({ name: "generateCss" }, async () => {
223
- await et(s);
218
+ await st(s);
224
219
  });
225
220
  }
226
221
  });
227
222
  };
228
223
  export {
229
- ct as saltyPlugin
224
+ it as saltyPlugin
230
225
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/webpack",
3
- "version": "0.0.1-alpha.13",
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,9 @@
27
27
  "import": "./index.js",
28
28
  "require": "./index.cjs"
29
29
  }
30
+ },
31
+ "peerDependencies": {
32
+ "@salty-css/core": ">=0.0.1-alpha.14",
33
+ "webpack": ">=5.x"
30
34
  }
31
35
  }