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