@salty-css/vite 0.0.1-alpha.18 → 0.0.1-alpha.180

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.
Files changed (5) hide show
  1. package/README.md +143 -26
  2. package/index.cjs +32 -14
  3. package/index.d.ts +3 -8
  4. package/index.js +450 -217
  5. package/package.json +9 -4
package/README.md CHANGED
@@ -1,15 +1,132 @@
1
- # Salty Css
1
+ ![Salty CSS Banner](https://salty-css.dev/assets/banners/dvd.svg)
2
2
 
3
- ## Basic usage example with Button
3
+ # Salty CSS - CSS-in-JS library that is kinda sweet
4
4
 
5
- ### Initial requirements
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
- 1. Add `saltyPlugin` to vite or webpack config from `@salty-css/vite` or `@salty-css/webpack`
8
- 2. Create `salty.config.ts` to the root of your project
9
- 3. Import global styles to any regular .css file from `saltygen/index.css` (does not exist during first run, cli command coming later)
10
- 4. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
7
+ ## Features
11
8
 
12
- ### Code examples
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
+ ![salty-next](https://github.com/user-attachments/assets/2cf6a93f-cdd5-4f5f-ab2e-3bc8bcfb83e8)
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
+ ![salty-vite-react](https://github.com/user-attachments/assets/12ec5b6a-0dcc-48fa-afc1-d337fc8f800c)
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/40',
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,36 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const W=require("esbuild"),z=require("child_process"),u=require("path"),m=require("fs"),J=require("fs/promises");function K(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=K(W),M=t=>String.fromCharCode(t+(t>25?39:97)),G=(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},L=(t,s)=>{let e=s.length;for(;e;)t=t*33^s.charCodeAt(--e);return t},E=(t,s=3)=>{const e=L(5381,JSON.stringify(t))>>>0;return G(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 U=(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:y}=n;t=t.replace(r,$=>{const{value:a,css:f}=y($);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=[],y=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(([d,l])=>{if(!l)return;const F=`${s}.${g}-${d}`,P=D(l,F);r.push(P)})}),a;if(i==="defaultVariants")return a;if(i==="compoundVariants")return o.forEach(g=>{const{css:c,...d}=g,l=Object.entries(d).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(`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const me=require("esbuild"),Se=require("child_process"),l=require("path"),u=require("fs"),G=require("fs/promises"),H=require("winston");var v=typeof document<"u"?document.currentScript:null;function be(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const oe=be(me),te=e=>String.fromCharCode(e+(e>25?39:97)),je=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=te(n%52)+s;return s=te(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},$e=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},L=(e,t=5)=>{const s=$e(5381,JSON.stringify(e))>>>0;return je(s,t)};function R(e){return e?typeof e!="string"?R(String(e)):e.replace(/[\s.]/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?"-":"")+t.toLowerCase()):""}const we=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:c,transform:a}=n;e=e.replace(c,i=>{const{value:d,css:r}=a(i);return r&&s.push(r),d})}),{result:e,additionalCss:s}},re=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${R(n[1].replaceAll(".","-"))})`)}:{result:e},M=(e,t,s)=>{if(!e)return"";const n=[],c=Object.entries(e).reduce((i,[d,r])=>{const o=d.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return i;if(o==="variants")return Object.entries(r).forEach(([P,b])=>{b&&Object.entries(b).forEach(([O,f])=>{if(!f)return;const $=`${t}.${P}-${O}`,S=M(f,$);n.push(S)})}),i;if(o==="defaultVariants")return i;if(o==="compoundVariants")return r.forEach(P=>{const{css:b,...O}=P,f=Object.entries(O).reduce((S,[w,h])=>`${S}.${w}-${h}`,t),$=M(b,f);n.push($)}),i;if(o.startsWith("@")){const P=M(r,t),b=`${o} {
2
+ ${P.replace(`
3
3
  `,`
4
4
  `)}
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 p=i.startsWith("-")?i:N(i),h=(b,C=";")=>a=`${a}${b}${C}`,j=b=>h(`${p}:${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 U(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(!y)return r.join(`
6
- `);if(!s)return y;let $="";return $=`${s} { ${y} }`,[$,...r].join(`
7
- `)},Z=(t,s=[])=>{if(!t)return"";const e=[],n={};if(Object.entries(t).forEach(([r,y])=>{if(typeof y=="object"){if(!y)return;const $=r.trim(),a=Z(y,[...s,$]);e.push(a)}else n[r]=y}),Object.keys(n).length){const r=s.map(N).join("-"),y=D(n,`.${r}`);e.push(y)}return e.join(`
8
- `)},T=t=>u.join(t,"./saltygen"),X=["salty","css","styles","styled"],Y=(t=[])=>new RegExp(`\\.(${[...X,...t].join("|")})\\.`),V=(t,s=[])=>Y(s).test(t),Q=async t=>{const s=T(t),e=u.join(t,"salty.config.ts"),n=u.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:y}=await import(`${n}?t=${r}`);return y},I=async t=>{const s=await Q(t),e=new Set,n=(g,c=[])=>g?Object.entries(g).flatMap(([d,l])=>{if(!l)return;if(typeof l=="object")return n(l,[...c,d]);const F=[...c,d].join(".");e.add(`"${F}"`);const P=[...c.map(N),N(d)].join("-"),{result:x}=q(l);return`--${P}: ${x};`}):[],r=g=>g?Object.entries(g).flatMap(([c,d])=>{const l=n(d);return c==="base"?l.join(""):`${c} { ${l.join("")} }`}):[],y=g=>g?Object.entries(g).flatMap(([c,d])=>Object.entries(d).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=y(s.conditionalVariables),o=T(t),i=u.join(o,"css/variables.css"),p=`:root { ${$.join("")} ${a.join("")} } ${f.join("")}`;m.writeFileSync(i,p);const h=u.join(o,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;m.writeFileSync(h,S);const w=u.join(o,"css/global.css"),O=D(s.global,"");m.writeFileSync(w,O);const b=u.join(o,"css/templates.css"),C=Z(s.templates);m.writeFileSync(b,C)},_=async(t,s)=>{const e=E(t),n=u.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=T(t),e=u.join(s,"salty.config.js"),{config:n}=await import(e);return n},v=async t=>{try{const s=[],e=[],n=T(t),r=u.join(n,"index.css");(()=>{m.existsSync(n)&&z.execSync("rm -rf "+n),m.mkdirSync(n),m.mkdirSync(u.join(n,"css")),m.mkdirSync(u.join(n,"types"))})(),await I(t);const $=await A(t);async function a(p,h){const j=m.statSync(p);if(j.isDirectory()){const S=m.readdirSync(p);await Promise.all(S.map(w=>a(u.join(p,w),u.join(h,w))))}else if(j.isFile()&&V(p)){const w=await _(p,n),O=[];Object.entries(w).forEach(([c,d])=>{if(d.isKeyframes&&d.css){const k=`${d.animationName}.css`,B=`css/${k}`,H=u.join(n,B);s.push(k),m.writeFileSync(H,d.css);return}if(!d.generator)return;const l=d.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=u.join(n,P);m.writeFileSync(x,l.css)});const b=O.map(c=>`@import url('./${c}');`).join(`
9
- `),C=E(p,6),g=u.join(n,`css/${C}.css`);m.writeFileSync(g,b)}}await a(t,n);const f=s.map(p=>`@import url('./css/${p}');`).join(`
10
- `);let i=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
5
+ }`;return n.push(b),i}const j=d.includes("&")?o.replace("&",t):o.startsWith(":")?`${t}${o}`:`${t} ${o}`,F=M(r,j);return n.push(F),i}const g=o.startsWith("-")?o:R(o),p=(j,F=";")=>i=`${i}${j}${F}`,y=j=>p(`${g}:${j}`);if(typeof r=="number")return y(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return i;const{modifiers:x}={},T=function*(){yield re(r),yield we(r,x)}();for(const{result:j,additionalCss:F=[]}of T)r=j,F.forEach(P=>{const b=M(P,"");p(b,"")});return y(r)},"");return c?t?[`${t} { ${c} }`,...n].join(`
6
+ `):c:n.join(`
7
+ `)},ie=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([c,a])=>{if(typeof a=="object"){if(!a)return;const i=c.trim(),d=ie(a,[...t,i]);s.push(d)}else n[c]=a}),Object.keys(n).length){const c=t.map(R).join("-"),a=M(n,`.${c}`);s.push(a)}return s.join(`
8
+ `)},Fe=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=ce(n).map(c=>`"${c}"`).join(" | ")),t),{}):{},ce=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,c])=>{const a=t?`${t}.${n}`:n;return typeof c=="object"?ce(c,a,s):s.add(t)}),[...s]):[],ae=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=l.join(e,"package.json");return u.existsSync(t)?t:ae(l.join(e,".."))},Ce=async e=>{const t=ae(e);return await G.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},ke=async e=>{const t=await Ce(e);if(t)return t.type};let A;const le=async e=>{if(A)return A;const t=await ke(e);return t==="module"?A="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:v&&v.tagName.toUpperCase()==="SCRIPT"&&v.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(A="cjs"),A||"esm"},Q=H.createLogger({level:"debug",format:H.format.combine(H.format.colorize(),H.format.cli()),transports:[new H.transports.Console({})]});function fe(e){return e?typeof e!="string"?fe(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const xe={"*, *::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"}},q=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),V={externalModules:[],rcFile:void 0,destDir:void 0},ue=e=>{if(V.externalModules.length>0)return V.externalModules;const s=u.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(c=>c.replace(/['"`]/g,"").trim());return V.externalModules=n,n},z=async e=>{if(V.destDir)return V.destDir;const t=await X(e),s=l.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},de=["salty","css","styles","styled"],Ne=(e=[])=>new RegExp(`\\.(${[...de,...e].join("|")})\\.`),W=(e,t=[])=>Ne(t).test(e),pe=async e=>{if(V.rcFile)return V.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=l.join(e,".saltyrc.json"),s=await G.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):pe(l.join(e,".."))},X=async e=>{var n,c;const t=await pe(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((c=t.projects)==null?void 0:c.find(a=>a.dir===t.defaultProject))},De=async e=>{const t=await X(e),s=await z(e),n=l.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),c=l.join(s,"salty.config.js"),a=await le(e),i=ue(n);await oe.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:c,format:a,external:i});const d=Date.now(),{config:r}=await import(`${c}?t=${d}`);return r},Pe=async(e,t)=>{const s=await De(e),n={...s},c=new Set,a=(N,k=[])=>N?Object.entries(N).flatMap(([E,_])=>{if(!_)return;if(typeof _=="object")return a(_,[...k,E]);const J=fe(E),B=R(E),K=[...k,J].join(".");c.add(`"${K}"`);const U=[...k.map(R),B].join("-"),{result:he}=re(_);return`--${U}: ${he};`}):[],i=N=>N?Object.entries(N).flatMap(([k,E])=>{const _=a(E);return k==="base"?_.join(""):`${k} { ${_.join("")} }`}):[],d=N=>N?Object.entries(N).flatMap(([k,E])=>Object.entries(E).flatMap(([_,J])=>{const B=a(J,[k]),K=`.${k}-${_}, [data-${k}="${_}"]`,U=B.join("");return`${K} { ${U} }`})):[],r=N=>t.variables.map(k=>k._current[N]),o=a(q(s.variables,r("variables"))),g=i(q(s.responsiveVariables,r("responsiveVariables"))),p=d(q(s.conditionalVariables,r("conditionalVariables"))),y=await z(e),x=l.join(y,"css/_variables.css"),D=`:root { ${o.join("")} ${g.join("")} } ${p.join("")}`;u.writeFileSync(x,D);const T=l.join(y,"css/_global.css"),j=q(s.global,t.globalStyles),F=M(j,"");u.writeFileSync(T,`@layer global { ${F} }`);const P=l.join(y,"css/_reset.css"),O=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:xe,f=M(O,"");u.writeFileSync(P,`@layer reset { ${f} }`);const $=l.join(y,"css/_templates.css"),S=q(s.templates,t.templates);console.log("all",S);const w=ie(S),h=Fe(S);u.writeFileSync($,w),n.templates=S;const C=l.join(y,"types/css-tokens.d.ts"),Z=`
9
+ // Variable types
10
+ type VariableTokens = ${[...c].join("|")};
11
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
11
12
 
12
- ${["@import url('./css/variables.css');","@import url('./css/global.css');","@import url('./css/templates.css');"].join(`
13
+ // Template types
14
+ type TemplateTokens = {
15
+ ${Object.entries(h).map(([N,k])=>`${N}?: ${k}`).join(`
13
16
  `)}
14
- ${f}`;if($.importStrategy!=="component"){const p=e.flat().map(h=>`@import url('./css/${h}');`).join(`
15
- `);i+=p}m.writeFileSync(r,i)}catch(s){console.error(s)}},tt=async(t,s)=>{try{const e=[],n=u.join(t,"./saltygen"),r=u.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=u.join(n,O);e.push(w),m.writeFileSync(b,S.css)});const f=m.readFileSync(r,"utf8").split(`
16
- `),o=e.map(h=>`@import url('../saltygen/css/${h}');`),p=[...new Set([...f,...o])].join(`
17
- `);m.writeFileSync(r,p)}}catch(e){console.error(e)}},st=async(t,s)=>{try{const e=u.join(t,"./saltygen");if(V(s)){const r=m.readFileSync(s,"utf8");r.replace(/^(?!export\s)const\s.*/gm,i=>`export ${i}`)!==r&&await J.writeFile(s,r);const $=await A(t),a=await _(s,e);let f=r;Object.entries(a).forEach(([i,p])=>{var b;if(p.isKeyframes){console.log("value",p);return}if(!p.generator)return;const h=p.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\\(([^,]+),[^;]+;`,"g");f=f.replace(O,w)});const o=E(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(e)}},et=t=>({name:"stylegen",buildStart:()=>v(t),load:async s=>{if(V(s))return await st(t,s)},watchChange:{handler:async s=>{V(s)&&await tt(t,s),s.includes("salty.config")&&await I(t)}}});exports.saltyPlugin=et;
17
+ }
18
+ `;u.writeFileSync(C,Z);const I=l.join(y,"cache/config-cache.json");u.writeFileSync(I,JSON.stringify(n,null,2))},se=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const c=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!c.test(e))return t;const i=c.exec(e);if(i){const d=i.at(1);if(de.some(o=>d==null?void 0:d.includes(o)))return t}return"styled('div',"}),Y=async(e,t,s)=>{const n=L(t),c=l.join(s,"./temp");u.existsSync(c)||u.mkdirSync(c);const a=l.parse(t);let i=u.readFileSync(t,"utf8");i=se(i);const d=l.join(s,"js",n+".js"),r=await X(e),o=l.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),g=ue(o),p=await le(e);await oe.build({stdin:{contents:i,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:p,target:["node20"],keepNames:!0,external:g,packages:"external",plugins:[{name:"test",setup:D=>{D.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},T=>{const j=u.readFileSync(T.path,"utf8");return{contents:se(j),loader:"ts"}})}}]});const y=Date.now();return await import(`${d}?t=${y}`)},ee=async e=>{const t=await z(e),s=l.join(t,"cache/config-cache.json"),n=u.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ye=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},_e=async(e,t=ye(),s=!0)=>{try{const n=Date.now();t?Q.info("Generating CSS in production mode! 🔥"):Q.info("Generating CSS in development mode! 🚀");const c=[],a=[],i=await z(e),d=l.join(i,"index.css");s&&(()=>{u.existsSync(i)&&Se.execSync("rm -rf "+i),u.mkdirSync(i,{recursive:!0}),u.mkdirSync(l.join(i,"css")),u.mkdirSync(l.join(i,"types")),u.mkdirSync(l.join(i,"js")),u.mkdirSync(l.join(i,"cache"))})();const o={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[],templates:[]};async function g(f){const $=["node_modules","saltygen"],S=u.statSync(f);if(S.isDirectory()){const w=u.readdirSync(f);if($.some(C=>f.includes(C)))return;await Promise.all(w.map(C=>g(l.join(f,C))))}else if(S.isFile()&&W(f)){const h=await Y(e,f,i);Object.entries(h).forEach(([C,m])=>{m.isKeyframes?o.keyframes.push({value:m,src:f,name:C}):m.isMedia?o.mediaQueries.push(m):m.isGlobalDefine?o.globalStyles.push(m):m.isDefineVariables?o.variables.push(m):m.isDefineTemplates?o.templates.push(m):m.generator&&o.components.push({value:m.generator,src:f,name:C})})}}await g(e),await Pe(e,o);const p=await ee(e);for(const f of o.keyframes){const{value:$}=f,S=`a_${$.animationName}.css`,w=`css/${S}`,h=l.join(i,w);c.push(S),u.writeFileSync(h,$.css)}const y={};for(const f of o.components){const{value:$,name:S,src:w}=f,h=$._withBuildContext({name:S,config:p,prod:t});a[h.priority]||(a[h.priority]=[]),a[h.priority].push(h.cssFileName),p.importStrategy==="component"&&(y[w]?y[w].push(h.cssFileName):y[w]=[h.cssFileName]);const C=`css/${h.cssFileName}`,m=l.join(i,C);u.writeFileSync(m,h.css)}p.importStrategy==="component"&&Object.entries(y).forEach(([f,$])=>{const S=$.map(Z=>`@import url('./${Z}');`).join(`
19
+ `),w=L(f,6),h=l.parse(f),C=R(h.name),m=l.join(i,`css/f_${C}-${w}.css`);u.writeFileSync(m,S)});const x=c.map(f=>`@import url('./css/${f}');`).join(`
20
+ `);let F=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
+
22
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return u.readFileSync(l.join(i,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
23
+ `)}
24
+ ${x}`;if(p.importStrategy!=="component"){const f=a.reduce(($,S,w)=>{const h=S.reduce((I,N)=>{var J;const k=l.join(i,"css",N),E=u.readFileSync(k,"utf8"),_=((J=/.*-([^-]+)-\d+.css/.exec(N))==null?void 0:J.at(1))||L(k,6);return I.includes(_)?I:`${I}
25
+ /*start:${_}*/
26
+ ${E}
27
+ /*end:${_}*/
28
+ `},""),C=`l_${w}.css`,m=l.join(i,"css",C),Z=`@layer l${w} { ${h}
29
+ }`;return u.writeFileSync(m,Z),`${$}
30
+ @import url('./css/${C}');`},"");F+=f}u.writeFileSync(d,F);const b=Date.now()-n,O=b<200?"🔥":b<500?"🚀":b<1e3?"🎉":b<2e3?"🚗":b<5e3?"🤔":"🥴";Q.info(`Generated CSS in ${b}ms! ${O}`)}catch(n){console.error(n)}},Te=async(e,t)=>{try{const s=await z(e);if(W(t)){const c=[],a=await ee(e),i=await Y(e,t,s);Object.entries(i).forEach(([d,r])=>{if(r.isKeyframes&&r.css){const x=`css/${`a_${r.animationName}.css`}`,D=l.join(s,x);u.writeFileSync(D,r.css);return}if(!r.generator)return;const o=r.generator._withBuildContext({name:d,config:a}),g=`css/${o.cssFileName}`,p=l.join(s,g);u.writeFileSync(p,o.css),c[o.priority]||(c[o.priority]=[]),c[o.priority].push(o.cssFileName)}),a.importStrategy!=="component"&&c.forEach((d,r)=>{const o=`l_${r}.css`,g=l.join(s,"css",o);let p=u.readFileSync(g,"utf8");d.forEach(y=>{var j;const x=l.join(s,"css",y),D=((j=/.*-([^-]+)-\d+.css/.exec(y))==null?void 0:j.at(1))||L(x,6);if(!p.includes(D)){const F=u.readFileSync(x,"utf8"),P=`/*start:${D}*/
31
+ ${F}
32
+ /*end:${D}*/
33
+ `;p=`${p.replace(/\}$/,"")}
34
+ ${P}
35
+ }`}}),u.writeFileSync(g,p)})}}catch(s){console.error(s)}},Oe=async(e,t,s=ye())=>{try{const n=await z(e);if(W(t)){const a=u.readFileSync(t,"utf8");a.replace(/^(?!export\s)const\s.*/gm,g=>`export ${g}`)!==a&&await G.writeFile(t,a);const d=await ee(e),r=await Y(e,t,n);let o=a;if(Object.entries(r).forEach(([g,p])=>{var C;if(p.isKeyframes||!p.generator)return;const y=p.generator._withBuildContext({name:g,config:d,prod:s}),x=new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(a);if(!x)return console.error("Could not find the original declaration");const D=(C=x.at(1))==null?void 0:C.trim(),T=new RegExp(`\\s${g}[=\\s]+styled\\(`,"g").exec(o);if(!T)return console.error("Could not find the original declaration");const{index:j}=T;let F=!1;const P=setTimeout(()=>F=!0,5e3);let b=0,O=!1,f=0;for(;!O&&!F;){const m=o[j+b];m==="("&&f++,m===")"&&f--,f===0&&m===")"&&(O=!0),b>o.length&&(F=!0),b++}if(!F)clearTimeout(P);else throw new Error("Failed to find the end of the styled call and timed out");const $=j+b,S=o.slice(j,$),w=o,h=` ${g} = styled(${D}, "${y.classNames}", ${JSON.stringify(y.props)});`;o=o.replace(S,h),w===o&&console.error("Minimize file failed to change content",{name:g,tagName:D})}),d.importStrategy==="component"){const g=L(t,6),p=l.parse(t);o=`import '../../saltygen/css/${`f_${R(p.name)}-${g}.css`}';
36
+ ${o}`}return o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}},ne=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!W(e))return!1;const n=await G.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},ge=e=>({name:"stylegen",buildStart:()=>_e(e),load:async t=>{if(W(t))return await Oe(e,t)},handleHotUpdate:async({file:t,server:s})=>{await ne(t)&&await s.restart()},watchChange:{handler:async t=>{W(t)&&(await ne(t)||await Te(e,t))}}});exports.default=ge;exports.saltyPlugin=ge;
package/index.d.ts CHANGED
@@ -1,8 +1,3 @@
1
- export declare const saltyPlugin: (dir: string) => {
2
- name: string;
3
- buildStart: () => Promise<void>;
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,505 @@
1
- import * as Z from "esbuild";
2
- import { execSync as q } from "child_process";
3
- import { join as u } from "path";
4
- import { writeFileSync as C, existsSync as z, 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) => {
7
- let e = "", n;
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) => {
11
- let e = s.length;
12
- for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
1
+ import * as ct from "esbuild";
2
+ import { execSync as bt } from "child_process";
3
+ import { join as f, parse as Y } from "path";
4
+ import { existsSync as v, mkdirSync as Z, statSync as St, readdirSync as wt, writeFileSync as P, readFileSync as M } from "fs";
5
+ import { readFile as tt, writeFile as jt } from "fs/promises";
6
+ import { createLogger as Ct, format as U, transports as Ft } from "winston";
7
+ const ot = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), xt = (t, e) => {
8
+ let s = "", n;
9
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = ot(n % 52) + s;
10
+ return s = ot(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
+ }, kt = (t, e) => {
12
+ let s = e.length;
13
+ for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
13
14
  return t;
14
- }, A = (t, s = 3) => {
15
- const e = Y(5381, JSON.stringify(t)) >>> 0;
16
- return X(e, s);
15
+ }, B = (t, e = 5) => {
16
+ const s = kt(5381, JSON.stringify(t)) >>> 0;
17
+ return xt(s, e);
17
18
  };
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()) : "";
19
+ function J(t) {
20
+ return t ? typeof t != "string" ? J(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 Q = (t, s) => {
22
+ const Nt = (t, e) => {
22
23
  if (typeof t != "string") return { result: t };
23
- if (!s) return { result: t };
24
- const e = [];
25
- return Object.values(s).forEach((n) => {
26
- const { pattern: r, transform: y } = n;
27
- t = t.replace(r, ($) => {
28
- const { value: a, css: f } = y($);
29
- return f && e.push(f), a;
24
+ if (!e) return { result: t };
25
+ const s = [];
26
+ return Object.values(e).forEach((n) => {
27
+ const { pattern: c, transform: a } = n;
28
+ t = t.replace(c, (i) => {
29
+ const { value: u, css: r } = a(i);
30
+ return r && s.push(r), u;
30
31
  });
31
- }), { result: t, additionalCss: e };
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) => {
32
+ }), { result: t, additionalCss: s };
33
+ }, at = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${J(n[1].replaceAll(".", "-"))})`) } : { result: t }, R = (t, e, s) => {
33
34
  if (!t) return "";
34
- const r = [], y = Object.entries(t).reduce((a, [f, o]) => {
35
- const i = f.trim();
36
- if (typeof o == "function" && (o = o()), typeof o == "object") {
37
- if (!o) return a;
38
- if (i === "variants")
39
- return Object.entries(o).forEach(([g, c]) => {
40
- c && Object.entries(c).forEach(([m, l]) => {
35
+ const n = [], c = Object.entries(t).reduce((i, [u, r]) => {
36
+ const o = u.trim();
37
+ if (typeof r == "function" && (r = r()), typeof r == "object") {
38
+ if (!r) return i;
39
+ if (o === "variants")
40
+ return Object.entries(r).forEach(([D, $]) => {
41
+ $ && Object.entries($).forEach(([O, l]) => {
41
42
  if (!l) return;
42
- const S = `${s}.${g}-${m}`, D = O(l, S);
43
- r.push(D);
43
+ const S = `${e}.${D}-${O}`, m = R(l, S);
44
+ n.push(m);
44
45
  });
45
- }), a;
46
- if (i === "defaultVariants")
47
- return a;
48
- if (i === "compoundVariants")
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
- }), a;
53
- if (i.startsWith("@")) {
54
- const g = O(o, s), c = `${i} {
55
- ${g.replace(`
46
+ }), i;
47
+ if (o === "defaultVariants")
48
+ return i;
49
+ if (o === "compoundVariants")
50
+ return r.forEach((D) => {
51
+ const { css: $, ...O } = D, l = Object.entries(O).reduce((m, [w, h]) => `${m}.${w}-${h}`, e), S = R($, l);
52
+ n.push(S);
53
+ }), i;
54
+ if (o.startsWith("@")) {
55
+ const D = R(r, e), $ = `${o} {
56
+ ${D.replace(`
56
57
  `, `
57
58
  `)}
58
59
  }`;
59
- return r.push(c), a;
60
+ return n.push($), i;
60
61
  }
61
- const d = f.includes("&") ? i.replace("&", s) : i.startsWith(":") ? `${s}${i}` : `${s} ${i}`, x = O(o, d);
62
- return r.push(x), a;
62
+ const b = u.includes("&") ? o.replace("&", e) : o.startsWith(":") ? `${e}${o}` : `${e} ${o}`, j = R(r, b);
63
+ return n.push(j), i;
63
64
  }
64
- const p = i.startsWith("-") ? i : V(i), h = (d, x = ";") => a = `${a}${d}${x}`, b = (d) => h(`${p}:${d}`);
65
- if (typeof o == "number") return b(o);
66
- if (typeof o != "string")
67
- if ("toString" in o) o = o.toString();
68
- else return a;
69
- const { modifiers: j } = {}, F = function* () {
70
- yield B(o), yield Q(o, j);
65
+ const g = o.startsWith("-") ? o : J(o), p = (b, j = ";") => i = `${i}${b}${j}`, d = (b) => p(`${g}:${b}`);
66
+ if (typeof r == "number") return d(r);
67
+ if (typeof r != "string")
68
+ if ("toString" in r) r = r.toString();
69
+ else return i;
70
+ const { modifiers: x } = {}, T = function* () {
71
+ yield at(r), yield Nt(r, x);
71
72
  }();
72
- for (const { result: d, additionalCss: x = [] } of F)
73
- o = d, x.forEach((g) => {
74
- const c = O(g, "");
75
- h(c, "");
73
+ for (const { result: b, additionalCss: j = [] } of T)
74
+ r = b, j.forEach((D) => {
75
+ const $ = R(D, "");
76
+ p($, "");
76
77
  });
77
- return b(o);
78
+ return d(r);
78
79
  }, "");
79
- if (!y) return r.join(`
80
+ return c ? e ? [`${e} { ${c} }`, ...n].join(`
81
+ `) : c : n.join(`
80
82
  `);
81
- if (!s) return y;
82
- let $ = "";
83
- return $ = `${s} { ${y} }`, [$, ...r].join(`
84
- `);
85
- }, H = (t, s = []) => {
83
+ }, lt = (t, e = []) => {
86
84
  if (!t) return "";
87
- const e = [], n = {};
88
- if (Object.entries(t).forEach(([r, y]) => {
89
- if (typeof y == "object") {
90
- if (!y) return;
91
- const $ = r.trim(), a = H(y, [...s, $]);
92
- e.push(a);
85
+ const s = [], n = {};
86
+ if (Object.entries(t).forEach(([c, a]) => {
87
+ if (typeof a == "object") {
88
+ if (!a) return;
89
+ const i = c.trim(), u = lt(a, [...e, i]);
90
+ s.push(u);
93
91
  } else
94
- n[r] = y;
92
+ n[c] = a;
95
93
  }), Object.keys(n).length) {
96
- const r = s.map(V).join("-"), y = O(n, `.${r}`);
97
- e.push(y);
94
+ const c = e.map(J).join("-"), a = R(n, `.${c}`);
95
+ s.push(a);
98
96
  }
99
- return e.join(`
97
+ return s.join(`
100
98
  `);
101
- }, E = (t) => u(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 = u(t, "salty.config.ts"), n = u(s, "salty.config.js");
103
- await Z.build({
104
- entryPoints: [e],
99
+ }, Dt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = ft(n).map((c) => `"${c}"`).join(" | ")), e), {}) : {}, ft = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, c]) => {
100
+ const a = e ? `${e}.${n}` : n;
101
+ return typeof c == "object" ? ft(c, a, s) : s.add(e);
102
+ }), [...s]) : [], ut = (t) => {
103
+ if (!t || t === "/") throw new Error("Could not find package.json file");
104
+ const e = f(t, "package.json");
105
+ return v(e) ? e : ut(f(t, ".."));
106
+ }, Et = async (t) => {
107
+ const e = ut(t);
108
+ return await tt(e, "utf-8").then(JSON.parse).catch(() => {
109
+ });
110
+ }, Pt = async (t) => {
111
+ const e = await Et(t);
112
+ if (e)
113
+ return e.type;
114
+ };
115
+ let W;
116
+ const pt = async (t) => {
117
+ if (W) return W;
118
+ const e = await Pt(t);
119
+ return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
120
+ }, X = Ct({
121
+ level: "debug",
122
+ format: U.combine(U.colorize(), U.cli()),
123
+ transports: [new Ft.Console({})]
124
+ });
125
+ function dt(t) {
126
+ return t ? typeof t != "string" ? dt(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
127
+ }
128
+ const Tt = {
129
+ /** Set box model to border-box */
130
+ "*, *::before, *::after": {
131
+ boxSizing: "border-box"
132
+ },
133
+ /** Remove default margin and padding */
134
+ "*": {
135
+ margin: 0
136
+ },
137
+ /** Remove adjust font properties */
138
+ html: {
139
+ lineHeight: 1.15,
140
+ textSizeAdjust: "100%",
141
+ WebkitFontSmoothing: "antialiased"
142
+ },
143
+ /** Make media elements responsive */
144
+ "img, picture, video, canvas, svg": {
145
+ display: "block",
146
+ maxWidth: "100%"
147
+ },
148
+ /** Avoid overflow of text */
149
+ "p, h1, h2, h3, h4, h5, h6": {
150
+ overflowWrap: "break-word"
151
+ },
152
+ /** Improve text wrapping */
153
+ p: {
154
+ textWrap: "pretty"
155
+ },
156
+ "h1, h2, h3, h4, h5, h6": {
157
+ textWrap: "balance"
158
+ },
159
+ /** Improve link color */
160
+ a: {
161
+ color: "currentColor"
162
+ },
163
+ /** Improve button line height */
164
+ button: {
165
+ lineHeight: "1em",
166
+ color: "currentColor"
167
+ },
168
+ /** Improve form elements */
169
+ "input, optgroup, select, textarea": {
170
+ fontFamily: "inherit",
171
+ fontSize: "100%",
172
+ lineHeight: "1.15em"
173
+ }
174
+ }, L = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), _ = {
175
+ externalModules: [],
176
+ rcFile: void 0,
177
+ destDir: void 0
178
+ }, gt = (t) => {
179
+ if (_.externalModules.length > 0) return _.externalModules;
180
+ const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
181
+ if (!s) return [];
182
+ const n = s[1].split(",").map((c) => c.replace(/['"`]/g, "").trim());
183
+ return _.externalModules = n, n;
184
+ }, H = async (t) => {
185
+ if (_.destDir) return _.destDir;
186
+ const e = await et(t), s = f(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
187
+ return _.destDir = s, s;
188
+ }, ht = ["salty", "css", "styles", "styled"], Ot = (t = []) => new RegExp(`\\.(${[...ht, ...t].join("|")})\\.`), z = (t, e = []) => Ot(e).test(t), yt = async (t) => {
189
+ if (_.rcFile) return _.rcFile;
190
+ if (t === "/") throw new Error("Could not find .saltyrc.json file");
191
+ const e = f(t, ".saltyrc.json"), s = await tt(e, "utf-8").then(JSON.parse).catch(() => {
192
+ });
193
+ return s ? (_.rcFile = s, s) : yt(f(t, ".."));
194
+ }, et = async (t) => {
195
+ var n, c;
196
+ const e = await yt(t), s = (n = e.projects) == null ? void 0 : n.find((a) => t.endsWith(a.dir || ""));
197
+ return s || ((c = e.projects) == null ? void 0 : c.find((a) => a.dir === e.defaultProject));
198
+ }, Vt = async (t) => {
199
+ const e = await et(t), s = await H(t), n = f(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), c = f(s, "salty.config.js"), a = await pt(t), i = gt(n);
200
+ await ct.build({
201
+ entryPoints: [n],
105
202
  minify: !0,
106
203
  treeShaking: !0,
107
204
  bundle: !0,
108
- outfile: n,
109
- format: "esm",
110
- external: ["react"]
205
+ outfile: c,
206
+ format: a,
207
+ external: i
111
208
  });
112
- const r = Date.now(), { config: y } = await import(`${n}?t=${r}`);
113
- return y;
114
- }, W = async (t) => {
115
- const s = await st(t), e = /* @__PURE__ */ new Set(), n = (g, c = []) => g ? Object.entries(g).flatMap(([m, l]) => {
116
- if (!l) return;
117
- if (typeof l == "object") return n(l, [...c, m]);
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]) => {
123
- const l = n(m);
124
- return c === "base" ? l.join("") : `${c} { ${l.join("")} }`;
125
- }) : [], y = (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 = y(s.conditionalVariables), o = E(t), i = u(o, "css/variables.css"), p = `:root { ${$.join("")} ${a.join("")} } ${f.join("")}`;
129
- C(i, p);
130
- const h = u(o, "types/css-tokens.d.ts"), j = `type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
131
- C(h, j);
132
- const w = u(o, "css/global.css"), F = O(s.global, "");
133
- C(w, F);
134
- const d = u(o, "css/templates.css"), x = H(s.templates);
135
- C(d, x);
136
- }, R = async (t, s) => {
137
- const e = A(t), n = u(s, "js", e + ".js");
138
- await Z.build({
139
- entryPoints: [t],
140
- minify: !0,
209
+ const u = Date.now(), { config: r } = await import(`${c}?t=${u}`);
210
+ return r;
211
+ }, _t = async (t, e) => {
212
+ const s = await Vt(t), n = { ...s }, c = /* @__PURE__ */ new Set(), a = (k, F = []) => k ? Object.entries(k).flatMap(([V, E]) => {
213
+ if (!E) return;
214
+ if (typeof E == "object") return a(E, [...F, V]);
215
+ const A = dt(V), K = J(V), q = [...F, A].join(".");
216
+ c.add(`"${q}"`);
217
+ const Q = [...F.map(J), K].join("-"), { result: $t } = at(E);
218
+ return `--${Q}: ${$t};`;
219
+ }) : [], i = (k) => k ? Object.entries(k).flatMap(([F, V]) => {
220
+ const E = a(V);
221
+ return F === "base" ? E.join("") : `${F} { ${E.join("")} }`;
222
+ }) : [], u = (k) => k ? Object.entries(k).flatMap(([F, V]) => Object.entries(V).flatMap(([E, A]) => {
223
+ const K = a(A, [F]), q = `.${F}-${E}, [data-${F}="${E}"]`, Q = K.join("");
224
+ return `${q} { ${Q} }`;
225
+ })) : [], r = (k) => e.variables.map((F) => F._current[k]), o = a(L(s.variables, r("variables"))), g = i(L(s.responsiveVariables, r("responsiveVariables"))), p = u(L(s.conditionalVariables, r("conditionalVariables"))), d = await H(t), x = f(d, "css/_variables.css"), N = `:root { ${o.join("")} ${g.join("")} } ${p.join("")}`;
226
+ P(x, N);
227
+ const T = f(d, "css/_global.css"), b = L(s.global, e.globalStyles), j = R(b, "");
228
+ P(T, `@layer global { ${j} }`);
229
+ const D = f(d, "css/_reset.css"), O = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Tt, l = R(O, "");
230
+ P(D, `@layer reset { ${l} }`);
231
+ const S = f(d, "css/_templates.css"), m = L(s.templates, e.templates);
232
+ console.log("all", m);
233
+ const w = lt(m), h = Dt(m);
234
+ P(S, w), n.templates = m;
235
+ const C = f(d, "types/css-tokens.d.ts"), I = `
236
+ // Variable types
237
+ type VariableTokens = ${[...c].join("|")};
238
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
239
+
240
+ // Template types
241
+ type TemplateTokens = {
242
+ ${Object.entries(h).map(([k, F]) => `${k}?: ${F}`).join(`
243
+ `)}
244
+ }
245
+ `;
246
+ P(C, I);
247
+ const G = f(d, "cache/config-cache.json");
248
+ P(G, JSON.stringify(n, null, 2));
249
+ }, rt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
250
+ if (/^['"`]/.test(s)) return e;
251
+ const c = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
252
+ if (!c.test(t)) return e;
253
+ const i = c.exec(t);
254
+ if (i) {
255
+ const u = i.at(1);
256
+ if (ht.some((o) => u == null ? void 0 : u.includes(o))) return e;
257
+ }
258
+ return "styled('div',";
259
+ }), st = async (t, e, s) => {
260
+ const n = B(e), c = f(s, "./temp");
261
+ v(c) || Z(c);
262
+ const a = Y(e);
263
+ let i = M(e, "utf8");
264
+ i = rt(i);
265
+ const u = f(s, "js", n + ".js"), r = await et(t), o = f(t, (r == null ? void 0 : r.configDir) || "", "salty.config.ts"), g = gt(o), p = await pt(t);
266
+ await ct.build({
267
+ stdin: {
268
+ contents: i,
269
+ sourcefile: a.base,
270
+ resolveDir: a.dir,
271
+ loader: "tsx"
272
+ },
273
+ minify: !1,
141
274
  treeShaking: !0,
142
275
  bundle: !0,
143
- outfile: n,
144
- format: "esm",
145
- target: ["es2022"],
276
+ outfile: u,
277
+ format: p,
278
+ target: ["node20"],
146
279
  keepNames: !0,
147
- external: ["react"]
280
+ external: g,
281
+ packages: "external",
282
+ plugins: [
283
+ {
284
+ name: "test",
285
+ setup: (N) => {
286
+ N.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (T) => {
287
+ const b = M(T.path, "utf8");
288
+ return { contents: rt(b), loader: "ts" };
289
+ });
290
+ }
291
+ }
292
+ ]
148
293
  });
149
- const r = Date.now();
150
- return await import(`${n}?t=${r}`);
151
- }, M = async (t) => {
152
- const s = E(t), e = u(s, "salty.config.js"), { config: n } = await import(e);
153
- return n;
154
- }, et = async (t) => {
294
+ const d = Date.now();
295
+ return await import(`${u}?t=${d}`);
296
+ }, nt = async (t) => {
297
+ const e = await H(t), s = f(e, "cache/config-cache.json"), n = M(s, "utf8");
298
+ if (!n) throw new Error("Could not find config cache file");
299
+ return JSON.parse(n);
300
+ }, mt = () => {
155
301
  try {
156
- const s = [], e = [], n = E(t), r = u(n, "index.css");
157
- (() => {
158
- z(n) && q("rm -rf " + n), T(n), T(u(n, "css")), T(u(n, "types"));
159
- })(), await W(t);
160
- const $ = await M(t);
161
- async function a(p, h) {
162
- const b = G(p);
163
- if (b.isDirectory()) {
164
- const j = L(p);
165
- await Promise.all(j.map((w) => a(u(p, w), u(h, w))));
166
- } else if (b.isFile() && k(p)) {
167
- const w = await R(p, n), F = [];
168
- Object.entries(w).forEach(([c, m]) => {
169
- if (m.isKeyframes && m.css) {
170
- const P = `${m.animationName}.css`, J = `css/${P}`, K = u(n, J);
171
- s.push(P), C(K, m.css);
172
- return;
173
- }
174
- if (!m.generator) return;
175
- const l = m.generator._withBuildContext({
176
- name: c,
177
- config: $
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 = u(n, D);
181
- C(N, l.css);
302
+ return process.env.NODE_ENV === "production";
303
+ } catch {
304
+ return !1;
305
+ }
306
+ }, Mt = async (t, e = mt(), s = !0) => {
307
+ try {
308
+ const n = Date.now();
309
+ e ? X.info("Generating CSS in production mode! 🔥") : X.info("Generating CSS in development mode! 🚀");
310
+ const c = [], a = [], i = await H(t), u = f(i, "index.css");
311
+ s && (() => {
312
+ v(i) && bt("rm -rf " + i), Z(i, { recursive: !0 }), Z(f(i, "css")), Z(f(i, "types")), Z(f(i, "js")), Z(f(i, "cache"));
313
+ })();
314
+ const o = {
315
+ keyframes: [],
316
+ mediaQueries: [],
317
+ globalStyles: [],
318
+ variables: [],
319
+ components: [],
320
+ templates: []
321
+ };
322
+ async function g(l) {
323
+ const S = ["node_modules", "saltygen"], m = St(l);
324
+ if (m.isDirectory()) {
325
+ const w = wt(l);
326
+ if (S.some((C) => l.includes(C))) return;
327
+ await Promise.all(w.map((C) => g(f(l, C))));
328
+ } else if (m.isFile() && z(l)) {
329
+ const h = await st(t, l, i);
330
+ Object.entries(h).forEach(([C, y]) => {
331
+ y.isKeyframes ? o.keyframes.push({
332
+ value: y,
333
+ src: l,
334
+ name: C
335
+ }) : y.isMedia ? o.mediaQueries.push(y) : y.isGlobalDefine ? o.globalStyles.push(y) : y.isDefineVariables ? o.variables.push(y) : y.isDefineTemplates ? o.templates.push(y) : y.generator && o.components.push({
336
+ value: y.generator,
337
+ src: l,
338
+ name: C
339
+ });
182
340
  });
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);
186
341
  }
187
342
  }
188
- await a(t, n);
189
- const f = s.map((p) => `@import url('./css/${p}');`).join(`
343
+ await g(t), await _t(t, o);
344
+ const p = await nt(t);
345
+ for (const l of o.keyframes) {
346
+ const { value: S } = l, m = `a_${S.animationName}.css`, w = `css/${m}`, h = f(i, w);
347
+ c.push(m), P(h, S.css);
348
+ }
349
+ const d = {};
350
+ for (const l of o.components) {
351
+ const { value: S, name: m, src: w } = l, h = S._withBuildContext({
352
+ name: m,
353
+ config: p,
354
+ prod: e
355
+ });
356
+ a[h.priority] || (a[h.priority] = []), a[h.priority].push(h.cssFileName), p.importStrategy === "component" && (d[w] ? d[w].push(h.cssFileName) : d[w] = [h.cssFileName]);
357
+ const C = `css/${h.cssFileName}`, y = f(i, C);
358
+ P(y, h.css);
359
+ }
360
+ p.importStrategy === "component" && Object.entries(d).forEach(([l, S]) => {
361
+ const m = S.map((I) => `@import url('./${I}');`).join(`
362
+ `), w = B(l, 6), h = Y(l), C = J(h.name), y = f(i, `css/f_${C}-${w}.css`);
363
+ P(y, m);
364
+ });
365
+ const x = c.map((l) => `@import url('./css/${l}');`).join(`
190
366
  `);
191
- let i = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
367
+ let j = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
192
368
 
193
- ${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
369
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
370
+ try {
371
+ return M(f(i, "css", l), "utf8").length > 0;
372
+ } catch {
373
+ return !1;
374
+ }
375
+ }).map((l) => `@import url('./css/${l}');`).join(`
194
376
  `)}
195
- ${f}`;
196
- if ($.importStrategy !== "component") {
197
- const p = e.flat().map((h) => `@import url('./css/${h}');`).join(`
198
- `);
199
- i += p;
377
+ ${x}`;
378
+ if (p.importStrategy !== "component") {
379
+ const l = a.reduce((S, m, w) => {
380
+ const h = m.reduce((G, k) => {
381
+ var A;
382
+ const F = f(i, "css", k), V = M(F, "utf8"), E = ((A = /.*-([^-]+)-\d+.css/.exec(k)) == null ? void 0 : A.at(1)) || B(F, 6);
383
+ return G.includes(E) ? G : `${G}
384
+ /*start:${E}*/
385
+ ${V}
386
+ /*end:${E}*/
387
+ `;
388
+ }, ""), C = `l_${w}.css`, y = f(i, "css", C), I = `@layer l${w} { ${h}
389
+ }`;
390
+ return P(y, I), `${S}
391
+ @import url('./css/${C}');`;
392
+ }, "");
393
+ j += l;
200
394
  }
201
- C(r, i);
202
- } catch (s) {
203
- console.error(s);
395
+ P(u, j);
396
+ const $ = Date.now() - n, O = $ < 200 ? "🔥" : $ < 500 ? "🚀" : $ < 1e3 ? "🎉" : $ < 2e3 ? "🚗" : $ < 5e3 ? "🤔" : "🥴";
397
+ X.info(`Generated CSS in ${$}ms! ${O}`);
398
+ } catch (n) {
399
+ console.error(n);
204
400
  }
205
- }, nt = async (t, s) => {
401
+ }, Rt = async (t, e) => {
206
402
  try {
207
- const e = [], n = u(t, "./saltygen"), r = u(n, "index.css");
208
- if (k(s)) {
209
- const $ = await M(t), a = await R(s, n);
210
- Object.entries(a).forEach(([h, b]) => {
211
- if (!b.generator) return;
212
- const j = b.generator._withBuildContext({
213
- name: h,
214
- config: $
215
- }), w = `${j.hash}-${j.priority}.css`, F = `css/${w}`, d = u(n, F);
216
- e.push(w), C(d, j.css);
403
+ const s = await H(t);
404
+ if (z(e)) {
405
+ const c = [], a = await nt(t), i = await st(t, e, s);
406
+ Object.entries(i).forEach(([u, r]) => {
407
+ if (r.isKeyframes && r.css) {
408
+ const x = `css/${`a_${r.animationName}.css`}`, N = f(s, x);
409
+ P(N, r.css);
410
+ return;
411
+ }
412
+ if (!r.generator) return;
413
+ const o = r.generator._withBuildContext({
414
+ name: u,
415
+ config: a
416
+ }), g = `css/${o.cssFileName}`, p = f(s, g);
417
+ P(p, o.css), c[o.priority] || (c[o.priority] = []), c[o.priority].push(o.cssFileName);
418
+ }), a.importStrategy !== "component" && c.forEach((u, r) => {
419
+ const o = `l_${r}.css`, g = f(s, "css", o);
420
+ let p = M(g, "utf8");
421
+ u.forEach((d) => {
422
+ var b;
423
+ const x = f(s, "css", d), N = ((b = /.*-([^-]+)-\d+.css/.exec(d)) == null ? void 0 : b.at(1)) || B(x, 6);
424
+ if (!p.includes(N)) {
425
+ const j = M(x, "utf8"), D = `/*start:${N}*/
426
+ ${j}
427
+ /*end:${N}*/
428
+ `;
429
+ p = `${p.replace(/\}$/, "")}
430
+ ${D}
431
+ }`;
432
+ }
433
+ }), P(g, p);
217
434
  });
218
- const f = I(r, "utf8").split(`
219
- `), o = e.map((h) => `@import url('../saltygen/css/${h}');`), p = [.../* @__PURE__ */ new Set([...f, ...o])].join(`
220
- `);
221
- C(r, p);
222
435
  }
223
- } catch (e) {
224
- console.error(e);
436
+ } catch (s) {
437
+ console.error(s);
225
438
  }
226
- }, rt = async (t, s) => {
439
+ }, Jt = async (t, e, s = mt()) => {
227
440
  try {
228
- const e = u(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);
233
- let f = r;
234
- Object.entries(a).forEach(([i, p]) => {
235
- var d;
236
- if (p.isKeyframes) {
237
- console.log("value", p);
238
- return;
441
+ const n = await H(t);
442
+ if (z(e)) {
443
+ const a = M(e, "utf8");
444
+ a.replace(/^(?!export\s)const\s.*/gm, (g) => `export ${g}`) !== a && await jt(e, a);
445
+ const u = await nt(t), r = await st(t, e, n);
446
+ let o = a;
447
+ if (Object.entries(r).forEach(([g, p]) => {
448
+ var C;
449
+ if (p.isKeyframes || !p.generator) return;
450
+ const d = p.generator._withBuildContext({
451
+ name: g,
452
+ config: u,
453
+ prod: s
454
+ }), x = new RegExp(`\\s${g}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
455
+ if (!x) return console.error("Could not find the original declaration");
456
+ const N = (C = x.at(1)) == null ? void 0 : C.trim(), T = new RegExp(`\\s${g}[=\\s]+styled\\(`, "g").exec(o);
457
+ if (!T) return console.error("Could not find the original declaration");
458
+ const { index: b } = T;
459
+ let j = !1;
460
+ const D = setTimeout(() => j = !0, 5e3);
461
+ let $ = 0, O = !1, l = 0;
462
+ for (; !O && !j; ) {
463
+ const y = o[b + $];
464
+ y === "(" && l++, y === ")" && l--, l === 0 && y === ")" && (O = !0), $ > o.length && (j = !0), $++;
239
465
  }
240
- if (!p.generator) return;
241
- const h = p.generator._withBuildContext({
242
- name: i,
243
- config: $
244
- }), b = new RegExp(`${i}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(r);
245
- if (!b)
246
- return console.error("Could not find the original declaration");
247
- 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\\(([^,]+),[^;]+;`, "g");
248
- f = f.replace(F, w);
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;
466
+ if (!j) clearTimeout(D);
467
+ else throw new Error("Failed to find the end of the styled call and timed out");
468
+ const S = b + $, m = o.slice(b, S), w = o, h = ` ${g} = styled(${N}, "${d.classNames}", ${JSON.stringify(d.props)});`;
469
+ o = o.replace(m, h), w === o && console.error("Minimize file failed to change content", { name: g, tagName: N });
470
+ }), u.importStrategy === "component") {
471
+ const g = B(e, 6), p = Y(e);
472
+ o = `import '../../saltygen/css/${`f_${J(p.name)}-${g}.css`}';
473
+ ${o}`;
474
+ }
475
+ return o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
253
476
  }
254
- } catch (e) {
255
- console.error(e);
477
+ } catch (n) {
478
+ console.error("Error in minimizeFile:", n);
256
479
  }
257
- }, lt = (t) => ({
480
+ }, it = async (t) => {
481
+ if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
482
+ if (t.includes("salty.config")) return !0;
483
+ if (!z(t)) return !1;
484
+ const n = await tt(t, "utf-8");
485
+ return !!/.+define[A-Z]\w+/.test(n);
486
+ }, It = (t) => ({
258
487
  name: "stylegen",
259
- buildStart: () => et(t),
260
- load: async (s) => {
261
- if (k(s))
262
- return await rt(t, s);
488
+ buildStart: () => Mt(t),
489
+ load: async (e) => {
490
+ if (z(e))
491
+ return await Jt(t, e);
492
+ },
493
+ handleHotUpdate: async ({ file: e, server: s }) => {
494
+ await it(e) && await s.restart();
263
495
  },
264
496
  watchChange: {
265
- handler: async (s) => {
266
- k(s) && await nt(t, s), s.includes("salty.config") && await W(t);
497
+ handler: async (e) => {
498
+ z(e) && (await it(e) || await Rt(t, e));
267
499
  }
268
500
  }
269
501
  });
270
502
  export {
271
- lt as saltyPlugin
503
+ It as default,
504
+ It as saltyPlugin
272
505
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.18",
3
+ "version": "0.0.1-alpha.180",
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
- "homepage": "https://github.com/margarita-form/salty-css",
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
- "peerDependencies": {
32
- "@salty-css/core": "^0.0.1-alpha.15"
36
+ "dependencies": {
37
+ "@salty-css/core": "^0.0.1-alpha.180"
33
38
  }
34
39
  }