@salty-css/webpack 0.0.1-alpha.12 → 0.0.1-alpha.120

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,91 @@
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
+ ### Initialize
20
+
21
+ 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 → [Next.js guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
24
+ - React → [React guide](#react) + [React example code](#code-examples)
25
+ - Vite → [Vite guide](#vite)
26
+ - Webpack → Guide coming soon
27
+ - ESLint → Guide coming soon
28
+
29
+ ### Salty CSS CLI
30
+
31
+ In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
32
+
33
+ - 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.
34
+ - 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.
35
+ - 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
36
+
37
+ ### Guides
38
+
39
+ #### Next.js
40
+
41
+ In your existing Next.js repository you can run `npx salty-css init` to automatically configure Salty CSS.
42
+
43
+ ##### Manual configuration
44
+
45
+ 1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
46
+ 2. Create `salty.config.ts` to your app directory
47
+ 3. Add Salty CSS plugin to next.js config
48
+
49
+ - **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);`
50
+ - **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);`
51
+
52
+ 4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
53
+ 5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
54
+ 6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
55
+
56
+ [Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
57
+
58
+ #### Vite
59
+
60
+ In your existing Vite repository you can run `npx salty-css init` to automatically configure Salty CSS.
61
+
62
+ ##### Manual configuration
63
+
64
+ 1. For Vite support install `npm i @salty-css/vite @salty-css/core`
65
+ 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
66
+ 3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
67
+ 4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
68
+ 5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
69
+
70
+ #### React
71
+
72
+ In your existing React repository you can run `npx salty-css init` to automatically configure Salty CSS.
73
+
74
+ ##### Manual configuration
75
+
76
+ 1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
77
+ 2. Create `salty.config.ts` to your app directory
78
+ 3. Configure your build tool to support Salty CSS ([Vite](#vite) or Webpack) or after changes run `npx salty-css build`
79
+
80
+ [Check out react example code](#code-examples)
81
+
82
+ ### Create components
83
+
84
+ 1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
85
+
86
+ ## Code examples
87
+
88
+ ### Basic usage example with Button
13
89
 
14
90
  **Salty config**
15
91
 
@@ -31,23 +107,6 @@ export const config = defineConfig({
31
107
  });
32
108
  ```
33
109
 
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
110
  **Wrapper** (`components/wrapper/wrapper.css.ts`)
52
111
 
53
112
  ```tsx
@@ -72,7 +131,7 @@ export const Button = styled('button', {
72
131
  padding: `0.6em 1.2em`,
73
132
  border: '1px solid currentColor',
74
133
  background: 'transparent',
75
- color: 'currentColor/40',
134
+ color: 'currentColor',
76
135
  cursor: 'pointer',
77
136
  transition: '200ms',
78
137
  textDecoration: 'none',
@@ -108,4 +167,21 @@ export const Button = styled('button', {
108
167
  });
109
168
  ```
110
169
 
170
+ **Your React component file**
171
+
172
+ ```tsx
173
+ import { Wrapper } from '../components/wrapper/wrapper.css';
174
+ import { Button } from '../components/button/button.css';
175
+
176
+ export const IndexPage = () => {
177
+ return (
178
+ <Wrapper>
179
+ <Button variant="solid" onClick={() => alert('It is a button.')}>
180
+ Outlined
181
+ </Button>
182
+ </Wrapper>
183
+ );
184
+ };
185
+ ```
186
+
111
187
  More examples coming soon
@@ -0,0 +1,28 @@
1
+ "use strict";const rt=require("esbuild"),it=require("child_process"),a=require("path"),f=require("fs"),U=require("fs/promises"),_=require("winston");var Z=typeof document<"u"?document.currentScript:null;function ct(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 G=ct(rt),L=t=>String.fromCharCode(t+(t>25?39:97)),at=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=L(n%52)+s;return s=L(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},lt=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=lt(5381,JSON.stringify(t))>>>0;return at(s,e)};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,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const ft=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:r,transform:i}=n;t=t.replace(r,y=>{const{value:c,css:j}=i(y);return j&&s.push(j),c})}),{result:t,additionalCss:s}},X=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${V(n[1].replaceAll(".","-"))})`)}:{result:t},E=(t,e,s,n)=>{if(!t)return"";const r=[],i=Object.entries(t).reduce((c,[j,o])=>{const d=j.trim();if(typeof o=="function"&&(o=o()),typeof o=="object"){if(!o)return c;if(d==="variants")return Object.entries(o).forEach(([w,u])=>{u&&Object.entries(u).forEach(([P,C])=>{if(!C)return;const O=`${e}.${w}-${P}`,g=E(C,O);r.push(g)})}),c;if(d==="defaultVariants")return c;if(d==="compoundVariants")return o.forEach(w=>{const{css:u,...P}=w,C=Object.entries(P).reduce((g,[p,m])=>`${g}.${p}-${m}`,e),O=E(u,C);r.push(O)}),c;if(d.startsWith("@")){const w=E(o,e),u=`${d} {
2
+ ${w.replace(`
3
+ `,`
4
+ `)}
5
+ }`;return r.push(u),c}const h=j.includes("&")?d.replace("&",e):d.startsWith(":")?`${e}${d}`:`${e} ${d}`,$=E(o,h);return r.push($),c}const S=d.startsWith("-")?d:V(d),F=(h,$=";")=>c=`${c}${h}${$}`,x=h=>F(`${S}:${h}`);if(typeof o=="number")return x(o);if(typeof o!="string")if("toString"in o)o=o.toString();else return c;const{modifiers:l}={},T=function*(){yield X(o),yield ft(o,l)}();for(const{result:h,additionalCss:$=[]}of T)o=h,$.forEach(w=>{const u=E(w,"");F(u,"")});return x(o)},"");if(!i)return r.join(`
6
+ `);if(!e)return i;let y="";return y=`${e} { ${i} }`,[y,...r].join(`
7
+ `)},Y=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([r,i])=>{if(typeof i=="object"){if(!i)return;const y=r.trim(),c=Y(i,[...e,y]);s.push(c)}else n[r]=i}),Object.keys(n).length){const r=e.map(V).join("-"),i=E(n,`.${r}`);s.push(i)}return s.join(`
8
+ `)},ut=t=>Object.entries(t).reduce((e,[s,n])=>(typeof n=="object"&&(e[s]=Q(n).map(r=>`"${r}"`).join(" | ")),e),{}),Q=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,r])=>{const i=e?`${e}.${n}`:n;return typeof r=="object"?Q(r,i,s):s.add(e)}),[...s]):[],v=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=a.join(t,"package.json");return f.existsSync(e)?e:v(a.join(t,".."))},pt=async t=>{const e=v(t);return await U.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},dt=async t=>{const e=await pt(t);if(e)return e.type};let N;const tt=async t=>{if(N)return N;const e=await dt(t);return e==="module"?N="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:Z&&Z.tagName.toUpperCase()==="SCRIPT"&&Z.src||new URL("index-C85_DMmG.cjs",document.baseURI).href).endsWith(".cjs"))&&(N="cjs"),N||"esm"},K=_.createLogger({level:"debug",format:_.format.combine(_.format.colorize(),_.format.cli()),transports:[new _.transports.Console({})]});function et(t){return t?typeof t!="string"?et(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 gt={"*, *::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"},button:{lineHeight:"1em"},"input, optgroup, select, textarea":{fontFamily:"inherit",fontSize:"100%",lineHeight:"1.15em"}},z={externalModules:[]},st=t=>{if(z.externalModules.length>0)return z.externalModules;const e=a.join(t,"salty.config.ts"),n=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const r=n[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return z.externalModules=r,r},J=t=>a.join(t,"./saltygen"),yt=["salty","css","styles","styled"],nt=(t=[])=>new RegExp(`\\.(${[...yt,...t].join("|")})\\.`),I=(t,e=[])=>nt(e).test(t),ht=async t=>{const e=J(t),s=a.join(t,"salty.config.ts"),n=a.join(e,"salty.config.js"),r=await tt(t),i=st(t);await G.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:r,external:i});const y=Date.now(),{config:c}=await import(`${n}?t=${y}`);return c},mt=async t=>{const e=await ht(t),s=new Set,n=(g,p=[])=>g?Object.entries(g).flatMap(([m,b])=>{if(!b)return;if(typeof b=="object")return n(b,[...p,m]);const D=et(m),A=V(m),M=[...p,D].join(".");s.add(`"${M}"`);const R=[...p.map(V),A].join("-"),{result:W}=X(b);return`--${R}: ${W};`}):[],r=g=>g?Object.entries(g).flatMap(([p,m])=>{const b=n(m);return p==="base"?b.join(""):`${p} { ${b.join("")} }`}):[],i=g=>g?Object.entries(g).flatMap(([p,m])=>Object.entries(m).flatMap(([b,D])=>{const A=n(D,[p]),M=`.${p}-${b}, [data-${p}="${b}"]`,R=A.join("");return`${M} { ${R} }`})):[],y=n(e.variables),c=r(e.responsiveVariables),j=i(e.conditionalVariables),o=J(t),d=a.join(o,"css/variables.css"),S=`:root { ${y.join("")} ${c.join("")} } ${j.join("")}`;f.writeFileSync(d,S);const F=a.join(o,"css/global.css"),x=E(e.global,"");f.writeFileSync(F,`@layer global { ${x} }`);const l=a.join(o,"css/reset.css"),T=e.reset==="none"?{}:typeof e.reset=="object"?e.reset:gt,h=E(T,"");f.writeFileSync(l,`@layer reset { ${h} }`);const $=a.join(o,"css/templates.css"),w=Y(e.templates),u=ut(e.templates);f.writeFileSync($,w);const P=a.join(o,"types/css-tokens.d.ts"),O=`
9
+ // Variable types
10
+ type VariableTokens = ${[...s].join("|")};
11
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
12
+
13
+ // Template types
14
+ type TemplateTokens = {
15
+ ${Object.entries(u).map(([g,p])=>`${g}?: ${p}`).join(`
16
+ `)}
17
+ }
18
+ `;f.writeFileSync(P,O)},H=async(t,e,s)=>{const n=q(e),r=a.join(s,"./temp");f.existsSync(r)||f.mkdirSync(r);const i=a.parse(e);let y=f.readFileSync(e,"utf8");y=y.replace(/styled\([^"'`{,]+,/g,"styled('div',");const c=a.join(s,"js",n+".js"),j=st(t),o=await tt(t);await G.build({stdin:{contents:y,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:c,format:o,target:["node20"],keepNames:!0,external:j,packages:"external"});const d=Date.now();return await import(`${c}?t=${d}`)},B=async t=>{const e=J(t),s=a.join(e,"salty.config.js"),{config:n}=await import(s);return n},ot=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},bt=async(t,e=ot())=>{try{e?K.info("Generating CSS in production mode! 🔥"):K.info("Generating CSS in development mode! 🚀");const s=[],n=[],r=J(t),i=a.join(r,"index.css");(()=>{f.existsSync(r)&&it.execSync("rm -rf "+r),f.mkdirSync(r),f.mkdirSync(a.join(r,"css")),f.mkdirSync(a.join(r,"types"))})(),await mt(t);const c=await B(t);async function j(l,k){const T=["node_modules","saltygen"],h=f.statSync(l);if(h.isDirectory()){const $=f.readdirSync(l);if(T.some(u=>l.includes(u)))return;await Promise.all($.map(u=>j(a.join(l,u),a.join(k,u))))}else if(h.isFile()&&I(l)){const w=await H(t,l,r),u=[];Object.entries(w).forEach(([g,p])=>{if(p.isKeyframes&&p.css){const M=`${p.animationName}.css`,R=`css/${M}`,W=a.join(r,R);s.push(M),f.writeFileSync(W,p.css);return}if(!p.generator)return;const m=p.generator._withBuildContext({name:g,config:c,prod:e}),b=`${m.hash}-${m.priority}.css`;n[m.priority]||(n[m.priority]=[]),n[m.priority].push(b),u.push(b);const D=`css/${b}`,A=a.join(r,D);f.writeFileSync(A,m.css)});const P=u.map(g=>`@import url('./${g}');`).join(`
19
+ `),C=q(l,6),O=a.join(r,`css/${C}.css`);f.writeFileSync(O,P)}}await j(t,r);const o=s.map(l=>`@import url('./css/${l}');`).join(`
20
+ `);let x=`@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
21
+
22
+ ${["variables.css","reset.css","global.css","templates.css"].filter(l=>{try{return f.readFileSync(a.join(r,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
23
+ `)}
24
+ ${o}`;if(c.importStrategy!=="component"){const l=n.flat().map(k=>`@import url('./css/${k}');`).join(`
25
+ `);x+=l}f.writeFileSync(i,x)}catch(s){console.error(s)}},jt=async(t,e)=>{try{const s=[],n=a.join(t,"./saltygen"),r=a.join(n,"index.css");if(I(e)){const y=await B(t),c=await H(t,e,n);Object.entries(c).forEach(([F,x])=>{if(!x.generator)return;const l=x.generator._withBuildContext({name:F,config:y}),k=`${l.hash}-${l.priority}.css`,T=`css/${k}`,h=a.join(n,T);s.push(k),f.writeFileSync(h,l.css)});const j=f.readFileSync(r,"utf8").split(`
26
+ `),o=s.map(F=>`@import url('../saltygen/css/${F}');`),S=[...new Set([...j,...o])].join(`
27
+ `);f.writeFileSync(r,S)}}catch(s){console.error(s)}},St=async(t,e,s=ot())=>{try{const n=a.join(t,"./saltygen");if(I(e)){const i=f.readFileSync(e,"utf8");i.replace(/^(?!export\s)const\s.*/gm,S=>`export ${S}`)!==i&&await U.writeFile(e,i);const c=await B(t),j=await H(t,e,n);let o=i;Object.entries(j).forEach(([S,F])=>{var b;if(F.isKeyframes||!F.generator)return;const x=F.generator._withBuildContext({name:S,config:c,prod:s}),l=new RegExp(`\\s${S}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!l)return console.error("Could not find the original declaration");const k=(b=l.at(1))==null?void 0:b.trim(),T=new RegExp(`\\s${S}[=\\s]+styled\\(`,"g").exec(o);if(!T)return console.error("Could not find the original declaration");const{index:h}=T;let $=!1;const w=setTimeout(()=>$=!0,5e3);let u=0,P=!1,C=0;for(;!P&&!$;){const D=o[h+u];D==="("&&C++,D===")"&&C--,C===0&&D===")"&&(P=!0),u>o.length&&($=!0),u++}if(!$)clearTimeout(w);else throw new Error("Failed to find the end of the styled call and timed out");const O=h+u,g=o.slice(h,O),p=o,m=` ${S} = styled(${k}, "${x.classNames}", ${JSON.stringify(x.props)});`;o=o.replace(g,m),p===o&&console.error("Minimize file failed to change content",{name:S,tagName:k})});const d=q(e,6);return c.importStrategy==="component"&&(o=`import '../../saltygen/css/${d}.css';
28
+ ${o}`),o=o.replace("{ styled }","{ styledClient as styled }"),o=o.replace("@salty-css/react/styled","@salty-css/react/styled-client"),o}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=bt;exports.generateFile=jt;exports.minimizeFile=St;exports.saltyFileRegExp=nt;
@@ -0,0 +1,388 @@
1
+ import * as X from "esbuild";
2
+ import { execSync as rt } from "child_process";
3
+ import { join as a, parse as it } from "path";
4
+ import { existsSync as B, writeFileSync as F, readFileSync as W, mkdirSync as R, statSync as ct, readdirSync as at } from "fs";
5
+ import { readFile as lt, writeFile as ft } from "fs/promises";
6
+ import { createLogger as pt, format as _, transports as ut } from "winston";
7
+ const q = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), gt = (t, e) => {
8
+ let s = "", n;
9
+ for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = q(n % 52) + s;
10
+ return s = q(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
11
+ }, dt = (t, e) => {
12
+ let s = e.length;
13
+ for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
14
+ return t;
15
+ }, I = (t, e = 5) => {
16
+ const s = dt(5381, JSON.stringify(t)) >>> 0;
17
+ return gt(s, e);
18
+ };
19
+ function N(t) {
20
+ return t ? typeof t != "string" ? N(String(t)) : t.replace(/[\s.]/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "-" : "") + e.toLowerCase()) : "";
21
+ }
22
+ const yt = (t, e) => {
23
+ if (typeof t != "string") return { result: t };
24
+ if (!e) return { result: t };
25
+ const s = [];
26
+ return Object.values(e).forEach((n) => {
27
+ const { pattern: r, transform: i } = n;
28
+ t = t.replace(r, (d) => {
29
+ const { value: c, css: b } = i(d);
30
+ return b && s.push(b), c;
31
+ });
32
+ }), { result: t, additionalCss: s };
33
+ }, Y = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${N(n[1].replaceAll(".", "-"))})`) } : { result: t }, O = (t, e, s, n) => {
34
+ if (!t) return "";
35
+ const r = [], i = Object.entries(t).reduce((c, [b, o]) => {
36
+ const u = b.trim();
37
+ if (typeof o == "function" && (o = o()), typeof o == "object") {
38
+ if (!o) return c;
39
+ if (u === "variants")
40
+ return Object.entries(o).forEach(([j, f]) => {
41
+ f && Object.entries(f).forEach(([P, C]) => {
42
+ if (!C) return;
43
+ const E = `${e}.${j}-${P}`, g = O(C, E);
44
+ r.push(g);
45
+ });
46
+ }), c;
47
+ if (u === "defaultVariants")
48
+ return c;
49
+ if (u === "compoundVariants")
50
+ return o.forEach((j) => {
51
+ const { css: f, ...P } = j, C = Object.entries(P).reduce((g, [p, h]) => `${g}.${p}-${h}`, e), E = O(f, C);
52
+ r.push(E);
53
+ }), c;
54
+ if (u.startsWith("@")) {
55
+ const j = O(o, e), f = `${u} {
56
+ ${j.replace(`
57
+ `, `
58
+ `)}
59
+ }`;
60
+ return r.push(f), c;
61
+ }
62
+ const y = b.includes("&") ? u.replace("&", e) : u.startsWith(":") ? `${e}${u}` : `${e} ${u}`, S = O(o, y);
63
+ return r.push(S), c;
64
+ }
65
+ const $ = u.startsWith("-") ? u : N(u), w = (y, S = ";") => c = `${c}${y}${S}`, x = (y) => w(`${$}:${y}`);
66
+ if (typeof o == "number") return x(o);
67
+ if (typeof o != "string")
68
+ if ("toString" in o) o = o.toString();
69
+ else return c;
70
+ const { modifiers: l } = {}, T = function* () {
71
+ yield Y(o), yield yt(o, l);
72
+ }();
73
+ for (const { result: y, additionalCss: S = [] } of T)
74
+ o = y, S.forEach((j) => {
75
+ const f = O(j, "");
76
+ w(f, "");
77
+ });
78
+ return x(o);
79
+ }, "");
80
+ if (!i) return r.join(`
81
+ `);
82
+ if (!e) return i;
83
+ let d = "";
84
+ return d = `${e} { ${i} }`, [d, ...r].join(`
85
+ `);
86
+ }, Q = (t, e = []) => {
87
+ if (!t) return "";
88
+ const s = [], n = {};
89
+ if (Object.entries(t).forEach(([r, i]) => {
90
+ if (typeof i == "object") {
91
+ if (!i) return;
92
+ const d = r.trim(), c = Q(i, [...e, d]);
93
+ s.push(c);
94
+ } else
95
+ n[r] = i;
96
+ }), Object.keys(n).length) {
97
+ const r = e.map(N).join("-"), i = O(n, `.${r}`);
98
+ s.push(i);
99
+ }
100
+ return s.join(`
101
+ `);
102
+ }, ht = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = v(n).map((r) => `"${r}"`).join(" | ")), e), {}), v = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, r]) => {
103
+ const i = e ? `${e}.${n}` : n;
104
+ return typeof r == "object" ? v(r, i, s) : s.add(e);
105
+ }), [...s]) : [], tt = (t) => {
106
+ if (!t || t === "/") throw new Error("Could not find package.json file");
107
+ const e = a(t, "package.json");
108
+ return B(e) ? e : tt(a(t, ".."));
109
+ }, mt = async (t) => {
110
+ const e = tt(t);
111
+ return await lt(e, "utf-8").then(JSON.parse).catch(() => {
112
+ });
113
+ }, bt = async (t) => {
114
+ const e = await mt(t);
115
+ if (e)
116
+ return e.type;
117
+ };
118
+ let M;
119
+ const et = async (t) => {
120
+ if (M) return M;
121
+ const e = await bt(t);
122
+ return e === "module" ? M = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (M = "cjs"), M || "esm";
123
+ }, U = pt({
124
+ level: "debug",
125
+ format: _.combine(_.colorize(), _.cli()),
126
+ transports: [new ut.Console({})]
127
+ });
128
+ function st(t) {
129
+ return t ? typeof t != "string" ? st(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
130
+ }
131
+ const $t = {
132
+ /** Set box model to border-box */
133
+ "*, *::before, *::after": {
134
+ boxSizing: "border-box"
135
+ },
136
+ /** Remove default margin and padding */
137
+ "*": {
138
+ margin: 0
139
+ },
140
+ /** Remove adjust font properties */
141
+ html: {
142
+ lineHeight: 1.15,
143
+ textSizeAdjust: "100%",
144
+ WebkitFontSmoothing: "antialiased"
145
+ },
146
+ /** Make media elements responsive */
147
+ "img, picture, video, canvas, svg": {
148
+ display: "block",
149
+ maxWidth: "100%"
150
+ },
151
+ /** Avoid overflow of text */
152
+ "p, h1, h2, h3, h4, h5, h6": {
153
+ overflowWrap: "break-word"
154
+ },
155
+ /** Improve text wrapping */
156
+ p: {
157
+ textWrap: "pretty"
158
+ },
159
+ "h1, h2, h3, h4, h5, h6": {
160
+ textWrap: "balance"
161
+ },
162
+ /** Improve button line height */
163
+ button: {
164
+ lineHeight: "1em"
165
+ },
166
+ /** Improve form elements */
167
+ "input, optgroup, select, textarea": {
168
+ fontFamily: "inherit",
169
+ fontSize: "100%",
170
+ lineHeight: "1.15em"
171
+ }
172
+ }, H = {
173
+ externalModules: []
174
+ }, nt = (t) => {
175
+ if (H.externalModules.length > 0) return H.externalModules;
176
+ const e = a(t, "salty.config.ts"), n = W(e, "utf8").match(/externalModules:\s?\[(.*)\]/);
177
+ if (!n) return [];
178
+ const r = n[1].split(",").map((i) => i.replace(/['"`]/g, "").trim());
179
+ return H.externalModules = r, r;
180
+ }, Z = (t) => a(t, "./saltygen"), St = ["salty", "css", "styles", "styled"], jt = (t = []) => new RegExp(`\\.(${[...St, ...t].join("|")})\\.`), K = (t, e = []) => jt(e).test(t), wt = async (t) => {
181
+ const e = Z(t), s = a(t, "salty.config.ts"), n = a(e, "salty.config.js"), r = await et(t), i = nt(t);
182
+ await X.build({
183
+ entryPoints: [s],
184
+ minify: !0,
185
+ treeShaking: !0,
186
+ bundle: !0,
187
+ outfile: n,
188
+ format: r,
189
+ external: i
190
+ });
191
+ const d = Date.now(), { config: c } = await import(`${n}?t=${d}`);
192
+ return c;
193
+ }, xt = async (t) => {
194
+ const e = await wt(t), s = /* @__PURE__ */ new Set(), n = (g, p = []) => g ? Object.entries(g).flatMap(([h, m]) => {
195
+ if (!m) return;
196
+ if (typeof m == "object") return n(m, [...p, h]);
197
+ const D = st(h), A = N(h), V = [...p, D].join(".");
198
+ s.add(`"${V}"`);
199
+ const J = [...p.map(N), A].join("-"), { result: z } = Y(m);
200
+ return `--${J}: ${z};`;
201
+ }) : [], r = (g) => g ? Object.entries(g).flatMap(([p, h]) => {
202
+ const m = n(h);
203
+ return p === "base" ? m.join("") : `${p} { ${m.join("")} }`;
204
+ }) : [], i = (g) => g ? Object.entries(g).flatMap(([p, h]) => Object.entries(h).flatMap(([m, D]) => {
205
+ const A = n(D, [p]), V = `.${p}-${m}, [data-${p}="${m}"]`, J = A.join("");
206
+ return `${V} { ${J} }`;
207
+ })) : [], d = n(e.variables), c = r(e.responsiveVariables), b = i(e.conditionalVariables), o = Z(t), u = a(o, "css/variables.css"), $ = `:root { ${d.join("")} ${c.join("")} } ${b.join("")}`;
208
+ F(u, $);
209
+ const w = a(o, "css/global.css"), x = O(e.global, "");
210
+ F(w, `@layer global { ${x} }`);
211
+ const l = a(o, "css/reset.css"), T = e.reset === "none" ? {} : typeof e.reset == "object" ? e.reset : $t, y = O(T, "");
212
+ F(l, `@layer reset { ${y} }`);
213
+ const S = a(o, "css/templates.css"), j = Q(e.templates), f = ht(e.templates);
214
+ F(S, j);
215
+ const P = a(o, "types/css-tokens.d.ts"), E = `
216
+ // Variable types
217
+ type VariableTokens = ${[...s].join("|")};
218
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
219
+
220
+ // Template types
221
+ type TemplateTokens = {
222
+ ${Object.entries(f).map(([g, p]) => `${g}?: ${p}`).join(`
223
+ `)}
224
+ }
225
+ `;
226
+ F(P, E);
227
+ }, G = async (t, e, s) => {
228
+ const n = I(e), r = a(s, "./temp");
229
+ B(r) || R(r);
230
+ const i = it(e);
231
+ let d = W(e, "utf8");
232
+ d = d.replace(/styled\([^"'`{,]+,/g, "styled('div',");
233
+ const c = a(s, "js", n + ".js"), b = nt(t), o = await et(t);
234
+ await X.build({
235
+ stdin: {
236
+ contents: d,
237
+ sourcefile: i.base,
238
+ resolveDir: i.dir,
239
+ loader: "tsx"
240
+ },
241
+ minify: !1,
242
+ treeShaking: !0,
243
+ bundle: !0,
244
+ outfile: c,
245
+ format: o,
246
+ target: ["node20"],
247
+ keepNames: !0,
248
+ external: b,
249
+ packages: "external"
250
+ });
251
+ const u = Date.now();
252
+ return await import(`${c}?t=${u}`);
253
+ }, L = async (t) => {
254
+ const e = Z(t), s = a(e, "salty.config.js"), { config: n } = await import(s);
255
+ return n;
256
+ }, ot = () => {
257
+ try {
258
+ return process.env.NODE_ENV === "production";
259
+ } catch {
260
+ return !1;
261
+ }
262
+ }, Et = async (t, e = ot()) => {
263
+ try {
264
+ e ? U.info("Generating CSS in production mode! 🔥") : U.info("Generating CSS in development mode! 🚀");
265
+ const s = [], n = [], r = Z(t), i = a(r, "index.css");
266
+ (() => {
267
+ B(r) && rt("rm -rf " + r), R(r), R(a(r, "css")), R(a(r, "types"));
268
+ })(), await xt(t);
269
+ const c = await L(t);
270
+ async function b(l, k) {
271
+ const T = ["node_modules", "saltygen"], y = ct(l);
272
+ if (y.isDirectory()) {
273
+ const S = at(l);
274
+ if (T.some((f) => l.includes(f))) return;
275
+ await Promise.all(S.map((f) => b(a(l, f), a(k, f))));
276
+ } else if (y.isFile() && K(l)) {
277
+ const j = await G(t, l, r), f = [];
278
+ Object.entries(j).forEach(([g, p]) => {
279
+ if (p.isKeyframes && p.css) {
280
+ const V = `${p.animationName}.css`, J = `css/${V}`, z = a(r, J);
281
+ s.push(V), F(z, p.css);
282
+ return;
283
+ }
284
+ if (!p.generator) return;
285
+ const h = p.generator._withBuildContext({
286
+ name: g,
287
+ config: c,
288
+ prod: e
289
+ }), m = `${h.hash}-${h.priority}.css`;
290
+ n[h.priority] || (n[h.priority] = []), n[h.priority].push(m), f.push(m);
291
+ const D = `css/${m}`, A = a(r, D);
292
+ F(A, h.css);
293
+ });
294
+ const P = f.map((g) => `@import url('./${g}');`).join(`
295
+ `), C = I(l, 6), E = a(r, `css/${C}.css`);
296
+ F(E, P);
297
+ }
298
+ }
299
+ await b(t, r);
300
+ const o = s.map((l) => `@import url('./css/${l}');`).join(`
301
+ `);
302
+ let x = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
303
+
304
+ ${["variables.css", "reset.css", "global.css", "templates.css"].filter((l) => {
305
+ try {
306
+ return W(a(r, "css", l), "utf8").length > 0;
307
+ } catch {
308
+ return !1;
309
+ }
310
+ }).map((l) => `@import url('./css/${l}');`).join(`
311
+ `)}
312
+ ${o}`;
313
+ if (c.importStrategy !== "component") {
314
+ const l = n.flat().map((k) => `@import url('./css/${k}');`).join(`
315
+ `);
316
+ x += l;
317
+ }
318
+ F(i, x);
319
+ } catch (s) {
320
+ console.error(s);
321
+ }
322
+ }, Dt = async (t, e) => {
323
+ try {
324
+ const s = [], n = a(t, "./saltygen"), r = a(n, "index.css");
325
+ if (K(e)) {
326
+ const d = await L(t), c = await G(t, e, n);
327
+ Object.entries(c).forEach(([w, x]) => {
328
+ if (!x.generator) return;
329
+ const l = x.generator._withBuildContext({
330
+ name: w,
331
+ config: d
332
+ }), k = `${l.hash}-${l.priority}.css`, T = `css/${k}`, y = a(n, T);
333
+ s.push(k), F(y, l.css);
334
+ });
335
+ const b = W(r, "utf8").split(`
336
+ `), o = s.map((w) => `@import url('../saltygen/css/${w}');`), $ = [.../* @__PURE__ */ new Set([...b, ...o])].join(`
337
+ `);
338
+ F(r, $);
339
+ }
340
+ } catch (s) {
341
+ console.error(s);
342
+ }
343
+ }, Ot = async (t, e, s = ot()) => {
344
+ try {
345
+ const n = a(t, "./saltygen");
346
+ if (K(e)) {
347
+ const i = W(e, "utf8");
348
+ i.replace(/^(?!export\s)const\s.*/gm, ($) => `export ${$}`) !== i && await ft(e, i);
349
+ const c = await L(t), b = await G(t, e, n);
350
+ let o = i;
351
+ Object.entries(b).forEach(([$, w]) => {
352
+ var m;
353
+ if (w.isKeyframes || !w.generator) return;
354
+ const x = w.generator._withBuildContext({
355
+ name: $,
356
+ config: c,
357
+ prod: s
358
+ }), l = new RegExp(`\\s${$}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
359
+ if (!l) return console.error("Could not find the original declaration");
360
+ const k = (m = l.at(1)) == null ? void 0 : m.trim(), T = new RegExp(`\\s${$}[=\\s]+styled\\(`, "g").exec(o);
361
+ if (!T) return console.error("Could not find the original declaration");
362
+ const { index: y } = T;
363
+ let S = !1;
364
+ const j = setTimeout(() => S = !0, 5e3);
365
+ let f = 0, P = !1, C = 0;
366
+ for (; !P && !S; ) {
367
+ const D = o[y + f];
368
+ D === "(" && C++, D === ")" && C--, C === 0 && D === ")" && (P = !0), f > o.length && (S = !0), f++;
369
+ }
370
+ if (!S) clearTimeout(j);
371
+ else throw new Error("Failed to find the end of the styled call and timed out");
372
+ const E = y + f, g = o.slice(y, E), p = o, h = ` ${$} = styled(${k}, "${x.classNames}", ${JSON.stringify(x.props)});`;
373
+ o = o.replace(g, h), p === o && console.error("Minimize file failed to change content", { name: $, tagName: k });
374
+ });
375
+ const u = I(e, 6);
376
+ return c.importStrategy === "component" && (o = `import '../../saltygen/css/${u}.css';
377
+ ${o}`), o = o.replace("{ styled }", "{ styledClient as styled }"), o = o.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), o;
378
+ }
379
+ } catch (n) {
380
+ console.error("Error in minimizeFile:", n);
381
+ }
382
+ };
383
+ export {
384
+ Dt as a,
385
+ Et as g,
386
+ Ot as m,
387
+ jt as s
388
+ };
package/index.cjs CHANGED
@@ -1,15 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("path"),z=require("esbuild"),H=require("winston"),L=require("child_process"),m=require("fs");require("fs/promises");function A(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 _=A(z),T=A(H),x=t=>String.fromCharCode(t+(t>25?39:97)),B=(t,s)=>{let e="",n;for(n=Math.abs(t);n>52;n=n/52|0)e=x(n%52)+e;return e=x(n%52)+e,e.length<s?e=e.padStart(s,"a"):e.length>s&&(e=e.slice(-s)),e},G=(t,s)=>{let e=s.length;for(;e;)t=t*33^s.charCodeAt(--e);return t},M=(t,s=3)=>{const e=G(5381,JSON.stringify(t))>>>0;return B(e,s)};function N(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 J=(t,s)=>{if(typeof t!="string")return{result:t};if(!s)return{result:t};const e=[];return Object.values(s).forEach(n=>{const{pattern:o,transform:a}=n;t=t.replace(o,b=>{const{value:l,css:$}=a(b);return $&&e.push($),l})}),{result:t,additionalCss:e}},q=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${N(n[1].replaceAll(".","-"))})`)}:{result:t},k=(t,s,e,n)=>{const o=[],a=Object.entries(t).reduce((l,[$,r])=>{const y=$.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return l;if(y==="variants")return Object.entries(r).forEach(([f,i])=>{i&&Object.entries(i).forEach(([p,c])=>{if(!c)return;const h=`${s}.${f}-${p}`,S=k(c,h);o.push(S)})}),l;if(y==="defaultVariants")return l;if(y==="compoundVariants")return r.forEach(f=>{const{css:i,...p}=f,c=Object.entries(p).reduce((S,[P,V])=>`${S}.${P}-${V}`,s),h=k(i,c);o.push(h)}),l;if(y.startsWith("@")){const f=k(r,s),i=`${y} {
2
- ${f.replace(`
3
- `,`
4
- `)}
5
- }`;return o.push(i),l}const j=$.includes("&")?y.replace("&",s):y.startsWith(":")?`${s}${y}`:`${s} ${y}`,d=k(r,j);return o.push(d),l}const g=y.startsWith("-")?y:N(y),w=(j,d=";")=>l=`${l}${j}${d}`,O=j=>w(`${g}:${j}`);if(typeof r=="number")return O(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return l;const{modifiers:C}={},D=function*(){yield q(r),yield J(r,C)}();for(const{result:j,additionalCss:d=[]}of D)r=j,d.forEach(f=>{const i=k(f,"");w(i,"")});return O(r)},"");if(!a)return o.join(`
6
- `);if(!s)return a;let b="";return b=`${s} { ${a} }`,[b,...o].join(`
7
- `)},Z=(t,s=[])=>{const e=[],n={};if(Object.entries(t).forEach(([o,a])=>{if(typeof a=="object"){if(!a)return;const b=o.trim(),l=Z(a,[...s,b]);e.push(l)}else n[o]=a}),Object.keys(n).length){const o=s.map(N).join("-"),a=k(n,`.${o}`);e.push(a)}return e.join(`
8
- `)};T.createLogger({level:"info",format:T.format.combine(T.format.colorize(),T.format.cli()),transports:[new T.transports.Console({})]});const E=t=>u.join(t,"./saltygen"),K=["salty","css","styles","styled"],R=(t=[])=>new RegExp(`\\.(${[...K,...t].join("|")})\\.`),U=(t,s=[])=>R(s).test(t),X=async t=>{const s=E(t),e=u.join(t,"salty-config.ts"),n=u.join(s,"salty-config.js");await _.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",external:["react"]});const o=Date.now(),{config:a}=await import(`${n}?t=${o}`);return a},Y=async t=>{const s=await X(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(N),N(p)].join("-"),{result:P}=q(c);return`--${S}: ${P};`}):[],o=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}"]`,V=S.join("");return`${P} { ${V} }`})):[],b=n(s.variables),l=o(s.responsiveVariables),$=a(s.conditionalVariables),r=E(t),y=u.join(r,"css/variables.css"),g=`:root { ${b.join("")} ${l.join("")} } ${$.join("")}`;m.writeFileSync(y,g);const w=u.join(r,"types/css-tokens.d.ts"),C=`type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;m.writeFileSync(w,C);const F=u.join(r,"css/global.css"),D=k(s.global,"");m.writeFileSync(F,D);const j=u.join(r,"css/templates.css"),d=Z(s.templates);m.writeFileSync(j,d)},Q=async(t,s)=>{const e=M(t),n=u.join(s,"js",e+".js");await _.build({entryPoints:[t],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:"esm",target:["es2022"],keepNames:!0,external:["react"]});const o=Date.now();return await import(`${n}?t=${o}`)},v=async t=>{const s=E(t),e=u.join(s,"salty-config.js"),{config:n}=await import(e);return n},tt=async t=>{try{const s=[],e=[],n=E(t),o=u.join(n,"index.css");(()=>{m.existsSync(n)&&L.execSync("rm -rf "+n),m.mkdirSync(n),m.mkdirSync(u.join(n,"css")),m.mkdirSync(u.join(n,"types"))})(),await Y(t);const b=await v(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()&&U(g)){const F=await Q(g,n),D=[];Object.entries(F).forEach(([i,p])=>{if(p.isKeyframes&&p.css){const V=`${p.animationName}.css`,I=`css/${V}`,W=u.join(n,I);s.push(V),m.writeFileSync(W,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=M(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(o,y)}catch(s){console.error(s)}},st=(t,s)=>{var e,n,o;(n=(e=t.module)==null?void 0:e.rules)==null||n.push({test:R(),use:[{loader:u.resolve("./loader.js"),options:{dir:s}}]}),(o=t.plugins)==null||o.push({apply:a=>{a.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await tt(s)})}})};exports.saltyPlugin=st;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const p=require("path"),u=require("./index-C85_DMmG.cjs"),r=(e,s,o=!1,n=!1)=>{var a,l,t;(l=(a=e.module)==null?void 0:a.rules)==null||l.push({test:u.saltyFileRegExp(),use:[{loader:p.resolve(__dirname,n?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),o||(t=e.plugins)==null||t.push({apply:i=>{i.hooks.afterPlugins.tap({name:"generateCss"},async()=>{await u.generateCss(s)})}})};exports.default=r;exports.saltyPlugin=r;
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,230 +1,24 @@
1
- import { join as m, resolve as L } from "path";
2
- import * as M from "esbuild";
3
- import * as T from "winston";
4
- import { execSync as q } from "child_process";
5
- import { existsSync as z, mkdirSync as E, statSync as B, readdirSync as G, writeFileSync as w } from "fs";
6
- import "fs/promises";
7
- const A = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), J = (t, s) => {
8
- let e = "", n;
9
- for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = A(n % 52) + e;
10
- return e = A(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
11
- }, K = (t, s) => {
12
- let e = s.length;
13
- for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
14
- return t;
15
- }, Z = (t, s = 3) => {
16
- const e = K(5381, JSON.stringify(t)) >>> 0;
17
- return J(e, s);
18
- };
19
- function N(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()) : "";
21
- }
22
- const U = (t, s) => {
23
- if (typeof t != "string") return { result: t };
24
- if (!s) return { result: t };
25
- const e = [];
26
- return Object.values(s).forEach((n) => {
27
- const { pattern: o, transform: a } = n;
28
- t = t.replace(o, (g) => {
29
- const { value: l, css: h } = a(g);
30
- return h && e.push(h), l;
31
- });
32
- }), { result: t, additionalCss: e };
33
- }, R = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${N(n[1].replaceAll(".", "-"))})`) } : { result: t }, k = (t, s, e, n) => {
34
- const o = [], a = Object.entries(t).reduce((l, [h, r]) => {
35
- const u = h.trim();
36
- if (typeof r == "function" && (r = r()), typeof r == "object") {
37
- if (!r) return l;
38
- if (u === "variants")
39
- return Object.entries(r).forEach(([f, i]) => {
40
- i && Object.entries(i).forEach(([p, c]) => {
41
- if (!c) return;
42
- const $ = `${s}.${f}-${p}`, j = k(c, $);
43
- o.push(j);
44
- });
45
- }), l;
46
- if (u === "defaultVariants")
47
- return l;
48
- if (u === "compoundVariants")
49
- return r.forEach((f) => {
50
- const { css: i, ...p } = f, c = Object.entries(p).reduce((j, [C, O]) => `${j}.${C}-${O}`, s), $ = k(i, c);
51
- o.push($);
52
- }), l;
53
- if (u.startsWith("@")) {
54
- const f = k(r, s), i = `${u} {
55
- ${f.replace(`
56
- `, `
57
- `)}
58
- }`;
59
- return o.push(i), l;
60
- }
61
- const b = h.includes("&") ? u.replace("&", s) : u.startsWith(":") ? `${s}${u}` : `${s} ${u}`, d = k(r, b);
62
- return o.push(d), l;
63
- }
64
- const y = u.startsWith("-") ? u : N(u), S = (b, d = ";") => l = `${l}${b}${d}`, V = (b) => S(`${y}:${b}`);
65
- if (typeof r == "number") return V(r);
66
- if (typeof r != "string")
67
- if ("toString" in r) r = r.toString();
68
- else return l;
69
- const { modifiers: D } = {}, F = function* () {
70
- yield R(r), yield U(r, D);
71
- }();
72
- for (const { result: b, additionalCss: d = [] } of F)
73
- r = b, d.forEach((f) => {
74
- const i = k(f, "");
75
- S(i, "");
76
- });
77
- return V(r);
78
- }, "");
79
- if (!a) return o.join(`
80
- `);
81
- if (!s) return a;
82
- let g = "";
83
- return g = `${s} { ${a} }`, [g, ...o].join(`
84
- `);
85
- }, I = (t, s = []) => {
86
- const e = [], n = {};
87
- if (Object.entries(t).forEach(([o, a]) => {
88
- if (typeof a == "object") {
89
- if (!a) return;
90
- const g = o.trim(), l = I(a, [...s, g]);
91
- e.push(l);
92
- } else
93
- n[o] = a;
94
- }), Object.keys(n).length) {
95
- const o = s.map(N).join("-"), a = k(n, `.${o}`);
96
- e.push(a);
97
- }
98
- return e.join(`
99
- `);
100
- };
101
- T.createLogger({
102
- level: "info",
103
- format: T.format.combine(T.format.colorize(), T.format.cli()),
104
- transports: [new T.transports.Console({})]
105
- });
106
- const x = (t) => m(t, "./saltygen"), X = ["salty", "css", "styles", "styled"], W = (t = []) => new RegExp(`\\.(${[...X, ...t].join("|")})\\.`), Y = (t, s = []) => W(s).test(t), Q = async (t) => {
107
- const s = x(t), e = m(t, "salty-config.ts"), n = m(s, "salty-config.js");
108
- await M.build({
109
- entryPoints: [e],
110
- minify: !0,
111
- treeShaking: !0,
112
- bundle: !0,
113
- outfile: n,
114
- format: "esm",
115
- external: ["react"]
116
- });
117
- const o = Date.now(), { config: a } = await import(`${n}?t=${o}`);
118
- return a;
119
- }, v = async (t) => {
120
- const s = await Q(t), e = /* @__PURE__ */ new Set(), n = (f, i = []) => f ? Object.entries(f).flatMap(([p, c]) => {
121
- if (!c) return;
122
- if (typeof c == "object") return n(c, [...i, p]);
123
- const $ = [...i, p].join(".");
124
- e.add(`"${$}"`);
125
- const j = [...i.map(N), N(p)].join("-"), { result: C } = R(c);
126
- return `--${j}: ${C};`;
127
- }) : [], o = (f) => f ? Object.entries(f).flatMap(([i, p]) => {
128
- const c = n(p);
129
- return i === "base" ? c.join("") : `${i} { ${c.join("")} }`;
130
- }) : [], a = (f) => f ? Object.entries(f).flatMap(([i, p]) => Object.entries(p).flatMap(([c, $]) => {
131
- const j = n($, [i]), C = `.${i}-${c}, [data-${i}="${c}"]`, O = j.join("");
132
- return `${C} { ${O} }`;
133
- })) : [], g = n(s.variables), l = o(s.responsiveVariables), h = a(s.conditionalVariables), r = x(t), u = m(r, "css/variables.css"), y = `:root { ${g.join("")} ${l.join("")} } ${h.join("")}`;
134
- w(u, y);
135
- const S = m(r, "types/css-tokens.d.ts"), D = `type VariableTokens = ${[...e].join("|")}; type PropertyValueToken = \`{\${VariableTokens}}\``;
136
- w(S, D);
137
- const P = m(r, "css/global.css"), F = k(s.global, "");
138
- w(P, F);
139
- const b = m(r, "css/templates.css"), d = I(s.templates);
140
- w(b, d);
141
- }, tt = async (t, s) => {
142
- const e = Z(t), n = m(s, "js", e + ".js");
143
- await M.build({
144
- entryPoints: [t],
145
- minify: !0,
146
- treeShaking: !0,
147
- bundle: !0,
148
- outfile: n,
149
- format: "esm",
150
- target: ["es2022"],
151
- keepNames: !0,
152
- external: ["react"]
153
- });
154
- const o = Date.now();
155
- return await import(`${n}?t=${o}`);
156
- }, st = async (t) => {
157
- const s = x(t), e = m(s, "salty-config.js"), { config: n } = await import(e);
158
- return n;
159
- }, et = async (t) => {
160
- try {
161
- const s = [], e = [], n = x(t), o = m(n, "index.css");
162
- (() => {
163
- z(n) && q("rm -rf " + n), E(n), E(m(n, "css")), E(m(n, "types"));
164
- })(), await v(t);
165
- const g = await st(t);
166
- async function l(y, S) {
167
- const V = B(y);
168
- if (V.isDirectory()) {
169
- const D = G(y);
170
- await Promise.all(D.map((P) => l(m(y, P), m(S, P))));
171
- } else if (V.isFile() && Y(y)) {
172
- const P = await tt(y, n), F = [];
173
- Object.entries(P).forEach(([i, p]) => {
174
- if (p.isKeyframes && p.css) {
175
- const O = `${p.animationName}.css`, _ = `css/${O}`, H = m(n, _);
176
- s.push(O), w(H, p.css);
177
- return;
178
- }
179
- if (!p.generator) return;
180
- const c = p.generator._withBuildContext({
181
- name: i,
182
- config: g
183
- }), $ = `${c.hash}-${c.priority}.css`;
184
- e[c.priority] || (e[c.priority] = []), e[c.priority].push($), F.push($);
185
- const j = `css/${$}`, C = m(n, j);
186
- w(C, c.css);
187
- });
188
- const b = F.map((i) => `@import url('./${i}');`).join(`
189
- `), d = Z(y, 6), f = m(n, `css/${d}.css`);
190
- w(f, b);
191
- }
192
- }
193
- await l(t, n);
194
- const h = s.map((y) => `@import url('./css/${y}');`).join(`
195
- `);
196
- let u = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
197
-
198
- ${["@import url('./css/variables.css');", "@import url('./css/global.css');", "@import url('./css/templates.css');"].join(`
199
- `)}
200
- ${h}`;
201
- if (g.importStrategy !== "component") {
202
- const y = e.flat().map((S) => `@import url('./css/${S}');`).join(`
203
- `);
204
- u += y;
205
- }
206
- w(o, u);
207
- } catch (s) {
208
- console.error(s);
209
- }
210
- }, ct = (t, s) => {
211
- var e, n, o;
212
- (n = (e = t.module) == null ? void 0 : e.rules) == null || n.push({
213
- test: W(),
1
+ import { resolve as n } from "path";
2
+ import { s as u, g as i } from "./index-DAmJ383d.js";
3
+ const g = (s, e, o = !1, r = !1) => {
4
+ var a, l, t;
5
+ (l = (a = s.module) == null ? void 0 : a.rules) == null || l.push({
6
+ test: u(),
214
7
  use: [
215
8
  {
216
- loader: L("./loader.js"),
217
- options: { dir: s }
9
+ loader: n(__dirname, r ? "./loader.cjs" : "./loader.js"),
10
+ options: { dir: e }
218
11
  }
219
12
  ]
220
- }), (o = t.plugins) == null || o.push({
221
- apply: (a) => {
222
- a.hooks.afterPlugins.tap({ name: "generateCss" }, async () => {
223
- await et(s);
13
+ }), o || (t = s.plugins) == null || t.push({
14
+ apply: (p) => {
15
+ p.hooks.afterPlugins.tap({ name: "generateCss" }, async () => {
16
+ await i(e);
224
17
  });
225
18
  }
226
19
  });
227
20
  };
228
21
  export {
229
- ct as saltyPlugin
22
+ g as default,
23
+ g as saltyPlugin
230
24
  };
package/loader.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";const i=require("./index-C85_DMmG.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-DAmJ383d.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.12",
3
+ "version": "0.0.1-alpha.120",
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
  },
@@ -27,5 +32,9 @@
27
32
  "import": "./index.js",
28
33
  "require": "./index.cjs"
29
34
  }
35
+ },
36
+ "dependencies": {
37
+ "@salty-css/core": "^0.0.1-alpha.120",
38
+ "webpack": ">=5.x"
30
39
  }
31
40
  }