import{k as e,X as t,e7 as a,U as i,al as n,an as r,ap as s,aV as o,E as c,a2 as h,S as l,a0 as f,q as d,cp as w,ef as u,eg as g}from"./index-C-dDkA_D.js";var p=s("<div id=heic-container style=position:relative;width:100%;height:75vh;display:flex;justify-content:center;align-items:center;overflow:hidden><canvas style=max-width:100%;max-height:100%;object-fit:contain>");const m=()=>{const s=d();e();const[m,y]=t(!0),[v,b]=t(!1),{libHeifPath:j}=a();let x,C,$,_=i.objs.filter(e=>/\.(heic|heif|avif|vvc|avc|jpeg|jpg)$/i.test(e.name));0===_.length&&(_=[i.obj]),n(()=>{k()}),r(()=>{x&&C&&(C=null),x=null});const k=async()=>{y(!0),b(!1);try{window.libheif||await E(`${j()}/libheif.js`,"libheif-script");const e=await H(`${j()}/libheif.wasm`);x=window.libheif({wasmBinary:e}),C=new x.HeifDecoder,await I(i.raw_url)}catch(e){console.error("HEIC初始化失败:",e),b(!0),y(!1)}},E=(e,t)=>new Promise((a,i)=>{const n=document.createElement("script");n.src=e,n.id=t,n.onload=()=>a(),n.onerror=()=>i(`脚本加载失败: ${e}`),document.head.appendChild(n)}),H=async e=>{const t=await fetch(e);if(!t.ok)throw`WASM加载失败: ${e}`;return await t.arrayBuffer()},I=async e=>{try{y(!0),b(!1);const t=await fetch(e);if(!t.ok)throw"文件获取失败";const a=await t.arrayBuffer(),i=C.decode(a);if(!i||0===i.length)throw"没有可解码的图像";const n=i[0];await B(n),y(!1)}catch(t){console.error("HEIC解码失败:",t),b(!0),y(!1)}},B=e=>new Promise(t=>{if(!$)return t();const a=e.get_width(),i=e.get_height();$.width=a,$.height=i;const n=new ImageData(a,i);e.display(n,e=>{if(!e||!$)return t();const a=$.getContext("2d");if(!a)return t();a.putImageData(e,0,0),t()})});return D=p(),P=D.firstChild,"function"==typeof $?g($,P):$=P,o(D,c(l,{get when(){return m()},get children(){return c(h,{})}}),null),o(D,c(l,{get when(){return v()},get children(){return c(f,{get msg(){return s("preview.failed_load_heic")},h:"75vh"})}}),null),w(e=>u(P,"display",m()||v()?"none":"block")),D;var D,P};export{m as default};
