webwallgl 1.3.5 → 1.3.16
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.en.md +33 -5
- package/README.md +33 -5
- package/package.json +1 -1
- package/types.d.ts +91 -3
- package/webwallgl.d.ts +43 -2
- package/webwallgl.global.js +34935 -10132
- package/webwallgl.global.js.map +1 -1
- package/webwallgl.global.min.js +544 -195
- package/webwallgl.global.min.js.map +1 -1
- package/webwallgl.min.mjs +544 -195
- package/webwallgl.min.mjs.map +1 -1
- package/webwallgl.mjs +35004 -10201
- package/webwallgl.mjs.map +1 -1
package/webwallgl.global.min.js
CHANGED
|
@@ -1,26 +1,309 @@
|
|
|
1
|
-
(function(Je,Wt){typeof exports=="object"&&typeof module<"u"?Wt(exports):typeof define=="function"&&define.amd?define(["exports"],Wt):(Je=typeof globalThis<"u"?globalThis:Je||self,Wt(Je.WebWallGL={}))})(this,function(Je){"use strict";function Wt(e,n){const t=n?.renderDpr??e.cfg?.renderDpr??1;return Math.min(window.devicePixelRatio||1,t)}function dn(e){return e==="fit"?"contain":e==="fill"?"cover":e==="contain"||e==="stretch"?e:"cover"}function Mo(e){const n=dn(e);return n==="contain"?{objectFit:"contain",background:"rgba(10,12,16,0.85)"}:n==="stretch"?{objectFit:"fill",background:"transparent"}:{objectFit:"cover",background:"transparent"}}function Ts(e){return{cfg:{type:"canvas"},coverAlign:{x:.5,y:.5,tx:.5,ty:.5},frameMeter:{stamps:[],last:0,fps:0},disposers:[]}}(()=>{const e=n=>n.preventDefault();window.addEventListener("contextmenu",e,!0),document.addEventListener("contextmenu",e,!0),window.__blockContextMenu=n=>n.addEventListener("contextmenu",e,!0)})();function rn(e){if(e.iframe)try{e.iframe.contentWindow?.location.replace("about:blank")}catch{}if(e.wrap)e.wrap.innerHTML="";else if(e.iframe?.isConnected)try{e.iframe.remove()}catch{}e.raf!==void 0&&cancelAnimationFrame(e.raf),e.raf=void 0;for(const t of e.videoPairs??[])t.destroy();if(e.videoPairs=void 0,e.sceneCleanup)try{e.sceneCleanup()}catch{}e.sceneCleanup=void 0,e.sceneCtl=void 0,e.pointerCtl=void 0,e.mediaCtl=void 0;const n=e.wallpaperDisposers??[];e.wallpaperDisposers=[];for(const t of n)try{t()}catch{}e.renderer&&(e.renderer.dispose?.(),e.renderer=void 0);for(const t of e.videoTextures??[])t.pause(),t.removeAttribute("src"),t.load(),t.remove();e.videoTextures=void 0;for(const t of e.objectUrls??[])try{URL.revokeObjectURL(t)}catch{}if(e.objectUrls=void 0,e.sceneAudio){for(const t of e.sceneAudio.audios)t.pause(),t.removeAttribute("src"),t.load();e.sceneAudio=void 0}if(e.video){e.video.pause(),e.video.removeAttribute("src");try{e.video.load()}catch{}e.video.remove()}e.video=void 0,e.img=void 0,e.iframe=void 0,e.canvas=void 0,e.ctx=void 0,e.info=void 0,Rs(),Ao(e)}function Ss(e){try{rn(e)}catch{}e.peekRaf!==void 0&&(cancelAnimationFrame(e.peekRaf),e.peekRaf=void 0);for(const n of e.disposers.splice(0))try{n()}catch{}e.wrap?.remove(),e.wrap=void 0}const Es=new TextDecoder,pt=e=>Es.decode(e).replace(/^\uFEFF/,""),_o=500;function An(e,n){const t=e.frameMeter.stamps;t.push(n),e.frameMeter.last=n;const r=n-_o;for(;t.length&&t[0]<r;)t.shift();const o=t.length>=2?t[t.length-1]-t[0]:0;e.frameMeter.fps=o>0?(t.length-1)*1e3/o:0}function Ao(e){e.frameMeter.stamps.length=0,e.frameMeter.last=0,e.frameMeter.fps=0}function Ps(e){return!e.frameMeter.last||e.paused?{fps:0,running:!1}:performance.now()-e.frameMeter.last>Math.max(_o,400)?{fps:0,running:!1}:{fps:e.frameMeter.fps,running:!0}}function se(e,n,t){try{e.onDiagnostic?.(t,/fail|error|失败|ERROR/.test(t)?"error":"info")}catch{}try{const r=n.mediaBase?new URL(n.mediaBase,window.location.href).origin:"";if(r){const o=new Image;o.src=`${r}/diag?msg=${encodeURIComponent(`scene ${n.src??"?"}: ${t.slice(0,500)}`)}`}}catch{}}function Pr(e){e.coverAlign.x=e.coverAlign.y=e.coverAlign.tx=e.coverAlign.ty=.5,Cs(e)}function Cs(e){const n=`${(e.coverAlign.x*100).toFixed(2)}% ${(e.coverAlign.y*100).toFixed(2)}%`,t=e.video??e.img;t&&t.isConnected&&(t.style.objectPosition=n)}const Ls=["__scene","__sceneLayers","__textures","__objScripts","__textWidgets","__mediaHooks","__mediaControl","__mediaStats","__mediaSet","__system","__liveSystem","__audioStats","__audioMute","__particleStats","__particleToggle","__pointerStats","__compositeStats","__compositeEnable"];function Rs(){const e=window;for(const n of Ls)n in e&&delete e[n]}function To(e,n,t){const r=Wt(e,t),o=Math.max(1,Math.round((n.clientWidth||window.innerWidth||1)*r)),i=Math.max(1,Math.round((n.clientHeight||window.innerHeight||1)*r));return n.width===o&&n.height===i?!1:(n.width=o,n.height=i,!0)}function ks(e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.length<16)throw new Error("\u6587\u4EF6\u592A\u5C0F\uFF0C\u4E0D\u662F scene.pkg");const t=n.getUint32(0,!0);if(t<4||t>16)throw new Error("\u9B54\u6570\u957F\u5EA6\u5F02\u5E38: "+t);const r=So(e,4,t);if(!r.startsWith("PKGV"))throw new Error("\u4E0D\u662F scene.pkg\uFF0C\u9B54\u6570: "+r);const o=n.getUint32(4+t,!0);let i=4+t+4;const s=[];for(let c=0;c<o;c++){if(i+8>e.length)throw new Error("\u5165\u53E3\u8868\u8D8A\u754C @"+c);const u=n.getUint32(i,!0);if(i+=4,i+u+8>e.length)throw new Error("\u5165\u53E3 "+c+" \u8D8A\u754C");const l=Ns(e,i,u);i+=u;const f=n.getUint32(i,!0);i+=4;const p=n.getUint32(i,!0);i+=4,s.push({name:l,offset:f,size:p})}const a=i;return{magic:r,version:r.slice(4),count:o,entries:s,dataStart:a,fileSize:e.length,buf:e}}function Cr(e,n){const t=e.entries.find(i=>i.name===n);if(t===void 0)return null;const r=e.dataStart+t.offset,o=r+t.size;if(r<0||o>e.fileSize)throw new Error("\u5165\u53E3 "+n+" \u8D8A\u754C");return e.buf.subarray(r,o)}function Fs(e){let n=0;for(const t of e.entries)n=Math.max(n,t.offset+t.size);return{dataEnd:e.dataStart+n,fileSize:e.fileSize,ok:e.dataStart+n<=e.fileSize}}function So(e,n,t){let r="";for(let o=n;o<n+t;o++)r+=String.fromCharCode(e[o]);return r}function Ns(e,n,t){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e.subarray(n,n+t))}catch{return So(e,n,t)}}const Us=Object.freeze(Object.defineProperty({__proto__:null,getEntry:Cr,parsePkg:ks,verifyLayout:Fs},Symbol.toStringTag,{value:"Module"})),Lr={0:"ARGB8888",1:"RGB888",2:"RGB565",4:"DXT5",6:"DXT3",7:"DXT1",8:"RG88",9:"R8",10:"RG1616f",11:"R16f",12:"BC7",13:"RGBa1010102",14:"RGBA16161616f",15:"RGB161616f"},Vt={UNKNOWN:-1,JPEG:2,PNG:13,GIF:25,WEBP:35,MP4:35};function Ds(e){const n=e.images[0];if(!n||n.length===0)throw new Error("\u65E0\u56FE\u50CF\u6570\u636E");const t=n[0];if(e.isVideo)return{width:t.width,height:t.height,video:t.data};if(e.freeImageFormat===Vt.PNG)return{width:t.width,height:t.height,png:t.data};if(e.freeImageFormat!==Vt.UNKNOWN)return{width:t.width,height:t.height,image:t.data,fif:e.freeImageFormat};const r=Rr(e.format,t.data,t.width,t.height);return!e.frames?.list?.length&&(t.width!==e.width||t.height!==e.height)?{width:e.width,height:e.height,rgba:Eo(r,t.width,t.height,e.width,e.height)}:{width:t.width,height:t.height,rgba:r}}function Bs(e){const n=e.images[0];if(!n||n.length===0)throw new Error("\u65E0\u56FE\u50CF\u6570\u636E");const t=[];for(const r of n){if(e.freeImageFormat!==Vt.UNKNOWN){t.push({width:r.width,height:r.height,image:r.data,fif:e.freeImageFormat});continue}const o=Rr(e.format,r.data,r.width,r.height);t.push({width:r.width,height:r.height,rgba:o})}return!e.frames?.list?.length&&t.length>0&&(t[0].width!==e.width||t[0].height!==e.height)&&t[0].rgba&&(t[0]={width:e.width,height:e.height,rgba:Eo(t[0].rgba,t[0].width,t[0].height,e.width,e.height)}),t}function Eo(e,n,t,r,o){const i=new Uint8Array(r*o*4);for(let s=0;s<o;s++)i.set(e.subarray(s*n*4,s*n*4+r*4),s*r*4);return i}function Rr(e,n,t,r){switch(e){case 0:return Is(n,t,r);case 1:return Os(n,t,r);case 2:return $s(n,t,r);case 4:return Hs(n,t,r);case 6:return Vs(n,t,r);case 7:return Ws(n,t,r);case 8:return js(n,t,r);case 9:return zs(n,t,r);case 12:throw new Error("BC7 \u89E3\u7801\u6682\u672A\u5B9E\u73B0\uFF08format=12\uFF09");default:throw new Error("\u672A\u652F\u6301\u7684\u7EB9\u7406\u683C\u5F0F: "+(Lr[e]||e))}}function Is(e,n,t){return new Uint8Array(e.buffer,e.byteOffset,n*t*4).slice()}function Os(e,n,t){const r=new Uint8Array(n*t*4);for(let o=0;o<n*t;o++)r[o*4]=e[o*3],r[o*4+1]=e[o*3+1],r[o*4+2]=e[o*3+2],r[o*4+3]=255;return r}function $s(e,n,t){const r=new Uint8Array(n*t*4);for(let o=0;o<n*t;o++){const i=e[o*2]|e[o*2+1]<<8,s=i>>11&31,a=i>>5&63,c=i&31;r[o*4]=s<<3|s>>2,r[o*4+1]=a<<2|a>>4,r[o*4+2]=c<<3|c>>2,r[o*4+3]=255}return r}function js(e,n,t){const r=new Uint8Array(n*t*4);for(let o=0;o<n*t;o++)r[o*4]=e[o*2+1],r[o*4+1]=e[o*2+1],r[o*4+2]=e[o*2+1],r[o*4+3]=e[o*2];return r}function zs(e,n,t){const r=new Uint8Array(n*t*4);for(let o=0;o<n*t;o++)r[o*4]=e[o],r[o*4+1]=e[o],r[o*4+2]=e[o],r[o*4+3]=255;return r}function Ws(e,n,t){return kr(e,n,t,!0,0)}function Vs(e,n,t){return kr(e,n,t,!1,3)}function Hs(e,n,t){return kr(e,n,t,!1,5)}function kr(e,n,t,r,o){const i=new Uint8Array(n*t*4),s=r?8:16,a=new Uint8Array(16);let c=0;for(let u=0;u<t;u+=4)for(let l=0;l<n;l+=4){if(c+s>e.length)return i;a.set(e.subarray(c,c+s)),c+=s;const f=Xs(a,r),p=Gs(a,r),d=o===3?Ys(a):o===5?qs(a):null;for(let y=0;y<4;y++)for(let x=0;x<4;x++){const m=l+x,M=u+y;if(m>=n||M>=t)continue;const h=y*4+x,g=(M*n+m)*4;i[g]=f[p[h]*4],i[g+1]=f[p[h]*4+1],i[g+2]=f[p[h]*4+2],i[g+3]=d!==null?d[h]:f[p[h]*4+3]}}return i}function Po(e,n){const t=e[n]|e[n+1]<<8,r=t>>11&31,o=t>>5&63,i=t&31;return[t,r<<3|r>>2,o<<2|o>>4,i<<3|i>>2]}function Xs(e,n){const t=n?0:8,r=Po(e,t),o=Po(e,t+2),i=new Uint8Array(16);return i[0]=r[1],i[1]=r[2],i[2]=r[3],i[3]=255,i[4]=o[1],i[5]=o[2],i[6]=o[3],i[7]=255,n&&r[0]<=o[0]?(i[8]=r[1]+o[1]>>1,i[9]=r[2]+o[2]>>1,i[10]=r[3]+o[3]>>1,i[11]=255,i[12]=0,i[13]=0,i[14]=0,i[15]=0):(i[8]=Math.floor((2*r[1]+o[1])/3),i[9]=Math.floor((2*r[2]+o[2])/3),i[10]=Math.floor((2*r[3]+o[3])/3),i[11]=255,i[12]=Math.floor((r[1]+2*o[1])/3),i[13]=Math.floor((r[2]+2*o[2])/3),i[14]=Math.floor((r[3]+2*o[3])/3),i[15]=255),i}function Gs(e,n){const t=n?4:12,r=new Uint8Array(16);for(let o=0;o<4;o++){const i=e[t+o];r[o*4]=i&3,r[o*4+1]=i>>2&3,r[o*4+2]=i>>4&3,r[o*4+3]=i>>6&3}return r}function Ys(e){const n=new Uint8Array(16);for(let t=0;t<8;t++){const r=e[t],o=r&15,i=r&240;n[2*t]=o|o<<4,n[2*t+1]=i|i>>4}return n}function qs(e){const n=e[0],t=e[1],r=new Uint8Array(8);if(r[0]=n,r[1]=t,n<=t){for(let a=1;a<5;a++)r[1+a]=Math.floor(((5-a)*n+a*t)/5);r[6]=0,r[7]=255}else for(let a=1;a<7;a++)r[a+1]=Math.floor(((7-a)*n+a*t)/7);const o=new Uint8Array(16);let i=0;for(let a=0;a<2;a++){let c=0;for(let u=0;u<3;u++)c|=e[2+a*3+u]<<8*u;for(let u=0;u<8;u++)o[i++]=c>>3*u&7}const s=new Uint8Array(16);for(let a=0;a<16;a++)s[a]=r[o[a]];return s}function Co(e,n){const t=new Uint8Array(n);let r=0,o=0;for(;r<e.length;){const i=e[r++];let s=i>>4;if(s===15){let l;do l=e[r++],s+=l;while(l===255)}for(let l=0;l<s;l++)t[o++]=e[r++];if(r>=e.length)break;const a=e[r]|e[r+1]<<8;r+=2;let c=4+(i&15);if((i&15)===15){let l;do l=e[r++],c+=l;while(l===255)}const u=o-a;for(let l=0;l<c;l++)t[o++]=t[u+l]}return t}function Fe(e,n){return(e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24)>>>0}function Lo(e,n){return Fe(e,n)|0}const Tn=new DataView(new ArrayBuffer(4));function Ht(e,n){return Tn.setUint8(0,e[n]),Tn.setUint8(1,e[n+1]),Tn.setUint8(2,e[n+2]),Tn.setUint8(3,e[n+3]),Tn.getFloat32(0,!0)}function Zs(e){let n=0;const t=er(e,n,9);if(n+=9,t!=="TEXV0005\0")throw new Error("\u4E0D\u662F .tex \u6587\u4EF6: "+t);const r=er(e,n,9);if(n+=9,r!=="TEXI0001\0")throw new Error("\u672A\u77E5 TEXI \u5B50\u5BB9\u5668: "+r);const o=Fe(e,n);n+=4;const i=Fe(e,n);n+=4;const s=Fe(e,n);n+=4;const a=Fe(e,n);n+=4;const c=Fe(e,n);n+=4;const u=Fe(e,n);n+=4,n+=4;const l=er(e,n,9);n+=9;const f=Fe(e,n);n+=4;let p=Vt.UNKNOWN,d=0;if(l==="TEXB0004\0"){p=Fe(e,n)|0,n+=4;const v=Fe(e,n);n+=4,p===Vt.UNKNOWN&&v===1&&(p=Vt.MP4),d=v===1?4:3}else if(l==="TEXB0003\0")p=Fe(e,n)|0,n+=4,d=3;else if(l==="TEXB0002\0")d=2;else if(l==="TEXB0001\0")d=1;else throw new Error("\u672A\u77E5 TEXB \u5BB9\u5668: "+l);const y=(i&32)!==0||p===Vt.MP4,x=[];for(let v=0;v<f;v++){const A=Fe(e,n);n+=4;const _=[];for(let R=0;R<A;R++){if(d===4){for(n+=8;n<e.length&&e[n]!==0;)n++;n+=1,n+=4}const L=Fe(e,n);n+=4;const N=Fe(e,n);n+=4;let j=0,H=0;d>=2&&(j=Fe(e,n),n+=4,H=Lo(e,n),n+=4);const K=Lo(e,n);if(n+=4,y){_.push({width:L,height:N,compression:0,data:e.subarray(n)}),n=e.length;continue}j===0&&(H=K);const O=e.subarray(n,n+K);n+=K;let V=O;j===1&&(V=Co(O,H)),_.push({width:L,height:N,compression:j,data:V})}x.push(_)}const m=x[0]&&x[0][0],M=m?m.width:s,h=m?m.height:a;let g=null;if(n+13<=e.length){const v=er(e,n,9);if(v.indexOf("TEXS")===0){let A=n+9;const _=Fe(e,A);A+=4;let R=0,L=0;v==="TEXS0003\0"&&(R=Fe(e,A),A+=4,L=Fe(e,A),A+=4);const N=e.length-A,j=_>0&&N>0&&N%_===0?N/_:0;if(_>0&&_<=4096&&j>=32){const H=[];for(let O=0;O<_;O++){const V=A+O*j;if(V+32>e.length)break;const X=Ht(e,V+8),ie=Ht(e,V+12),J=Ht(e,V+16),Z=Ht(e,V+20),te=Ht(e,V+24),le=Ht(e,V+28);H.push({imageId:Ht(e,V)|0,duration:Ht(e,V+4),x:X,y:ie,width:Math.hypot(J,Z)||R,height:Math.hypot(te,le)||L,uDir:[J,Z],vDir:[te,le],rotated:Math.abs(Z)>.5||Math.abs(te)>.5})}H.length===_&&H.every(O=>{if(!(O.width>0&&O.height>0))return!1;const V=[O.x,O.x+O.uDir[0],O.x+O.vDir[0],O.x+O.uDir[0]+O.vDir[0]],X=[O.y,O.y+O.uDir[1],O.y+O.vDir[1],O.y+O.uDir[1]+O.vDir[1]];return Math.min(...V)>=-1&&Math.max(...V)<=M+1&&Math.min(...X)>=-1&&Math.max(...X)<=h+1})&&(g={magic:v,frameWidth:R,frameHeight:L,atlasWidth:M,atlasHeight:h,list:H})}}}return{format:o,formatName:Lr[o]||String(o),flags:i,textureWidth:s,textureHeight:a,width:c,height:u,freeImageFormat:p,containerMagic:l,containerVersion:d,isVideo:y,images:x,frames:g}}function er(e,n,t){let r="";for(let o=n;o<n+t;o++)r+=String.fromCharCode(e[o]);return r}const Ks=Object.freeze(Object.defineProperty({__proto__:null,FIF:Vt,TEXTURE_FORMATS:Lr,decodeMip0:Ds,decodeMips:Bs,decodePixels:Rr,lz4Decompress:Co,parseTex:Zs},Symbol.toStringTag,{value:"Module"}));function Ro(e,n){if(!e||typeof n!="string")return null;const t=e[n];return t&&typeof t=="object"?t:null}function Fr(e){return typeof e=="string"?e:e&&typeof e=="object"&&typeof e.name=="string"?e.name:null}function Qs(e,n){return tr(e)&&tr(n)?Number(e)===Number(n):String(e)===String(n)}function Nr(e){if(typeof e=="boolean")return"bool";if(typeof e=="number")return Number.isFinite(e)?"num":"other";if(typeof e=="string"){const n=e.trim().split(/\s+/);return n.length>0&&n[0]!==""&&n.every(t=>Number.isFinite(Number(t)))?"num":"text"}return"other"}function Js(e){switch(e.type){case"bool":return"bool";case"slider":return"num";case"color":return"num";case"textinput":return"text";default:return Nr(e.value)}}function ko(e,n){if(e===null||typeof e!="object")return e;if(e.user&&typeof e.user=="object"&&typeof e.user.name=="string"){const r=Ro(n,e.user.name);if(!r||r.value===void 0||r.value===null)return e.value;const o=r.type==="combo"?Ur(r.value,r.options):r.value;return Qs(o,e.user.condition)}if(typeof e.user!="string")return e;const t=Ro(n,e.user);if(!t||t.value===void 0||t.value===null)return e.value;if(t.userOverridden)return t.value;if(e.value!==null&&typeof e.value=="object")return e.value;if(e.value===void 0)return t.value;if(Nr(e.value)==="bool"&&t.type==="slider"){const r=Number(t.value);return Number.isFinite(r)?r!==0:e.value}return Nr(e.value)===Js(t)?t.value:e.value}function pn(e,n,t){if(t>32||e===null||typeof e!="object")return e;if(Array.isArray(e)){for(let r=0;r<e.length;r++)e[r]=pn(e[r],n,t+1);return e}if(Fr(e.user)){let r=ko(e,n);for(let o=0;o<8&&r!==null&&typeof r=="object"&&Fr(r.user);o++)r=ko(r,n);return e.value=pn(r,n,t+1),e}for(const r of Object.keys(e))e[r]=pn(e[r],n,t+1);return e}function ea(e){return e?Array.isArray(e)?e.map(n=>n&&typeof n=="object"&&"value"in n?n.value:n):typeof e=="object"?Object.values(e):[]:[]}function tr(e){return typeof e=="number"?Number.isInteger(e):typeof e=="string"&&/^-?\d+$/.test(e.trim())}function Ur(e,n){const t=ea(n);return!(t.length>0?t.every(tr):tr(e))||typeof e=="number"&&Number.isFinite(e)?e:typeof e=="string"&&/^-?\d+$/.test(e.trim())?Number(e):e}function ta(e){const n={};if(!e||typeof e!="object")return n;for(const[t,r]of Object.entries(e))!r||typeof r!="object"||!("value"in r)||(n[t]=r.type==="combo"?Ur(r.value,r.options):r.value);return n}function Tt(e){return e&&typeof e=="object"?Fr(e.user):null}function na(e,n,t){const r={};if(!t||typeof t!="object")return r;const o=e&&typeof e=="object"?e:{},i=n&&typeof n=="object"?n:{};for(const[s,a]of Object.entries(t)){const c=a&&typeof a=="object"&&"value"in a?a.value:a,u=o[s];if(u&&typeof u=="object"){u.value=c,u.userOverridden=!0;const l=u.type==="combo"?Ur(u.value,u.options):u.value;i[s]=l,r[s]=l}else i[s]=c,r[s]=c}return r}function hn(e){typeof e=="object"&&e!==null&&(e=e.value);const n=String(e??"").trim().split(/\s+/).map(Number);return n.length===1?[n[0]||0,n[0]||0,n[0]||0]:[n[0]||0,n[1]||0,n[2]||0]}function Sn(e){typeof e=="object"&&e!==null&&(e=e.value);const n=String(e??"").trim().split(/\s+/).map(Number);return n.length===1?[n[0]||0,n[0]||0]:[n[0]||0,n[1]||0]}function nr(e){return e==null?[1,1,1]:typeof e=="string"?hn(e):typeof e=="object"&&e!==null?hn(e.value):[1,1,1]}function rt(e,n=!1){if(e==null)return n;if(typeof e=="boolean")return e;if(typeof e=="number")return e!==0;if(typeof e=="object"&&e!==null){const t=e.value;return typeof t=="number"?t!==0:!!t}return n}function ft(e,n){if(typeof e=="number")return e;if(e!==null&&typeof e=="object"){const t=Number(e.value);return Number.isFinite(t)?t:n}return n}function Dr(e){return e?!e.image&&!e.model&&!e.particle&&e.text==null&&!e.size:!1}function Br(e,n,t){const r=t?e.scale:[1,1,1],o=(e.angles[2]||0)*Math.PI/180,i=Math.cos(o),s=Math.sin(o),a=n.origin[0]*r[0],c=n.origin[1]*r[1];return{origin:[e.origin[0]+a*i-c*s,e.origin[1]+a*s+c*i,e.origin[2]+(n.origin[2]||0)],scale:[r[0]*n.scale[0],r[1]*n.scale[1],r[2]*n.scale[2]],angles:[n.angles[0],n.angles[1],(e.angles[2]||0)+n.angles[2]]}}function ra(e,n){const t=n&&n.general&&n.general.properties||{},r=e.objects||[];pn(r,t,0),pn(e.general||{},t,0);const o=new Map;for(const m of r)m.id!==void 0&&o.set(m.id,m);const i=r.map(m=>({id:m.id,parent:m.parent,origin:hn(m.origin||"0 0 0"),scale:hn(m.scale||"1 1 1"),angles:hn(m.angles||"0 0 0")})),s=i.map(m=>({origin:m.origin.slice(),scale:m.scale.slice(),angles:m.angles.slice()}));for(let m=0;m<8;m++){let M=!1;for(const h of i){if(h.parent===void 0||h.parent===null||!o.get(h.parent))continue;const v=i.findIndex(H=>H.id===h.parent);if(v<0)continue;const A=i[v];if(A.parent!==void 0&&A.parent!==null)continue;const _=r[v],R=_.scale,N=!(R!==null&&typeof R=="object"&&(typeof R.script=="string"||R.user!==void 0)&&Dr(_)),j=Br(A,h,N);h.origin=j.origin,h.scale=j.scale,h.angles=j.angles,h.parent=null,M=!0}if(!M)break}const a=r.map(m=>rt(m.visible,!0)),c=new Map;r.forEach((m,M)=>{m.id!==void 0&&c.set(m.id,M)});const u=new Map,l=new Map;for(const m of r)if(m.parent!==void 0&&m.parent!==null){u.set(m.parent,(u.get(m.parent)||0)+1);const M=m.id!==void 0?m.id:null;if(M!==null){const h=l.get(m.parent);h?h.push(M):l.set(m.parent,[M])}}const f=r.map(()=>!0);for(let m=0;m<r.length;m++){let M=a[m],h=r[m].parent;for(let g=0;M&&h!==void 0&&h!==null&&g<64;g++){const v=c.get(h);if(v===void 0)break;a[v]||(M=!1),h=r[v].parent}f[m]=M}const p=r.map((m,M)=>{const h=i[M],g=typeof m.image=="string"&&(m.image.indexOf("models/util/projectlayer")===0||m.image.indexOf("models/util/fullscreenlayer")===0);let v=Sn(m.size||"0 0"),A=h.origin;if(g){const _=(e.general||{}).orthogonalprojection,R=_&&Number(_.width),L=_&&Number(_.height);R>0&&L>0&&(v=[R,L],A=[R/2,L/2,h.origin[2]||0])}return{id:m.id!==void 0?m.id:M,name:m.name||"",visible:f[M],visibleSelf:a[M],srcObject:m,image:typeof m.image=="string"?m.image:null,model:typeof m.model=="string"?m.model:null,isSkybox:typeof m.name=="string"&&m.name.indexOf("\u5929\u7A7A\u76D2")>=0,particle:typeof m.particle=="string"?m.particle:null,instanceoverride:m.instanceoverride||null,sound:Array.isArray(m.sound)?m.sound.filter(_=>typeof _=="string"):[],soundprops:{volume:ft(m.volume,1),playbackmode:m.playbackmode||"single",startsilent:rt(m.startsilent,!1),maxtime:ft(m.maxtime,0),mintime:ft(m.mintime,0),spatialization:rt(m.spatialization,!1),muteineditor:rt(m.muteineditor,!1)},text:typeof m.text=="string"?m.text:m.text&&typeof m.text=="object"?m.text.value:null,textScript:m.text&&typeof m.text=="object"&&m.text.script||null,textScriptProps:m.text&&typeof m.text=="object"&&m.text.scriptproperties||null,component:typeof m.component=="string"?m.component:null,isText:m.text!==void 0&&m.text!==null,textFont:typeof m.font=="string"?m.font:null,textPointsize:ft(m.pointsize,24)||24,textColor:nr(m.color),textAnchor:typeof m.anchor=="string"&&m.anchor!=="none"?m.anchor:"center",textMaxwidth:ft(m.maxwidth,0),textMaxrows:ft(m.maxrows,0),textLimitwidth:rt(m.limitwidth,!1),textLimitrows:rt(m.limitrows,!1),textLimituseellipsis:rt(m.limituseellipsis,!1),textHAlign:m.horizontalalign||"center",textVAlign:m.verticalalign||"center",textSpacing:m.spacing?Sn(m.spacing):[0,0],textPadding:(()=>{const _=m.padding;if(typeof _=="number")return _;const R=String(_??"").trim().split(/\s+/).map(Number).filter(L=>Number.isFinite(L));return R.length?R.reduce((L,N)=>L+N,0)/R.length:0})(),textOpaquebackground:rt(m.opaquebackground,!1),textBackgroundcolor:nr(m.backgroundcolor),textBackgroundbrightness:ft(m.backgroundbrightness,1),textCastshadow:rt(m.castshadow,!1),isSound:!!(m.sound&&m.sound.length),isComponent:!!m.component,objectScripts:(()=>{const _={};for(const R of["scale","origin","color","alpha","brightness","angles","visible"]){const L=m[R];L&&typeof L=="object"&&typeof L.script=="string"&&L.script&&(_[R]={script:L.script,scriptproperties:L.scriptproperties||null,value:L.value})}return Object.keys(_).length?_:null})(),objectAnimations:(()=>{const _={};for(const R of["scale","origin","color","alpha","brightness","angles","visible","volume","maxwidth","zoom"]){const L=m[R];L&&typeof L=="object"&&L.animation&&typeof L.animation=="object"&&L.animation.options&&(_[R]={animation:L.animation,value:L.value})}return Object.keys(_).length?_:null})(),animationLayers:(m.animationlayers||[]).filter(_=>_&&typeof _.animation=="number").map(_=>({animation:_.animation,visible:rt(_.visible,!0),additive:rt(_.additive,!1),blend:ft(_.blend,1),rate:ft(_.rate,1)})),solid:(()=>{if(typeof m.particle=="string")return!1;const _=typeof m.image=="string"?m.image:"";return _.indexOf("models/util/composelayer")===0?!1:_.indexOf("models/util/solidlayer")===0?!0:m.solid?!_||_.indexOf("models/util/")===0:!1})(),isContainer:typeof m.image=="string"&&m.image.indexOf("models/util/composelayer")===0,hasChildren:(u.get(m.id!==void 0?m.id:M)||0)>0,childIds:l.get(m.id!==void 0?m.id:M)||null,parentId:m.parent!==void 0&&m.parent!==null?m.parent:null,attachment:typeof m.attachment=="string"&&m.attachment!==""?m.attachment:null,passthrough:!!(m.config&&m.config.passthrough===!0),isPostProcess:g,origin:A,scale:h.scale,angles:h.angles,localOrigin:s[M].origin,localScale:s[M].scale,localAngles:s[M].angles,renderInert:Dr(m),scaleRuntimeBound:m.scale!==null&&typeof m.scale=="object"&&(typeof m.scale.script=="string"||m.scale.user!==void 0),size:v,alignment:m.alignment||"center",color:nr(m.color),alpha:ft(m.alpha,1),brightness:ft(m.brightness,1),copybackground:!!m.copybackground,colorBlendMode:m.colorBlendMode||0,parallaxDepth:m.parallaxDepth!==void 0?Sn(m.parallaxDepth):null,effects:(m.effects||[]).map(_=>({file:_.file||"",name:typeof _.name=="string"?_.name:"",visible:rt(_.visible,!0),visibleScript:_.visible&&typeof _.visible=="object"&&typeof _.visible.script=="string"&&_.visible.script?{script:_.visible.script,scriptproperties:_.visible.scriptproperties||null,value:!!_.visible.value}:null,passes:(_.passes||[]).map(R=>({combos:R.combos||{},constantshadervalues:R.constantshadervalues||{},textures:R.textures||[]}))}))}}),d=e.general||{},y=(()=>{const m={};for(const[M,h]of Object.entries(d))h&&typeof h=="object"&&typeof h.script=="string"&&h.script&&(m[M]={script:h.script,scriptproperties:h.scriptproperties||null,value:h.value});return Object.keys(m).length?m:null})(),x=(()=>{const m={};for(const[M,h]of Object.entries(d))h&&typeof h=="object"&&h.animation&&typeof h.animation=="object"&&h.animation.options&&(m[M]={animation:h.animation,value:h.value});return Object.keys(m).length?m:null})();{const m=new Map;for(const M of p)M.id!==void 0&&m.set(M.id,M);for(let M=0;M<8;M++){let h=!1;for(const g of p){if(g.parallaxDepth||g.parentId==null)continue;const v=m.get(g.parentId);!v||!v.parallaxDepth||v.image||v.particle||v.model||(g.parallaxDepth=v.parallaxDepth.slice(),h=!0)}if(!h)break}}return{camera:e.camera||null,general:d,generalScripts:y,generalAnimations:x,layers:p,properties:t}}function oa(e){if(!Array.isArray(e))return;const n=new Map;for(const t of e)t&&t.id!==void 0&&t.id!==null&&n.set(t.id,t);for(const t of e){if(!t)continue;if(t.destroyed){t.visible=!1;continue}let r=t.visibleSelf!==!1,o=t.parentId;for(let i=0;r&&o!=null&&i<64;i++){const s=n.get(o);if(!s)break;(s.visibleSelf===!1||s.destroyed)&&(r=!1),o=s.parentId}t.visible=r}}function ia(e,n){!e||!n||typeof n!="object"||e.isContainer||n.solidlayer===!0&&(e.solid=!0)}function sa(e){return!e||typeof e.material!="string"?null:{materialPath:e.material,autosize:!!e.autosize,cropoffset:e.cropoffset?Sn(e.cropoffset):null}}function aa(e,n){if(!e||e.length===0)return;const t=new Map;for(const i of e)i&&i.id!==void 0&&i.id!==null&&t.set(i.id,i);const r=i=>{let s=0,a=i.parentId;for(let c=0;a!=null&&c<64;c++){const u=t.get(a);if(!u)break;s++,a=u.parentId}return s},o=[];for(const i of e)!i||!i.localOrigin||i.isPostProcess||n&&!n.has(i.id)||o.push(i);o.sort((i,s)=>r(i)-r(s));for(const i of o){const s=i.parentId!==void 0&&i.parentId!==null?t.get(i.parentId):null;let a;if(!s)a={origin:i.localOrigin.slice(),scale:i.localScale.slice(),angles:i.localAngles.slice()};else{const u=!(s.scaleRuntimeBound&&s.renderInert);a=Br({origin:s.origin,scale:s.scale,angles:s.angles},{origin:i.localOrigin,scale:i.localScale,angles:i.localAngles},u)}const c=i.attachBindDelta;c&&(a.origin[0]+=c[0],a.origin[1]+=c[1]),i.origin[0]=a.origin[0],i.origin[1]=a.origin[1],i.origin[2]=a.origin[2],i.scale[0]=a.scale[0],i.scale[1]=a.scale[1],i.scale[2]=a.scale[2],i.angles[0]=a.angles[0],i.angles[1]=a.angles[1],i.angles[2]=a.angles[2],i.attachBase&&(i.attachBase[0]=a.origin[0],i.attachBase[1]=a.origin[1])}}function ca(e,n){const t=new Set;if(!e||e.length===0)return t;const r=new Map;for(const a of e){if(!a||a.parentId===void 0||a.parentId===null)continue;const c=r.get(a.parentId);c?c.push(a):r.set(a.parentId,[a])}const o=["origin","scale","angles"],i=[];for(const a of e){if(!a||a.id===void 0||a.id===null)continue;const c=a.objectScripts||null,u=a.objectAnimations||null;o.some(f=>c&&c[f]||u&&u[f])&&i.push(a)}if(n)for(const a of n)a&&a.id!==void 0&&a.id!==null&&i.push(a);const s=i.slice();for(let a=0;s.length>0&&a<1e5;a++){const c=s.pop();if(!c||c.id===void 0||c.id===null||t.has(c.id))continue;t.add(c.id);const u=r.get(c.id);if(u)for(const l of u)s.push(l)}return t}const la=Object.freeze(Object.defineProperty({__proto__:null,applySolidFromModel:ia,collectTransformDirty:ca,composeChildTransform:Br,isRenderInert:Dr,parseBool:rt,parseColor:nr,parseNum:ft,parseScene:ra,parseVec2:Sn,parseVec3:hn,recomposeWorld:aa,recomputeLayerVisibility:oa,resolveMaterial:sa},Symbol.toStringTag,{value:"Module"}));function ua(e,n,t){const r=Cr(e,n.file);if(r===null)return;let o;try{o=JSON.parse(t(r))}catch{return}n.fbos=o.fbos||[],n.materialPasses=(o.passes||[]).map(i=>{if(!i.material)return{shader:null,copyCommand:!0,target:i.target||null,source:i.source||null,binds:i.bind||[],blending:"normal",textures:[],combos:{},constants:{}};const s=Cr(e,i.material);if(s===null)return{shader:null,copyCommand:!1,target:i.target||null,binds:i.bind||[],blending:"normal",textures:[],combos:{},constants:{}};const a=JSON.parse(t(s)),c=a.passes&&a.passes[0]||{};return{shader:c.shader||null,copyCommand:!1,target:i.target||null,binds:i.bind||[],blending:c.blending||"normal",textures:c.textures||[],combos:c.combos||{},constants:c.constantshadervalues||{}}})}const fa={"models/util/solidlayer.json":{material:"materials/util/solidlayer.json"},"models/util/composelayer.json":{material:"materials/util/solidlayer.json"},"models/util/fullscreenlayer.json":{material:"materials/util/solidlayer.json"},"models/util/projectlayer.json":{material:"materials/util/solidlayer.json"}};function Fo(e){if(!e||typeof e!="string")return!0;const n=e.toLowerCase();return n==="generic"||n==="sprite"||n==="flat"||n.startsWith("genericimage")}function da(e,n){return!e||!n||!n.shader||Fo(n.shader)||(e.effects=e.effects||[],e.effects.some(t=>t.layerMaterial))?!1:(e.effects.unshift({file:"",name:"_layerMaterial",visible:!0,layerMaterial:!0,passes:[{combos:n.combos||{},constantshadervalues:n.constantshadervalues||{},textures:n.textures||[]}],materialPasses:[{shader:n.shader,copyCommand:!1,target:null,binds:[],blending:n.blending||"normal",textures:n.textures||[],combos:n.combos||{},constants:n.constantshadervalues||{}}],fbos:[]}),!0)}const pa=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_MATERIALS:{"materials/util/solidlayer.json":{passes:[{shader:"flat",blending:"translucent",cullmode:"nocull",depthtest:"disabled",depthwrite:"disabled",textures:[],combos:{}}]}},BUILTIN_MODELS:fa,attachLayerMaterialEffect:da,isBuiltinAlbedoShader:Fo,resolveEffectChain:ua},Symbol.toStringTag,{value:"Module"}));function mn(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function St(e,n){const t=new Float32Array(16);for(let r=0;r<4;r++)for(let o=0;o<4;o++){let i=0;for(let s=0;s<4;s++)i+=e[s*4+o]*n[r*4+s];t[r*4+o]=i}return t}function gn(e,n,t,r,o,i){const s=mn();return s[0]=2/(n-e),s[5]=2/(r-t),s[10]=-2/(i-o),s[12]=-(n+e)/(n-e),s[13]=-(r+t)/(r-t),s[14]=-0/(i-o),s}function bn(e,n,t,r){return St(e,new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,n,t,r,1]))}function No(e){const n=new Float32Array(16);for(let t=0;t<4;t++)for(let r=0;r<4;r++)n[r*4+t]=e[t*4+r];return n}function En(e,n,t,r){return St(e,new Float32Array([n,0,0,0,0,t,0,0,0,0,r,0,0,0,0,1]))}function Uo(e,n){const t=Math.cos(n),r=Math.sin(n);return St(e,new Float32Array([t,r,0,0,-r,t,0,0,0,0,1,0,0,0,0,1]))}function ha(e,n){const t=Math.cos(n),r=Math.sin(n);return St(e,new Float32Array([1,0,0,0,0,t,r,0,0,-r,t,0,0,0,0,1]))}function ma(e,n){const t=Math.cos(n),r=Math.sin(n);return St(e,new Float32Array([t,0,-r,0,0,1,0,0,r,0,t,0,0,0,0,1]))}function ga(e,n,t,r){const o=1/Math.tan(e*Math.PI/180/2),i=new Float32Array(16);return i[0]=o/(n||1),i[5]=o,i[10]=(r+t)/(t-r),i[11]=-1,i[14]=2*r*t/(t-r),i}function rr(e,n){const t=e&&typeof e=="object"?e.value:e;return typeof t=="number"&&Number.isFinite(t)?t:n}function ba(e){const n=e&&e.general;return!n||n.orthogonalprojection?!1:rr(n.fov,0)>0}function ya(e,n){return n&&n.perspective&&e&&e.isSkybox&&n.eye?n.eye:e.origin}function va(e,n,t){const r=Bo([e[0]-n[0],e[1]-n[1],e[2]-n[2]]),o=Bo(Io(t,r)),i=Io(r,o),s=new Float32Array([o[0],i[0],r[0],0,o[1],i[1],r[1],0,o[2],i[2],r[2],0,0,0,0,1]);return s[12]=-(o[0]*e[0]+o[1]*e[1]+o[2]*e[2]),s[13]=-(i[0]*e[0]+i[1]*e[1]+i[2]*e[2]),s[14]=-(r[0]*e[0]+r[1]*e[1]+r[2]*e[2]),s}function xa(e,n,t,r){const o=e[3]*n+e[7]*t+e[11]*r+e[15];return[(e[0]*n+e[4]*t+e[8]*r+e[12])/o,(e[1]*n+e[5]*t+e[9]*r+e[13])/o,(e[2]*n+e[6]*t+e[10]*r+e[14])/o]}const wa=[[16,9],[16,10],[21,9],[32,9]];function Ma(e,n,t,r,o){const i=e/n;if(!Number.isFinite(i)||i<=0||!(t>0)||!(r>0))return null;const s=.02,a=t/r;if(Math.abs(i-a)<=s*a)return{viewW:t,viewH:r};for(const[c,u]of wa){const l=c/u;if(Math.abs(i-l)>s*l)continue;const f=r,p=r*l;return p>t+1e-6?{viewW:t,viewH:t/l}:{viewW:p,viewH:f}}return null}function Ir(e,n,t,r,o,i,s){const a=Do(i),c=Do(s);if(e==="cover"){const u=Ma(r,o,n,t);if(u)return{offX:(n-u.viewW)*a,offY:(t-u.viewH)*c,viewW:u.viewW,viewH:u.viewH};const l=Math.max(r/n,o/t),f=r/l,p=o/l;return{offX:(n-f)*a,offY:(t-p)*c,viewW:f,viewH:p}}if(e==="contain"){const u=r/o;if(n/t>u){const d=n,y=n/u;return{offX:0,offY:(t-y)/2,viewW:d,viewH:y}}const f=t,p=t*u;return{offY:0,offX:(n-p)/2,viewW:p,viewH:f}}return{offX:0,offY:0,viewW:n,viewH:t}}function _a(e,n,t,r,o,i){const s=e.general,a=e.camera,c=a&&a.eye?Or(a.eye):[0,0,0],u=a&&a.center?Or(a.center):[0,0,-1],l=a&&a.up?Or(a.up):[0,1,0];if(ba(e)){const g=t>0?n/t:1.7777777777777777,v=rr(s.fov,50),A=Math.max(rr(s.nearz,.01),1e-4),_=Math.max(rr(s.farz,1e4),A+1),R=va(c,u,l),L=ga(v,g,A,_);return{view:R,projection:L,eye:c,center:u,projW:g,projH:1,offX:0,offY:0,viewW:g,viewH:1,perspective:!0}}const f=mn(),p=s&&s.orthogonalprojection&&s.orthogonalprojection.width||n,d=s&&s.orthogonalprojection&&s.orthogonalprojection.height||t,y=Ir(r,p,d,n,t,o,i),x=e&&e.cameraTransforms?e.cameraTransforms.zoom:s&&s.zoom,m=x&&typeof x=="object"?x.value:x,M=Number(m);if(Number.isFinite(M)&&M>0&&Math.abs(M-1)>1e-6){const g=y.offX+y.viewW/2,v=y.offY+y.viewH/2,A=y.viewW/M,_=y.viewH/M;y.offX=g-A/2,y.offY=v-_/2,y.viewW=A,y.viewH=_}const h=gn(y.offX,y.offX+y.viewW,y.offY+y.viewH,y.offY,-1e4,1e4);return{view:f,projection:h,eye:c,projW:p,projH:d,offX:y.offX,offY:y.offY,viewW:y.viewW,viewH:y.viewH,perspective:!1}}function Do(e){const n=Number(e);return Number.isFinite(n)?n<0?0:n>1?1:n:.5}function Or(e){return String(e).trim().split(/\s+/).map(Number)}function Bo(e){const n=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/n,e[1]/n,e[2]/n]}function Io(e,n){return[e[1]*n[2]-e[2]*n[1],e[2]*n[0]-e[0]*n[2],e[0]*n[1]-e[1]*n[0]]}function yn(e){const n=Number(e);return Number.isFinite(n)?n*.5:0}function Aa(e){const n=new Map,t=new Map,r=/^[ \t]*#define[ \t]+([A-Za-z_][A-Za-z0-9_]*)(?:\(([^)]*)\))?[ \t]*(.*)$/gm;let o;for(;(o=r.exec(e))!==null;){const i=s=>s.replace(/\/\/.*$/,"").replace(/\/\*[\s\S]*?\*\//g,"").trim();o[2]!==void 0?t.set(o[1],{args:o[2].split(",").map(s=>s.trim()).filter(Boolean),body:i(o[3])}):n.set(o[1],i(o[3]))}return{defs:n,fns:t}}function Ta(e,n,t,r){const o=[];let i=0;for(;i<e.length;){const s=e.indexOf(n,i);if(s===-1){o.push(e.slice(i));break}o.push(e.slice(i,s));let c=s+n.length;for(;c<e.length&&/\s/.test(e[c]);)c++;if(e[c]!=="("){o.push(e.slice(s,c)),i=c;continue}let u=0,l=c;for(;l<e.length;l++)if(e[l]==="(")u++;else if(e[l]===")"&&(u--,u===0))break;if(l>=e.length){o.push(e.slice(s));break}const f=e.slice(c+1,l),p=Nt(f);let d=t.body;t.args.forEach((y,x)=>{const m=p[x]!==void 0?p[x].trim():"";d=Pn(d,y,m)}),r>0&&(d=Oo(d,r-1)),o.push("("+d+")"),i=l+1}return o.join("")}function Pn(e,n,t){return e.replace(new RegExp("\\b"+n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","g"),t)}function Nt(e){const n=[];let t=0,r="";for(let o=0;o<e.length;o++){const i=e[o];i==="("?t++:i===")"&&t--,i===","&&t===0?(n.push(r),r=""):r+=i}return r.trim()!==""&&n.push(r),n}function Oo(e,n){for(let t=0;t<12;t++){const{defs:r,fns:o}=Aa(e);if(r.size===0&&o.size===0)break;const i=e.split(`
|
|
2
|
-
`),s=new Map;for(let u=0;u<i.length;u++){const l=/^[ \t]*#define[ \t]+([A-Za-z_][A-Za-z0-9_]*)/.exec(i[u]);l&&!s.has(l[1])&&s.set(l[1],u)}const a=new Map;{const u="(?:float|int|bool|vec[234]|ivec[234]|bvec[234]|mat[234])";for(const l of r.keys()){const f=l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),p=new RegExp("^\\s*(?:const\\s+|uniform\\s+|varying\\s+|in\\s+|out\\s+|attribute\\s+)*"+u+"\\s+"+f+"\\s*[=;]");for(let d=0;d<i.length;d++)if(p.test(i[d])){a.set(l,d);break}}}let c=!1;for(let u=0;u<i.length;u++){const l=i[u];if(/^[ \t]*#/.test(l))continue;let f=l;for(const[p,d]of r){const y=s.get(p);if(y!==void 0&&u<y||a.get(p)===u)continue;new RegExp("\\b"+p.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b").test(f)&&(f=Pn(f,p,d),c=!0)}for(const[p,d]of o){const y=s.get(p);y!==void 0&&u<y||f.includes(p)&&(f=Ta(f,p,d,n),c=!0)}i[u]=f}if(e=i.join(`
|
|
3
|
-
`),!c)break}return e}function $o(e,n,t){const r=d=>n[d]!==void 0?String(n[d]):t.has(d)?"("+t.get(d)+")":"0";let o=e.replace(/\b[A-Za-z_][A-Za-z0-9_]*\b/g,d=>r(d)),i=0;function s(){for(;i<o.length&&/\s/.test(o[i]);)i++}function a(){let d=c();for(s();o.startsWith("||",i);){i+=2;const y=c();d=d||y,s()}return d}function c(){let d=u();for(s();o.startsWith("&&",i);){i+=2;const y=u();d=d&&y,s()}return d}function u(){let d=l();for(s();o.startsWith("==",i)||o.startsWith("!=",i);){const y=o[i]==="="?"==":"!=";i+=2;const x=l();d=y==="=="?d===x:d!==x,s()}return d}function l(){let d=f();for(s();/^[<>]/.test(o[i]||"");){let y=o[i];o[i+1]==="="&&(y+="=",i++),i++;const x=f();y==="<"?d=d<x:y===">"?d=d>x:y==="<="?d=d<=x:d=d>=x,s()}return d}function f(){return s(),o[i]==="!"?(i++,!f()):p()}function p(){if(s(),o[i]==="("){i++;const y=a();return s(),i++,y}const d=/^-?\d+(\.\d+)?/.exec(o.slice(i));return d?(i+=d[0].length,Number(d[0])):!1}return a()}function jo(e){let n="",t=0;const r=e.length;for(;t<r;){const o=e[t],i=e[t+1];if(o==="/"&&i==="*"){for(t+=2;t<r&&!(e[t]==="*"&&e[t+1]==="/");)e[t]===`
|
|
4
|
-
|
|
5
|
-
`),t++;t+=2;continue}if(o==="/"&&i==="/"){for(;t<r&&e[t]!==`
|
|
6
|
-
|
|
7
|
-
`),i=[],s=[],a=new Map;for(let c=0;c<o.length;c++){const u=o[c],l=u.trim();if(l.startsWith("#include")){if(Cn(s)){const f=/^#include[ \t]+"([^"]+)"|^#include[ \t]+<([^>]+)>/.exec(l),p=f&&(f[1]||f[2]),d=p&&t?t(p):null;d!=null?i.push(zo(jo(d),n,t)):i.push("// [include \u7F3A\u5931: "+p+"]")}continue}if(l.startsWith("#define")){if(Cn(s)){i.push(u);const f=/^#define[ \t]+([A-Za-z_][A-Za-z0-9_]*)(?:\([^)]*\))?[ \t]*(.*)$/.exec(l);f&&a.set(f[1],f[2].trim())}continue}if(l.startsWith("#undef")){Cn(s)&&i.push(u);continue}if(l.startsWith("#ifdef")||l.startsWith("#ifndef")||l.startsWith("#if")){const f=Cn(s);let p=!1;if(l.startsWith("#ifdef")){const d=l.slice(6).trim().split(/\s+/)[0];p=n[d]!==void 0||a.has(d)}else if(l.startsWith("#ifndef")){const d=l.slice(7).trim().split(/\s+/)[0];p=!(n[d]!==void 0||a.has(d))}else try{p=!!$o(l.slice(3).trim(),n,a)}catch{p=!1}s.push({parent:f,hit:p,done:p});continue}if(l.startsWith("#else")){if(s.length>0){const f=s[s.length-1];f.hit=!f.done,f.done=!0}continue}if(l.startsWith("#elif")){if(s.length>0){const f=s[s.length-1];if(f.done)f.hit=!1;else{let p=!1;try{p=!!$o(l.slice(5).trim(),n,a)}catch{p=!1}f.hit=p,f.done=p}}continue}if(l.startsWith("#endif")){s.length>0&&s.pop();continue}l.startsWith("#")||Cn(s)&&i.push(u)}return i.join(`
|
|
8
|
-
`)
|
|
9
|
-
`))break}for(;
|
|
10
|
-
`||V===")")break}const O=j.slice(N,K);return/\d\.\d/.test(O)?`${A}${_}.0 ${R} ${L}`:v});{const v=new Set,A=/\b(?:uniform\s+)?(?:highp|mediump|lowp\s+)?(?:float|vec2|vec3|vec4|mat2|mat3|mat4)\s+([A-Za-z_][A-Za-z0-9_]*)/g;let _;for(;(_=A.exec(l))!==null;)v.add(_[1]);if(v.size>0){const R=Array.from(v).sort((L,N)=>N.length-L.length).join("|");l=l.replace(new RegExp("(^|[^\\w.])(\\d+)\\s*([+-])\\s*("+R+")(?![A-Za-z0-9_])","g"),"$1$2.0 $3 $4"),l=l.replace(new RegExp("\\b("+R+")\\s*([+-])\\s*(\\d+)(?![\\d.])","g"),"$1 $2 $3.0")}}if(l===g)break}{const h=["smoothstep","step","mix","clamp","max","min","pow","mod","atan","sqrt","inversesqrt","exp","log","exp2","log2","abs","sign","floor","ceil","fract","length","distance","dot","reflect","refract","faceforward","normalize","cross"],g=/\b(ApplyBlending|ApplyComposite|BlendTransparency)\s*\(/;for(const v of h)l=je(l,v,A=>{const R=Nt(A).map(L=>{if(g.test(L))return L;const N=[];let j=L.replace(/\[[^\]]*\]/g,H=>(N.push(H),"\0"+(N.length-1)+"\0")).replace(/\b(?:ivec[234]|uvec[234]|int|uint)\s*\([^()]*\)/g,H=>(N.push(H),"\0"+(N.length-1)+"\0"));return j=j.replace(/(?<![A-Za-z0-9_.\u0000])(\d+)(?![.\d])(?![A-Za-z_])/g,"$1.0"),j.replace(/\u0000(\d+)\u0000/g,(H,K)=>N[Number(K)])});return v+"("+R.join(",")+")"});l=je(l,"pow",v=>{const A=Nt(v);if(A.length!==2)return"pow("+v+")";const _=A[0].trim(),R=A[1].trim(),L=/\.(xyzw|rgba|xyz|rgb|xy|rg|zw)\s*$/.exec(_),j=L?{xyzw:4,rgba:4,xyz:3,rgb:3,xy:2,rg:2,zw:2}[L[1]]:0,H=/\bvec[234]\s*\(/.test(R)||/\.(xyzw|rgba|xyz|rgb|xy|rg|zw)\b/.test(R);return j>=2&&!H?"pow("+_+", vec"+j+"("+R+"))":"pow("+_+", "+R+")"})}l=l.replace(/([)\]])\s*([*/])\s*(\d+)(?![\d.])/g,"$1 $2 $3.0"),l=l.replace(/\)\s*([+-])\s*(\d+)(?![\d.])/g,") $1 $2.0"),l=l.replace(/(^|[^\w.])(\d+)(?![.\d])\s*([+-])\s*((?:step|smoothstep|mix|mod|fract|abs|sin|cos|tan|atan|sqrt|pow|inversesqrt|floor|ceil|sign|length|normalize|distance|dot|cross|exp|log|exp2|log2|clamp|min|max)\s*\()/g,"$1$2.0 $3 $4");{const h=new Set,g=/\b(?:vec[234])\s+([A-Za-z_][A-Za-z0-9_]*)/g;let v;for(;(v=g.exec(l))!==null;)h.add(v[1]);if(h.size>0){const A=Array.from(h).sort((_,R)=>R.length-_.length).join("|");l=l.replace(new RegExp("\\b("+A+")\\s*([+-])\\s*(\\d+)(?![\\d.])","g"),"$1 $2 $3.0")}}{const h=new Set,g=/\b(?:int|uint)\s+([A-Za-z_][A-Za-z0-9_]*)/g;let v;for(;(v=g.exec(l))!==null;)h.add(v[1]);l=l.replace(/\buint\b/g,"int"),l=l.replace(/\b([A-Za-z_][A-Za-z0-9_]*)\s*%\s*(\d+)(?![\d.])/g,(A,_,R)=>h.has(_)?A:"mod("+_+", "+R+".0)"),l=l.replace(/\bint\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*mod\(([^;]*)\);/g,"int $1 = int(mod($2));")}l=l.replace(/\b(vec[234])\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*([^;()\n,]+);/g,(h,g,v,A)=>{const _=A.trim();return/^(vec[234]|mat[234]|int\b|float\b)/.test(_)?h:g+" "+v+" = "+g+"("+_+");"});for(const h of["mix","clamp","step","smoothstep","min","max","mod","pow"])l=je(l,h,g=>h+"("+g.replace(/(?<![A-Za-z0-9_.])(\d+)(?![.\d])/g,"$1.0")+")");l=je(l,"clamp",h=>{const g=Nt(h);if(g.length!==3)return"clamp("+h+")";const v=g[0].trim(),A=g[1].trim(),_=R=>/^-?\d+\.?\d*$/.test(R);return _(v)&&_(A)&&Number(v)===0&&Number(A)===1?"clamp("+g[2].trim()+", "+v+", "+A+")":"clamp("+h+")"}),l=l.replace(/(\.\d+)\s*([+-])\s*(\d+)(?![\d.])/g,"$1 $2 $3.0"),l=l.replace(/([)\]])\s*([+-])\s*(\d+)(?![\d.])/g,"$1 $2 $3.0"),l=je(l,"smoothstep",h=>{const g=Nt(h);return g.length===3&&g[1].trim()==="0.0"&&g[0].trim()!=="0.0"?"(1.0 - smoothstep(0.0, "+g[0].trim()+", "+g[2].trim()+"))":"smoothstep("+h+")"});{const h=new Map,g=/\b(?:uniform|varying|attribute|in|out)?\s*\b(vec([234]))\s+([A-Za-z_]\w*)/g;let v;for(;(v=g.exec(l))!==null;)h.set(v[3],Number(v[2]));if(h.size>0){const A={2:"xy",3:"xyz",4:"xyzw"};l=l.replace(/(^|[;{}\n]\s*)([A-Za-z_]\w*)\s*=\s*([A-Za-z_]\w*)\s*;/g,(_,R,L,N)=>{const j=h.get(L),H=h.get(N);return!j||!H||j>=H?_:R+L+" = "+N+"."+A[j]+";"})}{const A=new Set;{const L=/\b(?:uniform|varying|attribute|in|out|const)?\s*\bfloat\s+([A-Za-z_]\w*)/g;let N;for(;(N=L.exec(l))!==null;)A.add(N[1])}const _=L=>{const N=L.trim();{const K=/^vec([234])\s*\(/.exec(N);if(K){let O=0;for(let V=N.indexOf("(");V<N.length;V++)if(N[V]==="(")O++;else if(N[V]===")"&&(O--,O===0))return V===N.length-1?Number(K[1]):0;return 0}}if(/^texture(?:Lod)?\s*\(/.test(N)){let K=0;for(let O=N.indexOf("(");O<N.length;O++)if(N[O]==="(")K++;else if(N[O]===")"&&(K--,K===0))return O===N.length-1?4:0;return 0}const j=/^([A-Za-z_]\w*)(?:\.([xyzwrgba]{2,4}))?\s*[*/]\s*([^*/]+)$/.exec(N);if(!j)return 0;const H=j[3];return/\bvec[234]\s*\(|\.[xyzwrgba]{2,4}\b/.test(H)?0:j[2]?j[2].length:A.has(j[1])?0:h.get(j[1])||0};l=l.replace(/(^|[;{}\n]\s*)float\s+([A-Za-z_]\w*)\s*=\s*([^;]+);/g,(L,N,j,H)=>_(H)<2?L:`${N}float ${j} = (${H.trim()}).x;`);const R={2:"xy",3:"xyz"};l=l.replace(/(^|[;{}\n]\s*)vec([23])\s+([A-Za-z_]\w*)\s*=\s*([^;]+);/g,(L,N,j,H,K)=>{const O=Number(j);return _(K)<=O?L:`${N}vec${j} ${H} = (${K.trim()}).${R[O]};`})}if(h.size>0){const A=new Set,_=/\b(?:uniform|varying|attribute|in|out)?\s*\bfloat\s+([A-Za-z_]\w*)/g;let R;for(;(R=_.exec(l))!==null;)A.add(R[1]);const L="pow|saturate|clamp|smoothstep|step|abs|floor|ceil|fract|frac|sin|cos|tan|asin|acos|atan|sqrt|length|distance|dot|exp|log|sign|fmod|mod|min|max|mix|lerp",N=/^(?:length|distance|dot)$/,j=K=>{const O=K.match(new RegExp("^(?:"+L+")\\s*\\("));if(!O)return!1;let V=0;const X=O[0].length-1;let ie=-1;for(let te=X;te<K.length;te++)if(K[te]==="(")V++;else if(K[te]===")"&&(V--,V===0)){ie=te;break}if(ie!==K.length-1)return!1;const J=O[0].replace(/\s*\($/,"");if(N.test(J))return!0;const Z=K.slice(X+1,ie);if(/\bvec[234]\s*\(/.test(Z)||/\.[xyzwrgba]{2,4}\b/.test(Z))return!1;for(const te of h.keys()){const le=te.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");if(new RegExp("(?<!\\.)\\b"+le+"\\b(?!\\s*\\.[xyzwrgba]\\b)").test(Z))return!1}return!0},H=new Set;if(l=l.replace(/(^|[;{}\n]\s*)([A-Za-z_]\w*)\s*=\s*([^;]+);/g,(K,O,V,X)=>{const ie=h.get(V);if(!ie||A.has(V))return K;const J=X.trim();if(new RegExp("^vec"+ie+"\\s*\\(").test(J)||h.has(J))return K;const Z=/^-?\d+(?:\.\d+)?(?:e[-+]?\d+)?$/i.test(J),te=A.has(J);return!Z&&!te&&!j(J)?K:(H.add(V),O+V+" = vec"+ie+"("+J+");")}),H.size>0){const K=[...H].sort((O,V)=>V.length-O.length).join("|");l=l.replace(new RegExp(`\\b([A-Za-z_]\\w*)\\s*([*/])\\s*(${K})\\b`,"g"),(O,V,X,ie)=>h.has(V)?O:`${V} ${X} ${ie}.x`),l=l.replace(new RegExp(`\\b(${K})\\s*([*/])\\s*([A-Za-z_]\\w*)\\b`,"g"),(O,V,X,ie)=>h.has(ie)?O:`${V}.x ${X} ${ie}`)}}}l=l.replace(/(\.[xyzwrgba]{1,4}\s*=\s*)(-?\d+)\s*;/g,"$1$2.0;"),l=l.replace(/\b(float|vec2|vec3|vec4)\s+([A-Za-z_]\w*)\s*=\s*(-?\d+)\s*;/g,(h,g,v,A)=>g==="float"?`${g} ${v} = ${A}.0;`:`${g} ${v} = ${g}(${A}.0);`);{const h=new Set,g=/\b(?:uniform|varying|attribute|in|out)?\s*\bfloat\s+([A-Za-z_]\w*)/g;let v;for(;(v=g.exec(l))!==null;)h.add(v[1]);if(h.size>0){const A=[...h].sort((_,R)=>R.length-_.length).join("|");l=l.replace(new RegExp(`\\b(${A})\\s*=\\s*(-?\\d+)\\s*;`,"g"),"$1 = $2.0;"),l=l.replace(new RegExp(`\\b(${A})\\s*([-+*/]=)\\s*(-?\\d+)\\s*;`,"g"),"$1 $2 $3.0;")}}l=l.replace(/(\.[xyzwrgba]{1,4}\s*[-+*/]=\s*)(-?\d+)\s*;/g,"$1$2.0;");const d="step|smoothstep|saturate|clamp|mix|lerp|frac|fract|abs|floor|ceil|min|max|pow|sqrt|length|dot|distance";l=l.replace(new RegExp(`\\bint\\s+([A-Za-z_]\\w*)\\s*=\\s*((?:${d})\\s*\\()`,"g"),"float $1 = $2"),l=l.replace(/\bfloat\s+([A-Za-z_]\w*)\s*=\s*(int\s*\([^;]*\))\s*;/g,"float $1 = float($2);");{const h=Vo(l);h.size>0&&(l=l.replace(/\b(const\s+)?float\s+([A-Za-z_]\w*)\s*=\s*([^;{}]+);/g,(g,v,A,_)=>{const R=_.trim();if(/\./.test(R)||/[A-Za-z_]\w*\s*\(/.test(R))return g;const L=R.match(/[A-Za-z_]\w*/g);return!L||!L.length||!L.every(N=>h.has(N))?g:`${v||""}float ${A} = float(${R});`}))}{const h=Vo(l),g=new Set;let v;const A=/\b(?:const\s+|uniform\s+|varying\s+|in\s+|out\s+)*float\s+([A-Za-z_]\w*)/g;for(;(v=A.exec(l))!==null;)g.add(v[1]);for(const _ of[...h])g.has(_)&&(h.delete(_),g.delete(_));if(h.size>0&&g.size>0){const _=[...h].sort((L,N)=>N.length-L.length).join("|"),R=[...g].sort((L,N)=>N.length-L.length).join("|");l=l.replace(new RegExp(`\\b(${_})\\s*([*/+-])\\s*(${R})\\b`,"g"),(L,N,j,H)=>`float(${N}) ${j} ${H}`),l=l.replace(new RegExp(`\\b(${R})\\s*([*/+-])\\s*(${_})\\b`,"g"),(L,N,j,H)=>`${N} ${j} float(${H})`)}}{const h=new Set,g=/\bbool\s+([A-Za-z_]\w*)\s*=/g;let v;for(;(v=g.exec(l))!==null;)h.add(v[1]);if(h.size>0){const A=[...h].join("|");l=l.replace(new RegExp(`([-+*/]=\\s*)(${A})\\b`,"g"),(_,R,L)=>`${R}float(${L})`)}}{const h=/\(\s*([^()&|]+?)\s*(<=|>=|<|>|==|!=)\s*([^()&|]+?)\s*\)/g;l=l.replace(new RegExp(h.source+"\\s*([*/])","g"),(g,v,A,_,R)=>`float(${v.trim()} ${A} ${_.trim()}) ${R}`),l=l.replace(new RegExp("([-+*/]=\\s*)"+h.source,"g"),(g,v,A,_,R)=>`${v}float(${A.trim()} ${_} ${R.trim()})`)}{const h=new Set;for(const g of l.matchAll(/\b(?:uniform\s+)?(?:highp|mediump|lowp\s+)?float\s+([A-Za-z_]\w*)\s*\[/g))h.add(g[1]);if(h.size){const g=[...h].sort((L,N)=>N.length-L.length).join("|"),v=new RegExp("\\b("+g+")\\s*\\[","g");let A="",_=0,R;for(;R=v.exec(l);){const L=R.index+R[0].length-1,N=or(l,L,"[","]");if(N<0)break;let j=N+1;for(;j<l.length&&/[ \t]/.test(l[j]);)j++;if(l[j]!=="["){const X=l.slice(L+1,N).trim(),ie=/\d\.\d/.test(X)||/^[A-Za-z_]\w*$/.test(X)&&new RegExp("\\bfloat\\s+"+X.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b").test(l),J=/^\s*int\s*\(/.test(X)||/^-?\d+$/.test(X);if(ie&&!J){A+=l.slice(_,R.index),A+=R[1]+"[int("+X+")]",_=N+1,v.lastIndex=_;continue}v.lastIndex=N+1;continue}const H=or(l,j,"[","]");if(H<0)break;const K=l.slice(L+1,N),O=l.slice(j+1,H);A+=l.slice(_,R.index),A+=R[1]+"[int(("+K+")) * 4 + int(("+O+"))]",_=H+1,v.lastIndex=_}l=A+l.slice(_)}}l=je(l,"mix",(h,g)=>{const v=Nt(h);if(v.length!==3)return"mix("+h+")";const A=j=>{const H=j.trim(),K=/\.([xyzwrgba]{1,4})\s*$/.exec(H);if(K)return K[1].length;const O=/^vec([234])\s*\(/.exec(H);if(O)return Number(O[1]);if(!/^[A-Za-z_]\w*$/.test(H))return 0;const V=new RegExp("\\b(vec([234])|float)\\s+"+H+"\\b","g");let X=0,ie;for(;(ie=V.exec(l))!==null&&ie.index<g;)X=ie[1].startsWith("vec")?Number(ie[2]):1;return X},_=v[0].trim(),R=v[1].trim(),L=A(_),N=A(R);if(L>=2&&N>=2&&L!==N){const j=Math.min(L,N),H=j===2?".xy":j===3?".xyz":"";return H?"mix("+(L>j?_+H:_)+", "+(N>j?R+H:R)+", "+v[2].trim()+")":"mix("+h+")"}return"mix("+h+")"});{const h=/\b(vec([234]))\s+([A-Za-z_]\w*)\s*\(/g;let g="",v=0,A;for(;A=h.exec(l);){const _=Wo(l,A.index+A[0].length-1);if(_<0)break;let R=_+1;for(;R<l.length&&/\s/.test(l[R]);)R++;if(l[R]!=="{")continue;const L=or(l,R,"{","}");if(L<0)break;const N=Number(A[2]);if(N>=4){h.lastIndex=L;continue}let j=l.slice(R+1,L);const H=new Map;for(const O of l.slice(0,A.index).matchAll(/\buniform\s+(?:highp|mediump|lowp\s+)?(vec([234]))\s+([A-Za-z_]\w*)/g))H.set(O[3],Number(O[2]));for(const O of j.matchAll(/\b(vec([234]))\s+([A-Za-z_]\w*)/g))H.set(O[3],Number(O[2]));const K=N===2?"xy":"xyz";j=j.replace(/\breturn\s+([A-Za-z_]\w*)\s*;/g,(O,V)=>{const X=H.get(V);return X&&X>N?"return "+V+"."+K+";":O}),g+=l.slice(v,R+1)+j,v=L,h.lastIndex=L}l=g+l.slice(v)}const y=new Set,x=/\b(?:uniform\s+)?(?:mat4|mat3|mat2|float4x4)\s+([A-Za-z_][A-Za-z0-9_]*)/g;let m;for(;(m=x.exec(l))!==null;)y.add(m[1]);if(l=je(l,"mul",h=>{const g=Nt(h);if(g.length!==2)return"mul("+h+")";const v=g[0].trim(),A=g[1].trim(),_=R=>y.has(R.split(/[\[.\s]/)[0])||/^mat[234]\(/.test(R);return _(v)&&_(A)?"(transpose("+A+") * transpose("+v+"))":_(A)?"(transpose("+A+") * "+v+")":"("+v+" * "+A+")"}),l=l.replace(/\blerp\b/g,"mix").replace(/\bfrac\b/g,"fract"),l=je(l,"atan2",h=>"atan("+h+")"),l=je(l,"fmod",h=>{const g=Nt(h);if(g.length!==2)return"mod("+h+")";const v=g[0].trim(),A=g[1].trim();return"(("+v+") - ("+A+") * trunc(("+v+") / ("+A+")))"}),l=je(l,"ddx",h=>"dFdx("+h+")"),l=je(l,"ddy",h=>"dFdy("+h+")"),l=je(l,"CAST3X3",h=>"mat3("+h+")"),n==="vert")l=l.replace(/\battribute\b/g,"in").replace(/\bvarying\b/g,"out");else{if(l=l.replace(/\bvarying\b/g,"in").replace(/\battribute\b/g,"in"),typeof o=="string"&&o){const v=new Map,A=/^\s*(?:varying|out)\s+(?:highp|mediump|lowp\s+)?(vec[234]|float)\s+([A-Za-z_]\w*)\s*;/gm;let _;for(;(_=A.exec(o))!==null;)v.set(_[2],_[1]);const R={float:1,vec2:2,vec3:3,vec4:4},L=new Map;if(l=l.replace(/^(\s*in\s+(?:highp|mediump|lowp\s+)?)(vec[234]|float)(\s+)([A-Za-z_]\w*)(\s*;)/gm,(N,j,H,K,O,V)=>{const X=v.get(O);return!X||R[X]<=R[H]?N:(L.set(O,R[H]),j+X+K+O+V)}),L.size>0){const N={1:"x",2:"xy",3:"xyz"};for(const[j,H]of L){const K=N[H];K&&(l=l.split(`
|
|
11
|
-
`)
|
|
12
|
-
|
|
13
|
-
`).
|
|
14
|
-
`))}const
|
|
15
|
-
|
|
1
|
+
(function(It,fn){typeof exports=="object"&&typeof module<"u"?fn(exports):typeof define=="function"&&define.amd?define(["exports"],fn):(It=typeof globalThis<"u"?globalThis:It||self,fn(It.WebWallGL={}))})(this,function(It){"use strict";function fn(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function dn(t,e){const n=new Float32Array(16);for(let r=0;r<4;r++)for(let i=0;i<4;i++){let s=0;for(let a=0;a<4;a++)s+=t[a*4+i]*e[r*4+a];n[r*4+i]=s}return n}function Xr(t,e,n,r,i,s){const a=fn();return a[0]=2/(e-t),a[5]=2/(r-n),a[10]=-2/(s-i),a[12]=-(e+t)/(e-t),a[13]=-(r+n)/(r-n),a[14]=-0/(s-i),a}function Gr(t,e,n,r){return dn(t,new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,e,n,r,1]))}function Gc(t){const e=new Float32Array(16);for(let n=0;n<4;n++)for(let r=0;r<4;r++)e[r*4+n]=t[n*4+r];return e}function Ei(t,e,n,r){return dn(t,new Float32Array([e,0,0,0,0,n,0,0,0,0,r,0,0,0,0,1]))}function $c(t,e){const n=Math.cos(e),r=Math.sin(e);return dn(t,new Float32Array([n,r,0,0,-r,n,0,0,0,0,1,0,0,0,0,1]))}function gh(t,e){const n=Math.cos(e),r=Math.sin(e);return dn(t,new Float32Array([1,0,0,0,0,n,r,0,0,-r,n,0,0,0,0,1]))}function yh(t,e){const n=Math.cos(e),r=Math.sin(e);return dn(t,new Float32Array([n,0,-r,0,0,1,0,0,r,0,n,0,0,0,0,1]))}function bh(t,e,n,r){const i=1/Math.tan(t*Math.PI/180/2),s=new Float32Array(16);return s[0]=i/(e||1),s[5]=i,s[10]=(r+n)/(n-r),s[11]=-1,s[14]=2*r*n/(n-r),s}function _s(t,e){const n=t&&typeof t=="object"?t.value:t;return typeof n=="number"&&Number.isFinite(n)?n:e}function wh(t){const e=t&&t.general;return!e||e.orthogonalprojection?!1:_s(e.fov,0)>0}function vh(t,e){return e&&e.perspective&&t&&t.isSkybox&&e.eye?e.eye:t.origin}function kh(t,e,n){const r=Yc([t[0]-e[0],t[1]-e[1],t[2]-e[2]]),i=Yc(Kc(n,r)),s=Kc(r,i),a=new Float32Array([i[0],s[0],r[0],0,i[1],s[1],r[1],0,i[2],s[2],r[2],0,0,0,0,1]);return a[12]=-(i[0]*t[0]+i[1]*t[1]+i[2]*t[2]),a[13]=-(s[0]*t[0]+s[1]*t[1]+s[2]*t[2]),a[14]=-(r[0]*t[0]+r[1]*t[1]+r[2]*t[2]),a}function Ah(t,e,n,r){const i=t[3]*e+t[7]*n+t[11]*r+t[15];return[(t[0]*e+t[4]*n+t[8]*r+t[12])/i,(t[1]*e+t[5]*n+t[9]*r+t[13])/i,(t[2]*e+t[6]*n+t[10]*r+t[14])/i]}const xh=[[16,9],[16,10],[21,9],[32,9]];function Th(t,e,n,r,i){const s=t/e;if(!Number.isFinite(s)||s<=0||!(n>0)||!(r>0))return null;const a=.02,o=n/r;if(Math.abs(s-o)<=a*o)return{viewW:n,viewH:r};for(const[c,u]of xh){const l=c/u;if(Math.abs(s-l)>a*l)continue;const f=r,d=r*l;return d>n+1e-6?{viewW:n,viewH:n/l}:{viewW:d,viewH:f}}return null}function Sh(t){let e=1/0,n=1/0,r=-1/0,i=-1/0;for(const s of t||[]){if(!s||s.visible===!1||s.destroyed)continue;const a=Math.abs((s.size?.[0]??0)*(s.scale?.[0]??1)),o=Math.abs((s.size?.[1]??0)*(s.scale?.[1]??1));if(!(a>0)&&!(o>0))continue;const c=Number(s.angles?.[2]??0)||0,u=Math.abs(Math.cos(c)),l=Math.abs(Math.sin(c)),f=a*u+o*l,d=a*l+o*u,h=Number(s.origin?.[0]??0)||0,p=Number(s.origin?.[1]??0)||0;e=Math.min(e,h-f/2),r=Math.max(r,h+f/2),n=Math.min(n,p-d/2),i=Math.max(i,p+d/2)}return{minX:e,minY:n,maxX:r,maxY:i}}function Ua(t,e,n,r,i,s,a){const o=Qc(s),c=Qc(a);if(t==="cover"){const u=Th(r,i,e,n);if(u)return{offX:(e-u.viewW)*o,offY:(n-u.viewH)*c,viewW:u.viewW,viewH:u.viewH};const l=Math.max(r/e,i/n),f=r/l,d=i/l;return{offX:(e-f)*o,offY:(n-d)*c,viewW:f,viewH:d}}if(t==="contain"){const u=r/i;if(e/n>u){const h=e,p=e/u;return{offX:0,offY:(n-p)/2,viewW:h,viewH:p}}const f=n,d=n*u;return{offY:0,offX:(e-d)/2,viewW:d,viewH:f}}return{offX:0,offY:0,viewW:e,viewH:n}}function Ph(t,e,n,r,i,s){const a=t.general,o=t.camera,c=o&&o.eye?za(o.eye):[0,0,0],u=o&&o.center?za(o.center):[0,0,-1],l=o&&o.up?za(o.up):[0,1,0];if(wh(t)){const b=n>0?e/n:1.7777777777777777,v=_s(a.fov,50),k=Math.max(_s(a.nearz,.01),1e-4),A=Math.max(_s(a.farz,1e4),k+1),T=kh(c,u,l),S=bh(v,b,k,A);return{view:T,projection:S,eye:c,center:u,projW:b,projH:1,offX:0,offY:0,viewW:b,viewH:1,perspective:!0}}const f=fn(),d=a&&a.orthogonalprojection&&a.orthogonalprojection.width||e,h=a&&a.orthogonalprojection&&a.orthogonalprojection.height||n,p=Ua(r,d,h,e,n,i,s),m=t&&t.cameraTransforms?t.cameraTransforms.zoom:a&&a.zoom,g=m&&typeof m=="object"?m.value:m,w=Number(g);if(Number.isFinite(w)&&w>0&&Math.abs(w-1)>1e-6){const b=p.offX+p.viewW/2,v=p.offY+p.viewH/2,k=p.viewW/w,A=p.viewH/w;p.offX=b-k/2,p.offY=v-A/2,p.viewW=k,p.viewH=A}const y=Xr(p.offX,p.offX+p.viewW,p.offY+p.viewH,p.offY,-1e4,1e4);return{view:f,projection:y,eye:c,projW:d,projH:h,offX:p.offX,offY:p.offY,viewW:p.viewW,viewH:p.viewH,perspective:!1}}function Qc(t){const e=Number(t);return Number.isFinite(e)?e<0?0:e>1?1:e:.5}function za(t){return String(t).trim().split(/\s+/).map(Number)}function Yc(t){const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]}function Kc(t,e){return[t[1]*e[2]-t[2]*e[1],t[2]*e[0]-t[0]*e[2],t[0]*e[1]-t[1]*e[0]]}function $r(t){const e=Number(t);return Number.isFinite(e)?e*.5:0}function Es(t,e){const n=e?.renderDpr??t.cfg?.renderDpr??1;return Math.min(window.devicePixelRatio||1,n)}function xr(t){return t==="fit"?"contain":t==="fill"?"cover":t==="contain"||t==="stretch"?t:"cover"}function Ha(t){const e=xr(t);return e==="contain"?{objectFit:"contain",background:"rgba(10,12,16,0.85)"}:e==="stretch"?{objectFit:"fill",background:"transparent"}:{objectFit:"cover",background:"transparent"}}function _h(t){return{cfg:{type:"canvas"},coverAlign:{x:.5,y:.5,tx:.5,ty:.5},frameMeter:{stamps:[],last:0,fps:0},disposers:[]}}(()=>{const t=e=>e.preventDefault();window.addEventListener("contextmenu",t,!0),document.addEventListener("contextmenu",t,!0),window.__blockContextMenu=e=>e.addEventListener("contextmenu",t,!0)})();function Jn(t){if(t.iframe)try{t.iframe.contentWindow?.location.replace("about:blank")}catch{}if(t.wrap)t.wrap.innerHTML="";else if(t.iframe?.isConnected)try{t.iframe.remove()}catch{}t.raf!==void 0&&cancelAnimationFrame(t.raf),t.raf=void 0;for(const n of t.videoPairs??[])n.destroy();if(t.videoPairs=void 0,t.webcodecsPreferred=void 0,t.sceneCleanup)try{t.sceneCleanup()}catch{}t.sceneCleanup=void 0,t.sceneCtl=void 0,t.pointerCtl=void 0,t.mediaCtl=void 0;const e=t.wallpaperDisposers??[];t.wallpaperDisposers=[];for(const n of e)try{n()}catch{}t.renderer&&(t.renderer.dispose?.(),t.renderer=void 0);for(const n of t.videoTextures??[])n.pause(),n.removeAttribute("src"),n.load(),n.remove();t.videoTextures=void 0;for(const n of t.objectUrls??[])try{URL.revokeObjectURL(n)}catch{}if(t.objectUrls=void 0,t.sceneAudio){for(const n of t.sceneAudio.audios)n.pause(),n.removeAttribute("src"),n.load();t.sceneAudio=void 0}if(t.video){t.video.pause(),t.video.removeAttribute("src");try{t.video.load()}catch{}t.video.remove()}t.video=void 0,t.img=void 0,t.iframe=void 0,t.canvas=void 0,t.ctx=void 0,t.info=void 0,Rh(),Jc(t)}function Eh(t){try{Jn(t)}catch{}t.peekRaf!==void 0&&(cancelAnimationFrame(t.peekRaf),t.peekRaf=void 0);for(const e of t.disposers.splice(0))try{e()}catch{}t.wrap?.remove(),t.wrap=void 0}const Ch=new TextDecoder,Ot=t=>Ch.decode(t).replace(/^\uFEFF/,""),Zc=500;function er(t,e){const n=t.frameMeter.stamps;n.push(e),t.frameMeter.last=e;const r=e-Zc;for(;n.length&&n[0]<r;)n.shift();const i=n.length>=2?n[n.length-1]-n[0]:0;t.frameMeter.fps=i>0?(n.length-1)*1e3/i:0}function Jc(t){t.frameMeter.stamps.length=0,t.frameMeter.last=0,t.frameMeter.fps=0}function Ih(t){return!t.frameMeter.last||t.paused?{fps:0,running:!1}:performance.now()-t.frameMeter.last>Math.max(Zc,400)?{fps:0,running:!1}:{fps:t.frameMeter.fps,running:!0}}function ce(t,e,n){try{t.onDiagnostic?.(n,/fail|error|失败|ERROR/.test(n)?"error":"info")}catch{}try{const r=e.mediaBase?new URL(e.mediaBase,window.location.href).origin:"";if(r){const i=new Image;i.src=`${r}/diag?msg=${encodeURIComponent(`scene ${e.src??"?"}: ${n.slice(0,500)}`)}`}}catch{}}function Va(t){t.coverAlign.x=t.coverAlign.y=t.coverAlign.tx=t.coverAlign.ty=.5,Mh(t)}function Mh(t){const e=`${(t.coverAlign.x*100).toFixed(2)}% ${(t.coverAlign.y*100).toFixed(2)}%`,n=t.video??t.img;n&&n.isConnected&&(n.style.objectPosition=e)}const Bh=["__scene","__sceneLayers","__textures","__objScripts","__textWidgets","__mediaHooks","__mediaControl","__mediaStats","__mediaSet","__system","__liveSystem","__audioStats","__audioMute","__particleStats","__particleToggle","__pointerStats","__compositeStats","__compositeEnable"];function Rh(){const t=window;for(const e of Bh)e in t&&delete t[e]}function el(t,e,n){const r=Es(t,n),i=Math.max(1,Math.round((e.clientWidth||window.innerWidth||1)*r)),s=Math.max(1,Math.round((e.clientHeight||window.innerHeight||1)*r));return e.width===i&&e.height===s?!1:(e.width=i,e.height=s,!0)}const Fh=.5,tl=.12,Dh=.125,Nh=.0625,nl=64;function rl(t,e){const n=H=>{const G=document.createElement("video");H&&(G.src=t),G.muted=e.muted,G.playsInline=!0,G.preload="metadata";const Y=Math.min(window.devicePixelRatio||1,e.renderDpr||1),J=Math.max(1,Math.round((e.maxW||innerWidth)*Y)),ne=Math.max(1,Math.round((e.maxH||innerHeight)*Y));return G.width=J,G.height=ne,G.loop=!0,G};let r=n(!0),i=n(!1),s=!1,a=1,o=e.muted;i.muted=!0;const c=()=>{s||(i.src=t,s=!0)};let u=!1,l=!1,f,d=-1,h=0,p=0,m=tl,g=!1,w=0,y=0,b=0,v=0,k,A=-1,T=0,S=!1;const P=H=>{if(S||H!==r)return;if(!u||!g){M(),H.loop=!0,H.play().catch(()=>{}),q.onFallback?.();return}i.playbackRate=1;const G=r;l=!0,G.style.transition=`opacity ${nl}ms linear`,G.style.opacity="0";let Y=!1;const J=()=>{Y||S||(Y=!0,l=!1,G.style.transition="",B(),G.style.opacity="1")};G.addEventListener("transitionend",J,{once:!0}),f=window.setTimeout(J,nl+80)},M=()=>{u=!1,p=0,g=!1,l&&(l=!1,f&&(clearTimeout(f),f=void 0),r.style.transition="",r.style.opacity="1"),k&&(k.loop=!0,k=void 0),i.paused||i.pause(),i.playbackRate=1;try{i.currentTime=0}catch{}},B=()=>{const H=r;r=i,i=H,u=!1,p=0,g=!1,h=0,d=-1,b=0,v=0,y=performance.now()+Math.max(800,m*1e3+300),r.paused&&r.play().catch(()=>{}),r.playbackRate!==1&&(r.playbackRate=1),r.muted=o,r.volume=a,H.pause(),H.playbackRate=1;try{H.currentTime=0}catch{}H.muted=!0,H.loop=!0,A=-1,s=!0,q.onSwap?.(r)},N=(H,G)=>{const Y=performance.now();if(!(Y-v<1e3)){if(v=Y,b++,h=0,d=-1,b>=3){b=0;const J=G,ne=r;e.onRecover?.(`${H}\uFF1A\u91CD\u8F7D\u5A92\u4F53\u7BA1\u7EBF @${J.toFixed(2)}s`),A=-1,ne.addEventListener("loadedmetadata",()=>{if(!(S||ne!==r)){try{ne.currentTime=Math.max(0,Math.min(J,(ne.duration||J)-.05))}catch{}ne.play().catch(()=>{})}},{once:!0}),ne.src=t,ne.play().catch(()=>{});return}if(b===2){e.onRecover?.(`${H}\uFF1Aseek \u91CD\u542F\u89E3\u7801 @${G.toFixed(2)}s`);try{r.currentTime=Math.max(0,G-.001)}catch{}r.play().catch(()=>{});return}e.onRecover?.(`${H}\uFF1A\u8E22 play`),r.pause(),r.play().catch(()=>{})}},U=()=>{if(S)return;T=requestAnimationFrame(U);const H=r.duration;if(!isFinite(H)||H<=0)return;const G=r.currentTime;if(!document.hidden&&!l&&performance.now()>=y?r.paused&&!r.ended&&r.readyState>=1?(h++,h>30&&N("\u9759\u9ED8\u6682\u505C",G)):!r.paused&&r.readyState>=2?(d===G?(h++,h>30&&N("\u5047\u64AD\u653E",G)):(h=0,b=0),d=G):(h=0,d=-1):(h=0,d=-1),A>=0&&G<A-.05){const ne=u,fe=g;M(),A=G,ne&&!fe&&(m=Math.min(1,m*2)),ne||q.onFallback?.();return}A=G;const Y=H-G,J=Math.max(Fh,m+.5);if(Y>J+.5){u&&M();return}if(u){if(!g&&i.currentTime>.004){g=!0;const ne=performance.now()-w;m=Math.min(1,Math.max(tl,ne/1e3*1.5+.15)),k!==r&&(r.loop=!1,k=r)}!l&&g&&(r.ended||p>0&&performance.now()-p>1500)&&P(r);return}if(Y<=J&&(c(),i.readyState>=2)){if(Y<=m){try{i.currentTime=0}catch{}i.playbackRate=m>.3?Nh:Dh,w=performance.now(),g=!1,i.play().catch(()=>{}),u=!0,p=performance.now()}else if(i.paused)try{i.currentTime=0}catch{}}};T=requestAnimationFrame(U),r.addEventListener("ended",()=>P(r)),i.addEventListener("ended",()=>P(i));const q={get active(){return r},get standby(){return i},onSwap:void 0,onFallback:void 0,setVolume(H){a=Math.max(0,Math.min(1,H)),o=H<=0,r.muted=o,r.volume=a,i.muted=!0,i.volume=a},pause(){M(),r.pause(),T&&cancelAnimationFrame(T),T=0},resume(){S||(r.play().catch(H=>{H&&H.name}),T||(T=requestAnimationFrame(U)))},destroy(){S=!0,T&&cancelAnimationFrame(T),T=0;for(const H of[r,i]){H.pause(),H.removeAttribute("src");try{H.load()}catch{}H.remove()}}};return q}function R(t){if(!t)throw new Error("Assertion failed.")}const Wa=t=>{const e=(t%360+360)%360;if(e===0||e===90||e===180||e===270)return e;throw new Error(`Invalid rotation ${t}.`)},Mt=t=>t&&t[t.length-1],le=t=>{let e=0;for(;t.readBits(1)===0&&e<32;)e++;if(e>=32)throw new Error("Invalid exponential-Golomb code.");return(1<<e)-1+t.readBits(e)},Cn=t=>{const e=le(t);return(e&1)===0?-(e>>1):e+1>>1},In=t=>t.constructor===Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),Ie=t=>t.constructor===DataView?t:ArrayBuffer.isView(t)?new DataView(t.buffer,t.byteOffset,t.byteLength):new DataView(t),Bt=new TextDecoder,ja=t=>Object.fromEntries(Object.entries(t).map(([e,n])=>[n,e])),qa={bt709:1,bt470bg:5,smpte170m:6,bt2020:9,smpte432:12},Mn=ja(qa),Xa={bt709:1,smpte170m:6,linear:8,"iec61966-2-1":13,pq:16,hlg:18},Bn=ja(Xa),Ga={rgb:0,bt709:1,bt470bg:5,smpte170m:6,"bt2020-ncl":9},Rn=ja(Ga),$a=t=>!!t&&!!t.primaries&&!!t.transfer&&!!t.matrix&&t.fullRange!==void 0,il={primaries:void 0,transfer:void 0,matrix:void 0,fullRange:void 0},Lh=t=>t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer||ArrayBuffer.isView(t);class Cs{constructor(){this.currentPromise=Promise.resolve(),this.pending=0}async acquire(){let e;const n=new Promise(i=>{let s=!1;e=()=>{s||(i(),this.pending--,s=!0)}}),r=this.currentPromise;return this.currentPromise=n,this.pending++,await r,e}}const Oh=/^[0-9a-fA-F]+$/,Ci=t=>[...t].map(e=>e.toString(16).padStart(2,"0")).join(""),Uh=t=>{R(t.length%2===0);const e=new Uint8Array(t.length/2);for(let n=0;n<t.length;n+=2)e[n/2]=parseInt(t.slice(n,n+2),16);return e},sl=t=>(t=t>>1&1431655765|(t&1431655765)<<1,t=t>>2&858993459|(t&858993459)<<2,t=t>>4&252645135|(t&252645135)<<4,t=t>>8&16711935|(t&16711935)<<8,t=t>>16&65535|(t&65535)<<16,t>>>0),Ii=(t,e,n)=>{let r=0,i=t.length-1,s=-1;for(;r<=i;){const a=r+i>>1,o=n(t[a]);o===e?(s=a,i=a-1):o<e?r=a+1:i=a-1}return s},_e=(t,e,n)=>{let r=0,i=t.length-1,s=-1;for(;r<=i;){const a=r+(i-r+1)/2|0;n(t[a])<=e?(s=a,r=a+1):i=a-1}return s},al=(t,e,n)=>{const r=_e(t,n(e),n);t.splice(r+1,0,e)},mt=()=>{let t,e;return{promise:new Promise((r,i)=>{t=r,e=i}),resolve:t,reject:e}},Qa=(t,e)=>{const n=t.indexOf(e);n!==-1&&t.splice(n,1)},ol=(t,e)=>{for(let n=t.length-1;n>=0;n--)if(e(t[n]))return t[n]},Ya=(t,e)=>{for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1},zh=async function*(t){Symbol.iterator in t?yield*t[Symbol.iterator]():yield*t[Symbol.asyncIterator]()},Hh=t=>{if(!(Symbol.iterator in t)&&!(Symbol.asyncIterator in t))throw new TypeError("Argument must be an iterable or async iterable.")},Is=t=>{throw new Error(`Unexpected value: ${t}`)},cl=(t,e,n)=>{const r=t.getUint8(e),i=t.getUint8(e+1),s=t.getUint8(e+2);return r<<16|i<<8|s},Vh=(t,e,n,r)=>{n=n>>>0,n=n&16777215,t.setUint8(e,n>>>16&255),t.setUint8(e+1,n>>>8&255),t.setUint8(e+2,n&255)},Mi=(t,e,n)=>Math.max(e,Math.min(n,t)),Tt="und",Bi=t=>{const e=Math.round(t);return Math.abs(t/e-1)<10*Number.EPSILON?e:t},Ka=(t,e)=>Math.round(t/e)*e,ll=(t,e)=>Math.round(t*e)/e,Za=(t,e)=>Math.floor(t/e)*e,Wh=t=>{let e=0;for(;t;)e++,t>>=1;return e},Ja=t=>{let e=0;for(;t!==0;)t&=t-1,e++;return e},jh=/^[a-z]{3}$/,ul=t=>jh.test(t),Qr=1e6*(1+Number.EPSILON),fl=(t,e)=>{const n={...t,...e};if(t.headers||e.headers){const r=t.headers?eo(t.headers):{},i=e.headers?eo(e.headers):{},s={...r};Object.entries(i).forEach(([a,o])=>{const c=Object.keys(s).find(u=>u.toLowerCase()===a.toLowerCase());c&&delete s[c],s[a]=o}),n.headers=s}return n},eo=t=>{if(t instanceof Headers){const e={};return t.forEach((n,r)=>{e[r]=n}),e}if(Array.isArray(t)){const e={};return t.forEach(([n,r])=>{e[n]=r}),e}return t},dl=async(t,e,n,r,i)=>{let s=0;for(;;)try{return await t(e,n)}catch(a){if(i())throw a;s++;const o=r(s,a,e);if(o===null)throw a;if(pe._error("Retrying failed fetch. Error:",a),!Number.isFinite(o)||o<0)throw new TypeError("Retry delay must be a non-negative finite number.");if(o>0&&await Rs(1e3*o),i())throw a}};class qh{constructor(){this.currentPromise=Promise.resolve()}call(e){return this.currentPromise=this.currentPromise.then(e)}}let to=null;const no=()=>to!==null?to:to=!!(typeof navigator<"u"&&(navigator.vendor?.match(/apple/i)||/AppleWebKit/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent)||/\b(iPad|iPhone|iPod)\b/.test(navigator.userAgent)));let ro=null;const Xh=()=>ro!==null?ro:ro=typeof navigator<"u"&&navigator.userAgent?.includes("Firefox");let io=null;const so=()=>io!==null?io:io=!!(typeof navigator<"u"&&(navigator.vendor?.includes("Google Inc")||/Chrome/.test(navigator.userAgent))),Gh=t=>typeof globalThis.isSecureContext<"u"&&!globalThis.isSecureContext?`${t} is not available in this environment; this may be because this page is running in an insecure context. Try serving your page over HTTPS or use localhost.`:`${t} is not available in this environment.`,$h=(async()=>{})().constructor,ie=t=>t instanceof $h||t instanceof Promise?!0:typeof t?.then=="function",Yr=(t,e)=>t!==-1?t:e,ao=(t,e,n,r)=>t<=r&&n<=e,hl=t=>{const e=atob(t),n=new Uint8Array(e.length);for(let r=0;r<e.length;r++)n[r]=e.charCodeAt(r);return n},Qh=(t,e)=>{if(t.length!==e.length)return!1;for(let n=0;n<t.length;n++)if(t[n]!==e[n])return!1;return!0},oo=()=>{Symbol.dispose??=Symbol("Symbol.dispose")},Ms=t=>typeof t=="number"&&!Number.isNaN(t),tr=(t,e)=>{if(e.includes("://"))return e;if(t.includes("://")){const o=t.indexOf("?");o!==-1&&(t=t.slice(0,o))}let n;if(e.startsWith("/")){const o=t.indexOf("://");if(o===-1)n=e;else{const c=t.indexOf("/",o+3);c===-1?n=t+e:n=t.slice(0,c)+e}}else{const o=t.lastIndexOf("/");o===-1?n=e:n=t.slice(0,o+1)+e}let r="";const i=n.indexOf("://");if(i!==-1){const o=n.indexOf("/",i+3);o!==-1&&(r=n.slice(0,o),n=n.slice(o))}const s=n.split("/"),a=[];for(const o of s)o===".."?a.pop():o!=="."&&a.push(o);return r+a.join("/")},Ri=(t,e)=>{let n=0;for(let r=0;r<t.length;r++)e(t[r])&&n++;return n},co=(t,e)=>{let n=-1,r=1/0;for(let i=0;i<t.length;i++){const s=e(t[i]);s<r&&(r=s,n=i)}return n},Bs=t=>{R(Number.isInteger(t.num)),R(Number.isInteger(t.den)),R(t.den!==0);let e=Math.abs(t.num),n=Math.abs(t.den);for(;n!==0;){const i=e%n;e=n,n=i}const r=e||1;return{num:t.num/r,den:t.den/r}},lo=(t,e)=>{if(typeof t!="object"||!t)throw new TypeError(`${e} must be an object.`);if(!Number.isInteger(t.left)||t.left<0)throw new TypeError(`${e}.left must be a non-negative integer.`);if(!Number.isInteger(t.top)||t.top<0)throw new TypeError(`${e}.top must be a non-negative integer.`);if(!Number.isInteger(t.width)||t.width<0)throw new TypeError(`${e}.width must be a non-negative integer.`);if(!Number.isInteger(t.height)||t.height<0)throw new TypeError(`${e}.height must be a non-negative integer.`)},Rs=t=>new Promise(e=>setTimeout(e,t));class uo{constructor(){this._listeners=new Map}on(e,n,r){this._listeners.has(e)||this._listeners.set(e,new Set);const i={fn:n,once:r?.once??!1};return this._listeners.get(e).add(i),()=>{this._listeners.get(e)?.delete(i)}}_emit(...e){const[n,r]=e,i=this._listeners.get(n);if(i)for(const s of i){try{s.fn(r)}catch(a){console.error(a)}s.once&&i.delete(s)}}}var hn;(function(t){t[t.Silent=0]="Silent",t[t.Errors=1]="Errors",t[t.Warnings=2]="Warnings",t[t.Info=3]="Info"})(hn||(hn={}));class pe{constructor(){}static get level(){return pe._level}static set level(e){if(e!==hn.Silent&&e!==hn.Errors&&e!==hn.Warnings&&e!==hn.Info)throw new TypeError("Invalid log level. Use one of the values of the LogLevel enum.");pe._level=e}static get _emitter(){return pe._emitterInstance??=new uo}static on(e,n,r){return pe._emitter.on(e,n,r)}static _error(...e){pe._emitter._emit("error",e),pe._level>=hn.Errors&&console.error(...e)}static _warn(...e){pe._emitter._emit("warn",e),pe._level>=hn.Warnings&&console.warn(...e)}static _info(...e){pe._emitter._emit("info",e),pe._level>=hn.Info&&console.info(...e)}}pe._level=hn.Info,pe._emitterInstance=null;class Fs{constructor(e,n){if(this.data=e,this.mimeType=n,!(e instanceof Uint8Array))throw new TypeError("data must be a Uint8Array.");if(typeof n!="string")throw new TypeError("mimeType must be a string.")}}class Yh{constructor(e,n,r,i){if(this.data=e,this.mimeType=n,this.name=r,this.description=i,!(e instanceof Uint8Array))throw new TypeError("data must be a Uint8Array.");if(n!==void 0&&typeof n!="string")throw new TypeError("mimeType, when provided, must be a string.");if(r!==void 0&&typeof r!="string")throw new TypeError("name, when provided, must be a string.");if(i!==void 0&&typeof i!="string")throw new TypeError("description, when provided, must be a string.")}}const Fn={default:!0,primary:!0,forced:!1,original:!1,commentary:!1,hearingImpaired:!1,visuallyImpaired:!1};class Ee{constructor(e){this.bytes=e,this.pos=0}seekToByte(e){this.pos=8*e}readBit(){const e=Math.floor(this.pos/8),n=this.bytes[e]??0,r=7-(this.pos&7),i=(n&1<<r)>>r;return this.pos++,i}readBits(e){if(e===1)return this.readBit();let n=0;for(let r=0;r<e;r++)n<<=1,n|=this.readBit();return n}writeBits(e,n){const r=this.pos+e;for(let i=this.pos;i<r;i++){const s=Math.floor(i/8);let a=this.bytes[s];const o=7-(i&7);a&=~(1<<o),a|=(n&1<<r-i-1)>>r-i-1<<o,this.bytes[s]=a}this.pos=r}readAlignedByte(){if(this.pos%8!==0)throw new Error("Bitstream is not byte-aligned.");const e=this.pos/8,n=this.bytes[e]??0;return this.pos+=8,n}skipBits(e){this.pos+=e}getBitsLeft(){return this.bytes.length*8-this.pos}clone(){const e=new Ee(this.bytes);return e.pos=this.pos,e}}const Fi=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],fo=[-1,1,2,3,4,5,6,8],ml=t=>{if(!t||t.byteLength<2)throw new TypeError("AAC description must be at least 2 bytes long.");const e=new Ee(t),n=ho(e),{frequencyIndex:r,sampleRate:i}=mo(e),s=e.readBits(4);let a=null;s>=1&&s<=7&&(a=fo[s]);let o=n,c=!1,u=i;if(n===5||n===29)c=n===29,u=mo(e).sampleRate,o=ho(e),o===22&&e.skipBits(4);else for(;e.getBitsLeft()>15;){const l=e.pos;if(e.readBits(11)!==695){e.pos=l+1;continue}ho(e)===5&&e.readBits(1)&&(u=mo(e).sampleRate,e.getBitsLeft()>11&&e.readBits(11)===1352&&(c=!!e.readBits(1)));break}return a!==null&&a>1&&(c=!1),{objectType:n,coreObjectType:o,frequencyIndex:r,channelConfiguration:s,outputSampleRate:u,outputNumberOfChannels:c&&a===1?2:a}},ho=t=>{const e=t.readBits(5);return e===31?32+t.readBits(6):e},mo=t=>{const e=t.readBits(4);return e===15?{frequencyIndex:e,sampleRate:t.readBits(24)}:{frequencyIndex:e,sampleRate:e<Fi.length?Fi[e]:null}};const Ds=[48e3,44100,32e3],pl=[24e3,22050,16e3];var ct;(function(t){t[t.NON_IDR_SLICE=1]="NON_IDR_SLICE",t[t.SLICE_DPA=2]="SLICE_DPA",t[t.SLICE_DPB=3]="SLICE_DPB",t[t.SLICE_DPC=4]="SLICE_DPC",t[t.IDR=5]="IDR",t[t.SEI=6]="SEI",t[t.SPS=7]="SPS",t[t.PPS=8]="PPS",t[t.AUD=9]="AUD",t[t.SPS_EXT=13]="SPS_EXT"})(ct||(ct={}));var Ge;(function(t){t[t.RASL_N=8]="RASL_N",t[t.RASL_R=9]="RASL_R",t[t.BLA_W_LP=16]="BLA_W_LP",t[t.RSV_IRAP_VCL23=23]="RSV_IRAP_VCL23",t[t.VPS_NUT=32]="VPS_NUT",t[t.SPS_NUT=33]="SPS_NUT",t[t.PPS_NUT=34]="PPS_NUT",t[t.AUD_NUT=35]="AUD_NUT",t[t.PREFIX_SEI_NUT=39]="PREFIX_SEI_NUT",t[t.SUFFIX_SEI_NUT=40]="SUFFIX_SEI_NUT"})(Ge||(Ge={}));const Ns=function*(t){let e=0,n=-1;for(;e<t.length-2;){const r=t.indexOf(0,e);if(r===-1||r>=t.length-2)break;e=r;let i=0;if(e+3<t.length&&t[e+1]===0&&t[e+2]===0&&t[e+3]===1?i=4:t[e+1]===0&&t[e+2]===1&&(i=3),i===0){e++;continue}n!==-1&&e>n&&(yield{offset:n,length:e-n}),n=e+i,e=n}n!==-1&&n<t.length&&(yield{offset:n,length:t.length-n})},gl=function*(t,e){let n=0;const r=new DataView(t.buffer,t.byteOffset,t.byteLength);for(;n+e<=t.length;){let i;e===1?i=r.getUint8(n):e===2?i=r.getUint16(n,!1):e===3?i=cl(r,n):(R(e===4),i=r.getUint32(n,!1)),n+=e,yield{offset:n,length:i},n+=i}},yl=(t,e)=>{if(e.description){const i=(In(e.description)[4]&3)+1;return gl(t,i)}else return Ns(t)},Ls=t=>t&31,Os=t=>{const e=[],n=t.length;for(let r=0;r<n;r++)r+2<n&&t[r]===0&&t[r+1]===0&&t[r+2]===3?(e.push(0,0),r+=2):e.push(t[r]);return new Uint8Array(e)},po=new Uint8Array([0,0,0,1]),bl=t=>{const e=t.reduce((i,s)=>i+po.byteLength+s.byteLength,0),n=new Uint8Array(e);let r=0;for(const i of t)n.set(po,r),r+=po.byteLength,n.set(i,r),r+=i.byteLength;return n},wl=(t,e)=>{const n=t.reduce((s,a)=>s+e+a.byteLength,0),r=new Uint8Array(n);let i=0;for(const s of t){const a=new DataView(r.buffer,r.byteOffset,r.byteLength);switch(e){case 1:a.setUint8(i,s.byteLength);break;case 2:a.setUint16(i,s.byteLength,!1);break;case 3:Vh(a,i,s.byteLength);break;case 4:a.setUint32(i,s.byteLength,!1);break}i+=e,r.set(s,i),i+=s.byteLength}return r},Kh=(t,e)=>{if(e.description){const i=(In(e.description)[4]&3)+1;return wl(t,i)}else return bl(t)},go=t=>{try{const e=[],n=[],r=[];for(const o of Ns(t)){const c=t.subarray(o.offset,o.offset+o.length),u=Ls(c[0]);u===ct.SPS?e.push(c):u===ct.PPS?n.push(c):u===ct.SPS_EXT&&r.push(c)}if(e.length===0||n.length===0)return null;const i=e[0],s=Us(i);R(s!==null);const a=s.profileIdc===100||s.profileIdc===110||s.profileIdc===122||s.profileIdc===144;return{configurationVersion:1,avcProfileIndication:s.profileIdc,profileCompatibility:s.constraintFlags,avcLevelIndication:s.levelIdc,lengthSizeMinusOne:3,sequenceParameterSets:e,pictureParameterSets:n,chromaFormat:a?s.chromaFormatIdc:null,bitDepthLumaMinus8:a?s.bitDepthLumaMinus8:null,bitDepthChromaMinus8:a?s.bitDepthChromaMinus8:null,sequenceParameterSetExt:a?r:null}}catch(e){return pe._error("Error building AVC Decoder Configuration Record:",e),null}},vl=t=>{try{const e=Ie(t);let n=0;const r=e.getUint8(n++),i=e.getUint8(n++),s=e.getUint8(n++),a=e.getUint8(n++),o=e.getUint8(n++)&3,c=e.getUint8(n++)&31,u=[];for(let h=0;h<c;h++){const p=e.getUint16(n,!1);n+=2,u.push(t.subarray(n,n+p)),n+=p}const l=e.getUint8(n++),f=[];for(let h=0;h<l;h++){const p=e.getUint16(n,!1);n+=2,f.push(t.subarray(n,n+p)),n+=p}const d={configurationVersion:r,avcProfileIndication:i,profileCompatibility:s,avcLevelIndication:a,lengthSizeMinusOne:o,sequenceParameterSets:u,pictureParameterSets:f,chromaFormat:null,bitDepthLumaMinus8:null,bitDepthChromaMinus8:null,sequenceParameterSetExt:null};if((i===100||i===110||i===122||i===144)&&n+4<=t.length){const h=e.getUint8(n++)&3,p=e.getUint8(n++)&7,m=e.getUint8(n++)&7,g=e.getUint8(n++);d.chromaFormat=h,d.bitDepthLumaMinus8=p,d.bitDepthChromaMinus8=m;const w=[];for(let y=0;y<g;y++){const b=e.getUint16(n,!1);n+=2,w.push(t.subarray(n,n+b)),n+=b}d.sequenceParameterSetExt=w}return d}catch(e){return pe._error("Error deserializing AVC Decoder Configuration Record:",e),null}},kl={1:{num:1,den:1},2:{num:12,den:11},3:{num:10,den:11},4:{num:16,den:11},5:{num:40,den:33},6:{num:24,den:11},7:{num:20,den:11},8:{num:32,den:11},9:{num:80,den:33},10:{num:18,den:11},11:{num:15,den:11},12:{num:64,den:33},13:{num:160,den:99},14:{num:4,den:3},15:{num:3,den:2},16:{num:2,den:1}},Us=t=>{try{const e=new Ee(Os(t));if(e.skipBits(1),e.skipBits(2),e.readBits(5)!==7)return null;const r=e.readAlignedByte(),i=e.readAlignedByte(),s=e.readAlignedByte();le(e);let a=1,o=0,c=0,u=0;if((r===100||r===110||r===122||r===244||r===44||r===83||r===86||r===118||r===128)&&(a=le(e),a===3&&(u=e.readBits(1)),o=le(e),c=le(e),e.skipBits(1),e.readBits(1))){for(let N=0;N<(a!==3?8:12);N++)if(e.readBits(1)){const q=N<6?16:64;let H=8,G=8;for(let Y=0;Y<q;Y++){if(G!==0){const J=Cn(e);G=(H+J+256)%256}H=G===0?H:G}}}le(e);const l=le(e);if(l===0)le(e);else if(l===1){e.skipBits(1),Cn(e),Cn(e);const B=le(e);for(let N=0;N<B;N++)Cn(e)}le(e),e.skipBits(1);const f=le(e),d=le(e),h=16*(f+1),p=16*(d+1);let m=h,g=p;const w=e.readBits(1);if(w||e.skipBits(1),e.skipBits(1),e.readBits(1)){const B=le(e),N=le(e),U=le(e),q=le(e);let H,G;if((u===0?a:0)===0)H=1,G=2-w;else{const J=a===3?1:2,ne=a===1?2:1;H=J,G=ne*(2-w)}m-=H*(B+N),g-=G*(U+q)}let b=2,v=2,k=2,A=0,T={num:1,den:1},S=null,P=null;if(e.readBits(1)){if(e.readBits(1)){const ne=e.readBits(8);if(ne===255)T={num:e.readBits(16),den:e.readBits(16)};else{const fe=kl[ne];fe&&(T=fe)}}e.readBits(1)&&e.skipBits(1),e.readBits(1)&&(e.skipBits(3),A=e.readBits(1),e.readBits(1)&&(b=e.readBits(8),v=e.readBits(8),k=e.readBits(8))),e.readBits(1)&&(le(e),le(e)),e.readBits(1)&&(e.skipBits(32),e.skipBits(32),e.skipBits(1));const G=e.readBits(1);G&&Al(e);const Y=e.readBits(1);Y&&Al(e),(G||Y)&&e.skipBits(1),e.skipBits(1),e.readBits(1)&&(e.skipBits(1),le(e),le(e),le(e),le(e),S=le(e),P=le(e))}if(S===null){R(P===null);const B=i&16;if((r===44||r===86||r===100||r===110||r===122||r===244)&&B)S=0,P=0;else{const N=f+1,U=d+1,q=(2-w)*U,H=Ll.find(Y=>Y.level>=s)??Mt(Ll),G=Math.min(Math.floor(H.maxDpbMbs/(N*q)),16);S=G,P=G}}return R(P!==null),{profileIdc:r,constraintFlags:i,levelIdc:s,frameMbsOnlyFlag:w,chromaFormatIdc:a,bitDepthLumaMinus8:o,bitDepthChromaMinus8:c,codedWidth:h,codedHeight:p,displayWidth:m,displayHeight:g,pixelAspectRatio:T,colourPrimaries:b,matrixCoefficients:k,transferCharacteristics:v,fullRangeFlag:A,numReorderFrames:S,maxDecFrameBuffering:P}}catch(e){return pe._error("Error parsing AVC SPS:",e),null}},Al=t=>{const e=le(t);t.skipBits(4),t.skipBits(4);for(let n=0;n<=e;n++)le(t),le(t),t.skipBits(1);t.skipBits(5),t.skipBits(5),t.skipBits(5),t.skipBits(5)},Zh=(t,e)=>{if(e.description){const i=(In(e.description)[21]&3)+1;return wl(t,i)}else return bl(t)},zs=(t,e)=>{if(e.description){const i=(In(e.description)[21]&3)+1;return gl(t,i)}else return Ns(t)},Kr=t=>t>>1&63,yo=t=>{try{const e=new Ee(Os(t));e.skipBits(16),e.readBits(4);const n=e.readBits(3),r=e.readBits(1),{general_profile_space:i,general_tier_flag:s,general_profile_idc:a,general_profile_compatibility_flags:o,general_constraint_indicator_flags:c,general_level_idc:u}=Jh(e,n);le(e);const l=le(e);let f=0;l===3&&(f=e.readBits(1));const d=le(e),h=le(e);let p=d,m=h;if(e.readBits(1)){const N=le(e),U=le(e),q=le(e),H=le(e);let G=1,Y=1;const J=f===0?l:0;J===1?(G=2,Y=2):J===2&&(G=2,Y=1),p-=(N+U)*G,m-=(q+H)*Y}const g=le(e),w=le(e);le(e);const b=e.readBits(1)?0:n;let v=0;for(let N=b;N<=n;N++)le(e),v=le(e),le(e);le(e),le(e),le(e),le(e),le(e),le(e),e.readBits(1)&&e.readBits(1)&&em(e),e.skipBits(1),e.skipBits(1),e.readBits(1)&&(e.skipBits(4),e.skipBits(4),le(e),le(e),e.skipBits(1));const k=le(e);if(tm(e,k),e.readBits(1)){const N=le(e);for(let U=0;U<N;U++)le(e),e.skipBits(1)}e.skipBits(1),e.skipBits(1);let A=2,T=2,S=2,P=0,M=0,B={num:1,den:1};if(e.readBits(1)){const N=rm(e,n);B=N.pixelAspectRatio,A=N.colourPrimaries,T=N.transferCharacteristics,S=N.matrixCoefficients,P=N.fullRangeFlag,M=N.minSpatialSegmentationIdc}return{displayWidth:p,displayHeight:m,pixelAspectRatio:B,colourPrimaries:A,transferCharacteristics:T,matrixCoefficients:S,fullRangeFlag:P,maxDecFrameBuffering:v+1,spsMaxSubLayersMinus1:n,spsTemporalIdNestingFlag:r,generalProfileSpace:i,generalTierFlag:s,generalProfileIdc:a,generalProfileCompatibilityFlags:o,generalConstraintIndicatorFlags:c,generalLevelIdc:u,chromaFormatIdc:l,bitDepthLumaMinus8:g,bitDepthChromaMinus8:w,minSpatialSegmentationIdc:M}}catch(e){return pe._error("Error parsing HEVC SPS:",e),null}},bo=t=>{try{const e=[],n=[],r=[],i=[];for(const u of Ns(t)){const l=t.subarray(u.offset,u.offset+u.length),f=Kr(l[0]);f===Ge.VPS_NUT?e.push(l):f===Ge.SPS_NUT?n.push(l):f===Ge.PPS_NUT?r.push(l):(f===Ge.PREFIX_SEI_NUT||f===Ge.SUFFIX_SEI_NUT)&&i.push(l)}if(n.length===0||r.length===0)return null;const s=yo(n[0]);if(!s)return null;let a=0;if(r.length>0){const u=r[0],l=new Ee(Os(u));l.skipBits(16),le(l),le(l),l.skipBits(1),l.skipBits(1),l.skipBits(3),l.skipBits(1),l.skipBits(1),le(l),le(l),Cn(l),l.skipBits(1),l.skipBits(1),l.readBits(1)&&le(l),Cn(l),Cn(l),l.skipBits(1),l.skipBits(1),l.skipBits(1),l.skipBits(1);const f=l.readBits(1),d=l.readBits(1);!f&&!d?a=0:f&&!d?a=2:!f&&d?a=3:a=0}const o=[...e.length?[{arrayCompleteness:1,nalUnitType:Ge.VPS_NUT,nalUnits:e}]:[],...n.length?[{arrayCompleteness:1,nalUnitType:Ge.SPS_NUT,nalUnits:n}]:[],...r.length?[{arrayCompleteness:1,nalUnitType:Ge.PPS_NUT,nalUnits:r}]:[],...i.length?[{arrayCompleteness:1,nalUnitType:Kr(i[0][0]),nalUnits:i}]:[]];return{configurationVersion:1,generalProfileSpace:s.generalProfileSpace,generalTierFlag:s.generalTierFlag,generalProfileIdc:s.generalProfileIdc,generalProfileCompatibilityFlags:s.generalProfileCompatibilityFlags,generalConstraintIndicatorFlags:s.generalConstraintIndicatorFlags,generalLevelIdc:s.generalLevelIdc,minSpatialSegmentationIdc:s.minSpatialSegmentationIdc,parallelismType:a,chromaFormatIdc:s.chromaFormatIdc,bitDepthLumaMinus8:s.bitDepthLumaMinus8,bitDepthChromaMinus8:s.bitDepthChromaMinus8,avgFrameRate:0,constantFrameRate:0,numTemporalLayers:s.spsMaxSubLayersMinus1+1,temporalIdNested:s.spsTemporalIdNestingFlag,lengthSizeMinusOne:3,arrays:o}}catch(e){return pe._error("Error building HEVC Decoder Configuration Record:",e),null}},Jh=(t,e)=>{const n=t.readBits(2),r=t.readBits(1),i=t.readBits(5);let s=0;for(let l=0;l<32;l++)s=s<<1|t.readBits(1);const a=new Uint8Array(6);for(let l=0;l<6;l++)a[l]=t.readBits(8);const o=t.readBits(8),c=[],u=[];for(let l=0;l<e;l++)c.push(t.readBits(1)),u.push(t.readBits(1));if(e>0)for(let l=e;l<8;l++)t.skipBits(2);for(let l=0;l<e;l++)c[l]&&t.skipBits(88),u[l]&&t.skipBits(8);return{general_profile_space:n,general_tier_flag:r,general_profile_idc:i,general_profile_compatibility_flags:s,general_constraint_indicator_flags:a,general_level_idc:o}},em=t=>{for(let e=0;e<4;e++)for(let n=0;n<(e===3?2:6);n++)if(!t.readBits(1))le(t);else{const i=Math.min(64,1<<4+(e<<1));e>1&&Cn(t);for(let s=0;s<i;s++)Cn(t)}},tm=(t,e)=>{const n=[];for(let r=0;r<e;r++)n[r]=nm(t,r,e,n)},nm=(t,e,n,r)=>{let i=0,s=0,a=0;if(e!==0&&(s=t.readBits(1)),s){if(e===n){const c=le(t);a=e-(c+1)}else a=e-1;t.readBits(1),le(t);const o=r[a]??0;for(let c=0;c<=o;c++)t.readBits(1)||t.readBits(1);i=r[a]}else{const o=le(t),c=le(t);for(let u=0;u<o;u++)le(t),t.readBits(1);for(let u=0;u<c;u++)le(t),t.readBits(1);i=o+c}return i},rm=(t,e)=>{let n=2,r=2,i=2,s=0,a=0,o={num:1,den:1};if(t.readBits(1)){const c=t.readBits(8);if(c===255)o={num:t.readBits(16),den:t.readBits(16)};else{const u=kl[c];u&&(o=u)}}return t.readBits(1)&&t.readBits(1),t.readBits(1)&&(t.readBits(3),s=t.readBits(1),t.readBits(1)&&(n=t.readBits(8),r=t.readBits(8),i=t.readBits(8))),t.readBits(1)&&(le(t),le(t)),t.readBits(1),t.readBits(1),t.readBits(1),t.readBits(1)&&(le(t),le(t),le(t),le(t)),t.readBits(1)&&(t.readBits(32),t.readBits(32),t.readBits(1)&&le(t),t.readBits(1)&&im(t,!0,e)),t.readBits(1)&&(t.readBits(1),t.readBits(1),t.readBits(1),a=le(t),le(t),le(t),le(t),le(t)),{pixelAspectRatio:o,colourPrimaries:n,transferCharacteristics:r,matrixCoefficients:i,fullRangeFlag:s,minSpatialSegmentationIdc:a}},im=(t,e,n)=>{let r=!1,i=!1,s=!1;r=t.readBits(1)===1,i=t.readBits(1)===1,(r||i)&&(s=t.readBits(1)===1,s&&(t.readBits(8),t.readBits(5),t.readBits(1),t.readBits(5)),t.readBits(4),t.readBits(4),s&&t.readBits(4),t.readBits(5),t.readBits(5),t.readBits(5));for(let a=0;a<=n;a++){const o=t.readBits(1)===1;let c=!0;o||(c=t.readBits(1)===1);let u=!1;c?le(t):u=t.readBits(1)===1;let l=1;u||(l=le(t)+1),r&&xl(t,l,s),i&&xl(t,l,s)}},xl=(t,e,n)=>{for(let r=0;r<e;r++)le(t),le(t),n&&(le(t),le(t)),t.readBits(1)},sm=t=>{try{const e=Ie(t);let n=0;const r=e.getUint8(n++),i=e.getUint8(n++),s=i>>6&3,a=i>>5&1,o=i&31,c=e.getUint32(n,!1);n+=4;const u=t.subarray(n,n+6);n+=6;const l=e.getUint8(n++),f=(e.getUint8(n++)&15)<<8|e.getUint8(n++),d=e.getUint8(n++)&3,h=e.getUint8(n++)&3,p=e.getUint8(n++)&7,m=e.getUint8(n++)&7,g=e.getUint16(n,!1);n+=2;const w=e.getUint8(n++),y=w>>6&3,b=w>>3&7,v=w>>2&1,k=w&3,A=e.getUint8(n++),T=[];for(let S=0;S<A;S++){const P=e.getUint8(n++),M=P>>7&1,B=P&63,N=e.getUint16(n,!1);n+=2;const U=[];for(let q=0;q<N;q++){const H=e.getUint16(n,!1);n+=2,U.push(t.subarray(n,n+H)),n+=H}T.push({arrayCompleteness:M,nalUnitType:B,nalUnits:U})}return{configurationVersion:r,generalProfileSpace:s,generalTierFlag:a,generalProfileIdc:o,generalProfileCompatibilityFlags:c,generalConstraintIndicatorFlags:u,generalLevelIdc:l,minSpatialSegmentationIdc:f,parallelismType:d,chromaFormatIdc:h,bitDepthLumaMinus8:p,bitDepthChromaMinus8:m,avgFrameRate:g,constantFrameRate:y,numTemporalLayers:b,temporalIdNested:v,lengthSizeMinusOne:k,arrays:T}}catch(e){return pe._error("Error deserializing HEVC Decoder Configuration Record:",e),null}};var pt;(function(t){t[t.audAllowed=0]="audAllowed",t[t.beforeFirstVcl=1]="beforeFirstVcl",t[t.afterFirstVcl=2]="afterFirstVcl",t[t.eoBitstreamAllowed=3]="eoBitstreamAllowed",t[t.noMoreDataAllowed=4]="noMoreDataAllowed"})(pt||(pt={}));const am=(t,e)=>{const n=new Set;let r=pt.audAllowed;for(const s of zs(t,e)){if(r===pt.noMoreDataAllowed){n.add(s.offset);continue}const a=Kr(t[s.offset]);if(r===pt.eoBitstreamAllowed&&a!==37){n.add(s.offset);continue}let o=!1;a===35?r>pt.audAllowed?o=!0:r=pt.beforeFirstVcl:a<=31?r>pt.afterFirstVcl?o=!0:r=pt.afterFirstVcl:a===36?r!==pt.afterFirstVcl?o=!0:r=pt.eoBitstreamAllowed:a===37?r<pt.afterFirstVcl?o=!0:r=pt.noMoreDataAllowed:a===32||a===33||a===34||a===39||a>=41&&a<=44||a>=48&&a<=55?r>pt.beforeFirstVcl?o=!0:r=pt.beforeFirstVcl:(a===38||a===40||a>=45&&a<=47||a>=56&&a<=63)&&r<pt.afterFirstVcl&&(o=!0),o&&n.add(s.offset)}if(n.size===0)return null;const i=[];for(const s of zs(t,e))n.has(s.offset)||i.push(t.subarray(s.offset,s.offset+s.length));return Zh(i,e)},om={1:{colourPrimaries:5,transferCharacteristics:6,matrixCoefficients:5},2:{colourPrimaries:1,transferCharacteristics:1,matrixCoefficients:1},3:{colourPrimaries:6,transferCharacteristics:6,matrixCoefficients:6},4:{colourPrimaries:7,transferCharacteristics:7,matrixCoefficients:7},5:{colourPrimaries:9,transferCharacteristics:14,matrixCoefficients:9},7:{colourPrimaries:1,transferCharacteristics:13,matrixCoefficients:0}},Tl=t=>{const e=new Ee(t);if(e.readBits(2)!==2)return null;const r=e.readBits(1),s=(e.readBits(1)<<1)+r;if(s===3&&e.skipBits(1),e.readBits(1)===1||e.readBits(1)!==0||(e.skipBits(2),e.readBits(24)!==4817730))return null;let u=8;s>=2&&(u=e.readBits(1)?12:10);const l=e.readBits(3);let f=0,d=0;if(l!==7)if(d=e.readBits(1),s===1||s===3){const S=e.readBits(1),P=e.readBits(1);f=!S&&!P?3:S&&!P?2:1,e.skipBits(1)}else f=1;else f=3,d=1;const h=e.readBits(16),p=e.readBits(16),m=h+1,g=p+1,w=m*g;let y=Mt(Jr).level;for(const T of Jr)if(w<=T.maxPictureSize){y=T.level;break}const b=om[l],v=b?.colourPrimaries??2,k=b?.transferCharacteristics??2,A=b?.matrixCoefficients??2;return{profile:s,level:y,bitDepth:u,chromaSubsampling:f,videoFullRangeFlag:d,colourPrimaries:v,transferCharacteristics:k,matrixCoefficients:A}},cm=t=>t.colourPrimaries!==2||t.transferCharacteristics!==2||t.matrixCoefficients!==2,Sl=function*(t){const e=new Ee(t),n=()=>{let r=0;for(let i=0;i<8;i++){const s=e.readAlignedByte();if(r+=(s&127)*2**(i*7),!(s&128))break;if(i===7&&s&128)return null}return r>2**32-1?null:r};for(;e.getBitsLeft()>=8;){e.skipBits(1);const r=e.readBits(4),i=e.readBits(1),s=e.readBits(1);e.skipBits(1),i&&e.skipBits(8);let a;if(s){const o=n();if(o===null)return;a=o}else a=Math.floor(e.getBitsLeft()/8);R(e.pos%8===0),yield{type:r,data:t.subarray(e.pos/8,e.pos/8+a)},e.skipBits(a*8)}},wo=t=>{for(const{type:e,data:n}of Sl(t)){if(e!==1)continue;const r=new Ee(n),i=r.readBits(3);r.readBits(1);const s=r.readBits(1);let a=0,o=0,c=0;if(s)a=r.readBits(5);else{const P=r.readBits(1);let M=0;if(P){if(r.skipBits(32),r.skipBits(32),r.readBits(1)){let q=0;for(;q<32&&!r.readBits(1);)q++;q<32&&r.skipBits(q)}M=r.readBits(1),M&&(c=r.readBits(5),r.skipBits(32),r.skipBits(5),r.skipBits(5))}const B=r.readBits(1),N=r.readBits(5);for(let U=0;U<=N;U++){r.skipBits(12);const q=r.readBits(5);if(U===0&&(a=q),q>7){const H=r.readBits(1);U===0&&(o=H)}if(M&&r.readBits(1)){const G=c+1;r.skipBits(G),r.skipBits(G),r.skipBits(1)}B&&r.readBits(1)&&r.skipBits(4)}}const u=r.readBits(4),l=r.readBits(4),f=u+1;r.skipBits(f);const d=l+1;r.skipBits(d);let h=0;if(s?h=0:h=r.readBits(1),h&&(r.skipBits(4),r.skipBits(3)),r.skipBits(1),r.skipBits(1),r.skipBits(1),!s){r.skipBits(1),r.skipBits(1),r.skipBits(1),r.skipBits(1);const P=r.readBits(1);P&&(r.skipBits(1),r.skipBits(1));const M=r.readBits(1);let B=0;M?B=2:B=r.readBits(1),B>0&&(r.readBits(1)||r.skipBits(1)),P&&r.skipBits(3)}r.skipBits(1),r.skipBits(1),r.skipBits(1);const p=r.readBits(1);let m=8;i===2&&p?m=r.readBits(1)?12:10:i<=2&&(m=p?10:8);let g=0;i!==1&&(g=r.readBits(1));let w=2,y=2,b=2;r.readBits(1)&&(w=r.readBits(8),y=r.readBits(8),b=r.readBits(8));let k=0,A=1,T=1,S=0;return g?k=r.readBits(1):w===1&&y===13&&b===0?(k=1,A=0,T=0):(k=r.readBits(1),i===0?(A=1,T=1):i===1?(A=0,T=0):m===12?(A=r.readBits(1),T=A?r.readBits(1):0):(A=1,T=0),A&&T&&(S=r.readBits(2))),{profile:i,level:a,tier:o,bitDepth:m,monochrome:g,chromaSubsamplingX:A,chromaSubsamplingY:T,chromaSamplePosition:S,videoFullRangeFlag:k,colourPrimaries:w,transferCharacteristics:y,matrixCoefficients:b}}return null},lm=t=>t.colourPrimaries!==2||t.transferCharacteristics!==2||t.matrixCoefficients!==2,Pl=t=>{if(t.length<36)return null;const n=Ie(t);return n.getUint32(4)!==1768124518||n.getUint16(8)<28?null:{fullRange:!1,colourPrimaries:n.getUint8(22),transferCharacteristics:n.getUint8(23),matrixCoefficients:n.getUint8(24)}},um=t=>{const e=Ie(t),n=e.getUint8(9),r=e.getUint16(10,!0),i=e.getUint32(12,!0),s=e.getInt16(16,!0),a=e.getUint8(18);let o=null;return a&&(o=t.subarray(19,21+n)),{outputChannelCount:n,preSkip:r,inputSampleRate:i,outputGain:s,channelMappingFamily:a,channelMappingTable:o}},fm=[480,960,1920,2880,480,960,1920,2880,480,960,1920,2880,480,960,480,960,120,240,480,960,120,240,480,960,120,240,480,960,120,240,480,960],dm=t=>{const e=t[0]>>3,n=t[0]&3;let r;return n===0?r=1:n===1||n===2?r=2:r=t[1]&63,{durationInSamples:fm[e]*r}},hm=t=>{if(t.length<7)throw new Error("Setup header is too short.");if(t[0]!==5)throw new Error("Wrong packet type in Setup header.");if(String.fromCharCode(...t.slice(1,7))!=="vorbis")throw new Error("Invalid packet signature in Setup header.");const n=t.length,r=new Uint8Array(n);for(let f=0;f<n;f++)r[f]=t[n-1-f];const i=new Ee(r);let s=0;for(;i.getBitsLeft()>97;)if(i.readBits(1)===1){s=i.pos;break}if(s===0)throw new Error("Invalid Setup header: framing bit not found.");let a=0,o=!1,c=0;for(;i.getBitsLeft()>=97;){const f=i.pos,d=i.readBits(8),h=i.readBits(16),p=i.readBits(16);if(d>63||h!==0||p!==0){i.pos=f;break}if(i.skipBits(1),a++,a>64)break;i.clone().readBits(6)+1===a&&(o=!0,c=a)}if(!o)throw new Error("Invalid Setup header: mode header not found.");if(c>63)throw new Error(`Unsupported mode count: ${c}.`);const u=c;i.pos=0,i.skipBits(s);const l=Array(u).fill(0);for(let f=u-1;f>=0;f--)i.skipBits(40),l[f]=i.readBits(1);return{modeBlockflags:l}},vo=(t,e,n)=>{switch(t){case"avc":{for(const r of yl(n,e)){const i=n[r.offset],s=Ls(i);if(s>=ct.NON_IDR_SLICE&&s<=ct.SLICE_DPC)return"delta";if(s===ct.IDR)return"key";if(s===ct.SEI&&!so()){const a=n.subarray(r.offset,r.offset+r.length),o=Os(a);let c=1;do{let u=0;for(;;){const d=o[c++];if(d===void 0||(u+=d,d<255))break}let l=0;for(;;){const d=o[c++];if(d===void 0||(l+=d,d<255))break}if(u===6){const d=new Ee(o);d.pos=8*c;const h=le(d),p=d.readBits(1);if(h===0&&p===1)return"key"}c+=l}while(c<o.length-1)}}return"delta"}case"hevc":{for(const r of zs(n,e)){const i=Kr(n[r.offset]);if(i<Ge.BLA_W_LP)return"delta";if(i<=Ge.RSV_IRAP_VCL23)return"key"}return"delta"}case"vp8":return(n[0]&1)===0?"key":"delta";case"vp9":{const r=new Ee(n);if(r.readBits(2)!==2)return null;const i=r.readBits(1);return(r.readBits(1)<<1)+i===3&&r.skipBits(1),r.readBits(1)?null:r.readBits(1)===0?"key":"delta"}case"av1":{let r=!1;for(const{type:i,data:s}of Sl(n))if(i===1){const a=new Ee(s);a.skipBits(4),r=!!a.readBits(1)}else if(i===3||i===6||i===7){if(r)return"key";const a=new Ee(s);return a.readBits(1)?null:a.readBits(2)===0?"key":"delta"}return null}case"prores":return"key";default:Is(t),R(!1)}};var Zr;(function(t){t[t.STREAMINFO=0]="STREAMINFO",t[t.VORBIS_COMMENT=4]="VORBIS_COMMENT",t[t.PICTURE=6]="PICTURE"})(Zr||(Zr={}));const ko=(t,e)=>{const n=Ie(t);let r=0;const i=n.getUint32(r,!0);r+=4;const s=Bt.decode(t.subarray(r,r+i));r+=i,i>0&&(e.raw??={},e.raw.vendor??=s);const a=n.getUint32(r,!0);r+=4;for(let o=0;o<a;o++){const c=n.getUint32(r,!0);r+=4;const u=Bt.decode(t.subarray(r,r+c));r+=c;const l=u.indexOf("=");if(l===-1)continue;const f=u.slice(0,l).toUpperCase(),d=u.slice(l+1);switch(e.raw??={},e.raw[f]??=d,f){case"TITLE":e.title??=d;break;case"DESCRIPTION":e.description??=d;break;case"ARTIST":e.artist??=d;break;case"ALBUM":e.album??=d;break;case"ALBUMARTIST":e.albumArtist??=d;break;case"COMMENT":e.comment??=d;break;case"LYRICS":e.lyrics??=d;break;case"TRACKNUMBER":{const h=d.split("/"),p=Number.parseInt(h[0],10),m=h[1]&&Number.parseInt(h[1],10);Number.isInteger(p)&&p>0&&(e.trackNumber??=p),m&&Number.isInteger(m)&&m>0&&(e.tracksTotal??=m)}break;case"TRACKTOTAL":{const h=Number.parseInt(d,10);Number.isInteger(h)&&h>0&&(e.tracksTotal??=h)}break;case"DISCNUMBER":{const h=d.split("/"),p=Number.parseInt(h[0],10),m=h[1]&&Number.parseInt(h[1],10);Number.isInteger(p)&&p>0&&(e.discNumber??=p),m&&Number.isInteger(m)&&m>0&&(e.discsTotal??=m)}break;case"DISCTOTAL":{const h=Number.parseInt(d,10);Number.isInteger(h)&&h>0&&(e.discsTotal??=h)}break;case"DATE":{const h=new Date(d);Number.isNaN(h.getTime())||(e.date??=h)}break;case"GENRE":e.genre??=d;break;case"METADATA_BLOCK_PICTURE":{const h=hl(d),p=Ie(h),m=p.getUint32(0,!1),g=p.getUint32(4,!1),w=String.fromCharCode(...h.subarray(8,8+g)),y=p.getUint32(8+g,!1),b=Bt.decode(h.subarray(12+g,12+g+y)),v=p.getUint32(g+y+28),k=h.subarray(g+y+32,g+y+32+v);e.images??=[],e.images.push({data:k,mimeType:w,kind:m===3?"coverFront":m===4?"coverBack":"unknown",name:void 0,description:b||void 0})}break}}},Ao=[2,1,2,3,3,4,4,5],mm=t=>{if(t.length<7||t[0]!==11||t[1]!==119)return null;const e=new Ee(t);e.skipBits(16),e.skipBits(16);const n=e.readBits(2);if(n===3)return null;const r=e.readBits(6),i=e.readBits(5);if(i>8)return null;const s=e.readBits(3),a=e.readBits(3);(a&1)!==0&&a!==1&&e.skipBits(2),(a&4)!==0&&e.skipBits(2),a===2&&e.skipBits(2);const o=e.readBits(1),c=Math.floor(r/2);return{fscod:n,bsid:i,bsmod:s,acmod:a,lfeon:o,bitRateCode:c}},pm=[128,138,192,128,140,192,160,174,240,160,176,240,192,208,288,192,210,288,224,242,336,224,244,336,256,278,384,256,280,384,320,348,480,320,350,480,384,416,288*2,384,418,288*2,448,486,336*2,448,488,336*2,256*2,278*2,384*2,256*2,279*2,384*2,320*2,348*2,480*2,320*2,349*2,480*2,384*2,417*2,576*2,384*2,418*2,576*2,448*2,487*2,672*2,448*2,488*2,672*2,512*2,557*2,768*2,512*2,558*2,768*2,640*2,696*2,960*2,640*2,697*2,960*2,768*2,835*2,1152*2,768*2,836*2,1152*2,896*2,975*2,1344*2,896*2,976*2,1344*2,1024*2,1114*2,1536*2,1024*2,1115*2,1536*2,1152*2,1253*2,1728*2,1152*2,1254*2,1728*2,1280*2,1393*2,1920*2,1280*2,1394*2,1920*2],gm=1536,_l=[1,2,3,6],ym=t=>{if(t.length<6||t[0]!==11||t[1]!==119)return null;const e=new Ee(t);e.skipBits(16);const n=e.readBits(2);if(e.skipBits(3),n!==0&&n!==2)return null;const r=e.readBits(11),i=e.readBits(2);let s=0,a;i===3?(s=e.readBits(2),a=3):a=e.readBits(2);const o=e.readBits(3),c=e.readBits(1),u=e.readBits(5);if(u<11||u>16)return null;const l=_l[a];let f;return i<3?f=Ds[i]/1e3:f=pl[s]/1e3,{dataRate:Math.round((r+1)*f/(l*16)),substreams:[{fscod:i,fscod2:s,bsid:u,bsmod:0,acmod:o,lfeon:c,numDepSub:0,chanLoc:0}]}},bm=t=>{if(t.length<2)return null;const e=new Ee(t),n=e.readBits(13),r=e.readBits(3),i=[];for(let s=0;s<=r&&!(Math.ceil(e.pos/8)+3>t.length);s++){const a=e.readBits(2),o=e.readBits(5);e.skipBits(1),e.skipBits(1);const c=e.readBits(3),u=e.readBits(3),l=e.readBits(1);e.skipBits(3);const f=e.readBits(4);let d=0;f>0?d=e.readBits(9):e.skipBits(1),i.push({fscod:a,fscod2:null,bsid:o,bsmod:c,acmod:u,lfeon:l,numDepSub:f,chanLoc:d})}return i.length===0?null:{dataRate:n,substreams:i}},El=t=>{const e=t.substreams[0];return R(e),e.fscod<3?Ds[e.fscod]:e.fscod2!==null&&e.fscod2<3?pl[e.fscod2]:null},Cl=t=>{const e=t.substreams[0];R(e);let n=Ao[e.acmod]+e.lfeon;if(e.numDepSub>0){const r=[2,2,1,1,2,2,2,1,1];for(let i=0;i<9;i++)e.chanLoc&1<<8-i&&(n+=r[i])}return n},wm=1683496997,Hs=18,xo=10,vm=4096,Il=32,Ml=20,km=8,Am=[0,8e3,16e3,32e3,0,0,11025,22050,44100,0,0,12e3,24e3,48e3,96e3,192e3],xm=[32e3,56e3,64e3,96e3,112e3,128e3,192e3,224e3,256e3,32e4,384e3,448e3,512e3,576e3,64e4,768e3,96e4,1024e3,1152e3,128e4,1344e3,1408e3,1411200,1472e3,1536e3,192e4,2048e3,3072e3,384e4,0,0,0],Tm=[16,16,20,20,0,24,24,0],Vs=[1,2,2,2,2,3,3,4,4,5,6,6,6,7,8,8],Sm=[1,2,2,2,2,3,18,19,6,7,518,323,83,519,582,535],Pm=8,_m=44646,Em=[32e3,44100,48e3,0],Cm=[8e3,16e3,32e3,64e3,128e3,22050,44100,88200,176400,352800,12e3,24e3,48e3,96e3,192e3,384e3],Im=[512,1024,2048,4096],Bl=t=>{const e=Fl(t),n=Ie(t);let r=e?Math.ceil(e.frameSize/4)*4:0,i=null;for(;r+4<=t.length&&n.getUint32(r)===wm;){const a=Ws(t.subarray(r));if(!a)break;i??=a,r+=a.frameSize}if(e)return{frameSize:i?r:e.frameSize,sampleRate:e.sampleRate,numberOfChannels:e.numberOfChannels,sampleCount:e.sampleCount,channelLayout:e.channelLayout,pcmResolution:e.pcmResolution,bitRate:e.bitRate,core:e,hasExtensions:i!==null};if(!i?.asset)return null;const{asset:s}=i;return{frameSize:r,sampleRate:s.sampleRate,numberOfChannels:s.numberOfChannels,sampleCount:s.sampleCount,channelLayout:s.channelLayout,pcmResolution:s.pcmResolution,bitRate:0,core:null,hasExtensions:!0}},Rl=t=>{const e=Bl(t);return e?.core?e.hasExtensions?"dtsh":"dtsc":null},Fl=t=>{if(t.length<Hs||t[0]!==127||t[1]!==254||t[2]!==128||t[3]!==1)return null;const e=new Ee(t);if(e.skipBits(32),e.skipBits(1),e.readBits(5)!==Il-1)return null;const n=e.readBits(1),r=e.readBits(7)+1;if(r%km!==0)return null;const i=e.readBits(14)+1;if(i<96)return null;const s=e.readBits(6);if(s>=Vs.length)return null;const a=Am[e.readBits(4)];if(a===0)return null;const o=xm[e.readBits(5)];if(e.readBits(1)!==0)return null;e.skipBits(4),e.skipBits(5);const c=e.readBits(2);if(c===3)return null;e.skipBits(1),n&&e.skipBits(16),e.skipBits(7);const u=Tm[e.readBits(3)];if(u===0)return null;const l=c!==0;return{frameSize:i,sampleRate:a,numberOfChannels:Vs[s]+(l?1:0),sampleCount:r*Il,channelLayout:Sm[s]|(l?Pm:0),amode:s,lfePresent:l,bitRate:o,pcmResolution:u}},Ws=t=>{if(t.length<xo||t[0]!==100||t[1]!==88||t[2]!==32||t[3]!==37)return null;const e=new Ee(t);e.skipBits(32),e.skipBits(8);const n=e.readBits(2),r=e.readBits(1),i=8+4*r,s=16+4*r;e.skipBits(i);const a=e.readBits(s)+1,o={frameSize:a,asset:null};if(!e.readBits(1))return o;const c=Em[e.readBits(2)],u=512*(e.readBits(3)+1);e.readBits(1)&&e.skipBits(36);const l=e.readBits(3)+1,f=e.readBits(3)+1,d=[];for(let w=0;w<l;w++)d.push(e.readBits(n+1));for(const w of d)e.skipBits(8*Ja(w));if(e.readBits(1)){e.skipBits(2);const w=e.readBits(2)+1<<2,y=e.readBits(2)+1;e.skipBits(y*w)}for(let w=0;w<f;w++)e.skipBits(s);e.skipBits(9),e.skipBits(3),e.readBits(1)&&e.skipBits(4),e.readBits(1)&&e.skipBits(24),e.readBits(1)&&e.skipBits(8*(e.readBits(10)+1));const h=e.readBits(5)+1,p=Cm[e.readBits(4)],m=e.readBits(8)+1;let g=0;if(e.readBits(1)&&(m>2&&e.skipBits(1),m>6&&e.skipBits(1),e.readBits(1))){const w=e.readBits(2)+1<<2;g=e.readBits(w)}return c===0||e.getBitsLeft()<0?o:{frameSize:a,asset:{sampleRate:p,numberOfChannels:m,sampleCount:Math.round(u*p/c),channelLayout:g,pcmResolution:h}}},Mm=t=>{if(t.length<Ml)return null;const e=Ie(t),n=e.getUint32(0);if(n===0)return null;const r=new Ee(t);r.seekToByte(13);const i=r.readBits(2);r.skipBits(5);const s=r.readBits(1),a=r.readBits(6);r.skipBits(14),r.skipBits(1),r.skipBits(3);const o=r.readBits(16);let c=null;return o!==0?c=Bm(o):a<Vs.length&&(c=Vs[a]+s),{sampleRate:n,maxBitrate:e.getUint32(4),avgBitrate:e.getUint32(8),pcmSampleDepth:t[12],sampleCount:Im[i],channelLayout:o,numberOfChannels:c}},Bm=t=>Ja(t)+Ja(t&_m);const Dl=["avc","hevc","vp9","av1","vp8","prores"],js=["pcm-s16","pcm-s16be","pcm-s24","pcm-s24be","pcm-s32","pcm-s32be","pcm-f32","pcm-f32be","pcm-f64","pcm-f64be","pcm-u8","pcm-s8","ulaw","alaw"],Nl=[...["aac","opus","mp3","vorbis","flac","ac3","eac3","dts"],...js],Ll=[{maxMacroblocks:99,maxBitrate:64e3,maxDpbMbs:396,level:10},{maxMacroblocks:396,maxBitrate:192e3,maxDpbMbs:900,level:11},{maxMacroblocks:396,maxBitrate:384e3,maxDpbMbs:2376,level:12},{maxMacroblocks:396,maxBitrate:768e3,maxDpbMbs:2376,level:13},{maxMacroblocks:396,maxBitrate:2e6,maxDpbMbs:2376,level:20},{maxMacroblocks:792,maxBitrate:4e6,maxDpbMbs:4752,level:21},{maxMacroblocks:1620,maxBitrate:4e6,maxDpbMbs:8100,level:22},{maxMacroblocks:1620,maxBitrate:1e7,maxDpbMbs:8100,level:30},{maxMacroblocks:3600,maxBitrate:14e6,maxDpbMbs:18e3,level:31},{maxMacroblocks:5120,maxBitrate:2e7,maxDpbMbs:20480,level:32},{maxMacroblocks:8192,maxBitrate:2e7,maxDpbMbs:32768,level:40},{maxMacroblocks:8192,maxBitrate:5e7,maxDpbMbs:32768,level:41},{maxMacroblocks:8704,maxBitrate:5e7,maxDpbMbs:34816,level:42},{maxMacroblocks:22080,maxBitrate:135e6,maxDpbMbs:110400,level:50},{maxMacroblocks:36864,maxBitrate:24e7,maxDpbMbs:184320,level:51},{maxMacroblocks:36864,maxBitrate:24e7,maxDpbMbs:184320,level:52},{maxMacroblocks:139264,maxBitrate:24e7,maxDpbMbs:696320,level:60},{maxMacroblocks:139264,maxBitrate:48e7,maxDpbMbs:696320,level:61},{maxMacroblocks:139264,maxBitrate:8e8,maxDpbMbs:696320,level:62}],Jr=[{maxPictureSize:36864,maxBitrate:2e5,level:10},{maxPictureSize:73728,maxBitrate:8e5,level:11},{maxPictureSize:122880,maxBitrate:18e5,level:20},{maxPictureSize:245760,maxBitrate:36e5,level:21},{maxPictureSize:552960,maxBitrate:72e5,level:30},{maxPictureSize:983040,maxBitrate:12e6,level:31},{maxPictureSize:2228224,maxBitrate:18e6,level:40},{maxPictureSize:2228224,maxBitrate:3e7,level:41},{maxPictureSize:8912896,maxBitrate:6e7,level:50},{maxPictureSize:8912896,maxBitrate:12e7,level:51},{maxPictureSize:8912896,maxBitrate:18e7,level:52},{maxPictureSize:35651584,maxBitrate:18e7,level:60},{maxPictureSize:35651584,maxBitrate:24e7,level:61},{maxPictureSize:35651584,maxBitrate:48e7,level:62}],Ol=".01.01.01.01.00",Ul=".0.110.01.01.01.0",To=["ap4x","ap4h","apch","apcn","apcs","apco"],zl=["dtsc","dtsh","dtsl","dtse"],So=t=>{const{codec:e,codecDescription:n,colorSpace:r,avcCodecInfo:i,hevcCodecInfo:s,vp9CodecInfo:a,av1CodecInfo:o,proresFormat:c}=t;if(e==="avc"){if(R(t.avcType!==null),i){const u=new Uint8Array([i.avcProfileIndication,i.profileCompatibility,i.avcLevelIndication]);return`avc${t.avcType}.${Ci(u)}`}if(!n||n.byteLength<4)throw new TypeError("AVC decoder description is not provided or is not at least 4 bytes long.");return`avc${t.avcType}.${Ci(n.subarray(1,4))}`}else if(e==="hevc"){let u,l,f,d,h,p;if(s)u=s.generalProfileSpace,l=s.generalProfileIdc,f=sl(s.generalProfileCompatibilityFlags),d=s.generalTierFlag,h=s.generalLevelIdc,p=[...s.generalConstraintIndicatorFlags];else{if(!n||n.byteLength<23)throw new TypeError("HEVC decoder description is not provided or is not at least 23 bytes long.");const g=Ie(n),w=g.getUint8(1);u=w>>6&3,l=w&31,f=sl(g.getUint32(2)),d=w>>5&1,h=g.getUint8(12),p=[];for(let y=0;y<6;y++)p.push(g.getUint8(6+y))}let m="hev1.";for(m+=["","A","B","C"][u]+l,m+=".",m+=f.toString(16).toUpperCase(),m+=".",m+=d===0?"L":"H",m+=h;p.length>0&&p[p.length-1]===0;)p.pop();return p.length>0&&(m+=".",m+=p.map(g=>g.toString(16).toUpperCase()).join(".")),m}else{if(e==="vp8")return"vp8";if(e==="vp9"){if(!a){const y=t.width*t.height;let b=Mt(Jr).level;for(const v of Jr)if(y<=v.maxPictureSize){b=v.level;break}return`vp09.00.${b.toString().padStart(2,"0")}.08`}const u=a.profile.toString().padStart(2,"0"),l=a.level.toString().padStart(2,"0"),f=a.bitDepth.toString().padStart(2,"0"),d=a.chromaSubsampling.toString().padStart(2,"0"),h=a.colourPrimaries.toString().padStart(2,"0"),p=a.transferCharacteristics.toString().padStart(2,"0"),m=a.matrixCoefficients.toString().padStart(2,"0"),g=a.videoFullRangeFlag.toString().padStart(2,"0");let w=`vp09.${u}.${l}.${f}.${d}`;return w+=`.${h}.${p}.${m}.${g}`,w.endsWith(Ol)&&(w=w.slice(0,-Ol.length)),w}else if(e==="av1"){if(!o){const v=t.width*t.height;let k=Mt(Jr).level;for(const A of Jr)if(v<=A.maxPictureSize){k=A.level;break}return`av01.0.${k.toString().padStart(2,"0")}M.08`}const u=o.profile,l=o.level.toString().padStart(2,"0"),f=o.tier?"H":"M",d=o.bitDepth.toString().padStart(2,"0"),h=o.monochrome?"1":"0",p=100*o.chromaSubsamplingX+10*o.chromaSubsamplingY+1*(o.chromaSubsamplingX&&o.chromaSubsamplingY?o.chromaSamplePosition:0),m=r?.primaries?qa[r.primaries]:1,g=r?.transfer?Xa[r.transfer]:1,w=r?.matrix?Ga[r.matrix]:1,y=r?.fullRange?1:0;let b=`av01.${u}.${l}${f}.${d}`;return b+=`.${h}.${p.toString().padStart(3,"0")}`,b+=`.${m.toString().padStart(2,"0")}`,b+=`.${g.toString().padStart(2,"0")}`,b+=`.${w.toString().padStart(2,"0")}`,b+=`.${y}`,b.endsWith(Ul)&&(b=b.slice(0,-Ul.length)),b}else{if(e==="prores")return c??"apch";e!==null&&Is(e)}}throw new TypeError(`Unhandled codec '${e}'.`)},Hl=t=>{switch(t.codec){case"avc":{let e=t.avcCodecInfo?.sequenceParameterSets[0];if(!e&&t.codecDescription&&(e=vl(t.codecDescription)?.sequenceParameterSets[0]),e){const n=Us(e);if(n)return{primaries:Mn[n.colourPrimaries],transfer:Bn[n.transferCharacteristics],matrix:Rn[n.matrixCoefficients],fullRange:!!n.fullRangeFlag}}}break;case"hevc":{let e=t.hevcCodecInfo?.arrays.find(n=>n.nalUnitType===Ge.SPS_NUT)?.nalUnits[0];if(!e&&t.codecDescription&&(e=sm(t.codecDescription)?.arrays.find(n=>n.nalUnitType===Ge.SPS_NUT)?.nalUnits[0]),e){const n=yo(e);if(n)return{primaries:Mn[n.colourPrimaries],transfer:Bn[n.transferCharacteristics],matrix:Rn[n.matrixCoefficients],fullRange:!!n.fullRangeFlag}}}break;case"vp8":break;case"vp9":if(t.vp9CodecInfo)return{primaries:Mn[t.vp9CodecInfo.colourPrimaries],transfer:Bn[t.vp9CodecInfo.transferCharacteristics],matrix:Rn[t.vp9CodecInfo.matrixCoefficients],fullRange:!!t.vp9CodecInfo.videoFullRangeFlag};break;case"av1":if(t.av1CodecInfo)return{primaries:Mn[t.av1CodecInfo.colourPrimaries],transfer:Bn[t.av1CodecInfo.transferCharacteristics],matrix:Rn[t.av1CodecInfo.matrixCoefficients],fullRange:!!t.av1CodecInfo.videoFullRangeFlag};break;case"prores":if(t.proresCodecInfo)return{primaries:Mn[t.proresCodecInfo.colourPrimaries],transfer:Bn[t.proresCodecInfo.transferCharacteristics],matrix:Rn[t.proresCodecInfo.matrixCoefficients],fullRange:t.proresCodecInfo.fullRange};break}return{primaries:void 0,transfer:void 0,matrix:void 0,fullRange:void 0}},Po=t=>{const{codec:e,codecDescription:n,aacCodecInfo:r,dtsFormat:i}=t;if(e==="aac"){if(!r)throw new TypeError("AAC codec info must be provided.");if(r.isMpeg2)return"mp4a.67";{let s;return r.objectType!==null?s=r.objectType:s=ml(n).objectType,`mp4a.40.${s}`}}else{if(e==="mp3")return"mp3";if(e==="opus")return"opus";if(e==="vorbis")return"vorbis";if(e==="flac")return"flac";if(e==="ac3")return"ac-3";if(e==="eac3")return"ec-3";if(e==="dts")return i??"dtsc";if(e&&js.includes(e))return e}throw new TypeError(`Unhandled codec '${e}'.`)},qs=48e3,Vl=/^pcm-([usf])(\d+)(be)?$/,Rm=t=>{if(R(js.includes(t)),t==="ulaw")return{dataType:"ulaw",sampleSize:1,littleEndian:!0,silentValue:255};if(t==="alaw")return{dataType:"alaw",sampleSize:1,littleEndian:!0,silentValue:213};const e=Vl.exec(t);R(e);let n;e[1]==="u"?n="unsigned":e[1]==="s"?n="signed":n="float";const r=Number(e[2])/8,i=e[3]!=="be",s=t==="pcm-u8"?2**7:0;return{dataType:n,sampleSize:r,littleEndian:i,silentValue:s}},Di=t=>t.startsWith("avc1")||t.startsWith("avc3")?"avc":t.startsWith("hev1")||t.startsWith("hvc1")?"hevc":t==="vp8"?"vp8":t.startsWith("vp09")?"vp9":t.startsWith("av01")?"av1":To.includes(t)?"prores":t==="mp3"||t==="mp4a.69"||t==="mp4a.6B"||t==="mp4a.6b"||t==="mp4a.40.34"?"mp3":t.startsWith("mp4a.40.")||t==="mp4a.67"?"aac":t==="opus"?"opus":t==="vorbis"?"vorbis":t==="flac"?"flac":t==="ac-3"||t==="ac3"?"ac3":t==="ec-3"||t==="eac3"?"eac3":zl.includes(t)?"dts":t==="ulaw"?"ulaw":t==="alaw"?"alaw":Vl.test(t)?t:t==="webvtt"?"webvtt":null;const Tr=4,Fm=[44100,48e3,32e3],Dm=[-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,32,40,48,56,64,80,96,112,128,160,192,224,256,320,-1,-1,32,48,56,64,80,96,112,128,160,192,224,256,320,384,-1,-1,32,64,96,128,160,192,224,256,288,320,352,384,416,448,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,8,16,24,32,40,48,56,64,80,96,112,128,144,160,-1,-1,8,16,24,32,40,48,56,64,80,96,112,128,144,160,-1,-1,32,48,56,64,80,96,112,128,144,160,176,192,224,256,-1],Wl=1483304551,jl=1231971951,Nm=(t,e,n,r,i)=>e===0?0:e===1?Math.floor(144*n/(r<<t))+i:e===2?Math.floor(144*n/r)+i:(Math.floor(12*n/r)+i)*4,Lm=(t,e,n,r)=>e===0?0:e===1?144*n/(r<<t):e===2?144*n/r:12*n/r*4,ql=(t,e)=>t===3?e===3?21:36:e===3?13:21,_o=(t,e)=>{const n=t>>>24,r=t>>>16&255,i=t>>>8&255,s=t&255;if(n!==255&&r!==255&&i!==255&&s!==255)return{header:null,bytesAdvanced:4};if(n!==255)return{header:null,bytesAdvanced:1};if((r&224)!==224)return{header:null,bytesAdvanced:1};let a=0,o=0;r&16?a=r&8?0:1:(a=1,o=1);const c=r>>3&3,u=r>>1&3,l=i>>4&15,f=(i>>2&3)%3,d=i>>1&1,h=s>>6&3,p=s>>4&3,m=s>>3&1,g=s>>2&1,w=s&3,y=Dm[a*16*4+u*16+l];if(y===-1)return{header:null,bytesAdvanced:1};const b=y*1e3,v=Fm[f]>>a+o,k=Nm(a,u,b,v,d);if(e!==null&&e<k)return{header:null,bytesAdvanced:1};let A;return c===3?A=u===3?384:1152:u===3?A=384:u===2?A=1152:A=576,{header:{totalSize:k,mpegVersionId:c,lowSamplingFrequency:a,layer:u,bitrate:b,frequencyIndex:f,sampleRate:v,channel:h,modeExtension:p,copyright:m,original:g,emphasis:w,audioSamplesInFrame:A},bytesAdvanced:1}},Eo=t=>{let e=2130706432,n=0;for(;e!==0;)n>>=1,n|=t&e,e>>=8;return n};var Xs;(function(t){t[t.FrameCount=1]="FrameCount",t[t.FileSize=2]="FileSize",t[t.Toc=4]="Toc"})(Xs||(Xs={}));const Ni=t=>t===3?1:2;class Dn{constructor(e){this.input=e}dispose(){}}const Ut=new Uint8Array(0);class Qe{constructor(e,n,r,i,s=-1,a,o){if(this.data=e,this.type=n,this.timestamp=r,this.duration=i,this.sequenceNumber=s,e===Ut&&a===void 0)throw new Error("Internal error: byteLength must be explicitly provided when constructing metadata-only packets.");if(a===void 0&&(a=e.byteLength),!(e instanceof Uint8Array))throw new TypeError("data must be a Uint8Array.");if(n!=="key"&&n!=="delta")throw new TypeError('type must be either "key" or "delta".');if(!Number.isFinite(r))throw new TypeError("timestamp must be a number.");if(!Number.isFinite(i)||i<0)throw new TypeError("duration must be a non-negative number.");if(!Number.isFinite(s))throw new TypeError("sequenceNumber must be a number.");if(!Number.isInteger(a)||a<0)throw new TypeError("byteLength must be a non-negative integer.");if(o!==void 0&&(typeof o!="object"||!o))throw new TypeError("sideData, when provided, must be an object.");if(o?.alpha!==void 0&&!(o.alpha instanceof Uint8Array))throw new TypeError("sideData.alpha, when provided, must be a Uint8Array.");if(o?.alphaByteLength!==void 0&&(!Number.isInteger(o.alphaByteLength)||o.alphaByteLength<0))throw new TypeError("sideData.alphaByteLength, when provided, must be a non-negative integer.");this.byteLength=a,this.sideData=o??{},this.sideData.alpha&&this.sideData.alphaByteLength===void 0&&(this.sideData.alphaByteLength=this.sideData.alpha.byteLength)}get isMetadataOnly(){return this.data===Ut}get microsecondTimestamp(){return Math.trunc(Qr*this.timestamp)}get microsecondDuration(){return Math.trunc(Qr*this.duration)}toEncodedVideoChunk(){if(this.isMetadataOnly)throw new TypeError("Metadata-only packets cannot be converted to a video chunk.");if(typeof EncodedVideoChunk>"u")throw new Error("EncodedVideoChunk is not available in this environment.");return new EncodedVideoChunk({data:this.data,type:this.type,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}alphaToEncodedVideoChunk(e=this.type){if(!this.sideData.alpha)throw new TypeError("This packet does not contain alpha side data.");if(this.isMetadataOnly)throw new TypeError("Metadata-only packets cannot be converted to a video chunk.");if(typeof EncodedVideoChunk>"u")throw new Error("EncodedVideoChunk is not available in this environment.");return new EncodedVideoChunk({data:this.sideData.alpha,type:e,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}toEncodedAudioChunk(){if(this.isMetadataOnly)throw new TypeError("Metadata-only packets cannot be converted to an audio chunk.");if(typeof EncodedAudioChunk>"u")throw new Error("EncodedAudioChunk is not available in this environment.");return new EncodedAudioChunk({data:this.data,type:this.type,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration})}static fromEncodedChunk(e,n){if(!(e instanceof EncodedVideoChunk||e instanceof EncodedAudioChunk))throw new TypeError("chunk must be an EncodedVideoChunk or EncodedAudioChunk.");const r=new Uint8Array(e.byteLength);return e.copyTo(r),new Qe(r,e.type,e.timestamp/1e6,(e.duration??0)/1e6,void 0,void 0,n)}clone(e){if(e!==void 0&&(typeof e!="object"||e===null))throw new TypeError("options, when provided, must be an object.");if(e?.data!==void 0&&!(e.data instanceof Uint8Array))throw new TypeError("options.data, when provided, must be a Uint8Array.");if(e?.type!==void 0&&e.type!=="key"&&e.type!=="delta")throw new TypeError('options.type, when provided, must be either "key" or "delta".');if(e?.timestamp!==void 0&&!Number.isFinite(e.timestamp))throw new TypeError("options.timestamp, when provided, must be a number.");if(e?.duration!==void 0&&!Number.isFinite(e.duration))throw new TypeError("options.duration, when provided, must be a number.");if(e?.sequenceNumber!==void 0&&!Number.isFinite(e.sequenceNumber))throw new TypeError("options.sequenceNumber, when provided, must be a number.");if(e?.sideData!==void 0&&(typeof e.sideData!="object"||e.sideData===null))throw new TypeError("options.sideData, when provided, must be an object.");return new Qe(e?.data??this.data,e?.type??this.type,e?.timestamp??this.timestamp,e?.duration??this.duration,e?.sequenceNumber??this.sequenceNumber,this.byteLength,e?.sideData??this.sideData)}}const Om=t=>{let n=(t.hasVideo?"video/":t.hasAudio?"audio/":"application/")+(t.isQuickTime?"quicktime":"mp4");if(t.codecStrings.length>0){const r=[...new Set(t.codecStrings)];n+=`; codecs="${r.join(", ")}"`}return n},Xl=t=>{const e=Ie(t);let n=0;const r=e.getUint8(n);n+=1,n+=3;const i=Ci(t.subarray(n,n+16));n+=16;let s=null;if(r>0){const o=e.getUint32(n);if(n+=4,o>0){s=[];for(let c=0;c<o;c++)s.push(Ci(t.subarray(n,n+16))),n+=16}}const a=e.getUint32(n);return n+=4,{systemId:i,keyIds:s,data:t.slice(n,n+a)}},Gl=(t,e)=>t.systemId===e.systemId&&Qh(t.data,e.data);const ei=8,Li=16,nr=t=>{let e=ae(t);const n=Ve(t,4);let r=8;e===1&&(e=Ht(t),r=16);const s=e-r;return s<0?null:{name:n,totalSize:e,headerSize:r,contentSize:s}},Sr=t=>Mr(t)/65536,Co=t=>Mr(t)/1073741824,Io=t=>{let e=0;for(let n=0;n<4;n++){e<<=7;const r=de(t);if(e|=r&127,(r&128)===0)break}return e},mn=t=>{let e=$e(t);return t.skip(2),e=Math.min(e,t.remainingLength),Bt.decode(me(t,e))},Um=t=>{const e=nr(t);if(!e||e.name!=="data"||t.remainingLength<8)return null;const n=ae(t);t.skip(4);const r=me(t,e.contentSize-8);switch(n){case 1:return Bt.decode(r);case 2:return new TextDecoder("utf-16be").decode(r);case 13:return new Fs(r,"image/jpeg");case 14:return new Fs(r,"image/png");case 27:return new Fs(r,"image/bmp");default:return r}};const pn=16,Nn=new Uint32Array(256),ti=new Uint32Array(256),ni=new Uint32Array(256),ri=new Uint32Array(256),ii=new Uint32Array(256),lt=new Uint32Array(256),$l=new Uint32Array(10);let Ql=!1;const zm=()=>{const t=new Uint8Array(256),e=new Uint8Array(256),n=new Uint8Array(256);for(let s=0,a=1;s<256;s++)n[s]=a,e[a]=s,a=a^a<<1^(a&128?283:0);const r=(s,a)=>s&&a?n[(e[s]+e[a])%255]:0;t[0]=99;for(let s=1;s<256;s++){const a=n[255-e[s]];let o=a^a<<1^a<<2^a<<3^a<<4;o=o>>>8^o&255^99,t[s]=o}for(let s=0;s<256;s++){const a=t[s],o=t.indexOf(s);Nn[s]=a<<24|a<<16|a<<8|a,lt[s]=o<<24|o<<16|o<<8|o;const c=r(o,14),u=r(o,9),l=r(o,13),f=r(o,11),d=c<<24|u<<16|l<<8|f;ti[s]=d,ni[s]=d>>>8|d<<24,ri[s]=d>>>16|d<<16,ii[s]=d>>>24|d<<8}let i=1;for(let s=0;s<10;s++)$l[s]=i<<24,i=i<<1^(i&128?283:0);Ql=!0};class Yl{constructor(){this.roundkey=new Uint32Array(44),this.iv=new Uint32Array(pn/Uint32Array.BYTES_PER_ELEMENT),this.in=new Uint8Array(pn),this.out=new Uint8Array(pn),this.inView=new DataView(this.in.buffer),this.outView=new DataView(this.out.buffer)}init({key:e,iv:n}){R(e.byteLength===16),R(n.byteLength===16),Ql||zm();const r=new DataView(e.buffer,e.byteOffset,e.byteLength),i=new DataView(n.buffer,n.byteOffset,n.byteLength);this.roundkey[0]=r.getUint32(0,!1),this.roundkey[1]=r.getUint32(4,!1),this.roundkey[2]=r.getUint32(8,!1),this.roundkey[3]=r.getUint32(12,!1),this.iv[0]=i.getUint32(0,!1),this.iv[1]=i.getUint32(4,!1),this.iv[2]=i.getUint32(8,!1),this.iv[3]=i.getUint32(12,!1);for(let s=4;s<44;s+=4){const a=this.roundkey[s-1];this.roundkey[s]=this.roundkey[s-4]^Nn[a>>>16&255]&4278190080^Nn[a>>>8&255]&16711680^Nn[a>>>0&255]&65280^Nn[a>>>24&255]&255^$l[s/4-1],this.roundkey[s+1]=this.roundkey[s-3]^this.roundkey[s],this.roundkey[s+2]=this.roundkey[s-2]^this.roundkey[s+1],this.roundkey[s+3]=this.roundkey[s-1]^this.roundkey[s+2]}for(let s=0,a=40;s<a;s+=4,a-=4)for(let o=0;o<4;o++){const c=this.roundkey[s+o];this.roundkey[s+o]=this.roundkey[a+o],this.roundkey[a+o]=c}for(let s=4;s<40;s+=4)for(let a=0;a<4;a++){const o=this.roundkey[s+a];this.roundkey[s+a]=ti[Nn[o>>>24&255]&255]^ni[Nn[o>>>16&255]&255]^ri[Nn[o>>>8&255]&255]^ii[Nn[o>>>0&255]&255]}}decrypt(){let e=this.inView.getUint32(0,!1)^this.roundkey[0],n=this.inView.getUint32(4,!1)^this.roundkey[1],r=this.inView.getUint32(8,!1)^this.roundkey[2],i=this.inView.getUint32(12,!1)^this.roundkey[3];const s=this.inView.getUint32(0,!1),a=this.inView.getUint32(4,!1),o=this.inView.getUint32(8,!1),c=this.inView.getUint32(12,!1);let u,l,f,d;for(let w=1;w<10;w++){const y=w*4;u=ti[e>>>24]^ni[i>>>16&255]^ri[r>>>8&255]^ii[n&255]^this.roundkey[y],l=ti[n>>>24]^ni[e>>>16&255]^ri[i>>>8&255]^ii[r&255]^this.roundkey[y+1],f=ti[r>>>24]^ni[n>>>16&255]^ri[e>>>8&255]^ii[i&255]^this.roundkey[y+2],d=ti[i>>>24]^ni[r>>>16&255]^ri[n>>>8&255]^ii[e&255]^this.roundkey[y+3],e=u,n=l,r=f,i=d}const h=lt[e>>>24&255]&4278190080^lt[i>>>16&255]&16711680^lt[r>>>8&255]&65280^lt[n>>>0&255]&255^this.roundkey[40],p=lt[n>>>24&255]&4278190080^lt[e>>>16&255]&16711680^lt[i>>>8&255]&65280^lt[r>>>0&255]&255^this.roundkey[41],m=lt[r>>>24&255]&4278190080^lt[n>>>16&255]&16711680^lt[e>>>8&255]&65280^lt[i>>>0&255]&255^this.roundkey[42],g=lt[i>>>24&255]&4278190080^lt[r>>>16&255]&16711680^lt[n>>>8&255]&65280^lt[e>>>0&255]&255^this.roundkey[43];this.outView.setUint32(0,h^this.iv[0],!1),this.outView.setUint32(4,p^this.iv[1],!1),this.outView.setUint32(8,m^this.iv[2],!1),this.outView.setUint32(12,g^this.iv[3],!1),this.iv[0]=s,this.iv[1]=a,this.iv[2]=o,this.iv[3]=c}}const Hm=(t,e,n)=>{let r=!1,i=0;const s=2**16,a=16,o=new Yl;return new ReadableStream({pull:async c=>{r||(o.init(await e()),r=!0);const u=s+a;let l=t.requestSliceRange(i,0,u);if(ie(l)&&(l=await l),!l||l.length===0)throw new Error("Invalid ciphertext.");const f=l.length;if(f%16!==0)throw new Error("Invalid ciphertext.");const d=f===u?f-a:f,h=me(l,d),p=new Uint8Array(d);for(let m=0;m<d;m+=16)o.in.set(h.subarray(m,m+16)),o.decrypt(),p.set(o.out,m);if(d<f)c.enqueue(p),i+=d;else{const m=p[d-1];if(m===0||m>16)throw new Error("Invalid PKCS#7 padding. Incorrect key or corrupted data.");const g=p.subarray(0,d-m);c.enqueue(g),c.close(),n()}},cancel:()=>{n()}})};class Mo extends Dn{constructor(e){super(e),this.moovSlice=null,this.currentTrack=null,this.tracks=[],this.metadataPromise=null,this.movieTimescale=-1,this.movieDurationInTimescale=-1,this.isQuickTime=!1,this.metadataTags={},this.currentMetadataKeys=null,this.isFragmented=!1,this.fragmentTrackDefaults=[],this.psshBoxes=[],this.currentFragment=null,this.lastReadFragment=null,this.decryptionKeyCache=new Map,this.reader=e._reader}async getTrackBackings(){return await this.readMetadata(),this.tracks.map(e=>e.trackBacking)}async getMimeType(){await this.readMetadata();const e=await this.getTrackBackings(),n=await Promise.all(e.map(r=>r.getDecoderConfig().then(i=>i?.codec??null)));return Om({isQuickTime:this.isQuickTime,hasVideo:this.tracks.some(r=>r.info?.type==="video"),hasAudio:this.tracks.some(r=>r.info?.type==="audio"),codecStrings:n.filter(Boolean)})}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}readMetadata(){return this.metadataPromise??=(async()=>{let e=0,n=!1,r=!1;for(;;){let i=this.reader.requestSliceRange(e,ei,Li);if(ie(i)&&(i=await i),!i)break;const s=e,a=nr(i);if(!a)break;if(a.name==="ftyp"||a.name==="styp"){const o=Ve(i,4);this.isQuickTime=o==="qt "}else if(a.name==="moov"){let o=this.reader.requestSlice(i.filePos,a.contentSize);if(ie(o)&&(o=await o),!o)break;this.moovSlice=o,this.readContiguousBoxes(this.moovSlice);for(const c of this.tracks){const u=c.editListPreviousSegmentDurations/this.movieTimescale;c.editListOffset-=Math.round(u*c.timescale)}n=this.isFragmented&&this.reader.fileSize!==null&&this.reader.fileSize>s+a.totalSize,r=!0;break}else if(a.name==="moof"){if(!this.input._initInput)throw new Error('"moof" box encountered with no "moov" box present; this file is likely a Segment as described in ISO/IEC 14496-12 Section 8.16. A separate init file that contains a "moov" box is required to read this file, please provide it using InputOptions.initInput.');await this.copyMetadataFromInitInput(this.input._initInput),n=!1,r=!0;break}e=s+a.totalSize}if(!r&&this.input._initInput&&await this.copyMetadataFromInitInput(this.input._initInput),n){R(this.reader.fileSize!==null);let i=this.reader.requestSlice(this.reader.fileSize-4,4);ie(i)&&(i=await i),R(i);const s=ae(i),a=this.reader.fileSize-s;if(a>=0&&a<=this.reader.fileSize-Li){let o=this.reader.requestSliceRange(a,ei,Li);if(ie(o)&&(o=await o),o){const c=nr(o);if(c&&c.name==="mfra"){let u=this.reader.requestSlice(o.filePos,c.contentSize);ie(u)&&(u=await u),u&&this.readContiguousBoxes(u)}}}}})()}async copyMetadataFromInitInput(e){const n=await e._getDemuxer();if(n.constructor!==Mo)throw new Error("Init input must match the input's format.");await n.readMetadata(),this.movieTimescale=n.movieTimescale,this.movieDurationInTimescale=n.movieDurationInTimescale,this.metadataTags=n.metadataTags,this.isFragmented=!0,this.fragmentTrackDefaults=n.fragmentTrackDefaults,this.psshBoxes=n.psshBoxes;for(const r of n.tracks){const i={id:r.id,demuxer:this,trackBacking:null,disposition:r.disposition,timescale:r.timescale,durationInMediaTimescale:r.durationInMediaTimescale,durationInMovieTimescale:r.durationInMovieTimescale,rotation:r.rotation,internalCodecId:r.internalCodecId,name:r.name,languageCode:r.languageCode,sampleTableByteOffset:null,sampleTable:null,fragmentLookupTable:[],currentFragmentState:null,fragmentPositionCache:[],editListPreviousSegmentDurations:r.editListPreviousSegmentDurations,editListOffset:r.editListOffset,encryptionInfo:r.encryptionInfo,encryptionAuxInfo:null,frmaCodecString:null,info:r.info};if(r.trackBacking){if(R(i.info),i.info.type==="video"&&i.info.width!==-1){const s=i;i.trackBacking=new Zl(s),this.tracks.push(i)}else if(i.info.type==="audio"&&i.info.numberOfChannels!==-1){const s=i;i.trackBacking=new Jl(s),this.tracks.push(i)}}}}getSampleTableForTrack(e){if(e.sampleTable)return e.sampleTable;const n={sampleTimingEntries:[],sampleCompositionTimeOffsets:[],sampleSizes:[],keySampleIndices:null,chunkOffsets:[],sampleToChunk:[],presentationTimestamps:null,presentationTimestampIndexMap:null};if(e.sampleTable=n,e.sampleTableByteOffset===null)return n;R(this.moovSlice);const r=this.moovSlice.slice(e.sampleTableByteOffset);if(this.currentTrack=e,this.traverseBox(r),this.currentTrack=null,e.info?.type==="audio"&&e.info.codec&&js.includes(e.info.codec)&&n.sampleCompositionTimeOffsets.length===0){R(e.info?.type==="audio");const s=Rm(e.info.codec),a=[],o=[];for(let c=0;c<n.sampleToChunk.length;c++){const u=n.sampleToChunk[c],l=n.sampleToChunk[c+1],f=(l?l.startChunkIndex:n.chunkOffsets.length)-u.startChunkIndex;for(let d=0;d<f;d++){const h=u.startSampleIndex+d*u.samplesPerChunk,p=h+u.samplesPerChunk,m=_e(n.sampleTimingEntries,h,S=>S.startIndex),g=n.sampleTimingEntries[m],w=_e(n.sampleTimingEntries,p,S=>S.startIndex),y=n.sampleTimingEntries[w],b=g.startDecodeTimestamp+(h-g.startIndex)*g.delta,k=y.startDecodeTimestamp+(p-y.startIndex)*y.delta-b,A=Mt(a);A&&A.delta===k?A.count++:a.push({startIndex:u.startChunkIndex+d,startDecodeTimestamp:b,count:1,delta:k});const T=u.samplesPerChunk*s.sampleSize*e.info.numberOfChannels;o.push(T)}u.startSampleIndex=u.startChunkIndex,u.samplesPerChunk=1}n.sampleTimingEntries=a,n.sampleSizes=o}if(n.sampleCompositionTimeOffsets.length>0){n.presentationTimestamps=[];for(const s of n.sampleTimingEntries)for(let a=0;a<s.count;a++)n.presentationTimestamps.push({presentationTimestamp:s.startDecodeTimestamp+a*s.delta,sampleIndex:s.startIndex+a});for(const s of n.sampleCompositionTimeOffsets)for(let a=0;a<s.count;a++){const o=s.startIndex+a,c=n.presentationTimestamps[o];c&&(c.presentationTimestamp+=s.offset)}n.presentationTimestamps.sort((s,a)=>s.presentationTimestamp-a.presentationTimestamp),n.presentationTimestampIndexMap=Array(n.presentationTimestamps.length).fill(-1);for(let s=0;s<n.presentationTimestamps.length;s++)n.presentationTimestampIndexMap[n.presentationTimestamps[s].sampleIndex]=s}return n}async readFragment(e){if(this.lastReadFragment?.moofOffset===e)return this.lastReadFragment;let n=this.reader.requestSliceRange(e,ei,Li);ie(n)&&(n=await n),R(n);const r=nr(n);R(r?.name==="moof");let i=this.reader.requestSlice(e,r.totalSize);ie(i)&&(i=await i),R(i),this.traverseBox(i);const s=this.lastReadFragment;R(s&&s.moofOffset===e);for(const[,a]of s.trackData){const o=a.track,{fragmentPositionCache:c}=o;if(!a.startTimestampIsFinal){const l=o.fragmentLookupTable.find(f=>f.moofOffset===s.moofOffset);if(l)Ro(a,l.timestamp);else{const f=_e(c,s.moofOffset-1,d=>d.moofOffset);if(f!==-1){const d=c[f];Ro(a,d.endTimestamp)}}a.startTimestampIsFinal=!0}const u=_e(c,a.startTimestamp,l=>l.startTimestamp);if((u===-1||c[u].moofOffset!==s.moofOffset)&&c.splice(u+1,0,{moofOffset:s.moofOffset,startTimestamp:a.startTimestamp,endTimestamp:a.endTimestamp}),a.encryptionAuxInfo&&o.encryptionInfo){const l=await nu(this.reader,o.encryptionInfo,a.encryptionAuxInfo);for(let f=0;f<Math.min(a.samples.length,l.length);f++){const d=l[f];a.samples[f].encryption=d}}}return s}readContiguousBoxes(e){const n=e.filePos;for(;e.filePos-n<=e.length-ei&&this.traverseBox(e););}*iterateContiguousBoxes(e){const n=e.filePos;for(;e.filePos-n<=e.length-ei;){const r=e.filePos,i=nr(e);if(!i)break;yield{boxInfo:i,slice:e},e.filePos=r+i.totalSize}}traverseBox(e){const n=e.filePos,r=nr(e);if(!r)return!1;const i=e.filePos,s=n+r.totalSize;switch(r.name){case"mdia":case"minf":case"dinf":case"mfra":case"edts":case"sinf":case"schi":this.readContiguousBoxes(e.slice(i,r.contentSize));break;case"mvhd":{const a=de(e);e.skip(3),a===1?(e.skip(16),this.movieTimescale=ae(e),this.movieDurationInTimescale=Ht(e)):(e.skip(8),this.movieTimescale=ae(e),this.movieDurationInTimescale=ae(e))}break;case"trak":{const a={id:-1,demuxer:this,trackBacking:null,disposition:{...Fn,primary:!1},info:null,timescale:-1,durationInMovieTimescale:-1,durationInMediaTimescale:-1,rotation:0,internalCodecId:null,name:null,languageCode:Tt,sampleTableByteOffset:-1,sampleTable:null,fragmentLookupTable:[],currentFragmentState:null,fragmentPositionCache:[],editListPreviousSegmentDurations:0,editListOffset:0,encryptionInfo:null,encryptionAuxInfo:null,frmaCodecString:null};if(this.currentTrack=a,this.readContiguousBoxes(e.slice(i,r.contentSize)),a.id!==-1&&a.timescale!==-1&&a.info!==null){if(a.info.type==="video"&&a.info.width!==-1){const o=a;a.trackBacking=new Zl(o),this.tracks.push(a)}else if(a.info.type==="audio"&&a.info.numberOfChannels!==-1){const o=a;a.trackBacking=new Jl(o),this.tracks.push(a)}}this.currentTrack=null}break;case"tkhd":{const a=this.currentTrack;if(!a)break;const o=de(e),u=!!(Hn(e)&1);if(a.disposition.default=u,o===0)e.skip(8),a.id=ae(e),e.skip(4),a.durationInMovieTimescale=ae(e);else if(o===1)e.skip(16),a.id=ae(e),e.skip(4),a.durationInMovieTimescale=Ht(e);else throw new Error(`Incorrect track header version ${o}.`);e.skip(16);const l=[Sr(e),Sr(e),Co(e),Sr(e),Sr(e),Co(e),Sr(e),Sr(e),Co(e)],f=Wa(Ka(qm(l),90));R(f===0||f===90||f===180||f===270),a.rotation=f}break;case"elst":{const a=this.currentTrack;if(!a)break;const o=de(e);e.skip(3);let c=!1,u=0;const l=ae(e);for(let f=0;f<l;f++){const d=o===1?Ht(e):ae(e),h=o===1?Tg(e):Mr(e),p=Sr(e);if(c){pe._warn("Unsupported edit list: multiple edits are not currently supported. Only using first edit.");break}if(h===-1){u+=d;continue}if(p!==1){pe._warn("Unsupported edit list entry: media rate must be 1.");break}a.editListPreviousSegmentDurations=u,a.editListOffset=h,c=!0}}break;case"mdhd":{const a=this.currentTrack;if(!a)break;const o=de(e);e.skip(3),o===0?(e.skip(8),a.timescale=ae(e),a.durationInMediaTimescale=ae(e)):o===1&&(e.skip(16),a.timescale=ae(e),a.durationInMediaTimescale=Ht(e));let c=$e(e);if(c>0){a.languageCode="";for(let u=0;u<3;u++)a.languageCode=String.fromCharCode(96+(c&31))+a.languageCode,c>>=5;ul(a.languageCode)||(a.languageCode=Tt)}}break;case"hdlr":{const a=this.currentTrack;if(!a)break;e.skip(8);const o=Ve(e,4);o==="vide"?a.info={type:"video",width:-1,height:-1,squarePixelWidth:-1,squarePixelHeight:-1,codec:null,codecDescription:null,colorSpace:{...il},avcType:null,avcCodecInfo:null,hevcCodecInfo:null,vp9CodecInfo:null,av1CodecInfo:null,proresCodecInfo:null,proresFormat:null}:o==="soun"&&(a.info={type:"audio",numberOfChannels:-1,sampleRate:-1,codec:null,codecDescription:null,aacCodecInfo:null,dtsFormat:null,pcmLittleEndian:!1,pcmSampleSize:null})}break;case"stbl":{const a=this.currentTrack;if(!a)break;a.sampleTableByteOffset=n,this.readContiguousBoxes(e.slice(i,r.contentSize))}break;case"stsd":{const a=this.currentTrack;if(!a||a.info===null||a.sampleTable)break;const o=de(e);e.skip(3);const c=ae(e);for(let u=0;u<c;u++){const l=e.filePos,f=nr(e);if(!f)break;a.internalCodecId=f.name;const d=f.name.toLowerCase();if(a.info.type==="video"){e.skip(24),a.info.width=$e(e),a.info.height=$e(e),a.info.squarePixelWidth=a.info.width,a.info.squarePixelHeight=a.info.height,e.skip(50),a.frmaCodecString=null,this.readContiguousBoxes(e.slice(e.filePos,l+f.totalSize-e.filePos));const h=d==="encv"?a.frmaCodecString:d;a.frmaCodecString=null,h==="avc1"||h==="avc3"?(a.info.codec="avc",a.info.avcType=h==="avc1"?1:3):h==="hvc1"||h==="hev1"?a.info.codec="hevc":h==="vp08"?a.info.codec="vp8":h==="vp09"?a.info.codec="vp9":h==="av01"?a.info.codec="av1":To.includes(d)?(a.info.codec="prores",a.info.proresFormat=d):h===null?pe._warn("Unknown encrypted video codec due to missing frma box."):pe._warn(`Unsupported video codec (sample entry type '${f.name}').`)}else{e.skip(8);const h=$e(e);e.skip(6);let p=$e(e),m=$e(e);e.skip(4);let g=ae(e)/65536,w=null;o===0&&h>0&&(h===1?(e.skip(4),m=8*ae(e),e.skip(8)):h===2&&(e.skip(4),g=ff(e),p=ae(e),e.skip(4),m=ae(e),w=ae(e),e.skip(8))),a.info.numberOfChannels=p,a.info.sampleRate=g,a.frmaCodecString=null,this.readContiguousBoxes(e.slice(e.filePos,l+f.totalSize-e.filePos));const y=d==="enca"?a.frmaCodecString:d;if(a.frmaCodecString=null,y!=="mp4a")if(y==="opus")a.info.codec="opus",a.info.sampleRate=qs;else if(y==="flac")a.info.codec="flac";else if(y==="ulaw")a.info.codec="ulaw";else if(y==="alaw")a.info.codec="alaw";else if(y==="ac-3")a.info.codec="ac3";else if(y==="ec-3")a.info.codec="eac3";else if(zl.includes(y))a.info.codec="dts",a.info.dtsFormat=y;else if(y==="twos")m===8?a.info.codec="pcm-s8":m===16?a.info.codec=a.info.pcmLittleEndian?"pcm-s16":"pcm-s16be":(pe._warn(`Unsupported sample size ${m} for codec 'twos'.`),a.info.codec=null);else if(y==="sowt")m===8?a.info.codec="pcm-s8":m===16?a.info.codec="pcm-s16":(pe._warn(`Unsupported sample size ${m} for codec 'sowt'.`),a.info.codec=null);else if(y==="raw ")a.info.codec="pcm-u8";else if(y==="in24")a.info.codec=a.info.pcmLittleEndian?"pcm-s24":"pcm-s24be";else if(y==="in32")a.info.codec=a.info.pcmLittleEndian?"pcm-s32":"pcm-s32be";else if(y==="fl32")a.info.codec=a.info.pcmLittleEndian?"pcm-f32":"pcm-f32be";else if(y==="fl64")a.info.codec=a.info.pcmLittleEndian?"pcm-f64":"pcm-f64be";else if(y==="ipcm"){const b=a.info.pcmSampleSize;a.info.pcmLittleEndian?b===16?a.info.codec="pcm-s16":b===24?a.info.codec="pcm-s24":b===32?a.info.codec="pcm-s32":(pe._warn(`Invalid ipcm sample size ${b}.`),a.info.codec=null):b===16?a.info.codec="pcm-s16be":b===24?a.info.codec="pcm-s24be":b===32?a.info.codec="pcm-s32be":(pe._warn(`Invalid ipcm sample size ${b}.`),a.info.codec=null)}else if(y==="fpcm"){const b=a.info.pcmSampleSize;a.info.pcmLittleEndian?b===32?a.info.codec="pcm-f32":b===64?a.info.codec="pcm-f64":(pe._warn(`Invalid fpcm sample size ${b}.`),a.info.codec=null):b===32?a.info.codec="pcm-f32be":b===64?a.info.codec="pcm-f64be":(pe._warn(`Invalid fpcm sample size ${b}.`),a.info.codec=null)}else if(y==="lpcm"&&w!==null){const b=m+7>>3,v=!!(w&1),k=!!(w&2),A=w&4?-1:0;m>0&&m<=64&&(v?m===32&&(a.info.codec=k?"pcm-f32be":"pcm-f32"):A&1<<b-1?b===1?a.info.codec="pcm-s8":b===2?a.info.codec=k?"pcm-s16be":"pcm-s16":b===3?a.info.codec=k?"pcm-s24be":"pcm-s24":b===4&&(a.info.codec=k?"pcm-s32be":"pcm-s32"):b===1&&(a.info.codec="pcm-u8")),a.info.codec===null&&pe._warn("Unsupported PCM format.")}else y===null?pe._warn("Unknown encrypted audio codec due to missing frma box."):pe._warn(`Unsupported audio codec (sample entry type '${f.name}').`)}e.filePos=l+f.totalSize}}break;case"frma":{const a=this.currentTrack;if(!a)break;const c=Ve(e,4).toLowerCase();a.frmaCodecString=c}break;case"schm":{const a=this.currentTrack;if(!a)break;e.skip(4);const o=Ve(e,4);o==="cenc"||o==="cens"||o==="cbcs"?a.encryptionInfo={scheme:o,defaultKid:null,defaultIsProtected:null,defaultPerSampleIvSize:null,defaultConstantIv:null,defaultCryptByteBlock:null,defaultSkipByteBlock:null}:pe._warn(`Unsupported encryption scheme '${o}'.`)}break;case"tenc":{const a=this.currentTrack;if(!a||!a.encryptionInfo)break;const o=de(e);e.skip(3),e.skip(1);const c=de(e);if(o>0?(a.encryptionInfo.defaultCryptByteBlock=c>>4,a.encryptionInfo.defaultSkipByteBlock=c&15):(a.encryptionInfo.defaultCryptByteBlock=0,a.encryptionInfo.defaultSkipByteBlock=0),a.encryptionInfo.defaultIsProtected=de(e)!==0,a.encryptionInfo.defaultPerSampleIvSize=de(e),a.encryptionInfo.defaultKid=Ci(me(e,16)),a.encryptionInfo.defaultIsProtected&&a.encryptionInfo.defaultPerSampleIvSize===0){const u=de(e),l=new Uint8Array(16);l.set(me(e,u),0),a.encryptionInfo.defaultConstantIv=l}}break;case"avcC":{const a=this.currentTrack;if(!a||(R(a.info),r.contentSize===0))break;a.info.codecDescription=me(e,r.contentSize)}break;case"hvcC":{const a=this.currentTrack;if(!a||(R(a.info),r.contentSize===0))break;a.info.codecDescription=me(e,r.contentSize)}break;case"vpcC":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="video"),e.skip(4);const o=de(e),c=de(e),u=de(e),l=u>>4,f=u>>1&7,d=u&1,h=de(e),p=de(e),m=de(e);a.info.vp9CodecInfo={profile:o,level:c,bitDepth:l,chromaSubsampling:f,videoFullRangeFlag:d,colourPrimaries:h,transferCharacteristics:p,matrixCoefficients:m}}break;case"av1C":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="video"),e.skip(1);const o=de(e),c=o>>5,u=o&31,l=de(e),f=l>>7,d=l>>6&1,h=l>>5&1,p=l>>4&1,m=l>>3&1,g=l>>2&1,w=l&3,y=c===2&&d?h?12:10:d?10:8;e.skip(1);const b=me(e,r.contentSize-4),v=wo(b);a.info.av1CodecInfo={profile:c,level:u,tier:f,bitDepth:y,monochrome:p,chromaSubsamplingX:m,chromaSubsamplingY:g,chromaSamplePosition:w,videoFullRangeFlag:v?.videoFullRangeFlag??0,colourPrimaries:v?.colourPrimaries??2,transferCharacteristics:v?.transferCharacteristics??2,matrixCoefficients:v?.matrixCoefficients??2}}break;case"colr":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="video");const o=Ve(e,4);if(o!=="nclx"&&o!=="nclc")break;const c=$e(e),u=$e(e),l=$e(e);let f;o==="nclx"&&(f=!!(de(e)&128)),a.info.colorSpace={primaries:Mn[c],transfer:Bn[u],matrix:Rn[l],fullRange:f}}break;case"pasp":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="video");const o=ae(e),c=ae(e);o>0&&c>0&&(o>c?a.info.squarePixelWidth=Math.round(a.info.width*o/c):a.info.squarePixelHeight=Math.round(a.info.height*c/o))}break;case"wave":this.readContiguousBoxes(e.slice(i,r.contentSize));break;case"esds":{const a=this.currentTrack;if(!a||a.info?.type!=="audio")break;e.skip(4);const o=de(e);R(o===3),Io(e),e.skip(2);const c=de(e),u=(c&128)!==0,l=(c&64)!==0,f=(c&32)!==0;if(u&&e.skip(2),l){const g=de(e);e.skip(g)}f&&e.skip(2);const d=de(e);R(d===4);const h=Io(e),p=e.filePos,m=de(e);if(m===64||m===103?(a.info.codec="aac",a.info.aacCodecInfo={isMpeg2:m===103,objectType:null}):m===105||m===107?a.info.codec="mp3":m===221?a.info.codec="vorbis":m===169?a.info.codec="dts":pe._warn(`Unsupported audio codec (objectTypeIndication ${m}) - discarding track.`),e.skip(12),h>e.filePos-p){const g=de(e);R(g===5);const w=Io(e);if(a.info.codecDescription=me(e,w),a.info.codec==="aac"){const y=ml(a.info.codecDescription);y.outputNumberOfChannels!==null&&(a.info.numberOfChannels=y.outputNumberOfChannels),y.outputSampleRate!==null&&(a.info.sampleRate=y.outputSampleRate)}}}break;case"enda":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="audio"),a.info.pcmLittleEndian=!!($e(e)&255)}break;case"pcmC":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="audio"),e.skip(4);const o=de(e);a.info.pcmLittleEndian=!!(o&1),a.info.pcmSampleSize=de(e)}break;case"dOps":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="audio"),e.skip(1);const o=de(e),c=$e(e),u=ae(e),l=nc(e),f=de(e);let d;f!==0?d=me(e,2+o):d=new Uint8Array(0);const h=new Uint8Array(19+d.byteLength),p=new DataView(h.buffer);p.setUint32(0,1332770163,!1),p.setUint32(4,1214603620,!1),p.setUint8(8,1),p.setUint8(9,o),p.setUint16(10,c,!0),p.setUint32(12,u,!0),p.setInt16(16,l,!0),p.setUint8(18,f),h.set(d,19),a.info.codecDescription=h,a.info.numberOfChannels=o}break;case"dfLa":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="audio"),e.skip(4);const o=127,c=128,u=e.filePos;for(;e.filePos<s;){const p=de(e),m=Hn(e);if((p&o)===Zr.STREAMINFO){e.skip(10);const w=ae(e),y=w>>>12,b=(w>>9&7)+1;a.info.sampleRate=y,a.info.numberOfChannels=b,e.skip(20)}else e.skip(m);if(p&c)break}const l=e.filePos;e.filePos=u;const f=me(e,l-u),d=new Uint8Array(4+f.byteLength);new DataView(d.buffer).setUint32(0,1716281667,!1),d.set(f,4),a.info.codecDescription=d}break;case"dac3":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="audio");const o=me(e,3),c=new Ee(o),u=c.readBits(2);c.skipBits(8);const l=c.readBits(3),f=c.readBits(1);u<3&&(a.info.sampleRate=Ds[u]),a.info.numberOfChannels=Ao[l]+f}break;case"dec3":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="audio");const o=me(e,r.contentSize),c=bm(o);if(!c){pe._warn("Invalid dec3 box contents, ignoring.");break}const u=El(c);u!==null&&(a.info.sampleRate=u),a.info.numberOfChannels=Cl(c)}break;case"ddts":{const a=this.currentTrack;if(!a)break;R(a.info?.type==="audio");const o=me(e,Math.min(r.contentSize,Ml)),c=Mm(o);if(!c){pe._warn("Invalid ddts box contents, ignoring.");break}a.info.sampleRate=c.sampleRate,c.numberOfChannels!==null&&(a.info.numberOfChannels=c.numberOfChannels)}break;case"stts":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4);const o=ae(e);let c=0,u=0;for(let l=0;l<o;l++){const f=ae(e),d=ae(e);a.sampleTable.sampleTimingEntries.push({startIndex:c,startDecodeTimestamp:u,count:f,delta:d}),c+=f,u+=f*d}}break;case"ctts":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4);const o=ae(e);let c=0;for(let u=0;u<o;u++){const l=ae(e),f=Mr(e);a.sampleTable.sampleCompositionTimeOffsets.push({startIndex:c,count:l,offset:f}),c+=l}}break;case"stsz":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4);const o=ae(e),c=ae(e);if(o===0)for(let u=0;u<c;u++){const l=ae(e);a.sampleTable.sampleSizes.push(l)}else a.sampleTable.sampleSizes.push(o)}break;case"stz2":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4),e.skip(3);const o=de(e),c=ae(e),u=me(e,Math.ceil(c*o/8)),l=new Ee(u);for(let f=0;f<c;f++){const d=l.readBits(o);a.sampleTable.sampleSizes.push(d)}}break;case"stss":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4),a.sampleTable.keySampleIndices=[];const o=ae(e);for(let c=0;c<o;c++){const u=ae(e)-1;a.sampleTable.keySampleIndices.push(u)}a.sampleTable.keySampleIndices[0]!==0&&a.sampleTable.keySampleIndices.unshift(0)}break;case"stsc":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4);const o=ae(e);for(let u=0;u<o;u++){const l=ae(e)-1,f=ae(e),d=ae(e);a.sampleTable.sampleToChunk.push({startSampleIndex:-1,startChunkIndex:l,samplesPerChunk:f,sampleDescriptionIndex:d})}let c=0;for(let u=0;u<a.sampleTable.sampleToChunk.length;u++)if(a.sampleTable.sampleToChunk[u].startSampleIndex=c,u<a.sampleTable.sampleToChunk.length-1){const f=a.sampleTable.sampleToChunk[u+1].startChunkIndex-a.sampleTable.sampleToChunk[u].startChunkIndex;c+=f*a.sampleTable.sampleToChunk[u].samplesPerChunk}}break;case"stco":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4);const o=ae(e);for(let c=0;c<o;c++){const u=ae(e);a.sampleTable.chunkOffsets.push(u)}}break;case"co64":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4);const o=ae(e);for(let c=0;c<o;c++){const u=Ht(e);a.sampleTable.chunkOffsets.push(u)}}break;case"mvex":this.isFragmented=!0,this.readContiguousBoxes(e.slice(i,r.contentSize));break;case"mehd":{const a=de(e);e.skip(3);const o=a===1?Ht(e):ae(e);this.movieDurationInTimescale=o}break;case"trex":{e.skip(4);const a=ae(e),o=ae(e),c=ae(e),u=ae(e),l=ae(e);this.fragmentTrackDefaults.push({trackId:a,defaultSampleDescriptionIndex:o,defaultSampleDuration:c,defaultSampleSize:u,defaultSampleFlags:l})}break;case"tfra":{const a=de(e);e.skip(3);const o=ae(e),c=this.tracks.find(y=>y.id===o);if(!c)break;const u=ae(e),l=(u&48)>>4,f=(u&12)>>2,d=u&3,h=[de,$e,Hn,ae],p=h[l],m=h[f],g=h[d],w=ae(e);for(let y=0;y<w;y++){const b=a===1?Ht(e):ae(e),v=a===1?Ht(e):ae(e);p(e),m(e),g(e),c.fragmentLookupTable.push({timestamp:b,moofOffset:v})}c.fragmentLookupTable.sort((y,b)=>y.timestamp-b.timestamp);for(let y=0;y<c.fragmentLookupTable.length-1;y++){const b=c.fragmentLookupTable[y],v=c.fragmentLookupTable[y+1];b.timestamp===v.timestamp&&(c.fragmentLookupTable.splice(y+1,1),y--)}}break;case"moof":this.currentFragment={moofOffset:n,moofSize:r.totalSize,implicitBaseDataOffset:n,trackData:new Map,psshBoxes:[]},this.readContiguousBoxes(e.slice(i,r.contentSize)),this.lastReadFragment=this.currentFragment,this.currentFragment=null;break;case"traf":if(R(this.currentFragment),this.readContiguousBoxes(e.slice(i,r.contentSize)),this.currentTrack){const a=this.currentFragment.trackData.get(this.currentTrack.id);e:if(a){if(a.samples.length===0){this.currentFragment.trackData.delete(this.currentTrack.id);break e}a.presentationTimestamps=a.samples.map((l,f)=>({presentationTimestamp:l.presentationTimestamp,sampleIndex:f})).sort((l,f)=>l.presentationTimestamp-f.presentationTimestamp);for(let l=0;l<a.presentationTimestamps.length;l++){const f=a.presentationTimestamps[l],d=a.samples[f.sampleIndex];if(a.firstKeyFrameTimestamp===null&&d.isKeyFrame&&(a.firstKeyFrameTimestamp=d.presentationTimestamp),l<a.presentationTimestamps.length-1){const p=a.presentationTimestamps[l+1].presentationTimestamp-f.presentationTimestamp;d.duration=p}}const o=a.samples[a.presentationTimestamps[0].sampleIndex],c=a.samples[Mt(a.presentationTimestamps).sampleIndex];a.startTimestamp=o.presentationTimestamp,a.endTimestamp=c.presentationTimestamp+c.duration;const{currentFragmentState:u}=this.currentTrack;R(u),u.startTimestamp!==null&&(Ro(a,u.startTimestamp),a.startTimestampIsFinal=!0),u.encryptionAuxInfo&&!a.samples[0].encryption&&(a.encryptionAuxInfo=u.encryptionAuxInfo)}this.currentTrack.currentFragmentState=null,this.currentTrack=null}break;case"pssh":{if(this.input._formatOptions.isobmff?._suppressPsshParsing)break;const a=Xl(me(e,r.contentSize));this.currentFragment?this.currentFragment.psshBoxes.push(a):this.currentTrack||this.psshBoxes.push(a)}break;case"tfhd":{R(this.currentFragment),e.skip(1);const a=Hn(e),o=!!(a&1),c=!!(a&2),u=!!(a&8),l=!!(a&16),f=!!(a&32),d=!!(a&65536),h=!!(a&131072),p=ae(e),m=this.tracks.find(w=>w.id===p);if(!m)break;const g=this.fragmentTrackDefaults.find(w=>w.trackId===p);this.currentTrack=m,m.currentFragmentState={baseDataOffset:this.currentFragment.implicitBaseDataOffset,sampleDescriptionIndex:g?.defaultSampleDescriptionIndex??null,defaultSampleDuration:g?.defaultSampleDuration??null,defaultSampleSize:g?.defaultSampleSize??null,defaultSampleFlags:g?.defaultSampleFlags??null,startTimestamp:null,encryptionAuxInfo:null},o?m.currentFragmentState.baseDataOffset=Ht(e):h&&(m.currentFragmentState.baseDataOffset=this.currentFragment.moofOffset),c&&(m.currentFragmentState.sampleDescriptionIndex=ae(e)),u&&(m.currentFragmentState.defaultSampleDuration=ae(e)),l&&(m.currentFragmentState.defaultSampleSize=ae(e)),f&&(m.currentFragmentState.defaultSampleFlags=ae(e)),d&&(m.currentFragmentState.defaultSampleDuration=0)}break;case"tfdt":{const a=this.currentTrack;if(!a)break;R(a.currentFragmentState);const o=de(e);e.skip(3);const c=o===0?ae(e):Ht(e);a.currentFragmentState.startTimestamp=c}break;case"trun":{const a=this.currentTrack;if(!a)break;R(this.currentFragment),R(a.currentFragmentState);const o=de(e),c=Hn(e),u=!!(c&1),l=!!(c&4),f=!!(c&256),d=!!(c&512),h=!!(c&1024),p=!!(c&2048),m=ae(e);let g=null;u&&(g=Mr(e));let w=null;l&&(w=ae(e));let y;this.currentFragment.trackData.has(a.id)?(y=this.currentFragment.trackData.get(a.id),g!==null&&(y.currentOffset=a.currentFragmentState.baseDataOffset+g)):(y={track:a,currentTimestamp:0,currentOffset:a.currentFragmentState.baseDataOffset+(g??0),startTimestamp:0,endTimestamp:0,firstKeyFrameTimestamp:null,samples:[],presentationTimestamps:[],startTimestampIsFinal:!1,encryptionAuxInfo:null},this.currentFragment.trackData.set(a.id,y));for(let b=0;b<m;b++){let v;f?v=ae(e):(R(a.currentFragmentState.defaultSampleDuration!==null),v=a.currentFragmentState.defaultSampleDuration);let k;d?k=ae(e):(R(a.currentFragmentState.defaultSampleSize!==null),k=a.currentFragmentState.defaultSampleSize);let A;h?A=ae(e):(R(a.currentFragmentState.defaultSampleFlags!==null),A=a.currentFragmentState.defaultSampleFlags),b===0&&w!==null&&(A=w);let T=0;p&&(o===0?T=ae(e):T=Mr(e));const S=!(A&65536);y.samples.push({presentationTimestamp:y.currentTimestamp+T,duration:v,byteOffset:y.currentOffset,byteSize:k,isKeyFrame:S,encryption:null}),y.currentOffset+=k,y.currentTimestamp+=v}this.currentFragment.implicitBaseDataOffset=y.currentOffset}break;case"saiz":{const a=this.currentTrack;if(!a||!a.encryptionInfo)break;if(e.skip(1),Hn(e)&1){const d=Ve(e,4),h=ae(e);if(d!==a.encryptionInfo.scheme||h!==0)break}const c=de(e),u=ae(e);let l=null;c===0&&u>0&&(l=me(e,u));const f=tu(a);f.defaultSampleInfoSize=c,f.sampleSizes=l,f.sampleCount=u}break;case"saio":{const a=this.currentTrack;if(!a||!a.encryptionInfo)break;const o=de(e);if(Hn(e)&1){const d=Ve(e,4),h=ae(e);if(d!==a.encryptionInfo.scheme||h!==0)break}const u=ae(e);if(u===0)break;u>1&&pe._warn("Multiple saio entries are not supported; using the first offset only.");let l=o===0?ae(e):Number(Ht(e));this.currentFragment&&(l+=this.currentFragment.moofOffset);const f=tu(a);f.offset=l}break;case"senc":{const a=this.currentTrack;if(!a||!a.encryptionInfo)break;R(this.currentFragment);const o=this.currentFragment.trackData.get(a.id);if(!o)break;e.skip(1);const u=!!(Hn(e)&2),l=ae(e),f=a.encryptionInfo.defaultPerSampleIvSize;R(f!==null);for(let d=0;d<Math.min(l,o.samples.length);d++){const h=new Uint8Array(16);f>0?h.set(me(e,f),0):h.set(a.encryptionInfo.defaultConstantIv,0);let p=null;if(u){const g=$e(e);p=[];for(let w=0;w<g;w++){const y=$e(e),b=ae(e);p.push({clearLen:y,protectedLen:b})}}const m=o.samples[d];m.encryption={iv:h,subsamples:p}}}break;case"udta":{const a=this.iterateContiguousBoxes(e.slice(i,r.contentSize));for(const{boxInfo:o,slice:c}of a){if(o.name!=="meta"&&!this.currentTrack){const u=c.filePos;this.metadataTags.raw??={},o.name[0]==="\xA9"?this.metadataTags.raw[o.name]??=mn(c):this.metadataTags.raw[o.name]??=me(c,o.contentSize),c.filePos=u}switch(o.name){case"meta":c.skip(-o.headerSize),this.traverseBox(c);break;case"\xA9nam":case"name":this.currentTrack?this.currentTrack.name=Bt.decode(me(c,o.contentSize)):this.metadataTags.title??=mn(c);break;case"\xA9des":this.currentTrack||(this.metadataTags.description??=mn(c));break;case"\xA9ART":this.currentTrack||(this.metadataTags.artist??=mn(c));break;case"\xA9alb":this.currentTrack||(this.metadataTags.album??=mn(c));break;case"albr":this.currentTrack||(this.metadataTags.albumArtist??=mn(c));break;case"\xA9gen":this.currentTrack||(this.metadataTags.genre??=mn(c));break;case"\xA9day":if(!this.currentTrack){const u=new Date(mn(c));Number.isNaN(u.getTime())||(this.metadataTags.date??=u)}break;case"\xA9cmt":this.currentTrack||(this.metadataTags.comment??=mn(c));break;case"\xA9lyr":this.currentTrack||(this.metadataTags.lyrics??=mn(c));break}}}break;case"meta":{if(this.currentTrack)break;const o=ae(e)!==0;this.currentMetadataKeys=new Map,o?this.readContiguousBoxes(e.slice(i,r.contentSize)):this.readContiguousBoxes(e.slice(i+4,r.contentSize-4)),this.currentMetadataKeys=null}break;case"keys":{if(!this.currentMetadataKeys)break;e.skip(4);const a=ae(e);for(let o=0;o<a;o++){const c=ae(e);e.skip(4);const u=Bt.decode(me(e,c-8));this.currentMetadataKeys.set(o+1,u)}}break;case"ilst":{if(!this.currentMetadataKeys)break;const a=this.iterateContiguousBoxes(e.slice(i,r.contentSize));for(const{boxInfo:o,slice:c}of a){let u=o.name;const l=(u.charCodeAt(0)<<24)+(u.charCodeAt(1)<<16)+(u.charCodeAt(2)<<8)+u.charCodeAt(3);this.currentMetadataKeys.has(l)&&(u=this.currentMetadataKeys.get(l));const f=Um(c);switch(this.metadataTags.raw??={},this.metadataTags.raw[u]??=f,u){case"\xA9nam":case"titl":case"com.apple.quicktime.title":case"title":typeof f=="string"&&(this.metadataTags.title??=f);break;case"\xA9des":case"desc":case"dscp":case"com.apple.quicktime.description":case"description":typeof f=="string"&&(this.metadataTags.description??=f);break;case"\xA9ART":case"com.apple.quicktime.artist":case"artist":typeof f=="string"&&(this.metadataTags.artist??=f);break;case"\xA9alb":case"albm":case"com.apple.quicktime.album":case"album":typeof f=="string"&&(this.metadataTags.album??=f);break;case"aART":case"album_artist":typeof f=="string"&&(this.metadataTags.albumArtist??=f);break;case"\xA9cmt":case"com.apple.quicktime.comment":case"comment":typeof f=="string"&&(this.metadataTags.comment??=f);break;case"\xA9gen":case"gnre":case"com.apple.quicktime.genre":case"genre":typeof f=="string"&&(this.metadataTags.genre??=f);break;case"\xA9lyr":case"lyrics":typeof f=="string"&&(this.metadataTags.lyrics??=f);break;case"\xA9day":case"rldt":case"com.apple.quicktime.creationdate":case"date":if(typeof f=="string"){const d=new Date(f);Number.isNaN(d.getTime())||(this.metadataTags.date??=d)}break;case"covr":case"com.apple.quicktime.artwork":f instanceof Fs?(this.metadataTags.images??=[],this.metadataTags.images.push({data:f.data,kind:"coverFront",mimeType:f.mimeType})):f instanceof Uint8Array&&(this.metadataTags.images??=[],this.metadataTags.images.push({data:f,kind:"coverFront",mimeType:"image/*"}));break;case"track":if(typeof f=="string"){const d=f.split("/"),h=Number.parseInt(d[0],10),p=d[1]&&Number.parseInt(d[1],10);Number.isInteger(h)&&h>0&&(this.metadataTags.trackNumber??=h),p&&Number.isInteger(p)&&p>0&&(this.metadataTags.tracksTotal??=p)}break;case"trkn":if(f instanceof Uint8Array&&f.length>=6){const d=Ie(f),h=d.getUint16(2,!1),p=d.getUint16(4,!1);h>0&&(this.metadataTags.trackNumber??=h),p>0&&(this.metadataTags.tracksTotal??=p)}break;case"disc":case"disk":if(f instanceof Uint8Array&&f.length>=6){const d=Ie(f),h=d.getUint16(2,!1),p=d.getUint16(4,!1);h>0&&(this.metadataTags.discNumber??=h),p>0&&(this.metadataTags.discsTotal??=p)}break}}}break}return e.filePos=s,!0}}class Kl{constructor(e){this.internalTrack=e,this.packetToSampleIndex=new WeakMap,this.packetToFragmentLocation=new WeakMap}getId(){return this.internalTrack.id}getNumber(){const e=this.internalTrack.demuxer,n=this.internalTrack.trackBacking.getType();let r=0;for(const i of e.tracks)if(i.trackBacking.getType()===n&&r++,i===this.internalTrack)break;return r}getCodec(){throw new Error("Not implemented on base class.")}getInternalCodecId(){return this.internalTrack.internalCodecId}getName(){return this.internalTrack.name}getLanguageCode(){return this.internalTrack.languageCode}getTimeResolution(){return this.internalTrack.timescale}isRelativeToUnixEpoch(){return!1}getUnixTimeForTimestamp(){return null}getDisposition(){return this.internalTrack.disposition}getPairingMask(){return 1n}getBitrate(){return null}getAverageBitrate(){return null}async getDurationFromMetadata(){const e=this.internalTrack;return e.durationInMediaTimescale<=0?null:(R(e.trackBacking),((await e.trackBacking.getFirstPacket({metadataOnly:!0}))?.timestamp??0)+e.durationInMediaTimescale/e.timescale)}async getLiveRefreshInterval(){return null}async getFirstPacket(e){const n=await this.fetchPacketForSampleIndex(0,e);return n||!this.internalTrack.demuxer.isFragmented?n:this.performFragmentedLookup(null,r=>r.trackData.get(this.internalTrack.id)?{sampleIndex:0,correctSampleFound:!0}:{sampleIndex:-1,correctSampleFound:!1},-1/0,1/0,e)}mapTimestampIntoTimescale(e){return Bi(e*this.internalTrack.timescale)+this.internalTrack.editListOffset}async getPacket(e,n){const r=this.mapTimestampIntoTimescale(e),i=this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),s=Bo(i,r),a=await this.fetchPacketForSampleIndex(s,n);return!eu(i)||!this.internalTrack.demuxer.isFragmented?a:this.performFragmentedLookup(null,o=>{const c=o.trackData.get(this.internalTrack.id);if(!c)return{sampleIndex:-1,correctSampleFound:!1};const u=_e(c.presentationTimestamps,r,d=>d.presentationTimestamp),l=u!==-1?c.presentationTimestamps[u].sampleIndex:-1,f=u!==-1&&r<c.endTimestamp;return{sampleIndex:l,correctSampleFound:f}},r,r,n)}async getNextPacket(e,n){const r=this.packetToSampleIndex.get(e);if(r!==void 0)return this.fetchPacketForSampleIndex(r+1,n);const i=this.packetToFragmentLocation.get(e);if(i===void 0)throw new Error("Packet was not created from this track.");return this.performFragmentedLookup(i.fragment,s=>{if(s===i.fragment){const a=s.trackData.get(this.internalTrack.id);if(i.sampleIndex+1<a.samples.length)return{sampleIndex:i.sampleIndex+1,correctSampleFound:!0}}else if(s.trackData.get(this.internalTrack.id))return{sampleIndex:0,correctSampleFound:!0};return{sampleIndex:-1,correctSampleFound:!1}},-1/0,1/0,n)}async getKeyPacket(e,n){const r=this.mapTimestampIntoTimescale(e),i=this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),s=Vm(i,r),a=await this.fetchPacketForSampleIndex(s,n);return!eu(i)||!this.internalTrack.demuxer.isFragmented?a:this.performFragmentedLookup(null,o=>{const c=o.trackData.get(this.internalTrack.id);if(!c)return{sampleIndex:-1,correctSampleFound:!1};const u=Ya(c.presentationTimestamps,d=>c.samples[d.sampleIndex].isKeyFrame&&d.presentationTimestamp<=r),l=u!==-1?c.presentationTimestamps[u].sampleIndex:-1,f=u!==-1&&r<c.endTimestamp;return{sampleIndex:l,correctSampleFound:f}},r,r,n)}async getNextKeyPacket(e,n){const r=this.packetToSampleIndex.get(e);if(r!==void 0){const s=this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),a=jm(s,r);return this.fetchPacketForSampleIndex(a,n)}const i=this.packetToFragmentLocation.get(e);if(i===void 0)throw new Error("Packet was not created from this track.");return this.performFragmentedLookup(i.fragment,s=>{if(s===i.fragment){const o=s.trackData.get(this.internalTrack.id).samples.findIndex((c,u)=>c.isKeyFrame&&u>i.sampleIndex);if(o!==-1)return{sampleIndex:o,correctSampleFound:!0}}else{const a=s.trackData.get(this.internalTrack.id);if(a&&a.firstKeyFrameTimestamp!==null){const o=a.samples.findIndex(c=>c.isKeyFrame);return R(o!==-1),{sampleIndex:o,correctSampleFound:!0}}}return{sampleIndex:-1,correctSampleFound:!1}},-1/0,1/0,n)}async fetchPacketForSampleIndex(e,n){if(e===-1)return null;const r=this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),i=Wm(r,e);if(!i)return null;let s;if(n.metadataOnly)s=Ut;else{let u=this.internalTrack.demuxer.reader.requestSlice(i.sampleOffset,i.sampleSize);if(ie(u)&&(u=await u),!u)return null;if(s=me(u,i.sampleSize),this.internalTrack.encryptionInfo){let l=null;if(this.internalTrack.encryptionAuxInfo){const f=await nu(this.internalTrack.demuxer.reader,this.internalTrack.encryptionInfo,this.internalTrack.encryptionAuxInfo);e<f.length&&(l=f[e])}l??=ru(this.internalTrack.encryptionInfo),l&&(s=await iu(this.internalTrack,l,s,null))}}const a=(i.presentationTimestamp-this.internalTrack.editListOffset)/this.internalTrack.timescale,o=i.duration/this.internalTrack.timescale,c=new Qe(s,i.isKeyFrame?"key":"delta",a,o,e,i.sampleSize);return this.packetToSampleIndex.set(c,e),c}async fetchPacketInFragment(e,n,r){if(n===-1)return null;const s=e.trackData.get(this.internalTrack.id).samples[n];R(s);let a;if(r.metadataOnly)a=Ut;else{let l=this.internalTrack.demuxer.reader.requestSlice(s.byteOffset,s.byteSize);if(ie(l)&&(l=await l),!l)return null;if(a=me(l,s.byteSize),this.internalTrack.encryptionInfo){const f=s.encryption??ru(this.internalTrack.encryptionInfo);f&&(a=await iu(this.internalTrack,f,a,e))}}const o=(s.presentationTimestamp-this.internalTrack.editListOffset)/this.internalTrack.timescale,c=s.duration/this.internalTrack.timescale,u=new Qe(a,s.isKeyFrame?"key":"delta",o,c,e.moofOffset+n,s.byteSize);return this.packetToFragmentLocation.set(u,{fragment:e,sampleIndex:n}),u}async performFragmentedLookup(e,n,r,i,s){const a=this.internalTrack.demuxer;let o=null,c=null,u=-1;if(e){const{sampleIndex:g,correctSampleFound:w}=n(e);if(w)return this.fetchPacketInFragment(e,g,s);g!==-1&&(c=e,u=g)}const l=_e(this.internalTrack.fragmentLookupTable,r,g=>g.timestamp),f=l!==-1?this.internalTrack.fragmentLookupTable[l]:null,d=_e(this.internalTrack.fragmentPositionCache,r,g=>g.startTimestamp),h=d!==-1?this.internalTrack.fragmentPositionCache[d]:null,p=Math.max(f?.moofOffset??0,h?.moofOffset??0)||null;let m;for(e?p===null||e.moofOffset>=p?(m=e.moofOffset+e.moofSize,o=e):m=p:m=p??0;;){if(o){const b=o.trackData.get(this.internalTrack.id);if(b&&b.startTimestamp>i)break}let g=a.reader.requestSliceRange(m,ei,Li);if(ie(g)&&(g=await g),!g)break;const w=m,y=nr(g);if(!y)break;if(y.name==="moof"){o=await a.readFragment(w);const{sampleIndex:b,correctSampleFound:v}=n(o);if(v)return this.fetchPacketInFragment(o,b,s);b!==-1&&(c=o,u=b)}m=w+y.totalSize}if(f&&(!c||c.moofOffset<f.moofOffset)){const g=this.internalTrack.fragmentLookupTable[l-1];R(!g||g.timestamp<f.timestamp);const w=g?.timestamp??-1/0;return this.performFragmentedLookup(null,n,w,i,s)}return c?this.fetchPacketInFragment(c,u,s):null}}class Zl extends Kl{constructor(e){super(e),this.decoderConfigPromise=null,this.internalTrack=e}getType(){return"video"}getCodec(){return this.internalTrack.info.codec}getCodedWidth(){return this.internalTrack.info.width}getCodedHeight(){return this.internalTrack.info.height}getSquarePixelWidth(){return this.internalTrack.info.squarePixelWidth}getSquarePixelHeight(){return this.internalTrack.info.squarePixelHeight}getRotation(){return this.internalTrack.rotation}async getColorSpace(){const e=await this.getDecoderConfig();return e?{primaries:e.colorSpace?.primaries,transfer:e.colorSpace?.transfer,matrix:e.colorSpace?.matrix,fullRange:e.colorSpace?.fullRange}:this.internalTrack.info.colorSpace}async canBeTransparent(){return this.internalTrack.info.codec==="prores"&&(this.internalTrack.info.proresFormat==="ap4h"||this.internalTrack.info.proresFormat==="ap4x")}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfigPromise??=(async()=>{if(this.internalTrack.info.codec==="avc"&&!this.internalTrack.info.codecDescription){const n=await this.getFirstPacket({});this.internalTrack.info.avcCodecInfo=n&&go(n.data)}else if(this.internalTrack.info.codec==="hevc"&&!this.internalTrack.info.codecDescription){const n=await this.getFirstPacket({});this.internalTrack.info.hevcCodecInfo=n&&bo(n.data)}else if(this.internalTrack.info.codec==="vp9"&&(!this.internalTrack.info.vp9CodecInfo||!cm(this.internalTrack.info.vp9CodecInfo))){const n=await this.getFirstPacket({}),r=n&&Tl(n.data);r&&(this.internalTrack.info.vp9CodecInfo={...this.internalTrack.info.vp9CodecInfo??r,videoFullRangeFlag:r.videoFullRangeFlag,colourPrimaries:r.colourPrimaries,transferCharacteristics:r.transferCharacteristics,matrixCoefficients:r.matrixCoefficients})}else if(this.internalTrack.info.codec==="av1"&&(!this.internalTrack.info.av1CodecInfo||!lm(this.internalTrack.info.av1CodecInfo))){const n=await this.getFirstPacket({}),r=n&&wo(n.data);r&&(this.internalTrack.info.av1CodecInfo=r)}else if(this.internalTrack.info.codec==="prores"&&!this.internalTrack.info.proresCodecInfo){const n=await this.getFirstPacket({});this.internalTrack.info.proresCodecInfo=n&&Pl(n.data)}if(!$a(this.internalTrack.info.colorSpace)){const n=Hl(this.internalTrack.info);this.internalTrack.info.colorSpace.primaries??=n.primaries,this.internalTrack.info.colorSpace.transfer??=n.transfer,this.internalTrack.info.colorSpace.matrix??=n.matrix,this.internalTrack.info.colorSpace.fullRange??=n.fullRange}const e={codec:So(this.internalTrack.info),codedWidth:this.internalTrack.info.width,codedHeight:this.internalTrack.info.height,description:this.internalTrack.info.codecDescription??void 0,colorSpace:this.internalTrack.info.colorSpace};return(this.internalTrack.info.width!==this.internalTrack.info.squarePixelWidth||this.internalTrack.info.height!==this.internalTrack.info.squarePixelHeight)&&(e.displayAspectWidth=this.internalTrack.info.squarePixelWidth,e.displayAspectHeight=this.internalTrack.info.squarePixelHeight),e})():null}}class Jl extends Kl{constructor(e){super(e),this.decoderConfigPromise=null,this.internalTrack=e}getType(){return"audio"}getCodec(){return this.internalTrack.info.codec}getNumberOfChannels(){return this.internalTrack.info.numberOfChannels}getSampleRate(){return this.internalTrack.info.sampleRate}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfigPromise??=(async()=>{if(this.internalTrack.info.codec==="dts"&&!this.internalTrack.info.dtsFormat){const e=await this.getFirstPacket({});this.internalTrack.info.dtsFormat=e&&Rl(e.data)}return{codec:Po(this.internalTrack.info),numberOfChannels:this.internalTrack.info.numberOfChannels,sampleRate:this.internalTrack.info.sampleRate,description:this.internalTrack.info.codecDescription??void 0}})():null}}const Bo=(t,e)=>{if(t.presentationTimestamps){const n=_e(t.presentationTimestamps,e,r=>r.presentationTimestamp);return n===-1?-1:t.presentationTimestamps[n].sampleIndex}else{const n=_e(t.sampleTimingEntries,e,i=>i.startDecodeTimestamp);if(n===-1)return-1;const r=t.sampleTimingEntries[n];return r.startIndex+Math.min(Math.floor((e-r.startDecodeTimestamp)/r.delta),r.count-1)}},Vm=(t,e)=>{if(!t.keySampleIndices)return Bo(t,e);if(t.presentationTimestamps){const n=_e(t.presentationTimestamps,e,r=>r.presentationTimestamp);if(n===-1)return-1;for(let r=n;r>=0;r--){const i=t.presentationTimestamps[r].sampleIndex;if(Ii(t.keySampleIndices,i,a=>a)!==-1)return i}return-1}else{const n=Bo(t,e),r=_e(t.keySampleIndices,n,i=>i);return t.keySampleIndices[r]??-1}},Wm=(t,e)=>{const n=_e(t.sampleTimingEntries,e,w=>w.startIndex),r=t.sampleTimingEntries[n];if(!r||r.startIndex+r.count<=e)return null;let s=r.startDecodeTimestamp+(e-r.startIndex)*r.delta;const a=_e(t.sampleCompositionTimeOffsets,e,w=>w.startIndex),o=t.sampleCompositionTimeOffsets[a];o&&e-o.startIndex<o.count&&(s+=o.offset);const c=t.sampleSizes[Math.min(e,t.sampleSizes.length-1)],u=_e(t.sampleToChunk,e,w=>w.startSampleIndex),l=t.sampleToChunk[u];R(l);const f=l.startChunkIndex+Math.floor((e-l.startSampleIndex)/l.samplesPerChunk),d=t.chunkOffsets[f],h=l.startSampleIndex+(f-l.startChunkIndex)*l.samplesPerChunk;let p=0,m=d;if(t.sampleSizes.length===1)m+=c*(e-h),p+=c*l.samplesPerChunk;else for(let w=h;w<h+l.samplesPerChunk;w++){const y=t.sampleSizes[w];w<e&&(m+=y),p+=y}let g=r.delta;if(t.presentationTimestamps){const w=t.presentationTimestampIndexMap[e];R(w!==void 0),w<t.presentationTimestamps.length-1&&(g=t.presentationTimestamps[w+1].presentationTimestamp-s)}return{presentationTimestamp:s,duration:g,sampleOffset:m,sampleSize:c,chunkOffset:d,chunkSize:p,isKeyFrame:t.keySampleIndices?Ii(t.keySampleIndices,e,w=>w)!==-1:!0}},jm=(t,e)=>{if(!t.keySampleIndices)return e+1;const n=_e(t.keySampleIndices,e,r=>r);return t.keySampleIndices[n+1]??-1},Ro=(t,e)=>{t.startTimestamp+=e,t.endTimestamp+=e;for(const n of t.samples)n.presentationTimestamp+=e;for(const n of t.presentationTimestamps)n.presentationTimestamp+=e},qm=t=>{const[e,n]=t,r=Math.atan2(n,e);return Number.isFinite(r)?r*(180/Math.PI):0},eu=t=>t.sampleSizes.length===0,tu=t=>t.currentFragmentState?t.currentFragmentState.encryptionAuxInfo??={defaultSampleInfoSize:0,sampleSizes:null,sampleCount:0,offset:null,resolved:null}:t.encryptionAuxInfo??={defaultSampleInfoSize:0,sampleSizes:null,sampleCount:0,offset:null,resolved:null},nu=async(t,e,n)=>{if(n.resolved)return n.resolved;if(n.offset===null||n.sampleCount===0)throw new Error("Incomplete saiz/saio info; cannot resolve encryption data.");let r=0;if(n.defaultSampleInfoSize>0)r=n.defaultSampleInfoSize*n.sampleCount;else{R(n.sampleSizes);for(let o=0;o<n.sampleCount;o++)r+=n.sampleSizes[o]}let i=t.requestSlice(n.offset,r);if(ie(i)&&(i=await i),!i)throw new Error("Failed to read auxiliary encryption info.");const s=e.defaultPerSampleIvSize;R(s!==null);const a=[];for(let o=0;o<n.sampleCount;o++){const c=n.defaultSampleInfoSize>0?n.defaultSampleInfoSize:n.sampleSizes[o],u=new Uint8Array(16);s>0?u.set(me(i,s),0):u.set(e.defaultConstantIv,0);let l=null;if(c>s){const f=$e(i);l=[];for(let d=0;d<f;d++){const h=$e(i),p=ae(i);l.push({clearLen:h,protectedLen:p})}}a.push({iv:u,subsamples:l})}return n.resolved=a,a},ru=t=>t.defaultConstantIv?{iv:t.defaultConstantIv,subsamples:null}:null,iu=async(t,e,n,r)=>{R(t.encryptionInfo);const i=t.encryptionInfo;R(i.defaultKid!==null);const s=i.defaultKid;let a;const o=t.demuxer.decryptionKeyCache.get(s);if(o)a=await o;else{if(!t.demuxer.input._formatOptions.isobmff?.resolveKeyId)throw new Error("Encrypted media samples encountered. To decrypt them, please provide a callback for InputOptions.formatOptions.isobmff.resolveKeyId.");const c=(async()=>{let u=t.demuxer.psshBoxes;if(r){u=[...u,...r.psshBoxes].filter(f=>f.keyIds===null||f.keyIds.includes(s));for(let f=0;f<u.length-1;f++)for(let d=f+1;d<u.length;d++)Gl(u[f],u[d])&&(u.splice(d,1),d--)}const l=await t.demuxer.input._formatOptions.isobmff.resolveKeyId({keyId:s,psshBoxes:u});if(!(typeof l=="string"&&l.length===32&&Oh.test(l)||l instanceof Uint8Array&&l.byteLength===16))throw new TypeError("resolveKeyId must return a 32-character hex string or a 16-byte Uint8Array containing the decryption key.");return l instanceof Uint8Array?l:Uh(l)})();t.demuxer.decryptionKeyCache.set(s,c),a=await c}return i.scheme==="cenc"||i.scheme==="cens"?Xm(a,i,e,n):Gm(a,i,e,n)},Xm=async(t,e,n,r)=>{const i=new Uint8Array(16);i.set(n.iv,0);const s=await crypto.subtle.importKey("raw",t,{name:"AES-CTR"},!1,["decrypt"]),a=async p=>{const m=await crypto.subtle.decrypt({name:"AES-CTR",counter:i,length:64},s,p);return new Uint8Array(m)};if(!n.subsamples)return a(r);R(e.defaultCryptByteBlock!==null&&e.defaultSkipByteBlock!==null);const o=su(n.subsamples,e.defaultCryptByteBlock,e.defaultSkipByteBlock);let c=0;for(const p of o)for(const m of p.perSubsample)c+=m.length;const u=new Uint8Array(c);let l=0;for(const p of o)for(const m of p.perSubsample)u.set(r.subarray(m.offset,m.offset+m.length),l),l+=m.length;const f=await a(u),d=new Uint8Array(r);let h=0;for(const p of o)for(const m of p.perSubsample)d.set(f.subarray(h,h+m.length),m.offset),h+=m.length;return d},Gm=(t,e,n,r)=>{const i=new Yl;i.init({key:t,iv:n.iv});const s=e.defaultCryptByteBlock,a=e.defaultSkipByteBlock;if(R(s!==null&&a!==null),!n.subsamples){const l=new Uint8Array(r),f=Math.floor(r.length/16);for(let d=0;d<f;d++){const h=d*16;i.in.set(r.subarray(h,h+16)),i.decrypt(),l.set(i.out,h)}return l}if(s===0&&a===0)throw new Error("cbcs with subsamples requires pattern encryption.");const o=new Uint8Array(r),c=su(n.subsamples,s,a),u=new DataView(n.iv.buffer,n.iv.byteOffset,16);for(const l of c){i.iv[0]=u.getUint32(0,!1),i.iv[1]=u.getUint32(4,!1),i.iv[2]=u.getUint32(8,!1),i.iv[3]=u.getUint32(12,!1);for(const f of l.perSubsample){const d=f.length/16;for(let h=0;h<d;h++){const p=f.offset+h*16;i.in.set(r.subarray(p,p+16)),i.decrypt(),o.set(i.out,p)}}}return o},su=(t,e,n)=>{const r=[],i=e!==0||n!==0;let s=0;for(const a of t){s+=a.clearLen;const o=[];if(!i)a.protectedLen>0&&o.push({offset:s,length:a.protectedLen}),s+=a.protectedLen;else{let c=a.protectedLen,u=s;for(;c>0&&!(c<16*e);){const l=16*e;o.push({offset:u,length:l}),u+=l,c-=l;const f=Math.min(16*n,c);u+=f,c-=f}s+=a.protectedLen}r.push({perSubsample:o})}return r};var re;(function(t){t[t.EBML=440786851]="EBML",t[t.EBMLVersion=17030]="EBMLVersion",t[t.EBMLReadVersion=17143]="EBMLReadVersion",t[t.EBMLMaxIDLength=17138]="EBMLMaxIDLength",t[t.EBMLMaxSizeLength=17139]="EBMLMaxSizeLength",t[t.DocType=17026]="DocType",t[t.DocTypeVersion=17031]="DocTypeVersion",t[t.DocTypeReadVersion=17029]="DocTypeReadVersion",t[t.Void=236]="Void",t[t.Segment=408125543]="Segment",t[t.SeekHead=290298740]="SeekHead",t[t.Seek=19899]="Seek",t[t.SeekID=21419]="SeekID",t[t.SeekPosition=21420]="SeekPosition",t[t.Duration=17545]="Duration",t[t.Info=357149030]="Info",t[t.TimestampScale=2807729]="TimestampScale",t[t.MuxingApp=19840]="MuxingApp",t[t.WritingApp=22337]="WritingApp",t[t.Tracks=374648427]="Tracks",t[t.TrackEntry=174]="TrackEntry",t[t.TrackNumber=215]="TrackNumber",t[t.TrackUID=29637]="TrackUID",t[t.TrackType=131]="TrackType",t[t.FlagEnabled=185]="FlagEnabled",t[t.FlagDefault=136]="FlagDefault",t[t.FlagForced=21930]="FlagForced",t[t.FlagOriginal=21934]="FlagOriginal",t[t.FlagHearingImpaired=21931]="FlagHearingImpaired",t[t.FlagVisualImpaired=21932]="FlagVisualImpaired",t[t.FlagCommentary=21935]="FlagCommentary",t[t.FlagLacing=156]="FlagLacing",t[t.Name=21358]="Name",t[t.Language=2274716]="Language",t[t.LanguageBCP47=2274717]="LanguageBCP47",t[t.CodecID=134]="CodecID",t[t.CodecPrivate=25506]="CodecPrivate",t[t.CodecDelay=22186]="CodecDelay",t[t.SeekPreRoll=22203]="SeekPreRoll",t[t.DefaultDuration=2352003]="DefaultDuration",t[t.Video=224]="Video",t[t.PixelWidth=176]="PixelWidth",t[t.PixelHeight=186]="PixelHeight",t[t.DisplayWidth=21680]="DisplayWidth",t[t.DisplayHeight=21690]="DisplayHeight",t[t.DisplayUnit=21682]="DisplayUnit",t[t.AlphaMode=21440]="AlphaMode",t[t.Audio=225]="Audio",t[t.SamplingFrequency=181]="SamplingFrequency",t[t.Channels=159]="Channels",t[t.BitDepth=25188]="BitDepth",t[t.SimpleBlock=163]="SimpleBlock",t[t.BlockGroup=160]="BlockGroup",t[t.Block=161]="Block",t[t.BlockAdditions=30113]="BlockAdditions",t[t.BlockMore=166]="BlockMore",t[t.BlockAdditional=165]="BlockAdditional",t[t.BlockAddID=238]="BlockAddID",t[t.BlockDuration=155]="BlockDuration",t[t.ReferenceBlock=251]="ReferenceBlock",t[t.Cluster=524531317]="Cluster",t[t.Timestamp=231]="Timestamp",t[t.Cues=475249515]="Cues",t[t.CuePoint=187]="CuePoint",t[t.CueTime=179]="CueTime",t[t.CueTrackPositions=183]="CueTrackPositions",t[t.CueTrack=247]="CueTrack",t[t.CueClusterPosition=241]="CueClusterPosition",t[t.Colour=21936]="Colour",t[t.MatrixCoefficients=21937]="MatrixCoefficients",t[t.TransferCharacteristics=21946]="TransferCharacteristics",t[t.Primaries=21947]="Primaries",t[t.Range=21945]="Range",t[t.Projection=30320]="Projection",t[t.ProjectionType=30321]="ProjectionType",t[t.ProjectionPoseRoll=30325]="ProjectionPoseRoll",t[t.Attachments=423732329]="Attachments",t[t.AttachedFile=24999]="AttachedFile",t[t.FileDescription=18046]="FileDescription",t[t.FileName=18030]="FileName",t[t.FileMediaType=18016]="FileMediaType",t[t.FileData=18012]="FileData",t[t.FileUID=18094]="FileUID",t[t.Chapters=272869232]="Chapters",t[t.Tags=307544935]="Tags",t[t.Tag=29555]="Tag",t[t.Targets=25536]="Targets",t[t.TargetTypeValue=26826]="TargetTypeValue",t[t.TargetType=25546]="TargetType",t[t.TagTrackUID=25541]="TagTrackUID",t[t.TagEditionUID=25545]="TagEditionUID",t[t.TagChapterUID=25540]="TagChapterUID",t[t.TagAttachmentUID=25542]="TagAttachmentUID",t[t.SimpleTag=26568]="SimpleTag",t[t.TagName=17827]="TagName",t[t.TagLanguage=17530]="TagLanguage",t[t.TagString=17543]="TagString",t[t.TagBinary=17541]="TagBinary",t[t.ContentEncodings=28032]="ContentEncodings",t[t.ContentEncoding=25152]="ContentEncoding",t[t.ContentEncodingOrder=20529]="ContentEncodingOrder",t[t.ContentEncodingScope=20530]="ContentEncodingScope",t[t.ContentCompression=20532]="ContentCompression",t[t.ContentCompAlgo=16980]="ContentCompAlgo",t[t.ContentCompSettings=16981]="ContentCompSettings",t[t.ContentEncryption=20533]="ContentEncryption"})(re||(re={}));const $m=[re.EBML,re.Segment],Oi=[re.SeekHead,re.Info,re.Cluster,re.Tracks,re.Cues,re.Attachments,re.Chapters,re.Tags],Gs=[...$m,...Oi],Fo=8,Xt=2,Ln=2*Fo,au=t=>{if(t.remainingLength<1)return null;const e=de(t);if(t.skip(-1),e===0)return null;let n=1,r=128;for(;(e&r)===0;)n++,r>>=1;return t.remainingLength<n?null:n},Ui=t=>{if(t.remainingLength<1)return null;const e=de(t);if(e===0)return null;let n=1,r=128;for(;(e&r)===0;)n++,r>>=1;if(t.remainingLength<n-1)return null;let i=e&r-1;for(let s=1;s<n;s++)i*=256,i+=de(t);return i},Ae=(t,e)=>{if(e<1||e>8)throw new Error("Bad unsigned int size "+e);let n=0;for(let r=0;r<e;r++)n*=256,n+=de(t);return n},Qm=(t,e)=>{if(e<1)throw new Error("Bad unsigned int size "+e);let n=0n;for(let r=0;r<e;r++)n<<=8n,n+=BigInt(de(t));return n},Do=t=>{const e=au(t);return e===null||t.remainingLength<e?null:Ae(t,e)},ou=t=>{if(t.remainingLength<1)return null;if(de(t)===255)return;t.skip(-1);const n=Ui(t);if(n===null)return null;if(n!==72057594037927940)return n},On=t=>{R(t.remainingLength>=Xt);const e=Do(t);if(e===null)return null;const n=ou(t);return n===null?null:{id:e,size:n}},si=(t,e)=>{const n=me(t,e);let r=0;for(;r<e&&n[r]!==0;)r+=1;return String.fromCharCode(...n.subarray(0,r))},zi=(t,e)=>{const n=me(t,e);let r=0;for(;r<e&&n[r]!==0;)r+=1;return Bt.decode(n.subarray(0,r))},No=(t,e)=>{if(e===0)return 0;if(e!==4&&e!==8)throw new Error("Bad float size "+e);return e===4?Pg(t):ff(t)},Lo=async(t,e,n,r)=>{const i=new Set(n);let s=e;for(;r===null||s<r;){let a=t.requestSliceRange(s,Xt,Ln);if(ie(a)&&(a=await a),!a)break;const o=On(a);if(!o)break;if(i.has(o.id))return{pos:s,found:!0};rr(o.size),s=a.filePos+o.size}return{pos:r!==null&&r>s?r:s,found:!1}},cu=async(t,e,n,r)=>{const s=new Set(n);let a=e;for(;a<r;){let o=t.requestSliceRange(a,0,Math.min(65536,r-a));if(ie(o)&&(o=await o),!o||o.length<Fo)break;for(let c=0;c<o.length-Fo;c++){o.filePos=a;const u=Do(o);if(u!==null&&s.has(u))return a;a++}}return null},Rt={avc:"V_MPEG4/ISO/AVC",hevc:"V_MPEGH/ISO/HEVC",vp8:"V_VP8",vp9:"V_VP9",av1:"V_AV1",prores:"V_PRORES",aac:"A_AAC",mp3:"A_MPEG/L3",opus:"A_OPUS",vorbis:"A_VORBIS",flac:"A_FLAC",ac3:"A_AC3",eac3:"A_EAC3",dts:"A_DTS"};function rr(t){if(t===void 0)throw new Error("Undefined element size is used in a place where it is not supported.")}const Ym=t=>{let n=(t.hasVideo?"video/":t.hasAudio?"audio/":"application/")+(t.isWebM?"webm":"x-matroska");if(t.codecStrings.length>0){const r=[...new Set(t.codecStrings.filter(Boolean))];n+=`; codecs="${r.join(", ")}"`}return n};var Un;(function(t){t[t.None=0]="None",t[t.Xiph=1]="Xiph",t[t.FixedSize=2]="FixedSize",t[t.Ebml=3]="Ebml"})(Un||(Un={}));var $s;(function(t){t[t.Block=1]="Block",t[t.Private=2]="Private",t[t.Next=4]="Next"})($s||($s={}));var Hi;(function(t){t[t.Zlib=0]="Zlib",t[t.Bzlib=1]="Bzlib",t[t.lzo1x=2]="lzo1x",t[t.HeaderStripping=3]="HeaderStripping"})(Hi||(Hi={}));const Oo=[{id:re.SeekHead,flag:"seekHeadSeen"},{id:re.Info,flag:"infoSeen"},{id:re.Tracks,flag:"tracksSeen"},{id:re.Cues,flag:"cuesSeen"}],lu=10*2**20;class Km extends Dn{constructor(e){super(e),this.readMetadataPromise=null,this.segments=[],this.currentSegment=null,this.currentTrack=null,this.currentCluster=null,this.currentBlock=null,this.currentBlockAdditional=null,this.currentCueTime=null,this.currentDecodingInstruction=null,this.currentTagTargetIsMovie=!0,this.currentSimpleTagName=null,this.currentAttachedFile=null,this.isWebM=!1,this.reader=e._reader}async getTrackBackings(){return await this.readMetadata(),this.segments.flatMap(e=>e.tracks.map(n=>n.trackBacking))}async getMimeType(){await this.readMetadata();const e=await this.getTrackBackings(),n=await Promise.all(e.map(r=>r.getDecoderConfig().then(i=>i?.codec??null)));return Ym({isWebM:this.isWebM,hasVideo:this.segments.some(r=>r.tracks.some(i=>i.info?.type==="video")),hasAudio:this.segments.some(r=>r.tracks.some(i=>i.info?.type==="audio")),codecStrings:n.filter(Boolean)})}async getMetadataTags(){await this.readMetadata();for(const n of this.segments)n.metadataTagsCollected||(this.reader.fileSize!==null&&await this.loadSegmentMetadata(n),n.metadataTagsCollected=!0);let e={};for(const n of this.segments)e={...e,...n.metadataTags};return e}readMetadata(){return this.readMetadataPromise??=(async()=>{let e=0;for(;;){let n=this.reader.requestSliceRange(e,Xt,Ln);if(ie(n)&&(n=await n),!n)break;const r=On(n);if(!r)break;const i=r.id;let s=r.size;const a=n.filePos;if(i===re.EBML){rr(s);let o=this.reader.requestSlice(a,s);if(ie(o)&&(o=await o),!o)break;this.readContiguousElements(o)}else if(i===re.Segment){if(await this.readSegment(a,s),s===void 0||this.reader.fileSize===null)break}else if(i===re.Cluster){if(this.reader.fileSize===null)break;s===void 0&&(s=(await Lo(this.reader,a,Gs,this.reader.fileSize)).pos-a);const o=Mt(this.segments);o&&(o.elementEndPos=a+s)}rr(s),e=a+s}})()}async readSegment(e,n){this.currentSegment={seekHeadSeen:!1,infoSeen:!1,tracksSeen:!1,cuesSeen:!1,tagsSeen:!1,attachmentsSeen:!1,timestampScale:-1,timestampFactor:-1,duration:-1,seekEntries:[],tracks:[],cuePoints:[],dataStartPos:e,elementEndPos:n===void 0?null:e+n,clusterSeekStartPos:e,lastReadCluster:null,metadataTags:{},metadataTagsCollected:!1},this.segments.push(this.currentSegment);let r=e;for(;this.currentSegment.elementEndPos===null||r<this.currentSegment.elementEndPos;){let o=this.reader.requestSliceRange(r,Xt,Ln);if(ie(o)&&(o=await o),!o)break;const c=r,u=On(o);if(!u||!Oi.includes(u.id)&&u.id!==re.Void){const p=await cu(this.reader,c,Oi,Math.min(this.currentSegment.elementEndPos??1/0,c+lu));if(p){r=p;continue}else break}const{id:l,size:f}=u,d=o.filePos,h=Oo.findIndex(p=>p.id===l);if(h!==-1){const p=Oo[h].flag;this.currentSegment[p]=!0,rr(f);let m=this.reader.requestSlice(d,f);ie(m)&&(m=await m),m&&this.readContiguousElements(m)}else if(l===re.Tags||l===re.Attachments){l===re.Tags?this.currentSegment.tagsSeen=!0:this.currentSegment.attachmentsSeen=!0,rr(f);let p=this.reader.requestSlice(d,f);ie(p)&&(p=await p),p&&this.readContiguousElements(p)}else if(l===re.Cluster){this.currentSegment.clusterSeekStartPos=c;break}if(f===void 0)break;r=d+f}if(this.currentSegment.seekEntries.sort((o,c)=>o.segmentPosition-c.segmentPosition),this.reader.fileSize!==null)for(const o of this.currentSegment.seekEntries){const c=Oo.find(p=>p.id===o.id);if(!c||this.currentSegment[c.flag])continue;let u=this.reader.requestSliceRange(e+o.segmentPosition,Xt,Ln);if(ie(u)&&(u=await u),!u)continue;const l=On(u);if(!l)continue;const{id:f,size:d}=l;if(f!==c.id)continue;rr(d),this.currentSegment[c.flag]=!0;let h=this.reader.requestSlice(u.filePos,d);ie(h)&&(h=await h),h&&this.readContiguousElements(h)}this.currentSegment.timestampScale===-1&&(this.currentSegment.timestampScale=1e6,this.currentSegment.timestampFactor=1e9/1e6);for(const o of this.currentSegment.tracks)o.defaultDurationNs!==null&&(o.defaultDuration=this.currentSegment.timestampFactor*o.defaultDurationNs/1e9);const i=new Map(this.currentSegment.tracks.map(o=>[o.id,o]));for(const o of this.currentSegment.cuePoints){const c=i.get(o.trackId);c&&c.cuePoints.push(o)}for(const o of this.currentSegment.tracks){o.cuePoints.sort((c,u)=>c.time-u.time);for(let c=0;c<o.cuePoints.length-1;c++){const u=o.cuePoints[c],l=o.cuePoints[c+1];u.time===l.time&&(o.cuePoints.splice(c+1,1),c--)}}let s=null,a=-1/0;for(const o of this.currentSegment.tracks)o.cuePoints.length>a&&(a=o.cuePoints.length,s=o);for(const o of this.currentSegment.tracks)o.cuePoints.length===0&&(o.cuePoints=s.cuePoints);this.currentSegment=null}async readCluster(e,n){if(n.lastReadCluster?.elementStartPos===e)return n.lastReadCluster;let r=this.reader.requestSliceRange(e,Xt,Ln);ie(r)&&(r=await r),R(r);const i=e,s=On(r);R(s);const a=s.id;R(a===re.Cluster);let o=s.size;const c=r.filePos;o===void 0&&(o=(await Lo(this.reader,c,Gs,n.elementEndPos)).pos-c);let u=this.reader.requestSlice(c,o);ie(u)&&(u=await u);const l={segment:n,elementStartPos:i,elementEndPos:c+o,dataStartPos:c,timestamp:-1,trackData:new Map};if(this.currentCluster=l,u){const f=this.readContiguousElements(u,Gs);l.elementEndPos=f}for(const[,f]of l.trackData){const d=f.track;R(f.blocks.length>0);let h=!1;for(let w=0;w<f.blocks.length;w++){const y=f.blocks[w];y.timestamp+=l.timestamp,h||=y.lacing!==Un.None}f.presentationTimestamps=f.blocks.map((w,y)=>({timestamp:w.timestamp,blockIndex:y})).sort((w,y)=>w.timestamp-y.timestamp);for(let w=0;w<f.presentationTimestamps.length;w++){const y=f.presentationTimestamps[w],b=f.blocks[y.blockIndex];if(f.firstKeyFrameTimestamp===null&&b.isKeyFrame&&(f.firstKeyFrameTimestamp=b.timestamp),w<f.presentationTimestamps.length-1){const v=f.presentationTimestamps[w+1];b.duration=v.timestamp-b.timestamp}else b.duration===0&&d.defaultDuration!=null&&b.lacing===Un.None&&(b.duration=d.defaultDuration)}h&&(this.expandLacedBlocks(f.blocks,d),f.presentationTimestamps=f.blocks.map((w,y)=>({timestamp:w.timestamp,blockIndex:y})).sort((w,y)=>w.timestamp-y.timestamp));const p=f.blocks[f.presentationTimestamps[0].blockIndex],m=f.blocks[Mt(f.presentationTimestamps).blockIndex];f.startTimestamp=p.timestamp,f.endTimestamp=m.timestamp+m.duration;const g=_e(d.clusterPositionCache,f.startTimestamp,w=>w.startTimestamp);(g===-1||d.clusterPositionCache[g].elementStartPos!==i)&&d.clusterPositionCache.splice(g+1,0,{elementStartPos:l.elementStartPos,startTimestamp:f.startTimestamp})}return n.lastReadCluster=l,l}getTrackDataInCluster(e,n){let r=e.trackData.get(n);if(!r){const i=e.segment.tracks.find(s=>s.id===n);if(!i)return null;r={track:i,startTimestamp:0,endTimestamp:0,firstKeyFrameTimestamp:null,blocks:[],presentationTimestamps:[]},e.trackData.set(n,r)}return r}expandLacedBlocks(e,n){for(let r=0;r<e.length;r++){const i=e[r];if(i.lacing===Un.None)continue;i.decoded||(i.data=this.decodeBlockData(n,i.data),i.decoded=!0);const s=tn.tempFromBytes(i.data),a=[],o=de(s)+1;switch(i.lacing){case Un.Xiph:{let u=0;for(let l=0;l<o-1;l++){let f=0;for(;s.bufferPos<s.length;){const d=de(s);if(f+=d,d<255){a.push(f),u+=f;break}}}a.push(s.length-(s.bufferPos+u))}break;case Un.FixedSize:{const u=s.length-1,l=Math.floor(u/o);for(let f=0;f<o;f++)a.push(l)}break;case Un.Ebml:{const u=Ui(s);R(u!==null);let l=u;a.push(l);let f=l;for(let d=1;d<o-1;d++){const h=s.bufferPos,p=Ui(s);R(p!==null);const m=p,w=(1<<(s.bufferPos-h)*7-1)-1,y=m-w;l+=y,a.push(l),f+=l}a.push(s.length-(s.bufferPos+f))}break;default:R(!1)}R(a.length===o),e.splice(r,1);const c=i.duration||o*(n.defaultDuration??0);for(let u=0;u<o;u++){const l=a[u],f=me(s,l),d=i.timestamp+c*u/o,h=c/o;e.splice(r+u,0,{timestamp:d,duration:h,isKeyFrame:i.isKeyFrame,data:f,lacing:Un.None,decoded:!0,postProcessed:!1,mainAdditional:i.mainAdditional})}r+=o,r--}}async loadSegmentMetadata(e){for(const n of e.seekEntries){if(!(n.id===re.Tags&&!e.tagsSeen)){if(!(n.id===re.Attachments&&!e.attachmentsSeen))continue}let r=this.reader.requestSliceRange(e.dataStartPos+n.segmentPosition,Xt,Ln);if(ie(r)&&(r=await r),!r)continue;const i=On(r);if(!i||i.id!==n.id)continue;const{size:s}=i;rr(s),R(!this.currentSegment),this.currentSegment=e;let a=this.reader.requestSlice(r.filePos,s);ie(a)&&(a=await a),a&&this.readContiguousElements(a),this.currentSegment=null,n.id===re.Tags?e.tagsSeen=!0:n.id===re.Attachments&&(e.attachmentsSeen=!0)}}readContiguousElements(e,n){for(;e.remainingLength>=Xt;){const r=e.filePos;if(!this.traverseElement(e,n))return r}return e.filePos}traverseElement(e,n){const r=On(e);if(!r||n&&n.includes(r.id))return!1;const{id:i,size:s}=r,a=e.filePos;switch(rr(s),i){case re.DocType:this.isWebM=si(e,s)==="webm";break;case re.Seek:{if(!this.currentSegment)break;const o={id:-1,segmentPosition:-1};this.currentSegment.seekEntries.push(o),this.readContiguousElements(e.slice(a,s)),(o.id===-1||o.segmentPosition===-1)&&this.currentSegment.seekEntries.pop()}break;case re.SeekID:{const o=this.currentSegment?.seekEntries[this.currentSegment.seekEntries.length-1];if(!o)break;o.id=Ae(e,s)}break;case re.SeekPosition:{const o=this.currentSegment?.seekEntries[this.currentSegment.seekEntries.length-1];if(!o)break;o.segmentPosition=Ae(e,s)}break;case re.TimestampScale:{if(!this.currentSegment)break;this.currentSegment.timestampScale=Ae(e,s),this.currentSegment.timestampFactor=1e9/this.currentSegment.timestampScale}break;case re.Duration:{if(!this.currentSegment)break;this.currentSegment.duration=No(e,s)}break;case re.TrackEntry:{if(!this.currentSegment||(this.currentTrack={id:-1,segment:this.currentSegment,demuxer:this,clusterPositionCache:[],cuePoints:[],disposition:{...Fn,primary:!1},trackBacking:null,codecId:null,codecPrivate:null,defaultDuration:null,defaultDurationNs:null,name:null,languageCode:"eng",hasLanguageBcp47:!1,decodingInstructions:[],info:null},this.readContiguousElements(e.slice(a,s)),!this.currentTrack))break;if(this.currentTrack.decodingInstructions.some(o=>o.data?.type!=="decompress"||o.scope!==$s.Block||o.data.algorithm!==Hi.HeaderStripping)&&(pe._warn(`Track #${this.currentTrack.id} has an unsupported content encoding; dropping.`),this.currentTrack=null),this.currentTrack&&this.currentTrack.id!==-1&&this.currentTrack.codecId&&this.currentTrack.info){const o=this.currentTrack.codecId.indexOf("/"),c=o===-1?this.currentTrack.codecId:this.currentTrack.codecId.slice(0,o);if(this.currentTrack.info.type==="video"&&this.currentTrack.info.width!==-1&&this.currentTrack.info.height!==-1){if(this.currentTrack.info.squarePixelWidth=this.currentTrack.info.width,this.currentTrack.info.squarePixelHeight=this.currentTrack.info.height,this.currentTrack.info.displayWidth!==null&&this.currentTrack.info.displayHeight!==null){const l=this.currentTrack.info.displayWidth*this.currentTrack.info.height,f=this.currentTrack.info.displayHeight*this.currentTrack.info.width;l>0&&f>0&&(l>f?this.currentTrack.info.squarePixelWidth=Math.round(this.currentTrack.info.width*l/f):this.currentTrack.info.squarePixelHeight=Math.round(this.currentTrack.info.height*f/l))}if(this.currentTrack.codecId===Rt.avc)this.currentTrack.info.codec="avc",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate;else if(this.currentTrack.codecId===Rt.hevc)this.currentTrack.info.codec="hevc",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate;else if(c===Rt.vp8)this.currentTrack.info.codec="vp8";else if(c===Rt.vp9)this.currentTrack.info.codec="vp9";else if(c===Rt.av1)this.currentTrack.info.codec="av1";else if(c===Rt.prores){const l=this.currentTrack.codecPrivate?Bt.decode(this.currentTrack.codecPrivate):"";To.includes(l)&&(this.currentTrack.info.codec="prores",this.currentTrack.info.proresFormat=l)}const u=this.currentTrack;this.currentTrack.trackBacking=new Zm(u),this.currentSegment.tracks.push(this.currentTrack)}else if(this.currentTrack.info.type==="audio"){c===Rt.aac?(this.currentTrack.info.codec="aac",this.currentTrack.info.aacCodecInfo={isMpeg2:this.currentTrack.codecId.includes("MPEG2"),objectType:null},this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):this.currentTrack.codecId===Rt.mp3?this.currentTrack.info.codec="mp3":c===Rt.opus?(this.currentTrack.info.codec="opus",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate,this.currentTrack.info.sampleRate=qs):c===Rt.vorbis?(this.currentTrack.info.codec="vorbis",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):c===Rt.flac?(this.currentTrack.info.codec="flac",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):c===Rt.ac3?(this.currentTrack.info.codec="ac3",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):c===Rt.eac3?(this.currentTrack.info.codec="eac3",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):c===Rt.dts?(this.currentTrack.info.codec="dts",this.currentTrack.codecId==="A_DTS/EXPRESS"?this.currentTrack.info.dtsFormat="dtse":this.currentTrack.codecId==="A_DTS/LOSSLESS"&&(this.currentTrack.info.dtsFormat="dtsl")):this.currentTrack.codecId==="A_PCM/INT/LIT"?this.currentTrack.info.bitDepth===8?this.currentTrack.info.codec="pcm-u8":this.currentTrack.info.bitDepth===16?this.currentTrack.info.codec="pcm-s16":this.currentTrack.info.bitDepth===24?this.currentTrack.info.codec="pcm-s24":this.currentTrack.info.bitDepth===32&&(this.currentTrack.info.codec="pcm-s32"):this.currentTrack.codecId==="A_PCM/INT/BIG"?this.currentTrack.info.bitDepth===8?this.currentTrack.info.codec="pcm-u8":this.currentTrack.info.bitDepth===16?this.currentTrack.info.codec="pcm-s16be":this.currentTrack.info.bitDepth===24?this.currentTrack.info.codec="pcm-s24be":this.currentTrack.info.bitDepth===32&&(this.currentTrack.info.codec="pcm-s32be"):this.currentTrack.codecId==="A_PCM/FLOAT/IEEE"&&(this.currentTrack.info.bitDepth===32?this.currentTrack.info.codec="pcm-f32":this.currentTrack.info.bitDepth===64&&(this.currentTrack.info.codec="pcm-f64"));const u=this.currentTrack;this.currentTrack.trackBacking=new Jm(u),this.currentSegment.tracks.push(this.currentTrack)}}this.currentTrack=null}break;case re.TrackNumber:{if(!this.currentTrack)break;this.currentTrack.id=Ae(e,s)}break;case re.TrackType:{if(!this.currentTrack)break;const o=Ae(e,s);o===1?this.currentTrack.info={type:"video",width:-1,height:-1,displayWidth:null,displayHeight:null,displayUnit:null,squarePixelWidth:-1,squarePixelHeight:-1,rotation:0,codec:null,codecDescription:null,colorSpace:{...il},alphaMode:!1,proresFormat:null}:o===2&&(this.currentTrack.info={type:"audio",numberOfChannels:1,sampleRate:8e3,bitDepth:-1,codec:null,codecDescription:null,aacCodecInfo:null,dtsFormat:null})}break;case re.FlagEnabled:{if(!this.currentTrack)break;Ae(e,s)||(this.currentTrack=null)}break;case re.FlagDefault:{if(!this.currentTrack)break;this.currentTrack.disposition.default=!!Ae(e,s)}break;case re.FlagForced:{if(!this.currentTrack)break;this.currentTrack.disposition.forced=!!Ae(e,s)}break;case re.FlagOriginal:{if(!this.currentTrack)break;this.currentTrack.disposition.original=!!Ae(e,s)}break;case re.FlagHearingImpaired:{if(!this.currentTrack)break;this.currentTrack.disposition.hearingImpaired=!!Ae(e,s)}break;case re.FlagVisualImpaired:{if(!this.currentTrack)break;this.currentTrack.disposition.visuallyImpaired=!!Ae(e,s)}break;case re.FlagCommentary:{if(!this.currentTrack)break;this.currentTrack.disposition.commentary=!!Ae(e,s)}break;case re.CodecID:{if(!this.currentTrack)break;this.currentTrack.codecId=si(e,s)}break;case re.CodecPrivate:{if(!this.currentTrack)break;this.currentTrack.codecPrivate=me(e,s)}break;case re.DefaultDuration:{if(!this.currentTrack)break;this.currentTrack.defaultDurationNs=Ae(e,s)}break;case re.Name:{if(!this.currentTrack)break;this.currentTrack.name=zi(e,s)}break;case re.Language:{if(!this.currentTrack||this.currentTrack.hasLanguageBcp47)break;this.currentTrack.languageCode=si(e,s),ul(this.currentTrack.languageCode)||(this.currentTrack.languageCode=Tt)}break;case re.LanguageBCP47:{if(!this.currentTrack)break;const c=si(e,s).split("-")[0];c?this.currentTrack.languageCode=c:this.currentTrack.languageCode=Tt,this.currentTrack.hasLanguageBcp47=!0}break;case re.Video:{if(this.currentTrack?.info?.type!=="video")break;this.readContiguousElements(e.slice(a,s))}break;case re.PixelWidth:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.width=Ae(e,s)}break;case re.PixelHeight:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.height=Ae(e,s)}break;case re.DisplayWidth:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.displayWidth=Ae(e,s)}break;case re.DisplayHeight:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.displayHeight=Ae(e,s)}break;case re.DisplayUnit:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.displayUnit=Ae(e,s)}break;case re.AlphaMode:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.alphaMode=Ae(e,s)===1}break;case re.Colour:{if(this.currentTrack?.info?.type!=="video")break;this.readContiguousElements(e.slice(a,s))}break;case re.MatrixCoefficients:{if(this.currentTrack?.info?.type!=="video")break;const o=Ae(e,s),c=Rn[o];this.currentTrack.info.colorSpace.matrix=c}break;case re.Range:{if(this.currentTrack?.info?.type!=="video")break;const o=Ae(e,s);this.currentTrack.info.colorSpace.fullRange=o===1||o===2?o===2:void 0}break;case re.TransferCharacteristics:{if(this.currentTrack?.info?.type!=="video")break;const o=Ae(e,s),c=Bn[o];this.currentTrack.info.colorSpace.transfer=c}break;case re.Primaries:{if(this.currentTrack?.info?.type!=="video")break;const o=Ae(e,s),c=Mn[o];this.currentTrack.info.colorSpace.primaries=c}break;case re.Projection:{if(this.currentTrack?.info?.type!=="video")break;this.readContiguousElements(e.slice(a,s))}break;case re.ProjectionPoseRoll:{if(this.currentTrack?.info?.type!=="video")break;const c=-No(e,s);try{this.currentTrack.info.rotation=Wa(c)}catch{}}break;case re.Audio:{if(this.currentTrack?.info?.type!=="audio")break;this.readContiguousElements(e.slice(a,s))}break;case re.SamplingFrequency:{if(this.currentTrack?.info?.type!=="audio")break;this.currentTrack.info.sampleRate=No(e,s)}break;case re.Channels:{if(this.currentTrack?.info?.type!=="audio")break;this.currentTrack.info.numberOfChannels=Ae(e,s)}break;case re.BitDepth:{if(this.currentTrack?.info?.type!=="audio")break;this.currentTrack.info.bitDepth=Ae(e,s)}break;case re.CuePoint:{if(!this.currentSegment)break;this.readContiguousElements(e.slice(a,s)),this.currentCueTime=null}break;case re.CueTime:this.currentCueTime=Ae(e,s);break;case re.CueTrackPositions:{if(this.currentCueTime===null)break;R(this.currentSegment);const o={time:this.currentCueTime,trackId:-1,clusterPosition:-1};this.currentSegment.cuePoints.push(o),this.readContiguousElements(e.slice(a,s)),(o.trackId===-1||o.clusterPosition===-1)&&this.currentSegment.cuePoints.pop()}break;case re.CueTrack:{const o=this.currentSegment?.cuePoints[this.currentSegment.cuePoints.length-1];if(!o)break;o.trackId=Ae(e,s)}break;case re.CueClusterPosition:{const o=this.currentSegment?.cuePoints[this.currentSegment.cuePoints.length-1];if(!o)break;R(this.currentSegment),o.clusterPosition=this.currentSegment.dataStartPos+Ae(e,s)}break;case re.Timestamp:{if(!this.currentCluster)break;this.currentCluster.timestamp=Ae(e,s)}break;case re.SimpleBlock:{if(!this.currentCluster)break;const o=Ui(e);if(o===null)break;const c=this.getTrackDataInCluster(this.currentCluster,o);if(!c)break;const u=nc(e),l=de(e),f=l>>1&3;let d=!!(l&128);c.track.info?.type==="audio"&&c.track.info.codec&&(d=!0);const h=me(e,s-(e.filePos-a)),p=c.track.decodingInstructions.length>0;c.blocks.push({timestamp:u,duration:0,isKeyFrame:d,data:h,lacing:f,decoded:!p,postProcessed:!1,mainAdditional:null})}break;case re.BlockGroup:{if(!this.currentCluster)break;this.readContiguousElements(e.slice(a,s)),this.currentBlock=null}break;case re.Block:{if(!this.currentCluster)break;const o=Ui(e);if(o===null)break;const c=this.getTrackDataInCluster(this.currentCluster,o);if(!c)break;const u=nc(e),f=de(e)>>1&3,d=me(e,s-(e.filePos-a)),h=c.track.decodingInstructions.length>0;this.currentBlock={timestamp:u,duration:0,isKeyFrame:!0,data:d,lacing:f,decoded:!h,postProcessed:!1,mainAdditional:null},c.blocks.push(this.currentBlock)}break;case re.BlockAdditions:this.readContiguousElements(e.slice(a,s));break;case re.BlockMore:{if(!this.currentBlock)break;this.currentBlockAdditional={addId:1,data:null},this.readContiguousElements(e.slice(a,s)),this.currentBlockAdditional.data&&this.currentBlockAdditional.addId===1&&(this.currentBlock.mainAdditional=this.currentBlockAdditional.data),this.currentBlockAdditional=null}break;case re.BlockAdditional:{if(!this.currentBlockAdditional)break;this.currentBlockAdditional.data=me(e,s)}break;case re.BlockAddID:{if(!this.currentBlockAdditional)break;this.currentBlockAdditional.addId=Ae(e,s)}break;case re.BlockDuration:{if(!this.currentBlock)break;this.currentBlock.duration=Ae(e,s)}break;case re.ReferenceBlock:{if(!this.currentBlock)break;this.currentBlock.isKeyFrame=!1}break;case re.Tag:this.currentTagTargetIsMovie=!0,this.readContiguousElements(e.slice(a,s));break;case re.Targets:this.readContiguousElements(e.slice(a,s));break;case re.TargetTypeValue:Ae(e,s)!==50&&(this.currentTagTargetIsMovie=!1);break;case re.TagTrackUID:case re.TagEditionUID:case re.TagChapterUID:case re.TagAttachmentUID:this.currentTagTargetIsMovie=!1;break;case re.SimpleTag:{if(!this.currentTagTargetIsMovie)break;this.currentSimpleTagName=null,this.readContiguousElements(e.slice(a,s))}break;case re.TagName:this.currentSimpleTagName=zi(e,s);break;case re.TagString:{if(!this.currentSimpleTagName)break;const o=zi(e,s);this.processTagValue(this.currentSimpleTagName,o)}break;case re.TagBinary:{if(!this.currentSimpleTagName)break;const o=me(e,s);this.processTagValue(this.currentSimpleTagName,o)}break;case re.AttachedFile:{if(!this.currentSegment)break;this.currentAttachedFile={fileUid:null,fileName:null,fileMediaType:null,fileData:null,fileDescription:null},this.readContiguousElements(e.slice(a,s));const o=this.currentSegment.metadataTags;if(this.currentAttachedFile.fileUid&&this.currentAttachedFile.fileData&&(o.raw??={},o.raw[this.currentAttachedFile.fileUid.toString()]=new Yh(this.currentAttachedFile.fileData,this.currentAttachedFile.fileMediaType??void 0,this.currentAttachedFile.fileName??void 0,this.currentAttachedFile.fileDescription??void 0)),this.currentAttachedFile.fileMediaType?.startsWith("image/")&&this.currentAttachedFile.fileData){const c=this.currentAttachedFile.fileName;let u="unknown";if(c){const l=c.toLowerCase();l.startsWith("cover.")?u="coverFront":l.startsWith("back.")&&(u="coverBack")}o.images??=[],o.images.push({data:this.currentAttachedFile.fileData,mimeType:this.currentAttachedFile.fileMediaType,kind:u,name:this.currentAttachedFile.fileName??void 0,description:this.currentAttachedFile.fileDescription??void 0})}this.currentAttachedFile=null}break;case re.FileUID:{if(!this.currentAttachedFile)break;this.currentAttachedFile.fileUid=Qm(e,s)}break;case re.FileName:{if(!this.currentAttachedFile)break;this.currentAttachedFile.fileName=zi(e,s)}break;case re.FileMediaType:{if(!this.currentAttachedFile)break;this.currentAttachedFile.fileMediaType=si(e,s)}break;case re.FileData:{if(!this.currentAttachedFile)break;this.currentAttachedFile.fileData=me(e,s)}break;case re.FileDescription:{if(!this.currentAttachedFile)break;this.currentAttachedFile.fileDescription=zi(e,s)}break;case re.ContentEncodings:{if(!this.currentTrack)break;this.readContiguousElements(e.slice(a,s)),this.currentTrack.decodingInstructions.sort((o,c)=>c.order-o.order)}break;case re.ContentEncoding:this.currentDecodingInstruction={order:0,scope:$s.Block,data:null},this.readContiguousElements(e.slice(a,s)),this.currentDecodingInstruction.data&&this.currentTrack.decodingInstructions.push(this.currentDecodingInstruction),this.currentDecodingInstruction=null;break;case re.ContentEncodingOrder:{if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.order=Ae(e,s)}break;case re.ContentEncodingScope:{if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.scope=Ae(e,s)}break;case re.ContentCompression:{if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.data={type:"decompress",algorithm:Hi.Zlib,settings:null},this.readContiguousElements(e.slice(a,s))}break;case re.ContentCompAlgo:{if(this.currentDecodingInstruction?.data?.type!=="decompress")break;this.currentDecodingInstruction.data.algorithm=Ae(e,s)}break;case re.ContentCompSettings:{if(this.currentDecodingInstruction?.data?.type!=="decompress")break;this.currentDecodingInstruction.data.settings=me(e,s)}break;case re.ContentEncryption:{if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.data={type:"decrypt"}}break}return e.filePos=a+s,!0}decodeBlockData(e,n){R(e.decodingInstructions.length>0);let r=n;for(const i of e.decodingInstructions)switch(R(i.data),i.data.type){case"decompress":switch(i.data.algorithm){case Hi.HeaderStripping:if(i.data.settings&&i.data.settings.length>0){const s=i.data.settings,a=new Uint8Array(s.length+r.length);a.set(s,0),a.set(r,s.length),r=a}break}break}return r}processTagValue(e,n){if(!this.currentSegment?.metadataTags)return;const r=this.currentSegment.metadataTags;if(r.raw??={},r.raw[e]??=n,typeof n=="string")switch(e.toLowerCase()){case"title":r.title??=n;break;case"description":r.description??=n;break;case"artist":r.artist??=n;break;case"album":r.album??=n;break;case"album_artist":r.albumArtist??=n;break;case"genre":r.genre??=n;break;case"comment":r.comment??=n;break;case"lyrics":r.lyrics??=n;break;case"date":{const i=new Date(n);Number.isNaN(i.getTime())||(r.date??=i)}break;case"track_number":case"part_number":{const i=n.split("/"),s=Number.parseInt(i[0],10),a=i[1]&&Number.parseInt(i[1],10);Number.isInteger(s)&&s>0&&(r.trackNumber??=s),a&&Number.isInteger(a)&&a>0&&(r.tracksTotal??=a)}break;case"disc_number":case"disc":{const i=n.split("/"),s=Number.parseInt(i[0],10),a=i[1]&&Number.parseInt(i[1],10);Number.isInteger(s)&&s>0&&(r.discNumber??=s),a&&Number.isInteger(a)&&a>0&&(r.discsTotal??=a)}break}}async getDurationFromMetadata(e){if(e.duration<=0)return null;let n=null;for(const i of e.tracks){R(i.trackBacking);const s=await i.trackBacking.getFirstPacket({metadataOnly:!0});s&&(n=Math.min(n??1/0,s.timestamp))}let r=e.duration/e.timestampFactor;return r+=n??0,r}}class uu{constructor(e){this.internalTrack=e,this.packetToClusterLocation=new WeakMap}getId(){return this.internalTrack.id}getNumber(){const e=this.internalTrack.demuxer,n=this.internalTrack.trackBacking.getType();let r=0;for(const i of e.segments)for(const s of i.tracks)if(s.trackBacking.getType()===n&&r++,s===this.internalTrack)break;return r}getCodec(){throw new Error("Not implemented on base class.")}getInternalCodecId(){return this.internalTrack.codecId}getName(){return this.internalTrack.name}getLanguageCode(){return this.internalTrack.languageCode}getTimeResolution(){return this.internalTrack.segment.timestampFactor}isRelativeToUnixEpoch(){return!1}getUnixTimeForTimestamp(){return null}getDisposition(){return this.internalTrack.disposition}getPairingMask(){return 1n}getBitrate(){return null}getAverageBitrate(){return null}async getDurationFromMetadata(){return this.internalTrack.demuxer.getDurationFromMetadata(this.internalTrack.segment)}async getLiveRefreshInterval(){return null}async getFirstPacket(e){return this.performClusterLookup(null,n=>n.trackData.get(this.internalTrack.id)?{blockIndex:0,correctBlockFound:!0}:{blockIndex:-1,correctBlockFound:!1},-1/0,1/0,e)}intoTimescale(e){return Bi(e*this.internalTrack.segment.timestampFactor)}async getPacket(e,n){const r=this.intoTimescale(e);return this.performClusterLookup(null,i=>{const s=i.trackData.get(this.internalTrack.id);if(!s)return{blockIndex:-1,correctBlockFound:!1};const a=_e(s.presentationTimestamps,r,u=>u.timestamp),o=a!==-1?s.presentationTimestamps[a].blockIndex:-1,c=a!==-1&&r<s.endTimestamp;return{blockIndex:o,correctBlockFound:c}},r,r,n)}async getNextPacket(e,n){const r=this.packetToClusterLocation.get(e);if(r===void 0)throw new Error("Packet was not created from this track.");return this.performClusterLookup(r.cluster,i=>{if(i===r.cluster){const s=i.trackData.get(this.internalTrack.id);if(r.blockIndex+1<s.blocks.length)return{blockIndex:r.blockIndex+1,correctBlockFound:!0}}else if(i.trackData.get(this.internalTrack.id))return{blockIndex:0,correctBlockFound:!0};return{blockIndex:-1,correctBlockFound:!1}},-1/0,1/0,n)}async getKeyPacket(e,n){const r=this.intoTimescale(e);return this.performClusterLookup(null,i=>{const s=i.trackData.get(this.internalTrack.id);if(!s)return{blockIndex:-1,correctBlockFound:!1};const a=Ya(s.presentationTimestamps,u=>s.blocks[u.blockIndex].isKeyFrame&&u.timestamp<=r),o=a!==-1?s.presentationTimestamps[a].blockIndex:-1,c=a!==-1&&r<s.endTimestamp;return{blockIndex:o,correctBlockFound:c}},r,r,n)}async getNextKeyPacket(e,n){const r=this.packetToClusterLocation.get(e);if(r===void 0)throw new Error("Packet was not created from this track.");return this.performClusterLookup(r.cluster,i=>{if(i===r.cluster){const a=i.trackData.get(this.internalTrack.id).blocks.findIndex((o,c)=>o.isKeyFrame&&c>r.blockIndex);if(a!==-1)return{blockIndex:a,correctBlockFound:!0}}else{const s=i.trackData.get(this.internalTrack.id);if(s&&s.firstKeyFrameTimestamp!==null){const a=s.blocks.findIndex(o=>o.isKeyFrame);return R(a!==-1),{blockIndex:a,correctBlockFound:!0}}}return{blockIndex:-1,correctBlockFound:!1}},-1/0,1/0,n)}async fetchPacketInCluster(e,n,r){if(n===-1)return null;const s=e.trackData.get(this.internalTrack.id).blocks[n];if(R(s),s.decoded||(s.data=this.internalTrack.demuxer.decodeBlockData(this.internalTrack,s.data),s.decoded=!0),!s.postProcessed){if(this.internalTrack.info?.codec==="prores"&&!(s.data.length>=8&&s.data[4]===105&&s.data[5]===99&&s.data[6]===112&&s.data[7]===102)){const d=new Uint8Array(s.data.length+8);Ie(d).setUint32(0,d.length,!1),d[4]=105,d[5]=99,d[6]=112,d[7]=102,d.set(s.data,8),s.data=d}s.postProcessed=!0}const a=r.metadataOnly?Ut:s.data,o=s.timestamp/this.internalTrack.segment.timestampFactor,c=s.duration/this.internalTrack.segment.timestampFactor,u={};s.mainAdditional&&this.internalTrack.info?.type==="video"&&this.internalTrack.info.alphaMode&&(u.alpha=r.metadataOnly?Ut:s.mainAdditional,u.alphaByteLength=s.mainAdditional.byteLength);const l=new Qe(a,s.isKeyFrame?"key":"delta",o,c,e.dataStartPos+n,s.data.byteLength,u);return this.packetToClusterLocation.set(l,{cluster:e,blockIndex:n}),l}async performClusterLookup(e,n,r,i,s){const{demuxer:a,segment:o}=this.internalTrack;let c=null,u=null,l=-1;if(e){const{blockIndex:w,correctBlockFound:y}=n(e);if(y)return this.fetchPacketInCluster(e,w,s);w!==-1&&(u=e,l=w)}const f=_e(this.internalTrack.cuePoints,r,w=>w.time),d=f!==-1?this.internalTrack.cuePoints[f]:null,h=_e(this.internalTrack.clusterPositionCache,r,w=>w.startTimestamp),p=h!==-1?this.internalTrack.clusterPositionCache[h]:null,m=Math.max(d?.clusterPosition??0,p?.elementStartPos??0)||null;let g;for(e?m===null||e.elementStartPos>=m?(g=e.elementEndPos,c=e):g=m:g=m??o.clusterSeekStartPos;o.elementEndPos===null||g<=o.elementEndPos-Xt;){if(c){const S=c.trackData.get(this.internalTrack.id);if(S&&S.startTimestamp>i)break}let w=a.reader.requestSliceRange(g,Xt,Ln);if(ie(w)&&(w=await w),!w)break;const y=g,b=On(w);if(!b||!Oi.includes(b.id)&&b.id!==re.Void){const S=await cu(a.reader,y,Oi,Math.min(o.elementEndPos??1/0,y+lu));if(S){g=S;continue}else break}const v=b.id;let k=b.size;const A=w.filePos;if(v===re.Cluster){c=await a.readCluster(y,o),k=c.elementEndPos-A;const{blockIndex:S,correctBlockFound:P}=n(c);if(P)return this.fetchPacketInCluster(c,S,s);S!==-1&&(u=c,l=S)}k===void 0&&(R(v!==re.Cluster),k=(await Lo(a.reader,A,Gs,o.elementEndPos)).pos-A);const T=A+k;if(o.elementEndPos===null){let S=a.reader.requestSliceRange(T,Xt,Ln);if(ie(S)&&(S=await S),!S)break;if(Do(S)===re.Segment){o.elementEndPos=T;break}}g=T}if(d&&(!u||u.elementStartPos<d.clusterPosition)){const w=this.internalTrack.cuePoints[f-1];R(!w||w.time<d.time);const y=w?.time??-1/0;return this.performClusterLookup(null,n,y,i,s)}return u?this.fetchPacketInCluster(u,l,s):null}}class Zm extends uu{constructor(e){super(e),this.decoderConfigPromise=null,this.internalTrack=e}getType(){return"video"}getCodec(){return this.internalTrack.info.codec}getCodedWidth(){return this.internalTrack.info.width}getCodedHeight(){return this.internalTrack.info.height}getSquarePixelWidth(){return this.internalTrack.info.squarePixelWidth}getSquarePixelHeight(){return this.internalTrack.info.squarePixelHeight}getRotation(){return this.internalTrack.info.rotation}async getColorSpace(){const e=await this.getDecoderConfig();return e?{primaries:e.colorSpace?.primaries,transfer:e.colorSpace?.transfer,matrix:e.colorSpace?.matrix,fullRange:e.colorSpace?.fullRange}:this.internalTrack.info.colorSpace}async canBeTransparent(){return this.internalTrack.info.alphaMode||this.internalTrack.info.codec==="prores"&&(this.internalTrack.info.proresFormat==="ap4h"||this.internalTrack.info.proresFormat==="ap4x")}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfigPromise??=(async()=>{let e=null;(this.internalTrack.info.codec==="vp9"||this.internalTrack.info.codec==="av1"||this.internalTrack.info.codec==="prores"||this.internalTrack.info.codec==="avc"&&!this.internalTrack.info.codecDescription||this.internalTrack.info.codec==="hevc"&&!this.internalTrack.info.codecDescription)&&(e=await this.getFirstPacket({}));const r={width:this.internalTrack.info.width,height:this.internalTrack.info.height,codec:this.internalTrack.info.codec,codecDescription:this.internalTrack.info.codecDescription,colorSpace:this.internalTrack.info.colorSpace,avcType:1,avcCodecInfo:this.internalTrack.info.codec==="avc"&&e?go(e.data):null,hevcCodecInfo:this.internalTrack.info.codec==="hevc"&&e?bo(e.data):null,vp9CodecInfo:this.internalTrack.info.codec==="vp9"&&e?Tl(e.data):null,av1CodecInfo:this.internalTrack.info.codec==="av1"&&e?wo(e.data):null,proresCodecInfo:this.internalTrack.info.codec==="prores"&&e?Pl(e.data):null,proresFormat:this.internalTrack.info.proresFormat};if(!$a(this.internalTrack.info.colorSpace)){const s=Hl(r);this.internalTrack.info.colorSpace.primaries??=s.primaries,this.internalTrack.info.colorSpace.transfer??=s.transfer,this.internalTrack.info.colorSpace.matrix??=s.matrix,this.internalTrack.info.colorSpace.fullRange??=s.fullRange}const i={codec:So(r),codedWidth:this.internalTrack.info.width,codedHeight:this.internalTrack.info.height,description:this.internalTrack.info.codecDescription??void 0,colorSpace:this.internalTrack.info.colorSpace};return(this.internalTrack.info.width!==this.internalTrack.info.squarePixelWidth||this.internalTrack.info.height!==this.internalTrack.info.squarePixelHeight)&&(i.displayAspectWidth=this.internalTrack.info.squarePixelWidth,i.displayAspectHeight=this.internalTrack.info.squarePixelHeight),i})():null}}class Jm extends uu{constructor(e){super(e),this.decoderConfigPromise=null,this.internalTrack=e}getType(){return"audio"}getCodec(){return this.internalTrack.info.codec}getNumberOfChannels(){return this.internalTrack.info.numberOfChannels}getSampleRate(){return this.internalTrack.info.sampleRate}async getDecoderConfig(){return this.internalTrack.info.codec?this.decoderConfigPromise??=(async()=>{if(this.internalTrack.info.codec==="dts"&&!this.internalTrack.info.dtsFormat){const e=await this.getFirstPacket({});this.internalTrack.info.dtsFormat=e&&Rl(e.data)}return{codec:Po({codec:this.internalTrack.info.codec,codecDescription:this.internalTrack.info.codecDescription,aacCodecInfo:this.internalTrack.info.aacCodecInfo,dtsFormat:this.internalTrack.info.dtsFormat}),numberOfChannels:this.internalTrack.info.numberOfChannels,sampleRate:this.internalTrack.info.sampleRate,description:this.internalTrack.info.codecDescription??void 0}})():null}}const Uo=async(t,e,n,r=null)=>{let s=e;for(;n===null||s<n;){const a=n!==null?Math.min(65536,n-s):65536;let o=t.requestSliceRange(s,Tr,a);if(ie(o)&&(o=await o),!o||o.length<Tr)break;for(;o.remainingLength>=Tr;){const c=o.filePos,u=ae(o),l=t.fileSize!==null?t.fileSize-s:null,f=_o(u,l);if(f.header&&(!r||f.header.sampleRate===r.sampleRate&&f.header.mpegVersionId===r.mpegVersionId&&f.header.layer===r.layer&&Ni(f.header.channel)===Ni(r.channel)))return{header:f.header,startPos:s};o.filePos=c+f.bytesAdvanced,s=o.filePos}}return null};class ep extends Dn{constructor(e){super(e),this.metadataPromise=null,this.firstFrameHeader=null,this.firstFrameHeaderPos=null,this.xingFrameHeader=null,this.xingFrameHeaderPos=null,this.loadedSamples=[],this.metadataTags=null,this.xingData=null,this.trackBackings=[],this.readingMutex=new Cs,this.lastSampleLoaded=!1,this.lastLoadedPos=0,this.nextTimestampInSamples=0,this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{for(;!this.firstFrameHeader&&!this.lastSampleLoaded;)await this.advanceReader();if(!this.firstFrameHeader&&this.xingFrameHeader&&(this.firstFrameHeader=this.xingFrameHeader,this.firstFrameHeaderPos=this.xingFrameHeaderPos),!this.firstFrameHeader)throw new Error("No valid MP3 frame found.");this.trackBackings=[new tp(this)]})()}async advanceReader(){if(this.lastLoadedPos===0)for(;;){let o=this.reader.requestSlice(this.lastLoadedPos,Gt);if(ie(o)&&(o=await o),!o){this.lastSampleLoaded=!0;return}const c=Vn(o);if(!c)break;this.lastLoadedPos=o.filePos+c.size}const e=await Uo(this.reader,this.lastLoadedPos,this.reader.fileSize,this.firstFrameHeader);if(!e){this.lastSampleLoaded=!0;return}const n=e.header;this.lastLoadedPos=e.startPos+n.totalSize-1;const r=ql(n.mpegVersionId,n.channel);let i=this.reader.requestSlice(e.startPos+r,4);if(ie(i)&&(i=await i),i){const o=ae(i);if(o===Wl||o===jl){if(this.xingFrameHeader||(this.xingFrameHeader=n,this.xingFrameHeaderPos=e.startPos),!this.xingData){let u=this.reader.requestSlice(e.startPos+r+4,12);if(ie(u)&&(u=await u),u){const l=me(u,12),f=Ie(l),d=f.getUint32(0,!1);this.xingData={frameCount:d&Xs.FrameCount?f.getUint32(4,!1):null,fileSize:d&Xs.FileSize?f.getUint32(8,!1):null}}}return}}this.firstFrameHeader||(this.firstFrameHeader=n,this.firstFrameHeaderPos=e.startPos);const s=n.audioSamplesInFrame/this.firstFrameHeader.sampleRate,a={timestamp:this.nextTimestampInSamples/this.firstFrameHeader.sampleRate,duration:s,dataStart:e.startPos,dataSize:n.totalSize};this.loadedSamples.push(a),this.nextTimestampInSamples+=n.audioSamplesInFrame}async getMimeType(){return"audio/mpeg"}async getTrackBackings(){return await this.readMetadata(),this.trackBackings}async getMetadataTags(){const e=await this.readingMutex.acquire();try{if(await this.readMetadata(),this.metadataTags)return this.metadataTags;this.metadataTags={};let n=0,r=!1;for(;;){let i=this.reader.requestSlice(n,Gt);if(ie(i)&&(i=await i),!i)break;const s=Vn(i);if(!s)break;r=!0;let a=this.reader.requestSlice(i.filePos,s.size);if(ie(a)&&(a=await a),!a)break;na(a,s,this.metadataTags),n=i.filePos+s.size}if(!r&&this.reader.fileSize!==null&&this.reader.fileSize>=ta){let i=this.reader.requestSlice(this.reader.fileSize-ta,ta);ie(i)&&(i=await i),R(i),Ve(i,3)==="TAG"&&_g(i,this.metadataTags)}return this.metadataTags}finally{e()}}}class tp{constructor(e){this.demuxer=e}getType(){return"audio"}getId(){return 1}getNumber(){return 1}getTimeResolution(){return R(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.sampleRate/this.demuxer.firstFrameHeader.audioSamplesInFrame}isRelativeToUnixEpoch(){return!1}getUnixTimeForTimestamp(){return null}getPairingMask(){return 1n}getBitrate(){return null}getAverageBitrate(){return null}async getDurationFromMetadata(){const e=this.demuxer;if(R(e.firstFrameHeader!==null),R(e.firstFrameHeaderPos!==null),e.xingData){if(e.xingData.frameCount!==null)return e.xingData.frameCount*e.firstFrameHeader.audioSamplesInFrame/e.firstFrameHeader.sampleRate}else if(e.reader.fileSize!==null){const n=Lm(e.firstFrameHeader.lowSamplingFrequency,e.firstFrameHeader.layer,e.firstFrameHeader.bitrate,e.firstFrameHeader.sampleRate),r=(e.reader.fileSize-e.firstFrameHeaderPos)/n;return Math.round(r)*e.firstFrameHeader.audioSamplesInFrame/e.firstFrameHeader.sampleRate}return null}async getLiveRefreshInterval(){return null}getName(){return null}getLanguageCode(){return Tt}getCodec(){return"mp3"}getInternalCodecId(){return null}getNumberOfChannels(){return R(this.demuxer.firstFrameHeader),Ni(this.demuxer.firstFrameHeader.channel)}getSampleRate(){return R(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.sampleRate}getDisposition(){return{...Fn}}async getDecoderConfig(){return R(this.demuxer.firstFrameHeader),{codec:"mp3",numberOfChannels:Ni(this.demuxer.firstFrameHeader.channel),sampleRate:this.demuxer.firstFrameHeader.sampleRate}}async getPacketAtIndex(e,n){if(e===-1)return null;const r=this.demuxer.loadedSamples[e];if(!r)return null;let i;if(n.metadataOnly)i=Ut;else{let s=this.demuxer.reader.requestSlice(r.dataStart,r.dataSize);if(ie(s)&&(s=await s),!s)return null;i=me(s,r.dataSize)}return new Qe(i,"key",r.timestamp,r.duration,e,r.dataSize)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getNextPacket(e,n){const r=await this.demuxer.readingMutex.acquire();try{const i=Ii(this.demuxer.loadedSamples,e.timestamp,a=>a.timestamp);if(i===-1)throw new Error("Packet was not created from this track.");const s=i+1;for(;s>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(s,n)}finally{r()}}async getPacket(e,n){const r=await this.demuxer.readingMutex.acquire();try{for(;;){const i=_e(this.demuxer.loadedSamples,e,s=>s.timestamp);if(i===-1&&this.demuxer.loadedSamples.length>0)return null;if(this.demuxer.lastSampleLoaded)return this.getPacketAtIndex(i,n);if(i>=0&&i+1<this.demuxer.loadedSamples.length)return this.getPacketAtIndex(i,n);await this.demuxer.advanceReader()}}finally{r()}}getKeyPacket(e,n){return this.getPacket(e,n)}getNextKeyPacket(e,n){return this.getNextPacket(e,n)}}const fu=1399285583,np=79764919,du=new Uint32Array(256);for(let t=0;t<256;t++){let e=t<<24;for(let n=0;n<8;n++)e=e&2147483648?e<<1^np:e<<1;du[t]=e>>>0&4294967295}const rp=t=>{const e=Ie(t),n=e.getUint32(22,!0);e.setUint32(22,0,!0);let r=0;for(let i=0;i<t.length;i++){const s=t[i];r=(r<<8^du[r>>>24^s])>>>0}return e.setUint32(22,n,!0),r},ip=(t,e,n)=>{let r=0,i=null;if(t.length>0)if(e.codec==="vorbis"){R(e.vorbisInfo);const s=e.vorbisInfo.modeBlockflags.length,o=(1<<Wh(s-1))-1<<1,c=(t[0]&o)>>1;if(c>=e.vorbisInfo.modeBlockflags.length)throw new Error("Invalid mode number.");let u=n;const l=e.vorbisInfo.modeBlockflags[c];if(i=e.vorbisInfo.blocksizes[l],l===1){const f=(o|1)+1,d=t[0]&f?1:0;u=e.vorbisInfo.blocksizes[d]}r=u!==null?u+i>>2:0}else e.codec==="opus"&&(r=dm(t).durationInSamples);return{durationInSamples:r,vorbisBlockSize:i}},sp=t=>{let e="audio/ogg";if(t.codecStrings){const n=[...new Set(t.codecStrings)];e+=`; codecs="${n.join(", ")}"`}return e};const Pr=27,ai=282,ap=ai+65025,Vi=t=>{const e=t.filePos;if(di(t)!==fu)return null;t.skip(1);const r=de(t),i=Sg(t),s=di(t),a=di(t),o=di(t),c=de(t),u=new Uint8Array(c);for(let h=0;h<c;h++)u[h]=de(t);const l=27+c,f=u.reduce((h,p)=>h+p,0),d=l+f;return{headerStartPos:e,totalSize:d,dataStartPos:e+l,dataSize:f,headerType:r,granulePosition:i,serialNumber:s,sequenceNumber:a,checksum:o,lacingValues:u}},op=(t,e)=>{for(;t.filePos<e-3;){const n=di(t),r=n&255,i=n>>>8&255,s=n>>>16&255,a=n>>>24&255,o=79;if(!(r!==o&&i!==o&&s!==o&&a!==o)){if(t.skip(-4),n===fu)return!0;t.skip(1)}}return!1};class cp extends Dn{constructor(e){super(e),this.metadataPromise=null,this.bitstreams=[],this.trackBackings=[],this.metadataTags={},this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{let e=0;for(;;){let n=this.reader.requestSliceRange(e,Pr,ai);if(ie(n)&&(n=await n),!n)break;const r=Vi(n);if(!r||!!!(r.headerType&2))break;this.bitstreams.push({serialNumber:r.serialNumber,bosPage:r,description:null,numberOfChannels:-1,sampleRate:-1,codecInfo:{codec:null,vorbisInfo:null,opusInfo:null},lastMetadataPacket:null}),e=r.headerStartPos+r.totalSize}for(const n of this.bitstreams){const r=await this.readPacket(n.bosPage,0);r&&(r.data.byteLength>=7&&r.data[0]===1&&r.data[1]===118&&r.data[2]===111&&r.data[3]===114&&r.data[4]===98&&r.data[5]===105&&r.data[6]===115?await this.readVorbisMetadata(r,n):r.data.byteLength>=8&&r.data[0]===79&&r.data[1]===112&&r.data[2]===117&&r.data[3]===115&&r.data[4]===72&&r.data[5]===101&&r.data[6]===97&&r.data[7]===100&&await this.readOpusMetadata(r,n),n.codecInfo.codec!==null&&this.trackBackings.push(new lp(n,this)))}})()}async readVorbisMetadata(e,n){let r=await this.findNextPacketStart(e);if(!r)return;const i=await this.readPacket(r.startPage,r.startSegmentIndex);if(!i||(r=await this.findNextPacketStart(i),!r))return;const s=await this.readPacket(r.startPage,r.startSegmentIndex);if(!s||i.data[0]!==3||s.data[0]!==5)return;const a=[],o=f=>{for(;a.push(Math.min(255,f)),!(f<255);)f-=255};o(e.data.length),o(i.data.length);const c=new Uint8Array(1+a.length+e.data.length+i.data.length+s.data.length);c[0]=2,c.set(a,1),c.set(e.data,1+a.length),c.set(i.data,1+a.length+e.data.length),c.set(s.data,1+a.length+e.data.length+i.data.length),n.codecInfo.codec="vorbis",n.description=c,n.lastMetadataPacket=s;const u=Ie(e.data);n.numberOfChannels=u.getUint8(11),n.sampleRate=u.getUint32(12,!0);const l=u.getUint8(28);n.codecInfo.vorbisInfo={blocksizes:[1<<(l&15),1<<(l>>4)],modeBlockflags:hm(s.data).modeBlockflags},ko(i.data.subarray(7),this.metadataTags)}async readOpusMetadata(e,n){const r=await this.findNextPacketStart(e);if(!r)return;const i=await this.readPacket(r.startPage,r.startSegmentIndex);if(!i)return;n.codecInfo.codec="opus",n.description=e.data,n.lastMetadataPacket=i;const s=um(e.data);n.numberOfChannels=s.outputChannelCount,n.sampleRate=qs,n.codecInfo.opusInfo={preSkip:s.preSkip},ko(i.data.subarray(8),this.metadataTags)}async readPacket(e,n){R(n<e.lacingValues.length);let r=0;for(let f=0;f<n;f++)r+=e.lacingValues[f];let i=e,s=r,a=n;const o=[];e:for(;;){let f=this.reader.requestSlice(i.dataStartPos,i.dataSize);ie(f)&&(f=await f),R(f);const d=me(f,i.dataSize);for(;;){if(a===i.lacingValues.length){o.push(d.subarray(r,s));break}const p=i.lacingValues[a];if(s+=p,p<255){o.push(d.subarray(r,s));break e}a++}let h=i.headerStartPos+i.totalSize;for(;;){let p=this.reader.requestSliceRange(h,Pr,ai);if(ie(p)&&(p=await p),!p)return null;const m=Vi(p);if(!m)return null;if(i=m,i.serialNumber===e.serialNumber)break;h=i.headerStartPos+i.totalSize}r=0,s=0,a=0}const c=o.reduce((f,d)=>f+d.length,0);if(c===0)return null;const u=new Uint8Array(c);let l=0;for(let f=0;f<o.length;f++){const d=o[f];u.set(d,l),l+=d.length}return{data:u,endPage:i,endSegmentIndex:a}}async findNextPacketStart(e){if(e.endSegmentIndex<e.endPage.lacingValues.length-1)return{startPage:e.endPage,startSegmentIndex:e.endSegmentIndex+1};if(!!(e.endPage.headerType&4))return null;let r=e.endPage.headerStartPos+e.endPage.totalSize;for(;;){let i=this.reader.requestSliceRange(r,Pr,ai);if(ie(i)&&(i=await i),!i)return null;const s=Vi(i);if(!s)return null;if(s.serialNumber===e.endPage.serialNumber)return{startPage:s,startSegmentIndex:0};r=s.headerStartPos+s.totalSize}}async getMimeType(){await this.readMetadata();const e=await Promise.all(this.trackBackings.map(n=>n.getDecoderConfig().then(r=>r?.codec??null)));return sp({codecStrings:e.filter(Boolean)})}async getTrackBackings(){return await this.readMetadata(),this.trackBackings}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}}class lp{constructor(e,n){this.bitstream=e,this.demuxer=n,this.encodedPacketToMetadata=new WeakMap,this.sequentialScanCache=[],this.sequentialScanMutex=new Cs,this.internalSampleRate=e.codecInfo.codec==="opus"?qs:e.sampleRate}getType(){return"audio"}getId(){return this.bitstream.serialNumber}getNumber(){const e=this.demuxer.trackBackings.findIndex(n=>n.bitstream===this.bitstream);return R(e!==-1),e+1}getNumberOfChannels(){return this.bitstream.numberOfChannels}getSampleRate(){return this.bitstream.sampleRate}getTimeResolution(){return this.bitstream.sampleRate}isRelativeToUnixEpoch(){return!1}getUnixTimeForTimestamp(){return null}getPairingMask(){return 1n}getBitrate(){return null}getAverageBitrate(){return null}async getDurationFromMetadata(){return null}async getLiveRefreshInterval(){return null}getCodec(){return this.bitstream.codecInfo.codec}getInternalCodecId(){return null}async getDecoderConfig(){return R(this.bitstream.codecInfo.codec),{codec:this.bitstream.codecInfo.codec,numberOfChannels:this.bitstream.numberOfChannels,sampleRate:this.bitstream.sampleRate,description:this.bitstream.description??void 0}}getName(){return null}getLanguageCode(){return Tt}getDisposition(){return{...Fn,primary:!1}}granulePositionToTimestampInSamples(e){return this.bitstream.codecInfo.codec==="opus"?(R(this.bitstream.codecInfo.opusInfo),e-this.bitstream.codecInfo.opusInfo.preSkip):e}createEncodedPacketFromOggPacket(e,n,r){if(!e)return null;const{durationInSamples:i,vorbisBlockSize:s}=ip(e.data,this.bitstream.codecInfo,n.vorbisLastBlocksize),a=new Qe(r.metadataOnly?Ut:e.data,"key",Math.max(0,n.timestampInSamples)/this.internalSampleRate,i/this.internalSampleRate,e.endPage.headerStartPos+e.endSegmentIndex,e.data.byteLength);return this.encodedPacketToMetadata.set(a,{packet:e,timestampInSamples:n.timestampInSamples,durationInSamples:i,vorbisLastBlockSize:n.vorbisLastBlocksize,vorbisBlockSize:s}),a}async getFirstPacket(e){R(this.bitstream.lastMetadataPacket);const n=await this.demuxer.findNextPacketStart(this.bitstream.lastMetadataPacket);if(!n)return null;let r=0;this.bitstream.codecInfo.codec==="opus"&&(R(this.bitstream.codecInfo.opusInfo),r-=this.bitstream.codecInfo.opusInfo.preSkip);const i=await this.demuxer.readPacket(n.startPage,n.startSegmentIndex);return this.createEncodedPacketFromOggPacket(i,{timestampInSamples:r,vorbisLastBlocksize:null},e)}async getNextPacket(e,n){const r=this.encodedPacketToMetadata.get(e);if(!r)throw new Error("Packet was not created from this track.");const i=await this.demuxer.findNextPacketStart(r.packet);if(!i)return null;const s=r.timestampInSamples+r.durationInSamples,a=await this.demuxer.readPacket(i.startPage,i.startSegmentIndex);return this.createEncodedPacketFromOggPacket(a,{timestampInSamples:s,vorbisLastBlocksize:r.vorbisBlockSize},n)}async getPacket(e,n){if(this.demuxer.reader.fileSize===null)return this.getPacketSequential(e,n);const r=Bi(e*this.internalSampleRate);if(r===0)return this.getFirstPacket(n);if(r<0)return null;R(this.bitstream.lastMetadataPacket);const i=await this.demuxer.findNextPacketStart(this.bitstream.lastMetadataPacket);if(!i)return null;let s=i.startPage,a=this.demuxer.reader.fileSize;const o=[s];e:for(;s.headerStartPos+s.totalSize<a;){const y=s.headerStartPos,b=Math.floor((y+a)/2);let v=b;for(;;){const k=Math.min(v+ap,a-Pr);let A=this.demuxer.reader.requestSlice(v,k-v);if(ie(A)&&(A=await A),R(A),!op(A,k)){a=b+Pr;continue e}let S=this.demuxer.reader.requestSliceRange(A.filePos,Pr,ai);ie(S)&&(S=await S),R(S);const P=Vi(S);R(P);let M=!1;if(P.serialNumber===this.bitstream.serialNumber)M=!0;else{let N=this.demuxer.reader.requestSlice(P.headerStartPos,P.totalSize);ie(N)&&(N=await N),R(N);const U=me(N,P.totalSize);M=rp(U)===P.checksum}if(!M){v=P.headerStartPos+4;continue}if(M&&P.serialNumber!==this.bitstream.serialNumber){v=P.headerStartPos+P.totalSize;continue}if(P.granulePosition===-1){v=P.headerStartPos+P.totalSize;continue}this.granulePositionToTimestampInSamples(P.granulePosition)>r?a=P.headerStartPos:(s=P,o.push(P));continue e}}let c=i.startPage;for(const y of o){if(y.granulePosition===s.granulePosition)break;(!c||y.headerStartPos>c.headerStartPos)&&(c=y)}let u=c;const l=[u];for(;!(u.serialNumber===this.bitstream.serialNumber&&u.granulePosition===s.granulePosition);){const y=u.headerStartPos+u.totalSize;let b=this.demuxer.reader.requestSliceRange(y,Pr,ai);ie(b)&&(b=await b),R(b);const v=Vi(b);R(v),u=v,u.serialNumber===this.bitstream.serialNumber&&l.push(u)}R(u.granulePosition!==-1);let f=null,d,h,p=u,m=0;if(u.headerStartPos===i.startPage.headerStartPos)d=this.granulePositionToTimestampInSamples(0),h=!0,f=0;else{d=0,h=!1;for(let v=u.lacingValues.length-1;v>=0;v--)if(u.lacingValues[v]<255){f=v+1;break}if(f===null)throw new Error("Invalid page with granule position: no packets end on this page.");m=f-1;const y={data:Ut,endPage:p,endSegmentIndex:m};if(await this.demuxer.findNextPacketStart(y)){const v=mu(l,u,f);R(v);const k=hu(l,v.page,v.segmentIndex);k&&(u=k.page,f=k.segmentIndex)}else for(;;){const v=mu(l,u,f);if(!v)break;const k=hu(l,v.page,v.segmentIndex);if(!k)break;if(u=k.page,f=k.segmentIndex,v.page.headerStartPos!==p.headerStartPos){p=v.page,m=v.segmentIndex;break}}}let g=null,w=null;for(;u!==null;){R(f!==null);const y=await this.demuxer.readPacket(u,f);if(!y)break;if(!(u.headerStartPos===i.startPage.headerStartPos&&f<i.startSegmentIndex)){let k=this.createEncodedPacketFromOggPacket(y,{timestampInSamples:d,vorbisLastBlocksize:w?.vorbisBlockSize??null},n);R(k);let A=this.encodedPacketToMetadata.get(k);if(R(A),!h&&y.endPage.headerStartPos===p.headerStartPos&&y.endSegmentIndex===m?(d=this.granulePositionToTimestampInSamples(u.granulePosition),h=!0,k=this.createEncodedPacketFromOggPacket(y,{timestampInSamples:d-A.durationInSamples,vorbisLastBlocksize:w?.vorbisBlockSize??null},n),R(k),A=this.encodedPacketToMetadata.get(k),R(A)):d+=A.durationInSamples,g=k,w=A,h&&(Math.max(d,0)>r||Math.max(A.timestampInSamples,0)===r))break}const v=await this.demuxer.findNextPacketStart(y);if(!v)break;u=v.startPage,f=v.startSegmentIndex}return g}async getPacketSequential(e,n){const r=await this.sequentialScanMutex.acquire();try{const i=Bi(e*this.internalSampleRate);e=i/this.internalSampleRate;const s=_e(this.sequentialScanCache,i,c=>c.timestampInSamples);let a;if(s!==-1){const c=this.sequentialScanCache[s];a=this.createEncodedPacketFromOggPacket(c.packet,{timestampInSamples:c.timestampInSamples,vorbisLastBlocksize:c.vorbisLastBlockSize},n)}else a=await this.getFirstPacket(n);let o=0;for(;a&&a.timestamp<e;){const c=await this.getNextPacket(a,n);if(!c||c.timestamp>e)break;if(a=c,o++,o===100){o=0;const u=this.encodedPacketToMetadata.get(a);R(u),this.sequentialScanCache.length>0&&R(Mt(this.sequentialScanCache).timestampInSamples<=u.timestampInSamples),this.sequentialScanCache.push(u)}}return a}finally{r()}}getKeyPacket(e,n){return this.getPacket(e,n)}getNextKeyPacket(e,n){return this.getNextPacket(e,n)}}const hu=(t,e,n)=>{let r=e,i=n;e:for(;;){for(i--,i;i>=0;i--)if(r.lacingValues[i]<255){i++;break e}if(R(i===-1),!(r.headerType&1)){i=0;break}const a=ol(t,o=>o.headerStartPos<r.headerStartPos);if(!a)return null;r=a,i=r.lacingValues.length}if(R(i!==-1),i===r.lacingValues.length){const s=t[t.indexOf(r)+1];R(s),r=s,i=0}return{page:r,segmentIndex:i}},mu=(t,e,n)=>{if(n>0)return{page:e,segmentIndex:n-1};const r=ol(t,i=>i.headerStartPos<e.headerStartPos);return r?{page:r,segmentIndex:r.lacingValues.length-1}:null};var St;(function(t){t[t.PCM=1]="PCM",t[t.IEEE_FLOAT=3]="IEEE_FLOAT",t[t.ALAW=6]="ALAW",t[t.MULAW=7]="MULAW",t[t.EXTENSIBLE=65534]="EXTENSIBLE"})(St||(St={}));class up extends Dn{constructor(e){super(e),this.metadataPromise=null,this.dataStart=-1,this.dataSize=-1,this.audioInfo=null,this.trackBackings=[],this.lastKnownPacketIndex=0,this.metadataTags={},this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{let e=this.reader.requestSlice(0,12);ie(e)&&(e=await e),R(e);const n=Ve(e,4),r=n!=="RIFX",i=n==="RF64",s=ir(e,r);let a=i?this.reader.fileSize:Math.min(s+8,this.reader.fileSize??1/0);if(Ve(e,4)!=="WAVE")throw new Error("Invalid WAVE file - wrong format");let c=0,u=null,l=e.filePos;for(;a===null||l<a;){let d=this.reader.requestSlice(l,8);if(ie(d)&&(d=await d),!d)break;const h=Ve(d,4),p=ir(d,r),m=d.filePos;if(i&&c===0&&h!=="ds64")throw new Error('Invalid RF64 file: First chunk must be "ds64".');if(h==="fmt ")await this.parseFmtChunk(m,p,r);else if(h==="data"){if(u??=p,this.dataStart=d.filePos,this.dataSize=Math.min(u,(a??1/0)-this.dataStart),this.reader.fileSize===null)break}else if(h==="ds64"){let g=this.reader.requestSlice(m,p);if(ie(g)&&(g=await g),!g)break;const w=uf(g,r);u=uf(g,r),a=Math.min(w+8,this.reader.fileSize??1/0)}else h==="LIST"?await this.parseListChunk(m,p,r):(h==="ID3 "||h==="id3 ")&&await this.parseId3Chunk(m,p);l=m+p+(p&1),c++}if(!this.audioInfo)throw new Error('Invalid WAVE file - missing "fmt " chunk');if(this.dataStart===-1)throw new Error('Invalid WAVE file - missing "data" chunk');const f=this.audioInfo.blockSizeInBytes;this.dataSize=Math.floor(this.dataSize/f)*f,this.trackBackings.push(new fp(this))})()}async parseFmtChunk(e,n,r){let i=this.reader.requestSlice(e,n);if(ie(i)&&(i=await i),!i)return;let s=Ki(i,r);const a=Ki(i,r),o=ir(i,r);i.skip(4);const c=Ki(i,r);let u;if(n===14?u=8:u=Ki(i,r),n>=18&&s!==357){const l=Ki(i,r),f=n-18;if(Math.min(f,l)>=22&&s===St.EXTENSIBLE){i.skip(6);const h=me(i,16);s=h[0]|h[1]<<8}}if((s===St.MULAW||s===St.ALAW)&&(u=8),s!==St.PCM&&s!==St.IEEE_FLOAT&&s!==St.ALAW&&s!==St.MULAW)throw new Error(`Unsupported WAVE codec (format tag ${s}). Only integer/float PCM, A-law, and \u03BC-law are supported.`);if(s===St.PCM&&![8,16,24,32].includes(u))throw new Error(`Unsupported WAVE PCM bit depth (${u}). Only 8, 16, 24, and 32 bits are supported.`);if(s===St.IEEE_FLOAT&&![32,64].includes(u))throw new Error(`Unsupported WAVE float bit depth (${u}). Only 32 and 64 bits are supported.`);this.audioInfo={format:s,numberOfChannels:a,sampleRate:o,sampleSizeInBytes:Math.ceil(u/8),blockSizeInBytes:c}}async parseListChunk(e,n,r){let i=this.reader.requestSlice(e,n);if(ie(i)&&(i=await i),!i)return;const s=Ve(i,4);if(s!=="INFO"&&s!=="INF0")return;let a=i.filePos;for(;a<=e+n-8;){i.filePos=a;const o=Ve(i,4),c=ir(i,r),u=me(i,c);let l=0;for(let d=0;d<u.length&&u[d]!==0;d++)l++;const f=String.fromCharCode(...u.subarray(0,l));switch(this.metadataTags.raw??={},this.metadataTags.raw[o]=f,o){case"INAM":case"TITL":this.metadataTags.title??=f;break;case"TIT3":this.metadataTags.description??=f;break;case"IART":this.metadataTags.artist??=f;break;case"IPRD":this.metadataTags.album??=f;break;case"IPRT":case"ITRK":case"TRCK":{const d=f.split("/"),h=Number.parseInt(d[0],10),p=d[1]&&Number.parseInt(d[1],10);Number.isInteger(h)&&h>0&&(this.metadataTags.trackNumber??=h),p&&Number.isInteger(p)&&p>0&&(this.metadataTags.tracksTotal??=p)}break;case"ICRD":case"IDIT":{const d=new Date(f);Number.isNaN(d.getTime())||(this.metadataTags.date??=d)}break;case"YEAR":{const d=Number.parseInt(f,10);Number.isInteger(d)&&d>0&&(this.metadataTags.date??=new Date(d,0,1))}break;case"IGNR":case"GENR":this.metadataTags.genre??=f;break;case"ICMT":case"CMNT":case"COMM":this.metadataTags.comment??=f;break}a+=8+c+(c&1)}}async parseId3Chunk(e,n){let r=this.reader.requestSlice(e,n);if(ie(r)&&(r=await r),!r)return;const i=Vn(r);if(i){const s=n-Gt;if(i.size=Math.min(i.size,s),i.size>0){const a=r.slice(e+Gt,i.size);na(a,i,this.metadataTags)}}}getCodec(){if(R(this.audioInfo),this.audioInfo.format===St.MULAW)return"ulaw";if(this.audioInfo.format===St.ALAW)return"alaw";if(this.audioInfo.format===St.PCM){if(this.audioInfo.sampleSizeInBytes===1)return"pcm-u8";if(this.audioInfo.sampleSizeInBytes===2)return"pcm-s16";if(this.audioInfo.sampleSizeInBytes===3)return"pcm-s24";if(this.audioInfo.sampleSizeInBytes===4)return"pcm-s32"}if(this.audioInfo.format===St.IEEE_FLOAT){if(this.audioInfo.sampleSizeInBytes===4)return"pcm-f32";if(this.audioInfo.sampleSizeInBytes===8)return"pcm-f64"}R(!1)}async getMimeType(){return"audio/wav"}async getTrackBackings(){return await this.readMetadata(),this.trackBackings}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}}const oi=2048;class fp{constructor(e){this.demuxer=e}getType(){return"audio"}getId(){return 1}getNumber(){return 1}getCodec(){return this.demuxer.getCodec()}getInternalCodecId(){return R(this.demuxer.audioInfo),this.demuxer.audioInfo.format}async getDecoderConfig(){const e=this.demuxer.getCodec();return e?(R(this.demuxer.audioInfo),{codec:e,numberOfChannels:this.demuxer.audioInfo.numberOfChannels,sampleRate:this.demuxer.audioInfo.sampleRate}):null}getNumberOfChannels(){return R(this.demuxer.audioInfo),this.demuxer.audioInfo.numberOfChannels}getSampleRate(){return R(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getTimeResolution(){return R(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}isRelativeToUnixEpoch(){return!1}getUnixTimeForTimestamp(){return null}getPairingMask(){return 1n}getBitrate(){return null}getAverageBitrate(){return null}async getDurationFromMetadata(){return R(this.demuxer.dataSize!==-1),this.demuxer.dataSize/this.demuxer.audioInfo.blockSizeInBytes/this.demuxer.audioInfo.sampleRate}async getLiveRefreshInterval(){return null}getName(){return null}getLanguageCode(){return Tt}getDisposition(){return{...Fn}}async getPacketAtIndex(e,n){R(e>=0),R(this.demuxer.audioInfo);const r=e*oi*this.demuxer.audioInfo.blockSizeInBytes;if(r>=this.demuxer.dataSize)return null;const i=Math.min(oi*this.demuxer.audioInfo.blockSizeInBytes,this.demuxer.dataSize-r);if(this.demuxer.reader.fileSize===null){let c=this.demuxer.reader.requestSlice(this.demuxer.dataStart+r,i);if(ie(c)&&(c=await c),!c)return null}let s;if(n.metadataOnly)s=Ut;else{let c=this.demuxer.reader.requestSlice(this.demuxer.dataStart+r,i);ie(c)&&(c=await c),R(c),s=me(c,i)}const a=e*oi/this.demuxer.audioInfo.sampleRate,o=i/this.demuxer.audioInfo.blockSizeInBytes/this.demuxer.audioInfo.sampleRate;return this.demuxer.lastKnownPacketIndex=Math.max(e,this.demuxer.lastKnownPacketIndex),new Qe(s,"key",a,o,e,i)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getPacket(e,n){R(this.demuxer.audioInfo);const r=Math.floor(Math.min(e*this.demuxer.audioInfo.sampleRate/oi,(this.demuxer.dataSize-1)/(oi*this.demuxer.audioInfo.blockSizeInBytes)));if(r<0)return null;const i=await this.getPacketAtIndex(r,n);if(i)return i;if(r===0)return null;R(this.demuxer.reader.fileSize===null);let s=await this.getPacketAtIndex(this.demuxer.lastKnownPacketIndex,n);for(;s;){const a=await this.getNextPacket(s,n);if(!a)break;s=a}return s}getNextPacket(e,n){R(this.demuxer.audioInfo);const r=Math.round(e.timestamp*this.demuxer.audioInfo.sampleRate/oi);return this.getPacketAtIndex(r+1,n)}getKeyPacket(e,n){return this.getPacket(e,n)}getNextKeyPacket(e,n){return this.getNextPacket(e,n)}}const zo=7,ci=9,Wi=t=>{const e=t.filePos,n=me(t,9),r=new Ee(n);if(r.readBits(12)!==4095||(r.skipBits(1),r.readBits(2)!==0))return null;const a=r.readBits(1),o=r.readBits(2)+1,c=r.readBits(4);if(c===15)return null;r.skipBits(1);const u=r.readBits(3);if(u===0)throw new Error("ADTS frames with channel configuration 0 are not supported.");r.skipBits(1),r.skipBits(1),r.skipBits(1),r.skipBits(1);const l=r.readBits(13);r.skipBits(11);const f=r.readBits(2)+1;if(f!==1)throw new Error("ADTS frames with more than one AAC frame are not supported.");let d=null;return a===1?t.filePos-=2:d=r.readBits(16),{objectType:o,samplingFrequencyIndex:c,channelConfiguration:u,frameLength:l,numberOfAacFrames:f,crcCheck:d,startPos:e}};const Qs=1024;class dp extends Dn{constructor(e){super(e),this.metadataPromise=null,this.firstFrameHeader=null,this.loadedSamples=[],this.metadataTags=null,this.trackBackings=[],this.readingMutex=new Cs,this.lastSampleLoaded=!1,this.lastLoadedPos=0,this.nextTimestampInSamples=0,this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{for(;!this.firstFrameHeader&&!this.lastSampleLoaded;)await this.advanceReader();R(this.firstFrameHeader),this.trackBackings=[new hp(this)]})()}async advanceReader(){if(this.lastLoadedPos===0)for(;;){let a=this.reader.requestSlice(this.lastLoadedPos,Gt);if(ie(a)&&(a=await a),!a){this.lastSampleLoaded=!0;return}const o=Vn(a);if(!o)break;this.lastLoadedPos=a.filePos+o.size}let e=this.reader.requestSliceRange(this.lastLoadedPos,zo,ci);if(ie(e)&&(e=await e),!e){this.lastSampleLoaded=!0;return}const n=Wi(e);if(!n){this.lastSampleLoaded=!0;return}if(this.reader.fileSize!==null&&n.startPos+n.frameLength>this.reader.fileSize){this.lastSampleLoaded=!0;return}this.firstFrameHeader||(this.firstFrameHeader=n);const r=Fi[n.samplingFrequencyIndex];R(r!==void 0);const i=Qs/r,s={timestamp:this.nextTimestampInSamples/r,duration:i,dataStart:n.startPos,dataSize:n.frameLength};this.loadedSamples.push(s),this.nextTimestampInSamples+=Qs,this.lastLoadedPos=n.startPos+n.frameLength}async getMimeType(){return"audio/aac"}async getTrackBackings(){return await this.readMetadata(),this.trackBackings}async getMetadataTags(){const e=await this.readingMutex.acquire();try{if(await this.readMetadata(),this.metadataTags)return this.metadataTags;this.metadataTags={};let n=0;for(;;){let r=this.reader.requestSlice(n,Gt);if(ie(r)&&(r=await r),!r)break;const i=Vn(r);if(!i)break;let s=this.reader.requestSlice(r.filePos,i.size);if(ie(s)&&(s=await s),!s)break;na(s,i,this.metadataTags),n=r.filePos+i.size}return this.metadataTags}finally{e()}}}class hp{constructor(e){this.demuxer=e}getType(){return"audio"}getId(){return 1}getNumber(){return 1}getTimeResolution(){return this.getSampleRate()/Qs}isRelativeToUnixEpoch(){return!1}getUnixTimeForTimestamp(){return null}getPairingMask(){return 1n}getBitrate(){return null}getAverageBitrate(){return null}async getDurationFromMetadata(){return null}async getLiveRefreshInterval(){return null}getName(){return null}getLanguageCode(){return Tt}getCodec(){return"aac"}getInternalCodecId(){return R(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.objectType}getNumberOfChannels(){R(this.demuxer.firstFrameHeader);const e=fo[this.demuxer.firstFrameHeader.channelConfiguration];return R(e!==void 0),e}getSampleRate(){R(this.demuxer.firstFrameHeader);const e=Fi[this.demuxer.firstFrameHeader.samplingFrequencyIndex];return R(e!==void 0),e}getDisposition(){return{...Fn}}async getDecoderConfig(){return R(this.demuxer.firstFrameHeader),{codec:`mp4a.40.${this.demuxer.firstFrameHeader.objectType}`,numberOfChannels:this.getNumberOfChannels(),sampleRate:this.getSampleRate()}}async getPacketAtIndex(e,n){if(e===-1)return null;const r=this.demuxer.loadedSamples[e];if(!r)return null;let i;if(n.metadataOnly)i=Ut;else{let s=this.demuxer.reader.requestSlice(r.dataStart,r.dataSize);if(ie(s)&&(s=await s),!s)return null;i=me(s,r.dataSize)}return new Qe(i,"key",r.timestamp,r.duration,e,r.dataSize)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getNextPacket(e,n){const r=await this.demuxer.readingMutex.acquire();try{const i=Ii(this.demuxer.loadedSamples,e.timestamp,a=>a.timestamp);if(i===-1)throw new Error("Packet was not created from this track.");const s=i+1;for(;s>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(s,n)}finally{r()}}async getPacket(e,n){const r=await this.demuxer.readingMutex.acquire();try{for(;;){const i=_e(this.demuxer.loadedSamples,e,s=>s.timestamp);if(i===-1&&this.demuxer.loadedSamples.length>0)return null;if(this.demuxer.lastSampleLoaded)return this.getPacketAtIndex(i,n);if(i>=0&&i+1<this.demuxer.loadedSamples.length)return this.getPacketAtIndex(i,n);await this.demuxer.advanceReader()}}finally{r()}}getKeyPacket(e,n){return this.getPacket(e,n)}getNextKeyPacket(e,n){return this.getNextPacket(e,n)}}const mp=t=>t===0?null:t===1?192:t>=2&&t<=5?144*2**t:t===6?"uncommon-u8":t===7?"uncommon-u16":t>=8&&t<=15?2**t:null,pp=(t,e)=>{switch(t){case 0:return e;case 1:return 88200;case 2:return 176400;case 3:return 192e3;case 4:return 8e3;case 5:return 16e3;case 6:return 22050;case 7:return 24e3;case 8:return 32e3;case 9:return 44100;case 10:return 48e3;case 11:return 96e3;case 12:return"uncommon-u8";case 13:return"uncommon-u16";case 14:return"uncommon-u16-10";default:return null}},gp=t=>{let e=0;const n=new Ee(me(t,1));for(;n.readBits(1)===1;)e++;if(e===0)return n.readBits(7);const r=[],i=e-1,s=new Ee(me(t,i)),a=8-e-1;for(let c=0;c<a;c++)r.unshift(n.readBits(1));for(let c=0;c<i;c++)for(let u=0;u<8;u++){const l=s.readBits(1);u<2||r.unshift(l)}return r.reduce((c,u,l)=>c|u<<l,0)},yp=(t,e)=>{if(e==="uncommon-u16")return $e(t)+1;if(e==="uncommon-u8")return de(t)+1;if(typeof e=="number")return e;Is(e),R(!1)},bp=(t,e)=>e==="uncommon-u16"?$e(t):e==="uncommon-u16-10"?$e(t)*10:e==="uncommon-u8"?de(t):typeof e=="number"?e:null,wp=t=>{let n=0;for(const r of t){n^=r;for(let i=0;i<8;i++)(n&128)!==0?n=n<<1^7:n<<=1,n&=255}return n};class vp extends Dn{constructor(e){super(e),this.loadedSamples=[],this.metadataPromise=null,this.trackBacking=null,this.metadataTags={},this.audioInfo=null,this.lastLoadedPos=null,this.blockingBit=null,this.readingMutex=new Cs,this.lastSampleLoaded=!1,this.reader=e._reader}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}async getTrackBackings(){return await this.readMetadata(),R(this.trackBacking),[this.trackBacking]}async getMimeType(){return"audio/flac"}async readMetadata(){return this.metadataPromise??=(async()=>{let e=0;for(;;){let n=this.reader.requestSlice(e,Gt);if(ie(n)&&(n=await n),!n){this.lastSampleLoaded=!0;return}const r=Vn(n);if(!r)break;let i=this.reader.requestSlice(n.filePos,r.size);ie(i)&&(i=await i),R(i),na(i,r,this.metadataTags),e=n.filePos+r.size}for(e+=4;this.reader.fileSize===null||e<this.reader.fileSize;){let n=this.reader.requestSlice(e,4);if(ie(n)&&(n=await n),e+=4,n===null)throw new Error(`Metadata block at position ${e} is too small! Corrupted file.`);R(n);const r=de(n),i=Hn(n),s=(r&128)!==0;switch(r&127){case Zr.STREAMINFO:{let o=this.reader.requestSlice(e,i);if(ie(o)&&(o=await o),R(o),o===null)throw new Error(`StreamInfo block at position ${e} is too small! Corrupted file.`);const c=me(o,34),u=new Ee(c),l=u.readBits(16),f=u.readBits(16),d=u.readBits(24),h=u.readBits(24),p=u.readBits(20),m=u.readBits(3)+1;u.readBits(5);const g=u.readBits(36);u.skipBits(128);const w=new Uint8Array(42);w.set(new Uint8Array([102,76,97,67]),0),w.set(new Uint8Array([128,0,0,34]),4),w.set(c,8),this.audioInfo={numberOfChannels:m,sampleRate:p,totalSamples:g,minimumBlockSize:l,maximumBlockSize:f,minimumFrameSize:d,maximumFrameSize:h,description:w},this.trackBacking=new kp(this);break}case Zr.VORBIS_COMMENT:{let o=this.reader.requestSlice(e,i);ie(o)&&(o=await o),R(o),ko(me(o,i),this.metadataTags);break}case Zr.PICTURE:{let o=this.reader.requestSlice(e,i);ie(o)&&(o=await o),R(o);const c=ae(o),u=ae(o),l=Bt.decode(me(o,u)),f=ae(o),d=Bt.decode(me(o,f));o.skip(16);const h=ae(o),p=me(o,h);this.metadataTags.images??=[],this.metadataTags.images.push({data:p,mimeType:l,kind:c===3?"coverFront":c===4?"coverBack":"unknown",description:d});break}}if(e+=i,s){this.lastLoadedPos=e;break}}if(!this.audioInfo)throw new Error("Missing STREAMINFO metadata block! Corrupted FLAC file.")})()}async readNextFlacFrame({startPos:e,isFirstPacket:n}){R(this.audioInfo);const r=6,i=16,s=10,a=this.audioInfo.maximumBlockSize*this.audioInfo.numberOfChannels*4+i+2,o=this.audioInfo.minimumFrameSize||s,u=(this.audioInfo.maximumFrameSize||a)+i,l=await this.reader.requestSliceRange(e,i,u);if(!l)return null;const f=this.readFlacFrameHeader({slice:l,isFirstPacket:n});if(!f)return null;for(l.filePos=e+o;;){if(l.filePos>l.end-r)return{num:f.num,blockSize:f.blockSize,sampleRate:f.sampleRate,size:l.end-e,isLastFrame:!0};if(de(l)===255){const h=l.filePos,p=de(l),m=this.blockingBit===1?249:248;if(p!==m){l.filePos=h;continue}l.skip(-2);const g=l.filePos-e,w=this.readFlacFrameHeader({slice:l,isFirstPacket:!1});if(!w){l.filePos=h;continue}if(this.blockingBit===0){if(w.num-f.num!==1){l.filePos=h;continue}}else if(w.num-f.num!==f.blockSize){l.filePos=h;continue}return{num:f.num,blockSize:f.blockSize,sampleRate:f.sampleRate,size:g,isLastFrame:!1}}}}readFlacFrameHeader({slice:e,isFirstPacket:n}){const r=e.filePos,i=me(e,4),s=new Ee(i);if(s.readBits(15)!==32764)return null;if(this.blockingBit===null){R(n);const g=s.readBits(1);this.blockingBit=g}else if(this.blockingBit===1){if(R(!n),s.readBits(1)!==1)return null}else if(this.blockingBit===0){if(R(!n),s.readBits(1)!==0)return null}else throw new Error("Invalid blocking bit");const o=mp(s.readBits(4));if(!o)return null;R(this.audioInfo);const c=pp(s.readBits(4),this.audioInfo.sampleRate);if(!c||(s.readBits(4),s.readBits(3),s.readBits(1)!==0))return null;const l=gp(e),f=yp(e,o),d=bp(e,c);if(d===null||d!==this.audioInfo.sampleRate)return null;const h=e.filePos-r,p=de(e);e.skip(-h),e.skip(-1);const m=wp(me(e,h));return p!==m?null:{num:l,blockSize:f,sampleRate:d}}async advanceReader(){await this.readMetadata(),R(this.lastLoadedPos!==null),R(this.audioInfo);const e=this.lastLoadedPos,n=await this.readNextFlacFrame({startPos:e,isFirstPacket:this.loadedSamples.length===0});if(!n){this.lastSampleLoaded=!0;return}const r=this.loadedSamples[this.loadedSamples.length-1],s={blockOffset:r?r.blockOffset+r.blockSize:0,blockSize:n.blockSize,byteOffset:e,byteSize:n.size};if(this.lastLoadedPos=this.lastLoadedPos+n.size,this.loadedSamples.push(s),n.isLastFrame){this.lastSampleLoaded=!0;return}}}class kp{constructor(e){this.demuxer=e}getType(){return"audio"}getId(){return 1}getNumber(){return 1}getCodec(){return"flac"}getInternalCodecId(){return null}getNumberOfChannels(){return R(this.demuxer.audioInfo),this.demuxer.audioInfo.numberOfChannels}getSampleRate(){return R(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getName(){return null}getLanguageCode(){return Tt}getTimeResolution(){return R(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}isRelativeToUnixEpoch(){return!1}getUnixTimeForTimestamp(){return null}getPairingMask(){return 1n}getBitrate(){return null}getAverageBitrate(){return null}async getDurationFromMetadata(){return R(this.demuxer.audioInfo),this.demuxer.audioInfo.totalSamples===0?null:this.demuxer.audioInfo.totalSamples/this.demuxer.audioInfo.sampleRate}async getLiveRefreshInterval(){return null}getDisposition(){return{...Fn}}async getDecoderConfig(){return R(this.demuxer.audioInfo),{codec:"flac",numberOfChannels:this.demuxer.audioInfo.numberOfChannels,sampleRate:this.demuxer.audioInfo.sampleRate,description:this.demuxer.audioInfo.description}}async getPacket(e,n){if(R(this.demuxer.audioInfo),e<0)return null;const r=await this.demuxer.readingMutex.acquire();try{for(;;){const i=_e(this.demuxer.loadedSamples,e,c=>c.blockOffset/this.demuxer.audioInfo.sampleRate);if(i===-1){await this.demuxer.advanceReader();continue}const s=this.demuxer.loadedSamples[i],a=s.blockOffset/this.demuxer.audioInfo.sampleRate,o=s.blockSize/this.demuxer.audioInfo.sampleRate;if(a+o<=e){if(this.demuxer.lastSampleLoaded)return this.getPacketAtIndex(this.demuxer.loadedSamples.length-1,n);await this.demuxer.advanceReader();continue}return this.getPacketAtIndex(i,n)}}finally{r()}}async getNextPacket(e,n){const r=await this.demuxer.readingMutex.acquire();try{const i=e.sequenceNumber+1;if(this.demuxer.lastSampleLoaded&&i>=this.demuxer.loadedSamples.length)return null;for(;i>=this.demuxer.loadedSamples.length&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(i,n)}finally{r()}}getKeyPacket(e,n){return this.getPacket(e,n)}getNextKeyPacket(e,n){return this.getNextPacket(e,n)}async getPacketAtIndex(e,n){const r=this.demuxer.loadedSamples[e];if(!r)return null;let i;if(n.metadataOnly)i=Ut;else{let o=this.demuxer.reader.requestSlice(r.byteOffset,r.byteSize);if(ie(o)&&(o=await o),!o)return null;i=me(o,r.byteSize)}R(this.demuxer.audioInfo);const s=r.blockOffset/this.demuxer.audioInfo.sampleRate,a=r.blockSize/this.demuxer.audioInfo.sampleRate;return new Qe(i,"key",s,a,e,r.byteSize)}async getFirstPacket(e){for(;this.demuxer.loadedSamples.length===0&&!this.demuxer.lastSampleLoaded;)await this.demuxer.advanceReader();return this.getPacketAtIndex(0,e)}}const Jt=9e4,Ho=2**33,zt=188,Ap=t=>{let e="video/MP2T";const n=[...new Set(t.filter(Boolean))];return n.length>0&&(e+=`; codecs="${n.join(", ")}"`),e};const pu="PES packet is missing PTS where it was expected. PES packets without PTS are not currently supported. If you think this file should be supported, please report it.",gu=5,xp=1212435798,Tp=1212436562,Sp=1146376960,Pp=new Set([133,134,162]),yu=new Set;class _p extends Dn{constructor(e){super(e),this.metadataPromise=null,this.elementaryStreams=[],this.trackBackingEntries=[],this.packetOffset=0,this.packetStride=-1,this.sectionEndPositions=[],this.seekChunkSize=5*1024*1024,this.minReferencePointByteDistance=-1,this.timestampWrapInfo=null,this.reader=e._reader}async readMetadata(){return this.metadataPromise??=(async()=>{const e=zt+16+1;let n=this.reader.requestSlice(0,e);ie(n)&&(n=await n),R(n);const r=me(n,e);if(r[0]===71&&r[zt]===71)this.packetOffset=0,this.packetStride=zt;else if(r[0]===71&&r[zt+16]===71)this.packetOffset=0,this.packetStride=zt+16;else if(r[4]===71&&r[4+zt+4]===71)this.packetOffset=4,this.packetStride=zt+4;else throw new Error("Unreachable.");const i=256;this.minReferencePointByteDistance=i*this.packetStride;let s=this.packetOffset,a=null,o=!1,c=!1;for(;;){const u=await this.readPacketHeader(s);if(!u)break;if(u.payloadUnitStartIndicator===0){s+=this.packetStride;continue}if(c&&!this.elementaryStreams.some(m=>m.pid===u.pid)){s+=this.packetStride;continue}const l=await this.readSection(s,!0,!c);if(!l)break;const f=3,d=32;let h=!1;if(!c&&l.pid!==0&&!(l.payload[0]===0&&l.payload[1]===0&&l.payload[2]===1)){const g=new Ee(l.payload),w=g.readAlignedByte();g.skipBits(8*w),h=g.readBits(8)===2}if(l.pid===0&&!o){const m=new Ee(l.payload),g=m.readAlignedByte();m.skipBits(8*g),m.skipBits(14);const w=m.readBits(10);for(m.skipBits(40);8*(w+f)-m.pos>d;){const y=m.readBits(16);m.skipBits(3);const b=m.readBits(13);if(y!==0){if(a!==null)throw new Error("Only files with a single program are supported.");a=b}}if(a===null)throw new Error("Program Association Table must link to a Program Map Table.");o=!0}else if((l.pid===a||h)&&!c){const m=new Ee(l.payload),g=m.readAlignedByte();m.skipBits(8*g),m.skipBits(12);const w=m.readBits(12);m.skipBits(43),m.readBits(13),m.skipBits(6);const y=m.readBits(10),b=m.pos+8*y;let v=!1;for(;m.pos<b;){const k=m.readBits(8),A=m.readBits(8),T=m.pos+8*A;if(k===gu&&A>=4){const S=m.readBits(32);v||=S===xp||S===Tp}m.pos=T}for(m.pos=b;8*(w+f)-m.pos>d;){const k=m.readBits(8);m.skipBits(3);const A=m.readBits(13);m.skipBits(6);const T=m.readBits(10),S=m.pos+8*T;let P=!1,M=!1,B=!1;for(;m.pos<S;){const q=m.readBits(8),H=m.readBits(8),G=m.pos+8*H;if(q===106)P=!0;else if(q===122||q===204)M=!0;else if(q===123)B=!0;else if(q===gu&&H>=4){const Y=m.readBits(32);B||=(Y&4294967040)===Sp}m.pos=G}let N=null;const U=v&&Pp.has(k)?130:k;switch(U){case 27:case 36:N={type:"video",codec:k===27?"avc":"hevc",decoderConfig:null,avcCodecInfo:null,hevcCodecInfo:null,colorSpace:{primaries:null,transfer:null,matrix:null,fullRange:null},width:-1,height:-1,squarePixelWidth:-1,squarePixelHeight:-1,reorderSize:-1};break;case 3:case 4:case 15:case 129:case 135:case 130:case 138:{let q;U===3||U===4?q="mp3":U===15?q="aac":U===129?q="ac3":U===135?q="eac3":q="dts",N={type:"audio",codec:q,decoderConfig:null,aacCodecInfo:null,dtsFormat:null,numberOfChannels:-1,sampleRate:-1}}break;case 6:M?N={type:"audio",codec:"eac3",decoderConfig:null,aacCodecInfo:null,dtsFormat:null,numberOfChannels:-1,sampleRate:-1}:P?N={type:"audio",codec:"ac3",decoderConfig:null,aacCodecInfo:null,dtsFormat:null,numberOfChannels:-1,sampleRate:-1}:B&&(N={type:"audio",codec:"dts",decoderConfig:null,aacCodecInfo:null,dtsFormat:null,numberOfChannels:-1,sampleRate:-1});break;default:yu.has(k)||(pe._warn(`Note: MPEG-TS streams with stream_type 0x${k.toString(16)} are not currently supported.`),yu.add(k))}N&&this.elementaryStreams.push({demuxer:this,pid:A,streamType:k,initialized:!1,firstSection:null,canBeTrustedWithKeyPackets:!1,info:N,referencePesPackets:[]})}c=!0}else{const m=this.elementaryStreams.find(g=>g.pid===l.pid);e:if(m&&!m.initialized){const g=li(this,l,!0);if(!g)throw new Error(`Couldn't read first PES packet for Elementary Stream with PID ${m.pid}`);if(m.firstSection=l,m.canBeTrustedWithKeyPackets=l.randomAccessIndicator===1,this.input._initInput){const b=(await this.input._initInput._getDemuxer()).elementaryStreams.find(v=>v.pid===l.pid&&v.info.codec===m.info.codec);if(b){m.info=b.info,m.initialized=!0;break e}}const w=new ji(m,g);if(m.info.type==="video"){for(;;){const y=w;if(y.suppliedPacket=null,await w.markNextPacket(),m.info.codec==="avc"){if(!w.suppliedPacket)throw new Error("Invalid AVC video stream; could not extract AVCDecoderConfigurationRecord from any packet.");if(m.info.avcCodecInfo=go(w.suppliedPacket.data),!m.info.avcCodecInfo)continue;const b=m.info.avcCodecInfo.sequenceParameterSets[0];R(b);const v=Us(b);m.info.width=v.displayWidth,m.info.height=v.displayHeight;const k=v.pixelAspectRatio.num,A=v.pixelAspectRatio.den;k>0&&A>0&&(k>A?(m.info.squarePixelWidth=Math.round(m.info.width*k/A),m.info.squarePixelHeight=m.info.height):(m.info.squarePixelWidth=m.info.width,m.info.squarePixelHeight=Math.round(m.info.height*A/k))),m.info.colorSpace={primaries:Mn[v.colourPrimaries],transfer:Bn[v.transferCharacteristics],matrix:Rn[v.matrixCoefficients],fullRange:!!v.fullRangeFlag},m.info.reorderSize=v.maxDecFrameBuffering;break}else if(m.info.codec==="hevc"){if(!w.suppliedPacket)throw new Error("Invalid HEVC video stream; could not extract HVCDecoderConfigurationRecord from first packet.");if(m.info.hevcCodecInfo=bo(w.suppliedPacket.data),!m.info.hevcCodecInfo)continue;const v=m.info.hevcCodecInfo.arrays.find(A=>A.nalUnitType===Ge.SPS_NUT).nalUnits[0];R(v);const k=yo(v);m.info.width=k.displayWidth,m.info.height=k.displayHeight,k.pixelAspectRatio.num>k.pixelAspectRatio.den?(m.info.squarePixelWidth=Math.round(m.info.width*k.pixelAspectRatio.num/k.pixelAspectRatio.den),m.info.squarePixelHeight=m.info.height):(m.info.squarePixelWidth=m.info.width,m.info.squarePixelHeight=Math.round(m.info.height*k.pixelAspectRatio.den/k.pixelAspectRatio.num)),m.info.colorSpace={primaries:Mn[k.colourPrimaries],transfer:Bn[k.transferCharacteristics],matrix:Rn[k.matrixCoefficients],fullRange:!!k.fullRangeFlag},m.info.reorderSize=k.maxDecFrameBuffering;break}else throw new Error("Unhandled.")}m.info.decoderConfig={codec:So({width:m.info.width,height:m.info.height,codec:m.info.codec,codecDescription:null,colorSpace:m.info.colorSpace,avcType:1,avcCodecInfo:m.info.avcCodecInfo,hevcCodecInfo:m.info.hevcCodecInfo,vp9CodecInfo:null,av1CodecInfo:null,proresFormat:null}),codedWidth:m.info.width,codedHeight:m.info.height,colorSpace:m.info.colorSpace},(m.info.width!==m.info.squarePixelWidth||m.info.height!==m.info.squarePixelHeight)&&(m.info.decoderConfig.displayAspectWidth=m.info.squarePixelWidth,m.info.decoderConfig.displayAspectHeight=m.info.squarePixelHeight),m.initialized=!0}else{if(await w.markNextPacket(),!w.suppliedPacket)throw new Error(`Couldn't parse first media packet for Elementary Stream with PID ${m.pid}`);if(m.info.codec==="aac"){const y=tn.tempFromBytes(w.suppliedPacket.data),b=Wi(y);if(!b)throw new Error("Invalid AAC audio stream; could not read ADTS frame header from first packet.");m.info.aacCodecInfo={isMpeg2:!1,objectType:b.objectType},m.info.numberOfChannels=fo[b.channelConfiguration],m.info.sampleRate=Fi[b.samplingFrequencyIndex]}else if(m.info.codec==="mp3"){const y=ae(tn.tempFromBytes(w.suppliedPacket.data)),b=_o(y,w.suppliedPacket.data.byteLength);if(!b.header)throw new Error("Invalid MP3 audio stream; could not read frame header from first packet.");m.info.numberOfChannels=Ni(b.header.channel),m.info.sampleRate=b.header.sampleRate}else if(m.info.codec==="ac3"){const y=mm(w.suppliedPacket.data);if(!y)throw new Error("Invalid AC-3 audio stream; could not read sync frame from first packet.");if(y.fscod===3)throw new Error("Invalid AC-3 audio stream; reserved sample rate code found in first packet.");m.info.numberOfChannels=Ao[y.acmod]+y.lfeon,m.info.sampleRate=Ds[y.fscod]}else if(m.info.codec==="eac3"){const y=ym(w.suppliedPacket.data);if(!y)throw new Error("Invalid E-AC-3 audio stream; could not read sync frame from first packet.");const b=El(y);if(b===null)throw new Error("Invalid E-AC-3 audio stream; reserved sample rate code found in first packet.");m.info.numberOfChannels=Cl(y),m.info.sampleRate=b}else if(m.info.codec==="dts"){const y=Bl(w.suppliedPacket.data);if(!y)throw new Error("Invalid DTS audio stream; could not read frame header from first packet.");m.info.numberOfChannels=y.numberOfChannels,m.info.sampleRate=y.sampleRate,y.core&&(m.info.dtsFormat=y.hasExtensions?"dtsh":"dtsc")}else throw new Error("Unhandled.");m.info.decoderConfig={codec:Po({codec:m.info.codec,codecDescription:null,aacCodecInfo:m.info.aacCodecInfo,dtsFormat:m.info.dtsFormat}),numberOfChannels:m.info.numberOfChannels,sampleRate:m.info.sampleRate},m.initialized=!0}}}if(c&&this.elementaryStreams.every(m=>m.initialized))break;s+=this.packetStride}if(!c)throw o?new Error("No Program Map Table found in the file."):new Error("No Program Association Table found in the file.");for(const u of this.elementaryStreams)u.initialized&&(u.info.type==="video"?this.trackBackingEntries.push(new Ep(u)):this.trackBackingEntries.push(new Cp(u)))})()}async getTrackBackings(){return await this.readMetadata(),this.trackBackingEntries}async getMetadataTags(){return{}}async getMimeType(){await this.readMetadata();const e=await Promise.all(this.trackBackingEntries.map(n=>n.getDecoderConfig().then(r=>r?.codec??null)));return Ap(e)}async readSection(e,n,r=!1){let i=e,s=e;const a=[];let o=0,c=null,u=!0,l=0;for(;;){const d=await this.readPacket(s);if(s+=this.packetStride,!d)break;if(c){if(d.pid!==c.pid){if(r)break;continue}if(d.payloadUnitStartIndicator===1)break}else{if(d.payloadUnitStartIndicator===0)break;c=d}const h=!!(d.adaptationFieldControl&2),p=!!(d.adaptationFieldControl&1);let m=0;if(h&&(m=1+d.body[0],d===c&&m>1&&(l=d.body[1]>>6&1)),p&&(m===0?(a.push(d.body),o+=d.body.byteLength):(a.push(d.body.subarray(m)),o+=d.body.byteLength-m)),i=s,!n&&o>=64){u=!1;break}if(Ii(this.sectionEndPositions,i,w=>w)!==-1){u=!1;break}}if(u){const d=_e(this.sectionEndPositions,i,h=>h);this.sectionEndPositions.splice(d+1,0,i)}if(!c)return null;let f;if(a.length===1)f=a[0];else{const d=a.reduce((p,m)=>p+m.length,0);f=new Uint8Array(d);let h=0;for(const p of a)f.set(p,h),h+=p.length}return{startPos:e,endPos:n?i:null,pid:c.pid,payload:f,randomAccessIndicator:l}}async readPacketHeader(e){let n=this.reader.requestSlice(e,4);if(ie(n)&&(n=await n),!n)return null;if(de(n)!==71)throw new Error("Invalid TS packet sync byte. Likely an internal bug, please report this file.");const i=$e(n),s=i>>14&1,a=i&8191,c=de(n)>>4&3;return{payloadUnitStartIndicator:s,pid:a,adaptationFieldControl:c}}async readPacket(e){let n=this.reader.requestSlice(e,zt);if(ie(n)&&(n=await n),!n)return null;const r=me(n,zt);if(r[0]!==71)throw new Error("Invalid TS packet sync byte. Likely an internal bug, please report this file.");const s=(r[1]<<8)+r[2],a=s>>14&1,o=s&8191,u=r[3]>>4&3;return{payloadUnitStartIndicator:a,pid:o,adaptationFieldControl:u,body:r.subarray(4)}}normalizeTimestamp(e){if(!this.timestampWrapInfo){const i=60*Jt;this.timestampWrapInfo={reference:e-i,offset:e>=Ho-i?-Ho:Ho}}const{reference:n,offset:r}=this.timestampWrapInfo;return r<0&&e>=n||r>0&&e<n?e+r:e}}const _r=(t,e,n)=>{if(e.payload.byteLength<3)return null;const r=new Ee(e.payload);if(r.readBits(24)!==1)return null;const s=r.readBits(8);if(r.skipBits(16),s===188||s===190||s===191||s===240||s===241||s===255||s===242||s===248)return null;r.skipBits(8);const a=r.readBits(2);r.skipBits(14);let o=null;if(a===2||a===3)o=0,r.skipBits(4),o+=r.readBits(3)*(1<<30),r.skipBits(1),o+=r.readBits(15)*32768,r.skipBits(1),o+=r.readBits(15),o=t.normalizeTimestamp(o);else if(n)throw new Error(pu);return{sectionStartPos:e.startPos,sectionEndPos:e.endPos,pts:o,randomAccessIndicator:e.randomAccessIndicator}},li=(t,e,n)=>{R(e.endPos!==null);const r=_r(t,e,n);if(!r)return null;const i=new Ee(e.payload);i.skipBits(32);const s=i.readBits(16),a=6;i.skipBits(16);const o=i.readBits(8),c=i.pos+8*o;i.pos=c;const u=c/8;R(Number.isInteger(u));const l=e.payload.subarray(u,s>0?a+s:e.payload.byteLength);return{...r,data:l}};class Ys{constructor(e){this.elementaryStream=e,this.packetBuffers=new WeakMap,this.packetSectionStarts=new WeakMap}getId(){return this.elementaryStream.pid}getNumber(){const e=this.elementaryStream.demuxer,n=this.elementaryStream.info.type;let r=0;for(const i of e.trackBackingEntries)if(i.getType()===n&&r++,R(i instanceof Ys),i.elementaryStream===this.elementaryStream)break;return r}getCodec(){throw new Error("Not implemented on base class.")}getInternalCodecId(){return this.elementaryStream.streamType}getName(){return null}getLanguageCode(){return Tt}getDisposition(){return{...Fn,primary:!1}}getTimeResolution(){return Jt}isRelativeToUnixEpoch(){return!1}getUnixTimeForTimestamp(){return null}getPairingMask(){return 1n}getBitrate(){return null}getAverageBitrate(){return null}async getDurationFromMetadata(){return null}async getLiveRefreshInterval(){return null}createEncodedPacket(e,n,r){let i;return this.allPacketsAreKeyPackets()?i="key":i=e.randomAccessIndicator===1?"key":"delta",new Qe(r.metadataOnly?Ut:e.data,i,e.pts/Jt,Math.max(n/Jt,0),e.sequenceNumber,e.data.byteLength)}async getFirstPacket(e){const n=this.elementaryStream.firstSection;R(n);const r=li(this.elementaryStream.demuxer,n,!0);R(r);const i=new ji(this.elementaryStream,r),s=new Wo(this,i),a=await s.readNext();if(!a)return null;const o=this.createEncodedPacket(a.packet,a.duration,e);return this.packetBuffers.set(o,s),this.packetSectionStarts.set(o,a.packet.sectionStartPos),o}async getNextPacket(e,n){let r=this.packetBuffers.get(e);if(r){const l=await r.readNext();if(!l)return null;this.packetBuffers.delete(e);const f=this.createEncodedPacket(l.packet,l.duration,n);return this.packetBuffers.set(f,r),this.packetSectionStarts.set(f,l.packet.sectionStartPos),f}const i=this.packetSectionStarts.get(e);if(i===void 0)throw new Error("Packet was not created from this track.");const s=this.elementaryStream.demuxer,a=await s.readSection(i,!0);R(a);const o=li(s,a,!0);R(o);const c=new ji(this.elementaryStream,o);r=new Wo(this,c);const u=e.sequenceNumber;for(;;){const l=await r.readNext();if(!l)return null;if(l.packet.sequenceNumber>u){const f=this.createEncodedPacket(l.packet,l.duration,n);return this.packetBuffers.set(f,r),this.packetSectionStarts.set(f,l.packet.sectionStartPos),f}}}async getNextKeyPacket(e,n){let r=e;for(;;){if(r=await this.getNextPacket(r,n),!r)return null;if(r.type==="key")return r}}getPacket(e,n){return this.doPacketLookup(e,!1,n)}getKeyPacket(e,n){return this.doPacketLookup(e,!0,n)}async doPacketLookup(e,n,r){const i=Bi(e*Jt),s=this.elementaryStream.demuxer,{reader:a,seekChunkSize:o}=s,c=this.elementaryStream.pid,u=async(v,k,A)=>{let T=v;for(;T<k;){const S=await s.readPacketHeader(T);if(!S)return null;if(S.pid===c&&S.payloadUnitStartIndicator===1){const P=await s.readSection(T,A);if(!P)return null;const M=_r(s,P,!1);if(M&&M.pts!==null)return{pesPacketHeader:M,section:P}}T+=s.packetStride}return null},l=this.elementaryStream.firstSection;R(l);const f=_r(s,l,!0);if(R(f),i<f.pts)return null;let d;const h=this.elementaryStream.referencePesPackets,p=_e(h,i,v=>v.pts),m=p!==-1?h[p]:null;if(m&&i-m.pts<Jt/2)d=m.sectionStartPos;else{let v=0;if(a.fileSize!==null){const k=Math.ceil(a.fileSize/o);if(k>1){let A=0,T=k-1;for(v=A;A<=T;){const S=Math.floor((A+T)/2),P=Za(S*o,s.packetStride)+f.sectionStartPos,M=P+o,B=await u(P,M,!1);if(!B){T=S-1;continue}B.pesPacketHeader.pts<=i?(v=S,A=S+1):T=S-1}}}d=Za(v*o,s.packetStride)+f.sectionStartPos}let w=(await u(d,a.fileSize??1/0,!1))?.pesPacketHeader??null;w||(w=f);const y=this.getReorderSize(),b=async(v,k)=>{const A=await s.readSection(v,!0);R(A);const T=li(s,A,!0);R(T);const S=new ji(this.elementaryStream,T),P=new Wo(this,S);for(;!((Mt(P.presentationOrderPackets)?.pts??-1/0)>=i||!await P.readNextPacket()););const M=Ya(P.presentationOrderPackets,k);if(M===-1)return null;const B=P.presentationOrderPackets[M],N=M===0?0:B.pts-P.presentationOrderPackets[M-1].pts;for(;P.decodeOrderPackets[0]!==B;)P.decodeOrderPackets.shift();P.lastDuration=N;const U=await P.readNext();R(U);const q=this.createEncodedPacket(U.packet,U.duration,r);return this.packetBuffers.set(q,P),this.packetSectionStarts.set(q,U.packet.sectionStartPos),q};if(!n||this.allPacketsAreKeyPackets()){e:for(;;){let v=w.sectionStartPos+s.packetStride;for(;;){const k=await s.readPacketHeader(v);if(!k)break e;if(k.pid===c&&k.payloadUnitStartIndicator===1){const A=await s.readSection(v,!1);if(A){const T=_r(s,A,!1);if(T&&T.pts!==null){if(T.pts>i)break e;w=T,Vo(this.elementaryStream,w);break}}}v+=s.packetStride}}e:for(let v=0;v<y+1;v++){let k=w.sectionStartPos-s.packetStride;for(;k>=s.packetOffset;){const A=await s.readPacketHeader(k);if(!A)break e;if(A.pid===c&&A.payloadUnitStartIndicator===1){const T=await s.readSection(k,!1);if(T){const S=_r(s,T,!1);if(S&&S.pts!==null){w=S;break}}}k-=s.packetStride}}return b(w.sectionStartPos,v=>v.pts<=i)}else{let v=d,k=null;const A=!this.elementaryStream.canBeTrustedWithKeyPackets;for(;;){let T=null;const S=v<=f.sectionStartPos;let P,M=null;if(S)P=f,M=l;else{const U=await u(v,a.fileSize??1/0,A);P=U?.pesPacketHeader??null,M=U?.section??null}let B=!1,N=0;e:for(;P&&!(k!==null&&P.sectionStartPos>=k);){if(P.pts<=i){let q;if(this.elementaryStream.canBeTrustedWithKeyPackets)q=P.randomAccessIndicator===1;else{R(M);const H=li(s,M,!0);R(H);const G=new ji(this.elementaryStream,H);await G.markNextPacket(),q=G.suppliedPacket?.randomAccessIndicator===1}q&&(T=P)}if(P.pts>i&&(B=!0),B&&(N++,N>y))break;let U=P.sectionStartPos+s.packetStride;for(;;){const q=await s.readPacketHeader(U);if(!q)break e;if(q.pid===c&&q.payloadUnitStartIndicator===1){const H=await s.readSection(U,A);if(H){const G=_r(s,H,!1);if(G&&G.pts!==null){P=G,M=H,Vo(this.elementaryStream,P);break}}}U+=s.packetStride}}if(T){let U=T;if(N===0)e:for(let H=0;H<y;H++){let G=U.sectionStartPos-s.packetStride;for(;G>=s.packetOffset;){const Y=await s.readPacketHeader(G);if(!Y)break e;if(Y.pid===c&&Y.payloadUnitStartIndicator===1){const J=await s.readSection(G,A);if(J){const ne=_r(s,J,!1);if(ne&&ne.pts!==null){U=ne;break}}}G-=s.packetStride}}const q=await b(U.sectionStartPos,H=>H.pts<=i&&H.randomAccessIndicator===1);return R(q),q}if(S)return null;k=v,v=Math.max(Za(v-f.sectionStartPos-o,s.packetStride)+f.sectionStartPos,f.sectionStartPos)}}}}class Ep extends Ys{getType(){return"video"}getCodec(){return this.elementaryStream.info.codec}getCodedWidth(){return this.elementaryStream.info.width}getCodedHeight(){return this.elementaryStream.info.height}getSquarePixelWidth(){return this.elementaryStream.info.squarePixelWidth}getSquarePixelHeight(){return this.elementaryStream.info.squarePixelHeight}getRotation(){return 0}async getColorSpace(){return this.elementaryStream.info.colorSpace}async canBeTransparent(){return!1}async getDecoderConfig(){return R(this.elementaryStream.info.decoderConfig),this.elementaryStream.info.decoderConfig}allPacketsAreKeyPackets(){return!1}getReorderSize(){return this.elementaryStream.info.reorderSize}}class Cp extends Ys{getType(){return"audio"}getCodec(){return this.elementaryStream.info.codec}getNumberOfChannels(){return this.elementaryStream.info.numberOfChannels}getSampleRate(){return this.elementaryStream.info.sampleRate}async getDecoderConfig(){return R(this.elementaryStream.info.decoderConfig),this.elementaryStream.info.decoderConfig}allPacketsAreKeyPackets(){return!0}getReorderSize(){return 0}}const Vo=(t,e)=>{const n=t.referencePesPackets,r=_e(n,e.sectionStartPos,i=>i.sectionStartPos);if(r>=0){const i=n[r];if(e.pts<=i.pts)return!1;const s=t.demuxer.minReferencePointByteDistance;if(e.sectionStartPos-i.sectionStartPos<s)return!1;if(r<n.length-1){const a=n[r+1];if(a.pts<e.pts||a.sectionStartPos-e.sectionStartPos<s)return!1}}return n.splice(r+1,0,e),!0};class ji{constructor(e,n){this.currentPos=0,this.pesPackets=[],this.currentPesPacketIndex=0,this.currentPesPacketPos=0,this.endPos=0,this.lastSuppliedPesPacket=null,this.nextPts=null,this.suppliedPacket=null,this.elementaryStream=e,this.pid=e.pid,this.demuxer=e.demuxer,this.startingPesPacket=n}ensureBuffered(e){const n=this.endPos-this.currentPos;return n>=e?e:this.bufferData(e-n).then(()=>Math.min(this.endPos-this.currentPos,e))}getCurrentPesPacket(){const e=this.pesPackets[this.currentPesPacketIndex];return R(e),e}async bufferData(e){const n=this.endPos+e;for(;this.endPos<n;){let r;if(this.pesPackets.length===0)r=this.startingPesPacket;else{let i=Mt(this.pesPackets).sectionEndPos;for(R(i!==null);;){const s=await this.demuxer.readPacketHeader(i);if(!s)return;if(s.pid===this.pid){const a=await this.demuxer.readSection(i,!0);if(!a)return;const o=li(this.demuxer,a,!1);if(o){r=o;break}}i+=this.demuxer.packetStride}}this.pesPackets.push(r),this.endPos+=r.data.byteLength}}readBytes(e){const n=this.getCurrentPesPacket(),r=this.currentPos-this.currentPesPacketPos,i=r+e;if(this.currentPos+=e,i<=n.data.byteLength)return n.data.subarray(r,i);const s=new Uint8Array(e);s.set(n.data.subarray(r));let a=n.data.byteLength-r;for(;;){this.advanceCurrentPacket();const o=this.getCurrentPesPacket(),c=e-a;if(c<=o.data.byteLength){s.set(o.data.subarray(0,c),a);break}s.set(o.data,a),a+=o.data.byteLength}return s}readU8(){let e=this.getCurrentPesPacket();const n=this.currentPos-this.currentPesPacketPos;return this.currentPos++,n<e.data.byteLength?e.data[n]:(this.advanceCurrentPacket(),e=this.getCurrentPesPacket(),e.data[0])}seekTo(e){if(e!==this.currentPos){if(e<this.currentPos)for(;e<this.currentPesPacketPos;){this.currentPesPacketIndex--;const n=this.getCurrentPesPacket();this.currentPesPacketPos-=n.data.byteLength}else for(;;){const n=this.getCurrentPesPacket(),r=this.currentPesPacketPos+n.data.byteLength;if(e<r)break;this.currentPesPacketPos+=n.data.byteLength,this.currentPesPacketIndex++}this.currentPos=e}}skip(e){this.seekTo(this.currentPos+e)}advanceCurrentPacket(){this.currentPesPacketPos+=this.getCurrentPesPacket().data.byteLength,this.currentPesPacketIndex++}async markNextPacket(){R(!this.suppliedPacket);const e=this.elementaryStream;if(e.info.type==="video"){const n=e.info.codec,r=1024;if(n!=="avc"&&n!=="hevc")throw new Error("Unhandled.");const i=n==="avc"?1:2;let s=null,a=!1,o=0;for(;;){let c=this.ensureBuffered(r);if(ie(c)&&(c=await c),c===0)break;const u=this.currentPos,l=this.readBytes(c),f=l.byteLength;let d=0;for(;d<f;){const h=l.indexOf(0,d);if(h===-1||h>=f)break;d=h;const p=u+d;if(d+3>=f){this.seekTo(p);break}const m=l[d+1],g=l[d+2],w=l[d+3];let y=0;if(m===0&&g===0&&w===1?y=4:m===0&&g===1&&(y=3),y===0){d++;continue}const b=p;s??=b;const v=d+y,k=v+i,A=6;if(k+(n==="avc"?A:1)>f){this.seekTo(p);break}const S=l[v];let P,M,B;if(n==="avc")P=Ls(S),M=P===ct.NON_IDR_SLICE||P===ct.SLICE_DPA||P===ct.IDR,B=P===ct.SEI||P===ct.SPS||P===ct.PPS||P===ct.AUD;else{if(P=Kr(S),((S&1)<<5|l[v+1]>>3)>0){d+=y;continue}M=P<=Ge.RASL_R||P>=Ge.BLA_W_LP&&P<=21,B=P>=Ge.VPS_NUT&&P<=37||P===Ge.PREFIX_SEI_NUT||P>=41&&P<=44||P>=48&&P<=55}let N=!1;if(M){let U;if(n==="avc"){const q=l.subarray(k,k+A),H=le(new Ee(q));U=!a||H<=o,o=H}else U=l[k]>>7===1;U&&(a?N=!0:a=!0)}else B&&a&&(N=!0);if(N){const U=b-s;return this.seekTo(s),this.supplyPacket(U,0)}d+=y}if(c<r)break}if(s!==null&&this.endPos>s){const c=this.endPos-s;return this.seekTo(s),this.supplyPacket(c,0)}}else{const n=e.info.codec,r=128;for(;;){let i=this.ensureBuffered(r);ie(i)&&(i=await i);const s=this.currentPos;for(;this.currentPos-s<i;){const a=this.readU8();if(n==="aac"){if(a!==255)continue;this.skip(-1);const o=this.currentPos;let c=this.ensureBuffered(ci);if(ie(c)&&(c=await c),c<ci)return;const u=this.readBytes(ci),l=Wi(tn.tempFromBytes(u));if(l){this.seekTo(o);let f=this.ensureBuffered(l.frameLength);return ie(f)&&(f=await f),this.supplyPacket(f,Math.round(Qs*Jt/e.info.sampleRate))}else this.seekTo(o+1)}else if(n==="mp3"){if(a!==255)continue;this.skip(-1);const o=this.currentPos;let c=this.ensureBuffered(Tr);if(ie(c)&&(c=await c),c<Tr)return;const u=this.readBytes(Tr),l=Ie(u).getUint32(0),f=_o(l,null);if(f.header){this.seekTo(o);let d=this.ensureBuffered(f.header.totalSize);ie(d)&&(d=await d);const h=f.header.audioSamplesInFrame*Jt/e.info.sampleRate;return this.supplyPacket(d,Math.round(h))}else this.seekTo(o+1)}else if(n==="ac3"){if(a!==11)continue;this.skip(-1);const o=this.currentPos;let c=this.ensureBuffered(5);if(ie(c)&&(c=await c),c<5)return;const u=this.readBytes(5);if(u[0]!==11||u[1]!==119){this.seekTo(o+1);continue}const l=u[4]>>6,f=u[4]&63;if(l===3||f>37){this.seekTo(o+1);continue}const d=pm[3*f+l];R(d!==void 0),this.seekTo(o),c=this.ensureBuffered(d),ie(c)&&(c=await c);const h=Math.round(gm*Jt/e.info.sampleRate);return this.supplyPacket(c,h)}else if(n==="eac3"){if(a!==11)continue;this.skip(-1);const o=this.currentPos;let c=this.ensureBuffered(5);if(ie(c)&&(c=await c),c<5)return;const u=this.readBytes(5);if(u[0]!==11||u[1]!==119){this.seekTo(o+1);continue}const f=(((u[2]&7)<<8|u[3])+1)*2,h=u[4]>>6===3?3:u[4]>>4&3,p=_l[h];this.seekTo(o),c=this.ensureBuffered(f),ie(c)&&(c=await c);const m=p*256,g=Math.round(m*Jt/e.info.sampleRate);return this.supplyPacket(c,g)}else if(n==="dts"){if(a!==127&&a!==100)continue;this.skip(-1);const o=this.currentPos;let c=this.ensureBuffered(Hs);if(ie(c)&&(c=await c),c<Hs)return;const u=this.readBytes(Hs),l=Fl(u);let f=l?null:Ws(u);if(!l&&!f){this.seekTo(o+1);continue}if(f&&!f.asset){this.seekTo(o);const m=Math.min(f.frameSize,vm);let g=this.ensureBuffered(m);ie(g)&&(g=await g),f=Ws(this.readBytes(g))??f}let d=l?l.frameSize:f.frameSize;if(l){let m=Math.ceil(l.frameSize/4)*4;for(;;){this.seekTo(o);const g=m+xo;let w=this.ensureBuffered(g);if(ie(w)&&(w=await w),w<g)break;this.seekTo(o+m);const y=Ws(this.readBytes(xo));if(!y)break;m+=y.frameSize,d=m}}const h=l?.sampleCount??f.asset?.sampleCount;if(h===void 0){this.seekTo(o+1);continue}this.seekTo(o),c=this.ensureBuffered(d),ie(c)&&(c=await c);const p=Math.round(h*Jt/e.info.sampleRate);return this.supplyPacket(c,p)}else throw new Error("Unhandled.")}if(i<r)break}}}supplyPacket(e,n){const r=this.getCurrentPesPacket();let i;if(this.lastSuppliedPesPacket===r)R(this.nextPts!==null),i=this.nextPts;else{if(r.pts===null)throw new Error(pu);i=r.pts,Vo(this.elementaryStream,r)}this.lastSuppliedPesPacket=r,this.nextPts=i+n;const s=r.sectionStartPos,a=s+(this.currentPos-this.currentPesPacketPos),o=this.readBytes(e);let c=r.randomAccessIndicator;if(c===0&&!this.elementaryStream.canBeTrustedWithKeyPackets){if(this.elementaryStream.info.type==="audio")c=1;else if(this.elementaryStream.info.decoderConfig){const u=vo(this.elementaryStream.info.codec,this.elementaryStream.info.decoderConfig,o)==="key";c=Number(u)}}this.suppliedPacket={pts:i,data:o,sequenceNumber:a,sectionStartPos:s,randomAccessIndicator:c},this.pesPackets.splice(0,this.currentPesPacketIndex),this.currentPesPacketIndex=0}}class Wo{constructor(e,n){this.decodeOrderPackets=[],this.reorderBuffer=[],this.presentationOrderPackets=[],this.reachedEnd=!1,this.lastDuration=0,this.backing=e,this.context=n,this.reorderSize=e.getReorderSize(),R(this.reorderSize>=0)}async readNext(){if(this.decodeOrderPackets.length===0&&!await this.readNextPacket())return null;await this.ensureCurrentPacketHasNext();const e=this.decodeOrderPackets[0],n=this.presentationOrderPackets.indexOf(e);R(n!==-1);let r;for(n===this.presentationOrderPackets.length-1?r=this.lastDuration:(r=this.presentationOrderPackets[n+1].pts-e.pts,this.lastDuration=r),this.decodeOrderPackets.shift();this.presentationOrderPackets.length>0;){const i=this.presentationOrderPackets[0];if(this.decodeOrderPackets.includes(i))break;this.presentationOrderPackets.shift()}return{packet:e,duration:r}}async readNextPacket(){if(this.reachedEnd)return!1;let e;return this.context.suppliedPacket?e=this.context.suppliedPacket:(await this.context.markNextPacket(),e=this.context.suppliedPacket),this.context.suppliedPacket=null,e?(this.decodeOrderPackets.push(e),this.processPacketThroughReorderBuffer(e),!0):(this.reachedEnd=!0,this.flushReorderBuffer(),!1)}async ensureCurrentPacketHasNext(){const e=this.decodeOrderPackets[0];for(R(e);;){const n=this.presentationOrderPackets.indexOf(e);if(n!==-1&&n<=this.presentationOrderPackets.length-2||!await this.readNextPacket())break}}processPacketThroughReorderBuffer(e){if(this.reorderBuffer.push(e),this.reorderBuffer.length>this.reorderSize){let n=0;for(let i=1;i<this.reorderBuffer.length;i++)this.reorderBuffer[i].pts<this.reorderBuffer[n].pts&&(n=i);const r=this.reorderBuffer[n];this.presentationOrderPackets.push(r),this.reorderBuffer.splice(n,1)}}flushReorderBuffer(){this.reorderBuffer.sort((e,n)=>e.pts-n.pts),this.presentationOrderPackets.push(...this.reorderBuffer),this.reorderBuffer.length=0}}const bu="application/vnd.apple.mpegurl",wu="#EXT-X-STREAM-INF:",vu="#EXT-X-I-FRAME-STREAM-INF:",ku="#EXT-X-MEDIA:",jo="#EXTINF:",Au="#EXT-X-MAP:",xu="#EXT-X-KEY:",Tu="#EXT-X-MEDIA-SEQUENCE:",Su="#EXT-X-BYTERANGE:",Pu="#EXT-X-PROGRAM-DATE-TIME:",Ip="#EXT-X-DISCONTINUITY",_u="#EXT-X-TARGETDURATION:",Mp="#EXT-X-ENDLIST",Eu="#EXT-X-PLAYLIST-TYPE:",Bp="#EXT-X-I-FRAMES-ONLY",Cu=t=>t.length===0||t.startsWith("#")&&!t.startsWith("#EXT");class qi{constructor(e){this._attributes={};let n="",r="",i=!1,s=!1;for(let a=0;a<e.length;a++){const o=e[a];o==='"'?s=!s:o==="="&&!i&&!s?i=!0:o===","&&!s?(n&&(this._attributes[n.trim().toLowerCase()]=r),n="",r="",i=!1):i?r+=o:n+=o}n&&(this._attributes[n.trim().toLowerCase()]=r)}get(e){return this._attributes[e.toLowerCase()]??null}getAsNumber(e){const n=this.get(e);if(n===null)return null;const r=Number(n);return Number.isFinite(r)?r:null}merge(e){Object.assign(this._attributes,e._attributes)}}class Rp{constructor(e,n,r){this.nextInputCacheAge=0,this.inputCache=[],this.trackBackingsPromise=null,this.firstSegment=null,this.firstSegmentFirstTimestamps=new WeakMap,this.firstTimestampCache=new WeakMap,this.input=e,this.path=n,this.trackDeclarations=r}async getDurationFromMetadata(e){const n=await this.getSegmentAt(1/0,{skipLiveWait:e.skipLiveWait});return n?n.timestamp+n.duration:null}async getUnixTimeForTimestamp(e){let n=await this.getSegmentAt(e,{});if(n??=await this.getFirstSegment({}),!n||n.unixEpochTimestamp===null)return null;const r=e-n.timestamp;return n.unixEpochTimestamp+r}async getTrackBackings(){return this.trackBackingsPromise??=(async()=>{const e=[];if(this.trackDeclarations){for(const n of this.trackDeclarations)if(n.type==="video"){const r=Ri(e,i=>i.getType()==="video")+1;e.push(new Mu(this,n,r))}else if(n.type==="audio"){const r=Ri(e,i=>i.getType()==="audio")+1;e.push(new Bu(this,n,r))}}else{if(this.firstSegment=await this.getFirstSegment({}),!this.firstSegment)return[];const r=await this.getInputForSegment(this.firstSegment).getTracks();for(const i of r)if(i.type==="video"){const s=Ri(e,a=>a.getType()==="video")+1;e.push(new Mu(this,{id:e.length+1,type:"video"},s))}else if(i.type==="audio"){const s=Ri(e,a=>a.getType()==="audio")+1;e.push(new Bu(this,{id:e.length+1,type:"audio"},s))}}return e})()}async getFirstTimestampForInput(e){const n=this.firstTimestampCache.get(e);if(n!==void 0)return n;const r=await e.getFirstTimestamp();return this.firstTimestampCache.set(e,r),r}async getMediaOffset(e,n){const r=e.firstSegment??e;let i;if(this.firstSegmentFirstTimestamps.has(r))i=this.firstSegmentFirstTimestamps.get(r);else{const u=this.getInputForSegment(r);i=await this.getFirstTimestampForInput(u),this.firstSegmentFirstTimestamps.set(r,i)}if(r===e)return r.timestamp-i;const s=await this.getFirstTimestampForInput(n),a=e.timestamp-r.timestamp,c=s-i-a;return Math.abs(c)<=Math.min(.25,a)?r.timestamp-i:e.timestamp-s}dispose(){for(const e of this.inputCache)e.input.dispose();this.inputCache.length=0}}class Iu{constructor(e,n,r){this.packetInfos=new WeakMap,this.hydrationPromise=null,this.firstInputTrack=null,this.firstSegment=null,this.segmentedInput=e,this.decl=n,this.number=r}hydrate(){return this.hydrationPromise??=(async()=>{if(this.segmentedInput.firstSegment??=await this.segmentedInput.getFirstSegment({}),!this.segmentedInput.firstSegment)throw new Error("Missing first segment, can't retrieve track.");let e=this.segmentedInput.firstSegment,n=null;for(;e&&(n=(await this.segmentedInput.getInputForSegment(e).getTracks()).find(s=>s.type===this.decl.type&&s.number===this.number)??null,!n);)e=await this.segmentedInput.getNextSegment(e,{});if(!n)throw new Error("No matching track found in underlying media data.");this.firstInputTrack=n,this.firstSegment=e})()}getId(){return this.decl.id}getType(){return this.decl.type}getNumber(){return this.number}delegate(e){return this.firstInputTrack?e():this.hydrate().then(e)}async getDecoderConfig(){return this.delegate(()=>this.firstInputTrack._backing.getDecoderConfig())}getHasOnlyKeyPackets(){return this.delegate(()=>this.firstInputTrack._backing.getHasOnlyKeyPackets?.()??null)}getPairingMask(){return 1n}getCodec(){return this.delegate(()=>this.firstInputTrack._backing.getCodec())}getInternalCodecId(){return this.delegate(()=>this.firstInputTrack._backing.getInternalCodecId())}getDisposition(){return this.delegate(()=>this.firstInputTrack._backing.getDisposition())}getLanguageCode(){return this.delegate(()=>this.firstInputTrack._backing.getLanguageCode())}getName(){return this.delegate(()=>this.firstInputTrack._backing.getName())}getTimeResolution(){return this.delegate(()=>this.firstInputTrack._backing.getTimeResolution())}async isRelativeToUnixEpoch(){return await this.hydrate(),R(this.segmentedInput.firstSegment),this.segmentedInput.firstSegment.unixEpochTimestamp===this.segmentedInput.firstSegment.timestamp}getUnixTimeForTimestamp(e){return this.segmentedInput.getUnixTimeForTimestamp(e)}getBitrate(){return this.delegate(()=>this.firstInputTrack._backing.getBitrate())}getAverageBitrate(){return this.delegate(()=>this.firstInputTrack._backing.getAverageBitrate())}getDurationFromMetadata(e){return this.segmentedInput.getDurationFromMetadata(e)}getLiveRefreshInterval(){return this.segmentedInput.getLiveRefreshInterval()}async createAdjustedPacket(e,n,r){R(e.sequenceNumber>=0),R(this.segmentedInput.firstSegment);const i=await this.segmentedInput.getMediaOffset(n,r.input),s=n.timestamp-this.segmentedInput.firstSegment.timestamp,a=e.clone({timestamp:ll(e.timestamp+i,await r.getTimeResolution()),sequenceNumber:Math.floor(1e8*s)+e.sequenceNumber});return this.packetInfos.set(a,{segment:n,track:r,sourcePacket:e}),a}async getFirstPacket(e){await this.hydrate(),R(this.firstInputTrack),R(this.firstSegment);let n=this.firstInputTrack,r=this.firstSegment;for(;;){if(n){const a=await n._backing.getFirstPacket(e);if(a)return this.createAdjustedPacket(a,r,n)}if(r=await this.segmentedInput.getNextSegment(r,{skipLiveWait:e.skipLiveWait}),!r)break;n=(await this.segmentedInput.getInputForSegment(r).getTracks()).find(a=>a.type===this.firstInputTrack.type&&a.number===this.firstInputTrack.number)??null}return null}getNextPacket(e,n){return this._getNextInternal(e,n,!1)}getNextKeyPacket(e,n){return this._getNextInternal(e,n,!0)}async _getNextInternal(e,n,r){const i=this.packetInfos.get(e);if(!i)throw new Error("Packet was not created from this track.");const s=r?await i.track._backing.getNextKeyPacket(i.sourcePacket,n):await i.track._backing.getNextPacket(i.sourcePacket,n);if(s)return this.createAdjustedPacket(s,i.segment,i.track);let a=i.segment;for(;;){const o=await this.segmentedInput.getNextSegment(a,{skipLiveWait:n.skipLiveWait});if(!o)return null;const l=(await this.segmentedInput.getInputForSegment(o).getTracks()).find(d=>d.type===i.track.type&&d.number===i.track.number);if(!l){a=o;continue}const f=await l._backing.getFirstPacket(n);return f?this.createAdjustedPacket(f,o,l):null}}getPacket(e,n){return this._getPacketInternal(e,n,!1)}getKeyPacket(e,n){return this._getPacketInternal(e,n,!0)}async _getPacketInternal(e,n,r){let i=await this.segmentedInput.getSegmentAt(e,{skipLiveWait:n.skipLiveWait});if(!i)return null;for(await this.hydrate();i;){const s=this.segmentedInput.getInputForSegment(i),o=(await s.getTracks()).find(f=>f.type===this.firstInputTrack.type&&f.number===this.firstInputTrack.number);if(!o){i=await this.segmentedInput.getPreviousSegment(i,{skipLiveWait:n.skipLiveWait});continue}const c=await this.segmentedInput.getMediaOffset(i,s),u=e-c,l=r?await o._backing.getKeyPacket(u,n):await o._backing.getPacket(u,n);if(!l){i=await this.segmentedInput.getPreviousSegment(i,{skipLiveWait:n.skipLiveWait});continue}return this.createAdjustedPacket(l,i,o)}return null}}class Mu extends Iu{getType(){return"video"}getCodec(){return this.delegate(()=>this.firstInputTrack._backing.getCodec())}getCodedWidth(){return this.delegate(()=>this.firstInputTrack._backing.getCodedWidth())}getCodedHeight(){return this.delegate(()=>this.firstInputTrack._backing.getCodedHeight())}getSquarePixelWidth(){return this.delegate(()=>this.firstInputTrack._backing.getSquarePixelWidth())}getSquarePixelHeight(){return this.delegate(()=>this.firstInputTrack._backing.getSquarePixelHeight())}getRotation(){return this.delegate(()=>this.firstInputTrack._backing.getRotation())}async getColorSpace(){return this.delegate(()=>this.firstInputTrack._backing.getColorSpace())}async canBeTransparent(){return this.delegate(()=>this.firstInputTrack._backing.canBeTransparent())}async getDecoderConfig(){return this.delegate(()=>this.firstInputTrack._backing.getDecoderConfig())}}class Bu extends Iu{getType(){return"audio"}getCodec(){return this.delegate(()=>this.firstInputTrack._backing.getCodec())}getNumberOfChannels(){return this.delegate(()=>this.firstInputTrack._backing.getNumberOfChannels())}getSampleRate(){return this.delegate(()=>this.firstInputTrack._backing.getSampleRate())}async getDecoderConfig(){return this.delegate(()=>this.firstInputTrack._backing.getDecoderConfig())}}oo();const Ru=0,Fu=1/0;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(t=>{t()});class zn extends uo{constructor(){super(),this._disposed=!1,this._refCount=0,this._usedForHls=!1,this._refFinalizationRegistry=null,this._sizePromise=null,this.onread=null,typeof FinalizationRegistry<"u"&&(this._refFinalizationRegistry=new FinalizationRegistry(e=>{e._decrementRefCount()}))}async getSizeOrNull(){if(this._disposed)throw new gt;return this._sizePromise??=(async()=>{let e=this._getFileSize();return e!==void 0||(await this._read(0,1,Ru,Fu),e=this._getFileSize(),R(e!==void 0)),e})()}async getSize(){if(this._disposed)throw new gt;const e=await this.getSizeOrNull();if(e===null)throw new Error("Cannot determine the size of an unsized source.");return e}slice(e,n){if(!Number.isInteger(e)||e<0)throw new TypeError("offset must be a non-negative integer.");if(n!==void 0&&(!Number.isInteger(n)||n<0))throw new TypeError("length, when provided, must be a non-negative integer.");return new Hp(this,e,n)}_dispatchRead(e,n){this.onread?.(e,n),this._emit("read",{start:e,end:n})}ref(){return new qo(this)}_incrementRefCount(){this._refCount++}_decrementRefCount(){this._refCount--,this._refCount===0&&(this._dispose(),this._disposed=!0)}}class qo{constructor(e){if(this._freed=!1,e._disposed)throw new Error("Cannot ref a disposed source.");e._incrementRefCount(),e._refFinalizationRegistry?.register(this,e,this),this._source=e}get source(){if(!this._source)throw new Error("Can't get source; ref has already been freed.");return this._source}get freed(){return this._freed}free(){if(this._freed)throw new Error("Illegal operation: double free on SourceRef.");const e=this.source;R(e._refCount>0),e._decrementRefCount(),e._refFinalizationRegistry?.unregister(this),this._freed=!0,this._source=null}[Symbol.dispose](){this.freed||this.free()}}class ui extends zn{constructor(e,n){if(typeof e!="string")throw new TypeError("rootPath must be a string.");if(typeof n!="function")throw new TypeError("requestHandler must be a function.");super(),this.rootPath=e,this.requestHandler=n}_resolveRequest(e){const n=this.requestHandler(e),r=i=>{if(!(i instanceof zn||i instanceof qo))throw new TypeError("requestHandler must return or resolve to a Source or SourceRef.");const s=i instanceof zn?i.ref():i;return s.source._usedForHls||=this._usedForHls,s};return ie(n)?n.then(r):r(n)}}const Du=(t,e)=>t.path===e.path;class Fp extends ui{constructor(){super(...arguments),this._root=null,this._rootRequest=null}_read(e,n,r,i){if(!this._root){if(!this._rootRequest){const s=this._resolveRequest({path:this.rootPath,isRoot:!0}),a=o=>{const c=o instanceof zn?o.ref():o;return this._root=c,this._rootRequest=null,c};ie(s)?this._rootRequest=s.then(a):(a(s),R(this._root))}if(this._rootRequest)return this._rootRequest.then(s=>s.source._read(e,n,r,i))}return this._root.source._read(e,n,r,i)}_getFileSize(){if(this._root)return this._root.source._getFileSize()}_dispose(){this._root?this._root.free():this._rootRequest&&this._rootRequest.then(e=>e.free())}}typeof FinalizationRegistry<"u"&&new FinalizationRegistry(t=>{t.cancel().catch(()=>{})});const Dp=.5*2**20,Np=(t,e,n)=>{if(e instanceof Error&&(e.message.includes("Failed to fetch")||e.message.includes("Load failed")||e.message.includes("NetworkError when attempting to fetch resource"))&&typeof window<"u"){let i=null;try{typeof window<"u"&&typeof window.location<"u"&&(i=new URL(n instanceof Request?n.url:n,window.location.href).origin)}catch{}if((typeof navigator<"u"&&typeof navigator.onLine=="boolean"?navigator.onLine:!0)&&i!==null&&i!==window.location.origin)return pe._warn("Request will not be retried because a CORS error was suspected due to different origins. You can modify this behavior by providing your own function for the 'getRetryDelay' option."),null}return Math.min(2**(t-2),16)},Nu=new Set;class Xo extends ui{constructor(e,n={}){if(typeof e!="string"&&!(e instanceof URL)&&!(typeof Request<"u"&&e instanceof Request))throw new TypeError("url must be a string, URL or Request.");if(!n||typeof n!="object")throw new TypeError("options must be an object.");if(n.requestInit!==void 0&&(!n.requestInit||typeof n.requestInit!="object"))throw new TypeError("options.requestInit, when provided, must be an object.");if(n.getRetryDelay!==void 0&&typeof n.getRetryDelay!="function")throw new TypeError("options.getRetryDelay, when provided, must be a function.");if(n.maxCacheSize!==void 0&&(!Ms(n.maxCacheSize)||n.maxCacheSize<0))throw new TypeError("options.maxCacheSize, when provided, must be a non-negative number.");if(n.parallelism!==void 0&&(!Number.isInteger(n.parallelism)||n.parallelism<1))throw new TypeError("options.parallelism, when provided, must be a positive number.");if(n.fetchFn!==void 0&&typeof n.fetchFn!="function")throw new TypeError("options.fetchFn, when provided, must be a function.");if(n.handleUnhandledError!==void 0&&typeof n.handleUnhandledError!="function")throw new TypeError("options.handleUnhandledError, when provided, must be a function.");const r=e instanceof Request?e.url:e instanceof URL?e.href:e;super(r,a=>new Xo(a.path,this._options)),this._offset=0,this._length=null,this._fileSizeDetermined=!1,this._sequentialBacking=null,this._url=e,this._options=n,this._getRetryDelay=n.getRetryDelay??Np,this._requestInit={...n.requestInit};let i=null;if(n.requestInit?.headers){const a={...eo(n.requestInit.headers)},o=Object.keys(a).find(c=>c.toLowerCase()==="range");o!==void 0&&(i=a[o],delete a[o],this._requestInit.headers=a)}if(e instanceof Request){const a=e.headers.get("Range");if(a!==null){i??=a;const o=new Request(e);o.headers.delete("Range"),this._url=o}}if(i!==null){const a=Op(i);a&&(this._offset=a.offset,this._length=a.length)}const s=2;this._orchestrator=new zp({maxCacheSize:n.maxCacheSize??64*2**20,maxWorkerCount:n.parallelism??s,runWorker:this._runWorker.bind(this),prefetchProfile:Up.network,handleUnhandledError:n.handleUnhandledError})}_getFileSize(){if(!this._fileSizeDetermined)return this._length!==null?this._length:void 0;const e=this._sequentialBacking?this._sequentialBacking._endIndex:this._orchestrator.fileSize;return e===null?this._length!==null?this._length:null:Mi(e-this._offset,0,this._length??1/0)}_read(e,n,r,i){if(this._length!==null&&n>this._length)return null;const s=this._offset,a=this._sequentialBacking?this._sequentialBacking._read(s+e,s+n):this._orchestrator.read(s+e,s+n,Math.max(s+r,s),s+Math.min(i,this._length??1/0)),o=c=>c?(c.offset-=this._offset,c):null;return ie(a)?a.then(o):o(a)}async _runWorker(e){for(;;){const n=new AbortController,r=await dl(this._options.fetchFn??fetch,this._url,fl(this._requestInit,{headers:{Range:`bytes=${e.currentPos}-`},signal:n.signal}),this._getRetryDelay,()=>this._disposed);if(!r.ok)throw new Error(`Error fetching ${String(this._url)}: ${r.status} ${r.statusText}`);r.redirected&&(this.rootPath=r.url);e:if(this._orchestrator.fileSize===null&&(r.status===206||r.type==="basic"&&!r.headers.has("Content-Encoding"))){const s=r.headers.get("Content-Range");if(s){const o=/\/(\d+)/.exec(s);if(o){this._orchestrator.supplyFileSize(Number(o[1]));break e}}const a=r.headers.get("Content-Length");if(a){const o=r.status===206?e.currentPos:0;this._orchestrator.supplyFileSize(o+Number(a))}}if(this._fileSizeDetermined=!0,!r.body)throw new Error("Missing HTTP response body stream. The used fetch function must provide the response body as a ReadableStream.");if(r.status!==206){if(this._sequentialBacking){r.body.cancel();return}if(!this._usedForHls){const s=new URL(this._url instanceof Request?this._url.url:this._url,typeof window<"u"?window.location.href:void 0);s.origin!=="null"&&!(s.pathname.endsWith(".m3u8")||s.pathname.endsWith(".m3u"))&&(Nu.has(s.origin)||(pe._warn(`HTTP server (origin ${s.origin}) did not respond to a range request with 206 Partial Content, meaning the resource will now be streamed sequentially, with old data being evicted from the cache. Reads into evicted regions will throw. To enable efficient media file streaming across a network, please make sure your server supports range requests. Alternatively, set maxCacheSize to Infinity in the UrlSource options to keep the entire resource in memory.`),Nu.add(s.origin)))}this._transitionToSequentialMode(r.body);return}const i=r.body.getReader();for(;;){if(e.currentPos>=e.targetPos||e.aborted){n.abort(),this._orchestrator.signalWorkerStoppedRunning(e);return}let s;try{s=await i.read()}catch(c){if(this._disposed)throw c;const u=this._getRetryDelay(1,c,this._url);if(u!==null){pe._error("Error while reading response stream. Attempting to resume.",c),await Rs(1e3*u);break}else throw c}if(e.aborted)continue;const{done:a,value:o}=s;if(a){if(e.currentPos>=e.targetPos){this._orchestrator.onWorkerFinished(e);return}if(e.strictTarget)break;this._orchestrator.onWorkerFinished(e);return}this._dispatchRead(e.currentPos,e.currentPos+o.length),this._orchestrator.supplyWorkerData(e,o)}}}_transitionToSequentialMode(e){let n=e.getReader(),r=0,i=0;const s=new ReadableStream({pull:async c=>{for(;;){let u;try{u=await n.read()}catch(f){if(this._disposed)throw f;const d=this._getRetryDelay(1,f,this._url);if(d===null)throw f;pe._error("Error while reading response stream. Attempting to resume.",f),await Rs(1e3*d);const h=await dl(this._options.fetchFn??fetch,this._url,fl(this._requestInit,{headers:{Range:`bytes=${r}-`}}),this._getRetryDelay,()=>this._disposed);if(!h.ok)throw new Error(`Error fetching ${String(this._url)}: ${h.status} ${h.statusText}`);if(!h.body)throw new Error("Missing HTTP response body stream. The used fetch function must provide the response body as a ReadableStream.");n=h.body.getReader(),i=h.status===206?0:r;continue}if(u.done){c.close();return}let l=u.value;if(i>0){const f=Math.min(i,l.length);i-=f,l=l.subarray(f)}if(l.length!==0){r+=l.length,c.enqueue(l);return}}},cancel:()=>n.cancel()}),a=new Lu(s,{maxCacheSize:this._orchestrator.options.maxCacheSize,handleUnhandledError:this._options.handleUnhandledError});a._endIndex=this._orchestrator.fileSize,a._cacheMissErrorMessage="Attempted to read data from an already-evicted part of the cache. Because the HTTP server did not honor the range request, data can only be read sequentially, with old data being evicted from the cache. To fix this issue, either ensure your server responds to range requests with 206 Partial Content, or set maxCacheSize to Infinity in the UrlSource options. Note that the latter will store the entire file in the cache if needed, no matter how large.",a.on("read",({start:c,end:u})=>this._dispatchRead(c,u)),this._sequentialBacking=a;const o=new Set;for(const c of this._orchestrator.workers){for(const u of c.pendingSlices)o.add(u);c.aborted=!0,c.pendingSlices.length=0}for(const c of this._orchestrator.queuedReads)for(const u of c.pendingSlices)o.add(u);this._orchestrator.workers.length=0,this._orchestrator.queuedReads.length=0;for(const c of o){const u=a._read(c.start,c.start+c.bytes.length);ie(u)?u.then(l=>{l?(R(l.offset===c.start),c.resolve(l.bytes)):c.resolve(null)},l=>c.reject(l)):(R(u===null),c.resolve(null))}}_dispose(){this._orchestrator.dispose(),this._sequentialBacking&&(this._sequentialBacking._disposed=!0,this._sequentialBacking._dispose())}}const Lp=/^bytes=(\d+)-(\d*)$/,Op=t=>{const e=Lp.exec(t.trim());if(!e)return null;const n=Number(e[1]),r=e[2]===""?null:Number(e[2]);return r!==null&&r<n?null:{offset:n,length:r!==null?r-n+1:null}};class Lu extends zn{constructor(e,n={}){if(!(e instanceof ReadableStream))throw new TypeError("stream must be a ReadableStream.");if(!n||typeof n!="object")throw new TypeError("options must be an object.");if(n.handleUnhandledError!==void 0&&typeof n.handleUnhandledError!="function")throw new TypeError("options.handleUnhandledError, when provided, must be a function.");if(n.maxCacheSize!==void 0&&(!Ms(n.maxCacheSize)||n.maxCacheSize<0))throw new TypeError("options.maxCacheSize, when provided, must be a non-negative number.");super(),this._reader=null,this._cache=[],this._pendingSlices=[],this._currentIndex=0,this._targetIndex=0,this._maxRequestedIndex=0,this._endIndex=null,this._pulling=!1,this._cacheMissErrorMessage="Attempted to read data from an already-evicted part of the cache. With ReadableStreamSource, you must access the data more sequentially or increase the size of its cache.",this._stream=e,this._maxCacheSize=n.maxCacheSize??32*2**20,this._handleUnhandledError=n.handleUnhandledError}_getFileSize(){return this._endIndex}_read(e,n){if(this._endIndex!==null&&n>this._endIndex)return null;this._maxRequestedIndex=Math.max(this._maxRequestedIndex,n);const r=_e(this._cache,e,l=>l.start),i=r!==-1?this._cache[r]:null;if(i&&i.start<=e&&n<=i.end)return{bytes:i.bytes,view:i.view,offset:i.start};let s=e;const a=new Uint8Array(n-e);if(r!==-1)for(let l=r;l<this._cache.length;l++){const f=this._cache[l];if(f.start>=n)break;const d=Math.max(e,f.start);d>s&&this._throwDueToCacheMiss();const h=Math.min(n,f.end);d<h&&(a.set(f.bytes.subarray(d-f.start,h-f.start),d-e),s=h)}if(s===n)return{bytes:a,view:Ie(a),offset:e};this._currentIndex>s&&this._throwDueToCacheMiss();const{promise:o,resolve:c,reject:u}=mt();return this._pendingSlices.push({start:e,end:n,bytes:a,resolve:c,reject:u}),this._targetIndex=Math.max(this._targetIndex,n),this._pulling||(this._pulling=!0,this._pull().catch(l=>{if(this._pulling=!1,this._pendingSlices.length>0)this._pendingSlices.forEach(f=>f.reject(l)),this._pendingSlices.length=0;else if(this._handleUnhandledError)this._handleUnhandledError(l);else throw l})),o}_throwDueToCacheMiss(){throw new Error(this._cacheMissErrorMessage)}async _pull(){for(this._reader??=this._stream.getReader();this._currentIndex<this._targetIndex&&!this._disposed;){const{done:e,value:n}=await this._reader.read();if(e){for(const s of this._pendingSlices)s.resolve(null);this._pendingSlices.length=0,this._endIndex=this._currentIndex;break}const r=this._currentIndex,i=this._currentIndex+n.byteLength;this._dispatchRead(r,i);for(let s=0;s<this._pendingSlices.length;s++){const a=this._pendingSlices[s],o=Math.max(r,a.start),c=Math.min(i,a.end);o<c&&(a.bytes.set(n.subarray(o-r,c-r),o-a.start),c===a.end&&(a.resolve({bytes:a.bytes,view:Ie(a.bytes),offset:a.start}),this._pendingSlices.splice(s,1),s--))}for(this._cache.push({start:r,end:i,bytes:n,view:Ie(n),age:0});this._cache.length>0;){const s=this._cache[0];if(this._maxRequestedIndex-s.end<=this._maxCacheSize)break;this._cache.shift()}this._currentIndex+=n.byteLength}this._pulling=!1}_dispose(){for(const e of this._pendingSlices)e.reject(new gt);this._pendingSlices.length=0,this._cache.length=0,this._reader?.cancel()}}const Up={network:(t,e,n)=>{t=Math.max(0,Math.floor((t-65536)/65536)*65536);for(const i of n){const a=Math.max((i.startPos+i.targetPos)/2,i.targetPos-8388608);if(ao(t,e,a,i.targetPos)){const o=i.targetPos-i.startPos,c=Math.ceil((o+1)/8388608)*8388608,u=2**Math.ceil(Math.log2(o+1)),l=Math.min(u,c);e=Math.max(e,i.startPos+l)}}return e=Math.max(e,t+Dp),{start:t,end:e}}};class zp{constructor(e){this.options=e,this.fileSize=null,this.nextAge=0,this.workers=[],this.cache=[],this.currentCacheSize=0,this.disposed=!1,this.queuedReads=[]}read(e,n,r,i){R(!this.disposed);const s=this.options.prefetchProfile(e,n,this.workers),a=Math.max(s.start,r),o=Math.min(s.end,this.fileSize??1/0,i);R(a<=e&&n<=o);let c=null;const u=_e(this.cache,e,k=>k.start),l=u!==-1?this.cache[u]:null;l&&l.start<=e&&n<=l.end&&(l.age=this.nextAge++,c={bytes:l.bytes,view:l.view,offset:l.start});const f=_e(this.cache,a,k=>k.start),d=c?null:new Uint8Array(n-e);let h=0,p=a;const m=[];if(f!==-1){for(let k=f;k<this.cache.length;k++){const A=this.cache[k];if(A.start>=o)break;if(A.end<=a)continue;const T=Math.max(a,A.start),S=Math.min(o,A.end);if(R(T<=S),p<T&&m.push({start:p,end:T}),p=S,d){const P=Math.max(e,A.start),M=Math.min(n,A.end);if(P<M){const B=P-e;d.set(A.bytes.subarray(P-A.start,M-A.start),B),B===h&&(h=M-e)}}A.age=this.nextAge++}p<o&&m.push({start:p,end:o})}else m.push({start:a,end:o});if(d&&h>=d.length&&(c={bytes:d,view:Ie(d),offset:e}),m.length===0)return R(c),c;const{promise:g,resolve:w,reject:y}=mt(),b=[];for(const k of m){const A=Math.max(e,k.start),T=Math.min(n,k.end);A===k.start&&T===k.end?b.push(k):A<T&&b.push({start:A,end:T})}const v=d&&{start:e,bytes:d,holes:b,resolve:w,reject:y};e:for(const k of m){for(const S of this.workers)if(this.checkHoleAgainstWorker(S,k,v?[v]:[])){this.checkQueuedReadsAgainstWorker(S);continue e}const A=k.end<o||this.fileSize!==null,T=this.createWorker(k.start,k.end,A);if(T)v&&(T.pendingSlices=[v]),this.runWorker(T);else{let S=_e(this.queuedReads,k.start,M=>M.hole.start),P=S!==-1?this.queuedReads[S]:null;for(P&&k.start<=P.hole.end?(P.hole.end=Math.max(P.hole.end,k.end),P.strictTarget&&=A,v&&P.pendingSlices.push(v)):(S++,P={hole:{start:k.start,end:k.end},strictTarget:A,pendingSlices:v?[v]:[],age:this.nextAge++},this.queuedReads.splice(S,0,P));S+1<this.queuedReads.length;){const M=this.queuedReads[S+1];if(M.hole.start>P.hole.end)break;P.hole.end=Math.max(P.hole.end,M.hole.end),P.pendingSlices.push(...M.pendingSlices),P.strictTarget&&=M.strictTarget,P.age=Math.min(P.age,M.age),this.queuedReads.splice(S+1,1)}}}return c?g.catch(k=>{if(!this.disposed)if(this.options.handleUnhandledError)this.options.handleUnhandledError(k);else throw k}):(R(d),c=g.then(k=>k&&{bytes:k,view:Ie(k),offset:e})),c}checkHoleAgainstWorker(e,n,r){if(ao(n.start-131072,n.start,e.currentPos,e.targetPos)){e.targetPos=Math.max(e.targetPos,n.end);for(let s=0;s<r.length;s++){const a=r[s];e.pendingSlices.includes(a)||e.pendingSlices.push(a)}return e.running||this.runWorker(e),!0}return!1}checkQueuedReadsAgainstWorker(e){let n=!1;for(let r=0;r<this.queuedReads.length;r++){const i=this.queuedReads[r];if(this.checkHoleAgainstWorker(e,i.hole,i.pendingSlices))this.queuedReads.splice(r,1),r--,n=!0;else if(n)break}}createWorker(e,n,r){if(this.workers.length>=this.options.maxWorkerCount){let s=null,a=null;for(let o=0;o<this.workers.length;o++){const c=this.workers[o];!c.running&&c.pendingSlices.length===0&&(!s||c.age<s.age)&&(a=o,s=c)}if(s)R(a!==null),R(s.pendingSlices.length===0),this.workers.splice(a,1),this.options.onIdleWorkerRemoved?.(s);else return null}const i={startPos:e,currentPos:e,targetPos:n,strictTarget:r,running:!1,aborted:this.disposed,pendingSlices:[],age:this.nextAge++};return this.workers.push(i),i}runWorker(e){R(!e.running),R(e.currentPos<e.targetPos),e.running=!0,e.age=this.nextAge++,this.options.runWorker(e).catch(n=>{if(e.running=!1,e.pendingSlices.length>0)e.pendingSlices.forEach(r=>r.reject(n)),e.pendingSlices.length=0;else if(!e.aborted&&!this.disposed)if(this.options.handleUnhandledError)this.options.handleUnhandledError(n);else throw n}).finally(()=>{if(!e.running&&this.queuedReads.length>0){let n=0;for(let s=1;s<this.queuedReads.length;s++)this.queuedReads[s].age<this.queuedReads[n].age&&(n=s);const r=this.queuedReads[n],i=this.createWorker(r.hole.start,r.hole.end,r.strictTarget);if(!i)return;this.queuedReads.splice(n,1),i.pendingSlices=r.pendingSlices,this.runWorker(i)}})}supplyWorkerData(e,n){R(!e.aborted);const r=e.currentPos,i=r+n.length;this.insertIntoCache({start:r,end:i,bytes:n,view:Ie(n),age:this.nextAge++}),e.currentPos+=n.length,e.currentPos>e.targetPos&&(e.targetPos=e.currentPos,this.checkQueuedReadsAgainstWorker(e));for(let s=0;s<e.pendingSlices.length;s++){const a=e.pendingSlices[s],o=Math.max(r,a.start),c=Math.min(i,a.start+a.bytes.length);o<c&&a.bytes.set(n.subarray(o-r,c-r),o-a.start);for(let u=0;u<a.holes.length;u++){const l=a.holes[u];r<=l.start&&i>l.start&&(l.start=i),l.end<=l.start&&(a.holes.splice(u,1),u--)}a.holes.length===0&&(a.resolve(a.bytes),e.pendingSlices.splice(s,1),s--)}for(let s=0;s<this.workers.length;s++){const a=this.workers[s];e===a||a.running||ao(r,i,a.currentPos,a.targetPos)&&(this.workers.splice(s,1),this.options.onIdleWorkerRemoved?.(a),s--)}}supplyFileSize(e){R(this.fileSize===null),this.fileSize=e;for(const n of this.workers){n.targetPos=Math.min(n.targetPos,e),n.strictTarget=!0;for(let r=0;r<n.pendingSlices.length;r++){const i=n.pendingSlices[r];for(const s of i.holes)if(s.end>e){i.resolve(null),n.pendingSlices.splice(r,1),r--;break}}}for(let n=0;n<this.queuedReads.length;n++){const r=this.queuedReads[n];if(r.hole.start>=e){for(const i of r.pendingSlices)i.resolve(null);this.queuedReads.splice(n,1),n--}else if(r.hole.end>e){r.hole.end=e,r.strictTarget=!0;for(let i=0;i<r.pendingSlices.length;i++){const s=r.pendingSlices[i];s.start>=e&&(s.resolve(null),r.pendingSlices.splice(i,1),i--)}}}}signalWorkerStoppedRunning(e){e.running=!1,e.aborted||(e.pendingSlices.length=0)}onWorkerFinished(e){const n=this.workers.indexOf(e);R(n!==-1),e.running=!1,this.workers.splice(n,1),this.options.onIdleWorkerRemoved?.(e),this.fileSize===null&&this.supplyFileSize(e.currentPos);for(const r of e.pendingSlices)r.resolve(null)}insertIntoCache(e){if(this.options.maxCacheSize===0)return;let n=_e(this.cache,e.start,r=>r.start)+1;if(n>0){const r=this.cache[n-1];if(r.end>=e.end)return;if(r.end>e.start){const i=new Uint8Array(e.end-r.start);i.set(r.bytes,0),i.set(e.bytes,e.start-r.start),this.currentCacheSize+=e.end-r.end,r.bytes=i,r.view=Ie(i),r.end=e.end,n--,e=r}else this.cache.splice(n,0,e),this.currentCacheSize+=e.bytes.length}else this.cache.splice(n,0,e),this.currentCacheSize+=e.bytes.length;for(let r=n+1;r<this.cache.length;r++){const i=this.cache[r];if(e.end<=i.start)break;if(e.end>=i.end){this.cache.splice(r,1),this.currentCacheSize-=i.bytes.length,r--;continue}const s=new Uint8Array(i.end-e.start);s.set(e.bytes,0),s.set(i.bytes,i.start-e.start),this.currentCacheSize-=e.end-i.start,e.bytes=s,e.view=Ie(s),e.end=i.end,this.cache.splice(r,1);break}for(;this.currentCacheSize>this.options.maxCacheSize;){let r=0,i=this.cache[0];for(let s=1;s<this.cache.length;s++){const a=this.cache[s];a.age<i.age&&(r=s,i=a)}if(this.currentCacheSize-i.bytes.length<=this.options.maxCacheSize)break;this.cache.splice(r,1),this.currentCacheSize-=i.bytes.length}}dispose(){for(const e of this.workers){for(const n of e.pendingSlices)n.reject(new gt);e.pendingSlices.length=0,e.aborted=!0,e.running||this.options.onIdleWorkerRemoved?.(e)}for(const e of this.queuedReads)for(const n of e.pendingSlices)n.reject(new gt);this.workers.length=0,this.cache.length=0,this.queuedReads.length=0,this.disposed=!0}}class Hp extends zn{constructor(e,n,r){if(super(),this._ref=null,e._disposed)throw new Error("Cannot create a slice of a disposed source.");this._baseSource=e,this._offset=n,this._length=r??null}_getFileSize(){const e=this._baseSource._getFileSize();return e===void 0?this._length!==null?this._length:void 0:e===null?this._length!==null?this._length:null:Mi(e-this._offset,0,this._length??1/0)}_read(e,n,r,i){if(this._length!==null&&n>this._length)return null;const s=this._baseSource._read(this._offset+e,this._offset+n,this._offset+r,this._offset+i),a=o=>o?(o.offset-=this._offset,o):null;return ie(s)?s.then(a):a(s)}_dispose(){this._ref?.free()}ref(){return this._ref??=this._baseSource.ref(),super.ref()}}var Ou=function(t,e,n){if(e!=null){if(typeof e!="object"&&typeof e!="function")throw new TypeError("Object expected.");var r,i;if(n){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");r=e[Symbol.asyncDispose]}if(r===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");r=e[Symbol.dispose],n&&(i=r)}if(typeof r!="function")throw new TypeError("Object not disposable.");i&&(r=function(){try{i.call(this)}catch(s){return Promise.reject(s)}}),t.stack.push({value:e,dispose:r,async:n})}else n&&t.stack.push({async:!0});return e},Uu=(function(t){return function(e){function n(a){e.error=e.hasError?new t(a,e.error,"An error was suppressed during disposal."):a,e.hasError=!0}var r,i=0;function s(){for(;r=e.stack.pop();)try{if(!r.async&&i===1)return i=0,e.stack.push(r),Promise.resolve().then(s);if(r.dispose){var a=r.dispose.call(r.value);if(r.async)return i|=2,Promise.resolve(a).then(s,function(o){return n(o),s()})}else i|=1}catch(o){n(o)}if(i===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return s()}})(typeof SuppressedError=="function"?SuppressedError:function(t,e,n){var r=new Error(n);return r.name="SuppressedError",r.error=t,r.suppressed=e,r});const Vp=/^0[xX][0-9a-fA-F]+$/,Wp=/^data:.*;base64,/i;class zu extends Rp{constructor(e,n,r,i){super(e.input,n,r),this.segments=[],this.nextLines=null,this.currentUpdateSegmentsPromise=null,this.streamHasEnded=!1,this.lastSegmentUpdateTime=-1/0,this.refreshInterval=5,this.rootPath=n,this.demuxer=e,this.nextLines=i}runUpdateSegments(){return this.currentUpdateSegmentsPromise??=(async()=>{try{const e=this.getRemainingWaitTimeMs();e>0&&await Rs(e),this.lastSegmentUpdateTime=performance.now(),await this.updateSegments()}finally{this.currentUpdateSegmentsPromise=null}})()}getRemainingWaitTimeMs(){const e=performance.now()-this.lastSegmentUpdateTime,n=Math.max(0,1e3*this.refreshInterval-e);return n<=50?0:n}async updateSegments(){let e=this.nextLines;if(this.nextLines=null,!e){const b={stack:[],error:void 0,hasError:!1};try{const v=Ou(b,await this.demuxer.input._getSourceUncached({path:this.rootPath,isRoot:!1}),!1),A=await new ea(v.source).requestEntireFile();R(A),e=df(A,A.length,{ignore:Cu}),v.source instanceof ui&&(this.rootPath=v.source.rootPath)}catch(v){b.error=v,b.hasError=!0}finally{Uu(b)}}const n=this.input._formatOptions.hls?.offsetTimestampsByDateTime!==!1;let r=!1,i=0,s=null,a=null,o=null,c=0,u=null,l=null,f=null,d=null,h=null,p=null,m=!1,g=Mt(this.segments)??null;const w=b=>{const v=b.indexOf("@"),k=Number(v===-1?b:b.slice(0,v));if(!Number.isInteger(k)||k<0)throw new Error(`Invalid #EXT-X-BYTERANGE length '${b}'.`);let A=null;if(v!==-1&&(A=Number(b.slice(v+1)),!Number.isInteger(A)||A<0))throw new Error(`Invalid #EXT-X-BYTERANGE offset '${b}'.`);return{length:k,offset:A}},y=b=>{c=b,g&&(R(g.sequenceNumber!==null),g.sequenceNumber<b&&(i=g.timestamp+g.duration,u=g.firstSegment,l=g.initSegment,h=g.lastProgramDateTimeSeconds,s=g.unixEpochTimestamp!==null?g.unixEpochTimestamp+g.duration:null,g=null))};for(let b=0;b<e.length;b++){const v=e[b];if(!r){if(v!=="#EXTM3U")throw new Error("Invalid M3U8 file; expected first line to be #EXTM3U.");r=!0;continue}if(!v.startsWith("#")){if(!g){if(a===null)throw new Error("Invalid M3U8 file; a segment must be preceded by an #EXTINF tag.");let k=o;if(k&&k.method==="AES-128"&&!k.iv){const P=new Uint8Array(pn),M=Ie(P);M.setUint32(8,Math.floor(c/2**32)),M.setUint32(12,c),k={...k,iv:P}}const T={path:tr(this.rootPath,v),offset:d?.offset??0,length:d?.length??null},S={timestamp:i,unixEpochTimestamp:s,firstSegment:u,sequenceNumber:c,location:T,duration:a,encryption:k,initSegment:l,lastProgramDateTimeSeconds:h};u??=S,i+=a,s!==null&&(s+=a),this.segments.push(S)}a=null,d===null?f=null:d=null,y(c+1)}if(v.startsWith(jo)){if(g){m=!0;continue}m||(h===null&&c>0&&p!==null&&(i=c*p),m=!0);const k=v.slice(jo.length),A=k.indexOf(","),T=A===-1?k:k.slice(0,A),S=Number(T);if(!Number.isFinite(S)||S<0)throw new Error(`Invalid #EXTINF tag duration '${T}'.`);a=S}else if(v.startsWith(Au)){const k=new qi(v.slice(Au.length)),A=k.get("uri");if(!A)throw new Error("Invalid #EXT-X-MAP tag; missing URI attribute.");const T=k.get("byterange");let S=null;if(T!==null&&(S=w(T)),S&&S.offset===null)throw new Error("Invalid #EXT-X-MAP tag; BYTERANGE attribute must have a specified offset.");if(!g){const M={path:tr(this.rootPath,A),offset:S?.offset??0,length:S?.length??null};if(o?.method==="AES-128"&&!o.iv)throw new Error("IV attribute must be set on #EXT-X-KEY tag preceding the #EXT-X-MAP tag.");l={timestamp:i,unixEpochTimestamp:s,firstSegment:null,sequenceNumber:null,location:M,duration:0,encryption:o,initSegment:null,lastProgramDateTimeSeconds:h}}a=null,d===null?f=null:d=null}else if(v.startsWith(xu)){const k=new qi(v.slice(xu.length)),A=k.get("method");if(A==="NONE")o=null;else if(A==="AES-128"){const T=k.get("uri");if(!T)throw new Error("Invalid #EXT-X-KEY: AES-128 requires a URI attribute.");let S=null;const P=k.get("iv");if(P){if(!Vp.test(P))throw new Error(`Unsupported IV format '${P}'.`);let B=P.slice(2);B=B.padStart(pn*2,"0"),S=new Uint8Array(pn);for(let N=0;N<pn;N++){const U=-pn*2+N;S[N]=parseInt(B.slice(U,U+2),16)}}const M=k.get("keyformat")??"identity";if(M!=="identity")throw new Error("For AES-128 encryption, only the 'identity' KEYFORMAT is currently supported. If you think other formats should be supported, please raise an issue.");o={method:"AES-128",keyUri:tr(this.rootPath,T),iv:S,keyFormat:M}}else if(A==="SAMPLE-AES"||A==="SAMPLE-AES-CTR"){const T=k.get("uri");if(!T)throw new Error(`Invalid #EXT-X-KEY: ${A} requires a URI attribute.`);if((k.get("keyformat")??"identity")==="identity")throw new Error("For SAMPLE-AES and SAMPLE-AES-CTR encryption, the 'identity' KEYFORMAT is not supported. If you think this format should be supported, please raise an issue.");let P=null;if(Wp.test(T)){const M=T.indexOf(","),B=hl(T.slice(M+1));if(B.length>=8&&B[4]===112&&B[5]===115&&B[6]===115&&B[7]===104){const N=Ie(B).getUint32(0);P=Xl(B.subarray(8,Math.min(N,B.length)))}}o={method:A,psshBox:P}}else throw new Error(`Unsupported encryption method '${A}'. If you think this method should be supported, please raise an issue.`)}else if(v.startsWith(Tu)){const k=v.slice(Tu.length),A=Number(k);if(!Number.isInteger(A)||A<0)throw new Error(`Invalid EXT-X-MEDIA-SEQUENCE value '${k}'.`);y(A)}else if(v.startsWith(Su)){const k=w(v.slice(Su.length));if(k.offset===null){if(f===null)throw new Error("Invalid M3U8 file; #EXT-X-BYTERANGE without offset requires a previous byte range.");k.offset=f}d=k,f=k.offset+k.length}else if(v.startsWith(Pu)){if(g)continue;const k=v.slice(Pu.length),A=Date.parse(k);if(!Number.isFinite(A))continue;const T=A/1e3;if(h===T)continue;if(h===null&&this.segments.length>0){const S=Mt(this.segments),P=S.timestamp+S.duration,M=T-P;for(const B of this.segments)B.unixEpochTimestamp=B.timestamp+M,n&&(B.timestamp=B.unixEpochTimestamp)}h=T,s=T,n&&(i=T)}else if(v===Ip)u=null;else if(v.startsWith(_u)){const k=v.slice(_u.length),A=Number(k);if(!Number.isFinite(A)||A<0)throw new Error(`Invalid EXT-X-TARGETDURATION value '${k}'.`);this.refreshInterval=A,p=A}else if(v===Mp){this.streamHasEnded=!0;break}else v.startsWith(Eu)&&v.slice(Eu.length).toLowerCase()==="vod"&&(this.streamHasEnded=!0)}if(!r)throw new Error("Invalid M3U8 file; no #EXTM3U header.")}async getFirstSegment(){return this.segments.length===0&&await this.runUpdateSegments(),this.segments[0]??null}async getSegmentAt(e,n){this.segments.length===0&&await this.runUpdateSegments();let r=!!n.skipLiveWait&&this.getRemainingWaitTimeMs()>0;for(;;){const i=_e(this.segments,e,a=>a.timestamp);if(i===-1)return null;if(i<this.segments.length-1||this.streamHasEnded||r)return this.segments[i];const s=this.segments[i];if(e<s.timestamp+s.duration)return s;await this.runUpdateSegments(),n.skipLiveWait&&(r=!0)}}async getNextSegment(e,n){const r=this.segments.indexOf(e);R(r!==-1);const i=r+1;let s=!!n.skipLiveWait&&this.getRemainingWaitTimeMs()>0;for(;;){if(i<this.segments.length)return this.segments[i];if(this.streamHasEnded||s)return null;await this.runUpdateSegments(),n.skipLiveWait&&(s=!0)}}async getPreviousSegment(e){const n=this.segments.indexOf(e);return R(n!==-1),this.segments[n-1]??null}getInputForSegment(e){const n=e,r=this.inputCache.find(c=>c.segment===n);if(r)return r.age=this.nextInputCacheAge++,r.input;let i=null;(n.initSegment||n.firstSegment)&&(i=this.getInputForSegment(n.initSegment??n.firstSegment));const s={...this.input._formatOptions,isobmff:{...this.input._formatOptions.isobmff,resolveKeyId:this.input._formatOptions.isobmff?.resolveKeyId&&(c=>{if(!n.encryption||!(n.encryption.method==="SAMPLE-AES"||n.encryption.method==="SAMPLE-AES-CTR")||!n.encryption.psshBox)return this.input._formatOptions.isobmff.resolveKeyId(c);let u=c.psshBoxes;const{psshBox:l}=n.encryption;return(l.keyIds===null||l.keyIds.includes(c.keyId))&&!u.some(f=>Gl(f,l))&&(u=[...u,l]),this.input._formatOptions.isobmff.resolveKeyId({...c,psshBoxes:u})})}},a=new Js({source:new Fp(n.location.path,async c=>{R(c.isRoot);const u={...c,isRoot:!1};let l;const f=n.location.offset>0||n.location.length!==null;if(!n.encryption||n.encryption.method==="SAMPLE-AES"||n.encryption.method==="SAMPLE-AES-CTR"){if(l=await this.input._getSourceCached(u),f){const h=l.source.slice(n.location.offset,n.location.length??void 0).ref();l.free(),l=h}}else if(n.encryption.method==="AES-128"){const d=n.encryption;R(d.iv);let h=await this.input._getSourceCached(u);if(f){const w=h.source.slice(n.location.offset,n.location.length??void 0).ref();h.free(),h=w}const p=new ea(h.source),m=Hm(p,async()=>{const g={stack:[],error:void 0,hasError:!1};try{const w=Ou(g,await this.input._getSourceCached({path:d.keyUri,isRoot:!1},Ag),!1),b=await new ea(w.source).requestSlice(0,pn);if(!b)throw new Error("Invalid AES-128 key; expected at least 16 bytes of data.");return{key:me(b,pn),iv:d.iv}}catch(w){g.error=w,g.hasError=!0}finally{Uu(g)}},()=>{h.free()});l=new Lu(m).ref()}else R(!1);return l}),formats:this.input._formats.filter(c=>!(c instanceof $u)),initInput:i??void 0,formatOptions:s});if(a._onFormatDetermined=c=>{if((n.encryption?.method==="SAMPLE-AES"||n.encryption?.method==="SAMPLE-AES-CTR")&&!c._isIsobmff)throw new Error("The SAMPLE-AES and SAMPLE-AES-CTR encryption methods are currently only supported for ISOBMFF files.")},this.inputCache.push({segment:n,input:a,age:this.nextInputCacheAge++}),this.inputCache.length>4){const c=co(this.inputCache,u=>u.age);R(c!==-1),this.inputCache.splice(c,1)}return a}async getLiveRefreshInterval(){return this.getRemainingWaitTimeMs()===0&&await this.runUpdateSegments(),this.streamHasEnded?null:this.refreshInterval}}class jp extends Dn{constructor(e){super(e),this.metadataPromise=null,this.trackBackings=null,this.internalTracks=null,this.segmentedInputs=[],this.hasMasterPlaylist=!0}readMetadata(){return this.metadataPromise??=(async()=>{R(this.input._rootSource instanceof ui);const e=await this.input._reader.requestEntireFile();R(e);const n=df(e,e.length,{ignore:Cu}),{rootPath:r}=this.input._rootSource,i=[],s=[];for(let f=1;f<n.length;f++){const d=n[f];if(d.startsWith(wu)){const h=f,p=n[++f];if(p===void 0)throw new Error("Incorrect M3U8 file; a line must follow the #EXT-X-STREAM-INF tag.");const m=tr(r,p),g=new qi(d.slice(wu.length));if(g.getAsNumber("bandwidth")===null)throw new Error("Invalid M3U8 file; #EXT-X-STREAM-INF tag requires a BANDWIDTH attribute with a valid numerical value.");i.push({fullPath:m,attributes:g,lineNumber:h,hasOnlyKeyPackets:!1})}else if(d.startsWith(vu)){const h=new qi(d.slice(vu.length)),p=h.get("uri");if(p===null)throw new Error("Invalid M3U8 file; #EXT-X-I-FRAME-STREAM-INF tag requires a URI attribute.");if(h.getAsNumber("bandwidth")===null)throw new Error("Invalid M3U8 file; #EXT-X-I-FRAME-STREAM-INF tag requires a BANDWIDTH attribute with a valid numerical value.");const g=tr(r,p);i.push({fullPath:g,attributes:h,lineNumber:f,hasOnlyKeyPackets:!0})}else if(d.startsWith(ku)){const h=new qi(d.slice(ku.length));if(h.get("type")===null)throw new Error("Invalid M3U8 file; #EXT-X-MEDIA tag requires a TYPE attribute.");if(h.get("group-id")===null)throw new Error("Invalid M3U8 file; #EXT-X-MEDIA tag requires a GROUP-ID attribute.");let g=null;const w=h.get("uri");w!==null&&(g=tr(r,w)),s.push({fullPath:g,attributes:h,lineNumber:f})}else if(d!==Bp){if(d.startsWith(jo)){const h=new zu(this,r,null,n);this.segmentedInputs=[h],this.hasMasterPlaylist=!1,this.trackBackings=await h.getTrackBackings();return}}}const a=[...new Set(s.filter(f=>f.attributes.get("type").toLowerCase()==="video").map(f=>f.attributes.get("group-id")))],o=[...new Set(s.filter(f=>f.attributes.get("type").toLowerCase()==="audio").map(f=>f.attributes.get("group-id")))],c=await Promise.all(i.map(async(f,d)=>{const h=[],p=f.attributes.get("codecs");let m;if(p)m=p.split(",").map(P=>P.trim());else{const M=await this.getSegmentedInputForPath(f.fullPath).getTrackBackings(),B=await Promise.all(M.map(async N=>({track:N,codec:await N.getCodec()})));m=await Promise.all(B.filter(N=>N.codec!==null).map(N=>N.track.getDecoderConfig().then(U=>U.codec)))}const g=f.attributes.get("video"),w=f.attributes.get("audio"),y=m.some(P=>Dl.includes(Di(P))),b=m.some(P=>Nl.includes(Di(P)));if(g!==null&&!y){if(!a.includes(g))throw new Error(`Invalid M3U8 file; variant stream references video group "${g}" which is not defined in any #EXT-X-MEDIA tags.`);const P=s.find(M=>{const B=M.attributes.get("group-id"),N=M.attributes.get("type");return B===g&&N.toLowerCase()==="video"});e:if(P){const M=P.attributes.get("uri");if(M===null)break e;const B=tr(r,M),q=(await this.getSegmentedInputForPath(B).getTrackBackings()).find(G=>G.getType()==="video");if(!q||await q.getCodec()===null)break e;const H=await q.getDecoderConfig().then(G=>G?.codec??null);R(H!==null),m.push(H)}}if(w!==null&&!b){if(!o.includes(w))throw new Error(`Invalid M3U8 file; variant stream references audio group "${w}" which is not defined in any #EXT-X-MEDIA tags.`);const P=s.find(M=>{const B=M.attributes.get("group-id"),N=M.attributes.get("type");return B===w&&N.toLowerCase()==="audio"});e:if(P){const M=P.attributes.get("uri");if(M===null)break e;const B=tr(r,M),q=(await this.getSegmentedInputForPath(B).getTrackBackings()).find(G=>G.getType()==="audio");if(!q||await q.getCodec()===null)break e;const H=await q.getDecoderConfig().then(G=>G?.codec??null);R(H!==null),m.push(H)}}m=[...new Set(m)];let v=null,k=null;const A=f.attributes.getAsNumber("bandwidth");R(A!==null);const T=f.attributes.getAsNumber("average-bandwidth"),S=f.attributes.get("name");for(const P of m){const M=Di(P);if(M!==null){if(Dl.includes(M)){if(v!==null)throw new Error("Unsupported M3U8 file; multiple video codecs found in the CODECS attribute of a variant stream.");v=P;const B=f.attributes.get("video");if(B===null){const N=f.attributes.get("resolution");let U=null,q=null;if(N){const H=N.match(/^(\d+)x(\d+)$/);H&&(U=Number(H[1]),q=Number(H[2]))}h.push({id:-1,demuxer:this,backingTrack:null,default:!0,autoselect:!0,languageCode:Tt,lineNumber:f.lineNumber,fullPath:f.fullPath,fullCodecString:v,pairingMask:1n<<BigInt(d),peakBitrate:A,averageBitrate:T,name:S,hasOnlyKeyPackets:f.hasOnlyKeyPackets,info:{type:"video",width:U,height:q}})}else{if(!a.includes(B))throw new Error(`Invalid M3U8 file; variant stream references video group "${B}" which is not defined in any #EXT-X-MEDIA tags.`);for(const N of s){const U=N.attributes.get("group-id"),q=N.attributes.get("type");if(U!==B||q.toLowerCase()!=="video")continue;const H=N.attributes.get("resolution")??f.attributes.get("resolution");let G=null,Y=null;if(H){const J=H.match(/^(\d+)x(\d+)$/);J&&(G=Number(J[1]),Y=Number(J[2]))}h.push({id:-1,demuxer:this,backingTrack:null,default:Ks(N.attributes),autoselect:Ks(N.attributes)||ju(N.attributes),languageCode:qu(N.attributes.get("language")),lineNumber:N.lineNumber,fullPath:N.fullPath??f.fullPath,fullCodecString:v,pairingMask:1n<<BigInt(d),peakBitrate:null,averageBitrate:null,name:N.attributes.get("name"),hasOnlyKeyPackets:f.hasOnlyKeyPackets,info:{type:"video",width:G,height:Y}})}}}else if(Nl.includes(M)){if(k!==null)throw new Error("Unsupported M3U8 file; multiple audio codecs found in the CODECS attribute of a variant stream.");k=P;const B=f.attributes.get("audio");if(B===null){const N=f.attributes.get("channels"),U=N!==null?Number(N.split("/")[0]):null;h.push({id:-1,demuxer:this,backingTrack:null,default:!0,autoselect:!0,languageCode:Tt,lineNumber:f.lineNumber,fullPath:f.fullPath,fullCodecString:k,pairingMask:1n<<BigInt(d),peakBitrate:A,averageBitrate:T,name:S,hasOnlyKeyPackets:f.hasOnlyKeyPackets,info:{type:"audio",numberOfChannels:U!==null&&Number.isInteger(U)&&U>0?U:null}})}else{if(!o.includes(B))throw new Error(`Invalid M3U8 file; variant stream references audio group "${B}" which is not defined in any #EXT-X-MEDIA tags.`);for(const N of s){const U=N.attributes.get("group-id"),q=N.attributes.get("type");if(U!==B||q.toLowerCase()!=="audio")continue;const H=N.attributes.get("channels")??f.attributes.get("channels"),G=H!==null?Number(H.split("/")[0]):null;h.push({id:-1,demuxer:this,backingTrack:null,default:Ks(N.attributes),autoselect:Ks(N.attributes)||ju(N.attributes),languageCode:qu(N.attributes.get("language")),lineNumber:N.lineNumber,fullPath:N.fullPath??f.fullPath,fullCodecString:k,pairingMask:1n<<BigInt(d),peakBitrate:null,averageBitrate:null,name:N.attributes.get("name"),hasOnlyKeyPackets:f.hasOnlyKeyPackets,info:{type:"audio",numberOfChannels:G!==null&&Number.isInteger(G)&&G>0?G:null}})}}}}}return h})),u=[],l=f=>{const d=u.find(h=>h.fullPath===f.fullPath&&h.info.type===f.info.type);d?(d.pairingMask|=f.pairingMask,d.default||=f.default,d.autoselect||=f.autoselect,d.lineNumber=Math.min(d.lineNumber,f.lineNumber),f.peakBitrate!==null&&(d.peakBitrate=Math.max(d.peakBitrate??-1/0,f.peakBitrate)),f.averageBitrate!==null&&(d.averageBitrate=Math.max(d.averageBitrate??-1/0,f.averageBitrate)),d.languageCode===Tt&&(d.languageCode=f.languageCode)):(f.id=u.length+1,u.push(f))};for(const f of c)for(const d of f)l(d);u.sort((f,d)=>f.lineNumber-d.lineNumber),this.trackBackings=[];for(const f of u)f.info.type==="video"?this.trackBackings.push(new Vu(f)):this.trackBackings.push(new Wu(f));this.internalTracks=u})()}async getTrackBackings(){return await this.readMetadata(),R(this.trackBackings),this.trackBackings}getSegmentedInputForPath(e){let n=this.segmentedInputs.find(i=>i.path===e);if(n)return n;let r=null;return this.internalTracks&&(r=this.internalTracks.filter(s=>s.fullPath===e).map(s=>({id:s.id,type:s.info.type}))),n=new zu(this,e,r,null),this.segmentedInputs.push(n),n}async getMetadataTags(){return{}}async getMimeType(){return bu}dispose(){if(this.segmentedInputs){for(const e of this.segmentedInputs)e.dispose();this.segmentedInputs.length=0}}}class Hu{constructor(e){this.internalTrack=e,this.hydrationPromise=null}hydrate(){return this.hydrationPromise??=(async()=>{const e=this.internalTrack.demuxer.getSegmentedInputForPath(this.internalTrack.fullPath);let n=null;const i=(await e.getTrackBackings()).filter(s=>s.getType()===this.getType());if(i.length===1)n=i[0];else if(this instanceof Vu){for(const s of i)if(await s.getCodec()===this.getCodec()){n=s;break}}else{R(this instanceof Wu);for(const s of i)if(await s.getCodec()===this.getCodec()){n=s;break}}if(!n)throw new Error("Could not find matching track in underlying media data.");this.internalTrack.backingTrack=n})()}delegate(e){return this.internalTrack.backingTrack?e():this.hydrate().then(e)}getCodec(){throw new Error("Not implemented on base class.")}getDisposition(){return{...Fn,default:this.internalTrack.autoselect,primary:this.internalTrack.default}}getId(){return this.internalTrack.id}getPairingMask(){return this.internalTrack.pairingMask}getInternalCodecId(){return null}getLanguageCode(){return this.internalTrack.languageCode}getName(){return this.internalTrack.name}getNumber(){R(this.internalTrack.demuxer.internalTracks);const e=this.internalTrack.info.type;let n=0;for(const r of this.internalTrack.demuxer.internalTracks)if(r.info.type===e&&n++,r===this.internalTrack)break;return n}getTimeResolution(){return this.delegate(()=>this.internalTrack.backingTrack.getTimeResolution())}isRelativeToUnixEpoch(){return this.delegate(()=>this.internalTrack.backingTrack.isRelativeToUnixEpoch())}getUnixTimeForTimestamp(e){return this.delegate(()=>this.internalTrack.backingTrack.getUnixTimeForTimestamp(e))}getBitrate(){return this.internalTrack.peakBitrate}getAverageBitrate(){return this.internalTrack.averageBitrate}async getDurationFromMetadata(e){return await this.hydrate(),this.internalTrack.backingTrack.getDurationFromMetadata(e)}async getLiveRefreshInterval(){return await this.hydrate(),this.internalTrack.backingTrack.getLiveRefreshInterval()}getHasOnlyKeyPackets(){return this.internalTrack.hasOnlyKeyPackets||null}async getFirstPacket(e){return await this.hydrate(),this.internalTrack.backingTrack.getFirstPacket(e)}async getPacket(e,n){return await this.hydrate(),this.internalTrack.backingTrack.getPacket(e,n)}async getKeyPacket(e,n){return await this.hydrate(),this.internalTrack.backingTrack.getKeyPacket(e,n)}async getNextPacket(e,n){return await this.hydrate(),this.internalTrack.backingTrack.getNextPacket(e,n)}async getNextKeyPacket(e,n){return await this.hydrate(),this.internalTrack.backingTrack.getNextKeyPacket(e,n)}}class Vu extends Hu{constructor(e){super(e)}get backingVideoTrack(){return this.internalTrack.backingTrack}getType(){return"video"}getCodec(){return Di(this.internalTrack.fullCodecString)}getCodedWidth(){return this.delegate(()=>this.backingVideoTrack.getCodedWidth())}getCodedHeight(){return this.delegate(()=>this.backingVideoTrack.getCodedHeight())}getSquarePixelWidth(){return this.delegate(()=>this.backingVideoTrack.getSquarePixelWidth())}getSquarePixelHeight(){return this.delegate(()=>this.backingVideoTrack.getSquarePixelHeight())}getMetadataDisplayWidth(){return this.backingVideoTrack?null:this.internalTrack.info.width}getMetadataDisplayHeight(){return this.backingVideoTrack?null:this.internalTrack.info.height}getRotation(){return this.delegate(()=>this.backingVideoTrack.getRotation())}async getColorSpace(){return await this.hydrate(),this.backingVideoTrack.getColorSpace()}async canBeTransparent(){return await this.hydrate(),this.backingVideoTrack.canBeTransparent()}getMetadataCodecParameterString(){return this.backingVideoTrack?null:this.internalTrack.fullCodecString}async getDecoderConfig(){return await this.hydrate(),this.backingVideoTrack.getDecoderConfig()}}class Wu extends Hu{constructor(e){super(e)}get backingAudioTrack(){return this.internalTrack.backingTrack}getType(){return"audio"}getCodec(){return Di(this.internalTrack.fullCodecString)}getNumberOfChannels(){return this.internalTrack.info.numberOfChannels!==null?this.internalTrack.info.numberOfChannels:this.delegate(()=>this.backingAudioTrack.getNumberOfChannels())}getSampleRate(){return this.delegate(()=>this.backingAudioTrack.getSampleRate())}getMetadataCodecParameterString(){return this.backingAudioTrack?null:this.internalTrack.fullCodecString}async getDecoderConfig(){return await this.hydrate(),this.backingAudioTrack.getDecoderConfig()}}const Ks=t=>{const e=t.get("default");if(e===null)return!1;const n=e.toUpperCase();if(n==="YES")return!0;if(n==="NO")return!1;throw new Error(`Invalid M3U8 file; #EXT-X-MEDIA DEFAULT attribute must be YES or NO, got "${e}".`)},ju=t=>{const e=t.get("autoselect");if(e===null)return!1;const n=e.toUpperCase();if(n==="YES")return!0;if(n==="NO")return!1;throw new Error(`Invalid M3U8 file; #EXT-X-MEDIA AUTOSELECT attribute must be YES or NO, got "${e}".`)},qu=t=>{if(t===null)return Tt;const e=t.split("-")[0];return e||Tt};class gn{constructor(){this._isIsobmff=!1}}class Xu extends gn{constructor(){super(...arguments),this._isIsobmff=!0}async _getMajorBrand(e){let n=e._reader.requestSlice(0,12);if(ie(n)&&(n=await n),!n)return null;n.skip(4);const r=Ve(n,4);return r!=="ftyp"&&r!=="styp"?null:Ve(n,4)}_createDemuxer(e){return new Mo(e)}}class qp extends Xu{async _canReadInput(e){const n=await this._getMajorBrand(e);if(n!==null)return n!=="qt ";let r=0;for(let i=0;i<10;i++){let s=e._reader.requestSlice(r,8);if(ie(s)&&(s=await s),!s)return!1;let a=ae(s),o=8;if(a===1){let u=e._reader.requestSlice(r+8,8);if(ie(u)&&(u=await u),!u)return!1;a=Ht(u),o=16}if(a<o)return!1;const c=Ve(s,4);if(c==="moof"||c==="sidx")return!0;if(c==="emsg"||c==="prft"||c==="free")r+=a;else return!1}return!1}get name(){return"MP4"}get mimeType(){return"video/mp4"}}class Xp extends Xu{async _canReadInput(e){return await this._getMajorBrand(e)==="qt "}get name(){return"QuickTime File Format"}get mimeType(){return"video/quicktime"}}class Gu extends gn{async isSupportedEBMLOfDocType(e,n){let r=e._reader.requestSlice(0,Ln);if(ie(r)&&(r=await r),!r)return!1;const i=au(r);if(i===null||i<1||i>8||Ae(r,i)!==re.EBML)return!1;const a=ou(r);if(typeof a!="number")return!1;let o=e._reader.requestSlice(r.filePos,a);if(ie(o)&&(o=await o),!o)return!1;const c=r.filePos;for(;o.filePos<=c+a-Xt;){const u=On(o);if(!u)break;const{id:l,size:f}=u,d=o.filePos;if(f===void 0)return!1;switch(l){case re.EBMLVersion:if(Ae(o,f)!==1)return!1;break;case re.EBMLReadVersion:if(Ae(o,f)!==1)return!1;break;case re.DocType:if(si(o,f)!==n)return!1;break;case re.DocTypeVersion:if(Ae(o,f)>4)return!1;break}o.filePos=d+f}return!0}_canReadInput(e){return this.isSupportedEBMLOfDocType(e,"matroska")}_createDemuxer(e){return new Km(e)}get name(){return"Matroska"}get mimeType(){return"video/x-matroska"}}class Gp extends Gu{_canReadInput(e){return this.isSupportedEBMLOfDocType(e,"webm")}get name(){return"WebM"}get mimeType(){return"video/webm"}}class $p extends gn{async _canReadInput(e){let n=0;for(;;){let f=e._reader.requestSlice(n,Gt);if(ie(f)&&(f=await f),!f)break;const d=Vn(f);if(!d)break;n=f.filePos+d.size}const r=await Uo(e._reader,n,n+4096);if(!r)return!1;const i=r.header,s=ql(i.mpegVersionId,i.channel);let a=e._reader.requestSlice(r.startPos+s,4);if(ie(a)&&(a=await a),!a)return!1;const o=ae(a);if(o===Wl||o===jl)return!0;n=r.startPos+r.header.totalSize;const u=await Uo(e._reader,n,n+Tr);if(!u)return!1;const l=u.header;return!(i.channel!==l.channel||i.sampleRate!==l.sampleRate)}_createDemuxer(e){return new ep(e)}get name(){return"MP3"}get mimeType(){return"audio/mpeg"}}class Qp extends gn{async _canReadInput(e){let n=e._reader.requestSlice(0,12);if(ie(n)&&(n=await n),!n)return!1;const r=Ve(n,4);return r!=="RIFF"&&r!=="RIFX"&&r!=="RF64"?!1:(n.skip(4),Ve(n,4)==="WAVE")}_createDemuxer(e){return new up(e)}get name(){return"WAVE"}get mimeType(){return"audio/wav"}}class Yp extends gn{async _canReadInput(e){let n=e._reader.requestSlice(0,4);return ie(n)&&(n=await n),n?Ve(n,4)==="OggS":!1}_createDemuxer(e){return new cp(e)}get name(){return"Ogg"}get mimeType(){return"application/ogg"}}class Kp extends gn{async _canReadInput(e){let n=0;for(;;){let i=e._reader.requestSlice(n,Gt);if(ie(i)&&(i=await i),!i)break;const s=Vn(i);if(!s)break;n=i.filePos+s.size}let r=e._reader.requestSlice(n,4);return ie(r)&&(r=await r),r?Ve(r,4)==="fLaC":!1}get name(){return"FLAC"}get mimeType(){return"audio/flac"}_createDemuxer(e){return new vp(e)}}class Zp extends gn{async _canReadInput(e){let n=0;for(;;){let a=e._reader.requestSlice(n,Gt);if(ie(a)&&(a=await a),!a)break;const o=Vn(a);if(!o)break;n=a.filePos+o.size}let r=e._reader.requestSliceRange(n,zo,ci);if(ie(r)&&(r=await r),!r)return!1;const i=Wi(r);if(!i||(n+=i.frameLength,r=e._reader.requestSliceRange(n,zo,ci),ie(r)&&(r=await r),!r))return!1;const s=Wi(r);return s?i.objectType===s.objectType&&i.samplingFrequencyIndex===s.samplingFrequencyIndex&&i.channelConfiguration===s.channelConfiguration:!1}_createDemuxer(e){return new dp(e)}get name(){return"ADTS"}get mimeType(){return"audio/aac"}}class Jp extends gn{async _canReadInput(e){const n=zt+16+1;let r=e._reader.requestSlice(0,n);if(ie(r)&&(r=await r),!r)return!1;const i=me(r,n);return i[0]===71&&i[zt]===71||i[0]===71&&i[zt+16]===71?!0:i[4]===71&&i[4+zt+4]===71}_createDemuxer(e){return new _p(e)}get name(){return"MPEG Transport Stream"}get mimeType(){return"video/MP2T"}}class $u extends gn{async _canReadInput(e){let n=e._reader.requestSlice(0,7);if(ie(n)&&(n=await n),!n||!(Ve(n,7)==="#EXTM3U"))return!1;if(!(e._rootSource instanceof ui))throw new TypeError("HLS inputs require `InputOptions.source` to be a PathedSource or a ref to one.");return e._rootSource._usedForHls=!0,!0}_createDemuxer(e){return new jp(e)}get name(){return"HTTP Live Streaming (HLS)"}get mimeType(){return bu}}const eg=[new $u,new qp,new Xp,new Gu,new Gp,new Qp,new Yp,new Kp,new $p,new Zp,new Jp],tg=(t,e)=>{if(!t||typeof t!="object")throw new TypeError(`${e}, when provided, must be an object.`);if(t.isobmff!==void 0){if(!t.isobmff||typeof t.isobmff!="object")throw new TypeError(`${e}.isobmff, when provided, must be an object.`);if(t.isobmff.resolveKeyId!==void 0&&typeof t.isobmff.resolveKeyId!="function")throw new TypeError(`${e}.isobmff.resolveKeyId, when provided, must be a function.`)}if(t.hls!==void 0){if(!t.hls||typeof t.hls!="object")throw new TypeError(`${e}.hls, when provided, must be an object.`);if(t.hls.offsetTimestampsByDateTime!==void 0&&typeof t.hls.offsetTimestampsByDateTime!="boolean")throw new TypeError(`${e}.hls.offsetTimestampsByDateTime, when provided, must be a boolean.`)}};var ng=function(t,e,n){if(e!=null){if(typeof e!="object"&&typeof e!="function")throw new TypeError("Object expected.");var r,i;if(n){if(!Symbol.asyncDispose)throw new TypeError("Symbol.asyncDispose is not defined.");r=e[Symbol.asyncDispose]}if(r===void 0){if(!Symbol.dispose)throw new TypeError("Symbol.dispose is not defined.");r=e[Symbol.dispose],n&&(i=r)}if(typeof r!="function")throw new TypeError("Object not disposable.");i&&(r=function(){try{i.call(this)}catch(s){return Promise.reject(s)}}),t.stack.push({value:e,dispose:r,async:n})}else n&&t.stack.push({async:!0});return e},rg=(function(t){return function(e){function n(a){e.error=e.hasError?new t(a,e.error,"An error was suppressed during disposal."):a,e.hasError=!0}var r,i=0;function s(){for(;r=e.stack.pop();)try{if(!r.async&&i===1)return i=0,e.stack.push(r),Promise.resolve().then(s);if(r.dispose){var a=r.dispose.call(r.value);if(r.async)return i|=2,Promise.resolve(a).then(s,function(o){return n(o),s()})}else i|=1}catch(o){n(o)}if(i===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return s()}})(typeof SuppressedError=="function"?SuppressedError:function(t,e,n){var r=new Error(n);return r.name="SuppressedError",r.error=t,r.suppressed=e,r});oo();let Qu=-1/0,Yu=-1/0,Go=null;typeof FinalizationRegistry<"u"&&(Go=new FinalizationRegistry(t=>{const e=performance.now();t.type==="video"?(e-Qu>=1e3&&(pe._error("A VideoSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your VideoSamples as soon as you're done using them."),Qu=e),typeof VideoFrame<"u"&&t.data instanceof VideoFrame&&t.data.close()):(e-Yu>=1e3&&(pe._error("An AudioSample was garbage collected without first being closed. For proper resource management, make sure to call close() on all your AudioSamples as soon as you're done using them."),Yu=e),typeof AudioData<"u"&&t.data instanceof AudioData&&t.data.close())}));class Er{constructor(){this._referenceCount=0,this._lastAllocationBuffer=null}}const $o=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12","NV12","RGBA","RGBX","BGRA","BGRX"],ig=new Set($o);class en{get codedWidth(){return this.visibleRect.width}get codedHeight(){return this.visibleRect.height}get displayWidth(){return this.rotation%180===0?this.squarePixelWidth:this.squarePixelHeight}get displayHeight(){return this.rotation%180===0?this.squarePixelHeight:this.squarePixelWidth}get microsecondTimestamp(){return Math.trunc(Qr*this.timestamp)}get microsecondDuration(){return Math.trunc(Qr*this.duration)}get hasAlpha(){return this.format&&this.format.includes("A")}constructor(e,n){if(this._closed=!1,e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer||ArrayBuffer.isView(e)){if(!n||typeof n!="object")throw new TypeError("init must be an object.");if(n.format===void 0||!ig.has(n.format))throw new TypeError("init.format must be one of: "+$o.join(", "));if(!Number.isInteger(n.codedWidth)||n.codedWidth<=0)throw new TypeError("init.codedWidth must be a positive integer.");if(!Number.isInteger(n.codedHeight)||n.codedHeight<=0)throw new TypeError("init.codedHeight must be a positive integer.");if(n.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw new TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");if(!Number.isFinite(n.timestamp))throw new TypeError("init.timestamp must be a number.");if(n.duration!==void 0&&(!Number.isFinite(n.duration)||n.duration<0))throw new TypeError("init.duration, when provided, must be a non-negative number.");if(n.layout!==void 0){if(!Array.isArray(n.layout))throw new TypeError("init.layout, when provided, must be an array.");for(const s of n.layout){if(!s||typeof s!="object"||Array.isArray(s))throw new TypeError("Each entry in init.layout must be an object.");if(!Number.isInteger(s.offset)||s.offset<0)throw new TypeError("plane.offset must be a non-negative integer.");if(!Number.isInteger(s.stride)||s.stride<0)throw new TypeError("plane.stride must be a non-negative integer.")}}if(n.visibleRect!==void 0&&lo(n.visibleRect,"init.visibleRect"),n.displayWidth!==void 0&&(!Number.isInteger(n.displayWidth)||n.displayWidth<=0))throw new TypeError("init.displayWidth, when provided, must be a positive integer.");if(n.displayHeight!==void 0&&(!Number.isInteger(n.displayHeight)||n.displayHeight<=0))throw new TypeError("init.displayHeight, when provided, must be a positive integer.");if(n.displayWidth!==void 0!=(n.displayHeight!==void 0))throw new TypeError("init.displayWidth and init.displayHeight must be either both provided or both omitted.");this.format=n.format,this.rotation=n.rotation??0,this.timestamp=n.timestamp,this.duration=n.duration??0;const r=n.layout??og(n.format,n.codedWidth,n.codedHeight);let i=n.colorSpace??null;i===null&&(this.format==="RGBA"||this.format==="RGBX"||this.format==="BGRA"||this.format==="BGRX"?i={primaries:"bt709",transfer:"iec61966-2-1",matrix:"rgb",fullRange:!0}:i={primaries:"bt709",transfer:"bt709",matrix:"bt709",fullRange:!1}),this.visibleRect={left:n.visibleRect?.left??0,top:n.visibleRect?.top??0,width:n.visibleRect?.width??n.codedWidth,height:n.visibleRect?.height??n.codedHeight},n.displayWidth!==void 0?(this.squarePixelWidth=this.rotation%180===0?n.displayWidth:n.displayHeight,this.squarePixelHeight=this.rotation%180===0?n.displayHeight:n.displayWidth):(this.squarePixelWidth=this.visibleRect.width,this.squarePixelHeight=this.visibleRect.height),this._data=n._doNotCopy?In(e):In(e).slice(),this._layout=r,this.colorSpace=new Qo(i)}else if(typeof VideoFrame<"u"&&e instanceof VideoFrame){if(n?.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw new TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");if(n?.timestamp!==void 0&&!Number.isFinite(n?.timestamp))throw new TypeError("init.timestamp, when provided, must be a number.");if(n?.duration!==void 0&&(!Number.isFinite(n.duration)||n.duration<0))throw new TypeError("init.duration, when provided, must be a non-negative number.");n?.visibleRect!==void 0&&lo(n.visibleRect,"init.visibleRect"),this._data=e,this._layout=null,this.format=e.format,this.visibleRect={left:e.visibleRect?.x??0,top:e.visibleRect?.y??0,width:e.visibleRect?.width??e.codedWidth,height:e.visibleRect?.height??e.codedHeight},this.rotation=n?.rotation??0,this.squarePixelWidth=e.displayWidth,this.squarePixelHeight=e.displayHeight,this.timestamp=n?.timestamp??e.timestamp/1e6,this.duration=n?.duration??(e.duration??0)/1e6,this.colorSpace=new Qo(e.colorSpace)}else if(typeof HTMLImageElement<"u"&&e instanceof HTMLImageElement||typeof SVGImageElement<"u"&&e instanceof SVGImageElement||typeof ImageBitmap<"u"&&e instanceof ImageBitmap||typeof HTMLVideoElement<"u"&&e instanceof HTMLVideoElement||typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement||typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas){if(!n||typeof n!="object")throw new TypeError("init must be an object.");if(n.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw new TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");if(!Number.isFinite(n.timestamp))throw new TypeError("init.timestamp must be a number.");if(n.duration!==void 0&&(!Number.isFinite(n.duration)||n.duration<0))throw new TypeError("init.duration, when provided, must be a non-negative number.");if(n.visibleRect!==void 0&&lo(n.visibleRect,"init.visibleRect"),typeof VideoFrame<"u")return new en(new VideoFrame(e,{timestamp:Math.trunc(n.timestamp*Qr),duration:Math.trunc((n.duration??0)*Qr)||void 0,visibleRect:n.visibleRect&&{x:n.visibleRect.left,y:n.visibleRect.top,width:n.visibleRect.width,height:n.visibleRect.height}}),n);let r=0,i=0;if("naturalWidth"in e?(r=e.naturalWidth,i=e.naturalHeight):"videoWidth"in e?(r=e.videoWidth,i=e.videoHeight):"width"in e&&(r=Number(e.width),i=Number(e.height)),!r||!i)throw new TypeError("Could not determine dimensions.");const s=n.visibleRect??{left:0,top:0,width:r,height:i},a=new OffscreenCanvas(s.width,s.height),o=a.getContext("2d",{alpha:Xh(),willReadFrequently:!0});if(!o)throw new Error("OffscreenCanvas must have support for the '2d' context in order to create a VideoSample from this data.");o.drawImage(e,-s.left,-s.top),this._data=a,this._layout=null,this.format="RGBX",this.visibleRect={left:0,top:0,width:s.width,height:s.height},this.squarePixelWidth=s.width,this.squarePixelHeight=s.height,this.rotation=n.rotation??0,this.timestamp=n.timestamp,this.duration=n.duration??0,this.colorSpace=new Qo({matrix:"rgb",primaries:"bt709",transfer:"iec61966-2-1",fullRange:!0})}else if(e instanceof Er){if(!n||typeof n!="object")throw new TypeError("init must be an object.");if(n.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw new TypeError("init.rotation, when provided, must be 0, 90, 180, or 270.");if(!Number.isFinite(n.timestamp))throw new TypeError("init.timestamp must be a number.");if(n.duration!==void 0&&(!Number.isFinite(n.duration)||n.duration<0))throw new TypeError("init.duration, when provided, must be a non-negative number.");if(this._data=e,e._referenceCount++,this.format=e.getFormat(),this.format!==null&&!$o.includes(this.format))throw new TypeError("getFormat() must return a VideoSamplePixelFormat or null.");if(this.visibleRect={left:0,top:0,width:e.getCodedWidth(),height:e.getCodedHeight()},!Number.isInteger(this.visibleRect.width)||this.visibleRect.width<=0)throw new TypeError("getCodedWidth() must return a positive integer.");if(!Number.isInteger(this.visibleRect.height)||this.visibleRect.height<=0)throw new TypeError("getCodedHeight() must return a positive integer.");if(this.squarePixelWidth=e.getSquarePixelWidth(),!Number.isInteger(this.squarePixelWidth)||this.squarePixelWidth<=0)throw new TypeError("getSquarePixelWidth() must return a positive integer.");if(this.squarePixelHeight=e.getSquarePixelHeight(),!Number.isInteger(this.squarePixelHeight)||this.squarePixelHeight<=0)throw new TypeError("getSquarePixelHeight() must return a positive integer.");this.rotation=n.rotation??0,this.timestamp=n.timestamp,this.duration=n.duration??0,this.colorSpace=e.getColorSpace()}else throw new TypeError("Invalid data type: Must be a BufferSource, CanvasImageSource, or VideoSampleResource.");this.encodeOptions=n?.encodeOptions??{},this.pixelAspectRatio=Bs({num:this.squarePixelWidth*this.codedHeight,den:this.squarePixelHeight*this.codedWidth}),Go?.register(this,{type:"video",data:this._data},this)}clone(){if(this._closed)throw new Error("VideoSample is closed.");return R(this._data!==null),this._data instanceof Er?new en(this._data,{timestamp:this.timestamp,duration:this.duration,rotation:this.rotation,encodeOptions:this.encodeOptions}):Gi(this._data)?new en(this._data.clone(),{timestamp:this.timestamp,duration:this.duration,rotation:this.rotation,encodeOptions:this.encodeOptions}):this._data instanceof Uint8Array?(R(this._layout),new en(this._data,{format:this.format,layout:this._layout,codedWidth:this.codedWidth,codedHeight:this.codedHeight,timestamp:this.timestamp,duration:this.duration,colorSpace:this.colorSpace,rotation:this.rotation,visibleRect:this.visibleRect,displayWidth:this.displayWidth,displayHeight:this.displayHeight,encodeOptions:this.encodeOptions,_doNotCopy:!0})):new en(this._data,{format:this.format,codedWidth:this.codedWidth,codedHeight:this.codedHeight,timestamp:this.timestamp,duration:this.duration,colorSpace:this.colorSpace,rotation:this.rotation,visibleRect:this.visibleRect,displayWidth:this.displayWidth,displayHeight:this.displayHeight,encodeOptions:this.encodeOptions})}close(){this._closed||(Go?.unregister(this),this._data instanceof Er?(this._data._referenceCount--,this._data._referenceCount===0&&this._data.close()):Gi(this._data)?this._data.close():this._data=null,this._closed=!0)}allocationSize(e={}){if(tf(e),this._closed)throw new Error("VideoSample is closed.");if((e.format??this.format)==null)throw new Error("Cannot get allocation size when format is null.");return Gi(this._data)?this._data.allocationSize(e):nf(this,e).allocationSize}async copyTo(e,n={}){if(!Lh(e))throw new TypeError("destination must be an ArrayBuffer or an ArrayBuffer view.");if(tf(n),this._closed)throw new Error("VideoSample is closed.");if((n.format??this.format)==null)throw new Error("Cannot copy video sample data when format is null.");if(R(this._data!==null),Gi(this._data))return this._data.copyTo(e,n);if(n.format&&!["RGBA","RGBX","BGRA","BGRX"].includes(this.format)&&["RGBA","RGBX","BGRA","BGRX"].includes(n.format))if(this._data instanceof Er){const u={stack:[],error:void 0,hasError:!1};try{const l=ng(u,await this._data.toRgbSample({timestamp:this.timestamp,duration:this.duration,rotation:this.rotation},n.colorSpace??"srgb"),!1);if(!(l instanceof en))throw new TypeError("toRgbSample() must return a VideoSample.");if(!["RGBA","RGBX","BGRA","BGRX"].includes(l.format))throw new Error(`Sample returned by toRgbSample was expected to have an RGB format, got '${l.format}' instead.`);return await l.copyTo(e,n)}catch(l){u.error=l,u.hasError=!0}finally{rg(u)}}else{if(typeof VideoFrame>"u")throw new Error("For this sample, converting from a non-RGB to an RGB format requires VideoFrame to be defined.");const u=this.toVideoFrame(),l=await u.copyTo(e,n);return u.close(),l}const r=nf(this,n);R(this.format);const i=In(e);if(i.byteLength<r.allocationSize)throw new TypeError(`Destination buffer too small. Required: ${r.allocationSize}, Available: ${i.byteLength}`);const s=Zs(this.format);let a;if(this._data instanceof Er){let u=this._data.getDataPlanes();if(ie(u)&&(u=await u),!Array.isArray(u)||u.some(l=>!(l.data instanceof Uint8Array)||!Number.isInteger(l.stride)||l.stride<0))throw new TypeError('getDataPlanes() must return an array of objects with a Uint8Array "data" property and a non-negative integer "stride" property.');a=u}else if(this._data instanceof Uint8Array)R(this._layout),R(this._layout.length===s.length),a=this._layout.map((u,l)=>{const f=Math.ceil(this.codedHeight/s[l].heightDivisor);return{data:this._data.subarray(u.offset,u.offset+u.stride*f),stride:u.stride}});else{const l=this._data.getContext("2d");R(l);const f=l.getImageData(0,0,this.codedWidth,this.codedHeight);a=[{data:In(f.data),stride:4*this.codedWidth}]}const o=[],c=s.length;for(let u=0;u<c;u++){const l=r.computedLayouts[u],f=a[u].stride,d=a[u].data;let h=l.sourceTop*f;h+=l.sourceLeftBytes;let p=l.destinationOffset;const m=l.sourceWidthBytes,g={offset:p,stride:l.destinationStride};for(let w=0;w<l.sourceHeight;w++){if(h+m>d.byteLength)throw new Error("Source buffer OOB read.");if(p+m>i.byteLength)throw new Error("Destination buffer OOB write.");const y=d.subarray(h,h+m);i.set(y,p),h+=f,p+=l.destinationStride}o.push(g)}if(n.format!==void 0){const u=this.format.startsWith("RGB")!==n.format.startsWith("RGB"),l=this.format.includes("X")&&n.format.includes("A");if(u||l)for(let f=0;f<r.allocationSize;f+=4){if(u){const d=i[f],h=i[f+2];i[f]=h,i[f+2]=d}l&&(i[f+3]=255)}}return o}toVideoFrame(){if(this._closed)throw new Error("VideoSample is closed.");if(R(this._data!==null),this._data instanceof Er){if(this.format===null)throw new Error("Cannot convert a VideoSampleResource-backed VideoSample to VideoFrame if format is null.");const e=this._data.getDataPlanes();if(ie(e))throw new Error("Cannot convert a VideoSampleResource-backed VideoSample to VideoFrame if getDataPlanes() returns a promise.");const n=e.reduce((a,o)=>a+o.data.byteLength,0),r=new Uint8Array(n);let i=0;const s=[];for(const a of e)r.set(a.data,i),s.push(i),i+=a.data.byteLength;return new VideoFrame(r,{format:this.format,layout:e.map((a,o)=>({offset:s[o],stride:a.stride})),codedWidth:this.codedWidth,codedHeight:this.codedHeight,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration,colorSpace:this.colorSpace,visibleRect:this.visibleRect,displayWidth:this.squarePixelWidth,displayHeight:this.squarePixelHeight})}else return Gi(this._data)?new VideoFrame(this._data,{timestamp:this.microsecondTimestamp,duration:this.microsecondDuration||void 0}):this._data instanceof Uint8Array?(R(this._layout),new VideoFrame(this._data,{format:this.format,codedWidth:this.codedWidth,codedHeight:this.codedHeight,layout:this._layout,timestamp:this.microsecondTimestamp,duration:this.microsecondDuration||void 0,colorSpace:this.colorSpace,visibleRect:this.visibleRect,displayWidth:this.squarePixelWidth,displayHeight:this.squarePixelHeight})):new VideoFrame(this._data,{timestamp:this.microsecondTimestamp,duration:this.microsecondDuration||void 0})}draw(e,n,r,i,s,a,o,c,u){let l=0,f=0,d=this.displayWidth,h=this.displayHeight,p=0,m=0,g=this.displayWidth,w=this.displayHeight;if(a!==void 0?(l=n,f=r,d=i,h=s,p=a,m=o,c!==void 0?(g=c,w=u):(g=d,w=h)):(p=n,m=r,i!==void 0&&(g=i,w=s)),!(typeof CanvasRenderingContext2D<"u"&&e instanceof CanvasRenderingContext2D||typeof OffscreenCanvasRenderingContext2D<"u"&&e instanceof OffscreenCanvasRenderingContext2D))throw new TypeError("context must be a CanvasRenderingContext2D or OffscreenCanvasRenderingContext2D.");if(!Number.isFinite(l))throw new TypeError("sx must be a number.");if(!Number.isFinite(f))throw new TypeError("sy must be a number.");if(!Number.isFinite(d)||d<0)throw new TypeError("sWidth must be a non-negative number.");if(!Number.isFinite(h)||h<0)throw new TypeError("sHeight must be a non-negative number.");if(!Number.isFinite(p))throw new TypeError("dx must be a number.");if(!Number.isFinite(m))throw new TypeError("dy must be a number.");if(!Number.isFinite(g)||g<0)throw new TypeError("dWidth must be a non-negative number.");if(!Number.isFinite(w)||w<0)throw new TypeError("dHeight must be a non-negative number.");if(this._closed)throw new Error("VideoSample is closed.");({sx:l,sy:f,sWidth:d,sHeight:h}=this._rotateSourceRegion(l,f,d,h,this.rotation));const y=this.toCanvasImageSource();e.save();const b=p+g/2,v=m+w/2;e.translate(b,v),e.rotate(this.rotation*Math.PI/180);const k=this.rotation%180===0?1:g/w;e.scale(1/k,k),e.drawImage(y,l,f,d,h,-g/2,-w/2,g,w),e.restore()}drawWithFit(e,n){if(!(typeof CanvasRenderingContext2D<"u"&&e instanceof CanvasRenderingContext2D||typeof OffscreenCanvasRenderingContext2D<"u"&&e instanceof OffscreenCanvasRenderingContext2D))throw new TypeError("context must be a CanvasRenderingContext2D or OffscreenCanvasRenderingContext2D.");if(!n||typeof n!="object")throw new TypeError("options must be an object.");if(!["fill","contain","cover"].includes(n.fit))throw new TypeError("options.fit must be 'fill', 'contain', or 'cover'.");if(n.rotation!==void 0&&![0,90,180,270].includes(n.rotation))throw new TypeError("options.rotation, when provided, must be 0, 90, 180, or 270.");n.crop!==void 0&&ef(n.crop,"options.");const r=e.canvas.width,i=e.canvas.height,s=n.rotation??this.rotation,[a,o]=s%180===0?[this.squarePixelWidth,this.squarePixelHeight]:[this.squarePixelHeight,this.squarePixelWidth];let c=n.crop;c&&(c=Ju(c,a,o));let u,l,f,d;const{sx:h,sy:p,sWidth:m,sHeight:g}=this._rotateSourceRegion(n.crop?.left??0,n.crop?.top??0,n.crop?.width??a,n.crop?.height??o,s);if(n.fit==="fill")u=0,l=0,f=r,d=i;else{const[y,b]=n.crop?[n.crop.width,n.crop.height]:[a,o],v=n.fit==="contain"?Math.min(r/y,i/b):Math.max(r/y,i/b);f=y*v,d=b*v,u=(r-f)/2,l=(i-d)/2}e.save();const w=s%180===0?1:f/d;e.translate(r/2,i/2),e.rotate(s*Math.PI/180),e.scale(1/w,w),e.translate(-r/2,-i/2),e.drawImage(this.toCanvasImageSource(),h,p,m,g,u,l,f,d),e.restore()}_rotateSourceRegion(e,n,r,i,s){return s===90?[e,n,r,i]=[n,this.squarePixelHeight-e-r,i,r]:s===180?[e,n]=[this.squarePixelWidth-e-r,this.squarePixelHeight-n-i]:s===270&&([e,n,r,i]=[this.squarePixelWidth-n-i,e,i,r]),{sx:e,sy:n,sWidth:r,sHeight:i}}_drawWithFitAndMipmapping(e,n,r){const i=e.width,s=e.height,[a,o]=r.rotation%180===0?[this.squarePixelWidth,this.squarePixelHeight]:[this.squarePixelHeight,this.squarePixelWidth],c=r.crop?r.crop.width:a,u=r.crop?r.crop.height:o;let l=0;2*i<c&&2*s<u&&(l=Math.floor(Math.log2(Math.min(c/i,u/s))));const f=i*2**l,d=s*2**l,{canvas:h,context:p,isNew:m}=l>0?Zu(f,d):{canvas:e,context:n,isNew:r.targetIsFresh};p.imageSmoothingQuality="high",r.fillBlack?(p.fillStyle="black",p.fillRect(0,0,f,d)):m||p.clearRect(0,0,f,d),this.drawWithFit(p,{fit:r.fit,rotation:r.rotation,crop:r.crop}),p.globalCompositeOperation="copy";for(let g=l;g>1;g--){const w=i*2**g,y=s*2**g;p.drawImage(h,0,0,w,y,0,0,w/2,y/2)}p.globalCompositeOperation="source-over",l>0&&(n.imageSmoothingQuality="high",n.globalCompositeOperation="copy",n.drawImage(h,0,0,2*i,2*s,0,0,i,s),n.globalCompositeOperation="source-over")}toCanvasImageSource(){if(this._closed)throw new Error("VideoSample is closed.");if(R(this._data!==null),this._data instanceof Er||this._data instanceof Uint8Array){const e=this.toVideoFrame();return queueMicrotask(()=>e.close()),e}else return this._data}async transform(e){if(!e||typeof e!="object")throw new TypeError("options must be an object.");if(e.width!==void 0&&(!Number.isInteger(e.width)||e.width<=0))throw new TypeError("options.width, when provided, must be a positive integer.");if(e.height!==void 0&&(!Number.isInteger(e.height)||e.height<=0))throw new TypeError("options.height, when provided, must be a positive integer.");if(e.roundDimensionsTo!==void 0&&(!Number.isInteger(e.roundDimensionsTo)||e.roundDimensionsTo<=0))throw new TypeError("options.roundDimensionsTo, when provided, must be a positive integer.");if(e.fit!==void 0&&!["fill","contain","cover"].includes(e.fit))throw new TypeError('options.fit, when provided, must be one of "fill", "contain", or "cover".');if(e.width!==void 0&&e.height!==void 0&&e.fit===void 0)throw new TypeError("When both options.width and options.height are provided, options.fit must also be provided.");if(e.rotate!==void 0&&![0,90,180,270].includes(e.rotate))throw new TypeError("options.rotate, when provided, must be 0, 90, 180 or 270.");if(e.crop!==void 0&&ef(e.crop,"options."),e.alpha!==void 0&&!["keep","discard"].includes(e.alpha))throw new TypeError("options.alpha, when provided, must be 'keep' or 'discard'.");const n=Wa(this.rotation+(e.rotate??0)),[r,i]=n%180===0?[this.squarePixelWidth,this.squarePixelHeight]:[this.squarePixelHeight,this.squarePixelWidth];let s=e.crop;s&&(s=Ju(s,r,i));const a=s?s.width:r,o=s?s.height:i,c=a/o;let u,l;e.width!==void 0&&e.height===void 0?(u=e.width,l=u/c):e.width===void 0&&e.height!==void 0?(l=e.height,u=l*c):e.width!==void 0&&e.height!==void 0?(u=e.width,l=e.height):(u=a,l=o),u=Ka(u,e.roundDimensionsTo??1),l=Ka(l,e.roundDimensionsTo??1);const f={width:u,height:l,fit:e.fit??"fill",rotation:n,crop:s??{left:0,top:0,width:r,height:i},alpha:e.alpha??"keep"};for(const m of sg){let g=m(this,f);if(ie(g)&&(g=await g),g!==null)return g}const{canvas:d,context:h,isNew:p}=Zu(f.width,f.height);return this._drawWithFitAndMipmapping(d,h,{fit:f.fit,rotation:f.rotation,crop:f.crop,targetIsFresh:p,fillBlack:f.alpha==="discard"}),new en(d,{timestamp:this.timestamp,duration:this.duration,rotation:0})}setRotation(e){if(![0,90,180,270].includes(e))throw new TypeError("newRotation must be 0, 90, 180, or 270.");this.rotation=e}setTimestamp(e){if(!Number.isFinite(e))throw new TypeError("newTimestamp must be a number.");this.timestamp=e}setDuration(e){if(!Number.isFinite(e)||e<0)throw new TypeError("newDuration must be a non-negative number.");this.duration=e}setEncodeOptions(e){if(!e||typeof e!="object")throw new TypeError("newEncodeOptions must be an object.");this.encodeOptions=e}[Symbol.dispose](){this.close()}}const sg=[],ag=3,Xi=[];let Ku=0;const Zu=(t,e)=>{for(const i of Xi)if(i.canvas.width===t&&i.canvas.height===e)return i.age=Ku++,{canvas:i.canvas,context:i.context,isNew:!1};let n;if(typeof OffscreenCanvas<"u")n=new OffscreenCanvas(t,e);else{if(typeof window>"u"||typeof document>"u")throw new Error("Cannot transform VideoSamples in this environment. Either run in an environment with OffscreenCanvas or HTMLCanvasElement, or supply a custom VideoSample transformer using registerVideoSampleTransformer().");n=document.createElement("canvas"),n.width=t,n.height=e}const r=n.getContext("2d",{alpha:!0,willReadFrequently:!1});if(!r)throw new Error("The '2d' canvas context is required to transform VideoSamples. Register a custom transformer using registerVideoSampleTransformer to work around this limitation.");return Xi.length>=ag&&Xi.splice(co(Xi,i=>i.age),1),Xi.push({canvas:n,context:r,age:Ku++}),{canvas:n,context:r,isNew:!0}};class Qo{constructor(e){if(e!==void 0){if(!e||typeof e!="object")throw new TypeError("init.colorSpace, when provided, must be an object.");const n=Object.keys(qa);if(e.primaries!=null&&!n.includes(e.primaries))throw new TypeError(`init.colorSpace.primaries, when provided, must be one of ${n.join(", ")}.`);const r=Object.keys(Xa);if(e.transfer!=null&&!r.includes(e.transfer))throw new TypeError(`init.colorSpace.transfer, when provided, must be one of ${r.join(", ")}.`);const i=Object.keys(Ga);if(e.matrix!=null&&!i.includes(e.matrix))throw new TypeError(`init.colorSpace.matrix, when provided, must be one of ${i.join(", ")}.`);if(e.fullRange!=null&&typeof e.fullRange!="boolean")throw new TypeError("init.colorSpace.fullRange, when provided, must be a boolean.")}this.primaries=e?.primaries??null,this.transfer=e?.transfer??null,this.matrix=e?.matrix??null,this.fullRange=e?.fullRange??null}toJSON(){return{primaries:this.primaries,transfer:this.transfer,matrix:this.matrix,fullRange:this.fullRange}}}const Gi=t=>typeof VideoFrame<"u"&&t instanceof VideoFrame,Ju=(t,e,n)=>{const r=Math.min(t.left,e),i=Math.min(t.top,n),s=Math.min(t.width,e-r),a=Math.min(t.height,n-i);return R(s>=0),R(a>=0),{left:r,top:i,width:s,height:a}},ef=(t,e)=>{if(!t||typeof t!="object")throw new TypeError(e+"crop, when provided, must be an object.");if(!Number.isInteger(t.left)||t.left<0)throw new TypeError(e+"crop.left must be a non-negative integer.");if(!Number.isInteger(t.top)||t.top<0)throw new TypeError(e+"crop.top must be a non-negative integer.");if(!Number.isInteger(t.width)||t.width<0)throw new TypeError(e+"crop.width must be a non-negative integer.");if(!Number.isInteger(t.height)||t.height<0)throw new TypeError(e+"crop.height must be a non-negative integer.")},tf=t=>{if(!t||typeof t!="object")throw new TypeError("options must be an object.");if(t.colorSpace!==void 0&&!["display-p3","srgb"].includes(t.colorSpace))throw new TypeError("options.colorSpace, when provided, must be 'display-p3' or 'srgb'.");if(t.format!==void 0&&typeof t.format!="string")throw new TypeError("options.format, when provided, must be a string.");if(t.layout!==void 0){if(!Array.isArray(t.layout))throw new TypeError("options.layout, when provided, must be an array.");for(const e of t.layout){if(!e||typeof e!="object")throw new TypeError("Each entry in options.layout must be an object.");if(!Number.isInteger(e.offset)||e.offset<0)throw new TypeError("plane.offset must be a non-negative integer.");if(!Number.isInteger(e.stride)||e.stride<0)throw new TypeError("plane.stride must be a non-negative integer.")}}if(t.rect!==void 0){if(!t.rect||typeof t.rect!="object")throw new TypeError("options.rect, when provided, must be an object.");if(t.rect.x!==void 0&&(!Number.isInteger(t.rect.x)||t.rect.x<0))throw new TypeError("options.rect.x, when provided, must be a non-negative integer.");if(t.rect.y!==void 0&&(!Number.isInteger(t.rect.y)||t.rect.y<0))throw new TypeError("options.rect.y, when provided, must be a non-negative integer.");if(t.rect.width!==void 0&&(!Number.isInteger(t.rect.width)||t.rect.width<0))throw new TypeError("options.rect.width, when provided, must be a non-negative integer.");if(t.rect.height!==void 0&&(!Number.isInteger(t.rect.height)||t.rect.height<0))throw new TypeError("options.rect.height, when provided, must be a non-negative integer.")}},og=(t,e,n)=>{const r=Zs(t),i=[];let s=0;for(const a of r){const o=Math.ceil(e/a.widthDivisor),c=Math.ceil(n/a.heightDivisor),u=o*a.sampleBytes,l=u*c;i.push({offset:s,stride:u}),s+=l}return i},Zs=t=>{const e=(n,r,i,s,a)=>{const o=[{sampleBytes:n,widthDivisor:1,heightDivisor:1},{sampleBytes:r,widthDivisor:i,heightDivisor:s},{sampleBytes:r,widthDivisor:i,heightDivisor:s}];return a&&o.push({sampleBytes:n,widthDivisor:1,heightDivisor:1}),o};switch(t){case"I420":return e(1,1,2,2,!1);case"I420P10":case"I420P12":return e(2,2,2,2,!1);case"I420A":return e(1,1,2,2,!0);case"I420AP10":case"I420AP12":return e(2,2,2,2,!0);case"I422":return e(1,1,2,1,!1);case"I422P10":case"I422P12":return e(2,2,2,1,!1);case"I422A":return e(1,1,2,1,!0);case"I422AP10":case"I422AP12":return e(2,2,2,1,!0);case"I444":return e(1,1,1,1,!1);case"I444P10":case"I444P12":return e(2,2,1,1,!1);case"I444A":return e(1,1,1,1,!0);case"I444AP10":case"I444AP12":return e(2,2,1,1,!0);case"NV12":return[{sampleBytes:1,widthDivisor:1,heightDivisor:1},{sampleBytes:2,widthDivisor:2,heightDivisor:2}];case"RGBA":case"RGBX":case"BGRA":case"BGRX":return[{sampleBytes:4,widthDivisor:1,heightDivisor:1}];default:Is(t),R(!1)}},nf=(t,e)=>{const n={left:0,top:0,width:t.codedWidth,height:t.codedHeight},r=e.rect,i=cg(n,r,t.codedWidth,t.codedHeight,t.format),s=e.layout;let a;if(!e.format||e.format===t.format)a=t.format;else if(["RGBA","RGBX","BGRA","BGRX"].includes(e.format))a=e.format;else throw new Error("NotSupportedError: Invalid destination format.");return ug(i,a,s)},cg=(t,e,n,r,i)=>{const s={...t};if(e!==void 0){if(e.width===0||e.height===0)throw new TypeError("visibleRect dimensions cannot be zero.");if((e.x||0)+(e.width||0)>n)throw new TypeError("visibleRect exceeds codedWidth.");if((e.y||0)+(e.height||0)>r)throw new TypeError("visibleRect exceeds codedHeight.");s.x=e.x||0,s.y=e.y||0,s.width=e.width||0,s.height=e.height||0}if(!lg(i,s))throw new TypeError("visibleRect alignment is invalid for the format.");return s},lg=(t,e)=>{if(t===null)return!0;const n=Zs(t);for(let r=0;r<n.length;r++){const i=n[r],s=i.widthDivisor,a=i.heightDivisor;if((e.x||0)%s!==0||(e.y||0)%a!==0)return!1}return!0},ug=(t,e,n)=>{const r=Zs(e),i=r.length;if(n!==void 0&&n.length!==i)throw new TypeError(`Layout must have ${i} planes.`);let s=0;const a=[],o=[];for(let c=0;c<i;c++){const u=r[c],l=u.sampleBytes,f=u.widthDivisor,d=u.heightDivisor,h={destinationOffset:0,destinationStride:0,sourceTop:0,sourceHeight:0,sourceLeftBytes:0,sourceWidthBytes:0};if(h.sourceTop=Math.ceil(Math.trunc(t.y||0)/d),h.sourceHeight=Math.ceil(Math.trunc(t.height||0)/d),h.sourceLeftBytes=Math.floor(Math.trunc(t.x||0)/f)*l,h.sourceWidthBytes=Math.floor(Math.trunc(t.width||0)/f)*l,n!==void 0){const g=n[c];if(g.stride<h.sourceWidthBytes)throw new TypeError(`Stride for plane ${c} is too small.`);h.destinationOffset=g.offset,h.destinationStride=g.stride}else h.destinationOffset=s,h.destinationStride=h.sourceWidthBytes;const m=h.destinationStride*h.sourceHeight+h.destinationOffset;if(m>4294967295)throw new TypeError("Allocation size exceeds limit.");o.push(m),s=Math.max(s,m);for(let g=0;g<c;g++){const w=a[g];if(!(o[c]<=w.destinationOffset||o[g]<=h.destinationOffset))throw new TypeError("Planes overlap.")}a.push(h)}return{allocationSize:s,computedLayouts:a}};const rf=[],fg=[];const Cr=t=>{if(!t||typeof t!="object")throw new TypeError("options must be an object.");if(t.metadataOnly!==void 0&&typeof t.metadataOnly!="boolean")throw new TypeError("options.metadataOnly, when defined, must be a boolean.");if(t.verifyKeyPackets!==void 0&&typeof t.verifyKeyPackets!="boolean")throw new TypeError("options.verifyKeyPackets, when defined, must be a boolean.");if(t.verifyKeyPackets&&t.metadataOnly)throw new TypeError("options.verifyKeyPackets and options.metadataOnly cannot be enabled together.");if(t.skipLiveWait!==void 0&&typeof t.skipLiveWait!="boolean")throw new TypeError("options.skipLiveWait, when defined, must be a boolean.")},fi=t=>{if(!Ms(t))throw new TypeError("timestamp must be a number.")},Yo=(t,e,n)=>n.verifyKeyPackets?e.then(async r=>{if(!r||r.type==="delta")return r;const i=await t.determinePacketType(r);return i&&(r.type=i),r}):e;class Ko{constructor(e){if(!(e instanceof $i))throw new TypeError("track must be an InputTrack.");this._track=e}async getFirstPacket(e={}){if(Cr(e),this._track.input._disposed)throw new gt;return Yo(this._track,this._track._backing.getFirstPacket(e),e)}async getFirstKeyPacket(e={}){Cr(e);const n=await this.getFirstPacket(e);return n?n.type==="key"?n:this.getNextKeyPacket(n,e):null}async getPacket(e,n={}){if(fi(e),Cr(n),this._track.input._disposed)throw new gt;return Yo(this._track,this._track._backing.getPacket(e,n),n)}async getNextPacket(e,n={}){if(!(e instanceof Qe))throw new TypeError("packet must be an EncodedPacket.");if(Cr(n),this._track.input._disposed)throw new gt;return Yo(this._track,this._track._backing.getNextPacket(e,n),n)}async getKeyPacket(e,n={}){if(fi(e),Cr(n),this._track.input._disposed)throw new gt;if(!n.verifyKeyPackets)return this._track._backing.getKeyPacket(e,n);const r=await this._track._backing.getKeyPacket(e,n);return r&&(R(r.type==="key"),await this._track.determinePacketType(r)==="delta"?this.getKeyPacket(r.timestamp-1/await this._track.getTimeResolution(),n):r)}async getNextKeyPacket(e,n={}){if(!(e instanceof Qe))throw new TypeError("packet must be an EncodedPacket.");if(Cr(n),this._track.input._disposed)throw new gt;if(!n.verifyKeyPackets)return this._track._backing.getNextKeyPacket(e,n);const r=await this._track._backing.getNextKeyPacket(e,n);return r&&(R(r.type==="key"),await this._track.determinePacketType(r)==="delta"?this.getNextKeyPacket(r,n):r)}packets(e,n,r={}){if(e!==void 0&&!(e instanceof Qe))throw new TypeError("startPacket must be an EncodedPacket.");if(e!==void 0&&e.isMetadataOnly&&!r?.metadataOnly)throw new TypeError("startPacket can only be metadata-only if options.metadataOnly is enabled.");if(n!==void 0&&!(n instanceof Qe))throw new TypeError("endPacket must be an EncodedPacket.");if(Cr(r),this._track.input._disposed)throw new gt;const i=[];let{promise:s,resolve:a}=mt(),{promise:o,resolve:c}=mt(),u=!1,l=!1,f=null,d=!1;const h=[],p=()=>Math.max(2,h.length);(async()=>{let g=e??await this.getFirstPacket(r);for(;g&&!l&&!this._track.input._disposed&&!(n&&g.sequenceNumber>=n?.sequenceNumber);){if(i.length>p()){({promise:o,resolve:c}=mt()),await o;continue}i.push(g),a(),{promise:s,resolve:a}=mt(),g=await this.getNextPacket(g,r)}u=!0,a()})().catch(g=>{d||(f=g,d=!0,a())});const m=this._track;return{async next(){for(;;){if(m.input._disposed)throw new gt;if(l)return{value:void 0,done:!0};if(d)throw f;if(i.length>0){const g=i.shift(),w=performance.now();for(h.push(w);h.length>0&&w-h[0]>=1e3;)h.shift();return c(),{value:g,done:!1}}else{if(u)return{value:void 0,done:!0};await s}}},async return(){return l=!0,c(),a(),{value:void 0,done:!0}},async throw(g){throw g},[Symbol.asyncIterator](){return this}}}}class dg{constructor(e,n){this.onSample=e,this.onError=n}}class hg{mediaSamplesInRange(e=-1/0,n=1/0,r){fi(e),fi(n);const i=[];let s=!1,a=null,{promise:o,resolve:c}=mt(),{promise:u,resolve:l}=mt(),f=!1,d=!1,h=!1,p=null,m=null,g=!1;const w={...r,verifyKeyPackets:!0,metadataOnly:!1};(async()=>{p=await this._createDecoder(P=>{if(l(),P.timestamp>=n&&(d=!0),d){P.close();return}a&&(P.timestamp>e?(i.push(a),s=!0):a.close()),P.timestamp>=e&&(i.push(P),s=!0),a=s?null:P,i.length>0&&(c(),{promise:o,resolve:c}=mt())},P=>{g||(m=P,g=!0,c())});const v=this._createPacketSink(),k=await v.getKeyPacket(e,w)??await v.getFirstKeyPacket(w);let A=k;const S=v.packets(k??void 0,void 0,w);for(await S.next();A&&!d&&!this._track.input._disposed;){const P=sf(i.length);if(i.length+p.getDecodeQueueSize()>P){({promise:u,resolve:l}=mt()),await u;continue}p.decode(A);const M=await S.next();if(M.done)break;A=M.value}await S.return(),!h&&!this._track.input._disposed&&await p.flush(),!s&&a&&i.push(a),f=!0,c()})().catch(v=>{g||(m=v,g=!0,c())}).finally(()=>{p?.close()});const y=this._track,b=()=>{a?.close();for(const v of i)v.close()};return{async next(){for(;;){if(y.input._disposed)throw h=!0,d=!0,b(),new gt;if(h)return{value:void 0,done:!0};if(g)throw h=!0,d=!0,b(),m;if(i.length>0){const v=i.shift();return l(),{value:v,done:!1}}else if(!f)await o;else return{value:void 0,done:!0}}},async return(){return h=!0,d=!0,l(),c(),b(),{value:void 0,done:!0}},async throw(v){throw v},[Symbol.asyncIterator](){return this}}}mediaSamplesAtTimestamps(e,n){Hh(e);const r=zh(e),i=[],s=[];let{promise:a,resolve:o}=mt(),{promise:c,resolve:u}=mt(),l=!1,f=!1,d=null,h=null,p=!1;const m=b=>{s.push(b),o(),{promise:a,resolve:o}=mt()},g={...n,verifyKeyPackets:!0,metadataOnly:!1};(async()=>{d=await this._createDecoder(P=>{if(u(),f){P.close();return}let M=0;for(;i.length>0&&P.timestamp-i[0]>-1e-10;)M++,i.shift();if(M>0)for(let B=0;B<M;B++)m(B<M-1?P.clone():P);else P.close()},P=>{p||(h=P,p=!0,o())});const b=this._createPacketSink();let v=null,k=null,A=-1;const T=async()=>{R(k),R(d);let P=k;for(d.decode(P);P.sequenceNumber<A;){const M=sf(s.length);for(;s.length+d.getDecodeQueueSize()>M&&!f;)({promise:c,resolve:u}=mt()),await c;if(f)break;const B=await b.getNextPacket(P,g);R(B),d.decode(B),P=B}A=-1},S=async()=>{R(d),await d.flush();for(let P=0;P<i.length;P++)m(null);i.length=0};for await(const P of r){if(fi(P),f||this._track.input._disposed)break;const M=await b.getPacket(P,g),B=M&&await b.getKeyPacket(P,g);if(!B){A!==-1&&(await T(),await S()),m(null),v=null;continue}v&&(B.sequenceNumber!==k.sequenceNumber||M.timestamp<v.timestamp)&&(await T(),await S()),i.push(M.timestamp),A=Math.max(M.sequenceNumber,A),v=M,k=B}!f&&!this._track.input._disposed&&(A!==-1&&await T(),await S()),l=!0,o()})().catch(b=>{p||(h=b,p=!0,o())}).finally(()=>{d?.close()});const w=this._track,y=()=>{for(const b of s)b?.close()};return{async next(){for(;;){if(w.input._disposed)throw f=!0,y(),new gt;if(f)return{value:void 0,done:!0};if(p)throw f=!0,y(),h;if(s.length>0){const b=s.shift();return R(b!==void 0),u(),{value:b,done:!1}}else if(!l)await a;else return{value:void 0,done:!0}}},async return(){return f=!0,u(),o(),y(),{value:void 0,done:!0}},async throw(b){throw b},[Symbol.asyncIterator](){return this}}}}const sf=t=>t===0?40:8;class mg extends dg{constructor(e,n,r,i,s,a){super(e,n),this.codec=r,this.decoderConfig=i,this.rotation=s,this.timeResolution=a,this.decoder=null,this.customDecoder=null,this.customDecoderCallSerializer=new qh,this.customDecoderQueueSize=0,this.inputTimestamps=[],this.sampleQueue=[],this.currentPacketIndex=0,this.raslSkipped=!1,this.alphaDecoder=null,this.alphaHadKeyframe=!1,this.colorQueue=[],this.alphaQueue=[],this.merger=null,this.decodedAlphaChunkCount=0,this.alphaDecoderQueueSize=0,this.nullAlphaFrameQueue=[],this.currentAlphaPacketIndex=0,this.alphaRaslSkipped=!1,this.finalSamples=[],this.mergeAlphaPromises=[];const o=rf.find(c=>c.supports(r,i));if(o)this.customDecoder=new o,this.customDecoder.codec=r,this.customDecoder.config=i,this.customDecoder.onSample=c=>{if(!(c instanceof en))throw new TypeError("The argument passed to onSample must be a VideoSample.");this.finalizeAndEmitSample(c)},this.customDecoder.onError=c=>{n(c)},this.customDecoderCallSerializer.call(()=>this.customDecoder.init()).catch(c=>n(c));else{const c=l=>{if(this.alphaQueue.length>0){const f=this.alphaQueue.shift();R(f!==void 0),this.mergeAlpha(l,f)}else this.colorQueue.push(l)};if(so()){if(r==="avc"&&this.decoderConfig.description){const l=vl(In(this.decoderConfig.description));if(l&&l.sequenceParameterSets.length>0){const f=Us(l.sequenceParameterSets[0]);f&&f.frameMbsOnlyFlag===0&&(this.decoderConfig={...this.decoderConfig,hardwareAcceleration:"prefer-software"})}}$a(this.decoderConfig.colorSpace)||(this.decoderConfig={...this.decoderConfig,colorSpace:{primaries:this.decoderConfig.colorSpace?.primaries??"bt709",matrix:this.decoderConfig.colorSpace?.matrix??"bt709",transfer:this.decoderConfig.colorSpace?.transfer??"bt709",fullRange:this.decoderConfig.colorSpace?.fullRange??!1}})}const u=new Error("Decoding error").stack;this.decoder=new VideoDecoder({output:l=>{try{c(l)}catch(f){this.onError(f)}},error:l=>{l.stack=u,this.onError(l)}}),this.decoder.configure(this.decoderConfig)}}getDecodeQueueSize(){return this.customDecoder?this.customDecoderQueueSize:(R(this.decoder),Math.max(this.decoder.decodeQueueSize,this.alphaDecoder?.decodeQueueSize??0))}decode(e){if(this.codec==="hevc"&&this.currentPacketIndex>0&&!this.raslSkipped){if(this.hasHevcRaslPicture(e.data))return;this.raslSkipped=!0}if(this.customDecoder)this.customDecoderQueueSize++,this.customDecoderCallSerializer.call(()=>this.customDecoder.decode(e)).catch(n=>this.onError(n)).finally(()=>this.customDecoderQueueSize--);else{if(R(this.decoder),no()||al(this.inputTimestamps,e.timestamp,n=>n),so()&&this.currentPacketIndex===0){if(this.codec==="avc"){const n=[];let r=!1;for(const s of yl(e.data,this.decoderConfig)){const a=Ls(e.data[s.offset]);if(r||=a>=1&&a<=5,a===ct.AUD){if(r)break;n.length=0}a>=20&&a<=31||n.push(e.data.subarray(s.offset,s.offset+s.length))}const i=Kh(n,this.decoderConfig);e=new Qe(i,e.type,e.timestamp,e.duration)}else if(this.codec==="hevc"){const n=am(e.data,this.decoderConfig);n&&(e=new Qe(n,e.type,e.timestamp,e.duration))}}this.decoder.decode(e.toEncodedVideoChunk()),this.decodeAlphaData(e)}this.currentPacketIndex++}decodeAlphaData(e){if(!e.sideData.alpha){this.pushNullAlphaFrame();return}if(this.merger||(this.merger=new pg),!this.alphaDecoder){const r=s=>{if(this.colorQueue.length>0){const a=this.colorQueue.shift();R(a!==void 0),this.mergeAlpha(a,s)}else this.alphaQueue.push(s);for(this.decodedAlphaChunkCount++;this.nullAlphaFrameQueue.length>0&&this.nullAlphaFrameQueue[0]===this.decodedAlphaChunkCount;)if(this.nullAlphaFrameQueue.shift(),this.colorQueue.length>0){const a=this.colorQueue.shift();R(a!==void 0),this.mergeAlpha(a,null)}else this.alphaQueue.push(null);this.alphaDecoderQueueSize--},i=new Error("Decoding error").stack;this.alphaDecoder=new VideoDecoder({output:s=>{try{r(s)}catch(a){this.onError(a)}},error:s=>{s.stack=i,this.onError(s)}}),this.alphaDecoder.configure(this.decoderConfig)}const n=vo(this.codec,this.decoderConfig,e.sideData.alpha);if(this.alphaHadKeyframe||(this.alphaHadKeyframe=n==="key"),this.alphaHadKeyframe){if(this.codec==="hevc"&&this.currentAlphaPacketIndex>0&&!this.alphaRaslSkipped){if(this.hasHevcRaslPicture(e.sideData.alpha)){this.pushNullAlphaFrame();return}this.alphaRaslSkipped=!0}this.currentAlphaPacketIndex++,this.alphaDecoder.decode(e.alphaToEncodedVideoChunk(n??e.type)),this.alphaDecoderQueueSize++}else this.pushNullAlphaFrame()}pushNullAlphaFrame(){this.alphaDecoderQueueSize===0?this.alphaQueue.push(null):this.nullAlphaFrameQueue.push(this.decodedAlphaChunkCount+this.alphaDecoderQueueSize)}hasHevcRaslPicture(e){for(const n of zs(e,this.decoderConfig)){const r=Kr(e[n.offset]);if(r===Ge.RASL_N||r===Ge.RASL_R)return!0}return!1}sampleHandler(e){if(no()){if(this.sampleQueue.length>0&&e.timestamp>=Mt(this.sampleQueue).timestamp){for(const n of this.sampleQueue)this.finalizeAndEmitSample(n);this.sampleQueue.length=0}al(this.sampleQueue,e,n=>n.timestamp)}else{const n=this.inputTimestamps.shift();R(n!==void 0),e.setTimestamp(n),this.finalizeAndEmitSample(e)}}finalizeAndEmitSample(e){e.setTimestamp(Math.round(e.timestamp*this.timeResolution)/this.timeResolution),e.setDuration(Math.round(e.duration*this.timeResolution)/this.timeResolution),e.setRotation(this.rotation),this.onSample(e)}async mergeAlpha(e,n){const r=mt();this.mergeAlphaPromises.push(r.promise);const i={sample:null};this.finalSamples.push(i);try{if(!n)i.sample=new en(e);else{R(this.merger);const s=await this.merger.merge(e,n);i.sample=new en(s)}for(;this.finalSamples.length>0&&this.finalSamples[0].sample!==null;){const s=this.finalSamples.shift();this.sampleHandler(s.sample)}}catch(s){Qa(this.finalSamples,i),this.onError(s)}finally{Qa(this.mergeAlphaPromises,r.promise),r.resolve()}}async flush(){if(this.customDecoder?await this.customDecoderCallSerializer.call(()=>this.customDecoder.flush()):(R(this.decoder),await Promise.all([this.decoder.flush(),this.alphaDecoder?.flush()]),await Promise.all(this.mergeAlphaPromises),this.colorQueue.forEach(e=>e.close()),this.colorQueue.length=0,this.alphaQueue.forEach(e=>e?.close()),this.alphaQueue.length=0,this.alphaHadKeyframe=!1,this.decodedAlphaChunkCount=0,this.alphaDecoderQueueSize=0,this.nullAlphaFrameQueue.length=0,this.currentAlphaPacketIndex=0,this.alphaRaslSkipped=!1),no()){for(const e of this.sampleQueue)this.finalizeAndEmitSample(e);this.sampleQueue.length=0}this.currentPacketIndex=0,this.raslSkipped=!1}close(){this.customDecoder?this.customDecoderCallSerializer.call(()=>this.customDecoder.close()):(R(this.decoder),this.decoder.state!=="closed"&&this.decoder.close(),this.alphaDecoder&&this.alphaDecoder.state!=="closed"&&this.alphaDecoder.close(),this.colorQueue.forEach(e=>e.close()),this.colorQueue.length=0,this.alphaQueue.forEach(e=>e?.close()),this.alphaQueue.length=0,this.merger?.close());for(const e of this.sampleQueue)e.close();this.sampleQueue.length=0}}let Zo=null;class pg{constructor(){this.workers=[],this.nextWorkerIndex=0,this.pendingRequests=new Map,this.nextRequestId=0}merge(e,n){if(this.workers.length===0){if(!Zo){const o=new Blob([`(${gg.toString()})()`],{type:"application/javascript"});Zo=URL.createObjectURL(o)}const a=Mi(navigator.hardwareConcurrency,1,4);for(let o=0;o<a;o++){const c=new Worker(Zo);c.addEventListener("message",u=>{const l=u.data,f=this.pendingRequests.get(l.id);f&&(this.pendingRequests.delete(l.id),"error"in l?f.reject(new Error(l.error)):f.resolve(l.frame))}),c.addEventListener("error",u=>{const l=new Error(u.message||"Color/alpha merge worker error.");for(const f of this.pendingRequests.values())f.reject(l);this.pendingRequests.clear()}),this.workers.push(c)}}const r=this.nextRequestId++,i=mt();this.pendingRequests.set(r,i);const s=this.workers[this.nextWorkerIndex];return this.nextWorkerIndex=(this.nextWorkerIndex+1)%this.workers.length,s.postMessage({id:r,color:e,alpha:n},{transfer:[e,n]}),i.promise}close(){for(const n of this.workers)n.terminate();this.workers.length=0;const e=new Error("Color/alpha merger closed.");for(const n of this.pendingRequests.values())n.reject(e);this.pendingRequests.clear()}}const gg=()=>{let t=null,e=null,n=Promise.resolve();self.addEventListener("message",c=>{const{id:u,color:l,alpha:f}=c.data;n=n.then(async()=>{try{const d=await r(l,f);self.postMessage({id:u,frame:d},{transfer:[d]})}catch(d){self.postMessage({id:u,error:d.message})}finally{l.close(),f.close()}})});const r=async(c,u)=>{const l=c.format,f=u.format;if(!l||!f)throw new Error("CPU color/alpha merging requires a known VideoFrame format.");const d=l.includes("P10"),h=l.includes("P12"),p=f.includes("P10"),m=f.includes("P12");if(p!==d||m!==h)throw new Error(`CPU color/alpha merging requires the alpha frame to have the same bit depth as the color frame (color: '${l}', alpha: '${f}').`);if(l==="RGBX"||l==="RGBA"||l==="BGRX"||l==="BGRA")return await i(c,u,l);if(l==="I420"||l==="I420P10"||l==="I420P12"||l==="I422"||l==="I422P10"||l==="I422P12"||l==="I444"||l==="I444P10"||l==="I444P12")return await s(c,u,l);if(l==="NV12")return await a(c,u);throw new Error(`CPU color/alpha merging does not support format '${l}'.`)},i=async(c,u,l)=>{const f=c.visibleRect?.width??c.codedWidth,d=c.visibleRect?.height??c.codedHeight,h=f*d,p=new Uint8Array(h*4);await c.copyTo(p);const m=await o(u,f,d,1);for(let y=0,b=3;y<h;y++,b+=4)p[b]=m[y];const w={format:l==="RGBX"||l==="RGBA"?"RGBA":"BGRA",codedWidth:f,codedHeight:d,timestamp:c.timestamp,duration:c.duration??void 0,transfer:[p.buffer]};return new VideoFrame(p,w)},s=async(c,u,l)=>{const f=c.visibleRect?.width??c.codedWidth,d=c.visibleRect?.height??c.codedHeight,h=l.includes("P10"),p=l.includes("P12"),m=h||p?2:1;let g,w;l.startsWith("I420")?(g=Math.ceil(f/2),w=Math.ceil(d/2)):l.startsWith("I422")?(g=Math.ceil(f/2),w=d):(g=f,w=d);const y=f*d,b=g*w,v=y*m,k=b*m,A=y*m,T=v+2*k+A,S=new Uint8Array(T);await c.copyTo(S);const P=await o(u,f,d,m),M=v+2*k;S.set(P,M);const N={format:l.slice(0,4)+"A"+l.slice(4),codedWidth:f,codedHeight:d,timestamp:c.timestamp,duration:c.duration??void 0,transfer:[S.buffer]};return new VideoFrame(S,N)},a=async(c,u)=>{const l=c.visibleRect?.width??c.codedWidth,f=c.visibleRect?.height??c.codedHeight,d=l*f,h=Math.ceil(l/2),p=Math.ceil(f/2),m=h*p,g=c.allocationSize();(!e||e.byteLength!==g)&&(e=new Uint8Array(g)),await c.copyTo(e);const w=new Uint8Array(d+2*m+d);w.set(e.subarray(0,d),0);const y=d,b=d+m,v=d;for(let T=0;T<m;T++)w[y+T]=e[v+T*2],w[b+T]=e[v+T*2+1];const k=await o(u,l,f,1);w.set(k,d+2*m);const A={format:"I420A",codedWidth:l,codedHeight:f,timestamp:c.timestamp,duration:c.duration??void 0,transfer:[w.buffer]};return new VideoFrame(w,A)},o=async(c,u,l,f)=>{const d=c.allocationSize();(!t||t.byteLength!==d)&&(t=new Uint8Array(d)),await c.copyTo(t);const h=c.format;if(h==="RGBA"||h==="BGRA"||h==="RGBX"||h==="BGRX"){const p=h==="RGBA"||h==="RGBX"?0:2,m=u*l;for(let g=0;g<m;g++)t[g]=t[g*4+p];return t.subarray(0,m)}else return t.subarray(0,u*l*f)}},yg=t=>{if(!t||typeof t!="object")throw new TypeError("decoderOptions must be an object.");if(t.hardwareAcceleration!==void 0&&!["no-preference","prefer-hardware","prefer-software"].includes(t.hardwareAcceleration))throw new TypeError("decoderOptions.hardwareAcceleration, when provided, must be 'no-preference', 'prefer-hardware' or 'prefer-software'.");if(t.optimizeForLatency!==void 0&&typeof t.optimizeForLatency!="boolean")throw new TypeError("decoderOptions.optimizeForLatency, when provided, must be a boolean.")};class bg extends hg{constructor(e,n={}){if(!(e instanceof ec))throw new TypeError("videoTrack must be an InputVideoTrack.");yg(n),super(),this._track=e,this._decoderOptions=n}async _createDecoder(e,n){if(!await this._track.canDecode())throw typeof VideoDecoder>"u"?new Error(Gh("VideoDecoder")):new Error("This video track cannot be decoded in this environment. Make sure to check decodability before using a track.");const r=await this._track.getCodec(),i=await this._track.getRotation();let s=await this._track.getDecoderConfig();const a=await this._track.getTimeResolution();return R(r&&s),s={...s,hardwareAcceleration:this._decoderOptions.hardwareAcceleration,optimizeForLatency:this._decoderOptions.optimizeForLatency},new mg(e,n,r,s,i,a)}_createPacketSink(){return new Ko(this._track)}async getSample(e,n={}){fi(e);for await(const r of this.mediaSamplesAtTimestamps([e],n))return r;throw new Error("Internal error: Iterator returned nothing.")}samples(e,n,r={}){return this.mediaSamplesInRange(e,n,r)}samplesAtTimestamps(e,n={}){return this.mediaSamplesAtTimestamps(e,n)}}class $i{constructor(e,n){this.input=e,this._backing=n}isVideoTrack(){return this instanceof ec}isAudioTrack(){return this instanceof af}get id(){return this._backing.getId()}get number(){return this._backing.getNumber()}async getInternalCodecId(){return this._backing.getInternalCodecId()}get internalCodecId(){return Ue(this._backing.getInternalCodecId(),"internalCodecId","getInternalCodecId")}async getLanguageCode(){return this._backing.getLanguageCode()}get languageCode(){return Ue(this._backing.getLanguageCode(),"languageCode","getLanguageCode")}async getName(){return this._backing.getName()}get name(){return Ue(this._backing.getName(),"name","getName")}async getTimeResolution(){return this._backing.getTimeResolution()}get timeResolution(){return Ue(this._backing.getTimeResolution(),"timeResolution","getTimeResolution")}async isRelativeToUnixEpoch(){return this._backing.isRelativeToUnixEpoch()}async getUnixTimeForTimestamp(e){return this._backing.getUnixTimeForTimestamp(e)}async hasUnixTimeMapping(){return await this._backing.getUnixTimeForTimestamp(await this.getFirstTimestamp())!==null}async getDisposition(){return this._backing.getDisposition()}get disposition(){return Ue(this._backing.getDisposition(),"disposition","getDisposition")}async getBitrate(){return this._backing.getBitrate()}async getAverageBitrate(){return this._backing.getAverageBitrate()}async getFirstTimestamp(){return(await this._backing.getFirstPacket({metadataOnly:!0}))?.timestamp??0}async computeDuration(e){const n=await this._backing.getPacket(1/0,{metadataOnly:!0,...e}),r=(n?.timestamp??0)+(n?.duration??0);return ll(r,await this.getTimeResolution())}async getDurationFromMetadata(e={}){return this._backing.getDurationFromMetadata(e)}async computePacketStats(e=1/0,n){const r=new Ko(this);let i=1/0,s=-1/0,a=0,o=0;for await(const c of r.packets(void 0,void 0,{metadataOnly:!0,...n})){if(a>=e&&c.timestamp>=s)break;i=Math.min(i,c.timestamp),s=Math.max(s,c.timestamp+c.duration),a++,o+=c.byteLength}return{packetCount:a,averagePacketRate:a?Number((a/(s-i)).toPrecision(16)):0,averageBitrate:a?Number((8*o/(s-i)).toPrecision(16)):0}}async isLive(){return await this._backing.getLiveRefreshInterval()!==null}async getLiveRefreshInterval(){return this._backing.getLiveRefreshInterval()}canBePairedWith(e){if(!(e instanceof $i))throw new TypeError("other must be an InputTrack.");return this.input!==e.input||this===e?!1:(this._backing.getPairingMask()&e._backing.getPairingMask())!==0n}async getPairableTracks(e){return this.input.getTracks(Ir({filter:n=>n.canBePairedWith(this)},e))}async getPairableVideoTracks(e){return this.input.getVideoTracks(Ir({filter:n=>n.canBePairedWith(this)},e))}async getPairableAudioTracks(e){return this.input.getAudioTracks(Ir({filter:n=>n.canBePairedWith(this)},e))}async getPrimaryPairableVideoTrack(e){return this.input.getPrimaryVideoTrack(Ir({filter:n=>n.canBePairedWith(this)},e))}async getPrimaryPairableAudioTrack(e){return this.input.getPrimaryAudioTrack(Ir({filter:n=>n.canBePairedWith(this)},e))}async hasPairableTrack(e){e&&=Jo(e);const n=await this.input.getTracks();for(const r of n)if(this.canBePairedWith(r)&&(!e||await e(r)))return!0;return!1}hasPairableVideoTrack(e){return e&&=Jo(e),this.hasPairableTrack(async n=>n.isVideoTrack()&&(!e||await e(n)))}hasPairableAudioTrack(e){return e&&=Jo(e),this.hasPairableTrack(async n=>n.isAudioTrack()&&(!e||await e(n)))}}const Ue=(t,e,n)=>{if(ie(t))throw new Error(`'${e}' is deprecated and not available synchronously for this track. Use the preferred '${n}()' instead.`);return t},Jo=t=>{if(t!==void 0&&typeof t!="function")throw new TypeError("predicate, when provided, must be a function.");return t?e=>{const n=i=>{if(typeof i!="boolean")throw new TypeError("predicate must return or resolve to a boolean value.");return i},r=t(e);return ie(r)?r.then(n):n(r)}:void 0};class ec extends $i{constructor(e,n){super(e,n),this._pixelAspectRatioCache=null,this._backing=n}get type(){return"video"}async getCodec(){return this._backing.getCodec()}get codec(){return Ue(this._backing.getCodec(),"codec","getCodec")}async hasOnlyKeyPackets(){return await this._backing.getHasOnlyKeyPackets?.()??await this._backing.getCodec()==="prores"}async getCodedWidth(){return this._backing.getCodedWidth()}get codedWidth(){return Ue(this._backing.getCodedWidth(),"codedWidth","getCodedWidth")}async getCodedHeight(){return this._backing.getCodedHeight()}get codedHeight(){return Ue(this._backing.getCodedHeight(),"codedHeight","getCodedHeight")}async getRotation(){return this._backing.getRotation()}get rotation(){return Ue(this._backing.getRotation(),"rotation","getRotation")}async getSquarePixelWidth(){return this._backing.getSquarePixelWidth()}get squarePixelWidth(){return Ue(this._backing.getSquarePixelWidth(),"squarePixelWidth","getSquarePixelWidth")}async getSquarePixelHeight(){return this._backing.getSquarePixelHeight()}get squarePixelHeight(){return Ue(this._backing.getSquarePixelHeight(),"squarePixelHeight","getSquarePixelHeight")}async getPixelAspectRatio(){return this._pixelAspectRatioCache??=Bs({num:await this.getSquarePixelWidth()*await this.getCodedHeight(),den:await this.getSquarePixelHeight()*await this.getCodedWidth()})}get pixelAspectRatio(){return this._pixelAspectRatioCache??=Bs({num:Ue(this._backing.getSquarePixelWidth(),"pixelAspectRatio","getPixelAspectRatio")*Ue(this._backing.getCodedHeight(),"pixelAspectRatio","getPixelAspectRatio"),den:Ue(this._backing.getSquarePixelHeight(),"pixelAspectRatio","getPixelAspectRatio")*Ue(this._backing.getCodedWidth(),"pixelAspectRatio","getPixelAspectRatio")})}async getDisplayWidth(){const e=await this._backing.getMetadataDisplayWidth?.();return e??(await this.getRotation()%180===0?this.getSquarePixelWidth():this.getSquarePixelHeight())}get displayWidth(){const e=this._backing.getMetadataDisplayWidth?.();if(e!==void 0){const i=Ue(e,"displayWidth","getDisplayWidth");if(i!==null)return i}const r=Ue(this._backing.getRotation(),"displayWidth","getDisplayWidth")%180===0?this._backing.getSquarePixelWidth():this._backing.getSquarePixelHeight();return Ue(r,"displayWidth","getDisplayWidth")}async getDisplayHeight(){const e=await this._backing.getMetadataDisplayHeight?.();return e??(await this.getRotation()%180===0?this.getSquarePixelHeight():this.getSquarePixelWidth())}get displayHeight(){const e=this._backing.getMetadataDisplayHeight?.();if(e!==void 0){const i=Ue(e,"displayHeight","getDisplayHeight");if(i!==null)return i}const r=Ue(this._backing.getRotation(),"displayHeight","getDisplayHeight")%180===0?this._backing.getSquarePixelHeight():this._backing.getSquarePixelWidth();return Ue(r,"displayHeight","getDisplayHeight")}async getColorSpace(){return this._backing.getColorSpace()}async hasHighDynamicRange(){const e=await this._backing.getColorSpace();return e.primaries==="bt2020"||e.primaries==="smpte432"||e.transfer==="pq"||e.transfer==="hlg"||e.matrix==="bt2020-ncl"}async canBeTransparent(){return this._backing.canBeTransparent()}async getDecoderConfig(){return this._backing.getDecoderConfig()}async getCodecParameterString(){const e=await this._backing.getMetadataCodecParameterString?.();return e??(await this._backing.getDecoderConfig())?.codec??null}async canDecode(){try{const e=await this._backing.getDecoderConfig();if(!e)return!1;const n=await this._backing.getCodec();return R(n!==null),rf.some(i=>i.supports(n,e))?!0:typeof VideoDecoder>"u"?!1:(await VideoDecoder.isConfigSupported(e)).supported===!0}catch(e){return pe._error("Error during decodability check:",e),!1}}async determinePacketType(e){if(!(e instanceof Qe))throw new TypeError("packet must be an EncodedPacket.");if(e.isMetadataOnly)throw new TypeError("packet must not be metadata-only to determine its type.");const n=await this.getCodec();if(n===null)return null;const r=await this.getDecoderConfig();return R(r),vo(n,r,e.data)}async computeFrameRateMetrics(e={}){if(!e||typeof e!="object")throw new TypeError("options must be an object.");if(e.targetPacketCount!==void 0&&(!Ms(e.targetPacketCount)||e.targetPacketCount<0))throw new TypeError("options.targetPacketCount must be a non-negative number.");const n=await this.getTimeResolution(),r=e.targetPacketCount??256,i=new Ko(this),s=[];let a=-1/0,o=0;for await(const M of i.packets(void 0,void 0,{metadataOnly:!0})){if(s.length>=r&&M.timestamp>=a)break;s.push(M.timestamp),a=Math.max(a,M.timestamp),o++}const c=new Float64Array(s.length);for(let M=0;M<s.length;M++)c[M]=Math.round(s[M]*n);c.sort();let u=1;for(let M=1;M<c.length;M++)c[M]!==c[u-1]&&(c[u++]=c[M]);if(u<2)return{underlyingFrameRate:null,bestGuessFrameRate:n,minFrameRate:n,maxFrameRate:n,averageFrameRate:n,medianFrameRate:n,frameRateIsConstant:!0,probedPacketCount:o};const l=c.subarray(0,u),f=wg(l,n),d=f??n,h=f!==null?n/f:null,p=new Map;let m=1/0,g=-1/0,w=0;for(let M=1;M<u;M++){const B=l[M]-l[M-1],N=h!==null?Math.max(1,Math.round(B/h)):B;p.set(N,(p.get(N)??0)+1),m=Math.min(m,N),g=Math.max(g,N),w+=N}const y=u-1,b=[...p.keys()].sort((M,B)=>M-B),v=y-1>>1,k=y>>1;let A=0,T=0,S=0;for(const M of b)if(S+=p.get(M),A===0&&S>v&&(A=M),S>k){T=M;break}const P=(d/A+d/T)/2;return{underlyingFrameRate:f,bestGuessFrameRate:f!==null?f:vg(P),minFrameRate:d/g,maxFrameRate:d/m,averageFrameRate:d*y/w,medianFrameRate:P,frameRateIsConstant:f!==null&&m===1&&g===1,probedPacketCount:o}}}class af extends $i{constructor(e,n){super(e,n),this._backing=n}get type(){return"audio"}async getCodec(){return this._backing.getCodec()}get codec(){return Ue(this._backing.getCodec(),"codec","getCodec")}async hasOnlyKeyPackets(){return await this._backing.getHasOnlyKeyPackets?.()??!0}async getNumberOfChannels(){return this._backing.getNumberOfChannels()}get numberOfChannels(){return Ue(this._backing.getNumberOfChannels(),"numberOfChannels","getNumberOfChannels")}async getSampleRate(){return this._backing.getSampleRate()}get sampleRate(){return Ue(this._backing.getSampleRate(),"sampleRate","getSampleRate")}async getDecoderConfig(){return this._backing.getDecoderConfig()}async getCodecParameterString(){const e=await this._backing.getMetadataCodecParameterString?.();return e??(await this._backing.getDecoderConfig())?.codec??null}async canDecode(){try{const e=await this._backing.getDecoderConfig();if(!e)return!1;const n=await this._backing.getCodec();return R(n!==null),fg.some(r=>r.supports(n,e))||e.codec.startsWith("pcm-")?!0:typeof AudioDecoder>"u"?!1:(await AudioDecoder.isConfigSupported(e)).supported===!0}catch(e){return pe._error("Error during decodability check:",e),!1}}async determinePacketType(e){if(!(e instanceof Qe))throw new TypeError("packet must be an EncodedPacket.");return await this.getCodec()===null?null:"key"}}const of=t=>-(t??-1/0),Qi=t=>-t,Yi=t=>{if(typeof t!="object"||!t)throw new TypeError("query must be an object.");if(t.filter!==void 0&&typeof t.filter!="function")throw new TypeError("query.filter, when provided, must be a function.");if(t.sortBy!==void 0&&typeof t.sortBy!="function")throw new TypeError("query.sortBy, when provided, must be a function.");return{filter:t.filter?e=>{const n=i=>{if(typeof i!="boolean")throw new TypeError("query.filter must return or resolve to a boolean.");return i},r=t.filter(e);return ie(r)?r.then(n):n(r)}:void 0,sortBy:t.sortBy?e=>{const n=i=>{if(typeof i!="number"&&(!Array.isArray(i)||!i.every(s=>typeof s=="number")))throw new TypeError("query.sortBy must return or resolve to a number or an array of numbers.");return i},r=t.sortBy(e);return ie(r)?r.then(n):n(r)}:void 0}},Ir=(t,e)=>({filter:t?.filter||e?.filter?n=>{const r=t?.filter?.(n)??!0,i=s=>s===!1?!1:e?.filter?.(n)??!0;return ie(r)?r.then(i):i(r)}:void 0,sortBy:t?.sortBy||e?.sortBy?n=>{const r=t?.sortBy?.(n)??[],i=e?.sortBy?.(n)??[],s=(a,o)=>[...Array.isArray(a)?a:[a],...Array.isArray(o)?o:[o]];return ie(r)||ie(i)?Promise.all([r,i]).then(([a,o])=>s(a,o)):s(r,i)}:void 0}),tc=async(t,e)=>{let n=t;if(e?.filter){const a=t.map(c=>e.filter(c));if(a.some(c=>ie(c))){const c=await Promise.all(a);n=t.filter((u,l)=>c[l])}else n=t.filter((c,u)=>a[u])}if(!e?.sortBy)return n;const r=n.map(a=>e.sortBy(a)),s=r.some(a=>ie(a))?await Promise.all(r):r;return n.map((a,o)=>({track:a,sortValue:s[o]})).sort((a,o)=>{const c=Array.isArray(a.sortValue)?a.sortValue:[a.sortValue],u=Array.isArray(o.sortValue)?o.sortValue:[o.sortValue],l=Math.max(c.length,u.length);for(let f=0;f<l;f++){const d=c[f]??0,h=u[f]??0;if(d!==h)return d-h}return 0}).map(a=>a.track)},wg=(t,e)=>{const i=1.000000001,s=1e3,a=[12,15,20,24e3/1001,24,25,3e4/1001,30,48,50,6e4/1001,60,100,12e4/1001,120,144,240];if(t.length<2)return null;const o=new Float64Array(t.length-1);for(let T=1;T<t.length;T++){const S=t[T]-t[T-1];if(!(S>0))return null;o[T-1]=S}const c=o.slice();c.sort();let u=c[Math.floor(c.length*.05)];for(let T=0;T<6;T++){let S=0,P=0;for(const B of o){const N=Math.max(1,Math.round(B/u));Math.abs(B-N*u)>=i||(S+=B,P+=N)}if(P===0)return null;const M=S/P;if(Math.abs(M-u)<=1e-12*Math.max(1,u)){u=M;break}u=M}let l=0,f=0,d=0;for(const T of o){const S=Math.max(1,Math.round(T/u));Math.abs(T-S*u)>=i||(l++,f+=T,d+=S)}if(l/o.length<.98)return null;u=f/d;const h=1/Math.min(d,s),p=Math.max(Number.EPSILON,u-h),m=u+h,g=e/m,w=e/p,y=e/u;let b=null,v=1/0;for(const T of a){if(T<g||T>w)continue;const S=Math.abs(T/y-1);S<v&&(b=T,v=S)}if(b===null){const T=cf(p,m,1e6),S=cf(g,w,1e6);if(S&&(!T||S.den<T.den||S.den===T.den&&S.num<=T.num))b=S.num/S.den;else if(T)b=e*T.den/T.num;else return null}const k=e/b;let A=0;for(const T of o){const S=Math.max(1,Math.round(T/k));Math.abs(T-S*k)<i&&A++}return A/o.length<.98?null:b},cf=(t,e,n)=>{for(let r=1;r<=n;r++){const i=Math.floor(t*r)+1;if(i/r<e)return Bs({num:i,den:r})}return null},vg=t=>{const e=[23.976023976023978,29.970029970029973,59.940059940059946,119.88011988011989],n=[12,15,20,24,25,30,48,50,60,100,120,144,240],r=5e-4,i=.025;for(const o of e)if(Math.abs(o/t-1)<=r)return o;let s=t,a=1/0;for(const o of n){const c=Math.abs(o/t-1);c<=i&&c<a&&(s=o,a=c)}return s};oo();const kg=1,Ag=2;class Js extends uo{get disposed(){return this._disposed}constructor(e){if(super(),this._demuxerPromise=null,this._format=null,this._trackBackingsCache=null,this._backingToTrack=new Map,this._disposed=!1,this._nextSourceCacheAge=0,this._sourceRefs=[],this._sourceCache=[],this._sourceCachePromises=[],this._onFormatDetermined=null,!e||typeof e!="object")throw new TypeError("options must be an object.");if(!Array.isArray(e.formats)||e.formats.some(n=>!(n instanceof gn)))throw new TypeError("options.formats must be an array of InputFormat.");if(!(e.source instanceof zn||e.source instanceof qo))throw new TypeError("options.source must be a Source or SourceRef.");if(e.source instanceof zn&&e.source._disposed)throw new TypeError("options.source must not be a disposed Source.");if(e.initInput!==void 0&&!(e.initInput instanceof Js))throw new TypeError("options.initInput, when provided, must be an Input.");e.formatOptions!==void 0&&tg(e.formatOptions,"formatOptions"),this._formats=e.formats,this._initInput=e.initInput??null,this._formatOptions=e.formatOptions??{},e.source instanceof zn?this._rootRef=e.source.ref():this._rootRef=e.source,this._sourceRefs.push(this._rootRef)}get _rootSource(){return this._rootRef.source}async _getSourceUncached(e){R(this._rootSource instanceof ui);const n=await this._rootSource._resolveRequest(e);return this._emit("source",{source:n.source,request:e,isRoot:e.isRoot}),n}_getSourceCached(e,n=kg){const r=this._sourceCache.find(a=>a.cacheGroup===n&&Du(a.request,e));if(r)return r.age++,Promise.resolve(r.sourceRef.source.ref());const i=this._sourceCachePromises.find(a=>a.cacheGroup===n&&Du(a.request,e));if(i)return i.promise.then(a=>a.sourceRef.source.ref());const s=(async()=>{const a=await this._getSourceUncached(e);if(Ri(this._sourceCache,f=>f.cacheGroup===n&&f.sourceRef.source._refCount===1)>=4){const f=co(this._sourceCache,h=>h.cacheGroup===n&&h.sourceRef.source._refCount===1?h.age:1/0);R(f!==-1);const d=this._sourceCache[f];this._sourceCache.splice(f,1),d.sourceRef.free(),Qa(this._sourceRefs,d.sourceRef)}this._sourceRefs.push(a);const u=this._sourceCachePromises.findIndex(f=>f.request===e);return R(u!==-1),this._sourceCachePromises.splice(u,1),{request:e,sourceRef:a,age:this._nextSourceCacheAge++,cacheGroup:n}})();return this._sourceCachePromises.push({request:e,cacheGroup:n,promise:s}),s.then(a=>{const o=a.sourceRef.source.ref();return this._sourceCache.push(a),o})}_getDemuxer(){return this._demuxerPromise??=(async()=>{this._reader=new ea(this._rootSource),this._emit("source",{source:this._rootSource,request:null,isRoot:!0});for(const e of this._formats)if(await e._canReadInput(this))return this._format=e,this._onFormatDetermined?.(e),e._createDemuxer(this);throw new lf})()}get source(){return this._rootSource}async getFormat(){return await this._getDemuxer(),R(this._format),this._format}async canRead(){try{return await this._getDemuxer(),!0}catch(e){if(e instanceof lf)return!1;throw e}}async getFirstTimestamp(e){e??=await this.getTracks();const n=e.filter(s=>s!==null);if(n.length===0)return 0;const r=await Promise.all(n.map(s=>s._backing.getFirstPacket({metadataOnly:!0}))),i=Math.min(...r.map(s=>s?.timestamp??1/0));return i===1/0?0:i}async computeDuration(e,n){e??=await this.getTracks();const r=e.filter(s=>s!==null);if(r.length===0)return 0;const i=await Promise.all(r.map(s=>s.computeDuration(n)));return Math.max(...i)}async getDurationFromMetadata(e,n){e??=await this.getTracks();const r=e.filter(a=>a!==null),s=(await Promise.all(r.map(a=>a.getDurationFromMetadata(n)))).filter(a=>a!==null);return s.length===0?null:Math.max(...s)}async getTracks(e){e&&=Yi(e);const r=(await this._getTrackBackings()).map(i=>this._wrapBackingAsTrack(i));return tc(r,e)}async getVideoTracks(e){e&&=Yi(e);const r=(await this.getTracks()).filter(i=>i.isVideoTrack());return tc(r,e)}async getAudioTracks(e){e&&=Yi(e);const r=(await this.getTracks()).filter(i=>i.isAudioTrack());return tc(r,e)}async getPrimaryVideoTrack(e){e&&=Yi(e);const n=Ir(e,{sortBy:async i=>[Qi((await i.getDisposition()).default),Qi(await i.hasPairableAudioTrack()),Qi(!await i.hasOnlyKeyPackets()),of(await i.getBitrate())]});return(await this.getVideoTracks(n))[0]??null}async getPrimaryAudioTrack(e){e&&=Yi(e);const n=await this.getPrimaryVideoTrack(),r=Ir(e,{sortBy:async s=>[Qi(!n||s.canBePairedWith(n)),Qi((await s.getDisposition()).default),of(await s.getBitrate())]});return(await this.getAudioTracks(r))[0]??null}async _getTrackBackings(){const e=await this._getDemuxer();return this._trackBackingsCache??=await e.getTrackBackings()}_wrapBackingAsTrack(e){const n=this._backingToTrack.get(e);if(n)return n;const i=e.getType()==="video"?new ec(this,e):new af(this,e);return this._backingToTrack.set(e,i),i}async getMimeType(){return(await this._getDemuxer()).getMimeType()}async getMetadataTags(){return(await this._getDemuxer()).getMetadataTags()}dispose(){if(!this._disposed){this._disposed=!0;for(const e of this._sourceRefs)e.free();this._sourceRefs.length=0,this._demuxerPromise&&this._demuxerPromise.then(e=>e.dispose()).catch(()=>{})}}[Symbol.dispose](){this.dispose()}}class lf extends Error{constructor(e="Input has an unsupported or unrecognizable format."){super(e),this.name="UnsupportedInputFormatError"}}class gt extends Error{constructor(e="Input has been disposed."){super(e),this.name="InputDisposedError"}}class ea{constructor(e){this.source=e}get fileSize(){const e=this.source._getFileSize();if(e===void 0)throw new Error("Reading file size too early; read required first.");return e}get fileSizeNonStrict(){return this.source._getFileSize()??null}requestSlice(e,n){if(this.source._disposed)throw new gt;if(e<0||this.fileSizeNonStrict!==null&&e+n>this.fileSizeNonStrict)return null;if(n===0){const s=new Uint8Array(0);return new tn(s,Ie(s),0,e,e)}const r=e+n,i=this.source._read(e,r,Ru,Fu);return ie(i)?i.then(s=>s?new tn(s.bytes,s.view,s.offset,e,r):null):i?new tn(i.bytes,i.view,i.offset,e,r):null}requestSliceRange(e,n,r){if(this.source._disposed)throw new gt;if(e<0)return null;if(this.fileSizeNonStrict!==null)return this.requestSlice(e,Mi(this.fileSizeNonStrict-e,n,r));{const i=this.requestSlice(e,r),s=a=>a||(R(this.fileSizeNonStrict!==null),this.requestSlice(e,Mi(this.fileSizeNonStrict-e,n,r)));return ie(i)?i.then(s):s(i)}}requestEntireFile(){if(this.fileSizeNonStrict!==null)return this.requestSlice(0,this.fileSizeNonStrict);const e=1024;return(async()=>{const n=[];let r=0;for(;;){if(n.length===1&&this.fileSizeNonStrict!==null)return this.requestSlice(0,this.fileSizeNonStrict);let a=this.requestSliceRange(r,0,e);if(ie(a)&&(a=await a),!a||a.length===0)break;const o=me(a,a.length);n.push(o),r+=a.length}const i=new Uint8Array(r);let s=0;for(const a of n)i.set(a,s),s+=a.length;return new tn(i,Ie(i),0,0,r)})()}}class tn{constructor(e,n,r,i,s){this.bytes=e,this.view=n,this.offset=r,this.start=i,this.end=s,this.bufferPos=i-r}static tempFromBytes(e){return new tn(e,Ie(e),0,0,e.length)}get length(){return this.end-this.start}get filePos(){return this.offset+this.bufferPos}set filePos(e){this.bufferPos=e-this.offset}get remainingLength(){return Math.max(this.end-this.filePos,0)}skip(e){this.bufferPos+=e}slice(e,n=this.end-e){if(e<this.start||e+n>this.end)throw new RangeError("Slicing outside of original slice.");return new tn(this.bytes,this.view,this.offset,e,e+n)}}const Ft=(t,e)=>{if(t.filePos<t.start||t.filePos+e>t.end)throw new RangeError(`Tried reading [${t.filePos}, ${t.filePos+e}), but slice is [${t.start}, ${t.end}). This is likely an internal error, please report it alongside the file that caused it.`)},me=(t,e)=>{Ft(t,e);const n=t.bytes.subarray(t.bufferPos,t.bufferPos+e);return t.bufferPos+=e,n},de=t=>(Ft(t,1),t.view.getUint8(t.bufferPos++)),Ki=(t,e)=>{Ft(t,2);const n=t.view.getUint16(t.bufferPos,e);return t.bufferPos+=2,n},$e=t=>{Ft(t,2);const e=t.view.getUint16(t.bufferPos,!1);return t.bufferPos+=2,e},Hn=t=>{Ft(t,3);const e=cl(t.view,t.bufferPos);return t.bufferPos+=3,e},nc=t=>{Ft(t,2);const e=t.view.getInt16(t.bufferPos,!1);return t.bufferPos+=2,e},ir=(t,e)=>{Ft(t,4);const n=t.view.getUint32(t.bufferPos,e);return t.bufferPos+=4,n},ae=t=>{Ft(t,4);const e=t.view.getUint32(t.bufferPos,!1);return t.bufferPos+=4,e},di=t=>{Ft(t,4);const e=t.view.getUint32(t.bufferPos,!0);return t.bufferPos+=4,e},Mr=t=>{Ft(t,4);const e=t.view.getInt32(t.bufferPos,!1);return t.bufferPos+=4,e},xg=t=>{Ft(t,4);const e=t.view.getInt32(t.bufferPos,!0);return t.bufferPos+=4,e},uf=(t,e)=>{let n,r;return e?(n=ir(t,!0),r=ir(t,!0)):(r=ir(t,!1),n=ir(t,!1)),r*4294967296+n},Ht=t=>{const e=ae(t),n=ae(t);return e*4294967296+n},Tg=t=>{const e=Mr(t),n=ae(t);return e*4294967296+n},Sg=t=>{const e=di(t);return xg(t)*4294967296+e},Pg=t=>{Ft(t,4);const e=t.view.getFloat32(t.bufferPos,!1);return t.bufferPos+=4,e},ff=t=>{Ft(t,8);const e=t.view.getFloat64(t.bufferPos,!1);return t.bufferPos+=8,e},Ve=(t,e)=>{Ft(t,e);let n="";for(let r=0;r<e;r++)n+=String.fromCharCode(t.bytes[t.bufferPos++]);return n},df=(t,e,n)=>Bt.decode(me(t,e)).split(`
|
|
2
|
+
`).map(s=>s.trim()).filter(s=>s.length>0&&!n?.ignore?.(s));var Br;(function(t){t[t.Unsynchronisation=128]="Unsynchronisation",t[t.ExtendedHeader=64]="ExtendedHeader",t[t.ExperimentalIndicator=32]="ExperimentalIndicator",t[t.Footer=16]="Footer"})(Br||(Br={}));var hi;(function(t){t[t.ISO_8859_1=0]="ISO_8859_1",t[t.UTF_16_WITH_BOM=1]="UTF_16_WITH_BOM",t[t.UTF_16_BE_NO_BOM=2]="UTF_16_BE_NO_BOM",t[t.UTF_8=3]="UTF_8"})(hi||(hi={}));const ta=128,Gt=10,mi=["Blues","Classic rock","Country","Dance","Disco","Funk","Grunge","Hip-hop","Jazz","Metal","New age","Oldies","Other","Pop","Rhythm and blues","Rap","Reggae","Rock","Techno","Industrial","Alternative","Ska","Death metal","Pranks","Soundtrack","Euro-techno","Ambient","Trip-hop","Vocal","Jazz & funk","Fusion","Trance","Classical","Instrumental","Acid","House","Game","Sound clip","Gospel","Noise","Alternative rock","Bass","Soul","Punk","Space","Meditative","Instrumental pop","Instrumental rock","Ethnic","Gothic","Darkwave","Techno-industrial","Electronic","Pop-folk","Eurodance","Dream","Southern rock","Comedy","Cult","Gangsta","Top 40","Christian rap","Pop/funk","Jungle music","Native US","Cabaret","New wave","Psychedelic","Rave","Showtunes","Trailer","Lo-fi","Tribal","Acid punk","Acid jazz","Polka","Retro","Musical","Rock 'n' roll","Hard rock","Folk","Folk rock","National folk","Swing","Fast fusion","Bebop","Latin","Revival","Celtic","Bluegrass","Avantgarde","Gothic rock","Progressive rock","Psychedelic rock","Symphonic rock","Slow rock","Big band","Chorus","Easy listening","Acoustic","Humour","Speech","Chanson","Opera","Chamber music","Sonata","Symphony","Booty bass","Primus","Porn groove","Satire","Slow jam","Club","Tango","Samba","Folklore","Ballad","Power ballad","Rhythmic Soul","Freestyle","Duet","Punk rock","Drum solo","A cappella","Euro-house","Dance hall","Goa music","Drum & bass","Club-house","Hardcore techno","Terror","Indie","Britpop","Negerpunk","Polsk punk","Beat","Christian gangsta rap","Heavy metal","Black metal","Crossover","Contemporary Christian","Christian rock","Merengue","Salsa","Thrash metal","Anime","Jpop","Synthpop","Christmas","Art rock","Baroque","Bhangra","Big beat","Breakbeat","Chillout","Downtempo","Dub","EBM","Eclectic","Electro","Electroclash","Emo","Experimental","Garage","Global","IDM","Illbient","Industro-Goth","Jam Band","Krautrock","Leftfield","Lounge","Math rock","New romantic","Nu-breakz","Post-punk","Post-rock","Psytrance","Shoegaze","Space rock","Trop rock","World music","Neoclassical","Audiobook","Audio theatre","Neue Deutsche Welle","Podcast","Indie rock","G-Funk","Dubstep","Garage rock","Psybient"],_g=(t,e)=>{const n=t.filePos;e.raw??={},e.raw.TAG??=me(t,ta-3),t.filePos=n;const r=pi(t,30);r&&(e.title??=r);const i=pi(t,30);i&&(e.artist??=i);const s=pi(t,30);s&&(e.album??=s);const a=pi(t,4),o=Number.parseInt(a,10);Number.isInteger(o)&&o>0&&(e.date??=new Date(String(o)));const c=me(t,30);let u;if(c[28]===0&&c[29]!==0){const f=c[29];f>0&&(e.trackNumber??=f),t.skip(-30),u=pi(t,28),t.skip(2)}else t.skip(-30),u=pi(t,30);u&&(e.comment??=u);const l=de(t);l<mi.length&&(e.genre??=mi[l])},pi=(t,e)=>{const n=me(t,e),r=Yr(n.indexOf(0),n.length),i=n.subarray(0,r);let s="";for(let a=0;a<i.length;a++)s+=String.fromCharCode(i[a]);return s.trimEnd()},Vn=t=>{const e=t.filePos,n=Ve(t,3),r=de(t),i=de(t),s=de(t),a=ae(t);if(n!=="ID3"||r===255||i===255||(a&2155905152)!==0)return t.filePos=e,null;let o=Eo(a);return s&Br.Footer&&(o+=Gt),{majorVersion:r,revision:i,flags:s,size:o}},na=(t,e,n)=>{if(![2,3,4].includes(e.majorVersion)){pe._warn(`Unsupported ID3v2 major version: ${e.majorVersion}`);return}const r=e.flags&Br.Footer?e.size-Gt:e.size,i=me(t,r),s=new Eg(e,i);if(e.flags&Br.Unsynchronisation&&e.majorVersion===3&&s.ununsynchronizeAll(),e.flags&Br.ExtendedHeader){const a=s.readU32();e.majorVersion===3?s.pos+=a:s.pos+=a-4}for(;s.pos<=s.bytes.length-s.frameHeaderSize();){const a=s.readId3V2Frame();if(!a)break;const o=s.pos,c=s.pos+a.size;let u=!1,l=!1,f=!1;if(e.majorVersion===3?(u=!!(a.flags&64),l=!!(a.flags&128)):e.majorVersion===4&&(u=!!(a.flags&4),l=!!(a.flags&8),f=!!(a.flags&2)||!!(e.flags&Br.Unsynchronisation)),u){pe._warn(`Skipping encrypted ID3v2 frame ${a.id}`),s.pos=c;continue}if(l){pe._warn(`Skipping compressed ID3v2 frame ${a.id}`),s.pos=c;continue}if(f&&s.ununsynchronizeRegion(s.pos,c),n.raw??={},a.id==="TXXX"){const d=n.raw.TXXX??={},h=s.readId3V2TextEncoding(),p=s.readId3V2Text(h,c),m=s.readId3V2Text(h,c);d[p]??=m}else a.id[0]==="T"?n.raw[a.id]??=s.readId3V2EncodingAndText(c):n.raw[a.id]??=s.readBytes(a.size);switch(s.pos=o,a.id){case"TIT2":case"TT2":n.title??=s.readId3V2EncodingAndText(c);break;case"TIT3":case"TT3":n.description??=s.readId3V2EncodingAndText(c);break;case"TPE1":case"TP1":n.artist??=s.readId3V2EncodingAndText(c);break;case"TALB":case"TAL":n.album??=s.readId3V2EncodingAndText(c);break;case"TPE2":case"TP2":n.albumArtist??=s.readId3V2EncodingAndText(c);break;case"TRCK":case"TRK":{const h=s.readId3V2EncodingAndText(c).split("/"),p=Number.parseInt(h[0],10),m=h[1]&&Number.parseInt(h[1],10);Number.isInteger(p)&&p>0&&(n.trackNumber??=p),m&&Number.isInteger(m)&&m>0&&(n.tracksTotal??=m)}break;case"TPOS":case"TPA":{const h=s.readId3V2EncodingAndText(c).split("/"),p=Number.parseInt(h[0],10),m=h[1]&&Number.parseInt(h[1],10);Number.isInteger(p)&&p>0&&(n.discNumber??=p),m&&Number.isInteger(m)&&m>0&&(n.discsTotal??=m)}break;case"TCON":case"TCO":{const d=s.readId3V2EncodingAndText(c);let h=/^\((\d+)\)/.exec(d);if(h){const p=Number.parseInt(h[1]);if(mi[p]!==void 0){n.genre??=mi[p];break}}if(h=/^\d+$/.exec(d),h){const p=Number.parseInt(h[0]);if(mi[p]!==void 0){n.genre??=mi[p];break}}n.genre??=d}break;case"TDRC":case"TDAT":{const d=s.readId3V2EncodingAndText(c),h=new Date(d);Number.isNaN(h.getTime())||(n.date??=h)}break;case"TYER":case"TYE":{const d=s.readId3V2EncodingAndText(c),h=Number.parseInt(d,10);Number.isInteger(h)&&(n.date??=new Date(String(h)))}break;case"USLT":case"ULT":{const d=s.readU8();s.pos+=3,s.readId3V2Text(d,c),n.lyrics??=s.readId3V2Text(d,c)}break;case"COMM":case"COM":{const d=s.readU8();s.pos+=3,s.readId3V2Text(d,c),n.comment??=s.readId3V2Text(d,c)}break;case"APIC":case"PIC":{const d=s.readId3V2TextEncoding();let h;if(e.majorVersion===2){const w=s.readAscii(3);h=w==="PNG"?"image/png":w==="JPG"?"image/jpeg":"image/*"}else h=s.readId3V2Text(d,c);const p=s.readU8(),m=s.readId3V2Text(d,c).trimEnd(),g=c-s.pos;if(g>=0){const w=s.readBytes(g);n.images||(n.images=[]),n.images.push({data:w,mimeType:h,kind:p===3?"coverFront":p===4?"coverBack":"unknown",description:m})}}break;default:s.pos+=a.size;break}s.pos=c}};class Eg{constructor(e,n){this.header=e,this.bytes=n,this.pos=0,this.view=new DataView(n.buffer,n.byteOffset,n.byteLength)}frameHeaderSize(){return this.header.majorVersion===2?6:10}ununsynchronizeAll(){const e=[];for(let n=0;n<this.bytes.length;n++){const r=this.bytes[n];e.push(r),r===255&&n!==this.bytes.length-1&&this.bytes[n]===0&&n++}this.bytes=new Uint8Array(e),this.view=new DataView(this.bytes.buffer)}ununsynchronizeRegion(e,n){const r=[];for(let a=e;a<n;a++){const o=this.bytes[a];r.push(o),o===255&&a!==n-1&&this.bytes[a+1]===0&&a++}const i=this.bytes.subarray(0,e),s=this.bytes.subarray(n);this.bytes=new Uint8Array(i.length+r.length+s.length),this.bytes.set(i,0),this.bytes.set(r,i.length),this.bytes.set(s,i.length+r.length),this.view=new DataView(this.bytes.buffer)}readBytes(e){const n=this.bytes.subarray(this.pos,this.pos+e);return this.pos+=e,n}readU8(){const e=this.view.getUint8(this.pos);return this.pos+=1,e}readU16(){const e=this.view.getUint16(this.pos,!1);return this.pos+=2,e}readU24(){const e=this.view.getUint16(this.pos,!1),n=this.view.getUint8(this.pos+2);return this.pos+=3,e*256+n}readU32(){const e=this.view.getUint32(this.pos,!1);return this.pos+=4,e}readAscii(e){let n="";for(let r=0;r<e;r++)n+=String.fromCharCode(this.view.getUint8(this.pos+r));return this.pos+=e,n}readId3V2Frame(){if(this.header.majorVersion===2){const e=this.readAscii(3);if(e==="\0\0\0")return null;const n=this.readU24();return{id:e,size:n,flags:0}}else{const e=this.readAscii(4);if(e==="\0\0\0\0")return null;const n=this.readU32();let r=this.header.majorVersion===4?Eo(n):n;const i=this.readU16(),s=this.pos,a=o=>{const c=this.pos+o;if(c>this.bytes.length)return!1;if(c<=this.bytes.length-this.frameHeaderSize()){this.pos+=o;const u=this.readAscii(4);if(u!=="\0\0\0\0"&&!/[0-9A-Z]{4}/.test(u))return!1}return!0};if(!a(r)){const o=this.header.majorVersion===4?n:Eo(n);a(o)&&(r=o)}return this.pos=s,{id:e,size:r,flags:i}}}readId3V2TextEncoding(){const e=this.readU8();if(e>3)throw new Error(`Unsupported text encoding: ${e}`);return e}readId3V2Text(e,n){const r=this.pos,i=this.readBytes(n-this.pos);switch(e){case hi.ISO_8859_1:{let s="";for(let a=0;a<i.length;a++){const o=i[a];if(o===0){this.pos=r+a+1;break}s+=String.fromCharCode(o)}return s}case hi.UTF_16_WITH_BOM:if(i[0]===255&&i[1]===254){const s=new TextDecoder("utf-16le"),a=Yr(i.findIndex((o,c)=>o===0&&i[c+1]===0&&c%2===0),i.length);return this.pos=r+Math.min(a+2,i.length),s.decode(i.subarray(2,a))}else if(i[0]===254&&i[1]===255){const s=new TextDecoder("utf-16be"),a=Yr(i.findIndex((o,c)=>o===0&&i[c+1]===0&&c%2===0),i.length);return this.pos=r+Math.min(a+2,i.length),s.decode(i.subarray(2,a))}else{const s=Yr(i.findIndex(a=>a===0),i.length);return this.pos=r+Math.min(s+1,i.length),Bt.decode(i.subarray(0,s))}case hi.UTF_16_BE_NO_BOM:{const s=new TextDecoder("utf-16be"),a=Yr(i.findIndex((o,c)=>o===0&&i[c+1]===0&&c%2===0),i.length);return this.pos=r+Math.min(a+2,i.length),s.decode(i.subarray(0,a))}case hi.UTF_8:{const s=Yr(i.findIndex(a=>a===0),i.length);return this.pos=r+Math.min(s+1,i.length),Bt.decode(i.subarray(0,s))}}}readId3V2EncodingAndText(e){if(this.pos>=e)return"";const n=this.readId3V2TextEncoding();return this.readId3V2Text(n,e)}}function hf(){return typeof VideoDecoder=="function"&&typeof VideoFrame=="function"}const mf=6,pf=16;function Cg(t){const e=document.createElement("canvas");e.style.cssText=t.cssText,t.container.appendChild(e);const n=e.getContext("2d",{alpha:!1});if(!n)return e.remove(),queueMicrotask(()=>t.onFatal("2d \u4E0A\u4E0B\u6587\u521B\u5EFA\u5931\u8D25")),{canvas:e,pause(){},resume(){},destroy(){}};n.imageSmoothingEnabled=!0,n.imageSmoothingQuality="high";let r=!1,i=0,s=performance.now(),a=0,o=!1;const c=()=>{const B=Math.min(window.devicePixelRatio||1,t.renderDpr||1),N=Math.max(1,Math.round((t.container.clientWidth||window.innerWidth)*B)),U=Math.max(1,Math.round((t.container.clientHeight||window.innerHeight)*B));e.width!==N&&(e.width=N),e.height!==U&&(e.height=U)};c(),window.addEventListener("resize",c);const u=[];let l=null,f=null,d=null,h=0,p=0,m=mf,g=0,w=!1,y=-1,b=0,v=!1;const k=B=>{const N=e.width,U=e.height,q=B.displayWidth,H=B.displayHeight;if(N<=0||U<=0||q<=0||H<=0)return;const G=t.fit();if(G==="stretch"){B.draw(n,0,0,N,U);return}const Y=G==="cover"?Math.max(N/q,U/H):Math.min(N/q,U/H),J=Math.round(q*Y),ne=Math.round(H*Y),fe=Math.round((N-J)/2),Ne=Math.round((U-ne)/2);G==="contain"&&(n.fillStyle="#000",n.fillRect(0,0,N,U)),B.draw(n,fe,Ne,J,ne)},A=()=>h+(performance.now()-s)/1e3%p,T=()=>{g++,m<pf&&g%30===1&&(m=Math.min(pf,m+2),!w&&m>=mf+4&&(w=!0,t.onDiag?.(`\u5FAA\u73AF\u70B9\u89E3\u7801\u7A7A\u7A97\uFF0C\u524D\u77BB\u52A0\u6DF1\u81F3 ${m} \u5E27`)))},S=()=>{if(r||(i=requestAnimationFrame(S),o||t.paused()||p<=0))return;const B=A();for(;u.length>0;){const H=u[0],G=u[1];if(H.timestamp-B>p/2){H.close(),u.shift();continue}if(G&&G.timestamp<=B+1e-4){H.close(),u.shift();continue}break}const N=u[0];if(!N){T();return}if(N.timestamp>B+1e-4||N.timestamp===y)return;const U=t.fps(),q=performance.now();if(!(U>0&&q-b<1e3/U-.5)){y=N.timestamp,b=q;try{k(N)}catch{return}t.onFrame?.(),v||(v=!0,t.onFirstFrame?.())}},P=B=>new Promise(N=>setTimeout(N,B)),M=async()=>{try{for(;!r;){for(;!r&&(u.length>=m||o||t.paused());)await P(20);if(r)return;d||(d=f.samples(h));const B=await d.next();if(r){B.value?.close();return}if(B.done){d=null;continue}u.push(B.value)}}catch(B){r||t.onFatal(`\u89E3\u7801\u6CF5\u5F02\u5E38: ${B?.message??B}`)}};return(async()=>{try{l=new Js({source:new Xo(t.src),formats:eg});const B=await l.getPrimaryVideoTrack();if(!B)throw new Error("\u65E0\u89C6\u9891\u8F68");if(!await B.canDecode())throw new Error(`\u7F16\u7801\u4E0D\u53EF\u89E3\uFF08${B.codec}\uFF09`);const N=await B.computeDuration();if(h=await B.getFirstTimestamp(),p=Math.max(N-h,N>0?N:0),!isFinite(p)||p<=0)throw new Error("\u65F6\u957F\u5F02\u5E38");if(r){try{l.dispose()}catch{}return}f=new bg(B);const U=await B.getDisplayWidth(),q=await B.getDisplayHeight();t.onDiag?.(`${B.codec} ${U}x${q} ${p.toFixed(2)}s \u2192 WebCodecs \u9010\u5E27\u8C03\u5EA6`),M(),i=requestAnimationFrame(S)}catch(B){r||t.onFatal(B?.message??String(B))}})(),{canvas:e,pause(){o||(o=!0,a=performance.now())},resume(){o&&(o=!1,s+=performance.now()-a)},destroy(){if(!r){r=!0,i&&cancelAnimationFrame(i),i=0,window.removeEventListener("resize",c);for(const B of u.splice(0))try{B.close()}catch{}d&&d.return(void 0).catch(()=>{});try{l?.dispose()}catch{}e.remove()}}}}function Ig(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);if(t.length<16)throw new Error("\u6587\u4EF6\u592A\u5C0F\uFF0C\u4E0D\u662F scene.pkg");const n=e.getUint32(0,!0);if(n<4||n>16)throw new Error("\u9B54\u6570\u957F\u5EA6\u5F02\u5E38: "+n);const r=gf(t,4,n);if(!r.startsWith("PKGV"))throw new Error("\u4E0D\u662F scene.pkg\uFF0C\u9B54\u6570: "+r);const i=e.getUint32(4+n,!0);let s=4+n+4;const a=[];for(let c=0;c<i;c++){if(s+8>t.length)throw new Error("\u5165\u53E3\u8868\u8D8A\u754C @"+c);const u=e.getUint32(s,!0);if(s+=4,s+u+8>t.length)throw new Error("\u5165\u53E3 "+c+" \u8D8A\u754C");const l=Bg(t,s,u);s+=u;const f=e.getUint32(s,!0);s+=4;const d=e.getUint32(s,!0);s+=4,a.push({name:l,offset:f,size:d})}const o=s;return{magic:r,version:r.slice(4),count:i,entries:a,dataStart:o,fileSize:t.length,buf:t}}function rc(t,e){const n=t.entries.find(s=>s.name===e);if(n===void 0)return null;const r=t.dataStart+n.offset,i=r+n.size;if(r<0||i>t.fileSize)throw new Error("\u5165\u53E3 "+e+" \u8D8A\u754C");return t.buf.subarray(r,i)}function Mg(t){let e=0;for(const n of t.entries)e=Math.max(e,n.offset+n.size);return{dataEnd:t.dataStart+e,fileSize:t.fileSize,ok:t.dataStart+e<=t.fileSize}}function gf(t,e,n){let r="";for(let i=e;i<e+n;i++)r+=String.fromCharCode(t[i]);return r}function Bg(t,e,n){try{return new TextDecoder("utf-8",{fatal:!0}).decode(t.subarray(e,e+n))}catch{return gf(t,e,n)}}const Rg=Object.freeze(Object.defineProperty({__proto__:null,getEntry:rc,parsePkg:Ig,verifyLayout:Mg},Symbol.toStringTag,{value:"Module"})),ic={0:"ARGB8888",1:"RGB888",2:"RGB565",4:"DXT5",6:"DXT3",7:"DXT1",8:"RG88",9:"R8",10:"RG1616f",11:"R16f",12:"BC7",13:"RGBa1010102",14:"RGBA16161616f",15:"RGB161616f"},sr={UNKNOWN:-1,JPEG:2,PNG:13,GIF:25,WEBP:35,MP4:35};function Fg(t){const e=t.images[0];if(!e||e.length===0)throw new Error("\u65E0\u56FE\u50CF\u6570\u636E");const n=e[0];if(t.isVideo)return{width:n.width,height:n.height,video:n.data};if(t.freeImageFormat===sr.PNG)return{width:n.width,height:n.height,png:n.data};if(t.freeImageFormat!==sr.UNKNOWN)return{width:n.width,height:n.height,image:n.data,fif:t.freeImageFormat};const r=sc(t.format,n.data,n.width,n.height);return!t.frames?.list?.length&&(n.width!==t.width||n.height!==t.height)?{width:t.width,height:t.height,rgba:yf(r,n.width,n.height,t.width,t.height)}:{width:n.width,height:n.height,rgba:r}}function Dg(t){const e=t.images[0];if(!e||e.length===0)throw new Error("\u65E0\u56FE\u50CF\u6570\u636E");const n=[];for(const r of e){if(t.freeImageFormat!==sr.UNKNOWN){n.push({width:r.width,height:r.height,image:r.data,fif:t.freeImageFormat});continue}const i=sc(t.format,r.data,r.width,r.height);n.push({width:r.width,height:r.height,rgba:i})}return!t.frames?.list?.length&&n.length>0&&(n[0].width!==t.width||n[0].height!==t.height)&&n[0].rgba&&(n[0]={width:t.width,height:t.height,rgba:yf(n[0].rgba,n[0].width,n[0].height,t.width,t.height)}),n}function yf(t,e,n,r,i){const s=new Uint8Array(r*i*4);for(let a=0;a<i;a++)s.set(t.subarray(a*e*4,a*e*4+r*4),a*r*4);return s}function sc(t,e,n,r){switch(t){case 0:return Ng(e,n,r);case 1:return Lg(e,n,r);case 2:return Og(e,n,r);case 4:return Wg(e,n,r);case 6:return Vg(e,n,r);case 7:return Hg(e,n,r);case 8:return Ug(e,n,r);case 9:return zg(e,n,r);case 12:throw new Error("BC7 \u89E3\u7801\u6682\u672A\u5B9E\u73B0\uFF08format=12\uFF09");default:throw new Error("\u672A\u652F\u6301\u7684\u7EB9\u7406\u683C\u5F0F: "+(ic[t]||t))}}function Ng(t,e,n){return new Uint8Array(t.buffer,t.byteOffset,e*n*4).slice()}function Lg(t,e,n){const r=new Uint8Array(e*n*4);for(let i=0;i<e*n;i++)r[i*4]=t[i*3],r[i*4+1]=t[i*3+1],r[i*4+2]=t[i*3+2],r[i*4+3]=255;return r}function Og(t,e,n){const r=new Uint8Array(e*n*4);for(let i=0;i<e*n;i++){const s=t[i*2]|t[i*2+1]<<8,a=s>>11&31,o=s>>5&63,c=s&31;r[i*4]=a<<3|a>>2,r[i*4+1]=o<<2|o>>4,r[i*4+2]=c<<3|c>>2,r[i*4+3]=255}return r}function Ug(t,e,n){const r=new Uint8Array(e*n*4);for(let i=0;i<e*n;i++)r[i*4]=t[i*2+1],r[i*4+1]=t[i*2+1],r[i*4+2]=t[i*2+1],r[i*4+3]=t[i*2];return r}function zg(t,e,n){const r=new Uint8Array(e*n*4);for(let i=0;i<e*n;i++)r[i*4]=t[i],r[i*4+1]=t[i],r[i*4+2]=t[i],r[i*4+3]=255;return r}function Hg(t,e,n){return ac(t,e,n,!0,0)}function Vg(t,e,n){return ac(t,e,n,!1,3)}function Wg(t,e,n){return ac(t,e,n,!1,5)}function ac(t,e,n,r,i){const s=new Uint8Array(e*n*4),a=r?8:16,o=new Uint8Array(16);let c=0;for(let u=0;u<n;u+=4)for(let l=0;l<e;l+=4){if(c+a>t.length)return s;o.set(t.subarray(c,c+a)),c+=a;const f=jg(o,r),d=qg(o,r),h=i===3?Xg(o):i===5?Gg(o):null;for(let p=0;p<4;p++)for(let m=0;m<4;m++){const g=l+m,w=u+p;if(g>=e||w>=n)continue;const y=p*4+m,b=(w*e+g)*4;s[b]=f[d[y]*4],s[b+1]=f[d[y]*4+1],s[b+2]=f[d[y]*4+2],s[b+3]=h!==null?h[y]:f[d[y]*4+3]}}return s}function bf(t,e){const n=t[e]|t[e+1]<<8,r=n>>11&31,i=n>>5&63,s=n&31;return[n,r<<3|r>>2,i<<2|i>>4,s<<3|s>>2]}function jg(t,e){const n=e?0:8,r=bf(t,n),i=bf(t,n+2),s=new Uint8Array(16);return s[0]=r[1],s[1]=r[2],s[2]=r[3],s[3]=255,s[4]=i[1],s[5]=i[2],s[6]=i[3],s[7]=255,e&&r[0]<=i[0]?(s[8]=r[1]+i[1]>>1,s[9]=r[2]+i[2]>>1,s[10]=r[3]+i[3]>>1,s[11]=255,s[12]=0,s[13]=0,s[14]=0,s[15]=0):(s[8]=Math.floor((2*r[1]+i[1])/3),s[9]=Math.floor((2*r[2]+i[2])/3),s[10]=Math.floor((2*r[3]+i[3])/3),s[11]=255,s[12]=Math.floor((r[1]+2*i[1])/3),s[13]=Math.floor((r[2]+2*i[2])/3),s[14]=Math.floor((r[3]+2*i[3])/3),s[15]=255),s}function qg(t,e){const n=e?4:12,r=new Uint8Array(16);for(let i=0;i<4;i++){const s=t[n+i];r[i*4]=s&3,r[i*4+1]=s>>2&3,r[i*4+2]=s>>4&3,r[i*4+3]=s>>6&3}return r}function Xg(t){const e=new Uint8Array(16);for(let n=0;n<8;n++){const r=t[n],i=r&15,s=r&240;e[2*n]=i|i<<4,e[2*n+1]=s|s>>4}return e}function Gg(t){const e=t[0],n=t[1],r=new Uint8Array(8);if(r[0]=e,r[1]=n,e<=n){for(let o=1;o<5;o++)r[1+o]=Math.floor(((5-o)*e+o*n)/5);r[6]=0,r[7]=255}else for(let o=1;o<7;o++)r[o+1]=Math.floor(((7-o)*e+o*n)/7);const i=new Uint8Array(16);let s=0;for(let o=0;o<2;o++){let c=0;for(let u=0;u<3;u++)c|=t[2+o*3+u]<<8*u;for(let u=0;u<8;u++)i[s++]=c>>3*u&7}const a=new Uint8Array(16);for(let o=0;o<16;o++)a[o]=r[i[o]];return a}function wf(t,e){const n=new Uint8Array(e);let r=0,i=0;for(;r<t.length;){const s=t[r++];let a=s>>4;if(a===15){let l;do l=t[r++],a+=l;while(l===255)}for(let l=0;l<a;l++)n[i++]=t[r++];if(r>=t.length)break;const o=t[r]|t[r+1]<<8;r+=2;let c=4+(s&15);if((s&15)===15){let l;do l=t[r++],c+=l;while(l===255)}const u=i-o;for(let l=0;l<c;l++)n[i++]=n[u+l]}return n}function it(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0}function vf(t,e){return it(t,e)|0}const Zi=new DataView(new ArrayBuffer(4));function ar(t,e){return Zi.setUint8(0,t[e]),Zi.setUint8(1,t[e+1]),Zi.setUint8(2,t[e+2]),Zi.setUint8(3,t[e+3]),Zi.getFloat32(0,!0)}function $g(t){let e=0;const n=ra(t,e,9);if(e+=9,n!=="TEXV0005\0")throw new Error("\u4E0D\u662F .tex \u6587\u4EF6: "+n);const r=ra(t,e,9);if(e+=9,r!=="TEXI0001\0")throw new Error("\u672A\u77E5 TEXI \u5B50\u5BB9\u5668: "+r);const i=it(t,e);e+=4;const s=it(t,e);e+=4;const a=it(t,e);e+=4;const o=it(t,e);e+=4;const c=it(t,e);e+=4;const u=it(t,e);e+=4,e+=4;const l=ra(t,e,9);e+=9;const f=it(t,e);e+=4;let d=sr.UNKNOWN,h=0;if(l==="TEXB0004\0"){d=it(t,e)|0,e+=4;const v=it(t,e);e+=4,d===sr.UNKNOWN&&v===1&&(d=sr.MP4),h=v===1?4:3}else if(l==="TEXB0003\0")d=it(t,e)|0,e+=4,h=3;else if(l==="TEXB0002\0")h=2;else if(l==="TEXB0001\0")h=1;else throw new Error("\u672A\u77E5 TEXB \u5BB9\u5668: "+l);const p=(s&32)!==0||d===sr.MP4,m=[];for(let v=0;v<f;v++){const k=it(t,e);e+=4;const A=[];for(let T=0;T<k;T++){if(h===4){for(e+=8;e<t.length&&t[e]!==0;)e++;e+=1,e+=4}const S=it(t,e);e+=4;const P=it(t,e);e+=4;let M=0,B=0;h>=2&&(M=it(t,e),e+=4,B=vf(t,e),e+=4);const N=vf(t,e);if(e+=4,p){A.push({width:S,height:P,compression:0,data:t.subarray(e)}),e=t.length;continue}M===0&&(B=N);const U=t.subarray(e,e+N);e+=N;let q=U;M===1&&(q=wf(U,B)),A.push({width:S,height:P,compression:M,data:q})}m.push(A)}const g=m[0]&&m[0][0],w=g?g.width:a,y=g?g.height:o;let b=null;if(e+13<=t.length){const v=ra(t,e,9);if(v.indexOf("TEXS")===0){let k=e+9;const A=it(t,k);k+=4;let T=0,S=0;v==="TEXS0003\0"&&(T=it(t,k),k+=4,S=it(t,k),k+=4);const P=t.length-k,M=A>0&&P>0&&P%A===0?P/A:0;if(A>0&&A<=4096&&M>=32){const B=[];for(let U=0;U<A;U++){const q=k+U*M;if(q+32>t.length)break;const H=ar(t,q+8),G=ar(t,q+12),Y=ar(t,q+16),J=ar(t,q+20),ne=ar(t,q+24),fe=ar(t,q+28);B.push({imageId:ar(t,q)|0,duration:ar(t,q+4),x:H,y:G,width:Math.hypot(Y,J)||T,height:Math.hypot(ne,fe)||S,uDir:[Y,J],vDir:[ne,fe],rotated:Math.abs(J)>.5||Math.abs(ne)>.5})}B.length===A&&B.every(U=>{if(!(U.width>0&&U.height>0))return!1;const q=[U.x,U.x+U.uDir[0],U.x+U.vDir[0],U.x+U.uDir[0]+U.vDir[0]],H=[U.y,U.y+U.uDir[1],U.y+U.vDir[1],U.y+U.uDir[1]+U.vDir[1]];return Math.min(...q)>=-1&&Math.max(...q)<=w+1&&Math.min(...H)>=-1&&Math.max(...H)<=y+1})&&(b={magic:v,frameWidth:T,frameHeight:S,atlasWidth:w,atlasHeight:y,list:B})}}}return{format:i,formatName:ic[i]||String(i),flags:s,textureWidth:a,textureHeight:o,width:c,height:u,freeImageFormat:d,containerMagic:l,containerVersion:h,isVideo:p,images:m,frames:b}}function ra(t,e,n){let r="";for(let i=e;i<e+n;i++)r+=String.fromCharCode(t[i]);return r}const Qg=Object.freeze(Object.defineProperty({__proto__:null,FIF:sr,TEXTURE_FORMATS:ic,decodeMip0:Fg,decodeMips:Dg,decodePixels:sc,lz4Decompress:wf,parseTex:$g},Symbol.toStringTag,{value:"Module"}));function Yg(t,e,n){const r=Math.max(0,Number(n)||0),i=Math.max(1,Number(t)||1),s=Math.max(1,Number(e)||1);return r*2>=Math.min(i,s)?0:r}function Kg(t,e,n){const r=Math.max(1,e.boxW),i=Math.max(1,e.boxH),s=e.spacing||[0,0],a=Math.max(1,e.lineHeight||(e.pointsize||24)*1.25+s[1]),o=e.limitwidth&&e.maxwidth>0?e.maxwidth:1/0;function c(v){if(n(v)<=o)return[v];const k=[];let A="",T=-1;for(const S of v)if(A+=S,(S===" "||S===" ")&&(T=A.length),n(A)>o&&A.length>1)for(T>0?(k.push(A.slice(0,T-1)),A=A.slice(T)):(k.push(A.slice(0,-1)),A=S),T=-1;n(A)>o&&A.length>1;)k.push(A.slice(0,-1)),A=A.slice(-1);return A!==""&&k.push(A),k.length?k:[""]}let u=[];const l=String(t??"").split(`
|
|
3
|
+
`);for(const v of l)u.push(...c(v));let f=!1;if(e.limitrows&&e.maxrows>0&&u.length>e.maxrows&&(u=u.slice(0,e.maxrows),f=!0,e.limituseellipsis)){let v=u[e.maxrows-1];for(;v.length>0&&n(v+"\u2026")>o;)v=v.slice(0,-1);u[e.maxrows-1]=v+"\u2026"}const d=u.map(v=>n(v)),h=u.length*a,p=e.halign||"center",m=e.valign||"center",g=r/2,w=i/2,y=m==="top"?w:m==="bottom"?w-h:(i-h)/2;return{lines:u.map((v,k)=>{const A=d[k],T=p==="left"?g:p==="right"?g-A:(r-A)/2;return{text:v,width:A,x:T,y:y+k*a}}),lineHeight:a,totalH:h,truncated:f,boxW:r,boxH:i}}function kf(t,e,n){let r=1/0,i=-1/0,s=1/0,a=-1/0;for(const o of t.lines||[])r=Math.min(r,o.x),i=Math.max(i,o.x+o.width),s=Math.min(s,o.y),a=Math.max(a,o.y+(t.lineHeight||0));return!t.lines||!t.lines.length?[0,0,0,0]:[Math.max(0,-r),Math.max(0,-s),Math.max(0,i-e),Math.max(0,a-n)]}function Zg(t,e,n,r){const[i,s,a,o]=kf(t,e,n);return Math.max(r,i,s,a,o)}function Jg(t,e,n){return t<=4&&e<=4&&!!n}function e0(t,e,n){const r=e.boxW,i=e.boxH,s=n.color||[1,1,1],a=n.alpha!==void 0?n.alpha:1,o=n.brightness!==void 0?n.brightness:1;t.font=n.font;try{t.letterSpacing=(n.spacing&&n.spacing[0]?n.spacing[0]:0)+"px"}catch{}if(t.textBaseline="middle",n.opaquebackground){const u=n.backgroundcolor||[0,0,0],l=n.backgroundbrightness!==void 0?n.backgroundbrightness:1;t.fillStyle=`rgba(${Math.round(u[0]*255*l)},${Math.round(u[1]*255*l)},${Math.round(u[2]*255*l)},${a})`,t.fillRect(0,0,r,i)}const c=(u,l,f)=>{t.fillStyle=f;for(const d of e.lines)t.fillText(d.text,d.x+u,d.y+e.lineHeight/2+l)};if(n.castshadow){const u=Math.max(1,(n.pointsize||24)/10);c(u,u,`rgba(0,0,0,${a*.75})`)}c(0,0,`rgba(${Math.round(s[0]*255*o)},${Math.round(s[1]*255*o)},${Math.round(s[2]*255*o)},${a})`)}const Af=/^add[A-Z]/;function xf(){return{log:()=>{},warn:()=>{},error:()=>{},info:()=>{},debug:()=>{}}}function Tf(t){return new Proxy(t,{get(e,n,r){const i=Reflect.get(e,n,r);if(i==null&&typeof n=="string"&&n!=="then"){const s=()=>{};return e[n]=s,s}return i}})}function gi(t,e){return()=>{}}function Sf(t,e){t.isScreensaver=!!e.isScreensaver,typeof e.isRunningInEditor=="boolean"&&(t.isRunningInEditor=cc(e.isRunningInEditor)),t.setInterval||(t.setInterval=e.setInterval||gi),t.setTimeout||(t.setTimeout=e.setTimeout||gi),t.clearTimeout||(t.clearTimeout=e.clearTimeout||(()=>{})),t.clearInterval||(t.clearInterval=e.clearInterval||(()=>{})),typeof e.openUserShortcut=="function"&&(t.openUserShortcut=e.openUserShortcut);const n=e.mediaControl||null;t.media={skipNext:()=>{if(n&&n.skipNext)return n.skipNext()},skipPrevious:()=>{if(n&&n.skipPrevious)return n.skipPrevious()},play:()=>{if(n&&n.play)return n.play()},pause:()=>{if(n&&n.pause)return n.pause()},playPause:()=>{if(n&&n.playPause)return n.playPause()},get snapshot(){return n&&n.snapshot?n.snapshot:null}};const r=e.windowTitle;Object.defineProperty(t,"windowTitle",{configurable:!0,enumerable:!0,get(){return r&&r.title?String(r.title):""}}),Object.defineProperty(t,"windowApp",{configurable:!0,enumerable:!0,get(){return r&&r.app?String(r.app):""}})}class xe{constructor(e,n,r){if(e!==null&&typeof e=="object")this.x=e.x!==void 0?e.x:e.width||0,this.y=n!==void 0?n:e.y!==void 0?e.y:e.height||0,this.z=r!==void 0?r:e.z||0;else if(n===void 0&&r===void 0){const i=Number(e)||0;this.x=i,this.y=i,this.z=i}else this.x=Number(e)||0,this.y=Number(n)||0,this.z=Number(r)||0}add(e){const n=new xe(e);return new xe(this.x+n.x,this.y+n.y,this.z+n.z)}subtract(e){const n=new xe(e);return new xe(this.x-n.x,this.y-n.y,this.z-n.z)}multiply(e){return e&&typeof e=="object"?new xe(this.x*e.x,this.y*e.y,this.z*e.z):new xe(this.x*e,this.y*e,this.z*e)}divide(e){const n=(r,i)=>i===0?0:r/i;return e&&typeof e=="object"?new xe(n(this.x,e.x),n(this.y,e.y),n(this.z,e.z)):new xe(n(this.x,e),n(this.y,e),n(this.z,e))}copy(){return new xe(this.x,this.y,this.z)}mix(e,n){const r=new xe(e),i=Number(n),s=Number.isFinite(i)?i:0;return new xe(this.x+(r.x-this.x)*s,this.y+(r.y-this.y)*s,this.z+(r.z-this.z)*s)}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}lengthSqr(){return this.x*this.x+this.y*this.y+this.z*this.z}normalize(){const e=this.length();return e===0?new xe(0,0,0):new xe(this.x/e,this.y/e,this.z/e)}dot(e){const n=new xe(e);return this.x*n.x+this.y*n.y+this.z*n.z}toString(){return this.x+" "+this.y+" "+this.z}}const Pf=xe;function oc(t){if(t instanceof xe||!t||typeof t!="object"||Array.isArray(t)||!("x"in t)&&!("y"in t)&&!("z"in t)||Object.getPrototypeOf(t)===xe.prototype)return t;try{Object.setPrototypeOf(t,xe.prototype)}catch{}return t}function _f(t){return t&&t.cursorWorldPosition?t:{cursorWorldPosition:new xe(0,0,0),cursorScreenPosition:new xe(0,0,0),cursorPosition:new xe(0,0,0),cursorPositionLast:new xe(0,0,0),cursorLeftDown:!1}}function t0(t,e,n){return new xe(t||0,e||0,n||0)}function n0(){const t={cursorWorldPosition:new xe(0,0,0),cursorScreenPosition:new xe(0,0,0),cursorPosition:new xe(0,0,0),cursorPositionLast:new xe(0,0,0),cursorLeftDown:!1};return t.update=function(e){return e&&(t.cursorWorldPosition.x=e.wx,t.cursorWorldPosition.y=e.originY!=null?e.originY:e.wy,t.cursorWorldPosition.z=0,t.cursorScreenPosition.x=e.screenX,t.cursorScreenPosition.y=e.screenY,t.cursorScreenPosition.z=0,t.cursorPosition.x=e.u,t.cursorPosition.y=e.v,t.cursorPosition.z=0,t.cursorPositionLast.x=e.lastU,t.cursorPositionLast.y=e.lastV,t.cursorPositionLast.z=0,t.cursorLeftDown=!!e.leftDown),t},t}const Ef={mix:(t,e,n)=>t+(e-t)*n,lerp:(t,e,n)=>t+(e-t)*n,clamp:(t,e,n)=>Math.min(n,Math.max(e,t)),saturate:t=>Math.min(1,Math.max(0,t)),smoothstep:(t,e,n)=>{const r=Math.min(1,Math.max(0,(n-t)/(e-t||1)));return r*r*(3-2*r)},smoothStep:(t,e,n)=>{const r=Math.min(1,Math.max(0,(n-t)/(e-t||1)));return r*r*(3-2*r)},random:(t,e)=>t===void 0?Math.random():t+Math.random()*((e===void 0?1:e)-t),randomInt:(t,e)=>Math.floor((t||0)+Math.random()*((e===void 0?1:e)+1-(t||0))),degrees:t=>t*180/Math.PI,radians:t=>t*Math.PI/180},Cf={hsv2rgb:t=>{const e=t&&typeof t=="object"?t:{x:0,y:0,z:0},n=((Number(e.x)||0)%1+1)%1,r=Math.min(1,Math.max(0,Number(e.y)||0)),i=Math.min(1,Math.max(0,Number(e.z)||0)),s=Math.floor(n*6),a=n*6-s,o=i*(1-r),c=i*(1-a*r),u=i*(1-(1-a)*r),f=[[i,u,o],[c,i,o],[o,i,u],[o,c,i],[u,o,i],[i,o,c]][s%6];return new xe(f[0],f[1],f[2])},rgb2hsv:t=>{const e=t&&typeof t=="object"?t:{x:0,y:0,z:0},n=Number(e.x)||0,r=Number(e.y)||0,i=Number(e.z)||0,s=Math.max(n,r,i),a=Math.min(n,r,i),o=s-a;let c=0;return o>0&&(s===n?c=(r-i)/o/6:s===r?c=(2+(i-n)/o)/6:c=(4+(n-r)/o)/6,c<0&&(c+=1)),new xe(c,s===0?0:o/s,s)}},If={add:(t,e)=>({x:(t.x||0)+(e.x||0),y:(t.y||0)+(e.y||0),z:(t.z||0)+(e.z||0)}),subtract:(t,e)=>({x:(t.x||0)-(e.x||0),y:(t.y||0)-(e.y||0),z:(t.z||0)-(e.z||0)}),scale:(t,e)=>({x:(t.x||0)*e,y:(t.y||0)*e,z:(t.z||0)*e}),length:t=>Math.hypot(t.x||0,t.y||0,t.z||0),dot:(t,e)=>(t.x||0)*(e.x||0)+(t.y||0)*(e.y||0)+(t.z||0)*(e.z||0),normalize:t=>{const e=Math.hypot(t.x||0,t.y||0,t.z||0)||1;return{x:(t.x||0)/e,y:(t.y||0)/e,z:(t.z||0)/e}},mix:(t,e,n)=>({x:(t.x||0)+((e.x||0)-(t.x||0))*n,y:(t.y||0)+((e.y||0)-(t.y||0))*n,z:(t.z||0)+((e.z||0)-(t.z||0))*n})},Mf=Object.freeze({PLAYBACK_STOPPED:0,PLAYBACK_PLAYING:1,PLAYBACK_PAUSED:2}),ia=["mediaPropertiesChanged","mediaThumbnailChanged","mediaPlaybackChanged","mediaTimelineChanged","mediaStatusChanged","mediaLyricsChanged"],r0=["scriptProperties","engine","WEMath","WEColor","WEVector","createScriptProperties","shared","console","process","globalThis","self","window","document","require","module","exports","fetch","XMLHttpRequest","Worker","importScripts","location","navigator","alert","confirm","prompt","setTimeout","setInterval","clearTimeout","clearInterval","requestAnimationFrame","cancelAnimationFrame","performance","Function","Vec3","Vec2","input","thisLayer","thisScene","thisObject","localStorage","MediaPlaybackEvent"],i0=new RegExp(`(^[ \\t]*|;|\\})[ \\t]*(?:var|let|const)[ \\t]+(?=(?:${r0.join("|")})\\b)`,"gm"),s0={WEMath:!0,WEColor:!0,WEVector:!0};function Bf(t){return typeof t!="string"?t:t.replace(/([!=])==(\s*)(['"])(-?\d+)\3/g,"$1=$2$3$4$3")}function Rf(t){return Bf(t).replace(/\bimport\s*\*\s*as\s+(\w+)\s+from\s*['"]([^'"]+)['"]\s*;?/g,(e,n,r)=>{const i=String(r);return s0[i]?n===i?"":`var ${n} = ${i};`:`var ${n} = {};`}).replace(/(^[ \t]*|;|\})[ \t]*import\s+(?:[^;'"]+\s+from\s+)?['"][^'"]*['"];?[ \t]*/gm,"$1").replace(/(^[ \t]*|;|\})[ \t]*export[ \t]+(?=(?:async[ \t]+)?function\b|(?:var|let|const)\b)/gm,"$1").replace(i0,"$1")}function a0(t){if(typeof t=="boolean")return t;if(typeof t=="number"&&Number.isFinite(t))return t!==0}function Ff(t){const e=Math.floor(Number(t));return Number.isFinite(e)&&e>=1?Math.min(64,e):64}function sa(t){return t!==null&&typeof t=="object"&&"value"in t?t.value:t}function cc(t){const e=!!t;return Object.assign(()=>e,{valueOf(){return e},toString(){return e?"true":"false"}})}function Df(t,e,n,r){if(n!==null&&typeof n=="object"&&typeof n.user=="string"){const i=sa(n);let s,a=!1;Object.defineProperty(t,e,{enumerable:!0,configurable:!0,get(){if(a)return s;const o=r?r[n.user]:void 0;return o!==void 0?o:i},set(o){s=o,a=!0}})}else t[e]=sa(n)}function Nf(t){const e=t||{width:1920,height:1080};return e.x!==void 0&&e.y!==void 0?e:{x:e.width,y:e.height,width:e.width,height:e.height}}function o0(t,e,n={}){if(typeof t!="string"||t.length===0)return null;const r=Rf(t);if(r===t&&t.indexOf("update")<0)return null;const i={};if(e&&typeof e=="object")for(const[b,v]of Object.entries(e))Df(i,b,v,n.userProperties);const s=new Proxy(()=>s,{apply(){return s},get(b,v){if(v==="finish")return()=>i;if(typeof v=="string"&&Af.test(v))return k=>(k&&typeof k=="object"&&typeof k.name=="string"&&!(k.name in i)&&(i[k.name]=sa(k.value)),s)}}),a={text:n.text!==void 0&&n.text!==null?String(n.text):"",font:n.font||"",pointsize:n.pointsize||24,color:(n.color||[1,1,1]).slice(),angles:(n.angles||[0,0,0]).slice(),scale:(n.scale||[1,1,1]).slice(),visible:n.visible!==!1,origin:es(n.origin||[0,0,0])},o={registerAsset:b=>b,frametime:1/60,runtime:0,canvasSize:Nf(n.canvasSize),screenResolution:n.screenResolution||{x:1920,y:1080},timeOfDay:typeof n.timeOfDay=="number"?n.timeOfDay:0,userProperties:n.userProperties||{},AUDIO_RESOLUTION_16:16,AUDIO_RESOLUTION_32:32,AUDIO_RESOLUTION_64:64,setTimeout:n.setTimeout||gi,clearTimeout:n.clearTimeout||(()=>{}),setInterval:n.setInterval||gi,clearInterval:n.clearInterval||(()=>{}),openUserShortcut:n.openUserShortcut||(()=>{}),isRunningInEditor:cc(n.isRunningInEditor),isScreensaver:!!n.isScreensaver};Sf(o,n);const c=n.audioViews;o.registerAudioBuffers=b=>{const v=Ff(b);let k=c?c.get(v):void 0;return k||(k={left:new Float32Array(v),right:new Float32Array(v),average:new Float32Array(v)},c&&c.set(v,k)),k};const u={getLayer(b){const v=n.getLayerText?n.getLayerText(String(b)):void 0;return{text:v!=null?String(v):""}},createLayer(b){return{text:"",visible:!1,color:[0,0,0],alpha:1,pointsize:n.pointsize||24,font:n.font||"",origin:es(n.origin||[0,0,0]),angles:[0,0,0],scale:[1,1,1]}},sortLayer:()=>{},getLayerIndex:()=>0},l=n.shared||{},f={console:xf()},d=_f(n.inputView);let h;try{h=new Function("scriptProperties","engine","thisLayer","thisScene","WEMath","WEColor","WEVector","createScriptProperties","shared","console","process","globalThis","self","window","document","require","module","exports","fetch","XMLHttpRequest","Worker","importScripts","location","navigator","alert","confirm","prompt","setTimeout","setInterval","clearTimeout","clearInterval","requestAnimationFrame","cancelAnimationFrame","performance","Function","Vec3","Vec2","input","MediaPlaybackEvent",`"use strict";
|
|
4
|
+
`+r+`
|
|
5
|
+
;return {update: typeof update === "function" ? update : null,init: typeof init === "function" ? init : null,applyUserProperties: typeof applyUserProperties === "function" ? applyUserProperties : null,cursorClick: typeof cursorClick === "function" ? cursorClick : null,cursorEnter: typeof cursorEnter === "function" ? cursorEnter : null,cursorLeave: typeof cursorLeave === "function" ? cursorLeave : null,cursorDown: typeof cursorDown === "function" ? cursorDown : null,cursorUp: typeof cursorUp === "function" ? cursorUp : null,cursorMove: typeof cursorMove === "function" ? cursorMove : null,`+ia.map(v=>`${v}: typeof ${v} === "function" ? ${v} : null,`).join("")+'animationEvent: typeof animationEvent === "function" ? animationEvent : null,dummy_: 0};')(i,Tf(o),a,u,Ef,Cf,If,s,l,f.console,void 0,f,f,f,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,xe,Pf,d,Mf)}catch(b){return n.onError&&n.onError(b,"parse"),null}const p=!!(h&&ia.some(b=>h[b])),m=!!(h&&typeof h.applyUserProperties=="function"),g=!!(h&&typeof h.animationEvent=="function");if(!h||!h.update&&!p&&!m&&!g)return null;const w=(()=>{if(!h.update)return!1;const b=Function.prototype.toString.call(h.update),v=b.indexOf("{");if(v<0)return!1;const A=(/\(([^)]*)\)/.exec(b.slice(0,v))?.[1]||"").split(",").map(S=>S.trim().split(/[=\s]/)[0]).filter(Boolean);if(!A.length)return!1;let T=b.slice(v+1,b.lastIndexOf("}"));T=T.replace(/\/\*[\s\S]*?\*\//g," ").replace(/\/\/[^\n]*/g," ").replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*`/g,'""').replace(/([A-Za-z_$][\w$]*)\s*:/g,(S,P)=>A.includes(P)?" :":S);for(const S of A)T=T.replace(new RegExp(`\\b${S}\\s*(\\+\\+|--|=(?!=)|\\+=|-=|\\*=|\\/=)`,"g")," "),T=T.replace(new RegExp(`return\\s+${S}\\s*;?`,"g")," ");return A.some(S=>new RegExp(`\\b${S}\\b`).test(T))})();h.update&&w&&(a.text="");const y={engine:o,thisLayer:a,scriptProperties:i,hasUpdate:!!h.update,hasCursorHook:!!(h.cursorClick||h.cursorEnter||h.cursorLeave||h.cursorDown||h.cursorUp||h.cursorMove),hasMediaHook:p,hasApplyHook:m,hasAnimEventHook:g,errCount:0,disabled:!1,init(b){if(h.init)try{return h.init(b)}catch(v){y.errCount++,n.onError&&n.onError(v,"init")}},applyUserProperties(b){if(h.applyUserProperties)try{h.applyUserProperties(b||{})}catch(v){y.errCount++,n.onError&&n.onError(v,"applyUserProperties")}},callUpdateRaw(b){if(!(!h.update||y.disabled))try{return h.update(b)}catch(v){y.errCount++,n.onError&&n.onError(v,"update"),y.errCount>=3&&(y.disabled=!0);return}},callUpdate(b){if(!h.update||y.disabled)return null;const v=a.text;let k;try{k=h.update(v)}catch(A){return y.errCount++,n.onError&&n.onError(A,"update"),y.errCount>=3&&(y.disabled=!0),null}return typeof k=="string"?(a.text=k,k):typeof k=="boolean"?null:k!=null?(a.text=String(k),a.text):a.text!==v?a.text:null},callCursor(b,v){if(y.disabled)return;const k=h[b];if(typeof k=="function")try{return k(v)}catch(A){y.errCount++,n.onError&&n.onError(A,b),y.errCount>=3&&(y.disabled=!0);return}},callMedia(b,v){if(y.disabled)return;const k=h[b];if(typeof k=="function")try{return k(v)}catch(A){y.errCount++,n.onError&&n.onError(A,b),y.errCount>=3&&(y.disabled=!0);return}},callAnimationEvent(b,v){if(!y.disabled&&typeof h.animationEvent=="function")try{return h.animationEvent(b,v)}catch(k){y.errCount++,n.onError&&n.onError(k,"animationEvent"),y.errCount>=3&&(y.disabled=!0);return}},updateIsWriteback:w};return y}function Ji(){const t={play:()=>t,pause:()=>t,stop:()=>t,setFrame:()=>t,setRate:()=>t,setBlend:()=>t,setVisible:()=>t,isPlaying:Object.assign(()=>!1,{valueOf:()=>!1,toString:()=>"false"}),get frame(){return 0},get frameCount(){return 0},get rate(){return 1}};return t}function c0(t){if(!t)return Ji();if(t.textureAnimation)return t.textureAnimation.api;const e={frame:null,playing:!0,rate:1},n={play:()=>(e.playing=!0,n),pause:()=>(e.playing=!1,n),stop:()=>(e.playing=!1,n),setFrame:r=>{const i=Number(r);return e.frame=Number.isFinite(i)?i:0,n},setRate:r=>{const i=Number(r);return Number.isFinite(i)&&(e.rate=i),n},setBlend:()=>n,setVisible:r=>(t.visible=!!r,n),isPlaying:Object.assign(()=>e.playing,{valueOf:()=>e.playing,toString:()=>String(e.playing)}),get frame(){return e.frame===null?0:e.frame},get frameCount(){return t.spriteFrameCount||0},get rate(){return e.rate}};return e.api=n,t.textureAnimation=e,n}function l0(t){if(t&&t.videoTextureApi)return t.videoTextureApi;const e=()=>t&&t.videoCtl||null,n={get duration(){const r=e(),i=r&&typeof r.duration=="function"?r.duration():0;return Number.isFinite(i)?i:0},get rate(){const r=e(),i=r&&typeof r.getRate=="function"?r.getRate():1;return Number.isFinite(i)&&i>0?i:1},set rate(r){const i=e(),s=Number(r);i&&typeof i.setRate=="function"&&Number.isFinite(s)&&i.setRate(s)},get loop(){const r=e();return r&&typeof r.getLoop=="function"?!!r.getLoop():!0},set loop(r){const i=e();i&&typeof i.setLoop=="function"&&i.setLoop(!!r)},play:()=>{const r=e();r&&r.play&&r.play()},pause:()=>{const r=e();r&&r.pause&&r.pause()},stop:()=>{const r=e();r&&r.stop&&r.stop()},isPlaying:Object.assign(()=>{const r=e();return!!(r&&typeof r.isPlaying=="function"&&r.isPlaying())},{valueOf(){const r=e();return!!(r&&typeof r.isPlaying=="function"&&r.isPlaying())},toString(){const r=e();return String(!!(r&&typeof r.isPlaying=="function"&&r.isPlaying()))}}),getCurrentTime:()=>{const r=e(),i=r&&typeof r.getCurrentTime=="function"?r.getCurrentTime():0;return Number.isFinite(i)?i:0},setCurrentTime:r=>{const i=e(),s=Number(r);i&&typeof i.setCurrentTime=="function"&&Number.isFinite(s)&&i.setCurrentTime(s)},addEndedCallback:r=>{const i=e();typeof r=="function"&&i&&typeof i.addEndedCallback=="function"&&i.addEndedCallback(r)}};return t&&(t.videoTextureApi=n),n}function u0(){const t=new Map,e=r=>t.has(String(r))?t.get(String(r)):null,n=(r,i)=>{t.set(String(r),String(i))};return{getItem:e,setItem:n,get:e,set:n,removeItem:r=>{t.delete(String(r))},remove:r=>{t.delete(String(r))},clear:()=>{t.clear()},key:r=>Array.from(t.keys())[r]??null,get length(){return t.size}}}function f0(t,e){const n=t&&t.puppet,r=n&&n.bones||null,i=r?r.length:0,s=t&&t.origin||[0,0,0],a=t&&t.scale||[1,1,1],o=a[0]||1,c=a[1]||1,u=(p,m)=>[s[0]+p*o,s[1]-m*c],l=(p,m)=>[(p-s[0])/o,-(m-s[1])/c],f=p=>{const m=e.get(p);if(m)return[m[0],m[1],m[2]];const g=r[p].matrix;return[g[12],g[13],g[14]]},d=p=>{let m=0,g=0,w=p;for(let y=0;w>=0&&w<i&&y<64;y++){const b=f(w);m+=b[0],g+=b[1],w=r[w].parent}return u(m,g)},h=p=>{const m={translation(g){if(g===void 0){const k=d(p);return new xe(k[0],k[1],0)}const w=or(g);let y=0,b=0;if(r[p].parent>=0){const k=d(r[p].parent),A=l(k[0],k[1]);y=A[0],b=A[1]}const v=l(w[0],w[1]);return e.set(p,[v[0]-y,v[1]-b,0]),m},rotation(){return m},scale(){return m}};return m};return{getBoneCount:()=>i,getBoneTransform:p=>{const m=Math.floor(Number(p));if(!r||!(m>=0)||m>=i){const g={translation(w){return w===void 0?new xe(0,0,0):g},rotation(){return g},scale(){return g}};return g}return h(m)},setBoneTransform:(p,m)=>{const g=Math.floor(Number(p));!r||!(g>=0)||g>=i},applyBonePhysicsImpulse:()=>{}}}function lc(t){return{get visible(){return t?!!t.visible:!1},set visible(e){t&&(t.visible=!!e)},get name(){return t&&t.name||""},getMaterial:()=>null}}function Lf(t,e){if(t==null)return null;const n=r=>{if(!r)return null;if(e&&typeof e.getSceneLayer=="function"){const i=e.getSceneLayer(String(r));if(i)return i}return e&&e.layer&&e.layer.name===r?e.layer:null};if(typeof t=="object"){const r=Number(t.id);if(r>0&&e&&typeof e.enumerateSceneLayers=="function"){const i=e.enumerateSceneLayers();for(const s of i)if(s&&s.id===r)return s}return n(t.name)}return n(String(t))}function d0(t,e){t&&(t.visibleSelf=!1,t.visible=!1,t.destroyed=!0,e&&typeof e.recomputeVisibility=="function"&&e.recomputeVisibility())}function Of(t,e){if(typeof t!="string"||!t||/\/workshop\//.test(t))return t;const n=e!=null&&e!==""?String(e):"";if(!n)return t;const r=t.match(/^(models|materials|shaders|particles|effects)\/(.+)$/);return r?`${r[1]}/workshop/${n}/${r[2]}`:t}function h0(t){if(typeof t!="string")return null;const e=t.match(/export\s+let\s+__workshopId\s*=\s*['"](\d+)['"]/);return e?e[1]:null}function m0(t){const e=n=>aa(n||null,t);return{getLayer(n){if(t.getSceneLayer){const r=t.getSceneLayer(String(n));if(r&&!r.destroyed)return e(r)}return e(null)},createLayer(n){if(typeof t.createSceneLayer!="function")return e(null);let r=n;if(typeof n=="string"){const s=typeof t.getWorkshopId=="function"?t.getWorkshopId():t.workshopId;r=Of(n,s)}const i=t.createSceneLayer(r);return e(i||null)},destroyLayer(n){d0(Lf(n,t),t)},sortLayer:()=>{},getLayerIndex(n){const r=typeof t.enumerateSceneLayers=="function"?t.enumerateSceneLayers():[],i=n&&typeof n=="object"?n.name:String(n||""),s=r.findIndex(a=>a&&a.name===i);return s<0?0:s},enumerateLayers(){const n=typeof t.enumerateSceneLayers=="function"?t.enumerateSceneLayers():[],r=[];for(const i of n)i&&!i.destroyed&&r.push(e(i));return r},getAnimation(n){if(typeof t.getSceneAnimation=="function"){const r=t.getSceneAnimation(n);if(r)return r}return Ji()},getCameraTransforms(){const n=t.cameraTransforms||{zoom:1};return{zoom:typeof n.zoom=="number"?n.zoom:1,center:n.center||null,eye:n.eye||null,parallaxAmount:typeof n.parallaxAmount=="number"?n.parallaxAmount:0}},setCameraTransforms(n){const r=t.cameraTransforms;!r||!n||typeof n!="object"||(typeof n.zoom=="number"&&Number.isFinite(n.zoom)&&n.zoom>0&&(r.zoom=n.zoom),n.center!==void 0&&(r.center=n.center),n.eye!==void 0&&(r.eye=n.eye),typeof n.parallaxAmount=="number"&&(r.parallaxAmount=n.parallaxAmount))},getInitialLayerConfig(n){return typeof t.getInitialLayerConfig=="function"?t.getInitialLayerConfig(n):Lf(n,t)||null}}}function aa(t,e){const n=a=>es(Array.isArray(a)?a:[0,0,0]),r=e&&typeof e.getBoneOverrides=="function"&&t?e.getBoneOverrides(t):null,i={origin:n(t?t.origin:[0,0,0]),scale:n(t?t.scale:[1,1,1]),angles:y0(t),size:n(t?t.size:[0,0,0]),color:n(t?t.color:[1,1,1])},s={get name(){return t&&t.name||""},get id(){return t&&t.id||0},get visible(){const a=e&&e.targetEffect;return a?!!a.visible:t?t.visibleSelf!==void 0?!!t.visibleSelf:!!t.visible:!1},set visible(a){const o=e&&e.targetEffect;if(o){o.visible=!!a;return}t&&(t.visibleSelf=!!a,typeof e.recomputeVisibility=="function"?e.recomputeVisibility():t.visible=!!a)},get alpha(){return t&&typeof t.alpha=="number"?t.alpha:1},set alpha(a){t&&(t.alpha=Number(a)||0)},get brightness(){return t&&typeof t.brightness=="number"?t.brightness:1},set brightness(a){t&&(t.brightness=Number(a)||0)},get text(){return t&&t.text!==void 0?String(t.text):""},set text(a){t&&typeof a!="boolean"&&(t.text=a==null?"":String(a))},get pointsize(){return t&&t.textPointsize||24},set pointsize(a){t&&(t.textPointsize=Number(a)||24)},get font(){return t&&t.textFont||""},set font(a){t&&(t.textFont=String(a||""))},get alignment(){return t&&t.alignment||"center"},set alignment(a){if(!t)return;const o=String(a||"center").toLowerCase();t.alignment=o==="centre"?"center":o},...t&&t.puppet&&r?f0(t,r):{getBoneCount:()=>0,getBoneTransform:()=>{const a={translation(o){return o===void 0?new xe(0,0,0):a},rotation(){return a},scale(){return a}};return a},setBoneTransform:()=>{},applyBonePhysicsImpulse:()=>{}},getParent:()=>{if(!t||t.parentId==null)return null;const a=e&&typeof e.getSceneLayerById=="function"?e.getSceneLayerById(t.parentId):null;return!a||a.destroyed?null:aa(a,e)},getChildren:()=>{const a=t&&t.childIds||[];if(!a.length)return[];const o=e&&typeof e.getSceneLayerById=="function"?e.getSceneLayerById:null;if(!o)return[];const c=[];for(const u of a){const l=o(u);l&&!l.destroyed&&c.push(aa(l,e))}return c},getAnimation:a=>{const o=t&&t.animations,c=t&&t.animationList||[];if(a==null||a===""){if(typeof e.getAnimationForProperty=="function"){const u=e.getAnimationForProperty();if(u)return u}return c[0]||Ji()}return o&&o[a]?o[a]:typeof a=="number"&&c[a]?c[a]:typeof a=="string"&&/^\d+$/.test(a)&&c[Number(a)]?c[Number(a)]:Ji()},getAnimationLayer:a=>{const o=t&&t.animations,c=t&&t.animationList||[];return o&&o[a]?o[a]:typeof a=="number"&&c[a]?c[a]:typeof a=="string"&&/^\d+$/.test(a)&&c[Number(a)]?c[Number(a)]:Ji()},getAnimationLayerCount:()=>(t&&t.animationList||[]).length,getTextureAnimation:()=>c0(t),play:()=>{t&&t.soundCtl&&t.soundCtl.play&&t.soundCtl.play(),t&&t.videoCtl&&t.videoCtl.play&&t.videoCtl.play()},pause:()=>{t&&t.soundCtl&&t.soundCtl.pause&&t.soundCtl.pause(),t&&t.videoCtl&&t.videoCtl.pause&&t.videoCtl.pause()},stop:()=>{t&&t.soundCtl&&t.soundCtl.stop&&t.soundCtl.stop(),t&&t.videoCtl&&t.videoCtl.stop&&t.videoCtl.stop()},isPlaying:Object.assign(()=>{const a=t&&t.soundCtl&&typeof t.soundCtl.isPlaying=="function"&&t.soundCtl.isPlaying(),o=t&&t.videoCtl&&typeof t.videoCtl.isPlaying=="function"&&t.videoCtl.isPlaying();return!!(a||o)},{valueOf(){const a=t&&t.soundCtl&&typeof t.soundCtl.isPlaying=="function"&&t.soundCtl.isPlaying(),o=t&&t.videoCtl&&typeof t.videoCtl.isPlaying=="function"&&t.videoCtl.isPlaying();return!!(a||o)},toString(){const a=t&&t.soundCtl&&typeof t.soundCtl.isPlaying=="function"&&t.soundCtl.isPlaying(),o=t&&t.videoCtl&&typeof t.videoCtl.isPlaying=="function"&&t.videoCtl.isPlaying();return String(!!(a||o))}}),get volume(){if(t&&t.soundCtl&&typeof t.soundCtl.getVolume=="function")return t.soundCtl.getVolume();const a=t&&t.soundprops&&t.soundprops.volume;return typeof a=="number"?a:1},set volume(a){const o=Number(a);if(!Number.isFinite(o)||!t)return;const c=Math.max(0,Math.min(1,o));t.soundprops&&(t.soundprops.volume=c),t.soundCtl&&typeof t.soundCtl.setVolume=="function"&&t.soundCtl.setVolume(c)},getVideoTexture:()=>l0(t),getTransformMatrix:()=>{const a=t&&t.origin||[0,0,0],o=new Float32Array(16);return o[0]=1,o[5]=1,o[10]=1,o[15]=1,o[12]=a[0]||0,o[13]=a[1]||0,o[14]=a[2]||0,{m:o}},getEffect:a=>{const o=t&&t.effects||null;if(!o||o.length===0)return lc(null);if(typeof a=="number"||typeof a=="string"&&/^\d+$/.test(a))return lc(o[Number(a)]||null);const c=String(a);return lc(o.find(u=>u&&u.name===c)||null)}};Object.defineProperty(s,"angles",{enumerable:!0,get(){return i.angles},set(a){if(t&&Array.isArray(t.angles)){const o=Uf(a);t.angles[0]=o[0],t.angles[1]=o[1],t.angles[2]=o[2]}}});for(const a of["origin","scale","size","color"])Object.defineProperty(s,a,{enumerable:!0,get(){const o=t&&Array.isArray(t[a])?t[a]:null;return es(o||[0,0,0])},set(o){const c=or(o);i[a].x=c[0],i[a].y=c[1],i[a].z=c[2],t&&Array.isArray(t[a])&&a!=="size"&&(t[a][0]=c[0],t[a][1]=c[1],t[a][2]=c[2])}});return s}function p0(t,e,n={}){if(typeof t!="string"||t.length===0)return null;const r=Rf(t),i={};if(e&&typeof e=="object")for(const[A,T]of Object.entries(e))Df(i,A,T,n.userProperties);const s=new Proxy(()=>s,{apply(){return s},get(A,T){if(T==="finish")return()=>i;if(typeof T=="string"&&Af.test(T))return S=>(S&&typeof S=="object"&&typeof S.name=="string"&&!(S.name in i)&&(i[S.name]=sa(S.value)),s)}}),a={registerAsset:A=>A,frametime:1/60,runtime:0,canvasSize:Nf(n.canvasSize),screenResolution:n.screenResolution||{x:1920,y:1080},timeOfDay:typeof n.timeOfDay=="number"?n.timeOfDay:0,userProperties:n.userProperties||{},AUDIO_RESOLUTION_16:16,AUDIO_RESOLUTION_32:32,AUDIO_RESOLUTION_64:64,setTimeout:n.setTimeout||gi,clearTimeout:n.clearTimeout||(()=>{}),setInterval:n.setInterval||gi,clearInterval:n.clearInterval||(()=>{}),openUserShortcut:n.openUserShortcut||(()=>{}),isRunningInEditor:cc(n.isRunningInEditor),isScreensaver:!!n.isScreensaver};Sf(a,n);const o=n.audioViews;a.registerAudioBuffers=A=>{const T=Ff(A);let S=o?o.get(T):void 0;return S||(S={left:new Float32Array(T),right:new Float32Array(T),average:new Float32Array(T)},o&&o.set(T,S)),S};const c=n.shared||{},u={console:xf()},l=_f(n.inputView),f=n.layer||null,d=n.workshopId!=null?n.workshopId:h0(t),h=aa(f,n),p=m0({...n,workshopId:d,getWorkshopId:()=>d});let m;try{m=new Function("scriptProperties","engine","WEMath","WEColor","WEVector","createScriptProperties","shared","console","process","globalThis","self","window","document","require","module","exports","fetch","XMLHttpRequest","Worker","importScripts","location","navigator","alert","confirm","prompt","setTimeout","setInterval","clearTimeout","clearInterval","requestAnimationFrame","cancelAnimationFrame","performance","Function","Vec3","Vec2","input","thisLayer","thisScene","thisObject","localStorage","MediaPlaybackEvent",`"use strict";
|
|
6
|
+
`+r+`
|
|
7
|
+
;return {update: typeof update === "function" ? update : null,init: typeof init === "function" ? init : null,applyUserProperties: typeof applyUserProperties === "function" ? applyUserProperties : null,cursorClick: typeof cursorClick === "function" ? cursorClick : null,cursorEnter: typeof cursorEnter === "function" ? cursorEnter : null,cursorLeave: typeof cursorLeave === "function" ? cursorLeave : null,cursorDown: typeof cursorDown === "function" ? cursorDown : null,cursorUp: typeof cursorUp === "function" ? cursorUp : null,cursorMove: typeof cursorMove === "function" ? cursorMove : null,`+ia.map(T=>`${T}: typeof ${T} === "function" ? ${T} : null,`).join("")+'animationEvent: typeof animationEvent === "function" ? animationEvent : null,dummy_: 0};')(i,Tf(a),Ef,Cf,If,s,c,u.console,void 0,u,u,u,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,xe,Pf,l,h,p,h,u0(),Mf)}catch(A){return n.onError&&n.onError(A,"parse"),null}const g=!!(m&&(m.cursorClick||m.cursorEnter||m.cursorLeave||m.cursorDown||m.cursorUp||m.cursorMove)),w=!!(m&&ia.some(A=>m[A])),y=!!(m&&typeof m.applyUserProperties=="function"),b=/\bengine\s*\.\s*(runtime|frametime)\b/.test(r),v=!!(m&&typeof m.animationEvent=="function");if(!m||!m.update&&!g&&!w&&!y&&!b&&!v)return null;const k={engine:a,scriptProperties:i,hasUpdate:!!m.update,hasCursorHook:g,hasApplyHook:y,errCount:0,disabled:!1,init(A){if(m.init)try{return m.init(oc(A))}catch(T){k.errCount++,n.onError&&n.onError(T,"init")}},applyUserProperties(A){if(m.applyUserProperties)try{m.applyUserProperties(A||{})}catch(T){k.errCount++,n.onError&&n.onError(T,"applyUserProperties")}},callUpdate(A){if(k.disabled||!m.update)return;let T;try{T=m.update(oc(A))}catch(S){k.errCount++,n.onError&&n.onError(S,"update"),k.errCount>=3&&(k.disabled=!0);return}return T},hasCursorHook:g,callCursor(A,T){if(k.disabled)return;const S=m[A];if(typeof S=="function")try{return S(T)}catch(P){k.errCount++,n.onError&&n.onError(P,A),k.errCount>=3&&(k.disabled=!0);return}},hasMediaHook:w,callMedia(A,T){if(k.disabled)return;const S=m[A];if(typeof S=="function")try{return S(T)}catch(P){k.errCount++,n.onError&&n.onError(P,A),k.errCount>=3&&(k.disabled=!0);return}},hasMediaHook:w,hasAnimEventHook:v,callAnimationEvent(A,T){if(!k.disabled&&typeof m.animationEvent=="function")try{return m.animationEvent(A,oc(T))}catch(S){k.errCount++,n.onError&&n.onError(S,"animationEvent"),k.errCount>=3&&(k.disabled=!0);return}}};return k}function es(t){const e=Array.isArray(t)?t:[0,0,0],n={x:e[0]||0,y:e[1]||0,z:e[2]||0},r={get x(){return n.x},set x(i){n.x=Number(i)||0},get y(){return n.y},set y(i){n.y=Number(i)||0},get z(){return n.z},set z(i){n.z=Number(i)||0},add(i){const s=or(i);return n.x+=s[0],n.y+=s[1],n.z+=s[2],r},subtract(i){const s=or(i);return es([n.x-s[0],n.y-s[1],n.z-s[2]])},multiply(i){if(i&&typeof i=="object"){const s=or(i);n.x*=s[0],n.y*=s[1],n.z*=s[2]}else{const s=Number(i)||0;n.x*=s,n.y*=s,n.z*=s}return r},copy(){return new xe(n.x,n.y,n.z)},length(){return Math.sqrt(n.x*n.x+n.y*n.y+n.z*n.z)},lengthSqr(){return n.x*n.x+n.y*n.y+n.z*n.z},toArray(){return[n.x,n.y,n.z]}};return r}function or(t){if(Array.isArray(t))return[t[0]||0,t[1]||0,t[2]||0];if(t&&typeof t=="object")return[t.x||0,t.y||0,t.z||0];const e=Number(t)||0;return[e,e,e]}const oa=Math.PI/180,ca=180/Math.PI;function g0(t){const e=Array.isArray(t)?t:[0,0,0];return{x:(e[0]||0)*ca,y:(e[1]||0)*ca,z:(e[2]||0)*ca}}function Uf(t){const e=or(t);return[e[0]*oa,e[1]*oa,e[2]*oa]}function y0(t){const e={x:0,y:1,z:2},n={add(r){const i=or(r);return n.x+=i[0],n.y+=i[1],n.z+=i[2],n},subtract(r){const i=or(r);return n.x-=i[0],n.y-=i[1],n.z-=i[2],n},multiply(r){return n.x*=r,n.y*=r,n.z*=r,n},toArray(){return[n.x,n.y,n.z]}};for(const r of["x","y","z"])Object.defineProperty(n,r,{enumerable:!0,get(){return!t||!Array.isArray(t.angles)?0:(t.angles[e[r]]||0)*ca},set(i){!t||!Array.isArray(t.angles)||(t.angles[e[r]]=(Number(i)||0)*oa)}});return n}function b0(t,e){return Math.min(256,Math.ceil(Math.max(1,Number(t)||1)*2+8))}function w0(t){for(const e of t&&t.effects?t.effects:[]){if(e&&e.visible===!1)continue;if(String(e&&(e.file||e.name)||"").includes("tint"))return!0;for(const r of e&&e.passes||[])for(const i of r&&r.textures||[])if(i&&String(i).toLowerCase().includes("mask"))return!0}return!1}const v0=Object.freeze(Object.defineProperty({__proto__:null,Vec3:xe,createInputView:n0,drawTextLayer:e0,effectiveTextPadding:Yg,evalObjectScript:p0,evalTextScript:o0,foldVisibleReturn:a0,inkOverflow:kf,layoutText:Kg,makeCursorEventVec:t0,radToScriptAngles:g0,resolveWorkshopAssetPath:Of,rewriteComboStringEq:Bf,scriptAnglesToRad:Uf,shouldGrowMediaPlaceholder:Jg,textCanvasMargin:b0,textCanvasMarginGrow:Zg,textLayerHasTintMask:w0},Symbol.toStringTag,{value:"Module"}));function zf(t){if(t instanceof xe)return t;if(Array.isArray(t))return new xe(Number(t[0])||0,Number(t[1])||0,Number(t[2])||0);const e=String(t??"").trim().split(/\s+/).map(Number);return new xe(e[0]||0,e[1]||0,e[2]||0)}function Hf(t,e){if(!t||typeof e!="string")return null;const n=t[e];return n&&typeof n=="object"?n:null}function uc(t){return typeof t=="string"?t:t&&typeof t=="object"&&typeof t.name=="string"?t.name:null}function k0(t,e){return la(t)&&la(e)?Number(t)===Number(e):String(t)===String(e)}function fc(t){if(typeof t=="boolean")return"bool";if(typeof t=="number")return Number.isFinite(t)?"num":"other";if(typeof t=="string"){const e=t.trim().split(/\s+/);return e.length>0&&e[0]!==""&&e.every(n=>Number.isFinite(Number(n)))?"num":"text"}return"other"}function A0(t){switch(t.type){case"bool":return"bool";case"slider":return"num";case"color":return"num";case"textinput":return"text";default:return fc(t.value)}}function Vf(t,e){if(t===null||typeof t!="object")return t;if(t.user&&typeof t.user=="object"&&typeof t.user.name=="string"){const r=Hf(e,t.user.name);if(!r||r.value===void 0||r.value===null)return t.value;const i=r.type==="combo"?dc(r.value,r.options):r.value;return k0(i,t.user.condition)}if(typeof t.user!="string")return t;const n=Hf(e,t.user);if(!n||n.value===void 0||n.value===null)return t.value;if(n.userOverridden)return n.value;if(t.value!==null&&typeof t.value=="object")return t.value;if(t.value===void 0)return n.value;if(fc(t.value)==="bool"&&n.type==="slider"){const r=Number(n.value);return Number.isFinite(r)?r!==0:t.value}return fc(t.value)===A0(n)?n.value:t.value}function Rr(t,e,n){if(n>32||t===null||typeof t!="object")return t;if(Array.isArray(t)){for(let r=0;r<t.length;r++)t[r]=Rr(t[r],e,n+1);return t}if(uc(t.user)){let r=Vf(t,e);for(let i=0;i<8&&r!==null&&typeof r=="object"&&uc(r.user);i++)r=Vf(r,e);return t.value=Rr(r,e,n+1),t}for(const r of Object.keys(t))t[r]=Rr(t[r],e,n+1);return t}function x0(t){return t?Array.isArray(t)?t.map(e=>e&&typeof e=="object"&&"value"in e?e.value:e):typeof t=="object"?Object.values(t):[]:[]}function la(t){return typeof t=="number"?Number.isInteger(t):typeof t=="string"&&/^-?\d+$/.test(t.trim())}function dc(t,e){const n=x0(e);return!(n.length>0?n.every(la):la(t))||typeof t=="number"&&Number.isFinite(t)?t:typeof t=="string"&&/^-?\d+$/.test(t.trim())?Number(t):t}function T0(t){const e={};if(!t||typeof t!="object")return e;for(const[n,r]of Object.entries(t))!r||typeof r!="object"||!("value"in r)||(e[n]=r.type==="combo"?dc(r.value,r.options):r.type==="color"?zf(r.value):r.value);return e}function yn(t){return t&&typeof t=="object"?uc(t.user):null}function S0(t,e,n){const r={};if(!n||typeof n!="object")return r;const i=t&&typeof t=="object"?t:{},s=e&&typeof e=="object"?e:{};for(const[a,o]of Object.entries(n)){const c=o&&typeof o=="object"&&"value"in o?o.value:o,u=i[a];if(u&&typeof u=="object"){u.value=c,u.userOverridden=!0;const l=u.type==="combo"?dc(u.value,u.options):u.value,f=u.type==="color"?zf(l):l;s[a]=f,r[a]=f}else s[a]=c,r[a]=c}return r}function yi(t){typeof t=="object"&&t!==null&&(t=t.value);const e=String(t??"").trim().split(/\s+/).map(Number);return e.length===1?[e[0]||0,e[0]||0,e[0]||0]:[e[0]||0,e[1]||0,e[2]||0]}function ts(t){typeof t=="object"&&t!==null&&(t=t.value);const e=String(t??"").trim().split(/\s+/).map(Number);return e.length===1?[e[0]||0,e[0]||0]:[e[0]||0,e[1]||0]}function ua(t){return t==null?[1,1,1]:typeof t=="string"?yi(t):typeof t=="object"&&t!==null?yi(t.value):[1,1,1]}function Vt(t,e=!1){if(t==null)return e;if(typeof t=="boolean")return t;if(typeof t=="number")return t!==0;if(typeof t=="object"&&t!==null){const n=t.value;return typeof n=="number"?n!==0:!!n}return e}function $t(t,e){if(typeof t=="number")return t;if(t!==null&&typeof t=="object"){const n=Number(t.value);return Number.isFinite(n)?n:e}return e}function hc(t){return t?!t.image&&!t.model&&!t.particle&&t.text==null&&!t.size:!1}function mc(t,e,n){const r=n?t.scale:[1,1,1],i=(t.angles[2]||0)*Math.PI/180,s=Math.cos(i),a=Math.sin(i),o=e.origin[0]*r[0],c=e.origin[1]*r[1];return{origin:[t.origin[0]+o*s-c*a,t.origin[1]+o*a+c*s,t.origin[2]+(e.origin[2]||0)],scale:[r[0]*e.scale[0],r[1]*e.scale[1],r[2]*e.scale[2]],angles:[e.angles[0],e.angles[1],(t.angles[2]||0)+e.angles[2]]}}function P0(t,e){const n=e&&e.general&&e.general.properties||{},r=t.objects||[];Rr(r,n,0),Rr(t.general||{},n,0);const i=new Map;for(const g of r)g.id!==void 0&&i.set(g.id,g);const s=r.map(g=>({id:g.id,parent:g.parent,origin:yi(g.origin||"0 0 0"),scale:yi(g.scale||"1 1 1"),angles:yi(g.angles||"0 0 0")})),a=s.map(g=>({origin:g.origin.slice(),scale:g.scale.slice(),angles:g.angles.slice()}));for(let g=0;g<8;g++){let w=!1;for(const y of s){if(y.parent===void 0||y.parent===null||!i.get(y.parent))continue;const v=s.findIndex(B=>B.id===y.parent);if(v<0)continue;const k=s[v];if(k.parent!==void 0&&k.parent!==null)continue;const A=r[v],T=A.scale,P=!(T!==null&&typeof T=="object"&&(typeof T.script=="string"||T.user!==void 0)&&hc(A)),M=mc(k,y,P);y.origin=M.origin,y.scale=M.scale,y.angles=M.angles,y.parent=null,w=!0}if(!w)break}const o=r.map(g=>Vt(g.visible,!0)),c=new Map;r.forEach((g,w)=>{g.id!==void 0&&c.set(g.id,w)});const u=new Map,l=new Map;for(const g of r)if(g.parent!==void 0&&g.parent!==null){u.set(g.parent,(u.get(g.parent)||0)+1);const w=g.id!==void 0?g.id:null;if(w!==null){const y=l.get(g.parent);y?y.push(w):l.set(g.parent,[w])}}const f=r.map(()=>!0);for(let g=0;g<r.length;g++){let w=o[g],y=r[g].parent;for(let b=0;w&&y!==void 0&&y!==null&&b<64;b++){const v=c.get(y);if(v===void 0)break;o[v]||(w=!1),y=r[v].parent}f[g]=w}const d=r.map((g,w)=>{const y=s[w],b=typeof g.image=="string"&&(g.image.indexOf("models/util/projectlayer")===0||g.image.indexOf("models/util/fullscreenlayer")===0);let v=ts(g.size||"0 0"),k=y.origin;if(b){const A=(t.general||{}).orthogonalprojection,T=A&&Number(A.width),S=A&&Number(A.height);T>0&&S>0&&(v=[T,S],k=[T/2,S/2,y.origin[2]||0])}return{id:g.id!==void 0?g.id:w,name:g.name||"",visible:f[w],visibleSelf:o[w],srcObject:g,image:typeof g.image=="string"?g.image:null,model:typeof g.model=="string"?g.model:null,isSkybox:typeof g.name=="string"&&g.name.indexOf("\u5929\u7A7A\u76D2")>=0,particle:typeof g.particle=="string"?g.particle:null,instanceoverride:g.instanceoverride||null,particleOverrideAnimations:(()=>{const A=g.instanceoverride;if(!A||typeof A!="object")return null;const T={};for(const[S,P]of Object.entries(A))P&&typeof P=="object"&&P.animation&&typeof P.animation=="object"&&P.animation.options&&(T[S]={animation:P.animation,value:P.value});return Object.keys(T).length?T:null})(),sound:Array.isArray(g.sound)?g.sound.filter(A=>typeof A=="string"):[],soundprops:{volume:$t(g.volume,1),playbackmode:g.playbackmode||"single",startsilent:Vt(g.startsilent,!1),maxtime:$t(g.maxtime,0),mintime:$t(g.mintime,0),spatialization:Vt(g.spatialization,!1),muteineditor:Vt(g.muteineditor,!1)},text:typeof g.text=="string"?g.text:g.text&&typeof g.text=="object"?g.text.value:null,textScript:g.text&&typeof g.text=="object"&&g.text.script||null,textScriptProps:g.text&&typeof g.text=="object"&&g.text.scriptproperties||null,component:typeof g.component=="string"?g.component:null,isText:g.text!==void 0&&g.text!==null,textFont:typeof g.font=="string"?g.font:null,textPointsize:$t(g.pointsize,24)||24,textColor:ua(g.color),textAnchor:typeof g.anchor=="string"&&g.anchor!=="none"?g.anchor:"center",textMaxwidth:$t(g.maxwidth,0),textMaxrows:$t(g.maxrows,0),textLimitwidth:Vt(g.limitwidth,!1),textLimitrows:Vt(g.limitrows,!1),textLimituseellipsis:Vt(g.limituseellipsis,!1),textHAlign:g.horizontalalign||"center",textVAlign:g.verticalalign||"center",textSpacing:g.spacing?ts(g.spacing):[0,0],textPadding:(()=>{const A=g.padding;if(typeof A=="number")return A;const T=String(A??"").trim().split(/\s+/).map(Number).filter(S=>Number.isFinite(S));return T.length?T.reduce((S,P)=>S+P,0)/T.length:0})(),textOpaquebackground:Vt(g.opaquebackground,!1),textBackgroundcolor:ua(g.backgroundcolor),textBackgroundbrightness:$t(g.backgroundbrightness,1),textCastshadow:Vt(g.castshadow,!1),isSound:!!(g.sound&&g.sound.length),isComponent:!!g.component,objectScripts:(()=>{const A={};for(const T of["scale","origin","color","alpha","brightness","angles","visible"]){const S=g[T];S&&typeof S=="object"&&typeof S.script=="string"&&S.script&&(A[T]={script:S.script,scriptproperties:S.scriptproperties||null,value:S.value})}return Object.keys(A).length?A:null})(),objectAnimations:(()=>{const A={};for(const T of["scale","origin","color","alpha","brightness","angles","visible","volume","maxwidth","zoom"]){const S=g[T];S&&typeof S=="object"&&S.animation&&typeof S.animation=="object"&&S.animation.options&&(A[T]={animation:S.animation,value:S.value})}return Object.keys(A).length?A:null})(),animationLayers:(g.animationlayers||[]).filter(A=>A&&typeof A.animation=="number").map(A=>({animation:A.animation,visible:Vt(A.visible,!0),additive:Vt(A.additive,!1),blend:$t(A.blend,1),rate:$t(A.rate,1)})),solid:(()=>{if(typeof g.particle=="string")return!1;const A=typeof g.image=="string"?g.image:"";return A.indexOf("models/util/composelayer")===0?!1:A.indexOf("models/util/solidlayer")===0?!0:g.solid?!A||A.indexOf("models/util/")===0:!1})(),isContainer:typeof g.image=="string"&&g.image.indexOf("models/util/composelayer")===0,hasChildren:(u.get(g.id!==void 0?g.id:w)||0)>0,childIds:l.get(g.id!==void 0?g.id:w)||null,parentId:g.parent!==void 0&&g.parent!==null?g.parent:null,attachment:typeof g.attachment=="string"&&g.attachment!==""?g.attachment:null,passthrough:!!(g.config&&g.config.passthrough===!0),isPostProcess:b,origin:k,scale:y.scale,angles:y.angles,localOrigin:a[w].origin,localScale:a[w].scale,localAngles:a[w].angles,renderInert:hc(g),scaleRuntimeBound:g.scale!==null&&typeof g.scale=="object"&&(typeof g.scale.script=="string"||g.scale.user!==void 0),size:v,alignment:g.alignment||"center",color:ua(g.color),alpha:$t(g.alpha,1),brightness:$t(g.brightness,1),copybackground:!!g.copybackground,colorBlendMode:g.colorBlendMode||0,parallaxDepth:g.parallaxDepth!==void 0?ts(g.parallaxDepth):null,effects:(g.effects||[]).map(A=>({file:A.file||"",name:typeof A.name=="string"?A.name:"",visible:Vt(A.visible,!0),visibleScript:A.visible&&typeof A.visible=="object"&&typeof A.visible.script=="string"&&A.visible.script?{script:A.visible.script,scriptproperties:A.visible.scriptproperties||null,value:!!A.visible.value}:null,passes:(A.passes||[]).map(T=>{const S=T.textures||[],P=T.usertextures;let M=S;if(Array.isArray(P))for(let B=0;B<P.length;B++){const N=P[B],U=N&&typeof N=="object"&&typeof N.name=="string"?N.name:typeof N=="string"?N:null;U&&(M===S&&(M=S.slice()),M[B]=U)}return{combos:T.combos||{},constantshadervalues:T.constantshadervalues||{},textures:M}})}))}}),h=t.general||{},p=(()=>{const g={};for(const[w,y]of Object.entries(h))y&&typeof y=="object"&&typeof y.script=="string"&&y.script&&(g[w]={script:y.script,scriptproperties:y.scriptproperties||null,value:y.value});return Object.keys(g).length?g:null})(),m=(()=>{const g={};for(const[w,y]of Object.entries(h))y&&typeof y=="object"&&y.animation&&typeof y.animation=="object"&&y.animation.options&&(g[w]={animation:y.animation,value:y.value});return Object.keys(g).length?g:null})();{const g=new Map;for(const w of d)w.id!==void 0&&g.set(w.id,w);for(let w=0;w<8;w++){let y=!1;for(const b of d){if(b.parallaxDepth||b.parentId==null)continue;const v=g.get(b.parentId);!v||!v.parallaxDepth||v.image||v.particle||v.model||(b.parallaxDepth=v.parallaxDepth.slice(),y=!0)}if(!y)break}}return{camera:t.camera||null,general:h,generalScripts:p,generalAnimations:m,layers:d,properties:n}}function _0(t){if(!Array.isArray(t))return;const e=new Map;for(const n of t)n&&n.id!==void 0&&n.id!==null&&e.set(n.id,n);for(const n of t){if(!n)continue;if(n.destroyed){n.visible=!1;continue}let r=n.visibleSelf!==!1,i=n.parentId;for(let s=0;r&&i!=null&&s<64;s++){const a=e.get(i);if(!a)break;(a.visibleSelf===!1||a.destroyed)&&(r=!1),i=a.parentId}n.visible=r}}function E0(t,e){!t||!e||typeof e!="object"||t.isContainer||e.solidlayer===!0&&(t.solid=!0)}function C0(t){return!t||typeof t.material!="string"?null:{materialPath:t.material,autosize:!!t.autosize,cropoffset:t.cropoffset?ts(t.cropoffset):null}}function I0(t,e){if(!t||t.length===0)return;const n=new Map;for(const s of t)s&&s.id!==void 0&&s.id!==null&&n.set(s.id,s);const r=s=>{let a=0,o=s.parentId;for(let c=0;o!=null&&c<64;c++){const u=n.get(o);if(!u)break;a++,o=u.parentId}return a},i=[];for(const s of t)!s||!s.localOrigin||s.isPostProcess||e&&!e.has(s.id)||i.push(s);i.sort((s,a)=>r(s)-r(a));for(const s of i){const a=s.parentId!==void 0&&s.parentId!==null?n.get(s.parentId):null;let o;if(!a)o={origin:s.localOrigin.slice(),scale:s.localScale.slice(),angles:s.localAngles.slice()};else{const u=!(a.scaleRuntimeBound&&a.renderInert);o=mc({origin:a.origin,scale:a.scale,angles:a.angles},{origin:s.localOrigin,scale:s.localScale,angles:s.localAngles},u)}const c=s.attachBindDelta;c&&(o.origin[0]+=c[0],o.origin[1]+=c[1]),s.origin[0]=o.origin[0],s.origin[1]=o.origin[1],s.origin[2]=o.origin[2],s.scale[0]=o.scale[0],s.scale[1]=o.scale[1],s.scale[2]=o.scale[2],s.angles[0]=o.angles[0],s.angles[1]=o.angles[1],s.angles[2]=o.angles[2],s.attachBase&&(s.attachBase[0]=o.origin[0],s.attachBase[1]=o.origin[1])}}function M0(t,e){const n=new Set;if(!t||t.length===0)return n;const r=new Map;for(const o of t){if(!o||o.parentId===void 0||o.parentId===null)continue;const c=r.get(o.parentId);c?c.push(o):r.set(o.parentId,[o])}const i=["origin","scale","angles"],s=[];for(const o of t){if(!o||o.id===void 0||o.id===null)continue;const c=o.objectScripts||null,u=o.objectAnimations||null;i.some(f=>c&&c[f]||u&&u[f])&&s.push(o)}if(e)for(const o of e)o&&o.id!==void 0&&o.id!==null&&s.push(o);const a=s.slice();for(let o=0;a.length>0&&o<1e5;o++){const c=a.pop();if(!c||c.id===void 0||c.id===null||n.has(c.id))continue;n.add(c.id);const u=r.get(c.id);if(u)for(const l of u)a.push(l)}return n}const B0=Object.freeze(Object.defineProperty({__proto__:null,applySolidFromModel:E0,collectTransformDirty:M0,composeChildTransform:mc,isRenderInert:hc,parseBool:Vt,parseColor:ua,parseNum:$t,parseScene:P0,parseVec2:ts,parseVec3:yi,recomposeWorld:I0,recomputeLayerVisibility:_0,resolveMaterial:C0},Symbol.toStringTag,{value:"Module"}));function R0(t,e,n){const r=rc(t,e.file);if(r===null)return;let i;try{i=JSON.parse(n(r))}catch{return}e.fbos=i.fbos||[],e.materialPasses=(i.passes||[]).map(s=>{if(!s.material)return{shader:null,copyCommand:!0,target:s.target||null,source:s.source||null,binds:s.bind||[],blending:"normal",textures:[],combos:{},constants:{}};const a=rc(t,s.material);if(a===null)return{shader:null,copyCommand:!1,target:s.target||null,binds:s.bind||[],blending:"normal",textures:[],combos:{},constants:{}};const o=JSON.parse(n(a)),c=o.passes&&o.passes[0]||{};return{shader:c.shader||null,copyCommand:!1,target:s.target||null,binds:s.bind||[],blending:c.blending||"normal",textures:c.textures||[],combos:c.combos||{},constants:c.constantshadervalues||{}}})}const F0={"models/util/solidlayer.json":{material:"materials/util/solidlayer.json"},"models/util/composelayer.json":{material:"materials/util/solidlayer.json"},"models/util/fullscreenlayer.json":{material:"materials/util/solidlayer.json"},"models/util/projectlayer.json":{material:"materials/util/solidlayer.json"}};function Wf(t){if(!t||typeof t!="string")return!0;const e=t.toLowerCase();return e==="generic"||e==="sprite"||e==="flat"||e.startsWith("genericimage")}function D0(t,e){return!t||!e||!e.shader||Wf(e.shader)||(t.effects=t.effects||[],t.effects.some(n=>n.layerMaterial))?!1:(t.effects.unshift({file:"",name:"_layerMaterial",visible:!0,layerMaterial:!0,passes:[{combos:e.combos||{},constantshadervalues:e.constantshadervalues||{},textures:e.textures||[]}],materialPasses:[{shader:e.shader,copyCommand:!1,target:null,binds:[],blending:e.blending||"normal",textures:e.textures||[],combos:e.combos||{},constants:e.constantshadervalues||{}}],fbos:[]}),!0)}const N0=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_MATERIALS:{"materials/util/solidlayer.json":{passes:[{shader:"flat",blending:"translucent",cullmode:"nocull",depthtest:"disabled",depthwrite:"disabled",textures:[],combos:{}}]}},BUILTIN_MODELS:F0,attachLayerMaterialEffect:D0,isBuiltinAlbedoShader:Wf,resolveEffectChain:R0},Symbol.toStringTag,{value:"Module"}));function L0(t){const e=new Map,n=new Map,r=/^[ \t]*#define[ \t]+([A-Za-z_][A-Za-z0-9_]*)(?:\(([^)]*)\))?[ \t]*(.*)$/gm;let i;for(;(i=r.exec(t))!==null;){const s=a=>a.replace(/\/\/.*$/,"").replace(/\/\*[\s\S]*?\*\//g,"").trim();i[2]!==void 0?n.set(i[1],{args:i[2].split(",").map(a=>a.trim()).filter(Boolean),body:s(i[3])}):e.set(i[1],s(i[3]))}return{defs:e,fns:n}}function O0(t,e,n,r){const i=[];let s=0;for(;s<t.length;){const a=t.indexOf(e,s);if(a===-1){i.push(t.slice(s));break}i.push(t.slice(s,a));let c=a+e.length;for(;c<t.length&&/\s/.test(t[c]);)c++;if(t[c]!=="("){i.push(t.slice(a,c)),s=c;continue}let u=0,l=c;for(;l<t.length;l++)if(t[l]==="(")u++;else if(t[l]===")"&&(u--,u===0))break;if(l>=t.length){i.push(t.slice(a));break}const f=t.slice(c+1,l),d=Wn(f);let h=n.body;n.args.forEach((p,m)=>{const g=d[m]!==void 0?d[m].trim():"";h=ns(h,p,g)}),r>0&&(h=jf(h,r-1)),i.push("("+h+")"),s=l+1}return i.join("")}function ns(t,e,n){return t.replace(new RegExp("\\b"+e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","g"),n)}function Wn(t){const e=[];let n=0,r="";for(let i=0;i<t.length;i++){const s=t[i];s==="("?n++:s===")"&&n--,s===","&&n===0?(e.push(r),r=""):r+=s}return r.trim()!==""&&e.push(r),e}function jf(t,e){for(let n=0;n<12;n++){const{defs:r,fns:i}=L0(t);if(r.size===0&&i.size===0)break;const s=t.split(`
|
|
8
|
+
`),a=new Map;for(let u=0;u<s.length;u++){const l=/^[ \t]*#define[ \t]+([A-Za-z_][A-Za-z0-9_]*)/.exec(s[u]);l&&!a.has(l[1])&&a.set(l[1],u)}const o=new Map;{const u="(?:float|int|bool|vec[234]|ivec[234]|bvec[234]|mat[234])";for(const l of r.keys()){const f=l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),d=new RegExp("^\\s*(?:const\\s+|uniform\\s+|varying\\s+|in\\s+|out\\s+|attribute\\s+)*"+u+"\\s+"+f+"\\s*[=;]");for(let h=0;h<s.length;h++)if(d.test(s[h])){o.set(l,h);break}}}let c=!1;for(let u=0;u<s.length;u++){const l=s[u];if(/^[ \t]*#/.test(l))continue;let f=l;for(const[d,h]of r){const p=a.get(d);if(p!==void 0&&u<p||o.get(d)===u)continue;new RegExp("\\b"+d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b").test(f)&&(f=ns(f,d,h),c=!0)}for(const[d,h]of i){const p=a.get(d);p!==void 0&&u<p||f.includes(d)&&(f=O0(f,d,h,e),c=!0)}s[u]=f}if(t=s.join(`
|
|
9
|
+
`),!c)break}return t}function qf(t,e,n){const r=h=>e[h]!==void 0?String(e[h]):n.has(h)?"("+n.get(h)+")":"0";let i=t.replace(/\b[A-Za-z_][A-Za-z0-9_]*\b/g,h=>r(h)),s=0;function a(){for(;s<i.length&&/\s/.test(i[s]);)s++}function o(){let h=c();for(a();i.startsWith("||",s);){s+=2;const p=c();h=h||p,a()}return h}function c(){let h=u();for(a();i.startsWith("&&",s);){s+=2;const p=u();h=h&&p,a()}return h}function u(){let h=l();for(a();i.startsWith("==",s)||i.startsWith("!=",s);){const p=i[s]==="="?"==":"!=";s+=2;const m=l();h=p==="=="?h===m:h!==m,a()}return h}function l(){let h=f();for(a();/^[<>]/.test(i[s]||"");){let p=i[s];i[s+1]==="="&&(p+="=",s++),s++;const m=f();p==="<"?h=h<m:p===">"?h=h>m:p==="<="?h=h<=m:h=h>=m,a()}return h}function f(){return a(),i[s]==="!"?(s++,!f()):d()}function d(){if(a(),i[s]==="("){s++;const p=o();return a(),s++,p}const h=/^-?\d+(\.\d+)?/.exec(i.slice(s));return h?(s+=h[0].length,Number(h[0])):!1}return o()}function Xf(t){let e="",n=0;const r=t.length;for(;n<r;){const i=t[n],s=t[n+1];if(i==="/"&&s==="*"){for(n+=2;n<r&&!(t[n]==="*"&&t[n+1]==="/");)t[n]===`
|
|
10
|
+
`&&(e+=`
|
|
11
|
+
`),n++;n+=2;continue}if(i==="/"&&s==="/"){for(;n<r&&t[n]!==`
|
|
12
|
+
`;)n++;continue}e+=i,n++}return e}function Gf(t,e,n,r){const i=t.split(`
|
|
13
|
+
`),s=[],a=[],o=new Map;for(let c=0;c<i.length;c++){const u=i[c],l=u.trim();if(l.startsWith("#include")){if(rs(a)){const f=/^#include[ \t]+"([^"]+)"|^#include[ \t]+<([^>]+)>/.exec(l),d=f&&(f[1]||f[2]),h=d&&n?n(d):null;h!=null?s.push(Gf(Xf(h),e,n)):s.push("// [include \u7F3A\u5931: "+d+"]")}continue}if(l.startsWith("#define")){if(rs(a)){s.push(u);const f=/^#define[ \t]+([A-Za-z_][A-Za-z0-9_]*)(?:\([^)]*\))?[ \t]*(.*)$/.exec(l);f&&o.set(f[1],f[2].trim())}continue}if(l.startsWith("#undef")){rs(a)&&s.push(u);continue}if(l.startsWith("#ifdef")||l.startsWith("#ifndef")||l.startsWith("#if")){const f=rs(a);let d=!1;if(l.startsWith("#ifdef")){const h=l.slice(6).trim().split(/\s+/)[0];d=e[h]!==void 0||o.has(h)}else if(l.startsWith("#ifndef")){const h=l.slice(7).trim().split(/\s+/)[0];d=!(e[h]!==void 0||o.has(h))}else try{d=!!qf(l.slice(3).trim(),e,o)}catch{d=!1}a.push({parent:f,hit:d,done:d});continue}if(l.startsWith("#else")){if(a.length>0){const f=a[a.length-1];f.hit=!f.done,f.done=!0}continue}if(l.startsWith("#elif")){if(a.length>0){const f=a[a.length-1];if(f.done)f.hit=!1;else{let d=!1;try{d=!!qf(l.slice(5).trim(),e,o)}catch{d=!1}f.hit=d,f.done=d}}continue}if(l.startsWith("#endif")){a.length>0&&a.pop();continue}l.startsWith("#")||rs(a)&&s.push(u)}return s.join(`
|
|
14
|
+
`)}function rs(t){return t.every(e=>e.parent&&e.hit)}function fa(t,e,n,r){let i=0;for(let s=e;s<t.length;s++)if(t[s]===n)i++;else if(t[s]===r&&(i--,i===0))return s;return-1}function $f(t,e){return fa(t,e,"(",")")}const U0=new Set(["void","bool","int","uint","float","double","vec2","vec3","vec4","bvec2","bvec3","bvec4","ivec2","ivec3","ivec4","uvec2","uvec3","uvec4","mat2","mat3","mat4","mat2x2","mat2x3","mat2x4","mat3x2","mat3x3","mat3x4","mat4x2","mat4x3","mat4x4"]);function z0(t,e){let n=e-1;for(;n>=0&&/[ \t]/.test(t[n]);)n--;if(n<0||n===e-1)return!1;let r=n+1;for(;n>=0&&/[A-Za-z0-9_]/.test(t[n]);)n--;const i=t.slice(n+1,r);return U0.has(i)}function Qf(t){const e=new Set;let n;const r=/\b(?:const\s+)?int\s+([A-Za-z_]\w*)\s*[=;)\u0003]/g;for(;(n=r.exec(t))!==null;)e.add(n[1]);return e}function ut(t,e,n){let r="",i=0;for(;i<t.length;){const s=t.indexOf(e,i);if(s===-1){r+=t.slice(i);break}if(s>0&&/[A-Za-z0-9_]/.test(t[s-1])){r+=t.slice(i,s+1),i=s+1;continue}const a=s+e.length;if(a<t.length&&/[A-Za-z0-9_]/.test(t[a])){r+=t.slice(i,a),i=a;continue}if(z0(t,s)){r+=t.slice(i,a),i=a;continue}r+=t.slice(i,s);let o=s+e.length;for(;o<t.length&&/\s/.test(t[o]);)o++;if(t[o]!=="("){r+=t.slice(s,o),i=o;continue}const c=$f(t,o);if(c===-1){r+=t.slice(s);break}const u=t.slice(o+1,c);r+=n(u,s),i=c+1}return r}function Yf(t,e,n,r,i){const s=t;t=Xf(t);const a={},o=/\[COMBO\][^\n]*?"combo"\s*:\s*"([^"]+)"[^\n]*?"default"\s*:\s*(-?\d+)/g;let c;if(typeof i=="string"&&i){const y=new RegExp(o.source,"g");let b;for(;(b=y.exec(i))!==null;)a[b[1]]=Number(b[2])}for(;(c=o.exec(s))!==null;)a[c[1]]=Number(c[2]);const u={GLSL:1,...a,...n||{}};let l=Gf(t,u,r);l=jf(l,20),l=l.replace(/^[ \t]*#define[^\n]*\n?/gm,"");{const y=new Set,b=/\[COMBO\][^\n]*"combo"\s*:\s*"([^"]+)"/g;let v;for(;(v=b.exec(s))!==null;)y.add(v[1]);for(const k of Object.keys(u))y.add(k);y.delete("GLSL");for(const k of y){const A=u[k]!==void 0?u[k]:0;l=ns(l,k,String(A))}}l=ns(l,"sample","smp"),l=l.replace(/(\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)[fh]\b/g,"$1"),l=l.replace(/\bfloat4x4\b/g,"mat4").replace(/\bfloat3x3\b/g,"mat3").replace(/\bfloat2x2\b/g,"mat2").replace(/\bfloat4\b/g,"vec4").replace(/\bfloat3\b/g,"vec3").replace(/\bfloat2\b/g,"vec2").replace(/\bhalf4\b/g,"vec4").replace(/\bhalf3\b/g,"vec3").replace(/\bhalf2\b/g,"vec2").replace(/\bhalf\b/g,"float"),l=l.replace(/\btexSample2DLod\b/g,"textureLod").replace(/\btexSample2D\b/g,"texture"),l=ut(l,"saturate",y=>"clamp("+y+", 0.0, 1.0)"),l=ut(l,"CAST4",y=>"vec4("+y+")"),l=ut(l,"CAST3",y=>"vec3("+y+")"),l=ut(l,"CAST2",y=>"vec2("+y+")"),l=l.replace(/\b(max|min)\(\s*(-?\d+(?:\.\d+)?)\s*,\s*([A-Za-z_]\w*\.(rgb|xyz|rg|xy|r|x))\s*\)/g,(y,b,v,k,A)=>{const T=A.length;return b+"(vec"+T+"("+v+"), "+k+")"}),l=l.replace(/(\.([xyzwrgba]{2,4})\s*=\s*)(max|min)\(\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*,\s*([^;]+?)\s*\)\s*;/g,(y,b,v,k,A,T)=>/\.[xyzwrgba]{2,4}\b|\bvec[234]\s*\(/.test(T)?`${b}${k}(vec${v.length}(${A}), ${T});`:y),l=l.replace(/(^|[^\w)\]])([+-])([+-])(?=[\d.])/g,(y,b,v,k)=>b+(v===k?"+":"-"));const f=[];l=l.replace(/\b\d+(?:\.\d+)?[eE][+-]?\d+\b/g,y=>(f.push(y),""+"".repeat(f.length)+""));const d=[];l=l.replace(/\bfor\s*\(\s*int\s+([A-Za-z_]\w*)([^)]*)\)/g,(y,b,v)=>(d.push(v+")"),`for (int ${b}${"".repeat(d.length)}`));for(let y=0;y<8;y++){const b=l;l=l.replace(/(^|[^\w.])(\d+)\s*([*/])\s*([A-Za-z_][A-Za-z0-9_]*)/g,"$1$2.0 $3 $4"),l=l.replace(/\b([A-Za-z_][A-Za-z0-9_]*)\s*([*/])\s*(\d+)(?![\d.])/g,"$1 $2 $3.0"),l=l.replace(/(\d+\.\d+)\s*([*/])\s*(\d+)(?![\d.])/g,"$1 $2 $3.0"),l=l.replace(/(^|[^\w.])(\d+)\s*([*/])\s*(\d+\.\d+)/g,"$1$2.0 $3 $4"),l=l.replace(/(\.\d+)\s*([+-])\s*(\d+)(?![\d.])/g,"$1 $2 $3.0"),l=l.replace(/([A-Za-z_]\w*\.(?:xyzw|xyz|xy|zw|rgba|rgb|rg|x|y|z|w|r|g|b|a))\s*([+-])\s*(\d+)(?![\d.])/g,"$1 $2 $3.0"),l=l.replace(/(^|[^\w.])(\d+)\s*([+-])\s*(\d+\.\d+)/g,"$1$2.0 $3 $4"),l=l.replace(/(^|[^\w.])(\d+)\s*([+-])\s*([A-Za-z_]\w*\.(?:xyzw|xyz|xy|zw|rgba|rgb|rg|x|y|z|w|r|g|b|a))/g,"$1$2.0 $3 $4"),l=l.replace(/(^|[^\w.])(\d+)\s*([*/+-])\s*(\()/g,(v,k,A,T,S,P,M)=>{let B=0,N=P+v.length-1;for(;N<M.length;N++){const q=M[N];if(q==="(")B++;else if(q===")"){if(B--,B===0){N++;break}}else if(B===0&&(q===";"||q===","||q===`
|
|
15
|
+
`))break}for(;N<M.length;N++){const q=M[N];if(q===";"||q===","||q===`
|
|
16
|
+
`||q===")")break}const U=M.slice(P,N);return/\d\.\d/.test(U)?`${k}${A}.0 ${T} ${S}`:v});{const v=new Set,k=/\b(?:uniform\s+)?(?:highp|mediump|lowp\s+)?(?:float|vec2|vec3|vec4|mat2|mat3|mat4)\s+([A-Za-z_][A-Za-z0-9_]*)/g;let A;for(;(A=k.exec(l))!==null;)v.add(A[1]);if(v.size>0){const T=Array.from(v).sort((S,P)=>P.length-S.length).join("|");l=l.replace(new RegExp("(^|[^\\w.])(\\d+)\\s*([+-])\\s*("+T+")(?![A-Za-z0-9_])","g"),"$1$2.0 $3 $4"),l=l.replace(new RegExp("\\b("+T+")\\s*([+-])\\s*(\\d+)(?![\\d.])","g"),"$1 $2 $3.0")}}if(l===b)break}{const y=["smoothstep","step","mix","clamp","max","min","pow","mod","atan","sqrt","inversesqrt","exp","log","exp2","log2","abs","sign","floor","ceil","fract","length","distance","dot","reflect","refract","faceforward","normalize","cross"],b=/\b(ApplyBlending|ApplyComposite|BlendTransparency)\s*\(/;for(const v of y)l=ut(l,v,k=>{const T=Wn(k).map(S=>{if(b.test(S))return S;const P=[];let M=S.replace(/\[[^\]]*\]/g,B=>(P.push(B),"\0"+(P.length-1)+"\0")).replace(/\b(?:ivec[234]|uvec[234]|int|uint)\s*\([^()]*\)/g,B=>(P.push(B),"\0"+(P.length-1)+"\0"));return M=M.replace(/(?<![A-Za-z0-9_.\u0000])(\d+)(?![.\d])(?![A-Za-z_])/g,"$1.0"),M.replace(/\u0000(\d+)\u0000/g,(B,N)=>P[Number(N)])});return v+"("+T.join(",")+")"});l=ut(l,"pow",v=>{const k=Wn(v);if(k.length!==2)return"pow("+v+")";const A=k[0].trim(),T=k[1].trim(),S=/\.(xyzw|rgba|xyz|rgb|xy|rg|zw)\s*$/.exec(A),M=S?{xyzw:4,rgba:4,xyz:3,rgb:3,xy:2,rg:2,zw:2}[S[1]]:0,B=/\bvec[234]\s*\(/.test(T)||/\.(xyzw|rgba|xyz|rgb|xy|rg|zw)\b/.test(T);return M>=2&&!B?"pow("+A+", vec"+M+"("+T+"))":"pow("+A+", "+T+")"})}l=l.replace(/([)\]])\s*([*/])\s*(\d+)(?![\d.])/g,"$1 $2 $3.0"),l=l.replace(/\)\s*([+-])\s*(\d+)(?![\d.])/g,") $1 $2.0"),l=l.replace(/(^|[^\w.])(\d+)(?![.\d])\s*([+-])\s*((?:step|smoothstep|mix|mod|fract|abs|sin|cos|tan|atan|sqrt|pow|inversesqrt|floor|ceil|sign|length|normalize|distance|dot|cross|exp|log|exp2|log2|clamp|min|max)\s*\()/g,"$1$2.0 $3 $4");{const y=new Set,b=/\b(?:vec[234])\s+([A-Za-z_][A-Za-z0-9_]*)/g;let v;for(;(v=b.exec(l))!==null;)y.add(v[1]);if(y.size>0){const k=Array.from(y).sort((A,T)=>T.length-A.length).join("|");l=l.replace(new RegExp("\\b("+k+")\\s*([+-])\\s*(\\d+)(?![\\d.])","g"),"$1 $2 $3.0")}}{const y=new Set,b=/\b(?:int|uint)\s+([A-Za-z_][A-Za-z0-9_]*)/g;let v;for(;(v=b.exec(l))!==null;)y.add(v[1]);l=l.replace(/\buint\b/g,"int"),l=l.replace(/\b([A-Za-z_][A-Za-z0-9_]*)\s*%\s*(\d+)(?![\d.])/g,(k,A,T)=>y.has(A)?k:"mod("+A+", "+T+".0)"),l=l.replace(/\bint\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*mod\(([^;]*)\);/g,"int $1 = int(mod($2));")}l=l.replace(/\b(vec[234])\s+([A-Za-z_][A-Za-z0-9_]*)\s*=\s*([^;()\n,]+);/g,(y,b,v,k)=>{const A=k.trim();return/^(vec[234]|mat[234]|int\b|float\b)/.test(A)?y:b+" "+v+" = "+b+"("+A+");"});for(const y of["mix","clamp","step","smoothstep","min","max","mod","pow"])l=ut(l,y,b=>y+"("+b.replace(/(?<![A-Za-z0-9_.])(\d+)(?![.\d])/g,"$1.0")+")");l=ut(l,"clamp",y=>{const b=Wn(y);if(b.length!==3)return"clamp("+y+")";const v=b[0].trim(),k=b[1].trim(),A=T=>/^-?\d+\.?\d*$/.test(T);return A(v)&&A(k)&&Number(v)===0&&Number(k)===1?"clamp("+b[2].trim()+", "+v+", "+k+")":"clamp("+y+")"}),l=l.replace(/(\.\d+)\s*([+-])\s*(\d+)(?![\d.])/g,"$1 $2 $3.0"),l=l.replace(/([)\]])\s*([+-])\s*(\d+)(?![\d.])/g,"$1 $2 $3.0"),l=ut(l,"smoothstep",y=>{const b=Wn(y);return b.length===3&&b[1].trim()==="0.0"&&b[0].trim()!=="0.0"?"(1.0 - smoothstep(0.0, "+b[0].trim()+", "+b[2].trim()+"))":"smoothstep("+y+")"});{const y=new Map,b=/\b(?:uniform|varying|attribute|in|out)?\s*\b(vec([234]))\s+([A-Za-z_]\w*)/g;let v;for(;(v=b.exec(l))!==null;)y.set(v[3],Number(v[2]));if(y.size>0){const k={2:"xy",3:"xyz",4:"xyzw"};l=l.replace(/(^|[;{}\n]\s*)([A-Za-z_]\w*)\s*=\s*([A-Za-z_]\w*)\s*;/g,(A,T,S,P)=>{const M=y.get(S),B=y.get(P);return!M||!B||M>=B?A:T+S+" = "+P+"."+k[M]+";"})}{const k=new Set;{const S=/\b(?:uniform|varying|attribute|in|out|const)?\s*\bfloat\s+([A-Za-z_]\w*)/g;let P;for(;(P=S.exec(l))!==null;)k.add(P[1])}const A=S=>{const P=S.trim();{const N=/^vec([234])\s*\(/.exec(P);if(N){let U=0;for(let q=P.indexOf("(");q<P.length;q++)if(P[q]==="(")U++;else if(P[q]===")"&&(U--,U===0))return q===P.length-1?Number(N[1]):0;return 0}}if(/^texture(?:Lod)?\s*\(/.test(P)){let N=0;for(let U=P.indexOf("(");U<P.length;U++)if(P[U]==="(")N++;else if(P[U]===")"&&(N--,N===0))return U===P.length-1?4:0;return 0}const M=/^([A-Za-z_]\w*)(?:\.([xyzwrgba]{2,4}))?\s*[*/]\s*([^*/]+)$/.exec(P);if(!M)return 0;const B=M[3];return/\bvec[234]\s*\(|\.[xyzwrgba]{2,4}\b/.test(B)?0:M[2]?M[2].length:k.has(M[1])?0:y.get(M[1])||0};l=l.replace(/(^|[;{}\n]\s*)float\s+([A-Za-z_]\w*)\s*=\s*([^;]+);/g,(S,P,M,B)=>A(B)<2?S:`${P}float ${M} = (${B.trim()}).x;`);const T={2:"xy",3:"xyz"};l=l.replace(/(^|[;{}\n]\s*)vec([23])\s+([A-Za-z_]\w*)\s*=\s*([^;]+);/g,(S,P,M,B,N)=>{const U=Number(M);return A(N)<=U?S:`${P}vec${M} ${B} = (${N.trim()}).${T[U]};`})}if(y.size>0){const k=new Set,A=/\b(?:uniform|varying|attribute|in|out)?\s*\bfloat\s+([A-Za-z_]\w*)/g;let T;for(;(T=A.exec(l))!==null;)k.add(T[1]);const S="pow|saturate|clamp|smoothstep|step|abs|floor|ceil|fract|frac|sin|cos|tan|asin|acos|atan|sqrt|length|distance|dot|exp|log|sign|fmod|mod|min|max|mix|lerp",P=/^(?:length|distance|dot)$/,M=N=>{const U=N.match(new RegExp("^(?:"+S+")\\s*\\("));if(!U)return!1;let q=0;const H=U[0].length-1;let G=-1;for(let ne=H;ne<N.length;ne++)if(N[ne]==="(")q++;else if(N[ne]===")"&&(q--,q===0)){G=ne;break}if(G!==N.length-1)return!1;const Y=U[0].replace(/\s*\($/,"");if(P.test(Y))return!0;const J=N.slice(H+1,G);if(/\bvec[234]\s*\(/.test(J)||/\.[xyzwrgba]{2,4}\b/.test(J))return!1;for(const ne of y.keys()){const fe=ne.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");if(new RegExp("(?<!\\.)\\b"+fe+"\\b(?!\\s*\\.[xyzwrgba]\\b)").test(J))return!1}return!0},B=new Set;if(l=l.replace(/(^|[;{}\n]\s*)([A-Za-z_]\w*)\s*=\s*([^;]+);/g,(N,U,q,H)=>{const G=y.get(q);if(!G||k.has(q))return N;const Y=H.trim();if(new RegExp("^vec"+G+"\\s*\\(").test(Y)||y.has(Y))return N;const J=/^-?\d+(?:\.\d+)?(?:e[-+]?\d+)?$/i.test(Y),ne=k.has(Y);return!J&&!ne&&!M(Y)?N:(B.add(q),U+q+" = vec"+G+"("+Y+");")}),B.size>0){const N=[...B].sort((U,q)=>q.length-U.length).join("|");l=l.replace(new RegExp(`\\b([A-Za-z_]\\w*)\\s*([*/])\\s*(${N})\\b`,"g"),(U,q,H,G)=>y.has(q)?U:`${q} ${H} ${G}.x`),l=l.replace(new RegExp(`\\b(${N})\\s*([*/])\\s*([A-Za-z_]\\w*)\\b`,"g"),(U,q,H,G)=>y.has(G)?U:`${q}.x ${H} ${G}`)}}}l=l.replace(/(\.[xyzwrgba]{1,4}\s*=\s*)(-?\d+)\s*;/g,"$1$2.0;"),l=l.replace(/\b(float|vec2|vec3|vec4)\s+([A-Za-z_]\w*)\s*=\s*(-?\d+)\s*;/g,(y,b,v,k)=>b==="float"?`${b} ${v} = ${k}.0;`:`${b} ${v} = ${b}(${k}.0);`);{const y=new Set,b=/\b(?:uniform|varying|attribute|in|out)?\s*\bfloat\s+([A-Za-z_]\w*)/g;let v;for(;(v=b.exec(l))!==null;)y.add(v[1]);if(y.size>0){const k=[...y].sort((A,T)=>T.length-A.length).join("|");l=l.replace(new RegExp(`\\b(${k})\\s*=\\s*(-?\\d+)\\s*;`,"g"),"$1 = $2.0;"),l=l.replace(new RegExp(`\\b(${k})\\s*([-+*/]=)\\s*(-?\\d+)\\s*;`,"g"),"$1 $2 $3.0;")}}l=l.replace(/(\.[xyzwrgba]{1,4}\s*[-+*/]=\s*)(-?\d+)\s*;/g,"$1$2.0;");const h="step|smoothstep|saturate|clamp|mix|lerp|frac|fract|abs|floor|ceil|min|max|pow|sqrt|length|dot|distance";l=l.replace(new RegExp(`\\bint\\s+([A-Za-z_]\\w*)\\s*=\\s*((?:${h})\\s*\\()`,"g"),"float $1 = $2"),l=l.replace(/\bfloat\s+([A-Za-z_]\w*)\s*=\s*(int\s*\([^;]*\))\s*;/g,"float $1 = float($2);");{const y=Qf(l);y.size>0&&(l=l.replace(/\b(const\s+)?float\s+([A-Za-z_]\w*)\s*=\s*([^;{}]+);/g,(b,v,k,A)=>{const T=A.trim();if(/\./.test(T)||/[A-Za-z_]\w*\s*\(/.test(T))return b;const S=T.match(/[A-Za-z_]\w*/g);return!S||!S.length||!S.every(P=>y.has(P))?b:`${v||""}float ${k} = float(${T});`}))}{const y=Qf(l),b=new Set;let v;const k=/\b(?:const\s+|uniform\s+|varying\s+|in\s+|out\s+)*float\s+([A-Za-z_]\w*)/g;for(;(v=k.exec(l))!==null;)b.add(v[1]);for(const A of[...y])b.has(A)&&(y.delete(A),b.delete(A));if(y.size>0&&b.size>0){const A=[...y].sort((S,P)=>P.length-S.length).join("|"),T=[...b].sort((S,P)=>P.length-S.length).join("|");l=l.replace(new RegExp(`\\b(${A})\\s*([*/+-])\\s*(${T})\\b`,"g"),(S,P,M,B)=>`float(${P}) ${M} ${B}`),l=l.replace(new RegExp(`\\b(${T})\\s*([*/+-])\\s*(${A})\\b`,"g"),(S,P,M,B)=>`${P} ${M} float(${B})`)}}{const y=new Set,b=/\bbool\s+([A-Za-z_]\w*)\s*=/g;let v;for(;(v=b.exec(l))!==null;)y.add(v[1]);if(y.size>0){const k=[...y].join("|");l=l.replace(new RegExp(`([-+*/]=\\s*)(${k})\\b`,"g"),(A,T,S)=>`${T}float(${S})`)}}{const y=/\(\s*([^()&|]+?)\s*(<=|>=|<|>|==|!=)\s*([^()&|]+?)\s*\)/g;l=l.replace(new RegExp(y.source+"\\s*([*/])","g"),(b,v,k,A,T)=>`float(${v.trim()} ${k} ${A.trim()}) ${T}`),l=l.replace(new RegExp("([-+*/]=\\s*)"+y.source,"g"),(b,v,k,A,T)=>`${v}float(${k.trim()} ${A} ${T.trim()})`)}{const y=new Set;for(const b of l.matchAll(/\b(?:uniform\s+)?(?:highp|mediump|lowp\s+)?float\s+([A-Za-z_]\w*)\s*\[/g))y.add(b[1]);if(y.size){const b=[...y].sort((S,P)=>P.length-S.length).join("|"),v=new RegExp("\\b("+b+")\\s*\\[","g");let k="",A=0,T;for(;T=v.exec(l);){const S=T.index+T[0].length-1,P=fa(l,S,"[","]");if(P<0)break;let M=P+1;for(;M<l.length&&/[ \t]/.test(l[M]);)M++;if(l[M]!=="["){const H=l.slice(S+1,P).trim(),G=/\d\.\d/.test(H)||/^[A-Za-z_]\w*$/.test(H)&&new RegExp("\\bfloat\\s+"+H.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b").test(l),Y=/^\s*int\s*\(/.test(H)||/^-?\d+$/.test(H);if(G&&!Y){k+=l.slice(A,T.index),k+=T[1]+"[int("+H+")]",A=P+1,v.lastIndex=A;continue}v.lastIndex=P+1;continue}const B=fa(l,M,"[","]");if(B<0)break;const N=l.slice(S+1,P),U=l.slice(M+1,B);k+=l.slice(A,T.index),k+=T[1]+"[int(("+N+")) * 4 + int(("+U+"))]",A=B+1,v.lastIndex=A}l=k+l.slice(A)}}l=ut(l,"mix",(y,b)=>{const v=Wn(y);if(v.length!==3)return"mix("+y+")";const k=M=>{const B=M.trim(),N=/\.([xyzwrgba]{1,4})\s*$/.exec(B);if(N)return N[1].length;const U=/^vec([234])\s*\(/.exec(B);if(U)return Number(U[1]);if(!/^[A-Za-z_]\w*$/.test(B))return 0;const q=new RegExp("\\b(vec([234])|float)\\s+"+B+"\\b","g");let H=0,G;for(;(G=q.exec(l))!==null&&G.index<b;)H=G[1].startsWith("vec")?Number(G[2]):1;return H},A=v[0].trim(),T=v[1].trim(),S=k(A),P=k(T);if(S>=2&&P>=2&&S!==P){const M=Math.min(S,P),B=M===2?".xy":M===3?".xyz":"";return B?"mix("+(S>M?A+B:A)+", "+(P>M?T+B:T)+", "+v[2].trim()+")":"mix("+y+")"}return"mix("+y+")"});{const y=/\b(vec([234]))\s+([A-Za-z_]\w*)\s*\(/g;let b="",v=0,k;for(;k=y.exec(l);){const A=$f(l,k.index+k[0].length-1);if(A<0)break;let T=A+1;for(;T<l.length&&/\s/.test(l[T]);)T++;if(l[T]!=="{")continue;const S=fa(l,T,"{","}");if(S<0)break;const P=Number(k[2]);if(P>=4){y.lastIndex=S;continue}let M=l.slice(T+1,S);const B=new Map;for(const U of l.slice(0,k.index).matchAll(/\buniform\s+(?:highp|mediump|lowp\s+)?(vec([234]))\s+([A-Za-z_]\w*)/g))B.set(U[3],Number(U[2]));for(const U of M.matchAll(/\b(vec([234]))\s+([A-Za-z_]\w*)/g))B.set(U[3],Number(U[2]));const N=P===2?"xy":"xyz";M=M.replace(/\breturn\s+([A-Za-z_]\w*)\s*;/g,(U,q)=>{const H=B.get(q);return H&&H>P?"return "+q+"."+N+";":U}),b+=l.slice(v,T+1)+M,v=S,y.lastIndex=S}l=b+l.slice(v)}const p=new Set,m=/\b(?:uniform\s+)?(?:mat4|mat3|mat2|float4x4)\s+([A-Za-z_][A-Za-z0-9_]*)/g;let g;for(;(g=m.exec(l))!==null;)p.add(g[1]);if(l=ut(l,"mul",y=>{const b=Wn(y);if(b.length!==2)return"mul("+y+")";const v=b[0].trim(),k=b[1].trim(),A=T=>p.has(T.split(/[\[.\s]/)[0])||/^mat[234]\(/.test(T);return A(v)&&A(k)?"(transpose("+k+") * transpose("+v+"))":A(k)?"(transpose("+k+") * "+v+")":"("+v+" * "+k+")"}),l=l.replace(/\blerp\b/g,"mix").replace(/\bfrac\b/g,"fract"),l=ut(l,"atan2",y=>"atan("+y+")"),l=ut(l,"fmod",y=>{const b=Wn(y);if(b.length!==2)return"mod("+y+")";const v=b[0].trim(),k=b[1].trim();return"(("+v+") - ("+k+") * trunc(("+v+") / ("+k+")))"}),l=ut(l,"ddx",y=>"dFdx("+y+")"),l=ut(l,"ddy",y=>"dFdy("+y+")"),l=ut(l,"CAST3X3",y=>"mat3("+y+")"),e==="vert")l=l.replace(/\battribute\b/g,"in").replace(/\bvarying\b/g,"out");else{if(l=l.replace(/\bvarying\b/g,"in").replace(/\battribute\b/g,"in"),typeof i=="string"&&i){const v=new Map,k=/^\s*(?:varying|out)\s+(?:highp|mediump|lowp\s+)?(vec[234]|float)\s+([A-Za-z_]\w*)\s*;/gm;let A;for(;(A=k.exec(i))!==null;)v.set(A[2],A[1]);const T={float:1,vec2:2,vec3:3,vec4:4},S=new Map;if(l=l.replace(/^(\s*in\s+(?:highp|mediump|lowp\s+)?)(vec[234]|float)(\s+)([A-Za-z_]\w*)(\s*;)/gm,(P,M,B,N,U,q)=>{const H=v.get(U);return!H||T[H]<=T[B]?P:(S.set(U,T[B]),M+H+N+U+q)}),S.size>0){const P={1:"x",2:"xy",3:"xyz"};for(const[M,B]of S){const N=P[B];N&&(l=l.split(`
|
|
17
|
+
`).map(U=>/^\s*in\s/.test(U)?U:U.replace(new RegExp("\\b"+M+"\\b(?!\\s*[.\\w])","g"),M+"."+N)).join(`
|
|
18
|
+
`))}}l=l.replace(/^(\s*in\s+(?:highp|mediump|lowp\s+)?)(vec[234]|float)(\s+)([A-Za-z_]\w*)(\s*;)/gm,(P,M,B,N,U,q)=>{const H=v.get(U);if(!H||T[H]>=T[B])return P;const G="xyzw",Y="rgba";return new RegExp("\\b"+U+"\\s*\\.\\s*["+G+Y+"]*["+G.slice(T[H])+Y.slice(T[H])+"]").test(l)?P:M+H+N+U+q})}{const v=new Map,k=/^\s*in\s+(?:highp|mediump|lowp\s+)?(vec[34])\s+([A-Za-z_]\w*)\s*;/gm;let A;for(;(A=k.exec(l))!==null;)v.set(A[2],Number(A[1].slice(3)));const T=new Map(v),S=/\b(vec[34])\s+([A-Za-z_]\w*)\s*[=;]/g;for(;(A=S.exec(l))!==null;)T.has(A[2])||T.set(A[2],Number(A[1].slice(3)));if(T.size>0){const P=M=>{const B=M.trim();if(!B)return M;const N=/^([A-Za-z_]\w*)$/.exec(B);if(N&&T.has(N[1]))return N[1]+".xy";const U=/^([A-Za-z_]\w*)(\s*[+\-].+)$/.exec(B);return U&&T.has(U[1])?"("+U[1]+".xy"+U[2]+")":M};for(const M of["textureLod","texture"])l=ut(l,M,B=>{const N=Wn(B);return N.length>=2&&(N[1]=P(N[1])),M+"("+N.join(", ")+")"})}v.size>0&&(l=l.split(`
|
|
19
|
+
`).map(P=>{if(!/\bvec2\s+[A-Za-z_]\w*\s*=/.test(P))return P;let M=P;for(const B of v.keys())M=M.replace(new RegExp("\\b"+B+"\\b(?!\\s*[.\\w])","g"),B+".xy");return M}).join(`
|
|
20
|
+
`))}const y=new Set,b=new Set;{const v=/^\s*in\s+(?:highp|mediump|lowp\s+)?(vec[234]|float)\s+([A-Za-z_]\w*)\s*;/gm;let k;for(;(k=v.exec(l))!==null;)b.add(k[2])}for(const v of b)new RegExp("\\b"+v+"\\b\\s*(?:\\.[xyzwrgba]{1,4})?\\s*(?:[-+*/]?=(?!=)|\\+\\+|--)").test(l)&&y.add(v);if(y.size>0){const v=l.search(/\bvoid\s+main\s*\([^)]*\)\s*\{/);if(v!==-1){const k=l.indexOf("{",v),A=l.slice(0,k+1);let T=l.slice(k+1);const S=[];for(const P of y){if(new RegExp("(?:^|[;{}\\n])\\s*(?:highp|mediump|lowp\\s+)?(?:vec[234]|float|int|bool)\\s+"+P+"\\s*[=;]").test(T))continue;const B=new RegExp("^\\s*in\\s+(?:highp|mediump|lowp\\s+)?(vec[234]|float)\\s+"+P+"\\s*;","m").exec(l),N=B?B[1]:"vec4";S.push(" "+N+" "+P+"_rw = "+P+";"),T=ns(T,P,P+"_rw")}S.length>0&&(T=`
|
|
21
|
+
`+S.map(P=>P.replace(/= (\w+)_rw;/,"= $1;")).join(`
|
|
16
22
|
`)+`
|
|
17
|
-
`+
|
|
18
|
-
`).map(
|
|
19
|
-
`)}f.length>0&&(l=l.replace(/\u0001(\u0002+)\u0001/g,(
|
|
20
|
-
`;return
|
|
21
|
-
`),
|
|
22
|
-
`,/\bgl_FragColor\b/.test(l)&&(
|
|
23
|
-
`,l=l.replace(/\bgl_FragColor\b/g,"fragColor"))),
|
|
23
|
+
`+T),l=A+T}}}l=l.replace(/\[(?:unroll|loop|branch|flatten)\]\s*/g,""),l=l.replace(/\bstatic\s+/g,""),d.length>0&&(l=l.replace(/\u0003(\u0004+)\u0003/g,(y,b)=>d[b.length-1]));{const y=new Set;for(const b of l.matchAll(/\b(?:uniform[ \t]+)?(?:highp|mediump|lowp)?[ \t]*float[ \t]+([A-Za-z_]\w*)[ \t]*[;=]/g))y.add(b[1]);if(y.size){const b=v=>{const k=v.trim().startsWith("-"),A=v.replace(/^-\s*/,"").trim();return y.has(A)?(k?"-":"")+"int("+A+")":v};l=l.replace(/(for\s*\(\s*(?:int|uint)\s+(\w+)\s*=\s*)(-?\s*[A-Za-z_]\w*|-?\s*\d+)(\s*;\s*\2\s*[<>]=?\s*)(-?\s*[A-Za-z_]\w*|-?\s*\d+)(\s*;)/g,(v,k,A,T,S,P,M)=>k+b(T)+S+b(P)+M)}}{const y=new Set;l=l.split(`
|
|
24
|
+
`).map(b=>{const v=/^[ \t]*uniform[ \t]+(?:highp|mediump|lowp[ \t]+)?[A-Za-z0-9_]+[ \t]+([A-Za-z_][A-Za-z0-9_]*)/.exec(b);if(!v)return b;const k=v[1];return y.has(k)?"":(y.add(k),b)}).join(`
|
|
25
|
+
`)}f.length>0&&(l=l.replace(/\u0001(\u0002+)\u0001/g,(y,b)=>f[b.length-1]));let w=`#version 300 es
|
|
26
|
+
`;return e==="vert"&&(w+=`precision highp float;
|
|
27
|
+
`),e==="frag"&&(w+=`precision highp float;
|
|
28
|
+
`,/\bgl_FragColor\b/.test(l)&&(w+=`out vec4 fragColor;
|
|
29
|
+
`,l=l.replace(/\bgl_FragColor\b/g,"fragColor"))),w+l}const Kf={center:[.5,.5],centre:[.5,.5],left:[0,.5],right:[1,.5],top:[.5,0],bottom:[.5,1],topleft:[0,0],topright:[1,0],bottomleft:[0,1],bottomright:[1,1]},Zf={2:"multiply",6:"additive",7:"screen",9:"additive",31:"additive"},H0={screen:1,multiply:2},Jf=`// WE common_blending.h\uFF08\u91CD\u5EFA\u5B50\u96C6\uFF09
|
|
30
|
+
vec3 weBlendOverlay(vec3 a, vec3 b) {
|
|
31
|
+
return vec3(
|
|
32
|
+
a.r < 0.5 ? 2.0 * a.r * b.r : 1.0 - 2.0 * (1.0 - a.r) * (1.0 - b.r),
|
|
33
|
+
a.g < 0.5 ? 2.0 * a.g * b.g : 1.0 - 2.0 * (1.0 - a.g) * (1.0 - b.g),
|
|
34
|
+
a.b < 0.5 ? 2.0 * a.b * b.b : 1.0 - 2.0 * (1.0 - a.b) * (1.0 - b.b));
|
|
35
|
+
}
|
|
36
|
+
vec3 weBlendSoftLight(vec3 a, vec3 b) {
|
|
37
|
+
return vec3(
|
|
38
|
+
b.r < 0.5 ? 2.0 * a.r * b.r + a.r * a.r * (1.0 - 2.0 * b.r) : sqrt(a.r) * (2.0 * b.r - 1.0) + 2.0 * a.r * (1.0 - b.r),
|
|
39
|
+
b.g < 0.5 ? 2.0 * a.g * b.g + a.g * a.g * (1.0 - 2.0 * b.g) : sqrt(a.g) * (2.0 * b.g - 1.0) + 2.0 * a.g * (1.0 - b.g),
|
|
40
|
+
b.b < 0.5 ? 2.0 * a.b * b.b + a.b * a.b * (1.0 - 2.0 * b.b) : sqrt(a.b) * (2.0 * b.b - 1.0) + 2.0 * a.b * (1.0 - b.b));
|
|
41
|
+
}
|
|
42
|
+
float weBlendVivid(float a, float b) {
|
|
43
|
+
if (b < 0.5) {
|
|
44
|
+
float bb = 2.0 * b;
|
|
45
|
+
return bb == 0.0 ? 0.0 : max(1.0 - (1.0 - a) / bb, 0.0);
|
|
46
|
+
}
|
|
47
|
+
float bb = 2.0 * (b - 0.5);
|
|
48
|
+
return bb == 1.0 ? 1.0 : min(a / (1.0 - bb), 1.0);
|
|
49
|
+
}
|
|
50
|
+
// Reflect \u5355\u72EC\u6210\u51FD\u6570\uFF1AGlow = Reflect(B,A)\u3002GLSL \u7981\u6B62\u9012\u5F52\uFF0C\u4E0D\u80FD\u5728 ApplyBlending
|
|
51
|
+
// \u5185\u90E8\u8C03 ApplyBlending(21, \u2026)\uFF08\u6574\u4E2A\u51FD\u6570\u4F1A\u7F16\u8BD1\u5931\u8D25\uFF0C\u6548\u679C\u88AB\u9759\u9ED8\u8DF3\u8FC7\uFF09\u3002
|
|
52
|
+
vec3 weBlendReflect(vec3 A, vec3 B) {
|
|
53
|
+
return vec3(
|
|
54
|
+
A.r == 1.0 ? 1.0 : min(B.r * B.r / (1.0 - A.r), 1.0),
|
|
55
|
+
A.g == 1.0 ? 1.0 : min(B.g * B.g / (1.0 - A.g), 1.0),
|
|
56
|
+
A.b == 1.0 ? 1.0 : min(B.b * B.b / (1.0 - A.b), 1.0));
|
|
57
|
+
}
|
|
58
|
+
vec3 RGBToHSL(vec3 c) {
|
|
59
|
+
float fmin = min(c.r, min(c.g, c.b));
|
|
60
|
+
float fmax = max(c.r, max(c.g, c.b));
|
|
61
|
+
float delta = fmax - fmin;
|
|
62
|
+
vec3 h = vec3(0.0);
|
|
63
|
+
h.z = (fmax + fmin) / 2.0;
|
|
64
|
+
if (delta == 0.0) {
|
|
65
|
+
h.x = 0.0;
|
|
66
|
+
h.y = 0.0;
|
|
67
|
+
} else {
|
|
68
|
+
h.y = h.z < 0.5 ? delta / (fmax + fmin) : delta / (2.0 - fmax - fmin);
|
|
69
|
+
float deltaR = ((fmax - c.r) / 6.0 + delta / 2.0) / delta;
|
|
70
|
+
float deltaG = ((fmax - c.g) / 6.0 + delta / 2.0) / delta;
|
|
71
|
+
float deltaB = ((fmax - c.b) / 6.0 + delta / 2.0) / delta;
|
|
72
|
+
if (c.r == fmax) h.x = deltaB - deltaG;
|
|
73
|
+
else if (c.g == fmax) h.x = 1.0 / 3.0 + deltaR - deltaB;
|
|
74
|
+
else if (c.b == fmax) h.x = 2.0 / 3.0 + deltaG - deltaB;
|
|
75
|
+
if (h.x < 0.0) h.x += 1.0;
|
|
76
|
+
else if (h.x > 1.0) h.x -= 1.0;
|
|
77
|
+
}
|
|
78
|
+
return h;
|
|
79
|
+
}
|
|
80
|
+
float weHueToRgb(float f1, float f2, float hue) {
|
|
81
|
+
if (hue < 0.0) hue += 1.0;
|
|
82
|
+
else if (hue > 1.0) hue -= 1.0;
|
|
83
|
+
if (6.0 * hue < 1.0) return f1 + (f2 - f1) * 6.0 * hue;
|
|
84
|
+
if (2.0 * hue < 1.0) return f2;
|
|
85
|
+
if (3.0 * hue < 2.0) return f1 + (f2 - f1) * ((2.0 / 3.0 - hue) * 6.0);
|
|
86
|
+
return f1;
|
|
87
|
+
}
|
|
88
|
+
vec3 HSLToRGB(vec3 h) {
|
|
89
|
+
if (h.y == 0.0) return vec3(h.z);
|
|
90
|
+
float f2 = h.z < 0.5 ? h.z * (1.0 + h.y) : h.z + h.y - h.y * h.z;
|
|
91
|
+
float f1 = 2.0 * h.z - f2;
|
|
92
|
+
return vec3(
|
|
93
|
+
weHueToRgb(f1, f2, h.x + 1.0 / 3.0),
|
|
94
|
+
weHueToRgb(f1, f2, h.x),
|
|
95
|
+
weHueToRgb(f1, f2, h.x - 1.0 / 3.0));
|
|
96
|
+
}
|
|
97
|
+
// mode \u7F16\u53F7\u540C WE common_blending.h\uFF080=Normal \u2026 32=LighterColor \u7684\u5B9E\u73B0\u5B50\u96C6\uFF09
|
|
98
|
+
vec3 ApplyBlending(int mode, vec3 A, vec3 B, float opacity) {
|
|
99
|
+
vec3 r;
|
|
100
|
+
if (mode == 1) { r = min(B, A); } // Darken
|
|
101
|
+
else if (mode == 2) { r = A * B; } // Multiply
|
|
102
|
+
else if (mode == 3) { // ColorBurn
|
|
103
|
+
r = vec3(
|
|
104
|
+
B.r == 0.0 ? 0.0 : max(1.0 - (1.0 - A.r) / B.r, 0.0),
|
|
105
|
+
B.g == 0.0 ? 0.0 : max(1.0 - (1.0 - A.g) / B.g, 0.0),
|
|
106
|
+
B.b == 0.0 ? 0.0 : max(1.0 - (1.0 - A.b) / B.b, 0.0));
|
|
107
|
+
}
|
|
108
|
+
else if (mode == 4 || mode == 20) { r = max(A + B - 1.0, vec3(0.0)); } // Substract
|
|
109
|
+
else if (mode == 5) { r = min(A, B); } // LinearBurn
|
|
110
|
+
else if (mode == 6) { r = max(B, A); } // Lighten
|
|
111
|
+
else if (mode == 7) { r = 1.0 - (1.0 - A) * (1.0 - B); } // Screen
|
|
112
|
+
else if (mode == 8) { // ColorDodge
|
|
113
|
+
r = vec3(
|
|
114
|
+
B.r == 1.0 ? 1.0 : min(A.r / (1.0 - B.r), 1.0),
|
|
115
|
+
B.g == 1.0 ? 1.0 : min(A.g / (1.0 - B.g), 1.0),
|
|
116
|
+
B.b == 1.0 ? 1.0 : min(A.b / (1.0 - B.b), 1.0));
|
|
117
|
+
}
|
|
118
|
+
else if (mode == 9) { r = min(A + B, vec3(1.0)); } // Add
|
|
119
|
+
else if (mode == 10) { r = max(A, B); } // Lighter
|
|
120
|
+
else if (mode == 11) { r = weBlendOverlay(A, B); } // Overlay
|
|
121
|
+
else if (mode == 12) { r = weBlendSoftLight(A, B); } // SoftLight
|
|
122
|
+
else if (mode == 13) { r = weBlendOverlay(B, A); } // HardLight
|
|
123
|
+
else if (mode == 14) { // VividLight
|
|
124
|
+
r = vec3(weBlendVivid(A.r, B.r), weBlendVivid(A.g, B.g), weBlendVivid(A.b, B.b));
|
|
125
|
+
}
|
|
126
|
+
else if (mode == 15) { // LinearLight
|
|
127
|
+
r = vec3(
|
|
128
|
+
B.r < 0.5 ? max(A.r + 2.0 * B.r - 1.0, 0.0) : min(A.r + 2.0 * (B.r - 0.5), 1.0),
|
|
129
|
+
B.g < 0.5 ? max(A.g + 2.0 * B.g - 1.0, 0.0) : min(A.g + 2.0 * (B.g - 0.5), 1.0),
|
|
130
|
+
B.b < 0.5 ? max(A.b + 2.0 * B.b - 1.0, 0.0) : min(A.b + 2.0 * (B.b - 0.5), 1.0));
|
|
131
|
+
}
|
|
132
|
+
else if (mode == 16) { // PinLight
|
|
133
|
+
r = vec3(
|
|
134
|
+
B.r < 0.5 ? min(A.r, 2.0 * B.r) : max(A.r, 2.0 * (B.r - 0.5)),
|
|
135
|
+
B.g < 0.5 ? min(A.g, 2.0 * B.g) : max(A.g, 2.0 * (B.g - 0.5)),
|
|
136
|
+
B.b < 0.5 ? min(A.b, 2.0 * B.b) : max(A.b, 2.0 * (B.b - 0.5)));
|
|
137
|
+
}
|
|
138
|
+
else if (mode == 17) { // HardMix
|
|
139
|
+
r = vec3(
|
|
140
|
+
weBlendVivid(A.r, B.r) < 0.5 ? 0.0 : 1.0,
|
|
141
|
+
weBlendVivid(A.g, B.g) < 0.5 ? 0.0 : 1.0,
|
|
142
|
+
weBlendVivid(A.b, B.b) < 0.5 ? 0.0 : 1.0);
|
|
143
|
+
}
|
|
144
|
+
else if (mode == 18) { r = abs(A - B); } // Difference
|
|
145
|
+
else if (mode == 19) { r = A + B - 2.0 * A * B; } // Exclusion
|
|
146
|
+
else if (mode == 21) { r = weBlendReflect(A, B); } // Reflect
|
|
147
|
+
else if (mode == 22) { r = weBlendReflect(B, A); } // Glow = Reflect(B,A)
|
|
148
|
+
else if (mode == 23) { r = min(A, B) - max(A, B) + 1.0; } // Phoenix
|
|
149
|
+
else if (mode == 24) { r = (A + B) / 2.0; } // Average
|
|
150
|
+
else if (mode == 25) { r = 1.0 - abs(1.0 - A - B); } // Negation
|
|
151
|
+
else if (mode == 26) { r = HSLToRGB(vec3(RGBToHSL(B).x, RGBToHSL(A).y, RGBToHSL(A).z)); } // Hue
|
|
152
|
+
else if (mode == 27) { r = HSLToRGB(vec3(RGBToHSL(A).x, RGBToHSL(B).y, RGBToHSL(A).z)); } // Saturation
|
|
153
|
+
else if (mode == 28) { r = HSLToRGB(vec3(RGBToHSL(B).x, RGBToHSL(B).y, RGBToHSL(A).z)); } // Color
|
|
154
|
+
else if (mode == 29) { r = HSLToRGB(vec3(RGBToHSL(A).x, RGBToHSL(A).y, RGBToHSL(B).z)); } // Luminosity
|
|
155
|
+
else if (mode == 30) { r = mix(A, max(max(A.r, max(A.g, A.b)), 0.0) * B, opacity); } // Tint
|
|
156
|
+
else if (mode == 31) { r = A + B * opacity; } // Add(\u5E26 opacity \u6743\u91CD)
|
|
157
|
+
else if (mode == 32) { r = mix(A, A + A * B, opacity); } // LinearDodge \u53D8\u4F53
|
|
158
|
+
else { r = mix(A, B, opacity); } // Normal(\u542B 0)
|
|
159
|
+
// CPU \u53C2\u8003\uFF08effects.js applyBlending\uFF09\uFF1A5/10/30/31/32 \u76F4\u63A5\u8FD4\u56DE\u4E0D\u7ECF opacity \u6743\u91CD\uFF0C
|
|
160
|
+
// \u5176\u4F59\u7EDF\u4E00 mix(A, r, opacity) \u56DE\u5F52\u539F\u8272\u3002
|
|
161
|
+
//
|
|
162
|
+
// [we-scene patch] **mode 0 \u4E5F\u5FC5\u987B\u6392\u9664**\uFF1A\u5B83\u7684\u5206\u652F\u5DF2\u7ECF\u662F mix(A, B, opacity)\uFF0C
|
|
163
|
+
// \u518D\u5957\u4E00\u5C42\u7B49\u4E8E\u6309 opacity\xB2 \u52A0\u6743\u3002effects.js \u7684 default \u5206\u652F\u662F switch \u5185\u76F4\u63A5
|
|
164
|
+
// return mix3(A, B, opacity)\u3001\u4E0D\u8D70 per() \u7684\u4E8C\u6B21\u52A0\u6743\uFF0C\u8FD9\u91CC\u6F0F\u6392\u4E86 0\u3002
|
|
165
|
+
// \u75C7\u72B6\u6781\u9690\u853D\uFF1Axray \u7684\u4E24\u5F20\u56FE\u662F\u540C\u4E00\u6784\u56FE\u7684\u4E0D\u540C\u7248\u672C\uFF08A\u2248B\uFF09\uFF0C\u5E73\u65B9\u540E\u5DEE\u5F02\u88AB\u538B\u5230
|
|
166
|
+
// \u8089\u773C\u4E0E readPixels \u90FD\u8BFB\u4E0D\u51FA\uFF08\u5B9E\u6D4B 6 \u4E2A xray \u58C1\u7EB8\u50CF\u7D20\u5DEE\u6070\u597D\u4E3A 0\uFF0C
|
|
167
|
+
// \u800C\u628A\u6700\u7EC8\u8F93\u51FA\u6362\u6210\u4E2D\u95F4\u91CF\u7684\u63A2\u9488\u663E\u793A blend=187\u3001sprite=187\u3001mask.a=255 \u5168\u90FD\u6B63\u5E38\uFF09\u3002
|
|
168
|
+
// \u6CE8\u610F\u672C\u6587\u4EF6\u662F TS \u6A21\u677F\u5B57\u7B26\u4E32\uFF0C\u6CE8\u91CA\u91CC\u4E0D\u80FD\u51FA\u73B0\u53CD\u5F15\u53F7\u3002
|
|
169
|
+
if (mode != 0 && mode != 5 && mode != 10 && mode != 30 && mode != 31 && mode != 32) {
|
|
170
|
+
r = mix(A, r, opacity);
|
|
171
|
+
}
|
|
172
|
+
return r;
|
|
173
|
+
}`,V0=`#version 300 es
|
|
174
|
+
precision mediump float;
|
|
175
|
+
in vec2 v_UV;
|
|
176
|
+
uniform sampler2D u_Tex;
|
|
177
|
+
uniform sampler2D u_Backdrop;
|
|
178
|
+
uniform int u_BlendMode;
|
|
179
|
+
uniform vec2 u_CanvasSize;
|
|
180
|
+
uniform float u_Opacity;
|
|
181
|
+
out vec4 fragColor;
|
|
182
|
+
${Jf}
|
|
183
|
+
void main() {
|
|
184
|
+
vec4 src = texture(u_Tex, v_UV);
|
|
185
|
+
// \u80CC\u666F\u6309**\u7247\u5143\u7684\u5C4F\u5E55\u4F4D\u7F6E**\u91C7\u6837\uFF1Agl_FragCoord \u539F\u70B9\u5728\u5DE6\u4E0B\uFF0C\u4E0E copyTexImage2D
|
|
186
|
+
// \u5F97\u5230\u7684\u7EB9\u7406\u5750\u6807\u7CFB\u4E00\u81F4\uFF0C\u76F4\u63A5\u9664\u753B\u5E03\u5C3A\u5BF8\u5373\u53EF\uFF08\u4E0D\u8981\u590D\u7528 v_UV \u2014\u2014 \u90A3\u662F\u5C42 UV\uFF09\u3002
|
|
187
|
+
vec3 dst = texture(u_Backdrop, gl_FragCoord.xy / u_CanvasSize).rgb;
|
|
188
|
+
vec3 r = ApplyBlending(u_BlendMode, dst, src.rgb, src.a * u_Opacity);
|
|
189
|
+
// GL \u6DF7\u5408\u5DF2\u5173\u95ED\uFF1A\u8FD9\u91CC\u5199\u51FA\u7684\u5C31\u662F\u6700\u7EC8\u50CF\u7D20\uFF0Calpha \u6052 1\uFF08\u753B\u5E03\u65E0 alpha \u901A\u9053\uFF09\u3002
|
|
190
|
+
fragColor = vec4(r, 1.0);
|
|
191
|
+
}`,W0=`#version 300 es
|
|
192
|
+
in vec3 a_Position;
|
|
193
|
+
in vec2 a_TexCoord;
|
|
194
|
+
uniform vec2 u_Texel; // 1/\u573A\u666F\u7EB9\u7406\u5C3A\u5BF8
|
|
195
|
+
uniform float u_Damp; // Feather\uFF08\u6750\u8D28\u539F\u5B57\u6BB5 "Damp brightness"\uFF0C\u9ED8\u8BA4 0.5\uFF09
|
|
196
|
+
out vec2 v_TexCoord[4];
|
|
197
|
+
out float v_Damp;
|
|
198
|
+
void main() {
|
|
199
|
+
v_Damp = 1.0 + u_Damp * 0.1;
|
|
200
|
+
gl_Position = vec4(a_Position, 1.0);
|
|
201
|
+
vec2 offsets = u_Texel;
|
|
202
|
+
v_TexCoord[0] = a_TexCoord - offsets;
|
|
203
|
+
v_TexCoord[1] = a_TexCoord + vec2(offsets.x, -offsets.y);
|
|
204
|
+
v_TexCoord[2] = a_TexCoord + vec2(-offsets.x, offsets.y);
|
|
205
|
+
v_TexCoord[3] = a_TexCoord + offsets;
|
|
206
|
+
}`,j0=`#version 300 es
|
|
207
|
+
precision mediump float;
|
|
208
|
+
in vec2 v_TexCoord[4];
|
|
209
|
+
in float v_Damp;
|
|
210
|
+
uniform sampler2D u_Tex;
|
|
211
|
+
uniform float u_Alpha;
|
|
212
|
+
uniform float u_Strength;
|
|
213
|
+
uniform float u_Threshold;
|
|
214
|
+
// 0 = \u7ECF\u5178\u5BB6\u65CF\uFF08WE \u5F15\u64CE downsample_quarter_bloom \u9010\u884C\u8F6C\u5199\uFF09
|
|
215
|
+
// 1 = HDR \u5BB6\u65CF\uFF08bloomhdr*\uFF09\u7684 SDR \u7B49\u6548\u5224\u5B9A\uFF0C\u89C1 renderer.js bloomPostParams \u6CE8\u91CA
|
|
216
|
+
uniform int u_Metric;
|
|
217
|
+
out vec4 fragColor;
|
|
218
|
+
void main() {
|
|
219
|
+
vec3 lightMap = vec3(0.0);
|
|
220
|
+
if (u_Strength > 0.001 && u_Alpha > 0.001) {
|
|
221
|
+
if (u_Metric == 0) {
|
|
222
|
+
// \u5F15\u64CE\u539F\u6587\uFF1A4 \u62BD\u5934\u5E73\u5747 \u2192 saturate(max \u901A\u9053 - threshold) \u8F6F\u62D0\u70B9
|
|
223
|
+
// \u2192 \u9971\u548C\u5EA6 \xD72\uFF08-grayscale*sat + albedo*(1+sat)\uFF0Csat=1\uFF09\u2192 \xD7strength\uFF08\u4E00\u6B21\uFF09\u3002
|
|
224
|
+
// saturate \u5728 GLSL \u4E0D\u5B58\u5728\uFF0Cclamp(x,0,1) \u7B49\u4EF7\u3002
|
|
225
|
+
vec3 albedo = texture(u_Tex, v_TexCoord[0]).rgb +
|
|
226
|
+
texture(u_Tex, v_TexCoord[1]).rgb +
|
|
227
|
+
texture(u_Tex, v_TexCoord[2]).rgb +
|
|
228
|
+
texture(u_Tex, v_TexCoord[3]).rgb;
|
|
229
|
+
albedo *= 0.25;
|
|
230
|
+
float scale = max(max(albedo.x, albedo.y), albedo.z);
|
|
231
|
+
albedo *= clamp(scale - u_Threshold, 0.0, 1.0);
|
|
232
|
+
float grayscale = dot(vec3(0.2989, 0.5870, 0.1140), albedo);
|
|
233
|
+
albedo = -grayscale + albedo * 2.0;
|
|
234
|
+
lightMap = max(vec3(0.0), albedo * u_Strength);
|
|
235
|
+
} else {
|
|
236
|
+
// HDR \u5BB6\u65CF\u65E2\u6709\u6821\u51C6\uFF082646504847\uFF09\uFF1Araw sRGB \u4EAE\u5EA6 + \u8F6F\u7A97\u53E3\u3002
|
|
237
|
+
// strength \u5728\u6B64\u4E58\u4E24\u6B21\uFF0C\u8865\u507F blur \u4E0D\u518D\u4E58\uFF08\u4E0E\u65E7\u884C\u4E3A\u9010\u4F4D\u4E00\u81F4\uFF09\u3002
|
|
238
|
+
float weight = 0.0;
|
|
239
|
+
vec3 samplec;
|
|
240
|
+
for (int i = 0; i < 4; ++i) {
|
|
241
|
+
samplec = texture(u_Tex, v_TexCoord[i]).rgb;
|
|
242
|
+
float w = smoothstep(u_Threshold - 0.2, u_Threshold + 0.4, dot(samplec, vec3(0.2126, 0.7152, 0.0722)));
|
|
243
|
+
lightMap += samplec * w;
|
|
244
|
+
weight += w;
|
|
245
|
+
}
|
|
246
|
+
lightMap = lightMap * max(0.001, mix(weight, 1.0, v_Damp)) / 4.0 * u_Strength * u_Strength;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
fragColor = vec4(lightMap, 1.0);
|
|
250
|
+
}`,q0=`#version 300 es
|
|
251
|
+
in vec3 a_Position;
|
|
252
|
+
in vec2 a_TexCoord;
|
|
253
|
+
uniform vec2 u_Texel; // 1/\u6E90\u7EB9\u7406\u5C3A\u5BF8
|
|
254
|
+
uniform vec2 u_Res; // \u6E90\u7EB9\u7406\u5C3A\u5BF8
|
|
255
|
+
uniform float u_Radius; // Scatter
|
|
256
|
+
out vec2 v_TexCoord;
|
|
257
|
+
out vec2 v_SizeMultiplier;
|
|
258
|
+
void main() {
|
|
259
|
+
vec2 ratio = u_Res * u_Texel;
|
|
260
|
+
v_SizeMultiplier = u_Texel * vec2(1.0, ratio.x / ratio.y) * u_Radius;
|
|
261
|
+
gl_Position = vec4(a_Position, 1.0);
|
|
262
|
+
v_TexCoord = a_TexCoord;
|
|
263
|
+
}`,X0=`#version 300 es
|
|
264
|
+
precision mediump float;
|
|
265
|
+
in vec2 v_TexCoord;
|
|
266
|
+
in vec2 v_SizeMultiplier;
|
|
267
|
+
uniform sampler2D u_Tex;
|
|
268
|
+
uniform float u_Alpha;
|
|
269
|
+
uniform float u_Strength;
|
|
270
|
+
uniform float u_Iterations;
|
|
271
|
+
uniform vec2 u_Dir; // (1,0)=\u6A2A\u5411 / (0,1)=\u7EB5\u5411
|
|
272
|
+
out vec4 fragColor;
|
|
273
|
+
void main() {
|
|
274
|
+
vec4 albedo = vec4(0.0);
|
|
275
|
+
if (u_Strength > 0.001 && u_Alpha > 0.001) {
|
|
276
|
+
float divisor = 0.0, weight, n;
|
|
277
|
+
float iterations = u_Iterations;
|
|
278
|
+
for (int i = -15; i <= 15; i++) {
|
|
279
|
+
if (abs(float(i)) > iterations) continue;
|
|
280
|
+
n = float(i);
|
|
281
|
+
vec2 offset = u_Dir * (n * v_SizeMultiplier);
|
|
282
|
+
weight = exp(-abs(n) * 0.1);
|
|
283
|
+
divisor += weight;
|
|
284
|
+
albedo += texture(u_Tex, v_TexCoord + offset) * weight;
|
|
285
|
+
}
|
|
286
|
+
// \u6A21\u7CCA\u53EA\u505A\u80FD\u91CF\u5B88\u6052\u5F52\u4E00\uFF1Astrength \u5DF2\u5728\u4EAE\u90E8\u63D0\u53D6\u6BB5\u4E58\u8FC7\uFF08\u5F15\u64CE\u539F\u7248
|
|
287
|
+
// downsample_eighth_blur_v / blur_h_bloom \u540C\u6837\u4E0D\u4E58 strength\uFF09\u3002
|
|
288
|
+
// 2026-09-11 \u524D\u8FD9\u91CC\u6A2A/\u7EB5\u4E24\u8D9F\u5404\u4E58\u4E00\u6B21 \u2192 strength\xB2 \u53E0\u6EE1\u5168\u5C4F\u3002
|
|
289
|
+
albedo = albedo / divisor;
|
|
290
|
+
}
|
|
291
|
+
fragColor = albedo;
|
|
292
|
+
}`,G0=`#version 300 es
|
|
293
|
+
precision mediump float;
|
|
294
|
+
in vec2 v_UV;
|
|
295
|
+
uniform sampler2D u_Tex; // \u6A21\u7CCA\u540E\u7684 bloom
|
|
296
|
+
uniform float u_Alpha;
|
|
297
|
+
uniform float u_Strength;
|
|
298
|
+
uniform vec3 u_Tint;
|
|
299
|
+
out vec4 fragColor;
|
|
300
|
+
void main() {
|
|
301
|
+
vec3 bloom = texture(u_Tex, v_UV).rgb * u_Tint * u_Alpha;
|
|
302
|
+
if (u_Strength <= 0.001) bloom = vec3(0.0);
|
|
303
|
+
// Add\uFF08ApplyBlending 31\uFF09\uFF1Argb = base + bloom\uFF1BGL \u4FA7 blendFunc(ONE, ONE)\uFF0C
|
|
304
|
+
// dst \u5C31\u662F\u753B\u5E03\u91CC\u7684 base\u3002alpha +0 = \u4FDD\u6301\u573A\u666F alpha\uFF08\u753B\u5E03\u672C\u5C31\u65E0 alpha \u901A\u9053\uFF09\u3002
|
|
305
|
+
fragColor = vec4(bloom, 0.0);
|
|
306
|
+
}`,is=`#version 300 es
|
|
24
307
|
in vec3 a_Position;
|
|
25
308
|
in vec2 a_TexCoord;
|
|
26
309
|
uniform mat4 u_MVP;
|
|
@@ -28,7 +311,7 @@ out vec2 v_UV;
|
|
|
28
311
|
void main() {
|
|
29
312
|
gl_Position = u_MVP * vec4(a_Position, 1.0);
|
|
30
313
|
v_UV = a_TexCoord;
|
|
31
|
-
}
|
|
314
|
+
}`,$0=`#version 300 es
|
|
32
315
|
precision mediump float;
|
|
33
316
|
in vec2 v_UV;
|
|
34
317
|
uniform sampler2D u_Tex;
|
|
@@ -44,7 +327,7 @@ void main() {
|
|
|
44
327
|
if (u_BlendPrep == 1) c.rgb *= c.a;
|
|
45
328
|
else if (u_BlendPrep == 2) c.rgb = mix(vec3(1.0), c.rgb, c.a);
|
|
46
329
|
fragColor = c;
|
|
47
|
-
}`,
|
|
330
|
+
}`,Q0=`#version 300 es
|
|
48
331
|
precision mediump float;
|
|
49
332
|
in vec2 v_UV;
|
|
50
333
|
uniform sampler2D u_Tex;
|
|
@@ -55,15 +338,15 @@ void main() {
|
|
|
55
338
|
if (u_BlendPrep == 1) c.rgb *= c.a;
|
|
56
339
|
else if (u_BlendPrep == 2) c.rgb = mix(vec3(1.0), c.rgb, c.a);
|
|
57
340
|
fragColor = c;
|
|
58
|
-
}`,
|
|
341
|
+
}`,Y0=`#version 300 es
|
|
59
342
|
precision mediump float;
|
|
60
343
|
in vec2 v_UV;
|
|
61
344
|
uniform sampler2D u_Tex;
|
|
62
345
|
out vec4 fragColor;
|
|
63
346
|
void main() {
|
|
64
347
|
fragColor = vec4(texture(u_Tex, v_UV).rgb, 1.0);
|
|
65
|
-
}`;function Fa(e,n){return new Float32Array([0,n,0,0,1,0,0,0,0,0,e,n,0,1,1,e,n,0,1,1,0,0,0,0,0,e,0,0,1,0])}function Na(){return new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,1,0,1,1,-1,-1,0,0,0,1,-1,0,1,0])}function Ua(){return new Float32Array([-.5,.5,0,0,1,-.5,-.5,0,0,0,.5,.5,0,1,1,.5,.5,0,1,1,-.5,-.5,0,0,0,.5,-.5,0,1,0])}const Da={5126:"float",35664:"vec2",35665:"vec3",35666:"vec4",5124:"int",35667:"ivec2",35668:"ivec3",35669:"ivec4",35670:"bool",35676:"mat4",35675:"mat3"};function ir(e,n,t){const r=Go(e,e.VERTEX_SHADER,n),o=Go(e,e.FRAGMENT_SHADER,t),i=e.createProgram();if(e.attachShader(i,r),e.attachShader(i,o),e.bindAttribLocation(i,0,"a_Position"),e.bindAttribLocation(i,1,"a_TexCoord"),e.linkProgram(i),!e.getProgramParameter(i,e.LINK_STATUS))throw new Error("\u7740\u8272\u5668\u94FE\u63A5\u5931\u8D25: "+e.getProgramInfoLog(i));return i}function Go(e,n,t){const r=e.createShader(n);if(e.shaderSource(r,t),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS))throw new Error("\u7740\u8272\u5668\u7F16\u8BD1\u5931\u8D25: "+e.getShaderInfoLog(r));return r}function Yo(e){e!==null&&typeof e=="object"&&"value"in e&&(e=e.value);const n=String(e??"").trim().split(/\s+/).map(Number);return[n[0]||0,n[1]||0,n[2]||0]}function jr(e,n,t,r,o=null){const i=e.createTexture();return e.bindTexture(e.TEXTURE_2D,i),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),o?e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,o):e.texImage2D(e.TEXTURE_2D,0,e.RGBA,t,r,0,e.RGBA,e.UNSIGNED_BYTE,n),i}function Ba(e,n,t=!1){const r=e.createTexture();e.bindTexture(e.TEXTURE_2D,r),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR);const o=n[0];if(o.bitmap)e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,o.bitmap);else if(t&&o.rgba){const i=o.width*o.height,s=new Uint8Array(i*2);for(let c=0;c<i;c++)s[c*2]=o.rgba[c*4+3],s[c*2+1]=o.rgba[c*4];const a=e.getParameter(e.UNPACK_ALIGNMENT);e.pixelStorei(e.UNPACK_ALIGNMENT,1),e.texImage2D(e.TEXTURE_2D,0,e.RG8,o.width,o.height,0,e.RG,e.UNSIGNED_BYTE,s),e.pixelStorei(e.UNPACK_ALIGNMENT,a)}else e.texImage2D(e.TEXTURE_2D,0,e.RGBA,o.width,o.height,0,e.RGBA,e.UNSIGNED_BYTE,o.rgba);return e.generateMipmap(e.TEXTURE_2D),r}function zr(e,n,t,r,o){const i=1-o;return i*i*i*e+3*i*i*o*n+3*i*o*o*t+o*o*o*r}function Ia(e,n,t,r,o){if(o<=e)return 0;if(o>=r)return 1;let i=r-e>1e-9?(o-e)/(r-e):.5;for(let c=0;c<8;c++){const u=zr(e,n,t,r,i)-o;if(Math.abs(u)<1e-6)return i;const l=1-i,f=3*l*l*(n-e)+6*l*i*(t-n)+3*i*i*(r-t);if(Math.abs(f)<1e-9)break;const p=i-u/f;if(p<0||p>1||!Number.isFinite(p))break;i=p}let s=0,a=1;for(let c=0;c<40;c++)i=(s+a)/2,zr(e,n,t,r,i)<o?s=i:a=i;return i}function sr(e,n,t){if(!e||e.length===0)return 0;if(e.length===1)return Number(e[0].value)||0;if(t&&t.length>0){const N=e[0],j=e[e.length-1],H=t.length-j.frame;if(H>1e-9&&n>j.frame&&n<=t.length)return sr([{frame:0,value:j.value,front:j.front,back:j.back},{frame:H,value:N.value,front:N.front,back:N.back}],n-j.frame)}if(n<=e[0].frame)return Number(e[0].value)||0;const r=e[e.length-1];if(n>=r.frame)return Number(r.value)||0;let o=0,i=e.length-1;for(;i-o>1;){const N=o+i>>1;e[N].frame<=n?o=N:i=N}const s=e[o],a=e[i],c=s.frame,u=a.frame,l=Number(s.value)||0,f=Number(a.value)||0,p=u-c;if(p<=0)return f;const d=s.front,y=a.back,x=p/3,m=!!(d&&d.enabled),M=!!(y&&y.enabled),h=m?Math.abs(Number(d.x)||0):1,g=M?Math.abs(Number(y.x)||0):1,v=c+Math.min(h,1.5)*x,A=u-Math.min(g,1.5)*x,_=m?l+(Number(d.y)||0):l+(f-l)/3,R=M?f+(Number(y.y)||0):f-(f-l)/3,L=Ia(c,v,A,u,n);return zr(l,_,R,f,L)}function qo(e,n,t){const r=n>0?n:1;if(t==="loop"){let o=e%r;return o<0&&(o+=r),o}if(t==="mirror"){const o=r*2;let i=e%o;return i<0&&(i+=o),i<=r?i:o-i}return Math.max(0,Math.min(r,e))}function Oa(e){return Array.isArray(e)?e:typeof e=="string"?e.trim().split(/\s+/).map(Number):Number.isFinite(e)?[e]:[]}function Zo(e){const n=e&&e.options||{},t=Number(n.fps)>0?Number(n.fps):30,r=Number(n.length)>0?Number(n.length):0,o=n.mode==="loop"||n.mode==="mirror"?n.mode:"single",i=typeof n.name=="string"?n.name:"",s=!!(e&&e.relative),a=n.wraploop===!0&&o==="loop",c=[];for(let p=0;;p++){const d=e&&e["c"+p];if(!Array.isArray(d))break;c.push(d)}const u=n.startpaused!==!0,l=[],f={name:i,mode:o,fps:t,relative:s,channelCount:c.length,frame:0,rate:1,playing:u,ended:!1,get frameCount(){return r},play(){return f.playing=!0,f.ended=!1,f},pause(){return f.playing=!1,f},stop(){return f.playing=!1,f.frame=0,f.ended=!1,f},setFrame(p){const d=Number(p);return Number.isFinite(d)&&(f.frame=d),f},getFrame(){return f.frame},setRate(p){const d=Number(p);return Number.isFinite(d)&&(f.rate=d),f},addEndedCallback(p){return typeof p=="function"&&l.push(p),f},setBlend(){return f},setVisible(){return f},advance(p){if(f.playing&&(f.frame+=(Number(p)||0)*t*f.rate,o==="single"))if(f.frame>=r){if(f.frame=r,f.playing=!1,!f.ended){f.ended=!0;for(const d of l)try{d()}catch{}}}else f.frame<0&&(f.frame=0,f.playing=!1)},value(){const p=qo(f.frame,r,o),d=a?{length:r}:void 0;if(c.length===1)return sr(c[0],p,d);const y=[];for(const x of c)y.push(sr(x,p,d));return y},applyTo(p){const d=f.value();if(!s)return d;const y=Oa(p);return Array.isArray(d)?d.map((x,m)=>x+(Number(y[m])||0)):d+(Number(y[0])||0)}};return f}function $a(){const e={name:"",mode:"single",fps:30,relative:!1,channelCount:0,frame:0,rate:1,playing:!1,ended:!1,get frameCount(){return 0},play(){return e},pause(){return e},stop(){return e},setFrame(){return e},getFrame(){return 0},setRate(){return e},addEndedCallback(){return e},setBlend(){return e},setVisible(){return e},advance(){},value(){return 0},applyTo(n){return n}};return e}const ja=Object.freeze(Object.defineProperty({__proto__:null,createAnimation:Zo,createNeutralAnimation:$a,sampleChannel:sr,wrapFrame:qo},Symbol.toStringTag,{value:"Module"}));function Ko(e){const n=e&&e.puppet&&e.puppet.animBound;return n?[n.x*Math.abs(e.scale[0]),n.y*Math.abs(e.scale[1])]:[0,0]}function Qo(e){for(const n of e&&e.effects||[]){if(n.visible===!1)continue;const t=Math.max((n.passes||[]).length,(n.materialPasses||[]).length);for(let r=0;r<t;r++){const o=n.passes&&n.passes[r]&&n.passes[r].combos||{},i=n.materialPasses&&n.materialPasses[r]&&n.materialPasses[r].combos||{},s=o.TRANSPARENCY!==void 0?o.TRANSPARENCY:i.TRANSPARENCY;if(Number(s)===0)return!0}}return!1}function ar(e,n,t){if(t||(t=new Set),!n)return t;for(const r of e.childIds||[]){const o=n.get(r);!o||o.particle||o.isPostProcess||(t.add(r),ar(o,n,t))}return t}function Wr(e){const n=Pa[e]||"translucent";return{mode:n,prep:Ca[n]||0}}function za(e,n,t,r){const{mode:o,prep:i}=Wr(e);let s=t;return i===1?s=t*r:i===2&&(s=1-r+t*r),o==="screen"?s+n*(1-s):o==="multiply"?n*s:o==="additive"?n+t*r:n*(1-r)+t*r}function Jo(e,n,t){const r=e&&Number(e.scale)||1;let o=Math.max(1,Math.round(n/r)),i=Math.max(1,Math.round(t/r));const s=e&&Number(e.fit);if(Number.isFinite(s)&&s>0){const a=Math.max(o,i);if(a>s){const c=s/a;o=Math.max(1,Math.round(o*c)),i=Math.max(1,Math.round(i*c))}}return[o,i]}function Wa(e){const n=Number(e);return!Number.isFinite(n)||n<.001?999:1/n}const Ln=-1;function Vr(e,n){return!!n&&!e}const Va="mix(999.0, 1.0 / max(g_PointerScale, 0.001), step(0.001, g_PointerScale))";function ei(e){if(typeof e!="string"||/unprojectedUVs\s*\*=\s*mix\(999\.0,\s*1\.0\s*\/\s*max\(\s*g_PointerScale/.test(e))return e;const n=/unprojectedUVs\s*\*=\s*v_PointerScale\s*\*/.test(e),t=/unprojectedUVs\s*\*=\s*g_PointerScale\s*\*/.test(e);if(!n&&!t)return e;let r=e;/uniform\s+float\s+g_PointerScale\b/.test(r)||(r=r.replace(/void\s+main\s*\(/,`uniform float g_PointerScale;
|
|
66
|
-
void main(`));const o=n?/unprojectedUVs\s*\*=\s*v_PointerScale\s*\*/:/unprojectedUVs\s*\*=\s*g_PointerScale\s*\*/;return r.replace(o,"unprojectedUVs *= "+Va+" *")}const ti=1;function ni(e,n){return e==="g_PointerScale"?ti:n}function Ha(e,n={}){const t=e.getContext("webgl2",{premultipliedAlpha:!1,antialias:!1,alpha:!1,preserveDrawingBuffer:!0});if(!t)throw new Error("\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301 WebGL2");const r=n.shaderResolver||(async()=>null),o=n.diag||(()=>{}),i=typeof document<"u"?document.createElement("canvas"):null;i&&(i.style.cssText="position:fixed;left:-9999px;top:-9999px;width:2px;height:2px;opacity:0");let s=!1,a=n.fboCapFactor===void 0?0:n.fboCapFactor,c=null,u=null,l=null;const f=[["g_AudioSpectrum16Left","left16"],["g_AudioSpectrum16Right","right16"],["g_AudioSpectrum32Left","left32"],["g_AudioSpectrum32Right","right32"],["g_AudioSpectrum64Left","left64"],["g_AudioSpectrum64Right","right64"]];function p(w){l=w||null}let d=null,y=null,x=null,m=null,M=null,h=null,g=null;const v=new Map,A=new Map,_={total:0,ok:0,failed:0};function R(w,U){d=typeof w=="function"?w:null,y=U&&U.userProperties||null,x=U&&U.audioViews||null,m=U&&U.shared||null,M=U&&U.inputView||null,h=U&&U.timers||null,g=U&&typeof U.onSandbox=="function"?U.onSandbox:null,v.clear(),A.clear()}let L=!1;const N=ir(t,$r,La),j=ir(t,$r,Ra),H=ir(t,$r,ka),K=t.createVertexArray();t.bindVertexArray(K);const O=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,O),t.enableVertexAttribArray(0),t.vertexAttribPointer(0,3,t.FLOAT,!1,20,0),t.enableVertexAttribArray(1),t.vertexAttribPointer(1,2,t.FLOAT,!1,20,12),t.bindVertexArray(null);const V=new Map;let X=1;function ie(w,U,G){const W=(G||"")+"|"+w+"x"+U;if(V.has(W)){const b=V.get(W);return b.stamp=X,b}const Y=t.createFramebuffer(),ee=t.createTexture();t.bindTexture(t.TEXTURE_2D,ee),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,w,U,0,t.RGBA,t.UNSIGNED_BYTE,null),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.bindFramebuffer(t.FRAMEBUFFER,Y),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,ee,0),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindFramebuffer(t.FRAMEBUFFER,null);const oe={fbo:Y,tex:ee,width:w,height:U,stamp:X};return V.set(W,oe),oe}function J(){for(const[w,U]of V)U.stamp!==X&&(U.fbo&&t.deleteFramebuffer(U.fbo),U.tex&&t.deleteTexture(U.tex),V.delete(w))}const Z=new Map,te=new Map,le=new Map;function Ue(w){const U={},G=/uniform\s+[A-Za-z0-9_]+\s+([A-Za-z_][A-Za-z0-9_]*)[^;]*;\s*\/\/([^\n]*)/g;let W;for(;(W=G.exec(w))!==null;){const Y=W[1],ee=W[2],oe=/"material"\s*:\s*"([^"]+)"/.exec(ee);if(!oe)continue;const b=/"default"\s*:\s*("(?:[^"]*)"|-?\d+(?:\.\d+)?)/.exec(ee);U[oe[1]]={uniform:Y,default:b?Xe(b[1]):void 0}}return U}function _e(w){const U=new Map,G=/uniform\s+sampler2D\s+g_Texture(\d+)\s*;\s*\/\/([^\n]*)/g;let W;for(;(W=G.exec(w))!==null;){const Y=Number(W[1]),ee=/"default"\s*:\s*"([^"]+)"/.exec(W[2]);ee&&ee[1]&&U.set(Y,ee[1])}return U}function Ze(w){const U=[],G=/uniform\s+sampler2D\s+(g_Texture(\d+))[^;]*;\s*\/\/([^\n]*)/g;let W;for(;(W=G.exec(w))!==null;){const Y=/"combo"\s*:\s*"([^"]+)"/.exec(W[3]);Y&&U.push({slot:Number(W[2]),name:W[1],combo:Y[1]})}return U}function Xe(w){if(w.startsWith('"'))return w.slice(1,-1);const U=Number(w);return Number.isFinite(U)?U:void 0}async function De(w,U,G){let W=le.get(w);if(W===void 0){const oe=await r("shaders/"+w+".frag")||"",b=await r("shaders/"+w+".vert")||"";W={frag:oe,vert:b,texCombos:Ze(oe)},le.set(w,W)}const Y={...U};for(const oe of W.texCombos)G&&G[oe.slot]&&Y[oe.combo]===void 0&&(Y[oe.combo]=1);const ee=w+"|"+JSON.stringify(Y);if(Z.has(ee)){const oe=Z.get(ee);if(oe===null)throw new Error("shader="+w+" \u7F16\u8BD1\u5931\u8D25\uFF08\u5DF2\u7F13\u5B58\uFF09");return oe}for(let oe=0;oe<4;oe++){const b=new Set,T=I=>te.has(I)?te.get(I):(b.add(I),null),P=ei(Ho(W.frag,"frag",Y,T,W.vert)),C=Ho(W.vert,"vert",Y,T,W.frag);if(b.size===0){let I;try{I=ir(t,C,P)}catch(E){throw Z.set(ee,null),new Error("shader="+w+" "+(E&&E.message))}const D=new Map,$=t.getProgramParameter(I,t.ACTIVE_UNIFORMS);for(let E=0;E<$;E++){const k=t.getActiveUniform(I,E),F=k.name.replace(/\[0\]$/,"");D.set(F,{loc:t.getUniformLocation(I,k.name),type:Da[k.type]||"unknown",size:k.size})}const z={...Ue(W.vert),...Ue(W.frag)},B=/gl_Position\s*=\s*vec4\s*\(\s*a_Position/.test(W.vert)&&!/[aA]_Position[\s\S]{0,40}mul\s*\(/.test(W.vert),q=new Map([..._e(W.vert),..._e(W.frag)]),S={prog:I,uni:D,matMeta:z,samplerDefaults:q,fragGlsl:P,vertGlsl:C,ndcDirect:B};return Z.set(ee,S),S}await Promise.all(Array.from(b).map(async I=>{te.set(I,await r("shaders/"+I)||"")}))}throw new Error("include \u89E3\u6790\u5931\u8D25: "+w)}const Ke=jr(t,new Uint8Array([255,255,255,255]),1,1),Be=jr(t,new Uint8Array([0,0,0,0]),1,1);let ye=null;function he(w){ye=w||null}function Ie(){if(!ye)return null;const w=typeof ye=="function"?ye():ye;return w&&w.state?w.state:w}const Pe={x:0,y:0,sx:0,sy:0};let Qe=0,Oe=0,Ae=0,ot=1/60,it=-1;const It=typeof n.fadeDuration=="number"&&n.fadeDuration>=0?n.fadeDuration:1,we=(w,U)=>{const G=w!==null&&typeof w=="object"?w.value:w;return G===!0||G===1?!0:G===!1||G===0?!1:U},Kt=(w,U)=>{const G=w!==null&&typeof w=="object"?w.value:w;return typeof G=="number"&&Number.isFinite(G)?G:U},go=w=>n.fade!==!1&&we(w.camerafade,!1);function Qt(w,U){if(!we(w.camerashake,!1))return null;const G=Kt(w.camerashakeamplitude,0);if(G===0)return null;const W=Math.max(0,Math.min(1,Kt(w.camerashakeroughness,0))),Y=Kt(w.camerashakespeed,1),ee=U*Y,oe=Math.sin(ee*2.1)*Math.cos(ee*.7),b=Math.cos(ee*1.7)*Math.sin(ee*.9),T=Math.sin(ee*11.3)*Math.cos(ee*7.1),P=Math.cos(ee*9.7)*Math.sin(ee*13.1);return{x:(oe*(1-W)+T*W)*G,y:(b*(1-W)+P*W)*G}}function Wn(){const w=new Date;return(w.getHours()*3600+w.getMinutes()*60+w.getSeconds())/86400}function Me(w,U,G){const W=w.get(U);W&&W.loc!==null&&G(W.loc,W.type,W.size)}function Vn(w){if(typeof w=="number")return[w,w,w,w];const U=String(w).trim().split(/[\s,]+/).map(Number);return[U[0]||0,U[1]||0,U[2]||0,U[3]||0]}function Jt(w,U,G){const W=w.get(U);if(!W||W.loc===null)return;const Y=G&&G.value!==void 0?G.value:G,ee=Vn(Y);switch(W.type){case"float":t.uniform1f(W.loc,ee[0]);break;case"int":case"bool":t.uniform1i(W.loc,Y===!0||Y===1?1:Math.round(ee[0]));break;case"vec2":t.uniform2f(W.loc,ee[0],ee[1]);break;case"vec3":t.uniform3f(W.loc,ee[0],ee[1],ee[2]);break;case"vec4":t.uniform4f(W.loc,ee[0],ee[1],ee[2],ee[3]);break;case"mat4":t.uniformMatrix4fv(W.loc,!1,at);break;case"mat3":t.uniformMatrix3fv(W.loc,!1,vt);break}}const tt=()=>new Float32Array([1,0,0,0,1,0,0,0,1]);function Hn(w,U,G,W,Y,ee,oe,b,T,P,C){if(Me(w,"g_Time",S=>t.uniform1f(S,G)),Me(w,"g_Daytime",S=>t.uniform1f(S,Wn())),Me(w,"g_ModelViewProjectionMatrix",S=>t.uniformMatrix4fv(S,!1,ee)),Me(w,"g_ModelMatrix",S=>t.uniformMatrix4fv(S,!1,oe)),Me(w,"g_ViewProjectionMatrix",S=>t.uniformMatrix4fv(S,!1,b)),w.get("g_ModelViewProjectionMatrixInverse")){let S=null;for(const[k,F]of T)k===0&&(S=F);const E=S&&S[0]>0&&S[1]>0?No(En(mn(),S[0]/2,S[1]/2,1)):at;Me(w,"g_ModelViewProjectionMatrixInverse",k=>t.uniformMatrix4fv(k,!1,E))}Me(w,"g_Brightness",S=>t.uniform1f(S,U.brightness)),Me(w,"g_UserAlpha",S=>t.uniform1f(S,U.alpha)),Me(w,"g_Alpha",S=>t.uniform1f(S,U.alpha)),Me(w,"g_Color",S=>t.uniform3f(S,U.color[0],U.color[1],U.color[2])),Me(w,"g_Color4",S=>t.uniform4f(S,U.color[0],U.color[1],U.color[2],1)),Me(w,"g_CompositeColor",S=>t.uniform3f(S,U.color[0],U.color[1],U.color[2])),Me(w,"g_TexelSize",S=>t.uniform2f(S,1/W,1/Y)),Me(w,"g_TexelSizeHalf",S=>t.uniform2f(S,.5/W,.5/Y)),Me(w,"g_TextureReductionScale",S=>t.uniform1f(S,1));const I=Ie(),D=Vr(!!(I&&I.has),!!w.get("g_PointerScale"));let $=D?Ln:I?I.u:.5,z=D?Ln:I?I.v:.5,B=D?Ln:I?I.lastU:.5,q=D?Ln:I?I.lastV:.5;if(C&&U&&U.size&&U.size[0]>0&&U.size[1]>0){const S=Math.abs(U.size[0]*U.scale[0]),E=Math.abs(U.size[1]*U.scale[1]);if(S>0&&E>0){const k=U.origin[0]-S/2,F=C.projH-U.origin[1]-E/2,re=ce=>(C.offX+ce*C.viewW-k)/S,Q=ce=>(C.offY+ce*C.viewH-F)/E;$=re($),z=Q(z),B=re(B),q=Q(q)}}Me(w,"g_PointerPosition",S=>t.uniform2f(S,$,z)),Me(w,"g_PointerPositionLast",S=>t.uniform2f(S,B,q)),Me(w,"g_PointerState",S=>t.uniform4f(S,$,z,I&&I.leftDown?1:0,0)),Me(w,"g_ParallaxPosition",S=>t.uniform2f(S,Pe.sx*.5+.5,Pe.sy*.5+.5)),Me(w,"g_Frametime",S=>t.uniform1f(S,ot)),w.get("g_EffectTextureProjectionMatrixInverse")&&Me(w,"g_EffectTextureProjectionMatrixInverse",S=>t.uniformMatrix4fv(S,!1,at));for(let S=0;S<8;S++)Me(w,"g_Texture"+S,E=>t.uniform1i(E,S));for(const[S,E]of T)Me(w,"g_Texture"+S+"Resolution",k=>t.uniform4f(k,E[0],E[1],E[2],E[3]));if(l){const S=typeof l=="function"?l():l;if(S)for(const[E,k]of f){const F=S[k];F&&Me(w,E,re=>t.uniform1fv(re,F))}}}function en(w,U,G){for(const[W,Y]of Object.entries(U||{})){const ee=G&&G[W];ee&&Jt(w,ee.uniform,Y)}for(const[W,Y]of Object.entries(G||{}))if(!U||!(W in U)){const ee=ni(Y.uniform,Y.default);ee!==void 0&&Jt(w,Y.uniform,ee)}}function _r(w){const U=Ie();Vr(!!(U&&U.has),!!w.get("g_PointerScale"))&&Me(w,"g_PointerScale",G=>t.uniform1f(G,0))}function Ar(w,U,G,W){if(!w)return w;let Y=!1;for(const oe of Object.values(w))if(oe!==null&&typeof oe=="object"&&typeof oe.script=="string"){Y=!0;break}if(!Y||!d)return w;const ee={...w};for(const[oe,b]of Object.entries(w)){if(b===null||typeof b!="object"||typeof b.script!="string")continue;const T=U+"|"+oe;let P=v.get(T);if(P===void 0){_.total++;try{P=d(b.script,b.scriptproperties||b.scriptProperties||null,{userProperties:y||{},audioViews:x||void 0,layer:W||null,shared:m||{},inputView:M||void 0,setTimeout:h?h.setTimeout:void 0,clearTimeout:h?h.clearTimeout:void 0,setInterval:h?h.setInterval:void 0,clearInterval:h?h.clearInterval:void 0})}catch{P=null}if(P?_.ok++:_.failed++,v.set(T,P),P){const B=b.value!==void 0?b.value:b,q=Vn(B),E=typeof B=="number"?q[0]:{x:q[0],y:q[1],z:q[2]};P.init&&P.init(E)}if(P&&typeof P.applyUserProperties=="function")try{P.applyUserProperties(y||{})}catch{}if(P&&P.hasMediaHook&&g)try{g(P)}catch{}}if(!P||P.disabled||!P.hasUpdate)continue;if(P.engine){P.engine.runtime=G,P.engine.frametime=ot,P.engine.timeOfDay=Wn();const B=Ie();B&&B.screenW&&B.screenH&&(P.engine.screenResolution={x:B.screenW,y:B.screenH})}const C=Vn(b.value!==void 0?b.value:b),D=typeof(b.value!==void 0?b.value:b)=="number"?C[0]:{x:C[0],y:C[1],z:C[2]};let $;try{$=P.callUpdate(D)}catch{$=void 0}const z=$??D;if(typeof z=="number"&&Number.isFinite(z))ee[oe]=z;else if(z&&typeof z=="object"){const B=Number(z.x),q=Number(z.y),S=Number(z.z);Number.isFinite(B)&&Number.isFinite(q)&&(ee[oe]=Number.isFinite(S)?`${B} ${q} ${S}`:`${B} ${q} 0`)}}return ee}function bo(w,U,G){if(!w)return w;let W=!1;for(const ee of Object.values(w))if(ee&&typeof ee=="object"&&ee.animation&&ee.animation.options){W=!0;break}if(!W)return w;const Y={...w};for(const[ee,oe]of Object.entries(w)){if(!oe||typeof oe!="object"||!oe.animation||!oe.animation.options)continue;const b=U+"|anim|"+ee;let T=A.get(b);if(!T){const P=Zo(oe.animation),C=oe.value!==void 0?oe.value:0;P.baseNumeric=Array.isArray(C)?C.slice():C,T={ctrl:P},A.set(b,T)}T.ctrl.playing&&T.ctrl.setFrame(G*T.ctrl.fps*T.ctrl.rate),Y[ee]=T.ctrl.applyTo(T.ctrl.baseNumeric)}return Y}function Tr(w,U,G,W){return w==null||w===""?null:w.startsWith("_rt_")?w.startsWith("_rt_imageLayerComposite")?Mn&&xt.has(w)?xt.get(w):U:G.has(w)?G.get(w):null:G.has(w)?G.get(w):W.get(w)||null}const tn=Na(),yo=Ua(),wn=new Map;function ln(w,U){const G=w+"x"+U;let W=wn.get(G);return W===void 0&&(W=Fa(w,U),wn.set(G,W)),W}let st=null;function bt(w,U){st!==w&&(t.bindBuffer(t.ARRAY_BUFFER,O),t.bufferData(t.ARRAY_BUFFER,U,t.DYNAMIC_DRAW),st=w)}const Te={mvp:t.getUniformLocation(N,"u_MVP"),tex:t.getUniformLocation(N,"u_Tex"),color:t.getUniformLocation(N,"u_Color4"),frameOrigin:t.getUniformLocation(N,"u_FrameOrigin"),frameU:t.getUniformLocation(N,"u_FrameU"),frameV:t.getUniformLocation(N,"u_FrameV"),blendPrep:t.getUniformLocation(N,"u_BlendPrep")},yt={mvp:t.getUniformLocation(j,"u_MVP"),tex:t.getUniformLocation(j,"u_Tex"),blendPrep:t.getUniformLocation(j,"u_BlendPrep")},nn={mvp:t.getUniformLocation(H,"u_MVP"),tex:t.getUniformLocation(H,"u_Tex")},at=mn(),vt=tt();function Ct(w){w==="translucent"?(t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA)):w==="additive"?(t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE,t.ONE,t.ONE)):t.disable(t.BLEND)}let Ot=0;function Lt(w){const{mode:U,prep:G}=Wr(w);Ot=G,U==="additive"?(t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE,t.ONE,t.ONE)):U==="multiply"?(t.enable(t.BLEND),t.blendFuncSeparate(t.DST_COLOR,t.ZERO,t.ONE,t.ONE_MINUS_SRC_ALPHA)):U==="screen"?(t.enable(t.BLEND),t.blendFuncSeparate(t.ONE,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA)):Ct("translucent")}function Xn(w,U){if(U&&U.perspective)return!1;const G=w.size[0]*w.scale[0],W=w.size[1]*w.scale[1];if(G===0||W===0)return!1;let Y=Math.abs(G)/2,ee=Math.abs(W)/2;const oe=w.angles[2];if(oe!==0){const $=Math.abs(Math.cos(oe)),z=Math.abs(Math.sin(oe)),B=Y*$+ee*z,q=Y*z+ee*$;Y=B,ee=q}const b=w.origin[0],T=U.projH-w.origin[1];let P=64;w.parallaxDepth&&(P+=Math.abs(yn(w.parallaxDepth[0])*Oe),P+=Math.abs(yn(w.parallaxDepth[1])*Ae));const C=Ko(w),I=P+C[0],D=P+C[1];return b+Y+I<U.offX||b-Y-I>U.offX+U.viewW||T+ee+D<U.offY||T-ee-D>U.offY+U.viewH}function Gn(w,U,G){if(!w.spriteSheet)return null;const W=U&&U.frames,Y=Array.isArray(W)?W:W&&W.list;if(!Y||Y.length===0)return null;const ee=W&&W.atlasWidth||U.width||0,oe=W&&W.atlasHeight||U.height||0;if(ee<=0||oe<=0)return null;w.spriteFrameCount=Y.length;let b=0;const T=w.textureAnimation;if(T&&T.frame!==null&&T.frame!==void 0)b=Math.floor(Number(T.frame))||0,b>=0||(b=0),b>=Y.length&&(b=Y.length-1);else if(Y.length>1){const z=T&&T.playing===!1;let B=0;for(const q of Y)B+=q.duration>0?q.duration:1/30;if(!z&&B>0){let q=G%B;q<0&&(q+=B);for(let S=0;S<Y.length;S++){const E=Y[S].duration>0?Y[S].duration:.03333333333333333;if(q<E){b=S;break}q-=E,b=S}}}const P=Y[b],C=P.uDir?P.uDir[0]:P.width,I=P.uDir?P.uDir[1]:0,D=P.vDir?P.vDir[0]:0,$=P.vDir?P.vDir[1]:P.height;return[P.x/ee,P.y/oe,C/ee,I/oe,D/ee,$/oe]}function $t(w,U){const G=w.size[0]*w.scale[0],W=w.size[1]*w.scale[1];let Y=mn();if(U&&U.perspective){const oe=ya(w,U);Y=bn(Y,oe[0],oe[1],oe[2]);const b=w.angles[0]||0,T=w.angles[1]||0;T&&(Y=ma(Y,T)),b&&(Y=ha(Y,b)),Y=Uo(Y,-w.angles[2])}else{if(Y=bn(Y,w.origin[0],U.projH-w.origin[1],w.origin[2]),w.parallaxDepth&&(Oe!==0||Ae!==0)){const oe=yn(w.parallaxDepth[0]),b=yn(w.parallaxDepth[1]);Y=bn(Y,oe*Oe,b*Ae,0)}Y=Uo(Y,-w.angles[2])}const ee=Xo[w.alignment]||[.5,.5];return(ee[0]!==.5||ee[1]!==.5)&&(Y=bn(Y,(.5-ee[0])*G,(.5-ee[1])*W,0)),{m:Y,w:G,h:W}}function Yn(w,U,G,W,Y,ee,oe,b,T=!1,P=null,C=null){const I=$t(W,Y);let D=I.m;if(C){const B=(C[0]+C[2]/2)*W.scale[0],q=(C[1]+C[3]/2)*W.scale[1];D=bn(D,B,-q,0),D=En(D,C[2]*W.scale[0],C[3]*W.scale[1],1)}else D=En(D,I.w,I.h,1);const $=St(ee,D),z=w===j?yt:Te;t.useProgram(w),T?(Ot=0,t.enable(t.BLEND),W.containerAlphaMeaningful?t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA):t.blendFuncSeparate(t.ONE,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA)):Lt(W.colorBlendMode),z.blendPrep!==null&&z.blendPrep!==void 0&&t.uniform1i(z.blendPrep,Ot),ze?(t.bindFramebuffer(t.FRAMEBUFFER,ze.fbo.fbo),t.viewport(0,0,ze.w,ze.h)):(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,oe,b)),t.bindVertexArray(K),bt("local",yo),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,U),t.uniform1i(z.tex,0),t.uniformMatrix4fv(z.mvp,!1,$),z.color!==null&&z.color!==void 0&&t.uniform4f(z.color,G[0],G[1],G[2],G[3]),jt(z,P),t.drawArrays(t.TRIANGLES,0,6)}function jt(w,U){!w||w.frameOrigin===null||w.frameOrigin===void 0||(U?(t.uniform2f(w.frameOrigin,U[0],U[1]),t.uniform2f(w.frameU,U[2],U[3]),t.uniform2f(w.frameV,U[4],U[5])):(t.uniform2f(w.frameOrigin,0,0),t.uniform2f(w.frameU,1,0),t.uniform2f(w.frameV,0,1)))}let un=null,ze=null;const xt=new Map,wt=new Map;let Mn=!0;function qn(w,U){const G=$t(w,U),W=U&&U.perspective?w.scale[1]:-w.scale[1],Y=U&&U.perspective&&w.scale[2]||1;return En(G.m,w.scale[0],W,Y)}function fn(w,U,G,W,Y,ee,oe){ze?(t.bindFramebuffer(t.FRAMEBUFFER,ze.fbo.fbo),t.viewport(0,0,ze.w,ze.h)):(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,W,Y));const b=St(G,qn(w,U));un(w,b,{time:ee,overrideTex:oe||null}),st=null}let dt=null;function Zn(w,U){return dt===null&&(dt=t.createTexture(),t.bindTexture(t.TEXTURE_2D,dt),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE)),t.bindFramebuffer(t.FRAMEBUFFER,null),t.bindTexture(t.TEXTURE_2D,dt),t.copyTexImage2D(t.TEXTURE_2D,0,t.RGB8,0,0,w,U,0),dt}function Sr(w,U,G,W,Y,ee,oe,b){const T=Zn(oe,b),P=$t(w,Y);let C=P.m;C=En(C,P.w,P.h,1);const I=St(ee,C),D=[[-.5,.5],[.5,.5],[-.5,-.5],[.5,-.5]].map(([E,k])=>{const F=xa(I,E,k,0);return[F[0]*.5+.5,F[1]*.5+.5]}),[$,z,B,q]=D,S=new Float32Array([0,W,0,$[0],$[1],0,0,0,B[0],B[1],G,W,0,z[0],z[1],G,W,0,z[0],z[1],0,0,0,B[0],B[1],G,0,0,q[0],q[1]]);t.useProgram(H),Ct("normal"),t.disable(t.BLEND),t.bindFramebuffer(t.FRAMEBUFFER,U.fbo),t.viewport(0,0,G,W),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindVertexArray(K),t.bindBuffer(t.ARRAY_BUFFER,O),t.bufferData(t.ARRAY_BUFFER,S,t.DYNAMIC_DRAW),st=null,t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,T),t.uniform1i(nn.tex,0),t.uniformMatrix4fv(nn.mvp,!1,gn(0,G,0,W,-1e4,1e4)),t.drawArrays(t.TRIANGLES,0,6),t.enable(t.BLEND)}function zt(w,U,G,W,Y){if(!Mn||ze)return;const ee=wt.get(w.id);if(!ee||ee.size===0)return;const oe=Math.max(1,Math.round(Math.abs(w.size[0]*(w.scale[0]||1)))),b=Math.max(1,Math.round(Math.abs(w.size[1]*(w.scale[1]||1))));if(oe<=1&&b<=1)return;const T=ie(oe,b,"lc:"+w.id);Sr(w,T,oe,b,U,G,W,Y);for(const P of ee)xt.set(P,T);wt.delete(w.id),t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,W,Y)}async function vo(w,U,G,W,Y,ee,oe,b){X++,t.viewport(0,0,G,W);const T=w.general||{};if(T.clearenabled!==!1){const S=Yo(T.clearcolor||"0 0 0");t.clearColor(S[0],S[1],S[2],1)}else t.clearColor(0,0,0,1);if(t.clear(t.COLOR_BUFFER_BIT),it>=0){const S=Y-it;ot=S>0&&S<1?S:Math.min(.1,Math.max(.001,S||1/60))}it=Y;const P=_a(w,G,W,ee,oe,b);let C=St(P.projection,P.view);const I=T.cameraparallax,D=I===!0||I!==null&&typeof I=="object"&&I.value===!0;Oe=0,Ae=0;const $=Ie();if($&&(Pe.x=$.u*2-1,Pe.y=$.v*2-1),!P.perspective&&n.parallax!==!1&&D){const S=(_t,de)=>{const pe=_t!==null&&typeof _t=="object"?_t.value:_t;return typeof pe=="number"&&Number.isFinite(pe)?pe:de},E=S(T.cameraparallaxamount,0),k=S(T.cameraparallaxmouseinfluence,1),F=S(T.cameraparallaxdelay,1),re=Y-Qe;Qe=Y;const Q=re>0?1-Math.exp(-re/Math.max(.05,F)):1;Pe.sx+=(Pe.x-Pe.sx)*Q,Pe.sy+=(Pe.y-Pe.sy)*Q;const ce=E*k,ue=60,ge=Pe.sx*ce*P.viewW,$e=Pe.sy*ce*P.viewH,Mt=Math.max(Math.abs(ge),Math.abs($e))/ue,kt=Mt>1?1/Mt:1;Oe=-(ge*kt),Ae=-($e*kt)}if(!P.perspective&&n.shake!==!1){const S=Qt(T,Y);if(S){const E=S.x*P.viewW*.02,k=S.y*P.viewH*.02;(E!==0||k!==0)&&(C=St(C,bn(mn(),E,k,0)))}}if(ye){const S=typeof ye=="function"?ye():ye;S&&typeof S.syncWorld=="function"&&S.syncWorld(P,0,0)}if(!L){L=!0;const S=(w.layers||[]).filter(F=>F.isContainer),E=S.filter(F=>(F.effects||[]).some(re=>re.visible)&&!F.hasChildren),k=E.filter(F=>(F.effects||[]).some(re=>(re.materialPasses||[]).length>0));o(`containers total=${S.length} canvasCandidates=${E.length} passesResolved=${k.length} names=${E.slice(0,4).map(F=>F.name||"?").join("/")}`)}await xo(w,U,P,G,W,Y);const z=new Map;for(const S of w.layers)S.id!==void 0&&z.set(S.id,S);const B=new Set;for(const S of w.layers)!S.visible||S.destroyed||!S.isContainer||!S.hasChildren||!(S.effects||[]).some(k=>k.visible)||(S.childIds||[]).length===0||ar(S,z,B);if(c)try{c()}catch(S){o("particle advance error: "+(S&&S.message))}const q=P.perspective?w.layers.slice().sort((S,E)=>+!!E.isSkybox-+!!S.isSkybox):w.layers;for(const S of q)if(!S.destroyed){if(!S.visible){wt.has(S.id)&&zt(S,P,C,G,W);continue}if(!(S.isPostProcess&&!(S.effects||[]).some(E=>E.visible))&&!B.has(S.id)){if(S.isContainer){if(!(S.effects||[]).some(k=>k.visible)){zt(S,P,C,G,W);continue}if(S.hasChildren){(S.childIds||[]).length>0&&await Er(S,w,U,P,C,G,W,Y);continue}}if(S.particle){if(u)try{await u(S.id,P,C,G,W)}catch(E){o("particle render error: "+(E&&E.message))}continue}Xn(S,P)||await Rt(S,U,P,C,G,W,Y)}}if(go(T)&&Y<It){const S=Math.max(0,Math.min(1,Y/It)),E=1-S*S*(3-2*S);if(E>.002){const k=Yo(T.clearcolor||"0 0 0");t.useProgram(N),t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA),t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,G,W),t.bindVertexArray(K),bt("pass",tn),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,Ke),t.uniform1i(Te.tex,0),t.uniform4f(Te.color,k[0],k[1],k[2],E),jt(Te,null),Te.blendPrep!==null&&Te.blendPrep!==void 0&&t.uniform1i(Te.blendPrep,0),t.uniformMatrix4fv(Te.mvp,!1,at),t.drawArrays(t.TRIANGLES,0,6)}}t.bindVertexArray(null),J()}async function xo(w,U,G,W,Y,ee){xt.clear(),wt.clear();const oe=new Map,b=new Set;let T=null;const P=C=>{if(typeof C!="string")return;const I=/^_rt_imageLayerComposite_(\d+)_[a-z]$/.exec(C);if(!I)return;const D=Number(I[1]);T!==null&&D===T&&b.add(D);let $=oe.get(D);$||($=new Set,oe.set(D,$)),$.add(C)};for(const C of w.layers||[]){T=C.id;for(const I of C.effects||[])if(I.visible){for(const D of I.passes||[])for(const $ of D.textures||[])P($);for(const D of I.materialPasses||[]){for(const $ of D.binds||[])P($&&$.name);for(const $ of D.textures||[])P($)}}}if(oe.size!==0){for(const[C,I]of oe){const D=(w.layers||[]).find(ue=>ue.id===C);if(!D||D.particle||D.isPostProcess||b.has(C))continue;const $=typeof D.image=="string"?D.image:"";if(D.isContainer&&!D.hasChildren&&$.indexOf("models/util/composelayer")===0&&!(D.effects||[]).some(ue=>ue.visible)){wt.set(C,I);continue}const B=Math.max(1,Math.round(Math.abs(D.size[0]*(D.scale[0]||1)))),q=Math.max(1,Math.round(Math.abs(D.size[1]*(D.scale[1]||1))));if(B<=1&&q<=1)continue;const S=ie(B,q,"lc:"+C);t.bindFramebuffer(t.FRAMEBUFFER,S.fbo),t.viewport(0,0,B,q),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);const E={view:G.view,projection:gn(0,B,0,q,-1e4,1e4),eye:G.eye,projW:B,projH:q,offX:0,offY:0,viewW:B,viewH:q},k=ze,F=D.origin,re=D.scale,Q=D.angles,ce=D.visible;ze={fbo:S,w:B,h:q},D.origin=[B/2,E.projH-q/2,F[2]],D.scale=[Math.sign(re[0])||1,Math.sign(re[1])||1,re[2]],D.angles=[0,0,0],D.visible=!0;try{await Rt(D,U,E,E.projection,B,q,ee);for(const ue of I)xt.set(ue,S)}catch(ue){o(`composite \u6E90\u5C42 ${C} \u6E32\u67D3\u5931\u8D25: ${ue&&ue.message}`)}finally{ze=k,D.origin=F,D.scale=re,D.angles=Q,D.visible=ce}}t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,W,Y)}}async function Er(w,U,G,W,Y,ee,oe,b){const T=Math.max(1,Math.round(Math.abs(w.size[0]))),P=Math.max(1,Math.round(Math.abs(w.size[1])));if((w.childIds||[]).length===0)return;const I=new Map;for(const Q of U.layers)Q.id!==void 0&&I.set(Q.id,Q);const D=ar(w,I),$=U.layers.filter(Q=>D.has(Q.id)&&Q.visible);if($.length===0)return;const z=ie(T,P,"group");t.bindFramebuffer(t.FRAMEBUFFER,z.fbo),t.viewport(0,0,T,P),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);const B={view:W.view,projection:gn(0,T,0,P,-1e4,1e4),eye:W.eye,projW:T,projH:P,offX:0,offY:0,viewW:T,viewH:P},q=B.projection,S=w.scale[0]||1,E=w.scale[1]||1,k=w.angles[2]||0,F=Math.cos(-k),re=Math.sin(-k);ze={fbo:z,w:T,h:P};try{for(const Q of $){if(Q.isPostProcess||Q.particle||Q.isContainer&&(Q.childIds||[]).length>0)continue;const ce=Q.origin,ue=Q.scale,ge=Q.angles,$e=ce[0]-w.origin[0],Mt=ce[1]-w.origin[1],kt=($e*F-Mt*re)/S,_t=($e*re+Mt*F)/E;Q.origin=[T/2+kt,P/2+_t,ce[2]],Q.scale=[ue[0]/S,ue[1]/E,ue[2]],Q.angles=[ge[0],ge[1],ge[2]-k];try{await Rt(Q,G,B,q,T,P,b)}finally{Q.origin=ce,Q.scale=ue,Q.angles=ge}}}finally{ze=null}w.groupTex=z.tex,w.groupW=T,w.groupH=P;try{await Rt(w,G,W,Y,ee,oe,b)}finally{w.groupTex=null}}async function Rt(w,U,G,W,Y,ee,oe){const b=!!(w.puppet&&un),T=!w.solid&&w.textureName?U.get(w.textureName):null;if(T&&T.video){const de=T.video;if(de.readyState>=2&&de.currentTime!==T.lastUploaded){t.bindTexture(t.TEXTURE_2D,T.glTex);try{let pe=de.videoWidth||T.width,fe=de.videoHeight||T.height;const Ee=2048,ct=t.getParameter(t.MAX_TEXTURE_SIZE),lt=ct>0&&ct<4096?Math.min(Ee,ct):Ee;let At=1;Math.max(pe,fe)>lt&&(At=lt/Math.max(pe,fe));const nt=Math.max(1,Math.round(pe*At)),Ce=Math.max(1,Math.round(fe*At));let _n=de;if(i&&nt>0&&Ce>0){(i.width!==nt||i.height!==Ce)&&(i.width=nt,i.height=Ce);const ut=i.getContext("2d");ut&&(ut.clearRect(0,0,nt,Ce),ut.drawImage(de,0,0,nt,Ce),_n=i)}if(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,_n),t.getError()!==t.NO_ERROR&&i)try{const Ge=i.getContext("2d").getImageData(0,0,i.width,i.height);for(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,i.width,i.height,0,t.RGBA,t.UNSIGNED_BYTE,new Uint8Array(Ge.data.buffer));t.getError()!==t.NO_ERROR;);}catch{}T.width=nt,T.height=Ce,T.lastUploaded=de.currentTime,s||(s=!0,o("video tex ready "+nt+"x"+Ce+" (src "+pe+"x"+fe+")"))}catch(pe){s||(s=!0,o("video upload FAIL: "+(pe&&pe.message||pe))),console.warn("[we-scene] \u89C6\u9891\u5E27\u4E0A\u4F20\u5931\u8D25:",pe&&pe.message,"readyState=",de.readyState,"cur=",de.currentTime)}}}const P=w.groupTex?w.groupTex:T&&T.glTex?T.glTex:w.solid?Ke:Be,C=(!!w.passthrough||!!w.isPostProcess||Qo(w))&&!w.groupTex&&!T&&!b;let I,D;if(w.groupTex?(I=w.groupW||w.size[0],D=w.groupH||w.size[1]):b||!T?(I=w.size[0],D=w.size[1]):(I=T.width,D=T.height),!b&&T&&w.spriteSheet){const de=T.frames,pe=Array.isArray(de)?de:de&&de.list;pe&&pe.length&&(I=pe[0].width||I,D=pe[0].height||D)}const $=Math.max(1,Math.round(I)),z=Math.max(1,Math.round(D)),B=[w.color[0]*w.brightness,w.color[1]*w.brightness,w.color[2]*w.brightness,w.alpha],q=(w.effects||[]).filter(de=>de.visible);let S=$,E=z;if(a>0&&G.projW>0&&G.projH>0){const de=Math.min(Math.abs(w.size[0]*w.scale[0]),G.viewW),pe=Math.min(Math.abs(w.size[1]*w.scale[1]),G.viewH),fe=de*(Y/G.projW),Ee=pe*(ee/G.projH);if(fe>0&&Ee>0){const ct=Math.max(64,Math.round(fe*a)),lt=Math.max(64,Math.round(Ee*a));ct<$&&(S=ct),lt<z&&(E=lt)}}if(q.length===0){b?fn(w,G,W,Y,ee,oe):Yn(N,P,B,w,G,W,Y,ee,!1,Gn(w,T,oe));return}const k=ie(S,E,"ping"),F=ie(S,E,"pong"),re=gn(0,S,0,E,-1e4,1e4);if(b)t.useProgram(N),Ct("normal"),t.bindFramebuffer(t.FRAMEBUFFER,k.fbo),t.viewport(0,0,S,E),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindVertexArray(K),st=null,bt("layer"+S+"x"+E,ln(S,E)),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,P),t.uniform1i(Te.tex,0),t.uniform4f(Te.color,1,1,1,1),jt(Te,null),Te.blendPrep!==null&&Te.blendPrep!==void 0&&t.uniform1i(Te.blendPrep,0),t.uniformMatrix4fv(Te.mvp,!1,re),t.drawArrays(t.TRIANGLES,0,6);else if(C)Sr(w,k,S,E,G,W,Y,ee);else{t.useProgram(N),Ct("normal"),t.bindFramebuffer(t.FRAMEBUFFER,k.fbo),t.viewport(0,0,S,E),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindVertexArray(K),bt("layer"+S+"x"+E,ln(S,E)),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,P),t.uniform1i(Te.tex,0);const de=q.some(pe=>pe&&pe.layerMaterial)?[1,1,1,B[3]]:B;t.uniform4f(Te.color,de[0],de[1],de[2],de[3]),jt(Te,Gn(w,T,oe)),Te.blendPrep!==null&&Te.blendPrep!==void 0&&t.uniform1i(Te.blendPrep,0),t.uniformMatrix4fv(Te.mvp,!1,re),t.drawArrays(t.TRIANGLES,0,6)}let Q=k,ce=F;const ue=new Map;let ge=!1,$e=k;const Mt=[],kt=new Set;for(const de of q){for(const fe of de.fbos||[])if(!ue.has(fe.name)){const[Ee,ct]=Jo(fe,S,E),lt=fe.unique?w.id+":"+fe.name:fe.name;ue.set(fe.name,ie(Ee,ct,lt))}const pe=de.materialPasses||[];for(let fe=0;fe<pe.length;fe++)Mt.push({eff:de,mp:pe[fe],ov:de.passes&&de.passes[fe]})}const _t=[];for(let de=0;de<Mt.length;de++){const{eff:pe,mp:fe,ov:Ee}=Mt[de];if(kt.has(pe))continue;const ct={...fe.combos||{},...Ee&&Ee.combos||{}},lt=fe.textures||[],At=Ee&&Ee.textures||[],nt=[];for(let ve=0;ve<Math.max(lt.length,At.length);ve++)At[ve]!==void 0&&At[ve]!==null?nt[ve]=At[ve]:nt[ve]=lt[ve]!==void 0?lt[ve]:null;if(fe.copyCommand){const ve=fe.source?ue.get(fe.source):null,ke=fe.target?ue.get(fe.target):null;ve&&ke&&(t.useProgram(j),Ct("normal"),t.bindFramebuffer(t.FRAMEBUFFER,ke.fbo),t.viewport(0,0,ke.width,ke.height),t.bindVertexArray(K),bt("pass",tn),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,ve.tex),t.uniform1i(yt.tex,0),yt.blendPrep!==null&&yt.blendPrep!==void 0&&t.uniform1i(yt.blendPrep,0),t.uniformMatrix4fv(yt.mvp,!1,at),t.drawArrays(t.TRIANGLES,0,6),t.bindFramebuffer(t.FRAMEBUFFER,null));continue}let Ce;try{Ce=await De(fe.shader,ct,nt)}catch(ve){const ke=ve&&ve.message||String(ve);/已缓存/.test(ke)||console.warn("[we-scene] \u8DF3\u8FC7\u6548\u679C\uFF08pass \u7F16\u8BD1\u5931\u8D25\uFF09:",fe.shader,ke),kt.add(pe);continue}const _n=Ce.prog,ut=Ce.uni;Ce.fragGlsl&&_t.push(Ce.fragGlsl);let Ge,Kn;fe.target?(ge||($e=Q,ge=!0),Ge=ue.get(fe.target)||Q,Kn=$e):(ge=!1,Ge=ce,Kn=Q),t.useProgram(_n),Ct(fe.blending||"normal"),t.bindFramebuffer(t.FRAMEBUFFER,Ge.fbo),t.viewport(0,0,Ge.width,Ge.height),t.bindVertexArray(K);const _s=!Ce.ndcDirect;_s?bt("passPx"+Ge.width+"x"+Ge.height,ln(Ge.width,Ge.height)):bt("pass",tn);const Gu=_s?No(gn(0,Ge.width,0,Ge.height,-1e4,1e4)):at,wo=fe.textures||[],Yu=Math.max(wo.length,8),As=new Map,qu=new Set;for(let ve=0;ve<Yu;ve++){let ke=ve<wo.length?wo[ve]:null;Ee&&Ee.textures&&Ee.textures[ve]!==void 0&&Ee.textures[ve]!==null&&(ke=Ee.textures[ve]);for(const Jn of fe.binds||[])Jn.index===ve&&(ke=Jn.name);let Ft;if(ve===0&&(ke==null||ke===""))Ft=Kn;else{if((ke==null||ke==="")&&Ce.samplerDefaults){const Jn=Ce.samplerDefaults.get(ve);Jn&&(ke=Jn)}Ft=Tr(ke,Kn,ue,U)}ke==="previous"&&(Ft=Kn),Ft===null&&(Ft={glTex:Ke,width:1,height:1,tex:Ke});const Qn=Ft.fbo?Ft:{tex:Ft.glTex||Ke,width:Ft.width||1,height:Ft.height||1};t.activeTexture(t.TEXTURE0+ve),t.bindTexture(t.TEXTURE_2D,Qn.tex),qu.add(ve),As.set(ve,[Qn.width,Qn.height,Qn.width,Qn.height])}Hn(ut,w,oe,G.projW,G.projH,Gu,re,at,As,re,G),en(ut,bo(Ar({...fe.constants||{},...Ee&&Ee.constantshadervalues||{}},(w.id||w.name||"?")+"|"+(fe.shader||"?")+"|"+de,oe,w),(w.id||w.name||"?")+"|"+(fe.shader||"?")+"|"+de,oe),Ce.matMeta),_r(ut),t.drawArrays(t.TRIANGLES,0,6),fe.target||(ce=Q,Q=Ge)}if(w.isContainer&&!w.groupTex&&!C&&w.containerAlphaMeaningful===void 0){let de=!1;for(const pe of _t){if(typeof pe!="string")continue;const fe=pe.match(/\bfloat\s+alpha\s*=\s*([^;]+);/);if(fe&&!/^\s*scene\s*\.\s*a\s*$/.test(fe[1])){de=!0;break}}w.containerAlphaMeaningful=de,o(`container "${w.name||"?"}" alpha ${de?"\u643A\u5E26\u5F62\u72B6 \u2192 SRC_ALPHA":"\u65E0\u4FE1\u606F \u2192 \u52A0\u6CD5"}`)}if(b){fn(w,G,W,Y,ee,oe,Q.tex);return}Yn(j,Q.tex,[1,1,1,1],w,G,W,Y,ee,!!w.isContainer&&!w.groupTex&&!C,null,null)}return{gl:t,render:vo,getFBO:ie,getEffectProgram:De,progCache:Z,shaderResolver:r,whiteTex:Ke,resetShaderCaches:function(){Z.clear(),te.clear(),le&&le.clear()},setFboCapFactor:function(w){a=w},setParticleRenderer:function(w,U){c=typeof w=="function"?w:null,u=typeof U=="function"?U:null},setConstantScriptRuntime:R,applyConstUserProperties:function(w){if(w){for(const U of v.values())if(U&&typeof U.applyUserProperties=="function")try{U.applyUserProperties(w)}catch{}}},constantScriptStats:function(){return{..._,cached:v.size}},setCompositeEnabled:function(w){Mn=!!w},compositeStats:function(){const w=[],U=new Uint8Array(4);for(const[G,W]of xt){let Y=null;try{t.bindFramebuffer(t.FRAMEBUFFER,W.fbo),t.readPixels(W.w>>1,W.h>>1,1,1,t.RGBA,t.UNSIGNED_BYTE,U),Y=[U[0],U[1],U[2],U[3]]}catch{}w.push({name:G,w:W.w,h:W.h,center:Y})}return t.bindFramebuffer(t.FRAMEBUFFER,null),w},setPuppetRenderer:function(w){un=w},setAudioProvider:p,setPointerProvider:he,getParallaxOffset:function(){return{x:Oe,y:Ae}},dispose:function(){try{const w=t.getExtension("WEBGL_lose_context");w&&w.loseContext()}catch{}}}}const Xa=Object.freeze(Object.defineProperty({__proto__:null,ALIGN:Xo,XRAY_IDLE_SCREEN_UV:Ln,XRAY_SIZE_FALLBACK:ti,applyColorBlendCPU:za,collectGroupDescendantIds:ar,colorBlendPlan:Wr,constantFallback:ni,createRenderer:Ha,effectFboSize:Jo,layerWantsPreserveBackdrop:Qo,makeTexture:jr,makeTextureMip:Ba,puppetAnimMargin:Ko,rewriteXrayFragScale:ei,xrayShouldParkPointer:Vr,xrayUvScale:Wa},Symbol.toStringTag,{value:"Module"}));function Ga(e=256,n=8){const t=e/n,r=ri(1337),o=ri(4242),i=new Float32Array(t*t),s=new Float32Array(t*t);for(let u=0;u<t*t;u++)i[u]=r(),s[u]=o();const a=new Uint8Array(e*e*4),c=n;for(let u=0;u<e;u++){const l=Math.floor(u/c),f=u%c/c,p=f*f*(3-2*f);for(let d=0;d<e;d++){const y=Math.floor(d/c),x=d%c/c,m=x*x*(3-2*x),M=y%t,h=(y+1)%t,g=l%t,v=(l+1)%t,A=i[g*t+M],_=i[g*t+h],R=i[v*t+M],L=i[v*t+h],N=s[g*t+M],j=s[g*t+h],H=s[v*t+M],K=s[v*t+h],O=A+(_-A)*m+(R-A)*p+(A-_-R+L)*m*p,V=N+(j-N)*m+(H-N)*p+(N-j-H+K)*m*p,X=(u*e+d)*4;a[X]=Math.round(O*255),a[X+1]=Math.round(V*255),a[X+2]=0,a[X+3]=255}}return a}function ri(e){let n=e>>>0;return()=>{n|=0,n=n+1831565813|0;let t=Math.imul(n^n>>>15,1|n);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}const Ya=Object.freeze(Object.defineProperty({__proto__:null,generateNoiseTexture:Ga},Symbol.toStringTag,{value:"Module"})),ht=Math.PI*2;function Le(e,n){return e==null?Math.random():n==null?e:e+Math.random()*(n-e)}function oi(e,n,t){if(e==null)return Math.random();if(n==null)return e;const r=t&&t!==1?Math.pow(Math.random(),t):Math.random();return e+r*(n-e)}function be(e,n){if(Array.isArray(e))return[e[0]||0,e[1]||0,e[2]||0];if(e==null)return n?n.slice():[0,0,0];if(typeof e=="object")return be(e.value,n);if(typeof e=="number")return[e,e,e];const t=String(e).trim().split(/\s+/).map(Number);return[t[0]||0,t[1]||0,t[2]||0]}function ii(e){return e==null?null:typeof e=="number"?[e,e,e]:be(e)}function ne(e,n){if(e==null)return n;if(typeof e=="object")return ne(e.value,n);const t=Number(e);return Number.isFinite(t)?t:n}function Hr(e,n){const t=e[0],r=e[1]>t?e[1]:t+1e-6,o=Math.min(1,Math.max(0,(n-t)/(r-t)));return o*o*(3-2*o)}function Xt(e,n,t){const r=Math.sin(e*127.1+n*311.7+t*74.7)*43758.5453;return r-Math.floor(r)}function qa(e,n,t){const r=Math.floor(e),o=Math.floor(n),i=Math.floor(t),s=e-r,a=n-o,c=t-i,u=s*s*(3-2*s),l=a*a*(3-2*a),f=c*c*(3-2*c),p=(M,h,g)=>M+(h-M)*g,d=p(Xt(r,o,i),Xt(r+1,o,i),u),y=p(Xt(r,o+1,i),Xt(r+1,o+1,i),u),x=p(Xt(r,o,i+1),Xt(r+1,o,i+1),u),m=p(Xt(r,o+1,i+1),Xt(r+1,o+1,i+1),u);return p(p(d,y,l),p(x,m,l),f)}function Xr(e,n,t,r){let o=0,i=.5,s=1,a=0;for(let c=0;c<r;c++)o+=i*qa(e*s,n*s,t*s),a+=i,i*=.5,s*=2;return o/(a||1)}function Gr(e,n,t,r){return[Xr(e,n,t,r)*2-1,Xr(e+31.7,n+11.3,t+57.1,r)*2-1,Xr(e+73.9,n+92.1,t+13.7,r)*2-1]}function Za(e){const n=`#version 300 es
|
|
348
|
+
}`;function K0(t,e){return new Float32Array([0,e,0,0,1,0,0,0,0,0,t,e,0,1,1,t,e,0,1,1,0,0,0,0,0,t,0,0,1,0])}function Z0(){return new Float32Array([-1,1,0,0,1,-1,-1,0,0,0,1,1,0,1,1,1,1,0,1,1,-1,-1,0,0,0,1,-1,0,1,0])}function J0(){return new Float32Array([-.5,.5,0,0,1,-.5,-.5,0,0,0,.5,.5,0,1,1,.5,.5,0,1,1,-.5,-.5,0,0,0,.5,-.5,0,1,0])}const ey={5126:"float",35664:"vec2",35665:"vec3",35666:"vec4",5124:"int",35667:"ivec2",35668:"ivec3",35669:"ivec4",35670:"bool",35676:"mat4",35675:"mat3"};function cr(t,e,n){const r=ed(t,t.VERTEX_SHADER,e),i=ed(t,t.FRAGMENT_SHADER,n),s=t.createProgram();if(t.attachShader(s,r),t.attachShader(s,i),t.bindAttribLocation(s,0,"a_Position"),t.bindAttribLocation(s,1,"a_TexCoord"),t.linkProgram(s),!t.getProgramParameter(s,t.LINK_STATUS))throw new Error("\u7740\u8272\u5668\u94FE\u63A5\u5931\u8D25: "+t.getProgramInfoLog(s));return s}function ed(t,e,n){const r=t.createShader(e);if(t.shaderSource(r,n),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS))throw new Error("\u7740\u8272\u5668\u7F16\u8BD1\u5931\u8D25: "+t.getShaderInfoLog(r));return r}function pc(t){t!==null&&typeof t=="object"&&"value"in t&&(t=t.value);const e=String(t??"").trim().split(/\s+/).map(Number);return[e[0]||0,e[1]||0,e[2]||0]}function gc(t,e,n,r,i=null){const s=t.createTexture();return t.bindTexture(t.TEXTURE_2D,s),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),i?(t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,i),t.generateMipmap(t.TEXTURE_2D)):(t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,n,r,0,t.RGBA,t.UNSIGNED_BYTE,e)),s}function ty(t,e,n=!1){const r=t.createTexture();t.bindTexture(t.TEXTURE_2D,r),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR);const i=e[0];if(i.bitmap)t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,i.bitmap);else if(n&&i.rgba){const s=i.width*i.height,a=new Uint8Array(s*2);for(let c=0;c<s;c++)a[c*2]=i.rgba[c*4+3],a[c*2+1]=i.rgba[c*4];const o=t.getParameter(t.UNPACK_ALIGNMENT);t.pixelStorei(t.UNPACK_ALIGNMENT,1),t.texImage2D(t.TEXTURE_2D,0,t.RG8,i.width,i.height,0,t.RG,t.UNSIGNED_BYTE,a),t.pixelStorei(t.UNPACK_ALIGNMENT,o)}else t.texImage2D(t.TEXTURE_2D,0,t.RGBA,i.width,i.height,0,t.RGBA,t.UNSIGNED_BYTE,i.rgba);return t.generateMipmap(t.TEXTURE_2D),r}function yc(t,e,n,r,i){const s=1-i;return s*s*s*t+3*s*s*i*e+3*s*i*i*n+i*i*i*r}function ny(t,e,n,r,i){if(i<=t)return 0;if(i>=r)return 1;let s=r-t>1e-9?(i-t)/(r-t):.5;for(let c=0;c<8;c++){const u=yc(t,e,n,r,s)-i;if(Math.abs(u)<1e-6)return s;const l=1-s,f=3*l*l*(e-t)+6*l*s*(n-e)+3*s*s*(r-n);if(Math.abs(f)<1e-9)break;const d=s-u/f;if(d<0||d>1||!Number.isFinite(d))break;s=d}let a=0,o=1;for(let c=0;c<40;c++)s=(a+o)/2,yc(t,e,n,r,s)<i?a=s:o=s;return s}function da(t,e,n){if(!t||t.length===0)return 0;if(t.length===1)return Number(t[0].value)||0;if(n&&n.length>0){const P=t[0],M=t[t.length-1],B=n.length-M.frame;if(B>1e-9&&e>M.frame&&e<=n.length)return da([{frame:0,value:M.value,front:M.front,back:M.back},{frame:B,value:P.value,front:P.front,back:P.back}],e-M.frame)}if(e<=t[0].frame)return Number(t[0].value)||0;const r=t[t.length-1];if(e>=r.frame)return Number(r.value)||0;let i=0,s=t.length-1;for(;s-i>1;){const P=i+s>>1;t[P].frame<=e?i=P:s=P}const a=t[i],o=t[s],c=a.frame,u=o.frame,l=Number(a.value)||0,f=Number(o.value)||0,d=u-c;if(d<=0)return f;const h=a.front,p=o.back,m=d/3,g=!!(h&&h.enabled),w=!!(p&&p.enabled),y=g?Math.abs(Number(h.x)||0):1,b=w?Math.abs(Number(p.x)||0):1,v=c+Math.min(y,1.5)*m,k=u-Math.min(b,1.5)*m,A=g?l+(Number(h.y)||0):l+(f-l)/3,T=w?f+(Number(p.y)||0):f-(f-l)/3,S=ny(c,v,k,u,e);return yc(l,A,T,f,S)}function td(t,e,n){const r=e>0?e:1;if(n==="loop"){let i=t%r;return i<0&&(i+=r),i}if(n==="mirror"){const i=r*2;let s=t%i;return s<0&&(s+=i),s<=r?s:i-s}return Math.max(0,Math.min(r,t))}function ry(t){return Array.isArray(t)?t:typeof t=="string"?t.trim().split(/\s+/).map(Number):Number.isFinite(t)?[t]:[]}function nd(t,e,n,r,i){if(!t||!t.length||e===n)return[];const s=n>e,a=r>0?r:1,o=[];if(i==="single")for(const c of t)(s?c.frame>e&&c.frame<=n:c.frame>=n&&c.frame<e)&&o.push({at:c.frame,e:c});else if(i==="loop"){const c=Math.floor(Math.min(e,n)/a),u=Math.floor(Math.max(e,n)/a);for(let l=c;l<=u;l++)for(const f of t){const d=l*a+f.frame;(s?d>e&&d<=n:d>=n&&d<e)&&o.push({at:d,e:f})}}else{const c=a*2,u=Math.floor(Math.min(e,n)/c),l=Math.floor(Math.max(e,n)/c);for(let f=u;f<=l;f++)for(const d of t){const h=f*c+d.frame,p=f*c+2*a-d.frame;for(const m of h===p?[h]:[h,p])(s?m>e&&m<=n:m>=n&&m<e)&&o.push({at:m,e:d})}}return o.sort((c,u)=>s?c.at-u.at:u.at-c.at),o.map(c=>c.e)}function iy(t,e,n){const r=nd(t._events,e,n,t.frameCount||1,t.mode);for(const i of r)t._eventQueue.push(i)}function rd(t,e){const n=t instanceof Map?t:new Map(Object.entries(t||{}));for(const[r,i]of n){if(!i||!i.parentKey)continue;const s=n.get(i.parentKey);if(!s||s===i){e&&e(`\u52A8\u753B\u8054\u52A8 parent \u60AC\u7A7A\uFF08\u9000\u5316\u4E3A\u72EC\u7ACB\uFF09\uFF1A${r} -> ${i.parentKey}`);continue}if(s.parentKey){e&&e(`\u52A8\u753B\u8054\u52A8\u591A\u7EA7 parent\uFF08\u4E0D\u652F\u6301\uFF0C\u9000\u5316\u4E3A\u72EC\u7ACB\uFF09\uFF1A${r} -> ${i.parentKey}`);continue}i.parent=s}return n}function id(t){const e=t&&t.options||{},n=Number(e.fps)>0?Number(e.fps):30,r=Number(e.length)>0?Number(e.length):0,i=e.mode==="loop"||e.mode==="mirror"?e.mode:"single",s=typeof e.name=="string"?e.name:"",a=!!(t&&t.relative),o=e.wraploop===!0&&i==="loop",c=[];for(let m=0;;m++){const g=t&&t["c"+m];if(!Array.isArray(g))break;c.push(g)}const u=e.startpaused!==!0,l=[],f=e.parent&&typeof e.parent.key=="string"?e.parent.key:null,d=Array.isArray(e.children)?e.children.map(m=>m&&typeof m.key=="string"?m.key:null).filter(Boolean):[],h=Array.isArray(e.events)?e.events.filter(m=>m&&Number.isFinite(Number(m.frame))&&typeof m.name=="string").map(m=>({frame:Number(m.frame),name:m.name})):[],p={name:s,mode:i,fps:n,relative:a,channelCount:c.length,parentKey:f,childKeys:d,parent:null,frame:0,_playing:u,_rate:1,_ended:!1,_events:h,_eventQueue:[],get frameCount(){return r},get playing(){return p.parent?p.parent.playing:p._playing},set playing(m){p.parent?p.parent.playing=!!m:p._playing=!!m},get rate(){return p.parent?p.parent.rate:p._rate},set rate(m){const g=Number(m);Number.isFinite(g)&&(p.parent?p.parent.rate=g:p._rate=g)},get ended(){return p.parent?p.parent.ended:p._ended},set ended(m){p.parent?p.parent.ended=!!m:p._ended=!!m},play(){return p.parent?p.parent.play():(p._playing=!0,p._ended=!1,p)},pause(){return p.parent?p.parent.pause():(p._playing=!1,p)},stop(){return p.parent?p.parent.stop():(p._playing=!1,p.frame=0,p._ended=!1,p)},setFrame(m){if(p.parent)return p.parent.setFrame(m);const g=Number(m);return Number.isFinite(g)&&(p.frame=g),p},getFrame(){return p.parent?p.parent.getFrame():p.frame},setRate(m){return p.parent?p.parent.setRate(m):(p.rate=m,p)},addEndedCallback(m){return p.parent?p.parent.addEndedCallback(m):(typeof m=="function"&&l.push(m),p)},isPlaying(){return p.playing},setBlend(){return p},setVisible(){return p},advance(m){if(p.parent||!p._playing)return;const g=p.frame;if(p.frame+=(Number(m)||0)*n*p._rate,i==="single")if(p.frame>=r){if(p.frame=r,p._playing=!1,!p._ended){p._ended=!0;for(const w of l)try{w()}catch{}}}else p.frame<0&&(p.frame=0,p._playing=!1);iy(p,g,p.frame)},takeEvents(){if(!p._eventQueue.length)return[];const m=p._eventQueue.slice();return p._eventQueue.length=0,m},value(){const m=td(p.parent?p.parent.frame:p.frame,r,i),g=o?{length:r}:void 0;if(c.length===1)return da(c[0],m,g);const w=[];for(const y of c)w.push(da(y,m,g));return w},applyTo(m){const g=p.value();if(!a)return g;const w=ry(m);return Array.isArray(g)?g.map((y,b)=>y+(Number(w[b])||0)):g+(Number(w[0])||0)}};return p}function sy(){const t={name:"",mode:"single",fps:30,relative:!1,channelCount:0,parentKey:null,childKeys:[],parent:null,frame:0,rate:1,playing:!1,ended:!1,get frameCount(){return 0},play(){return t},pause(){return t},stop(){return t},setFrame(){return t},getFrame(){return 0},setRate(){return t},addEndedCallback(){return t},isPlaying(){return!1},setBlend(){return t},setVisible(){return t},advance(){},takeEvents(){return[]},value(){return 0},applyTo(e){return e}};return t}const ay=Object.freeze(Object.defineProperty({__proto__:null,createAnimation:id,createNeutralAnimation:sy,crossedEvents:nd,linkAnimations:rd,sampleChannel:da,wrapFrame:td},Symbol.toStringTag,{value:"Module"}));function oy(t,e,n,r){const i=s=>ha(e,s(e,n),r);switch(t){case 1:return i((s,a)=>[Math.min(a[0],s[0]),Math.min(a[1],s[1]),Math.min(a[2],s[2])]);case 2:return i((s,a)=>[s[0]*a[0],s[1]*a[1],s[2]*a[2]]);case 3:return i((s,a)=>[a[0]===0?0:Math.max(1-(1-s[0])/a[0],0),a[1]===0?0:Math.max(1-(1-s[1])/a[1],0),a[2]===0?0:Math.max(1-(1-s[2])/a[2],0)]);case 4:return i((s,a)=>[Math.max(s[0]+a[0]-1,0),Math.max(s[1]+a[1]-1,0),Math.max(s[2]+a[2]-1,0)]);case 5:return[Math.min(e[0],n[0]),Math.min(e[1],n[1]),Math.min(e[2],n[2])];case 6:return i((s,a)=>[Math.max(a[0],s[0]),Math.max(a[1],s[1]),Math.max(a[2],s[2])]);case 7:return i((s,a)=>[1-(1-s[0])*(1-a[0]),1-(1-s[1])*(1-a[1]),1-(1-s[2])*(1-a[2])]);case 8:return i((s,a)=>[a[0]===1?1:Math.min(s[0]/(1-a[0]),1),a[1]===1?1:Math.min(s[1]/(1-a[1]),1),a[2]===1?1:Math.min(s[2]/(1-a[2]),1)]);case 9:return i((s,a)=>[Math.min(s[0]+a[0],1),Math.min(s[1]+a[1],1),Math.min(s[2]+a[2],1)]);case 10:return[Math.max(e[0],n[0]),Math.max(e[1],n[1]),Math.max(e[2],n[2])];case 11:return i((s,a)=>sd(s,a));case 12:return i((s,a)=>cy(s,a));case 13:return i((s,a)=>sd(a,s));case 14:return i((s,a)=>[bi(s[0],a[0]),bi(s[1],a[1]),bi(s[2],a[2])]);case 15:return i((s,a)=>[a[0]<.5?Math.max(s[0]+2*a[0]-1,0):Math.min(s[0]+2*(a[0]-.5),1),a[1]<.5?Math.max(s[1]+2*a[1]-1,0):Math.min(s[1]+2*(a[1]-.5),1),a[2]<.5?Math.max(s[2]+2*a[2]-1,0):Math.min(s[2]+2*(a[2]-.5),1)]);case 16:return i((s,a)=>[a[0]<.5?Math.min(s[0],2*a[0]):Math.max(s[0],2*(a[0]-.5)),a[1]<.5?Math.min(s[1],2*a[1]):Math.max(s[1],2*(a[1]-.5)),a[2]<.5?Math.min(s[2],2*a[2]):Math.max(s[2],2*(a[2]-.5))]);case 17:return i((s,a)=>[bi(s[0],a[0])<.5?0:1,bi(s[1],a[1])<.5?0:1,bi(s[2],a[2])<.5?0:1]);case 18:return i((s,a)=>[Math.abs(s[0]-a[0]),Math.abs(s[1]-a[1]),Math.abs(s[2]-a[2])]);case 19:return i((s,a)=>[s[0]+a[0]-2*s[0]*a[0],s[1]+a[1]-2*s[1]*a[1],s[2]+a[2]-2*s[2]*a[2]]);case 20:return i((s,a)=>[Math.max(s[0]+a[0]-1,0),Math.max(s[1]+a[1]-1,0),Math.max(s[2]+a[2]-1,0)]);case 21:return i((s,a)=>[a[0]===1?1:Math.min(s[0]*s[0]/(1-a[0]),1),a[1]===1?1:Math.min(s[1]*s[1]/(1-a[1]),1),a[2]===1?1:Math.min(s[2]*s[2]/(1-a[2]),1)]);case 22:return i((s,a)=>[s[0]===1?1:Math.min(a[0]*a[0]/(1-s[0]),1),s[1]===1?1:Math.min(a[1]*a[1]/(1-s[1]),1),s[2]===1?1:Math.min(a[2]*a[2]/(1-s[2]),1)]);case 23:return i((s,a)=>[Math.min(s[0],a[0])-Math.max(s[0],a[0])+1,Math.min(s[1],a[1])-Math.max(s[1],a[1])+1,Math.min(s[2],a[2])-Math.max(s[2],a[2])+1]);case 24:return i((s,a)=>[(s[0]+a[0])/2,(s[1]+a[1])/2,(s[2]+a[2])/2]);case 25:return i((s,a)=>[1-Math.abs(1-s[0]-a[0]),1-Math.abs(1-s[1]-a[1]),1-Math.abs(1-s[2]-a[2])]);case 26:return i((s,a)=>ly(s,a));case 27:return i((s,a)=>uy(s,a));case 28:return i((s,a)=>fy(s,a));case 29:return i((s,a)=>dy(s,a));case 30:{const s=Math.max(e[0],Math.max(e[1],e[2]));return ha(e,[s*n[0],s*n[1],s*n[2]],r)}case 31:return[e[0]+n[0]*r,e[1]+n[1]*r,e[2]+n[2]*r];case 32:return ha(e,[e[0]+e[0]*n[0],e[1]+e[1]*n[1],e[2]+e[2]*n[2]],r);default:return ha(e,n,r)}}function ha(t,e,n){return[t[0]*(1-n)+e[0]*n,t[1]*(1-n)+e[1]*n,t[2]*(1-n)+e[2]*n]}function sd(t,e){const n=(r,i)=>r<.5?2*r*i:1-2*(1-r)*(1-i);return[n(t[0],e[0]),n(t[1],e[1]),n(t[2],e[2])]}function cy(t,e){const n=(r,i)=>i<.5?2*r*i+r*r*(1-2*i):Math.sqrt(r)*(2*i-1)+2*r*(1-i);return[n(t[0],e[0]),n(t[1],e[1]),n(t[2],e[2])]}function bi(t,e){if(e<.5){const r=2*e;return r===0?0:Math.max(1-(1-t)/r,0)}const n=2*(e-.5);return n===1?1:Math.min(t/(1-n),1)}function lr(t){const e=Math.min(t[0],Math.min(t[1],t[2])),n=Math.max(t[0],Math.max(t[1],t[2])),r=n-e,i=[0,0,0];if(i[2]=(n+e)/2,r===0)i[0]=0,i[1]=0;else{i[1]=i[2]<.5?r/(n+e):r/(2-n-e);const s=((n-t[0])/6+r/2)/r,a=((n-t[1])/6+r/2)/r,o=((n-t[2])/6+r/2)/r;t[0]===n?i[0]=o-a:t[1]===n?i[0]=1/3+s-o:t[2]===n&&(i[0]=2/3+a-s),i[0]<0?i[0]+=1:i[0]>1&&(i[0]-=1)}return i}function bc(t,e,n){return n<0?n+=1:n>1&&(n-=1),6*n<1?t+(e-t)*6*n:2*n<1?e:3*n<2?t+(e-t)*((2/3-n)*6):t}function ma(t){if(t[1]===0)return[t[2],t[2],t[2]];const e=t[2]<.5?t[2]*(1+t[1]):t[2]+t[1]-t[1]*t[2],n=2*t[2]-e;return[bc(n,e,t[0]+1/3),bc(n,e,t[0]),bc(n,e,t[0]-1/3)]}function ly(t,e){const n=lr(t);return ma([lr(e)[0],n[1],n[2]])}function uy(t,e){const n=lr(t);return ma([n[0],lr(e)[1],n[2]])}function fy(t,e){const n=lr(e);return ma([n[0],n[1],lr(t)[2]])}function dy(t,e){const n=lr(t);return ma([n[0],n[1],lr(e)[2]])}function ad(t){const e=t&&t.puppet&&t.puppet.animBound;return e?[e.x*Math.abs(t.scale[0]),e.y*Math.abs(t.scale[1])]:[0,0]}function od(t){for(const e of t&&t.effects||[]){if(e.visible===!1)continue;const n=Math.max((e.passes||[]).length,(e.materialPasses||[]).length);for(let r=0;r<n;r++){const i=e.passes&&e.passes[r]&&e.passes[r].combos||{},s=e.materialPasses&&e.materialPasses[r]&&e.materialPasses[r].combos||{},a=i.TRANSPARENCY!==void 0?i.TRANSPARENCY:s.TRANSPARENCY;if(Number(a)===0)return!0}}return!1}function pa(t,e,n){if(n||(n=new Set),!e)return n;for(const r of t.childIds||[]){const i=e.get(r);!i||i.particle||i.isPostProcess||(n.add(r),pa(i,e,n))}return n}function wc(t){const e=Zf[t]||"translucent";return{mode:e,prep:H0[e]||0}}function cd(t,e){const n=Number(t);return Number.isFinite(n)&&n!==0?n:e==="additive"?9:Number.isFinite(n)?n:0}function vc(t){const e=Number(t);return!Number.isFinite(e)||e===0?!1:!Zf[e]}function hy(t,e,n,r){if(vc(t))return oy(t,[e,e,e],[n,n,n],r)[0];const{mode:i,prep:s}=wc(t);let a=n;return s===1?a=n*r:s===2&&(a=1-r+n*r),i==="screen"?a+e*(1-a):i==="multiply"?e*a:i==="additive"?e+n*r:e*(1-r)+n*r}function ld(t,e,n){const r=t&&Number(t.scale)||1;let i=Math.max(1,Math.round(e/r)),s=Math.max(1,Math.round(n/r));const a=t&&Number(t.fit);if(Number.isFinite(a)&&a>0){const o=Math.max(i,s);if(o>a){const c=a/o;i=Math.max(1,Math.round(i*c)),s=Math.max(1,Math.round(s*c))}}return[i,s]}function ud(t){const e=t||{},n=(o,c)=>{const u=o!==null&&typeof o=="object"?o.value:o;return u===!0||u===1?!0:u===!1||u===0?!1:c},r=(o,c)=>{const u=o!==null&&typeof o=="object"?o.value:o;return typeof u=="number"&&Number.isFinite(u)?u:c};if(!n(e.bloom,!1))return null;const i=n(e.hdr,!1),s=r(i?e.bloomhdrstrength:e.bloomstrength,1.5),a=pc(e.bloomtint||"1 1 1");return{enabled:!0,hdr:i,strength:s,threshold:i?r(e.bloomhdrthreshold,.1):r(e.bloomthreshold,.65),iterations:Math.max(1,Math.round(i?r(e.bloomhdriterations,8):8)),radius:Math.max(0,i?r(e.bloomhdrscatter,3):3),damp:i?r(e.bloomhdrfeather,.5):.5,alpha:1,tint:a,metric:i?1:0}}function my(t){const e=Number(t);return!Number.isFinite(e)||e<.001?999:1/e}const ss=-1;function kc(t,e){return!!e&&!t}const py="mix(999.0, 1.0 / max(g_PointerScale, 0.001), step(0.001, g_PointerScale))";function fd(t){if(typeof t!="string"||/unprojectedUVs\s*\*=\s*mix\(999\.0,\s*1\.0\s*\/\s*max\(\s*g_PointerScale/.test(t))return t;const e=/unprojectedUVs\s*\*=\s*v_PointerScale\s*\*/.test(t),n=/unprojectedUVs\s*\*=\s*g_PointerScale\s*\*/.test(t);if(!e&&!n)return t;let r=t;/uniform\s+float\s+g_PointerScale\b/.test(r)||(r=r.replace(/void\s+main\s*\(/,`uniform float g_PointerScale;
|
|
349
|
+
void main(`));const i=e?/unprojectedUVs\s*\*=\s*v_PointerScale\s*\*/:/unprojectedUVs\s*\*=\s*g_PointerScale\s*\*/;return r.replace(i,"unprojectedUVs *= "+py+" *")}const dd=1;function hd(t,e){return t==="g_PointerScale"?dd:e}function gy(t,e={}){const n=t.getContext("webgl2",{premultipliedAlpha:!1,antialias:!1,alpha:!1,preserveDrawingBuffer:!0});if(!n)throw new Error("\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301 WebGL2");const r=e.shaderResolver||(async()=>null),i=e.diag||(()=>{}),s=typeof document<"u"?document.createElement("canvas"):null;s&&(s.style.cssText="position:fixed;left:-9999px;top:-9999px;width:2px;height:2px;opacity:0");let a=!1,o="";const c=3840,u=1024;let l=e.fboCapFactor===void 0?0:e.fboCapFactor,f=null,d=null,h=null;const p=[["g_AudioSpectrum16Left","left16"],["g_AudioSpectrum16Right","right16"],["g_AudioSpectrum32Left","left32"],["g_AudioSpectrum32Right","right32"],["g_AudioSpectrum64Left","left64"],["g_AudioSpectrum64Right","right64"]];function m(x){h=x||null}let g=null,w=null,y=null,b=null,v=null,k=null,A=null;const T=new Map,S=new Map,P=new Set;let M=null;const B={total:0,ok:0,failed:0};function N(x,_){g=typeof x=="function"?x:null,w=_&&_.userProperties||null,y=_&&_.audioViews||null,b=_&&_.shared||null,v=_&&_.inputView||null,k=_&&_.timers||null,A=_&&typeof _.onSandbox=="function"?_.onSandbox:null,M=_&&Array.isArray(_.animEventQueue)?_.animEventQueue:null,T.clear(),S.clear(),P.clear()}let U=!1,q=!1,H=0;typeof e.bloomDebugFrames=="number"&&e.bloomDebugFrames;const G=cr(n,is,$0),Y=cr(n,is,Q0),J=cr(n,is,Y0),ne=cr(n,W0,j0),fe=cr(n,q0,X0),Ne=cr(n,is,G0),Ze=cr(n,is,V0),je=n.createVertexArray();n.bindVertexArray(je);const Fe=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,Fe),n.enableVertexAttribArray(0),n.vertexAttribPointer(0,3,n.FLOAT,!1,20,0),n.enableVertexAttribArray(1),n.vertexAttribPointer(1,2,n.FLOAT,!1,20,12),n.bindVertexArray(null);const Le=new Map;let Pt=1;function Xe(x,_,V){const F=(V||"")+"|"+x+"x"+_;if(Le.has(F)){const D=Le.get(F);return D.stamp=Pt,D}const j=n.createFramebuffer(),X=n.createTexture();n.bindTexture(n.TEXTURE_2D,X),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,x,_,0,n.RGBA,n.UNSIGNED_BYTE,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindFramebuffer(n.FRAMEBUFFER,j),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,X,0),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.bindFramebuffer(n.FRAMEBUFFER,null);const K={fbo:j,tex:X,width:x,height:_,stamp:Pt};return Le.set(F,K),K}function Dt(){for(const[x,_]of Le)_.stamp!==Pt&&(_.fbo&&n.deleteFramebuffer(_.fbo),_.tex&&n.deleteTexture(_.tex),Le.delete(x))}const Oe=new Map,qe=new Map,ze=new Map;function st(x){const _={},V=/uniform\s+[A-Za-z0-9_]+\s+([A-Za-z_][A-Za-z0-9_]*)[^;]*;\s*\/\/([^\n]*)/g;let F;for(;(F=V.exec(x))!==null;){const j=F[1],X=F[2],K=/"material"\s*:\s*"([^"]+)"/.exec(X);if(!K)continue;const D=/"default"\s*:\s*("(?:[^"]*)"|-?\d+(?:\.\d+)?)/.exec(X);_[K[1]]={uniform:j,default:D?ki(D[1]):void 0}}return _}function ve(x){const _=new Map,V=/uniform\s+sampler2D\s+g_Texture(\d+)\s*;\s*\/\/([^\n]*)/g;let F;for(;(F=V.exec(x))!==null;){const j=Number(F[1]),X=/"default"\s*:\s*"([^"]+)"/.exec(F[2]);X&&X[1]&&_.set(j,X[1])}return _}function vn(x){const _=[],V=/uniform\s+sampler2D\s+(g_Texture(\d+))[^;]*;\s*\/\/([^\n]*)/g;let F;for(;(F=V.exec(x))!==null;){const j=/"combo"\s*:\s*"([^"]+)"/.exec(F[3]);j&&_.push({slot:Number(F[2]),name:F[1],combo:j[1]})}return _}function ki(x){if(x.startsWith('"'))return x.slice(1,-1);const _=Number(x);return Number.isFinite(_)?_:void 0}async function an(x,_,V){let F=ze.get(x);if(F===void 0){const K=await r("shaders/"+x+".frag")||"",D=await r("shaders/"+x+".vert")||"";F={frag:K,vert:D,texCombos:vn(K)},ze.set(x,F)}const j={..._};for(const K of F.texCombos)V&&V[K.slot]&&j[K.combo]===void 0&&(j[K.combo]=1);const X=x+"|"+JSON.stringify(j);if(Oe.has(X)){const K=Oe.get(X);if(K===null)throw new Error("shader="+x+" \u7F16\u8BD1\u5931\u8D25\uFF08\u5DF2\u7F13\u5B58\uFF09");return K}for(let K=0;K<4;K++){const D=new Set,z=I=>qe.has(I)?qe.get(I):(D.add(I),null),L=fd(Yf(F.frag,"frag",j,z,F.vert)),E=Yf(F.vert,"vert",j,z,F.frag);if(D.size===0){let I;try{I=cr(n,E,L)}catch(ee){throw Oe.set(X,null),new Error("shader="+x+" "+(ee&&ee.message))}const O=new Map,Q=n.getProgramParameter(I,n.ACTIVE_UNIFORMS);for(let ee=0;ee<Q;ee++){const ue=n.getActiveUniform(I,ee),we=ue.name.replace(/\[0\]$/,"");O.set(we,{loc:n.getUniformLocation(I,ue.name),type:ey[ue.type]||"unknown",size:ue.size})}const $={...st(F.vert),...st(F.frag)},Z=/gl_Position\s*=\s*vec4\s*\(\s*a_Position/.test(F.vert)&&!/[aA]_Position[\s\S]{0,40}mul\s*\(/.test(F.vert),se=new Map([...ve(F.vert),...ve(F.frag)]),te={prog:I,uni:O,matMeta:$,samplerDefaults:se,fragGlsl:L,vertGlsl:E,ndcDirect:Z};return Oe.set(X,te),te}await Promise.all(Array.from(D).map(async I=>{qe.set(I,await r("shaders/"+I)||"")}))}throw new Error("include \u89E3\u6790\u5931\u8D25: "+x)}const _t=gc(n,new Uint8Array([255,255,255,255]),1,1),dt=gc(n,new Uint8Array([0,0,0,0]),1,1);let At=null;function yr(x){At=x||null}function Gn(){if(!At)return null;const x=typeof At=="function"?At():At;return x&&x.state?x.state:x}const Te={x:0,y:0,sx:0,sy:0};let ys=0,on=0,br=0,cn=1/60,Ai=-1;const Ia=typeof e.fadeDuration=="number"&&e.fadeDuration>=0?e.fadeDuration:1,Ma=(x,_)=>{const V=x!==null&&typeof x=="object"?x.value:x;return V===!0||V===1?!0:V===!1||V===0?!1:_},$n=(x,_)=>{const V=x!==null&&typeof x=="object"?x.value:x;return typeof V=="number"&&Number.isFinite(V)?V:_},Et=x=>e.fade!==!1&&Ma(x.camerafade,!1);function bs(x,_){if(!Ma(x.camerashake,!1))return null;const V=$n(x.camerashakeamplitude,0);if(V===0)return null;const F=Math.max(0,Math.min(1,$n(x.camerashakeroughness,0))),j=$n(x.camerashakespeed,1),X=_*j,K=Math.sin(X*2.1)*Math.cos(X*.7),D=Math.cos(X*1.7)*Math.sin(X*.9),z=Math.sin(X*11.3)*Math.cos(X*7.1),L=Math.cos(X*9.7)*Math.sin(X*13.1);return{x:(K*(1-F)+z*F)*V,y:(D*(1-F)+L*F)*V}}function kn(){const x=new Date;return(x.getHours()*3600+x.getMinutes()*60+x.getSeconds())/86400}function Be(x,_,V){const F=x.get(_);F&&F.loc!==null&&V(F.loc,F.type,F.size)}function xi(x){if(typeof x=="number")return[x,x,x,x];const _=String(x).trim().split(/[\s,]+/).map(Number);return[_[0]||0,_[1]||0,_[2]||0,_[3]||0]}function Ba(x,_,V){const F=x.get(_);if(!F||F.loc===null)return;const j=V&&V.value!==void 0?V.value:V,X=xi(j);switch(F.type){case"float":n.uniform1f(F.loc,X[0]);break;case"int":case"bool":n.uniform1i(F.loc,j===!0||j===1?1:Math.round(X[0]));break;case"vec2":n.uniform2f(F.loc,X[0],X[1]);break;case"vec3":n.uniform3f(F.loc,X[0],X[1],X[2]);break;case"vec4":n.uniform4f(F.loc,X[0],X[1],X[2],X[3]);break;case"mat4":n.uniformMatrix4fv(F.loc,!1,Kt);break;case"mat3":n.uniformMatrix3fv(F.loc,!1,Ur);break}}const ws=()=>new Float32Array([1,0,0,0,1,0,0,0,1]);function Ti(x,_,V,F,j,X,K,D,z,L,E){if(Be(x,"g_Time",te=>n.uniform1f(te,V)),Be(x,"g_Daytime",te=>n.uniform1f(te,kn())),Be(x,"g_ModelViewProjectionMatrix",te=>n.uniformMatrix4fv(te,!1,X)),Be(x,"g_ModelMatrix",te=>n.uniformMatrix4fv(te,!1,K)),Be(x,"g_ViewProjectionMatrix",te=>n.uniformMatrix4fv(te,!1,D)),x.get("g_ModelViewProjectionMatrixInverse")){let te=null;for(const[ue,we]of z)ue===0&&(te=we);const ee=te&&te[0]>0&&te[1]>0?Gc(Ei(fn(),te[0]/2,te[1]/2,1)):Kt;Be(x,"g_ModelViewProjectionMatrixInverse",ue=>n.uniformMatrix4fv(ue,!1,ee))}Be(x,"g_Brightness",te=>n.uniform1f(te,_.brightness)),Be(x,"g_UserAlpha",te=>n.uniform1f(te,_.alpha)),Be(x,"g_Alpha",te=>n.uniform1f(te,_.alpha)),Be(x,"g_Color",te=>n.uniform3f(te,_.color[0],_.color[1],_.color[2])),Be(x,"g_Color4",te=>n.uniform4f(te,_.color[0],_.color[1],_.color[2],1)),Be(x,"g_CompositeColor",te=>n.uniform3f(te,_.color[0],_.color[1],_.color[2])),Be(x,"g_TexelSize",te=>n.uniform2f(te,1/F,1/j)),Be(x,"g_TexelSizeHalf",te=>n.uniform2f(te,.5/F,.5/j)),Be(x,"g_TextureReductionScale",te=>n.uniform1f(te,1));const I=Gn(),O=kc(!!(I&&I.has),!!x.get("g_PointerScale"));let Q=O?ss:I?I.u:.5,$=O?ss:I?I.v:.5,Z=O?ss:I?I.lastU:.5,se=O?ss:I?I.lastV:.5;if(E&&_&&_.size&&_.size[0]>0&&_.size[1]>0){const te=Math.abs(_.size[0]*_.scale[0]),ee=Math.abs(_.size[1]*_.scale[1]);if(te>0&&ee>0){const ue=_.origin[0]-te/2,we=E.projH-_.origin[1]-ee/2,ke=tt=>(E.offX+tt*E.viewW-ue)/te,ge=tt=>(E.offY+tt*E.viewH-we)/ee;Q=ke(Q),$=ge($),Z=ke(Z),se=ge(se)}}Be(x,"g_PointerPosition",te=>n.uniform2f(te,Q,$)),Be(x,"g_PointerPositionLast",te=>n.uniform2f(te,Z,se)),Be(x,"g_PointerState",te=>n.uniform4f(te,Q,$,I&&I.leftDown?1:0,0)),Be(x,"g_ParallaxPosition",te=>n.uniform2f(te,Te.sx*.5+.5,Te.sy*.5+.5)),Be(x,"g_Frametime",te=>n.uniform1f(te,cn)),x.get("g_EffectTextureProjectionMatrixInverse")&&Be(x,"g_EffectTextureProjectionMatrixInverse",te=>n.uniformMatrix4fv(te,!1,Kt));for(let te=0;te<8;te++)Be(x,"g_Texture"+te,ee=>n.uniform1i(ee,te));for(const[te,ee]of z)Be(x,"g_Texture"+te+"Resolution",ue=>n.uniform4f(ue,ee[0],ee[1],ee[2],ee[3]));if(h){const te=typeof h=="function"?h():h;if(te)for(const[ee,ue]of p){const we=te[ue];we&&Be(x,ee,ke=>n.uniform1fv(ke,we))}}}function qc(x,_,V){for(const[F,j]of Object.entries(_||{})){const X=V&&V[F];X&&Ba(x,X.uniform,j)}for(const[F,j]of Object.entries(V||{}))if(!_||!(F in _)){const X=hd(j.uniform,j.default);X!==void 0&&Ba(x,j.uniform,X)}}function Si(x){const _=Gn();kc(!!(_&&_.has),!!x.get("g_PointerScale"))&&Be(x,"g_PointerScale",V=>n.uniform1f(V,0))}function Nr(x,_){return _?typeof x=="number"&&Number.isFinite(x):!!x&&typeof x=="object"&&Number.isFinite(Number(x.x))&&Number.isFinite(Number(x.y))}function An(x,_,V,F){if(!x)return x;let j=!1;for(const K of Object.values(x))if(K!==null&&typeof K=="object"&&typeof K.script=="string"){j=!0;break}if(!j||!g)return x;const X={...x};for(const[K,D]of Object.entries(x)){if(D===null||typeof D!="object"||typeof D.script!="string")continue;const z=_+"|"+K;let L=T.get(z);if(L===void 0){B.total++;try{L=g(D.script,D.scriptproperties||D.scriptProperties||null,{userProperties:w||{},audioViews:y||void 0,layer:F||null,shared:b||{},inputView:v||void 0,setTimeout:k?k.setTimeout:void 0,clearTimeout:k?k.clearTimeout:void 0,setInterval:k?k.setInterval:void 0,clearInterval:k?k.clearInterval:void 0,getAnimationForProperty:()=>{const $=S.get(_+"|anim|"+K);return $?$.ctrl:null}})}catch{L=null}if(L?B.ok++:B.failed++,T.set(z,L),L){const $=D.value!==void 0?D.value:D,Z=xi($),se=typeof $=="number",te=se?Z[0]:{x:Z[0],y:Z[1],z:Z[2]},ee=L.init(te);L.__lastConstValue=Nr(ee,se)?ee:te}if(L&&typeof L.applyUserProperties=="function")try{L.applyUserProperties(w||{})}catch{}if(L&&(L.hasMediaHook||L.hasAnimEventHook)&&A)try{A(L,{layer:F,key:K})}catch{}}if(!L||L.disabled||!L.hasUpdate)continue;if(L.engine){L.engine.runtime=V,L.engine.frametime=cn,L.engine.timeOfDay=kn();const $=Gn();$&&$.screenW&&$.screenH&&(L.engine.screenResolution={x:$.screenW,y:$.screenH})}const E=typeof(D.value!==void 0?D.value:D)=="number";if(!Nr(L.__lastConstValue,E)){const $=xi(D.value!==void 0?D.value:D);L.__lastConstValue=E?$[0]:{x:$[0],y:$[1],z:$[2]}}const I=L.__lastConstValue;let O;try{O=L.callUpdate(I)}catch{O=void 0}const Q=O??I;if(Nr(Q,E)&&(L.__lastConstValue=Q),typeof Q=="number"&&Number.isFinite(Q))X[K]=Q;else if(Q&&typeof Q=="object"){const $=Number(Q.x),Z=Number(Q.y),se=Number(Q.z);Number.isFinite($)&&Number.isFinite(Z)&&(X[K]=Number.isFinite(se)?`${$} ${Z} ${se}`:`${$} ${Z} 0`)}}return X}function Ra(x,_,V,F){if(!x)return x;let j=!1;for(const D of Object.values(x))if(D&&typeof D=="object"&&D.animation&&D.animation.options){j=!0;break}if(!j)return x;const X={...x},K=new Map;for(const[D,z]of Object.entries(x)){if(!z||typeof z!="object"||!z.animation||!z.animation.options)continue;const L=_+"|anim|"+D;let E=S.get(L);if(!E){const I=id(z.animation),O=z.value!==void 0?z.value:0;I.baseNumeric=Array.isArray(O)?O.slice():O,E={ctrl:I,prevTime:V},S.set(L,E)}K.set(D,E.ctrl)}P.has(_)||(P.add(_),rd(K,D=>i(`${_}: ${D}`)));for(const[D,z]of Object.entries(x)){if(!z||typeof z!="object"||!z.animation||!z.animation.options)continue;const L=_+"|anim|"+D,E=S.get(L),I=V-E.prevTime;if(E.prevTime=V,E.ctrl.playing&&E.ctrl.advance(Math.max(0,I)),M){const O=E.ctrl.takeEvents();O.length&&M.push({layer:F,events:O})}else E.ctrl.takeEvents();X[D]=E.ctrl.applyTo(E.ctrl.baseNumeric)}return X}function vs(x,_,V,F){return x==null||x===""?null:x.startsWith("_rt_")?x.startsWith("_rt_imageLayerComposite")?As&&Wt.has(x)?Wt.get(x):_:V.has(x)?V.get(x):null:V.has(x)?V.get(x):F.get(x)||null}const Lr=Z0(),Or=J0(),wr=new Map;function Qn(x,_){const V=x+"x"+_;let F=wr.get(V);return F===void 0&&(F=K0(x,_),wr.set(V,F)),F}let Ct=null;function Qt(x,_){Ct!==x&&(n.bindBuffer(n.ARRAY_BUFFER,Fe),n.bufferData(n.ARRAY_BUFFER,_,n.DYNAMIC_DRAW),Ct=x)}const De={mvp:n.getUniformLocation(G,"u_MVP"),tex:n.getUniformLocation(G,"u_Tex"),color:n.getUniformLocation(G,"u_Color4"),frameOrigin:n.getUniformLocation(G,"u_FrameOrigin"),frameU:n.getUniformLocation(G,"u_FrameU"),frameV:n.getUniformLocation(G,"u_FrameV"),blendPrep:n.getUniformLocation(G,"u_BlendPrep")},Yt={mvp:n.getUniformLocation(Y,"u_MVP"),tex:n.getUniformLocation(Y,"u_Tex"),blendPrep:n.getUniformLocation(Y,"u_BlendPrep")},ln={mvp:n.getUniformLocation(J,"u_MVP"),tex:n.getUniformLocation(J,"u_Tex")},xn={mvp:n.getUniformLocation(Ze,"u_MVP"),tex:n.getUniformLocation(Ze,"u_Tex"),backdrop:n.getUniformLocation(Ze,"u_Backdrop"),blendMode:n.getUniformLocation(Ze,"u_BlendMode"),canvasSize:n.getUniformLocation(Ze,"u_CanvasSize"),opacity:n.getUniformLocation(Ze,"u_Opacity")},Tn={tex:n.getUniformLocation(ne,"u_Tex"),texel:n.getUniformLocation(ne,"u_Texel"),damp:n.getUniformLocation(ne,"u_Damp"),alpha:n.getUniformLocation(ne,"u_Alpha"),strength:n.getUniformLocation(ne,"u_Strength"),threshold:n.getUniformLocation(ne,"u_Threshold"),metric:n.getUniformLocation(ne,"u_Metric")},Nt={tex:n.getUniformLocation(fe,"u_Tex"),texel:n.getUniformLocation(fe,"u_Texel"),res:n.getUniformLocation(fe,"u_Res"),radius:n.getUniformLocation(fe,"u_Radius"),dir:n.getUniformLocation(fe,"u_Dir"),alpha:n.getUniformLocation(fe,"u_Alpha"),strength:n.getUniformLocation(fe,"u_Strength"),iterations:n.getUniformLocation(fe,"u_Iterations")},Yn={mvp:n.getUniformLocation(Ne,"u_MVP"),tex:n.getUniformLocation(Ne,"u_Tex"),alpha:n.getUniformLocation(Ne,"u_Alpha"),strength:n.getUniformLocation(Ne,"u_Strength"),tint:n.getUniformLocation(Ne,"u_Tint")},Kt=fn(),Ur=ws();function Sn(x){x==="translucent"?(n.enable(n.BLEND),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA)):x==="additive"?(n.enable(n.BLEND),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE,n.ONE,n.ONE)):n.disable(n.BLEND)}let zr=0;function Pi(x){const{mode:_,prep:V}=wc(x);zr=V,_==="additive"?(n.enable(n.BLEND),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE,n.ONE,n.ONE)):_==="multiply"?(n.enable(n.BLEND),n.blendFuncSeparate(n.DST_COLOR,n.ZERO,n.ONE,n.ONE_MINUS_SRC_ALPHA)):_==="screen"?(n.enable(n.BLEND),n.blendFuncSeparate(n.ONE,n.ONE_MINUS_SRC_COLOR,n.ONE,n.ONE_MINUS_SRC_ALPHA)):Sn("translucent")}function Hr(x,_){if(_&&_.perspective)return!1;const V=x.size[0]*x.scale[0],F=x.size[1]*x.scale[1];if(V===0||F===0)return!1;let j=Math.abs(V)/2,X=Math.abs(F)/2;const K=x.angles[2];if(K!==0){const Q=Math.abs(Math.cos(K)),$=Math.abs(Math.sin(K)),Z=j*Q+X*$,se=j*$+X*Q;j=Z,X=se}const D=x.origin[0],z=_.projH-x.origin[1];let L=64;x.parallaxDepth&&(L+=Math.abs($r(x.parallaxDepth[0])*on),L+=Math.abs($r(x.parallaxDepth[1])*br));const E=ad(x),I=L+E[0],O=L+E[1];return D+j+I<_.offX||D-j-I>_.offX+_.viewW||z+X+O<_.offY||z-X-O>_.offY+_.viewH}function ks(x,_,V){if(!x.spriteSheet)return null;const F=_&&_.frames,j=Array.isArray(F)?F:F&&F.list;if(!j||j.length===0)return null;const X=F&&F.atlasWidth||_.width||0,K=F&&F.atlasHeight||_.height||0;if(X<=0||K<=0)return null;x.spriteFrameCount=j.length;let D=0;const z=x.textureAnimation;if(z&&z.frame!==null&&z.frame!==void 0)D=Math.floor(Number(z.frame))||0,D>=0||(D=0),D>=j.length&&(D=j.length-1);else if(j.length>1){const $=z&&z.playing===!1;let Z=0;for(const se of j)Z+=se.duration>0?se.duration:1/30;if(!$&&Z>0){let se=V%Z;se<0&&(se+=Z);for(let te=0;te<j.length;te++){const ee=j[te].duration>0?j[te].duration:.03333333333333333;if(se<ee){D=te;break}se-=ee,D=te}}}const L=j[D],E=L.uDir?L.uDir[0]:L.width,I=L.uDir?L.uDir[1]:0,O=L.vDir?L.vDir[0]:0,Q=L.vDir?L.vDir[1]:L.height;return[L.x/X,L.y/K,E/X,I/K,O/X,Q/K]}function Vr(x,_){const V=x.size[0]*x.scale[0],F=x.size[1]*x.scale[1];let j=fn();if(_&&_.perspective){const K=vh(x,_);j=Gr(j,K[0],K[1],K[2]);const D=x.angles[0]||0,z=x.angles[1]||0;z&&(j=yh(j,z)),D&&(j=gh(j,D)),j=$c(j,-x.angles[2])}else{if(j=Gr(j,x.origin[0],_.projH-x.origin[1],x.origin[2]),x.parallaxDepth&&(on!==0||br!==0)){const K=$r(x.parallaxDepth[0]),D=$r(x.parallaxDepth[1]);j=Gr(j,K*on,D*br,0)}j=$c(j,-x.angles[2])}const X=Kf[x.alignment]||[.5,.5];return(X[0]!==.5||X[1]!==.5)&&(j=Gr(j,(.5-X[0])*V,(.5-X[1])*F,0)),{m:j,w:V,h:F}}function Wr(x,_,V,F,j,X,K,D,z=!1,L=null,E=null){const I=Vr(F,j);let O=I.m;if(E){const se=(E[0]+E[2]/2)*F.scale[0],te=(E[1]+E[3]/2)*F.scale[1];O=Gr(O,se,-te,0),O=Ei(O,E[2]*F.scale[0],E[3]*F.scale[1],1)}else O=Ei(O,I.w,I.h,1);const Q=dn(X,O);if(!z&&!ht&&vc(F.colorBlendMode)){const se=kr(K,D);n.useProgram(Ze),n.disable(n.BLEND),n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,K,D),n.bindVertexArray(je),Qt("local",Or),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,_),n.uniform1i(xn.tex,0),n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,se),n.uniform1i(xn.backdrop,1),n.uniform1i(xn.blendMode,Number(F.colorBlendMode)|0),n.uniform2f(xn.canvasSize,K,D),n.uniform1f(xn.opacity,V[3]),n.uniformMatrix4fv(xn.mvp,!1,Q),n.drawArrays(n.TRIANGLES,0,6),n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,null),n.activeTexture(n.TEXTURE0);return}const Z=x===Y?Yt:De;n.useProgram(x),z?(zr=0,n.enable(n.BLEND),F.containerAlphaMeaningful?n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA):n.blendFuncSeparate(n.ONE,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA)):Pi(cd(F.colorBlendMode,F.materialBlending)),Z.blendPrep!==null&&Z.blendPrep!==void 0&&n.uniform1i(Z.blendPrep,zr),ht?(n.bindFramebuffer(n.FRAMEBUFFER,ht.fbo.fbo),n.viewport(0,0,ht.w,ht.h)):(n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,K,D)),n.bindVertexArray(je),Qt("local",Or),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,_),n.uniform1i(Z.tex,0),n.uniformMatrix4fv(Z.mvp,!1,Q),Z.color!==null&&Z.color!==void 0&&n.uniform4f(Z.color,V[0],V[1],V[2],V[3]),un(Z,L),n.drawArrays(n.TRIANGLES,0,6)}function un(x,_){!x||x.frameOrigin===null||x.frameOrigin===void 0||(_?(n.uniform2f(x.frameOrigin,_[0],_[1]),n.uniform2f(x.frameU,_[2],_[3]),n.uniform2f(x.frameV,_[4],_[5])):(n.uniform2f(x.frameOrigin,0,0),n.uniform2f(x.frameU,1,0),n.uniform2f(x.frameV,0,1)))}let jr=null,ht=null;const Wt=new Map,qr=new Map;let As=!0;function Fa(x,_){const V=Vr(x,_),F=_&&_.perspective?x.scale[1]:-x.scale[1],j=_&&_.perspective&&x.scale[2]||1;return Ei(V.m,x.scale[0],F,j)}function vr(x,_,V,F,j,X,K){ht?(n.bindFramebuffer(n.FRAMEBUFFER,ht.fbo.fbo),n.viewport(0,0,ht.w,ht.h)):(n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,F,j)),K&&(n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,K),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.generateMipmap(n.TEXTURE_2D));const D=dn(V,Fa(x,_));jr(x,D,{time:X,overrideTex:K||null}),K&&(n.bindTexture(n.TEXTURE_2D,K),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR)),Ct=null}let Pn=null;function kr(x,_){return Pn===null&&(Pn=n.createTexture(),n.bindTexture(n.TEXTURE_2D,Pn),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE)),n.bindFramebuffer(n.FRAMEBUFFER,null),n.bindTexture(n.TEXTURE_2D,Pn),n.copyTexImage2D(n.TEXTURE_2D,0,n.RGB8,0,0,x,_,0),Pn}function Da(x,_,V){const F=kr(_,V),j=Math.max(1,Math.round(_/4)),X=Math.max(1,Math.round(V/4)),K=Xe(j,X,"bloomA"),D=Xe(j,X,"bloomB");n.bindVertexArray(je),Qt("pass",Lr),n.activeTexture(n.TEXTURE0),n.useProgram(ne),n.disable(n.BLEND),n.bindFramebuffer(n.FRAMEBUFFER,K.fbo),n.viewport(0,0,j,X),n.bindTexture(n.TEXTURE_2D,F),n.uniform1i(Tn.tex,0),n.uniform2f(Tn.texel,1/_,1/V),n.uniform1f(Tn.damp,x.damp),n.uniform1f(Tn.alpha,x.alpha),n.uniform1f(Tn.strength,x.strength),n.uniform1f(Tn.threshold,x.threshold),n.uniform1i(Tn.metric,x.metric),n.drawArrays(n.TRIANGLES,0,6),n.useProgram(fe);const z=(L,E,I,O)=>{n.bindFramebuffer(n.FRAMEBUFFER,E.fbo),n.viewport(0,0,E.width,E.height),n.bindTexture(n.TEXTURE_2D,L.tex),n.uniform1i(Nt.tex,0),n.uniform2f(Nt.texel,1/L.width,1/L.height),n.uniform2f(Nt.res,L.width,L.height),n.uniform1f(Nt.radius,x.radius),n.uniform2f(Nt.dir,I,O),n.uniform1f(Nt.alpha,x.alpha),n.uniform1f(Nt.strength,x.strength),n.uniform1f(Nt.iterations,x.iterations),n.drawArrays(n.TRIANGLES,0,6)};if(z(K,D,1,0),z(D,K,0,1),n.useProgram(Ne),n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,_,V),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE),n.bindTexture(n.TEXTURE_2D,K.tex),n.uniform1i(Yn.tex,0),n.uniformMatrix4fv(Yn.mvp,!1,Kt),n.uniform1f(Yn.alpha,x.alpha),n.uniform1f(Yn.strength,x.strength),n.uniform3f(Yn.tint,x.tint[0],x.tint[1],x.tint[2]),n.drawArrays(n.TRIANGLES,0,6),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA),H++,H===1||H===120||H===600){const L=new Uint8Array(4);n.bindFramebuffer(n.FRAMEBUFFER,K.fbo),n.readPixels(j>>1,X>>1,1,1,n.RGBA,n.UNSIGNED_BYTE,L),n.bindFramebuffer(n.FRAMEBUFFER,null),i(`bloom frame ${H}: center=[${[...L].join(",")}] glErr=${n.getError()} threshold=${x.threshold} strength=${x.strength} metric=${x.metric}`)}}function xs(x,_,V,F,j,X,K,D){const z=kr(K,D),L=Vr(x,j);let E=L.m;E=Ei(E,L.w,L.h,1);const I=dn(X,E),O=[[-.5,.5],[.5,.5],[-.5,-.5],[.5,-.5]].map(([ee,ue])=>{const we=Ah(I,ee,ue,0);return[we[0]*.5+.5,we[1]*.5+.5]}),[Q,$,Z,se]=O,te=new Float32Array([0,F,0,Q[0],Q[1],0,0,0,Z[0],Z[1],V,F,0,$[0],$[1],V,F,0,$[0],$[1],0,0,0,Z[0],Z[1],V,0,0,se[0],se[1]]);n.useProgram(J),Sn("normal"),n.disable(n.BLEND),n.bindFramebuffer(n.FRAMEBUFFER,_.fbo),n.viewport(0,0,V,F),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.bindVertexArray(je),n.bindBuffer(n.ARRAY_BUFFER,Fe),n.bufferData(n.ARRAY_BUFFER,te,n.DYNAMIC_DRAW),Ct=null,n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,z),n.uniform1i(ln.tex,0),n.uniformMatrix4fv(ln.mvp,!1,Xr(0,V,0,F,-1e4,1e4)),n.drawArrays(n.TRIANGLES,0,6),n.enable(n.BLEND)}function _i(x,_,V,F,j){if(!As||ht)return;const X=qr.get(x.id);if(!X||X.size===0)return;const K=Math.max(1,Math.round(Math.abs(x.size[0]*(x.scale[0]||1)))),D=Math.max(1,Math.round(Math.abs(x.size[1]*(x.scale[1]||1))));if(K<=1&&D<=1)return;const z=Xe(K,D,"lc:"+x.id);xs(x,z,K,D,_,V,F,j);for(const L of X)Wt.set(L,z);qr.delete(x.id),n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,F,j)}async function Na(x,_,V,F,j,X,K,D){Pt++,n.viewport(0,0,V,F);const z=x.general||{};if(z.clearenabled!==!1){const ee=pc(z.clearcolor||"0 0 0");n.clearColor(ee[0],ee[1],ee[2],1)}else n.clearColor(0,0,0,1);if(n.clear(n.COLOR_BUFFER_BIT),Ai>=0){const ee=j-Ai;cn=ee>0&&ee<1?ee:Math.min(.1,Math.max(.001,ee||1/60))}Ai=j;const L=Ph(x,V,F,X,K,D);let E=dn(L.projection,L.view);const I=z.cameraparallax,O=I===!0||I!==null&&typeof I=="object"&&I.value===!0;on=0,br=0;const Q=Gn();if(Q&&(Te.x=Q.u*2-1,Te.y=Q.v*2-1),!L.perspective&&e.parallax!==!1&&O){const ee=(be,Pe)=>{const ye=be!==null&&typeof be=="object"?be.value:be;return typeof ye=="number"&&Number.isFinite(ye)?ye:Pe},ue=ee(z.cameraparallaxamount,0),we=ee(z.cameraparallaxmouseinfluence,1),ke=ee(z.cameraparallaxdelay,1),ge=j-ys;ys=j;const tt=ge>0?1-Math.exp(-ge/Math.max(.05,ke)):1;Te.sx+=(Te.x-Te.sx)*tt,Te.sy+=(Te.y-Te.sy)*tt;const Re=ue*we,jt=60,Zt=Te.sx*Re*L.viewW,at=Te.sy*Re*L.viewH,xt=Math.max(Math.abs(Zt),Math.abs(at))/jt,_n=xt>1?1/xt:1;on=-(Zt*_n),br=-(at*_n)}if(!L.perspective&&e.shake!==!1){const ee=bs(z,j);if(ee){const ue=ee.x*L.viewW*.02,we=ee.y*L.viewH*.02;(ue!==0||we!==0)&&(E=dn(E,Gr(fn(),ue,we,0)))}}if(At){const ee=typeof At=="function"?At():At;ee&&typeof ee.syncWorld=="function"&&ee.syncWorld(L,0,0)}if(!U){U=!0;const ee=(x.layers||[]).filter(ke=>ke.isContainer),ue=ee.filter(ke=>(ke.effects||[]).some(ge=>ge.visible)&&!ke.hasChildren),we=ue.filter(ke=>(ke.effects||[]).some(ge=>(ge.materialPasses||[]).length>0));i(`containers total=${ee.length} canvasCandidates=${ue.length} passesResolved=${we.length} names=${ue.slice(0,4).map(ke=>ke.name||"?").join("/")}`)}await La(x,_,L,V,F,j);const $=new Map;for(const ee of x.layers)ee.id!==void 0&&$.set(ee.id,ee);const Z=new Set;for(const ee of x.layers)!ee.visible||ee.destroyed||!ee.isContainer||!ee.hasChildren||!(ee.effects||[]).some(we=>we.visible)||(ee.childIds||[]).length===0||pa(ee,$,Z);if(f)try{f()}catch(ee){i("particle advance error: "+(ee&&ee.message))}const se=L.perspective?x.layers.slice().sort((ee,ue)=>+!!ue.isSkybox-+!!ee.isSkybox):x.layers;for(const ee of se)if(!ee.destroyed){if(!ee.visible){qr.has(ee.id)&&_i(ee,L,E,V,F);continue}if(!(ee.isPostProcess&&!(ee.effects||[]).some(ue=>ue.visible))&&!Z.has(ee.id)){if(ee.isContainer){if(!(ee.effects||[]).some(we=>we.visible)){_i(ee,L,E,V,F);continue}if(ee.hasChildren){(ee.childIds||[]).length>0&&await C(ee,x,_,L,E,V,F,j);continue}}if(ee.particle){if(d)try{await d(ee.id,L,E,V,F)}catch(ue){i("particle render error: "+(ue&&ue.message))}continue}Hr(ee,L)||await W(ee,_,L,E,V,F,j)}}if(Et(z)&&j<Ia){const ee=Math.max(0,Math.min(1,j/Ia)),ue=1-ee*ee*(3-2*ee);if(ue>.002){const we=pc(z.clearcolor||"0 0 0");n.useProgram(G),n.enable(n.BLEND),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA),n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,V,F),n.bindVertexArray(je),Qt("pass",Lr),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,_t),n.uniform1i(De.tex,0),n.uniform4f(De.color,we[0],we[1],we[2],ue),un(De,null),De.blendPrep!==null&&De.blendPrep!==void 0&&n.uniform1i(De.blendPrep,0),n.uniformMatrix4fv(De.mvp,!1,Kt),n.drawArrays(n.TRIANGLES,0,6)}}const te=ud(z);q||(q=!0,i(te?`bloom post: on strength=${te.strength} threshold=${te.threshold} iter=${te.iterations} radius=${te.radius} damp=${te.damp} hdr=${te.hdr}`:"bloom post: off")),te&&te.strength>.001&&Da(te,V,F),n.bindVertexArray(null),Dt()}async function La(x,_,V,F,j,X){Wt.clear(),qr.clear();const K=new Map,D=new Set;let z=null;const L=E=>{if(typeof E!="string")return;const I=/^_rt_imageLayerComposite_(\d+)_[a-z]$/.exec(E);if(!I)return;const O=Number(I[1]);z!==null&&O===z&&D.add(O);let Q=K.get(O);Q||(Q=new Set,K.set(O,Q)),Q.add(E)};for(const E of x.layers||[]){z=E.id;for(const I of E.effects||[])if(I.visible){for(const O of I.passes||[])for(const Q of O.textures||[])L(Q);for(const O of I.materialPasses||[]){for(const Q of O.binds||[])L(Q&&Q.name);for(const Q of O.textures||[])L(Q)}}}if(K.size!==0){for(const[E,I]of K){const O=(x.layers||[]).find(Re=>Re.id===E);if(!O||O.particle||O.isPostProcess||D.has(E))continue;const Q=typeof O.image=="string"?O.image:"";if(O.isContainer&&!O.hasChildren&&Q.indexOf("models/util/composelayer")===0&&!(O.effects||[]).some(Re=>Re.visible)){qr.set(E,I);continue}const Z=Math.max(1,Math.round(Math.abs(O.size[0]*(O.scale[0]||1)))),se=Math.max(1,Math.round(Math.abs(O.size[1]*(O.scale[1]||1))));if(Z<=1&&se<=1)continue;const te=Xe(Z,se,"lc:"+E);n.bindFramebuffer(n.FRAMEBUFFER,te.fbo),n.viewport(0,0,Z,se),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT);const ee={view:V.view,projection:Xr(0,Z,0,se,-1e4,1e4),eye:V.eye,projW:Z,projH:se,offX:0,offY:0,viewW:Z,viewH:se},ue=ht,we=O.origin,ke=O.scale,ge=O.angles,tt=O.visible;ht={fbo:te,w:Z,h:se},O.origin=[Z/2,ee.projH-se/2,we[2]],O.scale=[Math.sign(ke[0])||1,Math.sign(ke[1])||1,ke[2]],O.angles=[0,0,0],O.visible=!0;try{await W(O,_,ee,ee.projection,Z,se,X);for(const Re of I)Wt.set(Re,te)}catch(Re){i(`composite \u6E90\u5C42 ${E} \u6E32\u67D3\u5931\u8D25: ${Re&&Re.message}`)}finally{ht=ue,O.origin=we,O.scale=ke,O.angles=ge,O.visible=tt}}n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,F,j)}}async function C(x,_,V,F,j,X,K,D){const z=Math.max(1,Math.round(Math.abs(x.size[0]))),L=Math.max(1,Math.round(Math.abs(x.size[1])));if((x.childIds||[]).length===0)return;const I=new Map;for(const ge of _.layers)ge.id!==void 0&&I.set(ge.id,ge);const O=pa(x,I),Q=_.layers.filter(ge=>O.has(ge.id)&&ge.visible);if(Q.length===0)return;const $=Xe(z,L,"group");n.bindFramebuffer(n.FRAMEBUFFER,$.fbo),n.viewport(0,0,z,L),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT);const Z={view:F.view,projection:Xr(0,z,0,L,-1e4,1e4),eye:F.eye,projW:z,projH:L,offX:0,offY:0,viewW:z,viewH:L},se=Z.projection,te=x.scale[0]||1,ee=x.scale[1]||1,ue=x.angles[2]||0,we=Math.cos(-ue),ke=Math.sin(-ue);ht={fbo:$,w:z,h:L};try{for(const ge of Q){if(ge.isPostProcess||ge.particle||ge.isContainer&&(ge.childIds||[]).length>0)continue;const tt=ge.origin,Re=ge.scale,jt=ge.angles,Zt=tt[0]-x.origin[0],at=tt[1]-x.origin[1],xt=(Zt*we-at*ke)/te,_n=(Zt*ke+at*we)/ee;ge.origin=[z/2+xt,L/2+_n,tt[2]],ge.scale=[Re[0]/te,Re[1]/ee,Re[2]],ge.angles=[jt[0],jt[1],jt[2]-ue];try{await W(ge,V,Z,se,z,L,D)}finally{ge.origin=tt,ge.scale=Re,ge.angles=jt}}}finally{ht=null}x.groupTex=$.tex,x.groupW=z,x.groupH=L;try{await W(x,V,F,j,X,K,D)}finally{x.groupTex=null}}async function W(x,_,V,F,j,X,K){const D=!!(x.puppet&&jr),z=!x.solid&&x.textureName?_.get(x.textureName):null;if(z&&z.video){const be=z.video;if(be.readyState>=2&&be.currentTime!==z.lastUploaded){n.bindTexture(n.TEXTURE_2D,z.glTex);try{let Pe=be.videoWidth||z.width,ye=be.videoHeight||z.height;const He=Math.max(j||0,X||0),Kn=n.getParameter(n.MAX_TEXTURE_SIZE)||0;let ot=c;Kn>0&&(ot=Math.min(ot,Kn)),He>0&&(ot=Math.min(ot,He)),ot=Math.max(ot,u);let Ar=1;Math.max(Pe,ye)>ot&&(Ar=ot/Math.max(Pe,ye));const qt=Math.max(1,Math.round(Pe*Ar)),nt=Math.max(1,Math.round(ye*Ar));let Oa=be;if(s&&qt>0&&nt>0){(s.width!==qt||s.height!==nt)&&(s.width=qt,s.height=nt);const Zn=s.getContext("2d");Zn&&(Zn.clearRect(0,0,qt,nt),Zn.drawImage(be,0,0,qt,nt),Oa=s)}if(n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,Oa),n.getError()!==n.NO_ERROR&&s)try{const Lt=s.getContext("2d").getImageData(0,0,s.width,s.height);for(n.texImage2D(n.TEXTURE_2D,0,n.RGBA,s.width,s.height,0,n.RGBA,n.UNSIGNED_BYTE,new Uint8Array(Lt.data.buffer));n.getError()!==n.NO_ERROR;);}catch{}z.width=qt,z.height=nt,z.lastUploaded=be.currentTime,o!==qt+"x"+nt&&(o=qt+"x"+nt,a=!0,i("video tex ready "+qt+"x"+nt+" (src "+Pe+"x"+ye+", limit "+ot+")"))}catch(Pe){a||(a=!0,i("video upload FAIL: "+(Pe&&Pe.message||Pe))),console.warn("[we-scene] \u89C6\u9891\u5E27\u4E0A\u4F20\u5931\u8D25:",Pe&&Pe.message,"readyState=",be.readyState,"cur=",be.currentTime)}}}const L=x.groupTex?x.groupTex:z&&z.glTex?z.glTex:x.solid?_t:dt,E=(!!x.passthrough||!!x.isPostProcess||od(x))&&!x.groupTex&&!z&&!D;let I,O;if(x.groupTex?(I=x.groupW||x.size[0],O=x.groupH||x.size[1]):D||!z?(I=x.size[0],O=x.size[1]):(I=z.width,O=z.height),!D&&z&&x.spriteSheet){const be=z.frames,Pe=Array.isArray(be)?be:be&&be.list;Pe&&Pe.length&&(I=Pe[0].width||I,O=Pe[0].height||O)}const Q=Math.max(1,Math.round(I)),$=Math.max(1,Math.round(O)),Z=[x.color[0]*x.brightness,x.color[1]*x.brightness,x.color[2]*x.brightness,x.alpha],se=(x.effects||[]).filter(be=>be.visible);let te=Q,ee=$;if(l>0&&V.projW>0&&V.projH>0){const be=Math.min(Math.abs(x.size[0]*x.scale[0]),V.viewW),Pe=Math.min(Math.abs(x.size[1]*x.scale[1]),V.viewH),ye=be*(j/V.projW),He=Pe*(X/V.projH);if(ye>0&&He>0){const Kn=Math.max(64,Math.round(ye*l)),ot=Math.max(64,Math.round(He*l));Kn<Q&&(te=Kn),ot<$&&(ee=ot)}}if(se.length===0){D?vr(x,V,F,j,X,K):Wr(G,L,Z,x,V,F,j,X,!1,ks(x,z,K));return}const ue=Xe(te,ee,"ping"),we=Xe(te,ee,"pong"),ke=Xr(0,te,0,ee,-1e4,1e4);if(D)n.useProgram(G),Sn("normal"),n.bindFramebuffer(n.FRAMEBUFFER,ue.fbo),n.viewport(0,0,te,ee),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.bindVertexArray(je),Ct=null,Qt("layer"+te+"x"+ee,Qn(te,ee)),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,L),n.uniform1i(De.tex,0),n.uniform4f(De.color,1,1,1,1),un(De,null),De.blendPrep!==null&&De.blendPrep!==void 0&&n.uniform1i(De.blendPrep,0),n.uniformMatrix4fv(De.mvp,!1,ke),n.drawArrays(n.TRIANGLES,0,6);else if(E)xs(x,ue,te,ee,V,F,j,X);else{n.useProgram(G),Sn("normal"),n.bindFramebuffer(n.FRAMEBUFFER,ue.fbo),n.viewport(0,0,te,ee),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.bindVertexArray(je),Qt("layer"+te+"x"+ee,Qn(te,ee)),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,L),n.uniform1i(De.tex,0);const be=se.some(Pe=>Pe&&Pe.layerMaterial)?[1,1,1,Z[3]]:Z;n.uniform4f(De.color,be[0],be[1],be[2],be[3]),un(De,ks(x,z,K)),De.blendPrep!==null&&De.blendPrep!==void 0&&n.uniform1i(De.blendPrep,0),n.uniformMatrix4fv(De.mvp,!1,ke),n.drawArrays(n.TRIANGLES,0,6)}let ge=ue,tt=we;const Re=new Map;let jt=!1,Zt=ue;const at=[],xt=new Set;for(const be of se){for(const ye of be.fbos||[])if(!Re.has(ye.name)){const[He,Kn]=ld(ye,te,ee),ot=ye.unique?x.id+":"+ye.name:ye.name;Re.set(ye.name,Xe(He,Kn,ot))}const Pe=be.materialPasses||[];for(let ye=0;ye<Pe.length;ye++)at.push({eff:be,mp:Pe[ye],ov:be.passes&&be.passes[ye]})}const _n=[];for(let be=0;be<at.length;be++){const{eff:Pe,mp:ye,ov:He}=at[be];if(xt.has(Pe))continue;const Kn={...ye.combos||{},...He&&He.combos||{}},ot=ye.textures||[],Ar=He&&He.textures||[],qt=[];for(let Me=0;Me<Math.max(ot.length,Ar.length);Me++)Ar[Me]!==void 0&&Ar[Me]!==null?qt[Me]=Ar[Me]:qt[Me]=ot[Me]!==void 0?ot[Me]:null;if(ye.copyCommand){const Me=ye.source?Re.get(ye.source):null,rt=ye.target?Re.get(ye.target):null;Me&&rt&&(n.useProgram(Y),Sn("normal"),n.bindFramebuffer(n.FRAMEBUFFER,rt.fbo),n.viewport(0,0,rt.width,rt.height),n.bindVertexArray(je),Qt("pass",Lr),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,Me.tex),n.uniform1i(Yt.tex,0),Yt.blendPrep!==null&&Yt.blendPrep!==void 0&&n.uniform1i(Yt.blendPrep,0),n.uniformMatrix4fv(Yt.mvp,!1,Kt),n.drawArrays(n.TRIANGLES,0,6),n.bindFramebuffer(n.FRAMEBUFFER,null));continue}let nt;try{nt=await an(ye.shader,Kn,qt)}catch(Me){const rt=Me&&Me.message||String(Me);/已缓存/.test(rt)||console.warn("[we-scene] \u8DF3\u8FC7\u6548\u679C\uFF08pass \u7F16\u8BD1\u5931\u8D25\uFF09:",ye.shader,rt),xt.add(Pe);continue}const Oa=nt.prog,Zn=nt.uni;nt.fragGlsl&&_n.push(nt.fragGlsl);let Lt,Ts;ye.target?(jt||(Zt=ge,jt=!0),Lt=Re.get(ye.target)||ge,Ts=Zt):(jt=!1,Lt=tt,Ts=ge),n.useProgram(Oa),Sn(ye.blending||"normal"),n.bindFramebuffer(n.FRAMEBUFFER,Lt.fbo),n.viewport(0,0,Lt.width,Lt.height),n.bindVertexArray(je);const mh=!nt.ndcDirect;mh?Qt("passPx"+Lt.width+"x"+Lt.height,Qn(Lt.width,Lt.height)):Qt("pass",Lr);const iw=mh?Gc(Xr(0,Lt.width,0,Lt.height,-1e4,1e4)):Kt,Xc=ye.textures||[],sw=Math.max(Xc.length,8),ph=new Map,aw=new Set;for(let Me=0;Me<sw;Me++){let rt=Me<Xc.length?Xc[Me]:null;He&&He.textures&&He.textures[Me]!==void 0&&He.textures[Me]!==null&&(rt=He.textures[Me]);for(const Ps of ye.binds||[])Ps.index===Me&&(rt=Ps.name);let En;if(Me===0&&(rt==null||rt===""))En=Ts;else{if((rt==null||rt==="")&&nt.samplerDefaults){const Ps=nt.samplerDefaults.get(Me);Ps&&(rt=Ps)}En=vs(rt,Ts,Re,_)}rt==="previous"&&(En=Ts),En===null&&(En={glTex:_t,width:1,height:1,tex:_t});const Ss=En.fbo?En:{tex:En.glTex||_t,width:En.width||1,height:En.height||1};n.activeTexture(n.TEXTURE0+Me),n.bindTexture(n.TEXTURE_2D,Ss.tex),aw.add(Me),ph.set(Me,[Ss.width,Ss.height,Ss.width,Ss.height])}Ti(Zn,x,K,V.projW,V.projH,iw,ke,Kt,ph,ke,V),qc(Zn,Ra(An({...ye.constants||{},...He&&He.constantshadervalues||{}},(x.id||x.name||"?")+"|"+(ye.shader||"?")+"|"+be,K,x),(x.id||x.name||"?")+"|"+(ye.shader||"?")+"|"+be,K,x),nt.matMeta),Si(Zn),n.drawArrays(n.TRIANGLES,0,6),ye.target||(tt=ge,ge=Lt)}if(x.isContainer&&!x.groupTex&&!E&&x.containerAlphaMeaningful===void 0){let be=!1;for(const Pe of _n){if(typeof Pe!="string")continue;const ye=Pe.match(/\bfloat\s+alpha\s*=\s*([^;]+);/);if(ye&&!/^\s*scene\s*\.\s*a\s*$/.test(ye[1])){be=!0;break}}x.containerAlphaMeaningful=be,i(`container "${x.name||"?"}" alpha ${be?"\u643A\u5E26\u5F62\u72B6 \u2192 SRC_ALPHA":"\u65E0\u4FE1\u606F \u2192 \u52A0\u6CD5"}`)}if(D){vr(x,V,F,j,X,K,ge.tex);return}Wr(Y,ge.tex,[1,1,1,1],x,V,F,j,X,!!x.isContainer&&!x.groupTex&&!E,null,null)}return{gl:n,render:Na,getFBO:Xe,getEffectProgram:an,progCache:Oe,shaderResolver:r,whiteTex:_t,resetShaderCaches:function(){Oe.clear(),qe.clear(),ze&&ze.clear()},setFboCapFactor:function(x){l=x},setParticleRenderer:function(x,_){f=typeof x=="function"?x:null,d=typeof _=="function"?_:null},setConstantScriptRuntime:N,applyConstUserProperties:function(x){if(x){for(const _ of T.values())if(_&&typeof _.applyUserProperties=="function")try{_.applyUserProperties(x)}catch{}}},constantScriptStats:function(){return{...B,cached:T.size}},setCompositeEnabled:function(x){As=!!x},compositeStats:function(){const x=[],_=new Uint8Array(4);for(const[V,F]of Wt){let j=null;try{n.bindFramebuffer(n.FRAMEBUFFER,F.fbo),n.readPixels(F.w>>1,F.h>>1,1,1,n.RGBA,n.UNSIGNED_BYTE,_),j=[_[0],_[1],_[2],_[3]]}catch{}x.push({name:V,w:F.w,h:F.h,center:j})}return n.bindFramebuffer(n.FRAMEBUFFER,null),x},setPuppetRenderer:function(x){jr=x},setAudioProvider:m,setPointerProvider:yr,getParallaxOffset:function(){return{x:on,y:br}},dispose:function(){try{const x=n.getExtension("WEBGL_lose_context");x&&x.loseContext()}catch{}}}}const yy=Object.freeze(Object.defineProperty({__proto__:null,ALIGN:Kf,XRAY_IDLE_SCREEN_UV:ss,XRAY_SIZE_FALLBACK:dd,applyColorBlendCPU:hy,bloomPostParams:ud,collectGroupDescendantIds:pa,colorBlendPlan:wc,constantFallback:hd,createRenderer:gy,effectFboSize:ld,layerCompositeBlendMode:cd,layerWantsPreserveBackdrop:od,makeTexture:gc,makeTextureMip:ty,needsShaderBlend:vc,puppetAnimMargin:ad,rewriteXrayFragScale:fd,xrayShouldParkPointer:kc,xrayUvScale:my},Symbol.toStringTag,{value:"Module"}));function by(t=256,e=8){const n=t/e,r=md(1337),i=md(4242),s=new Float32Array(n*n),a=new Float32Array(n*n);for(let u=0;u<n*n;u++)s[u]=r(),a[u]=i();const o=new Uint8Array(t*t*4),c=e;for(let u=0;u<t;u++){const l=Math.floor(u/c),f=u%c/c,d=f*f*(3-2*f);for(let h=0;h<t;h++){const p=Math.floor(h/c),m=h%c/c,g=m*m*(3-2*m),w=p%n,y=(p+1)%n,b=l%n,v=(l+1)%n,k=s[b*n+w],A=s[b*n+y],T=s[v*n+w],S=s[v*n+y],P=a[b*n+w],M=a[b*n+y],B=a[v*n+w],N=a[v*n+y],U=k+(A-k)*g+(T-k)*d+(k-A-T+S)*g*d,q=P+(M-P)*g+(B-P)*d+(P-M-B+N)*g*d,H=(u*t+h)*4;o[H]=Math.round(U*255),o[H+1]=Math.round(q*255),o[H+2]=0,o[H+3]=255}}return o}function md(t){let e=t>>>0;return()=>{e|=0,e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}const wy=Object.freeze(Object.defineProperty({__proto__:null,generateNoiseTexture:by},Symbol.toStringTag,{value:"Module"})),nn=Math.PI*2;function Je(t,e){return t==null?Math.random():e==null?t:t+Math.random()*(e-t)}function pd(t,e,n){if(t==null)return Math.random();if(e==null)return t;const r=n&&n!==1?Math.pow(Math.random(),n):Math.random();return t+r*(e-t)}function Ce(t,e){if(Array.isArray(t))return[t[0]||0,t[1]||0,t[2]||0];if(t==null)return e?e.slice():[0,0,0];if(typeof t=="object")return Ce(t.value,e);if(typeof t=="number")return[t,t,t];const n=String(t).trim().split(/\s+/).map(Number);return[n[0]||0,n[1]||0,n[2]||0]}function gd(t){return t==null?null:typeof t=="number"?[t,t,t]:Ce(t)}function oe(t,e){if(t==null)return e;if(typeof t=="object")return oe(t.value,e);const n=Number(t);return Number.isFinite(n)?n:e}function Ac(t,e){const n=t[0],r=t[1]>n?t[1]:n+1e-6,i=Math.min(1,Math.max(0,(e-n)/(r-n)));return i*i*(3-2*i)}function ur(t,e,n){const r=Math.sin(t*127.1+e*311.7+n*74.7)*43758.5453;return r-Math.floor(r)}function vy(t,e,n){const r=Math.floor(t),i=Math.floor(e),s=Math.floor(n),a=t-r,o=e-i,c=n-s,u=a*a*(3-2*a),l=o*o*(3-2*o),f=c*c*(3-2*c),d=(w,y,b)=>w+(y-w)*b,h=d(ur(r,i,s),ur(r+1,i,s),u),p=d(ur(r,i+1,s),ur(r+1,i+1,s),u),m=d(ur(r,i,s+1),ur(r+1,i,s+1),u),g=d(ur(r,i+1,s+1),ur(r+1,i+1,s+1),u);return d(d(h,p,l),d(m,g,l),f)}function xc(t,e,n,r){let i=0,s=.5,a=1,o=0;for(let c=0;c<r;c++)i+=s*vy(t*a,e*a,n*a),o+=s,s*=.5,a*=2;return i/(o||1)}function Tc(t,e,n,r){return[xc(t,e,n,r)*2-1,xc(t+31.7,e+11.3,n+57.1,r)*2-1,xc(t+73.9,e+92.1,n+13.7,r)*2-1]}function ky(t){const e=`#version 300 es
|
|
67
350
|
// \u5355\u4F4D quad\uFF08TRIANGLE_STRIP 4 \u9876\u70B9\uFF09\uFF0C\u6309\u5B9E\u4F8B\u7684 size/rot \u5C55\u5F00\u4E3A\u671D\u5C4F\u5E55\u7684\u7CBE\u7075
|
|
68
351
|
layout(location=0) in vec2 a_corner; // -0.5..0.5
|
|
69
352
|
layout(location=1) in vec3 a_pos; // \u5B9E\u4F8B\u4E2D\u5FC3\uFF08\u6295\u5F71\u7A7A\u95F4\u4E16\u754C\u5750\u6807\uFF09
|
|
@@ -100,7 +383,7 @@ void main(){
|
|
|
100
383
|
}
|
|
101
384
|
v_uv = uv;
|
|
102
385
|
v_color = a_color;
|
|
103
|
-
}`,
|
|
386
|
+
}`,n=`#version 300 es
|
|
104
387
|
precision mediump float;
|
|
105
388
|
uniform sampler2D u_tex;
|
|
106
389
|
uniform sampler2D u_normal;
|
|
@@ -138,13 +421,13 @@ void main(){
|
|
|
138
421
|
if (col.a < 0.004) discard;
|
|
139
422
|
}
|
|
140
423
|
fragColor = col;
|
|
141
|
-
}`,r=(u,l)=>{const f=e.createShader(u);if(e.shaderSource(f,l),e.compileShader(f),!e.getShaderParameter(f,e.COMPILE_STATUS))throw new Error("\u7C92\u5B50 shader: "+e.getShaderInfoLog(f));return f},o=e.createProgram();if(e.attachShader(o,r(e.VERTEX_SHADER,n)),e.attachShader(o,r(e.FRAGMENT_SHADER,t)),e.linkProgram(o),!e.getProgramParameter(o,e.LINK_STATUS))throw new Error("\u7C92\u5B50 shader \u94FE\u63A5\u5931\u8D25: "+e.getProgramInfoLog(o));const i=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,-.5,.5,.5,.5]),e.STATIC_DRAW);const s=e.createBuffer(),a=e.createVertexArray();e.bindVertexArray(a),e.bindBuffer(e.ARRAY_BUFFER,i),e.enableVertexAttribArray(0),e.vertexAttribPointer(0,2,e.FLOAT,!1,8,0),e.vertexAttribDivisor(0,0),e.bindBuffer(e.ARRAY_BUFFER,s);const c=56;return e.enableVertexAttribArray(1),e.vertexAttribPointer(1,3,e.FLOAT,!1,c,0),e.vertexAttribDivisor(1,1),e.enableVertexAttribArray(2),e.vertexAttribPointer(2,2,e.FLOAT,!1,c,12),e.vertexAttribDivisor(2,1),e.enableVertexAttribArray(3),e.vertexAttribPointer(3,4,e.FLOAT,!1,c,20),e.vertexAttribDivisor(3,1),e.enableVertexAttribArray(4),e.vertexAttribPointer(4,3,e.FLOAT,!1,c,36),e.vertexAttribDivisor(4,1),e.enableVertexAttribArray(5),e.vertexAttribPointer(5,2,e.FLOAT,!1,c,48),e.vertexAttribDivisor(5,1),e.bindVertexArray(null),{prog:{prog:o,uniTex:e.getUniformLocation(o,"u_tex"),uniNormal:e.getUniformLocation(o,"u_normal"),uniScene:e.getUniformLocation(o,"u_scene"),uniRefract:e.getUniformLocation(o,"u_refract"),uniSampleScene:e.getUniformLocation(o,"u_sampleScene"),uniResolution:e.getUniformLocation(o,"u_resolution"),uniRefractScale:e.getUniformLocation(o,"u_refractScale"),uniMvp:e.getUniformLocation(o,"u_mvp"),uniFrameCount:e.getUniformLocation(o,"u_frameCount"),uniFrames:e.getUniformLocation(o,"u_frames")},quadBuf:i,vbuf:s,vao:a}}function si(e){const n=e&&e.passes&&e.passes[0]&&e.passes[0].combos;return!!(n&&Number(n.REFRACT)===1)}function Ka(e){if(!e||e.length<16)return!1;const n=e.length/4,t=Math.max(1,n/64|0);let r=0;for(let o=0;o<n;o+=t){const i=o*4;if(e[i]<250||e[i+1]<250||e[i+2]<250||e[i+3]<250)return!1;r++}return r>0}function ai(e,n,t,r){let o=Math.abs(Number(e)||0)*(Number(n)||0);const i=Number(t)||0,s=Number(r)||0;return i>0&&(o=Math.max(i,o)),s>0&&(o=Math.min(s,o)),o}function Yr(e,n){return e||n?Math.atan2(n,e)-Math.PI/2:0}function ci(e,n){return e&&e.kind==="ropetrail"?Math.max(1,n||1):1}function li(e){if(!e||e.kind!=="ropetrail")return 1;const n=Math.round(Number(e.segments)||0);return n>=2?Math.min(32,n):8}function ui(e){if(!e||e.kind!=="ropetrail")return 0;const n=Number(e.length);return Number.isFinite(n)&&n>0?n:.2}function qr(e){return e.life>0?e.age/e.life:0}class Qa{constructor(){this.alive=!1,this.x=this.y=this.z=0,this.vx=this.vy=this.vz=0,this.bx=this.by=this.bz=0,this.age=0,this.life=1,this.size=1,this.baseSize=1,this.rot=0,this.rotVel=0,this.r=this.g=this.b=1,this.baseR=this.baseG=this.baseB=1,this.alpha=1,this.baseAlpha=1,this.seed=0,this.frame=0,this.oscPhase=0,this.oscFreq=0,this.oscAmp=0,this.oscAPhase=0,this.oscAFreq=0,this.oscSPhase=0,this.oscSFreq=0,this.turbSpeed=0,this.turbPhase=0,this.trail=null,this.trailClock=0,this.seq=0}}class Ja{constructor(n,t,r,o){this.gl=n,this.model=t||{},this.override=r||{},this.layer=o||null,this.syncLayerTransform(),this.maxCount=Math.max(1,Math.min(2e4,ne(this.model.maxcount,100))),this.simTime=0,this.paused=!1,this.texture=null,this.normalTex=null,this.material=null,this.blend="translucent",this.refract=!1,this.refractAmount=.04,this.opacityMul=1,this.lifetimeMul=1,this.visible=!0,this._ready=!1,this._prog=null,this._vbuf=null,this._quadBuf=null,this._vao=null,this._data=null,this._sceneTex=null,this.sequenceMul=Math.max(1,Math.round(ne(this.model.sequencemultiplier,1))),this.animationMode=this.model.animationmode||null,this.texFrames=null,this.frameCount=this.sequenceMul*this.sequenceMul,this.texAspectX=1,this.texAspectY=1,this.controlPoints=(this.model.controlpoint||[]).filter(Boolean).map(i=>({id:ne(i.id,0),lockToPointer:!!i.locktopointer||(ne(i.flags,0)&1)!==0,offset:be(i.offset),x:0,y:0,z:0})),this.pointer=null,this._followParent=null,this._followMode=null,this._followOffset=[0,0,0],this.ropeRenderer=null,this._seq=0,this._ropeOrder=[],this._ov={},this._applyOverride(),this.startTime=Math.max(0,Math.min(30,ne(this.model.starttime,0))),this._warmed=!1,this._compile()}reapplyOverride(){this._applyOverride()}_applyOverride(){this._ov={},this.opacityMul=1,this.lifetimeMul=1,this.maxCount=Math.max(1,Math.min(2e4,ne(this.model.maxcount,100)));const n=this.override||{};for(const t of Object.keys(n)){if(t==="id")continue;const r=n[t],o=r&&typeof r=="object"&&"value"in r?r.value:r;if(t==="count"){const i=ne(this.model.maxcount,100),s=Number(o),a=Number.isFinite(s)?s:1;this.maxCount=Math.max(1,Math.min(2e4,Math.round(i*a))),this._ov.countMul=a}else if(t==="alpha")this.opacityMul=Number(o),Number.isFinite(this.opacityMul)||(this.opacityMul=1);else if(t==="color"||t==="colorn"){const i=be(o);this._ov.color=t==="colorn"?i:[i[0]/255,i[1]/255,i[2]/255]}else t==="size"?this._ov.size=Number(o)||1:t==="rate"?(this._ov.rateMul=Number(o),Number.isFinite(this._ov.rateMul)||(this._ov.rateMul=1)):t==="speed"?this._ov.speed=Number(o)||1:t==="lifetime"?this.lifetimeMul=Number(o)||1:t==="brightness"?this._ov.brightness=Number(o)||1:this._ov[t]=o}this.pool=[];for(let t=0;t<this.maxCount;t++)this.pool.push(new Qa)}_compile(){const n=this.model;this.emitters=(n.emitter||[]).map(c=>({kind:c.name==="boxrandom"?"box":"sphere",origin:be(c.origin),directions:be(c.directions,[1,1,1]),distanceMin:ii(c.distancemin),distanceMax:ii(c.distancemax),sign:c.sign?be(c.sign):null,rate:ne(c.rate,0),audioDriven:c.audioprocessingmode!==void 0,audioBounds:be(c.audioprocessingbounds,[0,1]),fill:c.rate===void 0&&c.instantaneous===void 0&&c.audioprocessingmode===void 0,instantaneous:ne(c.instantaneous,0),speedMin:ne(c.speedmin,0),speedMax:ne(c.speedmax,0),controlPoint:c.controlpoint!==void 0&&c.controlpoint!==null?ne(c.controlpoint,0):0,_burst:!1}));const t=n.initializer||[];this.init={life:null,size:null,color:null,alpha:null,velocity:null,rotation:null,angularVelocity:null,turbulentVelocity:null,mapAround:null};for(const c of t)switch(c.name){case"lifetimerandom":this.init.life={min:ne(c.min,1),max:ne(c.max,1),exp:ne(c.exponent,1)};break;case"sizerandom":this.init.size={min:ne(c.min,1),max:ne(c.max,1),exp:ne(c.exponent,1)};break;case"colorrandom":this.init.color={min:be(c.min,[255,255,255]),max:be(c.max,[255,255,255])};break;case"alpharandom":this.init.alpha={min:ne(c.min,1),max:ne(c.max,1)};break;case"velocityrandom":this.init.velocity={min:be(c.min),max:be(c.max)};break;case"rotationrandom":this.init.rotation={min:be(c.min),max:be(c.max,[0,0,0]),exp:ne(c.exponent,1)};break;case"angularvelocityrandom":this.init.angularVelocity={min:be(c.min),max:be(c.max),exp:ne(c.exponent,1)};break;case"mapsequencearoundcontrolpoint":this.init.mapAround={count:Math.max(1,ne(c.count,1)),bounds:be(c.bounds,[0,1]),speedMin:be(c.speedmin),speedMax:be(c.speedmax,[0,0,0]),cp:ne(c.controlpoint,0)},this._mapAroundSeq=0;break;case"turbulentvelocityrandom":this.init.turbulentVelocity={scale:ne(c.scale,.1),offset:ne(c.offset,0),speedMin:ne(c.speedmin,0),speedMax:ne(c.speedmax,0),phaseMax:ne(c.phasemax,0),timeScale:ne(c.timescale,0),audioMode:ne(c.audioprocessingmode,0),audioBounds:be(c.audioprocessingbounds,[0,1])};break}const r=n.operator||[];this.ops={movement:null,angularMovement:null,alphaFade:null,alphaChange:null,sizeChange:null,colorChange:null,turbulence:[],oscAlpha:null,oscSize:null,oscPos:null,attract:[],vortex:[],remap:[]};for(const c of r)switch(c.name){case"movement":this.ops.movement={gravity:be(c.gravity),drag:ne(c.drag,0)};break;case"angularmovement":this.ops.angularMovement={force:be(c.force),drag:ne(c.drag,0)};break;case"alphafade":this.ops.alphaFade={fadeIn:ne(c.fadeintime,.1),fadeOut:ne(c.fadeouttime,.9)};break;case"alphachange":this.ops.alphaChange={startTime:ne(c.starttime,0),endTime:ne(c.endtime,1),startValue:ne(c.startvalue,1),endValue:ne(c.endvalue,0)};break;case"sizechange":this.ops.sizeChange={startTime:ne(c.starttime,0),endTime:ne(c.endtime,1),startValue:ne(c.startvalue,1),endValue:ne(c.endvalue,1)};break;case"colorchange":this.ops.colorChange={startTime:ne(c.starttime,0),endTime:ne(c.endtime,1),startValue:c.startvalue!==void 0?be(c.startvalue):null,endValue:be(c.endvalue,[1,1,1])};break;case"turbulence":this.ops.turbulence.push({scale:ne(c.scale,.01),speedMin:ne(c.speedmin,0),speedMax:ne(c.speedmax,0),timeScale:ne(c.timescale,1),phaseMin:ne(c.phasemin,0),phaseMax:ne(c.phasemax,0),mask:c.mask!==void 0?be(c.mask,[1,1,1]):[1,1,1]});break;case"oscillatealpha":this.ops.oscAlpha={freqMin:ne(c.frequencymin,ne(c.frequencymax,1)),freqMax:ne(c.frequencymax,1),scaleMin:ne(c.scalemin,0),scaleMax:ne(c.scalemax,1),phaseMax:ne(c.phasemax,ht)};break;case"oscillatesize":this.ops.oscSize={freqMin:ne(c.frequencymin,ne(c.frequencymax,1)),freqMax:ne(c.frequencymax,ne(c.frequencymin,1)),scaleMin:ne(c.scalemin,1),scaleMax:ne(c.scalemax,1),phaseMax:ne(c.phasemax,ht)};break;case"oscillateposition":this.ops.oscPos={freqMin:ne(c.frequencymin,ne(c.frequencymax,.5)),freqMax:ne(c.frequencymax,.5),scaleMin:ne(c.scalemin,0),scaleMax:ne(c.scalemax,1),phaseMin:ne(c.phasemin,0),phaseMax:ne(c.phasemax,ht),mask:c.mask!==void 0?be(c.mask,[1,1,0]):[1,1,0]};break;case"controlpointattract":this.ops.attract.push({cp:ne(c.controlpoint,0),origin:be(c.origin),scale:ne(c.scale,0),threshold:ne(c.threshold,0)});break;case"vortex":this.ops.vortex.push({axis:be(c.axis,[0,0,1]),offset:be(c.offset),distanceInner:ne(c.distanceinner,0),distanceOuter:ne(c.distanceouter,0),speedInner:ne(c.speedinner,0),speedOuter:ne(c.speedouter,0),cp:c.controlpoint!==void 0&&c.controlpoint!==null?ne(c.controlpoint,0):0,audioMode:ne(c.audioprocessingmode,0),audioBounds:be(c.audioprocessingbounds,[0,1])});break;case"remapvalue":this.ops.remap.push({output:c.output||"velocity",rangeMin:be(c.outputrangemin),rangeMax:be(c.outputrangemax),fn:c.transformfunction||"simplexnoise",inputScale:ne(c.transforminputscale,1)});break}const o=this.model.renderer,i=o==null,s=Array.isArray(o)?o:o?[o]:[];this.renderers=s.map(c=>{const u=c&&c.name||"sprite";return{kind:u,length:ne(c&&c.length,u==="spritetrail"?.1:u==="ropetrail"?.2:0),maxLength:ne(c&&c.maxlength,0),minLength:ne(c&&c.minlength,0),subdivision:ne(c&&c.subdivision,1),segments:ne(c&&c.segments,0),orientation:c&&c.orientation||null}}),i&&!this.renderers.length&&(this.renderers=[{kind:"sprite",length:0,maxLength:0,minLength:0,subdivision:1,segments:0,orientation:null}]);const a=this.renderers.find(c=>c.kind==="spritetrail"||c.kind==="ropetrail");if(this.trailCfg=a||null,this.trailSegments=1,this.trailDuration=0,this.trailSampleDt=0,a&&a.kind==="ropetrail"){const c=li(a);this.trailSegments=c,this.trailDuration=ui(a),this.trailSampleDt=this.trailDuration/Math.max(1,c-1);for(const u of this.pool)u.trail=new Float32Array(c*3),u.trailClock=0}this.ropeRenderer=this.renderers.find(c=>c.kind==="rope")||null}setModel(n){this.model=n,this._compile()}setMaterial(n){this.material=n;const t=n&&n.passes&&n.passes[0];this.blend=t&&t.blending||"translucent",this.refract=si(n);const r=t&&t.constantshadervalues,o=r&&r.ui_editor_properties_refract_amount,i=Number(o);this.refractAmount=Number.isFinite(i)?Math.min(.35,Math.max(0,i)):.04}setNormalTexture(n){this.normalTex=n||null}setTexture(n){this.texture=n,this._ready=!!n;const t=n&&n.frames,r=Array.isArray(t)?t:t&&t.list&&t.list.length?t.list:null,o=n&&n.width||r&&(t&&t.atlasWidth||r.atlasWidth)||0,i=n&&n.height||r&&(t&&t.atlasHeight||r.atlasHeight)||0;r&&o>0&&i>0?(this.texFrames=r.map(u=>({ou:u.x/o,ov:u.y/i,su:u.width/o,sv:u.height/i})),this.frameCount=this.texFrames.length):(this.texFrames=null,this.frameCount=this.sequenceMul*this.sequenceMul);let s=1,a=1;this.texFrames&&r?(s=r[0].width||1,a=r[0].height||1):n&&n.width>0&&n.height>0&&(s=n.width,a=n.height);const c=Math.max(s,a)||1;this.texAspectX=s/c,this.texAspectY=a/c,this._frameData=void 0}setVisible(n){this.visible=n}syncLayerTransform(){const n=this.layer,t=n&&n.origin?n.origin:[0,0,0],r=n&&n.scale?n.scale:[1,1,1],o=n&&n.angles?n.angles:[0,0,0];this.originX=t[0]||0,this.originY=t[1]||0,this.originZ=t[2]||0,this.scaleX=r[0]===0?1:r[0],this.scaleY=r[1]===0?1:r[1],this.angleZ=(o[2]||0)*Math.PI/180;const i=Math.abs(this.scaleX),s=Math.abs(this.scaleY);this.sysScale=Math.min(i,s)||1,this.spriteStretchX=i/this.sysScale,this.spriteStretchY=s/this.sysScale}setPointer(n,t){const r=n-this.originX,o=t-this.originY,i=Math.cos(-this.angleZ),s=Math.sin(-this.angleZ);this.pointer={x:(r*i-o*s)/(this.scaleX||1),y:(r*s+o*i)/(this.scaleY||1)}}attachFollow(n,t,r){this._followParent=n||null,this._followMode=t==="particle"||t==="origin"?t:null;const o=r||[0,0,0];this._followOffset=[o[0]||0,o[1]||0,o[2]||0],this._syncFollow()}leaderParticle(){const n=this.pool;for(let t=0;t<n.length;t++)if(n[t].alive)return n[t];return null}localToWorld(n,t){const r=n*this.scaleX,o=t*this.scaleY,i=Math.cos(this.angleZ),s=Math.sin(this.angleZ);return[this.originX+r*i-o*s,this.originY+r*s+o*i]}_syncFollow(){const n=this._followParent,t=this._followMode;if(!n||!t)return;const r=this._followOffset;if(t==="particle"){const o=n.leaderParticle();if(!o)return;const i=n.localToWorld(o.x+r[0],o.y+r[1]);this.originX=i[0],this.originY=i[1]}else{const o=n.localToWorld(r[0],r[1]);this.originX=o[0],this.originY=o[1]}}spawn(n){const t=this.pool,r=t.length;let o=null,i=this._cursor||0;for(let f=0;f<r;f++){const p=t[(i+f)%r];if(!p.alive){o=p,this._cursor=(i+f+1)%r;break}}if(!o)return;o.alive=!0,o.age=0,o.seed=Math.random(),o.rot=0,o.rotVel=0,o.vx=o.vy=o.vz=0,o.frame=0,o.seq=this._seq++;const s=n.origin;if(n.kind==="box"){const f=n.distanceMax||[0,0,0],p=n.distanceMin;o.x=s[0]+Le(-f[0],f[0])+(p?p[0]:0),o.y=s[1]+Le(-f[1],f[1])+(p?p[1]:0),o.z=s[2]+Le(-f[2],f[2])+(p?p[2]:0)}else{const f=n.directions,p=n.distanceMin?n.distanceMin[0]:0,d=n.distanceMax?n.distanceMax[0]:0,y=Math.random()*2-1,x=Math.random()*ht,m=Math.sqrt(Math.max(0,1-y*y));let M=m*Math.cos(x),h=m*Math.sin(x),g=y;n.sign&&(n.sign[0]&&(M=Math.abs(M)*Math.sign(n.sign[0])),n.sign[1]&&(h=Math.abs(h)*Math.sign(n.sign[1])),n.sign[2]&&(g=Math.abs(g)*Math.sign(n.sign[2])));const v=Le(p,d);if(o.x=s[0]+M*v*f[0],o.y=s[1]+h*v*f[1],o.z=s[2]+g*v*f[2],n.speedMax||n.speedMin){const A=Le(n.speedMin,n.speedMax);o.vx+=M*A,o.vy+=h*A,o.vz+=g*A}}{const f=this._cpPos(n.controlPoint);if(f)o.x+=f[0],o.y+=f[1],o.z+=f[2];else{const p=this.controlPoints.find(d=>d.id===n.controlPoint);if(p&&p.lockToPointer){o.alive=!1;return}}}if(this.init.mapAround){const f=this.init.mapAround,p=this._cpPos(f.cp);if(p){const d=f.count,y=this._mapAroundSeq++,x=d>0?y%d/d:0,M=(f.bounds[0]+(f.bounds[1]-f.bounds[0])*x)*ht,h=n.distanceMin?n.distanceMin[0]:0,g=n.distanceMax?n.distanceMax[0]:0,v=g>0?g:h;o.x=p[0]+Math.cos(M)*v,o.y=p[1]+Math.sin(M)*v,o.z=p[2];const A=Math.random();o.vx+=f.speedMin[0]+(f.speedMax[0]-f.speedMin[0])*A,o.vy+=f.speedMin[1]+(f.speedMax[1]-f.speedMin[1])*A,o.vz+=f.speedMin[2]+(f.speedMax[2]-f.speedMin[2])*A}}const a=this.init,c=this._ov.speed||1,u=this._ov.size||1;if(o.life=a.life?Math.max(.001,oi(a.life.min,a.life.max,a.life.exp)*this.lifetimeMul):1,o.baseSize=a.size?oi(a.size.min,a.size.max,a.size.exp)*u:u,o.size=o.baseSize,a.color){const f=a.color.min,p=a.color.max,d=Math.random();o.baseR=(f[0]+(p[0]-f[0])*d)/255,o.baseG=(f[1]+(p[1]-f[1])*d)/255,o.baseB=(f[2]+(p[2]-f[2])*d)/255}else o.baseR=o.baseG=o.baseB=1;if(this._ov.color&&(o.baseR=this._ov.color[0],o.baseG=this._ov.color[1],o.baseB=this._ov.color[2]),o.r=o.baseR,o.g=o.baseG,o.b=o.baseB,o.baseAlpha=(a.alpha?Le(a.alpha.min,a.alpha.max):1)*this.opacityMul,o.alpha=o.baseAlpha,a.velocity&&(o.vx+=Le(a.velocity.min[0],a.velocity.max[0])*c,o.vy+=Le(a.velocity.min[1],a.velocity.max[1])*c,o.vz+=Le(a.velocity.min[2],a.velocity.max[2])*c),a.turbulentVelocity){const f=a.turbulentVelocity,p=f.audioMode?Hr(f.audioBounds,this._audioLevel||0):1,d=Le(f.speedMin,f.speedMax)*c*p,y=this.simTime*(f.timeScale||0),x=Gr(o.x*f.scale+f.offset,o.y*f.scale+f.offset,y+o.seed*(f.phaseMax||0),3);o.vx+=x[0]*d,o.vy+=x[1]*d,o.vz+=x[2]*d}a.rotation&&(o.rot=Le(a.rotation.min[2],a.rotation.max[2])),a.angularVelocity&&(o.rotVel=Le(a.angularVelocity.min[2],a.angularVelocity.max[2]));const l=this.ops;if(l.oscPos&&(o.oscFreq=Le(l.oscPos.freqMin,l.oscPos.freqMax),o.oscAmp=Le(l.oscPos.scaleMin,l.oscPos.scaleMax),o.oscPhase=Le(l.oscPos.phaseMin,l.oscPos.phaseMax)+o.seed*ht),l.oscAlpha&&(o.oscAFreq=Le(l.oscAlpha.freqMin,l.oscAlpha.freqMax),o.oscAPhase=Math.random()*(l.oscAlpha.phaseMax||ht)),l.oscSize&&(o.oscSFreq=Le(l.oscSize.freqMin,l.oscSize.freqMax),o.oscSPhase=Math.random()*(l.oscSize.phaseMax||ht)),l.turbulence.length){const f=l.turbulence[0];o.turbSpeed=Le(f.speedMin,f.speedMax),o.turbPhase=Le(f.phaseMin,f.phaseMax)}if(this.frameCount>1&&(o.frame=this.animationMode==="randomframe"?Math.floor(Math.random()*this.frameCount):0),o.bx=o.x,o.by=o.y,o.bz=o.z,o.trail){for(let f=0;f<o.trail.length;f+=3)o.trail[f]=o.x,o.trail[f+1]=o.y,o.trail[f+2]=o.z;o.trailClock=0}}updateParticle(n,t){if(n.age+=t,n.age>=n.life){n.alive=!1;return}const r=n.age/n.life,o=this.ops;if(o.movement&&(n.vx+=o.movement.gravity[0]*t,n.vy+=o.movement.gravity[1]*t,n.vz+=o.movement.gravity[2]*t,o.movement.drag>0)){const a=Math.exp(-o.movement.drag*t);n.vx*=a,n.vy*=a,n.vz*=a}o.angularMovement&&(n.rotVel+=(o.angularMovement.force[2]||0)*t,o.angularMovement.drag>0&&(n.rotVel*=Math.exp(-o.angularMovement.drag*t)));for(const a of o.turbulence){const c=a.timeScale||1,u=Gr(n.bx*a.scale,n.by*a.scale,this.simTime*a.scale*c+n.turbPhase,3);n.vx+=u[0]*n.turbSpeed*a.mask[0]*t,n.vy+=u[1]*n.turbSpeed*a.mask[1]*t,n.vz+=u[2]*n.turbSpeed*a.mask[2]*t}for(const a of o.attract){const c=this._cpPos(a.cp);if(!c)continue;const u=c[0]+a.origin[0]-n.x,l=c[1]+a.origin[1]-n.y,f=Math.hypot(u,l);if(f<.001||a.threshold>0&&f>a.threshold)continue;const p=a.threshold>0?1-f/a.threshold:1,d=a.scale*p*t/Math.max(1,f);n.vx+=u*d,n.vy+=l*d}for(const a of o.vortex){const c=this._cpPos(a.cp)||[0,0,0],u=n.x-(c[0]+a.offset[0]),l=n.y-(c[1]+a.offset[1]),f=Math.hypot(u,l);if(f<.001)continue;const p=a.distanceOuter-a.distanceInner,d=p>0?Math.min(1,Math.max(0,(f-a.distanceInner)/p)):0,y=a.audioMode?Hr(a.audioBounds,this._audioLevel||0):1,x=a.speedInner+(a.speedOuter-a.speedInner)*d;n.vx+=-l/f*x*t*y,n.vy+=u/f*x*t*y}for(const a of o.remap){const c=a.inputScale||1,u=Gr(n.bx*.01*c,n.by*.01*c,this.simTime*.1,a.fn==="fbmnoise"?4:2);if(a.output==="velocity")for(let l=0;l<3;l++){const f=(u[l]+1)/2,p=a.rangeMin[l]+(a.rangeMax[l]-a.rangeMin[l])*f;l===0?n.vx=p:l===1?n.vy=p:n.vz=p}else if(a.output==="speed"){const l=(u[0]+1)/2,f=a.rangeMin[0]+(a.rangeMax[0]-a.rangeMin[0])*l,p=Math.hypot(n.vx,n.vy)||1;n.vx=n.vx/p*f,n.vy=n.vy/p*f}}if(n.bx+=n.vx*t,n.by+=n.vy*t,n.bz+=n.vz*t,n.rot+=n.rotVel*t,n.x=n.bx,n.y=n.by,n.z=n.bz,o.oscPos){const a=this.simTime*n.oscFreq*ht+n.oscPhase,c=o.oscPos.mask;n.x+=Math.sin(a)*n.oscAmp*c[0],n.y+=Math.cos(a)*n.oscAmp*c[1],n.z+=Math.sin(a*.7)*n.oscAmp*c[2]}let i=n.baseSize;if(o.sizeChange){const a=o.sizeChange,c=a.endTime-a.startTime,u=c>0?Math.min(1,Math.max(0,(r-a.startTime)/c)):r>=a.startTime?1:0;i*=a.startValue+(a.endValue-a.startValue)*u}if(o.oscSize){const a=this.simTime*n.oscSFreq*ht+n.oscSPhase,c=o.oscSize,u=(c.scaleMin+c.scaleMax)/2,l=(c.scaleMax-c.scaleMin)/2;i*=u+Math.sin(a)*l}if(n.size=i,o.colorChange){const a=o.colorChange,c=a.endTime-a.startTime,u=c>0?Math.min(1,Math.max(0,(r-a.startTime)/c)):r>=a.startTime?1:0,l=a.startValue||[n.baseR,n.baseG,n.baseB];n.r=l[0]+(a.endValue[0]-l[0])*u,n.g=l[1]+(a.endValue[1]-l[1])*u,n.b=l[2]+(a.endValue[2]-l[2])*u}let s=n.baseAlpha;if(o.alphaFade){const a=o.alphaFade.fadeIn,c=o.alphaFade.fadeOut;a>0&&r<a&&(s*=r/a),c<1&&r>c&&(s*=Math.max(0,(1-r)/(1-c)))}else o.alphaChange||(r<.1?s*=r/.1:r>.85&&(s*=(1-r)/.15));if(o.alphaChange){const a=o.alphaChange,c=a.endTime-a.startTime,u=c>0?Math.min(1,Math.max(0,(r-a.startTime)/c)):r>=a.startTime?1:0;s*=a.startValue+(a.endValue-a.startValue)*u}if(o.oscAlpha){const a=this.simTime*n.oscAFreq*ht+n.oscAPhase,c=o.oscAlpha,u=(c.scaleMin+c.scaleMax)/2,l=(c.scaleMax-c.scaleMin)/2;s*=u+Math.sin(a)*l}if(n.alpha=Math.max(0,s),this.frameCount>1&&this.animationMode!=="randomframe"&&(n.frame=Math.min(this.frameCount-1,Math.floor(r*this.frameCount))),n.trail){const a=n.trail,c=this.trailSampleDt;if(c>0){n.trailClock=(n.trailClock||0)+t;let u=0;const l=this.trailSegments||8;for(;n.trailClock>=c&&u<l;){n.trailClock-=c,u++;for(let f=a.length-3;f>=3;f-=3)a[f]=a[f-3],a[f+1]=a[f-2],a[f+2]=a[f-1]}}a[0]=n.x,a[1]=n.y,a[2]=n.z}}_cpPos(n){const t=this.controlPoints.find(r=>r.id===n);return t?t.lockToPointer?this.pointer?[this.pointer.x+t.offset[0],this.pointer.y+t.offset[1],t.offset[2]]:null:t.offset:null}advance(n,t){if(!(this.paused||!this.visible)){if(this._syncFollow(),!this._warmed&&(this._warmed=!0,this.startTime>0)){const r=.03333333333333333,o=Math.min(900,Math.round(this.startTime/r));for(let i=0;i<o;i++)this._step(r)}this._step(n,t)}}_step(n,t){this.simTime+=n;const r=t&&Number.isFinite(t.level)?Math.max(0,Math.min(1,t.level)):0;this._audioLevel=r;for(const i of this.emitters){if(i.instantaneous>0&&!i._burst){i._burst=!0;for(let c=0;c<Math.min(i.instantaneous,this.maxCount);c++)this.spawn(i)}if(i.fill){const u=Math.min(this.maxCount,2048);let l=0;for(let p=0;p<this.pool.length;p++)this.pool[p].alive&&l++;let f=Math.min(u-l,512);for(;f-- >0;)this.spawn(i);continue}if(i.audioDriven){const c=Hr(i.audioBounds,r);if(i.rate>0){const u=i.rate*c*(this._ov.rateMul!==void 0?this._ov.rateMul:1)*(this._ov.countMul!==void 0?this._ov.countMul:1);if(!(u>0))continue;i._accum=(i._accum||0)+u*n;let l=Math.floor(i._accum);if(l>0){i._accum-=l,l>this.maxCount&&(l=this.maxCount);for(let f=0;f<l;f++)this.spawn(i)}}else{const l=Math.round(Math.min(this.maxCount,2048)*c);let f=0;for(let d=0;d<this.pool.length;d++)this.pool[d].alive&&f++;let p=Math.min(l-f,256);for(;p-- >0;)this.spawn(i)}continue}const s=i.rate*(this._ov.rateMul!==void 0?this._ov.rateMul:1)*(this._ov.countMul!==void 0?this._ov.countMul:1);if(!(s>0))continue;i._accum=(i._accum||0)+s*n;let a=Math.floor(i._accum);if(a>0){i._accum-=a,a>this.maxCount&&(a=this.maxCount);for(let c=0;c<a;c++)this.spawn(i)}}const o=this.pool;for(let i=0;i<o.length;i++)o[i].alive&&this.updateParticle(o[i],n)}render(n,t,r,o,i){if(!this._ready||!this.visible||!this.renderers.length)return;const s=this.gl;this._prog||this._buildProgram(s);const a=this.trailCfg&&this.trailCfg.kind==="ropetrail"?this.trailCfg:null,c=this.trailCfg&&this.trailCfg.kind==="spritetrail"?this.trailCfg:null,u=this.ropeRenderer,l=ci(this.trailCfg,this.trailSegments),f=14,p=this.pool;let d=null;if(u){d=this._ropeOrder,d.length=0;for(let J=0;J<p.length;J++)p[J].alive&&d.push(p[J]);d.sort((J,Z)=>J.seq-Z.seq)}let y=0;if(d)y=d.length;else for(let J=0;J<p.length;J++)p[J].alive&&y++;if(y===0||u&&y<2)return;const x=u?y-1:y*l,m=x*f;(!this._data||this._data.length<m)&&(this._data=new Float32Array(Math.max(m,1024)));const M=this._data;let h=0;const g=this._ov.brightness||1,v=this.sysScale,A=this.spriteStretchX*(this.texAspectX||1),_=this.spriteStretchY*(this.texAspectY||1),R=Math.cos(this.angleZ),L=Math.sin(this.angleZ),N=this.originX,j=this.originY,H=this.scaleX,K=this.scaleY,O=(J,Z)=>{const te=J*H,le=Z*K;return[N+te*R-le*L,i-(j+te*L+le*R)]};if(u)for(let J=0;J+1<y;J++){const Z=d[J],te=d[J+1],le=O(Z.x,Z.y),Ue=O(te.x,te.y),_e=Ue[0]-le[0],Ze=Ue[1]-le[1],Xe=Math.hypot(_e,Ze),De=(Math.abs(Z.size)+Math.abs(te.size))*.5*v;De>0&&(M[h++]=(le[0]+Ue[0])*.5,M[h++]=(le[1]+Ue[1])*.5,M[h++]=0,M[h++]=De,M[h++]=Math.atan2(-_e,Ze),M[h++]=(Z.r+te.r)*.5*g,M[h++]=(Z.g+te.g)*.5*g,M[h++]=(Z.b+te.b)*.5*g,M[h++]=(Z.alpha+te.alpha)*.5,M[h++]=1,M[h++]=Xe/De,M[h++]=0,M[h++]=qr(Z),M[h++]=qr(te))}for(let J=0;J<p.length&&!u;J++){const Z=p[J];if(Z.alive)for(let te=0;te<l;te++){let le=Z.x,Ue=Z.y,_e=1,Ze=1,Xe=Z.rot,De=A,Ke=_,Be,ye;if(a&&Z.trail){le=Z.trail[te*3],Ue=Z.trail[te*3+1];const he=l>1?te/(l-1):0;_e=1-he,Ze=1-he*.55;let Ie=0,Pe=0;te+1<l?(Ie=Z.trail[te*3]-Z.trail[(te+1)*3],Pe=Z.trail[te*3+1]-Z.trail[(te+1)*3+1]):te>0?(Ie=Z.trail[(te-1)*3]-Z.trail[te*3],Pe=Z.trail[(te-1)*3+1]-Z.trail[te*3+1]):(Ie=Z.vx,Pe=Z.vy);const Qe=O(le,Ue),Oe=O(le-Ie,Ue-Pe),Ae=Qe[0]-Oe[0],ot=Qe[1]-Oe[1],it=Math.hypot(Ae,ot),It=Math.max(.001,Math.abs(Z.size)*v*Ze);it>.001?(Xe=Yr(Ae,ot),Be=(Qe[0]+Oe[0])*.5,ye=(Qe[1]+Oe[1])*.5,Ke=Math.max(_,it/It)):(Be=Qe[0],ye=Qe[1])}else{const he=O(le,Ue);Be=he[0],ye=he[1]}if(c){const he=O(Z.x,Z.y);Be=he[0],ye=he[1];const Ie=O(Z.x+Z.vx,Z.y+Z.vy);Xe=Yr(Ie[0]-he[0],Ie[1]-he[1]);const Pe=ai(Math.hypot(Z.vx,Z.vy),c.length,c.minLength,c.maxLength);Ke=_*Pe}M[h++]=Be,M[h++]=ye,M[h++]=0,M[h++]=Math.abs(Z.size)*v*Ze,M[h++]=Xe,M[h++]=Z.r*g,M[h++]=Z.g*g,M[h++]=Z.b*g,M[h++]=Z.alpha*_e,M[h++]=De,M[h++]=Ke,M[h++]=Z.frame,M[h++]=0,M[h++]=1}}const V=this._prog;s.useProgram(V.prog),s.bindVertexArray(this._vao),s.bindBuffer(s.ARRAY_BUFFER,this._vbuf),s.bufferData(s.ARRAY_BUFFER,M.subarray(0,h),s.DYNAMIC_DRAW),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.texture.glTex),s.uniform1i(V.uniTex,0),s.uniformMatrix4fv(V.uniMvp,!1,n);const X=this.refract&&this.normalTex&&this.normalTex.glTex;if(V.uniRefract&&s.uniform1i(V.uniRefract,X?1:0),X){s.activeTexture(s.TEXTURE1),s.bindTexture(s.TEXTURE_2D,this.normalTex.glTex),V.uniNormal&&s.uniform1i(V.uniNormal,1);const J=this.blend!=="additive";if(V.uniSampleScene&&s.uniform1i(V.uniSampleScene,J?1:0),J){const Z=s.drawingBufferWidth||t,te=s.drawingBufferHeight||r;s.bindFramebuffer(s.FRAMEBUFFER,null),s.activeTexture(s.TEXTURE2),this._sceneTex?s.bindTexture(s.TEXTURE_2D,this._sceneTex):(this._sceneTex=s.createTexture(),s.bindTexture(s.TEXTURE_2D,this._sceneTex),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MIN_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_MAG_FILTER,s.LINEAR),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_S,s.CLAMP_TO_EDGE),s.texParameteri(s.TEXTURE_2D,s.TEXTURE_WRAP_T,s.CLAMP_TO_EDGE)),s.copyTexImage2D(s.TEXTURE_2D,0,s.RGB8,0,0,Z,te,0),V.uniScene&&s.uniform1i(V.uniScene,2),V.uniResolution&&s.uniform2f(V.uniResolution,Z,te),V.uniRefractScale&&s.uniform1f(V.uniRefractScale,this.refractAmount||.04)}else s.activeTexture(s.TEXTURE2),s.bindTexture(s.TEXTURE_2D,this.texture.glTex),V.uniScene&&s.uniform1i(V.uniScene,2)}else V.uniNormal&&(s.activeTexture(s.TEXTURE1),s.bindTexture(s.TEXTURE_2D,this.texture.glTex),s.uniform1i(V.uniNormal,1),s.activeTexture(s.TEXTURE2),s.bindTexture(s.TEXTURE_2D,this.texture.glTex),V.uniScene&&s.uniform1i(V.uniScene,2),V.uniSampleScene&&s.uniform1i(V.uniSampleScene,0));const ie=this._frameUniformData();ie?(s.uniform1i(V.uniFrameCount,ie.count),s.uniform4fv(V.uniFrames,ie.arr)):s.uniform1i(V.uniFrameCount,0),s.enable(s.BLEND),this.blend==="additive"?s.blendFunc(s.SRC_ALPHA,s.ONE):s.blendFunc(s.SRC_ALPHA,s.ONE_MINUS_SRC_ALPHA),s.depthMask(!1),s.drawArraysInstanced(s.TRIANGLE_STRIP,0,4,x),s.depthMask(!0),s.disable(s.BLEND),s.bindVertexArray(null)}_buildProgram(n){const t=Za(n);this._quadBuf=t.quadBuf,this._vbuf=t.vbuf,this._vao=t.vao,this._prog=t.prog}_frameUniformData(){if(this._frameData!==void 0)return this._frameData;let n=this.texFrames;if(!n&&this.sequenceMul>1){const o=this.sequenceMul;n=[];for(let i=0;i<o;i++)for(let s=0;s<o;s++)n.push({ou:s/o,ov:i/o,su:1/o,sv:1/o})}if(!n||n.length===0)return this._frameData=null,null;const t=Math.min(n.length,128),r=new Float32Array(t*4);for(let o=0;o<t;o++)r[o*4]=n[o].ou,r[o*4+1]=n[o].ov,r[o*4+2]=n[o].su,r[o*4+3]=n[o].sv;return this._frameData={count:t,arr:r},this._frameData}liveCount(){let n=0;for(const t of this.pool)t.alive&&n++;return n}dispose(){this.paused=!0;const n=this.gl;if(n){try{this._vbuf&&n.deleteBuffer(this._vbuf),this._quadBuf&&n.deleteBuffer(this._quadBuf),this._vao&&n.deleteVertexArray(this._vao),this._prog&&this._prog.prog&&n.deleteProgram(this._prog.prog),this._sceneTex&&n.deleteTexture(this._sceneTex)}catch{}this._prog=null,this._vbuf=null,this._quadBuf=null,this._vao=null,this._data=null,this._sceneTex=null}}}const ec=Object.freeze(Object.defineProperty({__proto__:null,ParticleSystem:Ja,particleInstanceSegs:ci,particlePassRefract:si,rgbaIsBlankWhite:Ka,ropeParticleV:qr,ropeTrailDuration:ui,ropeTrailHistoryCount:li,spriteTrailLengthFactor:ai,spriteTrailRotation:Yr},Symbol.toStringTag,{value:"Module"})),Rn=new Map,Zr=new Map;let cr=null;function tc(e,n){const t=String(e);Zr.set(t,n),Rn.delete(t)}function nc(e){cr=typeof e=="function"?e:null}function rc(){Zr.clear(),cr=null,Rn.clear()}function oc(){return Object.keys(Dn)}function Se(e,n,t){e[n]=255,e[n+1]=255,e[n+2]=255,e[n+3]=Math.round(Math.min(1,Math.max(0,t))*255)}function kn(e,n){const{width:t,height:r,rgba:o}=e,i=Math.max(2,Math.round(Math.min(t,r)*.04));for(let s=0;s<r;s++)for(let a=0;a<t;a++){const c=Math.min(a,s,t-1-a,r-1-s);if(c>=i)continue;const u=c/i,l=(s*t+a)*4+3;o[l]=Math.round(o[l]*u)}if(n>0){let s=0;const a=t*r;for(let u=0;u<a;u++)s+=o[u*4+3];const c=s/a/255;if(c>n&&c>0){const u=n/c;for(let l=0;l<a;l++)o[l*4+3]=Math.round(o[l*4+3]*u)}}return e}function lr(e){let n=e>>>0;return function(){n|=0,n=n+1831565813|0;let t=Math.imul(n^n>>>15,1|n);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}const vn=e=>e*e*(3-2*e),fi=e=>e*e*e*(e*(e*6-15)+10),Kr=(e,n,t)=>e+(n-e)*t,ae=(e,n)=>Math.exp(-(e*e)/(n*n));function on(e,n,t,r){const o=Math.min(e,n,t-1-e,t-1-n);return o>=r?1:o/r}function Fn(e,n){const t=new Uint8Array(e*e*4),r=e/2;for(let o=0;o<e;o++)for(let i=0;i<e;i++){const s=Math.hypot((i+.5-r)/r,(o+.5-r)/r);let a=0;for(let c=0;c<n.length;c++)a+=n[c].w*ae(s,n[c].r);Se(t,(o*e+i)*4,a)}return{width:e,height:e,rgba:t}}function Ut(e,n,t){return Fn(e,[n,t])}function Dt(e,n,t,r,o){const i=new Uint8Array(e*e*4),s=e/2,a=Math.max(2,Math.round(e*.03));for(let c=0;c<e;c++)for(let u=0;u<e;u++){const l=(u+.5-s)/s,f=(c+.5-s)/s,p=Math.hypot(l,f),d=Math.atan2(f,l),y=Math.pow(.5+.5*Math.cos(n*d),r);let x=ae(p,o)+y*ae(p,t);x*=on(u,c,e,a),Se(i,(c*e+u)*4,x)}return{width:e,height:e,rgba:i}}function Et(e,n,t,r,o){const s=new Uint8Array(e*n*4);for(let a=0;a<n;a++){const c=a/(n-1),u=r?ae(c-.5,.27):vn(Math.min(1,c/.06))*Math.pow(1-c,1.35);for(let l=0;l<e;l++){const f=l/(e-1)*2-1,p=ae(f,t);Se(s,(a*e+l)*4,p*p*p*u*.55)}}return{width:e,height:n,rgba:s}}const Nn=4;function di(e,n,t,r,o){const i=o===void 0?.85:o,s=new Uint8Array(e*n*4),a=n/Nn,c=lr(335009),u=Math.tan(t*Math.PI/180),l=e/2;for(let f=0;f<Nn;f++){const p=i*(.8+c()*.35),d=r*(.85+c()*.5),y=(c()-.5)*e*.12;for(let x=0;x<a;x++){const m=x/(a-1),M=l+y+(a-1)*u/2-(a-1)*u*m,h=ae(m-.5,.27);for(let g=0;g<e;g++){const v=Math.abs(g+.5-M),_=Math.exp(-(v*v)/(d*d))*h*p;_<.004||Se(s,((f*a+x)*e+g)*4,_)}}}return{width:e,height:n,rgba:s}}function ic(e){if(e==="particle/nature/rain1"||e==="particle/nature/rain2"){const n=[];for(let t=0;t<Nn;t++)n.push({ou:0,ov:t/Nn,su:1,sv:1/Nn});return n}return null}function Qr(e,n,t){const r=new Uint8Array(e*e*4),o=e/2;for(let i=0;i<e;i++)for(let s=0;s<e;s++){const a=Math.hypot((s-o)/o,(i-o)/o);Se(r,(i*e+s)*4,ae(a-n,t*.6)*Math.max(0,1-a))}return{width:e,height:e,rgba:r}}function pi(e,n){const t={1:{r:.78,t:.048,inner:.06,hi:[[-.28,-.32,.22,.9],[.32,.36,.12,.28]]},2:{r:.7,t:.07,inner:.14,hi:[[-.2,-.28,.3,.72],[.38,.2,.14,.4]]},3:{r:.84,t:.036,inner:.04,hi:[[-.34,-.18,.16,.95],[.2,.42,.1,.22],[.04,-.08,.07,.18]]}},r=t[n]||t[1],o=new Uint8Array(e*e*4),i=e/2;for(let s=0;s<e;s++)for(let a=0;a<e;a++){const c=(a+.5-i)/i,u=(s+.5-i)/i,l=Math.hypot(c,u);let f=ae(l-r.r,r.t*.85)*Math.max(0,1.05-l);l<r.r&&(f+=r.inner*ae(l,.5));for(let p=0;p<r.hi.length;p++){const d=r.hi[p];f+=d[3]*ae(Math.hypot(c-d[0],u-d[1]),d[2])}Se(o,(s*e+a)*4,f)}return kn({width:e,height:e,rgba:o},.05)}function Un(e,n){const t=e>>1,r=new Uint8Array(e*e*4),o=n===1?[1,2,1,3]:n===2?[2,1,2,3]:[3,1,2,3];for(let i=0;i<2;i++)for(let s=0;s<2;s++){const a=pi(t,o[i*2+s]);for(let c=0;c<t;c++){const u=(i*t+c)*e,l=c*t;for(let f=0;f<t;f++){const p=(u+s*t+f)*4,d=(l+f)*4;r[p]=a.rgba[d],r[p+1]=a.rgba[d+1],r[p+2]=a.rgba[d+2],r[p+3]=a.rgba[d+3]}}}return{width:e,height:e,rgba:r}}function hi(e){const n=new Uint8Array(e*e*4),t=e/2,r=[[.32,0],[1.1,.35],[2.2,-.3],[-.7,.2]];for(let o=0;o<e;o++)for(let i=0;i<e;i++){const s=i>=t?1:0,a=o>=t?1:0,c=a*2+s,u=s*t+t/2,l=a*t+t/2,f=r[c][0],p=r[c][1],d=(i+.5-u)/(t*.4),y=(o+.5-l)/(t*.4),x=Math.cos(f),m=Math.sin(f);let M=d*x+y*m;const h=-d*m+y*x;M+=p*h*.18;const g=1-Math.max(0,h)*.42,v=Math.hypot(M/(.52*g),h/.92);let A=v>=1.12?0:ae(v,.48);A=Math.min(1,A+ae(M,.07)*ae(h,.65)*A*.4),Se(n,(o*e+i)*4,A)}return kn({width:e,height:e,rgba:n},.11)}function We(e,n){const t={0:{rx:.36,ry:.92,wave:0,folds:0},1:{rx:.48,ry:.86,wave:.05,folds:7},2:{rx:.4,ry:.88,wave:.08,folds:5},3:{rx:.58,ry:.72,wave:0,folds:0},5:{rx:.44,ry:.8,wave:.12,folds:9},6:{rx:.52,ry:.78,wave:.07,folds:4},7:{rx:.5,ry:.9,wave:.16,folds:3},8:{rx:.38,ry:.94,wave:.2,folds:2}},r=t[n]||t[0],o=new Uint8Array(e*e*4),i=e/2;for(let s=0;s<e;s++)for(let a=0;a<e;a++){const c=(a+.5-i)/i,u=(s+.5-i)/i,l=Math.atan2(c,u),f=r.wave?1+r.wave*Math.sin(l*r.folds):1,p=Math.hypot(c/(r.rx*f),u/r.ry);let d=p>=1.12?0:ae(p,.5);d>0&&(d=Math.min(1,d+ae(c,.028)*ae(u,.72)*.28)),Se(o,(s*e+a)*4,d)}return kn({width:e,height:e,rgba:o},.11)}function mt(e,n){const t=e.width,r=e.height,o=e.rgba,i=n??2.8,s=new Uint8Array(t*r*4),a=(c,u)=>{const l=c<0?0:c>=t?t-1:c,f=u<0?0:u>=r?r-1:u;return o[(f*t+l)*4+3]/255};for(let c=0;c<r;c++)for(let u=0;u<t;u++){const l=(a(u-1,c)-a(u+1,c))*i,f=(a(u,c-1)-a(u,c+1))*i,p=1/Math.hypot(l,f,1),d=(c*t+u)*4;s[d]=Math.round((l*p*.5+.5)*255),s[d+1]=Math.round((f*p*.5+.5)*255),s[d+2]=Math.round((p*.5+.5)*255),s[d+3]=255}return{width:t,height:r,rgba:s}}function mi(e){const n=new Uint8Array(e*e*4),t=e/2;for(let r=0;r<e;r++)for(let o=0;o<e;o++){const i=(o+.5-t)/t,s=(r+.5-t)/t,a=Math.hypot(i,s),c=a>=1?0:Math.sqrt(Math.max(0,1-a*a)),u=ae(a-.62,.11)*.55;Se(n,(r*e+o)*4,Math.min(1,c*.85+u))}return{width:e,height:e,rgba:n}}function sc(e){const n=new Uint8Array(e*e*4),t=e/2;for(let r=0;r<e;r++)for(let o=0;o<e;o++){const i=(o+.5-t)/t,s=(r+.5-t)/t,a=Math.hypot(i,s),c=Math.atan2(s,i),u=ae(a,.38)*(.55+.45*Math.cos(c*3+a*6));Se(n,(r*e+o)*4,u)}return{width:e,height:e,rgba:n}}function gi(e){const n=new Uint8Array(e*e*4),t=e/2,r=Math.max(2,Math.round(e*.04));for(let o=0;o<e;o++)for(let i=0;i<e;i++){const s=(i+.5-t)/t,a=(o+.5-t)/t,c=Math.hypot(s,a),u=Math.atan2(a,s),l=vn(Math.max(0,Math.cos(u)*.55+.45)),f=ae(c-.68,.07)*l+.35*ae(c-.78,.12)*ae(u-.9,.55);Se(n,(o*e+i)*4,Math.min(1,f)*on(i,o,e,r))}return{width:e,height:e,rgba:n}}function ac(e){if(!e||e.length<16)return!1;const n=e.length/4,t=Math.max(1,n/48|0);let r=0;for(let o=0;o<n;o+=t){const i=o*4;if(e[i]<240||e[i+1]<240||e[i+2]<240)return!1;r++}return r>0}function cc(e){return!e||!e.rgba?e:ac(e.rgba)?mt(e,2.8):e}const lc={"particle/drop":"particle/drop_normal","particle/water/rain_drops_sheet":"particle/water/rain_drops_sheet_normal","particle/bubbles/bubble1":"particle/bubbles/bubble1normal","particle/bubbles/bubble2":"particle/bubbles/bubble2_normal","particle/sharp_halo":"particle/sharp_halo_normal","particle/misc/wave":"particle/normal_splash","particle/halo":"particle/sharp_halo_normal"};function uc(e){if(!e)return null;const n=String(e);return/normal/i.test(n)?n:lc[n]||n+"_normal"}function fc(e){const n=String(e);return/(^|\/)normal_/.test(n)?null:/_normal$/i.test(n)?n.replace(/_normal$/i,""):/normal$/i.test(n)?n.replace(/normal$/i,""):null}function dc(e){if(Dn[e])return Dn[e]();const n=String(e).toLowerCase();return/normal/.test(n)?Ut(64,{r:.18,w:1},{r:.4,w:.2}):Ai(e)()}function bi(e,n,t){const r=lr(t*7919+17);let o=e;const i=[];for(let c=0;c<n;c++){const u=o*o,l=new Float32Array(u*2);for(let f=0;f<u;f++){const p=r()*Math.PI*2;l[f*2]=Math.cos(p),l[f*2+1]=Math.sin(p)}i.push({f:o,g:l,ox:c*7.31,oy:c*3.17}),o*=2}const s=(c,u,l,f,p)=>{const d=c.f,y=(u%d+d)%d,m=((l%d+d)%d*d+y)*2;return c.g[m]*f+c.g[m+1]*p},a=(c,u,l)=>{const f=(u+c.ox)*c.f,p=(l+c.oy)*c.f,d=Math.floor(f),y=Math.floor(p),x=f-d,m=p-y,M=fi(x),h=fi(m);return Kr(Kr(s(c,d,y,x,m),s(c,d+1,y,x-1,m),M),Kr(s(c,d,y+1,x,m-1),s(c,d+1,y+1,x-1,m-1),M),h)};return function(u,l,f){const p=f==null?i.length:Math.min(f,i.length);let d=1,y=0,x=0;for(let m=0;m<p;m++)y+=(a(i[m],u,l)*.5+.5)*d,x+=d,d*=.55;return y/x}}function yi(e,n,t){const{width:r,height:o,rgba:i}=e;if(r===n&&o===t)return e;const s=new Uint8Array(n*t*4);for(let a=0;a<t;a++){const c=(a+.5)/t*o-.5,u=Math.max(0,Math.min(o-1,Math.floor(c))),l=Math.max(0,Math.min(o-1,u+1)),f=c-Math.floor(c);for(let p=0;p<n;p++){const d=(p+.5)/n*r-.5,y=Math.max(0,Math.min(r-1,Math.floor(d))),x=Math.max(0,Math.min(r-1,y+1)),m=d-Math.floor(d),M=i[(u*r+y)*4+3],h=i[(u*r+x)*4+3],g=i[(l*r+y)*4+3],v=i[(l*r+x)*4+3],A=(M*(1-m)+h*m)*(1-f)+(g*(1-m)+v*m)*f;Se(s,(a*n+p)*4,A/255)}}return{width:n,height:t,rgba:s}}function Gt(e,n,t,r,o,i,s){const a=i===void 0?1:i,c=s===void 0?200:s,u=256,l=bi(n,t,r),f=new Uint8Array(u*u*4),p=u/2,d=u*u,y=new Float32Array(d);let x=1,m=0;for(let v=0;v<d;v++){const A=v%u,_=v/u|0,R=(A+.5)/u,L=(_+.5)/u,N=l(R+5.2,L+1.3,2)-.5,j=l(R+9.7,L+8.1,2)-.5,H=y[v]=l(R+N*.45,L+j*.45);H<x&&(x=H),H>m&&(m=H)}const M=m-x||1;for(let v=0;v<u;v++)for(let A=0;A<u;A++){const _=(y[v*u+A]-x)/M,R=Math.hypot((A+.5-p)/p,(v+.5-p)/p),L=Math.pow(Math.max(0,1-R),a);let N=Math.max(0,(_-(1-o))/(o||1));N=vn(Math.min(1,N))*L,Se(f,(v*u+A)*4,N)}let h=0;for(let v=0;v<d;v++)h=Math.max(h,f[v*4+3]);if(h>0&&h<c){const v=c/h;for(let A=0;A<d;A++)f[A*4+3]=Math.round(Math.min(255,f[A*4+3]*v))}const g={width:u,height:u,rgba:f};return u===e?g:yi(g,e,e)}function Jr(e,n){const t=e,r=bi(3,5,n??23),o=new Uint8Array(t*t*4),i=t*t,s=new Float32Array(i);let a=1,c=0;for(let p=0;p<i;p++){const d=p%t,y=p/t|0,x=(d+.5)/t,m=(y+.5)/t,M=r(x+2.1,m+4.7,2)-.5,h=r(x+6.3,m+1.9,2)-.5,g=s[p]=r(x+M*.28,m+h*.55);g<a&&(a=g),g>c&&(c=g)}const u=c-a||1;for(let p=0;p<t;p++)for(let d=0;d<t;d++){const y=(p+.5)/t,x=(d+.5)/t*2-1,m=.1+.52*Math.pow(y,1.25),M=(s[p*t+d]-a)/u,h=ae(x/(m||.01),.55)*ae(y-.58,.42);let g=vn(Math.min(1,Math.max(0,(M-.18)/.72)))*h;g*=y<.06?y/.06:1,Se(o,(p*t+d)*4,g)}let l=0;for(let p=0;p<i;p++)l=Math.max(l,o[p*4+3]);if(l>0&&l<220){const p=220/l;for(let d=0;d<i;d++)o[d*4+3]=Math.round(Math.min(255,o[d*4+3]*p))}const f=kn({width:t,height:t,rgba:o},.08);return t===e?f:yi(f,e,e)}function eo(e,n,t,r){const o=new Uint8Array(e*n*4),i=e/t,s=n/r;for(let a=0;a<n;a++)for(let c=0;c<e;c++){const u=Math.floor(c/i),l=Math.floor(a/s),f=(c+.5-u*i)/i*2-1,p=(a+.5-l*s)/s*2-1,d=1-Math.max(0,p)*.45,y=Math.hypot(f/(.52*d),p/.8),x=y>=1.12?0:ae(y,.48);Se(o,(a*e+c)*4,x)}return{width:e,height:n,rgba:o}}function vi(e){const n=new Uint8Array(e*e*4),t=lr(7),r=[];for(let o=0;o<11;o++)r.push({x:.14+t()*.72,y:.14+t()*.72,rx:.025+t()*.03,ry:.018+t()*.024,rot:t()*Math.PI});for(let o=0;o<e;o++)for(let i=0;i<e;i++){const s=(i+.5)/e,a=(o+.5)/e;let c=0;for(const u of r){const l=s-u.x,f=a-u.y,p=Math.cos(u.rot),d=Math.sin(u.rot),y=(l*p+f*d)/u.rx,x=(-l*d+f*p)/u.ry,m=ae(Math.hypot(y,x),.55);m>c&&(c=m)}Se(n,(o*e+i)*4,c)}return{width:e,height:e,rgba:n}}function ur(e,n){const t=n??19,r=lr(t),o=p=>Math.min(.86,Math.max(.14,p)),i=5+t%4,s=[];let a=o(.5+(r()-.5)*.16);for(let p=0;p<=i;p++){const d=.06+p/i*.86;p>0&&(a=o(a+(r()-.5)*.32)),s.push([a,d])}const c=[];for(let p=0;p<s.length-1;p++)c.push([s[p],s[p+1],1]);const u=1+t%2;for(let p=0;p<u;p++){const d=1+(t+p*3)%Math.max(1,s.length-2),y=s[d],x=[y];let m=y[0],M=y[1];const h=2+t%2;for(let g=0;g<h;g++)m=o(m+(r()-.5)*.36),M=Math.min(.92,M+.1+r()*.08),x.push([m,M]);for(let g=0;g<x.length-1;g++)c.push([x[g],x[g+1],.45+p*.1])}const l=new Uint8Array(e*e*4),f=Math.max(2,Math.round(e*.04));for(let p=0;p<e;p++)for(let d=0;d<e;d++){const y=(d+.5)/e,x=(p+.5)/e;let m=9,M=0;for(const[g,v,A]of c){const _=v[0]-g[0],R=v[1]-g[1],L=_*_+R*R||1e-8,N=Math.max(0,Math.min(1,((y-g[0])*_+(x-g[1])*R)/L)),j=Math.hypot(y-(g[0]+_*N),x-(g[1]+R*N));j/A<m&&(m=j/A,M=A)}const h=.95*ae(m,.012)+.3*ae(m,.05)*M;Se(l,(p*e+d)*4,Math.min(1,h)*on(d,p,e,f))}return{width:e,height:e,rgba:l}}function to(e,n){const t=new Uint8Array(e*n*4);for(let r=0;r<n;r++)for(let o=0;o<e;o++){const i=(o+.5-e/2)/(e/2),s=(r+.5-n/2)/(n/2),a=ae(i,.34)*Math.exp(-Math.max(0,-s-.05)*4.2)*(s<.1?1:Math.max(0,1-s*4)),c=Math.hypot(i/.34,(s-.42)/.3),u=c>=1?0:ae(c,.5);Se(t,(r*e+o)*4,Math.max(a,u))}return{width:e,height:n,rgba:t}}function pc(e){return Ut(e,{r:.1,w:1},{r:.3,w:.16})}function no(e,n){const t=new Uint8Array(e*n*4);for(let r=0;r<n;r++){const o=(r+.5)/n,i=vn(Math.min(1,Math.min(o/.08,(1-o)/.08))),s=ae(o-.46,.24)*i,a=.5*(1-vn(Math.min(1,Math.max(0,(o-.42)/.5)))*.6);for(let c=0;c<e;c++){const u=(c+.5-e/2)/(e/2);Se(t,(r*e+c)*4,ae(Math.abs(u)/(a||.01),.5)*s)}}return{width:e,height:n,rgba:t}}function xi(e){const n=new Uint8Array(e*e*4),t=e/2,r=Math.max(2,Math.round(e*.04));for(let o=0;o<e;o++)for(let i=0;i<e;i++){const s=(i+.5-t)/t,a=(o+.5-t)/t,c=ae(Math.hypot(s,a),.42),u=ae(Math.hypot(s-.34,a),.36),l=Math.max(0,c-u*1.08)*on(i,o,e,r);Se(n,(o*e+i)*4,l)}return{width:e,height:e,rgba:n}}function wi(e){const n=new Uint8Array(e*e*4),t=e/2,r=Math.max(2,Math.round(e*.04));for(let o=0;o<e;o++)for(let i=0;i<e;i++){const s=(i+.5-t)/t,a=(o+.5-t)/t;let c=ae(Math.hypot(s,a),.08);for(let u=0;u<6;u++){const l=u*Math.PI/3,f=Math.cos(l),p=Math.sin(l),d=s*f+a*p,y=-s*p+a*f;if(d<0)continue;const x=Math.max(0,1.02-d/.72);c+=ae(y,.028)*ae(d,.5)*x,c+=.55*ae(y-(d-.28)*.65,.02)*ae(d-.28,.12)*x,c+=.55*ae(y+(d-.28)*.65,.02)*ae(d-.28,.12)*x,c+=.4*ae(y-(d-.48)*.7,.016)*ae(d-.48,.08)*x,c+=.4*ae(y+(d-.48)*.7,.016)*ae(d-.48,.08)*x}Se(n,(o*e+i)*4,Math.min(1,c)*on(i,o,e,r))}return{width:e,height:e,rgba:n}}function Mi(e,n){const t=new Uint8Array(e*e*4),r=e/2,o=Math.max(2,Math.round(e*.04)),i=Math.abs(n|0)%3;for(let s=0;s<e;s++)for(let a=0;a<e;a++){const c=(a+.5-r)/r*1.55,u=(s+.5-r)/r*1.55,l=Math.abs(Math.abs(c)+Math.abs(u)-.55);let f=ae(l,.016);i===0?(f+=ae(c,.012)*ae(u,.38),f+=ae(u,.012)*ae(c,.38)):i===1?(f+=ae(c-u,.012)*ae(c+u,.36),f+=ae(c+u,.012)*ae(c-u,.36)):(f+=ae(Math.hypot(c,u)-.26,.014),f+=ae(c,.012)*ae(u,.22)),Se(t,(s*e+a)*4,Math.min(1,f)*on(a,s,e,o))}return kn({width:e,height:e,rgba:t},.03)}function ro(e){let n=0;const t=String(e);for(let r=0;r<t.length;r++)n=n*31+t.charCodeAt(r)|0;return n}function _i(e){const n=new Uint8Array(e*e*4),t=e/2,r=Math.max(2,Math.round(e*.03));for(let o=0;o<e;o++)for(let i=0;i<e;i++){const s=(i+.5-t)/t,a=(o+.5-t)/t,c=Math.hypot(s,a),u=ae(c,.07)+.85*ae(s,.62)*ae(a,.045)+.22*ae(s,.92)*ae(a,.018);Se(n,(o*e+i)*4,Math.min(1,u)*on(i,o,e,r))}return{width:e,height:e,rgba:n}}const Dn={"particle/halo_6":()=>Ut(256,{r:.14,w:1},{r:.4,w:.17}),"particle/normal_splash":()=>mt(mi(256),3.2),"particle/drop_normal":()=>mt(no(128,512),3.4),"particle/normal_ring_smooth":()=>mt(Qr(256,.55,.12),3.1),"particle/normal_pinch_rotate":()=>mt(sc(256),2.8),"particle/water/rain_drops_sheet_normal":()=>mt(eo(256,512,2,4),3.6),"particle/bubbles/bubble1normal":()=>mt(Un(256,1),3.2),"particle/bubbles/bubble2_normal":()=>mt(Un(256,2),3.2),"particle/sharp_halo_normal":()=>mt(Fn(256,[{r:.035,w:1},{r:.09,w:.45},{r:.22,w:.08}]),3.4),"particle/beam/beam_0":()=>Et(128,512,.46,!0),"particle/beam/beam_1":()=>Et(128,512,.34,!0),"particle/beam/beam_2":()=>Et(128,512,.22,!0),"particle/beam/beam_2_fade":()=>Et(128,512,.24,!1),"particle/light/light_shafts_0":()=>Et(128,512,.42,!0),"particle/light/light_shafts_1":()=>Et(128,512,.3,!0),"particle/light/light_shafts_3":()=>Et(128,512,.26,!0),"particle/light/light_shafts_5":()=>Et(128,512,.23,!0),"particle/light/light_shafts_6":()=>Et(128,512,.2,!0),"particle/nature/rosepetals":()=>hi(256),"particle/nature/leaves":()=>We(256,0),"particle/nature/leaves1":()=>We(256,1),"particle/nature/leaves2":()=>We(256,2),"particle/nature/leaves3":()=>We(256,3),"particle/nature/leaves5":()=>We(256,5),"particle/nature/leaves6":()=>We(256,6),"particle/nature/leaves7":()=>We(256,7),"particle/nature/leaves8":()=>We(256,8),"particle/nature/snow":()=>wi(256),"particle/halo":()=>Ut(256,{r:.12,w:1},{r:.3,w:.15}),"particle/halo_1":()=>Ut(256,{r:.1,w:1},{r:.3,w:.13}),"particle/halo_2":()=>Ut(256,{r:.2,w:.9},{r:.44,w:.2}),"particle/halo_3":()=>Fn(256,[{r:.045,w:1},{r:.13,w:.85},{r:.36,w:.15}]),"particle/halo_4":()=>Ut(256,{r:.085,w:1},{r:.28,w:.12}),"particle/halo_5":()=>Fn(256,[{r:.04,w:1},{r:.11,w:.8},{r:.34,w:.17}]),"particle/sharp_halo":()=>Fn(256,[{r:.035,w:1},{r:.09,w:.45},{r:.22,w:.08}]),"particle/chromaticdot":()=>pc(128),"particle/light/flare_0":()=>Dt(256,6,.58,10,.08),"particle/light/flare_1":()=>Dt(512,4,.62,14,.07),"particle/light/flare_2":()=>_i(256),"particle/drop":()=>no(128,512),"particle/nature/rain1":()=>di(128,512,10,1,.78),"particle/nature/rain2":()=>di(128,512,10,1.6,.66),"particle/water/rain_drops_sheet":()=>eo(256,512,2,4),"particle/fog/fog1":()=>Gt(512,4,5,1,.4,.9,150),"particle/fog/fog2":()=>Gt(512,3,5,2,.45,.8,140),"particle/fog/fog3":()=>Gt(512,6,4,3,.36,1,150),"particle/smoke/smoke1":()=>Gt(512,3,5,7,.55,1.5,130),"particle/smoke/smoke2":()=>Gt(512,2,5,11,.6,1.7,120),"particle/smoke/smoke2light":()=>Gt(512,2,5,13,.4,1.7,110),"particle/misc/wave":()=>Qr(512,.72,.085),"particle/misc/star_0":()=>Dt(256,5,.62,8,.1),"particle/bubbles/bubble1":()=>Un(256,1),"particle/bubbles/bubble2":()=>Un(256,2),"particle/bubbles/bubble3":()=>Un(256,3),"particle/debris/debris1":()=>vi(128),"particle/lightning/lightning1":()=>ur(256,3),"particle/lightning/lightning2":()=>ur(256,11),"particle/lightning/lightning3":()=>ur(256,19),"particle/fire/fire1":()=>Jr(256,23),"particle/fire/fire2":()=>Jr(256,41),"particle/star":()=>Dt(256,4,.58,12,.09),"particle/shape/circle_wind":()=>gi(256),"particle/sickle":()=>xi(256),"particle/magic/glyph_4":()=>Mi(256,4),"@sparkle":()=>Dt(256,4,.6,16,.08),"@star":()=>Dt(256,5,.62,8,.1),"@trail":()=>to(128,256)};function Ai(e){const n=String(e).toLowerCase();if(/normal/.test(n)){const t=fc(e);return t?()=>mt(dc(t),2.8):()=>mt(mi(128),2.6)}return/rosepetal|petal|sakura|blossom/.test(n)?()=>hi(256):/leaf|leaves|foliage/.test(n)?/leaves8/.test(n)?()=>We(256,8):/leaves7/.test(n)?()=>We(256,7):/leaves6/.test(n)?()=>We(256,6):/leaves5/.test(n)?()=>We(256,5):/leaves3/.test(n)?()=>We(256,3):/leaves2/.test(n)?()=>We(256,2):/leaves1/.test(n)?()=>We(256,1):()=>We(256,0):/circle_wind|windcircle/.test(n)?()=>gi(256):/fog|cloud|mist|vapor/.test(n)?()=>Gt(512,4,5,5,.4,.9,150):/smoke/.test(n)?()=>Gt(512,3,5,8,.55,1.5,130):/beam|shaft|ray|godray/.test(n)?()=>Et(128,512,.3,!0):/flare/.test(n)?()=>_i(256):/bubble/.test(n)?()=>pi(256,1):/ring|wave/.test(n)?()=>Qr(512,.72,.085):/fire|flame|ember|ash/.test(n)?()=>Jr(256,ro(n)):/sickle|crescent|moon/.test(n)?()=>xi(256):/glyph|magic|rune/.test(n)?()=>Mi(256,ro(n)):/snowflake|雪花|snow/.test(n)?()=>wi(256):/流星|meteor|shooting/.test(n)?()=>to(128,256):/star|星/.test(n)?()=>Dt(256,5,.62,8,.1):/sparkle|glint|twinkle/.test(n)?()=>Dt(256,4,.6,16,.08):/rain_drops_sheet|drops_sheet/.test(n)?()=>eo(256,512,2,4):/drop|rain/.test(n)?()=>no(128,512):/debris|dirt|rock/.test(n)?()=>vi(128):/lightning|bolt|arc/.test(n)?()=>ur(256,ro(n)):/note|music/.test(n)?()=>Dt(256,4,.55,8,.12):/trail|streak/.test(n)?()=>to(128,256):()=>Ut(256,{r:.12,w:1},{r:.3,w:.15})}function hc(e){if(Rn.has(e))return Rn.get(e);let n=null;const t=Zr.get(e);if(t)try{n=t()}catch{n=null}if(!n&&cr)try{n=cr(e)}catch{n=null}if(!n&&Dn[e])try{n=Dn[e]()}catch{n=null}if(!n)try{n=Ai(e)()}catch{n=null}return n||(n=Ut(256,{r:.12,w:1},{r:.3,w:.15})),Rn.set(e,n),n}function mc(e){return typeof e=="string"&&e.indexOf("particle/")===0}const gc=Object.freeze(Object.defineProperty({__proto__:null,buildBuiltinParticleTexture:hc,builtinParticleFrames:ic,isBuiltinParticleTextureName:mc,listBuiltinParticleTextureNames:oc,particleNormalNameForAlbedo:uc,prepareParticleNormalTexture:cc,resetParticleTextureFactories:rc,setParticleTextureFactory:tc,setParticleTextureProvider:nc},Symbol.toStringTag,{value:"Module"})),Ti=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function Yt(e,n,t){const r=t||new Float32Array(16);for(let o=0;o<4;o++)for(let i=0;i<4;i++)r[o*4+i]=e[i]*n[o*4]+e[4+i]*n[o*4+1]+e[8+i]*n[o*4+2]+e[12+i]*n[o*4+3];return r}function Si(e){const n=[];for(let r=0;r<4;r++)n.push([e[r],e[4+r],e[8+r],e[12+r],0,0,0,0]),n[r][4+r]=1;for(let r=0;r<4;r++){let o=r;for(let a=r+1;a<4;a++)Math.abs(n[a][r])>Math.abs(n[o][r])&&(o=a);const i=n[r];n[r]=n[o],n[o]=i;const s=n[r][r];if(Math.abs(s)<1e-12)return Float32Array.from(Ti);for(let a=0;a<8;a++)n[r][a]/=s;for(let a=0;a<4;a++){if(a===r)continue;const c=n[a][r];if(c!==0)for(let u=0;u<8;u++)n[a][u]-=c*n[r][u]}}const t=new Float32Array(16);for(let r=0;r<4;r++)for(let o=0;o<4;o++)t[r*4+o]=n[o][4+r];return t}function oo(e,n,t,r,o,i,s,a,c,u){const l=u||new Float32Array(16),f=Math.cos(r),p=Math.sin(r),d=Math.cos(o),y=Math.sin(o),x=Math.cos(i),m=Math.sin(i);return l[0]=x*d*s,l[1]=m*d*s,l[2]=-y*s,l[3]=0,l[4]=(x*y*p-m*f)*a,l[5]=(m*y*p+x*f)*a,l[6]=d*p*a,l[7]=0,l[8]=(x*y*f+m*p)*c,l[9]=(m*y*f-x*p)*c,l[10]=d*f*c,l[11]=0,l[12]=e,l[13]=n,l[14]=t,l[15]=1,l}function Bn(e,n){const t=[];for(;n<e.byteLength;){const o=e.getUint8(n++);if(o===0)break;t.push(o)}let r="";try{r=new TextDecoder("utf-8").decode(new Uint8Array(t))}catch{r=String.fromCharCode.apply(null,t)}return{value:r,next:n}}function fr(e,n,t=0){const r=[];for(let o=0;o<n.length;o++)r.push(n.charCodeAt(o));e:for(let o=t;o<=e.length-r.length;o++){for(let i=0;i<r.length;i++)if(e[o+i]!==r[i])continue e;return o}return-1}function bc(e){const n=new DataView(e.buffer,e.byteOffset,e.byteLength),t=String.fromCharCode.apply(null,Array.from(e.subarray(0,8)));if(!t.startsWith("MDLV"))throw new Error("\u4E0D\u662F MDL: "+t);const r=Bn(n,21),i=parseInt(t.slice(4),10)>=23?[{lenOff:32,stride:80,uv:72,bone:40,weight:56},{lenOff:32,stride:48,uv:40,bone:-1,weight:-1}]:[{lenOff:8,stride:52,uv:44,bone:12,weight:28},{lenOff:4,stride:52,uv:44,bone:12,weight:28},{lenOff:32,stride:80,uv:72,bone:40,weight:56}];let s=null,a=0,c=0;for(const X of i){const ie=r.next+X.lenOff;if(ie+4>e.byteLength)continue;const J=n.getUint32(ie,!0);if(J>0&&J%X.stride===0&&ie+4+J<=e.byteLength){s=X,a=J,c=ie;break}}if(!s)throw new Error("\u9876\u70B9\u533A\u957F\u5EA6\u5F02\u5E38\uFF08"+t+"\uFF0C\u5DF2\u8BD5 stride "+i.map(X=>X.stride).join("/")+"\uFF09");const u=c+4,l=a/s.stride,f=new Float32Array(l*3),p=new Float32Array(l*2),d=new Float32Array(l*4),y=new Float32Array(l*4);for(let X=0;X<l;X++){const ie=u+X*s.stride;if(f[X*3]=n.getFloat32(ie,!0),f[X*3+1]=n.getFloat32(ie+4,!0),f[X*3+2]=n.getFloat32(ie+8,!0),p[X*2]=n.getFloat32(ie+s.uv,!0),p[X*2+1]=n.getFloat32(ie+s.uv+4,!0),s.bone>=0&&s.weight>=0)for(let J=0;J<4;J++)d[X*4+J]=n.getUint32(ie+s.bone+J*4,!0),y[X*4+J]=n.getFloat32(ie+s.weight+J*4,!0);else d[X*4]=0,y[X*4]=1}const x=n.getUint32(u+a,!0),m=u+a+4,M=l>65535&&x%4===0,h=M?x/4:x/2,g=M?new Uint32Array(h):new Uint16Array(h);if(M)for(let X=0;X<h;X++)g[X]=n.getUint32(m+X*4,!0);else for(let X=0;X<h;X++)g[X]=n.getUint16(m+X*2,!0);const v=vc(e,n),A=xc(e,n,v.length),_=Mc(e,n,v),R=yc(e,n,v.length),L=[],N=[],j=[];if(v.length>0){const X=v.map((J,Z)=>{const te=J.matrix,le=Math.hypot(te[0],te[1]),Ue=Math.hypot(te[4],te[5]);return j[Z]=Float32Array.from([te[12],te[13],te[14],0,0,Math.atan2(te[1],te[0]),le||1,Ue||1,te[10]||1]),Float32Array.from(te)});for(let J=0;J<v.length;J++){const Z=j[J],te=v[J].matrix;Math.hypot(Z[0]-te[12],Z[1]-te[13])>.001&&(X[J]=oo(Z[0],Z[1],Z[2],Z[3],Z[4],Z[5],Z[6],Z[7],Z[8],new Float32Array(16)))}const ie=[];for(let J=0;J<v.length;J++){const Z=v[J].parent;ie[J]=Z>=0&&Z<J?Yt(ie[Z],X[J]):Float32Array.from(X[J])}for(let J=0;J<v.length;J++)L[J]=Si(ie[J]);if(_){const J=[];for(let Z=0;Z<v.length;Z++){const te=v[Z].parent;J[Z]=te>=0&&te<Z?Yt(J[te],_[Z]):Float32Array.from(_[Z])}for(let Z=0;Z<v.length;Z++)N[Z]=Yt(J[Z],L[Z])}}let H=1/0,K=-1/0,O=1/0,V=-1/0;for(let X=0;X<l;X++){const ie=f[X*3],J=f[X*3+1];ie<H&&(H=ie),ie>K&&(K=ie),J<O&&(O=J),J>V&&(V=J)}return{magic:t,materialPath:r.value,vertexCount:l,positions:f,uvs:p,boneIdx:d,weights:y,indexCount:h,indexType:M?"u32":"u16",indices:g,bones:v,animations:A,animBound:wc(A,v),invBindWorld:L,bindTRS:j.length>0?j:null,attachments:R.length>0?R:null,restCorrection:N.length>0?N:null,bounds:{minX:H,maxX:K,minY:O,maxY:V}}}function yc(e,n,t){const r=fr(e,"MDAT");if(r<0)return[];const o=n.getUint16(r+13,!0);if(o<=0||o>256)return[];const i=[];let s=r+15;for(let a=0;a<o&&!(s+2>e.length);a++){const c=n.getUint16(s,!0),u=Bn(n,s+2);if(u.next+64>e.length)break;const l=new Float32Array(16);for(let f=0;f<16;f++)l[f]=n.getFloat32(u.next+f*4,!0);c<t&&i.push({bone:c,name:u.value,matrix:l}),s=u.next+64}return i}function vc(e,n){const t=fr(e,"MDLS");if(t<0)return[];const r=n.getUint32(t+13,!0);if(r<=0||r>1024)return[];const o=[];let i=t+17;for(let s=0;s<r;s++){if(i+77>n.byteLength)return o;const a=n.getUint32(i+1,!0),c=n.getInt32(i+5,!0),u=new Float32Array(16);for(let f=0;f<16;f++)u[f]=n.getFloat32(i+13+f*4,!0);const l=Bn(n,i+13+64);o.push({id:a,parent:c>=0&&c<r?c:-1,matrix:u}),i=l.next}return o}function xc(e,n,t){const r=fr(e,"MDLA");if(r<0)return[];let o=r+9;const i=n.getUint32(o,!0);o+=4;const s=n.getUint32(o,!0);if(o+=4,s<=0||s>256)return[];const a=[];for(let c=0;c<s&&!(o+16>n.byteLength);c++){const u=n.getUint32(o,!0);o+=8;const l=Bn(n,o);o=l.next;const f=Bn(n,o);if(o=f.next,o+16>n.byteLength)break;const p=n.getFloat32(o,!0);o+=4;const d=n.getUint32(o,!0);o+=8;const y=n.getUint32(o,!0);if(o+=4,y>1024)break;const x=[];for(let m=0;m<y&&!(o+8>n.byteLength);m++){o+=4;const M=n.getUint32(o,!0);o+=4;const h=Math.floor(M/36);if(o+M>n.byteLength)break;const g=new Float32Array(h*9);for(let v=0;v<h;v++){const A=o+v*36;for(let _=0;_<9;_++)g[v*9+_]=n.getFloat32(A+_*4,!0)}o+=M,x.push({frameCount:h,keyframes:g})}if(o+=35,x.length>0&&d>0&&p>0&&a.push({id:u,name:l.value,mode:f.value,fps:p,frameCount:d,duration:d/p,tracks:x}),o>=i)break}return a}function wc(e,n){let t=0,r=0;for(const o of e)for(let i=0;i<o.tracks.length;i++){const s=o.tracks[i];if(!s)continue;const a=n[i],c=a?a.matrix[12]:0,u=a?a.matrix[13]:0,l=s.keyframes;for(let f=0;f<s.frameCount;f++){const p=Math.abs(l[f*9]-c),d=Math.abs(l[f*9+1]-u);p>t&&(t=p),d>r&&(r=d)}}return{x:t,y:r}}function Mc(e,n,t){if(t.length===0)return null;const r=fr(e,"MDLE");if(r<0)return null;const o=r+8+1+4+4;if(o+t.length*64>n.byteLength)return null;const i=[];for(let s=0;s<t.length;s++){const a=new Float32Array(16);for(let c=0;c<16;c++)a[c]=n.getFloat32(o+s*64+c*4,!0);i.push(a)}return i}function _c(e,n,t,r){const o=e.frameCount;if(o===0)return r[0]=0,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=0,r[6]=1,r[7]=1,r[8]=1,r;const i=t*n.fps;let s,a,c;if(n.mode==="loop"){const d=Math.max(1,o-1),y=(i%d+d)%d;s=Math.floor(y),a=(s+1)%o,c=y-s}else if(n.mode==="mirror"){const d=Math.max(1,o-1),y=d*2;let x=(i%y+y)%y;x>d&&(x=y-x),s=Math.floor(x),a=Math.min(s+1,o-1),c=x-s}else{const d=Math.min(Math.max(i,0),o-1);s=Math.floor(d),a=Math.min(s+1,o-1),c=d-s}const u=e.keyframes,l=s*9,f=a*9,p=1-c;for(let d=0;d<9;d++)if(d>=3&&d<=5){let y=u[f+d]-u[l+d];y>Math.PI?y-=2*Math.PI:y<-Math.PI&&(y+=2*Math.PI),r[d]=u[l+d]+y*c}else r[d]=u[l+d]*p+u[f+d]*c;return r}function Ac(e,n,t){const r=e.bindTRS&&e.bindTRS[n];if(r)return t.set(r),t;const o=e.bones[n].matrix;return t[0]=o[12],t[1]=o[13],t[2]=o[14],t[3]=0,t[4]=0,t[5]=Math.atan2(o[1],o[0]),t[6]=Math.hypot(o[0],o[1])||1,t[7]=Math.hypot(o[4],o[5])||1,t[8]=o[10]||1,t}function io(e,n,t,r){const o=e.bones,i=o.length;if(i===0)return null;const s=!!(r&&r.size>0);if(!e._skin||e._skin.length!==i*16){e._skin=new Float32Array(i*16),e._local=[],e._world=[],e._tmp=new Float32Array(16),e._tmp2=new Float32Array(16);for(let p=0;p<i;p++)e._local.push(new Float32Array(16)),e._world.push(new Float32Array(16))}const a=Array.isArray(t)&&t.length>0,c=[];if(a)for(const p of t){if(p.visible===!1||p.visible===0)continue;const d=e.animations.find(y=>y.id===p.animation);d&&c.push({anim:d,additive:!!p.additive,blend:typeof p.blend=="number"?p.blend:1,rate:typeof p.rate=="number"?p.rate:1})}if(c.length===0&&!a){const p=e.animations[0];if(p)c.push({anim:p,additive:!1,blend:1,rate:1});else if(!s)return null}const u=e._trsBase||(e._trsBase=new Float32Array(9)),l=e._trsAcc||(e._trsAcc=new Float32Array(9)),f=e._trsSmp||(e._trsSmp=new Float32Array(9));for(let p=0;p<i;p++){Ac(e,p,u),l.set(u);let d=!1,y=0;for(const m of c){const M=m.anim.tracks[p];if(!M)continue;_c(M,m.anim,n*m.rate,f);const h=m.blend;if(m.additive){for(let g=0;g<9;g++){let v=f[g]-u[g];g>=3&&g<=5&&(v>Math.PI?v-=2*Math.PI:v<-Math.PI&&(v+=2*Math.PI)),l[g]+=v*h}y+=h}else for(let g=0;g<9;g++)l[g]=l[g]*(1-h)+f[g]*h;d=!0}if(y>1)for(let m=0;m<9;m++)l[m]=u[m]+(l[m]-u[m])/y;const x=s?r.get(p):void 0;x&&(l[0]=x[0],l[1]=x[1],l[2]=x[2],d=!0),d?oo(l[0],l[1],l[2],l[3],l[4],l[5],l[6],l[7],l[8],e._local[p]):oo(u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7],u[8],e._local[p])}for(let p=0;p<i;p++){const d=o[p].parent;d>=0&&d<p?Yt(e._world[d],e._local[p],e._world[p]):e._world[p].set(e._local[p])}for(let p=0;p<i;p++)Yt(e._world[p],e.invBindWorld[p],e._tmp),e._skin.set(e._tmp,p*16);return e._skin}function Ei(e,n){return!e||!e.invBindWorld||!(n>=0&&n<e.invBindWorld.length)?null:Si(e.invBindWorld[n])}function Tc(e,n){return Yt(e,n)}function Pi(e,n){if(!e||!e.attachments||typeof n!="string"||n===""||!e._world)return null;for(const t of e.attachments)if(t.name===n)return t.bone<0||t.bone>=e._world.length?null:Yt(e._world[t.bone],t.matrix);return null}function Ci(e,n){if(!e||!e.attachments||typeof n!="string"||n==="")return null;for(const t of e.attachments){if(t.name!==n)continue;const r=Ei(e,t.bone);return r?Yt(r,t.matrix):null}return null}function so(e,n,t){const r=e&&e.angles&&e.angles[2]||0,o=e&&e.scale?e.scale[0]:1,i=e&&e.scale?e.scale[1]:1,s=r*Math.PI/180,a=Math.cos(s),c=Math.sin(s),u=n*o,l=t*i;return[u*a-l*c,u*c+l*a]}function Sc(e){const n=new Map,t=new Map;for(const i of e){if(!i||i.id===void 0||i.id===null||(n.set(i.id,i),i.parentId===void 0||i.parentId===null))continue;const s=t.get(i.parentId);s?s.push(i):t.set(i.parentId,[i])}const r=(i,s)=>{const a=t.get(i.id);if(a)for(const c of a)s.push(c),r(c,s)},o=[];for(const i of e){const s=i&&i.attachment;if(typeof s!="string"||s==="")continue;const a=n.get(i.parentId);if(!a||!a.puppet)continue;const c=Ci(a.puppet,s);if(!c)continue;const u=c[12],l=c[13],f=so(a,u,l),p=[];r(i,p),i.origin[0]+=f[0],i.origin[1]+=f[1];for(const d of p)d.origin[0]+=f[0],d.origin[1]+=f[1];i.parallaxDepth=a.parallaxDepth?a.parallaxDepth.slice():null;for(const d of p)d.parallaxDepth=i.parallaxDepth?i.parallaxDepth.slice():null;i.attachBindDelta=[f[0],f[1]],o.push({layer:i,parent:a,name:s,bindX:u,bindY:l,desc:p})}for(const i of o){i.baseX=i.layer.origin[0],i.baseY=i.layer.origin[1],i.subtree=[{layer:i.layer,x:i.layer.origin[0],y:i.layer.origin[1]}];for(const s of i.desc)i.subtree.push({layer:s,x:s.origin[0],y:s.origin[1]});for(const s of i.subtree)s.layer.attachBase||(s.layer.attachBase=[s.x,s.y])}return o}function Ec(e,n,t){if(!e||e.length===0)return;const r=new Set,o=[];for(const a of e){const c=a.parent&&a.parent.puppet;if(!c){o.push(null);continue}if(!r.has(c)){r.add(c);const l=typeof t=="function"?t(a.parent):null;io(c,n,a.parent.animationLayers,l)}const u=Pi(c,a.name);if(!u){o.push(null);continue}o.push(so(a.parent,u[12]-a.bindX,u[13]-a.bindY))}const i=a=>{const c=a.layer.attachBase;return c||[a.x,a.y]},s=new Set;for(const a of e){const c=a.subtree||[{layer:a.layer,x:a.baseX,y:a.baseY}];for(const u of c){if(s.has(u.layer))continue;s.add(u.layer);const l=i(u);u.layer.origin[0]=l[0],u.layer.origin[1]=l[1]}}for(let a=0;a<e.length;a++){const c=e[a],u=o[a],l=c.subtree||[{layer:c.layer,x:c.baseX,y:c.baseY}];if(u)for(const f of l)f.layer.origin[0]+=u[0],f.layer.origin[1]+=u[1]}}const Pc=128,dr=24;function Cc(e){const n=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS)||256,t=Math.floor((n-32)/4);return Math.max(dr,Math.min(Pc,t))}const Lc=e=>`#version 300 es
|
|
424
|
+
}`,r=(u,l)=>{const f=t.createShader(u);if(t.shaderSource(f,l),t.compileShader(f),!t.getShaderParameter(f,t.COMPILE_STATUS))throw new Error("\u7C92\u5B50 shader: "+t.getShaderInfoLog(f));return f},i=t.createProgram();if(t.attachShader(i,r(t.VERTEX_SHADER,e)),t.attachShader(i,r(t.FRAGMENT_SHADER,n)),t.linkProgram(i),!t.getProgramParameter(i,t.LINK_STATUS))throw new Error("\u7C92\u5B50 shader \u94FE\u63A5\u5931\u8D25: "+t.getProgramInfoLog(i));const s=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,s),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-.5,-.5,.5,-.5,-.5,.5,.5,.5]),t.STATIC_DRAW);const a=t.createBuffer(),o=t.createVertexArray();t.bindVertexArray(o),t.bindBuffer(t.ARRAY_BUFFER,s),t.enableVertexAttribArray(0),t.vertexAttribPointer(0,2,t.FLOAT,!1,8,0),t.vertexAttribDivisor(0,0),t.bindBuffer(t.ARRAY_BUFFER,a);const c=56;return t.enableVertexAttribArray(1),t.vertexAttribPointer(1,3,t.FLOAT,!1,c,0),t.vertexAttribDivisor(1,1),t.enableVertexAttribArray(2),t.vertexAttribPointer(2,2,t.FLOAT,!1,c,12),t.vertexAttribDivisor(2,1),t.enableVertexAttribArray(3),t.vertexAttribPointer(3,4,t.FLOAT,!1,c,20),t.vertexAttribDivisor(3,1),t.enableVertexAttribArray(4),t.vertexAttribPointer(4,3,t.FLOAT,!1,c,36),t.vertexAttribDivisor(4,1),t.enableVertexAttribArray(5),t.vertexAttribPointer(5,2,t.FLOAT,!1,c,48),t.vertexAttribDivisor(5,1),t.bindVertexArray(null),{prog:{prog:i,uniTex:t.getUniformLocation(i,"u_tex"),uniNormal:t.getUniformLocation(i,"u_normal"),uniScene:t.getUniformLocation(i,"u_scene"),uniRefract:t.getUniformLocation(i,"u_refract"),uniSampleScene:t.getUniformLocation(i,"u_sampleScene"),uniResolution:t.getUniformLocation(i,"u_resolution"),uniRefractScale:t.getUniformLocation(i,"u_refractScale"),uniMvp:t.getUniformLocation(i,"u_mvp"),uniFrameCount:t.getUniformLocation(i,"u_frameCount"),uniFrames:t.getUniformLocation(i,"u_frames")},quadBuf:s,vbuf:a,vao:o}}function yd(t){const e=t&&t.passes&&t.passes[0]&&t.passes[0].combos;return!!(e&&Number(e.REFRACT)===1)}function Ay(t){if(!t||t.length<16)return!1;const e=t.length/4,n=Math.max(1,e/64|0);let r=0;for(let i=0;i<e;i+=n){const s=i*4;if(t[s]<250||t[s+1]<250||t[s+2]<250||t[s+3]<250)return!1;r++}return r>0}function bd(t,e,n,r){let i=Math.abs(Number(t)||0)*(Number(e)||0);const s=Number(n)||0,a=Number(r)||0;return s>0&&(i=Math.max(s,i)),a>0&&(i=Math.min(a,i)),i}function Sc(t,e){return t||e?Math.atan2(e,t)-Math.PI/2:0}function wd(t,e){return t&&t.kind==="ropetrail"?Math.max(1,e||1):1}function vd(t){if(!t||t.kind!=="ropetrail")return 1;const e=Math.round(Number(t.segments)||0);return e>=2?Math.min(32,e):8}function kd(t){if(!t||t.kind!=="ropetrail")return 0;const e=Number(t.length);return Number.isFinite(e)&&e>0?e:.2}function Pc(t){return t.life>0?t.age/t.life:0}class xy{constructor(){this.alive=!1,this.x=this.y=this.z=0,this.vx=this.vy=this.vz=0,this.bx=this.by=this.bz=0,this.age=0,this.life=1,this.size=1,this.baseSize=1,this.rot=0,this.rotVel=0,this.r=this.g=this.b=1,this.baseR=this.baseG=this.baseB=1,this.alpha=1,this.baseAlpha=1,this.seed=0,this.frame=0,this.oscPhase=0,this.oscFreq=0,this.oscAmp=0,this.oscAPhase=0,this.oscAFreq=0,this.oscSPhase=0,this.oscSFreq=0,this.turbSpeed=0,this.turbPhase=0,this.trail=null,this.trailClock=0,this.seq=0}}class Ty{constructor(e,n,r,i){this.gl=e,this.model=n||{},this.override=r||{},this.layer=i||null,this.syncLayerTransform(),this.maxCount=Math.max(1,Math.min(2e4,oe(this.model.maxcount,100))),this.simTime=0,this.paused=!1,this.texture=null,this.normalTex=null,this.material=null,this.blend="translucent",this.refract=!1,this.refractAmount=.04,this.opacityMul=1,this.lifetimeMul=1,this.visible=!0,this._ready=!1,this._prog=null,this._vbuf=null,this._quadBuf=null,this._vao=null,this._data=null,this._sceneTex=null,this.sequenceMul=Math.max(1,Math.round(oe(this.model.sequencemultiplier,1))),this.animationMode=this.model.animationmode||null,this.texFrames=null,this.frameCount=this.sequenceMul*this.sequenceMul,this.texAspectX=1,this.texAspectY=1,this.controlPoints=(this.model.controlpoint||[]).filter(Boolean).map(s=>({id:oe(s.id,0),lockToPointer:!!s.locktopointer||(oe(s.flags,0)&1)!==0,offset:Ce(s.offset),x:0,y:0,z:0})),this.pointer=null,this._followParent=null,this._followMode=null,this._followOffset=[0,0,0],this.ropeRenderer=null,this._seq=0,this._ropeOrder=[],this._ov={},this._applyOverride(),this.startTime=Math.max(0,Math.min(30,oe(this.model.starttime,0))),this._warmed=!1,this._compile()}reapplyOverride(){this._applyOverride()}setOverrideValue(e,n){const r=Number(n);Number.isFinite(r)&&(e==="alpha"?this.opacityMul=r:e==="count"?this._ov.countMul=r:e==="size"?this._ov.size=r:e==="rate"?this._ov.rateMul=r:e==="speed"?this._ov.speed=r:e==="lifetime"?this.lifetimeMul=r:e==="brightness"?this._ov.brightness=r:this._ov[e]=r)}_applyOverride(){this._ov={},this.opacityMul=1,this.lifetimeMul=1,this.maxCount=Math.max(1,Math.min(2e4,oe(this.model.maxcount,100)));const e=this.override||{};for(const n of Object.keys(e)){if(n==="id")continue;const r=e[n],i=r&&typeof r=="object"&&"value"in r?r.value:r;if(n==="count"){const s=oe(this.model.maxcount,100),a=Number(i),o=Number.isFinite(a)?a:1;this.maxCount=Math.max(1,Math.min(2e4,Math.round(s*o))),this._ov.countMul=o}else if(n==="alpha")this.opacityMul=Number(i),Number.isFinite(this.opacityMul)||(this.opacityMul=1);else if(n==="color"||n==="colorn"){const s=Ce(i);this._ov.color=n==="colorn"?s:[s[0]/255,s[1]/255,s[2]/255]}else n==="size"?this._ov.size=Number(i)||1:n==="rate"?(this._ov.rateMul=Number(i),Number.isFinite(this._ov.rateMul)||(this._ov.rateMul=1)):n==="speed"?this._ov.speed=Number(i)||1:n==="lifetime"?this.lifetimeMul=Number(i)||1:n==="brightness"?this._ov.brightness=Number(i)||1:this._ov[n]=i}this.pool=[];for(let n=0;n<this.maxCount;n++)this.pool.push(new xy)}_compile(){const e=this.model;this.emitters=(e.emitter||[]).map(c=>({kind:c.name==="boxrandom"?"box":"sphere",origin:Ce(c.origin),directions:Ce(c.directions,[1,1,1]),distanceMin:gd(c.distancemin),distanceMax:gd(c.distancemax),sign:c.sign?Ce(c.sign):null,rate:oe(c.rate,0),audioDriven:c.audioprocessingmode!==void 0,audioBounds:Ce(c.audioprocessingbounds,[0,1]),fill:c.rate===void 0&&c.instantaneous===void 0&&c.audioprocessingmode===void 0,instantaneous:oe(c.instantaneous,0),speedMin:oe(c.speedmin,0),speedMax:oe(c.speedmax,0),controlPoint:c.controlpoint!==void 0&&c.controlpoint!==null?oe(c.controlpoint,0):0,_burst:!1}));const n=e.initializer||[];this.init={life:null,size:null,color:null,alpha:null,velocity:null,rotation:null,angularVelocity:null,turbulentVelocity:null,mapAround:null};for(const c of n)switch(c.name){case"lifetimerandom":this.init.life={min:oe(c.min,1),max:oe(c.max,1),exp:oe(c.exponent,1)};break;case"sizerandom":this.init.size={min:oe(c.min,1),max:oe(c.max,1),exp:oe(c.exponent,1)};break;case"colorrandom":this.init.color={min:Ce(c.min,[255,255,255]),max:Ce(c.max,[255,255,255])};break;case"alpharandom":this.init.alpha={min:oe(c.min,1),max:oe(c.max,1)};break;case"velocityrandom":this.init.velocity={min:Ce(c.min),max:Ce(c.max)};break;case"rotationrandom":this.init.rotation={min:Ce(c.min),max:Ce(c.max,[0,0,0]),exp:oe(c.exponent,1)};break;case"angularvelocityrandom":this.init.angularVelocity={min:Ce(c.min),max:Ce(c.max),exp:oe(c.exponent,1)};break;case"mapsequencearoundcontrolpoint":this.init.mapAround={count:Math.max(1,oe(c.count,1)),bounds:Ce(c.bounds,[0,1]),speedMin:Ce(c.speedmin),speedMax:Ce(c.speedmax,[0,0,0]),cp:oe(c.controlpoint,0)},this._mapAroundSeq=0;break;case"turbulentvelocityrandom":this.init.turbulentVelocity={scale:oe(c.scale,.1),offset:oe(c.offset,0),speedMin:oe(c.speedmin,0),speedMax:oe(c.speedmax,0),phaseMax:oe(c.phasemax,0),timeScale:oe(c.timescale,0),audioMode:oe(c.audioprocessingmode,0),audioBounds:Ce(c.audioprocessingbounds,[0,1])};break}const r=e.operator||[];this.ops={movement:null,angularMovement:null,alphaFade:null,alphaChange:null,sizeChange:null,colorChange:null,turbulence:[],oscAlpha:null,oscSize:null,oscPos:null,attract:[],vortex:[],remap:[]};for(const c of r)switch(c.name){case"movement":this.ops.movement={gravity:Ce(c.gravity),drag:oe(c.drag,0)};break;case"angularmovement":this.ops.angularMovement={force:Ce(c.force),drag:oe(c.drag,0)};break;case"alphafade":this.ops.alphaFade={fadeIn:oe(c.fadeintime,.1),fadeOut:oe(c.fadeouttime,.9)};break;case"alphachange":this.ops.alphaChange={startTime:oe(c.starttime,0),endTime:oe(c.endtime,1),startValue:oe(c.startvalue,1),endValue:oe(c.endvalue,0)};break;case"sizechange":this.ops.sizeChange={startTime:oe(c.starttime,0),endTime:oe(c.endtime,1),startValue:oe(c.startvalue,1),endValue:oe(c.endvalue,1)};break;case"colorchange":this.ops.colorChange={startTime:oe(c.starttime,0),endTime:oe(c.endtime,1),startValue:c.startvalue!==void 0?Ce(c.startvalue):null,endValue:Ce(c.endvalue,[1,1,1])};break;case"turbulence":this.ops.turbulence.push({scale:oe(c.scale,.01),speedMin:oe(c.speedmin,0),speedMax:oe(c.speedmax,0),timeScale:oe(c.timescale,1),phaseMin:oe(c.phasemin,0),phaseMax:oe(c.phasemax,0),mask:c.mask!==void 0?Ce(c.mask,[1,1,1]):[1,1,1]});break;case"oscillatealpha":this.ops.oscAlpha={freqMin:oe(c.frequencymin,oe(c.frequencymax,1)),freqMax:oe(c.frequencymax,1),scaleMin:oe(c.scalemin,0),scaleMax:oe(c.scalemax,1),phaseMax:oe(c.phasemax,nn)};break;case"oscillatesize":this.ops.oscSize={freqMin:oe(c.frequencymin,oe(c.frequencymax,1)),freqMax:oe(c.frequencymax,oe(c.frequencymin,1)),scaleMin:oe(c.scalemin,1),scaleMax:oe(c.scalemax,1),phaseMax:oe(c.phasemax,nn)};break;case"oscillateposition":this.ops.oscPos={freqMin:oe(c.frequencymin,oe(c.frequencymax,.5)),freqMax:oe(c.frequencymax,.5),scaleMin:oe(c.scalemin,0),scaleMax:oe(c.scalemax,1),phaseMin:oe(c.phasemin,0),phaseMax:oe(c.phasemax,nn),mask:c.mask!==void 0?Ce(c.mask,[1,1,0]):[1,1,0]};break;case"controlpointattract":this.ops.attract.push({cp:oe(c.controlpoint,0),origin:Ce(c.origin),scale:oe(c.scale,0),threshold:oe(c.threshold,0)});break;case"vortex":this.ops.vortex.push({axis:Ce(c.axis,[0,0,1]),offset:Ce(c.offset),distanceInner:oe(c.distanceinner,0),distanceOuter:oe(c.distanceouter,0),speedInner:oe(c.speedinner,0),speedOuter:oe(c.speedouter,0),cp:c.controlpoint!==void 0&&c.controlpoint!==null?oe(c.controlpoint,0):0,audioMode:oe(c.audioprocessingmode,0),audioBounds:Ce(c.audioprocessingbounds,[0,1])});break;case"remapvalue":this.ops.remap.push({output:c.output||"velocity",rangeMin:Ce(c.outputrangemin),rangeMax:Ce(c.outputrangemax),fn:c.transformfunction||"simplexnoise",inputScale:oe(c.transforminputscale,1)});break}const i=this.model.renderer,s=i==null,a=Array.isArray(i)?i:i?[i]:[];this.renderers=a.map(c=>{const u=c&&c.name||"sprite";return{kind:u,length:oe(c&&c.length,u==="spritetrail"?.1:u==="ropetrail"?.2:0),maxLength:oe(c&&c.maxlength,0),minLength:oe(c&&c.minlength,0),subdivision:oe(c&&c.subdivision,1),segments:oe(c&&c.segments,0),orientation:c&&c.orientation||null}}),s&&!this.renderers.length&&(this.renderers=[{kind:"sprite",length:0,maxLength:0,minLength:0,subdivision:1,segments:0,orientation:null}]);const o=this.renderers.find(c=>c.kind==="spritetrail"||c.kind==="ropetrail");if(this.trailCfg=o||null,this.trailSegments=1,this.trailDuration=0,this.trailSampleDt=0,o&&o.kind==="ropetrail"){const c=vd(o);this.trailSegments=c,this.trailDuration=kd(o),this.trailSampleDt=this.trailDuration/Math.max(1,c-1);for(const u of this.pool)u.trail=new Float32Array(c*3),u.trailClock=0}this.ropeRenderer=this.renderers.find(c=>c.kind==="rope")||null}setModel(e){this.model=e,this._compile()}setMaterial(e){this.material=e;const n=e&&e.passes&&e.passes[0];this.blend=n&&n.blending||"translucent",this.refract=yd(e);const r=n&&n.constantshadervalues,i=r&&r.ui_editor_properties_refract_amount,s=Number(i);this.refractAmount=Number.isFinite(s)?Math.min(.35,Math.max(0,s)):.04}setNormalTexture(e){this.normalTex=e||null}setTexture(e){this.texture=e,this._ready=!!e;const n=e&&e.frames,r=Array.isArray(n)?n:n&&n.list&&n.list.length?n.list:null,i=e&&e.width||r&&(n&&n.atlasWidth||r.atlasWidth)||0,s=e&&e.height||r&&(n&&n.atlasHeight||r.atlasHeight)||0;r&&i>0&&s>0?(this.texFrames=r.map(u=>({ou:u.x/i,ov:u.y/s,su:u.width/i,sv:u.height/s})),this.frameCount=this.texFrames.length):(this.texFrames=null,this.frameCount=this.sequenceMul*this.sequenceMul);let a=1,o=1;this.texFrames&&r?(a=r[0].width||1,o=r[0].height||1):e&&e.width>0&&e.height>0&&(a=e.width,o=e.height);const c=Math.max(a,o)||1;this.texAspectX=a/c,this.texAspectY=o/c,this._frameData=void 0}setVisible(e){this.visible=e}syncLayerTransform(){const e=this.layer,n=e&&e.origin?e.origin:[0,0,0],r=e&&e.scale?e.scale:[1,1,1],i=e&&e.angles?e.angles:[0,0,0];this.originX=n[0]||0,this.originY=n[1]||0,this.originZ=n[2]||0,this.scaleX=r[0]===0?1:r[0],this.scaleY=r[1]===0?1:r[1],this.angleZ=(i[2]||0)*Math.PI/180;const s=Math.abs(this.scaleX),a=Math.abs(this.scaleY);this.sysScale=Math.min(s,a)||1,this.spriteStretchX=s/this.sysScale,this.spriteStretchY=a/this.sysScale}setPointer(e,n){const r=e-this.originX,i=n-this.originY,s=Math.cos(-this.angleZ),a=Math.sin(-this.angleZ);this.pointer={x:(r*s-i*a)/(this.scaleX||1),y:(r*a+i*s)/(this.scaleY||1)}}attachFollow(e,n,r){this._followParent=e||null,this._followMode=n==="particle"||n==="origin"?n:null;const i=r||[0,0,0];this._followOffset=[i[0]||0,i[1]||0,i[2]||0],this._syncFollow()}leaderParticle(){const e=this.pool;for(let n=0;n<e.length;n++)if(e[n].alive)return e[n];return null}localToWorld(e,n){const r=e*this.scaleX,i=n*this.scaleY,s=Math.cos(this.angleZ),a=Math.sin(this.angleZ);return[this.originX+r*s-i*a,this.originY+r*a+i*s]}_syncFollow(){const e=this._followParent,n=this._followMode;if(!e||!n)return;const r=this._followOffset;if(n==="particle"){const i=e.leaderParticle();if(!i)return;const s=e.localToWorld(i.x+r[0],i.y+r[1]);this.originX=s[0],this.originY=s[1]}else{const i=e.localToWorld(r[0],r[1]);this.originX=i[0],this.originY=i[1]}}spawn(e){const n=this.pool,r=n.length;let i=null,s=this._cursor||0;for(let f=0;f<r;f++){const d=n[(s+f)%r];if(!d.alive){i=d,this._cursor=(s+f+1)%r;break}}if(!i)return;i.alive=!0,i.age=0,i.seed=Math.random(),i.rot=0,i.rotVel=0,i.vx=i.vy=i.vz=0,i.frame=0,i.seq=this._seq++;const a=e.origin;if(e.kind==="box"){const f=e.distanceMax||[0,0,0],d=e.distanceMin;i.x=a[0]+Je(-f[0],f[0])+(d?d[0]:0),i.y=a[1]+Je(-f[1],f[1])+(d?d[1]:0),i.z=a[2]+Je(-f[2],f[2])+(d?d[2]:0)}else{const f=e.directions,d=e.distanceMin?e.distanceMin[0]:0,h=e.distanceMax?e.distanceMax[0]:0,p=Math.random()*2-1,m=Math.random()*nn,g=Math.sqrt(Math.max(0,1-p*p));let w=g*Math.cos(m),y=g*Math.sin(m),b=p;e.sign&&(e.sign[0]&&(w=Math.abs(w)*Math.sign(e.sign[0])),e.sign[1]&&(y=Math.abs(y)*Math.sign(e.sign[1])),e.sign[2]&&(b=Math.abs(b)*Math.sign(e.sign[2])));const v=Je(d,h);if(i.x=a[0]+w*v*f[0],i.y=a[1]+y*v*f[1],i.z=a[2]+b*v*f[2],e.speedMax||e.speedMin){const k=Je(e.speedMin,e.speedMax);i.vx+=w*k,i.vy+=y*k,i.vz+=b*k}}{const f=this._cpPos(e.controlPoint);if(f)i.x+=f[0],i.y+=f[1],i.z+=f[2];else{const d=this.controlPoints.find(h=>h.id===e.controlPoint);if(d&&d.lockToPointer){i.alive=!1;return}}}if(this.init.mapAround){const f=this.init.mapAround,d=this._cpPos(f.cp);if(d){const h=f.count,p=this._mapAroundSeq++,m=h>0?p%h/h:0,w=(f.bounds[0]+(f.bounds[1]-f.bounds[0])*m)*nn,y=e.distanceMin?e.distanceMin[0]:0,b=e.distanceMax?e.distanceMax[0]:0,v=b>0?b:y;i.x=d[0]+Math.cos(w)*v,i.y=d[1]+Math.sin(w)*v,i.z=d[2];const k=Math.random();i.vx+=f.speedMin[0]+(f.speedMax[0]-f.speedMin[0])*k,i.vy+=f.speedMin[1]+(f.speedMax[1]-f.speedMin[1])*k,i.vz+=f.speedMin[2]+(f.speedMax[2]-f.speedMin[2])*k}}const o=this.init,c=this._ov.speed||1,u=this._ov.size||1;if(i.life=o.life?Math.max(.001,pd(o.life.min,o.life.max,o.life.exp)*this.lifetimeMul):1,i.baseSize=o.size?pd(o.size.min,o.size.max,o.size.exp)*u:u,i.size=i.baseSize,o.color){const f=o.color.min,d=o.color.max,h=Math.random();i.baseR=(f[0]+(d[0]-f[0])*h)/255,i.baseG=(f[1]+(d[1]-f[1])*h)/255,i.baseB=(f[2]+(d[2]-f[2])*h)/255}else i.baseR=i.baseG=i.baseB=1;if(this._ov.color&&(i.baseR=this._ov.color[0],i.baseG=this._ov.color[1],i.baseB=this._ov.color[2]),i.r=i.baseR,i.g=i.baseG,i.b=i.baseB,i.baseAlpha=(o.alpha?Je(o.alpha.min,o.alpha.max):1)*this.opacityMul,i.alpha=i.baseAlpha,o.velocity&&(i.vx+=Je(o.velocity.min[0],o.velocity.max[0])*c,i.vy+=Je(o.velocity.min[1],o.velocity.max[1])*c,i.vz+=Je(o.velocity.min[2],o.velocity.max[2])*c),o.turbulentVelocity){const f=o.turbulentVelocity,d=f.audioMode?Ac(f.audioBounds,this._audioLevel||0):1,h=Je(f.speedMin,f.speedMax)*c*d,p=this.simTime*(f.timeScale||0),m=Tc(i.x*f.scale+f.offset,i.y*f.scale+f.offset,p+i.seed*(f.phaseMax||0),3);i.vx+=m[0]*h,i.vy+=m[1]*h,i.vz+=m[2]*h}o.rotation&&(i.rot=Je(o.rotation.min[2],o.rotation.max[2])),o.angularVelocity&&(i.rotVel=Je(o.angularVelocity.min[2],o.angularVelocity.max[2]));const l=this.ops;if(l.oscPos&&(i.oscFreq=Je(l.oscPos.freqMin,l.oscPos.freqMax),i.oscAmp=Je(l.oscPos.scaleMin,l.oscPos.scaleMax),i.oscPhase=Je(l.oscPos.phaseMin,l.oscPos.phaseMax)+i.seed*nn),l.oscAlpha&&(i.oscAFreq=Je(l.oscAlpha.freqMin,l.oscAlpha.freqMax),i.oscAPhase=Math.random()*(l.oscAlpha.phaseMax||nn)),l.oscSize&&(i.oscSFreq=Je(l.oscSize.freqMin,l.oscSize.freqMax),i.oscSPhase=Math.random()*(l.oscSize.phaseMax||nn)),l.turbulence.length){const f=l.turbulence[0];i.turbSpeed=Je(f.speedMin,f.speedMax),i.turbPhase=Je(f.phaseMin,f.phaseMax)}if(this.frameCount>1&&(i.frame=this.animationMode==="randomframe"?Math.floor(Math.random()*this.frameCount):0),i.bx=i.x,i.by=i.y,i.bz=i.z,i.trail){for(let f=0;f<i.trail.length;f+=3)i.trail[f]=i.x,i.trail[f+1]=i.y,i.trail[f+2]=i.z;i.trailClock=0}}updateParticle(e,n){if(e.age+=n,e.age>=e.life){e.alive=!1;return}const r=e.age/e.life,i=this.ops;if(i.movement&&(e.vx+=i.movement.gravity[0]*n,e.vy+=i.movement.gravity[1]*n,e.vz+=i.movement.gravity[2]*n,i.movement.drag>0)){const o=Math.exp(-i.movement.drag*n);e.vx*=o,e.vy*=o,e.vz*=o}i.angularMovement&&(e.rotVel+=(i.angularMovement.force[2]||0)*n,i.angularMovement.drag>0&&(e.rotVel*=Math.exp(-i.angularMovement.drag*n)));for(const o of i.turbulence){const c=o.timeScale||1,u=Tc(e.bx*o.scale,e.by*o.scale,this.simTime*o.scale*c+e.turbPhase,3);e.vx+=u[0]*e.turbSpeed*o.mask[0]*n,e.vy+=u[1]*e.turbSpeed*o.mask[1]*n,e.vz+=u[2]*e.turbSpeed*o.mask[2]*n}for(const o of i.attract){const c=this._cpPos(o.cp);if(!c)continue;const u=c[0]+o.origin[0]-e.x,l=c[1]+o.origin[1]-e.y,f=Math.hypot(u,l);if(f<.001||o.threshold>0&&f>o.threshold)continue;const d=o.threshold>0?1-f/o.threshold:1,h=o.scale*d*n/Math.max(1,f);e.vx+=u*h,e.vy+=l*h}for(const o of i.vortex){const c=this._cpPos(o.cp)||[0,0,0],u=e.x-(c[0]+o.offset[0]),l=e.y-(c[1]+o.offset[1]),f=Math.hypot(u,l);if(f<.001)continue;const d=o.distanceOuter-o.distanceInner,h=d>0?Math.min(1,Math.max(0,(f-o.distanceInner)/d)):0,p=o.audioMode?Ac(o.audioBounds,this._audioLevel||0):1,m=o.speedInner+(o.speedOuter-o.speedInner)*h;e.vx+=-l/f*m*n*p,e.vy+=u/f*m*n*p}for(const o of i.remap){const c=o.inputScale||1,u=Tc(e.bx*.01*c,e.by*.01*c,this.simTime*.1,o.fn==="fbmnoise"?4:2);if(o.output==="velocity")for(let l=0;l<3;l++){const f=(u[l]+1)/2,d=o.rangeMin[l]+(o.rangeMax[l]-o.rangeMin[l])*f;l===0?e.vx=d:l===1?e.vy=d:e.vz=d}else if(o.output==="speed"){const l=(u[0]+1)/2,f=o.rangeMin[0]+(o.rangeMax[0]-o.rangeMin[0])*l,d=Math.hypot(e.vx,e.vy)||1;e.vx=e.vx/d*f,e.vy=e.vy/d*f}}if(e.bx+=e.vx*n,e.by+=e.vy*n,e.bz+=e.vz*n,e.rot+=e.rotVel*n,e.x=e.bx,e.y=e.by,e.z=e.bz,i.oscPos){const o=this.simTime*e.oscFreq*nn+e.oscPhase,c=i.oscPos.mask;e.x+=Math.sin(o)*e.oscAmp*c[0],e.y+=Math.cos(o)*e.oscAmp*c[1],e.z+=Math.sin(o*.7)*e.oscAmp*c[2]}let s=e.baseSize;if(i.sizeChange){const o=i.sizeChange,c=o.endTime-o.startTime,u=c>0?Math.min(1,Math.max(0,(r-o.startTime)/c)):r>=o.startTime?1:0;s*=o.startValue+(o.endValue-o.startValue)*u}if(i.oscSize){const o=this.simTime*e.oscSFreq*nn+e.oscSPhase,c=i.oscSize,u=(c.scaleMin+c.scaleMax)/2,l=(c.scaleMax-c.scaleMin)/2;s*=u+Math.sin(o)*l}if(e.size=s,i.colorChange){const o=i.colorChange,c=o.endTime-o.startTime,u=c>0?Math.min(1,Math.max(0,(r-o.startTime)/c)):r>=o.startTime?1:0,l=o.startValue||[e.baseR,e.baseG,e.baseB];e.r=l[0]+(o.endValue[0]-l[0])*u,e.g=l[1]+(o.endValue[1]-l[1])*u,e.b=l[2]+(o.endValue[2]-l[2])*u}let a=e.baseAlpha;if(i.alphaFade){const o=i.alphaFade.fadeIn,c=i.alphaFade.fadeOut;o>0&&r<o&&(a*=r/o),c<1&&r>c&&(a*=Math.max(0,(1-r)/(1-c)))}else i.alphaChange||(r<.1?a*=r/.1:r>.85&&(a*=(1-r)/.15));if(i.alphaChange){const o=i.alphaChange,c=o.endTime-o.startTime,u=c>0?Math.min(1,Math.max(0,(r-o.startTime)/c)):r>=o.startTime?1:0;a*=o.startValue+(o.endValue-o.startValue)*u}if(i.oscAlpha){const o=this.simTime*e.oscAFreq*nn+e.oscAPhase,c=i.oscAlpha,u=(c.scaleMin+c.scaleMax)/2,l=(c.scaleMax-c.scaleMin)/2;a*=u+Math.sin(o)*l}if(e.alpha=Math.max(0,a),this.frameCount>1&&this.animationMode!=="randomframe"&&(e.frame=Math.min(this.frameCount-1,Math.floor(r*this.frameCount))),e.trail){const o=e.trail,c=this.trailSampleDt;if(c>0){e.trailClock=(e.trailClock||0)+n;let u=0;const l=this.trailSegments||8;for(;e.trailClock>=c&&u<l;){e.trailClock-=c,u++;for(let f=o.length-3;f>=3;f-=3)o[f]=o[f-3],o[f+1]=o[f-2],o[f+2]=o[f-1]}}o[0]=e.x,o[1]=e.y,o[2]=e.z}}_cpPos(e){const n=this.controlPoints.find(r=>r.id===e);return n?n.lockToPointer?this.pointer?[this.pointer.x+n.offset[0],this.pointer.y+n.offset[1],n.offset[2]]:null:n.offset:null}advance(e,n){if(!(this.paused||!this.visible)){if(this._syncFollow(),!this._warmed&&(this._warmed=!0,this.startTime>0)){const r=.03333333333333333,i=Math.min(900,Math.round(this.startTime/r));for(let s=0;s<i;s++)this._step(r)}this._step(e,n)}}_step(e,n){this.simTime+=e;const r=n&&Number.isFinite(n.level)?Math.max(0,Math.min(1,n.level)):0;this._audioLevel=r;for(const s of this.emitters){if(s.instantaneous>0&&!s._burst){s._burst=!0;for(let c=0;c<Math.min(s.instantaneous,this.maxCount);c++)this.spawn(s)}if(s.fill){const u=Math.min(this.maxCount,2048);let l=0;for(let d=0;d<this.pool.length;d++)this.pool[d].alive&&l++;let f=Math.min(u-l,512);for(;f-- >0;)this.spawn(s);continue}if(s.audioDriven){const c=Ac(s.audioBounds,r);if(s.rate>0){const u=s.rate*c*(this._ov.rateMul!==void 0?this._ov.rateMul:1)*(this._ov.countMul!==void 0?this._ov.countMul:1);if(!(u>0))continue;s._accum=(s._accum||0)+u*e;let l=Math.floor(s._accum);if(l>0){s._accum-=l,l>this.maxCount&&(l=this.maxCount);for(let f=0;f<l;f++)this.spawn(s)}}else{const l=Math.round(Math.min(this.maxCount,2048)*c);let f=0;for(let h=0;h<this.pool.length;h++)this.pool[h].alive&&f++;let d=Math.min(l-f,256);for(;d-- >0;)this.spawn(s)}continue}const a=s.rate*(this._ov.rateMul!==void 0?this._ov.rateMul:1)*(this._ov.countMul!==void 0?this._ov.countMul:1);if(!(a>0))continue;s._accum=(s._accum||0)+a*e;let o=Math.floor(s._accum);if(o>0){s._accum-=o,o>this.maxCount&&(o=this.maxCount);for(let c=0;c<o;c++)this.spawn(s)}}const i=this.pool;for(let s=0;s<i.length;s++)i[s].alive&&this.updateParticle(i[s],e)}render(e,n,r,i,s){if(!this._ready||!this.visible||!this.renderers.length)return;const a=this.gl;this._prog||this._buildProgram(a);const o=this.trailCfg&&this.trailCfg.kind==="ropetrail"?this.trailCfg:null,c=this.trailCfg&&this.trailCfg.kind==="spritetrail"?this.trailCfg:null,u=this.ropeRenderer,l=wd(this.trailCfg,this.trailSegments),f=14,d=this.pool;let h=null;if(u){h=this._ropeOrder,h.length=0;for(let Y=0;Y<d.length;Y++)d[Y].alive&&h.push(d[Y]);h.sort((Y,J)=>Y.seq-J.seq)}let p=0;if(h)p=h.length;else for(let Y=0;Y<d.length;Y++)d[Y].alive&&p++;if(p===0||u&&p<2)return;const m=u?p-1:p*l,g=m*f;(!this._data||this._data.length<g)&&(this._data=new Float32Array(Math.max(g,1024)));const w=this._data;let y=0;const b=this._ov.brightness||1,v=this.sysScale,k=this.spriteStretchX*(this.texAspectX||1),A=this.spriteStretchY*(this.texAspectY||1),T=Math.cos(this.angleZ),S=Math.sin(this.angleZ),P=this.originX,M=this.originY,B=this.scaleX,N=this.scaleY,U=(Y,J)=>{const ne=Y*B,fe=J*N;return[P+ne*T-fe*S,s-(M+ne*S+fe*T)]};if(u)for(let Y=0;Y+1<p;Y++){const J=h[Y],ne=h[Y+1],fe=U(J.x,J.y),Ne=U(ne.x,ne.y),Ze=Ne[0]-fe[0],je=Ne[1]-fe[1],Fe=Math.hypot(Ze,je),Le=(Math.abs(J.size)+Math.abs(ne.size))*.5*v;Le>0&&(w[y++]=(fe[0]+Ne[0])*.5,w[y++]=(fe[1]+Ne[1])*.5,w[y++]=0,w[y++]=Le,w[y++]=Math.atan2(-Ze,je),w[y++]=(J.r+ne.r)*.5*b,w[y++]=(J.g+ne.g)*.5*b,w[y++]=(J.b+ne.b)*.5*b,w[y++]=(J.alpha+ne.alpha)*.5,w[y++]=1,w[y++]=Fe/Le,w[y++]=0,w[y++]=Pc(J),w[y++]=Pc(ne))}for(let Y=0;Y<d.length&&!u;Y++){const J=d[Y];if(J.alive)for(let ne=0;ne<l;ne++){let fe=J.x,Ne=J.y,Ze=1,je=1,Fe=J.rot,Le=k,Pt=A,Xe,Dt;if(o&&J.trail){fe=J.trail[ne*3],Ne=J.trail[ne*3+1];const Oe=l>1?ne/(l-1):0;Ze=1-Oe,je=1-Oe*.55;let qe=0,ze=0;ne+1<l?(qe=J.trail[ne*3]-J.trail[(ne+1)*3],ze=J.trail[ne*3+1]-J.trail[(ne+1)*3+1]):ne>0?(qe=J.trail[(ne-1)*3]-J.trail[ne*3],ze=J.trail[(ne-1)*3+1]-J.trail[ne*3+1]):(qe=J.vx,ze=J.vy);const st=U(fe,Ne),ve=U(fe-qe,Ne-ze),vn=st[0]-ve[0],ki=st[1]-ve[1],an=Math.hypot(vn,ki),_t=Math.max(.001,Math.abs(J.size)*v*je);an>.001?(Fe=Sc(vn,ki),Xe=(st[0]+ve[0])*.5,Dt=(st[1]+ve[1])*.5,Pt=Math.max(A,an/_t)):(Xe=st[0],Dt=st[1])}else{const Oe=U(fe,Ne);Xe=Oe[0],Dt=Oe[1]}if(c){const Oe=U(J.x,J.y);Xe=Oe[0],Dt=Oe[1];const qe=U(J.x+J.vx,J.y+J.vy);Fe=Sc(qe[0]-Oe[0],qe[1]-Oe[1]);const ze=bd(Math.hypot(J.vx,J.vy),c.length,c.minLength,c.maxLength);Pt=A*ze}w[y++]=Xe,w[y++]=Dt,w[y++]=0,w[y++]=Math.abs(J.size)*v*je,w[y++]=Fe,w[y++]=J.r*b,w[y++]=J.g*b,w[y++]=J.b*b,w[y++]=J.alpha*Ze,w[y++]=Le,w[y++]=Pt,w[y++]=J.frame,w[y++]=0,w[y++]=1}}const q=this._prog;a.useProgram(q.prog),a.bindVertexArray(this._vao),a.bindBuffer(a.ARRAY_BUFFER,this._vbuf),a.bufferData(a.ARRAY_BUFFER,w.subarray(0,y),a.DYNAMIC_DRAW),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,this.texture.glTex),a.uniform1i(q.uniTex,0),a.uniformMatrix4fv(q.uniMvp,!1,e);const H=this.refract&&this.normalTex&&this.normalTex.glTex;if(q.uniRefract&&a.uniform1i(q.uniRefract,H?1:0),H){a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,this.normalTex.glTex),q.uniNormal&&a.uniform1i(q.uniNormal,1);const Y=this.blend!=="additive";if(q.uniSampleScene&&a.uniform1i(q.uniSampleScene,Y?1:0),Y){const J=a.drawingBufferWidth||n,ne=a.drawingBufferHeight||r;a.bindFramebuffer(a.FRAMEBUFFER,null),a.activeTexture(a.TEXTURE2),this._sceneTex?a.bindTexture(a.TEXTURE_2D,this._sceneTex):(this._sceneTex=a.createTexture(),a.bindTexture(a.TEXTURE_2D,this._sceneTex),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MIN_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_MAG_FILTER,a.LINEAR),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_S,a.CLAMP_TO_EDGE),a.texParameteri(a.TEXTURE_2D,a.TEXTURE_WRAP_T,a.CLAMP_TO_EDGE)),a.copyTexImage2D(a.TEXTURE_2D,0,a.RGB8,0,0,J,ne,0),q.uniScene&&a.uniform1i(q.uniScene,2),q.uniResolution&&a.uniform2f(q.uniResolution,J,ne),q.uniRefractScale&&a.uniform1f(q.uniRefractScale,this.refractAmount||.04)}else a.activeTexture(a.TEXTURE2),a.bindTexture(a.TEXTURE_2D,this.texture.glTex),q.uniScene&&a.uniform1i(q.uniScene,2)}else q.uniNormal&&(a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,this.texture.glTex),a.uniform1i(q.uniNormal,1),a.activeTexture(a.TEXTURE2),a.bindTexture(a.TEXTURE_2D,this.texture.glTex),q.uniScene&&a.uniform1i(q.uniScene,2),q.uniSampleScene&&a.uniform1i(q.uniSampleScene,0));const G=this._frameUniformData();G?(a.uniform1i(q.uniFrameCount,G.count),a.uniform4fv(q.uniFrames,G.arr)):a.uniform1i(q.uniFrameCount,0),a.enable(a.BLEND),this.blend==="additive"?a.blendFunc(a.SRC_ALPHA,a.ONE):a.blendFunc(a.SRC_ALPHA,a.ONE_MINUS_SRC_ALPHA),a.depthMask(!1),a.drawArraysInstanced(a.TRIANGLE_STRIP,0,4,m),a.depthMask(!0),a.disable(a.BLEND),a.bindVertexArray(null)}_buildProgram(e){const n=ky(e);this._quadBuf=n.quadBuf,this._vbuf=n.vbuf,this._vao=n.vao,this._prog=n.prog}_frameUniformData(){if(this._frameData!==void 0)return this._frameData;let e=this.texFrames;if(!e&&this.sequenceMul>1){const i=this.sequenceMul;e=[];for(let s=0;s<i;s++)for(let a=0;a<i;a++)e.push({ou:a/i,ov:s/i,su:1/i,sv:1/i})}if(!e||e.length===0)return this._frameData=null,null;const n=Math.min(e.length,128),r=new Float32Array(n*4);for(let i=0;i<n;i++)r[i*4]=e[i].ou,r[i*4+1]=e[i].ov,r[i*4+2]=e[i].su,r[i*4+3]=e[i].sv;return this._frameData={count:n,arr:r},this._frameData}liveCount(){let e=0;for(const n of this.pool)n.alive&&e++;return e}dispose(){this.paused=!0;const e=this.gl;if(e){try{this._vbuf&&e.deleteBuffer(this._vbuf),this._quadBuf&&e.deleteBuffer(this._quadBuf),this._vao&&e.deleteVertexArray(this._vao),this._prog&&this._prog.prog&&e.deleteProgram(this._prog.prog),this._sceneTex&&e.deleteTexture(this._sceneTex)}catch{}this._prog=null,this._vbuf=null,this._quadBuf=null,this._vao=null,this._data=null,this._sceneTex=null}}}const Sy=Object.freeze(Object.defineProperty({__proto__:null,ParticleSystem:Ty,particleInstanceSegs:wd,particlePassRefract:yd,rgbaIsBlankWhite:Ay,ropeParticleV:Pc,ropeTrailDuration:kd,ropeTrailHistoryCount:vd,spriteTrailLengthFactor:bd,spriteTrailRotation:Sc},Symbol.toStringTag,{value:"Module"})),as=new Map,_c=new Map;let ga=null;function Py(t,e){const n=String(t);_c.set(n,e),as.delete(n)}function _y(t){ga=typeof t=="function"?t:null}function Ey(){_c.clear(),ga=null,as.clear()}function Cy(){return Object.keys(ds)}function We(t,e,n){t[e]=255,t[e+1]=255,t[e+2]=255,t[e+3]=Math.round(Math.min(1,Math.max(0,n))*255)}function os(t,e){const{width:n,height:r,rgba:i}=t,s=Math.max(2,Math.round(Math.min(n,r)*.04));for(let a=0;a<r;a++)for(let o=0;o<n;o++){const c=Math.min(o,a,n-1-o,r-1-a);if(c>=s)continue;const u=c/s,l=(a*n+o)*4+3;i[l]=Math.round(i[l]*u)}if(e>0){let a=0;const o=n*r;for(let u=0;u<o;u++)a+=i[u*4+3];const c=a/o/255;if(c>e&&c>0){const u=e/c;for(let l=0;l<o;l++)i[l*4+3]=Math.round(i[l*4+3]*u)}}return t}function cs(t){let e=t>>>0;return function(){e|=0,e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}const wi=t=>t*t*(3-2*t),Ad=t=>t*t*t*(t*(t*6-15)+10),Ec=(t,e,n)=>t+(e-t)*n,he=(t,e)=>Math.exp(-(t*t)/(e*e));function fr(t,e,n,r){const i=Math.min(t,e,n-1-t,n-1-e);return i>=r?1:i/r}function ls(t,e){const n=new Uint8Array(t*t*4),r=t/2;for(let i=0;i<t;i++)for(let s=0;s<t;s++){const a=Math.hypot((s+.5-r)/r,(i+.5-r)/r);let o=0;for(let c=0;c<e.length;c++)o+=e[c].w*he(a,e[c].r);We(n,(i*t+s)*4,o)}return{width:t,height:t,rgba:n}}function jn(t,e,n){return ls(t,[e,n])}function dr(t,e,n,r,i){const s=new Uint8Array(t*t*4),a=t/2,o=Math.max(2,Math.round(t*.03));for(let c=0;c<t;c++)for(let u=0;u<t;u++){const l=(u+.5-a)/a,f=(c+.5-a)/a,d=Math.hypot(l,f),h=Math.atan2(f,l),p=Math.pow(.5+.5*Math.cos(e*h),r);let m=he(d,i)+p*he(d,n);m*=fr(u,c,t,o),We(s,(c*t+u)*4,m)}return{width:t,height:t,rgba:s}}function bn(t,e,n,r,i){const a=new Uint8Array(t*e*4);for(let o=0;o<e;o++){const c=o/(e-1),u=r?he(c-.5,.27):wi(Math.min(1,c/.06))*Math.pow(1-c,1.35);for(let l=0;l<t;l++){const f=l/(t-1)*2-1,d=he(f,n);We(a,(o*t+l)*4,d*d*d*u*.55)}}return{width:t,height:e,rgba:a}}const ya=4,Cc=128,Ic=512;function xd(t,e,n,r,i){const s=i===void 0?.85:i,a=new Uint8Array(t*e*4),o=e/ya,c=cs(335009),u=Math.tan(n*Math.PI/180),l=t/2;for(let f=0;f<ya;f++){const d=s*(.8+c()*.35),h=r*(.85+c()*.5),p=(c()-.5)*t*.12;for(let m=0;m<o;m++){const g=m/(o-1),w=l+p+(o-1)*u/2-(o-1)*u*g,y=he(g-.5,.27);for(let b=0;b<t;b++){const v=Math.abs(b+.5-w),A=Math.exp(-(v*v)/(h*h))*y*d;A<.004||We(a,((f*o+m)*t+b)*4,A)}}}return{width:t,height:e,rgba:a}}function Iy(t){if(t==="particle/nature/rain1"||t==="particle/nature/rain2"){const e=[],n=Ic/ya;for(let r=0;r<ya;r++)e.push({x:0,y:r*n,width:Cc,height:n});return e}if(/^particle\/nature\/leaves\d*$/.test(t)){const e=[];for(let n=0;n<3;n++)for(let r=0;r<3;r++)e.push({x:r*fs,y:n*fs,width:fs,height:fs});return e}return null}function Mc(t,e,n){const r=new Uint8Array(t*t*4),i=t/2;for(let s=0;s<t;s++)for(let a=0;a<t;a++){const o=Math.hypot((a-i)/i,(s-i)/i);We(r,(s*t+a)*4,he(o-e,n*.6)*Math.max(0,1-o))}return{width:t,height:t,rgba:r}}function Td(t,e){const n={1:{r:.78,t:.048,inner:.06,hi:[[-.28,-.32,.22,.9],[.32,.36,.12,.28]]},2:{r:.7,t:.07,inner:.14,hi:[[-.2,-.28,.3,.72],[.38,.2,.14,.4]]},3:{r:.84,t:.036,inner:.04,hi:[[-.34,-.18,.16,.95],[.2,.42,.1,.22],[.04,-.08,.07,.18]]}},r=n[e]||n[1],i=new Uint8Array(t*t*4),s=t/2;for(let a=0;a<t;a++)for(let o=0;o<t;o++){const c=(o+.5-s)/s,u=(a+.5-s)/s,l=Math.hypot(c,u);let f=he(l-r.r,r.t*.85)*Math.max(0,1.05-l);l<r.r&&(f+=r.inner*he(l,.5));for(let d=0;d<r.hi.length;d++){const h=r.hi[d];f+=h[3]*he(Math.hypot(c-h[0],u-h[1]),h[2])}We(i,(a*t+o)*4,f)}return os({width:t,height:t,rgba:i},.05)}function us(t,e){const n=t>>1,r=new Uint8Array(t*t*4),i=e===1?[1,2,1,3]:e===2?[2,1,2,3]:[3,1,2,3];for(let s=0;s<2;s++)for(let a=0;a<2;a++){const o=Td(n,i[s*2+a]);for(let c=0;c<n;c++){const u=(s*n+c)*t,l=c*n;for(let f=0;f<n;f++){const d=(u+a*n+f)*4,h=(l+f)*4;r[d]=o.rgba[h],r[d+1]=o.rgba[h+1],r[d+2]=o.rgba[h+2],r[d+3]=o.rgba[h+3]}}}return{width:t,height:t,rgba:r}}function Sd(t){const e=new Uint8Array(t*t*4),n=t/2,r=[[.32,0],[1.1,.35],[2.2,-.3],[-.7,.2]];for(let i=0;i<t;i++)for(let s=0;s<t;s++){const a=s>=n?1:0,o=i>=n?1:0,c=o*2+a,u=a*n+n/2,l=o*n+n/2,f=r[c][0],d=r[c][1],h=(s+.5-u)/(n*.4),p=(i+.5-l)/(n*.4),m=Math.cos(f),g=Math.sin(f);let w=h*m+p*g;const y=-h*g+p*m;w+=d*y*.18;const b=1-Math.max(0,y)*.42,v=Math.hypot(w/(.52*b),y/.92);let k=v>=1.12?0:he(v,.48);k=Math.min(1,k+he(w,.07)*he(y,.65)*k*.4),We(e,(i*t+s)*4,k)}return os({width:t,height:t,rgba:e},.11)}const fs=256,yt=fs*3;function bt(t,e){const n={0:{rx:.36,ry:.92,wave:0,folds:0,rgb:[196,66,32]},1:{rx:.48,ry:.86,wave:.05,folds:7,rgb:[188,58,30]},2:{rx:.4,ry:.88,wave:.08,folds:5,rgb:[206,82,36]},3:{rx:.58,ry:.72,wave:0,folds:0,rgb:[214,148,40]},5:{rx:.44,ry:.8,wave:.12,folds:9,rgb:[220,158,48]},6:{rx:.52,ry:.78,wave:.07,folds:4,rgb:[122,150,52]},7:{rx:.5,ry:.9,wave:.16,folds:3,rgb:[96,138,50]},8:{rx:.38,ry:.94,wave:.2,folds:2,rgb:[110,148,56]}},r=n[e]||n[0],i=Math.floor(t/3),s=new Uint8Array(i*3*i*3*4),a=i/2,o=cs(7855+e*131);for(let c=0;c<9;c++){const u=c%3,l=c/3|0,f=c/9*Math.PI*2+(o()-.5)*.7,d=.9+o()*.16,h=.9+o()*.2,p=1+(o()-.5)*.12,m=Math.cos(f),g=Math.sin(f),w=c&1?-1:1;for(let y=0;y<i;y++)for(let b=0;b<i;b++){const v=(b+.5-a)/a*w,k=(y+.5-a)/a,A=(v*m+k*g)/d,T=(-v*g+k*m)/d,S=1-Math.pow(Math.min(1,Math.abs(T)),1.7)*.52,P=Math.atan2(A,T),M=r.wave?1+r.wave*Math.sin(P*r.folds):1,B=Math.hypot(A/(r.rx*M*S),T/r.ry),N=B>=1.08?0:Math.min(1,(1.08-B)/.14);if(N<=0)continue;const U=he(A,.028)*he(T,.72),q=(.8+.2*Math.max(0,1-B))*(1+U*.22)*h,H=((l*i+y)*i*3+u*i+b)*4;s[H]=Math.min(255,Math.round(r.rgb[0]*q*p)),s[H+1]=Math.min(255,Math.round(r.rgb[1]*q)),s[H+2]=Math.min(255,Math.round(r.rgb[2]*q*(2-p))),s[H+3]=Math.round(N*255)}}return os({width:i*3,height:i*3,rgba:s},0)}function rn(t,e){const n=t.width,r=t.height,i=t.rgba,s=e??2.8,a=new Uint8Array(n*r*4),o=(c,u)=>{const l=c<0?0:c>=n?n-1:c,f=u<0?0:u>=r?r-1:u;return i[(f*n+l)*4+3]/255};for(let c=0;c<r;c++)for(let u=0;u<n;u++){const l=(o(u-1,c)-o(u+1,c))*s,f=(o(u,c-1)-o(u,c+1))*s,d=1/Math.hypot(l,f,1),h=(c*n+u)*4;a[h]=Math.round((l*d*.5+.5)*255),a[h+1]=Math.round((f*d*.5+.5)*255),a[h+2]=Math.round((d*.5+.5)*255),a[h+3]=255}return{width:n,height:r,rgba:a}}function Pd(t){const e=new Uint8Array(t*t*4),n=t/2;for(let r=0;r<t;r++)for(let i=0;i<t;i++){const s=(i+.5-n)/n,a=(r+.5-n)/n,o=Math.hypot(s,a),c=o>=1?0:Math.sqrt(Math.max(0,1-o*o)),u=he(o-.62,.11)*.55;We(e,(r*t+i)*4,Math.min(1,c*.85+u))}return{width:t,height:t,rgba:e}}function My(t){const e=new Uint8Array(t*t*4),n=t/2;for(let r=0;r<t;r++)for(let i=0;i<t;i++){const s=(i+.5-n)/n,a=(r+.5-n)/n,o=Math.hypot(s,a),c=Math.atan2(a,s),u=he(o,.38)*(.55+.45*Math.cos(c*3+o*6));We(e,(r*t+i)*4,u)}return{width:t,height:t,rgba:e}}function _d(t){const e=new Uint8Array(t*t*4),n=t/2,r=Math.max(2,Math.round(t*.04));for(let i=0;i<t;i++)for(let s=0;s<t;s++){const a=(s+.5-n)/n,o=(i+.5-n)/n,c=Math.hypot(a,o),u=Math.atan2(o,a),l=wi(Math.max(0,Math.cos(u)*.55+.45)),f=he(c-.68,.07)*l+.35*he(c-.78,.12)*he(u-.9,.55);We(e,(i*t+s)*4,Math.min(1,f)*fr(s,i,t,r))}return{width:t,height:t,rgba:e}}function By(t){if(!t||t.length<16)return!1;const e=t.length/4,n=Math.max(1,e/48|0);let r=0;for(let i=0;i<e;i+=n){const s=i*4;if(t[s]<240||t[s+1]<240||t[s+2]<240)return!1;r++}return r>0}function Ry(t){return!t||!t.rgba?t:By(t.rgba)?rn(t,2.8):t}const Fy={"particle/drop":"particle/drop_normal","particle/water/rain_drops_sheet":"particle/water/rain_drops_sheet_normal","particle/bubbles/bubble1":"particle/bubbles/bubble1normal","particle/bubbles/bubble2":"particle/bubbles/bubble2_normal","particle/sharp_halo":"particle/sharp_halo_normal","particle/misc/wave":"particle/normal_splash","particle/halo":"particle/sharp_halo_normal"};function Dy(t){if(!t)return null;const e=String(t);return/normal/i.test(e)?e:Fy[e]||e+"_normal"}function Ny(t){const e=String(t);return/(^|\/)normal_/.test(e)?null:/_normal$/i.test(e)?e.replace(/_normal$/i,""):/normal$/i.test(e)?e.replace(/normal$/i,""):null}function Ly(t){if(ds[t])return ds[t]();const e=String(t).toLowerCase();return/normal/.test(e)?jn(64,{r:.18,w:1},{r:.4,w:.2}):Dd(t)()}function Ed(t,e,n){const r=cs(n*7919+17);let i=t;const s=[];for(let c=0;c<e;c++){const u=i*i,l=new Float32Array(u*2);for(let f=0;f<u;f++){const d=r()*Math.PI*2;l[f*2]=Math.cos(d),l[f*2+1]=Math.sin(d)}s.push({f:i,g:l,ox:c*7.31,oy:c*3.17}),i*=2}const a=(c,u,l,f,d)=>{const h=c.f,p=(u%h+h)%h,g=((l%h+h)%h*h+p)*2;return c.g[g]*f+c.g[g+1]*d},o=(c,u,l)=>{const f=(u+c.ox)*c.f,d=(l+c.oy)*c.f,h=Math.floor(f),p=Math.floor(d),m=f-h,g=d-p,w=Ad(m),y=Ad(g);return Ec(Ec(a(c,h,p,m,g),a(c,h+1,p,m-1,g),w),Ec(a(c,h,p+1,m,g-1),a(c,h+1,p+1,m-1,g-1),w),y)};return function(u,l,f){const d=f==null?s.length:Math.min(f,s.length);let h=1,p=0,m=0;for(let g=0;g<d;g++)p+=(o(s[g],u,l)*.5+.5)*h,m+=h,h*=.55;return p/m}}function Cd(t,e,n){const{width:r,height:i,rgba:s}=t;if(r===e&&i===n)return t;const a=new Uint8Array(e*n*4);for(let o=0;o<n;o++){const c=(o+.5)/n*i-.5,u=Math.max(0,Math.min(i-1,Math.floor(c))),l=Math.max(0,Math.min(i-1,u+1)),f=c-Math.floor(c);for(let d=0;d<e;d++){const h=(d+.5)/e*r-.5,p=Math.max(0,Math.min(r-1,Math.floor(h))),m=Math.max(0,Math.min(r-1,p+1)),g=h-Math.floor(h),w=s[(u*r+p)*4+3],y=s[(u*r+m)*4+3],b=s[(l*r+p)*4+3],v=s[(l*r+m)*4+3],k=(w*(1-g)+y*g)*(1-f)+(b*(1-g)+v*g)*f;We(a,(o*e+d)*4,k/255)}}return{width:e,height:n,rgba:a}}function hr(t,e,n,r,i,s,a){const o=s===void 0?1:s,c=a===void 0?200:a,u=256,l=Ed(e,n,r),f=new Uint8Array(u*u*4),d=u/2,h=u*u,p=new Float32Array(h);let m=1,g=0;for(let v=0;v<h;v++){const k=v%u,A=v/u|0,T=(k+.5)/u,S=(A+.5)/u,P=l(T+5.2,S+1.3,2)-.5,M=l(T+9.7,S+8.1,2)-.5,B=p[v]=l(T+P*.45,S+M*.45);B<m&&(m=B),B>g&&(g=B)}const w=g-m||1;for(let v=0;v<u;v++)for(let k=0;k<u;k++){const A=(p[v*u+k]-m)/w,T=Math.hypot((k+.5-d)/d,(v+.5-d)/d),S=Math.pow(Math.max(0,1-T),o);let P=Math.max(0,(A-(1-i))/(i||1));P=wi(Math.min(1,P))*S,We(f,(v*u+k)*4,P)}let y=0;for(let v=0;v<h;v++)y=Math.max(y,f[v*4+3]);if(y>0&&y<c){const v=c/y;for(let k=0;k<h;k++)f[k*4+3]=Math.round(Math.min(255,f[k*4+3]*v))}const b={width:u,height:u,rgba:f};return u===t?b:Cd(b,t,t)}function Bc(t,e){const n=t,r=Ed(3,5,e??23),i=new Uint8Array(n*n*4),s=n*n,a=new Float32Array(s);let o=1,c=0;for(let d=0;d<s;d++){const h=d%n,p=d/n|0,m=(h+.5)/n,g=(p+.5)/n,w=r(m+2.1,g+4.7,2)-.5,y=r(m+6.3,g+1.9,2)-.5,b=a[d]=r(m+w*.28,g+y*.55);b<o&&(o=b),b>c&&(c=b)}const u=c-o||1;for(let d=0;d<n;d++)for(let h=0;h<n;h++){const p=(d+.5)/n,m=(h+.5)/n*2-1,g=.1+.52*Math.pow(p,1.25),w=(a[d*n+h]-o)/u,y=he(m/(g||.01),.55)*he(p-.58,.42);let b=wi(Math.min(1,Math.max(0,(w-.18)/.72)))*y;b*=p<.06?p/.06:1,We(i,(d*n+h)*4,b)}let l=0;for(let d=0;d<s;d++)l=Math.max(l,i[d*4+3]);if(l>0&&l<220){const d=220/l;for(let h=0;h<s;h++)i[h*4+3]=Math.round(Math.min(255,i[h*4+3]*d))}const f=os({width:n,height:n,rgba:i},.08);return n===t?f:Cd(f,t,t)}function Rc(t,e,n,r){const i=new Uint8Array(t*e*4),s=t/n,a=e/r;for(let o=0;o<e;o++)for(let c=0;c<t;c++){const u=Math.floor(c/s),l=Math.floor(o/a),f=(c+.5-u*s)/s*2-1,d=(o+.5-l*a)/a*2-1,h=1-Math.max(0,d)*.45,p=Math.hypot(f/(.52*h),d/.8),m=p>=1.12?0:he(p,.48);We(i,(o*t+c)*4,m)}return{width:t,height:e,rgba:i}}function Id(t){const e=new Uint8Array(t*t*4),n=cs(7),r=[];for(let i=0;i<11;i++)r.push({x:.14+n()*.72,y:.14+n()*.72,rx:.025+n()*.03,ry:.018+n()*.024,rot:n()*Math.PI});for(let i=0;i<t;i++)for(let s=0;s<t;s++){const a=(s+.5)/t,o=(i+.5)/t;let c=0;for(const u of r){const l=a-u.x,f=o-u.y,d=Math.cos(u.rot),h=Math.sin(u.rot),p=(l*d+f*h)/u.rx,m=(-l*h+f*d)/u.ry,g=he(Math.hypot(p,m),.55);g>c&&(c=g)}We(e,(i*t+s)*4,c)}return{width:t,height:t,rgba:e}}function ba(t,e){const n=e??19,r=cs(n),i=d=>Math.min(.86,Math.max(.14,d)),s=5+n%4,a=[];let o=i(.5+(r()-.5)*.16);for(let d=0;d<=s;d++){const h=.06+d/s*.86;d>0&&(o=i(o+(r()-.5)*.32)),a.push([o,h])}const c=[];for(let d=0;d<a.length-1;d++)c.push([a[d],a[d+1],1]);const u=1+n%2;for(let d=0;d<u;d++){const h=1+(n+d*3)%Math.max(1,a.length-2),p=a[h],m=[p];let g=p[0],w=p[1];const y=2+n%2;for(let b=0;b<y;b++)g=i(g+(r()-.5)*.36),w=Math.min(.92,w+.1+r()*.08),m.push([g,w]);for(let b=0;b<m.length-1;b++)c.push([m[b],m[b+1],.45+d*.1])}const l=new Uint8Array(t*t*4),f=Math.max(2,Math.round(t*.04));for(let d=0;d<t;d++)for(let h=0;h<t;h++){const p=(h+.5)/t,m=(d+.5)/t;let g=9,w=0;for(const[b,v,k]of c){const A=v[0]-b[0],T=v[1]-b[1],S=A*A+T*T||1e-8,P=Math.max(0,Math.min(1,((p-b[0])*A+(m-b[1])*T)/S)),M=Math.hypot(p-(b[0]+A*P),m-(b[1]+T*P));M/k<g&&(g=M/k,w=k)}const y=.95*he(g,.012)+.3*he(g,.05)*w;We(l,(d*t+h)*4,Math.min(1,y)*fr(h,d,t,f))}return{width:t,height:t,rgba:l}}function Fc(t,e){const n=new Uint8Array(t*e*4);for(let r=0;r<e;r++)for(let i=0;i<t;i++){const s=(i+.5-t/2)/(t/2),a=(r+.5-e/2)/(e/2),o=he(s,.34)*Math.exp(-Math.max(0,-a-.05)*4.2)*(a<.1?1:Math.max(0,1-a*4)),c=Math.hypot(s/.34,(a-.42)/.3),u=c>=1?0:he(c,.5);We(n,(r*t+i)*4,Math.max(o,u))}return{width:t,height:e,rgba:n}}function Oy(t){return jn(t,{r:.1,w:1},{r:.3,w:.16})}function Dc(t,e){const n=new Uint8Array(t*e*4);for(let r=0;r<e;r++){const i=(r+.5)/e,s=wi(Math.min(1,Math.min(i/.08,(1-i)/.08))),a=he(i-.46,.24)*s,o=.5*(1-wi(Math.min(1,Math.max(0,(i-.42)/.5)))*.6);for(let c=0;c<t;c++){const u=(c+.5-t/2)/(t/2);We(n,(r*t+c)*4,he(Math.abs(u)/(o||.01),.5)*a)}}return{width:t,height:e,rgba:n}}function Md(t){const e=new Uint8Array(t*t*4),n=t/2,r=Math.max(2,Math.round(t*.04));for(let i=0;i<t;i++)for(let s=0;s<t;s++){const a=(s+.5-n)/n,o=(i+.5-n)/n,c=he(Math.hypot(a,o),.42),u=he(Math.hypot(a-.34,o),.36),l=Math.max(0,c-u*1.08)*fr(s,i,t,r);We(e,(i*t+s)*4,l)}return{width:t,height:t,rgba:e}}function Bd(t){const e=new Uint8Array(t*t*4),n=t/2,r=Math.max(2,Math.round(t*.04));for(let i=0;i<t;i++)for(let s=0;s<t;s++){const a=(s+.5-n)/n,o=(i+.5-n)/n;let c=he(Math.hypot(a,o),.08);for(let u=0;u<6;u++){const l=u*Math.PI/3,f=Math.cos(l),d=Math.sin(l),h=a*f+o*d,p=-a*d+o*f;if(h<0)continue;const m=Math.max(0,1.02-h/.72);c+=he(p,.028)*he(h,.5)*m,c+=.55*he(p-(h-.28)*.65,.02)*he(h-.28,.12)*m,c+=.55*he(p+(h-.28)*.65,.02)*he(h-.28,.12)*m,c+=.4*he(p-(h-.48)*.7,.016)*he(h-.48,.08)*m,c+=.4*he(p+(h-.48)*.7,.016)*he(h-.48,.08)*m}We(e,(i*t+s)*4,Math.min(1,c)*fr(s,i,t,r))}return{width:t,height:t,rgba:e}}function Rd(t,e){const n=new Uint8Array(t*t*4),r=t/2,i=Math.max(2,Math.round(t*.04)),s=Math.abs(e|0)%3;for(let a=0;a<t;a++)for(let o=0;o<t;o++){const c=(o+.5-r)/r*1.55,u=(a+.5-r)/r*1.55,l=Math.abs(Math.abs(c)+Math.abs(u)-.55);let f=he(l,.016);s===0?(f+=he(c,.012)*he(u,.38),f+=he(u,.012)*he(c,.38)):s===1?(f+=he(c-u,.012)*he(c+u,.36),f+=he(c+u,.012)*he(c-u,.36)):(f+=he(Math.hypot(c,u)-.26,.014),f+=he(c,.012)*he(u,.22)),We(n,(a*t+o)*4,Math.min(1,f)*fr(o,a,t,i))}return os({width:t,height:t,rgba:n},.03)}function Nc(t){let e=0;const n=String(t);for(let r=0;r<n.length;r++)e=e*31+n.charCodeAt(r)|0;return e}function Uy(t){const e=new Uint8Array(t*t*4),n=t/2,r=Math.max(2,Math.round(t*.03)),i=1.6/t;for(let s=0;s<t;s++)for(let a=0;a<t;a++){const o=(a+.5-n)/n,c=(s+.5-n)/n,u=Math.hypot(o,c);let l=he(u,.05)+.3*he(u,.15);l+=.9*he(c,i)*Math.exp(-Math.abs(o)/.3),l+=.9*he(o,i)*Math.exp(-Math.abs(c)/.3),l*=fr(a,s,t,r),We(e,(s*t+a)*4,l)}return{width:t,height:t,rgba:e}}function Fd(t){const e=new Uint8Array(t*t*4),n=t/2,r=Math.max(2,Math.round(t*.03));for(let i=0;i<t;i++)for(let s=0;s<t;s++){const a=(s+.5-n)/n,o=(i+.5-n)/n,c=Math.hypot(a,o),u=he(c,.07)+.85*he(a,.62)*he(o,.045)+.22*he(a,.92)*he(o,.018);We(e,(i*t+s)*4,Math.min(1,u)*fr(s,i,t,r))}return{width:t,height:t,rgba:e}}const ds={"particle/halo_6":()=>jn(256,{r:.14,w:1},{r:.4,w:.17}),"particle/normal_splash":()=>rn(Pd(256),3.2),"particle/drop_normal":()=>rn(Dc(128,512),3.4),"particle/normal_ring_smooth":()=>rn(Mc(256,.55,.12),3.1),"particle/normal_pinch_rotate":()=>rn(My(256),2.8),"particle/water/rain_drops_sheet_normal":()=>rn(Rc(256,512,2,4),3.6),"particle/bubbles/bubble1normal":()=>rn(us(256,1),3.2),"particle/bubbles/bubble2_normal":()=>rn(us(256,2),3.2),"particle/sharp_halo_normal":()=>rn(ls(256,[{r:.035,w:1},{r:.09,w:.45},{r:.22,w:.08}]),3.4),"particle/beam/beam_0":()=>bn(128,512,.46,!0),"particle/beam/beam_1":()=>bn(128,512,.34,!0),"particle/beam/beam_2":()=>bn(128,512,.22,!0),"particle/beam/beam_2_fade":()=>bn(128,512,.24,!1),"particle/light/light_shafts_0":()=>bn(128,512,.42,!0),"particle/light/light_shafts_1":()=>bn(128,512,.3,!0),"particle/light/light_shafts_3":()=>bn(128,512,.26,!0),"particle/light/light_shafts_5":()=>bn(128,512,.23,!0),"particle/light/light_shafts_6":()=>bn(128,512,.2,!0),"particle/nature/rosepetals":()=>Sd(256),"particle/nature/leaves":()=>bt(yt,0),"particle/nature/leaves1":()=>bt(yt,1),"particle/nature/leaves2":()=>bt(yt,2),"particle/nature/leaves3":()=>bt(yt,3),"particle/nature/leaves5":()=>bt(yt,5),"particle/nature/leaves6":()=>bt(yt,6),"particle/nature/leaves7":()=>bt(yt,7),"particle/nature/leaves8":()=>bt(yt,8),"particle/nature/snow":()=>Bd(256),"particle/halo":()=>jn(256,{r:.12,w:1},{r:.3,w:.15}),"particle/halo_1":()=>jn(256,{r:.1,w:1},{r:.3,w:.13}),"particle/halo_2":()=>jn(256,{r:.2,w:.9},{r:.44,w:.2}),"particle/halo_3":()=>ls(256,[{r:.045,w:1},{r:.13,w:.85},{r:.36,w:.15}]),"particle/halo_4":()=>jn(256,{r:.085,w:1},{r:.28,w:.12}),"particle/halo_5":()=>ls(256,[{r:.04,w:1},{r:.11,w:.8},{r:.34,w:.17}]),"particle/sharp_halo":()=>ls(256,[{r:.035,w:1},{r:.09,w:.45},{r:.22,w:.08}]),"particle/chromaticdot":()=>Oy(128),"particle/light/flare_0":()=>dr(256,6,.58,10,.08),"particle/light/flare_1":()=>Uy(512),"particle/light/flare_2":()=>Fd(256),"particle/drop":()=>Dc(128,512),"particle/nature/rain1":()=>xd(Cc,Ic,10,1,.78),"particle/nature/rain2":()=>xd(Cc,Ic,10,1.6,.66),"particle/water/rain_drops_sheet":()=>Rc(256,512,2,4),"particle/fog/fog1":()=>hr(512,4,5,1,.4,.9,150),"particle/fog/fog2":()=>hr(512,3,5,2,.45,.8,140),"particle/fog/fog3":()=>hr(512,6,4,3,.36,1,150),"particle/smoke/smoke1":()=>hr(512,3,5,7,.55,1.5,130),"particle/smoke/smoke2":()=>hr(512,2,5,11,.6,1.7,120),"particle/smoke/smoke2light":()=>hr(512,2,5,13,.4,1.7,110),"particle/misc/wave":()=>Mc(512,.72,.085),"particle/misc/star_0":()=>dr(256,5,.62,8,.1),"particle/bubbles/bubble1":()=>us(256,1),"particle/bubbles/bubble2":()=>us(256,2),"particle/bubbles/bubble3":()=>us(256,3),"particle/debris/debris1":()=>Id(128),"particle/lightning/lightning1":()=>ba(256,3),"particle/lightning/lightning2":()=>ba(256,11),"particle/lightning/lightning3":()=>ba(256,19),"particle/fire/fire1":()=>Bc(256,23),"particle/fire/fire2":()=>Bc(256,41),"particle/star":()=>dr(256,4,.58,12,.09),"particle/shape/circle_wind":()=>_d(256),"particle/sickle":()=>Md(256),"particle/magic/glyph_4":()=>Rd(256,4),"@sparkle":()=>dr(256,4,.6,16,.08),"@star":()=>dr(256,5,.62,8,.1),"@trail":()=>Fc(128,256)};function Dd(t){const e=String(t).toLowerCase();if(/normal/.test(e)){const n=Ny(t);return n?()=>rn(Ly(n),2.8):()=>rn(Pd(128),2.6)}return/rosepetal|petal|sakura|blossom/.test(e)?()=>Sd(256):/leaf|leaves|foliage/.test(e)?/leaves8/.test(e)?()=>bt(yt,8):/leaves7/.test(e)?()=>bt(yt,7):/leaves6/.test(e)?()=>bt(yt,6):/leaves5/.test(e)?()=>bt(yt,5):/leaves3/.test(e)?()=>bt(yt,3):/leaves2/.test(e)?()=>bt(yt,2):/leaves1/.test(e)?()=>bt(yt,1):()=>bt(yt,0):/circle_wind|windcircle/.test(e)?()=>_d(256):/fog|cloud|mist|vapor/.test(e)?()=>hr(512,4,5,5,.4,.9,150):/smoke/.test(e)?()=>hr(512,3,5,8,.55,1.5,130):/beam|shaft|ray|godray/.test(e)?()=>bn(128,512,.3,!0):/flare/.test(e)?()=>Fd(256):/bubble/.test(e)?()=>Td(256,1):/ring|wave/.test(e)?()=>Mc(512,.72,.085):/fire|flame|ember|ash/.test(e)?()=>Bc(256,Nc(e)):/sickle|crescent|moon/.test(e)?()=>Md(256):/glyph|magic|rune/.test(e)?()=>Rd(256,Nc(e)):/snowflake|雪花|snow/.test(e)?()=>Bd(256):/流星|meteor|shooting/.test(e)?()=>Fc(128,256):/star|星/.test(e)?()=>dr(256,5,.62,8,.1):/sparkle|glint|twinkle/.test(e)?()=>dr(256,4,.6,16,.08):/rain_drops_sheet|drops_sheet/.test(e)?()=>Rc(256,512,2,4):/drop|rain/.test(e)?()=>Dc(128,512):/debris|dirt|rock/.test(e)?()=>Id(128):/lightning|bolt|arc/.test(e)?()=>ba(256,Nc(e)):/note|music/.test(e)?()=>dr(256,4,.55,8,.12):/trail|streak/.test(e)?()=>Fc(128,256):()=>jn(256,{r:.12,w:1},{r:.3,w:.15})}function zy(t){if(as.has(t))return as.get(t);let e=null;const n=_c.get(t);if(n)try{e=n()}catch{e=null}if(!e&&ga)try{e=ga(t)}catch{e=null}if(!e&&ds[t])try{e=ds[t]()}catch{e=null}if(!e)try{e=Dd(t)()}catch{e=null}return e||(e=jn(256,{r:.12,w:1},{r:.3,w:.15})),as.set(t,e),e}function Hy(t){return typeof t=="string"&&t.indexOf("particle/")===0}const Vy=Object.freeze(Object.defineProperty({__proto__:null,buildBuiltinParticleTexture:zy,builtinParticleFrames:Iy,isBuiltinParticleTextureName:Hy,listBuiltinParticleTextureNames:Cy,particleNormalNameForAlbedo:Dy,prepareParticleNormalTexture:Ry,resetParticleTextureFactories:Ey,setParticleTextureFactory:Py,setParticleTextureProvider:_y},Symbol.toStringTag,{value:"Module"})),Nd=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function mr(t,e,n){const r=n||new Float32Array(16);for(let i=0;i<4;i++)for(let s=0;s<4;s++)r[i*4+s]=t[s]*e[i*4]+t[4+s]*e[i*4+1]+t[8+s]*e[i*4+2]+t[12+s]*e[i*4+3];return r}function Ld(t){const e=[];for(let r=0;r<4;r++)e.push([t[r],t[4+r],t[8+r],t[12+r],0,0,0,0]),e[r][4+r]=1;for(let r=0;r<4;r++){let i=r;for(let o=r+1;o<4;o++)Math.abs(e[o][r])>Math.abs(e[i][r])&&(i=o);const s=e[r];e[r]=e[i],e[i]=s;const a=e[r][r];if(Math.abs(a)<1e-12)return Float32Array.from(Nd);for(let o=0;o<8;o++)e[r][o]/=a;for(let o=0;o<4;o++){if(o===r)continue;const c=e[o][r];if(c!==0)for(let u=0;u<8;u++)e[o][u]-=c*e[r][u]}}const n=new Float32Array(16);for(let r=0;r<4;r++)for(let i=0;i<4;i++)n[r*4+i]=e[i][4+r];return n}function Lc(t,e,n,r,i,s,a,o,c,u){const l=u||new Float32Array(16),f=Math.cos(r),d=Math.sin(r),h=Math.cos(i),p=Math.sin(i),m=Math.cos(s),g=Math.sin(s);return l[0]=m*h*a,l[1]=g*h*a,l[2]=-p*a,l[3]=0,l[4]=(m*p*d-g*f)*o,l[5]=(g*p*d+m*f)*o,l[6]=h*d*o,l[7]=0,l[8]=(m*p*f+g*d)*c,l[9]=(g*p*f-m*d)*c,l[10]=h*f*c,l[11]=0,l[12]=t,l[13]=e,l[14]=n,l[15]=1,l}function pr(t,e){const n=[];for(;e<t.byteLength;){const i=t.getUint8(e++);if(i===0)break;n.push(i)}let r="";try{r=new TextDecoder("utf-8").decode(new Uint8Array(n))}catch{r=String.fromCharCode.apply(null,n)}return{value:r,next:e}}function wa(t,e,n=0){const r=[];for(let i=0;i<e.length;i++)r.push(e.charCodeAt(i));e:for(let i=n;i<=t.length-r.length;i++){for(let s=0;s<r.length;s++)if(t[i+s]!==r[s])continue e;return i}return-1}function Wy(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength),n=String.fromCharCode.apply(null,Array.from(t.subarray(0,8)));if(!n.startsWith("MDLV"))throw new Error("\u4E0D\u662F MDL: "+n);const r=pr(e,21),s=parseInt(n.slice(4),10)>=23?[{lenOff:32,stride:80,uv:72,bone:40,weight:56},{lenOff:32,stride:84,uv:76,bone:44,weight:60,formatMarker:25231374},{lenOff:32,stride:48,uv:40,bone:-1,weight:-1}]:[{lenOff:8,stride:52,uv:44,bone:12,weight:28},{lenOff:4,stride:52,uv:44,bone:12,weight:28},{lenOff:32,stride:80,uv:72,bone:40,weight:56}];let a=null,o=0,c=0;for(const H of s){const G=r.next+H.lenOff;if(G+4>t.byteLength)continue;const Y=e.getUint32(G,!0);if((H.formatMarker===void 0||e.getUint32(r.next+28,!0)===H.formatMarker)&&Y>0&&Y%H.stride===0&&G+4+Y<=t.byteLength){a=H,o=Y,c=G;break}}if(!a)throw new Error("\u9876\u70B9\u533A\u957F\u5EA6\u5F02\u5E38\uFF08"+n+"\uFF0C\u5DF2\u8BD5 stride "+s.map(H=>H.stride).join("/")+"\uFF09");const u=c+4,l=o/a.stride,f=new Float32Array(l*3),d=new Float32Array(l*2),h=new Float32Array(l*4),p=new Float32Array(l*4);for(let H=0;H<l;H++){const G=u+H*a.stride;if(f[H*3]=e.getFloat32(G,!0),f[H*3+1]=e.getFloat32(G+4,!0),f[H*3+2]=e.getFloat32(G+8,!0),d[H*2]=e.getFloat32(G+a.uv,!0),d[H*2+1]=e.getFloat32(G+a.uv+4,!0),a.bone>=0&&a.weight>=0)for(let Y=0;Y<4;Y++)h[H*4+Y]=e.getUint32(G+a.bone+Y*4,!0),p[H*4+Y]=e.getFloat32(G+a.weight+Y*4,!0);else h[H*4]=0,p[H*4]=1}const m=e.getUint32(u+o,!0),g=u+o+4,w=l>65535&&m%4===0,y=w?m/4:m/2,b=w?new Uint32Array(y):new Uint16Array(y);if(w)for(let H=0;H<y;H++)b[H]=e.getUint32(g+H*4,!0);else for(let H=0;H<y;H++)b[H]=e.getUint16(g+H*2,!0);const v=qy(t,e),k=$y(t,e,v.length),A=Yy(t,e,v),T=jy(t,e,v.length),S=[],P=[],M=[];if(v.length>0){const H=v.map((Y,J)=>{const ne=Y.matrix,fe=Math.hypot(ne[0],ne[1]),Ne=Math.hypot(ne[4],ne[5]);return M[J]=Float32Array.from([ne[12],ne[13],ne[14],0,0,Math.atan2(ne[1],ne[0]),fe||1,Ne||1,ne[10]||1]),Float32Array.from(ne)});for(let Y=0;Y<v.length;Y++){const J=M[Y],ne=v[Y].matrix;Math.hypot(J[0]-ne[12],J[1]-ne[13])>.001&&(H[Y]=Lc(J[0],J[1],J[2],J[3],J[4],J[5],J[6],J[7],J[8],new Float32Array(16)))}const G=[];for(let Y=0;Y<v.length;Y++){const J=v[Y].parent;G[Y]=J>=0&&J<Y?mr(G[J],H[Y]):Float32Array.from(H[Y])}for(let Y=0;Y<v.length;Y++)S[Y]=Float64Array.from(Ld(G[Y]));if(A){const Y=[];for(let J=0;J<v.length;J++){const ne=v[J].parent;Y[J]=ne>=0&&ne<J?mr(Y[ne],A[J]):Float32Array.from(A[J])}for(let J=0;J<v.length;J++)P[J]=mr(Y[J],S[J])}}let B=1/0,N=-1/0,U=1/0,q=-1/0;for(let H=0;H<l;H++){const G=f[H*3],Y=f[H*3+1];G<B&&(B=G),G>N&&(N=G),Y<U&&(U=Y),Y>q&&(q=Y)}return{magic:n,materialPath:r.value,vertexCount:l,positions:f,uvs:d,boneIdx:h,weights:p,indexCount:y,indexType:w?"u32":"u16",indices:b,bones:v,animations:k,animBound:Qy(k,v),invBindWorld:S,bindTRS:M.length>0?M:null,attachments:T.length>0?T:null,restCorrection:P.length>0?P:null,bounds:{minX:B,maxX:N,minY:U,maxY:q}}}function jy(t,e,n){const r=wa(t,"MDAT");if(r<0)return[];const i=e.getUint16(r+13,!0);if(i<=0||i>256)return[];const s=[];let a=r+15;for(let o=0;o<i&&!(a+2>t.length);o++){const c=e.getUint16(a,!0),u=pr(e,a+2);if(u.next+64>t.length)break;const l=new Float32Array(16);for(let f=0;f<16;f++)l[f]=e.getFloat32(u.next+f*4,!0);c<n&&s.push({bone:c,name:u.value,matrix:l}),a=u.next+64}return s}function qy(t,e){const n=wa(t,"MDLS");if(n<0)return[];const r=e.getUint32(n+13,!0);if(r<=0||r>1024)return[];const i=[];let s=n+17;for(let a=0;a<r;a++){if(s+77>e.byteLength)return i;const o=e.getUint32(s+1,!0),c=e.getInt32(s+5,!0),u=new Float32Array(16);for(let f=0;f<16;f++)u[f]=e.getFloat32(s+13+f*4,!0);const l=pr(e,s+13+64);i.push({id:o,parent:c>=0&&c<r?c:-1,matrix:u}),s=l.next}return i}function Xy(t,e,n){const r=Math.min(t.byteLength-24,n);for(let i=e;i<r;i++){if(t.getUint32(i+4,!0)!==0)continue;const s=pr(t,i+8);if(!s.value||s.value.length>64)continue;const a=pr(t,s.next);if(!a.value||a.value.length>16)continue;const o=t.getFloat32(a.next,!0);if(!(o>0&&o<=240))continue;const c=t.getUint32(a.next+4,!0);if(c<=0||c>1e5)continue;const u=t.getUint32(a.next+12,!0);if(!(u<=0||u>1024))return i}return-1}function Gy(t,e,n){const r=[],i=Math.min(t.byteLength,n,e+64);let s=e,a=0;for(;s<i&&t.getUint8(s)!==123&&a++<64;)s++;if(s>=i||t.getUint8(s)!==123)return{events:r,next:e};const o=Math.min(t.byteLength,n,e+8192);for(let c=0;c<64&&s<o&&t.getUint8(s)===123;c++){const u=pr(t,s);let l=null;try{l=JSON.parse(u.value)}catch{l=null}if(!l||typeof l!="object"||!Number.isFinite(Number(l.frame))||typeof l.name!="string")break;r.push({frame:Number(l.frame),name:l.name}),s=u.next;let f=s,d=0;for(;f<o&&t.getUint8(f)!==123&&d<8;)f++,d++;if(d<8&&f<o&&t.getUint8(f)===123){s=f;continue}break}return{events:r,next:s}}function $y(t,e,n){const r=wa(t,"MDLA");if(r<0)return[];let i=r+9;const s=e.getUint32(i,!0);i+=4;const a=e.getUint32(i,!0);if(i+=4,a<=0||a>256)return[];const o=[];for(let c=0;c<a&&!(i+16>e.byteLength);c++){const u=e.getUint32(i,!0);i+=8;const l=pr(e,i);i=l.next;const f=pr(e,i);if(i=f.next,i+16>e.byteLength)break;const d=e.getFloat32(i,!0);i+=4;const h=e.getUint32(i,!0);i+=8;const p=e.getUint32(i,!0);if(i+=4,p>1024)break;const m=[];for(let b=0;b<p&&!(i+8>e.byteLength);b++){i+=4;const v=e.getUint32(i,!0);i+=4;const k=Math.floor(v/36);if(i+v>e.byteLength)break;const A=new Float32Array(k*9);for(let T=0;T<k;T++){const S=i+T*36;for(let P=0;P<9;P++)A[T*9+P]=e.getFloat32(S+P*4,!0)}i+=v,m.push({frameCount:k,keyframes:A})}const g=s>0&&s<=e.byteLength?s:e.byteLength,w=Gy(e,i,g);m.length>0&&h>0&&d>0&&o.push({id:u,name:l.value,mode:f.value,fps:d,frameCount:h,duration:h/d,tracks:m,events:w.events});const y=Xy(e,w.next,g);if(y<0)break;i=y}return o}function Qy(t,e){let n=0,r=0;for(const i of t)for(let s=0;s<i.tracks.length;s++){const a=i.tracks[s];if(!a)continue;const o=e[s],c=o?o.matrix[12]:0,u=o?o.matrix[13]:0,l=a.keyframes;for(let f=0;f<a.frameCount;f++){const d=Math.abs(l[f*9]-c),h=Math.abs(l[f*9+1]-u);d>n&&(n=d),h>r&&(r=h)}}return{x:n,y:r}}function Yy(t,e,n){if(n.length===0)return null;const r=wa(t,"MDLE");if(r<0)return null;const i=r+8+1+4+4;if(i+n.length*64>e.byteLength)return null;const s=[];for(let a=0;a<n.length;a++){const o=new Float32Array(16);for(let c=0;c<16;c++)o[c]=e.getFloat32(i+a*64+c*4,!0);s.push(o)}return s}function Ky(t,e,n,r){const i=t.frameCount;if(i===0)return r[0]=0,r[1]=0,r[2]=0,r[3]=0,r[4]=0,r[5]=0,r[6]=1,r[7]=1,r[8]=1,r;const s=n*e.fps;let a,o,c;if(e.mode==="loop"){const h=Math.max(1,i-1),p=(s%h+h)%h;a=Math.floor(p),o=(a+1)%i,c=p-a}else if(e.mode==="mirror"){const h=Math.max(1,i-1),p=h*2;let m=(s%p+p)%p;m>h&&(m=p-m),a=Math.floor(m),o=Math.min(a+1,i-1),c=m-a}else{const h=Math.min(Math.max(s,0),i-1);a=Math.floor(h),o=Math.min(a+1,i-1),c=h-a}const u=t.keyframes,l=a*9,f=o*9,d=1-c;for(let h=0;h<9;h++)if(h>=3&&h<=5){let p=u[f+h]-u[l+h];p>Math.PI?p-=2*Math.PI:p<-Math.PI&&(p+=2*Math.PI),r[h]=u[l+h]+p*c}else r[h]=u[l+h]*d+u[f+h]*c;return r}function Zy(t,e,n){const r=t.bindTRS&&t.bindTRS[e];if(r)return n.set(r),n;const i=t.bones[e].matrix;return n[0]=i[12],n[1]=i[13],n[2]=i[14],n[3]=0,n[4]=0,n[5]=Math.atan2(i[1],i[0]),n[6]=Math.hypot(i[0],i[1])||1,n[7]=Math.hypot(i[4],i[5])||1,n[8]=i[10]||1,n}function Oc(t,e,n,r){const i=t.bones,s=i.length;if(s===0)return null;const a=!!(r&&r.size>0);if(!t._skin||t._skin.length!==s*16){t._skin=new Float32Array(s*16),t._local=[],t._world=[],t._tmp=new Float32Array(16),t._tmp2=new Float32Array(16);for(let d=0;d<s;d++)t._local.push(new Float32Array(16)),t._world.push(new Float32Array(16))}const o=Array.isArray(n)&&n.length>0,c=[];if(o)for(const d of n){if(d.visible===!1||d.visible===0)continue;const h=t.animations.find(p=>p.id===d.animation);h&&c.push({anim:h,additive:!!d.additive,blend:typeof d.blend=="number"?d.blend:1,rate:typeof d.rate=="number"?d.rate:1})}if(c.length===0&&!o){const d=t.animations[0];if(d)c.push({anim:d,additive:!1,blend:1,rate:1});else if(!a)return null}const u=t._trsBase||(t._trsBase=new Float32Array(9)),l=t._trsAcc||(t._trsAcc=new Float32Array(9)),f=t._trsSmp||(t._trsSmp=new Float32Array(9));for(let d=0;d<s;d++){Zy(t,d,u),l.set(u);let h=!1,p=0,m=!1,g=!1;const w=t._addDelta||(t._addDelta=new Float32Array(9));w.fill(0);for(const b of c){const v=b.anim.tracks[d];if(!v||!v.keyframes.length)continue;Ky(v,b.anim,e*b.rate,f);const k=b.blend;if(b.additive){const A=v.keyframes;if(!m&&!g){for(let T=0;T<9;T++)l[T]=A[T];g=!0}for(let T=0;T<9;T++){let S=f[T]-A[T];T>=3&&T<=5&&(S>Math.PI?S-=2*Math.PI:S<-Math.PI&&(S+=2*Math.PI)),w[T]+=S*k}p+=k}else{m=!0;for(let A=0;A<9;A++)l[A]=l[A]*(1-k)+f[A]*k}h=!0}if(p>1)for(let b=0;b<9;b++)w[b]/=p;if(p>0)for(let b=0;b<9;b++)l[b]+=w[b];const y=a?r.get(d):void 0;y&&(l[0]=y[0],l[1]=y[1],l[2]=y[2],h=!0),h?Lc(l[0],l[1],l[2],l[3],l[4],l[5],l[6],l[7],l[8],t._local[d]):Lc(u[0],u[1],u[2],u[3],u[4],u[5],u[6],u[7],u[8],t._local[d])}for(let d=0;d<s;d++){const h=i[d].parent;h>=0&&h<d?mr(t._world[h],t._local[d],t._world[d]):t._world[d].set(t._local[d])}for(let d=0;d<s;d++)mr(t._world[d],t.invBindWorld[d],t._tmp),t._skin.set(t._tmp,d*16);return t._skin}function Od(t,e){return!t||!t.invBindWorld||!(e>=0&&e<t.invBindWorld.length)?null:Ld(t.invBindWorld[e])}function Jy(t,e){return mr(t,e)}function Ud(t,e){if(!t||!t.attachments||typeof e!="string"||e===""||!t._world)return null;for(const n of t.attachments)if(n.name===e)return n.bone<0||n.bone>=t._world.length?null:mr(t._world[n.bone],n.matrix);return null}function zd(t,e){if(!t||!t.attachments||typeof e!="string"||e==="")return null;for(const n of t.attachments){if(n.name!==e)continue;const r=Od(t,n.bone);return r?mr(r,n.matrix):null}return null}function Uc(t,e,n){const r=t&&t.angles&&t.angles[2]||0,i=t&&t.scale?t.scale[0]:1,s=t&&t.scale?t.scale[1]:1,a=r*Math.PI/180,o=Math.cos(a),c=Math.sin(a),u=e*i,l=n*s;return[u*o-l*c,u*c+l*o]}function eb(t){const e=new Map,n=new Map;for(const s of t){if(!s||s.id===void 0||s.id===null||(e.set(s.id,s),s.parentId===void 0||s.parentId===null))continue;const a=n.get(s.parentId);a?a.push(s):n.set(s.parentId,[s])}const r=(s,a)=>{const o=n.get(s.id);if(o)for(const c of o)a.push(c),r(c,a)},i=[];for(const s of t){const a=s&&s.attachment;if(typeof a!="string"||a==="")continue;const o=e.get(s.parentId);if(!o||!o.puppet)continue;const c=zd(o.puppet,a);if(!c)continue;const u=c[12],l=c[13],f=Uc(o,u,l),d=[];r(s,d),s.origin[0]+=f[0],s.origin[1]+=f[1];for(const h of d)h.origin[0]+=f[0],h.origin[1]+=f[1];s.parallaxDepth=o.parallaxDepth?o.parallaxDepth.slice():null;for(const h of d)h.parallaxDepth=s.parallaxDepth?s.parallaxDepth.slice():null;s.attachBindDelta=[f[0],f[1]],i.push({layer:s,parent:o,name:a,bindX:u,bindY:l,desc:d})}for(const s of i){s.baseX=s.layer.origin[0],s.baseY=s.layer.origin[1],s.subtree=[{layer:s.layer,x:s.layer.origin[0],y:s.layer.origin[1]}];for(const a of s.desc)s.subtree.push({layer:a,x:a.origin[0],y:a.origin[1]});for(const a of s.subtree)a.layer.attachBase||(a.layer.attachBase=[a.x,a.y])}return i}function tb(t,e,n){if(!t||t.length===0)return;const r=new Set,i=[];for(const o of t){const c=o.parent&&o.parent.puppet;if(!c){i.push(null);continue}if(!r.has(c)){r.add(c);const l=typeof n=="function"?n(o.parent):null;Oc(c,e,o.parent.animationLayers,l)}const u=Ud(c,o.name);if(!u){i.push(null);continue}i.push(Uc(o.parent,u[12]-o.bindX,u[13]-o.bindY))}const s=o=>{const c=o.layer.attachBase;return c||[o.x,o.y]},a=new Set;for(const o of t){const c=o.subtree||[{layer:o.layer,x:o.baseX,y:o.baseY}];for(const u of c){if(a.has(u.layer))continue;a.add(u.layer);const l=s(u);u.layer.origin[0]=l[0],u.layer.origin[1]=l[1]}}for(let o=0;o<t.length;o++){const c=t[o],u=i[o],l=c.subtree||[{layer:c.layer,x:c.baseX,y:c.baseY}];if(u)for(const f of l)f.layer.origin[0]+=u[0],f.layer.origin[1]+=u[1]}}const nb=128,va=24;function rb(t){const e=t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS)||256,n=Math.floor((e-32)/4);return Math.max(va,Math.min(nb,n))}const ib=t=>`#version 300 es
|
|
142
425
|
in vec3 a_pos;
|
|
143
426
|
in vec2 a_uv;
|
|
144
427
|
in vec4 a_bone;
|
|
145
428
|
in vec4 a_weight;
|
|
146
429
|
uniform mat4 u_mvp;
|
|
147
|
-
uniform mat4 u_skin[${
|
|
430
|
+
uniform mat4 u_skin[${t}];
|
|
148
431
|
uniform int u_boneCount;
|
|
149
432
|
out vec2 v_uv;
|
|
150
433
|
void main() {
|
|
@@ -164,7 +447,7 @@ void main() {
|
|
|
164
447
|
vec4 local = total > 0.0 ? skinned / total : p;
|
|
165
448
|
gl_Position = u_mvp * vec4(local.xy, 0.0, 1.0);
|
|
166
449
|
v_uv = a_uv;
|
|
167
|
-
}`,
|
|
450
|
+
}`,sb=`#version 300 es
|
|
168
451
|
precision mediump float;
|
|
169
452
|
in vec2 v_uv;
|
|
170
453
|
uniform sampler2D u_tex;
|
|
@@ -173,12 +456,7 @@ out vec4 fragColor;
|
|
|
173
456
|
void main() {
|
|
174
457
|
vec4 t = texture(u_tex, v_uv);
|
|
175
458
|
fragColor = t * u_color;
|
|
176
|
-
}`;function kc(e){const n=(u,l)=>{const f=e.createShader(u);if(e.shaderSource(f,l),e.compileShader(f),!e.getShaderParameter(f,e.COMPILE_STATUS))throw new Error("MDL \u7740\u8272\u5668\u7F16\u8BD1\u5931\u8D25: "+e.getShaderInfoLog(f));return f};let t=Cc(e),r=null;for(;;){const u=e.createProgram();let l=!1;try{e.attachShader(u,n(e.VERTEX_SHADER,Lc(t))),e.attachShader(u,n(e.FRAGMENT_SHADER,Rc)),e.bindAttribLocation(u,0,"a_pos"),e.bindAttribLocation(u,1,"a_uv"),e.bindAttribLocation(u,2,"a_bone"),e.bindAttribLocation(u,3,"a_weight"),e.linkProgram(u),l=!!e.getProgramParameter(u,e.LINK_STATUS)}catch{l=!1}if(l){r=u;break}if(e.deleteProgram(u),t<=dr)throw new Error("MDL \u7740\u8272\u5668\u94FE\u63A5\u5931\u8D25\uFF08\u9AA8\u6570\u5DF2\u964D\u5230 "+dr+"\uFF09");t=Math.max(dr,t>>1)}const o=t,i={mvp:e.getUniformLocation(r,"u_mvp"),tex:e.getUniformLocation(r,"u_tex"),skin:e.getUniformLocation(r,"u_skin"),boneCount:e.getUniformLocation(r,"u_boneCount"),color:e.getUniformLocation(r,"u_color")},s=new Float32Array(o*16);for(let u=0;u<o;u++)s.set(Ti,u*16);const a=new WeakMap;function c(u){let l=a.get(u);if(l)return l;const f=e.createVertexArray();e.bindVertexArray(f);const p=u.vertexCount,d=new Float32Array(p*13);for(let M=0;M<p;M++){const h=M*13;d[h]=u.positions[M*3],d[h+1]=u.positions[M*3+1],d[h+2]=u.positions[M*3+2],d[h+3]=u.uvs[M*2],d[h+4]=u.uvs[M*2+1];for(let g=0;g<4;g++)d[h+5+g]=u.boneIdx[M*4+g],d[h+9+g]=u.weights[M*4+g]}const y=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,y),e.bufferData(e.ARRAY_BUFFER,d,e.STATIC_DRAW);const x=52;e.enableVertexAttribArray(0),e.vertexAttribPointer(0,3,e.FLOAT,!1,x,0),e.enableVertexAttribArray(1),e.vertexAttribPointer(1,2,e.FLOAT,!1,x,12),e.enableVertexAttribArray(2),e.vertexAttribPointer(2,4,e.FLOAT,!1,x,20),e.enableVertexAttribArray(3),e.vertexAttribPointer(3,4,e.FLOAT,!1,x,36);const m=e.createBuffer();return e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,m),e.bufferData(e.ELEMENT_ARRAY_BUFFER,u.indices,e.STATIC_DRAW),e.bindVertexArray(null),l={vao:f,vbuf:y,ibuf:m},a.set(u,l),l}return{gl:e,prog:r,maxBones:o,upload(u){c(u)},draw(u,l,f,p){const d=c(l);e.useProgram(r),e.bindVertexArray(d.vao),e.activeTexture(e.TEXTURE0);const y=f.overrideTex||(p&&p.glTex?p.glTex:p);e.bindTexture(e.TEXTURE_2D,y),e.uniform1i(i.tex,0),e.uniformMatrix4fv(i.mvp,!1,u);const x=f.color||[1,1,1,1];e.uniform4f(i.color,x[0],x[1],x[2],x[3]);const m=io(l,f.time||0,f.animLayers,f.boneOverrides),M=Math.min(l.bones.length,o);m&&M>0?(e.uniformMatrix4fv(i.skin,!1,m.subarray(0,M*16)),e.uniform1i(i.boneCount,M)):(e.uniformMatrix4fv(i.skin,!1,s),e.uniform1i(i.boneCount,0)),f.blending==="additive"?(e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE,e.ONE,e.ONE)):f.blending==="normal"?e.disable(e.BLEND):(e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA));const h=l.indexType==="u32"?e.UNSIGNED_INT:e.UNSIGNED_SHORT;e.drawElements(e.TRIANGLES,l.indexCount,h,0),e.bindVertexArray(null)}}}const Fc=Object.freeze(Object.defineProperty({__proto__:null,applyAttachmentBindOrigins:Sc,attachmentBind:Ci,attachmentWorld:Pi,bindWorldOf:Ei,computeSkinMatrices:io,createMDLRenderer:kc,followAttachments:Ec,mat4MulOut:Tc,parentMeshToWorldDelta:so,parseMDL:bc},Symbol.toStringTag,{value:"Module"}));function Li(e,n,t){const r=Math.max(0,Number(t)||0),o=Math.max(1,Number(e)||1),i=Math.max(1,Number(n)||1);return r*2>=Math.min(o,i)?0:r}function Nc(e,n,t){const r=Math.max(1,n.boxW),o=Math.max(1,n.boxH),i=Li(r,o,n.padding||0),s=n.spacing||[0,0],a=Math.max(1,n.lineHeight||(n.pointsize||24)*1.25+s[1]),c=Math.max(1,r-i*2),u=n.limitwidth&&n.maxwidth>0?Math.min(n.maxwidth,c):1/0;function l(_){if(t(_)<=u)return[_];const R=[];let L="",N=-1;for(const j of _)if(L+=j,(j===" "||j===" ")&&(N=L.length),t(L)>u&&L.length>1)for(N>0?(R.push(L.slice(0,N-1)),L=L.slice(N)):(R.push(L.slice(0,-1)),L=j),N=-1;t(L)>u&&L.length>1;)R.push(L.slice(0,-1)),L=L.slice(-1);return L!==""&&R.push(L),R.length?R:[""]}let f=[];const p=String(e??"").split(`
|
|
177
|
-
`);for(const _ of p)f.push(...l(_));let d=!1;if(n.limitrows&&n.maxrows>0&&f.length>n.maxrows&&(f=f.slice(0,n.maxrows),d=!0,n.limituseellipsis)){let _=f[n.maxrows-1];for(;_.length>0&&t(_+"\u2026")>u;)_=_.slice(0,-1);f[n.maxrows-1]=_+"\u2026"}const y=f.map(_=>t(_)),x=f.length*a,m=n.halign||"center",M=n.valign||"center",h=r/2,g=o/2,v=M==="top"?g:M==="bottom"?g-x:(o-x)/2;return{lines:f.map((_,R)=>{const L=y[R],N=m==="left"?h:m==="right"?h-L:(r-L)/2;return{text:_,width:L,x:N,y:v+R*a}}),lineHeight:a,totalH:x,truncated:d,boxW:r,boxH:o}}function Uc(e,n,t){const r=n.boxW,o=n.boxH,i=t.color||[1,1,1],s=t.alpha!==void 0?t.alpha:1,a=t.brightness!==void 0?t.brightness:1;e.font=t.font;try{e.letterSpacing=(t.spacing&&t.spacing[0]?t.spacing[0]:0)+"px"}catch{}if(e.textBaseline="middle",t.opaquebackground){const u=t.backgroundcolor||[0,0,0],l=t.backgroundbrightness!==void 0?t.backgroundbrightness:1;e.fillStyle=`rgba(${Math.round(u[0]*255*l)},${Math.round(u[1]*255*l)},${Math.round(u[2]*255*l)},${s})`,e.fillRect(0,0,r,o)}const c=(u,l,f)=>{e.fillStyle=f;for(const p of n.lines)e.fillText(p.text,p.x+u,p.y+n.lineHeight/2+l)};if(t.castshadow){const u=Math.max(1,(t.pointsize||24)/10);c(u,u,`rgba(0,0,0,${s*.75})`)}c(0,0,`rgba(${Math.round(i[0]*255*a)},${Math.round(i[1]*255*a)},${Math.round(i[2]*255*a)},${s})`)}const Ri=/^add[A-Z]/;function ki(){return{log:()=>{},warn:()=>{},error:()=>{},info:()=>{},debug:()=>{}}}function Fi(e){return new Proxy(e,{get(n,t,r){const o=Reflect.get(n,t,r);if(o==null&&typeof t=="string"&&t!=="then"){const i=()=>{};return n[t]=i,i}return o}})}function xn(e,n){return()=>{}}function Ni(e,n){e.isScreensaver=!!n.isScreensaver,typeof n.isRunningInEditor=="boolean"&&(e.isRunningInEditor=n.isRunningInEditor),e.setInterval||(e.setInterval=n.setInterval||xn),e.setTimeout||(e.setTimeout=n.setTimeout||xn),e.clearTimeout||(e.clearTimeout=n.clearTimeout||(()=>{})),e.clearInterval||(e.clearInterval=n.clearInterval||(()=>{})),typeof n.openUserShortcut=="function"&&(e.openUserShortcut=n.openUserShortcut);const t=n.mediaControl||null;e.media={skipNext:()=>{if(t&&t.skipNext)return t.skipNext()},skipPrevious:()=>{if(t&&t.skipPrevious)return t.skipPrevious()},play:()=>{if(t&&t.play)return t.play()},pause:()=>{if(t&&t.pause)return t.pause()},playPause:()=>{if(t&&t.playPause)return t.playPause()},get snapshot(){return t&&t.snapshot?t.snapshot:null}};const r=n.windowTitle;Object.defineProperty(e,"windowTitle",{configurable:!0,enumerable:!0,get(){return r&&r.title?String(r.title):""}}),Object.defineProperty(e,"windowApp",{configurable:!0,enumerable:!0,get(){return r&&r.app?String(r.app):""}})}class me{constructor(n,t,r){if(n!==null&&typeof n=="object")this.x=n.x!==void 0?n.x:n.width||0,this.y=t!==void 0?t:n.y!==void 0?n.y:n.height||0,this.z=r!==void 0?r:n.z||0;else if(t===void 0&&r===void 0){const o=Number(n)||0;this.x=o,this.y=o,this.z=o}else this.x=Number(n)||0,this.y=Number(t)||0,this.z=Number(r)||0}add(n){const t=new me(n);return new me(this.x+t.x,this.y+t.y,this.z+t.z)}subtract(n){const t=new me(n);return new me(this.x-t.x,this.y-t.y,this.z-t.z)}multiply(n){return n&&typeof n=="object"?new me(this.x*n.x,this.y*n.y,this.z*n.z):new me(this.x*n,this.y*n,this.z*n)}divide(n){const t=(r,o)=>o===0?0:r/o;return n&&typeof n=="object"?new me(t(this.x,n.x),t(this.y,n.y),t(this.z,n.z)):new me(t(this.x,n),t(this.y,n),t(this.z,n))}copy(){return new me(this.x,this.y,this.z)}mix(n,t){const r=new me(n),o=Number(t),i=Number.isFinite(o)?o:0;return new me(this.x+(r.x-this.x)*i,this.y+(r.y-this.y)*i,this.z+(r.z-this.z)*i)}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}normalize(){const n=this.length();return n===0?new me(0,0,0):new me(this.x/n,this.y/n,this.z/n)}dot(n){const t=new me(n);return this.x*t.x+this.y*t.y+this.z*t.z}toString(){return this.x+" "+this.y+" "+this.z}}const Ui=me;function Di(e){if(e instanceof me||!e||typeof e!="object"||Array.isArray(e)||!("x"in e)&&!("y"in e)&&!("z"in e)||Object.getPrototypeOf(e)===me.prototype)return e;try{Object.setPrototypeOf(e,me.prototype)}catch{}return e}function Bi(e){return e&&e.cursorWorldPosition?e:{cursorWorldPosition:new me(0,0,0),cursorScreenPosition:new me(0,0,0),cursorPosition:new me(0,0,0),cursorPositionLast:new me(0,0,0),cursorLeftDown:!1}}function Dc(e,n,t){return new me(e||0,n||0,t||0)}function Bc(){const e={cursorWorldPosition:new me(0,0,0),cursorScreenPosition:new me(0,0,0),cursorPosition:new me(0,0,0),cursorPositionLast:new me(0,0,0),cursorLeftDown:!1};return e.update=function(n){return n&&(e.cursorWorldPosition.x=n.wx,e.cursorWorldPosition.y=n.originY!=null?n.originY:n.wy,e.cursorWorldPosition.z=0,e.cursorScreenPosition.x=n.screenX,e.cursorScreenPosition.y=n.screenY,e.cursorScreenPosition.z=0,e.cursorPosition.x=n.u,e.cursorPosition.y=n.v,e.cursorPosition.z=0,e.cursorPositionLast.x=n.lastU,e.cursorPositionLast.y=n.lastV,e.cursorPositionLast.z=0,e.cursorLeftDown=!!n.leftDown),e},e}const Ii={mix:(e,n,t)=>e+(n-e)*t,lerp:(e,n,t)=>e+(n-e)*t,clamp:(e,n,t)=>Math.min(t,Math.max(n,e)),saturate:e=>Math.min(1,Math.max(0,e)),smoothstep:(e,n,t)=>{const r=Math.min(1,Math.max(0,(t-e)/(n-e||1)));return r*r*(3-2*r)},smoothStep:(e,n,t)=>{const r=Math.min(1,Math.max(0,(t-e)/(n-e||1)));return r*r*(3-2*r)},random:(e,n)=>e===void 0?Math.random():e+Math.random()*((n===void 0?1:n)-e),randomInt:(e,n)=>Math.floor((e||0)+Math.random()*((n===void 0?1:n)+1-(e||0))),degrees:e=>e*180/Math.PI,radians:e=>e*Math.PI/180},Oi={hsv2rgb:e=>{const n=e&&typeof e=="object"?e:{x:0,y:0,z:0},t=((Number(n.x)||0)%1+1)%1,r=Math.min(1,Math.max(0,Number(n.y)||0)),o=Math.min(1,Math.max(0,Number(n.z)||0)),i=Math.floor(t*6),s=t*6-i,a=o*(1-r),c=o*(1-s*r),u=o*(1-(1-s)*r),f=[[o,u,a],[c,o,a],[a,o,u],[a,c,o],[u,a,o],[o,a,c]][i%6];return{x:f[0],y:f[1],z:f[2]}},rgb2hsv:e=>{const n=e&&typeof e=="object"?e:{x:0,y:0,z:0},t=Number(n.x)||0,r=Number(n.y)||0,o=Number(n.z)||0,i=Math.max(t,r,o),s=Math.min(t,r,o),a=i-s;let c=0;return a>0&&(i===t?c=(r-o)/a/6:i===r?c=(2+(o-t)/a)/6:c=(4+(t-r)/a)/6,c<0&&(c+=1)),{x:c,y:i===0?0:a/i,z:i}}},$i={add:(e,n)=>({x:(e.x||0)+(n.x||0),y:(e.y||0)+(n.y||0),z:(e.z||0)+(n.z||0)}),subtract:(e,n)=>({x:(e.x||0)-(n.x||0),y:(e.y||0)-(n.y||0),z:(e.z||0)-(n.z||0)}),scale:(e,n)=>({x:(e.x||0)*n,y:(e.y||0)*n,z:(e.z||0)*n}),length:e=>Math.hypot(e.x||0,e.y||0,e.z||0),dot:(e,n)=>(e.x||0)*(n.x||0)+(e.y||0)*(n.y||0)+(e.z||0)*(n.z||0),normalize:e=>{const n=Math.hypot(e.x||0,e.y||0,e.z||0)||1;return{x:(e.x||0)/n,y:(e.y||0)/n,z:(e.z||0)/n}},mix:(e,n,t)=>({x:(e.x||0)+((n.x||0)-(e.x||0))*t,y:(e.y||0)+((n.y||0)-(e.y||0))*t,z:(e.z||0)+((n.z||0)-(e.z||0))*t})},ji=Object.freeze({PLAYBACK_STOPPED:0,PLAYBACK_PLAYING:1,PLAYBACK_PAUSED:2}),pr=["mediaPropertiesChanged","mediaThumbnailChanged","mediaPlaybackChanged","mediaTimelineChanged","mediaStatusChanged","mediaLyricsChanged"],Ic=["scriptProperties","engine","WEMath","WEColor","WEVector","createScriptProperties","shared","console","process","globalThis","self","window","document","require","module","exports","fetch","XMLHttpRequest","Worker","importScripts","location","navigator","alert","confirm","prompt","setTimeout","setInterval","clearTimeout","clearInterval","requestAnimationFrame","cancelAnimationFrame","performance","Function","Vec3","Vec2","input","thisLayer","thisScene","thisObject","localStorage","MediaPlaybackEvent"],Oc=new RegExp(`(^[ \\t]*|;|\\})[ \\t]*(?:var|let|const)[ \\t]+(?=(?:${Ic.join("|")})\\b)`,"gm"),$c={WEMath:!0,WEColor:!0,WEVector:!0};function zi(e){return typeof e!="string"?e:e.replace(/([!=])==(\s*)(['"])(-?\d+)\3/g,"$1=$2$3$4$3")}function Wi(e){return zi(e).replace(/\bimport\s*\*\s*as\s+(\w+)\s+from\s*['"]([^'"]+)['"]\s*;?/g,(n,t,r)=>{const o=String(r);return $c[o]?t===o?"":`var ${t} = ${o};`:`var ${t} = {};`}).replace(/(^[ \t]*|;|\})[ \t]*import\s+(?:[^;'"]+\s+from\s+)?['"][^'"]*['"];?[ \t]*/gm,"$1").replace(/(^[ \t]*|;|\})[ \t]*export[ \t]+(?=(?:async[ \t]+)?function\b|(?:var|let|const)\b)/gm,"$1").replace(Oc,"$1")}function In(e){return e!==null&&typeof e=="object"&&"value"in e?e.value:e}function Vi(e){const n=e||{width:1920,height:1080};return n.x!==void 0&&n.y!==void 0?n:{x:n.width,y:n.height,width:n.width,height:n.height}}function jc(e,n,t={}){if(typeof e!="string"||e.length===0)return null;const r=Wi(e);if(r===e&&e.indexOf("update")<0)return null;const o={};if(n&&typeof n=="object")for(const[M,h]of Object.entries(n))o[M]=In(h);const i=new Proxy(()=>i,{apply(){return i},get(M,h){if(h==="finish")return()=>o;if(typeof h=="string"&&Ri.test(h))return g=>(g&&typeof g=="object"&&typeof g.name=="string"&&!(g.name in o)&&(o[g.name]=In(g.value)),i)}}),s={text:t.text!==void 0&&t.text!==null?String(t.text):"",font:t.font||"",pointsize:t.pointsize||24,color:(t.color||[1,1,1]).slice(),angles:(t.angles||[0,0,0]).slice(),scale:(t.scale||[1,1,1]).slice(),visible:t.visible!==!1,origin:mr(t.origin||[0,0,0])},a={registerAsset:()=>{},frametime:1/60,runtime:0,canvasSize:Vi(t.canvasSize),screenResolution:t.screenResolution||{x:1920,y:1080},timeOfDay:typeof t.timeOfDay=="number"?t.timeOfDay:0,userProperties:t.userProperties||{},AUDIO_RESOLUTION_16:16,AUDIO_RESOLUTION_32:32,AUDIO_RESOLUTION_64:64,setTimeout:t.setTimeout||xn,clearTimeout:t.clearTimeout||(()=>{}),setInterval:t.setInterval||xn,clearInterval:t.clearInterval||(()=>{}),openUserShortcut:t.openUserShortcut||(()=>{}),isRunningInEditor:!!t.isRunningInEditor,isScreensaver:!!t.isScreensaver};Ni(a,t);const c=t.audioViews;a.registerAudioBuffers=M=>{const h=Math.max(1,Math.min(64,Math.floor(Number(M)||0)));let g=c?c.get(h):void 0;return g||(g={left:new Float32Array(h),right:new Float32Array(h),average:new Float32Array(h)},c&&c.set(h,g)),g};const u={getLayer(M){const h=t.getLayerText?t.getLayerText(String(M)):void 0;return{text:h!=null?String(h):""}},createLayer(M){return{text:"",visible:!1,color:[0,0,0],alpha:1,pointsize:t.pointsize||24,font:t.font||"",origin:mr(t.origin||[0,0,0]),angles:[0,0,0],scale:[1,1,1]}},sortLayer:()=>{},getLayerIndex:()=>0},l=t.shared||{},f={console:ki()},p=Bi(t.inputView);let d;try{d=new Function("scriptProperties","engine","thisLayer","thisScene","WEMath","WEColor","WEVector","createScriptProperties","shared","console","process","globalThis","self","window","document","require","module","exports","fetch","XMLHttpRequest","Worker","importScripts","location","navigator","alert","confirm","prompt","setTimeout","setInterval","clearTimeout","clearInterval","requestAnimationFrame","cancelAnimationFrame","performance","Function","Vec3","Vec2","input","MediaPlaybackEvent",`"use strict";
|
|
178
|
-
`+r+`
|
|
179
|
-
;return {update: typeof update === "function" ? update : null,init: typeof init === "function" ? init : null,applyUserProperties: typeof applyUserProperties === "function" ? applyUserProperties : null,cursorClick: typeof cursorClick === "function" ? cursorClick : null,cursorEnter: typeof cursorEnter === "function" ? cursorEnter : null,cursorLeave: typeof cursorLeave === "function" ? cursorLeave : null,cursorDown: typeof cursorDown === "function" ? cursorDown : null,cursorUp: typeof cursorUp === "function" ? cursorUp : null,cursorMove: typeof cursorMove === "function" ? cursorMove : null,`+pr.map(h=>`${h}: typeof ${h} === "function" ? ${h} : null,`).join("")+"dummy_: 0};")(o,Fi(a),s,u,Ii,Oi,$i,i,l,f.console,void 0,f,f,f,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,me,Ui,p,ji)}catch(M){return t.onError&&t.onError(M,"parse"),null}const y=!!(d&&pr.some(M=>d[M])),x=!!(d&&typeof d.applyUserProperties=="function");if(!d||!d.update&&!y&&!x)return null;const m={engine:a,thisLayer:s,scriptProperties:o,hasUpdate:!!d.update,hasCursorHook:!!(d.cursorClick||d.cursorEnter||d.cursorLeave||d.cursorDown||d.cursorUp||d.cursorMove),hasMediaHook:y,hasApplyHook:x,errCount:0,disabled:!1,init(M){if(d.init)try{d.init(M)}catch(h){m.errCount++,t.onError&&t.onError(h,"init")}},applyUserProperties(M){if(d.applyUserProperties)try{d.applyUserProperties(M||{})}catch(h){m.errCount++,t.onError&&t.onError(h,"applyUserProperties")}},callUpdateRaw(M){if(!(!d.update||m.disabled))try{return d.update(M)}catch(h){m.errCount++,t.onError&&t.onError(h,"update"),m.errCount>=3&&(m.disabled=!0);return}},callUpdate(M){if(!d.update||m.disabled)return null;const h=s.text;let g;try{g=d.update(h!==""?h:M!==void 0?M:"")}catch(v){return m.errCount++,t.onError&&t.onError(v,"update"),m.errCount>=3&&(m.disabled=!0),null}return typeof g=="string"?(s.text=g,g):typeof g=="boolean"?null:g!=null?(s.text=String(g),s.text):s.text!==h?s.text:null},callCursor(M,h){if(m.disabled)return;const g=d[M];if(typeof g=="function")try{return g(h)}catch(v){m.errCount++,t.onError&&t.onError(v,M),m.errCount>=3&&(m.disabled=!0);return}},callMedia(M,h){if(m.disabled)return;const g=d[M];if(typeof g=="function")try{return g(h)}catch(v){m.errCount++,t.onError&&t.onError(v,M),m.errCount>=3&&(m.disabled=!0);return}}};return m}function On(){const e={play:()=>e,pause:()=>e,stop:()=>e,setFrame:()=>e,setRate:()=>e,setBlend:()=>e,setVisible:()=>e,isPlaying:Object.assign(()=>!1,{valueOf:()=>!1,toString:()=>"false"}),get frame(){return 0},get frameCount(){return 0},get rate(){return 1}};return e}function zc(e){if(!e)return On();if(e.textureAnimation)return e.textureAnimation.api;const n={frame:null,playing:!0,rate:1},t={play:()=>(n.playing=!0,t),pause:()=>(n.playing=!1,t),stop:()=>(n.playing=!1,t),setFrame:r=>{const o=Number(r);return n.frame=Number.isFinite(o)?o:0,t},setRate:r=>{const o=Number(r);return Number.isFinite(o)&&(n.rate=o),t},setBlend:()=>t,setVisible:r=>(e.visible=!!r,t),isPlaying:Object.assign(()=>n.playing,{valueOf:()=>n.playing,toString:()=>String(n.playing)}),get frame(){return n.frame===null?0:n.frame},get frameCount(){return e.spriteFrameCount||0},get rate(){return n.rate}};return n.api=t,e.textureAnimation=n,t}function Wc(e){if(e&&e.videoTextureApi)return e.videoTextureApi;const n=()=>e&&e.videoCtl||null,t={get duration(){const r=n(),o=r&&typeof r.duration=="function"?r.duration():0;return Number.isFinite(o)?o:0},get rate(){const r=n(),o=r&&typeof r.getRate=="function"?r.getRate():1;return Number.isFinite(o)&&o>0?o:1},set rate(r){const o=n(),i=Number(r);o&&typeof o.setRate=="function"&&Number.isFinite(i)&&o.setRate(i)},get loop(){const r=n();return r&&typeof r.getLoop=="function"?!!r.getLoop():!0},set loop(r){const o=n();o&&typeof o.setLoop=="function"&&o.setLoop(!!r)},play:()=>{const r=n();r&&r.play&&r.play()},pause:()=>{const r=n();r&&r.pause&&r.pause()},stop:()=>{const r=n();r&&r.stop&&r.stop()},isPlaying:Object.assign(()=>{const r=n();return!!(r&&typeof r.isPlaying=="function"&&r.isPlaying())},{valueOf(){const r=n();return!!(r&&typeof r.isPlaying=="function"&&r.isPlaying())},toString(){const r=n();return String(!!(r&&typeof r.isPlaying=="function"&&r.isPlaying()))}}),getCurrentTime:()=>{const r=n(),o=r&&typeof r.getCurrentTime=="function"?r.getCurrentTime():0;return Number.isFinite(o)?o:0},setCurrentTime:r=>{const o=n(),i=Number(r);o&&typeof o.setCurrentTime=="function"&&Number.isFinite(i)&&o.setCurrentTime(i)},addEndedCallback:r=>{const o=n();typeof r=="function"&&o&&typeof o.addEndedCallback=="function"&&o.addEndedCallback(r)}};return e&&(e.videoTextureApi=t),t}function Vc(){const e=new Map,n=r=>e.has(String(r))?e.get(String(r)):null,t=(r,o)=>{e.set(String(r),String(o))};return{getItem:n,setItem:t,get:n,set:t,removeItem:r=>{e.delete(String(r))},remove:r=>{e.delete(String(r))},clear:()=>{e.clear()},key:r=>Array.from(e.keys())[r]??null,get length(){return e.size}}}function Hc(e,n){const t=e&&e.puppet,r=t&&t.bones||null,o=r?r.length:0,i=e&&e.origin||[0,0,0],s=e&&e.scale||[1,1,1],a=s[0]||1,c=s[1]||1,u=(y,x)=>[i[0]+y*a,i[1]-x*c],l=(y,x)=>[(y-i[0])/a,-(x-i[1])/c],f=y=>{const x=n.get(y);if(x)return[x[0],x[1],x[2]];const m=r[y].matrix;return[m[12],m[13],m[14]]},p=y=>{let x=0,m=0,M=y;for(let h=0;M>=0&&M<o&&h<64;h++){const g=f(M);x+=g[0],m+=g[1],M=r[M].parent}return u(x,m)},d=y=>{const x={translation(m){if(m===void 0){const A=p(y);return new me(A[0],A[1],0)}const M=qt(m);let h=0,g=0;if(r[y].parent>=0){const A=p(r[y].parent),_=l(A[0],A[1]);h=_[0],g=_[1]}const v=l(M[0],M[1]);return n.set(y,[v[0]-h,v[1]-g,0]),x},rotation(){return x},scale(){return x}};return x};return{getBoneCount:()=>o,getBoneTransform:y=>{const x=Math.floor(Number(y));if(!r||!(x>=0)||x>=o){const m={translation(M){return M===void 0?new me(0,0,0):m},rotation(){return m},scale(){return m}};return m}return d(x)},setBoneTransform:(y,x)=>{const m=Math.floor(Number(y));!r||!(m>=0)||m>=o},applyBonePhysicsImpulse:()=>{}}}function ao(e){return{get visible(){return e?!!e.visible:!1},set visible(n){e&&(e.visible=!!n)},get name(){return e&&e.name||""},getMaterial:()=>null}}function Hi(e,n){if(e==null)return null;const t=r=>{if(!r)return null;if(n&&typeof n.getSceneLayer=="function"){const o=n.getSceneLayer(String(r));if(o)return o}return n&&n.layer&&n.layer.name===r?n.layer:null};return t(typeof e=="object"?e.name:String(e))}function Xc(e,n){e&&(e.visibleSelf=!1,e.visible=!1,e.destroyed=!0,n&&typeof n.recomputeVisibility=="function"&&n.recomputeVisibility())}function Xi(e,n){if(typeof e!="string"||!e||/\/workshop\//.test(e))return e;const t=n!=null&&n!==""?String(n):"";if(!t)return e;const r=e.match(/^(models|materials|shaders|particles|effects)\/(.+)$/);return r?`${r[1]}/workshop/${t}/${r[2]}`:e}function Gc(e){if(typeof e!="string")return null;const n=e.match(/export\s+let\s+__workshopId\s*=\s*['"](\d+)['"]/);return n?n[1]:null}function Yc(e){const n=t=>hr(t||null,e);return{getLayer(t){if(e.getSceneLayer){const r=e.getSceneLayer(String(t));if(r&&!r.destroyed)return n(r)}return n(null)},createLayer(t){if(typeof e.createSceneLayer!="function")return n(null);let r=t;if(typeof t=="string"){const i=typeof e.getWorkshopId=="function"?e.getWorkshopId():e.workshopId;r=Xi(t,i)}const o=e.createSceneLayer(r);return n(o||null)},destroyLayer(t){Xc(Hi(t,e),e)},sortLayer:()=>{},getLayerIndex(t){const r=typeof e.enumerateSceneLayers=="function"?e.enumerateSceneLayers():[],o=t&&typeof t=="object"?t.name:String(t||""),i=r.findIndex(s=>s&&s.name===o);return i<0?0:i},enumerateLayers(){const t=typeof e.enumerateSceneLayers=="function"?e.enumerateSceneLayers():[],r=[];for(const o of t)o&&!o.destroyed&&r.push(n(o));return r},getAnimation(t){if(typeof e.getSceneAnimation=="function"){const r=e.getSceneAnimation(t);if(r)return r}return On()},getCameraTransforms(){const t=e.cameraTransforms||{zoom:1};return{zoom:typeof t.zoom=="number"?t.zoom:1,center:t.center||null,eye:t.eye||null,parallaxAmount:typeof t.parallaxAmount=="number"?t.parallaxAmount:0}},setCameraTransforms(t){const r=e.cameraTransforms;!r||!t||typeof t!="object"||(typeof t.zoom=="number"&&Number.isFinite(t.zoom)&&t.zoom>0&&(r.zoom=t.zoom),t.center!==void 0&&(r.center=t.center),t.eye!==void 0&&(r.eye=t.eye),typeof t.parallaxAmount=="number"&&(r.parallaxAmount=t.parallaxAmount))},getInitialLayerConfig(t){return typeof e.getInitialLayerConfig=="function"?e.getInitialLayerConfig(t):Hi(t,e)||null}}}function hr(e,n){const t=s=>mr(Array.isArray(s)?s:[0,0,0]),r=n&&typeof n.getBoneOverrides=="function"&&e?n.getBoneOverrides(e):null,o={origin:t(e?e.origin:[0,0,0]),scale:t(e?e.scale:[1,1,1]),angles:Kc(e),size:t(e?e.size:[0,0,0]),color:t(e?e.color:[1,1,1])},i={get name(){return e&&e.name||""},get id(){return e&&e.id||0},get visible(){const s=n&&n.targetEffect;return s?!!s.visible:e?e.visibleSelf!==void 0?!!e.visibleSelf:!!e.visible:!1},set visible(s){const a=n&&n.targetEffect;if(a){a.visible=!!s;return}e&&(e.visibleSelf=!!s,typeof n.recomputeVisibility=="function"?n.recomputeVisibility():e.visible=!!s)},get alpha(){return e&&typeof e.alpha=="number"?e.alpha:1},set alpha(s){e&&(e.alpha=Number(s)||0)},get brightness(){return e&&typeof e.brightness=="number"?e.brightness:1},set brightness(s){e&&(e.brightness=Number(s)||0)},get text(){return e&&e.text!==void 0?String(e.text):""},set text(s){e&&typeof s!="boolean"&&(e.text=s==null?"":String(s))},get pointsize(){return e&&e.textPointsize||24},set pointsize(s){e&&(e.textPointsize=Number(s)||24)},get font(){return e&&e.textFont||""},set font(s){e&&(e.textFont=String(s||""))},get alignment(){return e&&e.alignment||"center"},set alignment(s){if(!e)return;const a=String(s||"center").toLowerCase();e.alignment=a==="centre"?"center":a},...e&&e.puppet&&r?Hc(e,r):{getBoneCount:()=>0,getBoneTransform:()=>{const s={translation(a){return a===void 0?new me(0,0,0):s},rotation(){return s},scale(){return s}};return s},setBoneTransform:()=>{},applyBonePhysicsImpulse:()=>{}},getParent:()=>{if(!e||e.parentId==null)return null;const s=n&&typeof n.getSceneLayerById=="function"?n.getSceneLayerById(e.parentId):null;return!s||s.destroyed?null:hr(s,n)},getChildren:()=>{const s=e&&e.childIds||[];if(!s.length)return[];const a=n&&typeof n.getSceneLayerById=="function"?n.getSceneLayerById:null;if(!a)return[];const c=[];for(const u of s){const l=a(u);l&&!l.destroyed&&c.push(hr(l,n))}return c},getAnimation:s=>{const a=e&&e.animations,c=e&&e.animationList||[];return s==null||s===""?c[0]||On():a&&a[s]?a[s]:typeof s=="number"&&c[s]?c[s]:typeof s=="string"&&/^\d+$/.test(s)&&c[Number(s)]?c[Number(s)]:On()},getAnimationLayer:s=>{const a=e&&e.animations,c=e&&e.animationList||[];return a&&a[s]?a[s]:typeof s=="number"&&c[s]?c[s]:typeof s=="string"&&/^\d+$/.test(s)&&c[Number(s)]?c[Number(s)]:On()},getAnimationLayerCount:()=>(e&&e.animationList||[]).length,getTextureAnimation:()=>zc(e),play:()=>{e&&e.soundCtl&&e.soundCtl.play&&e.soundCtl.play(),e&&e.videoCtl&&e.videoCtl.play&&e.videoCtl.play()},pause:()=>{e&&e.soundCtl&&e.soundCtl.pause&&e.soundCtl.pause(),e&&e.videoCtl&&e.videoCtl.pause&&e.videoCtl.pause()},stop:()=>{e&&e.soundCtl&&e.soundCtl.stop&&e.soundCtl.stop(),e&&e.videoCtl&&e.videoCtl.stop&&e.videoCtl.stop()},isPlaying:Object.assign(()=>{const s=e&&e.soundCtl&&typeof e.soundCtl.isPlaying=="function"&&e.soundCtl.isPlaying(),a=e&&e.videoCtl&&typeof e.videoCtl.isPlaying=="function"&&e.videoCtl.isPlaying();return!!(s||a)},{valueOf(){const s=e&&e.soundCtl&&typeof e.soundCtl.isPlaying=="function"&&e.soundCtl.isPlaying(),a=e&&e.videoCtl&&typeof e.videoCtl.isPlaying=="function"&&e.videoCtl.isPlaying();return!!(s||a)},toString(){const s=e&&e.soundCtl&&typeof e.soundCtl.isPlaying=="function"&&e.soundCtl.isPlaying(),a=e&&e.videoCtl&&typeof e.videoCtl.isPlaying=="function"&&e.videoCtl.isPlaying();return String(!!(s||a))}}),get volume(){if(e&&e.soundCtl&&typeof e.soundCtl.getVolume=="function")return e.soundCtl.getVolume();const s=e&&e.soundprops&&e.soundprops.volume;return typeof s=="number"?s:1},set volume(s){const a=Number(s);if(!Number.isFinite(a)||!e)return;const c=Math.max(0,Math.min(1,a));e.soundprops&&(e.soundprops.volume=c),e.soundCtl&&typeof e.soundCtl.setVolume=="function"&&e.soundCtl.setVolume(c)},getVideoTexture:()=>Wc(e),getTransformMatrix:()=>{const s=e&&e.origin||[0,0,0],a=new Float32Array(16);return a[0]=1,a[5]=1,a[10]=1,a[15]=1,a[12]=s[0]||0,a[13]=s[1]||0,a[14]=s[2]||0,{m:a}},getEffect:s=>{const a=e&&e.effects||null;if(!a||a.length===0)return ao(null);if(typeof s=="number"||typeof s=="string"&&/^\d+$/.test(s))return ao(a[Number(s)]||null);const c=String(s);return ao(a.find(u=>u&&u.name===c)||null)}};Object.defineProperty(i,"angles",{enumerable:!0,get(){return o.angles},set(s){if(e&&Array.isArray(e.angles)){const a=Gi(s);e.angles[0]=a[0],e.angles[1]=a[1],e.angles[2]=a[2]}}});for(const s of["origin","scale","size","color"])Object.defineProperty(i,s,{enumerable:!0,get(){const a=e&&Array.isArray(e[s])?e[s]:null;return mr(a||[0,0,0])},set(a){const c=qt(a);o[s].x=c[0],o[s].y=c[1],o[s].z=c[2],e&&Array.isArray(e[s])&&s!=="size"&&(e[s][0]=c[0],e[s][1]=c[1],e[s][2]=c[2])}});return i}function qc(e,n,t={}){if(typeof e!="string"||e.length===0)return null;const r=Wi(e),o={};if(n&&typeof n=="object")for(const[A,_]of Object.entries(n))if(_!==null&&typeof _=="object"&&typeof _.user=="string"){const R=t.userProperties?t.userProperties[_.user]:void 0;o[A]=R!==void 0?R:In(_)}else o[A]=In(_);const i=new Proxy(()=>i,{apply(){return i},get(A,_){if(_==="finish")return()=>o;if(typeof _=="string"&&Ri.test(_))return R=>(R&&typeof R=="object"&&typeof R.name=="string"&&!(R.name in o)&&(o[R.name]=In(R.value)),i)}}),s={registerAsset:()=>{},frametime:1/60,runtime:0,canvasSize:Vi(t.canvasSize),screenResolution:t.screenResolution||{x:1920,y:1080},timeOfDay:typeof t.timeOfDay=="number"?t.timeOfDay:0,userProperties:t.userProperties||{},AUDIO_RESOLUTION_16:16,AUDIO_RESOLUTION_32:32,AUDIO_RESOLUTION_64:64,setTimeout:t.setTimeout||xn,clearTimeout:t.clearTimeout||(()=>{}),setInterval:t.setInterval||xn,clearInterval:t.clearInterval||(()=>{}),openUserShortcut:t.openUserShortcut||(()=>{}),isRunningInEditor:!!t.isRunningInEditor,isScreensaver:!!t.isScreensaver};Ni(s,t);const a=t.audioViews;s.registerAudioBuffers=A=>{const _=Math.max(1,Math.min(64,Math.floor(Number(A)||0)));let R=a?a.get(_):void 0;return R||(R={left:new Float32Array(_),right:new Float32Array(_),average:new Float32Array(_)},a&&a.set(_,R)),R};const c=t.shared||{},u={console:ki()},l=Bi(t.inputView),f=t.layer||null,p=t.workshopId!=null?t.workshopId:Gc(e),d=hr(f,t),y=Yc({...t,workshopId:p,getWorkshopId:()=>p});let x;try{x=new Function("scriptProperties","engine","WEMath","WEColor","WEVector","createScriptProperties","shared","console","process","globalThis","self","window","document","require","module","exports","fetch","XMLHttpRequest","Worker","importScripts","location","navigator","alert","confirm","prompt","setTimeout","setInterval","clearTimeout","clearInterval","requestAnimationFrame","cancelAnimationFrame","performance","Function","Vec3","Vec2","input","thisLayer","thisScene","thisObject","localStorage","MediaPlaybackEvent",`"use strict";
|
|
180
|
-
`+r+`
|
|
181
|
-
;return {update: typeof update === "function" ? update : null,init: typeof init === "function" ? init : null,applyUserProperties: typeof applyUserProperties === "function" ? applyUserProperties : null,cursorClick: typeof cursorClick === "function" ? cursorClick : null,cursorEnter: typeof cursorEnter === "function" ? cursorEnter : null,cursorLeave: typeof cursorLeave === "function" ? cursorLeave : null,cursorDown: typeof cursorDown === "function" ? cursorDown : null,cursorUp: typeof cursorUp === "function" ? cursorUp : null,cursorMove: typeof cursorMove === "function" ? cursorMove : null,`+pr.map(_=>`${_}: typeof ${_} === "function" ? ${_} : null,`).join("")+"dummy_: 0};")(o,Fi(s),Ii,Oi,$i,i,c,u.console,void 0,u,u,u,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,void 0,me,Ui,l,d,y,d,Vc(),ji)}catch(A){return t.onError&&t.onError(A,"parse"),null}const m=!!(x&&(x.cursorClick||x.cursorEnter||x.cursorLeave||x.cursorDown||x.cursorUp||x.cursorMove)),M=!!(x&&pr.some(A=>x[A])),h=!!(x&&typeof x.applyUserProperties=="function"),g=/\bengine\s*\.\s*(runtime|frametime)\b/.test(r);if(!x||!x.update&&!m&&!M&&!h&&!g)return null;const v={engine:s,scriptProperties:o,hasUpdate:!!x.update,hasCursorHook:m,hasApplyHook:h,errCount:0,disabled:!1,init(A){if(x.init)try{x.init(Di(A))}catch(_){v.errCount++,t.onError&&t.onError(_,"init")}},applyUserProperties(A){if(x.applyUserProperties)try{x.applyUserProperties(A||{})}catch(_){v.errCount++,t.onError&&t.onError(_,"applyUserProperties")}},callUpdate(A){if(v.disabled||!x.update)return;let _;try{_=x.update(Di(A))}catch(R){v.errCount++,t.onError&&t.onError(R,"update"),v.errCount>=3&&(v.disabled=!0);return}return _},hasCursorHook:m,callCursor(A,_){if(v.disabled)return;const R=x[A];if(typeof R=="function")try{return R(_)}catch(L){v.errCount++,t.onError&&t.onError(L,A),v.errCount>=3&&(v.disabled=!0);return}},hasMediaHook:M,callMedia(A,_){if(v.disabled)return;const R=x[A];if(typeof R=="function")try{return R(_)}catch(L){v.errCount++,t.onError&&t.onError(L,A),v.errCount>=3&&(v.disabled=!0);return}}};return v}function mr(e){const n=Array.isArray(e)?e:[0,0,0],t={x:n[0]||0,y:n[1]||0,z:n[2]||0},r={get x(){return t.x},set x(o){t.x=Number(o)||0},get y(){return t.y},set y(o){t.y=Number(o)||0},get z(){return t.z},set z(o){t.z=Number(o)||0},add(o){const i=qt(o);return t.x+=i[0],t.y+=i[1],t.z+=i[2],r},subtract(o){const i=qt(o);return t.x-=i[0],t.y-=i[1],t.z-=i[2],r},multiply(o){if(o&&typeof o=="object"){const i=qt(o);t.x*=i[0],t.y*=i[1],t.z*=i[2]}else{const i=Number(o)||0;t.x*=i,t.y*=i,t.z*=i}return r},copy(){return new me(t.x,t.y,t.z)},length(){return Math.sqrt(t.x*t.x+t.y*t.y+t.z*t.z)},toArray(){return[t.x,t.y,t.z]}};return r}function qt(e){if(Array.isArray(e))return[e[0]||0,e[1]||0,e[2]||0];if(e&&typeof e=="object")return[e.x||0,e.y||0,e.z||0];const n=Number(e)||0;return[n,n,n]}const gr=Math.PI/180,br=180/Math.PI;function Zc(e){const n=Array.isArray(e)?e:[0,0,0];return{x:(n[0]||0)*br,y:(n[1]||0)*br,z:(n[2]||0)*br}}function Gi(e){const n=qt(e);return[n[0]*gr,n[1]*gr,n[2]*gr]}function Kc(e){const n={x:0,y:1,z:2},t={add(r){const o=qt(r);return t.x+=o[0],t.y+=o[1],t.z+=o[2],t},subtract(r){const o=qt(r);return t.x-=o[0],t.y-=o[1],t.z-=o[2],t},multiply(r){return t.x*=r,t.y*=r,t.z*=r,t},toArray(){return[t.x,t.y,t.z]}};for(const r of["x","y","z"])Object.defineProperty(t,r,{enumerable:!0,get(){return!e||!Array.isArray(e.angles)?0:(e.angles[n[r]]||0)*br},set(o){!e||!Array.isArray(e.angles)||(e.angles[n[r]]=(Number(o)||0)*gr)}});return t}function Qc(e,n){return Math.min(256,Math.ceil(Math.max(1,Number(e)||1)*2+8))}function Jc(e){for(const n of e&&e.effects?e.effects:[]){if(n&&n.visible===!1)continue;if(String(n&&(n.file||n.name)||"").includes("tint"))return!0;for(const r of n&&n.passes||[])for(const o of r&&r.textures||[])if(o&&String(o).toLowerCase().includes("mask"))return!0}return!1}const el=Object.freeze(Object.defineProperty({__proto__:null,createInputView:Bc,drawTextLayer:Uc,effectiveTextPadding:Li,evalObjectScript:qc,evalTextScript:jc,layoutText:Nc,makeCursorEventVec:Dc,radToScriptAngles:Zc,resolveWorkshopAssetPath:Xi,rewriteComboStringEq:zi,scriptAnglesToRad:Gi,textCanvasMargin:Qc,textLayerHasTintMask:Jc},Symbol.toStringTag,{value:"Module"}));function tl(e={},n={}){const t=typeof e.setTimeout=="function"?e.setTimeout:null,r=typeof e.clearTimeout=="function"?e.clearTimeout:null,o=typeof e.setInterval=="function"?e.setInterval:null,i=typeof e.clearInterval=="function"?e.clearInterval:null,s=typeof n.onError=="function"?n.onError:null,a=new Set,c=m=>{const M=Number(m);return Number.isFinite(M)&&M>0?M:0},u=m=>()=>{try{m()}catch(M){s&&s(M,"timer")}},l=(m,M)=>{const h=()=>{m.fired||(m.fired=!0,a.delete(h),M&&m.handle!=null&&M(m.handle))};return h.handle=null,h.valueOf=()=>typeof m.handle=="number"?m.handle:0,h};function f(m,M){if(typeof m!="function")return l({fired:!0,handle:null},null);const h={fired:!1,handle:null},g=l(h,r);return a.add(g),h.handle=t?t(u(()=>{h.fired=!0,a.delete(g),m()}),c(M)):null,g.handle=h.handle,g}function p(m,M){if(typeof m!="function")return l({fired:!0,handle:null},null);const h={fired:!1,handle:null},g=l(h,i);return a.add(g),h.handle=o?o(u(m),c(M)):null,g.handle=h.handle,g}function d(m){if(typeof m=="function"){m();return}r&&m!=null&&r(m)}function y(m){if(typeof m=="function"){m();return}i&&m!=null&&i(m)}function x(){for(const m of[...a])m();a.clear()}return{setTimeout:f,setInterval:p,clearTimeout:d,clearInterval:y,dispose:x,pendingCount:()=>a.size}}const nl=Object.freeze(Object.defineProperty({__proto__:null,createEngineTimers:tl},Symbol.toStringTag,{value:"Module"}));function rl(e){let n=e>>>0;return function(){n|=0,n=n+1831565813|0;let t=Math.imul(n^n>>>15,1|n);return t=t+Math.imul(t^t>>>7,61|t)^t,((t^t>>>14)>>>0)/4294967296}}function co(e,n){const t=Math.floor(e),r=e-t,o=s=>{const a=Math.sin((s*127.1+n*311.7)*43758.5453)*43758.5453;return(a-Math.floor(a))*2-1},i=r*r*(3-2*r);return o(t)*(1-i)+o(t+1)*i}const ol=32,Yi=60/112,il=3.2;function sl(e){const n=new Float32Array(16),t=new Float32Array(16),r=new Float32Array(16);for(let o=0;o<16;o++)n[o]=o%4===0?1:o%4===2?.38+e()*.15:e()<.08?.5:0,t[o]=o%8===4?1:e()<.06?.6:0,r[o]=o%2===1?.5+e()*.4:o%4===0?.25:e()<.3?.3:0;return{kick:n,snare:t,hat:r}}function qi(e=20260830){const n=rl(e),t=sl(n),r=new Float32Array(64);for(let h=0;h<64;h++)r[h]=n()*64;const o=64,i=new Float32Array(o),s=new Float32Array(o),a=new Float32Array(o),c=new Float32Array(o),u=new Float32Array(o),l=new Float32Array(o),f=new Float32Array(32),p=new Float32Array(32),d=new Float32Array(16),y=new Float32Array(16),x={left64:u,right64:l,left32:f,right32:p,left16:d,right16:y,preL64:a,preR64:c,level:0,silent:!1};function m(h,g){const v=g.length/h.length;for(let A=0;A<h.length;A++){let _=0;const R=Math.floor(A*v),L=Math.floor((A+1)*v);for(let N=R;N<Math.max(R+1,L);N++)_+=g[N];h[A]=_/Math.max(1,L-R)}}function M(h){const g=h/Yi,v=g*4,A=Math.floor(v)%16,_=v-Math.floor(v),R=Math.exp(-_*Yi*14),L=h%ol,N=L>=27&&L<29,j=L>=29?(L-29)/3:0,H=L>=24&&L<27?1-(L-24)/3:0,K=N?0:j>0?j*j:H>0?0:1,O=N?0:H>0?.35:1,V=t.kick[A]*R*K,X=(t.snare[A]*R+t.hat[A]*R*.7)*K,ie=t.hat[A]*R*K,J=j>0?Math.pow(j,3)*(.4+.6*Math.abs(co(v*2,7))):0;let Z=0;for(let te=0;te<o;te++){const le=te/o,Ue=Math.pow(1-le*.85,1.6);let _e=O*(.5+.3*co(g*.5+r[te]*.05,te%8));if(_e*=.35+.65*le,le<.2&&(_e+=V*(1-le/.2)),le>=.12&&le<.62){const he=1-Math.abs(le-.34)/.28;he>0&&(_e+=X*.55*he)}le>=.45&&(_e+=ie*.5*((le-.45)/.55)),_e+=J*.5,_e*=Ue;const Ze=_e;_e=Math.min(1,_e*il);const Xe=.06+le*.2,De=co(g*.13+te*.35,11)*Xe;let Ke=Math.min(1,Math.max(0,_e*(1-De))),Be=Math.min(1,Math.max(0,_e*(1+De)));const ye=N?.012:0;i[te]=Math.max(ye,Ke),s[te]=Math.max(ye,Be),a[te]=Math.max(ye,Math.max(0,Ze*(1-De))),c[te]=Math.max(ye,Math.max(0,Ze*(1+De))),te<48&&(Z+=(i[te]+s[te])*.5)}return u.set(i),l.set(s),m(f,i),m(p,s),m(d,i),m(y,s),x.level=Math.min(1,Z/(48*1.2)),x.silent=N,x}return{update:M,snapshot:x,bands:o}}function al(e,n){for(const t of e.values()){Zi(t.left,n.left64),Zi(t.right,n.right64);for(let r=0;r<t.average.length;r++)t.average[r]=(t.left[r]+t.right[r])*.5}}function Zi(e,n){const t=n.length/e.length;for(let r=0;r<e.length;r++){let o=0;const i=Math.floor(r*t),s=Math.max(i+1,Math.floor((r+1)*t));for(let a=i;a<s;a++)o+=n[a];e[r]=o/(s-i)}}const Zt={STOPPED:0,PLAYING:1,PAUSED:2};class Re{constructor(n,t,r){this.x=Number(n)||0,this.y=Number(t)||0,this.z=Number(r)||0}add(n){return new Re(this.x+n.x,this.y+n.y,this.z+n.z)}subtract(n){return new Re(this.x-n.x,this.y-n.y,this.z-n.z)}multiply(n){if(n!==null&&typeof n=="object")return new Re(this.x*n.x,this.y*n.y,this.z*n.z);const t=Number(n)||0;return new Re(this.x*t,this.y*t,this.z*t)}divide(n){const t=Number(n)||1;return new Re(this.x/t,this.y/t,this.z/t)}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}copy(){return new Re(this.x,this.y,this.z)}toArray(){return[this.x,this.y,this.z]}}function cl(e,n,t){return new Re(e,n,t)}const ll=[{title:"\u591C\u822A\u661F",artist:"\u76F8\u4F4D\u8FC1\u79FB",album:"\u6DF1\u7A7A\u56DE\u58F0",albumArtist:"\u76F8\u4F4D\u8FC1\u79FB",duration:212,colors:{primary:[.24,.42,.86],secondary:[.12,.18,.42],tertiary:[.62,.74,.98],text:[.95,.97,1]},lyrics:[[0,"\u5728\u65E0\u5149\u7684\u822A\u9053\u4E0A"],[12,"\u6211\u4EEC\u53EA\u5E26\u8D70\u5F7C\u6B64\u7684\u540D\u5B57"],[26,"\u5F15\u64CE\u4F4E\u9E23\u50CF\u4E00\u53E5\u65E7\u8BFA\u8A00"],[41,"\u628A\u9ED1\u6697\u6298\u6210\u4E24\u534A"],[58,"\u591C\u822A\u661F\u554A"],[72,"\u522B\u5728\u4E2D\u9014\u7184\u706D"],[95,"\uFF08\u95F4\u594F\uFF09"],[126,"\u5982\u679C\u5750\u6807\u7EC8\u5C06\u5931\u6548"],[140,"\u5C31\u8BA9\u8F68\u8FF9\u81EA\u5DF1\u8BF4\u8BDD"],[158,"\u6211\u4EEC\u4E0D\u8FD4\u822A"],[176,"\u4E5F\u4E0D\u9057\u61BE"],[198,"\u2026\u2026"]]},{title:"Amber Lantern",artist:"Hollow Coast",album:"Tidewater",albumArtist:"Hollow Coast",duration:187,colors:{primary:[.93,.62,.24],secondary:[.44,.24,.1],tertiary:[.99,.82,.56],text:[1,.98,.93]},lyrics:[[0,"Salt on the window frame"],[14,"a lantern swinging slow"],[30,"you said the tide forgets"],[46,"but the harbour never does"],[63,"Amber lantern, burn a little longer"],[88,"(instrumental)"],[118,"Every rope remembers the knot"],[134,"every shore remembers the leaving"],[152,"burn a little longer"],[170,"for me"]]},{title:"\u82D4\u75D5",artist:"\u6797\u95F4\u7535\u53F0",album:"\u534A\u5C71\u96E8",albumArtist:"\u6797\u95F4\u7535\u53F0",duration:241,colors:{primary:[.3,.68,.44],secondary:[.1,.28,.2],tertiary:[.72,.92,.78],text:[.96,1,.97]},lyrics:[[0,"\u96E8\u505C\u5728\u7B2C\u4E09\u7EA7\u53F0\u9636"],[16,"\u82D4\u75D5\u722C\u6EE1\u4E86\u65E7\u95E8\u724C"],[33,"\u4F60\u8BF4\u6162\u4E00\u70B9\u4E5F\u6CA1\u5173\u7CFB"],[52,"\u5C71\u4E0D\u4F1A\u8D70"],[70,"\u800C\u6211\u4EEC\u6709\u7684\u662F\u65F6\u95F4"],[92,"\uFF08\u95F4\u594F\uFF09"],[130,"\u628A\u4F1E\u6536\u8D77\u6765\u5427"],[148,"\u8BA9\u6F6E\u6C14\u8BB0\u4F4F\u8FD9\u4E00\u523B"],[172,"\u6162\u4E00\u70B9"],[200,"\u771F\u7684\u6CA1\u5173\u7CFB"],[226,"\u2026\u2026"]]},{title:"Neon Ashes",artist:"VELVET//NULL",album:"Afterimage",albumArtist:"VELVET//NULL",duration:168,colors:{primary:[.86,.22,.58],secondary:[.3,.06,.22],tertiary:[.99,.64,.86],text:[1,.94,.98]},lyrics:[[0,"city bleeds into the lens"],[11,"we were only afterimage"],[24,"neon ashes on your coat"],[38,"nothing here stays lit"],[55,"burn out with me"],[76,"(drop)"],[104,"nothing here stays lit"],[122,"burn out with me"],[146,"\u2026"]]}],yr=3;function Ki(e=20260901){const n=ll,t=n.reduce((M,h)=>M+h.duration+yr,0),r={hasMedia:!1,state:Zt.STOPPED,title:"",artist:"",album:"",albumArtist:"",position:0,duration:0,hasThumbnail:!1,primaryColor:new Re(0,0,0),secondaryColor:new Re(0,0,0),tertiaryColor:new Re(0,0,0),textColor:new Re(1,1,1),highContrastColor:new Re(1,1,1),trackIndex:-1,lyrics:[],lyricLine:"",lyricIndex:-1};let o=0,i=!1,s=0,a=0;function c(M){let h=0;const g=(M%n.length+n.length)%n.length;for(let v=0;v<g;v++)h+=n[v].duration+yr;return h}function u(M){let h=t>0?M%t:0;h<0&&(h+=t);let g=-1,v=0,A=!1;for(let H=0;H<n.length;H++){const K=n[H].duration;if(h<K){g=H,v=h;break}if(h-=K,h<yr){g=H,v=K,A=!0;break}h-=yr}g<0&&(g=n.length-1,v=n[g].duration,A=!0);const _=n[g];r.hasMedia=!0,r.trackIndex=g,r.title=_.title,r.artist=_.artist,r.album=_.album,r.albumArtist=_.albumArtist,r.duration=_.duration,r.position=v;const R=_.duration>0?v/_.duration:0;i?r.state=Zt.PAUSED:A?r.state=Zt.STOPPED:R>.7&&R<.76?r.state=Zt.PAUSED:r.state=Zt.PLAYING,r.hasThumbnail=!A;const L=_.colors;r.primaryColor=new Re(L.primary[0],L.primary[1],L.primary[2]),r.secondaryColor=new Re(L.secondary[0],L.secondary[1],L.secondary[2]),r.tertiaryColor=new Re(L.tertiary[0],L.tertiary[1],L.tertiary[2]),r.textColor=new Re(L.text[0],L.text[1],L.text[2]);const N=.2126*L.primary[0]+.7152*L.primary[1]+.0722*L.primary[2];r.highContrastColor=N>.5?new Re(0,0,0):new Re(1,1,1),r.lyrics=_.lyrics;let j=-1;for(let H=0;H<_.lyrics.length;H++)v>=_.lyrics[H][0]&&(j=H);return r.lyricIndex=j,r.lyricLine=j>=0?_.lyrics[j][1]:"",r}function l(M){a=Number(M)||0;const h=i?s:a+o;return u(h)}function f(M){i=!1;const h=c(M);return o=h-a,u(h)}function p(){const M=r.trackIndex<0?0:r.trackIndex+1;return f(M)}function d(){const M=r.trackIndex<0?n.length-1:r.trackIndex-1;return f(M)}function y(){return i||(s=a+o,i=!0,r.state=Zt.PAUSED),r}function x(){return i?(i=!1,o=s-a,u(s)):r}function m(){return i?x():y()}return{update:l,snapshot:r,tracks:n,cycle:t,MEDIA_PLAYBACK:Zt,skipNext:p,skipPrevious:d,play:x,pause:y,playPause:m}}function ul(e,n=512){const t=Math.max(8,n|0),r=new Uint8Array(t*t*4),o=e&&e.colors?e.colors:{primary:[.5,.5,.5],secondary:[.1,.1,.1],tertiary:[.8,.8,.8]},[i,s,a]=o.primary,[c,u,l]=o.secondary,[f,p,d]=o.tertiary;for(let y=0;y<t;y++)for(let x=0;x<t;x++){const m=x/(t-1),M=y/(t-1),h=m-.5,g=M-.5,v=Math.sqrt(h*h+g*g)*2,A=.5+.5*Math.sin(v*18-1.2),_=.5+.5*Math.sin((m+M)*6),R=Math.min(1,Math.max(0,v));let L=i*(1-R)+c*R,N=s*(1-R)+u*R,j=a*(1-R)+l*R;L=L*(.72+.28*A)+f*.18*_,N=N*(.72+.28*A)+p*.18*_,j=j*(.72+.28*A)+d*.18*_;const H=1-.35*Math.min(1,v*v),K=(y*t+x)*4;r[K]=Math.max(0,Math.min(255,Math.round(L*H*255))),r[K+1]=Math.max(0,Math.min(255,Math.round(N*H*255))),r[K+2]=Math.max(0,Math.min(255,Math.round(j*H*255))),r[K+3]=255}return{width:t,height:t,rgba:r}}function fl(e,n){const t=[];if(!n)return t;const r=!e;return(r||e.hasMedia!==n.hasMedia)&&t.push({name:"mediaStatusChanged",event:{enabled:n.hasMedia}}),(r||e.title!==n.title||e.artist!==n.artist||e.album!==n.album||e.albumArtist!==n.albumArtist)&&t.push({name:"mediaPropertiesChanged",event:{title:n.title,artist:n.artist,album:n.album,albumArtist:n.albumArtist,albumTitle:n.album,subTitle:"",trackType:"music"}}),(r||e.hasThumbnail!==n.hasThumbnail||e.trackIndex!==n.trackIndex)&&t.push({name:"mediaThumbnailChanged",event:{hasThumbnail:n.hasThumbnail,primaryColor:n.primaryColor,secondaryColor:n.secondaryColor,tertiaryColor:n.tertiaryColor,textColor:n.textColor,highContrastColor:n.highContrastColor}}),(r||e.state!==n.state)&&t.push({name:"mediaPlaybackChanged",event:{state:n.state}}),(r||Math.floor(e.position)!==Math.floor(n.position)||e.duration!==n.duration)&&t.push({name:"mediaTimelineChanged",event:{position:n.position,duration:n.duration}}),(r||e.lyricIndex!==n.lyricIndex||e.trackIndex!==n.trackIndex)&&t.push({name:"mediaLyricsChanged",event:{line:n.lyricLine,index:n.lyricIndex,lines:n.lyrics}}),t}function dl(e){return e?{hasMedia:e.hasMedia,state:e.state,title:e.title,artist:e.artist,album:e.album,albumArtist:e.albumArtist,position:e.position,duration:e.duration,hasThumbnail:e.hasThumbnail,trackIndex:e.trackIndex,lyricIndex:e.lyricIndex,lyricLine:e.lyricLine}:null}const pl=Object.freeze(Object.defineProperty({__proto__:null,MEDIA_PLAYBACK:Zt,cloneMediaSnapshot:dl,createSimulatedMedia:Ki,diffMediaEvents:fl,mediaVec3:cl,renderThumbnail:ul},Symbol.toStringTag,{value:"Module"})),Qi=14,$n=[{app:"Safari",title:"GitHub \xB7 we-scene-renderer",url:"https://github.com/oneincase/we-scene-renderer"},{app:"Google Chrome",title:"YouTube",url:"https://www.youtube.com/watch?v=dQw4w9WgXcQ"},{app:"Google Chrome",title:"Wallpaper Engine - Workshop",url:"https://steamcommunity.com/app/431960/workshop/"},{app:"Safari",title:"MDN Web Docs",url:"https://developer.mozilla.org/en-US/docs/Web/API"},{app:"Music",title:"\u591C\u822A\u661F \u2014 \u76F8\u4F4D\u8FC1\u79FB",url:""},{app:"Code",title:"we-scene-renderer \u2014 text.js",url:""}];function Ji(){const e={app:"",title:"",url:"",index:-1};function n(t){const r=Number(t)||0,o=$n.length?Math.floor(r/Qi)%$n.length:0,i=$n[o]||$n[0];return e.app=i.app,e.title=i.title,e.url=i.url,e.index=o,e}return n(0),{update:n,snapshot:e,tabs:$n,hold:Qi}}function es(e){const n={name:"",at:0};function t(r){return n.name=String(r||""),n.at=Date.now(),typeof e=="function"&&e(n.name),n.name}return{openUserShortcut:t,last:n}}function hl(e){const n=Ki(e),t=Ji(),r=es(null);return{media:n,windowTitle:t,shortcuts:r}}const ml=Object.freeze(Object.defineProperty({__proto__:null,createShortcutHandler:es,createSimulatedSystem:hl,createSimulatedWindowTitle:Ji},Symbol.toStringTag,{value:"Module"}));function gl(e={}){const n=e.target||(typeof window<"u"?window:null),t=e.viewport||(typeof window<"u"?()=>({w:window.innerWidth||1,h:window.innerHeight||1}):null),r={u:.5,v:.5,screenX:0,screenY:0,wx:0,wy:0,originY:null,lastU:.5,lastV:.5,lastScreenX:0,lastScreenY:0,lastWx:0,lastWy:0,lastOriginY:null,leftDown:!1,has:!1,moveCount:0,downCount:0,upCount:0,lastEventTime:0,screenW:1,screenH:1};function o(){if(!t)return;const p=t();r.screenW=p.w||1,r.screenH=p.h||1}o();function i(p,d){const y=p/r.screenW,x=d/r.screenH;r.has||(r.lastU=y,r.lastV=x,r.lastScreenX=p,r.lastScreenY=d),r.screenX=p,r.screenY=d,r.u=y,r.v=x,r.has=!0,r.moveCount++,r.lastEventTime=Date.now()}function s(p){const d=(p&1)!==0;d!==r.leftDown&&(r.leftDown=d,d?r.downCount++:r.upCount++,r.lastEventTime=Date.now())}function a(p){o();let d=p.clientX,y=p.clientY;if(n&&typeof n.getBoundingClientRect=="function"){const x=n.getBoundingClientRect();d-=x.left,y-=x.top}i(d,y)}function c(p){p.button!==void 0&&p.button!==0||s(1)}function u(p){p.button!==void 0&&p.button!==0||s(0)}function l(){s(0)}let f=!1;return n&&n.addEventListener&&(f=!0,n.addEventListener("mousemove",a,{passive:!0}),n.addEventListener("mousedown",c,{passive:!0}),n.addEventListener("mouseup",u,{passive:!0}),n.addEventListener("blur",l,{passive:!0}),typeof document<"u"&&document.addEventListener&&document.addEventListener("mouseleave",l,{passive:!0})),{state:r,pushExternal(p){if(!p)return;o();const d=Number(p.u),y=Number(p.v);Number.isFinite(d)&&Number.isFinite(y)&&i(d*r.screenW,y*r.screenH),s(Number(p.buttons)||0)},pushExternalLeave(){s(0)},beginFrame(){o(),r.lastU=r.u,r.lastV=r.v,r.lastScreenX=r.screenX,r.lastScreenY=r.screenY,r.lastWx=r.wx,r.lastWy=r.wy,r.lastOriginY=r.originY},syncWorld(p,d=0,y=0){if(!p)return;r.wx=p.offX+r.u*p.viewW-d,r.wy=p.offY+r.v*p.viewH-y;const x=Number(p.projH);r.originY=Number.isFinite(x)?x-r.wy:r.wy,r.lastWx===0&&r.lastWy===0&&(r.lastWx=r.wx,r.lastWy=r.wy,r.lastOriginY=r.originY)},normalizedDelta(){const p=r.u-r.lastU,d=r.v-r.lastV;return Math.hypot(p,d)},dispose(){!f||!n||!n.removeEventListener||(f=!1,n.removeEventListener("mousemove",a),n.removeEventListener("mousedown",c),n.removeEventListener("mouseup",u),n.removeEventListener("blur",l),typeof document<"u"&&document.removeEventListener&&document.removeEventListener("mouseleave",l))}}}const bl=Object.freeze(Object.defineProperty({__proto__:null,createPointerSource:gl},Symbol.toStringTag,{value:"Module"}));function ts(e,n,t,r,o,i,s){const a=e.size||[0,0],c=e.scale||[1,1,1],u=a[0]*c[0],l=a[1]*c[1];if(!(u>0)||!(l>0))return null;const f=e.origin||[0,0,0];let p=f[0],d=r-f[1];if(e.parallaxDepth&&(o!==0||i!==0)){const h=e.parallaxDepth,g=yn(h[0]),v=yn(h[1]);p+=g*o,d+=v*i}let y=n-p,x=t-d;const m=e.angles?e.angles[2]:0;if(m){const h=Math.cos(-m),g=Math.sin(-m),v=y*h+x*g,A=-y*g+x*h;y=v,x=A}const M=s&&s[e.alignment]||[.5,.5];return(M[0]!==.5||M[1]!==.5)&&(y-=(.5-M[0])*u,x-=(.5-M[1])*l),{lx:y/u,ly:x/l,w:u,h:l}}function yl(e,n,t,r,o={}){if(!e||e.length===0)return null;const i=o.parOffX||0,s=o.parOffY||0,a=o.alignTable,c=o.filter;for(let u=e.length-1;u>=0;u--){const l=e[u];if(!l||!l.visible||l.destroyed||c&&!c(l))continue;const f=ts(l,n,t,r,i,s,a);if(f&&Math.abs(f.lx)<=.5&&Math.abs(f.ly)<=.5)return l}return null}const vl=Object.freeze(Object.defineProperty({__proto__:null,hitTestLayers:yl,worldToLayerLocal:ts},Symbol.toStringTag,{value:"Module"})),Ve=e=>e,He=Ve(Us),vr=Ve(Ks),Ye=Ve(la),Pt=Ve(pa),Ne=Ve(Xa),xl=Ve(Ya),wl=Ve(ec),sn=Ve(gc),jn=Ve(Fc),et=Ve(el),Ml=Ve(nl),xe=Ve(pl),ns=Ve(ml),rs=Ve(ja),_l=Ve(bl),Al=Ve(vl);function Tl(e,n,t){return{camera:null,general:{orthogonalprojection:{width:e,height:n},clearenabled:!0,clearcolor:"0 0 0"},layers:[{id:0,name:"media",visible:!0,image:t,textureName:t,particle:null,puppet:null,solid:!1,isContainer:!1,isPostProcess:!1,isText:!1,isSound:!1,isComponent:!1,sound:[],origin:[e/2,n/2,0],scale:[1,1,1],angles:[0,0,0],size:[e,n],alignment:"center",color:[1,1,1],alpha:1,brightness:1,colorBlendMode:0,copybackground:!1,parallaxDepth:null,animationLayers:[],effects:[]}],properties:{}}}async function Sl(e){const n=await fetch(e);if(!n.ok)throw new Error(`HTTP ${n.status}`);const t=new window.ImageDecoder({data:await n.arrayBuffer(),type:"image/gif"});await t.tracks.ready,await t.completed;const r=t.tracks.selectedTrack;if(!r||!r.frameCount)return null;const o=Math.min(r.frameCount,300),i=[];let s=0,a=0;for(let c=0;c<o;c++){const{image:u}=await t.decode({frameIndex:c});s=u.displayWidth,a=u.displayHeight,i.push({bitmap:await createImageBitmap(u),durationMs:u.duration?u.duration/1e3:100}),u.close()}return t.close?.(),{width:s,height:a,frames:i}}function El(e,n,t){if(e.audioBridge)return;const r=window.AudioContext||window.webkitAudioContext;if(!r)return;let o,i;try{o=new r;const l=o.createMediaElementSource(t);i=o.createAnalyser(),i.fftSize=256,i.smoothingTimeConstant=.75,l.connect(i),i.connect(o.destination)}catch(l){se(e,n,`media \u9891\u8C31\u63A5\u7BA1\u8DF3\u8FC7: ${l?.message??l}`);return}const s=new Uint8Array(i.frequencyBinCount),a=new Float32Array(64),c=new Float32Array(64),u=()=>{if(o.state!=="running")return null;i.getByteFrequencyData(s);const l=Math.min(64,s.length);for(let f=0;f<l;f++){const p=s[f]/255;a[f]=p,c[f]=p}for(let f=l;f<64;f++)a[f]=0,c[f]=0;return{left:a,right:c}};if(e.audioBridge=u,o.state==="suspended"){const l=()=>{o.resume().catch(()=>{}),window.removeEventListener("pointerdown",l),window.removeEventListener("keydown",l)};window.addEventListener("pointerdown",l,{once:!0}),window.addEventListener("keydown",l,{once:!0}),(e.wallpaperDisposers??=[]).push(()=>{window.removeEventListener("pointerdown",l),window.removeEventListener("keydown",l)})}(e.wallpaperDisposers??=[]).push(()=>{e.audioBridge===u&&(e.audioBridge=null),o.close().catch(()=>{})})}function Pl(e,n){rn(e);const t=m=>{se(e,n,`media ${n.type} \u5931\u8D25: ${m}`),e.onError?.(new Error(`\u5A92\u4F53\u58C1\u7EB8\uFF08${n.type}\uFF09${m}`)),e.fallbackPage?.()};if(!n.src){t("\u7F3A\u5C11\u8D44\u6E90 URL\uFF08cfg.src \u4E3A\u7A7A\uFF09");return}const r=n.type==="video",o=n.type==="gif",i=n.canvas instanceof HTMLCanvasElement,s=i?n.canvas:document.createElement("canvas"),a=Wt(e,n),c=s.clientWidth||window.innerWidth||1,u=s.clientHeight||window.innerHeight||1;if(s.width=Math.max(1,Math.round(c*a)),s.height=Math.max(1,Math.round(u*a)),i||(s.style.cssText="position:absolute;inset:0;width:100%;height:100%;"),!s.getContext("webgl2",{premultipliedAlpha:!1,antialias:!1,alpha:!1,preserveDrawingBuffer:!0})){if(se(e,n,`media ${n.type}: WEBGL2_UNAVAILABLE`),i){e.onError?.(new Error("WEBGL2_UNAVAILABLE"));return}r?Cl(e,n):Ll(e,n);return}if(i||e.wrap?.appendChild(s),e.canvas=s,e.onSceneInfo){const m=e.onSceneInfo;e.onSceneInfo=void 0;try{m({width:c,height:u,layerCount:0,hasModels:!1,hasParticles:!1,hasText:!1})}catch{}}let f=!1;e.sceneCleanup=()=>{f=!0,e.renderer&&(e.renderer.dispose?.(),e.renderer=void 0)};let p,d,y=!1;e.sceneAudio={setVolume(m){const M=e.video;if(!M)return;const h=Math.max(0,Math.min(1,Number(m)||0));M.volume=h,M.muted=h<=0,h>0&&M.paused&&!e.paused&&M.play().catch(g=>{se(e,n,`media \u53D6\u6D88\u9759\u97F3\u540E\u81EA\u52A8\u64AD\u653E\u88AB\u62D2\u7EDD: ${g?.message??g}`)})},audios:[]},e.sceneCtl={pause(){p?.()},resume(){d?.()},applyUserProperties(){}};const x=m=>{f||(f=!0,t(m))};(async()=>{try{const m=Ne.createRenderer(s,{diag:O=>se(e,n,`renderer: ${O}`),fboCapFactor:0});if(e.renderer=m,f)return;const M="__media",h=new Map;let g,v=0,A=0;if(r){const O=document.createElement("video");if(O.autoplay=!0,O.loop=n.loop!==!1,O.muted=n.muted!==!1,O.playsInline=!0,O.preload="metadata",O.width=s.width,O.height=s.height,O.style.cssText="position:fixed;left:-9999px;top:-9999px;width:2px;height:2px;opacity:0;pointer-events:none",O.src=n.src,document.body.appendChild(O),e.video=O,(e.videoTextures??=[]).push(O),await new Promise((V,X)=>{O.addEventListener("loadedmetadata",()=>V(),{once:!0}),O.addEventListener("error",()=>X(new Error(`video error ${O.error?.code??"?"}`)),{once:!0})}),f)return;v=O.videoWidth||s.width,A=O.videoHeight||s.height,h.set(M,{video:O,glTex:Ne.makeTexture(m.gl,new Uint8Array([0,0,0,255]),1,1),width:v,height:A,rg88:!1,lastUploaded:-1}),e.paused||O.play().catch(()=>{}),El(e,n,O),se(e,n,`media video ${v}x${A} \u2192 scene \u6E32\u67D3`)}else{let O=!1;if(o&&typeof window.ImageDecoder=="function")try{const V=await Sl(n.src);if(V&&V.frames.length>1){v=V.width,A=V.height;const X=m.gl,ie={glTex:Ne.makeTexture(X,null,0,0,V.frames[0].bitmap),width:v,height:A,rg88:!1};h.set(M,ie);let J=0,Z=performance.now()+V.frames[0].durationMs;g=()=>{const le=performance.now();if(!(le<Z)){J=(J+1)%V.frames.length,Z=le+V.frames[J].durationMs,X.bindTexture(X.TEXTURE_2D,ie.glTex);try{X.texImage2D(X.TEXTURE_2D,0,X.RGBA,X.RGBA,X.UNSIGNED_BYTE,V.frames[J].bitmap)}catch{}}};const te=e.sceneCleanup;e.sceneCleanup=()=>{te?.();for(const le of V.frames)le.bitmap.close()},O=!0,se(e,n,`media gif ${v}x${A} ${V.frames.length} \u5E27 \u2192 scene \u6E32\u67D3`)}}catch(V){se(e,n,`gif \u89E3\u7801\u5931\u8D25\uFF0C\u56DE\u9000\u9759\u6001\u9996\u5E27: ${String(V.message).slice(0,80)}`)}if(!O){const V=new Image;if(V.crossOrigin="anonymous",V.src=n.src,await new Promise((X,ie)=>{V.addEventListener("load",()=>X(),{once:!0}),V.addEventListener("error",()=>ie(new Error("image load error")),{once:!0})}),f)return;v=V.naturalWidth||1,A=V.naturalHeight||1,e.img=V,h.set(M,{glTex:Ne.makeTexture(m.gl,null,0,0,V),width:v,height:A,rg88:!1}),se(e,n,`media ${n.type} ${v}x${A} \u2192 scene \u6E32\u67D3`)}}if(f)return;const _=Tl(v,A,M),R=performance.now();let L=0,N=0,j=-1/0;const H=O=>{if(f||e.paused)return;const V=e.cfg.sceneFps||60;if(O-j>=1e3/V){j=O,An(e,O),To(e,s,e.cfg),g?.();const X=e.coverAlign;m.render(_,h,s.width,s.height,(O-R-L)/1e3,dn(e.cfg.fit),X.x,X.y).then(()=>{if(e.onFirstFrame){const ie=e.onFirstFrame;e.onFirstFrame=void 0;try{ie()}catch{}}f||e.paused||(e.raf=requestAnimationFrame(H))}).catch(ie=>x(String(ie.message||ie).slice(0,200)))}else e.paused||(e.raf=requestAnimationFrame(H))},K=()=>{f||e.paused||e.raf===void 0&&(e.raf=requestAnimationFrame(H))};p=()=>{e.raf!==void 0&&(cancelAnimationFrame(e.raf),e.raf=void 0),N||(N=performance.now());const O=e.video;y=!!(O&&!O.paused&&!O.ended),O?.pause()},d=()=>{N&&(L+=performance.now()-N,N=0),y&&e.video?.play().catch(()=>{}),y=!1,K()},K()}catch(m){x(String(m.message||m).slice(0,200))}})()}function Cl(e,n){if(rn(e),!n.src){e.fallbackPage?.();return}const t=Mo(n.fit),r=`position:absolute;inset:0;width:100%;height:100%;object-fit:${t.objectFit};object-position:50% 50%;background:${t.background};`;let o=!1;const i=()=>{o||(o=!0,console.warn("video error, fallback to default wallpaper"),e.fallbackPage?.())},s=document.createElement("video");s.autoplay=!0,s.loop=n.loop!==!1,s.muted=n.muted!==!1,s.playsInline=!0,s.preload="metadata";const a=Math.min(window.devicePixelRatio||1,e.cfg.renderDpr||1);s.width=Math.max(1,Math.round(innerWidth*a)),s.height=Math.max(1,Math.round(innerHeight*a)),s.style.cssText=r,s.src=n.src,s.addEventListener("error",i),e.wrap?.appendChild(s),e.video=s,s.addEventListener("canplay",()=>s.play().catch(()=>{}),{once:!0}),se(e,n,"video mounted (single + native loop)")}function Ll(e,n){rn(e);const t=document.createElement("img"),r=Mo(n.fit);t.style.cssText=`position:absolute;inset:0;width:100%;height:100%;object-fit:${r.objectFit};object-position:50% 50%;background:${r.background};`,t.src=n.src??"",t.addEventListener("error",()=>e.fallbackPage?.()),e.wrap?.appendChild(t),e.img=t}const Rl=["scene.pkg","scenes/scene.pkg","gifscene.pkg"],kl={mp4:"video",webm:"video",mov:"video",m4v:"video",ogv:"video",gif:"gif",png:"image",jpg:"image",jpeg:"image",webp:"image",avif:"image",bmp:"image"};function os(e){const n=e.toLowerCase().split(";")[0].trim();return n==="image/gif"?"gif":n.startsWith("video/")?"video":n.startsWith("image/")?"image":null}function lo(e){if(typeof e!="string"||!e)return null;let n=e;const t=n.indexOf("#");t>=0&&(n=n.slice(0,t));const r=n.indexOf("?");r>=0&&(n=n.slice(0,r));const o=n.split("/").pop()||"",i=o.lastIndexOf(".");return i<0?null:kl[o.slice(i+1).toLowerCase()]??null}async function Fl(e,n,t){try{const r=await fetch(e,{...n,method:"HEAD",signal:t});return r.ok?os(r.headers.get("content-type")||""):null}catch{return null}}function is(e,n){const t=e.replace(/\/+$/,"");return{key:t,async scenePkg(r){let o=null,i=null;for(const a of Rl){let c;try{c=await fetch(`${t}/${a}`,{...n,signal:r})}catch(u){if(r?.aborted)throw u;i=u;continue}if(!c.ok){o=c.status;continue}try{return await c.arrayBuffer()}catch(u){if(r?.aborted)throw u;const l=u instanceof Error?u.message:String(u);throw new Error(`\u8BFB\u53D6 scene.pkg \u4F53\u5931\u8D25\uFF08${l}\uFF09`)}}if(o!=null)throw new Error(`scene.pkg \u52A0\u8F7D\u5931\u8D25\uFF08HTTP ${o}\uFF09`);const s=i instanceof Error?i.message:"Failed to fetch";throw new Error(`scene.pkg \u52A0\u8F7D\u5931\u8D25\uFF08${s}\uFF09`)},async project(r){try{const o=await fetch(`${t}/project.json`,{...n,signal:r});return o.ok?await o.json():null}catch{return null}},async webEntry(r){let o="index.html";try{const i=await fetch(`${t}/project.json`,{...n,signal:r});if(i.ok){const s=await i.json();s&&typeof s.file=="string"&&s.file.trim()&&(o=s.file.trim().replace(/^\/+/,""))}}catch{if(r?.aborted)throw new Error("aborted")}return{url:`${t}/${o}`}},async mediaEntry(r){let o="";try{const i=await fetch(`${t}/project.json`,{...n,signal:r});if(i.ok){const s=await i.json();s&&typeof s.file=="string"&&s.file.trim()&&(o=s.file.trim().replace(/^\/+/,""))}}catch{if(r?.aborted)throw new Error("aborted")}return o?{url:`${t}/${o}`}:null}}}function Nl(e,n){const t=e;return{key:typeof t.name=="string"?`file:${t.name}:${t.size}:${t.lastModified??0}`:void 0,scenePkg:()=>e.arrayBuffer(),project:async()=>n??null}}function Ul(e,n,t){return{key:t,scenePkg:async()=>e,project:async()=>n??null}}function Dl(e,n){const t=typeof e!="string",r=e;let o=n?.type??(t?os(e.type||""):null)??lo(t?String(r.name??""):e),i=!1,s=null;const a=()=>t?(s||(s=URL.createObjectURL(e)),s):e;return{key:n?.key??(t?typeof r.name=="string"?`media:${r.name}:${r.size}:${r.lastModified??0}`:void 0:`media:${e}`),async scenePkg(){throw new Error("mediaSource \u662F\u7EAF\u5A92\u4F53\u6765\u6E90\uFF0C\u6CA1\u6709 scene.pkg\uFF08\u8BF7\u6539\u7528 httpSource/fileSource/bytesSource\uFF09")},async project(){return o?{type:o}:null},async mediaEntry(u){return!o&&!t&&!i&&(i=!0,o=await Fl(e,void 0,u)),{url:a(),type:o??void 0}},dispose(){s&&(URL.revokeObjectURL(s),s=null)}}}const ss=.5,Bl=.04,as=.08;function Il(e,n){const t=h=>{const g=document.createElement("video");h&&(g.src=e),g.muted=n.muted,g.playsInline=!0,g.preload="metadata";const v=Math.min(window.devicePixelRatio||1,n.renderDpr||1),A=Math.max(1,Math.round(n.maxW*v)),_=Math.max(1,Math.round(n.maxH*v));return g.width=A,g.height=_,g.loop=!0,g};let r=t(!0),o=t(!1),i=!1,s=1,a=n.muted;o.muted=!0;const c=()=>{i||(o.src=e,i=!0)};let u=!1,l=!1,f=-1,p=0,d=!1;const y=()=>{if(u=!1,l=!1,!o.paused){o.pause();try{o.currentTime=0}catch{}}},x=()=>{const h=r;r=o,o=h,u=!1,l=!1,r.play().catch(()=>{}),r.muted=a,r.volume=s,h.pause();try{h.currentTime=0}catch{}h.muted=!0,f=-1,i=!0,M.onSwap?.(r)},m=()=>{if(d)return;p=requestAnimationFrame(m);const h=r.duration;if(!isFinite(h)||h<=0)return;const g=r.currentTime;if(f>=0&&g<f-.05){const A=l;y(),f=g,A||M.onFallback?.();return}f=g;const v=h-g;if(v>ss+.5){(u||l)&&y();return}if(l){(v<=as||g<=as)&&x();return}if(u){o.paused?o.play().catch(()=>{}):o.currentTime>=Bl*.5&&(o.pause(),u=!1,l=!0);return}if(v<=ss&&(c(),o.readyState>=2)){try{o.currentTime=0}catch{}o.play().catch(()=>{}),u=!0}};p=requestAnimationFrame(m);const M={get active(){return r},get standby(){return o},onSwap:void 0,onFallback:void 0,setVolume(h){s=Math.max(0,Math.min(1,h)),a=h<=0,r.muted=a,r.volume=s,o.muted=!0,o.volume=s},pause(){y(),r.pause(),p&&cancelAnimationFrame(p),p=0},resume(){d||(r.play().catch(h=>{h&&h.name}),p||(p=requestAnimationFrame(m)))},destroy(){d=!0,p&&cancelAnimationFrame(p),p=0;for(const h of[r,o]){h.pause(),h.removeAttribute("src");try{h.load()}catch{}h.remove()}}};return M}const cs=!1,ls=!0,us=!1,Ol=!1,$l=!1,fs=4,zn=64,ds={STOPPED:0};function jl(){return{left64:new Float32Array(zn),right64:new Float32Array(zn),left32:new Float32Array(32),right32:new Float32Array(32),left16:new Float32Array(16),right16:new Float32Array(16),level:0,silent:!0}}function xr(e,n){const t=n.length/e.length;for(let r=0;r<e.length;r++){let o=0;const i=Math.floor(r*t),s=Math.max(i+1,Math.floor((r+1)*t));for(let a=i;a<s;a++)o+=n[a];e[r]=o/(s-i)}}function zl(e,n,t){const r=n.length,o=t*.5,i=20,s=Math.min(2e4,o);let a=0;for(let c=0;c<zn;c++){const u=c/zn,l=(c+1)/zn,f=i*Math.pow(s/i,u),p=i*Math.pow(s/i,l),d=Math.max(0,Math.floor(f/o*r)),y=Math.min(r,Math.max(d+1,Math.ceil(p/o*r)));let x=0;for(let M=d;M<y;M++)x+=n[M]/255;const m=Math.min(1,x/(y-d)*1.35);e.left64[c]=m,e.right64[c]=m,c<48&&(a+=m)}xr(e.left32,e.left64),xr(e.right32,e.right64),xr(e.left16,e.left64),xr(e.right16,e.right64),e.level=Math.min(1,a/(48*1.2)),e.silent=e.level<.02}function Wl(e){let n=2166136261;for(let t=0;t<e.length;t++)n^=e.charCodeAt(t),n=Math.imul(n,16777619);return(n>>>0)%360}function uo(e,n,t){const r=n/100,o=t/100,i=(1-Math.abs(2*o-1))*r,s=e/60,a=i*(1-Math.abs(s%2-1));let c=0,u=0,l=0;s<1?[c,u,l]=[i,a,0]:s<2?[c,u,l]=[a,i,0]:s<3?[c,u,l]=[0,i,a]:s<4?[c,u,l]=[0,a,i]:s<5?[c,u,l]=[a,0,i]:[c,u,l]=[i,0,a];const f=o-i/2;return[c+f,u+f,l+f]}function Vl(e,n){const t=Wl(n||"empty"),[r,o,i]=uo(t,72,48),[s,a,c]=uo((t+40)%360,55,28),[u,l,f]=uo((t+20)%360,70,72);e.primaryColor=xe.mediaVec3(r,o,i),e.secondaryColor=xe.mediaVec3(s,a,c),e.tertiaryColor=xe.mediaVec3(u,l,f),e.textColor=xe.mediaVec3(.98,.98,1),e.highContrastColor=xe.mediaVec3(1,1,1),e.hasThumbnail=!!n}function Hl(e,n,t){const r=document.createElement("canvas");r.width=32,r.height=32;const o=r.getContext("2d",{willReadFrequently:!0});if(!o)return null;o.drawImage(e,0,0,n,t,0,0,32,32);const i=o.getImageData(0,0,32,32).data;let s=0,a=0,c=0,u=0,l=0,f=0,p=0,d=-1;for(let M=0;M<i.length;M+=4){const h=i[M]/255,g=i[M+1]/255,v=i[M+2]/255;s+=h,a+=g,c+=v,u++;const A=Math.max(h,g,v),_=Math.min(h,g,v),R=A-_,L=.2126*h+.7152*g+.0722*v,N=R*1.4+(L>.15&&L<.85?.3:0);N>d&&(d=N,l=h,f=g,p=v)}if(!u)return null;const y=[l,f,p],x=[s/u*.55,a/u*.55,c/u*.55],m=[Math.min(1,y[0]*.45+.55),Math.min(1,y[1]*.45+.55),Math.min(1,y[2]*.45+.55)];return{primary:y,secondary:x,tertiary:m}}function Xl(e,n,t,r=512){const o=document.createElement("canvas");o.width=r,o.height=r;const i=o.getContext("2d"),s=Math.max(r/Math.max(1,n),r/Math.max(1,t)),a=n*s,c=t*s;i.fillStyle="#000",i.fillRect(0,0,r,r),i.drawImage(e,(r-a)/2,(r-c)/2,a,c);const u=i.getImageData(0,0,r,r);return{width:r,height:r,rgba:new Uint8Array(u.data)}}function Gl(){return{hasMedia:!1,state:ds.STOPPED,title:"",artist:"",album:"",albumArtist:"",position:0,duration:0,hasThumbnail:!1,primaryColor:xe.mediaVec3(0,0,0),secondaryColor:xe.mediaVec3(0,0,0),tertiaryColor:xe.mediaVec3(0,0,0),textColor:xe.mediaVec3(1,1,1),highContrastColor:xe.mediaVec3(1,1,1),trackIndex:-1,lyrics:[],lyricLine:"",lyricIndex:-1}}async function Yl(){if(!navigator.mediaDevices?.getUserMedia)return null;try{const e=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1},video:!1}),n=new AudioContext,t=n.createMediaStreamSource(e),r=n.createAnalyser();return r.fftSize=2048,r.smoothingTimeConstant=.8,t.connect(r),n.state==="suspended"&&await n.resume().catch(()=>{}),{ctx:n,stream:e,analyser:r,buf:new Uint8Array(r.frequencyBinCount)}}catch{return null}}async function ps(e){const n=e?.origin??(typeof location<"u"?location.origin:""),t=e?.onArtwork,r=jl(),o=Gl(),i={app:"",title:"",url:"",index:0};let s="off",a="offline",c="offline",u="",l=!1,f="";const p=await Yl();p?s="mic":navigator.mediaDevices?.getUserMedia?s="denied":s="unavailable";let d=null,y=null,x=!1;const m=(A,_,R)=>{!n||!t||!l||f!==A&&(f=A,t({url:`${n}/api/system/artwork?k=${encodeURIComponent(A)}&_=${Date.now()}`,trackKey:A,title:_,artist:R}))},M=A=>{if(!A||!A.hasMedia){o.hasMedia=!1,o.state=ds.STOPPED,o.title="",o.artist="",o.album="",o.albumArtist="",o.position=0,o.duration=0,o.hasThumbnail=!1,o.trackIndex=-1,a=A?"empty":"offline",u="",l=!1,f="";return}a="live",o.hasMedia=!0,o.state=Number(A.state)===2?2:Number(A.state)===1?1:0,o.title=String(A.title??""),o.artist=String(A.artist??""),o.album=String(A.album??""),o.albumArtist=String(A.albumArtist??A.artist??""),o.position=Number(A.position)||0,o.duration=Number(A.duration)||0,l=A.hasArtwork===!0;const _=`${o.title}|${o.artist}|${o.album}`;_!==u&&(u=_,f="",o.trackIndex=o.trackIndex+1|0,Vl(o,_)),m(_,o.title,o.artist)},h=A=>{if(!A){c="offline";return}i.app=String(A.app??""),i.title=String(A.title??""),i.url=String(A.url??""),c=i.app||i.title?"live":"empty"},g=async()=>{if(!(!n||x))try{const[A,_]=await Promise.all([fetch(`${n}/api/system/media`,{cache:"no-store"}),fetch(`${n}/api/system/window`,{cache:"no-store"})]);if(A.ok){const R=await A.json();M(R)}else a="offline";_.ok&&h(await _.json())}catch{a=a==="live"?"live":"offline",c=c==="live"?"live":"offline"}};if(n){await g(),y=setInterval(()=>{g()},1e3);try{d=new EventSource(`${n}/api/system/stream`),d.onmessage=A=>{if(!x)try{const _=JSON.parse(A.data);M(_.media),h(_.window)}catch{}}}catch{}}const v=A=>{!n||x||fetch(`${n}/api/system/media-control`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:A})}).then(async _=>_.ok?_.json():null).then(_=>{_&&typeof _=="object"&&M(_),g()}).catch(()=>{g()})};return{audio:{snapshot:r,pump:()=>{if(!p||x){r.level=0,r.silent=!0;return}p.analyser.getByteFrequencyData(p.buf),zl(r,p.buf,p.ctx.sampleRate||48e3)}},media:{snapshot:o,pump:()=>{},skipNext:()=>v("skipNext"),skipPrevious:()=>v("skipPrevious"),play:()=>v("play"),pause:()=>v("pause"),playPause:()=>v("playPause")},windowTitle:{snapshot:i,pump:()=>{}},status:()=>({audio:s,media:a,window:c,title:o.title,artist:o.artist,app:i.app,windowTitle:i.title,hasArtwork:l}),dispose:()=>{x=!0,y&&(clearInterval(y),y=null);try{d?.close()}catch{}if(d=null,p)try{p.stream.getTracks().forEach(A=>A.stop()),p.ctx.close()}catch{}}}}const ql={"common.h":`// WE common.h\uFF08\u91CD\u5EFA\u5B50\u96C6\uFF0C\u4F9B we-scene \u6D4F\u89C8\u5668\u6E32\u67D3\uFF09
|
|
459
|
+
}`;function ab(t){const e=(u,l)=>{const f=t.createShader(u);if(t.shaderSource(f,l),t.compileShader(f),!t.getShaderParameter(f,t.COMPILE_STATUS))throw new Error("MDL \u7740\u8272\u5668\u7F16\u8BD1\u5931\u8D25: "+t.getShaderInfoLog(f));return f};let n=rb(t),r=null;for(;;){const u=t.createProgram();let l=!1;try{t.attachShader(u,e(t.VERTEX_SHADER,ib(n))),t.attachShader(u,e(t.FRAGMENT_SHADER,sb)),t.bindAttribLocation(u,0,"a_pos"),t.bindAttribLocation(u,1,"a_uv"),t.bindAttribLocation(u,2,"a_bone"),t.bindAttribLocation(u,3,"a_weight"),t.linkProgram(u),l=!!t.getProgramParameter(u,t.LINK_STATUS)}catch{l=!1}if(l){r=u;break}if(t.deleteProgram(u),n<=va)throw new Error("MDL \u7740\u8272\u5668\u94FE\u63A5\u5931\u8D25\uFF08\u9AA8\u6570\u5DF2\u964D\u5230 "+va+"\uFF09");n=Math.max(va,n>>1)}const i=n,s={mvp:t.getUniformLocation(r,"u_mvp"),tex:t.getUniformLocation(r,"u_tex"),skin:t.getUniformLocation(r,"u_skin"),boneCount:t.getUniformLocation(r,"u_boneCount"),color:t.getUniformLocation(r,"u_color")},a=new Float32Array(i*16);for(let u=0;u<i;u++)a.set(Nd,u*16);const o=new WeakMap;function c(u){let l=o.get(u);if(l)return l;const f=t.createVertexArray();t.bindVertexArray(f);const d=u.vertexCount,h=new Float32Array(d*13);for(let w=0;w<d;w++){const y=w*13;h[y]=u.positions[w*3],h[y+1]=u.positions[w*3+1],h[y+2]=u.positions[w*3+2],h[y+3]=u.uvs[w*2],h[y+4]=u.uvs[w*2+1];for(let b=0;b<4;b++)h[y+5+b]=u.boneIdx[w*4+b],h[y+9+b]=u.weights[w*4+b]}const p=t.createBuffer();t.bindBuffer(t.ARRAY_BUFFER,p),t.bufferData(t.ARRAY_BUFFER,h,t.STATIC_DRAW);const m=52;t.enableVertexAttribArray(0),t.vertexAttribPointer(0,3,t.FLOAT,!1,m,0),t.enableVertexAttribArray(1),t.vertexAttribPointer(1,2,t.FLOAT,!1,m,12),t.enableVertexAttribArray(2),t.vertexAttribPointer(2,4,t.FLOAT,!1,m,20),t.enableVertexAttribArray(3),t.vertexAttribPointer(3,4,t.FLOAT,!1,m,36);const g=t.createBuffer();return t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,g),t.bufferData(t.ELEMENT_ARRAY_BUFFER,u.indices,t.STATIC_DRAW),t.bindVertexArray(null),l={vao:f,vbuf:p,ibuf:g},o.set(u,l),l}return{gl:t,prog:r,maxBones:i,upload(u){c(u)},draw(u,l,f,d){const h=c(l);t.useProgram(r),t.bindVertexArray(h.vao),t.activeTexture(t.TEXTURE0);const p=f.overrideTex||(d&&d.glTex?d.glTex:d);t.bindTexture(t.TEXTURE_2D,p),t.uniform1i(s.tex,0),t.uniformMatrix4fv(s.mvp,!1,u);const m=f.color||[1,1,1,1];t.uniform4f(s.color,m[0],m[1],m[2],m[3]);const g=Oc(l,f.time||0,f.animLayers,f.boneOverrides),w=Math.min(l.bones.length,i);g&&w>0?(t.uniformMatrix4fv(s.skin,!1,g.subarray(0,w*16)),t.uniform1i(s.boneCount,w)):(t.uniformMatrix4fv(s.skin,!1,a),t.uniform1i(s.boneCount,0)),f.blending==="additive"?(t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE,t.ONE,t.ONE)):f.blending==="normal"?t.disable(t.BLEND):(t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA));const y=l.indexType==="u32"?t.UNSIGNED_INT:t.UNSIGNED_SHORT;t.drawElements(t.TRIANGLES,l.indexCount,y,0),t.bindVertexArray(null)}}}const ob=Object.freeze(Object.defineProperty({__proto__:null,applyAttachmentBindOrigins:eb,attachmentBind:zd,attachmentWorld:Ud,bindWorldOf:Od,computeSkinMatrices:Oc,createMDLRenderer:ab,followAttachments:tb,mat4MulOut:Jy,parentMeshToWorldDelta:Uc,parseMDL:Wy},Symbol.toStringTag,{value:"Module"}));function cb(t={},e={}){const n=typeof t.setTimeout=="function"?t.setTimeout:null,r=typeof t.clearTimeout=="function"?t.clearTimeout:null,i=typeof t.setInterval=="function"?t.setInterval:null,s=typeof t.clearInterval=="function"?t.clearInterval:null,a=typeof e.onError=="function"?e.onError:null,o=new Set,c=g=>{const w=Number(g);return Number.isFinite(w)&&w>0?w:0},u=g=>()=>{try{g()}catch(w){a&&a(w,"timer")}},l=(g,w)=>{const y=()=>{g.fired||(g.fired=!0,o.delete(y),w&&g.handle!=null&&w(g.handle))};return y.handle=null,y.valueOf=()=>typeof g.handle=="number"?g.handle:0,y};function f(g,w){if(typeof g!="function")return l({fired:!0,handle:null},null);const y={fired:!1,handle:null},b=l(y,r);return o.add(b),y.handle=n?n(u(()=>{y.fired=!0,o.delete(b),g()}),c(w)):null,b.handle=y.handle,b}function d(g,w){if(typeof g!="function")return l({fired:!0,handle:null},null);const y={fired:!1,handle:null},b=l(y,s);return o.add(b),y.handle=i?i(u(g),c(w)):null,b.handle=y.handle,b}function h(g){if(typeof g=="function"){g();return}r&&g!=null&&r(g)}function p(g){if(typeof g=="function"){g();return}s&&g!=null&&s(g)}function m(){for(const g of[...o])g();o.clear()}return{setTimeout:f,setInterval:d,clearTimeout:h,clearInterval:p,dispose:m,pendingCount:()=>o.size}}const lb=Object.freeze(Object.defineProperty({__proto__:null,createEngineTimers:cb},Symbol.toStringTag,{value:"Module"}));function ub(t){let e=t>>>0;return function(){e|=0,e=e+1831565813|0;let n=Math.imul(e^e>>>15,1|e);return n=n+Math.imul(n^n>>>7,61|n)^n,((n^n>>>14)>>>0)/4294967296}}function ka(t,e){const n=Math.floor(t),r=t-n,i=a=>{const o=Math.sin((a*127.1+e*311.7)*43758.5453)*43758.5453;return(o-Math.floor(o))*2-1},s=r*r*(3-2*r);return i(n)*(1-s)+i(n+1)*s}const fb=32,Hd=60/112,Vd=3.2;function db(t){const e=new Float32Array(16),n=new Float32Array(16),r=new Float32Array(16);for(let i=0;i<16;i++)e[i]=i%4===0?1:i%4===2?.38+t()*.15:t()<.08?.5:0,n[i]=i%8===4?1:t()<.06?.6:0,r[i]=i%2===1?.5+t()*.4:i%4===0?.25:t()<.3?.3:0;return{kick:e,snare:n,hat:r}}function Wd(t=20260830){const e=ub(t),n=db(e),r=new Float32Array(64);for(let y=0;y<64;y++)r[y]=e()*64;const i=64,s=new Float32Array(i),a=new Float32Array(i),o=new Float32Array(i),c=new Float32Array(i),u=new Float32Array(i),l=new Float32Array(i),f=new Float32Array(32),d=new Float32Array(32),h=new Float32Array(16),p=new Float32Array(16),m={left64:u,right64:l,left32:f,right32:d,left16:h,right16:p,preL64:o,preR64:c,level:0,silent:!1};function g(y,b){const v=b.length/y.length;for(let k=0;k<y.length;k++){let A=0;const T=Math.floor(k*v),S=Math.floor((k+1)*v);for(let P=T;P<Math.max(T+1,S);P++)A+=b[P];y[k]=A/Math.max(1,S-T)}}function w(y){const b=y/Hd,v=b*4,k=(Math.floor(v)%16+16)%16,A=v-Math.floor(v),T=Math.exp(-A*Hd*14),S=y%fb,P=S>=27&&S<29,M=S>=29?(S-29)/3:0,B=S>=24&&S<27?1-(S-24)/3:0,N=P?0:M>0?M*M:B>0?0:1,U=P?0:B>0?.35:1,q=n.kick[k]*T*N,H=(n.snare[k]*T+n.hat[k]*T*.7)*N,G=n.hat[k]*T*N,Y=M>0?Math.pow(M,3)*(.4+.6*Math.abs(ka(v*2,7))):0;let J=0;for(let ne=0;ne<i;ne++){const fe=ne/i,Ne=Math.pow(1-fe*.85,1.6),Ze=U*(.5+.3*ka(b*.5+r[ne]*.05,ne%8)),je=U*(.5+.3*ka(b*.53+r[ne]*.05+31.7,ne%8+16));let Fe=Ze*(.35+.65*fe),Le=je*(.35+.65*fe);if(fe<.2){const ve=q*(1-fe/.2);Fe+=ve,Le+=ve}if(fe>=.12&&fe<.62){const ve=1-Math.abs(fe-.34)/.28;ve>0&&(Fe+=H*.55*ve,Le+=H*.35*ve)}if(fe>=.45){const ve=(fe-.45)/.55;Le+=G*.5*ve,Fe+=G*.3*ve}Fe+=Y*.5,Le+=Y*.5,Fe*=Ne,Le*=Ne;const Pt=Fe,Xe=Le;Fe=Math.min(1,Fe*Vd),Le=Math.min(1,Le*Vd);const Dt=.06+fe*.2,Oe=ka(b*.13+ne*.35,11)*Dt;let qe=Math.min(1,Math.max(0,Fe*(1-Oe))),ze=Math.min(1,Math.max(0,Le*(1+Oe)));const st=P?.012:0;s[ne]=Math.max(st,qe),a[ne]=Math.max(st,ze),o[ne]=Math.max(st,Math.max(0,Pt*(1-Oe))),c[ne]=Math.max(st,Math.max(0,Xe*(1+Oe))),ne<48&&(J+=(s[ne]+a[ne])*.5)}return u.set(s),l.set(a),g(f,s),g(d,a),g(h,s),g(p,a),m.level=Math.min(1,J/(48*1.2)),m.silent=P,m}return{update:w,snapshot:m,bands:i}}function hb(t,e){for(const n of t.values()){jd(n.left,e.left64),jd(n.right,e.right64);for(let r=0;r<n.average.length;r++)n.average[r]=(n.left[r]+n.right[r])*.5}}function jd(t,e){const n=e.length/t.length;for(let r=0;r<t.length;r++){let i=0;const s=Math.floor(r*n),a=Math.max(s+1,Math.floor((r+1)*n));for(let o=s;o<a;o++)i+=e[o];t[r]=i/(a-s)}}const Aa="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAYAAAD0eNT6AAA7J0lEQVR42u2d2XIcSZZY412mqYUbiIVYSBY3cKni1kWyyCKLxTZTd9u0pBlNz9L9JzMvmv4NfYn6s/ScsgQIEEBmRPhy7/Xr7ufhvIxNkwlWIs7x6+ERw3/9ZnMBAAAAfTHwjwAAAEAAAAAAAAEAAAAABAAAAAAQAAAAAFBtAGwtAAAAoC8IAAAAAAIAAAAACAAAAABoNAC+3VoAAABAXxAAAAAABAAAAAAQAAAAAEAAAAAAQCMB8Hffbi0AAACgLwgAAAAAAgAAAAAIAAAAAGg1ALYXAAAA0BcEAAAAAAEAAAAABAAAAAAQAAAAAEAAAAAAAAEAAAAABAAAAAAQAAAAAEAAAAAAAAEAAAAABAAAAAAoB8Cl7QUAAAD0xfB3l3YWAAAA0BcEAAAAAAEAAAAABAAAAAAQAAAAAEAAAAAAAAEAAAAABAAAAAAQAAAAAEAAAAAAAAEAAAAABAAAAAAQAAAAACAcAF9durEAAACAviAAAAAACAAAAAAgAAAAAIAAAAAAAAIAAAAAqg2AyzcWAAAA0BcEAAAAAAEAAAAABAAAAAAQAAAAAEAAAAAAAAEAAAAAFQXA7gIAAAD6ggAAAAAgAAAAAIAAAAAAAAIAAAAACAAAAAAgAAAAAIAAAAAAAAIAAAAACAAAAAAgAAAAAIAAAAAAAO0A2FsAAABAXxAAAAAAXQbAlb0FAAAA9AUBAAAAQAAAAABAFwHw9ZW9BQAAAPQFAQAAAEAAAAAAAAEAAAAABAAAAAAQAAAAAEAAAAAAAAEAAAAAngNgfwEAAAB9QQAAAAAQAAAAAEAAAAAAAAEAAAAABAAAAAAQAAAAAEAAAAAAAAEAAAAAngLg6v4CAAAA+oIAAAAAIAAAAACAAAAAAIBWA+BgAQAAAH1BAAAAABAAAAAAQAAAAAAAAQAAAAAEAAAAABAAAAAAQAAAAAAAAQAAAACOAuCbqwcLAAAA6AsCAAAAgAAAAAAAAgAAAABaDYCbCwAAAOgLAgAAAIAAAAAAAAIAAAAAGg2AazcXAAAA0BcEAAAAAAEAAAAABAAAAAAQAAAAAEAAAAAAAAEAAAAABAAAAAAQAAAAAOAqAG4tAAAAoC8IAAAAAAIAAAAACAAAAAAgAAAAAIAAAAAAAAIAAAAACAAAAAAgAAAAAIAAAAAAAAIAAAAAbANg49YCAAAA+mL4ZuP2AgAAAPqCAAAAAOgxAL7duL0AAACAviAAAAAACAAAAAAgAAAAAIAAAAAAAAIAAAAACAAAAAAgAAAAAIAAAAAAAAIAAAAACAAAAAAwDoDvFgAAANAXBAAAQCL/+183zsG/CRAAAAANyf3//Z//ksz//fdvT/+c373a5d8WCAAAAI/Cz5F9DEwNgAAAACjAcjX+n4bCn5sS/CcxAAQAAIAeS9EuhetB/MQAEAAAAJ2s9mMgBEA3AK5/twAAaJGl+D2v9sND4Dr/PUEcAgAAED8hAAQAAEDdLCXZmvgJASAAAAAmVv2ti//izYJHzxXgvz0QAADQKy2O+5kGAAEAADC66t/rVvyr04A9vhMQGwB3FgAAtdHDXn8sxxHAdwPCIAAAoDp6HvmHTAP4jgABAADInwgAIAAAoF7Y7ycCgAAAAOQPRAAQAACA/IEIgOgAuHT9zgIAwCPIXy4C+D7BRQgAAHALN/wRAUAAAADyByIACAAAQP6Q9Ojgf7vOdwwIAADwx1JQiFr/iYF814AAAAA/N/295qY/K/i+AQEAAG5AzNwPAKYBcHcBAFAa9v1L3Q/Ad69XhkubdxcAACVh9F/wfoDXe3wHO4UAAIDiIOLCWwF8BwkAAABruOvfwxRgn+8iAQAAwOq/y1MBfBcJAAAAK7jxz9kNgXwnCQAAAP0b//YRL1MAIAAAoL+9/02k624KsMl3kwAAAGDvnykAEAAAAKz+mQIAAQAAwOq/Tf7GcwEIAAAAVv998nueC0AAAABI8zeO/rENAF4C4N4CAMAKBFvLzYB8V1uHAAAAMxj/17YNwHeWAAAAEIDxf23bAHxnCQAAAMb/bAMAAQAAEMvvefQvAQAEAACw/w9sAwABAABd7P9fQqoEABAAAMD+P7ANAAQAADS+/3+ATAkAcBcAW/cWAACasP9f8/MADvgON8pweeveAgBAEwKg7vsA+A63CQEAAAQAEAB9BsD9BQCAJoi09gDgO9wiBAAAEAAwyvL4Jt9hAgAAgADoEL7DBAAAAAFAAAABAABAABAAQAAAABAABAAQAAAABAABAAQAABAAQAAAAQAABAAQAEAAAAABAAQAEAAAQAAAAQAEAAAQAEAAAAEAAAQAmL0L4M9bfIfbDYAHCwAATZbPk0emdfLXowDgO9wiBAAAqLOUCDIlAIAAAAACAAgAIAAAgAAAvzcA8v1tNwC2HywAALRBppUGAN/dZiEAAIAAgLUsb97ku0sAAABkwUmASvf/+e4SAAAAOXAfQH38/s1NvrsEAABAHkuZIFX2/4EAAADuAwD2/4EAAAC2AYD9fyAAAKBJ/sA2AON/IAAAgG0AYPwPRQPgcAEAYAXbALWM//mutg4BAACm/OEntgH8j//5nnYRAFe2DxcAAJb87T94KJDn1T/f0T4gAADAHLYB/PKHn27xHSUAAAD0QLYOb/77j0t8NwkAAACmAKz+gQAAAGAKwOofCAAAAJkpwDbyZfUPBAAAcCIAWP0DAQAAXbBceSJhVv9AAAAAUwAwPfe/zXeQAAAA4IZARv/QTwDsHC4AAErDVkCh0T/fvW4Zruw8XAAAeICtAOPRP9+5riEAAIAI6HH0z3eNAOAfAQA8wVaAPnzPgAAAACKgy31/vmNAAACAU3hKIPIHAgAAuB8AkD8QAADQVwRcRuDZN/1d5rsEBAAAEAHIH4AAAAAigLP+QAAAABABrez53+Y7AwQAALR0RPA2gkf+QAAAABEAyB8IAADoKgLYEuBmP8gKgEcLAIBa+etfeGDQ8t+A7wLEQgAAQPX0uiWwXPUfj/z5DgABAABMA1j1AxAAANDdNOBt2/cGHO/1898ZCAAAgC5C4Gjc/5ZxPxAAAABdhADiB7UAuHrj0QIAoHWWEv3rX3Yq2uPf4b8bqEIAAEB3LOXqcSqw/EyIHwgAAIAOYgDpAwEAAOBkm0AzCJZ//pLl38W/uQzXD54ttu+8PmXvwfvFzSe/zeLsn7eEAAAA6C4KvjuV9gmhkv8i++/4txQR/fNTIecKPpVlXLQSBQQAAAC4pLTsY6cFFQbA4wUAAEBpahF+yISghn9vAgAAACoX/qdVHmey8me2FwMEAAAAmHCyh59+k1644A8yCI+DuG2C5c9PAAAAQFfSzxK+guRF4yAiCJbx4yUECACAikenMfDvBv5H++uFf+CclBjwsD1AAAA4F7zEmeaQI01HI8qbz/n3h+TvbPx3tU7hS8dAqRAgAACcyF5T9LlxQBiAjPTbE35cDMxsDRj/nhEAANZ7ojc/3wh1+L7KY05EAdKP++72Jf3ZGJiZCliGAAEAYCh9GQl/ykBhUnD4niBA+rPSt5Ptr8KUmQos/70JAIAupS94njnqrPMn4Sej8T1A+jVIvkwYhISA5u8RAQAgzE609D8VO+6k/SCUE5b/JjsEQRXfXX/SDxTyI2UUg2AuBJb/TTQmbAQAgNBqP1z847J3ewPTaBgQBC18b31Jv7DoRaJAJwSkf2cIAIDMC2jYxbONG6EIgt5i1UL6lcg+OQjktwWkpgHD1RtPFgAQR5j4S94IVc+T0aaDgO+aBCf/nu6lnyngfQVKxUDYNCDvezFc3X2yAIAwgsXf8XGnA80g4DsY/D3dSX0Sn8qUSlb4+w7IiwGZEDi9NyDxe0IAAARdUF/MiP/8aukATIJg+d+F7+fx93Mn6dkSn9xLP0/UHxNRCoLcEBj5nUmNAAIAYIbplZS2+Os50lQyCJbi62lKcPKzpj1Myrf0bQT/UTUO4mNAZhpAAABYiV/04pkgbdEjTGXjQDoILkZBzZOCk9X9TtaDpIz381WE/9EpmTGQGgKj04AXBACAzrhf6iLq9KiTkyjQCIJ1YeBpYnD2M+U/Jlr71Im29AXE/DADpSCQDIEvvxvpEUAAACSs+j3d+ewjDEoFwSeVRxuflfEJmwlThM0zq/eLyH7uT66lryb8hwUQiAHxEEjcEiAAAD5fqHXE38j5ZmdRcFN5SuCfT0bPlnAi/YfOSYyB0hFAAED3hIz7sy+cFRx30o+COp9a6Fn2ZjeeinxfGxJ+VgzohMDUlsDY9IoAgK5X/evln3px1VwtVXLe2UkQHBR4AZL4Wx5NHxVdWPoPG6VUCKz5Tq+LAAIAOt3rfyO46o+/cO67OO7k5elotkcR096QmBILM3/OzOco8srcaqX/SxR7n4n739nFgFYELK975wLg2u6TBUBPyK364y6e9R11MogCR88mOHis/Orl4i9/Kix9RdnvGSAWBbkTgcDfkbEtgeX17+RaSABAN4zf6Kcn/nrPNudHQQtBUDe/NiB9e9HnRYFEDNhFwHBt9/sFQOvs3H0jsOqXEL+z406GUUAQ+F/ll5e+b+HHBYFlCMRvCSwjgACA5pka+UuKv7m7n6sLgl8RfnXSFxT+oSJWMZASAjHTgAsRQABAs4yO/FNX/Rrib+6Ik7cg+LUP2Zd4Ep+A9N2JXikKokJAcRpwMQIIAOhI/jEj/1Txd3jcyVMQPPL7AiTR90KoPFNCS/oZwj+sCOkYyJoGhN0XQAAAI39t8auI95cE6npcqt3zCKwjQfnFT9KnTiylLyLjD4LoBYFUCKRsCZxEAAEA7ctfaNUfdQFVFLz8USaDSPAWBGJvShRE4GfZL3pG31L6HwrjIQTytwQIAGhj5H9r3VP9Qkf+pcX/i6u7n03CwNPRQ4tQUPg84g+RspJ+dbIXjILcEBDeEiAAoAH5v1Qb+euIv86jTqpR8KjSKDDEh/AtpP+hAXJDQHAaMBEBBAAgfxPxKwlf6QhT8SgweKxx/aK3PGaqKX0dCe9m4CEGcqYBoREwXNv7fgFQI2sf7pM58pcVf2XHnZoKgo9+3pAo/tKnjz6lX2CVPyvzB4moxEH879++cggQAFAly1+oLPmnrvojLpxNHXdqIgjkwsCGEk+N9Cl9ccE/kI0DsRgwngYQANCA/A1W/dLiP2yAZoKgZBwIfOaHXqUvLPxkab+PJC8IioVAQgQQANCP/GdX/SkXV23pOzzWVEMQPPxY4YuWrJ4c6W8/P0/2740JDwKNENiPCoHpCBiu7f2wAKgBSfnnr/oDL6DV3/3cUBDUFgZKD45yKX2XohcIgugYiA2BuGnAxesgAQDuSb/TP0T+CuLv4riTTRSYP82waskLHDVV/O7Gr/LfV8p0DCT/filsCRAA0KD8f02Tf8BFNe/i+aFhGpoQVIv2k/i0pf++QXKnAvO/N5O/CzMRQABAXfJ/HCj/2JG/mvjLn2m2O+9sHwT9RsEvRi/Z0Rztv++M1BCQngZ8uQ4SANCZ/AXH/RY3Q2kedzKPA7vnErQVBb8YCh/p1xwCsRFAAEA18j8wln/8xdT67ucazjv7mBLseXlLYsILoPZMHiSlJX1jud5XwjAEVKcBFyKAAADkbyh+X8edvEVBmacX7qm/Unn+zzV7LHQL0h8V9c+LGwrsHqEZBTohEBIBBAA4ln/anf6p4t9XEn+ddz6XjoKyjzSWiAX1FzQZPVOiuPSNRJ8dBuYhkB8BBABUKn+DVX/GhbTdPdGSUwK/UeBP9hVL36Hso4OgZAhE3BdAAADyD77gVrov6ujJaG6CwGsYZP9MH+qTfqXC148B/WkAAQBty99a/Nz5XHcQaIaCymf7YPD4XYRfNgb0pgEEABSU/2+E5W+/6kf8noPgQxsvXRJ8pgTSLx0DqSGw+jsjEQEEAFQr//iR/8jNWaLiLyRZ0+NLNQdBLWHwQechUg/KSP9Gx9JXC4HJ342wCBiu7T1dAFhSSv4Sq35T8c+eT/45glJnnWsJAutI0Pvcuy6kX1qy775wL5Kz/1ur7QGLLYE1EUAAQDvyjxn5exP/iNyLHmsqFgba72Bvi+LP2y8m/UTB56IQBhIhkLIlMGzsPV0AWFCj/NXEf7+eEenaMOjm6KFz2Zd6toS59AuIvkAQxIdA3pbAsLH/dAGgjb38Q0f+MxdbyYtpQ3uiZaMg710HVcu+5MOkzKSvv7Lf+YzXIIj/nQqZBqxGAAEAfcg/e9WP9IMvWl6nBAEvQXIj+cOSj4guJH0BoWtSIgbifpfiI4AAAH/yzzrml77qFxM/dz8rPSq1zLsOVEl6UdP7Bp7C51f0alFgsi0Qd18AAQDIX2rczzln50Hw3tfbFh84eTeEY+nvVIbmVCBpGjBzXwABADryv11Y/oEjf5FVP6v9ioPAQxyUfm6E4n9nN8J/G4hhDOSEgNA0gAAAcba05O9t1W8mfqWboozOOtcbBI1hsjVVQvhvDVGIgYTfwfDfkekIIAAA+bsR/zs/x50cxAFB0N5oX130dxUQjgLxEIjcEiAAoFv5Z438xcXv+Gyz4UNQ6nkeQU3Cf+/mrn0V4d91QGYQSP2O5UQAAQB9yb+4+OXOMJsdZXIaBd0HwX3rl+xof0cdyz45CHJCQOOkwPmbA4eN/WcLgByKyl975C8h/sqOOzElqEH27909ga874UfFgFUIxEUAAQBNy3915B9zwa1hX7SCMPB2L4HnOJh48dMNh4/dFZH+3caJjIHc36GYCCAAoG35x676c1dXDZ5t9vZ0NJMw0IqEgDc8Fnt7XmPS387AJgZSQkByS4AAgGT5/9ik/LUunjvujjwRBOEX0ohYmHl1s6+fz1D6JpL/SRHhOAj8XdSeBhAA0Lj8NVf9Be5+dn7eufUgqBvN+1B0V/l2ojeOgqwQyI8AAgCcyn/uTn+h/f7i4n/r57iTQRQQBEg/TvhCsr4TiEAQmIZA4O/GWAQQANCO/GNG/kmr/jpWS7ZhUCoIiIIyT+LT+e5mCf+OIZFBoBECqdOAdfcFEADQpfylbu7ztidaexTcYErg8AU7TqR/xykak4GUEAj4HbgYAQQAJMj/t/3IP+si2vtxp4JB0GQUvDN8ja689JsRflYQpP5O6WwJEADQiPylR/6pF9LOpF9TEFS1fZD3XoidGqV/p0EkpgIzvzvpWwIEAHQi/9xVf2nxj59Zjrtb2ey8s1EQ7Ki8AOmdneCF3gexU6P0VeX7RgCvIRA6DZj/HhIAgPyzVv1a+6Jvix5r2q44CHbuVfiSJdNHRbci/TcF0YmB3BCI3RIYNg6eLQDOkiT/xwLynznjv6sp/0Li93e2WeGIk4Mg2OlW9to38VmN9t84RyoEbKcBw8bB8wXACa7lH3qzX9QjVW3Fny38IseZCkWB4VMM65d8a9JPE/GWAuoxYDYNIACgA/nrrPrTL6RV3v3s4XGpBYNAIhZsP5f2Q3l8CX9S2t8JkxUGBiGQEQEEAHQo/8RVf3U3QpWOglJB8LapFy5FPT2yGulnyv47B0QHgWIIJEYAAQCVyF9ovz9l1e9utVRrFLwtuG1QaxjYPSbai/Rdyj4yCERiQHMa8PnmQAIA+Xcrf8lx/+zF805HeAqCu+XfkCj28ie1o6VlpW8n/NcTlIoBhRCIiAACAPnXK//gm/30Vv2TF9Bqjjt1FgTRYWDMXYvX5zqSvqrYpdGKgTIRQAAg/2rlLzvyFxJ/c0edOgoCi0go8DPY3Llvtcp/7ZD4GLANgfEIGK4fPF9AX2zdftWl/CVW/bLif1MpHQdBBWx7lH4zsheKgZwQEJoGEADIv3P5lxB/+XPNcuedrR+bWugBRS0J37X0XzdGbgjE/Z6kRAAB0JP8v+tB/rIjfxnxZ4i+0JGm/DBo+KSBC9n7EH510r89QukYSA2BmGnAmgggALqV/6fm5Z+/6s+5mFZ6tjkwDuoJgnrDIOu9EG6lbyj1CTY/E/2/1Y4BkRAIjwACAPm3IX/tVb/AxbPa880qUeDlscZvi8bBttQLoO50Iv0ZoWsiHwUpISC5JUAANM9SxMg/TP55436L405vyh1lqikI7ui+JTEdoc9jeLy0qPSTRP9KgYgoUAiBqN+XyAgYrh+8WECbFJP/Q4fyV1n1B1w4q7z7udSjUg2eTXC3Mu7Yv0K3mPSjhP/KATNBIPV7lz0NGL/uEQDIP1P+Hx3LP3HVb77ab+yIU01B4CEOVH+uN1VJ36/s44MgPQaEQiAgAggA5F+h/BVH/gkX1PgLZ2dHnWoNgiqxeN4+wreJgZhtgbQIGJYXbaSZzt3n/y2K/cOf1T7L8ma/+uX/s5H8rcX/uhNKBcEbhO/1uF4Xwk+IAfFpQPx9AcNSEsuL91IeCH1e9E/e/sPiN7/9ixhSYbD2jH+v8hdd9eeI38eRJ/szz0JR4O15BDUL35X0X3WMfAikTAPOBcAJRMCq8Ocl/uf1fBr5v8/8ecvAWP69yN9gv9+r+APPMIseZfL0UBTVIKglDNJ+ri0n+/lFpX9LkBpCIGNLYLgojqMtgZsvumO5Ap8W/hmxf/rz4mUmvznLRBicTgdGPveNe2/XPt1PS/770vK/byX/9FV/2MXU+rhTyAXWy3lnmyDYquXtiELvgtgqvcovLf1Zgf+YgVUYpISA3JbAcLRSXBMBR9OArqUvJ/voKFgTBKeTgTOff3W/H/mrrPqlL6BujzolhIHz+wi2qn3hkubTIyuUvorkBePAUQgEBe1pAHwWxuoI+bdHF9wWxT++l28r/KAgWBMDy88ff7Mf8pdd9fd0I5T2g1Bsjx96DwP590K8rkv6QqK/nkF2FEiFgHIEDCdyOI6A9dOAtlf7KdL/NyHiY+Dp+z8l7Pd/WhF/E/IXGfkrir/pG6FKTgn0X4CkFQlBb2b08sTIotLXl7xeHEjEQOY0IHBLYDgribEIWLJd6ZbAUvyrq/0Y6a8R96+CRETBD0ny/xX5x8hfUPy9H3eqLggSAiEJlc/72uChPOWEf905QTGgHgIh04CJADiNgAamAffWrfZThD8i7heZxAbB3ee/707+scf8wkf+Cqv+0QsnR56qu4+gCl43Lf3rFaMTA6HbAnERMIzJY3oa8Loi8Yes9qeFHyb1fw0gPgp++Pmf1sv/MfIXk7+A+JG+9yB43bfoS9yP0onw42MgNQQypgEj9wUMU/vGUxFwfIPgSzfEi39c+nmST2X171vKP3m/vyn5vxWX//Sq35H4bxnQbRB4igPFn41V/io3f3OMlxiwmAasiYDhWBYzETA7DSgn/uUef5L4Z6U/I+yPAkz8+Wkjf4fyf+BB/m/k5K8p/lsljjt5igNPQZATDg4+l0PpmwhdE1chEDoNmL45cDgVxoxYpiJg/+jeAGvxv79wc1+8+IOk/9GW79/9r7X/xvnH/FqUv+TIv4D43ZxrjowDgsAf1i/ZKSV9C9EbRoFECERHwJlpwHAkipgIKDwNiBO/pvT/ZfE8gxdHnP8z16/6Q/b7kb/qyF/qQnrL33EnPw9C8X70sHPhl5K+N+ErBUHePQLpWwLDqTAeR4bAxDRAKwTkxB8n/OeZsp8jb9WP/NPlH7vql7hw1nPcyX8QdBAFUe+DeFW/9GsTvnAMpE8D0rYEhot7xVLTgOWb29Ru8FMWf7C8f8ng858xuuoX2e9vS/7J+/2xq34J8Td697P9k9EUn1roKQ6SXv70qn7ptyR8oRjYlAqBgAgY9h+tCiQ0AuamAbkhsDLulxB/ivSDxf7PI6z+/x6++uOk+JF/OflnXWRL3gjlOgp83VyY9JbE0HBI+HPSXvZUofSVRbuhQKkYWPs7JBwBw4ksxiMgfxqQsi1wcdwfL/751X688P85mydv/3FxJ2vVLyP/vYblnzTyz1n1z1w4r3eI7yDIe2OinNQLvxfCakpViejNw0B1WyAsAoaz0jhQngaEhMC9578L3+dPEH+c9Kdl/iyCZdDcef67zFV/5DG/RwGrfjH5v/cj/6xVv8wF1O2RJ4LAJBI2Pb706Vad0o+X80thlIMgNQQETgkMX2QxEQKC04CxEIga98+JP3S1Hyj8Sbl/mOfwxz+O/ltEr/qRv5z8U1f9FuKv+GhT+0FQERVKX0TyB0IkhoHW7530NGA4Lw3haUBgCKSM+9fu8SeJP1D4a+X+p0lCxK8y8m9N/ndS5S+86tcSf+NHnFSCgCjw8SQ+E+ErS14sDIRiQGUasD4ChhVxBEeAXAgsefj6f4ys+oXEP7Panxb+n4J58tM/LO48+52Q+JVu9kP+GfIXuIh2ftSJINB+VHTt0ncm+6QgEIgB8WnAagQMp5KICYHICIgNgeUz8C+O+0Pv6o9Z7UsI/4QHP/79jPgTV/3IX+5mv3Mjf2Pxc9zJPghu9SB7o2dLIPyMIMgIgajfjfAtgZMIGM7JwmoaEBACZ2PARvzx0n/80/88Ev/czyG16kf+efKPWvVLiL8X6bsMgh+dvgBJV/ae7kOJkv5Bw0zEgNo0IDAChhVpTESA+DQgMASOYuDVfz96Yl6q+HOk//SE9zHSzxB/9n7/3Bl/j/LXvdkvXv4+xF/VsSb3QRD4AqRbJQVf+DHRat/XjoRfKARSImBYLw/9aUBqCCxZPj3v8CgI/lFF/Ceyf/r+n06FPz/ePyP9aPEj/zz5C43811x4fayWKj/v7PbGwoxAECPus3l8uY5v6b9IxCoGEn7XBLcEhqUsUiJAMgRW7xEIj4ETlk/WO+LHP54Xf4T0l6I/IfbvPyt9KfHHj/yRv/mqX134L41wEgWuHmdcFs+vzvUj/TTBX/tM8ThQCoHQacCwdxQAMRHwUS0CcqYCZfiUIX7pVT/yT5J/6qrf4kYoq4to6QehOHpwUTOSb1L680LXRDUIUkMgMwKGs8LwMg0Yj4FPDUg/Y9WffLMf8g9Z9WtcSKu/8zkjCloIgmpRvwdF+3sbKfp9A4KjQDYENCNguCgO8WmAQAiMx8AnO+FnSz9W/Mg/Xf4Kq36RC2cjN0IlRsF1osC98MtJP1D4+86YDQJvIXD+voDhSBAxEZA6DRAKgZUYWBsFn/JE/2T933EgIX6xVX/8Mb9m5X87Xf6SF9eu7372FAQ9RIHZy3Vspe9e+BFBkB0DKdsCkREwnMriYWQIPJLYFsgLgckgECD/s/2qtOpH/iYjfynxd3/kyUEQ1BwF5m/T0/ruNij8pBgoNw24GAHDyri4yDRAJgRCQ0H/75oX/+yqH/nLyT925J98Ee1c+rUFgac4MPgZPUi/aeFHx4ByCATcFzAcCyIkAhSmAQVjwI/4JVf9Lcr/taj8JS7EZcT/QgGCQDUWCn/Ock/iKyH95wY4mAoIR8DwRRTTEZA2DeghBH6VEz/yV7jZT27VP3oRNRa9zlGmwoFQcxA4wqX0qxO9URTkTAQu/I6kButwXhi/mEwD4kPAWxCES3+9+GNW/b7kf6ND+euKP1HyQseY4iPBbxBsIHvjo6YW0n9eGYYhIDANGNaJw2oaMBsCrmLgVx3xz6z665X/2zLyjxn5R19kJS6igbJ3cqzJ7EEoSkGw0ZXwLU6daEtfUMZ7mVjHQFYIpEXASADERIBRCEzGgHQUzPw9j7TFn7nqR/7Cq/7ci2kDN0IdGD0IxeABRd7DIOsx0Qe1SV9P8FczkI8D5RBI3BIYToQRFAGp04CIEAiOgaAgECLw8wSL32TV34j8b8fIP3/kLzvut9gT9RUF/rYNXrp6EVLei5leFnvsbnHpK0heNA6UQiAnAjYCImA4lcVoBGhPA4RiQCIMEv6ufTHxj6z6kb+c/E1W/Y1LP/vJaC+cPLXwpeM3MJZ6L4SW9POFf9U5ajGQPA0Ii4DhnDRiIkB8GjAdAskxoMC+gvjDVv19yX8zUv4yq35B8avKttAxptqDIPgFSJqREPD3FnpdbjHpiwr/mSAWMaAQAoFbAsOxGM5HgMk0ICME9muR/qz481b9UTf7Hcn/Z+QvLv8KbobyFAlegyA5EDIo8rNp3o9iKfxnhdGIAfsIGM5LQmMaEBACmTEgHQVhf9/HbPFnj/wjbvZrSv6hN/tVI/5Gjze1FARVU7v0n1VCYAyIhkDclsBMAMhHgGwIxAWBPB+NxY/8/clfYsz/vBFKBQFRkHXUdL+M9NsTfloMhE8FBG8SHLkvYFgvjowtAakQCI6Bj2WF/+hj+M/zcPzfJm3kn7nfX6X8f5SVv5n4C55nVj3rrBwFBIGTl+xoSv9Z4+RMBXQjYJjeNw6dBiiHQFQMxARCxp/5ME78uat+5J8n//RVf474/R930o+DUkcPX3Qje71nS1Qm/V1lvIZAzL0BF+4LGGZvHMudBkiHQHYMWElfWPxRN/sh/7Kr/nTZuz3aJBYGJR9QVFsYvDAWfiXS33WEcAxM/44JTQPORMBwtEf8IASdaUBWCGgHQernmRK/5qq/cfnnjfwtVv3tnW+WfQhKmfsI4l6E5Efydo+K1pK+F9k/jcQyCDSnAfNbAsNSCKkRIDkNOB8CGTEQEgoaf/ac9CPFj/xLyD9F/Fo3Qlnvj3qJAm/vObBB/MVPSmf01b+vmXK/okByIJQKgYgIGE7EkBQBqdOAmRDY0w4BF+KPGfnLy3+nYfmnjfxj5d/L3c9CUeD1uQT7eq9Ujn5ds5cHR+0ZSj9R9lccEBUEaiGQtyUwnBXErto0ID0E/MXAL2HSTxB/6qp/9pifS/m/ciJ/HfG3f/dzw0EgGAvlPuvzBqTvR/ZiQZAbAsIRMKyThd40YCIEomPgF5/SzxE/8heSf8LIP/eiGnTh7POoU9NB4IbnDUi/LuHbxIDANGBiS2AYk8axXLSmAfkhsD4IcsNg9c/ay5b+L7P/FtHiDx35I/9J+Wev+oMunorSNT3CpBsF7m8sbEH4lnfudyb8rBiwmAaMRMAwJY+4LQGFEIiMgfkwGCf178kWv5r83/Upf9GRf0HxV3esyXMQ1B4Gcg+R6kr6NzJQjQGZEBj/3QjZEggIgPgtgfXbAiIhkBED4hzmiX/9qj905F+r/OVv+Mva789c9dtfOGs97+w5CLyFgdDP40r6ysK/UYCiISAzDTi5Fg5HsgiKAItpQEQMHHoSfqT4E1f9Qfv9yD9z5G8kfpPzzIrnnXedBcGe1/cfGHwm65fslJB+kJx/UEY+CkZ/D1OmAQkRMByJIjAC4qcBRiEgGQUpf6em+BP3+5uQv8id/qGrfmXxOzrXHHbe2UMUlH5qoUP2Cr1Vz1r6RUWfGQVmIZC5JXAaACfERIDJtkBmDKjyIUP8yD9f/i915W8mfv83QmWFgaeTBrVFgcijoiuRfhWyTwiCUiEQGAHDRXGERkD2NOBMCMTHwAe3wpcU/27ofwvkLzvyH73YSlw427jzOTkKPD6kqFQgzHyOqyWeHFlc+jaivvwZrzGw9vdKYUtg2LkYAClbAkVDQCMK0j9DtvhjVv29yl9kv99S/Bx38hwEUXEgTP5nflaP9BWFf9kAsRgwCoGQLYHhrCxspwFrQkA0BuzYFRR/uPznxP9uVPztyj9v5J98gZ24cF7pmPJBIBcGPrB8hoRP6V92hsVUQDMChovSyJsG6ITAbnXS/xD/byC66kf+Jqt+y9W+4yNN9QWB9zAo9dAof9K/XBmaU4G4EAi7L2BYJ48bEtOApBDwHQPz0k8TP/IvJ/+kC7Dmaj9K4EJHmArFgb8gsAoEo89fVPoFhL9zlu+F+PznqcZAbAhkTAMuXAOH4z3i9SLJiYD0bYGJEDAOgl0t6aes+jP3+1uWf/R+f+qqX0P87u5+LhcF/oPAObulb+IzEr645BPDQDwG9KcBFyNgOJLDiTiCIiB2GpAbAjMxsCYIxhgV+xhzf2+G+HejYuqdgPx/alf++7nyNxR/tUedSj029amzxxnXJHt/0q9T9rJBIBsCiRGwdzYAYiMgaRogEQKBQRAaCLF/Tu7nvq+x6teW/5tK5R868jcQfxPnm8tHQdZDihB+HdKvQvYyQSC1LbDyOxERAcM5WUxEgMQ0IP/+AKEgsBJ+jviDVv3IX23knyt+ReGXO8qUEQVen1y4W6vk1z89Euk7xCAEwrcEzl8Dh7XiUJ4G6IVAShwo/t1J4v957b+xF/lvFZX/CyH5+xd/XUebfATBFel3HUiGguhnsTppovSdbV34iVMBiW2B2C2BYUwe0dOA5BCwjAEjUsUfLP9p8SN/qZF/6sWzzaNONQaBehSo89T4aCnSLz0VEJ8GTETAMCWRtAjoOARyxC828leQ/3fe5Z+5328sflEx7wTgOgrKPZ/gqps4MHwBVEfSv3SOJ4Ec//97mArkTANCI2A4FsX0atJqGrCyPXC/HunvZvy8ciN/5J878tcSv+/jTnKhUHMQhEVCHkV+DivpFxD+rNy3E5kIBMsQyJ8GTG8JDF+EoRABmSHgNgbu5672Y8WP/MXln7rqj7iItnEjVF4ctBYEVXDD8Iy+0fd2VPTbBdCMAuNpwHBOGnd/mo4A422ByRi4X0b42dIfGfenrvpl5P/apfyvRco/deRfRPxV74laPB2NICjxMCkv3921wt92yoXPaR8C6REwHMnh7kW0pgEyIbByz4BkFKz7M4U+c5z4pW7261H+gqv+wAsqN0I5C4Ibvcle+Ul8yt/dFeFvV4xkDAhOA9ZFwHBOFDER4CQEVqNgJAyC+FlQ9vPjfv2Rf8Xy39eVf9zFNuMCypEnPycNaguDGzqPivYj/UaEHxQDVvcHxEXAsCIM4S2BEiHginsaq37kny5/A/Fz5Els28DsHQel4kDlxU8+pX+pF+nPxID+NCD85sBhrTjuyk8DuguBaPEr7vcj/zD5B1xwEX8LEwKBNyWqUOhpkUi/oqlA5JbATAQM46vHnAhIDIF7tYfA9M+WI/6V/X5J+d+uSP6hd/rHjvyzxG95pvmJENbnnXWC4LKnNyXeKPd2x8uupF9K+I8VcRYCQtOA4YswQiJAbhowHwLvql/tq636hY/5tS1/xVV/7ceddkqcd9YPgstNvGipHuHbS/+xE0qHQH4EDGelIRoBUiHgNgbeqYtfbr+/RvlbjvzLid/1USdXUfBDt1GQ95TI2qUfKeUtJSyCIPUegaDv+voIGLbOBcBEBGRPAwRC4DQG3rkU/rz0353/9xAZ+SN/aflrir/6PVFvUeDyBUiFXv5kcj5f+7ubJ/lvFUiPAssQiJgGnAuA746lsR0aAtnTgLcBkgyMAdUJQdxnkBW/vvw3G5a/+Ko/88J6TvpN39RUOgr0331w2dNLnsyewldY+kaizw4DDyEQGQHDqShiIsAwBKJjYHRiMELGn70jLP7UkX/X8t+Vkb/0BbZ56Xe0deAC4xMmutKPE/63laAWA7G/QxH3BQznhHFnXQgoREBiCGTHgAA7VuL3Kv+RACgv/5CRf8yqn4ebtBkEzsNgp9xx0mLSr1T4eTGgPQ0Iuy9gWBWH4TRgJQTiYmDHlfDTxJ898kf+0/I3WvWXk36hI0zNBcFIIEiGwk5Zwdvfj1JS+I8EcBgDUb8v8xEwHAtCIwJsQyA3DHay0RZ/yH4/8s+TvzfxV3qsqckgaIO2pP+oIJkxIBACElsCw3lZrEaAeQgoxIAeb5PEv/YOf42Rf+PyF9vvT1iRyV9AM+WddXzJWRwQBM2N9uuWvXwQjP9+Kk0DRiJgWJWGwDTgjkAEuI2BdOnnrvrT5f+qQ/nrrPrlLqQFzzSLxQJBwCpfS/qCct6MxDAIskMg5t6ANREwrJfHGz/TgMkYeGsv/Htpn307etWfsd/fq/wVV/0yF9N42Rc91hQdBqWmBAi/6FE9ke+roeBzcRoCKfcFDKMCUZ0GZIbAaAykxkHAn3W3jPij9/uRf4D8LcVf/53PxZ6MxpQg7FHR2zVKvwLRiweBcggEf+/PBsDtqQAQnAZMhEB2DERFgZ7s88WP/MflH7/ff1lC/krSb+qYk/aT0UTfdVC57HcKniqxlr6itL/5TLkgSAkB4WnAMgA2b395LGxUBIxOA1JD4Ce5ECiIqPgjR/7IX2bkn36hbVv6ck9G83bqoFwcTL7h0cNRUkvpCwh9moczTP/vdWJAKQQCI2A4FsOxOEynATMhsF2d9FPFL7nqb0T+Ucf85Eb+l5JX/drS93mkqZkgCH5DogLFflbNrSk94aeJXZKMKEj8HdSMgOGLIDIiIGcaMBkCfmNgUvo54kf+heTvQfz1H29qLgia4XGV0i8r+/gocBcCM5Ot4bwozkSA6DQgMAScx8Cs9BPFn7TqR/7T8g8c+aet+tdfQNs722z4hLStx3U+1bBb6VsI/2GFRMRATggITQOG9dLInwbohoBNEAQJP0r8Qqv+0Jv9WpO/8H5/GfE7Ou7kLAoIAruX7HhZ5dcvfIEYMJwGBAZATASkTAMiQiA4Bs5HwTpWxb6OiL/rTrr4p1f9Ujf79Sh/jZF/rvgrPO5UbRA8RviOR/vqI/3rCljFgMU04EIEDLMryJwtAekQiI4BBe4IiV995G/wSt+D+uQfd/NVjvgrP9ssHgYln0fwuH3Ziz5bQlP6jkVvFgayIZATAcORKAIiIGsaoBECVkGQ+rmixS+/34/8hVb90uLftDjyJHiUSSUKSgeB1zDIe/9Dk9K/XgkmISC0JfD55sDhdLUYEwEeQyAnDsT+zjcq4vck/w1v8hff71+9yGZfPEUlL3+USTwSPN1YuOXpZUiyL3syO15qLf0sER8qoRkDwiEQEQHDF2GERIDQNCAoBIRjQJVU8cfI/xXyT5D/pVT5B11kK9kXFQqEGoPgW/EXICmzpf1eCIfSdyV6hSiQCAGlCBjOSsN8GhAcAm+qkb6I+GNG/hl3+rcv/wLib+Zsc1gY1BgEQWGgFQkBf5/sz/moAemnCfrrDNSCwCgEVr+7IwFwIoj4CIidBoSFgO8YeGMiftGb/VTl/6KQ/L9Xk3/yBbXb407tBEFWJGyVkLvdiZPs76+S8L8ugEgMBP5uyU4DJgLgfAQkbglIhEB0DGhFQdjfuyUl/qRVf4vy/8FI/kKr/m7POHsLgkfNv2vB+oipnfR9il4uCnJCIGYaEL8lMFwUxqbENEAhBOJiQJdw6YeLP3Xk37L8Y+/0v5Qofz3xV3bcycujUkWfSdC58JOlr/l9LSD8jUBKxUBqCMRsCayJgGFMHnYREBACDmIgTvpvwn/2GPEjf7mR/+yqP+5iajsirT0MSgZBLWFg88TIb5xI30TuEojFQHoIpE4D1t0XMBoA6VsCyiEwEgRbWrKPkn6c+FVG/shfZ9UvvWISF7XA0aViUVDqpEHpOBD6vJudSD9a2A8ykY0CuRAInQbMR8BwJIeYCDAJgcgYmIiCJFL+bi3xI39D+SuL3/1RJy9RIPRMgq1G2axT+jrCf1CAvCCQDIHcLYHhnCgUpwHpIZAYAya8zhC/9ci/c/lvycg/+iJa1blm4TDwFgSbfcje/qE8QtJ3J3qBKIiOAYEIiJgGDCvSUJ4G5IXA67qkf0b8uat+5B8rf9lVv7z4D10cdzKNAk8nDTzFwabG46ErkH7Vwo+MgRIhEBABw1p5zIyZ06cBkiFgFQSJnytV/Bojf+QvIH8b6ddztMn6cakGDyiqiG+KPG9fU/oPGiUuBvJCID4ChjGB6E4DNEIgNw6E/s4c8ceM/L3Jf09A/jNP97skJn/hVX+pu5/dR4GPGwtrjwKVJ0deR/rFYyDnHoGsGwTPBMDGVACkTAMkQkAlBpRJ3eNPGfn3Kn+R/f55+eeLX1H4hY4zyUSBn+OH3uJA9+VPBe7cLyT8rxTwEwLy04DhRBhlI6DSGLjtR/zhd/rPvdLXo/zjbvYLHvmnjvsjL56uzzUrBUIdQRD+hsSUWIh7VbPCz3TdUPrGq/xJaV+b4/4FZv7/VcNAIAQyImA4XikGREChEHAXA6PSfx3/cyJ/AfnLjPyDLsQRF1B52Rc60iQUBfUFQWo8FP4sDUo/TPL3DZgOA9sQkImA4XRUfEYichGQGwIzMXDbVvgi0k8RP/KXk3/Kql9a/NXc/awXBf5PGlSA8HMlvEh/Wvb3nbE+CLRCIG0asGZydRoAJ3KIiYAiIfBqjXzXBEFqGIz8OZtS0h8Rf478N1Lkv4/881f9CRfPpm6Cko+COp5H0KHwDaQ/Lvz7FSIVAzEhkDgNOBcApxEgtyUwui2QHQLjQTAbBlGizxS+yaq/Y/lv5cpfWfzd3PlcKggOnb78qNQLoA7rlH7VwteMAf0IGFZkcVN+GqAfAmFREIbw5xFe9cfd6d+2/FVG/rni57jTfBR4DQKLSFB//4NP6X/VjfTDYqBsCEwFgNKWwOS2gEoIFOSWjviRv/LIP+AiG37xfAAuguDQ95sWFR4V/bVH6Xcn/JkYyAkBwQgYJgVy0yoEGomBHPGLjvyRv/Sqv5T4vzKknyDwHAeH+o+JZrRfcQiM/56kRMAwLxKdCGgqBBTFn7LfH/yAH1H5P21E/mXEH3emWfAo08xZ568qDYKvPb0lUfClT7IPj0L61YdAzDRgzfVvOBFGWATohECVMTAh/c2In1t65I/8A0f+qat+oYvoV66PO83HQY1BIB8Guug8MRLptxMCCdOAiwFw7TQAlCJAJAQuxMCt0sJ/Nfo5r2ut+pH/tPy1V/0CF9L6b4QqGQXeHmvsQPIlz+cjfX8hkLAlMBzJ4bM4giLAKASiYkAjCm4pSD9A/Fn7/d3IX2fkH3Zx5aI5d9SpeBBs1PeSJdlHRSP9lkJAMwKGU0mciwDFaUBCCEzHwEwUZPGjjPTVVv1O5X/DofyzV/2JF85ejztdcxYEtYZBgcdEI/1apwHxWwLDijBiIqBACITFgA7XlcSfLf/9VuT/2Fz+kuJfvXByASsXBA+KviFR7+VPBi/XQfpthEBABAxrxSGwJWARAtpBkPu5NMWP/JVG/jni58LpPAgSw6AYhq/N5bvb2LZAWAQMowI5MJ4GCIRAaCio/j0RPy/yt5T/zMg/4cLLar+VICgVCLY/F8LvbRowHwHDsSQmZBIbARIhYBAD9Yk/ZL8f+Vus+hF/b0FQJ6zymQaMhcCFAJiPAIlpQFIIeI6ByJ9jQ2LV36v8Nfb7I1djiJ8gQPrQ0pbAsCINg2lAcgh4iIGEz7yRuepPGflryf+KtPy3Sssf8bcSBF/1LnuEz5ZAZASsCQCFaYBGCFgFQcZnyxM/8k+Xv/CqnwsqUYDwoYlpwPkIGE6EERUBqdMAzRDIDQPBv3tU/CmrfumRP/IPkj+r/raj4KvaRO/qUdHQSgQMJ7JYHwFK04CJEFCJASPyxR+66s/d729E/gojf8TfSRRcK/OGxKA3M15D9pDJ7Pf3+Ho4nJVGUgTkTANmQmCjSukLiB/5l5M/F1ziICIQkriG5MHHNGA4FsSFCLCeBpwLAf8xsCEq/oxVf+Pyj73ZL3Xkz6ofxF6rjNShoggYvoji+UJ+GqATAhtNSD9/1Y/8WfUDAKRGwHBeGKERoDwNWBsD00GwYSL7NdK/mfizBa/6Q0b+yD9W/qz6AaC3+wJmAmA1BK5lTgNEQiAhBuSRkH7mqr9G+W97lj8XBQDo9+bAYfSomNQ0QDoERoPgpZ7sbwp83ijxZ+z3X5D/lSLyf2Iv/5j9flb9AMCWwGI4EkVMBKROA7RCYDIIMhD7bC/yxv0x+/3dy5+RPwBAaAQMp8LYiwyBfckQEI4BF7xQWvUjf0b+AAD5ETCc3ys2nAY0GwJC4k/e729X/sn7/az6AQBWGJZiCI8AhWlAEyGwRvoHgT+74Mh/9Ga/3fXiR/4AAJ0HwHEEPM2LAMEQqCMGXsiLP2PkHyv/yw3Ln5E/AEBEAKyNgIgtgflpQEQITMbAi4qlPy1+5C8kf1b9AABxAfAlBJ4pTgPSQ2B9DLwwE3669AVX/d3Ln5E/AIBaAMRPAwxCICoIQiNh/n93LVv6Wqv+iZv9WpM/+/0AAHYBIBEBqiGwJgbSwmBE9NnSFxR/9Kof+QMAwFwAnAgjJgT2nIVARBjoiD5Q/MhfVP7c7AcAkBUAPyySIiBnGjAbAoIxYMZzZfEjf+QPACAeAGEREH+DYOsh8DxD/HHyv5Ir/x2P8j9Mlz8jfwAAqQAID4GrRULASxA81xV/zMg/+AE/yB8AAGYDIGMakBgCV5NC4Llb6cuIP23kj/wBACAoAC6vDYCYCEiZBgSEQHQMSIRB4t+XK/6kVT/yBwCAzAA4wVMIyMWAErPSTxF/uvxjbvZD/gAA8P8BH8l/mUKxpUMAAAAASUVORK5CYII=",gr={STOPPED:0,PLAYING:1,PAUSED:2};class et{constructor(e,n,r){this.x=Number(e)||0,this.y=Number(n)||0,this.z=Number(r)||0}add(e){return new et(this.x+e.x,this.y+e.y,this.z+e.z)}subtract(e){return new et(this.x-e.x,this.y-e.y,this.z-e.z)}multiply(e){if(e!==null&&typeof e=="object")return new et(this.x*e.x,this.y*e.y,this.z*e.z);const n=Number(e)||0;return new et(this.x*n,this.y*n,this.z*n)}divide(e){const n=Number(e)||1;return new et(this.x/n,this.y/n,this.z/n)}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}copy(){return new et(this.x,this.y,this.z)}toArray(){return[this.x,this.y,this.z]}}function mb(t,e,n){return new et(t,e,n)}const xa={primary:[.96,.65,.14],secondary:[.08,.11,.18],tertiary:[.66,.74,.88],text:[.96,.97,1]},pb=[{title:"WebWallGL",artist:"oneincase",album:"Scene",albumArtist:"oneincase",duration:212,colors:xa,thumbnail:Aa,lyrics:[[0,"\u573A\u666F\u4E00\u5C42\u5C42\u4EAE\u8D77"],[12,"\u9AA8\u9ABC\u4E0E\u7C92\u5B50\u5404\u5C31\u5404\u4F4D"],[26,"\u811A\u672C\u5728\u6C99\u7BB1\u91CC\u82CF\u9192"],[41,"\u628A\u6BCF\u4E00\u5E27\u4EA4\u7ED9\u65F6\u95F4"],[58,"WebWallGL"],[72,"\u573A\u666F\u6B63\u5728\u547C\u5438"],[95,"\uFF08\u95F4\u594F\uFF09"],[126,"\u56FE\u5C42\u6392\u6210\u661F\u8F68"],[140,"\u6548\u679C\u94FE\u4E00\u5BF8\u5BF8\u70B9\u4EAE"],[158,"\u6211\u4EEC\u4E0D\u6E32\u67D3\u9ED1\u6697"],[176,"\u53EA\u6E32\u67D3\u5149"],[198,"\u2026\u2026"]]},{title:"WebWallGL",artist:"oneincase",album:"Web",albumArtist:"oneincase",duration:187,colors:xa,thumbnail:Aa,lyrics:[[0,"iframe \u91CC\u6709\u4E00\u5EA7\u57CE"],[14,"shim \u4E3A\u5B83\u70B9\u4EAE\u8DEF\u706F"],[30,"\u6307\u9488\u7FFB\u8FC7\u5C71\u810A"],[46,"\u4E8B\u4EF6\u6309\u65F6\u5230\u8FBE"],[63,"WebWallGL\uFF0C\u7F51\u9875\u6B63\u5728\u64AD\u653E"],[88,"(instrumental)"],[118,"\u6BCF\u4E00\u5E27\u90FD\u662F\u540C\u6E90"],[134,"\u6BCF\u4E00\u6B21\u70B9\u51FB\u90FD\u6709\u56DE\u58F0"],[152,"\u7F51\u9875\u6B63\u5728\u64AD\u653E"],[170,"\u4E0D\u505C\u6B47"]]},{title:"WebWallGL",artist:"oneincase",album:"Video",albumArtist:"oneincase",duration:241,colors:xa,thumbnail:Aa,lyrics:[[0,"\u89E3\u7801\u5668\u63A8\u5F00\u7B2C\u4E00\u5E27"],[16,"\u5FAA\u73AF\u70B9\u6CA1\u6709\u7F1D\u9699"],[33,"\u5E27\u7387\u8D34\u7740\u5FC3\u8DF3\u8D70"],[52,"\u753B\u9762\u4E0D\u65E7"],[70,"\u65F6\u95F4\u4E00\u76F4\u65B0"],[92,"\uFF08\u95F4\u594F\uFF09"],[130,"\u628A\u50CF\u7D20\u4EA4\u7ED9\u786C\u4EF6"],[148,"\u628A\u6D41\u7545\u7559\u7ED9\u773C\u775B"],[172,"\u4E00\u5708\u4E00\u5708"],[200,"\u90FD\u662F\u7B2C\u4E00\u5708"],[226,"\u2026\u2026"]]},{title:"WebWallGL",artist:"oneincase",album:"Live",albumArtist:"oneincase",duration:168,colors:xa,thumbnail:Aa,lyrics:[[0,"\u9EA6\u514B\u98CE\u542C\u89C1\u623F\u95F4"],[11,"\u9891\u8C31\u5F00\u51FA\u516D\u5341\u56DB\u4E2A\u7A97\u53E3"],[24,"\u6B63\u5728\u64AD\u653E\u7684\u6B4C"],[38,"\u6709\u540D\u5B57\u4E5F\u6709\u5C01\u9762"],[55,"WebWallGL \u5B9E\u51B5"],[76,"(drop)"],[104,"\u7CFB\u7EDF\u5728\u8BF4\u5B83\u5728\u542C"],[122,"\u58C1\u7EB8\u5728\u8DDF\u7740\u5531"],[146,"\u2026"]]}],Ta=3;function qd(t=20260901){const e=pb,n=e.reduce((w,y)=>w+y.duration+Ta,0),r={hasMedia:!1,state:gr.STOPPED,title:"",artist:"",album:"",albumArtist:"",position:0,duration:0,hasThumbnail:!1,thumbnail:"",primaryColor:new et(0,0,0),secondaryColor:new et(0,0,0),tertiaryColor:new et(0,0,0),textColor:new et(1,1,1),highContrastColor:new et(1,1,1),trackIndex:-1,lyrics:[],lyricLine:"",lyricIndex:-1};let i=0,s=!1,a=0,o=0;function c(w){let y=0;const b=(w%e.length+e.length)%e.length;for(let v=0;v<b;v++)y+=e[v].duration+Ta;return y}function u(w){let y=n>0?w%n:0;y<0&&(y+=n);let b=-1,v=0,k=!1;for(let B=0;B<e.length;B++){const N=e[B].duration;if(y<N){b=B,v=y;break}if(y-=N,y<Ta){b=B,v=N,k=!0;break}y-=Ta}b<0&&(b=e.length-1,v=e[b].duration,k=!0);const A=e[b];r.hasMedia=!0,r.trackIndex=b,r.title=A.title,r.artist=A.artist,r.album=A.album,r.albumArtist=A.albumArtist,r.duration=A.duration,r.position=v;const T=A.duration>0?v/A.duration:0;s?r.state=gr.PAUSED:k?r.state=gr.STOPPED:T>.7&&T<.76?r.state=gr.PAUSED:r.state=gr.PLAYING,r.hasThumbnail=!k,r.thumbnail=k?"":A.thumbnail||"";const S=A.colors;r.primaryColor=new et(S.primary[0],S.primary[1],S.primary[2]),r.secondaryColor=new et(S.secondary[0],S.secondary[1],S.secondary[2]),r.tertiaryColor=new et(S.tertiary[0],S.tertiary[1],S.tertiary[2]),r.textColor=new et(S.text[0],S.text[1],S.text[2]);const P=.2126*S.primary[0]+.7152*S.primary[1]+.0722*S.primary[2];r.highContrastColor=P>.5?new et(0,0,0):new et(1,1,1),r.lyrics=A.lyrics;let M=-1;for(let B=0;B<A.lyrics.length;B++)v>=A.lyrics[B][0]&&(M=B);return r.lyricIndex=M,r.lyricLine=M>=0?A.lyrics[M][1]:"",r}function l(w){o=Number(w)||0;const y=s?a:o+i;return u(y)}function f(w){s=!1;const y=c(w);return i=y-o,u(y)}function d(){const w=r.trackIndex<0?0:r.trackIndex+1;return f(w)}function h(){const w=r.trackIndex<0?e.length-1:r.trackIndex-1;return f(w)}function p(){return s||(a=o+i,s=!0,r.state=gr.PAUSED),r}function m(){return s?(s=!1,i=a-o,u(a)):r}function g(){return s?m():p()}return{update:l,snapshot:r,tracks:e,cycle:n,MEDIA_PLAYBACK:gr,skipNext:d,skipPrevious:h,play:m,pause:p,playPause:g}}function gb(t,e=512){const n=Math.max(8,e|0),r=new Uint8Array(n*n*4),i=t&&t.colors?t.colors:{primary:[.5,.5,.5],secondary:[.1,.1,.1],tertiary:[.8,.8,.8]},[s,a,o]=i.primary,[c,u,l]=i.secondary,[f,d,h]=i.tertiary;for(let p=0;p<n;p++)for(let m=0;m<n;m++){const g=m/(n-1),w=p/(n-1),y=g-.5,b=w-.5,v=Math.sqrt(y*y+b*b)*2,k=.5+.5*Math.sin(v*18-1.2),A=.5+.5*Math.sin((g+w)*6),T=Math.min(1,Math.max(0,v));let S=s*(1-T)+c*T,P=a*(1-T)+u*T,M=o*(1-T)+l*T;S=S*(.72+.28*k)+f*.18*A,P=P*(.72+.28*k)+d*.18*A,M=M*(.72+.28*k)+h*.18*A;const B=1-.35*Math.min(1,v*v),N=(p*n+m)*4;r[N]=Math.max(0,Math.min(255,Math.round(S*B*255))),r[N+1]=Math.max(0,Math.min(255,Math.round(P*B*255))),r[N+2]=Math.max(0,Math.min(255,Math.round(M*B*255))),r[N+3]=255}return{width:n,height:n,rgba:r}}function yb(t,e){const n=[];if(!e)return n;const r=!t;return(r||t.hasMedia!==e.hasMedia)&&n.push({name:"mediaStatusChanged",event:{enabled:e.hasMedia}}),(r||t.title!==e.title||t.artist!==e.artist||t.album!==e.album||t.albumArtist!==e.albumArtist)&&n.push({name:"mediaPropertiesChanged",event:{title:e.title,artist:e.artist,album:e.album,albumArtist:e.albumArtist,albumTitle:e.album,subTitle:"",trackType:"music"}}),(r||t.hasThumbnail!==e.hasThumbnail||t.trackIndex!==e.trackIndex||t.thumbnail!==e.thumbnail)&&n.push({name:"mediaThumbnailChanged",event:{hasThumbnail:e.hasThumbnail,thumbnail:e.thumbnail,primaryColor:e.primaryColor,secondaryColor:e.secondaryColor,tertiaryColor:e.tertiaryColor,textColor:e.textColor,highContrastColor:e.highContrastColor}}),(r||t.state!==e.state)&&n.push({name:"mediaPlaybackChanged",event:{state:e.state}}),(r||Math.floor(t.position)!==Math.floor(e.position)||t.duration!==e.duration)&&n.push({name:"mediaTimelineChanged",event:{position:e.position,duration:e.duration}}),(r||t.lyricIndex!==e.lyricIndex||t.trackIndex!==e.trackIndex)&&n.push({name:"mediaLyricsChanged",event:{line:e.lyricLine,index:e.lyricIndex,lines:e.lyrics}}),n}function bb(t){return t?{hasMedia:t.hasMedia,state:t.state,title:t.title,artist:t.artist,album:t.album,albumArtist:t.albumArtist,position:t.position,duration:t.duration,hasThumbnail:t.hasThumbnail,thumbnail:t.thumbnail,trackIndex:t.trackIndex,lyricIndex:t.lyricIndex,lyricLine:t.lyricLine}:null}const wb=Object.freeze(Object.defineProperty({__proto__:null,MEDIA_PLAYBACK:gr,cloneMediaSnapshot:bb,createSimulatedMedia:qd,diffMediaEvents:yb,mediaVec3:mb,renderThumbnail:gb},Symbol.toStringTag,{value:"Module"})),Xd=14,hs=[{app:"Safari",title:"GitHub \xB7 we-scene-renderer",url:"https://github.com/oneincase/we-scene-renderer"},{app:"Google Chrome",title:"YouTube",url:"https://www.youtube.com/watch?v=dQw4w9WgXcQ"},{app:"Google Chrome",title:"Wallpaper Engine - Workshop",url:"https://steamcommunity.com/app/431960/workshop/"},{app:"Safari",title:"MDN Web Docs",url:"https://developer.mozilla.org/en-US/docs/Web/API"},{app:"Music",title:"\u591C\u822A\u661F \u2014 \u76F8\u4F4D\u8FC1\u79FB",url:""},{app:"Code",title:"we-scene-renderer \u2014 text.js",url:""}];function Gd(){const t={app:"",title:"",url:"",index:-1};function e(n){const r=Number(n)||0,i=hs.length?Math.floor(r/Xd)%hs.length:0,s=hs[i]||hs[0];return t.app=s.app,t.title=s.title,t.url=s.url,t.index=i,t}return e(0),{update:e,snapshot:t,tabs:hs,hold:Xd}}function $d(t){const e={name:"",at:0};function n(r){return e.name=String(r||""),e.at=Date.now(),typeof t=="function"&&t(e.name),e.name}return{openUserShortcut:n,last:e}}function vb(t){const e=qd(t),n=Gd(),r=$d(null);return{media:e,windowTitle:n,shortcuts:r}}const kb=Object.freeze(Object.defineProperty({__proto__:null,createShortcutHandler:$d,createSimulatedSystem:vb,createSimulatedWindowTitle:Gd},Symbol.toStringTag,{value:"Module"}));function Ab(t={}){const e=t.target||(typeof window<"u"?window:null),n=t.viewport||(typeof window<"u"?()=>({w:window.innerWidth||1,h:window.innerHeight||1}):null),r={u:.5,v:.5,screenX:0,screenY:0,wx:0,wy:0,originY:null,lastU:.5,lastV:.5,lastScreenX:0,lastScreenY:0,lastWx:0,lastWy:0,lastOriginY:null,leftDown:!1,has:!1,moveCount:0,downCount:0,upCount:0,lastEventTime:0,screenW:1,screenH:1};function i(){if(!n)return;const d=n();r.screenW=d.w||1,r.screenH=d.h||1}i();function s(d,h){const p=d/r.screenW,m=h/r.screenH;r.has||(r.lastU=p,r.lastV=m,r.lastScreenX=d,r.lastScreenY=h),r.screenX=d,r.screenY=h,r.u=p,r.v=m,r.has=!0,r.moveCount++,r.lastEventTime=Date.now()}function a(d){const h=(d&1)!==0;h!==r.leftDown&&(r.leftDown=h,h?r.downCount++:r.upCount++,r.lastEventTime=Date.now())}function o(d){i();let h=d.clientX,p=d.clientY;if(e&&typeof e.getBoundingClientRect=="function"){const m=e.getBoundingClientRect();h-=m.left,p-=m.top}s(h,p)}function c(d){d.button!==void 0&&d.button!==0||a(1)}function u(d){d.button!==void 0&&d.button!==0||a(0)}function l(){a(0)}let f=!1;return e&&e.addEventListener&&(f=!0,e.addEventListener("mousemove",o,{passive:!0}),e.addEventListener("mousedown",c,{passive:!0}),e.addEventListener("mouseup",u,{passive:!0}),e.addEventListener("blur",l,{passive:!0}),typeof document<"u"&&document.addEventListener&&document.addEventListener("mouseleave",l,{passive:!0})),{state:r,pushExternal(d){if(!d)return;i();const h=Number(d.u),p=Number(d.v);Number.isFinite(h)&&Number.isFinite(p)&&s(h*r.screenW,p*r.screenH),a(Number(d.buttons)||0)},pushExternalLeave(){a(0)},beginFrame(){i(),r.lastU=r.u,r.lastV=r.v,r.lastScreenX=r.screenX,r.lastScreenY=r.screenY,r.lastWx=r.wx,r.lastWy=r.wy,r.lastOriginY=r.originY},syncWorld(d,h=0,p=0){if(!d)return;r.wx=d.offX+r.u*d.viewW-h,r.wy=d.offY+r.v*d.viewH-p;const m=Number(d.projH);r.originY=Number.isFinite(m)?m-r.wy:r.wy,r.lastWx===0&&r.lastWy===0&&(r.lastWx=r.wx,r.lastWy=r.wy,r.lastOriginY=r.originY)},normalizedDelta(){const d=r.u-r.lastU,h=r.v-r.lastV;return Math.hypot(d,h)},dispose(){!f||!e||!e.removeEventListener||(f=!1,e.removeEventListener("mousemove",o),e.removeEventListener("mousedown",c),e.removeEventListener("mouseup",u),e.removeEventListener("blur",l),typeof document<"u"&&document.removeEventListener&&document.removeEventListener("mouseleave",l))}}}const xb=Object.freeze(Object.defineProperty({__proto__:null,createPointerSource:Ab},Symbol.toStringTag,{value:"Module"}));function Qd(t,e,n,r,i,s,a){const o=t.size||[0,0],c=t.scale||[1,1,1],u=o[0]*c[0],l=o[1]*c[1];if(!(u>0)||!(l>0))return null;const f=t.origin||[0,0,0];let d=f[0],h=r-f[1];if(t.parallaxDepth&&(i!==0||s!==0)){const y=t.parallaxDepth,b=$r(y[0]),v=$r(y[1]);d+=b*i,h+=v*s}let p=e-d,m=n-h;const g=t.angles?t.angles[2]:0;if(g){const y=Math.cos(-g),b=Math.sin(-g),v=p*y+m*b,k=-p*b+m*y;p=v,m=k}const w=a&&a[t.alignment]||[.5,.5];return(w[0]!==.5||w[1]!==.5)&&(p-=(.5-w[0])*u,m-=(.5-w[1])*l),{lx:p/u,ly:m/l,w:u,h:l}}function Tb(t,e,n,r,i={}){if(!t||t.length===0)return null;const s=i.parOffX||0,a=i.parOffY||0,o=i.alignTable,c=i.filter;for(let u=t.length-1;u>=0;u--){const l=t[u];if(!l||!l.visible||l.destroyed||c&&!c(l))continue;const f=Qd(l,e,n,r,s,a,o);if(f&&Math.abs(f.lx)<=.5&&Math.abs(f.ly)<=.5)return l}return null}const Sb=Object.freeze(Object.defineProperty({__proto__:null,hitTestLayers:Tb,worldToLayerLocal:Qd},Symbol.toStringTag,{value:"Module"})),wt=t=>t,Ye=wt(Rg),Sa=wt(Qg),vt=wt(B0),wn=wt(N0),ft=wt(yy),Pb=wt(wy),_b=wt(Sy),Fr=wt(Vy),ms=wt(ob),Ke=wt(v0),Eb=wt(lb),Se=wt(wb),Yd=wt(kb),ps=wt(ay),Cb=wt(xb),Ib=wt(Sb);function Mb(t,e,n){return{camera:null,general:{orthogonalprojection:{width:t,height:e},clearenabled:!0,clearcolor:"0 0 0"},layers:[{id:0,name:"media",visible:!0,image:n,textureName:n,particle:null,puppet:null,solid:!1,isContainer:!1,isPostProcess:!1,isText:!1,isSound:!1,isComponent:!1,sound:[],origin:[t/2,e/2,0],scale:[1,1,1],angles:[0,0,0],size:[t,e],alignment:"center",color:[1,1,1],alpha:1,brightness:1,colorBlendMode:0,copybackground:!1,parallaxDepth:null,animationLayers:[],effects:[]}],properties:{}}}async function Bb(t){const e=await fetch(t);if(!e.ok)throw new Error(`HTTP ${e.status}`);const n=new window.ImageDecoder({data:await e.arrayBuffer(),type:"image/gif"});await n.tracks.ready,await n.completed;const r=n.tracks.selectedTrack;if(!r||!r.frameCount)return null;const i=Math.min(r.frameCount,300),s=[];let a=0,o=0;for(let c=0;c<i;c++){const{image:u}=await n.decode({frameIndex:c});a=u.displayWidth,o=u.displayHeight,s.push({bitmap:await createImageBitmap(u,{premultiplyAlpha:"none"}),durationMs:u.duration?u.duration/1e3:100}),u.close()}return n.close?.(),{width:a,height:o,frames:s}}function Rb(t,e,n){if(t.audioBridge)return;const r=window.AudioContext||window.webkitAudioContext;if(!r)return;let i,s;try{i=new r;const l=i.createMediaElementSource(n);s=i.createAnalyser(),s.fftSize=256,s.smoothingTimeConstant=.75,l.connect(s),s.connect(i.destination)}catch(l){ce(t,e,`media \u9891\u8C31\u63A5\u7BA1\u8DF3\u8FC7: ${l?.message??l}`);return}const a=new Uint8Array(s.frequencyBinCount),o=new Float32Array(64),c=new Float32Array(64),u=()=>{if(i.state!=="running")return null;s.getByteFrequencyData(a);const l=Math.min(64,a.length);for(let f=0;f<l;f++){const d=a[f]/255;o[f]=d,c[f]=d}for(let f=l;f<64;f++)o[f]=0,c[f]=0;return{left:o,right:c}};if(t.audioBridge=u,i.state==="suspended"){const l=()=>{i.resume().catch(()=>{}),window.removeEventListener("pointerdown",l),window.removeEventListener("keydown",l)};window.addEventListener("pointerdown",l,{once:!0}),window.addEventListener("keydown",l,{once:!0}),(t.wallpaperDisposers??=[]).push(()=>{window.removeEventListener("pointerdown",l),window.removeEventListener("keydown",l)})}(t.wallpaperDisposers??=[]).push(()=>{t.audioBridge===u&&(t.audioBridge=null),i.close().catch(()=>{})})}function Fb(t,e,n,r){if(t.audioBridge)return;const i=window.AudioContext||window.webkitAudioContext;if(!i)return;let s;const a=new Map;try{s=new i;for(const d of[n,r]){const h=s.createMediaElementSource(d),p=s.createAnalyser();p.fftSize=256,p.smoothingTimeConstant=.75,h.connect(p),p.connect(s.destination),a.set(d,p)}}catch(d){ce(t,e,`media \u9891\u8C31\u63A5\u7BA1\u8DF3\u8FC7: ${d?.message??d}`);return}let o=a.get(n);const c=new Uint8Array(o.frequencyBinCount),u=new Float32Array(64),l=new Float32Array(64),f=()=>{if(s.state!=="running")return null;o.getByteFrequencyData(c);const d=Math.min(64,c.length);for(let h=0;h<d;h++){const p=c[h]/255;u[h]=p,l[h]=p}for(let h=d;h<64;h++)u[h]=0,l[h]=0;return{left:u,right:l}};if(t.audioBridge=f,s.state==="suspended"){const d=()=>{s.resume().catch(()=>{}),window.removeEventListener("pointerdown",d),window.removeEventListener("keydown",d)};window.addEventListener("pointerdown",d,{once:!0}),window.addEventListener("keydown",d,{once:!0}),(t.wallpaperDisposers??=[]).push(()=>{window.removeEventListener("pointerdown",d),window.removeEventListener("keydown",d)})}return(t.wallpaperDisposers??=[]).push(()=>{t.audioBridge===f&&(t.audioBridge=null),s.close().catch(()=>{})}),d=>{const h=a.get(d);h&&(o=h)}}function Db(t,e){Jn(t);const n=g=>{ce(t,e,`media ${e.type} \u5931\u8D25: ${g}`),t.onError?.(new Error(`\u5A92\u4F53\u58C1\u7EB8\uFF08${e.type}\uFF09${g}`)),t.fallbackPage?.()};if(!e.src){n("\u7F3A\u5C11\u8D44\u6E90 URL\uFF08cfg.src \u4E3A\u7A7A\uFF09");return}const r=e.type==="video",i=e.type==="gif";if(r){Lb(t,e);return}const s=e.canvas instanceof HTMLCanvasElement,a=s?e.canvas:document.createElement("canvas"),o=Es(t,e),c=a.clientWidth||window.innerWidth||1,u=a.clientHeight||window.innerHeight||1;if(a.width=Math.max(1,Math.round(c*o)),a.height=Math.max(1,Math.round(u*o)),s||(a.style.cssText="position:absolute;inset:0;width:100%;height:100%;"),!a.getContext("webgl2",{premultipliedAlpha:!1,antialias:!1,alpha:!1,preserveDrawingBuffer:!0})){if(ce(t,e,`media ${e.type}: WEBGL2_UNAVAILABLE`),s){t.onError?.(new Error("WEBGL2_UNAVAILABLE"));return}Ub(t,e);return}if(s||t.wrap?.appendChild(a),a.setAttribute("data-webwallgl-gl","1"),t.canvas=a,t.onSceneInfo){const g=t.onSceneInfo;t.onSceneInfo=void 0;try{g({width:c,height:u,layerCount:0,hasModels:!1,hasParticles:!1,hasText:!1})}catch{}}let f=!1;t.sceneCleanup=()=>{f=!0,t.renderer&&(t.renderer.dispose?.(),t.renderer=void 0)};let d,h,p=!1;t.sceneAudio={setVolume(g){const w=t.video;if(!w)return;const y=Math.max(0,Math.min(1,Number(g)||0));w.volume=y,w.muted=y<=0,y>0&&w.paused&&!t.paused&&w.play().catch(b=>{ce(t,e,`media \u53D6\u6D88\u9759\u97F3\u540E\u81EA\u52A8\u64AD\u653E\u88AB\u62D2\u7EDD: ${b?.message??b}`)})},audios:[]},t.sceneCtl={pause(){d?.()},resume(){h?.()},applyUserProperties(){}};const m=g=>{f||(f=!0,n(g))};(async()=>{try{const g=ft.createRenderer(a,{diag:U=>ce(t,e,`renderer: ${U}`),fboCapFactor:0});if(t.renderer=g,f)return;const w="__media",y=new Map;let b,v=0,k=0;{let U=!1;if(i&&typeof window.ImageDecoder=="function")try{const q=await Bb(e.src);if(q&&q.frames.length>1){v=q.width,k=q.height;const H=g.gl,G={glTex:ft.makeTexture(H,null,0,0,q.frames[0].bitmap),width:v,height:k,rg88:!1};y.set(w,G);let Y=0,J=performance.now()+q.frames[0].durationMs;b=()=>{const fe=performance.now();if(!(fe<J)){Y=(Y+1)%q.frames.length,J=fe+q.frames[Y].durationMs,H.bindTexture(H.TEXTURE_2D,G.glTex);try{H.texImage2D(H.TEXTURE_2D,0,H.RGBA,H.RGBA,H.UNSIGNED_BYTE,q.frames[Y].bitmap)}catch{}}};const ne=t.sceneCleanup;t.sceneCleanup=()=>{ne?.();for(const fe of q.frames)fe.bitmap.close()},U=!0,ce(t,e,`media gif ${v}x${k} ${q.frames.length} \u5E27 \u2192 scene \u6E32\u67D3`)}}catch(q){ce(t,e,`gif \u89E3\u7801\u5931\u8D25\uFF0C\u56DE\u9000\u9759\u6001\u9996\u5E27: ${String(q.message).slice(0,80)}`)}if(!U){const q=new Image;if(q.crossOrigin="anonymous",q.src=e.src,await new Promise((H,G)=>{q.addEventListener("load",()=>H(),{once:!0}),q.addEventListener("error",()=>G(new Error("image load error")),{once:!0})}),f)return;v=q.naturalWidth||1,k=q.naturalHeight||1,t.img=q,y.set(w,{glTex:ft.makeTexture(g.gl,null,0,0,q),width:v,height:k,rg88:!1}),ce(t,e,`media ${e.type} ${v}x${k} \u2192 scene \u6E32\u67D3`)}}if(f)return;const A=Mb(v,k,w),T=performance.now();let S=0,P=0,M=-1/0;const B=U=>{if(f||t.paused)return;const q=t.cfg.sceneFps||60;if(U-M>=1e3/q){M=U,er(t,U),el(t,a,t.cfg),b?.();const H=t.coverAlign;g.render(A,y,a.width,a.height,(U-T-S)/1e3,xr(t.cfg.fit),H.x,H.y).then(()=>{if(t.onFirstFrame){const G=t.onFirstFrame;t.onFirstFrame=void 0;try{G()}catch{}}f||t.paused||(t.raf=requestAnimationFrame(B))}).catch(G=>m(String(G.message||G).slice(0,200)))}else t.paused||(t.raf=requestAnimationFrame(B))},N=()=>{f||t.paused||t.raf===void 0&&(t.raf=requestAnimationFrame(B))};d=()=>{t.raf!==void 0&&(cancelAnimationFrame(t.raf),t.raf=void 0),P||(P=performance.now());const U=t.video;p=!!(U&&!U.paused&&!U.ended),U?.pause()},h=()=>{P&&(S+=performance.now()-P,P=0),p&&t.video?.play().catch(()=>{}),p=!1,N()},N()}catch(g){m(String(g.message||g).slice(0,200))}})()}function Nb(t,e){if(t.wrap)return t.wrap;const n=e.canvas;return n?n instanceof HTMLCanvasElement?n.parentElement:n:null}function Lb(t,e){if(Jn(t),!e.src){t.fallbackPage?.(),t.onError?.(new Error("\u5A92\u4F53\u58C1\u7EB8\uFF08video\uFF09\u7F3A\u5C11\u8D44\u6E90 URL\uFF08cfg.src \u4E3A\u7A7A\uFF09"));return}const n=Nb(t,e);if(!n){const d="\u89C6\u9891\u58C1\u7EB8\u9700\u8981\u4E00\u4E2A\u5BB9\u5668\u5143\u7D20\uFF08\u4F20\u5165\u7684 canvas \u6CA1\u6709\u7236\u8282\u70B9\uFF09";ce(t,e,`media video \u5931\u8D25: ${d}`),t.onError?.(new Error(`\u5A92\u4F53\u58C1\u7EB8\uFF08video\uFF09${d}`));return}const r=Ha(e.fit),i=`position:absolute;inset:0;width:100%;height:100%;object-fit:${r.objectFit};object-position:50% 50%;background:${r.background};`;!t.wrap&&getComputedStyle(n).position==="static"&&(n.style.position="relative");let s=!1;const a=d=>{if(s)return;s=!0;const h=`\u89E3\u7801/\u52A0\u8F7D\u5931\u8D25\uFF08code ${d??"?"}\uFF09`;ce(t,e,`media video \u5931\u8D25: ${h}`),t.onError?.(new Error(`\u5A92\u4F53\u58C1\u7EB8\uFF08video\uFF09${h}`)),t.fallbackPage?.()},o=e.loop!==!1,c=e.muted!==!1,u=()=>{er(t,performance.now());const d=t.onFirstFrame;if(d){if(t.onFirstFrame=void 0,t.onSceneInfo){const h=t.onSceneInfo;t.onSceneInfo=void 0;try{h({width:t.video?.videoWidth||0,height:t.video?.videoHeight||0,layerCount:1,hasModels:!1,hasParticles:!1,hasText:!1})}catch{}}try{d()}catch{}}},l=d=>{let h=!1,p=0,m=-1;const g=v=>{if(t.paused||v.paused||v.readyState<2)return;const k=v.currentTime;m>=0&&k===m||(m=k,er(t,performance.now()))};let w;const y=()=>{h||!w||(g(w),w.requestVideoFrameCallback(y))},b=()=>{if(h)return;p=requestAnimationFrame(b);const v=d();v&&(v!==w&&typeof v.requestVideoFrameCallback=="function"&&(w=v,v.requestVideoFrameCallback(y)),g(v))};p=requestAnimationFrame(b),(t.wallpaperDisposers??=[]).push(()=>{h=!0,w=void 0,p&&cancelAnimationFrame(p)})};if(!o){const d=document.createElement("video");d.autoplay=!0,d.loop=!1,d.muted=c,d.playsInline=!0,d.preload="metadata",Ob(d,t,e),d.style.cssText=i,d.src=e.src,d.addEventListener("error",()=>a(d.error?.code)),n.appendChild(d),t.video=d,(t.videoTextures??=[]).push(d),d.addEventListener("canplay",()=>{d.play().catch(()=>{})},{once:!0}),d.addEventListener("loadeddata",u,{once:!0}),d.readyState>=2&&u(),Rb(t,e,d),l(()=>d),ce(t,e,"media video \u2192 DOM \u76F4\u663E\uFF08\u5355\u5143\u7D20\uFF0C\u4E0D\u5FAA\u73AF\uFF09");return}const f=()=>{const d=rl(e.src,{muted:c,renderDpr:e.renderDpr,maxW:n.clientWidth||window.innerWidth,maxH:n.clientHeight||window.innerHeight,onRecover:m=>ce(t,e,`media video \u81EA\u6108: ${m}`)});for(const m of[d.active,d.standby])m.style.cssText=i,n.appendChild(m),(t.videoTextures??=[]).push(m),m.addEventListener("error",()=>a(m.error?.code));const h=()=>{d.active.style.zIndex="1",d.standby.style.zIndex="0",t.video=d.active};h(),d.onSwap=()=>{h(),p?.(d.active)},d.onFallback=()=>ce(t,e,"media video: \u65E0\u7F1D\u5FAA\u73AF\u515C\u5E95\uFF08\u9000\u56DE\u539F\u751F loop\uFF09"),(t.videoPairs??=[]).push(d),t.webcodecsPreferred=hf();const p=Fb(t,e,d.active,d.standby);d.active.addEventListener("loadeddata",u,{once:!0}),d.active.readyState>=2&&u(),l(()=>d.active),t.paused||d.resume(),ce(t,e,"media video \u2192 DOM \u76F4\u663E\uFF08A/B \u65E0\u7F1D\u5FAA\u73AF\uFF09")};if(o&&c&&hf()){let d=!0,h=null;const p=(m,g=!0)=>{d&&(d=!1,h?.destroy(),h=null,ce(t,e,`media video: ${m}\uFF0C\u56DE\u9000 A/B <video>`),f(),g||(t.webcodecsPreferred=!1))};h=Cg({src:e.src,container:n,cssText:i,fit:()=>xr(t.cfg.fit),fps:()=>t.cfg.sceneFps||60,paused:()=>!!t.paused,renderDpr:e.renderDpr,onFirstFrame:u,onFrame:()=>er(t,performance.now()),onDiag:m=>ce(t,e,`media video(webcodecs): ${m}`),onFatal:m=>p(`WebCodecs \u8DEF\u5F84\u5931\u8D25\uFF08${m}\uFF09`,!1)}),t.sceneCtl={pause:()=>h?.pause(),resume:()=>h?.resume(),applyUserProperties(){}},t.sceneAudio={setVolume:m=>{m>0&&p("\u53D6\u6D88\u9759\u97F3\uFF08\u9700\u8981\u97F3\u8F68\uFF09")},audios:[]},(t.wallpaperDisposers??=[]).push(()=>{d=!1,h?.destroy(),h=null}),t.canvas=h.canvas,ce(t,e,"media video \u2192 WebCodecs \u9010\u5E27\u8C03\u5EA6\uFF08\u9759\u97F3\u5FAA\u73AF\uFF09");return}f()}function Ob(t,e,n){const r=Math.min(window.devicePixelRatio||1,n.renderDpr??e.cfg?.renderDpr??1),i=n.canvas?.clientWidth||window.innerWidth,s=n.canvas?.clientHeight||window.innerHeight;t.width=Math.max(1,Math.round(i*r)),t.height=Math.max(1,Math.round(s*r))}function Ub(t,e){Jn(t);const n=document.createElement("img"),r=Ha(e.fit);n.style.cssText=`position:absolute;inset:0;width:100%;height:100%;object-fit:${r.objectFit};object-position:50% 50%;background:${r.background};`,n.src=e.src??"",n.addEventListener("error",()=>t.fallbackPage?.()),t.wrap?.appendChild(n),t.img=n}const zb=["scene.pkg","scenes/scene.pkg","gifscene.pkg"],Hb={mp4:"video",webm:"video",mov:"video",m4v:"video",ogv:"video",gif:"gif",png:"image",jpg:"image",jpeg:"image",webp:"image",avif:"image",bmp:"image"};function Kd(t){const e=t.toLowerCase().split(";")[0].trim();return e==="image/gif"?"gif":e.startsWith("video/")?"video":e.startsWith("image/")?"image":null}function zc(t){if(typeof t!="string"||!t)return null;let e=t;const n=e.indexOf("#");n>=0&&(e=e.slice(0,n));const r=e.indexOf("?");r>=0&&(e=e.slice(0,r));const i=e.split("/").pop()||"",s=i.lastIndexOf(".");return s<0?null:Hb[i.slice(s+1).toLowerCase()]??null}async function Vb(t,e,n){try{const r=await fetch(t,{...e,method:"HEAD",signal:n});return r.ok?Kd(r.headers.get("content-type")||""):null}catch{return null}}function Zd(t,e){const n=t.replace(/\/+$/,"");return{key:n,async scenePkg(r){let i=null,s=null;for(const o of zb){let c;try{c=await fetch(`${n}/${o}`,{...e,signal:r})}catch(u){if(r?.aborted)throw u;s=u;continue}if(!c.ok){i=c.status;continue}try{return await c.arrayBuffer()}catch(u){if(r?.aborted)throw u;const l=u instanceof Error?u.message:String(u);throw new Error(`\u8BFB\u53D6 scene.pkg \u4F53\u5931\u8D25\uFF08${l}\uFF09`)}}if(i!=null)throw new Error(`scene.pkg \u52A0\u8F7D\u5931\u8D25\uFF08HTTP ${i}\uFF09`);const a=s instanceof Error?s.message:"Failed to fetch";throw new Error(`scene.pkg \u52A0\u8F7D\u5931\u8D25\uFF08${a}\uFF09`)},async project(r){try{const i=await fetch(`${n}/project.json`,{...e,signal:r});return i.ok?await i.json():null}catch{return null}},async webEntry(r){let i="index.html";try{const s=await fetch(`${n}/project.json`,{...e,signal:r});if(s.ok){const a=await s.json();a&&typeof a.file=="string"&&a.file.trim()&&(i=a.file.trim().replace(/^\/+/,""))}}catch{if(r?.aborted)throw new Error("aborted")}return{url:`${n}/${i}`}},async mediaEntry(r){let i="";try{const s=await fetch(`${n}/project.json`,{...e,signal:r});if(s.ok){const a=await s.json();a&&typeof a.file=="string"&&a.file.trim()&&(i=a.file.trim().replace(/^\/+/,""))}}catch{if(r?.aborted)throw new Error("aborted")}return i?{url:`${n}/${i}`}:null}}}function Wb(t,e){const n=t;return{key:typeof n.name=="string"?`file:${n.name}:${n.size}:${n.lastModified??0}`:void 0,scenePkg:()=>t.arrayBuffer(),project:async()=>e??null}}function jb(t,e,n){return{key:n,scenePkg:async()=>t,project:async()=>e??null}}function qb(t,e){const n=typeof t!="string",r=t;let i=e?.type??(n?Kd(t.type||""):null)??zc(n?String(r.name??""):t),s=!1,a=null;const o=()=>n?(a||(a=URL.createObjectURL(t)),a):t;return{key:e?.key??(n?typeof r.name=="string"?`media:${r.name}:${r.size}:${r.lastModified??0}`:void 0:`media:${t}`),async scenePkg(){throw new Error("mediaSource \u662F\u7EAF\u5A92\u4F53\u6765\u6E90\uFF0C\u6CA1\u6709 scene.pkg\uFF08\u8BF7\u6539\u7528 httpSource/fileSource/bytesSource\uFF09")},async project(){return i?{type:i}:null},async mediaEntry(u){return!i&&!n&&!s&&(s=!0,i=await Vb(t,void 0,u)),{url:o(),type:i??void 0}},dispose(){a&&(URL.revokeObjectURL(a),a=null)}}}const Jd=!1,eh=!0,th=!1,Xb=!1,Gb=!1,nh=4,gs=64,rh={STOPPED:0};function $b(){return{left64:new Float32Array(gs),right64:new Float32Array(gs),left32:new Float32Array(32),right32:new Float32Array(32),left16:new Float32Array(16),right16:new Float32Array(16),level:0,silent:!0}}function Pa(t,e){const n=e.length/t.length;for(let r=0;r<t.length;r++){let i=0;const s=Math.floor(r*n),a=Math.max(s+1,Math.floor((r+1)*n));for(let o=s;o<a;o++)i+=e[o];t[r]=i/(a-s)}}function Qb(t,e,n){const r=e.length,i=n*.5,s=20,a=Math.min(2e4,i);let o=0;for(let c=0;c<gs;c++){const u=c/gs,l=(c+1)/gs,f=s*Math.pow(a/s,u),d=s*Math.pow(a/s,l),h=Math.max(0,Math.floor(f/i*r)),p=Math.min(r,Math.max(h+1,Math.ceil(d/i*r)));let m=0;for(let w=h;w<p;w++)m+=e[w]/255;const g=Math.min(1,m/(p-h)*1.35);t.left64[c]=g,t.right64[c]=g,c<48&&(o+=g)}Pa(t.left32,t.left64),Pa(t.right32,t.right64),Pa(t.left16,t.left64),Pa(t.right16,t.right64),t.level=Math.min(1,o/(48*1.2)),t.silent=t.level<.02}function Yb(t){let e=2166136261;for(let n=0;n<t.length;n++)e^=t.charCodeAt(n),e=Math.imul(e,16777619);return(e>>>0)%360}function Hc(t,e,n){const r=e/100,i=n/100,s=(1-Math.abs(2*i-1))*r,a=t/60,o=s*(1-Math.abs(a%2-1));let c=0,u=0,l=0;a<1?[c,u,l]=[s,o,0]:a<2?[c,u,l]=[o,s,0]:a<3?[c,u,l]=[0,s,o]:a<4?[c,u,l]=[0,o,s]:a<5?[c,u,l]=[o,0,s]:[c,u,l]=[s,0,o];const f=i-s/2;return[c+f,u+f,l+f]}function Kb(t,e){const n=Yb(e||"empty"),[r,i,s]=Hc(n,72,48),[a,o,c]=Hc((n+40)%360,55,28),[u,l,f]=Hc((n+20)%360,70,72);t.primaryColor=Se.mediaVec3(r,i,s),t.secondaryColor=Se.mediaVec3(a,o,c),t.tertiaryColor=Se.mediaVec3(u,l,f),t.textColor=Se.mediaVec3(.98,.98,1),t.highContrastColor=Se.mediaVec3(1,1,1),t.hasThumbnail=!!e}function Zb(t,e,n){const r=document.createElement("canvas");r.width=32,r.height=32;const i=r.getContext("2d",{willReadFrequently:!0});if(!i)return null;i.drawImage(t,0,0,e,n,0,0,32,32);const s=i.getImageData(0,0,32,32).data;let a=0,o=0,c=0,u=0,l=0,f=0,d=0,h=-1;for(let w=0;w<s.length;w+=4){const y=s[w]/255,b=s[w+1]/255,v=s[w+2]/255;a+=y,o+=b,c+=v,u++;const k=Math.max(y,b,v),A=Math.min(y,b,v),T=k-A,S=.2126*y+.7152*b+.0722*v,P=T*1.4+(S>.15&&S<.85?.3:0);P>h&&(h=P,l=y,f=b,d=v)}if(!u)return null;const p=[l,f,d],m=[a/u*.55,o/u*.55,c/u*.55],g=[Math.min(1,p[0]*.45+.55),Math.min(1,p[1]*.45+.55),Math.min(1,p[2]*.45+.55)];return{primary:p,secondary:m,tertiary:g}}function Jb(t,e,n,r=512){const i=document.createElement("canvas");i.width=r,i.height=r;const s=i.getContext("2d"),a=Math.max(r/Math.max(1,e),r/Math.max(1,n)),o=e*a,c=n*a;s.fillStyle="#000",s.fillRect(0,0,r,r),s.drawImage(t,(r-o)/2,(r-c)/2,o,c);const u=s.getImageData(0,0,r,r);return{width:r,height:r,rgba:new Uint8Array(u.data)}}function e1(){return{hasMedia:!1,state:rh.STOPPED,title:"",artist:"",album:"",albumArtist:"",position:0,duration:0,hasThumbnail:!1,primaryColor:Se.mediaVec3(0,0,0),secondaryColor:Se.mediaVec3(0,0,0),tertiaryColor:Se.mediaVec3(0,0,0),textColor:Se.mediaVec3(1,1,1),highContrastColor:Se.mediaVec3(1,1,1),trackIndex:-1,lyrics:[],lyricLine:"",lyricIndex:-1}}async function t1(){if(!navigator.mediaDevices?.getUserMedia)return null;try{const t=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!1,noiseSuppression:!1,autoGainControl:!1},video:!1}),e=new AudioContext,n=e.createMediaStreamSource(t),r=e.createAnalyser();return r.fftSize=2048,r.smoothingTimeConstant=.8,n.connect(r),e.state==="suspended"&&await e.resume().catch(()=>{}),{ctx:e,stream:t,analyser:r,buf:new Uint8Array(r.frequencyBinCount)}}catch{return null}}async function ih(t){const e=t?.origin??(typeof location<"u"?location.origin:""),n=t?.onArtwork,r=$b(),i=e1(),s={app:"",title:"",url:"",index:0};let a="off",o="offline",c="offline",u="",l=!1,f="";const d=await t1();d?a="mic":navigator.mediaDevices?.getUserMedia?a="denied":a="unavailable";let h=null,p=null,m=!1;const g=(k,A,T)=>{!e||!n||!l||f!==k&&(f=k,n({url:`${e}/api/system/artwork?k=${encodeURIComponent(k)}&_=${Date.now()}`,trackKey:k,title:A,artist:T}))},w=k=>{if(!k||!k.hasMedia){i.hasMedia=!1,i.state=rh.STOPPED,i.title="",i.artist="",i.album="",i.albumArtist="",i.position=0,i.duration=0,i.hasThumbnail=!1,i.trackIndex=-1,o=k?"empty":"offline",u="",l=!1,f="";return}o="live",i.hasMedia=!0,i.state=Number(k.state)===2?2:Number(k.state)===1?1:0,i.title=String(k.title??""),i.artist=String(k.artist??""),i.album=String(k.album??""),i.albumArtist=String(k.albumArtist??k.artist??""),i.position=Number(k.position)||0,i.duration=Number(k.duration)||0,l=k.hasArtwork===!0;const A=`${i.title}|${i.artist}|${i.album}`;A!==u&&(u=A,f="",i.trackIndex=i.trackIndex+1|0,Kb(i,A)),g(A,i.title,i.artist)},y=k=>{if(!k){c="offline";return}s.app=String(k.app??""),s.title=String(k.title??""),s.url=String(k.url??""),c=s.app||s.title?"live":"empty"},b=async()=>{if(!(!e||m))try{const[k,A]=await Promise.all([fetch(`${e}/api/system/media`,{cache:"no-store"}),fetch(`${e}/api/system/window`,{cache:"no-store"})]);if(k.ok){const T=await k.json();w(T)}else o="offline";A.ok&&y(await A.json())}catch{o=o==="live"?"live":"offline",c=c==="live"?"live":"offline"}};if(e){await b(),p=setInterval(()=>{b()},1e3);try{h=new EventSource(`${e}/api/system/stream`),h.onmessage=k=>{if(!m)try{const A=JSON.parse(k.data);w(A.media),y(A.window)}catch{}}}catch{}}const v=k=>{!e||m||fetch(`${e}/api/system/media-control`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:k})}).then(async A=>A.ok?A.json():null).then(A=>{A&&typeof A=="object"&&w(A),b()}).catch(()=>{b()})};return{audio:{snapshot:r,pump:()=>{if(!d||m){r.level=0,r.silent=!0;return}d.analyser.getByteFrequencyData(d.buf),Qb(r,d.buf,d.ctx.sampleRate||48e3)}},media:{snapshot:i,pump:()=>{},skipNext:()=>v("skipNext"),skipPrevious:()=>v("skipPrevious"),play:()=>v("play"),pause:()=>v("pause"),playPause:()=>v("playPause")},windowTitle:{snapshot:s,pump:()=>{}},status:()=>({audio:a,media:o,window:c,title:i.title,artist:i.artist,app:s.app,windowTitle:s.title,hasArtwork:l}),dispose:()=>{m=!0,p&&(clearInterval(p),p=null);try{h?.close()}catch{}if(h=null,d)try{d.stream.getTracks().forEach(k=>k.stop()),d.ctx.close()}catch{}}}}const n1={"common.h":`// WE common.h\uFF08\u91CD\u5EFA\u5B50\u96C6\uFF0C\u4F9B we-scene \u6D4F\u89C8\u5668\u6E32\u67D3\uFF09
|
|
182
460
|
#define M_PI 3.14159265359
|
|
183
461
|
// M_PI_2 \u662F\u300CPI \xD7 2\u300D\u800C\u4E0D\u662F\u300CPI \xF7 2\u300D\u2014\u2014 \u540D\u5B57\u6781\u6613\u8BFB\u53CD\uFF0C\u6B64\u524D\u8BEF\u5199\u6210 1.5708\uFF0C
|
|
184
462
|
// \u5F71\u54CD\u5168\u5E93 142 \u4E2A\u6587\u4EF6\uFF0864 \u4E2A\u58C1\u7EB8\uFF09\u3002\u4E09\u6761\u72EC\u7ACB\u8BC1\u636E\uFF1A
|
|
@@ -226,151 +504,7 @@ vec3 hsv2rgb(vec3 c) {
|
|
|
226
504
|
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
|
227
505
|
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
|
228
506
|
}
|
|
229
|
-
`,"common_blending.h"
|
|
230
|
-
vec3 weBlendOverlay(vec3 a, vec3 b) {
|
|
231
|
-
return vec3(
|
|
232
|
-
a.r < 0.5 ? 2.0 * a.r * b.r : 1.0 - 2.0 * (1.0 - a.r) * (1.0 - b.r),
|
|
233
|
-
a.g < 0.5 ? 2.0 * a.g * b.g : 1.0 - 2.0 * (1.0 - a.g) * (1.0 - b.g),
|
|
234
|
-
a.b < 0.5 ? 2.0 * a.b * b.b : 1.0 - 2.0 * (1.0 - a.b) * (1.0 - b.b));
|
|
235
|
-
}
|
|
236
|
-
vec3 weBlendSoftLight(vec3 a, vec3 b) {
|
|
237
|
-
return vec3(
|
|
238
|
-
b.r < 0.5 ? 2.0 * a.r * b.r + a.r * a.r * (1.0 - 2.0 * b.r) : sqrt(a.r) * (2.0 * b.r - 1.0) + 2.0 * a.r * (1.0 - b.r),
|
|
239
|
-
b.g < 0.5 ? 2.0 * a.g * b.g + a.g * a.g * (1.0 - 2.0 * b.g) : sqrt(a.g) * (2.0 * b.g - 1.0) + 2.0 * a.g * (1.0 - b.g),
|
|
240
|
-
b.b < 0.5 ? 2.0 * a.b * b.b + a.b * a.b * (1.0 - 2.0 * b.b) : sqrt(a.b) * (2.0 * b.b - 1.0) + 2.0 * a.b * (1.0 - b.b));
|
|
241
|
-
}
|
|
242
|
-
float weBlendVivid(float a, float b) {
|
|
243
|
-
if (b < 0.5) {
|
|
244
|
-
float bb = 2.0 * b;
|
|
245
|
-
return bb == 0.0 ? 0.0 : max(1.0 - (1.0 - a) / bb, 0.0);
|
|
246
|
-
}
|
|
247
|
-
float bb = 2.0 * (b - 0.5);
|
|
248
|
-
return bb == 1.0 ? 1.0 : min(a / (1.0 - bb), 1.0);
|
|
249
|
-
}
|
|
250
|
-
// Reflect \u5355\u72EC\u6210\u51FD\u6570\uFF1AGlow = Reflect(B,A)\u3002GLSL \u7981\u6B62\u9012\u5F52\uFF0C\u4E0D\u80FD\u5728 ApplyBlending
|
|
251
|
-
// \u5185\u90E8\u8C03 ApplyBlending(21, \u2026)\uFF08\u6574\u4E2A\u51FD\u6570\u4F1A\u7F16\u8BD1\u5931\u8D25\uFF0C\u6548\u679C\u88AB\u9759\u9ED8\u8DF3\u8FC7\uFF09\u3002
|
|
252
|
-
vec3 weBlendReflect(vec3 A, vec3 B) {
|
|
253
|
-
return vec3(
|
|
254
|
-
A.r == 1.0 ? 1.0 : min(B.r * B.r / (1.0 - A.r), 1.0),
|
|
255
|
-
A.g == 1.0 ? 1.0 : min(B.g * B.g / (1.0 - A.g), 1.0),
|
|
256
|
-
A.b == 1.0 ? 1.0 : min(B.b * B.b / (1.0 - A.b), 1.0));
|
|
257
|
-
}
|
|
258
|
-
vec3 RGBToHSL(vec3 c) {
|
|
259
|
-
float fmin = min(c.r, min(c.g, c.b));
|
|
260
|
-
float fmax = max(c.r, max(c.g, c.b));
|
|
261
|
-
float delta = fmax - fmin;
|
|
262
|
-
vec3 h = vec3(0.0);
|
|
263
|
-
h.z = (fmax + fmin) / 2.0;
|
|
264
|
-
if (delta == 0.0) {
|
|
265
|
-
h.x = 0.0;
|
|
266
|
-
h.y = 0.0;
|
|
267
|
-
} else {
|
|
268
|
-
h.y = h.z < 0.5 ? delta / (fmax + fmin) : delta / (2.0 - fmax - fmin);
|
|
269
|
-
float deltaR = ((fmax - c.r) / 6.0 + delta / 2.0) / delta;
|
|
270
|
-
float deltaG = ((fmax - c.g) / 6.0 + delta / 2.0) / delta;
|
|
271
|
-
float deltaB = ((fmax - c.b) / 6.0 + delta / 2.0) / delta;
|
|
272
|
-
if (c.r == fmax) h.x = deltaB - deltaG;
|
|
273
|
-
else if (c.g == fmax) h.x = 1.0 / 3.0 + deltaR - deltaB;
|
|
274
|
-
else if (c.b == fmax) h.x = 2.0 / 3.0 + deltaG - deltaB;
|
|
275
|
-
if (h.x < 0.0) h.x += 1.0;
|
|
276
|
-
else if (h.x > 1.0) h.x -= 1.0;
|
|
277
|
-
}
|
|
278
|
-
return h;
|
|
279
|
-
}
|
|
280
|
-
float weHueToRgb(float f1, float f2, float hue) {
|
|
281
|
-
if (hue < 0.0) hue += 1.0;
|
|
282
|
-
else if (hue > 1.0) hue -= 1.0;
|
|
283
|
-
if (6.0 * hue < 1.0) return f1 + (f2 - f1) * 6.0 * hue;
|
|
284
|
-
if (2.0 * hue < 1.0) return f2;
|
|
285
|
-
if (3.0 * hue < 2.0) return f1 + (f2 - f1) * ((2.0 / 3.0 - hue) * 6.0);
|
|
286
|
-
return f1;
|
|
287
|
-
}
|
|
288
|
-
vec3 HSLToRGB(vec3 h) {
|
|
289
|
-
if (h.y == 0.0) return vec3(h.z);
|
|
290
|
-
float f2 = h.z < 0.5 ? h.z * (1.0 + h.y) : h.z + h.y - h.y * h.z;
|
|
291
|
-
float f1 = 2.0 * h.z - f2;
|
|
292
|
-
return vec3(
|
|
293
|
-
weHueToRgb(f1, f2, h.x + 1.0 / 3.0),
|
|
294
|
-
weHueToRgb(f1, f2, h.x),
|
|
295
|
-
weHueToRgb(f1, f2, h.x - 1.0 / 3.0));
|
|
296
|
-
}
|
|
297
|
-
// mode \u7F16\u53F7\u540C WE common_blending.h\uFF080=Normal \u2026 32=LighterColor \u7684\u5B9E\u73B0\u5B50\u96C6\uFF09
|
|
298
|
-
vec3 ApplyBlending(int mode, vec3 A, vec3 B, float opacity) {
|
|
299
|
-
vec3 r;
|
|
300
|
-
if (mode == 1) { r = min(B, A); } // Darken
|
|
301
|
-
else if (mode == 2) { r = A * B; } // Multiply
|
|
302
|
-
else if (mode == 3) { // ColorBurn
|
|
303
|
-
r = vec3(
|
|
304
|
-
B.r == 0.0 ? 0.0 : max(1.0 - (1.0 - A.r) / B.r, 0.0),
|
|
305
|
-
B.g == 0.0 ? 0.0 : max(1.0 - (1.0 - A.g) / B.g, 0.0),
|
|
306
|
-
B.b == 0.0 ? 0.0 : max(1.0 - (1.0 - A.b) / B.b, 0.0));
|
|
307
|
-
}
|
|
308
|
-
else if (mode == 4 || mode == 20) { r = max(A + B - 1.0, vec3(0.0)); } // Substract
|
|
309
|
-
else if (mode == 5) { r = min(A, B); } // LinearBurn
|
|
310
|
-
else if (mode == 6) { r = max(B, A); } // Lighten
|
|
311
|
-
else if (mode == 7) { r = 1.0 - (1.0 - A) * (1.0 - B); } // Screen
|
|
312
|
-
else if (mode == 8) { // ColorDodge
|
|
313
|
-
r = vec3(
|
|
314
|
-
B.r == 1.0 ? 1.0 : min(A.r / (1.0 - B.r), 1.0),
|
|
315
|
-
B.g == 1.0 ? 1.0 : min(A.g / (1.0 - B.g), 1.0),
|
|
316
|
-
B.b == 1.0 ? 1.0 : min(A.b / (1.0 - B.b), 1.0));
|
|
317
|
-
}
|
|
318
|
-
else if (mode == 9) { r = min(A + B, vec3(1.0)); } // Add
|
|
319
|
-
else if (mode == 10) { r = max(A, B); } // Lighter
|
|
320
|
-
else if (mode == 11) { r = weBlendOverlay(A, B); } // Overlay
|
|
321
|
-
else if (mode == 12) { r = weBlendSoftLight(A, B); } // SoftLight
|
|
322
|
-
else if (mode == 13) { r = weBlendOverlay(B, A); } // HardLight
|
|
323
|
-
else if (mode == 14) { // VividLight
|
|
324
|
-
r = vec3(weBlendVivid(A.r, B.r), weBlendVivid(A.g, B.g), weBlendVivid(A.b, B.b));
|
|
325
|
-
}
|
|
326
|
-
else if (mode == 15) { // LinearLight
|
|
327
|
-
r = vec3(
|
|
328
|
-
B.r < 0.5 ? max(A.r + 2.0 * B.r - 1.0, 0.0) : min(A.r + 2.0 * (B.r - 0.5), 1.0),
|
|
329
|
-
B.g < 0.5 ? max(A.g + 2.0 * B.g - 1.0, 0.0) : min(A.g + 2.0 * (B.g - 0.5), 1.0),
|
|
330
|
-
B.b < 0.5 ? max(A.b + 2.0 * B.b - 1.0, 0.0) : min(A.b + 2.0 * (B.b - 0.5), 1.0));
|
|
331
|
-
}
|
|
332
|
-
else if (mode == 16) { // PinLight
|
|
333
|
-
r = vec3(
|
|
334
|
-
B.r < 0.5 ? min(A.r, 2.0 * B.r) : max(A.r, 2.0 * (B.r - 0.5)),
|
|
335
|
-
B.g < 0.5 ? min(A.g, 2.0 * B.g) : max(A.g, 2.0 * (B.g - 0.5)),
|
|
336
|
-
B.b < 0.5 ? min(A.b, 2.0 * B.b) : max(A.b, 2.0 * (B.b - 0.5)));
|
|
337
|
-
}
|
|
338
|
-
else if (mode == 17) { // HardMix
|
|
339
|
-
r = vec3(
|
|
340
|
-
weBlendVivid(A.r, B.r) < 0.5 ? 0.0 : 1.0,
|
|
341
|
-
weBlendVivid(A.g, B.g) < 0.5 ? 0.0 : 1.0,
|
|
342
|
-
weBlendVivid(A.b, B.b) < 0.5 ? 0.0 : 1.0);
|
|
343
|
-
}
|
|
344
|
-
else if (mode == 18) { r = abs(A - B); } // Difference
|
|
345
|
-
else if (mode == 19) { r = A + B - 2.0 * A * B; } // Exclusion
|
|
346
|
-
else if (mode == 21) { r = weBlendReflect(A, B); } // Reflect
|
|
347
|
-
else if (mode == 22) { r = weBlendReflect(B, A); } // Glow = Reflect(B,A)
|
|
348
|
-
else if (mode == 23) { r = min(A, B) - max(A, B) + 1.0; } // Phoenix
|
|
349
|
-
else if (mode == 24) { r = (A + B) / 2.0; } // Average
|
|
350
|
-
else if (mode == 25) { r = 1.0 - abs(1.0 - A - B); } // Negation
|
|
351
|
-
else if (mode == 26) { r = HSLToRGB(vec3(RGBToHSL(B).x, RGBToHSL(A).y, RGBToHSL(A).z)); } // Hue
|
|
352
|
-
else if (mode == 27) { r = HSLToRGB(vec3(RGBToHSL(A).x, RGBToHSL(B).y, RGBToHSL(A).z)); } // Saturation
|
|
353
|
-
else if (mode == 28) { r = HSLToRGB(vec3(RGBToHSL(B).x, RGBToHSL(B).y, RGBToHSL(A).z)); } // Color
|
|
354
|
-
else if (mode == 29) { r = HSLToRGB(vec3(RGBToHSL(A).x, RGBToHSL(A).y, RGBToHSL(B).z)); } // Luminosity
|
|
355
|
-
else if (mode == 30) { r = mix(A, max(max(A.r, max(A.g, A.b)), 0.0) * B, opacity); } // Tint
|
|
356
|
-
else if (mode == 31) { r = A + B * opacity; } // Add(\u5E26 opacity \u6743\u91CD)
|
|
357
|
-
else if (mode == 32) { r = mix(A, A + A * B, opacity); } // LinearDodge \u53D8\u4F53
|
|
358
|
-
else { r = mix(A, B, opacity); } // Normal(\u542B 0)
|
|
359
|
-
// CPU \u53C2\u8003\uFF08effects.js applyBlending\uFF09\uFF1A5/10/30/31/32 \u76F4\u63A5\u8FD4\u56DE\u4E0D\u7ECF opacity \u6743\u91CD\uFF0C
|
|
360
|
-
// \u5176\u4F59\u7EDF\u4E00 mix(A, r, opacity) \u56DE\u5F52\u539F\u8272\u3002
|
|
361
|
-
//
|
|
362
|
-
// [we-scene patch] **mode 0 \u4E5F\u5FC5\u987B\u6392\u9664**\uFF1A\u5B83\u7684\u5206\u652F\u5DF2\u7ECF\u662F mix(A, B, opacity)\uFF0C
|
|
363
|
-
// \u518D\u5957\u4E00\u5C42\u7B49\u4E8E\u6309 opacity\xB2 \u52A0\u6743\u3002effects.js \u7684 default \u5206\u652F\u662F switch \u5185\u76F4\u63A5
|
|
364
|
-
// return mix3(A, B, opacity)\u3001\u4E0D\u8D70 per() \u7684\u4E8C\u6B21\u52A0\u6743\uFF0C\u8FD9\u91CC\u6F0F\u6392\u4E86 0\u3002
|
|
365
|
-
// \u75C7\u72B6\u6781\u9690\u853D\uFF1Axray \u7684\u4E24\u5F20\u56FE\u662F\u540C\u4E00\u6784\u56FE\u7684\u4E0D\u540C\u7248\u672C\uFF08A\u2248B\uFF09\uFF0C\u5E73\u65B9\u540E\u5DEE\u5F02\u88AB\u538B\u5230
|
|
366
|
-
// \u8089\u773C\u4E0E readPixels \u90FD\u8BFB\u4E0D\u51FA\uFF08\u5B9E\u6D4B 6 \u4E2A xray \u58C1\u7EB8\u50CF\u7D20\u5DEE\u6070\u597D\u4E3A 0\uFF0C
|
|
367
|
-
// \u800C\u628A\u6700\u7EC8\u8F93\u51FA\u6362\u6210\u4E2D\u95F4\u91CF\u7684\u63A2\u9488\u663E\u793A blend=187\u3001sprite=187\u3001mask.a=255 \u5168\u90FD\u6B63\u5E38\uFF09\u3002
|
|
368
|
-
// \u6CE8\u610F\u672C\u6587\u4EF6\u662F TS \u6A21\u677F\u5B57\u7B26\u4E32\uFF0C\u6CE8\u91CA\u91CC\u4E0D\u80FD\u51FA\u73B0\u53CD\u5F15\u53F7\u3002
|
|
369
|
-
if (mode != 0 && mode != 5 && mode != 10 && mode != 30 && mode != 31 && mode != 32) {
|
|
370
|
-
r = mix(A, r, opacity);
|
|
371
|
-
}
|
|
372
|
-
return r;
|
|
373
|
-
}
|
|
507
|
+
`,"common_blending.h":`${Jf}
|
|
374
508
|
// greyscale \u5FC5\u987B\u8FD4\u56DE **float** \u800C\u4E0D\u662F vec3 \u2014\u2014 \u8C03\u7528\u70B9\u51E0\u4E4E\u5168\u662F
|
|
375
509
|
// \`noise = CAST3(greyscale(noise))\`\uFF08filmgrain/vhs\uFF09\uFF0CCAST3 \u53EA\u80FD\u4F5C\u7528\u4E8E\u6807\u91CF\uFF1B
|
|
376
510
|
// \u82E5\u58F0\u660E\u6210 vec3 \u7248\u672C\uFF0C\u8FD9\u4E9B\u70B9\u4F1A\u53D8\u6210\u975E\u6CD5\u7684 vec3(vec3)\u3002
|
|
@@ -509,11 +643,11 @@ vec3 DecompressNormal(vec4 tex) {
|
|
|
509
643
|
return vec3(xy, sqrt(clamp(1.0 - dot(xy, xy), 0.0, 1.0)));
|
|
510
644
|
}
|
|
511
645
|
`,"common_vertex.h":`// WE common_vertex.h\uFF08\u91CD\u5EFA\uFF1A\u7A7A\u5360\u4F4D\uFF0C\u89C1 headers.ts \u6CE8\u91CA\uFF09
|
|
512
|
-
`};function Zl(e){if(!e||e.length<12)return e;const n=e[0],t=e[1],r=e[2],o=e[3];if(!(n===0&&t===1&&r===0&&o===0)&&!(n===79&&t===84&&r===84&&o===79))return e;const a=Uint8Array.from(e),c=new DataView(a.buffer,a.byteOffset,a.byteLength),u=c.getUint16(4);if(u<=0||12+u*16>a.length)return e;let l=-1,f=0,p=0;for(let M=0;M<u;M++){const h=12+M*16;if(String.fromCharCode(a[h],a[h+1],a[h+2],a[h+3])==="cmap"){l=h,f=c.getUint32(h+8),p=c.getUint32(h+12);break}}if(l<0||f+p>a.length)return e;let d=!1;const y=c.getUint16(f+2);for(let M=0;M<y;M++){const h=f+4+M*8,g=c.getUint32(h+4),v=f+g;if(v+14>a.length||c.getUint16(v)!==4)continue;const A=c.getUint16(v+6),_=A>>>1;if(_<1)continue;const R=2*Math.pow(2,Math.floor(Math.log2(_))),L=Math.floor(Math.log2(_)),N=A-R,j=c.getUint16(v+8),H=c.getUint16(v+10),K=c.getUint16(v+12);j===R&&H===L&&K===N||(c.setUint16(v+8,R),c.setUint16(v+10,L),c.setUint16(v+12,N),d=!0)}if(!d)return e;let x=0;const m=f+p;for(let M=f;M<m;M+=4){const h=a[M]||0,g=M+1<m?a[M+1]:0,v=M+2<m?a[M+2]:0,A=M+3<m?a[M+3]:0;x=x+(h<<24|g<<16|v<<8|A)>>>0}return c.setUint32(l+4,x),a}const Kl={systemfont_segoe:"'Segoe UI', 'Helvetica Neue', Arial, sans-serif",systemfont_arial:"Arial, 'Helvetica Neue', sans-serif",systemfont_verdana:"Verdana, Geneva, sans-serif",systemfont_tahoma:"Tahoma, Geneva, sans-serif",systemfont_timesnewroman:"'Times New Roman', Times, serif",systemfont_georgia:"Georgia, 'Times New Roman', serif",systemfont_couriernew:"'Courier New', Courier, monospace",systemfont_trebuchetms:"'Trebuchet MS', 'Helvetica Neue', sans-serif",systemfont_impact:"Impact, 'Arial Black', sans-serif",systemfont_comicsansms:"'Comic Sans MS', 'Comic Sans', cursive",systemfont_sylfaen:"Palatino, 'Times New Roman', serif",systemfont_calibri:"Calibri, Carlito, 'Helvetica Neue', sans-serif",systemfont_cambria:"Cambria, Georgia, serif",systemfont_consolas:"Consolas, 'Courier New', monospace",systemfont_microsoftyahei:"'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', sans-serif",systemfont_simsun:"SimSun, 'Songti SC', serif",systemfont_simhei:"SimHei, 'Heiti SC', sans-serif"},wr=new Map;function Ql(e){let n=5381;for(let t=0;t<e.length;t++)n=(n<<5)+n+e.charCodeAt(t)|0;return(n>>>0).toString(36)}function Jl(e){for(const n of e){const t=wr.get(n);if(t&&(t.refs--,!(t.refs>0))){wr.delete(n);try{const r=[];document.fonts.forEach(o=>{o.family===t.family&&r.push(o)});for(const o of r)document.fonts.delete(o)}catch{}}}}const an=new Map,eu=512*1024*1024;let fo=0;function tu(e){for(;an.size>0&&(an.size>2||fo>eu);){let n=null,t=1/0;for(const[o,i]of an)o!==e&&i.at<t&&(t=i.at,n=o);if(!n)break;const r=an.get(n);fo-=r.parsed.fileSize||0,an.delete(n)}}async function nu(e,n,t,r){const o=t.key;if(o){const c=an.get(o);if(c)return c.at=Date.now(),se(e,n,`pkg cache hit: ${c.parsed.fileSize} bytes`),c.parsed}let i;try{i=await t.scenePkg(r)}catch(c){throw r.aborted||c instanceof Error?c:new Error(String(c))}se(e,n,`pkg body: ${i.byteLength} bytes`);const s=i instanceof Uint8Array?i:new Uint8Array(i),a=He.parsePkg(s);return o&&(an.set(o,{parsed:a,at:Date.now()}),fo+=a.fileSize||0,tu(o)),a}function ru(e,n){rn(e);const t=(n.canvas instanceof HTMLCanvasElement?n.canvas:null)??document.createElement("canvas"),r=Wt(e,n),o=t.clientWidth||window.innerWidth||1,i=t.clientHeight||window.innerHeight||1;t.width=Math.max(1,Math.round(o*r)),t.height=Math.max(1,Math.round(i*r)),n.canvas instanceof HTMLCanvasElement||(t.style.cssText="position:absolute;inset:0;width:100%;height:100%;",e.wrap?.appendChild(t)),e.canvas=t;let s=!1;const a=console.warn.bind(console);console.warn=(...y)=>{const x=y.map(m=>typeof m=="string"?m:String(m?.message??m)).join(" ");if(x.includes("[we-scene]"))try{se(e,n,x.slice(0,300))}catch{}a(...y)};const c=new AbortController;let u;e.sceneCleanup=()=>{s=!0,console.warn=a,c.abort(),e.sceneTextUpdate=void 0,u&&(u(),u=void 0),e.renderer&&(e.renderer.dispose?.(),e.renderer=void 0)};let l=null,f,p,d;e.sceneCtl={pause(){p?.()},resume(){d?.()},applyUserProperties(y){f?f(y):l={...l||{},...y}}},(async()=>{try{const y=n.source??is(`${n.mediaBase}/${n.src}`);if(!n.source&&(!n.mediaBase||!n.src))throw new Error("\u573A\u666F\u58C1\u7EB8\u7F3A\u5C11 mediaBase/src");se(e,n,"mountScene start");const x=await nu(e,n,y,c.signal);if(s)return;let m=null;try{m=await y.project?.(c.signal)??null}catch{}if(!t.getContext("webgl2",{premultipliedAlpha:!1,antialias:!1,alpha:!1,preserveDrawingBuffer:!0}))throw new Error("WEBGL2_UNAVAILABLE");const h=He.getEntry(x,"scene.json");if(!h)throw new Error("pkg \u4E2D\u6CA1\u6709 scene.json\uFF08\u4E0D\u662F\u573A\u666F\u58C1\u7EB8\uFF1F\uFF09");const g=Ye.parseScene(JSON.parse(pt(h)),m);if(n.clearColor){const b=g.general??={};b.clearcolor=n.clearColor,b.clearenabled=!0}{const b=g.general?.zoom,T=Number(b&&typeof b=="object"?b.value:b);g.cameraTransforms={zoom:Number.isFinite(T)&&T>0?T:1}}const v=ta(g.properties||{});e.liveUserProps=v;const A=()=>Ye.recomputeLayerVisibility(g.layers);if(e.onSceneInfo){const b=g.general?.orthogonalprojection||{},T=Number(b.width)>0?Number(b.width):t.width,P=Number(b.height)>0?Number(b.height):t.height,C=g.layers||[],I={width:T,height:P,layerCount:C.length,hasModels:C.some($=>!!$.model),hasParticles:C.some($=>!!$.particle),hasText:C.some($=>!!$.text)},D=e.onSceneInfo;e.onSceneInfo=void 0,D(I)}const _=[];ls&&(g.layers=g.layers.filter(b=>!(ls&&b.isComponent)));const R=b=>{const T=b.startsWith("shaders/")?b:"shaders/"+b,P=b.startsWith("shaders/")?b.slice(8):b,C=He.getEntry(x,T);let I=C?pt(C):ql[P]??null;const D=window.__shaderPatch;if(I&&D){const $=P.replace(/\.(frag|vert|h)$/,""),z=D[$]||D[P];if(typeof z=="function")try{const B=z(I,P);typeof B=="string"&&(I=B)}catch{}}return Promise.resolve(I)},L=Ne.createRenderer(t,{shaderResolver:R,diag:b=>se(e,n,`renderer: ${b}`),fboCapFactor:0});if(e.renderer=L,s)return;const N=m?.general?.supportsaudioprocessing!==!1,j=qi(),H=xe.createSimulatedMedia(),K=ns.createSimulatedWindowTitle();let O=null;const V={mediaDriver:null,lastSnap:{get:()=>null,setHasThumbnail:()=>{}}},X={current:null};let ie=null;const J=()=>ie??e.mediaSource??H;let Z=K;const te={enabled:N&&!e.audioDisabled},le=b=>new Float32Array(b),Ue={left16:le(16),right16:le(16),left32:le(32),right32:le(32),left64:le(64),right64:le(64),level:0,silent:!0},_e=(()=>{const b={left64:le(64),right64:le(64),left32:le(32),right32:le(32),left16:le(16),right16:le(16),preL64:le(64),preR64:le(64),level:0,silent:!0},T=(P,C)=>{const I=C.length/P.length;for(let D=0;D<P.length;D++){let $=0;const z=Math.floor(D*I),B=Math.max(z+1,Math.floor((D+1)*I));for(let q=z;q<B;q++)$+=C[q];P[D]=$/(B-z)}};return{active:!1,snapshot:b,pump(){const P=e.audioBridge?.();if(!P||!P.left||!P.right){this.active=!1;return}const C=Math.min(64,P.left.length,P.right.length);let I=0;for(let D=0;D<C;D++){const $=P.left[D]||0,z=P.right[D]||0;b.left64[D]=$,b.right64[D]=z,b.preL64[D]=$,b.preR64[D]=z,D<48&&(I+=$)}for(let D=C;D<64;D++)b.left64[D]=0,b.right64[D]=0,b.preL64[D]=0,b.preR64[D]=0;T(b.left32,b.left64),T(b.right32,b.right64),T(b.left16,b.left64),T(b.right16,b.right64),b.level=Math.min(1,I/48),b.silent=b.level<.02,this.active=!0}}})(),Ze=()=>_e.active?_e.snapshot:X.current?X.current.snapshot:j.snapshot;L.setAudioProvider(()=>te.enabled?Ze():Ue);const Xe=new Map;window.__audioStats=()=>({enabled:te.enabled,live:!!X.current,level:te.enabled?Math.round((X.current?X.current.snapshot:j.snapshot).level*1e3)/1e3:0,silent:te.enabled?(X.current?X.current.snapshot:j.snapshot).silent:!0,bass:te.enabled?Math.round((X.current?X.current.snapshot:j.snapshot).left64[2]*1e3)/1e3:0}),window.__audioMute=b=>(te.enabled=!b,te.enabled),se(e,n,`audio: ${X.current?"live mic":"simulated"} stream, supportsaudioprocessing=${N}`);const De=ns.createShortcutHandler(b=>{se(e,n,`openUserShortcut: ${b}`)}),Ke={enabled:!e.mediaDisabled,override:null},Be=[];let ye=null;V.lastSnap={get:()=>ye,setHasThumbnail:b=>{ye&&(ye.hasThumbnail=b)}};const he=()=>J().snapshot,Ie=b=>{if(!(!b||!b.hasMediaHook||Be.includes(b))&&(Be.push(b),!!he().hasMedia))for(const{name:T,event:P}of xe.diffMediaEvents(null,he()))try{b.callMedia(T,P)}catch{}};window.__mediaStats=()=>({enabled:Ke.enabled,live:!!O,hooks:Be.length,title:he().title,artist:he().artist,album:he().album,state:he().state,position:Math.round(he().position),duration:he().duration,hasThumbnail:he().hasThumbnail,lyric:he().lyricLine,primaryColor:he().primaryColor?[he().primaryColor.x,he().primaryColor.y,he().primaryColor.z]:null}),window.__mediaSet=b=>{Object.assign(he(),b||{});const T=xe.diffMediaEvents(ye,he());for(const{name:P,event:C}of T)for(const I of Be)I.callMedia(P,C);return ye=xe.cloneMediaSnapshot(he()),window.__mediaStats()};const Pe=()=>{const b=xe.diffMediaEvents(ye,he());for(const{name:T,event:P}of b)for(const C of Be)try{C.callMedia(T,P)}catch{}ye=xe.cloneMediaSnapshot(he())},Qe=b=>{const T=J(),P=T?.[b];if(typeof P=="function")try{P.call(T)}catch(C){se(e,n,`media ${b} \u5931\u8D25: ${C?.message}`)}return Pe(),he()},Oe={get snapshot(){return he()},skipNext:()=>Qe("skipNext"),skipPrevious:()=>Qe("skipPrevious"),play:()=>Qe("play"),pause:()=>Qe("pause"),playPause:()=>Qe("playPause")};e.mediaCtl=Oe,window.__mediaControl=Oe,window.__system={media:Oe,windowTitle:Z.snapshot,shortcuts:De.last,live:null},window.__liveSystem=()=>({audio:"off",media:"offline",window:"offline"});const Ae=_l.createPointerSource(n.canvas?{target:n.canvas,viewport:()=>({w:n.canvas.clientWidth||window.innerWidth||1,h:n.canvas.clientHeight||window.innerHeight||1})}:{});L.setPointerProvider(()=>Ae),e.pointerCtl={push:b=>Ae.pushExternal(b),leave:()=>Ae.pushExternalLeave()};{const b=u;u=()=>{b?.(),Ae.dispose()}}const ot=et.createInputView(),it=Ml.createEngineTimers({setTimeout:(b,T)=>window.setTimeout(b,T),clearTimeout:b=>window.clearTimeout(b),setInterval:(b,T)=>window.setInterval(b,T),clearInterval:b=>window.clearInterval(b)},{onError:(()=>{let b=!1;return T=>{b||(b=!0,se(e,n,`engine \u5B9A\u65F6\u5668\u56DE\u8C03\u629B\u9519\uFF08\u6B64\u540E\u540C\u7C7B\u9759\u9ED8\uFF09: ${String(T?.message||T).slice(0,90)}`))}})()}),It={setTimeout:it.setTimeout,clearTimeout:it.clearTimeout,setInterval:it.setInterval,clearInterval:it.clearInterval};{const b=u;u=()=>{b?.(),it.dispose()}}window.__pointerStats=()=>{const b=Ae.state,T=P=>Math.round(P*1e3)/1e3;return{normalized:{u:T(b.u),v:T(b.v)},last:{u:T(b.lastU),v:T(b.lastV)},world:{x:Math.round(b.wx),y:Math.round(b.wy)},originY:b.originY!=null?Math.round(b.originY):null,screen:{x:b.screenX,y:b.screenY,w:b.screenW,h:b.screenH},leftDown:b.leftDown,has:b.has,delta:T(Ae.normalizedDelta()),counts:{move:b.moveCount,down:b.downCount,up:b.upCount}}};const we=new Map;we.set("util/white",{glTex:Ne.makeTexture(L.gl,new Uint8Array([255,255,255,255]),1,1),width:1,height:1,rg88:!1}),we.set("util/noflow",{glTex:Ne.makeTexture(L.gl,new Uint8Array([127,127,127,255]),1,1),width:1,height:1,rg88:!1}),we.set("util/noise",{glTex:Ne.makeTexture(L.gl,xl.generateNoiseTexture(),256,256),width:256,height:256,rg88:!1,mips:null});{const b=P=>{const C=xe.renderThumbnail(P,512);return{glTex:Ne.makeTextureMip(L.gl,[C],!1),width:C.width,height:C.height,rg88:!1,mips:[C],generated:!0}},T=H.tracks||[];T.length&&(we.set("$mediaThumbnail",b(T[0])),we.set("$mediaPreviousThumbnail",b(T[T.length-1])))}if(n.liveSystem){const b={handle:null,dead:!1};(e.wallpaperDisposers??=[]).push(()=>{b.dead=!0;try{b.handle?.dispose()}catch{}b.handle=null});try{const T=async P=>{try{const C=await fetch(P.url,{cache:"no-store"});if(!C.ok)return;const I=await C.blob(),D=await createImageBitmap(I),$=Xl(D,D.width,D.height,512),z=Hl(D,D.width,D.height);D.close?.();const B=we.get("$mediaThumbnail");B&&we.set("$mediaPreviousThumbnail",B);const q=L.gl,S=we.get("$mediaThumbnail");S?.glTex?(q.bindTexture(q.TEXTURE_2D,S.glTex),q.texImage2D(q.TEXTURE_2D,0,q.RGBA,$.width,$.height,0,q.RGBA,q.UNSIGNED_BYTE,$.rgba),S.width=$.width,S.height=$.height,S.mips=[$]):we.set("$mediaThumbnail",{glTex:Ne.makeTextureMip(q,[$],!1),width:$.width,height:$.height,rg88:!1,mips:[$],generated:!0});const E=J().snapshot;z&&(E.primaryColor=xe.mediaVec3(...z.primary),E.secondaryColor=xe.mediaVec3(...z.secondary),E.tertiaryColor=xe.mediaVec3(...z.tertiary),E.textColor=xe.mediaVec3(.98,.98,1),E.highContrastColor=xe.mediaVec3(1,1,1)),E.hasThumbnail=!0,V.lastSnap.setHasThumbnail(!1),se(e,n,`liveSystem: artwork ${P.title||P.trackKey}`)}catch(C){se(e,n,`liveSystem: artwork \u5931\u8D25 (${C instanceof Error?C.message:C})`)}};if(O=await ps({origin:location.origin,onArtwork:P=>{T(P)}}),b.dead){try{O.dispose()}catch{}O=null}else{if(b.handle=O,ie=O.media,Z=O.windowTitle,V.mediaDriver=O.media,O.status().audio==="mic"&&(X.current=O.audio),J().snapshot.hasMedia){for(const{name:C,event:I}of xe.diffMediaEvents(null,J().snapshot))for(const D of Be)try{D.callMedia(C,I)}catch{}ye=xe.cloneMediaSnapshot(J().snapshot)}const P=O.status();se(e,n,`liveSystem: audio=${P.audio} media=${P.media} window=${P.window}`+(P.title?` title="${P.title}"`:"")+(P.hasArtwork?" artwork=1":"")),se(e,n,`audio: ${X.current?"live mic":"simulated"} stream, supportsaudioprocessing=${N}`),window.__system={media:Oe,windowTitle:Z.snapshot,shortcuts:De.last,live:()=>O.status()},window.__liveSystem=()=>O.status()}}catch(T){se(e,n,`liveSystem: \u542F\u52A8\u5931\u8D25\uFF0C\u56DE\u9000\u6A21\u62DF\u6E90 (${T instanceof Error?T.message:T})`),O=null}}{const b=u;u=()=>{b?.(),O?.dispose(),O=null}}const Kt=new Map,go=async b=>{if(we.has(b))return we.get(b);const T=He.getEntry(x,`materials/${b}.tex`);if(!T){if(sn.isBuiltinParticleTextureName(b)){const $=sn.buildBuiltinParticleTexture(b);if($){const z={glTex:Ne.makeTextureMip(L.gl,[$],!1),width:$.width,height:$.height,rg88:!1,mips:[$],generated:!0};return we.set(b,z),z}}return null}const P=vr.parseTex(T),C=vr.decodeMip0(P),I=P.format===8;let D=null;if(C.video!==void 0){const $=URL.createObjectURL(new Blob([C.video],{type:"video/mp4"})),z=Il($,{muted:!0,renderDpr:Wt(e,n),maxW:t.clientWidth||window.innerWidth||1,maxH:t.clientHeight||window.innerHeight||1});for(const F of[z.active,z.standby])F.style.cssText="position:fixed;left:-9999px;top:-9999px;width:2px;height:2px;opacity:0;pointer-events:none",document.body.appendChild(F),(e.videoTextures??=[]).push(F);(e.objectUrls??=[]).push($),(e.videoPairs??=[]).push(z),z.active.addEventListener("loadedmetadata",()=>{se(e,n,`video tex '${b}': ${z.active.videoWidth}x${z.active.videoHeight}`)}),z.active.addEventListener("error",()=>{se(e,n,`video tex '${b}' ERROR: ${z.active.error?.code}`)});const B=[],q=F=>{for(const re of B)F.addEventListener("ended",re)},S={play:()=>{s||z.resume()},pause:()=>z.pause(),stop:()=>{z.pause();try{z.active.currentTime=0}catch{}},isPlaying:()=>!z.active.paused&&!z.active.ended,duration:()=>Number.isFinite(z.active.duration)?z.active.duration:0,getCurrentTime:()=>z.active.currentTime||0,setCurrentTime:F=>{try{z.active.currentTime=F}catch{}},getRate:()=>z.active.playbackRate||1,setRate:F=>{z.active.playbackRate=F,z.standby.playbackRate=F},getLoop:()=>z.active.loop,setLoop:F=>{z.active.loop=F,z.standby.loop=F},addEndedCallback:F=>{B.push(F),z.active.addEventListener("ended",F)}},E={get video(){return z.active},glTex:Ne.makeTexture(L.gl,new Uint8Array([0,0,0,0]),1,1),width:C.width,height:C.height,rg88:!1,lastUploaded:-1,videoCtl:S};let k=0;return z.onSwap=F=>{E.lastUploaded=-1,q(F),k++,(k===1||k===10||k===100)&&se(e,n,`video tex '${b}' loop swap ok x${k}`)},z.onFallback=()=>{se(e,n,`video tex '${b}' loop fallback (native loop used)`)},we.set(b,E),E}else if(C.png!==void 0||C.image!==void 0&&C.fif===vr.FIF.JPEG){const $=new Blob([C.png||C.image],{type:C.png?"image/png":"image/jpeg"}),z=await createImageBitmap($);D={glTex:Ne.makeTexture(L.gl,null,0,0,z),width:z.width,height:z.height,rg88:I}}else{if(C.image!==void 0)return null;{const $=vr.decodeMip0(P);D={glTex:Ne.makeTextureMip(L.gl,[$],I),width:$.width,height:$.height,rg88:I,mips:[$]}}}if(!D)return null;if(P.frames?.list?.length){const $=P.frames.list;$.atlasWidth=D.width,$.atlasHeight=D.height,D.frames=$}return we.set(b,D),D},Qt=b=>{if(we.has(b))return Promise.resolve(we.get(b));const T=Kt.get(b);if(T)return T;const P=go(b);return Kt.set(b,P),P.finally(()=>{Kt.get(b)===P&&Kt.delete(b)}),P},Wn=/uniform\s+sampler2D\s+g_Texture\d+\s*;\s*\/\/[^\n]*"default"\s*:\s*"([^"]+)"/g,Me=async b=>{for(const T of b.materialPasses||[])if(T.shader)for(const P of["frag","vert"]){const C=He.getEntry(x,`shaders/${T.shader}.${P}`);if(!C)continue;const I=pt(C);Wn.lastIndex=0;let D;for(;(D=Wn.exec(I))!==null;){const $=D[1];!$||$.startsWith("util/")||$.startsWith("_rt_")||we.has($)||await Qt($)}}};let Vn=0;const Jt=[];for(let b=0;b<g.layers.length;b++){const T=g.layers[b];if(T.image)try{let P;if(Pt.BUILTIN_MODELS[T.image])P=Pt.BUILTIN_MODELS[T.image];else{const E=He.getEntry(x,T.image);if(!E)continue;P=JSON.parse(pt(E))}Ye.applySolidFromModel(T,P);const C=T.srcObject?.instance?.usertextures,I=C?.[0]&&typeof C[0].name=="string"&&C[0].name.startsWith("$")?C[0].name:null,D=I&&we.has(I)?I:null;if(D&&(T.textureName=D,T.solid=!1),P&&typeof P=="object"&&"width"in P&&"height"in P){const E=P;(T.size?.[0]||0)===0&&(T.size?.[1]||0)===0&&E.width>0&&E.height>0&&(T.size=[E.width,E.height])}const $=Ye.resolveMaterial(P);if(!$)continue;let z;if(Pt.BUILTIN_MATERIALS[$.materialPath])z=Pt.BUILTIN_MATERIALS[$.materialPath];else{const E=He.getEntry(x,$.materialPath);if(E)z=JSON.parse(pt(E));else if(T.solid&&Pt.BUILTIN_MATERIALS["materials/util/solidlayer.json"])z=Pt.BUILTIN_MATERIALS["materials/util/solidlayer.json"];else continue}const B=z.passes?.[0],q=B?.textures||[],S=q[0];if(B?.combos){for(const E of Object.keys(B.combos))if(E.toLowerCase()==="spritesheet"&&Number(B.combos[E])===1){T.spriteSheet=!0;break}}for(let E=0;E<q.length;E++){const k=q[E];typeof k!="string"||!k||k.startsWith("util/")||k.startsWith("_rt_")||Jt.push(Qt(k).then(F=>{F&&E===0&&!D&&(T.textureName=k,Vn++,F.videoCtl&&(T.videoCtl=F.videoCtl))}))}B?.shader&&He.getEntry(x,`shaders/${B.shader}.frag`)&&Pt.attachLayerMaterialEffect(T,B);for(const E of T.effects||[])Pt.resolveEffectChain(x,E,pt);for(const E of T.effects||[]){for(const k of E.passes||[])for(const F of k.textures||[])typeof F=="string"&&F!==""&&!F.startsWith("util/")&&!F.startsWith("_rt_")&&Jt.push(Qt(F));Jt.push(Me(E))}}catch(P){console.warn(`\u56FE\u5C42 ${T.name||b} \u52A0\u8F7D\u5931\u8D25: ${P.message}`)}}if(!us){for(const b of g.layers)if(!(!b.isText||!(b.effects||[]).length))try{for(const T of b.effects||[])Pt.resolveEffectChain(x,T,pt);for(const T of b.effects||[])for(const P of T.passes||[])for(const C of P.textures||[])typeof C=="string"&&C!==""&&!C.startsWith("util/")&&!C.startsWith("_rt_")&&Jt.push(Qt(C))}catch(T){console.warn(`\u6587\u5B57\u5C42\u6548\u679C ${b.name} \u89E3\u6790\u5931\u8D25: ${T.message}`)}}await Promise.all(Jt);for(const[b,T]of we){if(!T?.videoCtl)continue;g.layers.some(C=>C.textureName===b&&C.visible&&!C.destroyed)&&!e.paused&&T.videoCtl.play()}const tt=[],Hn=[],en=new Map;let _r=0;const Ar=async b=>{const T=await Qt(b);if(T)return T;const P=sn.buildBuiltinParticleTexture(b);if(!P)return null;const C={glTex:Ne.makeTextureMip(L.gl,[P],!1),width:P.width,height:P.height,rg88:!1,mips:[P],generated:!0,frames:sn.builtinParticleFrames(b)??void 0};return we.set(b,C),_r++,C},bo=b=>{if(!b)return null;const T=b.mips&&b.mips[0];if(T?.rgba&&typeof sn.prepareParticleNormalTexture=="function"){const P=sn.prepareParticleNormalTexture(T);if(P&&P!==T)return{glTex:Ne.makeTextureMip(L.gl,[P],!1),width:P.width,height:P.height,rg88:!1,mips:[P],generated:!0}}return b},Tr=async(b,T,P,C)=>{if(C>3)return null;const I=He.getEntry(x,b);if(!I)return se(e,n,`particle '${b}' \u4E0D\u5728 pkg\uFF0C\u8DF3\u8FC7`),null;const D=JSON.parse(pt(I)),$=new wl.ParticleSystem(L.gl,D,P,T);let z=null,B=null;if(D.material){const k=He.getEntry(x,D.material);if(k){const F=JSON.parse(pt(k));$.setMaterial(F);const re=F?.passes?.[0]?.textures||[];z=re[0]||null,B=re[1]||null}}const q=await Ar(z||"particle/halo");if(!q)return se(e,n,`particle '${b}' \u65E0\u8D34\u56FE\u53EF\u7528\uFF0C\u8DF3\u8FC7`),null;$.setTexture({glTex:q.glTex,width:q.width,height:q.height,frames:q.frames});const S=B||($.refract?sn.particleNormalNameForAlbedo(z||"particle/halo"):null);if(S){const k=bo(await Ar(S));k&&$.setNormalTexture({glTex:k.glTex,width:k.width,height:k.height})}$.setVisible(!!T.visible),tt.push($);const E=T.id;if(E!==void 0){let k=en.get(E);k||(k=[],en.set(E,k)),k.push($)}for(const k of D.children||[]){if(!k||typeof k.name!="string")continue;const F=String(k.origin??"0 0 0").trim().split(/\s+/).map(Number),re=String(k.scale??"1 1 1").trim().split(/\s+/).map(Number),Q=String(k.angles??"0 0 0").trim().split(/\s+/).map(Number),ce=k.type==="eventfollow"?"particle":!k.type||k.type==="static"?"origin":null,ue=$.localToWorld(F[0]||0,F[1]||0),ge={...T,origin:[ue[0],ue[1],(T.origin?.[2]||0)+(F[2]||0)],scale:[(T.scale?.[0]??1)*(re[0]||1),(T.scale?.[1]??1)*(re[1]||1),(T.scale?.[2]??1)*(re[2]||1)],angles:[(T.angles?.[0]||0)+(Q[0]||0),(T.angles?.[1]||0)+(Q[1]||0),(T.angles?.[2]||0)+(Q[2]||0)]},$e=await Tr(k.name,ge,k.instanceoverride||P,C+1);$e&&ce&&$e.attachFollow($,ce,[F[0]||0,F[1]||0,F[2]||0])}return $};if(!Ol){for(const b of g.layers)if(b.particle)try{await Tr(b.particle,b,b.instanceoverride,0)}catch(T){console.warn(`\u7C92\u5B50\u56FE\u5C42 ${b.name} \u52A0\u8F7D\u5931\u8D25: ${T.message}`),se(e,n,`particle '${b.name}' FAIL: ${T.message.slice(0,80)}`)}}if(tt.length>0){const b=u;u=()=>{b?.();for(const T of tt)T.dispose()}}const tn=[];for(const b of g.layers)if(!(!b.sound||!b.sound.length))try{for(const T of b.sound){const P=He.getEntry(x,T);if(!P)continue;const C=(T.split(".").pop()||"").toLowerCase(),I=C==="mp3"?"audio/mpeg":C==="ogg"?"audio/ogg":C==="flac"?"audio/flac":"audio/wav",D=new Blob([P],{type:I}),$=URL.createObjectURL(D);(e.objectUrls??=[]).push($);const z=document.createElement("audio");z.src=$,z.loop=b.soundprops?.playbackmode==="loop",z.volume=Math.max(0,Math.min(1,b.soundprops?.volume??1)),z.muted=n.muted!==!1,b.soundCtl={play(){if(z.ended)try{z.currentTime=0}catch{}z.play().catch(()=>{})},pause(){z.pause()},stop(){z.pause();try{z.currentTime=0}catch{}},isPlaying:()=>!z.paused&&!z.ended,getVolume:()=>z.volume,setVolume:B=>{z.volume=Math.max(0,Math.min(1,B))}},!b.soundprops?.startsilent&&!e.paused&&z.play().catch(()=>{}),tn.push(z);break}}catch(T){console.warn(`\u58F0\u97F3\u56FE\u5C42 ${b.name} \u52A0\u8F7D\u5931\u8D25: ${T.message}`)}const yo=b=>{for(const T of tn)T.volume=Math.max(0,Math.min(1,b)),T.muted=b<=0};if(e.sceneAudio={setVolume:yo,audios:tn},s)return;let wn=performance.now(),ln=0;L.setParticleRenderer(()=>{const b=performance.now(),T=Math.min(.05,(b-wn)/1e3);if(wn=b,Ae.state.has){const{wx:P,wy:C,originY:I}=Ae.state,D=I??C;for(const $ of tt)$.setPointer(P,D)}if(Hn.length)for(const P of Hn)P.syncLayerTransform();for(const P of tt)P.advance(T,te.enabled?Ze():null);if(ln<2&&(ln++,ln===2)){const P=tt.reduce((C,I)=>C+I.liveCount(),0);se(e,n,`particles live: ${P} across ${tt.length} systems`)}},(b,T,P,C,I)=>{if(b===void 0)return;const D=en.get(b);if(D)for(const $ of D)$.render(P,C,I,T.projW,T.projH)}),se(e,n,`particles: ${tt.length} systems, ${_r} builtin tex generated`),window.__particleStats=()=>tt.map(b=>{let T=0,P=1/0,C=-1/0,I=1/0,D=-1/0,$=1/0,z=-1/0;for(const B of b.pool){if(!B.alive)continue;T++;const q=b.originX+B.x*b.scaleX,S=b.originY+B.y*b.scaleY;q<P&&(P=q),q>C&&(C=q),S<I&&(I=S),S>D&&(D=S);const E=Math.abs(B.size)*b.sysScale;E<$&&($=E),E>z&&(z=E)}return{live:T,max:b.maxCount,blend:b.blend,renderer:b.renderers.map(B=>B.kind).join("+"),origin:[Math.round(b.originX),Math.round(b.originY)],bbox:T?[Math.round(P),Math.round(I),Math.round(C),Math.round(D)]:null,size:T?[Math.round($),Math.round(z)]:null}}),window.__particleToggle=(b,T)=>{for(let P=0;P<tt.length;P++)tt[P].setVisible(T===void 0?b:P===T);return tt.length};const st=[],bt=new Map,Te=b=>{if(!b||!b.puppet)return null;let T=bt.get(b);return T||(T=new Map,bt.set(b,T)),T};for(const b of g.layers)if(b.image)try{if(Pt.BUILTIN_MODELS[b.image])continue;const T=He.getEntry(x,b.image);if(!T)continue;const P=JSON.parse(pt(T));if(!P.puppet)continue;const C=He.getEntry(x,P.puppet);if(!C)continue;const I=jn.parseMDL(new Uint8Array(C)),D=b.textureName?we.get(b.textureName):null;if(!D){se(e,n,`puppet '${b.name}' \u65E0\u8D34\u56FE\uFF0C\u8DF3\u8FC7`);continue}b.puppet=I,st.push({mdl:I,tex:D,layer:b});const $=I.animations[0];se(e,n,`puppet '${b.name}' v=${I.vertexCount} bones=${I.bones.length}`+($?` anim='${$.name}' ${$.fps}fps\xD7${$.frameCount}`:" \u65E0\u52A8\u753B"))}catch(T){console.warn(`puppet \u56FE\u5C42 ${b.name} \u52A0\u8F7D\u5931\u8D25: ${T.message}`),se(e,n,`puppet '${b.name}' \u5931\u8D25: ${T.message}`)}for(const b of g.layers)if(b.model&&!b.puppet)try{const T=He.getEntry(x,b.model);if(!T)continue;const P=jn.parseMDL(new Uint8Array(T));let C=null;if(P.materialPath){const D=He.getEntry(x,P.materialPath);if(D){const z=JSON.parse(pt(D))?.passes?.[0]?.textures?.[0];typeof z=="string"&&z&&(C=z)}}C&&(await Qt(C),b.textureName=C);const I=C?we.get(C):null;if(!I){se(e,n,`model '${b.name}' \u65E0\u8D34\u56FE\uFF0C\u8DF3\u8FC7`);continue}b.puppet=P,st.push({mdl:P,tex:I,layer:b}),se(e,n,`model '${b.name}' v=${P.vertexCount} static ${P.materialPath||""}`)}catch(T){console.warn(`model \u56FE\u5C42 ${b.name} \u52A0\u8F7D\u5931\u8D25: ${T.message}`),se(e,n,`model '${b.name}' \u5931\u8D25: ${T.message}`)}let yt=null;if(st.length>0)try{yt=jn.createMDLRenderer(L.gl);for(const T of st)yt.upload(T.mdl);const b=new Map;for(const T of st)b.set(T.layer,T);L.setPuppetRenderer((T,P,C)=>{const I=b.get(T);I&&yt.draw(P,I.mdl,{time:C.time,animLayers:T.animationLayers,boneOverrides:bt.get(T),overrideTex:C.overrideTex||null,color:[T.color[0]*T.brightness,T.color[1]*T.brightness,T.color[2]*T.brightness,T.alpha]},I.tex)})}catch(b){console.warn(`puppet \u6E32\u67D3\u5668\u521D\u59CB\u5316\u5931\u8D25: ${b.message}`),se(e,n,`puppet renderer \u5931\u8D25: ${b.message}`),yt=null;for(const T of st)T.layer.puppet=null}if(s)return;se(e,n,`puppet: ${st.length} meshes`);const nn=jn.applyAttachmentBindOrigins(g.layers);nn.length&&se(e,n,`attachments: ${nn.length} hanging layers`);const at=Ye.collectTransformDirty(g.layers,nn.map(b=>b.layer));if(at.size){se(e,n,`transform graph: ${at.size} live layers`);for(const[b,T]of en)if(at.has(b))for(const P of T)Hn.push(P)}const vt=[],Ct=new Map,Ot={};let Lt=null,Xn=null,Gn=0;if(!us&&g.layers.some(b=>b.isText)){const b=g.general?.orthogonalprojection,T=b?.width||t.width,P=b?.height||t.height,C=Ir(dn(e.cfg.fit),T,P,t.width,t.height),I=Math.min(3,Math.max(.5,t.width/Math.max(1,C.viewW))),D=new Map,$=[],z=new Set;for(const S of g.layers)S.isText&&S.textFont&&z.add(S.textFont);for(const S of x.entries||[])typeof S.name=="string"&&/^fonts\/.+\.(ttf|otf|woff2?)$/i.test(S.name)&&z.add(S.name);for(const S of z){const E=`${n.src}|${S}`,k=wr.get(E);if(k){k.refs++,$.push(E),D.set(S,k.family);continue}const F=Kl[S.toLowerCase()];if(F){D.set(S,F);continue}try{const re=He.getEntry(x,S);if(!re)continue;const Q=Zl(re instanceof Uint8Array?re:new Uint8Array(re)),ce="wefont_"+Ql(E)+"_"+S.split("/").pop().replace(/[^a-zA-Z0-9]/g,"_"),ue=URL.createObjectURL(new Blob([Q])),ge=new FontFace(ce,`url(${ue})`);if(await ge.load(),s){URL.revokeObjectURL(ue);break}document.fonts.add(ge),(e.objectUrls??=[]).push(ue),D.set(S,ce),wr.set(E,{family:ce,refs:1}),$.push(E)}catch(re){console.warn(`\u5B57\u4F53\u52A0\u8F7D\u5931\u8D25 ${S}: ${re.message}`)}}if($.length){const S=e.sceneCleanup;e.sceneCleanup=()=>{Jl($),S?.()}}Lt=document.createElement("canvas"),Xn=Lt.getContext("2d");const B=2048;for(const S of g.layers)if(S.isText)try{const E={layer:S,sandbox:null,texName:"__wstext_"+S.id,entry:null,lastKey:null,quality:I};if(S.textScript&&(E.sandbox=et.evalTextScript(S.textScript,S.textScriptProps,{text:S.text??"",font:S.textFont||"",pointsize:S.textPointsize,color:S.textColor,angles:S.angles,origin:S.origin,scale:S.scale,visible:S.visible,canvasSize:{width:T,height:P},userProperties:v,shared:Ot,audioViews:Xe,inputView:ot,...It,mediaControl:Oe,windowTitle:Z.snapshot,openUserShortcut:De.openUserShortcut,getLayerText:Q=>Ct.get(Q),onError:Q=>{se(e,n,`text script '${S.name}' \u5931\u8D25: ${String(Q.message||Q).slice(0,120)}`)}}),E.sandbox&&(_.push(E.sandbox),E.sandbox.init(),E.sandbox.applyUserProperties(v),E.sandbox.hasMediaHook&&Ie(E.sandbox))),Ct.set(S.name||"",String(S.text??"")),S.textAnchor!=="center"&&S.size[0]>0&&S.size[1]>0){const Q=S.size[0]*(S.scale[0]||1)/2,ce=S.size[1]*(S.scale[1]||1)/2,ue=S.textAnchor;let ge=0,$e=0;ue.includes("left")&&(ge+=Q),ue.includes("right")&&(ge-=Q),ue.includes("top")&&($e-=ce),ue.includes("bottom")&&($e+=ce),S.origin[0]+=ge,S.origin[1]+=$e,S.localOrigin&&(S.localOrigin[0]+=ge,S.localOrigin[1]+=$e)}const k=fs*Math.max(1,S.textPointsize),F=et.textLayerHasTintMask(S)?8:256,re=Math.min(F,et.textCanvasMargin(k,0));E.boxW=S.size[0]>0?S.size[0]:k*4,E.boxH=S.size[1]>0?S.size[1]:k*1.6,E.margin=re,S.size=[E.boxW+re*2,E.boxH+re*2],E.entry={glTex:Ne.makeTexture(L.gl,new Uint8Array([0,0,0,0]),1,1),width:1,height:1,rg88:!1},we.set(E.texName,E.entry),S.textureName=E.texName,S.solid=!1,vt.push(E)}catch(E){console.warn(`\u6587\u5B57\u5BF9\u8C61 ${S.name} \u521D\u59CB\u5316\u5931\u8D25: ${E.message}`)}if(vt.length>0){const S=u;u=()=>{S?.();for(const E of vt)L.gl.deleteTexture(E.entry.glTex)}}const q=S=>{if(!Xn||!Lt)return;const E=Xn;for(const k of vt){const F=k.layer;let re=String(F.text??"");if(k.sandbox&&k.sandbox.hasUpdate){k.sandbox.engine.runtime=S;const ge=k.sandbox.callUpdate(re);ge!=null?re=String(ge):k.sandbox.thisLayer.text&&(re=String(k.sandbox.thisLayer.text))}else k.sandbox&&typeof k.sandbox.thisLayer?.text=="string"&&(re=String(k.sandbox.thisLayer.text));if(Ct.set(F.name||"",re),!F.visible)continue;const Q=Math.max(1,k.sandbox?k.sandbox.thisLayer.pointsize:F.textPointsize),ce=k.sandbox&&k.sandbox.thisLayer.font||F.textFont||"",ue=`${re}\0${Q}\0${ce}\0${F.alpha}\0${F.textCastshadow}`;if(k.lastKey!==ue){k.lastKey=ue;try{const ge=fs*Q,$e=k.boxW,Mt=k.boxH,kt=k.margin,_t=Math.abs(F.scale[0]||1),de=Math.abs(F.scale[1]||1);let pe=Math.max(1,Math.round(F.size[0]*_t*k.quality)),fe=Math.max(1,Math.round(F.size[1]*de*k.quality));const Ee=Math.min(1,B/Math.max(pe,fe));pe=Math.max(1,Math.round(pe*Ee)),fe=Math.max(1,Math.round(fe*Ee)),Lt.width!==pe||Lt.height!==fe?(Lt.width=pe,Lt.height=fe):(E.setTransform(1,0,0,1,0,0),E.clearRect(0,0,pe,fe));const ct=Math.min(pe/F.size[0],fe/F.size[1]);E.setTransform(ct,0,0,ct,0,0),E.translate(kt,kt);const lt=ce&&D.get(ce)||"sans-serif";E.font=`${ge}px "${lt}", sans-serif`;const At=E.measureText(""),nt=(At.fontBoundingBoxAscent||0)+(At.fontBoundingBoxDescent||0),Ce=F.textSpacing||[0,0],_n=et.layoutText(re,{boxW:$e,boxH:Mt,pointsize:ge,lineHeight:(nt>0?nt:ge*1.25)+Ce[1],spacing:Ce,padding:F.textPadding||0,maxwidth:F.textMaxwidth||0,limitwidth:!!F.textLimitwidth,maxrows:F.textMaxrows||0,limitrows:!!F.textLimitrows,limituseellipsis:!!F.textLimituseellipsis,halign:F.textHAlign,valign:F.textVAlign},Ge=>E.measureText(Ge).width);et.drawTextLayer(E,_n,{font:E.font,color:F.textColor,alpha:F.alpha,brightness:F.brightness,spacing:Ce,pointsize:ge,opaquebackground:!!F.textOpaquebackground,backgroundcolor:F.textBackgroundcolor,backgroundbrightness:F.textBackgroundbrightness,castshadow:!!F.textCastshadow});const ut=k.entry;L.gl.bindTexture(L.gl.TEXTURE_2D,ut.glTex),L.gl.texImage2D(L.gl.TEXTURE_2D,0,L.gl.RGBA,L.gl.RGBA,L.gl.UNSIGNED_BYTE,Lt),ut.width=pe,ut.height=fe}catch(ge){console.warn(`\u6587\u5B57\u5BF9\u8C61 ${F.name} \u7ED8\u5236\u5931\u8D25: ${ge.message}`),k.lastKey=null}}}};e.sceneTextUpdate=q,window.__textWidgets=vt,se(e,n,`text widgets: ${vt.length} (scripts ${vt.filter(S=>S.sandbox).length}, fonts ${D.size}, quality ${I.toFixed(2)})`)}if(s)return;const $t=[],Yn=[],jt=[],un={},ze=[],xt=[],wt=new Map,Mn=(b,T)=>{if(!T||typeof T.callCursor!="function"||!T.hasCursorHook)return;const P=wt.get(b);P?P.push(T):wt.set(b,[T])};for(const b of vt)b.sandbox&&Mn(b.layer,b.sandbox);{const b=g.general?.orthogonalprojection,T=b?.width||t.width,P=b?.height||t.height,C=v,I=(E,k)=>{const F=g.general||{};if(E==="zoom"&&typeof k=="number"&&Number.isFinite(k)&&k>0){g.cameraTransforms.zoom=k,F.zoom&&typeof F.zoom=="object"?F.zoom.value=k:F.zoom=k;return}F[E]&&typeof F[E]=="object"&&"value"in F[E]?F[E].value=k:F[E]=k};let D=1+Math.max(0,...g.layers.map(E=>Number(E.id)||0));const $={recomputeVisibility:A,getSceneLayer:E=>g.layers.find(k=>k.name===E&&!k.destroyed)||null,getSceneLayerById:E=>g.layers.find(k=>k.id===E&&!k.destroyed)||null,enumerateSceneLayers:()=>g.layers.filter(E=>!E.destroyed),getSceneAnimation:E=>{if(E==null||E==="")return null;if(un[E])return un[E];for(const k of g.layers)if(k.animations&&k.animations[E])return k.animations[E];return null},cameraTransforms:g.cameraTransforms,getInitialLayerConfig:E=>{const k=E&&typeof E=="object"?E.name:String(E||"");return g.layers.find(F=>F.name===k)||null},createSceneLayer:E=>{let k=E&&typeof E=="object"?E:null;if(typeof E=="string"){const re=E;if(k=g.layers.find(Q=>Q&&!Q.destroyed&&Q.image===re&&Q.textureName)||g.layers.find(Q=>Q&&!Q.destroyed&&Q.image===re)||null,!k)return se(e,n,`createLayer('${re}') \u627E\u4E0D\u5230\u5DF2\u52A0\u8F7D\u7684\u540C\u6A21\u578B\u5C42`),null}k||(k={});const F={...k,id:D++,origin:Array.isArray(k.origin)?k.origin.slice():[0,0,0],scale:Array.isArray(k.scale)?k.scale.slice():[1,1,1],angles:Array.isArray(k.angles)?k.angles.slice():[0,0,0],size:Array.isArray(k.size)?k.size.slice():[0,0],color:Array.isArray(k.color)?k.color.slice():[1,1,1],childIds:null,hasChildren:!1,destroyed:!1,animations:{},animationList:[],objectScripts:null};return delete F.textureAnimation,delete F.videoTextureApi,delete F.soundCtl,delete F.videoCtl,Array.isArray(k.effects)&&(F.effects=k.effects.map(re=>({...re,passes:Array.isArray(re.passes)?re.passes.map(Q=>({...Q})):re.passes}))),g.layers.push(F),F},mediaControl:Oe,windowTitle:Z.snapshot,openUserShortcut:De.openUserShortcut,isScreensaver:!1};L.setConstantScriptRuntime?.(et.evalObjectScript,{userProperties:C,audioViews:Xe,shared:Ot,inputView:ot,timers:it,...$,onSandbox:E=>{E&&E.hasMediaHook&&Ie(E)}});const z={origin:"localOrigin",scale:"localScale",angles:"localAngles"},B=(E,k)=>{const F=z[k];return F&&E&&Array.isArray(E[F])?F:k};for(const E of g.layers){const k=E.objectAnimations;if(k){E.animations=E.animations||{},E.animationList=E.animationList||[];for(const[F,re]of Object.entries(k))try{const Q=rs.createAnimation(re.animation);Q.field=F,Q.baseValue=re.value;const ce=B(E,F),ue=E[ce];Q.baseNumeric=Array.isArray(ue)?ue.slice():ue,Q.slot=ce,E.animationList.push(Q),Q.name&&(E.animations[Q.name]=Q),Yn.push({layer:E,field:F,slot:ce,ctrl:Q})}catch(Q){se(e,n,`animation '${E.name}.${F}' \u5EFA\u63A7\u5236\u5668\u5931\u8D25: ${String(Q.message).slice(0,80)}`)}}}for(const E of g.layers){for(const[F,re]of(E.effects||[]).entries()){const Q=re.visibleScript;if(Q)try{const ce=et.evalObjectScript(Q.script,Q.scriptproperties,{canvasSize:{width:T,height:P},userProperties:C,audioViews:Xe,inputView:ot,...It,layer:E,targetEffect:re,...$,shared:Ot,onError:ue=>se(e,n,`effect visible script '${E.name}#${F}' \u5931\u8D25: ${String(ue.message||ue).slice(0,80)}`)});if(!ce)continue;_.push(ce),ce.init(re.visible),ce.applyUserProperties(C),ce.hasMediaHook&&Ie(ce),ce.hasUpdate&&ze.push({effect:re,sandbox:ce})}catch(ce){console.warn(`\u6548\u679C\u5F00\u5173\u811A\u672C ${E.name}#${F} \u6C42\u503C\u5931\u8D25: ${ce.message}`)}}const k=E.objectScripts;if(k)for(const[F,re]of Object.entries(k))try{const Q=et.evalObjectScript(re.script,re.scriptproperties,{canvasSize:{width:T,height:P},screenResolution:{x:t.clientWidth||window.innerWidth||1,y:t.clientHeight||window.innerHeight||1},timeOfDay:(()=>{const ce=new Date;return(ce.getHours()*3600+ce.getMinutes()*60+ce.getSeconds())/86400})(),userProperties:C,audioViews:Xe,inputView:ot,layer:E,...$,getBoneOverrides:Te,shared:Ot,...It,onError:ce=>se(e,n,`object script '${E.name}.${F}' \u5931\u8D25: ${String(ce.message||ce).slice(0,90)}`)});if(Q){_.push(Q);const ce=B(E,F),ue=E[ce],ge=F==="angles"&&Array.isArray(ue)?et.radToScriptAngles(ue):Array.isArray(ue)?{x:ue[0]??0,y:ue[1]??0,z:ue[2]??0}:ue;Q.init(ge),Q.applyUserProperties(C),Mn(E,Q),Q.hasMediaHook&&Ie(Q),Q.hasUpdate&&$t.push({layer:E,field:F,slot:ce,kind:F==="visible"?"bool":F==="alpha"||F==="brightness"?"scalar":"vec3",sandbox:Q})}}catch(Q){console.warn(`\u5BF9\u8C61\u811A\u672C ${E.name}.${F} \u6C42\u503C\u5931\u8D25: ${Q.message}`)}}const q=g.generalScripts;if(q){for(const[E,k]of Object.entries(q))try{const F=et.evalObjectScript(k.script,k.scriptproperties,{canvasSize:{width:T,height:P},userProperties:C,audioViews:Xe,inputView:ot,...It,...$,shared:Ot,onError:Q=>se(e,n,`general script '${E}' \u5931\u8D25: ${String(Q.message||Q).slice(0,80)}`)});if(!F)continue;_.push(F),F.init(k.value),F.applyUserProperties(C),F.hasMediaHook&&Ie(F);const re=Q=>I(E,Q);F.hasUpdate&&xt.push({field:E,sandbox:F,write:re})}catch(F){console.warn(`general \u811A\u672C ${E} \u6C42\u503C\u5931\u8D25: ${F.message}`)}xt.length&&se(e,n,`general scripts: ${xt.map(E=>E.field).join(",")}`)}const S=g.generalAnimations;if(S){for(const[E,k]of Object.entries(S))try{const F=rs.createAnimation(k.animation);F.field=E,F.baseValue=k.value,F.baseNumeric=k.value,F.name&&(un[F.name]=F),jt.push({field:E,ctrl:F,write:re=>I(E,re)})}catch(F){se(e,n,`general animation '${E}' \u5EFA\u63A7\u5236\u5668\u5931\u8D25: ${String(F.message).slice(0,80)}`)}jt.length&&se(e,n,`general animations: ${jt.map(E=>E.field).join(",")}`)}}$t.length&&(se(e,n,`object scripts: ${$t.length}`),window.__objScripts=$t),window.__mediaHooks=Be,window.__sceneLayers=g.layers,window.__compositeStats=()=>L.compositeStats?.()??null,window.__compositeEnable=b=>L.setCompositeEnabled?.(b),window.__scene=g,window.__textures=we;const qn=Array.from(wt.keys());qn.length&&se(e,n,`cursor hooks: ${qn.length} layers`);let fn=null,dt=null,Zn=!1;const Sr=()=>({worldPosition:et.makeCursorEventVec(Ae.state.wx,Ae.state.originY!=null?Ae.state.originY:Ae.state.wy,0)}),zt=(b,T,P)=>{const C=wt.get(b);if(C)for(const I of C)I.callCursor(T,P)},vo=()=>{if(qn.length===0)return;const b=Ae.state;if(!b.has)return;const T=L.getParallaxOffset?L.getParallaxOffset():{x:0,y:0},P=g.general?.orthogonalprojection?.height||t.height,C=Al.hitTestLayers(g.layers,b.wx,b.wy,P,{parOffX:T.x,parOffY:T.y,alignTable:Ne.ALIGN,filter:D=>wt.has(D)}),I=Sr();C!==fn&&(fn&&zt(fn,"cursorLeave",I),fn=C,C&&zt(C,"cursorEnter",I)),C&&zt(C,"cursorMove",I),b.leftDown&&!Zn?(dt=C,C&&zt(C,"cursorDown",I)):!b.leftDown&&Zn&&(dt&&zt(dt,"cursorUp",I),dt&&dt===C&&zt(C,"cursorClick",I),dt=null),Zn=b.leftDown},xo=performance.now();let Er=0,Rt=0;const w=[],U=[];let G=-1/0,W=0;const Y=b=>{if(s||e.paused)return;const P=1e3/(e.cfg.sceneFps||60);if(b-G>=P){G=b,An(e,b),To(e,t,e.cfg);const C=(b-xo-Er)/1e3;if(ot.update(Ae.state),Ke.enabled){if(O?.media)O.media.pump();else{const S=J();typeof S?.update=="function"&&S.update(C)}const B=he(),q=xe.diffMediaEvents(ye,B);if(q.length){for(const{name:S,event:E}of q)for(const k of Be)k.disabled||k.callMedia(S,E);ye=xe.cloneMediaSnapshot(B)}}O?.windowTitle?O.windowTitle.pump():K.update(C);const I=Math.max(0,C-W);W=C;for(const B of Yn){B.ctrl.advance(I);const q=B.field,S=B.slot||q,E=B.ctrl.applyTo(B.ctrl.baseNumeric);if(Array.isArray(E)){const k=B.layer[S];if(Array.isArray(k))for(let F=0;F<E.length&&F<k.length;F++)k[F]=E[F]}else Number.isFinite(E)&&(q==="visible"?B.layer[q]=!!E:B.layer[S]=E)}for(const B of jt){B.ctrl.advance(I);const q=B.ctrl.applyTo(B.ctrl.baseNumeric);typeof q=="number"&&Number.isFinite(q)?B.write(q):Array.isArray(q)&&Number.isFinite(q[0])&&B.write(q[0])}for(const B of ze){if(B.sandbox.disabled)continue;B.sandbox.engine.frametime=I,B.sandbox.engine.runtime=C;const q=B.sandbox.callUpdate(!!B.effect.visible);typeof q=="boolean"&&(B.effect.visible=q)}for(const B of xt){if(B.sandbox.disabled)continue;B.sandbox.engine.frametime=I,B.sandbox.engine.runtime=C;const q=g.general||{},S=q[B.field]&&typeof q[B.field]=="object"&&"value"in q[B.field]?q[B.field].value:q[B.field],E=B.sandbox.callUpdate(S);E!==void 0&&B.write(E)}const D={x:t.clientWidth||window.innerWidth||1,y:t.clientHeight||window.innerHeight||1};for(const B of _)!B||B.disabled||(B.engine.frametime=I,B.engine.runtime=C,B.engine.screenResolution=D);let $=!1;for(const B of $t){if(B.sandbox.disabled)continue;B.sandbox.engine.frametime=I,B.sandbox.engine.runtime=C,B.sandbox.engine.screenResolution=D;const q=B.layer[B.field];if(B.kind==="bool"){const S=B.sandbox.callUpdate(!!q);typeof S=="boolean"&&(B.field==="visible"?B.layer.visibleSelf!==S&&(B.layer.visibleSelf=S,$=!0):B.layer[B.field]=S)}else if(B.kind==="scalar"){const S=B.sandbox.callUpdate(Number(q)||0),E=Number(S);Number.isFinite(E)&&(B.layer[B.field]=E)}else{const S=B.slot||B.field,E=B.layer[S],k=B.field==="angles"?et.radToScriptAngles(E):{x:E[0]||0,y:E[1]||0,z:E[2]||0},F=B.sandbox.callUpdate(k),re=F&&typeof F=="object"&&"x"in F?F:k;B.layer[S]=B.field==="angles"?et.scriptAnglesToRad(re):[re.x||0,re.y||0,re.z||0]}}$&&A(),at.size&&Ye.recomposeWorld(g.layers,at),te.enabled&&(_e.pump(),_e.active||(X.current?X.current.pump():j.update(C)),al(Xe,Ze())),nn.length&&jn.followAttachments(nn,C,Te);const z=e.coverAlign;L.render(g,we,t.width,t.height,C,dn(e.cfg.fit),z.x,z.y).then(()=>{if(e.onFirstFrame){const B=e.onFirstFrame;e.onFirstFrame=void 0;try{B()}catch{}}if(!(s||e.paused)){try{vo()}catch{}Ae.beginFrame();try{e.sceneTextUpdate&&b>=Gn&&(Gn=b+100,e.sceneTextUpdate(C))}catch{}e.raf=requestAnimationFrame(Y)}}).catch(B=>{console.warn("scene render error:",B),se(e,n,`render: ${String(B.message||B).slice(0,200)}`),s=!0})}else e.paused||(e.raf=requestAnimationFrame(Y))},ee=()=>{s||e.paused||e.raf===void 0&&(e.raf=requestAnimationFrame(Y))},oe=b=>{if(s)return;const T=g.properties||{},P=na(T,v,b);if(Object.keys(P).length){for(const C of g.layers){const I=C.srcObject;if(!I)continue;pn(I,T,0);const D=Tt(I.visible);D&&D in P&&(C.visibleSelf=Ye.parseBool(I.visible,!0));const $=Tt(I.color);$&&$ in P&&(C.color=Ye.parseColor(I.color),C.isText&&(C.textColor=C.color));const z=Tt(I.alpha);z&&z in P&&(C.alpha=Ye.parseNum(I.alpha,1));const B=Tt(I.brightness);B&&B in P&&(C.brightness=Ye.parseNum(I.brightness,1));const q=Tt(I.volume);if(q&&q in P){const E=Ye.parseNum(I.volume,1);C.soundprops&&(C.soundprops.volume=E),C.soundCtl?.setVolume?.(E)}for(let E=0;E<(I.animationlayers||[]).length;E++){const k=I.animationlayers[E],F=C.animationLayers?.[E];if(!k||!F)continue;const re=Tt(k.visible);re&&re in P&&(F.visible=Ye.parseBool(k.visible,!0));const Q=Tt(k.rate);Q&&Q in P&&(F.rate=Ye.parseNum(k.rate,1));const ce=Tt(k.blend);ce&&ce in P&&(F.blend=Ye.parseNum(k.blend,1))}for(let E=0;E<(I.effects||[]).length;E++){const k=I.effects[E],F=C.effects?.[E];if(!k||!F)continue;const re=Tt(k.visible);re&&re in P&&!F.visibleScript&&(F.visible=Ye.parseBool(k.visible,!0))}const S=I.instanceoverride;if(S&&typeof S=="object"&&C.particle){let E=!1;for(const k of Object.keys(S)){if(k==="id")continue;const F=Tt(S[k]);if(F&&F in P){E=!0;break}}if(E){const k=en.get(C.id);if(k)for(const F of k)F.reapplyOverride?.()}}}for(const C of _)if(!(!C||C.disabled))try{C.applyUserProperties(P)}catch{}A();for(const C of g.layers){if(!C.particle)continue;const I=en.get(C.id);if(I)for(const D of I)D.setVisible(!!C.visible)}L.applyConstUserProperties?.(P);for(const C of vt)C.lastKey=null;se(e,n,`props hot: ${Object.keys(P).join(",")}`)}};p=()=>{e.raf!==void 0&&(cancelAnimationFrame(e.raf),e.raf=void 0),Rt||(Rt=performance.now()),w.length=0;for(const b of we.values())b?.videoCtl?.isPlaying?.()&&(w.push(b.videoCtl),b.videoCtl.pause());U.length=0;for(const b of tn)!b.paused&&!b.ended&&(U.push(b),b.pause())},d=()=>{Rt&&(Er+=performance.now()-Rt,Rt=0),wn=performance.now();for(const b of w)try{b.play()}catch{}w.length=0;for(const b of U)b.play().catch(()=>{});U.length=0,ee()},f=oe,l&&(oe(l),l=null),ee();{const b=g.general?.orthogonalprojection,T=b?.width||t.width,P=b?.height||t.height,C=dn(e.cfg.fit),I=Ir(C,T,P,t.width,t.height);se(e,n,`fit ${C}: view ${Math.round(I.viewW)}x${Math.round(I.viewH)} scene ${T}x${P} canvas ${t.width}x${t.height}`)}se(e,n,`renderer started: ${g.layers.length} layers`)}catch(y){if(s||y&&y.name==="AbortError")return;console.warn("scene render failed:",y);const x=y instanceof Error?y:new Error(String(y));se(e,n,`failed: ${String(x.message||x).slice(0,200)}`),e.onError?e.onError(x):e.fallbackPage?.()}})()}const ou='data-we-shim="1"',hs="data-we-shim-src";function iu(e){try{const n=new URL(e),t=n.pathname,r=t.lastIndexOf("/");return n.pathname=r<0?"/":t.slice(0,r+1),n.hash="",n.search="",n.href}catch{const n=e.replace(/[#?].*$/,""),t=n.lastIndexOf("/");return t<0?n:n.slice(0,t+1)}}function su(e){const n=/<meta[^>]+http-equiv\s*=\s*["']?Content-Security-Policy["']?[^>]*>/gi;let t;for(;t=n.exec(e);){const r=t[0],o=/content\s*=\s*"([^"]*)"/i.exec(r)?.[1]??/content\s*=\s*'([^']*)'/i.exec(r)?.[1]??"";if(/script-src/i.test(o)&&!/script-src[^;]*'unsafe-inline'/i.test(o)&&!/script-src[^;]*\*/i.test(o))return!0}return!1}function ms(e){return e.replace(/<\/script/gi,"<\\/script")}function au(e,n,t){if(e||(e=""),e.includes(ou)||e.includes(hs))return e;const r=t.baseHref&&!/<base\b/i.test(e)?`<base href="${t.baseHref.replace(/"/g,""")}">`:"",o=`<script ${hs}="1">
|
|
513
|
-
${
|
|
514
|
-
<\/script>`,
|
|
515
|
-
${
|
|
516
|
-
<\/script>`:"",
|
|
646
|
+
`};function r1(t){if(!t||t.length<12)return t;const e=t[0],n=t[1],r=t[2],i=t[3];if(!(e===0&&n===1&&r===0&&i===0)&&!(e===79&&n===84&&r===84&&i===79))return t;const o=Uint8Array.from(t),c=new DataView(o.buffer,o.byteOffset,o.byteLength),u=c.getUint16(4);if(u<=0||12+u*16>o.length)return t;let l=-1,f=0,d=0;for(let w=0;w<u;w++){const y=12+w*16;if(String.fromCharCode(o[y],o[y+1],o[y+2],o[y+3])==="cmap"){l=y,f=c.getUint32(y+8),d=c.getUint32(y+12);break}}if(l<0||f+d>o.length)return t;let h=!1;const p=c.getUint16(f+2);for(let w=0;w<p;w++){const y=f+4+w*8,b=c.getUint32(y+4),v=f+b;if(v+14>o.length||c.getUint16(v)!==4)continue;const k=c.getUint16(v+6),A=k>>>1;if(A<1)continue;const T=2*Math.pow(2,Math.floor(Math.log2(A))),S=Math.floor(Math.log2(A)),P=k-T,M=c.getUint16(v+8),B=c.getUint16(v+10),N=c.getUint16(v+12);M===T&&B===S&&N===P||(c.setUint16(v+8,T),c.setUint16(v+10,S),c.setUint16(v+12,P),h=!0)}if(!h)return t;let m=0;const g=f+d;for(let w=f;w<g;w+=4){const y=o[w]||0,b=w+1<g?o[w+1]:0,v=w+2<g?o[w+2]:0,k=w+3<g?o[w+3]:0;m=m+(y<<24|b<<16|v<<8|k)>>>0}return c.setUint32(l+4,m),o}function i1(t,e,n,r,i){if(e===r&&n===i)return"keep";if(e===i&&n===r&&r>0&&i>0){if(t===6||t===5)return"rot-ccw";if(t===8||t===7)return"rot-cw"}return"keep"}function s1(t){if(t.length<4||t[0]!==255||t[1]!==216)return 1;const e=new DataView(t.buffer,t.byteOffset,t.byteLength);let n=2;for(;n+4<=t.length;){if(t[n]!==255){n++;continue}const r=t[n+1];if(r===216||r===1||r>=208&&r<=215){n+=2;continue}if(r===218)break;const i=e.getUint16(n+2);if(r===225&&n+10<=t.length&&t[n+4]===69&&t[n+5]===120&&t[n+6]===105&&t[n+7]===102&&t[n+8]===0&&t[n+9]===0){const s=n+10,a=t[s]===77&&t[s+1]===77,o=t[s]===73&&t[s+1]===73;if(a||o){const c=f=>e.getUint16(f,o),u=f=>e.getUint32(f,o),l=s+u(s+4);if(l>=0&&l+2<=e.byteLength){const f=c(l);for(let d=0;d<f;d++){const h=l+2+d*12;if(h+12>e.byteLength)break;if(c(h)===274)return c(h+2)===3&&u(h+4)===1?c(h+8):1}}}}n+=2+i}return 1}async function a1(t,e,n,r){let i;try{i=await createImageBitmap(t,{imageOrientation:"none",premultiplyAlpha:"none"})}catch{i=await createImageBitmap(t,{premultiplyAlpha:"none"})}const s=i1(e?s1(e):1,i.width,i.height,n,r);if(s==="keep")return i;const a=document.createElement("canvas");a.width=n,a.height=r;const o=a.getContext("2d");if(!o)return i;s==="rot-cw"?(o.translate(n,0),o.rotate(Math.PI/2)):(o.translate(0,r),o.rotate(-Math.PI/2)),o.drawImage(i,0,0);const c=await createImageBitmap(a);return i.close?.(),c}const o1={systemfont_segoe:"'Segoe UI', 'Helvetica Neue', Arial, sans-serif",systemfont_arial:"Arial, 'Helvetica Neue', sans-serif",systemfont_verdana:"Verdana, Geneva, sans-serif",systemfont_tahoma:"Tahoma, Geneva, sans-serif",systemfont_timesnewroman:"'Times New Roman', Times, serif",systemfont_georgia:"Georgia, 'Times New Roman', serif",systemfont_couriernew:"'Courier New', Courier, monospace",systemfont_trebuchetms:"'Trebuchet MS', 'Helvetica Neue', sans-serif",systemfont_impact:"Impact, 'Arial Black', sans-serif",systemfont_comicsansms:"'Comic Sans MS', 'Comic Sans', cursive",systemfont_sylfaen:"Palatino, 'Times New Roman', serif",systemfont_calibri:"Calibri, Carlito, 'Helvetica Neue', sans-serif",systemfont_cambria:"Cambria, Georgia, serif",systemfont_consolas:"Consolas, 'Courier New', monospace",systemfont_microsoftyahei:"'Microsoft YaHei', 'PingFang SC', 'Hiragino Sans GB', sans-serif",systemfont_simsun:"SimSun, 'Songti SC', serif",systemfont_simhei:"SimHei, 'Heiti SC', sans-serif"},_a=new Map,vi=Ke.foldVisibleReturn;function c1(t){let e=5381;for(let n=0;n<t.length;n++)e=(e<<5)+e+t.charCodeAt(n)|0;return(e>>>0).toString(36)}function l1(t){for(const e of t){const n=_a.get(e);if(n&&(n.refs--,!(n.refs>0))){_a.delete(e);try{const r=[];document.fonts.forEach(i=>{i.family===n.family&&r.push(i)});for(const i of r)document.fonts.delete(i)}catch{}}}}const qn=new Map,u1=512*1024*1024;let Ea=0;function f1(t){for(;qn.size>0&&(qn.size>2||Ea>u1);){let e=null,n=1/0;for(const[i,s]of qn)i!==t&&s.at<n&&(n=s.at,e=i);if(!e)break;const r=qn.get(e);Ea-=r.parsed.fileSize||0,qn.delete(e)}}function d1(t){if(!t)return;const e=qn.get(t);e&&(Ea-=e.parsed.fileSize||0,qn.delete(t))}async function h1(t,e,n,r){const i=n.key;if(i){const c=qn.get(i);if(c)return c.at=Date.now(),ce(t,e,`pkg cache hit: ${c.parsed.fileSize} bytes`),c.parsed}let s;try{s=await n.scenePkg(r)}catch(c){throw r.aborted||c instanceof Error?c:new Error(String(c))}ce(t,e,`pkg body: ${s.byteLength} bytes`);const a=s instanceof Uint8Array?s:new Uint8Array(s),o=Ye.parsePkg(a);return i&&(qn.set(i,{parsed:o,at:Date.now()}),Ea+=o.fileSize||0,f1(i)),o}function m1(t,e){Jn(t);const n=(e.canvas instanceof HTMLCanvasElement?e.canvas:null)??document.createElement("canvas"),r=Es(t,e),i=n.clientWidth||window.innerWidth||1,s=n.clientHeight||window.innerHeight||1;n.width=Math.max(1,Math.round(i*r)),n.height=Math.max(1,Math.round(s*r)),e.canvas instanceof HTMLCanvasElement||(n.style.cssText="position:absolute;inset:0;width:100%;height:100%;",t.wrap?.appendChild(n)),t.canvas=n;let a=!1;const o=console.warn.bind(console);console.warn=(...p)=>{const m=p.map(g=>typeof g=="string"?g:String(g?.message??g)).join(" ");if(m.includes("[we-scene]"))try{ce(t,e,m.slice(0,300))}catch{}o(...p)};const c=new AbortController;let u;t.sceneCleanup=()=>{a=!0,console.warn=o,c.abort(),t.sceneTextUpdate=void 0,u&&(u(),u=void 0),t.renderer&&(t.renderer.dispose?.(),t.renderer=void 0)};let l=null,f,d,h;t.sceneCtl={pause(){d?.()},resume(){h?.()},applyUserProperties(p){f?f(p):l={...l||{},...p}}},(async()=>{try{const p=e.source??Zd(`${e.mediaBase}/${e.src}`);if(!e.source&&(!e.mediaBase||!e.src))throw new Error("\u573A\u666F\u58C1\u7EB8\u7F3A\u5C11 mediaBase/src");ce(t,e,"mountScene start");const m=await h1(t,e,p,c.signal);if(a)return;let g=null;try{g=await p.project?.(c.signal)??null}catch{}if(!n.getContext("webgl2",{premultipliedAlpha:!1,antialias:!1,alpha:!1,preserveDrawingBuffer:!0}))throw new Error("WEBGL2_UNAVAILABLE");n.setAttribute("data-webwallgl-gl","1");const y=Ye.getEntry(m,"scene.json");if(!y)throw new Error("pkg \u4E2D\u6CA1\u6709 scene.json\uFF08\u4E0D\u662F\u573A\u666F\u58C1\u7EB8\uFF1F\uFF09");const b=vt.parseScene(JSON.parse(Ot(y)),g);if(e.clearColor){const C=b.general??={};C.clearcolor=e.clearColor,C.clearenabled=!0}{const C=b.general?.zoom,W=Number(C&&typeof C=="object"?C.value:C);b.cameraTransforms={zoom:Number.isFinite(W)&&W>0?W:1}}const v=T0(b.properties||{});t.liveUserProps=v;const k=()=>vt.recomputeLayerVisibility(b.layers);if(t.onSceneInfo){const C=b.general?.orthogonalprojection||{},W=Number(C.width)>0?Number(C.width):n.width,x=Number(C.height)>0?Number(C.height):n.height,_=b.layers||[],V={width:W,height:x,layerCount:_.length,hasModels:_.some(j=>!!j.model),hasParticles:_.some(j=>!!j.particle),hasText:_.some(j=>!!j.text)},F=t.onSceneInfo;t.onSceneInfo=void 0,F(V)}const A=[];eh&&(b.layers=b.layers.filter(C=>!(eh&&C.isComponent)));const T=C=>{const W=C.startsWith("shaders/")?C:"shaders/"+C,x=C.startsWith("shaders/")?C.slice(8):C,_=Ye.getEntry(m,W);let V=_?Ot(_):n1[x]??null;const F=window.__shaderPatch;if(V&&F){const j=x.replace(/\.(frag|vert|h)$/,""),X=F[j]||F[x];if(typeof X=="function")try{const K=X(V,x);typeof K=="string"&&(V=K)}catch{}}return Promise.resolve(V)},S=ft.createRenderer(n,{shaderResolver:T,diag:C=>ce(t,e,`renderer: ${C}`),fboCapFactor:0});if(t.renderer=S,a)return;const P=g?.general?.supportsaudioprocessing!==!1,M=Wd(),B=Se.createSimulatedMedia(),N=Yd.createSimulatedWindowTitle();let U=null;const q={mediaDriver:null,lastSnap:{get:()=>null,setHasThumbnail:()=>{}}},H={current:null};let G=null;const Y=()=>G??t.mediaSource??B;let J=N;const ne={enabled:P&&!t.audioDisabled},fe=C=>new Float32Array(C),Ne={left16:fe(16),right16:fe(16),left32:fe(32),right32:fe(32),left64:fe(64),right64:fe(64),level:0,silent:!0},Ze=(()=>{const C={left64:fe(64),right64:fe(64),left32:fe(32),right32:fe(32),left16:fe(16),right16:fe(16),preL64:fe(64),preR64:fe(64),level:0,silent:!0},W=(x,_)=>{const V=_.length/x.length;for(let F=0;F<x.length;F++){let j=0;const X=Math.floor(F*V),K=Math.max(X+1,Math.floor((F+1)*V));for(let D=X;D<K;D++)j+=_[D];x[F]=j/(K-X)}};return{active:!1,snapshot:C,pump(){const x=t.audioBridge?.();if(!x||!x.left||!x.right){this.active=!1;return}const _=Math.min(64,x.left.length,x.right.length);let V=0;for(let F=0;F<_;F++){const j=x.left[F]||0,X=x.right[F]||0;C.left64[F]=j,C.right64[F]=X,C.preL64[F]=j,C.preR64[F]=X,F<48&&(V+=j)}for(let F=_;F<64;F++)C.left64[F]=0,C.right64[F]=0,C.preL64[F]=0,C.preR64[F]=0;W(C.left32,C.left64),W(C.right32,C.right64),W(C.left16,C.left64),W(C.right16,C.right64),C.level=Math.min(1,V/48),C.silent=C.level<.02,this.active=!0}}})(),je=()=>Ze.active?Ze.snapshot:H.current?H.current.snapshot:M.snapshot;S.setAudioProvider(()=>ne.enabled?je():Ne);const Fe=new Map,Le=new Map,Pt=[],Xe=(C,W)=>{if(!C||!W||!W.sandbox)return;let x=Le.get(C);x||(x=[],Le.set(C,x)),x.push(W)};window.__audioStats=()=>({enabled:ne.enabled,live:!!H.current,level:ne.enabled?Math.round((H.current?H.current.snapshot:M.snapshot).level*1e3)/1e3:0,silent:ne.enabled?(H.current?H.current.snapshot:M.snapshot).silent:!0,bass:ne.enabled?Math.round((H.current?H.current.snapshot:M.snapshot).left64[2]*1e3)/1e3:0}),window.__audioMute=C=>(ne.enabled=!C,ne.enabled),ce(t,e,`audio: ${H.current?"live mic":"simulated"} stream, supportsaudioprocessing=${P}`);const Dt=Yd.createShortcutHandler(C=>{ce(t,e,`openUserShortcut: ${C}`)}),Oe={enabled:!t.mediaDisabled,override:null},qe=[];let ze=null,st;q.lastSnap={get:()=>ze,setHasThumbnail:C=>{ze&&(ze.hasThumbnail=C)}};const ve=()=>Y().snapshot,vn=C=>{if(!(!C||!C.hasMediaHook||qe.includes(C))&&(qe.push(C),!!ve().hasMedia))for(const{name:W,event:x}of Se.diffMediaEvents(null,ve()))try{C.callMedia(W,x)}catch{}};window.__mediaStats=()=>({enabled:Oe.enabled,live:!!U,hooks:qe.length,title:ve().title,artist:ve().artist,album:ve().album,state:ve().state,position:Math.round(ve().position),duration:ve().duration,hasThumbnail:ve().hasThumbnail,lyric:ve().lyricLine,primaryColor:ve().primaryColor?[ve().primaryColor.x,ve().primaryColor.y,ve().primaryColor.z]:null}),window.__mediaSet=C=>{Object.assign(ve(),C||{});const W=Se.diffMediaEvents(ze,ve());for(const{name:x,event:_}of W)for(const V of qe)V.callMedia(x,_);return ze=Se.cloneMediaSnapshot(ve()),window.__mediaStats()};const ki=()=>{const C=Se.diffMediaEvents(ze,ve());for(const{name:W,event:x}of C)for(const _ of qe)try{_.callMedia(W,x)}catch{}ze=Se.cloneMediaSnapshot(ve())},an=C=>{const W=Y(),x=W?.[C];if(typeof x=="function")try{x.call(W)}catch(_){ce(t,e,`media ${C} \u5931\u8D25: ${_?.message}`)}return ki(),ve()},_t={get snapshot(){return ve()},skipNext:()=>an("skipNext"),skipPrevious:()=>an("skipPrevious"),play:()=>an("play"),pause:()=>an("pause"),playPause:()=>an("playPause")};t.mediaCtl=_t,window.__mediaControl=_t,window.__system={media:_t,windowTitle:J.snapshot,shortcuts:Dt.last,live:null},window.__liveSystem=()=>({audio:"off",media:"offline",window:"offline"});const dt=Cb.createPointerSource(e.canvas?{target:e.canvas,viewport:()=>({w:e.canvas.clientWidth||window.innerWidth||1,h:e.canvas.clientHeight||window.innerHeight||1})}:{});S.setPointerProvider(()=>dt),t.pointerCtl={push:C=>dt.pushExternal(C),leave:()=>dt.pushExternalLeave()};{const C=u;u=()=>{C?.(),dt.dispose()}}const At=Ke.createInputView(),yr=Eb.createEngineTimers({setTimeout:(C,W)=>window.setTimeout(C,W),clearTimeout:C=>window.clearTimeout(C),setInterval:(C,W)=>window.setInterval(C,W),clearInterval:C=>window.clearInterval(C)},{onError:(()=>{let C=!1;return W=>{C||(C=!0,ce(t,e,`engine \u5B9A\u65F6\u5668\u56DE\u8C03\u629B\u9519\uFF08\u6B64\u540E\u540C\u7C7B\u9759\u9ED8\uFF09: ${String(W?.message||W).slice(0,90)}`))}})()}),Gn={setTimeout:yr.setTimeout,clearTimeout:yr.clearTimeout,setInterval:yr.setInterval,clearInterval:yr.clearInterval};{const C=u;u=()=>{C?.(),yr.dispose()}}window.__pointerStats=()=>{const C=dt.state,W=x=>Math.round(x*1e3)/1e3;return{normalized:{u:W(C.u),v:W(C.v)},last:{u:W(C.lastU),v:W(C.lastV)},world:{x:Math.round(C.wx),y:Math.round(C.wy)},originY:C.originY!=null?Math.round(C.originY):null,screen:{x:C.screenX,y:C.screenY,w:C.screenW,h:C.screenH},leftDown:C.leftDown,has:C.has,delta:W(dt.normalizedDelta()),counts:{move:C.moveCount,down:C.downCount,up:C.upCount}}};const Te=new Map;Te.set("util/white",{glTex:ft.makeTexture(S.gl,new Uint8Array([255,255,255,255]),1,1),width:1,height:1,rg88:!1}),Te.set("util/noflow",{glTex:ft.makeTexture(S.gl,new Uint8Array([127,127,127,255]),1,1),width:1,height:1,rg88:!1}),Te.set("util/noise",{glTex:ft.makeTexture(S.gl,Pb.generateNoiseTexture(),256,256),width:256,height:256,rg88:!1,mips:null});{const C=x=>{const _=Se.renderThumbnail(x,512);return{glTex:ft.makeTextureMip(S.gl,[_],!1),width:_.width,height:_.height,rg88:!1,mips:[_],generated:!0}},W=B.tracks||[];W.length&&(Te.set("$mediaThumbnail",C(W[0])),Te.set("$mediaPreviousThumbnail",C(W[W.length-1])))}const ys=(C,W,x)=>{const _=Jb(C,W,x,512),V=Zb(C,W,x),F=S.gl,j=Te.get("$mediaThumbnail"),X=!!j?.generated;j&&!X&&Te.set("$mediaPreviousThumbnail",j);const K=Te.get("$mediaThumbnail");if(K?.glTex?(F.bindTexture(F.TEXTURE_2D,K.glTex),F.texImage2D(F.TEXTURE_2D,0,F.RGBA,_.width,_.height,0,F.RGBA,F.UNSIGNED_BYTE,_.rgba),K.width=_.width,K.height=_.height,K.mips=[_],K.generated=!1):Te.set("$mediaThumbnail",{glTex:ft.makeTextureMip(F,[_],!1),width:_.width,height:_.height,rg88:!1,mips:[_],generated:!1}),X){const D=Te.get("$mediaPreviousThumbnail");D?.glTex&&(F.bindTexture(F.TEXTURE_2D,D.glTex),F.texImage2D(F.TEXTURE_2D,0,F.RGBA,_.width,_.height,0,F.RGBA,F.UNSIGNED_BYTE,_.rgba),D.width=_.width,D.height=_.height,D.mips=[_],D.generated=!1)}return V};if(e.liveSystem){const C={handle:null,dead:!1};(t.wallpaperDisposers??=[]).push(()=>{C.dead=!0;try{C.handle?.dispose()}catch{}C.handle=null});try{const W=async x=>{try{const _=await fetch(x.url,{cache:"no-store"});if(!_.ok)return;const V=await _.blob(),F=await createImageBitmap(V,{premultiplyAlpha:"none"}),j=ys(F,F.width,F.height);F.close?.();const X=Y().snapshot;j&&(X.primaryColor=Se.mediaVec3(...j.primary),X.secondaryColor=Se.mediaVec3(...j.secondary),X.tertiaryColor=Se.mediaVec3(...j.tertiary),X.textColor=Se.mediaVec3(.98,.98,1),X.highContrastColor=Se.mediaVec3(1,1,1)),X.hasThumbnail=!0,q.lastSnap.setHasThumbnail(!1),ce(t,e,`liveSystem: artwork ${x.title||x.trackKey}`)}catch(_){ce(t,e,`liveSystem: artwork \u5931\u8D25 (${_ instanceof Error?_.message:_})`)}};if(U=await ih({origin:location.origin,onArtwork:x=>{W(x)}}),C.dead){try{U.dispose()}catch{}U=null}else{if(C.handle=U,G=U.media,J=U.windowTitle,q.mediaDriver=U.media,U.status().audio==="mic"&&(H.current=U.audio),Y().snapshot.hasMedia){for(const{name:_,event:V}of Se.diffMediaEvents(null,Y().snapshot))for(const F of qe)try{F.callMedia(_,V)}catch{}ze=Se.cloneMediaSnapshot(Y().snapshot)}const x=U.status();ce(t,e,`liveSystem: audio=${x.audio} media=${x.media} window=${x.window}`+(x.title?` title="${x.title}"`:"")+(x.hasArtwork?" artwork=1":"")),ce(t,e,`audio: ${H.current?"live mic":"simulated"} stream, supportsaudioprocessing=${P}`),window.__system={media:_t,windowTitle:J.snapshot,shortcuts:Dt.last,live:()=>U.status()},window.__liveSystem=()=>U.status()}}catch(W){ce(t,e,`liveSystem: \u542F\u52A8\u5931\u8D25\uFF0C\u56DE\u9000\u6A21\u62DF\u6E90 (${W instanceof Error?W.message:W})`),U=null}}{const C=u;u=()=>{C?.(),U?.dispose(),U=null}}const on=new Map,br=async C=>{if(Te.has(C))return Te.get(C);const W=Ye.getEntry(m,`materials/${C}.tex`);if(!W){if(Fr.isBuiltinParticleTextureName(C)){const j=Fr.buildBuiltinParticleTexture(C);if(j){const X={glTex:ft.makeTextureMip(S.gl,[j],!1),width:j.width,height:j.height,rg88:!1,mips:[j],generated:!0};return Te.set(C,X),X}}return null}const x=Sa.parseTex(W),_=Sa.decodeMip0(x),V=x.format===8;let F=null;if(_.video!==void 0){const j=URL.createObjectURL(new Blob([_.video],{type:"video/mp4"})),X=rl(j,{muted:!0,renderDpr:Es(t,e),maxW:n.clientWidth||window.innerWidth||1,maxH:n.clientHeight||window.innerHeight||1});for(const I of[X.active,X.standby])I.style.cssText="position:fixed;left:-9999px;top:-9999px;width:2px;height:2px;opacity:0;pointer-events:none",document.body.appendChild(I),(t.videoTextures??=[]).push(I);(t.objectUrls??=[]).push(j),(t.videoPairs??=[]).push(X),X.active.addEventListener("loadedmetadata",()=>{ce(t,e,`video tex '${C}': ${X.active.videoWidth}x${X.active.videoHeight}`)}),X.active.addEventListener("error",()=>{ce(t,e,`video tex '${C}' ERROR: ${X.active.error?.code}`)});const K=[],D=I=>{for(const O of K)I.addEventListener("ended",O)},z={play:()=>{a||X.resume()},pause:()=>X.pause(),stop:()=>{X.pause();try{X.active.currentTime=0}catch{}},isPlaying:()=>!X.active.paused&&!X.active.ended,duration:()=>Number.isFinite(X.active.duration)?X.active.duration:0,getCurrentTime:()=>X.active.currentTime||0,setCurrentTime:I=>{try{X.active.currentTime=I}catch{}},getRate:()=>X.active.playbackRate||1,setRate:I=>{X.active.playbackRate=I,X.standby.playbackRate=I},getLoop:()=>X.active.loop,setLoop:I=>{X.active.loop=I,X.standby.loop=I},addEndedCallback:I=>{K.push(I),X.active.addEventListener("ended",I)}},L={get video(){return X.active},glTex:ft.makeTexture(S.gl,new Uint8Array([0,0,0,0]),1,1),width:_.width,height:_.height,rg88:!1,lastUploaded:-1,videoCtl:z};let E=0;return X.onSwap=I=>{L.lastUploaded=-1,D(I),E++,(E===1||E===10||E===100)&&ce(t,e,`video tex '${C}' loop swap ok x${E}`)},X.onFallback=()=>{ce(t,e,`video tex '${C}' loop fallback (native loop used)`)},Te.set(C,L),L}else if(_.png!==void 0||_.image!==void 0&&_.fif===Sa.FIF.JPEG){const j=new Blob([_.png||_.image],{type:_.png?"image/png":"image/jpeg"}),X=await a1(j,_.png?null:_.image,_.width,_.height);F={glTex:ft.makeTexture(S.gl,null,0,0,X),width:X.width,height:X.height,rg88:V}}else{if(_.image!==void 0)return null;{const j=Sa.decodeMip0(x);F={glTex:ft.makeTextureMip(S.gl,[j],V),width:j.width,height:j.height,rg88:V,mips:[j]}}}if(!F)return null;if(x.frames?.list?.length){const j=x.frames.list;j.atlasWidth=F.width,j.atlasHeight=F.height,F.frames=j}return Te.set(C,F),F},cn=C=>{if(Te.has(C))return Promise.resolve(Te.get(C));const W=on.get(C);if(W)return W;const x=br(C);return on.set(C,x),x.finally(()=>{on.get(C)===x&&on.delete(C)}),x},Ai=/uniform\s+sampler2D\s+g_Texture\d+\s*;\s*\/\/[^\n]*"default"\s*:\s*"([^"]+)"/g,Ia=async C=>{for(const W of C.materialPasses||[])if(W.shader)for(const x of["frag","vert"]){const _=Ye.getEntry(m,`shaders/${W.shader}.${x}`);if(!_)continue;const V=Ot(_);Ai.lastIndex=0;let F;for(;(F=Ai.exec(V))!==null;){const j=F[1];!j||j.startsWith("util/")||j.startsWith("_rt_")||Te.has(j)||await cn(j)}}};let Ma=0;const $n=[];for(let C=0;C<b.layers.length;C++){const W=b.layers[C];if(W.image)try{let x;if(wn.BUILTIN_MODELS[W.image])x=wn.BUILTIN_MODELS[W.image];else{const L=Ye.getEntry(m,W.image);if(!L)continue;x=JSON.parse(Ot(L))}vt.applySolidFromModel(W,x);const _=W.srcObject?.instance?.usertextures,V=_?.[0]&&typeof _[0].name=="string"&&_[0].name.startsWith("$")?_[0].name:null,F=V&&Te.has(V)?V:null;if(F&&(W.textureName=F,W.solid=!1),x&&typeof x=="object"&&"width"in x&&"height"in x){const L=x;(W.size?.[0]||0)===0&&(W.size?.[1]||0)===0&&L.width>0&&L.height>0&&(W.size=[L.width,L.height])}const j=vt.resolveMaterial(x);if(!j)continue;let X;if(wn.BUILTIN_MATERIALS[j.materialPath])X=wn.BUILTIN_MATERIALS[j.materialPath];else{const L=Ye.getEntry(m,j.materialPath);if(L)X=JSON.parse(Ot(L));else if(W.solid&&wn.BUILTIN_MATERIALS["materials/util/solidlayer.json"])X=wn.BUILTIN_MATERIALS["materials/util/solidlayer.json"];else continue}const K=X.passes?.[0],D=K?.textures||[],z=D[0];if(W.materialBlending=typeof K?.blending=="string"?K.blending:null,K?.combos){for(const L of Object.keys(K.combos))if(L.toLowerCase()==="spritesheet"&&Number(K.combos[L])===1){W.spriteSheet=!0;break}}for(let L=0;L<D.length;L++){const E=D[L];typeof E!="string"||!E||E.startsWith("util/")||E.startsWith("_rt_")||$n.push(cn(E).then(I=>{I&&L===0&&!F&&(W.textureName=E,Ma++,I.videoCtl&&(W.videoCtl=I.videoCtl))}))}K?.shader&&Ye.getEntry(m,`shaders/${K.shader}.frag`)&&wn.attachLayerMaterialEffect(W,K);for(const L of W.effects||[])wn.resolveEffectChain(m,L,Ot);for(const L of W.effects||[]){for(const E of L.passes||[])for(const I of E.textures||[])typeof I=="string"&&I!==""&&!I.startsWith("util/")&&!I.startsWith("_rt_")&&$n.push(cn(I));$n.push(Ia(L))}}catch(x){console.warn(`\u56FE\u5C42 ${W.name||C} \u52A0\u8F7D\u5931\u8D25: ${x.message}`)}}if(!th){for(const C of b.layers)if(!(!C.isText||!(C.effects||[]).length))try{for(const W of C.effects||[])wn.resolveEffectChain(m,W,Ot);for(const W of C.effects||[])for(const x of W.passes||[])for(const _ of x.textures||[])typeof _=="string"&&_!==""&&!_.startsWith("util/")&&!_.startsWith("_rt_")&&$n.push(cn(_))}catch(W){console.warn(`\u6587\u5B57\u5C42\u6548\u679C ${C.name} \u89E3\u6790\u5931\u8D25: ${W.message}`)}}await Promise.all($n);for(const[C,W]of Te){if(!W?.videoCtl)continue;b.layers.some(_=>_.textureName===C&&_.visible&&!_.destroyed)&&!t.paused&&W.videoCtl.play()}const Et=[],bs=[],kn=new Map;let Be=0;const xi=async C=>{const W=await cn(C);if(W)return W;const x=Fr.buildBuiltinParticleTexture(C);if(!x)return null;const _={glTex:ft.makeTextureMip(S.gl,[x],!1),width:x.width,height:x.height,rg88:!1,mips:[x],generated:!0,frames:Fr.builtinParticleFrames(C)??void 0};return Te.set(C,_),Be++,_},Ba=C=>{if(!C)return null;const W=C.mips&&C.mips[0];if(W?.rgba&&typeof Fr.prepareParticleNormalTexture=="function"){const x=Fr.prepareParticleNormalTexture(W);if(x&&x!==W)return{glTex:ft.makeTextureMip(S.gl,[x],!1),width:x.width,height:x.height,rg88:!1,mips:[x],generated:!0}}return C},ws=async(C,W,x,_)=>{if(_>3)return null;const V=Ye.getEntry(m,C);if(!V)return ce(t,e,`particle '${C}' \u4E0D\u5728 pkg\uFF0C\u8DF3\u8FC7`),null;const F=JSON.parse(Ot(V)),j=new _b.ParticleSystem(S.gl,F,x,W);let X=null,K=null;if(F.material){const E=Ye.getEntry(m,F.material);if(E){const I=JSON.parse(Ot(E));j.setMaterial(I);const O=I?.passes?.[0]?.textures||[];X=O[0]||null,K=O[1]||null}}const D=await xi(X||"particle/halo");if(!D)return ce(t,e,`particle '${C}' \u65E0\u8D34\u56FE\u53EF\u7528\uFF0C\u8DF3\u8FC7`),null;j.setTexture({glTex:D.glTex,width:D.width,height:D.height,frames:D.frames});const z=K||(j.refract?Fr.particleNormalNameForAlbedo(X||"particle/halo"):null);if(z){const E=Ba(await xi(z));E&&j.setNormalTexture({glTex:E.glTex,width:E.width,height:E.height})}j.setVisible(!!W.visible),Et.push(j);const L=W.id;if(L!==void 0){let E=kn.get(L);E||(E=[],kn.set(L,E)),E.push(j)}for(const E of F.children||[]){if(!E||typeof E.name!="string")continue;const I=String(E.origin??"0 0 0").trim().split(/\s+/).map(Number),O=String(E.scale??"1 1 1").trim().split(/\s+/).map(Number),Q=String(E.angles??"0 0 0").trim().split(/\s+/).map(Number),$=E.type==="eventfollow"?"particle":!E.type||E.type==="static"?"origin":null,Z=j.localToWorld(I[0]||0,I[1]||0),se={...W,origin:[Z[0],Z[1],(W.origin?.[2]||0)+(I[2]||0)],scale:[(W.scale?.[0]??1)*(O[0]||1),(W.scale?.[1]??1)*(O[1]||1),(W.scale?.[2]??1)*(O[2]||1)],angles:[(W.angles?.[0]||0)+(Q[0]||0),(W.angles?.[1]||0)+(Q[1]||0),(W.angles?.[2]||0)+(Q[2]||0)]},te=await ws(E.name,se,E.instanceoverride||x,_+1);te&&$&&te.attachFollow(j,$,[I[0]||0,I[1]||0,I[2]||0])}return j};if(!Xb){for(const C of b.layers)if(C.particle)try{await ws(C.particle,C,C.instanceoverride,0)}catch(W){console.warn(`\u7C92\u5B50\u56FE\u5C42 ${C.name} \u52A0\u8F7D\u5931\u8D25: ${W.message}`),ce(t,e,`particle '${C.name}' FAIL: ${W.message.slice(0,80)}`)}}if(Et.length>0){const C=u;u=()=>{C?.();for(const W of Et)W.dispose()}}const Ti=[];for(const C of b.layers)if(!(!C.sound||!C.sound.length))try{for(const W of C.sound){const x=Ye.getEntry(m,W);if(!x)continue;const _=(W.split(".").pop()||"").toLowerCase(),V=_==="mp3"?"audio/mpeg":_==="ogg"?"audio/ogg":_==="flac"?"audio/flac":"audio/wav",F=new Blob([x],{type:V}),j=URL.createObjectURL(F);(t.objectUrls??=[]).push(j);const X=document.createElement("audio");X.src=j,X.loop=C.soundprops?.playbackmode==="loop",X.volume=Math.max(0,Math.min(1,C.soundprops?.volume??1)),X.muted=e.muted!==!1,C.soundCtl={play(){if(X.ended)try{X.currentTime=0}catch{}X.play().catch(()=>{})},pause(){X.pause()},stop(){X.pause();try{X.currentTime=0}catch{}},isPlaying:()=>!X.paused&&!X.ended,getVolume:()=>X.volume,setVolume:K=>{X.volume=Math.max(0,Math.min(1,K))}},!C.soundprops?.startsilent&&!t.paused&&X.play().catch(()=>{}),Ti.push(X);break}}catch(W){console.warn(`\u58F0\u97F3\u56FE\u5C42 ${C.name} \u52A0\u8F7D\u5931\u8D25: ${W.message}`)}const qc=C=>{for(const W of Ti)W.volume=Math.max(0,Math.min(1,C)),W.muted=C<=0};if(t.sceneAudio={setVolume:qc,audios:Ti},a)return;const Si={dt:1/60,t:0};let Nr=0;S.setParticleRenderer(()=>{const C=Math.min(.05,Math.max(0,Si.dt));if(dt.state.has){const{wx:W,wy:x,originY:_}=dt.state,V=_??x;for(const F of Et)F.setPointer(W,V)}if(bs.length)for(const W of bs)W.syncLayerTransform();for(const W of Et)W.layer&&W.layer.runtimeCreated&&W.syncLayerTransform();for(const W of Et)W.advance(C,ne.enabled?je():null);if(Nr<2&&(Nr++,Nr===2)){const W=Et.reduce((x,_)=>x+_.liveCount(),0);ce(t,e,`particles live: ${W} across ${Et.length} systems`)}},(C,W,x,_,V)=>{if(C===void 0)return;const F=kn.get(C);if(F)for(const j of F)j.render(x,_,V,W.projW,W.projH)}),ce(t,e,`particles: ${Et.length} systems, ${Be} builtin tex generated`),window.__particleStats=()=>({t:Si.t,systems:Et.map(C=>{let W=0,x=1/0,_=-1/0,V=1/0,F=-1/0,j=1/0,X=-1/0;for(const K of C.pool){if(!K.alive)continue;W++;const D=C.originX+K.x*C.scaleX,z=C.originY+K.y*C.scaleY;D<x&&(x=D),D>_&&(_=D),z<V&&(V=z),z>F&&(F=z);const L=Math.abs(K.size)*C.sysScale;L<j&&(j=L),L>X&&(X=L)}return{layer:C.layer&&C.layer.name,opacityMul:Math.round(C.opacityMul*1e4)/1e4,live:W,max:C.maxCount,blend:C.blend,renderer:C.renderers.map(K=>K.kind).join("+"),origin:[Math.round(C.originX),Math.round(C.originY)],bbox:W?[Math.round(x),Math.round(V),Math.round(_),Math.round(F)]:null,size:W?[Math.round(j),Math.round(X)]:null}})}),window.__particleToggle=(C,W)=>{for(let x=0;x<Et.length;x++)Et[x].setVisible(W===void 0?C:x===W);return Et.length};const An=[],Ra=new Map,vs=new Map,Lr=C=>{if(!C||!C.puppet)return null;let W=vs.get(C);return W||(W=new Map,vs.set(C,W)),W};for(const C of b.layers)if(C.image)try{if(wn.BUILTIN_MODELS[C.image])continue;const W=Ye.getEntry(m,C.image);if(!W)continue;const x=JSON.parse(Ot(W));if(!x.puppet)continue;const _=Ye.getEntry(m,x.puppet);if(!_)continue;const V=ms.parseMDL(new Uint8Array(_)),F=C.textureName?Te.get(C.textureName):null;if(!F){ce(t,e,`puppet '${C.name}' \u65E0\u8D34\u56FE\uFF0C\u8DF3\u8FC7`);continue}C.puppet=V,An.push({mdl:V,tex:F,layer:C});const j=V.animations[0];ce(t,e,`puppet '${C.name}' v=${V.vertexCount} bones=${V.bones.length}`+(j?` anim='${j.name}' ${j.fps}fps\xD7${j.frameCount}`:" \u65E0\u52A8\u753B"))}catch(W){console.warn(`puppet \u56FE\u5C42 ${C.name} \u52A0\u8F7D\u5931\u8D25: ${W.message}`),ce(t,e,`puppet '${C.name}' \u5931\u8D25: ${W.message}`)}for(const C of b.layers)if(C.model&&!C.puppet)try{const W=Ye.getEntry(m,C.model);if(!W)continue;const x=ms.parseMDL(new Uint8Array(W));let _=null;if(x.materialPath){const F=Ye.getEntry(m,x.materialPath);if(F){const X=JSON.parse(Ot(F))?.passes?.[0]?.textures?.[0];typeof X=="string"&&X&&(_=X)}}_&&(await cn(_),C.textureName=_);const V=_?Te.get(_):null;if(!V){ce(t,e,`model '${C.name}' \u65E0\u8D34\u56FE\uFF0C\u8DF3\u8FC7`);continue}C.puppet=x,An.push({mdl:x,tex:V,layer:C}),ce(t,e,`model '${C.name}' v=${x.vertexCount} static ${x.materialPath||""}`)}catch(W){console.warn(`model \u56FE\u5C42 ${C.name} \u52A0\u8F7D\u5931\u8D25: ${W.message}`),ce(t,e,`model '${C.name}' \u5931\u8D25: ${W.message}`)}let Or=null;if(An.length>0)try{Or=ms.createMDLRenderer(S.gl);for(const W of An)Or.upload(W.mdl);const C=new Map;for(const W of An)C.set(W.layer,W);S.setPuppetRenderer((W,x,_)=>{const V=C.get(W);V&&Or.draw(x,V.mdl,{time:_.time,animLayers:W.animationLayers,boneOverrides:vs.get(W),overrideTex:_.overrideTex||null,color:[W.color[0]*W.brightness,W.color[1]*W.brightness,W.color[2]*W.brightness,W.alpha]},V.tex)})}catch(C){console.warn(`puppet \u6E32\u67D3\u5668\u521D\u59CB\u5316\u5931\u8D25: ${C.message}`),ce(t,e,`puppet renderer \u5931\u8D25: ${C.message}`),Or=null;for(const W of An)W.layer.puppet=null}if(a)return;ce(t,e,`puppet: ${An.length} meshes`);const wr=ms.applyAttachmentBindOrigins(b.layers);wr.length&&ce(t,e,`attachments: ${wr.length} hanging layers`);const Qn=vt.collectTransformDirty(b.layers,wr.map(C=>C.layer));if(Qn.size){ce(t,e,`transform graph: ${Qn.size} live layers`);for(const[C,W]of kn)if(Qn.has(C))for(const x of W)bs.push(x)}const Ct=[],Qt=[],De=new Map,Yt={};let ln=null,xn=null,Tn=0;if(!th&&b.layers.some(C=>C.isText)){const C=b.general?.orthogonalprojection,W=C?.width||n.width,x=C?.height||n.height,_=Ua(xr(t.cfg.fit),W,x,n.width,n.height),V=Math.min(3,Math.max(.5,n.width/Math.max(1,_.viewW))),F=new Map,j=[],X=new Set;for(const z of b.layers)z.isText&&z.textFont&&X.add(z.textFont);for(const z of m.entries||[])typeof z.name=="string"&&/^fonts\/.+\.(ttf|otf|woff2?)$/i.test(z.name)&&X.add(z.name);for(const z of X){const L=`${e.src}|${z}`,E=_a.get(L);if(E){E.refs++,j.push(L),F.set(z,E.family);continue}const I=o1[z.toLowerCase()];if(I){F.set(z,I);continue}try{const O=Ye.getEntry(m,z);if(!O)continue;const Q=r1(O instanceof Uint8Array?O:new Uint8Array(O)),$="wefont_"+c1(L)+"_"+z.split("/").pop().replace(/[^a-zA-Z0-9]/g,"_"),Z=URL.createObjectURL(new Blob([Q])),se=new FontFace($,`url(${Z})`);if(await se.load(),a){URL.revokeObjectURL(Z);break}document.fonts.add(se),(t.objectUrls??=[]).push(Z),F.set(z,$),_a.set(L,{family:$,refs:1}),j.push(L)}catch(O){console.warn(`\u5B57\u4F53\u52A0\u8F7D\u5931\u8D25 ${z}: ${O.message}`)}}if(j.length){const z=t.sceneCleanup;t.sceneCleanup=()=>{l1(j),z?.()}}ln=document.createElement("canvas"),xn=ln.getContext("2d");const K=2048;for(const z of b.layers)if(z.isText)try{const L={layer:z,sandbox:null,texName:"__wstext_"+z.id,entry:null,lastKey:null,quality:V};if(z.textScript&&(L.sandbox=Ke.evalTextScript(z.textScript,z.textScriptProps,{text:z.text??"",font:z.textFont||"",pointsize:z.textPointsize,color:z.textColor,angles:z.angles,origin:z.origin,scale:z.scale,visible:z.visible,canvasSize:{width:W,height:x},userProperties:v,shared:Yt,audioViews:Fe,inputView:At,...Gn,mediaControl:_t,windowTitle:J.snapshot,openUserShortcut:Dt.openUserShortcut,getLayerText:Q=>De.get(Q),onError:Q=>{ce(t,e,`text script '${z.name}' \u5931\u8D25: ${String(Q.message||Q).slice(0,120)}`)}}),L.sandbox&&(A.push(L.sandbox),Qt.push({sandbox:L.sandbox,layer:z}),L.sandbox.hasMediaHook&&vn(L.sandbox),L.sandbox.hasAnimEventHook&&Xe(z,{sandbox:L.sandbox,kind:"text"}))),De.set(z.name||"",String(z.text??"")),z.textAnchor!=="center"&&z.size[0]>0&&z.size[1]>0){const Q=z.size[0]*(z.scale[0]||1)/2,$=z.size[1]*(z.scale[1]||1)/2,Z=z.textAnchor;let se=0,te=0;Z.includes("left")&&(se+=Q),Z.includes("right")&&(se-=Q),Z.includes("top")&&(te-=$),Z.includes("bottom")&&(te+=$),z.origin[0]+=se,z.origin[1]+=te,z.localOrigin&&(z.localOrigin[0]+=se,z.localOrigin[1]+=te)}const E=nh*Math.max(1,z.textPointsize),I=Ke.textLayerHasTintMask(z)?8:256,O=Math.min(I,Ke.textCanvasMargin(E,0));L.boxW=z.size[0]>0?z.size[0]:E*4,L.boxH=z.size[1]>0?z.size[1]:E*1.6,L.margin=O,z.size=[L.boxW+O*2,L.boxH+O*2],L.entry={glTex:ft.makeTexture(S.gl,new Uint8Array([0,0,0,0]),1,1),width:1,height:1,rg88:!1},Te.set(L.texName,L.entry),z.textureName=L.texName,z.solid=!1,Ct.push(L)}catch(L){console.warn(`\u6587\u5B57\u5BF9\u8C61 ${z.name} \u521D\u59CB\u5316\u5931\u8D25: ${L.message}`)}if(Ct.length>0){const z=u;u=()=>{z?.();for(const L of Ct)S.gl.deleteTexture(L.entry.glTex)}}const D=z=>{if(!xn||!ln)return;const L=xn;for(const E of Ct){const I=E.layer;let O=String(I.text??"");if(E.sandbox&&E.sandbox.hasUpdate){E.sandbox.engine.runtime=z;const se=E.sandbox.callUpdate(O);se!=null?O=String(se):E.sandbox.thisLayer.text&&(O=String(E.sandbox.thisLayer.text))}else E.sandbox&&typeof E.sandbox.thisLayer?.text=="string"&&(O=String(E.sandbox.thisLayer.text));if(De.set(I.name||"",O),!I.visible)continue;const Q=Math.max(1,E.sandbox?E.sandbox.thisLayer.pointsize:I.textPointsize),$=E.sandbox&&E.sandbox.thisLayer.font||I.textFont||"",Z=`${O}\0${Q}\0${$}\0${I.alpha}\0${I.textCastshadow}\0${I.textMaxwidth||0}\0${I.limitwidth?1:0}\0${I.maxrows||0}\0${I.limitrows?1:0}`;if(E.lastKey!==Z){E.lastKey=Z;try{const se=nh*Q,te=E.boxW,ee=E.boxH,ue=Math.abs(I.scale[0]||1),we=Math.abs(I.scale[1]||1),ke=$&&F.get($)||"sans-serif";L.setTransform(1,0,0,1,0,0),L.font=`${se}px "${ke}", sans-serif`;const ge=L.measureText(""),tt=(ge.fontBoundingBoxAscent||0)+(ge.fontBoundingBoxDescent||0),Re=I.textSpacing||[0,0],jt=Ke.layoutText(O,{boxW:te,boxH:ee,pointsize:se,lineHeight:(tt>0?tt:se*1.25)+Re[1],spacing:Re,padding:I.textPadding||0,maxwidth:I.textMaxwidth||0,limitwidth:!!I.textLimitwidth,maxrows:I.textMaxrows||0,limitrows:!!I.textLimitrows,limituseellipsis:!!I.textLimituseellipsis,halign:I.textHAlign,valign:I.textVAlign},He=>L.measureText(He).width),Zt=E.margin;if(Ke.shouldGrowMediaPlaceholder(te,ee,!!E.sandbox?.hasMediaHook)){const He=Ke.textCanvasMarginGrow(jt,te,ee,Zt);I.size[0]=te+He*2,I.size[1]=ee+He*2}let at=Math.max(1,Math.round(I.size[0]*ue*E.quality)),xt=Math.max(1,Math.round(I.size[1]*we*E.quality));const _n=Math.min(1,K/Math.max(at,xt));at=Math.max(1,Math.round(at*_n)),xt=Math.max(1,Math.round(xt*_n)),ln.width!==at||ln.height!==xt?(ln.width=at,ln.height=xt):L.clearRect(0,0,at,xt);const be=`${se}px "${ke}", sans-serif`,Pe=Math.min(at/I.size[0],xt/I.size[1]);L.setTransform(Pe,0,0,Pe,0,0),L.translate(Zt,Zt),Ke.drawTextLayer(L,jt,{font:be,color:I.textColor,alpha:I.alpha,brightness:I.brightness,spacing:Re,pointsize:se,opaquebackground:!!I.textOpaquebackground,backgroundcolor:I.textBackgroundcolor,backgroundbrightness:I.textBackgroundbrightness,castshadow:!!I.textCastshadow});const ye=E.entry;S.gl.bindTexture(S.gl.TEXTURE_2D,ye.glTex),S.gl.texImage2D(S.gl.TEXTURE_2D,0,S.gl.RGBA,S.gl.RGBA,S.gl.UNSIGNED_BYTE,ln),ye.width=at,ye.height=xt}catch(se){console.warn(`\u6587\u5B57\u5BF9\u8C61 ${I.name} \u7ED8\u5236\u5931\u8D25: ${se.message}`),E.lastKey=null}}}};t.sceneTextUpdate=D,window.__textWidgets=Ct,ce(t,e,`text widgets: ${Ct.length} (scripts ${Ct.filter(z=>z.sandbox).length}, fonts ${F.size}, quality ${V.toFixed(2)})`)}if(a)return;const Nt=[],Yn=[],Kt=[],Ur=[],Sn={},zr=[],Pi=[],Hr=new Map,ks=(C,W)=>{if(!W||typeof W.callCursor!="function"||!W.hasCursorHook)return;const x=Hr.get(C);x?x.push(W):Hr.set(C,[W])};for(const C of Ct)C.sandbox&&ks(C.layer,C.sandbox);{const C=b.general?.orthogonalprojection,W=C?.width||n.width,x=C?.height||n.height,_=v,V=(E,I)=>{const O=b.general||{};if(E==="zoom"&&typeof I=="number"&&Number.isFinite(I)&&I>0){b.cameraTransforms.zoom=I,O.zoom&&typeof O.zoom=="object"?O.zoom.value=I:O.zoom=I;return}O[E]&&typeof O[E]=="object"&&"value"in O[E]?O[E].value=I:O[E]=I};let F=1+Math.max(0,...b.layers.map(E=>Number(E.id)||0));const j={recomputeVisibility:k,getSceneLayer:E=>b.layers.find(I=>I.name===E&&!I.destroyed)||null,getSceneLayerById:E=>b.layers.find(I=>I.id===E&&!I.destroyed)||null,enumerateSceneLayers:()=>b.layers.filter(E=>!E.destroyed),getSceneAnimation:E=>{if(E==null||E==="")return null;if(Sn[E])return Sn[E];for(const I of b.layers)if(I.animations&&I.animations[E])return I.animations[E];return null},cameraTransforms:b.cameraTransforms,getInitialLayerConfig:E=>{const I=E&&typeof E=="object"?E.name:String(E||"");return b.layers.find(O=>O.name===I)||null},createSceneLayer:E=>{let I=E&&typeof E=="object"?E:null,O=null;if(typeof E=="string"){const $=E;if(I=b.layers.find(Z=>Z&&!Z.destroyed&&Z.image===$&&Z.textureName)||b.layers.find(Z=>Z&&!Z.destroyed&&Z.image===$)||null,!I)if(/^models\//.test($)&&Ye.getEntry(m,$))O={path:$,kind:"model"},I={image:$,origin:[0,0,0],scale:[1,1,1],angles:[0,0,0],size:[0,0],color:[1,1,1],visible:!0,alpha:1,brightness:1};else if(/^particles\//.test($)&&Ye.getEntry(m,$))O={path:$,kind:"particle"},I={particle:$,origin:[0,0,0],scale:[1,1,1],angles:[0,0,0],size:[0,0],color:[1,1,1],visible:!0,alpha:1,brightness:1};else return ce(t,e,`createLayer('${$}') \u627E\u4E0D\u5230\u5DF2\u52A0\u8F7D\u7684\u540C\u6A21\u578B\u5C42`),null}I||(I={});const Q={...I,id:F++,origin:Array.isArray(I.origin)?I.origin.slice():[0,0,0],scale:Array.isArray(I.scale)?I.scale.slice():[1,1,1],angles:Array.isArray(I.angles)?I.angles.slice():[0,0,0],size:Array.isArray(I.size)?I.size.slice():[0,0],color:Array.isArray(I.color)?I.color.slice():[1,1,1],childIds:null,hasChildren:!1,destroyed:!1,animations:{},animationList:[],objectScripts:null};if(delete Q.textureAnimation,delete Q.videoTextureApi,delete Q.soundCtl,delete Q.videoCtl,Array.isArray(I.effects)&&(Q.effects=I.effects.map($=>({...$,passes:Array.isArray($.passes)?$.passes.map(Z=>({...Z})):$.passes}))),b.layers.push(Q),Q.runtimeCreated=!0,O&&O.kind==="model"){const $=O.path;try{const Z=JSON.parse(Ot(Ye.getEntry(m,$))),se=vt.resolveMaterial(Z),te=se&&Ye.getEntry(m,se.materialPath),ue=(te?JSON.parse(Ot(te)):null)?.passes?.[0];if(ue?.combos){for(const ke of Object.keys(ue.combos))if(ke.toLowerCase()==="spritesheet"&&Number(ue.combos[ke])===1){Q.spriteSheet=!0;break}}const we=ue?.textures?.[0];typeof we=="string"&&we&&!we.startsWith("util/")&&!we.startsWith("_rt_")&&cn(we).then(ke=>{if(ke&&(Q.textureName=we,Q.size[0]===0||Q.size[1]===0)){const ge=ke.frames&&Array.isArray(ke.frames)?ke.frames[0]:null;Q.size=[ge&&ge.width||ke.width,ge&&ge.height||ke.height]}})}catch(Z){ce(t,e,`createLayer('${$}') \u8D44\u4EA7\u5B9E\u4F8B\u5316\u5931\u8D25: ${String(Z.message||Z).slice(0,120)}`)}}else if(O&&O.kind==="particle"){const $=O.path;ws($,Q,null,0).then(Z=>{Z||ce(t,e,`createLayer('${$}') \u7C92\u5B50\u7CFB\u7EDF\u88C5\u914D\u5931\u8D25`)})}return Q},mediaControl:_t,windowTitle:J.snapshot,openUserShortcut:Dt.openUserShortcut,isScreensaver:!1};S.setConstantScriptRuntime?.(Ke.evalObjectScript,{userProperties:_,audioViews:Fe,shared:Yt,inputView:At,timers:yr,animEventQueue:Pt,...j,onSandbox:(E,I)=>{E&&E.hasMediaHook&&vn(E),E&&E.hasAnimEventHook&&Xe(I&&I.layer,{sandbox:E,kind:"const"})}});const X={origin:"localOrigin",scale:"localScale",angles:"localAngles"},K=(E,I)=>{const O=X[I];return O&&E&&Array.isArray(E[O])?O:I};for(const E of b.layers){const I=E.objectAnimations;if(I){E.animations=E.animations||{},E.animationList=E.animationList||[];for(const[O,Q]of Object.entries(I))try{const $=ps.createAnimation(Q.animation);$.field=O,$.baseValue=Q.value;const Z=K(E,O),se=O==="volume"?E.soundprops?.volume:O==="maxwidth"?E.textMaxwidth:O==="zoom"?b.cameraTransforms?.zoom:E[Z];$.baseNumeric=Array.isArray(se)?se.slice():se,$.slot=Z,E.animationList.push($),$.name&&(E.animations[$.name]=$),Yn.push({layer:E,field:O,slot:Z,ctrl:$})}catch($){ce(t,e,`animation '${E.name}.${O}' \u5EFA\u63A7\u5236\u5668\u5931\u8D25: ${String($.message).slice(0,80)}`)}if(E.animationList.length){const O=new Map;for(const Q of E.animationList)O.set(Q.field,Q);ps.linkAnimations(O,Q=>ce(t,e,`${E.name}: ${Q}`)),E.animationsByField=Object.fromEntries(O)}}}for(const E of b.layers){const I=E.particleOverrideAnimations;if(I)for(const[O,Q]of Object.entries(I))try{const $=ps.createAnimation(Q.animation);$.baseNumeric=typeof Q.value=="number"?Q.value:Number(Q.value)||0,Kt.push({layer:E,key:O,ctrl:$})}catch($){ce(t,e,`override animation '${E.name}.${O}' \u5EFA\u63A7\u5236\u5668\u5931\u8D25: ${String($.message).slice(0,80)}`)}}let D=!1;for(const E of b.layers){for(const[O,Q]of(E.effects||[]).entries()){const $=Q.visibleScript;if($)try{const Z=Ke.evalObjectScript($.script,$.scriptproperties,{canvasSize:{width:W,height:x},userProperties:_,audioViews:Fe,inputView:At,...Gn,layer:E,targetEffect:Q,...j,shared:Yt,onError:ue=>ce(t,e,`effect visible script '${E.name}#${O}' \u5931\u8D25: ${String(ue.message||ue).slice(0,80)}`)});if(!Z)continue;A.push(Z);const se=Z.init(Q.visible),te=vi(se);te!==void 0&&(Q.visible=te),Z.applyUserProperties(_),Z.hasMediaHook&&vn(Z);let ee=null;Z.hasUpdate&&(ee={effect:Q,sandbox:Z,last:se},zr.push(ee)),Z.hasAnimEventHook&&Xe(E,{sandbox:Z,kind:"effectVisible",effect:Q,run:ee})}catch(Z){console.warn(`\u6548\u679C\u5F00\u5173\u811A\u672C ${E.name}#${O} \u6C42\u503C\u5931\u8D25: ${Z.message}`)}}const I=E.objectScripts;if(I)for(const[O,Q]of Object.entries(I))try{const $=Ke.evalObjectScript(Q.script,Q.scriptproperties,{canvasSize:{width:W,height:x},screenResolution:{x:n.clientWidth||window.innerWidth||1,y:n.clientHeight||window.innerHeight||1},timeOfDay:(()=>{const Z=new Date;return(Z.getHours()*3600+Z.getMinutes()*60+Z.getSeconds())/86400})(),userProperties:_,audioViews:Fe,inputView:At,layer:E,getAnimationForProperty:()=>E.animationsByField&&E.animationsByField[O]||null,...j,getBoneOverrides:Lr,shared:Yt,...Gn,onError:Z=>ce(t,e,`object script '${E.name}.${O}' \u5931\u8D25: ${String(Z.message||Z).slice(0,90)}`)});if($){A.push($);const Z=K(E,O),se=E[Z],te=O==="angles"&&Array.isArray(se)?Ke.radToScriptAngles(se):Array.isArray(se)?{x:se[0]??0,y:se[1]??0,z:se[2]??0}:se,ee=$.init(te);if(ee!=null){if(O==="visible"){const ue=vi(ee);ue!==void 0&&E.visibleSelf!==ue&&(E.visibleSelf=ue,D=!0)}else if(typeof ee=="number"&&Number.isFinite(ee))(O==="alpha"||O==="brightness")&&(E[O]=ee);else if(typeof ee=="object"&&ee.x!==void 0){const ue=ee;Number.isFinite(Number(ue.x))&&Number.isFinite(Number(ue.y))&&(E[Z]=O==="angles"?Ke.scriptAnglesToRad(ue):[Number(ue.x)||0,Number(ue.y)||0,Number(ue.z)||0])}}$.applyUserProperties(_),ks(E,$),$.hasMediaHook&&vn($),$.hasUpdate&&Nt.push({layer:E,field:O,slot:Z,kind:O==="visible"?"bool":O==="alpha"||O==="brightness"?"scalar":"vec3",sandbox:$,last:O==="visible"?ee:void 0}),$.hasAnimEventHook&&Xe(E,{sandbox:$,kind:O==="visible"?"bool":O==="alpha"||O==="brightness"?"scalar":"vec3",field:O,slot:Z})}}catch($){console.warn(`\u5BF9\u8C61\u811A\u672C ${E.name}.${O} \u6C42\u503C\u5931\u8D25: ${$.message}`)}}for(const E of Qt){const I=E.sandbox.init(E.layer.text??"");typeof I=="string"&&(E.layer.text=I),E.sandbox.applyUserProperties(v)}D&&k();const z=b.generalScripts;if(z){for(const[E,I]of Object.entries(z))try{const O=Ke.evalObjectScript(I.script,I.scriptproperties,{canvasSize:{width:W,height:x},userProperties:_,audioViews:Fe,inputView:At,...Gn,...j,shared:Yt,onError:$=>ce(t,e,`general script '${E}' \u5931\u8D25: ${String($.message||$).slice(0,80)}`)});if(!O)continue;A.push(O),O.init(I.value),O.applyUserProperties(_),O.hasMediaHook&&vn(O);const Q=$=>V(E,$);O.hasUpdate&&Pi.push({field:E,sandbox:O,write:Q})}catch(O){console.warn(`general \u811A\u672C ${E} \u6C42\u503C\u5931\u8D25: ${O.message}`)}Pi.length&&ce(t,e,`general scripts: ${Pi.map(E=>E.field).join(",")}`)}const L=b.generalAnimations;if(L){for(const[E,I]of Object.entries(L))try{const O=ps.createAnimation(I.animation);O.field=E,O.baseValue=I.value,O.baseNumeric=I.value,O.name&&(Sn[O.name]=O),Ur.push({field:E,ctrl:O,write:Q=>V(E,Q)})}catch(O){ce(t,e,`general animation '${E}' \u5EFA\u63A7\u5236\u5668\u5931\u8D25: ${String(O.message).slice(0,80)}`)}Ur.length&&ce(t,e,`general animations: ${Ur.map(E=>E.field).join(",")}`)}}Nt.length&&(ce(t,e,`object scripts: ${Nt.length}`),window.__objScripts=Nt,window.__effectScripts=zr),window.__mediaHooks=qe,window.__sceneLayers=b.layers,window.__compositeStats=()=>S.compositeStats?.()??null,window.__compositeEnable=C=>S.setCompositeEnabled?.(C),window.__scene=b,window.__textures=Te;const Vr=Array.from(Hr.keys());Vr.length&&ce(t,e,`cursor hooks: ${Vr.length} layers`);let Wr=null,un=null,jr=!1;const ht=()=>({worldPosition:Ke.makeCursorEventVec(dt.state.wx,dt.state.originY!=null?dt.state.originY:dt.state.wy,0)}),Wt=(C,W,x)=>{const _=Hr.get(C);if(_)for(const V of _)V.callCursor(W,x)},qr=()=>{if(Vr.length===0)return;const C=dt.state;if(!C.has)return;const W=S.getParallaxOffset?S.getParallaxOffset():{x:0,y:0},x=b.general?.orthogonalprojection?.height||n.height,_=Ib.hitTestLayers(b.layers,C.wx,C.wy,x,{parOffX:W.x,parOffY:W.y,alignTable:ft.ALIGN,filter:F=>Hr.has(F)}),V=ht();_!==Wr&&(Wr&&Wt(Wr,"cursorLeave",V),Wr=_,_&&Wt(_,"cursorEnter",V)),_&&Wt(_,"cursorMove",V),C.leftDown&&!jr?(un=_,_&&Wt(_,"cursorDown",V)):!C.leftDown&&jr&&(un&&Wt(un,"cursorUp",V),un&&un===_&&Wt(_,"cursorClick",V),un=null),jr=C.leftDown},As=performance.now();let Fa=0,vr=0;const Pn=[],kr=[];let Da=-1/0,xs=0;const _i=C=>{if(a||t.paused)return;const x=1e3/(t.cfg.sceneFps||60);if(C-Da>=x){Da=C,er(t,C),el(t,n,t.cfg);const _=Math.max(0,(C-As-Fa)/1e3);if(At.update(dt.state),Oe.enabled){if(U?.media)U.media.pump();else{const L=Y();typeof L?.update=="function"&&L.update(_)}const D=ve(),z=Se.diffMediaEvents(ze,D);if(z.length){for(const{name:L,event:E}of z)for(const I of qe)I.disabled||I.callMedia(L,E);ze=Se.cloneMediaSnapshot(D)}if(st!==D.thumbnail&&typeof D.thumbnail=="string"&&D.thumbnail){const L=D.thumbnail;st=L,(async()=>{try{const E=await fetch(L,{cache:"no-store"}).then(Z=>Z.ok?Z.blob():null);if(!E)return;const I=await createImageBitmap(E,{premultiplyAlpha:"none"});if(st!==L){I.close?.();return}const O=I.width,Q=I.height,$=ys(I,O,Q);if(I.close?.(),$){const Z=ve();Z.primaryColor=Se.mediaVec3(...$.primary),Z.secondaryColor=Se.mediaVec3(...$.secondary),Z.tertiaryColor=Se.mediaVec3(...$.tertiary),Z.textColor=Se.mediaVec3(.98,.98,1),Z.highContrastColor=Se.mediaVec3(1,1,1)}ce(t,e,`media: $mediaThumbnail \u5DF2\u66F4\u65B0\uFF08${O}\xD7${Q}\uFF09`)}catch(E){ce(t,e,`media: \u5C01\u9762\u4E0A\u4F20\u5931\u8D25\uFF08${E instanceof Error?E.message:E}\uFF09`)}})()}}U?.windowTitle?U.windowTitle.pump():N.update(_);const V=Math.max(0,_-xs);xs=_,Si.dt=V,Si.t=_;let F=!1;const j=(D,z)=>{const L=Le.get(D);if(!(!L||!L.length)){window.__animEventsFired=(window.__animEventsFired||0)+z.length;{const E=window,I=E.__animEventLog||(E.__animEventLog=[]);for(const O of z)I.push({l:String(D&&(D.name||D.id)),f:O.frame,n:O.name}),I.length>400&&I.shift()}for(const E of z)for(const I of L){const O=I.sandbox;if(!(!O||O.disabled))if(I.kind==="text"){const Q=O.callAnimationEvent(E,String(D.text??""));typeof Q=="string"&&(D.text=Q)}else if(I.kind==="effectVisible"){const Q=I.run&&I.run.last!==void 0&&I.run.last!==null?I.run.last:!!I.effect.visible,$=O.callAnimationEvent(E,Q);I.run&&(typeof $=="boolean"||typeof $=="number"&&Number.isFinite($))&&(I.run.last=$);const Z=vi($);Z!==void 0&&(I.effect.visible=Z)}else if(I.kind==="const"){const Q=O.callAnimationEvent(E,O.__lastConstValue);(typeof Q=="number"&&Number.isFinite(Q)||Q&&typeof Q=="object"&&Number.isFinite(Number(Q.x))&&Number.isFinite(Number(Q.y)))&&(O.__lastConstValue=Q)}else if(I.kind==="bool"){const Q=O.callAnimationEvent(E,!!D.visible),$=vi(Q);$!==void 0&&D.visibleSelf!==$&&(D.visibleSelf=$,F=!0)}else if(I.kind==="scalar"){const Q=O.callAnimationEvent(E,Number(D[I.field])||0),$=Number(Q);Number.isFinite($)&&(D[I.field]=$)}else{const Q=D[I.slot],$=I.field==="angles"?Ke.radToScriptAngles(Q):{x:Q&&Q[0]||0,y:Q&&Q[1]||0,z:Q&&Q[2]||0},Z=O.callAnimationEvent(E,$),se=Z&&typeof Z=="object"&&"x"in Z?Z:$;D[I.slot]=I.field==="angles"?Ke.scriptAnglesToRad(se):[Number(se.x)||0,Number(se.y)||0,Number(se.z)||0]}}}};for(const D of Yn){D.ctrl.advance(V);const z=D.field,L=D.slot||z,E=D.ctrl.applyTo(D.ctrl.baseNumeric);if(Array.isArray(E)){const I=D.layer[L];if(Array.isArray(I))for(let O=0;O<E.length&&O<I.length;O++)I[O]=E[O]}else Number.isFinite(E)&&(z==="visible"?D.layer.visibleSelf!==!!E&&(D.layer.visibleSelf=!!E,F=!0):z==="volume"?(D.layer.soundprops.volume=E,D.layer.soundCtl?.setVolume?.(E)):z==="maxwidth"?D.layer.textMaxwidth=E:z==="zoom"?E>0&&(b.cameraTransforms.zoom=E):D.layer[L]=E)}for(const D of Kt){D.ctrl.advance(V);const z=D.ctrl.applyTo(D.ctrl.baseNumeric);if(typeof z!="number"||!Number.isFinite(z))continue;const L=kn.get(D.layer.id);if(L)for(const E of L)E.setOverrideValue(D.key,z)}for(const D of Yn){const z=D.ctrl.takeEvents();z.length&&j(D.layer,z)}for(const D of Kt){const z=D.ctrl.takeEvents();z.length&&j(D.layer,z)}for(const D of Ur)D.ctrl.takeEvents();for(const D of Ur){D.ctrl.advance(V);const z=D.ctrl.applyTo(D.ctrl.baseNumeric);typeof z=="number"&&Number.isFinite(z)?D.write(z):Array.isArray(z)&&Number.isFinite(z[0])&&D.write(z[0])}for(const D of zr){if(D.sandbox.disabled)continue;D.sandbox.engine.frametime=V,D.sandbox.engine.runtime=_;const z=D.sandbox.callUpdate(D.last!==void 0&&D.last!==null?D.last:!!D.effect.visible);(typeof z=="boolean"||typeof z=="number"&&Number.isFinite(z))&&(D.last=z);const L=vi(z);L!==void 0&&(D.effect.visible=L)}for(const D of Pi){if(D.sandbox.disabled)continue;D.sandbox.engine.frametime=V,D.sandbox.engine.runtime=_;const z=b.general||{},L=z[D.field]&&typeof z[D.field]=="object"&&"value"in z[D.field]?z[D.field].value:z[D.field],E=D.sandbox.callUpdate(L);E!==void 0&&D.write(E)}const X={x:n.clientWidth||window.innerWidth||1,y:n.clientHeight||window.innerHeight||1};for(const D of A)!D||D.disabled||(D.engine.frametime=V,D.engine.runtime=_,D.engine.screenResolution=X);for(const D of Nt){if(D.sandbox.disabled)continue;D.sandbox.engine.frametime=V,D.sandbox.engine.runtime=_,D.sandbox.engine.screenResolution=X;const z=D.layer[D.field];if(D.kind==="bool"){const L=D.last!==void 0&&D.last!==null?D.last:!!z,E=D.sandbox.callUpdate(L);(typeof E=="boolean"||typeof E=="number"&&Number.isFinite(E))&&(D.last=E);const I=vi(E);I!==void 0&&(D.field==="visible"?D.layer.visibleSelf!==I&&(D.layer.visibleSelf=I,F=!0):D.layer[D.field]=I)}else if(D.kind==="scalar"){const L=D.sandbox.callUpdate(Number(z)||0),E=Number(L);Number.isFinite(E)&&(D.layer[D.field]=E)}else{const L=D.slot||D.field,E=D.layer[L],I=D.field==="angles"?Ke.radToScriptAngles(E):{x:E[0]||0,y:E[1]||0,z:E[2]||0},O=D.sandbox.callUpdate(I),Q=O&&typeof O=="object"&&"x"in O?O:I;D.layer[L]=D.field==="angles"?Ke.scriptAnglesToRad(Q):[Q.x||0,Q.y||0,Q.z||0]}}F&&k(),Qn.size&&vt.recomposeWorld(b.layers,Qn),ne.enabled&&(Ze.pump(),Ze.active||(H.current?H.current.pump():M.update(_)),hb(Fe,je())),wr.length&&ms.followAttachments(wr,_,Lr);for(const D of An){const z=D.mdl,L=D.layer,E=z.animations;if(!E||!E.length||!L.animationLayers||!L.visible||!E.some(O=>O.events&&O.events.length))continue;let I=Ra.get(L);I||(I=new Map,Ra.set(L,I));for(let O=0;O<L.animationLayers.length;O++){const Q=L.animationLayers[O];if(!Q||Q.visible===!1||Q.visible===0)continue;const $=E.find(ee=>ee.id===Q.animation);if(!$||!$.events||!$.events.length)continue;const Z=_*(typeof Q.rate=="number"?Q.rate:1)*$.fps,se=I.has(O)?I.get(O):Z,te=ps.crossedEvents($.events,se,Z,$.frameCount,$.mode==="loop"?"loop":$.mode==="mirror"?"mirror":"single");te.length&&j(L,te),I.set(O,Z)}}const K=t.coverAlign;S.render(b,Te,n.width,n.height,_,xr(t.cfg.fit),K.x,K.y).then(()=>{if(t.onFirstFrame){const D=t.onFirstFrame;t.onFirstFrame=void 0;try{D()}catch{}}if(!(a||t.paused)){if(Pt.length){for(const D of Pt)j(D.layer,D.events);Pt.length=0}try{qr()}catch{}dt.beginFrame();try{t.sceneTextUpdate&&C>=Tn&&(Tn=C+100,t.sceneTextUpdate(_))}catch{}t.raf=requestAnimationFrame(_i)}}).catch(D=>{console.warn("scene render error:",D),ce(t,e,`render: ${String(D.message||D).slice(0,200)}`),a=!0})}else t.paused||(t.raf=requestAnimationFrame(_i))},Na=()=>{a||t.paused||t.raf===void 0&&(t.raf=requestAnimationFrame(_i))},La=C=>{if(a)return;const W=b.properties||{},x=S0(W,v,C);if(Object.keys(x).length){Rr(b.general||{},W,0);for(const _ of b.layers){const V=_.srcObject;if(!V)continue;Rr(V,W,0);const F=yn(V.visible);F&&F in x&&(_.visibleSelf=vt.parseBool(V.visible,!0));const j=yn(V.color);j&&j in x&&(_.color=vt.parseColor(V.color),_.isText&&(_.textColor=_.color));const X=yn(V.alpha);X&&X in x&&(_.alpha=vt.parseNum(V.alpha,1));const K=yn(V.brightness);K&&K in x&&(_.brightness=vt.parseNum(V.brightness,1));const D=yn(V.volume);if(D&&D in x){const L=vt.parseNum(V.volume,1);_.soundprops&&(_.soundprops.volume=L),_.soundCtl?.setVolume?.(L)}for(let L=0;L<(V.animationlayers||[]).length;L++){const E=V.animationlayers[L],I=_.animationLayers?.[L];if(!E||!I)continue;const O=yn(E.visible);O&&O in x&&(I.visible=vt.parseBool(E.visible,!0));const Q=yn(E.rate);Q&&Q in x&&(I.rate=vt.parseNum(E.rate,1));const $=yn(E.blend);$&&$ in x&&(I.blend=vt.parseNum(E.blend,1))}for(let L=0;L<(V.effects||[]).length;L++){const E=V.effects[L],I=_.effects?.[L];if(!E||!I)continue;const O=yn(E.visible);O&&O in x&&!I.visibleScript&&(I.visible=vt.parseBool(E.visible,!0))}const z=V.instanceoverride;if(z&&typeof z=="object"&&_.particle){let L=!1;for(const E of Object.keys(z)){if(E==="id")continue;const I=yn(z[E]);if(I&&I in x){L=!0;break}}if(L){const E=kn.get(_.id);if(E)for(const I of E)I.reapplyOverride?.()}}}for(const _ of A)if(!(!_||_.disabled))try{_.applyUserProperties(x)}catch{}k();for(const _ of b.layers){if(!_.particle)continue;const V=kn.get(_.id);if(V)for(const F of V)F.setVisible(!!_.visible)}S.applyConstUserProperties?.(x);for(const _ of Ct)_.lastKey=null;ce(t,e,`props hot: ${Object.keys(x).join(",")}`)}};d=()=>{t.raf!==void 0&&(cancelAnimationFrame(t.raf),t.raf=void 0),vr||(vr=performance.now()),Pn.length=0;for(const C of Te.values())C?.videoCtl?.isPlaying?.()&&(Pn.push(C.videoCtl),C.videoCtl.pause());kr.length=0;for(const C of Ti)!C.paused&&!C.ended&&(kr.push(C),C.pause())},h=()=>{vr&&(Fa+=performance.now()-vr,vr=0);for(const C of Pn)try{C.play()}catch{}Pn.length=0;for(const C of kr)C.play().catch(()=>{});kr.length=0,Na()},f=La,l&&(La(l),l=null),Na();{const C=b.general?.orthogonalprojection,W=C?.width||n.width,x=C?.height||n.height,_=xr(t.cfg.fit),V=Ua(_,W,x,n.width,n.height);ce(t,e,`fit ${_}: view ${Math.round(V.viewW)}x${Math.round(V.viewH)} scene ${W}x${x} canvas ${n.width}x${n.height}`);{const F=Sh(b.layers);Number.isFinite(F.minX)&&Number.isFinite(F.minY)&&(t.coverPeek={contentW:F.maxX-F.minX,contentH:F.maxY-F.minY,projW:W,projH:x},ce(t,e,`cover peek gate: content ${Math.round(F.maxX-F.minX)}x${Math.round(F.maxY-F.minY)}`))}}ce(t,e,`renderer started: ${b.layers.length} layers`)}catch(p){if(a||p&&p.name==="AbortError")return;console.warn("scene render failed:",p);const m=p instanceof Error?p:new Error(String(p));ce(t,e,`failed: ${String(m.message||m).slice(0,200)}`),t.onError?t.onError(m):t.fallbackPage?.()}})()}const p1='data-we-shim="1"',sh="data-we-shim-src";function g1(t){try{const e=new URL(t),n=e.pathname,r=n.lastIndexOf("/");return e.pathname=r<0?"/":n.slice(0,r+1),e.hash="",e.search="",e.href}catch{const e=t.replace(/[#?].*$/,""),n=e.lastIndexOf("/");return n<0?e:e.slice(0,n+1)}}function y1(t){const e=/<meta[^>]+http-equiv\s*=\s*["']?Content-Security-Policy["']?[^>]*>/gi;let n;for(;n=e.exec(t);){const r=n[0],i=/content\s*=\s*"([^"]*)"/i.exec(r)?.[1]??/content\s*=\s*'([^']*)'/i.exec(r)?.[1]??"";if(/script-src/i.test(i)&&!/script-src[^;]*'unsafe-inline'/i.test(i)&&!/script-src[^;]*\*/i.test(i))return!0}return!1}function ah(t){return t.replace(/<\/script/gi,"<\\/script")}function b1(t,e,n){if(t||(t=""),t.includes(p1)||t.includes(sh))return t;const r=n.baseHref&&!/<base\b/i.test(t)?`<base href="${n.baseHref.replace(/"/g,""")}">`:"",i=`<script ${sh}="1">
|
|
647
|
+
${ah(e)}
|
|
648
|
+
<\/script>`,s=n.seedScript&&n.seedScript.trim()?`<script>
|
|
649
|
+
${ah(n.seedScript)}
|
|
650
|
+
<\/script>`:"",a=`${r}${i}${s}`,o=/<head(\s[^>]*)?>/i.exec(t);if(o){const u=o.index+o[0].length;return t.slice(0,u)+a+t.slice(u)}const c=/<html(\s[^>]*)?>/i.exec(t);if(c){const u=c.index+c[0].length;return t.slice(0,u)+`<head>${a}</head>`+t.slice(u)}return`<!DOCTYPE html><html><head>${a}</head><body>${t}</body></html>`}const w1=`/**
|
|
517
651
|
* WE \u7F51\u9875\u58C1\u7EB8\u517C\u5BB9 shim\uFF08\u6CE8\u5165\u5230 iframe\uFF0C\u5FC5\u987B\u5728\u4F5C\u8005\u811A\u672C\u4E4B\u524D\u6267\u884C\uFF09\u3002
|
|
518
652
|
*
|
|
519
653
|
* \u8BED\u6599\uFF1A\u672C\u673A\u5E93 42 \u5F20 web \u58C1\u7EB8\u626B\u63CF\uFF082026-09\uFF09\u2014\u2014
|
|
@@ -530,7 +664,8 @@ ${ms(t.seedScript)}
|
|
|
530
664
|
* __wePushMedia(event) \u2014 {op, payload} \u89C1\u4E0B
|
|
531
665
|
* __wePushDirectoryFiles(prop, files) / __weRemoveDirectoryFiles(prop, files)
|
|
532
666
|
* __weRewriteFileUrl(s) \u2014 file:/// \u2192 \u540C\u6E90\u76F8\u5BF9\uFF08HTTP \u9875\uFF09\uFF1B\u7A7A file:/// \u2192 ""
|
|
533
|
-
* __wePushPointer(x, y, buttons) / __wePointerLeave() \u2014 \u5916\u90E8\u6307\u9488\u6CE8\u5165\uFF08\u89C1\u6587\u672B\uFF09
|
|
667
|
+
* __wePushPointer(x, y, buttons, mods) / __wePointerLeave() \u2014 \u5916\u90E8\u6307\u9488\u6CE8\u5165\uFF08\u89C1\u6587\u672B\uFF09
|
|
668
|
+
* __wePushWheel(x, y, dx, dy, mode, mods) \u2014 \u5916\u90E8\u6EDA\u8F6E\u6CE8\u5165\uFF08\u542B\u89E6\u6478\u677F\u634F\u5408\uFF0C\u89C1\u6587\u672B\uFF09
|
|
534
669
|
*/
|
|
535
670
|
(function (w) {
|
|
536
671
|
"use strict";
|
|
@@ -1356,6 +1491,17 @@ ${ms(t.seedScript)}
|
|
|
1356
1491
|
var ptrDownTarget = null; // \u6309\u4E0B\u65F6\u7684\u547D\u4E2D\u5143\u7D20\uFF08click \u5224\u5B9A\uFF09
|
|
1357
1492
|
var ptrLastClickTime = 0;
|
|
1358
1493
|
var ptrLastClickTarget = null;
|
|
1494
|
+
/**
|
|
1495
|
+
* \u4FEE\u9970\u952E\u63A9\u7801\uFF1Abit0 ctrl / bit1 shift / bit2 alt / bit3 meta\u3002
|
|
1496
|
+
*
|
|
1497
|
+
* \u7531 __wePushPointer \u4E0E __wePushWheel \u7684\u672B\u4F4D\u53C2\u6570\u5171\u540C\u7EF4\u62A4\uFF08\u5BBF\u4E3B\u77E5\u9053\u5F53\u524D\u952E\u76D8\u72B6\u6001\uFF0C
|
|
1498
|
+
* \u8C01\u540E\u63A8\u8C01\u8D62\uFF09\u3002\u7701\u7565\u53C2\u6570\u65F6\u5F52 0 \u2014\u2014 \u8001\u5BBF\u4E3B\u4E0D\u4F20\u5C31\u7B49\u4E8E\u6539\u52A8\u524D\u7684\u5168 false\uFF0C\u65E0\u56DE\u5F52\u3002
|
|
1499
|
+
*
|
|
1500
|
+
* \u4E3A\u4EC0\u4E48\u5FC5\u987B\u6709\uFF1A\u89E6\u6478\u677F\u53CC\u6307\u634F\u5408\u5728\u6D4F\u89C8\u5668\u91CC\u5C31\u662F\u300CctrlKey \u4E3A\u771F\u7684 wheel\u300D\uFF0C
|
|
1501
|
+
* OrbitControls / pano2vr \u90FD\u9760 event.ctrlKey \u628A\u7F29\u653E\u548C\u6EDA\u52A8\u5206\u5F00\u3002\u63A9\u7801\u5199\u6B7B false
|
|
1502
|
+
* \u65F6\u634F\u5408\u4E0E\u666E\u901A\u6EDA\u52A8\u65E0\u4ECE\u533A\u5206\u3002
|
|
1503
|
+
*/
|
|
1504
|
+
var ptrMods = 0;
|
|
1359
1505
|
/** \u53CC\u51FB\u5224\u5B9A\u7A97\u53E3\uFF08ms\uFF09\u3002\u4E0E\u4E3B\u6D41\u6D4F\u89C8\u5668\u4E00\u81F4\uFF0C\u8BED\u6599\u91CC 5 \u5F20\u542C dblclick\u3002 */
|
|
1360
1506
|
var PTR_DBLCLICK_MS = 500;
|
|
1361
1507
|
|
|
@@ -1441,10 +1587,12 @@ ${ms(t.seedScript)}
|
|
|
1441
1587
|
buttons: o.buttons != null ? o.buttons : ptrButtons,
|
|
1442
1588
|
movementX: o.movementX || 0,
|
|
1443
1589
|
movementY: o.movementY || 0,
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1590
|
+
// \u4FEE\u9970\u952E\u7531\u5BBF\u4E3B\u63A8\u9001\u7684\u63A9\u7801\u9A71\u52A8\uFF08\u89C1 ptrMods\uFF09\u3002\u66FE\u7ECF\u786C\u7F16\u7801 false\uFF0C
|
|
1591
|
+
// \u4E8E\u662F\u89E6\u6478\u677F\u634F\u5408\uFF08= ctrlKey \u7684 wheel\uFF09\u65E0\u6CD5\u4E0E\u666E\u901A\u6EDA\u52A8\u533A\u5206\u3002
|
|
1592
|
+
ctrlKey: (ptrMods & 1) !== 0,
|
|
1593
|
+
shiftKey: (ptrMods & 2) !== 0,
|
|
1594
|
+
altKey: (ptrMods & 4) !== 0,
|
|
1595
|
+
metaKey: (ptrMods & 8) !== 0,
|
|
1448
1596
|
};
|
|
1449
1597
|
if ("relatedTarget" in o) init.relatedTarget = o.relatedTarget || null;
|
|
1450
1598
|
// \`button: -1\` \u65E0\u6CD5\u7ECF MouseEvent \u6784\u9020\u5668\u8868\u8FBE\uFF1AChromium \u628A -1 \u89C4\u8303\u5316\u6210 0
|
|
@@ -1554,6 +1702,8 @@ ${ms(t.seedScript)}
|
|
|
1554
1702
|
* @param {number} y \u540C\u4E0A\uFF0C\u76F8\u5BF9\u4E0A\u8FB9\uFF0CY \u671D\u4E0B
|
|
1555
1703
|
* @param {number} [buttons] \u6309\u952E\u4F4D\u63A9\u7801\uFF0Cbit0 \u5DE6\u952E\u3002\u4E0E\u573A\u666F\u901A\u9053\u540C\u4E00\u7EA6\u5B9A\uFF0C
|
|
1556
1704
|
* \u5F53\u524D\u53EA\u6D88\u8D39 bit0\uFF08\u53F3/\u4E2D\u952E\u4F4D\u4FDD\u7559\uFF1B\u684C\u9762\u53F3\u952E\u5C5E\u4E8E Finder\uFF0C\u4E0D\u8BE5\u88AB\u58C1\u7EB8\u52AB\u6301\uFF09
|
|
1705
|
+
* @param {number} [mods] \u4FEE\u9970\u952E\u63A9\u7801\uFF1Abit0 ctrl / bit1 shift / bit2 alt / bit3 meta\u3002
|
|
1706
|
+
* \u7701\u7565\u7B49\u4E8E 0\uFF08\u6539\u52A8\u524D\u7684\u5168 false \u884C\u4E3A\uFF09
|
|
1557
1707
|
*
|
|
1558
1708
|
* \u63A5**\u50CF\u7D20**\u800C\u4E0D\u662F\u5F52\u4E00\u5316\u5750\u6807\uFF1A\u7F51\u9875\u58C1\u7EB8\u7684 iframe \u5728 cover \u9732\u5E95\u81EA\u9002\u914D\u4E0B\u53EF\u80FD\u6BD4\u821E\u53F0\u5927
|
|
1559
1709
|
* \u5E76\u5E26\u5C45\u4E2D\u504F\u79FB\uFF08\u89C1 web.ts installLetterboxFix\uFF09\uFF0C\u6362\u7B97\u9700\u8981 iframe \u7684\u51E0\u4F55 \u2014\u2014 \u90A3\u662F\u7236\u9875
|
|
@@ -1562,7 +1712,7 @@ ${ms(t.seedScript)}
|
|
|
1562
1712
|
* \u6682\u505C\u671F\u95F4\u4E22\u5F03\uFF1A\u5B98\u65B9\u6682\u505C\u8BED\u4E49\u662F\u300C\u51BB\u7ED3\u6E32\u67D3\u8FDB\u7A0B\u300D\uFF0C\u6B64\u65F6\u6D3E\u53D1\u4E8B\u4EF6\u4F1A\u8BA9\u4F5C\u8005\u7684\u52A8\u753B\u72B6\u6001
|
|
1563
1713
|
* \u5728\u51BB\u7ED3\u4E2D\u7EE7\u7EED\u63A8\u8FDB\uFF0C\u6062\u590D\u65F6\u753B\u9762\u8DF3\u4E00\u4E0B\u3002
|
|
1564
1714
|
*/
|
|
1565
|
-
w.__wePushPointer = function (x, y, buttons) {
|
|
1715
|
+
w.__wePushPointer = function (x, y, buttons, mods) {
|
|
1566
1716
|
if (paused) return;
|
|
1567
1717
|
var nx = Number(x);
|
|
1568
1718
|
var ny = Number(y);
|
|
@@ -1570,6 +1720,7 @@ ${ms(t.seedScript)}
|
|
|
1570
1720
|
// \u8FD4\u56DE null\u3001\u540E\u7EED offsetX \u5168\u6210 NaN\uFF0C\u4F5C\u8005\u7684\u4F4D\u79FB\u79EF\u5206\u4F1A\u4E00\u6B21\u6027\u6C61\u67D3\u6210 NaN \u4E14\u4E0D\u62A5\u9519\u3002
|
|
1571
1721
|
if (!isFinite(nx) || !isFinite(ny)) return;
|
|
1572
1722
|
var mask = Number(buttons) || 0;
|
|
1723
|
+
ptrMods = Number(mods) || 0;
|
|
1573
1724
|
var moved = !ptrHas || nx !== ptrX || ny !== ptrY;
|
|
1574
1725
|
var maskChanged = mask !== ptrButtons;
|
|
1575
1726
|
// \u4F4D\u7F6E\u4E0E\u6309\u952E\u90FD\u6CA1\u53D8\u5C31\u4EC0\u4E48\u90FD\u4E0D\u53D1\uFF1A\u5BBF\u4E3B\u6309 ~90Hz \u63A8\u9001\uFF0C\u9759\u6B62\u65F6\u91CD\u590D\u6D3E\u53D1
|
|
@@ -1623,6 +1774,204 @@ ${ms(t.seedScript)}
|
|
|
1623
1774
|
ptrDownTarget = null;
|
|
1624
1775
|
};
|
|
1625
1776
|
|
|
1777
|
+
/**
|
|
1778
|
+
* \u5916\u90E8\u6EDA\u8F6E\u6CE8\u5165\uFF08\u5BBF\u4E3B\u6355\u83B7 scrollWheel / magnify \u624B\u52BF\u540E\u63A8\u5165\uFF09\u3002
|
|
1779
|
+
*
|
|
1780
|
+
* @param {number} x \u76F8\u5BF9 iframe \u89C6\u53E3\u5DE6\u8FB9\u7684 **CSS \u50CF\u7D20**\uFF08= clientX \u7A7A\u95F4\uFF09
|
|
1781
|
+
* @param {number} y \u540C\u4E0A\uFF0C\u76F8\u5BF9\u4E0A\u8FB9\uFF0CY \u671D\u4E0B
|
|
1782
|
+
* @param {number} dx \u6A2A\u5411\u6EDA\u52A8\u91CF\uFF0C\u6B63 = \u5185\u5BB9\u5411\u53F3\uFF08\u4E0E DOM deltaX \u540C\u5411\uFF09
|
|
1783
|
+
* @param {number} dy \u7EB5\u5411\u6EDA\u52A8\u91CF\uFF0C\u6B63 = \u5185\u5BB9\u5411\u4E0B\uFF08\u4E0E DOM deltaY \u540C\u5411\uFF0C
|
|
1784
|
+
* \u4E0E macOS NSEvent.scrollingDeltaY **\u53CD\u5411**\uFF0C\u53D6\u53CD\u7531\u5BBF\u4E3B\u8D1F\u8D23\uFF09
|
|
1785
|
+
* @param {number} [mode] deltaMode\uFF1A0 \u50CF\u7D20 / 1 \u884C / 2 \u9875\u3002\u89E6\u6478\u677F\u4E0E Magic Mouse \u6052\u4E3A 0
|
|
1786
|
+
* @param {number} [mods] \u4FEE\u9970\u952E\u63A9\u7801\uFF0Cbit0 ctrl\u3002**\u89E6\u6478\u677F\u53CC\u6307\u634F\u5408 = ctrl + \u6EDA\u8F6E**
|
|
1787
|
+
*
|
|
1788
|
+
* ---- \u4E3A\u4EC0\u4E48\u5FC5\u987B\u8865\u53D1\u65E7\u5F0F \`mousewheel\`\uFF08\u8BED\u6599\u51B3\u5B9A\uFF0C\u6F0F\u4E86\u547D\u4E2D\u7387\u4E3A 0\uFF09----
|
|
1789
|
+
*
|
|
1790
|
+
* \u672C\u673A 52 \u5F20\u7F51\u9875\u58C1\u7EB8\u91CC\u771F\u6B63\u6D88\u8D39\u6EDA\u8F6E\u7684\u4E09\u5904**\u5168\u90FD\u4E0D\u542C\u73B0\u4EE3 \`wheel\`**\uFF1A
|
|
1791
|
+
* - 3406740580 pano2vr\uFF08\u552F\u4E00\u4F5C\u8005\u8BBE\u8BA1\u5185\u7684\u6EDA\u8F6E\u4EA4\u4E92\uFF0C\u6EDA\u8F6E\u6539\u5168\u666F FOV\uFF09\uFF1A
|
|
1792
|
+
* \`addEventListener("mousewheel")\` + \`("DOMMouseScroll")\`\uFF0Chandler \u53D6
|
|
1793
|
+
* \`a.detail ? -1*a.detail : a.wheelDelta/40\`\uFF1B
|
|
1794
|
+
* - 2179153203 ge1doot\uFF1A\`onmousewheel\` \u91CC \`-event.wheelDelta * .25\`\uFF1B
|
|
1795
|
+
* - 2517518192 GameMaker \u8FD0\u884C\u65F6\uFF1A\`canvas.onmousewheel\` + DOMMouseScroll\u3002
|
|
1796
|
+
* \u53EA\u542C \`wheel\` \u7684\u662F OrbitControls\uFF081808443523\uFF09\u4E0E react-lrc\uFF082905017768\uFF09\u3002
|
|
1797
|
+
* \u6240\u4EE5\u4E24\u8DEF\u90FD\u5F97\u53D1\uFF0C\u53EA\u53D1\u4EFB\u610F\u4E00\u8DEF\u90FD\u6709\u771F\u5B9E\u58C1\u7EB8\u5B8C\u5168\u65E0\u53CD\u5E94\u3002
|
|
1798
|
+
*
|
|
1799
|
+
* ---- \u4E3A\u4EC0\u4E48**\u4E0D**\u53D1 \`DOMMouseScroll\`\uFF08\u5426\u5219\u6EDA\u52A8\u91CF\u7FFB\u500D\uFF09----
|
|
1800
|
+
*
|
|
1801
|
+
* \u4E0A\u9762\u4E09\u5904\u65E7\u5F0F\u6D88\u8D39\u65B9**\u6BCF\u4E00\u5904\u90FD\u540C\u65F6\u6CE8\u518C\u4E86 \`mousewheel\` \u548C \`DOMMouseScroll\`**\uFF0C
|
|
1802
|
+
* \u800C\u5B83\u4EEC\u7684 handler \u662F\u540C\u4E00\u4E2A\u51FD\u6570\u3002\u4E24\u4E2A\u90FD\u53D1 = \u540C\u4E00\u6B21\u6EDA\u52A8\u88AB\u5904\u7406\u4E24\u904D\uFF0Cpano2vr \u7684
|
|
1803
|
+
* FOV \u4E00\u6B21\u8DF3\u4E24\u683C\uFF0C\u4E14\u770B\u8D77\u6765\u53EA\u662F\u300C\u6EDA\u8F6E\u592A\u7075\u654F\u300D\uFF0C\u4E0D\u50CF bug\u3002\u771F\u5B9E\u6D4F\u89C8\u5668\u4E5F\u4ECE\u4E0D\u540C\u65F6\u53D1
|
|
1804
|
+
* \u8FD9\u4E24\u4E2A\uFF08Chromium \u53EA\u53D1 wheel + mousewheel\uFF09\u3002\u4E14\u5168\u8BED\u6599\u6CA1\u6709\u4EFB\u4F55\u4E00\u5F20\u53EA\u542C
|
|
1805
|
+
* DOMMouseScroll \u2014\u2014 \u5B83\u6CA1\u6709\u72EC\u5360\u6D88\u8D39\u65B9\uFF0C\u53D1\u5B83\u7EAF\u662F\u8D1F\u6536\u76CA\u3002
|
|
1806
|
+
*
|
|
1807
|
+
* \u6682\u505C\u671F\u95F4\u4E22\u5F03\uFF0C\u4E0E __wePushPointer \u4E00\u81F4\u3002
|
|
1808
|
+
*/
|
|
1809
|
+
w.__wePushWheel = function (x, y, dx, dy, mode, mods) {
|
|
1810
|
+
if (paused) return;
|
|
1811
|
+
// \u5148\u8F6C\u6570\u518D\u5224\u6709\u9650\uFF0C**\u4E0D\u8981**\u5199 \`Number(dx) || 0\`\uFF1A\u90A3\u4F1A\u628A NaN \u9759\u9ED8\u53D8\u6210 0\uFF0C
|
|
1812
|
+
// \u4E8E\u662F\u300C\u975E\u6709\u9650\u503C\u4E22\u5F03\u300D\u8FD9\u6761\u7EA6\u5B9A\u5F62\u540C\u865A\u8BBE\uFF08NaN \u7684 dy \u4F1A\u88AB\u5F53\u6210 0 \u653E\u8FC7\u53BB\uFF0C
|
|
1813
|
+
// \u518D\u4E0E\u5408\u6CD5\u7684 dx \u4E00\u8D77\u6D3E\u53D1\u51FA\u4E00\u4E2A\u534A\u6C61\u67D3\u7684\u4E8B\u4EF6\uFF09\u3002
|
|
1814
|
+
var ndx = Number(dx);
|
|
1815
|
+
var ndy = Number(dy);
|
|
1816
|
+
// \u975E\u6709\u9650\u503C\u4E22\u5F03\uFF08\u4E0E\u6307\u9488\u901A\u9053\u540C\u4E00\u7EA6\u5B9A\uFF09\uFF1ANaN \u7684 deltaY \u4F1A\u6C61\u67D3\u4F5C\u8005\u7684\u7F29\u653E\u7D2F\u52A0\u5668\uFF0C
|
|
1817
|
+
// \u4E4B\u540E\u65E0\u8BBA\u600E\u4E48\u6EDA\u90FD\u6062\u590D\u4E0D\u4E86\uFF0C\u4E14\u6CA1\u6709\u4EFB\u4F55\u62A5\u9519\u3002
|
|
1818
|
+
if (!isFinite(ndx) || !isFinite(ndy)) return;
|
|
1819
|
+
// \u4E24\u4E2A\u65B9\u5411\u90FD\u662F 0 \u5C31\u4EC0\u4E48\u90FD\u4E0D\u53D1\uFF1A\u5BBF\u4E3B\u5728\u60EF\u6027\u6EDA\u52A8\u5C3E\u58F0\u4F1A\u63A8\u4E00\u4E32 0\uFF0C
|
|
1820
|
+
// \u7A7A\u4E8B\u4EF6\u4F1A\u8BA9\u4F5C\u8005\u7684\u300C\u6709\u6CA1\u6709\u5728\u6EDA\u300D\u5224\u5B9A\u4E00\u76F4\u4E3A\u771F\u3002
|
|
1821
|
+
if (ndx === 0 && ndy === 0) return;
|
|
1822
|
+
var dmode = Number(mode) || 0;
|
|
1823
|
+
ptrMods = Number(mods) || 0;
|
|
1824
|
+
|
|
1825
|
+
// \u4F4D\u7F6E\uFF1A\u6EDA\u8F6E\u4E8B\u4EF6\u672C\u8EAB\u4E0D\u5E26\u4F4D\u7F6E\uFF0C\u7528\u6700\u540E\u5DF2\u77E5\u7684\u6307\u9488\u4F4D\u7F6E\u3002\u6CA1\u6536\u5230\u8FC7\u6307\u9488\u65F6\u53D6\u89C6\u53E3\u4E2D\u5FC3
|
|
1826
|
+
// \u800C\u4E0D\u662F (0,0) \u2014\u2014 OrbitControls \u4E00\u65CF\u6309\u4E8B\u4EF6\u5750\u6807\u5B9A\u7F29\u653E\u951A\u70B9\uFF0C\u843D\u5728\u5DE6\u4E0A\u89D2\u4F1A\u8BA9\u753B\u9762
|
|
1827
|
+
// \u4E00\u8FB9\u7F29\u653E\u4E00\u8FB9\u5F80\u89D2\u4E0A\u8DD1\u3002
|
|
1828
|
+
var px = ptrX;
|
|
1829
|
+
var py = ptrY;
|
|
1830
|
+
if (!ptrHas) {
|
|
1831
|
+
px = ptrViewportW() / 2;
|
|
1832
|
+
py = ptrViewportH() / 2;
|
|
1833
|
+
}
|
|
1834
|
+
var nx = Number(x);
|
|
1835
|
+
var ny = Number(y);
|
|
1836
|
+
if (isFinite(nx) && isFinite(ny)) {
|
|
1837
|
+
px = nx;
|
|
1838
|
+
py = ny;
|
|
1839
|
+
ptrX = nx;
|
|
1840
|
+
ptrY = ny;
|
|
1841
|
+
ptrHas = true;
|
|
1842
|
+
}
|
|
1843
|
+
|
|
1844
|
+
var target = ptrHitTest(px, py);
|
|
1845
|
+
// \u547D\u4E2D\u5143\u7D20\u53D8\u4E86\u8981\u5148\u8865\u8FB9\u754C\u94FE\uFF1A\u4F5C\u8005\u53EF\u80FD\u9760 mouseenter \u624D\u5F00\u59CB\u63A5\u6EDA\u8F6E
|
|
1846
|
+
// \uFF08\u4E0E __wePushPointer \u540C\u4E00\u7406\u7531\uFF09\uFF0C\u4E14 pano2vr \u7684 handler \u5F00\u5934\u5C31 \`this.zc(a.target)\`
|
|
1847
|
+
// \u6821\u9A8C\u547D\u4E2D\u662F\u4E0D\u662F\u81EA\u5DF1\u7684\u5BB9\u5668\u3002
|
|
1848
|
+
if (target !== ptrTarget) {
|
|
1849
|
+
ptrCrossBoundary(ptrTarget, target, px, py);
|
|
1850
|
+
ptrTarget = target;
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
// (1) \u73B0\u4EE3 \`wheel\`\u3002**\u5FC5\u987B cancelable**\uFF1Apano2vr \u4E0E ge1doot \u90FD\u5728 handler \u91CC\u8C03
|
|
1854
|
+
// preventDefault()\uFF0C\u4E0D\u53EF\u53D6\u6D88\u65F6 Chromium \u4F1A\u5728\u63A7\u5236\u53F0\u5237 Unable to preventDefault
|
|
1855
|
+
// \u4E14\u4F5C\u8005\u7684 \`return false\` \u5206\u652F\u8BED\u4E49\u6F02\u79FB\u3002
|
|
1856
|
+
ptrDispatchWheel(target, px, py, ndx, ndy, dmode);
|
|
1857
|
+
|
|
1858
|
+
// (2) \u65E7\u5F0F \`mousewheel\`\uFF08Chromium \u7684 legacy alias\uFF0C\u4E0E\u771F\u5B9E\u6D4F\u89C8\u5668\u540C\u6B3E\u7EC4\u5408\uFF09\u3002
|
|
1859
|
+
// wheelDelta \u4E0E deltaY **\u53CD\u53F7**\uFF1A\u4E00\u683C\u6807\u51C6\u6EDA\u52A8\u5728 Chromium \u91CC\u662F deltaY=+100\u3001
|
|
1860
|
+
// wheelDelta=-120\uFF0C\u6545\u7CFB\u6570 1.2\u3002pano2vr \u7684 \`wheelDelta/40\` \u5F97 -3 \u2192 \u7F29\u5C0F\uFF0C
|
|
1861
|
+
// \u4E0E\u771F\u5B9E\u6D4F\u89C8\u5668\u91CC\u6EDA\u4E0B\u7F29\u5C0F\u4E00\u81F4\uFF1B\u7B26\u53F7\u641E\u53CD\u4F1A\u8BA9\u6240\u6709\u65E7\u5F0F\u58C1\u7EB8\u7684\u6EDA\u8F6E\u65B9\u5411\u6574\u4F53\u53CD\u8FC7\u6765\u3002
|
|
1862
|
+
var pxPerUnit = dmode === 1 ? WHEEL_LINE_PX : dmode === 2 ? ptrViewportH() || 800 : 1;
|
|
1863
|
+
var legacyY = -ndy * pxPerUnit * 1.2;
|
|
1864
|
+
var legacyX = -ndx * pxPerUnit * 1.2;
|
|
1865
|
+
var ev = ptrMakeEvent("mousewheel", px, py, { button: -1 });
|
|
1866
|
+
if (ev) {
|
|
1867
|
+
ptrDefine(ev, "wheelDelta", legacyY);
|
|
1868
|
+
ptrDefine(ev, "wheelDeltaY", legacyY);
|
|
1869
|
+
ptrDefine(ev, "wheelDeltaX", legacyX);
|
|
1870
|
+
// detail \u6052\u4E3A 0\uFF1A\u65E7\u5F0F Firefox \u90A3\u5957 \`a.detail ? -1*a.detail : a.wheelDelta/40\`
|
|
1871
|
+
// \u7684\u4E09\u5143\u5224\u65AD\u91CC\uFF0Cdetail \u975E 0 \u4F1A\u62A2\u5728 wheelDelta \u4E4B\u524D\u88AB\u91C7\u7528\uFF08\u4E14\u91CF\u7EA7\u5B8C\u5168\u4E0D\u540C\uFF09\u3002
|
|
1872
|
+
ptrDefine(ev, "detail", 0);
|
|
1873
|
+
try {
|
|
1874
|
+
target && target.dispatchEvent && target.dispatchEvent(ev);
|
|
1875
|
+
} catch (_) {
|
|
1876
|
+
/* \u4F5C\u8005 handler \u629B\u9519\u4E0D\u6253\u65AD\uFF08\u4E0E ptrDispatch \u540C\u4E00\u7406\u7531\uFF09 */
|
|
1877
|
+
}
|
|
1878
|
+
}
|
|
1879
|
+
};
|
|
1880
|
+
|
|
1881
|
+
/** \u4E00\u683C\u300C\u884C\u300D\u6EDA\u52A8\u6298\u7B97\u7684\u50CF\u7D20\u6570\uFF0C\u4E0E Chromium \u7684 kDefaultLineHeight \u91CF\u7EA7\u4E00\u81F4\u3002 */
|
|
1882
|
+
var WHEEL_LINE_PX = 40;
|
|
1883
|
+
|
|
1884
|
+
function ptrViewportW() {
|
|
1885
|
+
try {
|
|
1886
|
+
return Number(w.innerWidth) || Number(w.document.documentElement.clientWidth) || 0;
|
|
1887
|
+
} catch (_) {
|
|
1888
|
+
return 0;
|
|
1889
|
+
}
|
|
1890
|
+
}
|
|
1891
|
+
|
|
1892
|
+
function ptrViewportH() {
|
|
1893
|
+
try {
|
|
1894
|
+
return Number(w.innerHeight) || Number(w.document.documentElement.clientHeight) || 0;
|
|
1895
|
+
} catch (_) {
|
|
1896
|
+
return 0;
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
|
|
1900
|
+
/** \u5728\u5408\u6210\u4E8B\u4EF6\u4E0A\u8865\u4E00\u4E2A\u53EA\u8BFB\u5B57\u6BB5\uFF08\u6784\u9020\u5668\u4E0D\u8BA4\u8BC6\u7684 legacy \u5B57\u6BB5\u53EA\u80FD\u8FD9\u4E48\u7ED9\uFF09\u3002 */
|
|
1901
|
+
function ptrDefine(ev, key, value) {
|
|
1902
|
+
try {
|
|
1903
|
+
Object.defineProperty(ev, key, {
|
|
1904
|
+
configurable: true,
|
|
1905
|
+
get: function () {
|
|
1906
|
+
return value;
|
|
1907
|
+
},
|
|
1908
|
+
});
|
|
1909
|
+
} catch (_) {
|
|
1910
|
+
try {
|
|
1911
|
+
ev[key] = value;
|
|
1912
|
+
} catch (__) {
|
|
1913
|
+
/* \u53EA\u8BFB\u4E14\u4E0D\u53EF\u91CD\u5B9A\u4E49\u65F6\u653E\u5F03\u8BE5\u5B57\u6BB5 */
|
|
1914
|
+
}
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
/**
|
|
1919
|
+
* \u6D3E\u53D1\u73B0\u4EE3 \`wheel\`\u3002\u4F18\u5148\u771F \`WheelEvent\`\uFF08\u4F5C\u8005\u8BFB deltaMode / deltaZ \u65F6\u624D\u5BF9\uFF09\uFF1B
|
|
1920
|
+
* \u73AF\u5883\u6CA1\u6709\u65F6\u9000\u56DE MouseEvent \u518D\u8865\u5B57\u6BB5 \u2014\u2014 \u4E8B\u4EF6\u540D\u7167\u65E7\uFF0C\`addEventListener('wheel')\`
|
|
1921
|
+
* \u4ECD\u7136\u6536\u5230\u3002
|
|
1922
|
+
*/
|
|
1923
|
+
function ptrDispatchWheel(target, x, y, dx, dy, mode) {
|
|
1924
|
+
if (!target || typeof target.dispatchEvent !== "function") return;
|
|
1925
|
+
var init = {
|
|
1926
|
+
bubbles: true,
|
|
1927
|
+
cancelable: true,
|
|
1928
|
+
composed: true,
|
|
1929
|
+
view: w,
|
|
1930
|
+
detail: 0,
|
|
1931
|
+
clientX: x,
|
|
1932
|
+
clientY: y,
|
|
1933
|
+
screenX: x + (Number(w.screenX) || 0),
|
|
1934
|
+
screenY: y + (Number(w.screenY) || 0),
|
|
1935
|
+
// \u6EDA\u8F6E\u4E0D\u662F\u6309\u952E\u72B6\u6001\u53D8\u5316\uFF0Cbutton \u53D6 -1 \u54E8\u5175\uFF08\u4E0E\u79FB\u52A8\u7C7B\u4E8B\u4EF6\u540C\u4E00\u7406\u7531\uFF0C
|
|
1936
|
+
// \u586B 0 \u4F1A\u8BA9 GameMaker \u4E00\u65CF\u8BEF\u8BA4\u4E3A\u5DE6\u952E\u6309\u7740\uFF09
|
|
1937
|
+
button: -1,
|
|
1938
|
+
buttons: ptrButtons,
|
|
1939
|
+
ctrlKey: (ptrMods & 1) !== 0,
|
|
1940
|
+
shiftKey: (ptrMods & 2) !== 0,
|
|
1941
|
+
altKey: (ptrMods & 4) !== 0,
|
|
1942
|
+
metaKey: (ptrMods & 8) !== 0,
|
|
1943
|
+
deltaX: dx,
|
|
1944
|
+
deltaY: dy,
|
|
1945
|
+
deltaZ: 0,
|
|
1946
|
+
deltaMode: mode,
|
|
1947
|
+
};
|
|
1948
|
+
var ev = null;
|
|
1949
|
+
try {
|
|
1950
|
+
if (typeof w.WheelEvent === "function") ev = new w.WheelEvent("wheel", init);
|
|
1951
|
+
} catch (_) {
|
|
1952
|
+
/* \u9000\u56DE MouseEvent */
|
|
1953
|
+
}
|
|
1954
|
+
if (!ev) {
|
|
1955
|
+
try {
|
|
1956
|
+
if (typeof w.MouseEvent === "function") ev = new w.MouseEvent("wheel", init);
|
|
1957
|
+
} catch (_) {
|
|
1958
|
+
/* \u5FFD\u7565 */
|
|
1959
|
+
}
|
|
1960
|
+
}
|
|
1961
|
+
if (!ev) return;
|
|
1962
|
+
// MouseEvent \u9000\u8DEF\u4E0A delta* \u4E0D\u4F1A\u88AB\u6784\u9020\u5668\u91C7\u7EB3\uFF0C\u5FC5\u987B\u8865\uFF1BWheelEvent \u8DEF\u5F84\u4E0B
|
|
1963
|
+
// \u8BFB\u5230\u7684\u503C\u4E0E init \u76F8\u540C\uFF0C\u6761\u4EF6\u4E0D\u6210\u7ACB\uFF0C\u8865\u4E5F\u4E0D\u4F1A\u53D1\u751F\u3002
|
|
1964
|
+
if (ev.deltaX !== dx) ptrDefine(ev, "deltaX", dx);
|
|
1965
|
+
if (ev.deltaY !== dy) ptrDefine(ev, "deltaY", dy);
|
|
1966
|
+
if (ev.deltaMode !== mode) ptrDefine(ev, "deltaMode", mode);
|
|
1967
|
+
if (ev.button !== -1) ptrDefine(ev, "button", -1);
|
|
1968
|
+
try {
|
|
1969
|
+
target.dispatchEvent(ev);
|
|
1970
|
+
} catch (_) {
|
|
1971
|
+
/* \u4F5C\u8005 handler \u629B\u9519\u4E0D\u6253\u65AD\u540E\u7EED\u65E7\u5F0F\u4E8B\u4EF6 */
|
|
1972
|
+
}
|
|
1973
|
+
}
|
|
1974
|
+
|
|
1626
1975
|
/**
|
|
1627
1976
|
* \u6307\u9488\u79BB\u5F00\u672C\u7A97\u53E3\uFF08\u9F20\u6807\u53BB\u4E86\u522B\u7684\u663E\u793A\u5668\uFF09\u3002
|
|
1628
1977
|
*
|
|
@@ -1714,7 +2063,7 @@ ${ms(t.seedScript)}
|
|
|
1714
2063
|
installRafThrottle();
|
|
1715
2064
|
})(window);
|
|
1716
2065
|
|
|
1717
|
-
`;function
|
|
1718
|
-
`)}function xu(e,n,t){const r="position:absolute;border:none;background:transparent;",o=()=>{n.style.cssText=r+"inset:0;width:100%;height:100%;"};o();let i="";const s=()=>{if(!n.isConnected)return;let p=null;try{p=n.contentDocument}catch{return}if(!p)return;const d=t.clientWidth||window.innerWidth||0,y=t.clientHeight||window.innerHeight||0,x=dn(e.cfg.fit)==="cover";o();const m=x&&d>0&&y>0?Pu(p):null,M=m?Eu(d,y,m.contentAspect):null,h=M?`${Math.round(M.width)}x${Math.round(M.height)}`:"full";if(!M){i="full";return}n.style.cssText=r+`left:${M.left}px;top:${M.top}px;width:${M.width}px;height:${M.height}px;`,h!==i&&(i=h,se(e,e.cfg,`\u7F51\u9875\u58C1\u7EB8\u9732\u5E95\u81EA\u9002\u914D\uFF1A\u89C6\u53E3\u6309\u5185\u5BB9\u6BD4\u4F8B\u6539\u4E3A ${Math.round(M.width)}\xD7${Math.round(M.height)}\uFF08cover \u5C45\u4E2D\u88C1\u5207\uFF09`))},a=()=>s();window.addEventListener("resize",a);let c;typeof ResizeObserver<"u"&&(c=new ResizeObserver(()=>s()),c.observe(t));const u=[],l=()=>{s();for(const p of[120,400,1200])u.push(window.setTimeout(s,p));try{const p=n.contentDocument;if(p)for(const d of p.querySelectorAll("video,img"))d.addEventListener("loadedmetadata",s,{once:!0}),d.addEventListener("load",s,{once:!0})}catch{}};n.addEventListener("load",l),e.webRelayout=s;const f=e.sceneCleanup;e.sceneCleanup=()=>{window.removeEventListener("resize",a),c?.disconnect();for(const p of u)clearTimeout(p);n.removeEventListener("load",l),e.webRelayout===s&&(e.webRelayout=void 0);try{f?.()}catch{}}}function wu(e,n,t,r,o){if(!Number.isFinite(e)||!Number.isFinite(n)||!(t.width>0)||!(t.height>0))return null;const i=r.width>0&&o.width>0?r.width/o.width:1,s=r.height>0&&o.height>0?r.height/o.height:1;return{x:(e*t.width-(r.left-t.left))/(i||1),y:(n*t.height-(r.top-t.top))/(s||1)}}function Mu(e,n,t){e.pointerCtl={push(r){if(!n.isConnected)return;const o=t.getBoundingClientRect(),i=n.getBoundingClientRect(),s=wu(Number(r?.u),Number(r?.v),{left:o.left,top:o.top,width:o.width||t.clientWidth||window.innerWidth||0,height:o.height||t.clientHeight||window.innerHeight||0},{left:i.left,top:i.top,width:i.width,height:i.height},{width:n.clientWidth,height:n.clientHeight});s&&qe(e,a=>a.__wePushPointer?.(s.x,s.y,Number(r.buttons)||0))},leave(){qe(e,r=>r.__wePointerLeave?.())}}}function po(e,n,t,r,o){const i=document.createElement("iframe");i.setAttribute("sandbox","allow-scripts allow-same-origin"),i.style.cssText="position:absolute;inset:0;width:100%;height:100%;border:none;background:transparent;",!e.wrap&&getComputedStyle(t).position==="static"&&(t.style.position="relative"),i.src=r,t.appendChild(i),e.iframe=i,o.blobUrl&&(e.objectUrls??=[]).push(o.blobUrl),xu(e,i,t),o.injected&&Mu(e,i,t);const s=c=>{if(c.source!==i.contentWindow)return;const u=c.data;if(!u||u.op!=="we-frame"||e.paused)return;const l=typeof u.t=="number"?u.t:performance.now();o.frameClock&&(o.frameClock.last=l),An(e,l)};window.addEventListener("message",s);const a=e.sceneCleanup;e.sceneCleanup=()=>{window.removeEventListener("message",s);try{a?.()}catch{}},i.addEventListener("load",()=>{try{const l=i.contentDocument;l&&window.__blockContextMenu?.(l),o.injected||lu(e,i,l)}catch{}qe(e,l=>{const f={};for(const[p,d]of Object.entries(e.liveUserProps??{}))f[p]={value:d};l.__weApplyProps?.(f),l.__weSetFps?.(e.cfg.sceneFps??60),l.__weSetVolume?.(e.cfg.muted===!1?1:0),e.paused&&l.__weSetPaused?.(!0)});try{e.onFirstFrame?.(),e.onFirstFrame=void 0}catch{}const c=t.clientWidth||window.innerWidth||1,u=t.clientHeight||window.innerHeight||1;try{e.onSceneInfo?.({width:c,height:u,layerCount:0,hasModels:!1,hasParticles:!1,hasText:!1})}catch{}})}const _u=.005,Au=.01,Tu=.2,Su=6;function Eu(e,n,t){if(!(e>0)||!(n>0)||!(t>0))return null;const r=e/n;if(Math.abs(r-t)<=_u)return null;if(r<t){const i=n*t;return{width:i,height:n,left:(e-i)/2,top:0}}const o=e/t;return{width:e,height:o,left:0,top:(n-o)/2}}function Pu(e){const n=e.defaultView;if(!n)return null;const t=n.innerWidth,r=n.innerHeight;if(!(t>0)||!(r>0))return null;const o=[...e.querySelectorAll("video,img")];for(const i of o){const s=i.getBoundingClientRect();if(s.width<=0||s.height<=0||s.width<t*.98||Math.abs(s.left)>t*.02||s.top>r*.02||r-s.height<r*Au)continue;const a=i.videoWidth||i.naturalWidth||0,c=i.videoHeight||i.naturalHeight||0;if(!(a>0)||!(c>0))continue;const u=a/c;if(!(!Number.isFinite(u)||u<Tu||u>Su))return{contentAspect:u}}return null}function cn(e){if(!e)return"rgb(128,128,128)";const n=Math.round(Math.max(0,Math.min(1,Number(e.x)||0))*255),t=Math.round(Math.max(0,Math.min(1,Number(e.y)||0))*255),r=Math.round(Math.max(0,Math.min(1,Number(e.z)||0))*255);return`rgb(${n},${t},${r})`}function Cu(e){try{const n=document.createElement("canvas");n.width=n.height=64;const t=n.getContext("2d");if(!t)return"";const r=e.primaryColor,o=e.secondaryColor,i=t.createLinearGradient(0,0,64,64);return i.addColorStop(0,cn(r)),i.addColorStop(1,cn(o)),t.fillStyle=i,t.fillRect(0,0,64,64),n.toDataURL("image/jpeg",.85)}catch{return""}}function Lu(){return xe.createSimulatedMedia()}function Ru(e,n,t){const r=xe.diffMediaEvents(n,t);for(const{name:o,event:i}of r)if(o==="mediaStatusChanged")qe(e,s=>s.__wePushMedia?.({op:"status",enabled:!!i.enabled}));else if(o==="mediaPropertiesChanged")qe(e,s=>s.__wePushMedia?.({op:"properties",title:i.title??"",artist:i.artist??"",album:i.album??"",albumArtist:i.albumArtist??""}));else if(o==="mediaThumbnailChanged"){const s=Cu(t);qe(e,a=>a.__wePushMedia?.({op:"thumbnail",thumbnail:s,hasThumbnail:!!i.hasThumbnail||!!s,primaryColor:cn(i.primaryColor),secondaryColor:cn(i.secondaryColor),tertiaryColor:cn(i.tertiaryColor),textColor:cn(i.textColor),highContrastColor:cn(i.highContrastColor)}))}else o==="mediaPlaybackChanged"?qe(e,s=>s.__wePushMedia?.({op:"playback",state:Number(i.state)||0})):o==="mediaTimelineChanged"&&qe(e,s=>s.__wePushMedia?.({op:"timeline",position:Number(i.position)||0,duration:Number(i.duration)||0}));return xe.cloneMediaSnapshot(t)}function bs(e,n,t,r={driver:null}){if(!n)return;const o=gu(e),i=()=>e.audioBridge?o:r.driver??n;let s=0,a=0;const c=l=>{if(s=requestAnimationFrame(c),e.paused||!e.iframe)return;const f=e.cfg.sceneFps||60,d=1e3/Math.min(Math.max(1,f),hu);if(!(l-a<d*.85)){a=l;try{const y=i();y.tick?.(l);const x=y.snapshot(),m=fu(uu,x.left,x.right);qe(e,M=>M.__wePushAudio?.(m)),t&&l-t.last>200&&An(e,l)}catch{}}};s=requestAnimationFrame(c);const u=e.sceneCleanup;e.sceneCleanup=()=>{cancelAnimationFrame(s);try{u?.()}catch{}}}function ys(e,n){if(!n)return;const t=()=>e.mediaSource??n;let r=0,o=null,i=0;const s=c=>{if(r=requestAnimationFrame(s),!(e.paused||!e.iframe)&&!(c-i<200)){i=c;try{const u=t();u.update?.(c/1e3),o=Ru(e,o,u.snapshot)}catch{}}};r=requestAnimationFrame(s);const a=e.sceneCleanup;e.sceneCleanup=()=>{cancelAnimationFrame(r);try{a?.()}catch{}}}function ku(e){e.sceneCtl={pause(){e.paused=!0,qe(e,n=>n.__weSetPaused?.(!0))},resume(){e.paused=!1,qe(e,n=>n.__weSetPaused?.(!1))},applyUserProperties(n){const t={...e.liveUserProps??{}};for(const[r,o]of Object.entries(n??{})){const i=o&&typeof o=="object"&&"value"in o?o.value:o;t[r]=i}e.liveUserProps=t,qe(e,r=>r.__weApplyProps?.(n))}}}function Fu(e){try{return new URL(e,location.href).origin===location.origin}catch{return!1}}function Nu(e){const n=e?.general?.properties;if(!n||typeof n!="object")return{};const t={};for(const[r,o]of Object.entries(n)){if(!o||typeof o!="object"||typeof o.type!="string")continue;const i=o.value,s=o.type.toLowerCase();if(i==null){if(s==="file"||s==="directory"){t[r]={value:""};continue}if(!("value"in o))continue}t[r]={value:i}}return t}async function Uu(e){try{const n=new URL("project.json",new URL(e,location.href)),t=await fetch(n.href,{credentials:"same-origin"});return t.ok?Nu(await t.json()):{}}catch{return{}}}function Du(e,n){const t={...e};if(n)for(const[r,o]of Object.entries(n))t[r]={value:o};return t}function Bu(e,n){rn(e),e.cfg=n;const t=yu(e,n);if(!t){se(e,n,"\u7F51\u9875\u58C1\u7EB8\uFF1A\u65E0\u53EF\u7528\u5BB9\u5668"),e.onError?.(new Error("\u7F51\u9875\u58C1\u7EB8\uFF1A\u65E0\u53EF\u7528\u5BB9\u5668"));return}const r=n.src??"";if(!r){se(e,n,"\u7F51\u9875\u58C1\u7EB8\uFF1A\u7F3A\u5C11 src"),e.onError?.(new Error("\u7F51\u9875\u58C1\u7EB8\uFF1A\u7F3A\u5C11 src"));return}ku(e);const o=n,i=o._webAudio===null||e.audioDisabled?null:o._webAudio??mu(),s=o._webMedia===null||e.mediaDisabled?null:o._webMedia??Lu(),a=f=>{se(e,n,`\u7F51\u9875\u58C1\u7EB8 shim \u6CE8\u5165\u5931\u8D25\uFF08${f}\uFF09\uFF0C\u9000\u56DE\u88F8 iframe`),po(e,n,t,r,{injected:!1}),bs(e,null),ys(e,null);let p=0;const d=y=>{e.iframe&&(p=requestAnimationFrame(d),!e.paused&&An(e,y))};p=requestAnimationFrame(d),(e.wallpaperDisposers??=[]).push(()=>cancelAnimationFrame(p))},c={last:0},u={driver:null},l=()=>{if(bs(e,i,c,u),ys(e,s),n.liveSystem&&i){const f={handle:null,dead:!1};(e.wallpaperDisposers??=[]).push(()=>{f.dead=!0,u.driver=null;try{f.handle?.dispose()}catch{}f.handle=null}),(async()=>{try{const p=await ps({origin:location.origin});if(f.dead){try{p.dispose()}catch{}return}f.handle=p;const d=p.status();d.audio==="mic"?(u.driver=bu(p),se(e,n,"liveSystem: \u7F51\u9875\u58C1\u7EB8\u97F3\u9891\u6539\u7528\u9EA6\u514B\u98CE")):se(e,n,`liveSystem: \u9EA6\u514B\u98CE\u4E0D\u53EF\u7528\uFF08${d.audio}\uFF09\uFF0C\u7F51\u9875\u58C1\u7EB8\u6CBF\u7528\u6A21\u62DF\u6E90`)}catch(p){se(e,n,`liveSystem: \u542F\u52A8\u5931\u8D25\uFF0C\u7F51\u9875\u58C1\u7EB8\u6CBF\u7528\u6A21\u62DF\u6E90 (${p?.message??p})`)}})()}};(async()=>{const f=await Uu(r),p=Du(f,e.liveUserProps);if(e.liveUserProps=Object.fromEntries(Object.entries(p).map(([d,y])=>[d,y.value])),Fu(r)){po(e,n,t,r,{injected:!0,frameClock:c}),l(),e.iframe?.addEventListener("load",()=>{let y=!1;qe(e,x=>{y=typeof x.__weSetPaused=="function"}),y||se(e,n,"\u7F51\u9875\u58C1\u7EB8\uFF1A\u540C\u6E90\u5165\u53E3\u672A\u68C0\u6D4B\u5230 WE shim\uFF08host \u672A\u6CE8\u5165\uFF1F\uFF09\uFF1BSpine \u7C7B\u58C1\u7EB8\u8BF7\u786E\u8BA4 /web/ HTML \u6539\u5199")},{once:!0});return}try{const d=await fetch(r,{credentials:"same-origin"});if(!d.ok){a(`HTTP ${d.status}`);return}const y=await d.text();if(su(y)){a("CSP \u963B\u6B62 inline script");return}const x=au(y,cu,{baseHref:iu(r),seedScript:vu(p,n.sceneFps,n.muted===!1?1:0)}),m=new Blob([x],{type:"text/html;charset=utf-8"}),M=URL.createObjectURL(m);po(e,n,t,M,{blobUrl:M,injected:!0,frameClock:c}),l()}catch(d){a(d instanceof Error?d.message:String(d))}})()}function Mr(e,n){const t=String(n.type??"").toLowerCase();n={...n,type:t},e.cfg=n,(t==="video"||t==="gif"||t==="image")&&n.src?Pl(e,n):t==="scene"&&(n.source||n.src)?ru(e,n):t==="web"&&n.src?Bu(e,n):e.onUnhandledType?.(n)}class Bt{x;y;z;constructor(n,t,r){this.x=Number(n)||0,this.y=Number(t)||0,this.z=Number(r)||0}add(n){return new Bt(this.x+n.x,this.y+n.y,this.z+n.z)}subtract(n){return new Bt(this.x-n.x,this.y-n.y,this.z-n.z)}multiply(n){return typeof n=="number"?new Bt(this.x*n,this.y*n,this.z*n):new Bt(this.x*n.x,this.y*n.y,this.z*n.z)}toString(){return`${this.x} ${this.y} ${this.z}`}}function gt(e,n,t){if(e instanceof Bt)return e;if(Array.isArray(e))return new Bt(e[0]??0,e[1]??0,e[2]??0);if(typeof e=="object"&&e!==null){const r=e;return new Bt(r.x??0,r.y??0,r.z??0)}return new Bt(e,n??0,t??0)}const Iu=[.35,.38,.45],Ou=[.12,.13,.17],$u=[.72,.76,.84],vs=[.95,.96,.98];function ju(e,n){if(!Array.isArray(e)||e.length===0)return{line:"",index:-1};let t=-1;for(let r=0;r<e.length;r++){const o=Number(e[r]?.[0]);if(Number.isFinite(o)&&o<=n)t=r;else break}return{line:t>=0?String(e[t][1]??""):"",index:t}}function xs(e){const n=Number(e.position)||0,t=Array.isArray(e.lyrics)?e.lyrics:[],{line:r,index:o}=ju(t,n),i=e.state!==void 0?e.state:e.playing===!1?2:e.playing?1:0;return{hasMedia:e.hasMedia??(e.title!=null||e.artist!=null||!!e.playing),state:i,title:String(e.title??""),artist:String(e.artist??""),album:String(e.album??""),albumArtist:String(e.albumArtist??e.artist??""),position:n,duration:Number(e.duration)||0,hasThumbnail:e.hasThumbnail??!1,primaryColor:gt(e.primaryColor??Iu),secondaryColor:gt(e.secondaryColor??Ou),tertiaryColor:gt(e.tertiaryColor??$u),textColor:gt(e.textColor??vs),highContrastColor:gt(e.highContrastColor??e.textColor??vs),trackIndex:Number(e.trackIndex)||0,lyrics:t,lyricLine:r,lyricIndex:o}}function zu(e={},n={}){let t={...e},r=xs(t);return{get snapshot(){return r},set(o){t={...t,...o},r=xs(t)},update(){},skipNext:n.skipNext,skipPrevious:n.skipPrevious,play:n.play,pause:n.pause,playPause:n.playPause}}function Wu(e){return e==="fit"?"contain":e==="fill"?"cover":e==="contain"||e==="stretch"?e:"cover"}function Vu(e){const n=e?.type;return typeof n=="string"&&n.toLowerCase()==="web"}const ho=new Set(["video","gif","image"]);function Hu(e){const n=e?.type;if(typeof n!="string")return null;const t=n.toLowerCase();return ho.has(t)?t:null}function mo(e){if(e instanceof HTMLCanvasElement)return e;const n=e.querySelector(":scope > canvas[data-webwallgl]");if(n instanceof HTMLCanvasElement)return n;const t=document.createElement("canvas");return t.setAttribute("data-webwallgl","1"),t.style.cssText="position:absolute;inset:0;width:100%;height:100%;display:block;",getComputedStyle(e).position==="static"&&(e.style.position="relative"),e.appendChild(t),t}async function ws(e,n){const t={fit:Wu(n.fit),renderDpr:n.renderDpr??1,sceneFps:n.fps??60,muted:(n.volume??0)<=0,loop:!0,canvas:e,source:n.source};let r=null;try{r=await n.source.project?.()??null}catch{r=null}if(Vu(r)){let a;try{a=(await n.source.webEntry?.())?.url}catch{a=void 0}if(!a&&n.source.key){const c=r&&typeof r.file=="string"&&String(r.file).trim().replace(/^\/+/,"")||"index.html";a=`${n.source.key.replace(/\/+$/,"")}/${c}`}if(!a)throw new Error("\u7F51\u9875\u58C1\u7EB8\uFF1A\u65E0\u6CD5\u89E3\u6790\u5165\u53E3 URL\uFF08\u9700\u8981 Source.webEntry \u6216 httpSource\uFF09");return{...t,type:"web",src:a,source:n.source}}const o=Hu(r);if(o){let a,c;try{const f=await n.source.mediaEntry?.();a=f?.url,c=f?.type}catch{a=void 0}if(!a&&n.source.key){const f=r&&typeof r.file=="string"?String(r.file).trim().replace(/^\/+/,""):"";f&&(a=`${n.source.key.replace(/\/+$/,"")}/${f}`)}if(!a)throw new Error(`\u5A92\u4F53\u58C1\u7EB8\uFF08${o}\uFF09\uFF1A\u65E0\u6CD5\u89E3\u6790\u8D44\u6E90 URL\uFF08\u9700\u8981 Source.mediaEntry \u6216 project.file + httpSource\uFF09`);const u=mo(e),l=ho.has(String(c).toLowerCase())?String(c).toLowerCase():o;return{...t,type:l,src:a,canvas:u,source:n.source}}if(!(typeof r?.type=="string"?String(r.type).trim():"")&&typeof n.source.mediaEntry=="function"){let a,c;try{const l=await n.source.mediaEntry();a=l?.url,c=l?.type}catch{a=void 0}const u=(ho.has(String(c).toLowerCase())?String(c).toLowerCase():null)??(a?lo(a):null);if(a&&u){const l=mo(e);return{...t,type:u,src:a,canvas:l,source:n.source}}}const s=mo(e);return{...t,type:"scene",canvas:s,source:n.source}}function Ms(e,n){const t=Ts(),r={ready:[],error:[],diagnostic:[]};let o={...n??{},source:null},i=e;const s=d=>{for(const y of r.error)try{y(d)}catch{}},a=d=>{t.onDiagnostic=(y,x)=>{try{d.onDiagnostic?.(y,x)}catch{}for(const m of r.diagnostic)try{m(y,x)}catch{}},t.onError=y=>{try{d.onError?.(y)}catch{}s(y)},t.onSceneInfo=y=>{t.info=y},"audio"in d&&c(d.audio??null),"media"in d&&(t.mediaSource=d.media??null,t.mediaDisabled=d.media===null)},c=d=>{if(t.audioDisabled=d===null,!d){t.audioBridge=null;return}t.audioBridge=()=>{try{const y=d.snapshot();return y&&y.left&&y.right?y:null}catch{return null}}},u=()=>new Promise(d=>{const y=t.onFirstFrame;t.onFirstFrame=()=>{t.onFirstFrame=void 0,y?.();const x=t.info??{width:0,height:0,layerCount:0,hasModels:!1,hasParticles:!1,hasText:!1};try{o.onReady?.(x)}catch{}for(const m of r.ready)try{m(x)}catch{}d()}}),l=()=>{let d=()=>{};return{promise:new Promise((x,m)=>{d=f.on("error",M=>m(M))}),off:d}},f={get canvas(){return i},pause(){t.paused=!0,t.sceneCtl?.pause()},resume(){t.paused=!1,Ao(t),t.sceneCtl?.resume()},get paused(){return!!t.paused},setFit(d){t.cfg.fit=d,Pr(t),t.webRelayout?.()},setFps(d){t.cfg.sceneFps=d,qe(t,y=>y.__weSetFps?.(d))},setVolume(d){const y=Math.max(0,Math.min(1,d));t.cfg.muted=y<=0,t.sceneAudio?.setVolume(y),qe(t,x=>x.__weSetVolume?.(y))},setRenderDpr(d){t.cfg.renderDpr=d,Mr(t,t.cfg)},setProperties(d){const y={};for(const[x,m]of Object.entries(d))y[x]={value:m};t.sceneCtl?.applyUserProperties(y)},getProperties(){return{...t.liveUserProps??{}}},setAudio(d){o={...o,audio:d},c(d),t.audioDisabled=!1},setMedia(d){o={...o,media:d},t.mediaSource=d??null,t.mediaDisabled=!1},get media(){const d=t.mediaCtl;if(d)return d;const y={hasMedia:!1,state:0,title:"",artist:"",album:"",albumArtist:"",position:0,duration:0,hasThumbnail:!1,primaryColor:gt(0,0,0),secondaryColor:gt(0,0,0),tertiaryColor:gt(0,0,0),textColor:gt(1,1,1),highContrastColor:gt(1,1,1),trackIndex:0,lyrics:[],lyricLine:"",lyricIndex:-1},x=()=>y;return{get snapshot(){return y},skipNext:x,skipPrevious:x,play:x,pause:x,playPause:x}},pushPointer(d,y,x){t.pointerCtl?.push({u:d,v:y,buttons:x})},pointerLeave(){t.pointerCtl?.leave()},async load(d){const y=o.source;if(y&&y!==d)try{y.dispose?.()}catch{}o={...o,source:d},a(o);const x=await ws(i,o);x.type!=="web"&&x.canvas instanceof HTMLCanvasElement&&(i=x.canvas),t.cfg=x,t.paused=!1,t.info=void 0,Pr(t),o.properties&&(t.liveUserProps={...o.properties});const m=u(),M=l();Mr(t,x);try{await Promise.race([m,M.promise])}finally{M.off()}},release(){rn(t)},restore(){Mr(t,t.cfg)},destroy(){Ss(t);try{o.source?.dispose?.()}catch{}t.onDiagnostic=void 0,t.onError=void 0,t.onFirstFrame=void 0,t.onSceneInfo=void 0,r.ready.length=0,r.error.length=0,r.diagnostic.length=0},get stats(){return Ps(t)},get info(){return t.info??null},on(d,y){const x=r[d];return x.push(y),()=>{const m=x.indexOf(y);m>=0&&x.splice(m,1)}}},p=async d=>{o=d,a(d);const y=await ws(e,d);y.type!=="web"&&y.canvas instanceof HTMLCanvasElement&&(i=y.canvas),t.cfg=y,t.paused=!1,t.info=void 0,Pr(t),d.properties&&Object.keys(d.properties).length&&(t.liveUserProps={...d.properties});const x=u(),m=l();Mr(t,t.cfg);try{await Promise.race([x,m.promise])}finally{m.off()}d.autoplay===!1&&f.pause(),(d.volume??0)>0&&f.setVolume(d.volume),d.properties&&Object.keys(d.properties).length&&f.setProperties(d.properties)};return f.__applyOptions=p,f}async function Xu(e,n){const t=Ms(e,n);return await t.__applyOptions(n),t}Je.bytesSource=Ul,Je.createMediaSource=zu,Je.createScene=Ms,Je.fileSource=Nl,Je.httpSource=is,Je.mediaColor=gt,Je.mediaSource=Dl,Je.mount=Xu,Je.sniffMediaType=lo,Object.defineProperty(Je,Symbol.toStringTag,{value:"Module"})});
|
|
2066
|
+
`;function kt(t,e){try{const n=t.iframe?.contentWindow;n&&e(n)}catch{}}function v1(t,e,n){const r=e.contentWindow;if(!r||r.requestAnimationFrame?.__weThrottled)return;const i=t.cfg.sceneFps||30;if(i>=60)return;const s=1e3/i;try{const a=r.requestAnimationFrame.bind(r),o=new Map;let c=0;r.requestAnimationFrame=u=>{const l=++c,f=r.setTimeout(()=>{o.delete(l),a(d=>{try{u(d)}catch{}})},s);return o.set(l,f),l},r.cancelAnimationFrame=u=>{const l=o.get(u);l!==void 0&&(r.clearTimeout(l),o.delete(u))}}catch{}}const k1=new Float32Array(128);function A1(t,e,n){const r=Math.min(64,e.length),i=Math.min(64,n.length);for(let s=0;s<r;s++)t[s]=Number(e[s])||0;for(let s=0;s<i;s++)t[64+s]=Number(n[s])||0;return t}const x1=1.8,T1=1.8,S1=30;function oh(t){const e=Number(t)||0;return e<=0?0:Math.min(1,Math.pow(e,T1)*x1)}function P1(){const t=Wd(),e=new Float32Array(64),n=new Float32Array(64);return{tick(r){t.update(r/1e3)},snapshot(){const r=t.snapshot,i=r.preL64,s=r.preR64;for(let a=0;a<64;a++)i&&s?(e[a]=oh(i[a]),n[a]=oh(s[a])):(e[a]=(Number(r.left64[a])||0)*.2,n[a]=(Number(r.right64[a])||0)*.2);return{left:e,right:n}}}}function _1(t){const e=new Float32Array(64),n=new Float32Array(64);return{snapshot(){const r=t.audioBridge?.(),i=r?.left,s=r?.right,a=i&&s?Math.min(64,i.length,s.length):0;for(let o=0;o<a;o++)e[o]=Math.max(0,Math.min(1,Number(i[o])||0)),n[o]=Math.max(0,Math.min(1,Number(s[o])||0));for(let o=a;o<64;o++)e[o]=0,n[o]=0;return{left:e,right:n}}}}function E1(t){const e=new Float32Array(64),n=new Float32Array(64);return{tick(){t.audio.pump()},snapshot(){const r=t.audio.snapshot;for(let i=0;i<64;i++)e[i]=Math.max(0,Math.min(1,Number(r.left64[i])||0)),n[i]=Math.max(0,Math.min(1,Number(r.right64[i])||0));return{left:e,right:n}}}}function C1(t,e){if(t.wrap)return t.wrap;const n=e.canvas;if(!n)return null;if(n instanceof HTMLCanvasElement){const r=n.parentElement;return r?(ce(t,e,"\u7F51\u9875\u58C1\u7EB8\u6302\u5728 canvas \u7236\u5BB9\u5668\u4E0A\uFF08canvas \u4E0D\u80FD\u6709\u5B50\u8282\u70B9\uFF1B\u66F4\u9002\u5408\u7A7A div\uFF09"),r):null}return n}function I1(t,e,n){const r=[];return e!=null&&Number.isFinite(e)&&r.push(`window.__weSetFps(${Number(e)});`),n!=null&&Number.isFinite(n)&&r.push(`window.__weSetVolume(${Math.max(0,Math.min(1,Number(n)))});`),t&&Object.keys(t).length&&r.push(`window.__weSeedProps(${JSON.stringify(t)});`),r.join(`
|
|
2067
|
+
`)}function M1(t,e,n){const r="position:absolute;border:none;background:transparent;",i=()=>{e.style.cssText=r+"inset:0;width:100%;height:100%;"};i();let s="";const a=()=>{if(!e.isConnected)return;let d=null;try{d=e.contentDocument}catch{return}if(!d)return;const h=n.clientWidth||window.innerWidth||0,p=n.clientHeight||window.innerHeight||0,m=xr(t.cfg.fit)==="cover";i();const g=m&&h>0&&p>0?U1(d):null,w=g?O1(h,p,g.contentAspect):null,y=w?`${Math.round(w.width)}x${Math.round(w.height)}`:"full";if(!w){s="full";return}e.style.cssText=r+`left:${w.left}px;top:${w.top}px;width:${w.width}px;height:${w.height}px;`,y!==s&&(s=y,ce(t,t.cfg,`\u7F51\u9875\u58C1\u7EB8\u9732\u5E95\u81EA\u9002\u914D\uFF1A\u89C6\u53E3\u6309\u5185\u5BB9\u6BD4\u4F8B\u6539\u4E3A ${Math.round(w.width)}\xD7${Math.round(w.height)}\uFF08cover \u5C45\u4E2D\u88C1\u5207\uFF09`))},o=()=>a();window.addEventListener("resize",o);let c;typeof ResizeObserver<"u"&&(c=new ResizeObserver(()=>a()),c.observe(n));const u=[],l=()=>{a();for(const d of[120,400,1200])u.push(window.setTimeout(a,d));try{const d=e.contentDocument;if(d)for(const h of d.querySelectorAll("video,img"))h.addEventListener("loadedmetadata",a,{once:!0}),h.addEventListener("load",a,{once:!0})}catch{}};e.addEventListener("load",l),t.webRelayout=a;const f=t.sceneCleanup;t.sceneCleanup=()=>{window.removeEventListener("resize",o),c?.disconnect();for(const d of u)clearTimeout(d);e.removeEventListener("load",l),t.webRelayout===a&&(t.webRelayout=void 0);try{f?.()}catch{}}}function B1(t,e,n,r,i){if(!Number.isFinite(t)||!Number.isFinite(e)||!(n.width>0)||!(n.height>0))return null;const s=r.width>0&&i.width>0?r.width/i.width:1,a=r.height>0&&i.height>0?r.height/i.height:1;return{x:(t*n.width-(r.left-n.left))/(s||1),y:(e*n.height-(r.top-n.top))/(a||1)}}function R1(t,e,n){const r=(i,s)=>{if(!e.isConnected)return null;const a=n.getBoundingClientRect(),o=e.getBoundingClientRect();return B1(Number(i),Number(s),{left:a.left,top:a.top,width:a.width||n.clientWidth||window.innerWidth||0,height:a.height||n.clientHeight||window.innerHeight||0},{left:o.left,top:o.top,width:o.width,height:o.height},{width:e.clientWidth,height:e.clientHeight})};t.pointerCtl={push(i){const s=r(i?.u,i?.v);s&&kt(t,a=>a.__wePushPointer?.(s.x,s.y,Number(i.buttons)||0,Number(i.mods)||0))},leave(){kt(t,i=>i.__wePointerLeave?.())},wheel(i){if(!e.isConnected)return;const s=i.u!==void 0&&i.v!==void 0?r(i.u,i.v):null;kt(t,a=>a.__wePushWheel?.(s?s.x:NaN,s?s.y:NaN,Number(i.dx)||0,Number(i.dy)||0,Number(i.mode)||0,Number(i.mods)||0))}}}function Vc(t,e,n,r,i){const s=document.createElement("iframe");s.setAttribute("sandbox","allow-scripts allow-same-origin"),s.style.cssText="position:absolute;inset:0;width:100%;height:100%;border:none;background:transparent;",!t.wrap&&getComputedStyle(n).position==="static"&&(n.style.position="relative"),s.src=r,n.appendChild(s),t.iframe=s,i.blobUrl&&(t.objectUrls??=[]).push(i.blobUrl),M1(t,s,n),i.injected&&R1(t,s,n);const a=c=>{if(c.source!==s.contentWindow)return;const u=c.data;if(!u||u.op!=="we-frame"||t.paused)return;const l=typeof u.t=="number"?u.t:performance.now();i.frameClock&&(i.frameClock.last=l),er(t,l)};window.addEventListener("message",a);const o=t.sceneCleanup;t.sceneCleanup=()=>{window.removeEventListener("message",a);try{o?.()}catch{}},s.addEventListener("load",()=>{try{const l=s.contentDocument;l&&window.__blockContextMenu?.(l),i.injected||v1(t,s,l)}catch{}kt(t,l=>{const f={};for(const[d,h]of Object.entries(t.liveUserProps??{}))f[d]={value:h};l.__weApplyProps?.(f),l.__weSetFps?.(t.cfg.sceneFps??60),l.__weSetVolume?.(t.cfg.muted===!1?1:0),t.paused&&l.__weSetPaused?.(!0)});try{t.onFirstFrame?.(),t.onFirstFrame=void 0}catch{}const c=n.clientWidth||window.innerWidth||1,u=n.clientHeight||window.innerHeight||1;try{t.onSceneInfo?.({width:c,height:u,layerCount:0,hasModels:!1,hasParticles:!1,hasText:!1})}catch{}})}const F1=.005,D1=.01,N1=.2,L1=6;function O1(t,e,n){if(!(t>0)||!(e>0)||!(n>0))return null;const r=t/e;if(Math.abs(r-n)<=F1)return null;if(r<n){const s=e*n;return{width:s,height:e,left:(t-s)/2,top:0}}const i=t/n;return{width:t,height:i,left:0,top:(e-i)/2}}function U1(t){const e=t.defaultView;if(!e)return null;const n=e.innerWidth,r=e.innerHeight;if(!(n>0)||!(r>0))return null;const i=[...t.querySelectorAll("video,img")];for(const s of i){const a=s.getBoundingClientRect();if(a.width<=0||a.height<=0||a.width<n*.98||Math.abs(a.left)>n*.02||a.top>r*.02||r-a.height<r*D1)continue;const o=s.videoWidth||s.naturalWidth||0,c=s.videoHeight||s.naturalHeight||0;if(!(o>0)||!(c>0))continue;const u=o/c;if(!(!Number.isFinite(u)||u<N1||u>L1))return{contentAspect:u}}return null}function Dr(t){if(!t)return"rgb(128,128,128)";const e=Math.round(Math.max(0,Math.min(1,Number(t.x)||0))*255),n=Math.round(Math.max(0,Math.min(1,Number(t.y)||0))*255),r=Math.round(Math.max(0,Math.min(1,Number(t.z)||0))*255);return`rgb(${e},${n},${r})`}function z1(t){const e=typeof t.thumbnail=="string"?t.thumbnail.trim():"";if(e)return e;try{const n=document.createElement("canvas");n.width=n.height=64;const r=n.getContext("2d");if(!r)return"";const i=t.primaryColor,s=t.secondaryColor,a=r.createLinearGradient(0,0,64,64);return a.addColorStop(0,Dr(i)),a.addColorStop(1,Dr(s)),r.fillStyle=a,r.fillRect(0,0,64,64),n.toDataURL("image/jpeg",.85)}catch{return""}}function H1(){return Se.createSimulatedMedia()}function V1(t,e,n){const r=Se.diffMediaEvents(e,n);for(const{name:i,event:s}of r)if(i==="mediaStatusChanged")kt(t,a=>a.__wePushMedia?.({op:"status",enabled:!!s.enabled}));else if(i==="mediaPropertiesChanged")kt(t,a=>a.__wePushMedia?.({op:"properties",title:s.title??"",artist:s.artist??"",album:s.album??"",albumArtist:s.albumArtist??""}));else if(i==="mediaThumbnailChanged"){const a=z1(n);kt(t,o=>o.__wePushMedia?.({op:"thumbnail",thumbnail:a,hasThumbnail:!!s.hasThumbnail||!!a,primaryColor:Dr(s.primaryColor),secondaryColor:Dr(s.secondaryColor),tertiaryColor:Dr(s.tertiaryColor),textColor:Dr(s.textColor),highContrastColor:Dr(s.highContrastColor)}))}else i==="mediaPlaybackChanged"?kt(t,a=>a.__wePushMedia?.({op:"playback",state:Number(s.state)||0})):i==="mediaTimelineChanged"&&kt(t,a=>a.__wePushMedia?.({op:"timeline",position:Number(s.position)||0,duration:Number(s.duration)||0}));return Se.cloneMediaSnapshot(n)}function ch(t,e,n,r={driver:null}){if(!e)return;const i=_1(t),s=()=>t.audioBridge?i:r.driver??e;let a=0,o=0;const c=l=>{if(a=requestAnimationFrame(c),t.paused||!t.iframe)return;const f=t.cfg.sceneFps||60,h=1e3/Math.min(Math.max(1,f),S1);if(!(l-o<h*.85)){o=l;try{const p=s();p.tick?.(l);const m=p.snapshot(),g=A1(k1,m.left,m.right);kt(t,w=>w.__wePushAudio?.(g)),n&&l-n.last>200&&er(t,l)}catch{}}};a=requestAnimationFrame(c);const u=t.sceneCleanup;t.sceneCleanup=()=>{cancelAnimationFrame(a);try{u?.()}catch{}}}function lh(t,e){if(!e)return;const n=()=>t.mediaSource??e;let r=0,i=null,s=0;const a=c=>{if(r=requestAnimationFrame(a),!(t.paused||!t.iframe)&&!(c-s<200)){s=c;try{const u=n();u.update?.(c/1e3),i=V1(t,i,u.snapshot)}catch{}}};r=requestAnimationFrame(a);const o=t.sceneCleanup;t.sceneCleanup=()=>{cancelAnimationFrame(r);try{o?.()}catch{}}}function W1(t){t.sceneCtl={pause(){t.paused=!0,kt(t,e=>e.__weSetPaused?.(!0))},resume(){t.paused=!1,kt(t,e=>e.__weSetPaused?.(!1))},applyUserProperties(e){const n={...t.liveUserProps??{}};for(const[r,i]of Object.entries(e??{})){const s=i&&typeof i=="object"&&"value"in i?i.value:i;n[r]=s}t.liveUserProps=n,kt(t,r=>r.__weApplyProps?.(e))}}}function j1(t){try{return new URL(t,location.href).origin===location.origin}catch{return!1}}function q1(t){const e=t?.general?.properties;if(!e||typeof e!="object")return{};const n={};for(const[r,i]of Object.entries(e)){if(!i||typeof i!="object"||typeof i.type!="string")continue;const s=i.value,a=i.type.toLowerCase();if(s==null){if(a==="file"||a==="directory"){n[r]={value:""};continue}if(!("value"in i))continue}n[r]={value:s}}return n}async function X1(t){try{const e=new URL("project.json",new URL(t,location.href)),n=await fetch(e.href,{credentials:"same-origin"});return n.ok?q1(await n.json()):{}}catch{return{}}}function G1(t,e){const n={...t};if(e)for(const[r,i]of Object.entries(e))n[r]={value:i};return n}function $1(t,e){Jn(t),t.cfg=e;const n=C1(t,e);if(!n){ce(t,e,"\u7F51\u9875\u58C1\u7EB8\uFF1A\u65E0\u53EF\u7528\u5BB9\u5668"),t.onError?.(new Error("\u7F51\u9875\u58C1\u7EB8\uFF1A\u65E0\u53EF\u7528\u5BB9\u5668"));return}const r=e.src??"";if(!r){ce(t,e,"\u7F51\u9875\u58C1\u7EB8\uFF1A\u7F3A\u5C11 src"),t.onError?.(new Error("\u7F51\u9875\u58C1\u7EB8\uFF1A\u7F3A\u5C11 src"));return}W1(t);const i=e,s=i._webAudio===null||t.audioDisabled?null:i._webAudio??P1(),a=i._webMedia===null||t.mediaDisabled?null:i._webMedia??H1(),o=f=>{ce(t,e,`\u7F51\u9875\u58C1\u7EB8 shim \u6CE8\u5165\u5931\u8D25\uFF08${f}\uFF09\uFF0C\u9000\u56DE\u88F8 iframe`),Vc(t,e,n,r,{injected:!1}),ch(t,null),lh(t,null);let d=0;const h=p=>{t.iframe&&(d=requestAnimationFrame(h),!t.paused&&er(t,p))};d=requestAnimationFrame(h),(t.wallpaperDisposers??=[]).push(()=>cancelAnimationFrame(d))},c={last:0},u={driver:null},l=()=>{if(ch(t,s,c,u),lh(t,a),e.liveSystem&&s){const f={handle:null,dead:!1};(t.wallpaperDisposers??=[]).push(()=>{f.dead=!0,u.driver=null;try{f.handle?.dispose()}catch{}f.handle=null}),(async()=>{try{const d=await ih({origin:location.origin});if(f.dead){try{d.dispose()}catch{}return}f.handle=d;const h=d.status();h.audio==="mic"?(u.driver=E1(d),ce(t,e,"liveSystem: \u7F51\u9875\u58C1\u7EB8\u97F3\u9891\u6539\u7528\u9EA6\u514B\u98CE")):ce(t,e,`liveSystem: \u9EA6\u514B\u98CE\u4E0D\u53EF\u7528\uFF08${h.audio}\uFF09\uFF0C\u7F51\u9875\u58C1\u7EB8\u6CBF\u7528\u6A21\u62DF\u6E90`)}catch(d){ce(t,e,`liveSystem: \u542F\u52A8\u5931\u8D25\uFF0C\u7F51\u9875\u58C1\u7EB8\u6CBF\u7528\u6A21\u62DF\u6E90 (${d?.message??d})`)}})()}};(async()=>{const f=await X1(r),d=G1(f,t.liveUserProps);if(t.liveUserProps=Object.fromEntries(Object.entries(d).map(([h,p])=>[h,p.value])),j1(r)){Vc(t,e,n,r,{injected:!0,frameClock:c}),l(),t.iframe?.addEventListener("load",()=>{let p=!1;kt(t,m=>{p=typeof m.__weSetPaused=="function"}),p||ce(t,e,"\u7F51\u9875\u58C1\u7EB8\uFF1A\u540C\u6E90\u5165\u53E3\u672A\u68C0\u6D4B\u5230 WE shim\uFF08host \u672A\u6CE8\u5165\uFF1F\uFF09\uFF1BSpine \u7C7B\u58C1\u7EB8\u8BF7\u786E\u8BA4 /web/ HTML \u6539\u5199")},{once:!0});return}try{const h=await fetch(r,{credentials:"same-origin"});if(!h.ok){o(`HTTP ${h.status}`);return}const p=await h.text();if(y1(p)){o("CSP \u963B\u6B62 inline script");return}const m=b1(p,w1,{baseHref:g1(r),seedScript:I1(d,e.sceneFps,e.muted===!1?1:0)}),g=new Blob([m],{type:"text/html;charset=utf-8"}),w=URL.createObjectURL(g);Vc(t,e,n,w,{blobUrl:w,injected:!0,frameClock:c}),l()}catch(h){o(h instanceof Error?h.message:String(h))}})()}function Wc(t,e){const n=String(e.type??"").toLowerCase();e={...e,type:n},t.cfg=e,(n==="video"||n==="gif"||n==="image")&&e.src?Db(t,e):n==="scene"&&(e.source||e.src)?m1(t,e):n==="web"&&e.src?$1(t,e):t.onUnhandledType?.(e)}class Xn{x;y;z;constructor(e,n,r){this.x=Number(e)||0,this.y=Number(n)||0,this.z=Number(r)||0}add(e){return new Xn(this.x+e.x,this.y+e.y,this.z+e.z)}subtract(e){return new Xn(this.x-e.x,this.y-e.y,this.z-e.z)}multiply(e){return typeof e=="number"?new Xn(this.x*e,this.y*e,this.z*e):new Xn(this.x*e.x,this.y*e.y,this.z*e.z)}toString(){return`${this.x} ${this.y} ${this.z}`}}function sn(t,e,n){if(t instanceof Xn)return t;if(Array.isArray(t))return new Xn(t[0]??0,t[1]??0,t[2]??0);if(typeof t=="object"&&t!==null){const r=t;return new Xn(r.x??0,r.y??0,r.z??0)}return new Xn(t,e??0,n??0)}const Q1=[.35,.38,.45],Y1=[.12,.13,.17],K1=[.72,.76,.84],uh=[.95,.96,.98];function Z1(t,e){if(!Array.isArray(t)||t.length===0)return{line:"",index:-1};let n=-1;for(let r=0;r<t.length;r++){const i=Number(t[r]?.[0]);if(Number.isFinite(i)&&i<=e)n=r;else break}return{line:n>=0?String(t[n][1]??""):"",index:n}}function fh(t){const e=Number(t.position)||0,n=Array.isArray(t.lyrics)?t.lyrics:[],{line:r,index:i}=Z1(n,e),s=t.state!==void 0?t.state:t.playing===!1?2:t.playing?1:0,a=t.thumbnail?String(t.thumbnail):"";return{hasMedia:t.hasMedia??(t.title!=null||t.artist!=null||!!t.playing),state:s,title:String(t.title??""),artist:String(t.artist??""),album:String(t.album??""),albumArtist:String(t.albumArtist??t.artist??""),position:e,duration:Number(t.duration)||0,hasThumbnail:t.hasThumbnail??!!a,...a?{thumbnail:a}:{},primaryColor:sn(t.primaryColor??Q1),secondaryColor:sn(t.secondaryColor??Y1),tertiaryColor:sn(t.tertiaryColor??K1),textColor:sn(t.textColor??uh),highContrastColor:sn(t.highContrastColor??t.textColor??uh),trackIndex:Number(t.trackIndex)||0,lyrics:n,lyricLine:r,lyricIndex:i}}function J1(t={},e={}){let n={...t},r=fh(n);return{get snapshot(){return r},set(i){n={...n,...i},r=fh(n)},update(){},skipNext:e.skipNext,skipPrevious:e.skipPrevious,play:e.play,pause:e.pause,playPause:e.playPause}}function ew(t){return t==="fit"?"contain":t==="fill"?"cover":t==="contain"||t==="stretch"?t:"cover"}function tw(t){const e=t?.type;return typeof e=="string"&&e.toLowerCase()==="web"}const jc=new Set(["video","gif","image"]);function nw(t){const e=t?.type;if(typeof e!="string")return null;const n=e.toLowerCase();return jc.has(n)?n:null}function Ca(t,e=!0){if(t instanceof HTMLCanvasElement)return t;const n=t.querySelector(":scope > canvas[data-webwallgl]");if(n instanceof HTMLCanvasElement){if(e||n.getAttribute("data-webwallgl-gl")!=="1")return n;n.remove()}const r=document.createElement("canvas");return r.setAttribute("data-webwallgl","1"),r.style.cssText="position:absolute;inset:0;width:100%;height:100%;display:block;",getComputedStyle(t).position==="static"&&(t.style.position="relative"),t.appendChild(r),r}async function dh(t,e){const n={fit:ew(e.fit),renderDpr:e.renderDpr??1,sceneFps:e.fps??60,muted:(e.volume??0)<=0,loop:!0,canvas:t,source:e.source};let r=null;try{r=await e.source.project?.()??null}catch{r=null}if(tw(r)){let o;try{o=(await e.source.webEntry?.())?.url}catch{o=void 0}if(!o&&e.source.key){const c=r&&typeof r.file=="string"&&String(r.file).trim().replace(/^\/+/,"")||"index.html";o=`${e.source.key.replace(/\/+$/,"")}/${c}`}if(!o)throw new Error("\u7F51\u9875\u58C1\u7EB8\uFF1A\u65E0\u6CD5\u89E3\u6790\u5165\u53E3 URL\uFF08\u9700\u8981 Source.webEntry \u6216 httpSource\uFF09");return{...n,type:"web",src:o,source:e.source}}const i=nw(r);if(i){let o,c;try{const f=await e.source.mediaEntry?.();o=f?.url,c=f?.type}catch{o=void 0}if(!o&&e.source.key){const f=r&&typeof r.file=="string"?String(r.file).trim().replace(/^\/+/,""):"";f&&(o=`${e.source.key.replace(/\/+$/,"")}/${f}`)}if(!o)throw new Error(`\u5A92\u4F53\u58C1\u7EB8\uFF08${i}\uFF09\uFF1A\u65E0\u6CD5\u89E3\u6790\u8D44\u6E90 URL\uFF08\u9700\u8981 Source.mediaEntry \u6216 project.file + httpSource\uFF09`);const u=jc.has(String(c).toLowerCase())?String(c).toLowerCase():i,l=u==="video"?t:Ca(t);return{...n,type:u,src:o,canvas:l,source:e.source}}if(!(typeof r?.type=="string"?String(r.type).trim():"")&&typeof e.source.mediaEntry=="function"){let o,c;try{const l=await e.source.mediaEntry();o=l?.url,c=l?.type}catch{o=void 0}const u=(jc.has(String(c).toLowerCase())?String(c).toLowerCase():null)??(o?zc(o):null);if(o&&u){const l=u==="video"?t:Ca(t);return{...n,type:u,src:o,canvas:l,source:e.source}}}const a=Ca(t);return{...n,type:"scene",canvas:a,source:e.source}}function hh(t,e){const n=_h(),r={ready:[],error:[],diagnostic:[]};let i={...e??{},source:null},s=t;const a=p=>{for(const m of r.error)try{m(p)}catch{}},o=p=>{n.onDiagnostic=(m,g)=>{try{p.onDiagnostic?.(m,g)}catch{}for(const w of r.diagnostic)try{w(m,g)}catch{}},n.onError=m=>{try{p.onError?.(m)}catch{}a(m)},n.onSceneInfo=m=>{n.info=m},"audio"in p&&c(p.audio??null),"media"in p&&(n.mediaSource=p.media??null,n.mediaDisabled=p.media===null)},c=p=>{if(n.audioDisabled=p===null,!p){n.audioBridge=null;return}n.audioBridge=()=>{try{const m=p.snapshot();return m&&m.left&&m.right?m:null}catch{return null}}},u=()=>new Promise(p=>{const m=n.onFirstFrame;n.onFirstFrame=()=>{n.onFirstFrame=void 0,m?.();const g=n.info??{width:0,height:0,layerCount:0,hasModels:!1,hasParticles:!1,hasText:!1};try{i.onReady?.(g)}catch{}for(const w of r.ready)try{w(g)}catch{}p()}}),l=()=>{let p=()=>{};return{promise:new Promise((g,w)=>{p=d.on("error",y=>w(y))}),off:p}},f=()=>{if(n.cfg.type!=="web"&&n.cfg.type!=="video"){if(Jn(n),t instanceof HTMLCanvasElement){a(new Error("\u91CD\u6302\u5931\u8D25\uFF1A\u8C03\u7528\u65B9\u76F4\u63A5\u4F20\u5165\u4E86 canvas\uFF0C\u5176 WebGL \u4E0A\u4E0B\u6587\u5DF2\u5728\u5378\u8F7D\u65F6\u5F52\u8FD8\u4E14\u65E0\u6CD5\u590D\u6D3B\uFF08loseContext \u540E\u540C\u4E00 canvas \u62FF\u4E0D\u56DE\u53EF\u7528\u4E0A\u4E0B\u6587\uFF09\uFF0C\u800C\u5E93\u4E0D\u80FD\u66FF\u8C03\u7528\u65B9\u66FF\u6362 DOM\u3002\u8BF7\u6539\u4F20\u4E00\u4E2A\u7A7A\u5BB9\u5668\u8BA9\u5E93\u81EA\u5EFA\u753B\u5E03\uFF0C\u6216\u91CD\u65B0\u8C03\u7528 mount()\u3002"));return}const m=Ca(t,!1);m!==n.cfg.canvas&&(n.cfg={...n.cfg,canvas:m},s=m)}Wc(n,n.cfg)},d={get canvas(){return s},pause(){n.paused=!0,n.sceneCtl?.pause();for(const p of n.videoPairs??[])p.pause();n.videoPairs?.length||n.video?.pause()},resume(){if(n.paused=!1,Jc(n),n.sceneCtl?.resume(),n.videoPairs?.length)for(const p of n.videoPairs)p.resume();else n.video&&n.video.play().catch(()=>{})},get paused(){return!!n.paused},setFit(p){n.cfg.fit=p,Va(n),n.webRelayout?.();const m=Ha(p),g=w=>{w.style.objectFit=m.objectFit,w.style.background=m.background,w.style.objectPosition="50% 50%"};for(const w of n.videoPairs??[])for(const y of[w.active,w.standby])y.isConnected&&g(y);!n.videoPairs?.length&&n.video?.isConnected&&g(n.video)},setFps(p){n.cfg.sceneFps=p,kt(n,m=>m.__weSetFps?.(p))},setVolume(p){const m=Math.max(0,Math.min(1,p));if(n.cfg.muted=m<=0,n.sceneAudio?.setVolume(m),kt(n,g=>g.__weSetVolume?.(m)),n.videoPairs?.length)for(const g of n.videoPairs)g.setVolume(m);else n.video&&(n.video.volume=m,n.video.muted=m<=0);m<=0&&n.webcodecsPreferred&&n.cfg.type==="video"&&f()},setRenderDpr(p){n.cfg.renderDpr=p,f()},setProperties(p){const m={};for(const[g,w]of Object.entries(p))m[g]={value:w};n.sceneCtl?.applyUserProperties(m)},getProperties(){return{...n.liveUserProps??{}}},setAudio(p){i={...i,audio:p},c(p),n.audioDisabled=!1},setMedia(p){i={...i,media:p},n.mediaSource=p??null,n.mediaDisabled=!1},get media(){const p=n.mediaCtl;if(p)return p;const m={hasMedia:!1,state:0,title:"",artist:"",album:"",albumArtist:"",position:0,duration:0,hasThumbnail:!1,primaryColor:sn(0,0,0),secondaryColor:sn(0,0,0),tertiaryColor:sn(0,0,0),textColor:sn(1,1,1),highContrastColor:sn(1,1,1),trackIndex:0,lyrics:[],lyricLine:"",lyricIndex:-1},g=()=>m;return{get snapshot(){return m},skipNext:g,skipPrevious:g,play:g,pause:g,playPause:g}},pushPointer(p,m,g,w){n.pointerCtl?.push({u:p,v:m,buttons:g,mods:w})},pointerLeave(){n.pointerCtl?.leave()},pushWheel(p,m,g,w){n.pointerCtl?.wheel?.({dx:p,dy:m,mode:g,mods:w})},async load(p){const m=i.source;if(m&&m!==p)try{m.dispose?.()}catch{}i={...i,source:p},o(i);const g=await dh(s,i);g.type!=="web"&&g.canvas instanceof HTMLCanvasElement&&(s=g.canvas),n.cfg=g,n.paused=!1,n.info=void 0,Va(n),i.properties&&(n.liveUserProps={...i.properties});const w=u(),y=l();Wc(n,g);try{await Promise.race([w,y.promise])}finally{y.off()}},release(){Jn(n)},restore(){f()},destroy(p){Eh(n),p?.releasePkgCache&&d1(n.cfg.source?.key??i.source?.key);try{i.source?.dispose?.()}catch{}n.onDiagnostic=void 0,n.onError=void 0,n.onFirstFrame=void 0,n.onSceneInfo=void 0,r.ready.length=0,r.error.length=0,r.diagnostic.length=0},get stats(){return Ih(n)},get info(){return n.info??null},on(p,m){const g=r[p];return g.push(m),()=>{const w=g.indexOf(m);w>=0&&g.splice(w,1)}}},h=async p=>{i=p,o(p);const m=await dh(t,p);m.type!=="web"&&m.canvas instanceof HTMLCanvasElement&&(s=m.canvas),n.cfg=m,n.paused=!1,n.info=void 0,Va(n),p.properties&&Object.keys(p.properties).length&&(n.liveUserProps={...p.properties});const g=u(),w=l();Wc(n,n.cfg);try{await Promise.race([g,w.promise])}finally{w.off()}p.autoplay===!1&&d.pause(),(p.volume??0)>0&&d.setVolume(p.volume),p.properties&&Object.keys(p.properties).length&&d.setProperties(p.properties)};return d.__applyOptions=h,d}async function rw(t,e){const n=hh(t,e);return await n.__applyOptions(e),n}It.bytesSource=jb,It.createMediaSource=J1,It.createScene=hh,It.fileSource=Wb,It.httpSource=Zd,It.mediaColor=sn,It.mediaSource=qb,It.mount=rw,It.sniffMediaType=zc,Object.defineProperty(It,Symbol.toStringTag,{value:"Module"})});
|
|
1719
2068
|
|
|
1720
2069
|
//# sourceMappingURL=webwallgl.global.min.js.map
|