@salty-css/vite 0.0.1-alpha.8 → 0.0.1-alpha.80
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 +105 -26
- package/index.cjs +14 -14
- package/index.d.ts +1 -0
- package/index.js +220 -186
- package/package.json +11 -2
package/README.md
CHANGED
@@ -1,15 +1,90 @@
|
|
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
|
+
### Packages
|
20
|
+
|
21
|
+
Note: 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](#nextjs) → `npm install @salty-css/next` + [Next.js install guide](#nextjs) + [Next.js example app](https://github.com/margarita-form/salty-css-website)
|
24
|
+
- [React](#react) → `npm install @salty-css/react` + [React install guide](#react) + [React example code](#code-examples)
|
25
|
+
- [Vite](#vite) → `npm install @salty-css/vite` + [(Vite install guide)](#vite)
|
26
|
+
- [Webpack](https://www.npmjs.com/package/@salty-css/webpack) → `npm install @salty-css/webpack` + Guide coming soon
|
27
|
+
- [ESLint](https://www.npmjs.com/package/@salty-css/eslint-plugin-core) → `npm install @salty-css/eslint-plugin-core` + Guide coming soon
|
28
|
+
- [Core](https://www.npmjs.com/package/@salty-css/react) → `npm install @salty-css/core` (This package contains code for internal use)
|
29
|
+
|
30
|
+
### Add Salty CSS to your project with `salty-css` CLI
|
31
|
+
|
32
|
+
#### Initialize Salty CSS for a project
|
33
|
+
|
34
|
+
In your existing repository run `npx salty-css init [directory]` which installs required salty-css packages to the current directory, detects framework in use (current support for vite and next.js) and creates project files to the provided directory. Directory can be left blank if you want files to be created to the current directory. Init will also create `.saltyrc` which contains some metadata for future CLI commands.
|
35
|
+
|
36
|
+
#### Create components
|
37
|
+
|
38
|
+
Components can be created with `npx salty-css generate [filePath]` which then creates a new Salty CSS component file to the specified path. Additional options like `--dir, --tag, --name and --className` are also supported. Read more about them with `npx salty-css generate --help`
|
39
|
+
|
40
|
+
#### Build / Compile Salty CSS
|
41
|
+
|
42
|
+
If you want to manually build your project that can be done by running `npx salty-css build [directory]`. Directory is not required as CLI can use default directory defined in `.saltyrc`. Note that build generates css files but Vite / Webpack plugin is still required for full support.
|
43
|
+
|
44
|
+
#### Update Salty CSS packages
|
45
|
+
|
46
|
+
To ease the pain of package updates all Salty CSS packages can be updated with `npx salty-css update`
|
47
|
+
|
48
|
+
### Manual work
|
49
|
+
|
50
|
+
#### Next.js
|
51
|
+
|
52
|
+
1. For Next.js support install `npm i @salty-css/next @salty-css/core @salty-css/react`
|
53
|
+
2. Create `salty.config.ts` to your app directory
|
54
|
+
3. Add Salty CSS plugin to next.js config
|
55
|
+
|
56
|
+
- **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);`
|
57
|
+
- **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);`
|
58
|
+
|
59
|
+
4. Make sure that `salty.config.ts` and `next.config.ts` are in the same folder!
|
60
|
+
5. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
|
61
|
+
6. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
|
62
|
+
|
63
|
+
[Check out Next.js demo project](https://github.com/margarita-form/salty-css-website) or [react example code](#code-examples)
|
64
|
+
|
65
|
+
#### React
|
66
|
+
|
67
|
+
1. Install related dependencies: `npm i @salty-css/core @salty-css/react`
|
68
|
+
2. Create `salty.config.ts` to your app directory
|
69
|
+
3. Configure your build tool to support Salty CSS ([Vite](#vite) or Webpack)
|
70
|
+
|
71
|
+
[Check out react example code](#code-examples)
|
72
|
+
|
73
|
+
#### Vite
|
74
|
+
|
75
|
+
1. For Vite support install `npm i @salty-css/vite @salty-css/core`
|
76
|
+
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
|
77
|
+
3. Make sure that `salty.config.ts` and `vite.config.ts` are in the same folder!
|
78
|
+
4. Build `saltygen` directory by running your app once or with cli `npx salty-css build [directory]`
|
79
|
+
5. Import global styles from `saltygen/index.css` to some global css file with `@import 'insert_path_to_index_css';`.
|
80
|
+
|
81
|
+
### Create components
|
82
|
+
|
83
|
+
1. Create salty components with styled only inside files that end with `.css.ts`, `.salty.ts` `.styled.ts` or `.styles.ts`
|
84
|
+
|
85
|
+
## Code examples
|
86
|
+
|
87
|
+
### Basic usage example with Button
|
13
88
|
|
14
89
|
**Salty config**
|
15
90
|
|
@@ -54,8 +129,10 @@ export const IndexPage = () => {
|
|
54
129
|
import { styled } from '@salty-css/react/styled';
|
55
130
|
|
56
131
|
export const Wrapper = styled('div', {
|
57
|
-
|
58
|
-
|
132
|
+
base: {
|
133
|
+
display: 'block',
|
134
|
+
padding: '2vw',
|
135
|
+
},
|
59
136
|
});
|
60
137
|
```
|
61
138
|
|
@@ -65,22 +142,24 @@ export const Wrapper = styled('div', {
|
|
65
142
|
import { styled } from '@salty-css/react/styled';
|
66
143
|
|
67
144
|
export const Button = styled('button', {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
145
|
+
base: {
|
146
|
+
display: 'block',
|
147
|
+
padding: `0.6em 1.2em`,
|
148
|
+
border: '1px solid currentColor',
|
149
|
+
background: 'transparent',
|
150
|
+
color: 'currentColor/40',
|
151
|
+
cursor: 'pointer',
|
152
|
+
transition: '200ms',
|
153
|
+
textDecoration: 'none',
|
154
|
+
'&:hover': {
|
155
|
+
background: 'black',
|
156
|
+
borderColor: 'black',
|
157
|
+
color: 'white',
|
158
|
+
},
|
159
|
+
'&:disabled': {
|
160
|
+
opacity: 0.25,
|
161
|
+
pointerEvents: 'none',
|
162
|
+
},
|
84
163
|
},
|
85
164
|
variants: {
|
86
165
|
variant: {
|
package/index.cjs
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
"use strict";Object.
|
2
|
-
${
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const tt=require("esbuild"),et=require("child_process"),u=require("path"),d=require("fs"),B=require("fs/promises");var _=typeof document<"u"?document.currentScript:null;function st(t){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const s in t)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(t,s);Object.defineProperty(e,s,n.get?n:{enumerable:!0,get:()=>t[s]})}}return e.default=t,Object.freeze(e)}const Z=st(tt),W=t=>String.fromCharCode(t+(t>25?39:97)),nt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=W(n%52)+s;return s=W(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},ot=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},R=(t,e=3)=>{const s=ot(5381,JSON.stringify(t))>>>0;return nt(s,e)};function D(t){return t?typeof t!="string"?D(String(t)):t.replace(/\s/g,"-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(e,s)=>(s>0?"-":"")+e.toLowerCase()):""}const rt=(t,e)=>{if(typeof t!="string")return{result:t};if(!e)return{result:t};const s=[];return Object.values(e).forEach(n=>{const{pattern:o,transform:y}=n;t=t.replace(o,g=>{const{value:a,css:c}=y(g);return c&&s.push(c),a})}),{result:t,additionalCss:s}},z=t=>typeof t!="string"?{result:t}:/\{[^{}]+\}/g.test(t)?{result:t.replace(/\{([^{}]+)\}/g,(...n)=>`var(--${D(n[1].replaceAll(".","-"))})`)}:{result:t},M=(t,e,s,n)=>{if(!t)return"";const o=[],y=Object.entries(t).reduce((a,[c,r])=>{const f=c.trim();if(typeof r=="function"&&(r=r()),typeof r=="object"){if(!r)return a;if(f==="variants")return Object.entries(r).forEach(([i,p])=>{p&&Object.entries(p).forEach(([j,m])=>{if(!m)return;const F=`${e}.${i}-${j}`,$=M(m,F);o.push($)})}),a;if(f==="defaultVariants")return a;if(f==="compoundVariants")return r.forEach(i=>{const{css:p,...j}=i,m=Object.entries(j).reduce(($,[w,T])=>`${$}.${w}-${T}`,e),F=M(p,m);o.push(F)}),a;if(f.startsWith("@")){const i=M(r,e),p=`${f} {
|
2
|
+
${i.replace(`
|
3
3
|
`,`
|
4
4
|
`)}
|
5
|
-
}`;return o.push(
|
6
|
-
`);if(!
|
7
|
-
`)},
|
8
|
-
`)};
|
9
|
-
`),
|
10
|
-
`);let
|
5
|
+
}`;return o.push(p),a}const h=c.includes("&")?f.replace("&",e):f.startsWith(":")?`${e}${f}`:`${e} ${f}`,C=M(r,h);return o.push(C),a}const x=f.startsWith("-")?f:D(f),b=(h,C=";")=>a=`${a}${h}${C}`,l=h=>b(`${x}:${h}`);if(typeof r=="number")return l(r);if(typeof r!="string")if("toString"in r)r=r.toString();else return a;const{modifiers:S}={},k=function*(){yield z(r),yield rt(r,S)}();for(const{result:h,additionalCss:C=[]}of k)r=h,C.forEach(i=>{const p=M(i,"");b(p,"")});return l(r)},"");if(!y)return o.join(`
|
6
|
+
`);if(!e)return y;let g="";return g=`${e} { ${y} }`,[g,...o].join(`
|
7
|
+
`)},U=(t,e=[])=>{if(!t)return"";const s=[],n={};if(Object.entries(t).forEach(([o,y])=>{if(typeof y=="object"){if(!y)return;const g=o.trim(),a=U(y,[...e,g]);s.push(a)}else n[o]=y}),Object.keys(n).length){const o=e.map(D).join("-"),y=M(n,`.${o}`);s.push(y)}return s.join(`
|
8
|
+
`)},H=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=u.join(t,"package.json");return d.existsSync(e)?e:H(u.join(t,".."))},it=async t=>{const e=H(t);return await B.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},ct=async t=>{const e=await it(t);if(e)return e.type};let O;const L=async t=>{if(O)return O;const e=await ct(t);return e==="module"?O="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:_&&_.tagName.toUpperCase()==="SCRIPT"&&_.src||new URL("index.cjs",document.baseURI).href).endsWith(".cjs"))&&(O="cjs"),O||"esm"},J={externalModules:[]},K=t=>{if(J.externalModules.length>0)return J.externalModules;const e=u.join(t,"salty.config.ts"),n=d.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!n)return[];const o=n[1].split(",").map(y=>y.replace(/['"`]/g,"").trim());return J.externalModules=o,o},V=t=>u.join(t,"./saltygen"),at=["salty","css","styles","styled"],lt=(t=[])=>new RegExp(`\\.(${[...at,...t].join("|")})\\.`),E=(t,e=[])=>lt(e).test(t),ut=async t=>{const e=V(t),s=u.join(t,"salty.config.ts"),n=u.join(e,"salty.config.js"),o=await L(t),y=K(t);await Z.build({entryPoints:[s],minify:!0,treeShaking:!0,bundle:!0,outfile:n,format:o,external:y});const g=Date.now(),{config:a}=await import(`${n}?t=${g}`);return a},G=async t=>{const e=await ut(t),s=new Set,n=(i,p=[])=>i?Object.entries(i).flatMap(([j,m])=>{if(!m)return;if(typeof m=="object")return n(m,[...p,j]);const F=[...p,j].join(".");s.add(`"${F}"`);const $=[...p.map(D),D(j)].join("-"),{result:w}=z(m);return`--${$}: ${w};`}):[],o=i=>i?Object.entries(i).flatMap(([p,j])=>{const m=n(j);return p==="base"?m.join(""):`${p} { ${m.join("")} }`}):[],y=i=>i?Object.entries(i).flatMap(([p,j])=>Object.entries(j).flatMap(([m,F])=>{const $=n(F,[p]),w=`.${p}-${m}, [data-${p}="${m}"]`,T=$.join("");return`${w} { ${T} }`})):[],g=n(e.variables),a=o(e.responsiveVariables),c=y(e.conditionalVariables),r=V(t),f=u.join(r,"css/variables.css"),x=`:root { ${g.join("")} ${a.join("")} } ${c.join("")}`;d.writeFileSync(f,x);const b=u.join(r,"types/css-tokens.d.ts"),S=`type VariableTokens = ${[...s].join("|")||'""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;d.writeFileSync(b,S);const P=u.join(r,"css/global.css"),k=M(e.global,"");d.writeFileSync(P,k);const h=u.join(r,"css/templates.css"),C=U(e.templates);d.writeFileSync(h,C)},A=async(t,e,s)=>{const n=R(e),o=u.join(s,"js",n+".js"),y=await L(t),g=K(t);await Z.build({entryPoints:[e],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:y,target:["es2022"],keepNames:!0,external:g});const a=Date.now();return await import(`${o}?t=${a}`)},q=async t=>{const e=V(t),s=u.join(e,"salty.config.js"),{config:n}=await import(s);return n},ft=async t=>{try{const e=[],s=[],n=V(t),o=u.join(n,"index.css");(()=>{d.existsSync(n)&&et.execSync("rm -rf "+n),d.mkdirSync(n),d.mkdirSync(u.join(n,"css")),d.mkdirSync(u.join(n,"types"))})(),await G(t);const g=await q(t);async function a(l,S){const P=["node_modules","saltygen"],k=d.statSync(l);if(k.isDirectory()){const h=d.readdirSync(l);if(P.some(i=>l.includes(i)))return;await Promise.all(h.map(i=>a(u.join(l,i),u.join(S,i))))}else if(k.isFile()&&E(l)){const C=await A(t,l,n),i=[];Object.entries(C).forEach(([F,$])=>{if($.isKeyframes&&$.css){const I=`${$.animationName}.css`,Q=`css/${I}`,v=u.join(n,Q);e.push(I),d.writeFileSync(v,$.css);return}if(!$.generator)return;const w=$.generator._withBuildContext({name:F,config:g}),T=`${w.hash}-${w.priority}.css`;s[w.priority]||(s[w.priority]=[]),s[w.priority].push(T),i.push(T);const N=`css/${T}`,Y=u.join(n,N);d.writeFileSync(Y,w.css)});const p=i.map(F=>`@import url('./${F}');`).join(`
|
9
|
+
`),j=R(l,6),m=u.join(n,`css/${j}.css`);d.writeFileSync(m,p)}}await a(t,n);const c=e.map(l=>`@import url('./css/${l}');`).join(`
|
10
|
+
`);let b=`@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
11
11
|
|
12
|
-
${["
|
12
|
+
${["variables.css","global.css","templates.css"].filter(l=>{try{return d.readFileSync(u.join(n,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
13
13
|
`)}
|
14
|
-
${
|
15
|
-
`);
|
16
|
-
`),r=
|
17
|
-
`);d.writeFileSync(o,
|
18
|
-
${
|
14
|
+
${c}`;if(g.importStrategy!=="component"){const l=s.flat().map(S=>`@import url('./css/${S}');`).join(`
|
15
|
+
`);b+=l}d.writeFileSync(o,b)}catch(e){console.error(e)}},pt=async(t,e)=>{try{const s=[],n=u.join(t,"./saltygen"),o=u.join(n,"index.css");if(E(e)){const g=await q(t),a=await A(t,e,n);Object.entries(a).forEach(([b,l])=>{if(!l.generator)return;const S=l.generator._withBuildContext({name:b,config:g}),P=`${S.hash}-${S.priority}.css`,k=`css/${P}`,h=u.join(n,k);s.push(P),d.writeFileSync(h,S.css)});const c=d.readFileSync(o,"utf8").split(`
|
16
|
+
`),r=s.map(b=>`@import url('../saltygen/css/${b}');`),x=[...new Set([...c,...r])].join(`
|
17
|
+
`);d.writeFileSync(o,x)}}catch(s){console.error(s)}},yt=async(t,e)=>{try{const s=u.join(t,"./saltygen");if(E(e)){const o=d.readFileSync(e,"utf8");o.replace(/^(?!export\s)const\s.*/gm,f=>`export ${f}`)!==o&&await B.writeFile(e,o);const g=await q(t),a=await A(t,e,s);let c=o;Object.entries(a).forEach(([f,x])=>{var T;if(x.isKeyframes||!x.generator)return;const b=x.generator._withBuildContext({name:f,config:g}),l=new RegExp(`\\s${f}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!l)return console.error("Could not find the original declaration");const S=(T=l.at(1))==null?void 0:T.trim(),P=new RegExp(`\\s${f}[=\\s]+styled\\(`,"g").exec(c);if(!P)return console.error("Could not find the original declaration");const{index:k}=P;let h=!1;const C=setTimeout(()=>h=!0,5e3);let i=0,p=!1,j=0;for(;!p&&!h;){const N=c[k+i];N==="("&&j++,N===")"&&j--,j===0&&N===")"&&(p=!0),i>c.length&&(h=!0),i++}if(!h)clearTimeout(C);else throw new Error("Failed to find the end of the styled call and timed out");const m=k+i,F=c.slice(k,m),$=c,w=` ${f} = styled(${S}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;c=c.replace(F,w),$===c&&console.error("Minimize file failed to change content",{name:f,tagName:S})});const r=R(e,6);return g.importStrategy==="component"&&(c=`import '../../saltygen/css/${r}.css';
|
18
|
+
${c}`),c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(s){console.error("Error in minimizeFile:",s)}},X=t=>({name:"stylegen",buildStart:()=>ft(t),load:async e=>{if(E(e))return await yt(t,e)},watchChange:{handler:async e=>{E(e)&&await pt(t,e),e.includes("salty.config")&&await G(t)}}});exports.default=X;exports.saltyPlugin=X;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
@@ -1,279 +1,313 @@
|
|
1
|
-
import * as
|
2
|
-
import
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import {
|
6
|
-
|
7
|
-
const Z = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), Y = (t, s) => {
|
1
|
+
import * as z from "esbuild";
|
2
|
+
import { execSync as tt } from "child_process";
|
3
|
+
import { join as f } from "path";
|
4
|
+
import { existsSync as H, writeFileSync as M, mkdirSync as A, statSync as st, readdirSync as et, readFileSync as V } from "fs";
|
5
|
+
import { readFile as nt, writeFile as ot } from "fs/promises";
|
6
|
+
const Z = (t) => String.fromCharCode(t + (t > 25 ? 39 : 97)), rt = (t, s) => {
|
8
7
|
let e = "", n;
|
9
8
|
for (n = Math.abs(t); n > 52; n = n / 52 | 0) e = Z(n % 52) + e;
|
10
9
|
return e = Z(n % 52) + e, e.length < s ? e = e.padStart(s, "a") : e.length > s && (e = e.slice(-s)), e;
|
11
|
-
},
|
10
|
+
}, ct = (t, s) => {
|
12
11
|
let e = s.length;
|
13
12
|
for (; e; ) t = t * 33 ^ s.charCodeAt(--e);
|
14
13
|
return t;
|
15
|
-
},
|
16
|
-
const e =
|
17
|
-
return
|
14
|
+
}, _ = (t, s = 3) => {
|
15
|
+
const e = ct(5381, JSON.stringify(t)) >>> 0;
|
16
|
+
return rt(e, s);
|
18
17
|
};
|
19
|
-
function
|
20
|
-
return t ? typeof t != "string" ? String(t) : t.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (s, e) => (e > 0 ? "-" : "") + s.toLowerCase()) : "";
|
18
|
+
function E(t) {
|
19
|
+
return t ? typeof t != "string" ? E(String(t)) : t.replace(/\s/g, "-").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (s, e) => (e > 0 ? "-" : "") + s.toLowerCase()) : "";
|
21
20
|
}
|
22
|
-
const
|
21
|
+
const it = (t, s) => {
|
23
22
|
if (typeof t != "string") return { result: t };
|
24
23
|
if (!s) return { result: t };
|
25
24
|
const e = [];
|
26
25
|
return Object.values(s).forEach((n) => {
|
27
|
-
const { pattern:
|
28
|
-
t = t.replace(
|
29
|
-
const { value: a, css:
|
30
|
-
return
|
26
|
+
const { pattern: o, transform: g } = n;
|
27
|
+
t = t.replace(o, (y) => {
|
28
|
+
const { value: a, css: i } = g(y);
|
29
|
+
return i && e.push(i), a;
|
31
30
|
});
|
32
31
|
}), { result: t, additionalCss: e };
|
33
|
-
},
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
if (
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
}, K = (t) => typeof t != "string" ? { result: t } : /\{[^{}]+\}/g.test(t) ? { result: t.replace(/\{([^{}]+)\}/g, (...n) => `var(--${E(n[1].replaceAll(".", "-"))})`) } : { result: t }, T = (t, s, e, n) => {
|
33
|
+
if (!t) return "";
|
34
|
+
const o = [], g = Object.entries(t).reduce((a, [i, r]) => {
|
35
|
+
const u = i.trim();
|
36
|
+
if (typeof r == "function" && (r = r()), typeof r == "object") {
|
37
|
+
if (!r) return a;
|
38
|
+
if (u === "variants")
|
39
|
+
return Object.entries(r).forEach(([c, p]) => {
|
40
|
+
p && Object.entries(p).forEach(([m, h]) => {
|
41
|
+
if (!h) return;
|
42
|
+
const S = `${s}.${c}-${m}`, $ = T(h, S);
|
43
|
+
o.push($);
|
44
44
|
});
|
45
45
|
}), a;
|
46
|
-
if (
|
46
|
+
if (u === "defaultVariants")
|
47
47
|
return a;
|
48
|
-
if (
|
49
|
-
return
|
50
|
-
const { css:
|
51
|
-
|
48
|
+
if (u === "compoundVariants")
|
49
|
+
return r.forEach((c) => {
|
50
|
+
const { css: p, ...m } = c, h = Object.entries(m).reduce(($, [j, P]) => `${$}.${j}-${P}`, s), S = T(p, h);
|
51
|
+
o.push(S);
|
52
52
|
}), a;
|
53
|
-
if (
|
54
|
-
const
|
55
|
-
${
|
53
|
+
if (u.startsWith("@")) {
|
54
|
+
const c = T(r, s), p = `${u} {
|
55
|
+
${c.replace(`
|
56
56
|
`, `
|
57
57
|
`)}
|
58
58
|
}`;
|
59
|
-
return
|
59
|
+
return o.push(p), a;
|
60
60
|
}
|
61
|
-
const d =
|
62
|
-
return
|
61
|
+
const d = i.includes("&") ? u.replace("&", s) : u.startsWith(":") ? `${s}${u}` : `${s} ${u}`, k = T(r, d);
|
62
|
+
return o.push(k), a;
|
63
63
|
}
|
64
|
-
const
|
65
|
-
if (typeof
|
66
|
-
if (typeof
|
67
|
-
if ("toString" in
|
64
|
+
const x = u.startsWith("-") ? u : E(u), b = (d, k = ";") => a = `${a}${d}${k}`, l = (d) => b(`${x}:${d}`);
|
65
|
+
if (typeof r == "number") return l(r);
|
66
|
+
if (typeof r != "string")
|
67
|
+
if ("toString" in r) r = r.toString();
|
68
68
|
else return a;
|
69
|
-
const { modifiers:
|
70
|
-
yield
|
69
|
+
const { modifiers: w } = {}, F = function* () {
|
70
|
+
yield K(r), yield it(r, w);
|
71
71
|
}();
|
72
|
-
for (const { result: d, additionalCss:
|
73
|
-
|
74
|
-
const
|
75
|
-
|
72
|
+
for (const { result: d, additionalCss: k = [] } of F)
|
73
|
+
r = d, k.forEach((c) => {
|
74
|
+
const p = T(c, "");
|
75
|
+
b(p, "");
|
76
76
|
});
|
77
|
-
return
|
77
|
+
return l(r);
|
78
78
|
}, "");
|
79
|
-
if (!g) return
|
79
|
+
if (!g) return o.join(`
|
80
80
|
`);
|
81
81
|
if (!s) return g;
|
82
|
-
let
|
83
|
-
return
|
82
|
+
let y = "";
|
83
|
+
return y = `${s} { ${g} }`, [y, ...o].join(`
|
84
84
|
`);
|
85
|
-
},
|
85
|
+
}, q = (t, s = []) => {
|
86
|
+
if (!t) return "";
|
86
87
|
const e = [], n = {};
|
87
|
-
if (Object.entries(t).forEach(([
|
88
|
+
if (Object.entries(t).forEach(([o, g]) => {
|
88
89
|
if (typeof g == "object") {
|
89
90
|
if (!g) return;
|
90
|
-
const
|
91
|
+
const y = o.trim(), a = q(g, [...s, y]);
|
91
92
|
e.push(a);
|
92
93
|
} else
|
93
|
-
n[
|
94
|
+
n[o] = g;
|
94
95
|
}), Object.keys(n).length) {
|
95
|
-
const
|
96
|
+
const o = s.map(E).join("-"), g = T(n, `.${o}`);
|
96
97
|
e.push(g);
|
97
98
|
}
|
98
99
|
return e.join(`
|
99
100
|
`);
|
101
|
+
}, G = (t) => {
|
102
|
+
if (!t || t === "/") throw new Error("Could not find package.json file");
|
103
|
+
const s = f(t, "package.json");
|
104
|
+
return H(s) ? s : G(f(t, ".."));
|
105
|
+
}, at = async (t) => {
|
106
|
+
const s = G(t);
|
107
|
+
return await nt(s, "utf-8").then(JSON.parse).catch(() => {
|
108
|
+
});
|
109
|
+
}, lt = async (t) => {
|
110
|
+
const s = await at(t);
|
111
|
+
if (s)
|
112
|
+
return s.type;
|
100
113
|
};
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
114
|
+
let D;
|
115
|
+
const L = async (t) => {
|
116
|
+
if (D) return D;
|
117
|
+
const s = await lt(t);
|
118
|
+
return s === "module" ? D = "esm" : (s === "commonjs" || import.meta.url.endsWith(".cjs")) && (D = "cjs"), D || "esm";
|
119
|
+
}, R = {
|
120
|
+
externalModules: []
|
121
|
+
}, U = (t) => {
|
122
|
+
if (R.externalModules.length > 0) return R.externalModules;
|
123
|
+
const s = f(t, "salty.config.ts"), n = V(s, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
124
|
+
if (!n) return [];
|
125
|
+
const o = n[1].split(",").map((g) => g.replace(/['"`]/g, "").trim());
|
126
|
+
return R.externalModules = o, o;
|
127
|
+
}, J = (t) => f(t, "./saltygen"), ft = ["salty", "css", "styles", "styled"], ut = (t = []) => new RegExp(`\\.(${[...ft, ...t].join("|")})\\.`), O = (t, s = []) => ut(s).test(t), pt = async (t) => {
|
128
|
+
const s = J(t), e = f(t, "salty.config.ts"), n = f(s, "salty.config.js"), o = await L(t), g = U(t);
|
129
|
+
await z.build({
|
109
130
|
entryPoints: [e],
|
110
131
|
minify: !0,
|
111
132
|
treeShaking: !0,
|
112
133
|
bundle: !0,
|
113
134
|
outfile: n,
|
114
|
-
format:
|
115
|
-
external:
|
135
|
+
format: o,
|
136
|
+
external: g
|
116
137
|
});
|
117
|
-
const
|
118
|
-
return
|
119
|
-
},
|
120
|
-
const s = await
|
121
|
-
if (!
|
122
|
-
if (typeof
|
123
|
-
const
|
124
|
-
e.add(`"${
|
125
|
-
const
|
126
|
-
return `--${
|
127
|
-
}) : [],
|
128
|
-
const
|
129
|
-
return
|
130
|
-
}) : [], g = (
|
131
|
-
const
|
132
|
-
return `${
|
133
|
-
})) : [],
|
134
|
-
|
135
|
-
const
|
136
|
-
|
137
|
-
const
|
138
|
-
|
139
|
-
const d =
|
140
|
-
|
141
|
-
},
|
142
|
-
const
|
143
|
-
await
|
144
|
-
entryPoints: [
|
138
|
+
const y = Date.now(), { config: a } = await import(`${n}?t=${y}`);
|
139
|
+
return a;
|
140
|
+
}, X = async (t) => {
|
141
|
+
const s = await pt(t), e = /* @__PURE__ */ new Set(), n = (c, p = []) => c ? Object.entries(c).flatMap(([m, h]) => {
|
142
|
+
if (!h) return;
|
143
|
+
if (typeof h == "object") return n(h, [...p, m]);
|
144
|
+
const S = [...p, m].join(".");
|
145
|
+
e.add(`"${S}"`);
|
146
|
+
const $ = [...p.map(E), E(m)].join("-"), { result: j } = K(h);
|
147
|
+
return `--${$}: ${j};`;
|
148
|
+
}) : [], o = (c) => c ? Object.entries(c).flatMap(([p, m]) => {
|
149
|
+
const h = n(m);
|
150
|
+
return p === "base" ? h.join("") : `${p} { ${h.join("")} }`;
|
151
|
+
}) : [], g = (c) => c ? Object.entries(c).flatMap(([p, m]) => Object.entries(m).flatMap(([h, S]) => {
|
152
|
+
const $ = n(S, [p]), j = `.${p}-${h}, [data-${p}="${h}"]`, P = $.join("");
|
153
|
+
return `${j} { ${P} }`;
|
154
|
+
})) : [], y = n(s.variables), a = o(s.responsiveVariables), i = g(s.conditionalVariables), r = J(t), u = f(r, "css/variables.css"), x = `:root { ${y.join("")} ${a.join("")} } ${i.join("")}`;
|
155
|
+
M(u, x);
|
156
|
+
const b = f(r, "types/css-tokens.d.ts"), w = `type VariableTokens = ${[...e].join("|") || '""'}; type PropertyValueToken = \`{\${VariableTokens}}\``;
|
157
|
+
M(b, w);
|
158
|
+
const C = f(r, "css/global.css"), F = T(s.global, "");
|
159
|
+
M(C, F);
|
160
|
+
const d = f(r, "css/templates.css"), k = q(s.templates);
|
161
|
+
M(d, k);
|
162
|
+
}, W = async (t, s, e) => {
|
163
|
+
const n = _(s), o = f(e, "js", n + ".js"), g = await L(t), y = U(t);
|
164
|
+
await z.build({
|
165
|
+
entryPoints: [s],
|
145
166
|
minify: !0,
|
146
167
|
treeShaking: !0,
|
147
168
|
bundle: !0,
|
148
|
-
outfile:
|
149
|
-
format:
|
169
|
+
outfile: o,
|
170
|
+
format: g,
|
150
171
|
target: ["es2022"],
|
151
172
|
keepNames: !0,
|
152
|
-
external:
|
173
|
+
external: y
|
153
174
|
});
|
154
|
-
const
|
155
|
-
return await import(`${
|
156
|
-
},
|
157
|
-
const s =
|
175
|
+
const a = Date.now();
|
176
|
+
return await import(`${o}?t=${a}`);
|
177
|
+
}, B = async (t) => {
|
178
|
+
const s = J(t), e = f(s, "salty.config.js"), { config: n } = await import(e);
|
158
179
|
return n;
|
159
|
-
},
|
180
|
+
}, gt = async (t) => {
|
160
181
|
try {
|
161
|
-
const s = [], e = [], n =
|
182
|
+
const s = [], e = [], n = J(t), o = f(n, "index.css");
|
162
183
|
(() => {
|
163
|
-
|
164
|
-
})(), await
|
165
|
-
const
|
166
|
-
async function a(
|
167
|
-
const
|
168
|
-
if (
|
169
|
-
const
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
184
|
+
H(n) && tt("rm -rf " + n), A(n), A(f(n, "css")), A(f(n, "types"));
|
185
|
+
})(), await X(t);
|
186
|
+
const y = await B(t);
|
187
|
+
async function a(l, w) {
|
188
|
+
const C = ["node_modules", "saltygen"], F = st(l);
|
189
|
+
if (F.isDirectory()) {
|
190
|
+
const d = et(l);
|
191
|
+
if (C.some((c) => l.includes(c))) return;
|
192
|
+
await Promise.all(d.map((c) => a(f(l, c), f(w, c))));
|
193
|
+
} else if (F.isFile() && O(l)) {
|
194
|
+
const k = await W(t, l, n), c = [];
|
195
|
+
Object.entries(k).forEach(([S, $]) => {
|
196
|
+
if ($.isKeyframes && $.css) {
|
197
|
+
const I = `${$.animationName}.css`, Q = `css/${I}`, v = f(n, Q);
|
198
|
+
s.push(I), M(v, $.css);
|
177
199
|
return;
|
178
200
|
}
|
179
|
-
if (
|
180
|
-
const
|
181
|
-
name:
|
182
|
-
config:
|
183
|
-
}),
|
184
|
-
e[
|
185
|
-
const N = `css/${
|
186
|
-
|
201
|
+
if (!$.generator) return;
|
202
|
+
const j = $.generator._withBuildContext({
|
203
|
+
name: S,
|
204
|
+
config: y
|
205
|
+
}), P = `${j.hash}-${j.priority}.css`;
|
206
|
+
e[j.priority] || (e[j.priority] = []), e[j.priority].push(P), c.push(P);
|
207
|
+
const N = `css/${P}`, Y = f(n, N);
|
208
|
+
M(Y, j.css);
|
187
209
|
});
|
188
|
-
const
|
189
|
-
`),
|
190
|
-
|
210
|
+
const p = c.map((S) => `@import url('./${S}');`).join(`
|
211
|
+
`), m = _(l, 6), h = f(n, `css/${m}.css`);
|
212
|
+
M(h, p);
|
191
213
|
}
|
192
214
|
}
|
193
215
|
await a(t, n);
|
194
|
-
const
|
216
|
+
const i = s.map((l) => `@import url('./css/${l}');`).join(`
|
195
217
|
`);
|
196
|
-
let
|
218
|
+
let b = `@layer l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
197
219
|
|
198
|
-
${["
|
220
|
+
${["variables.css", "global.css", "templates.css"].filter((l) => {
|
221
|
+
try {
|
222
|
+
return V(f(n, "css", l), "utf8").length > 0;
|
223
|
+
} catch {
|
224
|
+
return !1;
|
225
|
+
}
|
226
|
+
}).map((l) => `@import url('./css/${l}');`).join(`
|
199
227
|
`)}
|
200
|
-
${
|
201
|
-
if (
|
202
|
-
const
|
228
|
+
${i}`;
|
229
|
+
if (y.importStrategy !== "component") {
|
230
|
+
const l = e.flat().map((w) => `@import url('./css/${w}');`).join(`
|
203
231
|
`);
|
204
|
-
|
232
|
+
b += l;
|
205
233
|
}
|
206
|
-
|
234
|
+
M(o, b);
|
207
235
|
} catch (s) {
|
208
236
|
console.error(s);
|
209
237
|
}
|
210
|
-
},
|
238
|
+
}, yt = async (t, s) => {
|
211
239
|
try {
|
212
|
-
const e = [], n =
|
213
|
-
if (
|
214
|
-
const
|
215
|
-
Object.entries(a).forEach(([
|
216
|
-
if (!
|
217
|
-
const
|
218
|
-
name:
|
219
|
-
config:
|
220
|
-
}),
|
221
|
-
e.push(
|
240
|
+
const e = [], n = f(t, "./saltygen"), o = f(n, "index.css");
|
241
|
+
if (O(s)) {
|
242
|
+
const y = await B(t), a = await W(t, s, n);
|
243
|
+
Object.entries(a).forEach(([b, l]) => {
|
244
|
+
if (!l.generator) return;
|
245
|
+
const w = l.generator._withBuildContext({
|
246
|
+
name: b,
|
247
|
+
config: y
|
248
|
+
}), C = `${w.hash}-${w.priority}.css`, F = `css/${C}`, d = f(n, F);
|
249
|
+
e.push(C), M(d, w.css);
|
222
250
|
});
|
223
|
-
const
|
224
|
-
`),
|
251
|
+
const i = V(o, "utf8").split(`
|
252
|
+
`), r = e.map((b) => `@import url('../saltygen/css/${b}');`), x = [.../* @__PURE__ */ new Set([...i, ...r])].join(`
|
225
253
|
`);
|
226
|
-
|
254
|
+
M(o, x);
|
227
255
|
}
|
228
256
|
} catch (e) {
|
229
257
|
console.error(e);
|
230
258
|
}
|
231
|
-
},
|
259
|
+
}, dt = async (t, s) => {
|
232
260
|
try {
|
233
|
-
const e =
|
234
|
-
if (
|
235
|
-
|
236
|
-
|
237
|
-
const
|
238
|
-
let
|
239
|
-
Object.entries(a).forEach(([
|
240
|
-
var
|
241
|
-
if (
|
242
|
-
|
243
|
-
|
261
|
+
const e = f(t, "./saltygen");
|
262
|
+
if (O(s)) {
|
263
|
+
const o = V(s, "utf8");
|
264
|
+
o.replace(/^(?!export\s)const\s.*/gm, (u) => `export ${u}`) !== o && await ot(s, o);
|
265
|
+
const y = await B(t), a = await W(t, s, e);
|
266
|
+
let i = o;
|
267
|
+
Object.entries(a).forEach(([u, x]) => {
|
268
|
+
var P;
|
269
|
+
if (x.isKeyframes || !x.generator) return;
|
270
|
+
const b = x.generator._withBuildContext({
|
271
|
+
name: u,
|
272
|
+
config: y
|
273
|
+
}), l = new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
|
274
|
+
if (!l) return console.error("Could not find the original declaration");
|
275
|
+
const w = (P = l.at(1)) == null ? void 0 : P.trim(), C = new RegExp(`\\s${u}[=\\s]+styled\\(`, "g").exec(i);
|
276
|
+
if (!C) return console.error("Could not find the original declaration");
|
277
|
+
const { index: F } = C;
|
278
|
+
let d = !1;
|
279
|
+
const k = setTimeout(() => d = !0, 5e3);
|
280
|
+
let c = 0, p = !1, m = 0;
|
281
|
+
for (; !p && !d; ) {
|
282
|
+
const N = i[F + c];
|
283
|
+
N === "(" && m++, N === ")" && m--, m === 0 && N === ")" && (p = !0), c > i.length && (d = !0), c++;
|
244
284
|
}
|
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);
|
285
|
+
if (!d) clearTimeout(k);
|
286
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
287
|
+
const h = F + c, S = i.slice(F, h), $ = i, j = ` ${u} = styled(${w}, "${b.classNames}", "${b._callerName}", ${JSON.stringify(b.props)});`;
|
288
|
+
i = i.replace(S, j), $ === i && console.error("Minimize file failed to change content", { name: u, tagName: w });
|
256
289
|
});
|
257
|
-
const
|
258
|
-
return
|
259
|
-
${
|
290
|
+
const r = _(s, 6);
|
291
|
+
return y.importStrategy === "component" && (i = `import '../../saltygen/css/${r}.css';
|
292
|
+
${i}`), i = i.replace("{ styled }", "{ styledClient as styled }"), i = i.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), i;
|
260
293
|
}
|
261
294
|
} catch (e) {
|
262
|
-
console.error(e);
|
295
|
+
console.error("Error in minimizeFile:", e);
|
263
296
|
}
|
264
|
-
},
|
297
|
+
}, wt = (t) => ({
|
265
298
|
name: "stylegen",
|
266
|
-
buildStart: () =>
|
299
|
+
buildStart: () => gt(t),
|
267
300
|
load: async (s) => {
|
268
|
-
if (
|
269
|
-
return await
|
301
|
+
if (O(s))
|
302
|
+
return await dt(t, s);
|
270
303
|
},
|
271
304
|
watchChange: {
|
272
305
|
handler: async (s) => {
|
273
|
-
|
306
|
+
O(s) && await yt(t, s), s.includes("salty.config") && await X(t);
|
274
307
|
}
|
275
308
|
}
|
276
309
|
});
|
277
310
|
export {
|
278
|
-
|
311
|
+
wt as default,
|
312
|
+
wt as saltyPlugin
|
279
313
|
};
|
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.80",
|
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
|
},
|
@@ -19,6 +24,7 @@
|
|
19
24
|
"!**/*.tsbuildinfo"
|
20
25
|
],
|
21
26
|
"nx": {
|
27
|
+
"sourceRoot": "libs/vite/src",
|
22
28
|
"name": "vite"
|
23
29
|
},
|
24
30
|
"exports": {
|
@@ -26,5 +32,8 @@
|
|
26
32
|
"import": "./index.js",
|
27
33
|
"require": "./index.cjs"
|
28
34
|
}
|
35
|
+
},
|
36
|
+
"dependencies": {
|
37
|
+
"@salty-css/core": "^0.0.1-alpha.80"
|
29
38
|
}
|
30
39
|
}
|