@salty-css/vite 0.0.1-alpha.5 → 0.0.1-alpha.50
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/README.md +77 -26
- package/index.cjs +13 -13
- package/index.d.ts +1 -0
- package/index.js +161 -160
- package/package.json +5 -1
package/README.md
CHANGED
@@ -1,15 +1,62 @@
|
|
1
|
-
# Salty
|
1
|
+
# Salty CSS - Kinda sweet but yet spicy CSS-in-JS library
|
2
2
|
|
3
|
-
|
3
|
+
In the world of frontend dev is there anything saltier than CSS? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
|
4
4
|
|
5
|
-
|
5
|
+
## Features
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
- Build time compilation to achieve awesome runtime performance and minimal size
|
8
|
+
- Next.js, React Server Components, Vite and Webpack support
|
9
|
+
- Type safety with out of the box TypeScript and ESLint plugin
|
10
|
+
- Advanced CSS variables configuration to allow smooth token usage
|
11
|
+
- Style templates to create reusable styles easily
|
11
12
|
|
12
|
-
|
13
|
+
## Get started
|
14
|
+
|
15
|
+
### TL;DR
|
16
|
+
|
17
|
+
- Initialize: `npx salty-css init [directory]`
|
18
|
+
- Create component: `npx salty-css generate [filePath]`
|
19
|
+
- Build: `npx salty-css build [directory]`
|
20
|
+
|
21
|
+
### Quick way of using `salty-css` CLI
|
22
|
+
|
23
|
+
#### Initialize Salty CSS for a project
|
24
|
+
|
25
|
+
In your existing repository run `npx salty-css init [directory]` which installs required salty-css packages to the current directory and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory. Init will also create `.saltyrc` which contains some metadata for future CLI commands.
|
26
|
+
|
27
|
+
#### Create components
|
28
|
+
|
29
|
+
Components can be created with `npx salty-css generate [filePath]` which then creates a new Salty CSS component file to the specified path. Additional options like `--dir, --tag, --name and --className` are also supported. Read more about them with `npx salty-css generate --help`
|
30
|
+
|
31
|
+
#### Build / Compile Salty CSS
|
32
|
+
|
33
|
+
If you want to manually build your project that can be done by running `npx salty-css build [directory]`. Directory is not required as CLI can use default directory defined in `.saltyrc`. Note that build generates css files but Vite / Webpack plugin is still required for full support.
|
34
|
+
|
35
|
+
#### Update Salty CSS packages
|
36
|
+
|
37
|
+
To ease the pain of package updates all Salty CSS packages can be updated with `npx salty-css update`
|
38
|
+
|
39
|
+
### Manual work
|
40
|
+
|
41
|
+
#### React
|
42
|
+
|
43
|
+
1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
|
44
|
+
2. Create `salty.config.ts` to your app directory
|
45
|
+
|
46
|
+
#### Vite
|
47
|
+
|
48
|
+
1. First check the instructions for React
|
49
|
+
2. For Vite support install `npm i -D @salty-css/vite`
|
50
|
+
3. In `vite.config.ts` add import for salty plugin `import { saltyPlugin } from '@salty-css/vite';` and then add `saltyPlugin(__dirname)` to your vite configuration plugins
|
51
|
+
4. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
|
52
|
+
|
53
|
+
### Create components
|
54
|
+
|
55
|
+
1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
|
56
|
+
|
57
|
+
## Code examples
|
58
|
+
|
59
|
+
### Basic usage example with Button
|
13
60
|
|
14
61
|
**Salty config**
|
15
62
|
|
@@ -54,8 +101,10 @@ export const IndexPage = () => {
|
|
54
101
|
import { styled } from '@salty-css/react/styled';
|
55
102
|
|
56
103
|
export const Wrapper = styled('div', {
|
57
|
-
|
58
|
-
|
104
|
+
base: {
|
105
|
+
display: 'block',
|
106
|
+
padding: '2vw',
|
107
|
+
},
|
59
108
|
});
|
60
109
|
```
|
61
110
|
|
@@ -65,22 +114,24 @@ export const Wrapper = styled('div', {
|
|
65
114
|
import { styled } from '@salty-css/react/styled';
|
66
115
|
|
67
116
|
export const Button = styled('button', {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
117
|
+
base: {
|
118
|
+
display: 'block',
|
119
|
+
padding: `0.6em 1.2em`,
|
120
|
+
border: '1px solid currentColor',
|
121
|
+
background: 'transparent',
|
122
|
+
color: 'currentColor/40',
|
123
|
+
cursor: 'pointer',
|
124
|
+
transition: '200ms',
|
125
|
+
textDecoration: 'none',
|
126
|
+
'&:hover': {
|
127
|
+
background: 'black',
|
128
|
+
borderColor: 'black',
|
129
|
+
color: 'white',
|
130
|
+
},
|
131
|
+
'&:disabled': {
|
132
|
+
opacity: 0.25,
|
133
|
+
pointerEvents: 'none',
|
134
|
+
},
|
84
135
|
},
|
85
136
|
variants: {
|
86
137
|
variant: {
|
package/index.cjs
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
"use strict";Object.
|
2
|
-
${
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const W=require("esbuild"),J=require("child_process"),y=require("path"),h=require("fs"),K=require("fs/promises");function G(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const q=G(W),R=t=>String.fromCharCode(t+(t>25?39:97)),L=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=R(n%52)+s;return s=R(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},U=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},_=(t,e=3)=>{const s=U(5381,JSON.stringify(t))>>>0;return L(s,e)};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,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const X=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:r,transform:g}=n;t=t.replace(r,$=>{const{value:u,css:i}=g($);return i&&s.push(i),u})}),{result:t,additionalCss:s}},B=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${N(n[1].replaceAll(".","-"))})`)}:{result:t},D=(t,e,s,n)=>{if(!t)return"";const r=[],g=Object.entries(t).reduce((u,[i,o])=>{const c=i.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return u;if(c==="variants")return Object.entries(o).forEach(([f,a])=>{a&&Object.entries(a).forEach(([p,l])=>{if(!l)return;const w=`${e}.${f}-${p}`,x=D(l,w);r.push(x)})}),u;if(c==="defaultVariants")return u;if(c==="compoundVariants")return o.forEach(f=>{const{css:a,...p}=f,l=Object.entries(p).reduce((x,[k,P])=>`${x}.${k}-${P}`,e),w=D(a,l);r.push(w)}),u;if(c.startsWith("@")){const f=D(o,e),a=`${c} {
|
2
|
+
${f.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return r.push(
|
6
|
-
`);if(!
|
7
|
-
`)},
|
8
|
-
`)}
|
9
|
-
`),
|
10
|
-
`);let
|
5
|
+
}`;return r.push(a),u}const m=i.includes("&")?c.replace("&",e):c.startsWith(":")?`${e}${c}`:`${e} ${c}`,O=D(o,m);return r.push(O),u}const d=c.startsWith("-")?c:N(c),b=(m,O=";")=>u=`${u}${m}${O}`,F=m=>b(`${d}:${m}`);if(typeof o=="number")return F(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return u;const{modifiers:j}={},C=function*(){yield B(o),yield X(o,j)}();for(const{result:m,additionalCss:O=[]}of C)o=m,O.forEach(f=>{const a=D(f,"");b(a,"")});return F(o)},"");if(!g)return r.join(`
|
6
|
+
`);if(!e)return g;let $="";return $=`${e} { ${g} }`,[$,...r].join(`
|
7
|
+
`)},I=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([r,g])=>{if(typeof g=="object"){if(!g)return;const $=r.trim(),u=I(g,[...e,$]);s.push(u)}else n[r]=g}),Object.keys(n).length){const r=e.map(N).join("-"),g=D(n,`.${r}`);s.push(g)}return s.join(`
|
8
|
+
`)},V=t=>y.join(t,"./saltygen"),Y=["salty","css","styles","styled"],Q=(t=[])=>new RegExp(`\\.(${[...Y,...t].join("|")})\\.`),T=(t,e=[])=>Q(e).test(t),v=async t=>{const e=V(t),s=y.join(t,"salty.config.ts"),n=y.join(e,"salty.config.js");await q.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const r=Date.now(),{config:g}=await import(`${n}?t=${r}`);return g},Z=async t=>{const e=await v(t),s=new Set,n=(f,a=[])=>f?Object.entries(f).flatMap(([p,l])=>{if(!l)return;if(typeof l=="object")return n(l,[...a,p]);const w=[...a,p].join(".");s.add(`"${w}"`);const x=[...a.map(N),N(p)].join("-"),{result:k}=B(l);return`--${x}: ${k};`}):[],r=f=>f?Object.entries(f).flatMap(([a,p])=>{const l=n(p);return a==="base"?l.join(""):`${a} { ${l.join("")} }`}):[],g=f=>f?Object.entries(f).flatMap(([a,p])=>Object.entries(p).flatMap(([l,w])=>{const x=n(w,[a]),k=`.${a}-${l}, [data-${a}="${l}"]`,P=x.join("");return`${k} { ${P} }`})):[],$=n(e.variables),u=r(e.responsiveVariables),i=g(e.conditionalVariables),o=V(t),c=y.join(o,"css/variables.css"),d=`:root { ${$.join("")} ${u.join("")} } ${i.join("")}`;h.writeFileSync(c,d);const b=y.join(o,"types/css-tokens.d.ts"),j=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;h.writeFileSync(b,j);const S=y.join(o,"css/global.css"),C=D(e.global,"");h.writeFileSync(S,C);const m=y.join(o,"css/templates.css"),O=I(e.templates);h.writeFileSync(m,O)},M=async(t,e)=>{const s=_(t),n=y.join(e,"js",s+".js");await q.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 e=V(t),s=y.join(e,"salty.config.js"),{config:n}=await import(s);return n},tt=async t=>{try{const e=[],s=[],n=V(t),r=y.join(n,"index.css");(()=>{h.existsSync(n)&&J.execSync("rm -rf "+n),h.mkdirSync(n),h.mkdirSync(y.join(n,"css")),h.mkdirSync(y.join(n,"types"))})(),await Z(t);const $=await A(t);async function u(d,b){const F=h.statSync(d);if(F.isDirectory()){const j=h.readdirSync(d);await Promise.all(j.map(S=>u(y.join(d,S),y.join(b,S))))}else if(F.isFile()&&T(d)){const S=await M(d,n),C=[];Object.entries(S).forEach(([a,p])=>{if(p.isKeyframes&&p.css){const P=`${p.animationName}.css`,E=`css/${P}`,H=y.join(n,E);e.push(P),h.writeFileSync(H,p.css);return}if(!p.generator)return;const l=p.generator._withBuildContext({name:a,config:$}),w=`${l.hash}-${l.priority}.css`;s[l.priority]||(s[l.priority]=[]),s[l.priority].push(w),C.push(w);const x=`css/${w}`,k=y.join(n,x);h.writeFileSync(k,l.css)});const m=C.map(a=>`@import url('./${a}');`).join(`
|
9
|
+
`),O=_(d,6),f=y.join(n,`css/${O}.css`);h.writeFileSync(f,m)}}await u(t,n);const i=e.map(d=>`@import url('./css/${d}');`).join(`
|
10
|
+
`);let c=`@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
|
-
${
|
15
|
-
`);
|
16
|
-
`),o=
|
17
|
-
`);
|
18
|
-
${
|
14
|
+
${i}`;if($.importStrategy!=="component"){const d=s.flat().map(b=>`@import url('./css/${b}');`).join(`
|
15
|
+
`);c+=d}h.writeFileSync(r,c)}catch(e){console.error(e)}},et=async(t,e)=>{try{const s=[],n=y.join(t,"./saltygen"),r=y.join(n,"index.css");if(T(e)){const $=await A(t),u=await M(e,n);Object.entries(u).forEach(([b,F])=>{if(!F.generator)return;const j=F.generator._withBuildContext({name:b,config:$}),S=`${j.hash}-${j.priority}.css`,C=`css/${S}`,m=y.join(n,C);s.push(S),h.writeFileSync(m,j.css)});const i=h.readFileSync(r,"utf8").split(`
|
16
|
+
`),o=s.map(b=>`@import url('../saltygen/css/${b}');`),d=[...new Set([...i,...o])].join(`
|
17
|
+
`);h.writeFileSync(r,d)}}catch(s){console.error(s)}},st=async(t,e)=>{try{const s=y.join(t,"./saltygen");if(T(e)){const r=h.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,c=>`export ${c}`)!==r&&await K.writeFile(e,r);const $=await A(t),u=await M(e,s);let i=r;Object.entries(u).forEach(([c,d])=>{var P;if(d.isKeyframes||!d.generator)return;const b=d.generator._withBuildContext({name:c,config:$}),F=new RegExp(`\\s${c}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!F)return console.error("Could not find the original declaration");const j=(P=F.at(1))==null?void 0:P.trim(),S=new RegExp(`\\s${c}[=\\s]+styled\\(`,"g").exec(i);if(!S)return console.error("Could not find the original declaration");const{index:C}=S;let m=!1;const O=setTimeout(()=>m=!0,5e3);let f=0,a=!1,p=0;for(;!a&&!m;){const E=i[C+f];E==="("&&p++,E===")"&&p--,p===0&&E===")"&&(a=!0),f>i.length&&(m=!0),f++}if(!m)clearTimeout(O);else throw new Error("Failed to find the end of the styled call and timed out");const l=C+f,w=i.slice(C,l),x=i,k=` ${c} = styled(${j}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;i=i.replace(w,k),x===i&&console.error("Minimize file failed to change content",{name:c,tagName:j})});const o=_(e,6);return $.importStrategy==="component"&&(i=`import '../../saltygen/css/${o}.css';
|
18
|
+
${i}`),i=i.replace("{ styled }","{ styledClient as styled }"),i=i.replace("@salty-css/react/styled","@salty-css/react/styled-client"),i}}catch(s){console.error("Error in minimizeFile:",s)}},z=t=>({name:"stylegen",buildStart:()=>tt(t),load:async e=>{if(T(e))return await st(t,e)},watchChange:{handler:async e=>{T(e)&&await et(t,e),e.includes("salty.config")&&await Z(t)}}});exports.default=z;exports.saltyPlugin=z;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -1,110 +1,105 @@
|
|
1
1
|
import * as I from "esbuild";
|
2
|
-
import
|
3
|
-
import { execSync as L } from "child_process";
|
2
|
+
import { execSync as K } from "child_process";
|
4
3
|
import { join as y } from "path";
|
5
|
-
import { writeFileSync as
|
6
|
-
import { writeFile as
|
7
|
-
const
|
4
|
+
import { writeFileSync as k, existsSync as q, mkdirSync as A, statSync as G, readdirSync as L, readFileSync as Z } from "fs";
|
5
|
+
import { writeFile as U } from "fs/promises";
|
6
|
+
const B = (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 =
|
10
|
-
return e =
|
11
|
-
},
|
8
|
+
for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = B(n % 52) + e;
|
9
|
+
return e = B(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
|
-
},
|
16
|
-
const e =
|
17
|
-
return
|
14
|
+
}, M = (t, s = 3) => {
|
15
|
+
const e = Y(5381, JSON.stringify(t)) >>> 0;
|
16
|
+
return X(e, s);
|
18
17
|
};
|
19
|
-
function
|
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 O(t) {
|
19
|
+
return t ? typeof t != "string" ? O(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
|
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
26
|
const { pattern: r, transform: g } = n;
|
28
|
-
t = t.replace(r, (
|
29
|
-
const { value:
|
30
|
-
return
|
27
|
+
t = t.replace(r, (h) => {
|
28
|
+
const { value: p, css: i } = g(h);
|
29
|
+
return i && e.push(i), p;
|
31
30
|
});
|
32
31
|
}), { result: t, additionalCss: e };
|
33
|
-
},
|
34
|
-
|
35
|
-
|
32
|
+
}, z = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${O(n[1].replaceAll(".", "-"))})`) } : { result: t }, N = (t, s, e, n) => {
|
33
|
+
if (!t) return "";
|
34
|
+
const r = [], g = Object.entries(t).reduce((p, [i, o]) => {
|
35
|
+
const c = i.trim();
|
36
36
|
if (typeof o == "function" && (o = o()), typeof o == "object") {
|
37
|
-
if (!o) return
|
38
|
-
if (
|
39
|
-
return Object.entries(o).forEach(([
|
40
|
-
|
37
|
+
if (!o) return p;
|
38
|
+
if (c === "variants")
|
39
|
+
return Object.entries(o).forEach(([f, a]) => {
|
40
|
+
a && Object.entries(a).forEach(([u, l]) => {
|
41
41
|
if (!l) return;
|
42
|
-
const
|
43
|
-
r.push(
|
42
|
+
const j = `${s}.${f}-${u}`, x = N(l, j);
|
43
|
+
r.push(x);
|
44
44
|
});
|
45
|
-
}),
|
46
|
-
if (
|
47
|
-
return
|
48
|
-
if (
|
49
|
-
return o.forEach((
|
50
|
-
const { css:
|
51
|
-
r.push(
|
52
|
-
}),
|
53
|
-
if (
|
54
|
-
const
|
55
|
-
${
|
45
|
+
}), p;
|
46
|
+
if (c === "defaultVariants")
|
47
|
+
return p;
|
48
|
+
if (c === "compoundVariants")
|
49
|
+
return o.forEach((f) => {
|
50
|
+
const { css: a, ...u } = f, l = Object.entries(u).reduce((x, [D, E]) => `${x}.${D}-${E}`, s), j = N(a, l);
|
51
|
+
r.push(j);
|
52
|
+
}), p;
|
53
|
+
if (c.startsWith("@")) {
|
54
|
+
const f = N(o, s), a = `${c} {
|
55
|
+
${f.replace(`
|
56
56
|
`, `
|
57
57
|
`)}
|
58
58
|
}`;
|
59
|
-
return r.push(
|
59
|
+
return r.push(a), p;
|
60
60
|
}
|
61
|
-
const d =
|
62
|
-
return r.push(
|
61
|
+
const d = i.includes("&") ? c.replace("&", s) : c.startsWith(":") ? `${s}${c}` : `${s} ${c}`, C = N(o, d);
|
62
|
+
return r.push(C), p;
|
63
63
|
}
|
64
|
-
const
|
65
|
-
if (typeof o == "number") return
|
64
|
+
const m = c.startsWith("-") ? c : O(c), $ = (d, C = ";") => p = `${p}${d}${C}`, S = (d) => $(`${m}:${d}`);
|
65
|
+
if (typeof o == "number") return S(o);
|
66
66
|
if (typeof o != "string")
|
67
67
|
if ("toString" in o) o = o.toString();
|
68
|
-
else return
|
69
|
-
const { modifiers:
|
70
|
-
yield
|
68
|
+
else return p;
|
69
|
+
const { modifiers: b } = {}, F = function* () {
|
70
|
+
yield z(o), yield Q(o, b);
|
71
71
|
}();
|
72
|
-
for (const { result: d, additionalCss:
|
73
|
-
o = d,
|
74
|
-
const
|
75
|
-
|
72
|
+
for (const { result: d, additionalCss: C = [] } of F)
|
73
|
+
o = d, C.forEach((f) => {
|
74
|
+
const a = N(f, "");
|
75
|
+
$(a, "");
|
76
76
|
});
|
77
|
-
return
|
77
|
+
return S(o);
|
78
78
|
}, "");
|
79
79
|
if (!g) return r.join(`
|
80
80
|
`);
|
81
81
|
if (!s) return g;
|
82
|
-
let
|
83
|
-
return
|
82
|
+
let h = "";
|
83
|
+
return h = `${s} { ${g} }`, [h, ...r].join(`
|
84
84
|
`);
|
85
|
-
},
|
85
|
+
}, H = (t, s = []) => {
|
86
|
+
if (!t) return "";
|
86
87
|
const e = [], n = {};
|
87
88
|
if (Object.entries(t).forEach(([r, g]) => {
|
88
89
|
if (typeof g == "object") {
|
89
90
|
if (!g) return;
|
90
|
-
const
|
91
|
-
e.push(
|
91
|
+
const h = r.trim(), p = H(g, [...s, h]);
|
92
|
+
e.push(p);
|
92
93
|
} else
|
93
94
|
n[r] = g;
|
94
95
|
}), Object.keys(n).length) {
|
95
|
-
const r = s.map(
|
96
|
+
const r = s.map(O).join("-"), g = N(n, `.${r}`);
|
96
97
|
e.push(g);
|
97
98
|
}
|
98
99
|
return e.join(`
|
99
100
|
`);
|
100
|
-
}
|
101
|
-
|
102
|
-
level: "info",
|
103
|
-
format: P.format.combine(P.format.colorize(), P.format.cli()),
|
104
|
-
transports: [new P.transports.Console({})]
|
105
|
-
});
|
106
|
-
const E = (t) => y(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"], M = (t) => new RegExp(`\\.(${tt.join("|")})\\.`).test(t), st = async (t) => {
|
107
|
-
const s = E(t), e = y(t, "salty-config.ts"), n = y(s, "salty-config.js");
|
101
|
+
}, T = (t) => y(t, "./saltygen"), v = ["salty", "css", "styles", "styled"], tt = (t = []) => new RegExp(`\\.(${[...v, ...t].join("|")})\\.`), V = (t, s = []) => tt(s).test(t), st = async (t) => {
|
102
|
+
const s = T(t), e = y(t, "salty.config.ts"), n = y(s, "salty.config.js");
|
108
103
|
await I.build({
|
109
104
|
entryPoints: [e],
|
110
105
|
minify: !0,
|
@@ -116,30 +111,30 @@ const E = (t) => y(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"],
|
|
116
111
|
});
|
117
112
|
const r = Date.now(), { config: g } = await import(`${n}?t=${r}`);
|
118
113
|
return g;
|
119
|
-
},
|
120
|
-
const s = await st(t), e = /* @__PURE__ */ new Set(), n = (
|
114
|
+
}, W = async (t) => {
|
115
|
+
const s = await st(t), e = /* @__PURE__ */ new Set(), n = (f, a = []) => f ? Object.entries(f).flatMap(([u, l]) => {
|
121
116
|
if (!l) return;
|
122
|
-
if (typeof l == "object") return n(l, [...
|
123
|
-
const
|
124
|
-
e.add(`"${
|
125
|
-
const
|
126
|
-
return `--${
|
127
|
-
}) : [], r = (
|
128
|
-
const l = n(
|
129
|
-
return
|
130
|
-
}) : [], g = (
|
131
|
-
const
|
132
|
-
return `${D} { ${
|
133
|
-
})) : [],
|
134
|
-
|
135
|
-
const
|
136
|
-
|
137
|
-
const w = y(o, "css/global.css"),
|
138
|
-
|
139
|
-
const d = y(o, "css/templates.css"),
|
140
|
-
|
117
|
+
if (typeof l == "object") return n(l, [...a, u]);
|
118
|
+
const j = [...a, u].join(".");
|
119
|
+
e.add(`"${j}"`);
|
120
|
+
const x = [...a.map(O), O(u)].join("-"), { result: D } = z(l);
|
121
|
+
return `--${x}: ${D};`;
|
122
|
+
}) : [], r = (f) => f ? Object.entries(f).flatMap(([a, u]) => {
|
123
|
+
const l = n(u);
|
124
|
+
return a === "base" ? l.join("") : `${a} { ${l.join("")} }`;
|
125
|
+
}) : [], g = (f) => f ? Object.entries(f).flatMap(([a, u]) => Object.entries(u).flatMap(([l, j]) => {
|
126
|
+
const x = n(j, [a]), D = `.${a}-${l}, [data-${a}="${l}"]`, E = x.join("");
|
127
|
+
return `${D} { ${E} }`;
|
128
|
+
})) : [], h = n(s.variables), p = r(s.responsiveVariables), i = g(s.conditionalVariables), o = T(t), c = y(o, "css/variables.css"), m = `:root { ${h.join("")} ${p.join("")} } ${i.join("")}`;
|
129
|
+
k(c, m);
|
130
|
+
const $ = y(o, "types/css-tokens.d.ts"), b = `type VariableTokens = ${[...e].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
131
|
+
k($, b);
|
132
|
+
const w = y(o, "css/global.css"), F = N(s.global, "");
|
133
|
+
k(w, F);
|
134
|
+
const d = y(o, "css/templates.css"), C = H(s.templates);
|
135
|
+
k(d, C);
|
141
136
|
}, R = async (t, s) => {
|
142
|
-
const e =
|
137
|
+
const e = M(t), n = y(s, "js", e + ".js");
|
143
138
|
await I.build({
|
144
139
|
entryPoints: [t],
|
145
140
|
minify: !0,
|
@@ -154,76 +149,76 @@ const E = (t) => y(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"],
|
|
154
149
|
const r = Date.now();
|
155
150
|
return await import(`${n}?t=${r}`);
|
156
151
|
}, _ = async (t) => {
|
157
|
-
const s =
|
152
|
+
const s = T(t), e = y(s, "salty.config.js"), { config: n } = await import(e);
|
158
153
|
return n;
|
159
154
|
}, et = async (t) => {
|
160
155
|
try {
|
161
|
-
const s = [], e = [], n =
|
156
|
+
const s = [], e = [], n = T(t), r = y(n, "index.css");
|
162
157
|
(() => {
|
163
|
-
q(n) &&
|
164
|
-
})(), await
|
165
|
-
const
|
166
|
-
async function
|
167
|
-
const
|
168
|
-
if (
|
169
|
-
const
|
170
|
-
await Promise.all(
|
171
|
-
} else if (
|
172
|
-
const w = await R(
|
173
|
-
Object.entries(w).forEach(([
|
174
|
-
if (
|
175
|
-
const
|
176
|
-
s.push(
|
158
|
+
q(n) && K("rm -rf " + n), A(n), A(y(n, "css")), A(y(n, "types"));
|
159
|
+
})(), await W(t);
|
160
|
+
const h = await _(t);
|
161
|
+
async function p(m, $) {
|
162
|
+
const S = G(m);
|
163
|
+
if (S.isDirectory()) {
|
164
|
+
const b = L(m);
|
165
|
+
await Promise.all(b.map((w) => p(y(m, w), y($, w))));
|
166
|
+
} else if (S.isFile() && V(m)) {
|
167
|
+
const w = await R(m, n), F = [];
|
168
|
+
Object.entries(w).forEach(([a, u]) => {
|
169
|
+
if (u.isKeyframes && u.css) {
|
170
|
+
const E = `${u.animationName}.css`, P = `css/${E}`, J = y(n, P);
|
171
|
+
s.push(E), k(J, u.css);
|
177
172
|
return;
|
178
173
|
}
|
179
|
-
if (!
|
180
|
-
const l =
|
181
|
-
name:
|
182
|
-
config:
|
183
|
-
}),
|
184
|
-
e[l.priority] || (e[l.priority] = []), e[l.priority].push(
|
185
|
-
const
|
186
|
-
|
174
|
+
if (!u.generator) return;
|
175
|
+
const l = u.generator._withBuildContext({
|
176
|
+
name: a,
|
177
|
+
config: h
|
178
|
+
}), j = `${l.hash}-${l.priority}.css`;
|
179
|
+
e[l.priority] || (e[l.priority] = []), e[l.priority].push(j), F.push(j);
|
180
|
+
const x = `css/${j}`, D = y(n, x);
|
181
|
+
k(D, l.css);
|
187
182
|
});
|
188
|
-
const d =
|
189
|
-
`),
|
190
|
-
|
183
|
+
const d = F.map((a) => `@import url('./${a}');`).join(`
|
184
|
+
`), C = M(m, 6), f = y(n, `css/${C}.css`);
|
185
|
+
k(f, d);
|
191
186
|
}
|
192
187
|
}
|
193
|
-
await
|
194
|
-
const
|
188
|
+
await p(t, n);
|
189
|
+
const i = s.map((m) => `@import url('./css/${m}');`).join(`
|
195
190
|
`);
|
196
|
-
let
|
191
|
+
let c = `@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
|
-
${
|
201
|
-
if (
|
202
|
-
const
|
195
|
+
${i}`;
|
196
|
+
if (h.importStrategy !== "component") {
|
197
|
+
const m = e.flat().map(($) => `@import url('./css/${$}');`).join(`
|
203
198
|
`);
|
204
|
-
|
199
|
+
c += m;
|
205
200
|
}
|
206
|
-
|
201
|
+
k(r, c);
|
207
202
|
} catch (s) {
|
208
203
|
console.error(s);
|
209
204
|
}
|
210
205
|
}, nt = async (t, s) => {
|
211
206
|
try {
|
212
207
|
const e = [], n = y(t, "./saltygen"), r = y(n, "index.css");
|
213
|
-
if (
|
214
|
-
const
|
215
|
-
Object.entries(
|
216
|
-
if (!
|
217
|
-
const
|
218
|
-
name:
|
219
|
-
config:
|
220
|
-
}), w = `${
|
221
|
-
e.push(w),
|
208
|
+
if (V(s)) {
|
209
|
+
const h = await _(t), p = await R(s, n);
|
210
|
+
Object.entries(p).forEach(([$, S]) => {
|
211
|
+
if (!S.generator) return;
|
212
|
+
const b = S.generator._withBuildContext({
|
213
|
+
name: $,
|
214
|
+
config: h
|
215
|
+
}), w = `${b.hash}-${b.priority}.css`, F = `css/${w}`, d = y(n, F);
|
216
|
+
e.push(w), k(d, b.css);
|
222
217
|
});
|
223
|
-
const
|
224
|
-
`), o = e.map((
|
218
|
+
const i = Z(r, "utf8").split(`
|
219
|
+
`), o = e.map(($) => `@import url('../saltygen/css/${$}');`), m = [.../* @__PURE__ */ new Set([...i, ...o])].join(`
|
225
220
|
`);
|
226
|
-
|
221
|
+
k(r, m);
|
227
222
|
}
|
228
223
|
} catch (e) {
|
229
224
|
console.error(e);
|
@@ -231,49 +226,55 @@ ${f}`;
|
|
231
226
|
}, rt = async (t, s) => {
|
232
227
|
try {
|
233
228
|
const e = y(t, "./saltygen");
|
234
|
-
if (
|
235
|
-
|
236
|
-
r.replace(/^(?!export\s)const\s.*/gm, (
|
237
|
-
const
|
238
|
-
let
|
239
|
-
Object.entries(
|
240
|
-
var
|
241
|
-
if (
|
242
|
-
|
243
|
-
|
229
|
+
if (V(s)) {
|
230
|
+
const r = Z(s, "utf8");
|
231
|
+
r.replace(/^(?!export\s)const\s.*/gm, (c) => `export ${c}`) !== r && await U(s, r);
|
232
|
+
const h = await _(t), p = await R(s, e);
|
233
|
+
let i = r;
|
234
|
+
Object.entries(p).forEach(([c, m]) => {
|
235
|
+
var E;
|
236
|
+
if (m.isKeyframes || !m.generator) return;
|
237
|
+
const $ = m.generator._withBuildContext({
|
238
|
+
name: c,
|
239
|
+
config: h
|
240
|
+
}), S = new RegExp(`\\s${c}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
241
|
+
if (!S) return console.error("Could not find the original declaration");
|
242
|
+
const b = (E = S.at(1)) == null ? void 0 : E.trim(), w = new RegExp(`\\s${c}[=\\s]+styled\\(`, "g").exec(i);
|
243
|
+
if (!w) return console.error("Could not find the original declaration");
|
244
|
+
const { index: F } = w;
|
245
|
+
let d = !1;
|
246
|
+
const C = setTimeout(() => d = !0, 5e3);
|
247
|
+
let f = 0, a = !1, u = 0;
|
248
|
+
for (; !a && !d; ) {
|
249
|
+
const P = i[F + f];
|
250
|
+
P === "(" && u++, P === ")" && u--, u === 0 && P === ")" && (a = !0), f > i.length && (d = !0), f++;
|
244
251
|
}
|
245
|
-
if (!
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
}), b = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
250
|
-
if (!b)
|
251
|
-
return console.error("Could not find the original declaration");
|
252
|
-
const j = (u = b.at(1)) == null ? void 0 : u.trim(), { element: w, variantKeys: C } = h.props, d = `${i} = styled(${j}, "${h.classNames}", "${h._callerName}", ${JSON.stringify(w)}, ${JSON.stringify(
|
253
|
-
C
|
254
|
-
)});`, S = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
|
255
|
-
f = f.replace(S, d);
|
252
|
+
if (!d) clearTimeout(C);
|
253
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
254
|
+
const l = F + f, j = i.slice(F, l), x = i, D = ` ${c} = styled(${b}, "${$.classNames}", "${$._callerName}", ${JSON.stringify($.props)});`;
|
255
|
+
i = i.replace(j, D), x === i && console.error("Minimize file failed to change content", { name: c, tagName: b });
|
256
256
|
});
|
257
|
-
const o =
|
258
|
-
return
|
259
|
-
${
|
257
|
+
const o = M(s, 6);
|
258
|
+
return h.importStrategy === "component" && (i = `import '../../saltygen/css/${o}.css';
|
259
|
+
${i}`), i = i.replace("{ styled }", "{ styledClient as styled }"), i = i.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), i;
|
260
260
|
}
|
261
261
|
} catch (e) {
|
262
|
-
console.error(e);
|
262
|
+
console.error("Error in minimizeFile:", e);
|
263
263
|
}
|
264
264
|
}, lt = (t) => ({
|
265
265
|
name: "stylegen",
|
266
266
|
buildStart: () => et(t),
|
267
267
|
load: async (s) => {
|
268
|
-
if (s
|
268
|
+
if (V(s))
|
269
269
|
return await rt(t, s);
|
270
270
|
},
|
271
271
|
watchChange: {
|
272
272
|
handler: async (s) => {
|
273
|
-
s
|
273
|
+
V(s) && await nt(t, s), s.includes("salty.config") && await W(t);
|
274
274
|
}
|
275
275
|
}
|
276
276
|
});
|
277
277
|
export {
|
278
|
+
lt as default,
|
278
279
|
lt as saltyPlugin
|
279
280
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@salty-css/vite",
|
3
|
-
"version": "0.0.1-alpha.
|
3
|
+
"version": "0.0.1-alpha.50",
|
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/vite/src",
|
22
23
|
"name": "vite"
|
23
24
|
},
|
24
25
|
"exports": {
|
@@ -26,5 +27,8 @@
|
|
26
27
|
"import": "./index.js",
|
27
28
|
"require": "./index.cjs"
|
28
29
|
}
|
30
|
+
},
|
31
|
+
"dependencies": {
|
32
|
+
"@salty-css/core": "^0.0.1-alpha.50"
|
29
33
|
}
|
30
34
|
}
|