@salty-css/webpack 0.0.1-alpha.22 → 0.0.1-alpha.220
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 +143 -26
- package/index-DHuI5JGu.cjs +42 -0
- package/index-DimebhYU.js +653 -0
- package/index.cjs +1 -15
- package/index.d.ts +2 -1
- package/index.js +25 -215
- package/loader.cjs +1 -0
- package/loader.js +8 -0
- package/package.json +9 -4
package/README.md
CHANGED
@@ -1,15 +1,132 @@
|
|
1
|
-
|
1
|
+

|
2
2
|
|
3
|
-
|
3
|
+
# Salty CSS - CSS-in-JS library that is kinda sweet
|
4
4
|
|
5
|
-
|
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
|
-
|
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
|
-
|
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
|
+

|
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
|
+

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