@salty-css/core 0.0.1-alpha.227 → 0.0.1-alpha.228

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.
@@ -0,0 +1,38 @@
1
+ "use strict";const Ne=require("esbuild"),Pe=require("child_process"),x=require("./dash-case-BJEkFEGQ.cjs"),r=require("path"),l=require("fs"),pe=require("fs/promises"),Y=require("./parse-styles-3N79AOBO.cjs"),K=require("winston"),J=require("./css/merge.cjs"),ke=require("./define-templates-Cunsb_Tr.cjs"),xe=require("ts-morph");var ne=typeof document<"u"?document.currentScript:null;function De(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=De(Ne),ye=async(e,t=[])=>{if(!e)return"";const s=[],n={};for(const[o,a]of Object.entries(e))if(typeof a!="function")if(a&&typeof a=="object"){const i=o.trim(),b=await ye(a,[...t,i]);s.push(b)}else n[o]=a;if(Object.keys(n).length){const o=t.map(x.dashCase).join("-"),a="t_"+x.toHash(o,4),i=await Y.parseAndJoinStyles(n,`.${o}, .${a}`);s.push(i)}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(o=>`"${o}"`).join(" | ")),t),{}):{},me=(e,t="",s=new Set)=>e?(Object.entries(e).forEach(([n,o])=>{const a=t?`${t}.${n}`:n;return typeof o=="object"?me(o,a,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,".."))},Oe=async e=>{const t=ge(e);return await pe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{})},Te=async e=>{const t=await Oe(e);if(t)return t.type};let q;const he=async e=>{if(q)return q;const t=await Te(e);return t==="module"?q="esm":(t==="commonjs"||(typeof document>"u"?require("url").pathToFileURL(__filename).href:ne&&ne.tagName.toUpperCase()==="SCRIPT"&&ne.src||new URL("index-_XWMZNGO.cjs",document.baseURI).href).endsWith(".cjs"))&&(q="cjs"),q||"esm"},L=K.createLogger({level:"debug",format:K.format.combine(K.format.colorize(),K.format.cli()),transports:[new K.transports.Console({})]}),Ee=e=>{L.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 ve={"*, *::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=l.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},z=async e=>{if(V.destDir)return V.destDir;const t=await ie(e),s=r.join(e,(t==null?void 0:t.saltygenDir)||"saltygen");return V.destDir=s,s},oe=["salty","css","styles","styled"],be=(e=[])=>new RegExp(`\\.(${[...oe,...e].join("|")})\\.`),ee=(e,t=[])=>be(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 pe.readFile(t,"utf-8").then(JSON.parse).catch(()=>{});return s?(V.rcFile=s,s):we(r.join(e,".."))},ie=async e=>{var n,o;const t=await we(e),s=(n=t.projects)==null?void 0:n.find(a=>e.endsWith(a.dir||""));return s||((o=t.projects)==null?void 0:o.find(a=>a.dir===t.defaultProject))},Ve=async e=>{const t=await ie(e),s=await z(e),n=r.join(e,(t==null?void 0:t.configDir)||"","salty.config.ts"),o=r.join(s,"salty.config.js"),a=await he(e),i=je(n);await de.build({entryPoints:[n],minify:!0,treeShaking:!0,bundle:!0,outfile:o,format:a,external:i});const b=Date.now(),{config:c}=await import(`${o}?t=${b}`);return{config:c,path:o}},$e=async(e,t)=>{var ce,le;const s=await z(e),n={mediaQueries:[],globalStyles:[],variables:[],templates:[]};await Promise.all([...t].map(async g=>{const{contents:j,outputFilePath:v}=await B(e,g,s);Object.entries(j).forEach(([P,_])=>{_.isMedia?n.mediaQueries.push([P,_]):_.isGlobalDefine?n.globalStyles.push(_):_.isDefineVariables?n.variables.push(_):_.isDefineTemplates&&n.templates.push(_._setPath(`${P};;${v}`))})}));const{config:o,path:a}=await Ve(e),i={...o},b=new Set,c=(g,j=[])=>g?Object.entries(g).flatMap(([v,P])=>{if(!P)return;if(typeof P=="object")return c(P,[...j,v]);const _=Se(v),te=x.dashCase(v),se=[...j,_].join(".");b.add(`"${se}"`);const X=[...j.map(x.dashCase),te].join("-"),fe=Y.parseVariableTokens(P);return fe?`--${X}: ${fe.transformed};`:`--${X}: ${P};`}):[],p=g=>g?Object.entries(g).flatMap(([j,v])=>{const P=c(v);return j==="base"?P.join(""):`${j} { ${P.join("")} }`}):[],y=g=>g?Object.entries(g).flatMap(([j,v])=>Object.entries(v).flatMap(([P,_])=>{const te=c(_,[j]),se=`.${j}-${P}, [data-${j}="${P}"]`,X=te.join("");return`${se} { ${X} }`})):[],$=g=>({...g,responsive:void 0,conditional:void 0}),m=g=>n.variables.map(j=>g==="static"?$(j._current):j._current[g]),h=J.mergeObjects($(o.variables),m("static")),d=c(h),F=J.mergeObjects((ce=o.variables)==null?void 0:ce.responsive,m("responsive")),O=p(F),k=J.mergeObjects((le=o.variables)==null?void 0:le.conditional,m("conditional")),M=y(k),E=r.join(s,"css/_variables.css"),R=`:root { ${d.join("")} ${O.join("")} } ${M.join("")}`;l.writeFileSync(E,R),i.staticVariables=h;const D=r.join(s,"css/_global.css"),H=J.mergeObjects(o.global,n.globalStyles),u=await Y.parseAndJoinStyles(H,"");l.writeFileSync(D,`@layer global { ${u} }`);const S=r.join(s,"css/_reset.css"),f=o.reset==="none"?{}:typeof o.reset=="object"?o.reset:ve,C=await Y.parseAndJoinStyles(f,"");l.writeFileSync(S,`@layer reset { ${C} }`);const N=r.join(s,"css/_templates.css"),T=J.mergeObjects(o.templates,n.templates),W=await ye(T),I=_e(T);l.writeFileSync(N,`@layer templates { ${W} }`),i.templates=T;const A=o.templates?[ke.defineTemplates(o.templates)._setPath(`config;;${a}`)]:[],Q=J.mergeFactories(n.templates,A);i.templatePaths=Object.fromEntries(Object.entries(Q).map(([g,j])=>[g,j._path]));const{mediaQueries:Z}=n;i.mediaQueries=Object.fromEntries(Z.map(([g,j])=>[`@${g}`,j]));const G=Z.map(([g])=>`'@${g}'`).join(" | "),U=r.join(s,"types/css-tokens.d.ts"),Fe=`
3
+ // Variable types
4
+ type VariableTokens = ${[...b].join("|")};
5
+ type PropertyValueToken = \`{\${VariableTokens}}\`;
6
+
7
+ // Template types
8
+ type TemplateTokens = {
9
+ ${Object.entries(I).map(([g,j])=>`${g}?: ${j}`).join(`
10
+ `)}
11
+ }
12
+
13
+ // Media query types
14
+ type MediaQueryKeys = ${G||"''"};
15
+ `;l.writeFileSync(U,Fe);const Ce=r.join(s,"cache/config-cache.json");l.writeFileSync(Ce,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 i=o.exec(e);if(i){const b=i.at(1);if(oe.some(p=>b==null?void 0:b.includes(p)))return t}return"styled('div',"}),Me=(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}},B=async(e,t,s)=>{const n=x.toHash(t),o=r.join(s,"./temp");l.existsSync(o)||l.mkdirSync(o);const a=r.parse(t);let i=l.readFileSync(t,"utf8");i=ue(i),i=Me(i,e);const b=r.join(s,"js",n+".js"),c=await ie(e),p=r.join(e,(c==null?void 0:c.configDir)||"","salty.config.ts"),y=je(p),$=await he(e);await de.build({stdin:{contents:i,sourcefile:a.base,resolveDir:a.dir,loader:"tsx"},minify:!1,treeShaking:!0,bundle:!0,outfile:b,format:$,target:["node20"],keepNames:!0,external:y,packages:"external",plugins:[{name:"test",setup:d=>{d.onLoad({filter:/.*\.css|salty|styles|styled\.ts/},F=>{const O=l.readFileSync(F.path,"utf8");return{contents:ue(O),loader:"ts"}})}}]});const m=Date.now();return{contents:await import(`${b}?t=${m}`),outputFilePath:b}},Re=async e=>{const t=await z(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)},ae=async e=>{const t=await Re(e),s=await z(e),n=r.join(s,"salty.config.js"),o=Date.now(),{config:a}=await import(`${n}?t=${o}`);return J.mergeObjects(a,t)},re=()=>{try{return process.env.NODE_ENV==="production"}catch{return!1}},Je=async(e,t=re(),s=!0)=>{try{const n=Date.now();t?L.info("Generating CSS in production mode! 🔥"):L.info("Generating CSS in development mode! 🚀");const o=[],a=[],i=await z(e),b=r.join(i,"index.css");s&&(()=>{l.existsSync(i)&&Pe.execSync("rm -rf "+i),l.mkdirSync(i,{recursive:!0}),l.mkdirSync(r.join(i,"css")),l.mkdirSync(r.join(i,"types")),l.mkdirSync(r.join(i,"js")),l.mkdirSync(r.join(i,"cache"))})();const p=new Set,y=new Set;async function $(u){const S=["node_modules","saltygen"],w=l.statSync(u);if(w.isDirectory()){const f=l.readdirSync(u);if(S.some(N=>u.includes(N)))return;await Promise.all(f.map(N=>$(r.join(u,N))))}else if(w.isFile()&&ee(u)){p.add(u);const C=l.readFileSync(u,"utf8");/define[\w\d]+\(/.test(C)&&y.add(u)}}await $(e),await $e(e,y);const m={keyframes:[],components:[],classNames:[]};await Promise.all([...p].map(async u=>{const{contents:S}=await B(e,u,i);for(let[w,f]of Object.entries(S))f instanceof Promise&&(f=await f),f.isKeyframes?m.keyframes.push({value:f,src:u,name:w}):f.isClassName?m.classNames.push({...f,src:u,name:w}):f.generator&&m.components.push({...f,src:u,name:w})}));const h=await ae(e);for(const u of m.keyframes){const{value:S}=u,w=`a_${S.animationName}.css`,f=`css/${w}`,C=r.join(i,f);o.push(w),l.writeFileSync(C,S.css)}const d={};for(const u of m.components){const{src:S,name:w}=u;d[S]||(d[S]=[]);const f=u.generator._withBuildContext({callerName:w,isProduction:t,config:h});a[f.priority]||(a[f.priority]=[]);const C=await f.css;if(!C)continue;a[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,T=r.join(i,N);l.writeFileSync(T,C),h.importStrategy==="component"&&d[S].push(f.cssFileName)}for(const u of m.classNames){const{src:S,name:w}=u;d[S]||(d[S]=[]);const f=u.generator._withBuildContext({callerName:w,isProduction:t,config:h}),C=await f.css;if(!C)continue;a[f.priority]||(a[f.priority]=[]),a[f.priority].push(f.cssFileName);const N=`css/${f.cssFileName}`,T=r.join(i,N);l.writeFileSync(T,C),h.importStrategy==="component"&&d[S].push(f.cssFileName)}h.importStrategy==="component"&&Object.entries(d).forEach(([u,S])=>{const w=S.map(W=>`@import url('./${W}');`).join(`
20
+ `),f=x.toHash(u,6),C=r.parse(u),N=x.dashCase(C.name),T=r.join(i,`css/f_${N}-${f}.css`);l.writeFileSync(T,w||"/* Empty file */")});const F=o.map(u=>`@import url('./css/${u}');`).join(`
21
+ `);let E=`@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(i,"css",u),"utf8").length>0}catch{return!1}}).map(u=>`@import url('./css/${u}');`).join(`
24
+ `)}
25
+ ${F}`;if(h.importStrategy!=="component"){const u=a.reduce((S,w,f)=>{const C=w.reduce((I,A)=>{var U;const Q=r.join(i,"css",A),Z=l.readFileSync(Q,"utf8"),G=((U=/.*-([^-]+)-\d+.css/.exec(A))==null?void 0:U.at(1))||x.toHash(Q,6);return I.includes(G)?I:`${I}
26
+ /*start:${G}-${A}*/
27
+ ${Z}
28
+ /*end:${G}*/
29
+ `},""),N=`l_${f}.css`,T=r.join(i,"css",N),W=`@layer l${f} { ${C}
30
+ }`;return l.writeFileSync(T,W),`${S}
31
+ @import url('./css/${N}');`},"");E+=u}l.writeFileSync(b,E);const D=Date.now()-n,H=D<200?"🔥":D<500?"🚀":D<1e3?"🎉":D<2e3?"🚗":D<5e3?"🤔":"🥴";L.info(`Generated CSS in ${D}ms! ${H}`)}catch(n){console.error(n)}},ze=async(e,t,s=re())=>{try{const n=await z(e);if(ee(t)){const a=[],i=await ae(e),{contents:b}=await B(e,t,n);for(const[c,p]of Object.entries(b)){if(p.isKeyframes&&p.css){const F=`css/${`a_${p.animationName}.css`}`,O=r.join(n,F);l.writeFileSync(O,await p.css);return}if(p.isClassName){const d=p.generator._withBuildContext({callerName:c,isProduction:s,config:i}),F=await d.css;if(!F)continue;a[d.priority]||(a[d.priority]=[]),a[d.priority].push(d.cssFileName);const O=`css/${d.cssFileName}`,k=r.join(n,O);l.writeFileSync(k,F)}if(!p.generator)return;const y=p.generator._withBuildContext({callerName:c,isProduction:s,config:i}),$=await y.css;if(!$)continue;const m=`css/${y.cssFileName}`,h=r.join(n,m);l.writeFileSync(h,$),a[y.priority]||(a[y.priority]=[]),a[y.priority].push(y.cssFileName)}if(i.importStrategy!=="component")a.forEach((c,p)=>{const y=`l_${p}.css`,$=r.join(n,"css",y);let m=l.readFileSync($,"utf8");c.forEach(h=>{var k;const d=r.join(n,"css",h),F=((k=/.*-([^-]+)-\d+.css/.exec(h))==null?void 0:k.at(1))||x.toHash(d,6);if(!m.includes(F)){const M=l.readFileSync(d,"utf8"),E=`/*start:${F}-${h}*/
32
+ ${M}
33
+ /*end:${F}*/
34
+ `;m=`${m.replace(/\}$/,"")}
35
+ ${E}
36
+ }`}}),l.writeFileSync($,m)});else{const c=a.flat().map(h=>`@import url('./${h}');`).join(`
37
+ `),p=x.toHash(t,6),y=r.parse(t),$=x.dashCase(y.name),m=r.join(n,`css/f_${$}-${p}.css`);l.writeFileSync(m,c||"/* Empty file */")}}}catch(n){console.error(n)}},qe=async(e,t,s=re())=>{try{const n=await z(e);if(ee(t)){const a=l.readFileSync(t,"utf8"),i=await ae(e),{contents:b}=await B(e,t,n);let c=a;if(Object.entries(b).forEach(([p,y])=>{var M,E;if(y.isKeyframes)return;const h=new xe.Project({}).createSourceFile("temp.ts",c).getVariableDeclarationOrThrow(p);if(!y.generator)return;const d=y.generator._withBuildContext({callerName:p,isProduction:s,config:i}),F=h.getStart(),O=h.getEnd(),k=c.slice(F,O);if(y.isClassName){const R=c,D=` ${p} = className("${d.classNames}")`;c=c.replace(k,D),R===c&&console.error("Minimize file failed to change content",{name:p})}if(k.includes("styled")){const R=(E=(M=/styled\(([^,]+),/.exec(k))==null?void 0:M.at(1))==null?void 0:E.trim(),D=c,H=` ${p} = styled(${R}, "${d.classNames}", ${JSON.stringify(d.clientProps)})`;c=c.replace(k,H),D===c&&console.error("Minimize file failed to change content",{name:p,tagName:R})}}),i.importStrategy==="component"){const p=x.toHash(t,6),y=r.parse(t);c=`import '../../saltygen/css/${`f_${x.dashCase(y.name)}-${p}.css`}';
38
+ ${c}`}return c=c.replace("@salty-css/react/class-name","@salty-css/react/class-name-client"),c=c.replace("{ styled }","{ styledClient as styled }"),c=c.replace("@salty-css/react/styled","@salty-css/react/styled-client"),c}}catch(n){console.error("Error in minimizeFile:",n)}};exports.compileSaltyFile=B;exports.generateConfigStyles=$e;exports.generateCss=Je;exports.generateFile=ze;exports.isSaltyFile=ee;exports.logError=Ee;exports.logger=L;exports.minimizeFile=qe;exports.saltyFileExtensions=oe;exports.saltyFileRegExp=be;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salty-css/core",
3
- "version": "0.0.1-alpha.227",
3
+ "version": "0.0.1-alpha.228",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "typings": "./dist/index.d.ts",
@@ -35,6 +35,7 @@
35
35
  "esbuild": ">=0.21.x",
36
36
  "ora": ">=8.x",
37
37
  "react": ">=18.x || >=19.x",
38
+ "ts-morph": ">=25.0.1",
38
39
  "winston": ">=3.x"
39
40
  },
40
41
  "exports": {
package/server/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("fs/promises"),s=require("../index-CxycFYRY.cjs"),i=async e=>{if(!e||e.includes("node_modules")||e.includes("saltygen"))return!1;if(e.includes("salty.config"))return!0;if(!s.isSaltyFile(e))return!1;const t=await r.readFile(e,"utf-8");return!!/.+define[A-Z]\w+/.test(t)};exports.checkShouldRestart=i;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("fs/promises"),r=require("../index-_XWMZNGO.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-BdGwX7CP.js";
2
+ import { i as e } from "../index-BR0X24-T.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;