import{j as v,B as c,e3 as P,a4 as a,au as E,N as L,ax as R,aZ as u,D as l,ac as j,S as y,aa as C,o as x}from"./index-CNZMR1GT.js";var B=R("<div id=swf-container>");const _=()=>{const w=x(),{replace:i}=v(),[m,n]=c(!0),[p,s]=c(!1),{ruffleJSPath:h}=P();let r=a.objs.filter(e=>e.name.toLowerCase().endsWith(".swf"));r.length===0&&(r=[a.obj]);const d=e=>{const t=r.findIndex(o=>o.name===a.obj.name);e.key==="ArrowLeft"&&t>0?i(r[t-1].name):e.key==="ArrowRight"&&t<r.length-1&&i(r[t+1].name)};E(()=>{window.addEventListener("keydown",d),g()}),L(()=>{window.removeEventListener("keydown",d);const e=document.getElementById("ruffle-player");e==null||e.remove();const t=document.getElementById("ruffle-script");t==null||t.remove()});const g=()=>{n(!0),s(!1);const e=document.getElementById("ruffle-player");if(e==null||e.remove(),window.RufflePlayer){f();return}const t=document.createElement("script");t.src=h(),t.async=!0,t.id="ruffle-script",t.onload=()=>{f()},t.onerror=()=>{s(!0),n(!1),console.error("无法加载Ruffle播放器")},document.head.appendChild(t)},f=()=>{try{const t=window.RufflePlayer.newest().createPlayer();t.id="ruffle-player",t.style.width="100%",t.style.height="100%";const o=document.getElementById("swf-container");o&&(o.innerHTML="",o.appendChild(t),t.addEventListener("loaded",()=>{n(!1)}),t.addEventListener("error",()=>{s(!0),n(!1)}),t.load(a.raw_url))}catch(e){console.error("Ruffle初始化失败:",e),s(!0),n(!1)}};return(()=>{var e=B();return 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"),u(e,l(y,{get when(){return m()},get children(){return l(j,{})}}),null),u(e,l(y,{get when(){return p()},get children(){return l(C,{get msg(){return w("preview.failed_load_swf")},h:"75vh"})}}),null),e})()};export{_ as default};
