@salty-css/vite 0.0.1-alpha.6 → 0.0.1-alpha.60

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