// @bun
var{defineProperty:T,getOwnPropertyNames:c,getOwnPropertyDescriptor:l}=Object,h=Object.prototype.hasOwnProperty;function m(q){return this[q]}var o=(q)=>{var z=(F??=new WeakMap).get(q),A;if(z)return z;if(z=T({},"__esModule",{value:!0}),q&&typeof q==="object"||typeof q==="function"){for(var L of c(q))if(!h.call(z,L))T(z,L,{get:m.bind(q,L),enumerable:!(A=l(q,L))||A.enumerable})}return F.set(q,z),z},F;var p=(q)=>q;function u(q,z){this[q]=p.bind(null,z)}var s=(q,z)=>{for(var A in z)T(q,A,{get:z[A],enumerable:!0,configurable:!0,set:u.bind(z,A)})};var x=(q,z)=>()=>(q&&(z=q(q=0)),z);var D=import.meta.require;import{createHash as W}from"crypto";import{readFile as n,stat as f}from"fs/promises";async function I(q){try{let z=await n(q);return W("sha256").update(z).digest("hex").slice(0,16)}catch{return""}}function Aq(q){return W("sha256").update(q).digest("hex").slice(0,16)}function P(q){return W("sha256").update(q).digest("hex").slice(0,16)}function Jq(q,z){let A=JSON.stringify(z,Object.keys(z).sort());return`${P(q)}-${P(A)}`}async function Kq(q){try{return(await f(q)).mtimeMs}catch{return 0}}async function w(q){try{return await f(q),!0}catch{return!1}}var b=()=>{};import{resolve as j,basename as k,extname as B,join as E}from"path";import{mkdir as U}from"fs/promises";async function v(){try{return await import("ts-videos")}catch{return null}}async function Qq(q,z,A,L){let M=await v();if(!M)return console.warn("[stx-media] ts-videos not installed, cannot generate poster"),null;try{let J=j(q);if(!await w(J))return null;await U(A,{recursive:!0});let X=await I(J),Y=k(q,B(q)),R=z.format||"webp",G=z.timestamp||0,$=`${Y}-poster-${X}.${R}`,Q=E(A,$),N=await M.extractThumbnails(J,{timestamps:[G],width:z.width||1280,height:z.height,format:R,quality:z.quality||85,outputDir:A,outputPattern:$.replace(`.${R}`,"")});if(N&&N.length>0){let O=N[0];return{path:Q,url:`${L}/${$}`,width:O.width||z.width||1280,height:O.height||720,timestamp:G,size:O.size||0}}return null}catch(J){return console.warn(`[stx-media] Failed to generate poster: ${J}`),null}}async function Rq(q,z,A,L){let M=await v();if(!M)return[];try{let J=j(q);if(!await w(J))return[];await U(A,{recursive:!0});let X=await I(J),Y=k(q,B(q)),R=z.format||"webp",Q=(await new M.Input(J).getInfo()).duration||60,N=z.count||10,O=z.interval||Q/N,Z=[];for(let K=0;K<N&&K*O<Q;K++)Z.push(K*O);let _=await M.extractThumbnails(J,{timestamps:Z,width:z.width||320,format:R,quality:z.quality||80,outputDir:A,outputPattern:`${Y}-thumb-${X}`});if(_&&_.length>0)return _.map((K,y)=>({path:K.path||E(A,`${Y}-thumb-${X}-${y}.${R}`),url:`${L}/${Y}-thumb-${X}-${y}.${R}`,width:K.width||z.width||320,height:K.height||180,timestamp:Z[y],size:K.size||0}));return[]}catch(J){return console.warn(`[stx-media] Failed to generate thumbnails: ${J}`),[]}}async function Xq(q,z,A,L){let M=await v();if(!M)return console.warn("[stx-media] ts-videos not installed, cannot generate sprite sheet"),null;try{let J=j(q);if(!await w(J))return null;await U(A,{recursive:!0});let X=await I(J),Y=k(q,B(q)),$=(await new M.Input(J).getInfo()).duration||60,Q=z.columns||10,N=z.interval||5,O=z.thumbnailWidth||160,Z=z.thumbnailHeight||90,_=z.format||"jpeg",K=Math.ceil($/N),y=Math.ceil(K/Q),H=`${Y}-sprite-${X}.${_}`,V=E(A,H),g=[];for(let C=0;C<K;C++)g.push(C*N);let S=await M.extractThumbnails(J,{timestamps:g,width:O,height:Z,format:_,quality:z.quality||70,outputDir:E(A,".temp")});if(!S||S.length===0)return null;try{let C=await import("ts-images"),r=Q*O,e=y*Z,i=await C.createSprite({images:S.map((d)=>d.path),columns:Q,padding:0,outputPath:V,format:_,quality:z.quality||70});return{url:`${L}/${H}`,path:V,columns:Q,rows:y,thumbnailWidth:O,thumbnailHeight:Z,interval:N,totalFrames:K}}catch{return console.warn("[stx-media] ts-images not installed, sprite sheet generation skipped"),null}}catch(J){return console.warn(`[stx-media] Failed to generate sprite sheet: ${J}`),null}}var a=x(()=>{b()});a();export{Rq as generateThumbnails,Xq as generateSpriteSheet,Qq as generatePoster};
