@salty-css/webpack 0.0.1-alpha.21 → 0.0.1-alpha.211

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