@salty-css/webpack 0.0.1-alpha.247 → 0.0.1-alpha.249
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 +8 -8
- package/index-CVxTKQjD.cjs +46 -0
- package/index-DGrPV3kl.js +685 -0
- package/index.cjs +1 -1
- package/index.js +1 -1
- package/loader.cjs +1 -1
- package/loader.js +1 -1
- package/package.json +2 -2
- package/index-C46X2dm-.cjs +0 -42
- package/index-C_rzJhGh.js +0 -679
package/README.md
CHANGED
@@ -64,6 +64,14 @@ To get help with problems, [Join Salty CSS Discord server](https://discord.gg/R6
|
|
64
64
|
- [defineViewportClamp](#viewport-clamp) - create CSS clamp functions that are based on user's viewport and can calculate relative values easily
|
65
65
|
- [color](#color-function) - transform any valid color code or variable to be darker, lighter etc. easily (uses [color library by Qix-](https://github.com/Qix-/color))
|
66
66
|
|
67
|
+
### Salty CSS CLI
|
68
|
+
|
69
|
+
In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
|
70
|
+
|
71
|
+
- 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.
|
72
|
+
- 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.
|
73
|
+
- Build files → `npx salty-css build [directory/filename]` - Compile Salty CSS related files in your project. This should not be needed if you are using tools like Next.js or Vite
|
74
|
+
|
67
75
|
## Styled function
|
68
76
|
|
69
77
|
Styled function is the main way to use Salty CSS within React. Styled function creates a React component that then can be used anywhere in your app. All styled functions must be created in `.css.ts` or `.css.tsx` files
|
@@ -375,14 +383,6 @@ import { color } from '@salty-css/core/helpers';
|
|
375
383
|
export const Wrapper = styled('span', { base: { backgroundColor: color('#000').alpha(0.5) } });
|
376
384
|
```
|
377
385
|
|
378
|
-
## Salty CSS CLI
|
379
|
-
|
380
|
-
In your existing repository you can use `npx salty-css [command]` to initialize a project, generate components, update related packages and build required files.
|
381
|
-
|
382
|
-
- 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.
|
383
|
-
- 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.
|
384
|
-
- 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
|
385
|
-
|
386
386
|
## Usage
|
387
387
|
|
388
388
|
### Next.js
|
@@ -0,0 +1,46 @@
|
|
1
|
+
"use strict";var vt=Object.defineProperty;var Mt=(t,e,s)=>e in t?vt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s;var et=(t,e,s)=>Mt(t,typeof e!="symbol"?e+"":e,s);const Rt=require("esbuild"),zt=require("child_process"),c=require("path"),d=require("fs"),St=require("fs/promises"),Z=require("winston"),ft=require("typescript");var ut=typeof document<"u"?document.currentScript:null;function Jt(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 jt=Jt(Rt),$t=t=>String.fromCharCode(t+(t>25?39:97)),Wt=(t,e)=>{let s="",n;for(n=Math.abs(t);n>52;n=n/52|0)s=$t(n%52)+s;return s=$t(n%52)+s,s.length<e?s=s.padStart(e,"a"):s.length>e&&(s=s.slice(-e)),s},At=(t,e)=>{let s=e.length;for(;s;)t=t*33^e.charCodeAt(--s);return t},q=(t,e=5)=>{const s=At(5381,JSON.stringify(t))>>>0;return Wt(s,e)};function R(t){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()):""}const qt=t=>e=>{if(typeof e!="string"||!t)return;let s=e;const n=[];return Object.values(t).forEach(i=>{const{pattern:r,transform:o}=i;s=s.replace(r,y=>{const{value:$,css:m}=o(y);return m&&n.push(m),$})}),{transformed:s,additionalCss:n}},Ft=t=>e=>typeof e!="string"||!/\{[^{}]+\}/g.test(e)?void 0:{transformed:e.replace(/\{([^{}]+)\}/g,(...i)=>`var(--${R(i[1].replaceAll(".","-"))})`)},It=Ft(),Gt=["top","right","bottom","left","min-width",/.*width.*/,/^[^line]*height.*/,/padding.*/,/margin.*/,/border.*/,/inset.*/,/.*radius.*/,/.*spacing.*/,/.*gap.*/,/.*indent.*/,/.*offset.*/,/.*size.*/,/.*thickness.*/,/.*font-size.*/],Ht=(t,e,s)=>Gt.some(i=>typeof i=="string"?i===t:i.test(t))?`${e}px`:`${e}`,Lt=["Webkit","Moz","ms","O"],Qt=t=>t.startsWith("-")?t:Lt.some(e=>t.startsWith(e))?`-${R(t)}`:R(t),st=async(t,e="",s,n=!1)=>{if(!t)throw new Error("No styles provided to parseStyles function!");const i=new Set,r=Object.entries(t),o=async([p,u])=>{const w=p.trim(),P=Qt(w),T=(D,J=";")=>`${P}:${D}${J}`,V={scope:e,config:s};if(typeof u=="function")return o([p,u(V)]);if(u instanceof Promise)return o([p,await u]);if(typeof u=="object"){if(!u)return;if(u.isColor)return T(u.toString());if(w==="defaultVariants")return;if(w==="variants"){const N=Object.entries(u);for(const[v,f]of N){if(!f)continue;const b=Object.entries(f);for(const[F,a]of b){if(!a)continue;const C=`${e}.${v}-${F}`;(await st(a,C,s)).forEach(M=>i.add(M))}}return}if(w==="compoundVariants"){for(const N of u){const{css:v,...f}=N,b=Object.entries(f).reduce((a,[C,_])=>`${a}.${C}-${_}`,e);(await st(v,b,s)).forEach(a=>i.add(a))}return}if(w.startsWith("@")){const N=w,v=await X(u,e,s),f=`${N} { ${v} }`;i.add(f);return}const D=p.includes("&")?w.replace("&",e):w.startsWith(":")?`${e}${w}`:`${e} ${w}`;(await st(u,D,s)).forEach(N=>i.add(N));return}if(typeof u=="number"){const D=Ht(P,u);return T(D)}if(typeof u!="string")if("toString"in u)u=u.toString();else throw new Error(`Invalid value type for property ${P}`);return T(u)},y=r.map(o),{modifiers:$}={},m=[Ft(),qt($)],g=(await Promise.all(y).then(p=>Promise.all(p.map(u=>m.reduce(async(w,P)=>{const T=await w;if(!T)return T;const V=await P(T);if(!V)return T;const{transformed:D,additionalCss:J}=V;let N="";if(J)for(const v of J)N+=await X(v,"");return`${N}${D}`},Promise.resolve(u)))))).filter(p=>p!==void 0).join(`
|
2
|
+
`);if(!g.trim())return Array.from(i);const h=e?`${e} {
|
3
|
+
${g}
|
4
|
+
}`:g;return i.has(h)?Array.from(i):[h,...i]},X=async(t,e,s,n=!1)=>(await st(t,e,s,n)).join(`
|
5
|
+
`),Ct=async(t,e=[])=>{if(!t)return"";const s=[],n={};for(const[i,r]of Object.entries(t))if(typeof r!="function")if(r&&typeof r=="object"){const o=i.trim(),y=await Ct(r,[...e,o]);s.push(y)}else n[i]=r;if(Object.keys(n).length){const i=e.map(R).join("-"),r="t_"+q(i,4),o=await X(n,`.${i}, .${r}`);s.push(o)}return s.join(`
|
6
|
+
`)},Kt=t=>t?Object.entries(t).reduce((e,[s,n])=>(typeof n=="function"?e[s]="any":typeof n=="object"&&(e[s]=Pt(n).map(i=>`"${i}"`).join(" | ")),e),{}):{},Pt=(t,e="",s=new Set)=>t?(Object.entries(t).forEach(([n,i])=>{const r=e?`${e}.${n}`:n;return typeof i=="object"?Pt(i,r,s):s.add(e)}),[...s]):[],Nt=t=>{if(!t||t==="/")throw new Error("Could not find package.json file");const e=c.join(t,"package.json");return d.existsSync(e)?e:Nt(c.join(t,".."))},Ut=async t=>{const e=Nt(t);return await St.readFile(e,"utf-8").then(JSON.parse).catch(()=>{})},Bt=async t=>{const e=await Ut(t);if(e)return e.type};let G;const _t=async t=>{if(G)return G;const e=await Bt(t);return e==="module"?G="esm":(e==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ut&&ut.tagName.toUpperCase()==="SCRIPT"&&ut.src||new URL("index-CVxTKQjD.cjs",document.baseURI).href).endsWith(".cjs"))&&(G="cjs"),G||"esm"},dt=Z.createLogger({level:"debug",format:Z.format.combine(Z.format.colorize(),Z.format.cli()),transports:[new Z.transports.Console({})]});function xt(t){return t?typeof t!="string"?xt(String(t)):t.replace(/[^\d\w]/g,"."):""}const Zt={"*, *::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"}},H=(...t)=>t.flat().reduce((e,s)=>s!=null&&s._current?{...e,...s._current}:{...e,...s},{}),Xt=(...t)=>t.flat().reduce((e,s)=>({...e,...s._children}),{});class Yt{constructor(e){et(this,"_path");this.params=e}get _current(){return this.params.template}get isDefineTemplate(){return!0}_setPath(e){return this._path=e,this}}class te{constructor(e){et(this,"_path");et(this,"templates",[]);this.params=e,Object.entries(e).forEach(([s,n])=>{this.templates.push(new Yt({name:s,template:n}))})}get _current(){return this.params}get _children(){return Object.fromEntries(this.templates.map(e=>[e.params.name,e]))}get isDefineTemplates(){return!0}_setPath(e){return this._path=e,this.templates.forEach(s=>s._setPath(e)),this}}const ee=t=>new te(t),se=(t,e)=>new Promise((s,n)=>{const i=setTimeout(()=>{n(new Error("Timeout"))},100),r=ft.createSourceFile("temp.ts",t,ft.ScriptTarget.Latest,!0);function o(y){if(ft.isVariableDeclaration(y)&&y.name.getText()===e){const $=y.getStart(),m=y.getEnd();clearTimeout(i),s([$,m])}y.forEachChild(o)}o(r)}),z={externalModules:[],rcFile:void 0,destDir:void 0},Tt=t=>{if(z.externalModules.length>0)return z.externalModules;const s=d.readFileSync(t,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(i=>i.replace(/['"`]/g,"").trim());return z.externalModules=n,n},I=async t=>{if(z.destDir)return z.destDir;const e=await pt(t),s=c.join(t,(e==null?void 0:e.saltygenDir)||"saltygen");return z.destDir=s,s},kt=["salty","css","styles","styled"],Dt=(t=[])=>new RegExp(`\\.(${[...kt,...t].join("|")})\\.`),nt=(t,e=[])=>Dt(e).test(t),Et=async t=>{if(z.rcFile)return z.rcFile;if(t==="/")throw new Error("Could not find .saltyrc.json file");const e=c.join(t,".saltyrc.json"),s=await St.readFile(e,"utf-8").then(JSON.parse).catch(()=>{});return s?(z.rcFile=s,s):Et(c.join(t,".."))},pt=async t=>{var n,i;const e=await Et(t),s=(n=e.projects)==null?void 0:n.find(r=>t.endsWith(r.dir||""));return s||((i=e.projects)==null?void 0:i.find(r=>r.dir===e.defaultProject))},ne=async t=>{const e=await pt(t),s=await I(t),n=c.join(t,(e==null?void 0:e.configDir)||"","salty.config.ts"),i=c.join(s,"salty.config.js"),r=await _t(t),o=Tt(n);await jt.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:i,format:r,external:o});const y=Date.now(),{config:$}=await import(`${i}?t=${y}`);return{config:$,path:i}},ie=async(t,e)=>{var ht,gt;const s=await I(t),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...e].map(async j=>{const{contents:x,outputFilePath:U}=await it(t,j,s);Object.entries(x).forEach(([E,k])=>{k.isMedia?n.mediaQueries.push([E,k]):k.isGlobalDefine?n.globalStyles.push(k):k.isDefineVariables?n.variables.push(k):k.isDefineTemplates&&n.templates.push(k._setPath(`${E};;${U}`))})}));const{config:i,path:r}=await ne(t),o={...i},{mediaQueries:y}=n;o.mediaQueries=Object.fromEntries(y.map(([j,x])=>[`@${j}`,x]));const $=y.map(([j])=>`'@${j}'`).join(" | "),m=new Set,l=async(j,x=[])=>{if(!j)return[];const U=Object.entries(j).map(async([k,A])=>{const B=async O=>{if(!O)return;if(O instanceof Promise)return await B(await O);if(typeof O=="function")return await B(await O());if(typeof O=="object")return await l(O,[...x,k]);const at=xt(k),ct=R(k),lt=[...x,at].join(".");m.add(`"${lt}"`);const tt=[...x.map(R),ct].join("-"),wt=It(O);return wt?`--${tt}: ${wt.transformed};`:`--${tt}: ${O};`};return await B(A)});return(await Promise.all(U)).flat()},g=async j=>{if(!j)return[];const x=Object.entries(j).map(async([E,k])=>{const A=await l(k);return E==="base"?A.join(""):o.mediaQueries[E]?`${o.mediaQueries[E]} { ${A.join("")} }`:`${E} { ${A.join("")} }`});return(await Promise.all(x)).flat()},h=async j=>{if(!j)return[];const x=Object.entries(j).map(async([E,k])=>{const A=Object.entries(k).map(async([O,at])=>{const ct=await l(at,[E]),lt=`.${E}-${O}, [data-${E}="${O}"]`,tt=ct.join("");return`${lt} { ${tt} }`});return(await Promise.all(A)).flat()});return(await Promise.all(x)).flat()},S=j=>({...j,responsive:void 0,conditional:void 0}),p=j=>n.variables.map(x=>j==="static"?S(x._current):x._current[j]),u=H(S(i.variables),p("static")),w=await l(u),P=H((ht=i.variables)==null?void 0:ht.responsive,p("responsive")),T=await g(P),V=H((gt=i.variables)==null?void 0:gt.conditional,p("conditional")),D=await h(V),J=c.join(s,"css/_variables.css"),N=`:root { ${w.join("")} ${T.join("")} } ${D.join("")}`;d.writeFileSync(J,N),o.staticVariables=u;const v=c.join(s,"css/_global.css"),f=H(i.global,n.globalStyles),b=await X(f,"");d.writeFileSync(v,`@layer global { ${b} }`);const F=c.join(s,"css/_reset.css"),C=i.reset==="none"?{}:typeof i.reset=="object"?i.reset:Zt,_=await X(C,"");d.writeFileSync(F,`@layer reset { ${_} }`);const M=c.join(s,"css/_templates.css"),W=H(i.templates,n.templates),L=await Ct(W),Q=Kt(W);d.writeFileSync(M,`@layer templates { ${L} }`),o.templates=W;const Y=i.templates?[ee(i.templates)._setPath(`config;;${r}`)]:[],ot=Xt(n.templates,Y);o.templatePaths=Object.fromEntries(Object.entries(ot).map(([j,x])=>[j,x._path]));const K=c.join(s,"types/css-tokens.d.ts"),Ot=`
|
7
|
+
// Variable types
|
8
|
+
type VariableTokens = ${[...m].join("|")};
|
9
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
10
|
+
|
11
|
+
// Template types
|
12
|
+
type TemplateTokens = {
|
13
|
+
${Object.entries(Q).map(([j,x])=>`${j}?: ${x}`).join(`
|
14
|
+
`)}
|
15
|
+
}
|
16
|
+
|
17
|
+
// Media query types
|
18
|
+
type MediaQueryKeys = ${$||"''"};
|
19
|
+
`;d.writeFileSync(K,Ot);const Vt=c.join(s,"cache/config-cache.json");d.writeFileSync(Vt,JSON.stringify(o,null,2))},bt=t=>t.replace(/styled\(([^"'`{,]+),/g,(e,s)=>{if(/^['"`]/.test(s))return e;const i=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!i.test(t))return e;const o=i.exec(t);if(o){const y=o.at(1);if(kt.some(m=>y==null?void 0:y.includes(m)))return e}return"styled('div',"}),oe=(t,e)=>{try{const s=d.readFileSync(c.join(e,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
20
|
+
|
21
|
+
${t}`:`globalThis.saltyConfig = {};
|
22
|
+
|
23
|
+
${t}`}catch{return t}},it=async(t,e,s)=>{const n=q(e),i=c.join(s,"./temp");d.existsSync(i)||d.mkdirSync(i);const r=c.parse(e);let o=d.readFileSync(e,"utf8");o=bt(o),o=oe(o,t);const y=c.join(s,"js",n+".js"),$=await pt(t),m=c.join(t,($==null?void 0:$.configDir)||"","salty.config.ts"),l=Tt(m),g=await _t(t);await jt.build({stdin:{contents:o,sourcefile:r.base,resolveDir:r.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:l,packages:"external",plugins:[{name:"test",setup:p=>{p.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},u=>{const w=d.readFileSync(u.path,"utf8");return{contents:bt(w),loader:"ts"}})}}]});const h=Date.now();return{contents:await import(`${y}?t=${h}`),outputFilePath:y}},re=async t=>{const e=await I(t),s=c.join(e,"cache/config-cache.json"),n=d.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},mt=async t=>{const e=await re(t),s=await I(t),n=c.join(s,"salty.config.js"),i=Date.now(),{config:r}=await import(`${n}?t=${i}`);return H(r,e)},yt=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},ae=async(t,e=yt(),s=!0)=>{try{const n=Date.now();e?dt.info("Generating CSS in production mode! 🔥"):dt.info("Generating CSS in development mode! 🚀");const i=[],r=[],o=await I(t),y=c.join(o,"index.css");s&&(()=>{d.existsSync(o)&&zt.execSync("rm -rf "+o),d.mkdirSync(o,{recursive:!0}),d.mkdirSync(c.join(o,"css")),d.mkdirSync(c.join(o,"types")),d.mkdirSync(c.join(o,"js")),d.mkdirSync(c.join(o,"cache"))})();const m=new Set,l=new Set;async function g(f){const b=["node_modules","saltygen"],F=d.statSync(f);if(F.isDirectory()){const a=d.readdirSync(f);if(b.some(_=>f.includes(_)))return;await Promise.all(a.map(_=>g(c.join(f,_))))}else if(F.isFile()&&nt(f)){m.add(f);const C=d.readFileSync(f,"utf8");/define[\w\d]+\(/.test(C)&&l.add(f)}}await g(t),await ie(t,l);const h={keyframes:[],components:[],classNames:[]};await Promise.all([...m].map(async f=>{const{contents:b}=await it(t,f,o);for(let[F,a]of Object.entries(b))a instanceof Promise&&(a=await a),a.isKeyframes?h.keyframes.push({value:a,src:f,name:F}):a.isClassName?h.classNames.push({...a,src:f,name:F}):a.generator&&h.components.push({...a,src:f,name:F})}));const S=await mt(t);for(const f of h.keyframes){const{value:b}=f,F=`a_${b.animationName}.css`,a=`css/${F}`,C=c.join(o,a);i.push(F),d.writeFileSync(C,b.css)}const p={};for(const f of h.components){const{src:b,name:F}=f;p[b]||(p[b]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:S});r[a.priority]||(r[a.priority]=[]);const C=await a.css;if(!C)continue;r[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,M=c.join(o,_);d.writeFileSync(M,C),S.importStrategy==="component"&&p[b].push(a.cssFileName)}for(const f of h.classNames){const{src:b,name:F}=f;p[b]||(p[b]=[]);const a=f.generator._withBuildContext({callerName:F,isProduction:e,config:S}),C=await a.css;if(!C)continue;r[a.priority]||(r[a.priority]=[]),r[a.priority].push(a.cssFileName);const _=`css/${a.cssFileName}`,M=c.join(o,_);d.writeFileSync(M,C),S.importStrategy==="component"&&p[b].push(a.cssFileName)}S.importStrategy==="component"&&Object.entries(p).forEach(([f,b])=>{const F=b.map(W=>`@import url('./${W}');`).join(`
|
24
|
+
`),a=q(f,6),C=c.parse(f),_=R(C.name),M=c.join(o,`css/f_${_}-${a}.css`);d.writeFileSync(M,F||"/* Empty file */")});const u=i.map(f=>`@import url('./css/${f}');`).join(`
|
25
|
+
`);let D=`/*!
|
26
|
+
* Generated with Salty CSS (https://salty-css.dev)
|
27
|
+
* Do not edit this file directly
|
28
|
+
*/
|
29
|
+
@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
30
|
+
|
31
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return d.readFileSync(c.join(o,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
32
|
+
`)}
|
33
|
+
${u}`;if(S.importStrategy!=="component"){const f=r.reduce((b,F,a)=>{const C=F.reduce((L,Q)=>{var rt;const Y=c.join(o,"css",Q),ot=d.readFileSync(Y,"utf8"),K=((rt=/.*-([^-]+)-\d+.css/.exec(Q))==null?void 0:rt.at(1))||q(Y,6);return L.includes(K)?L:`${L}
|
34
|
+
/*start:${K}-${Q}*/
|
35
|
+
${ot}
|
36
|
+
/*end:${K}*/
|
37
|
+
`},""),_=`l_${a}.css`,M=c.join(o,"css",_),W=`@layer l${a} { ${C}
|
38
|
+
}`;return d.writeFileSync(M,W),`${b}
|
39
|
+
@import url('./css/${_}');`},"");D+=f}d.writeFileSync(y,D);const N=Date.now()-n,v=N<200?"🔥":N<500?"🚀":N<1e3?"🎉":N<2e3?"🚗":N<5e3?"🤔":"🥴";dt.info(`Generated CSS in ${N}ms! ${v}`)}catch(n){console.error(n)}},ce=async(t,e,s=yt())=>{try{const n=await I(t);if(nt(e)){const r=[],o=await mt(t),{contents:y}=await it(t,e,n);for(const[$,m]of Object.entries(y)){if(m.isKeyframes&&m.css){const u=`css/${`a_${m.animationName}.css`}`,w=c.join(n,u);d.writeFileSync(w,await m.css);continue}if(m.isClassName){const p=m.generator._withBuildContext({callerName:$,isProduction:s,config:o}),u=await p.css;if(!u)continue;r[p.priority]||(r[p.priority]=[]),r[p.priority].push(p.cssFileName);const w=`css/${p.cssFileName}`,P=c.join(n,w);d.writeFileSync(P,u);continue}if(!m.generator)continue;const l=m.generator._withBuildContext({callerName:$,isProduction:s,config:o}),g=await l.css;if(!g)continue;const h=`css/${l.cssFileName}`,S=c.join(n,h);d.writeFileSync(S,g),r[l.priority]||(r[l.priority]=[]),r[l.priority].push(l.cssFileName)}if(o.importStrategy!=="component")r.forEach(($,m)=>{const l=`l_${m}.css`,g=c.join(n,"css",l);let h=d.readFileSync(g,"utf8");$.forEach(S=>{var P;const p=c.join(n,"css",S),u=((P=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:P.at(1))||q(p,6);if(!h.includes(u)){const T=d.readFileSync(p,"utf8"),V=`/*start:${u}-${S}*/
|
40
|
+
${T}
|
41
|
+
/*end:${u}*/
|
42
|
+
`;h=`${h.replace(/\}$/,"")}
|
43
|
+
${V}
|
44
|
+
}`}}),d.writeFileSync(g,h)});else{const $=r.flat().map(S=>`@import url('./${S}');`).join(`
|
45
|
+
`),m=q(e,6),l=c.parse(e),g=R(l.name),h=c.join(n,`css/f_${g}-${m}.css`);d.writeFileSync(h,$||"/* Empty file */")}}}catch(n){console.error(n)}},le=async(t,e,s=yt())=>{var n,i;try{const r=await I(t);if(nt(e)){const y=d.readFileSync(e,"utf8"),$=await mt(t),{contents:m}=await it(t,e,r);let l=y;for(const[g,h]of Object.entries(m)){if(h.isKeyframes||!h.generator)continue;const S=h.generator._withBuildContext({callerName:g,isProduction:s,config:$}),[p,u]=await se(l,g),w=l.slice(p,u);if(h.isClassName){const P=l,T=` ${g} = className("${S.classNames}")`;l=l.replace(w,T),P===l&&console.error("Minimize file failed to change content",{name:g})}if(w.includes("styled")){const P=(i=(n=/styled\(([^,]+),/.exec(w))==null?void 0:n.at(1))==null?void 0:i.trim(),T=l,V=` ${g} = styled(${P}, "${S.classNames}", ${JSON.stringify(S.clientProps)})`;l=l.replace(w,V),T===l&&console.error("Minimize file failed to change content",{name:g,tagName:P})}}if($.importStrategy==="component"){const g=q(e,6),h=c.parse(e);l=`import '../../saltygen/css/${`f_${R(h.name)}-${g}.css`}';
|
46
|
+
${l}`}return l=l.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(r){console.error("Error in minimizeFile:",r)}};exports.generateCss=ae;exports.generateFile=ce;exports.isSaltyFile=nt;exports.minimizeFile=le;exports.saltyFileRegExp=Dt;
|