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

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -54,8 +54,10 @@ export const IndexPage = () => {
54
54
  import { styled } from '@salty-css/react/styled';
55
55
 
56
56
  export const Wrapper = styled('div', {
57
- display: 'block',
58
- padding: '2vw',
57
+ base: {
58
+ display: 'block',
59
+ padding: '2vw',
60
+ },
59
61
  });
60
62
  ```
61
63
 
@@ -65,22 +67,24 @@ export const Wrapper = styled('div', {
65
67
  import { styled } from '@salty-css/react/styled';
66
68
 
67
69
  export const Button = styled('button', {
68
- display: 'block',
69
- padding: `0.6em 1.2em`,
70
- border: '1px solid currentColor',
71
- background: 'transparent',
72
- color: 'currentColor/40',
73
- cursor: 'pointer',
74
- transition: '200ms',
75
- textDecoration: 'none',
76
- '&:hover': {
77
- background: 'black',
78
- borderColor: 'black',
79
- color: 'white',
80
- },
81
- '&:disabled': {
82
- opacity: 0.25,
83
- pointerEvents: 'none',
70
+ base: {
71
+ display: 'block',
72
+ padding: `0.6em 1.2em`,
73
+ border: '1px solid currentColor',
74
+ background: 'transparent',
75
+ color: 'currentColor/40',
76
+ cursor: 'pointer',
77
+ transition: '200ms',
78
+ textDecoration: 'none',
79
+ '&:hover': {
80
+ background: 'black',
81
+ borderColor: 'black',
82
+ color: 'white',
83
+ },
84
+ '&:disabled': {
85
+ opacity: 0.25,
86
+ pointerEvents: 'none',
87
+ },
84
88
  },
85
89
  variants: {
86
90
  variant: {
package/index.cjs ADDED
@@ -0,0 +1,4 @@
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;
package/index.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/index.js ADDED
@@ -0,0 +1,103 @@
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);
18
+ };
19
+ p.createLogger({
20
+ level: "info",
21
+ format: p.format.combine(p.format.colorize(), p.format.cli()),
22
+ transports: [new p.transports.Console({})]
23
+ });
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({
27
+ entryPoints: [e],
28
+ minify: !0,
29
+ treeShaking: !0,
30
+ bundle: !0,
31
+ outfile: n,
32
+ format: "esm",
33
+ target: ["es2022"],
34
+ keepNames: !0,
35
+ external: ["react"]
36
+ });
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);
41
+ return n;
42
+ }, J = async (e, s) => {
43
+ 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(`
57
+ `);
58
+ F(r, l);
59
+ }
60
+ } catch (t) {
61
+ console.error(t);
62
+ }
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);
88
+ });
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
+ }
93
+ } catch (t) {
94
+ console.error(t);
95
+ }
96
+ };
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
+ export {
102
+ I as default
103
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/webpack",
3
- "version": "0.0.1-alpha.1",
3
+ "version": "0.0.1-alpha.10",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -15,7 +15,7 @@
15
15
  "url": "https://github.com/margarita-form/salty-css/issues"
16
16
  },
17
17
  "files": [
18
- "dist",
18
+ "**/*",
19
19
  "!**/*.tsbuildinfo"
20
20
  ],
21
21
  "nx": {