@salty-css/webpack 0.0.1-alpha.17 → 0.0.1-alpha.171
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-a4KtTJRO.cjs +36 -0
- package/index-jvM0uSOz.js +481 -0
- package/index.cjs +1 -15
- package/index.d.ts +2 -1
- package/index.js +28 -214
- 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,36 @@
|
|
1
|
+
"use strict";const de=require("esbuild"),ye=require("child_process"),a=require("path"),f=require("fs"),K=require("fs/promises"),I=require("winston");var G=typeof document<"u"?document.currentScript:null;function ge(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 ee=ge(de),Y=e=>String.fromCharCode(e+(e>25?39:97)),me=(e,t)=>{let s="",n;for(n=Math.abs(e);n>52;n=n/52|0)s=Y(n%52)+s;return s=Y(n%52)+s,s.length<t?s=s.padStart(t,"a"):s.length>t&&(s=s.slice(-t)),s},he=(e,t)=>{let s=t.length;for(;s;)e=e*33^t.charCodeAt(--s);return e},Z=(e,t=5)=>{const s=he(5381,JSON.stringify(e))>>>0;return me(s,t)};function M(e){return e?typeof e!="string"?M(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 be=(e,t)=>{if(typeof e!="string")return{result:e};if(!t)return{result:e};const s=[];return Object.values(t).forEach(n=>{const{pattern:o,transform:i}=n;e=e.replace(o,u=>{const{value:d,css:r}=i(u);return r&&s.push(r),d})}),{result:e,additionalCss:s}},te=e=>typeof e!="string"?{result:e}:/\{[^{}]+\}/g.test(e)?{result:e.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${M(n[1].replaceAll(".","-"))})`)}:{result:e},V=(e,t,s)=>{if(!e)return"";const n=[],o=Object.entries(e).reduce((u,[d,r])=>{const c=d.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return u;if(c==="variants")return Object.entries(r).forEach(([j,x])=>{x&&Object.entries(x).forEach(([l,m])=>{if(!m)return;const w=`${t}.${j}-${l}`,b=V(m,w);n.push(b)})}),u;if(c==="defaultVariants")return u;if(c==="compoundVariants")return r.forEach(j=>{const{css:x,...l}=j,m=Object.entries(l).reduce((b,[g,F])=>`${b}.${g}-${F}`,t),w=V(x,m);n.push(w)}),u;if(c.startsWith("@")){const j=V(r,t),x=`${c} {
|
2
|
+
${j.replace(`
|
3
|
+
`,`
|
4
|
+
`)}
|
5
|
+
}`;return n.push(x),u}const h=d.includes("&")?c.replace("&",t):c.startsWith(":")?`${t}${c}`:`${t} ${c}`,D=V(r,h);return n.push(D),u}const y=c.startsWith("-")?c:M(c),p=(h,D=";")=>u=`${u}${h}${D}`,k=h=>p(`${y}:${h}`);if(typeof r=="number")return k(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return u;const{modifiers:N}={},T=function*(){yield te(r),yield be(r,N)}();for(const{result:h,additionalCss:D=[]}of T)r=h,D.forEach(j=>{const x=V(j,"");p(x,"")});return k(r)},"");return o?t?[`${t} { ${o} }`,...n].join(`
|
6
|
+
`):o:n.join(`
|
7
|
+
`)},se=(e,t=[])=>{if(!e)return"";const s=[],n={};if(Object.entries(e).forEach(([o,i])=>{if(typeof i=="object"){if(!i)return;const u=o.trim(),d=se(i,[...t,u]);s.push(d)}else n[o]=i}),Object.keys(n).length){const o=t.map(M).join("-"),i=V(n,`.${o}`);s.push(i)}return s.join(`
|
8
|
+
`)},Se=e=>Object.entries(e).reduce((t,[s,n])=>(typeof n=="object"&&(t[s]=ne(n).map(o=>`"${o}"`).join(" | ")),t),{}),ne=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const i=t?`${t}.${n}`:n;return typeof o=="object"?ne(o,i,s):s.add(t)}),[...s]):[],re=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=a.join(e,"package.json");return f.existsSync(t)?t:re(a.join(e,".."))},$e=async e=>{const t=re(e);return await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},je=async e=>{const t=await $e(e);if(t)return t.type};let J;const oe=async e=>{if(J)return J;const t=await je(e);return t==="module"?J="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:G&&G.tagName.toUpperCase()==="SCRIPT"&&G.src||new URL("index-a4KtTJRO.cjs",document.baseURI).href).endsWith(".cjs"))&&(J="cjs"),J||"esm"},B=I.createLogger({level:"debug",format:I.format.combine(I.format.colorize(),I.format.cli()),transports:[new I.transports.Console({})]});function ie(e){return e?typeof e!="string"?ie(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 we={"*, *::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"}},q=(...e)=>e.flat().reduce((t,s)=>s!=null&&s._current?{...t,...s._current}:{...t,...s},{}),O={externalModules:[],rcFile:void 0,destDir:void 0},ce=e=>{if(O.externalModules.length>0)return O.externalModules;const s=f.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return O.externalModules=n,n},W=async e=>{if(O.destDir)return O.destDir;const t=await U(e),s=a.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return O.destDir=s,s},ae=["salty","css","styles","styled"],le=(e=[])=>new RegExp(`\\.(${[...ae,...e].join("|")})\\.`),H=(e,t=[])=>le(t).test(e),fe=async e=>{if(O.rcFile)return O.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=a.join(e,".saltyrc.json"),s=await K.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(O.rcFile=s,s):fe(a.join(e,".."))},U=async e=>{var n,o;const t=await fe(e),s=(n=t.projects)==null?void 0:n.find(i=>e.endsWith(i.dir||""));return s||((o=t.projects)==null?void 0:o.find(i=>i.dir===t.defaultProject))},Fe=async e=>{const t=await U(e),s=await W(e),n=a.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=a.join(s,"salty.config.js"),i=await oe(e),u=ce(n);await ee.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:u});const d=Date.now(),{config:r}=await import(`${o}?t=${d}`);return r},Ce=async(e,t)=>{const s=await Fe(e),n=new Set,o=($,C=[])=>$?Object.entries($).flatMap(([E,_])=>{if(!_)return;if(typeof _=="object")return o(_,[...C,E]);const z=ie(E),R=M(E),A=[...C,z].join(".");n.add(`"${A}"`);const L=[...C.map(M),R].join("-"),{result:pe}=te(_);return`--${L}: ${pe};`}):[],i=$=>$?Object.entries($).flatMap(([C,E])=>{const _=o(E);return C==="base"?_.join(""):`${C} { ${_.join("")} }`}):[],u=$=>$?Object.entries($).flatMap(([C,E])=>Object.entries(E).flatMap(([_,z])=>{const R=o(z,[C]),A=`.${C}-${_}, [data-${C}="${_}"]`,L=R.join("");return`${A} { ${L} }`})):[],d=$=>t.variables.map(C=>C._current[$]),r=o(q(s.variables,d("variables"))),c=i(q(s.responsiveVariables,d("responsiveVariables"))),y=u(q(s.conditionalVariables,d("conditionalVariables"))),p=await W(e),k=a.join(p,"css/_variables.css"),N=`:root { ${r.join("")} ${c.join("")} } ${y.join("")}`;f.writeFileSync(k,N);const P=a.join(p,"css/_global.css"),T=q(s.global,t.globalStyles),h=V(T,"");f.writeFileSync(P,`@layer global { ${h} }`);const D=a.join(p,"css/_reset.css"),x=s.reset==="none"?{}:typeof s.reset=="object"?s.reset:we,l=V(x,"");f.writeFileSync(D,`@layer reset { ${l} }`);const m=a.join(p,"css/_templates.css"),w=se(s.templates),b=Se(s.templates);f.writeFileSync(m,w);const g=a.join(p,"types/css-tokens.d.ts"),S=`
|
9
|
+
// Variable types
|
10
|
+
type VariableTokens = ${[...n].join("|")};
|
11
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
12
|
+
|
13
|
+
// Template types
|
14
|
+
type TemplateTokens = {
|
15
|
+
${Object.entries(b).map(([$,C])=>`${$}?: ${C}`).join(`
|
16
|
+
`)}
|
17
|
+
}
|
18
|
+
`;f.writeFileSync(g,S)},v=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 u=o.exec(e);if(u){const d=u.at(1);if(ae.some(c=>d==null?void 0:d.includes(c)))return t}return"styled('div',"}),Q=async(e,t,s)=>{const n=Z(t),o=a.join(s,"./temp");f.existsSync(o)||f.mkdirSync(o);const i=a.parse(t);let u=f.readFileSync(t,"utf8");u=v(u);const d=a.join(s,"js",n+".js"),r=await U(e),c=a.join(e,(r==null?void 0:r.configDir)||"","salty.config.ts"),y=ce(c),p=await oe(e);await ee.build({stdin:{contents:u,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:p,target:["node20"],keepNames:!0,external:y,packages:"external",plugins:[{name:"test",setup:P=>{P.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},T=>{const h=f.readFileSync(T.path,"utf8");return{contents:v(h),loader:"ts"}})}}]});const k=Date.now();return await import(`${d}?t=${k}`)},X=async e=>{const t=await W(e),s=a.join(t,"salty.config.js"),n=Date.now(),{config:o}=await import(`${s}?t=${n}`);return o},ue=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},xe=async(e,t=ue())=>{try{const s=Date.now();t?B.info("Generating CSS in production mode! 🔥"):B.info("Generating CSS in development mode! 🚀");const n=[],o=[],i=await W(e),u=a.join(i,"index.css");(()=>{f.existsSync(i)&&ye.execSync("rm -rf "+i),f.mkdirSync(i,{recursive:!0}),f.mkdirSync(a.join(i,"css")),f.mkdirSync(a.join(i,"types"))})();const r={keyframes:[],mediaQueries:[],globalStyles:[],variables:[],components:[]};async function c(l){const m=["node_modules","saltygen"],w=f.statSync(l);if(w.isDirectory()){const b=f.readdirSync(l);if(m.some(F=>l.includes(F)))return;await Promise.all(b.map(F=>c(a.join(l,F))))}else if(w.isFile()&&H(l)){const g=await Q(e,l,i);Object.entries(g).forEach(([F,S])=>{S.isKeyframes?r.keyframes.push({value:S,src:l,name:F}):S.isMedia?r.mediaQueries.push(S):S.isGlobalDefine?r.globalStyles.push(S):S.isDefineVariables?r.variables.push(S):S.generator&&r.components.push({value:S.generator,src:l,name:F})})}}await c(e),await Ce(e,r);const y=await X(e);for(const l of r.keyframes){const{value:m}=l,w=`a_${m.animationName}.css`,b=`css/${w}`,g=a.join(i,b);n.push(w),f.writeFileSync(g,m.css)}const p={};for(const l of r.components){const{value:m,name:w,src:b}=l,g=m._withBuildContext({name:w,config:y,prod:t});o[g.priority]||(o[g.priority]=[]),o[g.priority].push(g.cssFileName),y.importStrategy==="component"&&(p[b]?p[b].push(g.cssFileName):p[b]=[g.cssFileName]);const F=`css/${g.cssFileName}`,S=a.join(i,F);f.writeFileSync(S,g.css)}y.importStrategy==="component"&&Object.entries(p).forEach(([l,m])=>{const w=m.map($=>`@import url('./${$}');`).join(`
|
19
|
+
`),b=Z(l,6),g=a.parse(l),F=M(g.name),S=a.join(i,`css/f_${F}-${b}.css`);f.writeFileSync(S,w)});const k=n.map(l=>`@import url('./css/${l}');`).join(`
|
20
|
+
`);let h=`@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(i,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
23
|
+
`)}
|
24
|
+
${k}`;if(y.importStrategy!=="component"){const l=o.reduce((m,w,b)=>{const g=w.reduce((C,E)=>{var A;const _=a.join(i,"css",E),z=f.readFileSync(_,"utf8"),R=((A=/.*-([^-]+)-\d+.css/.exec(E))==null?void 0:A.at(1))||Z(_,6);return C.includes(R)?C:`${C}
|
25
|
+
/*start:${R}*/
|
26
|
+
${z}
|
27
|
+
/*end:${R}*/
|
28
|
+
`},""),F=`l_${b}.css`,S=a.join(i,"css",F),$=`@layer l${b} { ${g}
|
29
|
+
}`;return f.writeFileSync(S,$),`${m}
|
30
|
+
@import url('./css/${F}');`},"");h+=l}f.writeFileSync(u,h);const j=Date.now()-s,x=j<200?"🔥":j<500?"🚀":j<1e3?"🎉":j<2e3?"🚗":j<5e3?"🤔":"🥴";B.info(`Generated CSS in ${j}ms! ${x}`)}catch(s){console.error(s)}},ke=async(e,t)=>{try{const s=await W(e);if(H(t)){const o=[],i=await X(e),u=await Q(e,t,s);Object.entries(u).forEach(([d,r])=>{if(r.isKeyframes&&r.css){const N=`css/${`a_${r.animationName}.css`}`,P=a.join(s,N);f.writeFileSync(P,r.css);return}if(!r.generator)return;const c=r.generator._withBuildContext({name:d,config:i}),y=`css/${c.cssFileName}`,p=a.join(s,y);f.writeFileSync(p,c.css),o[c.priority]||(o[c.priority]=[]),o[c.priority].push(c.cssFileName)}),i.importStrategy!=="component"&&o.forEach((d,r)=>{const c=`l_${r}.css`,y=a.join(s,"css",c);let p=f.readFileSync(y,"utf8");d.forEach(k=>{var h;const N=a.join(s,"css",k),P=((h=/.*-([^-]+)-\d+.css/.exec(k))==null?void 0:h.at(1))||Z(N,6);if(!p.includes(P)){const D=f.readFileSync(N,"utf8"),j=`/*start:${P}*/
|
31
|
+
${D}
|
32
|
+
/*end:${P}*/
|
33
|
+
`;p=`${p.replace(/\}$/,"")}
|
34
|
+
${j}
|
35
|
+
}`}}),f.writeFileSync(y,p)})}}catch(s){console.error(s)}},De=async(e,t,s=ue())=>{try{const n=await W(e);if(H(t)){const i=f.readFileSync(t,"utf8");i.replace(/^(?!export\s)const\s.*/gm,y=>`export ${y}`)!==i&&await K.writeFile(t,i);const d=await X(e),r=await Q(e,t,n);let c=i;if(Object.entries(r).forEach(([y,p])=>{var S;if(p.isKeyframes||!p.generator)return;const k=p.generator._withBuildContext({name:y,config:d,prod:s}),N=new RegExp(`\\s${y}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!N)return console.error("Could not find the original declaration");const P=(S=N.at(1))==null?void 0:S.trim(),T=new RegExp(`\\s${y}[=\\s]+styled\\(`,"g").exec(c);if(!T)return console.error("Could not find the original declaration");const{index:h}=T;let D=!1;const j=setTimeout(()=>D=!0,5e3);let x=0,l=!1,m=0;for(;!l&&!D;){const $=c[h+x];$==="("&&m++,$===")"&&m--,m===0&&$===")"&&(l=!0),x>c.length&&(D=!0),x++}if(!D)clearTimeout(j);else throw new Error("Failed to find the end of the styled call and timed out");const w=h+x,b=c.slice(h,w),g=c,F=` ${y} = styled(${P}, "${k.classNames}", ${JSON.stringify(k.props)});`;c=c.replace(b,F),g===c&&console.error("Minimize file failed to change content",{name:y,tagName:P})}),d.importStrategy==="component"){const y=Z(t,6),p=a.parse(t);c=`import '../../saltygen/css/${`f_${M(p.name)}-${y}.css`}';
|
36
|
+
${c}`}return c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(n){console.error("Error in minimizeFile:",n)}};exports.generateCss=xe;exports.generateFile=ke;exports.isSaltyFile=H;exports.minimizeFile=De;exports.saltyFileRegExp=le;
|
@@ -0,0 +1,481 @@
|
|
1
|
+
import * as st from "esbuild";
|
2
|
+
import { execSync as mt } from "child_process";
|
3
|
+
import { join as l, parse as q } from "path";
|
4
|
+
import { existsSync as Q, writeFileSync as E, readFileSync as M, mkdirSync as G, statSync as yt, readdirSync as ht } from "fs";
|
5
|
+
import { readFile as nt, writeFile as $t } from "fs/promises";
|
6
|
+
import { createLogger as bt, format as B, transports as St } from "winston";
|
7
|
+
const tt = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), wt = (t, e) => {
|
8
|
+
let s = "", n;
|
9
|
+
for (n = Math.abs(t); n > 52; n = n / 52 | 0) s = tt(n % 52) + s;
|
10
|
+
return s = tt(n % 52) + s, s.length < e ? s = s.padStart(e, "a") : s.length > e && (s = s.slice(-e)), s;
|
11
|
+
}, jt = (t, e) => {
|
12
|
+
let s = e.length;
|
13
|
+
for (; s; ) t = t * 33 ^ e.charCodeAt(--s);
|
14
|
+
return t;
|
15
|
+
}, H = (t, e = 5) => {
|
16
|
+
const s = jt(5381, JSON.stringify(t)) >>> 0;
|
17
|
+
return wt(s, e);
|
18
|
+
};
|
19
|
+
function R(t) {
|
20
|
+
return t ? typeof t != "string" ? R(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 Ct = (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, (f) => {
|
29
|
+
const { value: u, css: o } = i(f);
|
30
|
+
return o && s.push(o), u;
|
31
|
+
});
|
32
|
+
}), { result: t, additionalCss: s };
|
33
|
+
}, ot = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${R(n[1].replaceAll(".", "-"))})`) } : { result: t }, O = (t, e, s) => {
|
34
|
+
if (!t) return "";
|
35
|
+
const n = [], r = Object.entries(t).reduce((f, [u, o]) => {
|
36
|
+
const c = u.trim();
|
37
|
+
if (typeof o == "function" && (o = o()), typeof o == "object") {
|
38
|
+
if (!o) return f;
|
39
|
+
if (c === "variants")
|
40
|
+
return Object.entries(o).forEach(([S, F]) => {
|
41
|
+
F && Object.entries(F).forEach(([a, m]) => {
|
42
|
+
if (!m) return;
|
43
|
+
const w = `${e}.${S}-${a}`, h = O(m, w);
|
44
|
+
n.push(h);
|
45
|
+
});
|
46
|
+
}), f;
|
47
|
+
if (c === "defaultVariants")
|
48
|
+
return f;
|
49
|
+
if (c === "compoundVariants")
|
50
|
+
return o.forEach((S) => {
|
51
|
+
const { css: F, ...a } = S, m = Object.entries(a).reduce((h, [g, j]) => `${h}.${g}-${j}`, e), w = O(F, m);
|
52
|
+
n.push(w);
|
53
|
+
}), f;
|
54
|
+
if (c.startsWith("@")) {
|
55
|
+
const S = O(o, e), F = `${c} {
|
56
|
+
${S.replace(`
|
57
|
+
`, `
|
58
|
+
`)}
|
59
|
+
}`;
|
60
|
+
return n.push(F), f;
|
61
|
+
}
|
62
|
+
const y = u.includes("&") ? c.replace("&", e) : c.startsWith(":") ? `${e}${c}` : `${e} ${c}`, k = O(o, y);
|
63
|
+
return n.push(k), f;
|
64
|
+
}
|
65
|
+
const d = c.startsWith("-") ? c : R(c), p = (y, k = ";") => f = `${f}${y}${k}`, x = (y) => p(`${d}:${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 f;
|
70
|
+
const { modifiers: D } = {}, T = function* () {
|
71
|
+
yield ot(o), yield Ct(o, D);
|
72
|
+
}();
|
73
|
+
for (const { result: y, additionalCss: k = [] } of T)
|
74
|
+
o = y, k.forEach((S) => {
|
75
|
+
const F = O(S, "");
|
76
|
+
p(F, "");
|
77
|
+
});
|
78
|
+
return x(o);
|
79
|
+
}, "");
|
80
|
+
return r ? e ? [`${e} { ${r} }`, ...n].join(`
|
81
|
+
`) : r : n.join(`
|
82
|
+
`);
|
83
|
+
}, rt = (t, e = []) => {
|
84
|
+
if (!t) return "";
|
85
|
+
const s = [], n = {};
|
86
|
+
if (Object.entries(t).forEach(([r, i]) => {
|
87
|
+
if (typeof i == "object") {
|
88
|
+
if (!i) return;
|
89
|
+
const f = r.trim(), u = rt(i, [...e, f]);
|
90
|
+
s.push(u);
|
91
|
+
} else
|
92
|
+
n[r] = i;
|
93
|
+
}), Object.keys(n).length) {
|
94
|
+
const r = e.map(R).join("-"), i = O(n, `.${r}`);
|
95
|
+
s.push(i);
|
96
|
+
}
|
97
|
+
return s.join(`
|
98
|
+
`);
|
99
|
+
}, Ft = (t) => Object.entries(t).reduce((e, [s, n]) => (typeof n == "object" && (e[s] = it(n).map((r) => `"${r}"`).join(" | ")), e), {}), it = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, r]) => {
|
100
|
+
const i = e ? `${e}.${n}` : n;
|
101
|
+
return typeof r == "object" ? it(r, i, s) : s.add(e);
|
102
|
+
}), [...s]) : [], ct = (t) => {
|
103
|
+
if (!t || t === "/") throw new Error("Could not find package.json file");
|
104
|
+
const e = l(t, "package.json");
|
105
|
+
return Q(e) ? e : ct(l(t, ".."));
|
106
|
+
}, xt = async (t) => {
|
107
|
+
const e = ct(t);
|
108
|
+
return await nt(e, "utf-8").then(JSON.parse).catch(() => {
|
109
|
+
});
|
110
|
+
}, kt = async (t) => {
|
111
|
+
const e = await xt(t);
|
112
|
+
if (e)
|
113
|
+
return e.type;
|
114
|
+
};
|
115
|
+
let W;
|
116
|
+
const at = async (t) => {
|
117
|
+
if (W) return W;
|
118
|
+
const e = await kt(t);
|
119
|
+
return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
|
120
|
+
}, K = bt({
|
121
|
+
level: "debug",
|
122
|
+
format: B.combine(B.colorize(), B.cli()),
|
123
|
+
transports: [new St.Console({})]
|
124
|
+
});
|
125
|
+
function lt(t) {
|
126
|
+
return t ? typeof t != "string" ? lt(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
|
127
|
+
}
|
128
|
+
const Dt = {
|
129
|
+
/** Set box model to border-box */
|
130
|
+
"*, *::before, *::after": {
|
131
|
+
boxSizing: "border-box"
|
132
|
+
},
|
133
|
+
/** Remove default margin and padding */
|
134
|
+
"*": {
|
135
|
+
margin: 0
|
136
|
+
},
|
137
|
+
/** Remove adjust font properties */
|
138
|
+
html: {
|
139
|
+
lineHeight: 1.15,
|
140
|
+
textSizeAdjust: "100%",
|
141
|
+
WebkitFontSmoothing: "antialiased"
|
142
|
+
},
|
143
|
+
/** Make media elements responsive */
|
144
|
+
"img, picture, video, canvas, svg": {
|
145
|
+
display: "block",
|
146
|
+
maxWidth: "100%"
|
147
|
+
},
|
148
|
+
/** Avoid overflow of text */
|
149
|
+
"p, h1, h2, h3, h4, h5, h6": {
|
150
|
+
overflowWrap: "break-word"
|
151
|
+
},
|
152
|
+
/** Improve text wrapping */
|
153
|
+
p: {
|
154
|
+
textWrap: "pretty"
|
155
|
+
},
|
156
|
+
"h1, h2, h3, h4, h5, h6": {
|
157
|
+
textWrap: "balance"
|
158
|
+
},
|
159
|
+
/** Improve link color */
|
160
|
+
a: {
|
161
|
+
color: "currentColor"
|
162
|
+
},
|
163
|
+
/** Improve button line height */
|
164
|
+
button: {
|
165
|
+
lineHeight: "1em",
|
166
|
+
color: "currentColor"
|
167
|
+
},
|
168
|
+
/** Improve form elements */
|
169
|
+
"input, optgroup, select, textarea": {
|
170
|
+
fontFamily: "inherit",
|
171
|
+
fontSize: "100%",
|
172
|
+
lineHeight: "1.15em"
|
173
|
+
}
|
174
|
+
}, I = (...t) => t.flat().reduce((e, s) => s != null && s._current ? { ...e, ...s._current } : { ...e, ...s }, {}), _ = {
|
175
|
+
externalModules: [],
|
176
|
+
rcFile: void 0,
|
177
|
+
destDir: void 0
|
178
|
+
}, ft = (t) => {
|
179
|
+
if (_.externalModules.length > 0) return _.externalModules;
|
180
|
+
const s = M(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
181
|
+
if (!s) return [];
|
182
|
+
const n = s[1].split(",").map((r) => r.replace(/['"`]/g, "").trim());
|
183
|
+
return _.externalModules = n, n;
|
184
|
+
}, z = async (t) => {
|
185
|
+
if (_.destDir) return _.destDir;
|
186
|
+
const e = await X(t), s = l(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
187
|
+
return _.destDir = s, s;
|
188
|
+
}, pt = ["salty", "css", "styles", "styled"], Nt = (t = []) => new RegExp(`\\.(${[...pt, ...t].join("|")})\\.`), U = (t, e = []) => Nt(e).test(t), ut = async (t) => {
|
189
|
+
if (_.rcFile) return _.rcFile;
|
190
|
+
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
191
|
+
const e = l(t, ".saltyrc.json"), s = await nt(e, "utf-8").then(JSON.parse).catch(() => {
|
192
|
+
});
|
193
|
+
return s ? (_.rcFile = s, s) : ut(l(t, ".."));
|
194
|
+
}, X = async (t) => {
|
195
|
+
var n, r;
|
196
|
+
const e = await ut(t), s = (n = e.projects) == null ? void 0 : n.find((i) => t.endsWith(i.dir || ""));
|
197
|
+
return s || ((r = e.projects) == null ? void 0 : r.find((i) => i.dir === e.defaultProject));
|
198
|
+
}, Pt = async (t) => {
|
199
|
+
const e = await X(t), s = await z(t), n = l(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), r = l(s, "salty.config.js"), i = await at(t), f = ft(n);
|
200
|
+
await st.build({
|
201
|
+
entryPoints: [n],
|
202
|
+
minify: !0,
|
203
|
+
treeShaking: !0,
|
204
|
+
bundle: !0,
|
205
|
+
outfile: r,
|
206
|
+
format: i,
|
207
|
+
external: f
|
208
|
+
});
|
209
|
+
const u = Date.now(), { config: o } = await import(`${r}?t=${u}`);
|
210
|
+
return o;
|
211
|
+
}, Et = async (t, e) => {
|
212
|
+
const s = await Pt(t), n = /* @__PURE__ */ new Set(), r = (b, C = []) => b ? Object.entries(b).flatMap(([V, P]) => {
|
213
|
+
if (!P) return;
|
214
|
+
if (typeof P == "object") return r(P, [...C, V]);
|
215
|
+
const Z = lt(V), A = R(V), J = [...C, Z].join(".");
|
216
|
+
n.add(`"${J}"`);
|
217
|
+
const L = [...C.map(R), A].join("-"), { result: gt } = ot(P);
|
218
|
+
return `--${L}: ${gt};`;
|
219
|
+
}) : [], i = (b) => b ? Object.entries(b).flatMap(([C, V]) => {
|
220
|
+
const P = r(V);
|
221
|
+
return C === "base" ? P.join("") : `${C} { ${P.join("")} }`;
|
222
|
+
}) : [], f = (b) => b ? Object.entries(b).flatMap(([C, V]) => Object.entries(V).flatMap(([P, Z]) => {
|
223
|
+
const A = r(Z, [C]), J = `.${C}-${P}, [data-${C}="${P}"]`, L = A.join("");
|
224
|
+
return `${J} { ${L} }`;
|
225
|
+
})) : [], u = (b) => e.variables.map((C) => C._current[b]), o = r(I(s.variables, u("variables"))), c = i(I(s.responsiveVariables, u("responsiveVariables"))), d = f(I(s.conditionalVariables, u("conditionalVariables"))), p = await z(t), x = l(p, "css/_variables.css"), D = `:root { ${o.join("")} ${c.join("")} } ${d.join("")}`;
|
226
|
+
E(x, D);
|
227
|
+
const N = l(p, "css/_global.css"), T = I(s.global, e.globalStyles), y = O(T, "");
|
228
|
+
E(N, `@layer global { ${y} }`);
|
229
|
+
const k = l(p, "css/_reset.css"), F = s.reset === "none" ? {} : typeof s.reset == "object" ? s.reset : Dt, a = O(F, "");
|
230
|
+
E(k, `@layer reset { ${a} }`);
|
231
|
+
const m = l(p, "css/_templates.css"), w = rt(s.templates), h = Ft(s.templates);
|
232
|
+
E(m, w);
|
233
|
+
const g = l(p, "types/css-tokens.d.ts"), $ = `
|
234
|
+
// Variable types
|
235
|
+
type VariableTokens = ${[...n].join("|")};
|
236
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
237
|
+
|
238
|
+
// Template types
|
239
|
+
type TemplateTokens = {
|
240
|
+
${Object.entries(h).map(([b, C]) => `${b}?: ${C}`).join(`
|
241
|
+
`)}
|
242
|
+
}
|
243
|
+
`;
|
244
|
+
E(g, $);
|
245
|
+
}, et = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
246
|
+
if (/^['"`]/.test(s)) return e;
|
247
|
+
const r = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
248
|
+
if (!r.test(t)) return e;
|
249
|
+
const f = r.exec(t);
|
250
|
+
if (f) {
|
251
|
+
const u = f.at(1);
|
252
|
+
if (pt.some((c) => u == null ? void 0 : u.includes(c))) return e;
|
253
|
+
}
|
254
|
+
return "styled('div',";
|
255
|
+
}), Y = async (t, e, s) => {
|
256
|
+
const n = H(e), r = l(s, "./temp");
|
257
|
+
Q(r) || G(r);
|
258
|
+
const i = q(e);
|
259
|
+
let f = M(e, "utf8");
|
260
|
+
f = et(f);
|
261
|
+
const u = l(s, "js", n + ".js"), o = await X(t), c = l(t, (o == null ? void 0 : o.configDir) || "", "salty.config.ts"), d = ft(c), p = await at(t);
|
262
|
+
await st.build({
|
263
|
+
stdin: {
|
264
|
+
contents: f,
|
265
|
+
sourcefile: i.base,
|
266
|
+
resolveDir: i.dir,
|
267
|
+
loader: "tsx"
|
268
|
+
},
|
269
|
+
minify: !1,
|
270
|
+
treeShaking: !0,
|
271
|
+
bundle: !0,
|
272
|
+
outfile: u,
|
273
|
+
format: p,
|
274
|
+
target: ["node20"],
|
275
|
+
keepNames: !0,
|
276
|
+
external: d,
|
277
|
+
packages: "external",
|
278
|
+
plugins: [
|
279
|
+
{
|
280
|
+
name: "test",
|
281
|
+
setup: (N) => {
|
282
|
+
N.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (T) => {
|
283
|
+
const y = M(T.path, "utf8");
|
284
|
+
return { contents: et(y), loader: "ts" };
|
285
|
+
});
|
286
|
+
}
|
287
|
+
}
|
288
|
+
]
|
289
|
+
});
|
290
|
+
const x = Date.now();
|
291
|
+
return await import(`${u}?t=${x}`);
|
292
|
+
}, v = async (t) => {
|
293
|
+
const e = await z(t), s = l(e, "salty.config.js"), n = Date.now(), { config: r } = await import(`${s}?t=${n}`);
|
294
|
+
return r;
|
295
|
+
}, dt = () => {
|
296
|
+
try {
|
297
|
+
return process.env.NODE_ENV === "production";
|
298
|
+
} catch {
|
299
|
+
return !1;
|
300
|
+
}
|
301
|
+
}, Rt = async (t, e = dt()) => {
|
302
|
+
try {
|
303
|
+
const s = Date.now();
|
304
|
+
e ? K.info("Generating CSS in production mode! 🔥") : K.info("Generating CSS in development mode! 🚀");
|
305
|
+
const n = [], r = [], i = await z(t), f = l(i, "index.css");
|
306
|
+
(() => {
|
307
|
+
Q(i) && mt("rm -rf " + i), G(i, { recursive: !0 }), G(l(i, "css")), G(l(i, "types"));
|
308
|
+
})();
|
309
|
+
const o = {
|
310
|
+
keyframes: [],
|
311
|
+
mediaQueries: [],
|
312
|
+
globalStyles: [],
|
313
|
+
variables: [],
|
314
|
+
components: []
|
315
|
+
};
|
316
|
+
async function c(a) {
|
317
|
+
const m = ["node_modules", "saltygen"], w = yt(a);
|
318
|
+
if (w.isDirectory()) {
|
319
|
+
const h = ht(a);
|
320
|
+
if (m.some((j) => a.includes(j))) return;
|
321
|
+
await Promise.all(h.map((j) => c(l(a, j))));
|
322
|
+
} else if (w.isFile() && U(a)) {
|
323
|
+
const g = await Y(t, a, i);
|
324
|
+
Object.entries(g).forEach(([j, $]) => {
|
325
|
+
$.isKeyframes ? o.keyframes.push({
|
326
|
+
value: $,
|
327
|
+
src: a,
|
328
|
+
name: j
|
329
|
+
}) : $.isMedia ? o.mediaQueries.push($) : $.isGlobalDefine ? o.globalStyles.push($) : $.isDefineVariables ? o.variables.push($) : $.generator && o.components.push({
|
330
|
+
value: $.generator,
|
331
|
+
src: a,
|
332
|
+
name: j
|
333
|
+
});
|
334
|
+
});
|
335
|
+
}
|
336
|
+
}
|
337
|
+
await c(t), await Et(t, o);
|
338
|
+
const d = await v(t);
|
339
|
+
for (const a of o.keyframes) {
|
340
|
+
const { value: m } = a, w = `a_${m.animationName}.css`, h = `css/${w}`, g = l(i, h);
|
341
|
+
n.push(w), E(g, m.css);
|
342
|
+
}
|
343
|
+
const p = {};
|
344
|
+
for (const a of o.components) {
|
345
|
+
const { value: m, name: w, src: h } = a, g = m._withBuildContext({
|
346
|
+
name: w,
|
347
|
+
config: d,
|
348
|
+
prod: e
|
349
|
+
});
|
350
|
+
r[g.priority] || (r[g.priority] = []), r[g.priority].push(g.cssFileName), d.importStrategy === "component" && (p[h] ? p[h].push(g.cssFileName) : p[h] = [g.cssFileName]);
|
351
|
+
const j = `css/${g.cssFileName}`, $ = l(i, j);
|
352
|
+
E($, g.css);
|
353
|
+
}
|
354
|
+
d.importStrategy === "component" && Object.entries(p).forEach(([a, m]) => {
|
355
|
+
const w = m.map((b) => `@import url('./${b}');`).join(`
|
356
|
+
`), h = H(a, 6), g = q(a), j = R(g.name), $ = l(i, `css/f_${j}-${h}.css`);
|
357
|
+
E($, w);
|
358
|
+
});
|
359
|
+
const x = n.map((a) => `@import url('./css/${a}');`).join(`
|
360
|
+
`);
|
361
|
+
let y = `@layer reset, global, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
362
|
+
|
363
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((a) => {
|
364
|
+
try {
|
365
|
+
return M(l(i, "css", a), "utf8").length > 0;
|
366
|
+
} catch {
|
367
|
+
return !1;
|
368
|
+
}
|
369
|
+
}).map((a) => `@import url('./css/${a}');`).join(`
|
370
|
+
`)}
|
371
|
+
${x}`;
|
372
|
+
if (d.importStrategy !== "component") {
|
373
|
+
const a = r.reduce((m, w, h) => {
|
374
|
+
const g = w.reduce((C, V) => {
|
375
|
+
var J;
|
376
|
+
const P = l(i, "css", V), Z = M(P, "utf8"), A = ((J = /.*-([^-]+)-\d+.css/.exec(V)) == null ? void 0 : J.at(1)) || H(P, 6);
|
377
|
+
return C.includes(A) ? C : `${C}
|
378
|
+
/*start:${A}*/
|
379
|
+
${Z}
|
380
|
+
/*end:${A}*/
|
381
|
+
`;
|
382
|
+
}, ""), j = `l_${h}.css`, $ = l(i, "css", j), b = `@layer l${h} { ${g}
|
383
|
+
}`;
|
384
|
+
return E($, b), `${m}
|
385
|
+
@import url('./css/${j}');`;
|
386
|
+
}, "");
|
387
|
+
y += a;
|
388
|
+
}
|
389
|
+
E(f, y);
|
390
|
+
const S = Date.now() - s, F = S < 200 ? "🔥" : S < 500 ? "🚀" : S < 1e3 ? "🎉" : S < 2e3 ? "🚗" : S < 5e3 ? "🤔" : "🥴";
|
391
|
+
K.info(`Generated CSS in ${S}ms! ${F}`);
|
392
|
+
} catch (s) {
|
393
|
+
console.error(s);
|
394
|
+
}
|
395
|
+
}, At = async (t, e) => {
|
396
|
+
try {
|
397
|
+
const s = await z(t);
|
398
|
+
if (U(e)) {
|
399
|
+
const r = [], i = await v(t), f = await Y(t, e, s);
|
400
|
+
Object.entries(f).forEach(([u, o]) => {
|
401
|
+
if (o.isKeyframes && o.css) {
|
402
|
+
const D = `css/${`a_${o.animationName}.css`}`, N = l(s, D);
|
403
|
+
E(N, o.css);
|
404
|
+
return;
|
405
|
+
}
|
406
|
+
if (!o.generator) return;
|
407
|
+
const c = o.generator._withBuildContext({
|
408
|
+
name: u,
|
409
|
+
config: i
|
410
|
+
}), d = `css/${c.cssFileName}`, p = l(s, d);
|
411
|
+
E(p, c.css), r[c.priority] || (r[c.priority] = []), r[c.priority].push(c.cssFileName);
|
412
|
+
}), i.importStrategy !== "component" && r.forEach((u, o) => {
|
413
|
+
const c = `l_${o}.css`, d = l(s, "css", c);
|
414
|
+
let p = M(d, "utf8");
|
415
|
+
u.forEach((x) => {
|
416
|
+
var y;
|
417
|
+
const D = l(s, "css", x), N = ((y = /.*-([^-]+)-\d+.css/.exec(x)) == null ? void 0 : y.at(1)) || H(D, 6);
|
418
|
+
if (!p.includes(N)) {
|
419
|
+
const k = M(D, "utf8"), S = `/*start:${N}*/
|
420
|
+
${k}
|
421
|
+
/*end:${N}*/
|
422
|
+
`;
|
423
|
+
p = `${p.replace(/\}$/, "")}
|
424
|
+
${S}
|
425
|
+
}`;
|
426
|
+
}
|
427
|
+
}), E(d, p);
|
428
|
+
});
|
429
|
+
}
|
430
|
+
} catch (s) {
|
431
|
+
console.error(s);
|
432
|
+
}
|
433
|
+
}, Jt = async (t, e, s = dt()) => {
|
434
|
+
try {
|
435
|
+
const n = await z(t);
|
436
|
+
if (U(e)) {
|
437
|
+
const i = M(e, "utf8");
|
438
|
+
i.replace(/^(?!export\s)const\s.*/gm, (d) => `export ${d}`) !== i && await $t(e, i);
|
439
|
+
const u = await v(t), o = await Y(t, e, n);
|
440
|
+
let c = i;
|
441
|
+
if (Object.entries(o).forEach(([d, p]) => {
|
442
|
+
var $;
|
443
|
+
if (p.isKeyframes || !p.generator) return;
|
444
|
+
const x = p.generator._withBuildContext({
|
445
|
+
name: d,
|
446
|
+
config: u,
|
447
|
+
prod: s
|
448
|
+
}), D = new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(i);
|
449
|
+
if (!D) return console.error("Could not find the original declaration");
|
450
|
+
const N = ($ = D.at(1)) == null ? void 0 : $.trim(), T = new RegExp(`\\s${d}[=\\s]+styled\\(`, "g").exec(c);
|
451
|
+
if (!T) return console.error("Could not find the original declaration");
|
452
|
+
const { index: y } = T;
|
453
|
+
let k = !1;
|
454
|
+
const S = setTimeout(() => k = !0, 5e3);
|
455
|
+
let F = 0, a = !1, m = 0;
|
456
|
+
for (; !a && !k; ) {
|
457
|
+
const b = c[y + F];
|
458
|
+
b === "(" && m++, b === ")" && m--, m === 0 && b === ")" && (a = !0), F > c.length && (k = !0), F++;
|
459
|
+
}
|
460
|
+
if (!k) clearTimeout(S);
|
461
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
462
|
+
const w = y + F, h = c.slice(y, w), g = c, j = ` ${d} = styled(${N}, "${x.classNames}", ${JSON.stringify(x.props)});`;
|
463
|
+
c = c.replace(h, j), g === c && console.error("Minimize file failed to change content", { name: d, tagName: N });
|
464
|
+
}), u.importStrategy === "component") {
|
465
|
+
const d = H(e, 6), p = q(e);
|
466
|
+
c = `import '../../saltygen/css/${`f_${R(p.name)}-${d}.css`}';
|
467
|
+
${c}`;
|
468
|
+
}
|
469
|
+
return c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
|
470
|
+
}
|
471
|
+
} catch (n) {
|
472
|
+
console.error("Error in minimizeFile:", n);
|
473
|
+
}
|
474
|
+
};
|
475
|
+
export {
|
476
|
+
At as a,
|
477
|
+
Rt as g,
|
478
|
+
U as i,
|
479
|
+
Jt as m,
|
480
|
+
Nt as s
|
481
|
+
};
|
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 p=require("path"),t=require("./index-a4KtTJRO.cjs"),v=require("fs/promises"),F=require("fs"),S=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 r=await v.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(r)},g=(e,s,i=!1,r=!1)=>{var o,u,c;(u=(o=e.module)==null?void 0:o.rules)==null||u.push({test:t.saltyFileRegExp(),use:[{loader:p.resolve(__dirname,r?"./loader.cjs":"./loader.js"),options:{dir:s}}]}),i||(c=e.plugins)==null||c.push({apply:y=>{let l=!1,a=!1;y.hooks.watchRun.tapAsync({name:"generateCss"},async(f,w)=>{if(l)return;l=!0,a=!1,await t.generateCss(s);const h=F.watch(s,{recursive:!0},async(C,n)=>{const d=await S(n);d&&!a?(a=!0,f.watching?(console.log("Restarting server"),l=!1,f.watching.invalidate(),h.close()):console.warn("Could not invalidate watcher and restart server")):!d&&!a&&t.isSaltyFile(n)&&await t.generateFile(s,n)});w()})}})};exports.default=g;exports.saltyPlugin=g;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -1,225 +1,39 @@
|
|
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 w } from "path";
|
2
|
+
import { i as d, s as h, g as m, a as v } from "./index-jvM0uSOz.js";
|
3
|
+
import { readFile as F } from "fs/promises";
|
4
|
+
import { watch as C } from "fs";
|
5
|
+
const R = async (e) => {
|
6
|
+
if (!e || e.includes("node_modules") || e.includes("saltygen")) return !1;
|
7
|
+
if (e.includes("salty.config")) return !0;
|
8
|
+
if (!d(e)) return !1;
|
9
|
+
const a = await F(e, "utf-8");
|
10
|
+
return !!/.+define[A-Z]\w+/.test(a);
|
11
|
+
}, E = (e, s, n = !1, a = !1) => {
|
12
|
+
var i, o, u;
|
13
|
+
(o = (i = e.module) == null ? void 0 : i.rules) == null || o.push({
|
14
|
+
test: h(),
|
209
15
|
use: [
|
210
16
|
{
|
211
|
-
loader:
|
17
|
+
loader: w(__dirname, a ? "./loader.cjs" : "./loader.js"),
|
212
18
|
options: { dir: s }
|
213
19
|
}
|
214
20
|
]
|
215
|
-
}), (
|
216
|
-
apply: (
|
217
|
-
|
218
|
-
|
21
|
+
}), n || (u = e.plugins) == null || u.push({
|
22
|
+
apply: (g) => {
|
23
|
+
let r = !1, t = !1;
|
24
|
+
g.hooks.watchRun.tapAsync({ name: "generateCss" }, async (c, y) => {
|
25
|
+
if (r) return;
|
26
|
+
r = !0, t = !1, await m(s);
|
27
|
+
const p = C(s, { recursive: !0 }, async (S, l) => {
|
28
|
+
const f = await R(l);
|
29
|
+
f && !t ? (t = !0, c.watching ? (console.log("Restarting server"), r = !1, c.watching.invalidate(), p.close()) : console.warn("Could not invalidate watcher and restart server")) : !f && !t && d(l) && await v(s, l);
|
30
|
+
});
|
31
|
+
y();
|
219
32
|
});
|
220
33
|
}
|
221
34
|
});
|
222
35
|
};
|
223
36
|
export {
|
224
|
-
|
37
|
+
E as default,
|
38
|
+
E as saltyPlugin
|
225
39
|
};
|
package/loader.cjs
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
"use strict";const i=require("./index-a4KtTJRO.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.171",
|
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.171",
|
33
38
|
"webpack": ">=5.x"
|
34
39
|
}
|
35
40
|
}
|