@salty-css/vite 0.0.1-alpha.16 → 0.0.1-alpha.160

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 +438 -212
  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 ye=require("esbuild"),ge=require("child_process"),a=require("path"),f=require("fs"),L=require("fs/promises"),I=require("winston");var B=typeof document<"u"?document.currentScript:null;function me(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 te=me(ye),Y=e=>String.fromCharCode(e+(e>25?39:97)),he=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=Y(n%52)+s;return s=Y(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},Se=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},H=(e,t=5)=>{const s=Se(5381,JSON.stringify(e))>>>0;return he(s,t)};function M(e){return e?typeof e!="string"?M(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 be=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:r,transform:i}=n;e=e.replace(r,u=>{const{value:p,css:o}=i(u);return o&&s.push(o),p})}),{result:e,additionalCss:s}},se=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${M(n[1].replaceAll(".","-"))})`)}:{result:e},V=(e,t,s)=>{if(!e)return"";const n=[],r=Object.entries(e).reduce((u,[p,o])=>{const c=p.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return u;if(c==="variants")return Object.entries(o).forEach(([j,x])=>{x&&Object.entries(x).forEach(([l,m])=>{if(!m)return;const w=`${t}.${j}-${l}`,S=V(m,w);n.push(S)})}),u;if(c==="defaultVariants")return u;if(c==="compoundVariants")return o.forEach(j=>{const{css:x,...l}=j,m=Object.entries(l).reduce((S,[g,F])=>`${S}.${g}-${F}`,t),w=V(x,m);n.push(w)}),u;if(c.startsWith("@")){const j=V(o,t),x=`${c} {
2
+ ${j.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(x),u}const h=p.includes("&")?c.replace("&",t):c.startsWith(":")?`${t}${c}`:`${t} ${c}`,D=V(o,h);return n.push(D),u}const y=c.startsWith("-")?c:M(c),d=(h,D=";")=>u=`${u}${h}${D}`,k=h=>d(`${y}:${h}`);if(typeof o=="number")return k(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return u;const{modifiers:N}={},T=function*(){yield se(o),yield be(o,N)}();for(const{result:h,additionalCss:D=[]}of T)o=h,D.forEach(j=>{const x=V(j,"");d(x,"")});return k(o)},"");return r?t?[`${t} { ${r} }`,...n].join(`
6
+ `):r:n.join(`
7
+ `)},ne=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([r,i])=>{if(typeof i=="object"){if(!i)return;const u=r.trim(),p=ne(i,[...t,u]);s.push(p)}else n[r]=i}),Object.keys(n).length){const r=t.map(M).join("-"),i=V(n,`.${r}`);s.push(i)}return s.join(`
8
+ `)},$e=e=>Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=oe(n).map(r=>`"${r}"`).join(" | ")),t),{}),oe=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,r])=>{const i=t?`${t}.${n}`:n;return typeof r=="object"?oe(r,i,s):s.add(t)}),[...s]):[],re=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=a.join(e,"package.json");return f.existsSync(t)?t:re(a.join(e,".."))},je=async e=>{const t=re(e);return await L.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},we=async e=>{const t=await je(e);if(t)return t.type};let J;const ie=async e=>{if(J)return J;const t=await we(e);return t==="module"?J="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:B&&B.tagName.toUpperCase()==="SCRIPT"&&B.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(J="cjs"),J||"esm"},K=I.createLogger({level:"debug",format:I.format.combine(I.format.colorize(),I.format.cli()),transports:[new I.transports.Console({})]});function ce(e){return e?typeof e!="string"?ce(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 Fe={"*, *::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},{}),E={externalModules:[],rcFile:void 0,destDir:void 0},ae=e=>{if(E.externalModules.length>0)return E.externalModules;const s=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return E.externalModules=n,n},z=async e=>{if(E.destDir)return E.destDir;const t=await U(e),s=a.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return E.destDir=s,s},le=["salty","css","styles","styled"],Ce=(e=[])=>new RegExp(`\\.(${[...le,...e].join("|")})\\.`),W=(e,t=[])=>Ce(t).test(e),fe=async e=>{if(E.rcFile)return E.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=a.join(e,".saltyrc.json"),s=await L.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(E.rcFile=s,s):fe(a.join(e,".."))},U=async e=>{var n,r;const t=await fe(e),s=(n=t.projects)==null?void 0:n.find(i=>e.endsWith(i.dir||""));return s||((r=t.projects)==null?void 0:r.find(i=>i.dir===t.defaultProject))},xe=async e=>{const t=await U(e),s=await z(e),n=a.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=a.join(s,"salty.config.js"),i=await ie(e),u=ae(n);await te.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:i,external:u});const p=Date.now(),{config:o}=await import(`${r}?t=${p}`);return o},ke=async(e,t)=>{const s=await xe(e),n=new Set,r=($,C=[])=>$?Object.entries($).flatMap(([O,_])=>{if(!_)return;if(typeof _=="object")return r(_,[...C,O]);const Z=ce(O),R=M(O),A=[...C,Z].join(".");n.add(`"${A}"`);const G=[...C.map(M),R].join("-"),{result:pe}=se(_);return`--${G}: ${pe};`}):[],i=$=>$?Object.entries($).flatMap(([C,O])=>{const _=r(O);return C==="base"?_.join(""):`${C} { ${_.join("")} }`}):[],u=$=>$?Object.entries($).flatMap(([C,O])=>Object.entries(O).flatMap(([_,Z])=>{const R=r(Z,[C]),A=`.${C}-${_}, [data-${C}="${_}"]`,G=R.join("");return`${A} { ${G} }`})):[],p=$=>t.variables.map(C=>C._current[$]),o=r(q(s.variables,p("variables"))),c=i(q(s.responsiveVariables,p("responsiveVariables"))),y=u(q(s.conditionalVariables,p("conditionalVariables"))),d=await z(e),k=a.join(d,"css/_variables.css"),N=`:root { ${o.join("")} ${c.join("")} } ${y.join("")}`;f.writeFileSync(k,N);const P=a.join(d,"css/_global.css"),T=q(s.global,t.globalStyles),h=V(T,"");f.writeFileSync(P,`@layer global { ${h} }`);const D=a.join(d,"css/_reset.css"),x=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:Fe,l=V(x,"");f.writeFileSync(D,`@layer reset { ${l} }`);const m=a.join(d,"css/_templates.css"),w=ne(s.templates),S=$e(s.templates);f.writeFileSync(m,w);const g=a.join(d,"types/css-tokens.d.ts"),b=`
9
+ // Variable types
10
+ type VariableTokens = ${[...n].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(S).map(([$,C])=>`${$}?: ${C}`).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
+ `;f.writeFileSync(g,b)},v=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const r=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!r.test(e))return t;const u=r.exec(e);if(u){const p=u.at(1);if(le.some(c=>p==null?void 0:p.includes(c)))return t}return"styled('div',"}),Q=async(e,t,s)=>{const n=H(t),r=a.join(s,"./temp");f.existsSync(r)||f.mkdirSync(r);const i=a.parse(t);let u=f.readFileSync(t,"utf8");u=v(u);const p=a.join(s,"js",n+".js"),o=await U(e),c=a.join(e,(o==null?void 0:o.configDir)||"","salty.config.ts"),y=ae(c),d=await ie(e);await te.build({stdin:{contents:u,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:p,format:d,target:["node20"],keepNames:!0,external:y,packages:"external",plugins:[{name:"test",setup:P=>{P.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},T=>{const h=f.readFileSync(T.path,"utf8");return{contents:v(h),loader:"ts"}})}}]});const k=Date.now();return await import(`${p}?t=${k}`)},X=async e=>{const t=await z(e),s=a.join(t,"salty.config.js"),n=Date.now(),{config:r}=await import(`${s}?t=${n}`);return r},ue=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},De=async(e,t=ue())=>{try{const s=Date.now();t?K.info("Generating CSS in production mode! 🔥"):K.info("Generating CSS in development mode! 🚀");const n=[],r=[],i=await z(e),u=a.join(i,"index.css");(()=>{f.existsSync(i)&&ge.execSync("rm -rf "+i),f.mkdirSync(i,{recursive:!0}),f.mkdirSync(a.join(i,"css")),f.mkdirSync(a.join(i,"types"))})();const o={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[]};async function c(l){const m=["node_modules","saltygen"],w=f.statSync(l);if(w.isDirectory()){const S=f.readdirSync(l);if(m.some(F=>l.includes(F)))return;await Promise.all(S.map(F=>c(a.join(l,F))))}else if(w.isFile()&&W(l)){const g=await Q(e,l,i);Object.entries(g).forEach(([F,b])=>{b.isKeyframes?o.keyframes.push({value:b,src:l,name:F}):b.isMedia?o.mediaQueries.push(b):b.isGlobalDefine?o.globalStyles.push(b):b.isDefineVariables?o.variables.push(b):b.generator&&o.components.push({value:b.generator,src:l,name:F})})}}await c(e),await ke(e,o);const y=await X(e);for(const l of o.keyframes){const{value:m}=l,w=`a_${m.animationName}.css`,S=`css/${w}`,g=a.join(i,S);n.push(w),f.writeFileSync(g,m.css)}const d={};for(const l of o.components){const{value:m,name:w,src:S}=l,g=m._withBuildContext({name:w,config:y,prod:t});r[g.priority]||(r[g.priority]=[]),r[g.priority].push(g.cssFileName),y.importStrategy==="component"&&(d[S]?d[S].push(g.cssFileName):d[S]=[g.cssFileName]);const F=`css/${g.cssFileName}`,b=a.join(i,F);f.writeFileSync(b,g.css)}y.importStrategy==="component"&&Object.entries(d).forEach(([l,m])=>{const w=m.map($=>`@import url('./${$}');`).join(`
19
+ `),S=H(l,6),g=a.parse(l),F=M(g.name),b=a.join(i,`css/f_${F}-${S}.css`);f.writeFileSync(b,w)});const k=n.map(l=>`@import url('./css/${l}');`).join(`
20
+ `);let h=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
+
22
+ ${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return f.readFileSync(a.join(i,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
23
+ `)}
24
+ ${k}`;if(y.importStrategy!=="component"){const l=r.reduce((m,w,S)=>{const g=w.reduce((C,O)=>{var A;const _=a.join(i,"css",O),Z=f.readFileSync(_,"utf8"),R=((A=/.*-([^-]+)-\d+.css/.exec(O))==null?void 0:A.at(1))||H(_,6);return C.includes(R)?C:`${C}
25
+ /*start:${R}*/
26
+ ${Z}
27
+ /*end:${R}*/
28
+ `},""),F=`l_${S}.css`,b=a.join(i,"css",F),$=`@layer l${S} { ${g}
29
+ }`;return f.writeFileSync(b,$),`${m}
30
+ @import url('./css/${F}');`},"");h+=l}f.writeFileSync(u,h);const j=Date.now()-s,x=j<200?"🔥":j<500?"🚀":j<1e3?"🎉":j<2e3?"🚗":j<5e3?"🤔":"🥴";K.info(`Generated CSS in ${j}ms! ${x}`)}catch(s){console.error(s)}},Ne=async(e,t)=>{try{const s=await z(e);if(W(t)){const r=[],i=await X(e),u=await Q(e,t,s);Object.entries(u).forEach(([p,o])=>{if(o.isKeyframes&&o.css){const N=`css/${`a_${o.animationName}.css`}`,P=a.join(s,N);f.writeFileSync(P,o.css);return}if(!o.generator)return;const c=o.generator._withBuildContext({name:p,config:i}),y=`css/${c.cssFileName}`,d=a.join(s,y);f.writeFileSync(d,c.css),r[c.priority]||(r[c.priority]=[]),r[c.priority].push(c.cssFileName)}),i.importStrategy!=="component"&&r.forEach((p,o)=>{const c=`l_${o}.css`,y=a.join(s,"css",c);let d=f.readFileSync(y,"utf8");p.forEach(k=>{var h;const N=a.join(s,"css",k),P=((h=/.*-([^-]+)-\d+.css/.exec(k))==null?void 0:h.at(1))||H(N,6);if(!d.includes(P)){const D=f.readFileSync(N,"utf8"),j=`/*start:${P}*/
31
+ ${D}
32
+ /*end:${P}*/
33
+ `;d=`${d.replace(/\}$/,"")}
34
+ ${j}
35
+ }`}}),f.writeFileSync(y,d)})}}catch(s){console.error(s)}},Pe=async(e,t,s=ue())=>{try{const n=await z(e);if(W(t)){const i=f.readFileSync(t,"utf8");i.replace(/^(?!export\s)const\s.*/gm,y=>`export ${y}`)!==i&&await L.writeFile(t,i);const p=await X(e),o=await Q(e,t,n);let c=i;if(Object.entries(o).forEach(([y,d])=>{var b;if(d.isKeyframes||!d.generator)return;const k=d.generator._withBuildContext({name:y,config:p,prod:s}),N=new RegExp(`\\s${y}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!N)return console.error("Could not find the original declaration");const P=(b=N.at(1))==null?void 0:b.trim(),T=new RegExp(`\\s${y}[=\\s]+styled\\(`,"g").exec(c);if(!T)return console.error("Could not find the original declaration");const{index:h}=T;let D=!1;const j=setTimeout(()=>D=!0,5e3);let x=0,l=!1,m=0;for(;!l&&!D;){const $=c[h+x];$==="("&&m++,$===")"&&m--,m===0&&$===")"&&(l=!0),x>c.length&&(D=!0),x++}if(!D)clearTimeout(j);else throw new Error("Failed to find the end of the styled call and timed out");const w=h+x,S=c.slice(h,w),g=c,F=` ${y} = styled(${P}, "${k.classNames}", ${JSON.stringify(k.props)});`;c=c.replace(S,F),g===c&&console.error("Minimize file failed to change content",{name:y,tagName:P})}),p.importStrategy==="component"){const y=H(t,6),d=a.parse(t);c=`import '../../saltygen/css/${`f_${M(d.name)}-${y}.css`}';
36
+ ${c}`}return c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(n){console.error("Error in minimizeFile:",n)}},ee=async e=>{if(e.includes("salty.config"))return!0;if(!W(e))return!1;const n=await L.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(n)},de=e=>({name:"stylegen",buildStart:()=>De(e),load:async t=>{if(W(t))return await Pe(e,t)},handleHotUpdate:async({file:t,server:s})=>{await ee(t)&&await s.restart()},watchChange:{handler:async t=>{W(t)&&(await ee(t)||await Ne(e,t))}}});exports.default=de;exports.saltyPlugin=de;
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,498 @@
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 ot from "esbuild";
2
+ import { execSync as mt } from "child_process";
3
+ import { join as l, parse as Q } from "path";
4
+ import { existsSync as U, mkdirSync as L, statSync as ht, readdirSync as $t, writeFileSync as P, readFileSync as M } from "fs";
5
+ import { readFile as X, writeFile as bt } from "fs/promises";
6
+ import { createLogger as St, format as K, transports as wt } from "winston";
7
+ const et = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), jt = (t, e) => {
8
+ let s = "", n;
9
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = et(n % 52) + s;
10
+ return s = et(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
+ }, Ft = (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
+ }, I = (t, e = 5) => {
16
+ const s = Ft(5381, JSON.stringify(t)) >>> 0;
17
+ return jt(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 R(t) {
20
+ return t ? typeof t != "string" ? R(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 Ct = (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: r, transform: i } = n;
28
+ t = t.replace(r, (f) => {
29
+ const { value: p, css: o } = i(f);
30
+ return o && s.push(o), p;
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
+ }, rt = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${R(n[1].replaceAll(".", "-"))})`) } : { result: t }, O = (t, e, s) => {
33
34
  if (!t) return "";
34
- const r = [], y = Object.entries(t).reduce((a, [f, o]) => {
35
- const i = f.trim();
35
+ const n = [], r = Object.entries(t).reduce((f, [p, o]) => {
36
+ const c = p.trim();
36
37
  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]) => {
41
- if (!l) return;
42
- const S = `${s}.${g}-${m}`, D = O(l, S);
43
- r.push(D);
38
+ if (!o) return f;
39
+ if (c === "variants")
40
+ return Object.entries(o).forEach(([S, C]) => {
41
+ C && Object.entries(C).forEach(([a, y]) => {
42
+ if (!y) return;
43
+ const w = `${e}.${S}-${a}`, h = O(y, w);
44
+ n.push(h);
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
+ }), f;
47
+ if (c === "defaultVariants")
48
+ return f;
49
+ if (c === "compoundVariants")
50
+ return o.forEach((S) => {
51
+ const { css: C, ...a } = S, y = Object.entries(a).reduce((h, [g, j]) => `${h}.${g}-${j}`, e), w = O(C, y);
52
+ n.push(w);
53
+ }), f;
54
+ if (c.startsWith("@")) {
55
+ const S = O(o, e), C = `${c} {
56
+ ${S.replace(`
56
57
  `, `
57
58
  `)}
58
59
  }`;
59
- return r.push(c), a;
60
+ return n.push(C), f;
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 m = p.includes("&") ? c.replace("&", e) : c.startsWith(":") ? `${e}${c}` : `${e} ${c}`, k = O(o, m);
63
+ return n.push(k), f;
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);
65
+ const d = c.startsWith("-") ? c : R(c), u = (m, k = ";") => f = `${f}${m}${k}`, x = (m) => u(`${d}:${m}`);
66
+ if (typeof o == "number") return x(o);
66
67
  if (typeof o != "string")
67
68
  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);
69
+ else return f;
70
+ const { modifiers: D } = {}, T = function* () {
71
+ yield rt(o), yield Ct(o, D);
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: m, additionalCss: k = [] } of T)
74
+ o = m, k.forEach((S) => {
75
+ const C = O(S, "");
76
+ u(C, "");
76
77
  });
77
- return b(o);
78
+ return x(o);
78
79
  }, "");
79
- if (!y) return r.join(`
80
+ return r ? e ? [`${e} { ${r} }`, ...n].join(`
81
+ `) : r : n.join(`
80
82
  `);
81
- if (!s) return y;
82
- let $ = "";
83
- return $ = `${s} { ${y} }`, [$, ...r].join(`
84
- `);
85
- }, H = (t, s = []) => {
83
+ }, it = (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(([r, i]) => {
87
+ if (typeof i == "object") {
88
+ if (!i) return;
89
+ const f = r.trim(), p = it(i, [...e, f]);
90
+ s.push(p);
93
91
  } else
94
- n[r] = y;
92
+ n[r] = i;
95
93
  }), Object.keys(n).length) {
96
- const r = s.map(V).join("-"), y = O(n, `.${r}`);
97
- e.push(y);
94
+ const r = e.map(R).join("-"), i = O(n, `.${r}`);
95
+ s.push(i);
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
+ }, xt = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = ct(n).map((r) => `"${r}"`).join(" | ")), e), {}), ct = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, r]) => {
100
+ const i = e ? `${e}.${n}` : n;
101
+ return typeof r == "object" ? ct(r, i, s) : s.add(e);
102
+ }), [...s]) : [], at = (t) => {
103
+ if (!t || t === "/") throw new Error("Could not find package.json file");
104
+ const e = l(t, "package.json");
105
+ return U(e) ? e : at(l(t, ".."));
106
+ }, kt = async (t) => {
107
+ const e = at(t);
108
+ return await X(e, "utf-8").then(JSON.parse).catch(() => {
109
+ });
110
+ }, Dt = async (t) => {
111
+ const e = await kt(t);
112
+ if (e)
113
+ return e.type;
114
+ };
115
+ let W;
116
+ const lt = async (t) => {
117
+ if (W) return W;
118
+ const e = await Dt(t);
119
+ return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
120
+ }, q = St({
121
+ level: "debug",
122
+ format: K.combine(K.colorize(), K.cli()),
123
+ transports: [new wt.Console({})]
124
+ });
125
+ function ft(t) {
126
+ return t ? typeof t != "string" ? ft(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 Nt = {
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
+ }, G = (...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
+ }, ut = (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((r) => r.replace(/['"`]/g, "").trim());
183
+ return _.externalModules = n, n;
184
+ }, z = async (t) => {
185
+ if (_.destDir) return _.destDir;
186
+ const e = await Y(t), s = l(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
187
+ return _.destDir = s, s;
188
+ }, pt = ["salty", "css", "styles", "styled"], Et = (t = []) => new RegExp(`\\.(${[...pt, ...t].join("|")})\\.`), Z = (t, e = []) => Et(e).test(t), dt = async (t) => {
189
+ if (_.rcFile) return _.rcFile;
190
+ if (t === "/") throw new Error("Could not find .saltyrc.json file");
191
+ const e = l(t, ".saltyrc.json"), s = await X(e, "utf-8").then(JSON.parse).catch(() => {
192
+ });
193
+ return s ? (_.rcFile = s, s) : dt(l(t, ".."));
194
+ }, Y = async (t) => {
195
+ var n, r;
196
+ const e = await dt(t), s = (n = e.projects) == null ? void 0 : n.find((i) => t.endsWith(i.dir || ""));
197
+ return s || ((r = e.projects) == null ? void 0 : r.find((i) => i.dir === e.defaultProject));
198
+ }, Pt = async (t) => {
199
+ const e = await Y(t), s = await z(t), n = l(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), r = l(s, "salty.config.js"), i = await lt(t), f = ut(n);
200
+ await ot.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: r,
206
+ format: i,
207
+ external: f
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 p = Date.now(), { config: o } = await import(`${r}?t=${p}`);
210
+ return o;
211
+ }, Tt = async (t, e) => {
212
+ const s = await Pt(t), n = /* @__PURE__ */ new Set(), r = (b, F = []) => b ? Object.entries(b).flatMap(([V, E]) => {
213
+ if (!E) return;
214
+ if (typeof E == "object") return r(E, [...F, V]);
215
+ const H = ft(V), A = R(V), J = [...F, H].join(".");
216
+ n.add(`"${J}"`);
217
+ const B = [...F.map(R), A].join("-"), { result: yt } = rt(E);
218
+ return `--${B}: ${yt};`;
219
+ }) : [], i = (b) => b ? Object.entries(b).flatMap(([F, V]) => {
220
+ const E = r(V);
221
+ return F === "base" ? E.join("") : `${F} { ${E.join("")} }`;
222
+ }) : [], f = (b) => b ? Object.entries(b).flatMap(([F, V]) => Object.entries(V).flatMap(([E, H]) => {
223
+ const A = r(H, [F]), J = `.${F}-${E}, [data-${F}="${E}"]`, B = A.join("");
224
+ return `${J} { ${B} }`;
225
+ })) : [], p = (b) => e.variables.map((F) => F._current[b]), o = r(G(s.variables, p("variables"))), c = i(G(s.responsiveVariables, p("responsiveVariables"))), d = f(G(s.conditionalVariables, p("conditionalVariables"))), u = await z(t), x = l(u, "css/_variables.css"), D = `:root { ${o.join("")} ${c.join("")} } ${d.join("")}`;
226
+ P(x, D);
227
+ const N = l(u, "css/_global.css"), T = G(s.global, e.globalStyles), m = O(T, "");
228
+ P(N, `@layer global { ${m} }`);
229
+ const k = l(u, "css/_reset.css"), C = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Nt, a = O(C, "");
230
+ P(k, `@layer reset { ${a} }`);
231
+ const y = l(u, "css/_templates.css"), w = it(s.templates), h = xt(s.templates);
232
+ P(y, w);
233
+ const g = l(u, "types/css-tokens.d.ts"), $ = `
234
+ // Variable types
235
+ type VariableTokens = ${[...n].join("|")};
236
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
237
+
238
+ // Template types
239
+ type TemplateTokens = {
240
+ ${Object.entries(h).map(([b, F]) => `${b}?: ${F}`).join(`
241
+ `)}
242
+ }
243
+ `;
244
+ P(g, $);
245
+ }, st = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
246
+ if (/^['"`]/.test(s)) return e;
247
+ const r = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
248
+ if (!r.test(t)) return e;
249
+ const f = r.exec(t);
250
+ if (f) {
251
+ const p = f.at(1);
252
+ if (pt.some((c) => p == null ? void 0 : p.includes(c))) return e;
253
+ }
254
+ return "styled('div',";
255
+ }), v = async (t, e, s) => {
256
+ const n = I(e), r = l(s, "./temp");
257
+ U(r) || L(r);
258
+ const i = Q(e);
259
+ let f = M(e, "utf8");
260
+ f = st(f);
261
+ const p = l(s, "js", n + ".js"), o = await Y(t), c = l(t, (o == null ? void 0 : o.configDir) || "", "salty.config.ts"), d = ut(c), u = await lt(t);
262
+ await ot.build({
263
+ stdin: {
264
+ contents: f,
265
+ sourcefile: i.base,
266
+ resolveDir: i.dir,
267
+ loader: "tsx"
268
+ },
269
+ minify: !1,
141
270
  treeShaking: !0,
142
271
  bundle: !0,
143
- outfile: n,
144
- format: "esm",
145
- target: ["es2022"],
272
+ outfile: p,
273
+ format: u,
274
+ target: ["node20"],
146
275
  keepNames: !0,
147
- external: ["react"]
276
+ external: d,
277
+ packages: "external",
278
+ plugins: [
279
+ {
280
+ name: "test",
281
+ setup: (N) => {
282
+ N.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (T) => {
283
+ const m = M(T.path, "utf8");
284
+ return { contents: st(m), loader: "ts" };
285
+ });
286
+ }
287
+ }
288
+ ]
148
289
  });
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) => {
290
+ const x = Date.now();
291
+ return await import(`${p}?t=${x}`);
292
+ }, tt = async (t) => {
293
+ const e = await z(t), s = l(e, "salty.config.js"), n = Date.now(), { config: r } = await import(`${s}?t=${n}`);
294
+ return r;
295
+ }, gt = () => {
296
+ try {
297
+ return process.env.NODE_ENV === "production";
298
+ } catch {
299
+ return !1;
300
+ }
301
+ }, Vt = async (t, e = gt()) => {
155
302
  try {
156
- const s = [], e = [], n = E(t), r = u(n, "index.css");
303
+ const s = Date.now();
304
+ e ? q.info("Generating CSS in production mode! 🔥") : q.info("Generating CSS in development mode! 🚀");
305
+ const n = [], r = [], i = await z(t), f = l(i, "index.css");
157
306
  (() => {
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);
307
+ U(i) && mt("rm -rf " + i), L(i, { recursive: !0 }), L(l(i, "css")), L(l(i, "types"));
308
+ })();
309
+ const o = {
310
+ keyframes: [],
311
+ mediaQueries: [],
312
+ globalStyles: [],
313
+ variables: [],
314
+ components: []
315
+ };
316
+ async function c(a) {
317
+ const y = ["node_modules", "saltygen"], w = ht(a);
318
+ if (w.isDirectory()) {
319
+ const h = $t(a);
320
+ if (y.some((j) => a.includes(j))) return;
321
+ await Promise.all(h.map((j) => c(l(a, j))));
322
+ } else if (w.isFile() && Z(a)) {
323
+ const g = await v(t, a, i);
324
+ Object.entries(g).forEach(([j, $]) => {
325
+ $.isKeyframes ? o.keyframes.push({
326
+ value: $,
327
+ src: a,
328
+ name: j
329
+ }) : $.isMedia ? o.mediaQueries.push($) : $.isGlobalDefine ? o.globalStyles.push($) : $.isDefineVariables ? o.variables.push($) : $.generator && o.components.push({
330
+ value: $.generator,
331
+ src: a,
332
+ name: j
333
+ });
182
334
  });
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
335
  }
187
336
  }
188
- await a(t, n);
189
- const f = s.map((p) => `@import url('./css/${p}');`).join(`
337
+ await c(t), await Tt(t, o);
338
+ const d = await tt(t);
339
+ for (const a of o.keyframes) {
340
+ const { value: y } = a, w = `a_${y.animationName}.css`, h = `css/${w}`, g = l(i, h);
341
+ n.push(w), P(g, y.css);
342
+ }
343
+ const u = {};
344
+ for (const a of o.components) {
345
+ const { value: y, name: w, src: h } = a, g = y._withBuildContext({
346
+ name: w,
347
+ config: d,
348
+ prod: e
349
+ });
350
+ r[g.priority] || (r[g.priority] = []), r[g.priority].push(g.cssFileName), d.importStrategy === "component" && (u[h] ? u[h].push(g.cssFileName) : u[h] = [g.cssFileName]);
351
+ const j = `css/${g.cssFileName}`, $ = l(i, j);
352
+ P($, g.css);
353
+ }
354
+ d.importStrategy === "component" && Object.entries(u).forEach(([a, y]) => {
355
+ const w = y.map((b) => `@import url('./${b}');`).join(`
356
+ `), h = I(a, 6), g = Q(a), j = R(g.name), $ = l(i, `css/f_${j}-${h}.css`);
357
+ P($, w);
358
+ });
359
+ const x = n.map((a) => `@import url('./css/${a}');`).join(`
190
360
  `);
191
- let i = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
361
+ let m = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
192
362
 
193
- ${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
363
+ ${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((a) => {
364
+ try {
365
+ return M(l(i, "css", a), "utf8").length > 0;
366
+ } catch {
367
+ return !1;
368
+ }
369
+ }).map((a) => `@import url('./css/${a}');`).join(`
194
370
  `)}
195
- ${f}`;
196
- if ($.importStrategy !== "component") {
197
- const p = e.flat().map((h) => `@import url('./css/${h}');`).join(`
198
- `);
199
- i += p;
371
+ ${x}`;
372
+ if (d.importStrategy !== "component") {
373
+ const a = r.reduce((y, w, h) => {
374
+ const g = w.reduce((F, V) => {
375
+ var J;
376
+ const E = l(i, "css", V), H = M(E, "utf8"), A = ((J = /.*-([^-]+)-\d+.css/.exec(V)) == null ? void 0 : J.at(1)) || I(E, 6);
377
+ return F.includes(A) ? F : `${F}
378
+ /*start:${A}*/
379
+ ${H}
380
+ /*end:${A}*/
381
+ `;
382
+ }, ""), j = `l_${h}.css`, $ = l(i, "css", j), b = `@layer l${h} { ${g}
383
+ }`;
384
+ return P($, b), `${y}
385
+ @import url('./css/${j}');`;
386
+ }, "");
387
+ m += a;
200
388
  }
201
- C(r, i);
389
+ P(f, m);
390
+ const S = Date.now() - s, C = S < 200 ? "🔥" : S < 500 ? "🚀" : S < 1e3 ? "🎉" : S < 2e3 ? "🚗" : S < 5e3 ? "🤔" : "🥴";
391
+ q.info(`Generated CSS in ${S}ms! ${C}`);
202
392
  } catch (s) {
203
393
  console.error(s);
204
394
  }
205
- }, nt = async (t, s) => {
395
+ }, _t = async (t, e) => {
206
396
  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);
397
+ const s = await z(t);
398
+ if (Z(e)) {
399
+ const r = [], i = await tt(t), f = await v(t, e, s);
400
+ Object.entries(f).forEach(([p, o]) => {
401
+ if (o.isKeyframes && o.css) {
402
+ const D = `css/${`a_${o.animationName}.css`}`, N = l(s, D);
403
+ P(N, o.css);
404
+ return;
405
+ }
406
+ if (!o.generator) return;
407
+ const c = o.generator._withBuildContext({
408
+ name: p,
409
+ config: i
410
+ }), d = `css/${c.cssFileName}`, u = l(s, d);
411
+ P(u, c.css), r[c.priority] || (r[c.priority] = []), r[c.priority].push(c.cssFileName);
412
+ }), i.importStrategy !== "component" && r.forEach((p, o) => {
413
+ const c = `l_${o}.css`, d = l(s, "css", c);
414
+ let u = M(d, "utf8");
415
+ p.forEach((x) => {
416
+ var m;
417
+ const D = l(s, "css", x), N = ((m = /.*-([^-]+)-\d+.css/.exec(x)) == null ? void 0 : m.at(1)) || I(D, 6);
418
+ if (!u.includes(N)) {
419
+ const k = M(D, "utf8"), S = `/*start:${N}*/
420
+ ${k}
421
+ /*end:${N}*/
422
+ `;
423
+ u = `${u.replace(/\}$/, "")}
424
+ ${S}
425
+ }`;
426
+ }
427
+ }), P(d, u);
217
428
  });
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
429
  }
223
- } catch (e) {
224
- console.error(e);
430
+ } catch (s) {
431
+ console.error(s);
225
432
  }
226
- }, rt = async (t, s) => {
433
+ }, Ot = async (t, e, s = gt()) => {
227
434
  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;
435
+ const n = await z(t);
436
+ if (Z(e)) {
437
+ const i = M(e, "utf8");
438
+ i.replace(/^(?!export\s)const\s.*/gm, (d) => `export ${d}`) !== i && await bt(e, i);
439
+ const p = await tt(t), o = await v(t, e, n);
440
+ let c = i;
441
+ if (Object.entries(o).forEach(([d, u]) => {
442
+ var $;
443
+ if (u.isKeyframes || !u.generator) return;
444
+ const x = u.generator._withBuildContext({
445
+ name: d,
446
+ config: p,
447
+ prod: s
448
+ }), D = new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
449
+ if (!D) return console.error("Could not find the original declaration");
450
+ const N = ($ = D.at(1)) == null ? void 0 : $.trim(), T = new RegExp(`\\s${d}[=\\s]+styled\\(`, "g").exec(c);
451
+ if (!T) return console.error("Could not find the original declaration");
452
+ const { index: m } = T;
453
+ let k = !1;
454
+ const S = setTimeout(() => k = !0, 5e3);
455
+ let C = 0, a = !1, y = 0;
456
+ for (; !a && !k; ) {
457
+ const b = c[m + C];
458
+ b === "(" && y++, b === ")" && y--, y === 0 && b === ")" && (a = !0), C > c.length && (k = !0), C++;
239
459
  }
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;
460
+ if (!k) clearTimeout(S);
461
+ else throw new Error("Failed to find the end of the styled call and timed out");
462
+ const w = m + C, h = c.slice(m, w), g = c, j = ` ${d} = styled(${N}, "${x.classNames}", ${JSON.stringify(x.props)});`;
463
+ c = c.replace(h, j), g === c && console.error("Minimize file failed to change content", { name: d, tagName: N });
464
+ }), p.importStrategy === "component") {
465
+ const d = I(e, 6), u = Q(e);
466
+ c = `import '../../saltygen/css/${`f_${R(u.name)}-${d}.css`}';
467
+ ${c}`;
468
+ }
469
+ return c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
253
470
  }
254
- } catch (e) {
255
- console.error(e);
471
+ } catch (n) {
472
+ console.error("Error in minimizeFile:", n);
256
473
  }
257
- }, lt = (t) => ({
474
+ }, nt = async (t) => {
475
+ if (t.includes("salty.config")) return !0;
476
+ if (!Z(t)) return !1;
477
+ const n = await X(t, "utf-8");
478
+ return !!/.+define[A-Z]\w+/.test(n);
479
+ }, Zt = (t) => ({
258
480
  name: "stylegen",
259
- buildStart: () => et(t),
260
- load: async (s) => {
261
- if (k(s))
262
- return await rt(t, s);
481
+ buildStart: () => Vt(t),
482
+ load: async (e) => {
483
+ if (Z(e))
484
+ return await Ot(t, e);
485
+ },
486
+ handleHotUpdate: async ({ file: e, server: s }) => {
487
+ await nt(e) && await s.restart();
263
488
  },
264
489
  watchChange: {
265
- handler: async (s) => {
266
- k(s) && await nt(t, s), s.includes("salty.config") && await W(t);
490
+ handler: async (e) => {
491
+ Z(e) && (await nt(e) || await _t(t, e));
267
492
  }
268
493
  }
269
494
  });
270
495
  export {
271
- lt as saltyPlugin
496
+ Zt as default,
497
+ Zt as saltyPlugin
272
498
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.16",
3
+ "version": "0.0.1-alpha.160",
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.160"
33
38
  }
34
39
  }