filens-preview 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/all-in-one/filens.js +306 -306
- package/dist/split/chunks/{archive-DMapcEqq.js → archive-haip2eOP.js} +1 -1
- package/dist/split/chunks/{browser-video-session-CGI8FpX_.js → browser-video-session-C_14e_mG.js} +1 -1
- package/dist/split/chunks/{cad-BvXJNqHR.js → cad-5oTkbaDV.js} +1 -1
- package/dist/split/chunks/{core-BLayEJn5.js → core-EjELrtsP.js} +2 -2
- package/dist/split/chunks/{diagram-DlpgioZ9.js → diagram-BRcdlitF.js} +1 -1
- package/dist/split/chunks/{docx-Sii3GNtE.js → docx-I39iDYpR.js} +1 -1
- package/dist/split/chunks/{ebook-CLCQfska.js → ebook-BRfadCGl.js} +1 -1
- package/dist/split/chunks/{index-DI_GyFX1.js → index-C4jdVbDq.js} +1 -1
- package/dist/split/chunks/{index-BPK_cNTp.js → index-DkF8PBGR.js} +1 -1
- package/dist/split/chunks/{iwork-Datv3D5d.js → iwork-DXq9Adf7.js} +1 -1
- package/dist/split/chunks/{media-runtime-tb-Q4Sah.js → media-runtime-B6322raw.js} +1 -1
- package/dist/split/chunks/{mindmap-B_GYpiFO.js → mindmap-CyR3TRfx.js} +1 -1
- package/dist/split/chunks/model3d-BEt6INTt.js +55 -0
- package/dist/split/chunks/{panorama-CIdiLIwD.js → panorama-ChsqnvWC.js} +1 -1
- package/dist/split/chunks/vendor-C1aIdQ-w.js +4115 -0
- package/dist/split/chunks/{xlsx-D2NFYc3n.js → xlsx-CITQo0Od.js} +1 -1
- package/dist/split/filens.js +1 -1
- package/package.json +1 -1
- package/dist/split/chunks/model3d-BsIQNF2D.js +0 -55
- package/dist/split/chunks/vendor-CBCxJuSg.js +0 -4115
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var To=Object.defineProperty;var Ro=(t,e,i)=>e in t?To(t,e,{enumerable:true,configurable:true,writable:true,value:i}):t[e]=i;var L=(t,e,i)=>Ro(t,typeof e!="symbol"?e+"":e,i);import{x as Tn,c as Po,b as Ao,y as Lo,z as _o}from"./core-BLayEJn5.js";import{ac as Uo,S as Ki,ad as Mt,ae as Ta,af as Ra,ag as Pa,ah as Zi,j as ea,ai as Co,aj as Aa,ak as Rn,m as Eo,o as Io,a9 as zo,al as Yr,w as Bo}from"./vendor-CBCxJuSg.js";function Se(t){if(t!=null&&t.aborted)throw Pn()}function Pn(){return Object.assign(new Error("The conversion was aborted."),{name:"AbortError"})}function ut(t,e){return e?new Promise((i,n)=>{const r=()=>n(Pn());t.then(o=>{e.removeEventListener("abort",r),i(o)},o=>{e.removeEventListener("abort",r),n(o)}),e.aborted?r():e.addEventListener("abort",r,{once:true})}):t}function La(t){let e;return()=>{if(!e){const i=Promise.resolve().then(t);e=i,i.catch(()=>{e===i&&(e=void 0)})}return e}}function jo(t){return/^(?:https?:|blob:|\/|\.{1,2}\/)/i.test(t)}function No(t){return t.trimStart().toLowerCase().startsWith("data:")}function Oo(t){const e=atob(t),i=new Uint8Array(e.length);for(let n=0;n<i.length;n++)i[n]=e.charCodeAt(n);return i}function Vo(t){var c;const e=t.trimStart(),i=e.indexOf(",");if(i<0)throw new Error("Conversion data URL is missing its payload separator.");const n=e.slice(0,i),r=e.slice(i+1),o=(c=n.match(/^data:([^;,]+)/i))==null?void 0:c[1];if(/;base64$/i.test(n))return{bytes:Oo(r),contentType:o};const s=new TextEncoder().encode(r);let a=0;for(let l=0;l<s.length;l++){if(s[l]===37){const u=Qr(s[l+1]),f=Qr(s[l+2]);if(u>=0&&f>=0){s[a++]=u<<4|f,l+=2;continue}}s[a++]=s[l]}return{bytes:s.subarray(0,a),contentType:o}}function Qr(t){if(t>=48&&t<=57)return t-48;const e=t|32;return e>=97&&e<=102?e-87:-1}async function An(t,e=globalThis.fetch,i,n=1/0){var o;const r=s=>{if(s>n)throw new Error("Conversion source exceeds the preview byte limit.")};if(Wo(t)){r(t.size);const s=new Uint8Array(await ut(t.arrayBuffer(),i));return r(s.length),s}if(t instanceof ArrayBuffer)return r(t.byteLength),new Uint8Array(t);if(ArrayBuffer.isView(t))return r(t.byteLength),new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(typeof t=="string"){if(No(t)){r(Math.max(0,t.length-t.indexOf(",")-1)/3);const a=Vo(t).bytes;return r(a.length),a}if(jo(t)){if(!e)throw new Error("A fetch implementation is required to load a conversion source URL.");const a=await ut(e(t,{signal:i}),i);if(Se(i),!a.ok)throw new Error(`Failed to fetch conversion source: ${a.status} ${a.statusText}`.trim());try{if(r(Number(a.headers.get("content-length"))),!Number.isFinite(n)||!a.body){const l=new Uint8Array(await ut(a.arrayBuffer(),i));return r(l.length),l}const c=a.body.getReader();try{const l=[];let u=0;for(;;){const{value:p,done:h}=await ut(c.read(),i);if(h)break;u+=p.length,r(u),l.push(p)}const f=new Uint8Array(u);let y=0;for(const p of l)f.set(p,y),y+=p.length;return f}finally{await c.cancel().catch(()=>{}),c.releaseLock()}}catch(c){throw await((o=a.body)==null?void 0:o.cancel().catch(()=>{})),c}}r(t.length);const s=new TextEncoder().encode(t);return r(s.length),s}throw new Error("Unsupported conversion source type.")}function Wo(t){return typeof t=="object"&&t!==null&&"arrayBuffer"in t&&typeof t.arrayBuffer=="function"}async function Go(t){var i;if(((i=t.headers.get("content-type"))==null?void 0:i.split(";",1)[0])!=="application/wasm+gzip")return t;if(typeof DecompressionStream<"u"&&t.body)return new Response(t.body.pipeThrough(new DecompressionStream("gzip")),{headers:{"content-type":"application/wasm"}});const e=Uo(new Uint8Array(await t.arrayBuffer()));return new Response(e,{headers:{"content-type":"application/wasm"}})}function wi(t){const e=La(()=>Ln(t.wasm,t.fetch));return async i=>{const n=i.signal;Se(n);const r=new Cn({args:i.args,files:i.files,captureStdio:i.captureStdio}),o=await ut(e(),n);Se(n);const s=await ut(WebAssembly.instantiate(o,{wasi_snapshot_preview1:r.imports}),n);Se(n),r.setInstance(s);let a=0;try{s.exports._start()}catch(c){if(c instanceof _n)a=c.code;else throw c}return{exitCode:a,...i.captureStdio?{stdout:r.readStdio(1),stderr:r.readStdio(2)}:{},files:Object.fromEntries((i.readFiles??[]).flatMap(c=>{const l=r.readFileIfPresent(c);return l?[[c,l]]:[]}))}}}async function Ln(t,e=globalThis.fetch){const i=typeof t=="function"?await t():await t;if(i instanceof WebAssembly.Module)return i;if(typeof i=="string"||qo(i)){if(!e)throw new Error("A fetch implementation is required to load converter WASM from a URL.");return Hr(await e(String(i)))}return typeof Response<"u"&&i instanceof Response?Hr(i):WebAssembly.compile(i)}function qo(t){return typeof URL<"u"&&t instanceof URL}async function Hr(t){var i;if(!t.ok)throw new Error(`Failed to fetch converter WASM: ${t.status} ${t.statusText}`.trim());const e=await Go(t);return typeof WebAssembly.compileStreaming=="function"&&((i=e.headers.get("content-type"))==null?void 0:i.split(";",1)[0])==="application/wasm"?WebAssembly.compileStreaming(e):WebAssembly.compile(await e.arrayBuffer())}class _n extends Error{constructor(e){super(`WASI exited with code ${e}`),this.code=e}}const Q=0,ge=8,Xo=20,Jr=28,hi=31,mi=44,Kr=54,ya=55,Un=2,wa=3,Fa=4,Zr=1,$o=2,Yo=4,Qo=8,en=1;class Cn{constructor(e){L(this,"imports",{args_get:(e2,i)=>this.argsGet(e2,i),args_sizes_get:(e2,i)=>this.argsSizesGet(e2,i),clock_time_get:(e2,i,n)=>this.clockTimeGet(n),environ_get:(e2,i)=>Q,environ_sizes_get:(e2,i)=>this.environSizesGet(e2,i),fd_close:e2=>this.fdClose(e2),fd_fdstat_get:(e2,i)=>this.fdFdstatGet(e2,i),fd_fdstat_set_flags:(e2,i)=>Q,fd_filestat_get:(e2,i)=>this.fdFilestatGet(e2,i),fd_pread:(e2,i,n,r,o)=>this.fdRead(e2,i,n,o,Number(r),false),fd_prestat_dir_name:(e2,i,n)=>this.fdPrestatDirName(e2,i,n),fd_prestat_get:(e2,i)=>this.fdPrestatGet(e2,i),fd_read:(e2,i,n,r)=>this.fdRead(e2,i,n,r),fd_seek:(e2,i,n,r)=>this.fdSeek(e2,i,n,r),fd_tell:(e2,i)=>this.fdTell(e2,i),fd_write:(e2,i,n,r)=>this.fdWrite(e2,i,n,r),path_create_directory:(e2,i,n)=>this.pathCreateDirectory(e2,i,n),path_filestat_get:(e2,i,n,r,o)=>this.pathFilestatGet(e2,n,r,o),path_open:(e2,i,n,r,o,s,a,c,l)=>this.pathOpen(e2,n,r,o,c,l),path_remove_directory:(e2,i,n)=>this.pathRemoveDirectory(e2,i,n),path_unlink_file:(e2,i,n)=>this.pathUnlinkFile(e2,i,n),poll_oneoff:(e2,i,n,r)=>this.pollOneoff(r),proc_exit:e2=>{throw new _n(e2)},random_get:(e2,i)=>this.randomGet(e2,i),sched_yield:()=>Q});L(this,"instance");L(this,"captureStdio");L(this,"stdio",{1:[],2:[]});L(this,"args");L(this,"files",new Map);L(this,"dirs",new Set(["/","/work"]));L(this,"fds",new Map([[0,{kind:"stdio",fd:0,position:0}],[1,{kind:"stdio",fd:1,position:0}],[2,{kind:"stdio",fd:2,position:0}],[3,{kind:"dir",path:"/work",position:0}]]));L(this,"nextFd",4);this.args=e.args,this.captureStdio=e.captureStdio??false;for(const[i,n]of Object.entries(e.files))this.writeInitialFile(i,n)}setInstance(e){this.instance=e}readStdio(e){return new TextDecoder().decode(new Uint8Array(this.stdio[e]))}readFile(e){const i=this.files.get(qt(e));if(!i)throw new Error(`WASM file was not written: ${e}`);const n=new Uint8Array(i.byteLength);return n.set(i),n}readFileIfPresent(e){return this.files.has(qt(e))?this.readFile(e):void 0}get memory(){var i;const e=(i=this.instance)==null?void 0:i.exports.memory;if(!(e instanceof WebAssembly.Memory))throw new Error("WASM instance did not export memory.");return e}get bytes(){return new Uint8Array(this.memory.buffer)}get view(){return new DataView(this.memory.buffer)}argsSizesGet(e,i){return this.view.setUint32(e,this.args.length,true),this.view.setUint32(i,Ho(this.args),true),Q}argsGet(e,i){return this.writeStringList(this.args,e,i)}environSizesGet(e,i){return this.view.setUint32(e,0,true),this.view.setUint32(i,0,true),Q}clockTimeGet(e){return this.view.setBigUint64(e,BigInt(Date.now())*1000000n,true),Q}fdClose(e){return e<=3||this.fds.delete(e)?Q:ge}fdFdstatGet(e,i){const n=this.fds.get(e);return n?(this.bytes.fill(0,i,i+24),this.bytes[i]=Jo(n),this.view.setBigUint64(i+8,0xffffffffffffffffn,true),this.view.setBigUint64(i+16,0xffffffffffffffffn,true),Q):ge}fdFilestatGet(e,i){var r;const n=this.fds.get(e);return n?n.kind==="file"?(this.writeFilestat(i,Fa,((r=this.files.get(n.path))==null?void 0:r.byteLength)??0),Q):n.kind==="dir"?(this.writeFilestat(i,wa,0),Q):(this.writeFilestat(i,Un,0),Q):ge}fdPrestatGet(e,i){const n=this.fds.get(e);return!n||n.kind!=="dir"||n.path!=="/work"?ge:(this.bytes.fill(0,i,i+8),this.view.setUint32(i+4,n.path.length,true),Q)}fdPrestatDirName(e,i,n){const r=this.fds.get(e);if(!r||r.kind!=="dir")return ge;const o=new TextEncoder().encode(r.path);return this.bytes.set(o.subarray(0,n),i),Q}fdRead(e,i,n,r,o,s=true){const a=this.fds.get(e);if(!a)return ge;if(a.kind!=="file")return this.view.setUint32(r,0,true),a.kind==="dir"?hi:Q;const c=this.files.get(a.path)??new Uint8Array;let l=o??a.position,u=0;for(const[f,y]of this.iovs(i,n)){const p=c.subarray(l,l+y);if(this.bytes.set(p,f),l+=p.byteLength,u+=p.byteLength,p.byteLength<y)break}return s&&o===void 0&&(a.position=l),this.view.setUint32(r,u,true),Q}fdSeek(e,i,n,r){var c;const o=this.fds.get(e);if(!o||o.kind!=="file")return(o==null?void 0:o.kind)==="dir"?hi:ge;if(n!==0&&n!==1&&n!==2)return Jr;const a=(n===0?0:n===1?o.position:n===2?((c=this.files.get(o.path))==null?void 0:c.byteLength)??0:-1)+Number(i);return!Number.isSafeInteger(a)||a<0?Jr:(o.position=a,this.view.setBigUint64(r,BigInt(a),true),Q)}fdTell(e,i){const n=this.fds.get(e);return!n||n.kind!=="file"?(n==null?void 0:n.kind)==="dir"?hi:ge:(this.view.setBigUint64(i,BigInt(n.position),true),Q)}fdWrite(e,i,n,r){const o=this.fds.get(e);if(!o)return ge;let s=0;if(o.kind==="stdio"){for(const[a,c]of this.iovs(i,n)){const l=this.captureStdio?this.stdio[o.fd]:void 0;if(l){const u=a+Math.min(c,Math.max(0,1048576-l.length)),f=this.bytes;for(let y=a;y<u;y++)l.push(f[y])}s+=c}return this.view.setUint32(r,s,true),Q}if(o.kind!=="file")return hi;for(const[a,c]of this.iovs(i,n)){const l=this.bytes.subarray(a,a+c);this.writeFileChunk(o,l),s+=c}return this.view.setUint32(r,s,true),Q}pathCreateDirectory(e,i,n){const r=this.readPath(e,i,n);return r?(this.ensureParentDir(r),this.files.has(r)?Kr:(this.dirs.add(r),Q)):ge}pathFilestatGet(e,i,n,r){var s;const o=this.readPath(e,i,n);return o?this.files.has(o)?(this.writeFilestat(r,Fa,((s=this.files.get(o))==null?void 0:s.byteLength)??0),Q):this.dirs.has(o)?(this.writeFilestat(r,wa,0),Q):mi:ge}pathOpen(e,i,n,r,o,s){var l;const a=this.readPath(e,i,n);if(!a)return ge;if(r&Zr&&r&Yo&&(this.files.has(a)||this.dirs.has(a)))return Xo;if(!!(r&$o))return this.dirs.has(a)?this.openDescriptor({kind:"dir",path:a,position:0},s):this.files.has(a)?Kr:mi;if(this.files.has(a))r&Qo&&this.files.set(a,new Uint8Array);else{if(!(r&Zr))return this.dirs.has(a)?hi:mi;this.ensureParentDir(a),this.files.set(a,new Uint8Array)}return this.openDescriptor({kind:"file",path:a,position:o&en?((l=this.files.get(a))==null?void 0:l.byteLength)??0:0,append:!!(o&en)},s)}pathRemoveDirectory(e,i,n){const r=this.readPath(e,i,n);if(!r)return ge;if(r==="/"||r==="/work")return ya;for(const o of this.dirs)if(o!==r&&ga(o)===r)return ya;for(const o of this.files.keys())if(ga(o)===r)return ya;return this.dirs.delete(r)?Q:mi}pathUnlinkFile(e,i,n){const r=this.readPath(e,i,n);return r?this.files.delete(r)?Q:mi:ge}pollOneoff(e){return this.view.setUint32(e,0,true),Q}randomGet(e,i){const n=this.bytes.subarray(e,e+i),r=globalThis.crypto;if(r!=null&&r.getRandomValues)r.getRandomValues(n);else for(let o=0;o<n.length;o+=1)n[o]=Math.floor(Math.random()*256);return Q}writeStringList(e,i,n){let r=n;for(let o=0;o<e.length;o+=1){const s=new TextEncoder().encode(e[o]);this.view.setUint32(i+o*4,r,true),this.bytes.set(s,r),this.bytes[r+s.byteLength]=0,r+=s.byteLength+1}return Q}iovs(e,i){const n=[];for(let r=0;r<i;r+=1){const o=e+r*8;n.push([this.view.getUint32(o,true),this.view.getUint32(o+4,true)])}return n}readPath(e,i,n){const r=this.fds.get(e);if(!r||r.kind!=="dir")return null;const o=new TextDecoder().decode(this.bytes.subarray(i,i+n));return Ko(r.path,o)}openDescriptor(e,i){const n=this.nextFd++;return this.fds.set(n,e),this.view.setUint32(i,n,true),Q}writeFilestat(e,i,n){this.bytes.fill(0,e,e+64),this.bytes[e+16]=i,this.view.setBigUint64(e+24,1n,true),this.view.setBigUint64(e+32,BigInt(n),true)}writeInitialFile(e,i){const n=qt(e);this.ensureParentDir(n);const r=new Uint8Array(i.byteLength);r.set(i),this.files.set(n,r)}ensureParentDir(e){const i=ga(e);i===e||this.dirs.has(i)||(this.ensureParentDir(i),this.dirs.add(i))}writeFileChunk(e,i){if(!i.byteLength)return;const n=this.files.get(e.path)??new Uint8Array,r=e.append?n.byteLength:e.position,o=Math.max(n.byteLength,r+i.byteLength);let s;if(o<=n.buffer.byteLength)s=new Uint8Array(n.buffer,0,o);else{const a=new Uint8Array(Math.max(o,n.buffer.byteLength*2));a.set(n),s=a.subarray(0,o)}s.set(i,r),this.files.set(e.path,s),e.position=r+i.byteLength}}function Ho(t){return t.reduce((e,i)=>e+new TextEncoder().encode(i).byteLength+1,0)}function Jo(t){switch(t.kind){case"dir":return wa;case"file":return Fa;default:return Un}}function Ko(t,e){return e.startsWith("/")?qt(e):qt(`${t}/${e}`)}function qt(t){const e=[];for(const i of t.replace(/\\/g,"/").split("/"))if(!(!i||i===".")){if(i===".."){e.pop();continue}e.push(i)}return`/${e.join("/")}`}function ga(t){const e=qt(t);if(e==="/")return"/";const i=e.lastIndexOf("/");return i<=0?"/":e.slice(0,i)}const Zo=[{sourceFormat:"dng",targetFormat:"jpg"},{sourceFormat:"cr2",targetFormat:"jpg"},{sourceFormat:"cr3",targetFormat:"jpg"},{sourceFormat:"nef",targetFormat:"jpg"},{sourceFormat:"nrw",targetFormat:"jpg"},{sourceFormat:"arw",targetFormat:"jpg"},{sourceFormat:"sr2",targetFormat:"jpg"},{sourceFormat:"srf",targetFormat:"jpg"},{sourceFormat:"orf",targetFormat:"jpg"},{sourceFormat:"rw2",targetFormat:"jpg"},{sourceFormat:"rwl",targetFormat:"jpg"},{sourceFormat:"raf",targetFormat:"jpg"},{sourceFormat:"kdc",targetFormat:"jpg"},{sourceFormat:"x3f",targetFormat:"jpg"},{sourceFormat:"pef",targetFormat:"jpg"},{sourceFormat:"srw",targetFormat:"jpg"},{sourceFormat:"erf",targetFormat:"jpg"},{sourceFormat:"mef",targetFormat:"jpg"},{sourceFormat:"mos",targetFormat:"jpg"},{sourceFormat:"mrw",targetFormat:"jpg"},{sourceFormat:"3fr",targetFormat:"jpg"},{sourceFormat:"iiq",targetFormat:"jpg"},{sourceFormat:"icns",targetFormat:"png"}],es=new Set(Tn.map(t=>dt(t.sourceFormat))),ts=new Set(Tn.map(t=>`${dt(t.sourceFormat)}->${dt(t.targetFormat)}`)),is=new Set(Zo.map(t=>`${dt(t.sourceFormat)}->${dt(t.targetFormat)}`));class Qi extends Error{constructor(e){super(e.errorMessage||e.errorCode||"WASM conversion failed."),this.result=e,this.name="WasmConversionError"}}function Hc(t){const e=wi(t),i=t.officeWasm?wi({wasm:t.officeWasm,fetch:t.fetch}):void 0,n=t.imageWasm?La(()=>Ln(t.imageWasm,t.fetch)):void 0,r=t.imageWasm?wi({wasm:n,fetch:t.fetch}):void 0,o=n?as(n):void 0;return{async convert(s,a){Se(a.signal);const c=dt(s.sourceFormat),l=dt(s.targetFormat),u=rs(c,l),f=`/work/input.${c}`,y=`/work/output.${l}`,p="/work/options.json",h="/work/result.json",d=await An(s.source,t.fetch,a.signal);Se(a.signal);const m=JSON.stringify({...s.password?{password:s.password}:{},...s.locale?{locale:s.locale}:{}}),g=!!(r&&is.has(u));if(g&&l==="jpg"&&o){const D=await o(d,a.signal);if(Se(a.signal),D)return D}const b=g?r:e,x=(D,F)=>D({args:[g?"converter-image":"converter-core","--input",f,"--output",y,"--source",c,"--target",l,"--options",p,"--result",h],files:{[f]:F,[p]:new TextEncoder().encode(m)},readFiles:[h,y],signal:a.signal});let v=await x(b,d),w=$i(v.files[h]);if(!w.ok&&w.errorCode==="engine_unavailable"&&w.requiredModule==="office"&&i){const D=await x(i,d);tn($i(D.files[h]),D.exitCode),v=await x(e,D.files[y]),w=$i(v.files[h])}return Se(a.signal),tn(w,v.exitCode),{source:v.files[y],format:dt(w.targetFormat||l),contentType:w.contentType,warnings:w.warnings}}}}function tn(t,e){if(!t.ok)throw new Qi(t);if(e!==0)throw new Qi({...t,ok:false,errorCode:t.errorCode||"conversion_failed",errorMessage:t.errorMessage||`converter WASM exited with code ${e}`})}function as(t){const e=La(async()=>{const i=await t(),n=new Set(WebAssembly.Module.exports(i).map(s=>s.name));if(!["filens_image_alloc","filens_image_free","filens_image_preview","memory"].every(s=>n.has(s)))return null;const r=new Cn({args:["converter-image"],files:{}}),o=await WebAssembly.instantiate(i,{wasi_snapshot_preview1:r.imports});return r.setInstance(o),o.exports});return async(i,n)=>{const r=await ut(e(),n);if(Se(n),!r||i.length===0)return null;let o=0,s=0,a=0;try{if(o=r.filens_image_alloc(i.length)>>>0,!o)throw new Error("Image core could not allocate its input buffer.");new Uint8Array(r.memory.buffer).set(i,o);const c=r.filens_image_preview(o,i.length);if(s=Number(c&0xffffffffn),a=Number(c>>32n),!s||a<4||s+a>r.memory.buffer.byteLength)throw new Error("Image core returned an invalid preview buffer.");const l=new Uint8Array(r.memory.buffer,s,a),u=new DataView(l.buffer,l.byteOffset,4).getUint32(0,true);if(u>l.length-4)throw new Error("Image core returned invalid preview metadata.");const f=$i(l.subarray(4,4+u));if(!f.ok)throw new Qi(f);return{source:l.slice(4+u),format:"jpg",contentType:f.contentType,warnings:f.warnings}}finally{s&&a&&r.filens_image_free(s,a),o&&r.filens_image_free(o,i.length)}}}function rs(t,e){const i=`${t}->${e}`;if(ts.has(i))return i;const n=es.has(t)?`unsupported conversion pair: ${t} -> ${e}`:`unsupported source format: ${t}`;throw new Qi({ok:false,sourceFormat:t,targetFormat:e,warnings:[],errorCode:"unsupported_format",errorMessage:n,metrics:{}})}function $i(t){const e=new TextDecoder().decode(t),i=JSON.parse(e);return{...i,warnings:Array.isArray(i.warnings)?i.warnings.map(String):[]}}function dt(t){return t.trim().replace(/^\./,"").toLowerCase()}const an=64*1024*1024;function Jc(){return{async convert(t,e){const i=t.sourceFormat.replace(/^\./,"").toLowerCase(),n=t.targetFormat.replace(/^\./,"").toLowerCase();if(!(["heic","heif"].includes(i)&&n==="png"))throw new Error(`Unsupported media conversion: ${i} -> ${n}.`);if(Se(e.signal),(t.source instanceof Blob?t.source.size:typeof t.source=="string"?0:t.source.byteLength)>an)throw new Error("HEIF input exceeds the 64 MiB preview limit.");const r=ArrayBuffer.isView(t.source)?t.source.slice():t.source instanceof ArrayBuffer?t.source.slice(0):t.source,o=await An(r,globalThis.fetch,e.signal,an);Se(e.signal);const s=await ut(import("./media-runtime-tb-Q4Sah.js"),e.signal);return Se(e.signal),s.convertMedia(o,i,e.signal)}}}function H(t){if(t!=null&&t.aborted)throw new DOMException("Panorama preview was aborted.","AbortError")}function le(t,e,i){return new Promise((n,r)=>{const o=()=>r(new DOMException("Panorama preview was aborted.","AbortError"));e.aborted?o():e.addEventListener("abort",o,{once:true}),t.then(s=>{e.removeEventListener("abort",o),e.aborted?i==null||i(s):n(s)},s=>{e.removeEventListener("abort",o),e.aborted||r(s)})})}function ns(t,e){const i=n=>(H(e),le(n(),e));return{open:(n,r)=>i(()=>t.open(n,{...r,signal:e})),...t.decodeImage?{decodeImage:()=>i(()=>t.decodeImage(e))}:{},readSample:(n,r,o)=>i(()=>t.readSample(n,r,o??e)),readImuWindow:(n,r,o)=>i(()=>t.readImuWindow(n,r,o??e)),computeSeam:(n,r)=>i(()=>t.computeSeam(n,r??e)),seek:n=>(H(e),t.seek(n)),getManifest:()=>(H(e),t.getManifest()),close:()=>{e.aborted||t.close()},abort:()=>{e.aborted||t.abort()}}}const rn=8,Mi=64<<20,os=128<<20,nn=120,ss=8<<20;class B extends Error{constructor(e,i){super(i),this.code=e,this.name="PanoramaProcessorError"}}function cs(t){const e=t.fetch??globalThis.fetch,i=wi({wasm:t.wasm,fetch:e}),n=t.imageWasm?wi({wasm:t.imageWasm,fetch:e}):void 0,r=l=>{const u=new AbortController,f=pi(u.signal,l);return{controller:u,...f,companionTrackIds:new Map}};let o=r();const s=l=>{const{reader:u,companionProcessor:f}=l;l.reader=void 0,l.manifest=void 0,l.companionProcessor=void 0,l.companionTrackIds.clear(),l.controller.abort(),l.release(),u==null||u.close(),f==null||f.close()},a=()=>{const l=o;o=r(),s(l)},c=async(l,u,f,y)=>{var x;ie(y);const p=l.companionTrackIds.get(u);if(p!==void 0&&l.companionProcessor){const v=await l.companionProcessor.readSample(p,f,y);return ie(y),{...v,trackId:u}}const{reader:h,manifest:d}=l;if(!h||!d)throw new B("invalid_manifest","Open a panorama source before reading samples.");const m=d.tracks.find(v=>v.id===u)??(((x=d.metadataTrack)==null?void 0:x.id)===u?d.metadataTrack:void 0),g=m==null?void 0:m.samples[f];if(!m||!g)throw new RangeError(`Unknown panorama sample ${u}:${f}.`);const b=await h.read(g.offset,g.size,y);return{...g,trackId:u,timescale:m.timescale,data:b}};return{async open(l,u){var h;const f=r(u.signal),y=o;o=f,s(y);const p=f.signal;try{ie(p);const d=await le(wt.open(l,e,p),p,k=>k.close());ie(p),f.reader=d;let m;const g=new Map,b=u.format==="insp"?1<<20:65536,x=u.format==="insp"?65536:1<<20,v=[{offset:0,length:Math.min(b,d.size)},{offset:Math.max(0,d.size-x),length:Math.min(x,d.size)}];await sn(d,g,v,p);let w;if(u.sidecar){const k=await wt.open(u.sidecar,e,p);try{if(k.size>8<<20)throw new B("resource_limit","Panorama sidecar exceeds 8 MiB.");w=await k.read(0,k.size,p)}finally{k.close()}}for(let k=0;k<rn;k+=1){ie(p);const D=[...g.values()].map((A,C)=>({offset:A.offset,path:`/work/range-${C}.bin`})),F={"/work/options.json":new TextEncoder().encode(JSON.stringify({logicalSize:d.size,ranges:D,...w?{sidecarPath:"/work/sidecar.pb"}:{}}))};w&&(F["/work/sidecar.pb"]=w),[...g.values()].forEach((A,C)=>{F[`/work/range-${C}.bin`]=A.bytes});const S="/work/result.json",R=await i({args:["converter-core","--operation","inspect-panorama","--source",u.format,"--options","/work/options.json","--result",S],files:F,readFiles:[S],signal:p});ie(p);const _=R.files[S];if(!_)throw new B("invalid_manifest","Panorama inspector did not return a result.");const T=JSON.parse(new TextDecoder().decode(_));if(T.ok&&T.payload){if(m=us(T.payload),u.companion){f.companionProcessor=cs(t);const A=await f.companionProcessor.open(u.companion,{format:u.format,sidecar:u.sidecar,signal:p});ie(p);const C=new Set(m.tracks.map(J=>J.id)),j=new Map,G=A.tracks.map(J=>{let Z=J.id;for(;C.has(Z);)Z+=1e6;return C.add(Z),f.companionTrackIds.set(Z,J.id),j.set(J.id,Z),{...J,id:Z}}),q=A.lenses.map(J=>({...J,sourceTrackId:J.sourceTrackId===void 0?void 0:j.get(J.sourceTrackId)})),te=[...m.tracks,...G],ne=hs(fs(m.lenses,q),te),ue=[...m.warnings,...A.warnings];m={...m,cameraModel:m.cameraModel||A.cameraModel,firmware:m.firmware||A.firmware,textureOrigin:m.textureOrigin||A.textureOrigin,projection:m.projection.kind==="unknown"?A.projection:m.projection,calibrationSource:m.calibrationSource==="unavailable"?A.calibrationSource:m.calibrationSource,confidence:m.confidence==="low"?A.confidence:m.confidence,tracks:te,lenses:ne,warnings:ne.length>=2?ue.filter(J=>!J.includes("matching companion file")&&!J.startsWith("INSV calibration was not found")):ue}}return f.manifest=m,m}if(T.errorCode!=="need_ranges"||!((h=T.requiredRanges)!=null&&h.length))throw va(T.errorCode,T.errorMessage);await sn(d,g,T.requiredRanges,p)}throw new B("resource_limit",`Panorama inspection exceeded ${rn} range iterations.`)}catch(d){throw o===f&&(o=r()),s(f),d}},async decodeImage(l){var p;const u=o,f=pi(u.signal,l),y=f.signal;try{ie(y);const h=u.reader,d=u.manifest;if(!h||(d==null?void 0:d.format)!=="dng")throw new B("invalid_manifest","Open a DNG before developing its RAW preview.");if(!n)throw new B("codec_unsupported","Calibrated DNG preview requires converter-image.wasm (imageWasm).");if(h.size>256*1024*1024)throw new B("resource_limit","RAW preview input exceeds 256 MiB.");const m=new Uint8Array(h.size);for(let w=0;w<m.length;w+=Mi){const k=Math.min(Mi,m.length-w),D=await h.read(w,k,y);if(ie(y),D.length!==k)throw new B("range_unavailable","DNG source returned an incomplete byte range.");m.set(D,w)}const g="/work/result.json",b="/work/preview.jpg",x=await n({args:["converter-image","--source","dng","--target","jpg","--input","/work/input.dng","--output",b,"--options","/work/options.json","--result",g],files:{"/work/input.dng":m,"/work/options.json":new TextEncoder().encode(JSON.stringify({preserveSensorGeometry:true}))},readFiles:[g,b],signal:y});ie(y);const v=JSON.parse(new TextDecoder().decode(x.files[g]??new Uint8Array));if(!v.ok||x.exitCode!==0||!((p=x.files[b])!=null&&p.length))throw new B("codec_unsupported",v.errorMessage||"WASM could not develop the DNG sensor preview.");return x.files[b]}finally{f.release()}},async readSample(l,u,f){const y=o,p=pi(y.signal,f);try{return await c(y,l,u,p.signal)}finally{p.release()}},async readImuWindow(l,u,f){var h;const y=o,p=pi(y.signal,f);try{ie(p.signal);const d=y.manifest;if(!(d!=null&&d.metadataTrack))return[];if(!Number.isSafeInteger(l)||!Number.isSafeInteger(u)||l<0||u<0||u>nn)throw new B("resource_limit",`Panorama metadata windows are limited to ${nn} samples.`);const m=d.metadataTrack,g=m.samples.slice(l,l+u);if(g.reduce((S,R)=>S+R.size,0)>ss)throw new B("resource_limit","Panorama metadata window exceeds 8 MiB.");const x={},v=[];for(let S=0;S<g.length;S+=1){const R=await c(y,m.id,l+S,p.signal),_=`/work/metadata-${S}.bin`;x[_]=R.data,v.push({path:_,pts:R.pts,timescale:R.timescale})}const w="/work/result.json";ie(p.signal),x["/work/options.json"]=new TextEncoder().encode(JSON.stringify({vendor:d.vendor,samples:v}));const k=await i({args:["converter-core","--operation","decode-panorama-metadata","--options","/work/options.json","--result",w],files:x,readFiles:[w],signal:p.signal});ie(p.signal);const D=k.files[w];if(!D)throw new B("invalid_manifest","Panorama metadata decoder did not return a result.");const F=JSON.parse(new TextDecoder().decode(D));if(!F.ok||!Array.isArray((h=F.payload)==null?void 0:h.samples))throw va(F.errorCode,F.errorMessage);return F.payload.samples}finally{p.release()}},seek(l){const u=o.manifest;return u?Object.fromEntries(u.tracks.map(f=>[f.id,ds(f,l)])):{}},async computeSeam(l,u){const f=pi(o.signal,u);try{ie(f.signal);const y="/work/result.json",p=await i({args:["converter-core","--operation","panorama-seam","--options","/work/options.json","--result",y],files:{"/work/options.json":new TextEncoder().encode(JSON.stringify({width:l.width,height:l.height,costs:Array.from(l.costs),previous:l.previous?Array.from(l.previous):[],temporalWeight:l.temporalWeight??2,maxStep:l.maxStep??1}))},readFiles:[y],signal:f.signal});ie(f.signal);const h=p.files[y];if(!h)throw new B("invalid_manifest","Panorama seam solver did not return a result.");const d=JSON.parse(new TextDecoder().decode(h));if(!d.ok||!d.payload)throw va(d.errorCode,d.errorMessage);const m=d.payload;if(!Array.isArray(m.seam)||!Number.isFinite(m.cost))throw new B("invalid_manifest","Panorama seam solver returned an invalid path.");return m}finally{f.release()}},close:a,abort:()=>o.controller.abort(),getManifest:()=>o.manifest}}function En(t){return{codec:ms(t),codedWidth:t.width,codedHeight:t.height,description:In(t.decoderConfig),optimizeForLatency:true}}function ls(t){return new EncodedVideoChunk({type:t.key?"key":"delta",timestamp:Math.round(t.pts*1e6/t.timescale),duration:Math.round(t.duration*1e6/t.timescale),data:t.data})}function us(t){var r;if(!t||!Array.isArray(t.tracks)||!Array.isArray(t.lenses))throw new B("invalid_manifest","Panorama inspector returned an invalid manifest.");const e=(r=t.lenses[0])==null?void 0:r.projection,i=typeof t.projection=="string"?e&&typeof e=="object"?e:{kind:t.projection}:{kind:"unknown"},n=t.lenses.map(o=>({...o,projection:o.projection&&typeof o.projection=="object"?o.projection:i}));return{...t,projection:i,lenses:n}}function ds(t,e){const i=Math.max(0,e)*t.timescale;let n=0;for(let r=0;r<t.samples.length;r+=1){const o=t.samples[r];if(o.pts>i)break;o.key&&(n=r)}return n}function fs(t,e){const i=t.slice(0,2),n=new Set(i.map(on));for(const r of e){if(i.length===2)break;const o=on(r);n.has(o)||(i.push(r),n.add(o))}return i}function hs(t,e){return e.length<t.length?t:t.map((i,n)=>i.sourceTrackId===void 0?{...i,sourceTrackId:e[n].id}:i)}function on(t){const e={...t};return delete e.sourceTrackId,delete e.sourceRect,JSON.stringify(e)}function ms(t){const e=In(t.decoderConfig);if((t.codec==="avc1"||t.codec==="avc3")&&e.length>=4)return`${t.codec}.${[...e.slice(1,4)].map(i=>i.toString(16).padStart(2,"0")).join("")}`;if((t.codec==="hvc1"||t.codec==="hev1")&&e.length>=13){const i=["","A","B","C"][e[1]>>6],n=e[1]&32?"H":"L",r=e[1]&31;let o=new DataView(e.buffer,e.byteOffset+2,4).getUint32(0),s=0;for(let u=0;u<32;u+=1)s=s<<1|o&1,o>>>=1;const a=(s>>>0).toString(16),c=[...e.slice(6,12)];for(;c.at(-1)===0;)c.pop();const l=c.length?`.${c.map(u=>u.toString(16)).join(".")}`:"";return`${t.codec}.${i}${r}.${a}.${n}${e[12]}${l}`}return t.codec}function In(t){return t?Uint8Array.from(t.match(/.{1,2}/g)??[],e=>Number.parseInt(e,16)):new Uint8Array}async function sn(t,e,i,n){for(const r of i){const o=r.offset+r.length;if(!Number.isSafeInteger(r.offset)||!Number.isSafeInteger(r.length)||!Number.isSafeInteger(o)||r.offset<0||r.length<=0||r.length>Mi||o>t.size)throw new B("resource_limit","Panorama inspector requested an invalid source range.");const s=[...e.values()].sort((u,f)=>u.offset-f.offset),a=[];let c=r.offset;for(const u of s)if(u.offset>c&&a.push({offset:c,length:Math.min(u.offset,o)-c}),c=Math.max(c,u.offset+u.bytes.length),c>=o)break;if(c<o&&a.push({offset:c,length:o-c}),s.reduce((u,f)=>u+f.bytes.length,0)+a.reduce((u,f)=>u+f.length,0)>os)throw new B("resource_limit","Panorama inspection exceeded its 128 MiB range budget.");for(const u of a){const f=await t.read(u.offset,u.length,n);e.set(`${u.offset}:${u.length}`,{offset:u.offset,bytes:f})}}}class wt{constructor(e,i,n){this.size=e,this.readRange=i,this.cleanup=n}static async open(e,i,n){if(ie(n),e instanceof Blob)return new wt(e.size,async(u,f)=>new Uint8Array(await e.slice(u,u+f).arrayBuffer()));if(e instanceof ArrayBuffer||ArrayBuffer.isView(e)){const u=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return new wt(u.byteLength,async(f,y)=>u.slice(f,f+y))}if(!i)throw new B("range_unavailable","A fetch implementation is required for remote panorama sources.");const r=String(e),o=await yi(i(r,{headers:{Range:"bytes=0-0"},signal:n}),n,gi);ie(n);const s=o.headers.get("content-range");if(o.status===206){const u=s==null?void 0:s.match(/^bytes 0-0\/(\d+)$/i),f=Number(u==null?void 0:u[1]);if(gi(o),!Number.isSafeInteger(f)||f<=0)throw new B("range_unavailable","Remote panorama size is unavailable.");return new wt(f,async(y,p,h)=>{var m;const d=await yi(i(r,{headers:{Range:`bytes=${y}-${y+p-1}`},signal:h}),h,gi);if(ie(h),d.status!==206||((m=d.headers.get("content-range"))==null?void 0:m.toLowerCase())!==`bytes ${y}-${y+p-1}/${f}`)throw gi(d),new B("range_unavailable","Remote server returned an inconsistent panorama byte range.");return new Uint8Array(await yi(d.arrayBuffer(),h))})}const a=Number(o.headers.get("content-length"));if(!o.ok||!Number.isSafeInteger(a)||a<=0||a>Mi)throw gi(o),new B("range_unavailable","Remote server must support HTTP byte ranges for large panorama files.");const c=new Uint8Array(await yi(o.arrayBuffer(),n));ie(n);const l=o.headers.get("content-encoding");if(!c.length||c.length>Mi||(!l||l.toLowerCase()==="identity")&&c.length!==a)throw new B("range_unavailable","Remote panorama body does not match its declared length or size limit.");return new wt(c.byteLength,async(u,f)=>c.slice(u,u+f))}async read(e,i,n){if(ie(n),!Number.isSafeInteger(e)||!Number.isSafeInteger(i)||e<0||i<0||i>this.size-e)throw new B("range_unavailable","Panorama source range is out of bounds.");if(!i)return new Uint8Array;const r=await yi(this.readRange(e,i,n),n);if(ie(n),r.length!==i)throw new B("range_unavailable","Panorama source returned an incomplete byte range.");return r}close(){var e;(e=this.cleanup)==null||e.call(this)}}function va(t,e){const i={range_unavailable:"range_unavailable",resource_limit:"resource_limit",sidecar_missing:"sidecar_missing",firmware_unknown:"firmware_unknown",invalid_panorama_options:"invalid_manifest",invalid_panorama_metadata:"invalid_manifest",unsupported_container:"invalid_manifest",unsupported_projection:"calibration_missing"};return new B(i[t??""]??"calibration_missing",e||t||"Panorama inspection failed.")}function pi(t,...e){const i=[...new Set([t,...e.filter(s=>!!s)])],n=[],r=()=>{n.splice(0).forEach(s=>s())};if(i.length===1)return{signal:i[0],release:r};if(typeof AbortSignal.any=="function")return{signal:AbortSignal.any(i),release:r};const o=new AbortController;for(const s of i){const a=()=>{o.abort(s.reason),r()};if(s.aborted){a();break}s.addEventListener("abort",a,{once:true}),n.push(()=>s.removeEventListener("abort",a))}return{signal:o.signal,release:r}}function yi(t,e,i){return e?le(t,e,i):t}function gi(t){var e;try{(e=t.body)==null||e.cancel().catch(()=>{})}catch{}}function ie(t){if(t!=null&&t.aborted)throw t.reason instanceof Error?t.reason:new DOMException("The panorama operation was aborted.","AbortError")}async function ps(t,e,i){var y,p,h,d;if(e.projection.kind!=="mei-extended"||!ta(e))throw new B("calibration_missing","This INSP does not contain two supported calibrated panorama lenses.");const n=e.width??Number(((y=i.image)==null?void 0:y.naturalWidth)??((p=i.image)==null?void 0:p.width)),r=e.height??Number(((h=i.image)==null?void 0:h.naturalHeight)??((d=i.image)==null?void 0:d.height));if(!(n>0)||!(r>0))throw new B("invalid_manifest","The calibrated INSP image dimensions are unavailable.");const o={id:0,codec:"jpeg",decoderConfig:"",width:n,height:r,timescale:1,samples:[]},s=e.lenses.slice(0,2).map(m=>({track:o,rect:m.sourceRect??{x:0,y:0,width:1,height:1}}));if(!s.every(m=>zn(m.rect)))throw new B("invalid_manifest","The calibrated INSP lenses are not bound to valid image regions.");i.flipY=Ua(e.textureOrigin),i.colorSpace=Ki,i.minFilter=Mt,i.generateMipmaps=false,i.needsUpdate=true;const a=new Ta(new Uint8Array(128*64).fill(128),128,64,Ra,Pa);a.needsUpdate=true,a.minFilter=Mt;const c=ys(e,s,i,a);Ca(c,e.lenses);const l=new Zi(500,96,64);l.scale(-1,1,1);const u=new ea(l,c),f=new jn(t,e,s,c,a);return await f.acceptImage(i.image),{mesh:u,update:()=>{},play:()=>{},pause:()=>{},seek:()=>{},close:()=>{f.close(),a.dispose(),l.dispose(),c.dispose()},duration:0,currentTime:0,paused:true,streamSyncMs:0,get dynamicSeam(){return f.active},stabilizationAvailable:false,stabilizationMode:"off",error:void 0,setStabilization:()=>"off"}}function ys(t,e,i,n){const r=t.lenses.slice(0,2);return new Aa({uniforms:{lens0:{value:i},lens1:{value:i},intrinsics0:{value:Yt(r[0])},intrinsics1:{value:Yt(r[1])},size0:{value:$t(r[0],e[0])},size1:{value:$t(r[1],e[1])},sourceRect0:{value:Xt(e[0],t.textureOrigin)},sourceRect1:{value:Xt(e[1],t.textureOrigin)},distortion0:{value:Ze(r[0])},distortion1:{value:Ze(r[1])},quaternion0:{value:ft(r[0])},quaternion1:{value:ft(r[1])},radialScale0:{value:St(r[0])},radialScale1:{value:St(r[1])},projectionKind:{value:1},xi0:{value:r[0].xi||0},xi1:{value:r[1].xi||0},tangential0:{value:ve(r[0].tangential)},tangential1:{value:ve(r[1].tangential)},thinPrism0:{value:Dt(r[0].thinPrism)},thinPrism1:{value:Dt(r[1].thinPrism)},sensorTilt0:{value:ve(r[0].sensorTilt)},sensorTilt1:{value:ve(r[1].sensorTilt)},seamMask:{value:n},useDynamicSeam:{value:0},exposureGain0:{value:[1,1,1]},exposureGain1:{value:[1,1,1]},stabilizationQuaternion:{value:[1,0,0,0]}},vertexShader:`
|
|
1
|
+
var To=Object.defineProperty;var Ro=(t,e,i)=>e in t?To(t,e,{enumerable:true,configurable:true,writable:true,value:i}):t[e]=i;var L=(t,e,i)=>Ro(t,typeof e!="symbol"?e+"":e,i);import{x as Tn,c as Po,b as Ao,y as Lo,z as _o}from"./core-EjELrtsP.js";import{ac as Uo,S as Ki,ad as Mt,ae as Ta,af as Ra,ag as Pa,ah as Zi,j as ea,ai as Co,aj as Aa,ak as Rn,m as Eo,o as Io,a9 as zo,al as Yr,w as Bo}from"./vendor-C1aIdQ-w.js";function Se(t){if(t!=null&&t.aborted)throw Pn()}function Pn(){return Object.assign(new Error("The conversion was aborted."),{name:"AbortError"})}function ut(t,e){return e?new Promise((i,n)=>{const r=()=>n(Pn());t.then(o=>{e.removeEventListener("abort",r),i(o)},o=>{e.removeEventListener("abort",r),n(o)}),e.aborted?r():e.addEventListener("abort",r,{once:true})}):t}function La(t){let e;return()=>{if(!e){const i=Promise.resolve().then(t);e=i,i.catch(()=>{e===i&&(e=void 0)})}return e}}function jo(t){return/^(?:https?:|blob:|\/|\.{1,2}\/)/i.test(t)}function No(t){return t.trimStart().toLowerCase().startsWith("data:")}function Oo(t){const e=atob(t),i=new Uint8Array(e.length);for(let n=0;n<i.length;n++)i[n]=e.charCodeAt(n);return i}function Vo(t){var c;const e=t.trimStart(),i=e.indexOf(",");if(i<0)throw new Error("Conversion data URL is missing its payload separator.");const n=e.slice(0,i),r=e.slice(i+1),o=(c=n.match(/^data:([^;,]+)/i))==null?void 0:c[1];if(/;base64$/i.test(n))return{bytes:Oo(r),contentType:o};const s=new TextEncoder().encode(r);let a=0;for(let l=0;l<s.length;l++){if(s[l]===37){const u=Qr(s[l+1]),f=Qr(s[l+2]);if(u>=0&&f>=0){s[a++]=u<<4|f,l+=2;continue}}s[a++]=s[l]}return{bytes:s.subarray(0,a),contentType:o}}function Qr(t){if(t>=48&&t<=57)return t-48;const e=t|32;return e>=97&&e<=102?e-87:-1}async function An(t,e=globalThis.fetch,i,n=1/0){var o;const r=s=>{if(s>n)throw new Error("Conversion source exceeds the preview byte limit.")};if(Wo(t)){r(t.size);const s=new Uint8Array(await ut(t.arrayBuffer(),i));return r(s.length),s}if(t instanceof ArrayBuffer)return r(t.byteLength),new Uint8Array(t);if(ArrayBuffer.isView(t))return r(t.byteLength),new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(typeof t=="string"){if(No(t)){r(Math.max(0,t.length-t.indexOf(",")-1)/3);const a=Vo(t).bytes;return r(a.length),a}if(jo(t)){if(!e)throw new Error("A fetch implementation is required to load a conversion source URL.");const a=await ut(e(t,{signal:i}),i);if(Se(i),!a.ok)throw new Error(`Failed to fetch conversion source: ${a.status} ${a.statusText}`.trim());try{if(r(Number(a.headers.get("content-length"))),!Number.isFinite(n)||!a.body){const l=new Uint8Array(await ut(a.arrayBuffer(),i));return r(l.length),l}const c=a.body.getReader();try{const l=[];let u=0;for(;;){const{value:p,done:h}=await ut(c.read(),i);if(h)break;u+=p.length,r(u),l.push(p)}const f=new Uint8Array(u);let y=0;for(const p of l)f.set(p,y),y+=p.length;return f}finally{await c.cancel().catch(()=>{}),c.releaseLock()}}catch(c){throw await((o=a.body)==null?void 0:o.cancel().catch(()=>{})),c}}r(t.length);const s=new TextEncoder().encode(t);return r(s.length),s}throw new Error("Unsupported conversion source type.")}function Wo(t){return typeof t=="object"&&t!==null&&"arrayBuffer"in t&&typeof t.arrayBuffer=="function"}async function Go(t){var i;if(((i=t.headers.get("content-type"))==null?void 0:i.split(";",1)[0])!=="application/wasm+gzip")return t;if(typeof DecompressionStream<"u"&&t.body)return new Response(t.body.pipeThrough(new DecompressionStream("gzip")),{headers:{"content-type":"application/wasm"}});const e=Uo(new Uint8Array(await t.arrayBuffer()));return new Response(e,{headers:{"content-type":"application/wasm"}})}function wi(t){const e=La(()=>Ln(t.wasm,t.fetch));return async i=>{const n=i.signal;Se(n);const r=new Cn({args:i.args,files:i.files,captureStdio:i.captureStdio}),o=await ut(e(),n);Se(n);const s=await ut(WebAssembly.instantiate(o,{wasi_snapshot_preview1:r.imports}),n);Se(n),r.setInstance(s);let a=0;try{s.exports._start()}catch(c){if(c instanceof _n)a=c.code;else throw c}return{exitCode:a,...i.captureStdio?{stdout:r.readStdio(1),stderr:r.readStdio(2)}:{},files:Object.fromEntries((i.readFiles??[]).flatMap(c=>{const l=r.readFileIfPresent(c);return l?[[c,l]]:[]}))}}}async function Ln(t,e=globalThis.fetch){const i=typeof t=="function"?await t():await t;if(i instanceof WebAssembly.Module)return i;if(typeof i=="string"||qo(i)){if(!e)throw new Error("A fetch implementation is required to load converter WASM from a URL.");return Hr(await e(String(i)))}return typeof Response<"u"&&i instanceof Response?Hr(i):WebAssembly.compile(i)}function qo(t){return typeof URL<"u"&&t instanceof URL}async function Hr(t){var i;if(!t.ok)throw new Error(`Failed to fetch converter WASM: ${t.status} ${t.statusText}`.trim());const e=await Go(t);return typeof WebAssembly.compileStreaming=="function"&&((i=e.headers.get("content-type"))==null?void 0:i.split(";",1)[0])==="application/wasm"?WebAssembly.compileStreaming(e):WebAssembly.compile(await e.arrayBuffer())}class _n extends Error{constructor(e){super(`WASI exited with code ${e}`),this.code=e}}const Q=0,ge=8,Xo=20,Jr=28,hi=31,mi=44,Kr=54,ya=55,Un=2,wa=3,Fa=4,Zr=1,$o=2,Yo=4,Qo=8,en=1;class Cn{constructor(e){L(this,"imports",{args_get:(e2,i)=>this.argsGet(e2,i),args_sizes_get:(e2,i)=>this.argsSizesGet(e2,i),clock_time_get:(e2,i,n)=>this.clockTimeGet(n),environ_get:(e2,i)=>Q,environ_sizes_get:(e2,i)=>this.environSizesGet(e2,i),fd_close:e2=>this.fdClose(e2),fd_fdstat_get:(e2,i)=>this.fdFdstatGet(e2,i),fd_fdstat_set_flags:(e2,i)=>Q,fd_filestat_get:(e2,i)=>this.fdFilestatGet(e2,i),fd_pread:(e2,i,n,r,o)=>this.fdRead(e2,i,n,o,Number(r),false),fd_prestat_dir_name:(e2,i,n)=>this.fdPrestatDirName(e2,i,n),fd_prestat_get:(e2,i)=>this.fdPrestatGet(e2,i),fd_read:(e2,i,n,r)=>this.fdRead(e2,i,n,r),fd_seek:(e2,i,n,r)=>this.fdSeek(e2,i,n,r),fd_tell:(e2,i)=>this.fdTell(e2,i),fd_write:(e2,i,n,r)=>this.fdWrite(e2,i,n,r),path_create_directory:(e2,i,n)=>this.pathCreateDirectory(e2,i,n),path_filestat_get:(e2,i,n,r,o)=>this.pathFilestatGet(e2,n,r,o),path_open:(e2,i,n,r,o,s,a,c,l)=>this.pathOpen(e2,n,r,o,c,l),path_remove_directory:(e2,i,n)=>this.pathRemoveDirectory(e2,i,n),path_unlink_file:(e2,i,n)=>this.pathUnlinkFile(e2,i,n),poll_oneoff:(e2,i,n,r)=>this.pollOneoff(r),proc_exit:e2=>{throw new _n(e2)},random_get:(e2,i)=>this.randomGet(e2,i),sched_yield:()=>Q});L(this,"instance");L(this,"captureStdio");L(this,"stdio",{1:[],2:[]});L(this,"args");L(this,"files",new Map);L(this,"dirs",new Set(["/","/work"]));L(this,"fds",new Map([[0,{kind:"stdio",fd:0,position:0}],[1,{kind:"stdio",fd:1,position:0}],[2,{kind:"stdio",fd:2,position:0}],[3,{kind:"dir",path:"/work",position:0}]]));L(this,"nextFd",4);this.args=e.args,this.captureStdio=e.captureStdio??false;for(const[i,n]of Object.entries(e.files))this.writeInitialFile(i,n)}setInstance(e){this.instance=e}readStdio(e){return new TextDecoder().decode(new Uint8Array(this.stdio[e]))}readFile(e){const i=this.files.get(qt(e));if(!i)throw new Error(`WASM file was not written: ${e}`);const n=new Uint8Array(i.byteLength);return n.set(i),n}readFileIfPresent(e){return this.files.has(qt(e))?this.readFile(e):void 0}get memory(){var i;const e=(i=this.instance)==null?void 0:i.exports.memory;if(!(e instanceof WebAssembly.Memory))throw new Error("WASM instance did not export memory.");return e}get bytes(){return new Uint8Array(this.memory.buffer)}get view(){return new DataView(this.memory.buffer)}argsSizesGet(e,i){return this.view.setUint32(e,this.args.length,true),this.view.setUint32(i,Ho(this.args),true),Q}argsGet(e,i){return this.writeStringList(this.args,e,i)}environSizesGet(e,i){return this.view.setUint32(e,0,true),this.view.setUint32(i,0,true),Q}clockTimeGet(e){return this.view.setBigUint64(e,BigInt(Date.now())*1000000n,true),Q}fdClose(e){return e<=3||this.fds.delete(e)?Q:ge}fdFdstatGet(e,i){const n=this.fds.get(e);return n?(this.bytes.fill(0,i,i+24),this.bytes[i]=Jo(n),this.view.setBigUint64(i+8,0xffffffffffffffffn,true),this.view.setBigUint64(i+16,0xffffffffffffffffn,true),Q):ge}fdFilestatGet(e,i){var r;const n=this.fds.get(e);return n?n.kind==="file"?(this.writeFilestat(i,Fa,((r=this.files.get(n.path))==null?void 0:r.byteLength)??0),Q):n.kind==="dir"?(this.writeFilestat(i,wa,0),Q):(this.writeFilestat(i,Un,0),Q):ge}fdPrestatGet(e,i){const n=this.fds.get(e);return!n||n.kind!=="dir"||n.path!=="/work"?ge:(this.bytes.fill(0,i,i+8),this.view.setUint32(i+4,n.path.length,true),Q)}fdPrestatDirName(e,i,n){const r=this.fds.get(e);if(!r||r.kind!=="dir")return ge;const o=new TextEncoder().encode(r.path);return this.bytes.set(o.subarray(0,n),i),Q}fdRead(e,i,n,r,o,s=true){const a=this.fds.get(e);if(!a)return ge;if(a.kind!=="file")return this.view.setUint32(r,0,true),a.kind==="dir"?hi:Q;const c=this.files.get(a.path)??new Uint8Array;let l=o??a.position,u=0;for(const[f,y]of this.iovs(i,n)){const p=c.subarray(l,l+y);if(this.bytes.set(p,f),l+=p.byteLength,u+=p.byteLength,p.byteLength<y)break}return s&&o===void 0&&(a.position=l),this.view.setUint32(r,u,true),Q}fdSeek(e,i,n,r){var c;const o=this.fds.get(e);if(!o||o.kind!=="file")return(o==null?void 0:o.kind)==="dir"?hi:ge;if(n!==0&&n!==1&&n!==2)return Jr;const a=(n===0?0:n===1?o.position:n===2?((c=this.files.get(o.path))==null?void 0:c.byteLength)??0:-1)+Number(i);return!Number.isSafeInteger(a)||a<0?Jr:(o.position=a,this.view.setBigUint64(r,BigInt(a),true),Q)}fdTell(e,i){const n=this.fds.get(e);return!n||n.kind!=="file"?(n==null?void 0:n.kind)==="dir"?hi:ge:(this.view.setBigUint64(i,BigInt(n.position),true),Q)}fdWrite(e,i,n,r){const o=this.fds.get(e);if(!o)return ge;let s=0;if(o.kind==="stdio"){for(const[a,c]of this.iovs(i,n)){const l=this.captureStdio?this.stdio[o.fd]:void 0;if(l){const u=a+Math.min(c,Math.max(0,1048576-l.length)),f=this.bytes;for(let y=a;y<u;y++)l.push(f[y])}s+=c}return this.view.setUint32(r,s,true),Q}if(o.kind!=="file")return hi;for(const[a,c]of this.iovs(i,n)){const l=this.bytes.subarray(a,a+c);this.writeFileChunk(o,l),s+=c}return this.view.setUint32(r,s,true),Q}pathCreateDirectory(e,i,n){const r=this.readPath(e,i,n);return r?(this.ensureParentDir(r),this.files.has(r)?Kr:(this.dirs.add(r),Q)):ge}pathFilestatGet(e,i,n,r){var s;const o=this.readPath(e,i,n);return o?this.files.has(o)?(this.writeFilestat(r,Fa,((s=this.files.get(o))==null?void 0:s.byteLength)??0),Q):this.dirs.has(o)?(this.writeFilestat(r,wa,0),Q):mi:ge}pathOpen(e,i,n,r,o,s){var l;const a=this.readPath(e,i,n);if(!a)return ge;if(r&Zr&&r&Yo&&(this.files.has(a)||this.dirs.has(a)))return Xo;if(!!(r&$o))return this.dirs.has(a)?this.openDescriptor({kind:"dir",path:a,position:0},s):this.files.has(a)?Kr:mi;if(this.files.has(a))r&Qo&&this.files.set(a,new Uint8Array);else{if(!(r&Zr))return this.dirs.has(a)?hi:mi;this.ensureParentDir(a),this.files.set(a,new Uint8Array)}return this.openDescriptor({kind:"file",path:a,position:o&en?((l=this.files.get(a))==null?void 0:l.byteLength)??0:0,append:!!(o&en)},s)}pathRemoveDirectory(e,i,n){const r=this.readPath(e,i,n);if(!r)return ge;if(r==="/"||r==="/work")return ya;for(const o of this.dirs)if(o!==r&&ga(o)===r)return ya;for(const o of this.files.keys())if(ga(o)===r)return ya;return this.dirs.delete(r)?Q:mi}pathUnlinkFile(e,i,n){const r=this.readPath(e,i,n);return r?this.files.delete(r)?Q:mi:ge}pollOneoff(e){return this.view.setUint32(e,0,true),Q}randomGet(e,i){const n=this.bytes.subarray(e,e+i),r=globalThis.crypto;if(r!=null&&r.getRandomValues)r.getRandomValues(n);else for(let o=0;o<n.length;o+=1)n[o]=Math.floor(Math.random()*256);return Q}writeStringList(e,i,n){let r=n;for(let o=0;o<e.length;o+=1){const s=new TextEncoder().encode(e[o]);this.view.setUint32(i+o*4,r,true),this.bytes.set(s,r),this.bytes[r+s.byteLength]=0,r+=s.byteLength+1}return Q}iovs(e,i){const n=[];for(let r=0;r<i;r+=1){const o=e+r*8;n.push([this.view.getUint32(o,true),this.view.getUint32(o+4,true)])}return n}readPath(e,i,n){const r=this.fds.get(e);if(!r||r.kind!=="dir")return null;const o=new TextDecoder().decode(this.bytes.subarray(i,i+n));return Ko(r.path,o)}openDescriptor(e,i){const n=this.nextFd++;return this.fds.set(n,e),this.view.setUint32(i,n,true),Q}writeFilestat(e,i,n){this.bytes.fill(0,e,e+64),this.bytes[e+16]=i,this.view.setBigUint64(e+24,1n,true),this.view.setBigUint64(e+32,BigInt(n),true)}writeInitialFile(e,i){const n=qt(e);this.ensureParentDir(n);const r=new Uint8Array(i.byteLength);r.set(i),this.files.set(n,r)}ensureParentDir(e){const i=ga(e);i===e||this.dirs.has(i)||(this.ensureParentDir(i),this.dirs.add(i))}writeFileChunk(e,i){if(!i.byteLength)return;const n=this.files.get(e.path)??new Uint8Array,r=e.append?n.byteLength:e.position,o=Math.max(n.byteLength,r+i.byteLength);let s;if(o<=n.buffer.byteLength)s=new Uint8Array(n.buffer,0,o);else{const a=new Uint8Array(Math.max(o,n.buffer.byteLength*2));a.set(n),s=a.subarray(0,o)}s.set(i,r),this.files.set(e.path,s),e.position=r+i.byteLength}}function Ho(t){return t.reduce((e,i)=>e+new TextEncoder().encode(i).byteLength+1,0)}function Jo(t){switch(t.kind){case"dir":return wa;case"file":return Fa;default:return Un}}function Ko(t,e){return e.startsWith("/")?qt(e):qt(`${t}/${e}`)}function qt(t){const e=[];for(const i of t.replace(/\\/g,"/").split("/"))if(!(!i||i===".")){if(i===".."){e.pop();continue}e.push(i)}return`/${e.join("/")}`}function ga(t){const e=qt(t);if(e==="/")return"/";const i=e.lastIndexOf("/");return i<=0?"/":e.slice(0,i)}const Zo=[{sourceFormat:"dng",targetFormat:"jpg"},{sourceFormat:"cr2",targetFormat:"jpg"},{sourceFormat:"cr3",targetFormat:"jpg"},{sourceFormat:"nef",targetFormat:"jpg"},{sourceFormat:"nrw",targetFormat:"jpg"},{sourceFormat:"arw",targetFormat:"jpg"},{sourceFormat:"sr2",targetFormat:"jpg"},{sourceFormat:"srf",targetFormat:"jpg"},{sourceFormat:"orf",targetFormat:"jpg"},{sourceFormat:"rw2",targetFormat:"jpg"},{sourceFormat:"rwl",targetFormat:"jpg"},{sourceFormat:"raf",targetFormat:"jpg"},{sourceFormat:"kdc",targetFormat:"jpg"},{sourceFormat:"x3f",targetFormat:"jpg"},{sourceFormat:"pef",targetFormat:"jpg"},{sourceFormat:"srw",targetFormat:"jpg"},{sourceFormat:"erf",targetFormat:"jpg"},{sourceFormat:"mef",targetFormat:"jpg"},{sourceFormat:"mos",targetFormat:"jpg"},{sourceFormat:"mrw",targetFormat:"jpg"},{sourceFormat:"3fr",targetFormat:"jpg"},{sourceFormat:"iiq",targetFormat:"jpg"},{sourceFormat:"icns",targetFormat:"png"}],es=new Set(Tn.map(t=>dt(t.sourceFormat))),ts=new Set(Tn.map(t=>`${dt(t.sourceFormat)}->${dt(t.targetFormat)}`)),is=new Set(Zo.map(t=>`${dt(t.sourceFormat)}->${dt(t.targetFormat)}`));class Qi extends Error{constructor(e){super(e.errorMessage||e.errorCode||"WASM conversion failed."),this.result=e,this.name="WasmConversionError"}}function Hc(t){const e=wi(t),i=t.officeWasm?wi({wasm:t.officeWasm,fetch:t.fetch}):void 0,n=t.imageWasm?La(()=>Ln(t.imageWasm,t.fetch)):void 0,r=t.imageWasm?wi({wasm:n,fetch:t.fetch}):void 0,o=n?as(n):void 0;return{async convert(s,a){Se(a.signal);const c=dt(s.sourceFormat),l=dt(s.targetFormat),u=rs(c,l),f=`/work/input.${c}`,y=`/work/output.${l}`,p="/work/options.json",h="/work/result.json",d=await An(s.source,t.fetch,a.signal);Se(a.signal);const m=JSON.stringify({...s.password?{password:s.password}:{},...s.locale?{locale:s.locale}:{}}),g=!!(r&&is.has(u));if(g&&l==="jpg"&&o){const D=await o(d,a.signal);if(Se(a.signal),D)return D}const b=g?r:e,x=(D,F)=>D({args:[g?"converter-image":"converter-core","--input",f,"--output",y,"--source",c,"--target",l,"--options",p,"--result",h],files:{[f]:F,[p]:new TextEncoder().encode(m)},readFiles:[h,y],signal:a.signal});let v=await x(b,d),w=$i(v.files[h]);if(!w.ok&&w.errorCode==="engine_unavailable"&&w.requiredModule==="office"&&i){const D=await x(i,d);tn($i(D.files[h]),D.exitCode),v=await x(e,D.files[y]),w=$i(v.files[h])}return Se(a.signal),tn(w,v.exitCode),{source:v.files[y],format:dt(w.targetFormat||l),contentType:w.contentType,warnings:w.warnings}}}}function tn(t,e){if(!t.ok)throw new Qi(t);if(e!==0)throw new Qi({...t,ok:false,errorCode:t.errorCode||"conversion_failed",errorMessage:t.errorMessage||`converter WASM exited with code ${e}`})}function as(t){const e=La(async()=>{const i=await t(),n=new Set(WebAssembly.Module.exports(i).map(s=>s.name));if(!["filens_image_alloc","filens_image_free","filens_image_preview","memory"].every(s=>n.has(s)))return null;const r=new Cn({args:["converter-image"],files:{}}),o=await WebAssembly.instantiate(i,{wasi_snapshot_preview1:r.imports});return r.setInstance(o),o.exports});return async(i,n)=>{const r=await ut(e(),n);if(Se(n),!r||i.length===0)return null;let o=0,s=0,a=0;try{if(o=r.filens_image_alloc(i.length)>>>0,!o)throw new Error("Image core could not allocate its input buffer.");new Uint8Array(r.memory.buffer).set(i,o);const c=r.filens_image_preview(o,i.length);if(s=Number(c&0xffffffffn),a=Number(c>>32n),!s||a<4||s+a>r.memory.buffer.byteLength)throw new Error("Image core returned an invalid preview buffer.");const l=new Uint8Array(r.memory.buffer,s,a),u=new DataView(l.buffer,l.byteOffset,4).getUint32(0,true);if(u>l.length-4)throw new Error("Image core returned invalid preview metadata.");const f=$i(l.subarray(4,4+u));if(!f.ok)throw new Qi(f);return{source:l.slice(4+u),format:"jpg",contentType:f.contentType,warnings:f.warnings}}finally{s&&a&&r.filens_image_free(s,a),o&&r.filens_image_free(o,i.length)}}}function rs(t,e){const i=`${t}->${e}`;if(ts.has(i))return i;const n=es.has(t)?`unsupported conversion pair: ${t} -> ${e}`:`unsupported source format: ${t}`;throw new Qi({ok:false,sourceFormat:t,targetFormat:e,warnings:[],errorCode:"unsupported_format",errorMessage:n,metrics:{}})}function $i(t){const e=new TextDecoder().decode(t),i=JSON.parse(e);return{...i,warnings:Array.isArray(i.warnings)?i.warnings.map(String):[]}}function dt(t){return t.trim().replace(/^\./,"").toLowerCase()}const an=64*1024*1024;function Jc(){return{async convert(t,e){const i=t.sourceFormat.replace(/^\./,"").toLowerCase(),n=t.targetFormat.replace(/^\./,"").toLowerCase();if(!(["heic","heif"].includes(i)&&n==="png"))throw new Error(`Unsupported media conversion: ${i} -> ${n}.`);if(Se(e.signal),(t.source instanceof Blob?t.source.size:typeof t.source=="string"?0:t.source.byteLength)>an)throw new Error("HEIF input exceeds the 64 MiB preview limit.");const r=ArrayBuffer.isView(t.source)?t.source.slice():t.source instanceof ArrayBuffer?t.source.slice(0):t.source,o=await An(r,globalThis.fetch,e.signal,an);Se(e.signal);const s=await ut(import("./media-runtime-B6322raw.js"),e.signal);return Se(e.signal),s.convertMedia(o,i,e.signal)}}}function H(t){if(t!=null&&t.aborted)throw new DOMException("Panorama preview was aborted.","AbortError")}function le(t,e,i){return new Promise((n,r)=>{const o=()=>r(new DOMException("Panorama preview was aborted.","AbortError"));e.aborted?o():e.addEventListener("abort",o,{once:true}),t.then(s=>{e.removeEventListener("abort",o),e.aborted?i==null||i(s):n(s)},s=>{e.removeEventListener("abort",o),e.aborted||r(s)})})}function ns(t,e){const i=n=>(H(e),le(n(),e));return{open:(n,r)=>i(()=>t.open(n,{...r,signal:e})),...t.decodeImage?{decodeImage:()=>i(()=>t.decodeImage(e))}:{},readSample:(n,r,o)=>i(()=>t.readSample(n,r,o??e)),readImuWindow:(n,r,o)=>i(()=>t.readImuWindow(n,r,o??e)),computeSeam:(n,r)=>i(()=>t.computeSeam(n,r??e)),seek:n=>(H(e),t.seek(n)),getManifest:()=>(H(e),t.getManifest()),close:()=>{e.aborted||t.close()},abort:()=>{e.aborted||t.abort()}}}const rn=8,Mi=64<<20,os=128<<20,nn=120,ss=8<<20;class B extends Error{constructor(e,i){super(i),this.code=e,this.name="PanoramaProcessorError"}}function cs(t){const e=t.fetch??globalThis.fetch,i=wi({wasm:t.wasm,fetch:e}),n=t.imageWasm?wi({wasm:t.imageWasm,fetch:e}):void 0,r=l=>{const u=new AbortController,f=pi(u.signal,l);return{controller:u,...f,companionTrackIds:new Map}};let o=r();const s=l=>{const{reader:u,companionProcessor:f}=l;l.reader=void 0,l.manifest=void 0,l.companionProcessor=void 0,l.companionTrackIds.clear(),l.controller.abort(),l.release(),u==null||u.close(),f==null||f.close()},a=()=>{const l=o;o=r(),s(l)},c=async(l,u,f,y)=>{var x;ie(y);const p=l.companionTrackIds.get(u);if(p!==void 0&&l.companionProcessor){const v=await l.companionProcessor.readSample(p,f,y);return ie(y),{...v,trackId:u}}const{reader:h,manifest:d}=l;if(!h||!d)throw new B("invalid_manifest","Open a panorama source before reading samples.");const m=d.tracks.find(v=>v.id===u)??(((x=d.metadataTrack)==null?void 0:x.id)===u?d.metadataTrack:void 0),g=m==null?void 0:m.samples[f];if(!m||!g)throw new RangeError(`Unknown panorama sample ${u}:${f}.`);const b=await h.read(g.offset,g.size,y);return{...g,trackId:u,timescale:m.timescale,data:b}};return{async open(l,u){var h;const f=r(u.signal),y=o;o=f,s(y);const p=f.signal;try{ie(p);const d=await le(wt.open(l,e,p),p,k=>k.close());ie(p),f.reader=d;let m;const g=new Map,b=u.format==="insp"?1<<20:65536,x=u.format==="insp"?65536:1<<20,v=[{offset:0,length:Math.min(b,d.size)},{offset:Math.max(0,d.size-x),length:Math.min(x,d.size)}];await sn(d,g,v,p);let w;if(u.sidecar){const k=await wt.open(u.sidecar,e,p);try{if(k.size>8<<20)throw new B("resource_limit","Panorama sidecar exceeds 8 MiB.");w=await k.read(0,k.size,p)}finally{k.close()}}for(let k=0;k<rn;k+=1){ie(p);const D=[...g.values()].map((A,C)=>({offset:A.offset,path:`/work/range-${C}.bin`})),F={"/work/options.json":new TextEncoder().encode(JSON.stringify({logicalSize:d.size,ranges:D,...w?{sidecarPath:"/work/sidecar.pb"}:{}}))};w&&(F["/work/sidecar.pb"]=w),[...g.values()].forEach((A,C)=>{F[`/work/range-${C}.bin`]=A.bytes});const S="/work/result.json",R=await i({args:["converter-core","--operation","inspect-panorama","--source",u.format,"--options","/work/options.json","--result",S],files:F,readFiles:[S],signal:p});ie(p);const _=R.files[S];if(!_)throw new B("invalid_manifest","Panorama inspector did not return a result.");const T=JSON.parse(new TextDecoder().decode(_));if(T.ok&&T.payload){if(m=us(T.payload),u.companion){f.companionProcessor=cs(t);const A=await f.companionProcessor.open(u.companion,{format:u.format,sidecar:u.sidecar,signal:p});ie(p);const C=new Set(m.tracks.map(J=>J.id)),j=new Map,G=A.tracks.map(J=>{let Z=J.id;for(;C.has(Z);)Z+=1e6;return C.add(Z),f.companionTrackIds.set(Z,J.id),j.set(J.id,Z),{...J,id:Z}}),q=A.lenses.map(J=>({...J,sourceTrackId:J.sourceTrackId===void 0?void 0:j.get(J.sourceTrackId)})),te=[...m.tracks,...G],ne=hs(fs(m.lenses,q),te),ue=[...m.warnings,...A.warnings];m={...m,cameraModel:m.cameraModel||A.cameraModel,firmware:m.firmware||A.firmware,textureOrigin:m.textureOrigin||A.textureOrigin,projection:m.projection.kind==="unknown"?A.projection:m.projection,calibrationSource:m.calibrationSource==="unavailable"?A.calibrationSource:m.calibrationSource,confidence:m.confidence==="low"?A.confidence:m.confidence,tracks:te,lenses:ne,warnings:ne.length>=2?ue.filter(J=>!J.includes("matching companion file")&&!J.startsWith("INSV calibration was not found")):ue}}return f.manifest=m,m}if(T.errorCode!=="need_ranges"||!((h=T.requiredRanges)!=null&&h.length))throw va(T.errorCode,T.errorMessage);await sn(d,g,T.requiredRanges,p)}throw new B("resource_limit",`Panorama inspection exceeded ${rn} range iterations.`)}catch(d){throw o===f&&(o=r()),s(f),d}},async decodeImage(l){var p;const u=o,f=pi(u.signal,l),y=f.signal;try{ie(y);const h=u.reader,d=u.manifest;if(!h||(d==null?void 0:d.format)!=="dng")throw new B("invalid_manifest","Open a DNG before developing its RAW preview.");if(!n)throw new B("codec_unsupported","Calibrated DNG preview requires converter-image.wasm (imageWasm).");if(h.size>256*1024*1024)throw new B("resource_limit","RAW preview input exceeds 256 MiB.");const m=new Uint8Array(h.size);for(let w=0;w<m.length;w+=Mi){const k=Math.min(Mi,m.length-w),D=await h.read(w,k,y);if(ie(y),D.length!==k)throw new B("range_unavailable","DNG source returned an incomplete byte range.");m.set(D,w)}const g="/work/result.json",b="/work/preview.jpg",x=await n({args:["converter-image","--source","dng","--target","jpg","--input","/work/input.dng","--output",b,"--options","/work/options.json","--result",g],files:{"/work/input.dng":m,"/work/options.json":new TextEncoder().encode(JSON.stringify({preserveSensorGeometry:true}))},readFiles:[g,b],signal:y});ie(y);const v=JSON.parse(new TextDecoder().decode(x.files[g]??new Uint8Array));if(!v.ok||x.exitCode!==0||!((p=x.files[b])!=null&&p.length))throw new B("codec_unsupported",v.errorMessage||"WASM could not develop the DNG sensor preview.");return x.files[b]}finally{f.release()}},async readSample(l,u,f){const y=o,p=pi(y.signal,f);try{return await c(y,l,u,p.signal)}finally{p.release()}},async readImuWindow(l,u,f){var h;const y=o,p=pi(y.signal,f);try{ie(p.signal);const d=y.manifest;if(!(d!=null&&d.metadataTrack))return[];if(!Number.isSafeInteger(l)||!Number.isSafeInteger(u)||l<0||u<0||u>nn)throw new B("resource_limit",`Panorama metadata windows are limited to ${nn} samples.`);const m=d.metadataTrack,g=m.samples.slice(l,l+u);if(g.reduce((S,R)=>S+R.size,0)>ss)throw new B("resource_limit","Panorama metadata window exceeds 8 MiB.");const x={},v=[];for(let S=0;S<g.length;S+=1){const R=await c(y,m.id,l+S,p.signal),_=`/work/metadata-${S}.bin`;x[_]=R.data,v.push({path:_,pts:R.pts,timescale:R.timescale})}const w="/work/result.json";ie(p.signal),x["/work/options.json"]=new TextEncoder().encode(JSON.stringify({vendor:d.vendor,samples:v}));const k=await i({args:["converter-core","--operation","decode-panorama-metadata","--options","/work/options.json","--result",w],files:x,readFiles:[w],signal:p.signal});ie(p.signal);const D=k.files[w];if(!D)throw new B("invalid_manifest","Panorama metadata decoder did not return a result.");const F=JSON.parse(new TextDecoder().decode(D));if(!F.ok||!Array.isArray((h=F.payload)==null?void 0:h.samples))throw va(F.errorCode,F.errorMessage);return F.payload.samples}finally{p.release()}},seek(l){const u=o.manifest;return u?Object.fromEntries(u.tracks.map(f=>[f.id,ds(f,l)])):{}},async computeSeam(l,u){const f=pi(o.signal,u);try{ie(f.signal);const y="/work/result.json",p=await i({args:["converter-core","--operation","panorama-seam","--options","/work/options.json","--result",y],files:{"/work/options.json":new TextEncoder().encode(JSON.stringify({width:l.width,height:l.height,costs:Array.from(l.costs),previous:l.previous?Array.from(l.previous):[],temporalWeight:l.temporalWeight??2,maxStep:l.maxStep??1}))},readFiles:[y],signal:f.signal});ie(f.signal);const h=p.files[y];if(!h)throw new B("invalid_manifest","Panorama seam solver did not return a result.");const d=JSON.parse(new TextDecoder().decode(h));if(!d.ok||!d.payload)throw va(d.errorCode,d.errorMessage);const m=d.payload;if(!Array.isArray(m.seam)||!Number.isFinite(m.cost))throw new B("invalid_manifest","Panorama seam solver returned an invalid path.");return m}finally{f.release()}},close:a,abort:()=>o.controller.abort(),getManifest:()=>o.manifest}}function En(t){return{codec:ms(t),codedWidth:t.width,codedHeight:t.height,description:In(t.decoderConfig),optimizeForLatency:true}}function ls(t){return new EncodedVideoChunk({type:t.key?"key":"delta",timestamp:Math.round(t.pts*1e6/t.timescale),duration:Math.round(t.duration*1e6/t.timescale),data:t.data})}function us(t){var r;if(!t||!Array.isArray(t.tracks)||!Array.isArray(t.lenses))throw new B("invalid_manifest","Panorama inspector returned an invalid manifest.");const e=(r=t.lenses[0])==null?void 0:r.projection,i=typeof t.projection=="string"?e&&typeof e=="object"?e:{kind:t.projection}:{kind:"unknown"},n=t.lenses.map(o=>({...o,projection:o.projection&&typeof o.projection=="object"?o.projection:i}));return{...t,projection:i,lenses:n}}function ds(t,e){const i=Math.max(0,e)*t.timescale;let n=0;for(let r=0;r<t.samples.length;r+=1){const o=t.samples[r];if(o.pts>i)break;o.key&&(n=r)}return n}function fs(t,e){const i=t.slice(0,2),n=new Set(i.map(on));for(const r of e){if(i.length===2)break;const o=on(r);n.has(o)||(i.push(r),n.add(o))}return i}function hs(t,e){return e.length<t.length?t:t.map((i,n)=>i.sourceTrackId===void 0?{...i,sourceTrackId:e[n].id}:i)}function on(t){const e={...t};return delete e.sourceTrackId,delete e.sourceRect,JSON.stringify(e)}function ms(t){const e=In(t.decoderConfig);if((t.codec==="avc1"||t.codec==="avc3")&&e.length>=4)return`${t.codec}.${[...e.slice(1,4)].map(i=>i.toString(16).padStart(2,"0")).join("")}`;if((t.codec==="hvc1"||t.codec==="hev1")&&e.length>=13){const i=["","A","B","C"][e[1]>>6],n=e[1]&32?"H":"L",r=e[1]&31;let o=new DataView(e.buffer,e.byteOffset+2,4).getUint32(0),s=0;for(let u=0;u<32;u+=1)s=s<<1|o&1,o>>>=1;const a=(s>>>0).toString(16),c=[...e.slice(6,12)];for(;c.at(-1)===0;)c.pop();const l=c.length?`.${c.map(u=>u.toString(16)).join(".")}`:"";return`${t.codec}.${i}${r}.${a}.${n}${e[12]}${l}`}return t.codec}function In(t){return t?Uint8Array.from(t.match(/.{1,2}/g)??[],e=>Number.parseInt(e,16)):new Uint8Array}async function sn(t,e,i,n){for(const r of i){const o=r.offset+r.length;if(!Number.isSafeInteger(r.offset)||!Number.isSafeInteger(r.length)||!Number.isSafeInteger(o)||r.offset<0||r.length<=0||r.length>Mi||o>t.size)throw new B("resource_limit","Panorama inspector requested an invalid source range.");const s=[...e.values()].sort((u,f)=>u.offset-f.offset),a=[];let c=r.offset;for(const u of s)if(u.offset>c&&a.push({offset:c,length:Math.min(u.offset,o)-c}),c=Math.max(c,u.offset+u.bytes.length),c>=o)break;if(c<o&&a.push({offset:c,length:o-c}),s.reduce((u,f)=>u+f.bytes.length,0)+a.reduce((u,f)=>u+f.length,0)>os)throw new B("resource_limit","Panorama inspection exceeded its 128 MiB range budget.");for(const u of a){const f=await t.read(u.offset,u.length,n);e.set(`${u.offset}:${u.length}`,{offset:u.offset,bytes:f})}}}class wt{constructor(e,i,n){this.size=e,this.readRange=i,this.cleanup=n}static async open(e,i,n){if(ie(n),e instanceof Blob)return new wt(e.size,async(u,f)=>new Uint8Array(await e.slice(u,u+f).arrayBuffer()));if(e instanceof ArrayBuffer||ArrayBuffer.isView(e)){const u=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);return new wt(u.byteLength,async(f,y)=>u.slice(f,f+y))}if(!i)throw new B("range_unavailable","A fetch implementation is required for remote panorama sources.");const r=String(e),o=await yi(i(r,{headers:{Range:"bytes=0-0"},signal:n}),n,gi);ie(n);const s=o.headers.get("content-range");if(o.status===206){const u=s==null?void 0:s.match(/^bytes 0-0\/(\d+)$/i),f=Number(u==null?void 0:u[1]);if(gi(o),!Number.isSafeInteger(f)||f<=0)throw new B("range_unavailable","Remote panorama size is unavailable.");return new wt(f,async(y,p,h)=>{var m;const d=await yi(i(r,{headers:{Range:`bytes=${y}-${y+p-1}`},signal:h}),h,gi);if(ie(h),d.status!==206||((m=d.headers.get("content-range"))==null?void 0:m.toLowerCase())!==`bytes ${y}-${y+p-1}/${f}`)throw gi(d),new B("range_unavailable","Remote server returned an inconsistent panorama byte range.");return new Uint8Array(await yi(d.arrayBuffer(),h))})}const a=Number(o.headers.get("content-length"));if(!o.ok||!Number.isSafeInteger(a)||a<=0||a>Mi)throw gi(o),new B("range_unavailable","Remote server must support HTTP byte ranges for large panorama files.");const c=new Uint8Array(await yi(o.arrayBuffer(),n));ie(n);const l=o.headers.get("content-encoding");if(!c.length||c.length>Mi||(!l||l.toLowerCase()==="identity")&&c.length!==a)throw new B("range_unavailable","Remote panorama body does not match its declared length or size limit.");return new wt(c.byteLength,async(u,f)=>c.slice(u,u+f))}async read(e,i,n){if(ie(n),!Number.isSafeInteger(e)||!Number.isSafeInteger(i)||e<0||i<0||i>this.size-e)throw new B("range_unavailable","Panorama source range is out of bounds.");if(!i)return new Uint8Array;const r=await yi(this.readRange(e,i,n),n);if(ie(n),r.length!==i)throw new B("range_unavailable","Panorama source returned an incomplete byte range.");return r}close(){var e;(e=this.cleanup)==null||e.call(this)}}function va(t,e){const i={range_unavailable:"range_unavailable",resource_limit:"resource_limit",sidecar_missing:"sidecar_missing",firmware_unknown:"firmware_unknown",invalid_panorama_options:"invalid_manifest",invalid_panorama_metadata:"invalid_manifest",unsupported_container:"invalid_manifest",unsupported_projection:"calibration_missing"};return new B(i[t??""]??"calibration_missing",e||t||"Panorama inspection failed.")}function pi(t,...e){const i=[...new Set([t,...e.filter(s=>!!s)])],n=[],r=()=>{n.splice(0).forEach(s=>s())};if(i.length===1)return{signal:i[0],release:r};if(typeof AbortSignal.any=="function")return{signal:AbortSignal.any(i),release:r};const o=new AbortController;for(const s of i){const a=()=>{o.abort(s.reason),r()};if(s.aborted){a();break}s.addEventListener("abort",a,{once:true}),n.push(()=>s.removeEventListener("abort",a))}return{signal:o.signal,release:r}}function yi(t,e,i){return e?le(t,e,i):t}function gi(t){var e;try{(e=t.body)==null||e.cancel().catch(()=>{})}catch{}}function ie(t){if(t!=null&&t.aborted)throw t.reason instanceof Error?t.reason:new DOMException("The panorama operation was aborted.","AbortError")}async function ps(t,e,i){var y,p,h,d;if(e.projection.kind!=="mei-extended"||!ta(e))throw new B("calibration_missing","This INSP does not contain two supported calibrated panorama lenses.");const n=e.width??Number(((y=i.image)==null?void 0:y.naturalWidth)??((p=i.image)==null?void 0:p.width)),r=e.height??Number(((h=i.image)==null?void 0:h.naturalHeight)??((d=i.image)==null?void 0:d.height));if(!(n>0)||!(r>0))throw new B("invalid_manifest","The calibrated INSP image dimensions are unavailable.");const o={id:0,codec:"jpeg",decoderConfig:"",width:n,height:r,timescale:1,samples:[]},s=e.lenses.slice(0,2).map(m=>({track:o,rect:m.sourceRect??{x:0,y:0,width:1,height:1}}));if(!s.every(m=>zn(m.rect)))throw new B("invalid_manifest","The calibrated INSP lenses are not bound to valid image regions.");i.flipY=Ua(e.textureOrigin),i.colorSpace=Ki,i.minFilter=Mt,i.generateMipmaps=false,i.needsUpdate=true;const a=new Ta(new Uint8Array(128*64).fill(128),128,64,Ra,Pa);a.needsUpdate=true,a.minFilter=Mt;const c=ys(e,s,i,a);Ca(c,e.lenses);const l=new Zi(500,96,64);l.scale(-1,1,1);const u=new ea(l,c),f=new jn(t,e,s,c,a);return await f.acceptImage(i.image),{mesh:u,update:()=>{},play:()=>{},pause:()=>{},seek:()=>{},close:()=>{f.close(),a.dispose(),l.dispose(),c.dispose()},duration:0,currentTime:0,paused:true,streamSyncMs:0,get dynamicSeam(){return f.active},stabilizationAvailable:false,stabilizationMode:"off",error:void 0,setStabilization:()=>"off"}}function ys(t,e,i,n){const r=t.lenses.slice(0,2);return new Aa({uniforms:{lens0:{value:i},lens1:{value:i},intrinsics0:{value:Yt(r[0])},intrinsics1:{value:Yt(r[1])},size0:{value:$t(r[0],e[0])},size1:{value:$t(r[1],e[1])},sourceRect0:{value:Xt(e[0],t.textureOrigin)},sourceRect1:{value:Xt(e[1],t.textureOrigin)},distortion0:{value:Ze(r[0])},distortion1:{value:Ze(r[1])},quaternion0:{value:ft(r[0])},quaternion1:{value:ft(r[1])},radialScale0:{value:St(r[0])},radialScale1:{value:St(r[1])},projectionKind:{value:1},xi0:{value:r[0].xi||0},xi1:{value:r[1].xi||0},tangential0:{value:ve(r[0].tangential)},tangential1:{value:ve(r[1].tangential)},thinPrism0:{value:Dt(r[0].thinPrism)},thinPrism1:{value:Dt(r[1].thinPrism)},sensorTilt0:{value:ve(r[0].sensorTilt)},sensorTilt1:{value:ve(r[1].sensorTilt)},seamMask:{value:n},useDynamicSeam:{value:0},exposureGain0:{value:[1,1,1]},exposureGain1:{value:[1,1,1]},stabilizationQuaternion:{value:[1,0,0,0]}},vertexShader:`
|
|
2
2
|
varying vec2 panoramaUv;
|
|
3
3
|
void main() {
|
|
4
4
|
panoramaUv = uv;
|