@salty-css/vite 0.0.1-alpha.7 → 0.0.1-alpha.70

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 +105 -26
  2. package/index.cjs +14 -14
  3. package/index.d.ts +1 -0
  4. package/index.js +204 -188
  5. package/package.json +11 -2
package/README.md CHANGED
@@ -1,15 +1,90 @@
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
+ Note: Fastest way to get started with any framework is [npx salty-css init [directory]](#initialize-salty-css-for-a-project) command
22
+
23
+ - [Next.js](#nextjs) → `npm install @salty-css/next` + [Next.js install guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
24
+ - [React](#react) → `npm install @salty-css/react` + [React install guide](#react) + [React example code](#code-examples)
25
+ - [Vite](#vite) → `npm install @salty-css/vite` + [(Vite install guide)](#vite)
26
+ - [Webpack](https://www.npmjs.com/package/@salty-css/webpack) → `npm install @salty-css/webpack` + Guide coming soon
27
+ - [ESLint](https://www.npmjs.com/package/@salty-css/eslint-plugin-core) → `npm install @salty-css/eslint-plugin-core` + Guide coming soon
28
+ - [Core](https://www.npmjs.com/package/@salty-css/react) → `npm install @salty-css/core` (This package contains code for internal use)
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
+ #### Next.js
51
+
52
+ 1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
53
+ 2. Create `salty.config.ts` to your app directory
54
+ 3. Add Salty CSS plugin to next.js config
55
+
56
+ - **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);`
57
+ - **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);`
58
+
59
+ 4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
60
+ 5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
61
+ 6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
62
+
63
+ [Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
64
+
65
+ #### React
66
+
67
+ 1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
68
+ 2. Create `salty.config.ts` to your app directory
69
+ 3. Configure your build tool to support Salty CSS ([Vite](#vite) or Webpack)
70
+
71
+ [Check out react example code](#code-examples)
72
+
73
+ #### Vite
74
+
75
+ 1. For Vite support install `npm i @salty-css/vite @salty-css/core`
76
+ 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
77
+ 3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
78
+ 4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
79
+ 5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
80
+
81
+ ### Create components
82
+
83
+ 1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
84
+
85
+ ## Code examples
86
+
87
+ ### Basic usage example with Button
13
88
 
14
89
  **Salty config**
15
90
 
@@ -54,8 +129,10 @@ export const IndexPage = () => {
54
129
  import { styled } from '@salty-css/react/styled';
55
130
 
56
131
  export const Wrapper = styled('div', {
57
- display: 'block',
58
- padding: '2vw',
132
+ base: {
133
+ display: 'block',
134
+ padding: '2vw',
135
+ },
59
136
  });
60
137
  ```
61
138
 
@@ -65,22 +142,24 @@ export const Wrapper = styled('div', {
65
142
  import { styled } from '@salty-css/react/styled';
66
143
 
67
144
  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',
145
+ base: {
146
+ display: 'block',
147
+ padding: `0.6em 1.2em`,
148
+ border: '1px solid currentColor',
149
+ background: 'transparent',
150
+ color: 'currentColor/40',
151
+ cursor: 'pointer',
152
+ transition: '200ms',
153
+ textDecoration: 'none',
154
+ '&:hover': {
155
+ background: 'black',
156
+ borderColor: 'black',
157
+ color: 'white',
158
+ },
159
+ '&:disabled': {
160
+ opacity: 0.25,
161
+ pointerEvents: 'none',
162
+ },
84
163
  },
85
164
  variants: {
86
165
  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 Y=require("esbuild"),Q=require("child_process"),y=require("path"),g=require("fs"),v=require("fs/promises");var V=typeof document<"u"?document.currentScript:null;function tt(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 B=tt(Y),W=t=>String.fromCharCode(t+(t>25?39:97)),et=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=W(n%52)+s;return s=W(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},st=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},R=(t,e=3)=>{const s=st(5381,JSON.stringify(t))>>>0;return et(s,e)};function D(t){return t?typeof t!="string"?D(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 nt=(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:p}=n;t=t.replace(o,d=>{const{value:a,css:c}=p(d);return c&&s.push(c),a})}),{result:t,additionalCss:s}},Z=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${D(n[1].replaceAll(".","-"))})`)}:{result:t},P=(t,e,s,n)=>{if(!t)return"";const o=[],p=Object.entries(t).reduce((a,[c,r])=>{const u=c.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(u==="variants")return Object.entries(r).forEach(([i,f])=>{f&&Object.entries(f).forEach(([$,h])=>{if(!h)return;const F=`${e}.${i}-${$}`,j=P(h,F);o.push(j)})}),a;if(u==="defaultVariants")return a;if(u==="compoundVariants")return r.forEach(i=>{const{css:f,...$}=i,h=Object.entries($).reduce((j,[w,O])=>`${j}.${w}-${O}`,e),F=P(f,h);o.push(F)}),a;if(u.startsWith("@")){const i=P(r,e),f=`${u} {
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),a}const m=c.includes("&")?u.replace("&",e):u.startsWith(":")?`${e}${u}`:`${e} ${u}`,C=P(r,m);return o.push(C),a}const k=u.startsWith("-")?u:D(u),b=(m,C=";")=>a=`${a}${m}${C}`,l=m=>b(`${k}:${m}`);if(typeof r=="number")return l(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:S}={},x=function*(){yield Z(r),yield nt(r,S)}();for(const{result:m,additionalCss:C=[]}of x)r=m,C.forEach(i=>{const f=P(i,"");b(f,"")});return l(r)},"");if(!p)return o.join(`
6
+ `);if(!e)return p;let d="";return d=`${e} { ${p} }`,[d,...o].join(`
7
+ `)},z=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,p])=>{if(typeof p=="object"){if(!p)return;const d=o.trim(),a=z(p,[...e,d]);s.push(a)}else n[o]=p}),Object.keys(n).length){const o=e.map(D).join("-"),p=P(n,`.${o}`);s.push(p)}return s.join(`
8
+ `)},U=()=>(typeof document>"u"?require("url").pathToFileURL(__filename).href:V&&V.tagName.toUpperCase()==="SCRIPT"&&V.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs")?"cjs":"esm",_={externalModules:[]},H=t=>{if(_.externalModules.length>0)return _.externalModules;const e=y.join(t,"salty.config.ts"),n=g.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const o=n[1].split(",").map(p=>p.replace(/['"`]/g,"").trim());return _.externalModules=o,o},E=t=>y.join(t,"./saltygen"),ot=["salty","css","styles","styled"],rt=(t=[])=>new RegExp(`\\.(${[...ot,...t].join("|")})\\.`),N=(t,e=[])=>rt(e).test(t),it=async t=>{const e=E(t),s=y.join(t,"salty.config.ts"),n=y.join(e,"salty.config.js"),o=U(),p=H(t);await B.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o,external:p});const d=Date.now(),{config:a}=await import(`${n}?t=${d}`);return a},L=async t=>{const e=await it(t),s=new Set,n=(i,f=[])=>i?Object.entries(i).flatMap(([$,h])=>{if(!h)return;if(typeof h=="object")return n(h,[...f,$]);const F=[...f,$].join(".");s.add(`"${F}"`);const j=[...f.map(D),D($)].join("-"),{result:w}=Z(h);return`--${j}: ${w};`}):[],o=i=>i?Object.entries(i).flatMap(([f,$])=>{const h=n($);return f==="base"?h.join(""):`${f} { ${h.join("")} }`}):[],p=i=>i?Object.entries(i).flatMap(([f,$])=>Object.entries($).flatMap(([h,F])=>{const j=n(F,[f]),w=`.${f}-${h}, [data-${f}="${h}"]`,O=j.join("");return`${w} { ${O} }`})):[],d=n(e.variables),a=o(e.responsiveVariables),c=p(e.conditionalVariables),r=E(t),u=y.join(r,"css/variables.css"),k=`:root { ${d.join("")} ${a.join("")} } ${c.join("")}`;g.writeFileSync(u,k);const b=y.join(r,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;g.writeFileSync(b,S);const T=y.join(r,"css/global.css"),x=P(e.global,"");g.writeFileSync(T,x);const m=y.join(r,"css/templates.css"),C=z(e.templates);g.writeFileSync(m,C)},A=async(t,e,s)=>{const n=R(e),o=y.join(s,"js",n+".js"),p=U(),d=H(t);await B.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:p,target:["es2022"],keepNames:!0,external:d});const a=Date.now();return await import(`${o}?t=${a}`)},q=async t=>{const e=E(t),s=y.join(e,"salty.config.js"),{config:n}=await import(s);return n},ct=async t=>{try{const e=[],s=[],n=E(t),o=y.join(n,"index.css");(()=>{g.existsSync(n)&&Q.execSync("rm -rf "+n),g.mkdirSync(n),g.mkdirSync(y.join(n,"css")),g.mkdirSync(y.join(n,"types"))})(),await L(t);const d=await q(t);async function a(l,S){const T=["node_modules","saltygen"],x=g.statSync(l);if(x.isDirectory()){const m=g.readdirSync(l);if(T.some(i=>l.includes(i)))return;await Promise.all(m.map(i=>a(y.join(l,i),y.join(S,i))))}else if(x.isFile()&&N(l)){const C=await A(t,l,n),i=[];Object.entries(C).forEach(([F,j])=>{if(j.isKeyframes&&j.css){const I=`${j.animationName}.css`,G=`css/${I}`,X=y.join(n,G);e.push(I),g.writeFileSync(X,j.css);return}if(!j.generator)return;const w=j.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 M=`css/${O}`,K=y.join(n,M);g.writeFileSync(K,w.css)});const f=i.map(F=>`@import url('./${F}');`).join(`
9
+ `),$=R(l,6),h=y.join(n,`css/${$}.css`);g.writeFileSync(h,f)}}await a(t,n);const c=e.map(l=>`@import url('./css/${l}');`).join(`
10
+ `);let b=`@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(l=>{try{return g.readFileSync(y.join(n,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).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 l=s.flat().map(S=>`@import url('./css/${S}');`).join(`
15
+ `);b+=l}g.writeFileSync(o,b)}catch(e){console.error(e)}},at=async(t,e)=>{try{const s=[],n=y.join(t,"./saltygen"),o=y.join(n,"index.css");if(N(e)){const d=await q(t),a=await A(t,e,n);Object.entries(a).forEach(([b,l])=>{if(!l.generator)return;const S=l.generator._withBuildContext({name:b,config:d}),T=`${S.hash}-${S.priority}.css`,x=`css/${T}`,m=y.join(n,x);s.push(T),g.writeFileSync(m,S.css)});const c=g.readFileSync(o,"utf8").split(`
16
+ `),r=s.map(b=>`@import url('../saltygen/css/${b}');`),k=[...new Set([...c,...r])].join(`
17
+ `);g.writeFileSync(o,k)}}catch(s){console.error(s)}},lt=async(t,e)=>{try{const s=y.join(t,"./saltygen");if(N(e)){const o=g.readFileSync(e,"utf8");o.replace(/^(?!export\s)const\s.*/gm,u=>`export ${u}`)!==o&&await v.writeFile(e,o);const d=await q(t),a=await A(t,e,s);let c=o;Object.entries(a).forEach(([u,k])=>{var O;if(k.isKeyframes||!k.generator)return;const b=k.generator._withBuildContext({name:u,config:d}),l=new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!l)return console.error("Could not find the original declaration");const S=(O=l.at(1))==null?void 0:O.trim(),T=new RegExp(`\\s${u}[=\\s]+styled\\(`,"g").exec(c);if(!T)return console.error("Could not find the original declaration");const{index:x}=T;let m=!1;const C=setTimeout(()=>m=!0,5e3);let i=0,f=!1,$=0;for(;!f&&!m;){const M=c[x+i];M==="("&&$++,M===")"&&$--,$===0&&M===")"&&(f=!0),i>c.length&&(m=!0),i++}if(!m)clearTimeout(C);else throw new Error("Failed to find the end of the styled call and timed out");const h=x+i,F=c.slice(x,h),j=c,w=` ${u} = styled(${S}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;c=c.replace(F,w),j===c&&console.error("Minimize file failed to change content",{name:u,tagName:S})});const r=R(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)}},J=t=>({name:"stylegen",buildStart:()=>ct(t),load:async e=>{if(N(e))return await lt(t,e)},watchChange:{handler:async e=>{N(e)&&await at(t,e),e.includes("salty.config")&&await L(t)}}});exports.default=J;exports.saltyPlugin=J;
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,295 @@
1
- import * as I from "esbuild";
2
- import * as P from "winston";
3
- import { execSync as L } from "child_process";
1
+ import * as z from "esbuild";
2
+ import { execSync as Y } from "child_process";
4
3
  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) => {
4
+ import { writeFileSync as T, existsSync as Q, mkdirSync as A, statSync as v, readdirSync as tt, readFileSync as O } from "fs";
5
+ import { writeFile as st } from "fs/promises";
6
+ const Z = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), et = (t, s) => {
8
7
  let e = "", n;
9
8
  for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = Z(n % 52) + e;
10
9
  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) => {
10
+ }, nt = (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
+ }, _ = (t, s = 3) => {
15
+ const e = nt(5381, JSON.stringify(t)) >>> 0;
16
+ return et(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 M(t) {
19
+ return t ? typeof t != "string" ? M(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 ot = (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: p } = n;
27
+ t = t.replace(o, (g) => {
28
+ const { value: a, css: c } = p(g);
29
+ return c && e.push(c), a;
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
+ }, H = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${M(n[1].replaceAll(".", "-"))})`) } : { result: t }, E = (t, s, e, n) => {
33
+ if (!t) return "";
34
+ const o = [], p = Object.entries(t).reduce((a, [c, r]) => {
35
+ const f = c.trim();
36
+ if (typeof r == "function" && (r = r()), typeof r == "object") {
37
+ if (!r) return a;
38
+ if (f === "variants")
39
+ return Object.entries(r).forEach(([i, u]) => {
40
+ u && Object.entries(u).forEach(([h, m]) => {
41
+ if (!m) return;
42
+ const S = `${s}.${i}-${h}`, $ = E(m, S);
43
+ o.push($);
44
44
  });
45
45
  }), a;
46
- if (i === "defaultVariants")
46
+ if (f === "defaultVariants")
47
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);
48
+ if (f === "compoundVariants")
49
+ return r.forEach((i) => {
50
+ const { css: u, ...h } = i, m = Object.entries(h).reduce(($, [w, D]) => `${$}.${w}-${D}`, s), S = E(u, m);
51
+ o.push(S);
52
52
  }), a;
53
- if (i.startsWith("@")) {
54
- const u = O(o, s), c = `${i} {
55
- ${u.replace(`
53
+ if (f.startsWith("@")) {
54
+ const i = E(r, s), u = `${f} {
55
+ ${i.replace(`
56
56
  `, `
57
57
  `)}
58
58
  }`;
59
- return r.push(c), a;
59
+ return o.push(u), a;
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("&") ? f.replace("&", s) : f.startsWith(":") ? `${s}${f}` : `${s} ${f}`, x = E(r, d);
62
+ return o.push(x), a;
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();
64
+ const C = f.startsWith("-") ? f : M(f), b = (d, x = ";") => a = `${a}${d}${x}`, l = (d) => b(`${C}:${d}`);
65
+ if (typeof r == "number") return l(r);
66
+ if (typeof r != "string")
67
+ if ("toString" in r) r = r.toString();
68
68
  else return a;
69
- const { modifiers: j } = {}, C = function* () {
70
- yield H(o), yield v(o, j);
69
+ const { modifiers: j } = {}, F = function* () {
70
+ yield H(r), yield ot(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: x = [] } of F)
73
+ r = d, x.forEach((i) => {
74
+ const u = E(i, "");
75
+ b(u, "");
76
76
  });
77
- return b(o);
77
+ return l(r);
78
78
  }, "");
79
- if (!g) return r.join(`
79
+ if (!p) return o.join(`
80
80
  `);
81
- if (!s) return g;
82
- let $ = "";
83
- return $ = `${s} { ${g} }`, [$, ...r].join(`
81
+ if (!s) return p;
82
+ let g = "";
83
+ return g = `${s} { ${p} }`, [g, ...o].join(`
84
84
  `);
85
85
  }, J = (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, $]);
88
+ if (Object.entries(t).forEach(([o, p]) => {
89
+ if (typeof p == "object") {
90
+ if (!p) return;
91
+ const g = o.trim(), a = J(p, [...s, g]);
91
92
  e.push(a);
92
93
  } else
93
- n[r] = g;
94
+ n[o] = p;
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(M).join("-"), p = E(n, `.${o}`);
97
+ e.push(p);
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
+ }, K = () => import.meta.url.endsWith(".cjs") ? "cjs" : "esm", R = {
102
+ externalModules: []
103
+ }, q = (t) => {
104
+ if (R.externalModules.length > 0) return R.externalModules;
105
+ const s = y(t, "salty.config.ts"), n = O(s, "utf8").match(/externalModules:\s?\[(.*)\]/);
106
+ if (!n) return [];
107
+ const o = n[1].split(",").map((p) => p.replace(/['"`]/g, "").trim());
108
+ return R.externalModules = o, o;
109
+ }, V = (t) => y(t, "./saltygen"), rt = ["salty", "css", "styles", "styled"], it = (t = []) => new RegExp(`\\.(${[...rt, ...t].join("|")})\\.`), P = (t, s = []) => it(s).test(t), ct = async (t) => {
110
+ const s = V(t), e = y(t, "salty.config.ts"), n = y(s, "salty.config.js"), o = K(), p = q(t);
111
+ await z.build({
109
112
  entryPoints: [e],
110
113
  minify: !0,
111
114
  treeShaking: !0,
112
115
  bundle: !0,
113
116
  outfile: n,
114
- format: "esm",
115
- external: ["react"]
117
+ format: o,
118
+ external: p
116
119
  });
117
- const r = Date.now(), { config: g } = await import(`${n}?t=${r}`);
118
- return g;
119
- }, 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({
144
- entryPoints: [t],
120
+ const g = Date.now(), { config: a } = await import(`${n}?t=${g}`);
121
+ return a;
122
+ }, G = async (t) => {
123
+ const s = await ct(t), e = /* @__PURE__ */ new Set(), n = (i, u = []) => i ? Object.entries(i).flatMap(([h, m]) => {
124
+ if (!m) return;
125
+ if (typeof m == "object") return n(m, [...u, h]);
126
+ const S = [...u, h].join(".");
127
+ e.add(`"${S}"`);
128
+ const $ = [...u.map(M), M(h)].join("-"), { result: w } = H(m);
129
+ return `--${$}: ${w};`;
130
+ }) : [], o = (i) => i ? Object.entries(i).flatMap(([u, h]) => {
131
+ const m = n(h);
132
+ return u === "base" ? m.join("") : `${u} { ${m.join("")} }`;
133
+ }) : [], p = (i) => i ? Object.entries(i).flatMap(([u, h]) => Object.entries(h).flatMap(([m, S]) => {
134
+ const $ = n(S, [u]), w = `.${u}-${m}, [data-${u}="${m}"]`, D = $.join("");
135
+ return `${w} { ${D} }`;
136
+ })) : [], g = n(s.variables), a = o(s.responsiveVariables), c = p(s.conditionalVariables), r = V(t), f = y(r, "css/variables.css"), C = `:root { ${g.join("")} ${a.join("")} } ${c.join("")}`;
137
+ T(f, C);
138
+ const b = y(r, "types/css-tokens.d.ts"), j = `type VariableTokens = ${[...e].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
139
+ T(b, j);
140
+ const k = y(r, "css/global.css"), F = E(s.global, "");
141
+ T(k, F);
142
+ const d = y(r, "css/templates.css"), x = J(s.templates);
143
+ T(d, x);
144
+ }, W = async (t, s, e) => {
145
+ const n = _(s), o = y(e, "js", n + ".js"), p = K(), g = q(t);
146
+ await z.build({
147
+ entryPoints: [s],
145
148
  minify: !0,
146
149
  treeShaking: !0,
147
150
  bundle: !0,
148
- outfile: n,
149
- format: "esm",
151
+ outfile: o,
152
+ format: p,
150
153
  target: ["es2022"],
151
154
  keepNames: !0,
152
- external: ["react"]
155
+ external: g
153
156
  });
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);
157
+ const a = Date.now();
158
+ return await import(`${o}?t=${a}`);
159
+ }, B = async (t) => {
160
+ const s = V(t), e = y(s, "salty.config.js"), { config: n } = await import(e);
158
161
  return n;
159
- }, et = async (t) => {
162
+ }, at = async (t) => {
160
163
  try {
161
- const s = [], e = [], n = E(t), r = y(n, "index.css");
164
+ const s = [], e = [], n = V(t), o = y(n, "index.css");
162
165
  (() => {
163
- q(n) && L("rm -rf " + n), T(n), T(y(n, "css")), T(y(n, "types"));
164
- })(), 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);
166
+ Q(n) && Y("rm -rf " + n), A(n), A(y(n, "css")), A(y(n, "types"));
167
+ })(), await G(t);
168
+ const g = await B(t);
169
+ async function a(l, j) {
170
+ const k = ["node_modules", "saltygen"], F = v(l);
171
+ if (F.isDirectory()) {
172
+ const d = tt(l);
173
+ if (k.some((i) => l.includes(i))) return;
174
+ await Promise.all(d.map((i) => a(y(l, i), y(j, i))));
175
+ } else if (F.isFile() && P(l)) {
176
+ const x = await W(t, l, n), i = [];
177
+ Object.entries(x).forEach(([S, $]) => {
178
+ if ($.isKeyframes && $.css) {
179
+ const I = `${$.animationName}.css`, U = `css/${I}`, X = y(n, U);
180
+ s.push(I), T(X, $.css);
177
181
  return;
178
182
  }
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);
183
+ if (!$.generator) return;
184
+ const w = $.generator._withBuildContext({
185
+ name: S,
186
+ config: g
187
+ }), D = `${w.hash}-${w.priority}.css`;
188
+ e[w.priority] || (e[w.priority] = []), e[w.priority].push(D), i.push(D);
189
+ const N = `css/${D}`, L = y(n, N);
190
+ T(L, w.css);
187
191
  });
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);
192
+ const u = i.map((S) => `@import url('./${S}');`).join(`
193
+ `), h = _(l, 6), m = y(n, `css/${h}.css`);
194
+ T(m, u);
191
195
  }
192
196
  }
193
197
  await a(t, n);
194
- const f = s.map((p) => `@import url('./css/${p}');`).join(`
198
+ const c = s.map((l) => `@import url('./css/${l}');`).join(`
195
199
  `);
196
- let i = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
200
+ let b = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
197
201
 
198
- ${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
202
+ ${["variables.css", "global.css", "templates.css"].filter((l) => {
203
+ try {
204
+ return O(y(n, "css", l), "utf8").length > 0;
205
+ } catch {
206
+ return !1;
207
+ }
208
+ }).map((l) => `@import url('./css/${l}');`).join(`
199
209
  `)}
200
- ${f}`;
201
- if ($.importStrategy !== "component") {
202
- const p = e.flat().map((h) => `@import url('./css/${h}');`).join(`
210
+ ${c}`;
211
+ if (g.importStrategy !== "component") {
212
+ const l = e.flat().map((j) => `@import url('./css/${j}');`).join(`
203
213
  `);
204
- i += p;
214
+ b += l;
205
215
  }
206
- x(r, i);
216
+ T(o, b);
207
217
  } catch (s) {
208
218
  console.error(s);
209
219
  }
210
- }, nt = async (t, s) => {
220
+ }, lt = async (t, s) => {
211
221
  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);
222
+ const e = [], n = y(t, "./saltygen"), o = y(n, "index.css");
223
+ if (P(s)) {
224
+ const g = await B(t), a = await W(t, s, n);
225
+ Object.entries(a).forEach(([b, l]) => {
226
+ if (!l.generator) return;
227
+ const j = l.generator._withBuildContext({
228
+ name: b,
229
+ config: g
230
+ }), k = `${j.hash}-${j.priority}.css`, F = `css/${k}`, d = y(n, F);
231
+ e.push(k), T(d, j.css);
222
232
  });
223
- const f = B(r, "utf8").split(`
224
- `), o = e.map((h) => `@import url('../saltygen/css/${h}');`), p = [.../* @__PURE__ */ new Set([...f, ...o])].join(`
233
+ const c = O(o, "utf8").split(`
234
+ `), r = e.map((b) => `@import url('../saltygen/css/${b}');`), C = [.../* @__PURE__ */ new Set([...c, ...r])].join(`
225
235
  `);
226
- x(r, p);
236
+ T(o, C);
227
237
  }
228
238
  } catch (e) {
229
239
  console.error(e);
230
240
  }
231
- }, rt = async (t, s) => {
241
+ }, ft = async (t, s) => {
232
242
  try {
233
243
  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;
244
+ if (P(s)) {
245
+ const o = O(s, "utf8");
246
+ o.replace(/^(?!export\s)const\s.*/gm, (f) => `export ${f}`) !== o && await st(s, o);
247
+ const g = await B(t), a = await W(t, s, e);
248
+ let c = o;
249
+ Object.entries(a).forEach(([f, C]) => {
250
+ var D;
251
+ if (C.isKeyframes || !C.generator) return;
252
+ const b = C.generator._withBuildContext({
253
+ name: f,
254
+ config: g
255
+ }), l = new RegExp(`\\s${f}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
256
+ if (!l) return console.error("Could not find the original declaration");
257
+ const j = (D = l.at(1)) == null ? void 0 : D.trim(), k = new RegExp(`\\s${f}[=\\s]+styled\\(`, "g").exec(c);
258
+ if (!k) return console.error("Could not find the original declaration");
259
+ const { index: F } = k;
260
+ let d = !1;
261
+ const x = setTimeout(() => d = !0, 5e3);
262
+ let i = 0, u = !1, h = 0;
263
+ for (; !u && !d; ) {
264
+ const N = c[F + i];
265
+ N === "(" && h++, N === ")" && h--, h === 0 && N === ")" && (u = !0), i > c.length && (d = !0), i++;
244
266
  }
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);
267
+ if (!d) clearTimeout(x);
268
+ else throw new Error("Failed to find the end of the styled call and timed out");
269
+ const m = F + i, S = c.slice(F, m), $ = c, w = ` ${f} = styled(${j}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;
270
+ c = c.replace(S, w), $ === c && console.error("Minimize file failed to change content", { name: f, tagName: j });
256
271
  });
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;
272
+ const r = _(s, 6);
273
+ return g.importStrategy === "component" && (c = `import '../../saltygen/css/${r}.css';
274
+ ${c}`), c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
260
275
  }
261
276
  } catch (e) {
262
- console.error(e);
277
+ console.error("Error in minimizeFile:", e);
263
278
  }
264
- }, lt = (t) => ({
279
+ }, dt = (t) => ({
265
280
  name: "stylegen",
266
- buildStart: () => et(t),
281
+ buildStart: () => at(t),
267
282
  load: async (s) => {
268
- if (s.includes(".salty."))
269
- return await rt(t, s);
283
+ if (P(s))
284
+ return await ft(t, s);
270
285
  },
271
286
  watchChange: {
272
287
  handler: async (s) => {
273
- s.includes(".salty.") && await nt(t, s), s.includes("salty-config") && await K(t);
288
+ P(s) && await lt(t, s), s.includes("salty.config") && await G(t);
274
289
  }
275
290
  }
276
291
  });
277
292
  export {
278
- lt as saltyPlugin
293
+ dt as default,
294
+ dt as saltyPlugin
279
295
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/vite",
3
- "version": "0.0.1-alpha.7",
3
+ "version": "0.0.1-alpha.70",
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
  },
@@ -19,6 +24,7 @@
19
24
  "!**/*.tsbuildinfo"
20
25
  ],
21
26
  "nx": {
27
+ "sourceRoot": "libs/vite/src",
22
28
  "name": "vite"
23
29
  },
24
30
  "exports": {
@@ -26,5 +32,8 @@
26
32
  "import": "./index.js",
27
33
  "require": "./index.cjs"
28
34
  }
35
+ },
36
+ "dependencies": {
37
+ "@salty-css/core": "^0.0.1-alpha.70"
29
38
  }
30
39
  }