webwallgl 1.3.5 → 1.4.1
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 +26 -84
- package/README.md +26 -84
- package/package.json +1 -1
- package/types.d.ts +132 -5
- package/webwallgl.d.ts +58 -2
- package/webwallgl.global.js +40500 -10454
- package/webwallgl.global.js.map +1 -1
- package/webwallgl.global.min.js +707 -221
- package/webwallgl.global.min.js.map +1 -1
- package/webwallgl.min.mjs +707 -221
- package/webwallgl.min.mjs.map +1 -1
- package/webwallgl.mjs +40499 -10454
- package/webwallgl.mjs.map +1 -1
package/webwallgl.min.mjs
CHANGED
|
@@ -1,26 +1,316 @@
|
|
|
1
|
-
function rr(e,n){const t=n?.renderDpr??e.cfg?.renderDpr??1;return Math.min(window.devicePixelRatio||1,t)}function pn(e){return e==="fit"?"contain":e==="fill"?"cover":e==="contain"||e==="stretch"?e:"cover"}function _o(e){const n=pn(e);return n==="contain"?{objectFit:"contain",background:"rgba(10,12,16,0.85)"}:n==="stretch"?{objectFit:"fill",background:"transparent"}:{objectFit:"cover",background:"transparent"}}function Es(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 on(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,Fs(),To(e)}function Ps(e){try{on(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 Cs=new TextDecoder,xt=e=>Cs.decode(e).replace(/^\uFEFF/,""),Ao=500;function Fn(e,n){const t=e.frameMeter.stamps;t.push(n),e.frameMeter.last=n;const r=n-Ao;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 To(e){e.frameMeter.stamps.length=0,e.frameMeter.last=0,e.frameMeter.fps=0}function Ls(e){return!e.frameMeter.last||e.paused?{fps:0,running:!1}:performance.now()-e.frameMeter.last>Math.max(Ao,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 Fr(e){e.coverAlign.x=e.coverAlign.y=e.coverAlign.tx=e.coverAlign.ty=.5,Rs(e)}function Rs(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 ks=["__scene","__sceneLayers","__textures","__objScripts","__textWidgets","__mediaHooks","__mediaControl","__mediaStats","__mediaSet","__system","__liveSystem","__audioStats","__audioMute","__particleStats","__particleToggle","__pointerStats","__compositeStats","__compositeEnable"];function Fs(){const e=window;for(const n of ks)n in e&&delete e[n]}function So(e,n,t){const r=rr(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 Ns(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=Eo(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=Ds(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 Nr(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 Us(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 Eo(e,n,t){let r="";for(let o=n;o<n+t;o++)r+=String.fromCharCode(e[o]);return r}function Ds(e,n,t){try{return new TextDecoder("utf-8",{fatal:!0}).decode(e.subarray(n,n+t))}catch{return Eo(e,n,t)}}const Bs=Object.freeze(Object.defineProperty({__proto__:null,getEntry:Nr,parsePkg:Ns,verifyLayout:Us},Symbol.toStringTag,{value:"Module"})),Ur={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"},Yt={UNKNOWN:-1,JPEG:2,PNG:13,GIF:25,WEBP:35,MP4:35};function Is(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===Yt.PNG)return{width:t.width,height:t.height,png:t.data};if(e.freeImageFormat!==Yt.UNKNOWN)return{width:t.width,height:t.height,image:t.data,fif:e.freeImageFormat};const r=Dr(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:Po(r,t.width,t.height,e.width,e.height)}:{width:t.width,height:t.height,rgba:r}}function Os(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!==Yt.UNKNOWN){t.push({width:r.width,height:r.height,image:r.data,fif:e.freeImageFormat});continue}const o=Dr(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:Po(t[0].rgba,t[0].width,t[0].height,e.width,e.height)}),t}function Po(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 Dr(e,n,t,r){switch(e){case 0:return $s(n,t,r);case 1:return js(n,t,r);case 2:return zs(n,t,r);case 4:return Gs(n,t,r);case 6:return Xs(n,t,r);case 7:return Hs(n,t,r);case 8:return Vs(n,t,r);case 9:return Ws(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: "+(Ur[e]||e))}}function $s(e,n,t){return new Uint8Array(e.buffer,e.byteOffset,n*t*4).slice()}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*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 zs(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 Vs(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 Ws(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 Hs(e,n,t){return Br(e,n,t,!0,0)}function Xs(e,n,t){return Br(e,n,t,!1,3)}function Gs(e,n,t){return Br(e,n,t,!1,5)}function Br(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=Ys(a,r),p=qs(a,r),d=o===3?Zs(a):o===5?Ks(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 Co(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 Ys(e,n){const t=n?0:8,r=Co(e,t),o=Co(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 qs(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 Zs(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 Ks(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 Lo(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 Oe(e,n){return(e[n]|e[n+1]<<8|e[n+2]<<16|e[n+3]<<24)>>>0}function Ro(e,n){return Oe(e,n)|0}const Nn=new DataView(new ArrayBuffer(4));function qt(e,n){return Nn.setUint8(0,e[n]),Nn.setUint8(1,e[n+1]),Nn.setUint8(2,e[n+2]),Nn.setUint8(3,e[n+3]),Nn.getFloat32(0,!0)}function Qs(e){let n=0;const t=or(e,n,9);if(n+=9,t!=="TEXV0005\0")throw new Error("\u4E0D\u662F .tex \u6587\u4EF6: "+t);const r=or(e,n,9);if(n+=9,r!=="TEXI0001\0")throw new Error("\u672A\u77E5 TEXI \u5B50\u5BB9\u5668: "+r);const o=Oe(e,n);n+=4;const i=Oe(e,n);n+=4;const s=Oe(e,n);n+=4;const a=Oe(e,n);n+=4;const c=Oe(e,n);n+=4;const u=Oe(e,n);n+=4,n+=4;const l=or(e,n,9);n+=9;const f=Oe(e,n);n+=4;let p=Yt.UNKNOWN,d=0;if(l==="TEXB0004\0"){p=Oe(e,n)|0,n+=4;const v=Oe(e,n);n+=4,p===Yt.UNKNOWN&&v===1&&(p=Yt.MP4),d=v===1?4:3}else if(l==="TEXB0003\0")p=Oe(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===Yt.MP4,x=[];for(let v=0;v<f;v++){const A=Oe(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=Oe(e,n);n+=4;const N=Oe(e,n);n+=4;let j=0,H=0;d>=2&&(j=Oe(e,n),n+=4,H=Ro(e,n),n+=4);const K=Ro(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 W=O;j===1&&(W=Lo(O,H)),_.push({width:L,height:N,compression:j,data:W})}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=or(e,n,9);if(v.indexOf("TEXS")===0){let A=n+9;const _=Oe(e,A);A+=4;let R=0,L=0;v==="TEXS0003\0"&&(R=Oe(e,A),A+=4,L=Oe(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 W=A+O*j;if(W+32>e.length)break;const X=qt(e,W+8),ie=qt(e,W+12),J=qt(e,W+16),Z=qt(e,W+20),te=qt(e,W+24),le=qt(e,W+28);H.push({imageId:qt(e,W)|0,duration:qt(e,W+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 W=[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(...W)>=-1&&Math.max(...W)<=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:Ur[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 or(e,n,t){let r="";for(let o=n;o<n+t;o++)r+=String.fromCharCode(e[o]);return r}const Js=Object.freeze(Object.defineProperty({__proto__:null,FIF:Yt,TEXTURE_FORMATS:Ur,decodeMip0:Is,decodeMips:Os,decodePixels:Dr,lz4Decompress:Lo,parseTex:Qs},Symbol.toStringTag,{value:"Module"}));function ko(e,n){if(!e||typeof n!="string")return null;const t=e[n];return t&&typeof t=="object"?t:null}function Ir(e){return typeof e=="string"?e:e&&typeof e=="object"&&typeof e.name=="string"?e.name:null}function ea(e,n){return ir(e)&&ir(n)?Number(e)===Number(n):String(e)===String(n)}function Or(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 ta(e){switch(e.type){case"bool":return"bool";case"slider":return"num";case"color":return"num";case"textinput":return"text";default:return Or(e.value)}}function Fo(e,n){if(e===null||typeof e!="object")return e;if(e.user&&typeof e.user=="object"&&typeof e.user.name=="string"){const r=ko(n,e.user.name);if(!r||r.value===void 0||r.value===null)return e.value;const o=r.type==="combo"?$r(r.value,r.options):r.value;return ea(o,e.user.condition)}if(typeof e.user!="string")return e;const t=ko(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(Or(e.value)==="bool"&&t.type==="slider"){const r=Number(t.value);return Number.isFinite(r)?r!==0:e.value}return Or(e.value)===ta(t)?t.value:e.value}function hn(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]=hn(e[r],n,t+1);return e}if(Ir(e.user)){let r=Fo(e,n);for(let o=0;o<8&&r!==null&&typeof r=="object"&&Ir(r.user);o++)r=Fo(r,n);return e.value=hn(r,n,t+1),e}for(const r of Object.keys(e))e[r]=hn(e[r],n,t+1);return e}function na(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 ir(e){return typeof e=="number"?Number.isInteger(e):typeof e=="string"&&/^-?\d+$/.test(e.trim())}function $r(e,n){const t=na(n);return!(t.length>0?t.every(ir):ir(e))||typeof e=="number"&&Number.isFinite(e)?e:typeof e=="string"&&/^-?\d+$/.test(e.trim())?Number(e):e}function ra(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"?$r(r.value,r.options):r.value);return n}function Ct(e){return e&&typeof e=="object"?Ir(e.user):null}function oa(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"?$r(u.value,u.options):u.value;i[s]=l,r[s]=l}else i[s]=c,r[s]=c}return r}function mn(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 Un(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 sr(e){return e==null?[1,1,1]:typeof e=="string"?mn(e):typeof e=="object"&&e!==null?mn(e.value):[1,1,1]}function lt(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 jr(e){return e?!e.image&&!e.model&&!e.particle&&e.text==null&&!e.size:!1}function zr(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 ia(e,n){const t=n&&n.general&&n.general.properties||{},r=e.objects||[];hn(r,t,0),hn(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:mn(m.origin||"0 0 0"),scale:mn(m.scale||"1 1 1"),angles:mn(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)&&jr(_)),j=zr(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=>lt(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=Un(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:lt(m.startsilent,!1),maxtime:ft(m.maxtime,0),mintime:ft(m.mintime,0),spatialization:lt(m.spatialization,!1),muteineditor:lt(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:sr(m.color),textAnchor:typeof m.anchor=="string"&&m.anchor!=="none"?m.anchor:"center",textMaxwidth:ft(m.maxwidth,0),textMaxrows:ft(m.maxrows,0),textLimitwidth:lt(m.limitwidth,!1),textLimitrows:lt(m.limitrows,!1),textLimituseellipsis:lt(m.limituseellipsis,!1),textHAlign:m.horizontalalign||"center",textVAlign:m.verticalalign||"center",textSpacing:m.spacing?Un(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:lt(m.opaquebackground,!1),textBackgroundcolor:sr(m.backgroundcolor),textBackgroundbrightness:ft(m.backgroundbrightness,1),textCastshadow:lt(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:lt(_.visible,!0),additive:lt(_.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:jr(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:sr(m.color),alpha:ft(m.alpha,1),brightness:ft(m.brightness,1),copybackground:!!m.copybackground,colorBlendMode:m.colorBlendMode||0,parallaxDepth:m.parallaxDepth!==void 0?Un(m.parallaxDepth):null,effects:(m.effects||[]).map(_=>({file:_.file||"",name:typeof _.name=="string"?_.name:"",visible:lt(_.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 sa(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 aa(e,n){!e||!n||typeof n!="object"||e.isContainer||n.solidlayer===!0&&(e.solid=!0)}function ca(e){return!e||typeof e.material!="string"?null:{materialPath:e.material,autosize:!!e.autosize,cropoffset:e.cropoffset?Un(e.cropoffset):null}}function la(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=zr({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 ua(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 fa=Object.freeze(Object.defineProperty({__proto__:null,applySolidFromModel:aa,collectTransformDirty:ua,composeChildTransform:zr,isRenderInert:jr,parseBool:lt,parseColor:sr,parseNum:ft,parseScene:ia,parseVec2:Un,parseVec3:mn,recomposeWorld:la,recomputeLayerVisibility:sa,resolveMaterial:ca},Symbol.toStringTag,{value:"Module"}));function da(e,n,t){const r=Nr(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=Nr(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 pa={"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 No(e){if(!e||typeof e!="string")return!0;const n=e.toLowerCase();return n==="generic"||n==="sprite"||n==="flat"||n.startsWith("genericimage")}function ha(e,n){return!e||!n||!n.shader||No(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 ma={"materials/util/solidlayer.json":{passes:[{shader:"flat",blending:"translucent",cullmode:"nocull",depthtest:"disabled",depthwrite:"disabled",textures:[],combos:{}}]}},ga=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_MATERIALS:ma,BUILTIN_MODELS:pa,attachLayerMaterialEffect:ha,isBuiltinAlbedoShader:No,resolveEffectChain:da},Symbol.toStringTag,{value:"Module"}));function gn(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function Lt(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 bn(e,n,t,r,o,i){const s=gn();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 yn(e,n,t,r){return Lt(e,new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,n,t,r,1]))}function Uo(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 Dn(e,n,t,r){return Lt(e,new Float32Array([n,0,0,0,0,t,0,0,0,0,r,0,0,0,0,1]))}function Do(e,n){const t=Math.cos(n),r=Math.sin(n);return Lt(e,new Float32Array([t,r,0,0,-r,t,0,0,0,0,1,0,0,0,0,1]))}function ba(e,n){const t=Math.cos(n),r=Math.sin(n);return Lt(e,new Float32Array([1,0,0,0,0,t,r,0,0,-r,t,0,0,0,0,1]))}function ya(e,n){const t=Math.cos(n),r=Math.sin(n);return Lt(e,new Float32Array([t,0,-r,0,0,1,0,0,r,0,t,0,0,0,0,1]))}function va(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 ar(e,n){const t=e&&typeof e=="object"?e.value:e;return typeof t=="number"&&Number.isFinite(t)?t:n}function xa(e){const n=e&&e.general;return!n||n.orthogonalprojection?!1:ar(n.fov,0)>0}function wa(e,n){return n&&n.perspective&&e&&e.isSkybox&&n.eye?n.eye:e.origin}function Ma(e,n,t){const r=Io([e[0]-n[0],e[1]-n[1],e[2]-n[2]]),o=Io(Oo(t,r)),i=Oo(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 _a(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 Aa=[[16,9],[16,10],[21,9],[32,9]];function Ta(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 Aa){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 Vr(e,n,t,r,o,i,s){const a=Bo(i),c=Bo(s);if(e==="cover"){const u=Ta(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 Sa(e,n,t,r,o,i){const s=e.general,a=e.camera,c=a&&a.eye?Wr(a.eye):[0,0,0],u=a&&a.center?Wr(a.center):[0,0,-1],l=a&&a.up?Wr(a.up):[0,1,0];if(xa(e)){const g=t>0?n/t:1.7777777777777777,v=ar(s.fov,50),A=Math.max(ar(s.nearz,.01),1e-4),_=Math.max(ar(s.farz,1e4),A+1),R=Ma(c,u,l),L=va(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=gn(),p=s&&s.orthogonalprojection&&s.orthogonalprojection.width||n,d=s&&s.orthogonalprojection&&s.orthogonalprojection.height||t,y=Vr(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=bn(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 Bo(e){const n=Number(e);return Number.isFinite(n)?n<0?0:n>1?1:n:.5}function Wr(e){return String(e).trim().split(/\s+/).map(Number)}function Io(e){const n=Math.hypot(e[0],e[1],e[2])||1;return[e[0]/n,e[1]/n,e[2]/n]}function Oo(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 vn(e){const n=Number(e);return Number.isFinite(n)?n*.5:0}function Ea(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 Pa(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=It(f);let d=t.body;t.args.forEach((y,x)=>{const m=p[x]!==void 0?p[x].trim():"";d=Bn(d,y,m)}),r>0&&(d=$o(d,r-1)),o.push("("+d+")"),i=l+1}return o.join("")}function Bn(e,n,t){return e.replace(new RegExp("\\b"+n.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","g"),t)}function It(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 $o(e,n){for(let t=0;t<12;t++){const{defs:r,fns:o}=Ea(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=Bn(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=Pa(f,p,d,n),c=!0)}i[u]=f}if(e=i.join(`
|
|
3
|
-
`),!c)break}return e}function jo(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 zo(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(In(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(Vo(zo(d),n,t)):i.push("// [include \u7F3A\u5931: "+p+"]")}continue}if(l.startsWith("#define")){if(In(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")){In(s)&&i.push(u);continue}if(l.startsWith("#ifdef")||l.startsWith("#ifndef")||l.startsWith("#if")){const f=In(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=!!jo(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=!!jo(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("#")||In(s)&&i.push(u)}return i.join(`
|
|
8
|
-
`)
|
|
9
|
-
`))break}for(;
|
|
10
|
-
`||W===")")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=ze(l,v,A=>{const R=It(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=ze(l,"pow",v=>{const A=It(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=ze(l,h,g=>h+"("+g.replace(/(?<![A-Za-z0-9_.])(\d+)(?![.\d])/g,"$1.0")+")");l=ze(l,"clamp",h=>{const g=It(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=ze(l,"smoothstep",h=>{const g=It(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 W=N.indexOf("(");W<N.length;W++)if(N[W]==="(")O++;else if(N[W]===")"&&(O--,O===0))return W===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 W=0;const X=O[0].length-1;let ie=-1;for(let te=X;te<K.length;te++)if(K[te]==="(")W++;else if(K[te]===")"&&(W--,W===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,W,X)=>{const ie=h.get(W);if(!ie||A.has(W))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(W),O+W+" = vec"+ie+"("+J+");")}),H.size>0){const K=[...H].sort((O,W)=>W.length-O.length).join("|");l=l.replace(new RegExp(`\\b([A-Za-z_]\\w*)\\s*([*/])\\s*(${K})\\b`,"g"),(O,W,X,ie)=>h.has(W)?O:`${W} ${X} ${ie}.x`),l=l.replace(new RegExp(`\\b(${K})\\s*([*/])\\s*([A-Za-z_]\\w*)\\b`,"g"),(O,W,X,ie)=>h.has(ie)?O:`${W}.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=Ho(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=Ho(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=cr(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=cr(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=ze(l,"mix",(h,g)=>{const v=It(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 W=new RegExp("\\b(vec([234])|float)\\s+"+H+"\\b","g");let X=0,ie;for(;(ie=W.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=cr(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,W)=>{const X=H.get(W);return X&&X>N?"return "+W+"."+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=ze(l,"mul",h=>{const g=It(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=ze(l,"atan2",h=>"atan("+h+")"),l=ze(l,"fmod",h=>{const g=It(h);if(g.length!==2)return"mod("+h+")";const v=g[0].trim(),A=g[1].trim();return"(("+v+") - ("+A+") * trunc(("+v+") / ("+A+")))"}),l=ze(l,"ddx",h=>"dFdx("+h+")"),l=ze(l,"ddy",h=>"dFdy("+h+")"),l=ze(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,W)=>{const X=v.get(O);return!X||R[X]<=R[H]?N:(L.set(O,R[H]),j+X+K+O+W)}),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 Nr(){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}function Wt(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 Hi(t,e,n,r,i,s){const a=Nr();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 ui(t,e,n,r){return Wt(t,new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,e,n,r,1]))}function $o(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 Lr(t,e,n,r){return Wt(t,new Float32Array([e,0,0,0,0,n,0,0,0,0,r,0,0,0,0,1]))}function xu(t,e){const n=Math.cos(e),r=Math.sin(e);return Wt(t,new Float32Array([n,r,0,0,-r,n,0,0,0,0,1,0,0,0,0,1]))}function ku(t,e){const n=Math.cos(e),r=Math.sin(e);return Wt(t,new Float32Array([1,0,0,0,0,n,r,0,0,-r,n,0,0,0,0,1]))}function Tu(t,e){const n=Math.cos(e),r=Math.sin(e);return Wt(t,new Float32Array([n,0,-r,0,0,1,0,0,r,0,n,0,0,0,0,1]))}function Su(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 Ps(t,e){const n=t&&typeof t=="object"?t.value:t;return typeof n=="number"&&Number.isFinite(n)?n:e}function bp(t){const e=t&&t.general;if(!e)return!1;const n=e.orthogonalprojection;if(n&&typeof n=="object"){if(Object.keys(n).length>0)return!1}else if(n)return!1;return Ps(e.fov,0)>0}function wp(t,e){return e&&e.perspective&&t&&t.isSkybox&&e.eye?e.eye:t.origin}function vp(t,e,n){const r=_u([t[0]-e[0],t[1]-e[1],t[2]-e[2]]),i=_u(Eu(n,r)),s=Eu(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 Ap(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 xp=[[16,9],[16,10],[21,9],[32,9]];function kp(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 xp){const l=c/u;if(Math.abs(s-l)>a*l)continue;const d=r,f=r*l;return f>n+1e-6?{viewW:n,viewH:n/l}:{viewW:f,viewH:d}}return null}function Go(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)),d=a*u+o*l,f=a*l+o*u,h=Number(s.origin?.[0]??0)||0,p=Number(s.origin?.[1]??0)||0;e=Math.min(e,h-d/2),r=Math.max(r,h+d/2),n=Math.min(n,p-f/2),i=Math.max(i,p+f/2)}return{minX:e,minY:n,maxX:r,maxY:i}}function Qo(t,e,n,r,i,s,a){const o=Pu(s),c=Pu(a);if(t==="cover"){const u=kp(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),d=r/l,f=i/l;return{offX:(e-d)*o,offY:(n-f)*c,viewW:d,viewH:f}}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 d=n,f=n*u;return{offY:0,offX:(e-f)/2,viewW:f,viewH:d}}return{offX:0,offY:0,viewW:e,viewH:n}}function Tp(t,e,n,r,i,s){const a=t.general,o=t.camera,c=o&&o.eye?Yo(o.eye):[0,0,0],u=o&&o.center?Yo(o.center):[0,0,-1],l=o&&o.up?Yo(o.up):[0,1,0];if(bp(t)){const A=n>0?e/n:1.7777777777777777,b=Ps(a.fov,50),v=Math.max(Ps(a.nearz,.01),1e-4),x=Math.max(Ps(a.farz,1e4),v+1),P=vp(c,u,l),S=Su(b,A,v,x);return{view:P,projection:S,eye:c,center:u,projW:A,projH:1,offX:0,offY:0,viewW:A,viewH:1,perspective:!0}}const d=Nr(),f=a&&a.orthogonalprojection&&a.orthogonalprojection.width||e,h=a&&a.orthogonalprojection&&a.orthogonalprojection.height||n,p=Qo(r,f,h,e,n,i,s),m=t&&t.cameraTransforms?t.cameraTransforms.zoom:a&&a.zoom,g=m&&typeof m=="object"?m.value:m,y=Number(g);if(Number.isFinite(y)&&y>0&&Math.abs(y-1)>1e-6){const A=p.offX+p.viewW/2,b=p.offY+p.viewH/2,v=p.viewW/y,x=p.viewH/y;p.offX=A-v/2,p.offY=b-x/2,p.viewW=v,p.viewH=x}const w=Hi(p.offX,p.offX+p.viewW,p.offY+p.viewH,p.offY,-1e4,1e4);return{view:d,projection:w,eye:c,projW:f,projH:h,offX:p.offX,offY:p.offY,viewW:p.viewW,viewH:p.viewH,perspective:!1}}function Sp(t,e){if(!t||t.perspective||!(t.viewW>0)||!(t.viewH>0))return null;const n=Ps(e&&e.perspectiveoverridefov,0);let r,i;n>0?(r=n,i=t.viewH/2/Math.tan(r*Math.PI/180/2)):(i=1e3,r=2*Math.atan(t.viewH/2/i)*180/Math.PI);const s=t.offX+t.viewW/2,a=t.offY+t.viewH/2,o=[s,a,i],c=new Float32Array([1,0,0,0,0,-1,0,0,0,0,1,0,-s,a,-i,1]),u=Su(r,t.viewW/t.viewH,1,i+2e4);return{viewProj:Wt(u,c),eye:o,fovY:r,dist:i}}function Pu(t){const e=Number(t);return Number.isFinite(e)?e<0?0:e>1?1:e:.5}function Yo(t){return String(t).trim().split(/\s+/).map(Number)}function _u(t){const e=Math.hypot(t[0],t[1],t[2])||1;return[t[0]/e,t[1]/e,t[2]/e]}function Eu(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 Ea(t){const e=Number(t);return Number.isFinite(e)?e*.5:0}const Pp=Object.freeze(["3233141951"]);function _p(t){const e=t&&t.parallaxFormula;if(e==="mirage"||e==="legacy")return e;const n=t&&t.workshopId!=null?String(t.workshopId):"";return n&&Pp.includes(n)?"mirage":"legacy"}function Ep(t,e){if(!e||!e.active||!t.parallaxDepth)return[0,0];const n=e.lx||0,r=e.ly||0;if(n===0&&r===0)return[0,0];const i=Ea(t.parallaxDepth[0]),s=Ea(t.parallaxDepth[1]);return[i*n,s*r]}function Mp(t,e){if(!e||!e.active)return[0,0];const n=t.parallaxDepthProp||t.parallaxDepth;if(!n)return[0,0];const r=Number(n[0]),i=Number(n[1]);if(!Number.isFinite(r)||!Number.isFinite(i))return[0,0];if(r===0&&i===0)return[0,0];const s=t.parallaxAnchor||(t.origin?[t.origin[0],t.origin[1]]:null);if(!s)return[0,0];const a=Number(e.amount)||0,o=Number(e.cx)||0,c=Number(e.cy)||0,u=(s[0]-o+(Number(e.mx)||0))*r*a,l=(s[1]-c+(Number(e.my)||0))*i*a;return[u,-l]}function Ko(t,e){return!e||!e.active?[0,0]:e.mode==="mirage"?Mp(t,e):Ep(t,e)}const Cp=2,Mu=32;function Cu(t,e){const n=typeof location<"u"?location.search:"",r=new URLSearchParams(n).get(t);if(r===null||r==="")return null;if(r==="native"||r==="off"||r==="0")return 1;if(r==="auto")return null;const i=Number(r);return Number.isFinite(i)&&i>0?Math.min(1,i):null}function Ip(t,e){const n=Cu("resources");if(n!==null)return n;const r=e?.renderDpr??t.cfg?.renderDpr,i=Number(r);if(r==null||r===0||Number.isNaN(i)){const s=typeof window<"u"&&window.devicePixelRatio||1;return Math.max(.6,Math.min(1,s/Cp))}return i>=1.5?1:i>=.9?.8:.6}function Rp(t,e){const n=Cu("resourcesNormal");return n!==null?n:1}const Bp=1e6;function Iu(t,e,n=4){const r=Math.abs(Number(t)||0),i=Math.abs(Number(e)||0);return!(r>0)||!(i>0)?!0:r*i*(n>0?n:4)<Bp}function Fp(t,e,n){return t.startsWith("util/")||t.startsWith("_rt_")?1:/normal/i.test(t)?n:e}function Dp(t){const e=typeof location<"u"?location.search:"",n=new URLSearchParams(e).get("resources");return n==="native"||n==="off"||n==="0"}function Np(t,e,n,r){const i=Math.abs(Number(t?.[0]||0)*Number(e?.[0]??1)),s=Math.abs(Number(t?.[1]||0)*Number(e?.[1]??1));if(!(i>0)||!(s>0))return 0;const a=Math.abs(Math.cos(n||0)),o=Math.abs(Math.sin(n||0)),c=i*a+s*o,u=i*o+s*a,l=(r.canvasDeviceW||0)/Math.max(1,r.viewW||1),d=(r.canvasDeviceH||0)/Math.max(1,r.viewH||1),f=r.safety&&r.safety>0?r.safety:1;return Math.max(c*l,u*d)*f}function Lp(t,e,n){const r=Math.max(1,Math.round(e||0)),i=Math.max(1,Math.min(r,Math.round(t||0)||r));return n>0?Math.max(Mu,Math.min(r,Math.min(i,Math.round(n)))):i}function Up(t,e){return!t||e>=1?t:Math.max(Mu,Math.round(t*e))}function Op(t,e,n=0){if(!t||t.length<=1||!e)return 0;let r=-1;for(let s=0;s<t.length;s++)if(t[s]<=e){r=s;break}const i=Math.max(0,Number(n)||0);if(i>0){for(let s=Math.max(0,r);s<t.length;s++)if(t[s]<=e&&t[s]>=i)return s;for(let s=t.length-1;s>=0;s--)if(t[s]>=i)return s;return 0}return r<0?t.length-1:r}function zp(t,e){if(!(e<.999))return t;for(const n of t)n.x=Math.round(n.x*e),n.y=Math.round(n.y*e),n.width=Math.max(1,Math.round(n.width*e)),n.height=Math.max(1,Math.round(n.height*e));return t}function Hp(t){const e=t.length/4,n=Math.max(1,e/96|0);for(let r=0;r<e;r+=n)if(t[r*4+3]<250)return!1;return!0}const Vp=4096;function Vi(t,e){const n=window.devicePixelRatio||1,r=e?.renderDpr??t.cfg?.renderDpr;let i;r==null||r===0||Number.isNaN(Number(r))?i=n:i=Math.max(.25,Number(r));const s=Math.max(window.innerWidth||0,window.innerHeight||0,1),a=Vp/s;return Math.max(.25,Math.min(i,a))}function Ur(t){return t==="fit"?"contain":t==="fill"?"cover":t==="contain"||t==="stretch"?t:"cover"}function Zo(t){const e=Ur(t);return e==="contain"?{objectFit:"contain",background:"rgba(10,12,16,0.85)"}:e==="stretch"?{objectFit:"fill",background:"transparent"}:{objectFit:"cover",background:"transparent"}}function Jo(t,e){const n=t.userVolume;return typeof n=="number"&&Number.isFinite(n)?Math.max(0,Math.min(1,n)):(e??t.cfg)?.muted===!1?1:0}function Ru(t){const e=t.userVolume;if(typeof e!="number"||!Number.isFinite(e))return;const n=Math.max(0,Math.min(1,e));try{t.sceneAudio?.setVolume(n)}catch{}if(t.videoPairs?.length)for(const r of t.videoPairs)try{r.setVolume(n)}catch{}else t.video&&(t.video.volume=n,t.video.muted=n<=0);if(t.iframe)try{t.iframe.contentWindow.__weSetVolume?.(n)}catch{}}function Wp(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 Or(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();try{t.sceneAudio.dispose?.()}catch{}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,Qp(),Fu(t)}function jp(t){try{Or(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 qp=new TextDecoder,jt=t=>qp.decode(t).replace(/^\uFEFF/,""),Bu=500;function zr(t,e){const n=t.frameMeter.stamps;n.push(e),t.frameMeter.last=e;const r=e-Bu;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 Fu(t){t.frameMeter.stamps.length=0,t.frameMeter.last=0,t.frameMeter.fps=0}function Xp(t){return!t.frameMeter.last||t.paused?{fps:0,running:!1}:performance.now()-t.frameMeter.last>Math.max(Bu,400)?{fps:0,running:!1}:{fps:t.frameMeter.fps,running:!0}}class ys{static EPS_MS=.5;interval=0;nextAt=0;armed=!1;constructor(e){this.interval=ys.intervalFor(e)}static intervalFor(e){const n=Number(e);return n>0&&isFinite(n)?1e3/n:0}setFps(e){this.interval=ys.intervalFor(e)}shouldRender(e){const n=this.interval;return n<=0?!0:this.armed?e+ys.EPS_MS<this.nextAt?!1:(this.nextAt+=n,this.nextAt<e-n&&(this.nextAt=e+n),!0):(this.armed=!0,this.nextAt=e,!0)}reset(){this.armed=!1,this.nextAt=0}}function be(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 ec(t){t.coverAlign.x=t.coverAlign.y=t.coverAlign.tx=t.coverAlign.ty=.5,$p(t)}function $p(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 Gp=["__scene","__sceneLayers","__textures","__objScripts","__textWidgets","__mediaHooks","__mediaControl","__mediaStats","__mediaSet","__system","__liveSystem","__audioStats","__audioMute","__particleStats","__particleToggle","__pointerStats","__compositeStats","__compositeEnable"];function Qp(){const t=window;for(const e of Gp)e in t&&delete t[e]}function Du(t,e,n){const r=Vi(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 Yp=.5,Nu=.12,Kp=.125,Zp=.0625,Lu=64;function Uu(t,e){const n=U=>{const W=document.createElement("video");U&&(W.src=t),W.muted=e.muted,W.playsInline=!0,W.preload="metadata";const ie=e.renderDpr||0,we=Math.min(window.devicePixelRatio||1,ie<=0?window.devicePixelRatio||1:ie),Y=Math.max(1,Math.round((e.maxW||innerWidth)*we)),oe=Math.max(1,Math.round((e.maxH||innerHeight)*we));return W.width=Y,W.height=oe,W.loop=!0,W};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,d,f=-1,h=0,p=0,m=Nu,g=!1,y=0,w=0,A=0,b=0,v,x=-1,P=0,S=!1;const k=U=>{if(S||U!==r)return;if(!u||!g){_(),U.loop=!0,U.play().catch(()=>{}),O.onFallback?.();return}i.playbackRate=1;const W=r;l=!0,W.style.transition=`opacity ${Lu}ms linear`,W.style.opacity="0";let ie=!1;const we=()=>{ie||S||(ie=!0,l=!1,W.style.transition="",I(),W.style.opacity="1")};W.addEventListener("transitionend",we,{once:!0}),d=window.setTimeout(we,Lu+80)},_=()=>{u=!1,p=0,g=!1,l&&(l=!1,d&&(clearTimeout(d),d=void 0),r.style.transition="",r.style.opacity="1"),v&&(v.loop=!0,v=void 0),i.paused||i.pause(),i.playbackRate=1;try{i.currentTime=0}catch{}},I=()=>{const U=r;r=i,i=U,u=!1,p=0,g=!1,h=0,f=-1,A=0,b=0,w=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,U.pause(),U.playbackRate=1;try{U.currentTime=0}catch{}U.muted=!0,U.loop=!0,x=-1,s=!0,O.onSwap?.(r)},B=(U,W)=>{const ie=performance.now();if(!(ie-b<1e3)){if(b=ie,A++,h=0,f=-1,A>=3){A=0;const we=W,Y=r;e.onRecover?.(`${U}\uFF1A\u91CD\u8F7D\u5A92\u4F53\u7BA1\u7EBF @${we.toFixed(2)}s`),x=-1,Y.addEventListener("loadedmetadata",()=>{if(!(S||Y!==r)){try{Y.currentTime=Math.max(0,Math.min(we,(Y.duration||we)-.05))}catch{}Y.play().catch(()=>{})}},{once:!0}),Y.src=t,Y.play().catch(()=>{});return}if(A===2){e.onRecover?.(`${U}\uFF1Aseek \u91CD\u542F\u89E3\u7801 @${W.toFixed(2)}s`);try{r.currentTime=Math.max(0,W-.001)}catch{}r.play().catch(()=>{});return}e.onRecover?.(`${U}\uFF1A\u8E22 play`),r.pause(),r.play().catch(()=>{})}},V=()=>{if(S)return;P=requestAnimationFrame(V);const U=r.duration;if(!isFinite(U)||U<=0)return;const W=r.currentTime;if(!document.hidden&&!l&&performance.now()>=w?r.paused&&!r.ended&&r.readyState>=1?(h++,h>30&&B("\u9759\u9ED8\u6682\u505C",W)):!r.paused&&r.readyState>=2?(f===W?(h++,h>30&&B("\u5047\u64AD\u653E",W)):(h=0,A=0),f=W):(h=0,f=-1):(h=0,f=-1),x>=0&&W<x-.05){const Y=u,oe=g;_(),x=W,Y&&!oe&&(m=Math.min(1,m*2)),Y||O.onFallback?.();return}x=W;const ie=U-W,we=Math.max(Yp,m+.5);if(ie>we+.5){u&&_();return}if(u){if(!g&&i.currentTime>.004){g=!0;const Y=performance.now()-y;m=Math.min(1,Math.max(Nu,Y/1e3*1.5+.15)),v!==r&&(r.loop=!1,v=r)}!l&&g&&(r.ended||p>0&&performance.now()-p>1500)&&k(r);return}if(ie<=we&&(c(),i.readyState>=2)){if(ie<=m){try{i.currentTime=0}catch{}i.playbackRate=m>.3?Zp:Kp,y=performance.now(),g=!1,i.play().catch(()=>{}),u=!0,p=performance.now()}else if(i.paused)try{i.currentTime=0}catch{}}};P=requestAnimationFrame(V),r.addEventListener("ended",()=>k(r)),i.addEventListener("ended",()=>k(i));const O={get active(){return r},get standby(){return i},onSwap:void 0,onFallback:void 0,setVolume(U){a=Math.max(0,Math.min(1,U)),o=U<=0,r.muted=o,r.volume=a,i.muted=!0,i.volume=a},pause(){_(),r.pause(),P&&cancelAnimationFrame(P),P=0},resume(){S||(r.play().catch(U=>{U&&U.name}),P||(P=requestAnimationFrame(V)))},destroy(){S=!0,P&&cancelAnimationFrame(P),P=0;for(const U of[r,i]){U.pause(),U.removeAttribute("src");try{U.load()}catch{}U.remove()}}};return O}function N(t){if(!t)throw new Error("Assertion failed.")}const tc=t=>{const e=(t%360+360)%360;if(e===0||e===90||e===180||e===270)return e;throw new Error(`Invalid rotation ${t}.`)},Yt=t=>t&&t[t.length-1],ke=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)},cr=t=>{const e=ke(t);return(e&1)===0?-(e>>1):e+1>>1},lr=t=>t.constructor===Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):new Uint8Array(t),et=t=>t.constructor===DataView?t:ArrayBuffer.isView(t)?new DataView(t.buffer,t.byteOffset,t.byteLength):new DataView(t),Kt=new TextDecoder,nc=t=>Object.fromEntries(Object.entries(t).map(([e,n])=>[n,e])),rc={bt709:1,bt470bg:5,smpte170m:6,bt2020:9,smpte432:12},ur=nc(rc),ic={bt709:1,smpte170m:6,linear:8,"iec61966-2-1":13,pq:16,hlg:18},fr=nc(ic),sc={rgb:0,bt709:1,bt470bg:5,smpte170m:6,"bt2020-ncl":9},dr=nc(sc),ac=t=>!!t&&!!t.primaries&&!!t.transfer&&!!t.matrix&&t.fullRange!==void 0,Ou={primaries:void 0,transfer:void 0,matrix:void 0,fullRange:void 0},Jp=t=>t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer||ArrayBuffer.isView(t);class Ma{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 e0=/^[0-9a-fA-F]+$/,_s=t=>[...t].map(e=>e.toString(16).padStart(2,"0")).join(""),t0=t=>{N(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},zu=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),Es=(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},Ge=(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},Hu=(t,e,n)=>{const r=Ge(t,n(e),n);t.splice(r+1,0,e)},Dt=()=>{let t,e;return{promise:new Promise((r,i)=>{t=r,e=i}),resolve:t,reject:e}},oc=(t,e)=>{const n=t.indexOf(e);n!==-1&&t.splice(n,1)},Vu=(t,e)=>{for(let n=t.length-1;n>=0;n--)if(e(t[n]))return t[n]},cc=(t,e)=>{for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1},n0=async function*(t){Symbol.iterator in t?yield*t[Symbol.iterator]():yield*t[Symbol.asyncIterator]()},r0=t=>{if(!(Symbol.iterator in t)&&!(Symbol.asyncIterator in t))throw new TypeError("Argument must be an iterable or async iterable.")},Ca=t=>{throw new Error(`Unexpected value: ${t}`)},Wu=(t,e,n)=>{const r=t.getUint8(e),i=t.getUint8(e+1),s=t.getUint8(e+2);return r<<16|i<<8|s},i0=(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)},Ms=(t,e,n)=>Math.max(e,Math.min(n,t)),qt="und",Cs=t=>{const e=Math.round(t);return Math.abs(t/e-1)<10*Number.EPSILON?e:t},lc=(t,e)=>Math.round(t/e)*e,ju=(t,e)=>Math.round(t*e)/e,uc=(t,e)=>Math.floor(t/e)*e,s0=t=>{let e=0;for(;t;)e++,t>>=1;return e},fc=t=>{let e=0;for(;t!==0;)t&=t-1,e++;return e},a0=/^[a-z]{3}$/,qu=t=>a0.test(t),Wi=1e6*(1+Number.EPSILON),Xu=(t,e)=>{const n={...t,...e};if(t.headers||e.headers){const r=t.headers?dc(t.headers):{},i=e.headers?dc(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},dc=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},$u=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(Be._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 Ba(1e3*o),i())throw a}};class o0{constructor(){this.currentPromise=Promise.resolve()}call(e){return this.currentPromise=this.currentPromise.then(e)}}let hc=null;const mc=()=>hc!==null?hc:hc=!!(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 pc=null;const c0=()=>pc!==null?pc:pc=typeof navigator<"u"&&navigator.userAgent?.includes("Firefox");let gc=null;const yc=()=>gc!==null?gc:gc=!!(typeof navigator<"u"&&(navigator.vendor?.includes("Google Inc")||/Chrome/.test(navigator.userAgent))),l0=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.`,u0=(async()=>{})().constructor,le=t=>t instanceof u0||t instanceof Promise?!0:typeof t?.then=="function",ji=(t,e)=>t!==-1?t:e,bc=(t,e,n,r)=>t<=r&&n<=e,Gu=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},f0=(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},wc=()=>{Symbol.dispose??=Symbol("Symbol.dispose")},Ia=t=>typeof t=="number"&&!Number.isNaN(t),Hr=(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("/")},Is=(t,e)=>{let n=0;for(let r=0;r<t.length;r++)e(t[r])&&n++;return n},vc=(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},Ra=t=>{N(Number.isInteger(t.num)),N(Number.isInteger(t.den)),N(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}},Ac=(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.`)},Ba=t=>new Promise(e=>setTimeout(e,t));class xc{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 qn;(function(t){t[t.Silent=0]="Silent",t[t.Errors=1]="Errors",t[t.Warnings=2]="Warnings",t[t.Info=3]="Info"})(qn||(qn={}));class Be{constructor(){}static get level(){return Be._level}static set level(e){if(e!==qn.Silent&&e!==qn.Errors&&e!==qn.Warnings&&e!==qn.Info)throw new TypeError("Invalid log level. Use one of the values of the LogLevel enum.");Be._level=e}static get _emitter(){return Be._emitterInstance??=new xc}static on(e,n,r){return Be._emitter.on(e,n,r)}static _error(...e){Be._emitter._emit("error",e),Be._level>=qn.Errors&&console.error(...e)}static _warn(...e){Be._emitter._emit("warn",e),Be._level>=qn.Warnings&&console.warn(...e)}static _info(...e){Be._emitter._emit("info",e),Be._level>=qn.Info&&console.info(...e)}}Be._level=qn.Info,Be._emitterInstance=null;class Fa{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 d0{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 hr={default:!0,primary:!0,forced:!1,original:!1,commentary:!1,hearingImpaired:!1,visuallyImpaired:!1};class Qe{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 Qe(this.bytes);return e.pos=this.pos,e}}const Rs=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],kc=[-1,1,2,3,4,5,6,8],Qu=t=>{if(!t||t.byteLength<2)throw new TypeError("AAC description must be at least 2 bytes long.");const e=new Qe(t),n=Tc(e),{frequencyIndex:r,sampleRate:i}=Sc(e),s=e.readBits(4);let a=null;s>=1&&s<=7&&(a=kc[s]);let o=n,c=!1,u=i;if(n===5||n===29)c=n===29,u=Sc(e).sampleRate,o=Tc(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}Tc(e)===5&&e.readBits(1)&&(u=Sc(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}},Tc=t=>{const e=t.readBits(5);return e===31?32+t.readBits(6):e},Sc=t=>{const e=t.readBits(4);return e===15?{frequencyIndex:e,sampleRate:t.readBits(24)}:{frequencyIndex:e,sampleRate:e<Rs.length?Rs[e]:null}};const Da=[48e3,44100,32e3],Yu=[24e3,22050,16e3];var Rt;(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"})(Rt||(Rt={}));var vt;(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"})(vt||(vt={}));const Na=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})},Ku=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=Wu(r,n):(N(e===4),i=r.getUint32(n,!1)),n+=e,yield{offset:n,length:i},n+=i}},Zu=(t,e)=>{if(e.description){const i=(lr(e.description)[4]&3)+1;return Ku(t,i)}else return Na(t)},La=t=>t&31,Ua=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)},Pc=new Uint8Array([0,0,0,1]),Ju=t=>{const e=t.reduce((i,s)=>i+Pc.byteLength+s.byteLength,0),n=new Uint8Array(e);let r=0;for(const i of t)n.set(Pc,r),r+=Pc.byteLength,n.set(i,r),r+=i.byteLength;return n},ef=(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:i0(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},h0=(t,e)=>{if(e.description){const i=(lr(e.description)[4]&3)+1;return ef(t,i)}else return Ju(t)},_c=t=>{try{const e=[],n=[],r=[];for(const o of Na(t)){const c=t.subarray(o.offset,o.offset+o.length),u=La(c[0]);u===Rt.SPS?e.push(c):u===Rt.PPS?n.push(c):u===Rt.SPS_EXT&&r.push(c)}if(e.length===0||n.length===0)return null;const i=e[0],s=Oa(i);N(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 Be._error("Error building AVC Decoder Configuration Record:",e),null}},tf=t=>{try{const e=et(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++),d=[];for(let h=0;h<l;h++){const p=e.getUint16(n,!1);n+=2,d.push(t.subarray(n,n+p)),n+=p}const f={configurationVersion:r,avcProfileIndication:i,profileCompatibility:s,avcLevelIndication:a,lengthSizeMinusOne:o,sequenceParameterSets:u,pictureParameterSets:d,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++);f.chromaFormat=h,f.bitDepthLumaMinus8=p,f.bitDepthChromaMinus8=m;const y=[];for(let w=0;w<g;w++){const A=e.getUint16(n,!1);n+=2,y.push(t.subarray(n,n+A)),n+=A}f.sequenceParameterSetExt=y}return f}catch(e){return Be._error("Error deserializing AVC Decoder Configuration Record:",e),null}},nf={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}},Oa=t=>{try{const e=new Qe(Ua(t));if(e.skipBits(1),e.skipBits(2),e.readBits(5)!==7)return null;const r=e.readAlignedByte(),i=e.readAlignedByte(),s=e.readAlignedByte();ke(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=ke(e),a===3&&(u=e.readBits(1)),o=ke(e),c=ke(e),e.skipBits(1),e.readBits(1))){for(let B=0;B<(a!==3?8:12);B++)if(e.readBits(1)){const O=B<6?16:64;let U=8,W=8;for(let ie=0;ie<O;ie++){if(W!==0){const we=cr(e);W=(U+we+256)%256}U=W===0?U:W}}}ke(e);const l=ke(e);if(l===0)ke(e);else if(l===1){e.skipBits(1),cr(e),cr(e);const I=ke(e);for(let B=0;B<I;B++)cr(e)}ke(e),e.skipBits(1);const d=ke(e),f=ke(e),h=16*(d+1),p=16*(f+1);let m=h,g=p;const y=e.readBits(1);if(y||e.skipBits(1),e.skipBits(1),e.readBits(1)){const I=ke(e),B=ke(e),V=ke(e),O=ke(e);let U,W;if((u===0?a:0)===0)U=1,W=2-y;else{const we=a===3?1:2,Y=a===1?2:1;U=we,W=Y*(2-y)}m-=U*(I+B),g-=W*(V+O)}let A=2,b=2,v=2,x=0,P={num:1,den:1},S=null,k=null;if(e.readBits(1)){if(e.readBits(1)){const Y=e.readBits(8);if(Y===255)P={num:e.readBits(16),den:e.readBits(16)};else{const oe=nf[Y];oe&&(P=oe)}}e.readBits(1)&&e.skipBits(1),e.readBits(1)&&(e.skipBits(3),x=e.readBits(1),e.readBits(1)&&(A=e.readBits(8),b=e.readBits(8),v=e.readBits(8))),e.readBits(1)&&(ke(e),ke(e)),e.readBits(1)&&(e.skipBits(32),e.skipBits(32),e.skipBits(1));const W=e.readBits(1);W&&rf(e);const ie=e.readBits(1);ie&&rf(e),(W||ie)&&e.skipBits(1),e.skipBits(1),e.readBits(1)&&(e.skipBits(1),ke(e),ke(e),ke(e),ke(e),S=ke(e),k=ke(e))}if(S===null){N(k===null);const I=i&16;if((r===44||r===86||r===100||r===110||r===122||r===244)&&I)S=0,k=0;else{const B=d+1,V=f+1,O=(2-y)*V,U=wf.find(ie=>ie.level>=s)??Yt(wf),W=Math.min(Math.floor(U.maxDpbMbs/(B*O)),16);S=W,k=W}}return N(k!==null),{profileIdc:r,constraintFlags:i,levelIdc:s,frameMbsOnlyFlag:y,chromaFormatIdc:a,bitDepthLumaMinus8:o,bitDepthChromaMinus8:c,codedWidth:h,codedHeight:p,displayWidth:m,displayHeight:g,pixelAspectRatio:P,colourPrimaries:A,matrixCoefficients:v,transferCharacteristics:b,fullRangeFlag:x,numReorderFrames:S,maxDecFrameBuffering:k}}catch(e){return Be._error("Error parsing AVC SPS:",e),null}},rf=t=>{const e=ke(t);t.skipBits(4),t.skipBits(4);for(let n=0;n<=e;n++)ke(t),ke(t),t.skipBits(1);t.skipBits(5),t.skipBits(5),t.skipBits(5),t.skipBits(5)},m0=(t,e)=>{if(e.description){const i=(lr(e.description)[21]&3)+1;return ef(t,i)}else return Ju(t)},za=(t,e)=>{if(e.description){const i=(lr(e.description)[21]&3)+1;return Ku(t,i)}else return Na(t)},qi=t=>t>>1&63,Ec=t=>{try{const e=new Qe(Ua(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}=p0(e,n);ke(e);const l=ke(e);let d=0;l===3&&(d=e.readBits(1));const f=ke(e),h=ke(e);let p=f,m=h;if(e.readBits(1)){const B=ke(e),V=ke(e),O=ke(e),U=ke(e);let W=1,ie=1;const we=d===0?l:0;we===1?(W=2,ie=2):we===2&&(W=2,ie=1),p-=(B+V)*W,m-=(O+U)*ie}const g=ke(e),y=ke(e);ke(e);const A=e.readBits(1)?0:n;let b=0;for(let B=A;B<=n;B++)ke(e),b=ke(e),ke(e);ke(e),ke(e),ke(e),ke(e),ke(e),ke(e),e.readBits(1)&&e.readBits(1)&&g0(e),e.skipBits(1),e.skipBits(1),e.readBits(1)&&(e.skipBits(4),e.skipBits(4),ke(e),ke(e),e.skipBits(1));const v=ke(e);if(y0(e,v),e.readBits(1)){const B=ke(e);for(let V=0;V<B;V++)ke(e),e.skipBits(1)}e.skipBits(1),e.skipBits(1);let x=2,P=2,S=2,k=0,_=0,I={num:1,den:1};if(e.readBits(1)){const B=w0(e,n);I=B.pixelAspectRatio,x=B.colourPrimaries,P=B.transferCharacteristics,S=B.matrixCoefficients,k=B.fullRangeFlag,_=B.minSpatialSegmentationIdc}return{displayWidth:p,displayHeight:m,pixelAspectRatio:I,colourPrimaries:x,transferCharacteristics:P,matrixCoefficients:S,fullRangeFlag:k,maxDecFrameBuffering:b+1,spsMaxSubLayersMinus1:n,spsTemporalIdNestingFlag:r,generalProfileSpace:i,generalTierFlag:s,generalProfileIdc:a,generalProfileCompatibilityFlags:o,generalConstraintIndicatorFlags:c,generalLevelIdc:u,chromaFormatIdc:l,bitDepthLumaMinus8:g,bitDepthChromaMinus8:y,minSpatialSegmentationIdc:_}}catch(e){return Be._error("Error parsing HEVC SPS:",e),null}},Mc=t=>{try{const e=[],n=[],r=[],i=[];for(const u of Na(t)){const l=t.subarray(u.offset,u.offset+u.length),d=qi(l[0]);d===vt.VPS_NUT?e.push(l):d===vt.SPS_NUT?n.push(l):d===vt.PPS_NUT?r.push(l):(d===vt.PREFIX_SEI_NUT||d===vt.SUFFIX_SEI_NUT)&&i.push(l)}if(n.length===0||r.length===0)return null;const s=Ec(n[0]);if(!s)return null;let a=0;if(r.length>0){const u=r[0],l=new Qe(Ua(u));l.skipBits(16),ke(l),ke(l),l.skipBits(1),l.skipBits(1),l.skipBits(3),l.skipBits(1),l.skipBits(1),ke(l),ke(l),cr(l),l.skipBits(1),l.skipBits(1),l.readBits(1)&&ke(l),cr(l),cr(l),l.skipBits(1),l.skipBits(1),l.skipBits(1),l.skipBits(1);const d=l.readBits(1),f=l.readBits(1);!d&&!f?a=0:d&&!f?a=2:!d&&f?a=3:a=0}const o=[...e.length?[{arrayCompleteness:1,nalUnitType:vt.VPS_NUT,nalUnits:e}]:[],...n.length?[{arrayCompleteness:1,nalUnitType:vt.SPS_NUT,nalUnits:n}]:[],...r.length?[{arrayCompleteness:1,nalUnitType:vt.PPS_NUT,nalUnits:r}]:[],...i.length?[{arrayCompleteness:1,nalUnitType:qi(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 Be._error("Error building HEVC Decoder Configuration Record:",e),null}},p0=(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}},g0=t=>{for(let e=0;e<4;e++)for(let n=0;n<(e===3?2:6);n++)if(!t.readBits(1))ke(t);else{const i=Math.min(64,1<<4+(e<<1));e>1&&cr(t);for(let s=0;s<i;s++)cr(t)}},y0=(t,e)=>{const n=[];for(let r=0;r<e;r++)n[r]=b0(t,r,e,n)},b0=(t,e,n,r)=>{let i=0,s=0,a=0;if(e!==0&&(s=t.readBits(1)),s){if(e===n){const c=ke(t);a=e-(c+1)}else a=e-1;t.readBits(1),ke(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=ke(t),c=ke(t);for(let u=0;u<o;u++)ke(t),t.readBits(1);for(let u=0;u<c;u++)ke(t),t.readBits(1);i=o+c}return i},w0=(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=nf[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)&&(ke(t),ke(t)),t.readBits(1),t.readBits(1),t.readBits(1),t.readBits(1)&&(ke(t),ke(t),ke(t),ke(t)),t.readBits(1)&&(t.readBits(32),t.readBits(32),t.readBits(1)&&ke(t),t.readBits(1)&&v0(t,!0,e)),t.readBits(1)&&(t.readBits(1),t.readBits(1),t.readBits(1),a=ke(t),ke(t),ke(t),ke(t),ke(t)),{pixelAspectRatio:o,colourPrimaries:n,transferCharacteristics:r,matrixCoefficients:i,fullRangeFlag:s,minSpatialSegmentationIdc:a}},v0=(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?ke(t):u=t.readBits(1)===1;let l=1;u||(l=ke(t)+1),r&&sf(t,l,s),i&&sf(t,l,s)}},sf=(t,e,n)=>{for(let r=0;r<e;r++)ke(t),ke(t),n&&(ke(t),ke(t)),t.readBits(1)},A0=t=>{try{const e=et(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++),d=(e.getUint8(n++)&15)<<8|e.getUint8(n++),f=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 y=e.getUint8(n++),w=y>>6&3,A=y>>3&7,b=y>>2&1,v=y&3,x=e.getUint8(n++),P=[];for(let S=0;S<x;S++){const k=e.getUint8(n++),_=k>>7&1,I=k&63,B=e.getUint16(n,!1);n+=2;const V=[];for(let O=0;O<B;O++){const U=e.getUint16(n,!1);n+=2,V.push(t.subarray(n,n+U)),n+=U}P.push({arrayCompleteness:_,nalUnitType:I,nalUnits:V})}return{configurationVersion:r,generalProfileSpace:s,generalTierFlag:a,generalProfileIdc:o,generalProfileCompatibilityFlags:c,generalConstraintIndicatorFlags:u,generalLevelIdc:l,minSpatialSegmentationIdc:d,parallelismType:f,chromaFormatIdc:h,bitDepthLumaMinus8:p,bitDepthChromaMinus8:m,avgFrameRate:g,constantFrameRate:w,numTemporalLayers:A,temporalIdNested:b,lengthSizeMinusOne:v,arrays:P}}catch(e){return Be._error("Error deserializing HEVC Decoder Configuration Record:",e),null}};var Nt;(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"})(Nt||(Nt={}));const x0=(t,e)=>{const n=new Set;let r=Nt.audAllowed;for(const s of za(t,e)){if(r===Nt.noMoreDataAllowed){n.add(s.offset);continue}const a=qi(t[s.offset]);if(r===Nt.eoBitstreamAllowed&&a!==37){n.add(s.offset);continue}let o=!1;a===35?r>Nt.audAllowed?o=!0:r=Nt.beforeFirstVcl:a<=31?r>Nt.afterFirstVcl?o=!0:r=Nt.afterFirstVcl:a===36?r!==Nt.afterFirstVcl?o=!0:r=Nt.eoBitstreamAllowed:a===37?r<Nt.afterFirstVcl?o=!0:r=Nt.noMoreDataAllowed:a===32||a===33||a===34||a===39||a>=41&&a<=44||a>=48&&a<=55?r>Nt.beforeFirstVcl?o=!0:r=Nt.beforeFirstVcl:(a===38||a===40||a>=45&&a<=47||a>=56&&a<=63)&&r<Nt.afterFirstVcl&&(o=!0),o&&n.add(s.offset)}if(n.size===0)return null;const i=[];for(const s of za(t,e))n.has(s.offset)||i.push(t.subarray(s.offset,s.offset+s.length));return m0(i,e)},k0={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}},af=t=>{const e=new Qe(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 d=0,f=0;if(l!==7)if(f=e.readBits(1),s===1||s===3){const S=e.readBits(1),k=e.readBits(1);d=!S&&!k?3:S&&!k?2:1,e.skipBits(1)}else d=1;else d=3,f=1;const h=e.readBits(16),p=e.readBits(16),m=h+1,g=p+1,y=m*g;let w=Yt($i).level;for(const P of $i)if(y<=P.maxPictureSize){w=P.level;break}const A=k0[l],b=A?.colourPrimaries??2,v=A?.transferCharacteristics??2,x=A?.matrixCoefficients??2;return{profile:s,level:w,bitDepth:u,chromaSubsampling:d,videoFullRangeFlag:f,colourPrimaries:b,transferCharacteristics:v,matrixCoefficients:x}},T0=t=>t.colourPrimaries!==2||t.transferCharacteristics!==2||t.matrixCoefficients!==2,of=function*(t){const e=new Qe(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);N(e.pos%8===0),yield{type:r,data:t.subarray(e.pos/8,e.pos/8+a)},e.skipBits(a*8)}},Cc=t=>{for(const{type:e,data:n}of of(t)){if(e!==1)continue;const r=new Qe(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 k=r.readBits(1);let _=0;if(k){if(r.skipBits(32),r.skipBits(32),r.readBits(1)){let O=0;for(;O<32&&!r.readBits(1);)O++;O<32&&r.skipBits(O)}_=r.readBits(1),_&&(c=r.readBits(5),r.skipBits(32),r.skipBits(5),r.skipBits(5))}const I=r.readBits(1),B=r.readBits(5);for(let V=0;V<=B;V++){r.skipBits(12);const O=r.readBits(5);if(V===0&&(a=O),O>7){const U=r.readBits(1);V===0&&(o=U)}if(_&&r.readBits(1)){const W=c+1;r.skipBits(W),r.skipBits(W),r.skipBits(1)}I&&r.readBits(1)&&r.skipBits(4)}}const u=r.readBits(4),l=r.readBits(4),d=u+1;r.skipBits(d);const f=l+1;r.skipBits(f);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 k=r.readBits(1);k&&(r.skipBits(1),r.skipBits(1));const _=r.readBits(1);let I=0;_?I=2:I=r.readBits(1),I>0&&(r.readBits(1)||r.skipBits(1)),k&&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 y=2,w=2,A=2;r.readBits(1)&&(y=r.readBits(8),w=r.readBits(8),A=r.readBits(8));let v=0,x=1,P=1,S=0;return g?v=r.readBits(1):y===1&&w===13&&A===0?(v=1,x=0,P=0):(v=r.readBits(1),i===0?(x=1,P=1):i===1?(x=0,P=0):m===12?(x=r.readBits(1),P=x?r.readBits(1):0):(x=1,P=0),x&&P&&(S=r.readBits(2))),{profile:i,level:a,tier:o,bitDepth:m,monochrome:g,chromaSubsamplingX:x,chromaSubsamplingY:P,chromaSamplePosition:S,videoFullRangeFlag:v,colourPrimaries:y,transferCharacteristics:w,matrixCoefficients:A}}return null},S0=t=>t.colourPrimaries!==2||t.transferCharacteristics!==2||t.matrixCoefficients!==2,cf=t=>{if(t.length<36)return null;const n=et(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)}},P0=t=>{const e=et(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}},_0=[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],E0=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:_0[e]*r}},M0=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 d=0;d<n;d++)r[d]=t[n-1-d];const i=new Qe(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 d=i.pos,f=i.readBits(8),h=i.readBits(16),p=i.readBits(16);if(f>63||h!==0||p!==0){i.pos=d;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 d=u-1;d>=0;d--)i.skipBits(40),l[d]=i.readBits(1);return{modeBlockflags:l}},Ic=(t,e,n)=>{switch(t){case"avc":{for(const r of Zu(n,e)){const i=n[r.offset],s=La(i);if(s>=Rt.NON_IDR_SLICE&&s<=Rt.SLICE_DPC)return"delta";if(s===Rt.IDR)return"key";if(s===Rt.SEI&&!yc()){const a=n.subarray(r.offset,r.offset+r.length),o=Ua(a);let c=1;do{let u=0;for(;;){const f=o[c++];if(f===void 0||(u+=f,f<255))break}let l=0;for(;;){const f=o[c++];if(f===void 0||(l+=f,f<255))break}if(u===6){const f=new Qe(o);f.pos=8*c;const h=ke(f),p=f.readBits(1);if(h===0&&p===1)return"key"}c+=l}while(c<o.length-1)}}return"delta"}case"hevc":{for(const r of za(n,e)){const i=qi(n[r.offset]);if(i<vt.BLA_W_LP)return"delta";if(i<=vt.RSV_IRAP_VCL23)return"key"}return"delta"}case"vp8":return(n[0]&1)===0?"key":"delta";case"vp9":{const r=new Qe(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 of(n))if(i===1){const a=new Qe(s);a.skipBits(4),r=!!a.readBits(1)}else if(i===3||i===6||i===7){if(r)return"key";const a=new Qe(s);return a.readBits(1)?null:a.readBits(2)===0?"key":"delta"}return null}case"prores":return"key";default:Ca(t),N(!1)}};var Xi;(function(t){t[t.STREAMINFO=0]="STREAMINFO",t[t.VORBIS_COMMENT=4]="VORBIS_COMMENT",t[t.PICTURE=6]="PICTURE"})(Xi||(Xi={}));const Rc=(t,e)=>{const n=et(t);let r=0;const i=n.getUint32(r,!0);r+=4;const s=Kt.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=Kt.decode(t.subarray(r,r+c));r+=c;const l=u.indexOf("=");if(l===-1)continue;const d=u.slice(0,l).toUpperCase(),f=u.slice(l+1);switch(e.raw??={},e.raw[d]??=f,d){case"TITLE":e.title??=f;break;case"DESCRIPTION":e.description??=f;break;case"ARTIST":e.artist??=f;break;case"ALBUM":e.album??=f;break;case"ALBUMARTIST":e.albumArtist??=f;break;case"COMMENT":e.comment??=f;break;case"LYRICS":e.lyrics??=f;break;case"TRACKNUMBER":{const h=f.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(f,10);Number.isInteger(h)&&h>0&&(e.tracksTotal??=h)}break;case"DISCNUMBER":{const h=f.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(f,10);Number.isInteger(h)&&h>0&&(e.discsTotal??=h)}break;case"DATE":{const h=new Date(f);Number.isNaN(h.getTime())||(e.date??=h)}break;case"GENRE":e.genre??=f;break;case"METADATA_BLOCK_PICTURE":{const h=Gu(f),p=et(h),m=p.getUint32(0,!1),g=p.getUint32(4,!1),y=String.fromCharCode(...h.subarray(8,8+g)),w=p.getUint32(8+g,!1),A=Kt.decode(h.subarray(12+g,12+g+w)),b=p.getUint32(g+w+28),v=h.subarray(g+w+32,g+w+32+b);e.images??=[],e.images.push({data:v,mimeType:y,kind:m===3?"coverFront":m===4?"coverBack":"unknown",name:void 0,description:A||void 0})}break}}},Bc=[2,1,2,3,3,4,4,5],C0=t=>{if(t.length<7||t[0]!==11||t[1]!==119)return null;const e=new Qe(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}},I0=[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],R0=1536,lf=[1,2,3,6],B0=t=>{if(t.length<6||t[0]!==11||t[1]!==119)return null;const e=new Qe(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=lf[a];let d;return i<3?d=Da[i]/1e3:d=Yu[s]/1e3,{dataRate:Math.round((r+1)*d/(l*16)),substreams:[{fscod:i,fscod2:s,bsid:u,bsmod:0,acmod:o,lfeon:c,numDepSub:0,chanLoc:0}]}},F0=t=>{if(t.length<2)return null;const e=new Qe(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 d=e.readBits(4);let f=0;d>0?f=e.readBits(9):e.skipBits(1),i.push({fscod:a,fscod2:null,bsid:o,bsmod:c,acmod:u,lfeon:l,numDepSub:d,chanLoc:f})}return i.length===0?null:{dataRate:n,substreams:i}},uf=t=>{const e=t.substreams[0];return N(e),e.fscod<3?Da[e.fscod]:e.fscod2!==null&&e.fscod2<3?Yu[e.fscod2]:null},ff=t=>{const e=t.substreams[0];N(e);let n=Bc[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},D0=1683496997,Ha=18,Fc=10,N0=4096,df=32,hf=20,L0=8,U0=[0,8e3,16e3,32e3,0,0,11025,22050,44100,0,0,12e3,24e3,48e3,96e3,192e3],O0=[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],z0=[16,16,20,20,0,24,24,0],Va=[1,2,2,2,2,3,3,4,4,5,6,6,6,7,8,8],H0=[1,2,2,2,2,3,18,19,6,7,518,323,83,519,582,535],V0=8,W0=44646,j0=[32e3,44100,48e3,0],q0=[8e3,16e3,32e3,64e3,128e3,22050,44100,88200,176400,352800,12e3,24e3,48e3,96e3,192e3,384e3],X0=[512,1024,2048,4096],mf=t=>{const e=gf(t),n=et(t);let r=e?Math.ceil(e.frameSize/4)*4:0,i=null;for(;r+4<=t.length&&n.getUint32(r)===D0;){const a=Wa(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}},pf=t=>{const e=mf(t);return e?.core?e.hasExtensions?"dtsh":"dtsc":null},gf=t=>{if(t.length<Ha||t[0]!==127||t[1]!==254||t[2]!==128||t[3]!==1)return null;const e=new Qe(t);if(e.skipBits(32),e.skipBits(1),e.readBits(5)!==df-1)return null;const n=e.readBits(1),r=e.readBits(7)+1;if(r%L0!==0)return null;const i=e.readBits(14)+1;if(i<96)return null;const s=e.readBits(6);if(s>=Va.length)return null;const a=U0[e.readBits(4)];if(a===0)return null;const o=O0[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=z0[e.readBits(3)];if(u===0)return null;const l=c!==0;return{frameSize:i,sampleRate:a,numberOfChannels:Va[s]+(l?1:0),sampleCount:r*df,channelLayout:H0[s]|(l?V0:0),amode:s,lfePresent:l,bitRate:o,pcmResolution:u}},Wa=t=>{if(t.length<Fc||t[0]!==100||t[1]!==88||t[2]!==32||t[3]!==37)return null;const e=new Qe(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=j0[e.readBits(2)],u=512*(e.readBits(3)+1);e.readBits(1)&&e.skipBits(36);const l=e.readBits(3)+1,d=e.readBits(3)+1,f=[];for(let y=0;y<l;y++)f.push(e.readBits(n+1));for(const y of f)e.skipBits(8*fc(y));if(e.readBits(1)){e.skipBits(2);const y=e.readBits(2)+1<<2,w=e.readBits(2)+1;e.skipBits(w*y)}for(let y=0;y<d;y++)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=q0[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 y=e.readBits(2)+1<<2;g=e.readBits(y)}return c===0||e.getBitsLeft()<0?o:{frameSize:a,asset:{sampleRate:p,numberOfChannels:m,sampleCount:Math.round(u*p/c),channelLayout:g,pcmResolution:h}}},$0=t=>{if(t.length<hf)return null;const e=et(t),n=e.getUint32(0);if(n===0)return null;const r=new Qe(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=G0(o):a<Va.length&&(c=Va[a]+s),{sampleRate:n,maxBitrate:e.getUint32(4),avgBitrate:e.getUint32(8),pcmSampleDepth:t[12],sampleCount:X0[i],channelLayout:o,numberOfChannels:c}},G0=t=>fc(t)+fc(t&W0);const yf=["avc","hevc","vp9","av1","vp8","prores"],ja=["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"],Q0=["aac","opus","mp3","vorbis","flac","ac3","eac3","dts"],bf=[...Q0,...ja],wf=[{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}],$i=[{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}],vf=".01.01.01.01.00",Af=".0.110.01.01.01.0",Dc=["ap4x","ap4h","apch","apcn","apcs","apco"],xf=["dtsc","dtsh","dtsl","dtse"],Nc=t=>{const{codec:e,codecDescription:n,colorSpace:r,avcCodecInfo:i,hevcCodecInfo:s,vp9CodecInfo:a,av1CodecInfo:o,proresFormat:c}=t;if(e==="avc"){if(N(t.avcType!==null),i){const u=new Uint8Array([i.avcProfileIndication,i.profileCompatibility,i.avcLevelIndication]);return`avc${t.avcType}.${_s(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}.${_s(n.subarray(1,4))}`}else if(e==="hevc"){let u,l,d,f,h,p;if(s)u=s.generalProfileSpace,l=s.generalProfileIdc,d=zu(s.generalProfileCompatibilityFlags),f=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=et(n),y=g.getUint8(1);u=y>>6&3,l=y&31,d=zu(g.getUint32(2)),f=y>>5&1,h=g.getUint8(12),p=[];for(let w=0;w<6;w++)p.push(g.getUint8(6+w))}let m="hev1.";for(m+=["","A","B","C"][u]+l,m+=".",m+=d.toString(16).toUpperCase(),m+=".",m+=f===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 w=t.width*t.height;let A=Yt($i).level;for(const b of $i)if(w<=b.maxPictureSize){A=b.level;break}return`vp09.00.${A.toString().padStart(2,"0")}.08`}const u=a.profile.toString().padStart(2,"0"),l=a.level.toString().padStart(2,"0"),d=a.bitDepth.toString().padStart(2,"0"),f=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 y=`vp09.${u}.${l}.${d}.${f}`;return y+=`.${h}.${p}.${m}.${g}`,y.endsWith(vf)&&(y=y.slice(0,-vf.length)),y}else if(e==="av1"){if(!o){const b=t.width*t.height;let v=Yt($i).level;for(const x of $i)if(b<=x.maxPictureSize){v=x.level;break}return`av01.0.${v.toString().padStart(2,"0")}M.08`}const u=o.profile,l=o.level.toString().padStart(2,"0"),d=o.tier?"H":"M",f=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?rc[r.primaries]:1,g=r?.transfer?ic[r.transfer]:1,y=r?.matrix?sc[r.matrix]:1,w=r?.fullRange?1:0;let A=`av01.${u}.${l}${d}.${f}`;return A+=`.${h}.${p.toString().padStart(3,"0")}`,A+=`.${m.toString().padStart(2,"0")}`,A+=`.${g.toString().padStart(2,"0")}`,A+=`.${y.toString().padStart(2,"0")}`,A+=`.${w}`,A.endsWith(Af)&&(A=A.slice(0,-Af.length)),A}else{if(e==="prores")return c??"apch";e!==null&&Ca(e)}}throw new TypeError(`Unhandled codec '${e}'.`)},kf=t=>{switch(t.codec){case"avc":{let e=t.avcCodecInfo?.sequenceParameterSets[0];if(!e&&t.codecDescription&&(e=tf(t.codecDescription)?.sequenceParameterSets[0]),e){const n=Oa(e);if(n)return{primaries:ur[n.colourPrimaries],transfer:fr[n.transferCharacteristics],matrix:dr[n.matrixCoefficients],fullRange:!!n.fullRangeFlag}}}break;case"hevc":{let e=t.hevcCodecInfo?.arrays.find(n=>n.nalUnitType===vt.SPS_NUT)?.nalUnits[0];if(!e&&t.codecDescription&&(e=A0(t.codecDescription)?.arrays.find(n=>n.nalUnitType===vt.SPS_NUT)?.nalUnits[0]),e){const n=Ec(e);if(n)return{primaries:ur[n.colourPrimaries],transfer:fr[n.transferCharacteristics],matrix:dr[n.matrixCoefficients],fullRange:!!n.fullRangeFlag}}}break;case"vp8":break;case"vp9":if(t.vp9CodecInfo)return{primaries:ur[t.vp9CodecInfo.colourPrimaries],transfer:fr[t.vp9CodecInfo.transferCharacteristics],matrix:dr[t.vp9CodecInfo.matrixCoefficients],fullRange:!!t.vp9CodecInfo.videoFullRangeFlag};break;case"av1":if(t.av1CodecInfo)return{primaries:ur[t.av1CodecInfo.colourPrimaries],transfer:fr[t.av1CodecInfo.transferCharacteristics],matrix:dr[t.av1CodecInfo.matrixCoefficients],fullRange:!!t.av1CodecInfo.videoFullRangeFlag};break;case"prores":if(t.proresCodecInfo)return{primaries:ur[t.proresCodecInfo.colourPrimaries],transfer:fr[t.proresCodecInfo.transferCharacteristics],matrix:dr[t.proresCodecInfo.matrixCoefficients],fullRange:t.proresCodecInfo.fullRange};break}return{primaries:void 0,transfer:void 0,matrix:void 0,fullRange:void 0}},Lc=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=Qu(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&&ja.includes(e))return e}throw new TypeError(`Unhandled codec '${e}'.`)},qa=48e3,Tf=/^pcm-([usf])(\d+)(be)?$/,Y0=t=>{if(N(ja.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=Tf.exec(t);N(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}},Bs=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":Dc.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":xf.includes(t)?"dts":t==="ulaw"?"ulaw":t==="alaw"?"alaw":Tf.test(t)?t:t==="webvtt"?"webvtt":null;const fi=4,K0=[44100,48e3,32e3],Z0=[-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],Sf=1483304551,Pf=1231971951,J0=(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,eg=(t,e,n,r)=>e===0?0:e===1?144*n/(r<<t):e===2?144*n/r:12*n/r*4,_f=(t,e)=>t===3?e===3?21:36:e===3?13:21,Uc=(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,d=(i>>2&3)%3,f=i>>1&1,h=s>>6&3,p=s>>4&3,m=s>>3&1,g=s>>2&1,y=s&3,w=Z0[a*16*4+u*16+l];if(w===-1)return{header:null,bytesAdvanced:1};const A=w*1e3,b=K0[d]>>a+o,v=J0(a,u,A,b,f);if(e!==null&&e<v)return{header:null,bytesAdvanced:1};let x;return c===3?x=u===3?384:1152:u===3?x=384:u===2?x=1152:x=576,{header:{totalSize:v,mpegVersionId:c,lowSamplingFrequency:a,layer:u,bitrate:A,frequencyIndex:d,sampleRate:b,channel:h,modeExtension:p,copyright:m,original:g,emphasis:y,audioSamplesInFrame:x},bytesAdvanced:1}},Oc=t=>{let e=2130706432,n=0;for(;e!==0;)n>>=1,n|=t&e,e>>=8;return n};var Xa;(function(t){t[t.FrameCount=1]="FrameCount",t[t.FileSize=2]="FileSize",t[t.Toc=4]="Toc"})(Xa||(Xa={}));const Fs=t=>t===3?1:2;class mr{constructor(e){this.input=e}dispose(){}}const cn=new Uint8Array(0);class kt{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===cn&&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===cn}get microsecondTimestamp(){return Math.trunc(Wi*this.timestamp)}get microsecondDuration(){return Math.trunc(Wi*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 kt(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 kt(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 tg=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},Ef=t=>{const e=et(t);let n=0;const r=e.getUint8(n);n+=1,n+=3;const i=_s(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(_s(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)}},Mf=(t,e)=>t.systemId===e.systemId&&f0(t.data,e.data);const Gi=8,Ds=16,Vr=t=>{let e=ve(t);const n=mt(t,4);let r=8;e===1&&(e=un(t),r=16);const s=e-r;return s<0?null:{name:n,totalSize:e,headerSize:r,contentSize:s}},di=t=>bi(t)/65536,zc=t=>bi(t)/1073741824,Hc=t=>{let e=0;for(let n=0;n<4;n++){e<<=7;const r=Se(t);if(e|=r&127,(r&128)===0)break}return e},Xn=t=>{let e=At(t);return t.skip(2),e=Math.min(e,t.remainingLength),Kt.decode(Ee(t,e))},ng=t=>{const e=Vr(t);if(!e||e.name!=="data"||t.remainingLength<8)return null;const n=ve(t);t.skip(4);const r=Ee(t,e.contentSize-8);switch(n){case 1:return Kt.decode(r);case 2:return new TextDecoder("utf-16be").decode(r);case 13:return new Fa(r,"image/jpeg");case 14:return new Fa(r,"image/png");case 27:return new Fa(r,"image/bmp");default:return r}};const $n=16,pr=new Uint32Array(256),Qi=new Uint32Array(256),Yi=new Uint32Array(256),Ki=new Uint32Array(256),Zi=new Uint32Array(256),Bt=new Uint32Array(256),Cf=new Uint32Array(10);let If=!1;const rg=()=>{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);pr[s]=a<<24|a<<16|a<<8|a,Bt[s]=o<<24|o<<16|o<<8|o;const c=r(o,14),u=r(o,9),l=r(o,13),d=r(o,11),f=c<<24|u<<16|l<<8|d;Qi[s]=f,Yi[s]=f>>>8|f<<24,Ki[s]=f>>>16|f<<16,Zi[s]=f>>>24|f<<8}let i=1;for(let s=0;s<10;s++)Cf[s]=i<<24,i=i<<1^(i&128?283:0);If=!0};class Rf{constructor(){this.roundkey=new Uint32Array(44),this.iv=new Uint32Array($n/Uint32Array.BYTES_PER_ELEMENT),this.in=new Uint8Array($n),this.out=new Uint8Array($n),this.inView=new DataView(this.in.buffer),this.outView=new DataView(this.out.buffer)}init({key:e,iv:n}){N(e.byteLength===16),N(n.byteLength===16),If||rg();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]^pr[a>>>16&255]&4278190080^pr[a>>>8&255]&16711680^pr[a>>>0&255]&65280^pr[a>>>24&255]&255^Cf[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]=Qi[pr[o>>>24&255]&255]^Yi[pr[o>>>16&255]&255]^Ki[pr[o>>>8&255]&255]^Zi[pr[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,d,f;for(let y=1;y<10;y++){const w=y*4;u=Qi[e>>>24]^Yi[i>>>16&255]^Ki[r>>>8&255]^Zi[n&255]^this.roundkey[w],l=Qi[n>>>24]^Yi[e>>>16&255]^Ki[i>>>8&255]^Zi[r&255]^this.roundkey[w+1],d=Qi[r>>>24]^Yi[n>>>16&255]^Ki[e>>>8&255]^Zi[i&255]^this.roundkey[w+2],f=Qi[i>>>24]^Yi[r>>>16&255]^Ki[n>>>8&255]^Zi[e&255]^this.roundkey[w+3],e=u,n=l,r=d,i=f}const h=Bt[e>>>24&255]&4278190080^Bt[i>>>16&255]&16711680^Bt[r>>>8&255]&65280^Bt[n>>>0&255]&255^this.roundkey[40],p=Bt[n>>>24&255]&4278190080^Bt[e>>>16&255]&16711680^Bt[i>>>8&255]&65280^Bt[r>>>0&255]&255^this.roundkey[41],m=Bt[r>>>24&255]&4278190080^Bt[n>>>16&255]&16711680^Bt[e>>>8&255]&65280^Bt[i>>>0&255]&255^this.roundkey[42],g=Bt[i>>>24&255]&4278190080^Bt[r>>>16&255]&16711680^Bt[n>>>8&255]&65280^Bt[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 ig=(t,e,n)=>{let r=!1,i=0;const s=2**16,a=16,o=new Rf;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(le(l)&&(l=await l),!l||l.length===0)throw new Error("Invalid ciphertext.");const d=l.length;if(d%16!==0)throw new Error("Invalid ciphertext.");const f=d===u?d-a:d,h=Ee(l,f),p=new Uint8Array(f);for(let m=0;m<f;m+=16)o.in.set(h.subarray(m,m+16)),o.decrypt(),p.set(o.out,m);if(f<d)c.enqueue(p),i+=f;else{const m=p[f-1];if(m===0||m>16)throw new Error("Invalid PKCS#7 padding. Incorrect key or corrupted data.");const g=p.subarray(0,f-m);c.enqueue(g),c.close(),n()}},cancel:()=>{n()}})};class bu extends mr{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 tg({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,Gi,Ds);if(le(i)&&(i=await i),!i)break;const s=e,a=Vr(i);if(!a)break;if(a.name==="ftyp"||a.name==="styp"){const o=mt(i,4);this.isQuickTime=o==="qt "}else if(a.name==="moov"){let o=this.reader.requestSlice(i.filePos,a.contentSize);if(le(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){N(this.reader.fileSize!==null);let i=this.reader.requestSlice(this.reader.fileSize-4,4);le(i)&&(i=await i),N(i);const s=ve(i),a=this.reader.fileSize-s;if(a>=0&&a<=this.reader.fileSize-Ds){let o=this.reader.requestSliceRange(a,Gi,Ds);if(le(o)&&(o=await o),o){const c=Vr(o);if(c&&c.name==="mfra"){let u=this.reader.requestSlice(o.filePos,c.contentSize);le(u)&&(u=await u),u&&this.readContiguousBoxes(u)}}}}})()}async copyMetadataFromInitInput(e){const n=await e._getDemuxer();if(n.constructor!==bu)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(N(i.info),i.info.type==="video"&&i.info.width!==-1){const s=i;i.trackBacking=new Ff(s),this.tracks.push(i)}else if(i.info.type==="audio"&&i.info.numberOfChannels!==-1){const s=i;i.trackBacking=new Df(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;N(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&&ja.includes(e.info.codec)&&n.sampleCompositionTimeOffsets.length===0){N(e.info?.type==="audio");const s=Y0(e.info.codec),a=[],o=[];for(let c=0;c<n.sampleToChunk.length;c++){const u=n.sampleToChunk[c],l=n.sampleToChunk[c+1],d=(l?l.startChunkIndex:n.chunkOffsets.length)-u.startChunkIndex;for(let f=0;f<d;f++){const h=u.startSampleIndex+f*u.samplesPerChunk,p=h+u.samplesPerChunk,m=Ge(n.sampleTimingEntries,h,S=>S.startIndex),g=n.sampleTimingEntries[m],y=Ge(n.sampleTimingEntries,p,S=>S.startIndex),w=n.sampleTimingEntries[y],A=g.startDecodeTimestamp+(h-g.startIndex)*g.delta,v=w.startDecodeTimestamp+(p-w.startIndex)*w.delta-A,x=Yt(a);x&&x.delta===v?x.count++:a.push({startIndex:u.startChunkIndex+f,startDecodeTimestamp:A,count:1,delta:v});const P=u.samplesPerChunk*s.sampleSize*e.info.numberOfChannels;o.push(P)}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,Gi,Ds);le(n)&&(n=await n),N(n);const r=Vr(n);N(r?.name==="moof");let i=this.reader.requestSlice(e,r.totalSize);le(i)&&(i=await i),N(i),this.traverseBox(i);const s=this.lastReadFragment;N(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(d=>d.moofOffset===s.moofOffset);if(l)Wc(a,l.timestamp);else{const d=Ge(c,s.moofOffset-1,f=>f.moofOffset);if(d!==-1){const f=c[d];Wc(a,f.endTimestamp)}}a.startTimestampIsFinal=!0}const u=Ge(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 Uf(this.reader,o.encryptionInfo,a.encryptionAuxInfo);for(let d=0;d<Math.min(a.samples.length,l.length);d++){const f=l[d];a.samples[d].encryption=f}}}return s}readContiguousBoxes(e){const n=e.filePos;for(;e.filePos-n<=e.length-Gi&&this.traverseBox(e););}*iterateContiguousBoxes(e){const n=e.filePos;for(;e.filePos-n<=e.length-Gi;){const r=e.filePos,i=Vr(e);if(!i)break;yield{boxInfo:i,slice:e},e.filePos=r+i.totalSize}}traverseBox(e){const n=e.filePos,r=Vr(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=Se(e);e.skip(3),a===1?(e.skip(16),this.movieTimescale=ve(e),this.movieDurationInTimescale=un(e)):(e.skip(8),this.movieTimescale=ve(e),this.movieDurationInTimescale=ve(e))}break;case"trak":{const a={id:-1,demuxer:this,trackBacking:null,disposition:{...hr,primary:!1},info:null,timescale:-1,durationInMovieTimescale:-1,durationInMediaTimescale:-1,rotation:0,internalCodecId:null,name:null,languageCode:qt,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 Ff(o),this.tracks.push(a)}else if(a.info.type==="audio"&&a.info.numberOfChannels!==-1){const o=a;a.trackBacking=new Df(o),this.tracks.push(a)}}this.currentTrack=null}break;case"tkhd":{const a=this.currentTrack;if(!a)break;const o=Se(e),u=!!(vr(e)&1);if(a.disposition.default=u,o===0)e.skip(8),a.id=ve(e),e.skip(4),a.durationInMovieTimescale=ve(e);else if(o===1)e.skip(16),a.id=ve(e),e.skip(4),a.durationInMovieTimescale=un(e);else throw new Error(`Incorrect track header version ${o}.`);e.skip(16);const l=[di(e),di(e),zc(e),di(e),di(e),zc(e),di(e),di(e),zc(e)],d=tc(lc(cg(l),90));N(d===0||d===90||d===180||d===270),a.rotation=d}break;case"elst":{const a=this.currentTrack;if(!a)break;const o=Se(e);e.skip(3);let c=!1,u=0;const l=ve(e);for(let d=0;d<l;d++){const f=o===1?un(e):ve(e),h=o===1?Z1(e):bi(e),p=di(e);if(c){Be._warn("Unsupported edit list: multiple edits are not currently supported. Only using first edit.");break}if(h===-1){u+=f;continue}if(p!==1){Be._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=Se(e);e.skip(3),o===0?(e.skip(8),a.timescale=ve(e),a.durationInMediaTimescale=ve(e)):o===1&&(e.skip(16),a.timescale=ve(e),a.durationInMediaTimescale=un(e));let c=At(e);if(c>0){a.languageCode="";for(let u=0;u<3;u++)a.languageCode=String.fromCharCode(96+(c&31))+a.languageCode,c>>=5;qu(a.languageCode)||(a.languageCode=qt)}}break;case"hdlr":{const a=this.currentTrack;if(!a)break;e.skip(8);const o=mt(e,4);o==="vide"?a.info={type:"video",width:-1,height:-1,squarePixelWidth:-1,squarePixelHeight:-1,codec:null,codecDescription:null,colorSpace:{...Ou},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=Se(e);e.skip(3);const c=ve(e);for(let u=0;u<c;u++){const l=e.filePos,d=Vr(e);if(!d)break;a.internalCodecId=d.name;const f=d.name.toLowerCase();if(a.info.type==="video"){e.skip(24),a.info.width=At(e),a.info.height=At(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+d.totalSize-e.filePos));const h=f==="encv"?a.frmaCodecString:f;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":Dc.includes(f)?(a.info.codec="prores",a.info.proresFormat=f):h===null?Be._warn("Unknown encrypted video codec due to missing frma box."):Be._warn(`Unsupported video codec (sample entry type '${d.name}').`)}else{e.skip(8);const h=At(e);e.skip(6);let p=At(e),m=At(e);e.skip(4);let g=ve(e)/65536,y=null;o===0&&h>0&&(h===1?(e.skip(4),m=8*ve(e),e.skip(8)):h===2&&(e.skip(4),g=Xd(e),p=ve(e),e.skip(4),m=ve(e),y=ve(e),e.skip(8))),a.info.numberOfChannels=p,a.info.sampleRate=g,a.frmaCodecString=null,this.readContiguousBoxes(e.slice(e.filePos,l+d.totalSize-e.filePos));const w=f==="enca"?a.frmaCodecString:f;if(a.frmaCodecString=null,w!=="mp4a")if(w==="opus")a.info.codec="opus",a.info.sampleRate=qa;else if(w==="flac")a.info.codec="flac";else if(w==="ulaw")a.info.codec="ulaw";else if(w==="alaw")a.info.codec="alaw";else if(w==="ac-3")a.info.codec="ac3";else if(w==="ec-3")a.info.codec="eac3";else if(xf.includes(w))a.info.codec="dts",a.info.dtsFormat=w;else if(w==="twos")m===8?a.info.codec="pcm-s8":m===16?a.info.codec=a.info.pcmLittleEndian?"pcm-s16":"pcm-s16be":(Be._warn(`Unsupported sample size ${m} for codec 'twos'.`),a.info.codec=null);else if(w==="sowt")m===8?a.info.codec="pcm-s8":m===16?a.info.codec="pcm-s16":(Be._warn(`Unsupported sample size ${m} for codec 'sowt'.`),a.info.codec=null);else if(w==="raw ")a.info.codec="pcm-u8";else if(w==="in24")a.info.codec=a.info.pcmLittleEndian?"pcm-s24":"pcm-s24be";else if(w==="in32")a.info.codec=a.info.pcmLittleEndian?"pcm-s32":"pcm-s32be";else if(w==="fl32")a.info.codec=a.info.pcmLittleEndian?"pcm-f32":"pcm-f32be";else if(w==="fl64")a.info.codec=a.info.pcmLittleEndian?"pcm-f64":"pcm-f64be";else if(w==="ipcm"){const A=a.info.pcmSampleSize;a.info.pcmLittleEndian?A===16?a.info.codec="pcm-s16":A===24?a.info.codec="pcm-s24":A===32?a.info.codec="pcm-s32":(Be._warn(`Invalid ipcm sample size ${A}.`),a.info.codec=null):A===16?a.info.codec="pcm-s16be":A===24?a.info.codec="pcm-s24be":A===32?a.info.codec="pcm-s32be":(Be._warn(`Invalid ipcm sample size ${A}.`),a.info.codec=null)}else if(w==="fpcm"){const A=a.info.pcmSampleSize;a.info.pcmLittleEndian?A===32?a.info.codec="pcm-f32":A===64?a.info.codec="pcm-f64":(Be._warn(`Invalid fpcm sample size ${A}.`),a.info.codec=null):A===32?a.info.codec="pcm-f32be":A===64?a.info.codec="pcm-f64be":(Be._warn(`Invalid fpcm sample size ${A}.`),a.info.codec=null)}else if(w==="lpcm"&&y!==null){const A=m+7>>3,b=!!(y&1),v=!!(y&2),x=y&4?-1:0;m>0&&m<=64&&(b?m===32&&(a.info.codec=v?"pcm-f32be":"pcm-f32"):x&1<<A-1?A===1?a.info.codec="pcm-s8":A===2?a.info.codec=v?"pcm-s16be":"pcm-s16":A===3?a.info.codec=v?"pcm-s24be":"pcm-s24":A===4&&(a.info.codec=v?"pcm-s32be":"pcm-s32"):A===1&&(a.info.codec="pcm-u8")),a.info.codec===null&&Be._warn("Unsupported PCM format.")}else w===null?Be._warn("Unknown encrypted audio codec due to missing frma box."):Be._warn(`Unsupported audio codec (sample entry type '${d.name}').`)}e.filePos=l+d.totalSize}}break;case"frma":{const a=this.currentTrack;if(!a)break;const c=mt(e,4).toLowerCase();a.frmaCodecString=c}break;case"schm":{const a=this.currentTrack;if(!a)break;e.skip(4);const o=mt(e,4);o==="cenc"||o==="cens"||o==="cbcs"?a.encryptionInfo={scheme:o,defaultKid:null,defaultIsProtected:null,defaultPerSampleIvSize:null,defaultConstantIv:null,defaultCryptByteBlock:null,defaultSkipByteBlock:null}:Be._warn(`Unsupported encryption scheme '${o}'.`)}break;case"tenc":{const a=this.currentTrack;if(!a||!a.encryptionInfo)break;const o=Se(e);e.skip(3),e.skip(1);const c=Se(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=Se(e)!==0,a.encryptionInfo.defaultPerSampleIvSize=Se(e),a.encryptionInfo.defaultKid=_s(Ee(e,16)),a.encryptionInfo.defaultIsProtected&&a.encryptionInfo.defaultPerSampleIvSize===0){const u=Se(e),l=new Uint8Array(16);l.set(Ee(e,u),0),a.encryptionInfo.defaultConstantIv=l}}break;case"avcC":{const a=this.currentTrack;if(!a||(N(a.info),r.contentSize===0))break;a.info.codecDescription=Ee(e,r.contentSize)}break;case"hvcC":{const a=this.currentTrack;if(!a||(N(a.info),r.contentSize===0))break;a.info.codecDescription=Ee(e,r.contentSize)}break;case"vpcC":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="video"),e.skip(4);const o=Se(e),c=Se(e),u=Se(e),l=u>>4,d=u>>1&7,f=u&1,h=Se(e),p=Se(e),m=Se(e);a.info.vp9CodecInfo={profile:o,level:c,bitDepth:l,chromaSubsampling:d,videoFullRangeFlag:f,colourPrimaries:h,transferCharacteristics:p,matrixCoefficients:m}}break;case"av1C":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="video"),e.skip(1);const o=Se(e),c=o>>5,u=o&31,l=Se(e),d=l>>7,f=l>>6&1,h=l>>5&1,p=l>>4&1,m=l>>3&1,g=l>>2&1,y=l&3,w=c===2&&f?h?12:10:f?10:8;e.skip(1);const A=Ee(e,r.contentSize-4),b=Cc(A);a.info.av1CodecInfo={profile:c,level:u,tier:d,bitDepth:w,monochrome:p,chromaSubsamplingX:m,chromaSubsamplingY:g,chromaSamplePosition:y,videoFullRangeFlag:b?.videoFullRangeFlag??0,colourPrimaries:b?.colourPrimaries??2,transferCharacteristics:b?.transferCharacteristics??2,matrixCoefficients:b?.matrixCoefficients??2}}break;case"colr":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="video");const o=mt(e,4);if(o!=="nclx"&&o!=="nclc")break;const c=At(e),u=At(e),l=At(e);let d;o==="nclx"&&(d=!!(Se(e)&128)),a.info.colorSpace={primaries:ur[c],transfer:fr[u],matrix:dr[l],fullRange:d}}break;case"pasp":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="video");const o=ve(e),c=ve(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=Se(e);N(o===3),Hc(e),e.skip(2);const c=Se(e),u=(c&128)!==0,l=(c&64)!==0,d=(c&32)!==0;if(u&&e.skip(2),l){const g=Se(e);e.skip(g)}d&&e.skip(2);const f=Se(e);N(f===4);const h=Hc(e),p=e.filePos,m=Se(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":Be._warn(`Unsupported audio codec (objectTypeIndication ${m}) - discarding track.`),e.skip(12),h>e.filePos-p){const g=Se(e);N(g===5);const y=Hc(e);if(a.info.codecDescription=Ee(e,y),a.info.codec==="aac"){const w=Qu(a.info.codecDescription);w.outputNumberOfChannels!==null&&(a.info.numberOfChannels=w.outputNumberOfChannels),w.outputSampleRate!==null&&(a.info.sampleRate=w.outputSampleRate)}}}break;case"enda":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="audio"),a.info.pcmLittleEndian=!!(At(e)&255)}break;case"pcmC":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="audio"),e.skip(4);const o=Se(e);a.info.pcmLittleEndian=!!(o&1),a.info.pcmSampleSize=Se(e)}break;case"dOps":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="audio"),e.skip(1);const o=Se(e),c=At(e),u=ve(e),l=fl(e),d=Se(e);let f;d!==0?f=Ee(e,2+o):f=new Uint8Array(0);const h=new Uint8Array(19+f.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,d),h.set(f,19),a.info.codecDescription=h,a.info.numberOfChannels=o}break;case"dfLa":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="audio"),e.skip(4);const o=127,c=128,u=e.filePos;for(;e.filePos<s;){const p=Se(e),m=vr(e);if((p&o)===Xi.STREAMINFO){e.skip(10);const y=ve(e),w=y>>>12,A=(y>>9&7)+1;a.info.sampleRate=w,a.info.numberOfChannels=A,e.skip(20)}else e.skip(m);if(p&c)break}const l=e.filePos;e.filePos=u;const d=Ee(e,l-u),f=new Uint8Array(4+d.byteLength);new DataView(f.buffer).setUint32(0,1716281667,!1),f.set(d,4),a.info.codecDescription=f}break;case"dac3":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="audio");const o=Ee(e,3),c=new Qe(o),u=c.readBits(2);c.skipBits(8);const l=c.readBits(3),d=c.readBits(1);u<3&&(a.info.sampleRate=Da[u]),a.info.numberOfChannels=Bc[l]+d}break;case"dec3":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="audio");const o=Ee(e,r.contentSize),c=F0(o);if(!c){Be._warn("Invalid dec3 box contents, ignoring.");break}const u=uf(c);u!==null&&(a.info.sampleRate=u),a.info.numberOfChannels=ff(c)}break;case"ddts":{const a=this.currentTrack;if(!a)break;N(a.info?.type==="audio");const o=Ee(e,Math.min(r.contentSize,hf)),c=$0(o);if(!c){Be._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=ve(e);let c=0,u=0;for(let l=0;l<o;l++){const d=ve(e),f=ve(e);a.sampleTable.sampleTimingEntries.push({startIndex:c,startDecodeTimestamp:u,count:d,delta:f}),c+=d,u+=d*f}}break;case"ctts":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4);const o=ve(e);let c=0;for(let u=0;u<o;u++){const l=ve(e),d=bi(e);a.sampleTable.sampleCompositionTimeOffsets.push({startIndex:c,count:l,offset:d}),c+=l}}break;case"stsz":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4);const o=ve(e),c=ve(e);if(o===0)for(let u=0;u<c;u++){const l=ve(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=Se(e),c=ve(e),u=Ee(e,Math.ceil(c*o/8)),l=new Qe(u);for(let d=0;d<c;d++){const f=l.readBits(o);a.sampleTable.sampleSizes.push(f)}}break;case"stss":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4),a.sampleTable.keySampleIndices=[];const o=ve(e);for(let c=0;c<o;c++){const u=ve(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=ve(e);for(let u=0;u<o;u++){const l=ve(e)-1,d=ve(e),f=ve(e);a.sampleTable.sampleToChunk.push({startSampleIndex:-1,startChunkIndex:l,samplesPerChunk:d,sampleDescriptionIndex:f})}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 d=a.sampleTable.sampleToChunk[u+1].startChunkIndex-a.sampleTable.sampleToChunk[u].startChunkIndex;c+=d*a.sampleTable.sampleToChunk[u].samplesPerChunk}}break;case"stco":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4);const o=ve(e);for(let c=0;c<o;c++){const u=ve(e);a.sampleTable.chunkOffsets.push(u)}}break;case"co64":{const a=this.currentTrack;if(!a||!a.sampleTable)break;e.skip(4);const o=ve(e);for(let c=0;c<o;c++){const u=un(e);a.sampleTable.chunkOffsets.push(u)}}break;case"mvex":this.isFragmented=!0,this.readContiguousBoxes(e.slice(i,r.contentSize));break;case"mehd":{const a=Se(e);e.skip(3);const o=a===1?un(e):ve(e);this.movieDurationInTimescale=o}break;case"trex":{e.skip(4);const a=ve(e),o=ve(e),c=ve(e),u=ve(e),l=ve(e);this.fragmentTrackDefaults.push({trackId:a,defaultSampleDescriptionIndex:o,defaultSampleDuration:c,defaultSampleSize:u,defaultSampleFlags:l})}break;case"tfra":{const a=Se(e);e.skip(3);const o=ve(e),c=this.tracks.find(w=>w.id===o);if(!c)break;const u=ve(e),l=(u&48)>>4,d=(u&12)>>2,f=u&3,h=[Se,At,vr,ve],p=h[l],m=h[d],g=h[f],y=ve(e);for(let w=0;w<y;w++){const A=a===1?un(e):ve(e),b=a===1?un(e):ve(e);p(e),m(e),g(e),c.fragmentLookupTable.push({timestamp:A,moofOffset:b})}c.fragmentLookupTable.sort((w,A)=>w.timestamp-A.timestamp);for(let w=0;w<c.fragmentLookupTable.length-1;w++){const A=c.fragmentLookupTable[w],b=c.fragmentLookupTable[w+1];A.timestamp===b.timestamp&&(c.fragmentLookupTable.splice(w+1,1),w--)}}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(N(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,d)=>({presentationTimestamp:l.presentationTimestamp,sampleIndex:d})).sort((l,d)=>l.presentationTimestamp-d.presentationTimestamp);for(let l=0;l<a.presentationTimestamps.length;l++){const d=a.presentationTimestamps[l],f=a.samples[d.sampleIndex];if(a.firstKeyFrameTimestamp===null&&f.isKeyFrame&&(a.firstKeyFrameTimestamp=f.presentationTimestamp),l<a.presentationTimestamps.length-1){const p=a.presentationTimestamps[l+1].presentationTimestamp-d.presentationTimestamp;f.duration=p}}const o=a.samples[a.presentationTimestamps[0].sampleIndex],c=a.samples[Yt(a.presentationTimestamps).sampleIndex];a.startTimestamp=o.presentationTimestamp,a.endTimestamp=c.presentationTimestamp+c.duration;const{currentFragmentState:u}=this.currentTrack;N(u),u.startTimestamp!==null&&(Wc(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=Ef(Ee(e,r.contentSize));this.currentFragment?this.currentFragment.psshBoxes.push(a):this.currentTrack||this.psshBoxes.push(a)}break;case"tfhd":{N(this.currentFragment),e.skip(1);const a=vr(e),o=!!(a&1),c=!!(a&2),u=!!(a&8),l=!!(a&16),d=!!(a&32),f=!!(a&65536),h=!!(a&131072),p=ve(e),m=this.tracks.find(y=>y.id===p);if(!m)break;const g=this.fragmentTrackDefaults.find(y=>y.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=un(e):h&&(m.currentFragmentState.baseDataOffset=this.currentFragment.moofOffset),c&&(m.currentFragmentState.sampleDescriptionIndex=ve(e)),u&&(m.currentFragmentState.defaultSampleDuration=ve(e)),l&&(m.currentFragmentState.defaultSampleSize=ve(e)),d&&(m.currentFragmentState.defaultSampleFlags=ve(e)),f&&(m.currentFragmentState.defaultSampleDuration=0)}break;case"tfdt":{const a=this.currentTrack;if(!a)break;N(a.currentFragmentState);const o=Se(e);e.skip(3);const c=o===0?ve(e):un(e);a.currentFragmentState.startTimestamp=c}break;case"trun":{const a=this.currentTrack;if(!a)break;N(this.currentFragment),N(a.currentFragmentState);const o=Se(e),c=vr(e),u=!!(c&1),l=!!(c&4),d=!!(c&256),f=!!(c&512),h=!!(c&1024),p=!!(c&2048),m=ve(e);let g=null;u&&(g=bi(e));let y=null;l&&(y=ve(e));let w;this.currentFragment.trackData.has(a.id)?(w=this.currentFragment.trackData.get(a.id),g!==null&&(w.currentOffset=a.currentFragmentState.baseDataOffset+g)):(w={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,w));for(let A=0;A<m;A++){let b;d?b=ve(e):(N(a.currentFragmentState.defaultSampleDuration!==null),b=a.currentFragmentState.defaultSampleDuration);let v;f?v=ve(e):(N(a.currentFragmentState.defaultSampleSize!==null),v=a.currentFragmentState.defaultSampleSize);let x;h?x=ve(e):(N(a.currentFragmentState.defaultSampleFlags!==null),x=a.currentFragmentState.defaultSampleFlags),A===0&&y!==null&&(x=y);let P=0;p&&(o===0?P=ve(e):P=bi(e));const S=!(x&65536);w.samples.push({presentationTimestamp:w.currentTimestamp+P,duration:b,byteOffset:w.currentOffset,byteSize:v,isKeyFrame:S,encryption:null}),w.currentOffset+=v,w.currentTimestamp+=b}this.currentFragment.implicitBaseDataOffset=w.currentOffset}break;case"saiz":{const a=this.currentTrack;if(!a||!a.encryptionInfo)break;if(e.skip(1),vr(e)&1){const f=mt(e,4),h=ve(e);if(f!==a.encryptionInfo.scheme||h!==0)break}const c=Se(e),u=ve(e);let l=null;c===0&&u>0&&(l=Ee(e,u));const d=Lf(a);d.defaultSampleInfoSize=c,d.sampleSizes=l,d.sampleCount=u}break;case"saio":{const a=this.currentTrack;if(!a||!a.encryptionInfo)break;const o=Se(e);if(vr(e)&1){const f=mt(e,4),h=ve(e);if(f!==a.encryptionInfo.scheme||h!==0)break}const u=ve(e);if(u===0)break;u>1&&Be._warn("Multiple saio entries are not supported; using the first offset only.");let l=o===0?ve(e):Number(un(e));this.currentFragment&&(l+=this.currentFragment.moofOffset);const d=Lf(a);d.offset=l}break;case"senc":{const a=this.currentTrack;if(!a||!a.encryptionInfo)break;N(this.currentFragment);const o=this.currentFragment.trackData.get(a.id);if(!o)break;e.skip(1);const u=!!(vr(e)&2),l=ve(e),d=a.encryptionInfo.defaultPerSampleIvSize;N(d!==null);for(let f=0;f<Math.min(l,o.samples.length);f++){const h=new Uint8Array(16);d>0?h.set(Ee(e,d),0):h.set(a.encryptionInfo.defaultConstantIv,0);let p=null;if(u){const g=At(e);p=[];for(let y=0;y<g;y++){const w=At(e),A=ve(e);p.push({clearLen:w,protectedLen:A})}}const m=o.samples[f];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]??=Xn(c):this.metadataTags.raw[o.name]??=Ee(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=Kt.decode(Ee(c,o.contentSize)):this.metadataTags.title??=Xn(c);break;case"\xA9des":this.currentTrack||(this.metadataTags.description??=Xn(c));break;case"\xA9ART":this.currentTrack||(this.metadataTags.artist??=Xn(c));break;case"\xA9alb":this.currentTrack||(this.metadataTags.album??=Xn(c));break;case"albr":this.currentTrack||(this.metadataTags.albumArtist??=Xn(c));break;case"\xA9gen":this.currentTrack||(this.metadataTags.genre??=Xn(c));break;case"\xA9day":if(!this.currentTrack){const u=new Date(Xn(c));Number.isNaN(u.getTime())||(this.metadataTags.date??=u)}break;case"\xA9cmt":this.currentTrack||(this.metadataTags.comment??=Xn(c));break;case"\xA9lyr":this.currentTrack||(this.metadataTags.lyrics??=Xn(c));break}}}break;case"meta":{if(this.currentTrack)break;const o=ve(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=ve(e);for(let o=0;o<a;o++){const c=ve(e);e.skip(4);const u=Kt.decode(Ee(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 d=ng(c);switch(this.metadataTags.raw??={},this.metadataTags.raw[u]??=d,u){case"\xA9nam":case"titl":case"com.apple.quicktime.title":case"title":typeof d=="string"&&(this.metadataTags.title??=d);break;case"\xA9des":case"desc":case"dscp":case"com.apple.quicktime.description":case"description":typeof d=="string"&&(this.metadataTags.description??=d);break;case"\xA9ART":case"com.apple.quicktime.artist":case"artist":typeof d=="string"&&(this.metadataTags.artist??=d);break;case"\xA9alb":case"albm":case"com.apple.quicktime.album":case"album":typeof d=="string"&&(this.metadataTags.album??=d);break;case"aART":case"album_artist":typeof d=="string"&&(this.metadataTags.albumArtist??=d);break;case"\xA9cmt":case"com.apple.quicktime.comment":case"comment":typeof d=="string"&&(this.metadataTags.comment??=d);break;case"\xA9gen":case"gnre":case"com.apple.quicktime.genre":case"genre":typeof d=="string"&&(this.metadataTags.genre??=d);break;case"\xA9lyr":case"lyrics":typeof d=="string"&&(this.metadataTags.lyrics??=d);break;case"\xA9day":case"rldt":case"com.apple.quicktime.creationdate":case"date":if(typeof d=="string"){const f=new Date(d);Number.isNaN(f.getTime())||(this.metadataTags.date??=f)}break;case"covr":case"com.apple.quicktime.artwork":d instanceof Fa?(this.metadataTags.images??=[],this.metadataTags.images.push({data:d.data,kind:"coverFront",mimeType:d.mimeType})):d instanceof Uint8Array&&(this.metadataTags.images??=[],this.metadataTags.images.push({data:d,kind:"coverFront",mimeType:"image/*"}));break;case"track":if(typeof d=="string"){const f=d.split("/"),h=Number.parseInt(f[0],10),p=f[1]&&Number.parseInt(f[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(d instanceof Uint8Array&&d.length>=6){const f=et(d),h=f.getUint16(2,!1),p=f.getUint16(4,!1);h>0&&(this.metadataTags.trackNumber??=h),p>0&&(this.metadataTags.tracksTotal??=p)}break;case"disc":case"disk":if(d instanceof Uint8Array&&d.length>=6){const f=et(d),h=f.getUint16(2,!1),p=f.getUint16(4,!1);h>0&&(this.metadataTags.discNumber??=h),p>0&&(this.metadataTags.discsTotal??=p)}break}}}break}return e.filePos=s,!0}}class Bf{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:(N(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 Cs(e*this.internalTrack.timescale)+this.internalTrack.editListOffset}async getPacket(e,n){const r=this.mapTimestampIntoTimescale(e),i=this.internalTrack.demuxer.getSampleTableForTrack(this.internalTrack),s=Vc(i,r),a=await this.fetchPacketForSampleIndex(s,n);return!Nf(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=Ge(c.presentationTimestamps,r,f=>f.presentationTimestamp),l=u!==-1?c.presentationTimestamps[u].sampleIndex:-1,d=u!==-1&&r<c.endTimestamp;return{sampleIndex:l,correctSampleFound:d}},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=sg(i,r),a=await this.fetchPacketForSampleIndex(s,n);return!Nf(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=cc(c.presentationTimestamps,f=>c.samples[f.sampleIndex].isKeyFrame&&f.presentationTimestamp<=r),l=u!==-1?c.presentationTimestamps[u].sampleIndex:-1,d=u!==-1&&r<c.endTimestamp;return{sampleIndex:l,correctSampleFound:d}},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=og(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 N(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=ag(r,e);if(!i)return null;let s;if(n.metadataOnly)s=cn;else{let u=this.internalTrack.demuxer.reader.requestSlice(i.sampleOffset,i.sampleSize);if(le(u)&&(u=await u),!u)return null;if(s=Ee(u,i.sampleSize),this.internalTrack.encryptionInfo){let l=null;if(this.internalTrack.encryptionAuxInfo){const d=await Uf(this.internalTrack.demuxer.reader,this.internalTrack.encryptionInfo,this.internalTrack.encryptionAuxInfo);e<d.length&&(l=d[e])}l??=Of(this.internalTrack.encryptionInfo),l&&(s=await zf(this.internalTrack,l,s,null))}}const a=(i.presentationTimestamp-this.internalTrack.editListOffset)/this.internalTrack.timescale,o=i.duration/this.internalTrack.timescale,c=new kt(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];N(s);let a;if(r.metadataOnly)a=cn;else{let l=this.internalTrack.demuxer.reader.requestSlice(s.byteOffset,s.byteSize);if(le(l)&&(l=await l),!l)return null;if(a=Ee(l,s.byteSize),this.internalTrack.encryptionInfo){const d=s.encryption??Of(this.internalTrack.encryptionInfo);d&&(a=await zf(this.internalTrack,d,a,e))}}const o=(s.presentationTimestamp-this.internalTrack.editListOffset)/this.internalTrack.timescale,c=s.duration/this.internalTrack.timescale,u=new kt(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:y}=n(e);if(y)return this.fetchPacketInFragment(e,g,s);g!==-1&&(c=e,u=g)}const l=Ge(this.internalTrack.fragmentLookupTable,r,g=>g.timestamp),d=l!==-1?this.internalTrack.fragmentLookupTable[l]:null,f=Ge(this.internalTrack.fragmentPositionCache,r,g=>g.startTimestamp),h=f!==-1?this.internalTrack.fragmentPositionCache[f]:null,p=Math.max(d?.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 A=o.trackData.get(this.internalTrack.id);if(A&&A.startTimestamp>i)break}let g=a.reader.requestSliceRange(m,Gi,Ds);if(le(g)&&(g=await g),!g)break;const y=m,w=Vr(g);if(!w)break;if(w.name==="moof"){o=await a.readFragment(y);const{sampleIndex:A,correctSampleFound:b}=n(o);if(b)return this.fetchPacketInFragment(o,A,s);A!==-1&&(c=o,u=A)}m=y+w.totalSize}if(d&&(!c||c.moofOffset<d.moofOffset)){const g=this.internalTrack.fragmentLookupTable[l-1];N(!g||g.timestamp<d.timestamp);const y=g?.timestamp??-1/0;return this.performFragmentedLookup(null,n,y,i,s)}return c?this.fetchPacketInFragment(c,u,s):null}}class Ff extends Bf{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&&_c(n.data)}else if(this.internalTrack.info.codec==="hevc"&&!this.internalTrack.info.codecDescription){const n=await this.getFirstPacket({});this.internalTrack.info.hevcCodecInfo=n&&Mc(n.data)}else if(this.internalTrack.info.codec==="vp9"&&(!this.internalTrack.info.vp9CodecInfo||!T0(this.internalTrack.info.vp9CodecInfo))){const n=await this.getFirstPacket({}),r=n&&af(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||!S0(this.internalTrack.info.av1CodecInfo))){const n=await this.getFirstPacket({}),r=n&&Cc(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&&cf(n.data)}if(!ac(this.internalTrack.info.colorSpace)){const n=kf(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:Nc(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 Df extends Bf{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&&pf(e.data)}return{codec:Lc(this.internalTrack.info),numberOfChannels:this.internalTrack.info.numberOfChannels,sampleRate:this.internalTrack.info.sampleRate,description:this.internalTrack.info.codecDescription??void 0}})():null}}const Vc=(t,e)=>{if(t.presentationTimestamps){const n=Ge(t.presentationTimestamps,e,r=>r.presentationTimestamp);return n===-1?-1:t.presentationTimestamps[n].sampleIndex}else{const n=Ge(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)}},sg=(t,e)=>{if(!t.keySampleIndices)return Vc(t,e);if(t.presentationTimestamps){const n=Ge(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(Es(t.keySampleIndices,i,a=>a)!==-1)return i}return-1}else{const n=Vc(t,e),r=Ge(t.keySampleIndices,n,i=>i);return t.keySampleIndices[r]??-1}},ag=(t,e)=>{const n=Ge(t.sampleTimingEntries,e,y=>y.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=Ge(t.sampleCompositionTimeOffsets,e,y=>y.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=Ge(t.sampleToChunk,e,y=>y.startSampleIndex),l=t.sampleToChunk[u];N(l);const d=l.startChunkIndex+Math.floor((e-l.startSampleIndex)/l.samplesPerChunk),f=t.chunkOffsets[d],h=l.startSampleIndex+(d-l.startChunkIndex)*l.samplesPerChunk;let p=0,m=f;if(t.sampleSizes.length===1)m+=c*(e-h),p+=c*l.samplesPerChunk;else for(let y=h;y<h+l.samplesPerChunk;y++){const w=t.sampleSizes[y];y<e&&(m+=w),p+=w}let g=r.delta;if(t.presentationTimestamps){const y=t.presentationTimestampIndexMap[e];N(y!==void 0),y<t.presentationTimestamps.length-1&&(g=t.presentationTimestamps[y+1].presentationTimestamp-s)}return{presentationTimestamp:s,duration:g,sampleOffset:m,sampleSize:c,chunkOffset:f,chunkSize:p,isKeyFrame:t.keySampleIndices?Es(t.keySampleIndices,e,y=>y)!==-1:!0}},og=(t,e)=>{if(!t.keySampleIndices)return e+1;const n=Ge(t.keySampleIndices,e,r=>r);return t.keySampleIndices[n+1]??-1},Wc=(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},cg=t=>{const[e,n]=t,r=Math.atan2(n,e);return Number.isFinite(r)?r*(180/Math.PI):0},Nf=t=>t.sampleSizes.length===0,Lf=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},Uf=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{N(n.sampleSizes);for(let o=0;o<n.sampleCount;o++)r+=n.sampleSizes[o]}let i=t.requestSlice(n.offset,r);if(le(i)&&(i=await i),!i)throw new Error("Failed to read auxiliary encryption info.");const s=e.defaultPerSampleIvSize;N(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(Ee(i,s),0):u.set(e.defaultConstantIv,0);let l=null;if(c>s){const d=At(i);l=[];for(let f=0;f<d;f++){const h=At(i),p=ve(i);l.push({clearLen:h,protectedLen:p})}}a.push({iv:u,subsamples:l})}return n.resolved=a,a},Of=t=>t.defaultConstantIv?{iv:t.defaultConstantIv,subsamples:null}:null,zf=async(t,e,n,r)=>{N(t.encryptionInfo);const i=t.encryptionInfo;N(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(d=>d.keyIds===null||d.keyIds.includes(s));for(let d=0;d<u.length-1;d++)for(let f=d+1;f<u.length;f++)Mf(u[d],u[f])&&(u.splice(f,1),f--)}const l=await t.demuxer.input._formatOptions.isobmff.resolveKeyId({keyId:s,psshBoxes:u});if(!(typeof l=="string"&&l.length===32&&e0.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:t0(l)})();t.demuxer.decryptionKeyCache.set(s,c),a=await c}return i.scheme==="cenc"||i.scheme==="cens"?lg(a,i,e,n):ug(a,i,e,n)},lg=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);N(e.defaultCryptByteBlock!==null&&e.defaultSkipByteBlock!==null);const o=Hf(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 d=await a(u),f=new Uint8Array(r);let h=0;for(const p of o)for(const m of p.perSubsample)f.set(d.subarray(h,h+m.length),m.offset),h+=m.length;return f},ug=(t,e,n,r)=>{const i=new Rf;i.init({key:t,iv:n.iv});const s=e.defaultCryptByteBlock,a=e.defaultSkipByteBlock;if(N(s!==null&&a!==null),!n.subsamples){const l=new Uint8Array(r),d=Math.floor(r.length/16);for(let f=0;f<d;f++){const h=f*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=Hf(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 d of l.perSubsample){const f=d.length/16;for(let h=0;h<f;h++){const p=d.offset+h*16;i.in.set(r.subarray(p,p+16)),i.decrypt(),o.set(i.out,p)}}}return o},Hf=(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 d=Math.min(16*n,c);u+=d,c-=d}s+=a.protectedLen}r.push({perSubsample:o})}return r};var ce;(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"})(ce||(ce={}));const fg=[ce.EBML,ce.Segment],Ns=[ce.SeekHead,ce.Info,ce.Cluster,ce.Tracks,ce.Cues,ce.Attachments,ce.Chapters,ce.Tags],$a=[...fg,...Ns],jc=8,bn=2,gr=2*jc,Vf=t=>{if(t.remainingLength<1)return null;const e=Se(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},Ls=t=>{if(t.remainingLength<1)return null;const e=Se(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+=Se(t);return i},He=(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+=Se(t);return n},dg=(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(Se(t));return n},qc=t=>{const e=Vf(t);return e===null||t.remainingLength<e?null:He(t,e)},Wf=t=>{if(t.remainingLength<1)return null;if(Se(t)===255)return;t.skip(-1);const n=Ls(t);if(n===null)return null;if(n!==72057594037927940)return n},yr=t=>{N(t.remainingLength>=bn);const e=qc(t);if(e===null)return null;const n=Wf(t);return n===null?null:{id:e,size:n}},Ji=(t,e)=>{const n=Ee(t,e);let r=0;for(;r<e&&n[r]!==0;)r+=1;return String.fromCharCode(...n.subarray(0,r))},Us=(t,e)=>{const n=Ee(t,e);let r=0;for(;r<e&&n[r]!==0;)r+=1;return Kt.decode(n.subarray(0,r))},Xc=(t,e)=>{if(e===0)return 0;if(e!==4&&e!==8)throw new Error("Bad float size "+e);return e===4?ey(t):Xd(t)},$c=async(t,e,n,r)=>{const i=new Set(n);let s=e;for(;r===null||s<r;){let a=t.requestSliceRange(s,bn,gr);if(le(a)&&(a=await a),!a)break;const o=yr(a);if(!o)break;if(i.has(o.id))return{pos:s,found:!0};Wr(o.size),s=a.filePos+o.size}return{pos:r!==null&&r>s?r:s,found:!1}},jf=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(le(o)&&(o=await o),!o||o.length<jc)break;for(let c=0;c<o.length-jc;c++){o.filePos=a;const u=qc(o);if(u!==null&&s.has(u))return a;a++}}return null},Zt={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 Wr(t){if(t===void 0)throw new Error("Undefined element size is used in a place where it is not supported.")}const hg=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 br;(function(t){t[t.None=0]="None",t[t.Xiph=1]="Xiph",t[t.FixedSize=2]="FixedSize",t[t.Ebml=3]="Ebml"})(br||(br={}));var Ga;(function(t){t[t.Block=1]="Block",t[t.Private=2]="Private",t[t.Next=4]="Next"})(Ga||(Ga={}));var Os;(function(t){t[t.Zlib=0]="Zlib",t[t.Bzlib=1]="Bzlib",t[t.lzo1x=2]="lzo1x",t[t.HeaderStripping=3]="HeaderStripping"})(Os||(Os={}));const Gc=[{id:ce.SeekHead,flag:"seekHeadSeen"},{id:ce.Info,flag:"infoSeen"},{id:ce.Tracks,flag:"tracksSeen"},{id:ce.Cues,flag:"cuesSeen"}],qf=10*2**20;class mg extends mr{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 hg({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,bn,gr);if(le(n)&&(n=await n),!n)break;const r=yr(n);if(!r)break;const i=r.id;let s=r.size;const a=n.filePos;if(i===ce.EBML){Wr(s);let o=this.reader.requestSlice(a,s);if(le(o)&&(o=await o),!o)break;this.readContiguousElements(o)}else if(i===ce.Segment){if(await this.readSegment(a,s),s===void 0||this.reader.fileSize===null)break}else if(i===ce.Cluster){if(this.reader.fileSize===null)break;s===void 0&&(s=(await $c(this.reader,a,$a,this.reader.fileSize)).pos-a);const o=Yt(this.segments);o&&(o.elementEndPos=a+s)}Wr(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,bn,gr);if(le(o)&&(o=await o),!o)break;const c=r,u=yr(o);if(!u||!Ns.includes(u.id)&&u.id!==ce.Void){const p=await jf(this.reader,c,Ns,Math.min(this.currentSegment.elementEndPos??1/0,c+qf));if(p){r=p;continue}else break}const{id:l,size:d}=u,f=o.filePos,h=Gc.findIndex(p=>p.id===l);if(h!==-1){const p=Gc[h].flag;this.currentSegment[p]=!0,Wr(d);let m=this.reader.requestSlice(f,d);le(m)&&(m=await m),m&&this.readContiguousElements(m)}else if(l===ce.Tags||l===ce.Attachments){l===ce.Tags?this.currentSegment.tagsSeen=!0:this.currentSegment.attachmentsSeen=!0,Wr(d);let p=this.reader.requestSlice(f,d);le(p)&&(p=await p),p&&this.readContiguousElements(p)}else if(l===ce.Cluster){this.currentSegment.clusterSeekStartPos=c;break}if(d===void 0)break;r=f+d}if(this.currentSegment.seekEntries.sort((o,c)=>o.segmentPosition-c.segmentPosition),this.reader.fileSize!==null)for(const o of this.currentSegment.seekEntries){const c=Gc.find(p=>p.id===o.id);if(!c||this.currentSegment[c.flag])continue;let u=this.reader.requestSliceRange(e+o.segmentPosition,bn,gr);if(le(u)&&(u=await u),!u)continue;const l=yr(u);if(!l)continue;const{id:d,size:f}=l;if(d!==c.id)continue;Wr(f),this.currentSegment[c.flag]=!0;let h=this.reader.requestSlice(u.filePos,f);le(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,bn,gr);le(r)&&(r=await r),N(r);const i=e,s=yr(r);N(s);const a=s.id;N(a===ce.Cluster);let o=s.size;const c=r.filePos;o===void 0&&(o=(await $c(this.reader,c,$a,n.elementEndPos)).pos-c);let u=this.reader.requestSlice(c,o);le(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 d=this.readContiguousElements(u,$a);l.elementEndPos=d}for(const[,d]of l.trackData){const f=d.track;N(d.blocks.length>0);let h=!1;for(let y=0;y<d.blocks.length;y++){const w=d.blocks[y];w.timestamp+=l.timestamp,h||=w.lacing!==br.None}d.presentationTimestamps=d.blocks.map((y,w)=>({timestamp:y.timestamp,blockIndex:w})).sort((y,w)=>y.timestamp-w.timestamp);for(let y=0;y<d.presentationTimestamps.length;y++){const w=d.presentationTimestamps[y],A=d.blocks[w.blockIndex];if(d.firstKeyFrameTimestamp===null&&A.isKeyFrame&&(d.firstKeyFrameTimestamp=A.timestamp),y<d.presentationTimestamps.length-1){const b=d.presentationTimestamps[y+1];A.duration=b.timestamp-A.timestamp}else A.duration===0&&f.defaultDuration!=null&&A.lacing===br.None&&(A.duration=f.defaultDuration)}h&&(this.expandLacedBlocks(d.blocks,f),d.presentationTimestamps=d.blocks.map((y,w)=>({timestamp:y.timestamp,blockIndex:w})).sort((y,w)=>y.timestamp-w.timestamp));const p=d.blocks[d.presentationTimestamps[0].blockIndex],m=d.blocks[Yt(d.presentationTimestamps).blockIndex];d.startTimestamp=p.timestamp,d.endTimestamp=m.timestamp+m.duration;const g=Ge(f.clusterPositionCache,d.startTimestamp,y=>y.startTimestamp);(g===-1||f.clusterPositionCache[g].elementStartPos!==i)&&f.clusterPositionCache.splice(g+1,0,{elementStartPos:l.elementStartPos,startTimestamp:d.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===br.None)continue;i.decoded||(i.data=this.decodeBlockData(n,i.data),i.decoded=!0);const s=Nn.tempFromBytes(i.data),a=[],o=Se(s)+1;switch(i.lacing){case br.Xiph:{let u=0;for(let l=0;l<o-1;l++){let d=0;for(;s.bufferPos<s.length;){const f=Se(s);if(d+=f,f<255){a.push(d),u+=d;break}}}a.push(s.length-(s.bufferPos+u))}break;case br.FixedSize:{const u=s.length-1,l=Math.floor(u/o);for(let d=0;d<o;d++)a.push(l)}break;case br.Ebml:{const u=Ls(s);N(u!==null);let l=u;a.push(l);let d=l;for(let f=1;f<o-1;f++){const h=s.bufferPos,p=Ls(s);N(p!==null);const m=p,y=(1<<(s.bufferPos-h)*7-1)-1,w=m-y;l+=w,a.push(l),d+=l}a.push(s.length-(s.bufferPos+d))}break;default:N(!1)}N(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],d=Ee(s,l),f=i.timestamp+c*u/o,h=c/o;e.splice(r+u,0,{timestamp:f,duration:h,isKeyFrame:i.isKeyFrame,data:d,lacing:br.None,decoded:!0,postProcessed:!1,mainAdditional:i.mainAdditional})}r+=o,r--}}async loadSegmentMetadata(e){for(const n of e.seekEntries){if(!(n.id===ce.Tags&&!e.tagsSeen)){if(!(n.id===ce.Attachments&&!e.attachmentsSeen))continue}let r=this.reader.requestSliceRange(e.dataStartPos+n.segmentPosition,bn,gr);if(le(r)&&(r=await r),!r)continue;const i=yr(r);if(!i||i.id!==n.id)continue;const{size:s}=i;Wr(s),N(!this.currentSegment),this.currentSegment=e;let a=this.reader.requestSlice(r.filePos,s);le(a)&&(a=await a),a&&this.readContiguousElements(a),this.currentSegment=null,n.id===ce.Tags?e.tagsSeen=!0:n.id===ce.Attachments&&(e.attachmentsSeen=!0)}}readContiguousElements(e,n){for(;e.remainingLength>=bn;){const r=e.filePos;if(!this.traverseElement(e,n))return r}return e.filePos}traverseElement(e,n){const r=yr(e);if(!r||n&&n.includes(r.id))return!1;const{id:i,size:s}=r,a=e.filePos;switch(Wr(s),i){case ce.DocType:this.isWebM=Ji(e,s)==="webm";break;case ce.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 ce.SeekID:{const o=this.currentSegment?.seekEntries[this.currentSegment.seekEntries.length-1];if(!o)break;o.id=He(e,s)}break;case ce.SeekPosition:{const o=this.currentSegment?.seekEntries[this.currentSegment.seekEntries.length-1];if(!o)break;o.segmentPosition=He(e,s)}break;case ce.TimestampScale:{if(!this.currentSegment)break;this.currentSegment.timestampScale=He(e,s),this.currentSegment.timestampFactor=1e9/this.currentSegment.timestampScale}break;case ce.Duration:{if(!this.currentSegment)break;this.currentSegment.duration=Xc(e,s)}break;case ce.TrackEntry:{if(!this.currentSegment||(this.currentTrack={id:-1,segment:this.currentSegment,demuxer:this,clusterPositionCache:[],cuePoints:[],disposition:{...hr,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!==Ga.Block||o.data.algorithm!==Os.HeaderStripping)&&(Be._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,d=this.currentTrack.info.displayHeight*this.currentTrack.info.width;l>0&&d>0&&(l>d?this.currentTrack.info.squarePixelWidth=Math.round(this.currentTrack.info.width*l/d):this.currentTrack.info.squarePixelHeight=Math.round(this.currentTrack.info.height*d/l))}if(this.currentTrack.codecId===Zt.avc)this.currentTrack.info.codec="avc",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate;else if(this.currentTrack.codecId===Zt.hevc)this.currentTrack.info.codec="hevc",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate;else if(c===Zt.vp8)this.currentTrack.info.codec="vp8";else if(c===Zt.vp9)this.currentTrack.info.codec="vp9";else if(c===Zt.av1)this.currentTrack.info.codec="av1";else if(c===Zt.prores){const l=this.currentTrack.codecPrivate?Kt.decode(this.currentTrack.codecPrivate):"";Dc.includes(l)&&(this.currentTrack.info.codec="prores",this.currentTrack.info.proresFormat=l)}const u=this.currentTrack;this.currentTrack.trackBacking=new pg(u),this.currentSegment.tracks.push(this.currentTrack)}else if(this.currentTrack.info.type==="audio"){c===Zt.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===Zt.mp3?this.currentTrack.info.codec="mp3":c===Zt.opus?(this.currentTrack.info.codec="opus",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate,this.currentTrack.info.sampleRate=qa):c===Zt.vorbis?(this.currentTrack.info.codec="vorbis",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):c===Zt.flac?(this.currentTrack.info.codec="flac",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):c===Zt.ac3?(this.currentTrack.info.codec="ac3",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):c===Zt.eac3?(this.currentTrack.info.codec="eac3",this.currentTrack.info.codecDescription=this.currentTrack.codecPrivate):c===Zt.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 gg(u),this.currentSegment.tracks.push(this.currentTrack)}}this.currentTrack=null}break;case ce.TrackNumber:{if(!this.currentTrack)break;this.currentTrack.id=He(e,s)}break;case ce.TrackType:{if(!this.currentTrack)break;const o=He(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:{...Ou},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 ce.FlagEnabled:{if(!this.currentTrack)break;He(e,s)||(this.currentTrack=null)}break;case ce.FlagDefault:{if(!this.currentTrack)break;this.currentTrack.disposition.default=!!He(e,s)}break;case ce.FlagForced:{if(!this.currentTrack)break;this.currentTrack.disposition.forced=!!He(e,s)}break;case ce.FlagOriginal:{if(!this.currentTrack)break;this.currentTrack.disposition.original=!!He(e,s)}break;case ce.FlagHearingImpaired:{if(!this.currentTrack)break;this.currentTrack.disposition.hearingImpaired=!!He(e,s)}break;case ce.FlagVisualImpaired:{if(!this.currentTrack)break;this.currentTrack.disposition.visuallyImpaired=!!He(e,s)}break;case ce.FlagCommentary:{if(!this.currentTrack)break;this.currentTrack.disposition.commentary=!!He(e,s)}break;case ce.CodecID:{if(!this.currentTrack)break;this.currentTrack.codecId=Ji(e,s)}break;case ce.CodecPrivate:{if(!this.currentTrack)break;this.currentTrack.codecPrivate=Ee(e,s)}break;case ce.DefaultDuration:{if(!this.currentTrack)break;this.currentTrack.defaultDurationNs=He(e,s)}break;case ce.Name:{if(!this.currentTrack)break;this.currentTrack.name=Us(e,s)}break;case ce.Language:{if(!this.currentTrack||this.currentTrack.hasLanguageBcp47)break;this.currentTrack.languageCode=Ji(e,s),qu(this.currentTrack.languageCode)||(this.currentTrack.languageCode=qt)}break;case ce.LanguageBCP47:{if(!this.currentTrack)break;const c=Ji(e,s).split("-")[0];c?this.currentTrack.languageCode=c:this.currentTrack.languageCode=qt,this.currentTrack.hasLanguageBcp47=!0}break;case ce.Video:{if(this.currentTrack?.info?.type!=="video")break;this.readContiguousElements(e.slice(a,s))}break;case ce.PixelWidth:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.width=He(e,s)}break;case ce.PixelHeight:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.height=He(e,s)}break;case ce.DisplayWidth:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.displayWidth=He(e,s)}break;case ce.DisplayHeight:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.displayHeight=He(e,s)}break;case ce.DisplayUnit:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.displayUnit=He(e,s)}break;case ce.AlphaMode:{if(this.currentTrack?.info?.type!=="video")break;this.currentTrack.info.alphaMode=He(e,s)===1}break;case ce.Colour:{if(this.currentTrack?.info?.type!=="video")break;this.readContiguousElements(e.slice(a,s))}break;case ce.MatrixCoefficients:{if(this.currentTrack?.info?.type!=="video")break;const o=He(e,s),c=dr[o];this.currentTrack.info.colorSpace.matrix=c}break;case ce.Range:{if(this.currentTrack?.info?.type!=="video")break;const o=He(e,s);this.currentTrack.info.colorSpace.fullRange=o===1||o===2?o===2:void 0}break;case ce.TransferCharacteristics:{if(this.currentTrack?.info?.type!=="video")break;const o=He(e,s),c=fr[o];this.currentTrack.info.colorSpace.transfer=c}break;case ce.Primaries:{if(this.currentTrack?.info?.type!=="video")break;const o=He(e,s),c=ur[o];this.currentTrack.info.colorSpace.primaries=c}break;case ce.Projection:{if(this.currentTrack?.info?.type!=="video")break;this.readContiguousElements(e.slice(a,s))}break;case ce.ProjectionPoseRoll:{if(this.currentTrack?.info?.type!=="video")break;const c=-Xc(e,s);try{this.currentTrack.info.rotation=tc(c)}catch{}}break;case ce.Audio:{if(this.currentTrack?.info?.type!=="audio")break;this.readContiguousElements(e.slice(a,s))}break;case ce.SamplingFrequency:{if(this.currentTrack?.info?.type!=="audio")break;this.currentTrack.info.sampleRate=Xc(e,s)}break;case ce.Channels:{if(this.currentTrack?.info?.type!=="audio")break;this.currentTrack.info.numberOfChannels=He(e,s)}break;case ce.BitDepth:{if(this.currentTrack?.info?.type!=="audio")break;this.currentTrack.info.bitDepth=He(e,s)}break;case ce.CuePoint:{if(!this.currentSegment)break;this.readContiguousElements(e.slice(a,s)),this.currentCueTime=null}break;case ce.CueTime:this.currentCueTime=He(e,s);break;case ce.CueTrackPositions:{if(this.currentCueTime===null)break;N(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 ce.CueTrack:{const o=this.currentSegment?.cuePoints[this.currentSegment.cuePoints.length-1];if(!o)break;o.trackId=He(e,s)}break;case ce.CueClusterPosition:{const o=this.currentSegment?.cuePoints[this.currentSegment.cuePoints.length-1];if(!o)break;N(this.currentSegment),o.clusterPosition=this.currentSegment.dataStartPos+He(e,s)}break;case ce.Timestamp:{if(!this.currentCluster)break;this.currentCluster.timestamp=He(e,s)}break;case ce.SimpleBlock:{if(!this.currentCluster)break;const o=Ls(e);if(o===null)break;const c=this.getTrackDataInCluster(this.currentCluster,o);if(!c)break;const u=fl(e),l=Se(e),d=l>>1&3;let f=!!(l&128);c.track.info?.type==="audio"&&c.track.info.codec&&(f=!0);const h=Ee(e,s-(e.filePos-a)),p=c.track.decodingInstructions.length>0;c.blocks.push({timestamp:u,duration:0,isKeyFrame:f,data:h,lacing:d,decoded:!p,postProcessed:!1,mainAdditional:null})}break;case ce.BlockGroup:{if(!this.currentCluster)break;this.readContiguousElements(e.slice(a,s)),this.currentBlock=null}break;case ce.Block:{if(!this.currentCluster)break;const o=Ls(e);if(o===null)break;const c=this.getTrackDataInCluster(this.currentCluster,o);if(!c)break;const u=fl(e),d=Se(e)>>1&3,f=Ee(e,s-(e.filePos-a)),h=c.track.decodingInstructions.length>0;this.currentBlock={timestamp:u,duration:0,isKeyFrame:!0,data:f,lacing:d,decoded:!h,postProcessed:!1,mainAdditional:null},c.blocks.push(this.currentBlock)}break;case ce.BlockAdditions:this.readContiguousElements(e.slice(a,s));break;case ce.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 ce.BlockAdditional:{if(!this.currentBlockAdditional)break;this.currentBlockAdditional.data=Ee(e,s)}break;case ce.BlockAddID:{if(!this.currentBlockAdditional)break;this.currentBlockAdditional.addId=He(e,s)}break;case ce.BlockDuration:{if(!this.currentBlock)break;this.currentBlock.duration=He(e,s)}break;case ce.ReferenceBlock:{if(!this.currentBlock)break;this.currentBlock.isKeyFrame=!1}break;case ce.Tag:this.currentTagTargetIsMovie=!0,this.readContiguousElements(e.slice(a,s));break;case ce.Targets:this.readContiguousElements(e.slice(a,s));break;case ce.TargetTypeValue:He(e,s)!==50&&(this.currentTagTargetIsMovie=!1);break;case ce.TagTrackUID:case ce.TagEditionUID:case ce.TagChapterUID:case ce.TagAttachmentUID:this.currentTagTargetIsMovie=!1;break;case ce.SimpleTag:{if(!this.currentTagTargetIsMovie)break;this.currentSimpleTagName=null,this.readContiguousElements(e.slice(a,s))}break;case ce.TagName:this.currentSimpleTagName=Us(e,s);break;case ce.TagString:{if(!this.currentSimpleTagName)break;const o=Us(e,s);this.processTagValue(this.currentSimpleTagName,o)}break;case ce.TagBinary:{if(!this.currentSimpleTagName)break;const o=Ee(e,s);this.processTagValue(this.currentSimpleTagName,o)}break;case ce.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 d0(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 ce.FileUID:{if(!this.currentAttachedFile)break;this.currentAttachedFile.fileUid=dg(e,s)}break;case ce.FileName:{if(!this.currentAttachedFile)break;this.currentAttachedFile.fileName=Us(e,s)}break;case ce.FileMediaType:{if(!this.currentAttachedFile)break;this.currentAttachedFile.fileMediaType=Ji(e,s)}break;case ce.FileData:{if(!this.currentAttachedFile)break;this.currentAttachedFile.fileData=Ee(e,s)}break;case ce.FileDescription:{if(!this.currentAttachedFile)break;this.currentAttachedFile.fileDescription=Us(e,s)}break;case ce.ContentEncodings:{if(!this.currentTrack)break;this.readContiguousElements(e.slice(a,s)),this.currentTrack.decodingInstructions.sort((o,c)=>c.order-o.order)}break;case ce.ContentEncoding:this.currentDecodingInstruction={order:0,scope:Ga.Block,data:null},this.readContiguousElements(e.slice(a,s)),this.currentDecodingInstruction.data&&this.currentTrack.decodingInstructions.push(this.currentDecodingInstruction),this.currentDecodingInstruction=null;break;case ce.ContentEncodingOrder:{if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.order=He(e,s)}break;case ce.ContentEncodingScope:{if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.scope=He(e,s)}break;case ce.ContentCompression:{if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.data={type:"decompress",algorithm:Os.Zlib,settings:null},this.readContiguousElements(e.slice(a,s))}break;case ce.ContentCompAlgo:{if(this.currentDecodingInstruction?.data?.type!=="decompress")break;this.currentDecodingInstruction.data.algorithm=He(e,s)}break;case ce.ContentCompSettings:{if(this.currentDecodingInstruction?.data?.type!=="decompress")break;this.currentDecodingInstruction.data.settings=Ee(e,s)}break;case ce.ContentEncryption:{if(!this.currentDecodingInstruction)break;this.currentDecodingInstruction.data={type:"decrypt"}}break}return e.filePos=a+s,!0}decodeBlockData(e,n){N(e.decodingInstructions.length>0);let r=n;for(const i of e.decodingInstructions)switch(N(i.data),i.data.type){case"decompress":switch(i.data.algorithm){case Os.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){N(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 Xf{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 Cs(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=Ge(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=cc(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 N(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(N(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 f=new Uint8Array(s.data.length+8);et(f).setUint32(0,f.length,!1),f[4]=105,f[5]=99,f[6]=112,f[7]=102,f.set(s.data,8),s.data=f}s.postProcessed=!0}const a=r.metadataOnly?cn: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?cn:s.mainAdditional,u.alphaByteLength=s.mainAdditional.byteLength);const l=new kt(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:y,correctBlockFound:w}=n(e);if(w)return this.fetchPacketInCluster(e,y,s);y!==-1&&(u=e,l=y)}const d=Ge(this.internalTrack.cuePoints,r,y=>y.time),f=d!==-1?this.internalTrack.cuePoints[d]:null,h=Ge(this.internalTrack.clusterPositionCache,r,y=>y.startTimestamp),p=h!==-1?this.internalTrack.clusterPositionCache[h]:null,m=Math.max(f?.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-bn;){if(c){const S=c.trackData.get(this.internalTrack.id);if(S&&S.startTimestamp>i)break}let y=a.reader.requestSliceRange(g,bn,gr);if(le(y)&&(y=await y),!y)break;const w=g,A=yr(y);if(!A||!Ns.includes(A.id)&&A.id!==ce.Void){const S=await jf(a.reader,w,Ns,Math.min(o.elementEndPos??1/0,w+qf));if(S){g=S;continue}else break}const b=A.id;let v=A.size;const x=y.filePos;if(b===ce.Cluster){c=await a.readCluster(w,o),v=c.elementEndPos-x;const{blockIndex:S,correctBlockFound:k}=n(c);if(k)return this.fetchPacketInCluster(c,S,s);S!==-1&&(u=c,l=S)}v===void 0&&(N(b!==ce.Cluster),v=(await $c(a.reader,x,$a,o.elementEndPos)).pos-x);const P=x+v;if(o.elementEndPos===null){let S=a.reader.requestSliceRange(P,bn,gr);if(le(S)&&(S=await S),!S)break;if(qc(S)===ce.Segment){o.elementEndPos=P;break}}g=P}if(f&&(!u||u.elementStartPos<f.clusterPosition)){const y=this.internalTrack.cuePoints[d-1];N(!y||y.time<f.time);const w=y?.time??-1/0;return this.performClusterLookup(null,n,w,i,s)}return u?this.fetchPacketInCluster(u,l,s):null}}class pg extends Xf{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?_c(e.data):null,hevcCodecInfo:this.internalTrack.info.codec==="hevc"&&e?Mc(e.data):null,vp9CodecInfo:this.internalTrack.info.codec==="vp9"&&e?af(e.data):null,av1CodecInfo:this.internalTrack.info.codec==="av1"&&e?Cc(e.data):null,proresCodecInfo:this.internalTrack.info.codec==="prores"&&e?cf(e.data):null,proresFormat:this.internalTrack.info.proresFormat};if(!ac(this.internalTrack.info.colorSpace)){const s=kf(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:Nc(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 gg extends Xf{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&&pf(e.data)}return{codec:Lc({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 Qc=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,fi,a);if(le(o)&&(o=await o),!o||o.length<fi)break;for(;o.remainingLength>=fi;){const c=o.filePos,u=ve(o),l=t.fileSize!==null?t.fileSize-s:null,d=Uc(u,l);if(d.header&&(!r||d.header.sampleRate===r.sampleRate&&d.header.mpegVersionId===r.mpegVersionId&&d.header.layer===r.layer&&Fs(d.header.channel)===Fs(r.channel)))return{header:d.header,startPos:s};o.filePos=c+d.bytesAdvanced,s=o.filePos}}return null};class yg extends mr{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 Ma,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 bg(this)]})()}async advanceReader(){if(this.lastLoadedPos===0)for(;;){let o=this.reader.requestSlice(this.lastLoadedPos,wn);if(le(o)&&(o=await o),!o){this.lastSampleLoaded=!0;return}const c=Ar(o);if(!c)break;this.lastLoadedPos=o.filePos+c.size}const e=await Qc(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=_f(n.mpegVersionId,n.channel);let i=this.reader.requestSlice(e.startPos+r,4);if(le(i)&&(i=await i),i){const o=ve(i);if(o===Sf||o===Pf){if(this.xingFrameHeader||(this.xingFrameHeader=n,this.xingFrameHeaderPos=e.startPos),!this.xingData){let u=this.reader.requestSlice(e.startPos+r+4,12);if(le(u)&&(u=await u),u){const l=Ee(u,12),d=et(l),f=d.getUint32(0,!1);this.xingData={frameCount:f&Xa.FrameCount?d.getUint32(4,!1):null,fileSize:f&Xa.FileSize?d.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,wn);if(le(i)&&(i=await i),!i)break;const s=Ar(i);if(!s)break;r=!0;let a=this.reader.requestSlice(i.filePos,s.size);if(le(a)&&(a=await a),!a)break;eo(a,s,this.metadataTags),n=i.filePos+s.size}if(!r&&this.reader.fileSize!==null&&this.reader.fileSize>=Ja){let i=this.reader.requestSlice(this.reader.fileSize-Ja,Ja);le(i)&&(i=await i),N(i),mt(i,3)==="TAG"&&ty(i,this.metadataTags)}return this.metadataTags}finally{e()}}}class bg{constructor(e){this.demuxer=e}getType(){return"audio"}getId(){return 1}getNumber(){return 1}getTimeResolution(){return N(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(N(e.firstFrameHeader!==null),N(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=eg(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 qt}getCodec(){return"mp3"}getInternalCodecId(){return null}getNumberOfChannels(){return N(this.demuxer.firstFrameHeader),Fs(this.demuxer.firstFrameHeader.channel)}getSampleRate(){return N(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.sampleRate}getDisposition(){return{...hr}}async getDecoderConfig(){return N(this.demuxer.firstFrameHeader),{codec:"mp3",numberOfChannels:Fs(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=cn;else{let s=this.demuxer.reader.requestSlice(r.dataStart,r.dataSize);if(le(s)&&(s=await s),!s)return null;i=Ee(s,r.dataSize)}return new kt(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=Es(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=Ge(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 $f=1399285583,wg=79764919,Gf=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^wg:e<<1;Gf[t]=e>>>0&4294967295}const vg=t=>{const e=et(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^Gf[r>>>24^s])>>>0}return e.setUint32(22,n,!0),r},Ag=(t,e,n)=>{let r=0,i=null;if(t.length>0)if(e.codec==="vorbis"){N(e.vorbisInfo);const s=e.vorbisInfo.modeBlockflags.length,o=(1<<s0(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 d=(o|1)+1,f=t[0]&d?1:0;u=e.vorbisInfo.blocksizes[f]}r=u!==null?u+i>>2:0}else e.codec==="opus"&&(r=E0(t).durationInSamples);return{durationInSamples:r,vorbisBlockSize:i}},xg=t=>{let e="audio/ogg";if(t.codecStrings){const n=[...new Set(t.codecStrings)];e+=`; codecs="${n.join(", ")}"`}return e};const hi=27,es=282,kg=es+65025,zs=t=>{const e=t.filePos;if(as(t)!==$f)return null;t.skip(1);const r=Se(t),i=J1(t),s=as(t),a=as(t),o=as(t),c=Se(t),u=new Uint8Array(c);for(let h=0;h<c;h++)u[h]=Se(t);const l=27+c,d=u.reduce((h,p)=>h+p,0),f=l+d;return{headerStartPos:e,totalSize:f,dataStartPos:e+l,dataSize:d,headerType:r,granulePosition:i,serialNumber:s,sequenceNumber:a,checksum:o,lacingValues:u}},Tg=(t,e)=>{for(;t.filePos<e-3;){const n=as(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===$f)return!0;t.skip(1)}}return!1};class Sg extends mr{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,hi,es);if(le(n)&&(n=await n),!n)break;const r=zs(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 Pg(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=d=>{for(;a.push(Math.min(255,d)),!(d<255);)d-=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=et(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:M0(s.data).modeBlockflags},Rc(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=P0(e.data);n.numberOfChannels=s.outputChannelCount,n.sampleRate=qa,n.codecInfo.opusInfo={preSkip:s.preSkip},Rc(i.data.subarray(8),this.metadataTags)}async readPacket(e,n){N(n<e.lacingValues.length);let r=0;for(let d=0;d<n;d++)r+=e.lacingValues[d];let i=e,s=r,a=n;const o=[];e:for(;;){let d=this.reader.requestSlice(i.dataStartPos,i.dataSize);le(d)&&(d=await d),N(d);const f=Ee(d,i.dataSize);for(;;){if(a===i.lacingValues.length){o.push(f.subarray(r,s));break}const p=i.lacingValues[a];if(s+=p,p<255){o.push(f.subarray(r,s));break e}a++}let h=i.headerStartPos+i.totalSize;for(;;){let p=this.reader.requestSliceRange(h,hi,es);if(le(p)&&(p=await p),!p)return null;const m=zs(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((d,f)=>d+f.length,0);if(c===0)return null;const u=new Uint8Array(c);let l=0;for(let d=0;d<o.length;d++){const f=o[d];u.set(f,l),l+=f.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,hi,es);if(le(i)&&(i=await i),!i)return null;const s=zs(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 xg({codecStrings:e.filter(Boolean)})}async getTrackBackings(){return await this.readMetadata(),this.trackBackings}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}}class Pg{constructor(e,n){this.bitstream=e,this.demuxer=n,this.encodedPacketToMetadata=new WeakMap,this.sequentialScanCache=[],this.sequentialScanMutex=new Ma,this.internalSampleRate=e.codecInfo.codec==="opus"?qa:e.sampleRate}getType(){return"audio"}getId(){return this.bitstream.serialNumber}getNumber(){const e=this.demuxer.trackBackings.findIndex(n=>n.bitstream===this.bitstream);return N(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 N(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 qt}getDisposition(){return{...hr,primary:!1}}granulePositionToTimestampInSamples(e){return this.bitstream.codecInfo.codec==="opus"?(N(this.bitstream.codecInfo.opusInfo),e-this.bitstream.codecInfo.opusInfo.preSkip):e}createEncodedPacketFromOggPacket(e,n,r){if(!e)return null;const{durationInSamples:i,vorbisBlockSize:s}=Ag(e.data,this.bitstream.codecInfo,n.vorbisLastBlocksize),a=new kt(r.metadataOnly?cn: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){N(this.bitstream.lastMetadataPacket);const n=await this.demuxer.findNextPacketStart(this.bitstream.lastMetadataPacket);if(!n)return null;let r=0;this.bitstream.codecInfo.codec==="opus"&&(N(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=Cs(e*this.internalSampleRate);if(r===0)return this.getFirstPacket(n);if(r<0)return null;N(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 w=s.headerStartPos,A=Math.floor((w+a)/2);let b=A;for(;;){const v=Math.min(b+kg,a-hi);let x=this.demuxer.reader.requestSlice(b,v-b);if(le(x)&&(x=await x),N(x),!Tg(x,v)){a=A+hi;continue e}let S=this.demuxer.reader.requestSliceRange(x.filePos,hi,es);le(S)&&(S=await S),N(S);const k=zs(S);N(k);let _=!1;if(k.serialNumber===this.bitstream.serialNumber)_=!0;else{let B=this.demuxer.reader.requestSlice(k.headerStartPos,k.totalSize);le(B)&&(B=await B),N(B);const V=Ee(B,k.totalSize);_=vg(V)===k.checksum}if(!_){b=k.headerStartPos+4;continue}if(_&&k.serialNumber!==this.bitstream.serialNumber){b=k.headerStartPos+k.totalSize;continue}if(k.granulePosition===-1){b=k.headerStartPos+k.totalSize;continue}this.granulePositionToTimestampInSamples(k.granulePosition)>r?a=k.headerStartPos:(s=k,o.push(k));continue e}}let c=i.startPage;for(const w of o){if(w.granulePosition===s.granulePosition)break;(!c||w.headerStartPos>c.headerStartPos)&&(c=w)}let u=c;const l=[u];for(;!(u.serialNumber===this.bitstream.serialNumber&&u.granulePosition===s.granulePosition);){const w=u.headerStartPos+u.totalSize;let A=this.demuxer.reader.requestSliceRange(w,hi,es);le(A)&&(A=await A),N(A);const b=zs(A);N(b),u=b,u.serialNumber===this.bitstream.serialNumber&&l.push(u)}N(u.granulePosition!==-1);let d=null,f,h,p=u,m=0;if(u.headerStartPos===i.startPage.headerStartPos)f=this.granulePositionToTimestampInSamples(0),h=!0,d=0;else{f=0,h=!1;for(let b=u.lacingValues.length-1;b>=0;b--)if(u.lacingValues[b]<255){d=b+1;break}if(d===null)throw new Error("Invalid page with granule position: no packets end on this page.");m=d-1;const w={data:cn,endPage:p,endSegmentIndex:m};if(await this.demuxer.findNextPacketStart(w)){const b=Yf(l,u,d);N(b);const v=Qf(l,b.page,b.segmentIndex);v&&(u=v.page,d=v.segmentIndex)}else for(;;){const b=Yf(l,u,d);if(!b)break;const v=Qf(l,b.page,b.segmentIndex);if(!v)break;if(u=v.page,d=v.segmentIndex,b.page.headerStartPos!==p.headerStartPos){p=b.page,m=b.segmentIndex;break}}}let g=null,y=null;for(;u!==null;){N(d!==null);const w=await this.demuxer.readPacket(u,d);if(!w)break;if(!(u.headerStartPos===i.startPage.headerStartPos&&d<i.startSegmentIndex)){let v=this.createEncodedPacketFromOggPacket(w,{timestampInSamples:f,vorbisLastBlocksize:y?.vorbisBlockSize??null},n);N(v);let x=this.encodedPacketToMetadata.get(v);if(N(x),!h&&w.endPage.headerStartPos===p.headerStartPos&&w.endSegmentIndex===m?(f=this.granulePositionToTimestampInSamples(u.granulePosition),h=!0,v=this.createEncodedPacketFromOggPacket(w,{timestampInSamples:f-x.durationInSamples,vorbisLastBlocksize:y?.vorbisBlockSize??null},n),N(v),x=this.encodedPacketToMetadata.get(v),N(x)):f+=x.durationInSamples,g=v,y=x,h&&(Math.max(f,0)>r||Math.max(x.timestampInSamples,0)===r))break}const b=await this.demuxer.findNextPacketStart(w);if(!b)break;u=b.startPage,d=b.startSegmentIndex}return g}async getPacketSequential(e,n){const r=await this.sequentialScanMutex.acquire();try{const i=Cs(e*this.internalSampleRate);e=i/this.internalSampleRate;const s=Ge(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);N(u),this.sequentialScanCache.length>0&&N(Yt(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 Qf=(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(N(i===-1),!(r.headerType&1)){i=0;break}const a=Vu(t,o=>o.headerStartPos<r.headerStartPos);if(!a)return null;r=a,i=r.lacingValues.length}if(N(i!==-1),i===r.lacingValues.length){const s=t[t.indexOf(r)+1];N(s),r=s,i=0}return{page:r,segmentIndex:i}},Yf=(t,e,n)=>{if(n>0)return{page:e,segmentIndex:n-1};const r=Vu(t,i=>i.headerStartPos<e.headerStartPos);return r?{page:r,segmentIndex:r.lacingValues.length-1}:null};var Xt;(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"})(Xt||(Xt={}));class _g extends mr{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);le(e)&&(e=await e),N(e);const n=mt(e,4),r=n!=="RIFX",i=n==="RF64",s=jr(e,r);let a=i?this.reader.fileSize:Math.min(s+8,this.reader.fileSize??1/0);if(mt(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 f=this.reader.requestSlice(l,8);if(le(f)&&(f=await f),!f)break;const h=mt(f,4),p=jr(f,r),m=f.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=f.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(le(g)&&(g=await g),!g)break;const y=qd(g,r);u=qd(g,r),a=Math.min(y+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 d=this.audioInfo.blockSizeInBytes;this.dataSize=Math.floor(this.dataSize/d)*d,this.trackBackings.push(new Eg(this))})()}async parseFmtChunk(e,n,r){let i=this.reader.requestSlice(e,n);if(le(i)&&(i=await i),!i)return;let s=Gs(i,r);const a=Gs(i,r),o=jr(i,r);i.skip(4);const c=Gs(i,r);let u;if(n===14?u=8:u=Gs(i,r),n>=18&&s!==357){const l=Gs(i,r),d=n-18;if(Math.min(d,l)>=22&&s===Xt.EXTENSIBLE){i.skip(6);const h=Ee(i,16);s=h[0]|h[1]<<8}}if((s===Xt.MULAW||s===Xt.ALAW)&&(u=8),s!==Xt.PCM&&s!==Xt.IEEE_FLOAT&&s!==Xt.ALAW&&s!==Xt.MULAW)throw new Error(`Unsupported WAVE codec (format tag ${s}). Only integer/float PCM, A-law, and \u03BC-law are supported.`);if(s===Xt.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===Xt.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(le(i)&&(i=await i),!i)return;const s=mt(i,4);if(s!=="INFO"&&s!=="INF0")return;let a=i.filePos;for(;a<=e+n-8;){i.filePos=a;const o=mt(i,4),c=jr(i,r),u=Ee(i,c);let l=0;for(let f=0;f<u.length&&u[f]!==0;f++)l++;const d=String.fromCharCode(...u.subarray(0,l));switch(this.metadataTags.raw??={},this.metadataTags.raw[o]=d,o){case"INAM":case"TITL":this.metadataTags.title??=d;break;case"TIT3":this.metadataTags.description??=d;break;case"IART":this.metadataTags.artist??=d;break;case"IPRD":this.metadataTags.album??=d;break;case"IPRT":case"ITRK":case"TRCK":{const f=d.split("/"),h=Number.parseInt(f[0],10),p=f[1]&&Number.parseInt(f[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 f=new Date(d);Number.isNaN(f.getTime())||(this.metadataTags.date??=f)}break;case"YEAR":{const f=Number.parseInt(d,10);Number.isInteger(f)&&f>0&&(this.metadataTags.date??=new Date(f,0,1))}break;case"IGNR":case"GENR":this.metadataTags.genre??=d;break;case"ICMT":case"CMNT":case"COMM":this.metadataTags.comment??=d;break}a+=8+c+(c&1)}}async parseId3Chunk(e,n){let r=this.reader.requestSlice(e,n);if(le(r)&&(r=await r),!r)return;const i=Ar(r);if(i){const s=n-wn;if(i.size=Math.min(i.size,s),i.size>0){const a=r.slice(e+wn,i.size);eo(a,i,this.metadataTags)}}}getCodec(){if(N(this.audioInfo),this.audioInfo.format===Xt.MULAW)return"ulaw";if(this.audioInfo.format===Xt.ALAW)return"alaw";if(this.audioInfo.format===Xt.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===Xt.IEEE_FLOAT){if(this.audioInfo.sampleSizeInBytes===4)return"pcm-f32";if(this.audioInfo.sampleSizeInBytes===8)return"pcm-f64"}N(!1)}async getMimeType(){return"audio/wav"}async getTrackBackings(){return await this.readMetadata(),this.trackBackings}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}}const ts=2048;class Eg{constructor(e){this.demuxer=e}getType(){return"audio"}getId(){return 1}getNumber(){return 1}getCodec(){return this.demuxer.getCodec()}getInternalCodecId(){return N(this.demuxer.audioInfo),this.demuxer.audioInfo.format}async getDecoderConfig(){const e=this.demuxer.getCodec();return e?(N(this.demuxer.audioInfo),{codec:e,numberOfChannels:this.demuxer.audioInfo.numberOfChannels,sampleRate:this.demuxer.audioInfo.sampleRate}):null}getNumberOfChannels(){return N(this.demuxer.audioInfo),this.demuxer.audioInfo.numberOfChannels}getSampleRate(){return N(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getTimeResolution(){return N(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 N(this.demuxer.dataSize!==-1),this.demuxer.dataSize/this.demuxer.audioInfo.blockSizeInBytes/this.demuxer.audioInfo.sampleRate}async getLiveRefreshInterval(){return null}getName(){return null}getLanguageCode(){return qt}getDisposition(){return{...hr}}async getPacketAtIndex(e,n){N(e>=0),N(this.demuxer.audioInfo);const r=e*ts*this.demuxer.audioInfo.blockSizeInBytes;if(r>=this.demuxer.dataSize)return null;const i=Math.min(ts*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(le(c)&&(c=await c),!c)return null}let s;if(n.metadataOnly)s=cn;else{let c=this.demuxer.reader.requestSlice(this.demuxer.dataStart+r,i);le(c)&&(c=await c),N(c),s=Ee(c,i)}const a=e*ts/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 kt(s,"key",a,o,e,i)}getFirstPacket(e){return this.getPacketAtIndex(0,e)}async getPacket(e,n){N(this.demuxer.audioInfo);const r=Math.floor(Math.min(e*this.demuxer.audioInfo.sampleRate/ts,(this.demuxer.dataSize-1)/(ts*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;N(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){N(this.demuxer.audioInfo);const r=Math.round(e.timestamp*this.demuxer.audioInfo.sampleRate/ts);return this.getPacketAtIndex(r+1,n)}getKeyPacket(e,n){return this.getPacket(e,n)}getNextKeyPacket(e,n){return this.getNextPacket(e,n)}}const Yc=7,ns=9,Hs=t=>{const e=t.filePos,n=Ee(t,9),r=new Qe(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 d=r.readBits(2)+1;if(d!==1)throw new Error("ADTS frames with more than one AAC frame are not supported.");let f=null;return a===1?t.filePos-=2:f=r.readBits(16),{objectType:o,samplingFrequencyIndex:c,channelConfiguration:u,frameLength:l,numberOfAacFrames:d,crcCheck:f,startPos:e}};const Qa=1024;class Mg extends mr{constructor(e){super(e),this.metadataPromise=null,this.firstFrameHeader=null,this.loadedSamples=[],this.metadataTags=null,this.trackBackings=[],this.readingMutex=new Ma,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();N(this.firstFrameHeader),this.trackBackings=[new Cg(this)]})()}async advanceReader(){if(this.lastLoadedPos===0)for(;;){let a=this.reader.requestSlice(this.lastLoadedPos,wn);if(le(a)&&(a=await a),!a){this.lastSampleLoaded=!0;return}const o=Ar(a);if(!o)break;this.lastLoadedPos=a.filePos+o.size}let e=this.reader.requestSliceRange(this.lastLoadedPos,Yc,ns);if(le(e)&&(e=await e),!e){this.lastSampleLoaded=!0;return}const n=Hs(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=Rs[n.samplingFrequencyIndex];N(r!==void 0);const i=Qa/r,s={timestamp:this.nextTimestampInSamples/r,duration:i,dataStart:n.startPos,dataSize:n.frameLength};this.loadedSamples.push(s),this.nextTimestampInSamples+=Qa,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,wn);if(le(r)&&(r=await r),!r)break;const i=Ar(r);if(!i)break;let s=this.reader.requestSlice(r.filePos,i.size);if(le(s)&&(s=await s),!s)break;eo(s,i,this.metadataTags),n=r.filePos+i.size}return this.metadataTags}finally{e()}}}class Cg{constructor(e){this.demuxer=e}getType(){return"audio"}getId(){return 1}getNumber(){return 1}getTimeResolution(){return this.getSampleRate()/Qa}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 qt}getCodec(){return"aac"}getInternalCodecId(){return N(this.demuxer.firstFrameHeader),this.demuxer.firstFrameHeader.objectType}getNumberOfChannels(){N(this.demuxer.firstFrameHeader);const e=kc[this.demuxer.firstFrameHeader.channelConfiguration];return N(e!==void 0),e}getSampleRate(){N(this.demuxer.firstFrameHeader);const e=Rs[this.demuxer.firstFrameHeader.samplingFrequencyIndex];return N(e!==void 0),e}getDisposition(){return{...hr}}async getDecoderConfig(){return N(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=cn;else{let s=this.demuxer.reader.requestSlice(r.dataStart,r.dataSize);if(le(s)&&(s=await s),!s)return null;i=Ee(s,r.dataSize)}return new kt(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=Es(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=Ge(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 Ig=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,Rg=(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}},Bg=t=>{let e=0;const n=new Qe(Ee(t,1));for(;n.readBits(1)===1;)e++;if(e===0)return n.readBits(7);const r=[],i=e-1,s=new Qe(Ee(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)},Fg=(t,e)=>{if(e==="uncommon-u16")return At(t)+1;if(e==="uncommon-u8")return Se(t)+1;if(typeof e=="number")return e;Ca(e),N(!1)},Dg=(t,e)=>e==="uncommon-u16"?At(t):e==="uncommon-u16-10"?At(t)*10:e==="uncommon-u8"?Se(t):typeof e=="number"?e:null,Ng=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 Lg extends mr{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 Ma,this.lastSampleLoaded=!1,this.reader=e._reader}async getMetadataTags(){return await this.readMetadata(),this.metadataTags}async getTrackBackings(){return await this.readMetadata(),N(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,wn);if(le(n)&&(n=await n),!n){this.lastSampleLoaded=!0;return}const r=Ar(n);if(!r)break;let i=this.reader.requestSlice(n.filePos,r.size);le(i)&&(i=await i),N(i),eo(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(le(n)&&(n=await n),e+=4,n===null)throw new Error(`Metadata block at position ${e} is too small! Corrupted file.`);N(n);const r=Se(n),i=vr(n),s=(r&128)!==0;switch(r&127){case Xi.STREAMINFO:{let o=this.reader.requestSlice(e,i);if(le(o)&&(o=await o),N(o),o===null)throw new Error(`StreamInfo block at position ${e} is too small! Corrupted file.`);const c=Ee(o,34),u=new Qe(c),l=u.readBits(16),d=u.readBits(16),f=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 y=new Uint8Array(42);y.set(new Uint8Array([102,76,97,67]),0),y.set(new Uint8Array([128,0,0,34]),4),y.set(c,8),this.audioInfo={numberOfChannels:m,sampleRate:p,totalSamples:g,minimumBlockSize:l,maximumBlockSize:d,minimumFrameSize:f,maximumFrameSize:h,description:y},this.trackBacking=new Ug(this);break}case Xi.VORBIS_COMMENT:{let o=this.reader.requestSlice(e,i);le(o)&&(o=await o),N(o),Rc(Ee(o,i),this.metadataTags);break}case Xi.PICTURE:{let o=this.reader.requestSlice(e,i);le(o)&&(o=await o),N(o);const c=ve(o),u=ve(o),l=Kt.decode(Ee(o,u)),d=ve(o),f=Kt.decode(Ee(o,d));o.skip(16);const h=ve(o),p=Ee(o,h);this.metadataTags.images??=[],this.metadataTags.images.push({data:p,mimeType:l,kind:c===3?"coverFront":c===4?"coverBack":"unknown",description:f});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}){N(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 d=this.readFlacFrameHeader({slice:l,isFirstPacket:n});if(!d)return null;for(l.filePos=e+o;;){if(l.filePos>l.end-r)return{num:d.num,blockSize:d.blockSize,sampleRate:d.sampleRate,size:l.end-e,isLastFrame:!0};if(Se(l)===255){const h=l.filePos,p=Se(l),m=this.blockingBit===1?249:248;if(p!==m){l.filePos=h;continue}l.skip(-2);const g=l.filePos-e,y=this.readFlacFrameHeader({slice:l,isFirstPacket:!1});if(!y){l.filePos=h;continue}if(this.blockingBit===0){if(y.num-d.num!==1){l.filePos=h;continue}}else if(y.num-d.num!==d.blockSize){l.filePos=h;continue}return{num:d.num,blockSize:d.blockSize,sampleRate:d.sampleRate,size:g,isLastFrame:!1}}}}readFlacFrameHeader({slice:e,isFirstPacket:n}){const r=e.filePos,i=Ee(e,4),s=new Qe(i);if(s.readBits(15)!==32764)return null;if(this.blockingBit===null){N(n);const g=s.readBits(1);this.blockingBit=g}else if(this.blockingBit===1){if(N(!n),s.readBits(1)!==1)return null}else if(this.blockingBit===0){if(N(!n),s.readBits(1)!==0)return null}else throw new Error("Invalid blocking bit");const o=Ig(s.readBits(4));if(!o)return null;N(this.audioInfo);const c=Rg(s.readBits(4),this.audioInfo.sampleRate);if(!c||(s.readBits(4),s.readBits(3),s.readBits(1)!==0))return null;const l=Bg(e),d=Fg(e,o),f=Dg(e,c);if(f===null||f!==this.audioInfo.sampleRate)return null;const h=e.filePos-r,p=Se(e);e.skip(-h),e.skip(-1);const m=Ng(Ee(e,h));return p!==m?null:{num:l,blockSize:d,sampleRate:f}}async advanceReader(){await this.readMetadata(),N(this.lastLoadedPos!==null),N(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 Ug{constructor(e){this.demuxer=e}getType(){return"audio"}getId(){return 1}getNumber(){return 1}getCodec(){return"flac"}getInternalCodecId(){return null}getNumberOfChannels(){return N(this.demuxer.audioInfo),this.demuxer.audioInfo.numberOfChannels}getSampleRate(){return N(this.demuxer.audioInfo),this.demuxer.audioInfo.sampleRate}getName(){return null}getLanguageCode(){return qt}getTimeResolution(){return N(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 N(this.demuxer.audioInfo),this.demuxer.audioInfo.totalSamples===0?null:this.demuxer.audioInfo.totalSamples/this.demuxer.audioInfo.sampleRate}async getLiveRefreshInterval(){return null}getDisposition(){return{...hr}}async getDecoderConfig(){return N(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(N(this.demuxer.audioInfo),e<0)return null;const r=await this.demuxer.readingMutex.acquire();try{for(;;){const i=Ge(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=cn;else{let o=this.demuxer.reader.requestSlice(r.byteOffset,r.byteSize);if(le(o)&&(o=await o),!o)return null;i=Ee(o,r.byteSize)}N(this.demuxer.audioInfo);const s=r.blockOffset/this.demuxer.audioInfo.sampleRate,a=r.blockSize/this.demuxer.audioInfo.sampleRate;return new kt(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 Mn=9e4,Kc=2**33,ln=188,Og=t=>{let e="video/MP2T";const n=[...new Set(t.filter(Boolean))];return n.length>0&&(e+=`; codecs="${n.join(", ")}"`),e};const Kf="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.",Zf=5,zg=1212435798,Hg=1212436562,Vg=1146376960,Wg=new Set([133,134,162]),Jf=new Set;class jg extends mr{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=ln+16+1;let n=this.reader.requestSlice(0,e);le(n)&&(n=await n),N(n);const r=Ee(n,e);if(r[0]===71&&r[ln]===71)this.packetOffset=0,this.packetStride=ln;else if(r[0]===71&&r[ln+16]===71)this.packetOffset=0,this.packetStride=ln+16;else if(r[4]===71&&r[4+ln+4]===71)this.packetOffset=4,this.packetStride=ln+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 d=3,f=32;let h=!1;if(!c&&l.pid!==0&&!(l.payload[0]===0&&l.payload[1]===0&&l.payload[2]===1)){const g=new Qe(l.payload),y=g.readAlignedByte();g.skipBits(8*y),h=g.readBits(8)===2}if(l.pid===0&&!o){const m=new Qe(l.payload),g=m.readAlignedByte();m.skipBits(8*g),m.skipBits(14);const y=m.readBits(10);for(m.skipBits(40);8*(y+d)-m.pos>f;){const w=m.readBits(16);m.skipBits(3);const A=m.readBits(13);if(w!==0){if(a!==null)throw new Error("Only files with a single program are supported.");a=A}}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 Qe(l.payload),g=m.readAlignedByte();m.skipBits(8*g),m.skipBits(12);const y=m.readBits(12);m.skipBits(43),m.readBits(13),m.skipBits(6);const w=m.readBits(10),A=m.pos+8*w;let b=!1;for(;m.pos<A;){const v=m.readBits(8),x=m.readBits(8),P=m.pos+8*x;if(v===Zf&&x>=4){const S=m.readBits(32);b||=S===zg||S===Hg}m.pos=P}for(m.pos=A;8*(y+d)-m.pos>f;){const v=m.readBits(8);m.skipBits(3);const x=m.readBits(13);m.skipBits(6);const P=m.readBits(10),S=m.pos+8*P;let k=!1,_=!1,I=!1;for(;m.pos<S;){const O=m.readBits(8),U=m.readBits(8),W=m.pos+8*U;if(O===106)k=!0;else if(O===122||O===204)_=!0;else if(O===123)I=!0;else if(O===Zf&&U>=4){const ie=m.readBits(32);I||=(ie&4294967040)===Vg}m.pos=W}let B=null;const V=b&&Wg.has(v)?130:v;switch(V){case 27:case 36:B={type:"video",codec:v===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 O;V===3||V===4?O="mp3":V===15?O="aac":V===129?O="ac3":V===135?O="eac3":O="dts",B={type:"audio",codec:O,decoderConfig:null,aacCodecInfo:null,dtsFormat:null,numberOfChannels:-1,sampleRate:-1}}break;case 6:_?B={type:"audio",codec:"eac3",decoderConfig:null,aacCodecInfo:null,dtsFormat:null,numberOfChannels:-1,sampleRate:-1}:k?B={type:"audio",codec:"ac3",decoderConfig:null,aacCodecInfo:null,dtsFormat:null,numberOfChannels:-1,sampleRate:-1}:I&&(B={type:"audio",codec:"dts",decoderConfig:null,aacCodecInfo:null,dtsFormat:null,numberOfChannels:-1,sampleRate:-1});break;default:Jf.has(v)||(Be._warn(`Note: MPEG-TS streams with stream_type 0x${v.toString(16)} are not currently supported.`),Jf.add(v))}B&&this.elementaryStreams.push({demuxer:this,pid:x,streamType:v,initialized:!1,firstSection:null,canBeTrustedWithKeyPackets:!1,info:B,referencePesPackets:[]})}c=!0}else{const m=this.elementaryStreams.find(g=>g.pid===l.pid);e:if(m&&!m.initialized){const g=rs(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 A=(await this.input._initInput._getDemuxer()).elementaryStreams.find(b=>b.pid===l.pid&&b.info.codec===m.info.codec);if(A){m.info=A.info,m.initialized=!0;break e}}const y=new Vs(m,g);if(m.info.type==="video"){for(;;){const w=y;if(w.suppliedPacket=null,await y.markNextPacket(),m.info.codec==="avc"){if(!y.suppliedPacket)throw new Error("Invalid AVC video stream; could not extract AVCDecoderConfigurationRecord from any packet.");if(m.info.avcCodecInfo=_c(y.suppliedPacket.data),!m.info.avcCodecInfo)continue;const A=m.info.avcCodecInfo.sequenceParameterSets[0];N(A);const b=Oa(A);m.info.width=b.displayWidth,m.info.height=b.displayHeight;const v=b.pixelAspectRatio.num,x=b.pixelAspectRatio.den;v>0&&x>0&&(v>x?(m.info.squarePixelWidth=Math.round(m.info.width*v/x),m.info.squarePixelHeight=m.info.height):(m.info.squarePixelWidth=m.info.width,m.info.squarePixelHeight=Math.round(m.info.height*x/v))),m.info.colorSpace={primaries:ur[b.colourPrimaries],transfer:fr[b.transferCharacteristics],matrix:dr[b.matrixCoefficients],fullRange:!!b.fullRangeFlag},m.info.reorderSize=b.maxDecFrameBuffering;break}else if(m.info.codec==="hevc"){if(!y.suppliedPacket)throw new Error("Invalid HEVC video stream; could not extract HVCDecoderConfigurationRecord from first packet.");if(m.info.hevcCodecInfo=Mc(y.suppliedPacket.data),!m.info.hevcCodecInfo)continue;const b=m.info.hevcCodecInfo.arrays.find(x=>x.nalUnitType===vt.SPS_NUT).nalUnits[0];N(b);const v=Ec(b);m.info.width=v.displayWidth,m.info.height=v.displayHeight,v.pixelAspectRatio.num>v.pixelAspectRatio.den?(m.info.squarePixelWidth=Math.round(m.info.width*v.pixelAspectRatio.num/v.pixelAspectRatio.den),m.info.squarePixelHeight=m.info.height):(m.info.squarePixelWidth=m.info.width,m.info.squarePixelHeight=Math.round(m.info.height*v.pixelAspectRatio.den/v.pixelAspectRatio.num)),m.info.colorSpace={primaries:ur[v.colourPrimaries],transfer:fr[v.transferCharacteristics],matrix:dr[v.matrixCoefficients],fullRange:!!v.fullRangeFlag},m.info.reorderSize=v.maxDecFrameBuffering;break}else throw new Error("Unhandled.")}m.info.decoderConfig={codec:Nc({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 y.markNextPacket(),!y.suppliedPacket)throw new Error(`Couldn't parse first media packet for Elementary Stream with PID ${m.pid}`);if(m.info.codec==="aac"){const w=Nn.tempFromBytes(y.suppliedPacket.data),A=Hs(w);if(!A)throw new Error("Invalid AAC audio stream; could not read ADTS frame header from first packet.");m.info.aacCodecInfo={isMpeg2:!1,objectType:A.objectType},m.info.numberOfChannels=kc[A.channelConfiguration],m.info.sampleRate=Rs[A.samplingFrequencyIndex]}else if(m.info.codec==="mp3"){const w=ve(Nn.tempFromBytes(y.suppliedPacket.data)),A=Uc(w,y.suppliedPacket.data.byteLength);if(!A.header)throw new Error("Invalid MP3 audio stream; could not read frame header from first packet.");m.info.numberOfChannels=Fs(A.header.channel),m.info.sampleRate=A.header.sampleRate}else if(m.info.codec==="ac3"){const w=C0(y.suppliedPacket.data);if(!w)throw new Error("Invalid AC-3 audio stream; could not read sync frame from first packet.");if(w.fscod===3)throw new Error("Invalid AC-3 audio stream; reserved sample rate code found in first packet.");m.info.numberOfChannels=Bc[w.acmod]+w.lfeon,m.info.sampleRate=Da[w.fscod]}else if(m.info.codec==="eac3"){const w=B0(y.suppliedPacket.data);if(!w)throw new Error("Invalid E-AC-3 audio stream; could not read sync frame from first packet.");const A=uf(w);if(A===null)throw new Error("Invalid E-AC-3 audio stream; reserved sample rate code found in first packet.");m.info.numberOfChannels=ff(w),m.info.sampleRate=A}else if(m.info.codec==="dts"){const w=mf(y.suppliedPacket.data);if(!w)throw new Error("Invalid DTS audio stream; could not read frame header from first packet.");m.info.numberOfChannels=w.numberOfChannels,m.info.sampleRate=w.sampleRate,w.core&&(m.info.dtsFormat=w.hasExtensions?"dtsh":"dtsc")}else throw new Error("Unhandled.");m.info.decoderConfig={codec:Lc({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 qg(u)):this.trackBackingEntries.push(new Xg(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 Og(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 f=await this.readPacket(s);if(s+=this.packetStride,!f)break;if(c){if(f.pid!==c.pid){if(r)break;continue}if(f.payloadUnitStartIndicator===1)break}else{if(f.payloadUnitStartIndicator===0)break;c=f}const h=!!(f.adaptationFieldControl&2),p=!!(f.adaptationFieldControl&1);let m=0;if(h&&(m=1+f.body[0],f===c&&m>1&&(l=f.body[1]>>6&1)),p&&(m===0?(a.push(f.body),o+=f.body.byteLength):(a.push(f.body.subarray(m)),o+=f.body.byteLength-m)),i=s,!n&&o>=64){u=!1;break}if(Es(this.sectionEndPositions,i,y=>y)!==-1){u=!1;break}}if(u){const f=Ge(this.sectionEndPositions,i,h=>h);this.sectionEndPositions.splice(f+1,0,i)}if(!c)return null;let d;if(a.length===1)d=a[0];else{const f=a.reduce((p,m)=>p+m.length,0);d=new Uint8Array(f);let h=0;for(const p of a)d.set(p,h),h+=p.length}return{startPos:e,endPos:n?i:null,pid:c.pid,payload:d,randomAccessIndicator:l}}async readPacketHeader(e){let n=this.reader.requestSlice(e,4);if(le(n)&&(n=await n),!n)return null;if(Se(n)!==71)throw new Error("Invalid TS packet sync byte. Likely an internal bug, please report this file.");const i=At(n),s=i>>14&1,a=i&8191,c=Se(n)>>4&3;return{payloadUnitStartIndicator:s,pid:a,adaptationFieldControl:c}}async readPacket(e){let n=this.reader.requestSlice(e,ln);if(le(n)&&(n=await n),!n)return null;const r=Ee(n,ln);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*Mn;this.timestampWrapInfo={reference:e-i,offset:e>=Kc-i?-Kc:Kc}}const{reference:n,offset:r}=this.timestampWrapInfo;return r<0&&e>=n||r>0&&e<n?e+r:e}}const mi=(t,e,n)=>{if(e.payload.byteLength<3)return null;const r=new Qe(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(Kf);return{sectionStartPos:e.startPos,sectionEndPos:e.endPos,pts:o,randomAccessIndicator:e.randomAccessIndicator}},rs=(t,e,n)=>{N(e.endPos!==null);const r=mi(t,e,n);if(!r)return null;const i=new Qe(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;N(Number.isInteger(u));const l=e.payload.subarray(u,s>0?a+s:e.payload.byteLength);return{...r,data:l}};class Ho{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++,N(i instanceof Ho),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 qt}getDisposition(){return{...hr,primary:!1}}getTimeResolution(){return Mn}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 kt(r.metadataOnly?cn:e.data,i,e.pts/Mn,Math.max(n/Mn,0),e.sequenceNumber,e.data.byteLength)}async getFirstPacket(e){const n=this.elementaryStream.firstSection;N(n);const r=rs(this.elementaryStream.demuxer,n,!0);N(r);const i=new Vs(this.elementaryStream,r),s=new Jc(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 d=this.createEncodedPacket(l.packet,l.duration,n);return this.packetBuffers.set(d,r),this.packetSectionStarts.set(d,l.packet.sectionStartPos),d}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);N(a);const o=rs(s,a,!0);N(o);const c=new Vs(this.elementaryStream,o);r=new Jc(this,c);const u=e.sequenceNumber;for(;;){const l=await r.readNext();if(!l)return null;if(l.packet.sequenceNumber>u){const d=this.createEncodedPacket(l.packet,l.duration,n);return this.packetBuffers.set(d,r),this.packetSectionStarts.set(d,l.packet.sectionStartPos),d}}}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=Cs(e*Mn),s=this.elementaryStream.demuxer,{reader:a,seekChunkSize:o}=s,c=this.elementaryStream.pid,u=async(b,v,x)=>{let P=b;for(;P<v;){const S=await s.readPacketHeader(P);if(!S)return null;if(S.pid===c&&S.payloadUnitStartIndicator===1){const k=await s.readSection(P,x);if(!k)return null;const _=mi(s,k,!1);if(_&&_.pts!==null)return{pesPacketHeader:_,section:k}}P+=s.packetStride}return null},l=this.elementaryStream.firstSection;N(l);const d=mi(s,l,!0);if(N(d),i<d.pts)return null;let f;const h=this.elementaryStream.referencePesPackets,p=Ge(h,i,b=>b.pts),m=p!==-1?h[p]:null;if(m&&i-m.pts<Mn/2)f=m.sectionStartPos;else{let b=0;if(a.fileSize!==null){const v=Math.ceil(a.fileSize/o);if(v>1){let x=0,P=v-1;for(b=x;x<=P;){const S=Math.floor((x+P)/2),k=uc(S*o,s.packetStride)+d.sectionStartPos,_=k+o,I=await u(k,_,!1);if(!I){P=S-1;continue}I.pesPacketHeader.pts<=i?(b=S,x=S+1):P=S-1}}}f=uc(b*o,s.packetStride)+d.sectionStartPos}let y=(await u(f,a.fileSize??1/0,!1))?.pesPacketHeader??null;y||(y=d);const w=this.getReorderSize(),A=async(b,v)=>{const x=await s.readSection(b,!0);N(x);const P=rs(s,x,!0);N(P);const S=new Vs(this.elementaryStream,P),k=new Jc(this,S);for(;!((Yt(k.presentationOrderPackets)?.pts??-1/0)>=i||!await k.readNextPacket()););const _=cc(k.presentationOrderPackets,v);if(_===-1)return null;const I=k.presentationOrderPackets[_],B=_===0?0:I.pts-k.presentationOrderPackets[_-1].pts;for(;k.decodeOrderPackets[0]!==I;)k.decodeOrderPackets.shift();k.lastDuration=B;const V=await k.readNext();N(V);const O=this.createEncodedPacket(V.packet,V.duration,r);return this.packetBuffers.set(O,k),this.packetSectionStarts.set(O,V.packet.sectionStartPos),O};if(!n||this.allPacketsAreKeyPackets()){e:for(;;){let b=y.sectionStartPos+s.packetStride;for(;;){const v=await s.readPacketHeader(b);if(!v)break e;if(v.pid===c&&v.payloadUnitStartIndicator===1){const x=await s.readSection(b,!1);if(x){const P=mi(s,x,!1);if(P&&P.pts!==null){if(P.pts>i)break e;y=P,Zc(this.elementaryStream,y);break}}}b+=s.packetStride}}e:for(let b=0;b<w+1;b++){let v=y.sectionStartPos-s.packetStride;for(;v>=s.packetOffset;){const x=await s.readPacketHeader(v);if(!x)break e;if(x.pid===c&&x.payloadUnitStartIndicator===1){const P=await s.readSection(v,!1);if(P){const S=mi(s,P,!1);if(S&&S.pts!==null){y=S;break}}}v-=s.packetStride}}return A(y.sectionStartPos,b=>b.pts<=i)}else{let b=f,v=null;const x=!this.elementaryStream.canBeTrustedWithKeyPackets;for(;;){let P=null;const S=b<=d.sectionStartPos;let k,_=null;if(S)k=d,_=l;else{const V=await u(b,a.fileSize??1/0,x);k=V?.pesPacketHeader??null,_=V?.section??null}let I=!1,B=0;e:for(;k&&!(v!==null&&k.sectionStartPos>=v);){if(k.pts<=i){let O;if(this.elementaryStream.canBeTrustedWithKeyPackets)O=k.randomAccessIndicator===1;else{N(_);const U=rs(s,_,!0);N(U);const W=new Vs(this.elementaryStream,U);await W.markNextPacket(),O=W.suppliedPacket?.randomAccessIndicator===1}O&&(P=k)}if(k.pts>i&&(I=!0),I&&(B++,B>w))break;let V=k.sectionStartPos+s.packetStride;for(;;){const O=await s.readPacketHeader(V);if(!O)break e;if(O.pid===c&&O.payloadUnitStartIndicator===1){const U=await s.readSection(V,x);if(U){const W=mi(s,U,!1);if(W&&W.pts!==null){k=W,_=U,Zc(this.elementaryStream,k);break}}}V+=s.packetStride}}if(P){let V=P;if(B===0)e:for(let U=0;U<w;U++){let W=V.sectionStartPos-s.packetStride;for(;W>=s.packetOffset;){const ie=await s.readPacketHeader(W);if(!ie)break e;if(ie.pid===c&&ie.payloadUnitStartIndicator===1){const we=await s.readSection(W,x);if(we){const Y=mi(s,we,!1);if(Y&&Y.pts!==null){V=Y;break}}}W-=s.packetStride}}const O=await A(V.sectionStartPos,U=>U.pts<=i&&U.randomAccessIndicator===1);return N(O),O}if(S)return null;v=b,b=Math.max(uc(b-d.sectionStartPos-o,s.packetStride)+d.sectionStartPos,d.sectionStartPos)}}}}class qg extends Ho{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 N(this.elementaryStream.info.decoderConfig),this.elementaryStream.info.decoderConfig}allPacketsAreKeyPackets(){return!1}getReorderSize(){return this.elementaryStream.info.reorderSize}}class Xg extends Ho{getType(){return"audio"}getCodec(){return this.elementaryStream.info.codec}getNumberOfChannels(){return this.elementaryStream.info.numberOfChannels}getSampleRate(){return this.elementaryStream.info.sampleRate}async getDecoderConfig(){return N(this.elementaryStream.info.decoderConfig),this.elementaryStream.info.decoderConfig}allPacketsAreKeyPackets(){return!0}getReorderSize(){return 0}}const Zc=(t,e)=>{const n=t.referencePesPackets,r=Ge(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 Vs{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 N(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=Yt(this.pesPackets).sectionEndPos;for(N(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=rs(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(){N(!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(le(c)&&(c=await c),c===0)break;const u=this.currentPos,l=this.readBytes(c),d=l.byteLength;let f=0;for(;f<d;){const h=l.indexOf(0,f);if(h===-1||h>=d)break;f=h;const p=u+f;if(f+3>=d){this.seekTo(p);break}const m=l[f+1],g=l[f+2],y=l[f+3];let w=0;if(m===0&&g===0&&y===1?w=4:m===0&&g===1&&(w=3),w===0){f++;continue}const A=p;s??=A;const b=f+w,v=b+i,x=6;if(v+(n==="avc"?x:1)>d){this.seekTo(p);break}const S=l[b];let k,_,I;if(n==="avc")k=La(S),_=k===Rt.NON_IDR_SLICE||k===Rt.SLICE_DPA||k===Rt.IDR,I=k===Rt.SEI||k===Rt.SPS||k===Rt.PPS||k===Rt.AUD;else{if(k=qi(S),((S&1)<<5|l[b+1]>>3)>0){f+=w;continue}_=k<=vt.RASL_R||k>=vt.BLA_W_LP&&k<=21,I=k>=vt.VPS_NUT&&k<=37||k===vt.PREFIX_SEI_NUT||k>=41&&k<=44||k>=48&&k<=55}let B=!1;if(_){let V;if(n==="avc"){const O=l.subarray(v,v+x),U=ke(new Qe(O));V=!a||U<=o,o=U}else V=l[v]>>7===1;V&&(a?B=!0:a=!0)}else I&&a&&(B=!0);if(B){const V=A-s;return this.seekTo(s),this.supplyPacket(V,0)}f+=w}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);le(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(ns);if(le(c)&&(c=await c),c<ns)return;const u=this.readBytes(ns),l=Hs(Nn.tempFromBytes(u));if(l){this.seekTo(o);let d=this.ensureBuffered(l.frameLength);return le(d)&&(d=await d),this.supplyPacket(d,Math.round(Qa*Mn/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(fi);if(le(c)&&(c=await c),c<fi)return;const u=this.readBytes(fi),l=et(u).getUint32(0),d=Uc(l,null);if(d.header){this.seekTo(o);let f=this.ensureBuffered(d.header.totalSize);le(f)&&(f=await f);const h=d.header.audioSamplesInFrame*Mn/e.info.sampleRate;return this.supplyPacket(f,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(le(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,d=u[4]&63;if(l===3||d>37){this.seekTo(o+1);continue}const f=I0[3*d+l];N(f!==void 0),this.seekTo(o),c=this.ensureBuffered(f),le(c)&&(c=await c);const h=Math.round(R0*Mn/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(le(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 d=(((u[2]&7)<<8|u[3])+1)*2,h=u[4]>>6===3?3:u[4]>>4&3,p=lf[h];this.seekTo(o),c=this.ensureBuffered(d),le(c)&&(c=await c);const m=p*256,g=Math.round(m*Mn/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(Ha);if(le(c)&&(c=await c),c<Ha)return;const u=this.readBytes(Ha),l=gf(u);let d=l?null:Wa(u);if(!l&&!d){this.seekTo(o+1);continue}if(d&&!d.asset){this.seekTo(o);const m=Math.min(d.frameSize,N0);let g=this.ensureBuffered(m);le(g)&&(g=await g),d=Wa(this.readBytes(g))??d}let f=l?l.frameSize:d.frameSize;if(l){let m=Math.ceil(l.frameSize/4)*4;for(;;){this.seekTo(o);const g=m+Fc;let y=this.ensureBuffered(g);if(le(y)&&(y=await y),y<g)break;this.seekTo(o+m);const w=Wa(this.readBytes(Fc));if(!w)break;m+=w.frameSize,f=m}}const h=l?.sampleCount??d.asset?.sampleCount;if(h===void 0){this.seekTo(o+1);continue}this.seekTo(o),c=this.ensureBuffered(f),le(c)&&(c=await c);const p=Math.round(h*Mn/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)N(this.nextPts!==null),i=this.nextPts;else{if(r.pts===null)throw new Error(Kf);i=r.pts,Zc(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=Ic(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 Jc{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(),N(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);N(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(N(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 ed="application/vnd.apple.mpegurl",td="#EXT-X-STREAM-INF:",nd="#EXT-X-I-FRAME-STREAM-INF:",rd="#EXT-X-MEDIA:",el="#EXTINF:",id="#EXT-X-MAP:",sd="#EXT-X-KEY:",ad="#EXT-X-MEDIA-SEQUENCE:",od="#EXT-X-BYTERANGE:",cd="#EXT-X-PROGRAM-DATE-TIME:",$g="#EXT-X-DISCONTINUITY",ld="#EXT-X-TARGETDURATION:",Gg="#EXT-X-ENDLIST",ud="#EXT-X-PLAYLIST-TYPE:",Qg="#EXT-X-I-FRAMES-ONLY",fd=t=>t.length===0||t.startsWith("#")&&!t.startsWith("#EXT");class Ws{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 Yg{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=Is(e,i=>i.getType()==="video")+1;e.push(new hd(this,n,r))}else if(n.type==="audio"){const r=Is(e,i=>i.getType()==="audio")+1;e.push(new md(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=Is(e,a=>a.getType()==="video")+1;e.push(new hd(this,{id:e.length+1,type:"video"},s))}else if(i.type==="audio"){const s=Is(e,a=>a.getType()==="audio")+1;e.push(new md(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 dd{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(),N(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){N(e.sequenceNumber>=0),N(this.segmentedInput.firstSegment);const i=await this.segmentedInput.getMediaOffset(n,r.input),s=n.timestamp-this.segmentedInput.firstSegment.timestamp,a=e.clone({timestamp:ju(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(),N(this.firstInputTrack),N(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(f=>f.type===i.track.type&&f.number===i.track.number);if(!l){a=o;continue}const d=await l._backing.getFirstPacket(n);return d?this.createAdjustedPacket(d,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(d=>d.type===this.firstInputTrack.type&&d.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 hd extends dd{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 md extends dd{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())}}wc();const pd=0,gd=1/0;typeof FinalizationRegistry<"u"&&new FinalizationRegistry(t=>{t()});class wr extends xc{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 Lt;return this._sizePromise??=(async()=>{let e=this._getFileSize();return e!==void 0||(await this._read(0,1,pd,gd),e=this._getFileSize(),N(e!==void 0)),e})()}async getSize(){if(this._disposed)throw new Lt;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 i1(this,e,n)}_dispatchRead(e,n){this.onread?.(e,n),this._emit("read",{start:e,end:n})}ref(){return new tl(this)}_incrementRefCount(){this._refCount++}_decrementRefCount(){this._refCount--,this._refCount===0&&(this._dispose(),this._disposed=!0)}}class tl{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;N(e._refCount>0),e._decrementRefCount(),e._refFinalizationRegistry?.unregister(this),this._freed=!0,this._source=null}[Symbol.dispose](){this.freed||this.free()}}class is extends wr{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 wr||i instanceof tl))throw new TypeError("requestHandler must return or resolve to a Source or SourceRef.");const s=i instanceof wr?i.ref():i;return s.source._usedForHls||=this._usedForHls,s};return le(n)?n.then(r):r(n)}}const yd=(t,e)=>t.path===e.path;class Kg extends is{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 wr?o.ref():o;return this._root=c,this._rootRequest=null,c};le(s)?this._rootRequest=s.then(a):(a(s),N(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 Zg=.5*2**20,Jg=(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 Be._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)},bd=new Set;class wu extends is{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&&(!Ia(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 wu(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??Jg,this._requestInit={...n.requestInit};let i=null;if(n.requestInit?.headers){const a={...dc(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=t1(i);a&&(this._offset=a.offset,this._length=a.length)}const s=2;this._orchestrator=new r1({maxCacheSize:n.maxCacheSize??64*2**20,maxWorkerCount:n.parallelism??s,runWorker:this._runWorker.bind(this),prefetchProfile:n1.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:Ms(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 le(a)?a.then(o):o(a)}async _runWorker(e){for(;;){const n=new AbortController,r=await $u(this._options.fetchFn??fetch,this._url,Xu(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"))&&(bd.has(s.origin)||(Be._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.`),bd.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){Be._error("Error while reading response stream. Attempting to resume.",c),await Ba(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(d){if(this._disposed)throw d;const f=this._getRetryDelay(1,d,this._url);if(f===null)throw d;Be._error("Error while reading response stream. Attempting to resume.",d),await Ba(1e3*f);const h=await $u(this._options.fetchFn??fetch,this._url,Xu(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 d=Math.min(i,l.length);i-=d,l=l.subarray(d)}if(l.length!==0){r+=l.length,c.enqueue(l);return}}},cancel:()=>n.cancel()}),a=new wd(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);le(u)?u.then(l=>{l?(N(l.offset===c.start),c.resolve(l.bytes)):c.resolve(null)},l=>c.reject(l)):(N(u===null),c.resolve(null))}}_dispose(){this._orchestrator.dispose(),this._sequentialBacking&&(this._sequentialBacking._disposed=!0,this._sequentialBacking._dispose())}}const e1=/^bytes=(\d+)-(\d*)$/,t1=t=>{const e=e1.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 wd extends wr{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&&(!Ia(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=Ge(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 d=this._cache[l];if(d.start>=n)break;const f=Math.max(e,d.start);f>s&&this._throwDueToCacheMiss();const h=Math.min(n,d.end);f<h&&(a.set(d.bytes.subarray(f-d.start,h-d.start),f-e),s=h)}if(s===n)return{bytes:a,view:et(a),offset:e};this._currentIndex>s&&this._throwDueToCacheMiss();const{promise:o,resolve:c,reject:u}=Dt();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(d=>d.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:et(a.bytes),offset:a.start}),this._pendingSlices.splice(s,1),s--))}for(this._cache.push({start:r,end:i,bytes:n,view:et(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 Lt);this._pendingSlices.length=0,this._cache.length=0,this._reader?.cancel()}}const n1={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(bc(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+Zg),{start:t,end:e}}};class r1{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){N(!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);N(a<=e&&n<=o);let c=null;const u=Ge(this.cache,e,v=>v.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 d=Ge(this.cache,a,v=>v.start),f=c?null:new Uint8Array(n-e);let h=0,p=a;const m=[];if(d!==-1){for(let v=d;v<this.cache.length;v++){const x=this.cache[v];if(x.start>=o)break;if(x.end<=a)continue;const P=Math.max(a,x.start),S=Math.min(o,x.end);if(N(P<=S),p<P&&m.push({start:p,end:P}),p=S,f){const k=Math.max(e,x.start),_=Math.min(n,x.end);if(k<_){const I=k-e;f.set(x.bytes.subarray(k-x.start,_-x.start),I),I===h&&(h=_-e)}}x.age=this.nextAge++}p<o&&m.push({start:p,end:o})}else m.push({start:a,end:o});if(f&&h>=f.length&&(c={bytes:f,view:et(f),offset:e}),m.length===0)return N(c),c;const{promise:g,resolve:y,reject:w}=Dt(),A=[];for(const v of m){const x=Math.max(e,v.start),P=Math.min(n,v.end);x===v.start&&P===v.end?A.push(v):x<P&&A.push({start:x,end:P})}const b=f&&{start:e,bytes:f,holes:A,resolve:y,reject:w};e:for(const v of m){for(const S of this.workers)if(this.checkHoleAgainstWorker(S,v,b?[b]:[])){this.checkQueuedReadsAgainstWorker(S);continue e}const x=v.end<o||this.fileSize!==null,P=this.createWorker(v.start,v.end,x);if(P)b&&(P.pendingSlices=[b]),this.runWorker(P);else{let S=Ge(this.queuedReads,v.start,_=>_.hole.start),k=S!==-1?this.queuedReads[S]:null;for(k&&v.start<=k.hole.end?(k.hole.end=Math.max(k.hole.end,v.end),k.strictTarget&&=x,b&&k.pendingSlices.push(b)):(S++,k={hole:{start:v.start,end:v.end},strictTarget:x,pendingSlices:b?[b]:[],age:this.nextAge++},this.queuedReads.splice(S,0,k));S+1<this.queuedReads.length;){const _=this.queuedReads[S+1];if(_.hole.start>k.hole.end)break;k.hole.end=Math.max(k.hole.end,_.hole.end),k.pendingSlices.push(..._.pendingSlices),k.strictTarget&&=_.strictTarget,k.age=Math.min(k.age,_.age),this.queuedReads.splice(S+1,1)}}}return c?g.catch(v=>{if(!this.disposed)if(this.options.handleUnhandledError)this.options.handleUnhandledError(v);else throw v}):(N(f),c=g.then(v=>v&&{bytes:v,view:et(v),offset:e})),c}checkHoleAgainstWorker(e,n,r){if(bc(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)N(a!==null),N(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){N(!e.running),N(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){N(!e.aborted);const r=e.currentPos,i=r+n.length;this.insertIntoCache({start:r,end:i,bytes:n,view:et(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||bc(r,i,a.currentPos,a.targetPos)&&(this.workers.splice(s,1),this.options.onIdleWorkerRemoved?.(a),s--)}}supplyFileSize(e){N(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);N(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=Ge(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=et(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=et(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 Lt);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 Lt);this.workers.length=0,this.cache.length=0,this.queuedReads.length=0,this.disposed=!0}}class i1 extends wr{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:Ms(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 le(s)?s.then(a):a(s)}_dispose(){this._ref?.free()}ref(){return this._ref??=this._baseSource.ref(),super.ref()}}var vd=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},Ad=(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 s1=/^0[xX][0-9a-fA-F]+$/,a1=/^data:.*;base64,/i;class xd extends Yg{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 Ba(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 A={stack:[],error:void 0,hasError:!1};try{const b=vd(A,await this.demuxer.input._getSourceUncached({path:this.rootPath,isRoot:!1}),!1),x=await new Za(b.source).requestEntireFile();N(x),e=$d(x,x.length,{ignore:fd}),b.source instanceof is&&(this.rootPath=b.source.rootPath)}catch(b){A.error=b,A.hasError=!0}finally{Ad(A)}}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,d=null,f=null,h=null,p=null,m=!1,g=Yt(this.segments)??null;const y=A=>{const b=A.indexOf("@"),v=Number(b===-1?A:A.slice(0,b));if(!Number.isInteger(v)||v<0)throw new Error(`Invalid #EXT-X-BYTERANGE length '${A}'.`);let x=null;if(b!==-1&&(x=Number(A.slice(b+1)),!Number.isInteger(x)||x<0))throw new Error(`Invalid #EXT-X-BYTERANGE offset '${A}'.`);return{length:v,offset:x}},w=A=>{c=A,g&&(N(g.sequenceNumber!==null),g.sequenceNumber<A&&(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 A=0;A<e.length;A++){const b=e[A];if(!r){if(b!=="#EXTM3U")throw new Error("Invalid M3U8 file; expected first line to be #EXTM3U.");r=!0;continue}if(!b.startsWith("#")){if(!g){if(a===null)throw new Error("Invalid M3U8 file; a segment must be preceded by an #EXTINF tag.");let v=o;if(v&&v.method==="AES-128"&&!v.iv){const k=new Uint8Array($n),_=et(k);_.setUint32(8,Math.floor(c/2**32)),_.setUint32(12,c),v={...v,iv:k}}const P={path:Hr(this.rootPath,b),offset:f?.offset??0,length:f?.length??null},S={timestamp:i,unixEpochTimestamp:s,firstSegment:u,sequenceNumber:c,location:P,duration:a,encryption:v,initSegment:l,lastProgramDateTimeSeconds:h};u??=S,i+=a,s!==null&&(s+=a),this.segments.push(S)}a=null,f===null?d=null:f=null,w(c+1)}if(b.startsWith(el)){if(g){m=!0;continue}m||(h===null&&c>0&&p!==null&&(i=c*p),m=!0);const v=b.slice(el.length),x=v.indexOf(","),P=x===-1?v:v.slice(0,x),S=Number(P);if(!Number.isFinite(S)||S<0)throw new Error(`Invalid #EXTINF tag duration '${P}'.`);a=S}else if(b.startsWith(id)){const v=new Ws(b.slice(id.length)),x=v.get("uri");if(!x)throw new Error("Invalid #EXT-X-MAP tag; missing URI attribute.");const P=v.get("byterange");let S=null;if(P!==null&&(S=y(P)),S&&S.offset===null)throw new Error("Invalid #EXT-X-MAP tag; BYTERANGE attribute must have a specified offset.");if(!g){const _={path:Hr(this.rootPath,x),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:_,duration:0,encryption:o,initSegment:null,lastProgramDateTimeSeconds:h}}a=null,f===null?d=null:f=null}else if(b.startsWith(sd)){const v=new Ws(b.slice(sd.length)),x=v.get("method");if(x==="NONE")o=null;else if(x==="AES-128"){const P=v.get("uri");if(!P)throw new Error("Invalid #EXT-X-KEY: AES-128 requires a URI attribute.");let S=null;const k=v.get("iv");if(k){if(!s1.test(k))throw new Error(`Unsupported IV format '${k}'.`);let I=k.slice(2);I=I.padStart($n*2,"0"),S=new Uint8Array($n);for(let B=0;B<$n;B++){const V=-$n*2+B;S[B]=parseInt(I.slice(V,V+2),16)}}const _=v.get("keyformat")??"identity";if(_!=="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:Hr(this.rootPath,P),iv:S,keyFormat:_}}else if(x==="SAMPLE-AES"||x==="SAMPLE-AES-CTR"){const P=v.get("uri");if(!P)throw new Error(`Invalid #EXT-X-KEY: ${x} requires a URI attribute.`);if((v.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 k=null;if(a1.test(P)){const _=P.indexOf(","),I=Gu(P.slice(_+1));if(I.length>=8&&I[4]===112&&I[5]===115&&I[6]===115&&I[7]===104){const B=et(I).getUint32(0);k=Ef(I.subarray(8,Math.min(B,I.length)))}}o={method:x,psshBox:k}}else throw new Error(`Unsupported encryption method '${x}'. If you think this method should be supported, please raise an issue.`)}else if(b.startsWith(ad)){const v=b.slice(ad.length),x=Number(v);if(!Number.isInteger(x)||x<0)throw new Error(`Invalid EXT-X-MEDIA-SEQUENCE value '${v}'.`);w(x)}else if(b.startsWith(od)){const v=y(b.slice(od.length));if(v.offset===null){if(d===null)throw new Error("Invalid M3U8 file; #EXT-X-BYTERANGE without offset requires a previous byte range.");v.offset=d}f=v,d=v.offset+v.length}else if(b.startsWith(cd)){if(g)continue;const v=b.slice(cd.length),x=Date.parse(v);if(!Number.isFinite(x))continue;const P=x/1e3;if(h===P)continue;if(h===null&&this.segments.length>0){const S=Yt(this.segments),k=S.timestamp+S.duration,_=P-k;for(const I of this.segments)I.unixEpochTimestamp=I.timestamp+_,n&&(I.timestamp=I.unixEpochTimestamp)}h=P,s=P,n&&(i=P)}else if(b===$g)u=null;else if(b.startsWith(ld)){const v=b.slice(ld.length),x=Number(v);if(!Number.isFinite(x)||x<0)throw new Error(`Invalid EXT-X-TARGETDURATION value '${v}'.`);this.refreshInterval=x,p=x}else if(b===Gg){this.streamHasEnded=!0;break}else b.startsWith(ud)&&b.slice(ud.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=Ge(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);N(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 N(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(d=>Mf(d,l))&&(u=[...u,l]),this.input._formatOptions.isobmff.resolveKeyId({...c,psshBoxes:u})})}},a=new Vo({source:new Kg(n.location.path,async c=>{N(c.isRoot);const u={...c,isRoot:!1};let l;const d=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),d){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 f=n.encryption;N(f.iv);let h=await this.input._getSourceCached(u);if(d){const y=h.source.slice(n.location.offset,n.location.length??void 0).ref();h.free(),h=y}const p=new Za(h.source),m=ig(p,async()=>{const g={stack:[],error:void 0,hasError:!1};try{const y=vd(g,await this.input._getSourceCached({path:f.keyUri,isRoot:!1},Y1),!1),A=await new Za(y.source).requestSlice(0,$n);if(!A)throw new Error("Invalid AES-128 key; expected at least 16 bytes of data.");return{key:Ee(A,$n),iv:f.iv}}catch(y){g.error=y,g.hasError=!0}finally{Ad(g)}},()=>{h.free()});l=new wd(m).ref()}else N(!1);return l}),formats:this.input._formats.filter(c=>!(c instanceof Cd)),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=vc(this.inputCache,u=>u.age);N(c!==-1),this.inputCache.splice(c,1)}return a}async getLiveRefreshInterval(){return this.getRemainingWaitTimeMs()===0&&await this.runUpdateSegments(),this.streamHasEnded?null:this.refreshInterval}}class o1 extends mr{constructor(e){super(e),this.metadataPromise=null,this.trackBackings=null,this.internalTracks=null,this.segmentedInputs=[],this.hasMasterPlaylist=!0}readMetadata(){return this.metadataPromise??=(async()=>{N(this.input._rootSource instanceof is);const e=await this.input._reader.requestEntireFile();N(e);const n=$d(e,e.length,{ignore:fd}),{rootPath:r}=this.input._rootSource,i=[],s=[];for(let d=1;d<n.length;d++){const f=n[d];if(f.startsWith(td)){const h=d,p=n[++d];if(p===void 0)throw new Error("Incorrect M3U8 file; a line must follow the #EXT-X-STREAM-INF tag.");const m=Hr(r,p),g=new Ws(f.slice(td.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(f.startsWith(nd)){const h=new Ws(f.slice(nd.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=Hr(r,p);i.push({fullPath:g,attributes:h,lineNumber:d,hasOnlyKeyPackets:!0})}else if(f.startsWith(rd)){const h=new Ws(f.slice(rd.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 y=h.get("uri");y!==null&&(g=Hr(r,y)),s.push({fullPath:g,attributes:h,lineNumber:d})}else if(f!==Qg){if(f.startsWith(el)){const h=new xd(this,r,null,n);this.segmentedInputs=[h],this.hasMasterPlaylist=!1,this.trackBackings=await h.getTrackBackings();return}}}const a=[...new Set(s.filter(d=>d.attributes.get("type").toLowerCase()==="video").map(d=>d.attributes.get("group-id")))],o=[...new Set(s.filter(d=>d.attributes.get("type").toLowerCase()==="audio").map(d=>d.attributes.get("group-id")))],c=await Promise.all(i.map(async(d,f)=>{const h=[],p=d.attributes.get("codecs");let m;if(p)m=p.split(",").map(k=>k.trim());else{const _=await this.getSegmentedInputForPath(d.fullPath).getTrackBackings(),I=await Promise.all(_.map(async B=>({track:B,codec:await B.getCodec()})));m=await Promise.all(I.filter(B=>B.codec!==null).map(B=>B.track.getDecoderConfig().then(V=>V.codec)))}const g=d.attributes.get("video"),y=d.attributes.get("audio"),w=m.some(k=>yf.includes(Bs(k))),A=m.some(k=>bf.includes(Bs(k)));if(g!==null&&!w){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 k=s.find(_=>{const I=_.attributes.get("group-id"),B=_.attributes.get("type");return I===g&&B.toLowerCase()==="video"});e:if(k){const _=k.attributes.get("uri");if(_===null)break e;const I=Hr(r,_),O=(await this.getSegmentedInputForPath(I).getTrackBackings()).find(W=>W.getType()==="video");if(!O||await O.getCodec()===null)break e;const U=await O.getDecoderConfig().then(W=>W?.codec??null);N(U!==null),m.push(U)}}if(y!==null&&!A){if(!o.includes(y))throw new Error(`Invalid M3U8 file; variant stream references audio group "${y}" which is not defined in any #EXT-X-MEDIA tags.`);const k=s.find(_=>{const I=_.attributes.get("group-id"),B=_.attributes.get("type");return I===y&&B.toLowerCase()==="audio"});e:if(k){const _=k.attributes.get("uri");if(_===null)break e;const I=Hr(r,_),O=(await this.getSegmentedInputForPath(I).getTrackBackings()).find(W=>W.getType()==="audio");if(!O||await O.getCodec()===null)break e;const U=await O.getDecoderConfig().then(W=>W?.codec??null);N(U!==null),m.push(U)}}m=[...new Set(m)];let b=null,v=null;const x=d.attributes.getAsNumber("bandwidth");N(x!==null);const P=d.attributes.getAsNumber("average-bandwidth"),S=d.attributes.get("name");for(const k of m){const _=Bs(k);if(_!==null){if(yf.includes(_)){if(b!==null)throw new Error("Unsupported M3U8 file; multiple video codecs found in the CODECS attribute of a variant stream.");b=k;const I=d.attributes.get("video");if(I===null){const B=d.attributes.get("resolution");let V=null,O=null;if(B){const U=B.match(/^(\d+)x(\d+)$/);U&&(V=Number(U[1]),O=Number(U[2]))}h.push({id:-1,demuxer:this,backingTrack:null,default:!0,autoselect:!0,languageCode:qt,lineNumber:d.lineNumber,fullPath:d.fullPath,fullCodecString:b,pairingMask:1n<<BigInt(f),peakBitrate:x,averageBitrate:P,name:S,hasOnlyKeyPackets:d.hasOnlyKeyPackets,info:{type:"video",width:V,height:O}})}else{if(!a.includes(I))throw new Error(`Invalid M3U8 file; variant stream references video group "${I}" which is not defined in any #EXT-X-MEDIA tags.`);for(const B of s){const V=B.attributes.get("group-id"),O=B.attributes.get("type");if(V!==I||O.toLowerCase()!=="video")continue;const U=B.attributes.get("resolution")??d.attributes.get("resolution");let W=null,ie=null;if(U){const we=U.match(/^(\d+)x(\d+)$/);we&&(W=Number(we[1]),ie=Number(we[2]))}h.push({id:-1,demuxer:this,backingTrack:null,default:Ya(B.attributes),autoselect:Ya(B.attributes)||Pd(B.attributes),languageCode:_d(B.attributes.get("language")),lineNumber:B.lineNumber,fullPath:B.fullPath??d.fullPath,fullCodecString:b,pairingMask:1n<<BigInt(f),peakBitrate:null,averageBitrate:null,name:B.attributes.get("name"),hasOnlyKeyPackets:d.hasOnlyKeyPackets,info:{type:"video",width:W,height:ie}})}}}else if(bf.includes(_)){if(v!==null)throw new Error("Unsupported M3U8 file; multiple audio codecs found in the CODECS attribute of a variant stream.");v=k;const I=d.attributes.get("audio");if(I===null){const B=d.attributes.get("channels"),V=B!==null?Number(B.split("/")[0]):null;h.push({id:-1,demuxer:this,backingTrack:null,default:!0,autoselect:!0,languageCode:qt,lineNumber:d.lineNumber,fullPath:d.fullPath,fullCodecString:v,pairingMask:1n<<BigInt(f),peakBitrate:x,averageBitrate:P,name:S,hasOnlyKeyPackets:d.hasOnlyKeyPackets,info:{type:"audio",numberOfChannels:V!==null&&Number.isInteger(V)&&V>0?V:null}})}else{if(!o.includes(I))throw new Error(`Invalid M3U8 file; variant stream references audio group "${I}" which is not defined in any #EXT-X-MEDIA tags.`);for(const B of s){const V=B.attributes.get("group-id"),O=B.attributes.get("type");if(V!==I||O.toLowerCase()!=="audio")continue;const U=B.attributes.get("channels")??d.attributes.get("channels"),W=U!==null?Number(U.split("/")[0]):null;h.push({id:-1,demuxer:this,backingTrack:null,default:Ya(B.attributes),autoselect:Ya(B.attributes)||Pd(B.attributes),languageCode:_d(B.attributes.get("language")),lineNumber:B.lineNumber,fullPath:B.fullPath??d.fullPath,fullCodecString:v,pairingMask:1n<<BigInt(f),peakBitrate:null,averageBitrate:null,name:B.attributes.get("name"),hasOnlyKeyPackets:d.hasOnlyKeyPackets,info:{type:"audio",numberOfChannels:W!==null&&Number.isInteger(W)&&W>0?W:null}})}}}}}return h})),u=[],l=d=>{const f=u.find(h=>h.fullPath===d.fullPath&&h.info.type===d.info.type);f?(f.pairingMask|=d.pairingMask,f.default||=d.default,f.autoselect||=d.autoselect,f.lineNumber=Math.min(f.lineNumber,d.lineNumber),d.peakBitrate!==null&&(f.peakBitrate=Math.max(f.peakBitrate??-1/0,d.peakBitrate)),d.averageBitrate!==null&&(f.averageBitrate=Math.max(f.averageBitrate??-1/0,d.averageBitrate)),f.languageCode===qt&&(f.languageCode=d.languageCode)):(d.id=u.length+1,u.push(d))};for(const d of c)for(const f of d)l(f);u.sort((d,f)=>d.lineNumber-f.lineNumber),this.trackBackings=[];for(const d of u)d.info.type==="video"?this.trackBackings.push(new Td(d)):this.trackBackings.push(new Sd(d));this.internalTracks=u})()}async getTrackBackings(){return await this.readMetadata(),N(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 xd(this,e,r,null),this.segmentedInputs.push(n),n}async getMetadataTags(){return{}}async getMimeType(){return ed}dispose(){if(this.segmentedInputs){for(const e of this.segmentedInputs)e.dispose();this.segmentedInputs.length=0}}}class kd{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 Td){for(const s of i)if(await s.getCodec()===this.getCodec()){n=s;break}}else{N(this instanceof Sd);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{...hr,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(){N(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 Td extends kd{constructor(e){super(e)}get backingVideoTrack(){return this.internalTrack.backingTrack}getType(){return"video"}getCodec(){return Bs(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 Sd extends kd{constructor(e){super(e)}get backingAudioTrack(){return this.internalTrack.backingTrack}getType(){return"audio"}getCodec(){return Bs(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 Ya=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}".`)},Pd=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}".`)},_d=t=>{if(t===null)return qt;const e=t.split("-")[0];return e||qt};class Gn{constructor(){this._isIsobmff=!1}}class Ed extends Gn{constructor(){super(...arguments),this._isIsobmff=!0}async _getMajorBrand(e){let n=e._reader.requestSlice(0,12);if(le(n)&&(n=await n),!n)return null;n.skip(4);const r=mt(n,4);return r!=="ftyp"&&r!=="styp"?null:mt(n,4)}_createDemuxer(e){return new bu(e)}}class c1 extends Ed{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(le(s)&&(s=await s),!s)return!1;let a=ve(s),o=8;if(a===1){let u=e._reader.requestSlice(r+8,8);if(le(u)&&(u=await u),!u)return!1;a=un(u),o=16}if(a<o)return!1;const c=mt(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 l1 extends Ed{async _canReadInput(e){return await this._getMajorBrand(e)==="qt "}get name(){return"QuickTime File Format"}get mimeType(){return"video/quicktime"}}class Md extends Gn{async isSupportedEBMLOfDocType(e,n){let r=e._reader.requestSlice(0,gr);if(le(r)&&(r=await r),!r)return!1;const i=Vf(r);if(i===null||i<1||i>8||He(r,i)!==ce.EBML)return!1;const a=Wf(r);if(typeof a!="number")return!1;let o=e._reader.requestSlice(r.filePos,a);if(le(o)&&(o=await o),!o)return!1;const c=r.filePos;for(;o.filePos<=c+a-bn;){const u=yr(o);if(!u)break;const{id:l,size:d}=u,f=o.filePos;if(d===void 0)return!1;switch(l){case ce.EBMLVersion:if(He(o,d)!==1)return!1;break;case ce.EBMLReadVersion:if(He(o,d)!==1)return!1;break;case ce.DocType:if(Ji(o,d)!==n)return!1;break;case ce.DocTypeVersion:if(He(o,d)>4)return!1;break}o.filePos=f+d}return!0}_canReadInput(e){return this.isSupportedEBMLOfDocType(e,"matroska")}_createDemuxer(e){return new mg(e)}get name(){return"Matroska"}get mimeType(){return"video/x-matroska"}}class u1 extends Md{_canReadInput(e){return this.isSupportedEBMLOfDocType(e,"webm")}get name(){return"WebM"}get mimeType(){return"video/webm"}}class f1 extends Gn{async _canReadInput(e){let n=0;for(;;){let d=e._reader.requestSlice(n,wn);if(le(d)&&(d=await d),!d)break;const f=Ar(d);if(!f)break;n=d.filePos+f.size}const r=await Qc(e._reader,n,n+4096);if(!r)return!1;const i=r.header,s=_f(i.mpegVersionId,i.channel);let a=e._reader.requestSlice(r.startPos+s,4);if(le(a)&&(a=await a),!a)return!1;const o=ve(a);if(o===Sf||o===Pf)return!0;n=r.startPos+r.header.totalSize;const u=await Qc(e._reader,n,n+fi);if(!u)return!1;const l=u.header;return!(i.channel!==l.channel||i.sampleRate!==l.sampleRate)}_createDemuxer(e){return new yg(e)}get name(){return"MP3"}get mimeType(){return"audio/mpeg"}}class d1 extends Gn{async _canReadInput(e){let n=e._reader.requestSlice(0,12);if(le(n)&&(n=await n),!n)return!1;const r=mt(n,4);return r!=="RIFF"&&r!=="RIFX"&&r!=="RF64"?!1:(n.skip(4),mt(n,4)==="WAVE")}_createDemuxer(e){return new _g(e)}get name(){return"WAVE"}get mimeType(){return"audio/wav"}}class h1 extends Gn{async _canReadInput(e){let n=e._reader.requestSlice(0,4);return le(n)&&(n=await n),n?mt(n,4)==="OggS":!1}_createDemuxer(e){return new Sg(e)}get name(){return"Ogg"}get mimeType(){return"application/ogg"}}class m1 extends Gn{async _canReadInput(e){let n=0;for(;;){let i=e._reader.requestSlice(n,wn);if(le(i)&&(i=await i),!i)break;const s=Ar(i);if(!s)break;n=i.filePos+s.size}let r=e._reader.requestSlice(n,4);return le(r)&&(r=await r),r?mt(r,4)==="fLaC":!1}get name(){return"FLAC"}get mimeType(){return"audio/flac"}_createDemuxer(e){return new Lg(e)}}class p1 extends Gn{async _canReadInput(e){let n=0;for(;;){let a=e._reader.requestSlice(n,wn);if(le(a)&&(a=await a),!a)break;const o=Ar(a);if(!o)break;n=a.filePos+o.size}let r=e._reader.requestSliceRange(n,Yc,ns);if(le(r)&&(r=await r),!r)return!1;const i=Hs(r);if(!i||(n+=i.frameLength,r=e._reader.requestSliceRange(n,Yc,ns),le(r)&&(r=await r),!r))return!1;const s=Hs(r);return s?i.objectType===s.objectType&&i.samplingFrequencyIndex===s.samplingFrequencyIndex&&i.channelConfiguration===s.channelConfiguration:!1}_createDemuxer(e){return new Mg(e)}get name(){return"ADTS"}get mimeType(){return"audio/aac"}}class g1 extends Gn{async _canReadInput(e){const n=ln+16+1;let r=e._reader.requestSlice(0,n);if(le(r)&&(r=await r),!r)return!1;const i=Ee(r,n);return i[0]===71&&i[ln]===71||i[0]===71&&i[ln+16]===71?!0:i[4]===71&&i[4+ln+4]===71}_createDemuxer(e){return new jg(e)}get name(){return"MPEG Transport Stream"}get mimeType(){return"video/MP2T"}}class Cd extends Gn{async _canReadInput(e){let n=e._reader.requestSlice(0,7);if(le(n)&&(n=await n),!n||!(mt(n,7)==="#EXTM3U"))return!1;if(!(e._rootSource instanceof is))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 o1(e)}get name(){return"HTTP Live Streaming (HLS)"}get mimeType(){return ed}}const y1=new c1,b1=new l1,w1=new Md,v1=new u1,A1=new f1,x1=new d1,k1=new h1,T1=new p1,S1=new m1,P1=new g1,_1=new Cd,E1=[_1,y1,b1,w1,v1,x1,k1,S1,A1,T1,P1],M1=(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 C1=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},I1=(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});wc();let Id=-1/0,Rd=-1/0,nl=null;typeof FinalizationRegistry<"u"&&(nl=new FinalizationRegistry(t=>{const e=performance.now();t.type==="video"?(e-Id>=1e3&&(Be._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."),Id=e),typeof VideoFrame<"u"&&t.data instanceof VideoFrame&&t.data.close()):(e-Rd>=1e3&&(Be._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."),Rd=e),typeof AudioData<"u"&&t.data instanceof AudioData&&t.data.close())}));class pi{constructor(){this._referenceCount=0,this._lastAllocationBuffer=null}}const rl=["I420","I420P10","I420P12","I420A","I420AP10","I420AP12","I422","I422P10","I422P12","I422A","I422AP10","I422AP12","I444","I444P10","I444P12","I444A","I444AP10","I444AP12","NV12","RGBA","RGBX","BGRA","BGRX"],R1=new Set(rl);class Ln{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(Wi*this.timestamp)}get microsecondDuration(){return Math.trunc(Wi*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||!R1.has(n.format))throw new TypeError("init.format must be one of: "+rl.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&&Ac(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??D1(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?lr(e):lr(e).slice(),this._layout=r,this.colorSpace=new il(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&&Ac(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 il(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&&Ac(n.visibleRect,"init.visibleRect"),typeof VideoFrame<"u")return new Ln(new VideoFrame(e,{timestamp:Math.trunc(n.timestamp*Wi),duration:Math.trunc((n.duration??0)*Wi)||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:c0(),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 il({matrix:"rgb",primaries:"bt709",transfer:"iec61966-2-1",fullRange:!0})}else if(e instanceof pi){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&&!rl.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=Ra({num:this.squarePixelWidth*this.codedHeight,den:this.squarePixelHeight*this.codedWidth}),nl?.register(this,{type:"video",data:this._data},this)}clone(){if(this._closed)throw new Error("VideoSample is closed.");return N(this._data!==null),this._data instanceof pi?new Ln(this._data,{timestamp:this.timestamp,duration:this.duration,rotation:this.rotation,encodeOptions:this.encodeOptions}):qs(this._data)?new Ln(this._data.clone(),{timestamp:this.timestamp,duration:this.duration,rotation:this.rotation,encodeOptions:this.encodeOptions}):this._data instanceof Uint8Array?(N(this._layout),new Ln(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 Ln(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||(nl?.unregister(this),this._data instanceof pi?(this._data._referenceCount--,this._data._referenceCount===0&&this._data.close()):qs(this._data)?this._data.close():this._data=null,this._closed=!0)}allocationSize(e={}){if(Ld(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 qs(this._data)?this._data.allocationSize(e):Ud(this,e).allocationSize}async copyTo(e,n={}){if(!Jp(e))throw new TypeError("destination must be an ArrayBuffer or an ArrayBuffer view.");if(Ld(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(N(this._data!==null),qs(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 pi){const u={stack:[],error:void 0,hasError:!1};try{const l=C1(u,await this._data.toRgbSample({timestamp:this.timestamp,duration:this.duration,rotation:this.rotation},n.colorSpace??"srgb"),!1);if(!(l instanceof Ln))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{I1(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=Ud(this,n);N(this.format);const i=lr(e);if(i.byteLength<r.allocationSize)throw new TypeError(`Destination buffer too small. Required: ${r.allocationSize}, Available: ${i.byteLength}`);const s=Ka(this.format);let a;if(this._data instanceof pi){let u=this._data.getDataPlanes();if(le(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)N(this._layout),N(this._layout.length===s.length),a=this._layout.map((u,l)=>{const d=Math.ceil(this.codedHeight/s[l].heightDivisor);return{data:this._data.subarray(u.offset,u.offset+u.stride*d),stride:u.stride}});else{const l=this._data.getContext("2d");N(l);const d=l.getImageData(0,0,this.codedWidth,this.codedHeight);a=[{data:lr(d.data),stride:4*this.codedWidth}]}const o=[],c=s.length;for(let u=0;u<c;u++){const l=r.computedLayouts[u],d=a[u].stride,f=a[u].data;let h=l.sourceTop*d;h+=l.sourceLeftBytes;let p=l.destinationOffset;const m=l.sourceWidthBytes,g={offset:p,stride:l.destinationStride};for(let y=0;y<l.sourceHeight;y++){if(h+m>f.byteLength)throw new Error("Source buffer OOB read.");if(p+m>i.byteLength)throw new Error("Destination buffer OOB write.");const w=f.subarray(h,h+m);i.set(w,p),h+=d,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 d=0;d<r.allocationSize;d+=4){if(u){const f=i[d],h=i[d+2];i[d]=h,i[d+2]=f}l&&(i[d+3]=255)}}return o}toVideoFrame(){if(this._closed)throw new Error("VideoSample is closed.");if(N(this._data!==null),this._data instanceof pi){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(le(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 qs(this._data)?new VideoFrame(this._data,{timestamp:this.microsecondTimestamp,duration:this.microsecondDuration||void 0}):this._data instanceof Uint8Array?(N(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,d=0,f=this.displayWidth,h=this.displayHeight,p=0,m=0,g=this.displayWidth,y=this.displayHeight;if(a!==void 0?(l=n,d=r,f=i,h=s,p=a,m=o,c!==void 0?(g=c,y=u):(g=f,y=h)):(p=n,m=r,i!==void 0&&(g=i,y=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(d))throw new TypeError("sy must be a number.");if(!Number.isFinite(f)||f<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(y)||y<0)throw new TypeError("dHeight must be a non-negative number.");if(this._closed)throw new Error("VideoSample is closed.");({sx:l,sy:d,sWidth:f,sHeight:h}=this._rotateSourceRegion(l,d,f,h,this.rotation));const w=this.toCanvasImageSource();e.save();const A=p+g/2,b=m+y/2;e.translate(A,b),e.rotate(this.rotation*Math.PI/180);const v=this.rotation%180===0?1:g/y;e.scale(1/v,v),e.drawImage(w,l,d,f,h,-g/2,-y/2,g,y),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&&Nd(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=Dd(c,a,o));let u,l,d,f;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,d=r,f=i;else{const[w,A]=n.crop?[n.crop.width,n.crop.height]:[a,o],b=n.fit==="contain"?Math.min(r/w,i/A):Math.max(r/w,i/A);d=w*b,f=A*b,u=(r-d)/2,l=(i-f)/2}e.save();const y=s%180===0?1:d/f;e.translate(r/2,i/2),e.rotate(s*Math.PI/180),e.scale(1/y,y),e.translate(-r/2,-i/2),e.drawImage(this.toCanvasImageSource(),h,p,m,g,u,l,d,f),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 d=i*2**l,f=s*2**l,{canvas:h,context:p,isNew:m}=l>0?Fd(d,f):{canvas:e,context:n,isNew:r.targetIsFresh};p.imageSmoothingQuality="high",r.fillBlack?(p.fillStyle="black",p.fillRect(0,0,d,f)):m||p.clearRect(0,0,d,f),this.drawWithFit(p,{fit:r.fit,rotation:r.rotation,crop:r.crop}),p.globalCompositeOperation="copy";for(let g=l;g>1;g--){const y=i*2**g,w=s*2**g;p.drawImage(h,0,0,y,w,0,0,y/2,w/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(N(this._data!==null),this._data instanceof pi||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&&Nd(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=tc(this.rotation+(e.rotate??0)),[r,i]=n%180===0?[this.squarePixelWidth,this.squarePixelHeight]:[this.squarePixelHeight,this.squarePixelWidth];let s=e.crop;s&&(s=Dd(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=lc(u,e.roundDimensionsTo??1),l=lc(l,e.roundDimensionsTo??1);const d={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 B1){let g=m(this,d);if(le(g)&&(g=await g),g!==null)return g}const{canvas:f,context:h,isNew:p}=Fd(d.width,d.height);return this._drawWithFitAndMipmapping(f,h,{fit:d.fit,rotation:d.rotation,crop:d.crop,targetIsFresh:p,fillBlack:d.alpha==="discard"}),new Ln(f,{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 B1=[],F1=3,js=[];let Bd=0;const Fd=(t,e)=>{for(const i of js)if(i.canvas.width===t&&i.canvas.height===e)return i.age=Bd++,{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 js.length>=F1&&js.splice(vc(js,i=>i.age),1),js.push({canvas:n,context:r,age:Bd++}),{canvas:n,context:r,isNew:!0}};class il{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(rc);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(ic);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(sc);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 qs=t=>typeof VideoFrame<"u"&&t instanceof VideoFrame,Dd=(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 N(s>=0),N(a>=0),{left:r,top:i,width:s,height:a}},Nd=(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.")},Ld=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.")}},D1=(t,e,n)=>{const r=Ka(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},Ka=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:Ca(t),N(!1)}},Ud=(t,e)=>{const n={left:0,top:0,width:t.codedWidth,height:t.codedHeight},r=e.rect,i=N1(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 U1(i,a,s)},N1=(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(!L1(i,s))throw new TypeError("visibleRect alignment is invalid for the format.");return s},L1=(t,e)=>{if(t===null)return!0;const n=Ka(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},U1=(t,e,n)=>{const r=Ka(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,d=u.widthDivisor,f=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)/f),h.sourceHeight=Math.ceil(Math.trunc(t.height||0)/f),h.sourceLeftBytes=Math.floor(Math.trunc(t.x||0)/d)*l,h.sourceWidthBytes=Math.floor(Math.trunc(t.width||0)/d)*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 y=a[g];if(!(o[c]<=y.destinationOffset||o[g]<=h.destinationOffset))throw new TypeError("Planes overlap.")}a.push(h)}return{allocationSize:s,computedLayouts:a}};const Od=[],O1=[];const gi=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.")},ss=t=>{if(!Ia(t))throw new TypeError("timestamp must be a number.")},sl=(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 al{constructor(e){if(!(e instanceof ma))throw new TypeError("track must be an InputTrack.");this._track=e}async getFirstPacket(e={}){if(gi(e),this._track.input._disposed)throw new Lt;return sl(this._track,this._track._backing.getFirstPacket(e),e)}async getFirstKeyPacket(e={}){gi(e);const n=await this.getFirstPacket(e);return n?n.type==="key"?n:this.getNextKeyPacket(n,e):null}async getPacket(e,n={}){if(ss(e),gi(n),this._track.input._disposed)throw new Lt;return sl(this._track,this._track._backing.getPacket(e,n),n)}async getNextPacket(e,n={}){if(!(e instanceof kt))throw new TypeError("packet must be an EncodedPacket.");if(gi(n),this._track.input._disposed)throw new Lt;return sl(this._track,this._track._backing.getNextPacket(e,n),n)}async getKeyPacket(e,n={}){if(ss(e),gi(n),this._track.input._disposed)throw new Lt;if(!n.verifyKeyPackets)return this._track._backing.getKeyPacket(e,n);const r=await this._track._backing.getKeyPacket(e,n);return r&&(N(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 kt))throw new TypeError("packet must be an EncodedPacket.");if(gi(n),this._track.input._disposed)throw new Lt;if(!n.verifyKeyPackets)return this._track._backing.getNextKeyPacket(e,n);const r=await this._track._backing.getNextKeyPacket(e,n);return r&&(N(r.type==="key"),await this._track.determinePacketType(r)==="delta"?this.getNextKeyPacket(r,n):r)}packets(e,n,r={}){if(e!==void 0&&!(e instanceof kt))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 kt))throw new TypeError("endPacket must be an EncodedPacket.");if(gi(r),this._track.input._disposed)throw new Lt;const i=[];let{promise:s,resolve:a}=Dt(),{promise:o,resolve:c}=Dt(),u=!1,l=!1,d=null,f=!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}=Dt()),await o;continue}i.push(g),a(),{promise:s,resolve:a}=Dt(),g=await this.getNextPacket(g,r)}u=!0,a()})().catch(g=>{f||(d=g,f=!0,a())});const m=this._track;return{async next(){for(;;){if(m.input._disposed)throw new Lt;if(l)return{value:void 0,done:!0};if(f)throw d;if(i.length>0){const g=i.shift(),y=performance.now();for(h.push(y);h.length>0&&y-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 z1{constructor(e,n){this.onSample=e,this.onError=n}}class H1{mediaSamplesInRange(e=-1/0,n=1/0,r){ss(e),ss(n);const i=[];let s=!1,a=null,{promise:o,resolve:c}=Dt(),{promise:u,resolve:l}=Dt(),d=!1,f=!1,h=!1,p=null,m=null,g=!1;const y={...r,verifyKeyPackets:!0,metadataOnly:!1};(async()=>{p=await this._createDecoder(k=>{if(l(),k.timestamp>=n&&(f=!0),f){k.close();return}a&&(k.timestamp>e?(i.push(a),s=!0):a.close()),k.timestamp>=e&&(i.push(k),s=!0),a=s?null:k,i.length>0&&(c(),{promise:o,resolve:c}=Dt())},k=>{g||(m=k,g=!0,c())});const b=this._createPacketSink(),v=await b.getKeyPacket(e,y)??await b.getFirstKeyPacket(y);let x=v;const S=b.packets(v??void 0,void 0,y);for(await S.next();x&&!f&&!this._track.input._disposed;){const k=zd(i.length);if(i.length+p.getDecodeQueueSize()>k){({promise:u,resolve:l}=Dt()),await u;continue}p.decode(x);const _=await S.next();if(_.done)break;x=_.value}await S.return(),!h&&!this._track.input._disposed&&await p.flush(),!s&&a&&i.push(a),d=!0,c()})().catch(b=>{g||(m=b,g=!0,c())}).finally(()=>{p?.close()});const w=this._track,A=()=>{a?.close();for(const b of i)b.close()};return{async next(){for(;;){if(w.input._disposed)throw h=!0,f=!0,A(),new Lt;if(h)return{value:void 0,done:!0};if(g)throw h=!0,f=!0,A(),m;if(i.length>0){const b=i.shift();return l(),{value:b,done:!1}}else if(!d)await o;else return{value:void 0,done:!0}}},async return(){return h=!0,f=!0,l(),c(),A(),{value:void 0,done:!0}},async throw(b){throw b},[Symbol.asyncIterator](){return this}}}mediaSamplesAtTimestamps(e,n){r0(e);const r=n0(e),i=[],s=[];let{promise:a,resolve:o}=Dt(),{promise:c,resolve:u}=Dt(),l=!1,d=!1,f=null,h=null,p=!1;const m=A=>{s.push(A),o(),{promise:a,resolve:o}=Dt()},g={...n,verifyKeyPackets:!0,metadataOnly:!1};(async()=>{f=await this._createDecoder(k=>{if(u(),d){k.close();return}let _=0;for(;i.length>0&&k.timestamp-i[0]>-1e-10;)_++,i.shift();if(_>0)for(let I=0;I<_;I++)m(I<_-1?k.clone():k);else k.close()},k=>{p||(h=k,p=!0,o())});const A=this._createPacketSink();let b=null,v=null,x=-1;const P=async()=>{N(v),N(f);let k=v;for(f.decode(k);k.sequenceNumber<x;){const _=zd(s.length);for(;s.length+f.getDecodeQueueSize()>_&&!d;)({promise:c,resolve:u}=Dt()),await c;if(d)break;const I=await A.getNextPacket(k,g);N(I),f.decode(I),k=I}x=-1},S=async()=>{N(f),await f.flush();for(let k=0;k<i.length;k++)m(null);i.length=0};for await(const k of r){if(ss(k),d||this._track.input._disposed)break;const _=await A.getPacket(k,g),I=_&&await A.getKeyPacket(k,g);if(!I){x!==-1&&(await P(),await S()),m(null),b=null;continue}b&&(I.sequenceNumber!==v.sequenceNumber||_.timestamp<b.timestamp)&&(await P(),await S()),i.push(_.timestamp),x=Math.max(_.sequenceNumber,x),b=_,v=I}!d&&!this._track.input._disposed&&(x!==-1&&await P(),await S()),l=!0,o()})().catch(A=>{p||(h=A,p=!0,o())}).finally(()=>{f?.close()});const y=this._track,w=()=>{for(const A of s)A?.close()};return{async next(){for(;;){if(y.input._disposed)throw d=!0,w(),new Lt;if(d)return{value:void 0,done:!0};if(p)throw d=!0,w(),h;if(s.length>0){const A=s.shift();return N(A!==void 0),u(),{value:A,done:!1}}else if(!l)await a;else return{value:void 0,done:!0}}},async return(){return d=!0,u(),o(),w(),{value:void 0,done:!0}},async throw(A){throw A},[Symbol.asyncIterator](){return this}}}}const zd=t=>t===0?40:8;class V1 extends z1{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 o0,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=Od.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 Ln))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 d=this.alphaQueue.shift();N(d!==void 0),this.mergeAlpha(l,d)}else this.colorQueue.push(l)};if(yc()){if(r==="avc"&&this.decoderConfig.description){const l=tf(lr(this.decoderConfig.description));if(l&&l.sequenceParameterSets.length>0){const d=Oa(l.sequenceParameterSets[0]);d&&d.frameMbsOnlyFlag===0&&(this.decoderConfig={...this.decoderConfig,hardwareAcceleration:"prefer-software"})}}ac(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(d){this.onError(d)}},error:l=>{l.stack=u,this.onError(l)}}),this.decoder.configure(this.decoderConfig)}}getDecodeQueueSize(){return this.customDecoder?this.customDecoderQueueSize:(N(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(N(this.decoder),mc()||Hu(this.inputTimestamps,e.timestamp,n=>n),yc()&&this.currentPacketIndex===0){if(this.codec==="avc"){const n=[];let r=!1;for(const s of Zu(e.data,this.decoderConfig)){const a=La(e.data[s.offset]);if(r||=a>=1&&a<=5,a===Rt.AUD){if(r)break;n.length=0}a>=20&&a<=31||n.push(e.data.subarray(s.offset,s.offset+s.length))}const i=h0(n,this.decoderConfig);e=new kt(i,e.type,e.timestamp,e.duration)}else if(this.codec==="hevc"){const n=x0(e.data,this.decoderConfig);n&&(e=new kt(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 W1),!this.alphaDecoder){const r=s=>{if(this.colorQueue.length>0){const a=this.colorQueue.shift();N(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();N(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=Ic(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 za(e,this.decoderConfig)){const r=qi(e[n.offset]);if(r===vt.RASL_N||r===vt.RASL_R)return!0}return!1}sampleHandler(e){if(mc()){if(this.sampleQueue.length>0&&e.timestamp>=Yt(this.sampleQueue).timestamp){for(const n of this.sampleQueue)this.finalizeAndEmitSample(n);this.sampleQueue.length=0}Hu(this.sampleQueue,e,n=>n.timestamp)}else{const n=this.inputTimestamps.shift();N(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=Dt();this.mergeAlphaPromises.push(r.promise);const i={sample:null};this.finalSamples.push(i);try{if(!n)i.sample=new Ln(e);else{N(this.merger);const s=await this.merger.merge(e,n);i.sample=new Ln(s)}for(;this.finalSamples.length>0&&this.finalSamples[0].sample!==null;){const s=this.finalSamples.shift();this.sampleHandler(s.sample)}}catch(s){oc(this.finalSamples,i),this.onError(s)}finally{oc(this.mergeAlphaPromises,r.promise),r.resolve()}}async flush(){if(this.customDecoder?await this.customDecoderCallSerializer.call(()=>this.customDecoder.flush()):(N(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),mc()){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()):(N(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 ol=null;class W1{constructor(){this.workers=[],this.nextWorkerIndex=0,this.pendingRequests=new Map,this.nextRequestId=0}merge(e,n){if(this.workers.length===0){if(!ol){const o=new Blob([`(${j1.toString()})()`],{type:"application/javascript"});ol=URL.createObjectURL(o)}const a=Ms(navigator.hardwareConcurrency,1,4);for(let o=0;o<a;o++){const c=new Worker(ol);c.addEventListener("message",u=>{const l=u.data,d=this.pendingRequests.get(l.id);d&&(this.pendingRequests.delete(l.id),"error"in l?d.reject(new Error(l.error)):d.resolve(l.frame))}),c.addEventListener("error",u=>{const l=new Error(u.message||"Color/alpha merge worker error.");for(const d of this.pendingRequests.values())d.reject(l);this.pendingRequests.clear()}),this.workers.push(c)}}const r=this.nextRequestId++,i=Dt();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 j1=()=>{let t=null,e=null,n=Promise.resolve();self.addEventListener("message",c=>{const{id:u,color:l,alpha:d}=c.data;n=n.then(async()=>{try{const f=await r(l,d);self.postMessage({id:u,frame:f},{transfer:[f]})}catch(f){self.postMessage({id:u,error:f.message})}finally{l.close(),d.close()}})});const r=async(c,u)=>{const l=c.format,d=u.format;if(!l||!d)throw new Error("CPU color/alpha merging requires a known VideoFrame format.");const f=l.includes("P10"),h=l.includes("P12"),p=d.includes("P10"),m=d.includes("P12");if(p!==f||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: '${d}').`);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 d=c.visibleRect?.width??c.codedWidth,f=c.visibleRect?.height??c.codedHeight,h=d*f,p=new Uint8Array(h*4);await c.copyTo(p);const m=await o(u,d,f,1);for(let w=0,A=3;w<h;w++,A+=4)p[A]=m[w];const y={format:l==="RGBX"||l==="RGBA"?"RGBA":"BGRA",codedWidth:d,codedHeight:f,timestamp:c.timestamp,duration:c.duration??void 0,transfer:[p.buffer]};return new VideoFrame(p,y)},s=async(c,u,l)=>{const d=c.visibleRect?.width??c.codedWidth,f=c.visibleRect?.height??c.codedHeight,h=l.includes("P10"),p=l.includes("P12"),m=h||p?2:1;let g,y;l.startsWith("I420")?(g=Math.ceil(d/2),y=Math.ceil(f/2)):l.startsWith("I422")?(g=Math.ceil(d/2),y=f):(g=d,y=f);const w=d*f,A=g*y,b=w*m,v=A*m,x=w*m,P=b+2*v+x,S=new Uint8Array(P);await c.copyTo(S);const k=await o(u,d,f,m),_=b+2*v;S.set(k,_);const B={format:l.slice(0,4)+"A"+l.slice(4),codedWidth:d,codedHeight:f,timestamp:c.timestamp,duration:c.duration??void 0,transfer:[S.buffer]};return new VideoFrame(S,B)},a=async(c,u)=>{const l=c.visibleRect?.width??c.codedWidth,d=c.visibleRect?.height??c.codedHeight,f=l*d,h=Math.ceil(l/2),p=Math.ceil(d/2),m=h*p,g=c.allocationSize();(!e||e.byteLength!==g)&&(e=new Uint8Array(g)),await c.copyTo(e);const y=new Uint8Array(f+2*m+f);y.set(e.subarray(0,f),0);const w=f,A=f+m,b=f;for(let P=0;P<m;P++)y[w+P]=e[b+P*2],y[A+P]=e[b+P*2+1];const v=await o(u,l,d,1);y.set(v,f+2*m);const x={format:"I420A",codedWidth:l,codedHeight:d,timestamp:c.timestamp,duration:c.duration??void 0,transfer:[y.buffer]};return new VideoFrame(y,x)},o=async(c,u,l,d)=>{const f=c.allocationSize();(!t||t.byteLength!==f)&&(t=new Uint8Array(f)),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*d)}},q1=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 X1 extends H1{constructor(e,n={}){if(!(e instanceof ll))throw new TypeError("videoTrack must be an InputVideoTrack.");q1(n),super(),this._track=e,this._decoderOptions=n}async _createDecoder(e,n){if(!await this._track.canDecode())throw typeof VideoDecoder>"u"?new Error(l0("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 N(r&&s),s={...s,hardwareAcceleration:this._decoderOptions.hardwareAcceleration,optimizeForLatency:this._decoderOptions.optimizeForLatency},new V1(e,n,r,s,i,a)}_createPacketSink(){return new al(this._track)}async getSample(e,n={}){ss(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 ma{constructor(e,n){this.input=e,this._backing=n}isVideoTrack(){return this instanceof ll}isAudioTrack(){return this instanceof Hd}get id(){return this._backing.getId()}get number(){return this._backing.getNumber()}async getInternalCodecId(){return this._backing.getInternalCodecId()}get internalCodecId(){return dt(this._backing.getInternalCodecId(),"internalCodecId","getInternalCodecId")}async getLanguageCode(){return this._backing.getLanguageCode()}get languageCode(){return dt(this._backing.getLanguageCode(),"languageCode","getLanguageCode")}async getName(){return this._backing.getName()}get name(){return dt(this._backing.getName(),"name","getName")}async getTimeResolution(){return this._backing.getTimeResolution()}get timeResolution(){return dt(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 dt(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 ju(r,await this.getTimeResolution())}async getDurationFromMetadata(e={}){return this._backing.getDurationFromMetadata(e)}async computePacketStats(e=1/0,n){const r=new al(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 ma))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(yi({filter:n=>n.canBePairedWith(this)},e))}async getPairableVideoTracks(e){return this.input.getVideoTracks(yi({filter:n=>n.canBePairedWith(this)},e))}async getPairableAudioTracks(e){return this.input.getAudioTracks(yi({filter:n=>n.canBePairedWith(this)},e))}async getPrimaryPairableVideoTrack(e){return this.input.getPrimaryVideoTrack(yi({filter:n=>n.canBePairedWith(this)},e))}async getPrimaryPairableAudioTrack(e){return this.input.getPrimaryAudioTrack(yi({filter:n=>n.canBePairedWith(this)},e))}async hasPairableTrack(e){e&&=cl(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&&=cl(e),this.hasPairableTrack(async n=>n.isVideoTrack()&&(!e||await e(n)))}hasPairableAudioTrack(e){return e&&=cl(e),this.hasPairableTrack(async n=>n.isAudioTrack()&&(!e||await e(n)))}}const dt=(t,e,n)=>{if(le(t))throw new Error(`'${e}' is deprecated and not available synchronously for this track. Use the preferred '${n}()' instead.`);return t},cl=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 le(r)?r.then(n):n(r)}:void 0};class ll extends ma{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 dt(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 dt(this._backing.getCodedWidth(),"codedWidth","getCodedWidth")}async getCodedHeight(){return this._backing.getCodedHeight()}get codedHeight(){return dt(this._backing.getCodedHeight(),"codedHeight","getCodedHeight")}async getRotation(){return this._backing.getRotation()}get rotation(){return dt(this._backing.getRotation(),"rotation","getRotation")}async getSquarePixelWidth(){return this._backing.getSquarePixelWidth()}get squarePixelWidth(){return dt(this._backing.getSquarePixelWidth(),"squarePixelWidth","getSquarePixelWidth")}async getSquarePixelHeight(){return this._backing.getSquarePixelHeight()}get squarePixelHeight(){return dt(this._backing.getSquarePixelHeight(),"squarePixelHeight","getSquarePixelHeight")}async getPixelAspectRatio(){return this._pixelAspectRatioCache??=Ra({num:await this.getSquarePixelWidth()*await this.getCodedHeight(),den:await this.getSquarePixelHeight()*await this.getCodedWidth()})}get pixelAspectRatio(){return this._pixelAspectRatioCache??=Ra({num:dt(this._backing.getSquarePixelWidth(),"pixelAspectRatio","getPixelAspectRatio")*dt(this._backing.getCodedHeight(),"pixelAspectRatio","getPixelAspectRatio"),den:dt(this._backing.getSquarePixelHeight(),"pixelAspectRatio","getPixelAspectRatio")*dt(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=dt(e,"displayWidth","getDisplayWidth");if(i!==null)return i}const r=dt(this._backing.getRotation(),"displayWidth","getDisplayWidth")%180===0?this._backing.getSquarePixelWidth():this._backing.getSquarePixelHeight();return dt(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=dt(e,"displayHeight","getDisplayHeight");if(i!==null)return i}const r=dt(this._backing.getRotation(),"displayHeight","getDisplayHeight")%180===0?this._backing.getSquarePixelHeight():this._backing.getSquarePixelWidth();return dt(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 N(n!==null),Od.some(i=>i.supports(n,e))?!0:typeof VideoDecoder>"u"?!1:(await VideoDecoder.isConfigSupported(e)).supported===!0}catch(e){return Be._error("Error during decodability check:",e),!1}}async determinePacketType(e){if(!(e instanceof kt))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 N(r),Ic(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&&(!Ia(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 al(this),s=[];let a=-1/0,o=0;for await(const _ of i.packets(void 0,void 0,{metadataOnly:!0})){if(s.length>=r&&_.timestamp>=a)break;s.push(_.timestamp),a=Math.max(a,_.timestamp),o++}const c=new Float64Array(s.length);for(let _=0;_<s.length;_++)c[_]=Math.round(s[_]*n);c.sort();let u=1;for(let _=1;_<c.length;_++)c[_]!==c[u-1]&&(c[u++]=c[_]);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),d=$1(l,n),f=d??n,h=d!==null?n/d:null,p=new Map;let m=1/0,g=-1/0,y=0;for(let _=1;_<u;_++){const I=l[_]-l[_-1],B=h!==null?Math.max(1,Math.round(I/h)):I;p.set(B,(p.get(B)??0)+1),m=Math.min(m,B),g=Math.max(g,B),y+=B}const w=u-1,A=[...p.keys()].sort((_,I)=>_-I),b=w-1>>1,v=w>>1;let x=0,P=0,S=0;for(const _ of A)if(S+=p.get(_),x===0&&S>b&&(x=_),S>v){P=_;break}const k=(f/x+f/P)/2;return{underlyingFrameRate:d,bestGuessFrameRate:d!==null?d:G1(k),minFrameRate:f/g,maxFrameRate:f/m,averageFrameRate:f*w/y,medianFrameRate:k,frameRateIsConstant:d!==null&&m===1&&g===1,probedPacketCount:o}}}class Hd extends ma{constructor(e,n){super(e,n),this._backing=n}get type(){return"audio"}async getCodec(){return this._backing.getCodec()}get codec(){return dt(this._backing.getCodec(),"codec","getCodec")}async hasOnlyKeyPackets(){return await this._backing.getHasOnlyKeyPackets?.()??!0}async getNumberOfChannels(){return this._backing.getNumberOfChannels()}get numberOfChannels(){return dt(this._backing.getNumberOfChannels(),"numberOfChannels","getNumberOfChannels")}async getSampleRate(){return this._backing.getSampleRate()}get sampleRate(){return dt(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 N(n!==null),O1.some(r=>r.supports(n,e))||e.codec.startsWith("pcm-")?!0:typeof AudioDecoder>"u"?!1:(await AudioDecoder.isConfigSupported(e)).supported===!0}catch(e){return Be._error("Error during decodability check:",e),!1}}async determinePacketType(e){if(!(e instanceof kt))throw new TypeError("packet must be an EncodedPacket.");return await this.getCodec()===null?null:"key"}}const Vd=t=>-(t??-1/0),Xs=t=>-t,$s=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 le(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 le(r)?r.then(n):n(r)}:void 0}},yi=(t,e)=>({filter:t?.filter||e?.filter?n=>{const r=t?.filter?.(n)??!0,i=s=>s===!1?!1:e?.filter?.(n)??!0;return le(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 le(r)||le(i)?Promise.all([r,i]).then(([a,o])=>s(a,o)):s(r,i)}:void 0}),ul=async(t,e)=>{let n=t;if(e?.filter){const a=t.map(c=>e.filter(c));if(a.some(c=>le(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=>le(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 d=0;d<l;d++){const f=c[d]??0,h=u[d]??0;if(f!==h)return f-h}return 0}).map(a=>a.track)},$1=(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 P=1;P<t.length;P++){const S=t[P]-t[P-1];if(!(S>0))return null;o[P-1]=S}const c=o.slice();c.sort();let u=c[Math.floor(c.length*.05)];for(let P=0;P<6;P++){let S=0,k=0;for(const I of o){const B=Math.max(1,Math.round(I/u));Math.abs(I-B*u)>=i||(S+=I,k+=B)}if(k===0)return null;const _=S/k;if(Math.abs(_-u)<=1e-12*Math.max(1,u)){u=_;break}u=_}let l=0,d=0,f=0;for(const P of o){const S=Math.max(1,Math.round(P/u));Math.abs(P-S*u)>=i||(l++,d+=P,f+=S)}if(l/o.length<.98)return null;u=d/f;const h=1/Math.min(f,s),p=Math.max(Number.EPSILON,u-h),m=u+h,g=e/m,y=e/p,w=e/u;let A=null,b=1/0;for(const P of a){if(P<g||P>y)continue;const S=Math.abs(P/w-1);S<b&&(A=P,b=S)}if(A===null){const P=Wd(p,m,1e6),S=Wd(g,y,1e6);if(S&&(!P||S.den<P.den||S.den===P.den&&S.num<=P.num))A=S.num/S.den;else if(P)A=e*P.den/P.num;else return null}const v=e/A;let x=0;for(const P of o){const S=Math.max(1,Math.round(P/v));Math.abs(P-S*v)<i&&x++}return x/o.length<.98?null:A},Wd=(t,e,n)=>{for(let r=1;r<=n;r++){const i=Math.floor(t*r)+1;if(i/r<e)return Ra({num:i,den:r})}return null},G1=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};wc();const Q1=1,Y1=2;class Vo extends xc{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 wr||e.source instanceof tl))throw new TypeError("options.source must be a Source or SourceRef.");if(e.source instanceof wr&&e.source._disposed)throw new TypeError("options.source must not be a disposed Source.");if(e.initInput!==void 0&&!(e.initInput instanceof Vo))throw new TypeError("options.initInput, when provided, must be an Input.");e.formatOptions!==void 0&&M1(e.formatOptions,"formatOptions"),this._formats=e.formats,this._initInput=e.initInput??null,this._formatOptions=e.formatOptions??{},e.source instanceof wr?this._rootRef=e.source.ref():this._rootRef=e.source,this._sourceRefs.push(this._rootRef)}get _rootSource(){return this._rootRef.source}async _getSourceUncached(e){N(this._rootSource instanceof is);const n=await this._rootSource._resolveRequest(e);return this._emit("source",{source:n.source,request:e,isRoot:e.isRoot}),n}_getSourceCached(e,n=Q1){const r=this._sourceCache.find(a=>a.cacheGroup===n&&yd(a.request,e));if(r)return r.age++,Promise.resolve(r.sourceRef.source.ref());const i=this._sourceCachePromises.find(a=>a.cacheGroup===n&&yd(a.request,e));if(i)return i.promise.then(a=>a.sourceRef.source.ref());const s=(async()=>{const a=await this._getSourceUncached(e);if(Is(this._sourceCache,d=>d.cacheGroup===n&&d.sourceRef.source._refCount===1)>=4){const d=vc(this._sourceCache,h=>h.cacheGroup===n&&h.sourceRef.source._refCount===1?h.age:1/0);N(d!==-1);const f=this._sourceCache[d];this._sourceCache.splice(d,1),f.sourceRef.free(),oc(this._sourceRefs,f.sourceRef)}this._sourceRefs.push(a);const u=this._sourceCachePromises.findIndex(d=>d.request===e);return N(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 Za(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 jd})()}get source(){return this._rootSource}async getFormat(){return await this._getDemuxer(),N(this._format),this._format}async canRead(){try{return await this._getDemuxer(),!0}catch(e){if(e instanceof jd)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&&=$s(e);const r=(await this._getTrackBackings()).map(i=>this._wrapBackingAsTrack(i));return ul(r,e)}async getVideoTracks(e){e&&=$s(e);const r=(await this.getTracks()).filter(i=>i.isVideoTrack());return ul(r,e)}async getAudioTracks(e){e&&=$s(e);const r=(await this.getTracks()).filter(i=>i.isAudioTrack());return ul(r,e)}async getPrimaryVideoTrack(e){e&&=$s(e);const n=yi(e,{sortBy:async i=>[Xs((await i.getDisposition()).default),Xs(await i.hasPairableAudioTrack()),Xs(!await i.hasOnlyKeyPackets()),Vd(await i.getBitrate())]});return(await this.getVideoTracks(n))[0]??null}async getPrimaryAudioTrack(e){e&&=$s(e);const n=await this.getPrimaryVideoTrack(),r=yi(e,{sortBy:async s=>[Xs(!n||s.canBePairedWith(n)),Xs((await s.getDisposition()).default),Vd(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 ll(this,e):new Hd(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 jd extends Error{constructor(e="Input has an unsupported or unrecognizable format."){super(e),this.name="UnsupportedInputFormatError"}}class Lt extends Error{constructor(e="Input has been disposed."){super(e),this.name="InputDisposedError"}}class Za{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 Lt;if(e<0||this.fileSizeNonStrict!==null&&e+n>this.fileSizeNonStrict)return null;if(n===0){const s=new Uint8Array(0);return new Nn(s,et(s),0,e,e)}const r=e+n,i=this.source._read(e,r,pd,gd);return le(i)?i.then(s=>s?new Nn(s.bytes,s.view,s.offset,e,r):null):i?new Nn(i.bytes,i.view,i.offset,e,r):null}requestSliceRange(e,n,r){if(this.source._disposed)throw new Lt;if(e<0)return null;if(this.fileSizeNonStrict!==null)return this.requestSlice(e,Ms(this.fileSizeNonStrict-e,n,r));{const i=this.requestSlice(e,r),s=a=>a||(N(this.fileSizeNonStrict!==null),this.requestSlice(e,Ms(this.fileSizeNonStrict-e,n,r)));return le(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(le(a)&&(a=await a),!a||a.length===0)break;const o=Ee(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 Nn(i,et(i),0,0,r)})()}}class Nn{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 Nn(e,et(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 Nn(this.bytes,this.view,this.offset,e,e+n)}}const Jt=(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.`)},Ee=(t,e)=>{Jt(t,e);const n=t.bytes.subarray(t.bufferPos,t.bufferPos+e);return t.bufferPos+=e,n},Se=t=>(Jt(t,1),t.view.getUint8(t.bufferPos++)),Gs=(t,e)=>{Jt(t,2);const n=t.view.getUint16(t.bufferPos,e);return t.bufferPos+=2,n},At=t=>{Jt(t,2);const e=t.view.getUint16(t.bufferPos,!1);return t.bufferPos+=2,e},vr=t=>{Jt(t,3);const e=Wu(t.view,t.bufferPos);return t.bufferPos+=3,e},fl=t=>{Jt(t,2);const e=t.view.getInt16(t.bufferPos,!1);return t.bufferPos+=2,e},jr=(t,e)=>{Jt(t,4);const n=t.view.getUint32(t.bufferPos,e);return t.bufferPos+=4,n},ve=t=>{Jt(t,4);const e=t.view.getUint32(t.bufferPos,!1);return t.bufferPos+=4,e},as=t=>{Jt(t,4);const e=t.view.getUint32(t.bufferPos,!0);return t.bufferPos+=4,e},bi=t=>{Jt(t,4);const e=t.view.getInt32(t.bufferPos,!1);return t.bufferPos+=4,e},K1=t=>{Jt(t,4);const e=t.view.getInt32(t.bufferPos,!0);return t.bufferPos+=4,e},qd=(t,e)=>{let n,r;return e?(n=jr(t,!0),r=jr(t,!0)):(r=jr(t,!1),n=jr(t,!1)),r*4294967296+n},un=t=>{const e=ve(t),n=ve(t);return e*4294967296+n},Z1=t=>{const e=bi(t),n=ve(t);return e*4294967296+n},J1=t=>{const e=as(t);return K1(t)*4294967296+e},ey=t=>{Jt(t,4);const e=t.view.getFloat32(t.bufferPos,!1);return t.bufferPos+=4,e},Xd=t=>{Jt(t,8);const e=t.view.getFloat64(t.bufferPos,!1);return t.bufferPos+=8,e},mt=(t,e)=>{Jt(t,e);let n="";for(let r=0;r<e;r++)n+=String.fromCharCode(t.bytes[t.bufferPos++]);return n},$d=(t,e,n)=>Kt.decode(Ee(t,e)).split(`
|
|
2
|
+
`).map(s=>s.trim()).filter(s=>s.length>0&&!n?.ignore?.(s));var wi;(function(t){t[t.Unsynchronisation=128]="Unsynchronisation",t[t.ExtendedHeader=64]="ExtendedHeader",t[t.ExperimentalIndicator=32]="ExperimentalIndicator",t[t.Footer=16]="Footer"})(wi||(wi={}));var os;(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"})(os||(os={}));const Ja=128,wn=10,cs=["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"],ty=(t,e)=>{const n=t.filePos;e.raw??={},e.raw.TAG??=Ee(t,Ja-3),t.filePos=n;const r=ls(t,30);r&&(e.title??=r);const i=ls(t,30);i&&(e.artist??=i);const s=ls(t,30);s&&(e.album??=s);const a=ls(t,4),o=Number.parseInt(a,10);Number.isInteger(o)&&o>0&&(e.date??=new Date(String(o)));const c=Ee(t,30);let u;if(c[28]===0&&c[29]!==0){const d=c[29];d>0&&(e.trackNumber??=d),t.skip(-30),u=ls(t,28),t.skip(2)}else t.skip(-30),u=ls(t,30);u&&(e.comment??=u);const l=Se(t);l<cs.length&&(e.genre??=cs[l])},ls=(t,e)=>{const n=Ee(t,e),r=ji(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()},Ar=t=>{const e=t.filePos,n=mt(t,3),r=Se(t),i=Se(t),s=Se(t),a=ve(t);if(n!=="ID3"||r===255||i===255||(a&2155905152)!==0)return t.filePos=e,null;let o=Oc(a);return s&wi.Footer&&(o+=wn),{majorVersion:r,revision:i,flags:s,size:o}},eo=(t,e,n)=>{if(![2,3,4].includes(e.majorVersion)){Be._warn(`Unsupported ID3v2 major version: ${e.majorVersion}`);return}const r=e.flags&wi.Footer?e.size-wn:e.size,i=Ee(t,r),s=new ny(e,i);if(e.flags&wi.Unsynchronisation&&e.majorVersion===3&&s.ununsynchronizeAll(),e.flags&wi.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,d=!1;if(e.majorVersion===3?(u=!!(a.flags&64),l=!!(a.flags&128)):e.majorVersion===4&&(u=!!(a.flags&4),l=!!(a.flags&8),d=!!(a.flags&2)||!!(e.flags&wi.Unsynchronisation)),u){Be._warn(`Skipping encrypted ID3v2 frame ${a.id}`),s.pos=c;continue}if(l){Be._warn(`Skipping compressed ID3v2 frame ${a.id}`),s.pos=c;continue}if(d&&s.ununsynchronizeRegion(s.pos,c),n.raw??={},a.id==="TXXX"){const f=n.raw.TXXX??={},h=s.readId3V2TextEncoding(),p=s.readId3V2Text(h,c),m=s.readId3V2Text(h,c);f[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 f=s.readId3V2EncodingAndText(c);let h=/^\((\d+)\)/.exec(f);if(h){const p=Number.parseInt(h[1]);if(cs[p]!==void 0){n.genre??=cs[p];break}}if(h=/^\d+$/.exec(f),h){const p=Number.parseInt(h[0]);if(cs[p]!==void 0){n.genre??=cs[p];break}}n.genre??=f}break;case"TDRC":case"TDAT":{const f=s.readId3V2EncodingAndText(c),h=new Date(f);Number.isNaN(h.getTime())||(n.date??=h)}break;case"TYER":case"TYE":{const f=s.readId3V2EncodingAndText(c),h=Number.parseInt(f,10);Number.isInteger(h)&&(n.date??=new Date(String(h)))}break;case"USLT":case"ULT":{const f=s.readU8();s.pos+=3,s.readId3V2Text(f,c),n.lyrics??=s.readId3V2Text(f,c)}break;case"COMM":case"COM":{const f=s.readU8();s.pos+=3,s.readId3V2Text(f,c),n.comment??=s.readId3V2Text(f,c)}break;case"APIC":case"PIC":{const f=s.readId3V2TextEncoding();let h;if(e.majorVersion===2){const y=s.readAscii(3);h=y==="PNG"?"image/png":y==="JPG"?"image/jpeg":"image/*"}else h=s.readId3V2Text(f,c);const p=s.readU8(),m=s.readId3V2Text(f,c).trimEnd(),g=c-s.pos;if(g>=0){const y=s.readBytes(g);n.images||(n.images=[]),n.images.push({data:y,mimeType:h,kind:p===3?"coverFront":p===4?"coverBack":"unknown",description:m})}}break;default:s.pos+=a.size;break}s.pos=c}};class ny{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?Oc(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:Oc(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 os.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 os.UTF_16_WITH_BOM:if(i[0]===255&&i[1]===254){const s=new TextDecoder("utf-16le"),a=ji(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=ji(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=ji(i.findIndex(a=>a===0),i.length);return this.pos=r+Math.min(s+1,i.length),Kt.decode(i.subarray(0,s))}case os.UTF_16_BE_NO_BOM:{const s=new TextDecoder("utf-16be"),a=ji(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 os.UTF_8:{const s=ji(i.findIndex(a=>a===0),i.length);return this.pos=r+Math.min(s+1,i.length),Kt.decode(i.subarray(0,s))}}}readId3V2EncodingAndText(e){if(this.pos>=e)return"";const n=this.readId3V2TextEncoding();return this.readId3V2Text(n,e)}}function Gd(){return typeof VideoDecoder=="function"&&typeof VideoFrame=="function"}const Qd=6,Yd=16;function ry(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 I=t.renderDpr||0,B=Math.min(window.devicePixelRatio||1,I<=0?window.devicePixelRatio||1:I),V=Math.max(1,Math.round((t.container.clientWidth||window.innerWidth)*B)),O=Math.max(1,Math.round((t.container.clientHeight||window.innerHeight)*B));e.width!==V&&(e.width=V),e.height!==O&&(e.height=O)};c(),window.addEventListener("resize",c);const u=[];let l=null,d=null,f=null,h=0,p=0,m=Qd,g=0,y=!1,w=-1,A=0,b=!1;const v=I=>{const B=e.width,V=e.height,O=I.displayWidth,U=I.displayHeight;if(B<=0||V<=0||O<=0||U<=0)return;const W=t.fit();if(W==="stretch"){I.draw(n,0,0,B,V);return}const ie=W==="cover"?Math.max(B/O,V/U):Math.min(B/O,V/U),we=Math.round(O*ie),Y=Math.round(U*ie),oe=Math.round((B-we)/2),he=Math.round((V-Y)/2);W==="contain"&&(n.fillStyle="#000",n.fillRect(0,0,B,V)),I.draw(n,oe,he,we,Y)},x=()=>h+(performance.now()-s)/1e3%p,P=()=>{g++,m<Yd&&g%30===1&&(m=Math.min(Yd,m+2),!y&&m>=Qd+4&&(y=!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 I=x();for(;u.length>0;){const U=u[0],W=u[1];if(U.timestamp-I>p/2){U.close(),u.shift();continue}if(W&&W.timestamp<=I+1e-4){U.close(),u.shift();continue}break}const B=u[0];if(!B){P();return}if(B.timestamp>I+1e-4||B.timestamp===w)return;const V=t.fps(),O=performance.now();if(!(V>0&&O-A<1e3/V-.5)){w=B.timestamp,A=O;try{v(B)}catch{return}t.onFrame?.(),b||(b=!0,t.onFirstFrame?.())}},k=I=>new Promise(B=>setTimeout(B,I)),_=async()=>{try{for(;!r;){for(;!r&&(u.length>=m||o||t.paused());)await k(20);if(r)return;f||(f=d.samples(h));const I=await f.next();if(r){I.value?.close();return}if(I.done){f=null;continue}u.push(I.value)}}catch(I){r||t.onFatal(`\u89E3\u7801\u6CF5\u5F02\u5E38: ${I?.message??I}`)}};return(async()=>{try{l=new Vo({source:new wu(t.src),formats:E1});const I=await l.getPrimaryVideoTrack();if(!I)throw new Error("\u65E0\u89C6\u9891\u8F68");if(!await I.canDecode())throw new Error(`\u7F16\u7801\u4E0D\u53EF\u89E3\uFF08${I.codec}\uFF09`);const B=await I.computeDuration();if(h=await I.getFirstTimestamp(),p=Math.max(B-h,B>0?B:0),!isFinite(p)||p<=0)throw new Error("\u65F6\u957F\u5F02\u5E38");if(r){try{l.dispose()}catch{}return}d=new X1(I);const V=await I.getDisplayWidth(),O=await I.getDisplayHeight();t.onDiag?.(`${I.codec} ${V}x${O} ${p.toFixed(2)}s \u2192 WebCodecs \u9010\u5E27\u8C03\u5EA6`),_(),i=requestAnimationFrame(S)}catch(I){r||t.onFatal(I?.message??String(I))}})(),{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 I of u.splice(0))try{I.close()}catch{}f&&f.return(void 0).catch(()=>{});try{l?.dispose()}catch{}e.remove()}}}}function iy(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=Kd(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=ay(t,s,u);s+=u;const d=e.getUint32(s,!0);s+=4;const f=e.getUint32(s,!0);s+=4,a.push({name:l,offset:d,size:f})}const o=s;return{magic:r,version:r.slice(4),count:i,entries:a,dataStart:o,fileSize:t.length,buf:t}}function dl(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 sy(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 Kd(t,e,n){let r="";for(let i=e;i<e+n;i++)r+=String.fromCharCode(t[i]);return r}function ay(t,e,n){try{return new TextDecoder("utf-8",{fatal:!0}).decode(t.subarray(e,e+n))}catch{return Kd(t,e,n)}}const oy=Object.freeze(Object.defineProperty({__proto__:null,getEntry:dl,parsePkg:iy,verifyLayout:sy},Symbol.toStringTag,{value:"Module"})),to={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"},$t={UNKNOWN:-1,JPEG:2,PNG:13,GIF:25,WEBP:35,MP4:35};function cy(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===$t.PNG)return{width:n.width,height:n.height,png:n.data};if(t.freeImageFormat!==$t.UNKNOWN)return{width:n.width,height:n.height,image:n.data,fif:t.freeImageFormat};const r=no(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:hl(r,n.width,n.height,t.width,t.height)}:{width:n.width,height:n.height,rgba:r}}function ly(t,e){const n=t.images[0];if(!n||n.length===0)throw new Error("\u65E0\u56FE\u50CF\u6570\u636E");const r=Math.max(0,Math.min(n.length-1,Math.floor(e)||0)),i=n[r];if(t.isVideo)return{width:i.width,height:i.height,video:i.data,level:r};if(t.freeImageFormat===$t.PNG)return{width:i.width,height:i.height,png:i.data,level:r};if(t.freeImageFormat!==$t.UNKNOWN)return{width:i.width,height:i.height,image:i.data,fif:t.freeImageFormat,level:r};const s=no(t.format,i.data,i.width,i.height);if(!t.frames?.list?.length){const a=Math.min(i.width,Math.max(1,Math.round((t.width||i.width)/2**r))),o=Math.min(i.height,Math.max(1,Math.round((t.height||i.height)/2**r)));if(i.width!==a||i.height!==o)return{width:a,height:o,rgba:hl(s,i.width,i.height,a,o),level:r}}return{width:i.width,height:i.height,rgba:s,level:r}}function uy(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!==$t.UNKNOWN){n.push({width:r.width,height:r.height,image:r.data,fif:t.freeImageFormat});continue}const i=no(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:hl(n[0].rgba,n[0].width,n[0].height,t.width,t.height)}),n}function hl(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 no(t,e,n,r){switch(t){case 0:return fy(e,n,r);case 1:return dy(e,n,r);case 2:return hy(e,n,r);case 4:return by(e,n,r);case 6:return yy(e,n,r);case 7:return gy(e,n,r);case 8:return my(e,n,r);case 9:return py(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: "+(to[t]||t))}}function fy(t,e,n){return new Uint8Array(t.buffer,t.byteOffset,e*n*4).slice()}function dy(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 hy(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 my(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 py(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 gy(t,e,n){return ml(t,e,n,!0,0)}function yy(t,e,n){return ml(t,e,n,!1,3)}function by(t,e,n){return ml(t,e,n,!1,5)}function ml(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 d=wy(o,r),f=vy(o,r),h=i===3?Ay(o):i===5?xy(o):null;for(let p=0;p<4;p++)for(let m=0;m<4;m++){const g=l+m,y=u+p;if(g>=e||y>=n)continue;const w=p*4+m,A=(y*e+g)*4;s[A]=d[f[w]*4],s[A+1]=d[f[w]*4+1],s[A+2]=d[f[w]*4+2],s[A+3]=h!==null?h[w]:d[f[w]*4+3]}}return s}function Zd(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 wy(t,e){const n=e?0:8,r=Zd(t,n),i=Zd(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 vy(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 Ay(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 xy(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 ky(t,e,n,r,i){const s=Math.ceil(e/4),a=Math.ceil(n/4),o=Math.ceil(r/4);if(s===a)return t.subarray(0,a*o*i);const c=new Uint8Array(a*o*i);for(let u=0;u<o;u++){const l=u*s*i;c.set(t.subarray(l,l+a*i),u*a*i)}return c}function Jd(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 tt(t,e){return(t[e]|t[e+1]<<8|t[e+2]<<16|t[e+3]<<24)>>>0}function ro(t,e){return tt(t,e)|0}const Qs=new DataView(new ArrayBuffer(4));function qr(t,e){return Qs.setUint8(0,t[e]),Qs.setUint8(1,t[e+1]),Qs.setUint8(2,t[e+2]),Qs.setUint8(3,t[e+3]),Qs.getFloat32(0,!0)}const Ty={[$t.PNG]:[137,80,78,71],[$t.JPEG]:[255,216,255],[$t.GIF]:[71,73,70],[$t.WEBP]:[82,73,70,70]};function Sy(t){let e=0;const n=Ys(t,e,9);if(e+=9,n==="TEXV0004\0")return Py(t);if(n!=="TEXV0005\0")throw new Error("\u4E0D\u662F .tex \u6587\u4EF6: "+n);const r=Ys(t,e,9);if(e+=9,r!=="TEXI0001\0")throw new Error("\u672A\u77E5 TEXI \u5B50\u5BB9\u5668: "+r);const i=tt(t,e);e+=4;const s=tt(t,e);e+=4;const a=tt(t,e);e+=4;const o=tt(t,e);e+=4;let c=46;for(let v=34;v<=64;v++){const x=Ys(t,v,9);if(x==="TEXB0001\0"||x==="TEXB0002\0"||x==="TEXB0003\0"||x==="TEXB0004\0"){c=v;break}}const u=tt(t,c-12),l=tt(t,c-8);e=c;const d=Ys(t,e,9);e+=9;const f=tt(t,e);e+=4;let h=$t.UNKNOWN,p=0;if(d==="TEXB0004\0"){h=tt(t,e)|0,e+=4;const v=tt(t,e);e+=4,h===$t.UNKNOWN&&v===1&&(h=$t.MP4),p=v===1?4:3}else if(d==="TEXB0003\0")h=tt(t,e)|0,e+=4,p=3;else if(d==="TEXB0002\0")p=2;else if(d==="TEXB0001\0")p=1;else throw new Error("\u672A\u77E5 TEXB \u5BB9\u5668: "+d);const m=(s&32)!==0||h===$t.MP4,g=[];for(let v=0;v<f;v++){const x=tt(t,e);e+=4;const P=[];for(let S=0;S<x;S++){if(p===4){for(e+=8;e<t.length&&t[e]!==0;)e++;e+=1,e+=4}const k=tt(t,e);e+=4;const _=tt(t,e);e+=4;let I=0;if(s&64&&p>=2&&!m){const ie=tt(t,e),we=ro(t,e+8),Y=tt(t,e+4),oe=ro(t,e+12),he=Ce=>{if(!(oe>=0)||Ce+oe>t.length)return!1;const Le=Ty[h];return Le?Le.every((Ne,De)=>t[Ce+De]===Ne):!0},Ae=ie<=1&&we>=0&&e+12+we<=t.length,Pe=Y<=1&&he(e+16);!Ae&&Pe&&(I=4)}e+=I;let B=0,V=0;p>=2&&(B=tt(t,e),e+=4,V=ro(t,e),e+=4);const O=ro(t,e);if(e+=4,m){P.push({width:k,height:_,compression:0,data:t.subarray(e)}),e=t.length;continue}B===0&&(V=O);const U=t.subarray(e,e+O);e+=O;let W=U;B===1&&(W=Jd(U,V)),P.push({width:k,height:_,compression:B,data:W})}g.push(P)}const y=g[0]&&g[0][0],w=y?y.width:a,A=y?y.height:o;let b=null;if(e+13<=t.length){const v=Ys(t,e,9);if(v.indexOf("TEXS")===0){let x=e+9;const P=tt(t,x);x+=4;let S=0,k=0;v==="TEXS0003\0"&&(S=tt(t,x),x+=4,k=tt(t,x),x+=4);const _=t.length-x,I=P>0&&_>0&&_%P===0?_/P:0;if(P>0&&P<=4096&&I>=32){const B=[];for(let O=0;O<P;O++){const U=x+O*I;if(U+32>t.length)break;const W=qr(t,U+8),ie=qr(t,U+12),we=qr(t,U+16),Y=qr(t,U+20),oe=qr(t,U+24),he=qr(t,U+28),Ae=Math.hypot(we,Y),Pe=Math.hypot(oe,he);B.push({imageId:qr(t,U)|0,duration:qr(t,U+4),x:W,y:ie,width:(Ae>1e-30?Ae:0)||S,height:(Pe>1e-30?Pe:0)||k,uDir:[we,Y],vDir:[oe,he],rotated:Math.abs(Y)>.5||Math.abs(oe)>.5})}B.length===P&&B.every(O=>{if(!(O.width>0&&O.height>0))return!1;const U=[O.x,O.x+O.uDir[0],O.x+O.vDir[0],O.x+O.uDir[0]+O.vDir[0]],W=[O.y,O.y+O.uDir[1],O.y+O.vDir[1],O.y+O.uDir[1]+O.vDir[1]];return Math.min(...U)>=-1&&Math.max(...U)<=w+1&&Math.min(...W)>=-1&&Math.max(...W)<=A+1})&&(b={magic:v,frameWidth:S,frameHeight:k,atlasWidth:w,atlasHeight:A,list:B})}}}return{format:i,formatName:to[i]||String(i),flags:s,textureWidth:a,textureHeight:o,width:u,height:l,freeImageFormat:h,containerMagic:d,containerVersion:p,isVideo:m,images:g,frames:b}}function Py(t){let e=9;const n=tt(t,e);e+=4;const r=tt(t,e);e+=4;const i=tt(t,e);e+=4;const s=tt(t,e);e+=4;const a=tt(t,e);e+=4;const o=tt(t,e);e+=4;const c=tt(t,e);e+=4;const u=[];for(let l=0;l<c;l++){if(e+12>t.length)throw new Error("TEXV0004 mip \u8BB0\u5F55\u8D8A\u754C @"+l);const d=tt(t,e);e+=4;const f=tt(t,e);e+=4;const h=tt(t,e);if(e+=4,e+h>t.length)throw new Error("TEXV0004 \u8F7D\u8377\u8D8A\u754C @"+l);u.push([{width:d,height:f,compression:0,data:t.subarray(e,e+h)}]),e+=h}return{format:n,formatName:to[n]||String(n),flags:r,textureWidth:i,textureHeight:s,width:a,height:o,freeImageFormat:$t.UNKNOWN,containerMagic:"TEXV0004",containerVersion:0,isVideo:!1,images:u,frames:null}}function Ys(t,e,n){let r="";for(let i=e;i<e+n;i++)r+=String.fromCharCode(t[i]);return r}const _y=Object.freeze(Object.defineProperty({__proto__:null,FIF:$t,TEXTURE_FORMATS:to,cropBlocks:ky,decodeMip0:cy,decodeMipLevel:ly,decodeMips:uy,decodePixels:no,lz4Decompress:Jd,parseTex:Sy},Symbol.toStringTag,{value:"Module"})),Xr=0,pl=1;function gl(t,e){const n=new Map,r=eh(t)||Ey(n),i=eh(e)||null,s=o=>o===pl&&i?i:r,a={LOCATION_SCREEN:Xr,LOCATION_GLOBAL:pl,getItem(o,c=Xr){return s(c).get(String(o))},setItem(o,c,u=Xr){s(u).set(String(o),String(c))},delete(o,c=Xr){s(c).remove(String(o))},removeItem(o,c=Xr){s(c).remove(String(o))},clear(o=Xr){s(o).clear()},key(o,c=Xr){const u=s(c).keys();return o>=0&&o<u.length?u[o]:null}};return a.get=a.getItem,a.set=a.setItem,a.remove=a.delete,Object.defineProperties(a,{length:{enumerable:!1,get(){return r.keys().length}}}),a}function eh(t){return!t||typeof t!="object"?null:typeof t.get=="function"&&typeof t.set=="function"&&typeof t.remove=="function"&&typeof t.keys=="function"&&typeof t.clear=="function"?t:null}function Ey(t){return{get:e=>t.has(e)?t.get(e):null,set:(e,n)=>{t.set(e,String(n))},remove:e=>{t.delete(e)},keys:()=>Array.from(t.keys()),clear:()=>{t.clear()}}}function My(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 Cy(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(b){if(n(b)<=o)return[b];const v=[];let x="",P=-1;for(const S of b)if(x+=S,(S===" "||S===" ")&&(P=x.length),n(x)>o&&x.length>1)for(P>0?(v.push(x.slice(0,P-1)),x=x.slice(P)):(v.push(x.slice(0,-1)),x=S),P=-1;n(x)>o&&x.length>1;)v.push(x.slice(0,-1)),x=x.slice(-1);return x!==""&&v.push(x),v.length?v:[""]}let u=[];const l=String(t??"").split(`
|
|
3
|
+
`);for(const b of l)u.push(...c(b));let d=!1;if(e.limitrows&&e.maxrows>0&&u.length>e.maxrows&&(u=u.slice(0,e.maxrows),d=!0,e.limituseellipsis)){let b=u[e.maxrows-1];for(;b.length>0&&n(b+"\u2026")>o;)b=b.slice(0,-1);u[e.maxrows-1]=b+"\u2026"}const f=u.map(b=>n(b)),h=u.length*a,p=e.halign||"center",m=e.valign||"center",g=r/2,y=i/2,w=m==="top"?y:m==="bottom"?y-h:(i-h)/2;return{lines:u.map((b,v)=>{const x=f[v],P=p==="left"?g:p==="right"?g-x:(r-x)/2;return{text:b,width:x,x:P,y:w+v*a}}),lineHeight:a,totalH:h,truncated:d,boxW:r,boxH:i}}function th(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 Iy(t,e,n,r){const[i,s,a,o]=th(t,e,n);return Math.max(r,i,s,a,o)}function Ry(t,e,n){return t<=4&&e<=4&&!!n}function By(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,d)=>{t.fillStyle=d;for(const f of e.lines)t.fillText(f.text,f.x+u,f.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 nh=/^add[A-Z]/;function rh(){return{log:()=>{},warn:()=>{},error:()=>{},info:()=>{},debug:()=>{}}}function ih(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 us(t,e){return()=>{}}function sh(t,e){t.isScreensaver=!!e.isScreensaver,typeof e.isRunningInEditor=="boolean"&&(t.isRunningInEditor=bl(e.isRunningInEditor)),t.setInterval||(t.setInterval=e.setInterval||us),t.setTimeout||(t.setTimeout=e.setTimeout||us),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 Ue{constructor(e,n,r){if(e!==null&&typeof e=="object")this.x=e.x!==void 0?e.x:e.width||0,this.y=e.y!==void 0?e.y:e.height||0,this.z=(n!==void 0?n: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 Ue(e);return new Ue(this.x+n.x,this.y+n.y,this.z+n.z)}subtract(e){const n=new Ue(e);return new Ue(this.x-n.x,this.y-n.y,this.z-n.z)}multiply(e){return e&&typeof e=="object"?new Ue(this.x*e.x,this.y*e.y,this.z*e.z):new Ue(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 Ue(n(this.x,e.x),n(this.y,e.y),n(this.z,e.z)):new Ue(n(this.x,e),n(this.y,e),n(this.z,e))}copy(){return new Ue(this.x,this.y,this.z)}mix(e,n){const r=new Ue(e),i=Number(n),s=Number.isFinite(i)?i:0;return new Ue(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 Ue(0,0,0):new Ue(this.x/e,this.y/e,this.z/e)}dot(e){const n=new Ue(e);return this.x*n.x+this.y*n.y+this.z*n.z}toString(){return this.x+" "+this.y+" "+this.z}}const ah=Ue;function yl(t){if(t instanceof Ue||!t||typeof t!="object"||Array.isArray(t)||!("x"in t)&&!("y"in t)&&!("z"in t)||Object.getPrototypeOf(t)===Ue.prototype)return t;try{Object.setPrototypeOf(t,Ue.prototype)}catch{}return t}function oh(t){return t&&t.cursorWorldPosition?t:{cursorWorldPosition:new Ue(0,0,0),cursorScreenPosition:new Ue(0,0,0),cursorPosition:new Ue(0,0,0),cursorPositionLast:new Ue(0,0,0),cursorLeftDown:!1}}function Fy(t,e,n){return new Ue(t||0,e||0,n||0)}function Dy(){const t={cursorWorldPosition:new Ue(0,0,0),cursorScreenPosition:new Ue(0,0,0),cursorPosition:new Ue(0,0,0),cursorPositionLast:new Ue(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 ch={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},lh={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),d=[[i,u,o],[c,i,o],[o,i,u],[o,c,i],[u,o,i],[i,o,c]][s%6];return new Ue(d[0],d[1],d[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 Ue(c,s===0?0:o/s,s)}},uh={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})},fh=Object.freeze({PLAYBACK_STOPPED:0,PLAYBACK_PLAYING:1,PLAYBACK_PAUSED:2}),io=["mediaPropertiesChanged","mediaThumbnailChanged","mediaPlaybackChanged","mediaTimelineChanged","mediaStatusChanged","mediaLyricsChanged"],Ny=["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"],Ly=new RegExp(`(^[ \\t]*|;|\\})[ \\t]*(?:var|let|const)[ \\t]+(?=(?:${Ny.join("|")})\\b)`,"gm"),Uy={WEMath:!0,WEColor:!0,WEVector:!0};function dh(t){return typeof t!="string"?t:t.replace(/([!=])==(\s*)(['"])(-?\d+)\3/g,"$1=$2$3$4$3")}function hh(t){return dh(t).replace(/\bimport\s*\*\s*as\s+(\w+)\s+from\s*['"]([^'"]+)['"]\s*;?/g,(e,n,r)=>{const i=String(r);return Uy[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(Ly,"$1")}function Oy(t){if(typeof t=="boolean")return t;if(typeof t=="number"&&Number.isFinite(t))return t!==0}function mh(t){const e=Math.floor(Number(t));return Number.isFinite(e)&&e>=1?Math.min(64,e):64}function so(t){return t!==null&&typeof t=="object"&&"value"in t?t.value:t}function bl(t){const e=!!t;return Object.assign(()=>e,{valueOf(){return e},toString(){return e?"true":"false"}})}function ph(t,e,n,r){if(n!==null&&typeof n=="object"&&typeof n.user=="string"){const i=so(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]=so(n)}function gh(t){const e=t||{width:1920,height:1080};if(typeof e.divide=="function"&&e.x!==void 0)return e;const n=new Ue(e.x!==void 0?e.x:e.width||0,e.y!==void 0?e.y:e.height||0,0);return n.width=n.x,n.height=n.y,n}function zy(t,e,n={}){if(typeof t!="string"||t.length===0)return null;const r=hh(t);if(r===t&&t.indexOf("update")<0&&t.indexOf("resizeScreen")<0)return null;const i={};if(e&&typeof e=="object")for(const[b,v]of Object.entries(e))ph(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"&&nh.test(v))return x=>(x&&typeof x=="object"&&typeof x.name=="string"&&!(x.name in i)&&(i[x.name]=so(x.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:vi(n.origin||[0,0,0])},o={registerAsset:b=>b,frametime:1/60,runtime:0,canvasSize:gh(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||us,clearTimeout:n.clearTimeout||(()=>{}),setInterval:n.setInterval||us,clearInterval:n.clearInterval||(()=>{}),openUserShortcut:n.openUserShortcut||(()=>{}),isRunningInEditor:bl(n.isRunningInEditor),isScreensaver:!!n.isScreensaver};sh(o,n);const c=n.audioViews;o.registerAudioBuffers=b=>{const v=mh(b);let x=c?c.get(v):void 0;return x||(x={left:new Float32Array(v),right:new Float32Array(v),average:new Float32Array(v)},c&&c.set(v,x)),x};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:vi(n.origin||[0,0,0]),angles:[0,0,0],scale:[1,1,1]}},sortLayer:()=>{},getLayerIndex:()=>0},l=n.shared||{},d={console:rh()},f=oh(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","localStorage",`"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,`+io.map(v=>`${v}: typeof ${v} === "function" ? ${v} : null,`).join("")+'animationEvent: typeof animationEvent === "function" ? animationEvent : null,resizeScreen: typeof resizeScreen === "function" ? resizeScreen : null,dummy_: 0};')(i,ih(o),a,u,ch,lh,uh,s,l,d.console,void 0,d,d,d,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,Ue,ah,f,fh,n.storage||gl())}catch(b){return n.onError&&n.onError(b,"parse"),null}const p=!!(h&&io.some(b=>h[b])),m=!!(h&&typeof h.applyUserProperties=="function"),g=!!(h&&typeof h.animationEvent=="function"),y=!!(h&&typeof h.resizeScreen=="function");if(!h||!h.update&&!p&&!m&&!g&&!y)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 P=(/\(([^)]*)\)/.exec(b.slice(0,v))?.[1]||"").split(",").map(k=>k.trim().split(/[=\s]/)[0]).filter(Boolean);if(!P.length)return!1;let S=b.slice(v+1,b.lastIndexOf("}"));S=S.replace(/\/\*[\s\S]*?\*\//g," ").replace(/\/\/[^\n]*/g," ").replace(/'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`(?:[^`\\]|\\.)*`/g,'""').replace(/([A-Za-z_$][\w$]*)\s*:/g,(k,_)=>P.includes(_)?" :":k);for(const k of P)S=S.replace(new RegExp(`\\b${k}\\s*(\\+\\+|--|=(?!=)|\\+=|-=|\\*=|\\/=)`,"g")," "),S=S.replace(new RegExp(`return\\s+${k}\\s*;?`,"g")," ");return P.some(k=>new RegExp(`\\b${k}\\b`).test(S))})();h.update&&w&&(a.text="");const A={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,hasResizeHook:y,errCount:0,disabled:!1,init(b){if(h.init)try{return h.init(b)}catch(v){A.errCount++,n.onError&&n.onError(v,"init")}},applyUserProperties(b){if(h.applyUserProperties)try{h.applyUserProperties(b||{})}catch(v){A.errCount++,n.onError&&n.onError(v,"applyUserProperties")}},callUpdateRaw(b){if(!(!h.update||A.disabled))try{return h.update(b)}catch(v){A.errCount++,n.onError&&n.onError(v,"update"),A.errCount>=3&&(A.disabled=!0);return}},callUpdate(b){if(!h.update||A.disabled)return null;const v=a.text;let x;try{x=h.update(v)}catch(P){return A.errCount++,n.onError&&n.onError(P,"update"),A.errCount>=3&&(A.disabled=!0),null}return typeof x=="string"?(a.text=x,x):typeof x=="boolean"?null:x!=null?(a.text=String(x),a.text):a.text!==v?a.text:null},callCursor(b,v){if(A.disabled)return;const x=h[b];if(typeof x=="function")try{return x(v)}catch(P){A.errCount++,n.onError&&n.onError(P,b),A.errCount>=3&&(A.disabled=!0);return}},callMedia(b,v){if(A.disabled)return;const x=h[b];if(typeof x=="function")try{return x(v)}catch(P){A.errCount++,n.onError&&n.onError(P,b),A.errCount>=3&&(A.disabled=!0);return}},callAnimationEvent(b,v){if(!A.disabled&&typeof h.animationEvent=="function")try{return h.animationEvent(b,v)}catch(x){A.errCount++,n.onError&&n.onError(x,"animationEvent"),A.errCount>=3&&(A.disabled=!0);return}},callResize(b,v){if(A.disabled||typeof h.resizeScreen!="function")return;const x=Number(b)||0,P=Number(v)||0;o.screenResolution={x,y:P};const S={x,y:P,width:x,height:P};try{const k=h.resizeScreen(S);return typeof k=="string"&&(a.text=k),k}catch(k){A.errCount++,n.onError&&n.onError(k,"resizeScreen"),A.errCount>=3&&(A.disabled=!0);return}},updateIsWriteback:w};return A}function Ks(){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 Hy(t){if(!t)return Ks();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 Vy(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 Wy(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],d=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]]},f=p=>{let m=0,g=0,y=p;for(let w=0;y>=0&&y<i&&w<64;w++){const A=d(y);m+=A[0],g+=A[1],y=r[y].parent}return u(m,g)},h=p=>{const m={translation(g){if(g===void 0){const v=f(p);return new Ue(v[0],v[1],0)}const y=xr(g);let w=0,A=0;if(r[p].parent>=0){const v=f(r[p].parent),x=l(v[0],v[1]);w=x[0],A=x[1]}const b=l(y[0],y[1]);return e.set(p,[b[0]-w,b[1]-A,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(y){return y===void 0?new Ue(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 wl(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 yh(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 jy(t,e){t&&(t.visibleSelf=!1,t.visible=!1,t.destroyed=!0,e&&typeof e.recomputeVisibility=="function"&&e.recomputeVisibility())}function bh(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 qy(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 Xy(t){const e=n=>ao(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=bh(n,s)}const i=t.createSceneLayer(r);return e(i||null)},destroyLayer(n){jy(yh(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 Ks()},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):yh(n,t)||null}}}function ao(t,e){const n=o=>vi(Array.isArray(o)?o:[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:Qy(t,e),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 originalOrigin(){const o=t&&(t.originalOrigin||t.localOrigin)||[0,0,0];return vi(o)},get visible(){const o=e&&e.targetEffect;return o?!!o.visible:t?t.visibleSelf!==void 0?!!t.visibleSelf:!!t.visible:!1},set visible(o){const c=e&&e.targetEffect;if(c){c.visible=!!o;return}t&&(t.visibleSelf=!!o,typeof e.recomputeVisibility=="function"?e.recomputeVisibility():t.visible=!!o)},get alpha(){return t&&typeof t.alpha=="number"?t.alpha:1},set alpha(o){t&&(t.alpha=Number(o)||0)},get perspective(){return!!(t&&t.perspective)},set perspective(o){t&&(t.perspective=!!o)},get brightness(){return t&&typeof t.brightness=="number"?t.brightness:1},set brightness(o){t&&(t.brightness=Number(o)||0)},get text(){return t&&t.text!==void 0?String(t.text):""},set text(o){t&&typeof o!="boolean"&&(t.text=o==null?"":String(o))},get pointsize(){return t&&t.textPointsize||24},set pointsize(o){t&&(t.textPointsize=Number(o)||24)},get font(){return t&&t.textFont||""},set font(o){t&&(t.textFont=String(o||""))},get alignment(){return t&&t.alignment||"center"},set alignment(o){if(!t)return;const c=String(o||"center").toLowerCase();t.alignment=c==="centre"?"center":c},...t&&t.puppet&&r?Wy(t,r):{getBoneCount:()=>0,getBoneTransform:()=>{const o={translation(c){return c===void 0?new Ue(0,0,0):o},rotation(){return o},scale(){return o}};return o},setBoneTransform:()=>{},applyBonePhysicsImpulse:()=>{}},getParent:()=>{if(!t||t.parentId==null)return null;const o=e&&typeof e.getSceneLayerById=="function"?e.getSceneLayerById(t.parentId):null;return!o||o.destroyed?null:ao(o,e)},getChildren:()=>{const o=t&&t.childIds||[];if(!o.length)return[];const c=e&&typeof e.getSceneLayerById=="function"?e.getSceneLayerById:null;if(!c)return[];const u=[];for(const l of o){const d=c(l);d&&!d.destroyed&&u.push(ao(d,e))}return u},getAnimation:o=>{const c=t&&t.animations,u=t&&t.animationList||[];if(o==null||o===""){if(typeof e.getAnimationForProperty=="function"){const l=e.getAnimationForProperty();if(l)return l}return u[0]||Ks()}return c&&c[o]?c[o]:typeof o=="number"&&u[o]?u[o]:typeof o=="string"&&/^\d+$/.test(o)&&u[Number(o)]?u[Number(o)]:Ks()},getAnimationLayer:o=>{const c=t&&t.animationLayers||[];let u=null;if(typeof o=="number"?u=c[o]||null:typeof o=="string"&&/^\d+$/.test(o)?u=c[Number(o)]||null:typeof o=="string"&&(u=c.find(f=>f&&f.name===o)||null),u)return{play:()=>u.play?.(),pause:()=>u.pause?.(),stop:()=>u.stop?.(),isPlaying:()=>u.playing!==!1&&!u.paused,get visible(){return u.visible!==!1},set visible(f){u.visible=!!f},get rate(){return u.rate??1},set rate(f){u.rate=Number(f)||1},get name(){return u.name||""}};const l=t&&t.animations,d=t&&t.animationList||[];return l&&l[o]?l[o]:typeof o=="number"&&d[o]?d[o]:typeof o=="string"&&/^\d+$/.test(o)&&d[Number(o)]?d[Number(o)]:Ks()},getAnimationLayerCount:()=>(t&&t.animationLayers||[]).length||(t&&t.animationList||[]).length,getTextureAnimation:()=>Hy(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 o=t&&t.soundCtl&&typeof t.soundCtl.isPlaying=="function"&&t.soundCtl.isPlaying(),c=t&&t.videoCtl&&typeof t.videoCtl.isPlaying=="function"&&t.videoCtl.isPlaying();return!!(o||c)},{valueOf(){const o=t&&t.soundCtl&&typeof t.soundCtl.isPlaying=="function"&&t.soundCtl.isPlaying(),c=t&&t.videoCtl&&typeof t.videoCtl.isPlaying=="function"&&t.videoCtl.isPlaying();return!!(o||c)},toString(){const o=t&&t.soundCtl&&typeof t.soundCtl.isPlaying=="function"&&t.soundCtl.isPlaying(),c=t&&t.videoCtl&&typeof t.videoCtl.isPlaying=="function"&&t.videoCtl.isPlaying();return String(!!(o||c))}}),get volume(){if(t&&t.soundCtl&&typeof t.soundCtl.getVolume=="function")return t.soundCtl.getVolume();const o=t&&t.soundprops&&t.soundprops.volume;return typeof o=="number"?o:1},set volume(o){const c=Number(o);if(!Number.isFinite(c)||!t)return;const u=Math.max(0,Math.min(1,c));t.soundprops&&(t.soundprops.volume=u),t.soundCtl&&typeof t.soundCtl.setVolume=="function"&&t.soundCtl.setVolume(u)},getVideoTexture:()=>Vy(t),getTransformMatrix:()=>{const o=t&&t.origin||[0,0,0],c=new Float32Array(16);return c[0]=1,c[5]=1,c[10]=1,c[15]=1,c[12]=o[0]||0,c[13]=o[1]||0,c[14]=o[2]||0,{m:c}},getEffect:o=>{const c=t&&t.effects||null;if(!c||c.length===0)return wl(null);if(typeof o=="number"||typeof o=="string"&&/^\d+$/.test(o))return wl(c[Number(o)]||null);const u=String(o);return wl(c.find(l=>l&&l.name===u)||null)},getMaterial(o){const c=t&&Array.isArray(t.effects)?t.effects:null;let u=null;if(c){const l=[];for(const f of c)for(const h of f.materialPasses||[])l.push(h);const d=l[Number(o)];d&&(d.constantshadervalues=d.constantshadervalues||{},u=d.constantshadervalues)}return u||(u=t&&t.__dummyMaterialBags?.[Number(o)]||null),u||(u={},t&&((t.__dummyMaterialBags||={})[Number(o)]=u)),u}};Object.defineProperty(s,"angles",{enumerable:!0,get(){return i.angles},set(o){if(t&&Array.isArray(t.angles)){const c=wh(o);Array.isArray(t.localAngles)&&(t.localAngles[0]=c[0],t.localAngles[1]=c[1],t.localAngles[2]=c[2]),t.parentId===void 0||t.parentId===null?(t.angles[0]=c[0],t.angles[1]=c[1],t.angles[2]=c[2]):e&&typeof e.markTransformDirty=="function"&&e.markTransformDirty(t)}}});const a={origin:"localOrigin",scale:"localScale"};for(const o of["origin","scale","size","color"])Object.defineProperty(s,o,{enumerable:!0,get(){const c=a[o],u=o==="scale"?[1,1,1]:[0,0,0],l=t&&c&&Array.isArray(t[c])?t[c]:t&&Array.isArray(t[o])?t[o]:null;return vi(l||u)},set(c){const u=xr(c);i[o].x=u[0],i[o].y=u[1],i[o].z=u[2];const l=a[o];if(t)if(l){Array.isArray(t[l])&&(t[l][0]=u[0],t[l][1]=u[1],t[l][2]=u[2]);const d=t.parentId===void 0||t.parentId===null;d&&Array.isArray(t[o])?(t[o][0]=u[0],t[o][1]=u[1],t[o][2]=u[2]):!d&&typeof e.markTransformDirty=="function"&&e.markTransformDirty(t)}else Array.isArray(t[o])&&o!=="size"&&(t[o][0]=u[0],t[o][1]=u[1],t[o][2]=u[2])}});return s}function $y(t,e,n={}){if(typeof t!="string"||t.length===0)return null;const r=hh(t),i={};if(e&&typeof e=="object")for(const[S,k]of Object.entries(e))ph(i,S,k,n.userProperties);const s=new Proxy(()=>s,{apply(){return s},get(S,k){if(k==="finish")return()=>i;if(typeof k=="string"&&nh.test(k))return _=>(_&&typeof _=="object"&&typeof _.name=="string"&&!(_.name in i)&&(i[_.name]=so(_.value)),s)}}),a={registerAsset:S=>S,frametime:1/60,runtime:0,canvasSize:gh(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||us,clearTimeout:n.clearTimeout||(()=>{}),setInterval:n.setInterval||us,clearInterval:n.clearInterval||(()=>{}),openUserShortcut:n.openUserShortcut||(()=>{}),isRunningInEditor:bl(n.isRunningInEditor),isScreensaver:!!n.isScreensaver};sh(a,n);const o=n.audioViews;a.registerAudioBuffers=S=>{const k=mh(S);let _=o?o.get(k):void 0;return _||(_={left:new Float32Array(k),right:new Float32Array(k),average:new Float32Array(k)},o&&o.set(k,_)),_};const c=n.shared||{},u={console:rh()},l=oh(n.inputView),d=n.layer||null,f=n.workshopId!=null?n.workshopId:qy(t),h=ao(d,n),p=Xy({...n,workshopId:f,getWorkshopId:()=>f});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,`+io.map(k=>`${k}: typeof ${k} === "function" ? ${k} : null,`).join("")+'animationEvent: typeof animationEvent === "function" ? animationEvent : null,resizeScreen: typeof resizeScreen === "function" ? resizeScreen : null,dummy_: 0};')(i,ih(a),ch,lh,uh,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,Ue,ah,l,h,p,h,n.storage||gl(),fh)}catch(S){return n.onError&&n.onError(S,"parse"),null}const g=!!(m&&(m.cursorClick||m.cursorEnter||m.cursorLeave||m.cursorDown||m.cursorUp||m.cursorMove)),y=!!(m&&io.some(S=>m[S])),w=!!(m&&typeof m.applyUserProperties=="function"),A=/\bengine\s*\.\s*(runtime|frametime)\b/.test(r),b=!!(m&&typeof m.animationEvent=="function"),v=!!(m&&typeof m.resizeScreen=="function"),x=!!(m&&typeof m.init=="function");if(!m||!m.update&&!g&&!y&&!w&&!A&&!b&&!v&&!x)return null;const P={engine:a,scriptProperties:i,hasUpdate:!!m.update,hasCursorHook:g,hasApplyHook:w,errCount:0,disabled:!1,init(S){if(m.init)try{return m.init(yl(S))}catch(k){P.errCount++,n.onError&&n.onError(k,"init")}},applyUserProperties(S){if(m.applyUserProperties)try{m.applyUserProperties(S||{})}catch(k){P.errCount++,n.onError&&n.onError(k,"applyUserProperties")}},callUpdate(S){if(P.disabled||!m.update)return;let k;try{k=m.update(yl(S))}catch(_){P.errCount++,n.onError&&n.onError(_,"update"),P.errCount>=3&&(P.disabled=!0);return}return k},hasCursorHook:g,callCursor(S,k){if(P.disabled)return;const _=m[S];if(typeof _=="function")try{return _(k)}catch(I){P.errCount++,n.onError&&n.onError(I,S),P.errCount>=3&&(P.disabled=!0);return}},hasMediaHook:y,callMedia(S,k){if(P.disabled)return;const _=m[S];if(typeof _=="function")try{return _(k)}catch(I){P.errCount++,n.onError&&n.onError(I,S),P.errCount>=3&&(P.disabled=!0);return}},hasMediaHook:y,hasAnimEventHook:b,callAnimationEvent(S,k){if(!P.disabled&&typeof m.animationEvent=="function")try{return m.animationEvent(S,yl(k))}catch(_){P.errCount++,n.onError&&n.onError(_,"animationEvent"),P.errCount>=3&&(P.disabled=!0);return}},hasResizeHook:v,callResize(S,k){if(P.disabled||typeof m.resizeScreen!="function")return;const _=Number(S)||0,I=Number(k)||0;a.screenResolution={x:_,y:I};const B={x:_,y:I,width:_,height:I};try{return m.resizeScreen(B)}catch(V){P.errCount++,n.onError&&n.onError(V,"resizeScreen"),P.errCount>=3&&(P.disabled=!0);return}}};return P}function vi(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=xr(i);return n.x+=s[0],n.y+=s[1],n.z+=s[2],r},subtract(i){const s=xr(i);return vi([n.x-s[0],n.y-s[1],n.z-s[2]])},divide(i){const s=xr(i),a=(o,c)=>c===0?0:o/c;return vi([a(n.x,s[0]),a(n.y,s[1]),a(n.z,s[2])])},multiply(i){if(i&&typeof i=="object"){const s=xr(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 Ue(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 xr(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 oo=Math.PI/180,co=180/Math.PI;function Gy(t){const e=Array.isArray(t)?t:[0,0,0];return{x:(e[0]||0)*co,y:(e[1]||0)*co,z:(e[2]||0)*co}}function wh(t){const e=xr(t);return[e[0]*oo,e[1]*oo,e[2]*oo]}function Qy(t,e){const n={x:0,y:1,z:2},r=(s,a)=>{if(!t||!Array.isArray(t.angles))return;Array.isArray(t.localAngles)&&(t.localAngles[s]=a),t.parentId===void 0||t.parentId===null?t.angles[s]=a:e&&typeof e.markTransformDirty=="function"&&e.markTransformDirty(t)},i={add(s){const a=xr(s);return i.x+=a[0],i.y+=a[1],i.z+=a[2],i},subtract(s){const a=xr(s);return i.x-=a[0],i.y-=a[1],i.z-=a[2],i},multiply(s){return i.x*=s,i.y*=s,i.z*=s,i},toArray(){return[i.x,i.y,i.z]}};for(const s of["x","y","z"])Object.defineProperty(i,s,{enumerable:!0,get(){const a=t&&Array.isArray(t.localAngles)?t.localAngles:t&&Array.isArray(t.angles)?t.angles:null;return a?(a[n[s]]||0)*co:0},set(a){r(n[s],(Number(a)||0)*oo)}});return i}function Yy(t,e){return Math.min(256,Math.ceil(Math.max(1,Number(t)||1)*2+8))}function Ky(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 Zy=Object.freeze(Object.defineProperty({__proto__:null,LOCATION_GLOBAL:pl,LOCATION_SCREEN:Xr,Vec3:Ue,createInputView:Dy,drawTextLayer:By,effectiveTextPadding:My,evalObjectScript:$y,evalTextScript:zy,foldVisibleReturn:Oy,inkOverflow:th,layoutText:Cy,makeCursorEventVec:Fy,makeSandboxStorage:gl,radToScriptAngles:Gy,resolveWorkshopAssetPath:bh,rewriteComboStringEq:dh,scriptAnglesToRad:wh,shouldGrowMediaPlaceholder:Ry,textCanvasMargin:Yy,textCanvasMarginGrow:Iy,textLayerHasTintMask:Ky},Symbol.toStringTag,{value:"Module"}));function vh(t){if(t instanceof Ue)return t;if(Array.isArray(t))return new Ue(Number(t[0])||0,Number(t[1])||0,Number(t[2])||0);const e=String(t??"").trim().split(/\s+/).map(Number);return new Ue(e[0]||0,e[1]||0,e[2]||0)}function Ah(t,e){if(!t||typeof e!="string")return null;const n=t[e];return n&&typeof n=="object"?n:null}function vl(t){return typeof t=="string"?t:t&&typeof t=="object"&&typeof t.name=="string"?t.name:null}function Jy(t,e){return lo(t)&&lo(e)?Number(t)===Number(e):String(t)===String(e)}function Al(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 eb(t){switch(t.type){case"bool":return"bool";case"slider":return"num";case"color":return"num";case"textinput":return"text";default:return Al(t.value)}}function xh(t,e){if(t===null||typeof t!="object")return t;if(t.user&&typeof t.user=="object"&&typeof t.user.name=="string"){const r=Ah(e,t.user.name);if(!r||r.value===void 0||r.value===null)return t.value;const i=r.type==="combo"?xl(r.value,r.options):r.value;return Jy(i,t.user.condition)}if(typeof t.user!="string")return t;const n=Ah(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(Al(t.value)==="bool"&&n.type==="slider"){const r=Number(n.value);return Number.isFinite(r)?r!==0:t.value}return Al(t.value)===eb(n)?n.value:t.value}function Ai(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]=Ai(t[r],e,n+1);return t}if(vl(t.user)){let r=xh(t,e);for(let i=0;i<8&&r!==null&&typeof r=="object"&&vl(r.user);i++)r=xh(r,e);return t.value=Ai(r,e,n+1),t}for(const r of Object.keys(t))t[r]=Ai(t[r],e,n+1);return t}function tb(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 lo(t){return typeof t=="number"?Number.isInteger(t):typeof t=="string"&&/^-?\d+$/.test(t.trim())}function xl(t,e){const n=tb(e);return!(n.length>0?n.every(lo):lo(t))||typeof t=="number"&&Number.isFinite(t)?t:typeof t=="string"&&/^-?\d+$/.test(t.trim())?Number(t):t}function nb(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"?xl(r.value,r.options):r.type==="color"?vh(r.value):r.value);return e}function Qn(t){return t&&typeof t=="object"?vl(t.user):null}function rb(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"?xl(u.value,u.options):u.value,d=u.type==="color"?vh(l):l;s[a]=d,r[a]=d}else s[a]=c,r[a]=c}return r}function fs(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 ds(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 uo(t){return t==null?[1,1,1]:typeof t=="string"?fs(t):typeof t=="object"&&t!==null?fs(t.value):[1,1,1]}function fn(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 vn(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 kh(t){return t?!t.image&&!t.model&&!t.particle&&t.text==null&&!t.size:!1}function kl(t,e,n){const r=n?t.scale:[1,1,1],i=t.angles[2]||0,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 ib(t,e){const n=e&&e.general&&e.general.properties||{},r=t.objects||[];Ai(r,n,0),Ai(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:fs(g.origin||"0 0 0"),scale:fs(g.scale||"1 1 1"),angles:fs(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 y=!1;for(const w of s){if(w.parent===void 0||w.parent===null||!i.get(w.parent))continue;const b=s.findIndex(P=>P.id===w.parent);if(b<0)continue;const v=s[b];if(v.parent!==void 0&&v.parent!==null)continue;const x=kl(v,w,!0);w.origin=x.origin,w.scale=x.scale,w.angles=x.angles,w.parent=null,y=!0}if(!y)break}const o=r.map(g=>fn(g.visible,!0)),c=new Map;r.forEach((g,y)=>{g.id!==void 0&&c.set(g.id,y)});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 y=g.id!==void 0?g.id:null;if(y!==null){const w=l.get(g.parent);w?w.push(y):l.set(g.parent,[y])}}const d=r.map(()=>!0);for(let g=0;g<r.length;g++){let y=o[g],w=r[g].parent;for(let A=0;y&&w!==void 0&&w!==null&&A<64;A++){const b=c.get(w);if(b===void 0)break;o[b]||(y=!1),w=r[b].parent}d[g]=y}const f=r.map((g,y)=>{const w=s[y],A=typeof g.image=="string"&&(g.image.indexOf("models/util/projectlayer")===0||g.image.indexOf("models/util/fullscreenlayer")===0);let b=ds(g.size||"0 0"),v=w.origin;if(A){const x=(t.general||{}).orthogonalprojection,P=x&&Number(x.width),S=x&&Number(x.height);P>0&&S>0&&(b=[P,S],v=[P/2,S/2,w.origin[2]||0])}return{id:g.id!==void 0?g.id:y,name:g.name||"",visible:d[y],visibleSelf:o[y],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 x=g.instanceoverride;if(!x||typeof x!="object")return null;const P={};for(const[S,k]of Object.entries(x))k&&typeof k=="object"&&k.animation&&typeof k.animation=="object"&&k.animation.options&&(P[S]={animation:k.animation,value:k.value});return Object.keys(P).length?P:null})(),particleOverrideScripts:(()=>{const x=g.instanceoverride;if(!x||typeof x!="object")return null;const P={};for(const[S,k]of Object.entries(x))k&&typeof k=="object"&&typeof k.script=="string"&&k.script&&(P[S]={script:k.script,scriptproperties:k.scriptproperties||null,value:k.value});return Object.keys(P).length?P:null})(),sound:Array.isArray(g.sound)?g.sound.filter(x=>typeof x=="string"):[],soundprops:{volume:vn(g.volume,1),playbackmode:g.playbackmode||"single",startsilent:fn(g.startsilent,!1),maxtime:vn(g.maxtime,0),mintime:vn(g.mintime,0),spatialization:fn(g.spatialization,!1),muteineditor:fn(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:vn(g.pointsize,24)||24,textColor:uo(g.color),textAnchor:typeof g.anchor=="string"&&g.anchor!=="none"?g.anchor:"center",textMaxwidth:vn(g.maxwidth,0),textMaxrows:vn(g.maxrows,0),textLimitwidth:fn(g.limitwidth,!1),textLimitrows:fn(g.limitrows,!1),textLimituseellipsis:fn(g.limituseellipsis,!1),textHAlign:g.horizontalalign||"center",textVAlign:g.verticalalign||"center",textSpacing:g.spacing?ds(g.spacing):[0,0],textPadding:(()=>{const x=g.padding;if(typeof x=="number")return x;const P=String(x??"").trim().split(/\s+/).map(Number).filter(S=>Number.isFinite(S));return P.length?P.reduce((S,k)=>S+k,0)/P.length:0})(),textOpaquebackground:fn(g.opaquebackground,!1),textBackgroundcolor:uo(g.backgroundcolor),textBackgroundbrightness:vn(g.backgroundbrightness,1),textCastshadow:fn(g.castshadow,!1),isSound:!!(g.sound&&g.sound.length),isComponent:!!g.component,objectScripts:(()=>{const x={};for(const P of["scale","origin","color","alpha","brightness","angles","visible","maxwidth","pointsize","volume","intensity","exponent"]){const S=g[P];S&&typeof S=="object"&&typeof S.script=="string"&&S.script&&(x[P]={script:S.script,scriptproperties:S.scriptproperties||null,value:S.value})}return Object.keys(x).length?x:null})(),objectAnimations:(()=>{const x={};for(const P of["scale","origin","color","alpha","brightness","angles","visible","volume","maxwidth","zoom"]){const S=g[P];S&&typeof S=="object"&&S.animation&&typeof S.animation=="object"&&S.animation.options&&(x[P]={animation:S.animation,value:S.value})}return Object.keys(x).length?x:null})(),animationLayers:(g.animationlayers||[]).filter(x=>x&&typeof x.animation=="number").map(x=>({animation:x.animation,name:typeof x.name=="string"?x.name:"",visibleScript:x.visible&&typeof x.visible=="object"&&typeof x.visible.script=="string"&&x.visible.script?{script:x.visible.script,scriptproperties:x.visible.scriptproperties||null,value:x.visible.value}:null,visible:fn(x.visible,!0),additive:fn(x.additive,!1),blend:vn(x.blend,1),rate:vn(x.rate,1),playing:!0,paused:!1,play(){this.playing=!0,this.paused=!1},pause(){this.paused=!0},stop(){this.playing=!1,this.paused=!1}})),solid:(()=>{if(typeof g.particle=="string")return!1;const x=typeof g.image=="string"?g.image:"";return x.indexOf("models/util/composelayer")===0?!1:x.indexOf("models/util/solidlayer")===0?!0:g.solid?!x||x.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:y)||0)>0,childIds:l.get(g.id!==void 0?g.id:y)||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:A,origin:v,scale:w.scale,angles:w.angles,localOrigin:a[y].origin,localScale:a[y].scale,localAngles:a[y].angles,originalOrigin:a[y].origin.slice(),renderInert:kh(g),scaleRuntimeBound:g.scale!==null&&typeof g.scale=="object"&&(typeof g.scale.script=="string"||g.scale.user!==void 0),size:b,alignment:g.alignment||"center",color:uo(g.color),alpha:vn(g.alpha,1),brightness:vn(g.brightness,1),copybackground:!!g.copybackground,colorBlendMode:g.colorBlendMode||0,perspective:g.perspective===!0?!0:void 0,parallaxDepth:g.parallaxDepth!==void 0?ds(g.parallaxDepth):null,parallaxDepthOwn:g.parallaxDepth!==void 0?ds(g.parallaxDepth):null,disablePropagation:g.disablepropagation===!0,effects:(g.effects||[]).map(x=>({file:x.file||"",name:typeof x.name=="string"?x.name:"",visible:fn(x.visible,!0),visibleScript:x.visible&&typeof x.visible=="object"&&typeof x.visible.script=="string"&&x.visible.script?{script:x.visible.script,scriptproperties:x.visible.scriptproperties||null,value:!!x.visible.value}:null,passes:(x.passes||[]).map(P=>{const S=P.textures||[],k=P.usertextures;let _=S,I=null;if(Array.isArray(k))for(let B=0;B<k.length;B++){const V=k[B],O=V&&typeof V=="object"&&typeof V.name=="string"?V.name:typeof V=="string"?V:null;O&&(_===S&&(_=S.slice()),S[B]!==void 0&&S[B]!==null&&S[B]!==O&&(I||(I=[]),I[B]=S[B]),_[B]=O)}return{combos:P.combos||{},constantshadervalues:P.constantshadervalues||{},textures:_,textureFallbacks:I}})}))}}),h=t.general||{},p=(()=>{const g={};for(const[y,w]of Object.entries(h))w&&typeof w=="object"&&typeof w.script=="string"&&w.script&&(g[y]={script:w.script,scriptproperties:w.scriptproperties||null,value:w.value});return Object.keys(g).length?g:null})(),m=(()=>{const g={};for(const[y,w]of Object.entries(h))w&&typeof w=="object"&&w.animation&&typeof w.animation=="object"&&w.animation.options&&(g[y]={animation:w.animation,value:w.value});return Object.keys(g).length?g:null})();{const g=new Map;for(const y of f)y.id!==void 0&&g.set(y.id,y);for(let y=0;y<8;y++){let w=!1;for(const A of f){if(A.parallaxDepth||A.parentId==null)continue;const b=g.get(A.parentId);!b||!b.parallaxDepth||b.image||b.particle||b.model||(A.parallaxDepth=b.parallaxDepth.slice(),w=!0)}if(!w)break}}{const g=new Map;for(const y of f)y.id!==void 0&&g.set(y.id,y);for(const y of f){let w=y;for(let b=y.parentId!=null?g.get(y.parentId):null;b&&b.disablePropagation!==!0;b=b.parentId!=null?g.get(b.parentId):null)w=b;y.parallaxNodeId=w===y?null:w.id,y.parallaxAnchor=[w.origin?w.origin[0]:0,w.origin?w.origin[1]:0];const A=w.parallaxDepthOwn;y.parallaxDepthProp=A?A.slice():[0,0]}}return{camera:t.camera||null,general:h,generalScripts:p,generalAnimations:m,layers:f,properties:n}}function sb(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 ab(t,e){!t||!e||typeof e!="object"||t.isContainer||e.solidlayer===!0&&(t.solid=!0)}function ob(t){return!t||typeof t.material!="string"?null:{materialPath:t.material,autosize:!!t.autosize,cropoffset:t.cropoffset?ds(t.cropoffset):null}}function cb(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;a?o=kl({origin:a.origin,scale:a.scale,angles:a.angles},{origin:s.localOrigin,scale:s.localScale,angles:s.localAngles},!0):o={origin:s.localOrigin.slice(),scale:s.localScale.slice(),angles:s.localAngles.slice()};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])}if(n.size)for(const s of t){if(s.parallaxNodeId==null||e&&!e.has(s.parallaxNodeId))continue;const a=n.get(s.parallaxNodeId);a&&s.parallaxAnchor&&(s.parallaxAnchor[0]=a.origin[0],s.parallaxAnchor[1]=a.origin[1])}}function lb(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(d=>c&&c[d]||u&&u[d])&&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 ub=Object.freeze(Object.defineProperty({__proto__:null,applySolidFromModel:ab,collectTransformDirty:lb,composeChildTransform:kl,isRenderInert:kh,parseBool:fn,parseColor:uo,parseNum:vn,parseScene:ib,parseVec2:ds,parseVec3:fs,recomposeWorld:cb,recomputeLayerVisibility:sb,resolveMaterial:ob},Symbol.toStringTag,{value:"Module"}));function fb(t,e,n){const r=dl(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=dl(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 db={"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 Th(t){if(!t||typeof t!="string")return!0;const e=t.toLowerCase();return e==="generic"||e==="sprite"||e==="flat"||e.startsWith("genericimage")}function hb(t,e){return!t||!e||!e.shader||Th(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 mb={"materials/util/solidlayer.json":{passes:[{shader:"flat",blending:"translucent",cullmode:"nocull",depthtest:"disabled",depthwrite:"disabled",textures:[],combos:{}}]}},pb=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_MATERIALS:mb,BUILTIN_MODELS:db,attachLayerMaterialEffect:hb,isBuiltinAlbedoShader:Th,resolveEffectChain:fb},Symbol.toStringTag,{value:"Module"}));function gb(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 yb(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 d=t.slice(c+1,l),f=kr(d);let h=n.body;n.args.forEach((p,m)=>{const g=f[m]!==void 0?f[m].trim():"";h=Zs(h,p,g)}),r>0&&(h=Sh(h,r-1)),i.push("("+h+")"),s=l+1}return i.join("")}function Zs(t,e,n){return t.replace(new RegExp("\\b"+e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b","g"),n)}function kr(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 Sh(t,e){for(let n=0;n<12;n++){const{defs:r,fns:i}=gb(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 d=l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f=new RegExp("^\\s*(?:const\\s+|uniform\\s+|varying\\s+|in\\s+|out\\s+|attribute\\s+)*"+u+"\\s+"+d+"\\s*[=;]");for(let h=0;h<s.length;h++)if(f.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 d=l;for(const[f,h]of r){const p=a.get(f);if(p!==void 0&&u<p||o.get(f)===u)continue;new RegExp("\\b"+f.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b").test(d)&&(d=Zs(d,f,h),c=!0)}for(const[f,h]of i){const p=a.get(f);p!==void 0&&u<p||d.includes(f)&&(d=yb(d,f,h,e),c=!0)}s[u]=d}if(t=s.join(`
|
|
9
|
+
`),!c)break}return t}function Ph(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=d();for(a();/^[<>]/.test(i[s]||"");){let p=i[s];i[s+1]==="="&&(p+="=",s++),s++;const m=d();p==="<"?h=h<m:p===">"?h=h>m:p==="<="?h=h<=m:h=h>=m,a()}return h}function d(){return a(),i[s]==="!"?(s++,!d()):f()}function f(){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 _h(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 Eh(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(Js(a)){const d=/^#include[ \t]+"([^"]+)"|^#include[ \t]+<([^>]+)>/.exec(l),f=d&&(d[1]||d[2]),h=f&&n?n(f):null;h!=null?s.push(Eh(_h(h),e,n)):s.push("// [include \u7F3A\u5931: "+f+"]")}continue}if(l.startsWith("#define")){if(Js(a)){s.push(u);const d=/^#define[ \t]+([A-Za-z_][A-Za-z0-9_]*)(?:\([^)]*\))?[ \t]*(.*)$/.exec(l);d&&o.set(d[1],d[2].trim())}continue}if(l.startsWith("#undef")){Js(a)&&s.push(u);continue}if(l.startsWith("#ifdef")||l.startsWith("#ifndef")||l.startsWith("#if")){const d=Js(a);let f=!1;if(l.startsWith("#ifdef")){const h=l.slice(6).trim().split(/\s+/)[0];f=e[h]!==void 0||o.has(h)}else if(l.startsWith("#ifndef")){const h=l.slice(7).trim().split(/\s+/)[0];f=!(e[h]!==void 0||o.has(h))}else try{f=!!Ph(l.slice(3).trim(),e,o)}catch{f=!1}a.push({parent:d,hit:f,done:f});continue}if(l.startsWith("#else")){if(a.length>0){const d=a[a.length-1];d.hit=!d.done,d.done=!0}continue}if(l.startsWith("#elif")){if(a.length>0){const d=a[a.length-1];if(d.done)d.hit=!1;else{let f=!1;try{f=!!Ph(l.slice(5).trim(),e,o)}catch{f=!1}d.hit=f,d.done=f}}continue}if(l.startsWith("#endif")){a.length>0&&a.pop();continue}l.startsWith("#")||Js(a)&&s.push(u)}return s.join(`
|
|
14
|
+
`)}function Js(t){return t.every(e=>e.parent&&e.hit)}function fo(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 Mh(t,e){return fo(t,e,"(",")")}const bb=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 wb(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 bb.has(i)}function Ch(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 vb(t){let e=0;for(let n=0;n<t.length;n++){const r=t[n];if(r==="("||r==="["){e++;continue}if(r===")"||r==="]"){e--;continue}if(e===0){if(r==="?"||r==="#")return!1;if((r==="&"||r==="|")&&t[n+1]===r)return!0;if(r==="<"||r===">"){if(t[n+1]===r){n++;continue}return!0}if(r==="="&&t[n+1]==="="||r==="!"&&t[n+1]==="=")return!0}}return!1}function Ab(t,e){const n=a=>{if(/[{}]/.test(a))return a;const o=/^(\s*)([A-Za-z_]\w*(?:\.\s*[A-Za-z_]\w*)*)\s*([-+*/]=)([\s\S]+)$/.exec(a);if(!o)return a;const[,c,u,l,d]=o,f=d.trim();return!f||e.has(u.split(".")[0])||!vb(f)?a:c+u+" "+l+" float("+f+")"};let r="",i=0,s=0;for(let a=0;a<t.length;a++){const o=t[a];o==="("||o==="["?s++:o===")"||o==="]"?s--:o===";"&&s===0&&(r+=n(t.slice(i,a))+";",i=a+1)}return r+n(t.slice(i))}function Ft(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(wb(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=Mh(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 Ih(t,e,n,r,i){const s=t;t=_h(t);const a={},o=/\[COMBO\][^\n]*?"combo"\s*:\s*"([^"]+)"[^\n]*?"default"\s*:\s*(-?\d+)/g;let c;if(typeof i=="string"&&i){const w=new RegExp(o.source,"g");let A;for(;(A=w.exec(i))!==null;)a[A[1]]=Number(A[2])}for(;(c=o.exec(s))!==null;)a[c[1]]=Number(c[2]);const u={GLSL:1,...a,...n||{}};{const w=["mod","mix","clamp","min","max","step","smoothstep","fract","abs","floor","ceil","sign","pow","exp","exp2","log","log2","sqrt","inversesqrt","sin","cos","tan","asin","acos","atan","sinh","cosh","tanh","dot","cross","normalize","length","distance","reflect","refract","round","trunc","modf","degrees","radians"],A="(?:void|float|int|uint|bool|half|double|vec[234]|ivec[234]|bvec[234]|mat[234]|mat[234]x[234])";for(const b of w){if(!new RegExp("(^|[;}\\n])[ \\t]*(?:(?:static|const|inline)[ \\t]+)*"+A+"[ \\t]+"+b+"[ \\t]*\\(","m").test(t))continue;const x="we_fn_"+b;new RegExp("\\b"+x+"\\b").test(t)||(t=t.replace(new RegExp("\\b"+b+"\\b(?=\\s*\\()","g"),x))}}let l=Eh(t,u,r);l=l.replace(/(#define\s+bufferRes\s+)(\d+)/g,(A,b,v)=>b+Math.min(Number(v),24)),l=l.replace(/(\b(?:varying|out|in)\s+vec4\s+audioValue\s*\[\s*)(\d+)(\s*\])/g,(A,b,v,x)=>b+Math.min(Number(v),24)+x),l=Sh(l,20),l=l.replace(/^[ \t]*#define[^\n]*\n?/gm,"");{const w=new Set,A=/\[COMBO\][^\n]*"combo"\s*:\s*"([^"]+)"/g;let b;for(;(b=A.exec(s))!==null;)w.add(b[1]);for(const v of Object.keys(u))w.add(v);w.delete("GLSL");for(const v of w){const x=u[v]!==void 0?u[v]:0;l=Zs(l,v,String(x))}}l=Zs(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=Ft(l,"saturate",w=>"clamp("+w+", 0.0, 1.0)"),l=Ft(l,"CAST4",w=>"vec4("+w+")"),l=Ft(l,"CAST3",w=>"vec3("+w+")"),l=Ft(l,"CAST2",w=>"vec2("+w+")"),l=l.replace(/\b(max|min)\(\s*(-?\d+(?:\.\d+)?)\s*,\s*([A-Za-z_]\w*\.(rgb|xyz|rg|xy|r|x))\s*\)/g,(w,A,b,v,x)=>{const P=x.length;return A+"(vec"+P+"("+b+"), "+v+")"}),l=l.replace(/(\.([xyzwrgba]{2,4})\s*=\s*)(max|min)\(\s*(-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\s*,\s*([^;]+?)\s*\)\s*;/g,(w,A,b,v,x,P)=>/\.[xyzwrgba]{2,4}\b|\bvec[234]\s*\(/.test(P)?`${A}${v}(vec${b.length}(${x}), ${P});`:w),l=l.replace(/(^|[^\w)\]])([+-])([+-])(?=[\d.])/g,(w,A,b,v)=>A+(b===v?"+":"-"));const d=[];l=l.replace(/\b\d+(?:\.\d+)?[eE][+-]?\d+\b/g,w=>(d.push(w),""+"".repeat(d.length)+""));const f=[];l=l.replace(/\bfor\s*\(\s*int\s+([A-Za-z_]\w*)([^)]*)\)/g,(w,A,b)=>(f.push(b+")"),`for (int ${A}${"".repeat(f.length)}`));for(let w=0;w<8;w++){const A=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,(b,v,x,P,S,k,_)=>{let I=0,B=k+b.length-1;for(;B<_.length;B++){const O=_[B];if(O==="(")I++;else if(O===")"){if(I--,I===0){B++;break}}else if(I===0&&(O===";"||O===","||O===`
|
|
15
|
+
`))break}for(;B<_.length;B++){const O=_[B];if(O===";"||O===","||O===`
|
|
16
|
+
`||O===")")break}const V=_.slice(k,B);return/\d\.\d/.test(V)?`${v}${x}.0 ${P} ${S}`:b});{const b=new Set,v=/\b(?:uniform\s+)?(?:highp|mediump|lowp\s+)?(?:float|vec2|vec3|vec4|mat2|mat3|mat4)\s+([A-Za-z_][A-Za-z0-9_]*)/g;let x;for(;(x=v.exec(l))!==null;)b.add(x[1]);if(b.size>0){const P=Array.from(b).sort((S,k)=>k.length-S.length).join("|");l=l.replace(new RegExp("(^|[^\\w.])(\\d+)\\s*([+-])\\s*("+P+")(?![A-Za-z0-9_])","g"),"$1$2.0 $3 $4"),l=l.replace(new RegExp("\\b("+P+")\\s*([+-])\\s*(\\d+)(?![\\d.])","g"),"$1 $2 $3.0")}}if(l===A)break}{const w=["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"],A=/\b(ApplyBlending|ApplyComposite|BlendTransparency)\s*\(/;for(const b of w)l=Ft(l,b,v=>{const P=kr(v).map(S=>{if(A.test(S))return S;const k=[];let _=S.replace(/\[[^\]]*\]/g,I=>(k.push(I),"\0"+(k.length-1)+"\0")).replace(/\b(?:ivec[234]|uvec[234]|int|uint)\s*\([^()]*\)/g,I=>(k.push(I),"\0"+(k.length-1)+"\0"));return _=_.replace(/(?<![A-Za-z0-9_.\u0000])(\d+)(?![.\d])(?![A-Za-z_])/g,"$1.0"),_.replace(/\u0000(\d+)\u0000/g,(I,B)=>k[Number(B)])});return b+"("+P.join(",")+")"});l=Ft(l,"pow",b=>{const v=kr(b);if(v.length!==2)return"pow("+b+")";const x=v[0].trim(),P=v[1].trim(),S=/\.(xyzw|rgba|xyz|rgb|xy|rg|zw)\s*$/.exec(x),_=S?{xyzw:4,rgba:4,xyz:3,rgb:3,xy:2,rg:2,zw:2}[S[1]]:0,I=/\bvec[234]\s*\(/.test(P)||/\.(xyzw|rgba|xyz|rgb|xy|rg|zw)\b/.test(P);return _>=2&&!I?"pow("+x+", vec"+_+"("+P+"))":"pow("+x+", "+P+")"})}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 w=new Set,A=/\b(?:vec[234])\s+([A-Za-z_][A-Za-z0-9_]*)/g;let b;for(;(b=A.exec(l))!==null;)w.add(b[1]);if(w.size>0){const v=Array.from(w).sort((x,P)=>P.length-x.length).join("|");l=l.replace(new RegExp("\\b("+v+")\\s*([+-])\\s*(\\d+)(?![\\d.])","g"),"$1 $2 $3.0")}}{const w=new Set,A=/\b(?:int|uint)\s+([A-Za-z_][A-Za-z0-9_]*)/g;let b;for(;(b=A.exec(l))!==null;)w.add(b[1]);l=l.replace(/\buint\b/g,"int"),l=l.replace(/\b([A-Za-z_][A-Za-z0-9_]*)\s*%\s*(\d+)(?![\d.])/g,(v,x,P)=>w.has(x)?v:"mod("+x+", "+P+".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,(w,A,b,v)=>{const x=v.trim();return/^(vec[234]|mat[234]|int\b|float\b)/.test(x)?w:A+" "+b+" = "+A+"("+x+");"});for(const w of["mix","clamp","step","smoothstep","min","max","mod","pow"])l=Ft(l,w,A=>w+"("+A.replace(/(?<![A-Za-z0-9_.])(\d+)(?![.\d])/g,"$1.0")+")");l=Ft(l,"clamp",w=>{const A=kr(w);if(A.length!==3)return"clamp("+w+")";const b=A[0].trim(),v=A[1].trim(),x=P=>/^-?\d+\.?\d*$/.test(P);return x(b)&&x(v)&&Number(b)===0&&Number(v)===1?"clamp("+A[2].trim()+", "+b+", "+v+")":"clamp("+w+")"}),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=Ft(l,"smoothstep",w=>{const A=kr(w);return A.length===3&&A[1].trim()==="0.0"&&A[0].trim()!=="0.0"?"(1.0 - smoothstep(0.0, "+A[0].trim()+", "+A[2].trim()+"))":"smoothstep("+w+")"});{const w=new Map,A=/\b(?:uniform|varying|attribute|in|out)?\s*\b(vec([234]))\s+([A-Za-z_]\w*)/g;let b;for(;(b=A.exec(l))!==null;)w.set(b[3],Number(b[2]));if(w.size>0){const v={2:"xy",3:"xyz",4:"xyzw"};l=l.replace(/(^|[;{}\n]\s*)([A-Za-z_]\w*)\s*=\s*([A-Za-z_]\w*)\s*;/g,(x,P,S,k)=>{const _=w.get(S),I=w.get(k);return!_||!I||_>=I?x:P+S+" = "+k+"."+v[_]+";"}),l=l.replace(/(^|[;{}\n]\s*)([A-Za-z_]\w*)\s*(\*=|\/=|\+=|-=)\s*([^;\n]+);/g,(x,P,S,k,_)=>{const I=w.get(S);if(!I)return x;const B=/^\s*(-?\s*(?:\d+(?:\.\d+)?f?|([A-Za-z_]\w*))\s*(?:[*/+\-]\s*(-?\s*(?:\d+(?:\.\d+)?f?|[A-Za-z_]\w*))\s*)?)$/.exec(_);if(!B)return x;const V=[B[2],B[3]].filter(Boolean);let O=null,U=0;for(const ie of V){const we=w.get(ie);if(we){O=ie,U=we;break}}if(!O||U<=I)return x;const W=v[I];return P+S+" "+k+" "+_.replace(O,O+"."+W)+";"})}{const v=new Set;{const S=/\b(?:uniform|varying|attribute|in|out|const)?\s*\bfloat\s+([A-Za-z_]\w*)/g;let k;for(;(k=S.exec(l))!==null;)v.add(k[1])}const x=S=>{const k=S.trim();{const B=/^vec([234])\s*\(/.exec(k);if(B){let V=0;for(let O=k.indexOf("(");O<k.length;O++)if(k[O]==="(")V++;else if(k[O]===")"&&(V--,V===0))return O===k.length-1?Number(B[1]):0;return 0}}if(/^texture(?:Lod)?\s*\(/.test(k)){let B=0;for(let V=k.indexOf("(");V<k.length;V++)if(k[V]==="(")B++;else if(k[V]===")"&&(B--,B===0))return V===k.length-1?4:0;return 0}const _=/^([A-Za-z_]\w*)(?:\.([xyzwrgba]{2,4}))?\s*[*/]\s*([^*/]+)$/.exec(k);if(!_)return 0;const I=_[3];return/\bvec[234]\s*\(|\.[xyzwrgba]{2,4}\b/.test(I)?0:_[2]?_[2].length:v.has(_[1])?0:w.get(_[1])||0};l=l.replace(/(^|[;{}\n]\s*)float\s+([A-Za-z_]\w*)\s*=\s*([^;]+);/g,(S,k,_,I)=>x(I)<2?S:`${k}float ${_} = (${I.trim()}).x;`);const P={2:"xy",3:"xyz"};l=l.replace(/(^|[;{}\n]\s*)vec([23])\s+([A-Za-z_]\w*)\s*=\s*([^;]+);/g,(S,k,_,I,B)=>{const V=Number(_);return x(B)<=V?S:`${k}vec${_} ${I} = (${B.trim()}).${P[V]};`})}if(w.size>0){const v=new Set,x=/\b(?:uniform|varying|attribute|in|out)?\s*\bfloat\s+([A-Za-z_]\w*)/g;let P;for(;(P=x.exec(l))!==null;)v.add(P[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",k=/^(?:length|distance|dot)$/,_=B=>{const V=B.match(new RegExp("^(?:"+S+")\\s*\\("));if(!V)return!1;let O=0;const U=V[0].length-1;let W=-1;for(let Y=U;Y<B.length;Y++)if(B[Y]==="(")O++;else if(B[Y]===")"&&(O--,O===0)){W=Y;break}if(W!==B.length-1)return!1;const ie=V[0].replace(/\s*\($/,"");if(k.test(ie))return!0;const we=B.slice(U+1,W);if(/\bvec[234]\s*\(/.test(we)||/\.[xyzwrgba]{2,4}\b/.test(we))return!1;for(const Y of w.keys()){const oe=Y.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");if(new RegExp("(?<!\\.)\\b"+oe+"\\b(?!\\s*\\.[xyzwrgba]\\b)").test(we))return!1}return!0},I=new Set;if(l=l.replace(/(^|[;{}\n]\s*)([A-Za-z_]\w*)\s*=\s*([^;]+);/g,(B,V,O,U)=>{const W=w.get(O);if(!W||v.has(O))return B;const ie=U.trim();if(new RegExp("^vec"+W+"\\s*\\(").test(ie)||w.has(ie))return B;const we=/^-?\d+(?:\.\d+)?(?:e[-+]?\d+)?$/i.test(ie),Y=v.has(ie);return!we&&!Y&&!_(ie)?B:(I.add(O),V+O+" = vec"+W+"("+ie+");")}),I.size>0){const B=[...I].sort((V,O)=>O.length-V.length).join("|");l=l.replace(new RegExp(`\\b([A-Za-z_]\\w*)\\s*([*/])\\s*(${B})\\b`,"g"),(V,O,U,W)=>w.has(O)?V:`${O} ${U} ${W}.x`),l=l.replace(new RegExp(`\\b(${B})\\s*([*/])\\s*([A-Za-z_]\\w*)\\b`,"g"),(V,O,U,W)=>w.has(W)?V:`${O}.x ${U} ${W}`)}}}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,(w,A,b,v)=>A==="float"?`${A} ${b} = ${v}.0;`:`${A} ${b} = ${A}(${v}.0);`);{const w=new Set,A=/\b(?:uniform|varying|attribute|in|out)?\s*\bfloat\s+([A-Za-z_]\w*)/g;let b;for(;(b=A.exec(l))!==null;)w.add(b[1]);if(w.size>0){const v=[...w].sort((x,P)=>P.length-x.length).join("|");l=l.replace(new RegExp(`\\b(${v})\\s*=\\s*(-?\\d+)\\s*;`,"g"),"$1 = $2.0;"),l=l.replace(new RegExp(`\\b(${v})\\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 w=Ch(l);w.size>0&&(l=l.replace(/\b(const\s+)?float\s+([A-Za-z_]\w*)\s*=\s*([^;{}]+);/g,(A,b,v,x)=>{const P=x.trim();if(/\./.test(P)||/[A-Za-z_]\w*\s*\(/.test(P))return A;const S=P.match(/[A-Za-z_]\w*/g);return!S||!S.length||!S.every(k=>w.has(k))?A:`${b||""}float ${v} = float(${P});`}))}{const w=Ch(l),A=new Set;let b;const v=/\b(?:const\s+|uniform\s+|varying\s+|in\s+|out\s+)*float\s+([A-Za-z_]\w*)/g;for(;(b=v.exec(l))!==null;)A.add(b[1]);for(const x of[...w])A.has(x)&&(w.delete(x),A.delete(x));if(w.size>0&&A.size>0){const x=[...w].sort((S,k)=>k.length-S.length).join("|"),P=[...A].sort((S,k)=>k.length-S.length).join("|");l=l.replace(new RegExp(`\\b(${x})\\s*([*/+-])\\s*(${P})\\b`,"g"),(S,k,_,I)=>`float(${k}) ${_} ${I}`),l=l.replace(new RegExp(`\\b(${P})\\s*([*/+-])\\s*(${x})\\b`,"g"),(S,k,_,I)=>`${k} ${_} float(${I})`)}}{const w=new Set,A=/\bbool\s+([A-Za-z_]\w*)\s*=/g;let b;for(;(b=A.exec(l))!==null;)w.add(b[1]);if(w.size>0){const v=[...w].join("|");l=l.replace(new RegExp(`([-+*/]=\\s*)(${v})\\b`,"g"),(x,P,S)=>`${P}float(${S})`)}}{const w=/\(\s*([^()&|]+?)\s*(<=|>=|<|>|==|!=)\s*([^()&|]+?)\s*\)/g;l=l.replace(new RegExp(w.source+"\\s*([*/])","g"),(A,b,v,x,P)=>`float(${b.trim()} ${v} ${x.trim()}) ${P}`),l=l.replace(new RegExp("([-+*/]=\\s*)"+w.source,"g"),(A,b,v,x,P)=>`${b}float(${v.trim()} ${x} ${P.trim()})`)}{const w=new Set;for(const A of l.matchAll(/\bbool\s+([A-Za-z_]\w*)\s*(?=[=;,)\[])/g))w.add(A[1]);l=Ab(l,w)}{const w=new Set;for(const A of l.matchAll(/\b(?:uniform\s+)?(?:highp|mediump|lowp\s+)?float\s+([A-Za-z_]\w*)\s*\[/g))w.add(A[1]);if(w.size){const A=[...w].sort((S,k)=>k.length-S.length).join("|"),b=new RegExp("\\b("+A+")\\s*\\[","g");let v="",x=0,P;for(;P=b.exec(l);){const S=P.index+P[0].length-1,k=fo(l,S,"[","]");if(k<0)break;let _=k+1;for(;_<l.length&&/[ \t]/.test(l[_]);)_++;if(l[_]!=="["){const U=l.slice(S+1,k).trim(),W=/\d\.\d/.test(U)||/^[A-Za-z_]\w*$/.test(U)&&new RegExp("\\bfloat\\s+"+U.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")+"\\b").test(l),ie=/^\s*int\s*\(/.test(U)||/^-?\d+$/.test(U);if(W&&!ie){v+=l.slice(x,P.index),v+=P[1]+"[int("+U+")]",x=k+1,b.lastIndex=x;continue}b.lastIndex=k+1;continue}const I=fo(l,_,"[","]");if(I<0)break;const B=l.slice(S+1,k),V=l.slice(_+1,I);v+=l.slice(x,P.index),v+=P[1]+"[int(("+B+")) * 4 + int(("+V+"))]",x=I+1,b.lastIndex=x}l=v+l.slice(x)}}l=Ft(l,"mix",(w,A)=>{const b=kr(w);if(b.length!==3)return"mix("+w+")";const v=_=>{const I=_.trim(),B=/\.([xyzwrgba]{1,4})\s*$/.exec(I);if(B)return B[1].length;const V=/^vec([234])\s*\(/.exec(I);if(V)return Number(V[1]);if(!/^[A-Za-z_]\w*$/.test(I))return 0;const O=new RegExp("\\b(vec([234])|float)\\s+"+I+"\\b","g");let U=0,W;for(;(W=O.exec(l))!==null&&W.index<A;)U=W[1].startsWith("vec")?Number(W[2]):1;return U},x=b[0].trim(),P=b[1].trim(),S=v(x),k=v(P);if(S>=2&&k>=2&&S!==k){const _=Math.min(S,k),I=_===2?".xy":_===3?".xyz":"";return I?"mix("+(S>_?x+I:x)+", "+(k>_?P+I:P)+", "+b[2].trim()+")":"mix("+w+")"}return"mix("+w+")"});{const w=/\b(vec([234]))\s+([A-Za-z_]\w*)\s*\(/g;let A="",b=0,v;for(;v=w.exec(l);){const x=Mh(l,v.index+v[0].length-1);if(x<0)break;let P=x+1;for(;P<l.length&&/\s/.test(l[P]);)P++;if(l[P]!=="{")continue;const S=fo(l,P,"{","}");if(S<0)break;const k=Number(v[2]);if(k>=4){w.lastIndex=S;continue}let _=l.slice(P+1,S);const I=new Map;for(const V of l.slice(0,v.index).matchAll(/\buniform\s+(?:highp|mediump|lowp\s+)?(vec([234]))\s+([A-Za-z_]\w*)/g))I.set(V[3],Number(V[2]));for(const V of _.matchAll(/\b(vec([234]))\s+([A-Za-z_]\w*)/g))I.set(V[3],Number(V[2]));const B=k===2?"xy":"xyz";_=_.replace(/\breturn\s+([A-Za-z_]\w*)\s*;/g,(V,O)=>{const U=I.get(O);return U&&U>k?"return "+O+"."+B+";":V}),A+=l.slice(b,P+1)+_,b=S,w.lastIndex=S}l=A+l.slice(b)}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=Ft(l,"mul",w=>{const A=kr(w);if(A.length!==2)return"mul("+w+")";const b=A[0].trim(),v=A[1].trim(),x=P=>p.has(P.split(/[\[.\s]/)[0])||/^mat[234]\(/.test(P);return x(b)&&x(v)?"(transpose("+v+") * transpose("+b+"))":x(v)?"(transpose("+v+") * "+b+")":"("+b+" * "+v+")"}),l=l.replace(/\blerp\b/g,"mix").replace(/\bfrac\b/g,"fract"),l=Ft(l,"atan2",w=>"atan("+w+")"),l=Ft(l,"fmod",w=>{const A=kr(w);if(A.length!==2)return"mod("+w+")";const b=A[0].trim(),v=A[1].trim();return"(("+b+") - ("+v+") * trunc(("+b+") / ("+v+")))"}),l=Ft(l,"ddx",w=>"dFdx("+w+")"),l=Ft(l,"ddy",w=>"dFdy("+w+")"),l=Ft(l,"CAST3X3",w=>"mat3("+w+")"),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 b=new Map,v=new Set,x=/^\s*(?:varying|out)\s+(?:highp|mediump|lowp\s+)?(vec[234]|float)\s+([A-Za-z_]\w*)\s*;/gm;let P;for(;(P=x.exec(i))!==null;){const _=b.get(P[2]);_!==void 0&&_!==P[1]&&v.add(P[2]),b.set(P[2],P[1])}const S={float:1,vec2:2,vec3:3,vec4:4},k=new Map;if(l=l.replace(/^(\s*in\s+(?:highp|mediump|lowp\s+)?)(vec[234]|float)(\s+)([A-Za-z_]\w*)(\s*;)/gm,(_,I,B,V,O,U)=>{const W=b.get(O);return!W||v.has(O)||S[W]<=S[B]?_:(k.set(O,S[B]),I+W+V+O+U)}),k.size>0){const _={1:"x",2:"xy",3:"xyz"};for(const[I,B]of k){const V=_[B];V&&(l=l.split(`
|
|
17
|
+
`).map(O=>/^\s*in\s/.test(O)?O:O.replace(new RegExp("\\b"+I+"\\b(?!\\s*[.\\w])","g"),I+"."+V)).join(`
|
|
18
|
+
`))}}l=l.replace(/^(\s*in\s+(?:highp|mediump|lowp\s+)?)(vec[234]|float)(\s+)([A-Za-z_]\w*)(\s*;)/gm,(_,I,B,V,O,U)=>{const W=b.get(O);if(!W||v.has(O)||S[W]>=S[B])return _;const ie="xyzw",we="rgba";return new RegExp("\\b"+O+"\\s*\\.\\s*["+ie+we+"]*["+ie.slice(S[W])+we.slice(S[W])+"]").test(l)?_:I+W+V+O+U})}{const b=new Map,v=/^\s*in\s+(?:highp|mediump|lowp\s+)?(vec[34])\s+([A-Za-z_]\w*)\s*;/gm;let x;for(;(x=v.exec(l))!==null;)b.set(x[2],Number(x[1].slice(3)));const P=new Map(b),S=/\b(vec[34])\s+([A-Za-z_]\w*)\s*[=;]/g;for(;(x=S.exec(l))!==null;)P.has(x[2])||P.set(x[2],Number(x[1].slice(3)));if(P.size>0){const k=_=>{const I=_.trim();if(!I)return _;const B=/^([A-Za-z_]\w*)$/.exec(I);if(B&&P.has(B[1]))return B[1]+".xy";const V=/^([A-Za-z_]\w*)(\s*[+\-].+)$/.exec(I);return V&&P.has(V[1])?"("+V[1]+".xy"+V[2]+")":_};for(const _ of["textureLod","texture"])l=Ft(l,_,I=>{const B=kr(I);return B.length>=2&&(B[1]=k(B[1])),_+"("+B.join(", ")+")"})}b.size>0&&(l=l.split(`
|
|
19
|
+
`).map(k=>{if(!/\bvec2\s+[A-Za-z_]\w*\s*=/.test(k))return k;let _=k;for(const I of b.keys())_=_.replace(new RegExp("\\b"+I+"\\b(?!\\s*[.\\w])","g"),I+".xy");return _}).join(`
|
|
20
|
+
`))}const w=new Set,A=new Set;{const b=/^\s*in\s+(?:highp|mediump|lowp\s+)?(vec[234]|float)\s+([A-Za-z_]\w*)\s*;/gm;let v;for(;(v=b.exec(l))!==null;)A.add(v[2])}for(const b of A)new RegExp("\\b"+b+"\\b\\s*(?:\\.[xyzwrgba]{1,4})?\\s*(?:[-+*/]?=(?!=)|\\+\\+|--)").test(l)&&w.add(b);if(w.size>0){const b=l.search(/\bvoid\s+main\s*\([^)]*\)\s*\{/);if(b!==-1){const v=l.indexOf("{",b),x=l.slice(0,v+1);let P=l.slice(v+1);const S=[];for(const k of w){if(new RegExp("(?:^|[;{}\\n])\\s*(?:highp|mediump|lowp\\s+)?(?:vec[234]|float|int|bool)\\s+"+k+"\\s*[=;]").test(P))continue;const I=new RegExp("^\\s*in\\s+(?:highp|mediump|lowp\\s+)?(vec[234]|float)\\s+"+k+"\\s*;","m").exec(l),B=I?I[1]:"vec4";S.push(" "+B+" "+k+"_rw = "+k+";"),P=Zs(P,k,k+"_rw")}S.length>0&&(P=`
|
|
21
|
+
`+S.map(k=>k.replace(/= (\w+)_rw;/,"= $1;")).join(`
|
|
16
22
|
`)+`
|
|
17
|
-
`+
|
|
18
|
-
`).map(
|
|
19
|
-
`)}
|
|
20
|
-
`;return
|
|
21
|
-
`),
|
|
22
|
-
`,/\bgl_FragColor\b/.test(l)&&(
|
|
23
|
-
`,l=l.replace(/\bgl_FragColor\b/g,"fragColor"))),
|
|
23
|
+
`+P),l=x+P}}}l=l.replace(/\[(?:unroll|loop|branch|flatten)\]\s*/g,""),l=l.replace(/\bstatic\s+/g,""),f.length>0&&(l=l.replace(/\u0003(\u0004+)\u0003/g,(w,A)=>f[A.length-1]));{const w=new Set;for(const A of l.matchAll(/\b(?:uniform[ \t]+)?(?:highp|mediump|lowp)?[ \t]*float[ \t]+([A-Za-z_]\w*)[ \t]*[;=]/g))w.add(A[1]);if(w.size){const A=b=>{const v=b.trim().startsWith("-"),x=b.replace(/^-\s*/,"").trim();return w.has(x)?(v?"-":"")+"int("+x+")":b};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,(b,v,x,P,S,k,_)=>v+A(P)+S+A(k)+_)}}{const w=new Set;l=l.split(`
|
|
24
|
+
`).map(A=>{const b=/^[ \t]*uniform[ \t]+(?:highp|mediump|lowp[ \t]+)?[A-Za-z0-9_]+[ \t]+([A-Za-z_][A-Za-z0-9_]*)/.exec(A);if(!b)return A;const v=b[1];return w.has(v)?"":(w.add(v),A)}).join(`
|
|
25
|
+
`)}{const w=()=>{const S=new Set,k=/\b(?:uniform\s+)?(?:highp\s+|mediump\s+|lowp\s+)?(?:float|vec2|vec3|vec4|mat2|mat3|mat4)\s+([A-Za-z_][A-Za-z0-9_]*)/g;let _;for(;(_=k.exec(l))!==null;)S.add(_[1]);return S},A=(S,k)=>{if(!S)return!1;if(/\d*\.\d|\d\./.test(S)||/^float\s*\(/.test(S))return!0;const _=/^[A-Za-z_]\w*/.exec(S);return!!(_&&k.has(_[0]))},b=(S,k)=>{let _="",I=0;for(;I<S.length;){const B=/\bint\s*\(/.exec(S.slice(I));if(!B){_+=S.slice(I);break}const V=I+B.index;_+=S.slice(I,V);let O=0,U=V+B[0].length-1;for(;U<S.length;U++)if(S[U]==="(")O++;else if(S[U]===")"&&(O--,O===0)){U++;break}const W=S.slice(V,U),ie=S.slice(0,V),we=S.slice(U);if(/\b(?:float|int|uint)\s*\(\s*$/.test(ie)){_+=W,I=U;continue}{const Le=/\bfor\s*\(/g;let Ne=-1,De;for(;(De=Le.exec(ie))!==null;)Ne=De.index;if(Ne>=0){const Re=ie.slice(Ne);let Fe=0,Xe=!1;for(const $e of Re)$e==="("?(Fe++,Xe=!0):$e===")"&&(Fe--,Fe<=0&&(Xe=!1));if(Xe&&Fe>0){_+=W,I=U;continue}}}const Y=/(?:([^\s;,(]+)\s*)?([+\-*/%<>=!]=?|[<>])\s*$/.exec(ie),oe=/^\s*([+\-*/%<>=!]=?|[<>])\s*([^\s;,)]+)?/.exec(we),he=Y&&Y[1]?Y[1]:null,Ae=oe&&oe[2]?oe[2]:null,Pe=!!(Y&&Y[2])||!!(oe&&oe[1]),Ce=(he&&A(he,k)?he:null)||(Ae&&A(Ae,k)?Ae:null);Pe&&Ce?_+="float("+W+")":_+=W,I=U}return _},v=(S,k)=>{S=S.replace(/\b([A-Za-z_]\w*)\s*%=\s*([^;]+);/g,(I,B,V)=>{if(!k.has(B))return I;const O=/^\s*(\d+)\s*$/.exec(V);return`${B} = mod(${B}, ${O?O[1]+".0":V.trim()});`});const _=Array.from(k).sort((I,B)=>B.length-I.length).join("|");return _&&(S=S.replace(new RegExp("\\b("+_+")\\s*%\\s*([^=;]+)","g"),(I,B,V)=>/^\s*[A-Za-z_]/.test(V)&&!k.has(V.trim())?I:`${B} % ${V}`)),S},x=S=>S.replace(/\bconst\s+((?:highp|mediump|lowp)\s+)?(float|int|bool|vec2|vec3|vec4|mat2|mat3|mat4)\s+([A-Za-z_]\w*)\s*=\s*([^;]+);/g,(k,_,I,B,V,O)=>{let U=0;for(let ie=0;ie<O;ie++){const we=S[ie];we==="{"?U++:we==="}"&&U--}if(U<=0)return k;const W=V.replace(/\b(vec2|vec3|vec4|mat2|mat3|mat4|float|int|bool|true|false)\b/g," ");return/[A-Za-z_]/.test(W)?`${I} ${B} = ${V};`:k});l=l.replace(/\b((?:highp|mediump|lowp)\s+)?(float|vec2|vec3|vec4)(\s+[A-Za-z_]\w*\s*=\s*)(\((?:[^()]|\([^()]*\))*\s*(?:[<>]=?|==|!=)\s*(?:[^()]|\([^()]*\))*\))\s*;/g,(S,k,_,I,B)=>`${k||""}${_}${I}${_}(${B});`);const P=w();l=b(l,P),l=v(l,P),l=x(l)}d.length>0&&(l=l.replace(/\u0001(\u0002+)\u0001/g,(w,A)=>d[A.length-1]));let y=`#version 300 es
|
|
26
|
+
`;return e==="vert"&&(y+=`precision highp float;
|
|
27
|
+
`),e==="frag"&&(y+=`precision highp float;
|
|
28
|
+
`,/\bgl_FragColor\b/.test(l)&&(y+=`out vec4 fragColor;
|
|
29
|
+
`,l=l.replace(/\bgl_FragColor\b/g,"fragColor"))),y+l}const Rh={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]},Bh={2:"multiply",6:"additive",7:"screen",9:"additive",31:"additive"},xb={screen:1,multiply:2},Fh=`// 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
|
+
// [we-scene patch] **mode 0 \u4E5F\u5FC5\u987B\u6392\u9664**\uFF1A\u5B83\u7684\u5206\u652F\u5DF2\u7ECF\u662F mix(A, B, opacity)\uFF0C
|
|
162
|
+
// \u518D\u5957\u4E00\u5C42\u7B49\u4E8E\u6309 opacity\xB2 \u52A0\u6743\u3002effects.js \u7684 default \u5206\u652F\u662F switch \u5185\u76F4\u63A5
|
|
163
|
+
// return mix3(A, B, opacity)\u3001\u4E0D\u8D70 per() \u7684\u4E8C\u6B21\u52A0\u6743\uFF0C\u8FD9\u91CC\u6F0F\u6392\u4E86 0\u3002
|
|
164
|
+
// \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
|
|
165
|
+
// \u8089\u773C\u4E0E readPixels \u90FD\u8BFB\u4E0D\u51FA\uFF08\u5B9E\u6D4B 6 \u4E2A xray \u58C1\u7EB8\u50CF\u7D20\u5DEE\u6070\u597D\u4E3A 0\uFF0C
|
|
166
|
+
// \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
|
|
167
|
+
// \u6CE8\u610F\u672C\u6587\u4EF6\u662F TS \u6A21\u677F\u5B57\u7B26\u4E32\uFF0C\u6CE8\u91CA\u91CC\u4E0D\u80FD\u51FA\u73B0\u53CD\u5F15\u53F7\u3002
|
|
168
|
+
if (mode != 0 && mode != 5 && mode != 10 && mode != 30 && mode != 31 && mode != 32) {
|
|
169
|
+
r = mix(A, r, opacity);
|
|
170
|
+
}
|
|
171
|
+
return r;
|
|
172
|
+
}
|
|
173
|
+
// [we-scene patch 3351179520] combo \u66FF\u6362\u4F1A\u628A int \u578B combo \u503C\u5199\u6210\u6D6E\u70B9\u5B57\u9762\u91CF
|
|
174
|
+
// \uFF08BLENDMODE \u2192 0.0\uFF09\uFF0CGLSL ES \u6CA1\u6709 float\u2192int \u9690\u5F0F\u8F6C\u6362\uFF0Ccircular_text \u7B49
|
|
175
|
+
// workshop shader \u6309 \`ApplyBlending(0.0, \u2026)\` \u8C03\u7528\u4F1A\u300Cno matching overloaded
|
|
176
|
+
// function found\u300D\u6574\u6761 pass \u62A5\u5E9F\u3002\u52A0\u4E00\u4E2A float \u91CD\u8F7D\u8F6C\u56DE int\uFF1A\u5DF2\u6709\u8C03\u7528\u70B9
|
|
177
|
+
// \uFF08int \u5B57\u9762\u91CF/uniform\uFF09\u4ECD\u7CBE\u786E\u547D\u4E2D\u539F\u91CD\u8F7D\uFF0C\u4E0D\u53D7\u5F71\u54CD\u3002
|
|
178
|
+
vec3 ApplyBlending(float mode, vec3 A, vec3 B, float opacity) {
|
|
179
|
+
return ApplyBlending(int(mode + 0.5), A, B, opacity);
|
|
180
|
+
}`,kb=`#version 300 es
|
|
181
|
+
precision mediump float;
|
|
182
|
+
in vec2 v_UV;
|
|
183
|
+
uniform sampler2D u_Tex;
|
|
184
|
+
uniform sampler2D u_Backdrop;
|
|
185
|
+
uniform int u_BlendMode;
|
|
186
|
+
uniform vec2 u_CanvasSize;
|
|
187
|
+
uniform float u_Opacity;
|
|
188
|
+
out vec4 fragColor;
|
|
189
|
+
${Fh}
|
|
190
|
+
void main() {
|
|
191
|
+
vec4 src = texture(u_Tex, v_UV);
|
|
192
|
+
// \u80CC\u666F\u6309**\u7247\u5143\u7684\u5C4F\u5E55\u4F4D\u7F6E**\u91C7\u6837\uFF1Agl_FragCoord \u539F\u70B9\u5728\u5DE6\u4E0B\uFF0C\u4E0E copyTexImage2D
|
|
193
|
+
// \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
|
|
194
|
+
vec3 dst = texture(u_Backdrop, gl_FragCoord.xy / u_CanvasSize).rgb;
|
|
195
|
+
vec3 r = ApplyBlending(u_BlendMode, dst, src.rgb, src.a * u_Opacity);
|
|
196
|
+
// 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
|
|
197
|
+
fragColor = vec4(r, 1.0);
|
|
198
|
+
}`,Tb=`#version 300 es
|
|
199
|
+
in vec3 a_Position;
|
|
200
|
+
in vec2 a_TexCoord;
|
|
201
|
+
uniform vec2 u_Texel; // 1/\u573A\u666F\u7EB9\u7406\u5C3A\u5BF8
|
|
202
|
+
uniform float u_Damp; // Feather\uFF08\u6750\u8D28\u539F\u5B57\u6BB5 "Damp brightness"\uFF0C\u9ED8\u8BA4 0.5\uFF09
|
|
203
|
+
out vec2 v_TexCoord[4];
|
|
204
|
+
out float v_Damp;
|
|
205
|
+
void main() {
|
|
206
|
+
v_Damp = 1.0 + u_Damp * 0.1;
|
|
207
|
+
gl_Position = vec4(a_Position, 1.0);
|
|
208
|
+
vec2 offsets = u_Texel;
|
|
209
|
+
v_TexCoord[0] = a_TexCoord - offsets;
|
|
210
|
+
v_TexCoord[1] = a_TexCoord + vec2(offsets.x, -offsets.y);
|
|
211
|
+
v_TexCoord[2] = a_TexCoord + vec2(-offsets.x, offsets.y);
|
|
212
|
+
v_TexCoord[3] = a_TexCoord + offsets;
|
|
213
|
+
}`,Sb=`#version 300 es
|
|
214
|
+
precision mediump float;
|
|
215
|
+
in vec2 v_TexCoord[4];
|
|
216
|
+
in float v_Damp;
|
|
217
|
+
uniform sampler2D u_Tex;
|
|
218
|
+
uniform float u_Alpha;
|
|
219
|
+
uniform float u_Strength;
|
|
220
|
+
uniform float u_Threshold;
|
|
221
|
+
// 0 = \u7ECF\u5178\u5BB6\u65CF\uFF08WE \u5F15\u64CE downsample_quarter_bloom \u9010\u884C\u8F6C\u5199\uFF09
|
|
222
|
+
// 1 = HDR \u5BB6\u65CF\uFF08bloomhdr*\uFF09\u7684 SDR \u7B49\u6548\u5224\u5B9A\uFF0C\u89C1 renderer.js bloomPostParams \u6CE8\u91CA
|
|
223
|
+
uniform int u_Metric;
|
|
224
|
+
out vec4 fragColor;
|
|
225
|
+
void main() {
|
|
226
|
+
vec3 lightMap = vec3(0.0);
|
|
227
|
+
if (u_Strength > 0.001 && u_Alpha > 0.001) {
|
|
228
|
+
if (u_Metric == 0) {
|
|
229
|
+
// \u5F15\u64CE\u539F\u6587\uFF1A4 \u62BD\u5934\u5E73\u5747 \u2192 saturate(max \u901A\u9053 - threshold) \u8F6F\u62D0\u70B9
|
|
230
|
+
// \u2192 \u9971\u548C\u5EA6 \xD72\uFF08-grayscale*sat + albedo*(1+sat)\uFF0Csat=1\uFF09\u2192 \xD7strength\uFF08\u4E00\u6B21\uFF09\u3002
|
|
231
|
+
// saturate \u5728 GLSL \u4E0D\u5B58\u5728\uFF0Cclamp(x,0,1) \u7B49\u4EF7\u3002
|
|
232
|
+
vec3 albedo = texture(u_Tex, v_TexCoord[0]).rgb +
|
|
233
|
+
texture(u_Tex, v_TexCoord[1]).rgb +
|
|
234
|
+
texture(u_Tex, v_TexCoord[2]).rgb +
|
|
235
|
+
texture(u_Tex, v_TexCoord[3]).rgb;
|
|
236
|
+
albedo *= 0.25;
|
|
237
|
+
float scale = max(max(albedo.x, albedo.y), albedo.z);
|
|
238
|
+
albedo *= clamp(scale - u_Threshold, 0.0, 1.0);
|
|
239
|
+
float grayscale = dot(vec3(0.2989, 0.5870, 0.1140), albedo);
|
|
240
|
+
albedo = -grayscale + albedo * 2.0;
|
|
241
|
+
lightMap = max(vec3(0.0), albedo * u_Strength);
|
|
242
|
+
} else {
|
|
243
|
+
// HDR \u5BB6\u65CF\u65E2\u6709\u6821\u51C6\uFF082646504847\uFF09\uFF1Araw sRGB \u4EAE\u5EA6 + \u8F6F\u7A97\u53E3\u3002
|
|
244
|
+
// strength \u5728\u6B64\u4E58\u4E24\u6B21\uFF0C\u8865\u507F blur \u4E0D\u518D\u4E58\uFF08\u4E0E\u65E7\u884C\u4E3A\u9010\u4F4D\u4E00\u81F4\uFF09\u3002
|
|
245
|
+
float weight = 0.0;
|
|
246
|
+
vec3 samplec;
|
|
247
|
+
for (int i = 0; i < 4; ++i) {
|
|
248
|
+
samplec = texture(u_Tex, v_TexCoord[i]).rgb;
|
|
249
|
+
float w = smoothstep(u_Threshold - 0.2, u_Threshold + 0.4, dot(samplec, vec3(0.2126, 0.7152, 0.0722)));
|
|
250
|
+
lightMap += samplec * w;
|
|
251
|
+
weight += w;
|
|
252
|
+
}
|
|
253
|
+
lightMap = lightMap * max(0.001, mix(weight, 1.0, v_Damp)) / 4.0 * u_Strength * u_Strength;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
fragColor = vec4(lightMap, 1.0);
|
|
257
|
+
}`,Pb=`#version 300 es
|
|
258
|
+
in vec3 a_Position;
|
|
259
|
+
in vec2 a_TexCoord;
|
|
260
|
+
uniform vec2 u_Texel; // 1/\u6E90\u7EB9\u7406\u5C3A\u5BF8
|
|
261
|
+
uniform vec2 u_Res; // \u6E90\u7EB9\u7406\u5C3A\u5BF8
|
|
262
|
+
uniform float u_Radius; // Scatter
|
|
263
|
+
out vec2 v_TexCoord;
|
|
264
|
+
out vec2 v_SizeMultiplier;
|
|
265
|
+
void main() {
|
|
266
|
+
vec2 ratio = u_Res * u_Texel;
|
|
267
|
+
v_SizeMultiplier = u_Texel * vec2(1.0, ratio.x / ratio.y) * u_Radius;
|
|
268
|
+
gl_Position = vec4(a_Position, 1.0);
|
|
269
|
+
v_TexCoord = a_TexCoord;
|
|
270
|
+
}`,_b=`#version 300 es
|
|
271
|
+
precision mediump float;
|
|
272
|
+
in vec2 v_TexCoord;
|
|
273
|
+
in vec2 v_SizeMultiplier;
|
|
274
|
+
uniform sampler2D u_Tex;
|
|
275
|
+
uniform float u_Alpha;
|
|
276
|
+
uniform float u_Strength;
|
|
277
|
+
uniform float u_Iterations;
|
|
278
|
+
uniform vec2 u_Dir; // (1,0)=\u6A2A\u5411 / (0,1)=\u7EB5\u5411
|
|
279
|
+
out vec4 fragColor;
|
|
280
|
+
void main() {
|
|
281
|
+
vec4 albedo = vec4(0.0);
|
|
282
|
+
if (u_Strength > 0.001 && u_Alpha > 0.001) {
|
|
283
|
+
float divisor = 0.0, weight, n;
|
|
284
|
+
float iterations = u_Iterations;
|
|
285
|
+
for (int i = -15; i <= 15; i++) {
|
|
286
|
+
if (abs(float(i)) > iterations) continue;
|
|
287
|
+
n = float(i);
|
|
288
|
+
vec2 offset = u_Dir * (n * v_SizeMultiplier);
|
|
289
|
+
weight = exp(-abs(n) * 0.1);
|
|
290
|
+
divisor += weight;
|
|
291
|
+
albedo += texture(u_Tex, v_TexCoord + offset) * weight;
|
|
292
|
+
}
|
|
293
|
+
// \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
|
|
294
|
+
// downsample_eighth_blur_v / blur_h_bloom \u540C\u6837\u4E0D\u4E58 strength\uFF09\u3002
|
|
295
|
+
// 2026-09-11 \u524D\u8FD9\u91CC\u6A2A/\u7EB5\u4E24\u8D9F\u5404\u4E58\u4E00\u6B21 \u2192 strength\xB2 \u53E0\u6EE1\u5168\u5C4F\u3002
|
|
296
|
+
albedo = albedo / divisor;
|
|
297
|
+
}
|
|
298
|
+
fragColor = albedo;
|
|
299
|
+
}`,Eb=`#version 300 es
|
|
300
|
+
precision mediump float;
|
|
301
|
+
in vec2 v_UV;
|
|
302
|
+
uniform sampler2D u_Tex; // \u6A21\u7CCA\u540E\u7684 bloom
|
|
303
|
+
uniform float u_Alpha;
|
|
304
|
+
uniform float u_Strength;
|
|
305
|
+
uniform vec3 u_Tint;
|
|
306
|
+
out vec4 fragColor;
|
|
307
|
+
void main() {
|
|
308
|
+
vec3 bloom = texture(u_Tex, v_UV).rgb * u_Tint * u_Alpha;
|
|
309
|
+
if (u_Strength <= 0.001) bloom = vec3(0.0);
|
|
310
|
+
// Add\uFF08ApplyBlending 31\uFF09\uFF1Argb = base + bloom\uFF1BGL \u4FA7 blendFunc(ONE, ONE)\uFF0C
|
|
311
|
+
// 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
|
|
312
|
+
fragColor = vec4(bloom, 0.0);
|
|
313
|
+
}`,hs=`#version 300 es
|
|
24
314
|
in vec3 a_Position;
|
|
25
315
|
in vec2 a_TexCoord;
|
|
26
316
|
uniform mat4 u_MVP;
|
|
@@ -28,7 +318,7 @@ out vec2 v_UV;
|
|
|
28
318
|
void main() {
|
|
29
319
|
gl_Position = u_MVP * vec4(a_Position, 1.0);
|
|
30
320
|
v_UV = a_TexCoord;
|
|
31
|
-
}`,
|
|
321
|
+
}`,Mb=`#version 300 es
|
|
32
322
|
precision mediump float;
|
|
33
323
|
in vec2 v_UV;
|
|
34
324
|
uniform sampler2D u_Tex;
|
|
@@ -44,7 +334,7 @@ void main() {
|
|
|
44
334
|
if (u_BlendPrep == 1) c.rgb *= c.a;
|
|
45
335
|
else if (u_BlendPrep == 2) c.rgb = mix(vec3(1.0), c.rgb, c.a);
|
|
46
336
|
fragColor = c;
|
|
47
|
-
}`,
|
|
337
|
+
}`,Cb=`#version 300 es
|
|
48
338
|
precision mediump float;
|
|
49
339
|
in vec2 v_UV;
|
|
50
340
|
uniform sampler2D u_Tex;
|
|
@@ -55,15 +345,52 @@ void main() {
|
|
|
55
345
|
if (u_BlendPrep == 1) c.rgb *= c.a;
|
|
56
346
|
else if (u_BlendPrep == 2) c.rgb = mix(vec3(1.0), c.rgb, c.a);
|
|
57
347
|
fragColor = c;
|
|
58
|
-
}`,
|
|
348
|
+
}`,Ib=`#version 300 es
|
|
59
349
|
precision mediump float;
|
|
60
350
|
in vec2 v_UV;
|
|
61
351
|
uniform sampler2D u_Tex;
|
|
62
352
|
out vec4 fragColor;
|
|
63
353
|
void main() {
|
|
64
354
|
fragColor = vec4(texture(u_Tex, v_UV).rgb, 1.0);
|
|
65
|
-
}
|
|
66
|
-
void main(`));const o=n?/unprojectedUVs\s*\*=\s*v_PointerScale\s*\*/:/unprojectedUVs\s*\*=\s*g_PointerScale\s*\*/;return r.replace(o,"unprojectedUVs *= "+Ga+" *")}const ni=1;function ri(e,n){return e==="g_PointerScale"?ni:n}function Ya(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=lr(t,Hr,Fa),j=lr(t,Hr,Na),H=lr(t,Hr,Ua),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 W=new Map;let X=1;function ie(w,U,G){const V=(G||"")+"|"+w+"x"+U;if(W.has(V)){const b=W.get(V);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 W.set(V,oe),oe}function J(){for(const[w,U]of W)U.stamp!==X&&(U.fbo&&t.deleteFramebuffer(U.fbo),U.tex&&t.deleteTexture(U.tex),W.delete(w))}const Z=new Map,te=new Map,le=new Map;function Fe(w){const U={},G=/uniform\s+[A-Za-z0-9_]+\s+([A-Za-z_][A-Za-z0-9_]*)[^;]*;\s*\/\/([^\n]*)/g;let V;for(;(V=G.exec(w))!==null;){const Y=V[1],ee=V[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?Ve(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 V;for(;(V=G.exec(w))!==null;){const Y=Number(V[1]),ee=/"default"\s*:\s*"([^"]+)"/.exec(V[2]);ee&&ee[1]&&U.set(Y,ee[1])}return U}function Ye(w){const U=[],G=/uniform\s+sampler2D\s+(g_Texture(\d+))[^;]*;\s*\/\/([^\n]*)/g;let V;for(;(V=G.exec(w))!==null;){const Y=/"combo"\s*:\s*"([^"]+)"/.exec(V[3]);Y&&U.push({slot:Number(V[2]),name:V[1],combo:Y[1]})}return U}function Ve(w){if(w.startsWith('"'))return w.slice(1,-1);const U=Number(w);return Number.isFinite(U)?U:void 0}async function Ne(w,U,G){let V=le.get(w);if(V===void 0){const oe=await r("shaders/"+w+".frag")||"",b=await r("shaders/"+w+".vert")||"";V={frag:oe,vert:b,texCombos:Ye(oe)},le.set(w,V)}const Y={...U};for(const oe of V.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=ti(Xo(V.frag,"frag",Y,T,V.vert)),C=Xo(V.vert,"vert",Y,T,V.frag);if(b.size===0){let I;try{I=lr(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:Oa[k.type]||"unknown",size:k.size})}const z={...Fe(V.vert),...Fe(V.frag)},B=/gl_Position\s*=\s*vec4\s*\(\s*a_Position/.test(V.vert)&&!/[aA]_Position[\s\S]{0,40}mul\s*\(/.test(V.vert),q=new Map([..._e(V.vert),..._e(V.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 qe=Xr(t,new Uint8Array([255,255,255,255]),1,1),Ue=Xr(t,new Uint8Array([0,0,0,0]),1,1);let ye=null;function he(w){ye=w||null}function De(){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 Ze=0,Be=0,Ae=0,nt=1/60,rt=-1;const Ft=typeof n.fadeDuration=="number"&&n.fadeDuration>=0?n.fadeDuration:1,xe=(w,U)=>{const G=w!==null&&typeof w=="object"?w.value:w;return G===!0||G===1?!0:G===!1||G===0?!1:U},zt=(w,U)=>{const G=w!==null&&typeof w=="object"?w.value:w;return typeof G=="number"&&Number.isFinite(G)?G:U},Er=w=>n.fade!==!1&&xe(w.camerafade,!1);function Vt(w,U){if(!xe(w.camerashake,!1))return null;const G=zt(w.camerashakeamplitude,0);if(G===0)return null;const V=Math.max(0,Math.min(1,zt(w.camerashakeroughness,0))),Y=zt(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-V)+T*V)*G,y:(b*(1-V)+P*V)*G}}function Mn(){const w=new Date;return(w.getHours()*3600+w.getMinutes()*60+w.getSeconds())/86400}function Me(w,U,G){const V=w.get(U);V&&V.loc!==null&&G(V.loc,V.type,V.size)}function _n(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 Wt(w,U,G){const V=w.get(U);if(!V||V.loc===null)return;const Y=G&&G.value!==void 0?G.value:G,ee=_n(Y);switch(V.type){case"float":t.uniform1f(V.loc,ee[0]);break;case"int":case"bool":t.uniform1i(V.loc,Y===!0||Y===1?1:Math.round(ee[0]));break;case"vec2":t.uniform2f(V.loc,ee[0],ee[1]);break;case"vec3":t.uniform3f(V.loc,ee[0],ee[1],ee[2]);break;case"vec4":t.uniform4f(V.loc,ee[0],ee[1],ee[2],ee[3]);break;case"mat4":t.uniformMatrix4fv(V.loc,!1,it);break;case"mat3":t.uniformMatrix3fv(V.loc,!1,ht);break}}const Je=()=>new Float32Array([1,0,0,0,1,0,0,0,1]);function An(w,U,G,V,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,Mn())),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?Uo(Dn(gn(),S[0]/2,S[1]/2,1)):it;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/V,1/Y)),Me(w,"g_TexelSizeHalf",S=>t.uniform2f(S,.5/V,.5/Y)),Me(w,"g_TextureReductionScale",S=>t.uniform1f(S,1));const I=De(),D=qr(!!(I&&I.has),!!w.get("g_PointerScale"));let $=D?On:I?I.u:.5,z=D?On:I?I.v:.5,B=D?On:I?I.lastU:.5,q=D?On: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,ne=ce=>(C.offX+ce*C.viewW-k)/S,Q=ce=>(C.offY+ce*C.viewH-F)/E;$=ne($),z=Q(z),B=ne(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,nt)),w.get("g_EffectTextureProjectionMatrixInverse")&&Me(w,"g_EffectTextureProjectionMatrixInverse",S=>t.uniformMatrix4fv(S,!1,it));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,ne=>t.uniform1fv(ne,F))}}}function Ht(w,U,G){for(const[V,Y]of Object.entries(U||{})){const ee=G&&G[V];ee&&Wt(w,ee.uniform,Y)}for(const[V,Y]of Object.entries(G||{}))if(!U||!(V in U)){const ee=ri(Y.uniform,Y.default);ee!==void 0&&Wt(w,Y.uniform,ee)}}function Qn(w){const U=De();qr(!!(U&&U.has),!!w.get("g_PointerScale"))&&Me(w,"g_PointerScale",G=>t.uniform1f(G,0))}function Jn(w,U,G,V){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:V||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=_n(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=nt,P.engine.timeOfDay=Mn();const B=De();B&&B.screenW&&B.screenH&&(P.engine.screenResolution={x:B.screenW,y:B.screenH})}const C=_n(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 Pr(w,U,G){if(!w)return w;let V=!1;for(const ee of Object.values(w))if(ee&&typeof ee=="object"&&ee.animation&&ee.animation.options){V=!0;break}if(!V)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=Ko(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 er(w,U,G,V){return w==null||w===""?null:w.startsWith("_rt_")?w.startsWith("_rt_imageLayerComposite")?fn&&mt.has(w)?mt.get(w):U:G.has(w)?G.get(w):null:G.has(w)?G.get(w):V.get(w)||null}const Xt=Ba(),Cr=Ia(),un=new Map;function tn(w,U){const G=w+"x"+U;let V=un.get(G);return V===void 0&&(V=Da(w,U),un.set(G,V)),V}let ot=null;function dt(w,U){ot!==w&&(t.bindBuffer(t.ARRAY_BUFFER,O),t.bufferData(t.ARRAY_BUFFER,U,t.DYNAMIC_DRAW),ot=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")},pt={mvp:t.getUniformLocation(j,"u_MVP"),tex:t.getUniformLocation(j,"u_Tex"),blendPrep:t.getUniformLocation(j,"u_BlendPrep")},Gt={mvp:t.getUniformLocation(H,"u_MVP"),tex:t.getUniformLocation(H,"u_Tex")},it=gn(),ht=Je();function At(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 Nt=0;function Tt(w){const{mode:U,prep:G}=Yr(w);Nt=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)):At("translucent")}function Tn(w,U){if(U&&U.perspective)return!1;const G=w.size[0]*w.scale[0],V=w.size[1]*w.scale[1];if(G===0||V===0)return!1;let Y=Math.abs(G)/2,ee=Math.abs(V)/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(vn(w.parallaxDepth[0])*Be),P+=Math.abs(vn(w.parallaxDepth[1])*Ae));const C=Qo(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 Sn(w,U,G){if(!w.spriteSheet)return null;const V=U&&U.frames,Y=Array.isArray(V)?V:V&&V.list;if(!Y||Y.length===0)return null;const ee=V&&V.atlasWidth||U.width||0,oe=V&&V.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 Ut(w,U){const G=w.size[0]*w.scale[0],V=w.size[1]*w.scale[1];let Y=gn();if(U&&U.perspective){const oe=wa(w,U);Y=yn(Y,oe[0],oe[1],oe[2]);const b=w.angles[0]||0,T=w.angles[1]||0;T&&(Y=ya(Y,T)),b&&(Y=ba(Y,b)),Y=Do(Y,-w.angles[2])}else{if(Y=yn(Y,w.origin[0],U.projH-w.origin[1],w.origin[2]),w.parallaxDepth&&(Be!==0||Ae!==0)){const oe=vn(w.parallaxDepth[0]),b=vn(w.parallaxDepth[1]);Y=yn(Y,oe*Be,b*Ae,0)}Y=Do(Y,-w.angles[2])}const ee=Go[w.alignment]||[.5,.5];return(ee[0]!==.5||ee[1]!==.5)&&(Y=yn(Y,(.5-ee[0])*G,(.5-ee[1])*V,0)),{m:Y,w:G,h:V}}function En(w,U,G,V,Y,ee,oe,b,T=!1,P=null,C=null){const I=Ut(V,Y);let D=I.m;if(C){const B=(C[0]+C[2]/2)*V.scale[0],q=(C[1]+C[3]/2)*V.scale[1];D=yn(D,B,-q,0),D=Dn(D,C[2]*V.scale[0],C[3]*V.scale[1],1)}else D=Dn(D,I.w,I.h,1);const $=Lt(ee,D),z=w===j?pt:Te;t.useProgram(w),T?(Nt=0,t.enable(t.BLEND),V.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)):Tt(V.colorBlendMode),z.blendPrep!==null&&z.blendPrep!==void 0&&t.uniform1i(z.blendPrep,Nt),je?(t.bindFramebuffer(t.FRAMEBUFFER,je.fbo.fbo),t.viewport(0,0,je.w,je.h)):(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,oe,b)),t.bindVertexArray(K),dt("local",Cr),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]),Dt(z,P),t.drawArrays(t.TRIANGLES,0,6)}function Dt(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 nn=null,je=null;const mt=new Map,gt=new Map;let fn=!0;function Pn(w,U){const G=Ut(w,U),V=U&&U.perspective?w.scale[1]:-w.scale[1],Y=U&&U.perspective&&w.scale[2]||1;return Dn(G.m,w.scale[0],V,Y)}function rn(w,U,G,V,Y,ee,oe){je?(t.bindFramebuffer(t.FRAMEBUFFER,je.fbo.fbo),t.viewport(0,0,je.w,je.h)):(t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,V,Y));const b=Lt(G,Pn(w,U));nn(w,b,{time:ee,overrideTex:oe||null}),ot=null}let ut=null;function Cn(w,U){return ut===null&&(ut=t.createTexture(),t.bindTexture(t.TEXTURE_2D,ut),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,ut),t.copyTexImage2D(t.TEXTURE_2D,0,t.RGB8,0,0,w,U,0),ut}function tr(w,U,G,V,Y,ee,oe,b){const T=Cn(oe,b),P=Ut(w,Y);let C=P.m;C=Dn(C,P.w,P.h,1);const I=Lt(ee,C),D=[[-.5,.5],[.5,.5],[-.5,-.5],[.5,-.5]].map(([E,k])=>{const F=_a(I,E,k,0);return[F[0]*.5+.5,F[1]*.5+.5]}),[$,z,B,q]=D,S=new Float32Array([0,V,0,$[0],$[1],0,0,0,B[0],B[1],G,V,0,z[0],z[1],G,V,0,z[0],z[1],0,0,0,B[0],B[1],G,0,0,q[0],q[1]]);t.useProgram(H),At("normal"),t.disable(t.BLEND),t.bindFramebuffer(t.FRAMEBUFFER,U.fbo),t.viewport(0,0,G,V),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),ot=null,t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,T),t.uniform1i(Gt.tex,0),t.uniformMatrix4fv(Gt.mvp,!1,bn(0,G,0,V,-1e4,1e4)),t.drawArrays(t.TRIANGLES,0,6),t.enable(t.BLEND)}function Bt(w,U,G,V,Y){if(!fn||je)return;const ee=gt.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);tr(w,T,oe,b,U,G,V,Y);for(const P of ee)mt.set(P,T);gt.delete(w.id),t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,V,Y)}async function Lr(w,U,G,V,Y,ee,oe,b){X++,t.viewport(0,0,G,V);const T=w.general||{};if(T.clearenabled!==!1){const S=qo(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),rt>=0){const S=Y-rt;nt=S>0&&S<1?S:Math.min(.1,Math.max(.001,S||1/60))}rt=Y;const P=Sa(w,G,V,ee,oe,b);let C=Lt(P.projection,P.view);const I=T.cameraparallax,D=I===!0||I!==null&&typeof I=="object"&&I.value===!0;Be=0,Ae=0;const $=De();if($&&(Pe.x=$.u*2-1,Pe.y=$.v*2-1),!P.perspective&&n.parallax!==!1&&D){const S=(yt,de)=>{const pe=yt!==null&&typeof yt=="object"?yt.value:yt;return typeof pe=="number"&&Number.isFinite(pe)?pe:de},E=S(T.cameraparallaxamount,0),k=S(T.cameraparallaxmouseinfluence,1),F=S(T.cameraparallaxdelay,1),ne=Y-Ze;Ze=Y;const Q=ne>0?1-Math.exp(-ne/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,me=Pe.sx*ce*P.viewW,Ie=Pe.sy*ce*P.viewH,bt=Math.max(Math.abs(me),Math.abs(Ie))/ue,Et=bt>1?1/bt:1;Be=-(me*Et),Ae=-(Ie*Et)}if(!P.perspective&&n.shake!==!1){const S=Vt(T,Y);if(S){const E=S.x*P.viewW*.02,k=S.y*P.viewH*.02;(E!==0||k!==0)&&(C=Lt(C,yn(gn(),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(ne=>ne.visible)&&!F.hasChildren),k=E.filter(F=>(F.effects||[]).some(ne=>(ne.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 Rr(w,U,P,G,V,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||fr(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){gt.has(S.id)&&Bt(S,P,C,G,V);continue}if(!(S.isPostProcess&&!(S.effects||[]).some(E=>E.visible))&&!B.has(S.id)){if(S.isContainer){if(!(S.effects||[]).some(k=>k.visible)){Bt(S,P,C,G,V);continue}if(S.hasChildren){(S.childIds||[]).length>0&&await nr(S,w,U,P,C,G,V,Y);continue}}if(S.particle){if(u)try{await u(S.id,P,C,G,V)}catch(E){o("particle render error: "+(E&&E.message))}continue}Tn(S,P)||await St(S,U,P,C,G,V,Y)}}if(Er(T)&&Y<Ft){const S=Math.max(0,Math.min(1,Y/Ft)),E=1-S*S*(3-2*S);if(E>.002){const k=qo(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,V),t.bindVertexArray(K),dt("pass",Xt),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,qe),t.uniform1i(Te.tex,0),t.uniform4f(Te.color,k[0],k[1],k[2],E),Dt(Te,null),Te.blendPrep!==null&&Te.blendPrep!==void 0&&t.uniform1i(Te.blendPrep,0),t.uniformMatrix4fv(Te.mvp,!1,it),t.drawArrays(t.TRIANGLES,0,6)}}t.bindVertexArray(null),J()}async function Rr(w,U,G,V,Y,ee){mt.clear(),gt.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)){gt.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:bn(0,B,0,q,-1e4,1e4),eye:G.eye,projW:B,projH:q,offX:0,offY:0,viewW:B,viewH:q},k=je,F=D.origin,ne=D.scale,Q=D.angles,ce=D.visible;je={fbo:S,w:B,h:q},D.origin=[B/2,E.projH-q/2,F[2]],D.scale=[Math.sign(ne[0])||1,Math.sign(ne[1])||1,ne[2]],D.angles=[0,0,0],D.visible=!0;try{await St(D,U,E,E.projection,B,q,ee);for(const ue of I)mt.set(ue,S)}catch(ue){o(`composite \u6E90\u5C42 ${C} \u6E32\u67D3\u5931\u8D25: ${ue&&ue.message}`)}finally{je=k,D.origin=F,D.scale=ne,D.angles=Q,D.visible=ce}}t.bindFramebuffer(t.FRAMEBUFFER,null),t.viewport(0,0,V,Y)}}async function nr(w,U,G,V,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=fr(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:V.view,projection:bn(0,T,0,P,-1e4,1e4),eye:V.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),ne=Math.sin(-k);je={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,me=Q.angles,Ie=ce[0]-w.origin[0],bt=ce[1]-w.origin[1],Et=(Ie*F-bt*ne)/S,yt=(Ie*ne+bt*F)/E;Q.origin=[T/2+Et,P/2+yt,ce[2]],Q.scale=[ue[0]/S,ue[1]/E,ue[2]],Q.angles=[me[0],me[1],me[2]-k];try{await St(Q,G,B,q,T,P,b)}finally{Q.origin=ce,Q.scale=ue,Q.angles=me}}}finally{je=null}w.groupTex=z.tex,w.groupW=T,w.groupH=P;try{await St(w,G,V,Y,ee,oe,b)}finally{w.groupTex=null}}async function St(w,U,G,V,Y,ee,oe){const b=!!(w.puppet&&nn),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,st=t.getParameter(t.MAX_TEXTURE_SIZE),at=st>0&&st<4096?Math.min(Ee,st):Ee;let vt=1;Math.max(pe,fe)>at&&(vt=at/Math.max(pe,fe));const et=Math.max(1,Math.round(pe*vt)),Ce=Math.max(1,Math.round(fe*vt));let dn=de;if(i&&et>0&&Ce>0){(i.width!==et||i.height!==Ce)&&(i.width=et,i.height=Ce);const ct=i.getContext("2d");ct&&(ct.clearRect(0,0,et,Ce),ct.drawImage(de,0,0,et,Ce),dn=i)}if(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,dn),t.getError()!==t.NO_ERROR&&i)try{const We=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(We.data.buffer));t.getError()!==t.NO_ERROR;);}catch{}T.width=et,T.height=Ce,T.lastUploaded=de.currentTime,s||(s=!0,o("video tex ready "+et+"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?qe:Ue,C=(!!w.passthrough||!!w.isPostProcess||Jo(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 st=Math.max(64,Math.round(fe*a)),at=Math.max(64,Math.round(Ee*a));st<$&&(S=st),at<z&&(E=at)}}if(q.length===0){b?rn(w,G,V,Y,ee,oe):En(N,P,B,w,G,V,Y,ee,!1,Sn(w,T,oe));return}const k=ie(S,E,"ping"),F=ie(S,E,"pong"),ne=bn(0,S,0,E,-1e4,1e4);if(b)t.useProgram(N),At("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),ot=null,dt("layer"+S+"x"+E,tn(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),Dt(Te,null),Te.blendPrep!==null&&Te.blendPrep!==void 0&&t.uniform1i(Te.blendPrep,0),t.uniformMatrix4fv(Te.mvp,!1,ne),t.drawArrays(t.TRIANGLES,0,6);else if(C)tr(w,k,S,E,G,V,Y,ee);else{t.useProgram(N),At("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),dt("layer"+S+"x"+E,tn(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]),Dt(Te,Sn(w,T,oe)),Te.blendPrep!==null&&Te.blendPrep!==void 0&&t.uniform1i(Te.blendPrep,0),t.uniformMatrix4fv(Te.mvp,!1,ne),t.drawArrays(t.TRIANGLES,0,6)}let Q=k,ce=F;const ue=new Map;let me=!1,Ie=k;const bt=[],Et=new Set;for(const de of q){for(const fe of de.fbos||[])if(!ue.has(fe.name)){const[Ee,st]=ei(fe,S,E),at=fe.unique?w.id+":"+fe.name:fe.name;ue.set(fe.name,ie(Ee,st,at))}const pe=de.materialPasses||[];for(let fe=0;fe<pe.length;fe++)bt.push({eff:de,mp:pe[fe],ov:de.passes&&de.passes[fe]})}const yt=[];for(let de=0;de<bt.length;de++){const{eff:pe,mp:fe,ov:Ee}=bt[de];if(Et.has(pe))continue;const st={...fe.combos||{},...Ee&&Ee.combos||{}},at=fe.textures||[],vt=Ee&&Ee.textures||[],et=[];for(let ve=0;ve<Math.max(at.length,vt.length);ve++)vt[ve]!==void 0&&vt[ve]!==null?et[ve]=vt[ve]:et[ve]=at[ve]!==void 0?at[ve]:null;if(fe.copyCommand){const ve=fe.source?ue.get(fe.source):null,Le=fe.target?ue.get(fe.target):null;ve&&Le&&(t.useProgram(j),At("normal"),t.bindFramebuffer(t.FRAMEBUFFER,Le.fbo),t.viewport(0,0,Le.width,Le.height),t.bindVertexArray(K),dt("pass",Xt),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,ve.tex),t.uniform1i(pt.tex,0),pt.blendPrep!==null&&pt.blendPrep!==void 0&&t.uniform1i(pt.blendPrep,0),t.uniformMatrix4fv(pt.mvp,!1,it),t.drawArrays(t.TRIANGLES,0,6),t.bindFramebuffer(t.FRAMEBUFFER,null));continue}let Ce;try{Ce=await Ne(fe.shader,st,et)}catch(ve){const Le=ve&&ve.message||String(ve);/已缓存/.test(Le)||console.warn("[we-scene] \u8DF3\u8FC7\u6548\u679C\uFF08pass \u7F16\u8BD1\u5931\u8D25\uFF09:",fe.shader,Le),Et.add(pe);continue}const dn=Ce.prog,ct=Ce.uni;Ce.fragGlsl&&yt.push(Ce.fragGlsl);let We,Ln;fe.target?(me||(Ie=Q,me=!0),We=ue.get(fe.target)||Q,Ln=Ie):(me=!1,We=ce,Ln=Q),t.useProgram(dn),At(fe.blending||"normal"),t.bindFramebuffer(t.FRAMEBUFFER,We.fbo),t.viewport(0,0,We.width,We.height),t.bindVertexArray(K);const wo=!Ce.ndcDirect;wo?dt("passPx"+We.width+"x"+We.height,tn(We.width,We.height)):dt("pass",Xt);const As=wo?Uo(bn(0,We.width,0,We.height,-1e4,1e4)):it,kr=fe.textures||[],Ts=Math.max(kr.length,8),Mo=new Map,Ss=new Set;for(let ve=0;ve<Ts;ve++){let Le=ve<kr.length?kr[ve]:null;Ee&&Ee.textures&&Ee.textures[ve]!==void 0&&Ee.textures[ve]!==null&&(Le=Ee.textures[ve]);for(const kn of fe.binds||[])kn.index===ve&&(Le=kn.name);let Pt;if(ve===0&&(Le==null||Le===""))Pt=Ln;else{if((Le==null||Le==="")&&Ce.samplerDefaults){const kn=Ce.samplerDefaults.get(ve);kn&&(Le=kn)}Pt=er(Le,Ln,ue,U)}Le==="previous"&&(Pt=Ln),Pt===null&&(Pt={glTex:qe,width:1,height:1,tex:qe});const Rn=Pt.fbo?Pt:{tex:Pt.glTex||qe,width:Pt.width||1,height:Pt.height||1};t.activeTexture(t.TEXTURE0+ve),t.bindTexture(t.TEXTURE_2D,Rn.tex),Ss.add(ve),Mo.set(ve,[Rn.width,Rn.height,Rn.width,Rn.height])}An(ct,w,oe,G.projW,G.projH,As,ne,it,Mo,ne,G),Ht(ct,Pr(Jn({...fe.constants||{},...Ee&&Ee.constantshadervalues||{}},(w.id||w.name||"?")+"|"+(fe.shader||"?")+"|"+de,oe,w),(w.id||w.name||"?")+"|"+(fe.shader||"?")+"|"+de,oe),Ce.matMeta),Qn(ct),t.drawArrays(t.TRIANGLES,0,6),fe.target||(ce=Q,Q=We)}if(w.isContainer&&!w.groupTex&&!C&&w.containerAlphaMeaningful===void 0){let de=!1;for(const pe of yt){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){rn(w,G,V,Y,ee,oe,Q.tex);return}En(j,Q.tex,[1,1,1,1],w,G,V,Y,ee,!!w.isContainer&&!w.groupTex&&!C,null,null)}return{gl:t,render:Lr,getFBO:ie,getEffectProgram:Ne,progCache:Z,shaderResolver:r,whiteTex:qe,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){fn=!!w},compositeStats:function(){const w=[],U=new Uint8Array(4);for(const[G,V]of mt){let Y=null;try{t.bindFramebuffer(t.FRAMEBUFFER,V.fbo),t.readPixels(V.w>>1,V.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:V.w,h:V.h,center:Y})}return t.bindFramebuffer(t.FRAMEBUFFER,null),w},setPuppetRenderer:function(w){nn=w},setAudioProvider:p,setPointerProvider:he,getParallaxOffset:function(){return{x:Be,y:Ae}},dispose:function(){try{const w=t.getExtension("WEBGL_lose_context");w&&w.loseContext()}catch{}}}}const qa=Object.freeze(Object.defineProperty({__proto__:null,ALIGN:Go,XRAY_IDLE_SCREEN_UV:On,XRAY_SIZE_FALLBACK:ni,applyColorBlendCPU:Ha,collectGroupDescendantIds:fr,colorBlendPlan:Yr,constantFallback:ri,createRenderer:Ya,effectFboSize:ei,layerWantsPreserveBackdrop:Jo,makeTexture:Xr,makeTextureMip:$a,puppetAnimMargin:Qo,rewriteXrayFragScale:ti,xrayShouldParkPointer:qr,xrayUvScale:Xa},Symbol.toStringTag,{value:"Module"}));function Za(e=256,n=8){const t=e/n,r=oi(1337),o=oi(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,W=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(W*255),a[X+2]=0,a[X+3]=255}}return a}function oi(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 Ka=Object.freeze(Object.defineProperty({__proto__:null,generateNoiseTexture:Za},Symbol.toStringTag,{value:"Module"})),wt=Math.PI*2;function Re(e,n){return e==null?Math.random():n==null?e:e+Math.random()*(n-e)}function ii(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 si(e){return e==null?null:typeof e=="number"?[e,e,e]:be(e)}function re(e,n){if(e==null)return n;if(typeof e=="object")return re(e.value,n);const t=Number(e);return Number.isFinite(t)?t:n}function Zr(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 Zt(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(Zt(r,o,i),Zt(r+1,o,i),u),y=p(Zt(r,o+1,i),Zt(r+1,o+1,i),u),x=p(Zt(r,o,i+1),Zt(r+1,o,i+1),u),m=p(Zt(r,o+1,i+1),Zt(r+1,o+1,i+1),u);return p(p(d,y,l),p(x,m,l),f)}function Kr(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 Qr(e,n,t,r){return[Kr(e,n,t,r)*2-1,Kr(e+31.7,n+11.3,t+57.1,r)*2-1,Kr(e+73.9,n+92.1,t+13.7,r)*2-1]}function Ja(e){const n=`#version 300 es
|
|
355
|
+
}`,Rb=`#version 300 es
|
|
356
|
+
precision highp float;
|
|
357
|
+
in vec2 v_UV;
|
|
358
|
+
uniform sampler2D u_Tex;
|
|
359
|
+
uniform vec2 u_Texel; // 1/width, 1/height
|
|
360
|
+
out vec4 fragColor;
|
|
361
|
+
void main() {
|
|
362
|
+
const float SPAN_MAX = 8.0;
|
|
363
|
+
const float REDUCE_MUL = 1.0 / 8.0;
|
|
364
|
+
const float REDUCE_MIN = 1.0 / 128.0;
|
|
365
|
+
const vec3 LUMA = vec3(0.299, 0.587, 0.114);
|
|
366
|
+
vec3 rgbNW = texture(u_Tex, v_UV + vec2(-1.0, -1.0) * u_Texel).rgb;
|
|
367
|
+
vec3 rgbNE = texture(u_Tex, v_UV + vec2( 1.0, -1.0) * u_Texel).rgb;
|
|
368
|
+
vec3 rgbSW = texture(u_Tex, v_UV + vec2(-1.0, 1.0) * u_Texel).rgb;
|
|
369
|
+
vec3 rgbSE = texture(u_Tex, v_UV + vec2( 1.0, 1.0) * u_Texel).rgb;
|
|
370
|
+
vec3 rgbM = texture(u_Tex, v_UV).rgb;
|
|
371
|
+
float lumaNW = dot(rgbNW, LUMA);
|
|
372
|
+
float lumaNE = dot(rgbNE, LUMA);
|
|
373
|
+
float lumaSW = dot(rgbSW, LUMA);
|
|
374
|
+
float lumaSE = dot(rgbSE, LUMA);
|
|
375
|
+
float lumaM = dot(rgbM, LUMA);
|
|
376
|
+
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
|
|
377
|
+
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
|
|
378
|
+
vec2 dir = vec2(
|
|
379
|
+
-((lumaNW + lumaNE) - (lumaSW + lumaSE)),
|
|
380
|
+
((lumaNW + lumaSW) - (lumaNE + lumaSE)));
|
|
381
|
+
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * REDUCE_MUL), REDUCE_MIN);
|
|
382
|
+
float rcpDirMin = 1.0 / (min(abs(dir.x), abs(dir.y)) + dirReduce);
|
|
383
|
+
dir = min(vec2(SPAN_MAX), max(vec2(-SPAN_MAX), dir * rcpDirMin)) * u_Texel;
|
|
384
|
+
vec3 rgbA = 0.5 * (
|
|
385
|
+
texture(u_Tex, v_UV + dir * (1.0 / 3.0 - 0.5)).rgb +
|
|
386
|
+
texture(u_Tex, v_UV + dir * (2.0 / 3.0 - 0.5)).rgb);
|
|
387
|
+
vec3 rgbB = rgbA * 0.5 + 0.25 * (
|
|
388
|
+
texture(u_Tex, v_UV + dir * -0.5).rgb +
|
|
389
|
+
texture(u_Tex, v_UV + dir * 0.5).rgb);
|
|
390
|
+
float lumaB = dot(rgbB, LUMA);
|
|
391
|
+
fragColor = vec4((lumaB < lumaMin || lumaB > lumaMax) ? rgbA : rgbB, 1.0);
|
|
392
|
+
}`;function Bb(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 Fb(){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 Db(){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 Nb={5126:"float",35664:"vec2",35665:"vec3",35666:"vec4",5124:"int",35667:"ivec2",35668:"ivec3",35669:"ivec4",35670:"bool",35676:"mat4",35675:"mat3"};function Tr(t,e,n){const r=Dh(t,t.VERTEX_SHADER,e),i=Dh(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 Dh(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 ho(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 Tl(t,e,n,r,i=null,s=null){const a=t.createTexture();t.bindTexture(t.TEXTURE_2D,a);const o=s&&s.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE;return t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,o),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,o),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)),a}function Lb(t,e,n=!1,r=null){const i=t.createTexture();t.bindTexture(t.TEXTURE_2D,i);const s=r&&r.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE;t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,s),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,s),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 a=e[0];if(a.bitmap)t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,a.bitmap);else if(n&&a.rgba){const o=a.width*a.height,c=new Uint8Array(o*2);for(let l=0;l<o;l++)c[l*2]=a.rgba[l*4+3],c[l*2+1]=a.rgba[l*4];const u=t.getParameter(t.UNPACK_ALIGNMENT);t.pixelStorei(t.UNPACK_ALIGNMENT,1),t.texImage2D(t.TEXTURE_2D,0,t.RG8,a.width,a.height,0,t.RG,t.UNSIGNED_BYTE,c),t.pixelStorei(t.UNPACK_ALIGNMENT,u)}else t.texImage2D(t.TEXTURE_2D,0,t.RGBA,a.width,a.height,0,t.RGBA,t.UNSIGNED_BYTE,a.rgba);return t.generateMipmap(t.TEXTURE_2D),i}function Ub(t,e,n,r=null){const i=t.createTexture();t.bindTexture(t.TEXTURE_2D,i);const s=r&&r.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE;t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,s),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,s),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR_MIPMAP_LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR);for(let a=0;a<e.length;a++){const o=e[a];t.compressedTexImage2D(t.TEXTURE_2D,a,n,o.width,o.height,0,o.data)}return t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAX_LEVEL,Math.max(0,e.length-1)),i}function Ob(t,e){const n=Number(e);if(n===7){const r=t.getExtension("WEBGL_compressed_texture_s3tc");return r?{internalFormat:r.COMPRESSED_RGBA_S3TC_DXT1_EXT,blockBytes:8}:null}if(n===6){const r=t.getExtension("WEBGL_compressed_texture_s3tc");return r?{internalFormat:r.COMPRESSED_RGBA_S3TC_DXT3_EXT,blockBytes:16}:null}if(n===4){const r=t.getExtension("WEBGL_compressed_texture_s3tc");return r?{internalFormat:r.COMPRESSED_RGBA_S3TC_DXT5_EXT,blockBytes:16}:null}if(n===12){const r=t.getExtension("WEBGL_compressed_texture_bptc");return r?{internalFormat:r.COMPRESSED_RGBA_BPTC_UNORM_EXT,blockBytes:16}:null}return n===5?{internalFormat:t.COMPRESSED_RGBA8_ETC2_EAC,blockBytes:16}:n===3?{internalFormat:t.COMPRESSED_RGB8_ETC2,blockBytes:8}:null}function zb(t,e,n=null){const r=t.createTexture();t.bindTexture(t.TEXTURE_2D,r);const i=n&&n.wrap==="repeat"?t.REPEAT:t.CLAMP_TO_EDGE;t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,i),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,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);const s=e[0],a=t.getParameter(t.UNPACK_ALIGNMENT);return t.pixelStorei(t.UNPACK_ALIGNMENT,1),t.texImage2D(t.TEXTURE_2D,0,t.R8,s.width,s.height,0,t.RED,t.UNSIGNED_BYTE,s.data),t.pixelStorei(t.UNPACK_ALIGNMENT,a),t.generateMipmap(t.TEXTURE_2D),r}function Sl(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 Hb(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=Sl(t,e,n,r,s)-i;if(Math.abs(u)<1e-6)return s;const l=1-s,d=3*l*l*(e-t)+6*l*s*(n-e)+3*s*s*(r-n);if(Math.abs(d)<1e-9)break;const f=s-u/d;if(f<0||f>1||!Number.isFinite(f))break;s=f}let a=0,o=1;for(let c=0;c<40;c++)s=(a+o)/2,Sl(t,e,n,r,s)<i?a=s:o=s;return s}function mo(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 k=t[0],_=t[t.length-1],I=n.length-_.frame;if(I>1e-9&&e>_.frame&&e<=n.length)return mo([{frame:0,value:_.value,front:_.front,back:_.back},{frame:I,value:k.value,front:k.front,back:k.back}],e-_.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 k=i+s>>1;t[k].frame<=e?i=k:s=k}const a=t[i],o=t[s],c=a.frame,u=o.frame,l=Number(a.value)||0,d=Number(o.value)||0,f=u-c;if(f<=0)return d;const h=a.front,p=o.back,m=f/3,g=!!(h&&h.enabled),y=!!(p&&p.enabled),w=g?Math.abs(Number(h.x)||0):1,A=y?Math.abs(Number(p.x)||0):1,b=c+Math.min(w,1.5)*m,v=u-Math.min(A,1.5)*m,x=g?l+(Number(h.y)||0):l+(d-l)/3,P=y?d+(Number(p.y)||0):d-(d-l)/3,S=Hb(c,b,v,u,e);return Sl(l,x,P,d,S)}function Nh(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 Vb(t){return Array.isArray(t)?t:typeof t=="string"?t.trim().split(/\s+/).map(Number):Number.isFinite(t)?[t]:[]}function Lh(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 d of t){const f=l*a+d.frame;(s?f>e&&f<=n:f>=n&&f<e)&&o.push({at:f,e:d})}}else{const c=a*2,u=Math.floor(Math.min(e,n)/c),l=Math.floor(Math.max(e,n)/c);for(let d=u;d<=l;d++)for(const f of t){const h=d*c+f.frame,p=d*c+2*a-f.frame;for(const m of h===p?[h]:[h,p])(s?m>e&&m<=n:m>=n&&m<e)&&o.push({at:m,e:f})}}return o.sort((c,u)=>s?c.at-u.at:u.at-c.at),o.map(c=>c.e)}function Wb(t,e,n){const r=Lh(t._events,e,n,t.frameCount||1,t.mode);for(const i of r)t._eventQueue.push(i)}function Uh(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 Pl(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=[],d=e.parent&&typeof e.parent.key=="string"?e.parent.key:null,f=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:d,childKeys:f,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 y of l)try{y()}catch{}}}else p.frame<0&&(p.frame=0,p._playing=!1);Wb(p,g,p.frame)},takeEvents(){if(!p._eventQueue.length)return[];const m=p._eventQueue.slice();return p._eventQueue.length=0,m},value(){const m=Nh(p.parent?p.parent.frame:p.frame,r,i),g=o?{length:r}:void 0;if(c.length===1)return mo(c[0],m,g);const y=[];for(const w of c)y.push(mo(w,m,g));return y},applyTo(m){const g=p.value();if(!a)return g;const y=Vb(m);return Array.isArray(g)?g.map((w,A)=>w+(Number(y[A])||0)):g+(Number(y[0])||0)}};return p}function jb(){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 qb=Object.freeze(Object.defineProperty({__proto__:null,createAnimation:Pl,createNeutralAnimation:jb,crossedEvents:Lh,linkAnimations:Uh,sampleChannel:mo,wrapFrame:Nh},Symbol.toStringTag,{value:"Module"}));function Xb(t,e,n,r){const i=s=>po(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)=>Oh(s,a));case 12:return i((s,a)=>$b(s,a));case 13:return i((s,a)=>Oh(a,s));case 14:return i((s,a)=>[ms(s[0],a[0]),ms(s[1],a[1]),ms(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)=>[ms(s[0],a[0])<.5?0:1,ms(s[1],a[1])<.5?0:1,ms(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)=>Gb(s,a));case 27:return i((s,a)=>Qb(s,a));case 28:return i((s,a)=>Yb(s,a));case 29:return i((s,a)=>Kb(s,a));case 30:{const s=Math.max(e[0],Math.max(e[1],e[2]));return po(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 po(e,[e[0]+e[0]*n[0],e[1]+e[1]*n[1],e[2]+e[2]*n[2]],r);default:return po(e,n,r)}}function po(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 Oh(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 $b(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 ms(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 $r(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 _l(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 go(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[_l(n,e,t[0]+1/3),_l(n,e,t[0]),_l(n,e,t[0]-1/3)]}function Gb(t,e){const n=$r(t);return go([$r(e)[0],n[1],n[2]])}function Qb(t,e){const n=$r(t);return go([n[0],$r(e)[1],n[2]])}function Yb(t,e){const n=$r(e);return go([n[0],n[1],$r(t)[2]])}function Kb(t,e){const n=$r(t);return go([n[0],n[1],$r(e)[2]])}function zh(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 Hh(t){for(const e of t||[]){if(typeof e!="string")continue;const n=e.match(/\bfloat\s+alpha\s*=\s*([^;]+);/);if(n&&!/^\s*scene\s*\.\s*a\s*$/.test(n[1]))return!0;if(e.includes("BlendTransparency(")){if(/ApplyBlending\s*\([^;]*wave\.a/.test(e)||/vec4\s*\(\s*u_color\s*,\s*u_brightness\s*\*\s*smoothed\s*\)/.test(e))return!0;continue}}return!1}function Vh(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 Wh(t){return!!(t&&t.isContainer&&!t.hasChildren)}function yo(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),yo(i,e,n))}return n}function El(t){const e=Bh[t]||"translucent";return{mode:e,prep:xb[e]||0}}function jh(t,e){const n=Number(t);return Number.isFinite(n)&&n!==0?n:e==="additive"?9:Number.isFinite(n)?n:0}function Ml(t){const e=Number(t);return!Number.isFinite(e)||e===0?!1:!Bh[e]}function Zb(t,e,n,r){if(Ml(t))return Xb(t,[e,e,e],[n,n,n],r)[0];const{mode:i,prep:s}=El(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 qh(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 Xh(t,e,n){const r=Math.max(1,Math.round(Math.abs(t)||1)),i=Math.max(1,Math.round(Math.abs(e)||1)),s=Math.max(1,Math.floor(Number(n)||1)),a=Math.min(1,s/r,s/i);return{width:Math.max(1,Math.round(r*a)),height:Math.max(1,Math.round(i*a)),k:a}}function Cl(t,e){if(!t)return[1,1,1];const n=e||[0,0,0];return[Math.min(1,Math.max(.001,Number(n[0])||0)*Math.PI),Math.min(1,Math.max(.001,Number(n[1])||0)*Math.PI),Math.min(1,Math.max(.001,Number(n[2])||0)*Math.PI)]}function $h(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=ho(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 Jb(t){const e=Number(t);return!Number.isFinite(e)||e<.001?999:1/e}const ea=-1;function Il(t,e){return!!e&&!t}const ew="mix(999.0, 1.0 / max(g_PointerScale, 0.001), step(0.001, g_PointerScale))";function Gh(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;
|
|
393
|
+
void main(`));const i=e?/unprojectedUVs\s*\*=\s*v_PointerScale\s*\*/:/unprojectedUVs\s*\*=\s*g_PointerScale\s*\*/;return r.replace(i,"unprojectedUVs *= "+ew+" *")}const Qh=1;function Yh(t,e){return t==="g_PointerScale"?Qh:e}function Kh(t,e,n,r,i){const s=e&&e[0]||1,a=e&&e[1]||1;if(!(Math.abs((t&&t[0])*s)<1||Math.abs((t&&t[1])*a)<1))return null;const c=i||1;return[n/c,r/c]}function Zh(t,e,n,r,i){const s=Array.isArray(t)&&t.length>=2?t:[1,1],a=Array.isArray(e)&&e.length>=2?e:[1,1,1],o=i||1,c=Kh(s,a,n,r,o);return c?{size:c,scale:[(Math.sign(a[0])||1)*o,(Math.sign(a[1])||1)*o,a[2]]}:{size:s,scale:[a[0]*o,a[1]*o,a[2]]}}function tw(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,d="off",f=!0,h=null,p=!1;function m(){return d==="msaa2"?2:d==="msaa4"?4:0}function g(){n.bindFramebuffer(n.FRAMEBUFFER,h?h.fbo:null)}function y(M,j){const te=m();if(!te||!(M>0)||!(j>0)){h&&w();return}if(h&&h.width===M&&h.height===j&&h.samples===te)return;w();let Z=te;try{const ye=n.getInternalformatParameter(n.RENDERBUFFER,n.RGBA8,n.SAMPLES);let fe=0;if(ye&&ye.length)for(const se of ye)se>fe&&(fe=se);fe>=te||(Z=0)}catch{Z=0}if(!Z){p||(p=!0,i(`msaa: \u9A71\u52A8\u4E0D\u652F\u6301 ${te}x \u591A\u91CD\u91C7\u6837\uFF0C\u56DE\u9000 off`)),d="off";return}const ne=n.createFramebuffer(),de=n.createRenderbuffer();n.bindRenderbuffer(n.RENDERBUFFER,de),n.renderbufferStorageMultisample(n.RENDERBUFFER,Z,n.RGBA8,M,j),n.bindFramebuffer(n.FRAMEBUFFER,ne),n.framebufferRenderbuffer(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.RENDERBUFFER,de);const me=n.checkFramebufferStatus(n.FRAMEBUFFER)===n.FRAMEBUFFER_COMPLETE;if(n.bindRenderbuffer(n.RENDERBUFFER,null),n.bindFramebuffer(n.FRAMEBUFFER,null),!me){n.deleteFramebuffer(ne),n.deleteRenderbuffer(de),p||(p=!0,i(`msaa: FBO \u4E0D\u5B8C\u6574\uFF08${te}x ${M}x${j}\uFF09\uFF0C\u56DE\u9000 off`)),d="off";return}h={fbo:ne,rbo:de,width:M,height:j,samples:Z},p||(p=!0,i(`msaa: on ${Z}x ${M}x${j}`))}function w(){h&&(n.deleteFramebuffer(h.fbo),n.deleteRenderbuffer(h.rbo),h=null)}let A=!1;function b(M,j){if(!h)return;const te=Pt(M,j,"msaaResolve");if(n.bindFramebuffer(n.READ_FRAMEBUFFER,h.fbo),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,te.fbo),n.blitFramebuffer(0,0,M,j,0,0,M,j,n.COLOR_BUFFER_BIT,n.NEAREST),n.bindFramebuffer(n.READ_FRAMEBUFFER,null),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),n.useProgram(De),n.disable(n.BLEND),n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,M,j),n.bindVertexArray(st),rn("pass",ir),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,te.tex),n.uniform1i(Ze.tex,0),n.uniform4f(Ze.color,1,1,1,1),sr(Ze,null),Ze.blendPrep!==null&&Ze.blendPrep!==void 0&&n.uniform1i(Ze.blendPrep,0),n.uniformMatrix4fv(Ze.mvp,!1,sn),n.drawArrays(n.TRIANGLES,0,6),!A){A=!0;const Z=n.getError();Z!==n.NO_ERROR&&i(`msaa resolve: glErr=${Z}`)}}let v=null,x=null,P=null;const S=[["g_AudioSpectrum16Left","left16"],["g_AudioSpectrum16Right","right16"],["g_AudioSpectrum32Left","left32"],["g_AudioSpectrum32Right","right32"],["g_AudioSpectrum64Left","left64"],["g_AudioSpectrum64Right","right64"]];function k(M){P=M||null}let _=null,I=null,B=null,V=null,O=null,U=null,W=null,ie=null;const we=new Map,Y=new Map,oe=new Set;let he=null;const Ae={total:0,ok:0,failed:0};function Pe(M,j){_=typeof M=="function"?M:null,I=j&&j.userProperties||null,B=j&&j.audioViews||null,V=j&&j.shared||null,O=j&&j.inputView||null,U=j&&j.timers||null,W=j&&j.storage||null,ie=j&&typeof j.onSandbox=="function"?j.onSandbox:null,he=j&&Array.isArray(j.animEventQueue)?j.animEventQueue:null,we.clear(),Y.clear(),oe.clear()}let Ce=!1,Le=!1,Ne=0;typeof e.bloomDebugFrames=="number"&&e.bloomDebugFrames;const De=Tr(n,hs,Mb),Re=Tr(n,hs,Cb),Fe=Tr(n,hs,Ib),Xe=Tr(n,Tb,Sb),$e=Tr(n,Pb,_b),Ye=Tr(n,hs,Eb),nt=Tr(n,hs,kb),dn=Tr(n,hs,Rb),st=n.createVertexArray();n.bindVertexArray(st);const gt=n.createBuffer();n.bindBuffer(n.ARRAY_BUFFER,gt),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 Vt=new Map;let xn=1;function Pt(M,j,te){const Z=(te||"")+"|"+M+"x"+j;if(Vt.has(Z)){const ye=Vt.get(Z);return ye.stamp=xn,ye}const ne=n.createFramebuffer(),de=n.createTexture();n.bindTexture(n.TEXTURE_2D,de),n.texImage2D(n.TEXTURE_2D,0,n.RGBA,M,j,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,ne),n.framebufferTexture2D(n.FRAMEBUFFER,n.COLOR_ATTACHMENT0,n.TEXTURE_2D,de,0),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.bindFramebuffer(n.FRAMEBUFFER,null);const me={fbo:ne,tex:de,width:M,height:j,stamp:xn};return Vt.set(Z,me),me}function xt(){for(const[M,j]of Vt)j.stamp!==xn&&(j.fbo&&n.deleteFramebuffer(j.fbo),j.tex&&n.deleteTexture(j.tex),Vt.delete(M))}const tn=new Map,Mt=new Map,Pi=new Map;function nn(M){const j={},te=/uniform\s+[A-Za-z0-9_]+\s+([A-Za-z_][A-Za-z0-9_]*)[^;]*;\s*\/\/([^\n]*)/g;let Z;for(;(Z=te.exec(M))!==null;){const ne=Z[1],de=Z[2],me=/"material"\s*:\s*"([^"]+)"/.exec(de);if(!me)continue;const ye=/"default"\s*:\s*("(?:[^"]*)"|-?\d+(?:\.\d+)?)/.exec(de);j[me[1]]={uniform:ne,default:ye?tr(ye[1]):void 0}}return j}function _i(M){const j=new Map,te=/uniform\s+sampler2D\s+g_Texture(\d+)\s*;\s*\/\/([^\n]*)/g;let Z;for(;(Z=te.exec(M))!==null;){const ne=Number(Z[1]),de=/"default"\s*:\s*"([^"]+)"/.exec(Z[2]);de&&de[1]&&j.set(ne,de[1])}return j}function ct(M){const j=[],te=/uniform\s+sampler2D\s+(g_Texture(\d+))[^;]*;\s*\/\/([^\n]*)/g;let Z;for(;(Z=te.exec(M))!==null;){const ne=/"combo"\s*:\s*"([^"]+)"/.exec(Z[3]);ne&&j.push({slot:Number(Z[2]),name:Z[1],combo:ne[1]})}return j}function tr(M){if(M.startsWith('"'))return M.slice(1,-1);const j=Number(M);return Number.isFinite(j)?j:void 0}async function pa(M,j,te){let Z=Pi.get(M);if(Z===void 0){const me=await r("shaders/"+M+".frag")||"",ye=await r("shaders/"+M+".vert")||"";Z={frag:me,vert:ye,texCombos:ct(me)},Pi.set(M,Z)}const ne={...j};for(const me of Z.texCombos)te&&te[me.slot]&&ne[me.combo]===void 0&&(ne[me.combo]=1);const de=M+"|"+JSON.stringify(ne);if(tn.has(de)){const me=tn.get(de);if(me===null)throw new Error("shader="+M+" \u7F16\u8BD1\u5931\u8D25\uFF08\u5DF2\u7F13\u5B58\uFF09");return me}for(let me=0;me<4;me++){const ye=new Set,fe=xe=>Mt.has(xe)?Mt.get(xe):(ye.add(xe),null),se=Gh(Ih(Z.frag,"frag",ne,fe,Z.vert)),_e=Ih(Z.vert,"vert",ne,fe,Z.frag);if(ye.size===0){let xe;try{xe=Tr(n,_e,se)}catch(L){throw tn.set(de,null),new Error("shader="+M+" "+(L&&L.message))}const T=new Map,C=n.getProgramParameter(xe,n.ACTIVE_UNIFORMS);for(let L=0;L<C;L++){const X=n.getActiveUniform(xe,L),Q=X.name.replace(/\[0\]$/,"");T.set(Q,{loc:n.getUniformLocation(xe,X.name),type:Nb[X.type]||"unknown",size:X.size})}const R={...nn(Z.vert),...nn(Z.frag)},F=/gl_Position\s*=\s*vec4\s*\(\s*a_Position/.test(Z.vert)&&!/[aA]_Position[\s\S]{0,40}mul\s*\(/.test(Z.vert),$=new Map([..._i(Z.vert),..._i(Z.frag)]),H={prog:xe,uni:T,matMeta:R,samplerDefaults:$,fragGlsl:se,vertGlsl:_e,ndcDirect:F};return tn.set(de,H),H}await Promise.all(Array.from(ye).map(async xe=>{Mt.set(xe,await r("shaders/"+xe)||"")}))}throw new Error("include \u89E3\u6790\u5931\u8D25: "+M)}const hn=Tl(n,new Uint8Array([255,255,255,255]),1,1),Cr=Tl(n,new Uint8Array([0,0,0,0]),1,1);let lt=null;function Un(M){lt=M||null}function kn(){if(!lt)return null;const M=typeof lt=="function"?lt():lt;return M&&M.state?M.state:M}const nr=_p(e),yt=nr==="mirage"?{x:.5,y:.5,sx:.5,sy:.5}:{x:0,y:0,sx:0,sy:0},Oe={mode:nr,mx:0,my:0,amount:0,cx:0,cy:0,lx:0,ly:0,active:!1};let Ke=0,Ei=null,ni=0,On=null,Ir=0,Rr=0,ga=1/60,Ve=-1;const ya=typeof e.fadeDuration=="number"&&e.fadeDuration>=0?e.fadeDuration:1,ba=(M,j)=>{const te=M!==null&&typeof M=="object"?M.value:M;return te===!0||te===1?!0:te===!1||te===0?!1:j},bs=(M,j)=>{const te=M!==null&&typeof M=="object"?M.value:M;return typeof te=="number"&&Number.isFinite(te)?te:j},ws=M=>e.fade===!0&&ba(M.camerafade,!1);function wa(M,j){if(!ba(M.camerashake,!1))return null;const te=bs(M.camerashakeamplitude,0);if(te===0)return null;const Z=Math.max(0,Math.min(1,bs(M.camerashakeroughness,0))),ne=bs(M.camerashakespeed,1),de=j*ne,me=Math.sin(de*2.1)*Math.cos(de*.7),ye=Math.cos(de*1.7)*Math.sin(de*.9),fe=Math.sin(de*11.3)*Math.cos(de*7.1),se=Math.cos(de*9.7)*Math.sin(de*13.1);return{x:(me*(1-Z)+fe*Z)*te,y:(ye*(1-Z)+se*Z)*te}}function ri(){const M=new Date;return(M.getHours()*3600+M.getMinutes()*60+M.getSeconds())/86400}function rt(M,j,te){const Z=M.get(j);Z&&Z.loc!==null&&te(Z.loc,Z.type,Z.size)}function Mi(M){if(typeof M=="number")return[M,M,M,M];const j=String(M).trim().split(/[\s,]+/).map(Number);return[j[0]||0,j[1]||0,j[2]||0,j[3]||0]}function va(M,j,te){const Z=M.get(j);if(!Z||Z.loc===null)return;const ne=te&&te.value!==void 0?te.value:te,de=Mi(ne);switch(Z.type){case"float":n.uniform1f(Z.loc,de[0]);break;case"int":case"bool":n.uniform1i(Z.loc,ne===!0||ne===1?1:Math.round(de[0]));break;case"vec2":n.uniform2f(Z.loc,de[0],de[1]);break;case"vec3":n.uniform3f(Z.loc,de[0],de[1],de[2]);break;case"vec4":n.uniform4f(Z.loc,de[0],de[1],de[2],de[3]);break;case"mat4":n.uniformMatrix4fv(Z.loc,!1,sn);break;case"mat3":n.uniformMatrix3fv(Z.loc,!1,Fi);break}}const Aa=()=>new Float32Array([1,0,0,0,1,0,0,0,1]);function Ci(M,j,te,Z,ne,de,me,ye,fe,se,_e,xe){if(rt(M,"g_Time",L=>n.uniform1f(L,te)),rt(M,"g_Daytime",L=>n.uniform1f(L,ri())),rt(M,"g_ModelViewProjectionMatrix",L=>n.uniformMatrix4fv(L,!1,de)),rt(M,"g_ModelMatrix",L=>n.uniformMatrix4fv(L,!1,me)),rt(M,"g_ViewProjectionMatrix",L=>n.uniformMatrix4fv(L,!1,ye)),xe&&rt(M,"g_EffectModelViewProjectionMatrix",L=>n.uniformMatrix4fv(L,!1,xe)),M.get("g_ModelViewProjectionMatrixInverse")){let L=null;for(const[Q,re]of fe)Q===0&&(L=re);const X=L&&L[0]>0&&L[1]>0?$o(Lr(Nr(),L[0]/2,L[1]/2,1)):sn;rt(M,"g_ModelViewProjectionMatrixInverse",Q=>n.uniformMatrix4fv(Q,!1,X))}rt(M,"g_Brightness",L=>n.uniform1f(L,j.brightness)),rt(M,"g_UserAlpha",L=>n.uniform1f(L,j.alpha)),rt(M,"g_Alpha",L=>n.uniform1f(L,j.alpha)),rt(M,"g_Color",L=>n.uniform3f(L,j.color[0],j.color[1],j.color[2])),rt(M,"g_Color4",L=>n.uniform4f(L,j.color[0],j.color[1],j.color[2],1)),rt(M,"g_CompositeColor",L=>n.uniform3f(L,j.color[0],j.color[1],j.color[2])),rt(M,"g_TexelSize",L=>n.uniform2f(L,1/Z,1/ne)),rt(M,"g_TexelSizeHalf",L=>n.uniform2f(L,.5/Z,.5/ne)),rt(M,"g_TextureReductionScale",L=>n.uniform1f(L,1));const T=kn(),C=Il(!!(T&&T.has),!!M.get("g_PointerScale"));let R=C?ea:T?T.u:.5,F=C?ea:T?T.v:.5,$=C?ea:T?T.lastU:.5,H=C?ea:T?T.lastV:.5;if(_e&&j&&j.size&&j.size[0]>0&&j.size[1]>0){const L=Math.abs(j.size[0]*j.scale[0]),X=Math.abs(j.size[1]*j.scale[1]);if(L>0&&X>0){const Q=j.origin[0]-L/2,re=_e.projH-j.origin[1]-X/2,q=D=>(_e.offX+D*_e.viewW-Q)/L,K=D=>(_e.offY+D*_e.viewH-re)/X;R=q(R),F=K(F),$=q($),H=K(H)}}rt(M,"g_PointerPosition",L=>n.uniform2f(L,R,F)),rt(M,"g_PointerPositionLast",L=>n.uniform2f(L,$,H)),rt(M,"g_PointerState",L=>n.uniform4f(L,R,F,T&&T.leftDown?1:0,0)),rt(M,"g_ParallaxPosition",L=>{Oe.mode==="mirage"?n.uniform2f(L,yt.sx,yt.sy):n.uniform2f(L,yt.sx*.5+.5,yt.sy*.5+.5)}),rt(M,"g_Frametime",L=>n.uniform1f(L,ga)),M.get("g_EffectTextureProjectionMatrixInverse")&&rt(M,"g_EffectTextureProjectionMatrixInverse",L=>n.uniformMatrix4fv(L,!1,sn));for(let L=0;L<8;L++)rt(M,"g_Texture"+L,X=>n.uniform1i(X,L));for(const[L,X]of fe)rt(M,"g_Texture"+L+"Resolution",Q=>n.uniform4f(Q,X[0],X[1],X[2],X[3]));if(P){const L=typeof P=="function"?P():P;if(L)for(const[X,Q]of S){const re=L[Q];re&&rt(M,X,q=>n.uniform1fv(q,re))}}}function Wo(M,j,te){for(const[Z,ne]of Object.entries(j||{})){const de=te&&te[Z];de&&va(M,de.uniform,ne)}for(const[Z,ne]of Object.entries(te||{}))if(!j||!(Z in j)){const de=Yh(ne.uniform,ne.default);de!==void 0&&va(M,ne.uniform,de)}}function zn(M){const j=kn();Il(!!(j&&j.has),!!M.get("g_PointerScale"))&&rt(M,"g_PointerScale",te=>n.uniform1f(te,0))}function Ii(M,j){return j?typeof M=="number"&&Number.isFinite(M):!!M&&typeof M=="object"&&Number.isFinite(Number(M.x))&&Number.isFinite(Number(M.y))}let vs=[1,1,1],xa=1920,rr=1080;function Ct(M,j,te,Z){if(!M)return M;let ne=!1;for(const me of Object.values(M))if(me!==null&&typeof me=="object"&&typeof me.script=="string"){ne=!0;break}if(!ne||!_)return M;const de={...M};for(const[me,ye]of Object.entries(M)){if(ye===null||typeof ye!="object"||typeof ye.script!="string")continue;const fe=j+"|"+me;let se=we.get(fe);if(se===void 0){Ae.total++;try{se=_(ye.script,ye.scriptproperties||ye.scriptProperties||null,{userProperties:I||{},screenResolution:{x:xa,y:rr},timeOfDay:ri(),audioViews:B||void 0,layer:Z||null,shared:V||{},inputView:O||void 0,setTimeout:U?U.setTimeout:void 0,clearTimeout:U?U.clearTimeout:void 0,setInterval:U?U.setInterval:void 0,clearInterval:U?U.clearInterval:void 0,storage:W||void 0,getAnimationForProperty:()=>{const R=Y.get(j+"|anim|"+me);return R?R.ctrl:null}})}catch{se=null}if(se?Ae.ok++:Ae.failed++,we.set(fe,se),se){const R=ye.value!==void 0?ye.value:ye,F=Mi(R),$=typeof R=="number",H=$?F[0]:{x:F[0],y:F[1],z:F[2]},L=se.init(H);se.__lastConstValue=Ii(L,$)?L:H}if(se&&typeof se.applyUserProperties=="function")try{se.applyUserProperties(I||{})}catch{}if(se&&(se.hasMediaHook||se.hasAnimEventHook||se.hasResizeHook)&&ie)try{ie(se,{layer:Z,key:me})}catch{}}if(!se||se.disabled||!se.hasUpdate)continue;if(se.engine){se.engine.runtime=te,se.engine.frametime=ga,se.engine.timeOfDay=ri();const R=kn();R&&R.screenW&&R.screenH&&(se.engine.screenResolution={x:R.screenW,y:R.screenH})}const _e=typeof(ye.value!==void 0?ye.value:ye)=="number";if(!Ii(se.__lastConstValue,_e)){const R=Mi(ye.value!==void 0?ye.value:ye);se.__lastConstValue=_e?R[0]:{x:R[0],y:R[1],z:R[2]}}const xe=se.__lastConstValue;let T;try{T=se.callUpdate(xe)}catch{T=void 0}const C=T??xe;if(Ii(C,_e)&&(se.__lastConstValue=C),typeof C=="number"&&Number.isFinite(C))de[me]=C;else if(C&&typeof C=="object"){const R=Number(C.x),F=Number(C.y),$=Number(C.z);Number.isFinite(R)&&Number.isFinite(F)&&(de[me]=Number.isFinite($)?`${R} ${F} ${$}`:`${R} ${F} 0`)}}return de}function As(M,j,te){if(M)for(const[Z,ne]of Object.entries(M)){if(!ne||typeof ne!="object"||!ne.animation||!ne.animation.options)continue;const de=j+"|anim|"+Z;let me=Y.get(de);if(!me){const ye=Pl(ne.animation),fe=ne.value!==void 0?ne.value:0;ye.baseNumeric=Array.isArray(fe)?fe.slice():fe,me={ctrl:ye,prevTime:te},Y.set(de,me)}}}function Hn(M,j,te,Z){if(!M)return M;let ne=!1;for(const ye of Object.values(M))if(ye&&typeof ye=="object"&&ye.animation&&ye.animation.options){ne=!0;break}if(!ne)return M;const de={...M},me=new Map;for(const[ye,fe]of Object.entries(M)){if(!fe||typeof fe!="object"||!fe.animation||!fe.animation.options)continue;const se=j+"|anim|"+ye;let _e=Y.get(se);if(!_e){const xe=Pl(fe.animation),T=fe.value!==void 0?fe.value:0;xe.baseNumeric=Array.isArray(T)?T.slice():T,_e={ctrl:xe,prevTime:te},Y.set(se,_e)}me.set(ye,_e.ctrl)}oe.has(j)||(oe.add(j),Uh(me,ye=>i(`${j}: ${ye}`)));for(const[ye,fe]of Object.entries(M)){if(!fe||typeof fe!="object"||!fe.animation||!fe.animation.options)continue;const se=j+"|anim|"+ye,_e=Y.get(se),xe=te-_e.prevTime;if(_e.prevTime=te,_e.ctrl.playing&&_e.ctrl.advance(Math.max(0,xe)),he){const T=_e.ctrl.takeEvents();T.length&&he.push({layer:Z,events:T})}else _e.ctrl.takeEvents();de[ye]=_e.ctrl.applyTo(_e.ctrl.baseNumeric)}return de}function ka(M,j,te,Z){if(M==null||M==="")return null;if(M==="_rt_FullFrameBuffer"){if(!On||On.stamp!==ni){const ne=n.getParameter(n.FRAMEBUFFER_BINDING),de=n.getParameter(n.TEXTURE_BINDING_2D);On={glTex:_n(Ir||1,Rr||1),width:Ir||1,height:Rr||1,stamp:ni},n.bindFramebuffer(n.FRAMEBUFFER,ne),n.bindTexture(n.TEXTURE_2D,de)}return On}return M.startsWith("_rt_")?M.startsWith("_rt_imageLayerComposite")?Li&&gn.has(M)?gn.get(M):j:te.has(M)?te.get(M):null:te.has(M)?te.get(M):Z.get(M)||null}const ir=Fb(),Ta=Db(),Ri=new Map;function Br(M,j){const te=M+"x"+j;let Z=Ri.get(te);return Z===void 0&&(Z=Bb(M,j),Ri.set(te,Z)),Z}let Gt=null;function rn(M,j){Gt!==M&&(n.bindBuffer(n.ARRAY_BUFFER,gt),n.bufferData(n.ARRAY_BUFFER,j,n.DYNAMIC_DRAW),Gt=M)}const Ze={mvp:n.getUniformLocation(De,"u_MVP"),tex:n.getUniformLocation(De,"u_Tex"),color:n.getUniformLocation(De,"u_Color4"),frameOrigin:n.getUniformLocation(De,"u_FrameOrigin"),frameU:n.getUniformLocation(De,"u_FrameU"),frameV:n.getUniformLocation(De,"u_FrameV"),blendPrep:n.getUniformLocation(De,"u_BlendPrep")},Tn={mvp:n.getUniformLocation(Re,"u_MVP"),tex:n.getUniformLocation(Re,"u_Tex"),blendPrep:n.getUniformLocation(Re,"u_BlendPrep")},Bi={mvp:n.getUniformLocation(Fe,"u_MVP"),tex:n.getUniformLocation(Fe,"u_Tex")},Vn={mvp:n.getUniformLocation(nt,"u_MVP"),tex:n.getUniformLocation(nt,"u_Tex"),backdrop:n.getUniformLocation(nt,"u_Backdrop"),blendMode:n.getUniformLocation(nt,"u_BlendMode"),canvasSize:n.getUniformLocation(nt,"u_CanvasSize"),opacity:n.getUniformLocation(nt,"u_Opacity")},Wn={tex:n.getUniformLocation(Xe,"u_Tex"),texel:n.getUniformLocation(Xe,"u_Texel"),damp:n.getUniformLocation(Xe,"u_Damp"),alpha:n.getUniformLocation(Xe,"u_Alpha"),strength:n.getUniformLocation(Xe,"u_Strength"),threshold:n.getUniformLocation(Xe,"u_Threshold"),metric:n.getUniformLocation(Xe,"u_Metric")},It={tex:n.getUniformLocation($e,"u_Tex"),texel:n.getUniformLocation($e,"u_Texel"),res:n.getUniformLocation($e,"u_Res"),radius:n.getUniformLocation($e,"u_Radius"),dir:n.getUniformLocation($e,"u_Dir"),alpha:n.getUniformLocation($e,"u_Alpha"),strength:n.getUniformLocation($e,"u_Strength"),iterations:n.getUniformLocation($e,"u_Iterations")},Fr={mvp:n.getUniformLocation(Ye,"u_MVP"),tex:n.getUniformLocation(Ye,"u_Tex"),alpha:n.getUniformLocation(Ye,"u_Alpha"),strength:n.getUniformLocation(Ye,"u_Strength"),tint:n.getUniformLocation(Ye,"u_Tint")},ii={mvp:n.getUniformLocation(dn,"u_MVP"),tex:n.getUniformLocation(dn,"u_Tex"),texel:n.getUniformLocation(dn,"u_Texel")},sn=Nr(),Fi=Aa();function mn(M){M==="translucent"?(n.enable(n.BLEND),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA)):M==="additive"?(n.enable(n.BLEND),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE,n.ONE,n.ONE)):n.disable(n.BLEND)}let jn=0;function Sn(M){const{mode:j,prep:te}=El(M);jn=te,j==="additive"?(n.enable(n.BLEND),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE,n.ONE,n.ONE)):j==="multiply"?(n.enable(n.BLEND),n.blendFuncSeparate(n.DST_COLOR,n.ZERO,n.ONE,n.ONE_MINUS_SRC_ALPHA)):j==="screen"?(n.enable(n.BLEND),n.blendFuncSeparate(n.ONE,n.ONE_MINUS_SRC_COLOR,n.ONE,n.ONE_MINUS_SRC_ALPHA)):mn("translucent")}function Sa(M,j){if(j&&j.perspective||M.perspective)return!1;const te=M.size[0]*M.scale[0],Z=M.size[1]*M.scale[1];if(te===0||Z===0)return!1;let ne=Math.abs(te)/2,de=Math.abs(Z)/2;const me=M.angles[2];if(me!==0){const C=Math.abs(Math.cos(me)),R=Math.abs(Math.sin(me)),F=ne*C+de*R,$=ne*R+de*C;ne=F,de=$}const ye=M.origin[0],fe=j.projH-M.origin[1];let se=64;if(M.parallaxDepthOwn||M.parallaxDepth||M.parallaxDepthProp)if(Oe.active&&Oe.mode==="mirage"){const C=M.parallaxDepthProp||M.parallaxDepth||[0,0],R=M.parallaxAnchor||[ye,j.projH-fe],F=Math.abs(R[0]-Oe.cx+Oe.mx)*Math.abs(C[0])*Oe.amount,$=Math.abs(R[1]-Oe.cy+Oe.my)*Math.abs(C[1])*Oe.amount;se+=F+$}else Oe.active&&M.parallaxDepth&&(se+=Math.abs(Ea(M.parallaxDepth[0])*Oe.lx),se+=Math.abs(Ea(M.parallaxDepth[1])*Oe.ly));const _e=zh(M),xe=se+_e[0],T=se+_e[1];return ye+ne+xe<j.offX||ye-ne-xe>j.offX+j.viewW||fe+de+T<j.offY||fe-de-T>j.offY+j.viewH}function Di(M,j,te){if(!M.spriteSheet)return null;const Z=j&&j.frames,ne=Array.isArray(Z)?Z:Z&&Z.list;if(!ne||ne.length===0)return null;const de=Z&&Z.atlasWidth||j.width||0,me=Z&&Z.atlasHeight||j.height||0;if(de<=0||me<=0)return null;M.spriteFrameCount=ne.length;let ye=0;const fe=M.textureAnimation;if(fe&&fe.frame!==null&&fe.frame!==void 0)ye=Math.floor(Number(fe.frame))||0,ye>=0||(ye=0),ye>=ne.length&&(ye=ne.length-1);else if(ne.length>1){const R=fe&&fe.playing===!1;let F=0;for(const $ of ne)F+=$.duration>0?$.duration:1/30;if(!R&&F>0){let $=te%F;$<0&&($+=F);for(let H=0;H<ne.length;H++){const L=ne[H].duration>0?ne[H].duration:.03333333333333333;if($<L){ye=H;break}$-=L,ye=H}}}const se=ne[ye],_e=se.uDir?se.uDir[0]:se.width,xe=se.uDir?se.uDir[1]:0,T=se.vDir?se.vDir[0]:0,C=se.vDir?se.vDir[1]:se.height;return[se.x/de,se.y/me,_e/de,xe/me,T/de,C/me]}function pn(M,j){const te=M.size[0]*M.scale[0],Z=M.size[1]*M.scale[1];let ne=Nr();if(j&&j.perspective){const me=wp(M,j);ne=ui(ne,me[0],me[1],me[2]);const ye=M.angles[0]||0,fe=M.angles[1]||0;fe&&(ne=Tu(ne,fe)),ye&&(ne=ku(ne,ye)),ne=xu(ne,-M.angles[2])}else{if(ne=ui(ne,M.origin[0],j.projH-M.origin[1],M.origin[2]),M.parallaxDepth&&Oe.active){const me=Ko(M,Oe);(me[0]!==0||me[1]!==0)&&(ne=ui(ne,me[0],me[1],0))}ne=xu(ne,-M.angles[2]),M.perspective&&(M.angles[1]&&(ne=Tu(ne,-M.angles[1])),M.angles[0]&&(ne=ku(ne,M.angles[0])))}const de=Rh[M.alignment]||[.5,.5];return(de[0]!==.5||de[1]!==.5)&&(ne=ui(ne,(.5-de[0])*te,(.5-de[1])*Z,0)),{m:ne,w:te,h:Z}}function Pn(M,j,te,Z,ne,de,me,ye,fe=!1,se=null,_e=null){const xe=pn(Z,ne);let T=xe.m;if(_e){const $=(_e[0]+_e[2]/2)*Z.scale[0],H=(_e[1]+_e[3]/2)*Z.scale[1];T=ui(T,$,-H,0),T=Lr(T,_e[2]*Z.scale[0],_e[3]*Z.scale[1],1)}else T=Lr(T,xe.w,xe.h,1);const C=Wt(de,T);if(!fe&&!it&&Ml(Z.colorBlendMode)){const $=_n(me,ye);n.useProgram(nt),n.disable(n.BLEND),g(),n.viewport(0,0,me,ye),n.bindVertexArray(st),rn("local",Ta),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,j),n.uniform1i(Vn.tex,0),n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,$),n.uniform1i(Vn.backdrop,1),n.uniform1i(Vn.blendMode,Number(Z.colorBlendMode)|0),n.uniform2f(Vn.canvasSize,me,ye),n.uniform1f(Vn.opacity,te[3]),n.uniformMatrix4fv(Vn.mvp,!1,C),n.drawArrays(n.TRIANGLES,0,6),n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,null),n.activeTexture(n.TEXTURE0);return}const F=M===Re?Tn:Ze;n.useProgram(M),fe?(jn=0,n.enable(n.BLEND),Z.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)):Sn(jh(Z.colorBlendMode,Z.materialBlending)),F.blendPrep!==null&&F.blendPrep!==void 0&&n.uniform1i(F.blendPrep,jn),it?(n.bindFramebuffer(n.FRAMEBUFFER,it.fbo.fbo),n.viewport(0,0,it.w,it.h)):(g(),n.viewport(0,0,me,ye)),n.bindVertexArray(st),rn("local",Ta),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,j),n.uniform1i(F.tex,0),n.uniformMatrix4fv(F.mvp,!1,C),F.color!==null&&F.color!==void 0&&n.uniform4f(F.color,te[0],te[1],te[2],te[3]),sr(F,se),n.drawArrays(n.TRIANGLES,0,6)}function sr(M,j){!M||M.frameOrigin===null||M.frameOrigin===void 0||(j?(n.uniform2f(M.frameOrigin,j[0],j[1]),n.uniform2f(M.frameU,j[2],j[3]),n.uniform2f(M.frameV,j[4],j[5])):(n.uniform2f(M.frameOrigin,0,0),n.uniform2f(M.frameU,1,0),n.uniform2f(M.frameV,0,1)))}let Ni=null,it=null;const gn=new Map;let si=0;const ar=new Map,ai=new Map;let Li=!0;function oi(M,j){const te=pn(M,j),Z=j&&j.perspective?M.scale[1]:-M.scale[1],ne=j&&j.perspective&&M.scale[2]||1;return Lr(te.m,M.scale[0],Z,ne)}function Ui(M,j,te,Z,ne,de,me){it?(n.bindFramebuffer(n.FRAMEBUFFER,it.fbo.fbo),n.viewport(0,0,it.w,it.h)):(g(),n.viewport(0,0,Z,ne)),me&&(n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,me),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.generateMipmap(n.TEXTURE_2D));const ye=Wt(te,oi(M,j));Ni(M,ye,{time:de,overrideTex:me||null,ambient:Cl(M.lightingEnabled,vs),keepZ:!!(j&&j.perspective)}),me&&(n.bindTexture(n.TEXTURE_2D,me),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR)),Gt=null}let or=null;function _n(M,j){if(it)return it.fbo.tex;if(h){const te=Pt(M,j,"msaaBackdrop");return n.bindFramebuffer(n.READ_FRAMEBUFFER,h.fbo),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,te.fbo),n.blitFramebuffer(0,0,M,j,0,0,M,j,n.COLOR_BUFFER_BIT,n.NEAREST),n.bindFramebuffer(n.READ_FRAMEBUFFER,null),n.bindFramebuffer(n.DRAW_FRAMEBUFFER,null),te.tex}return or===null&&(or=n.createTexture(),n.bindTexture(n.TEXTURE_2D,or),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,or),n.copyTexImage2D(n.TEXTURE_2D,0,n.RGB8,0,0,M,j,0),or}function ci(M,j,te){const Z=_n(j,te),ne=Math.max(1,Math.round(j/4)),de=Math.max(1,Math.round(te/4)),me=Pt(ne,de,"bloomA"),ye=Pt(ne,de,"bloomB");n.bindVertexArray(st),rn("pass",ir),n.activeTexture(n.TEXTURE0),n.useProgram(Xe),n.disable(n.BLEND),n.bindFramebuffer(n.FRAMEBUFFER,me.fbo),n.viewport(0,0,ne,de),n.bindTexture(n.TEXTURE_2D,Z),n.uniform1i(Wn.tex,0),n.uniform2f(Wn.texel,1/j,1/te),n.uniform1f(Wn.damp,M.damp),n.uniform1f(Wn.alpha,M.alpha),n.uniform1f(Wn.strength,M.strength),n.uniform1f(Wn.threshold,M.threshold),n.uniform1i(Wn.metric,M.metric),n.drawArrays(n.TRIANGLES,0,6),n.useProgram($e);const fe=(se,_e,xe,T)=>{n.bindFramebuffer(n.FRAMEBUFFER,_e.fbo),n.viewport(0,0,_e.width,_e.height),n.bindTexture(n.TEXTURE_2D,se.tex),n.uniform1i(It.tex,0),n.uniform2f(It.texel,1/se.width,1/se.height),n.uniform2f(It.res,se.width,se.height),n.uniform1f(It.radius,M.radius),n.uniform2f(It.dir,xe,T),n.uniform1f(It.alpha,M.alpha),n.uniform1f(It.strength,M.strength),n.uniform1f(It.iterations,M.iterations),n.drawArrays(n.TRIANGLES,0,6)};if(fe(me,ye,1,0),fe(ye,me,0,1),n.useProgram(Ye),n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,j,te),n.enable(n.BLEND),n.blendFunc(n.ONE,n.ONE),n.bindTexture(n.TEXTURE_2D,me.tex),n.uniform1i(Fr.tex,0),n.uniformMatrix4fv(Fr.mvp,!1,sn),n.uniform1f(Fr.alpha,M.alpha),n.uniform1f(Fr.strength,M.strength),n.uniform3f(Fr.tint,M.tint[0],M.tint[1],M.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),Ne++,Ne===1||Ne===120||Ne===600){const se=new Uint8Array(4);n.bindFramebuffer(n.FRAMEBUFFER,me.fbo),n.readPixels(ne>>1,de>>1,1,1,n.RGBA,n.UNSIGNED_BYTE,se),n.bindFramebuffer(n.FRAMEBUFFER,null),i(`bloom frame ${Ne}: center=[${[...se].join(",")}] glErr=${n.getError()} threshold=${M.threshold} strength=${M.strength} metric=${M.metric}`)}}function xs(M,j,te,Z,ne,de,me,ye){const fe=_n(me,ye),se=pn(M,ne);let _e=se.m;_e=Lr(_e,se.w,se.h,1);const xe=Wt(de,_e),T=[[-.5,.5],[.5,.5],[-.5,-.5],[.5,-.5]].map(([L,X])=>{const Q=Ap(xe,L,X,0);return[Q[0]*.5+.5,Q[1]*.5+.5]}),[C,R,F,$]=T,H=new Float32Array([0,Z,0,C[0],C[1],0,0,0,F[0],F[1],te,Z,0,R[0],R[1],te,Z,0,R[0],R[1],0,0,0,F[0],F[1],te,0,0,$[0],$[1]]);n.useProgram(Fe),mn("normal"),n.disable(n.BLEND),n.bindFramebuffer(n.FRAMEBUFFER,j.fbo),n.viewport(0,0,te,Z),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.bindVertexArray(st),n.bindBuffer(n.ARRAY_BUFFER,gt),n.bufferData(n.ARRAY_BUFFER,H,n.DYNAMIC_DRAW),Gt=null,n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,fe),n.uniform1i(Bi.tex,0),n.uniformMatrix4fv(Bi.mvp,!1,Hi(0,te,0,Z,-1e4,1e4)),n.drawArrays(n.TRIANGLES,0,6),n.enable(n.BLEND)}async function Oi(M,j,te,Z,ne,de){if(!Li||it)return;const me=ar.get(M.id);if(!me||me.size===0)return;const ye=Math.max(1,Math.round(Math.abs(M.size[0]*(M.scale[0]||1)))),fe=Math.max(1,Math.round(Math.abs(M.size[1]*(M.scale[1]||1))));if(ye<=1&&fe<=1)return;const se=Pt(ye,fe,"lc:"+M.id);if((M.effects||[]).some(xe=>xe.visible)){const xe=it;it={fbo:se,w:ye,h:fe};try{li(M,textures,j,te,Z,ne,de)}catch(T){i(`z \u5E8F\u5408\u6210\u6E90 ${M.id} \u6548\u679C\u94FE\u5931\u8D25: ${T&&T.message}`)}finally{it=xe}}else xs(M,se,ye,fe,j,te,Z,ne);for(const xe of me)gn.set(xe,se);if(ar.delete(M.id),M.copybackground)for(const xe of me)ai.set(xe,se);g(),n.viewport(0,0,Z,ne)}async function Pa(M,j,te,Z,ne,de,me,ye){xa=te,rr=Z,xn++,y(te,Z),g(),n.viewport(0,0,te,Z);const fe=M.general||{};if(vs=ho(fe.ambientcolor||"1 1 1"),fe.clearenabled!==!1){const Q=ho(fe.clearcolor||"0 0 0");n.clearColor(Q[0],Q[1],Q[2],1)}else n.clearColor(0,0,0,1);if(n.clear(n.COLOR_BUFFER_BIT),Ve>=0){const Q=ne-Ve;ga=Q>0&&Q<1?Q:Math.min(.1,Math.max(.001,Q||1/60))}Ve=ne;const se=Tp(M,te,Z,de,me,ye);let _e=Wt(se.projection,se.view);ni++,Ir=te,Rr=Z;const xe=fe.cameraparallax,T=xe===!0||xe!==null&&typeof xe=="object"&&xe.value===!0,C=kn();if(C&&(Oe.mode==="mirage"?(yt.x=C.u,yt.y=C.v):(yt.x=C.u*2-1,yt.y=C.v*2-1)),!se.perspective&&e.parallax!==!1&&T){const Q=(z,ee)=>{const G=z!==null&&typeof z=="object"?z.value:z;return typeof G=="number"&&Number.isFinite(G)?G:ee},re=Q(fe.cameraparallaxamount,0),q=Q(fe.cameraparallaxmouseinfluence,1),K=Q(fe.cameraparallaxdelay,1),D=ne-Ke;Ke=ne;const E=D>0?1-Math.exp(-D/Math.max(.05,K)):1;if(yt.sx+=(yt.x-yt.sx)*E,yt.sy+=(yt.y-yt.sy)*E,Oe.mode==="mirage")Oe.mx=(.5-yt.sx)*se.projW*q,Oe.my=(yt.sy-.5)*se.projH*q,Oe.amount=re,Oe.cx=se.projW/2,Oe.cy=se.projH/2,Oe.lx=0,Oe.ly=0;else{const z=re*q,ee=60,G=yt.sx*z*se.viewW,J=yt.sy*z*se.viewH,ge=Math.max(Math.abs(G),Math.abs(J))/ee,ae=ge>1?1/ge:1;Oe.lx=-(G*ae),Oe.ly=-(J*ae),Oe.mx=0,Oe.my=0,Oe.amount=0}Oe.active=!0}else Oe.active=!1,Oe.lx=0,Oe.ly=0;let R=null;if(!se.perspective&&e.shake!==!1){const Q=wa(fe,ne);if(Q){const re=Q.x*se.viewW*.02,q=Q.y*se.viewH*.02;(re!==0||q!==0)&&(R=ui(Nr(),re,q,0),_e=Wt(_e,R))}}let F=null;if(Ei=null,!se.perspective)for(const Q of M.layers){if(!Q.perspective||Q.destroyed)continue;const re=Sp(se,fe);re&&(F=R?Wt(re.viewProj,R):re.viewProj,Ei=re.eye);break}if(lt){const Q=typeof lt=="function"?lt():lt;Q&&typeof Q.syncWorld=="function"&&Q.syncWorld(se,0,0)}if(!Ce){Ce=!0;const Q=(M.layers||[]).filter(K=>K.isContainer),re=Q.filter(K=>(K.effects||[]).some(D=>D.visible)&&!K.hasChildren),q=re.filter(K=>(K.effects||[]).some(D=>(D.materialPasses||[]).length>0));i(`containers total=${Q.length} canvasCandidates=${re.length} passesResolved=${q.length} names=${re.slice(0,4).map(K=>K.name||"?").join("/")}`)}await jo(M,j,se,te,Z,ne);const $=new Map;for(const Q of M.layers)Q.id!==void 0&&$.set(Q.id,Q);const H=new Set;for(const Q of M.layers)!Q.visible||Q.destroyed||!Q.isContainer||!Q.hasChildren||!(Q.effects||[]).some(q=>q.visible)||(Q.childIds||[]).length===0||yo(Q,$,H);if(v)try{v()}catch(Q){i("particle advance error: "+(Q&&Q.message))}const L=se.perspective?M.layers.slice().sort((Q,re)=>+!!re.isSkybox-+!!Q.isSkybox):M.layers;for(const Q of L){if(Q.destroyed)continue;const re=Q.perspective&&F?F:_e;if(!Q.visible){ar.has(Q.id)&&await Oi(Q,se,re,te,Z,ne);continue}if(!(Q.isPostProcess&&!(Q.effects||[]).some(q=>q.visible))&&!(!f&&Q.isPostProcess)&&!H.has(Q.id)){if(Q.isContainer){if(!(Q.effects||[]).some(K=>K.visible)){await Oi(Q,se,re,te,Z,ne);continue}if(Q.hasChildren){(Q.childIds||[]).length>0&&await Dr(Q,M,j,se,re,te,Z,ne);continue}}if(Q.particle){if(x)try{await x(Q.id,se,re,te,Z)}catch(q){i("particle render error: "+(q&&q.message))}continue}Sa(Q,se)||await li(Q,j,se,re,te,Z,ne)}}if(ws(fe)&&ne<ya){const Q=Math.max(0,Math.min(1,ne/ya)),re=1-Q*Q*(3-2*Q);if(re>.002){const q=ho(fe.clearcolor||"0 0 0");n.useProgram(De),n.enable(n.BLEND),n.blendFuncSeparate(n.SRC_ALPHA,n.ONE_MINUS_SRC_ALPHA,n.ONE,n.ONE_MINUS_SRC_ALPHA),g(),n.viewport(0,0,te,Z),n.bindVertexArray(st),rn("pass",ir),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,hn),n.uniform1i(Ze.tex,0),n.uniform4f(Ze.color,q[0],q[1],q[2],re),sr(Ze,null),Ze.blendPrep!==null&&Ze.blendPrep!==void 0&&n.uniform1i(Ze.blendPrep,0),n.uniformMatrix4fv(Ze.mvp,!1,sn),n.drawArrays(n.TRIANGLES,0,6)}}b(te,Z);const X=f?$h(fe):null;if(Le||(Le=!0,i(X?`bloom post: on strength=${X.strength} threshold=${X.threshold} iter=${X.iterations} radius=${X.radius} damp=${X.damp} hdr=${X.hdr}`:"bloom post: off")),X&&X.strength>.001&&ci(X,te,Z),d==="fxaa"){const Q=_n(te,Z);n.useProgram(dn),n.disable(n.BLEND),n.bindFramebuffer(n.FRAMEBUFFER,null),n.viewport(0,0,te,Z),n.bindVertexArray(st),rn("pass",ir),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,Q),n.uniform1i(ii.tex,0),n.uniform2f(ii.texel,1/te,1/Z),n.uniformMatrix4fv(ii.mvp,!1,sn),n.drawArrays(n.TRIANGLES,0,6)}n.bindVertexArray(null),xt()}async function jo(M,j,te,Z,ne,de){gn.clear(),ar.clear();for(const[xe,T]of ai)gn.set(xe,T);const me=new Map,ye=new Set;let fe=null;const se=xe=>{if(typeof xe!="string")return;const T=/^_rt_imageLayerComposite_(\d+)_[a-z]$/.exec(xe);if(!T)return;const C=Number(T[1]);fe!==null&&C===fe&&ye.add(C);let R=me.get(C);R||(R=new Set,me.set(C,R)),R.add(xe)};for(const xe of M.layers||[]){fe=xe.id;for(const T of xe.effects||[])if(T.visible){for(const C of T.passes||[])for(const R of C.textures||[])se(R);for(const C of T.materialPasses||[]){for(const R of C.binds||[])se(R&&R.name);for(const R of C.textures||[])se(R)}}}for(const xe of[...ai.keys()]){let T=!1;for(const C of me.values())if(C.has(xe)){T=!0;break}T||ai.delete(xe)}if(me.size===0)return;const _e=(()=>{const xe=[...me.keys()],T=new Map;for(const $ of xe){const H=(M.layers||[]).find(X=>X.id===$),L=new Set;if(H){const X=Q=>{if(typeof Q=="string"){const re=/^_rt_imageLayerComposite_(\d+)_[a-z]$/.exec(Q);if(re){const q=Number(re[1]);q!==$&&me.has(q)&&L.add(q)}}else Array.isArray(Q)&&Q.forEach(X)};for(const Q of H.effects||[])if(Q.visible){for(const re of Q.passes||[])for(const q of re.textures||[])X(q);for(const re of Q.materialPasses||[]){for(const q of re.binds||[])X(q&&q.name);for(const q of re.textures||[])X(q)}}}T.set($,L)}const C=[],R=new Map,F=$=>{if((R.get($)||0)===0){R.set($,1);for(const L of T.get($)||[])F(L);R.set($,2),C.push($)}};for(const $ of xe)F($);return C})();for(const xe of _e){const T=me.get(xe),C=(M.layers||[]).find(pe=>pe.id===xe);if(!C||C.particle||C.isPostProcess||ye.has(xe))continue;const R=typeof C.image=="string"?C.image:"",F=C.isContainer&&!C.hasChildren&&R.indexOf("models/util/composelayer")===0&&!(C.effects||[]).some(pe=>pe.visible),$=!C.solid&&!!C.textureName,H=!!C.copybackground&&!$;if(F||H){ar.set(xe,T);continue}const L=Math.max(1,Math.round(Math.abs(C.size[0]*(C.scale[0]||1)))),X=Math.max(1,Math.round(Math.abs(C.size[1]*(C.scale[1]||1))));if(L<=1&&X<=1)continue;si<=0&&(si=Math.max(1,n.getParameter(n.MAX_TEXTURE_SIZE)||8192));const Q=Xh(L,X,si),re=Q.width,q=Q.height,K=Q.k,D=Pt(re,q,"lc:"+xe);n.bindFramebuffer(n.FRAMEBUFFER,D.fbo),n.viewport(0,0,re,q),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT);const E={view:te.view,projection:Hi(0,re,0,q,-1e4,1e4),eye:te.eye,projW:re,projH:q,offX:0,offY:0,viewW:re,viewH:q},z=it,ee=C.origin,G=C.scale,J=C.angles,ge=C.visible,ae=C.size;it={fbo:D,w:re,h:q};const ue=Zh(C.size,G,re,q,K);C.origin=[re/2,E.projH-q/2,ee[2]],C.size=ue.size,C.scale=ue.scale,C.angles=[0,0,0],C.visible=!0;try{await li(C,j,E,E.projection,re,q,de);for(const pe of T)gn.set(pe,D)}catch(pe){i(`composite \u6E90\u5C42 ${xe} \u6E32\u67D3\u5931\u8D25: ${pe&&pe.message}`)}finally{it=z,C.origin=ee,C.scale=G,C.angles=J,C.visible=ge,C.size=ae}}g(),n.viewport(0,0,Z,ne)}async function Dr(M,j,te,Z,ne,de,me,ye){const fe=Math.max(1,Math.round(Math.abs(M.size[0]))),se=Math.max(1,Math.round(Math.abs(M.size[1])));if((M.childIds||[]).length===0)return;const xe=new Map;for(const q of j.layers)q.id!==void 0&&xe.set(q.id,q);const T=yo(M,xe),C=j.layers.filter(q=>T.has(q.id)&&q.visible);if(C.length===0)return;const R=Pt(fe,se,"group");n.bindFramebuffer(n.FRAMEBUFFER,R.fbo),n.viewport(0,0,fe,se),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT);const F={view:Z.view,projection:Hi(0,fe,0,se,-1e4,1e4),eye:Z.eye,projW:fe,projH:se,offX:0,offY:0,viewW:fe,viewH:se},$=F.projection,H=M.scale[0]||1,L=M.scale[1]||1,X=M.angles[2]||0,Q=Math.cos(-X),re=Math.sin(-X);it={fbo:R,w:fe,h:se};try{for(const q of C){if(q.isPostProcess||q.particle||q.isContainer&&(q.childIds||[]).length>0)continue;const K=q.origin,D=q.scale,E=q.angles,z=K[0]-M.origin[0],ee=K[1]-M.origin[1],G=(z*Q-ee*re)/H,J=(z*re+ee*Q)/L;q.origin=[fe/2+G,se/2+J,K[2]],q.scale=[D[0]/H,D[1]/L,D[2]],q.angles=[E[0],E[1],E[2]-X];try{await li(q,te,F,$,fe,se,ye)}finally{q.origin=K,q.scale=D,q.angles=E}}}finally{it=null}M.groupTex=R.tex,M.groupW=fe,M.groupH=se;try{await li(M,te,Z,ne,de,me,ye)}finally{M.groupTex=null}}async function li(M,j,te,Z,ne,de,me){const ye=!!(M.puppet&&Ni),fe=!M.solid&&M.textureName?j.get(M.textureName):null;if(fe&&fe.video){const ae=fe.video;if(ae.readyState>=2&&ae.currentTime!==fe.lastUploaded){n.bindTexture(n.TEXTURE_2D,fe.glTex);try{let ue=ae.videoWidth||fe.width,pe=ae.videoHeight||fe.height;const Ie=Math.max(ne||0,de||0),je=n.getParameter(n.MAX_TEXTURE_SIZE)||0;let qe=c;je>0&&(qe=Math.min(qe,je)),Ie>0&&(qe=Math.min(qe,Ie)),qe=Math.max(qe,u);let Tt=1;Math.max(ue,pe)>qe&&(Tt=qe/Math.max(ue,pe));const bt=Math.max(1,Math.round(ue*Tt)),wt=Math.max(1,Math.round(pe*Tt));let En=ae;if(s&&bt>0&&wt>0){(s.width!==bt||s.height!==wt)&&(s.width=bt,s.height=wt);const yn=s.getContext("2d");yn&&(yn.clearRect(0,0,bt,wt),yn.drawImage(ae,0,0,bt,wt),En=s)}if(n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,En),n.getError()!==n.NO_ERROR&&s)try{const ut=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(ut.data.buffer));n.getError()!==n.NO_ERROR;);}catch{}fe.width=bt,fe.height=wt,fe.lastUploaded=ae.currentTime,o!==bt+"x"+wt&&(o=bt+"x"+wt,a=!0,i("video tex ready "+bt+"x"+wt+" (src "+ue+"x"+pe+", limit "+qe+")"))}catch(ue){a||(a=!0,i("video upload FAIL: "+(ue&&ue.message||ue))),console.warn("[we-scene] \u89C6\u9891\u5E27\u4E0A\u4F20\u5931\u8D25:",ue&&ue.message,"readyState=",ae.readyState,"cur=",ae.currentTime)}}}const se=M.groupTex?M.groupTex:fe&&fe.glTex?fe.glTex:M.solid?hn:Cr,_e=(!!M.passthrough||!!M.isPostProcess||Vh(M)||Wh(M))&&!M.groupTex&&!fe&&!ye&&!it;let xe,T;if(M.groupTex)xe=M.groupW||M.size[0],T=M.groupH||M.size[1];else if(ye||!fe)xe=M.size[0],T=M.size[1];else{const ae=Math.round(Math.abs(M.size&&M.size[0]||0)*Math.abs(M.scale&&M.scale[0]||1)),ue=Math.round(Math.abs(M.size&&M.size[1]||0)*Math.abs(M.scale&&M.scale[1]||1));xe=ae>0?ae:fe.width,T=ue>0?ue:fe.height}if(!ye&&fe&&M.spriteSheet){const ae=fe.frames,ue=Array.isArray(ae)?ae:ae&&ae.list;ue&&ue.length&&(xe=ue[0].width||xe,T=ue[0].height||T)}const C=Math.max(1,Math.round(xe)),R=Math.max(1,Math.round(T)),F=Cl(M.lightingEnabled,vs),$=[M.color[0]*M.brightness*F[0],M.color[1]*M.brightness*F[1],M.color[2]*M.brightness*F[2],M.alpha],H=f?(M.effects||[]).filter(ae=>ae.visible):[];let L=C,X=R;if(l>0&&te.projW>0&&te.projH>0){const ae=Math.min(Math.abs(M.size[0]*M.scale[0]),te.viewW),ue=Math.min(Math.abs(M.size[1]*M.scale[1]),te.viewH),pe=ae*(ne/te.projW),Ie=ue*(de/te.projH);if(pe>0&&Ie>0){const je=Math.max(64,Math.round(pe*l)),qe=Math.max(64,Math.round(Ie*l));je<C&&(L=je),qe<R&&(X=qe)}}if(H.length===0){ye?Ui(M,te,Z,ne,de,me):Pn(De,se,$,M,te,Z,ne,de,!1,Di(M,fe,me));return}const Q=Pt(L,X,"ping"),re=Pt(L,X,"pong"),q=Hi(0,L,0,X,-1e4,1e4);if(ye)n.useProgram(De),mn("normal"),n.bindFramebuffer(n.FRAMEBUFFER,Q.fbo),n.viewport(0,0,L,X),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.bindVertexArray(st),Gt=null,rn("layer"+L+"x"+X,Br(L,X)),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,se),n.uniform1i(Ze.tex,0),n.uniform4f(Ze.color,1,1,1,1),sr(Ze,null),Ze.blendPrep!==null&&Ze.blendPrep!==void 0&&n.uniform1i(Ze.blendPrep,0),n.uniformMatrix4fv(Ze.mvp,!1,q),n.drawArrays(n.TRIANGLES,0,6);else if(_e)xs(M,Q,L,X,te,Z,ne,de);else{n.useProgram(De),mn("normal"),n.bindFramebuffer(n.FRAMEBUFFER,Q.fbo),n.viewport(0,0,L,X),n.clearColor(0,0,0,0),n.clear(n.COLOR_BUFFER_BIT),n.bindVertexArray(st),rn("layer"+L+"x"+X,Br(L,X)),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,se),n.uniform1i(Ze.tex,0);const ae=H.some(ue=>ue&&ue.layerMaterial)?[1,1,1,$[3]]:$;n.uniform4f(Ze.color,ae[0],ae[1],ae[2],ae[3]),sr(Ze,Di(M,fe,me)),Ze.blendPrep!==null&&Ze.blendPrep!==void 0&&n.uniform1i(Ze.blendPrep,0),n.uniformMatrix4fv(Ze.mvp,!1,q),n.drawArrays(n.TRIANGLES,0,6)}let K=Q,D=re;const E=new Map;let z=!1,ee=Q;const G=[],J=new Set;for(const ae of H){for(const pe of ae.fbos||[])if(!E.has(pe.name)){const[Ie,je]=qh(pe,L,X),qe=pe.unique?M.id+":"+pe.name:pe.name;E.set(pe.name,Pt(Ie,je,qe))}const ue=ae.materialPasses||[];for(let pe=0;pe<ue.length;pe++)G.push({eff:ae,mp:ue[pe],ov:ae.passes&&ae.passes[pe]})}const ge=[];for(let ae=0;ae<G.length;ae++){const{eff:ue,mp:pe,ov:Ie}=G[ae];if(J.has(ue))continue;const je={...pe.combos||{},...Ie&&Ie.combos||{}};if(/audio_responsive_oscilloscope/i.test(pe.shader||"")){const ze=Ie&&Ie.combos||{},Je=pe.combos||{};ze.WRITEALPHA===void 0&&Je.WRITEALPHA===void 0&&(je.WRITEALPHA=1),ze.TRANSPARENCY===void 0&&Je.TRANSPARENCY===void 0&&(je.TRANSPARENCY=1)}const qe=pe.textures||[],Tt=Ie&&Ie.textures||[],bt=[];for(let ze=0;ze<Math.max(qe.length,Tt.length);ze++)Tt[ze]!==void 0&&Tt[ze]!==null?bt[ze]=Tt[ze]:bt[ze]=qe[ze]!==void 0?qe[ze]:null;if(Ie&&Array.isArray(Ie.textureFallbacks))for(let ze=0;ze<bt.length;ze++){const Je=bt[ze];if(typeof Je!="string"||Je===""||j&&j.get(Je))continue;const on=Ie.textureFallbacks[ze];on&&(bt[ze]=on)}if(pe.copyCommand){const ze=pe.source?E.get(pe.source):null,Je=pe.target?E.get(pe.target):null;ze&&Je&&(n.useProgram(Re),mn("normal"),n.bindFramebuffer(n.FRAMEBUFFER,Je.fbo),n.viewport(0,0,Je.width,Je.height),n.bindVertexArray(st),rn("pass",ir),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,ze.tex),n.uniform1i(Tn.tex,0),Tn.blendPrep!==null&&Tn.blendPrep!==void 0&&n.uniform1i(Tn.blendPrep,0),n.uniformMatrix4fv(Tn.mvp,!1,sn),n.drawArrays(n.TRIANGLES,0,6),g());continue}let wt;try{wt=await pa(pe.shader,je,bt)}catch(ze){const Je=ze&&ze.message||String(ze);/已缓存/.test(Je)||console.warn("[we-scene] \u8DF3\u8FC7\u6548\u679C\uFF08pass \u7F16\u8BD1\u5931\u8D25\uFF09:",pe.shader,Je),J.add(ue);continue}const En=wt.prog,yn=wt.uni;wt.fragGlsl&&ge.push(wt.fragGlsl);let ut,Qt;pe.target?(z||(ee=K,z=!0),ut=E.get(pe.target)||K,Qt=ee):(z=!1,ut=D,Qt=K),n.useProgram(En),mn(pe.blending||"normal"),n.bindFramebuffer(n.FRAMEBUFFER,ut.fbo),n.viewport(0,0,ut.width,ut.height),n.bindVertexArray(st);const zi=!wt.ndcDirect;zi?rn("passPx"+ut.width+"x"+ut.height,Br(ut.width,ut.height)):rn("pass",ir);const qo=zi?$o(Hi(0,ut.width,0,ut.height,-1e4,1e4)):sn,_a=pe.textures||[],ks=Math.max(_a.length,8),an=new Map,yp=new Set;for(let ze=0;ze<ks;ze++){let Je=bt[ze]!==void 0?bt[ze]:null;for(const Ss of pe.binds||[])Ss.index===ze&&(Je=Ss.name);let on;if(ze===0&&(Je==null||Je===""))on=Qt;else{if((Je==null||Je==="")&&wt.samplerDefaults){const Ss=wt.samplerDefaults.get(ze);Ss&&(Je=Ss)}on=ka(Je,Qt,E,j)}Je==="previous"&&(on=Qt),on===null&&(on={glTex:hn,width:1,height:1,tex:hn});const Ts=on.fbo?on:{tex:on.glTex||hn,width:on.width||1,height:on.height||1};n.activeTexture(n.TEXTURE0+ze),n.bindTexture(n.TEXTURE_2D,Ts.tex),yp.add(ze),an.set(ze,[Ts.width,Ts.height,Ts.width,Ts.height])}let vu=null;if(yn.get("g_EffectModelViewProjectionMatrix")){const ze=pn(M,te);let Je=Lr(ze.m,ze.w,ze.h,1);Je=zi?Wt(Je,Lr(ui(Nr(),-.5,-.5,0),1/ut.width,1/ut.height,1)):Wt(Je,Lr(Nr(),.5,.5,1)),vu=$o(Wt(Z,Je))}Ci(yn,M,me,te.projW,te.projH,qo,q,sn,an,q,te,vu);const Xo=(M.id||M.name||"?")+"|"+(pe.shader||"?")+"|"+ae,Au={...pe.constants||{},...Ie&&Ie.constantshadervalues||{}};As(Au,Xo,me),Wo(yn,Hn(Ct(Au,Xo,me,M),Xo,me,M),wt.matMeta),zn(yn),n.drawArrays(n.TRIANGLES,0,6),pe.target||(D=K,K=ut)}if(M.isContainer&&!M.groupTex&&!_e&&M.containerAlphaMeaningful===void 0&&(M.containerAlphaMeaningful=Hh(ge),i(`container "${M.name||"?"}" alpha ${M.containerAlphaMeaningful?"\u643A\u5E26\u5F62\u72B6 \u2192 SRC_ALPHA":"\u65E0\u4FE1\u606F \u2192 \u52A0\u6CD5"}`)),ye){Ui(M,te,Z,ne,de,me,K.tex);return}Pn(Re,K.tex,[1,1,1,1],M,te,Z,ne,de,!!M.isContainer&&!M.groupTex&&!_e,null,null)}return{gl:n,render:Pa,getFBO:Pt,getEffectProgram:pa,progCache:tn,shaderResolver:r,whiteTex:hn,resetShaderCaches:function(){tn.clear(),Mt.clear(),Pi&&Pi.clear()},setFboCapFactor:function(M){l=M},setAntiAliasing:function(M){d=M==="fxaa"||M==="msaa2"||M==="msaa4"?M:"off"},setEffectsEnabled:function(M){f=!!M},getFrameTarget:function(){return h?h.fbo:null},captureSceneTexture:function(M,j){return _n(M,j)},setParticleRenderer:function(M,j){v=typeof M=="function"?M:null,x=typeof j=="function"?j:null},setConstantScriptRuntime:Pe,applyConstUserProperties:function(M){if(M){for(const j of we.values())if(j&&typeof j.applyUserProperties=="function")try{j.applyUserProperties(M)}catch{}}},constantScriptStats:function(){return{...Ae,cached:we.size}},setCompositeEnabled:function(M){Li=!!M},compositeStats:function(){const M=[],j=new Uint8Array(4);for(const[te,Z]of gn){let ne=null;try{n.bindFramebuffer(n.FRAMEBUFFER,Z.fbo),n.readPixels(Z.w>>1,Z.h>>1,1,1,n.RGBA,n.UNSIGNED_BYTE,j),ne=[j[0],j[1],j[2],j[3]]}catch{}M.push({name:te,w:Z.w,h:Z.h,center:ne})}return n.bindFramebuffer(n.FRAMEBUFFER,null),M},setPuppetRenderer:function(M){Ni=M},setAudioProvider:k,setPointerProvider:Un,getParallaxOffset:function(){return Oe},getPerspectiveEye:function(){return Ei},dispose:function(){try{const M=n.getExtension("WEBGL_lose_context");M&&M.loseContext()}catch{}}}}const nw=Object.freeze(Object.defineProperty({__proto__:null,ALIGN:Rh,XRAY_IDLE_SCREEN_UV:ea,XRAY_SIZE_FALLBACK:Qh,applyColorBlendCPU:Zb,bloomPostParams:$h,chainAlphaMeaningful:Hh,clampCompositeFboSize:Xh,collectGroupDescendantIds:yo,colorBlendPlan:El,compositeSourcePlacement:Zh,compositeSourceQuadSize:Kh,compressedFormatFor:Ob,constantFallback:Yh,createRenderer:tw,effectFboSize:qh,layerColorAmbient:Cl,layerCompositeBlendMode:jh,layerWantsComposeBackdrop:Wh,layerWantsPreserveBackdrop:Vh,makeCompressedTextureMip:Ub,makeR8TextureMip:zb,makeTexture:Tl,makeTextureMip:Lb,needsShaderBlend:Ml,puppetAnimMargin:zh,rewriteXrayFragScale:Gh,xrayShouldParkPointer:Il,xrayUvScale:Jb},Symbol.toStringTag,{value:"Module"})),Gr=Math.PI*2;function _t(t,e){return t==null?Math.random():e==null?t:t+Math.random()*(e-t)}function Qr(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 ht(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 ht(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 Sr(t){if(t==null)return null;if(Array.isArray(t)){if(t.length!==3)return null;const r=t.map(Number);return r.every(Number.isFinite)?r:null}if(typeof t=="object")return Sr(t.value);if(typeof t=="number")return Number.isFinite(t)?[t,0,0]:null;const e=String(t).trim().split(/\s+/);if(e.length!==3)return null;const n=e.map(Number);return n.every(Number.isFinite)?n:null}function Jh(t){return t==null?null:typeof t=="number"?[t,t,t]:ht(t)}function Te(t,e){if(t==null)return e;if(typeof t=="object")return Te(t.value,e);const n=Number(t);return Number.isFinite(n)?n:e}function Rl(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 Yr(t,e,n){const r=Math.sin(t*127.1+e*311.7+n*74.7)*43758.5453;return r-Math.floor(r)}function rw(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),d=c*c*(3-2*c),f=(y,w,A)=>y+(w-y)*A,h=f(Yr(r,i,s),Yr(r+1,i,s),u),p=f(Yr(r,i+1,s),Yr(r+1,i+1,s),u),m=f(Yr(r,i,s+1),Yr(r+1,i,s+1),u),g=f(Yr(r,i+1,s+1),Yr(r+1,i+1,s+1),u);return f(f(h,p,l),f(m,g,l),d)}function Bl(t,e,n,r){let i=0,s=.5,a=1,o=0;for(let c=0;c<r;c++)i+=s*rw(t*a,e*a,n*a),o+=s,s*=.5,a*=2;return i/(o||1)}function Fl(t,e,n,r){return[Bl(t,e,n,r)*2-1,Bl(t+31.7,e+11.3,n+57.1,r)*2-1,Bl(t+73.9,e+92.1,n+13.7,r)*2-1]}function iw(t){const e=`#version 300 es
|
|
67
394
|
// \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
395
|
layout(location=0) in vec2 a_corner; // -0.5..0.5
|
|
69
396
|
layout(location=1) in vec3 a_pos; // \u5B9E\u4F8B\u4E2D\u5FC3\uFF08\u6295\u5F71\u7A7A\u95F4\u4E16\u754C\u5750\u6807\uFF09
|
|
@@ -71,81 +398,145 @@ layout(location=2) in vec2 a_sizeRot; // x=size(\u50CF\u7D20) y=rot(\u5F27\u
|
|
|
71
398
|
layout(location=3) in vec4 a_color; // rgb + alpha
|
|
72
399
|
layout(location=4) in vec3 a_stretchFrame; // xy=\u975E\u7B49\u6BD4\u62C9\u4F38 z=\u5E27\u5E8F\u53F7
|
|
73
400
|
layout(location=5) in vec2 a_vrange; // \u6BB5\u4E24\u7AEF\u6CBF\u8D34\u56FE v \u7684\u53D6\u503C\uFF08rope \u8FDE\u7EBF\u7528\uFF1B\u666E\u901A\u7CBE\u7075 0..1\uFF09
|
|
401
|
+
layout(location=6) in vec4 a_frameBlend; // xy=\u4E0B\u4E00\u5E27\u5E8F\u53F7/\u5E27\u95F4\u6DF7\u5408\u6743\u91CD zw=rotation.x/rotation.y
|
|
74
402
|
uniform mat4 u_mvp;
|
|
403
|
+
// \u5B98\u65B9 g_RefractAmount\uFF08common_particles.h \u7684 uniform \u58F0\u660E\uFF1A\u9ED8\u8BA4 0.05\u3001range [-1,1]\uFF09
|
|
404
|
+
uniform float u_refractScale;
|
|
75
405
|
// \u5E8F\u5217\u5E27 uv \u53D8\u6362\u8868\uFF08TEXS \u5E27\u77E9\u5F62\u5F52\u4E00\u5316\u540E\u7684 offset/scale\uFF09\uFF0C\u6700\u591A 128 \u5E27
|
|
76
406
|
// \uFF08matrix spritesheet 72 \u6709 71 \u5E27\uFF0C\u65E7\u4E0A\u9650 64 \u4F1A\u4E22\u672B\u5C3E\u5B57\u7B26\uFF09
|
|
77
407
|
uniform int u_frameCount;
|
|
78
408
|
uniform vec4 u_frames[128]; // xy=offset zw=scale
|
|
409
|
+
out vec4 v_refract; // \u5B98\u65B9 v_ScreenTangents\uFF1Axy=\u7CBE\u7075 x \u8F74\u3001zw=\u7CBE\u7075 y \u8F74\uFF08\u5DF2\u4E58 Refract Amount\uFF09
|
|
79
410
|
out vec2 v_uv;
|
|
411
|
+
out vec2 v_uv2; // \u4E0B\u4E00\u5E27\u7684 uv\uFF08\u540C\u4E00 quad \u4F4D\u7F6E\u3001\u6362\u5E27\u77E9\u5F62\uFF09
|
|
412
|
+
out float v_frameMix; // \u5E27\u95F4\u6DF7\u5408\u6743\u91CD\uFF080 = \u4E0D\u6DF7\u5408\uFF0C\u786C\u5207\uFF09
|
|
80
413
|
out vec4 v_color;
|
|
81
414
|
void main(){
|
|
82
415
|
float size = a_sizeRot.x;
|
|
83
|
-
float
|
|
84
|
-
float
|
|
416
|
+
float rz = a_sizeRot.y;
|
|
417
|
+
float rx = a_frameBlend.z;
|
|
418
|
+
float ry = a_frameBlend.w;
|
|
419
|
+
// \u5B98\u65B9 ComputeParticleTangents\uFF1Aright/up = \u65CB\u8F6C\u57FA\uFF08Rz\xB7Rx\xB7Ry\uFF09\u7684\u4E24\u4E2A\u8F74\u3002\u6B63\u4EA4\u6295\u5F71\u4E0B
|
|
420
|
+
// \u7CBE\u7075\u7684\u5C4F\u5E55\u5F62\u72B6 = \u8FD9\u4E24\u4E2A\u8F74\u5728\u5C4F\u5E55\u5E73\u9762\u7684\u6295\u5F71\uFF08x/y \u4FA7\u503E \u21D2 \u5BF9\u5E94\u8F74\u6309 cos \u538B\u7F29\uFF09\u3002
|
|
421
|
+
// z \u7684\u7B26\u53F7\u6CBF\u7528\u65E2\u6709\u6807\u5B9A\uFF08652 \u4E2A\u7EAF z \u6A21\u578B\u7684\u671D\u5411\u9010\u4F4D\u4E0D\u80FD\u53D8\uFF09\uFF1Aright=(cos rz, sin rz)\u3001
|
|
422
|
+
// up=(-sin rz, cos rz)\uFF1Bx/y \u7684\u4EA4\u53C9\u9879\u6309\u5B98\u65B9 Rz\xB7Rx\xB7Ry \u7684\u987A\u5E8F\u5C55\u5F00\u3002
|
|
423
|
+
float cz = cos(rz), sz = sin(rz);
|
|
424
|
+
float cx = cos(rx), sx = sin(rx);
|
|
425
|
+
float cy = cos(ry), sy = sin(ry);
|
|
426
|
+
// R = Rz * Rx * Ry\uFF08\u5217\u5411\u91CF\u7EA6\u5B9A\uFF0C\u4E0E\u5B98\u65B9 mul(mul(Rz,Rx),Ry) \u540C\u5E8F\uFF09
|
|
427
|
+
vec2 rightXY = vec2(cz * cy - sz * sx * sy, sz * cy + cz * sx * sy);
|
|
428
|
+
vec2 upXY = vec2(-sz * cx, cz * cx);
|
|
85
429
|
// \u5148\u6309 size \u4E0E\u975E\u7B49\u6BD4\u62C9\u4F38\u5C55\u5F00\uFF0C\u518D\u65CB\u8F6C\uFF08\u987A\u5E8F\u53CD\u4E86\u4F1A\u628A\u62C9\u4F38\u65B9\u5411\u4E5F\u8F6C\u8D70\uFF09
|
|
86
430
|
vec2 corner = a_corner * size * a_stretchFrame.xy;
|
|
87
|
-
vec2 rotated = vec2(corner.x *
|
|
431
|
+
vec2 rotated = vec2(corner.x * rightXY.x + corner.y * upXY.x,
|
|
432
|
+
corner.x * rightXY.y + corner.y * upXY.y);
|
|
88
433
|
gl_Position = u_mvp * vec4(a_pos.xy + rotated, a_pos.z, 1.0);
|
|
89
434
|
// quad \u89D2 \u2192 \u8D34\u56FE uv\u3002\u4E16\u754C y \u5DF2\u7FFB\u8F6C\u5230\u6295\u5F71\u7A7A\u95F4\uFF08y \u5411\u4E0B\uFF09\uFF0C\u6545 quad \u7684 +y \u89D2
|
|
90
435
|
// \u5BF9\u5E94\u5C4F\u5E55\u4E0A\u65B9\uFF0C\u5E94\u91C7\u6837\u7EB9\u7406\u9876\u884C v=1\uFF08\u4E0E renderer.js \u7684 layerQuadVerts \u540C\u7EA6\u5B9A\uFF09\u3002
|
|
91
436
|
// a_vrange \u8BA9 rope \u6BB5\u4E24\u7AEF\u5404\u53D6\u81EA\u5DF1\u7684 v\uFF08\u6CBF\u7EF3\u8FDE\u7EED\u6E10\u53D8\uFF09\uFF1B\u666E\u901A\u7CBE\u7075\u662F (0,1) \u6052\u7B49\u3002
|
|
92
437
|
vec2 uv = vec2(a_corner.x + 0.5, mix(a_vrange.x, a_vrange.y, a_corner.y + 0.5));
|
|
438
|
+
// \u5B98\u65B9 ComputeScreenRefractionTangents\uFF1A\u628A\u7CBE\u7075\u7684 x/y \u8F74\uFF08\u5F52\u4E00\u5316\u65CB\u8F6C\u57FA\uFF09\u6295\u5F71\u5230\u5C4F\u5E55\u53F3/\u4E0A
|
|
439
|
+
// \u65B9\u5411\u540E\u4E58 g_RefractAmount\u30022D \u6B63\u4EA4\u573A\u666F\u91CC\u89C6\u56FE\u53F3=(1,0)\u3001\u89C6\u56FE\u4E0A=(0,1)\uFF08\u5C4F\u5E55 y \u5411\u4E0B\uFF09\uFF0C
|
|
440
|
+
// \u4E8E\u662F\u5207\u7EBF\u5C31\u662F\u65CB\u8F6C\u540E\u7684\u4E24\u4E2A\u8F74\u672C\u8EAB \u2014\u2014 \u7CBE\u7075\u4E00\u8F6C\uFF0C\u6298\u5C04\u504F\u79FB\u65B9\u5411\u8DDF\u7740\u8F6C\uFF08\u65E7\u5B9E\u73B0\u6052\u6309\u5C4F\u5E55\u8F74\uFF09\u3002
|
|
441
|
+
v_refract = vec4(rightXY, upXY) * u_refractScale;
|
|
442
|
+
v_uv2 = uv;
|
|
443
|
+
v_frameMix = 0.0;
|
|
93
444
|
if (u_frameCount > 0) {
|
|
94
445
|
// \u5E27\u77E9\u5F62\u4EE5\u5DE6\u4E0A\u4E3A\u539F\u70B9\uFF08TEXS \u662F top-down \u50CF\u7D20\u5750\u6807\uFF09\uFF0C\u6545\u5148\u628A v \u7FFB\u6210 top-down
|
|
446
|
+
vec2 uv2 = uv;
|
|
95
447
|
int fi = int(a_stretchFrame.z);
|
|
96
448
|
fi = clamp(fi, 0, u_frameCount - 1);
|
|
97
449
|
vec4 fr = u_frames[fi];
|
|
98
450
|
vec2 cell = vec2(uv.x, 1.0 - uv.y) * fr.zw + fr.xy;
|
|
99
451
|
uv = vec2(cell.x, 1.0 - cell.y);
|
|
452
|
+
// \u5B98\u65B9 ComputeSpriteFrame\uFF1AnextFrame = min(n-1, cur+1)\u3001frameBlend = frac(lifetime*n)\uFF1B
|
|
453
|
+
// frag \u7528 mix(\u5F53\u524D\u5E27, \u4E0B\u4E00\u5E27, blend) \u505A\u4EA4\u53C9\u6DE1\u5165\uFF08\u786C\u5207\u4F1A\u8DF3\u5E27\uFF09\u3002
|
|
454
|
+
int fj = clamp(int(a_frameBlend.x), 0, u_frameCount - 1);
|
|
455
|
+
vec4 fr2 = u_frames[fj];
|
|
456
|
+
vec2 cell2 = vec2(uv2.x, 1.0 - uv2.y) * fr2.zw + fr2.xy;
|
|
457
|
+
uv2 = vec2(cell2.x, 1.0 - cell2.y);
|
|
458
|
+
v_uv2 = uv2;
|
|
459
|
+
v_frameMix = clamp(a_frameBlend.y, 0.0, 1.0);
|
|
100
460
|
}
|
|
101
461
|
v_uv = uv;
|
|
102
462
|
v_color = a_color;
|
|
103
|
-
}`,
|
|
463
|
+
}`,n=`#version 300 es
|
|
104
464
|
precision mediump float;
|
|
105
465
|
uniform sampler2D u_tex;
|
|
106
466
|
uniform sampler2D u_normal;
|
|
107
467
|
uniform sampler2D u_scene;
|
|
108
468
|
uniform int u_refract;
|
|
109
469
|
uniform int u_sampleScene;
|
|
470
|
+
// [we-scene patch 2026-09-20] \u53CD\u7167\u7387\u662F **R8 \u5355\u901A\u9053**\uFF08WE \u8BED\u4E49 vec4(1,1,1,r)\uFF09\uFF1A
|
|
471
|
+
// \u4E0A\u4F20\u65F6\u6309 GL_R8 \u5B58\uFF08\u7701 4 \u500D\u663E\u5B58\uFF09\uFF0C\u8FD9\u91CC\u8865\u4E0A\u300Crgb \u767D\u3001\u5F62\u72B6\u53D6 .r\u300D\u7684\u6620\u5C04\u3002
|
|
472
|
+
uniform int u_albedoR8;
|
|
473
|
+
// \u6CD5\u7EBF\u901A\u9053\u5E03\u5C40\uFF1A1 = \u5B98\u65B9\u6253\u5305\uFF08x \u5728 A\u3001\u8499\u7248\u5728 R\uFF09\uFF0C0 = \u6211\u4EEC\u81EA\u5DF1\u7684\u751F\u6210\u5668/RG88 \u8F6C\u6362\uFF08x \u5728 R\u3001A \u6052 255\uFF09
|
|
474
|
+
uniform int u_normalPacked;
|
|
110
475
|
uniform vec2 u_resolution;
|
|
111
|
-
|
|
476
|
+
in vec4 v_refract;
|
|
112
477
|
in vec2 v_uv;
|
|
478
|
+
in vec2 v_uv2;
|
|
479
|
+
in float v_frameMix;
|
|
113
480
|
in vec4 v_color;
|
|
114
481
|
out vec4 fragColor;
|
|
115
482
|
void main(){
|
|
116
483
|
vec4 t = texture(u_tex, v_uv);
|
|
117
|
-
|
|
484
|
+
// \u5E27\u95F4\u4EA4\u53C9\u6DE1\u5165\uFF08\u5B98\u65B9 SPRITESHEETBLEND\uFF1Amix(frame, nextFrame, frac(lifetime*n))\uFF09\u3002
|
|
485
|
+
// \u6CD5\u7EBF\u69FD\u4ECD\u53EA\u91C7\u5F53\u524D\u5E27 \u2014\u2014 \u5B98\u65B9 frag \u4E5F\u662F\u53EA\u5BF9 albedo \u505A mix\u3002
|
|
486
|
+
if (v_frameMix > 0.0) t = mix(t, texture(u_tex, v_uv2), v_frameMix);
|
|
487
|
+
// R8 \u4E0A\u4F20\uFF08GL_R8\uFF09\u91C7\u6837\u5F97\u5230 (r,0,0,1)\uFF1A\u6309 WE \u8BED\u4E49\u6062\u590D\u6210\u300Crgb \u767D + \u5F62\u72B6\u5728 alpha\u300D
|
|
488
|
+
vec3 albedoRgb = u_albedoR8 == 1 ? vec3(1.0) : t.rgb;
|
|
489
|
+
float albedoA = u_albedoR8 == 1 ? t.r : t.a;
|
|
490
|
+
vec4 col = vec4(albedoRgb * v_color.rgb, albedoA * v_color.a);
|
|
118
491
|
if (u_refract == 1) {
|
|
119
492
|
// genericparticle REFRACT\uFF1A\u69FD 0 \u7ECF\u5E38\u662F\u7A7A\u767D\u767D\u56FE\uFF08Rain2 \u7684
|
|
120
493
|
// "particles 256x1280 blank"\u3001firework \u7684 util/white\uFF09\uFF0C\u6C34\u73E0\u5F62\u72B6\u5728\u6CD5\u7EBF\u91CC\u3002
|
|
121
|
-
// \
|
|
122
|
-
// \
|
|
494
|
+
// \u5B98\u65B9\u505A\u6CD5\uFF1Aalbedo **\u7167\u5E38**\u53C2\u4E0E\uFF08\u7A7A\u767D\u767D\u56FE = alpha 1 \u7684\u767D quad\uFF09\uFF0C\u753B\u9762\u8272\u662F
|
|
495
|
+
// \u300Ccolor.rgb *= scene(uv+offset)\u300D**\u4E58\u8FDB\u53BB**\u7684 \u2014\u2014 \u6CD5\u7EBF\u5E73\u5766\u5904 offset=0\uFF0C\u91C7\u5230\u7684\u5C31\u662F
|
|
496
|
+
// \u539F\u753B\u9762\uFF0C\u5929\u7136\u300C\u9690\u5F62\u300D\uFF1B\u53EA\u6709\u6CD5\u7EBF\u504F\u79BB\u5904\u624D\u51FA\u73B0\u626D\u66F2\uFF0C\u6240\u4EE5\u7A7A\u767D albedo \u4E0D\u4F1A\u753B\u6210\u767D\u5757\u3002
|
|
123
497
|
vec4 ntex = texture(u_normal, v_uv);
|
|
124
|
-
// \
|
|
125
|
-
// \
|
|
126
|
-
|
|
127
|
-
// \
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
498
|
+
// \u5B98\u65B9 DecompressNormalWithMask\uFF08common_fragment.h\uFF09\u5BF9**\u975E RG88** \u7684\u6CD5\u7EBF\u4E00\u5F8B
|
|
499
|
+
// normal.xw = normal.wx\uFF1Ax \u2190 \u539F A \u901A\u9053\u3001y \u2190 G\uFF0C\u8499\u7248 = normal.a\uFF08= \u539F R \u901A\u9053\uFF09\u3002
|
|
500
|
+
// \u4E5F\u5C31\u662F\u5B98\u65B9\u6253\u5305\u6CD5\u7EBF\u662F\u300Cx \u5728 A\u3001\u5F62\u72B6/\u8499\u7248\u5728 R\u300D\uFF08DXT5nm \u4E0E RGBA8888 \u90FD\u662F\u8FD9\u6761\uFF0C
|
|
501
|
+
// \u53EA\u662F\u538B\u7F29\u65CF\u591A\u4E00\u4E2A 0.965 \u7684\u7F29\u653E\uFF0C2% \u91CF\u7EA7\uFF09\uFF1A\u5B9E\u6D4B
|
|
502
|
+
// particle/water/rain_drops_sheet_normal\uFF08RGBA8888\uFF09R=35/255\uFF08\u6C34\u6EF4\u526A\u5F71\uFF09\u3001G=190\u3001A=190\uFF1B
|
|
503
|
+
// particle/water/splash_1_normal\uFF08DXT5nm\uFF09R=11.8\uFF08\u6C34\u82B1\u526A\u5F71\uFF09\u3001G=128\u3001A=128\u3002
|
|
504
|
+
// \u6211\u4EEC\u81EA\u5DF1\u7684\u751F\u6210\u5668\uFF08heightToNormal\uFF09\u4E0E RG88 \u8F6C\u6362\u7ED3\u679C\u662F (x,y,z,255)\uFF1Ax \u5728 R\u3001\u8499\u7248\u6052 1\u3002
|
|
505
|
+
// \u65E7\u5B9E\u73B0\u6309\u300CR \u5F88\u4EAE\u300D\u7684\u542F\u53D1\u5F0F\u731C DXT5nm \u2014\u2014 \u4E0A\u9762\u4E24\u5F20\u7684 R \u662F**\u526A\u5F71**\uFF08\u5F88\u6697\uFF09\uFF0C\u731C\u53CD\u4E86\uFF1A
|
|
506
|
+
// x \u53D6\u6210\u526A\u5F71\uFF080/1 \u4E8C\u503C\uFF09\u800C\u8499\u7248\u53D6\u6210\u5E38\u91CF A\uFF0C\u6298\u5C04\u65B9\u5411\u4E0E\u4F5C\u7528\u8303\u56F4\u90FD\u9519\uFF083801012392 \u7684
|
|
507
|
+
// \u300C\u548C\u539F\u7248\u7D20\u6750\u4E0B\u6709\u7EC6\u5FAE\u5DEE\u522B\u300D\uFF09\u3002\u73B0\u5728\u5E03\u5C40\u7531\u8D34\u56FE\u5C42\u5224\u5B9A\u540E\u7ECF uniform \u4F20\u8FDB\u6765\u3002
|
|
508
|
+
vec2 nxy = u_normalPacked == 1 ? (ntex.ag * 2.0 - 1.0) : (ntex.rg * 2.0 - 1.0);
|
|
509
|
+
float nMask = min(u_normalPacked == 1 ? ntex.r : ntex.a, 1.0);
|
|
510
|
+
// \u5B98\u65B9 alpha \u5C31\u662F albedo.a \xD7 \u9876\u70B9 alpha\uFF08\u4E0D\u518D\u62FF\u6CD5\u7EBF\u504F\u79BB\u9876\u66FF \u2014\u2014 \u90A3\u662F\u4E3A\u4E86\u7ED5\u5F00
|
|
511
|
+
// \u300C\u6CA1\u91C7\u5230\u753B\u9762\u65F6\u4F1A\u628A\u767D quad \u753B\u51FA\u6765\u300D\u7684\u65E7\u5B9E\u73B0\uFF0C\u73B0\u5728 rgb \u6052\u4E3A albedo\xD7\u9876\u70B9\u8272\xD7\u753B\u9762\uFF09\u3002
|
|
512
|
+
float alpha = albedoA * v_color.a;
|
|
513
|
+
vec3 rgb = albedoRgb * v_color.rgb;
|
|
132
514
|
if (u_sampleScene == 1) {
|
|
133
515
|
vec2 screenUV = gl_FragCoord.xy / max(u_resolution, vec2(1.0));
|
|
134
|
-
|
|
135
|
-
|
|
516
|
+
// \u5B98\u65B9 frag\uFF1Aoffset = v_ScreenTangents.xy*normal.x + v_ScreenTangents.zw*normal.y\uFF0C
|
|
517
|
+
// \u518D\u4E58 normal.a\uFF08\u8499\u7248\uFF09\xD7 v_Color.a\uFF08\u7C92\u5B50 alpha\uFF09\u3002y \u7684\u7B26\u53F7\u5728\u5B98\u65B9\u91CC\u4E3A\u9002\u914D GLSL \u53D6\u8D1F\uFF1B
|
|
518
|
+
// \u6211\u4EEC\u7684\u5207\u7EBF\u672C\u6765\u5C31\u5728\u5C4F\u5E55 y \u5411\u4E0B\u7A7A\u95F4\uFF0C\u6545\u4E0D\u7FFB\u3002
|
|
519
|
+
vec2 offset = vec2(
|
|
520
|
+
v_refract.x * nxy.x + v_refract.z * nxy.y,
|
|
521
|
+
v_refract.y * nxy.x + v_refract.w * nxy.y
|
|
522
|
+
) * (nMask * v_color.a);
|
|
523
|
+
vec3 scene = texture(u_scene, clamp(screenUV + offset, 0.0, 1.0)).rgb;
|
|
524
|
+
// \u5B98\u65B9\u662F\u300Ccolor.rgb *= scene\u300D\uFF08albedo \xD7 \u9876\u70B9\u8272 \xD7 \u753B\u9762\uFF09\uFF0C\u4E0D\u662F\u7528\u753B\u9762\u66FF\u6362 albedo
|
|
525
|
+
rgb = albedoRgb * v_color.rgb * scene;
|
|
136
526
|
}
|
|
137
527
|
col = vec4(rgb, alpha);
|
|
138
528
|
if (col.a < 0.004) discard;
|
|
139
529
|
}
|
|
140
530
|
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 ai(e){const n=e&&e.passes&&e.passes[0]&&e.passes[0].combos;return!!(n&&Number(n.REFRACT)===1)}function ec(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 ci(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 Jr(e,n){return e||n?Math.atan2(n,e)-Math.PI/2:0}function li(e,n){return e&&e.kind==="ropetrail"?Math.max(1,n||1):1}function ui(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 fi(e){if(!e||e.kind!=="ropetrail")return 0;const n=Number(e.length);return Number.isFinite(n)&&n>0?n:.2}function eo(e){return e.life>0?e.age/e.life:0}class tc{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 nc{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,re(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(re(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:re(i.id,0),lockToPointer:!!i.locktopointer||(re(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,re(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,re(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=re(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 tc)}_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:si(c.distancemin),distanceMax:si(c.distancemax),sign:c.sign?be(c.sign):null,rate:re(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:re(c.instantaneous,0),speedMin:re(c.speedmin,0),speedMax:re(c.speedmax,0),controlPoint:c.controlpoint!==void 0&&c.controlpoint!==null?re(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:re(c.min,1),max:re(c.max,1),exp:re(c.exponent,1)};break;case"sizerandom":this.init.size={min:re(c.min,1),max:re(c.max,1),exp:re(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:re(c.min,1),max:re(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:re(c.exponent,1)};break;case"angularvelocityrandom":this.init.angularVelocity={min:be(c.min),max:be(c.max),exp:re(c.exponent,1)};break;case"mapsequencearoundcontrolpoint":this.init.mapAround={count:Math.max(1,re(c.count,1)),bounds:be(c.bounds,[0,1]),speedMin:be(c.speedmin),speedMax:be(c.speedmax,[0,0,0]),cp:re(c.controlpoint,0)},this._mapAroundSeq=0;break;case"turbulentvelocityrandom":this.init.turbulentVelocity={scale:re(c.scale,.1),offset:re(c.offset,0),speedMin:re(c.speedmin,0),speedMax:re(c.speedmax,0),phaseMax:re(c.phasemax,0),timeScale:re(c.timescale,0),audioMode:re(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:re(c.drag,0)};break;case"angularmovement":this.ops.angularMovement={force:be(c.force),drag:re(c.drag,0)};break;case"alphafade":this.ops.alphaFade={fadeIn:re(c.fadeintime,.1),fadeOut:re(c.fadeouttime,.9)};break;case"alphachange":this.ops.alphaChange={startTime:re(c.starttime,0),endTime:re(c.endtime,1),startValue:re(c.startvalue,1),endValue:re(c.endvalue,0)};break;case"sizechange":this.ops.sizeChange={startTime:re(c.starttime,0),endTime:re(c.endtime,1),startValue:re(c.startvalue,1),endValue:re(c.endvalue,1)};break;case"colorchange":this.ops.colorChange={startTime:re(c.starttime,0),endTime:re(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:re(c.scale,.01),speedMin:re(c.speedmin,0),speedMax:re(c.speedmax,0),timeScale:re(c.timescale,1),phaseMin:re(c.phasemin,0),phaseMax:re(c.phasemax,0),mask:c.mask!==void 0?be(c.mask,[1,1,1]):[1,1,1]});break;case"oscillatealpha":this.ops.oscAlpha={freqMin:re(c.frequencymin,re(c.frequencymax,1)),freqMax:re(c.frequencymax,1),scaleMin:re(c.scalemin,0),scaleMax:re(c.scalemax,1),phaseMax:re(c.phasemax,wt)};break;case"oscillatesize":this.ops.oscSize={freqMin:re(c.frequencymin,re(c.frequencymax,1)),freqMax:re(c.frequencymax,re(c.frequencymin,1)),scaleMin:re(c.scalemin,1),scaleMax:re(c.scalemax,1),phaseMax:re(c.phasemax,wt)};break;case"oscillateposition":this.ops.oscPos={freqMin:re(c.frequencymin,re(c.frequencymax,.5)),freqMax:re(c.frequencymax,.5),scaleMin:re(c.scalemin,0),scaleMax:re(c.scalemax,1),phaseMin:re(c.phasemin,0),phaseMax:re(c.phasemax,wt),mask:c.mask!==void 0?be(c.mask,[1,1,0]):[1,1,0]};break;case"controlpointattract":this.ops.attract.push({cp:re(c.controlpoint,0),origin:be(c.origin),scale:re(c.scale,0),threshold:re(c.threshold,0)});break;case"vortex":this.ops.vortex.push({axis:be(c.axis,[0,0,1]),offset:be(c.offset),distanceInner:re(c.distanceinner,0),distanceOuter:re(c.distanceouter,0),speedInner:re(c.speedinner,0),speedOuter:re(c.speedouter,0),cp:c.controlpoint!==void 0&&c.controlpoint!==null?re(c.controlpoint,0):0,audioMode:re(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:re(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:re(c&&c.length,u==="spritetrail"?.1:u==="ropetrail"?.2:0),maxLength:re(c&&c.maxlength,0),minLength:re(c&&c.minlength,0),subdivision:re(c&&c.subdivision,1),segments:re(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=ui(a);this.trailSegments=c,this.trailDuration=fi(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=ai(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]+Re(-f[0],f[0])+(p?p[0]:0),o.y=s[1]+Re(-f[1],f[1])+(p?p[1]:0),o.z=s[2]+Re(-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()*wt,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=Re(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=Re(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)*wt,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,ii(a.life.min,a.life.max,a.life.exp)*this.lifetimeMul):1,o.baseSize=a.size?ii(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?Re(a.alpha.min,a.alpha.max):1)*this.opacityMul,o.alpha=o.baseAlpha,a.velocity&&(o.vx+=Re(a.velocity.min[0],a.velocity.max[0])*c,o.vy+=Re(a.velocity.min[1],a.velocity.max[1])*c,o.vz+=Re(a.velocity.min[2],a.velocity.max[2])*c),a.turbulentVelocity){const f=a.turbulentVelocity,p=f.audioMode?Zr(f.audioBounds,this._audioLevel||0):1,d=Re(f.speedMin,f.speedMax)*c*p,y=this.simTime*(f.timeScale||0),x=Qr(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=Re(a.rotation.min[2],a.rotation.max[2])),a.angularVelocity&&(o.rotVel=Re(a.angularVelocity.min[2],a.angularVelocity.max[2]));const l=this.ops;if(l.oscPos&&(o.oscFreq=Re(l.oscPos.freqMin,l.oscPos.freqMax),o.oscAmp=Re(l.oscPos.scaleMin,l.oscPos.scaleMax),o.oscPhase=Re(l.oscPos.phaseMin,l.oscPos.phaseMax)+o.seed*wt),l.oscAlpha&&(o.oscAFreq=Re(l.oscAlpha.freqMin,l.oscAlpha.freqMax),o.oscAPhase=Math.random()*(l.oscAlpha.phaseMax||wt)),l.oscSize&&(o.oscSFreq=Re(l.oscSize.freqMin,l.oscSize.freqMax),o.oscSPhase=Math.random()*(l.oscSize.phaseMax||wt)),l.turbulence.length){const f=l.turbulence[0];o.turbSpeed=Re(f.speedMin,f.speedMax),o.turbPhase=Re(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=Qr(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?Zr(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=Qr(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*wt+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*wt+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*wt+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=Zr(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=li(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),Fe=O(te.x,te.y),_e=Fe[0]-le[0],Ye=Fe[1]-le[1],Ve=Math.hypot(_e,Ye),Ne=(Math.abs(Z.size)+Math.abs(te.size))*.5*v;Ne>0&&(M[h++]=(le[0]+Fe[0])*.5,M[h++]=(le[1]+Fe[1])*.5,M[h++]=0,M[h++]=Ne,M[h++]=Math.atan2(-_e,Ye),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++]=Ve/Ne,M[h++]=0,M[h++]=eo(Z),M[h++]=eo(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,Fe=Z.y,_e=1,Ye=1,Ve=Z.rot,Ne=A,qe=_,Ue,ye;if(a&&Z.trail){le=Z.trail[te*3],Fe=Z.trail[te*3+1];const he=l>1?te/(l-1):0;_e=1-he,Ye=1-he*.55;let De=0,Pe=0;te+1<l?(De=Z.trail[te*3]-Z.trail[(te+1)*3],Pe=Z.trail[te*3+1]-Z.trail[(te+1)*3+1]):te>0?(De=Z.trail[(te-1)*3]-Z.trail[te*3],Pe=Z.trail[(te-1)*3+1]-Z.trail[te*3+1]):(De=Z.vx,Pe=Z.vy);const Ze=O(le,Fe),Be=O(le-De,Fe-Pe),Ae=Ze[0]-Be[0],nt=Ze[1]-Be[1],rt=Math.hypot(Ae,nt),Ft=Math.max(.001,Math.abs(Z.size)*v*Ye);rt>.001?(Ve=Jr(Ae,nt),Ue=(Ze[0]+Be[0])*.5,ye=(Ze[1]+Be[1])*.5,qe=Math.max(_,rt/Ft)):(Ue=Ze[0],ye=Ze[1])}else{const he=O(le,Fe);Ue=he[0],ye=he[1]}if(c){const he=O(Z.x,Z.y);Ue=he[0],ye=he[1];const De=O(Z.x+Z.vx,Z.y+Z.vy);Ve=Jr(De[0]-he[0],De[1]-he[1]);const Pe=ci(Math.hypot(Z.vx,Z.vy),c.length,c.minLength,c.maxLength);qe=_*Pe}M[h++]=Ue,M[h++]=ye,M[h++]=0,M[h++]=Math.abs(Z.size)*v*Ye,M[h++]=Ve,M[h++]=Z.r*g,M[h++]=Z.g*g,M[h++]=Z.b*g,M[h++]=Z.alpha*_e,M[h++]=Ne,M[h++]=qe,M[h++]=Z.frame,M[h++]=0,M[h++]=1}}const W=this._prog;s.useProgram(W.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(W.uniTex,0),s.uniformMatrix4fv(W.uniMvp,!1,n);const X=this.refract&&this.normalTex&&this.normalTex.glTex;if(W.uniRefract&&s.uniform1i(W.uniRefract,X?1:0),X){s.activeTexture(s.TEXTURE1),s.bindTexture(s.TEXTURE_2D,this.normalTex.glTex),W.uniNormal&&s.uniform1i(W.uniNormal,1);const J=this.blend!=="additive";if(W.uniSampleScene&&s.uniform1i(W.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),W.uniScene&&s.uniform1i(W.uniScene,2),W.uniResolution&&s.uniform2f(W.uniResolution,Z,te),W.uniRefractScale&&s.uniform1f(W.uniRefractScale,this.refractAmount||.04)}else s.activeTexture(s.TEXTURE2),s.bindTexture(s.TEXTURE_2D,this.texture.glTex),W.uniScene&&s.uniform1i(W.uniScene,2)}else W.uniNormal&&(s.activeTexture(s.TEXTURE1),s.bindTexture(s.TEXTURE_2D,this.texture.glTex),s.uniform1i(W.uniNormal,1),s.activeTexture(s.TEXTURE2),s.bindTexture(s.TEXTURE_2D,this.texture.glTex),W.uniScene&&s.uniform1i(W.uniScene,2),W.uniSampleScene&&s.uniform1i(W.uniSampleScene,0));const ie=this._frameUniformData();ie?(s.uniform1i(W.uniFrameCount,ie.count),s.uniform4fv(W.uniFrames,ie.arr)):s.uniform1i(W.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=Ja(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 rc=Object.freeze(Object.defineProperty({__proto__:null,ParticleSystem:nc,particleInstanceSegs:li,particlePassRefract:ai,rgbaIsBlankWhite:ec,ropeParticleV:eo,ropeTrailDuration:fi,ropeTrailHistoryCount:ui,spriteTrailLengthFactor:ci,spriteTrailRotation:Jr},Symbol.toStringTag,{value:"Module"})),$n=new Map,to=new Map;let dr=null;function oc(e,n){const t=String(e);to.set(t,n),$n.delete(t)}function ic(e){dr=typeof e=="function"?e:null}function sc(){to.clear(),dr=null,$n.clear()}function ac(){return Object.keys(Hn)}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 jn(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 pr(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 xn=e=>e*e*(3-2*e),di=e=>e*e*e*(e*(e*6-15)+10),no=(e,n,t)=>e+(n-e)*t,ae=(e,n)=>Math.exp(-(e*e)/(n*n));function sn(e,n,t,r){const o=Math.min(e,n,t-1-e,t-1-n);return o>=r?1:o/r}function zn(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 Ot(e,n,t){return zn(e,[n,t])}function $t(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*=sn(u,c,e,a),Se(i,(c*e+u)*4,x)}return{width:e,height:e,rgba:i}}function Rt(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):xn(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 Vn=4;function pi(e,n,t,r,o){const i=o===void 0?.85:o,s=new Uint8Array(e*n*4),a=n/Vn,c=pr(335009),u=Math.tan(t*Math.PI/180),l=e/2;for(let f=0;f<Vn;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 cc(e){if(e==="particle/nature/rain1"||e==="particle/nature/rain2"){const n=[];for(let t=0;t<Vn;t++)n.push({ou:0,ov:t/Vn,su:1,sv:1/Vn});return n}return null}function ro(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 hi(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 jn({width:e,height:e,rgba:o},.05)}function Wn(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=hi(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 mi(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 jn({width:e,height:e,rgba:n},.11)}function He(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 jn({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 gi(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 lc(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 bi(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=xn(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)*sn(i,o,e,r))}return{width:e,height:e,rgba:n}}function uc(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 fc(e){return!e||!e.rgba?e:uc(e.rgba)?Mt(e,2.8):e}const dc={"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 pc(e){if(!e)return null;const n=String(e);return/normal/i.test(n)?n:dc[n]||n+"_normal"}function hc(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 mc(e){if(Hn[e])return Hn[e]();const n=String(e).toLowerCase();return/normal/.test(n)?Ot(64,{r:.18,w:1},{r:.4,w:.2}):Ti(e)()}function yi(e,n,t){const r=pr(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=di(x),h=di(m);return no(no(s(c,d,y,x,m),s(c,d+1,y,x-1,m),M),no(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 vi(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 Kt(e,n,t,r,o,i,s){const a=i===void 0?1:i,c=s===void 0?200:s,u=256,l=yi(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=xn(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:vi(g,e,e)}function oo(e,n){const t=e,r=yi(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=xn(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=jn({width:t,height:t,rgba:o},.08);return t===e?f:vi(f,e,e)}function io(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 xi(e){const n=new Uint8Array(e*e*4),t=pr(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 hr(e,n){const t=n??19,r=pr(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)*sn(d,p,e,f))}return{width:e,height:e,rgba:l}}function so(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 gc(e){return Ot(e,{r:.1,w:1},{r:.3,w:.16})}function ao(e,n){const t=new Uint8Array(e*n*4);for(let r=0;r<n;r++){const o=(r+.5)/n,i=xn(Math.min(1,Math.min(o/.08,(1-o)/.08))),s=ae(o-.46,.24)*i,a=.5*(1-xn(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 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,c=ae(Math.hypot(s,a),.42),u=ae(Math.hypot(s-.34,a),.36),l=Math.max(0,c-u*1.08)*sn(i,o,e,r);Se(n,(o*e+i)*4,l)}return{width:e,height:e,rgba:n}}function Mi(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)*sn(i,o,e,r))}return{width:e,height:e,rgba:n}}function _i(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)*sn(a,s,e,o))}return jn({width:e,height:e,rgba:t},.03)}function co(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 Ai(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)*sn(i,o,e,r))}return{width:e,height:e,rgba:n}}const Hn={"particle/halo_6":()=>Ot(256,{r:.14,w:1},{r:.4,w:.17}),"particle/normal_splash":()=>Mt(gi(256),3.2),"particle/drop_normal":()=>Mt(ao(128,512),3.4),"particle/normal_ring_smooth":()=>Mt(ro(256,.55,.12),3.1),"particle/normal_pinch_rotate":()=>Mt(lc(256),2.8),"particle/water/rain_drops_sheet_normal":()=>Mt(io(256,512,2,4),3.6),"particle/bubbles/bubble1normal":()=>Mt(Wn(256,1),3.2),"particle/bubbles/bubble2_normal":()=>Mt(Wn(256,2),3.2),"particle/sharp_halo_normal":()=>Mt(zn(256,[{r:.035,w:1},{r:.09,w:.45},{r:.22,w:.08}]),3.4),"particle/beam/beam_0":()=>Rt(128,512,.46,!0),"particle/beam/beam_1":()=>Rt(128,512,.34,!0),"particle/beam/beam_2":()=>Rt(128,512,.22,!0),"particle/beam/beam_2_fade":()=>Rt(128,512,.24,!1),"particle/light/light_shafts_0":()=>Rt(128,512,.42,!0),"particle/light/light_shafts_1":()=>Rt(128,512,.3,!0),"particle/light/light_shafts_3":()=>Rt(128,512,.26,!0),"particle/light/light_shafts_5":()=>Rt(128,512,.23,!0),"particle/light/light_shafts_6":()=>Rt(128,512,.2,!0),"particle/nature/rosepetals":()=>mi(256),"particle/nature/leaves":()=>He(256,0),"particle/nature/leaves1":()=>He(256,1),"particle/nature/leaves2":()=>He(256,2),"particle/nature/leaves3":()=>He(256,3),"particle/nature/leaves5":()=>He(256,5),"particle/nature/leaves6":()=>He(256,6),"particle/nature/leaves7":()=>He(256,7),"particle/nature/leaves8":()=>He(256,8),"particle/nature/snow":()=>Mi(256),"particle/halo":()=>Ot(256,{r:.12,w:1},{r:.3,w:.15}),"particle/halo_1":()=>Ot(256,{r:.1,w:1},{r:.3,w:.13}),"particle/halo_2":()=>Ot(256,{r:.2,w:.9},{r:.44,w:.2}),"particle/halo_3":()=>zn(256,[{r:.045,w:1},{r:.13,w:.85},{r:.36,w:.15}]),"particle/halo_4":()=>Ot(256,{r:.085,w:1},{r:.28,w:.12}),"particle/halo_5":()=>zn(256,[{r:.04,w:1},{r:.11,w:.8},{r:.34,w:.17}]),"particle/sharp_halo":()=>zn(256,[{r:.035,w:1},{r:.09,w:.45},{r:.22,w:.08}]),"particle/chromaticdot":()=>gc(128),"particle/light/flare_0":()=>$t(256,6,.58,10,.08),"particle/light/flare_1":()=>$t(512,4,.62,14,.07),"particle/light/flare_2":()=>Ai(256),"particle/drop":()=>ao(128,512),"particle/nature/rain1":()=>pi(128,512,10,1,.78),"particle/nature/rain2":()=>pi(128,512,10,1.6,.66),"particle/water/rain_drops_sheet":()=>io(256,512,2,4),"particle/fog/fog1":()=>Kt(512,4,5,1,.4,.9,150),"particle/fog/fog2":()=>Kt(512,3,5,2,.45,.8,140),"particle/fog/fog3":()=>Kt(512,6,4,3,.36,1,150),"particle/smoke/smoke1":()=>Kt(512,3,5,7,.55,1.5,130),"particle/smoke/smoke2":()=>Kt(512,2,5,11,.6,1.7,120),"particle/smoke/smoke2light":()=>Kt(512,2,5,13,.4,1.7,110),"particle/misc/wave":()=>ro(512,.72,.085),"particle/misc/star_0":()=>$t(256,5,.62,8,.1),"particle/bubbles/bubble1":()=>Wn(256,1),"particle/bubbles/bubble2":()=>Wn(256,2),"particle/bubbles/bubble3":()=>Wn(256,3),"particle/debris/debris1":()=>xi(128),"particle/lightning/lightning1":()=>hr(256,3),"particle/lightning/lightning2":()=>hr(256,11),"particle/lightning/lightning3":()=>hr(256,19),"particle/fire/fire1":()=>oo(256,23),"particle/fire/fire2":()=>oo(256,41),"particle/star":()=>$t(256,4,.58,12,.09),"particle/shape/circle_wind":()=>bi(256),"particle/sickle":()=>wi(256),"particle/magic/glyph_4":()=>_i(256,4),"@sparkle":()=>$t(256,4,.6,16,.08),"@star":()=>$t(256,5,.62,8,.1),"@trail":()=>so(128,256)};function Ti(e){const n=String(e).toLowerCase();if(/normal/.test(n)){const t=hc(e);return t?()=>Mt(mc(t),2.8):()=>Mt(gi(128),2.6)}return/rosepetal|petal|sakura|blossom/.test(n)?()=>mi(256):/leaf|leaves|foliage/.test(n)?/leaves8/.test(n)?()=>He(256,8):/leaves7/.test(n)?()=>He(256,7):/leaves6/.test(n)?()=>He(256,6):/leaves5/.test(n)?()=>He(256,5):/leaves3/.test(n)?()=>He(256,3):/leaves2/.test(n)?()=>He(256,2):/leaves1/.test(n)?()=>He(256,1):()=>He(256,0):/circle_wind|windcircle/.test(n)?()=>bi(256):/fog|cloud|mist|vapor/.test(n)?()=>Kt(512,4,5,5,.4,.9,150):/smoke/.test(n)?()=>Kt(512,3,5,8,.55,1.5,130):/beam|shaft|ray|godray/.test(n)?()=>Rt(128,512,.3,!0):/flare/.test(n)?()=>Ai(256):/bubble/.test(n)?()=>hi(256,1):/ring|wave/.test(n)?()=>ro(512,.72,.085):/fire|flame|ember|ash/.test(n)?()=>oo(256,co(n)):/sickle|crescent|moon/.test(n)?()=>wi(256):/glyph|magic|rune/.test(n)?()=>_i(256,co(n)):/snowflake|雪花|snow/.test(n)?()=>Mi(256):/流星|meteor|shooting/.test(n)?()=>so(128,256):/star|星/.test(n)?()=>$t(256,5,.62,8,.1):/sparkle|glint|twinkle/.test(n)?()=>$t(256,4,.6,16,.08):/rain_drops_sheet|drops_sheet/.test(n)?()=>io(256,512,2,4):/drop|rain/.test(n)?()=>ao(128,512):/debris|dirt|rock/.test(n)?()=>xi(128):/lightning|bolt|arc/.test(n)?()=>hr(256,co(n)):/note|music/.test(n)?()=>$t(256,4,.55,8,.12):/trail|streak/.test(n)?()=>so(128,256):()=>Ot(256,{r:.12,w:1},{r:.3,w:.15})}function bc(e){if($n.has(e))return $n.get(e);let n=null;const t=to.get(e);if(t)try{n=t()}catch{n=null}if(!n&&dr)try{n=dr(e)}catch{n=null}if(!n&&Hn[e])try{n=Hn[e]()}catch{n=null}if(!n)try{n=Ti(e)()}catch{n=null}return n||(n=Ot(256,{r:.12,w:1},{r:.3,w:.15})),$n.set(e,n),n}function yc(e){return typeof e=="string"&&e.indexOf("particle/")===0}const vc=Object.freeze(Object.defineProperty({__proto__:null,buildBuiltinParticleTexture:bc,builtinParticleFrames:cc,isBuiltinParticleTextureName:yc,listBuiltinParticleTextureNames:ac,particleNormalNameForAlbedo:pc,prepareParticleNormalTexture:fc,resetParticleTextureFactories:sc,setParticleTextureFactory:oc,setParticleTextureProvider:ic},Symbol.toStringTag,{value:"Module"})),Si=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function Qt(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 Ei(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(Si);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 lo(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 Xn(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 mr(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 xc(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=Xn(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=Mc(e,n),A=_c(e,n,v.length),_=Tc(e,n,v),R=wc(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]),Fe=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,Fe||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]=lo(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?Qt(ie[Z],X[J]):Float32Array.from(X[J])}for(let J=0;J<v.length;J++)L[J]=Ei(ie[J]);if(_){const J=[];for(let Z=0;Z<v.length;Z++){const te=v[Z].parent;J[Z]=te>=0&&te<Z?Qt(J[te],_[Z]):Float32Array.from(_[Z])}for(let Z=0;Z<v.length;Z++)N[Z]=Qt(J[Z],L[Z])}}let H=1/0,K=-1/0,O=1/0,W=-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>W&&(W=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:Ac(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:W}}}function wc(e,n,t){const r=mr(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=Xn(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 Mc(e,n){const t=mr(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=Xn(n,i+13+64);o.push({id:a,parent:c>=0&&c<r?c:-1,matrix:u}),i=l.next}return o}function _c(e,n,t){const r=mr(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=Xn(n,o);o=l.next;const f=Xn(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 Ac(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 Tc(e,n,t){if(t.length===0)return null;const r=mr(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 Sc(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 Ec(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 uo(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++){Ec(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;Sc(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?lo(l[0],l[1],l[2],l[3],l[4],l[5],l[6],l[7],l[8],e._local[p]):lo(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?Qt(e._world[d],e._local[p],e._world[p]):e._world[p].set(e._local[p])}for(let p=0;p<i;p++)Qt(e._world[p],e.invBindWorld[p],e._tmp),e._skin.set(e._tmp,p*16);return e._skin}function Pi(e,n){return!e||!e.invBindWorld||!(n>=0&&n<e.invBindWorld.length)?null:Ei(e.invBindWorld[n])}function Pc(e,n){return Qt(e,n)}function Ci(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:Qt(e._world[t.bone],t.matrix);return null}function Li(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=Pi(e,t.bone);return r?Qt(r,t.matrix):null}return null}function fo(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 Cc(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=Li(a.puppet,s);if(!c)continue;const u=c[12],l=c[13],f=fo(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 Lc(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;uo(c,n,a.parent.animationLayers,l)}const u=Ci(c,a.name);if(!u){o.push(null);continue}o.push(fo(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 Rc=128,gr=24;function kc(e){const n=e.getParameter(e.MAX_VERTEX_UNIFORM_VECTORS)||256,t=Math.floor((n-32)/4);return Math.max(gr,Math.min(Rc,t))}const Fc=e=>`#version 300 es
|
|
531
|
+
}`,r=(u,l)=>{const d=t.createShader(u);if(t.shaderSource(d,l),t.compileShader(d),!t.getShaderParameter(d,t.COMPILE_STATUS))throw new Error("\u7C92\u5B50 shader: "+t.getShaderInfoLog(d));return d},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=72;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.enableVertexAttribArray(6),t.vertexAttribPointer(6,4,t.FLOAT,!1,c,56),t.vertexAttribDivisor(6,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"),uniNormalPacked:t.getUniformLocation(i,"u_normalPacked"),uniAlbedoR8:t.getUniformLocation(i,"u_albedoR8"),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 sw(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 aw(t,e,n){const r=Math.min(1,Math.max(0,(n-t)/(e-t||1)));return r*r*(3-2*r)}function bo(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 ow=32,cw=112,em=60/cw,tm=3.2;function lw(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 nm(t=20260830){const e=sw(t),n=lw(e),r=new Float32Array(64);for(let w=0;w<64;w++)r[w]=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),d=new Float32Array(32),f=new Float32Array(32),h=new Float32Array(16),p=new Float32Array(16),m={left64:u,right64:l,left32:d,right32:f,left16:h,right16:p,preL64:o,preR64:c,level:0,silent:!1};function g(w,A){const b=A.length/w.length;for(let v=0;v<w.length;v++){let x=0;const P=Math.floor(v*b),S=Math.floor((v+1)*b);for(let k=P;k<Math.max(P+1,S);k++)x+=A[k];w[v]=x/Math.max(1,S-P)}}function y(w){const A=w/em,b=A*4,v=(Math.floor(b)%16+16)%16,x=b-Math.floor(b),P=Math.exp(-x*em*14),S=w%ow,k=S>=27&&S<29,_=S>=29?(S-29)/3:0,I=S>=24&&S<27?1-(S-24)/3:0,B=k?0:_>0?_*_:I>0?0:1,V=k?0:I>0?.35:1,O=n.kick[v]*P*B,U=(n.snare[v]*P+n.hat[v]*P*.7)*B,W=n.hat[v]*P*B,ie=_>0?Math.pow(_,3)*(.4+.6*Math.abs(bo(b*2,7))):0;let we=0;for(let Y=0;Y<i;Y++){const oe=Y/i,he=Math.pow(1-oe*.85,1.6),Ae=V*(.5+.3*bo(A*.5+r[Y]*.05,Y%8)),Pe=V*(.5+.3*bo(A*.53+r[Y]*.05+31.7,Y%8+16));let Ce=Ae*(.35+.65*oe),Le=Pe*(.35+.65*oe);if(oe<.2){const nt=O*(1-oe/.2);Ce+=nt,Le+=nt}if(oe>=.12&&oe<.62){const nt=1-Math.abs(oe-.34)/.28;nt>0&&(Ce+=U*.55*nt,Le+=U*.35*nt)}if(oe>=.45){const nt=(oe-.45)/.55;Le+=W*.5*nt,Ce+=W*.3*nt}Ce+=ie*.5,Le+=ie*.5,Ce*=he,Le*=he;const Ne=Ce,De=Le;Ce=Math.min(1,Ce*tm),Le=Math.min(1,Le*tm);const Re=.06+oe*.2,Fe=bo(A*.13+Y*.35,11)*Re;let Xe=Math.min(1,Math.max(0,Ce*(1-Fe))),$e=Math.min(1,Math.max(0,Le*(1+Fe)));const Ye=k?.012:0;s[Y]=Math.max(Ye,Xe),a[Y]=Math.max(Ye,$e),o[Y]=Math.max(Ye,Math.max(0,Ne*(1-Fe))),c[Y]=Math.max(Ye,Math.max(0,De*(1+Fe))),Y<48&&(we+=(s[Y]+a[Y])*.5)}return u.set(s),l.set(a),g(d,s),g(f,a),g(h,s),g(p,a),m.level=Math.min(1,we/(48*1.2)),m.silent=k,m}return{update:y,snapshot:m,bands:i}}function rm(t,e){for(const n of t.values()){im(n.left,e.left64),im(n.right,e.right64);for(let r=0;r<n.average.length;r++)n.average[r]=(n.left[r]+n.right[r])*.5}}function im(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 uw(t,e,n,r,i,s,a){if(!e)return 0;const o=t.left.length-1,c=Math.max(0,Math.min(o,Math.round(n))),u=Math.max(c,Math.min(o,Math.round(r)));let l=0,d=0;for(let h=c;h<=u;h++)e===1?l+=t.left[h]:e===2?l+=t.right[h]:l+=(t.left[h]+t.right[h])*.5,d++;let f=d>0?l/d:0;return f=aw(i[0],i[1],f),f=Math.min(1,Math.max(0,Math.pow(f,s)))*a,f}let ps=1;function fw(t){const e=Number(t);ps=Number.isFinite(e)&&e>=0?e:1}function dw(){return ps}const sm={low:3e3,medium:6e3,high:12e3},hw={low:3,medium:5,high:8};let wo="high";function mw(t){wo=sm[t]?t:"high"}function pw(){return wo}const Dl=2048,gw=256,yw=64;let Nl=null;function bw(t){Nl=typeof t=="function"?t:null}let Ll=null;function ww(t){Ll=typeof t=="function"?t:null}function am(t){const e=Nl?Nl():null;t.bindFramebuffer(t.FRAMEBUFFER,e||null)}function om(t){const e=t&&t.passes&&t.passes[0]&&t.passes[0].combos;return!!(e&&Number(e.REFRACT)===1)}function vw(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 cm(t,e,n,r){let i=Math.abs(Number(t)||0)*(Number(e)||0);const s=Number(r)||0;return s>0&&(i=Math.min(s,i)),i}function lm(t,e){return t||e?Math.atan2(e,t)-Math.PI/2:0}function um(t,e){return t&&t.kind==="ropetrail"?Math.max(1,e||1):1}function fm(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 dm(t){if(!t||t.kind!=="ropetrail")return 0;const e=Number(t.length);return Number.isFinite(e)&&e>0?e:.2}function Ul(t){return t.life>0?t.age/t.life:0}class Aw{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.rotX=0,this.rotY=0,this.rotVelX=0,this.rotVelY=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.oscPFreq=[0,0,0],this.oscPAmp=[0,0,0],this.oscPPhase=[0,0,0],this.oscAPhase=0,this.oscAFreq=0,this.oscAAmp=[0,0],this.oscSPhase=0,this.oscSFreq=0,this.oscSAmp=[0,0],this.turbSpeed=0,this.turbPhase=0,this.trail=null,this.trailClock=0,this.seq=0}}class xw{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,Te(this.model.maxcount,100)*ps)),this.simTime=0,this.paused=!1,this.texture=null,this.normalTex=null,this.material=null,this.blend="translucent",this.refract=!1,this.refractAmount=.05,this.normalPacked=!1,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.frameBlend=(Te(n.flags,0)&2)===0,this.worldSpace=(Te(n.flags,0)&1)!==0,this.sequenceMul=Math.max(1,Math.round(Te(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:Te(s.id,0),lockToPointer:!!s.locktopointer||(Te(s.flags,0)&1)!==0,offset:ht(s.offset),x:0,y:0,z:0})),this.pointer=null,this._followParent=null,this._followMode=null,this._followOffset=[0,0,0],this._eventParent=null,this._eventType=null,this._eventOffset=null,this._eventChildren=[],this._burstQueue=[],this._bound=[],this._aliveCount=0,this._poolGen=0,this.ropeRenderer=null,this._seq=0,this._ropeOrder=[],this._ov={},this.timeScale=1,this._applyOverride(),this.startTime=Math.max(0,Math.min(30,Te(this.model.starttime,0))),this._warmed=!1,this._compile()}reapplyOverride(){this._applyOverride()}setColorOverride(e){const n=Array.isArray(e)?e:[e?.x||0,e?.y||0,e?.z||0];this._ov.color=[Number(n[0])||0,Number(n[1])||0,Number(n[2])||0]}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.timeScale=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,Te(this.model.maxcount,100)*ps));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=Te(this.model.maxcount,100),a=Number(i),o=Number.isFinite(a)?a:1,c=sm[wo];this.maxCount=Math.max(1,Math.min(c,Math.round(s*o*ps)));const u=hw[wo],l=o<=1?o:Math.min(o,u);this._ov.countMul=l*ps,this._ov.countRaw=o}else if(n==="alpha")this.opacityMul=Number(i),Number.isFinite(this.opacityMul)||(this.opacityMul=1);else if(n==="color"||n==="colorn"){const s=ht(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.timeScale=Number(i),Number.isFinite(this.timeScale)||(this.timeScale=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 Aw);this._aliveCount=0,this._poolGen=(this._poolGen||0)+1,this.allocTrails()}_compile(){const e=this.model;this.emitters=(e.emitter||[]).map(c=>({kind:c.name==="boxrandom"?"box":"sphere",origin:ht(c.origin),directions:ht(c.directions,[1,1,1]),distanceMin:Jh(c.distancemin),distanceMax:Jh(c.distancemax),sign:c.sign?ht(c.sign):null,rate:Te(c.rate,0),audioDriven:c.audioprocessingmode!==void 0,audioBounds:ht(c.audioprocessingbounds,[.8,1]),audioMode:Te(c.audioprocessingmode,0),audioExponent:Te(c.audioprocessingexponent,2),audioFreqStart:Te(c.audioprocessingfrequencystart,0),audioFreqEnd:Te(c.audioprocessingfrequencyend,1),fill:c.rate===void 0&&c.instantaneous===void 0&&c.audioprocessingmode===void 0,instantaneous:Te(c.instantaneous,0),speedMin:Te(c.speedmin,0),speedMax:Te(c.speedmax,0),controlPoint:c.controlpoint!==void 0&&c.controlpoint!==null?Te(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:Te(c.min,1),max:Te(c.max,1),exp:Te(c.exponent,1)};break;case"sizerandom":this.init.size={min:Te(c.min,1),max:Te(c.max,1),exp:Te(c.exponent,1)};break;case"colorrandom":this.init.color={min:Sr(c.min)||[0,0,0],max:Sr(c.max)||[255,255,255]};break;case"alpharandom":this.init.alpha={min:Te(c.min,1),max:Te(c.max,1)};break;case"velocityrandom":this.init.velocity={min:Sr(c.min)||[-32,-32,0],max:Sr(c.max)||[32,32,0]};break;case"rotationrandom":this.init.rotation={min:Sr(c.min)||[0,0,0],max:Sr(c.max)||[0,0,Gr],exp:Te(c.exponent,1)};break;case"angularvelocityrandom":this.init.angularVelocity={min:Sr(c.min)||[0,0,-5],max:Sr(c.max)||[0,0,5],exp:Te(c.exponent,1)};break;case"mapsequencearoundcontrolpoint":this.init.mapAround={count:Math.max(1,Te(c.count,1)),bounds:ht(c.bounds,[0,1]),speedMin:ht(c.speedmin),speedMax:ht(c.speedmax,[0,0,0]),cp:Te(c.controlpoint,0)},this._mapAroundSeq=0;break;case"turbulentvelocityrandom":this.init.turbulentVelocity={scale:Te(c.scale,.1),offset:Te(c.offset,0),speedMin:Te(c.speedmin,0),speedMax:Te(c.speedmax,0),phaseMax:Te(c.phasemax,0),timeScale:Te(c.timescale,0),audioMode:Te(c.audioprocessingmode,0),audioBounds:ht(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:ht(c.gravity),drag:Te(c.drag,0)};break;case"angularmovement":this.ops.angularMovement={force:ht(c.force),drag:Te(c.drag,0)};break;case"alphafade":this.ops.alphaFade={fadeIn:Te(c.fadeintime,.1),fadeOut:Te(c.fadeouttime,.9)};break;case"alphachange":this.ops.alphaChange={startTime:Te(c.starttime,0),endTime:Te(c.endtime,1),startValue:Te(c.startvalue,1),endValue:Te(c.endvalue,0)};break;case"sizechange":this.ops.sizeChange={startTime:Te(c.starttime,0),endTime:Te(c.endtime,1),startValue:Te(c.startvalue,1),endValue:Te(c.endvalue,1)};break;case"colorchange":this.ops.colorChange={startTime:Te(c.starttime,0),endTime:Te(c.endtime,1),startValue:c.startvalue!==void 0?ht(c.startvalue):null,endValue:ht(c.endvalue,[1,1,1])};break;case"turbulence":this.ops.turbulence.push({scale:Te(c.scale,.01),speedMin:Te(c.speedmin,0),speedMax:Te(c.speedmax,0),timeScale:Te(c.timescale,1),phaseMin:Te(c.phasemin,0),phaseMax:Te(c.phasemax,0),mask:c.mask!==void 0?ht(c.mask,[1,1,1]):[1,1,1]});break;case"oscillatealpha":case"oscillatesize":case"oscillateposition":{const u=c.name,l=u==="oscillateposition",d=Te(c.frequencymin,0);let f=c.frequencymax===void 0?l?5:10:Te(c.frequencymax);f===0&&(f=d);const h={freqMin:d,freqMax:f,scaleMin:Te(c.scalemin,u==="oscillatesize"?.8:0),scaleMax:Te(c.scalemax,u==="oscillatesize"?1.2:1),phaseMin:Te(c.phasemin,0),phaseMax:Te(c.phasemax,Gr)};u==="oscillatealpha"?this.ops.oscAlpha=h:u==="oscillatesize"?this.ops.oscSize=h:this.ops.oscPos={...h,mask:c.mask!==void 0?ht(c.mask,[1,1,0]):[1,1,0]};break}case"controlpointattract":this.ops.attract.push({cp:Te(c.controlpoint,0),origin:ht(c.origin),scale:Te(c.scale,0),threshold:Te(c.threshold,0)});break;case"vortex":this.ops.vortex.push({axis:ht(c.axis,[0,0,1]),offset:ht(c.offset),distanceInner:Te(c.distanceinner,0),distanceOuter:Te(c.distanceouter,0),speedInner:Te(c.speedinner,0),speedOuter:Te(c.speedouter,0),cp:c.controlpoint!==void 0&&c.controlpoint!==null?Te(c.controlpoint,0):0,audioMode:Te(c.audioprocessingmode,0),audioBounds:ht(c.audioprocessingbounds,[0,1])});break;case"remapvalue":this.ops.remap.push({output:c.output||"velocity",rangeMin:ht(c.outputrangemin),rangeMax:ht(c.outputrangemax),fn:c.transformfunction||"simplexnoise",inputScale:Te(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:Te(c&&c.length,u==="spritetrail"?.1:u==="ropetrail"?.2:0),maxLength:Te(c&&c.maxlength,u==="ropetrail"?10:0),minLength:Te(c&&c.minlength,0),subdivision:Te(c&&c.subdivision,1),segments:Te(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=fm(o);this.trailSegments=c,this.trailDuration=dm(o),this.trailSampleDt=this.trailDuration/Math.max(1,c-1)}this.allocTrails(),this.ropeRenderer=this.renderers.find(c=>c.kind==="rope")||null}allocTrails(){const e=this.trailCfg;if(!e||e.kind!=="ropetrail")return;const n=Math.max(1,this.trailSegments||1);for(const r of this.pool)(!r.trail||r.trail.length!==n*3)&&(r.trail=new Float32Array(n*3)),r.trailClock=0}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=om(e);const r=n&&n.constantshadervalues,i=r&&r.ui_editor_properties_refract_amount,s=Number(i);this.refractAmount=Number.isFinite(s)?Math.min(1,Math.max(-1,s)):.05;const a=r?r.ui_editor_properties_overbright:void 0,o=Number(a);this.overbright=a==null||!Number.isFinite(o)?1:Math.max(0,o)}setNormalTexture(e){this.normalTex=e||null,this.normalPacked=!!(e&&e.packed)}setTexture(e){this.albedoR8=!!(e&&e.albedoR8),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=.5,this.texAspectY=.5*((o||1)/(a||1)),this.frameLongPx=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;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}setParallaxOffset(e,n){this.parallaxX=Number(e)||0,this.parallaxY=Number(n)||0}setPointer(e,n){const r=this.worldToLocal(e,n);this.pointer={x:r[0],y:r[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}attachEventParent(e,n,r){if(!e||n!=="eventdeath"&&n!=="eventspawn")return;const i=r||[0,0,0];this._eventParent=e,this._eventType=n,this._eventOffset=[i[0]||0,i[1]||0,i[2]||0],e._eventChildren.includes(this)||e._eventChildren.push(this),this._syncEventOrigin()}_syncEventOrigin(){const e=this._eventParent;if(!e||!this._eventOffset)return;const n=e.localToWorld(this._eventOffset[0],this._eventOffset[1]);this.originX=n[0],this.originY=n[1]}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]}worldToLocal(e,n){const r=e-this.originX,i=n-this.originY,s=Math.cos(-this.angleZ),a=Math.sin(-this.angleZ);return[(r*s-i*a)/(this.scaleX||1),(r*a+i*s)/(this.scaleY||1)]}onParentEvent(e,n,r,i,s,a){this._syncEventOrigin();const o=this.worldToLocal(i,s),c=this._burstQueue;if(c.length>=yw&&c.shift(),c.push([o[0],o[1],a]),e==="spawn"){for(const u of this.emitters)if(!(u.instantaneous>0)&&!(!(u.rate>0)&&!u.fill)){if(this._bound.length>=gw)break;this._bound.push({em:u,parent:n,particle:r,seq:r.seq,poolGen:n._poolGen,pos:[o[0],o[1],a],accum:0,parts:[],cap:u.fill?Math.min(this.maxCount,Dl):0})}}}_notifyChildren(e,n){const r=this._eventChildren;if(!r.length)return;const i=this.localToWorld(n.x,n.y);for(const s of r)(e==="death"?s._eventType!=="eventdeath":s._eventType!=="eventspawn")||s.onParentEvent(e,this,n,i[0],i[1],n.z)}_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,n){if(this._aliveCount>=this.pool.length)return null;const r=this.pool,i=r.length;let s=null,a=this._cursor||0;for(let f=0;f<i;f++){const h=r[(a+f)%i];if(!h.alive){s=h,this._cursor=(a+f+1)%i;break}}if(!s)return null;s.alive=!0,s.age=0,s.seed=Math.random(),s.rot=0,s.rotVel=0,s.rotX=0,s.rotY=0,s.rotVelX=0,s.rotVelY=0,s.vx=s.vy=s.vz=0,s.frame=0,s.seq=this._seq++;const o=e.origin;if(e.kind==="box"){const f=e.distanceMax||[0,0,0],h=e.distanceMin;s.x=o[0]+_t(-f[0],f[0])+(h?h[0]:0),s.y=o[1]+_t(-f[1],f[1])+(h?h[1]:0),s.z=o[2]+_t(-f[2],f[2])+(h?h[2]:0)}else{const f=e.directions,h=e.distanceMin?e.distanceMin[0]:0,p=e.distanceMax?e.distanceMax[0]:0,m=Math.abs(f[2])>1e-6,g=Math.abs(f[0])>1e-6,y=Math.abs(f[1])>1e-6,w=Math.max(1,(g?1:0)+(y?1:0)+(m?1:0));let A,b,v;if(m){const k=Math.random()*2-1,_=Math.random()*Gr,I=Math.sqrt(Math.max(0,1-k*k));A=I*Math.cos(_),b=I*Math.sin(_),v=k}else{const k=Math.random()*Gr;A=Math.cos(k),b=Math.sin(k),v=0}e.sign&&(e.sign[0]&&(A=Math.abs(A)*Math.sign(e.sign[0])),e.sign[1]&&(b=Math.abs(b)*Math.sign(e.sign[1])),e.sign[2]&&(v=Math.abs(v)*Math.sign(e.sign[2])));const x=Math.max(0,h),P=Math.max(x,p),S=x===P?x:Math.pow(x**w+Math.random()*(P**w-x**w),1/w);if(s.x=o[0]+A*S*f[0],s.y=o[1]+b*S*f[1],s.z=o[2]+v*S*f[2],e.speedMax||e.speedMin){const k=_t(e.speedMin,e.speedMax);s.vx+=A*k,s.vy+=b*k,s.vz+=v*k}}{const f=this._cpPos(e.controlPoint);if(f)s.x+=f[0],s.y+=f[1],s.z+=f[2];else{const h=this.controlPoints.find(p=>p.id===e.controlPoint);if(h&&h.lockToPointer){s.alive=!1;return}}}if(this.init.mapAround){const f=this.init.mapAround,h=this._cpPos(f.cp);if(h){const p=f.count,m=this._mapAroundSeq++,g=p>0?m%p/p:0,w=(f.bounds[0]+(f.bounds[1]-f.bounds[0])*g)*Gr,A=e.distanceMin?e.distanceMin[0]:0,b=e.distanceMax?e.distanceMax[0]:0,v=b>0?b:A;s.x=h[0]+Math.cos(w)*v,s.y=h[1]+Math.sin(w)*v,s.z=h[2];const x=Math.random();s.vx+=f.speedMin[0]+(f.speedMax[0]-f.speedMin[0])*x,s.vy+=f.speedMin[1]+(f.speedMax[1]-f.speedMin[1])*x,s.vz+=f.speedMin[2]+(f.speedMax[2]-f.speedMin[2])*x}}n&&(s.x+=n[0],s.y+=n[1],s.z+=n[2]);const c=this.init,u=this._ov.speed||1,l=this._ov.size||1;if(s.life=c.life?Math.max(.001,Qr(c.life.min,c.life.max,c.life.exp)*this.lifetimeMul):1,s.baseSize=c.size?Qr(c.size.min,c.size.max,c.size.exp)*l:20*l,s.size=s.baseSize,c.color){const f=c.color.min,h=c.color.max,p=Math.random();s.baseR=(f[0]+(h[0]-f[0])*p)/255,s.baseG=(f[1]+(h[1]-f[1])*p)/255,s.baseB=(f[2]+(h[2]-f[2])*p)/255}else s.baseR=s.baseG=s.baseB=1;if(this._ov.color&&(s.baseR=this._ov.color[0],s.baseG=this._ov.color[1],s.baseB=this._ov.color[2]),s.r=s.baseR,s.g=s.baseG,s.b=s.baseB,s.baseAlpha=(c.alpha?_t(c.alpha.min,c.alpha.max):1)*this.opacityMul,s.alpha=s.baseAlpha,c.velocity&&(s.vx+=_t(c.velocity.min[0],c.velocity.max[0])*u,s.vy+=_t(c.velocity.min[1],c.velocity.max[1])*u,s.vz+=_t(c.velocity.min[2],c.velocity.max[2])*u),c.turbulentVelocity){const f=c.turbulentVelocity,h=f.audioMode?Rl(f.audioBounds,this._audioLevel||0):1,p=_t(f.speedMin,f.speedMax)*u*h,m=this.simTime*(f.timeScale||0),g=Fl(s.x*f.scale+f.offset,s.y*f.scale+f.offset,m+s.seed*(f.phaseMax||0),3);s.vx+=g[0]*p,s.vy+=g[1]*p,s.vz+=g[2]*p}c.rotation&&(s.rotX=Qr(c.rotation.min[0],c.rotation.max[0],c.rotation.exp),s.rotY=Qr(c.rotation.min[1],c.rotation.max[1],c.rotation.exp),s.rot=Qr(c.rotation.min[2],c.rotation.max[2],c.rotation.exp)),c.angularVelocity&&(s.rotVelX=Qr(c.angularVelocity.min[0],c.angularVelocity.max[0],c.angularVelocity.exp),s.rotVelY=Qr(c.angularVelocity.min[1],c.angularVelocity.max[1],c.angularVelocity.exp),s.rotVel=Qr(c.angularVelocity.min[2],c.angularVelocity.max[2],c.angularVelocity.exp)),s.rotVelX*=u,s.rotVelY*=u,s.rotVel*=u;const d=this.ops;if(d.oscPos)for(let f=0;f<3;f++)d.oscPos.mask[f]&&(s.oscPFreq[f]=_t(d.oscPos.freqMin,d.oscPos.freqMax),s.oscPAmp[f]=_t(d.oscPos.scaleMin,d.oscPos.scaleMax),s.oscPPhase[f]=_t(d.oscPos.phaseMin,d.oscPos.phaseMax+Gr));if(d.oscAlpha&&(s.oscAFreq=_t(d.oscAlpha.freqMin,d.oscAlpha.freqMax),s.oscAAmp=[d.oscAlpha.scaleMin,d.oscAlpha.scaleMax],s.oscAPhase=_t(d.oscAlpha.phaseMin,d.oscAlpha.phaseMax+Gr)),d.oscSize&&(s.oscSFreq=_t(d.oscSize.freqMin,d.oscSize.freqMax),s.oscSAmp=[d.oscSize.scaleMin,d.oscSize.scaleMax],s.oscSPhase=_t(d.oscSize.phaseMin,d.oscSize.phaseMax+Gr)),d.turbulence.length){const f=d.turbulence[0];s.turbSpeed=_t(f.speedMin,f.speedMax),s.turbPhase=_t(f.phaseMin,f.phaseMax)}if(this.frameCount>1&&(s.frame=this.animationMode==="randomframe"?Math.floor(Math.random()*this.frameCount):0),s.frameB=s.frame,s.frameMix=0,this.worldSpace){const f=Math.cos(this.angleZ),h=Math.sin(this.angleZ),p=s.x*this.scaleX,m=s.y*this.scaleY;s.x=this.originX+p*f-m*h,s.y=this.originY+p*h+m*f;const g=s.vx*this.scaleX,y=s.vy*this.scaleY;s.vx=g*f-y*h,s.vy=g*h+y*f,s.vz=s.vz*(this.scaleZ||1)}if(s.bx=s.x,s.by=s.y,s.bz=s.z,s.trail){for(let f=0;f<s.trail.length;f+=3)s.trail[f]=s.x,s.trail[f+1]=s.y,s.trail[f+2]=s.z;s.trailClock=0}return this._aliveCount++,this._eventChildren.length&&this._notifyChildren("spawn",s),s}updateParticle(e,n){if(e.age+=n,e.age>=e.life){this._eventChildren.length&&this._notifyChildren("death",e),e.alive=!1,this._aliveCount--;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}if(i.angularMovement){const o=i.angularMovement.force,c=i.angularMovement.drag||0;e.rotVelX+=(-e.rotVelX*c+(o[0]||0))*n,e.rotVelY+=(-e.rotVelY*c+(o[1]||0))*n,e.rotVel+=(-e.rotVel*c+(o[2]||0))*n}for(const o of i.turbulence){const c=o.timeScale||1,u=Fl(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){let c=this._cpPos(o.cp);if(!c)continue;if(this.worldSpace){const h=this.localToWorld(c[0]+(o.origin[0]||0),c[1]+(o.origin[1]||0));c=[h[0],h[1],c[2]];const p=c[0]-e.x,m=c[1]-e.y,g=Math.hypot(p,m);if(g<.001||o.threshold>0&&g>=o.threshold)continue;const y=o.scale*n/g;e.vx+=p*y,e.vy+=m*y;continue}const u=c[0]+o.origin[0]-e.x,l=c[1]+o.origin[1]-e.y,d=Math.hypot(u,l);if(d<.001||o.threshold>0&&d>=o.threshold)continue;const f=o.scale*n/d;e.vx+=u*f,e.vy+=l*f}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]),d=Math.hypot(u,l);if(d<.001)continue;const f=o.distanceOuter-o.distanceInner,h=f>0?Math.min(1,Math.max(0,(d-o.distanceInner)/f)):0,p=o.audioMode?Rl(o.audioBounds,this._audioLevel||0):1,m=o.speedInner+(o.speedOuter-o.speedInner)*h;e.vx+=l/d*m*n*p,e.vy+=-u/d*m*n*p}for(const o of i.remap){const c=o.inputScale||1,u=Fl(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 d=(u[l]+1)/2,f=o.rangeMin[l]+(o.rangeMax[l]-o.rangeMin[l])*d;l===0?e.vx=f:l===1?e.vy=f:e.vz=f}else if(o.output==="speed"){const l=(u[0]+1)/2,d=o.rangeMin[0]+(o.rangeMax[0]-o.rangeMin[0])*l,f=Math.hypot(e.vx,e.vy)||1;e.vx=e.vx/f*d,e.vy=e.vy/f*d}}if(e.bx+=e.vx*n,e.by+=e.vy*n,e.bz+=e.vz*n,e.rotX+=e.rotVelX*n,e.rotY+=e.rotVelY*n,e.rot+=e.rotVel*n,e.x=e.bx,e.y=e.by,e.z=e.bz,i.oscPos){const o=i.oscPos.mask,c=e.age;for(let u=0;u<3;u++){if(!(o[u]>=.01))continue;const d=e.oscPFreq[u]*c+e.oscPPhase[u],f=e.oscPAmp[u]*(Math.cos(d)-Math.cos(e.oscPPhase[u]));u===0?e.x+=f:u===1?e.y+=f:e.z+=f}}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=e.oscSFreq*e.age+e.oscSPhase;s*=e.oscSAmp[0]+(Math.cos(o)+1)*.5*(e.oscSAmp[1]-e.oscSAmp[0])}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&&!this.ropeRenderer&&(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=e.oscAFreq*e.age+e.oscAPhase;a*=e.oscAAmp[0]+(Math.cos(o)+1)*.5*(e.oscAAmp[1]-e.oscAAmp[0])}if(e.alpha=Math.max(0,a),this.frameCount>1&&this.animationMode!=="randomframe"){const o=r*this.frameCount,c=Math.min(this.frameCount-1,Math.floor(o));e.frame=c,e.frameB=Math.min(this.frameCount-1,c+1),e.frameMix=this.frameBlend?Math.min(1,Math.max(0,o-c)):0}if(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 d=o.length-3;d>=3;d-=3)o[d]=o[d-3],o[d+1]=o[d-2],o[d+2]=o[d-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(e=e*(this.timeScale===void 0?1:Math.max(0,this.timeScale)),this._syncFollow(),!this._warmed&&(this._warmed=!0,this.startTime>0)){const r=.03333333333333333,i=Math.min(900,Math.round(this.startTime/r)),a=Math.max(1,Math.floor(24e4/Math.max(1,this.maxCount))),o=Math.min(i,a);for(let c=0;c<o;c++)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;if(this._audioLevel=r,this._eventParent)this._stepEventChild(e);else 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 c=Math.min(this.maxCount,Dl),u=this._aliveCount;let l=Math.min(c-u,512);for(;l-- >0;)this.spawn(s);continue}if(s.audioDriven){let c;if(n&&(n.left16||n.right16)?c=uw({left:n.left16,right:n.right16},s.audioMode,s.audioFreqStart,s.audioFreqEnd,s.audioBounds,s.audioExponent,1):c=Rl(s.audioBounds,r),s.rate>0){const u=s.rate*c*(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 d=0;d<l;d++)this.spawn(s)}}else{const u=Math.round(Math.min(this.maxCount,Dl)*c),l=this._aliveCount;let d=Math.min(u-l,256);for(;d-- >0;)this.spawn(s)}continue}const a=s.rate*(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)}_stepEventChild(e){this._syncEventOrigin();const n=this._burstQueue;if(n.length){this._burstQueue=[];for(const i of n)this._burstAt(i)}if(!this._bound.length)return;const r=[];for(const i of this._bound){const s=i.particle;if(!s.alive||s.seq!==i.seq||i.parent._poolGen!==i.poolGen)continue;const a=i.parent.localToWorld(s.x,s.y),o=this.worldToLocal(a[0],a[1]);i.pos[0]=o[0],i.pos[1]=o[1],i.pos[2]=s.z,this._emitBound(i,e),r.push(i)}this._bound=r}_burstAt(e){for(const n of this.emitters){if(!(n.instantaneous>0))continue;const r=Math.min(n.instantaneous,this.maxCount);for(let i=0;i<r&&this.spawn(n,e);i++);}}_emitBound(e,n){const r=e.em;if(e.cap>0){let o=0;const c=[];for(const l of e.parts)l.p.alive&&l.p.seq===l.seq&&(o++,c.push(l));e.parts=c;let u=Math.min(e.cap-o,32);for(;u-- >0;){const l=this.spawn(r,e.pos);if(!l)break;e.parts.push({p:l,seq:l.seq})}return}const i=this._ov.countMul!==void 0?this._ov.countMul:1,s=r.rate*i;if(!(s>0))return;e.accum=(e.accum||0)+s*n;let a=Math.floor(e.accum);if(!(a<=0)){e.accum-=a,a>this.maxCount&&(a=this.maxCount);for(let o=0;o<a&&this.spawn(r,e.pos);o++);}}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;um(this.trailCfg,this.trailSegments);const l=18,d=this.pool;let f=null;if(u){f=this._ropeOrder,f.length=0;for(let Y=0;Y<d.length;Y++)d[Y].alive&&f.push(d[Y]);f.sort((Y,oe)=>Y.seq-oe.seq)}let h=0;if(f)h=f.length;else for(let Y=0;Y<d.length;Y++)d[Y].alive&&h++;if(h===0||u&&h<2)return;const p=u?h-1:h,m=p*l;(!this._data||this._data.length<m)&&(this._data=new Float32Array(Math.max(m,1024)));const g=this._data;let y=0;const w=(this._ov.brightness||1)*(this.overbright??1),A=this.worldSpace,b=A?1:this.sysScale,v=Y=>Math.abs(Y)*b,x=(A?1:this.spriteStretchX)*(this.texAspectX||1),P=(A?1:this.spriteStretchY)*(this.texAspectY||1),S=A?1:Math.cos(this.angleZ),k=A?0:Math.sin(this.angleZ),_=A?this.parallaxX||0:this.originX+(this.parallaxX||0),I=A?this.parallaxY||0:this.originY+(this.parallaxY||0),B=A?1:this.scaleX,V=A?1:this.scaleY,O=(Y,oe)=>{const he=Y*B,Ae=oe*V;return[_+he*S-Ae*k,s-(I+he*k+Ae*S)]};if(u)for(let Y=0;Y+1<h;Y++){const oe=f[Y],he=f[Y+1],Ae=O(oe.x,oe.y),Pe=O(he.x,he.y),Ce=Pe[0]-Ae[0],Le=Pe[1]-Ae[1],Ne=Math.hypot(Ce,Le),De=(v(oe.size)+v(he.size))*.5;De>0&&(g[y++]=(Ae[0]+Pe[0])*.5,g[y++]=(Ae[1]+Pe[1])*.5,g[y++]=0,g[y++]=De,g[y++]=Math.atan2(-Ce,Le),g[y++]=(oe.r+he.r)*.5*w,g[y++]=(oe.g+he.g)*.5*w,g[y++]=(oe.b+he.b)*.5*w,g[y++]=(oe.alpha+he.alpha)*.5,g[y++]=1,g[y++]=Ne/De,g[y++]=0,g[y++]=Ul(oe),g[y++]=Ul(he),g[y++]=0,g[y++]=0,g[y++]=0,g[y++]=0)}const U=(Y,oe,he,Ae,Pe,Ce,Le,Ne,De)=>{g[y++]=Y,g[y++]=oe,g[y++]=0,g[y++]=Ae,g[y++]=he,g[y++]=Ne.r*w,g[y++]=Ne.g*w,g[y++]=Ne.b*w,g[y++]=Ne.alpha,g[y++]=x,g[y++]=Pe,g[y++]=De,g[y++]=Ce,g[y++]=Le,g[y++]=Ne.frameB===void 0?Ne.frame:Ne.frameB,g[y++]=Ne.frameMix||0,g[y++]=Ne.rotX||0,g[y++]=Ne.rotY||0};for(let Y=0;Y<d.length&&!u;Y++){const oe=d[Y];if(oe.alive)if(o||c){const he=o||c,Ae=O(oe.x,oe.y),Pe=O(oe.x+oe.vx,oe.y+oe.vy),Ce=Pe[0]-Ae[0],Le=Pe[1]-Ae[1],Ne=v(oe.size),De=lm(Ce,Le),Re=cm(Math.hypot(oe.vx,oe.vy),he.length,he.minLength,he.maxLength);U(Ae[0],Ae[1],De,Ne,Re,0,1,oe,oe.frame)}else{const he=O(oe.x,oe.y);U(he[0],he[1],oe.rot,v(oe.size),P,0,1,oe,oe.frame)}}const W=this._prog;am(a),a.useProgram(W.prog),a.bindVertexArray(this._vao),a.bindBuffer(a.ARRAY_BUFFER,this._vbuf),a.bufferData(a.ARRAY_BUFFER,g.subarray(0,y),a.DYNAMIC_DRAW),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,this.texture.glTex),a.uniform1i(W.uniTex,0),a.uniformMatrix4fv(W.uniMvp,!1,e);const ie=this.refract&&this.normalTex&&this.normalTex.glTex;if(W.uniRefract&&a.uniform1i(W.uniRefract,ie?1:0),W.uniAlbedoR8&&a.uniform1i(W.uniAlbedoR8,this.albedoR8?1:0),ie){a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,this.normalTex.glTex),W.uniNormal&&a.uniform1i(W.uniNormal,1),W.uniNormalPacked&&a.uniform1i(W.uniNormalPacked,this.normalPacked?1:0),W.uniSampleScene&&a.uniform1i(W.uniSampleScene,1);{const Y=a.drawingBufferWidth||n,oe=a.drawingBufferHeight||r;if(a.activeTexture(a.TEXTURE2),Ll){const he=Ll(Y,oe);a.bindTexture(a.TEXTURE_2D,he||this.texture.glTex),am(a)}else a.bindFramebuffer(a.FRAMEBUFFER,null),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,Y,oe,0);W.uniScene&&a.uniform1i(W.uniScene,2),W.uniResolution&&a.uniform2f(W.uniResolution,Y,oe),W.uniRefractScale&&a.uniform1f(W.uniRefractScale,Number.isFinite(this.refractAmount)?this.refractAmount:.05)}}else W.uniNormal&&(a.activeTexture(a.TEXTURE1),a.bindTexture(a.TEXTURE_2D,this.texture.glTex),a.uniform1i(W.uniNormal,1),a.activeTexture(a.TEXTURE2),a.bindTexture(a.TEXTURE_2D,this.texture.glTex),W.uniScene&&a.uniform1i(W.uniScene,2),W.uniSampleScene&&a.uniform1i(W.uniSampleScene,0));const we=this._frameUniformData();we?(a.uniform1i(W.uniFrameCount,we.count),a.uniform4fv(W.uniFrames,we.arr)):a.uniform1i(W.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,p),a.depthMask(!0),a.disable(a.BLEND),a.bindVertexArray(null)}_buildProgram(e){const n=iw(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 kw=Object.freeze(Object.defineProperty({__proto__:null,ParticleSystem:xw,getParticleDensityTier:pw,getParticleQualityScale:dw,particleInstanceSegs:um,particlePassRefract:om,rgbaIsBlankWhite:vw,ropeParticleV:Ul,ropeTrailDuration:dm,ropeTrailHistoryCount:fm,setParticleDensityTier:mw,setParticleFrameTargetProvider:bw,setParticleQualityScale:fw,setParticleSceneCapture:ww,spriteTrailLengthFactor:cm,spriteTrailRotation:lm},Symbol.toStringTag,{value:"Module"})),Cn=new Map,Ol=new Map;let vo=null;function Tw(t,e){const n=String(t);Ol.set(n,e),Cn.delete(n)}function Sw(t){vo=typeof t=="function"?t:null}function Pw(){Ol.clear(),vo=null,Cn.clear()}function _w(){return Object.keys(oa)}function ft(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 ta(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 Yn(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 Kn=t=>t*t*(3-2*t),na=t=>t*t*t*(t*(t*6-15)+10),Zn=(t,e,n)=>t+(e-t)*n,Me=(t,e)=>Math.exp(-(t*t)/(e*e));function Kr(t,e,n,r){const i=Math.min(t,e,n-1-t,n-1-e);return i>=r?1:i/r}function ra(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*Me(a,e[c].r);ft(n,(i*t+s)*4,o)}return{width:t,height:t,rgba:n}}function xi(t,e,n){return ra(t,[e,n])}function Ew(t,e){const n=new Uint8Array(t*t*4),r=t/2,i=e.length-1;for(let s=0;s<t;s++)for(let a=0;a<t;a++){const o=Math.hypot(a+.5-r,s+.5-r)/r;let c=0;if(o<1){const u=o*i,l=Math.min(i-1,Math.floor(u));c=e[l]+(e[l+1]-e[l])*(u-l)}ft(n,(s*t+a)*4,c)}return{width:t,height:t,rgba:n}}function Mw(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=Math.hypot(i+.5-n,r+.5-n)/n,a=Math.min(1,Math.max(0,(s-.6)/.4)),o=a*a*(3-2*a);ft(e,(r*t+i)*4,Math.pow(1-o,1.6))}return{width:t,height:t,rgba:e}}function Zr(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,d=(c+.5-a)/a,f=Math.hypot(l,d),h=Math.atan2(d,l),p=Math.pow(.5+.5*Math.cos(e*h),r);let m=Me(f,i)+p*Me(f,n);m*=Kr(u,c,t,o),ft(s,(c*t+u)*4,m)}return{width:t,height:t,rgba:s}}function Ao(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?Me(c-.5,.27):Kn(Math.min(1,c/.06))*Math.pow(1-c,1.35);for(let l=0;l<t;l++){const d=l/(t-1)*2-1,f=Me(d,n);ft(a,(o*t+l)*4,f*f*f*u*.55)}}return{width:t,height:e,rgba:a}}function Cw(t){const e=t,n=new Uint8Array(e*e*4),r=15;for(let i=0;i<e;i++)for(let s=0;s<e;s++){const a=(i*e+s)*4;let o=0;s===r?o=255:(s===r-1||s===r+1)&&(o=50),n[a]=o,n[a+1]=o,n[a+2]=o,n[a+3]=255}return{width:e,height:e,rgba:n}}function Iw(t,e,n,r){const i=Math.round(t/Math.sqrt(e)),s=Math.round(t/i),a=new Uint8Array(t*t*4);for(let u=0;u<t*t;u++)a[u*4+3]=255;const o=Yn(r>>>0),c=[];for(let u=0;u<n;u++){const l=o()*Math.PI*2,d=Math.pow(o(),1.15)*.38*i;c.push({x:i/2+Math.cos(l)*d,y:i/2+Math.sin(l)*d,r:.5+o()*1.35,phase:o(),drift:(o()-.5)*.06,tint:[.55+o()*.45,.75+o()*.25,.85+o()*.15],bright:o()<.18?.75+o()*.6:.22+o()*.35})}for(let u=0;u<e;u++){const l=u%s*i,d=(u/s|0)*i,f=u/e;for(const h of c){const p=(f-h.phase+1)%1,m=Math.min(1,p*6),g=p>.75?Math.max(0,1-(p-.75)/.25):1,y=m*g*h.bright;if(y<=.02)continue;const w=h.r*(.6+.8*Math.min(1,p*3)),A=h.x+h.drift*i*p*3,b=h.y-p*i*.12;for(let v=Math.floor(b-w-1);v<=Math.ceil(b+w+1);v++)for(let x=Math.floor(A-w-1);x<=Math.ceil(A+w+1);x++){if(x<0||v<0||x>=i||v>=i)continue;const P=Math.hypot(x+.5-A,v+.5-b),S=Math.exp(-Math.pow((P-w)/.7,2)),k=Math.exp(-Math.pow(P/(w*.9),2))*.22,_=Math.min(1,(S+k)*y);if(_<=.01)continue;const I=((d+v)*t+l+x)*4,B=V=>Math.min(255,a[I+V]+Math.round(_*h.tint[V]*255*.42));a[I]=B(0),a[I+1]=B(1),a[I+2]=B(2),a[I+3]=255}}}return{width:t,height:t,rgba:a}}const hm={0:{w:256,h:512,p:.9,k:.996,grid:[[0,0,0,0,0,0,0,0,0],[0,0,.008,.122,.376,.247,.031,0,0],[0,0,.063,.314,.804,.698,.188,0,0],[0,.004,.129,.408,.741,.737,.22,0,0],[0,.008,.082,.278,.647,.639,.18,0,0],[0,.012,.075,.278,.541,.541,.125,0,0],[0,0,.027,.275,.451,.451,.098,0,0],[0,0,.027,.239,.361,.357,.067,0,0],[0,0,.031,.176,.278,.275,.031,0,0],[0,0,0,.137,.212,.188,.027,0,0],[0,0,0,.106,.153,.145,0,0,0],[0,0,0,.078,.106,.118,.027,0,0],[0,0,0,.067,.078,.086,0,0,0],[0,0,0,.055,.059,.071,.031,0,0],[0,0,0,.027,.031,.055,0,0,0],[0,0,0,.027,.027,.027,0,0,0],[0,0,0,0,0,0,0,0,0]]},1:{w:256,h:512,p:.75,k:1.137,grid:[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,.012,.027,0,.02,.02,0,0],[0,0,0,.09,0,.192,.035,0,0],[0,0,0,.024,.098,.075,.047,0,0],[0,0,0,.157,.208,.42,.031,0,0],[0,0,0,.059,.106,.157,0,0,0],[0,0,0,0,.031,0,0,0,0],[0,0,0,0,.016,.031,0,0,0],[0,0,0,0,.012,.039,0,0,0],[0,0,0,0,.012,.031,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,.075,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]]},2:{w:256,h:256,p:3.15,k:2.941,grid:[[0,0,0,0,0,0,0,0,0],[0,0,.071,0,0,0,0,0,0],[0,0,.11,0,0,0,0,0,0],[0,0,.192,.02,0,.067,.008,0,0],[0,0,0,.098,.11,0,0,0,0],[0,0,0,.286,.427,.161,.012,0,0],[0,0,0,.902,1,.137,0,0,0],[0,0,0,.678,.965,0,0,0,0],[0,0,0,0,.973,0,0,0,0],[0,0,0,.212,.969,0,0,0,0],[0,0,0,.071,.894,.02,0,0,0],[0,0,0,.396,.757,.408,0,0,0],[0,0,0,.012,.514,0,.071,0,0],[0,0,.09,.102,.275,0,.02,0,0],[0,0,0,0,.106,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]]},3:{w:128,h:512,p:3,k:5.021,grid:[[0,0,0,0,.141,0,0,0,0],[0,0,.035,.424,.455,.337,0,0,0],[0,0,.098,.231,.125,0,.039,0,0],[0,0,.031,.247,.592,.09,.196,0,0],[0,0,.071,0,.678,0,.012,0,0],[0,0,.122,0,.69,0,0,.004,0],[0,.004,0,0,.659,.039,0,0,0],[0,0,0,.047,.58,.008,0,0,0],[0,0,0,0,.467,0,0,0,0],[0,0,0,.016,.408,0,0,0,0],[0,0,0,.031,.392,0,0,0,0],[0,0,0,.027,.349,0,0,0,0],[0,0,0,.024,.255,0,0,0,0],[0,0,0,.02,.184,0,0,0,0],[0,0,0,0,.125,0,0,0,0],[0,0,0,0,.078,0,0,0,0],[0,0,0,0,0,0,0,0,0]]},4:{w:256,h:256,p:.8,k:.875,grid:[[0,0,0,0,.024,0,0,0,0],[0,0,.004,.114,.145,.09,.039,0,0],[0,.004,.286,0,.008,0,0,.063,0],[0,.149,0,0,.188,.169,.086,.086,0],[0,.247,.216,0,.514,.467,.22,0,0],[0,0,.122,.122,.604,.467,.086,.106,0],[0,0,0,.118,.494,.525,.306,.043,0],[0,.012,0,.263,.329,.416,.157,0,0],[0,0,0,.153,.192,.573,.102,.024,0],[0,0,0,.204,.122,.278,.082,.012,0],[0,0,.086,.169,.078,.259,.059,0,0],[0,0,.039,.075,.051,.208,.02,0,0],[0,0,.016,.02,.027,.145,.035,0,0],[0,0,.02,0,.012,.106,.016,0,0],[0,0,0,0,0,.075,0,0,0],[0,.012,0,0,0,.031,0,0,0],[0,0,0,0,0,0,0,0,0]]},5:{w:256,h:256,p:1.15,k:1.569,grid:[[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,.008,0,0,0,0,0],[0,0,0,.094,.051,0,.067,0,0],[0,0,0,0,.137,.039,0,0,0],[0,0,0,.145,.031,.243,0,0,0],[0,0,0,.067,0,.016,0,0,0],[0,0,0,0,0,.008,0,0,0],[0,0,0,.094,.016,.125,.039,0,0],[0,0,0,.565,.231,.369,0,0,0],[0,0,0,.004,.557,.114,0,0,0],[0,0,0,.004,.184,0,.106,0,0],[0,0,0,.165,.035,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]]},6:{w:128,h:512,p:.8,k:.838,grid:[[0,0,0,0,0,0,0,0,0],[0,0,.063,.09,.071,.137,.118,.008,0],[0,0,.129,.263,.176,.455,.365,.055,0],[0,0,.173,.376,.239,.655,.522,.067,0],[0,0,.157,.345,.22,.592,.471,.067,0],[0,0,.145,.306,.196,.486,.392,.051,0],[0,0,.133,.267,.165,.357,.282,.051,0],[0,0,.11,.208,.129,.231,.18,.02,0],[0,0,.086,.161,.098,.137,.106,.008,0],[0,0,.071,.118,.078,.078,.067,0,0],[0,0,.055,.082,.055,.031,.012,0,0],[0,0,.031,.063,.039,.012,0,0,0],[0,0,.02,.039,.02,.008,0,0,0],[0,0,.008,.012,.012,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]]}};function ki(t){const e=hm[t]||hm[0],{w:n,h:r,p:i,k:s,grid:a}=e,o=a[0].length,c=a.length,u=new Uint8Array(n*r*4),l=(f,h)=>a[Math.min(c-1,Math.max(0,h))][Math.min(o-1,Math.max(0,f))],d=(f,h)=>{const p=Math.min(h-1-1e-6,Math.max(0,f*(h-1))),m=Math.floor(p);return[m,p-m]};for(let f=0;f<r;f++){const[h,p]=d(f/(r-1),c);for(let m=0;m<n;m++){const[g,y]=d(m/(n-1),o),w=l(g,h)*(1-y)+l(g+1,h)*y,A=l(g,h+1)*(1-y)+l(g+1,h+1)*y,b=w*(1-p)+A*p,v=Math.min(1,s*Math.pow(b,i)),x=Math.round(255*v),P=(f*n+m)*4;u[P]=x,u[P+1]=x,u[P+2]=x,u[P+3]=x}}return{width:n,height:r,rgba:u}}const mm=4,In=512,ia=In*2;function pm(t){const e=t||{},n=e.segments||89,r=e.peakMax||.37,i=e.peakPow||1.6,s=e.lean===void 0?-.019:e.lean,a=new Uint8Array(ia*ia*4);for(let o=0;o<mm;o++){const c=Yn((2654435769^o*2246822507)>>>0),u=o%2*In,l=(o/2|0)*In,d=3,f=(h,p,m)=>{if(h<d||p<d||h>=In-d||p>=In-d)return;const g=((l+p)*ia+u+h)*4,y=Math.round(Math.min(1,Math.max(0,m))*255);y*255>a[g+3]*255&&ft(a,g,y/255)};for(let h=0;h<n;h++){const p=c()*In,m=c()*In,g=16+430*Math.pow(c(),2.2),y=.04+(r-.04)*Math.pow(c(),i),w=.5+c()*.35;for(let A=0;A<g;A++){const b=Math.round(m+A),v=p+s*A,x=Math.min(1,Math.min(A,g-1-A)/5);if(!(x<=0))for(let P=Math.floor(v-3);P<=Math.ceil(v+3);P++){const S=P+.5-v,k=Math.exp(-(S*S)/(w*w))*y*x;k>.004&&f(P,b,k)}}}}return{width:ia,height:ia,rgba:a}}function Rw(t){if(t==="particle/nature/rain1"||t==="particle/nature/rain2"){const e=[];for(let n=0;n<mm;n++)e.push({x:n%2*In,y:(n/2|0)*In,width:In,height:In});return e}if(t==="particle/bubbles/bubble3"){const e=[];for(let n=0;n<64;n++)e.push({x:n%8*128,y:(n/8|0)*128,width:128,height:128});return e}{const e=gs[t];if(e)return _m(e.cols,e.fw,e.fh,e.frames);if(t==="particle/water/rain_drops_sheet")return _m(4,64,64,16)}if(t==="particle/fog/fog1"){const e=[];for(let n=0;n<Pm;n++)e.push({x:n%8*Jn,y:(n/8|0)*Jn,width:Jn,height:Jn});return e}if(t==="particle/smoke/smoke2"||t==="particle/smoke/smoke2light"){const e=[];for(let n=0;n<Ql;n++)e.push({x:n%8*Bn,y:(n/8|0)*Bn,width:Bn,height:Bn});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*sa,y:n*sa,width:sa,height:sa});return e}return null}function zl(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);ft(r,(s*t+a)*4,Me(o-e,n*.6)*Math.max(0,1-o))}return{width:t,height:t,rgba:r}}function gm(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 d=Me(l-r.r,r.t*.85)*Math.max(0,1.05-l);l<r.r&&(d+=r.inner*Me(l,.5));for(let f=0;f<r.hi.length;f++){const h=r.hi[f];d+=h[3]*Me(Math.hypot(c-h[0],u-h[1]),h[2])}ft(i,(a*t+o)*4,d)}return ta({width:t,height:t,rgba:i},.05)}function xo(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=gm(n,i[s*2+a]);for(let c=0;c<n;c++){const u=(s*n+c)*t,l=c*n;for(let d=0;d<n;d++){const f=(u+a*n+d)*4,h=(l+d)*4;r[f]=o.rgba[h],r[f+1]=o.rgba[h+1],r[f+2]=o.rgba[h+2],r[f+3]=o.rgba[h+3]}}}return{width:t,height:t,rgba:r}}function ym(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,d=r[c][0],f=r[c][1],h=(s+.5-u)/(n*.4),p=(i+.5-l)/(n*.4),m=Math.cos(d),g=Math.sin(d);let y=h*m+p*g;const w=-h*g+p*m;y+=f*w*.18;const A=1-Math.max(0,w)*.42,b=Math.hypot(y/(.52*A),w/.92);let v=b>=1.12?0:Me(b,.48);v=Math.min(1,v+Me(y,.07)*Me(w,.65)*v*.4),ft(e,(i*t+s)*4,v)}return ta({width:t,height:t,rgba:e},.11)}const sa=256,Ut=sa*3;function Ot(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=Yn(7855+e*131);for(let c=0;c<9;c++){const u=c%3,l=c/3|0,d=c/9*Math.PI*2+(o()-.5)*.7,f=.9+o()*.16,h=.9+o()*.2,p=1+(o()-.5)*.12,m=Math.cos(d),g=Math.sin(d),y=c&1?-1:1;for(let w=0;w<i;w++)for(let A=0;A<i;A++){const b=(A+.5-a)/a*y,v=(w+.5-a)/a,x=(b*m+v*g)/f,P=(-b*g+v*m)/f,S=1-Math.pow(Math.min(1,Math.abs(P)),1.7)*.52,k=Math.atan2(x,P),_=r.wave?1+r.wave*Math.sin(k*r.folds):1,I=Math.hypot(x/(r.rx*_*S),P/r.ry),B=I>=1.08?0:Math.min(1,(1.08-I)/.14);if(B<=0)continue;const V=Me(x,.028)*Me(P,.72),O=(.8+.2*Math.max(0,1-I))*(1+V*.22)*h,U=((l*i+w)*i*3+u*i+A)*4;s[U]=Math.min(255,Math.round(r.rgb[0]*O*p)),s[U+1]=Math.min(255,Math.round(r.rgb[1]*O)),s[U+2]=Math.min(255,Math.round(r.rgb[2]*O*(2-p))),s[U+3]=Math.round(B*255)}}return ta({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,d=u<0?0:u>=r?r-1:u;return i[(d*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,d=(o(u,c-1)-o(u,c+1))*s,f=1/Math.hypot(l,d,1),h=(c*n+u)*4;a[h]=Math.round((l*f*.5+.5)*255),a[h+1]=Math.round((d*f*.5+.5)*255),a[h+2]=Math.round((f*.5+.5)*255),a[h+3]=255}return{width:n,height:r,rgba:a}}function bm(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=Me(o-.62,.11)*.55;ft(e,(r*t+i)*4,Math.min(1,c*.85+u))}return{width:t,height:t,rgba:e}}function Bw(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=Me(o,.38)*(.55+.45*Math.cos(c*3+o*6));ft(e,(r*t+i)*4,u)}return{width:t,height:t,rgba:e}}function wm(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=Kn(Math.max(0,Math.cos(u)*.55+.45)),d=Me(c-.68,.07)*l+.35*Me(c-.78,.12)*Me(u-.9,.55);ft(e,(i*t+s)*4,Math.min(1,d)*Kr(s,i,t,r))}return{width:t,height:t,rgba:e}}function Fw(t,e){if(!t||!t.rgba)return t;const n=Number(e);if(n!==8&&n!==9&&n!==10&&n!==11)return t;const r=t.width*t.height,i=new Uint8Array(r*4),s=t.rgba;if(n===9||n===11)for(let a=0;a<r;a++)i[a*4]=255,i[a*4+1]=255,i[a*4+2]=255,i[a*4+3]=s[a*4];else for(let a=0;a<r;a++){const o=s[a*4+3],c=s[a*4];i[a*4]=o,i[a*4+1]=o,i[a*4+2]=o,i[a*4+3]=c}return{width:t.width,height:t.height,rgba:i,format:n,frames:t.frames}}function Dw(t,e){if(!t||!t.rgba)return t;const n=Number(e);if(n!==8&&n!==10)return t;const r=t.width*t.height,i=new Uint8Array(r*4),s=t.rgba;for(let a=0;a<r;a++)i[a*4]=s[a*4+1],i[a*4+1]=s[a*4],i[a*4+2]=0,i[a*4+3]=255;return{width:t.width,height:t.height,rgba:i,format:n,frames:t.frames}}function vm(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 Nw(t){if(!t||!t.rgba||!t.rgba.length)return!1;const e=t.rgba.length/4,n=Math.max(1,e/96|0);let r=0,i=0;for(let s=0;s<e;s+=n){const a=t.rgba[s*4+3];r++,a<250&&i++}return r>0&&i/r>.2}function Lw(t){return!t||!t.rgba?t:vm(t.rgba)?Rn(t,2.8):t}const Uw={"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 Ow(t){if(!t)return null;const e=String(t);return/normal/i.test(e)?e:Uw[e]||e+"_normal"}function zw(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 Hw(t){if(oa[t])return oa[t]();const e=String(t).toLowerCase();return/normal/.test(e)?xi(64,{r:.18,w:1},{r:.4,w:.2}):Mm(t)()}function Hl(t,e,n){const r=Yn(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 d=0;d<u;d++){const f=r()*Math.PI*2;l[d*2]=Math.cos(f),l[d*2+1]=Math.sin(f)}s.push({f:i,g:l,ox:c*7.31,oy:c*3.17}),i*=2}const a=(c,u,l,d,f)=>{const h=c.f,p=(u%h+h)%h,g=((l%h+h)%h*h+p)*2;return c.g[g]*d+c.g[g+1]*f},o=(c,u,l)=>{const d=(u+c.ox)*c.f,f=(l+c.oy)*c.f,h=Math.floor(d),p=Math.floor(f),m=d-h,g=f-p,y=na(m),w=na(g);return Zn(Zn(a(c,h,p,m,g),a(c,h+1,p,m-1,g),y),Zn(a(c,h,p+1,m,g-1),a(c,h+1,p+1,m-1,g-1),y),w)};return function(u,l,d){const f=d==null?s.length:Math.min(d,s.length);let h=1,p=0,m=0;for(let g=0;g<f;g++)p+=(o(s[g],u,l)*.5+.5)*h,m+=h,h*=.55;return p/m}}function Vl(t,e,n,r,i){const s=i===void 0?.55:i,a=Yn(n*7919+17),o=[];let c=t,u=r;for(let f=0;f<e;f++){const h=c*c*u,p=new Float32Array(h);for(let m=0;m<h;m++)p[m]=a();o.push({f:c,zf:u,g:p,ox:f*7.31,oy:f*3.17,oz:f*.379+.123}),c*=2,u*=2}const l=(f,h,p,m)=>{const g=(h%f.f+f.f)%f.f,y=(p%f.f+f.f)%f.f,w=(m%f.zf+f.zf)%f.zf;return f.g[(w*f.f+y)*f.f+g]},d=(f,h,p,m)=>{const g=(h+f.ox)*f.f,y=(p+f.oy)*f.f,w=m+f.oz,A=Math.floor(g),b=Math.floor(y),v=Math.floor(w),x=g-A,P=y-b,S=w-v,k=na(x),_=na(P),I=na(S),B=Zn(l(f,A,b,v),l(f,A+1,b,v),k),V=Zn(l(f,A,b+1,v),l(f,A+1,b+1,v),k),O=Zn(l(f,A,b,v+1),l(f,A+1,b,v+1),k),U=Zn(l(f,A,b+1,v+1),l(f,A+1,b+1,v+1),k);return Zn(Zn(B,V,_),Zn(O,U,_),I)};return function(h,p,m,g){const y=g==null?o.length:Math.min(g,o.length);let w=1,A=0,b=0;for(let v=0;v<y;v++)A+=d(o[v],h,p,m*o[v].zf)*w,b+=w,w*=s;return A/b}}function Wl(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)),d=c-Math.floor(c);for(let f=0;f<e;f++){const h=(f+.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),y=s[(u*r+p)*4+3],w=s[(u*r+m)*4+3],A=s[(l*r+p)*4+3],b=s[(l*r+m)*4+3],v=(y*(1-g)+w*g)*(1-d)+(A*(1-g)+b*g)*d;ft(a,(o*e+f)*4,v/255)}}return{width:e,height:n,rgba:a}}function jl(t,e,n,r,i,s,a){const o=s===void 0?1:s,c=a===void 0?200:a,u=256,l=Hl(e,n,r),d=new Uint8Array(u*u*4),f=u/2,h=u*u,p=new Float32Array(h);let m=1,g=0;for(let b=0;b<h;b++){const v=b%u,x=b/u|0,P=(v+.5)/u,S=(x+.5)/u,k=l(P+5.2,S+1.3,2)-.5,_=l(P+9.7,S+8.1,2)-.5,I=p[b]=l(P+k*.45,S+_*.45);I<m&&(m=I),I>g&&(g=I)}const y=g-m||1;for(let b=0;b<u;b++)for(let v=0;v<u;v++){const x=(p[b*u+v]-m)/y,P=Math.hypot((v+.5-f)/f,(b+.5-f)/f),S=Math.exp(-((P/.45)**2)),k=Math.pow(Math.max(0,1-P),o)*S;let _=Math.max(0,(x-(1-i))/(i||1));_=Kn(Math.min(1,_))*k,_=_<=.02?0:(_-.02)/.98,ft(d,(b*u+v)*4,_)}let w=0;for(let b=0;b<h;b++)w=Math.max(w,d[b*4+3]);if(w>0&&w<c){const b=c/w;for(let v=0;v<h;v++)d[v*4+3]=Math.round(Math.min(255,d[v*4+3]*b))}const A={width:u,height:u,rgba:d};return u===t?A:Wl(A,t,t)}function ql(t,e){const n=t,r=Hl(3,5,e??23),i=new Uint8Array(n*n*4),s=n*n,a=new Float32Array(s);let o=1,c=0;for(let f=0;f<s;f++){const h=f%n,p=f/n|0,m=(h+.5)/n,g=(p+.5)/n,y=r(m+2.1,g+4.7,2)-.5,w=r(m+6.3,g+1.9,2)-.5,A=a[f]=r(m+y*.28,g+w*.55);A<o&&(o=A),A>c&&(c=A)}const u=c-o||1;for(let f=0;f<n;f++)for(let h=0;h<n;h++){const p=(f+.5)/n,m=(h+.5)/n*2-1,g=.1+.52*Math.pow(p,1.25),y=(a[f*n+h]-o)/u,w=Me(m/(g||.01),.55)*Me(p-.58,.42);let A=Kn(Math.min(1,Math.max(0,(y-.18)/.72)))*w;A*=p<.06?p/.06:1,ft(i,(f*n+h)*4,A)}let l=0;for(let f=0;f<s;f++)l=Math.max(l,i[f*4+3]);if(l>0&&l<220){const f=220/l;for(let h=0;h<s;h++)i[h*4+3]=Math.round(Math.min(255,i[h*4+3]*f))}const d=ta({width:n,height:n,rgba:i},.08);return n===t?d:Wl(d,t,t)}function Vw(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),d=(c+.5-u*s)/s*2-1,f=(o+.5-l*a)/a*2-1,h=1-Math.max(0,f)*.45,p=Math.hypot(d/(.52*h),f/.8),m=p>=1.12?0:Me(p,.48);ft(i,(o*t+c)*4,m)}return{width:t,height:e,rgba:i}}function Am(t){const e=new Uint8Array(t*t*4),n=Yn(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,d=o-u.y,f=Math.cos(u.rot),h=Math.sin(u.rot),p=(l*f+d*h)/u.rx,m=(-l*h+d*f)/u.ry,g=Me(Math.hypot(p,m),.55);g>c&&(c=g)}ft(e,(i*t+s)*4,c)}return{width:t,height:t,rgba:e}}function ko(t,e){const n=e??19,r=Yn(n),i=f=>Math.min(.86,Math.max(.14,f)),s=5+n%4,a=[];let o=i(.5+(r()-.5)*.16);for(let f=0;f<=s;f++){const h=.06+f/s*.86;f>0&&(o=i(o+(r()-.5)*.32)),a.push([o,h])}const c=[];for(let f=0;f<a.length-1;f++)c.push([a[f],a[f+1],1]);const u=1+n%2;for(let f=0;f<u;f++){const h=1+(n+f*3)%Math.max(1,a.length-2),p=a[h],m=[p];let g=p[0],y=p[1];const w=2+n%2;for(let A=0;A<w;A++)g=i(g+(r()-.5)*.36),y=Math.min(.92,y+.1+r()*.08),m.push([g,y]);for(let A=0;A<m.length-1;A++)c.push([m[A],m[A+1],.45+f*.1])}const l=new Uint8Array(t*t*4),d=Math.max(2,Math.round(t*.04));for(let f=0;f<t;f++)for(let h=0;h<t;h++){const p=(h+.5)/t,m=(f+.5)/t;let g=9,y=0;for(const[A,b,v]of c){const x=b[0]-A[0],P=b[1]-A[1],S=x*x+P*P||1e-8,k=Math.max(0,Math.min(1,((p-A[0])*x+(m-A[1])*P)/S)),_=Math.hypot(p-(A[0]+x*k),m-(A[1]+P*k));_/v<g&&(g=_/v,y=v)}const w=.95*Me(g,.012)+.3*Me(g,.05)*y;ft(l,(f*t+h)*4,Math.min(1,w)*Kr(h,f,t,d))}return{width:t,height:t,rgba:l}}function Xl(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=Me(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:Me(c,.5);ft(n,(r*t+i)*4,Math.max(o,u))}return{width:t,height:e,rgba:n}}function Ww(t){return xi(t,{r:.1,w:1},{r:.3,w:.16})}function $l(t,e){const n=new Uint8Array(t*e*4);for(let r=0;r<e;r++){const i=(r+.5)/e,s=Kn(Math.min(1,Math.min(i/.08,(1-i)/.08))),a=Me(i-.46,.24)*s,o=.5*(1-Kn(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);ft(n,(r*t+c)*4,Me(Math.abs(u)/(o||.01),.5)*a)}}return{width:t,height:e,rgba:n}}function xm(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=Me(Math.hypot(a,o),.42),u=Me(Math.hypot(a-.34,o),.36),l=Math.max(0,c-u*1.08)*Kr(s,i,t,r);ft(e,(i*t+s)*4,l)}return{width:t,height:t,rgba:e}}function km(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=Me(Math.hypot(a,o),.08);for(let u=0;u<6;u++){const l=u*Math.PI/3,d=Math.cos(l),f=Math.sin(l),h=a*d+o*f,p=-a*f+o*d;if(h<0)continue;const m=Math.max(0,1.02-h/.72);c+=Me(p,.028)*Me(h,.5)*m,c+=.55*Me(p-(h-.28)*.65,.02)*Me(h-.28,.12)*m,c+=.55*Me(p+(h-.28)*.65,.02)*Me(h-.28,.12)*m,c+=.4*Me(p-(h-.48)*.7,.016)*Me(h-.48,.08)*m,c+=.4*Me(p+(h-.48)*.7,.016)*Me(h-.48,.08)*m}ft(e,(i*t+s)*4,Math.min(1,c)*Kr(s,i,t,r))}return{width:t,height:t,rgba:e}}function Tm(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 d=Me(l,.016);s===0?(d+=Me(c,.012)*Me(u,.38),d+=Me(u,.012)*Me(c,.38)):s===1?(d+=Me(c-u,.012)*Me(c+u,.36),d+=Me(c+u,.012)*Me(c-u,.36)):(d+=Me(Math.hypot(c,u)-.26,.014),d+=Me(c,.012)*Me(u,.22)),ft(n,(a*t+o)*4,Math.min(1,d)*Kr(o,a,t,i))}return ta({width:t,height:t,rgba:n},.03)}function Gl(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 jw(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=Me(u,.05)+.3*Me(u,.15);l+=.9*Me(c,i)*Math.exp(-Math.abs(o)/.3),l+=.9*Me(o,i)*Math.exp(-Math.abs(c)/.3),l*=Kr(a,s,t,r),ft(e,(s*t+a)*4,l)}return{width:t,height:t,rgba:e}}function Sm(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=Me(c,.07)+.85*Me(a,.62)*Me(o,.045)+.22*Me(a,.92)*Me(o,.018);ft(e,(i*t+s)*4,Math.min(1,u)*Kr(s,i,t,r))}return{width:t,height:t,rgba:e}}const qw=1024,Pm=64,Jn=128,Xw=[.02,.05,.09,.12,.14,.12,.09,.07,.03,.01,0];function $w(t){const e={},n=e.gen===void 0?Jn>>1:e.gen,r=e.frames===void 0?Pm:e.frames,i=e.seed===void 0?21:e.seed,s=e.freq===void 0?9:e.freq,a=e.oct===void 0?4:e.oct,o=e.ampFall===void 0?.8:e.ampFall,c=e.zCells===void 0?2:e.zCells,u=e.warp===void 0?.25:e.warp,l=e.thr===void 0?.62:e.thr,d=e.soft===void 0?.2:e.soft,f=e.gain===void 0?.85:e.gain,h=e.gamma===void 0?1.1:e.gamma,p=e.margin===void 0?.151:e.margin,m=e.envScale===void 0?.925:e.envScale,g=e.radial||Xw,y=Vl(s,a,i,c,o),w=Vl(Math.max(2,Math.round(s/2)),2,i+401,c,.55),A=Math.max(...g),b=g.map(k=>k/A),v=n/2,x=e.size===void 0?qw:e.size,P=Math.max(1,Math.round(Jn/n)),S={width:x,height:x,rgba:new Uint8Array(x*x*4),frames:[]};for(let k=0;k<r;k++){const _=k/r,I=k/8|0,V=k%8*Jn,O=I*Jn;for(let U=0;U<n;U++)for(let W=0;W<n;W++){const ie=(W+.5)/n,we=(U+.5)/n,Y=w(ie,we,_)-.5,oe=w(ie+.37,we+.11,_)-.5,he=y(ie+Y*u,we+oe*u,_),Ae=Math.hypot((W+.5-v)/v,(U+.5-v)/v),Pe=Math.min(10,Math.max(0,Ae*10)),Ce=Math.min(9,Math.floor(Pe)),Le=(b[Ce]+(b[Ce+1]-b[Ce])*(Pe-Ce))*m,Ne=Math.min(1,Math.max(0,(he-(l-d))/(2*d)));let De=Math.min(1,Math.max(0,f*Le*Ne));h!==1&&(De=Math.pow(De,h));const Re=Math.min(W,U,n-1-W,n-1-U)/n;Re<p&&(De*=Kn(Re/p));const Fe=Math.round(255*De);for(let Xe=0;Xe<P;Xe++)for(let $e=0;$e<P;$e++){const Ye=((O+U*P+Xe)*x+V+W*P+$e)*4;S.rgba[Ye]=255,S.rgba[Ye+1]=255,S.rgba[Ye+2]=255,S.rgba[Ye+3]=Fe}}S.frames.push({x:V,y:O,width:Jn,height:Jn})}return S}const Gw=[[.625,.3,.24,.476],[.618,.3,.24,.484],[.615,.3,.24,.492],[.613,.3,.24,.501],[.617,.3,.24,.54],[.626,.3,.24,.564],[.64,.3,.24,.557],[.669,.32,.22,.641],[.681,.32,.22,.611],[.699,.32,.22,.59],[.719,.32,.22,.568],[.735,.32,.22,.548],[.747,.32,.22,.54],[.743,.3,.24,.388],[.731,.3,.26,.272],[.74,.3,.26,.226],[.737,.28,.28,.118],[.73,.28,.3,.013],[.734,.28,.3,.026],[.735,.26,.32,0],[.735,.26,.32,.008],[.726,.26,.32,.045],[.707,.24,.34,.036],[.689,.24,.34,.064],[.685,.24,.34,.035],[.688,.24,.34,0],[.687,.24,.34,0],[.684,.26,.32,.009],[.703,.26,.3,0],[.7,.26,.3,0],[.706,.28,.28,0],[.707,.28,.28,0],[.692,.3,.28,0],[.686,.3,.28,0],[.68,.3,.28,0],[.674,.3,.28,0],[.669,.3,.28,0],[.664,.3,.28,0],[.661,.3,.28,0],[.649,.3,.3,0],[.641,.3,.32,0],[.673,.28,.3,0],[.662,.28,.32,0],[.684,.26,.32,0],[.694,.26,.32,0],[.705,.24,.34,0],[.717,.24,.34,.008],[.735,.24,.34,.021],[.754,.22,.36,.025],[.743,.24,.36,.135],[.748,.26,.34,.293],[.745,.26,.36,.328],[.733,.28,.34,.445],[.721,.28,.34,.464],[.705,.28,.34,.475],[.68,.26,.38,.407],[.684,.24,.38,.356],[.681,.22,.4,.266],[.703,.18,.42,.118],[.725,.14,.44,0],[.711,.16,.4,0],[.693,.18,.36,0],[.677,.2,.32,0],[.679,.22,.28,0]],Qw=[[.014,.1,.1,.004],[.018,.14,.08,.013],[.039,.16,.08,.02],[.055,.16,.06,.029],[.06,.18,.08,.038],[.073,.18,.1,.034],[.076,.18,.12,.035],[.084,.18,.12,.045],[.087,.18,.14,.049],[.096,.18,.14,.043],[.101,.2,.14,.064],[.113,.22,.12,.09],[.118,.22,.12,.098],[.119,.22,.14,.091],[.124,.22,.14,.102],[.122,.22,.16,.108],[.126,.22,.16,.129],[.129,.22,.16,.153],[.127,.22,.18,.159],[.126,.24,.18,.178],[.128,.24,.18,.183],[.123,.26,.18,.209],[.118,.26,.2,.207],[.115,.26,.22,.204],[.109,.24,.26,.188],[.109,.22,.3,.161],[.116,.16,.36,.104],[.124,.1,.42,.074],[.148,0,.48,.023],[.153,0,.48,.005],[.147,.02,.48,.002],[.135,.12,.4,0],[.136,.14,.38,0],[.139,.14,.36,0],[.141,.12,.38,.001],[.147,.12,.36,0],[.144,.16,.32,0],[.146,.16,.32,0],[.135,.22,.26,.072],[.136,.26,.22,.092],[.144,.28,.2,.053],[.139,.28,.22,.012],[.136,.3,.22,.036],[.134,.3,.22,.036],[.128,.3,.22,.027],[.113,.32,.22,.026],[.097,.32,.22,.015],[.077,.32,.24,.004],[.062,.32,.24,0],[.049,.32,.24,.001],[.038,.34,.24,.003],[.028,.34,.26,0],[.021,.34,.26,.002],[.016,.34,.26,.001],[.011,.34,.26,.001],[.007,.34,.3,0],[.007,.26,.14,.004],[.016,0,.06,.011],[.008,0,.06,.007],[.002,.28,.12,.001],[.001,.28,.1,0],[.001,.26,.08,0],[0,.26,.1,0],[0,.26,.08,0]],Yw=[[.489,.12,.06,.991],[.661,.08,.1,.651],[.714,.08,.12,.544],[.583,.14,.08,.978],[.568,.14,.1,.918],[.607,.14,.1,.876],[.616,.16,.1,.898],[.649,.16,.1,.849],[.663,.16,.1,.799],[.641,.16,.12,.658],[.657,.16,.12,.572],[.686,.14,.14,.321],[.664,.14,.16,.217],[.679,.14,.16,.12],[.695,.14,.16,.051],[.66,.14,.18,0],[.651,.14,.18,0],[.592,.16,.18,.036],[.591,.16,.18,0],[.542,.18,.18,.019],[.529,.18,.18,.016],[.528,.18,.18,0],[.513,.18,.18,0],[.48,.2,.18,.005],[.451,.2,.2,0],[.452,.2,.18,0],[.445,.2,.18,0],[.407,.22,.2,0],[.394,.22,.2,0],[.371,.22,.22,0],[.345,.24,.22,0],[.339,.24,.22,0],[.33,.24,.22,0],[.314,.26,.22,0],[.305,.26,.22,0],[.29,.26,.24,0],[.291,.26,.22,0],[.269,.28,.24,0],[.261,.28,.24,0],[.249,.28,.26,0],[.243,.28,.26,0],[.235,.3,.26,0],[.22,.3,.28,0],[.232,.3,.24,0],[.207,.32,.28,0],[.209,.32,.26,0],[.196,.32,.28,0],[.19,.34,.28,0],[.187,.34,.28,0],[.176,.34,.3,0],[.174,.34,.3,0],[.174,.36,.28,0],[.164,.36,.3,0],[.16,.36,.3,0],[.155,.38,.3,0],[.152,.38,.3,0],[.144,.38,.32,0],[.141,.38,.32,0],[.139,.4,.32,0],[.136,.4,.32,0],[.131,.4,.34,0],[.127,.42,.34,0],[.125,.42,.34,0],[.122,.42,.34,0]],Kw=[[.399,.12,.1,.755],[.782,.16,.1,.878],[.912,.24,.14,.852],[.704,.24,.24,.457],[.706,.38,.22,.173],[.586,.5,.16,0],[.444,.6,.12,.136],[.622,.16,.12,.759],[.887,.22,.16,.626],[.807,.36,.1,0],[.571,.48,.08,0],[.451,.56,.06,0],[.141,.64,.08,0],[.058,.72,.06,0]];function aa(t){const{fw:e,fh:n,cols:r,frames:i,noise:s=1,q:a=1,gate:o=0,gamma:c=1,power:u=1,seed:l=31,freq:d=5,oct:f=3,zCells:h=2,ampFall:p=.6,margin:m=.05,rgbOf:g,rows:y,gen:w}=t,A=Math.max(1,Math.ceil(i/r)),b={w:r*e,h:A*n},v=new Uint8Array(b.w*b.h*4),x=Vl(d,f,l,h,p),P=g||(()=>255),S={width:b.w,height:b.h,rgba:v,frames:[]},k=w===void 0?e>64?e>>1:e:w,_=n>64?n>>1:n,I=Math.max(1,Math.round(e/k)),B=Math.max(1,Math.round(n/_)),V=new Float32Array(k*_);for(let O=0;O<i;O++){const[U,W,ie,we]=y[O],Y=O/i;for(let Re=0;Re<_;Re++)for(let Fe=0;Fe<k;Fe++){const Xe=Math.max(0,x((Fe+.5)/k,(Re+.5)/_,Y));V[Re*k+Fe]=Xe}const oe=O%r*e,he=(O/r|0)*n,Ae=11,Pe=new Float64Array(Ae),Ce=new Float64Array(Ae),Le=new Float64Array(Ae),Ne=new Float32Array(k*_),De=Re=>Math.min(Ae-1,Math.round(Math.min(1.2,Re)*10));for(let Re=0;Re<_;Re++)for(let Fe=0;Fe<k;Fe++){const Xe=Re*k+Fe,$e=Math.hypot((Fe+.5-k/2)/(k/2),(Re+.5-_/2)/(_/2)),Ye=we*Math.exp(-(($e/.12)**2))+U*Math.exp(-((($e-W)/ie)**2)),nt=o*(1-Math.min(1,Ye)),dn=Math.pow(Math.max(0,(V[Xe]-nt)/(1-nt)),a),st=1-s+s*dn*2.2;let gt=Ye*st;u!==1&&(gt=Math.pow(Math.max(0,gt),u)),c!==1&&(gt=Math.pow(Math.min(1,Math.max(0,gt)),c)),gt=Math.min(1,Math.max(0,gt)),Ne[Xe]=gt;const Vt=De($e);Pe[Vt]+=Math.min(1,Ye),Ce[Vt]+=gt,Le[Vt]++}for(let Re=0;Re<Ae;Re++)Le[Re]>0&&(Pe[Re]/=Le[Re],Ce[Re]/=Le[Re]);for(let Re=0;Re<_;Re++)for(let Fe=0;Fe<k;Fe++){const Xe=Re*k+Fe,$e=Math.hypot((Fe+.5-k/2)/(k/2),(Re+.5-_/2)/(_/2)),Ye=De($e),nt=Math.abs(1.2-$e*10)<.001?Ae-1:Ye,dn=Pe[nt]||Pe[Ae-1],st=Ce[nt]||Ce[Ae-1];let gt=st>1e-6?Ne[Xe]*(dn/st):Ne[Xe];const Vt=Math.min(Fe,Re,k-1-Fe,_-1-Re)/k;Vt<m&&(gt*=Kn(Vt/m)),gt=Math.min(1,Math.max(0,gt));const xn=P(gt),Pt=Math.round(255*gt);for(let xt=0;xt<B;xt++)for(let tn=0;tn<I;tn++){const Mt=((he+Re*B+xt)*b.w+oe+Fe*I+tn)*4;v[Mt]=xn,v[Mt+1]=xn,v[Mt+2]=xn,v[Mt+3]=Pt}}S.frames.push({x:oe,y:he,width:e,height:n})}return S}const gs={"particle/water/ripple_single":{fw:32,fh:32,cols:7,frames:14,rows:Kw,noise:.35,q:.5,gate:.5,power:1,gamma:1,seed:31,freq:4,oct:3,zCells:4,ampFall:.6},"particle/water/splash_1":{fw:128,fh:128,cols:8,frames:64,rows:Yw,noise:1,q:.3,gate:.7,power:1,gamma:1,seed:53,freq:10,oct:4,zCells:6,ampFall:.78,gen:128},"particle/fog/fog2":{fw:128,fh:128,cols:8,frames:64,rows:Gw,noise:1,q:.8,gate:.7,power:1,gamma:1,seed:61,freq:5,oct:4,zCells:6,ampFall:.6,rgbOf:t=>Math.round(255*Math.min(1,.325+.246*t))},"particle/fog/fog3":{fw:128,fh:128,cols:8,frames:64,rows:Qw,noise:1,q:1.2,gate:.5,power:1,gamma:1,seed:71,freq:5,oct:4,zCells:12,ampFall:.6,rgbOf:t=>Math.round(255*Math.min(1,.116+1.274*t))}};function _m(t,e,n,r){const i=[];for(let s=0;s<r;s++)i.push({x:s%t*e,y:(s/t|0)*n,width:e,height:n});return i}function Em(t){const i=[23.27,11.11,14.31,18.68,6.93,15.33,8.42,10.38,17.43,4.3,16.92,13.45,16.58,8.28,22.31,13.33],s=Yn(47*7919+13),a=256,o=new Uint8Array(a*a*4),c={width:a,height:a,rgba:o,frames:[]};for(let u=0;u<16;u++){const l=5+(s()*3|0),d=s()*Math.PI*2,f=[];for(let b=0;b<l;b++)f.push(.78+.44*s());const h=b=>{let v=0;const x=f.map((S,k)=>{const _=d+k/l*Math.PI*2;return[Math.cos(_)*S*b,Math.sin(_)*S*b]}),P=(S,k)=>{let _=!1;for(let I=0,B=x.length-1;I<x.length;B=I++){const[V,O]=x[I],[U,W]=x[B];O>k!=W>k&&S<(U-V)*(k-O)/(W-O)+V&&(_=!_)}return _};for(let S=0;S<64;S++)for(let k=0;k<64;k++)P((k+.5-64/2)/(64/2),(S+.5-64/2)/(64/2))&&v++;return v/4096};let p=.05,m=1.2;for(let b=0;b<22;b++){const v=(p+m)/2;h(v)<i[u]/100?p=v:m=v}const g=(p+m)/2,y=u%4*64,w=(u/4|0)*64,A=f.map((b,v)=>{const x=d+v/l*Math.PI*2;return[Math.cos(x)*b*g,Math.sin(x)*b*g]});for(let b=0;b<64;b++)for(let v=0;v<64;v++){const x=(v+.5-32)/32,P=(b+.5-64/2)/(64/2);let S=!1;for(let _=0,I=A.length-1;_<A.length;I=_++){const[B,V]=A[_],[O,U]=A[I];V>P!=U>P&&x<(O-B)*(P-V)/(U-V)+B&&(S=!S)}const k=((w+b)*a+y+v)*4;o[k]=255,o[k+1]=255,o[k+2]=255,o[k+3]=S?255:0}c.frames.push({x:y,y:w,width:64,height:64})}return c}const Zw=1024,Ql=64,Bn=128;function Jw(t){const{gen:e=Bn>>1,frames:n=Ql,seed:r=11,puffs:i=81,spread:s=.73,sMin:a=.044,sMax:o=.15,ampMin:c=.4,ampMax:u=1,coreAmp:l=.64,coreS:d=.225,lobeBias:f=1.7,hazes:h=8,hazeAmp:p=.162,hazeSMin:m=.175,hazeSMax:g=.31,hazeSpread:y=.33,move:w=.06,pulse:A=.41,spin:b=0}=t,v=Yn(r*7919+101),x=e/2,P=[];for(let I=0;I<i+h;I++){const B=I>=i,V=(B?y:s)*Math.pow(v(),1/(2*(B?1:f))),O=v()*Math.PI*2,U=B?m+(g-m)*v():a+(o-a)*v(),W=B?p*(.6+.8*v()):c+(u-c)*v();P.push({cx:V*Math.cos(O),cy:V*Math.sin(O),s:U,amp:W,ph:v()*Math.PI*2,r1:1+(v()*2|0),r2:1+(v()*3|0),w:v()*Math.PI*2})}const S=new Float32Array(n*e*e),k=Math.PI*2,_=Math.round(b);for(let I=0;I<n;I++){const B=I/n,V=k*B,O=Math.cos(_*V),U=Math.sin(_*V),W=I*e*e;for(const ie of P){const we=x+(ie.cx*O-ie.cy*U+w*Math.cos(ie.r1*V+ie.ph))*x,Y=x+(ie.cx*U+ie.cy*O+w*Math.sin(ie.r1*V+ie.ph))*x,oe=ie.s*(1+A*.5*Math.sin(ie.r2*V+ie.w))*x,he=ie.amp*(1+A*.4*Math.sin(ie.r2*V+ie.w+1.7)),Ae=2.4*oe,Pe=Math.max(0,Math.floor(we-Ae)),Ce=Math.min(e-1,Math.ceil(we+Ae)),Le=Math.max(0,Math.floor(Y-Ae)),Ne=Math.min(e-1,Math.ceil(Y+Ae)),De=1/(oe*oe);for(let Re=Le;Re<=Ne;Re++)for(let Fe=Pe;Fe<=Ce;Fe++){const Xe=Fe+.5-we,$e=Re+.5-Y,Ye=(Xe*Xe+$e*$e)*De;Ye>5.76||(S[W+Re*e+Fe]+=he*Math.exp(-Ye))}}for(let ie=0;ie<e;ie++)for(let we=0;we<e;we++){const Y=(we+.5-x)/x,oe=(ie+.5-x)/x,he=Math.hypot(Y,oe);S[W+ie*e+we]+=l*Math.exp(-((he/d)**2))}}return{out:S,gen:e,frames:n}}function Yl(t,e){const n=e||{},r=n.gen===void 0?Bn>>1:n.gen,i=Ql,s=n.detail===void 0?.048:n.detail,a=5,o=3,c=.05,u=77,l=n.gamma===void 0?.838:n.gamma,d=n.gain===void 0?1.238:n.gain,f=n.margin===void 0?.038:n.margin,p=Jw({gen:r,frames:i,seed:11,...n}),m=Math.max(1,Math.round(Bn/r)),g=Hl(a,o,u),y=Zw,w=new Uint8Array(y*y*4),A={width:y,height:y,rgba:w,frames:[]},b=Math.PI*2,v=p.out;for(let x=0;x<i;x++){const P=x/i,S=c*Math.cos(b*P),k=c*Math.sin(b*P),_=Math.min(7,x/8|0),B=x%8*Bn,V=_*Bn,O=x*r*r;for(let U=0;U<r;U++)for(let W=0;W<r;W++){const ie=(W+.5)/r,we=(U+.5)/r,Y=v[O+U*r+W]+s*(g(ie+S,we+k)-.5)*2;let oe=Y<=0?0:Math.pow(Math.min(1,d*Y),l);const he=Math.min(W,U,r-1-W,r-1-U)/r;he<f&&(oe*=Kn(he/f));const Ae=t==="light"?Math.min(1,.8*Math.pow(oe,1.25)):.865+.108*oe,Pe=Math.round(255*Ae),Ce=Math.round(255*oe);for(let Le=0;Le<m;Le++)for(let Ne=0;Ne<m;Ne++){const De=((V+U*m+Le)*y+B+W*m+Ne)*4;w[De]=Pe,w[De+1]=Pe,w[De+2]=Pe,w[De+3]=Ce}}A.frames.push({x:B,y:V,width:Bn,height:Bn})}return A}const oa={"particle/halo_6":()=>Mw(128),"particle/normal_splash":()=>Rn(bm(256),3.2),"particle/drop_normal":()=>Rn($l(128,512),3.4),"particle/normal_ring_smooth":()=>Rn(zl(256,.55,.12),3.1),"particle/normal_pinch_rotate":()=>Rn(Bw(256),2.8),"particle/water/rain_drops_sheet_normal":()=>Rn(Em(),3.6),"particle/bubbles/bubble1normal":()=>Rn(xo(256,1),3.2),"particle/bubbles/bubble2_normal":()=>Rn(xo(256,2),3.2),"particle/sharp_halo_normal":()=>Rn(ra(256,[{r:.035,w:1},{r:.09,w:.45},{r:.22,w:.08}]),3.4),"particle/beam/beam_0":()=>Ao(128,512,.46,!0),"particle/beam/beam_1":()=>Cw(32),"particle/beam/beam_2":()=>Ao(128,512,.22,!0),"particle/beam/beam_2_fade":()=>Ao(128,512,.24,!1),"particle/light/light_shafts_0":()=>ki(0),"particle/light/light_shafts_1":()=>ki(1),"particle/light/light_shafts_2":()=>ki(2),"particle/light/light_shafts_3":()=>ki(3),"particle/light/light_shafts_4":()=>ki(4),"particle/light/light_shafts_5":()=>ki(5),"particle/light/light_shafts_6":()=>ki(6),"particle/nature/rosepetals":()=>ym(256),"particle/nature/leaves":()=>Ot(Ut,0),"particle/nature/leaves1":()=>Ot(Ut,1),"particle/nature/leaves2":()=>Ot(Ut,2),"particle/nature/leaves3":()=>Ot(Ut,3),"particle/nature/leaves5":()=>Ot(Ut,5),"particle/nature/leaves6":()=>Ot(Ut,6),"particle/nature/leaves7":()=>Ot(Ut,7),"particle/nature/leaves8":()=>Ot(Ut,8),"particle/nature/snow":()=>km(256),"particle/halo":()=>Ew(256,[234,225,201,164,119,75,41,19,8,3,1].map(t=>t/255)),"particle/halo_1":()=>xi(256,{r:.1,w:1},{r:.3,w:.13}),"particle/halo_2":()=>xi(256,{r:.2,w:.9},{r:.44,w:.2}),"particle/halo_3":()=>ra(256,[{r:.045,w:1},{r:.13,w:.85},{r:.36,w:.15}]),"particle/halo_4":()=>xi(256,{r:.085,w:1},{r:.28,w:.12}),"particle/halo_5":()=>ra(256,[{r:.04,w:1},{r:.11,w:.8},{r:.34,w:.17}]),"particle/sharp_halo":()=>ra(256,[{r:.035,w:1},{r:.09,w:.45},{r:.22,w:.08}]),"particle/chromaticdot":()=>Ww(128),"particle/light/flare_0":()=>Zr(256,6,.58,10,.08),"particle/light/flare_1":()=>jw(512),"particle/light/flare_2":()=>Sm(256),"particle/drop":()=>$l(128,512),"particle/nature/rain1":()=>pm({segments:120,peakMax:.42,peakPow:2.4}),"particle/nature/rain2":()=>pm({segments:120,peakMax:.55,peakPow:2.2}),"particle/water/rain_drops_sheet":()=>Em(),"particle/water/splash_1":()=>aa(gs["particle/water/splash_1"]),"particle/water/ripple_single":()=>aa(gs["particle/water/ripple_single"]),"particle/fog/fog1":()=>$w(),"particle/fog/fog2":()=>aa(gs["particle/fog/fog2"]),"particle/fog/fog3":()=>aa(gs["particle/fog/fog3"]),"particle/smoke/smoke2":()=>Yl("smoke2"),"particle/smoke/smoke2light":()=>Yl("light"),"particle/smoke/smoke1":()=>jl(512,3,5,7,.55,1.5,185),"particle/misc/wave":()=>zl(512,.72,.085),"particle/misc/star_0":()=>Zr(256,5,.62,8,.1),"particle/bubbles/bubble1":()=>xo(256,1),"particle/bubbles/bubble2":()=>xo(256,2),"particle/bubbles/bubble3":()=>Iw(1024,64,58,11776798),"particle/debris/debris1":()=>Am(128),"particle/lightning/lightning1":()=>ko(256,3),"particle/lightning/lightning2":()=>ko(256,11),"particle/lightning/lightning3":()=>ko(256,19),"particle/fire/fire1":()=>ql(256,23),"particle/fire/fire2":()=>ql(256,41),"particle/star":()=>Zr(256,4,.58,12,.09),"particle/shape/circle_wind":()=>wm(256),"particle/sickle":()=>xm(256),"particle/magic/glyph_4":()=>Tm(256,4),"@sparkle":()=>Zr(256,4,.6,16,.08),"@star":()=>Zr(256,5,.62,8,.1),"@trail":()=>Xl(128,256)};function Mm(t){const e=String(t).toLowerCase();if(/normal/.test(e)){const n=zw(t);return n?()=>Rn(Hw(n),2.8):()=>Rn(bm(128),2.6)}return/rosepetal|petal|sakura|blossom/.test(e)?()=>ym(256):/leaf|leaves|foliage/.test(e)?/leaves8/.test(e)?()=>Ot(Ut,8):/leaves7/.test(e)?()=>Ot(Ut,7):/leaves6/.test(e)?()=>Ot(Ut,6):/leaves5/.test(e)?()=>Ot(Ut,5):/leaves3/.test(e)?()=>Ot(Ut,3):/leaves2/.test(e)?()=>Ot(Ut,2):/leaves1/.test(e)?()=>Ot(Ut,1):()=>Ot(Ut,0):/circle_wind|windcircle/.test(e)?()=>wm(256):/fog|cloud|mist|vapor/.test(e)?()=>jl(512,4,5,5,.4,.9,210):/smoke/.test(e)?()=>jl(512,3,5,8,.55,1.5,185):/beam|shaft|ray|godray/.test(e)?()=>Ao(128,512,.3,!0):/flare/.test(e)?()=>Sm(256):/bubble/.test(e)?()=>gm(256,1):/ring|wave/.test(e)?()=>zl(512,.72,.085):/fire|flame|ember|ash/.test(e)?()=>ql(256,Gl(e)):/sickle|crescent|moon/.test(e)?()=>xm(256):/glyph|magic|rune/.test(e)?()=>Tm(256,Gl(e)):/snowflake|雪花|snow/.test(e)?()=>km(256):/流星|meteor|shooting/.test(e)?()=>Xl(128,256):/star|星/.test(e)?()=>Zr(256,5,.62,8,.1):/sparkle|glint|twinkle/.test(e)?()=>Zr(256,4,.6,16,.08):/rain_drops_sheet|drops_sheet/.test(e)?()=>Vw(256,512,2,4):/drop|rain/.test(e)?()=>$l(128,512):/debris|dirt|rock/.test(e)?()=>Am(128):/lightning|bolt|arc/.test(e)?()=>ko(256,Gl(e)):/note|music/.test(e)?()=>Zr(256,4,.55,8,.12):/trail|streak/.test(e)?()=>Xl(128,256):()=>xi(256,{r:.12,w:1},{r:.3,w:.15})}function ev(t){if(Cn.has(t))return Cn.get(t);let e=null;const n=Ol.get(t);if(n)try{e=n()}catch{e=null}if(!e&&vo)try{e=vo(t)}catch{e=null}if(!e&&oa[t])try{e=oa[t]()}catch{e=null}if(!e)try{e=Mm(t)()}catch{e=null}e||(e=xi(256,{r:.12,w:1},{r:.3,w:.15}));for(const r of tv)if(r.re.test(t)){nv(e,r.band);break}return Cn.set(t,e),e}const tv=[{re:/^particle\/(light|beam|fire)\/(?!beam_1)/,band:.18},{re:/^particle\/bubbles\/(?!.*normal)(?!bubble3)/,band:.18},{re:/^particle\/(misc|shape)\//,band:.18},{re:/^particle\/(star|sickle)/,band:.18},{re:/^particle\/drop$/,band:.08},{re:/^@(star|sparkle|trail)$/,band:.18}];function nv(t,e){if(!t||!t.rgba)return t;const n=t.width,r=t.height,i=Math.max(2,Math.round(Math.min(n,r)*e)),s=t.rgba;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>=i)continue;const u=Kn(c/i),l=(a*n+o)*4+3;s[l]=Math.round(s[l]*u)}return t}function rv(t){return typeof t=="string"&&t.indexOf("particle/")===0}function iv(t,e,n){const r=Yn(n),i=new Float32Array(e*e);for(let o=0;o<i.length;o++)i[o]=r();const s=new Float32Array(t*t),a=t/e;for(let o=0;o<t;o++){const c=o/a,u=Math.floor(c),l=c-u,d=l*l*(3-2*l),f=u%e*e,h=(u+1)%e*e;for(let p=0;p<t;p++){const m=p/a,g=Math.floor(m),y=m-g,w=y*y*(3-2*y),A=g%e,b=(g+1)%e,v=i[f+A],x=i[f+b],P=i[h+A],S=i[h+b],k=v+(x-v)*w,_=P+(S-P)*w;s[o*t+p]=k+(_-k)*d}}return s}function sv(t=256){const e=[[4,.5,2654435761],[8,.25,2246822507],[16,.125,3266489909],[32,.0625,668265263],[64,.03125,374761393]],n=new Float32Array(t*t);let r=0;for(const[s,a,o]of e){const c=iv(t,s,o);for(let u=0;u<n.length;u++)n[u]+=c[u]*a;r+=a}const i=new Uint8Array(t*t*4);for(let s=0;s<n.length;s++){let a=n[s]/r;a=Math.min(1,Math.max(0,(a-.3)/.52)),a=a*a*(3-2*a);const o=Math.round(a*255),c=s*4;i[c]=o,i[c+1]=o,i[c+2]=o,i[c+3]=255}return{width:t,height:t,rgba:i}}function av(t){return t==="util/clouds_256"?(Cn.has(t)||Cn.set(t,sv(256)),Cn.get(t)):t==="util/black"?(Cn.has(t)||Cn.set(t,{width:1,height:1,rgba:new Uint8Array([0,0,0,255])}),Cn.get(t)):null}const ov=Object.freeze(Object.defineProperty({__proto__:null,RING_SHEETS:gs,bilinearResize:Wl,buildBuiltinParticleTexture:ev,buildBuiltinUtilTexture:av,builtinParticleFrames:Rw,convertParticleNormalFormat:Dw,convertParticleTexFormat:Fw,isBuiltinParticleTextureName:rv,isPackedNormalTexture:Nw,listBuiltinParticleTextureNames:_w,particleNormalNameForAlbedo:Ow,prepareParticleNormalTexture:Lw,resetParticleTextureFactories:Pw,rgbaLooksLikeAlbedo:vm,ringSheetAtlas:aa,setParticleTextureFactory:Tw,setParticleTextureProvider:Sw,smokePuffAtlas:Yl},Symbol.toStringTag,{value:"Module"})),cv=["util/white","util/black","util/noflow","util/flatnormal","util/noise","util/perlin_256","util/uniform_256","util/fur","util/clouds_256"],lv=new Set(["util/flatnormal","util/fur","util/noflow","util/noise"]);function uv(t){return lv.has(t)}function To(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 fv(t,e,n,r){const i=To((n^Math.imul(r|0,2654435761))>>>0),s=new Float32Array(e*e);for(let c=0;c<s.length;c++)s[c]=i();const a=new Float32Array(t*t),o=t/e;for(let c=0;c<t;c++){const u=c/o,l=Math.floor(u),d=u-l,f=d*d*d*(d*(d*6-15)+10),h=l%e*e,p=(l+1)%e*e;for(let m=0;m<t;m++){const g=m/o,y=Math.floor(g),w=g-y,A=w*w*w*(w*(w*6-15)+10),b=y%e,v=(y+1)%e,x=s[h+b],P=s[h+v],S=s[p+b],k=s[p+v],_=x+(P-x)*A,I=S+(k-S)*A;a[c*t+m]=_+(I-_)*f}}return a}function Cm(t,e,n){const r=new Float32Array(t*t);let i=0;for(const[s,a]of e){const o=fv(t,s,s*2654435761^2246822507,n);for(let c=0;c<r.length;c++)r[c]+=o[c]*a;i+=a}for(let s=0;s<r.length;s++)r[s]/=i;return r}function Im(t,e,n){let r=0,i=0;for(let l=0;l<t.length;l++)r+=t[l],i+=t[l]*t[l];const s=t.length,a=r/s,o=Math.sqrt(Math.max(1e-9,i/s-a*a)),c=n/o,u=new Uint8ClampedArray(s);for(let l=0;l<s;l++)u[l]=e+(t[l]-a)*c;return u}function Rm(t,e){const n=new Uint8Array(e*e*4);for(let r=0;r<e*e;r++)n[r*4]=t[0][r],n[r*4+1]=t[1][r],n[r*4+2]=t[2][r],n[r*4+3]=t[3][r];return n}function So(t,e,n,r,i){const s=new Uint8Array(t*t*4);for(let a=0;a<t*t;a++)s[a*4]=e,s[a*4+1]=n,s[a*4+2]=r,s[a*4+3]=i;return s}const Kl=new Map;function dv(){const e=To(1852795251),n=new Uint8Array(256*256*4);for(let r=0;r<256*256;r++)n[r*4]=e()*256,n[r*4+1]=e()*256,n[r*4+2]=e()*256,n[r*4+3]=e()*256;return{width:256,height:256,rgba:n}}function hv(){const e=[[4,.55],[8,.27],[16,.13],[32,.05]],r=[[94.8,21.5,1],[108.4,26.2,2],[145.2,23.6,3],[112,32,4]].map(([i,s,a])=>Im(Cm(256,e,a),i,s));return Rm(r,256)}function mv(){const e=To(1970170214),n=new Uint8Array(256*256*4);for(let r=0;r<256*256;r++)for(let i=0;i<4;i++)n[r*4+i]=e()<.5?0:1+Math.floor(e()*254);return{width:256,height:256,rgba:n}}function pv(){const e=To(1718972961),n=new Uint8Array(16384*4);for(let r=0;r<16384;r++){const i=e()<.413?0:Math.floor(21+Math.pow(e(),.62)*234);n[r*4]=i,n[r*4+1]=i,n[r*4+2]=i,n[r*4+3]=255}return{width:128,height:128,rgba:n}}function gv(){const n=Im(Cm(256,[[4,.42],[8,.24],[16,.16],[32,.11],[64,.07]],5),126,52.7);return{width:256,height:256,rgba:Rm([n,n,n,n],256)}}let Zl=null;function yv(t){Zl=typeof t=="function"?t:null}function bv(t){if(Zl)try{const n=Zl(t);if(n&&n.rgba)return n}catch{}if(Kl.has(t))return Kl.get(t);let e=null;switch(t){case"util/white":e={width:32,height:32,rgba:So(32,255,255,255,255)};break;case"util/black":e={width:32,height:32,rgba:So(32,0,0,0,255)};break;case"util/noflow":e={width:32,height:32,rgba:So(32,127,127,0,255)};break;case"util/flatnormal":e={width:16,height:16,rgba:So(16,255,127,0,127)};break;case"util/noise":e=dv();break;case"util/perlin_256":e={width:256,height:256,rgba:hv()};break;case"util/uniform_256":e=mv();break;case"util/fur":e=pv();break;case"util/clouds_256":e=gv();break}return e&&Kl.set(t,e),e}const wv=Object.freeze(Object.defineProperty({__proto__:null,SYSTEM_UTIL_TEXTURES:cv,buildSystemUtilTexture:bv,isNomipSystemTexture:uv,setSystemTextureProvider:yv},Symbol.toStringTag,{value:"Module"})),Po=64,Jl=2,vv=256,eu={ferro_fluid:{r8:!1,stops:[[0,0,0,0],[4,0,0,1],[8,0,0,0],[12,0,0,0],[16,0,0,0],[20,0,0,0],[24,0,0,0],[28,0,0,0],[32,0,0,5],[36,0,0,12],[40,9,3,23],[41,234,233,235],[42,243,242,243],[44,159,156,165],[46,74,69,85],[48,14,8,28],[52,0,0,9],[56,0,0,0],[60,0,0,0],[63,0,0,1]]},fire:{r8:!1,stops:[[0,130,14,14],[4,142,11,12],[8,160,5,10],[12,180,0,7],[16,202,0,4],[20,223,0,1],[24,241,0,0],[28,254,0,0],[32,255,23,3],[36,255,63,10],[40,255,105,17],[44,255,126,20],[48,255,146,24],[52,254,164,27],[56,252,180,30],[60,251,194,32],[63,250,202,34]]},fire_2:{r8:!1,stops:[[0,255,255,255],[2,255,255,255],[3,0,0,0],[4,0,0,0],[8,0,0,0],[12,0,0,0],[16,0,0,0],[20,0,0,0],[21,0,0,0],[22,52,33,16],[24,233,149,71],[26,248,152,72],[28,194,108,50],[30,142,66,28],[32,135,60,24],[36,135,60,22],[40,144,60,22],[44,155,62,22],[48,166,66,23],[52,166,66,23],[56,166,66,22],[60,118,47,15],[62,79,31,10],[63,32,12,4]]},fire_3:{r8:!1,stops:[[0,18,10,10],[4,21,8,8],[8,26,6,6],[12,42,5,5],[16,102,10,10],[20,134,17,17],[24,130,23,23],[26,145,20,21],[28,182,5,13],[32,253,0,0],[36,255,39,2],[40,255,103,8],[44,254,167,19],[47,250,202,32],[48,248,219,56],[50,243,225,145],[51,241,225,169],[52,244,215,108],[53,250,204,34],[56,252,212,64],[60,254,231,147],[63,255,243,200]]},ghost_flame:{r8:!1,stops:[[0,0,0,0],[4,0,0,0],[8,0,0,0],[12,2,0,1],[16,209,28,126],[17,183,24,110],[18,191,25,115],[20,74,10,44],[22,0,0,0],[24,0,0,0],[28,0,0,0],[32,0,0,0],[36,0,0,0],[40,19,2,20],[43,201,26,207],[44,231,60,235],[47,255,216,253],[48,223,226,252],[49,216,255,255],[52,25,244,255],[53,0,220,247],[56,0,103,117],[60,0,42,47],[63,0,8,9]]},ice:{r8:!1,stops:[[0,114,190,255],[4,117,191,255],[8,121,193,255],[12,126,196,255],[16,132,199,255],[20,138,202,255],[24,145,205,255],[28,152,208,255],[32,158,211,255],[36,164,214,255],[40,170,216,255],[44,175,218,255],[48,178,220,255],[52,181,220,255],[56,182,220,255],[58,181,219,255],[60,146,194,255],[63,107,168,255]]},iridescent:{r8:!1,stops:[[0,254,164,142],[4,254,164,139],[8,239,174,149],[12,210,187,172],[16,177,196,198],[20,134,189,226],[24,90,183,254],[28,75,175,254],[32,70,170,255],[36,80,159,255],[40,104,142,255],[44,139,126,255],[48,179,126,255],[52,164,130,253],[56,119,135,255],[60,102,162,255],[63,93,175,255]]},neon:{r8:!1,stops:[[0,0,186,255],[4,0,186,255],[8,10,178,255],[12,40,153,255],[16,79,120,255],[20,122,83,255],[24,165,49,255],[28,205,21,255],[32,238,3,255],[36,255,1,248],[40,255,17,221],[44,255,47,184],[48,255,86,142],[52,255,129,99],[56,255,170,58],[60,255,205,24],[63,255,224,5]]},rainbow:{r8:!1,stops:[[0,255,0,0],[4,255,0,94],[8,255,0,213],[10,255,0,253],[12,224,0,255],[16,117,0,255],[20,16,0,255],[22,0,13,255],[24,0,57,255],[28,0,170,255],[32,0,255,255],[36,0,255,165],[40,0,255,49],[42,0,255,7],[44,26,255,0],[48,144,255,0],[52,248,255,0],[54,255,232,0],[56,255,187,0],[60,255,80,0],[63,255,14,0]]},swamp:{r8:!1,stops:[[0,60,36,50],[4,60,36,50],[8,60,36,50],[12,60,36,50],[16,58,46,61],[20,54,65,82],[24,50,87,108],[28,45,112,135],[32,42,135,159],[36,40,154,176],[40,41,167,182],[44,45,175,180],[48,51,179,171],[52,59,181,157],[56,66,181,141],[60,73,181,128],[63,76,182,121]]},swipe_dual:{r8:!1,stops:[[0,0,0,0],[2,0,0,0],[4,76,76,76],[7,224,224,224],[8,255,255,255],[9,255,255,255],[10,0,0,0],[11,0,0,0],[12,245,245,245],[16,218,218,218],[20,183,183,183],[24,143,143,143],[28,102,102,102],[32,63,63,63],[36,29,29,30],[40,4,4,5],[44,0,0,0],[48,0,0,0],[52,0,0,0],[56,0,0,0],[60,0,0,0],[63,0,0,0]]},swipe_wide:{r8:!1,stops:[[0,0,0,0],[2,0,0,0],[3,255,255,255],[4,255,255,255],[8,233,233,233],[12,201,201,201],[16,163,163,163],[20,122,122,122],[24,82,82,82],[28,45,45,45],[32,16,16,16],[36,0,0,0],[40,0,0,0],[44,0,0,0],[48,0,0,0],[52,0,0,0],[56,0,0,0],[60,0,0,0],[63,0,0,0]]},toon:{r8:!0,stops:[[0,0,0,0],[4,0,0,0],[8,0,0,0],[12,0,0,0],[16,0,0,0],[20,0,0,0],[24,0,0,0],[28,0,0,0],[32,0,0,0],[36,0,0,0],[39,0,0,0],[40,255,255,255],[44,255,255,255],[48,255,255,255],[52,255,255,255],[56,255,255,255],[60,255,255,255],[63,255,255,255]]},toon_smooth:{r8:!0,stops:[[0,0,0,0],[4,0,0,0],[8,0,0,0],[12,0,0,0],[16,1,1,1],[20,3,3,3],[24,6,6,6],[28,11,11,11],[32,17,17,17],[36,28,28,28],[38,34,34,34],[39,77,77,77],[40,165,165,165],[41,184,184,184],[44,197,197,197],[48,213,213,213],[52,227,227,227],[56,238,238,238],[60,248,248,248],[63,253,253,253]]}},tu={blend_gradient:{invert:!1,stops:[[0,0],[8,6],[16,14],[24,23],[32,33],[40,44],[48,56],[56,68],[64,81],[72,95],[80,109],[88,123],[96,137],[104,151],[112,165],[120,178],[128,191],[136,203],[144,215],[152,226],[160,235],[168,244],[176,251],[181,254]]},blend_gradient_reverse:{invert:!0,stops:[[0,0],[8,6],[16,14],[24,23],[32,33],[40,44],[48,56],[56,68],[64,81],[72,95],[80,109],[88,123],[96,137],[104,151],[112,165],[120,178],[128,191],[136,203],[144,215],[152,226],[160,235],[168,244],[176,251],[181,254]]}},nu=new Map;let ru=null;function Av(t){ru=typeof t=="function"?t:null}function xv(){return[...Object.keys(eu).map(t=>"gradient/gradient_"+t),...Object.keys(tu).map(t=>"gradient/"+t)]}function kv(t){return Bm(t)!==null}function Bm(t){if(typeof t!="string")return null;let e=/^gradient\/gradient_([a-z0-9_]+)$/.exec(t);return e&&eu[e[1]]?{kind:"ramp",spec:eu[e[1]]}:(e=/^gradient\/(blend_gradient(?:_reverse)?)$/.exec(t),e&&tu[e[1]]?{kind:"radial",spec:tu[e[1]]}:null)}function _o(t){return t<0?0:t>255?255:t}function Tv(t,e){if(e<=t[0][0])return[t[0][1],t[0][2],t[0][3]];const n=t[t.length-1];if(e>=n[0])return[n[1],n[2],n[3]];for(let r=0;r<t.length-1;r++){const i=t[r],s=t[r+1];if(e>=i[0]&&e<=s[0]){const a=s[0]===i[0]?0:(e-i[0])/(s[0]-i[0]);return[i[1]+(s[1]-i[1])*a,i[2]+(s[2]-i[2])*a,i[3]+(s[3]-i[3])*a]}}return[n[1],n[2],n[3]]}function Sv(t,e){if(e<=t[0][0])return t[0][1];const n=t[t.length-1];if(e>=n[0])return n[1];for(let r=0;r<t.length-1;r++){const i=t[r],s=t[r+1];if(e>=i[0]&&e<=s[0]){const a=s[0]===i[0]?0:(e-i[0])/(s[0]-i[0]);return i[1]+(s[1]-i[1])*a}}return n[1]}function Pv(t){const e=new Uint8Array(Po*Jl*4);for(let n=0;n<Jl;n++){const r=n*Po;for(let i=0;i<Po;i++){const[s,a,o]=Tv(t.stops,i),c=(r+i)*4;e[c]=_o(Math.round(s)),e[c+1]=_o(Math.round(a)),e[c+2]=_o(Math.round(o)),e[c+3]=255}}return{width:Po,height:Jl,rgba:e}}function _v(t){const e=vv,n=new Uint8Array(e*e*4),r=(e-1)/2;for(let i=0;i<e;i++)for(let s=0;s<e;s++){const a=Math.sqrt((s-r)*(s-r)+(i-r)*(i-r));let o=Sv(t.stops,a);t.invert&&(o=255-o);const c=(i*e+s)*4;n[c]=n[c+1]=n[c+2]=_o(Math.round(o)),n[c+3]=255}return{width:e,height:e,rgba:n}}function Ev(t){const e=Bm(t);if(!e)return null;const n=nu.get(t);if(n)return n;if(ru)try{const i=ru(t);if(i&&i.rgba)return nu.set(t,i),i}catch{}const r=e.kind==="radial"?_v(e.spec):Pv(e.spec);return nu.set(t,r),r}const Mv=Object.freeze(Object.defineProperty({__proto__:null,buildBuiltinGradientTexture:Ev,isBuiltinGradientTextureName:kv,listBuiltinGradientTextureNames:xv,setGradientTextureProvider:Av},Symbol.toStringTag,{value:"Module"})),Fm=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]);function Jr(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 Dm(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(Fm);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 iu(t,e,n,r,i,s,a,o,c,u){const l=u||new Float32Array(16),d=Math.cos(r),f=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*f-g*d)*o,l[5]=(g*p*f+m*d)*o,l[6]=h*f*o,l[7]=0,l[8]=(m*p*d+g*f)*c,l[9]=(g*p*d-m*f)*c,l[10]=h*d*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 Eo(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 Cv(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 Y of s){const oe=r.next+Y.lenOff;if(oe+4>t.byteLength)continue;const he=e.getUint32(oe,!0);if((Y.formatMarker===void 0||e.getUint32(r.next+28,!0)===Y.formatMarker)&&he>0&&he%Y.stride===0&&oe+4+he<=t.byteLength){a=Y,o=he,c=oe;break}}if(!a)throw new Error("\u9876\u70B9\u533A\u957F\u5EA6\u5F02\u5E38\uFF08"+n+"\uFF0C\u5DF2\u8BD5 stride "+s.map(Y=>Y.stride).join("/")+"\uFF09");const u=c+4,l=o/a.stride,d=new Float32Array(l*3),f=new Float32Array(l*2),h=new Float32Array(l*4),p=new Float32Array(l*4);for(let Y=0;Y<l;Y++){const oe=u+Y*a.stride;if(d[Y*3]=e.getFloat32(oe,!0),d[Y*3+1]=e.getFloat32(oe+4,!0),d[Y*3+2]=e.getFloat32(oe+8,!0),f[Y*2]=e.getFloat32(oe+a.uv,!0),f[Y*2+1]=e.getFloat32(oe+a.uv+4,!0),a.bone>=0&&a.weight>=0)for(let he=0;he<4;he++)h[Y*4+he]=e.getUint32(oe+a.bone+he*4,!0),p[Y*4+he]=e.getFloat32(oe+a.weight+he*4,!0);else h[Y*4]=0,p[Y*4]=1}const m=e.getUint32(u+o,!0),g=u+o+4,y=l>65535&&m%4===0,w=y?m/4:m/2,A=y?new Uint32Array(w):new Uint16Array(w);if(y)for(let Y=0;Y<w;Y++)A[Y]=e.getUint32(g+Y*4,!0);else for(let Y=0;Y<w;Y++)A[Y]=e.getUint16(g+Y*2,!0);const b=Rv(t,e),v=b.bones,x=Bv(e,b,v.length),P=Nv(t,e,v.length),S=Uv(t,e,v),k=Iv(t,e,v.length),_=[],I=[],B=[];if(v.length>0){const Y=v.map((he,Ae)=>{const Pe=he.matrix,Ce=Math.hypot(Pe[0],Pe[1]),Le=Math.hypot(Pe[4],Pe[5]);return B[Ae]=Float32Array.from([Pe[12],Pe[13],Pe[14],0,0,Math.atan2(Pe[1],Pe[0]),Ce||1,Le||1,Pe[10]||1]),Float32Array.from(Pe)});for(let he=0;he<v.length;he++){const Ae=B[he],Pe=v[he].matrix;Math.hypot(Ae[0]-Pe[12],Ae[1]-Pe[13])>.001&&(Y[he]=iu(Ae[0],Ae[1],Ae[2],Ae[3],Ae[4],Ae[5],Ae[6],Ae[7],Ae[8],new Float32Array(16)))}const oe=[];for(let he=0;he<v.length;he++){const Ae=v[he].parent;oe[he]=Ae>=0&&Ae<he?Jr(oe[Ae],Y[he]):Float32Array.from(Y[he])}for(let he=0;he<v.length;he++)_[he]=Float64Array.from(Dm(oe[he]));if(S){const he=[];for(let Ae=0;Ae<v.length;Ae++){const Pe=v[Ae].parent;he[Ae]=Pe>=0&&Pe<Ae?Jr(he[Pe],S[Ae]):Float32Array.from(S[Ae])}for(let Ae=0;Ae<v.length;Ae++)I[Ae]=Jr(he[Ae],_[Ae])}}let V=1/0,O=-1/0,U=1/0,W=-1/0;for(let Y=0;Y<l;Y++){const oe=d[Y*3],he=d[Y*3+1];oe<V&&(V=oe),oe>O&&(O=oe),he<U&&(U=he),he>W&&(W=he)}let ie=null,we=null;return x&&x.local.length===v.length&&(ie=x.local.map(Y=>Float32Array.from([Y[12],Y[13],Y[14],0,0,Math.atan2(Y[1],Y[0]),Math.hypot(Y[0],Y[1])||1,Math.hypot(Y[4],Y[5])||1,Y[10]||1])),x.permutationIdentity||(we=x.permutation)),{magic:n,materialPath:r.value,vertexCount:l,positions:d,uvs:f,boneIdx:h,weights:p,indexCount:w,indexType:y?"u32":"u16",indices:A,bones:v,staticPoseTRS:ie,staticPoseLocal:x?x.local:null,staticPosePermutation:we,staticPoseAt:x?x.at:-1,animations:P,animBound:Lv(P,v),invBindWorld:_,bindTRS:B.length>0?B:null,attachments:k.length>0?k:null,restCorrection:I.length>0?I:null,bounds:{minX:V,maxX:O,minY:U,maxY:W}}}function Iv(t,e,n){const r=Eo(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 d=0;d<16;d++)l[d]=e.getFloat32(u.next+d*4,!0);c<n&&s.push({bone:c,name:u.value,matrix:l}),a=u.next+64}return s}function Rv(t,e){const n=Eo(t,"MDLS");if(n<0)return{bones:[],sectionStart:-1,recordsEnd:-1,nextOff:-1,permutation:null};const r=e.getUint32(n+13,!0);if(r<=0||r>1024)return{bones:[],sectionStart:n,recordsEnd:-1,nextOff:-1,permutation:null};const i=h=>Number.isFinite(h[12])&&Number.isFinite(h[13])&&Number.isFinite(h[14])&&Math.abs(Math.hypot(h[0],h[1])-1)<.05&&Math.abs(Math.hypot(h[4],h[5])-1)<.05,s=()=>{const h=[];let p=n+17,m=!0;for(let g=0;g<r;g++){if(p+77>e.byteLength)return{bones:h,ok:!1,end:-1};const y=e.getUint32(p+1,!0),w=e.getInt32(p+5,!0),A=new Float32Array(16);for(let v=0;v<16;v++)A[v]=e.getFloat32(p+13+v*4,!0);const b=Pr(e,p+77);(!(w===-1||w>=0&&w<r)||!i(A))&&(m=!1),h.push({id:y,name:"",parent:w>=0&&w<r?w:-1,matrix:A}),p=b.next}return{bones:h,ok:m,end:p}},a=(h,p)=>({bones:h,sectionStart:n,recordsEnd:p,nextOff:e.getUint32(n+9,!0),permutation:null}),o=s();if(o.ok)return a(o.bones,o.end);const c=h=>{const p=Math.min(h+80,e.byteLength-76);for(let m=h;m<=p;m++){const g=e.getUint32(m,!0),y=e.getInt32(m+4,!0),w=e.getUint32(m+8,!0);if(g>=1e5||!(y===-1||y>=0&&y<r)||w!==64)continue;const A=new Float32Array(16);for(let b=0;b<16;b++)A[b]=e.getFloat32(m+12+b*4,!0);if(i(A)&&!(m<=h||t[m-1]!==0))return{id:g,parent:y,matrix:A,head:m,nameStart:h}}return null},u=[];let l=n+17,d=!0;for(let h=0;h<r;h++){const p=c(l);if(!p){d=!1;break}let m="",g=p.nameStart,y=p.head-1;for(;g<y&&t[g]===0;)g++;for(;y>g&&t[y-1]===0;)y--;if(y>g){const A=new TextDecoder("utf-8",{fatal:!1}).decode(t.subarray(g,y));/^[\x20-\x7e\u3000-\u9fff\uff00-\uffefA-Za-z0-9 _.-]*$/.test(A)&&(m=A)}u.push({id:p.id,name:m,parent:p.parent,matrix:p.matrix});const w=p.head+12+64;l=w<e.byteLength&&t[w]===123?Pr(e,w).next:w}return d&&u.length===r&&u.every(h=>h.parent===-1||h.parent>=0&&h.parent<r)&&u.every(h=>i(h.matrix))?a(u,l):a(o.bones,o.end)}function Bv(t,e,n){if(!e||n<=0||!(e.recordsEnd>0&&e.nextOff>e.recordsEnd))return null;const r=1+4*n,i=76*n,s=64*n,a=[],o=e.nextOff-r-i-9-s;o>=e.recordsEnd&&a.push(o);for(let u=e.recordsEnd;u<Math.min(e.recordsEnd+32,e.nextOff-s);u++)a.includes(u)||a.push(u);const c=u=>{if(!(Number.isFinite(u[12])&&Number.isFinite(u[13]))||Math.abs(u[15]-1)>.001||Math.abs(u[3])>.001||Math.abs(u[7])>.001||Math.abs(u[11])>.001)return!1;const l=(d,f,h)=>Math.hypot(u[d],u[f],u[h]);return Math.abs(l(0,1,2)-1)<.05&&Math.abs(l(4,5,6)-1)<.05&&Math.abs(l(8,9,10)-1)<.05};for(const u of a){if(u<0||u+s>e.nextOff)continue;const l=[];let d=!0;for(let m=0;m<n;m++){const g=new Float32Array(16);for(let y=0;y<16;y++)g[y]=t.getFloat32(u+m*64+y*4,!0);if(!c(g)){d=!1;break}l.push(g)}if(!d)continue;const f=[],h=e.nextOff-r;if(h>=u+s)for(let m=0;m<n;m++)f.push(t.getUint32(h+1+m*4,!0));const p=f.length===n&&f.every((m,g)=>m===g);return{local:l,permutation:f.length===n?f:null,permutationIdentity:p,at:u}}return null}function Fv(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 Dv(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 d=s,f=0;for(;d<o&&t.getUint8(d)!==123&&f<8;)d++,f++;if(f<8&&d<o&&t.getUint8(d)===123){s=d;continue}break}return{events:r,next:s}}function Nv(t,e,n){const r=Eo(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 d=Pr(e,i);if(i=d.next,i+16>e.byteLength)break;const f=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 A=0;A<p&&!(i+8>e.byteLength);A++){i+=4;const b=e.getUint32(i,!0);i+=4;const v=Math.floor(b/36);if(i+b>e.byteLength)break;const x=new Float32Array(v*9);for(let P=0;P<v;P++){const S=i+P*36;for(let k=0;k<9;k++)x[P*9+k]=e.getFloat32(S+k*4,!0)}i+=b,m.push({frameCount:v,keyframes:x})}const g=s>0&&s<=e.byteLength?s:e.byteLength,y=Dv(e,i,g);m.length>0&&h>0&&f>0&&o.push({id:u,name:l.value,mode:d.value,fps:f,frameCount:h,duration:h/f,tracks:m,events:y.events});const w=Fv(e,y.next,g);if(w<0)break;i=w}return o}function Lv(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 d=0;d<a.frameCount;d++){const f=Math.abs(l[d*9]-c),h=Math.abs(l[d*9+1]-u);f>n&&(n=f),h>r&&(r=h)}}return{x:n,y:r}}function Uv(t,e,n){if(n.length===0)return null;const r=Eo(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 Ov(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,d=o*9,f=1-c;for(let h=0;h<9;h++)if(h>=3&&h<=5){let p=u[d+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]*f+u[d+h]*c;return r}function Nm(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 zv(t,e,n){const r=t.staticPoseTRS&&t.staticPoseTRS[e];return r?(n.set(r),n):Nm(t,e,n)}function su(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 p=0;p<s;p++)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 p of n){if(p.visible===!1||p.visible===0||p.playing===!1)continue;const m=t.animations.find(g=>g.id===p.animation);m&&c.push({anim:m,additive:!!p.additive,blend:typeof p.blend=="number"?p.blend:1,rate:typeof p.rate=="number"?p.rate:1})}const u=!(t.animations&&t.animations.length)&&!!(t.staticPoseTRS&&t.staticPoseTRS.length===s);let l=!1;if(c.length===0&&!o){const p=t.animations[0];p?c.push({anim:p,additive:!1,blend:1,rate:1}):l=!a&&!u}const d=t._trsBase||(t._trsBase=new Float32Array(9)),f=t._trsAcc||(t._trsAcc=new Float32Array(9)),h=t._trsSmp||(t._trsSmp=new Float32Array(9));for(let p=0;p<s;p++){u?zv(t,p,d):Nm(t,p,d),f.set(d);let m=!1,g=0,y=!1,w=!1;const A=t._addDelta||(t._addDelta=new Float32Array(9));A.fill(0);for(const v of c){const x=v.anim.tracks[p];if(!x||!x.keyframes.length)continue;Ov(x,v.anim,e*v.rate,h);const P=v.blend;if(v.additive){const S=x.keyframes;if(!y&&!w){for(let k=0;k<9;k++)f[k]=S[k];w=!0}for(let k=0;k<9;k++){let _=h[k]-S[k];if(k>=3&&k<=5)_>Math.PI?_-=2*Math.PI:_<-Math.PI&&(_+=2*Math.PI);else if(k>=6&&(!(Math.abs(S[k])>.001)||Math.abs(h[k])>3&&Math.abs(S[k])<1.5))continue;A[k]+=_*P}g+=P}else{y=!0;for(let S=0;S<9;S++)f[S]=f[S]*(1-P)+h[S]*P}m=!0}if(g>1)for(let v=0;v<9;v++)A[v]/=g;if(g>0)for(let v=0;v<9;v++)f[v]+=A[v];const b=a?r.get(p):void 0;b&&(f[0]=b[0],f[1]=b[1],f[2]=b[2],m=!0),m?iu(f[0],f[1],f[2],f[3],f[4],f[5],f[6],f[7],f[8],t._local[p]):iu(d[0],d[1],d[2],d[3],d[4],d[5],d[6],d[7],d[8],t._local[p])}for(let p=0;p<s;p++){const m=i[p].parent;m>=0&&m<p?Jr(t._world[m],t._local[p],t._world[p]):t._world[p].set(t._local[p])}for(let p=0;p<s;p++)Jr(t._world[p],t.invBindWorld[p],t._tmp),t._skin.set(t._tmp,p*16);return l?null:t._skin}function Lm(t,e){return!t||!t.invBindWorld||!(e>=0&&e<t.invBindWorld.length)?null:Dm(t.invBindWorld[e])}function Hv(t,e){return Jr(t,e)}function Um(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:Jr(t._world[n.bone],n.matrix);return null}function Om(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=Lm(t,n.bone);return r?Jr(r,n.matrix):null}return null}function Vv(t,e){if(!t||!t.uvs||!t.positions||!e)return!1;const n=e[0],r=e[1];if(!(n>0&&r>0)||t.vertexCount<3)return!1;const i=Math.min(t.vertexCount,48),s=Math.max(1,t.vertexCount/i|0);let a=0,o=0;for(let c=0;c<t.vertexCount;c+=s){const u=t.positions[c*3],l=t.positions[c*3+1],d=Math.abs(t.uvs[c*2]-(u+n/2)/n),f=Math.abs(t.uvs[c*2+1]-(r/2-l)/r);a+=Math.max(d,f),o++}return o>0&&a/o<.001}function au(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,o=Math.cos(a),c=Math.sin(a),u=e*i,l=n*s;return[u*o-l*c,u*c+l*o]}function Wv(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=Om(o.puppet,a);if(!c)continue;const u=c[12],l=c[13],f=!(o.puppet.animations&&o.puppet.animations.length)&&!o.puppet.staticPoseTRS&&o.puppet.magic==="MDLV0019"&&Vv(o.puppet,o.size)?[0,0]:au(o,u,l),h=[];r(s,h),s.origin[0]+=f[0],s.origin[1]+=f[1];for(const p of h)p.origin[0]+=f[0],p.origin[1]+=f[1];s.parallaxDepth=o.parallaxDepth?o.parallaxDepth.slice():null;for(const p of h)p.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:h})}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 jv(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;su(c,e,o.parent.animationLayers,l)}const u=Um(c,o.name);if(!u){i.push(null);continue}i.push(au(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 d of l)d.layer.origin[0]+=u[0],d.layer.origin[1]+=u[1]}}const qv=128,Mo=24;function Xv(t){const e=t.getParameter(t.MAX_VERTEX_UNIFORM_VECTORS)||256,n=Math.floor((e-32)/4);return Math.max(Mo,Math.min(qv,n))}const $v=t=>`#version 300 es
|
|
142
532
|
in vec3 a_pos;
|
|
143
533
|
in vec2 a_uv;
|
|
144
534
|
in vec4 a_bone;
|
|
145
535
|
in vec4 a_weight;
|
|
146
536
|
uniform mat4 u_mvp;
|
|
147
|
-
uniform mat4 u_skin[${
|
|
537
|
+
uniform mat4 u_skin[${t}];
|
|
148
538
|
uniform int u_boneCount;
|
|
539
|
+
uniform float u_keepZ;
|
|
149
540
|
out vec2 v_uv;
|
|
150
541
|
void main() {
|
|
151
542
|
vec4 p = vec4(a_pos, 1.0);
|
|
@@ -162,9 +553,9 @@ void main() {
|
|
|
162
553
|
}
|
|
163
554
|
}
|
|
164
555
|
vec4 local = total > 0.0 ? skinned / total : p;
|
|
165
|
-
gl_Position = u_mvp * vec4(local.xy,
|
|
556
|
+
gl_Position = u_mvp * vec4(local.xy, local.z * u_keepZ, 1.0);
|
|
166
557
|
v_uv = a_uv;
|
|
167
|
-
}`,
|
|
558
|
+
}`,Gv=`#version 300 es
|
|
168
559
|
precision mediump float;
|
|
169
560
|
in vec2 v_uv;
|
|
170
561
|
uniform sampler2D u_tex;
|
|
@@ -173,12 +564,7 @@ out vec4 fragColor;
|
|
|
173
564
|
void main() {
|
|
174
565
|
vec4 t = texture(u_tex, v_uv);
|
|
175
566
|
fragColor = t * u_color;
|
|
176
|
-
}`;function Uc(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=kc(e),r=null;for(;;){const u=e.createProgram();let l=!1;try{e.attachShader(u,n(e.VERTEX_SHADER,Fc(t))),e.attachShader(u,n(e.FRAGMENT_SHADER,Nc)),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<=gr)throw new Error("MDL \u7740\u8272\u5668\u94FE\u63A5\u5931\u8D25\uFF08\u9AA8\u6570\u5DF2\u964D\u5230 "+gr+"\uFF09");t=Math.max(gr,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(Si,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=uo(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 Dc=Object.freeze(Object.defineProperty({__proto__:null,applyAttachmentBindOrigins:Cc,attachmentBind:Li,attachmentWorld:Ci,bindWorldOf:Pi,computeSkinMatrices:uo,createMDLRenderer:Uc,followAttachments:Lc,mat4MulOut:Pc,parentMeshToWorldDelta:fo,parseMDL:xc},Symbol.toStringTag,{value:"Module"}));function Ri(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 Bc(e,n,t){const r=Math.max(1,n.boxW),o=Math.max(1,n.boxH),i=Ri(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 Ic(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 ki=/^add[A-Z]/;function Fi(){return{log:()=>{},warn:()=>{},error:()=>{},info:()=>{},debug:()=>{}}}function Ni(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 wn(e,n){return()=>{}}function Ui(e,n){e.isScreensaver=!!n.isScreensaver,typeof n.isRunningInEditor=="boolean"&&(e.isRunningInEditor=n.isRunningInEditor),e.setInterval||(e.setInterval=n.setInterval||wn),e.setTimeout||(e.setTimeout=n.setTimeout||wn),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 ge{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 ge(n);return new ge(this.x+t.x,this.y+t.y,this.z+t.z)}subtract(n){const t=new ge(n);return new ge(this.x-t.x,this.y-t.y,this.z-t.z)}multiply(n){return n&&typeof n=="object"?new ge(this.x*n.x,this.y*n.y,this.z*n.z):new ge(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 ge(t(this.x,n.x),t(this.y,n.y),t(this.z,n.z)):new ge(t(this.x,n),t(this.y,n),t(this.z,n))}copy(){return new ge(this.x,this.y,this.z)}mix(n,t){const r=new ge(n),o=Number(t),i=Number.isFinite(o)?o:0;return new ge(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 ge(0,0,0):new ge(this.x/n,this.y/n,this.z/n)}dot(n){const t=new ge(n);return this.x*t.x+this.y*t.y+this.z*t.z}toString(){return this.x+" "+this.y+" "+this.z}}const Di=ge;function Bi(e){if(e instanceof ge||!e||typeof e!="object"||Array.isArray(e)||!("x"in e)&&!("y"in e)&&!("z"in e)||Object.getPrototypeOf(e)===ge.prototype)return e;try{Object.setPrototypeOf(e,ge.prototype)}catch{}return e}function Ii(e){return e&&e.cursorWorldPosition?e:{cursorWorldPosition:new ge(0,0,0),cursorScreenPosition:new ge(0,0,0),cursorPosition:new ge(0,0,0),cursorPositionLast:new ge(0,0,0),cursorLeftDown:!1}}function Oc(e,n,t){return new ge(e||0,n||0,t||0)}function $c(){const e={cursorWorldPosition:new ge(0,0,0),cursorScreenPosition:new ge(0,0,0),cursorPosition:new ge(0,0,0),cursorPositionLast:new ge(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 Oi={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},$i={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}}},ji={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})},zi=Object.freeze({PLAYBACK_STOPPED:0,PLAYBACK_PLAYING:1,PLAYBACK_PAUSED:2}),br=["mediaPropertiesChanged","mediaThumbnailChanged","mediaPlaybackChanged","mediaTimelineChanged","mediaStatusChanged","mediaLyricsChanged"],jc=["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"],zc=new RegExp(`(^[ \\t]*|;|\\})[ \\t]*(?:var|let|const)[ \\t]+(?=(?:${jc.join("|")})\\b)`,"gm"),Vc={WEMath:!0,WEColor:!0,WEVector:!0};function Vi(e){return typeof e!="string"?e:e.replace(/([!=])==(\s*)(['"])(-?\d+)\3/g,"$1=$2$3$4$3")}function Wi(e){return Vi(e).replace(/\bimport\s*\*\s*as\s+(\w+)\s+from\s*['"]([^'"]+)['"]\s*;?/g,(n,t,r)=>{const o=String(r);return Vc[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(zc,"$1")}function Gn(e){return e!==null&&typeof e=="object"&&"value"in e?e.value:e}function Hi(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 Wc(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]=Gn(h);const i=new Proxy(()=>i,{apply(){return i},get(M,h){if(h==="finish")return()=>o;if(typeof h=="string"&&ki.test(h))return g=>(g&&typeof g=="object"&&typeof g.name=="string"&&!(g.name in o)&&(o[g.name]=Gn(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:vr(t.origin||[0,0,0])},a={registerAsset:()=>{},frametime:1/60,runtime:0,canvasSize:Hi(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||wn,clearTimeout:t.clearTimeout||(()=>{}),setInterval:t.setInterval||wn,clearInterval:t.clearInterval||(()=>{}),openUserShortcut:t.openUserShortcut||(()=>{}),isRunningInEditor:!!t.isRunningInEditor,isScreensaver:!!t.isScreensaver};Ui(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:vr(t.origin||[0,0,0]),angles:[0,0,0],scale:[1,1,1]}},sortLayer:()=>{},getLayerIndex:()=>0},l=t.shared||{},f={console:Fi()},p=Ii(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,`+br.map(h=>`${h}: typeof ${h} === "function" ? ${h} : null,`).join("")+"dummy_: 0};")(o,Ni(a),s,u,Oi,$i,ji,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,ge,Di,p,zi)}catch(M){return t.onError&&t.onError(M,"parse"),null}const y=!!(d&&br.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 Yn(){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 Hc(e){if(!e)return Yn();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 Xc(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 Gc(){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 Yc(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 ge(A[0],A[1],0)}const M=Jt(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 ge(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 po(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 Xi(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 qc(e,n){e&&(e.visibleSelf=!1,e.visible=!1,e.destroyed=!0,n&&typeof n.recomputeVisibility=="function"&&n.recomputeVisibility())}function Gi(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 Zc(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 Kc(e){const n=t=>yr(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=Gi(t,i)}const o=e.createSceneLayer(r);return n(o||null)},destroyLayer(t){qc(Xi(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 Yn()},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):Xi(t,e)||null}}}function yr(e,n){const t=s=>vr(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:el(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?Yc(e,r):{getBoneCount:()=>0,getBoneTransform:()=>{const s={translation(a){return a===void 0?new ge(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:yr(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(yr(l,n))}return c},getAnimation:s=>{const a=e&&e.animations,c=e&&e.animationList||[];return s==null||s===""?c[0]||Yn():a&&a[s]?a[s]:typeof s=="number"&&c[s]?c[s]:typeof s=="string"&&/^\d+$/.test(s)&&c[Number(s)]?c[Number(s)]:Yn()},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)]:Yn()},getAnimationLayerCount:()=>(e&&e.animationList||[]).length,getTextureAnimation:()=>Hc(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:()=>Xc(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 po(null);if(typeof s=="number"||typeof s=="string"&&/^\d+$/.test(s))return po(a[Number(s)]||null);const c=String(s);return po(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=Yi(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 vr(a||[0,0,0])},set(a){const c=Jt(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:Gn(_)}else o[A]=Gn(_);const i=new Proxy(()=>i,{apply(){return i},get(A,_){if(_==="finish")return()=>o;if(typeof _=="string"&&ki.test(_))return R=>(R&&typeof R=="object"&&typeof R.name=="string"&&!(R.name in o)&&(o[R.name]=Gn(R.value)),i)}}),s={registerAsset:()=>{},frametime:1/60,runtime:0,canvasSize:Hi(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||wn,clearTimeout:t.clearTimeout||(()=>{}),setInterval:t.setInterval||wn,clearInterval:t.clearInterval||(()=>{}),openUserShortcut:t.openUserShortcut||(()=>{}),isRunningInEditor:!!t.isRunningInEditor,isScreensaver:!!t.isScreensaver};Ui(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:Fi()},l=Ii(t.inputView),f=t.layer||null,p=t.workshopId!=null?t.workshopId:Zc(e),d=yr(f,t),y=Kc({...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,`+br.map(_=>`${_}: typeof ${_} === "function" ? ${_} : null,`).join("")+"dummy_: 0};")(o,Ni(s),Oi,$i,ji,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,ge,Di,l,d,y,d,Gc(),zi)}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&&br.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(Bi(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(Bi(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 vr(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=Jt(o);return t.x+=i[0],t.y+=i[1],t.z+=i[2],r},subtract(o){const i=Jt(o);return t.x-=i[0],t.y-=i[1],t.z-=i[2],r},multiply(o){if(o&&typeof o=="object"){const i=Jt(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 ge(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 Jt(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 xr=Math.PI/180,wr=180/Math.PI;function Jc(e){const n=Array.isArray(e)?e:[0,0,0];return{x:(n[0]||0)*wr,y:(n[1]||0)*wr,z:(n[2]||0)*wr}}function Yi(e){const n=Jt(e);return[n[0]*xr,n[1]*xr,n[2]*xr]}function el(e){const n={x:0,y:1,z:2},t={add(r){const o=Jt(r);return t.x+=o[0],t.y+=o[1],t.z+=o[2],t},subtract(r){const o=Jt(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)*wr},set(o){!e||!Array.isArray(e.angles)||(e.angles[n[r]]=(Number(o)||0)*xr)}});return t}function tl(e,n){return Math.min(256,Math.ceil(Math.max(1,Number(e)||1)*2+8))}function nl(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 rl=Object.freeze(Object.defineProperty({__proto__:null,createInputView:$c,drawTextLayer:Ic,effectiveTextPadding:Ri,evalObjectScript:Qc,evalTextScript:Wc,layoutText:Bc,makeCursorEventVec:Oc,radToScriptAngles:Jc,resolveWorkshopAssetPath:Gi,rewriteComboStringEq:Vi,scriptAnglesToRad:Yi,textCanvasMargin:tl,textLayerHasTintMask:nl},Symbol.toStringTag,{value:"Module"}));function ol(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 il=Object.freeze(Object.defineProperty({__proto__:null,createEngineTimers:ol},Symbol.toStringTag,{value:"Module"}));function sl(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 ho(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 al=32,cl=112,qi=60/cl,ll=3.2;function ul(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 Zi(e=20260830){const n=sl(e),t=ul(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/qi,v=g*4,A=Math.floor(v)%16,_=v-Math.floor(v),R=Math.exp(-_*qi*14),L=h%al,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,W=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(ho(v*2,7))):0;let Z=0;for(let te=0;te<o;te++){const le=te/o,Fe=Math.pow(1-le*.85,1.6);let _e=O*(.5+.3*ho(g*.5+r[te]*.05,te%8));if(_e*=.35+.65*le,le<.2&&(_e+=W*(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*=Fe;const Ye=_e;_e=Math.min(1,_e*ll);const Ve=.06+le*.2,Ne=ho(g*.13+te*.35,11)*Ve;let qe=Math.min(1,Math.max(0,_e*(1-Ne))),Ue=Math.min(1,Math.max(0,_e*(1+Ne)));const ye=N?.012:0;i[te]=Math.max(ye,qe),s[te]=Math.max(ye,Ue),a[te]=Math.max(ye,Math.max(0,Ye*(1-Ne))),c[te]=Math.max(ye,Math.max(0,Ye*(1+Ne))),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 fl(e,n){for(const t of e.values()){Ki(t.left,n.left64),Ki(t.right,n.right64);for(let r=0;r<t.average.length;r++)t.average[r]=(t.left[r]+t.right[r])*.5}}function Ki(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 en={STOPPED:0,PLAYING:1,PAUSED:2};class ke{constructor(n,t,r){this.x=Number(n)||0,this.y=Number(t)||0,this.z=Number(r)||0}add(n){return new ke(this.x+n.x,this.y+n.y,this.z+n.z)}subtract(n){return new ke(this.x-n.x,this.y-n.y,this.z-n.z)}multiply(n){if(n!==null&&typeof n=="object")return new ke(this.x*n.x,this.y*n.y,this.z*n.z);const t=Number(n)||0;return new ke(this.x*t,this.y*t,this.z*t)}divide(n){const t=Number(n)||1;return new ke(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 ke(this.x,this.y,this.z)}toArray(){return[this.x,this.y,this.z]}}function dl(e,n,t){return new ke(e,n,t)}const pl=[{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"]]}],Mr=3;function Qi(e=20260901){const n=pl,t=n.reduce((M,h)=>M+h.duration+Mr,0),r={hasMedia:!1,state:en.STOPPED,title:"",artist:"",album:"",albumArtist:"",position:0,duration:0,hasThumbnail:!1,primaryColor:new ke(0,0,0),secondaryColor:new ke(0,0,0),tertiaryColor:new ke(0,0,0),textColor:new ke(1,1,1),highContrastColor:new ke(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+Mr;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<Mr){g=H,v=K,A=!0;break}h-=Mr}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=en.PAUSED:A?r.state=en.STOPPED:R>.7&&R<.76?r.state=en.PAUSED:r.state=en.PLAYING,r.hasThumbnail=!A;const L=_.colors;r.primaryColor=new ke(L.primary[0],L.primary[1],L.primary[2]),r.secondaryColor=new ke(L.secondary[0],L.secondary[1],L.secondary[2]),r.tertiaryColor=new ke(L.tertiary[0],L.tertiary[1],L.tertiary[2]),r.textColor=new ke(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 ke(0,0,0):new ke(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=en.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:en,skipNext:p,skipPrevious:d,play:x,pause:y,playPause:m}}function hl(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 ml(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 gl(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 bl=Object.freeze(Object.defineProperty({__proto__:null,MEDIA_PLAYBACK:en,cloneMediaSnapshot:gl,createSimulatedMedia:Qi,diffMediaEvents:ml,mediaVec3:dl,renderThumbnail:hl},Symbol.toStringTag,{value:"Module"})),Ji=14,qn=[{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 es(){const e={app:"",title:"",url:"",index:-1};function n(t){const r=Number(t)||0,o=qn.length?Math.floor(r/Ji)%qn.length:0,i=qn[o]||qn[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:qn,hold:Ji}}function ts(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 yl(e){const n=Qi(e),t=es(),r=ts(null);return{media:n,windowTitle:t,shortcuts:r}}const vl=Object.freeze(Object.defineProperty({__proto__:null,createShortcutHandler:ts,createSimulatedSystem:yl,createSimulatedWindowTitle:es},Symbol.toStringTag,{value:"Module"}));function xl(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 wl=Object.freeze(Object.defineProperty({__proto__:null,createPointerSource:xl},Symbol.toStringTag,{value:"Module"}));function ns(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=vn(h[0]),v=vn(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 Ml(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=ns(l,n,t,r,i,s,a);if(f&&Math.abs(f.lx)<=.5&&Math.abs(f.ly)<=.5)return l}return null}const _l=Object.freeze(Object.defineProperty({__proto__:null,hitTestLayers:Ml,worldToLayerLocal:ns},Symbol.toStringTag,{value:"Module"})),Xe=e=>e,Ge=Xe(Bs),_r=Xe(Js),Ke=Xe(fa),kt=Xe(ga),$e=Xe(qa),Al=Xe(Ka),Tl=Xe(rc),an=Xe(vc),Zn=Xe(Dc),tt=Xe(rl),Sl=Xe(il),we=Xe(bl),rs=Xe(vl),os=Xe(Wa),El=Xe(wl),Pl=Xe(_l);function Cl(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 Ll(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 Rl(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 kl(e,n){on(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=rr(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?Fl(e,n):Nl(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=$e.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((W,X)=>{O.addEventListener("loadedmetadata",()=>W(),{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:$e.makeTexture(m.gl,new Uint8Array([0,0,0,255]),1,1),width:v,height:A,rg88:!1,lastUploaded:-1}),e.paused||O.play().catch(()=>{}),Rl(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 W=await Ll(n.src);if(W&&W.frames.length>1){v=W.width,A=W.height;const X=m.gl,ie={glTex:$e.makeTexture(X,null,0,0,W.frames[0].bitmap),width:v,height:A,rg88:!1};h.set(M,ie);let J=0,Z=performance.now()+W.frames[0].durationMs;g=()=>{const le=performance.now();if(!(le<Z)){J=(J+1)%W.frames.length,Z=le+W.frames[J].durationMs,X.bindTexture(X.TEXTURE_2D,ie.glTex);try{X.texImage2D(X.TEXTURE_2D,0,X.RGBA,X.RGBA,X.UNSIGNED_BYTE,W.frames[J].bitmap)}catch{}}};const te=e.sceneCleanup;e.sceneCleanup=()=>{te?.();for(const le of W.frames)le.bitmap.close()},O=!0,se(e,n,`media gif ${v}x${A} ${W.frames.length} \u5E27 \u2192 scene \u6E32\u67D3`)}}catch(W){se(e,n,`gif \u89E3\u7801\u5931\u8D25\uFF0C\u56DE\u9000\u9759\u6001\u9996\u5E27: ${String(W.message).slice(0,80)}`)}if(!O){const W=new Image;if(W.crossOrigin="anonymous",W.src=n.src,await new Promise((X,ie)=>{W.addEventListener("load",()=>X(),{once:!0}),W.addEventListener("error",()=>ie(new Error("image load error")),{once:!0})}),f)return;v=W.naturalWidth||1,A=W.naturalHeight||1,e.img=W,h.set(M,{glTex:$e.makeTexture(m.gl,null,0,0,W),width:v,height:A,rg88:!1}),se(e,n,`media ${n.type} ${v}x${A} \u2192 scene \u6E32\u67D3`)}}if(f)return;const _=Cl(v,A,M),R=performance.now();let L=0,N=0,j=-1/0;const H=O=>{if(f||e.paused)return;const W=e.cfg.sceneFps||60;if(O-j>=1e3/W){j=O,Fn(e,O),So(e,s,e.cfg),g?.();const X=e.coverAlign;m.render(_,h,s.width,s.height,(O-R-L)/1e3,pn(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 Fl(e,n){if(on(e),!n.src){e.fallbackPage?.();return}const t=_o(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 Nl(e,n){on(e);const t=document.createElement("img"),r=_o(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 Ul=["scene.pkg","scenes/scene.pkg","gifscene.pkg"],Dl={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 is(e){const n=e.toLowerCase().split(";")[0].trim();return n==="image/gif"?"gif":n.startsWith("video/")?"video":n.startsWith("image/")?"image":null}function mo(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:Dl[o.slice(i+1).toLowerCase()]??null}async function Bl(e,n,t){try{const r=await fetch(e,{...n,method:"HEAD",signal:t});return r.ok?is(r.headers.get("content-type")||""):null}catch{return null}}function ss(e,n){const t=e.replace(/\/+$/,"");return{key:t,async scenePkg(r){let o=null,i=null;for(const a of Ul){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 Il(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 Ol(e,n,t){return{key:t,scenePkg:async()=>e,project:async()=>n??null}}function $l(e,n){const t=typeof e!="string",r=e;let o=n?.type??(t?is(e.type||""):null)??mo(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 Bl(e,void 0,u)),{url:a(),type:o??void 0}},dispose(){s&&(URL.revokeObjectURL(s),s=null)}}}const as=.5,jl=.04,cs=.08;function zl(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>as+.5){(u||l)&&y();return}if(l){(v<=cs||g<=cs)&&x();return}if(u){o.paused?o.play().catch(()=>{}):o.currentTime>=jl*.5&&(o.pause(),u=!1,l=!0);return}if(v<=as&&(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 ls=!1,us=!0,fs=!1,Vl=!1,Wl=!1,ds=4,Kn=64,ps={STOPPED:0};function Hl(){return{left64:new Float32Array(Kn),right64:new Float32Array(Kn),left32:new Float32Array(32),right32:new Float32Array(32),left16:new Float32Array(16),right16:new Float32Array(16),level:0,silent:!0}}function Ar(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 Xl(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<Kn;c++){const u=c/Kn,l=(c+1)/Kn,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)}Ar(e.left32,e.left64),Ar(e.right32,e.right64),Ar(e.left16,e.left64),Ar(e.right16,e.right64),e.level=Math.min(1,a/(48*1.2)),e.silent=e.level<.02}function Gl(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 go(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 Yl(e,n){const t=Gl(n||"empty"),[r,o,i]=go(t,72,48),[s,a,c]=go((t+40)%360,55,28),[u,l,f]=go((t+20)%360,70,72);e.primaryColor=we.mediaVec3(r,o,i),e.secondaryColor=we.mediaVec3(s,a,c),e.tertiaryColor=we.mediaVec3(u,l,f),e.textColor=we.mediaVec3(.98,.98,1),e.highContrastColor=we.mediaVec3(1,1,1),e.hasThumbnail=!!n}function ql(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 Zl(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 Kl(){return{hasMedia:!1,state:ps.STOPPED,title:"",artist:"",album:"",albumArtist:"",position:0,duration:0,hasThumbnail:!1,primaryColor:we.mediaVec3(0,0,0),secondaryColor:we.mediaVec3(0,0,0),tertiaryColor:we.mediaVec3(0,0,0),textColor:we.mediaVec3(1,1,1),highContrastColor:we.mediaVec3(1,1,1),trackIndex:-1,lyrics:[],lyricLine:"",lyricIndex:-1}}async function Ql(){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 hs(e){const n=e?.origin??(typeof location<"u"?location.origin:""),t=e?.onArtwork,r=Hl(),o=Kl(),i={app:"",title:"",url:"",index:0};let s="off",a="offline",c="offline",u="",l=!1,f="";const p=await Ql();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=ps.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,Yl(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),Xl(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 Jl={"common.h":`// WE common.h\uFF08\u91CD\u5EFA\u5B50\u96C6\uFF0C\u4F9B we-scene \u6D4F\u89C8\u5668\u6E32\u67D3\uFF09
|
|
567
|
+
}`;function Qv(t){const e=(u,l)=>{const d=t.createShader(u);if(t.shaderSource(d,l),t.compileShader(d),!t.getShaderParameter(d,t.COMPILE_STATUS))throw new Error("MDL \u7740\u8272\u5668\u7F16\u8BD1\u5931\u8D25: "+t.getShaderInfoLog(d));return d};let n=Xv(t),r=null;for(;;){const u=t.createProgram();let l=!1;try{t.attachShader(u,e(t.VERTEX_SHADER,$v(n))),t.attachShader(u,e(t.FRAGMENT_SHADER,Gv)),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<=Mo)throw new Error("MDL \u7740\u8272\u5668\u94FE\u63A5\u5931\u8D25\uFF08\u9AA8\u6570\u5DF2\u964D\u5230 "+Mo+"\uFF09");n=Math.max(Mo,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"),keepZ:t.getUniformLocation(r,"u_keepZ")},a=new Float32Array(i*16);for(let u=0;u<i;u++)a.set(Fm,u*16);const o=new WeakMap;function c(u){let l=o.get(u);if(l)return l;const d=t.createVertexArray();t.bindVertexArray(d);const f=u.vertexCount,h=new Float32Array(f*13);for(let y=0;y<f;y++){const w=y*13;h[w]=u.positions[y*3],h[w+1]=u.positions[y*3+1],h[w+2]=u.positions[y*3+2],h[w+3]=u.uvs[y*2],h[w+4]=u.uvs[y*2+1];for(let A=0;A<4;A++)h[w+5+A]=u.boneIdx[y*4+A],h[w+9+A]=u.weights[y*4+A]}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:d,vbuf:p,ibuf:g},o.set(u,l),l}return{gl:t,prog:r,maxBones:i,upload(u){c(u)},draw(u,l,d,f){const h=c(l);t.useProgram(r),t.bindVertexArray(h.vao),t.activeTexture(t.TEXTURE0);const p=d.overrideTex||(f&&f.glTex?f.glTex:f);t.bindTexture(t.TEXTURE_2D,p),t.uniform1i(s.tex,0),t.uniformMatrix4fv(s.mvp,!1,u),t.uniform1f(s.keepZ,d.keepZ?1:0);const m=d.color||[1,1,1,1];t.uniform4f(s.color,m[0],m[1],m[2],m[3]);const g=su(l,d.time||0,d.animLayers,d.boneOverrides),y=Math.min(l.bones.length,i);g&&y>0?(t.uniformMatrix4fv(s.skin,!1,g.subarray(0,y*16)),t.uniform1i(s.boneCount,y)):(t.uniformMatrix4fv(s.skin,!1,a),t.uniform1i(s.boneCount,0)),d.blending==="additive"?(t.enable(t.BLEND),t.blendFuncSeparate(t.SRC_ALPHA,t.ONE,t.ONE,t.ONE)):d.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 w=l.indexType==="u32"?t.UNSIGNED_INT:t.UNSIGNED_SHORT;t.drawElements(t.TRIANGLES,l.indexCount,w,0),t.bindVertexArray(null)}}}const Yv=Object.freeze(Object.defineProperty({__proto__:null,applyAttachmentBindOrigins:Wv,attachmentBind:Om,attachmentWorld:Um,bindWorldOf:Lm,computeSkinMatrices:su,createMDLRenderer:Qv,followAttachments:jv,mat4MulOut:Hv,parentMeshToWorldDelta:au,parseMDL:Cv},Symbol.toStringTag,{value:"Module"}));function Kv(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 y=Number(g);return Number.isFinite(y)&&y>0?y:0},u=g=>()=>{try{g()}catch(y){a&&a(y,"timer")}},l=(g,y)=>{const w=()=>{g.fired||(g.fired=!0,o.delete(w),y&&g.handle!=null&&y(g.handle))};return w.handle=null,w.valueOf=()=>typeof g.handle=="number"?g.handle:0,w};function d(g,y){if(typeof g!="function")return l({fired:!0,handle:null},null);const w={fired:!1,handle:null},A=l(w,r);return o.add(A),w.handle=n?n(u(()=>{w.fired=!0,o.delete(A),g()}),c(y)):null,A.handle=w.handle,A}function f(g,y){if(typeof g!="function")return l({fired:!0,handle:null},null);const w={fired:!1,handle:null},A=l(w,s);return o.add(A),w.handle=i?i(u(g),c(y)):null,A.handle=w.handle,A}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:d,setInterval:f,clearTimeout:h,clearInterval:p,dispose:m,pendingCount:()=>o.size}}const Zv=Object.freeze(Object.defineProperty({__proto__:null,createEngineTimers:Kv},Symbol.toStringTag,{value:"Module"})),Co="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=",ei={STOPPED:0,PLAYING:1,PAUSED:2};class St{constructor(e,n,r){this.x=Number(e)||0,this.y=Number(n)||0,this.z=Number(r)||0}add(e){return new St(this.x+e.x,this.y+e.y,this.z+e.z)}subtract(e){return new St(this.x-e.x,this.y-e.y,this.z-e.z)}multiply(e){if(e!==null&&typeof e=="object")return new St(this.x*e.x,this.y*e.y,this.z*e.z);const n=Number(e)||0;return new St(this.x*n,this.y*n,this.z*n)}divide(e){const n=Number(e)||1;return new St(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 St(this.x,this.y,this.z)}toArray(){return[this.x,this.y,this.z]}}function Jv(t,e,n){return new St(t,e,n)}const Io={primary:[.96,.65,.14],secondary:[.08,.11,.18],tertiary:[.66,.74,.88],text:[.96,.97,1]},eA=[{title:"WebWallGL",artist:"oneincase",album:"Scene",albumArtist:"oneincase",duration:212,colors:Io,thumbnail:Co,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:Io,thumbnail:Co,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:Io,thumbnail:Co,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:Io,thumbnail:Co,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"]]}],Ro=3;function zm(t=20260901){const e=eA,n=e.reduce((y,w)=>y+w.duration+Ro,0),r={hasMedia:!1,state:ei.STOPPED,title:"",artist:"",album:"",albumArtist:"",position:0,duration:0,hasThumbnail:!1,thumbnail:"",primaryColor:new St(0,0,0),secondaryColor:new St(0,0,0),tertiaryColor:new St(0,0,0),textColor:new St(1,1,1),highContrastColor:new St(1,1,1),trackIndex:-1,lyrics:[],lyricLine:"",lyricIndex:-1};let i=0,s=!1,a=0,o=0;function c(y){let w=0;const A=(y%e.length+e.length)%e.length;for(let b=0;b<A;b++)w+=e[b].duration+Ro;return w}function u(y){let w=n>0?y%n:0;w<0&&(w+=n);let A=-1,b=0,v=!1;for(let I=0;I<e.length;I++){const B=e[I].duration;if(w<B){A=I,b=w;break}if(w-=B,w<Ro){A=I,b=B,v=!0;break}w-=Ro}A<0&&(A=e.length-1,b=e[A].duration,v=!0);const x=e[A];r.hasMedia=!0,r.trackIndex=A,r.title=x.title,r.artist=x.artist,r.album=x.album,r.albumArtist=x.albumArtist,r.duration=x.duration,r.position=b;const P=x.duration>0?b/x.duration:0;s?r.state=ei.PAUSED:v?r.state=ei.STOPPED:P>.7&&P<.76?r.state=ei.PAUSED:r.state=ei.PLAYING,r.hasThumbnail=!v,r.thumbnail=v?"":x.thumbnail||"";const S=x.colors;r.primaryColor=new St(S.primary[0],S.primary[1],S.primary[2]),r.secondaryColor=new St(S.secondary[0],S.secondary[1],S.secondary[2]),r.tertiaryColor=new St(S.tertiary[0],S.tertiary[1],S.tertiary[2]),r.textColor=new St(S.text[0],S.text[1],S.text[2]);const k=.2126*S.primary[0]+.7152*S.primary[1]+.0722*S.primary[2];r.highContrastColor=k>.5?new St(0,0,0):new St(1,1,1),r.lyrics=x.lyrics;let _=-1;for(let I=0;I<x.lyrics.length;I++)b>=x.lyrics[I][0]&&(_=I);return r.lyricIndex=_,r.lyricLine=_>=0?x.lyrics[_][1]:"",r}function l(y){o=Number(y)||0;const w=s?a:o+i;return u(w)}function d(y){s=!1;const w=c(y);return i=w-o,u(w)}function f(){const y=r.trackIndex<0?0:r.trackIndex+1;return d(y)}function h(){const y=r.trackIndex<0?e.length-1:r.trackIndex-1;return d(y)}function p(){return s||(a=o+i,s=!0,r.state=ei.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:ei,skipNext:f,skipPrevious:h,play:m,pause:p,playPause:g}}function tA(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,[d,f,h]=i.tertiary;for(let p=0;p<n;p++)for(let m=0;m<n;m++){const g=m/(n-1),y=p/(n-1),w=g-.5,A=y-.5,b=Math.sqrt(w*w+A*A)*2,v=.5+.5*Math.sin(b*18-1.2),x=.5+.5*Math.sin((g+y)*6),P=Math.min(1,Math.max(0,b));let S=s*(1-P)+c*P,k=a*(1-P)+u*P,_=o*(1-P)+l*P;S=S*(.72+.28*v)+d*.18*x,k=k*(.72+.28*v)+f*.18*x,_=_*(.72+.28*v)+h*.18*x;const I=1-.35*Math.min(1,b*b),B=(p*n+m)*4;r[B]=Math.max(0,Math.min(255,Math.round(S*I*255))),r[B+1]=Math.max(0,Math.min(255,Math.round(k*I*255))),r[B+2]=Math.max(0,Math.min(255,Math.round(_*I*255))),r[B+3]=255}return{width:n,height:n,rgba:r}}function nA(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 rA(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}function Hm(t){let e=String(t||"");return e=e.replace(/\.(ogg|oga|mp3|wav|flac|m4a)$/i,""),e=e.replace(/^\s*\d{1,3}\s*[.\-_]\s*\d{0,3}\s*[.\-_\)]?\s+/,""),e=e.replace(/^\s*\d{1,3}\s*[.\-_\)]\s+/,""),e.trim()}function iA(t,e){const n=[],r=new Map;let i=null,s=0;const a={primaryColor:new e(.18,.22,.3),secondaryColor:new e(.08,.1,.16),tertiaryColor:new e(.6,.66,.76),textColor:new e(.96,.97,1),highContrastColor:new e(1,1,1)};function o(h,p){if(!h||r.has(h))return;const m=Hm(p),g={au:h,title:m,key:`wa:${n.length}:${m}`};return n.push(g),r.set(h,g),g}function c(h){const p=r.get(h);!p||i===p||(i=p,s++)}function u(h){i&&i.au===h&&(i=null,s++)}function l(){return i?n.indexOf(i):-1}const d={get hasMedia(){return i!=null},get state(){if(!i)return t.STOPPED;const h=i.au;return!h.paused&&!h.ended?t.PLAYING:h.ended?t.STOPPED:t.PAUSED},get title(){return i?i.title:""},get artist(){return""},get album(){return""},get albumArtist(){return""},get position(){return i&&Number(i.au.currentTime)||0},get duration(){const h=i?Number(i.au.duration):0;return Number.isFinite(h)?h:0},get hasThumbnail(){return!1},get thumbnail(){return""},get trackIndex(){return l()},get lyrics(){return[]},get lyricIndex(){return-1},get lyricLine(){return""},primaryColor:a.primaryColor,secondaryColor:a.secondaryColor,tertiaryColor:a.tertiaryColor,textColor:a.textColor,highContrastColor:a.highContrastColor};function f(h){const p=(h%n.length+n.length)%n.length,m=n[p];if(m){for(const{au:g}of n)if(g!==m.au){g.pause();try{g.currentTime=0}catch{}}Promise.resolve(m.au.play()).catch(()=>{}),c(m.au)}}return{snapshot:d,register:o,markPlayed:c,markStopped:u,hasCurrent:()=>i!=null,_changeSeq:()=>s,skipNext(){n.length&&f(l()+1)},skipPrevious(){n.length&&f(l()-1)},play(){i&&Promise.resolve(i.au.play()).catch(()=>{})},pause(){i&&i.au.pause()},playPause(){i&&(i.au.paused?this.play():this.pause())}}}const sA=Object.freeze(Object.defineProperty({__proto__:null,MEDIA_PLAYBACK:ei,cloneMediaSnapshot:rA,createSimulatedMedia:zm,createWallpaperAudioMedia:iA,diffMediaEvents:nA,mediaVec3:Jv,renderThumbnail:tA,songTitleFromLayerName:Hm},Symbol.toStringTag,{value:"Module"})),Vm=14,ca=[{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 Wm(){const t={app:"",title:"",url:"",index:-1};function e(n){const r=Number(n)||0,i=ca.length?Math.floor(r/Vm)%ca.length:0,s=ca[i]||ca[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:ca,hold:Vm}}function jm(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 aA(t){const e=zm(t),n=Wm(),r=jm(null);return{media:e,windowTitle:n,shortcuts:r}}const oA=Object.freeze(Object.defineProperty({__proto__:null,createShortcutHandler:jm,createSimulatedSystem:aA,createSimulatedWindowTitle:Wm},Symbol.toStringTag,{value:"Module"}));function cA(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 f=n();r.screenW=f.w||1,r.screenH=f.h||1}i();function s(f,h){const p=f/r.screenW,m=h/r.screenH;r.has||(r.lastU=p,r.lastV=m,r.lastScreenX=f,r.lastScreenY=h),r.screenX=f,r.screenY=h,r.u=p,r.v=m,r.has=!0,r.moveCount++,r.lastEventTime=Date.now()}function a(f){const h=(f&1)!==0;h!==r.leftDown&&(r.leftDown=h,h?r.downCount++:r.upCount++,r.lastEventTime=Date.now())}function o(f){i();let h=f.clientX,p=f.clientY;if(e&&typeof e.getBoundingClientRect=="function"){const m=e.getBoundingClientRect();h-=m.left,p-=m.top}s(h,p)}function c(f){f.button!==void 0&&f.button!==0||a(1)}function u(f){f.button!==void 0&&f.button!==0||a(0)}function l(){a(0)}let d=!1;return e&&e.addEventListener&&(d=!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(f){if(!f)return;i();const h=Number(f.u),p=Number(f.v);Number.isFinite(h)&&Number.isFinite(p)&&s(h*r.screenW,p*r.screenH),a(Number(f.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(f,h=0,p=0){if(!f)return;r.wx=f.offX+r.u*f.viewW-h,r.wy=f.offY+r.v*f.viewH-p;const m=Number(f.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 f=r.u-r.lastU,h=r.v-r.lastV;return Math.hypot(f,h)},dispose(){!d||!e||!e.removeEventListener||(d=!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 lA=Object.freeze(Object.defineProperty({__proto__:null,createPointerSource:cA},Symbol.toStringTag,{value:"Module"}));function qm(t,e,n,r,i,s,a,o,c){const u=t.size||[0,0],l=t.scale||[1,1,1],d=u[0]*l[0],f=u[1]*l[1];if(!(d>0)||!(f>0))return null;const h=t.origin||[0,0,0];let p=h[0],m=r-h[1];if(t.parallaxDepth&&c){const b=Ko(t,c);p+=b[0],m+=b[1]}else if(t.parallaxDepth&&(i!==0||s!==0)){const b=t.parallaxDepth;p+=b[0]*.5*i,m+=b[1]*.5*s}if(t.perspective&&o)return hA(t,e,n,p,m,d,f,a,o);let g=e-p,y=n-m;const w=t.angles?t.angles[2]:0;if(w){const b=Math.cos(-w),v=Math.sin(-w),x=g*b+y*v,P=-g*v+y*b;g=x,y=P}const A=a&&a[t.alignment]||[.5,.5];return(A[0]!==.5||A[1]!==.5)&&(g-=(.5-A[0])*d,y-=(.5-A[1])*f),{lx:g/d,ly:y/f,w:d,h:f}}function uA(t){const e=Math.cos(t),n=Math.sin(t);return[e,n,0,-n,e,0,0,0,1]}function fA(t){const e=Math.cos(t),n=Math.sin(t);return[e,0,-n,0,1,0,n,0,e]}function dA(t){const e=Math.cos(t),n=Math.sin(t);return[1,0,0,0,e,n,0,-n,e]}function Xm(t,e){const n=new Array(9);for(let r=0;r<3;r++)for(let i=0;i<3;i++)n[r*3+i]=t[i]*e[r*3]+t[3+i]*e[r*3+1]+t[6+i]*e[r*3+2];return n}function hA(t,e,n,r,i,s,a,o,c){const u=(t.origin||[0,0,0])[2]||0,l=t.angles||[0,0,0];let d=uA(-(l[2]||0));d=Xm(d,fA(-(l[1]||0))),d=Xm(d,dA(l[0]||0));const f=d[6],h=d[7],p=d[8],m=e-c[0],g=n-c[1],y=-c[2],w=f*m+h*g+p*y;if(Math.abs(w)<1e-9)return null;const A=r-c[0],b=i-c[1],v=u-c[2],x=(f*A+h*b+p*v)/w,P=c[0]+m*x-r,S=c[1]+g*x-i,k=c[2]+y*x-u;let _=d[0]*P+d[1]*S+d[2]*k,I=d[3]*P+d[4]*S+d[5]*k;const B=o&&o[t.alignment]||[.5,.5];return(B[0]!==.5||B[1]!==.5)&&(_-=(.5-B[0])*s,I-=(.5-B[1])*a),{lx:_/s,ly:I/a,w:s,h:a}}function $m(t,e,n,r,i={}){if(!t||t.length===0)return[];const s=i.parOffX||0,a=i.parOffY||0,o=i.parallaxCtx,c=i.alignTable,u=i.filter,l=[];for(let d=t.length-1;d>=0;d--){const f=t[d];if(!f||!f.visible||f.destroyed||u&&!u(f))continue;const h=qm(f,e,n,r,s,a,c,i.perspEye,o);h&&Math.abs(h.lx)<=.5&&Math.abs(h.ly)<=.5&&l.push(f)}return l}function mA(t,e,n,r,i={}){const s=$m(t,e,n,r,i);return s.length?s[0]:null}const pA=Object.freeze(Object.defineProperty({__proto__:null,hitTestLayers:mA,hitTestLayersAll:$m,worldToLayerLocal:qm},Symbol.toStringTag,{value:"Module"}));function gA(t,e,n){const r=t&&t.hovered||[],i=t&&t.pressed||[],s=!!(t&&t.lastLeftDown),a=Array.isArray(e)?e:[],o=new Set(a),c=[],u=[],l=[],d=[],f=[],h=[];for(const m of r)o.has(m)||c.push(m);for(const m of a)r.includes(m)||u.push(m);for(const m of a)l.push(m);let p=i;if(n&&!s){p=a.slice();for(const m of a)d.push(m)}else if(!n&&s){for(const m of i)f.push(m);for(const m of i)o.has(m)&&h.push(m);p=[]}return{leave:c,enter:u,move:l,down:d,up:f,click:h,next:{hovered:a,pressed:p,lastLeftDown:n}}}const yA=Object.freeze(Object.defineProperty({__proto__:null,planCursorDispatch:gA},Symbol.toStringTag,{value:"Module"})),Et=t=>t,at=Et(oy),er=Et(_y),zt=Et(ub),An=Et(pb),pt=Et(nw),Ti=Et(kw),en=Et(ov),Bo=Et(wv),ou=Et(Mv),la=Et(Yv),ot=Et(Zy),bA=Et(Zv),We=Et(sA),Gm=Et(oA),ua=Et(qb),wA=Et(lA),vA=Et(pA),AA=Et(yA);function xA(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 kA(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 TA(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){be(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 d=0;d<l;d++){const f=a[d]/255;o[d]=f,c[d]=f}for(let d=l;d<64;d++)o[d]=0,c[d]=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 SA(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 f of[n,r]){const h=s.createMediaElementSource(f),p=s.createAnalyser();p.fftSize=256,p.smoothingTimeConstant=.75,h.connect(p),p.connect(s.destination),a.set(f,p)}}catch(f){be(t,e,`media \u9891\u8C31\u63A5\u7BA1\u8DF3\u8FC7: ${f?.message??f}`);return}let o=a.get(n);const c=new Uint8Array(o.frequencyBinCount),u=new Float32Array(64),l=new Float32Array(64),d=()=>{if(s.state!=="running")return null;o.getByteFrequencyData(c);const f=Math.min(64,c.length);for(let h=0;h<f;h++){const p=c[h]/255;u[h]=p,l[h]=p}for(let h=f;h<64;h++)u[h]=0,l[h]=0;return{left:u,right:l}};if(t.audioBridge=d,s.state==="suspended"){const f=()=>{s.resume().catch(()=>{}),window.removeEventListener("pointerdown",f),window.removeEventListener("keydown",f)};window.addEventListener("pointerdown",f,{once:!0}),window.addEventListener("keydown",f,{once:!0}),(t.wallpaperDisposers??=[]).push(()=>{window.removeEventListener("pointerdown",f),window.removeEventListener("keydown",f)})}return(t.wallpaperDisposers??=[]).push(()=>{t.audioBridge===d&&(t.audioBridge=null),s.close().catch(()=>{})}),f=>{const h=a.get(f);h&&(o=h)}}function PA(t,e){Or(t);const n=g=>{be(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){EA(t,e),Ru(t);return}const s=e.canvas instanceof HTMLCanvasElement,a=s?e.canvas:document.createElement("canvas"),o=Vi(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(be(t,e,`media ${e.type}: WEBGL2_UNAVAILABLE`),s){t.onError?.(new Error("WEBGL2_UNAVAILABLE"));return}CA(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 d=!1;t.sceneCleanup=()=>{d=!0,t.renderer&&(t.renderer.dispose?.(),t.renderer=void 0)};let f,h,p=!1;t.sceneAudio={setVolume(g){const y=t.video;if(!y)return;const w=Math.max(0,Math.min(1,Number(g)||0));y.volume=w,y.muted=w<=0,w>0&&y.paused&&!t.paused&&y.play().catch(A=>{be(t,e,`media \u53D6\u6D88\u9759\u97F3\u540E\u81EA\u52A8\u64AD\u653E\u88AB\u62D2\u7EDD: ${A?.message??A}`)})},audios:[]},t.sceneCtl={pause(){f?.()},resume(){h?.()},applyUserProperties(){}};const m=g=>{d||(d=!0,n(g))};(async()=>{try{const g=pt.createRenderer(a,{diag:O=>be(t,e,`renderer: ${O}`),fboCapFactor:0});if(t.renderer=g,d)return;const y="__media",w=new Map;let A,b=0,v=0;{let O=!1;if(i&&typeof window.ImageDecoder=="function")try{const U=await kA(e.src);if(U&&U.frames.length>1){b=U.width,v=U.height;const W=g.gl,ie={glTex:pt.makeTexture(W,null,0,0,U.frames[0].bitmap),width:b,height:v,rg88:!1};w.set(y,ie);let we=0,Y=performance.now()+U.frames[0].durationMs;A=()=>{const he=performance.now();if(!(he<Y)){we=(we+1)%U.frames.length,Y=he+U.frames[we].durationMs,W.bindTexture(W.TEXTURE_2D,ie.glTex);try{W.texImage2D(W.TEXTURE_2D,0,W.RGBA,W.RGBA,W.UNSIGNED_BYTE,U.frames[we].bitmap)}catch{}}};const oe=t.sceneCleanup;t.sceneCleanup=()=>{oe?.();for(const he of U.frames)he.bitmap.close()},O=!0,be(t,e,`media gif ${b}x${v} ${U.frames.length} \u5E27 \u2192 scene \u6E32\u67D3`)}}catch(U){be(t,e,`gif \u89E3\u7801\u5931\u8D25\uFF0C\u56DE\u9000\u9759\u6001\u9996\u5E27: ${String(U.message).slice(0,80)}`)}if(!O){const U=new Image;if(U.crossOrigin="anonymous",U.src=e.src,await new Promise((W,ie)=>{U.addEventListener("load",()=>W(),{once:!0}),U.addEventListener("error",()=>ie(new Error("image load error")),{once:!0})}),d)return;b=U.naturalWidth||1,v=U.naturalHeight||1,t.img=U,w.set(y,{glTex:pt.makeTexture(g.gl,null,0,0,U),width:b,height:v,rg88:!1}),be(t,e,`media ${e.type} ${b}x${v} \u2192 scene \u6E32\u67D3`)}}if(d)return;const x=xA(b,v,y),P=performance.now();let S=0,k=0;const _=new ys(t.cfg.sceneFps||60);let I=t.cfg.sceneFps||60;const B=O=>{if(d||t.paused)return;const U=t.cfg.sceneFps||60;if(U!==I&&(I=U,_.setFps(U)),_.shouldRender(O)){zr(t,O),Du(t,a,t.cfg),A?.();const W=t.coverAlign;g.render(x,w,a.width,a.height,(O-P-S)/1e3,Ur(t.cfg.fit),W.x,W.y).then(()=>{if(t.onFirstFrame){const ie=t.onFirstFrame;t.onFirstFrame=void 0;try{ie()}catch{}}d||t.paused||(t.raf=requestAnimationFrame(B))}).catch(ie=>m(String(ie.message||ie).slice(0,200)))}else t.paused||(t.raf=requestAnimationFrame(B))},V=()=>{d||t.paused||t.raf===void 0&&(t.raf=requestAnimationFrame(B))};f=()=>{t.raf!==void 0&&(cancelAnimationFrame(t.raf),t.raf=void 0),k||(k=performance.now());const O=t.video;p=!!(O&&!O.paused&&!O.ended),O?.pause()},h=()=>{k&&(S+=performance.now()-k,k=0),p&&t.video?.play().catch(()=>{}),p=!1,_.reset(),V()},V()}catch(g){m(String(g.message||g).slice(0,200))}})()}function _A(t,e){if(t.wrap)return t.wrap;const n=e.canvas;return n?n instanceof HTMLCanvasElement?n.parentElement:n:null}function EA(t,e){if(Or(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=_A(t,e);if(!n){const f="\u89C6\u9891\u58C1\u7EB8\u9700\u8981\u4E00\u4E2A\u5BB9\u5668\u5143\u7D20\uFF08\u4F20\u5165\u7684 canvas \u6CA1\u6709\u7236\u8282\u70B9\uFF09";be(t,e,`media video \u5931\u8D25: ${f}`),t.onError?.(new Error(`\u5A92\u4F53\u58C1\u7EB8\uFF08video\uFF09${f}`));return}const r=Zo(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=f=>{if(s)return;s=!0;const h=`\u89E3\u7801/\u52A0\u8F7D\u5931\u8D25\uFF08code ${f??"?"}\uFF09`;be(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=()=>{zr(t,performance.now());const f=t.onFirstFrame;if(f){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{f()}catch{}}},l=f=>{let h=!1,p=0,m=-1;const g=b=>{if(t.paused||b.paused||b.readyState<2)return;const v=b.currentTime;m>=0&&v===m||(m=v,zr(t,performance.now()))};let y;const w=()=>{h||!y||(g(y),y.requestVideoFrameCallback(w))},A=()=>{if(h)return;p=requestAnimationFrame(A);const b=f();b&&(b!==y&&typeof b.requestVideoFrameCallback=="function"&&(y=b,b.requestVideoFrameCallback(w)),g(b))};p=requestAnimationFrame(A),(t.wallpaperDisposers??=[]).push(()=>{h=!0,y=void 0,p&&cancelAnimationFrame(p)})};if(!o){const f=document.createElement("video");f.autoplay=!0,f.loop=!1,f.muted=c,f.playsInline=!0,f.preload="metadata",MA(f,t,e),f.style.cssText=i,f.src=e.src,f.addEventListener("error",()=>a(f.error?.code)),n.appendChild(f),t.video=f,(t.videoTextures??=[]).push(f),f.addEventListener("canplay",()=>{f.play().catch(()=>{})},{once:!0}),f.addEventListener("loadeddata",u,{once:!0}),f.readyState>=2&&u(),TA(t,e,f),l(()=>f),be(t,e,"media video \u2192 DOM \u76F4\u663E\uFF08\u5355\u5143\u7D20\uFF0C\u4E0D\u5FAA\u73AF\uFF09");return}const d=()=>{const f=Uu(e.src,{muted:c,renderDpr:e.renderDpr,maxW:n.clientWidth||window.innerWidth,maxH:n.clientHeight||window.innerHeight,onRecover:m=>be(t,e,`media video \u81EA\u6108: ${m}`)});for(const m of[f.active,f.standby])m.style.cssText=i,n.appendChild(m),(t.videoTextures??=[]).push(m),m.addEventListener("error",()=>a(m.error?.code));const h=()=>{f.active.style.zIndex="1",f.standby.style.zIndex="0",t.video=f.active};h(),f.onSwap=()=>{h(),p?.(f.active)},f.onFallback=()=>be(t,e,"media video: \u65E0\u7F1D\u5FAA\u73AF\u515C\u5E95\uFF08\u9000\u56DE\u539F\u751F loop\uFF09"),(t.videoPairs??=[]).push(f),t.webcodecsPreferred=Gd();const p=SA(t,e,f.active,f.standby);f.active.addEventListener("loadeddata",u,{once:!0}),f.active.readyState>=2&&u(),l(()=>f.active),t.paused||f.resume(),be(t,e,"media video \u2192 DOM \u76F4\u663E\uFF08A/B \u65E0\u7F1D\u5FAA\u73AF\uFF09")};if(o&&c&&Gd()){let f=!0,h=null;const p=(m,g=!0)=>{f&&(f=!1,h?.destroy(),h=null,be(t,e,`media video: ${m}\uFF0C\u56DE\u9000 A/B <video>`),d(),g||(t.webcodecsPreferred=!1))};h=ry({src:e.src,container:n,cssText:i,fit:()=>Ur(t.cfg.fit),fps:()=>t.cfg.sceneFps||60,paused:()=>!!t.paused,renderDpr:e.renderDpr,onFirstFrame:u,onFrame:()=>zr(t,performance.now()),onDiag:m=>be(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(()=>{f=!1,h?.destroy(),h=null}),t.canvas=h.canvas,be(t,e,"media video \u2192 WebCodecs \u9010\u5E27\u8C03\u5EA6\uFF08\u9759\u97F3\u5FAA\u73AF\uFF09");return}d()}function MA(t,e,n){const r=n.renderDpr??e.cfg?.renderDpr??0,i=Math.min(window.devicePixelRatio||1,!r||r<=0?window.devicePixelRatio||1:r),s=n.canvas?.clientWidth||window.innerWidth,a=n.canvas?.clientHeight||window.innerHeight;t.width=Math.max(1,Math.round(s*i)),t.height=Math.max(1,Math.round(a*i))}function CA(t,e){Or(t);const n=document.createElement("img"),r=Zo(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 IA=["scene.pkg","scenes/scene.pkg","gifscene.pkg"],RA={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 Qm(t){const e=t.toLowerCase().split(";")[0].trim();return e==="image/gif"?"gif":e.startsWith("video/")?"video":e.startsWith("image/")?"image":null}function cu(t){if(typeof t!="string"||!t)return;const e=t.replace(/[?#].*$/,"").replace(/\/+$/,"").split(/[/\\]/).pop()??"";return/^\d+$/.test(e)?e:void 0}function lu(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:RA[i.slice(s+1).toLowerCase()]??null}async function BA(t,e,n){try{const r=await fetch(t,{...e,method:"HEAD",signal:n});return r.ok?Qm(r.headers.get("content-type")||""):null}catch{return null}}function Ym(t,e){const n=t.replace(/\/+$/,"");return{key:n,async scenePkg(r){let i=null,s=null;for(const o of IA){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 FA(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 DA(t,e,n){return{key:n,scenePkg:async()=>t,project:async()=>e??null}}function NA(t,e){const n=typeof t!="string",r=t;let i=e?.type??(n?Qm(t.type||""):null)??lu(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 BA(t,void 0,u)),{url:o(),type:i??void 0}},dispose(){a&&(URL.revokeObjectURL(a),a=null)}}}const Km=!1,Zm=!0,Jm=!1,LA=!1,UA=!1,ep=4,uu={antiAliasing:"off",particles:"high",postProcessing:"high"},OA={low:.4,medium:.7,high:1},zA={low:.5,medium:1,high:0},HA=["off","fxaa","msaa2","msaa4"],VA=["off","low","medium","high"],WA=["off","low","medium","high"];function fu(t,e,n){return typeof t=="string"&&e.includes(t)?t:n}function fa(t){const e=t??{};return{antiAliasing:fu(e.antiAliasing,HA,uu.antiAliasing),particles:fu(e.particles,VA,uu.particles),postProcessing:fu(e.postProcessing,WA,uu.postProcessing)}}function jA(t){return t==="off"?0:OA[t]}function qA(t){return t==="off"?0:zA[t]}const da=64,tp={STOPPED:0};function XA(){return{left64:new Float32Array(da),right64:new Float32Array(da),left32:new Float32Array(32),right32:new Float32Array(32),left16:new Float32Array(16),right16:new Float32Array(16),level:0,silent:!0}}function Fo(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 $A(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<da;c++){const u=c/da,l=(c+1)/da,d=s*Math.pow(a/s,u),f=s*Math.pow(a/s,l),h=Math.max(0,Math.floor(d/i*r)),p=Math.min(r,Math.max(h+1,Math.ceil(f/i*r)));let m=0;for(let y=h;y<p;y++)m+=e[y]/255;const g=Math.min(1,m/(p-h)*1.35);t.left64[c]=g,t.right64[c]=g,c<48&&(o+=g)}Fo(t.left32,t.left64),Fo(t.right32,t.right64),Fo(t.left16,t.left64),Fo(t.right16,t.right64),t.level=Math.min(1,o/(48*1.2)),t.silent=t.level<.02}function GA(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 du(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 d=i-s/2;return[c+d,u+d,l+d]}function QA(t,e){const n=GA(e||"empty"),[r,i,s]=du(n,72,48),[a,o,c]=du((n+40)%360,55,28),[u,l,d]=du((n+20)%360,70,72);t.primaryColor=We.mediaVec3(r,i,s),t.secondaryColor=We.mediaVec3(a,o,c),t.tertiaryColor=We.mediaVec3(u,l,d),t.textColor=We.mediaVec3(.98,.98,1),t.highContrastColor=We.mediaVec3(1,1,1),t.hasThumbnail=!!e}function YA(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,d=0,f=0,h=-1;for(let y=0;y<s.length;y+=4){const w=s[y]/255,A=s[y+1]/255,b=s[y+2]/255;a+=w,o+=A,c+=b,u++;const v=Math.max(w,A,b),x=Math.min(w,A,b),P=v-x,S=.2126*w+.7152*A+.0722*b,k=P*1.4+(S>.15&&S<.85?.3:0);k>h&&(h=k,l=w,d=A,f=b)}if(!u)return null;const p=[l,d,f],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 KA(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 ZA(){return{hasMedia:!1,state:tp.STOPPED,title:"",artist:"",album:"",albumArtist:"",position:0,duration:0,hasThumbnail:!1,primaryColor:We.mediaVec3(0,0,0),secondaryColor:We.mediaVec3(0,0,0),tertiaryColor:We.mediaVec3(0,0,0),textColor:We.mediaVec3(1,1,1),highContrastColor:We.mediaVec3(1,1,1),trackIndex:-1,lyrics:[],lyricLine:"",lyricIndex:-1}}async function JA(){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 np(t){const e=t?.origin??(typeof location<"u"?location.origin:""),n=t?.onArtwork,r=XA(),i=ZA(),s={app:"",title:"",url:"",index:0};let a="off",o="offline",c="offline",u="",l=!1,d="";const f=await JA();f?a="mic":navigator.mediaDevices?.getUserMedia?a="denied":a="unavailable";let h=null,p=null,m=!1;const g=(v,x,P)=>{!e||!n||!l||d!==v&&(d=v,n({url:`${e}/api/system/artwork?k=${encodeURIComponent(v)}&_=${Date.now()}`,trackKey:v,title:x,artist:P}))},y=v=>{if(!v||!v.hasMedia){i.hasMedia=!1,i.state=tp.STOPPED,i.title="",i.artist="",i.album="",i.albumArtist="",i.position=0,i.duration=0,i.hasThumbnail=!1,i.trackIndex=-1,o=v?"empty":"offline",u="",l=!1,d="";return}o="live",i.hasMedia=!0,i.state=Number(v.state)===2?2:Number(v.state)===1?1:0,i.title=String(v.title??""),i.artist=String(v.artist??""),i.album=String(v.album??""),i.albumArtist=String(v.albumArtist??v.artist??""),i.position=Number(v.position)||0,i.duration=Number(v.duration)||0,l=v.hasArtwork===!0;const x=`${i.title}|${i.artist}|${i.album}`;x!==u&&(u=x,d="",i.trackIndex=i.trackIndex+1|0,QA(i,x)),g(x,i.title,i.artist)},w=v=>{if(!v){c="offline";return}s.app=String(v.app??""),s.title=String(v.title??""),s.url=String(v.url??""),c=s.app||s.title?"live":"empty"},A=async()=>{if(!(!e||m))try{const[v,x]=await Promise.all([fetch(`${e}/api/system/media`,{cache:"no-store"}),fetch(`${e}/api/system/window`,{cache:"no-store"})]);if(v.ok){const P=await v.json();y(P)}else o="offline";x.ok&&w(await x.json())}catch{o=o==="live"?"live":"offline",c=c==="live"?"live":"offline"}};if(e){await A(),p=setInterval(()=>{A()},1e3);try{h=new EventSource(`${e}/api/system/stream`),h.onmessage=v=>{if(!m)try{const x=JSON.parse(v.data);y(x.media),w(x.window)}catch{}}}catch{}}const b=v=>{!e||m||fetch(`${e}/api/system/media-control`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:v})}).then(async x=>x.ok?x.json():null).then(x=>{x&&typeof x=="object"&&y(x),A()}).catch(()=>{A()})};return{audio:{snapshot:r,pump:()=>{if(!f||m){r.level=0,r.silent=!0;return}f.analyser.getByteFrequencyData(f.buf),$A(r,f.buf,f.ctx.sampleRate||48e3)}},media:{snapshot:i,pump:()=>{},skipNext:()=>b("skipNext"),skipPrevious:()=>b("skipPrevious"),play:()=>b("play"),pause:()=>b("pause"),playPause:()=>b("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,f)try{f.stream.getTracks().forEach(v=>v.stop()),f.ctx.close()}catch{}}}}const e2=2048,Do=64;function t2(){let t=null,e=null,n=null,r=1,i=null;const s=new WeakSet,a=new WeakSet,o=[],c=()=>{if(t)return!0;try{const m=globalThis.AudioContext??globalThis.webkitAudioContext;return m?(t=new m,e=t.createAnalyser(),e.fftSize=e2,e.smoothingTimeConstant=.8,e.maxDecibels=-25,n=t.createGain(),n.gain.value=r,n.connect(t.destination),i=new Uint8Array(e.frequencyBinCount),!0):!1}catch{return t=null,e=null,n=null,!1}};return{attach:m=>{if(!(!m||s.has(m))&&!(!c()||!t||!e))try{const g=t.createMediaElementSource(m);g.connect(e),n&&g.connect(n),s.add(m),a.add(m),o.push(m)}catch{s.add(m)}},routes:m=>a.has(m),readBands:()=>{if(!e||!i||!t||!o.some(A=>!A.paused&&!A.ended&&!A.muted&&A.volume>0))return null;e.getByteFrequencyData(i);const g=new Float32Array(Do),y=i.length*.72,w=2;for(let A=0;A<Do;A++){const b=w+Math.floor(y*(A/Do)**2),v=Math.max(b+1,w+Math.floor(y*((A+1)/Do)**2));let x=0;for(let P=b;P<v&&P<i.length;P++){const S=i[P];S>x&&(x=S)}g[A]=x/255}return g},resume:()=>{t&&t.state==="suspended"&&t.resume().catch(()=>{})},setVolume:m=>{r=Math.max(0,Math.min(1,Number(m)||0)),n&&(n.gain.value=r)},dispose:()=>{try{t?.close()}catch{}t=null,e=null,n=null,i=null,o.length=0}}}function n2(t,e,n){for(let r=0;r<64;r++){const i=Math.min(1,e[r]*n);i>t.left64[r]&&(t.left64[r]=i),i>t.right64[r]&&(t.right64[r]=i)}No(t.left64,t.left32),No(t.right64,t.right32),No(t.left64,t.left16),No(t.right64,t.right16)}function No(t,e){if(!e)return;const n=t.length/e.length;for(let r=0;r<e.length;r++){const i=Math.floor(r*n),s=Math.max(i+1,Math.floor((r+1)*n));let a=0;for(let o=i;o<s;o++)t[o]>a&&(a=t[o]);e[r]=a}}const _r=new Map;let Fn=null,rp=!1,ha=null,hu=null;const mu=new Map,Lo="/api/local-assets";function r2(){if(typeof location>"u")return"off";const t=new URLSearchParams(location.search).get("localAssets");return t==="0"||t==="off"||t==="false"?"off":t==="all"?"all":t==="1"||t==="on"||t==="true"||typeof import.meta<"u"&&!1?"lazy":"off"}async function i2(t){if(t&&t.rgba)return{width:t.width,height:t.height,rgba:t.rgba};const e=t&&(t.png||t.image);if(!e)return null;const n=!!t.png;if(!n&&t.fif!==er.FIF?.JPEG&&t.fif!==er.FIF?.PNG)return null;const r=new Blob([e],{type:n?"image/png":"image/jpeg"}),i=await createImageBitmap(r,{premultiplyAlpha:"none"}),s=i.width,a=i.height,o=document.createElement("canvas");o.width=s,o.height=a;const c=o.getContext("2d",{willReadFrequently:!0});if(!c)return null;c.drawImage(i,0,0),typeof i.close=="function"&&i.close();const u=c.getImageData(0,0,s,a),l=new Uint8Array(s*a*4);return l.set(u.data),{width:s,height:a,rgba:l}}async function s2(t){const e=await fetch(t,{cache:"force-cache"});if(!e.ok)return null;const n=new Uint8Array(await e.arrayBuffer()),r=er.parseTex(n),i=er.decodeMips(r);if(!i.length)return null;const s=await i2(i[0]);if(!s)return null;s.format=r.format;const a=r.frames?.list;return a&&a.length&&(a.atlasWidth=s.width,a.atlasHeight=s.height,s.frames=a),s}async function a2(t,e,n){const r=new Array(t.length);let i=0;const s=new Array(Math.min(e,Math.max(1,t.length))).fill(0).map(async()=>{for(;;){const a=i++;if(a>=t.length)return;r[a]=await n(t[a])}});return await Promise.all(s),r}async function ip(t){const e=_r.get(t);if(e)return e;if(!Fn||!Fn.names.has(t))return null;const n=mu.get(t);if(n)return n;const r=`${Lo}/${encodeURIComponent(Fn.id)}/materials/${t.split("/").map(encodeURIComponent).join("/")}.tex`,i=(async()=>{try{const s=await s2(r);return s&&_r.set(t,s),s}catch{return null}finally{mu.delete(t)}})();return mu.set(t,i),i}async function o2(){const t=r2();if(t==="off")return null;if(rp)return hu;if(ha)return ha;ha=(async()=>{const e=typeof performance<"u"?performance.now():Date.now();try{const u=await fetch(Lo,{cache:"no-store"});if(!u.ok)return null;const l=await u.json();if(!l?.ok||!l.roots?.length)return null;const d=l.roots[0],f=await fetch(`${Lo}/${encodeURIComponent(d.id)}/materials/index.json`,{cache:"force-cache"});if(!f.ok)return null;const h=await f.json();if(!Array.isArray(h.names)||!h.names.length)return null;Fn={id:d.id,names:new Set(h.names)}}catch{return null}Bo.setSystemTextureProvider(u=>_r.get(u)??null),en.setParticleTextureProvider(u=>_r.get(u)??null),ou.setGradientTextureProvider(u=>_r.get(u)??null);const n=[...Fn.names].filter(u=>u.startsWith("util/")),r=t==="all"?[...Fn.names]:n;let i=0;await a2(r,8,async u=>{await ip(u)||i++}),rp=!0;let s=0,a=0,o=0;for(const[u,l]of _r)o+=l.rgba.byteLength,u.startsWith("util/")?s++:u.startsWith("particle/")&&a++;const c={source:Fn.id,available:Fn.names.size,requested:r.length,loaded:_r.size,failed:i,bytes:o,ms:Math.round((typeof performance<"u"?performance.now():Date.now())-e),mode:t==="all"?"all":"lazy",util:s,particle:a};return hu=c,globalThis.__localAssets=c,c})();try{return await ha}finally{ha=null}}async function sp(t){if(typeof t!="string"||!t)return!1;if(_r.has(t))return!0;if(!Fn)return!1;const e=await ip(t);if(!e)return!1;const n=hu;return n&&(n.loaded=_r.size,n.bytes+=e.rgba.byteLength,t.startsWith("util/")?n.util++:t.startsWith("particle/")&&n.particle++,globalThis.__localAssets=n),!0}const ap=new Map;async function c2(t){if(!Fn||!t||t.includes(".."))return null;const e=ap.get(t);if(e)return e;try{const n=`${Lo}/${encodeURIComponent(Fn.id)}/${t.split("/").map(encodeURIComponent).join("/")}`,r=await fetch(n,{cache:"force-cache"});if(!r.ok)return null;const i=new Uint8Array(await r.arrayBuffer());return ap.set(t,i),i}catch{return null}}const l2={"common.h":`// WE common.h\uFF08\u91CD\u5EFA\u5B50\u96C6\uFF0C\u4F9B we-scene \u6D4F\u89C8\u5668\u6E32\u67D3\uFF09
|
|
182
568
|
#define M_PI 3.14159265359
|
|
183
569
|
// 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
570
|
// \u5F71\u54CD\u5168\u5E93 142 \u4E2A\u6587\u4EF6\uFF0864 \u4E2A\u58C1\u7EB8\uFF09\u3002\u4E09\u6761\u72EC\u7ACB\u8BC1\u636E\uFF1A
|
|
@@ -202,6 +588,14 @@ vec2 rotateVec2(vec2 v, float a) {
|
|
|
202
588
|
float s = sin(a);
|
|
203
589
|
return vec2(v.x * c - v.y * s, v.x * s + v.y * c);
|
|
204
590
|
}
|
|
591
|
+
// [we-scene patch 3351179520] HLSL \u5141\u8BB8\u628A vec4 \u9690\u5F0F\u622A\u65AD\u6210 float2 \u4F20\u53C2\uFF0CGLSL \u4E0D\u5141\u8BB8 \u2014\u2014
|
|
592
|
+
// multistage_wave.vert\uFF08GLOBAL_ROTATION=1 \u65F6 v_DirectionN \u662F vec4\uFF09\u5199
|
|
593
|
+
// \`v_DirectionN.zw = rotateVec2(v_DirectionN, g_DirectionOffset)\`\uFF0C\u6CA1\u6709\u8FD9\u4E2A\u91CD\u8F7D
|
|
594
|
+
// \u6574\u6761 pass \u7F16\u8BD1\u5931\u8D25\u3001\u6548\u679C\u88AB\u9759\u9ED8\u8DF3\u8FC7\uFF08\u98D8\u5E26/\u5934\u53D1\u7684\u591A\u5C42\u6CE2\u52A8\u5168\u6D88\u5931\uFF09\u3002
|
|
595
|
+
// \u8BED\u4E49 = \u53D6 xy \u5206\u91CF\u65CB\u8F6C\uFF0C\u4E0E WE \u539F\u751F\u622A\u65AD\u4E00\u81F4\u3002
|
|
596
|
+
vec2 rotateVec2(vec4 v, float a) {
|
|
597
|
+
return rotateVec2(v.xy, a);
|
|
598
|
+
}
|
|
205
599
|
float rand(vec2 n) { return fract(sin(dot(n, vec2(12.9898, 78.233))) * 43758.5453); }
|
|
206
600
|
float rand(vec2 n, float m) { return 0.5 + 0.5 * rand(n * m); }
|
|
207
601
|
float smoothstep01(float x) { return smoothstep(0.0, 1.0, x); }
|
|
@@ -226,157 +620,12 @@ vec3 hsv2rgb(vec3 c) {
|
|
|
226
620
|
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
|
|
227
621
|
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
|
|
228
622
|
}
|
|
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
|
-
}
|
|
623
|
+
`,"common_blending.h":`${Fh}
|
|
374
624
|
// greyscale \u5FC5\u987B\u8FD4\u56DE **float** \u800C\u4E0D\u662F vec3 \u2014\u2014 \u8C03\u7528\u70B9\u51E0\u4E4E\u5168\u662F
|
|
375
625
|
// \`noise = CAST3(greyscale(noise))\`\uFF08filmgrain/vhs\uFF09\uFF0CCAST3 \u53EA\u80FD\u4F5C\u7528\u4E8E\u6807\u91CF\uFF1B
|
|
376
626
|
// \u82E5\u58F0\u660E\u6210 vec3 \u7248\u672C\uFF0C\u8FD9\u4E9B\u70B9\u4F1A\u53D8\u6210\u975E\u6CD5\u7684 vec3(vec3)\u3002
|
|
377
627
|
// \u552F\u4E00\u7684 \`albedo.rgb = greyscale(albedo.rgb)\`\uFF08color_grading\uFF09\u5728 HLSL \u91CC\u9760\u6807\u91CF
|
|
378
628
|
// \u81EA\u52A8\u5E7F\u64AD\u6210\u7ACB\uFF0C\u8F6C\u8BD1\u5230 GLSL \u540E\u7531\u8D4B\u503C\u7AEF\u7684 vec3 = float \u5E7F\u64AD\u627F\u63A5\u3002
|
|
379
|
-
//
|
|
380
629
|
// \u6743\u91CD\u662F **vec3(0.11, 0.59, 0.3)**\uFF0C\u5373 Rec.601 (0.30,0.59,0.11) \u7684**\u9006\u5E8F**\u2014\u2014
|
|
381
630
|
// WE \u7B2C\u4E00\u65B9 shader \u91CC\u7684\u5386\u53F2\u9057\u7559\uFF08BGR \u65F6\u4EE3\uFF09\u3002\u4F9D\u636E\u662F 4 \u4E2A\u7B2C\u4E00\u65B9\u6587\u4EF6\u628A\u5B83\u5185\u8054\u5199\u6B7B\uFF1A
|
|
382
631
|
// localcontrast_combine.frag\uFF08\u6B63\u662F blur_combine \u7684\u514D\u5934\u6587\u4EF6\u7248\uFF0C#if GREYSCALE \u4E0B
|
|
@@ -509,11 +758,11 @@ vec3 DecompressNormal(vec4 tex) {
|
|
|
509
758
|
return vec3(xy, sqrt(clamp(1.0 - dot(xy, xy), 0.0, 1.0)));
|
|
510
759
|
}
|
|
511
760
|
`,"common_vertex.h":`// WE common_vertex.h\uFF08\u91CD\u5EFA\uFF1A\u7A7A\u5360\u4F4D\uFF0C\u89C1 headers.ts \u6CE8\u91CA\uFF09
|
|
512
|
-
`};function eu(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 tu={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"},Tr=new Map;function nu(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 ru(e){for(const n of e){const t=Tr.get(n);if(t&&(t.refs--,!(t.refs>0))){Tr.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 cn=new Map,ou=512*1024*1024;let bo=0;function iu(e){for(;cn.size>0&&(cn.size>2||bo>ou);){let n=null,t=1/0;for(const[o,i]of cn)o!==e&&i.at<t&&(t=i.at,n=o);if(!n)break;const r=cn.get(n);bo-=r.parsed.fileSize||0,cn.delete(n)}}async function su(e,n,t,r){const o=t.key;if(o){const c=cn.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=Ge.parsePkg(s);return o&&(cn.set(o,{parsed:a,at:Date.now()}),bo+=a.fileSize||0,iu(o)),a}function au(e,n){on(e);const t=(n.canvas instanceof HTMLCanvasElement?n.canvas:null)??document.createElement("canvas"),r=rr(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??ss(`${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 su(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=Ge.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=Ke.parseScene(JSON.parse(xt(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=ra(g.properties||{});e.liveUserProps=v;const A=()=>Ke.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 _=[];us&&(g.layers=g.layers.filter(b=>!(us&&b.isComponent)));const R=b=>{const T=b.startsWith("shaders/")?b:"shaders/"+b,P=b.startsWith("shaders/")?b.slice(8):b,C=Ge.getEntry(x,T);let I=C?xt(C):Jl[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=$e.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=Zi(),H=we.createSimulatedMedia(),K=rs.createSimulatedWindowTitle();let O=null;const W={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),Fe={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}}})(),Ye=()=>_e.active?_e.snapshot:X.current?X.current.snapshot:j.snapshot;L.setAudioProvider(()=>te.enabled?Ye():Fe);const Ve=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 Ne=rs.createShortcutHandler(b=>{se(e,n,`openUserShortcut: ${b}`)}),qe={enabled:!e.mediaDisabled,override:null},Ue=[];let ye=null;W.lastSnap={get:()=>ye,setHasThumbnail:b=>{ye&&(ye.hasThumbnail=b)}};const he=()=>J().snapshot,De=b=>{if(!(!b||!b.hasMediaHook||Ue.includes(b))&&(Ue.push(b),!!he().hasMedia))for(const{name:T,event:P}of we.diffMediaEvents(null,he()))try{b.callMedia(T,P)}catch{}};window.__mediaStats=()=>({enabled:qe.enabled,live:!!O,hooks:Ue.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=we.diffMediaEvents(ye,he());for(const{name:P,event:C}of T)for(const I of Ue)I.callMedia(P,C);return ye=we.cloneMediaSnapshot(he()),window.__mediaStats()};const Pe=()=>{const b=we.diffMediaEvents(ye,he());for(const{name:T,event:P}of b)for(const C of Ue)try{C.callMedia(T,P)}catch{}ye=we.cloneMediaSnapshot(he())},Ze=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()},Be={get snapshot(){return he()},skipNext:()=>Ze("skipNext"),skipPrevious:()=>Ze("skipPrevious"),play:()=>Ze("play"),pause:()=>Ze("pause"),playPause:()=>Ze("playPause")};e.mediaCtl=Be,window.__mediaControl=Be,window.__system={media:Be,windowTitle:Z.snapshot,shortcuts:Ne.last,live:null},window.__liveSystem=()=>({audio:"off",media:"offline",window:"offline"});const Ae=El.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 nt=tt.createInputView(),rt=Sl.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)}`))}})()}),Ft={setTimeout:rt.setTimeout,clearTimeout:rt.clearTimeout,setInterval:rt.setInterval,clearInterval:rt.clearInterval};{const b=u;u=()=>{b?.(),rt.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 xe=new Map;xe.set("util/white",{glTex:$e.makeTexture(L.gl,new Uint8Array([255,255,255,255]),1,1),width:1,height:1,rg88:!1}),xe.set("util/noflow",{glTex:$e.makeTexture(L.gl,new Uint8Array([127,127,127,255]),1,1),width:1,height:1,rg88:!1}),xe.set("util/noise",{glTex:$e.makeTexture(L.gl,Al.generateNoiseTexture(),256,256),width:256,height:256,rg88:!1,mips:null});{const b=P=>{const C=we.renderThumbnail(P,512);return{glTex:$e.makeTextureMip(L.gl,[C],!1),width:C.width,height:C.height,rg88:!1,mips:[C],generated:!0}},T=H.tracks||[];T.length&&(xe.set("$mediaThumbnail",b(T[0])),xe.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),$=Zl(D,D.width,D.height,512),z=ql(D,D.width,D.height);D.close?.();const B=xe.get("$mediaThumbnail");B&&xe.set("$mediaPreviousThumbnail",B);const q=L.gl,S=xe.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=[$]):xe.set("$mediaThumbnail",{glTex:$e.makeTextureMip(q,[$],!1),width:$.width,height:$.height,rg88:!1,mips:[$],generated:!0});const E=J().snapshot;z&&(E.primaryColor=we.mediaVec3(...z.primary),E.secondaryColor=we.mediaVec3(...z.secondary),E.tertiaryColor=we.mediaVec3(...z.tertiary),E.textColor=we.mediaVec3(.98,.98,1),E.highContrastColor=we.mediaVec3(1,1,1)),E.hasThumbnail=!0,W.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 hs({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,W.mediaDriver=O.media,O.status().audio==="mic"&&(X.current=O.audio),J().snapshot.hasMedia){for(const{name:C,event:I}of we.diffMediaEvents(null,J().snapshot))for(const D of Ue)try{D.callMedia(C,I)}catch{}ye=we.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:Be,windowTitle:Z.snapshot,shortcuts:Ne.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 zt=new Map,Er=async b=>{if(xe.has(b))return xe.get(b);const T=Ge.getEntry(x,`materials/${b}.tex`);if(!T){if(an.isBuiltinParticleTextureName(b)){const $=an.buildBuiltinParticleTexture(b);if($){const z={glTex:$e.makeTextureMip(L.gl,[$],!1),width:$.width,height:$.height,rg88:!1,mips:[$],generated:!0};return xe.set(b,z),z}}return null}const P=_r.parseTex(T),C=_r.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=zl($,{muted:!0,renderDpr:rr(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 ne of B)F.addEventListener("ended",ne)},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:$e.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)`)},xe.set(b,E),E}else if(C.png!==void 0||C.image!==void 0&&C.fif===_r.FIF.JPEG){const $=new Blob([C.png||C.image],{type:C.png?"image/png":"image/jpeg"}),z=await createImageBitmap($);D={glTex:$e.makeTexture(L.gl,null,0,0,z),width:z.width,height:z.height,rg88:I}}else{if(C.image!==void 0)return null;{const $=_r.decodeMip0(P);D={glTex:$e.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 xe.set(b,D),D},Vt=b=>{if(xe.has(b))return Promise.resolve(xe.get(b));const T=zt.get(b);if(T)return T;const P=Er(b);return zt.set(b,P),P.finally(()=>{zt.get(b)===P&&zt.delete(b)}),P},Mn=/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=Ge.getEntry(x,`shaders/${T.shader}.${P}`);if(!C)continue;const I=xt(C);Mn.lastIndex=0;let D;for(;(D=Mn.exec(I))!==null;){const $=D[1];!$||$.startsWith("util/")||$.startsWith("_rt_")||xe.has($)||await Vt($)}}};let _n=0;const Wt=[];for(let b=0;b<g.layers.length;b++){const T=g.layers[b];if(T.image)try{let P;if(kt.BUILTIN_MODELS[T.image])P=kt.BUILTIN_MODELS[T.image];else{const E=Ge.getEntry(x,T.image);if(!E)continue;P=JSON.parse(xt(E))}Ke.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&&xe.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 $=Ke.resolveMaterial(P);if(!$)continue;let z;if(kt.BUILTIN_MATERIALS[$.materialPath])z=kt.BUILTIN_MATERIALS[$.materialPath];else{const E=Ge.getEntry(x,$.materialPath);if(E)z=JSON.parse(xt(E));else if(T.solid&&kt.BUILTIN_MATERIALS["materials/util/solidlayer.json"])z=kt.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_")||Wt.push(Vt(k).then(F=>{F&&E===0&&!D&&(T.textureName=k,_n++,F.videoCtl&&(T.videoCtl=F.videoCtl))}))}B?.shader&&Ge.getEntry(x,`shaders/${B.shader}.frag`)&&kt.attachLayerMaterialEffect(T,B);for(const E of T.effects||[])kt.resolveEffectChain(x,E,xt);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_")&&Wt.push(Vt(F));Wt.push(Me(E))}}catch(P){console.warn(`\u56FE\u5C42 ${T.name||b} \u52A0\u8F7D\u5931\u8D25: ${P.message}`)}}if(!fs){for(const b of g.layers)if(!(!b.isText||!(b.effects||[]).length))try{for(const T of b.effects||[])kt.resolveEffectChain(x,T,xt);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_")&&Wt.push(Vt(C))}catch(T){console.warn(`\u6587\u5B57\u5C42\u6548\u679C ${b.name} \u89E3\u6790\u5931\u8D25: ${T.message}`)}}await Promise.all(Wt);for(const[b,T]of xe){if(!T?.videoCtl)continue;g.layers.some(C=>C.textureName===b&&C.visible&&!C.destroyed)&&!e.paused&&T.videoCtl.play()}const Je=[],An=[],Ht=new Map;let Qn=0;const Jn=async b=>{const T=await Vt(b);if(T)return T;const P=an.buildBuiltinParticleTexture(b);if(!P)return null;const C={glTex:$e.makeTextureMip(L.gl,[P],!1),width:P.width,height:P.height,rg88:!1,mips:[P],generated:!0,frames:an.builtinParticleFrames(b)??void 0};return xe.set(b,C),Qn++,C},Pr=b=>{if(!b)return null;const T=b.mips&&b.mips[0];if(T?.rgba&&typeof an.prepareParticleNormalTexture=="function"){const P=an.prepareParticleNormalTexture(T);if(P&&P!==T)return{glTex:$e.makeTextureMip(L.gl,[P],!1),width:P.width,height:P.height,rg88:!1,mips:[P],generated:!0}}return b},er=async(b,T,P,C)=>{if(C>3)return null;const I=Ge.getEntry(x,b);if(!I)return se(e,n,`particle '${b}' \u4E0D\u5728 pkg\uFF0C\u8DF3\u8FC7`),null;const D=JSON.parse(xt(I)),$=new Tl.ParticleSystem(L.gl,D,P,T);let z=null,B=null;if(D.material){const k=Ge.getEntry(x,D.material);if(k){const F=JSON.parse(xt(k));$.setMaterial(F);const ne=F?.passes?.[0]?.textures||[];z=ne[0]||null,B=ne[1]||null}}const q=await Jn(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?an.particleNormalNameForAlbedo(z||"particle/halo"):null);if(S){const k=Pr(await Jn(S));k&&$.setNormalTexture({glTex:k.glTex,width:k.width,height:k.height})}$.setVisible(!!T.visible),Je.push($);const E=T.id;if(E!==void 0){let k=Ht.get(E);k||(k=[],Ht.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),ne=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),me={...T,origin:[ue[0],ue[1],(T.origin?.[2]||0)+(F[2]||0)],scale:[(T.scale?.[0]??1)*(ne[0]||1),(T.scale?.[1]??1)*(ne[1]||1),(T.scale?.[2]??1)*(ne[2]||1)],angles:[(T.angles?.[0]||0)+(Q[0]||0),(T.angles?.[1]||0)+(Q[1]||0),(T.angles?.[2]||0)+(Q[2]||0)]},Ie=await er(k.name,me,k.instanceoverride||P,C+1);Ie&&ce&&Ie.attachFollow($,ce,[F[0]||0,F[1]||0,F[2]||0])}return $};if(!Vl){for(const b of g.layers)if(b.particle)try{await er(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(Je.length>0){const b=u;u=()=>{b?.();for(const T of Je)T.dispose()}}const Xt=[];for(const b of g.layers)if(!(!b.sound||!b.sound.length))try{for(const T of b.sound){const P=Ge.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(()=>{}),Xt.push(z);break}}catch(T){console.warn(`\u58F0\u97F3\u56FE\u5C42 ${b.name} \u52A0\u8F7D\u5931\u8D25: ${T.message}`)}const Cr=b=>{for(const T of Xt)T.volume=Math.max(0,Math.min(1,b)),T.muted=b<=0};if(e.sceneAudio={setVolume:Cr,audios:Xt},s)return;let un=performance.now(),tn=0;L.setParticleRenderer(()=>{const b=performance.now(),T=Math.min(.05,(b-un)/1e3);if(un=b,Ae.state.has){const{wx:P,wy:C,originY:I}=Ae.state,D=I??C;for(const $ of Je)$.setPointer(P,D)}if(An.length)for(const P of An)P.syncLayerTransform();for(const P of Je)P.advance(T,te.enabled?Ye():null);if(tn<2&&(tn++,tn===2)){const P=Je.reduce((C,I)=>C+I.liveCount(),0);se(e,n,`particles live: ${P} across ${Je.length} systems`)}},(b,T,P,C,I)=>{if(b===void 0)return;const D=Ht.get(b);if(D)for(const $ of D)$.render(P,C,I,T.projW,T.projH)}),se(e,n,`particles: ${Je.length} systems, ${Qn} builtin tex generated`),window.__particleStats=()=>Je.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<Je.length;P++)Je[P].setVisible(T===void 0?b:P===T);return Je.length};const ot=[],dt=new Map,Te=b=>{if(!b||!b.puppet)return null;let T=dt.get(b);return T||(T=new Map,dt.set(b,T)),T};for(const b of g.layers)if(b.image)try{if(kt.BUILTIN_MODELS[b.image])continue;const T=Ge.getEntry(x,b.image);if(!T)continue;const P=JSON.parse(xt(T));if(!P.puppet)continue;const C=Ge.getEntry(x,P.puppet);if(!C)continue;const I=Zn.parseMDL(new Uint8Array(C)),D=b.textureName?xe.get(b.textureName):null;if(!D){se(e,n,`puppet '${b.name}' \u65E0\u8D34\u56FE\uFF0C\u8DF3\u8FC7`);continue}b.puppet=I,ot.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=Ge.getEntry(x,b.model);if(!T)continue;const P=Zn.parseMDL(new Uint8Array(T));let C=null;if(P.materialPath){const D=Ge.getEntry(x,P.materialPath);if(D){const z=JSON.parse(xt(D))?.passes?.[0]?.textures?.[0];typeof z=="string"&&z&&(C=z)}}C&&(await Vt(C),b.textureName=C);const I=C?xe.get(C):null;if(!I){se(e,n,`model '${b.name}' \u65E0\u8D34\u56FE\uFF0C\u8DF3\u8FC7`);continue}b.puppet=P,ot.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 pt=null;if(ot.length>0)try{pt=Zn.createMDLRenderer(L.gl);for(const T of ot)pt.upload(T.mdl);const b=new Map;for(const T of ot)b.set(T.layer,T);L.setPuppetRenderer((T,P,C)=>{const I=b.get(T);I&&pt.draw(P,I.mdl,{time:C.time,animLayers:T.animationLayers,boneOverrides:dt.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}`),pt=null;for(const T of ot)T.layer.puppet=null}if(s)return;se(e,n,`puppet: ${ot.length} meshes`);const Gt=Zn.applyAttachmentBindOrigins(g.layers);Gt.length&&se(e,n,`attachments: ${Gt.length} hanging layers`);const it=Ke.collectTransformDirty(g.layers,Gt.map(b=>b.layer));if(it.size){se(e,n,`transform graph: ${it.size} live layers`);for(const[b,T]of Ht)if(it.has(b))for(const P of T)An.push(P)}const ht=[],At=new Map,Nt={};let Tt=null,Tn=null,Sn=0;if(!fs&&g.layers.some(b=>b.isText)){const b=g.general?.orthogonalprojection,T=b?.width||t.width,P=b?.height||t.height,C=Vr(pn(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=Tr.get(E);if(k){k.refs++,$.push(E),D.set(S,k.family);continue}const F=tu[S.toLowerCase()];if(F){D.set(S,F);continue}try{const ne=Ge.getEntry(x,S);if(!ne)continue;const Q=eu(ne instanceof Uint8Array?ne:new Uint8Array(ne)),ce="wefont_"+nu(E)+"_"+S.split("/").pop().replace(/[^a-zA-Z0-9]/g,"_"),ue=URL.createObjectURL(new Blob([Q])),me=new FontFace(ce,`url(${ue})`);if(await me.load(),s){URL.revokeObjectURL(ue);break}document.fonts.add(me),(e.objectUrls??=[]).push(ue),D.set(S,ce),Tr.set(E,{family:ce,refs:1}),$.push(E)}catch(ne){console.warn(`\u5B57\u4F53\u52A0\u8F7D\u5931\u8D25 ${S}: ${ne.message}`)}}if($.length){const S=e.sceneCleanup;e.sceneCleanup=()=>{ru($),S?.()}}Tt=document.createElement("canvas"),Tn=Tt.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=tt.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:Nt,audioViews:Ve,inputView:nt,...Ft,mediaControl:Be,windowTitle:Z.snapshot,openUserShortcut:Ne.openUserShortcut,getLayerText:Q=>At.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&&De(E.sandbox))),At.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 me=0,Ie=0;ue.includes("left")&&(me+=Q),ue.includes("right")&&(me-=Q),ue.includes("top")&&(Ie-=ce),ue.includes("bottom")&&(Ie+=ce),S.origin[0]+=me,S.origin[1]+=Ie,S.localOrigin&&(S.localOrigin[0]+=me,S.localOrigin[1]+=Ie)}const k=ds*Math.max(1,S.textPointsize),F=tt.textLayerHasTintMask(S)?8:256,ne=Math.min(F,tt.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=ne,S.size=[E.boxW+ne*2,E.boxH+ne*2],E.entry={glTex:$e.makeTexture(L.gl,new Uint8Array([0,0,0,0]),1,1),width:1,height:1,rg88:!1},xe.set(E.texName,E.entry),S.textureName=E.texName,S.solid=!1,ht.push(E)}catch(E){console.warn(`\u6587\u5B57\u5BF9\u8C61 ${S.name} \u521D\u59CB\u5316\u5931\u8D25: ${E.message}`)}if(ht.length>0){const S=u;u=()=>{S?.();for(const E of ht)L.gl.deleteTexture(E.entry.glTex)}}const q=S=>{if(!Tn||!Tt)return;const E=Tn;for(const k of ht){const F=k.layer;let ne=String(F.text??"");if(k.sandbox&&k.sandbox.hasUpdate){k.sandbox.engine.runtime=S;const me=k.sandbox.callUpdate(ne);me!=null?ne=String(me):k.sandbox.thisLayer.text&&(ne=String(k.sandbox.thisLayer.text))}else k.sandbox&&typeof k.sandbox.thisLayer?.text=="string"&&(ne=String(k.sandbox.thisLayer.text));if(At.set(F.name||"",ne),!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=`${ne}\0${Q}\0${ce}\0${F.alpha}\0${F.textCastshadow}`;if(k.lastKey!==ue){k.lastKey=ue;try{const me=ds*Q,Ie=k.boxW,bt=k.boxH,Et=k.margin,yt=Math.abs(F.scale[0]||1),de=Math.abs(F.scale[1]||1);let pe=Math.max(1,Math.round(F.size[0]*yt*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)),Tt.width!==pe||Tt.height!==fe?(Tt.width=pe,Tt.height=fe):(E.setTransform(1,0,0,1,0,0),E.clearRect(0,0,pe,fe));const st=Math.min(pe/F.size[0],fe/F.size[1]);E.setTransform(st,0,0,st,0,0),E.translate(Et,Et);const at=ce&&D.get(ce)||"sans-serif";E.font=`${me}px "${at}", sans-serif`;const vt=E.measureText(""),et=(vt.fontBoundingBoxAscent||0)+(vt.fontBoundingBoxDescent||0),Ce=F.textSpacing||[0,0],dn=tt.layoutText(ne,{boxW:Ie,boxH:bt,pointsize:me,lineHeight:(et>0?et:me*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},We=>E.measureText(We).width);tt.drawTextLayer(E,dn,{font:E.font,color:F.textColor,alpha:F.alpha,brightness:F.brightness,spacing:Ce,pointsize:me,opaquebackground:!!F.textOpaquebackground,backgroundcolor:F.textBackgroundcolor,backgroundbrightness:F.textBackgroundbrightness,castshadow:!!F.textCastshadow});const ct=k.entry;L.gl.bindTexture(L.gl.TEXTURE_2D,ct.glTex),L.gl.texImage2D(L.gl.TEXTURE_2D,0,L.gl.RGBA,L.gl.RGBA,L.gl.UNSIGNED_BYTE,Tt),ct.width=pe,ct.height=fe}catch(me){console.warn(`\u6587\u5B57\u5BF9\u8C61 ${F.name} \u7ED8\u5236\u5931\u8D25: ${me.message}`),k.lastKey=null}}}};e.sceneTextUpdate=q,window.__textWidgets=ht,se(e,n,`text widgets: ${ht.length} (scripts ${ht.filter(S=>S.sandbox).length}, fonts ${D.size}, quality ${I.toFixed(2)})`)}if(s)return;const Ut=[],En=[],Dt=[],nn={},je=[],mt=[],gt=new Map,fn=(b,T)=>{if(!T||typeof T.callCursor!="function"||!T.hasCursorHook)return;const P=gt.get(b);P?P.push(T):gt.set(b,[T])};for(const b of ht)b.sandbox&&fn(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(nn[E])return nn[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 ne=E;if(k=g.layers.find(Q=>Q&&!Q.destroyed&&Q.image===ne&&Q.textureName)||g.layers.find(Q=>Q&&!Q.destroyed&&Q.image===ne)||null,!k)return se(e,n,`createLayer('${ne}') \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(ne=>({...ne,passes:Array.isArray(ne.passes)?ne.passes.map(Q=>({...Q})):ne.passes}))),g.layers.push(F),F},mediaControl:Be,windowTitle:Z.snapshot,openUserShortcut:Ne.openUserShortcut,isScreensaver:!1};L.setConstantScriptRuntime?.(tt.evalObjectScript,{userProperties:C,audioViews:Ve,shared:Nt,inputView:nt,timers:rt,...$,onSandbox:E=>{E&&E.hasMediaHook&&De(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,ne]of Object.entries(k))try{const Q=os.createAnimation(ne.animation);Q.field=F,Q.baseValue=ne.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),En.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,ne]of(E.effects||[]).entries()){const Q=ne.visibleScript;if(Q)try{const ce=tt.evalObjectScript(Q.script,Q.scriptproperties,{canvasSize:{width:T,height:P},userProperties:C,audioViews:Ve,inputView:nt,...Ft,layer:E,targetEffect:ne,...$,shared:Nt,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(ne.visible),ce.applyUserProperties(C),ce.hasMediaHook&&De(ce),ce.hasUpdate&&je.push({effect:ne,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,ne]of Object.entries(k))try{const Q=tt.evalObjectScript(ne.script,ne.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:Ve,inputView:nt,layer:E,...$,getBoneOverrides:Te,shared:Nt,...Ft,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],me=F==="angles"&&Array.isArray(ue)?tt.radToScriptAngles(ue):Array.isArray(ue)?{x:ue[0]??0,y:ue[1]??0,z:ue[2]??0}:ue;Q.init(me),Q.applyUserProperties(C),fn(E,Q),Q.hasMediaHook&&De(Q),Q.hasUpdate&&Ut.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=tt.evalObjectScript(k.script,k.scriptproperties,{canvasSize:{width:T,height:P},userProperties:C,audioViews:Ve,inputView:nt,...Ft,...$,shared:Nt,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&&De(F);const ne=Q=>I(E,Q);F.hasUpdate&&mt.push({field:E,sandbox:F,write:ne})}catch(F){console.warn(`general \u811A\u672C ${E} \u6C42\u503C\u5931\u8D25: ${F.message}`)}mt.length&&se(e,n,`general scripts: ${mt.map(E=>E.field).join(",")}`)}const S=g.generalAnimations;if(S){for(const[E,k]of Object.entries(S))try{const F=os.createAnimation(k.animation);F.field=E,F.baseValue=k.value,F.baseNumeric=k.value,F.name&&(nn[F.name]=F),Dt.push({field:E,ctrl:F,write:ne=>I(E,ne)})}catch(F){se(e,n,`general animation '${E}' \u5EFA\u63A7\u5236\u5668\u5931\u8D25: ${String(F.message).slice(0,80)}`)}Dt.length&&se(e,n,`general animations: ${Dt.map(E=>E.field).join(",")}`)}}Ut.length&&(se(e,n,`object scripts: ${Ut.length}`),window.__objScripts=Ut),window.__mediaHooks=Ue,window.__sceneLayers=g.layers,window.__compositeStats=()=>L.compositeStats?.()??null,window.__compositeEnable=b=>L.setCompositeEnabled?.(b),window.__scene=g,window.__textures=xe;const Pn=Array.from(gt.keys());Pn.length&&se(e,n,`cursor hooks: ${Pn.length} layers`);let rn=null,ut=null,Cn=!1;const tr=()=>({worldPosition:tt.makeCursorEventVec(Ae.state.wx,Ae.state.originY!=null?Ae.state.originY:Ae.state.wy,0)}),Bt=(b,T,P)=>{const C=gt.get(b);if(C)for(const I of C)I.callCursor(T,P)},Lr=()=>{if(Pn.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=Pl.hitTestLayers(g.layers,b.wx,b.wy,P,{parOffX:T.x,parOffY:T.y,alignTable:$e.ALIGN,filter:D=>gt.has(D)}),I=tr();C!==rn&&(rn&&Bt(rn,"cursorLeave",I),rn=C,C&&Bt(C,"cursorEnter",I)),C&&Bt(C,"cursorMove",I),b.leftDown&&!Cn?(ut=C,C&&Bt(C,"cursorDown",I)):!b.leftDown&&Cn&&(ut&&Bt(ut,"cursorUp",I),ut&&ut===C&&Bt(C,"cursorClick",I),ut=null),Cn=b.leftDown},Rr=performance.now();let nr=0,St=0;const w=[],U=[];let G=-1/0,V=0;const Y=b=>{if(s||e.paused)return;const P=1e3/(e.cfg.sceneFps||60);if(b-G>=P){G=b,Fn(e,b),So(e,t,e.cfg);const C=(b-Rr-nr)/1e3;if(nt.update(Ae.state),qe.enabled){if(O?.media)O.media.pump();else{const S=J();typeof S?.update=="function"&&S.update(C)}const B=he(),q=we.diffMediaEvents(ye,B);if(q.length){for(const{name:S,event:E}of q)for(const k of Ue)k.disabled||k.callMedia(S,E);ye=we.cloneMediaSnapshot(B)}}O?.windowTitle?O.windowTitle.pump():K.update(C);const I=Math.max(0,C-V);V=C;for(const B of En){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 Dt){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 je){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 mt){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 Ut){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"?tt.radToScriptAngles(E):{x:E[0]||0,y:E[1]||0,z:E[2]||0},F=B.sandbox.callUpdate(k),ne=F&&typeof F=="object"&&"x"in F?F:k;B.layer[S]=B.field==="angles"?tt.scriptAnglesToRad(ne):[ne.x||0,ne.y||0,ne.z||0]}}$&&A(),it.size&&Ke.recomposeWorld(g.layers,it),te.enabled&&(_e.pump(),_e.active||(X.current?X.current.pump():j.update(C)),fl(Ve,Ye())),Gt.length&&Zn.followAttachments(Gt,C,Te);const z=e.coverAlign;L.render(g,xe,t.width,t.height,C,pn(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{Lr()}catch{}Ae.beginFrame();try{e.sceneTextUpdate&&b>=Sn&&(Sn=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=oa(T,v,b);if(Object.keys(P).length){for(const C of g.layers){const I=C.srcObject;if(!I)continue;hn(I,T,0);const D=Ct(I.visible);D&&D in P&&(C.visibleSelf=Ke.parseBool(I.visible,!0));const $=Ct(I.color);$&&$ in P&&(C.color=Ke.parseColor(I.color),C.isText&&(C.textColor=C.color));const z=Ct(I.alpha);z&&z in P&&(C.alpha=Ke.parseNum(I.alpha,1));const B=Ct(I.brightness);B&&B in P&&(C.brightness=Ke.parseNum(I.brightness,1));const q=Ct(I.volume);if(q&&q in P){const E=Ke.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 ne=Ct(k.visible);ne&&ne in P&&(F.visible=Ke.parseBool(k.visible,!0));const Q=Ct(k.rate);Q&&Q in P&&(F.rate=Ke.parseNum(k.rate,1));const ce=Ct(k.blend);ce&&ce in P&&(F.blend=Ke.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 ne=Ct(k.visible);ne&&ne in P&&!F.visibleScript&&(F.visible=Ke.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=Ct(S[k]);if(F&&F in P){E=!0;break}}if(E){const k=Ht.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=Ht.get(C.id);if(I)for(const D of I)D.setVisible(!!C.visible)}L.applyConstUserProperties?.(P);for(const C of ht)C.lastKey=null;se(e,n,`props hot: ${Object.keys(P).join(",")}`)}};p=()=>{e.raf!==void 0&&(cancelAnimationFrame(e.raf),e.raf=void 0),St||(St=performance.now()),w.length=0;for(const b of xe.values())b?.videoCtl?.isPlaying?.()&&(w.push(b.videoCtl),b.videoCtl.pause());U.length=0;for(const b of Xt)!b.paused&&!b.ended&&(U.push(b),b.pause())},d=()=>{St&&(nr+=performance.now()-St,St=0),un=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=pn(e.cfg.fit),I=Vr(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 cu='data-we-shim="1"',ms="data-we-shim-src";function lu(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 uu(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 gs(e){return e.replace(/<\/script/gi,"<\\/script")}function fu(e,n,t){if(e||(e=""),e.includes(cu)||e.includes(ms))return e;const r=t.baseHref&&!/<base\b/i.test(e)?`<base href="${t.baseHref.replace(/"/g,""")}">`:"",o=`<script ${ms}="1">
|
|
513
|
-
${
|
|
514
|
-
<\/script>`,
|
|
515
|
-
${
|
|
516
|
-
<\/script>`:"",
|
|
761
|
+
`};function u2(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;const l=(g,y,w)=>{let A=0;const b=y+w;for(let v=y;v<b;v+=4){const x=o[v]||0,P=v+1<b?o[v+1]:0,S=v+2<b?o[v+2]:0,k=v+3<b?o[v+3]:0;A=A+(x<<24|P<<16|S<<8|k)>>>0}c.setUint32(g+4,A)};let d=!1;for(let g=0;g<u;g++){const y=12+g*16,w=String.fromCharCode(o[y],o[y+1],o[y+2],o[y+3]);if(w!=="vhea"&&w!=="hhea")continue;const A=c.getUint32(y+8),b=c.getUint32(y+12);if(b!==36||A+b>o.length)continue;const v=c.getUint32(A);v===65536||v===69632||(c.setUint32(A,65536),l(y,A,b),d=!0)}let f=-1,h=0,p=0;for(let g=0;g<u;g++){const y=12+g*16;if(String.fromCharCode(o[y],o[y+1],o[y+2],o[y+3])==="cmap"){f=y,h=c.getUint32(y+8),p=c.getUint32(y+12);break}}if(f<0||h+p>o.length)return d?o:t;const m=c.getUint16(h+2);for(let g=0;g<m;g++){const y=h+4+g*8,w=c.getUint32(y+4),A=h+w;if(A+14>o.length||c.getUint16(A)!==4)continue;const b=c.getUint16(A+6),v=b>>>1;if(v<1)continue;const x=2*Math.pow(2,Math.floor(Math.log2(v))),P=Math.floor(Math.log2(v)),S=b-x,k=c.getUint16(A+8),_=c.getUint16(A+10),I=c.getUint16(A+12);k===x&&_===P&&I===S||(c.setUint16(A+8,x),c.setUint16(A+10,P),c.setUint16(A+12,S),d=!0)}return d?(l(f,h,p),o):t}function f2(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 d2(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=d=>e.getUint16(d,o),u=d=>e.getUint32(d,o),l=s+u(s+4);if(l>=0&&l+2<=e.byteLength){const d=c(l);for(let f=0;f<d;f++){const h=l+2+f*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 h2(t,e,n,r,i=1){const s=Number.isFinite(i)&&i>0?Math.min(1,i):1,a=n>0?Math.max(1,Math.round(n*s)):1,o=r>0?Math.max(1,Math.round(r*s)):1,c=s<.999&&n>0&&r>0?{resizeWidth:a,resizeHeight:o,resizeQuality:"high"}:null;let u;try{u=await createImageBitmap(t,{imageOrientation:"none",premultiplyAlpha:"none",...c||{}})}catch{try{u=await createImageBitmap(t,{premultiplyAlpha:"none",...c||{}})}catch{u=await createImageBitmap(t,{premultiplyAlpha:"none"})}}const l=f2(e?d2(e):1,u.width,u.height,a,o);if(l==="keep")return u;const d=document.createElement("canvas");d.width=a,d.height=o;const f=d.getContext("2d");if(!f)return u;l==="rot-cw"?(f.translate(a,0),f.rotate(Math.PI/2)):(f.translate(0,o),f.rotate(-Math.PI/2)),f.drawImage(u,0,0);const h=await createImageBitmap(d);return u.close?.(),h}function m2(t,e,n){const{width:r,height:i,rgba:s}=t,a=Math.max(1,Math.round(e)),o=Math.max(1,Math.round(n));if(a===r&&o===i)return t;const c=new Uint8Array(a*o*4),u=r/a,l=i/o;for(let d=0;d<o;d++){const f=Math.min(i-1,Math.max(0,(d+.5)*l-.5)),h=Math.floor(f),p=Math.min(i-1,h+1),m=f-h;for(let g=0;g<a;g++){const y=Math.min(r-1,Math.max(0,(g+.5)*u-.5)),w=Math.floor(y),A=Math.min(r-1,w+1),b=y-w,v=(h*r+w)*4,x=(h*r+A)*4,P=(p*r+w)*4,S=(p*r+A)*4,k=(d*a+g)*4;for(let _=0;_<4;_++){const I=s[v+_]*(1-b)+s[x+_]*b,B=s[P+_]*(1-b)+s[S+_]*b;c[k+_]=Math.round(I*(1-m)+B*m)}}}return{width:a,height:o,rgba:c}}const p2={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"},Uo=new Map,ti=ot.foldVisibleReturn;function op(t,e){return e==="maxwidth"?{get:()=>Number(t.textMaxwidth)||0,set:n=>{t.textMaxwidth=n,t.lastKey=null}}:e==="pointsize"?{get:()=>Number(t.textPointsize)||0,set:n=>{t.textPointsize=n,t.lastKey=null}}:e==="volume"?{get:()=>t.soundprops?Number(t.soundprops.volume)??1:Number(t.volume)||1,set:n=>{const r=Math.max(0,Math.min(1,n));t.soundprops&&(t.soundprops.volume=r),t.volume=r,t.soundCtl?.setVolume&&t.soundCtl.setVolume(r)}}:{get:()=>Number(t[e])||0,set:n=>{t[e]=n}}}const g2=1;function y2(t,e){if(t.storageProvider)return ot.makeSandboxStorage(t.storageProvider.screen,t.storageProvider.global);let n=null;try{n=typeof window<"u"&&window.localStorage?window.localStorage:null}catch{n=null}if(!n)return ot.makeSandboxStorage();const r="wst:"+(e?encodeURIComponent(e):"nokey")+":",i="wst:global:",s=a=>({get:o=>{const c=n.getItem(a+o);return c===null?null:c},set:(o,c)=>n.setItem(a+o,c),remove:o=>n.removeItem(a+o),clear:()=>{const o=[];for(let c=0;c<n.length;c++){const u=n.key(c);u&&u.startsWith(a)&&o.push(u)}for(const c of o)n.removeItem(c)},keys:()=>{const o=[];for(let c=0;c<n.length;c++){const u=n.key(c);u&&u.startsWith(a)&&o.push(u.slice(a.length))}return o}});return ot.makeSandboxStorage(s(r),s(i))}function b2(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 w2(t){for(const e of t){const n=Uo.get(e);if(n&&(n.refs--,!(n.refs>0))){Uo.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 Er=new Map,v2=512*1024*1024;let Oo=0;function A2(t){for(;Er.size>0&&(Er.size>2||Oo>v2);){let e=null,n=1/0;for(const[i,s]of Er)i!==t&&s.at<n&&(n=s.at,e=i);if(!e)break;const r=Er.get(e);Oo-=r.parsed.fileSize||0,Er.delete(e)}}function x2(t){if(!t)return;const e=Er.get(t);e&&(Oo-=e.parsed.fileSize||0,Er.delete(t))}async function k2(t,e,n,r){const i=n.key;if(i){const c=Er.get(i);if(c)return c.at=Date.now(),be(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))}be(t,e,`pkg body: ${s.byteLength} bytes`);const a=s instanceof Uint8Array?s:new Uint8Array(s),o=at.parsePkg(a);return i&&(Er.set(i,{parsed:o,at:Date.now()}),Oo+=o.fileSize||0,A2(i)),o}function T2(t,e){Or(t);const n=(e.canvas instanceof HTMLCanvasElement?e.canvas:null)??document.createElement("canvas"),r=Vi(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=(...m)=>{const g=m.map(y=>typeof y=="string"?y:String(y?.message??y)).join(" ");if(g.includes("[we-scene]"))try{be(t,e,g.slice(0,300))}catch{}o(...m)};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,d,f,h,p;t.sceneCtl={pause(){f?.()},resume(){h?.()},applyUserProperties(m){d?d(m):l={...l||{},...m}},setQuality(m){t.cfg.quality={...fa(t.cfg.quality),...m??{}},p?.(fa(t.cfg.quality))}},(async()=>{try{const m=e.source??Ym(`${e.mediaBase}/${e.src}`);if(!e.source&&(!e.mediaBase||!e.src))throw new Error("\u573A\u666F\u58C1\u7EB8\u7F3A\u5C11 mediaBase/src");be(t,e,"mountScene start");const g=await k2(t,e,m,c.signal);if(a)return;let y=null;try{y=await m.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 A=at.getEntry(g,"scene.json")??at.getEntry(g,"gifscene.json")??at.getEntry(g,"scenes/scene.json")??at.getEntry(g,"scenes/gifscene.json");if(!A)throw new Error("pkg \u4E2D\u6CA1\u6709 scene.json\uFF08\u4E0D\u662F\u573A\u666F\u58C1\u7EB8\uFF1F\uFF09");const b=zt.parseScene(JSON.parse(jt(A)),y);if(e.clearColor){const T=b.general??={};T.clearcolor=e.clearColor,T.clearenabled=!0}{const T=b.general?.zoom,C=Number(T&&typeof T=="object"?T.value:T);b.cameraTransforms={zoom:Number.isFinite(C)&&C>0?C:1}}const v=nb(b.properties||{});t.liveUserProps=v;const x=()=>zt.recomputeLayerVisibility(b.layers);if(t.onSceneInfo){const T=b.general?.orthogonalprojection||{},C=Number(T.width)>0?Number(T.width):n.width,R=Number(T.height)>0?Number(T.height):n.height,F=b.layers||[],$={width:C,height:R,layerCount:F.length,hasModels:F.some(L=>!!L.model),hasParticles:F.some(L=>!!L.particle),hasText:F.some(L=>!!L.text)},H=t.onSceneInfo;t.onSceneInfo=void 0,H($)}const P=[],S=y2(e,m.key);Zm&&(b.layers=b.layers.filter(T=>!(Zm&&T.isComponent)));const k=T=>{const C=T.startsWith("shaders/")?T:"shaders/"+T,R=T.startsWith("shaders/")?T.slice(8):T,F=at.getEntry(g,C);let $=F?jt(F):l2[R]??null;const H=window.__shaderPatch;if($&&H){const L=R.replace(/\.(frag|vert|h)$/,""),X=H[L]||H[R];if(typeof X=="function")try{const Q=X($,R);typeof Q=="string"&&($=Q)}catch{}}return Promise.resolve($)},_=pt.createRenderer(n,{shaderResolver:k,diag:T=>be(t,e,`renderer: ${T}`),fboCapFactor:0,workshopId:e.src??cu(e.source?.key),parallaxFormula:e.parallaxFormula});if(t.renderer=_,a)return;Ti.setParticleFrameTargetProvider(()=>_.getFrameTarget?.()??null),Ti.setParticleSceneCapture((T,C)=>_.captureSceneTexture?.(T,C)??null);{const T=u;u=()=>{T?.(),Ti.setParticleFrameTargetProvider(null),Ti.setParticleSceneCapture(null)}}const I=y?.general?.supportsaudioprocessing!==!1,B=nm(),V=We.createSimulatedMedia(),O=Gm.createSimulatedWindowTitle();let U=null;const W={mediaDriver:null,lastSnap:{get:()=>null,setHasThumbnail:()=>{}}},ie={current:null},we=We.createWallpaperAudioMedia(We.MEDIA_PLAYBACK,We.mediaVec3);let Y=null;const oe=T=>!!(T&&T.snapshot&&T.snapshot.hasMedia),he=()=>oe(Y)?Y:oe(t.mediaSource)?t.mediaSource:(we.hasCurrent()?we:null)??V;let Ae=O;const Pe={enabled:I&&!t.audioDisabled},Ce=T=>new Float32Array(T),Le={left16:Ce(16),right16:Ce(16),left32:Ce(32),right32:Ce(32),left64:Ce(64),right64:Ce(64),level:0,silent:!0},Ne=(()=>{const T={left64:Ce(64),right64:Ce(64),left32:Ce(32),right32:Ce(32),left16:Ce(16),right16:Ce(16),preL64:Ce(64),preR64:Ce(64),level:0,silent:!0},C=(R,F)=>{const $=F.length/R.length;for(let H=0;H<R.length;H++){let L=0;const X=Math.floor(H*$),Q=Math.max(X+1,Math.floor((H+1)*$));for(let re=X;re<Q;re++)L+=F[re];R[H]=L/(Q-X)}};return{active:!1,snapshot:T,pump(){const R=t.audioBridge?.();if(!R||!R.left||!R.right){this.active=!1;return}const F=Math.min(64,R.left.length,R.right.length);let $=0;for(let H=0;H<F;H++){const L=R.left[H]||0,X=R.right[H]||0;T.left64[H]=L,T.right64[H]=X,T.preL64[H]=L,T.preR64[H]=X,H<48&&($+=L)}for(let H=F;H<64;H++)T.left64[H]=0,T.right64[H]=0,T.preL64[H]=0,T.preR64[H]=0;C(T.left32,T.left64),C(T.right32,T.right64),C(T.left16,T.left64),C(T.right16,T.right64),T.level=Math.min(1,$/48),T.silent=T.level<.02,this.active=!0}}})(),De=()=>Ne.active?Ne.snapshot:ie.current?ie.current.snapshot:B.snapshot;let Re=null;_.setAudioProvider(()=>Pe.enabled?Re||De():Le);const Fe=new Map,Xe=new Map,$e=[],Ye=(T,C)=>{if(!T||!C||!C.sandbox)return;let R=Xe.get(T);R||(R=[],Xe.set(T,R)),R.push(C)};window.__audioStats=()=>({enabled:Pe.enabled,live:!!ie.current,level:Pe.enabled?Math.round((ie.current?ie.current.snapshot:B.snapshot).level*1e3)/1e3:0,silent:Pe.enabled?(ie.current?ie.current.snapshot:B.snapshot).silent:!0,bass:Pe.enabled?Math.round((ie.current?ie.current.snapshot:B.snapshot).left64[2]*1e3)/1e3:0}),window.__audioMute=T=>(Pe.enabled=!T,Pe.enabled),be(t,e,`audio: ${ie.current?"live mic":"simulated"} stream, supportsaudioprocessing=${I}`);const nt=Gm.createShortcutHandler(T=>{be(t,e,`openUserShortcut: ${T}`)}),dn={enabled:!t.mediaDisabled,override:null},st=[],gt=new Set;let Vt=0,xn=0,Pt=null,xt=(()=>{const T=new Date;return(T.getHours()*3600+T.getMinutes()*60+T.getSeconds())/86400})(),tn=-1;const Mt=T=>{if(!(!T||!T.hasResizeHook||typeof T.callResize!="function")&&!gt.has(T)&&(gt.add(T),Pt))try{T.callResize(Pt.w,Pt.h)}catch{}},Pi=(T,C)=>{for(const R of gt)if(!(!R||R.disabled))try{R.callResize(T,C)}catch{}};let nn=null,_i;W.lastSnap={get:()=>nn,setHasThumbnail:T=>{nn&&(nn.hasThumbnail=T)}};const ct=()=>he().snapshot,tr=T=>{if(!(!T||!T.hasMediaHook||st.includes(T))&&(st.push(T),!!ct().hasMedia))for(const{name:C,event:R}of We.diffMediaEvents(null,ct()))try{T.callMedia(C,R)}catch{}};window.__mediaStats=()=>({enabled:dn.enabled,live:!!U,hooks:st.length,title:ct().title,artist:ct().artist,album:ct().album,state:ct().state,position:Math.round(ct().position),duration:ct().duration,hasThumbnail:ct().hasThumbnail,lyric:ct().lyricLine,primaryColor:ct().primaryColor?[ct().primaryColor.x,ct().primaryColor.y,ct().primaryColor.z]:null}),window.__mediaSet=T=>{try{Object.assign(ct(),T||{})}catch{be(t,e,"__mediaSet: \u5F53\u524D\u5A92\u4F53\u5FEB\u7167\u4E3A\u53EA\u8BFB\u89C6\u56FE\uFF08\u58C1\u7EB8\u97F3\u9891\u9A71\u52A8\uFF09\uFF0C\u8986\u5199\u8DF3\u8FC7")}const C=We.diffMediaEvents(nn,ct());for(const{name:R,event:F}of C)for(const $ of st)$.callMedia(R,F);return nn=We.cloneMediaSnapshot(ct()),window.__mediaStats()};const pa=()=>{const T=We.diffMediaEvents(nn,ct());for(const{name:C,event:R}of T)for(const F of st)try{F.callMedia(C,R)}catch{}nn=We.cloneMediaSnapshot(ct())},hn=T=>{const C=he(),R=C?.[T];if(typeof R=="function")try{R.call(C)}catch(F){be(t,e,`media ${T} \u5931\u8D25: ${F?.message}`)}return pa(),ct()},Cr={get snapshot(){return ct()},skipNext:()=>hn("skipNext"),skipPrevious:()=>hn("skipPrevious"),play:()=>hn("play"),pause:()=>hn("pause"),playPause:()=>hn("playPause")};t.mediaCtl=Cr,window.__mediaControl=Cr,window.__system={media:Cr,windowTitle:Ae.snapshot,shortcuts:nt.last,live:null},window.__liveSystem=()=>({audio:"off",media:"offline",window:"offline"});const lt=wA.createPointerSource(e.canvas?{target:e.canvas,viewport:()=>({w:e.canvas.clientWidth||window.innerWidth||1,h:e.canvas.clientHeight||window.innerHeight||1})}:{});_.setPointerProvider(()=>lt),t.pointerCtl={push:T=>lt.pushExternal(T),leave:()=>lt.pushExternalLeave()};{const T=u;u=()=>{T?.(),lt.dispose()}}const Un=ot.createInputView(),kn=bA.createEngineTimers({setTimeout:(T,C)=>window.setTimeout(T,C),clearTimeout:T=>window.clearTimeout(T),setInterval:(T,C)=>window.setInterval(T,C),clearInterval:T=>window.clearInterval(T)},{onError:(()=>{let T=!1;return C=>{T||(T=!0,be(t,e,`engine \u5B9A\u65F6\u5668\u56DE\u8C03\u629B\u9519\uFF08\u6B64\u540E\u540C\u7C7B\u9759\u9ED8\uFF09: ${String(C?.message||C).slice(0,90)}`))}})()}),nr={setTimeout:kn.setTimeout,clearTimeout:kn.clearTimeout,setInterval:kn.setInterval,clearInterval:kn.clearInterval};{const T=u;u=()=>{T?.(),kn.dispose()}}window.__pointerStats=()=>{const T=lt.state,C=R=>Math.round(R*1e3)/1e3;return{normalized:{u:C(T.u),v:C(T.v)},last:{u:C(T.lastU),v:C(T.lastV)},world:{x:Math.round(T.wx),y:Math.round(T.wy)},originY:T.originY!=null?Math.round(T.originY):null,screen:{x:T.screenX,y:T.screenY,w:T.screenW,h:T.screenH},leftDown:T.leftDown,has:T.has,delta:C(lt.normalizedDelta()),counts:{move:T.moveCount,down:T.downCount,up:T.upCount}}};const yt=1.15,Oe=new Map;{const C=(b.general??null)?.orthogonalprojection??null,R=Number(C?.width)||0,F=Number(C?.height)||0,$=R>0&&F>0&&C?.auto!==!0,H=Vi(t,e)||1,L=(n.clientWidth||window.innerWidth||1280)*H,X=(n.clientHeight||window.innerHeight||720)*H;if($){const Q={canvasDeviceW:L,canvasDeviceH:X,viewW:R,viewH:F,safety:yt};for(const re of b.layers){if(!re||re.destroyed||!re.visible)continue;const q=re.image||re.model;if(!q)continue;let K=null;try{if(An.BUILTIN_MODELS[q])K=An.BUILTIN_MODELS[q];else{const ue=at.getEntry(g,q);ue&&(K=JSON.parse(jt(ue)))}}catch{K=null}if(!K||K.meshes||K.puppet)continue;const D=K.material;if(!D)continue;const E=at.getEntry(g,D);if(!E)continue;let z=[];try{z=(JSON.parse(jt(E))?.passes||[]).flatMap(pe=>Array.isArray(pe?.textures)?pe.textures:[])}catch{z=[]}const ee=re.size||[0,0],G=Math.abs(Number(ee[0]))>0&&Math.abs(Number(ee[1]))>0?[Number(ee[0]),Number(ee[1])]:[Number(K.width||0),Number(K.height||0)];if(!(Math.abs(G[0])>0)||!(Math.abs(G[1])>0))continue;const J=re.scale||[1,1,1],ge=!!(re.sizeAnimation||re.scaleAnimation||re.animationlayers?.length),ae=Np(G,[Number(J[0]??1),Number(J[1]??1)],Number((re.angles||[0,0,0])[2]||0),{...Q,safety:yt*(ge?1.4:1)});if(ae>0)for(const ue of z){if(typeof ue!="string"||!ue||ue.startsWith("util/")||ue.startsWith("_rt_"))continue;const pe=Oe.get(ue)||0;ae>pe&&Oe.set(ue,ae)}}be(t,e,`[S4] \u56FE\u5C42\u8DB3\u8FF9\u8868 ${Oe.size} \u4E2A\u8D34\u56FE\uFF08\u89C6\u53E3 ${R}x${F} \u4E16\u754C \u2192 \u753B\u5E03 ${Math.round(L)}x${Math.round(X)} \u8BBE\u5907\u50CF\u7D20\uFF0Csafety=${yt}\uFF09`)}else be(t,e,"[S4] \u6B63\u4EA4\u6295\u5F71\u975E\u663E\u5F0F\uFF08auto/\u900F\u89C6\uFF09\uFF1A\u8DF3\u8FC7\u56FE\u5C42\u8DB3\u8FF9\u6A21\u578B\uFF0C\u56DE\u9000\u5230\u5168\u5C40\u6863\u4F4D")}const Ke=new Map,Ei=Dp();let ni="",On=!1;const Ir=Ip(t,e),Rr=Rp(t,e),ga=32,Ve={texCount:0,cpuDecoded:0,cpuReleased:0,gpuUploaded:0,compressed:0,r8Native:0,framesScaled:[],scaled:[],textures:[],pkgBytes:0},ya=(()=>{if(typeof location>"u")return!0;const T=new URLSearchParams(location.search).get("texr8");return!(T==="0"||T==="off"||T==="native")})(),ba=(()=>{if(typeof location>"u")return!0;const T=new URLSearchParams(location.search).get("texcompress");return!(T==="0"||T==="off"||T==="native")})(),bs=()=>{const T=Vi(t,e)||1,C=(n.clientWidth||window.innerWidth||1280)*T,R=(n.clientHeight||window.innerHeight||720)*T;return Math.max(C,R)},ws=T=>Fp(T,Ir,Rr),wa=T=>{const C=T?.images?.[0]?.[0];return!!T?.frames?.list?.length?Math.max(Number(C?.width||0),Number(C?.height||0)):Math.max(Number(T?.width||0),Number(T?.height||0),0)||Math.max(Number(C?.width||0),Number(C?.height||0))},ri=(T,C)=>{const R=wa(C);if(Ei||On)return R;const F=Up(R,T),$=Oe.get(ni)||0;return Lp(F,R,$)},rt=(T,C,R)=>{if(Ei||On)return 0;const F=T?.images?.[0];if(!F)return 0;const $=F[0],H=!!T?.frames?.list?.length,L=H?Math.max(Number($?.width||0),Number($?.height||0)):Math.max(Number(T?.width||0),Number(T?.height||0),0)||Math.max(Number($?.width||0),Number($?.height||0)),X=F.map((q,K)=>H?Math.max(Number(q.width||0),Number(q.height||0)):Math.max(1,Math.round(L/2**K))),Q=Oe.get(ni)||0,re=Q>0?Math.round(Q):Math.max(64,Math.round(bs()));return Op(X,C,re)},Mi=(T,C)=>{const R=Math.max(Number(T.width||0),Number(T.height||0));if(!C||R<=C*1.1)return T;const F=C/R;return m2(T,Math.max(1,Math.round(T.width*F)),Math.max(1,Math.round(T.height*F)))},va=async(T,C,R)=>{const F=document.createElement("canvas");F.width=T.width,F.height=T.height;const $=F.getContext("2d",{alpha:!0,willReadFrequently:!1});if(!$)return null;$.putImageData(new ImageData(new Uint8ClampedArray(T.rgba.buffer,T.rgba.byteOffset,T.rgba.length),T.width,T.height),0,0);const H=document.createElement("canvas");H.width=C,H.height=R;const L=H.getContext("2d",{alpha:!0});if(!L)return null;L.imageSmoothingEnabled=!0,L.imageSmoothingQuality="high",L.drawImage(F,0,0,C,R);try{return await createImageBitmap(H,{premultiplyAlpha:"none"})}catch{return null}};Ve.pkgBytes=Number(g?.fileSize||0);{let T=null;try{T=await o2()}catch(C){be(t,e,`local assets \u88C5\u8F7D\u5931\u8D25\uFF08\u5FFD\u7565\uFF09\uFF1A${C?.message}`)}T&&be(t,e,`local assets: ${T.loaded}/${T.requested} tex\uFF08util ${T.util} / particle ${T.particle}\uFF09 ${(T.bytes/1e6).toFixed(1)}MB ${T.ms}ms source=${T.source} mode=${T.mode}`+(T.failed?` failed=${T.failed}`:""))}for(const T of Bo.SYSTEM_UTIL_TEXTURES){const C=Bo.buildSystemUtilTexture(T);if(!C)continue;const R={wrap:"repeat"};Ke.set(T,Bo.isNomipSystemTexture(T)?{glTex:pt.makeTexture(_.gl,C.rgba,C.width,C.height,null,R),width:C.width,height:C.height,rg88:!1,mips:null}:{glTex:pt.makeTextureMip(_.gl,[C],!1,R),width:C.width,height:C.height,rg88:!1,mips:[C]})}{const T=R=>{const F=We.renderThumbnail(R,512);return{glTex:pt.makeTextureMip(_.gl,[F],!1),width:F.width,height:F.height,rg88:!1,mips:[F],generated:!0}},C=V.tracks||[];C.length&&dn.enabled&&(Ke.set("$mediaThumbnail",T(C[0])),Ke.set("$mediaPreviousThumbnail",T(C[C.length-1])))}const Aa=(T,C,R)=>{const F=KA(T,C,R,512),$=YA(T,C,R),H=_.gl,L=Ke.get("$mediaThumbnail"),X=!!L?.generated;L&&!X&&Ke.set("$mediaPreviousThumbnail",L);const Q=Ke.get("$mediaThumbnail");if(Q?.glTex?(H.bindTexture(H.TEXTURE_2D,Q.glTex),H.texImage2D(H.TEXTURE_2D,0,H.RGBA,F.width,F.height,0,H.RGBA,H.UNSIGNED_BYTE,F.rgba),H.generateMipmap(H.TEXTURE_2D),Q.width=F.width,Q.height=F.height,Q.mips=[F],Q.generated=!1):Ke.set("$mediaThumbnail",{glTex:pt.makeTextureMip(H,[F],!1),width:F.width,height:F.height,rg88:!1,mips:[F],generated:!1}),X){const re=Ke.get("$mediaPreviousThumbnail");re?.glTex&&(H.bindTexture(H.TEXTURE_2D,re.glTex),H.texImage2D(H.TEXTURE_2D,0,H.RGBA,F.width,F.height,0,H.RGBA,H.UNSIGNED_BYTE,F.rgba),H.generateMipmap(H.TEXTURE_2D),re.width=F.width,re.height=F.height,re.mips=[F],re.generated=!1)}return $};if(e.liveSystem){const T={handle:null,dead:!1};(t.wallpaperDisposers??=[]).push(()=>{T.dead=!0;try{T.handle?.dispose()}catch{}T.handle=null});try{const C=async R=>{try{const F=await fetch(R.url,{cache:"no-store"});if(!F.ok)return;const $=await F.blob(),H=await createImageBitmap($,{premultiplyAlpha:"none"}),L=Aa(H,H.width,H.height);H.close?.();const X=he().snapshot;L&&(X.primaryColor=We.mediaVec3(...L.primary),X.secondaryColor=We.mediaVec3(...L.secondary),X.tertiaryColor=We.mediaVec3(...L.tertiary),X.textColor=We.mediaVec3(.98,.98,1),X.highContrastColor=We.mediaVec3(1,1,1)),X.hasThumbnail=!0,W.lastSnap.setHasThumbnail(!1),be(t,e,`liveSystem: artwork ${R.title||R.trackKey}`)}catch(F){be(t,e,`liveSystem: artwork \u5931\u8D25 (${F instanceof Error?F.message:F})`)}};if(U=await np({origin:location.origin,onArtwork:R=>{C(R)}}),T.dead){try{U.dispose()}catch{}U=null}else{if(T.handle=U,Y=U.media,Ae=U.windowTitle,W.mediaDriver=U.media,U.status().audio==="mic"&&(ie.current=U.audio),he().snapshot.hasMedia){for(const{name:F,event:$}of We.diffMediaEvents(null,he().snapshot))for(const H of st)try{H.callMedia(F,$)}catch{}nn=We.cloneMediaSnapshot(he().snapshot)}const R=U.status();be(t,e,`liveSystem: audio=${R.audio} media=${R.media} window=${R.window}`+(R.title?` title="${R.title}"`:"")+(R.hasArtwork?" artwork=1":"")),be(t,e,`audio: ${ie.current?"live mic":"simulated"} stream, supportsaudioprocessing=${I}`),window.__system={media:Cr,windowTitle:Ae.snapshot,shortcuts:nt.last,live:()=>U.status()},window.__liveSystem=()=>U.status()}}catch(C){be(t,e,`liveSystem: \u542F\u52A8\u5931\u8D25\uFF0C\u56DE\u9000\u6A21\u62DF\u6E90 (${C instanceof Error?C.message:C})`),U=null}}{const T=u;u=()=>{T?.(),U?.dispose(),U=null}}const Ci=new Map,Wo=async T=>{if(ni=T,On=!1,Ke.has(T))return Ke.get(T);const C=at.getEntry(g,`materials/${T}.tex`);if(!C){if(await sp(T),en.isBuiltinParticleTextureName(T)){const L=en.buildBuiltinParticleTexture(T);if(L){const X={glTex:pt.makeTextureMip(_.gl,[L],!1),width:L.width,height:L.height,rg88:!1,mips:[L],generated:!0};return Ke.set(T,X),X}}if(!Ke.has(T)&&ou.isBuiltinGradientTextureName(T)){const L=ou.buildBuiltinGradientTexture(T);if(L){const X={glTex:pt.makeTextureMip(_.gl,[L],!1,{wrap:"repeat"}),width:L.width,height:L.height,rg88:!1,mips:[L],generated:!0};return Ke.set(T,X),X}}return null}const R=er.parseTex(C);if(!R.isVideo&&R.images&&R.images.length>1){const L=R.textureWidth||R.width,X=R.textureHeight||R.height;if(L>0&&X>0&&L*X<=4096*4096){const Q=_.gl,re=[];try{for(const q of R.images){const K=q[0];if(!K||K.data===void 0||K.compression!==0)throw new Error("skip");const D=K.width*4,E=new Uint8Array(L*X*4);for(let z=0;z<X;z++)E.set(K.data.subarray(z*D,z*D+L*4),z*L*4);re.push(E)}}catch{re.length=0}if(re.length>1){const q=pt.makeTexture(Q,re[0],L,X,null);let K=0;const D=window.setInterval(()=>{a||t.paused||(K=(K+1)%re.length,Q.bindTexture(Q.TEXTURE_2D,q),Q.texSubImage2D(Q.TEXTURE_2D,0,0,0,L,X,Q.RGBA,Q.UNSIGNED_BYTE,re[K]))},100);(t.wallpaperDisposers??=[]).push(()=>window.clearInterval(D));const E={glTex:q,width:L,height:X,rg88:!1,generated:!0};return E.declaredWidth=R.textureWidth,E.declaredHeight=R.textureHeight,Ke.set(T,E),be(t,e,`tex '${T}': animated multi-image, ${re.length} frames @ ${L}x${X}`),E}}}const F=er.decodeMip0(R),$=R.format===8;let H=null;if(F.video!==void 0){const L=URL.createObjectURL(new Blob([F.video],{type:"video/mp4"})),X=Uu(L,{muted:!0,renderDpr:Vi(t,e),maxW:n.clientWidth||window.innerWidth||1,maxH:n.clientHeight||window.innerHeight||1});for(const E of[X.active,X.standby])E.style.cssText="position:fixed;left:-9999px;top:-9999px;width:2px;height:2px;opacity:0;pointer-events:none",document.body.appendChild(E),(t.videoTextures??=[]).push(E);(t.objectUrls??=[]).push(L),(t.videoPairs??=[]).push(X),X.active.addEventListener("loadedmetadata",()=>{be(t,e,`video tex '${T}': ${X.active.videoWidth}x${X.active.videoHeight}`)}),X.active.addEventListener("error",()=>{be(t,e,`video tex '${T}' ERROR: ${X.active.error?.code}`)});const Q=[],re=E=>{for(const z of Q)E.addEventListener("ended",z)},q={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:E=>{try{X.active.currentTime=E}catch{}},getRate:()=>X.active.playbackRate||1,setRate:E=>{X.active.playbackRate=E,X.standby.playbackRate=E},getLoop:()=>X.active.loop,setLoop:E=>{X.active.loop=E,X.standby.loop=E},addEndedCallback:E=>{Q.push(E),X.active.addEventListener("ended",E)}},K={get video(){return X.active},glTex:pt.makeTexture(_.gl,new Uint8Array([0,0,0,0]),1,1),width:F.width,height:F.height,rg88:!1,lastUploaded:-1,videoCtl:q};let D=0;return X.onSwap=E=>{K.lastUploaded=-1,re(E),D++,(D===1||D===10||D===100)&&be(t,e,`video tex '${T}' loop swap ok x${D}`)},X.onFallback=()=>{be(t,e,`video tex '${T}' loop fallback (native loop used)`)},Ke.set(T,K),K}else if(F.png!==void 0||F.image!==void 0&&F.fif===er.FIF.JPEG){const L=new Blob([F.png||F.image],{type:F.png?"image/png":"image/jpeg"}),X=Math.max(Number(F.width||0),Number(F.height||0))||1,Q=!!R?.frames?.list?.length||Iu(Number(F.width||0),Number(F.height||0));On=Q;const re=Q?X:ri(ws(T),R)||X,q=Math.min(1,re/X),K=await h2(L,F.png?null:F.image,F.width,F.height,q);q<.999&&Ve.scaled.push({name:T,how:"decode-resize",from:`${F.width}x${F.height}`,to:`${K.width}x${K.height}`}),H={glTex:pt.makeTexture(_.gl,null,0,0,K),width:K.width,height:K.height,rg88:$}}else{if(F.image!==void 0)return null;{const L=R?.images?.[0]?.[0],X=!!R?.frames?.list?.length||Iu(Number(L?.width||0),Number(L?.height||0));On=X;const Q=X?1:ws(T),re=ri(Q,R),q=rt(R,re,Q);{const E=ba?pt.compressedFormatFor(_.gl,R?.format):null,z=R?.images?.[0];if(E&&z&&z.length&&!(Number(R?.flags)&64)&&!X){const ee=[];let G=!0;const J=Math.max(1,Math.floor(Number(R?.width||z[0].width)/2**q)),ge=Math.max(1,Math.floor(Number(R?.height||z[0].height)/2**q)),ae=Math.min(z[q].width,Math.ceil(J/4)*4),ue=Math.min(z[q].height,Math.ceil(ge/4)*4);for(let pe=0;pe<z.length-q;pe++){const Ie=z[q+pe],je=Math.max(1,Math.floor(ae/2**pe)),qe=Math.max(1,Math.floor(ue/2**pe));if(je>Ie.width||qe>Ie.height)break;const Tt=je===Ie.width&&qe===Ie.height?Ie.data:er.cropBlocks(Ie.data,Ie.width,je,qe,E.blockBytes);if(Tt.length!==Math.ceil(je/4)*Math.ceil(qe/4)*E.blockBytes){G=!1;break}ee.push({width:je,height:qe,data:Tt})}if(G&&ee.length){const pe=_.gl,Ie=ee[0];H={glTex:pt.makeCompressedTextureMip(pe,ee,E.internalFormat),width:Ie.width,height:Ie.height,rg88:!1,compressed:!0,cpuMips:null,looksAlbedo:!1,packedNormal:!0,mipLevel:q},Ve.compressed+=Ie.width*Ie.height*(R.format===7?.5:1),Ve.scaled.push({name:T,how:`compressed-${R.format}${q?`+mip${q}`:""}`,from:`${L?.width}x${L?.height}`,to:`${Ie.width}x${Ie.height}`})}}}const K=H?null:er.decodeMipLevel(R,q),D=!H&&ya&&Number(R?.format)===9&&!X&&!(Number(R?.flags)&64)&&K!=null&&K.png===void 0&&K.image===void 0&&K.video===void 0;if(!H&&K&&(K.png!==void 0||K.image!==void 0||K.video!==void 0)){const E=er.decodeMip0(R);H={glTex:pt.makeTextureMip(_.gl,[E],$),width:E.width,height:E.height,rg88:$,cpuMips:[E]},Ve.cpuDecoded+=E.rgba.byteLength}else if(!H&&D&&K){const E=K,z=E.width*E.height,ee=new Uint8Array(z);for(let G=0;G<z;G++)ee[G]=E.rgba[G*4];H={glTex:pt.makeR8TextureMip(_.gl,[{width:E.width,height:E.height,data:ee}]),width:E.width,height:E.height,rg88:!1,r8:!0,albedoR8:!0,cpuMips:null,looksAlbedo:!1,packedNormal:!1,mipLevel:q},Ve.r8Native+=z,Ve.scaled.push({name:T,how:`r8${q?`+mip${q}`:""}`,from:`${L?.width}x${L?.height}`,to:`${E.width}x${E.height}`})}else if(!H){const E=K,z=Math.max(E.width,E.height),ee=R.images?.[0]?.length||1,G=Math.max(1,Math.round(E.width*re/z)),J=Math.max(1,Math.round(E.height*re/z));let ge=E,ae=null,ue=q>0?`mip${q}`:"";if(q===0&&ee===1&&re>0&&z>re)if($||Hp(E.rgba)){const Ie=$?null:await va(E,G,J);Ie?(ae=Ie,ge={width:Ie.width,height:Ie.height,rgba:E.rgba},ue="resample-native"):E.width*E.height<=16e6||$?(ge=Mi(E,re),ue="resample"):ue="skip-big-alpha"}else E.width*E.height<=16e6?(ge=Mi(E,re),ue="resample"):ue="skip-big-alpha";const pe=en.rgbaLooksLikeAlbedo(E.rgba);H={glTex:ae?pt.makeTexture(_.gl,null,0,0,ae):pt.makeTextureMip(_.gl,[ge],$),width:ge.width,height:ge.height,rg88:ae?!1:$,cpuMips:pe?[ge]:null,looksAlbedo:pe,packedNormal:en.isPackedNormalTexture(E),mipLevel:q},Ve.cpuDecoded+=E.rgba.byteLength,pe||(Ve.cpuReleased+=E.rgba.byteLength),ue&&Ve.scaled.push({name:T,how:ue,from:`${R.images[0][0].width}x${R.images[0][0].height}`,to:`${ge.width}x${ge.height}`})}}}if(!H)return null;if(H.declaredWidth=R.textureWidth,H.declaredHeight=R.textureHeight,R.frames?.list?.length){const L=R.frames.list;L.atlasWidth=H.width,L.atlasHeight=H.height;const X=L[0];H.geomFrame={width:Math.abs(Number(X?.width??H.declaredWidth??0)),height:Math.abs(Number(X?.height??H.declaredHeight??0))};const Q=Number(L.nativeAtlasWidth)||Number(R.images?.[0]?.[0]?.width||0)||H.width;L.nativeAtlasWidth=Q;const re=Q>0?H.width/Q:1;re<.999&&(zp(L,re),Ve.framesScaled.push(`${T} x${re.toFixed(3)}`)),H.frames=L}if(H.looksAlbedo===void 0&&H.glTex){const L=H.cpuMips&&H.cpuMips[0];H.looksAlbedo=L?.rgba?en.rgbaLooksLikeAlbedo(L.rgba):!1,H.packedNormal===void 0&&(H.packedNormal=L?.rgba?en.isPackedNormalTexture(L):!1),!H.looksAlbedo&&H.cpuMips&&(Ve.cpuReleased+=L?.rgba?L.rgba.byteLength:0,H.cpuMips=null)}H.resourceScale=ws(T),Ve.texCount++;{const L=Number(R?.format),X=H.compressed?L===7||L===3?.5:1:H.r8?1:H.rg88?2:4;Ve.gpuUploaded+=Math.round(H.width*H.height*X*(4/3))}return Ve.textures.push({name:T,size:`${H.width}x${H.height}`,scale:H.resourceScale,level:H.mipLevel??0,native:wa(R),need:Math.round(Oe.get(T)||0),target:ri(H.resourceScale,R)}),Ke.set(T,H),be(t,e,`tex '${T}': ${H.width}x${H.height} declared=${H.declaredWidth}x${H.declaredHeight} R=${H.resourceScale} lvl=${H.mipLevel??0} frames=${Array.isArray(H.frames)?H.frames.length:"none"} video=${!!H.videoCtl}`),H},zn=T=>{if(Ke.has(T))return Promise.resolve(Ke.get(T));const C=Ci.get(T);if(C)return C;const R=Wo(T);return Ci.set(T,R),R.finally(()=>{Ci.get(T)===R&&Ci.delete(T)}),R},Ii=/uniform\s+sampler2D\s+g_Texture\d+\s*;\s*\/\/[^\n]*"default"\s*:\s*"([^"]+)"/g,vs=async T=>{for(const C of T.materialPasses||[])if(C.shader)for(const R of["frag","vert"]){const F=at.getEntry(g,`shaders/${C.shader}.${R}`);if(!F)continue;const $=jt(F);Ii.lastIndex=0;let H;for(;(H=Ii.exec($))!==null;){const L=H[1];!L||L.startsWith("util/")||L.startsWith("_rt_")||Ke.has(L)||await zn(L)}}};window.__memStats=()=>({resourceScale:Ir,resourceScaleNormal:Rr,texCount:Ve.texCount,cpuDecodedMB:+(Ve.cpuDecoded/1e6).toFixed(1),cpuReleasedMB:+(Ve.cpuReleased/1e6).toFixed(1),gpuUploadedMB:+(Ve.gpuUploaded/1e6).toFixed(1),compressedMB:+(Ve.compressed/1e6).toFixed(1),r8NativeMB:+(Ve.r8Native/1e6).toFixed(1),pkgBytes:Ve.pkgBytes||0,framesScaled:Ve.framesScaled.slice(0,20),scaledCount:Ve.scaled.length,scaled:Ve.scaled.slice(0,40),textures:Ve.textures.slice(0,60)});let xa=0;const rr=[];for(let T=0;T<b.layers.length;T++){const C=b.layers[T];if(C.image)try{let R;if(An.BUILTIN_MODELS[C.image])R=An.BUILTIN_MODELS[C.image];else{const K=at.getEntry(g,C.image);if(!K)continue;R=JSON.parse(jt(K))}zt.applySolidFromModel(C,R);const F=C.srcObject?.instance?.usertextures,$=F?.[0]&&typeof F[0].name=="string"&&F[0].name.startsWith("$")?F[0].name:null,H=$&&Ke.has($)?$:null;if(H&&(C.textureName=H,C.solid=!1),R&&typeof R=="object"&&"width"in R&&"height"in R){const K=R;(C.size?.[0]||0)===0&&(C.size?.[1]||0)===0&&K.width>0&&K.height>0&&(C.size=[K.width,K.height])}const L=zt.resolveMaterial(R);if(!L)continue;let X;if(An.BUILTIN_MATERIALS[L.materialPath])X=An.BUILTIN_MATERIALS[L.materialPath];else{const K=at.getEntry(g,L.materialPath);if(K)X=JSON.parse(jt(K));else if(C.solid&&An.BUILTIN_MATERIALS["materials/util/solidlayer.json"])X=An.BUILTIN_MATERIALS["materials/util/solidlayer.json"];else continue}const Q=X.passes?.[0],re=Q?.textures||[],q=re[0];if(C.materialBlending=typeof Q?.blending=="string"?Q.blending:null,Q?.combos)for(const K of Object.keys(Q.combos)){const D=K.toLowerCase();D==="spritesheet"&&Number(Q.combos[K])===1&&(C.spriteSheet=!0),D==="lighting"&&Number(Q.combos[K])===1&&(C.lightingEnabled=!0)}for(let K=0;K<re.length;K++){const D=re[K];typeof D!="string"||!D||D.startsWith("util/")||D.startsWith("_rt_")||rr.push(zn(D).then(E=>{if(E&&K===0&&!H&&(C.textureName=D,xa++,E.videoCtl&&(C.videoCtl=E.videoCtl),be(t,e,`autosize gate: model.autosize=${R?.autosize} size=${C.size?.[0]}x${C.size?.[1]}`),R?.autosize&&C.size&&(C.size[0]===0||C.size[1]===0))){const z=Array.isArray(E.frames)&&E.frames.length?E.frames[0]:null,ee=Math.abs(Number(z?.width??0)),G=Math.abs(Number(z?.height??0)),J=Math.abs(Number(E.geomFrame?.width||0)),ge=Math.abs(Number(E.geomFrame?.height||0)),ae=J>0?J:ee>0?ee:Number(E.declaredWidth||0),ue=ge>0?ge:G>0?G:Number(E.declaredHeight||0);ae>0&&ue>0?(C.size=[ae,ue],be(t,e,`autosize applied: layer.size=${ae}x${ue}`)):be(t,e,`autosize skipped: fw=${ee} fh=${G} declared=${E.declaredWidth}x${E.declaredHeight}`)}}))}Q?.shader&&at.getEntry(g,`shaders/${Q.shader}.frag`)&&An.attachLayerMaterialEffect(C,Q);for(const K of C.effects||[])An.resolveEffectChain(g,K,jt);for(const K of C.effects||[]){for(const D of K.passes||[]){for(const E of D.textures||[])typeof E=="string"&&E!==""&&!E.startsWith("util/")&&!E.startsWith("_rt_")&&rr.push(zn(E));for(const E of D.textureFallbacks||[])typeof E=="string"&&E!==""&&!E.startsWith("util/")&&!E.startsWith("_rt_")&&rr.push(zn(E))}rr.push(vs(K))}}catch(R){console.warn(`\u56FE\u5C42 ${C.name||T} \u52A0\u8F7D\u5931\u8D25: ${R.message}`)}}if(!Jm){for(const T of b.layers)if(!(!T.isText||!(T.effects||[]).length))try{for(const C of T.effects||[])An.resolveEffectChain(g,C,jt);for(const C of T.effects||[])for(const R of C.passes||[])for(const F of R.textures||[])typeof F=="string"&&F!==""&&!F.startsWith("util/")&&!F.startsWith("_rt_")&&rr.push(zn(F))}catch(C){console.warn(`\u6587\u5B57\u5C42\u6548\u679C ${T.name} \u89E3\u6790\u5931\u8D25: ${C.message}`)}}await Promise.all(rr);{const C=(b.general??(b.general={})).orthogonalprojection??null,R=Number(C?.width)>0&&Number(C?.height)>0;if(C){const F=Go(b.layers);be(t,e,`auto ortho probe: auto=${C.auto} explicit=${R} bounds=${Math.round(F.minX)},${Math.round(F.minY)}..${Math.round(F.maxX)},${Math.round(F.maxY)} sizes=${b.layers.map($=>`${$.size?.[0]}x${$.size?.[1]}`).join("|")}`)}if(C&&C.auto===!0&&!R){const F=Go(b.layers),$=F.maxX-F.minX,H=F.maxY-F.minY;Math.abs(F.minX)<.5&&Math.abs(F.minY)<.5&&Number.isFinite($)&&Number.isFinite(H)&&$>0&&H>0&&(C.width=$,C.height=H,be(t,e,`auto ortho: content ${Math.round($)}x${Math.round(H)}\uFF08orthogonalprojection.auto\uFF09`))}}be(t,e,`resources R=${Ir}${Rr!==Ir?` (normal R=${Rr})`:""} tex=${Ve.texCount} gpu\u2248${(Ve.gpuUploaded/1e6).toFixed(1)}MB cpuDecoded=${(Ve.cpuDecoded/1e6).toFixed(1)}MB released=${(Ve.cpuReleased/1e6).toFixed(1)}MB scaled=${Ve.scaled.length}`+(Ve.scaled.length?` \u4F8B: ${Ve.scaled.slice(0,3).map(T=>`${T.name}(${T.how} ${T.from}\u2192${T.to})`).join(" ")}`:"")+(Ve.framesScaled.length?` \u5E27\u56FE\u96C6\u7F29\u653E: ${Ve.framesScaled.slice(0,3).join(" ")}`:""));for(const[T,C]of Ke){if(!C?.videoCtl)continue;b.layers.some(F=>F.textureName===T&&F.visible&&!F.destroyed)&&!t.paused&&C.videoCtl.play()}const Ct=[],As=[],Hn=new Map;let ka=0;const ir=async(T,C="albedo")=>{const R=at.getEntry(g,`materials/${T}.tex`)?await zn(T):null;if(R)return R;await sp(T);let F=en.buildBuiltinParticleTexture(T);if(!F)return null;F=C==="normal"?en.convertParticleNormalFormat(F,F.format):en.convertParticleTexFormat(F,F.format);const $={glTex:pt.makeTextureMip(_.gl,[F],!1),width:F.width,height:F.height,rg88:!1,mips:[F],generated:!0,frames:F.frames&&F.frames.length?F.frames:en.builtinParticleFrames(T)??void 0};return Ke.set(T,$),ka++,$},Ta=T=>{if(!T)return null;if(T.looksAlbedo===!1)return T;const C=T.cpuMips&&T.cpuMips[0]||T.mips&&T.mips[0];if(C?.rgba&&typeof en.prepareParticleNormalTexture=="function"){const R=en.prepareParticleNormalTexture(C);if(R&&R!==C)return{glTex:pt.makeTextureMip(_.gl,[R],!1),width:R.width,height:R.height,rg88:!1,mips:[R],generated:!0}}return T},Ri=async(T,C,R,F)=>{if(F>3)return null;const $=at.getEntry(g,T);if(!$)return be(t,e,`particle '${T}' \u4E0D\u5728 pkg\uFF0C\u8DF3\u8FC7`),null;const H=JSON.parse(jt($)),L=new Ti.ParticleSystem(_.gl,H,R,C);let X=null,Q=null;if(H.material){const D=at.getEntry(g,H.material);if(D){const E=JSON.parse(jt(D));L.setMaterial(E);const z=E?.passes?.[0]?.textures||[];X=z[0]||null,Q=z[1]||null}}const re=await ir(X||"particle/halo");if(!re)return be(t,e,`particle '${T}' \u65E0\u8D34\u56FE\u53EF\u7528\uFF0C\u8DF3\u8FC7`),null;L.setTexture({glTex:re.glTex,width:re.width,height:re.height,frames:re.frames});const q=Q||(L.refract?en.particleNormalNameForAlbedo(X||"particle/halo"):null);if(q){const D=Ta(await ir(q,"normal"));D&&(D.packed=D.packedNormal===!0,L.setNormalTexture({glTex:D.glTex,width:D.width,height:D.height,packed:!!D.packed}))}L.setVisible(!!C.visible),Ct.push(L);const K=C.id;if(K!==void 0){let D=Hn.get(K);D||(D=[],Hn.set(K,D)),D.push(L)}for(const D of H.children||[]){if(!D||typeof D.name!="string")continue;const E=String(D.origin??"0 0 0").trim().split(/\s+/).map(Number),z=String(D.scale??"1 1 1").trim().split(/\s+/).map(Number),ee=String(D.angles??"0 0 0").trim().split(/\s+/).map(Number),G=D.type==="eventfollow"?"particle":!D.type||D.type==="static"?"origin":null,J=L.localToWorld(E[0]||0,E[1]||0),ge={...C,origin:[J[0],J[1],(C.origin?.[2]||0)+(E[2]||0)],scale:[(C.scale?.[0]??1)*(z[0]||1),(C.scale?.[1]??1)*(z[1]||1),(C.scale?.[2]??1)*(z[2]||1)],angles:[(C.angles?.[0]||0)+(ee[0]||0),(C.angles?.[1]||0)+(ee[1]||0),(C.angles?.[2]||0)+(ee[2]||0)]},ae=await Ri(D.name,ge,D.instanceoverride||R,F+1);ae&&G?ae.attachFollow(L,G,[E[0]||0,E[1]||0,E[2]||0]):ae&&(D.type==="eventdeath"||D.type==="eventspawn")&&ae.attachEventParent(L,D.type,[E[0]||0,E[1]||0,E[2]||0])}return L};if(!LA){for(const T of b.layers)if(T.particle)try{await Ri(T.particle,T,T.instanceoverride,0)}catch(C){console.warn(`\u7C92\u5B50\u56FE\u5C42 ${T.name} \u52A0\u8F7D\u5931\u8D25: ${C.message}`),be(t,e,`particle '${T.name}' FAIL: ${C.message.slice(0,80)}`)}}if(Ct.length>0){const T=u;u=()=>{T?.();for(const C of Ct)C.dispose()}}const Br=[],Gt=t2();Gt.setVolume(Jo(t,e));const rn=()=>Gt.dispose();for(const T of b.layers)if(!(!T.sound||!T.sound.length))try{for(const C of T.sound){const R=at.getEntry(g,C);if(!R)continue;const F=(C.split(".").pop()||"").toLowerCase(),$=F==="mp3"?"audio/mpeg":F==="ogg"?"audio/ogg":F==="flac"?"audio/flac":"audio/wav",H=new Blob([R],{type:$}),L=URL.createObjectURL(H);(t.objectUrls??=[]).push(L);const X=document.createElement("audio");X.src=L,X.loop=T.soundprops?.playbackmode==="loop",X.volume=Math.max(0,Math.min(1,T.soundprops?.volume??1)),X.muted=e.muted!==!1,Gt.attach(X),T.soundCtl={play(){if(X.ended)try{X.currentTime=0}catch{}Gt.resume(),X.play().catch(()=>{}),we.markPlayed(X)},pause(){X.pause()},stop(){X.pause();try{X.currentTime=0}catch{}we.markStopped(X)},isPlaying:()=>!X.paused&&!X.ended,getVolume:()=>X.volume,setVolume:Q=>{X.volume=Math.max(0,Math.min(1,Q))}},we.register(X,T.name||""),!T.soundprops?.startsilent&&!t.paused&&(Gt.resume(),X.play().catch(()=>{})),Br.push(X);break}}catch(C){console.warn(`\u58F0\u97F3\u56FE\u5C42 ${T.name} \u52A0\u8F7D\u5931\u8D25: ${C.message}`)}const Ze=T=>{const C=Math.max(0,Math.min(1,T));for(const R of Br)Gt.routes(R)?(R.volume=1,R.muted=C<=0):(R.volume=C,R.muted=C<=0);Gt.setVolume(C)};if(t.sceneAudio={setVolume:Ze,audios:Br,dispose:rn},Ru(t),a)return;const Tn={dt:1/60,t:0};let Bi=0,Vn=!1;_.setParticleRenderer(()=>{if(Vn)return;const T=Math.min(.05,Math.max(0,Tn.dt));if(lt.state.has){const{wx:C,wy:R,originY:F}=lt.state,$=F??R;for(const H of Ct)H.setPointer(C,$)}if(As.length)for(const C of As)C.syncLayerTransform();for(const C of Ct)C.layer&&C.layer.runtimeCreated&&C.syncLayerTransform();{const C=_.getParallaxOffset?_.getParallaxOffset():null;for(const R of Ct)if(!C||!C.active||!R.layer||!R.layer.parallaxDepth)R.setParallaxOffset(0,0);else{const F=Ko(R.layer,C);R.setParallaxOffset(F[0],F[1])}}for(const C of Ct)C.advance(T,Pe.enabled?De():null);if(Bi<2&&(Bi++,Bi===2)){const C=Ct.reduce((R,F)=>R+F.liveCount(),0);be(t,e,`particles live: ${C} across ${Ct.length} systems`)}},(T,C,R,F,$)=>{if(Vn||T===void 0)return;const H=Hn.get(T);if(H)for(const L of H)L.render(R,F,$,C.projW,C.projH)});const Wn=T=>{_.setAntiAliasing?.(T.antiAliasing),_.setEffectsEnabled?.(T.postProcessing!=="off"),_.setFboCapFactor?.(qA(T.postProcessing)),Vn=T.particles==="off",Ti.setParticleQualityScale?.(jA(T.particles)),Ti.setParticleDensityTier?.(T.particles==="off"?"high":T.particles);for(const C of Ct)C._applyOverride?.();be(t,e,`quality: aa=${T.antiAliasing} particles=${T.particles} post=${T.postProcessing}`)};p=Wn,Wn(fa(e.quality)),be(t,e,`particles: ${Ct.length} systems, ${ka} builtin tex generated`),window.__particleStats=()=>({t:Tn.t,systems:Ct.map(T=>{let C=0,R=1/0,F=-1/0,$=1/0,H=-1/0,L=1/0,X=-1/0,Q=0;for(const re of T.pool){if(!re.alive)continue;C++,(re.frameMix||0)>Q&&(Q=re.frameMix);const q=T.originX+re.x*T.scaleX,K=T.originY+re.y*T.scaleY;q<R&&(R=q),q>F&&(F=q),K<$&&($=K),K>H&&(H=K);const D=Math.abs(re.size)*T.sysScale;D<L&&(L=D),D>X&&(X=D)}return{layer:T.layer&&T.layer.name,opacityMul:Math.round(T.opacityMul*1e4)/1e4,live:C,max:T.maxCount,blend:T.blend,renderer:T.renderers.map(re=>re.kind).join("+"),origin:[Math.round(T.originX),Math.round(T.originY)],bbox:C?[Math.round(R),Math.round($),Math.round(F),Math.round(H)]:null,size:C?[Math.round(L),Math.round(X)]:null,frameCount:T.frameCount,frameMixMax:Math.round(Q*1e3)/1e3,refract:!!T.refract,refractAmount:Math.round((Number.isFinite(T.refractAmount)?T.refractAmount:.05)*1e3)/1e3}})}),window.__particleToggle=(T,C)=>{for(let R=0;R<Ct.length;R++)Ct[R].setVisible(C===void 0?T:R===C);return Ct.length};const It=[],Fr=new Map,ii=new Map,sn=T=>{if(!T||!T.puppet)return null;let C=ii.get(T);return C||(C=new Map,ii.set(T,C)),C};for(const T of b.layers)if(T.image)try{if(An.BUILTIN_MODELS[T.image])continue;const C=at.getEntry(g,T.image);if(!C)continue;const R=JSON.parse(jt(C));if(!R.puppet)continue;const F=at.getEntry(g,R.puppet);if(!F)continue;const $=la.parseMDL(new Uint8Array(F)),H=T.textureName?Ke.get(T.textureName):null;if(!H){be(t,e,`puppet '${T.name}' \u65E0\u8D34\u56FE\uFF0C\u8DF3\u8FC7`);continue}T.puppet=$,It.push({mdl:$,tex:H,layer:T});const L=$.animations[0];be(t,e,`puppet '${T.name}' v=${$.vertexCount} bones=${$.bones.length}`+(L?` anim='${L.name}' ${L.fps}fps\xD7${L.frameCount}`:" \u65E0\u52A8\u753B"))}catch(C){console.warn(`puppet \u56FE\u5C42 ${T.name} \u52A0\u8F7D\u5931\u8D25: ${C.message}`),be(t,e,`puppet '${T.name}' \u5931\u8D25: ${C.message}`)}for(const T of b.layers)if(T.model&&!T.puppet)try{const C=at.getEntry(g,T.model);if(!C)continue;const R=la.parseMDL(new Uint8Array(C));let F=null;if(R.materialPath){const H=at.getEntry(g,R.materialPath);if(H){const X=JSON.parse(jt(H))?.passes?.[0],Q=X?.textures?.[0];typeof Q=="string"&&Q&&(F=Q);const re=X?.combos?.LIGHTING??X?.combos?.lighting;Number(re)===1&&(T.lightingEnabled=!0)}}if(F)try{await zn(F),T.textureName=F}catch(H){be(t,e,`model '${T.name}' \u7684\u8D34\u56FE '${F}' \u52A0\u8F7D\u5931\u8D25\uFF0C\u8DF3\u8FC7\u8BE5\u5C42\uFF1A${H?.message}`)}const $=F?Ke.get(F):null;if(!$){be(t,e,`model '${T.name}' \u65E0\u8D34\u56FE\uFF0C\u8DF3\u8FC7`);continue}T.puppet=R,It.push({mdl:R,tex:$,layer:T}),be(t,e,`model '${T.name}' v=${R.vertexCount} static ${R.materialPath||""}`)}catch(C){console.warn(`model \u56FE\u5C42 ${T.name} \u52A0\u8F7D\u5931\u8D25: ${C.message}`),be(t,e,`model '${T.name}' \u5931\u8D25: ${C.message}`)}let Fi=null;if(It.length>0)try{Fi=la.createMDLRenderer(_.gl);for(const C of It)Fi.upload(C.mdl);const T=new Map;for(const C of It)T.set(C.layer,C);_.setPuppetRenderer((C,R,F)=>{const $=T.get(C);$&&Fi.draw(R,$.mdl,{time:F.time,animLayers:C.animationLayers,boneOverrides:ii.get(C),overrideTex:F.overrideTex||null,keepZ:!!F.keepZ,color:[C.color[0]*C.brightness*(F.ambient?.[0]??1),C.color[1]*C.brightness*(F.ambient?.[1]??1),C.color[2]*C.brightness*(F.ambient?.[2]??1),C.alpha]},$.tex)})}catch(T){console.warn(`puppet \u6E32\u67D3\u5668\u521D\u59CB\u5316\u5931\u8D25: ${T.message}`),be(t,e,`puppet renderer \u5931\u8D25: ${T.message}`),Fi=null;for(const C of It)C.layer.puppet=null}if(a)return;be(t,e,`puppet: ${It.length} meshes`);const mn=la.applyAttachmentBindOrigins(b.layers);mn.length&&be(t,e,`attachments: ${mn.length} hanging layers`);const jn=zt.collectTransformDirty(b.layers,mn.map(T=>T.layer));if(jn.size){be(t,e,`transform graph: ${jn.size} live layers`);for(const[T,C]of Hn)if(jn.has(T))for(const R of C)As.push(R)}const Sn=[],Sa=[],Di=new Map,pn={};let Pn=null,sr=null,Ni=0;if(!Jm&&b.layers.some(T=>T.isText)){const T=b.general?.orthogonalprojection,C=T?.width||n.width,R=T?.height||n.height,F=Qo(Ur(t.cfg.fit),C,R,n.width,n.height),$=Math.min(3,Math.max(.5,n.width/Math.max(1,F.viewW))),H=new Map,L=[],X=new Set;for(const q of b.layers)q.isText&&q.textFont&&X.add(q.textFont);for(const q of g.entries||[])typeof q.name=="string"&&/^fonts\/.+\.(ttf|otf|woff2?)$/i.test(q.name)&&X.add(q.name);for(const q of X){const K=`${e.src}|${q}`,D=Uo.get(K);if(D){D.refs++,L.push(K),H.set(q,D.family);continue}const E=p2[q.toLowerCase()];if(E){H.set(q,E);continue}try{const z=at.getEntry(g,q),ee=z?z instanceof Uint8Array?z:new Uint8Array(z):await c2(q);if(!ee)continue;const G=u2(ee),J="wefont_"+b2(K)+"_"+q.split("/").pop().replace(/[^a-zA-Z0-9]/g,"_"),ge=URL.createObjectURL(new Blob([G])),ae=new FontFace(J,`url(${ge})`);if(await ae.load(),a){URL.revokeObjectURL(ge);break}document.fonts.add(ae),(t.objectUrls??=[]).push(ge),H.set(q,J),Uo.set(K,{family:J,refs:1}),L.push(K)}catch(z){console.warn(`\u5B57\u4F53\u52A0\u8F7D\u5931\u8D25 ${q}: ${z.message}`)}}if(L.length){const q=t.sceneCleanup;t.sceneCleanup=()=>{w2(L),q?.()}}Pn=document.createElement("canvas"),sr=Pn.getContext("2d");const Q=2048;for(const q of b.layers)if(q.isText)try{const K={layer:q,sandbox:null,texName:"__wstext_"+q.id,entry:null,lastKey:null,quality:$};if(q.textScript&&(K.sandbox=ot.evalTextScript(q.textScript,q.textScriptProps,{text:q.text??"",font:q.textFont||"",pointsize:q.textPointsize,color:q.textColor,angles:q.angles,origin:q.origin,scale:q.scale,visible:q.visible,canvasSize:{width:C,height:R},timeOfDay:xt,userProperties:v,shared:pn,storage:S,audioViews:Fe,inputView:Un,...nr,mediaControl:Cr,windowTitle:Ae.snapshot,openUserShortcut:nt.openUserShortcut,getLayerText:ee=>Di.get(ee),onError:ee=>{be(t,e,`text script '${q.name}' \u5931\u8D25: ${String(ee.message||ee).slice(0,120)}`)}}),K.sandbox&&(P.push(K.sandbox),Sa.push({sandbox:K.sandbox,layer:q}),K.sandbox.hasMediaHook&&tr(K.sandbox),Mt(K.sandbox),K.sandbox.hasAnimEventHook&&Ye(q,{sandbox:K.sandbox,kind:"text"}))),Di.set(q.name||"",String(q.text??"")),q.textAnchor!=="center"&&q.size[0]>0&&q.size[1]>0){const ee=q.size[0]*(q.scale[0]||1)/2,G=q.size[1]*(q.scale[1]||1)/2,J=q.textAnchor;let ge=0,ae=0;J.includes("left")&&(ge+=ee),J.includes("right")&&(ge-=ee),J.includes("top")&&(ae-=G),J.includes("bottom")&&(ae+=G),q.origin[0]+=ge,q.origin[1]+=ae,q.localOrigin&&(q.localOrigin[0]+=ge,q.localOrigin[1]+=ae)}const D=ep*Math.max(1,q.textPointsize),E=ot.textLayerHasTintMask(q)?8:256,z=Math.min(E,ot.textCanvasMargin(D,0));K.boxW=q.size[0]>0?q.size[0]:D*4,K.boxH=q.size[1]>0?q.size[1]:D*1.6,K.margin=z,q.size=[K.boxW+z*2,K.boxH+z*2],K.entry={glTex:pt.makeTexture(_.gl,new Uint8Array([0,0,0,0]),1,1),width:1,height:1,rg88:!1},Ke.set(K.texName,K.entry),q.textureName=K.texName,q.solid=!1,Sn.push(K)}catch(K){console.warn(`\u6587\u5B57\u5BF9\u8C61 ${q.name} \u521D\u59CB\u5316\u5931\u8D25: ${K.message}`)}if(Sn.length>0){const q=u;u=()=>{q?.();for(const K of Sn)_.gl.deleteTexture(K.entry.glTex)}}const re=q=>{if(!sr||!Pn)return;const K=sr;for(const D of Sn){const E=D.layer;let z=String(E.text??"");if(D.sandbox&&D.sandbox.hasUpdate){D.sandbox.engine.runtime=q,D.sandbox.engine.timeOfDay=xt;const ge=D.sandbox.callUpdate(z);ge!=null?z=String(ge):D.sandbox.thisLayer.text&&(z=String(D.sandbox.thisLayer.text))}else D.sandbox&&typeof D.sandbox.thisLayer?.text=="string"&&(z=String(D.sandbox.thisLayer.text));if(Di.set(E.name||"",z),!E.visible)continue;const ee=Math.max(1,D.sandbox?D.sandbox.thisLayer.pointsize:E.textPointsize),G=D.sandbox&&D.sandbox.thisLayer.font||E.textFont||"",J=`${z}\0${ee}\0${G}\0${E.alpha}\0${E.textCastshadow}\0${E.textMaxwidth||0}\0${E.limitwidth?1:0}\0${E.maxrows||0}\0${E.limitrows?1:0}`;if(D.lastKey!==J){D.lastKey=J;try{const ge=ep*ee,ae=D.boxW,ue=D.boxH,pe=Math.abs(E.scale[0]||1),Ie=Math.abs(E.scale[1]||1),je=G&&H.get(G)||"sans-serif";K.setTransform(1,0,0,1,0,0),K.font=`${ge}px "${je}", sans-serif`;const qe=K.measureText(""),Tt=(qe.fontBoundingBoxAscent||0)+(qe.fontBoundingBoxDescent||0),bt=E.textSpacing||[0,0],wt=ot.layoutText(z,{boxW:ae,boxH:ue,pointsize:ge,lineHeight:(Tt>0?Tt:ge*1.25)+bt[1],spacing:bt,padding:E.textPadding||0,maxwidth:E.textMaxwidth||0,limitwidth:!!E.textLimitwidth,maxrows:E.textMaxrows||0,limitrows:!!E.textLimitrows,limituseellipsis:!!E.textLimituseellipsis,halign:E.textHAlign,valign:E.textVAlign},an=>K.measureText(an).width);let En=D.margin;const yn=!E.textAnchor||E.textAnchor==="center"||E.textAnchor==="none";if(D.sandbox?.hasMediaHook&&!ot.textLayerHasTintMask(E)&&yn){const an=ot.textCanvasMarginGrow(wt,ae,ue,En);(ot.shouldGrowMediaPlaceholder(ae,ue,!0)||an>En)&&(E.size[0]=ae+an*2,E.size[1]=ue+an*2),an!==En&&(D.margin=an,En=an)}let ut=Math.max(1,Math.round(E.size[0]*pe*D.quality)),Qt=Math.max(1,Math.round(E.size[1]*Ie*D.quality));const zi=Math.min(1,Q/Math.max(ut,Qt));ut=Math.max(1,Math.round(ut*zi)),Qt=Math.max(1,Math.round(Qt*zi)),Pn.width!==ut||Pn.height!==Qt?(Pn.width=ut,Pn.height=Qt):K.clearRect(0,0,ut,Qt);const qo=`${ge}px "${je}", sans-serif`,_a=Math.min(ut/E.size[0],Qt/E.size[1]);K.setTransform(_a,0,0,_a,0,0),K.translate(En,En),ot.drawTextLayer(K,wt,{font:qo,color:E.textColor,alpha:E.alpha,brightness:E.brightness,spacing:bt,pointsize:ge,opaquebackground:!!E.textOpaquebackground,backgroundcolor:E.textBackgroundcolor,backgroundbrightness:E.textBackgroundbrightness,castshadow:!!E.textCastshadow});const ks=D.entry;_.gl.bindTexture(_.gl.TEXTURE_2D,ks.glTex),_.gl.texImage2D(_.gl.TEXTURE_2D,0,_.gl.RGBA,_.gl.RGBA,_.gl.UNSIGNED_BYTE,Pn),ks.width=ut,ks.height=Qt}catch(ge){console.warn(`\u6587\u5B57\u5BF9\u8C61 ${E.name} \u7ED8\u5236\u5931\u8D25: ${ge.message}`),D.lastKey=null}}}};t.sceneTextUpdate=re,window.__textWidgets=Sn,be(t,e,`text widgets: ${Sn.length} (scripts ${Sn.filter(q=>q.sandbox).length}, fonts ${H.size}, quality ${$.toFixed(2)})`)}if(a)return;const it=[],gn=new Set,si=[],ar=[],ai=[],Li=[],oi=[],Ui={},or=[],_n=[],ci=new Map,xs=(T,C)=>{if(!C||typeof C.callCursor!="function"||!C.hasCursorHook)return;const R=ci.get(T);R?R.push(C):ci.set(T,[C])};for(const T of Sn)T.sandbox&&xs(T.layer,T.sandbox);{const T=b.general?.orthogonalprojection,C=T?.width||n.width,R=T?.height||n.height,F=v,$=(D,E)=>{const z=b.general||{};if(D==="zoom"&&typeof E=="number"&&Number.isFinite(E)&&E>0){b.cameraTransforms.zoom=E,z.zoom&&typeof z.zoom=="object"?z.zoom.value=E:z.zoom=E;return}z[D]&&typeof z[D]=="object"&&"value"in z[D]?z[D].value=E:z[D]=E};let H=1+Math.max(0,...b.layers.map(D=>Number(D.id)||0));const L={recomputeVisibility:x,markTransformDirty:D=>{D&&D.id!==void 0&&D.id!==null&&gn.add(D.id)},getSceneLayer:D=>b.layers.find(E=>E.name===D&&!E.destroyed)||null,getSceneLayerById:D=>b.layers.find(E=>E.id===D&&!E.destroyed)||null,enumerateSceneLayers:()=>b.layers.filter(D=>!D.destroyed),getSceneAnimation:D=>{if(D==null||D==="")return null;if(Ui[D])return Ui[D];for(const E of b.layers)if(E.animations&&E.animations[D])return E.animations[D];return null},cameraTransforms:b.cameraTransforms,getInitialLayerConfig:D=>{const E=D&&typeof D=="object"?D.name:String(D||"");return b.layers.find(z=>z.name===E)||null},createSceneLayer:D=>{let E=D&&typeof D=="object"?D:null,z=null;if(typeof D=="string"){const G=D;if(E=b.layers.find(J=>J&&!J.destroyed&&J.image===G&&J.textureName)||b.layers.find(J=>J&&!J.destroyed&&J.image===G)||null,!E)if(/^models\//.test(G)&&at.getEntry(g,G))z={path:G,kind:"model"},E={image:G,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(G)&&at.getEntry(g,G))z={path:G,kind:"particle"},E={particle:G,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 be(t,e,`createLayer('${G}') \u627E\u4E0D\u5230\u5DF2\u52A0\u8F7D\u7684\u540C\u6A21\u578B\u5C42`),null}E||(E={});const ee={...E,id:H++,origin:Array.isArray(E.origin)?E.origin.slice():[0,0,0],scale:Array.isArray(E.scale)?E.scale.slice():[1,1,1],angles:Array.isArray(E.angles)?E.angles.slice():[0,0,0],size:Array.isArray(E.size)?E.size.slice():[0,0],color:Array.isArray(E.color)?E.color.slice():[1,1,1],childIds:null,hasChildren:!1,destroyed:!1,animations:{},animationList:[],objectScripts:null};if(delete ee.textureAnimation,delete ee.videoTextureApi,delete ee.soundCtl,delete ee.videoCtl,Array.isArray(E.effects)&&(ee.effects=E.effects.map(G=>({...G,passes:Array.isArray(G.passes)?G.passes.map(J=>({...J})):G.passes}))),b.layers.push(ee),ee.runtimeCreated=!0,z&&z.kind==="model"){const G=z.path;try{const J=JSON.parse(jt(at.getEntry(g,G))),ge=zt.resolveMaterial(J),ae=ge&&at.getEntry(g,ge.materialPath),pe=(ae?JSON.parse(jt(ae)):null)?.passes?.[0];if(pe?.combos){for(const je of Object.keys(pe.combos))if(je.toLowerCase()==="spritesheet"&&Number(pe.combos[je])===1){ee.spriteSheet=!0;break}}const Ie=pe?.textures?.[0];typeof Ie=="string"&&Ie&&!Ie.startsWith("util/")&&!Ie.startsWith("_rt_")&&zn(Ie).then(je=>{if(je&&(ee.textureName=Ie,ee.size[0]===0||ee.size[1]===0)){const qe=je.geomFrame,Tt=je.frames&&Array.isArray(je.frames)?je.frames[0]:null;ee.size=[qe&&qe.width||Tt&&Tt.width||je.declaredWidth||je.width,qe&&qe.height||Tt&&Tt.height||je.declaredHeight||je.height]}})}catch(J){be(t,e,`createLayer('${G}') \u8D44\u4EA7\u5B9E\u4F8B\u5316\u5931\u8D25: ${String(J.message||J).slice(0,120)}`)}}else if(z&&z.kind==="particle"){const G=z.path;Ri(G,ee,null,0).then(J=>{J||be(t,e,`createLayer('${G}') \u7C92\u5B50\u7CFB\u7EDF\u88C5\u914D\u5931\u8D25`)})}return ee},mediaControl:Cr,windowTitle:Ae.snapshot,openUserShortcut:nt.openUserShortcut,isScreensaver:!1};_.setConstantScriptRuntime?.(ot.evalObjectScript,{userProperties:F,audioViews:Fe,shared:pn,storage:S,inputView:Un,timers:kn,animEventQueue:$e,...L,onSandbox:(D,E)=>{D&&D.hasMediaHook&&tr(D),Mt(D),D&&D.hasAnimEventHook&&Ye(E&&E.layer,{sandbox:D,kind:"const"})}});const X={origin:"localOrigin",scale:"localScale",angles:"localAngles"},Q=(D,E)=>{const z=X[E];return z&&D&&Array.isArray(D[z])?z:E};for(const D of b.layers){const E=D.objectAnimations;if(E){D.animations=D.animations||{},D.animationList=D.animationList||[];for(const[z,ee]of Object.entries(E))try{const G=ua.createAnimation(ee.animation);G.field=z,G.baseValue=ee.value;const J=Q(D,z),ge=z==="volume"?D.soundprops?.volume:z==="maxwidth"?D.textMaxwidth:z==="zoom"?b.cameraTransforms?.zoom:D[J];G.baseNumeric=Array.isArray(ge)?ge.slice():ge,G.slot=J,D.animationList.push(G),G.name&&(D.animations[G.name]=G),si.push({layer:D,field:z,slot:J,ctrl:G})}catch(G){be(t,e,`animation '${D.name}.${z}' \u5EFA\u63A7\u5236\u5668\u5931\u8D25: ${String(G.message).slice(0,80)}`)}if(D.animationList.length){const z=new Map;for(const ee of D.animationList)z.set(ee.field,ee);ua.linkAnimations(z,ee=>be(t,e,`${D.name}: ${ee}`)),D.animationsByField=Object.fromEntries(z)}}}for(const D of b.layers){const E=D.particleOverrideAnimations;if(E)for(const[z,ee]of Object.entries(E))try{const G=ua.createAnimation(ee.animation);G.baseNumeric=typeof ee.value=="number"?ee.value:Number(ee.value)||0,ar.push({layer:D,key:z,ctrl:G})}catch(G){be(t,e,`override animation '${D.name}.${z}' \u5EFA\u63A7\u5236\u5668\u5931\u8D25: ${String(G.message).slice(0,80)}`)}}for(const D of b.layers)(Array.isArray(D.animationLayers)?D.animationLayers:[]).forEach((z,ee)=>{const G=z.visibleScript;if(G)try{const J=ot.evalObjectScript(G.script,G.scriptproperties,{canvasSize:{width:C,height:R},timeOfDay:xt,userProperties:F,audioViews:Fe,inputView:Un,layer:D,...nr,...L,shared:pn,storage:S,onError:ue=>be(t,e,`animationlayer visible script '${D.name}[${ee}]' \u5931\u8D25: ${String(ue.message||ue).slice(0,80)}`)});if(!J)return;P.push(J);const ge=J.init(z.visible!==!1),ae=ti(ge);ae!==void 0&&(z.visible=ae),J.applyUserProperties(F),J.hasMediaHook&&tr(J),Mt(J),Li.push({layer:D,index:ee,sandbox:J}),J.hasAnimEventHook&&Ye(D,{sandbox:J,kind:"animLayer",animLayerIndex:ee})}catch(J){be(t,e,`animationlayer script '${D.name}[${ee}]' \u6C42\u503C\u5931\u8D25: ${String(J.message).slice(0,80)}`)}});for(const D of b.layers){const E=D.particleOverrideScripts;if(E)for(const[z,ee]of Object.entries(E))try{const G=ot.evalObjectScript(ee.script,ee.scriptproperties,{canvasSize:{width:C,height:R},timeOfDay:xt,userProperties:F,audioViews:Fe,inputView:Un,layer:D,...nr,...L,shared:pn,storage:S,onError:J=>be(t,e,`override script '${D.name}.${z}' \u5931\u8D25: ${String(J.message||J).slice(0,80)}`)});if(!G)continue;P.push(G),G.init(ee.value),G.applyUserProperties(F),G.hasMediaHook&&tr(G),Mt(G),G.hasUpdate&&ai.push({layer:D,key:z,sandbox:G})}catch(G){be(t,e,`override script '${D.name}.${z}' \u6C42\u503C\u5931\u8D25: ${String(G.message).slice(0,80)}`)}}let re=!1;for(const D of b.layers){for(const[z,ee]of(D.effects||[]).entries()){const G=ee.visibleScript;if(G)try{const J=ot.evalObjectScript(G.script,G.scriptproperties,{canvasSize:{width:C,height:R},timeOfDay:xt,userProperties:F,audioViews:Fe,inputView:Un,...nr,layer:D,targetEffect:ee,...L,shared:pn,storage:S,onError:pe=>be(t,e,`effect visible script '${D.name}#${z}' \u5931\u8D25: ${String(pe.message||pe).slice(0,80)}`)});if(!J)continue;P.push(J);const ge=J.init(ee.visible),ae=ti(ge);ae!==void 0&&(ee.visible=ae),J.applyUserProperties(F),J.hasMediaHook&&tr(J),Mt(J);let ue=null;J.hasUpdate&&(ue={effect:ee,sandbox:J,last:ge},or.push(ue)),J.hasAnimEventHook&&Ye(D,{sandbox:J,kind:"effectVisible",effect:ee,run:ue})}catch(J){console.warn(`\u6548\u679C\u5F00\u5173\u811A\u672C ${D.name}#${z} \u6C42\u503C\u5931\u8D25: ${J.message}`)}}const E=D.objectScripts;if(E)for(const[z,ee]of Object.entries(E))try{const G=ot.evalObjectScript(ee.script,ee.scriptproperties,{canvasSize:{width:C,height:R},screenResolution:{x:n.clientWidth||window.innerWidth||1,y:n.clientHeight||window.innerHeight||1},timeOfDay:xt,userProperties:F,audioViews:Fe,inputView:Un,layer:D,getAnimationForProperty:()=>D.animationsByField&&D.animationsByField[z]||null,...L,getBoneOverrides:sn,shared:pn,storage:S,...nr,onError:J=>be(t,e,`object script '${D.name}.${z}' \u5931\u8D25: ${String(J.message||J).slice(0,90)}`)});if(G){P.push(G);const J=Q(D,z),ge=D[J],ae=z==="angles"&&Array.isArray(ge)?ot.radToScriptAngles(ge):Array.isArray(ge)?{x:ge[0]??0,y:ge[1]??0,z:ge[2]??0}:ge,ue=G.init(ae);if(ue!=null){if(z==="visible"){const pe=ti(ue);pe!==void 0&&D.visibleSelf!==pe&&(D.visibleSelf=pe,re=!0)}else if(typeof ue=="number"&&Number.isFinite(ue))["alpha","brightness","maxwidth","pointsize","volume","intensity","exponent"].includes(z)&&op(D,z).set(ue);else if(typeof ue=="object"&&ue.x!==void 0){const pe=ue;Number.isFinite(Number(pe.x))&&Number.isFinite(Number(pe.y))&&(D[J]=z==="angles"?ot.scriptAnglesToRad(pe):[Number(pe.x)||0,Number(pe.y)||0,Number(pe.z)||0])}}G.applyUserProperties(F),xs(D,G),G.hasMediaHook&&tr(G),Mt(G),G.hasUpdate&&it.push({layer:D,field:z,slot:J,kind:z==="visible"?"bool":["alpha","brightness","maxwidth","pointsize","volume","intensity","exponent"].includes(z)?"scalar":"vec3",sandbox:G,last:z==="visible"?ue:void 0}),G.hasAnimEventHook&&Ye(D,{sandbox:G,kind:z==="visible"?"bool":z==="alpha"||z==="brightness"?"scalar":"vec3",field:z,slot:J})}}catch(G){console.warn(`\u5BF9\u8C61\u811A\u672C ${D.name}.${z} \u6C42\u503C\u5931\u8D25: ${G.message}`)}}for(const D of Sa){const E=D.sandbox.init(D.layer.text??"");typeof E=="string"&&(D.layer.text=E),D.sandbox.applyUserProperties(v)}re&&x();const q=b.generalScripts;if(q){for(const[D,E]of Object.entries(q))try{const z=ot.evalObjectScript(E.script,E.scriptproperties,{canvasSize:{width:C,height:R},timeOfDay:xt,userProperties:F,audioViews:Fe,inputView:Un,...nr,...L,shared:pn,storage:S,onError:G=>be(t,e,`general script '${D}' \u5931\u8D25: ${String(G.message||G).slice(0,80)}`)});if(!z)continue;P.push(z),z.init(E.value),z.applyUserProperties(F),z.hasMediaHook&&tr(z),Mt(z);const ee=G=>$(D,G);z.hasUpdate&&_n.push({field:D,sandbox:z,write:ee})}catch(z){console.warn(`general \u811A\u672C ${D} \u6C42\u503C\u5931\u8D25: ${z.message}`)}_n.length&&be(t,e,`general scripts: ${_n.map(D=>D.field).join(",")}`)}const K=b.generalAnimations;if(K){for(const[D,E]of Object.entries(K))try{const z=ua.createAnimation(E.animation);z.field=D,z.baseValue=E.value,z.baseNumeric=E.value,z.name&&(Ui[z.name]=z),oi.push({field:D,ctrl:z,write:ee=>$(D,ee)})}catch(z){be(t,e,`general animation '${D}' \u5EFA\u63A7\u5236\u5668\u5931\u8D25: ${String(z.message).slice(0,80)}`)}oi.length&&be(t,e,`general animations: ${oi.map(D=>D.field).join(",")}`)}}it.length&&(be(t,e,`object scripts: ${it.length}`),window.__objScripts=it,window.__effectScripts=or),window.__mediaHooks=st,window.__sceneLayers=b.layers,window.__compositeStats=()=>_.compositeStats?.()??null,window.__compositeEnable=T=>_.setCompositeEnabled?.(T),window.__scene=b,window.__textures=Ke;const Oi=Array.from(ci.keys());Oi.length&&be(t,e,`cursor hooks: ${Oi.length} layers`);let Pa={hovered:[],pressed:[],lastLeftDown:!1};const jo=()=>({worldPosition:ot.makeCursorEventVec(lt.state.wx,lt.state.originY!=null?lt.state.originY:lt.state.wy,0)}),Dr=(T,C,R)=>{const F=ci.get(T);if(F)for(const $ of F)$.callCursor(C,R)},li=()=>{if(Oi.length===0)return;const T=lt.state;if(!T.has)return;const C=_.getParallaxOffset?_.getParallaxOffset():null,R=b.general?.orthogonalprojection?.height||n.height,F=vA.hitTestLayersAll(b.layers,T.wx,T.wy,R,{parallaxCtx:C,alignTable:pt.ALIGN,perspEye:_.getPerspectiveEye?_.getPerspectiveEye():null,filter:L=>ci.has(L)}),$=AA.planCursorDispatch(Pa,F,T.leftDown);Pa=$.next;const H=jo();for(const L of $.leave)Dr(L,"cursorLeave",H);for(const L of $.enter)Dr(L,"cursorEnter",H);for(const L of $.move)Dr(L,"cursorMove",H);for(const L of $.down)Dr(L,"cursorDown",H);for(const L of $.up)Dr(L,"cursorUp",H);for(const L of $.click)Dr(L,"cursorClick",H)},M=performance.now();let j=0,te=0;const Z=[],ne=[],de=new ys(t.cfg.sceneFps||60);let me=t.cfg.sceneFps||60,ye=0;const fe=.05,se=T=>{if(a||t.paused)return;const C=t.cfg.sceneFps||60;if(C!==me&&(me=C,de.setFps(C)),de.shouldRender(T)){zr(t,T),Du(t,n,t.cfg);const R=n.clientWidth||window.innerWidth||1,F=n.clientHeight||window.innerHeight||1;(R!==Vt||F!==xn)&&(Vt=R,xn=F,Pt={w:R,h:F},Pi(R,F));const $=Math.max(0,(T-M-j)/1e3);if(Un.update(lt.state),dn.enabled){if(U?.media)U.media.pump();else{const ee=he();typeof ee?.update=="function"&&ee.update($)}const E=ct(),z=We.diffMediaEvents(nn,E);if(z.length){for(const{name:ee,event:G}of z)for(const J of st)J.disabled||J.callMedia(ee,G);nn=We.cloneMediaSnapshot(E)}if(_i!==E.thumbnail&&typeof E.thumbnail=="string"&&E.thumbnail){const ee=E.thumbnail;_i=ee,(async()=>{try{const G=await fetch(ee,{cache:"no-store"}).then(pe=>pe.ok?pe.blob():null);if(!G)return;const J=await createImageBitmap(G,{premultiplyAlpha:"none"});if(_i!==ee){J.close?.();return}const ge=J.width,ae=J.height,ue=Aa(J,ge,ae);if(J.close?.(),ue){const pe=ct();pe.primaryColor=We.mediaVec3(...ue.primary),pe.secondaryColor=We.mediaVec3(...ue.secondary),pe.tertiaryColor=We.mediaVec3(...ue.tertiary),pe.textColor=We.mediaVec3(.98,.98,1),pe.highContrastColor=We.mediaVec3(1,1,1)}be(t,e,`media: $mediaThumbnail \u5DF2\u66F4\u65B0\uFF08${ge}\xD7${ae}\uFF09`)}catch(G){be(t,e,`media: \u5C01\u9762\u4E0A\u4F20\u5931\u8D25\uFF08${G instanceof Error?G.message:G}\uFF09`)}})()}}U?.windowTitle?U.windowTitle.pump():O.update($);const H=Math.max(0,$-ye);ye=$;const L=H,X=Math.min(H,fe);Tn.dt=L,Tn.t=$;let Q=!1;const re=(E,z)=>{const ee=Xe.get(E);if(!(!ee||!ee.length)){window.__animEventsFired=(window.__animEventsFired||0)+z.length;{const G=window,J=G.__animEventLog||(G.__animEventLog=[]);for(const ge of z)J.push({l:String(E&&(E.name||E.id)),f:ge.frame,n:ge.name}),J.length>400&&J.shift()}for(const G of z)for(const J of ee){const ge=J.sandbox;if(!(!ge||ge.disabled))if(J.kind==="text"){const ae=ge.callAnimationEvent(G,String(E.text??""));typeof ae=="string"&&(E.text=ae)}else if(J.kind==="effectVisible"){const ae=J.run&&J.run.last!==void 0&&J.run.last!==null?J.run.last:!!J.effect.visible,ue=ge.callAnimationEvent(G,ae);J.run&&(typeof ue=="boolean"||typeof ue=="number"&&Number.isFinite(ue))&&(J.run.last=ue);const pe=ti(ue);pe!==void 0&&(J.effect.visible=pe)}else if(J.kind==="const"){const ae=ge.callAnimationEvent(G,ge.__lastConstValue);(typeof ae=="number"&&Number.isFinite(ae)||ae&&typeof ae=="object"&&Number.isFinite(Number(ae.x))&&Number.isFinite(Number(ae.y)))&&(ge.__lastConstValue=ae)}else if(J.kind==="bool"){const ae=ge.callAnimationEvent(G,!!E.visible),ue=ti(ae);ue!==void 0&&E.visibleSelf!==ue&&(E.visibleSelf=ue,Q=!0)}else if(J.kind==="scalar"){const ae=ge.callAnimationEvent(G,Number(E[J.field])||0),ue=Number(ae);Number.isFinite(ue)&&(E[J.field]=ue)}else{const ae=E[J.slot],ue=J.field==="angles"?ot.radToScriptAngles(ae):{x:ae&&ae[0]||0,y:ae&&ae[1]||0,z:ae&&ae[2]||0},pe=ge.callAnimationEvent(G,ue),Ie=pe&&typeof pe=="object"&&"x"in pe?pe:ue;E[J.slot]=J.field==="angles"?ot.scriptAnglesToRad(Ie):[Number(Ie.x)||0,Number(Ie.y)||0,Number(Ie.z)||0]}}}};for(const E of si){E.ctrl.advance(L);const z=E.field,ee=E.slot||z,G=E.ctrl.applyTo(E.ctrl.baseNumeric);if(Array.isArray(G)){const J=E.layer[ee];if(Array.isArray(J))for(let ge=0;ge<G.length&&ge<J.length;ge++)J[ge]=G[ge]}else Number.isFinite(G)&&(z==="visible"?E.layer.visibleSelf!==!!G&&(E.layer.visibleSelf=!!G,Q=!0):z==="volume"?(E.layer.soundprops.volume=G,E.layer.soundCtl?.setVolume?.(G)):z==="maxwidth"?E.layer.textMaxwidth=G:z==="zoom"?G>0&&(b.cameraTransforms.zoom=G):E.layer[ee]=G)}for(const E of ar){E.ctrl.advance(L);const z=E.ctrl.applyTo(E.ctrl.baseNumeric);if(typeof z!="number"||!Number.isFinite(z))continue;const ee=Hn.get(E.layer.id);if(ee)for(const G of ee)G.setOverrideValue(E.key,z)}for(const E of Li){if(E.sandbox.disabled)continue;E.sandbox.engine.frametime=X,E.sandbox.engine.runtime=$,E.sandbox.engine.timeOfDay=xt;const z=E.layer.animationLayers?.[E.index];if(!z)continue;const ee=E.sandbox.callUpdate(z.visible!==!1),G=ti(ee);G!==void 0&&(z.visible=G)}for(const E of ai){if(E.sandbox.disabled)continue;E.sandbox.engine.frametime=X,E.sandbox.engine.runtime=$,E.sandbox.engine.screenResolution={x:n.clientWidth||window.innerWidth||1,y:n.clientHeight||window.innerHeight||1},E.sandbox.engine.timeOfDay=xt;const z=E.sandbox.callUpdate(void 0),ee=Hn.get(E.layer.id);if(!ee)continue;let G=z;if(z&&typeof z=="object"){const J=z;(J.x!==void 0||J.y!==void 0)&&(G=[Number(J.x)||0,Number(J.y)||0,Number(J.z)||0])}for(const J of ee)E.key==="colorn"&&Array.isArray(G)?J.setColorOverride(G):J.setOverrideValue(E.key,G)}for(const E of si){const z=E.ctrl.takeEvents();z.length&&re(E.layer,z)}for(const E of ar){const z=E.ctrl.takeEvents();z.length&&re(E.layer,z)}for(const E of oi)E.ctrl.takeEvents();for(const E of oi){E.ctrl.advance(L);const z=E.ctrl.applyTo(E.ctrl.baseNumeric);typeof z=="number"&&Number.isFinite(z)?E.write(z):Array.isArray(z)&&Number.isFinite(z[0])&&E.write(z[0])}const q=Math.floor(T/1e3);if(q!==tn){tn=q;const E=new Date;xt=(E.getHours()*3600+E.getMinutes()*60+E.getSeconds())/86400}for(const E of or){if(E.sandbox.disabled)continue;E.sandbox.engine.frametime=X,E.sandbox.engine.runtime=$,E.sandbox.engine.timeOfDay=xt;const z=E.sandbox.callUpdate(E.last!==void 0&&E.last!==null?E.last:!!E.effect.visible);(typeof z=="boolean"||typeof z=="number"&&Number.isFinite(z))&&(E.last=z);const ee=ti(z);ee!==void 0&&(E.effect.visible=ee)}for(const E of _n){if(E.sandbox.disabled)continue;E.sandbox.engine.frametime=X,E.sandbox.engine.runtime=$,E.sandbox.engine.timeOfDay=xt;const z=b.general||{},ee=z[E.field]&&typeof z[E.field]=="object"&&"value"in z[E.field]?z[E.field].value:z[E.field],G=E.sandbox.callUpdate(ee);G!==void 0&&E.write(G)}const K={x:n.clientWidth||window.innerWidth||1,y:n.clientHeight||window.innerHeight||1};for(const E of P)!E||E.disabled||(E.engine.frametime=X,E.engine.runtime=$,E.engine.screenResolution=K,E.engine.timeOfDay=xt);for(const E of it){if(E.sandbox.disabled)continue;E.sandbox.engine.frametime=X,E.sandbox.engine.runtime=$,E.sandbox.engine.screenResolution=K,E.sandbox.engine.timeOfDay=xt;const z=E.layer[E.field];if(E.kind==="bool"){const ee=E.last!==void 0&&E.last!==null?E.last:!!z,G=E.sandbox.callUpdate(ee);(typeof G=="boolean"||typeof G=="number"&&Number.isFinite(G))&&(E.last=G);const J=ti(G);J!==void 0&&(E.field==="visible"?E.layer.visibleSelf!==J&&(E.layer.visibleSelf=J,Q=!0):E.layer[E.field]=J)}else if(E.kind==="scalar"){const ee=op(E.layer,E.field),G=E.sandbox.callUpdate(Number(ee.get())||0),J=Number(G);Number.isFinite(J)&&ee.set(J)}else{const ee=E.slot||E.field,G=E.layer[ee],J=E.field==="angles"?ot.radToScriptAngles(G):{x:G[0]||0,y:G[1]||0,z:G[2]||0},ge=E.sandbox.callUpdate(J),ae=ge&&typeof ge=="object"&&"x"in ge?ge:J;E.layer[ee]=E.field==="angles"?ot.scriptAnglesToRad(ae):[ae.x||0,ae.y||0,ae.z||0]}}if(Q&&x(),gn.size){for(const E of gn)jn.add(E);gn.clear()}if(jn.size&&zt.recomposeWorld(b.layers,jn),Pe.enabled){Ne.pump(),Ne.active||(ie.current?ie.current.pump():B.update($));const E=Gt.readBands(),z=De();if(E){const ee={left64:z.left64.slice(),right64:z.right64.slice(),left32:z.left32.slice(),right32:z.right32.slice(),left16:z.left16.slice(),right16:z.right16.slice(),level:z.level,silent:!1};n2(ee,E,g2),Re=ee,rm(Fe,ee)}else Re=z,rm(Fe,z)}mn.length&&la.followAttachments(mn,$,sn);for(const E of It){const z=E.mdl,ee=E.layer,G=z.animations;if(!G||!G.length||!ee.animationLayers||!ee.visible||!G.some(ge=>ge.events&&ge.events.length))continue;let J=Fr.get(ee);J||(J=new Map,Fr.set(ee,J));for(let ge=0;ge<ee.animationLayers.length;ge++){const ae=ee.animationLayers[ge];if(!ae||ae.visible===!1||ae.visible===0)continue;const ue=G.find(qe=>qe.id===ae.animation);if(!ue||!ue.events||!ue.events.length)continue;const pe=$*(typeof ae.rate=="number"?ae.rate:1)*ue.fps,Ie=J.has(ge)?J.get(ge):pe,je=ua.crossedEvents(ue.events,Ie,pe,ue.frameCount,ue.mode==="loop"?"loop":ue.mode==="mirror"?"mirror":"single");je.length&&re(ee,je),J.set(ge,pe)}}const D=t.coverAlign;_.render(b,Ke,n.width,n.height,$,Ur(t.cfg.fit),D.x,D.y).then(()=>{if(t.onFirstFrame){const E=t.onFirstFrame;t.onFirstFrame=void 0;try{E()}catch{}}if(!(a||t.paused)){if($e.length){for(const E of $e)re(E.layer,E.events);$e.length=0}try{li()}catch{}lt.beginFrame();try{t.sceneTextUpdate&&T>=Ni&&(Ni=T+100,t.sceneTextUpdate($))}catch{}t.raf=requestAnimationFrame(se)}}).catch(E=>{console.warn("scene render error:",E),be(t,e,`render: ${String(E.message||E).slice(0,200)}`),a=!0})}else t.paused||(t.raf=requestAnimationFrame(se))},_e=()=>{a||t.paused||t.raf===void 0&&(t.raf=requestAnimationFrame(se))},xe=T=>{if(a)return;const C=b.properties||{},R=rb(C,v,T);if(Object.keys(R).length){Ai(b.general||{},C,0);for(const F of b.layers){const $=F.srcObject;if(!$)continue;Ai($,C,0);const H=Qn($.visible);H&&H in R&&(F.visibleSelf=zt.parseBool($.visible,!0));const L=Qn($.color);L&&L in R&&(F.color=zt.parseColor($.color),F.isText&&(F.textColor=F.color));const X=Qn($.alpha);X&&X in R&&(F.alpha=zt.parseNum($.alpha,1));const Q=Qn($.brightness);Q&&Q in R&&(F.brightness=zt.parseNum($.brightness,1));const re=Qn($.volume);if(re&&re in R){const K=zt.parseNum($.volume,1);F.soundprops&&(F.soundprops.volume=K),F.soundCtl?.setVolume?.(K)}for(let K=0;K<($.animationlayers||[]).length;K++){const D=$.animationlayers[K],E=F.animationLayers?.[K];if(!D||!E)continue;const z=Qn(D.visible);z&&z in R&&(E.visible=zt.parseBool(D.visible,!0));const ee=Qn(D.rate);ee&&ee in R&&(E.rate=zt.parseNum(D.rate,1));const G=Qn(D.blend);G&&G in R&&(E.blend=zt.parseNum(D.blend,1))}for(let K=0;K<($.effects||[]).length;K++){const D=$.effects[K],E=F.effects?.[K];if(!D||!E)continue;const z=Qn(D.visible);z&&z in R&&!E.visibleScript&&(E.visible=zt.parseBool(D.visible,!0))}const q=$.instanceoverride;if(q&&typeof q=="object"&&F.particle){let K=!1;for(const D of Object.keys(q)){if(D==="id")continue;const E=Qn(q[D]);if(E&&E in R){K=!0;break}}if(K){const D=Hn.get(F.id);if(D)for(const E of D)E.reapplyOverride?.()}}}for(const F of P)if(!(!F||F.disabled))try{F.applyUserProperties(R)}catch{}x();for(const F of b.layers){if(!F.particle)continue;const $=Hn.get(F.id);if($)for(const H of $)H.setVisible(!!F.visible)}_.applyConstUserProperties?.(R);for(const F of Sn)F.lastKey=null;be(t,e,`props hot: ${Object.keys(R).join(",")}`)}};f=()=>{t.raf!==void 0&&(cancelAnimationFrame(t.raf),t.raf=void 0),te||(te=performance.now()),Z.length=0;for(const T of Ke.values())T?.videoCtl?.isPlaying?.()&&(Z.push(T.videoCtl),T.videoCtl.pause());ne.length=0;for(const T of Br)!T.paused&&!T.ended&&(ne.push(T),T.pause())},h=()=>{te&&(j+=performance.now()-te,te=0);for(const T of Z)try{T.play()}catch{}Z.length=0;for(const T of ne)T.play().catch(()=>{});ne.length=0,de.reset(),_e()},d=xe,l&&(xe(l),l=null),_e();{const T=b.general?.orthogonalprojection,C=T?.width||n.width,R=T?.height||n.height,F=Ur(t.cfg.fit),$=Qo(F,C,R,n.width,n.height);be(t,e,`fit ${F}: view ${Math.round($.viewW)}x${Math.round($.viewH)} scene ${C}x${R} canvas ${n.width}x${n.height}`);{const H=Go(b.layers);Number.isFinite(H.minX)&&Number.isFinite(H.minY)&&(t.coverPeek={contentW:H.maxX-H.minX,contentH:H.maxY-H.minY,projW:C,projH:R},be(t,e,`cover peek gate: content ${Math.round(H.maxX-H.minX)}x${Math.round(H.maxY-H.minY)}`))}}be(t,e,`renderer started: ${b.layers.length} layers`)}catch(m){if(a||m&&m.name==="AbortError")return;console.warn("scene render failed:",m);const g=m instanceof Error?m:new Error(String(m));be(t,e,`failed: ${String(g.message||g).slice(0,200)}`),t.onError?t.onError(g):t.fallbackPage?.()}})()}const S2='data-we-shim="1"',cp="data-we-shim-src";function P2(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 _2(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 lp(t){return t.replace(/<\/script/gi,"<\\/script")}function E2(t,e,n){if(t||(t=""),t.includes(S2)||t.includes(cp))return t;const r=n.baseHref&&!/<base\b/i.test(t)?`<base href="${n.baseHref.replace(/"/g,""")}">`:"",i=`<script ${cp}="1">
|
|
762
|
+
${lp(e)}
|
|
763
|
+
<\/script>`,s=n.seedScript&&n.seedScript.trim()?`<script>
|
|
764
|
+
${lp(n.seedScript)}
|
|
765
|
+
<\/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 M2=`/**
|
|
517
766
|
* 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
767
|
*
|
|
519
768
|
* \u8BED\u6599\uFF1A\u672C\u673A\u5E93 42 \u5F20 web \u58C1\u7EB8\u626B\u63CF\uFF082026-09\uFF09\u2014\u2014
|
|
@@ -530,7 +779,8 @@ ${gs(t.seedScript)}
|
|
|
530
779
|
* __wePushMedia(event) \u2014 {op, payload} \u89C1\u4E0B
|
|
531
780
|
* __wePushDirectoryFiles(prop, files) / __weRemoveDirectoryFiles(prop, files)
|
|
532
781
|
* __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
|
|
782
|
+
* __wePushPointer(x, y, buttons, mods) / __wePointerLeave() \u2014 \u5916\u90E8\u6307\u9488\u6CE8\u5165\uFF08\u89C1\u6587\u672B\uFF09
|
|
783
|
+
* __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
784
|
*/
|
|
535
785
|
(function (w) {
|
|
536
786
|
"use strict";
|
|
@@ -539,7 +789,7 @@ ${gs(t.seedScript)}
|
|
|
539
789
|
w.document.documentElement.setAttribute("data-we-shim", "1");
|
|
540
790
|
}
|
|
541
791
|
} catch (_) {
|
|
542
|
-
|
|
792
|
+
|
|
543
793
|
}
|
|
544
794
|
|
|
545
795
|
var audioListener = null;
|
|
@@ -1016,6 +1266,7 @@ ${gs(t.seedScript)}
|
|
|
1016
1266
|
liveMedia.push(new w.WeakRef(el));
|
|
1017
1267
|
}
|
|
1018
1268
|
function applyMediaVolume(el) {
|
|
1269
|
+
if (!mediaVolDesc || !mediaMutedDesc) return;
|
|
1019
1270
|
if (el.__weBaseVol != null) {
|
|
1020
1271
|
mediaVolDesc.set.call(el, el.__weBaseVol * hostVolume);
|
|
1021
1272
|
} else {
|
|
@@ -1094,6 +1345,33 @@ ${gs(t.seedScript)}
|
|
|
1094
1345
|
}
|
|
1095
1346
|
installMediaVolumeHooks();
|
|
1096
1347
|
|
|
1348
|
+
// \u2014\u2014 \u65B0\u5EFA\u5A92\u4F53\u5143\u7D20\u7684\u97F3\u91CF\u6536\u655B \u2014\u2014
|
|
1349
|
+
// \u5C5E\u6027 hook \u53EA\u62E6\u5F97\u5230\u300C\u4F5C\u8005\u7528 JS \u8D4B .volume/.muted\u300D\u4E0E\u65B0 Audio() \u6784\u9020\uFF1B
|
|
1350
|
+
// createElement + innerHTML \u63D2\u5165\u3001\u4E14\u4ECE\u672A\u8D4B\u8FC7\u503C\u7684 <audio>/<video>\uFF08autoplay
|
|
1351
|
+
// \u76F4\u63A5\u5F00\u8D70\uFF09\u65E2\u6CA1\u767B\u8BB0\u4E5F\u6CA1\u5237\u65B0\uFF0C\u4E3B\u97F3\u91CF\u4E3A 0 \u65F6\u7167\u6837\u51FA\u58F0\u2014\u2014\u8868\u73B0\u4E3A\u300C\u6062\u590D\u64AD\u653E/\u6302
|
|
1352
|
+
// \u540E\u53F0\u4E00\u6BB5\u65F6\u95F4\u540E\u5192\u4E00\u5C0F\u6BB5\u97F3\u4E50\u300D\u3002\u5BF9\u63D2\u5165 DOM \u7684\u5A92\u4F53\u5143\u7D20\u7ACB\u5373\u6309\u5F53\u524D\u4E3B\u97F3\u91CF\u843D
|
|
1353
|
+
// \u4E00\u6B21\u771F\u5B9E\u5C5E\u6027\uFF1B\u4E0D\u8FDB DOM\u7684\u5143\u7D20\u89C2\u5BDF\u4E0D\u5230\uFF08\u7F55\u89C1\uFF0C\u63A5\u53D7\uFF09\u3002
|
|
1354
|
+
try {
|
|
1355
|
+
var mediaObserver = new w.MutationObserver(function (records) {
|
|
1356
|
+
for (var i = 0; i < records.length; i++) {
|
|
1357
|
+
var added = records[i].addedNodes;
|
|
1358
|
+
for (var j = 0; j < added.length; j++) {
|
|
1359
|
+
var n = added[j];
|
|
1360
|
+
if (!n || n.nodeType !== 1) continue;
|
|
1361
|
+
if (n.tagName === "AUDIO" || n.tagName === "VIDEO") {
|
|
1362
|
+
applyMediaVolume(n);
|
|
1363
|
+
} else if (n.querySelectorAll) {
|
|
1364
|
+
var inner = n.querySelectorAll("audio,video");
|
|
1365
|
+
for (var k = 0; k < inner.length; k++) applyMediaVolume(inner[k]);
|
|
1366
|
+
}
|
|
1367
|
+
}
|
|
1368
|
+
}
|
|
1369
|
+
});
|
|
1370
|
+
mediaObserver.observe(w.document, { childList: true, subtree: true });
|
|
1371
|
+
} catch (_) {
|
|
1372
|
+
/* \u65E7\u5F15\u64CE\u65E0 MutationObserver\uFF1A\u9000\u5316\u4E3A\u4EC5\u5C5E\u6027 hook\uFF0C\u884C\u4E3A\u540C\u65E7\u7248 */
|
|
1373
|
+
}
|
|
1374
|
+
|
|
1097
1375
|
// \u2014\u2014 \u7236\u9875\u63A7\u5236\u9762 \u2014\u2014
|
|
1098
1376
|
// \u5B98\u65B9 setPaused \u53EA\u5728\u6682\u505C\u72B6\u6001\u5B9E\u9645\u53D8\u5316\u65F6\u8C03\u7528\u4E00\u6B21\uFF1B\u91CD\u590D\u8C03\u7528\u53BB\u91CD\u3002
|
|
1099
1377
|
// \u6682\u505C\u8FD8\u8981\u51BB\u7ED3\u9875\u5185\u5A92\u4F53\uFF1A\u5B98\u65B9\u662F\u8FDB\u7A0B\u7EA7\u51BB\u7ED3\uFF08\u65E0\u58F0\u3001\u89E3\u7801\u5668\u53EF\u56DE\u6536\uFF09\uFF0C\u4F5C\u8005\u7684
|
|
@@ -1320,31 +1598,25 @@ ${gs(t.seedScript)}
|
|
|
1320
1598
|
};
|
|
1321
1599
|
|
|
1322
1600
|
// \u2014\u2014 \u5916\u90E8\u6307\u9488\u6CE8\u5165\uFF08\u684C\u9762 underlay \u5C42\u6536\u4E0D\u5230\u9F20\u6807\u4E8B\u4EF6\uFF0C\u7236\u9875\u7ECF __wp.pushPointer \u63A8\u5165\uFF09\u2014\u2014
|
|
1323
|
-
//
|
|
1324
1601
|
// \u573A\u666F\u58C1\u7EB8\u90A3\u6761\u901A\u9053\u662F\u300C\u5199\u4E00\u4E2A\u72B6\u6001\u5BF9\u8C61\u3001\u6E32\u67D3\u5668\u6BCF\u5E27\u8BFB\u300D\uFF08render/pointer.js\uFF09\uFF1B\u7F51\u9875\u58C1\u7EB8
|
|
1325
1602
|
// \u6CA1\u6709\u8FD9\u6837\u7684\u5355\u4E00\u6D88\u8D39\u70B9 \u2014\u2014 \u4F5C\u8005\u4EE3\u7801\u5C31\u662F**\u76D1\u542C DOM \u4E8B\u4EF6**\u7684\uFF0C\u6240\u4EE5\u8FD9\u91CC\u5FC5\u987B\u628A\u63A8\u9001
|
|
1326
1603
|
// \u8FD8\u539F\u6210\u4E00\u4E32\u5408\u6210\u4E8B\u4EF6\u3002\u8BED\u6599\uFF08\u672C\u673A 49 \u5F20 web\uFF09\uFF1Amousemove 24 \u5F20\u3001click 29 \u5F20\u3001
|
|
1327
1604
|
// mouseover/out 17 \u5F20\u3001mouseenter/leave 8 \u5F20\u3001pointer* 16 \u5F20\uFF08createjs \u7CFB\u4E00\u5F8B\u8D70
|
|
1328
1605
|
// pointerdown/move/up\uFF09\u3001.button 18 \u5F20\u3001.which 17 \u5F20\u3001pointerId/relatedTarget 15 \u5F20\u3002
|
|
1329
|
-
//
|
|
1330
1606
|
// \u4E09\u6761\u8981\u70B9\uFF08\u90FD\u6709\u8BED\u6599\u4F9D\u636E\uFF0C\u6539\u9519\u4E86\u4F1A\u9759\u9ED8\u5931\u6548\uFF09\uFF1A
|
|
1331
|
-
//
|
|
1332
1607
|
// 1. **\u5FC5\u987B elementFromPoint \u6309\u547D\u4E2D\u5143\u7D20\u6D3E\u53D1**\uFF0C\u4E0D\u80FD\u4E00\u5F8B\u6253 document\u3002\u4F5C\u8005\u65E2\u6709\u6302
|
|
1333
1608
|
// document/window \u7684\uFF0815 \u5F20\uFF0C\u9760\u5192\u6CE1\u6536\u5230\uFF09\uFF0C\u4E5F\u6709\u6302 canvas \u4E0A\u8BFB \`event.offsetX\`
|
|
1334
1609
|
// \u7684\uFF081748506393 \u6D41\u4F53 \`pointers[0].dx = (e.offsetX - \u2026)\`\uFF09\u3002offsetX/offsetY \u7531
|
|
1335
1610
|
// \u6D4F\u89C8\u5668\u6309 target \u7684 padding box \u73B0\u7B97 \u2014\u2014 target \u6253\u9519\u5C31\u662F\u9519\u7684\u504F\u79FB\uFF0C\u4E14\u65E0\u4EFB\u4F55\u62A5\u9519\u3002
|
|
1336
1611
|
// pageX/pageY \u540C\u7406\u7531 clientX + \u6EDA\u52A8\u91CF\u73B0\u7B97\uFF0C\u4E0D\u7528\u6211\u4EEC\u586B\u3002
|
|
1337
|
-
//
|
|
1338
1612
|
// 2. **over/out/enter/leave \u94FE\u8981\u6309 W3C \u8BED\u4E49\u8865\u5168**\u30021748506393 \u9760 canvas \u7684
|
|
1339
1613
|
// \`mouseenter\` \u628A \`pointers[0].down\` \u7F6E true\uFF08\u4E0D\u8FDB\u8FD9\u4E2A\u5206\u652F\u5219\u9F20\u6807\u600E\u4E48\u52A8\u90FD\u4E0D\u51FA\u67D3\u6599\uFF09\u3001
|
|
1340
1614
|
// \u9760 window \u7684 \`mouseleave\` \u590D\u4F4D\uFF1B1081733658 animatedGrid \u9760 \`document.body\` \u7684
|
|
1341
1615
|
// mouseover/mouseleave \u8D77\u505C\u6574\u4E2A\u7F51\u683C\u52A8\u753B\u3002leave/enter \u4E0D\u5192\u6CE1\uFF0C\u5FC5\u987B\u81EA\u5DF1\u6CBF\u7956\u5148\u94FE\u8D70\u5230
|
|
1342
1616
|
// \u6700\u8FD1\u516C\u5171\u7956\u5148\uFF0C\u53EA\u53D1\u751F\u53D8\u5316\u7684\u90A3\u4E00\u6BB5\u3002
|
|
1343
|
-
//
|
|
1344
1617
|
// 3. **click \u8981\u9760 down/up \u8FB9\u7F18\u5408\u6210**\uFF0C\u4E14 down \u4E0E up \u7684 target \u4E0D\u540C\uFF08\u62D6\u62FD\uFF09\u65F6\u4E0D\u53D1\u3002
|
|
1345
1618
|
// 29 \u5F20\u542C click \u662F\u6700\u5927\u7684\u6D88\u8D39\u65B9\uFF1B\u8F6E\u8BE2\u63A8\u9001\u91CC\u6CA1\u6709\u300C\u70B9\u51FB\u300D\u8FD9\u4E2A\u4E8B\u4EF6\uFF0C\u53EA\u6709\u6309\u952E\u63A9\u7801\u7684
|
|
1346
1619
|
// \u8DF3\u53D8\uFF0C\u8FB9\u7F18\u4E22\u4E86\u5C31\u7B49\u4E8E\u6574\u7C7B\u4EA4\u4E92\u6D88\u5931\u3002
|
|
1347
|
-
//
|
|
1348
1620
|
// \u786C\u9650\u5236\uFF08\u5199\u5728\u8FD9\u91CC\u907F\u514D\u53CD\u590D\u8BD5\uFF09\uFF1ACSS \`:hover\` \u7531\u6D4F\u89C8\u5668\u81EA\u5DF1\u7684 hit-test \u9A71\u52A8\uFF0C\u5408\u6210\u4E8B\u4EF6
|
|
1349
1621
|
// \u6C38\u8FDC\u70B9\u4E0D\u4EAE\u5B83\uFF0818 \u5F20\u542B \`:hover\`\uFF09\u2014\u2014 \u7EAF CSS hover \u52A8\u753B\u7684\u58C1\u7EB8\u65E0\u6CD5\u7528\u6CE8\u5165\u901A\u9053\u54CD\u5E94\uFF0C
|
|
1350
1622
|
// \u8FD9\u4E0D\u662F\u5B9E\u73B0\u7F3A\u9677\uFF0C\u662F\u5408\u6210\u4E8B\u4EF6\u7684\u56FA\u6709\u8FB9\u754C\u3002
|
|
@@ -1356,6 +1628,17 @@ ${gs(t.seedScript)}
|
|
|
1356
1628
|
var ptrDownTarget = null; // \u6309\u4E0B\u65F6\u7684\u547D\u4E2D\u5143\u7D20\uFF08click \u5224\u5B9A\uFF09
|
|
1357
1629
|
var ptrLastClickTime = 0;
|
|
1358
1630
|
var ptrLastClickTarget = null;
|
|
1631
|
+
/**
|
|
1632
|
+
* \u4FEE\u9970\u952E\u63A9\u7801\uFF1Abit0 ctrl / bit1 shift / bit2 alt / bit3 meta\u3002
|
|
1633
|
+
*
|
|
1634
|
+
* \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
|
|
1635
|
+
* \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
|
|
1636
|
+
*
|
|
1637
|
+
* \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
|
|
1638
|
+
* OrbitControls / pano2vr \u90FD\u9760 event.ctrlKey \u628A\u7F29\u653E\u548C\u6EDA\u52A8\u5206\u5F00\u3002\u63A9\u7801\u5199\u6B7B false
|
|
1639
|
+
* \u65F6\u634F\u5408\u4E0E\u666E\u901A\u6EDA\u52A8\u65E0\u4ECE\u533A\u5206\u3002
|
|
1640
|
+
*/
|
|
1641
|
+
var ptrMods = 0;
|
|
1359
1642
|
/** \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
1643
|
var PTR_DBLCLICK_MS = 500;
|
|
1361
1644
|
|
|
@@ -1441,10 +1724,12 @@ ${gs(t.seedScript)}
|
|
|
1441
1724
|
buttons: o.buttons != null ? o.buttons : ptrButtons,
|
|
1442
1725
|
movementX: o.movementX || 0,
|
|
1443
1726
|
movementY: o.movementY || 0,
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1727
|
+
// \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
|
|
1728
|
+
// \u4E8E\u662F\u89E6\u6478\u677F\u634F\u5408\uFF08= ctrlKey \u7684 wheel\uFF09\u65E0\u6CD5\u4E0E\u666E\u901A\u6EDA\u52A8\u533A\u5206\u3002
|
|
1729
|
+
ctrlKey: (ptrMods & 1) !== 0,
|
|
1730
|
+
shiftKey: (ptrMods & 2) !== 0,
|
|
1731
|
+
altKey: (ptrMods & 4) !== 0,
|
|
1732
|
+
metaKey: (ptrMods & 8) !== 0,
|
|
1448
1733
|
};
|
|
1449
1734
|
if ("relatedTarget" in o) init.relatedTarget = o.relatedTarget || null;
|
|
1450
1735
|
// \`button: -1\` \u65E0\u6CD5\u7ECF MouseEvent \u6784\u9020\u5668\u8868\u8FBE\uFF1AChromium \u628A -1 \u89C4\u8303\u5316\u6210 0
|
|
@@ -1554,6 +1839,8 @@ ${gs(t.seedScript)}
|
|
|
1554
1839
|
* @param {number} y \u540C\u4E0A\uFF0C\u76F8\u5BF9\u4E0A\u8FB9\uFF0CY \u671D\u4E0B
|
|
1555
1840
|
* @param {number} [buttons] \u6309\u952E\u4F4D\u63A9\u7801\uFF0Cbit0 \u5DE6\u952E\u3002\u4E0E\u573A\u666F\u901A\u9053\u540C\u4E00\u7EA6\u5B9A\uFF0C
|
|
1556
1841
|
* \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
|
|
1842
|
+
* @param {number} [mods] \u4FEE\u9970\u952E\u63A9\u7801\uFF1Abit0 ctrl / bit1 shift / bit2 alt / bit3 meta\u3002
|
|
1843
|
+
* \u7701\u7565\u7B49\u4E8E 0\uFF08\u6539\u52A8\u524D\u7684\u5168 false \u884C\u4E3A\uFF09
|
|
1557
1844
|
*
|
|
1558
1845
|
* \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
1846
|
* \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 +1849,7 @@ ${gs(t.seedScript)}
|
|
|
1562
1849
|
* \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
1850
|
* \u5728\u51BB\u7ED3\u4E2D\u7EE7\u7EED\u63A8\u8FDB\uFF0C\u6062\u590D\u65F6\u753B\u9762\u8DF3\u4E00\u4E0B\u3002
|
|
1564
1851
|
*/
|
|
1565
|
-
w.__wePushPointer = function (x, y, buttons) {
|
|
1852
|
+
w.__wePushPointer = function (x, y, buttons, mods) {
|
|
1566
1853
|
if (paused) return;
|
|
1567
1854
|
var nx = Number(x);
|
|
1568
1855
|
var ny = Number(y);
|
|
@@ -1570,6 +1857,7 @@ ${gs(t.seedScript)}
|
|
|
1570
1857
|
// \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
1858
|
if (!isFinite(nx) || !isFinite(ny)) return;
|
|
1572
1859
|
var mask = Number(buttons) || 0;
|
|
1860
|
+
ptrMods = Number(mods) || 0;
|
|
1573
1861
|
var moved = !ptrHas || nx !== ptrX || ny !== ptrY;
|
|
1574
1862
|
var maskChanged = mask !== ptrButtons;
|
|
1575
1863
|
// \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 +1911,204 @@ ${gs(t.seedScript)}
|
|
|
1623
1911
|
ptrDownTarget = null;
|
|
1624
1912
|
};
|
|
1625
1913
|
|
|
1914
|
+
/**
|
|
1915
|
+
* \u5916\u90E8\u6EDA\u8F6E\u6CE8\u5165\uFF08\u5BBF\u4E3B\u6355\u83B7 scrollWheel / magnify \u624B\u52BF\u540E\u63A8\u5165\uFF09\u3002
|
|
1916
|
+
*
|
|
1917
|
+
* @param {number} x \u76F8\u5BF9 iframe \u89C6\u53E3\u5DE6\u8FB9\u7684 **CSS \u50CF\u7D20**\uFF08= clientX \u7A7A\u95F4\uFF09
|
|
1918
|
+
* @param {number} y \u540C\u4E0A\uFF0C\u76F8\u5BF9\u4E0A\u8FB9\uFF0CY \u671D\u4E0B
|
|
1919
|
+
* @param {number} dx \u6A2A\u5411\u6EDA\u52A8\u91CF\uFF0C\u6B63 = \u5185\u5BB9\u5411\u53F3\uFF08\u4E0E DOM deltaX \u540C\u5411\uFF09
|
|
1920
|
+
* @param {number} dy \u7EB5\u5411\u6EDA\u52A8\u91CF\uFF0C\u6B63 = \u5185\u5BB9\u5411\u4E0B\uFF08\u4E0E DOM deltaY \u540C\u5411\uFF0C
|
|
1921
|
+
* \u4E0E macOS NSEvent.scrollingDeltaY **\u53CD\u5411**\uFF0C\u53D6\u53CD\u7531\u5BBF\u4E3B\u8D1F\u8D23\uFF09
|
|
1922
|
+
* @param {number} [mode] deltaMode\uFF1A0 \u50CF\u7D20 / 1 \u884C / 2 \u9875\u3002\u89E6\u6478\u677F\u4E0E Magic Mouse \u6052\u4E3A 0
|
|
1923
|
+
* @param {number} [mods] \u4FEE\u9970\u952E\u63A9\u7801\uFF0Cbit0 ctrl\u3002**\u89E6\u6478\u677F\u53CC\u6307\u634F\u5408 = ctrl + \u6EDA\u8F6E**
|
|
1924
|
+
*
|
|
1925
|
+
* ---- \u4E3A\u4EC0\u4E48\u5FC5\u987B\u8865\u53D1\u65E7\u5F0F \`mousewheel\`\uFF08\u8BED\u6599\u51B3\u5B9A\uFF0C\u6F0F\u4E86\u547D\u4E2D\u7387\u4E3A 0\uFF09----
|
|
1926
|
+
*
|
|
1927
|
+
* \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
|
|
1928
|
+
* - 3406740580 pano2vr\uFF08\u552F\u4E00\u4F5C\u8005\u8BBE\u8BA1\u5185\u7684\u6EDA\u8F6E\u4EA4\u4E92\uFF0C\u6EDA\u8F6E\u6539\u5168\u666F FOV\uFF09\uFF1A
|
|
1929
|
+
* \`addEventListener("mousewheel")\` + \`("DOMMouseScroll")\`\uFF0Chandler \u53D6
|
|
1930
|
+
* \`a.detail ? -1*a.detail : a.wheelDelta/40\`\uFF1B
|
|
1931
|
+
* - 2179153203 ge1doot\uFF1A\`onmousewheel\` \u91CC \`-event.wheelDelta * .25\`\uFF1B
|
|
1932
|
+
* - 2517518192 GameMaker \u8FD0\u884C\u65F6\uFF1A\`canvas.onmousewheel\` + DOMMouseScroll\u3002
|
|
1933
|
+
* \u53EA\u542C \`wheel\` \u7684\u662F OrbitControls\uFF081808443523\uFF09\u4E0E react-lrc\uFF082905017768\uFF09\u3002
|
|
1934
|
+
* \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
|
|
1935
|
+
*
|
|
1936
|
+
* ---- \u4E3A\u4EC0\u4E48**\u4E0D**\u53D1 \`DOMMouseScroll\`\uFF08\u5426\u5219\u6EDA\u52A8\u91CF\u7FFB\u500D\uFF09----
|
|
1937
|
+
*
|
|
1938
|
+
* \u4E0A\u9762\u4E09\u5904\u65E7\u5F0F\u6D88\u8D39\u65B9**\u6BCF\u4E00\u5904\u90FD\u540C\u65F6\u6CE8\u518C\u4E86 \`mousewheel\` \u548C \`DOMMouseScroll\`**\uFF0C
|
|
1939
|
+
* \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
|
|
1940
|
+
* 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
|
|
1941
|
+
* \u8FD9\u4E24\u4E2A\uFF08Chromium \u53EA\u53D1 wheel + mousewheel\uFF09\u3002\u4E14\u5168\u8BED\u6599\u6CA1\u6709\u4EFB\u4F55\u4E00\u5F20\u53EA\u542C
|
|
1942
|
+
* DOMMouseScroll \u2014\u2014 \u5B83\u6CA1\u6709\u72EC\u5360\u6D88\u8D39\u65B9\uFF0C\u53D1\u5B83\u7EAF\u662F\u8D1F\u6536\u76CA\u3002
|
|
1943
|
+
*
|
|
1944
|
+
* \u6682\u505C\u671F\u95F4\u4E22\u5F03\uFF0C\u4E0E __wePushPointer \u4E00\u81F4\u3002
|
|
1945
|
+
*/
|
|
1946
|
+
w.__wePushWheel = function (x, y, dx, dy, mode, mods) {
|
|
1947
|
+
if (paused) return;
|
|
1948
|
+
// \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
|
|
1949
|
+
// \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
|
|
1950
|
+
// \u518D\u4E0E\u5408\u6CD5\u7684 dx \u4E00\u8D77\u6D3E\u53D1\u51FA\u4E00\u4E2A\u534A\u6C61\u67D3\u7684\u4E8B\u4EF6\uFF09\u3002
|
|
1951
|
+
var ndx = Number(dx);
|
|
1952
|
+
var ndy = Number(dy);
|
|
1953
|
+
// \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
|
|
1954
|
+
// \u4E4B\u540E\u65E0\u8BBA\u600E\u4E48\u6EDA\u90FD\u6062\u590D\u4E0D\u4E86\uFF0C\u4E14\u6CA1\u6709\u4EFB\u4F55\u62A5\u9519\u3002
|
|
1955
|
+
if (!isFinite(ndx) || !isFinite(ndy)) return;
|
|
1956
|
+
// \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
|
|
1957
|
+
// \u7A7A\u4E8B\u4EF6\u4F1A\u8BA9\u4F5C\u8005\u7684\u300C\u6709\u6CA1\u6709\u5728\u6EDA\u300D\u5224\u5B9A\u4E00\u76F4\u4E3A\u771F\u3002
|
|
1958
|
+
if (ndx === 0 && ndy === 0) return;
|
|
1959
|
+
var dmode = Number(mode) || 0;
|
|
1960
|
+
ptrMods = Number(mods) || 0;
|
|
1961
|
+
|
|
1962
|
+
// \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
|
|
1963
|
+
// \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
|
|
1964
|
+
// \u4E00\u8FB9\u7F29\u653E\u4E00\u8FB9\u5F80\u89D2\u4E0A\u8DD1\u3002
|
|
1965
|
+
var px = ptrX;
|
|
1966
|
+
var py = ptrY;
|
|
1967
|
+
if (!ptrHas) {
|
|
1968
|
+
px = ptrViewportW() / 2;
|
|
1969
|
+
py = ptrViewportH() / 2;
|
|
1970
|
+
}
|
|
1971
|
+
var nx = Number(x);
|
|
1972
|
+
var ny = Number(y);
|
|
1973
|
+
if (isFinite(nx) && isFinite(ny)) {
|
|
1974
|
+
px = nx;
|
|
1975
|
+
py = ny;
|
|
1976
|
+
ptrX = nx;
|
|
1977
|
+
ptrY = ny;
|
|
1978
|
+
ptrHas = true;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
var target = ptrHitTest(px, py);
|
|
1982
|
+
// \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
|
|
1983
|
+
// \uFF08\u4E0E __wePushPointer \u540C\u4E00\u7406\u7531\uFF09\uFF0C\u4E14 pano2vr \u7684 handler \u5F00\u5934\u5C31 \`this.zc(a.target)\`
|
|
1984
|
+
// \u6821\u9A8C\u547D\u4E2D\u662F\u4E0D\u662F\u81EA\u5DF1\u7684\u5BB9\u5668\u3002
|
|
1985
|
+
if (target !== ptrTarget) {
|
|
1986
|
+
ptrCrossBoundary(ptrTarget, target, px, py);
|
|
1987
|
+
ptrTarget = target;
|
|
1988
|
+
}
|
|
1989
|
+
|
|
1990
|
+
// (1) \u73B0\u4EE3 \`wheel\`\u3002**\u5FC5\u987B cancelable**\uFF1Apano2vr \u4E0E ge1doot \u90FD\u5728 handler \u91CC\u8C03
|
|
1991
|
+
// preventDefault()\uFF0C\u4E0D\u53EF\u53D6\u6D88\u65F6 Chromium \u4F1A\u5728\u63A7\u5236\u53F0\u5237 Unable to preventDefault
|
|
1992
|
+
// \u4E14\u4F5C\u8005\u7684 \`return false\` \u5206\u652F\u8BED\u4E49\u6F02\u79FB\u3002
|
|
1993
|
+
ptrDispatchWheel(target, px, py, ndx, ndy, dmode);
|
|
1994
|
+
|
|
1995
|
+
// (2) \u65E7\u5F0F \`mousewheel\`\uFF08Chromium \u7684 legacy alias\uFF0C\u4E0E\u771F\u5B9E\u6D4F\u89C8\u5668\u540C\u6B3E\u7EC4\u5408\uFF09\u3002
|
|
1996
|
+
// wheelDelta \u4E0E deltaY **\u53CD\u53F7**\uFF1A\u4E00\u683C\u6807\u51C6\u6EDA\u52A8\u5728 Chromium \u91CC\u662F deltaY=+100\u3001
|
|
1997
|
+
// wheelDelta=-120\uFF0C\u6545\u7CFB\u6570 1.2\u3002pano2vr \u7684 \`wheelDelta/40\` \u5F97 -3 \u2192 \u7F29\u5C0F\uFF0C
|
|
1998
|
+
// \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
|
|
1999
|
+
var pxPerUnit = dmode === 1 ? WHEEL_LINE_PX : dmode === 2 ? ptrViewportH() || 800 : 1;
|
|
2000
|
+
var legacyY = -ndy * pxPerUnit * 1.2;
|
|
2001
|
+
var legacyX = -ndx * pxPerUnit * 1.2;
|
|
2002
|
+
var ev = ptrMakeEvent("mousewheel", px, py, { button: -1 });
|
|
2003
|
+
if (ev) {
|
|
2004
|
+
ptrDefine(ev, "wheelDelta", legacyY);
|
|
2005
|
+
ptrDefine(ev, "wheelDeltaY", legacyY);
|
|
2006
|
+
ptrDefine(ev, "wheelDeltaX", legacyX);
|
|
2007
|
+
// detail \u6052\u4E3A 0\uFF1A\u65E7\u5F0F Firefox \u90A3\u5957 \`a.detail ? -1*a.detail : a.wheelDelta/40\`
|
|
2008
|
+
// \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
|
|
2009
|
+
ptrDefine(ev, "detail", 0);
|
|
2010
|
+
try {
|
|
2011
|
+
target && target.dispatchEvent && target.dispatchEvent(ev);
|
|
2012
|
+
} catch (_) {
|
|
2013
|
+
/* \u4F5C\u8005 handler \u629B\u9519\u4E0D\u6253\u65AD\uFF08\u4E0E ptrDispatch \u540C\u4E00\u7406\u7531\uFF09 */
|
|
2014
|
+
}
|
|
2015
|
+
}
|
|
2016
|
+
};
|
|
2017
|
+
|
|
2018
|
+
/** \u4E00\u683C\u300C\u884C\u300D\u6EDA\u52A8\u6298\u7B97\u7684\u50CF\u7D20\u6570\uFF0C\u4E0E Chromium \u7684 kDefaultLineHeight \u91CF\u7EA7\u4E00\u81F4\u3002 */
|
|
2019
|
+
var WHEEL_LINE_PX = 40;
|
|
2020
|
+
|
|
2021
|
+
function ptrViewportW() {
|
|
2022
|
+
try {
|
|
2023
|
+
return Number(w.innerWidth) || Number(w.document.documentElement.clientWidth) || 0;
|
|
2024
|
+
} catch (_) {
|
|
2025
|
+
return 0;
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
|
|
2029
|
+
function ptrViewportH() {
|
|
2030
|
+
try {
|
|
2031
|
+
return Number(w.innerHeight) || Number(w.document.documentElement.clientHeight) || 0;
|
|
2032
|
+
} catch (_) {
|
|
2033
|
+
return 0;
|
|
2034
|
+
}
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
/** \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 */
|
|
2038
|
+
function ptrDefine(ev, key, value) {
|
|
2039
|
+
try {
|
|
2040
|
+
Object.defineProperty(ev, key, {
|
|
2041
|
+
configurable: true,
|
|
2042
|
+
get: function () {
|
|
2043
|
+
return value;
|
|
2044
|
+
},
|
|
2045
|
+
});
|
|
2046
|
+
} catch (_) {
|
|
2047
|
+
try {
|
|
2048
|
+
ev[key] = value;
|
|
2049
|
+
} catch (__) {
|
|
2050
|
+
/* \u53EA\u8BFB\u4E14\u4E0D\u53EF\u91CD\u5B9A\u4E49\u65F6\u653E\u5F03\u8BE5\u5B57\u6BB5 */
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
|
|
2055
|
+
/**
|
|
2056
|
+
* \u6D3E\u53D1\u73B0\u4EE3 \`wheel\`\u3002\u4F18\u5148\u771F \`WheelEvent\`\uFF08\u4F5C\u8005\u8BFB deltaMode / deltaZ \u65F6\u624D\u5BF9\uFF09\uFF1B
|
|
2057
|
+
* \u73AF\u5883\u6CA1\u6709\u65F6\u9000\u56DE MouseEvent \u518D\u8865\u5B57\u6BB5 \u2014\u2014 \u4E8B\u4EF6\u540D\u7167\u65E7\uFF0C\`addEventListener('wheel')\`
|
|
2058
|
+
* \u4ECD\u7136\u6536\u5230\u3002
|
|
2059
|
+
*/
|
|
2060
|
+
function ptrDispatchWheel(target, x, y, dx, dy, mode) {
|
|
2061
|
+
if (!target || typeof target.dispatchEvent !== "function") return;
|
|
2062
|
+
var init = {
|
|
2063
|
+
bubbles: true,
|
|
2064
|
+
cancelable: true,
|
|
2065
|
+
composed: true,
|
|
2066
|
+
view: w,
|
|
2067
|
+
detail: 0,
|
|
2068
|
+
clientX: x,
|
|
2069
|
+
clientY: y,
|
|
2070
|
+
screenX: x + (Number(w.screenX) || 0),
|
|
2071
|
+
screenY: y + (Number(w.screenY) || 0),
|
|
2072
|
+
// \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
|
|
2073
|
+
// \u586B 0 \u4F1A\u8BA9 GameMaker \u4E00\u65CF\u8BEF\u8BA4\u4E3A\u5DE6\u952E\u6309\u7740\uFF09
|
|
2074
|
+
button: -1,
|
|
2075
|
+
buttons: ptrButtons,
|
|
2076
|
+
ctrlKey: (ptrMods & 1) !== 0,
|
|
2077
|
+
shiftKey: (ptrMods & 2) !== 0,
|
|
2078
|
+
altKey: (ptrMods & 4) !== 0,
|
|
2079
|
+
metaKey: (ptrMods & 8) !== 0,
|
|
2080
|
+
deltaX: dx,
|
|
2081
|
+
deltaY: dy,
|
|
2082
|
+
deltaZ: 0,
|
|
2083
|
+
deltaMode: mode,
|
|
2084
|
+
};
|
|
2085
|
+
var ev = null;
|
|
2086
|
+
try {
|
|
2087
|
+
if (typeof w.WheelEvent === "function") ev = new w.WheelEvent("wheel", init);
|
|
2088
|
+
} catch (_) {
|
|
2089
|
+
/* \u9000\u56DE MouseEvent */
|
|
2090
|
+
}
|
|
2091
|
+
if (!ev) {
|
|
2092
|
+
try {
|
|
2093
|
+
if (typeof w.MouseEvent === "function") ev = new w.MouseEvent("wheel", init);
|
|
2094
|
+
} catch (_) {
|
|
2095
|
+
/* \u5FFD\u7565 */
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
if (!ev) return;
|
|
2099
|
+
// MouseEvent \u9000\u8DEF\u4E0A delta* \u4E0D\u4F1A\u88AB\u6784\u9020\u5668\u91C7\u7EB3\uFF0C\u5FC5\u987B\u8865\uFF1BWheelEvent \u8DEF\u5F84\u4E0B
|
|
2100
|
+
// \u8BFB\u5230\u7684\u503C\u4E0E init \u76F8\u540C\uFF0C\u6761\u4EF6\u4E0D\u6210\u7ACB\uFF0C\u8865\u4E5F\u4E0D\u4F1A\u53D1\u751F\u3002
|
|
2101
|
+
if (ev.deltaX !== dx) ptrDefine(ev, "deltaX", dx);
|
|
2102
|
+
if (ev.deltaY !== dy) ptrDefine(ev, "deltaY", dy);
|
|
2103
|
+
if (ev.deltaMode !== mode) ptrDefine(ev, "deltaMode", mode);
|
|
2104
|
+
if (ev.button !== -1) ptrDefine(ev, "button", -1);
|
|
2105
|
+
try {
|
|
2106
|
+
target.dispatchEvent(ev);
|
|
2107
|
+
} catch (_) {
|
|
2108
|
+
/* \u4F5C\u8005 handler \u629B\u9519\u4E0D\u6253\u65AD\u540E\u7EED\u65E7\u5F0F\u4E8B\u4EF6 */
|
|
2109
|
+
}
|
|
2110
|
+
}
|
|
2111
|
+
|
|
1626
2112
|
/**
|
|
1627
2113
|
* \u6307\u9488\u79BB\u5F00\u672C\u7A97\u53E3\uFF08\u9F20\u6807\u53BB\u4E86\u522B\u7684\u663E\u793A\u5668\uFF09\u3002
|
|
1628
2114
|
*
|
|
@@ -1714,7 +2200,7 @@ ${gs(t.seedScript)}
|
|
|
1714
2200
|
installRafThrottle();
|
|
1715
2201
|
})(window);
|
|
1716
2202
|
|
|
1717
|
-
`;function
|
|
1718
|
-
`)}function Au(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=pn(e.cfg.fit)==="cover";o();const m=x&&d>0&&y>0?ku(p):null,M=m?Ru(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 Tu(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 Su(e,n,t){e.pointerCtl={push(r){if(!n.isConnected)return;const o=t.getBoundingClientRect(),i=n.getBoundingClientRect(),s=Tu(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 yo(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),Au(e,i,t),o.injected&&Su(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),Fn(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||pu(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 Eu=.005,Pu=.01,Cu=.2,Lu=6;function Ru(e,n,t){if(!(e>0)||!(n>0)||!(t>0))return null;const r=e/n;if(Math.abs(r-t)<=Eu)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 ku(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*Pu)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<Cu||u>Lu))return{contentAspect:u}}return null}function ln(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 Fu(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,ln(r)),i.addColorStop(1,ln(o)),t.fillStyle=i,t.fillRect(0,0,64,64),n.toDataURL("image/jpeg",.85)}catch{return""}}function Nu(){return we.createSimulatedMedia()}function Uu(e,n,t){const r=we.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=Fu(t);Qe(e,a=>a.__wePushMedia?.({op:"thumbnail",thumbnail:s,hasThumbnail:!!i.hasThumbnail||!!s,primaryColor:ln(i.primaryColor),secondaryColor:ln(i.secondaryColor),tertiaryColor:ln(i.tertiaryColor),textColor:ln(i.textColor),highContrastColor:ln(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 we.cloneMediaSnapshot(t)}function ys(e,n,t,r={driver:null}){if(!n)return;const o=xu(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),yu);if(!(l-a<d*.85)){a=l;try{const y=i();y.tick?.(l);const x=y.snapshot(),m=mu(hu,x.left,x.right);Qe(e,M=>M.__wePushAudio?.(m)),t&&l-t.last>200&&Fn(e,l)}catch{}}};s=requestAnimationFrame(c);const u=e.sceneCleanup;e.sceneCleanup=()=>{cancelAnimationFrame(s);try{u?.()}catch{}}}function vs(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=Uu(e,o,u.snapshot)}catch{}}};r=requestAnimationFrame(s);const a=e.sceneCleanup;e.sceneCleanup=()=>{cancelAnimationFrame(r);try{a?.()}catch{}}}function Du(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 Bu(e){try{return new URL(e,location.href).origin===location.origin}catch{return!1}}function Iu(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 Ou(e){try{const n=new URL("project.json",new URL(e,location.href)),t=await fetch(n.href,{credentials:"same-origin"});return t.ok?Iu(await t.json()):{}}catch{return{}}}function $u(e,n){const t={...e};if(n)for(const[r,o]of Object.entries(n))t[r]={value:o};return t}function ju(e,n){on(e),e.cfg=n;const t=Mu(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}Du(e);const o=n,i=o._webAudio===null||e.audioDisabled?null:o._webAudio??vu(),s=o._webMedia===null||e.mediaDisabled?null:o._webMedia??Nu(),a=f=>{se(e,n,`\u7F51\u9875\u58C1\u7EB8 shim \u6CE8\u5165\u5931\u8D25\uFF08${f}\uFF09\uFF0C\u9000\u56DE\u88F8 iframe`),yo(e,n,t,r,{injected:!1}),ys(e,null),vs(e,null);let p=0;const d=y=>{e.iframe&&(p=requestAnimationFrame(d),!e.paused&&Fn(e,y))};p=requestAnimationFrame(d),(e.wallpaperDisposers??=[]).push(()=>cancelAnimationFrame(p))},c={last:0},u={driver:null},l=()=>{if(ys(e,i,c,u),vs(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 hs({origin:location.origin});if(f.dead){try{p.dispose()}catch{}return}f.handle=p;const d=p.status();d.audio==="mic"?(u.driver=wu(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 Ou(r),p=$u(f,e.liveUserProps);if(e.liveUserProps=Object.fromEntries(Object.entries(p).map(([d,y])=>[d,y.value])),Bu(r)){yo(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(uu(y)){a("CSP \u963B\u6B62 inline script");return}const x=fu(y,du,{baseHref:lu(r),seedScript:_u(p,n.sceneFps,n.muted===!1?1:0)}),m=new Blob([x],{type:"text/html;charset=utf-8"}),M=URL.createObjectURL(m);yo(e,n,t,M,{blobUrl:M,injected:!0,frameClock:c}),l()}catch(d){a(d instanceof Error?d.message:String(d))}})()}function Sr(e,n){const t=String(n.type??"").toLowerCase();n={...n,type:t},e.cfg=n,(t==="video"||t==="gif"||t==="image")&&n.src?kl(e,n):t==="scene"&&(n.source||n.src)?au(e,n):t==="web"&&n.src?ju(e,n):e.onUnhandledType?.(n)}class jt{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 jt(this.x+n.x,this.y+n.y,this.z+n.z)}subtract(n){return new jt(this.x-n.x,this.y-n.y,this.z-n.z)}multiply(n){return typeof n=="number"?new jt(this.x*n,this.y*n,this.z*n):new jt(this.x*n.x,this.y*n.y,this.z*n.z)}toString(){return`${this.x} ${this.y} ${this.z}`}}function _t(e,n,t){if(e instanceof jt)return e;if(Array.isArray(e))return new jt(e[0]??0,e[1]??0,e[2]??0);if(typeof e=="object"&&e!==null){const r=e;return new jt(r.x??0,r.y??0,r.z??0)}return new jt(e,n??0,t??0)}const zu=[.35,.38,.45],Vu=[.12,.13,.17],Wu=[.72,.76,.84],xs=[.95,.96,.98];function Hu(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 ws(e){const n=Number(e.position)||0,t=Array.isArray(e.lyrics)?e.lyrics:[],{line:r,index:o}=Hu(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:_t(e.primaryColor??zu),secondaryColor:_t(e.secondaryColor??Vu),tertiaryColor:_t(e.tertiaryColor??Wu),textColor:_t(e.textColor??xs),highContrastColor:_t(e.highContrastColor??e.textColor??xs),trackIndex:Number(e.trackIndex)||0,lyrics:t,lyricLine:r,lyricIndex:o}}function Xu(e={},n={}){let t={...e},r=ws(t);return{get snapshot(){return r},set(o){t={...t,...o},r=ws(t)},update(){},skipNext:n.skipNext,skipPrevious:n.skipPrevious,play:n.play,pause:n.pause,playPause:n.playPause}}function Gu(e){return e==="fit"?"contain":e==="fill"?"cover":e==="contain"||e==="stretch"?e:"cover"}function Yu(e){const n=e?.type;return typeof n=="string"&&n.toLowerCase()==="web"}const vo=new Set(["video","gif","image"]);function qu(e){const n=e?.type;if(typeof n!="string")return null;const t=n.toLowerCase();return vo.has(t)?t:null}function xo(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 Ms(e,n){const t={fit:Gu(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(Yu(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=qu(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=xo(e),l=vo.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=(vo.has(String(c).toLowerCase())?String(c).toLowerCase():null)??(a?mo(a):null);if(a&&u){const l=xo(e);return{...t,type:u,src:a,canvas:l,source:n.source}}}const s=xo(e);return{...t,type:"scene",canvas:s,source:n.source}}function _s(e,n){const t=Es(),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,To(t),t.sceneCtl?.resume()},get paused(){return!!t.paused},setFit(d){t.cfg.fit=d,Fr(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,Sr(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:_t(0,0,0),secondaryColor:_t(0,0,0),tertiaryColor:_t(0,0,0),textColor:_t(1,1,1),highContrastColor:_t(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 Ms(i,o);x.type!=="web"&&x.canvas instanceof HTMLCanvasElement&&(i=x.canvas),t.cfg=x,t.paused=!1,t.info=void 0,Fr(t),o.properties&&(t.liveUserProps={...o.properties});const m=u(),M=l();Sr(t,x);try{await Promise.race([m,M.promise])}finally{M.off()}},release(){on(t)},restore(){Sr(t,t.cfg)},destroy(){Ps(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 Ls(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 Ms(e,d);y.type!=="web"&&y.canvas instanceof HTMLCanvasElement&&(i=y.canvas),t.cfg=y,t.paused=!1,t.info=void 0,Fr(t),d.properties&&Object.keys(d.properties).length&&(t.liveUserProps={...d.properties});const x=u(),m=l();Sr(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 Zu(e,n){const t=_s(e,n);return await t.__applyOptions(n),t}export{Ol as bytesSource,Xu as createMediaSource,_s as createScene,Il as fileSource,ss as httpSource,_t as mediaColor,$l as mediaSource,Zu as mount,mo as sniffMediaType};
|
|
2203
|
+
`;function Ht(t,e){try{const n=t.iframe?.contentWindow;n&&e(n)}catch{}}function C2(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,d=r.setTimeout(()=>{o.delete(l),a(f=>{try{u(f)}catch{}})},s);return o.set(l,d),l},r.cancelAnimationFrame=u=>{const l=o.get(u);l!==void 0&&(r.clearTimeout(l),o.delete(u))}}catch{}}const I2=new Float32Array(128);function R2(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 B2=1.8,F2=1.8,D2=30;function up(t){const e=Number(t)||0;return e<=0?0:Math.min(1,Math.pow(e,F2)*B2)}function N2(){const t=nm(),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]=up(i[a]),n[a]=up(s[a])):(e[a]=(Number(r.left64[a])||0)*.2,n[a]=(Number(r.right64[a])||0)*.2);return{left:e,right:n}}}}function L2(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 U2(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 O2(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?(be(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 z2(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(`
|
|
2204
|
+
`)}function H2(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 f=null;try{f=e.contentDocument}catch{return}if(!f)return;const h=n.clientWidth||window.innerWidth||0,p=n.clientHeight||window.innerHeight||0,m=Ur(t.cfg.fit)==="cover";i();const g=m&&h>0&&p>0?Q2(f):null,y=g?G2(h,p,g.contentAspect):null,w=y?`${Math.round(y.width)}x${Math.round(y.height)}`:"full";if(!y){s="full";return}e.style.cssText=r+`left:${y.left}px;top:${y.top}px;width:${y.width}px;height:${y.height}px;`,w!==s&&(s=w,be(t,t.cfg,`\u7F51\u9875\u58C1\u7EB8\u9732\u5E95\u81EA\u9002\u914D\uFF1A\u89C6\u53E3\u6309\u5185\u5BB9\u6BD4\u4F8B\u6539\u4E3A ${Math.round(y.width)}\xD7${Math.round(y.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 f of[120,400,1200])u.push(window.setTimeout(a,f));try{const f=e.contentDocument;if(f)for(const h of f.querySelectorAll("video,img"))h.addEventListener("loadedmetadata",a,{once:!0}),h.addEventListener("load",a,{once:!0})}catch{}};e.addEventListener("load",l),t.webRelayout=a;const d=t.sceneCleanup;t.sceneCleanup=()=>{window.removeEventListener("resize",o),c?.disconnect();for(const f of u)clearTimeout(f);e.removeEventListener("load",l),t.webRelayout===a&&(t.webRelayout=void 0);try{d?.()}catch{}}}function V2(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 W2(t,e,n){const r=(i,s)=>{if(!e.isConnected)return null;const a=n.getBoundingClientRect(),o=e.getBoundingClientRect();return V2(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&&Ht(t,a=>a.__wePushPointer?.(s.x,s.y,Number(i.buttons)||0,Number(i.mods)||0))},leave(){Ht(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;Ht(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 pu(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),H2(t,s,n),i.injected&&W2(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),zr(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||C2(t,s,l)}catch{}Ht(t,l=>{const d={};for(const[f,h]of Object.entries(t.liveUserProps??{}))d[f]={value:h};l.__weApplyProps?.(d),l.__weSetFps?.(t.cfg.sceneFps??60),l.__weSetVolume?.(Jo(t)),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 j2=.005,q2=.01,X2=.2,$2=6;function G2(t,e,n){if(!(t>0)||!(e>0)||!(n>0))return null;const r=t/e;if(Math.abs(r-n)<=j2)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 Q2(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*q2)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<X2||u>$2))return{contentAspect:u}}return null}function Si(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 Y2(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,Si(i)),a.addColorStop(1,Si(s)),r.fillStyle=a,r.fillRect(0,0,64,64),n.toDataURL("image/jpeg",.85)}catch{return""}}function K2(){return We.createSimulatedMedia()}function Z2(t,e,n){const r=We.diffMediaEvents(e,n);for(const{name:i,event:s}of r)if(i==="mediaStatusChanged")Ht(t,a=>a.__wePushMedia?.({op:"status",enabled:!!s.enabled}));else if(i==="mediaPropertiesChanged")Ht(t,a=>a.__wePushMedia?.({op:"properties",title:s.title??"",artist:s.artist??"",album:s.album??"",albumArtist:s.albumArtist??""}));else if(i==="mediaThumbnailChanged"){const a=Y2(n);Ht(t,o=>o.__wePushMedia?.({op:"thumbnail",thumbnail:a,hasThumbnail:!!s.hasThumbnail||!!a,primaryColor:Si(s.primaryColor),secondaryColor:Si(s.secondaryColor),tertiaryColor:Si(s.tertiaryColor),textColor:Si(s.textColor),highContrastColor:Si(s.highContrastColor)}))}else i==="mediaPlaybackChanged"?Ht(t,a=>a.__wePushMedia?.({op:"playback",state:Number(s.state)||0})):i==="mediaTimelineChanged"&&Ht(t,a=>a.__wePushMedia?.({op:"timeline",position:Number(s.position)||0,duration:Number(s.duration)||0}));return We.cloneMediaSnapshot(n)}function fp(t,e,n,r={driver:null}){if(!e)return;const i=L2(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 d=t.cfg.sceneFps||60,h=1e3/Math.min(Math.max(1,d),D2);if(!(l-o<h*.85)){o=l;try{const p=s();p.tick?.(l);const m=p.snapshot(),g=R2(I2,m.left,m.right);Ht(t,y=>y.__wePushAudio?.(g)),n&&l-n.last>200&&zr(t,l)}catch{}}};a=requestAnimationFrame(c);const u=t.sceneCleanup;t.sceneCleanup=()=>{cancelAnimationFrame(a);try{u?.()}catch{}}}function dp(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=Z2(t,i,u.snapshot)}catch{}}};r=requestAnimationFrame(a);const o=t.sceneCleanup;t.sceneCleanup=()=>{cancelAnimationFrame(r);try{o?.()}catch{}}}function J2(t){t.sceneCtl={pause(){t.paused=!0,Ht(t,e=>e.__weSetPaused?.(!0))},resume(){t.paused=!1,Ht(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,Ht(t,r=>r.__weApplyProps?.(e))}}}function ex(t){try{return new URL(t,location.href).origin===location.origin}catch{return!1}}function tx(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 nx(t){try{const e=new URL("project.json",new URL(t,location.href)),n=await fetch(e.href,{credentials:"same-origin"});return n.ok?tx(await n.json()):{}}catch{return{}}}function rx(t,e){const n={...t};if(e)for(const[r,i]of Object.entries(e))n[r]={value:i};return n}function ix(t,e){Or(t),t.cfg=e;const n=O2(t,e);if(!n){be(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){be(t,e,"\u7F51\u9875\u58C1\u7EB8\uFF1A\u7F3A\u5C11 src"),t.onError?.(new Error("\u7F51\u9875\u58C1\u7EB8\uFF1A\u7F3A\u5C11 src"));return}J2(t);const i=e,s=i._webAudio===null||t.audioDisabled?null:i._webAudio??N2(),a=i._webMedia===null||t.mediaDisabled?null:i._webMedia??K2(),o=d=>{be(t,e,`\u7F51\u9875\u58C1\u7EB8 shim \u6CE8\u5165\u5931\u8D25\uFF08${d}\uFF09\uFF0C\u9000\u56DE\u88F8 iframe`),pu(t,e,n,r,{injected:!1}),fp(t,null),dp(t,null);let f=0;const h=p=>{t.iframe&&(f=requestAnimationFrame(h),!t.paused&&zr(t,p))};f=requestAnimationFrame(h),(t.wallpaperDisposers??=[]).push(()=>cancelAnimationFrame(f))},c={last:0},u={driver:null},l=()=>{if(fp(t,s,c,u),dp(t,a),e.liveSystem&&s){const d={handle:null,dead:!1};(t.wallpaperDisposers??=[]).push(()=>{d.dead=!0,u.driver=null;try{d.handle?.dispose()}catch{}d.handle=null}),(async()=>{try{const f=await np({origin:location.origin});if(d.dead){try{f.dispose()}catch{}return}d.handle=f;const h=f.status();h.audio==="mic"?(u.driver=U2(f),be(t,e,"liveSystem: \u7F51\u9875\u58C1\u7EB8\u97F3\u9891\u6539\u7528\u9EA6\u514B\u98CE")):be(t,e,`liveSystem: \u9EA6\u514B\u98CE\u4E0D\u53EF\u7528\uFF08${h.audio}\uFF09\uFF0C\u7F51\u9875\u58C1\u7EB8\u6CBF\u7528\u6A21\u62DF\u6E90`)}catch(f){be(t,e,`liveSystem: \u542F\u52A8\u5931\u8D25\uFF0C\u7F51\u9875\u58C1\u7EB8\u6CBF\u7528\u6A21\u62DF\u6E90 (${f?.message??f})`)}})()}};(async()=>{const d=await nx(r),f=rx(d,t.liveUserProps);if(t.liveUserProps=Object.fromEntries(Object.entries(f).map(([h,p])=>[h,p.value])),ex(r)){pu(t,e,n,r,{injected:!0,frameClock:c}),l(),t.iframe?.addEventListener("load",()=>{let p=!1;Ht(t,m=>{p=typeof m.__weSetPaused=="function"}),p||be(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(_2(p)){o("CSP \u963B\u6B62 inline script");return}const m=E2(p,M2,{baseHref:P2(r),seedScript:z2(f,e.sceneFps,Jo(t,e))}),g=new Blob([m],{type:"text/html;charset=utf-8"}),y=URL.createObjectURL(g);pu(t,e,n,y,{blobUrl:y,injected:!0,frameClock:c}),l()}catch(h){o(h instanceof Error?h.message:String(h))}})()}function gu(t,e){const n=String(e.type??"").toLowerCase();e={...e,type:n},t.cfg=e,(n==="video"||n==="gif"||n==="image")&&e.src?PA(t,e):n==="scene"&&(e.source||e.src)?T2(t,e):n==="web"&&e.src?ix(t,e):t.onUnhandledType?.(e)}class Mr{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 Mr(this.x+e.x,this.y+e.y,this.z+e.z)}subtract(e){return new Mr(this.x-e.x,this.y-e.y,this.z-e.z)}multiply(e){return typeof e=="number"?new Mr(this.x*e,this.y*e,this.z*e):new Mr(this.x*e.x,this.y*e.y,this.z*e.z)}toString(){return`${this.x} ${this.y} ${this.z}`}}function Dn(t,e,n){if(t instanceof Mr)return t;if(Array.isArray(t))return new Mr(t[0]??0,t[1]??0,t[2]??0);if(typeof t=="object"&&t!==null){const r=t;return new Mr(r.x??0,r.y??0,r.z??0)}return new Mr(t,e??0,n??0)}const sx=[.35,.38,.45],ax=[.12,.13,.17],ox=[.72,.76,.84],hp=[.95,.96,.98];function cx(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 mp(t){const e=Number(t.position)||0,n=Array.isArray(t.lyrics)?t.lyrics:[],{line:r,index:i}=cx(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:Dn(t.primaryColor??sx),secondaryColor:Dn(t.secondaryColor??ax),tertiaryColor:Dn(t.tertiaryColor??ox),textColor:Dn(t.textColor??hp),highContrastColor:Dn(t.highContrastColor??t.textColor??hp),trackIndex:Number(t.trackIndex)||0,lyrics:n,lyricLine:r,lyricIndex:i}}function lx(t={},e={}){let n={...t},r=mp(n);return{get snapshot(){return r},set(i){n={...n,...i},r=mp(n)},update(){},skipNext:e.skipNext,skipPrevious:e.skipPrevious,play:e.play,pause:e.pause,playPause:e.playPause}}function ux(t){const e=t?.type;return typeof e=="string"&&e.toLowerCase()==="web"}const yu=new Set(["video","gif","image"]);function fx(t){const e=t?.type;if(typeof e!="string")return null;const n=e.toLowerCase();return yu.has(n)?n:null}function zo(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 pp(t,e){const n={fit:Ur(e.fit),renderDpr:e.renderDpr??0,sceneFps:e.fps??60,muted:(e.volume??0)<=0,loop:!0,canvas:t,source:e.source,quality:e.quality};let r=null;try{r=await e.source.project?.()??null}catch{r=null}if(ux(r)){let c;try{c=(await e.source.webEntry?.())?.url}catch{c=void 0}if(!c&&e.source.key){const u=r&&typeof r.file=="string"&&String(r.file).trim().replace(/^\/+/,"")||"index.html";c=`${e.source.key.replace(/\/+$/,"")}/${u}`}if(!c)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:c,source:e.source}}const i=fx(r);if(i){let c,u;try{const f=await e.source.mediaEntry?.();c=f?.url,u=f?.type}catch{c=void 0}if(!c&&e.source.key){const f=r&&typeof r.file=="string"?String(r.file).trim().replace(/^\/+/,""):"";f&&(c=`${e.source.key.replace(/\/+$/,"")}/${f}`)}if(!c)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 l=yu.has(String(u).toLowerCase())?String(u).toLowerCase():i,d=l==="video"?t:zo(t);return{...n,type:l,src:c,canvas:d,source:e.source}}if(!(typeof r?.type=="string"?String(r.type).trim():"")&&typeof e.source.mediaEntry=="function"){let c,u;try{const d=await e.source.mediaEntry();c=d?.url,u=d?.type}catch{c=void 0}const l=(yu.has(String(u).toLowerCase())?String(u).toLowerCase():null)??(c?lu(c):null);if(c&&l){const d=l==="video"?t:zo(t);return{...n,type:l,src:c,canvas:d,source:e.source}}}const a=zo(t),o=cu(e.source.key);return{...n,type:"scene",canvas:a,source:e.source,...o?{src:o}:{}}}function gp(t,e){const n=Wp(),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 y of r.diagnostic)try{y(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 y of r.ready)try{y(g)}catch{}p()}}),l=()=>{let p=()=>{};return{promise:new Promise((g,y)=>{p=f.on("error",w=>y(w))}),off:p}},d=()=>{if(n.cfg.type!=="web"&&n.cfg.type!=="video"){if(Or(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=zo(t,!1);m!==n.cfg.canvas&&(n.cfg={...n.cfg,canvas:m},s=m)}gu(n,n.cfg)},f={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,Fu(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,ec(n),n.webRelayout?.();const m=Zo(p),g=y=>{y.style.objectFit=m.objectFit,y.style.background=m.background,y.style.objectPosition="50% 50%"};for(const y of n.videoPairs??[])for(const w of[y.active,y.standby])w.isConnected&&g(w);!n.videoPairs?.length&&n.video?.isConnected&&g(n.video)},setFps(p){n.cfg.sceneFps=p,Ht(n,m=>m.__weSetFps?.(p))},setVolume(p){const m=Math.max(0,Math.min(1,p));if(n.userVolume=m,n.cfg.muted=m<=0,n.sceneAudio?.setVolume(m),Ht(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"&&d()},setRenderDpr(p){n.cfg.renderDpr=p,d()},setQuality(p){const m={...fa(i.quality??n.cfg.quality),...p??{}};i={...i,quality:m},n.cfg.quality=m,n.sceneCtl?.setQuality?.(p??{})},getQuality(){return fa(i.quality??n.cfg.quality)},setProperties(p){const m={};for(const[g,y]of Object.entries(p))m[g]={value:y};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:Dn(0,0,0),secondaryColor:Dn(0,0,0),tertiaryColor:Dn(0,0,0),textColor:Dn(1,1,1),highContrastColor:Dn(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,y){n.pointerCtl?.push({u:p,v:m,buttons:g,mods:y})},pointerLeave(){n.pointerCtl?.leave()},pushWheel(p,m,g,y){n.pointerCtl?.wheel?.({dx:p,dy:m,mode:g,mods:y})},async load(p){const m=i.source;if(m&&m!==p)try{m.dispose?.()}catch{}i={...i,source:p},o(i);const g=await pp(s,i);g.type!=="web"&&g.canvas instanceof HTMLCanvasElement&&(s=g.canvas),n.cfg=g,n.paused=!1,n.info=void 0,ec(n),i.properties&&(n.liveUserProps={...i.properties});const y=u(),w=l();gu(n,g);try{await Promise.race([y,w.promise])}finally{w.off()}},release(){Or(n)},restore(){d()},destroy(p){jp(n),p?.releasePkgCache&&x2(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 Xp(n)},get info(){return n.info??null},on(p,m){const g=r[p];return g.push(m),()=>{const y=g.indexOf(m);y>=0&&g.splice(y,1)}}},h=async p=>{i=p,o(p);const m=await pp(t,p);m.type!=="web"&&m.canvas instanceof HTMLCanvasElement&&(s=m.canvas),n.cfg=m,n.paused=!1,n.info=void 0,ec(n),p.properties&&Object.keys(p.properties).length&&(n.liveUserProps={...p.properties});const g=u(),y=l();gu(n,n.cfg);try{await Promise.race([g,y.promise])}finally{y.off()}p.autoplay===!1&&f.pause(),(p.volume??0)>0&&f.setVolume(p.volume),p.properties&&Object.keys(p.properties).length&&f.setProperties(p.properties)};return f.__applyOptions=h,f}async function dx(t,e){const n=gp(t,e);return await n.__applyOptions(e),n}export{DA as bytesSource,lx as createMediaSource,gp as createScene,FA as fileSource,Ym as httpSource,Dn as mediaColor,NA as mediaSource,dx as mount,lu as sniffMediaType,cu as workshopIdFromSourceKey};
|
|
1719
2205
|
|
|
1720
2206
|
//# sourceMappingURL=webwallgl.min.mjs.map
|