import{existsSync as a,readdirSync as f,statSync as s,readFileSync as p}from"node:fs";import{join as r}from"node:path";var u=/^live-frame.*\.(png|jpe?g)$/i,l=["live-frame.png","live-frame.jpg"];function g(t){return[r(t,"execute_live","frames"),r(t,"frames"),r(t,"execute_live"),t]}function y(t){let e=[];for(let n of g(t)){if(!a(n))continue;for(let m of l){let i=r(n,m);if(a(i))try{e.push({p:i,mtime:s(i).mtimeMs})}catch{}}let c;try{c=f(n)}catch{continue}for(let m of c){if(!u.test(m))continue;let i=r(n,m);try{let o=s(i);o.isFile()&&e.push({p:i,mtime:o.mtimeMs})}catch{}}}return e.length===0?null:(e.sort((n,c)=>c.mtime-n.mtime),e[0])}function v(t){let e=y(t);if(!e)return null;try{return{base64:p(e.p).toString("base64"),mime:e.p.toLowerCase().endsWith(".png")?"image/png":"image/jpeg",mtime:e.mtime,path:e.p}}catch{return null}}export{y as findLatestLiveFrameFileSync,g as liveFrameScanDirs,v as readLatestLiveFramePayloadSync};
