@salty-css/webpack 0.0.1-alpha.2 → 0.0.1-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # Salty Css
2
+
3
+ ## Basic usage example with Button
4
+
5
+ ### Initial requirements
6
+
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
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
+ 4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
11
+
12
+ ### Code examples
13
+
14
+ **Salty config**
15
+
16
+ ```tsx
17
+ import { defineConfig } from '@salty-css/core/config';
18
+
19
+ export const config = defineConfig({
20
+ variables: {
21
+ colors: {
22
+ brand: '#111',
23
+ highlight: 'yellow',
24
+ },
25
+ },
26
+ global: {
27
+ html: {
28
+ backgroundColor: '#f8f8f8',
29
+ },
30
+ },
31
+ });
32
+ ```
33
+
34
+ **Your React component file**
35
+
36
+ ```tsx
37
+ import { Wrapper } from '../components/wrapper/wrapper.css';
38
+ import { Button } from '../components/button/button.css';
39
+
40
+ export const IndexPage = () => {
41
+ return (
42
+ <Wrapper>
43
+ <Button variant="solid" onClick={() => alert('It is a button.')}>
44
+ Outlined
45
+ </Button>
46
+ </Wrapper>
47
+ );
48
+ };
49
+ ```
50
+
51
+ **Wrapper** (`components/wrapper/wrapper.css.ts`)
52
+
53
+ ```tsx
54
+ import { styled } from '@salty-css/react/styled';
55
+
56
+ export const Wrapper = styled('div', {
57
+ display: 'block',
58
+ padding: '2vw',
59
+ });
60
+ ```
61
+
62
+ **Button** (`components/button/button.css.ts`)
63
+
64
+ ```tsx
65
+ import { styled } from '@salty-css/react/styled';
66
+
67
+ 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',
84
+ },
85
+ variants: {
86
+ variant: {
87
+ outlined: {
88
+ // same as default styles
89
+ },
90
+ solid: {
91
+ '&:not(:hover)': {
92
+ background: 'black',
93
+ borderColor: 'black',
94
+ color: 'white',
95
+ },
96
+ '&:hover': {
97
+ background: 'transparent',
98
+ borderColor: 'currentColor',
99
+ color: 'currentColor',
100
+ },
101
+ },
102
+ },
103
+ },
104
+ });
105
+ ```
106
+
107
+ More examples coming soon
package/dist/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;
@@ -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/dist/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
+ };
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@salty-css/webpack",
3
+ "version": "0.0.1-alpha.3",
4
+ "main": "./dist/index.js",
5
+ "module": "./dist/index.mjs",
6
+ "typings": "./dist/index.d.ts",
7
+ "type": "module",
8
+ "license": "MIT",
9
+ "private": false,
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "homepage": "https://github.com/margarita-form/salty-css",
14
+ "bugs": {
15
+ "url": "https://github.com/margarita-form/salty-css/issues"
16
+ },
17
+ "files": [
18
+ "dist",
19
+ "!**/*.tsbuildinfo"
20
+ ],
21
+ "nx": {
22
+ "name": "webpack"
23
+ },
24
+ "exports": {
25
+ ".": {
26
+ "import": "./index.js",
27
+ "require": "./index.cjs"
28
+ }
29
+ }
30
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/webpack",
3
- "version": "0.0.1-alpha.2",
3
+ "version": "0.0.1-alpha.3",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",