@salty-css/vite 0.0.1-alpha.21 → 0.0.1-alpha.210
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 +143 -26
- package/index.cjs +40 -16
- package/index.d.ts +3 -8
- package/index.js +582 -231
- package/package.json +9 -4
package/README.md
CHANGED
@@ -1,15 +1,132 @@
|
|
1
|
-
|
1
|
+

|
2
2
|
|
3
|
-
|
3
|
+
# Salty CSS - CSS-in-JS library that is kinda sweet
|
4
4
|
|
5
|
-
|
5
|
+
Is there anything saltier than CSS in frontend web development? Salty CSS is built to provide better developer experience for developers looking for performant and feature rich CSS-in-JS solutions.
|
6
6
|
|
7
|
-
|
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`
|
7
|
+
## Features
|
11
8
|
|
12
|
-
|
9
|
+
- Build time compilation to achieve awesome runtime performance and minimal size
|
10
|
+
- Next.js, React Server Components, Vite and Webpack support
|
11
|
+
- Type safety with out of the box TypeScript and ESLint plugin
|
12
|
+
- Advanced CSS variables configuration to allow smooth token usage
|
13
|
+
- Style templates to create reusable styles easily
|
14
|
+
|
15
|
+
## Get started
|
16
|
+
|
17
|
+
Fastest way to get started with any framework is `npx salty-css init [directory]` command
|
18
|
+
|
19
|
+
- Next.js → [Next.js guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
|
20
|
+
- React + Vite → [React + Vite guide](#react--vite) + [React example code](#code-examples)
|
21
|
+
- React + Webpack → Guide coming soon
|
22
|
+
|
23
|
+
## Useful commands
|
24
|
+
|
25
|
+
- Create component: `npx salty-css generate [filePath]`
|
26
|
+
- Build: `npx salty-css build [directory]`
|
27
|
+
- Update Salty CSS packages: `npx salty-css up`
|
28
|
+
|
29
|
+
## Salty CSS styled function
|
30
|
+
|
31
|
+
```ts
|
32
|
+
// components/wrapper.css.ts
|
33
|
+
import { styled } from '@salty-css/react/styled';
|
34
|
+
|
35
|
+
// Define a component with styled function. First argument is the component name or existing component to extend and second argument is the object containing the styles and other options
|
36
|
+
export const Component = styled('div', {
|
37
|
+
className: 'wrapper', // Define custom class name that will be included for this component
|
38
|
+
element: 'section', // Define the html element that will be rendered for this component, overrides the first 'div' argument
|
39
|
+
base: {
|
40
|
+
// 👉 Add your CSS-in-JS base styles here! 👈
|
41
|
+
},
|
42
|
+
variants: {
|
43
|
+
// Define conditional styles that will be applied to the component based on the variant prop values
|
44
|
+
},
|
45
|
+
compoundVariants: [
|
46
|
+
// Define conditional styles that will be applied to the component based on the combination of variant prop values
|
47
|
+
],
|
48
|
+
defaultVariants: {
|
49
|
+
// Set default variant prop values
|
50
|
+
},
|
51
|
+
defaultProps: {
|
52
|
+
// Add additional default props for the component (eg, id and other html element attributes)
|
53
|
+
},
|
54
|
+
passProps: true, // Pass variant props to the rendered element / parent component (default: false)
|
55
|
+
});
|
56
|
+
```
|
57
|
+
|
58
|
+
## Salty CSS CLI
|
59
|
+
|
60
|
+
In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
|
61
|
+
|
62
|
+
- Initialize project → `npx salty-css init [directory]` - Installs required packages, detects framework in use and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory.
|
63
|
+
- Generate component → `npx salty-css update [version]` - Update @salty-css packages in your repository. Default version is "latest". Additional options like `--dir`, `--tag`, `--name` and `--className` are also supported.
|
64
|
+
- Build files → `npx salty-css build [directory]` - Compile Salty CSS related files in your project. This should not be needed if you are using tools like Next.js or Vite
|
65
|
+
|
66
|
+
## Usage
|
67
|
+
|
68
|
+
### Next.js
|
69
|
+
|
70
|
+

|
71
|
+
|
72
|
+
Salty CSS provides Next.js App & Pages router support with full React Server Components support.
|
73
|
+
|
74
|
+
### Add Salty CSS to Next.js
|
75
|
+
|
76
|
+
1. In your existing Next.js repository you can run `npx salty-css init` to automatically configure Salty CSS.
|
77
|
+
2. Create your first Salty CSS component with `npx salty-css generate [filePath]` (e.g. src/custom-wrapper)
|
78
|
+
3. Import your component for example to `page.tsx` and see it working!
|
79
|
+
|
80
|
+
And note: steps 2 & 3 are just to show how get new components up and running, step 1 does all of the important stuff 🤯
|
81
|
+
|
82
|
+
#### Manual configuration
|
83
|
+
|
84
|
+
1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
|
85
|
+
2. Create `salty.config.ts` to your app directory
|
86
|
+
3. Add Salty CSS plugin to next.js config
|
87
|
+
|
88
|
+
- **Next.js 15:** In `next.config.ts` add import for salty plugin `import { withSaltyCss } from '@salty-css/next';` and then add `withSaltyCss` to wrap your nextConfig export like so `export default withSaltyCss(nextConfig);`
|
89
|
+
- **Next.js 14 and older:** In `next.config.js` add import for salty plugin `const { withSaltyCss } = require('@salty-css/next');` and then add `withSaltyCss` to wrap your nextConfig export like so `module.exports = withSaltyCss(nextConfig);`
|
90
|
+
|
91
|
+
4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
|
92
|
+
5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
|
93
|
+
6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
|
94
|
+
|
95
|
+
[Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
|
96
|
+
|
97
|
+
---
|
98
|
+
|
99
|
+
### React + Vite
|
100
|
+
|
101
|
+

|
102
|
+
|
103
|
+
### Add Salty CSS to your React + Vite app
|
104
|
+
|
105
|
+
1. In your existing Vite repository you can run `npx salty-css init` to automatically configure Salty CSS.
|
106
|
+
2. Create your first Salty CSS component with `npx salty-css generate [filePath]` (e.g. src/custom-wrapper)
|
107
|
+
3. Import your component for example to `main.tsx` and see it working!
|
108
|
+
|
109
|
+
And note: steps 2 & 3 are just to show how get new components up and running, step 1 does all of the important stuff 🤯
|
110
|
+
|
111
|
+
#### Manual configuration
|
112
|
+
|
113
|
+
1. For Vite support install `npm i @salty-css/vite @salty-css/core`
|
114
|
+
2. In `vite.config` add import for salty plugin `import { saltyPlugin } from '@salty-css/vite';` and then add `saltyPlugin(__dirname)` to your vite configuration plugins
|
115
|
+
3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
|
116
|
+
4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
|
117
|
+
5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
|
118
|
+
|
119
|
+
[Check out react example code](#code-examples)
|
120
|
+
|
121
|
+
---
|
122
|
+
|
123
|
+
### Create components
|
124
|
+
|
125
|
+
1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
|
126
|
+
|
127
|
+
## Code examples
|
128
|
+
|
129
|
+
### Basic usage example with Button
|
13
130
|
|
14
131
|
**Salty config**
|
15
132
|
|
@@ -31,23 +148,6 @@ export const config = defineConfig({
|
|
31
148
|
});
|
32
149
|
```
|
33
150
|
|
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
151
|
**Wrapper** (`components/wrapper/wrapper.css.ts`)
|
52
152
|
|
53
153
|
```tsx
|
@@ -72,7 +172,7 @@ export const Button = styled('button', {
|
|
72
172
|
padding: `0.6em 1.2em`,
|
73
173
|
border: '1px solid currentColor',
|
74
174
|
background: 'transparent',
|
75
|
-
color: 'currentColor
|
175
|
+
color: 'currentColor',
|
76
176
|
cursor: 'pointer',
|
77
177
|
transition: '200ms',
|
78
178
|
textDecoration: 'none',
|
@@ -108,4 +208,21 @@ export const Button = styled('button', {
|
|
108
208
|
});
|
109
209
|
```
|
110
210
|
|
211
|
+
**Your React component file**
|
212
|
+
|
213
|
+
```tsx
|
214
|
+
import { Wrapper } from '../components/wrapper/wrapper.css';
|
215
|
+
import { Button } from '../components/button/button.css';
|
216
|
+
|
217
|
+
export const IndexPage = () => {
|
218
|
+
return (
|
219
|
+
<Wrapper>
|
220
|
+
<Button variant="solid" onClick={() => alert('It is a button.')}>
|
221
|
+
Outlined
|
222
|
+
</Button>
|
223
|
+
</Wrapper>
|
224
|
+
);
|
225
|
+
};
|
226
|
+
```
|
227
|
+
|
111
228
|
More examples coming soon
|
package/index.cjs
CHANGED
@@ -1,18 +1,42 @@
|
|
1
|
-
"use strict";Object.
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
`);if(!
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
`);let i=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const kt=require("esbuild"),_t=require("child_process"),l=require("path"),d=require("fs"),tt=require("fs/promises"),B=require("winston");var rt=typeof document<"u"?document.currentScript:null;function Dt(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 gt=Dt(kt),pt=t=>String.fromCharCode(t+(t>25?39:97)),Ot=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=pt(n%52)+s;return s=pt(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},Et=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},v=(t,e=5)=>{const s=Et(5381,JSON.stringify(t))>>>0;return Ot(s,e)};function V(t){return t?typeof t!="string"?V(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 Tt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(o=>{const{pattern:r,transform:a}=o;s=s.replace(r,g=>{const{value:C,css:f}=a(g);return f&&n.push(f),C})}),{transformed:s,additionalCss:n}},ht=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...o)=>`var(--${V(o[1].replaceAll(".","-"))})`)},Mt=ht(),Rt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Vt=(t,e,s)=>Rt.some(o=>typeof o=="string"?o===t:o.test(t))?`${e}px`:`${e}`,At=["Webkit","Moz","ms","O"],Jt=t=>t.startsWith("-")?t:At.some(e=>t.startsWith(e))?`-${V(t)}`:V(t),Y=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const o=new Set,a=Object.entries(t).map(async([m,i])=>{const y=m.trim(),k=Jt(y),P=(_,T=";")=>`${k}:${_}${T}`;if(typeof i=="function"&&(i=i({scope:e,config:s})),i instanceof Promise&&(i=await i),typeof i=="object"){if(!i)return;if(i.isColor)return P(i.toString());if(y==="defaultVariants")return;if(y==="variants"){const j=Object.entries(i);for(const[O,c]of j){if(!c)return;const h=Object.entries(c);for(const[b,u]of h){if(!u)return;const S=`${e}.${O}-${b}`;(await Y(u,S,s)).forEach(M=>o.add(M))}}return}if(y==="compoundVariants"){for(const j of i){const{css:O,...c}=j,h=Object.entries(c).reduce((u,[S,N])=>`${u}.${S}-${N}`,e);(await Y(O,h,s)).forEach(u=>o.add(u))}return}if(y.startsWith("@")){const j=y,O=await G(i,e,s),c=`${j} { ${O} }`;o.add(c);return}const _=m.includes("&")?y.replace("&",e):y.startsWith(":")?`${e}${y}`:`${e} ${y}`;(await Y(i,_,s)).forEach(j=>o.add(j));return}if(typeof i=="number"){const _=Vt(k,i);return P(_)}if(typeof i!="string")if("toString"in i)i=i.toString();else throw new Error(`Invalid value type for property ${k}`);return P(i)}),{modifiers:g}={},C=[ht(),Tt(g)],p=(await Promise.all(a).then(m=>Promise.all(m.map(i=>C.reduce(async(y,k)=>{const P=await y;if(!P)return P;const R=await k(P);if(!R)return P;const{transformed:_,additionalCss:T}=R;let j="";if(T)for(const O of T)j+=await G(O,"");return`${j}${_}`},Promise.resolve(i)))))).filter(m=>m!==void 0).join(`
|
2
|
+
`);if(!p.trim())return Array.from(o);const w=e?`${e} {
|
3
|
+
${p}
|
4
|
+
}`:p;return o.has(w)?Array.from(o):[w,...o]},G=async(t,e,s,n=!1)=>(await Y(t,e,s,n)).join(`
|
5
|
+
`),wt=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[o,r]of Object.entries(t))if(typeof r!="function")if(r&&typeof r=="object"){const a=o.trim(),g=await wt(r,[...e,a]);s.push(g)}else n[o]=r;if(Object.keys(n).length){const o=e.map(V).join("-"),r="t_"+v(o,4),a=await G(n,`.${o}, .${r}`);s.push(a)}return s.join(`
|
6
|
+
`)},vt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=$t(n).map(o=>`"${o}"`).join(" | ")),e),{}):{},$t=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,o])=>{const r=e?`${e}.${n}`:n;return typeof o=="object"?$t(o,r,s):s.add(e)}),[...s]):[],bt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=l.join(t,"package.json");return d.existsSync(e)?e:bt(l.join(t,".."))},zt=async t=>{const e=bt(t);return await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Wt=async t=>{const e=await zt(t);if(e)return e.type};let I;const St=async t=>{if(I)return I;const e=await Wt(t);return e==="module"?I="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:rt&&rt.tagName.toUpperCase()==="SCRIPT"&&rt.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(I="cjs"),I||"esm"},it=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]});function jt(t){return t?typeof t!="string"?jt(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 It={"*, *::before, *::after":{boxSizing:"border-box"},"*":{margin:0},html:{lineHeight:1.15,textSizeAdjust:"100%",WebkitFontSmoothing:"antialiased"},"img, picture, video, canvas, svg":{display:"block",maxWidth:"100%"},"p, h1, h2, h3, h4, h5, h6":{overflowWrap:"break-word"},p:{textWrap:"pretty"},"h1, h2, h3, h4, h5, h6":{textWrap:"balance"},a:{color:"currentColor"},button:{lineHeight:"1em",color:"currentColor"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},Z=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Zt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{}),J={externalModules:[],rcFile:void 0,destDir:void 0},Ft=t=>{if(J.externalModules.length>0)return J.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return J.externalModules=n,n},z=async t=>{if(J.destDir)return J.destDir;const e=await at(t),s=l.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return J.destDir=s,s},Ct=["salty","css","styles","styled"],qt=(t=[])=>new RegExp(`\\.(${[...Ct,...t].join("|")})\\.`),q=(t,e=[])=>qt(e).test(t),Pt=async t=>{if(J.rcFile)return J.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=l.join(t,".saltyrc.json"),s=await tt.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(J.rcFile=s,s):Pt(l.join(t,".."))},at=async t=>{var n,o;const e=await Pt(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((o=e.projects)==null?void 0:o.find(r=>r.dir===e.defaultProject))},Ht=async t=>{const e=await at(t),s=await z(t),n=l.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),o=l.join(s,"salty.config.js"),r=await St(t),a=Ft(n);await gt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:r,external:a});const g=Date.now(),{config:C}=await import(`${o}?t=${g}`);return C},Lt=async(t,e)=>{var ft,ut;const s=await z(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async F=>{const{contents:x,outputFilePath:A}=await et(t,F,s);Object.entries(x).forEach(([D,E])=>{E.isMedia?n.mediaQueries.push([D,E]):E.isGlobalDefine?n.globalStyles.push(E):E.isDefineVariables?n.variables.push(E):E.isDefineTemplates&&n.templates.push(E._setPath(`${D};;${A}`))})}));const o=await Ht(t),r={...o},a=new Set,g=(F,x=[])=>F?Object.entries(F).flatMap(([A,D])=>{if(!D)return;if(typeof D=="object")return g(D,[...x,A]);const E=jt(A),nt=V(A),ot=[...x,E].join(".");a.add(`"${ot}"`);const X=[...x.map(V),nt].join("-"),dt=Mt(D);return dt?`--${X}: ${dt.transformed};`:`--${X}: ${D};`}):[],C=F=>F?Object.entries(F).flatMap(([x,A])=>{const D=g(A);return x==="base"?D.join(""):`${x} { ${D.join("")} }`}):[],f=F=>F?Object.entries(F).flatMap(([x,A])=>Object.entries(A).flatMap(([D,E])=>{const nt=g(E,[x]),ot=`.${x}-${D}, [data-${x}="${D}"]`,X=nt.join("");return`${ot} { ${X} }`})):[],p=F=>({...F,responsive:void 0,conditional:void 0}),w=F=>n.variables.map(x=>F==="static"?p(x._current):x._current[F]),$=Z(p(o.variables),w("static")),m=g($),i=Z((ft=o.variables)==null?void 0:ft.responsive,w("responsive")),y=C(i),k=Z((ut=o.variables)==null?void 0:ut.conditional,w("conditional")),P=f(k),R=l.join(s,"css/_variables.css"),_=`:root { ${m.join("")} ${y.join("")} } ${P.join("")}`;d.writeFileSync(R,_),r.staticVariables=$;const T=l.join(s,"css/_global.css"),j=Z(o.global,n.globalStyles),O=await G(j,"");d.writeFileSync(T,`@layer global { ${O} }`);const c=l.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:It,u=await G(b,"");d.writeFileSync(c,`@layer reset { ${u} }`);const S=l.join(s,"css/_templates.css"),N=Z(o.templates,n.templates),M=await wt(N),H=vt(N);d.writeFileSync(S,`@layer templates { ${M} }`),r.templates=N;const L=Zt(n.templates);r.templatePaths=Object.fromEntries(Object.entries(L).map(([F,x])=>[F,x._path]));const{mediaQueries:W}=n;r.mediaQueries=Object.fromEntries(W.map(([F,x])=>[`@${F}`,x]));const K=W.map(([F])=>`'@${F}'`).join(" | "),st=l.join(s,"types/css-tokens.d.ts"),Q=`
|
7
|
+
// Variable types
|
8
|
+
type VariableTokens = ${[...a].join("|")};
|
9
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
11
10
|
|
12
|
-
|
11
|
+
// Template types
|
12
|
+
type TemplateTokens = {
|
13
|
+
${Object.entries(H).map(([F,x])=>`${F}?: ${x}`).join(`
|
13
14
|
`)}
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
}
|
16
|
+
|
17
|
+
// Media query types
|
18
|
+
type MediaQueryKeys = ${K||"''"};
|
19
|
+
`;d.writeFileSync(st,Q);const Nt=l.join(s,"cache/config-cache.json");d.writeFileSync(Nt,JSON.stringify(r,null,2))},yt=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(t))return e;const a=o.exec(t);if(a){const g=a.at(1);if(Ct.some(f=>g==null?void 0:g.includes(f)))return e}return"styled('div',"}),Bt=(t,e)=>{try{const s=d.readFileSync(l.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
20
|
+
|
21
|
+
${t}`:`globalThis.saltyConfig = {};
|
22
|
+
|
23
|
+
${t}`}catch{return t}},et=async(t,e,s)=>{const n=v(e),o=l.join(s,"./temp");d.existsSync(o)||d.mkdirSync(o);const r=l.parse(e);let a=d.readFileSync(e,"utf8");a=yt(a),a=Bt(a,t);const g=l.join(s,"js",n+".js"),C=await at(t),f=l.join(t,(C==null?void 0:C.configDir)||"","salty.config.ts"),p=Ft(f),w=await St(t);await gt.build({stdin:{contents:a,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:g,format:w,target:["node20"],keepNames:!0,external:p,packages:"external",plugins:[{name:"test",setup:i=>{i.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},y=>{const k=d.readFileSync(y.path,"utf8");return{contents:yt(k),loader:"ts"}})}}]});const $=Date.now();return{contents:await import(`${g}?t=${$}`),outputFilePath:g}},Gt=async t=>{const e=await z(t),s=l.join(e,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ct=async t=>{const e=await Gt(t),s=await z(t),n=l.join(s,"salty.config.js"),o=Date.now(),{config:r}=await import(`${n}?t=${o}`);return Z(r,e)},lt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Kt=async(t,e=lt(),s=!0)=>{try{const n=Date.now();e?it.info("Generating CSS in production mode! 🔥"):it.info("Generating CSS in development mode! 🚀");const o=[],r=[],a=await z(t),g=l.join(a,"index.css");s&&(()=>{d.existsSync(a)&&_t.execSync("rm -rf "+a),d.mkdirSync(a,{recursive:!0}),d.mkdirSync(l.join(a,"css")),d.mkdirSync(l.join(a,"types")),d.mkdirSync(l.join(a,"js")),d.mkdirSync(l.join(a,"cache"))})();const f=new Set,p=new Set;async function w(c){const h=["node_modules","saltygen"],b=d.statSync(c);if(b.isDirectory()){const u=d.readdirSync(c);if(h.some(N=>c.includes(N)))return;await Promise.all(u.map(N=>w(l.join(c,N))))}else if(b.isFile()&&q(c)){f.add(c);const S=d.readFileSync(c,"utf8");/define[\w\d]+\(/.test(S)&&p.add(c)}}await w(t),await Lt(t,p);const $={keyframes:[],components:[],classNames:[]};await Promise.all([...f].map(async c=>{const{contents:h}=await et(t,c,a);Object.entries(h).forEach(([b,u])=>{u.isKeyframes?$.keyframes.push({value:u,src:c,name:b}):u.isClassName?$.classNames.push({...u,src:c,name:b}):u.generator&&$.components.push({...u,src:c,name:b})})}));const m=await ct(t);for(const c of $.keyframes){const{value:h}=c,b=`a_${h.animationName}.css`,u=`css/${b}`,S=l.join(a,u);o.push(b),d.writeFileSync(S,h.css)}const i={};for(const c of $.components){const{src:h,name:b}=c;i[h]||(i[h]=[]);const u=c.generator._withBuildContext({callerName:b,isProduction:e,config:m});r[u.priority]||(r[u.priority]=[]);const S=await u.css;if(!S)continue;r[u.priority].push(u.cssFileName);const N=`css/${u.cssFileName}`,M=l.join(a,N);d.writeFileSync(M,S),m.importStrategy==="component"&&i[h].push(u.cssFileName)}for(const c of $.classNames){const{src:h,name:b}=c;i[h]||(i[h]=[]);const u=c.generator._withBuildContext({callerName:b,isProduction:e,config:m}),S=await u.css;if(!S)continue;r[0].push(u.cssFileName);const N=`css/${u.cssFileName}`,M=l.join(a,N);d.writeFileSync(M,S),m.importStrategy==="component"&&i[h].push(u.cssFileName)}m.importStrategy==="component"&&Object.entries(i).forEach(([c,h])=>{const b=h.map(H=>`@import url('./${H}');`).join(`
|
24
|
+
`),u=v(c,6),S=l.parse(c),N=V(S.name),M=l.join(a,`css/f_${N}-${u}.css`);d.writeFileSync(M,b||"/* Empty file */")});const y=o.map(c=>`@import url('./css/${c}');`).join(`
|
25
|
+
`);let _=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
26
|
+
|
27
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(c=>{try{return d.readFileSync(l.join(a,"css",c),"utf8").length>0}catch{return!1}}).map(c=>`@import url('./css/${c}');`).join(`
|
28
|
+
`)}
|
29
|
+
${y}`;if(m.importStrategy!=="component"){const c=r.reduce((h,b,u)=>{const S=b.reduce((L,W)=>{var Q;const K=l.join(a,"css",W),st=d.readFileSync(K,"utf8"),U=((Q=/.*-([^-]+)-\d+.css/.exec(W))==null?void 0:Q.at(1))||v(K,6);return L.includes(U)?L:`${L}
|
30
|
+
/*start:${U}-${W}*/
|
31
|
+
${st}
|
32
|
+
/*end:${U}*/
|
33
|
+
`},""),N=`l_${u}.css`,M=l.join(a,"css",N),H=`@layer l${u} { ${S}
|
34
|
+
}`;return d.writeFileSync(M,H),`${h}
|
35
|
+
@import url('./css/${N}');`},"");_+=c}d.writeFileSync(g,_);const j=Date.now()-n,O=j<200?"🔥":j<500?"🚀":j<1e3?"🎉":j<2e3?"🚗":j<5e3?"🤔":"🥴";it.info(`Generated CSS in ${j}ms! ${O}`)}catch(n){console.error(n)}},Ut=async(t,e,s=lt())=>{try{const n=await z(t);if(q(e)){const r=[],a=await ct(t),{contents:g}=await et(t,e,n);for(const[C,f]of Object.entries(g)){if(f.isKeyframes&&f.css){const y=`css/${`a_${f.animationName}.css`}`,k=l.join(n,y);d.writeFileSync(k,await f.css);return}if(f.isClassName){const i=f.generator._withBuildContext({callerName:C,isProduction:s,config:a}),y=await i.css;if(!y)continue;r[0].push(i.cssFileName);const k=`css/${i.cssFileName}`,P=l.join(n,k);d.writeFileSync(P,y)}if(!f.generator)return;const p=f.generator._withBuildContext({callerName:C,isProduction:s,config:a}),w=await p.css;if(!w)continue;const $=`css/${p.cssFileName}`,m=l.join(n,$);d.writeFileSync(m,w),r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName)}if(a.importStrategy!=="component")r.forEach((C,f)=>{const p=`l_${f}.css`,w=l.join(n,"css",p);let $=d.readFileSync(w,"utf8");C.forEach(m=>{var P;const i=l.join(n,"css",m),y=((P=/.*-([^-]+)-\d+.css/.exec(m))==null?void 0:P.at(1))||v(i,6);if(!$.includes(y)){const R=d.readFileSync(i,"utf8"),_=`/*start:${y}-${m}*/
|
36
|
+
${R}
|
37
|
+
/*end:${y}*/
|
38
|
+
`;$=`${$.replace(/\}$/,"")}
|
39
|
+
${_}
|
40
|
+
}`}}),d.writeFileSync(w,$)});else{const C=r.flat().map(m=>`@import url('./${m}');`).join(`
|
41
|
+
`),f=v(e,6),p=l.parse(e),w=V(p.name),$=l.join(n,`css/f_${w}-${f}.css`);d.writeFileSync($,C||"/* Empty file */")}}}catch(n){console.error(n)}},Qt=async(t,e,s=lt())=>{try{const n=await z(t);if(q(e)){const r=d.readFileSync(e,"utf8");r.replace(/^(?!export\s)const\s.*/gm,p=>`export ${p}`)!==r&&await tt.writeFile(e,r);const g=await ct(t),{contents:C}=await et(t,e,n);let f=r;if(Object.entries(C).forEach(([p,w])=>{var u;if(w.isKeyframes||!w.generator)return;const $=w.generator._withBuildContext({callerName:p,isProduction:s,config:g}),m=new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(r);if(!m)return console.error("Could not find the original declaration");const i=(u=m.at(1))==null?void 0:u.trim(),y=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(f);if(!y)return console.error("Could not find the original declaration");const{index:k}=y;let P=!1;const R=setTimeout(()=>P=!0,5e3);let _=0,T=!1,j=0;for(;!T&&!P;){const S=f[k+_];S==="("&&j++,S===")"&&j--,j===0&&S===")"&&(T=!0),_>f.length&&(P=!0),_++}if(!P)clearTimeout(R);else throw new Error("Failed to find the end of the styled call and timed out");const O=k+_,c=f.slice(k,O),h=f,b=` ${p} = styled(${i}, "${$.classNames}", ${JSON.stringify($.clientProps)});`;f=f.replace(c,b),h===f&&console.error("Minimize file failed to change content",{name:p,tagName:i})}),g.importStrategy==="component"){const p=v(e,6),w=l.parse(e);f=`import '../../saltygen/css/${`f_${V(w.name)}-${p}.css`}';
|
42
|
+
${f}`}return f=f.replace("{ styled }","{ styledClient as styled }"),f=f.replace("@salty-css/react/styled","@salty-css/react/styled-client"),f}}catch(n){console.error("Error in minimizeFile:",n)}},mt=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!q(t))return!1;const n=await tt.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},xt=t=>({name:"stylegen",buildStart:()=>Kt(t),load:async e=>{if(q(e))return await Qt(t,e)},handleHotUpdate:async({file:e,server:s})=>{await mt(e)&&await s.restart()},watchChange:{handler:async e=>{q(e)&&(await mt(e)||await Ut(t,e))}}});exports.default=xt;exports.saltyPlugin=xt;
|
package/index.d.ts
CHANGED
@@ -1,8 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
load: (filePath: string) => Promise<string | undefined>;
|
5
|
-
watchChange: {
|
6
|
-
handler: (filePath: string) => Promise<void>;
|
7
|
-
};
|
8
|
-
};
|
1
|
+
import { PluginOption } from 'vite';
|
2
|
+
export declare const saltyPlugin: (dir: string) => PluginOption;
|
3
|
+
export default saltyPlugin;
|
package/index.js
CHANGED
@@ -1,272 +1,623 @@
|
|
1
|
-
import * as
|
2
|
-
import { execSync as
|
3
|
-
import { join as u } from "path";
|
4
|
-
import {
|
5
|
-
import { writeFile as
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
1
|
+
import * as wt from "esbuild";
|
2
|
+
import { execSync as _t } from "child_process";
|
3
|
+
import { join as u, parse as et } from "path";
|
4
|
+
import { existsSync as ct, mkdirSync as I, statSync as Et, readdirSync as Tt, readFileSync as M, writeFileSync as D } from "fs";
|
5
|
+
import { readFile as lt, writeFile as Ot } from "fs/promises";
|
6
|
+
import { createLogger as Vt, format as it, transports as Mt } from "winston";
|
7
|
+
const yt = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Rt = (t, e) => {
|
8
|
+
let s = "", n;
|
9
|
+
for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = yt(n % 52) + s;
|
10
|
+
return s = yt(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
+
}, At = (t, e) => {
|
12
|
+
let s = e.length;
|
13
|
+
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
13
14
|
return t;
|
14
|
-
},
|
15
|
-
const
|
16
|
-
return
|
15
|
+
}, z = (t, e = 5) => {
|
16
|
+
const s = At(5381, JSON.stringify(t)) >>> 0;
|
17
|
+
return Rt(s, e);
|
17
18
|
};
|
18
|
-
function
|
19
|
-
return t ? typeof t != "string" ?
|
19
|
+
function A(t) {
|
20
|
+
return t ? typeof t != "string" ? A(String(t)) : t.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
|
20
21
|
}
|
21
|
-
const
|
22
|
-
if (typeof
|
23
|
-
|
24
|
-
const
|
25
|
-
return Object.values(
|
26
|
-
const { pattern: r, transform:
|
27
|
-
|
28
|
-
const { value:
|
29
|
-
return
|
22
|
+
const Jt = (t) => (e) => {
|
23
|
+
if (typeof e != "string" || !t) return;
|
24
|
+
let s = e;
|
25
|
+
const n = [];
|
26
|
+
return Object.values(t).forEach((o) => {
|
27
|
+
const { pattern: r, transform: a } = o;
|
28
|
+
s = s.replace(r, (h) => {
|
29
|
+
const { value: j, css: l } = a(h);
|
30
|
+
return l && n.push(l), j;
|
30
31
|
});
|
31
|
-
}), {
|
32
|
-
},
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
32
|
+
}), { transformed: s, additionalCss: n };
|
33
|
+
}, bt = (t) => (e) => typeof e != "string" || !/\{[^{}]+\}/g.test(e) ? void 0 : { transformed: e.replace(/\{([^{}]+)\}/g, (...o) => `var(--${A(o[1].replaceAll(".", "-"))})`) }, Wt = bt(), zt = [
|
34
|
+
"top",
|
35
|
+
"right",
|
36
|
+
"bottom",
|
37
|
+
"left",
|
38
|
+
"min-width",
|
39
|
+
/.*width.*/,
|
40
|
+
/^[^line]*height.*/,
|
41
|
+
// Exclude line-height
|
42
|
+
/padding.*/,
|
43
|
+
/margin.*/,
|
44
|
+
/border.*/,
|
45
|
+
/inset.*/,
|
46
|
+
/.*radius.*/,
|
47
|
+
/.*spacing.*/,
|
48
|
+
/.*gap.*/,
|
49
|
+
/.*indent.*/,
|
50
|
+
/.*offset.*/,
|
51
|
+
/.*size.*/,
|
52
|
+
/.*thickness.*/,
|
53
|
+
/.*font-size.*/
|
54
|
+
], vt = (t, e, s) => zt.some((o) => typeof o == "string" ? o === t : o.test(t)) ? `${e}px` : `${e}`, Zt = ["Webkit", "Moz", "ms", "O"], Ht = (t) => t.startsWith("-") ? t : Zt.some((e) => t.startsWith(e)) ? `-${A(t)}` : A(t), tt = async (t, e = "", s, n = !1) => {
|
55
|
+
if (!t) throw new Error("No styles provided to parseStyles function!");
|
56
|
+
const o = /* @__PURE__ */ new Set(), a = Object.entries(t).map(async ([m, i]) => {
|
57
|
+
const p = m.trim(), P = Ht(p), F = (k, O = ";") => `${P}:${k}${O}`;
|
58
|
+
if (typeof i == "function" && (i = i({ scope: e, config: s })), i instanceof Promise && (i = await i), typeof i == "object") {
|
59
|
+
if (!i) return;
|
60
|
+
if (i.isColor) return F(i.toString());
|
61
|
+
if (p === "defaultVariants") return;
|
62
|
+
if (p === "variants") {
|
63
|
+
const C = Object.entries(i);
|
64
|
+
for (const [E, c] of C) {
|
65
|
+
if (!c) return;
|
66
|
+
const y = Object.entries(c);
|
67
|
+
for (const [w, f] of y) {
|
68
|
+
if (!f) return;
|
69
|
+
const b = `${e}.${E}-${w}`;
|
70
|
+
(await tt(f, b, s)).forEach((V) => o.add(V));
|
71
|
+
}
|
72
|
+
}
|
73
|
+
return;
|
60
74
|
}
|
61
|
-
|
62
|
-
|
75
|
+
if (p === "compoundVariants") {
|
76
|
+
for (const C of i) {
|
77
|
+
const { css: E, ...c } = C, y = Object.entries(c).reduce((f, [b, N]) => `${f}.${b}-${N}`, e);
|
78
|
+
(await tt(E, y, s)).forEach((f) => o.add(f));
|
79
|
+
}
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
if (p.startsWith("@")) {
|
83
|
+
const C = p, E = await Q(i, e, s), c = `${C} { ${E} }`;
|
84
|
+
o.add(c);
|
85
|
+
return;
|
86
|
+
}
|
87
|
+
const k = m.includes("&") ? p.replace("&", e) : p.startsWith(":") ? `${e}${p}` : `${e} ${p}`;
|
88
|
+
(await tt(i, k, s)).forEach((C) => o.add(C));
|
89
|
+
return;
|
63
90
|
}
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
91
|
+
if (typeof i == "number") {
|
92
|
+
const k = vt(P, i);
|
93
|
+
return F(k);
|
94
|
+
}
|
95
|
+
if (typeof i != "string")
|
96
|
+
if ("toString" in i) i = i.toString();
|
97
|
+
else throw new Error(`Invalid value type for property ${P}`);
|
98
|
+
return F(i);
|
99
|
+
}), { modifiers: h } = {}, j = [bt(), Jt(h)], d = (await Promise.all(a).then((m) => Promise.all(
|
100
|
+
m.map((i) => j.reduce(async (p, P) => {
|
101
|
+
const F = await p;
|
102
|
+
if (!F) return F;
|
103
|
+
const R = await P(F);
|
104
|
+
if (!R) return F;
|
105
|
+
const { transformed: k, additionalCss: O } = R;
|
106
|
+
let C = "";
|
107
|
+
if (O)
|
108
|
+
for (const E of O)
|
109
|
+
C += await Q(E, "");
|
110
|
+
return `${C}${k}`;
|
111
|
+
}, Promise.resolve(i)))
|
112
|
+
))).filter((m) => m !== void 0).join(`
|
113
|
+
`);
|
114
|
+
if (!d.trim()) return Array.from(o);
|
115
|
+
const g = e ? `${e} {
|
116
|
+
${d}
|
117
|
+
}` : d;
|
118
|
+
return o.has(g) ? Array.from(o) : [g, ...o];
|
119
|
+
}, Q = async (t, e, s, n = !1) => (await tt(t, e, s, n)).join(`
|
120
|
+
`), Ct = async (t, e = []) => {
|
86
121
|
if (!t) return "";
|
87
|
-
const
|
88
|
-
|
89
|
-
if (typeof
|
90
|
-
|
91
|
-
|
92
|
-
e.push(a);
|
122
|
+
const s = [], n = {};
|
123
|
+
for (const [o, r] of Object.entries(t))
|
124
|
+
if (typeof r != "function") if (r && typeof r == "object") {
|
125
|
+
const a = o.trim(), h = await Ct(r, [...e, a]);
|
126
|
+
s.push(h);
|
93
127
|
} else
|
94
|
-
n[
|
95
|
-
|
96
|
-
const
|
97
|
-
|
128
|
+
n[o] = r;
|
129
|
+
if (Object.keys(n).length) {
|
130
|
+
const o = e.map(A).join("-"), r = "t_" + z(o, 4), a = await Q(n, `.${o}, .${r}`);
|
131
|
+
s.push(a);
|
98
132
|
}
|
99
|
-
return
|
133
|
+
return s.join(`
|
100
134
|
`);
|
101
|
-
},
|
102
|
-
const
|
103
|
-
|
104
|
-
|
135
|
+
}, It = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = St(n).map((o) => `"${o}"`).join(" | ")), e), {}) : {}, St = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, o]) => {
|
136
|
+
const r = e ? `${e}.${n}` : n;
|
137
|
+
return typeof o == "object" ? St(o, r, s) : s.add(e);
|
138
|
+
}), [...s]) : [], jt = (t) => {
|
139
|
+
if (!t || t === "/") throw new Error("Could not find package.json file");
|
140
|
+
const e = u(t, "package.json");
|
141
|
+
return ct(e) ? e : jt(u(t, ".."));
|
142
|
+
}, Bt = async (t) => {
|
143
|
+
const e = jt(t);
|
144
|
+
return await lt(e, "utf-8").then(JSON.parse).catch(() => {
|
145
|
+
});
|
146
|
+
}, Gt = async (t) => {
|
147
|
+
const e = await Bt(t);
|
148
|
+
if (e)
|
149
|
+
return e.type;
|
150
|
+
};
|
151
|
+
let H;
|
152
|
+
const Ft = async (t) => {
|
153
|
+
if (H) return H;
|
154
|
+
const e = await Gt(t);
|
155
|
+
return e === "module" ? H = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (H = "cjs"), H || "esm";
|
156
|
+
}, at = Vt({
|
157
|
+
level: "debug",
|
158
|
+
format: it.combine(it.colorize(), it.cli()),
|
159
|
+
transports: [new Mt.Console({})]
|
160
|
+
});
|
161
|
+
function xt(t) {
|
162
|
+
return t ? typeof t != "string" ? xt(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
|
163
|
+
}
|
164
|
+
const Kt = {
|
165
|
+
/** Set box model to border-box */
|
166
|
+
"*, *::before, *::after": {
|
167
|
+
boxSizing: "border-box"
|
168
|
+
},
|
169
|
+
/** Remove default margin and padding */
|
170
|
+
"*": {
|
171
|
+
margin: 0
|
172
|
+
},
|
173
|
+
/** Remove adjust font properties */
|
174
|
+
html: {
|
175
|
+
lineHeight: 1.15,
|
176
|
+
textSizeAdjust: "100%",
|
177
|
+
WebkitFontSmoothing: "antialiased"
|
178
|
+
},
|
179
|
+
/** Make media elements responsive */
|
180
|
+
"img, picture, video, canvas, svg": {
|
181
|
+
display: "block",
|
182
|
+
maxWidth: "100%"
|
183
|
+
},
|
184
|
+
/** Avoid overflow of text */
|
185
|
+
"p, h1, h2, h3, h4, h5, h6": {
|
186
|
+
overflowWrap: "break-word"
|
187
|
+
},
|
188
|
+
/** Improve text wrapping */
|
189
|
+
p: {
|
190
|
+
textWrap: "pretty"
|
191
|
+
},
|
192
|
+
"h1, h2, h3, h4, h5, h6": {
|
193
|
+
textWrap: "balance"
|
194
|
+
},
|
195
|
+
/** Improve link color */
|
196
|
+
a: {
|
197
|
+
color: "currentColor"
|
198
|
+
},
|
199
|
+
/** Improve button line height */
|
200
|
+
button: {
|
201
|
+
lineHeight: "1em",
|
202
|
+
color: "currentColor"
|
203
|
+
},
|
204
|
+
/** Improve form elements */
|
205
|
+
"input, optgroup, select, textarea": {
|
206
|
+
fontFamily: "inherit",
|
207
|
+
fontSize: "100%",
|
208
|
+
lineHeight: "1.15em"
|
209
|
+
}
|
210
|
+
}, B = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), Lt = (...t) => t.flat().reduce((e, s) => ({ ...e, ...s._children }), {}), W = {
|
211
|
+
externalModules: [],
|
212
|
+
rcFile: void 0,
|
213
|
+
destDir: void 0
|
214
|
+
}, Nt = (t) => {
|
215
|
+
if (W.externalModules.length > 0) return W.externalModules;
|
216
|
+
const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
217
|
+
if (!s) return [];
|
218
|
+
const n = s[1].split(",").map((o) => o.replace(/['"`]/g, "").trim());
|
219
|
+
return W.externalModules = n, n;
|
220
|
+
}, v = async (t) => {
|
221
|
+
if (W.destDir) return W.destDir;
|
222
|
+
const e = await ft(t), s = u(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
223
|
+
return W.destDir = s, s;
|
224
|
+
}, Pt = ["salty", "css", "styles", "styled"], Qt = (t = []) => new RegExp(`\\.(${[...Pt, ...t].join("|")})\\.`), G = (t, e = []) => Qt(e).test(t), kt = async (t) => {
|
225
|
+
if (W.rcFile) return W.rcFile;
|
226
|
+
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
227
|
+
const e = u(t, ".saltyrc.json"), s = await lt(e, "utf-8").then(JSON.parse).catch(() => {
|
228
|
+
});
|
229
|
+
return s ? (W.rcFile = s, s) : kt(u(t, ".."));
|
230
|
+
}, ft = async (t) => {
|
231
|
+
var n, o;
|
232
|
+
const e = await kt(t), s = (n = e.projects) == null ? void 0 : n.find((r) => t.endsWith(r.dir || ""));
|
233
|
+
return s || ((o = e.projects) == null ? void 0 : o.find((r) => r.dir === e.defaultProject));
|
234
|
+
}, Ut = async (t) => {
|
235
|
+
const e = await ft(t), s = await v(t), n = u(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), o = u(s, "salty.config.js"), r = await Ft(t), a = Nt(n);
|
236
|
+
await wt.build({
|
237
|
+
entryPoints: [n],
|
105
238
|
minify: !0,
|
106
239
|
treeShaking: !0,
|
107
240
|
bundle: !0,
|
108
|
-
outfile:
|
109
|
-
format:
|
110
|
-
external:
|
241
|
+
outfile: o,
|
242
|
+
format: r,
|
243
|
+
external: a
|
111
244
|
});
|
112
|
-
const
|
113
|
-
return
|
114
|
-
},
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
const
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
245
|
+
const h = Date.now(), { config: j } = await import(`${o}?t=${h}`);
|
246
|
+
return j;
|
247
|
+
}, qt = async (t, e) => {
|
248
|
+
var pt, mt;
|
249
|
+
const s = await v(t), n = {
|
250
|
+
mediaQueries: [],
|
251
|
+
globalStyles: [],
|
252
|
+
variables: [],
|
253
|
+
templates: []
|
254
|
+
};
|
255
|
+
await Promise.all(
|
256
|
+
[...e].map(async (S) => {
|
257
|
+
const { contents: x, outputFilePath: J } = await st(t, S, s);
|
258
|
+
Object.entries(x).forEach(([_, T]) => {
|
259
|
+
T.isMedia ? n.mediaQueries.push([_, T]) : T.isGlobalDefine ? n.globalStyles.push(T) : T.isDefineVariables ? n.variables.push(T) : T.isDefineTemplates && n.templates.push(T._setPath(`${_};;${J}`));
|
260
|
+
});
|
261
|
+
})
|
262
|
+
);
|
263
|
+
const o = await Ut(t), r = { ...o }, a = /* @__PURE__ */ new Set(), h = (S, x = []) => S ? Object.entries(S).flatMap(([J, _]) => {
|
264
|
+
if (!_) return;
|
265
|
+
if (typeof _ == "object") return h(_, [...x, J]);
|
266
|
+
const T = xt(J), ot = A(J), rt = [...x, T].join(".");
|
267
|
+
a.add(`"${rt}"`);
|
268
|
+
const Y = [...x.map(A), ot].join("-"), ht = Wt(_);
|
269
|
+
return ht ? `--${Y}: ${ht.transformed};` : `--${Y}: ${_};`;
|
270
|
+
}) : [], j = (S) => S ? Object.entries(S).flatMap(([x, J]) => {
|
271
|
+
const _ = h(J);
|
272
|
+
return x === "base" ? _.join("") : `${x} { ${_.join("")} }`;
|
273
|
+
}) : [], l = (S) => S ? Object.entries(S).flatMap(([x, J]) => Object.entries(J).flatMap(([_, T]) => {
|
274
|
+
const ot = h(T, [x]), rt = `.${x}-${_}, [data-${x}="${_}"]`, Y = ot.join("");
|
275
|
+
return `${rt} { ${Y} }`;
|
276
|
+
})) : [], d = (S) => ({ ...S, responsive: void 0, conditional: void 0 }), g = (S) => n.variables.map((x) => S === "static" ? d(x._current) : x._current[S]), $ = B(d(o.variables), g("static")), m = h($), i = B((pt = o.variables) == null ? void 0 : pt.responsive, g("responsive")), p = j(i), P = B((mt = o.variables) == null ? void 0 : mt.conditional, g("conditional")), F = l(P), R = u(s, "css/_variables.css"), k = `:root { ${m.join("")} ${p.join("")} } ${F.join("")}`;
|
277
|
+
D(R, k), r.staticVariables = $;
|
278
|
+
const O = u(s, "css/_global.css"), C = B(o.global, n.globalStyles), E = await Q(C, "");
|
279
|
+
D(O, `@layer global { ${E} }`);
|
280
|
+
const c = u(s, "css/_reset.css"), w = o.reset === "none" ? {} : typeof o.reset == "object" ? o.reset : Kt, f = await Q(w, "");
|
281
|
+
D(c, `@layer reset { ${f} }`);
|
282
|
+
const b = u(s, "css/_templates.css"), N = B(o.templates, n.templates), V = await Ct(N), K = It(N);
|
283
|
+
D(b, `@layer templates { ${V} }`), r.templates = N;
|
284
|
+
const L = Lt(n.templates);
|
285
|
+
r.templatePaths = Object.fromEntries(Object.entries(L).map(([S, x]) => [S, x._path]));
|
286
|
+
const { mediaQueries: Z } = n;
|
287
|
+
r.mediaQueries = Object.fromEntries(Z.map(([S, x]) => [`@${S}`, x]));
|
288
|
+
const U = Z.map(([S]) => `'@${S}'`).join(" | "), nt = u(s, "types/css-tokens.d.ts"), X = `
|
289
|
+
// Variable types
|
290
|
+
type VariableTokens = ${[...a].join("|")};
|
291
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
292
|
+
|
293
|
+
// Template types
|
294
|
+
type TemplateTokens = {
|
295
|
+
${Object.entries(K).map(([S, x]) => `${S}?: ${x}`).join(`
|
296
|
+
`)}
|
297
|
+
}
|
298
|
+
|
299
|
+
// Media query types
|
300
|
+
type MediaQueryKeys = ${U || "''"};
|
301
|
+
`;
|
302
|
+
D(nt, X);
|
303
|
+
const Dt = u(s, "cache/config-cache.json");
|
304
|
+
D(Dt, JSON.stringify(r, null, 2));
|
305
|
+
}, gt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
306
|
+
if (/^['"`]/.test(s)) return e;
|
307
|
+
const o = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
308
|
+
if (!o.test(t)) return e;
|
309
|
+
const a = o.exec(t);
|
310
|
+
if (a) {
|
311
|
+
const h = a.at(1);
|
312
|
+
if (Pt.some((l) => h == null ? void 0 : h.includes(l))) return e;
|
313
|
+
}
|
314
|
+
return "styled('div',";
|
315
|
+
}), Xt = (t, e) => {
|
316
|
+
try {
|
317
|
+
const s = M(u(e, "saltygen/cache/config-cache.json"), "utf8");
|
318
|
+
return s ? `globalThis.saltyConfig = ${s};
|
319
|
+
|
320
|
+
${t}` : `globalThis.saltyConfig = {};
|
321
|
+
|
322
|
+
${t}`;
|
323
|
+
} catch {
|
324
|
+
return t;
|
325
|
+
}
|
326
|
+
}, st = async (t, e, s) => {
|
327
|
+
const n = z(e), o = u(s, "./temp");
|
328
|
+
ct(o) || I(o);
|
329
|
+
const r = et(e);
|
330
|
+
let a = M(e, "utf8");
|
331
|
+
a = gt(a), a = Xt(a, t);
|
332
|
+
const h = u(s, "js", n + ".js"), j = await ft(t), l = u(t, (j == null ? void 0 : j.configDir) || "", "salty.config.ts"), d = Nt(l), g = await Ft(t);
|
333
|
+
await wt.build({
|
334
|
+
stdin: {
|
335
|
+
contents: a,
|
336
|
+
sourcefile: r.base,
|
337
|
+
resolveDir: r.dir,
|
338
|
+
loader: "tsx"
|
339
|
+
},
|
340
|
+
minify: !1,
|
141
341
|
treeShaking: !0,
|
142
342
|
bundle: !0,
|
143
|
-
outfile:
|
144
|
-
format:
|
145
|
-
target: ["
|
343
|
+
outfile: h,
|
344
|
+
format: g,
|
345
|
+
target: ["node20"],
|
146
346
|
keepNames: !0,
|
147
|
-
external:
|
347
|
+
external: d,
|
348
|
+
packages: "external",
|
349
|
+
plugins: [
|
350
|
+
{
|
351
|
+
name: "test",
|
352
|
+
setup: (i) => {
|
353
|
+
i.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (p) => {
|
354
|
+
const P = M(p.path, "utf8");
|
355
|
+
return { contents: gt(P), loader: "ts" };
|
356
|
+
});
|
357
|
+
}
|
358
|
+
}
|
359
|
+
]
|
148
360
|
});
|
149
|
-
const
|
150
|
-
return await import(`${
|
151
|
-
},
|
152
|
-
const
|
153
|
-
|
154
|
-
|
361
|
+
const $ = Date.now();
|
362
|
+
return { contents: await import(`${h}?t=${$}`), outputFilePath: h };
|
363
|
+
}, Yt = async (t) => {
|
364
|
+
const e = await v(t), s = u(e, "cache/config-cache.json"), n = M(s, "utf8");
|
365
|
+
if (!n) throw new Error("Could not find config cache file");
|
366
|
+
return JSON.parse(n);
|
367
|
+
}, ut = async (t) => {
|
368
|
+
const e = await Yt(t), s = await v(t), n = u(s, "salty.config.js"), o = Date.now(), { config: r } = await import(`${n}?t=${o}`);
|
369
|
+
return B(r, e);
|
370
|
+
}, dt = () => {
|
155
371
|
try {
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
}
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
e[l.priority] || (e[l.priority] = []), e[l.priority].push(S), F.push(S);
|
180
|
-
const D = `css/${S}`, N = u(n, D);
|
181
|
-
C(N, l.css);
|
182
|
-
});
|
183
|
-
const d = F.map((c) => `@import url('./${c}');`).join(`
|
184
|
-
`), x = A(p, 6), g = u(n, `css/${x}.css`);
|
185
|
-
C(g, d);
|
372
|
+
return process.env.NODE_ENV === "production";
|
373
|
+
} catch {
|
374
|
+
return !1;
|
375
|
+
}
|
376
|
+
}, te = async (t, e = dt(), s = !0) => {
|
377
|
+
try {
|
378
|
+
const n = Date.now();
|
379
|
+
e ? at.info("Generating CSS in production mode! 🔥") : at.info("Generating CSS in development mode! 🚀");
|
380
|
+
const o = [], r = [], a = await v(t), h = u(a, "index.css");
|
381
|
+
s && (() => {
|
382
|
+
ct(a) && _t("rm -rf " + a), I(a, { recursive: !0 }), I(u(a, "css")), I(u(a, "types")), I(u(a, "js")), I(u(a, "cache"));
|
383
|
+
})();
|
384
|
+
const l = /* @__PURE__ */ new Set(), d = /* @__PURE__ */ new Set();
|
385
|
+
async function g(c) {
|
386
|
+
const y = ["node_modules", "saltygen"], w = Et(c);
|
387
|
+
if (w.isDirectory()) {
|
388
|
+
const f = Tt(c);
|
389
|
+
if (y.some((N) => c.includes(N))) return;
|
390
|
+
await Promise.all(f.map((N) => g(u(c, N))));
|
391
|
+
} else if (w.isFile() && G(c)) {
|
392
|
+
l.add(c);
|
393
|
+
const b = M(c, "utf8");
|
394
|
+
/define[\w\d]+\(/.test(b) && d.add(c);
|
186
395
|
}
|
187
396
|
}
|
188
|
-
await
|
189
|
-
const
|
397
|
+
await g(t), await qt(t, d);
|
398
|
+
const $ = {
|
399
|
+
keyframes: [],
|
400
|
+
components: [],
|
401
|
+
classNames: []
|
402
|
+
};
|
403
|
+
await Promise.all(
|
404
|
+
[...l].map(async (c) => {
|
405
|
+
const { contents: y } = await st(t, c, a);
|
406
|
+
Object.entries(y).forEach(([w, f]) => {
|
407
|
+
f.isKeyframes ? $.keyframes.push({
|
408
|
+
value: f,
|
409
|
+
src: c,
|
410
|
+
name: w
|
411
|
+
}) : f.isClassName ? $.classNames.push({
|
412
|
+
...f,
|
413
|
+
src: c,
|
414
|
+
name: w
|
415
|
+
}) : f.generator && $.components.push({
|
416
|
+
...f,
|
417
|
+
src: c,
|
418
|
+
name: w
|
419
|
+
});
|
420
|
+
});
|
421
|
+
})
|
422
|
+
);
|
423
|
+
const m = await ut(t);
|
424
|
+
for (const c of $.keyframes) {
|
425
|
+
const { value: y } = c, w = `a_${y.animationName}.css`, f = `css/${w}`, b = u(a, f);
|
426
|
+
o.push(w), D(b, y.css);
|
427
|
+
}
|
428
|
+
const i = {};
|
429
|
+
for (const c of $.components) {
|
430
|
+
const { src: y, name: w } = c;
|
431
|
+
i[y] || (i[y] = []);
|
432
|
+
const f = c.generator._withBuildContext({
|
433
|
+
callerName: w,
|
434
|
+
isProduction: e,
|
435
|
+
config: m
|
436
|
+
});
|
437
|
+
r[f.priority] || (r[f.priority] = []);
|
438
|
+
const b = await f.css;
|
439
|
+
if (!b) continue;
|
440
|
+
r[f.priority].push(f.cssFileName);
|
441
|
+
const N = `css/${f.cssFileName}`, V = u(a, N);
|
442
|
+
D(V, b), m.importStrategy === "component" && i[y].push(f.cssFileName);
|
443
|
+
}
|
444
|
+
for (const c of $.classNames) {
|
445
|
+
const { src: y, name: w } = c;
|
446
|
+
i[y] || (i[y] = []);
|
447
|
+
const f = c.generator._withBuildContext({
|
448
|
+
callerName: w,
|
449
|
+
isProduction: e,
|
450
|
+
config: m
|
451
|
+
}), b = await f.css;
|
452
|
+
if (!b) continue;
|
453
|
+
r[0].push(f.cssFileName);
|
454
|
+
const N = `css/${f.cssFileName}`, V = u(a, N);
|
455
|
+
D(V, b), m.importStrategy === "component" && i[y].push(f.cssFileName);
|
456
|
+
}
|
457
|
+
m.importStrategy === "component" && Object.entries(i).forEach(([c, y]) => {
|
458
|
+
const w = y.map((K) => `@import url('./${K}');`).join(`
|
459
|
+
`), f = z(c, 6), b = et(c), N = A(b.name), V = u(a, `css/f_${N}-${f}.css`);
|
460
|
+
D(V, w || "/* Empty file */");
|
461
|
+
});
|
462
|
+
const p = o.map((c) => `@import url('./css/${c}');`).join(`
|
190
463
|
`);
|
191
|
-
let
|
464
|
+
let k = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
192
465
|
|
193
|
-
${["
|
466
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((c) => {
|
467
|
+
try {
|
468
|
+
return M(u(a, "css", c), "utf8").length > 0;
|
469
|
+
} catch {
|
470
|
+
return !1;
|
471
|
+
}
|
472
|
+
}).map((c) => `@import url('./css/${c}');`).join(`
|
194
473
|
`)}
|
195
|
-
${
|
196
|
-
if (
|
197
|
-
const
|
198
|
-
|
199
|
-
|
474
|
+
${p}`;
|
475
|
+
if (m.importStrategy !== "component") {
|
476
|
+
const c = r.reduce((y, w, f) => {
|
477
|
+
const b = w.reduce((L, Z) => {
|
478
|
+
var X;
|
479
|
+
const U = u(a, "css", Z), nt = M(U, "utf8"), q = ((X = /.*-([^-]+)-\d+.css/.exec(Z)) == null ? void 0 : X.at(1)) || z(U, 6);
|
480
|
+
return L.includes(q) ? L : `${L}
|
481
|
+
/*start:${q}-${Z}*/
|
482
|
+
${nt}
|
483
|
+
/*end:${q}*/
|
484
|
+
`;
|
485
|
+
}, ""), N = `l_${f}.css`, V = u(a, "css", N), K = `@layer l${f} { ${b}
|
486
|
+
}`;
|
487
|
+
return D(V, K), `${y}
|
488
|
+
@import url('./css/${N}');`;
|
489
|
+
}, "");
|
490
|
+
k += c;
|
200
491
|
}
|
201
|
-
|
202
|
-
|
203
|
-
|
492
|
+
D(h, k);
|
493
|
+
const C = Date.now() - n, E = C < 200 ? "🔥" : C < 500 ? "🚀" : C < 1e3 ? "🎉" : C < 2e3 ? "🚗" : C < 5e3 ? "🤔" : "🥴";
|
494
|
+
at.info(`Generated CSS in ${C}ms! ${E}`);
|
495
|
+
} catch (n) {
|
496
|
+
console.error(n);
|
204
497
|
}
|
205
|
-
},
|
498
|
+
}, ee = async (t, e, s = dt()) => {
|
206
499
|
try {
|
207
|
-
const
|
208
|
-
if (
|
209
|
-
const
|
210
|
-
Object.entries(
|
211
|
-
if (
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
}
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
500
|
+
const n = await v(t);
|
501
|
+
if (G(e)) {
|
502
|
+
const r = [], a = await ut(t), { contents: h } = await st(t, e, n);
|
503
|
+
for (const [j, l] of Object.entries(h)) {
|
504
|
+
if (l.isKeyframes && l.css) {
|
505
|
+
const p = `css/${`a_${l.animationName}.css`}`, P = u(n, p);
|
506
|
+
D(P, await l.css);
|
507
|
+
return;
|
508
|
+
}
|
509
|
+
if (l.isClassName) {
|
510
|
+
const i = l.generator._withBuildContext({
|
511
|
+
callerName: j,
|
512
|
+
isProduction: s,
|
513
|
+
config: a
|
514
|
+
}), p = await i.css;
|
515
|
+
if (!p) continue;
|
516
|
+
r[0].push(i.cssFileName);
|
517
|
+
const P = `css/${i.cssFileName}`, F = u(n, P);
|
518
|
+
D(F, p);
|
519
|
+
}
|
520
|
+
if (!l.generator) return;
|
521
|
+
const d = l.generator._withBuildContext({
|
522
|
+
callerName: j,
|
523
|
+
isProduction: s,
|
524
|
+
config: a
|
525
|
+
}), g = await d.css;
|
526
|
+
if (!g) continue;
|
527
|
+
const $ = `css/${d.cssFileName}`, m = u(n, $);
|
528
|
+
D(m, g), r[d.priority] || (r[d.priority] = []), r[d.priority].push(d.cssFileName);
|
529
|
+
}
|
530
|
+
if (a.importStrategy !== "component")
|
531
|
+
r.forEach((j, l) => {
|
532
|
+
const d = `l_${l}.css`, g = u(n, "css", d);
|
533
|
+
let $ = M(g, "utf8");
|
534
|
+
j.forEach((m) => {
|
535
|
+
var F;
|
536
|
+
const i = u(n, "css", m), p = ((F = /.*-([^-]+)-\d+.css/.exec(m)) == null ? void 0 : F.at(1)) || z(i, 6);
|
537
|
+
if (!$.includes(p)) {
|
538
|
+
const R = M(i, "utf8"), k = `/*start:${p}-${m}*/
|
539
|
+
${R}
|
540
|
+
/*end:${p}*/
|
541
|
+
`;
|
542
|
+
$ = `${$.replace(/\}$/, "")}
|
543
|
+
${k}
|
544
|
+
}`;
|
545
|
+
}
|
546
|
+
}), D(g, $);
|
547
|
+
});
|
548
|
+
else {
|
549
|
+
const j = r.flat().map((m) => `@import url('./${m}');`).join(`
|
550
|
+
`), l = z(e, 6), d = et(e), g = A(d.name), $ = u(n, `css/f_${g}-${l}.css`);
|
551
|
+
D($, j || "/* Empty file */");
|
552
|
+
}
|
222
553
|
}
|
223
|
-
} catch (
|
224
|
-
console.error(
|
554
|
+
} catch (n) {
|
555
|
+
console.error(n);
|
225
556
|
}
|
226
|
-
},
|
557
|
+
}, se = async (t, e, s = dt()) => {
|
227
558
|
try {
|
228
|
-
const
|
229
|
-
if (
|
230
|
-
const r =
|
231
|
-
r.replace(/^(?!export\s)const\s.*/gm, (
|
232
|
-
const
|
233
|
-
let
|
234
|
-
Object.entries(
|
235
|
-
var
|
236
|
-
if (
|
237
|
-
|
238
|
-
|
559
|
+
const n = await v(t);
|
560
|
+
if (G(e)) {
|
561
|
+
const r = M(e, "utf8");
|
562
|
+
r.replace(/^(?!export\s)const\s.*/gm, (d) => `export ${d}`) !== r && await Ot(e, r);
|
563
|
+
const h = await ut(t), { contents: j } = await st(t, e, n);
|
564
|
+
let l = r;
|
565
|
+
if (Object.entries(j).forEach(([d, g]) => {
|
566
|
+
var f;
|
567
|
+
if (g.isKeyframes || !g.generator) return;
|
568
|
+
const $ = g.generator._withBuildContext({
|
569
|
+
callerName: d,
|
570
|
+
isProduction: s,
|
571
|
+
config: h
|
572
|
+
}), m = new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
|
573
|
+
if (!m) return console.error("Could not find the original declaration");
|
574
|
+
const i = (f = m.at(1)) == null ? void 0 : f.trim(), p = new RegExp(`\\s${d}[=\\s]+styled\\(`, "g").exec(l);
|
575
|
+
if (!p) return console.error("Could not find the original declaration");
|
576
|
+
const { index: P } = p;
|
577
|
+
let F = !1;
|
578
|
+
const R = setTimeout(() => F = !0, 5e3);
|
579
|
+
let k = 0, O = !1, C = 0;
|
580
|
+
for (; !O && !F; ) {
|
581
|
+
const b = l[P + k];
|
582
|
+
b === "(" && C++, b === ")" && C--, C === 0 && b === ")" && (O = !0), k > l.length && (F = !0), k++;
|
239
583
|
}
|
240
|
-
if (!
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
});
|
250
|
-
const o = A(s, 6);
|
251
|
-
return $.importStrategy === "component" && (f = `import '../../saltygen/css/${o}.css';
|
252
|
-
${f}`), f = f.replace("{ styled }", "{ styledClient as styled }"), f = f.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), f;
|
584
|
+
if (!F) clearTimeout(R);
|
585
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
586
|
+
const E = P + k, c = l.slice(P, E), y = l, w = ` ${d} = styled(${i}, "${$.classNames}", ${JSON.stringify($.clientProps)});`;
|
587
|
+
l = l.replace(c, w), y === l && console.error("Minimize file failed to change content", { name: d, tagName: i });
|
588
|
+
}), h.importStrategy === "component") {
|
589
|
+
const d = z(e, 6), g = et(e);
|
590
|
+
l = `import '../../saltygen/css/${`f_${A(g.name)}-${d}.css`}';
|
591
|
+
${l}`;
|
592
|
+
}
|
593
|
+
return l = l.replace("{ styled }", "{ styledClient as styled }"), l = l.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), l;
|
253
594
|
}
|
254
|
-
} catch (
|
255
|
-
console.error(
|
595
|
+
} catch (n) {
|
596
|
+
console.error("Error in minimizeFile:", n);
|
256
597
|
}
|
257
|
-
},
|
598
|
+
}, $t = async (t) => {
|
599
|
+
if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
|
600
|
+
if (t.includes("salty.config")) return !0;
|
601
|
+
if (!G(t)) return !1;
|
602
|
+
const n = await lt(t, "utf-8");
|
603
|
+
return !!/.+define[A-Z]\w+/.test(n);
|
604
|
+
}, ce = (t) => ({
|
258
605
|
name: "stylegen",
|
259
|
-
buildStart: () =>
|
260
|
-
load: async (
|
261
|
-
if (
|
262
|
-
return await
|
606
|
+
buildStart: () => te(t),
|
607
|
+
load: async (e) => {
|
608
|
+
if (G(e))
|
609
|
+
return await se(t, e);
|
610
|
+
},
|
611
|
+
handleHotUpdate: async ({ file: e, server: s }) => {
|
612
|
+
await $t(e) && await s.restart();
|
263
613
|
},
|
264
614
|
watchChange: {
|
265
|
-
handler: async (
|
266
|
-
|
615
|
+
handler: async (e) => {
|
616
|
+
G(e) && (await $t(e) || await ee(t, e));
|
267
617
|
}
|
268
618
|
}
|
269
619
|
});
|
270
620
|
export {
|
271
|
-
|
621
|
+
ce as default,
|
622
|
+
ce as saltyPlugin
|
272
623
|
};
|
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.210",
|
4
4
|
"main": "./dist/index.js",
|
5
5
|
"module": "./dist/index.mjs",
|
6
6
|
"typings": "./dist/index.d.ts",
|
@@ -10,7 +10,12 @@
|
|
10
10
|
"publishConfig": {
|
11
11
|
"access": "public"
|
12
12
|
},
|
13
|
-
"
|
13
|
+
"description": "Vite plugin for Salty CSS",
|
14
|
+
"homepage": "https://salty-css.dev/",
|
15
|
+
"repository": {
|
16
|
+
"type": "git",
|
17
|
+
"url": "git+https://github.com/margarita-form/salty-css.git"
|
18
|
+
},
|
14
19
|
"bugs": {
|
15
20
|
"url": "https://github.com/margarita-form/salty-css/issues"
|
16
21
|
},
|
@@ -28,7 +33,7 @@
|
|
28
33
|
"require": "./index.cjs"
|
29
34
|
}
|
30
35
|
},
|
31
|
-
"
|
32
|
-
"@salty-css/core": "^0.0.1-alpha.
|
36
|
+
"dependencies": {
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.210"
|
33
38
|
}
|
34
39
|
}
|