@salty-css/vite 0.0.1-alpha.4 → 0.0.1-alpha.40
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 +12 -12
- package/index.d.ts +1 -0
- package/index.js +120 -130
- 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"),p=require("path"),d=require("fs"),K=require("fs/promises");function G(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 R=G(W),M=t=>String.fromCharCode(t+(t>25?39:97)),L=(t,s)=>{let e="",n;for(n=Math.abs(t);n>52;n=n/52|0)e=M(n%52)+e;return e=M(n%52)+e,e.length<s?e=e.padStart(s,"a"):e.length>s&&(e=e.slice(-s)),e},U=(t,s)=>{let e=s.length;for(;e;)t=t*33^s.charCodeAt(--e);return t},T=(t,s=3)=>{const e=U(5381,JSON.stringify(t))>>>0;return L(e,s)};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,(s,e)=>(e>0?"-":"")+s.toLowerCase()):""}const X=(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:u}=n;t=t.replace(r,$=>{const{value:a,css:f}=u($);return f&&e.push(f),a})}),{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},D=(t,s,e,n)=>{if(!t)return"";const r=[],u=Object.entries(t).reduce((a,[f,o])=>{const i=f.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return a;if(i==="variants")return Object.entries(o).forEach(([g,c])=>{c&&Object.entries(c).forEach(([m,l])=>{if(!l)return;const F=`${s}.${g}-${m}`,P=D(l,F);r.push(P)})}),a;if(i==="defaultVariants")return a;if(i==="compoundVariants")return o.forEach(g=>{const{css:c,...m}=g,l=Object.entries(m).reduce((P,[x,k])=>`${P}.${x}-${k}`,s),F=D(c,l);r.push(F)}),a;if(i.startsWith("@")){const g=D(o,s),c=`${i} {
|
2
|
+
${g.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return r.push(c),a}const
|
6
|
-
`);if(!s)return
|
7
|
-
`)},
|
8
|
-
`)}
|
9
|
-
`),
|
5
|
+
}`;return r.push(c),a}const b=f.includes("&")?i.replace("&",s):i.startsWith(":")?`${s}${i}`:`${s} ${i}`,C=D(o,b);return r.push(C),a}const y=i.startsWith("-")?i:N(i),h=(b,C=";")=>a=`${a}${b}${C}`,j=b=>h(`${y}:${b}`);if(typeof o=="number")return j(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return a;const{modifiers:S}={},O=function*(){yield q(o),yield X(o,S)}();for(const{result:b,additionalCss:C=[]}of O)o=b,C.forEach(g=>{const c=D(g,"");h(c,"")});return j(o)},"");if(!u)return r.join(`
|
6
|
+
`);if(!s)return u;let $="";return $=`${s} { ${u} }`,[$,...r].join(`
|
7
|
+
`)},Z=(t,s=[])=>{if(!t)return"";const e=[],n={};if(Object.entries(t).forEach(([r,u])=>{if(typeof u=="object"){if(!u)return;const $=r.trim(),a=Z(u,[...s,$]);e.push(a)}else n[r]=u}),Object.keys(n).length){const r=s.map(N).join("-"),u=D(n,`.${r}`);e.push(u)}return e.join(`
|
8
|
+
`)},E=t=>p.join(t,"./saltygen"),Y=["salty","css","styles","styled"],Q=(t=[])=>new RegExp(`\\.(${[...Y,...t].join("|")})\\.`),V=(t,s=[])=>Q(s).test(t),v=async t=>{const s=E(t),e=p.join(t,"salty.config.ts"),n=p.join(s,"salty.config.js");await R.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const r=Date.now(),{config:u}=await import(`${n}?t=${r}`);return u},I=async t=>{const s=await v(t),e=new Set,n=(g,c=[])=>g?Object.entries(g).flatMap(([m,l])=>{if(!l)return;if(typeof l=="object")return n(l,[...c,m]);const F=[...c,m].join(".");e.add(`"${F}"`);const P=[...c.map(N),N(m)].join("-"),{result:x}=q(l);return`--${P}: ${x};`}):[],r=g=>g?Object.entries(g).flatMap(([c,m])=>{const l=n(m);return c==="base"?l.join(""):`${c} { ${l.join("")} }`}):[],u=g=>g?Object.entries(g).flatMap(([c,m])=>Object.entries(m).flatMap(([l,F])=>{const P=n(F,[c]),x=`.${c}-${l}, [data-${c}="${l}"]`,k=P.join("");return`${x} { ${k} }`})):[],$=n(s.variables),a=r(s.responsiveVariables),f=u(s.conditionalVariables),o=E(t),i=p.join(o,"css/variables.css"),y=`:root { ${$.join("")} ${a.join("")} } ${f.join("")}`;d.writeFileSync(i,y);const h=p.join(o,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...e].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;d.writeFileSync(h,S);const w=p.join(o,"css/global.css"),O=D(s.global,"");d.writeFileSync(w,O);const b=p.join(o,"css/templates.css"),C=Z(s.templates);d.writeFileSync(b,C)},_=async(t,s)=>{const e=T(t),n=p.join(s,"js",e+".js");await R.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 s=E(t),e=p.join(s,"salty.config.js"),{config:n}=await import(e);return n},tt=async t=>{try{const s=[],e=[],n=E(t),r=p.join(n,"index.css");(()=>{d.existsSync(n)&&J.execSync("rm -rf "+n),d.mkdirSync(n),d.mkdirSync(p.join(n,"css")),d.mkdirSync(p.join(n,"types"))})(),await I(t);const $=await A(t);async function a(y,h){const j=d.statSync(y);if(j.isDirectory()){const S=d.readdirSync(y);await Promise.all(S.map(w=>a(p.join(y,w),p.join(h,w))))}else if(j.isFile()&&V(y)){const w=await _(y,n),O=[];Object.entries(w).forEach(([c,m])=>{if(m.isKeyframes&&m.css){const k=`${m.animationName}.css`,B=`css/${k}`,H=p.join(n,B);s.push(k),d.writeFileSync(H,m.css);return}if(!m.generator)return;const l=m.generator._withBuildContext({name:c,config:$}),F=`${l.hash}-${l.priority}.css`;e[l.priority]||(e[l.priority]=[]),e[l.priority].push(F),O.push(F);const P=`css/${F}`,x=p.join(n,P);d.writeFileSync(x,l.css)});const b=O.map(c=>`@import url('./${c}');`).join(`
|
9
|
+
`),C=T(y,6),g=p.join(n,`css/${C}.css`);d.writeFileSync(g,b)}}await a(t,n);const f=s.map(y=>`@import url('./css/${y}');`).join(`
|
10
10
|
`);let i=`@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
|
-
${f}`;if($.importStrategy!=="component"){const
|
15
|
-
`);i+=
|
16
|
-
`),o=e.map(
|
17
|
-
`);d.writeFileSync(r,
|
18
|
-
${f}`),f=f.replace("{ styled }","{ styledClient as styled }"),f=f.replace("@salty-css/react/styled","@salty-css/react/styled-client"),f}}catch(e){console.error(e)}},
|
14
|
+
${f}`;if($.importStrategy!=="component"){const y=e.flat().map(h=>`@import url('./css/${h}');`).join(`
|
15
|
+
`);i+=y}d.writeFileSync(r,i)}catch(s){console.error(s)}},st=async(t,s)=>{try{const e=[],n=p.join(t,"./saltygen"),r=p.join(n,"index.css");if(V(s)){const $=await A(t),a=await _(s,n);Object.entries(a).forEach(([h,j])=>{if(!j.generator)return;const S=j.generator._withBuildContext({name:h,config:$}),w=`${S.hash}-${S.priority}.css`,O=`css/${w}`,b=p.join(n,O);e.push(w),d.writeFileSync(b,S.css)});const f=d.readFileSync(r,"utf8").split(`
|
16
|
+
`),o=e.map(h=>`@import url('../saltygen/css/${h}');`),y=[...new Set([...f,...o])].join(`
|
17
|
+
`);d.writeFileSync(r,y)}}catch(e){console.error(e)}},et=async(t,s)=>{try{const e=p.join(t,"./saltygen");if(V(s)){const r=d.readFileSync(s,"utf8");r.replace(/^(?!export\s)const\s.*/gm,i=>`export ${i}`)!==r&&await K.writeFile(s,r);const $=await A(t),a=await _(s,e);let f=r;Object.entries(a).forEach(([i,y])=>{var b;if(y.isKeyframes||!y.generator)return;const h=y.generator._withBuildContext({name:i,config:$}),j=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!j)return console.error("Could not find the original declaration");const S=(b=j.at(1))==null?void 0:b.trim(),w=`${i} = styled(${S}, "${h.classNames}", "${h._callerName}", ${JSON.stringify(h.props)});`,O=new RegExp(`${i}[=\\s]+[^()]+styled\\(([^)]|\\n|\\(.*\\){1})+\\)$`,"gm");f=f.replace(O,w)});const o=T(s,6);return $.importStrategy==="component"&&(f=`import '../../saltygen/css/${o}.css';
|
18
|
+
${f}`),f=f.replace("{ styled }","{ styledClient as styled }"),f=f.replace("@salty-css/react/styled","@salty-css/react/styled-client"),f}}catch(e){console.error("Error in minimizeFile",e)}},z=t=>({name:"stylegen",buildStart:()=>tt(t),load:async s=>{if(V(s))return await et(t,s)},watchChange:{handler:async s=>{V(s)&&await st(t,s),s.includes("salty.config")&&await I(t)}}});exports.default=z;exports.saltyPlugin=z;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -1,111 +1,106 @@
|
|
1
|
-
import * as
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
|
7
|
-
const Z = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Y = (t, s) => {
|
1
|
+
import * as Z from "esbuild";
|
2
|
+
import { execSync as K } from "child_process";
|
3
|
+
import { join as p } from "path";
|
4
|
+
import { writeFileSync as C, existsSync as q, mkdirSync as T, statSync as G, readdirSync as L, readFileSync as I } from "fs";
|
5
|
+
import { writeFile as U } from "fs/promises";
|
6
|
+
const _ = (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 = _(n % 52) + e;
|
9
|
+
return e = _(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
14
|
}, A = (t, s = 3) => {
|
16
|
-
const e =
|
17
|
-
return
|
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 V(t) {
|
19
|
+
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()) : "";
|
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
|
-
const { pattern: r, transform:
|
26
|
+
const { pattern: r, transform: u } = n;
|
28
27
|
t = t.replace(r, ($) => {
|
29
|
-
const { value: a, css: f } =
|
28
|
+
const { value: a, css: f } = u($);
|
30
29
|
return f && e.push(f), a;
|
31
30
|
});
|
32
31
|
}), { result: t, additionalCss: e };
|
33
|
-
},
|
34
|
-
|
32
|
+
}, B = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${V(n[1].replaceAll(".", "-"))})`) } : { result: t }, O = (t, s, e, n) => {
|
33
|
+
if (!t) return "";
|
34
|
+
const r = [], u = Object.entries(t).reduce((a, [f, o]) => {
|
35
35
|
const i = f.trim();
|
36
36
|
if (typeof o == "function" && (o = o()), typeof o == "object") {
|
37
37
|
if (!o) return a;
|
38
38
|
if (i === "variants")
|
39
|
-
return Object.entries(o).forEach(([
|
39
|
+
return Object.entries(o).forEach(([g, c]) => {
|
40
40
|
c && Object.entries(c).forEach(([m, l]) => {
|
41
41
|
if (!l) return;
|
42
|
-
const
|
43
|
-
r.push(
|
42
|
+
const S = `${s}.${g}-${m}`, D = O(l, S);
|
43
|
+
r.push(D);
|
44
44
|
});
|
45
45
|
}), a;
|
46
46
|
if (i === "defaultVariants")
|
47
47
|
return a;
|
48
48
|
if (i === "compoundVariants")
|
49
|
-
return o.forEach((
|
50
|
-
const { css: c, ...m } =
|
51
|
-
r.push(
|
49
|
+
return o.forEach((g) => {
|
50
|
+
const { css: c, ...m } = g, l = Object.entries(m).reduce((D, [N, P]) => `${D}.${N}-${P}`, s), S = O(c, l);
|
51
|
+
r.push(S);
|
52
52
|
}), a;
|
53
53
|
if (i.startsWith("@")) {
|
54
|
-
const
|
55
|
-
${
|
54
|
+
const g = O(o, s), c = `${i} {
|
55
|
+
${g.replace(`
|
56
56
|
`, `
|
57
57
|
`)}
|
58
58
|
}`;
|
59
59
|
return r.push(c), a;
|
60
60
|
}
|
61
|
-
const d = f.includes("&") ? i.replace("&", s) : i.startsWith(":") ? `${s}${i}` : `${s} ${i}`,
|
62
|
-
return r.push(
|
61
|
+
const d = f.includes("&") ? i.replace("&", s) : i.startsWith(":") ? `${s}${i}` : `${s} ${i}`, x = O(o, d);
|
62
|
+
return r.push(x), a;
|
63
63
|
}
|
64
|
-
const
|
64
|
+
const y = i.startsWith("-") ? i : V(i), h = (d, x = ";") => a = `${a}${d}${x}`, b = (d) => h(`${y}:${d}`);
|
65
65
|
if (typeof o == "number") return b(o);
|
66
66
|
if (typeof o != "string")
|
67
67
|
if ("toString" in o) o = o.toString();
|
68
68
|
else return a;
|
69
|
-
const { modifiers: j } = {},
|
70
|
-
yield
|
69
|
+
const { modifiers: j } = {}, F = function* () {
|
70
|
+
yield B(o), yield Q(o, j);
|
71
71
|
}();
|
72
|
-
for (const { result: d, additionalCss:
|
73
|
-
o = d,
|
74
|
-
const c = O(
|
72
|
+
for (const { result: d, additionalCss: x = [] } of F)
|
73
|
+
o = d, x.forEach((g) => {
|
74
|
+
const c = O(g, "");
|
75
75
|
h(c, "");
|
76
76
|
});
|
77
77
|
return b(o);
|
78
78
|
}, "");
|
79
|
-
if (!
|
79
|
+
if (!u) return r.join(`
|
80
80
|
`);
|
81
|
-
if (!s) return
|
81
|
+
if (!s) return u;
|
82
82
|
let $ = "";
|
83
|
-
return $ = `${s} { ${
|
83
|
+
return $ = `${s} { ${u} }`, [$, ...r].join(`
|
84
84
|
`);
|
85
|
-
},
|
85
|
+
}, H = (t, s = []) => {
|
86
|
+
if (!t) return "";
|
86
87
|
const e = [], n = {};
|
87
|
-
if (Object.entries(t).forEach(([r,
|
88
|
-
if (typeof
|
89
|
-
if (!
|
90
|
-
const $ = r.trim(), a =
|
88
|
+
if (Object.entries(t).forEach(([r, u]) => {
|
89
|
+
if (typeof u == "object") {
|
90
|
+
if (!u) return;
|
91
|
+
const $ = r.trim(), a = H(u, [...s, $]);
|
91
92
|
e.push(a);
|
92
93
|
} else
|
93
|
-
n[r] =
|
94
|
+
n[r] = u;
|
94
95
|
}), Object.keys(n).length) {
|
95
|
-
const r = s.map(
|
96
|
-
e.push(
|
96
|
+
const r = s.map(V).join("-"), u = O(n, `.${r}`);
|
97
|
+
e.push(u);
|
97
98
|
}
|
98
99
|
return e.join(`
|
99
100
|
`);
|
100
|
-
}
|
101
|
-
|
102
|
-
|
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");
|
108
|
-
await I.build({
|
101
|
+
}, E = (t) => p(t, "./saltygen"), v = ["salty", "css", "styles", "styled"], tt = (t = []) => new RegExp(`\\.(${[...v, ...t].join("|")})\\.`), k = (t, s = []) => tt(s).test(t), st = async (t) => {
|
102
|
+
const s = E(t), e = p(t, "salty.config.ts"), n = p(s, "salty.config.js");
|
103
|
+
await Z.build({
|
109
104
|
entryPoints: [e],
|
110
105
|
minify: !0,
|
111
106
|
treeShaking: !0,
|
@@ -114,33 +109,33 @@ const E = (t) => y(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"],
|
|
114
109
|
format: "esm",
|
115
110
|
external: ["react"]
|
116
111
|
});
|
117
|
-
const r = Date.now(), { config:
|
118
|
-
return
|
119
|
-
},
|
120
|
-
const s = await st(t), e = /* @__PURE__ */ new Set(), n = (
|
112
|
+
const r = Date.now(), { config: u } = await import(`${n}?t=${r}`);
|
113
|
+
return u;
|
114
|
+
}, W = async (t) => {
|
115
|
+
const s = await st(t), e = /* @__PURE__ */ new Set(), n = (g, c = []) => g ? Object.entries(g).flatMap(([m, l]) => {
|
121
116
|
if (!l) return;
|
122
117
|
if (typeof l == "object") return n(l, [...c, m]);
|
123
|
-
const
|
124
|
-
e.add(`"${
|
125
|
-
const
|
126
|
-
return `--${
|
127
|
-
}) : [], r = (
|
118
|
+
const S = [...c, m].join(".");
|
119
|
+
e.add(`"${S}"`);
|
120
|
+
const D = [...c.map(V), V(m)].join("-"), { result: N } = B(l);
|
121
|
+
return `--${D}: ${N};`;
|
122
|
+
}) : [], r = (g) => g ? Object.entries(g).flatMap(([c, m]) => {
|
128
123
|
const l = n(m);
|
129
124
|
return c === "base" ? l.join("") : `${c} { ${l.join("")} }`;
|
130
|
-
}) : [],
|
131
|
-
const
|
132
|
-
return `${
|
133
|
-
})) : [], $ = n(s.variables), a = r(s.responsiveVariables), f =
|
134
|
-
|
135
|
-
const h =
|
136
|
-
|
137
|
-
const w =
|
138
|
-
|
139
|
-
const d =
|
140
|
-
|
125
|
+
}) : [], u = (g) => g ? Object.entries(g).flatMap(([c, m]) => Object.entries(m).flatMap(([l, S]) => {
|
126
|
+
const D = n(S, [c]), N = `.${c}-${l}, [data-${c}="${l}"]`, P = D.join("");
|
127
|
+
return `${N} { ${P} }`;
|
128
|
+
})) : [], $ = n(s.variables), a = r(s.responsiveVariables), f = u(s.conditionalVariables), o = E(t), i = p(o, "css/variables.css"), y = `:root { ${$.join("")} ${a.join("")} } ${f.join("")}`;
|
129
|
+
C(i, y);
|
130
|
+
const h = p(o, "types/css-tokens.d.ts"), j = `type VariableTokens = ${[...e].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
131
|
+
C(h, j);
|
132
|
+
const w = p(o, "css/global.css"), F = O(s.global, "");
|
133
|
+
C(w, F);
|
134
|
+
const d = p(o, "css/templates.css"), x = H(s.templates);
|
135
|
+
C(d, x);
|
141
136
|
}, R = async (t, s) => {
|
142
|
-
const e = A(t), n =
|
143
|
-
await
|
137
|
+
const e = A(t), n = p(s, "js", e + ".js");
|
138
|
+
await Z.build({
|
144
139
|
entryPoints: [t],
|
145
140
|
minify: !0,
|
146
141
|
treeShaking: !0,
|
@@ -153,45 +148,45 @@ const E = (t) => y(t, "./saltygen"), tt = ["salty", "css", "styles", "styled"],
|
|
153
148
|
});
|
154
149
|
const r = Date.now();
|
155
150
|
return await import(`${n}?t=${r}`);
|
156
|
-
},
|
157
|
-
const s = E(t), e =
|
151
|
+
}, M = async (t) => {
|
152
|
+
const s = E(t), e = p(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 = E(t), r =
|
156
|
+
const s = [], e = [], n = E(t), r = p(n, "index.css");
|
162
157
|
(() => {
|
163
|
-
q(n) &&
|
164
|
-
})(), await
|
165
|
-
const $ = await
|
166
|
-
async function a(
|
167
|
-
const b = G(
|
158
|
+
q(n) && K("rm -rf " + n), T(n), T(p(n, "css")), T(p(n, "types"));
|
159
|
+
})(), await W(t);
|
160
|
+
const $ = await M(t);
|
161
|
+
async function a(y, h) {
|
162
|
+
const b = G(y);
|
168
163
|
if (b.isDirectory()) {
|
169
|
-
const j =
|
170
|
-
await Promise.all(j.map((w) => a(y
|
171
|
-
} else if (b.isFile() &&
|
172
|
-
const w = await R(
|
164
|
+
const j = L(y);
|
165
|
+
await Promise.all(j.map((w) => a(p(y, w), p(h, w))));
|
166
|
+
} else if (b.isFile() && k(y)) {
|
167
|
+
const w = await R(y, n), F = [];
|
173
168
|
Object.entries(w).forEach(([c, m]) => {
|
174
169
|
if (m.isKeyframes && m.css) {
|
175
|
-
const
|
176
|
-
s.push(
|
170
|
+
const P = `${m.animationName}.css`, z = `css/${P}`, J = p(n, z);
|
171
|
+
s.push(P), C(J, m.css);
|
177
172
|
return;
|
178
173
|
}
|
179
174
|
if (!m.generator) return;
|
180
175
|
const l = m.generator._withBuildContext({
|
181
176
|
name: c,
|
182
177
|
config: $
|
183
|
-
}),
|
184
|
-
e[l.priority] || (e[l.priority] = []), e[l.priority].push(
|
185
|
-
const
|
186
|
-
|
178
|
+
}), S = `${l.hash}-${l.priority}.css`;
|
179
|
+
e[l.priority] || (e[l.priority] = []), e[l.priority].push(S), F.push(S);
|
180
|
+
const D = `css/${S}`, N = p(n, D);
|
181
|
+
C(N, l.css);
|
187
182
|
});
|
188
|
-
const d =
|
189
|
-
`),
|
190
|
-
|
183
|
+
const d = F.map((c) => `@import url('./${c}');`).join(`
|
184
|
+
`), x = A(y, 6), g = p(n, `css/${x}.css`);
|
185
|
+
C(g, d);
|
191
186
|
}
|
192
187
|
}
|
193
188
|
await a(t, n);
|
194
|
-
const f = s.map((
|
189
|
+
const f = s.map((y) => `@import url('./css/${y}');`).join(`
|
195
190
|
`);
|
196
191
|
let i = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
197
192
|
|
@@ -199,81 +194,76 @@ ${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@
|
|
199
194
|
`)}
|
200
195
|
${f}`;
|
201
196
|
if ($.importStrategy !== "component") {
|
202
|
-
const
|
197
|
+
const y = e.flat().map((h) => `@import url('./css/${h}');`).join(`
|
203
198
|
`);
|
204
|
-
i +=
|
199
|
+
i += y;
|
205
200
|
}
|
206
|
-
|
201
|
+
C(r, i);
|
207
202
|
} catch (s) {
|
208
203
|
console.error(s);
|
209
204
|
}
|
210
205
|
}, nt = async (t, s) => {
|
211
206
|
try {
|
212
|
-
const e = [], n =
|
213
|
-
if (
|
214
|
-
const $ = await
|
207
|
+
const e = [], n = p(t, "./saltygen"), r = p(n, "index.css");
|
208
|
+
if (k(s)) {
|
209
|
+
const $ = await M(t), a = await R(s, n);
|
215
210
|
Object.entries(a).forEach(([h, b]) => {
|
216
211
|
if (!b.generator) return;
|
217
212
|
const j = b.generator._withBuildContext({
|
218
213
|
name: h,
|
219
214
|
config: $
|
220
|
-
}), w = `${j.hash}-${j.priority}.css`,
|
221
|
-
e.push(w),
|
215
|
+
}), w = `${j.hash}-${j.priority}.css`, F = `css/${w}`, d = p(n, F);
|
216
|
+
e.push(w), C(d, j.css);
|
222
217
|
});
|
223
|
-
const f =
|
224
|
-
`), o = e.map((h) => `@import url('../saltygen/css/${h}');`),
|
218
|
+
const f = I(r, "utf8").split(`
|
219
|
+
`), o = e.map((h) => `@import url('../saltygen/css/${h}');`), y = [.../* @__PURE__ */ new Set([...f, ...o])].join(`
|
225
220
|
`);
|
226
|
-
|
221
|
+
C(r, y);
|
227
222
|
}
|
228
223
|
} catch (e) {
|
229
224
|
console.error(e);
|
230
225
|
}
|
231
226
|
}, rt = async (t, s) => {
|
232
227
|
try {
|
233
|
-
const e =
|
234
|
-
if (
|
235
|
-
|
236
|
-
r.replace(/^(?!export\s)const\s.*/gm, (i) => `export ${i}`) !== r && await
|
237
|
-
const $ = await
|
228
|
+
const e = p(t, "./saltygen");
|
229
|
+
if (k(s)) {
|
230
|
+
const r = I(s, "utf8");
|
231
|
+
r.replace(/^(?!export\s)const\s.*/gm, (i) => `export ${i}`) !== r && await U(s, r);
|
232
|
+
const $ = await M(t), a = await R(s, e);
|
238
233
|
let f = r;
|
239
|
-
Object.entries(a).forEach(([i,
|
240
|
-
var
|
241
|
-
if (
|
242
|
-
|
243
|
-
return;
|
244
|
-
}
|
245
|
-
if (!p.generator) return;
|
246
|
-
const h = p.generator._withBuildContext({
|
234
|
+
Object.entries(a).forEach(([i, y]) => {
|
235
|
+
var d;
|
236
|
+
if (y.isKeyframes || !y.generator) return;
|
237
|
+
const h = y.generator._withBuildContext({
|
247
238
|
name: i,
|
248
239
|
config: $
|
249
240
|
}), b = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
250
241
|
if (!b)
|
251
242
|
return console.error("Could not find the original declaration");
|
252
|
-
const j = (
|
253
|
-
|
254
|
-
)});`, S = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),[^;]+;`, "g");
|
255
|
-
f = f.replace(S, d);
|
243
|
+
const j = (d = b.at(1)) == null ? void 0 : d.trim(), w = `${i} = styled(${j}, "${h.classNames}", "${h._callerName}", ${JSON.stringify(h.props)});`, F = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^)]|\\n|\\(.*\\){1})+\\)$`, "gm");
|
244
|
+
f = f.replace(F, w);
|
256
245
|
});
|
257
246
|
const o = A(s, 6);
|
258
247
|
return $.importStrategy === "component" && (f = `import '../../saltygen/css/${o}.css';
|
259
248
|
${f}`), f = f.replace("{ styled }", "{ styledClient as styled }"), f = f.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), f;
|
260
249
|
}
|
261
250
|
} catch (e) {
|
262
|
-
console.error(e);
|
251
|
+
console.error("Error in minimizeFile", e);
|
263
252
|
}
|
264
253
|
}, lt = (t) => ({
|
265
254
|
name: "stylegen",
|
266
255
|
buildStart: () => et(t),
|
267
256
|
load: async (s) => {
|
268
|
-
if (s
|
257
|
+
if (k(s))
|
269
258
|
return await rt(t, s);
|
270
259
|
},
|
271
260
|
watchChange: {
|
272
261
|
handler: async (s) => {
|
273
|
-
s
|
262
|
+
k(s) && await nt(t, s), s.includes("salty.config") && await W(t);
|
274
263
|
}
|
275
264
|
}
|
276
265
|
});
|
277
266
|
export {
|
267
|
+
lt as default,
|
278
268
|
lt as saltyPlugin
|
279
269
|
};
|
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.40",
|
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.40"
|
29
33
|
}
|
30
34
|
}
|