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