@salty-css/core 0.0.1-alpha.206 → 0.0.1-alpha.207
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/bin/main.cjs +1 -1
- package/bin/main.js +1 -1
- package/compiler/index.cjs +1 -1
- package/compiler/index.d.ts +1 -1
- package/compiler/index.js +1 -1
- package/index-BZxPdVzL.cjs +38 -0
- package/index-Djy7Z9Ft.js +498 -0
- package/package.json +1 -1
- package/server/index.cjs +1 -1
- package/server/index.js +1 -1
- package/index-BwBIR0y8.cjs +0 -38
- package/index-ED4VBH54.js +0 -495
package/bin/main.cjs
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const te=require("commander"),G=require("fs"),s=require("fs/promises"),n=require("path"),ne=require("ejs"),t=require("../index-BZxPdVzL.cjs"),ie=require("../pascal-case-iWoaJWwT.cjs"),se=require("child_process"),oe=require("ora");var z=typeof document<"u"?document.currentScript:null;const X=y=>new Promise((C,P)=>{se.exec(y,F=>{if(F)return P(F);C()})}),I=async(...y)=>{const C=y.map(b=>b.replace("-D","").split("@").slice(0,-1).join("@").trim()).join(", "),P=oe(`Installing packages: ${C}`).start(),F=y.join(" ");await X(`npm install ${F}`),P.succeed(`Installed packages: ${C}`)},ae=()=>G.existsSync(n.join(process.cwd(),"node_modules",".bin","prettier"));async function S(y){try{if(!ae())return;await X(`./node_modules/.bin/prettier --write "${y}"`),t.logger.info(`Formatted ${y} with Prettier`)}catch(C){t.logger.error(`Error formatting ${y} with Prettier:`,C)}}async function re(){const y=new te.Command;y.name("salty-css").description("Salty-CSS CLI tool to help with annoying configuration tasks.");const C={"salty.config.ts":Promise.resolve().then(()=>require("../salty.config-Dk6ZcCxI.cjs")),"saltygen/index.css":Promise.resolve().then(()=>require("../index-84Wroia-.cjs")),"react/react-styled-file.ts":Promise.resolve().then(()=>require("../react-styled-file-Dkubsz-U.cjs")),"react/react-vanilla-file.ts":Promise.resolve().then(()=>require("../react-vanilla-file-CG_WJLam.cjs"))},P=async(i,a)=>{const{default:l}=await C[i],u=ne.render(l,a);return{fileName:i,content:u}},F=async()=>{const i=n.join(process.cwd(),".saltyrc.json");return await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>({}))},b=n.join(process.cwd(),"package.json"),N=async(i=b)=>{const a=await s.readFile(i,"utf-8").then(JSON.parse).catch(()=>{});if(!a)throw"Could not read package.json file!";return a},Y=async(i,a=b)=>{typeof i=="object"&&(i=JSON.stringify(i,null,2)),await s.writeFile(a,i)},B=async()=>{const i=new URL("../package.json",typeof document>"u"?require("url").pathToFileURL(__filename).href:z&&z.tagName.toUpperCase()==="SCRIPT"&&z.src||new URL("bin/main.cjs",document.baseURI).href);return N(i)},V=await(async()=>(await F()).defaultProject)(),$=await B(),D={core:`@salty-css/core@${$.version}`,react:`@salty-css/react@${$.version}`,eslintConfigCore:`@salty-css/eslint-config-core@${$.version}`,vite:`@salty-css/vite@${$.version}`,next:`@salty-css/next@${$.version}`},R=i=>{const a=i==="."?"":i,l=process.cwd();return n.join(l,a)};y.command("init [directory]").description("Initialize a new Salty-CSS project.").option("-d, --dir <dir>","Project directory to initialize the project in.").option("--css-file <css-file>","Existing CSS file where to import the generated CSS. Path must be relative to the given project directory.").option("--skip-install","Skip installing dependencies.").action(async function(i="."){if(!await N().catch(()=>{}))return t.logError("Salty CSS project must be initialized in a directory with a package.json file.");t.logger.info("Initializing a new Salty-CSS project!");const{dir:l=i,cssFile:u,skipInstall:p}=this.opts();if(!l)return t.logError("Project directory must be provided. Add it as the first argument after init command or use the --dir option.");p||await I(D.core,D.react);const f=process.cwd(),r=R(l),T=await Promise.all([P("salty.config.ts"),P("saltygen/index.css")]);await s.mkdir(r,{recursive:!0});const m=T.map(async({fileName:e,content:g})=>{const c=n.join(r,e);if(await s.readFile(c,"utf-8").catch(()=>{})!==void 0){t.logger.debug("File already exists: "+c);return}const k=e.split("/").slice(0,-1).join("/");k&&await s.mkdir(n.join(r,k),{recursive:!0}),t.logger.info("Creating file: "+c),await s.writeFile(c,g),await S(c)});await Promise.all(m);const w=n.relative(f,r)||".",h=n.join(f,".saltyrc.json"),d=await s.readFile(h,"utf-8").catch(()=>{});if(d===void 0){t.logger.info("Creating file: "+h);const g=JSON.stringify({$schema:"./node_modules/@salty-css/core/.saltyrc.schema.json",info:"This file is used to define projects and their configurations for Salty CSS cli. Do not delete, modify or add this file to .gitignore.",defaultProject:w,projects:[{dir:w,framework:"react"}]},null,2);await s.writeFile(h,g),await S(h)}else{const e=JSON.parse(d),g=(e==null?void 0:e.projects)||[];if(g.findIndex(o=>o.dir===w)===-1){g.push({dir:w,framework:"react"}),e.projects=[...g];const o=JSON.stringify(e,null,2);o!==d&&(t.logger.info("Edit file: "+h),await s.writeFile(h,o),await S(h))}}const j=n.join(f,".gitignore"),U=await s.readFile(j,"utf-8").catch(()=>{});U!==void 0&&(U.includes("saltygen")||(t.logger.info("Edit file: "+j),await s.writeFile(j,U+`
|
2
2
|
|
3
3
|
# Salty-CSS
|
4
4
|
saltygen
|
package/bin/main.js
CHANGED
@@ -3,7 +3,7 @@ import { existsSync as K } from "fs";
|
|
3
3
|
import { mkdir as q, readFile as C, writeFile as w } from "fs/promises";
|
4
4
|
import { join as i, relative as z, parse as re, format as ee } from "path";
|
5
5
|
import { render as ce } from "ejs";
|
6
|
-
import { l as t, a as h, g as te } from "../index-
|
6
|
+
import { l as t, a as h, g as te } from "../index-Djy7Z9Ft.js";
|
7
7
|
import { p as le } from "../pascal-case-BQpR5PdN.js";
|
8
8
|
import { exec as de } from "child_process";
|
9
9
|
import fe from "ora";
|
package/compiler/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-DKWtadpv.cjs");const e=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});require("esbuild");require("child_process");require("../dash-case-BJEkFEGQ.cjs");require("path");require("fs");require("fs/promises");require("../parse-styles-DKWtadpv.cjs");const e=require("../index-BZxPdVzL.cjs");require("../css/merge.cjs");exports.compileSaltyFile=e.compileSaltyFile;exports.generateConfigStyles=e.generateConfigStyles;exports.generateCss=e.generateCss;exports.generateFile=e.generateFile;exports.isSaltyFile=e.isSaltyFile;exports.minimizeFile=e.minimizeFile;exports.saltyFileExtensions=e.saltyFileExtensions;exports.saltyFileRegExp=e.saltyFileRegExp;
|
package/compiler/index.d.ts
CHANGED
@@ -20,5 +20,5 @@ export declare const compileSaltyFile: (dirname: string, sourceFilePath: string,
|
|
20
20
|
outputFilePath: string;
|
21
21
|
}>;
|
22
22
|
export declare const generateCss: (dirname: string, prod?: boolean, clean?: boolean) => Promise<void>;
|
23
|
-
export declare const generateFile: (dirname: string, file: string) => Promise<void>;
|
23
|
+
export declare const generateFile: (dirname: string, file: string, prod?: boolean) => Promise<void>;
|
24
24
|
export declare const minimizeFile: (dirname: string, file: string, prod?: boolean) => Promise<string | undefined>;
|
package/compiler/index.js
CHANGED
@@ -5,7 +5,7 @@ import "path";
|
|
5
5
|
import "fs";
|
6
6
|
import "fs/promises";
|
7
7
|
import "../parse-styles-CkaV3OGz.js";
|
8
|
-
import { d as n, c as g, g as F, e as y, i as x, m as S, s as c, b as f } from "../index-
|
8
|
+
import { d as n, c as g, g as F, e as y, i as x, m as S, s as c, b as f } from "../index-Djy7Z9Ft.js";
|
9
9
|
import "../css/merge.js";
|
10
10
|
export {
|
11
11
|
n as compileSaltyFile,
|
@@ -0,0 +1,38 @@
|
|
1
|
+
"use strict";const Ce=require("esbuild"),xe=require("child_process"),D=require("./dash-case-BJEkFEGQ.cjs"),i=require("path"),c=require("fs"),oe=require("fs/promises"),X=require("./parse-styles-DKWtadpv.cjs"),B=require("winston"),M=require("./css/merge.cjs");var ne=typeof document<"u"?document.currentScript:null;function Ne(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const pe=Ne(Ce),ye=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[r,o]of Object.entries(e))if(typeof o!="function")if(o&&typeof o=="object"){const a=r.trim(),y=await ye(o,[...t,a]);s.push(y)}else n[r]=o;if(Object.keys(n).length){const r=t.map(D.dashCase).join("-"),o="t_"+D.toHash(r,4),a=await X.parseAndJoinStyles(n,`.${r}, .${o}`);s.push(a)}return s.join(`
|
2
|
+
`)},Pe=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=me(n).map(r=>`"${r}"`).join(" | ")),t),{}):{},me=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,r])=>{const o=t?`${t}.${n}`:n;return typeof r=="object"?me(r,o,s):s.add(t)}),[...s]):[],ge=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=i.join(e,"package.json");return c.existsSync(t)?t:ge(i.join(e,".."))},ke=async e=>{const t=ge(e);return await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},De=async e=>{const t=await ke(e);if(t)return t.type};let H;const he=async e=>{if(H)return H;const t=await De(e);return t==="module"?H="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ne&&ne.tagName.toUpperCase()==="SCRIPT"&&ne.src||new URL("index-BZxPdVzL.cjs",document.baseURI).href).endsWith(".cjs"))&&(H="cjs"),H||"esm"},G=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]}),_e=e=>{G.error(e)};function Se(e){return e?typeof e!="string"?Se(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const Oe={"*, *::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"}},V={externalModules:[],rcFile:void 0,destDir:void 0},je=e=>{if(V.externalModules.length>0)return V.externalModules;const s=c.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(r=>r.replace(/['"`]/g,"").trim());return V.externalModules=n,n},v=async e=>{if(V.destDir)return V.destDir;const t=await re(e),s=i.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},ie=["salty","css","styles","styled"],we=(e=[])=>new RegExp(`\\.(${[...ie,...e].join("|")})\\.`),Y=(e,t=[])=>we(t).test(e),be=async e=>{if(V.rcFile)return V.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=i.join(e,".saltyrc.json"),s=await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):be(i.join(e,".."))},re=async e=>{var n,r;const t=await be(e),s=(n=t.projects)==null?void 0:n.find(o=>e.endsWith(o.dir||""));return s||((r=t.projects)==null?void 0:r.find(o=>o.dir===t.defaultProject))},Te=async e=>{const t=await re(e),s=await v(e),n=i.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),r=i.join(s,"salty.config.js"),o=await he(e),a=je(n);await pe.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:r,format:o,external:a});const y=Date.now(),{config:$}=await import(`${r}?t=${y}`);return $},Fe=async(e,t)=>{var le,fe;const s=await v(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async m=>{const{contents:b,outputFilePath:R}=await K(e,m,s);Object.entries(b).forEach(([k,O])=>{O.isMedia?n.mediaQueries.push([k,O]):O.isGlobalDefine?n.globalStyles.push(O):O.isDefineVariables?n.variables.push(O):O.isDefineTemplates&&n.templates.push(O._setPath(R))})}));const r=await Te(e),o={...r},a=new Set,y=(m,b=[])=>m?Object.entries(m).flatMap(([R,k])=>{if(!k)return;if(typeof k=="object")return y(k,[...b,R]);const O=Se(R),te=D.dashCase(R),se=[...b,O].join(".");a.add(`"${se}"`);const U=[...b.map(D.dashCase),te].join("-"),ue=X.parseVariableTokens(k);return ue?`--${U}: ${ue.transformed};`:`--${U}: ${k};`}):[],$=m=>m?Object.entries(m).flatMap(([b,R])=>{const k=y(R);return b==="base"?k.join(""):`${b} { ${k.join("")} }`}):[],l=m=>m?Object.entries(m).flatMap(([b,R])=>Object.entries(R).flatMap(([k,O])=>{const te=y(O,[b]),se=`.${b}-${k}, [data-${b}="${k}"]`,U=te.join("");return`${se} { ${U} }`})):[],d=m=>({...m,responsive:void 0,conditional:void 0}),g=m=>n.variables.map(b=>m==="static"?d(b._current):b._current[m]),p=M.mergeObjects(d(r.variables),g("static")),j=y(p),h=M.mergeObjects((le=r.variables)==null?void 0:le.responsive,g("responsive")),C=$(h),N=M.mergeObjects((fe=r.variables)==null?void 0:fe.conditional,g("conditional")),P=l(N),J=i.join(s,"css/_variables.css"),T=`:root { ${j.join("")} ${C.join("")} } ${P.join("")}`;c.writeFileSync(J,T),o.staticVariables=p;const q=i.join(s,"css/_global.css"),_=M.mergeObjects(r.global,n.globalStyles),I=await X.parseAndJoinStyles(_,"");c.writeFileSync(q,`@layer global { ${I} }`);const f=i.join(s,"css/_reset.css"),w=r.reset==="none"?{}:typeof r.reset=="object"?r.reset:Oe,u=await X.parseAndJoinStyles(w,"");c.writeFileSync(f,`@layer reset { ${u} }`);const F=i.join(s,"css/_templates.css"),x=M.mergeObjects(r.templates,n.templates),E=await ye(x),W=Pe(x);c.writeFileSync(F,`@layer templates { ${E} }`),o.templates=x;const A=M.mergeFactories(n.templates);o.templatePaths=Object.fromEntries(Object.entries(A).map(([m,b])=>[m,b._path]));const{mediaQueries:z}=n;o.mediaQueries=Object.fromEntries(z.map(([m,b])=>[`@${m}`,b]));const L=z.map(([m])=>`'@${m}'`).join(" | "),ee=i.join(s,"types/css-tokens.d.ts"),Z=`
|
3
|
+
// Variable types
|
4
|
+
type VariableTokens = ${[...a].join("|")};
|
5
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
6
|
+
|
7
|
+
// Template types
|
8
|
+
type TemplateTokens = {
|
9
|
+
${Object.entries(W).map(([m,b])=>`${m}?: ${b}`).join(`
|
10
|
+
`)}
|
11
|
+
}
|
12
|
+
|
13
|
+
// Media query types
|
14
|
+
type MediaQueryKeys = ${L||"''"};
|
15
|
+
`;c.writeFileSync(ee,Z);const $e=i.join(s,"cache/config-cache.json");c.writeFileSync($e,JSON.stringify(o,null,2))},de=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const r=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!r.test(e))return t;const a=r.exec(e);if(a){const y=a.at(1);if(ie.some(l=>y==null?void 0:y.includes(l)))return t}return"styled('div',"}),Ee=(e,t)=>{try{const s=c.readFileSync(i.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
16
|
+
|
17
|
+
${e}`:`globalThis.saltyConfig = {};
|
18
|
+
|
19
|
+
${e}`}catch{return e}},K=async(e,t,s)=>{const n=D.toHash(t),r=i.join(s,"./temp");c.existsSync(r)||c.mkdirSync(r);const o=i.parse(t);let a=c.readFileSync(t,"utf8");a=de(a),a=Ee(a,e);const y=i.join(s,"js",n+".js"),$=await re(e),l=i.join(e,($==null?void 0:$.configDir)||"","salty.config.ts"),d=je(l),g=await he(e);await pe.build({stdin:{contents:a,sourcefile:o.base,resolveDir:o.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:y,format:g,target:["node20"],keepNames:!0,external:d,packages:"external",plugins:[{name:"test",setup:h=>{h.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},C=>{const N=c.readFileSync(C.path,"utf8");return{contents:de(N),loader:"ts"}})}}]});const p=Date.now();return{contents:await import(`${y}?t=${p}`),outputFilePath:y}},Re=async e=>{const t=await v(e),s=i.join(t,"cache/config-cache.json"),n=c.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ae=async e=>{const t=await Re(e),s=await v(e),n=i.join(s,"salty.config.js"),r=Date.now(),{config:o}=await import(`${n}?t=${r}`);return M.mergeObjects(o,t)},ce=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ve=async(e,t=ce(),s=!0)=>{try{const n=Date.now();t?G.info("Generating CSS in production mode! 🔥"):G.info("Generating CSS in development mode! 🚀");const r=[],o=[],a=await v(e),y=i.join(a,"index.css");s&&(()=>{c.existsSync(a)&&xe.execSync("rm -rf "+a),c.mkdirSync(a,{recursive:!0}),c.mkdirSync(i.join(a,"css")),c.mkdirSync(i.join(a,"types")),c.mkdirSync(i.join(a,"js")),c.mkdirSync(i.join(a,"cache"))})();const l=new Set,d=new Set;async function g(f){const S=["node_modules","saltygen"],w=c.statSync(f);if(w.isDirectory()){const u=c.readdirSync(f);if(S.some(x=>f.includes(x)))return;await Promise.all(u.map(x=>g(i.join(f,x))))}else if(w.isFile()&&Y(f)){l.add(f);const F=c.readFileSync(f,"utf8");/define[\w\d]+\(/.test(F)&&d.add(f)}}await g(e),await Fe(e,d);const p={keyframes:[],components:[],classNames:[]};await Promise.all([...l].map(async f=>{const{contents:S}=await K(e,f,a);Object.entries(S).forEach(([w,u])=>{u.isKeyframes?p.keyframes.push({value:u,src:f,name:w}):u.isClassName?p.classNames.push({...u,src:f,name:w}):u.generator&&p.components.push({...u,src:f,name:w})})}));const j=await ae(e);for(const f of p.keyframes){const{value:S}=f,w=`a_${S.animationName}.css`,u=`css/${w}`,F=i.join(a,u);r.push(w),c.writeFileSync(F,S.css)}const h={};for(const f of p.components){const{src:S,name:w}=f,u=f.generator._withBuildContext({callerName:w,isProduction:t,config:j});o[u.priority]||(o[u.priority]=[]);const F=await u.css;if(!F)continue;o[u.priority].push(u.cssFileName);const x=`css/${u.cssFileName}`,E=i.join(a,x);c.writeFileSync(E,F),j.importStrategy==="component"&&(h[S]?h[S].push(u.cssFileName):h[S]=[u.cssFileName])}for(const f of p.classNames){const{src:S,name:w}=f,u=f.generator._withBuildContext({callerName:w,isProduction:t,config:j}),F=await u.css;if(!F)continue;o[0].push(u.cssFileName);const x=`css/${u.cssFileName}`,E=i.join(a,x);c.writeFileSync(E,F),j.importStrategy==="component"&&(h[S]?h[S].push(u.cssFileName):h[S]=[u.cssFileName])}j.importStrategy==="component"&&Object.entries(h).forEach(([f,S])=>{const w=S.map(W=>`@import url('./${W}');`).join(`
|
20
|
+
`),u=D.toHash(f,6),F=i.parse(f),x=D.dashCase(F.name),E=i.join(a,`css/f_${x}-${u}.css`);c.writeFileSync(E,w)});const C=r.map(f=>`@import url('./css/${f}');`).join(`
|
21
|
+
`);let T=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
22
|
+
|
23
|
+
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(f=>{try{return c.readFileSync(i.join(a,"css",f),"utf8").length>0}catch{return!1}}).map(f=>`@import url('./css/${f}');`).join(`
|
24
|
+
`)}
|
25
|
+
${C}`;if(j.importStrategy!=="component"){const f=o.reduce((S,w,u)=>{const F=w.reduce((A,z)=>{var Z;const L=i.join(a,"css",z),ee=c.readFileSync(L,"utf8"),Q=((Z=/.*-([^-]+)-\d+.css/.exec(z))==null?void 0:Z.at(1))||D.toHash(L,6);return A.includes(Q)?A:`${A}
|
26
|
+
/*start:${Q}-${z}*/
|
27
|
+
${ee}
|
28
|
+
/*end:${Q}*/
|
29
|
+
`},""),x=`l_${u}.css`,E=i.join(a,"css",x),W=`@layer l${u} { ${F}
|
30
|
+
}`;return c.writeFileSync(E,W),`${S}
|
31
|
+
@import url('./css/${x}');`},"");T+=f}c.writeFileSync(y,T);const _=Date.now()-n,I=_<200?"🔥":_<500?"🚀":_<1e3?"🎉":_<2e3?"🚗":_<5e3?"🤔":"🥴";G.info(`Generated CSS in ${_}ms! ${I}`)}catch(n){console.error(n)}},Me=async(e,t,s=ce())=>{try{const n=await v(e);if(Y(t)){const o=[],a=await ae(e),{contents:y}=await K(e,t,n);for(const[$,l]of Object.entries(y)){if(l.isKeyframes&&l.css){const C=`css/${`a_${l.animationName}.css`}`,N=i.join(n,C);c.writeFileSync(N,await l.css);return}if(l.isClassName){const h=l.generator._withBuildContext({callerName:$,isProduction:s,config:a}),C=await h.css;if(!C)continue;o[0].push(h.cssFileName);const N=`css/${h.cssFileName}`,P=i.join(n,N);c.writeFileSync(P,C)}if(!l.generator)return;const d=l.generator._withBuildContext({callerName:$,isProduction:s,config:a}),g=await d.css;if(!g)continue;const p=`css/${d.cssFileName}`,j=i.join(n,p);c.writeFileSync(j,g),o[d.priority]||(o[d.priority]=[]),o[d.priority].push(d.cssFileName)}if(a.importStrategy!=="component")o.forEach(($,l)=>{const d=`l_${l}.css`,g=i.join(n,"css",d);let p=c.readFileSync(g,"utf8");$.forEach(j=>{var P;const h=i.join(n,"css",j),C=((P=/.*-([^-]+)-\d+.css/.exec(j))==null?void 0:P.at(1))||D.toHash(h,6);if(!p.includes(C)){const J=c.readFileSync(h,"utf8"),T=`/*start:${C}-${j}*/
|
32
|
+
${J}
|
33
|
+
/*end:${C}*/
|
34
|
+
`;p=`${p.replace(/\}$/,"")}
|
35
|
+
${T}
|
36
|
+
}`}}),c.writeFileSync(g,p)});else{const $=o.flat().map(j=>`@import url('./${j}');`).join(`
|
37
|
+
`),l=D.toHash(t,6),d=i.parse(t),g=D.dashCase(d.name),p=i.join(n,`css/f_${g}-${l}.css`);c.writeFileSync(p,$)}}}catch(n){console.error(n)}},ve=async(e,t,s=ce())=>{try{const n=await v(e);if(Y(t)){const o=c.readFileSync(t,"utf8");o.replace(/^(?!export\s)const\s.*/gm,d=>`export ${d}`)!==o&&await oe.writeFile(t,o);const y=await ae(e),{contents:$}=await K(e,t,n);let l=o;if(Object.entries($).forEach(([d,g])=>{var u;if(g.isKeyframes||!g.generator)return;const p=g.generator._withBuildContext({callerName:d,isProduction:s,config:y}),j=new RegExp(`\\s${d}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(o);if(!j)return console.error("Could not find the original declaration");const h=(u=j.at(1))==null?void 0:u.trim(),C=new RegExp(`\\s${d}[=\\s]+styled\\(`,"g").exec(l);if(!C)return console.error("Could not find the original declaration");const{index:N}=C;let P=!1;const J=setTimeout(()=>P=!0,5e3);let T=0,q=!1,_=0;for(;!q&&!P;){const F=l[N+T];F==="("&&_++,F===")"&&_--,_===0&&F===")"&&(q=!0),T>l.length&&(P=!0),T++}if(!P)clearTimeout(J);else throw new Error("Failed to find the end of the styled call and timed out");const I=N+T,f=l.slice(N,I),S=l,w=` ${d} = styled(${h}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;l=l.replace(f,w),S===l&&console.error("Minimize file failed to change content",{name:d,tagName:h})}),y.importStrategy==="component"){const d=D.toHash(t,6),g=i.parse(t);l=`import '../../saltygen/css/${`f_${D.dashCase(g.name)}-${d}.css`}';
|
38
|
+
${l}`}return l=l.replace("{ styled }","{ styledClient as styled }"),l=l.replace("@salty-css/react/styled","@salty-css/react/styled-client"),l}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=K;exports.generateConfigStyles=Fe;exports.generateCss=Ve;exports.generateFile=Me;exports.isSaltyFile=Y;exports.logError=_e;exports.logger=G;exports.minimizeFile=ve;exports.saltyFileExtensions=ie;exports.saltyFileRegExp=we;
|
@@ -0,0 +1,498 @@
|
|
1
|
+
import * as gt from "esbuild";
|
2
|
+
import { execSync as xt } from "child_process";
|
3
|
+
import { d as G, t as v } from "./dash-case-DBThphLm.js";
|
4
|
+
import { join as r, parse as Y } from "path";
|
5
|
+
import { existsSync as it, writeFileSync as N, mkdirSync as I, readFileSync as E, statSync as Pt, readdirSync as kt } from "fs";
|
6
|
+
import { readFile as yt, writeFile as Dt } from "fs/promises";
|
7
|
+
import { p as at, a as _t } from "./parse-styles-CkaV3OGz.js";
|
8
|
+
import { createLogger as Tt, format as ot, transports as Et } from "winston";
|
9
|
+
import { mergeObjects as B, mergeFactories as Ot } from "./css/merge.js";
|
10
|
+
const ht = async (t, e = []) => {
|
11
|
+
if (!t) return "";
|
12
|
+
const s = [], n = {};
|
13
|
+
for (const [a, o] of Object.entries(t))
|
14
|
+
if (typeof o != "function") if (o && typeof o == "object") {
|
15
|
+
const i = a.trim(), d = await ht(o, [...e, i]);
|
16
|
+
s.push(d);
|
17
|
+
} else
|
18
|
+
n[a] = o;
|
19
|
+
if (Object.keys(n).length) {
|
20
|
+
const a = e.map(G).join("-"), o = "t_" + v(a, 4), i = await at(n, `.${a}, .${o}`);
|
21
|
+
s.push(i);
|
22
|
+
}
|
23
|
+
return s.join(`
|
24
|
+
`);
|
25
|
+
}, Vt = (t) => t ? Object.entries(t).reduce((e, [s, n]) => (typeof n == "function" ? e[s] = "any" : typeof n == "object" && (e[s] = $t(n).map((a) => `"${a}"`).join(" | ")), e), {}) : {}, $t = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([n, a]) => {
|
26
|
+
const o = e ? `${e}.${n}` : n;
|
27
|
+
return typeof a == "object" ? $t(a, o, s) : s.add(e);
|
28
|
+
}), [...s]) : [], bt = (t) => {
|
29
|
+
if (!t || t === "/") throw new Error("Could not find package.json file");
|
30
|
+
const e = r(t, "package.json");
|
31
|
+
return it(e) ? e : bt(r(t, ".."));
|
32
|
+
}, Mt = async (t) => {
|
33
|
+
const e = bt(t);
|
34
|
+
return await yt(e, "utf-8").then(JSON.parse).catch(() => {
|
35
|
+
});
|
36
|
+
}, vt = async (t) => {
|
37
|
+
const e = await Mt(t);
|
38
|
+
if (e)
|
39
|
+
return e.type;
|
40
|
+
};
|
41
|
+
let W;
|
42
|
+
const wt = async (t) => {
|
43
|
+
if (W) return W;
|
44
|
+
const e = await vt(t);
|
45
|
+
return e === "module" ? W = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (W = "cjs"), W || "esm";
|
46
|
+
}, X = Tt({
|
47
|
+
level: "debug",
|
48
|
+
format: ot.combine(ot.colorize(), ot.cli()),
|
49
|
+
transports: [new Et.Console({})]
|
50
|
+
}), Ut = (t) => {
|
51
|
+
X.error(t);
|
52
|
+
};
|
53
|
+
function St(t) {
|
54
|
+
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()) : "";
|
55
|
+
}
|
56
|
+
const Rt = {
|
57
|
+
/** Set box model to border-box */
|
58
|
+
"*, *::before, *::after": {
|
59
|
+
boxSizing: "border-box"
|
60
|
+
},
|
61
|
+
/** Remove default margin and padding */
|
62
|
+
"*": {
|
63
|
+
margin: 0
|
64
|
+
},
|
65
|
+
/** Remove adjust font properties */
|
66
|
+
html: {
|
67
|
+
lineHeight: 1.15,
|
68
|
+
textSizeAdjust: "100%",
|
69
|
+
WebkitFontSmoothing: "antialiased"
|
70
|
+
},
|
71
|
+
/** Make media elements responsive */
|
72
|
+
"img, picture, video, canvas, svg": {
|
73
|
+
display: "block",
|
74
|
+
maxWidth: "100%"
|
75
|
+
},
|
76
|
+
/** Avoid overflow of text */
|
77
|
+
"p, h1, h2, h3, h4, h5, h6": {
|
78
|
+
overflowWrap: "break-word"
|
79
|
+
},
|
80
|
+
/** Improve text wrapping */
|
81
|
+
p: {
|
82
|
+
textWrap: "pretty"
|
83
|
+
},
|
84
|
+
"h1, h2, h3, h4, h5, h6": {
|
85
|
+
textWrap: "balance"
|
86
|
+
},
|
87
|
+
/** Improve link color */
|
88
|
+
a: {
|
89
|
+
color: "currentColor"
|
90
|
+
},
|
91
|
+
/** Improve button line height */
|
92
|
+
button: {
|
93
|
+
lineHeight: "1em",
|
94
|
+
color: "currentColor"
|
95
|
+
},
|
96
|
+
/** Improve form elements */
|
97
|
+
"input, optgroup, select, textarea": {
|
98
|
+
fontFamily: "inherit",
|
99
|
+
fontSize: "100%",
|
100
|
+
lineHeight: "1.15em"
|
101
|
+
}
|
102
|
+
}, M = {
|
103
|
+
externalModules: [],
|
104
|
+
rcFile: void 0,
|
105
|
+
destDir: void 0
|
106
|
+
}, Ct = (t) => {
|
107
|
+
if (M.externalModules.length > 0) return M.externalModules;
|
108
|
+
const s = E(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
109
|
+
if (!s) return [];
|
110
|
+
const n = s[1].split(",").map((a) => a.replace(/['"`]/g, "").trim());
|
111
|
+
return M.externalModules = n, n;
|
112
|
+
}, R = async (t) => {
|
113
|
+
if (M.destDir) return M.destDir;
|
114
|
+
const e = await ct(t), s = r(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
115
|
+
return M.destDir = s, s;
|
116
|
+
}, Ft = ["salty", "css", "styles", "styled"], Jt = (t = []) => new RegExp(`\\.(${[...Ft, ...t].join("|")})\\.`), rt = (t, e = []) => Jt(e).test(t), jt = async (t) => {
|
117
|
+
if (M.rcFile) return M.rcFile;
|
118
|
+
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
119
|
+
const e = r(t, ".saltyrc.json"), s = await yt(e, "utf-8").then(JSON.parse).catch(() => {
|
120
|
+
});
|
121
|
+
return s ? (M.rcFile = s, s) : jt(r(t, ".."));
|
122
|
+
}, ct = async (t) => {
|
123
|
+
var n, a;
|
124
|
+
const e = await jt(t), s = (n = e.projects) == null ? void 0 : n.find((o) => t.endsWith(o.dir || ""));
|
125
|
+
return s || ((a = e.projects) == null ? void 0 : a.find((o) => o.dir === e.defaultProject));
|
126
|
+
}, zt = async (t) => {
|
127
|
+
const e = await ct(t), s = await R(t), n = r(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), a = r(s, "salty.config.js"), o = await wt(t), i = Ct(n);
|
128
|
+
await gt.build({
|
129
|
+
entryPoints: [n],
|
130
|
+
minify: !0,
|
131
|
+
treeShaking: !0,
|
132
|
+
bundle: !0,
|
133
|
+
outfile: a,
|
134
|
+
format: o,
|
135
|
+
external: i
|
136
|
+
});
|
137
|
+
const d = Date.now(), { config: C } = await import(`${a}?t=${d}`);
|
138
|
+
return C;
|
139
|
+
}, Wt = async (t, e) => {
|
140
|
+
var ut, pt;
|
141
|
+
const s = await R(t), n = {
|
142
|
+
mediaQueries: [],
|
143
|
+
globalStyles: [],
|
144
|
+
variables: [],
|
145
|
+
templates: []
|
146
|
+
};
|
147
|
+
await Promise.all(
|
148
|
+
[...e].map(async (m) => {
|
149
|
+
const { contents: w, outputFilePath: V } = await tt(t, m, s);
|
150
|
+
Object.entries(w).forEach(([k, _]) => {
|
151
|
+
_.isMedia ? n.mediaQueries.push([k, _]) : _.isGlobalDefine ? n.globalStyles.push(_) : _.isDefineVariables ? n.variables.push(_) : _.isDefineTemplates && n.templates.push(_._setPath(V));
|
152
|
+
});
|
153
|
+
})
|
154
|
+
);
|
155
|
+
const a = await zt(t), o = { ...a }, i = /* @__PURE__ */ new Set(), d = (m, w = []) => m ? Object.entries(m).flatMap(([V, k]) => {
|
156
|
+
if (!k) return;
|
157
|
+
if (typeof k == "object") return d(k, [...w, V]);
|
158
|
+
const _ = St(V), st = G(V), nt = [...w, _].join(".");
|
159
|
+
i.add(`"${nt}"`);
|
160
|
+
const U = [...w.map(G), st].join("-"), dt = _t(k);
|
161
|
+
return dt ? `--${U}: ${dt.transformed};` : `--${U}: ${k};`;
|
162
|
+
}) : [], C = (m) => m ? Object.entries(m).flatMap(([w, V]) => {
|
163
|
+
const k = d(V);
|
164
|
+
return w === "base" ? k.join("") : `${w} { ${k.join("")} }`;
|
165
|
+
}) : [], c = (m) => m ? Object.entries(m).flatMap(([w, V]) => Object.entries(V).flatMap(([k, _]) => {
|
166
|
+
const st = d(_, [w]), nt = `.${w}-${k}, [data-${w}="${k}"]`, U = st.join("");
|
167
|
+
return `${nt} { ${U} }`;
|
168
|
+
})) : [], u = (m) => ({ ...m, responsive: void 0, conditional: void 0 }), g = (m) => n.variables.map((w) => m === "static" ? u(w._current) : w._current[m]), p = B(u(a.variables), g("static")), $ = d(p), y = B((ut = a.variables) == null ? void 0 : ut.responsive, g("responsive")), F = C(y), x = B((pt = a.variables) == null ? void 0 : pt.conditional, g("conditional")), P = c(x), J = r(s, "css/_variables.css"), T = `:root { ${$.join("")} ${F.join("")} } ${P.join("")}`;
|
169
|
+
N(J, T), o.staticVariables = p;
|
170
|
+
const H = r(s, "css/_global.css"), D = B(a.global, n.globalStyles), K = await at(D, "");
|
171
|
+
N(H, `@layer global { ${K} }`);
|
172
|
+
const l = r(s, "css/_reset.css"), b = a.reset === "none" ? {} : typeof a.reset == "object" ? a.reset : Rt, f = await at(b, "");
|
173
|
+
N(l, `@layer reset { ${f} }`);
|
174
|
+
const S = r(s, "css/_templates.css"), j = B(a.templates, n.templates), O = await ht(j), A = Vt(j);
|
175
|
+
N(S, `@layer templates { ${O} }`), o.templates = j;
|
176
|
+
const L = Ot(n.templates);
|
177
|
+
o.templatePaths = Object.fromEntries(Object.entries(L).map(([m, w]) => [m, w._path]));
|
178
|
+
const { mediaQueries: z } = n;
|
179
|
+
o.mediaQueries = Object.fromEntries(z.map(([m, w]) => [`@${m}`, w]));
|
180
|
+
const Q = z.map(([m]) => `'@${m}'`).join(" | "), et = r(s, "types/css-tokens.d.ts"), q = `
|
181
|
+
// Variable types
|
182
|
+
type VariableTokens = ${[...i].join("|")};
|
183
|
+
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
184
|
+
|
185
|
+
// Template types
|
186
|
+
type TemplateTokens = {
|
187
|
+
${Object.entries(A).map(([m, w]) => `${m}?: ${w}`).join(`
|
188
|
+
`)}
|
189
|
+
}
|
190
|
+
|
191
|
+
// Media query types
|
192
|
+
type MediaQueryKeys = ${Q || "''"};
|
193
|
+
`;
|
194
|
+
N(et, q);
|
195
|
+
const Nt = r(s, "cache/config-cache.json");
|
196
|
+
N(Nt, JSON.stringify(o, null, 2));
|
197
|
+
}, mt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
198
|
+
if (/^['"`]/.test(s)) return e;
|
199
|
+
const a = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
200
|
+
if (!a.test(t)) return e;
|
201
|
+
const i = a.exec(t);
|
202
|
+
if (i) {
|
203
|
+
const d = i.at(1);
|
204
|
+
if (Ft.some((c) => d == null ? void 0 : d.includes(c))) return e;
|
205
|
+
}
|
206
|
+
return "styled('div',";
|
207
|
+
}), It = (t, e) => {
|
208
|
+
try {
|
209
|
+
const s = E(r(e, "saltygen/cache/config-cache.json"), "utf8");
|
210
|
+
return s ? `globalThis.saltyConfig = ${s};
|
211
|
+
|
212
|
+
${t}` : `globalThis.saltyConfig = {};
|
213
|
+
|
214
|
+
${t}`;
|
215
|
+
} catch {
|
216
|
+
return t;
|
217
|
+
}
|
218
|
+
}, tt = async (t, e, s) => {
|
219
|
+
const n = v(e), a = r(s, "./temp");
|
220
|
+
it(a) || I(a);
|
221
|
+
const o = Y(e);
|
222
|
+
let i = E(e, "utf8");
|
223
|
+
i = mt(i), i = It(i, t);
|
224
|
+
const d = r(s, "js", n + ".js"), C = await ct(t), c = r(t, (C == null ? void 0 : C.configDir) || "", "salty.config.ts"), u = Ct(c), g = await wt(t);
|
225
|
+
await gt.build({
|
226
|
+
stdin: {
|
227
|
+
contents: i,
|
228
|
+
sourcefile: o.base,
|
229
|
+
resolveDir: o.dir,
|
230
|
+
loader: "tsx"
|
231
|
+
},
|
232
|
+
minify: !1,
|
233
|
+
treeShaking: !0,
|
234
|
+
bundle: !0,
|
235
|
+
outfile: d,
|
236
|
+
format: g,
|
237
|
+
target: ["node20"],
|
238
|
+
keepNames: !0,
|
239
|
+
external: u,
|
240
|
+
packages: "external",
|
241
|
+
plugins: [
|
242
|
+
{
|
243
|
+
name: "test",
|
244
|
+
setup: (y) => {
|
245
|
+
y.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (F) => {
|
246
|
+
const x = E(F.path, "utf8");
|
247
|
+
return { contents: mt(x), loader: "ts" };
|
248
|
+
});
|
249
|
+
}
|
250
|
+
}
|
251
|
+
]
|
252
|
+
});
|
253
|
+
const p = Date.now();
|
254
|
+
return { contents: await import(`${d}?t=${p}`), outputFilePath: d };
|
255
|
+
}, Bt = async (t) => {
|
256
|
+
const e = await R(t), s = r(e, "cache/config-cache.json"), n = E(s, "utf8");
|
257
|
+
if (!n) throw new Error("Could not find config cache file");
|
258
|
+
return JSON.parse(n);
|
259
|
+
}, lt = async (t) => {
|
260
|
+
const e = await Bt(t), s = await R(t), n = r(s, "salty.config.js"), a = Date.now(), { config: o } = await import(`${n}?t=${a}`);
|
261
|
+
return B(o, e);
|
262
|
+
}, ft = () => {
|
263
|
+
try {
|
264
|
+
return process.env.NODE_ENV === "production";
|
265
|
+
} catch {
|
266
|
+
return !1;
|
267
|
+
}
|
268
|
+
}, Xt = async (t, e = ft(), s = !0) => {
|
269
|
+
try {
|
270
|
+
const n = Date.now();
|
271
|
+
e ? X.info("Generating CSS in production mode! 🔥") : X.info("Generating CSS in development mode! 🚀");
|
272
|
+
const a = [], o = [], i = await R(t), d = r(i, "index.css");
|
273
|
+
s && (() => {
|
274
|
+
it(i) && xt("rm -rf " + i), I(i, { recursive: !0 }), I(r(i, "css")), I(r(i, "types")), I(r(i, "js")), I(r(i, "cache"));
|
275
|
+
})();
|
276
|
+
const c = /* @__PURE__ */ new Set(), u = /* @__PURE__ */ new Set();
|
277
|
+
async function g(l) {
|
278
|
+
const h = ["node_modules", "saltygen"], b = Pt(l);
|
279
|
+
if (b.isDirectory()) {
|
280
|
+
const f = kt(l);
|
281
|
+
if (h.some((j) => l.includes(j))) return;
|
282
|
+
await Promise.all(f.map((j) => g(r(l, j))));
|
283
|
+
} else if (b.isFile() && rt(l)) {
|
284
|
+
c.add(l);
|
285
|
+
const S = E(l, "utf8");
|
286
|
+
/define[\w\d]+\(/.test(S) && u.add(l);
|
287
|
+
}
|
288
|
+
}
|
289
|
+
await g(t), await Wt(t, u);
|
290
|
+
const p = {
|
291
|
+
keyframes: [],
|
292
|
+
components: [],
|
293
|
+
classNames: []
|
294
|
+
};
|
295
|
+
await Promise.all(
|
296
|
+
[...c].map(async (l) => {
|
297
|
+
const { contents: h } = await tt(t, l, i);
|
298
|
+
Object.entries(h).forEach(([b, f]) => {
|
299
|
+
f.isKeyframes ? p.keyframes.push({
|
300
|
+
value: f,
|
301
|
+
src: l,
|
302
|
+
name: b
|
303
|
+
}) : f.isClassName ? p.classNames.push({
|
304
|
+
...f,
|
305
|
+
src: l,
|
306
|
+
name: b
|
307
|
+
}) : f.generator && p.components.push({
|
308
|
+
...f,
|
309
|
+
src: l,
|
310
|
+
name: b
|
311
|
+
});
|
312
|
+
});
|
313
|
+
})
|
314
|
+
);
|
315
|
+
const $ = await lt(t);
|
316
|
+
for (const l of p.keyframes) {
|
317
|
+
const { value: h } = l, b = `a_${h.animationName}.css`, f = `css/${b}`, S = r(i, f);
|
318
|
+
a.push(b), N(S, h.css);
|
319
|
+
}
|
320
|
+
const y = {};
|
321
|
+
for (const l of p.components) {
|
322
|
+
const { src: h, name: b } = l, f = l.generator._withBuildContext({
|
323
|
+
callerName: b,
|
324
|
+
isProduction: e,
|
325
|
+
config: $
|
326
|
+
});
|
327
|
+
o[f.priority] || (o[f.priority] = []);
|
328
|
+
const S = await f.css;
|
329
|
+
if (!S) continue;
|
330
|
+
o[f.priority].push(f.cssFileName);
|
331
|
+
const j = `css/${f.cssFileName}`, O = r(i, j);
|
332
|
+
N(O, S), $.importStrategy === "component" && (y[h] ? y[h].push(f.cssFileName) : y[h] = [f.cssFileName]);
|
333
|
+
}
|
334
|
+
for (const l of p.classNames) {
|
335
|
+
const { src: h, name: b } = l, f = l.generator._withBuildContext({
|
336
|
+
callerName: b,
|
337
|
+
isProduction: e,
|
338
|
+
config: $
|
339
|
+
}), S = await f.css;
|
340
|
+
if (!S) continue;
|
341
|
+
o[0].push(f.cssFileName);
|
342
|
+
const j = `css/${f.cssFileName}`, O = r(i, j);
|
343
|
+
N(O, S), $.importStrategy === "component" && (y[h] ? y[h].push(f.cssFileName) : y[h] = [f.cssFileName]);
|
344
|
+
}
|
345
|
+
$.importStrategy === "component" && Object.entries(y).forEach(([l, h]) => {
|
346
|
+
const b = h.map((A) => `@import url('./${A}');`).join(`
|
347
|
+
`), f = v(l, 6), S = Y(l), j = G(S.name), O = r(i, `css/f_${j}-${f}.css`);
|
348
|
+
N(O, b);
|
349
|
+
});
|
350
|
+
const F = a.map((l) => `@import url('./css/${l}');`).join(`
|
351
|
+
`);
|
352
|
+
let T = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
353
|
+
|
354
|
+
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((l) => {
|
355
|
+
try {
|
356
|
+
return E(r(i, "css", l), "utf8").length > 0;
|
357
|
+
} catch {
|
358
|
+
return !1;
|
359
|
+
}
|
360
|
+
}).map((l) => `@import url('./css/${l}');`).join(`
|
361
|
+
`)}
|
362
|
+
${F}`;
|
363
|
+
if ($.importStrategy !== "component") {
|
364
|
+
const l = o.reduce((h, b, f) => {
|
365
|
+
const S = b.reduce((L, z) => {
|
366
|
+
var q;
|
367
|
+
const Q = r(i, "css", z), et = E(Q, "utf8"), Z = ((q = /.*-([^-]+)-\d+.css/.exec(z)) == null ? void 0 : q.at(1)) || v(Q, 6);
|
368
|
+
return L.includes(Z) ? L : `${L}
|
369
|
+
/*start:${Z}-${z}*/
|
370
|
+
${et}
|
371
|
+
/*end:${Z}*/
|
372
|
+
`;
|
373
|
+
}, ""), j = `l_${f}.css`, O = r(i, "css", j), A = `@layer l${f} { ${S}
|
374
|
+
}`;
|
375
|
+
return N(O, A), `${h}
|
376
|
+
@import url('./css/${j}');`;
|
377
|
+
}, "");
|
378
|
+
T += l;
|
379
|
+
}
|
380
|
+
N(d, T);
|
381
|
+
const D = Date.now() - n, K = D < 200 ? "🔥" : D < 500 ? "🚀" : D < 1e3 ? "🎉" : D < 2e3 ? "🚗" : D < 5e3 ? "🤔" : "🥴";
|
382
|
+
X.info(`Generated CSS in ${D}ms! ${K}`);
|
383
|
+
} catch (n) {
|
384
|
+
console.error(n);
|
385
|
+
}
|
386
|
+
}, Yt = async (t, e, s = ft()) => {
|
387
|
+
try {
|
388
|
+
const n = await R(t);
|
389
|
+
if (rt(e)) {
|
390
|
+
const o = [], i = await lt(t), { contents: d } = await tt(t, e, n);
|
391
|
+
for (const [C, c] of Object.entries(d)) {
|
392
|
+
if (c.isKeyframes && c.css) {
|
393
|
+
const F = `css/${`a_${c.animationName}.css`}`, x = r(n, F);
|
394
|
+
N(x, await c.css);
|
395
|
+
return;
|
396
|
+
}
|
397
|
+
if (c.isClassName) {
|
398
|
+
const y = c.generator._withBuildContext({
|
399
|
+
callerName: C,
|
400
|
+
isProduction: s,
|
401
|
+
config: i
|
402
|
+
}), F = await y.css;
|
403
|
+
if (!F) continue;
|
404
|
+
o[0].push(y.cssFileName);
|
405
|
+
const x = `css/${y.cssFileName}`, P = r(n, x);
|
406
|
+
N(P, F);
|
407
|
+
}
|
408
|
+
if (!c.generator) return;
|
409
|
+
const u = c.generator._withBuildContext({
|
410
|
+
callerName: C,
|
411
|
+
isProduction: s,
|
412
|
+
config: i
|
413
|
+
}), g = await u.css;
|
414
|
+
if (!g) continue;
|
415
|
+
const p = `css/${u.cssFileName}`, $ = r(n, p);
|
416
|
+
N($, g), o[u.priority] || (o[u.priority] = []), o[u.priority].push(u.cssFileName);
|
417
|
+
}
|
418
|
+
if (i.importStrategy !== "component")
|
419
|
+
o.forEach((C, c) => {
|
420
|
+
const u = `l_${c}.css`, g = r(n, "css", u);
|
421
|
+
let p = E(g, "utf8");
|
422
|
+
C.forEach(($) => {
|
423
|
+
var P;
|
424
|
+
const y = r(n, "css", $), F = ((P = /.*-([^-]+)-\d+.css/.exec($)) == null ? void 0 : P.at(1)) || v(y, 6);
|
425
|
+
if (!p.includes(F)) {
|
426
|
+
const J = E(y, "utf8"), T = `/*start:${F}-${$}*/
|
427
|
+
${J}
|
428
|
+
/*end:${F}*/
|
429
|
+
`;
|
430
|
+
p = `${p.replace(/\}$/, "")}
|
431
|
+
${T}
|
432
|
+
}`;
|
433
|
+
}
|
434
|
+
}), N(g, p);
|
435
|
+
});
|
436
|
+
else {
|
437
|
+
const C = o.flat().map(($) => `@import url('./${$}');`).join(`
|
438
|
+
`), c = v(e, 6), u = Y(e), g = G(u.name), p = r(n, `css/f_${g}-${c}.css`);
|
439
|
+
N(p, C);
|
440
|
+
}
|
441
|
+
}
|
442
|
+
} catch (n) {
|
443
|
+
console.error(n);
|
444
|
+
}
|
445
|
+
}, te = async (t, e, s = ft()) => {
|
446
|
+
try {
|
447
|
+
const n = await R(t);
|
448
|
+
if (rt(e)) {
|
449
|
+
const o = E(e, "utf8");
|
450
|
+
o.replace(/^(?!export\s)const\s.*/gm, (u) => `export ${u}`) !== o && await Dt(e, o);
|
451
|
+
const d = await lt(t), { contents: C } = await tt(t, e, n);
|
452
|
+
let c = o;
|
453
|
+
if (Object.entries(C).forEach(([u, g]) => {
|
454
|
+
var f;
|
455
|
+
if (g.isKeyframes || !g.generator) return;
|
456
|
+
const p = g.generator._withBuildContext({
|
457
|
+
callerName: u,
|
458
|
+
isProduction: s,
|
459
|
+
config: d
|
460
|
+
}), $ = new RegExp(`\\s${u}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(o);
|
461
|
+
if (!$) return console.error("Could not find the original declaration");
|
462
|
+
const y = (f = $.at(1)) == null ? void 0 : f.trim(), F = new RegExp(`\\s${u}[=\\s]+styled\\(`, "g").exec(c);
|
463
|
+
if (!F) return console.error("Could not find the original declaration");
|
464
|
+
const { index: x } = F;
|
465
|
+
let P = !1;
|
466
|
+
const J = setTimeout(() => P = !0, 5e3);
|
467
|
+
let T = 0, H = !1, D = 0;
|
468
|
+
for (; !H && !P; ) {
|
469
|
+
const S = c[x + T];
|
470
|
+
S === "(" && D++, S === ")" && D--, D === 0 && S === ")" && (H = !0), T > c.length && (P = !0), T++;
|
471
|
+
}
|
472
|
+
if (!P) clearTimeout(J);
|
473
|
+
else throw new Error("Failed to find the end of the styled call and timed out");
|
474
|
+
const K = x + T, l = c.slice(x, K), h = c, b = ` ${u} = styled(${y}, "${p.classNames}", ${JSON.stringify(p.clientProps)});`;
|
475
|
+
c = c.replace(l, b), h === c && console.error("Minimize file failed to change content", { name: u, tagName: y });
|
476
|
+
}), d.importStrategy === "component") {
|
477
|
+
const u = v(e, 6), g = Y(e);
|
478
|
+
c = `import '../../saltygen/css/${`f_${G(g.name)}-${u}.css`}';
|
479
|
+
${c}`;
|
480
|
+
}
|
481
|
+
return c = c.replace("{ styled }", "{ styledClient as styled }"), c = c.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), c;
|
482
|
+
}
|
483
|
+
} catch (n) {
|
484
|
+
console.error("Error in minimizeFile:", n);
|
485
|
+
}
|
486
|
+
};
|
487
|
+
export {
|
488
|
+
Ut as a,
|
489
|
+
Jt as b,
|
490
|
+
Wt as c,
|
491
|
+
tt as d,
|
492
|
+
Yt as e,
|
493
|
+
Xt as g,
|
494
|
+
rt as i,
|
495
|
+
X as l,
|
496
|
+
te as m,
|
497
|
+
Ft as s
|
498
|
+
};
|
package/package.json
CHANGED
package/server/index.cjs
CHANGED
@@ -1 +1 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-BZxPdVzL.cjs"),i=async t=>{if(!t||t.includes("node_modules")||t.includes("saltygen"))return!1;if(t.includes("salty.config"))return!0;if(!r.isSaltyFile(t))return!1;const e=await s.readFile(t,"utf-8");return!!/.+define[A-Z]\w+/.test(e)};exports.checkShouldRestart=i;
|
package/server/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { readFile as r } from "fs/promises";
|
2
|
-
import { i as e } from "../index-
|
2
|
+
import { i as e } from "../index-Djy7Z9Ft.js";
|
3
3
|
const f = async (t) => {
|
4
4
|
if (!t || t.includes("node_modules") || t.includes("saltygen")) return !1;
|
5
5
|
if (t.includes("salty.config")) return !0;
|
package/index-BwBIR0y8.cjs
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
"use strict";const Ce=require("esbuild"),xe=require("child_process"),P=require("./dash-case-BJEkFEGQ.cjs"),r=require("path"),a=require("fs"),oe=require("fs/promises"),X=require("./parse-styles-DKWtadpv.cjs"),B=require("winston"),M=require("./css/merge.cjs");var ne=typeof document<"u"?document.currentScript:null;function Ne(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const de=Ne(Ce),pe=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,i]of Object.entries(e))if(typeof i!="function")if(i&&typeof i=="object"){const c=o.trim(),d=await pe(i,[...t,c]);s.push(d)}else n[o]=i;if(Object.keys(n).length){const o=t.map(P.dashCase).join("-"),i="t_"+P.toHash(o,4),c=await X.parseAndJoinStyles(n,`.${o}, .${i}`);s.push(c)}return s.join(`
|
2
|
-
`)},ke=e=>e?Object.entries(e).reduce((t,[s,n])=>(typeof n=="function"?t[s]="any":typeof n=="object"&&(t[s]=ye(n).map(o=>`"${o}"`).join(" | ")),t),{}):{},ye=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const i=t?`${t}.${n}`:n;return typeof o=="object"?ye(o,i,s):s.add(t)}),[...s]):[],me=e=>{if(!e||e==="/")throw new Error("Could not find package.json file");const t=r.join(e,"package.json");return a.existsSync(t)?t:me(r.join(e,".."))},Pe=async e=>{const t=me(e);return await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},De=async e=>{const t=await Pe(e);if(t)return t.type};let z;const ge=async e=>{if(z)return z;const t=await De(e);return t==="module"?z="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ne&&ne.tagName.toUpperCase()==="SCRIPT"&&ne.src||new URL("index-BwBIR0y8.cjs",document.baseURI).href).endsWith(".cjs"))&&(z="cjs"),z||"esm"},G=B.createLogger({level:"debug",format:B.format.combine(B.format.colorize(),B.format.cli()),transports:[new B.transports.Console({})]}),_e=e=>{G.error(e)};function he(e){return e?typeof e!="string"?he(String(e)):e.replace(/[\s-]/g,".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g,(t,s)=>(s>0?".":"")+t.toLowerCase()):""}const Oe={"*, *::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"}},V={externalModules:[],rcFile:void 0,destDir:void 0},Se=e=>{if(V.externalModules.length>0)return V.externalModules;const s=a.readFileSync(e,"utf8").match(/externalModules:\s?\[(.*)\]/);if(!s)return[];const n=s[1].split(",").map(o=>o.replace(/['"`]/g,"").trim());return V.externalModules=n,n},v=async e=>{if(V.destDir)return V.destDir;const t=await re(e),s=r.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},ie=["salty","css","styles","styled"],je=(e=[])=>new RegExp(`\\.(${[...ie,...e].join("|")})\\.`),Y=(e,t=[])=>je(t).test(e),we=async e=>{if(V.rcFile)return V.rcFile;if(e==="/")throw new Error("Could not find .saltyrc.json file");const t=r.join(e,".saltyrc.json"),s=await oe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):we(r.join(e,".."))},re=async e=>{var n,o;const t=await we(e),s=(n=t.projects)==null?void 0:n.find(i=>e.endsWith(i.dir||""));return s||((o=t.projects)==null?void 0:o.find(i=>i.dir===t.defaultProject))},Te=async e=>{const t=await re(e),s=await v(e),n=r.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=r.join(s,"salty.config.js"),i=await ge(e),c=Se(n);await de.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:i,external:c});const d=Date.now(),{config:y}=await import(`${o}?t=${d}`);return y},be=async(e,t)=>{var ce,le;const s=await v(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async h=>{const{contents:F,outputFilePath:R}=await K(e,h,s);Object.entries(F).forEach(([k,_])=>{_.isMedia?n.mediaQueries.push([k,_]):_.isGlobalDefine?n.globalStyles.push(_):_.isDefineVariables?n.variables.push(_):_.isDefineTemplates&&n.templates.push(_._setPath(R))})}));const o=await Te(e),i={...o},c=new Set,d=(h,F=[])=>h?Object.entries(h).flatMap(([R,k])=>{if(!k)return;if(typeof k=="object")return d(k,[...F,R]);const _=he(R),te=P.dashCase(R),se=[...F,_].join(".");c.add(`"${se}"`);const U=[...F.map(P.dashCase),te].join("-"),fe=X.parseVariableTokens(k);return fe?`--${U}: ${fe.transformed};`:`--${U}: ${k};`}):[],y=h=>h?Object.entries(h).flatMap(([F,R])=>{const k=d(R);return F==="base"?k.join(""):`${F} { ${k.join("")} }`}):[],u=h=>h?Object.entries(h).flatMap(([F,R])=>Object.entries(R).flatMap(([k,_])=>{const te=d(_,[F]),se=`.${F}-${k}, [data-${F}="${k}"]`,U=te.join("");return`${se} { ${U} }`})):[],p=h=>({...h,responsive:void 0,conditional:void 0}),m=h=>n.variables.map(F=>h==="static"?p(F._current):F._current[h]),S=M.mergeObjects(p(o.variables),m("static")),w=d(S),g=M.mergeObjects((ce=o.variables)==null?void 0:ce.responsive,m("responsive")),x=y(g),N=M.mergeObjects((le=o.variables)==null?void 0:le.conditional,m("conditional")),O=u(N),J=r.join(s,"css/_variables.css"),T=`:root { ${w.join("")} ${x.join("")} } ${O.join("")}`;a.writeFileSync(J,T),i.staticVariables=S;const H=r.join(s,"css/_global.css"),D=M.mergeObjects(o.global,n.globalStyles),q=await X.parseAndJoinStyles(D,"");a.writeFileSync(H,`@layer global { ${q} }`);const l=r.join(s,"css/_reset.css"),b=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:Oe,f=await X.parseAndJoinStyles(b,"");a.writeFileSync(l,`@layer reset { ${f} }`);const $=r.join(s,"css/_templates.css"),C=M.mergeObjects(o.templates,n.templates),E=await pe(C),I=ke(C);a.writeFileSync($,`@layer templates { ${E} }`),i.templates=C;const W=M.mergeFactories(n.templates);i.templatePaths=Object.fromEntries(Object.entries(W).map(([h,F])=>[h,F._path]));const{mediaQueries:A}=n;i.mediaQueries=Object.fromEntries(A.map(([h,F])=>[`@${h}`,F]));const L=A.map(([h])=>`'@${h}'`).join(" | "),ee=r.join(s,"types/css-tokens.d.ts"),Z=`
|
3
|
-
// Variable types
|
4
|
-
type VariableTokens = ${[...c].join("|")};
|
5
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
6
|
-
|
7
|
-
// Template types
|
8
|
-
type TemplateTokens = {
|
9
|
-
${Object.entries(I).map(([h,F])=>`${h}?: ${F}`).join(`
|
10
|
-
`)}
|
11
|
-
}
|
12
|
-
|
13
|
-
// Media query types
|
14
|
-
type MediaQueryKeys = ${L||"''"};
|
15
|
-
`;a.writeFileSync(ee,Z);const $e=r.join(s,"cache/config-cache.json");a.writeFileSync($e,JSON.stringify(i,null,2))},ue=e=>e.replace(/styled\(([^"'`{,]+),/g,(t,s)=>{if(/^['"`]/.test(s))return t;const o=new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);if(!o.test(e))return t;const c=o.exec(e);if(c){const d=c.at(1);if(ie.some(u=>d==null?void 0:d.includes(u)))return t}return"styled('div',"}),Ee=(e,t)=>{try{const s=a.readFileSync(r.join(t,"saltygen/cache/config-cache.json"),"utf8");return s?`globalThis.saltyConfig = ${s};
|
16
|
-
|
17
|
-
${e}`:`globalThis.saltyConfig = {};
|
18
|
-
|
19
|
-
${e}`}catch{return e}},K=async(e,t,s)=>{const n=P.toHash(t),o=r.join(s,"./temp");a.existsSync(o)||a.mkdirSync(o);const i=r.parse(t);let c=a.readFileSync(t,"utf8");c=ue(c),c=Ee(c,e);const d=r.join(s,"js",n+".js"),y=await re(e),u=r.join(e,(y==null?void 0:y.configDir)||"","salty.config.ts"),p=Se(u),m=await ge(e);await de.build({stdin:{contents:c,sourcefile:i.base,resolveDir:i.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:d,format:m,target:["node20"],keepNames:!0,external:p,packages:"external",plugins:[{name:"test",setup:g=>{g.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},x=>{const N=a.readFileSync(x.path,"utf8");return{contents:ue(N),loader:"ts"}})}}]});const S=Date.now();return{contents:await import(`${d}?t=${S}`),outputFilePath:d}},Re=async e=>{const t=await v(e),s=r.join(t,"cache/config-cache.json"),n=a.readFileSync(s,"utf8");if(!n)throw new Error("Could not find config cache file");return JSON.parse(n)},ae=async e=>{const t=await Re(e),s=await v(e),n=r.join(s,"salty.config.js"),o=Date.now(),{config:i}=await import(`${n}?t=${o}`);return M.mergeObjects(i,t)},Fe=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Ve=async(e,t=Fe(),s=!0)=>{try{const n=Date.now();t?G.info("Generating CSS in production mode! 🔥"):G.info("Generating CSS in development mode! 🚀");const o=[],i=[],c=await v(e),d=r.join(c,"index.css");s&&(()=>{a.existsSync(c)&&xe.execSync("rm -rf "+c),a.mkdirSync(c,{recursive:!0}),a.mkdirSync(r.join(c,"css")),a.mkdirSync(r.join(c,"types")),a.mkdirSync(r.join(c,"js")),a.mkdirSync(r.join(c,"cache"))})();const u=new Set,p=new Set;async function m(l){const j=["node_modules","saltygen"],b=a.statSync(l);if(b.isDirectory()){const f=a.readdirSync(l);if(j.some(C=>l.includes(C)))return;await Promise.all(f.map(C=>m(r.join(l,C))))}else if(b.isFile()&&Y(l)){u.add(l);const $=a.readFileSync(l,"utf8");/define[\w\d]+\(/.test($)&&p.add(l)}}await m(e),await be(e,p);const S={keyframes:[],components:[],classNames:[]};await Promise.all([...u].map(async l=>{const{contents:j}=await K(e,l,c);Object.entries(j).forEach(([b,f])=>{f.isKeyframes?S.keyframes.push({value:f,src:l,name:b}):f.isClassName?S.classNames.push({...f,src:l,name:b}):f.generator&&S.components.push({...f,src:l,name:b})})}));const w=await ae(e);for(const l of S.keyframes){const{value:j}=l,b=`a_${j.animationName}.css`,f=`css/${b}`,$=r.join(c,f);o.push(b),a.writeFileSync($,j.css)}const g={};for(const l of S.components){const{src:j,name:b}=l,f=l.generator._withBuildContext({callerName:b,isProduction:t,config:w});i[f.priority]||(i[f.priority]=[]);const $=await f.css;if(!$)continue;i[f.priority].push(f.cssFileName);const C=`css/${f.cssFileName}`,E=r.join(c,C);a.writeFileSync(E,$),w.importStrategy==="component"&&(g[j]?g[j].push(f.cssFileName):g[j]=[f.cssFileName])}for(const l of S.classNames){const{src:j,name:b}=l,f=l.generator._withBuildContext({callerName:b,isProduction:t,config:w}),$=await f.css;if(!$)continue;i[0].push(f.cssFileName);const C=`css/${f.cssFileName}`,E=r.join(c,C);a.writeFileSync(E,$),w.importStrategy==="component"&&(g[j]?g[j].push(f.cssFileName):g[j]=[f.cssFileName])}w.importStrategy==="component"&&Object.entries(g).forEach(([l,j])=>{const b=j.map(I=>`@import url('./${I}');`).join(`
|
20
|
-
`),f=P.toHash(l,6),$=r.parse(l),C=P.dashCase($.name),E=r.join(c,`css/f_${C}-${f}.css`);a.writeFileSync(E,b)});const x=o.map(l=>`@import url('./css/${l}');`).join(`
|
21
|
-
`);let T=`@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
22
|
-
|
23
|
-
${["_variables.css","_reset.css","_global.css","_templates.css"].filter(l=>{try{return a.readFileSync(r.join(c,"css",l),"utf8").length>0}catch{return!1}}).map(l=>`@import url('./css/${l}');`).join(`
|
24
|
-
`)}
|
25
|
-
${x}`;if(w.importStrategy!=="component"){const l=i.reduce((j,b,f)=>{const $=b.reduce((W,A)=>{var Z;const L=r.join(c,"css",A),ee=a.readFileSync(L,"utf8"),Q=((Z=/.*-([^-]+)-\d+.css/.exec(A))==null?void 0:Z.at(1))||P.toHash(L,6);return W.includes(Q)?W:`${W}
|
26
|
-
/*start:${Q}*/
|
27
|
-
${ee}
|
28
|
-
/*end:${Q}*/
|
29
|
-
`},""),C=`l_${f}.css`,E=r.join(c,"css",C),I=`@layer l${f} { ${$}
|
30
|
-
}`;return a.writeFileSync(E,I),`${j}
|
31
|
-
@import url('./css/${C}');`},"");T+=l}a.writeFileSync(d,T);const D=Date.now()-n,q=D<200?"🔥":D<500?"🚀":D<1e3?"🎉":D<2e3?"🚗":D<5e3?"🤔":"🥴";G.info(`Generated CSS in ${D}ms! ${q}`)}catch(n){console.error(n)}},Me=async(e,t)=>{try{const s=await v(e);if(Y(t)){const o=[],i=await ae(e),{contents:c}=await K(e,t,s);for(const[d,y]of Object.entries(c)){if(y.isKeyframes&&y.css){const g=`css/${`a_${y.animationName}.css`}`,x=r.join(s,g);a.writeFileSync(x,await y.css);return}if(y.isClassName){const w=y.generator._withBuildContext({name:d}),g=await w.css;if(!g)continue;o[0].push(w.cssFileName);const x=`css/${w.cssFileName}`,N=r.join(s,x);a.writeFileSync(N,g)}if(!y.generator)return;const u=y.generator._withBuildContext({name:d,config:i}),p=await u.css;if(!p)continue;const m=`css/${u.cssFileName}`,S=r.join(s,m);a.writeFileSync(S,p),o[u.priority]||(o[u.priority]=[]),o[u.priority].push(u.cssFileName)}if(i.importStrategy!=="component")o.forEach((d,y)=>{const u=`l_${y}.css`,p=r.join(s,"css",u);let m=a.readFileSync(p,"utf8");d.forEach(S=>{var N;const w=r.join(s,"css",S),g=((N=/.*-([^-]+)-\d+.css/.exec(S))==null?void 0:N.at(1))||P.toHash(w,6);if(!m.includes(g)){const O=a.readFileSync(w,"utf8"),J=`/*start:${g}*/
|
32
|
-
${O}
|
33
|
-
/*end:${g}*/
|
34
|
-
`;m=`${m.replace(/\}$/,"")}
|
35
|
-
${J}
|
36
|
-
}`}}),a.writeFileSync(p,m)});else{const d=o.flat().map(S=>`@import url('./${S}');`).join(`
|
37
|
-
`),y=P.toHash(t,6),u=r.parse(t),p=P.dashCase(u.name),m=r.join(s,`css/f_${p}-${y}.css`);a.writeFileSync(m,d)}}}catch(s){console.error(s)}},ve=async(e,t,s=Fe())=>{try{const n=await v(e);if(Y(t)){const i=a.readFileSync(t,"utf8");i.replace(/^(?!export\s)const\s.*/gm,p=>`export ${p}`)!==i&&await oe.writeFile(t,i);const d=await ae(e),{contents:y}=await K(e,t,n);let u=i;if(Object.entries(y).forEach(([p,m])=>{var f;if(m.isKeyframes||!m.generator)return;const S=m.generator._withBuildContext({name:p,config:d,prod:s}),w=new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`,"g").exec(i);if(!w)return console.error("Could not find the original declaration");const g=(f=w.at(1))==null?void 0:f.trim(),x=new RegExp(`\\s${p}[=\\s]+styled\\(`,"g").exec(u);if(!x)return console.error("Could not find the original declaration");const{index:N}=x;let O=!1;const J=setTimeout(()=>O=!0,5e3);let T=0,H=!1,D=0;for(;!H&&!O;){const $=u[N+T];$==="("&&D++,$===")"&&D--,D===0&&$===")"&&(H=!0),T>u.length&&(O=!0),T++}if(!O)clearTimeout(J);else throw new Error("Failed to find the end of the styled call and timed out");const q=N+T,l=u.slice(N,q),j=u,b=` ${p} = styled(${g}, "${S.classNames}", ${JSON.stringify(S.clientProps)});`;u=u.replace(l,b),j===u&&console.error("Minimize file failed to change content",{name:p,tagName:g})}),d.importStrategy==="component"){const p=P.toHash(t,6),m=r.parse(t);u=`import '../../saltygen/css/${`f_${P.dashCase(m.name)}-${p}.css`}';
|
38
|
-
${u}`}return u=u.replace("{ styled }","{ styledClient as styled }"),u=u.replace("@salty-css/react/styled","@salty-css/react/styled-client"),u}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=K;exports.generateConfigStyles=be;exports.generateCss=Ve;exports.generateFile=Me;exports.isSaltyFile=Y;exports.logError=_e;exports.logger=G;exports.minimizeFile=ve;exports.saltyFileExtensions=ie;exports.saltyFileRegExp=je;
|
package/index-ED4VBH54.js
DELETED
@@ -1,495 +0,0 @@
|
|
1
|
-
import * as mt from "esbuild";
|
2
|
-
import { execSync as Nt } from "child_process";
|
3
|
-
import { d as B, t as v } from "./dash-case-DBThphLm.js";
|
4
|
-
import { join as i, parse as Y } from "path";
|
5
|
-
import { existsSync as it, writeFileSync as j, mkdirSync as W, readFileSync as _, statSync as Pt, readdirSync as kt } from "fs";
|
6
|
-
import { readFile as gt, writeFile as Dt } from "fs/promises";
|
7
|
-
import { p as at, a as _t } from "./parse-styles-CkaV3OGz.js";
|
8
|
-
import { createLogger as Tt, format as ot, transports as Et } from "winston";
|
9
|
-
import { mergeObjects as I, mergeFactories as Ot } from "./css/merge.js";
|
10
|
-
const yt = async (t, e = []) => {
|
11
|
-
if (!t) return "";
|
12
|
-
const s = [], o = {};
|
13
|
-
for (const [n, a] of Object.entries(t))
|
14
|
-
if (typeof a != "function") if (a && typeof a == "object") {
|
15
|
-
const r = n.trim(), u = await yt(a, [...e, r]);
|
16
|
-
s.push(u);
|
17
|
-
} else
|
18
|
-
o[n] = a;
|
19
|
-
if (Object.keys(o).length) {
|
20
|
-
const n = e.map(B).join("-"), a = "t_" + v(n, 4), r = await at(o, `.${n}, .${a}`);
|
21
|
-
s.push(r);
|
22
|
-
}
|
23
|
-
return s.join(`
|
24
|
-
`);
|
25
|
-
}, Vt = (t) => t ? Object.entries(t).reduce((e, [s, o]) => (typeof o == "function" ? e[s] = "any" : typeof o == "object" && (e[s] = ht(o).map((n) => `"${n}"`).join(" | ")), e), {}) : {}, ht = (t, e = "", s = /* @__PURE__ */ new Set()) => t ? (Object.entries(t).forEach(([o, n]) => {
|
26
|
-
const a = e ? `${e}.${o}` : o;
|
27
|
-
return typeof n == "object" ? ht(n, a, s) : s.add(e);
|
28
|
-
}), [...s]) : [], bt = (t) => {
|
29
|
-
if (!t || t === "/") throw new Error("Could not find package.json file");
|
30
|
-
const e = i(t, "package.json");
|
31
|
-
return it(e) ? e : bt(i(t, ".."));
|
32
|
-
}, Mt = async (t) => {
|
33
|
-
const e = bt(t);
|
34
|
-
return await gt(e, "utf-8").then(JSON.parse).catch(() => {
|
35
|
-
});
|
36
|
-
}, vt = async (t) => {
|
37
|
-
const e = await Mt(t);
|
38
|
-
if (e)
|
39
|
-
return e.type;
|
40
|
-
};
|
41
|
-
let z;
|
42
|
-
const $t = async (t) => {
|
43
|
-
if (z) return z;
|
44
|
-
const e = await vt(t);
|
45
|
-
return e === "module" ? z = "esm" : (e === "commonjs" || import.meta.url.endsWith(".cjs")) && (z = "cjs"), z || "esm";
|
46
|
-
}, X = Tt({
|
47
|
-
level: "debug",
|
48
|
-
format: ot.combine(ot.colorize(), ot.cli()),
|
49
|
-
transports: [new Et.Console({})]
|
50
|
-
}), Ut = (t) => {
|
51
|
-
X.error(t);
|
52
|
-
};
|
53
|
-
function wt(t) {
|
54
|
-
return t ? typeof t != "string" ? wt(String(t)) : t.replace(/[\s-]/g, ".").replace(/[A-Z](?:(?=[^A-Z])|[A-Z]*(?=[A-Z][^A-Z]|$))/g, (e, s) => (s > 0 ? "." : "") + e.toLowerCase()) : "";
|
55
|
-
}
|
56
|
-
const Rt = {
|
57
|
-
/** Set box model to border-box */
|
58
|
-
"*, *::before, *::after": {
|
59
|
-
boxSizing: "border-box"
|
60
|
-
},
|
61
|
-
/** Remove default margin and padding */
|
62
|
-
"*": {
|
63
|
-
margin: 0
|
64
|
-
},
|
65
|
-
/** Remove adjust font properties */
|
66
|
-
html: {
|
67
|
-
lineHeight: 1.15,
|
68
|
-
textSizeAdjust: "100%",
|
69
|
-
WebkitFontSmoothing: "antialiased"
|
70
|
-
},
|
71
|
-
/** Make media elements responsive */
|
72
|
-
"img, picture, video, canvas, svg": {
|
73
|
-
display: "block",
|
74
|
-
maxWidth: "100%"
|
75
|
-
},
|
76
|
-
/** Avoid overflow of text */
|
77
|
-
"p, h1, h2, h3, h4, h5, h6": {
|
78
|
-
overflowWrap: "break-word"
|
79
|
-
},
|
80
|
-
/** Improve text wrapping */
|
81
|
-
p: {
|
82
|
-
textWrap: "pretty"
|
83
|
-
},
|
84
|
-
"h1, h2, h3, h4, h5, h6": {
|
85
|
-
textWrap: "balance"
|
86
|
-
},
|
87
|
-
/** Improve link color */
|
88
|
-
a: {
|
89
|
-
color: "currentColor"
|
90
|
-
},
|
91
|
-
/** Improve button line height */
|
92
|
-
button: {
|
93
|
-
lineHeight: "1em",
|
94
|
-
color: "currentColor"
|
95
|
-
},
|
96
|
-
/** Improve form elements */
|
97
|
-
"input, optgroup, select, textarea": {
|
98
|
-
fontFamily: "inherit",
|
99
|
-
fontSize: "100%",
|
100
|
-
lineHeight: "1.15em"
|
101
|
-
}
|
102
|
-
}, M = {
|
103
|
-
externalModules: [],
|
104
|
-
rcFile: void 0,
|
105
|
-
destDir: void 0
|
106
|
-
}, St = (t) => {
|
107
|
-
if (M.externalModules.length > 0) return M.externalModules;
|
108
|
-
const s = _(t, "utf8").match(/externalModules:\s?\[(.*)\]/);
|
109
|
-
if (!s) return [];
|
110
|
-
const o = s[1].split(",").map((n) => n.replace(/['"`]/g, "").trim());
|
111
|
-
return M.externalModules = o, o;
|
112
|
-
}, R = async (t) => {
|
113
|
-
if (M.destDir) return M.destDir;
|
114
|
-
const e = await ct(t), s = i(t, (e == null ? void 0 : e.saltygenDir) || "saltygen");
|
115
|
-
return M.destDir = s, s;
|
116
|
-
}, Ct = ["salty", "css", "styles", "styled"], Jt = (t = []) => new RegExp(`\\.(${[...Ct, ...t].join("|")})\\.`), rt = (t, e = []) => Jt(e).test(t), Ft = async (t) => {
|
117
|
-
if (M.rcFile) return M.rcFile;
|
118
|
-
if (t === "/") throw new Error("Could not find .saltyrc.json file");
|
119
|
-
const e = i(t, ".saltyrc.json"), s = await gt(e, "utf-8").then(JSON.parse).catch(() => {
|
120
|
-
});
|
121
|
-
return s ? (M.rcFile = s, s) : Ft(i(t, ".."));
|
122
|
-
}, ct = async (t) => {
|
123
|
-
var o, n;
|
124
|
-
const e = await Ft(t), s = (o = e.projects) == null ? void 0 : o.find((a) => t.endsWith(a.dir || ""));
|
125
|
-
return s || ((n = e.projects) == null ? void 0 : n.find((a) => a.dir === e.defaultProject));
|
126
|
-
}, zt = async (t) => {
|
127
|
-
const e = await ct(t), s = await R(t), o = i(t, (e == null ? void 0 : e.configDir) || "", "salty.config.ts"), n = i(s, "salty.config.js"), a = await $t(t), r = St(o);
|
128
|
-
await mt.build({
|
129
|
-
entryPoints: [o],
|
130
|
-
minify: !0,
|
131
|
-
treeShaking: !0,
|
132
|
-
bundle: !0,
|
133
|
-
outfile: n,
|
134
|
-
format: a,
|
135
|
-
external: r
|
136
|
-
});
|
137
|
-
const u = Date.now(), { config: d } = await import(`${n}?t=${u}`);
|
138
|
-
return d;
|
139
|
-
}, Wt = async (t, e) => {
|
140
|
-
var ft, ut;
|
141
|
-
const s = await R(t), o = {
|
142
|
-
mediaQueries: [],
|
143
|
-
globalStyles: [],
|
144
|
-
variables: [],
|
145
|
-
templates: []
|
146
|
-
};
|
147
|
-
await Promise.all(
|
148
|
-
[...e].map(async (y) => {
|
149
|
-
const { contents: S, outputFilePath: V } = await tt(t, y, s);
|
150
|
-
Object.entries(S).forEach(([P, D]) => {
|
151
|
-
D.isMedia ? o.mediaQueries.push([P, D]) : D.isGlobalDefine ? o.globalStyles.push(D) : D.isDefineVariables ? o.variables.push(D) : D.isDefineTemplates && o.templates.push(D._setPath(V));
|
152
|
-
});
|
153
|
-
})
|
154
|
-
);
|
155
|
-
const n = await zt(t), a = { ...n }, r = /* @__PURE__ */ new Set(), u = (y, S = []) => y ? Object.entries(y).flatMap(([V, P]) => {
|
156
|
-
if (!P) return;
|
157
|
-
if (typeof P == "object") return u(P, [...S, V]);
|
158
|
-
const D = wt(V), st = B(V), nt = [...S, D].join(".");
|
159
|
-
r.add(`"${nt}"`);
|
160
|
-
const U = [...S.map(B), st].join("-"), pt = _t(P);
|
161
|
-
return pt ? `--${U}: ${pt.transformed};` : `--${U}: ${P};`;
|
162
|
-
}) : [], d = (y) => y ? Object.entries(y).flatMap(([S, V]) => {
|
163
|
-
const P = u(V);
|
164
|
-
return S === "base" ? P.join("") : `${S} { ${P.join("")} }`;
|
165
|
-
}) : [], f = (y) => y ? Object.entries(y).flatMap(([S, V]) => Object.entries(V).flatMap(([P, D]) => {
|
166
|
-
const st = u(D, [S]), nt = `.${S}-${P}, [data-${S}="${P}"]`, U = st.join("");
|
167
|
-
return `${nt} { ${U} }`;
|
168
|
-
})) : [], p = (y) => ({ ...y, responsive: void 0, conditional: void 0 }), m = (y) => o.variables.map((S) => y === "static" ? p(S._current) : S._current[y]), h = I(p(n.variables), m("static")), $ = u(h), g = I((ft = n.variables) == null ? void 0 : ft.responsive, m("responsive")), x = d(g), N = I((ut = n.variables) == null ? void 0 : ut.conditional, m("conditional")), T = f(N), J = i(s, "css/_variables.css"), E = `:root { ${$.join("")} ${x.join("")} } ${T.join("")}`;
|
169
|
-
j(J, E), a.staticVariables = h;
|
170
|
-
const G = i(s, "css/_global.css"), k = I(n.global, o.globalStyles), H = await at(k, "");
|
171
|
-
j(G, `@layer global { ${H} }`);
|
172
|
-
const c = i(s, "css/_reset.css"), w = n.reset === "none" ? {} : typeof n.reset == "object" ? n.reset : Rt, l = await at(w, "");
|
173
|
-
j(c, `@layer reset { ${l} }`);
|
174
|
-
const C = i(s, "css/_templates.css"), F = I(n.templates, o.templates), O = await yt(F), K = Vt(F);
|
175
|
-
j(C, `@layer templates { ${O} }`), a.templates = F;
|
176
|
-
const A = Ot(o.templates);
|
177
|
-
a.templatePaths = Object.fromEntries(Object.entries(A).map(([y, S]) => [y, S._path]));
|
178
|
-
const { mediaQueries: L } = o;
|
179
|
-
a.mediaQueries = Object.fromEntries(L.map(([y, S]) => [`@${y}`, S]));
|
180
|
-
const Q = L.map(([y]) => `'@${y}'`).join(" | "), et = i(s, "types/css-tokens.d.ts"), q = `
|
181
|
-
// Variable types
|
182
|
-
type VariableTokens = ${[...r].join("|")};
|
183
|
-
type PropertyValueToken = \`{\${VariableTokens}}\`;
|
184
|
-
|
185
|
-
// Template types
|
186
|
-
type TemplateTokens = {
|
187
|
-
${Object.entries(K).map(([y, S]) => `${y}?: ${S}`).join(`
|
188
|
-
`)}
|
189
|
-
}
|
190
|
-
|
191
|
-
// Media query types
|
192
|
-
type MediaQueryKeys = ${Q || "''"};
|
193
|
-
`;
|
194
|
-
j(et, q);
|
195
|
-
const xt = i(s, "cache/config-cache.json");
|
196
|
-
j(xt, JSON.stringify(a, null, 2));
|
197
|
-
}, dt = (t) => t.replace(/styled\(([^"'`{,]+),/g, (e, s) => {
|
198
|
-
if (/^['"`]/.test(s)) return e;
|
199
|
-
const n = new RegExp(`import[^;]*${s}[,\\s{][^;]*from\\s?([^{};]+);`);
|
200
|
-
if (!n.test(t)) return e;
|
201
|
-
const r = n.exec(t);
|
202
|
-
if (r) {
|
203
|
-
const u = r.at(1);
|
204
|
-
if (Ct.some((f) => u == null ? void 0 : u.includes(f))) return e;
|
205
|
-
}
|
206
|
-
return "styled('div',";
|
207
|
-
}), It = (t, e) => {
|
208
|
-
try {
|
209
|
-
const s = _(i(e, "saltygen/cache/config-cache.json"), "utf8");
|
210
|
-
return s ? `globalThis.saltyConfig = ${s};
|
211
|
-
|
212
|
-
${t}` : `globalThis.saltyConfig = {};
|
213
|
-
|
214
|
-
${t}`;
|
215
|
-
} catch {
|
216
|
-
return t;
|
217
|
-
}
|
218
|
-
}, tt = async (t, e, s) => {
|
219
|
-
const o = v(e), n = i(s, "./temp");
|
220
|
-
it(n) || W(n);
|
221
|
-
const a = Y(e);
|
222
|
-
let r = _(e, "utf8");
|
223
|
-
r = dt(r), r = It(r, t);
|
224
|
-
const u = i(s, "js", o + ".js"), d = await ct(t), f = i(t, (d == null ? void 0 : d.configDir) || "", "salty.config.ts"), p = St(f), m = await $t(t);
|
225
|
-
await mt.build({
|
226
|
-
stdin: {
|
227
|
-
contents: r,
|
228
|
-
sourcefile: a.base,
|
229
|
-
resolveDir: a.dir,
|
230
|
-
loader: "tsx"
|
231
|
-
},
|
232
|
-
minify: !1,
|
233
|
-
treeShaking: !0,
|
234
|
-
bundle: !0,
|
235
|
-
outfile: u,
|
236
|
-
format: m,
|
237
|
-
target: ["node20"],
|
238
|
-
keepNames: !0,
|
239
|
-
external: p,
|
240
|
-
packages: "external",
|
241
|
-
plugins: [
|
242
|
-
{
|
243
|
-
name: "test",
|
244
|
-
setup: (g) => {
|
245
|
-
g.onLoad({ filter: /.*\.css|salty|styles|styled\.ts/ }, (x) => {
|
246
|
-
const N = _(x.path, "utf8");
|
247
|
-
return { contents: dt(N), loader: "ts" };
|
248
|
-
});
|
249
|
-
}
|
250
|
-
}
|
251
|
-
]
|
252
|
-
});
|
253
|
-
const h = Date.now();
|
254
|
-
return { contents: await import(`${u}?t=${h}`), outputFilePath: u };
|
255
|
-
}, Bt = async (t) => {
|
256
|
-
const e = await R(t), s = i(e, "cache/config-cache.json"), o = _(s, "utf8");
|
257
|
-
if (!o) throw new Error("Could not find config cache file");
|
258
|
-
return JSON.parse(o);
|
259
|
-
}, lt = async (t) => {
|
260
|
-
const e = await Bt(t), s = await R(t), o = i(s, "salty.config.js"), n = Date.now(), { config: a } = await import(`${o}?t=${n}`);
|
261
|
-
return I(a, e);
|
262
|
-
}, jt = () => {
|
263
|
-
try {
|
264
|
-
return process.env.NODE_ENV === "production";
|
265
|
-
} catch {
|
266
|
-
return !1;
|
267
|
-
}
|
268
|
-
}, Xt = async (t, e = jt(), s = !0) => {
|
269
|
-
try {
|
270
|
-
const o = Date.now();
|
271
|
-
e ? X.info("Generating CSS in production mode! 🔥") : X.info("Generating CSS in development mode! 🚀");
|
272
|
-
const n = [], a = [], r = await R(t), u = i(r, "index.css");
|
273
|
-
s && (() => {
|
274
|
-
it(r) && Nt("rm -rf " + r), W(r, { recursive: !0 }), W(i(r, "css")), W(i(r, "types")), W(i(r, "js")), W(i(r, "cache"));
|
275
|
-
})();
|
276
|
-
const f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set();
|
277
|
-
async function m(c) {
|
278
|
-
const b = ["node_modules", "saltygen"], w = Pt(c);
|
279
|
-
if (w.isDirectory()) {
|
280
|
-
const l = kt(c);
|
281
|
-
if (b.some((F) => c.includes(F))) return;
|
282
|
-
await Promise.all(l.map((F) => m(i(c, F))));
|
283
|
-
} else if (w.isFile() && rt(c)) {
|
284
|
-
f.add(c);
|
285
|
-
const C = _(c, "utf8");
|
286
|
-
/define[\w\d]+\(/.test(C) && p.add(c);
|
287
|
-
}
|
288
|
-
}
|
289
|
-
await m(t), await Wt(t, p);
|
290
|
-
const h = {
|
291
|
-
keyframes: [],
|
292
|
-
components: [],
|
293
|
-
classNames: []
|
294
|
-
};
|
295
|
-
await Promise.all(
|
296
|
-
[...f].map(async (c) => {
|
297
|
-
const { contents: b } = await tt(t, c, r);
|
298
|
-
Object.entries(b).forEach(([w, l]) => {
|
299
|
-
l.isKeyframes ? h.keyframes.push({
|
300
|
-
value: l,
|
301
|
-
src: c,
|
302
|
-
name: w
|
303
|
-
}) : l.isClassName ? h.classNames.push({
|
304
|
-
...l,
|
305
|
-
src: c,
|
306
|
-
name: w
|
307
|
-
}) : l.generator && h.components.push({
|
308
|
-
...l,
|
309
|
-
src: c,
|
310
|
-
name: w
|
311
|
-
});
|
312
|
-
});
|
313
|
-
})
|
314
|
-
);
|
315
|
-
const $ = await lt(t);
|
316
|
-
for (const c of h.keyframes) {
|
317
|
-
const { value: b } = c, w = `a_${b.animationName}.css`, l = `css/${w}`, C = i(r, l);
|
318
|
-
n.push(w), j(C, b.css);
|
319
|
-
}
|
320
|
-
const g = {};
|
321
|
-
for (const c of h.components) {
|
322
|
-
const { src: b, name: w } = c, l = c.generator._withBuildContext({
|
323
|
-
callerName: w,
|
324
|
-
isProduction: e,
|
325
|
-
config: $
|
326
|
-
});
|
327
|
-
a[l.priority] || (a[l.priority] = []);
|
328
|
-
const C = await l.css;
|
329
|
-
if (!C) continue;
|
330
|
-
a[l.priority].push(l.cssFileName);
|
331
|
-
const F = `css/${l.cssFileName}`, O = i(r, F);
|
332
|
-
j(O, C), $.importStrategy === "component" && (g[b] ? g[b].push(l.cssFileName) : g[b] = [l.cssFileName]);
|
333
|
-
}
|
334
|
-
for (const c of h.classNames) {
|
335
|
-
const { src: b, name: w } = c, l = c.generator._withBuildContext({
|
336
|
-
callerName: w,
|
337
|
-
isProduction: e,
|
338
|
-
config: $
|
339
|
-
}), C = await l.css;
|
340
|
-
if (!C) continue;
|
341
|
-
a[0].push(l.cssFileName);
|
342
|
-
const F = `css/${l.cssFileName}`, O = i(r, F);
|
343
|
-
j(O, C), $.importStrategy === "component" && (g[b] ? g[b].push(l.cssFileName) : g[b] = [l.cssFileName]);
|
344
|
-
}
|
345
|
-
$.importStrategy === "component" && Object.entries(g).forEach(([c, b]) => {
|
346
|
-
const w = b.map((K) => `@import url('./${K}');`).join(`
|
347
|
-
`), l = v(c, 6), C = Y(c), F = B(C.name), O = i(r, `css/f_${F}-${l}.css`);
|
348
|
-
j(O, w);
|
349
|
-
});
|
350
|
-
const x = n.map((c) => `@import url('./css/${c}');`).join(`
|
351
|
-
`);
|
352
|
-
let E = `@layer reset, global, templates, l0, l1, l2, l3, l4, l5, l6, l7, l8;
|
353
|
-
|
354
|
-
${["_variables.css", "_reset.css", "_global.css", "_templates.css"].filter((c) => {
|
355
|
-
try {
|
356
|
-
return _(i(r, "css", c), "utf8").length > 0;
|
357
|
-
} catch {
|
358
|
-
return !1;
|
359
|
-
}
|
360
|
-
}).map((c) => `@import url('./css/${c}');`).join(`
|
361
|
-
`)}
|
362
|
-
${x}`;
|
363
|
-
if ($.importStrategy !== "component") {
|
364
|
-
const c = a.reduce((b, w, l) => {
|
365
|
-
const C = w.reduce((A, L) => {
|
366
|
-
var q;
|
367
|
-
const Q = i(r, "css", L), et = _(Q, "utf8"), Z = ((q = /.*-([^-]+)-\d+.css/.exec(L)) == null ? void 0 : q.at(1)) || v(Q, 6);
|
368
|
-
return A.includes(Z) ? A : `${A}
|
369
|
-
/*start:${Z}*/
|
370
|
-
${et}
|
371
|
-
/*end:${Z}*/
|
372
|
-
`;
|
373
|
-
}, ""), F = `l_${l}.css`, O = i(r, "css", F), K = `@layer l${l} { ${C}
|
374
|
-
}`;
|
375
|
-
return j(O, K), `${b}
|
376
|
-
@import url('./css/${F}');`;
|
377
|
-
}, "");
|
378
|
-
E += c;
|
379
|
-
}
|
380
|
-
j(u, E);
|
381
|
-
const k = Date.now() - o, H = k < 200 ? "🔥" : k < 500 ? "🚀" : k < 1e3 ? "🎉" : k < 2e3 ? "🚗" : k < 5e3 ? "🤔" : "🥴";
|
382
|
-
X.info(`Generated CSS in ${k}ms! ${H}`);
|
383
|
-
} catch (o) {
|
384
|
-
console.error(o);
|
385
|
-
}
|
386
|
-
}, Yt = async (t, e) => {
|
387
|
-
try {
|
388
|
-
const s = await R(t);
|
389
|
-
if (rt(e)) {
|
390
|
-
const n = [], a = await lt(t), { contents: r } = await tt(t, e, s);
|
391
|
-
for (const [u, d] of Object.entries(r)) {
|
392
|
-
if (d.isKeyframes && d.css) {
|
393
|
-
const g = `css/${`a_${d.animationName}.css`}`, x = i(s, g);
|
394
|
-
j(x, await d.css);
|
395
|
-
return;
|
396
|
-
}
|
397
|
-
if (d.isClassName) {
|
398
|
-
const $ = d.generator._withBuildContext({
|
399
|
-
name: u
|
400
|
-
}), g = await $.css;
|
401
|
-
if (!g) continue;
|
402
|
-
n[0].push($.cssFileName);
|
403
|
-
const x = `css/${$.cssFileName}`, N = i(s, x);
|
404
|
-
j(N, g);
|
405
|
-
}
|
406
|
-
if (!d.generator) return;
|
407
|
-
const f = d.generator._withBuildContext({
|
408
|
-
name: u,
|
409
|
-
config: a
|
410
|
-
}), p = await f.css;
|
411
|
-
if (!p) continue;
|
412
|
-
const m = `css/${f.cssFileName}`, h = i(s, m);
|
413
|
-
j(h, p), n[f.priority] || (n[f.priority] = []), n[f.priority].push(f.cssFileName);
|
414
|
-
}
|
415
|
-
if (a.importStrategy !== "component")
|
416
|
-
n.forEach((u, d) => {
|
417
|
-
const f = `l_${d}.css`, p = i(s, "css", f);
|
418
|
-
let m = _(p, "utf8");
|
419
|
-
u.forEach((h) => {
|
420
|
-
var N;
|
421
|
-
const $ = i(s, "css", h), g = ((N = /.*-([^-]+)-\d+.css/.exec(h)) == null ? void 0 : N.at(1)) || v($, 6);
|
422
|
-
if (!m.includes(g)) {
|
423
|
-
const T = _($, "utf8"), J = `/*start:${g}*/
|
424
|
-
${T}
|
425
|
-
/*end:${g}*/
|
426
|
-
`;
|
427
|
-
m = `${m.replace(/\}$/, "")}
|
428
|
-
${J}
|
429
|
-
}`;
|
430
|
-
}
|
431
|
-
}), j(p, m);
|
432
|
-
});
|
433
|
-
else {
|
434
|
-
const u = n.flat().map((h) => `@import url('./${h}');`).join(`
|
435
|
-
`), d = v(e, 6), f = Y(e), p = B(f.name), m = i(s, `css/f_${p}-${d}.css`);
|
436
|
-
j(m, u);
|
437
|
-
}
|
438
|
-
}
|
439
|
-
} catch (s) {
|
440
|
-
console.error(s);
|
441
|
-
}
|
442
|
-
}, te = async (t, e, s = jt()) => {
|
443
|
-
try {
|
444
|
-
const o = await R(t);
|
445
|
-
if (rt(e)) {
|
446
|
-
const a = _(e, "utf8");
|
447
|
-
a.replace(/^(?!export\s)const\s.*/gm, (p) => `export ${p}`) !== a && await Dt(e, a);
|
448
|
-
const u = await lt(t), { contents: d } = await tt(t, e, o);
|
449
|
-
let f = a;
|
450
|
-
if (Object.entries(d).forEach(([p, m]) => {
|
451
|
-
var l;
|
452
|
-
if (m.isKeyframes || !m.generator) return;
|
453
|
-
const h = m.generator._withBuildContext({
|
454
|
-
name: p,
|
455
|
-
config: u,
|
456
|
-
prod: s
|
457
|
-
}), $ = new RegExp(`\\s${p}[=\\s]+[^()]+styled\\(([^,]+),`, "g").exec(a);
|
458
|
-
if (!$) return console.error("Could not find the original declaration");
|
459
|
-
const g = (l = $.at(1)) == null ? void 0 : l.trim(), x = new RegExp(`\\s${p}[=\\s]+styled\\(`, "g").exec(f);
|
460
|
-
if (!x) return console.error("Could not find the original declaration");
|
461
|
-
const { index: N } = x;
|
462
|
-
let T = !1;
|
463
|
-
const J = setTimeout(() => T = !0, 5e3);
|
464
|
-
let E = 0, G = !1, k = 0;
|
465
|
-
for (; !G && !T; ) {
|
466
|
-
const C = f[N + E];
|
467
|
-
C === "(" && k++, C === ")" && k--, k === 0 && C === ")" && (G = !0), E > f.length && (T = !0), E++;
|
468
|
-
}
|
469
|
-
if (!T) clearTimeout(J);
|
470
|
-
else throw new Error("Failed to find the end of the styled call and timed out");
|
471
|
-
const H = N + E, c = f.slice(N, H), b = f, w = ` ${p} = styled(${g}, "${h.classNames}", ${JSON.stringify(h.clientProps)});`;
|
472
|
-
f = f.replace(c, w), b === f && console.error("Minimize file failed to change content", { name: p, tagName: g });
|
473
|
-
}), u.importStrategy === "component") {
|
474
|
-
const p = v(e, 6), m = Y(e);
|
475
|
-
f = `import '../../saltygen/css/${`f_${B(m.name)}-${p}.css`}';
|
476
|
-
${f}`;
|
477
|
-
}
|
478
|
-
return f = f.replace("{ styled }", "{ styledClient as styled }"), f = f.replace("@salty-css/react/styled", "@salty-css/react/styled-client"), f;
|
479
|
-
}
|
480
|
-
} catch (o) {
|
481
|
-
console.error("Error in minimizeFile:", o);
|
482
|
-
}
|
483
|
-
};
|
484
|
-
export {
|
485
|
-
Ut as a,
|
486
|
-
Jt as b,
|
487
|
-
Wt as c,
|
488
|
-
tt as d,
|
489
|
-
Yt as e,
|
490
|
-
Xt as g,
|
491
|
-
rt as i,
|
492
|
-
X as l,
|
493
|
-
te as m,
|
494
|
-
Ct as s
|
495
|
-
};
|