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