@salty-css/webpack 0.0.1-alpha.10 → 0.0.1-alpha.12

Sign up to get free protection for your applications and to get access to all the features.
package/index.cjs CHANGED
@@ -1,4 +1,15 @@
1
- "use strict";const _=require("esbuild"),P=require("winston");require("child_process");const a=require("path"),d=require("fs"),q=require("fs/promises");function S(e){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const t in e)if(t!=="default"){const n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(s,t,n.get?n:{enumerable:!0,get:()=>e[t]})}}return s.default=e,Object.freeze(s)}const E=S(_),f=S(P),F=e=>String.fromCharCode(e+(e>25?39:97)),v=(e,s)=>{let t="",n;for(n=Math.abs(e);n>52;n=n/52|0)t=F(n%52)+t;return t=F(n%52)+t,t.length<s?t=t.padStart(s,"a"):t.length>s&&(t=t.slice(-s)),t},R=(e,s)=>{let t=s.length;for(;t;)e=e*33^s.charCodeAt(--t);return e},x=(e,s=3)=>{const t=R(5381,JSON.stringify(e))>>>0;return v(t,s)};f.createLogger({level:"info",format:f.format.combine(f.format.colorize(),f.format.cli()),transports:[new f.transports.Console({})]});const k=e=>a.join(e,"./saltygen"),z=["salty","css","styles","styled"],C=e=>new RegExp(`\\.(${z.join("|")})\\.`).test(e),N=async(e,s)=>{const t=x(e),n=a.join(s,"js",t+".js");await E.build({entryPoints:[e],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}`)},O=async e=>{const s=k(e),t=a.join(s,"salty-config.js"),{config:n}=await import(t);return n},A=async(e,s)=>{try{const t=[],n=a.join(e,"./saltygen"),r=a.join(n,"index.css");if(C(s)){const y=await O(e),m=await N(s,n);Object.entries(m).forEach(([c,u])=>{if(!u.generator)return;const g=u.generator._withBuildContext({name:c,config:y}),p=`${g.hash}-${g.priority}.css`,w=`css/${p}`,j=a.join(n,w);t.push(p),d.writeFileSync(j,g.css)});const o=d.readFileSync(r,"utf8").split(`
2
- `),h=t.map(c=>`@import url('../saltygen/css/${c}');`),l=[...new Set([...o,...h])].join(`
3
- `);d.writeFileSync(r,l)}}catch(t){console.error(t)}},H=async(e,s)=>{try{const t=a.join(e,"./saltygen");if(C(s)){let r=d.readFileSync(s,"utf8");r.replace(/^(?!export\s)const\s.*/gm,i=>`export ${i}`)!==r&&await q.writeFile(s,r);const y=await O(e),m=await N(s,t);let o=r;Object.entries(m).forEach(([i,l])=>{var b;if(l.isKeyframes){console.log("value",l);return}if(!l.generator)return;const c=l.generator._withBuildContext({name:i,config:y}),u=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!u)return console.error("Could not find the original declaration");const g=(b=u.at(1))==null?void 0:b.trim(),{element:p,variantKeys:w}=c.props,j=`${i} = styled(${g}, "${c.classNames}", "${c._callerName}", ${JSON.stringify(p)}, ${JSON.stringify(w)});`,D=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`,"g");o=o.replace(D,j)});const h=x(s,6);return y.importStrategy==="component"&&(o=`import '../../saltygen/css/${h}.css';
4
- ${o}`),o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(t){console.error(t)}};async function J(){const{dir:e}=this.getOptions(),{resourcePath:s,hot:t}=this;return t&&await A(e,s),await H(e,s)}module.exports=J;
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} {
2
+ ${f.replace(`
3
+ `,`
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(`
10
+ `);let y=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
11
+
12
+ ${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
13
+ `)}
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;
package/index.d.ts CHANGED
@@ -1,7 +1,2 @@
1
- import { LoaderContext } from 'webpack';
2
- interface SaltyLoaderOptions {
3
- dir: string;
4
- }
5
- type WebpackLoaderThis = LoaderContext<SaltyLoaderOptions>;
6
- export default function (this: WebpackLoaderThis): Promise<string | undefined>;
7
- export {};
1
+ import { Configuration } from 'webpack';
2
+ export declare const saltyPlugin: (config: Configuration, dir: string) => void;
package/index.js CHANGED
@@ -1,103 +1,230 @@
1
- import * as O from "esbuild";
2
- import * as p from "winston";
3
- import "child_process";
4
- import { join as a } from "path";
5
- import { writeFileSync as F, readFileSync as C } from "fs";
6
- import { writeFile as P } from "fs/promises";
7
- const S = (e) => String.fromCharCode(e + (e > 25 ? 39 : 97)), v = (e, s) => {
8
- let t = "", n;
9
- for (n = Math.abs(e); n > 52; n = n / 52 | 0) t = S(n % 52) + t;
10
- return t = S(n % 52) + t, t.length < s ? t = t.padStart(s, "a") : t.length > s && (t = t.slice(-s)), t;
11
- }, R = (e, s) => {
12
- let t = s.length;
13
- for (; t; ) e = e * 33 ^ s.charCodeAt(--t);
14
- return e;
15
- }, N = (e, s = 3) => {
16
- const t = R(5381, JSON.stringify(e)) >>> 0;
17
- return v(t, s);
1
+ import { join as m, resolve as L } from "path";
2
+ import * as M from "esbuild";
3
+ import * as T from "winston";
4
+ 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";
6
+ import "fs/promises";
7
+ const A = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), J = (t, s) => {
8
+ 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) => {
12
+ let e = s.length;
13
+ for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
14
+ return t;
15
+ }, Z = (t, s = 3) => {
16
+ const e = K(5381, JSON.stringify(t)) >>> 0;
17
+ return J(e, s);
18
18
  };
19
- p.createLogger({
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()) : "";
21
+ }
22
+ const U = (t, s) => {
23
+ if (typeof t != "string") return { result: t };
24
+ if (!s) return { result: t };
25
+ const e = [];
26
+ 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;
31
+ });
32
+ }), { 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;
38
+ if (u === "variants")
39
+ return Object.entries(r).forEach(([f, i]) => {
40
+ i && Object.entries(i).forEach(([p, c]) => {
41
+ if (!c) return;
42
+ const $ = `${s}.${f}-${p}`, j = k(c, $);
43
+ o.push(j);
44
+ });
45
+ }), l;
46
+ if (u === "defaultVariants")
47
+ return l;
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($);
52
+ }), l;
53
+ if (u.startsWith("@")) {
54
+ const f = k(r, s), i = `${u} {
55
+ ${f.replace(`
56
+ `, `
57
+ `)}
58
+ }`;
59
+ return o.push(i), l;
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;
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();
68
+ else return l;
69
+ const { modifiers: D } = {}, F = function* () {
70
+ yield R(r), yield U(r, D);
71
+ }();
72
+ for (const { result: b, additionalCss: d = [] } of F)
73
+ r = b, d.forEach((f) => {
74
+ const i = k(f, "");
75
+ S(i, "");
76
+ });
77
+ return V(r);
78
+ }, "");
79
+ if (!a) return o.join(`
80
+ `);
81
+ if (!s) return a;
82
+ let g = "";
83
+ return g = `${s} { ${a} }`, [g, ...o].join(`
84
+ `);
85
+ }, I = (t, s = []) => {
86
+ const e = [], n = {};
87
+ if (Object.entries(t).forEach(([o, a]) => {
88
+ if (typeof a == "object") {
89
+ if (!a) return;
90
+ const g = o.trim(), l = I(a, [...s, g]);
91
+ e.push(l);
92
+ } else
93
+ n[o] = a;
94
+ }), Object.keys(n).length) {
95
+ const o = s.map(N).join("-"), a = k(n, `.${o}`);
96
+ e.push(a);
97
+ }
98
+ return e.join(`
99
+ `);
100
+ };
101
+ T.createLogger({
20
102
  level: "info",
21
- format: p.format.combine(p.format.colorize(), p.format.cli()),
22
- transports: [new p.transports.Console({})]
103
+ format: T.format.combine(T.format.colorize(), T.format.cli()),
104
+ transports: [new T.transports.Console({})]
23
105
  });
24
- const A = (e) => a(e, "./saltygen"), H = ["salty", "css", "styles", "styled"], b = (e) => new RegExp(`\\.(${H.join("|")})\\.`).test(e), j = async (e, s) => {
25
- const t = N(e), n = a(s, "js", t + ".js");
26
- await O.build({
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({
27
109
  entryPoints: [e],
28
110
  minify: !0,
29
111
  treeShaking: !0,
30
112
  bundle: !0,
31
113
  outfile: n,
32
114
  format: "esm",
115
+ external: ["react"]
116
+ });
117
+ const o = Date.now(), { config: a } = await import(`${n}?t=${o}`);
118
+ 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]) => {
121
+ if (!c) return;
122
+ 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);
126
+ return `--${j}: ${C};`;
127
+ }) : [], o = (f) => f ? Object.entries(f).flatMap(([i, p]) => {
128
+ const c = n(p);
129
+ 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("");
132
+ 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("")}`;
134
+ 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({
144
+ entryPoints: [t],
145
+ minify: !0,
146
+ treeShaking: !0,
147
+ bundle: !0,
148
+ outfile: n,
149
+ format: "esm",
33
150
  target: ["es2022"],
34
151
  keepNames: !0,
35
152
  external: ["react"]
36
153
  });
37
- const r = Date.now();
38
- return await import(`${n}?t=${r}`);
39
- }, D = async (e) => {
40
- const s = A(e), t = a(s, "salty-config.js"), { config: n } = await import(t);
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);
41
158
  return n;
42
- }, J = async (e, s) => {
159
+ }, et = async (t) => {
43
160
  try {
44
- const t = [], n = a(e, "./saltygen"), r = a(n, "index.css");
45
- if (b(s)) {
46
- const y = await D(e), d = await j(s, n);
47
- Object.entries(d).forEach(([c, g]) => {
48
- if (!g.generator) return;
49
- const f = g.generator._withBuildContext({
50
- name: c,
51
- config: y
52
- }), m = `${f.hash}-${f.priority}.css`, h = `css/${m}`, w = a(n, h);
53
- t.push(m), F(w, f.css);
54
- });
55
- const o = C(r, "utf8").split(`
56
- `), u = t.map((c) => `@import url('../saltygen/css/${c}');`), l = [.../* @__PURE__ */ new Set([...o, ...u])].join(`
161
+ const s = [], e = [], n = x(t), o = m(n, "index.css");
162
+ (() => {
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);
166
+ 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 = [];
173
+ Object.entries(P).forEach(([i, p]) => {
174
+ if (p.isKeyframes && p.css) {
175
+ const O = `${p.animationName}.css`, _ = `css/${O}`, H = m(n, _);
176
+ s.push(O), w(H, p.css);
177
+ return;
178
+ }
179
+ if (!p.generator) return;
180
+ const c = p.generator._withBuildContext({
181
+ name: i,
182
+ 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);
186
+ w(C, c.css);
187
+ });
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);
191
+ }
192
+ }
193
+ await l(t, n);
194
+ const h = s.map((y) => `@import url('./css/${y}');`).join(`
57
195
  `);
58
- F(r, l);
196
+ let u = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
197
+
198
+ ${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
199
+ `)}
200
+ ${h}`;
201
+ if (g.importStrategy !== "component") {
202
+ const y = e.flat().map((S) => `@import url('./css/${S}');`).join(`
203
+ `);
204
+ u += y;
59
205
  }
60
- } catch (t) {
61
- console.error(t);
206
+ w(o, u);
207
+ } catch (s) {
208
+ console.error(s);
62
209
  }
63
- }, _ = async (e, s) => {
64
- try {
65
- const t = a(e, "./saltygen");
66
- if (b(s)) {
67
- let r = C(s, "utf8");
68
- r.replace(/^(?!export\s)const\s.*/gm, (i) => `export ${i}`) !== r && await P(s, r);
69
- const y = await D(e), d = await j(s, t);
70
- let o = r;
71
- Object.entries(d).forEach(([i, l]) => {
72
- var x;
73
- if (l.isKeyframes) {
74
- console.log("value", l);
75
- return;
76
- }
77
- if (!l.generator) return;
78
- const c = l.generator._withBuildContext({
79
- name: i,
80
- config: y
81
- }), g = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
82
- if (!g)
83
- return console.error("Could not find the original declaration");
84
- const f = (x = g.at(1)) == null ? void 0 : x.trim(), { element: m, variantKeys: h } = c.props, w = `${i} = styled(${f}, "${c.classNames}", "${c._callerName}", ${JSON.stringify(m)}, ${JSON.stringify(
85
- h
86
- )});`, E = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
87
- o = o.replace(E, w);
210
+ }, ct = (t, s) => {
211
+ var e, n, o;
212
+ (n = (e = t.module) == null ? void 0 : e.rules) == null || n.push({
213
+ test: W(),
214
+ use: [
215
+ {
216
+ loader: L("./loader.js"),
217
+ options: { dir: s }
218
+ }
219
+ ]
220
+ }), (o = t.plugins) == null || o.push({
221
+ apply: (a) => {
222
+ a.hooks.afterPlugins.tap({ name: "generateCss" }, async () => {
223
+ await et(s);
88
224
  });
89
- const u = N(s, 6);
90
- return y.importStrategy === "component" && (o = `import '../../saltygen/css/${u}.css';
91
- ${o}`), o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
92
225
  }
93
- } catch (t) {
94
- console.error(t);
95
- }
226
+ });
96
227
  };
97
- async function I() {
98
- const { dir: e } = this.getOptions(), { resourcePath: s, hot: t } = this;
99
- return t && await J(e, s), await _(e, s);
100
- }
101
228
  export {
102
- I as default
229
+ ct as saltyPlugin
103
230
  };
package/loader.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { LoaderContext } from 'webpack';
2
+ interface SaltyLoaderOptions {
3
+ dir: string;
4
+ }
5
+ type WebpackLoaderThis = LoaderContext<SaltyLoaderOptions>;
6
+ export default function (this: WebpackLoaderThis): Promise<string | undefined>;
7
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/webpack",
3
- "version": "0.0.1-alpha.10",
3
+ "version": "0.0.1-alpha.12",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -19,6 +19,7 @@
19
19
  "!**/*.tsbuildinfo"
20
20
  ],
21
21
  "nx": {
22
+ "sourceRoot": "libs/webpack/src",
22
23
  "name": "webpack"
23
24
  },
24
25
  "exports": {