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