const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./index-6jOCfdig.js","./index-Ds2meNS5.js","./index-W6UN98iO.css","./pass.fragment-BFsk8pdK.js"])))=>i.map(i=>d[i]);
import{_ as D}from"./index-Ds2meNS5.js";import{e as u,aI as A,L as v,aJ as b,E as g,aK as I,aL as T,_ as C,aM as x}from"./index-6jOCfdig.js";import"./svelte/svelte_svelte.js";import"./svelte/svelte_animate.js";import"./svelte/svelte_attachments.js";import"./svelte/svelte_easing.js";import"./svelte/svelte_internal_client.js";import"./svelte/svelte_internal_flags_async.js";import"./svelte/svelte_internal_flags_legacy.js";import"./svelte/svelte_internal_flags_tracing.js";import"./svelte/svelte_internal_server.js";import"./svelte/svelte_legacy.js";import"./svelte/svelte_motion.js";import"./svelte/svelte_reactivity.js";import"./svelte/svelte_reactivity_window.js";import"./svelte/svelte_server.js";import"./svelte/svelte_store.js";import"./svelte/svelte_transition.js";import"./svelte/svelte_events.js";let f=null;async function S(){const n=g.LastCreatedEngine?.createCanvas(100,100)??new OffscreenCanvas(100,100);n instanceof OffscreenCanvas&&v.Warn("DumpData: OffscreenCanvas will be used for dumping data. This may result in lossy alpha values.");const{ThinEngine:i}=await D(async()=>{const{ThinEngine:t}=await import("./index-6jOCfdig.js").then(a=>a.co);return{ThinEngine:t}},__vite__mapDeps([0,1,2]),import.meta.url);if(!i.IsSupported)throw new Error("DumpData: No WebGL context available. Cannot dump data.");const r={preserveDrawingBuffer:!0,depth:!1,stencil:!1,alpha:!0,premultipliedAlpha:!1,antialias:!1,failIfMajorPerformanceCaveat:!1},e=new i(n,!1,r);g.Instances.pop(),g.OnEnginesDisposedObservable.add(t=>{e&&t!==e&&!e.isDisposed&&g.Instances.length===0&&_()}),e.getCaps().parallelShaderCompile=void 0;const o=new I(e),{passPixelShader:s}=await D(async()=>{const{passPixelShader:t}=await import("./pass.fragment-BFsk8pdK.js");return{passPixelShader:t}},__vite__mapDeps([3,0,1,2]),import.meta.url),p=new T({engine:e,name:s.name,fragmentShader:s.shader,samplerNames:["textureSampler"]});return{canvas:n,dumpEngine:{engine:e,renderer:o,wrapper:p}}}async function P(){return f||(f=S()),await f}class E{static async EncodeImageAsync(i,r,e,o,s,p){const t=await P(),a=t.dumpEngine;a.engine.setSize(r,e,!0);const c=a.engine.createRawTexture(i,r,e,5,!1,!s,1);return a.renderer.setViewport(),a.renderer.applyEffectWrapper(a.wrapper),a.wrapper.effect._bindTexture("textureSampler",c),a.renderer.draw(),c.dispose(),await new Promise((d,m)=>{u.ToBlob(t.canvas,l=>{l?d(l):m(new Error("EncodeImageAsync: Failed to convert canvas to blob."))},o,p)})}}C([x],E,"EncodeImageAsync",null);const Z=E.EncodeImageAsync;async function h(n,i,r,e,o="image/png",s,p){const t=await r.readPixels(0,0,n,i),a=new Uint8Array(t.buffer);y(n,i,a,e,o,s,!0,void 0,p)}async function w(n,i,r,e="image/png",o,s=!1,p=!1,t){if(r instanceof Float32Array){const d=new Uint8Array(r.length);let m=r.length;for(;m--;){const l=r[m];d[m]=Math.round(A(l)*255)}r=d}const a=await E.EncodeImageAsync(r,n,i,e,s,t);o!==void 0&&u.DownloadBlob(a,o),a.type!==e&&v.Warn(`DumpData: The requested mimeType '${e}' is not supported. The result has mimeType '${a.type}' instead.`);const c=await a.arrayBuffer();return p?c:`data:${e};base64,${b(c)}`}function y(n,i,r,e,o="image/png",s,p=!1,t=!1,a){s===void 0&&!e&&(s=""),w(n,i,r,o,s,p,t,a).then(c=>{e&&e(c)})}function _(){f&&(f?.then(n=>{n.canvas instanceof HTMLCanvasElement&&n.canvas.remove(),n.dumpEngine&&(n.dumpEngine.engine.dispose(),n.dumpEngine.renderer.dispose(),n.dumpEngine.wrapper.dispose())}),f=null)}const N={DumpData:y,DumpDataAsync:w,DumpFramebuffer:h,Dispose:_},L=()=>{u.DumpData=y,u.DumpDataAsync=w,u.DumpFramebuffer=h};L();export{_ as Dispose,y as DumpData,w as DumpDataAsync,h as DumpFramebuffer,N as DumpTools,Z as EncodeImageAsync};
