@phil65/demoreel 0.3.1 → 0.4.0
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/THIRD_PARTY_NOTICES.md +1 -1
- package/dist/args.js +12 -0
- package/dist/cli.js +31 -2
- package/dist/compose.d.ts +4 -0
- package/dist/compose.js +4 -0
- package/dist/gif.d.ts +16 -0
- package/dist/gif.js +19 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/openscreen/project.js +3 -3
- package/dist/project.d.ts +51 -1
- package/dist/project.js +89 -1
- package/dist/record.d.ts +6 -1
- package/dist/record.js +2 -1
- package/dist/renderer/assets/CanvasPool-PBu3bHFZ.js +1 -0
- package/dist/renderer/assets/CanvasRenderer-HmF-4gyW.js +1 -0
- package/dist/renderer/assets/RenderTargetSystem-Dk1U4wDJ.js +184 -0
- package/dist/renderer/assets/WebGLRenderer-C0v9HBel.js +149 -0
- package/dist/renderer/assets/WebGPURenderer-Ce0-U9Q1.js +95 -0
- package/dist/renderer/assets/{browserAll-aHn2isHo.js → browserAll-DhvWQ7nM.js} +2 -2
- package/dist/renderer/assets/canvasUtils-KRroregW.js +1 -0
- package/dist/renderer/assets/{getTexelRangeRects-yD6MQ0xy.js → getTexelRangeRects-D3pwCyRt.js} +3 -3
- package/dist/renderer/assets/index-CE-lli1m.js +556 -0
- package/dist/renderer/assets/init-DfmWKarH.js +83 -0
- package/dist/renderer/assets/webworkerAll-B41hok0-.js +1 -0
- package/dist/renderer/index.html +1 -6
- package/dist/scene.d.ts +24 -4
- package/dist/scene.js +74 -5
- package/dist/types.d.ts +4 -0
- package/package.json +1 -1
- package/dist/renderer/assets/CanvasPool-CHSHS1-v.js +0 -23
- package/dist/renderer/assets/RenderTargetSystem-EAUH9iQk.js +0 -404
- package/dist/renderer/assets/canvasUtils-n5g2f3_X.js +0 -1
- package/dist/renderer/assets/getTextureBatchBindGroup-Bwvgbco6.js +0 -1
- package/dist/renderer/assets/index-BwP6rH7I.js +0 -556
- package/dist/renderer/assets/init-C2Za5NQh.js +0 -83
- package/dist/renderer/assets/webworkerAll-JSSmbaR2.js +0 -1
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./browserAll-DhvWQ7nM.js","./init-DfmWKarH.js","./canvasUtils-KRroregW.js","./CanvasPool-PBu3bHFZ.js","./webworkerAll-B41hok0-.js","./WebGPURenderer-Ce0-U9Q1.js","./getTexelRangeRects-D3pwCyRt.js","./RenderTargetSystem-Dk1U4wDJ.js","./WebGLRenderer-C0v9HBel.js","./CanvasRenderer-HmF-4gyW.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t,t.exports),e=null),t.exports),s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(let c of r(i))!a.call(e,c)&&c!==o&&(s=n(i,c),t(e,c,{get:s&&s.get&&!s.configurable?s.get:()=>i[c],enumerable:!s||s.enumerable}));return e},c=(n,r,o)=>(o=n==null?{}:e(i(n)),s(r||!n||!n.__esModule||!a.call(n,`default`)?t(o,`default`,{value:n,enumerable:!0}):o,n));(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var l=[{value:`none`,translationKey:`textAnimation.none`},{value:`fade`,translationKey:`textAnimation.fade`},{value:`rise`,translationKey:`textAnimation.rise`},{value:`pop`,translationKey:`textAnimation.pop`},{value:`slide-left`,translationKey:`textAnimation.slideLeft`},{value:`typewriter`,translationKey:`textAnimation.typewriter`},{value:`pulse`,translationKey:`textAnimation.pulse`}];function u(e,t=0,n=1){return Math.min(n,Math.max(t,e))}function d(e){return 1-(1-u(e))**3}function f(e){let t=u(e);return 1+2.70158*(t-1)**3+1.70158*(t-1)**2}function p(e){return l.some(t=>t.value===e)?e:`none`}function m(e,t){let n=p(e.style.textAnimation);if(n===`none`)return{opacity:1,scale:1,translateX:0,translateY:0,revealProgress:1};let r=u(Math.max(0,t-e.startMs)/700),i=d(r);switch(n){case`fade`:return{opacity:i,scale:1,translateX:0,translateY:0,revealProgress:1};case`rise`:return{opacity:i,scale:1,translateX:0,translateY:(1-i)*18,revealProgress:1};case`pop`:return{opacity:i,scale:Math.max(.72,f(r)),translateX:0,translateY:0,revealProgress:1};case`slide-left`:return{opacity:i,scale:1,translateX:(1-i)*-28,translateY:0,revealProgress:1};case`typewriter`:return{opacity:1,scale:1,translateX:0,translateY:0,revealProgress:r};case`pulse`:return{opacity:1,scale:1+Math.sin(r*Math.PI)*.06,translateX:0,translateY:0,revealProgress:1};default:return{opacity:1,scale:1,translateX:0,translateY:0,revealProgress:1}}}var h=`picture-in-picture`,g=`rectangle`,_={rotationX:0,rotationY:0,rotationZ:0},v={iso:{rotationX:-10,rotationY:-16,rotationZ:0},left:{rotationX:0,rotationY:-22,rotationZ:0},right:{rotationX:0,rotationY:22,rotationZ:0}},y=2.6;function b(e,t){return Math.min(e,t)*y}function x(e){return e.rotationPreset?v[e.rotationPreset]:_}function S(e,t=.01){return Math.abs(e.rotationX)<t&&Math.abs(e.rotationY)<t&&Math.abs(e.rotationZ)<t}function C(e,t,n){return{rotationX:e.rotationX+(t.rotationX-e.rotationX)*n,rotationY:e.rotationY+(t.rotationY-e.rotationY)*n,rotationZ:e.rotationZ+(t.rotationZ-e.rotationZ)*n}}function w(e,t,n,r){let i=e.rotationX*Math.PI/180,a=e.rotationY*Math.PI/180,o=e.rotationZ*Math.PI/180,s=Math.cos(i),c=Math.sin(i),l=Math.cos(a),u=Math.sin(a),d=Math.cos(o),f=Math.sin(o),p=t/2,m=n/2,h=[[-p,-m],[p,-m],[p,m],[-p,m]],g=0,_=0;for(let[e,t]of h){let n=e,i=t,a=0,o=n*d-i*f,p=n*f+i*d;n=o,i=p;let m=n*l+a*u,h=-n*u+a*l;n=m,a=h;let v=i*s-a*c,y=i*c+a*s;if(i=v,a=y,r>0){let e=r-a;if(e<=0)return 1;let t=r/e;n*=t,i*=t}Math.abs(n)>g&&(g=Math.abs(n)),Math.abs(i)>_&&(_=Math.abs(i))}if(g===0||_===0)return 1;let v=p/g,y=m/_;return Math.min(v,y,1)}var T=.35,E={x:50,y:50},D={width:30,height:20},O={color:`#ffffff`,backgroundColor:`transparent`,fontSize:32,fontFamily:`Inter`,fontWeight:`bold`,fontStyle:`normal`,textDecoration:`none`,textAlign:`center`,textAnimation:`none`},k={arrowDirection:`right`,color:`#34B27B`,strokeWidth:4},ee=[{x:10,y:30},{x:25,y:10},{x:55,y:8},{x:82,y:20},{x:90,y:45},{x:78,y:72},{x:52,y:90},{x:22,y:84},{x:8,y:58}],te={type:`mosaic`,shape:`rectangle`,color:`white`,intensity:12,blockSize:12,freehandPoints:ee},A={x:0,y:0,width:1,height:1},j=.1;function ne(e){return Math.round(Math.min(16,Math.max(j,e))*100)/100}var re=1.5,ie={1:1.25,2:1.5,3:1.8,4:2.2,5:3.5,6:5};function ae(e){if(e.customScale!=null){let t=Math.max(1,Math.min(5,e.customScale));if(Number.isFinite(t))return t}return ie[e.depth]}function oe(e,t,n){return Number.isFinite(e)?Math.min(n,Math.max(t,e)):t}function se(e){return`mosaic`}function ce(e){return e===`black`?`black`:`white`}function le(e){return oe(e?.intensity??12,2,40)}function ue(e,t=1){let n=oe(e?.blockSize??12,4,48);return Math.max(1,Math.round(n*Math.max(t,.01)))}function de(e){return ce(e?.color)===`black`?`rgba(0, 0, 0, 0.72)`:`rgba(255, 255, 255, 0.06)`}function fe(e,t){let n=e.width,r=e.height,i=e.data,a=Math.max(1,Math.floor(t));if(n<=0||r<=0||a<=1)return e;for(let e=0;e<r;e+=a)for(let t=0;t<n;t+=a){let o=Math.min(a,n-t),s=Math.min(a,r-e),c=o*s;if(c<=0)continue;let l=0,u=0,d=0,f=0;for(let r=e;r<e+s;r++)for(let e=t;e<t+o;e++){let t=(r*n+e)*4;l+=i[t],u+=i[t+1],d+=i[t+2],f+=i[t+3]}let p=Math.round(l/c),m=Math.round(u/c),h=Math.round(d/c),g=Math.round(f/c);for(let r=e;r<e+s;r++)for(let e=t;e<t+o;e++){let t=(r*n+e)*4;i[t]=p,i[t+1]=m,i[t+2]=h,i[t+3]=g}}return e}var pe=`default`,me=[{id:`hello-kitty-watermelon`,name:`Hello Kitty & Watermelon`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/hello-kitty-watermelon/arrow.png`,width:32,height:32,hotspotX:1.5,hotspotY:.5},pointer:{assetPath:`cursors/hello-kitty-watermelon/pointer.png`,width:32,height:32,hotspotX:4,hotspotY:2}}},{id:`among-us-sus-knife-and-red-animated`,name:`Among Us Sus Knife & Red Animated`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/among-us-sus-knife-and-red-animated/arrow.png`,width:32,height:32,hotspotX:1.6,hotspotY:.96},pointer:{assetPath:`cursors/among-us-sus-knife-and-red-animated/pointer.png`,width:32,height:32,hotspotX:12,hotspotY:2}}},{id:`black-and-rainbow-stroke-gradient-animated`,name:`Black & Rainbow Stroke Gradient Animated`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/black-and-rainbow-stroke-gradient-animated/arrow.png`,width:32,height:32,hotspotX:1.6,hotspotY:.96},pointer:{assetPath:`cursors/black-and-rainbow-stroke-gradient-animated/pointer.png`,width:32,height:32,hotspotX:8,hotspotY:1.5}}},{id:`black-pixel`,name:`Black Pixel`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/black-pixel/arrow.png`,width:32,height:32,hotspotX:2,hotspotY:3.5},pointer:{assetPath:`cursors/black-pixel/pointer.png`,width:32,height:32,hotspotX:8,hotspotY:1.5}}},{id:`christmas-miles-morales`,name:`Christmas Miles Morales`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/christmas-miles-morales/arrow.png`,width:32,height:32,hotspotX:1,hotspotY:.5},pointer:{assetPath:`cursors/christmas-miles-morales/pointer.png`,width:32,height:32,hotspotX:5.5,hotspotY:3}}},{id:`hollow-knight-and-game-arrow`,name:`Hollow Knight & Game Arrow`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/hollow-knight-and-game-arrow/arrow.png`,width:32,height:32,hotspotX:.5,hotspotY:.5},pointer:{assetPath:`cursors/hollow-knight-and-game-arrow/pointer.png`,width:32,height:32,hotspotX:5,hotspotY:.5}}},{id:`hollow-knight-nail-sword-and-mask`,name:`Hollow Knight Nail Sword & Mask`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/hollow-knight-nail-sword-and-mask/arrow.png`,width:32,height:32,hotspotX:.5,hotspotY:.5},pointer:{assetPath:`cursors/hollow-knight-nail-sword-and-mask/pointer.png`,width:32,height:32,hotspotX:3.5,hotspotY:2}}},{id:`naruto-akatsuki-cloud-arrow`,name:`Naruto Akatsuki Cloud Arrow`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/naruto-akatsuki-cloud-arrow/arrow.png`,width:32,height:32,hotspotX:.5,hotspotY:.5},pointer:{assetPath:`cursors/naruto-akatsuki-cloud-arrow/pointer.png`,width:32,height:32,hotspotX:1,hotspotY:1}}},{id:`old-roblox`,name:`Old Roblox`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/old-roblox/arrow.png`,width:32,height:32,hotspotX:2.5,hotspotY:1.5},pointer:{assetPath:`cursors/old-roblox/pointer.png`,width:32,height:32,hotspotX:3.5,hotspotY:1.5}}},{id:`pink-glossy-arrow-and-hand-3d`,name:`Pink Glossy Arrow & Hand 3D`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/pink-glossy-arrow-and-hand-3d/arrow.png`,width:32,height:32,hotspotX:1.5,hotspotY:1.5},pointer:{assetPath:`cursors/pink-glossy-arrow-and-hand-3d/pointer.png`,width:32,height:32,hotspotX:3,hotspotY:1}}},{id:`pinky-pixel`,name:`Pinky Pixel`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/pinky-pixel/arrow.png`,width:32,height:32,hotspotX:.5,hotspotY:.5},pointer:{assetPath:`cursors/pinky-pixel/pointer.png`,width:32,height:32,hotspotX:7,hotspotY:1}}},{id:`pokemon-neon-gengar`,name:`Pokemon Neon Gengar`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/pokemon-neon-gengar/arrow.png`,width:32,height:32,hotspotX:1,hotspotY:.5},pointer:{assetPath:`cursors/pokemon-neon-gengar/pointer.png`,width:32,height:32,hotspotX:2,hotspotY:2.5}}},{id:`sanrio-gudetama-and-arrow-kawaii`,name:`Sanrio Gudetama & Arrow Kawaii`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/sanrio-gudetama-and-arrow-kawaii/arrow.png`,width:32,height:32,hotspotX:.5,hotspotY:.5},pointer:{assetPath:`cursors/sanrio-gudetama-and-arrow-kawaii/pointer.png`,width:32,height:32,hotspotX:8,hotspotY:4}}},{id:`spring-gradient`,name:`Spring Gradient`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/spring-gradient/arrow.png`,width:32,height:32,hotspotX:1.5,hotspotY:.5},pointer:{assetPath:`cursors/spring-gradient/pointer.png`,width:32,height:32,hotspotX:8,hotspotY:.5}}},{id:`mickey-mouse-black-hand-inflated-glove`,name:`Mickey Mouse Black Hand Inflated Glove`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/mickey-mouse-black-hand-inflated-glove/arrow.png`,width:32,height:32,hotspotX:2.5,hotspotY:.5},pointer:{assetPath:`cursors/mickey-mouse-black-hand-inflated-glove/pointer.png`,width:32,height:32,hotspotX:10,hotspotY:.5}}},{id:`sanrio-kuromi-skull-arrow`,name:`Sanrio Kuromi Skull Arrow`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/sanrio-kuromi-skull-arrow/arrow.png`,width:32,height:32,hotspotX:1.5,hotspotY:.5},pointer:{assetPath:`cursors/sanrio-kuromi-skull-arrow/pointer.png`,width:32,height:32,hotspotX:9.5,hotspotY:1}}},{id:`solo-leveling-sung-jinwoo-dark-flames`,name:`Solo Leveling Sung Jinwoo Dark Flames`,source:`sweezy-cursors.com`,assets:{arrow:{assetPath:`cursors/solo-leveling-sung-jinwoo-dark-flames/arrow.png`,width:32,height:32,hotspotX:2,hotspotY:1},pointer:{assetPath:`cursors/solo-leveling-sung-jinwoo-dark-flames/pointer.png`,width:32,height:32,hotspotX:7,hotspotY:4.5}}}],he=new Set([pe,...me.map(e=>e.id)]);function ge(e){return!e||e==="default"?null:me.find(t=>t.id===e)??null}function _e(e){return typeof e==`string`&&he.has(e)?e:pe}function ve(e){return e===`editable-overlay`||e===`system`?e:void 0}function ye(e){return typeof e==`string`&&e.trim()||void 0}function be(e){if(!e||typeof e!=`object`)return null;let t=e,n=ye(t.screenVideoPath);if(!n)return null;let r=ye(t.webcamVideoPath),i=ve(t.cursorCaptureMode);return{screenVideoPath:n,...r?{webcamVideoPath:r}:{},...i?{cursorCaptureMode:i}:{}}}var xe=class extends Error{constructor(e){super(`Unsafe asset path segment: ${e}`),this.name=`UnsafeAssetPathError`}},Se=class extends Error{constructor(){super(`electronAPI.assetBaseUrl is not available; preload did not load correctly`),this.name=`AssetBaseUnavailableError`}};function Ce(e){return e.replace(/^\/+/,``).split(`/`).filter(Boolean).map(e=>{let t=decodeURIComponent(e);if(t===`.`||t===`..`)throw new xe(t);return encodeURIComponent(t)}).join(`/`)}function we(e){return e.endsWith(`/`)?e:`${e}/`}function Te(e){let t=Ce(e);if(typeof window>`u`||window.location?.protocol?.startsWith(`http`))return`/${t}`;let n=window.electronAPI?.assetBaseUrl;if(!n)throw new Se;return new URL(t,we(n)).toString()}var Ee=Array.from({length:18},(e,t)=>`/wallpapers/wallpaper${t+1}.jpg`),De=Ee[0],Oe=/^(repeating-)?(linear|radial|conic)-gradient\(/,ke=/^(rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color)\(/,Ae=/^(\/|https?:\/\/|file:\/\/|data:)/;function je(e){let t=e.trim();return t===``?{kind:`color`,value:`#000000`}:t.startsWith(`#`)||ke.test(t)?{kind:`color`,value:t}:Oe.test(t)?{kind:`gradient`,value:t}:Ae.test(t)?{kind:`image`,path:t}:{kind:`color`,value:t}}var Me=`/wallpapers/`,Ne=class extends Error{constructor(e){super(`Image wallpaper path must live under ${e}`),this.name=`UnsafeImagePrefixError`}};function Pe(e){if(e.startsWith(`http://`)||e.startsWith(`https://`)||e.startsWith(`file://`)||e.startsWith(`data:`))return e;let t=e.startsWith(`/`)?e:`/${e}`;if(!t.startsWith(Me))throw new Fe(e,new Ne(Me));try{return Te(t.slice(1))}catch(t){throw t instanceof Fe?t:new Fe(e,t)}}var Fe=class extends Error{url;cause;constructor(e,t){super(`Failed to load background image: ${Ie(e)}`),this.name=`BackgroundLoadError`,this.url=e,this.cause=t}get displayUrl(){return Ie(this.url)}};function Ie(e){if(e.startsWith(`data:`))return`data:…`;try{let t=new URL(e).pathname.split(`/`).filter(Boolean).pop();return t?decodeURIComponent(t):`(unknown)`}catch{return e.split(`/`).filter(Boolean).pop()??`(unknown)`}}var Le=[`16:9`,`9:16`,`1:1`,`4:3`,`4:5`,`16:10`,`10:16`,`native`],Re=16/9;function ze(e){switch(e){case`16:9`:return 16/9;case`9:16`:return 9/16;case`1:1`:return 1;case`4:3`:return 4/3;case`4:5`:return .8;case`16:10`:return 1.6;case`10:16`:return .625;case`native`:return Re;default:return e}}function Be(e,t,n){let r=n?.width??1,i=n?.height??1;if(!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(r)||!Number.isFinite(i)||e<=0||t<=0||r<=0||i<=0)return Re;let a=e*r/(t*i);return Number.isFinite(a)&&a>0?a:Re}function Ve(e){return ze(e)<1}var He={width:1280,height:720},Ue={shadowIntensity:0,showBlur:!1,motionBlurAmount:0,borderRadius:0,showTrimWaveform:!0},We={padding:50,aspectRatio:`16:9`,cropRegion:A,wallpaper:De},Ge={layoutPreset:h,maskShape:g,sizePreset:25,position:null},Ke={quality:`good`,format:`mp4`},qe={frameRate:15,loop:!0,sizePreset:`medium`,outputDimensions:He},Je=new Set([`rectangle`,`oval`,`freehand`]),Ye=/^file:\/\/.*?\/(?:resources\/(?:assets\/)?|public\/)wallpapers\/(wallpaper\d+\.jpg)$/i,Xe=new Set(Ee);function Ze(e){let t=Ye.exec(e);if(!t)return e;let n=`/wallpapers/${t[1]}`;return Xe.has(n)?n:De}function M(e){return typeof e==`number`&&Number.isFinite(e)}function Qe(e,t){switch(e){case`picture-in-picture`:case`no-webcam`:return e;case`vertical-stack`:return Ve(t)?e:Ge.layoutPreset;case`dual-frame`:return Ve(t)?Ge.layoutPreset:e;default:return Ge.layoutPreset}}function $e(e,t,n){return Math.min(n,Math.max(t,e))}function et(e){if(!e||typeof e!=`object`)return!1;let t=e;return!(typeof t.version!=`number`||!tt(t)||!t.editor||typeof t.editor!=`object`)}function tt(e){return be(e.media)||(typeof e.videoPath==`string`&&e.videoPath.trim()?{screenVideoPath:e.videoPath}:null)}function nt(e){let t=new Set(Le).has(e.aspectRatio)?e.aspectRatio:We.aspectRatio,n=Qe(e.webcamLayoutPreset,t),r=n===`picture-in-picture`&&e.webcamPosition&&typeof e.webcamPosition==`object`&&M(e.webcamPosition.cx)&&M(e.webcamPosition.cy)?{cx:$e(e.webcamPosition.cx,0,1),cy:$e(e.webcamPosition.cy,0,1)}:Ge.position,i=Array.isArray(e.zoomRegions)?e.zoomRegions.filter(e=>!!(e&&typeof e.id==`string`)).map(e=>{let t=M(e.startMs)?Math.round(e.startMs):0,n=M(e.endMs)?Math.round(e.endMs):t+1e3,r=Math.max(0,Math.min(t,n)),i=Math.max(r+1,n),a=e.rotationPreset===`iso`||e.rotationPreset===`left`||e.rotationPreset===`right`?e.rotationPreset:void 0;return{id:e.id,startMs:r,endMs:i,depth:[1,2,3,4,5,6].includes(e.depth)?e.depth:3,focus:{cx:$e(M(e.focus?.cx)?e.focus.cx:.5,0,1),cy:$e(M(e.focus?.cy)?e.focus.cy:.5,0,1)},focusMode:e.focusMode===`auto`?`auto`:`manual`,source:e.source===`auto`?`auto`:`manual`,...a?{rotationPreset:a}:{}}}):[],a=Array.isArray(e.trimRegions)?e.trimRegions.filter(e=>!!(e&&typeof e.id==`string`)).map(e=>{let t=M(e.startMs)?Math.round(e.startMs):0,n=M(e.endMs)?Math.round(e.endMs):t+1e3,r=Math.max(0,Math.min(t,n)),i=Math.max(r+1,n);return{id:e.id,startMs:r,endMs:i}}):[],o=Array.isArray(e.speedRegions)?e.speedRegions.filter(e=>!!(e&&typeof e.id==`string`)).map(e=>{let t=M(e.startMs)?Math.round(e.startMs):0,n=M(e.endMs)?Math.round(e.endMs):t+1e3,r=Math.max(0,Math.min(t,n)),i=Math.max(r+1,n),a=M(e.speed)&&e.speed>=.1&&e.speed<=16?ne(e.speed):re;return{id:e.id,startMs:r,endMs:i,speed:a}}):[],s=Array.isArray(e.annotationRegions)?e.annotationRegions.filter(e=>!!(e&&typeof e.id==`string`)).map((e,t)=>{let n=M(e.startMs)?Math.round(e.startMs):0,r=M(e.endMs)?Math.round(e.endMs):n+1e3,i=Math.max(0,Math.min(n,r)),a=Math.max(i+1,r),o=typeof e.blurData?.shape==`string`&&Je.has(e.blurData.shape)?e.blurData.shape:te.shape,s=se(e.blurData?.type),c=ce(e.blurData?.color);return{id:e.id,startMs:i,endMs:a,type:e.type===`image`||e.type===`figure`||e.type===`blur`?e.type:`text`,content:typeof e.content==`string`?e.content:``,textContent:typeof e.textContent==`string`?e.textContent:void 0,imageContent:typeof e.imageContent==`string`?e.imageContent:void 0,annotationSource:e.annotationSource===`auto-caption`?`auto-caption`:void 0,position:{x:$e(M(e.position?.x)?e.position.x:E.x,0,100),y:$e(M(e.position?.y)?e.position.y:E.y,0,100)},size:{width:$e(M(e.size?.width)?e.size.width:D.width,1,200),height:$e(M(e.size?.height)?e.size.height:D.height,1,200)},style:{...O,...e.style&&typeof e.style==`object`?e.style:{},textAnimation:p(e.style?.textAnimation)},zIndex:M(e.zIndex)?e.zIndex:t+1,figureData:e.figureData?{...k,...e.figureData}:void 0,blurData:e.blurData&&typeof e.blurData==`object`?{...te,...e.blurData,type:s,shape:o,color:c,intensity:M(e.blurData.intensity)?$e(e.blurData.intensity,2,40):12,blockSize:M(e.blurData.blockSize)?$e(e.blurData.blockSize,4,48):12,freehandPoints:Array.isArray(e.blurData.freehandPoints)?e.blurData.freehandPoints.filter(e=>!!(e&&M(e.x)&&M(e.y))).map(e=>({x:$e(e.x,0,100),y:$e(e.y,0,100)})):ee}:void 0}}):[],c=M(e.cropRegion?.x)?e.cropRegion.x:We.cropRegion.x,l=M(e.cropRegion?.y)?e.cropRegion.y:We.cropRegion.y,u=M(e.cropRegion?.width)?e.cropRegion.width:We.cropRegion.width,d=M(e.cropRegion?.height)?e.cropRegion.height:We.cropRegion.height,f=$e(c,0,1),m=$e(l,0,1),h=$e(u,.01,1-f),g=$e(d,.01,1-m);return{cursorTheme:_e(e.cursorTheme),wallpaper:typeof e.wallpaper==`string`?Ze(e.wallpaper):We.wallpaper,shadowIntensity:typeof e.shadowIntensity==`number`?e.shadowIntensity:Ue.shadowIntensity,showBlur:typeof e.showBlur==`boolean`?e.showBlur:Ue.showBlur,showTrimWaveform:typeof e.showTrimWaveform==`boolean`?e.showTrimWaveform:Ue.showTrimWaveform,motionBlurAmount:M(e.motionBlurAmount)?$e(e.motionBlurAmount,0,1):typeof e.motionBlurEnabled==`boolean`&&e.motionBlurEnabled?T:Ue.motionBlurAmount,borderRadius:typeof e.borderRadius==`number`?e.borderRadius:Ue.borderRadius,padding:M(e.padding)?$e(e.padding,0,100):We.padding,cropRegion:{x:f,y:m,width:h,height:g},zoomRegions:i,autoZoomEnabled:typeof e.autoZoomEnabled!=`boolean`||e.autoZoomEnabled,autoFocusAll:typeof e.autoFocusAll==`boolean`&&e.autoFocusAll,trimRegions:a,speedRegions:o,annotationRegions:s,aspectRatio:t,webcamLayoutPreset:n,webcamMaskShape:e.webcamMaskShape===`rectangle`||e.webcamMaskShape===`circle`||e.webcamMaskShape===`square`||e.webcamMaskShape===`rounded`?e.webcamMaskShape:Ge.maskShape,webcamMirrored:typeof e.webcamMirrored==`boolean`&&e.webcamMirrored,webcamReactiveZoom:typeof e.webcamReactiveZoom!=`boolean`||e.webcamReactiveZoom,webcamSizePreset:typeof e.webcamSizePreset==`number`&&M(e.webcamSizePreset)?Math.max(10,Math.min(50,e.webcamSizePreset)):Ge.sizePreset,webcamPosition:r,exportQuality:e.exportQuality===`medium`||e.exportQuality===`source`?e.exportQuality:Ke.quality,exportFormat:e.exportFormat===`gif`?`gif`:Ke.format,gifFrameRate:e.gifFrameRate===15||e.gifFrameRate===20||e.gifFrameRate===25||e.gifFrameRate===30?e.gifFrameRate:qe.frameRate,gifLoop:typeof e.gifLoop==`boolean`?e.gifLoop:qe.loop,gifSizePreset:e.gifSizePreset===`medium`||e.gifSizePreset===`large`||e.gifSizePreset===`original`?e.gifSizePreset:qe.sizePreset}}var N=(e=>(e.Application=`application`,e.WebGLPipes=`webgl-pipes`,e.WebGLPipesAdaptor=`webgl-pipes-adaptor`,e.WebGLSystem=`webgl-system`,e.WebGLLoader=`webgl-loader`,e.WebGPUPipes=`webgpu-pipes`,e.WebGPUPipesAdaptor=`webgpu-pipes-adaptor`,e.WebGPUSystem=`webgpu-system`,e.WebGPULoader=`webgpu-loader`,e.CanvasSystem=`canvas-system`,e.CanvasPipesAdaptor=`canvas-pipes-adaptor`,e.CanvasPipes=`canvas-pipes`,e.CanvasLoader=`canvas-loader`,e.Asset=`asset`,e.LoadParser=`load-parser`,e.ResolveParser=`resolve-parser`,e.CacheParser=`cache-parser`,e.DetectionParser=`detection-parser`,e.MaskEffect=`mask-effect`,e.BlendMode=`blend-mode`,e.TextureSource=`texture-source`,e.TextureUploaderWebGL=`texture-uploader-webgl`,e.TextureUploaderWebGPU=`texture-uploader-webgpu`,e.Environment=`environment`,e.ShapeBuilder=`shape-builder`,e.Batcher=`batcher`,e))(N||{}),rt=e=>{if(typeof e==`function`||typeof e==`object`&&e.extension){if(!e.extension)throw Error(`Extension class must have an extension object`);e={...typeof e.extension==`object`?e.extension:{type:e.extension},ref:e}}if(typeof e==`object`)e={...e};else throw Error(`Invalid extension type`);return typeof e.type==`string`&&(e.type=[e.type]),e},it=(e,t)=>rt(e).priority??t,at={_addHandlers:{},_removeHandlers:{},_queue:{},remove(...e){return e.map(rt).forEach(e=>{e.type.forEach(t=>this._removeHandlers[t]?.(e))}),this},add(...e){return e.map(rt).forEach(e=>{e.type.forEach(t=>{let n=this._addHandlers,r=this._queue;n[t]?n[t]?.(e):(r[t]=r[t]||[],r[t]?.push(e))})}),this},handle(e,t,n){let r=this._addHandlers,i=this._removeHandlers;if(r[e]||i[e])throw Error(`Extension type ${e} already has a handler`);r[e]=t,i[e]=n;let a=this._queue;return a[e]&&(a[e]?.forEach(e=>t(e)),delete a[e]),this},handleByMap(e,t){return this.handle(e,e=>{e.name&&(t[e.name]=e.ref)},e=>{e.name&&delete t[e.name]})},handleByNamedList(e,t,n=-1){return this.handle(e,e=>{t.findIndex(t=>t.name===e.name)>=0||(t.push({name:e.name,value:e.ref}),t.sort((e,t)=>it(t.value,n)-it(e.value,n)))},e=>{let n=t.findIndex(t=>t.name===e.name);n!==-1&&t.splice(n,1)})},handleByList(e,t,n=-1){return this.handle(e,e=>{t.includes(e.ref)||(t.push(e.ref),t.sort((e,t)=>it(t,n)-it(e,n)))},e=>{let n=t.indexOf(e.ref);n!==-1&&t.splice(n,1)})},mixin(e,...t){for(let n of t)Object.defineProperties(e.prototype,Object.getOwnPropertyDescriptors(n))}},ot=`modulepreload`,st=function(e,t){return new URL(e,t).href},ct={},lt={},ut=function(e){return e.pathname.endsWith(`.css`)},dt=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw delete e[t],n});return e[t]=i,i},ft=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=st(t,n);let r=s(t),i=ut(r);return dt(ct,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}let t=i?e.styles:e.all,n=i?lt[r.href]:void 0;if(!n&&t.has(r.href))return;let o=document.createElement(`link`);if(o.rel=i?`stylesheet`:ot,i||(o.as=`script`),o.crossOrigin=``,o.href=r.href,a&&o.setAttribute(`nonce`,a),n&&delete lt[r.href],n?.isConnected?n.replaceWith(o):document.head.appendChild(o),i)return new Promise((e,t)=>{let n=i=>{o.removeEventListener(`load`,n),o.removeEventListener(`error`,n),i.type===`error`?(lt[r.href]=o,t(Error(`Unable to preload CSS for ${r}`))):e(i)};o.addEventListener(`load`,n),o.addEventListener(`error`,n)})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},pt={extension:{type:N.Environment,name:`browser`,priority:-1},test:()=>!0,load:async()=>{await ft(()=>import(`./browserAll-DhvWQ7nM.js`),__vite__mapDeps([0,1,2,3]),import.meta.url)}},mt={extension:{type:N.Environment,name:`webworker`,priority:0},test:()=>typeof self<`u`&&self.WorkerGlobalScope!==void 0,load:async()=>{await ft(()=>import(`./webworkerAll-B41hok0-.js`),__vite__mapDeps([4,1,2,3]),import.meta.url)}},ht=class e{constructor(e,t,n){this._x=t||0,this._y=n||0,this._observer=e}clone(t){return new e(t??this._observer,this._x,this._y)}set(e=0,t=e){return(this._x!==e||this._y!==t)&&(this._x=e,this._y=t,this._observer._onUpdate(this)),this}copyFrom(e){return(this._x!==e.x||this._y!==e.y)&&(this._x=e.x,this._y=e.y,this._observer._onUpdate(this)),this}copyTo(e){return e.set(this._x,this._y),e}equals(e){return e.x===this._x&&e.y===this._y}toString(){return`[pixi.js/math:ObservablePoint x=${this._x} y=${this._y} scope=${this._observer}]`}get x(){return this._x}set x(e){this._x!==e&&(this._x=e,this._observer._onUpdate(this))}get y(){return this._y}set y(e){this._y!==e&&(this._y=e,this._observer._onUpdate(this))}},gt=c(o(((e,t)=>{var n=Object.prototype.hasOwnProperty,r=`~`;function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(r=!1));function a(e,t,n){this.fn=e,this.context=t,this.once=n||!1}function o(e,t,n,i,o){if(typeof n!=`function`)throw TypeError(`The listener must be a function`);var s=new a(n,i||e,o),c=r?r+t:t;return e._events[c]?e._events[c].fn?e._events[c]=[e._events[c],s]:e._events[c].push(s):(e._events[c]=s,e._eventsCount++),e}function s(e,t){--e._eventsCount===0?e._events=new i:delete e._events[t]}function c(){this._events=new i,this._eventsCount=0}c.prototype.eventNames=function(){var e=[],t,i;if(this._eventsCount===0)return e;for(i in t=this._events)n.call(t,i)&&e.push(r?i.slice(1):i);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e},c.prototype.listeners=function(e){var t=r?r+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,a=n.length,o=Array(a);i<a;i++)o[i]=n[i].fn;return o},c.prototype.listenerCount=function(e){var t=r?r+e:e,n=this._events[t];return n?n.fn?1:n.length:0},c.prototype.emit=function(e,t,n,i,a,o){var s=r?r+e:e;if(!this._events[s])return!1;var c=this._events[s],l=arguments.length,u,d;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,a),!0;case 6:return c.fn.call(c.context,t,n,i,a,o),!0}for(d=1,u=Array(l-1);d<l;d++)u[d-1]=arguments[d];c.fn.apply(c.context,u)}else{var f=c.length,p;for(d=0;d<f;d++)switch(c[d].once&&this.removeListener(e,c[d].fn,void 0,!0),l){case 1:c[d].fn.call(c[d].context);break;case 2:c[d].fn.call(c[d].context,t);break;case 3:c[d].fn.call(c[d].context,t,n);break;case 4:c[d].fn.call(c[d].context,t,n,i);break;default:if(!u)for(p=1,u=Array(l-1);p<l;p++)u[p-1]=arguments[p];c[d].fn.apply(c[d].context,u)}}return!0},c.prototype.on=function(e,t,n){return o(this,e,t,n,!1)},c.prototype.once=function(e,t,n){return o(this,e,t,n,!0)},c.prototype.removeListener=function(e,t,n,i){var a=r?r+e:e;if(!this._events[a])return this;if(!t)return s(this,a),this;var o=this._events[a];if(o.fn)o.fn!==t||i&&!o.once||n&&o.context!==n||s(this,a);else{for(var c=0,l=[],u=o.length;c<u;c++)(o[c].fn!==t||i&&!o[c].once||n&&o[c].context!==n)&&l.push(o[c]);l.length?this._events[a]=l.length===1?l[0]:l:s(this,a)}return this},c.prototype.removeAllListeners=function(e){var t;return e?(t=r?r+e:e,this._events[t]&&s(this,t)):(this._events=new i,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=r,c.EventEmitter=c,t!==void 0&&(t.exports=c)}))(),1).default,_t=Math.PI*2,vt=180/Math.PI,yt=Math.PI/180,bt=class e{constructor(e=0,t=0){this.x=0,this.y=0,this.x=e,this.y=t}clone(){return new e(this.x,this.y)}copyFrom(e){return this.set(e.x,e.y),this}copyTo(e){return e.set(this.x,this.y),e}equals(e){return e.x===this.x&&e.y===this.y}set(e=0,t=e){return this.x=e,this.y=t,this}toString(){return`[pixi.js/math:Point x=${this.x} y=${this.y}]`}static get shared(){return xt.x=0,xt.y=0,xt}},xt=new bt,P=class e{constructor(e=1,t=0,n=0,r=1,i=0,a=0){this.array=null,this.a=e,this.b=t,this.c=n,this.d=r,this.tx=i,this.ty=a}fromArray(e){this.a=e[0],this.b=e[1],this.c=e[3],this.d=e[4],this.tx=e[2],this.ty=e[5]}set(e,t,n,r,i,a){return this.a=e,this.b=t,this.c=n,this.d=r,this.tx=i,this.ty=a,this}toArray(e,t){this.array||=new Float32Array(9);let n=t||this.array;return e?(n[0]=this.a,n[1]=this.b,n[2]=0,n[3]=this.c,n[4]=this.d,n[5]=0,n[6]=this.tx,n[7]=this.ty,n[8]=1):(n[0]=this.a,n[1]=this.c,n[2]=this.tx,n[3]=this.b,n[4]=this.d,n[5]=this.ty,n[6]=0,n[7]=0,n[8]=1),n}apply(e,t){t||=new bt;let n=e.x,r=e.y;return t.x=this.a*n+this.c*r+this.tx,t.y=this.b*n+this.d*r+this.ty,t}applyInverse(e,t){t||=new bt;let n=this.a,r=this.b,i=this.c,a=this.d,o=this.tx,s=this.ty,c=1/(n*a+i*-r),l=e.x,u=e.y;return t.x=a*c*l+-i*c*u+(s*i-o*a)*c,t.y=n*c*u+-r*c*l+(-s*n+o*r)*c,t}translate(e,t){return this.tx+=e,this.ty+=t,this}scale(e,t){return this.a*=e,this.d*=t,this.c*=e,this.b*=t,this.tx*=e,this.ty*=t,this}rotate(e){let t=Math.cos(e),n=Math.sin(e),r=this.a,i=this.c,a=this.tx;return this.a=r*t-this.b*n,this.b=r*n+this.b*t,this.c=i*t-this.d*n,this.d=i*n+this.d*t,this.tx=a*t-this.ty*n,this.ty=a*n+this.ty*t,this}append(e){let t=this.a,n=this.b,r=this.c,i=this.d;return this.a=e.a*t+e.b*r,this.b=e.a*n+e.b*i,this.c=e.c*t+e.d*r,this.d=e.c*n+e.d*i,this.tx=e.tx*t+e.ty*r+this.tx,this.ty=e.tx*n+e.ty*i+this.ty,this}appendFrom(e,t){let n=e.a,r=e.b,i=e.c,a=e.d,o=e.tx,s=e.ty,c=t.a,l=t.b,u=t.c,d=t.d;return this.a=n*c+r*u,this.b=n*l+r*d,this.c=i*c+a*u,this.d=i*l+a*d,this.tx=o*c+s*u+t.tx,this.ty=o*l+s*d+t.ty,this}setTransform(e,t,n,r,i,a,o,s,c){return this.a=Math.cos(o+c)*i,this.b=Math.sin(o+c)*i,this.c=-Math.sin(o-s)*a,this.d=Math.cos(o-s)*a,this.tx=e-(n*this.a+r*this.c),this.ty=t-(n*this.b+r*this.d),this}prepend(e){let t=this.tx;if(e.a!==1||e.b!==0||e.c!==0||e.d!==1){let t=this.a,n=this.c;this.a=t*e.a+this.b*e.c,this.b=t*e.b+this.b*e.d,this.c=n*e.a+this.d*e.c,this.d=n*e.b+this.d*e.d}return this.tx=t*e.a+this.ty*e.c+e.tx,this.ty=t*e.b+this.ty*e.d+e.ty,this}decompose(e){let t=this.a,n=this.b,r=this.c,i=this.d,a=e.pivot,o=-Math.atan2(-r,i),s=Math.atan2(n,t),c=Math.abs(o+s),l=Math.sqrt(t*t+n*n);return c<1e-5||Math.abs(_t-c)<1e-5?(e.rotation=s,e.skew.x=e.skew.y=0):Math.abs(Math.PI-c)<1e-5?(e.rotation=s-Math.PI,e.skew.x=e.skew.y=0,l=-l):(e.rotation=0,e.skew.x=o,e.skew.y=s),e.scale.x=l,e.scale.y=Math.sqrt(r*r+i*i),e.position.x=this.tx+(a.x*t+a.y*r),e.position.y=this.ty+(a.x*n+a.y*i),e}invert(){let e=this.a,t=this.b,n=this.c,r=this.d,i=this.tx,a=e*r-t*n;return this.a=r/a,this.b=-t/a,this.c=-n/a,this.d=e/a,this.tx=(n*this.ty-r*i)/a,this.ty=-(e*this.ty-t*i)/a,this}isIdentity(){return this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.tx===0&&this.ty===0}identity(){return this.a=1,this.b=0,this.c=0,this.d=1,this.tx=0,this.ty=0,this}clone(){let t=new e;return t.a=this.a,t.b=this.b,t.c=this.c,t.d=this.d,t.tx=this.tx,t.ty=this.ty,t}copyTo(e){return e.a=this.a,e.b=this.b,e.c=this.c,e.d=this.d,e.tx=this.tx,e.ty=this.ty,e}copyFrom(e){return this.a=e.a,this.b=e.b,this.c=e.c,this.d=e.d,this.tx=e.tx,this.ty=e.ty,this}equals(e){return e.a===this.a&&e.b===this.b&&e.c===this.c&&e.d===this.d&&e.tx===this.tx&&e.ty===this.ty}toString(){return`[pixi.js:Matrix a=${this.a} b=${this.b} c=${this.c} d=${this.d} tx=${this.tx} ty=${this.ty}]`}static get IDENTITY(){return Ct.identity()}static get shared(){return St.identity()}},St=new P,Ct=new P,wt=[1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1,0,1],Tt=[0,1,1,1,0,-1,-1,-1,0,1,1,1,0,-1,-1,-1],Et=[0,-1,-1,-1,0,1,1,1,0,1,1,1,0,-1,-1,-1],Dt=[1,1,0,-1,-1,-1,0,1,-1,-1,0,1,1,1,0,-1],Ot=[],kt=[],At=Math.sign;function jt(){for(let e=0;e<16;e++){let t=[];Ot.push(t);for(let n=0;n<16;n++){let r=At(wt[e]*wt[n]+Et[e]*Tt[n]),i=At(Tt[e]*wt[n]+Dt[e]*Tt[n]),a=At(wt[e]*Et[n]+Et[e]*Dt[n]),o=At(Tt[e]*Et[n]+Dt[e]*Dt[n]);for(let e=0;e<16;e++)if(wt[e]===r&&Tt[e]===i&&Et[e]===a&&Dt[e]===o){t.push(e);break}}}for(let e=0;e<16;e++){let t=new P;t.set(wt[e],Tt[e],Et[e],Dt[e],0,0),kt.push(t)}}jt();var F={E:0,SE:1,S:2,SW:3,W:4,NW:5,N:6,NE:7,MIRROR_VERTICAL:8,MAIN_DIAGONAL:10,MIRROR_HORIZONTAL:12,REVERSE_DIAGONAL:14,uX:e=>wt[e],uY:e=>Tt[e],vX:e=>Et[e],vY:e=>Dt[e],inv:e=>e&8?e&15:-e&7,add:(e,t)=>Ot[e][t],sub:(e,t)=>Ot[e][F.inv(t)],rotate180:e=>e^4,isVertical:e=>(e&3)==2,byDirection:(e,t)=>Math.abs(e)*2<=Math.abs(t)?t>=0?F.S:F.N:Math.abs(t)*2<=Math.abs(e)?e>0?F.E:F.W:t>0?e>0?F.SE:F.SW:e>0?F.NE:F.NW,matrixAppendRotationInv:(e,t,n=0,r=0,i=0,a=0)=>{let o=kt[F.inv(t)],s=o.a,c=o.b,l=o.c,u=o.d,d=n-Math.min(0,s*i,l*a,s*i+l*a),f=r-Math.min(0,c*i,u*a,c*i+u*a),p=e.a,m=e.b,h=e.c,g=e.d;e.a=s*p+c*h,e.b=s*m+c*g,e.c=l*p+u*h,e.d=l*m+u*g,e.tx=d*p+f*h+e.tx,e.ty=d*m+f*g+e.ty},transformRectCoords:(e,t,n,r)=>{let{x:i,y:a,width:o,height:s}=e,{x:c,y:l,width:u,height:d}=t;return n===F.E?(r.set(i+c,a+l,o,s),r):n===F.S?r.set(u-a-s+c,i+l,s,o):n===F.W?r.set(u-i-o+c,d-a-s+l,o,s):n===F.N?r.set(a+c,d-i-o+l,s,o):r.set(i+c,a+l,o,s)}},Mt=[new bt,new bt,new bt,new bt],Nt=class e{constructor(e=0,t=0,n=0,r=0){this.type=`rectangle`,this.x=Number(e),this.y=Number(t),this.width=Number(n),this.height=Number(r)}get left(){return this.x}get right(){return this.x+this.width}get top(){return this.y}get bottom(){return this.y+this.height}isEmpty(){return this.left===this.right||this.top===this.bottom}static get EMPTY(){return new e(0,0,0,0)}clone(){return new e(this.x,this.y,this.width,this.height)}copyFromBounds(e){return this.x=e.minX,this.y=e.minY,this.width=e.maxX-e.minX,this.height=e.maxY-e.minY,this}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){return this.width<=0||this.height<=0?!1:e>=this.x&&e<this.x+this.width&&t>=this.y&&t<this.y+this.height}strokeContains(e,t,n,r=.5){let{width:i,height:a}=this;if(i<=0||a<=0)return!1;let o=this.x,s=this.y,c=n*(1-r),l=n-c,u=o-c,d=o+i+c,f=s-c,p=s+a+c,m=o+l,h=o+i-l,g=s+l,_=s+a-l;return e>=u&&e<=d&&t>=f&&t<=p&&!(e>m&&e<h&&t>g&&t<_)}intersects(e,t){if(!t){let t=this.x<e.x?e.x:this.x;if((this.right>e.right?e.right:this.right)<=t)return!1;let n=this.y<e.y?e.y:this.y;return(this.bottom>e.bottom?e.bottom:this.bottom)>n}let n=this.left,r=this.right,i=this.top,a=this.bottom;if(r<=n||a<=i)return!1;let o=Mt[0].set(e.left,e.top),s=Mt[1].set(e.left,e.bottom),c=Mt[2].set(e.right,e.top),l=Mt[3].set(e.right,e.bottom);if(c.x<=o.x||s.y<=o.y)return!1;let u=Math.sign(t.a*t.d-t.b*t.c);if(u===0||(t.apply(o,o),t.apply(s,s),t.apply(c,c),t.apply(l,l),Math.max(o.x,s.x,c.x,l.x)<=n||Math.min(o.x,s.x,c.x,l.x)>=r||Math.max(o.y,s.y,c.y,l.y)<=i||Math.min(o.y,s.y,c.y,l.y)>=a))return!1;let d=u*(s.y-o.y),f=u*(o.x-s.x),p=d*n+f*i,m=d*r+f*i,h=d*n+f*a,g=d*r+f*a;if(Math.max(p,m,h,g)<=d*o.x+f*o.y||Math.min(p,m,h,g)>=d*l.x+f*l.y)return!1;let _=u*(o.y-c.y),v=u*(c.x-o.x),y=_*n+v*i,b=_*r+v*i,x=_*n+v*a,S=_*r+v*a;return!(Math.max(y,b,x,S)<=_*o.x+v*o.y||Math.min(y,b,x,S)>=_*l.x+v*l.y)}pad(e=0,t=e){return this.x-=e,this.y-=t,this.width+=e*2,this.height+=t*2,this}fit(e){let t=Math.max(this.x,e.x),n=Math.min(this.x+this.width,e.x+e.width),r=Math.max(this.y,e.y),i=Math.min(this.y+this.height,e.y+e.height);return this.x=t,this.width=Math.max(n-t,0),this.y=r,this.height=Math.max(i-r,0),this}ceil(e=1,t=.001){let n=Math.ceil((this.x+this.width-t)*e)/e,r=Math.ceil((this.y+this.height-t)*e)/e;return this.x=Math.floor((this.x+t)*e)/e,this.y=Math.floor((this.y+t)*e)/e,this.width=n-this.x,this.height=r-this.y,this}scale(e,t=e){return this.x*=e,this.y*=t,this.width*=e,this.height*=t,this}enlarge(e){let t=Math.min(this.x,e.x),n=Math.max(this.x+this.width,e.x+e.width),r=Math.min(this.y,e.y),i=Math.max(this.y+this.height,e.y+e.height);return this.x=t,this.width=n-t,this.y=r,this.height=i-r,this}getBounds(t){return t||=new e,t.copyFrom(this),t}containsRect(e){if(this.width<=0||this.height<=0)return!1;let t=e.x,n=e.y,r=e.x+e.width,i=e.y+e.height;return t>=this.x&&t<this.x+this.width&&n>=this.y&&n<this.y+this.height&&r>=this.x&&r<=this.x+this.width&&i>=this.y&&i<=this.y+this.height}set(e,t,n,r){return this.x=e,this.y=t,this.width=n,this.height=r,this}toString(){return`[pixi.js/math:Rectangle x=${this.x} y=${this.y} width=${this.width} height=${this.height}]`}},Pt={default:-1};function I(e=`default`){return Pt[e]===void 0&&(Pt[e]=-1),++Pt[e]}var Ft=new Set,L=`8.0.0`,It=`8.3.4`,Lt=`8.21.0`,Rt=`8.22.0`,zt={quiet:!1,noColor:!1},R=((e,t,n=3)=>{if(zt.quiet||Ft.has(t))return;let r=Error().stack,i=`${t}
|
|
3
|
+
Deprecated since v${e}`,a=typeof console.groupCollapsed==`function`&&!zt.noColor;r===void 0?console.warn(`PixiJS Deprecation Warning: `,i):(r=r.split(`
|
|
4
|
+
`).splice(n).join(`
|
|
5
|
+
`),a?(console.groupCollapsed(`%cPixiJS Deprecation Warning: %c%s`,`color:#614108;background:#fffbe6`,`font-weight:normal;color:#614108;background:#fffbe6`,i),console.warn(r),console.groupEnd()):(console.warn(`PixiJS Deprecation Warning: `,i),console.warn(r))),Ft.add(t)});Object.defineProperties(R,{quiet:{get:()=>zt.quiet,set:e=>{zt.quiet=e},enumerable:!0,configurable:!1},noColor:{get:()=>zt.noColor,set:e=>{zt.noColor=e},enumerable:!0,configurable:!1}});var Bt=()=>{};function Vt(e){return e.endsWith(`int`)}function Ht(e){return e+=+(e===0),--e,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e+1}function Ut(e){return!(e&e-1)&&!!e}function Wt(e){let t={};for(let n in e)e[n]!==void 0&&(t[n]=e[n]);return t}var Gt=Object.create(null);function Kt(e){let t=Gt[e];return t===void 0&&(Gt[e]=I(`resource`)),t}var qt=class e extends gt{constructor(t={}){super(),this._resourceType=`textureSampler`,this._maxAnisotropy=1,this.destroyed=!1,t={...e.defaultOptions,...t},this.addressMode=t.addressMode,this.addressModeU=t.addressModeU??this.addressModeU,this.addressModeV=t.addressModeV??this.addressModeV,this.addressModeW=t.addressModeW??this.addressModeW,this.scaleMode=t.scaleMode,this.magFilter=t.magFilter??this.magFilter,this.minFilter=t.minFilter??this.minFilter,this.mipmapFilter=t.mipmapFilter??this.mipmapFilter,this.lodMinClamp=t.lodMinClamp,this.lodMaxClamp=t.lodMaxClamp,this.compare=t.compare,this.maxAnisotropy=t.maxAnisotropy??1}set addressMode(e){this.addressModeU=e,this.addressModeV=e,this.addressModeW=e}get addressMode(){return this.addressModeU}set wrapMode(e){R(L,`TextureStyle.wrapMode is now TextureStyle.addressMode`),this.addressMode=e}get wrapMode(){return this.addressMode}set scaleMode(e){this.magFilter=e,this.minFilter=e,this.mipmapFilter=e}get scaleMode(){return this.magFilter}set maxAnisotropy(e){this._maxAnisotropy=Math.min(e,16),this._maxAnisotropy>1&&(this.scaleMode=`linear`)}get maxAnisotropy(){return this._maxAnisotropy}get _resourceId(){return this._sharedResourceId||this._generateResourceId()}update(){this._sharedResourceId=null,this.emit(`change`,this)}_generateResourceId(){let e=`${this.addressModeU}-${this.addressModeV}-${this.addressModeW}-${this.magFilter}-${this.minFilter}-${this.mipmapFilter}-${this.lodMinClamp}-${this.lodMaxClamp}-${this.compare}-${this._maxAnisotropy}`;return this._sharedResourceId=Kt(e),this._resourceId}destroy(){this.destroyed=!0,this.emit(`destroy`,this),this.emit(`change`,this),this.removeAllListeners()}};qt.defaultOptions={addressMode:`clamp-to-edge`,scaleMode:`linear`};var Jt=qt,Yt=class e extends gt{constructor(t={}){super(),this.options=t,this._gpuData=Object.create(null),this._gcLastUsed=-1,this.uid=I(`textureSource`),this._resourceType=`textureSource`,this._resourceId=I(`resource`),this.uploadMethodId=`unknown`,this._resolution=1,this.pixelWidth=1,this.pixelHeight=1,this.width=1,this.height=1,this.sampleCount=1,this.mipLevelCount=1,this.autoGenerateMipmaps=!1,this.format=`rgba8unorm`,this.dimension=`2d`,this.viewDimension=`2d`,this.arrayLayerCount=1,this.depth=1,this._ownsStyle=!1,this.antialias=!1,this.transient=!1,this.storage=!1,this._batchTick=-1,this._textureBindLocation=-1;let n=t;t={...e.defaultOptions,...t};let r=Zt(t),i=r===`3d`||r===`1d`?r:`2d`;Qt(n,r,i),this.label=t.label??``,this.resource=t.resource,this.autoGarbageCollect=t.autoGarbageCollect,this._resolution=t.resolution,this.pixelWidth=t.width?t.width*this._resolution:this.resource?this.resourceWidth??1:1,this.pixelHeight=t.height?t.height*this._resolution:this.resource?this.resourceHeight??1:1,this.width=this.pixelWidth/this._resolution,this.height=this.pixelHeight/this._resolution,this.format=t.format,this.dimension=i,this.viewDimension=r,this.arrayLayerCount=t.arrayLayerCount,this.depth=i===`3d`?t.depth??1:1,this.mipLevelCount=t.mipLevelCount,this.autoGenerateMipmaps=t.autoGenerateMipmaps,this.sampleCount=t.sampleCount,this.antialias=i!==`3d`&&t.antialias,this.transient=t.transient??!1,this.storage=t.storage??!1,this.alphaMode=t.alphaMode,this.style=new Jt(Wt(t)),this._ownsStyle=!0,this.destroyed=!1,this._refreshPOT()}get depthOrArrayLayers(){return this.dimension===`3d`?this.depth:this.arrayLayerCount||1}get source(){return this}get style(){return this._style}set style(e){this.style!==e&&(this._ownsStyle=!1,this._style?.off(`change`,this._onStyleChange,this),this._style=e,this._style?.on(`change`,this._onStyleChange,this),this._onStyleChange())}set maxAnisotropy(e){this._style.maxAnisotropy=e}get maxAnisotropy(){return this._style.maxAnisotropy}get addressMode(){return this._style.addressMode}set addressMode(e){this._style.addressMode=e}get repeatMode(){return this._style.addressMode}set repeatMode(e){this._style.addressMode=e}get magFilter(){return this._style.magFilter}set magFilter(e){this._style.magFilter=e}get minFilter(){return this._style.minFilter}set minFilter(e){this._style.minFilter=e}get mipmapFilter(){return this._style.mipmapFilter}set mipmapFilter(e){this._style.mipmapFilter=e}get lodMinClamp(){return this._style.lodMinClamp}set lodMinClamp(e){this._style.lodMinClamp=e}get lodMaxClamp(){return this._style.lodMaxClamp}set lodMaxClamp(e){this._style.lodMaxClamp=e}_onStyleChange(){this.emit(`styleChange`,this)}update(){if(this.resource){let e=this._resolution;if(this.resize(this.resourceWidth/e,this.resourceHeight/e))return}this.emit(`update`,this)}destroy(){this.destroyed=!0,this.unload(),this.emit(`destroy`,this),this._style&&=(this._ownsStyle&&this._style.destroy(),null),this.uploadMethodId=null,this.resource=null,this.removeAllListeners()}unload(){this._resourceId=I(`resource`),this.emit(`change`,this),this.emit(`unload`,this);for(let e in this._gpuData)this._gpuData[e]?.destroy?.();this._gpuData=Object.create(null)}get resourceWidth(){let{resource:e}=this;return e.naturalWidth||e.videoWidth||e.displayWidth||e.width}get resourceHeight(){let{resource:e}=this;return e.naturalHeight||e.videoHeight||e.displayHeight||e.height}get resolution(){return this._resolution}set resolution(e){this._resolution!==e&&(this._resolution=e,this.width=this.pixelWidth/e,this.height=this.pixelHeight/e)}resize(e,t,n){n||=this._resolution,e||=this.width,t||=this.height;let r=Math.round(e*n),i=Math.round(t*n);return this.width=r/n,this.height=i/n,this._resolution=n,this.pixelWidth===r&&this.pixelHeight===i?!1:(this._refreshPOT(),this.pixelWidth=r,this.pixelHeight=i,this.emit(`resize`,this),this._resourceId=I(`resource`),this.emit(`change`,this),!0)}updateMipmaps(){this.autoGenerateMipmaps&&this.mipLevelCount>1&&this.emit(`updateMipmaps`,this)}set wrapMode(e){this._style.wrapMode=e}get wrapMode(){return this._style.wrapMode}set scaleMode(e){this._style.scaleMode=e}get scaleMode(){return this._style.scaleMode}_refreshPOT(){this.isPowerOfTwo=Ut(this.pixelWidth)&&Ut(this.pixelHeight)}static test(e){throw Error(`Unimplemented`)}};Yt.defaultOptions={resolution:1,format:`bgra8unorm`,alphaMode:`premultiply-alpha-on-upload`,arrayLayerCount:1,mipLevelCount:1,autoGenerateMipmaps:!1,sampleCount:1,antialias:!1,autoGarbageCollect:!1};var Xt=Yt;function Zt(e){return e.viewDimension?e.viewDimension:e.depth?`3d`:e.arrayLayerCount>1?`2d-array`:`2d`}function Qt(e,t,n){if(e.depth!==void 0&&typeof e.depth!=`number`)throw Error(`[TextureSource] depth is a 3D texture's depth in texels, but got ${e.depth}. For a depth buffer, use the depth option of a RenderTarget or the renderer.`);if(e.depth&&e.arrayLayerCount>1)throw Error(`[TextureSource] depth and arrayLayerCount can't be combined: use depth for a 3D texture or arrayLayerCount for a 2D array.`);if(e.depth&&t!==`3d`)throw Error(`[TextureSource] depth makes a 3D texture, but viewDimension is '${t}'. Use arrayLayerCount for layered textures.`);if(t===`3d`&&e.arrayLayerCount>1)throw Error(`[TextureSource] a 3D texture takes depth, not arrayLayerCount.`);if(e.dimensions&&e.dimensions!==n)throw Error(`[TextureSource] dimensions '${e.dimensions}' doesn't match viewDimension '${t}'. Leave dimensions out; it is derived from the view.`);if(e.dimensions&&R(Rt,`TextureSource dimensions is derived from viewDimension and depth; leave it out.`),n===`3d`&&e.antialias)throw Error(`[TextureSource] a 3D texture can't be antialiased: WebGPU has no multisampled 3D textures.`)}var $t=class extends Xt{constructor(e){let t=e.depth??e.arrayLayerCount??1,n=e.resource||new Float32Array(e.width*e.height*t*4),r=e.format;r||=n instanceof Float32Array?`rgba32float`:n instanceof Int32Array||n instanceof Uint32Array?`rgba32uint`:n instanceof Int16Array||n instanceof Uint16Array?`rgba16uint`:(n instanceof Int8Array,`bgra8unorm`);let i=Vt(r)||t>1;super({...i&&{alphaMode:`no-premultiply-alpha`},...e,resource:n,format:r}),this.uploadMethodId=`buffer`,this._updateStart=0,this._updateEnd=1/0}update(e=0,t=1/0){if((e>0||t<1/0)&&this.depthOrArrayLayers>1)throw Error(`[BufferImageSource] a 3D texture or 2D array uploads whole: call update() with no range.`);this._updateStart=e,this._updateEnd=t,super.update(),this._updateStart=0,this._updateEnd=1/0}static test(e){return e instanceof Int8Array||e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int16Array||e instanceof Uint16Array||e instanceof Int32Array||e instanceof Uint32Array||e instanceof Float32Array}};$t.extension=N.TextureSource;var en=new P,tn=class{constructor(e,t){this.mapCoord=new P,this.uClampFrame=new Float32Array(4),this.uClampOffset=new Float32Array(2),this._updateID=0,this.clampOffset=0,this.clampMargin=t===void 0?e.width<10?0:.5:t,this.isSimple=!1,this.texture=e}get texture(){return this._texture}set texture(e){this._texture!==e&&(this._texture?.removeListener(`update`,this.update,this),this._texture=e,this._texture.addListener(`update`,this.update,this)),this.update()}destroy(){this._texture?.removeListener(`update`,this.update,this),this._texture=null}multiplyUvs(e,t){t===void 0&&(t=e);let n=this.mapCoord;for(let r=0;r<e.length;r+=2){let i=e[r],a=e[r+1];t[r]=i*n.a+a*n.c+n.tx,t[r+1]=i*n.b+a*n.d+n.ty}return t}update(){let e=this._texture;this._updateID++;let t=e.uvs;this.mapCoord.set(t.x1-t.x0,t.y1-t.y0,t.x3-t.x0,t.y3-t.y0,t.x0,t.y0);let n=e.orig,r=e.trim;r&&(en.set(n.width/r.width,0,0,n.height/r.height,-r.x/r.width,-r.y/r.height),this.mapCoord.append(en));let i=e.source,a=this.uClampFrame,o=this.clampMargin/i._resolution,s=this.clampOffset/i._resolution;return a[0]=(e.frame.x+o+s)/i.width,a[1]=(e.frame.y+o+s)/i.height,a[2]=(e.frame.x+e.frame.width-o+s)/i.width,a[3]=(e.frame.y+e.frame.height-o+s)/i.height,this.uClampOffset[0]=this.clampOffset/i.pixelWidth,this.uClampOffset[1]=this.clampOffset/i.pixelHeight,this.isSimple=e.frame.width===i.width&&e.frame.height===i.height&&e.rotate===0,!0}},z=class extends gt{constructor({source:e,label:t,frame:n,orig:r,trim:i,defaultAnchor:a,defaultBorders:o,rotate:s,dynamic:c}={}){if(super(),this.uid=I(`texture`),this.uvs={x0:0,y0:0,x1:0,y1:0,x2:0,y2:0,x3:0,y3:0},this.frame=new Nt,this.noFrame=!1,this.dynamic=!1,this.isTexture=!0,this.label=t,this.source=e?.source??new Xt,this.noFrame=!n,n)this.frame.copyFrom(n);else{let{width:e,height:t}=this._source;this.frame.width=e,this.frame.height=t}this.orig=r||this.frame,this.trim=i,this.rotate=s??0,this.defaultAnchor=a,this.defaultBorders=o,this.destroyed=!1,this.dynamic=c||!1,this.updateUvs()}set source(e){this._source&&this._source.off(`resize`,this.update,this),this._source=e,e.on(`resize`,this.update,this),this.emit(`update`,this)}get source(){return this._source}get textureMatrix(){return this._textureMatrix||=new tn(this),this._textureMatrix}get width(){return this.orig.width}get height(){return this.orig.height}updateUvs(){let{uvs:e,frame:t}=this,{width:n,height:r}=this._source,i=t.x/n,a=t.y/r,o=t.width/n,s=t.height/r,c=this.rotate;if(c){let t=o/2,n=s/2,r=i+t,l=a+n;c=F.add(c,F.NW),e.x0=r+t*F.uX(c),e.y0=l+n*F.uY(c),c=F.add(c,2),e.x1=r+t*F.uX(c),e.y1=l+n*F.uY(c),c=F.add(c,2),e.x2=r+t*F.uX(c),e.y2=l+n*F.uY(c),c=F.add(c,2),e.x3=r+t*F.uX(c),e.y3=l+n*F.uY(c)}else e.x0=i,e.y0=a,e.x1=i+o,e.y1=a,e.x2=i+o,e.y2=a+s,e.x3=i,e.y3=a+s}destroy(e=!1){this._source&&(this._source.off(`resize`,this.update,this),e&&(this._source.destroy(),this._source=null)),this._textureMatrix=null,this.destroyed=!0,this.emit(`destroy`,this),this.removeAllListeners()}update(){this.noFrame&&(this.frame.width=this._source.width,this.frame.height=this._source.height),this.updateUvs(),this.emit(`update`,this)}get baseTexture(){return R(L,`Texture.baseTexture is now Texture.source`),this._source}};z.EMPTY=new z({label:`EMPTY`,source:new Xt({label:`EMPTY`})}),z.EMPTY.destroy=Bt,z.WHITE=new z({source:new $t({resource:new Uint8Array([255,255,255,255]),width:1,height:1,alphaMode:`premultiply-alpha-on-upload`,label:`WHITE`}),label:`WHITE`}),z.WHITE.destroy=Bt;function nn(e,t,n){let{width:r,height:i}=n.orig,a=n.trim;if(a){let n=a.width,o=a.height;e.minX=a.x-t._x*r,e.maxX=e.minX+n,e.minY=a.y-t._y*i,e.maxY=e.minY+o}else e.minX=-t._x*r,e.maxX=e.minX+r,e.minY=-t._y*i,e.maxY=e.minY+i}for(var rn=new P,an=class e{constructor(e=1/0,t=1/0,n=-1/0,r=-1/0){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=rn,this.minX=e,this.minY=t,this.maxX=n,this.maxY=r}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}get rectangle(){this._rectangle||=new Nt;let e=this._rectangle;return this.minX>this.maxX||this.minY>this.maxY?(e.x=0,e.y=0,e.width=0,e.height=0):e.copyFromBounds(this),e}clear(){return this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.matrix=rn,this}set(e,t,n,r){this.minX=e,this.minY=t,this.maxX=n,this.maxY=r}addFrame(e,t,n,r,i){i||=this.matrix;let a=i.a,o=i.b,s=i.c,c=i.d,l=i.tx,u=i.ty,d=this.minX,f=this.minY,p=this.maxX,m=this.maxY,h=a*e+s*t+l,g=o*e+c*t+u;h<d&&(d=h),g<f&&(f=g),h>p&&(p=h),g>m&&(m=g),h=a*n+s*t+l,g=o*n+c*t+u,h<d&&(d=h),g<f&&(f=g),h>p&&(p=h),g>m&&(m=g),h=a*e+s*r+l,g=o*e+c*r+u,h<d&&(d=h),g<f&&(f=g),h>p&&(p=h),g>m&&(m=g),h=a*n+s*r+l,g=o*n+c*r+u,h<d&&(d=h),g<f&&(f=g),h>p&&(p=h),g>m&&(m=g),this.minX=d,this.minY=f,this.maxX=p,this.maxY=m}addRect(e,t){this.addFrame(e.x,e.y,e.x+e.width,e.y+e.height,t)}addBounds(e,t){this.addFrame(e.minX,e.minY,e.maxX,e.maxY,t)}addBoundsMask(e){this.minX=this.minX>e.minX?this.minX:e.minX,this.minY=this.minY>e.minY?this.minY:e.minY,this.maxX=this.maxX<e.maxX?this.maxX:e.maxX,this.maxY=this.maxY<e.maxY?this.maxY:e.maxY}applyMatrix(e){let t=this.minX,n=this.minY,r=this.maxX,i=this.maxY,{a,b:o,c:s,d:c,tx:l,ty:u}=e,d=a*t+s*n+l,f=o*t+c*n+u;this.minX=d,this.minY=f,this.maxX=d,this.maxY=f,d=a*r+s*n+l,f=o*r+c*n+u,this.minX=d<this.minX?d:this.minX,this.minY=f<this.minY?f:this.minY,this.maxX=d>this.maxX?d:this.maxX,this.maxY=f>this.maxY?f:this.maxY,d=a*t+s*i+l,f=o*t+c*i+u,this.minX=d<this.minX?d:this.minX,this.minY=f<this.minY?f:this.minY,this.maxX=d>this.maxX?d:this.maxX,this.maxY=f>this.maxY?f:this.maxY,d=a*r+s*i+l,f=o*r+c*i+u,this.minX=d<this.minX?d:this.minX,this.minY=f<this.minY?f:this.minY,this.maxX=d>this.maxX?d:this.maxX,this.maxY=f>this.maxY?f:this.maxY}fit(e){return this.minX<e.left&&(this.minX=e.left),this.maxX>e.right&&(this.maxX=e.right),this.minY<e.top&&(this.minY=e.top),this.maxY>e.bottom&&(this.maxY=e.bottom),this}fitBounds(e,t,n,r){return this.minX<e&&(this.minX=e),this.maxX>t&&(this.maxX=t),this.minY<n&&(this.minY=n),this.maxY>r&&(this.maxY=r),this}pad(e,t=e){return this.minX-=e,this.maxX+=e,this.minY-=t,this.maxY+=t,this}ceil(){return this.minX=Math.floor(this.minX),this.minY=Math.floor(this.minY),this.maxX=Math.ceil(this.maxX),this.maxY=Math.ceil(this.maxY),this}clone(){return new e(this.minX,this.minY,this.maxX,this.maxY)}scale(e,t=e){return this.minX*=e,this.minY*=t,this.maxX*=e,this.maxY*=t,this}get x(){return this.minX}set x(e){let t=this.maxX-this.minX;this.minX=e,this.maxX=e+t}get y(){return this.minY}set y(e){let t=this.maxY-this.minY;this.minY=e,this.maxY=e+t}get width(){return this.maxX-this.minX}set width(e){this.maxX=this.minX+e}get height(){return this.maxY-this.minY}set height(e){this.maxY=this.minY+e}get left(){return this.minX}get right(){return this.maxX}get top(){return this.minY}get bottom(){return this.maxY}get isPositive(){return this.maxX-this.minX>0&&this.maxY-this.minY>0}get isValid(){return this.minX+this.minY!==1/0}addVertexData(e,t,n,r){let i=this.minX,a=this.minY,o=this.maxX,s=this.maxY;r||=this.matrix;let c=r.a,l=r.b,u=r.c,d=r.d,f=r.tx,p=r.ty;for(let r=t;r<n;r+=2){let t=e[r],n=e[r+1],m=c*t+u*n+f,h=l*t+d*n+p;i=m<i?m:i,a=h<a?h:a,o=m>o?m:o,s=h>s?h:s}this.minX=i,this.minY=a,this.maxX=o,this.maxY=s}containsPoint(e,t){return this.minX<=e&&this.minY<=t&&this.maxX>=e&&this.maxY>=t}toString(){return`[pixi.js:Bounds minX=${this.minX} minY=${this.minY} maxX=${this.maxX} maxY=${this.maxY} width=${this.width} height=${this.height}]`}copyFrom(e){return this.minX=e.minX,this.minY=e.minY,this.maxX=e.maxX,this.maxY=e.maxY,this}},on={grad:.9,turn:360,rad:360/(2*Math.PI)},sn=function(e){return typeof e==`string`?e.length>0:typeof e==`number`},cn=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=10**t),Math.round(n*e)/n+0},ln=function(e){var t=Math.round(100*e)/100;return Math.round(255*t)===255*e?t:Math.round(1e3*e)/1e3},un=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=1),e>n?n:e>t?e:t},dn=function(e){return(e=isFinite(e)?e%360:0)<0?e+360:e},fn=function(e,t){return t===void 0&&(t=0),cn(e,t)%360},pn=function(e){return{r:un(e.r,0,255),g:un(e.g,0,255),b:un(e.b,0,255),a:un(e.a)}},mn=function(e){return{r:cn(e.r),g:cn(e.g),b:cn(e.b),a:ln(e.a)}},hn=/^#([0-9a-f]{3,8})$/i,gn=function(e,t){var n=e.charCodeAt(t);return(15&n)+9*(n>>6)},_n=function(e,t){return gn(e,t)<<4|gn(e,t+1)},vn=[],yn=0;yn<256;yn++)vn.push((yn<16?`0`:``)+yn.toString(16));var bn=function(e){return vn[un(e,0,255)]},xn=function(e){var t=e.r,n=e.g,r=e.b,i=e.a,a=Math.max(t,n,r),o=a-Math.min(t,n,r),s=o?a===t?(n-r)/o:a===n?2+(r-t)/o:4+(t-n)/o:0;return{h:60*(s<0?s+6:s),s:a?o/a*100:0,v:a/255*100,a:i}},Sn=function(e){var t=e.h,n=e.s,r=e.v,i=e.a;t=t/360*6,n/=100,r/=100;var a=Math.floor(t),o=r*(1-n),s=r*(1-(t-a)*n),c=r*(1-(1-t+a)*n),l=a%6,u=function(e){return Math.round(255e9*e)/1e9+0};return{r:u([r,s,o,o,c,r][l]),g:u([c,r,r,s,o,o][l]),b:u([o,o,c,r,r,s][l]),a:i}},Cn=function(e){return{h:dn(e.h),s:un(e.s,0,100),l:un(e.l,0,100),a:un(e.a)}},wn=function(e){return{h:fn(e.h),s:cn(e.s),l:cn(e.l),a:ln(e.a)}},Tn=function(e){return Sn((n=(t=e).s,{h:t.h,s:(n*=((r=t.l)<50?r:100-r)/100)>0?2*n/(r+n)*100:0,v:r+n,a:t.a}));var t,n,r},En=function(e){return{h:(t=xn(e)).h,s:(i=(200-(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(!hn.test(e))return null;var t=e.length;return t<=5?{r:17*gn(e,1),g:17*gn(e,2),b:17*gn(e,3),a:t===5?17*gn(e,4)/255:1}:t===7||t===9?{r:_n(e,1),g:_n(e,3),b:_n(e,5),a:t===9?_n(e,7)/255:1}:null},`hex`],[function(e){var t=kn.exec(e);if(t&&(t[2]!==t[4]||t[4]!==t[6]))return null;var n=t||An.exec(e);return n?pn({r:Number(n[1])/(n[2]?100/255:1),g:Number(n[3])/(n[4]?100/255:1),b:Number(n[5])/(n[6]?100/255:1),a:n[7]===void 0?1:Number(n[7])/(n[8]?100:1)}):null},`rgb`],[function(e){var t=Dn.exec(e)||On.exec(e);if(!t)return null;var n,r;return Tn(Cn({h:(n=t[1],r=t[2],r===void 0&&(r=`deg`),Number(n)*(on[r.toLowerCase()]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)}))},`hsl`]],object:[[function(e){var t=e.r,n=e.g,r=e.b,i=e.a,a=i===void 0?1:i;return sn(t)&&sn(n)&&sn(r)?pn({r:Number(t),g:Number(n),b:Number(r),a:Number(a)}):null},`rgb`],[function(e){var t=e.h,n=e.s,r=e.l,i=e.a,a=i===void 0?1:i;return!sn(t)||!sn(n)||!sn(r)?null:Tn(Cn({h:Number(t),s:Number(n),l:Number(r),a:Number(a)}))},`hsl`],[function(e){var t=e.h,n=e.s,r=e.v,i=e.a,a=i===void 0?1:i;return!sn(t)||!sn(n)||!sn(r)?null:Sn(function(e){return{h:dn(e.h),s:un(e.s,0,100),v:un(e.v,0,100),a:un(e.a)}}({h:Number(t),s:Number(n),v:Number(r),a:Number(a)}))},`hsv`]]},Mn=function(e,t){for(var n=0;n<t.length;n++){var r=t[n][0](e);if(r)return[r,t[n][1]]}return[null,void 0]},Nn=function(e){return typeof e==`string`?Mn(e.trim(),jn.string):typeof e==`object`&&e?Mn(e,jn.object):[null,void 0]},Pn=function(e,t,n){var r=En(e);return{h:r.h,s:un(r.s+t*(n?r.s:100),0,100),l:r.l,a:r.a}},Fn=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},In=function(e,t,n){var r=En(e);return{h:r.h,s:r.s,l:un(r.l+t*(n?r.l:100),0,100),a:r.a}},Ln=function(){function e(e){this.parsed=Nn(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return e.prototype.isValid=function(){return this.parsed!==null},e.prototype.brightness=function(){return cn(Fn(this.rgba),2)},e.prototype.isDark=function(){return Fn(this.rgba)<.5},e.prototype.isLight=function(){return Fn(this.rgba)>=.5},e.prototype.toHex=function(){return e=mn(this.rgba),t=e.r,n=e.g,r=e.b,a=(i=e.a)<1?bn(cn(255*i)):``,`#`+bn(t)+bn(n)+bn(r)+a;var e,t,n,r,i,a},e.prototype.toRgb=function(){return mn(this.rgba)},e.prototype.toRgbString=function(){return e=mn(this.rgba),t=e.r,n=e.g,r=e.b,(i=e.a)<1?`rgba(`+t+`, `+n+`, `+r+`, `+i+`)`:`rgb(`+t+`, `+n+`, `+r+`)`;var e,t,n,r,i},e.prototype.toHsl=function(){return wn(En(this.rgba))},e.prototype.toHslString=function(){return e=wn(En(this.rgba)),t=e.h,n=e.s,r=e.l,(i=e.a)<1?`hsla(`+t+`, `+n+`%, `+r+`%, `+i+`)`:`hsl(`+t+`, `+n+`%, `+r+`%)`;var e,t,n,r,i},e.prototype.toHsv=function(){return e=xn(this.rgba),{h:fn(e.h),s:cn(e.s),v:cn(e.v),a:ln(e.a)};var e},e.prototype.invert=function(){return Rn({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},e.prototype.saturate=function(e,t){return e===void 0&&(e=.1),Rn(Pn(this.rgba,e,t?.relative))},e.prototype.desaturate=function(e,t){return e===void 0&&(e=.1),Rn(Pn(this.rgba,-e,t?.relative))},e.prototype.grayscale=function(){return Rn(Pn(this.rgba,-1))},e.prototype.lighten=function(e,t){return e===void 0&&(e=.1),Rn(In(this.rgba,e,t?.relative))},e.prototype.darken=function(e,t){return e===void 0&&(e=.1),Rn(In(this.rgba,-e,t?.relative))},e.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(En(this.rgba).h+e)},e.prototype.alpha=function(e){return typeof e==`number`?Rn({r:(t=this.rgba).r,g:t.g,b:t.b,a:e}):ln(this.rgba.a);var t},e.prototype.hue=function(e){var t=En(this.rgba);return typeof e==`number`?Rn({h:e,s:t.s,l:t.l,a:t.a}):fn(t.h)},e.prototype.isEqual=function(e){return this.toHex()===Rn(e).toHex()},e}(),Rn=function(e){return e instanceof Ln?e:new Ln(e)},zn=[];(function(e){e.forEach(function(e){zn.indexOf(e)<0&&(e(Ln,jn),zn.push(e))})})([function(e,t){var n={white:`#ffffff`,bisque:`#ffe4c4`,blue:`#0000ff`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,antiquewhite:`#faebd7`,aqua:`#00ffff`,azure:`#f0ffff`,whitesmoke:`#f5f5f5`,papayawhip:`#ffefd5`,plum:`#dda0dd`,blanchedalmond:`#ffebcd`,black:`#000000`,gold:`#ffd700`,goldenrod:`#daa520`,gainsboro:`#dcdcdc`,cornsilk:`#fff8dc`,cornflowerblue:`#6495ed`,burlywood:`#deb887`,aquamarine:`#7fffd4`,beige:`#f5f5dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkkhaki:`#bdb76b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkgrey:`#a9a9a9`,peachpuff:`#ffdab9`,darkmagenta:`#8b008b`,darkred:`#8b0000`,darkorchid:`#9932cc`,darkorange:`#ff8c00`,darkslateblue:`#483d8b`,gray:`#808080`,darkslategray:`#2f4f4f`,darkslategrey:`#2f4f4f`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,wheat:`#f5deb3`,firebrick:`#b22222`,floralwhite:`#fffaf0`,ghostwhite:`#f8f8ff`,darkviolet:`#9400d3`,magenta:`#ff00ff`,green:`#008000`,dodgerblue:`#1e90ff`,grey:`#808080`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,blueviolet:`#8a2be2`,forestgreen:`#228b22`,lawngreen:`#7cfc00`,indianred:`#cd5c5c`,indigo:`#4b0082`,fuchsia:`#ff00ff`,brown:`#a52a2a`,maroon:`#800000`,mediumblue:`#0000cd`,lightcoral:`#f08080`,darkturquoise:`#00ced1`,lightcyan:`#e0ffff`,ivory:`#fffff0`,lightyellow:`#ffffe0`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,linen:`#faf0e6`,mediumaquamarine:`#66cdaa`,lemonchiffon:`#fffacd`,lime:`#00ff00`,khaki:`#f0e68c`,mediumseagreen:`#3cb371`,limegreen:`#32cd32`,mediumspringgreen:`#00fa9a`,lightskyblue:`#87cefa`,lightblue:`#add8e6`,midnightblue:`#191970`,lightpink:`#ffb6c1`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,mintcream:`#f5fffa`,lightslategray:`#778899`,lightslategrey:`#778899`,navajowhite:`#ffdead`,navy:`#000080`,mediumvioletred:`#c71585`,powderblue:`#b0e0e6`,palegoldenrod:`#eee8aa`,oldlace:`#fdf5e6`,paleturquoise:`#afeeee`,mediumturquoise:`#48d1cc`,mediumorchid:`#ba55d3`,rebeccapurple:`#663399`,lightsteelblue:`#b0c4de`,mediumslateblue:`#7b68ee`,thistle:`#d8bfd8`,tan:`#d2b48c`,orchid:`#da70d6`,mediumpurple:`#9370db`,purple:`#800080`,pink:`#ffc0cb`,skyblue:`#87ceeb`,springgreen:`#00ff7f`,palegreen:`#98fb98`,red:`#ff0000`,yellow:`#ffff00`,slateblue:`#6a5acd`,lavenderblush:`#fff0f5`,peru:`#cd853f`,palevioletred:`#db7093`,violet:`#ee82ee`,teal:`#008080`,slategray:`#708090`,slategrey:`#708090`,aliceblue:`#f0f8ff`,darkseagreen:`#8fbc8f`,darkolivegreen:`#556b2f`,greenyellow:`#adff2f`,seagreen:`#2e8b57`,seashell:`#fff5ee`,tomato:`#ff6347`,silver:`#c0c0c0`,sienna:`#a0522d`,lavender:`#e6e6fa`,lightgreen:`#90ee90`,orange:`#ffa500`,orangered:`#ff4500`,steelblue:`#4682b4`,royalblue:`#4169e1`,turquoise:`#40e0d0`,yellowgreen:`#9acd32`,salmon:`#fa8072`,saddlebrown:`#8b4513`,sandybrown:`#f4a460`,rosybrown:`#bc8f8f`,darksalmon:`#e9967a`,lightgoldenrodyellow:`#fafad2`,snow:`#fffafa`,lightgrey:`#d3d3d3`,lightgray:`#d3d3d3`,dimgray:`#696969`,dimgrey:`#696969`,olivedrab:`#6b8e23`,olive:`#808000`},r={};for(var i in n)r[n[i]]=i;var a={};e.prototype.toName=function(t){if(!(this.rgba.a||this.rgba.r||this.rgba.g||this.rgba.b))return`transparent`;var i,o,s=r[this.toHex()];if(s)return s;if(t?.closest){var c=this.toRgb(),l=1/0,u=`black`;if(!a.length)for(var d in n)a[d]=new e(n[d]).toRgb();for(var f in n){var p=(i=c,o=a[f],(i.r-o.r)**2+(i.g-o.g)**2+(i.b-o.b)**2);p<l&&(l=p,u=f)}return u}},t.string.push([function(t){var r=t.toLowerCase(),i=r===`transparent`?`#0000`:n[r];return typeof i==`string`?new e(i).toRgb():null},`name`])}]);var Bn=class e{constructor(e=0xffffff){this._value=null,this._components=new Float32Array(4),this._components.fill(1),this._int=0xffffff,this.value=e}get red(){return this._components[0]}get green(){return this._components[1]}get blue(){return this._components[2]}get alpha(){return this._components[3]}setValue(e){return this.value=e,this}set value(t){if(t instanceof e)this._value=this._cloneSource(t._value),this._int=t._int,this._components.set(t._components);else if(t===null)throw Error(`Cannot set Color#value to null`);else this._value!==null&&this._isSourceEqual(this._value,t)||(this._value=this._cloneSource(t),this._normalize(this._value))}get value(){return this._value}_cloneSource(e){return typeof e==`string`||typeof e==`number`||e instanceof Number||e===null?e:Array.isArray(e)||ArrayBuffer.isView(e)?e.slice(0):typeof e==`object`&&e?{...e}:e}_isSourceEqual(e,t){let n=typeof e;if(n!==typeof t)return!1;if(n===`number`||n===`string`||e instanceof Number)return e===t;if(Array.isArray(e)&&Array.isArray(t)||ArrayBuffer.isView(e)&&ArrayBuffer.isView(t))return e.length===t.length&&e.every((e,n)=>e===t[n]);if(e!==null&&t!==null){let n=Object.keys(e),r=Object.keys(t);return n.length===r.length&&n.every(n=>e[n]===t[n])}return e===t}toRgba(){let[e,t,n,r]=this._components;return{r:e,g:t,b:n,a:r}}toRgb(){let[e,t,n]=this._components;return{r:e,g:t,b:n}}toRgbaString(){let[e,t,n]=this.toUint8RgbArray();return`rgba(${e},${t},${n},${this.alpha})`}toUint8RgbArray(e){let[t,n,r]=this._components;return this._arrayRgb||=[],e||=this._arrayRgb,e[0]=Math.round(t*255),e[1]=Math.round(n*255),e[2]=Math.round(r*255),e}toArray(e){this._arrayRgba||=[],e||=this._arrayRgba;let[t,n,r,i]=this._components;return e[0]=t,e[1]=n,e[2]=r,e[3]=i,e}toRgbArray(e){this._arrayRgb||=[],e||=this._arrayRgb;let[t,n,r]=this._components;return e[0]=t,e[1]=n,e[2]=r,e}toNumber(){return this._int}toBgrNumber(){let[e,t,n]=this.toUint8RgbArray();return(n<<16)+(t<<8)+e}toLittleEndianNumber(){let e=this._int;return(e>>16)+(e&65280)+((e&255)<<16)}multiply(t){let[n,r,i,a]=e._temp.setValue(t)._components;return this._components[0]*=n,this._components[1]*=r,this._components[2]*=i,this._components[3]*=a,this._refreshInt(),this._value=null,this}premultiply(e,t=!0){return t&&(this._components[0]*=e,this._components[1]*=e,this._components[2]*=e),this._components[3]=e,this._refreshInt(),this._value=null,this}toPremultiplied(e,t=!0){if(e===1)return(255<<24)+this._int;if(e===0)return t?0:this._int;let n=this._int>>16&255,r=this._int>>8&255,i=this._int&255;return t&&(n=n*e+.5|0,r=r*e+.5|0,i=i*e+.5|0),(e*255<<24)+(n<<16)+(r<<8)+i}toHex(){let e=this._int.toString(16);return`#${`000000`.substring(0,6-e.length)+e}`}toHexa(){let e=Math.round(this._components[3]*255).toString(16);return this.toHex()+`00`.substring(0,2-e.length)+e}setAlpha(e){return this._components[3]=this._clamp(e),this._value=null,this}_normalize(t){let n,r,i,a;if((typeof t==`number`||t instanceof Number)&&t>=0&&t<=0xffffff){let e=t;n=(e>>16&255)/255,r=(e>>8&255)/255,i=(e&255)/255,a=1}else if((Array.isArray(t)||t instanceof Float32Array)&&t.length>=3&&t.length<=4)t=this._clamp(t),[n,r,i,a=1]=t;else if((t instanceof Uint8Array||t instanceof Uint8ClampedArray)&&t.length>=3&&t.length<=4)t=this._clamp(t,0,255),[n,r,i,a=255]=t,n/=255,r/=255,i/=255,a/=255;else if(typeof t==`string`||typeof t==`object`){if(typeof t==`string`){let n=e.HEX_PATTERN.exec(t);n&&(t=`#${n[2]}`)}let o=Rn(t);o.isValid()&&({r:n,g:r,b:i,a}=o.rgba,n/=255,r/=255,i/=255)}if(n!==void 0)this._components[0]=n,this._components[1]=r,this._components[2]=i,this._components[3]=a,this._refreshInt();else throw Error(`Unable to convert color ${t}`)}_refreshInt(){this._clamp(this._components);let[e,t,n]=this._components;this._int=(e*255<<16)+(t*255<<8)+(n*255|0)}_clamp(e,t=0,n=1){return typeof e==`number`?Math.min(Math.max(e,t),n):(e.forEach((r,i)=>{e[i]=Math.min(Math.max(r,t),n)}),e)}static isColorLike(t){return t==null?!1:typeof t==`number`||typeof t==`string`||t instanceof Number||t instanceof e||Array.isArray(t)||t instanceof Uint8Array||t instanceof Uint8ClampedArray||t instanceof Float32Array||t.r!==void 0&&t.g!==void 0&&t.b!==void 0||t.r!==void 0&&t.g!==void 0&&t.b!==void 0&&t.a!==void 0||t.h!==void 0&&t.s!==void 0&&t.l!==void 0||t.h!==void 0&&t.s!==void 0&&t.l!==void 0&&t.a!==void 0||t.h!==void 0&&t.s!==void 0&&t.v!==void 0||t.h!==void 0&&t.s!==void 0&&t.v!==void 0&&t.a!==void 0}};Bn.shared=new Bn,Bn._temp=new Bn,Bn.HEX_PATTERN=/^(#|0x)?(([a-f0-9]{3}){1,2}([a-f0-9]{2})?)$/i;var Vn=Bn,Hn={cullArea:null,cullable:!1,cullableChildren:!0},Un=0,Wn=500;function Gn(...e){Un!==Wn&&(Un++,Un===Wn?console.warn(`PixiJS Warning: too many warnings, no more warnings will be reported to the console by PixiJS.`):console.warn(`PixiJS Warning: `,...e))}var Kn={_registeredResources:new Set,register(e){this._registeredResources.add(e)},unregister(e){this._registeredResources.delete(e)},release(){this._registeredResources.forEach(e=>e.clear())},get registeredCount(){return this._registeredResources.size},isRegistered(e){return this._registeredResources.has(e)},reset(){this._registeredResources.clear()}},qn=class{constructor(e,t){this._pool=[],this._count=0,this._index=0,this._classType=e,t&&this.prepopulate(t)}prepopulate(e){for(let t=0;t<e;t++)this._pool[this._index++]=new this._classType;this._count+=e}get(e){let t;return this._index>0?t=this._pool[--this._index]:(t=new this._classType,this._count++),t.init?.(e),t}return(e){e.reset?.(),this._pool[this._index++]=e}get totalSize(){return this._count}get totalFree(){return this._index}get totalUsed(){return this._count-this._index}clear(){if(this._pool.length>0&&this._pool[0].destroy)for(let e=0;e<this._index;e++)this._pool[e].destroy();this._pool.length=0,this._count=0,this._index=0}},Jn=new class{constructor(){this._poolsByClass=new Map}prepopulate(e,t){this.getPool(e).prepopulate(t)}get(e,t){return this.getPool(e).get(t)}return(e){this.getPool(e.constructor).return(e)}getPool(e){return this._poolsByClass.has(e)||this._poolsByClass.set(e,new qn(e)),this._poolsByClass.get(e)}stats(){let e={};return this._poolsByClass.forEach(t=>{let n=e[t._classType.name]?t._classType.name+t._classType.ID:t._classType.name;e[n]={free:t.totalFree,used:t.totalUsed,size:t.totalSize}}),e}clear(){this._poolsByClass.forEach(e=>e.clear()),this._poolsByClass.clear()}};Kn.register(Jn);var Yn={get isCachedAsTexture(){return!!this.renderGroup?.isCachedAsTexture},cacheAsTexture(e){typeof e==`boolean`&&e===!1?this.disableRenderGroup():(this.enableRenderGroup(),this.renderGroup.enableCacheAsTexture(e===!0?{}:e))},updateCacheTexture(){this.renderGroup?.updateCacheTexture()},get cacheAsBitmap(){return this.isCachedAsTexture},set cacheAsBitmap(e){R(`v8.6.0`,`cacheAsBitmap is deprecated, use cacheAsTexture instead.`),this.cacheAsTexture(e)}};function Xn(e,t,n){let r=e.length,i;if(t>=r||n===0)return;n=t+n>r?r-t:n;let a=r-n;for(i=t;i<a;++i)e[i]=e[i+n];e.length=a}var Zn={allowChildren:!0,removeChildren(e=0,t){let n=t??this.children.length,r=n-e,i=[];if(r>0&&r<=n){for(let t=n-1;t>=e;t--){let e=this.children[t];e&&(i.push(e),e.parent=null)}Xn(this.children,e,r);let t=this.renderGroup||this.parentRenderGroup;t&&t.removeChildren(i);for(let e=0;e<i.length;++e){let t=i[e];t.parentRenderLayer?.detach(t),this.emit(`childRemoved`,t,this,e),i[e].emit(`removed`,this)}return i.length>0&&this._didViewChangeTick++,i}if(r===0&&this.children.length===0)return i;throw RangeError(`removeChildren: numeric values are outside the acceptable range.`)},removeChildAt(e){let t=this.getChildAt(e);return this.removeChild(t)},getChildAt(e){if(e<0||e>=this.children.length)throw Error(`getChildAt: Index (${e}) does not exist.`);return this.children[e]},setChildIndex(e,t){if(t<0||t>=this.children.length)throw Error(`The index ${t} supplied is out of bounds ${this.children.length}`);this.getChildIndex(e),this.addChildAt(e,t)},getChildIndex(e){let t=this.children.indexOf(e);if(t===-1)throw Error(`The supplied Container must be a child of the caller`);return t},addChildAt(e,t){this.allowChildren||R(L,`addChildAt: Only Containers will be allowed to add children in v8.0.0`);let{children:n}=this;if(t<0||t>n.length)throw Error(`${e}addChildAt: The index ${t} supplied is out of bounds ${n.length}`);let r=e.parent===this;if(e.parent){let n=e.parent.children.indexOf(e);if(r){if(n===t)return e;e.parent.children.splice(n,1)}else e.removeFromParent()}t===n.length?n.push(e):n.splice(t,0,e);let i=this.renderGroup||this.parentRenderGroup;return this.sortableChildren&&(this.sortDirty=!0),r?(i&&(i.structureDidChange=!0),e):(e.parent=this,e.didChange=!0,e._updateFlags=15,i&&i.addChild(e),this.emit(`childAdded`,e,this,t),e.emit(`added`,this),e)},swapChildren(e,t){if(e===t)return;let n=this.getChildIndex(e),r=this.getChildIndex(t);this.children[n]=t,this.children[r]=e;let i=this.renderGroup||this.parentRenderGroup;i&&(i.structureDidChange=!0),this._didContainerChangeTick++},removeFromParent(){this.parent?.removeChild(this)},reparentChild(...e){return e.length===1?this.reparentChildAt(e[0],this.children.length):(e.forEach(e=>this.reparentChildAt(e,this.children.length)),e[0])},reparentChildAt(e,t){if(e.parent===this)return this.setChildIndex(e,t),e;let n=e.worldTransform.clone();e.removeFromParent(),this.addChildAt(e,t);let r=this.worldTransform.clone();return r.invert(),n.prepend(r),e.setFromMatrix(n),e},replaceChild(e,t){e.updateLocalTransform(),this.addChildAt(t,this.getChildIndex(e)),t.setFromMatrix(e.localTransform),t.updateLocalTransform(),this.removeChild(e)}},Qn={collectRenderables(e,t,n){this.parentRenderLayer&&this.parentRenderLayer!==n||this.globalDisplayStatus<7||!this.includeInBuild||(this.sortableChildren&&this.sortChildren(),this.isSimple?this.collectRenderablesSimple(e,t,n):this.renderGroup?t.renderPipes.renderGroup.addRenderGroup(this.renderGroup,e):this.collectRenderablesWithEffects(e,t,n))},collectRenderablesSimple(e,t,n){let r=this.children,i=r.length;for(let a=0;a<i;a++)r[a].collectRenderables(e,t,n)},collectRenderablesWithEffects(e,t,n){let{renderPipes:r}=t;for(let t=0;t<this.effects.length;t++){let n=this.effects[t];r[n.pipe].push(n,this,e)}this.collectRenderablesSimple(e,t,n);for(let t=this.effects.length-1;t>=0;t--){let n=this.effects[t];r[n.pipe].pop(n,this,e)}}},$n=class{constructor(){this.pipe=`filter`,this.priority=1}destroy(){for(let e=0;e<this.filters.length;e++)this.filters[e].destroy();this.filters=null,this.filterArea=null}},er=new class{constructor(){this._effectClasses=[],this._tests=[],this._initialized=!1}init(){this._initialized||(this._initialized=!0,this._effectClasses.forEach(e=>{this.add({test:e.test,maskClass:e})}))}add(e){this._tests.push(e)}getMaskEffect(e){this._initialized||this.init();for(let t=0;t<this._tests.length;t++){let n=this._tests[t];if(n.test(e))return Jn.get(n.maskClass,e)}return e}returnMaskEffect(e){Jn.return(e)}};at.handleByList(N.MaskEffect,er._effectClasses);var tr={_maskEffect:null,_maskOptions:{inverse:!1,channel:`red`},_filterEffect:null,effects:[],_markStructureAsChanged(){let e=this.renderGroup||this.parentRenderGroup;e&&(e.structureDidChange=!0)},addEffect(e){this.effects.indexOf(e)===-1&&(this.effects.push(e),this.effects.sort((e,t)=>e.priority-t.priority),this._markStructureAsChanged(),this._updateIsSimple())},removeEffect(e){let t=this.effects.indexOf(e);t!==-1&&(this.effects.splice(t,1),this._markStructureAsChanged(),this._updateIsSimple())},set mask(e){let t=this._maskEffect;t?.mask!==e&&(t&&(this.removeEffect(t),er.returnMaskEffect(t),this._maskEffect=null),e!=null&&(this._maskEffect=er.getMaskEffect(e),this.addEffect(this._maskEffect)))},get mask(){return this._maskEffect?.mask},setMask(e){this._maskOptions={...this._maskOptions,...e},e.mask&&(this.mask=e.mask),this._markStructureAsChanged()},set filters(e){!Array.isArray(e)&&e&&(e=[e]);let t=this._filterEffect||=new $n;e=e;let n=e?.length>0,r=n!==t.filters?.length>0;e=Array.isArray(e)?e.slice(0):e,t.filters=Object.freeze(e),r&&(n?this.addEffect(t):(this.removeEffect(t),t.filters=e??null))},get filters(){return this._filterEffect?.filters},set filterArea(e){this._filterEffect||=new $n,this._filterEffect.filterArea=e},get filterArea(){return this._filterEffect?.filterArea}},nr={label:null,get name(){return R(L,`Container.name property has been removed, use Container.label instead`),this.label},set name(e){R(L,`Container.name property has been removed, use Container.label instead`),this.label=e},getChildByName(e,t=!1){return this.getChildByLabel(e,t)},getChildByLabel(e,t=!1){let n=this.children;for(let t=0;t<n.length;t++){let r=n[t];if(r.label===e||e instanceof RegExp&&e.test(r.label))return r}if(t)for(let t=0;t<n.length;t++){let r=n[t].getChildByLabel(e,!0);if(r)return r}return null},getChildrenByLabel(e,t=!1,n=[]){let r=this.children;for(let t=0;t<r.length;t++){let i=r[t];(i.label===e||e instanceof RegExp&&e.test(i.label))&&n.push(i)}if(t)for(let t=0;t<r.length;t++)r[t].getChildrenByLabel(e,!0,n);return n}},rr=Jn.getPool(P),ir=Jn.getPool(an),ar=new P,or={getFastGlobalBounds(e,t){t||=new an,t.clear(),this._getGlobalBoundsRecursive(!!e,t,this.parentRenderLayer),t.isValid||t.set(0,0,0,0);let n=this.renderGroup||this.parentRenderGroup;return t.applyMatrix(n.worldTransform),t},_getGlobalBoundsRecursive(e,t,n){let r=t;if(e&&this.parentRenderLayer&&this.parentRenderLayer!==n||this.localDisplayStatus!==7||!this.measurable)return;let i=!!this.effects.length;if((this.renderGroup||i)&&(r=ir.get().clear()),this.boundsArea)t.addRect(this.boundsArea,this.worldTransform);else{if(this.renderPipeId){let e=this.bounds;r.addFrame(e.minX,e.minY,e.maxX,e.maxY,this.groupTransform)}let t=this.children;for(let i=0;i<t.length;i++)t[i]._getGlobalBoundsRecursive(e,r,n)}if(i){let e=!1,n=this.renderGroup||this.parentRenderGroup;for(let t=0;t<this.effects.length;t++)this.effects[t].addBounds&&(e||(e=!0,r.applyMatrix(n.worldTransform)),this.effects[t].addBounds(r,!0));e&&r.applyMatrix(n.worldTransform.copyTo(ar).invert()),t.addBounds(r),ir.return(r)}else this.renderGroup&&(t.addBounds(r,this.relativeGroupTransform),ir.return(r))}};function sr(e,t,n){n.clear();let r,i;return e.parent?t?r=e.parent.worldTransform:(i=rr.get().identity(),r=lr(e,i)):r=P.IDENTITY,cr(e,n,r,t),i&&rr.return(i),n.isValid||n.set(0,0,0,0),n}function cr(e,t,n,r){if(!e.visible||!e.measurable)return;let i;r?i=e.worldTransform:(e.updateLocalTransform(),i=rr.get(),i.appendFrom(e.localTransform,n));let a=t,o=!!e.effects.length;if(o&&(t=ir.get().clear()),e.boundsArea)t.addRect(e.boundsArea,i);else{let n=e.bounds;n&&!n.isEmpty()&&(t.matrix=i,t.addBounds(n));for(let n=0;n<e.children.length;n++)cr(e.children[n],t,i,r)}if(o){for(let n=0;n<e.effects.length;n++)e.effects[n].addBounds?.(t);a.addBounds(t,P.IDENTITY),ir.return(t)}r||rr.return(i)}function lr(e,t){let n=e.parent;return n&&(lr(n,t),n.updateLocalTransform(),t.append(n.localTransform)),t}function ur(e,t){if(e===0xffffff||!t)return t;if(t===0xffffff||!e)return e;let n=e>>16&255,r=e>>8&255,i=e&255,a=t>>16&255,o=t>>8&255,s=t&255,c=n*a/255|0,l=r*o/255|0,u=i*s/255|0;return(c<<16)+(l<<8)+u}var dr=0xffffff;function fr(e,t){return e===dr?t:t===dr?e:ur(e,t)}function pr(e){return((e&255)<<16)+(e&65280)+(e>>16&255)}var mr={getGlobalAlpha(e){if(e)return this.renderGroup?this.renderGroup.worldAlpha:this.parentRenderGroup?this.parentRenderGroup.worldAlpha*this.alpha:this.alpha;let t=this.alpha,n=this.parent;for(;n;)t*=n.alpha,n=n.parent;return t},getGlobalTransform(e=new P,t){if(t)return e.copyFrom(this.worldTransform);this.updateLocalTransform();let n=lr(this,rr.get().identity());return e.appendFrom(this.localTransform,n),rr.return(n),e},getGlobalTint(e){if(e)return this.renderGroup?pr(this.renderGroup.worldColor):this.parentRenderGroup?pr(fr(this.localColor,this.parentRenderGroup.worldColor)):this.tint;let t=this.localColor,n=this.parent;for(;n;)t=fr(t,n.localColor),n=n.parent;return pr(t)}};function hr(e,t,n){return t.clear(),n||=P.IDENTITY,gr(e,t,n,e,!0),t.isValid||t.set(0,0,0,0),t}function gr(e,t,n,r,i){let a;if(i)a=rr.get(),a=n.copyTo(a);else{if(!e.visible||!e.measurable)return;e.updateLocalTransform();let t=e.localTransform;a=rr.get(),a.appendFrom(t,n)}let o=t,s=!!e.effects.length;if(s&&(t=ir.get().clear()),e.boundsArea)t.addRect(e.boundsArea,a);else{e.renderPipeId&&(t.matrix=a,t.addBounds(e.bounds));let n=e.children;for(let e=0;e<n.length;e++)gr(n[e],t,a,r,!1)}if(s){for(let n=0;n<e.effects.length;n++)e.effects[n].addLocalBounds?.(t,r);o.addBounds(t,P.IDENTITY),ir.return(t)}rr.return(a)}function _r(e,t){let n=e.children;for(let e=0;e<n.length;e++){let r=n[e],i=r.uid,a=(r._didViewChangeTick&65535)<<16|r._didContainerChangeTick&65535,o=t.index;(t.data[o]!==i||t.data[o+1]!==a)&&(t.data[t.index]=i,t.data[t.index+1]=a,t.didChange=!0),t.index=o+2,r.children.length&&_r(r,t)}return t.didChange}var vr=new P,yr={_localBoundsCacheId:-1,_localBoundsCacheData:null,_setWidth(e,t){let n=Math.sign(this.scale.x)||1;t===0?this.scale.x=n:this.scale.x=e/t*n},_setHeight(e,t){let n=Math.sign(this.scale.y)||1;t===0?this.scale.y=n:this.scale.y=e/t*n},getLocalBounds(){this._localBoundsCacheData||={data:[],index:1,didChange:!1,localBounds:new an};let e=this._localBoundsCacheData;return e.index=1,e.didChange=!1,e.data[0]!==this._didViewChangeTick&&(e.didChange=!0,e.data[0]=this._didViewChangeTick),_r(this,e),e.didChange&&hr(this,e.localBounds,vr),e.localBounds},getBounds(e,t){return sr(this,e,t||new an)}},br={_onRender:null,set onRender(e){let t=this.renderGroup||this.parentRenderGroup;e?(this._onRender||t?.addOnRender(this),this._onRender=e):(this._onRender&&t?.removeOnRender(this),this._onRender=null)},get onRender(){return this._onRender}},xr={_zIndex:0,sortDirty:!1,sortableChildren:!1,get zIndex(){return this._zIndex},set zIndex(e){this._zIndex!==e&&(this._zIndex=e,this.depthOfChildModified())},depthOfChildModified(){this.parent&&(this.parent.sortableChildren=!0,this.parent.sortDirty=!0),this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0)},sortChildren(){this.sortDirty&&(this.sortDirty=!1,this.children.sort(Sr))}};function Sr(e,t){return e._zIndex-t._zIndex}var Cr={getGlobalPosition(e=new bt,t=!1){return this.parent?this.parent.toGlobal(this._position,e,t):(e.x=this._position.x,e.y=this._position.y),e},toGlobal(e,t,n=!1){let r=this.getGlobalTransform(rr.get(),n);return t=r.apply(e,t),rr.return(r),t},toLocal(e,t,n,r){t&&(e=t.toGlobal(e,n,r));let i=this.getGlobalTransform(rr.get(),r);return n=i.applyInverse(e,n),rr.return(i),n}},wr=class{constructor(){this.uid=I(`instructionSet`),this.instructions=[],this.instructionSize=0,this.renderables=[],this.gcTick=0}reset(){this.instructionSize=0}destroy(){if(this.renderPipes)for(let e in this.renderPipes)this.renderPipes[e].destroyInstructionSet?.(this);this.instructions.length=0,this.renderables.length=0,this.renderPipes=null,this.gcTick=0}add(e){this.instructions[this.instructionSize++]=e}log(){this.instructions.length=this.instructionSize,console.table(this.instructions,[`type`,`action`])}},Tr=class{constructor(){this._screenSizes=new Map,this._widths=[],this._heights=[],this._logicalWidths=[],this._logicalHeights=[]}get size(){return this._screenSizes.size}set(e,t,n,r=1){let i=this._screenSizes.get(e);return i&&i.pixelWidth===t&&i.pixelHeight===n&&i.resolution===r?!1:(this._screenSizes.set(e,{pixelWidth:t,pixelHeight:n,resolution:r}),this._update(),!0)}remove(e){return this._screenSizes.delete(e)?(this._update(),!0):!1}getFittingWidth(e,t=1){return this._getFittingAxis(e,t,this._widths,this._logicalWidths)}getFittingHeight(e,t=1){return this._getFittingAxis(e,t,this._heights,this._logicalHeights)}hasWidth(e){return this._widths.includes(e)}hasHeight(e){return this._heights.includes(e)}_getFittingAxis(e,t,n,r){let i;for(let t=0;t<n.length;t++)if(n[t]>=e){i=n[t];break}for(let n=0;n<r.length;n++){let a=Math.ceil(r[n]*t-1e-6);if(a>=e)return i===void 0?a:Math.min(i,a)}return i}_update(){let e=[...this._screenSizes.values()];this._widths=Er(e.map(e=>e.pixelWidth)),this._heights=Er(e.map(e=>e.pixelHeight)),this._logicalWidths=Er(e.map(e=>e.pixelWidth/e.resolution)),this._logicalHeights=Er(e.map(e=>e.pixelHeight/e.resolution))}};function Er(e){return e.filter((t,n)=>e.indexOf(t)===n).sort((e,t)=>e-t)}var Dr=0,Or=32767,kr=4294967296,Ar=8589934592,jr=Object.create(null),Mr=0;function Nr(e){let t=jr[e];return t===void 0?jr[e]=Mr++:t}function Pr(e,t,n,r,i,a){return(e<<17)+(t<<2)+(!!r<<1)+ +!!n+ +(a===`nearest`)*kr+Nr(i)*Ar}var Fr=new class extends gt{constructor(e){super(),this._buckets=new Map,this._poolKey=Object.create(null),this._poolStyle=Object.create(null),this._screens=new Tr,this._enableFullScreen=!1,this.textureOptions=e||{}}get textureStyle(){return R(Lt,`TexturePool.textureStyle is no longer used, pooled textures carry their own style. Pass scaleMode in the request instead.`),this._textureStyle||=new Jt(this.textureOptions),this._textureStyle}set textureStyle(e){R(Lt,`TexturePool.textureStyle is no longer used, pooled textures carry their own style. Pass scaleMode in the request instead.`),this._textureStyle=e}get enableFullScreen(){return R(Lt,`TexturePool.enableFullScreen is no longer used, the pool sizes textures to the screens registered with setScreenSize.`),this._enableFullScreen}set enableFullScreen(e){R(Lt,`TexturePool.enableFullScreen is no longer used, the pool sizes textures to the screens registered with setScreenSize.`),this._enableFullScreen=e}createTexture(...e){let t=e[0];typeof t==`number`&&(R(Lt,`TexturePool.createTexture params are now an options object. See params: { width, height, antialias, autoGenerateMipmaps }`),t={width:t,height:e[1],antialias:e[2]??!1,autoGenerateMipmaps:e[3]??!1});let n=t.format??this.textureOptions.format??Xt.defaultOptions.format,r=t.scaleMode??this.textureOptions.scaleMode??Jt.defaultOptions.scaleMode;return new z({source:new Xt({...this.textureOptions,width:t.width,height:t.height,resolution:1,antialias:t.antialias??!1,autoGarbageCollect:!1,autoGenerateMipmaps:t.autoGenerateMipmaps??!1,format:n,scaleMode:r}),label:`texturePool_${Dr++}`})}getOptimalTexture(...e){let t=e[0];typeof t==`number`&&(R(Lt,`TexturePool.getOptimalTexture params are now an options object. See params: { width, height, resolution, antialias, autoGenerateMipmaps }`),t={width:t,height:e[1],resolution:e[2]??1,antialias:e[3]??!1,autoGenerateMipmaps:e[4]??!1});let{width:n,height:r}=this.getOptimalSize(t.width,t.height,t.resolution??1);return this._getTexture(n,r,t)}getAlignedTexture(e,t,n){let r=e.source,i=t/r._resolution;return this._getTexture(Math.ceil(r.pixelWidth*i-1e-6),Math.ceil(r.pixelHeight*i-1e-6),{width:e.frame.width,height:e.frame.height,resolution:t,format:n})}_getTexture(e,t,n){let r=n.width,i=n.height,a=n.resolution??1,o=n.antialias??!1,s=n.autoGenerateMipmaps??!1,c=n.format??this.textureOptions.format??Xt.defaultOptions.format,l=n.scaleMode??this.textureOptions.scaleMode??Jt.defaultOptions.scaleMode;(e>Or||t>Or)&&Gn(`TexturePool: ${e}x${t} is larger than the ${Or}px pool key limit, textures of this size may be pooled together`);let u=Pr(e,t,o,s,c,l),d=this._buckets.get(u);d||(d=[],this._buckets.set(u,d));let f=d.pop();return f||(f=this.createTexture({width:e,height:t,antialias:o,autoGenerateMipmaps:s,format:c,scaleMode:l}),this._poolStyle[f.uid]=f.source.style),f.source._resolution=a,f.source.width=e/a,f.source.height=t/a,f.source.pixelWidth=e,f.source.pixelHeight=t,f.frame.x=0,f.frame.y=0,f.frame.width=r,f.frame.height=i,f.updateUvs(),this._poolKey[f.uid]=u,f}getOptimalSize(e,t,n=1){let r=Math.ceil(e*n-1e-6),i=Math.ceil(t*n-1e-6),a=Ht(r),o=this._screens.getFittingWidth(r,n),s=Ht(i),c=this._screens.getFittingHeight(i,n);return{width:o===void 0?a:Math.min(o,a),height:c===void 0?s:Math.min(c,s)}}getSameSizeTexture(e,t=!1){let n=e.source;return this.getOptimalTexture({width:e.width,height:e.height,resolution:n._resolution,antialias:t})}returnTexture(e,t=!1){let n=e.uid,r=this._poolKey[n];if(r===void 0){Gn(`TexturePool: returnTexture was passed a texture that did not come from this pool, ignoring it`);return}let i=this._poolStyle[n];t&&e.source.style!==i&&(e.source.style=i);let a=this._buckets.get(r);a?a.push(e):this._dropTextures([e],!0)}setScreenSize(e,t,n,r=1){this._screens.set(e,t,n,r)&&this._pruneScreenTextures()}removeScreen(e){this._screens.remove(e)&&this._pruneScreenTextures()}_pruneScreenTextures(){for(let[e,t]of this._buckets){let n=e>>>0,r=n>>>17,i=n>>>2&32767;(!Ut(r)&&!this._screens.hasWidth(r)||!Ut(i)&&!this._screens.hasHeight(i))&&(this._dropTextures(t,!0),this._buckets.delete(e))}}_dropTextures(e,t){t&&e.length>0&&this.emit(`evict`);for(let n=0;n<e.length;n++){let r=e[n];delete this._poolKey[r.uid],delete this._poolStyle[r.uid],t&&r.destroy(!0)}}clear(e){for(let t of this._buckets.values())this._dropTextures(t,e!==!1);this._buckets.clear()}};Kn.register(Fr);var Ir=class{constructor(){this.renderPipeId=`renderGroup`,this.root=null,this.canBundle=!1,this.renderGroupParent=null,this.renderGroupChildren=[],this.worldTransform=new P,this.worldColorAlpha=0xffffffff,this.worldColor=0xffffff,this.worldAlpha=1,this.childrenToUpdate=Object.create(null),this.updateTick=0,this.gcTick=0,this.childrenRenderablesToUpdate={list:[],index:0},this.structureDidChange=!0,this.instructionSet=new wr,this._onRenderContainers=[],this.textureNeedsUpdate=!0,this.isCachedAsTexture=!1,this._matrixDirty=7}init(e){this.root=e,e._onRender&&this.addOnRender(e),e.didChange=!0;let t=e.children;for(let e=0;e<t.length;e++){let n=t[e];n._updateFlags=15,this.addChild(n)}}enableCacheAsTexture(e={}){this.textureOptions=e,this.isCachedAsTexture=!0,this.textureNeedsUpdate=!0}disableCacheAsTexture(){this.isCachedAsTexture=!1,this.texture&&=(Fr.returnTexture(this.texture),null)}updateCacheTexture(){this.textureNeedsUpdate=!0;let e=this._parentCacheAsTextureRenderGroup;e&&!e.textureNeedsUpdate&&e.updateCacheTexture()}reset(){this.renderGroupChildren.length=0;for(let e in this.childrenToUpdate){let t=this.childrenToUpdate[e];t.list.fill(null),t.index=0}this.childrenRenderablesToUpdate.index=0,this.childrenRenderablesToUpdate.list.fill(null),this.root=null,this.updateTick=0,this.structureDidChange=!0,this._onRenderContainers.length=0,this.renderGroupParent=null,this.disableCacheAsTexture()}get localTransform(){return this.root.localTransform}addRenderGroupChild(e){e.renderGroupParent&&e.renderGroupParent._removeRenderGroupChild(e),e.renderGroupParent=this,this.renderGroupChildren.push(e)}_removeRenderGroupChild(e){let t=this.renderGroupChildren.indexOf(e);t>-1&&this.renderGroupChildren.splice(t,1),e.renderGroupParent=null}addChild(e){if(this.structureDidChange=!0,e.parentRenderGroup=this,e.updateTick=-1,e.relativeRenderGroupDepth=e.parent===this.root?1:e.parent.relativeRenderGroupDepth+1,e.didChange=!0,this.onChildUpdate(e),e.renderGroup){this.addRenderGroupChild(e.renderGroup);return}e._onRender&&this.addOnRender(e);let t=e.children;for(let e=0;e<t.length;e++)this.addChild(t[e])}removeChild(e){if(this.structureDidChange=!0,e._onRender&&(e.renderGroup||this.removeOnRender(e)),e.parentRenderGroup=null,e.renderGroup){this._removeRenderGroupChild(e.renderGroup);return}let t=e.children;for(let e=0;e<t.length;e++)this.removeChild(t[e])}removeChildren(e){for(let t=0;t<e.length;t++)this.removeChild(e[t])}onChildUpdate(e){let t=this.childrenToUpdate[e.relativeRenderGroupDepth];t||=this.childrenToUpdate[e.relativeRenderGroupDepth]={index:0,list:[]},t.list[t.index++]=e}updateRenderable(e){e.globalDisplayStatus<7||(this.instructionSet.renderPipes[e.renderPipeId].updateRenderable(e),e.didViewUpdate=!1)}onChildViewUpdate(e){this.childrenRenderablesToUpdate.list[this.childrenRenderablesToUpdate.index++]=e}get isRenderable(){return this.root.localDisplayStatus===7&&this.worldAlpha>0}addOnRender(e){this._onRenderContainers.indexOf(e)===-1&&this._onRenderContainers.push(e)}removeOnRender(e){let t=this._onRenderContainers.indexOf(e);t!==-1&&this._onRenderContainers.splice(t,1)}runOnRender(e){for(let t=0;t<this._onRenderContainers.length;t++)this._onRenderContainers[t]._onRender(e)}destroy(){this.disableCacheAsTexture(),this.renderGroupParent=null,this.root=null,this.childrenRenderablesToUpdate=null,this.childrenToUpdate=null,this.renderGroupChildren=null,this._onRenderContainers=null,this.instructionSet?.destroy(),this.instructionSet=null}getChildren(e=[]){let t=this.root.children;for(let n=0;n<t.length;n++)this._getChildren(t[n],e);return e}_getChildren(e,t=[]){if(t.push(e),e.renderGroup)return t;let n=e.children;for(let e=0;e<n.length;e++)this._getChildren(n[e],t);return t}invalidateMatrices(){this._matrixDirty=7}get inverseWorldTransform(){return this._matrixDirty&1?(this._matrixDirty&=-2,this._inverseWorldTransform||=new P,this._inverseWorldTransform.copyFrom(this.worldTransform).invert()):this._inverseWorldTransform}get textureOffsetInverseTransform(){return this._matrixDirty&2?(this._matrixDirty&=-3,this._textureOffsetInverseTransform||=new P,this._textureOffsetInverseTransform.copyFrom(this.inverseWorldTransform).translate(-this._textureBounds.x,-this._textureBounds.y)):this._textureOffsetInverseTransform}get inverseParentTextureTransform(){if(!(this._matrixDirty&4))return this._inverseParentTextureTransform;this._matrixDirty&=-5;let e=this._parentCacheAsTextureRenderGroup;return e?(this._inverseParentTextureTransform||=new P,this._inverseParentTextureTransform.copyFrom(this.worldTransform).prepend(e.inverseWorldTransform).translate(-e._textureBounds.x,-e._textureBounds.y)):this.worldTransform}get cacheToLocalTransform(){return this.isCachedAsTexture?this.textureOffsetInverseTransform:this._parentCacheAsTextureRenderGroup?this._parentCacheAsTextureRenderGroup.textureOffsetInverseTransform:null}};function Lr(e,t,n={}){for(let r in t)!n[r]&&t[r]!==void 0&&(e[r]=t[r])}var Rr=new ht(null),zr=new ht(null),Br=new ht(null,1,1),Vr=new ht(null),Hr=class e extends gt{constructor(e={}){super(),this.uid=I(`renderable`),this._updateFlags=15,this.renderGroup=null,this.parentRenderGroup=null,this.parentRenderGroupIndex=0,this.didChange=!1,this.didViewUpdate=!1,this.relativeRenderGroupDepth=0,this.children=[],this.parent=null,this.includeInBuild=!0,this.measurable=!0,this.isSimple=!0,this.parentRenderLayer=null,this.updateTick=-1,this.localTransform=new P,this.relativeGroupTransform=new P,this.groupTransform=this.relativeGroupTransform,this.destroyed=!1,this._position=new ht(this,0,0),this._scale=Br,this._pivot=zr,this._origin=Vr,this._skew=Rr,this._cx=1,this._sx=0,this._cy=0,this._sy=1,this._rotation=0,this.localColor=0xffffff,this.localAlpha=1,this.groupAlpha=1,this.groupColor=0xffffff,this.groupColorAlpha=0xffffffff,this.localBlendMode=`inherit`,this.groupBlendMode=`normal`,this.localDisplayStatus=7,this.globalDisplayStatus=7,this._didContainerChangeTick=0,this._didViewChangeTick=0,this._didLocalTransformChangeId=-1,this.effects=[],Lr(this,e,{children:!0,parent:!0,effects:!0}),e.children?.forEach(e=>this.addChild(e)),e.parent?.addChild(this)}static mixin(t){R(`8.8.0`,`Container.mixin is deprecated, please use extensions.mixin instead.`),at.mixin(e,t)}set _didChangeId(e){this._didViewChangeTick=e>>12&4095,this._didContainerChangeTick=e&4095}get _didChangeId(){return this._didContainerChangeTick&4095|(this._didViewChangeTick&4095)<<12}addChild(...e){if(this.allowChildren||R(L,`addChild: Only Containers will be allowed to add children in v8.0.0`),e.length>1){for(let t=0;t<e.length;t++)this.addChild(e[t]);return e[0]}let t=e[0],n=this.renderGroup||this.parentRenderGroup;return t.parent===this?(this.children.splice(this.children.indexOf(t),1),this.children.push(t),n&&(n.structureDidChange=!0),t):(t.parent&&t.parent.removeChild(t),this.children.push(t),this.sortableChildren&&(this.sortDirty=!0),t.parent=this,t.didChange=!0,t._updateFlags=15,n&&n.addChild(t),this.emit(`childAdded`,t,this,this.children.length-1),t.emit(`added`,this),this._didViewChangeTick++,t._zIndex!==0&&t.depthOfChildModified(),t)}removeChild(...e){if(e.length>1){for(let t=0;t<e.length;t++)this.removeChild(e[t]);return e[0]}let t=e[0],n=this.children.indexOf(t);return n>-1&&(this._didViewChangeTick++,this.children.splice(n,1),this.renderGroup?this.renderGroup.removeChild(t):this.parentRenderGroup&&this.parentRenderGroup.removeChild(t),t.parentRenderLayer&&t.parentRenderLayer.detach(t),t.parent=null,this.emit(`childRemoved`,t,this,n),t.emit(`removed`,this)),t}_onUpdate(e){e&&e===this._skew&&this._updateSkew(),this._didContainerChangeTick++,this.didChange||(this.didChange=!0,this.parentRenderGroup&&this.parentRenderGroup.onChildUpdate(this))}set isRenderGroup(e){!!this.renderGroup!==e&&(e?this.enableRenderGroup():this.disableRenderGroup())}get isRenderGroup(){return!!this.renderGroup}enableRenderGroup(){if(this.renderGroup)return;let e=this.parentRenderGroup;e?.removeChild(this),this.renderGroup=Jn.get(Ir,this),this.groupTransform=P.IDENTITY,e?.addChild(this),this._updateIsSimple()}disableRenderGroup(){if(!this.renderGroup)return;let e=this.parentRenderGroup;e?.removeChild(this),Jn.return(this.renderGroup),this.renderGroup=null,this.groupTransform=this.relativeGroupTransform,e?.addChild(this),this._updateIsSimple()}_updateIsSimple(){this.isSimple=!this.renderGroup&&this.effects.length===0}get worldTransform(){return this._worldTransform||=new P,this.renderGroup?this._worldTransform.copyFrom(this.renderGroup.worldTransform):this.parentRenderGroup&&this._worldTransform.appendFrom(this.relativeGroupTransform,this.parentRenderGroup.worldTransform),this._worldTransform}get x(){return this._position.x}set x(e){this._position.x=e}get y(){return this._position.y}set y(e){this._position.y=e}get position(){return this._position}set position(e){this._position.copyFrom(e)}get rotation(){return this._rotation}set rotation(e){this._rotation!==e&&(this._rotation=e,this._onUpdate(this._skew))}get angle(){return this.rotation*vt}set angle(e){this.rotation=e*yt}get pivot(){return this._pivot===zr&&(this._pivot=new ht(this,0,0)),this._pivot}set pivot(e){this._pivot===zr&&(this._pivot=new ht(this,0,0),this._origin!==Vr&&Gn(`Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.`)),typeof e==`number`?this._pivot.set(e):this._pivot.copyFrom(e)}get skew(){return this._skew===Rr&&(this._skew=new ht(this,0,0)),this._skew}set skew(e){this._skew===Rr&&(this._skew=new ht(this,0,0)),this._skew.copyFrom(e)}get scale(){return this._scale===Br&&(this._scale=new ht(this,1,1)),this._scale}set scale(e){this._scale===Br&&(this._scale=new ht(this,0,0)),typeof e==`string`&&(e=parseFloat(e)),typeof e==`number`?this._scale.set(e):this._scale.copyFrom(e)}get origin(){return this._origin===Vr&&(this._origin=new ht(this,0,0)),this._origin}set origin(e){this._origin===Vr&&(this._origin=new ht(this,0,0),this._pivot!==zr&&Gn(`Setting both a pivot and origin on a Container is not recommended. This can lead to unexpected behavior if not handled carefully.`)),typeof e==`number`?this._origin.set(e):this._origin.copyFrom(e)}get width(){return Math.abs(this.scale.x*this.getLocalBounds().width)}set width(e){let t=this.getLocalBounds().width;this._setWidth(e,t)}get height(){return Math.abs(this.scale.y*this.getLocalBounds().height)}set height(e){let t=this.getLocalBounds().height;this._setHeight(e,t)}getSize(e){e||={};let t=this.getLocalBounds();return e.width=Math.abs(this.scale.x*t.width),e.height=Math.abs(this.scale.y*t.height),e}setSize(e,t){let n=this.getLocalBounds();typeof e==`object`?(t=e.height??e.width,e=e.width):t??=e,e!==void 0&&this._setWidth(e,n.width),t!==void 0&&this._setHeight(t,n.height)}_updateSkew(){let e=this._rotation,t=this._skew;this._cx=Math.cos(e+t._y),this._sx=Math.sin(e+t._y),this._cy=-Math.sin(e-t._x),this._sy=Math.cos(e-t._x)}updateTransform(e){return this.position.set(typeof e.x==`number`?e.x:this.position.x,typeof e.y==`number`?e.y:this.position.y),this.scale.set(typeof e.scaleX==`number`?e.scaleX:this.scale.x,typeof e.scaleY==`number`?e.scaleY:this.scale.y),this.rotation=typeof e.rotation==`number`?e.rotation:this.rotation,this.skew.set(typeof e.skewX==`number`?e.skewX:this.skew.x,typeof e.skewY==`number`?e.skewY:this.skew.y),this.pivot.set(typeof e.pivotX==`number`?e.pivotX:this.pivot.x,typeof e.pivotY==`number`?e.pivotY:this.pivot.y),this.origin.set(typeof e.originX==`number`?e.originX:this.origin.x,typeof e.originY==`number`?e.originY:this.origin.y),this}setFromMatrix(e){e.decompose(this)}updateLocalTransform(){let e=this._didContainerChangeTick;if(this._didLocalTransformChangeId===e)return;this._didLocalTransformChangeId=e;let t=this.localTransform,n=this._scale,r=this._pivot,i=this._origin,a=this._position,o=n._x,s=n._y,c=r._x,l=r._y,u=-i._x,d=-i._y;t.a=this._cx*o,t.b=this._sx*o,t.c=this._cy*s,t.d=this._sy*s,t.tx=a._x-(c*t.a+l*t.c)+(u*t.a+d*t.c)-u,t.ty=a._y-(c*t.b+l*t.d)+(u*t.b+d*t.d)-d}set alpha(e){e!==this.localAlpha&&(this.localAlpha=e,this._updateFlags|=1,this._onUpdate())}get alpha(){return this.localAlpha}set tint(e){let t=typeof e==`number`?pr(e):Vn.shared.setValue(e??0xffffff).toBgrNumber();t!==this.localColor&&(this.localColor=t,this._updateFlags|=1,this._onUpdate())}get tint(){return pr(this.localColor)}set blendMode(e){this.localBlendMode!==e&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=2,this.localBlendMode=e,this._onUpdate())}get blendMode(){return this.localBlendMode}get visible(){return!!(this.localDisplayStatus&2)}set visible(e){let t=e?2:0;(this.localDisplayStatus&2)!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=4,this.localDisplayStatus^=2,this._onUpdate(),this.emit(`visibleChanged`,e))}get culled(){return!(this.localDisplayStatus&4)}set culled(e){let t=e?0:4;(this.localDisplayStatus&4)!==t&&(this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._updateFlags|=4,this.localDisplayStatus^=4,this._onUpdate())}get renderable(){return!!(this.localDisplayStatus&1)}set renderable(e){let t=+!!e;(this.localDisplayStatus&1)!==t&&(this._updateFlags|=4,this.localDisplayStatus^=1,this.parentRenderGroup&&(this.parentRenderGroup.structureDidChange=!0),this._onUpdate())}get isRenderable(){return this.localDisplayStatus===7&&this.groupAlpha>0}destroy(e=!1){if(this.destroyed)return;this.destroyed=!0;let t;if(this.children.length&&(t=this.removeChildren(0,this.children.length)),this.removeFromParent(),this.parent=null,this._maskEffect=null,this._filterEffect=null,this.effects=null,this._position=null,this._scale=null,this._pivot=null,this._origin=null,this._skew=null,this.emit(`destroyed`,this),this.removeAllListeners(),(typeof e==`boolean`?e:e?.children)&&t)for(let n=0;n<t.length;++n)t[n].destroy(e);this.renderGroup?.destroy(),this.renderGroup=null}};at.mixin(Hr,Zn,or,Cr,br,yr,tr,nr,xr,Hn,Yn,mr,Qn);var Ur=class extends Hr{constructor(e){super(e),this.canBundle=!0,this.allowChildren=!1,this._roundPixels=0,this._lastUsed=-1,this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this._bounds=new an(0,1,0,0),this._boundsDirty=!0,this.autoGarbageCollect=e.autoGarbageCollect??!0}get bounds(){return this._boundsDirty&&=(this.updateBounds(),!1),this._bounds}get roundPixels(){return!!this._roundPixels}set roundPixels(e){this._roundPixels=+!!e}containsPoint(e){let t=this.bounds,{x:n,y:r}=e;return n>=t.minX&&n<=t.maxX&&r>=t.minY&&r<=t.maxY}onViewUpdate(){if(this._didViewChangeTick++,this._boundsDirty=!0,this.didViewUpdate)return;this.didViewUpdate=!0;let e=this.renderGroup||this.parentRenderGroup;e&&e.onChildViewUpdate(this)}unload(){this.emit(`unload`,this);for(let e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null),this.onViewUpdate()}destroy(e){this.unload(),super.destroy(e),this._bounds=null}collectRenderablesSimple(e,t,n){let{renderPipes:r}=t;r.blendMode.pushBlendMode(this,this.groupBlendMode,e);let i=r[this.renderPipeId];i?.addRenderable&&i.addRenderable(this,e),this.didViewUpdate=!1;let a=this.children,o=a.length;for(let r=0;r<o;r++)a[r].collectRenderables(e,t,n);r.blendMode.popBlendMode(e)}},Wr=class e extends Ur{constructor(e=z.EMPTY){e instanceof z&&(e={texture:e});let{texture:t=z.EMPTY,anchor:n,roundPixels:r,width:i,height:a,...o}=e;super({label:`Sprite`,...o}),this.renderPipeId=`sprite`,this.batched=!0,this._visualBounds={minX:0,maxX:1,minY:0,maxY:0},this._anchor=new ht({_onUpdate:()=>{this.onViewUpdate()}}),n?this.anchor=n:t.defaultAnchor&&(this.anchor=t.defaultAnchor),this.texture=t,this.allowChildren=!1,this.roundPixels=r??!1,i!==void 0&&(this.width=i),a!==void 0&&(this.height=a)}static from(t,n=!1){return t instanceof z?new e(t):new e(z.from(t,n))}set texture(e){e||=z.EMPTY;let t=this._texture;t!==e&&(t&&t.dynamic&&t.off(`update`,this.onViewUpdate,this),e.dynamic&&e.on(`update`,this.onViewUpdate,this),this._texture=e,this._width&&this._setWidth(this._width,this._texture.orig.width),this._height&&this._setHeight(this._height,this._texture.orig.height),this.onViewUpdate())}get texture(){return this._texture}get visualBounds(){return nn(this._visualBounds,this._anchor,this._texture),this._visualBounds}get sourceBounds(){return R(`8.6.1`,`Sprite.sourceBounds is deprecated, use visualBounds instead.`),this.visualBounds}updateBounds(){let e=this._anchor,t=this._texture,n=this._bounds,{width:r,height:i}=t.orig;n.minX=-e._x*r,n.maxX=n.minX+r,n.minY=-e._y*i,n.maxY=n.minY+i}destroy(e=!1){if(super.destroy(e),typeof e==`boolean`?e:e?.texture){let t=typeof e==`boolean`?e:e?.textureSource;this._texture.destroy(t)}this._texture=null,this._visualBounds=null,this._bounds=null,this._anchor=null}get anchor(){return this._anchor}set anchor(e){typeof e==`number`?this._anchor.set(e):this._anchor.copyFrom(e)}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(e){this._setWidth(e,this._texture.orig.width),this._width=e}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(e){this._setHeight(e,this._texture.orig.height),this._height=e}getSize(e){return e||={},e.width=Math.abs(this.scale.x)*this._texture.orig.width,e.height=Math.abs(this.scale.y)*this._texture.orig.height,e}setSize(e,t){typeof e==`object`?(t=e.height??e.width,e=e.width):t??=e,e!==void 0&&this._setWidth(e,this._texture.orig.width),t!==void 0&&this._setHeight(t,this._texture.orig.height)}},Gr=new an;function Kr(e,t,n){let r=Gr;e.measurable=!0,sr(e,n,r),t.addBoundsMask(r),e.measurable=!1}function qr(e,t,n){let r=ir.get();e.measurable=!0;let i=rr.get().identity();hr(e,r,Jr(e,n,i)),e.measurable=!1,t.addBoundsMask(r),rr.return(i),ir.return(r)}function Jr(e,t,n){return e?(e!==t&&(Jr(e.parent,t,n),e.updateLocalTransform(),n.append(e.localTransform)),n):(Gn(`Mask bounds, renderable is not inside the root container`),n)}var Yr=class{constructor(e){this.priority=0,this.inverse=!1,this.channel=`red`,this.pipe=`alphaMask`,e?.mask&&this.init(e.mask)}init(e){this.mask=e,this.renderMaskToTexture=!(e instanceof Wr),this.mask.renderable=this.renderMaskToTexture,this.mask.includeInBuild=!this.renderMaskToTexture,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask=null)}addBounds(e,t){this.inverse||Kr(this.mask,e,t)}addLocalBounds(e,t){qr(this.mask,e,t)}containsPoint(e,t){return t(this.mask,e)}destroy(){this.reset()}static test(e){return e instanceof Wr}};Yr.extension=N.MaskEffect;var Xr=class{constructor(e){this.priority=0,this.pipe=`colorMask`,e?.mask&&this.init(e.mask)}init(e){this.mask=e}destroy(){}static test(e){return typeof e==`number`}};Xr.extension=N.MaskEffect;var Zr=class{constructor(e){this.priority=0,this.pipe=`stencilMask`,e?.mask&&this.init(e.mask)}init(e){this.mask=e,this.mask.includeInBuild=!1,this.mask.measurable=!1}reset(){this.mask!==null&&(this.mask.measurable=!0,this.mask.includeInBuild=!0,this.mask=null)}addBounds(e,t){Kr(this.mask,e,t)}addLocalBounds(e,t){qr(this.mask,e,t)}containsPoint(e,t){return t(this.mask,e)}destroy(){this.reset()}static test(e){return e instanceof Hr}};Zr.extension=N.MaskEffect;var Qr={createCanvas:(e,t)=>{let n=document.createElement(`canvas`);return n.width=e,n.height=t,n},createImage:()=>new Image,getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(e,t)=>fetch(e,t),parseXML:e=>new DOMParser().parseFromString(e,`text/xml`)},$r={get(){return Qr},set(e){Qr=e}},ei=class extends Xt{constructor(e){e.resource||=$r.get().createCanvas(),e.width||(e.width=e.resource.width,e.autoDensity||(e.width/=e.resolution)),e.height||(e.height=e.resource.height,e.autoDensity||(e.height/=e.resolution)),super(e),this.uploadMethodId=`image`,this.autoDensity=e.autoDensity,this.resizeCanvas(),this.transparent=!!e.transparent}resizeCanvas(){this.autoDensity&&`style`in this.resource&&(this.resource.style.width=`${this.width}px`,this.resource.style.height=`${this.height}px`),(this.resource.width!==this.pixelWidth||this.resource.height!==this.pixelHeight)&&(this.resource.width=this.pixelWidth,this.resource.height=this.pixelHeight)}resize(e=this.width,t=this.height,n=this._resolution){let r=super.resize(e,t,n);return r&&this.resizeCanvas(),r}static test(e){return globalThis.HTMLCanvasElement&&e instanceof HTMLCanvasElement||globalThis.OffscreenCanvas&&e instanceof OffscreenCanvas}get context2D(){return this._context2D||=this.resource.getContext(`2d`)}};ei.extension=N.TextureSource;var ti=class extends Xt{constructor(e){super(e),this.uploadMethodId=`image`,this.autoGarbageCollect=!0}static test(e){return globalThis.HTMLImageElement&&e instanceof HTMLImageElement||typeof ImageBitmap<`u`&&e instanceof ImageBitmap||globalThis.VideoFrame&&e instanceof VideoFrame}};ti.extension=N.TextureSource;var ni=(e=>(e[e.INTERACTION=50]=`INTERACTION`,e[e.HIGH=25]=`HIGH`,e[e.NORMAL=0]=`NORMAL`,e[e.LOW=-25]=`LOW`,e[e.UTILITY=-50]=`UTILITY`,e))(ni||{}),ri=class{constructor(e,t=null,n=0,r=!1){this.next=null,this.previous=null,this._destroyed=!1,this._fn=e,this._context=t,this.priority=n,this._once=r}match(e,t=null){return this._fn===e&&this._context===t}emit(e){this._fn&&(this._context?this._fn.call(this._context,e):this._fn(e));let t=this.next;return this._once&&this.destroy(!0),this._destroyed&&(this.next=null),t}connect(e){this.previous=e,e.next&&(e.next.previous=this),this.next=e.next,e.next=this}destroy(e=!1){this._destroyed=!0,this._fn=null,this._context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);let t=this.next;return this.next=e?null:t,this.previous=null,t}},ii=class e{constructor(){this.autoStart=!1,this.deltaTime=1,this.lastTime=-1,this.speed=1,this.started=!1,this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this._protected=!1,this._lastFrame=-1,this._head=new ri(null,null,1/0),this.deltaMS=1/e.targetFPMS,this.elapsedMS=1/e.targetFPMS,this._tick=e=>{this._requestId=null,this.started&&(this.update(e),this.started&&this._requestId===null&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){this._requestId===null&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){this._requestId!==null&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(e,t,n=ni.NORMAL){return this._addListener(new ri(e,t,n))}addOnce(e,t,n=ni.NORMAL){return this._addListener(new ri(e,t,n,!0))}_addListener(e){let t=this._head.next,n=this._head;if(!t)e.connect(n);else{for(;t;){if(e.priority>t.priority){e.connect(n);break}n=t,t=t.next}e.previous||e.connect(n)}return this._startIfPossible(),this}remove(e,t){let n=this._head.next;for(;n;)n=n.match(e,t)?n.destroy():n.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let e=0,t=this._head;for(;t=t.next;)e++;return e}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let e=this._head.next;for(;e;)e=e.destroy(!0);this._head.destroy(),this._head=null}}update(t=performance.now()){let n;if(t>this.lastTime){if(n=this.elapsedMS=t-this.lastTime,n>this._maxElapsedMS&&(n=this._maxElapsedMS),n*=this.speed,this._minElapsedMS){let e=t-this._lastFrame|0;if(e<this._minElapsedMS)return;this._lastFrame=t-e%this._minElapsedMS}this.deltaMS=n,this.deltaTime=this.deltaMS*e.targetFPMS;let r=this._head,i=r.next;for(;i;)i=i.emit(this);r.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=t}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(t){let n=Math.min(Math.max(0,t)/1e3,e.targetFPMS);this._maxElapsedMS=1/n,this._minElapsedMS&&t>this.maxFPS&&(this.maxFPS=t)}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(e){e===0?this._minElapsedMS=0:(e<this.minFPS&&(this.minFPS=e),this._minElapsedMS=1/(e/1e3))}static get shared(){if(!e._shared){let t=e._shared=new e;t.autoStart=!0,t._protected=!0}return e._shared}static get system(){if(!e._system){let t=e._system=new e;t.autoStart=!0,t._protected=!0}return e._system}};ii.targetFPMS=.06;var ai=ii,oi;async function si(){return oi??=(async()=>{let e=$r.get().createCanvas(1,1).getContext(`webgl`);if(!e)return`premultiply-alpha-on-upload`;let t=await new Promise(e=>{let t=document.createElement(`video`);t.onloadeddata=()=>e(t),t.onerror=()=>e(null),t.autoplay=!1,t.crossOrigin=`anonymous`,t.preload=`auto`,t.src=`data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAHTEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHGTbuMU6uEElTDZ1OsggEXTbuMU6uEHFO7a1OsggG97AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmoCrXsYMPQkBNgIRMYXZmV0GETGF2ZkSJiEBEAAAAAAAAFlSua8yuAQAAAAAAAEPXgQFzxYgAAAAAAAAAAZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDglLCBArqBApqBAlPAgQFVsIRVuYEBElTDZ9Vzc9JjwItjxYgAAAAAAAAAAWfInEWjh0VOQ09ERVJEh49MYXZjIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dcfngQCgwqGggQAAAIJJg0IAABAAFgA4JBwYSgAAICAAEb///4r+AAB1oZ2mm+6BAaWWgkmDQgAAEAAWADgkHBhKAAAgIABIQBxTu2uRu4+zgQC3iveBAfGCAXHwgQM=`,t.load()});if(!t)return`premultiply-alpha-on-upload`;let n=e.createTexture();e.bindTexture(e.TEXTURE_2D,n);let r=e.createFramebuffer();e.bindFramebuffer(e.FRAMEBUFFER,r),e.framebufferTexture2D(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0,e.TEXTURE_2D,n,0),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.NONE),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t);let i=new Uint8Array(4);return e.readPixels(0,0,1,1,e.RGBA,e.UNSIGNED_BYTE,i),e.deleteFramebuffer(r),e.deleteTexture(n),e.getExtension(`WEBGL_lose_context`)?.loseContext(),i[0]<=i[3]?`premultiplied-alpha`:`premultiply-alpha-on-upload`})(),oi}var ci=class e extends Xt{constructor(t){super(t),this.isReady=!1,this.uploadMethodId=`video`,t={...e.defaultOptions,...t},this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=t.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=t.autoPlay!==!1,this.alphaMode=t.alphaMode??`premultiply-alpha-on-upload`,this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onCanPlayThrough=this._onCanPlayThrough.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),this._onLoadedMetadata=this._onLoadedMetadata.bind(this),t.autoLoad!==!1&&this.load()}updateFrame(){if(!this.destroyed){if(this._updateFPS){let e=ai.shared.elapsedMS*this.resource.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-e)}(!this._updateFPS||this._msToNextUpdate<=0)&&(this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0),this.isValid&&this.update()}}_videoFrameRequestCallback(){this.updateFrame(),this._videoFrameRequestCallbackHandle=this.destroyed?null:this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback)}get isValid(){return!!this.resource.videoWidth&&!!this.resource.videoHeight}async load(){if(this._load)return this._load;let e=this.resource,t=this.options;return(e.readyState===e.HAVE_ENOUGH_DATA||e.readyState===e.HAVE_FUTURE_DATA)&&e.width&&e.height&&(e.complete=!0),e.addEventListener(`play`,this._onPlayStart),e.addEventListener(`pause`,this._onPlayStop),e.addEventListener(`seeked`,this._onSeeked),this._isSourceReady()?this._mediaReady():(t.preload||e.addEventListener(`canplay`,this._onCanPlay),e.addEventListener(`canplaythrough`,this._onCanPlayThrough),e.addEventListener(`error`,this._onError,!0)),this.isValid||e.addEventListener(`loadedmetadata`,this._onLoadedMetadata),this.alphaMode=await si(),this._load=new Promise((n,r)=>{this.isValid?n(this):(this._resolve=n,this._reject=r,t.preloadTimeoutMs!==void 0&&(this._preloadTimeout=setTimeout(()=>{this._onError(new ErrorEvent(`Preload exceeded timeout of ${t.preloadTimeoutMs}ms`))})),e.load())}),this._load}_onError(e){this.resource.removeEventListener(`error`,this._onError,!0),this.emit(`error`,e),this._reject&&(this._reject(e),this._reject=null,this._resolve=null)}_isSourcePlaying(){let e=this.resource;return!e.paused&&!e.ended}_isSourceReady(){return this.resource.readyState>2}_onPlayStart(){this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0)}_onLoadedMetadata(){this.isValid&&this._mediaReady()}_onCanPlay(){this.resource.removeEventListener(`canplay`,this._onCanPlay),this._mediaReady()}_onCanPlayThrough(){this.resource.removeEventListener(`canplaythrough`,this._onCanPlayThrough),this._preloadTimeout&&=(clearTimeout(this._preloadTimeout),void 0),this._mediaReady()}_mediaReady(){let e=this.resource;this.isValid&&(this.isReady=!0,this.resize(e.videoWidth,e.videoHeight)),this._msToNextUpdate=0,this.updateFrame(),this._msToNextUpdate=0,this._resolve&&this.isValid&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&this.resource.play()}destroy(){this._configureAutoUpdate();let e=this.resource;e&&(e.removeEventListener(`play`,this._onPlayStart),e.removeEventListener(`pause`,this._onPlayStop),e.removeEventListener(`seeked`,this._onSeeked),e.removeEventListener(`canplay`,this._onCanPlay),e.removeEventListener(`canplaythrough`,this._onCanPlayThrough),e.removeEventListener(`loadedmetadata`,this._onLoadedMetadata),e.removeEventListener(`error`,this._onError,!0),e.pause(),e.src=``,e.load()),super.destroy()}get autoUpdate(){return this._autoUpdate}set autoUpdate(e){e!==this._autoUpdate&&(this._autoUpdate=e,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(e){e!==this._updateFPS&&(this._updateFPS=e,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.resource.requestVideoFrameCallback?(this._isConnectedToTicker&&(ai.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0),this._videoFrameRequestCallbackHandle===null&&(this._videoFrameRequestCallbackHandle=this.resource.requestVideoFrameCallback(this._videoFrameRequestCallback))):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker||(ai.shared.add(this.updateFrame,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.resource.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(ai.shared.remove(this.updateFrame,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(e){return globalThis.HTMLVideoElement&&e instanceof HTMLVideoElement}};ci.extension=N.TextureSource,ci.defaultOptions={...Xt.defaultOptions,autoLoad:!0,autoPlay:!0,updateFPS:0,crossorigin:!0,loop:!1,muted:!0,playsinline:!0,preload:!1},ci.MIME_TYPES={ogv:`video/ogg`,mov:`video/quicktime`,m4v:`video/mp4`};var li=ci,ui=(e,t,n=!1)=>(Array.isArray(e)||(e=[e]),t?e.map(e=>typeof e==`string`||n?t(e):e):e),di=new class{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(e){return this._cache.has(e)}get(e){let t=this._cache.get(e);return t||Gn(`[Assets] Asset id ${e} was not found in the Cache`),t}set(e,t){let n=ui(e),r;for(let e=0;e<this.parsers.length;e++){let i=this.parsers[e];if(i.test(t)){r=i.getCacheableAssets(n,t);break}}let i=new Map(Object.entries(r||{}));r||n.forEach(e=>{i.set(e,t)});let a=[...i.keys()],o={cacheKeys:a,keys:n};n.forEach(e=>{this._cacheMap.set(e,o)}),a.forEach(e=>{let n=r?r[e]:t;this._cache.has(e)&&this._cache.get(e)!==n&&Gn(`[Cache] already has key:`,e),this._cache.set(e,i.get(e))})}remove(e){if(!this._cacheMap.has(e)){Gn(`[Assets] Asset id ${e} was not found in the Cache`);return}let t=this._cacheMap.get(e);t.cacheKeys.forEach(e=>{this._cache.delete(e)}),t.keys.forEach(e=>{this._cacheMap.delete(e)})}get parsers(){return this._parsers}},fi=[];at.handleByList(N.TextureSource,fi);function pi(e={}){let t=e&&e.resource,n=t?e.resource:e,r=t?e:{resource:e};for(let e=0;e<fi.length;e++){let t=fi[e];if(t.test(n))return new t(r)}throw Error(`Could not find a source type for resource: ${r.resource}`)}function mi(e={},t=!1){let n=e&&e.resource,r=n?e.resource:e,i=n?e:{resource:e};if(!t&&di.has(r))return di.get(r);let a=new z({source:pi(i)});return a.on(`destroy`,()=>{di.has(r)&&di.remove(r)}),t||di.set(r,a),a}z.from=function(e,t=!1){return typeof e==`string`?di.get(e):e instanceof Xt?new z({source:e}):mi(e,t)},Xt.from=pi,at.add(Yr,Xr,Zr,li,ti,ei,$t);var hi=(e=>(e[e.Low=0]=`Low`,e[e.Normal=1]=`Normal`,e[e.High=2]=`High`,e))(hi||{});function gi(e){if(typeof e!=`string`)throw TypeError(`Path must be a string. Received ${JSON.stringify(e)}`)}function _i(e){return e.split(`?`)[0].split(`#`)[0]}function vi(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function yi(e,t,n){return e.replace(new RegExp(vi(t),`g`),n)}function bi(e,t){let n=``,r=0,i=-1,a=0,o=-1;for(let s=0;s<=e.length;++s){if(s<e.length)o=e.charCodeAt(s);else if(o===47)break;else o=47;if(o===47){if(i!==s-1&&a!==1){if(i!==s-1&&a===2){if(n.length<2||r!==2||n.charCodeAt(n.length-1)!==46||n.charCodeAt(n.length-2)!==46){if(n.length>2){let e=n.lastIndexOf(`/`);if(e!==n.length-1){e===-1?(n=``,r=0):(n=n.slice(0,e),r=n.length-1-n.lastIndexOf(`/`)),i=s,a=0;continue}}else if(n.length===2||n.length===1){n=``,r=0,i=s,a=0;continue}}t&&(n.length>0?n+=`/..`:n=`..`,r=2)}else n.length>0?n+=`/${e.slice(i+1,s)}`:n=e.slice(i+1,s),r=s-i-1}i=s,a=0}else o===46&&a!==-1?++a:a=-1}return n}var xi={toPosix(e){return yi(e,`\\`,`/`)},isUrl(e){return/^https?:/.test(this.toPosix(e))},isDataUrl(e){return/^data:([a-z]+\/[a-z0-9-+.]+(;[a-z0-9-.!#$%*+.{}|~`]+=[a-z0-9-.!#$%*+.{}()_|~`]+)*)?(;base64)?,([a-z0-9!$&',()*+;=\-._~:@\/?%\s<>]*?)$/i.test(e)},isBlobUrl(e){return e.startsWith(`blob:`)},hasProtocol(e){return/^[^/:]+:/.test(this.toPosix(e))},getProtocol(e){gi(e),e=this.toPosix(e);let t=/^file:\/\/\//.exec(e);if(t)return t[0];let n=/^[^/:]+:\/{0,2}/.exec(e);return n?n[0]:``},toAbsolute(e,t,n){if(gi(e),this.isDataUrl(e)||this.isBlobUrl(e))return e;let r=_i(this.toPosix(t??$r.get().getBaseUrl())),i=_i(this.toPosix(n??this.rootname(r)));return e=this.toPosix(e),e.startsWith(`/`)?xi.join(i,e.slice(1)):this.isAbsolute(e)?e:this.join(r,e)},normalize(e){if(gi(e),e.length===0)return`.`;if(this.isDataUrl(e)||this.isBlobUrl(e))return e;e=this.toPosix(e);let t=``,n=e.startsWith(`/`);this.hasProtocol(e)&&(t=this.rootname(e),e=e.slice(t.length));let r=e.endsWith(`/`);return e=bi(e,!1),e.length>0&&r&&(e+=`/`),n?`/${e}`:t+e},isAbsolute(e){return gi(e),e=this.toPosix(e),this.hasProtocol(e)?!0:e.startsWith(`/`)},join(...e){if(e.length===0)return`.`;let t;for(let n=0;n<e.length;++n){let r=e[n];if(gi(r),r.length>0){if(t===void 0)t=r;else{let i=e[n-1]??``;this.joinExtensions.includes(this.extname(i).toLowerCase())?t+=`/../${r}`:t+=`/${r}`}}}return t===void 0?`.`:this.normalize(t)},dirname(e){if(gi(e),e.length===0)return`.`;e=this.toPosix(e);let t=e.charCodeAt(0),n=t===47,r=-1,i=!0,a=this.getProtocol(e),o=e;e=e.slice(a.length);for(let n=e.length-1;n>=1;--n)if(t=e.charCodeAt(n),t===47){if(!i){r=n;break}}else i=!1;return r===-1?n?`/`:this.isUrl(o)?a+e:a:n&&r===1?`//`:a+e.slice(0,r)},rootname(e){gi(e),e=this.toPosix(e);let t=``;if(t=e.startsWith(`/`)?`/`:this.getProtocol(e),this.isUrl(e)){let n=e.indexOf(`/`,t.length);t=n===-1?e:e.slice(0,n),t.endsWith(`/`)||(t+=`/`)}return t},basename(e,t){gi(e),t&&gi(t),e=_i(this.toPosix(e));let n=0,r=-1,i=!0,a;if(t!==void 0&&t.length>0&&t.length<=e.length){if(t.length===e.length&&t===e)return``;let o=t.length-1,s=-1;for(a=e.length-1;a>=0;--a){let c=e.charCodeAt(a);if(c===47){if(!i){n=a+1;break}}else s===-1&&(i=!1,s=a+1),o>=0&&(c===t.charCodeAt(o)?--o===-1&&(r=a):(o=-1,r=s))}return n===r?r=s:r===-1&&(r=e.length),e.slice(n,r)}for(a=e.length-1;a>=0;--a)if(e.charCodeAt(a)===47){if(!i){n=a+1;break}}else r===-1&&(i=!1,r=a+1);return r===-1?``:e.slice(n,r)},extname(e){gi(e),e=_i(this.toPosix(e));let t=-1,n=0,r=-1,i=!0,a=0;for(let o=e.length-1;o>=0;--o){let s=e.charCodeAt(o);if(s===47){if(!i){n=o+1;break}}else r===-1&&(i=!1,r=o+1),s===46?t===-1?t=o:a!==1&&(a=1):t!==-1&&(a=-1)}return t===-1||r===-1||a===0||a===1&&t===r-1&&t===n+1?``:e.slice(t,r)},parse(e){gi(e);let t={root:``,dir:``,base:``,ext:``,name:``};if(e.length===0)return t;e=_i(this.toPosix(e));let n=e.charCodeAt(0),r=this.isAbsolute(e),i;t.root=this.rootname(e),i=r||this.hasProtocol(e)?1:0;let a=-1,o=0,s=-1,c=!0,l=e.length-1,u=0;for(;l>=i;--l)if(n=e.charCodeAt(l),n===47){if(!c){o=l+1;break}}else s===-1&&(c=!1,s=l+1),n===46?a===-1?a=l:u!==1&&(u=1):a!==-1&&(u=-1);return a===-1||s===-1||u===0||u===1&&a===s-1&&a===o+1?s!==-1&&(t.base=t.name=o===0&&r?e.slice(1,s):e.slice(o,s)):(o===0&&r?(t.name=e.slice(1,a),t.base=e.slice(1,s)):(t.name=e.slice(o,a),t.base=e.slice(o,s)),t.ext=e.slice(a,s)),t.dir=this.dirname(e),t},sep:`/`,delimiter:`:`,joinExtensions:[`.html`]};function Si(e,t,n,r,i){let a=t[n];for(let o=0;o<a.length;o++){let s=a[o];n<t.length-1?Si(e.replace(r[n],s),t,n+1,r,i):i.push(e.replace(r[n],s))}}function Ci(e){let t=e.match(/\{(.*?)\}/g),n=[];if(t){let r=[];t.forEach(e=>{let t=e.substring(1,e.length-1).split(`,`);r.push(t)}),Si(e,r,0,t,n)}else n.push(e);return n}var wi=e=>!Array.isArray(e),Ti=class{constructor(){this._defaultBundleIdentifierOptions={connector:`-`,createBundleAssetId:(e,t)=>`${e}${this._bundleIdConnector}${t}`,extractAssetIdFromBundle:(e,t)=>t.replace(`${e}${this._bundleIdConnector}`,``)},this._bundleIdConnector=this._defaultBundleIdentifierOptions.connector,this._createBundleAssetId=this._defaultBundleIdentifierOptions.createBundleAssetId,this._extractAssetIdFromBundle=this._defaultBundleIdentifierOptions.extractAssetIdFromBundle,this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}setBundleIdentifier(e){if(this._bundleIdConnector=e.connector??this._bundleIdConnector,this._createBundleAssetId=e.createBundleAssetId??this._createBundleAssetId,this._extractAssetIdFromBundle=e.extractAssetIdFromBundle??this._extractAssetIdFromBundle,this._extractAssetIdFromBundle(`foo`,this._createBundleAssetId(`foo`,`bar`))!==`bar`)throw Error(`[Resolver] GenerateBundleAssetId are not working correctly`)}prefer(...e){e.forEach(e=>{this._preferredOrder.push(e),e.priority||=Object.keys(e.params)}),this._resolverHash={}}set basePath(e){this._basePath=e}get basePath(){return this._basePath}set rootPath(e){this._rootPath=e}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this.setBundleIdentifier(this._defaultBundleIdentifierOptions),this._assetMap={},this._preferredOrder=[],this._resolverHash={},this._rootPath=null,this._basePath=null,this._manifest=null,this._bundles={},this._defaultSearchParams=null}setDefaultSearchParams(e){if(typeof e==`string`)this._defaultSearchParams=e;else{let t=e;this._defaultSearchParams=Object.keys(t).map(e=>`${encodeURIComponent(e)}=${encodeURIComponent(t[e])}`).join(`&`)}}getAlias(e){let{alias:t,src:n}=e;return ui(t||n,e=>typeof e==`string`?e:Array.isArray(e)?e.map(e=>e?.src??e):e?.src?e.src:e,!0)}removeAlias(e,t){this._assetMap[e]&&(t&&t!==this._resolverHash[e]||(delete this._resolverHash[e],delete this._assetMap[e]))}addManifest(e){this._manifest&&Gn(`[Resolver] Manifest already exists, this will be overwritten`),this._manifest=e,e.bundles.forEach(e=>{this.addBundle(e.name,e.assets)})}addBundle(e,t){let n=[],r=t;Array.isArray(t)||(r=Object.entries(t).map(([e,t])=>typeof t==`string`||Array.isArray(t)?{alias:e,src:t}:{alias:e,...t})),r.forEach(t=>{let r=t.src,i=t.alias,a;if(typeof i==`string`){let t=this._createBundleAssetId(e,i);n.push(t),a=[i,t]}else{let t=i.map(t=>this._createBundleAssetId(e,t));n.push(...t),a=[...i,...t]}this.add({...t,alias:a,src:r})}),this._bundles[e]=n}add(e){let t=[];Array.isArray(e)?t.push(...e):t.push(e);let n=e=>{this.hasKey(e)&&Gn(`[Resolver] already has key: ${e} overwriting`)};ui(t).forEach(e=>{let{src:t}=e,{data:r,format:i,loadParser:a,parser:o}=e,s=ui(t).map(e=>typeof e==`string`?Ci(e):Array.isArray(e)?e:[e]),c=this.getAlias(e);Array.isArray(c)?c.forEach(n):n(c);let l=[],u=e=>({src:e,...this._parsers.find(t=>t.test(e))?.parse(e)});s.forEach(t=>{t.forEach(t=>{let n={};if(typeof t==`object`?(r=t.data??r,i=t.format??i,(t.loadParser||t.parser)&&(a=t.loadParser??a,o=t.parser??o),n={...u(t.src),...t}):n=u(t),!c)throw Error(`[Resolver] alias is undefined for this asset: ${n.src}`);n=this._buildResolvedAsset(n,{aliases:c,data:r,format:i,loadParser:a,parser:o,progressSize:e.progressSize}),l.push(n)})}),c.forEach(e=>{this._assetMap[e]=l})})}resolveBundle(e){let t=wi(e);e=ui(e);let n={};return e.forEach(e=>{let t=this._bundles[e];if(t){let r=this.resolve(t),i={};for(let t in r){let n=r[t];i[this._extractAssetIdFromBundle(e,t)]=n}n[e]=i}}),t?n[e[0]]:n}resolveUrl(e){let t=this.resolve(e);if(typeof e!=`string`){let e={};for(let n in t)e[n]=t[n].src;return e}return t.src}resolve(e){let t=wi(e);e=ui(e);let n={};return e.forEach(e=>{if(!this._resolverHash[e]){if(this._assetMap[e]){let t=this._assetMap[e],n=this._getPreferredOrder(t);n?.priority.forEach(e=>{n.params[e].forEach(n=>{let r=t.filter(t=>t[e]?t[e]===n:!1);r.length&&(t=r)})}),this._resolverHash[e]=t[0]}else this._resolverHash[e]=this._buildResolvedAsset({alias:[e],src:e},{})}n[e]=this._resolverHash[e]}),t?n[e[0]]:n}hasKey(e){return!!this._assetMap[e]}hasBundle(e){return!!this._bundles[e]}_getPreferredOrder(e){for(let t=0;t<e.length;t++){let n=e[t],r=this._preferredOrder.find(e=>e.params.format.includes(n.format));if(r)return r}return this._preferredOrder[0]}_appendDefaultSearchParams(e){return this._defaultSearchParams?`${e}${/\?/.test(e)?`&`:`?`}${this._defaultSearchParams}`:e}_buildResolvedAsset(e,t){let{aliases:n,data:r,loadParser:i,parser:a,format:o,progressSize:s}=t;return(this._basePath||this._rootPath)&&(e.src=xi.toAbsolute(e.src,this._basePath,this._rootPath)),e.alias=n??e.alias??[e.src],e.src=this._appendDefaultSearchParams(e.src),e.data={...r||{},...e.data},e.loadParser=i??e.loadParser,e.parser=a??e.parser,e.format=o??e.format??Ei(e.src),s!==void 0&&(e.progressSize=s),e}};Ti.RETINA_PREFIX=/@([0-9\.]+)x/;function Ei(e){return e.split(`.`).pop().split(`?`).shift().split(`#`).shift()}var Di=(e,t)=>{let n=t.split(`?`)[1];return n&&(e+=`?${n}`),e},Oi=class e{constructor(e,t){this.linkedSheets=[];let n=e;e?.source instanceof Xt&&(n={texture:e,data:t});let{texture:r,data:i,cachePrefix:a=``}=n;this.cachePrefix=a,this._texture=r instanceof z?r:null,this.textureSource=r.source,this.textures={},this.animations={},this.data=i;let o=parseFloat(i.meta.scale);o?(this.resolution=o,r.source.resolution=this.resolution):this.resolution=r.source._resolution,this._frames=this.data.frames,this._frameKeys=Object.keys(this._frames),this._batchIndex=0,this._callback=null}parse(){return new Promise(t=>{this._callback=t,this._batchIndex=0,this._frameKeys.length<=e.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}parseSync(){return this._processFrames(0,!0),this._processAnimations(),this.textures}_processFrames(t,n=!1){let r=t,i=n?1/0:e.BATCH_SIZE;for(;r-t<i&&r<this._frameKeys.length;){let e=this._frameKeys[r],t=this._frames[e],n=t.frame;if(n){let r=null,i=null,a=t.trimmed!==!1&&t.sourceSize?t.sourceSize:t.frame,o=new Nt(0,0,Math.floor(a.w)/this.resolution,Math.floor(a.h)/this.resolution);r=t.rotated?new Nt(Math.floor(n.x)/this.resolution,Math.floor(n.y)/this.resolution,Math.floor(n.h)/this.resolution,Math.floor(n.w)/this.resolution):new Nt(Math.floor(n.x)/this.resolution,Math.floor(n.y)/this.resolution,Math.floor(n.w)/this.resolution,Math.floor(n.h)/this.resolution),t.trimmed!==!1&&t.spriteSourceSize&&(i=new Nt(Math.floor(t.spriteSourceSize.x)/this.resolution,Math.floor(t.spriteSourceSize.y)/this.resolution,Math.floor(n.w)/this.resolution,Math.floor(n.h)/this.resolution)),this.textures[e]=new z({source:this.textureSource,frame:r,orig:o,trim:i,rotate:t.rotated?2:0,defaultAnchor:t.anchor,defaultBorders:t.borders,label:e.toString()})}r++}}_processAnimations(){let e=this.data.animations||{};for(let t in e){this.animations[t]=[];for(let n=0;n<e[t].length;n++){let r=e[t][n];this.animations[t].push(this.textures[r])}}}_parseComplete(){let e=this._callback;this._callback=null,this._batchIndex=0,e.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*e.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*e.BATCH_SIZE<this._frameKeys.length?this._nextBatch():(this._processAnimations(),this._parseComplete())},0)}destroy(e=!1){for(let e in this.textures)this.textures[e].destroy();this._frames=null,this._frameKeys=null,this.data=null,this.textures=null,e&&(this._texture?.destroy(),this.textureSource.destroy()),this._texture=null,this.textureSource=null,this.linkedSheets=[]}};Oi.BATCH_SIZE=1e3;var ki=Oi,Ai=[`jpg`,`png`,`jpeg`,`avif`,`webp`,`basis`,`etc2`,`bc7`,`bc6h`,`bc5`,`bc4`,`bc3`,`bc2`,`bc1`,`eac`,`astc`];function ji(e,t,n){let r={};if(e.forEach(e=>{r[e]=t}),Object.keys(t.textures).forEach(e=>{r[`${t.cachePrefix}${e}`]=t.textures[e]}),!n){let n=xi.dirname(e[0]);t.linkedSheets.forEach((e,i)=>{let a=ji([`${n}/${t.data.meta.related_multi_packs[i]}`],e,!0);Object.assign(r,a)})}return r}var Mi={extension:N.Asset,cache:{test:e=>e instanceof ki,getCacheableAssets:(e,t)=>ji(e,t,!1)},resolver:{extension:{type:N.ResolveParser,name:`resolveSpritesheet`},test:e=>{let t=e.split(`?`)[0].split(`.`),n=t.pop(),r=t.pop();return n===`json`&&Ai.includes(r)},parse:e=>{let t=e.split(`.`);return{resolution:parseFloat(Ti.RETINA_PREFIX.exec(e)?.[1]??`1`),format:t[t.length-2],src:e}}},loader:{name:`spritesheetLoader`,id:`spritesheet`,extension:{type:N.LoadParser,priority:hi.Normal,name:`spritesheetLoader`},async testParse(e,t){return xi.extname(t.src).toLowerCase()===`.json`&&!!e.frames},async parse(e,t,n){let{texture:r,imageFilename:i,textureOptions:a,cachePrefix:o}=t?.data??{},s=xi.dirname(t.src);s&&s.lastIndexOf(`/`)!==s.length-1&&(s+=`/`);let c;if(r instanceof z)c=r;else{let r=Di(s+(i??e.meta.image),t.src);c=(await n.load([{src:r,data:a}]))[r]}let l=new ki({texture:c.source,data:e,cachePrefix:o});await l.parse();let u=e?.meta?.related_multi_packs;if(Array.isArray(u)){let e=[];for(let r of u){if(typeof r!=`string`)continue;let i=s+r;t.data?.ignoreMultiPack||(i=Di(i,t.src),e.push(n.load({src:i,data:{textureOptions:a,ignoreMultiPack:!0}})))}let r=await Promise.all(e);l.linkedSheets=r,r.forEach(e=>{e.linkedSheets=[l].concat(l.linkedSheets.filter(t=>t!==e))})}return l},async unload(e,t,n){await n.unload(e.textureSource._sourceOrigin),e.destroy(!1)}}};at.add(Mi);var Ni=Object.create(null),Pi=Object.create(null);function Fi(e,t){let n=Pi[e];return n===void 0&&(Ni[t]===void 0&&(Ni[t]=1),Pi[e]=n=Ni[t]++),n}function Ii(e){return e.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm,``)}var Li=RegExp(`(?:layout\\s*\\(\\s*location\\s*=\\s*(\\d+)\\s*\\)\\s*)?\\bout\\s+(?:(?:highp|mediump|lowp)\\s+)?\\w+\\s+\\w+\\s*(?:\\[\\s*(\\d+)\\s*\\])?\\s*;`,`g`);function Ri(e){if(!e.includes(`#version 300 es`))return e.includes(`gl_FragData`)?null:1;let t=Ii(e),n=0,r;for(;(r=Li.exec(t))!==null;){let e=r[1]===void 0?0:parseInt(r[1],10),t=r[2]===void 0?1:parseInt(r[2],10);n|=(1<<t)-1<<e}return Li.lastIndex=0,n||(/\bout\b/.test(t)?null:0)}var zi;function Bi(){return(!zi||zi?.isContextLost())&&(zi=$r.get().createCanvas().getContext(`webgl`,{})),zi}var Vi;function Hi(){if(!Vi){Vi=`mediump`;let e=Bi();e&&e.getShaderPrecisionFormat&&(Vi=e.getShaderPrecisionFormat(e.FRAGMENT_SHADER,e.HIGH_FLOAT).precision?`highp`:`mediump`)}return Vi}function Ui(e,t,n){return t?e:n?(e=e.replace(`out vec4 finalColor;`,``),`
|
|
6
|
+
|
|
7
|
+
#ifdef GL_ES // This checks if it is WebGL1
|
|
8
|
+
#define in varying
|
|
9
|
+
#define finalColor gl_FragColor
|
|
10
|
+
#define texture texture2D
|
|
11
|
+
#endif
|
|
12
|
+
${e}
|
|
13
|
+
`):`
|
|
14
|
+
|
|
15
|
+
#ifdef GL_ES // This checks if it is WebGL1
|
|
16
|
+
#define in attribute
|
|
17
|
+
#define out varying
|
|
18
|
+
#endif
|
|
19
|
+
${e}
|
|
20
|
+
`}var Wi=/\buniform\s+([iu]?sampler\w+)/g,Gi=/\bprecision\s+\w+\s+([iu]?sampler\w+)\s*;/g,Ki={sampler2D:`lowp`,samplerCube:`lowp`};function qi(e,t,n){let r=n?t.maxSupportedFragmentPrecision:t.maxSupportedVertexPrecision;if(e.substring(0,9)!==`precision`){let i=n?t.requestedFragmentPrecision:t.requestedVertexPrecision;i===`highp`&&r!==`highp`&&(i=`mediump`),e=`precision ${i} float;
|
|
21
|
+
${e}`}else r!==`highp`&&e.substring(0,15)===`precision highp`&&(e=e.replace(`precision highp`,`precision mediump`));let i=t.maxSupportedFragmentPrecision===`highp`?`highp`:`mediump`;return Ji(e,i)}function Ji(e,t){let n=new Set,r=``;for(let[,t]of e.matchAll(Gi))n.add(t);for(let[,i]of e.matchAll(Wi))n.has(i)||(n.add(i),r+=`precision ${Ki[i]??t} ${i};
|
|
22
|
+
`);return r+e}function Yi(e,t){return t?`#version 300 es
|
|
23
|
+
${e}`:e}var Xi={},Zi={};function Qi(e,{name:t=`pixi-program`},n=!0){t=t.replace(/\s+/g,`-`),t+=n?`-fragment`:`-vertex`;let r=n?Xi:Zi;return r[t]?(r[t]++,t+=`-${r[t]}`):r[t]=1,e.indexOf(`#define SHADER_NAME`)===-1?`#define SHADER_NAME ${t}
|
|
24
|
+
${e}`:e}function $i(e,t){return t?e.replace(`#version 300 es`,``):e}var ea={stripVersion:$i,ensurePrecision:qi,addProgramDefines:Ui,setProgramName:Qi,insertVersion:Yi},ta=Object.create(null),na=class e{constructor(t){t={...e.defaultOptions,...t};let n=t.fragment.indexOf(`#version 300 es`)!==-1,r={stripVersion:n,ensurePrecision:{requestedFragmentPrecision:t.preferredFragmentPrecision,requestedVertexPrecision:t.preferredVertexPrecision,maxSupportedVertexPrecision:`highp`,maxSupportedFragmentPrecision:Hi()},setProgramName:{name:t.name},addProgramDefines:n,insertVersion:n},i=t.fragment,a=t.vertex;Object.keys(ea).forEach(e=>{let t=r[e];i=ea[e](i,t,!0),a=ea[e](a,t,!1)}),this.fragment=i,this.vertex=a,this.transformFeedbackVaryings=t.transformFeedbackVaryings,this._key=Fi(`${this.vertex}:${this.fragment}`,`gl-program`)}get fragmentOutputMask(){return this._fragmentOutputMask===void 0&&(this._fragmentOutputMask=Ri(this.fragment)),this._fragmentOutputMask}destroy(){this.fragment=null,this.vertex=null,this._attributeData=null,this._uniformData=null,this._uniformBlockData=null,this.transformFeedbackVaryings=null,ta[this._cacheKey]=null}static from(t){let n=`${t.vertex}:${t.fragment}`;return ta[n]||(ta[n]=new e(t),ta[n]._cacheKey=n),ta[n]}};na.defaultOptions={preferredVertexPrecision:`highp`,preferredFragmentPrecision:`mediump`};var ra=na,ia={uint8x2:{size:2,stride:2,normalised:!1},uint8x4:{size:4,stride:4,normalised:!1},sint8x2:{size:2,stride:2,normalised:!1},sint8x4:{size:4,stride:4,normalised:!1},unorm8x2:{size:2,stride:2,normalised:!0},unorm8x4:{size:4,stride:4,normalised:!0},snorm8x2:{size:2,stride:2,normalised:!0},snorm8x4:{size:4,stride:4,normalised:!0},uint16x2:{size:2,stride:4,normalised:!1},uint16x4:{size:4,stride:8,normalised:!1},sint16x2:{size:2,stride:4,normalised:!1},sint16x4:{size:4,stride:8,normalised:!1},unorm16x2:{size:2,stride:4,normalised:!0},unorm16x4:{size:4,stride:8,normalised:!0},snorm16x2:{size:2,stride:4,normalised:!0},snorm16x4:{size:4,stride:8,normalised:!0},float16x2:{size:2,stride:4,normalised:!1},float16x4:{size:4,stride:8,normalised:!1},float32:{size:1,stride:4,normalised:!1},float32x2:{size:2,stride:8,normalised:!1},float32x3:{size:3,stride:12,normalised:!1},float32x4:{size:4,stride:16,normalised:!1},uint32:{size:1,stride:4,normalised:!1},uint32x2:{size:2,stride:8,normalised:!1},uint32x3:{size:3,stride:12,normalised:!1},uint32x4:{size:4,stride:16,normalised:!1},sint32:{size:1,stride:4,normalised:!1},sint32x2:{size:2,stride:8,normalised:!1},sint32x3:{size:3,stride:12,normalised:!1},sint32x4:{size:4,stride:16,normalised:!1}};function aa(e){return ia[e]??ia.float32}var oa={f32:`float32`,"vec2<f32>":`float32x2`,"vec3<f32>":`float32x3`,"vec4<f32>":`float32x4`,vec2f:`float32x2`,vec3f:`float32x3`,vec4f:`float32x4`,i32:`sint32`,"vec2<i32>":`sint32x2`,"vec3<i32>":`sint32x3`,"vec4<i32>":`sint32x4`,vec2i:`sint32x2`,vec3i:`sint32x3`,vec4i:`sint32x4`,u32:`uint32`,"vec2<u32>":`uint32x2`,"vec3<u32>":`uint32x3`,"vec4<u32>":`uint32x4`,vec2u:`uint32x2`,vec3u:`uint32x3`,vec4u:`uint32x4`,bool:`uint32`,"vec2<bool>":`uint32x2`,"vec3<bool>":`uint32x3`,"vec4<bool>":`uint32x4`},sa=/@location\((\d+)\)\s+([a-zA-Z0-9_]+)\s*:\s*([a-zA-Z0-9_<>]+)(?:,|\s|\)|$)/g;function ca(e,t){let n;for(;(n=sa.exec(e))!==null;){let e=oa[n[3]]??`float32`;t[n[2]]={location:parseInt(n[1],10),format:e,stride:aa(e).stride,offset:0,instance:!1,start:0}}sa.lastIndex=0}function la({source:e,entryPoint:t}){let n={},r=Ii(e),i=r.indexOf(`fn ${t}(`);if(i===-1)return n;let a=r.indexOf(`->`,i);if(a===-1)return n;let o=r.substring(i,a);if(ca(o,n),Object.keys(n).length===0){let e=o.match(/\(\s*\w+\s*:\s*(\w+)/);if(e){let t=e[1],i=RegExp(`struct\\s+${t}\\s*\\{([^}]+)\\}`,`s`),a=r.match(i);a&&ca(a[1],n)}}return n}var ua=/@location\(\s*(\d+)\s*\)/g;function da(e){let t=0,n;for(;(n=ua.exec(e))!==null;)t|=1<<parseInt(n[1],10);return ua.lastIndex=0,t}function fa({source:e,entryPoint:t}){if(!t)return null;let n=Ii(e),r=RegExp(`fn\\s+${t}\\s*\\(`).exec(n);if(!r)return null;let i=1,a=r.index+r[0].length;for(;a<n.length&&i>0;){let e=n[a++];e===`(`?i++:e===`)`&&i--}let o=n.indexOf(`{`,a);if(o===-1)return null;let s=n.substring(a,o).trim();if(!s.startsWith(`->`))return 0;let c=s.substring(2).trim();if(c.startsWith(`@builtin`))return 0;if(c.startsWith(`@location`))return da(c);if(!/^\w+$/.test(c))return null;let l=RegExp(`struct\\s+${c}\\s*\\{([^}]*)\\}`).exec(n);return l?da(l[1]):null}function pa(e){let t=/(^|[^/])@(group|binding)\(\d+\)[^;]+;/g,n=/@group\((\d+)\)/,r=/@binding\((\d+)\)/,i=/var(<[^>]+>)? (\w+)/,a=/:\s*([\w<>]+)/,o=/struct\s+(\w+)\s*{([^}]+)}/g,s=/(\w+)\s*:\s*([\w\<\>]+)/g,c=/struct\s+(\w+)/,l=e.match(t)?.map(e=>{let t=e.match(i),o=t?.[1]??``,s;return o===`<uniform>`?s=`uniform`:o.startsWith(`<storage`)&&(s=`storage`),{group:parseInt(e.match(n)[1],10),binding:parseInt(e.match(r)[1],10),name:t[2],accessMode:s,type:e.match(a)[1]}});return l?{groups:l,structs:e.match(o)?.map(e=>{let t=e.match(c)[1],n=e.match(s).reduce((e,t)=>{let[n,r]=t.split(`:`);return e[n.trim()]=r.trim(),e},{});return n?{name:t,members:n}:null}).filter(({name:e})=>l.some(t=>t.type===e||t.type.includes(`<${e}>`)))??[]}:{groups:[],structs:[]}}var B=(e=>(e[e.VERTEX=1]=`VERTEX`,e[e.FRAGMENT=2]=`FRAGMENT`,e[e.COMPUTE=4]=`COMPUTE`,e))(B||{});function ma(e){return e.endsWith(`<u32>`)?`uint`:e.endsWith(`<i32>`)?`sint`:`float`}function ha({groups:e}){let t=[];for(let n=0;n<e.length;n++){let r=e[n];t[r.group]||(t[r.group]=[]),r.accessMode===`uniform`?t[r.group].push({binding:r.binding,visibility:B.VERTEX|B.FRAGMENT,buffer:{type:`uniform`}}):r.accessMode===`storage`?t[r.group].push({binding:r.binding,visibility:B.VERTEX|B.FRAGMENT,buffer:{type:`read-only-storage`}}):r.type===`sampler`?t[r.group].push({binding:r.binding,visibility:B.VERTEX|B.FRAGMENT,sampler:{type:`filtering`}}):r.type===`sampler_comparison`?t[r.group].push({binding:r.binding,visibility:B.VERTEX|B.FRAGMENT,sampler:{type:`comparison`}}):r.type===`texture_2d`||r.type.startsWith(`texture_2d<`)?t[r.group].push({binding:r.binding,visibility:B.VERTEX|B.FRAGMENT,texture:{sampleType:ma(r.type),viewDimension:`2d`,multisampled:!1}}):r.type===`texture_depth_2d`?t[r.group].push({binding:r.binding,visibility:B.VERTEX|B.FRAGMENT,texture:{sampleType:`depth`,viewDimension:`2d`,multisampled:!1}}):r.type===`texture_depth_2d_array`?t[r.group].push({binding:r.binding,visibility:B.VERTEX|B.FRAGMENT,texture:{sampleType:`depth`,viewDimension:`2d-array`,multisampled:!1}}):r.type===`texture_2d_array`||r.type.startsWith(`texture_2d_array<`)?t[r.group].push({binding:r.binding,visibility:B.VERTEX|B.FRAGMENT,texture:{sampleType:ma(r.type),viewDimension:`2d-array`,multisampled:!1}}):r.type===`texture_3d`||r.type.startsWith(`texture_3d<`)?t[r.group].push({binding:r.binding,visibility:B.VERTEX|B.FRAGMENT,texture:{sampleType:ma(r.type),viewDimension:`3d`,multisampled:!1}}):(r.type===`texture_cube`||r.type.startsWith(`texture_cube<`))&&t[r.group].push({binding:r.binding,visibility:B.VERTEX|B.FRAGMENT,texture:{sampleType:ma(r.type),viewDimension:`cube`,multisampled:!1}})}for(let e=0;e<t.length;e++)t[e]||(t[e]=[]);return t}function ga({groups:e}){let t=[];for(let n=0;n<e.length;n++){let r=e[n];t[r.group]||(t[r.group]={}),t[r.group][r.name]=r.binding}return t}function _a(e,t){let n=new Set,r=new Set;return{structs:[...e.structs,...t.structs].filter(e=>!n.has(e.name)&&(n.add(e.name),!0)),groups:[...e.groups,...t.groups].filter(e=>{let t=`${e.name}-${e.binding}`;return!r.has(t)&&(r.add(t),!0)})}}var va=Object.create(null),ya=class e{constructor(e){this._layoutKey=0,this._attributeLocationsKey=0;let{fragment:t,vertex:n,layout:r,gpuLayout:i,name:a}=e;if(this.name=a,this.fragment=t,this.vertex=n,t.source===n.source){let e=pa(t.source);this.structsAndGroups=e}else{let e=pa(n.source),r=pa(t.source);this.structsAndGroups=_a(e,r)}this.layout=r??ga(this.structsAndGroups),this.gpuLayout=i??ha(this.structsAndGroups),this.autoAssignGlobalUniforms=this.layout[0]?.globalUniforms!==void 0,this.autoAssignLocalUniforms=this.layout[1]?.localUniforms!==void 0,this._generateProgramKey()}_generateProgramKey(){let{vertex:e,fragment:t}=this,n=e.source+t.source+e.entryPoint+t.entryPoint;this._layoutKey=Fi(n,`program`)}get attributeData(){return this._attributeData??=la(this.vertex),this._attributeData}get fragmentOutputMask(){return this._fragmentOutputMask===void 0&&(this._fragmentOutputMask=fa(this.fragment)),this._fragmentOutputMask}destroy(){this.gpuLayout=null,this.layout=null,this.structsAndGroups=null,this.fragment=null,this.vertex=null,va[this._cacheKey]=null}static from(t){let n=`${t.vertex.source}:${t.fragment.source}:${t.fragment.entryPoint}:${t.vertex.entryPoint}`;return va[n]||(va[n]=new e(t),va[n]._cacheKey=n),va[n]}},ba=[`f32`,`i32`,`u32`,`vec2<f32>`,`vec3<f32>`,`vec4<f32>`,`mat2x2<f32>`,`mat3x3<f32>`,`mat4x4<f32>`,`mat3x2<f32>`,`mat4x2<f32>`,`mat2x3<f32>`,`mat4x3<f32>`,`mat2x4<f32>`,`mat3x4<f32>`,`vec2<i32>`,`vec3<i32>`,`vec4<i32>`,`vec2<u32>`,`vec3<u32>`,`vec4<u32>`],xa=ba.reduce((e,t)=>(e[t]=!0,e),{});function Sa(e,t){switch(e){case`f32`:return 0;case`vec2<f32>`:return new Float32Array(2*t);case`vec3<f32>`:return new Float32Array(3*t);case`vec4<f32>`:return new Float32Array(4*t);case`mat2x2<f32>`:return new Float32Array([1,0,0,1]);case`mat3x3<f32>`:return new Float32Array([1,0,0,0,1,0,0,0,1]);case`mat4x4<f32>`:return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}var Ca=class e extends gt{constructor(t,n){super(),this.uid=I(`uniform`),this._resourceType=`uniformGroup`,this._resourceId=I(`resource`),this.isUniformGroup=!0,this._dirtyId=0,this.destroyed=!1,n={...e.defaultOptions,...n},this.uniformStructures=t;let r={};for(let e in t){let n=t[e];if(n.name=e,n.size=n.size??1,!xa[n.type]){let e=n.type.match(/^array<(\w+(?:<\w+>)?),\s*(\d+)>$/);if(e){let[,t,r]=e;throw Error(`Uniform type ${n.type} is not supported. Use type: '${t}', size: ${r} instead.`)}throw Error(`Uniform type ${n.type} is not supported. Supported uniform types are: ${ba.join(`, `)}`)}n.value??=Sa(n.type,n.size),r[e]=n.value}this.uniforms=r,this._dirtyId=1,this.ubo=n.ubo,this.isStatic=n.isStatic,this._signature=Fi(Object.keys(r).map(e=>`${e}-${t[e].type}`).join(`-`),`uniform-group`)}get buffer(){return this._buffer}set buffer(e){this._buffer!==e&&(this._buffer?.off(`change`,this.onBufferChange,this),this._buffer=e,e?.on(`change`,this.onBufferChange,this))}get _gcLastUsed(){return this._buffer?._gcLastUsed??-1}set _gcLastUsed(e){this._buffer&&(this._buffer._gcLastUsed=e)}onBufferChange(){this._resourceId=I(`resource`),this.emit(`change`,this)}update(){this._dirtyId++}};Ca.defaultOptions={ubo:!1,isStatic:!1};var wa=Ca;function Ta(e,t){let n=Math.imul(t+0x9e3779b9,0x85ebca6b)^Math.imul(e+1,0xc2b2ae35);return n^=n>>>16,n=Math.imul(n,0x7feb352d),n^=n>>>15,n=Math.imul(n,0x846ca68b),n^n>>>16}function Ea(e,t){let n=Math.imul(t+0x7f4a7c15,668265263)^Math.imul(e+374761393,0x9e3779b1);return n^=n>>>15,n=Math.imul(n,739982445),n^=n>>>12,n=Math.imul(n,695872825),n^n>>>15}var Da=class{constructor(e){this.resources=Object.create(null),this._resourceKeysValue=null,this._touchKeysValue=null,this._keyLow=0,this._keyHigh=0,this._gpuEntry=null,this._gpuEntryLayoutKey=-1,this._keyedIds=[],this.layout=null;let t=0;for(let n in e){t===0&&!/^\d/.test(n)&&(this.layout={}),this.layout&&(this.layout[n]=t);let r=e[n];r&&this.setResource(r,t),t++}}get _resourceKeys(){return this._resourceKeysValue??=Object.keys(this.resources).map(Number),this._resourceKeysValue}setResource(e,t){typeof t==`string`&&(t=this._bindingOf(t));let n=this.resources[t];e!==n&&(n&&n.off?.(`change`,this.onResourceChange,this),e.on?.(`change`,this.onResourceChange,this),this.setResourceUnwatched(e,t))}setResourceUnwatched(e,t){let n=this.resources[t];if(e===n)return;let r=e._resourceId;n?._resourceType!==e._resourceType&&(this._touchKeysValue=null),n===void 0?(this._resourceKeysValue=null,this._keyLow^=Ta(t,r),this._keyHigh^=Ea(t,r),this._keyedIds[t]=r,this._gpuEntry=null):this._keyedIds[t]!==r&&this._rekey(t,r),this.resources[t]=e}_rekey(e,t){let n=this._keyedIds[e];this._keyLow^=Ta(e,n)^Ta(e,t),this._keyHigh^=Ea(e,n)^Ea(e,t),this._keyedIds[e]=t,this._gpuEntry=null}getResource(e){return this.resources[typeof e==`string`?this._bindingOf(e):e]}_bindingOf(e){let t=this.layout?.[e];if(t===void 0)throw Error(`[BindGroup] no binding named '${e}' in this group`);return t}_touch(e){let t=this.resources,n=this._touchKeys;for(let r=0;r<n.length;r++){let i=t[n[r]];i&&(i._gcLastUsed=e)}}get _touchKeys(){return this._touchKeysValue??=this._resourceKeys.filter(e=>this.resources[e]?._resourceType!==`textureSampler`),this._touchKeysValue}destroy(){let e=this.resources;for(let t in e)e[t]?.off?.(`change`,this.onResourceChange,this);this.resources=null,this._resourceKeysValue=null,this._touchKeysValue=null,this._gpuEntry=null}onResourceChange(e){let t=this.resources;if(!t)return;let n=this._resourceKeys,r=e.destroyed;for(let i=0;i<n.length;i++){let a=n[i];t[a]===e&&(r&&(t[a]=null),this._rekey(a,r?-1:e._resourceId))}r&&Gn(`[BindGroup] a '${e._resourceType}' was destroyed while still bound to a shader. Remove it from the shader before destroying it.`)}},Oa=(e=>(e[e.WEBGL=1]=`WEBGL`,e[e.WEBGPU=2]=`WEBGPU`,e[e.CANVAS=4]=`CANVAS`,e[e.BOTH=3]=`BOTH`,e))(Oa||{}),ka=class e{constructor(e){this.data={...e};let t=Object.keys(e).sort().map(t=>`${t}:${e[t]}`).join(`|`);this.id=Fi(t,`shader-overrides`)}static from(t){return t instanceof e?t:new e(t)}},Aa=class e extends gt{constructor(e){super(),this.uid=I(`shader`),this._uniformBindMap=Object.create(null),this._ownedBindGroups=[],this._destroyed=!1;let{gpuProgram:t,glProgram:n,groups:r,resources:i,compatibleRenderers:a,groupMap:o,overrides:s}=e;this._overrides=s?ka.from(s):null,this.gpuProgram=t,this.glProgram=n,a===void 0&&(a=0,t&&(a|=Oa.WEBGPU),n&&(a|=Oa.WEBGL)),this.compatibleRenderers=a;let c={};if(o)for(let e in o)for(let t in o[e]){let n=o[e][t];c[n]={group:Number(e),binding:Number(t),name:n}}if(!i&&!r&&(i={}),i&&r)throw Error(`[Shader] Cannot have both resources and groups`);if(!t&&r&&!o)throw Error(`[Shader] No group map or WebGPU shader provided - consider using resources instead.`);if(t&&r&&!o){let e=t.structsAndGroups.groups;o={},e.forEach(e=>{o[e.group]=o[e.group]||{},o[e.group][e.binding]=e.name,c[e.name]=e})}else if(i){r={},o||={},t&&t.structsAndGroups.groups.forEach(e=>{o[e.group]=o[e.group]||{},o[e.group][e.binding]=e.name,c[e.name]=e});let e=0;for(let a in i)c[a]||(t&&!n&&Gn(`[Shader] the resource '${a}' matches no binding in the WGSL source \u2014 is the name correct?`),r[99]||(r[99]=new Da,this._ownedBindGroups.push(r[99])),c[a]={group:99,binding:e,name:a},o[99]=o[99]||{},o[99][e]=a,e++);for(let e in i){let t=e,n=i[e];!n.source&&!n._resourceType&&(n=new wa(n));let a=c[t];a&&(r[a.group]||(r[a.group]=new Da,this._ownedBindGroups.push(r[a.group])),r[a.group].setResource(n,a.binding))}}this.groups=r,this._uniformBindMap=o,this.resources=this._buildResourceAccessor(r,c)}addResource(e,t,n){var r,i;(r=this._uniformBindMap)[t]||(r[t]={}),(i=this._uniformBindMap[t])[n]||(i[n]=e),this.groups[t]||(this.groups[t]=new Da,this._ownedBindGroups.push(this.groups[t]))}_buildResourceAccessor(e,t){let n={};for(let r in t){let i=t[r];Object.defineProperty(n,i.name,{get(){let t=e[i.group];return t.getResource(t.layout?t.layout[i.name]:i.binding)},set(t){let n=e[i.group];n.setResource(t,n.layout?n.layout[i.name]:i.binding)}})}return n}destroy(e=!1){this._destroyed||(this._destroyed=!0,this.emit(`destroy`,this),e&&(this.gpuProgram?.destroy(),this.glProgram?.destroy()),this.gpuProgram=null,this.glProgram=null,this.removeAllListeners(),this._uniformBindMap=null,this._ownedBindGroups.forEach(e=>{e.destroy()}),this._ownedBindGroups=null,this.resources=null,this.groups=null,this._overrides=null)}static from(t){let{gpu:n,gl:r,...i}=t,a,o;return n&&(a=ya.from(n)),r&&(o=ra.from(r)),new e({gpuProgram:a,glProgram:o,...i})}},ja={normal:0,add:1,multiply:2,screen:3,overlay:4,erase:5,"normal-npm":6,"add-npm":7,"screen-npm":8,min:9,max:10},Ma={BLEND:0,OFFSET:1,CULLING:2,DEPTH_TEST:3,WINDING:4,DEPTH_MASK:5},{BLEND:Na,OFFSET:Pa,CULLING:Fa,DEPTH_TEST:Ia,WINDING:La,DEPTH_MASK:Ra}=Ma,za=class e{constructor(){this.data=0,this.blendMode=`normal`,this.polygonOffset=0,this.blend=!0,this.depthMask=!0}get blend(){return!!(this.data&1<<Na)}set blend(e){!!(this.data&1<<Na)!==e&&(this.data^=1<<Na)}get offsets(){return!!(this.data&1<<Pa)}set offsets(e){!!(this.data&1<<Pa)!==e&&(this.data^=1<<Pa)}set cullMode(e){e===`none`?this.culling=!1:(this.culling=!0,this.clockwiseFrontFace=e===`front`)}get cullMode(){return this.culling?this.clockwiseFrontFace?`front`:`back`:`none`}get culling(){return!!(this.data&1<<Fa)}set culling(e){!!(this.data&1<<Fa)!==e&&(this.data^=1<<Fa)}get depthTest(){return!!(this.data&1<<Ia)}set depthTest(e){!!(this.data&1<<Ia)!==e&&(this.data^=1<<Ia)}get depthMask(){return!!(this.data&1<<Ra)}set depthMask(e){!!(this.data&1<<Ra)!==e&&(this.data^=1<<Ra)}get clockwiseFrontFace(){return!!(this.data&1<<La)}set clockwiseFrontFace(e){!!(this.data&1<<La)!==e&&(this.data^=1<<La)}get blendMode(){return this._blendMode}set blendMode(e){this.blend=e!==`none`,this._blendMode=e,this._blendModeId=ja[e]||0}get polygonOffset(){return this._polygonOffset}set polygonOffset(e){this.offsets=!!e,this._polygonOffset=e}toString(){return`[pixi.js/core:State blendMode=${this.blendMode} clockwiseFrontFace=${this.clockwiseFrontFace} culling=${this.culling} depthMask=${this.depthMask} polygonOffset=${this.polygonOffset}]`}static for2d(){let t=new e;return t.depthTest=!1,t.depthMask=!1,t.blend=!0,t}};za.default2d=za.for2d();var Ba=za,Va=class e extends Aa{constructor(t){t={...e.defaultOptions,...t},super(t),this.enabled=!0,this._state=Ba.for2d(),this.blendMode=t.blendMode,this.padding=t.padding,this.antialias=typeof t.antialias==`boolean`?t.antialias?`on`:`off`:t.antialias,this.resolution=t.resolution,this.blendRequired=t.blendRequired,this.clipToViewport=t.clipToViewport,this.addResource(`uTexture`,0,1),t.blendRequired&&this.addResource(`uBackTexture`,0,3)}apply(e,t,n,r){e.applyFilter(this,t,n,r)}get blendMode(){return this._state.blendMode}set blendMode(e){this._state.blendMode=e}static from(t){let{gpu:n,gl:r,...i}=t,a,o;return n&&(a=ya.from(n)),r&&(o=ra.from(r)),new e({gpuProgram:a,glProgram:o,...i})}};Va.defaultOptions={blendMode:`normal`,resolution:1,padding:0,antialias:`off`,blendRequired:!1,clipToViewport:!0};var Ha=Va,Ua=[];at.handleByNamedList(N.Environment,Ua);async function Wa(e){if(!e)for(let e=0;e<Ua.length;e++){let t=Ua[e];if(t.value.test()){await t.value.load();return}}}var Ga;function Ka(){if(typeof Ga==`boolean`)return Ga;try{Ga=Function(`param1`,`param2`,`param3`,`return param1[param2] === param3;`)({a:`b`},`a`,`b`)===!0}catch{Ga=!1}return Ga}var qa=new Set,Ja=!1;function Ya(e,t,n=2){let r=t&&t.length,i=r?t[0]*n:e.length;qa.size&&qa.clear();let a=Xa(e,0,i,n,!0),o=[];if(!a||a.next===a.prev)return o;let s=0,c=0,l=0;if(r&&(a=io(e,t,a,n)),e.length>80*n){s=e[0],c=e[1];let t=s,r=c;for(let a=n;a<i;a+=n){let n=e[a],i=e[a+1];n<s&&(s=n),i<c&&(c=i),n>t&&(t=n),i>r&&(r=i)}l=Math.max(t-s,r-c),l=l===0?0:32767/l}return Qa(a,o,s,c,l),o}function Xa(e,t,n,r,i){let a=null;if(i===Vo(e,t,n,r)>0)for(let i=t;i<n;i+=r)a=Ro(i/r|0,e[i],e[i+1],a);else for(let i=n-r;i>=t;i-=r)a=Ro(i/r|0,e[i],e[i+1],a);return a&&jo(a,a.next)&&(zo(a),a=a.next),a}function Za(e,t=e){let n=t===e,r=e,i;do i=!1,r!==r.next&&(qa.size===0||!qa.has(r))&&(jo(r,r.next)||H(r.prev,r,r.next)===0)?((n||r===t)&&(t=r.prev),Ja=!0,zo(r),r=r.prev,i=!0):(n||r!==t)&&(r=r.next,i=!n);while(i||r!==t);return t}function Qa(e,t,n,r,i){i&&wo(e,n,r,i);let a=e,o=!1;for(;e.prev!==e.next;){let s=e.prev,c=e.next;if(H(s,e,c)<0&&(i?eo(e,n,r,i):$a(e)))t.push(s.i,e.i,c.i),zo(e),e=c,a=c;else if(e=c,e===a){if(Ja=!1,e=Za(e),Ja){a=e;continue}if(!o){e=to(e,t),a=e,o=!0;continue}no(e,t,n,r,i);break}}}function $a(e){let t=e.prev,n=e,r=e.next,i=t.x,a=n.x,o=r.x,s=t.y,c=n.y,l=r.y,u=Math.min(i,a,o),d=Math.min(s,c,l),f=Math.max(i,a,o),p=Math.max(s,c,l),m=r.next;for(;m!==t;){if(m.x>=u&&m.x<=f&&m.y>=d&&m.y<=p&&(i!==m.x||s!==m.y)&&ko(i,s,a,c,o,l,m.x,m.y)&&H(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function eo(e,t,n,r){let i=e.prev,a=e,o=e.next,s=i.x,c=a.x,l=o.x,u=i.y,d=a.y,f=o.y,p=Math.min(s,c,l),m=Math.min(u,d,f),h=Math.max(s,c,l),g=Math.max(u,d,f),_=Do(p,m,t,n,r),v=Do(h,g,t,n,r),y=e.prevZ;for(;y&&y.z>=_;){if(y.x>=p&&y.x<=h&&y.y>=m&&y.y<=g&&y!==o&&(s!==y.x||u!==y.y)&&ko(s,u,c,d,l,f,y.x,y.y)&&H(y.prev,y,y.next)>=0)return!1;y=y.prevZ}let b=e.nextZ;for(;b&&b.z<=v;){if(b.x>=p&&b.x<=h&&b.y>=m&&b.y<=g&&b!==o&&(s!==b.x||u!==b.y)&&ko(s,u,c,d,l,f,b.x,b.y)&&H(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function to(e,t){let n=e,r=!1;do{let i=n.prev,a=n.next.next;Mo(i,n,n.next,a,!1)&&Fo(i,a)&&Fo(a,i)&&(t.push(i.i,n.i,a.i),zo(n),zo(n.next),n=e=a,r=!0),n=n.next}while(n!==e);return r?Za(n):n}function no(e,t,n,r,i){let a=e;do{let e=a.next.next;for(;e!==a.prev;){if(a.i!==e.i&&Ao(a,e)){let o=Lo(a,e);a=Za(a,a.next),o=Za(o,o.next),Qa(a,t,n,r,i),Qa(o,t,n,r,i);return}e=e.next}a=a.next}while(a!==e)}var ro=!1;function io(e,t,n,r){let i=[];for(let n=0,a=t.length;n<a;n++){let o=Xa(e,t[n]*r,n<a-1?t[n+1]*r:e.length,r,!1);o===o.next&&qa.add(o),i.push(Oo(o))}i.sort(ao),fo(e.length/r,t.length),po(n,n),ro=!0;for(let e=0;e<i.length;e++)n=oo(i[e],n);return ro=!1,Za(n)}function ao(e,t){return e.x-t.x||e.y-t.y||(e.next.y-e.y)/(e.next.x-e.x)-(t.next.y-t.y)/(t.next.x-t.x)}function oo(e,t){let n=_o(e,t);if(!n)return t;let r=Lo(n,e);return po(n,r.next.next),Za(r,r.next),Za(n,n.next)}var so=16,V=new Float64Array,co=0,lo=[],uo=[];function fo(e,t){let n=Math.ceil((e+2*t)/so)+t+2;V.length<n*4&&(V=new Float64Array(n*4)),co=0}function po(e,t){let n=e;do{let e=co++;lo[e]=n;let r=n.x,i=n.y,a=n.x,o=n.y,s=0;do{let t=n.next;n.z=e,t.x<r&&(r=t.x),t.x>a&&(a=t.x),t.y<i&&(i=t.y),t.y>o&&(o=t.y),n=t}while(++s<so&&n!==t);uo[e]=n;let c=e*4;V[c]=r,V[c+1]=i,V[c+2]=a,V[c+3]=o}while(n!==t)}function mo(e,t){let n=e.z*4;t.x<V[n]&&(V[n]=t.x),t.y<V[n+1]&&(V[n+1]=t.y),t.x>V[n+2]&&(V[n+2]=t.x),t.y>V[n+3]&&(V[n+3]=t.y)}function ho(e){let t=uo[e];for(;t.prev.next!==t;)t=t.next;return uo[e]=t,t}function go(e){let t=lo[e];for(;t.prev.next!==t;)t=t.next;return lo[e]=t,t}function _o(e,t){let n=t,r=e.x,i=e.y,a=-1/0,o;if(jo(e,n))return n;for(let t=0,s=0;t<co;t++,s+=4){if(i<V[s+1]||i>V[s+3]||V[s]>r||V[s+2]<=a)continue;let c=ho(t);n=go(t);do{if(n.prev.next===n){if(jo(e,n.next))return n.next;if(i<=n.y&&i>=n.next.y&&n.next.y!==n.y){let e=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(e<=r&&e>a&&(a=e,o=n.x<n.next.x?n:n.next,e===r))return o}}n=n.next}while(n!==c)}if(!o)return null;let s=o.x,c=o.y,l=Math.min(i,c),u=Math.max(i,c),d=1/0;for(let t=0,f=0;t<co;t++,f+=4){if(V[f+2]<s||V[f]>r||V[f+3]<l||V[f+1]>u)continue;let p=ho(t);n=go(t);do{if(n.prev.next===n&&r>=n.x&&n.x>=s&&r!==n.x&&ko(i<c?r:a,i,s,c,i<c?a:r,i,n.x,n.y)){let t=Math.abs(i-n.y)/(r-n.x);(Fo(n,e)||n.y===i&&n.next.y===i&&n.next.x>r)&&(t<d||t===d&&(n.x>o.x||n.x===o.x&&vo(o,n)))&&(o=n,d=t)}n=n.next}while(n!==p)}return o}function vo(e,t){return H(e.prev,e,t.prev)<0&&H(t.next,e,e.next)<0}var yo=[],bo=[],xo=new Uint32Array,So=new Uint32Array,Co=new Uint32Array(256);function wo(e,t,n,r){let i=e,a=0;do i.z=Do(i.x,i.y,t,n,r),yo[a++]=i,i=i.next;while(i!==e);To(a);let o=null;for(let e=0;e<a;e++){let t=yo[e];t.prevZ=o,o&&(o.nextZ=t),o=t}o.nextZ=null,yo.fill(null,0,a),bo.fill(null,0,a)}function To(e){if(e<=32)for(let t=1;t<e;t++){let e=yo[t],n=e.z,r=t-1;for(;r>=0&&yo[r].z>n;)yo[r+1]=yo[r],r--;yo[r+1]=e}else{xo.length<e&&(xo=new Uint32Array(e),So=new Uint32Array(e),bo=Array(e));for(let t=0;t<e;t++)xo[t]=yo[t].z;Eo(e,yo,xo,bo,So,0),Eo(e,bo,So,yo,xo,8),Eo(e,yo,xo,bo,So,16),Eo(e,bo,So,yo,xo,24)}}function Eo(e,t,n,r,i,a){Co.fill(0);for(let t=0;t<e;t++)Co[n[t]>>>a&255]++;let o=0;for(let e=0;e<256;e++){let t=Co[e];Co[e]=o,o+=t}for(let o=0;o<e;o++){let e=n[o],s=Co[e>>>a&255]++;r[s]=t[o],i[s]=e}}function Do(e,t,n,r,i){return e=(e-n)*i|0,t=(t-r)*i|0,e=(e|e<<8)&0xff00ff,e=(e|e<<4)&0xf0f0f0f,e=(e|e<<2)&858993459,e=(e|e<<1)&0x55555555,t=(t|t<<8)&0xff00ff,t=(t|t<<4)&0xf0f0f0f,t=(t|t<<2)&858993459,t=(t|t<<1)&0x55555555,e|t<<1}function Oo(e){let t=e,n=e;do(t.x<n.x||t.x===n.x&&t.y<n.y)&&(n=t),t=t.next;while(t!==e);return n}function ko(e,t,n,r,i,a,o,s){return(i-o)*(t-s)>=(e-o)*(a-s)&&(e-o)*(r-s)>=(n-o)*(t-s)&&(n-o)*(a-s)>=(i-o)*(r-s)}function Ao(e,t){let n=jo(e,t)&&H(e.prev,e,e.next)>0&&H(t.prev,t,t.next)>0;return e.next.i!==t.i&&(n||Fo(e,t)&&Fo(t,e)&&(H(e.prev,e,t.prev)!==0||H(e,t.prev,t)!==0))&&!Po(e,t)&&(n||Io(e,t))}function H(e,t,n){return(t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y)}function jo(e,t){return e.x===t.x&&e.y===t.y}function Mo(e,t,n,r,i=!0){let a=H(e,t,n),o=H(e,t,r),s=H(n,r,e),c=H(n,r,t);return(a>0&&o<0||a<0&&o>0)&&(s>0&&c<0||s<0&&c>0)?!0:i?!!(a===0&&No(e,n,t)||o===0&&No(e,r,t)||s===0&&No(n,e,r)||c===0&&No(n,t,r)):!1}function No(e,t,n){return t.x<=Math.max(e.x,n.x)&&t.x>=Math.min(e.x,n.x)&&t.y<=Math.max(e.y,n.y)&&t.y>=Math.min(e.y,n.y)}function Po(e,t){let n=Math.min(e.x,t.x),r=Math.max(e.x,t.x),i=Math.min(e.y,t.y),a=Math.max(e.y,t.y),o=e;do{let s=o.next;if(o.x>r&&s.x>r||o.x<n&&s.x<n||o.y>a&&s.y>a||o.y<i&&s.y<i)o=s;else{if(o.i!==e.i&&s.i!==e.i&&o.i!==t.i&&s.i!==t.i&&Mo(o,s,e,t))return!0;o=s}}while(o!==e);return!1}function Fo(e,t){return H(e.prev,e,e.next)<0?H(e,t,e.next)>=0&&H(e,e.prev,t)>=0:H(e,t,e.prev)<0||H(e,e.next,t)<0}function Io(e,t){let n=e,r=!1,i=(e.x+t.x)/2,a=(e.y+t.y)/2;do{let e=n.next;n.y>a!=e.y>a&&i<(e.x-n.x)*(a-n.y)/(e.y-n.y)+n.x&&(r=!r),n=e}while(n!==e);return r}function Lo(e,t){let n=Bo(e.i,e.x,e.y),r=Bo(t.i,t.x,t.y),i=e.next,a=t.prev;return e.next=t,t.prev=e,n.next=i,i.prev=n,r.next=n,n.prev=r,a.next=r,r.prev=a,r}function Ro(e,t,n,r){let i=Bo(e,t,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function zo(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ),ro&&mo(e.prev,e.next)}function Bo(e,t,n){return{i:e,x:t,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function Vo(e,t,n,r){let i=0;for(let a=t,o=n-r;a<n;a+=r)i+=(e[o]-e[a])*(e[a+1]+e[o+1]),o=a;return i}var Ho=Ya.default||Ya,Uo=(e=>(e[e.NONE=0]=`NONE`,e[e.COLOR=16384]=`COLOR`,e[e.STENCIL=1024]=`STENCIL`,e[e.DEPTH=256]=`DEPTH`,e[e.COLOR_DEPTH=16640]=`COLOR_DEPTH`,e[e.COLOR_STENCIL=17408]=`COLOR_STENCIL`,e[e.DEPTH_STENCIL=1280]=`DEPTH_STENCIL`,e[e.ALL=17664]=`ALL`,e))(Uo||{}),Wo=class{constructor(e){this.items=[],this._name=e}emit(e,t,n,r,i,a,o,s){let{name:c,items:l}=this;for(let u=0,d=l.length;u<d;u++)l[u][c](e,t,n,r,i,a,o,s);return this}add(e){return e[this._name]&&(this.remove(e),this.items.push(e)),this}remove(e){let t=this.items.indexOf(e);return t!==-1&&this.items.splice(t,1),this}contains(e){return this.items.indexOf(e)!==-1}removeAll(){return this.items.length=0,this}destroy(){this.removeAll(),this.items=null,this._name=null}get empty(){return this.items.length===0}get name(){return this._name}},Go=[`init`,`destroy`,`contextChange`,`resolutionChange`,`resetState`,`renderEnd`,`renderStart`,`render`,`update`,`postrender`,`prerender`],Ko=class e extends gt{constructor(e){super(),this.tick=0,this.uid=I(`renderer`),this.runners=Object.create(null),this.renderPipes=Object.create(null),this._initOptions={},this._systemsHash=Object.create(null),this.type=e.type,this.name=e.name,this.config=e;let t=[...Go,...this.config.runners??[]];this._addRunners(...t),this._unsafeEvalCheck()}async init(t={}){let n=t.skipExtensionImports===!0||t.manageImports===!1;await Wa(n),!n&&this.config.loaders&&await Promise.all(this.config.loaders.map(e=>e.value.load())),this._addSystems(this.config.systems),this._addPipes(this.config.renderPipes,this.config.renderPipeAdaptors);for(let e in this._systemsHash)t={...this._systemsHash[e].constructor.defaultOptions,...t};t={...e.defaultOptions,...t},this._roundPixels=+!!t.roundPixels;for(let e=0;e<this.runners.init.items.length;e++)await this.runners.init.items[e].init(t);this._initOptions=t}render(e,t){this.tick++;let n=e;if(n instanceof Hr&&(n={container:n},t&&(R(L,`passing a second argument is deprecated, please use render options instead`),n.target=t.renderTexture)),n.target||(n.target=this.view.renderTarget),n.target===this.view.renderTarget&&(this._lastObjectRendered=n.container,n.clearColor??(n.clearColor=this.background.colorRgba),n.clear??(n.clear=this.background.clearBeforeRender)),n.clearColor){let e=Array.isArray(n.clearColor)&&n.clearColor.length===4;n.clearColor=e?n.clearColor:Vn.shared.setValue(n.clearColor).toArray()}n.transform||(n.container.updateLocalTransform(),n.transform=n.container.localTransform),n.container.visible&&(n.container.enableRenderGroup(),this.runners.prerender.emit(n),this.runners.renderStart.emit(n),this.runners.render.emit(n),this.runners.renderEnd.emit(n),this.runners.postrender.emit(n))}resize(e,t,n){let r=this.view.resolution;this.view.resize(e,t,n),this.emit(`resize`,this.view.screen.width,this.view.screen.height,this.view.resolution),n!==void 0&&n!==r&&this.runners.resolutionChange.emit(n)}clear(e={}){let t=this;e.target||=t.renderTarget.renderTarget,e.clearColor||=this.background.colorRgba,e.clear??=Uo.ALL;let{clear:n,clearColor:r,target:i,mipLevel:a,layer:o}=e;Vn.shared.setValue(r??this.background.colorRgba),t.renderTarget.clear(i,n,Vn.shared.toArray(),a??0,o??0)}get resolution(){return this.view.resolution}set resolution(e){this.view.resolution=e,this.runners.resolutionChange.emit(e)}get width(){return this.view.texture.frame.width}get height(){return this.view.texture.frame.height}get canvas(){return this.view.canvas}get lastObjectRendered(){return this._lastObjectRendered}get renderingToScreen(){return this.renderTarget.renderingToScreen}get screen(){return this.view.screen}_addRunners(...e){e.forEach(e=>{this.runners[e]=new Wo(e)})}_addSystems(e){let t;for(t in e){let n=e[t];this._addSystem(n.value,n.name)}}_addSystem(e,t){let n=new e(this);if(this[t])throw Error(`Whoops! The name "${t}" is already in use`);this[t]=n,this._systemsHash[t]=n;for(let e in this.runners)this.runners[e].add(n);return this}_addPipes(e,t){let n=t.reduce((e,t)=>(e[t.name]=t.value,e),{});e.forEach(e=>{let t=e.value,r=e.name,i=n[r];this.renderPipes[r]=new t(this,i?new i:null),this.runners.destroy.add(this.renderPipes[r])})}destroy(e=!1){this.runners.destroy.items.reverse(),this.runners.destroy.emit(e),(e===!0||typeof e==`object`&&e.releaseGlobalResources)&&Kn.release(),Object.values(this.runners).forEach(e=>{e.destroy()}),this._systemsHash=null,this.renderPipes=null,this.removeAllListeners()}generateTexture(e){return this.textureGenerator.generateTexture(e)}get roundPixels(){return!!this._roundPixels}_unsafeEvalCheck(){if(!Ka())throw Error(`Current environment does not allow unsafe-eval, please use pixi.js/unsafe-eval module to enable support.`)}resetState(){this.runners.resetState.emit()}};Ko.defaultOptions={resolution:1,failIfMajorPerformanceCaveat:!1,roundPixels:!1};var qo=Ko,Jo;function Yo(e){return Jo===void 0&&(Jo=(()=>{let t={stencil:!0,failIfMajorPerformanceCaveat:e??qo.defaultOptions.failIfMajorPerformanceCaveat};try{if(!$r.get().getWebGLRenderingContext())return!1;let e=$r.get().createCanvas().getContext(`webgl`,t),n=!!e?.getContextAttributes()?.stencil;if(e){let t=e.getExtension(`WEBGL_lose_context`);t&&t.loseContext()}return e=null,n}catch{return!1}})()),Jo}var Xo;async function Zo(e={}){return Xo===void 0&&(Xo=await(async()=>{let t=$r.get().getNavigator().gpu;if(!t)return!1;try{return await(await t.requestAdapter(e)).requestDevice(),!0}catch{return!1}})()),Xo}var Qo=[`webgl`,`webgpu`,`canvas`];async function $o(e){let t=[];e.preference?Array.isArray(e.preference)?t=e.preference.slice():(t.push(e.preference),Qo.forEach(n=>{n!==e.preference&&t.push(n)})):t=Qo.slice();let n,r={};for(let i=0;i<t.length;i++){let a=t[i];if(a===`webgpu`&&await Zo()){let{WebGPURenderer:t}=await ft(async()=>{let{WebGPURenderer:e}=await import(`./WebGPURenderer-Ce0-U9Q1.js`);return{WebGPURenderer:e}},__vite__mapDeps([5,6,7,3]),import.meta.url);n=t,r={...e,...e.webgpu};break}if(a===`webgl`&&Yo(e.failIfMajorPerformanceCaveat??qo.defaultOptions.failIfMajorPerformanceCaveat)){let{WebGLRenderer:t}=await ft(async()=>{let{WebGLRenderer:e}=await import(`./WebGLRenderer-C0v9HBel.js`);return{WebGLRenderer:e}},__vite__mapDeps([8,6,7,3]),import.meta.url);n=t,r={...e,...e.webgl};break}if(a===`canvas`){let{CanvasRenderer:t}=await ft(async()=>{let{CanvasRenderer:e}=await import(`./CanvasRenderer-HmF-4gyW.js`);return{CanvasRenderer:e}},__vite__mapDeps([9,7,3,2]),import.meta.url);n=t,r={...e,...e.canvasOptions};break}}if(delete r.webgpu,delete r.webgl,delete r.canvasOptions,!n)throw Error(`No available renderer for the current environment`);let i=new n;return await i.init(r),i}var es=`8.23.0`,ts=class{static init(){globalThis.__PIXI_APP_INIT__?.(this,es)}static destroy(){}};ts.extension=N.Application;var ns=class{constructor(e){this._renderer=e}init(){globalThis.__PIXI_RENDERER_INIT__?.(this._renderer,es)}destroy(){this._renderer=null}};ns.extension={type:[N.WebGLSystem,N.WebGPUSystem],name:`initHook`,priority:-10};var rs=class{static init(e){Object.defineProperty(this,"resizeTo",{configurable:!0,set(e){globalThis.removeEventListener(`resize`,this.queueResize),this._resizeTo=e,e&&(globalThis.addEventListener(`resize`,this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this._cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this._cancelResize=()=>{this._resizeId&&=(cancelAnimationFrame(this._resizeId),null)},this.resize=()=>{if(!this._resizeTo)return;this._cancelResize();let e,t;if(this._resizeTo===globalThis.window)e=globalThis.innerWidth,t=globalThis.innerHeight;else{let{clientWidth:n,clientHeight:r}=this._resizeTo;e=n,t=r}this.renderer.resize(e,t),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=e.resizeTo||null}static destroy(){globalThis.removeEventListener(`resize`,this.queueResize),this._cancelResize(),this._cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}};rs.extension=N.Application;var is=class{static init(e){e=Object.assign({autoStart:!0,sharedTicker:!1},e),Object.defineProperty(this,"ticker",{configurable:!0,set(e){this._ticker&&this._ticker.remove(this.render,this),this._ticker=e,e&&e.add(this.render,this,ni.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=e.sharedTicker?ai.shared:new ai,e.autoStart&&this.start()}static destroy(){if(this._ticker){let e=this._ticker;this.ticker=null,e.destroy()}}};is.extension=N.Application,at.add(rs),at.add(is);var as=class e{constructor(...e){this.stage=new Hr,e[0]!==void 0&&R(L,`Application constructor options are deprecated, please use Application.init() instead.`)}async init(t){t={...t},this.stage||=new Hr,this.renderer=await $o(t),e._plugins.forEach(e=>{e.init.call(this,t)})}render(){this.renderer.render({container:this.stage})}get canvas(){return this.renderer.canvas}get view(){return R(L,`Application.view is deprecated, please use Application.canvas instead.`),this.renderer.canvas}get screen(){return this.renderer.screen}get domContainerRoot(){return this.renderer.renderPipes.dom?._domElement}destroy(t=!1,n=!1){let r=e._plugins.slice(0);r.reverse(),r.forEach(e=>{e.destroy.call(this)}),this.stage.destroy(n),this.stage=null,this.renderer.destroy(t),this.renderer=null}};as._plugins=[];var os=as;at.handleByList(N.Application,os._plugins),at.add(ts);var ss={a:7,c:6,h:1,l:2,m:2,q:4,s:4,t:2,v:1,z:0},cs=/([astvzqmhlc])([^astvzqmhlc]*)/gi,ls=/-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/gi;function us(e){let t=[];return e.replace(cs,(e,n,r)=>{let i=n.toLowerCase(),a=n,o=ds(r);for(i===`m`&&o.length>2&&(t.push([a,...o.splice(0,2)]),i=`l`,a=a===`m`?`l`:`L`);;){if(o.length===ss[i])return t.push([a,...o]),``;if(o.length<ss[i])throw Error(`malformed path data`);t.push([a,...o.splice(0,ss[i])])}}),t}function ds(e){let t=e.match(ls);return t?t.map(Number):[]}function fs(e,t){let n=us(e),r=[],i=null,a=0,o=0;for(let e=0;e<n.length;e++){let s=n[e],c=s[0],l=s;switch(c){case`M`:a=l[1],o=l[2],t.moveTo(a,o);break;case`m`:a+=l[1],o+=l[2],t.moveTo(a,o);break;case`H`:a=l[1],t.lineTo(a,o);break;case`h`:a+=l[1],t.lineTo(a,o);break;case`V`:o=l[1],t.lineTo(a,o);break;case`v`:o+=l[1],t.lineTo(a,o);break;case`L`:a=l[1],o=l[2],t.lineTo(a,o);break;case`l`:a+=l[1],o+=l[2],t.lineTo(a,o);break;case`C`:a=l[5],o=l[6],t.bezierCurveTo(l[1],l[2],l[3],l[4],a,o);break;case`c`:t.bezierCurveTo(a+l[1],o+l[2],a+l[3],o+l[4],a+l[5],o+l[6]),a+=l[5],o+=l[6];break;case`S`:a=l[3],o=l[4],t.bezierCurveToShort(l[1],l[2],a,o);break;case`s`:t.bezierCurveToShort(a+l[1],o+l[2],a+l[3],o+l[4]),a+=l[3],o+=l[4];break;case`Q`:a=l[3],o=l[4],t.quadraticCurveTo(l[1],l[2],a,o);break;case`q`:t.quadraticCurveTo(a+l[1],o+l[2],a+l[3],o+l[4]),a+=l[3],o+=l[4];break;case`T`:a=l[1],o=l[2],t.quadraticCurveToShort(a,o);break;case`t`:a+=l[1],o+=l[2],t.quadraticCurveToShort(a,o);break;case`A`:a=l[6],o=l[7],t.arcToSvg(l[1],l[2],l[3],l[4],l[5],a,o);break;case`a`:a+=l[6],o+=l[7],t.arcToSvg(l[1],l[2],l[3],l[4],l[5],a,o);break;case`Z`:case`z`:t.closePath(),r.length>0&&(i=r.pop(),i?(a=i.startX,o=i.startY):(a=0,o=0)),i=null;break;default:Gn(`Unknown SVG path command: ${c}`)}c!==`Z`&&c!==`z`&&i===null&&(i={startX:a,startY:o},r.push(i))}return t}var ps=class e{constructor(e=0,t=0,n=0){this.type=`circle`,this.x=e,this.y=t,this.radius=n}clone(){return new e(this.x,this.y,this.radius)}contains(e,t){if(this.radius<=0)return!1;let n=this.radius*this.radius,r=this.x-e,i=this.y-t;return r*=r,i*=i,r+i<=n}strokeContains(e,t,n,r=.5){if(this.radius===0)return!1;let i=this.x-e,a=this.y-t,o=this.radius,s=(1-r)*n,c=Math.sqrt(i*i+a*a);return c<=o+s&&c>o-(n-s)}getBounds(e){return e||=new Nt,e.x=this.x-this.radius,e.y=this.y-this.radius,e.width=this.radius*2,e.height=this.radius*2,e}copyFrom(e){return this.x=e.x,this.y=e.y,this.radius=e.radius,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:Circle x=${this.x} y=${this.y} radius=${this.radius}]`}},ms=class e{constructor(e=0,t=0,n=0,r=0){this.type=`ellipse`,this.x=e,this.y=t,this.halfWidth=n,this.halfHeight=r}clone(){return new e(this.x,this.y,this.halfWidth,this.halfHeight)}contains(e,t){if(this.halfWidth<=0||this.halfHeight<=0)return!1;let n=(e-this.x)/this.halfWidth,r=(t-this.y)/this.halfHeight;return n*=n,r*=r,n+r<=1}strokeContains(e,t,n,r=.5){let{halfWidth:i,halfHeight:a}=this;if(i<=0||a<=0)return!1;let o=n*(1-r),s=n-o,c=i-s,l=a-s,u=i+o,d=a+o,f=e-this.x,p=t-this.y;return f*f/(u*u)+p*p/(d*d)>1?!1:c<=0||l<=0||f*f/(c*c)+p*p/(l*l)>1}getBounds(e){return e||=new Nt,e.x=this.x-this.halfWidth,e.y=this.y-this.halfHeight,e.width=this.halfWidth*2,e.height=this.halfHeight*2,e}copyFrom(e){return this.x=e.x,this.y=e.y,this.halfWidth=e.halfWidth,this.halfHeight=e.halfHeight,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:Ellipse x=${this.x} y=${this.y} halfWidth=${this.halfWidth} halfHeight=${this.halfHeight}]`}};function hs(e){let t=e.length;if(t<6)return 1;let n=0;for(let r=0,i=e[t-2],a=e[t-1];r<t;r+=2){let t=e[r],o=e[r+1];n+=(t-i)*(o+a),i=t,a=o}return n<0?-1:1}function gs(e,t,n,r,i,a){let o=e-n,s=t-r,c=i-n,l=a-r,u=o*c+s*l,d=c*c+l*l,f=-1;d!==0&&(f=u/d);let p,m;f<0?(p=n,m=r):f>1?(p=i,m=a):(p=n+f*c,m=r+f*l);let h=e-p,g=t-m;return h*h+g*g}var _s,vs,ys=class e{constructor(...e){this.type=`polygon`;let t=Array.isArray(e[0])?e[0]:e;if(typeof t[0]!=`number`){let e=[];for(let n=0,r=t.length;n<r;n++)e.push(t[n].x,t[n].y);t=e}this.points=t,this.closePath=!0}isClockwise(){let e=0,t=this.points,n=t.length;for(let r=0;r<n;r+=2){let i=t[r],a=t[r+1],o=t[(r+2)%n],s=t[(r+3)%n];e+=(o-i)*(s+a)}return e<0}containsPolygon(e){let t=this.getBounds(_s),n=e.getBounds(vs);if(!t.containsRect(n))return!1;let r=e.points;for(let e=0;e<r.length;e+=2){let t=r[e],n=r[e+1];if(!this.contains(t,n))return!1}return!0}clone(){let t=this.points.slice(),n=new e(t);return n.closePath=this.closePath,n}contains(e,t){let n=!1,r=this.points.length/2;for(let i=0,a=r-1;i<r;a=i++){let r=this.points[i*2],o=this.points[i*2+1],s=this.points[a*2],c=this.points[a*2+1];o>t!=c>t&&e<(s-r)*((t-o)/(c-o))+r&&(n=!n)}return n}strokeContains(e,t,n,r=.5){let{points:i}=this,a=n*(r===.5?r:(r-.5)*hs(i)+.5),o=n-a,s=a*a,c=o*o,l=i.length-(this.closePath?0:2);for(let n=0;n<l;n+=2){let r=i[n],a=i[n+1],o=i[(n+2)%i.length],l=i[(n+3)%i.length];if(gs(e,t,r,a,o,l)<=(Math.sign((o-r)*(t-a)-(l-a)*(e-r))<0?s:c))return!0}return!1}getBounds(e){e||=new Nt;let t=this.points,n=1/0,r=-1/0,i=1/0,a=-1/0;for(let e=0,o=t.length;e<o;e+=2){let o=t[e],s=t[e+1];n=o<n?o:n,r=o>r?o:r,i=s<i?s:i,a=s>a?s:a}return e.x=n,e.width=r-n,e.y=i,e.height=a-i,e}copyFrom(e){return this.points=e.points.slice(),this.closePath=e.closePath,this}copyTo(e){return e.copyFrom(this),e}toString(){return`[pixi.js/math:PolygoncloseStroke=${this.closePath}points=${this.points.reduce((e,t)=>`${e}, ${t}`,``)}]`}get lastX(){return this.points[this.points.length-2]}get lastY(){return this.points[this.points.length-1]}get x(){return R(`8.11.0`,`Polygon.lastX is deprecated, please use Polygon.lastX instead.`),this.points[this.points.length-2]}get y(){return R(`8.11.0`,`Polygon.y is deprecated, please use Polygon.lastY instead.`),this.points[this.points.length-1]}get startX(){return this.points[0]}get startY(){return this.points[1]}},bs=(e,t,n,r,i,a,o)=>{let s=e-n,c=t-r,l=Math.sqrt(s*s+c*c);return l>=i-a&&l<=i+o},xs=class e{constructor(e=0,t=0,n=0,r=0,i=20){this.type=`roundedRectangle`,this.x=e,this.y=t,this.width=n,this.height=r,this.radius=i}getBounds(e){return e||=new Nt,e.x=this.x,e.y=this.y,e.width=this.width,e.height=this.height,e}clone(){return new e(this.x,this.y,this.width,this.height,this.radius)}copyFrom(e){return this.x=e.x,this.y=e.y,this.width=e.width,this.height=e.height,this.radius=e.radius,this}copyTo(e){return e.copyFrom(this),e}contains(e,t){if(this.width<=0||this.height<=0)return!1;if(e>=this.x&&e<=this.x+this.width&&t>=this.y&&t<=this.y+this.height){let n=Math.max(0,Math.min(this.radius,Math.min(this.width,this.height)/2));if(t>=this.y+n&&t<=this.y+this.height-n||e>=this.x+n&&e<=this.x+this.width-n)return!0;let r=e-(this.x+n),i=t-(this.y+n),a=n*n;if(r*r+i*i<=a||(r=e-(this.x+this.width-n),r*r+i*i<=a)||(i=t-(this.y+this.height-n),r*r+i*i<=a)||(r=e-(this.x+n),r*r+i*i<=a))return!0}return!1}strokeContains(e,t,n,r=.5){let{x:i,y:a,width:o,height:s}=this,c=Math.max(0,Math.min(this.radius,Math.min(o,s)/2)),l=n*(1-r),u=n-l,d=i+c,f=a+c,p=o-c*2,m=s-c*2,h=i+o,g=a+s;return(e>=i-l&&e<=i+u||e>=h-u&&e<=h+l)&&t>=f&&t<=f+m||(t>=a-l&&t<=a+u||t>=g-u&&t<=g+l)&&e>=d&&e<=d+p||e<d&&t<f&&bs(e,t,d,f,c,u,l)||e>h-c&&t<f&&bs(e,t,h-c,f,c,u,l)||e>h-c&&t>g-c&&bs(e,t,h-c,g-c,c,u,l)||e<d&&t>g-c&&bs(e,t,d,g-c,c,u,l)}toString(){return`[pixi.js/math:RoundedRectangle x=${this.x} y=${this.y}width=${this.width} height=${this.height} radius=${this.radius}]`}},Ss=class{constructor(e){this.rawBinaryData=typeof e==`number`?new ArrayBuffer(e):e instanceof Uint8Array?e.buffer:e,this.uint32View=new Uint32Array(this.rawBinaryData),this.float32View=new Float32Array(this.rawBinaryData),this.size=this.rawBinaryData.byteLength}get int8View(){return this._int8View||=new Int8Array(this.rawBinaryData),this._int8View}get uint8View(){return this._uint8View||=new Uint8Array(this.rawBinaryData),this._uint8View}get int16View(){return this._int16View||=new Int16Array(this.rawBinaryData),this._int16View}get int32View(){return this._int32View||=new Int32Array(this.rawBinaryData),this._int32View}get float64View(){return this._float64Array||=new Float64Array(this.rawBinaryData),this._float64Array}get bigUint64View(){return this._bigUint64Array||=new BigUint64Array(this.rawBinaryData),this._bigUint64Array}view(e){return this[`${e}View`]}destroy(){this.rawBinaryData=null,this.uint32View=null,this.float32View=null,this.uint16View=null,this._int8View=null,this._uint8View=null,this._int16View=null,this._int32View=null,this._float64Array=null,this._bigUint64Array=null}static sizeOf(e){switch(e){case`int8`:case`uint8`:return 1;case`int16`:case`uint16`:return 2;case`int32`:case`uint32`:case`float32`:return 4;default:throw Error(`${e} isn't a valid view type`)}}};function Cs(e,t,n,r){if(n??=0,r??=Math.min(e.byteLength-n,t.byteLength),!(n&7)&&!(r&7)){let i=r/8;new Float64Array(t,0,i).set(new Float64Array(e,n,i))}else if(!(n&3)&&!(r&3)){let i=r/4;new Float32Array(t,0,i).set(new Float32Array(e,n,i))}else new Uint8Array(t).set(new Uint8Array(e,n,r))}var ws={normal:`normal-npm`,add:`add-npm`,screen:`screen-npm`},Ts=(e=>(e[e.DISABLED=0]=`DISABLED`,e[e.RENDERING_MASK_ADD=1]=`RENDERING_MASK_ADD`,e[e.MASK_ACTIVE=2]=`MASK_ACTIVE`,e[e.INVERSE_MASK_ACTIVE=3]=`INVERSE_MASK_ACTIVE`,e[e.RENDERING_MASK_REMOVE=4]=`RENDERING_MASK_REMOVE`,e[e.NONE=5]=`NONE`,e))(Ts||{});function Es(e,t){return t.alphaMode===`no-premultiply-alpha`&&ws[e]||e}var Ds=`precision mediump float;
|
|
25
|
+
void main(void){
|
|
26
|
+
float test = 0.1;
|
|
27
|
+
%forloop%
|
|
28
|
+
gl_FragColor = vec4(0.0);
|
|
29
|
+
}`;function Os(e){let t=``;for(let n=0;n<e;++n)n>0&&(t+=`
|
|
30
|
+
else `),n<e-1&&(t+=`if(test == ${n}.0){}`);return t}function ks(e,t){if(e===0)throw Error("Invalid value of `0` passed to `checkMaxIfStatementsInShader`");let n=t.createShader(t.FRAGMENT_SHADER);try{for(;;){let r=Ds.replace(/%forloop%/gi,Os(e));if(t.shaderSource(n,r),t.compileShader(n),!t.getShaderParameter(n,t.COMPILE_STATUS))e=e/2|0;else break}}finally{t.deleteShader(n)}return e}var As=null;function js(){if(As)return As;let e=Bi();return As=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),As=ks(As,e),e.getExtension(`WEBGL_lose_context`)?.loseContext(),As}var Ms=class{constructor(){this.ids=Object.create(null),this.textures=[],this.count=0}clear(){for(let e=0;e<this.count;e++){let t=this.textures[e];this.textures[e]=null,this.ids[t.uid]=null}this.count=0}},Ns=class{constructor(){this.renderPipeId=`batch`,this.action=`startBatch`,this.start=0,this.size=0,this.textures=new Ms,this.blendMode=`normal`,this.topology=`triangle-strip`,this.canBundle=!0}destroy(){this.textures=null,this.gpuBindGroup=null,this.bindGroup=null,this.batcher=null,this.elements=null}},Ps=[],Fs=0;Kn.register({clear:()=>{if(Ps.length>0)for(let e of Ps)e&&e.destroy();Ps.length=0,Fs=0}});function Is(){return Fs>0?Ps[--Fs]:new Ns}function Ls(e){e.elements=null,Ps[Fs++]=e}var Rs=0,zs=class e{constructor(t){this.uid=I(`batcher`),this.dirty=!0,this.batchIndex=0,this.batches=[],this._elements=[],t={...e.defaultOptions,...t},t.maxTextures||(R(`v8.8.0`,`maxTextures is a required option for Batcher now, please pass it in the options`),t.maxTextures=js());let{maxTextures:n,attributesInitialSize:r,indicesInitialSize:i}=t;this.attributeBuffer=new Ss(r*4),this.indexBuffer=new Uint16Array(i),this.maxTextures=n}begin(){this.elementSize=0,this.elementStart=0,this.indexSize=0,this.attributeSize=0;for(let e=0;e<this.batchIndex;e++)Ls(this.batches[e]);this.batchIndex=0,this._batchIndexStart=0,this._batchIndexSize=0,this.dirty=!0}add(e){this._elements[this.elementSize++]=e,e._indexStart=this.indexSize,e._attributeStart=this.attributeSize,e._batcher=this,this.indexSize+=e.indexSize,this.attributeSize+=e.attributeSize*this.vertexSize}checkAndUpdateTexture(e,t){let n=e._batch.textures.ids[t._source.uid];return!n&&n!==0?!1:(e._textureId=n,e.texture=t,!0)}updateElement(e){this.dirty=!0;let t=this.attributeBuffer;e.packAsQuad?this.packQuadAttributes(e,t.float32View,t.uint32View,e._attributeStart,e._textureId):this.packAttributes(e,t.float32View,t.uint32View,e._attributeStart,e._textureId)}break(e){let t=this._elements;if(!t[this.elementStart])return;let n=Is(),r=n.textures;r.clear();let i=t[this.elementStart],a=Es(i.blendMode,i.texture._source),o=i.topology;this.attributeSize*4>this.attributeBuffer.size&&this._resizeAttributeBuffer(this.attributeSize*4),this.indexSize>this.indexBuffer.length&&this._resizeIndexBuffer(this.indexSize);let s=this.attributeBuffer.float32View,c=this.attributeBuffer.uint32View,l=this.indexBuffer,u=this._batchIndexSize,d=this._batchIndexStart,f=`startBatch`,p=[],m=this.maxTextures;for(let i=this.elementStart;i<this.elementSize;++i){let h=t[i];t[i]=null;let g=h.texture._source,_=Es(h.blendMode,g),v=a!==_||o!==h.topology;g._batchTick===Rs&&!v?(h._textureId=g._textureBindLocation,u+=h.indexSize,h.packAsQuad?(this.packQuadAttributes(h,s,c,h._attributeStart,h._textureId),this.packQuadIndex(l,h._indexStart,h._attributeStart/this.vertexSize)):(this.packAttributes(h,s,c,h._attributeStart,h._textureId),this.packIndex(h,l,h._indexStart,h._attributeStart/this.vertexSize)),h._batch=n,p.push(h)):((r.count>=m||v)&&(this._finishBatch(n,d,u-d,r,a,o,e,f,p),f=`renderBatch`,d=u,a=_,o=h.topology,n=Is(),r=n.textures,r.clear(),p=[],++Rs),g._batchTick=Rs,h._textureId=g._textureBindLocation=r.count,r.ids[g.uid]=r.count,r.textures[r.count++]=g,h._batch=n,p.push(h),u+=h.indexSize,h.packAsQuad?(this.packQuadAttributes(h,s,c,h._attributeStart,h._textureId),this.packQuadIndex(l,h._indexStart,h._attributeStart/this.vertexSize)):(this.packAttributes(h,s,c,h._attributeStart,h._textureId),this.packIndex(h,l,h._indexStart,h._attributeStart/this.vertexSize)))}r.count>0&&(this._finishBatch(n,d,u-d,r,a,o,e,f,p),d=u,++Rs),this.elementStart=this.elementSize,this._batchIndexStart=d,this._batchIndexSize=u}_finishBatch(e,t,n,r,i,a,o,s,c){e.gpuBindGroup=null,e.bindGroup=null,e.action=s,e.batcher=this,e.textures=r,e.blendMode=i,e.topology=a,e.start=t,e.size=n,e.elements=c,++Rs,this.batches[this.batchIndex++]=e,o.add(e)}finish(e){this.break(e)}ensureAttributeBuffer(e){e*4<=this.attributeBuffer.size||this._resizeAttributeBuffer(e*4)}ensureIndexBuffer(e){e<=this.indexBuffer.length||this._resizeIndexBuffer(e)}_resizeAttributeBuffer(e){let t=new Ss(Math.max(e,this.attributeBuffer.size*2));Cs(this.attributeBuffer.rawBinaryData,t.rawBinaryData),this.attributeBuffer=t}_resizeIndexBuffer(e){let t=this.indexBuffer,n=Math.max(e,t.length*1.5);n+=n%2;let r=n>65535?new Uint32Array(n):new Uint16Array(n);if(r.BYTES_PER_ELEMENT!==t.BYTES_PER_ELEMENT)for(let e=0;e<t.length;e++)r[e]=t[e];else Cs(t.buffer,r.buffer);this.indexBuffer=r}packQuadIndex(e,t,n){e[t]=n+0,e[t+1]=n+1,e[t+2]=n+2,e[t+3]=n+0,e[t+4]=n+2,e[t+5]=n+3}packIndex(e,t,n,r){let i=e.indices,a=e.indexSize,o=e.indexOffset,s=e.attributeOffset;for(let e=0;e<a;e++)t[n++]=r+i[e+o]-s}destroy(e={}){if(this.batches!==null){for(let e=0;e<this.batchIndex;e++)Ls(this.batches[e]);this.batches=null,this.geometry.destroy(!0),this.geometry=null,e.shader&&(this.shader?.destroy(),this.shader=null);for(let e=0;e<this._elements.length;e++)this._elements[e]&&(this._elements[e]._batch=null);this._elements=null,this.indexBuffer=null,this.attributeBuffer.destroy(),this.attributeBuffer=null}}};zs.defaultOptions={maxTextures:null,attributesInitialSize:4,indicesInitialSize:6};var Bs=zs,Vs=(e=>(e[e.MAP_READ=1]=`MAP_READ`,e[e.MAP_WRITE=2]=`MAP_WRITE`,e[e.COPY_SRC=4]=`COPY_SRC`,e[e.COPY_DST=8]=`COPY_DST`,e[e.INDEX=16]=`INDEX`,e[e.VERTEX=32]=`VERTEX`,e[e.UNIFORM=64]=`UNIFORM`,e[e.STORAGE=128]=`STORAGE`,e[e.INDIRECT=256]=`INDIRECT`,e[e.QUERY_RESOLVE=512]=`QUERY_RESOLVE`,e[e.STATIC=1024]=`STATIC`,e))(Vs||{}),Hs=class extends gt{constructor(e){let{data:t,size:n}=e,{usage:r,label:i,shrinkToFit:a}=e;super(),this._gpuData=Object.create(null),this._gcLastUsed=-1,this.autoGarbageCollect=!0,this.uid=I(`buffer`),this._resourceType=`buffer`,this._resourceId=I(`resource`),this._updateID=1,this._updateOffset=0,this._dataInt32=null,this.shrinkToFit=!0,this.destroyed=!1,t instanceof Array&&(t=new Float32Array(t)),this._data=t,n??=t?.byteLength;let o=!!t;this.descriptor={size:n,usage:r,mappedAtCreation:o,label:i},this.shrinkToFit=a??!0}get data(){return this._data}set data(e){this.setDataWithSize(e,e.length,!0)}get dataInt32(){return this._dataInt32||=new Int32Array(this.data.buffer),this._dataInt32}get static(){return!!(this.descriptor.usage&Vs.STATIC)}set static(e){e?this.descriptor.usage|=Vs.STATIC:this.descriptor.usage&=~Vs.STATIC}setDataWithSize(e,t,n){if(this._updateID++,this._updateSize=t*e.BYTES_PER_ELEMENT,this._updateOffset=0,this._data===e){n&&this.emit(`update`,this);return}let r=this._data;this._data=e,this._dataInt32=null,!r||r.length!==e.length?!this.shrinkToFit&&r&&e.byteLength<r.byteLength?n&&this.emit(`update`,this):(this.descriptor.size=e.byteLength,this._resourceId=I(`resource`),this.emit(`change`,this)):n&&this.emit(`update`,this)}update(e,t){this._updateSize=e,this._updateOffset=t||0,this._updateID++,this.emit(`update`,this)}unload(){this.emit(`unload`,this);for(let e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null),this.destroyed||(this._resourceId=I(`resource`),this.emit(`change`,this))}destroy(){this.destroyed=!0,this.unload(),this.emit(`destroy`,this),this.emit(`change`,this),this._data=null,this.descriptor=null,this.removeAllListeners()}};function Us(e,t){if(!(e instanceof Hs)){let n=t?Vs.INDEX:Vs.VERTEX;e instanceof Array&&(t?(e=new Uint32Array(e),n=Vs.INDEX|Vs.COPY_DST):(e=new Float32Array(e),n=Vs.VERTEX|Vs.COPY_DST)),e=new Hs({data:e,label:t?`index-mesh-buffer`:`vertex-mesh-buffer`,usage:n})}return e}function Ws(e,t,n){let r=e.getAttribute(t);if(!r)return n.minX=0,n.minY=0,n.maxX=0,n.maxY=0,n;let i=r.buffer.data,a=1/0,o=1/0,s=-1/0,c=-1/0,l=i.BYTES_PER_ELEMENT,u=(r.offset||0)/l,d=(r.stride||8)/l;for(let e=u;e<i.length;e+=d){let t=i[e],n=i[e+1];t>s&&(s=t),n>c&&(c=n),t<a&&(a=t),n<o&&(o=n)}return n.minX=a,n.minY=o,n.maxX=s,n.maxY=c,n}function Gs(e){return(e instanceof Hs||Array.isArray(e)||e.BYTES_PER_ELEMENT)&&(e={buffer:e}),e.buffer=Us(e.buffer,!1),e}var Ks=class extends gt{constructor(e={}){super(),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=I(`geometry`),this._layoutKey=0,this.instanceCount=1,this.indexCount=0,this._bounds=new an,this._boundsDirty=!0,this._vertexCount=0,this._vertexCountDirty=!0;let{attributes:t,indexBuffer:n,topology:r}=e;if(this.buffers=[],this.attributes={},t)for(let e in t)this.addAttribute(e,t[e]);this.instanceCount=e.instanceCount??1,this.indexCount=e.indexCount??0,n&&this.addIndex(n),this.topology=r||`triangle-list`}onBufferUpdate(){this._boundsDirty=!0,this._vertexCountDirty=!0,this.emit(`update`,this)}getAttribute(e){return this.attributes[e]}getIndex(){return this.indexBuffer}getBuffer(e){return this.getAttribute(e).buffer}get vertexCount(){if(!this._vertexCountDirty)return this._vertexCount;this._vertexCountDirty=!1;let e=this.attributes;for(let t in e){let n=e[t];if(n.instance)continue;let r=n.buffer;return this._vertexCount=r.data.length/(n.stride/4||n.size),this._vertexCount}return this._vertexCount=0,0}getSize(){return R(`8.20.0`,`Geometry.getSize is deprecated, please use Geometry.vertexCount instead.`),this.vertexCount}addAttribute(e,t){let n=Gs(t);this.buffers.indexOf(n.buffer)===-1&&(this.buffers.push(n.buffer),n.buffer.on(`update`,this.onBufferUpdate,this),n.buffer.on(`change`,this.onBufferUpdate,this)),this.attributes[e]=n,this._vertexCountDirty=!0}addIndex(e){this.indexBuffer=Us(e,!0),this.buffers.push(this.indexBuffer)}get bounds(){return this._boundsDirty?(this._boundsDirty=!1,Ws(this,`aPosition`,this._bounds)):this._bounds}unload(){this.emit(`unload`,this);for(let e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null)}destroy(e=!1){this.emit(`destroy`,this);for(let t of this.buffers)t.off(`update`,this.onBufferUpdate,this),t.off(`change`,this.onBufferUpdate,this),e&&t.destroy();this.unload(),this.removeAllListeners(),this.attributes=null,this.buffers=null,this.indexBuffer=null,this._bounds=null}},qs=new Float32Array(1),Js=new Uint32Array(1),Ys=class extends Ks{constructor(){let e=new Hs({data:qs,label:`attribute-batch-buffer`,usage:Vs.VERTEX|Vs.COPY_DST,shrinkToFit:!1}),t=new Hs({data:Js,label:`index-batch-buffer`,usage:Vs.INDEX|Vs.COPY_DST,shrinkToFit:!1});super({attributes:{aPosition:{buffer:e,format:`float32x2`,stride:24,offset:0},aUV:{buffer:e,format:`float32x2`,stride:24,offset:8},aColor:{buffer:e,format:`unorm8x4`,stride:24,offset:16},aTextureIdAndRound:{buffer:e,format:`uint16x2`,stride:24,offset:20}},indexBuffer:t})}};function Xs(e,t,n){if(e)for(let r in e){let i=t[r.toLocaleLowerCase()];if(i){let t=e[r];r===`header`&&(t=t.replace(/@in\s+[^;]+;\s*/g,``).replace(/@out\s+[^;]+;\s*/g,``)),n&&i.push(`//----${n}----//`),i.push(t)}else Gn(`${r} placement hook does not exist in shader`)}}var Zs=/\{\{(.*?)\}\}/g;function Qs(e){let t={};return(e.match(Zs)?.map(e=>e.replace(/[{()}]/g,``))??[]).forEach(e=>{t[e]=[]}),t}function $s(e,t){let n,r=/@in\s+([^;]+);/g;for(;(n=r.exec(e))!==null;)t.push(n[1])}function ec(e,t,n=!1){let r=[];$s(t,r),e.forEach(e=>{e.header&&$s(e.header,r)});let i=r;n&&i.sort();let a=i.map((e,t)=>` @location(${t}) ${e},`).join(`
|
|
31
|
+
`),o=t.replace(/@in\s+[^;]+;\s*/g,``);return o=o.replace(`{{in}}`,`
|
|
32
|
+
${a}
|
|
33
|
+
`),o}function tc(e,t){let n,r=/@out\s+([^;]+);/g;for(;(n=r.exec(e))!==null;)t.push(n[1])}function nc(e){let t=/\b(\w+)\s*:/g.exec(e);return t?t[1]:``}function rc(e){return e.replace(/@.*?\s+/g,``)}function ic(e,t){let n=[];tc(t,n),e.forEach(e=>{e.header&&tc(e.header,n)});let r=0,i=n.sort().map(e=>e.indexOf(`builtin`)>-1?e:`@location(${r++}) ${e}`).join(`,
|
|
34
|
+
`),a=n.sort().map(e=>` var ${rc(e)};`).join(`
|
|
35
|
+
`),o=`return VSOutput(
|
|
36
|
+
${n.sort().map(e=>` ${nc(e)}`).join(`,
|
|
37
|
+
`)});`,s=t.replace(/@out\s+[^;]+;\s*/g,``);return s=s.replace(`{{struct}}`,`
|
|
38
|
+
${i}
|
|
39
|
+
`),s=s.replace(`{{start}}`,`
|
|
40
|
+
${a}
|
|
41
|
+
`),s=s.replace(`{{return}}`,`
|
|
42
|
+
${o}
|
|
43
|
+
`),s}function ac(e,t){let n=e;for(let e in t){let r=t[e];n=r.join(`
|
|
44
|
+
`).length?n.replace(`{{${e}}}`,`//-----${e} START-----//
|
|
45
|
+
${r.join(`
|
|
46
|
+
`)}
|
|
47
|
+
//----${e} FINISH----//`):n.replace(`{{${e}}}`,``)}return n}var oc=Object.create(null),sc=new Map,cc=0;function lc({template:e,bits:t}){let n=fc(e,t);if(oc[n])return oc[n];let{vertex:r,fragment:i}=dc(e,t);return oc[n]=pc(r,i,t),oc[n]}function uc({template:e,bits:t}){let n=fc(e,t);return oc[n]||(oc[n]=pc(e.vertex,e.fragment,t)),oc[n]}function dc(e,t){let n=t.map(e=>e.vertex).filter(e=>!!e),r=t.map(e=>e.fragment).filter(e=>!!e),i=ec(n,e.vertex,!0);i=ic(n,i);let a=ec(r,e.fragment,!0);return{vertex:i,fragment:a}}function fc(e,t){return t.map(e=>(sc.has(e)||sc.set(e,cc++),sc.get(e))).sort((e,t)=>e-t).join(`-`)+e.vertex+e.fragment}function pc(e,t,n){let r=Qs(e),i=Qs(t);return n.forEach(e=>{Xs(e.vertex,r,e.name),Xs(e.fragment,i,e.name)}),{vertex:ac(e,r),fragment:ac(t,i)}}var mc=`
|
|
48
|
+
@in aPosition: vec2<f32>;
|
|
49
|
+
@in aUV: vec2<f32>;
|
|
50
|
+
|
|
51
|
+
@out @builtin(position) vPosition: vec4<f32>;
|
|
52
|
+
@out vUV : vec2<f32>;
|
|
53
|
+
@out vColor : vec4<f32>;
|
|
54
|
+
|
|
55
|
+
{{header}}
|
|
56
|
+
|
|
57
|
+
struct VSOutput {
|
|
58
|
+
{{struct}}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
@vertex
|
|
62
|
+
fn main( {{in}} ) -> VSOutput {
|
|
63
|
+
|
|
64
|
+
var worldTransformMatrix = globalUniforms.uWorldTransformMatrix;
|
|
65
|
+
var modelMatrix = mat3x3<f32>(
|
|
66
|
+
1.0, 0.0, 0.0,
|
|
67
|
+
0.0, 1.0, 0.0,
|
|
68
|
+
0.0, 0.0, 1.0
|
|
69
|
+
);
|
|
70
|
+
var position = aPosition;
|
|
71
|
+
var uv = aUV;
|
|
72
|
+
|
|
73
|
+
{{start}}
|
|
74
|
+
|
|
75
|
+
vColor = vec4<f32>(1., 1., 1., 1.);
|
|
76
|
+
|
|
77
|
+
{{main}}
|
|
78
|
+
|
|
79
|
+
vUV = uv;
|
|
80
|
+
|
|
81
|
+
var modelViewProjectionMatrix = globalUniforms.uProjectionMatrix * worldTransformMatrix * modelMatrix;
|
|
82
|
+
|
|
83
|
+
vPosition = vec4<f32>((modelViewProjectionMatrix * vec3<f32>(position, 1.0)).xy, 0.0, 1.0);
|
|
84
|
+
|
|
85
|
+
vColor *= globalUniforms.uWorldColorAlpha;
|
|
86
|
+
|
|
87
|
+
{{end}}
|
|
88
|
+
|
|
89
|
+
{{return}}
|
|
90
|
+
};
|
|
91
|
+
`,hc=`
|
|
92
|
+
@in vUV : vec2<f32>;
|
|
93
|
+
@in vColor : vec4<f32>;
|
|
94
|
+
|
|
95
|
+
{{header}}
|
|
96
|
+
|
|
97
|
+
@fragment
|
|
98
|
+
fn main(
|
|
99
|
+
{{in}}
|
|
100
|
+
) -> @location(0) vec4<f32> {
|
|
101
|
+
|
|
102
|
+
{{start}}
|
|
103
|
+
|
|
104
|
+
var outColor:vec4<f32>;
|
|
105
|
+
|
|
106
|
+
{{main}}
|
|
107
|
+
|
|
108
|
+
var finalColor:vec4<f32> = outColor * vColor;
|
|
109
|
+
|
|
110
|
+
{{end}}
|
|
111
|
+
|
|
112
|
+
return finalColor;
|
|
113
|
+
};
|
|
114
|
+
`,gc=`
|
|
115
|
+
in vec2 aPosition;
|
|
116
|
+
in vec2 aUV;
|
|
117
|
+
|
|
118
|
+
out vec4 vColor;
|
|
119
|
+
out vec2 vUV;
|
|
120
|
+
|
|
121
|
+
{{header}}
|
|
122
|
+
|
|
123
|
+
void main(void){
|
|
124
|
+
|
|
125
|
+
mat3 worldTransformMatrix = uWorldTransformMatrix;
|
|
126
|
+
mat3 modelMatrix = mat3(
|
|
127
|
+
1.0, 0.0, 0.0,
|
|
128
|
+
0.0, 1.0, 0.0,
|
|
129
|
+
0.0, 0.0, 1.0
|
|
130
|
+
);
|
|
131
|
+
vec2 position = aPosition;
|
|
132
|
+
vec2 uv = aUV;
|
|
133
|
+
|
|
134
|
+
{{start}}
|
|
135
|
+
|
|
136
|
+
vColor = vec4(1.);
|
|
137
|
+
|
|
138
|
+
{{main}}
|
|
139
|
+
|
|
140
|
+
vUV = uv;
|
|
141
|
+
|
|
142
|
+
mat3 modelViewProjectionMatrix = uProjectionMatrix * worldTransformMatrix * modelMatrix;
|
|
143
|
+
|
|
144
|
+
gl_Position = vec4((modelViewProjectionMatrix * vec3(position, 1.0)).xy, 0.0, 1.0);
|
|
145
|
+
|
|
146
|
+
vColor *= uWorldColorAlpha;
|
|
147
|
+
|
|
148
|
+
{{end}}
|
|
149
|
+
}
|
|
150
|
+
`,_c=`
|
|
151
|
+
|
|
152
|
+
in vec4 vColor;
|
|
153
|
+
in vec2 vUV;
|
|
154
|
+
|
|
155
|
+
out vec4 finalColor;
|
|
156
|
+
|
|
157
|
+
{{header}}
|
|
158
|
+
|
|
159
|
+
void main(void) {
|
|
160
|
+
|
|
161
|
+
{{start}}
|
|
162
|
+
|
|
163
|
+
vec4 outColor;
|
|
164
|
+
|
|
165
|
+
{{main}}
|
|
166
|
+
|
|
167
|
+
finalColor = outColor * vColor;
|
|
168
|
+
|
|
169
|
+
{{end}}
|
|
170
|
+
}
|
|
171
|
+
`,vc={name:`global-uniforms-bit`,vertex:{header:`
|
|
172
|
+
struct GlobalUniforms {
|
|
173
|
+
uProjectionMatrix:mat3x3<f32>,
|
|
174
|
+
uWorldTransformMatrix:mat3x3<f32>,
|
|
175
|
+
uWorldColorAlpha: vec4<f32>,
|
|
176
|
+
uResolution: vec2<f32>,
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
@group(0) @binding(0) var<uniform> globalUniforms : GlobalUniforms;
|
|
180
|
+
`}},yc={name:`global-uniforms-bit`,vertex:{header:`
|
|
181
|
+
uniform mat3 uProjectionMatrix;
|
|
182
|
+
uniform mat3 uWorldTransformMatrix;
|
|
183
|
+
uniform vec4 uWorldColorAlpha;
|
|
184
|
+
uniform vec2 uResolution;
|
|
185
|
+
`}};function bc({bits:e,name:t}){let n=lc({template:{fragment:hc,vertex:mc},bits:[vc,...e]});return ya.from({name:t,vertex:{source:n.vertex,entryPoint:`main`},fragment:{source:n.fragment,entryPoint:`main`}})}function xc({bits:e,name:t}){return new ra({name:t,...uc({template:{vertex:gc,fragment:_c},bits:[yc,...e]})})}var Sc={name:`color-bit`,vertex:{header:`
|
|
186
|
+
@in aColor: vec4<f32>;
|
|
187
|
+
`,main:`
|
|
188
|
+
vColor *= vec4<f32>(aColor.rgb * aColor.a, aColor.a);
|
|
189
|
+
`}},Cc={name:`color-bit`,vertex:{header:`
|
|
190
|
+
in vec4 aColor;
|
|
191
|
+
`,main:`
|
|
192
|
+
vColor *= vec4(aColor.rgb * aColor.a, aColor.a);
|
|
193
|
+
`}},wc={};function Tc(e){let t=[];if(e===1)t.push(`@group(1) @binding(0) var textureSource1: texture_2d<f32>;`),t.push(`@group(1) @binding(1) var textureSampler1: sampler;`);else{let n=0;for(let r=0;r<e;r++)t.push(`@group(1) @binding(${n++}) var textureSource${r+1}: texture_2d<f32>;`),t.push(`@group(1) @binding(${n++}) var textureSampler${r+1}: sampler;`)}return t.join(`
|
|
194
|
+
`)}function Ec(e){let t=[];if(e===1)t.push(`outColor = textureSampleGrad(textureSource1, textureSampler1, vUV, uvDx, uvDy);`);else{t.push(`switch vTextureId {`);for(let n=0;n<e;n++)n===e-1?t.push(` default:{`):t.push(` case ${n}:{`),t.push(` outColor = textureSampleGrad(textureSource${n+1}, textureSampler${n+1}, vUV, uvDx, uvDy);`),t.push(` break;}`);t.push(`}`)}return t.join(`
|
|
195
|
+
`)}function Dc(e){return wc[e]||(wc[e]={name:`texture-batch-bit`,vertex:{header:`
|
|
196
|
+
@in aTextureIdAndRound: vec2<u32>;
|
|
197
|
+
@out @interpolate(flat) vTextureId : u32;
|
|
198
|
+
`,main:`
|
|
199
|
+
vTextureId = aTextureIdAndRound.y;
|
|
200
|
+
`,end:`
|
|
201
|
+
if(aTextureIdAndRound.x == 1)
|
|
202
|
+
{
|
|
203
|
+
vPosition = vec4<f32>(roundPixels(vPosition.xy, globalUniforms.uResolution), vPosition.zw);
|
|
204
|
+
}
|
|
205
|
+
`},fragment:{header:`
|
|
206
|
+
@in @interpolate(flat) vTextureId: u32;
|
|
207
|
+
|
|
208
|
+
${Tc(e)}
|
|
209
|
+
`,main:`
|
|
210
|
+
var uvDx = dpdx(vUV);
|
|
211
|
+
var uvDy = dpdy(vUV);
|
|
212
|
+
|
|
213
|
+
${Ec(e)}
|
|
214
|
+
`}}),wc[e]}var Oc={};function kc(e){let t=[];for(let n=0;n<e;n++)n>0&&t.push(`else`),n<e-1&&t.push(`if(vTextureId < ${n}.5)`),t.push(`{`),t.push(` outColor = texture(uTextures[${n}], vUV);`),t.push(`}`);return t.join(`
|
|
215
|
+
`)}function Ac(e){return Oc[e]||(Oc[e]={name:`texture-batch-bit`,vertex:{header:`
|
|
216
|
+
in vec2 aTextureIdAndRound;
|
|
217
|
+
out float vTextureId;
|
|
218
|
+
|
|
219
|
+
`,main:`
|
|
220
|
+
vTextureId = aTextureIdAndRound.y;
|
|
221
|
+
`,end:`
|
|
222
|
+
if(aTextureIdAndRound.x == 1.)
|
|
223
|
+
{
|
|
224
|
+
gl_Position.xy = roundPixels(gl_Position.xy, uResolution);
|
|
225
|
+
}
|
|
226
|
+
`},fragment:{header:`
|
|
227
|
+
in float vTextureId;
|
|
228
|
+
|
|
229
|
+
uniform sampler2D uTextures[${e}];
|
|
230
|
+
|
|
231
|
+
`,main:`
|
|
232
|
+
|
|
233
|
+
${kc(e)}
|
|
234
|
+
`}}),Oc[e]}var jc={name:`round-pixels-bit`,vertex:{header:`
|
|
235
|
+
fn roundPixels(position: vec2<f32>, targetSize: vec2<f32>) -> vec2<f32>
|
|
236
|
+
{
|
|
237
|
+
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
238
|
+
}
|
|
239
|
+
`}},Mc={name:`round-pixels-bit`,vertex:{header:`
|
|
240
|
+
vec2 roundPixels(vec2 position, vec2 targetSize)
|
|
241
|
+
{
|
|
242
|
+
return (floor(((position * 0.5 + 0.5) * targetSize) + 0.5) / targetSize) * 2.0 - 1.0;
|
|
243
|
+
}
|
|
244
|
+
`}},Nc={};function Pc(e){let t=Nc[e];if(t)return t;let n=new Int32Array(e);for(let t=0;t<e;t++)n[t]=t;return t=Nc[e]=new wa({uTextures:{value:n,type:`i32`,size:e}},{isStatic:!0}),t}var Fc=class extends Aa{constructor(e){let t=xc({name:`batch`,bits:[Cc,Ac(e),Mc]}),n=bc({name:`batch`,bits:[Sc,Dc(e),jc]});super({glProgram:t,gpuProgram:n,resources:{batchSamplers:Pc(e)}}),this.maxTextures=e}},Ic=null,Lc=class e extends Bs{constructor(t){super(t),this.geometry=new Ys,this.name=e.extension.name,this.vertexSize=6,Ic??=new Fc(t.maxTextures),this.shader=Ic}packAttributes(e,t,n,r,i){let a=i<<16|e.roundPixels&65535,o=e.transform,s=o.a,c=o.b,l=o.c,u=o.d,d=o.tx,f=o.ty,{positions:p,uvs:m}=e,h=e.color,g=e.attributeOffset,_=g+e.attributeSize;for(let e=g;e<_;e++){let i=e*2,o=p[i],g=p[i+1];t[r++]=s*o+l*g+d,t[r++]=u*g+c*o+f,t[r++]=m[i],t[r++]=m[i+1],n[r++]=h,n[r++]=a}}packQuadAttributes(e,t,n,r,i){let a=e.texture,o=e.transform,s=o.a,c=o.b,l=o.c,u=o.d,d=o.tx,f=o.ty,p=e.bounds,m=p.maxX,h=p.minX,g=p.maxY,_=p.minY,v=a.uvs,y=e.color,b=i<<16|e.roundPixels&65535;t[r+0]=s*h+l*_+d,t[r+1]=u*_+c*h+f,t[r+2]=v.x0,t[r+3]=v.y0,n[r+4]=y,n[r+5]=b,t[r+6]=s*m+l*_+d,t[r+7]=u*_+c*m+f,t[r+8]=v.x1,t[r+9]=v.y1,n[r+10]=y,n[r+11]=b,t[r+12]=s*m+l*g+d,t[r+13]=u*g+c*m+f,t[r+14]=v.x2,t[r+15]=v.y2,n[r+16]=y,n[r+17]=b,t[r+18]=s*h+l*g+d,t[r+19]=u*g+c*h+f,t[r+20]=v.x3,t[r+21]=v.y3,n[r+22]=y,n[r+23]=b}_updateMaxTextures(e){this.shader.maxTextures!==e&&(Ic=new Fc(e),this.shader=Ic)}destroy(){this.shader=null,super.destroy()}};Lc.extension={type:[N.Batcher],name:`default`};var Rc=Lc,zc={};function Bc(e,t,n){let r=0x811c9dc5;for(let n=0;n<t;n++)r^=e[n].uid,r=Math.imul(r,16777619),r>>>=0;return zc[r]||Vc(e,t,r,n)}function Vc(e,t,n,r){let i={},a=0;for(let n=0;n<r;n++){let r=n<t?e[n]:z.EMPTY.source;i[a++]=r.source,i[a++]=r.style}let o=new Da(i);return zc[n]=o,o}var Hc=class{constructor(e){this.items=Object.create(null);let{renderer:t,type:n,onUnload:r,priority:i,name:a}=e;this._renderer=t,t.gc.addResourceHash(this,`items`,n,i??0),this._onUnload=r,this.name=a}add(e){return!this.items[e.uid]&&(this.items[e.uid]=e,e.once(`unload`,this.remove,this),e._gcLastUsed=this._renderer.gc.now,!0)}remove(e,...t){if(!this.items[e.uid])return;let n=e._gpuData[this._renderer.uid];n&&(this._onUnload?.(e,...t),e.off(`unload`,this.remove,this),n.destroy(),e._gpuData[this._renderer.uid]=null,this.items[e.uid]=null)}removeAll(...e){Object.values(this.items).forEach(t=>t&&this.remove(t,...e))}destroy(...e){this.removeAll(...e),this.items=Object.create(null),this._renderer=null,this._onUnload=null}},Uc=class{constructor(){this.instructions=new wr}init(e){let t=e.maxTextures;this.batcher?this.batcher._updateMaxTextures(t):this.batcher=this._createBatcher(t),this.instructions.reset()}destroy(){this.batcher.destroy(),this.instructions.destroy(),this.batcher=null,this.instructions=null}},Wc=class{constructor(){this.batches=[]}reset(){this.batches&&this.batches.forEach(e=>{Jn.return(e)}),this.graphicsData&&Jn.return(this.graphicsData),this.isBatchable=!1,this.context=null,this.batches.length=0,this.graphicsData=null}destroy(){this.reset(),this.batches=null}},Gc=class{constructor(e,t){this._renderer=e,this._managedContexts=new Hc({renderer:e,type:`resource`,name:t})}getContextRenderData(e){return this._getGpuData(e).graphicsData||this._initContextRenderData(e)}updateGpuContext(e){let t=!!this._getGpuData(e),n=this._getGpuData(e)||this._initContext(e);if(e.dirty||!t){t&&(n.reset(),n.context=e),this._buildContextData(e,n);let r=e.batchMode;n.isBatchable=e.customShader||r===`no-batch`?!1:r!==`auto`||this._getGeometrySize(n).attributes<400,e.dirty=!1}return n}getGpuContext(e){return this._getGpuData(e)||this._initContext(e)}_getGpuData(e){return e._gpuData[this._renderer.uid]}_initContextRenderData(e){let t=this._renderer.limits.maxBatchableTextures,n=this._getGpuData(e),r=this._getRenderData(t,n),{batches:i}=n;n.graphicsData=r;let{attributes:a,indices:o}=this._getGeometrySize(n);for(let e=0;e<i.length;e++)i[e].applyTransform=!1;let s=r.batcher;s.ensureAttributeBuffer(a),s.ensureIndexBuffer(o),s.begin();for(let e=0;e<i.length;e++)s.add(i[e]);s.finish(r.instructions);let c=s.geometry;c.indexBuffer.setDataWithSize(s.indexBuffer,s.indexSize,!0),c.buffers[0].setDataWithSize(s.attributeBuffer.float32View,s.attributeSize,!0);let l=s.batches;for(let e=0;e<s.batchIndex;e++){let n=l[e];n.bindGroup=Bc(n.textures.textures,n.textures.count,t)}return r}_initContext(e){let t=this._createGpuContext();return t.context=e,e._gpuData[this._renderer.uid]=t,this._managedContexts.add(e),t}destroy(){this._managedContexts.destroy(),this._renderer=null}};function Kc(e,t,n,r,i,a,o,s=null){let c=0;n*=t,i*=a;let l=s.a,u=s.b,d=s.c,f=s.d,p=s.tx,m=s.ty;for(;c<o;){let o=e[n],s=e[n+1];r[i]=l*o+d*s+p,r[i+1]=u*o+f*s+m,i+=a,n+=t,c++}}function qc(e,t,n,r){let i=0;for(t*=n;i<r;)e[t]=0,e[t+1]=0,t+=n,i++}function Jc(e,t,n,r,i){let a=t.a,o=t.b,s=t.c,c=t.d,l=t.tx,u=t.ty;n||=0,r||=2,i||=e.length/r-n;let d=n*r;for(let t=0;t<i;t++){let t=e[d],n=e[d+1];e[d]=a*t+s*n+l,e[d+1]=o*t+c*n+u,d+=r}}var Yc=new P,Xc=class{constructor(){this.packAsQuad=!1,this.topology=`triangle-list`,this.applyTransform=!0,this.roundPixels=0,this._batcher=null,this._batch=null}get blendMode(){return this.renderable&&this.applyTransform?this.renderable.groupBlendMode:`normal`}get color(){let e=this.baseColor,t=e>>16|e&65280|(e&255)<<16,n=this.renderable;return n?ur(t,n.groupColor)+(this.alpha*n.groupAlpha*255<<24):t+(this.alpha*255<<24)}get transform(){return this.renderable?.groupTransform||Yc}reset(){this.applyTransform=!0,this.renderable=null,this.topology=`triangle-list`}destroy(){this.renderable=null,this.texture=null,this._batcher=null,this._batch=null}},Zc=class extends Xc{constructor(){super(...arguments),this.batcherName=`default`}get uvs(){return this.geometryData.uvs}get positions(){return this.geometryData.vertices}get indices(){return this.geometryData.indices}copyTo(e){e.indexOffset=this.indexOffset,e.indexSize=this.indexSize,e.attributeOffset=this.attributeOffset,e.attributeSize=this.attributeSize,e.baseColor=this.baseColor,e.alpha=this.alpha,e.texture=this.texture,e.geometryData=this.geometryData,e.topology=this.topology}destroy(){super.destroy(),this.geometryData=null}},Qc={extension:{type:N.ShapeBuilder,name:`circle`},build(e,t){let n,r,i,a,o,s;if(e.type===`circle`){let t=e;if(o=s=t.radius,o<=0)return!1;n=t.x,r=t.y,i=a=0}else if(e.type===`ellipse`){let t=e;if(o=t.halfWidth,s=t.halfHeight,o<=0||s<=0)return!1;n=t.x,r=t.y,i=a=0}else{let t=e,c=t.width/2,l=t.height/2;n=t.x+c,r=t.y+l,o=s=Math.max(0,Math.min(t.radius,Math.min(c,l))),i=c-o,a=l-s}if(i<0||a<0)return!1;let c=Math.ceil(2.3*Math.sqrt(o+s)),l=c*8+(i?4:0)+(a?4:0);if(l===0)return!1;if(c===0)return t[0]=t[6]=n+i,t[1]=t[3]=r+a,t[2]=t[4]=n-i,t[5]=t[7]=r-a,!0;let u=0,d=c*4+(i?2:0)+2,f=d,p=l,m=i+o,h=a,g=n+m,_=n-m,v=r+h;if(t[u++]=g,t[u++]=v,t[--d]=v,t[--d]=_,a){let e=r-h;t[f++]=_,t[f++]=e,t[--p]=e,t[--p]=g}for(let e=1;e<c;e++){let l=Math.PI/2*(e/c),m=i+Math.cos(l)*o,h=a+Math.sin(l)*s,g=n+m,_=n-m,v=r+h,y=r-h;t[u++]=g,t[u++]=v,t[--d]=v,t[--d]=_,t[f++]=_,t[f++]=y,t[--p]=y,t[--p]=g}m=i,h=a+s,g=n+m,_=n-m,v=r+h;let y=r-h;return t[u++]=g,t[u++]=v,t[--p]=y,t[--p]=g,i&&(t[u++]=_,t[u++]=v,t[--p]=y,t[--p]=_),!0},triangulate(e,t,n,r,i,a){if(e.length===0)return;let o=0,s=0;for(let t=0;t<e.length;t+=2)o+=e[t],s+=e[t+1];o/=e.length/2,s/=e.length/2;let c=r;t[c*n]=o,t[c*n+1]=s;let l=c++;for(let r=0;r<e.length;r+=2)t[c*n]=e[r],t[c*n+1]=e[r+1],r>0&&(i[a++]=c,i[a++]=l,i[a++]=c-1),c++;i[a++]=l+1,i[a++]=l,i[a++]=c-1}},$c={...Qc,extension:{...Qc.extension,name:`ellipse`}},el={...Qc,extension:{...Qc.extension,name:`roundedRectangle`}},tl=1e-4,nl=1e-4;function rl(e,t,n,r,i,a,o,s){let c=e-n*i,l=t-r*i,u=e+n*a,d=t+r*a,f,p;o?(f=r,p=-n):(f=-r,p=n);let m=c+f,h=l+p,g=u+f,_=d+p;return s.push(m,h),s.push(g,_),2}function il(e,t,n,r,i,a,o,s){let c=n-e,l=r-t,u=Math.atan2(c,l),d=Math.atan2(i-e,a-t);s&&u<d?u+=Math.PI*2:!s&&u>d&&(d+=Math.PI*2);let f=u,p=d-u,m=Math.abs(p),h=Math.sqrt(c*c+l*l),g=(15*m*Math.sqrt(h)/Math.PI|0)+1,_=p/g;if(f+=_,s){o.push(e,t),o.push(n,r);for(let n=1,r=f;n<g;n++,r+=_)o.push(e,t),o.push(e+Math.sin(r)*h,t+Math.cos(r)*h);o.push(e,t),o.push(i,a)}else{o.push(n,r),o.push(e,t);for(let n=1,r=f;n<g;n++,r+=_)o.push(e+Math.sin(r)*h,t+Math.cos(r)*h),o.push(e,t);o.push(i,a),o.push(e,t)}return g*2}function al(e,t,n,r,i,a){let o=tl;if(e.length===0)return;let s=t,c=s.alignment;if(t.alignment!==.5){let t=hs(e);n&&(t*=-1),c=(c-.5)*t+.5}let l=new bt(e[0],e[1]),u=new bt(e[e.length-2],e[e.length-1]),d=r,f=Math.abs(l.x-u.x)<o&&Math.abs(l.y-u.y)<o;if(d){e=e.slice(),f&&(e.pop(),e.pop(),u.set(e[e.length-2],e[e.length-1]));let t=(l.x+u.x)*.5,n=(u.y+l.y)*.5;e.unshift(t,n),e.push(t,n)}let p=i,m=e.length/2,h=e.length,g=p.length/2,_=s.width/2,v=_*_,y=s.miterLimit*s.miterLimit,b=e[0],x=e[1],S=e[2],C=e[3],w=0,T=0,E=-(x-C),D=b-S,O=0,k=0,ee=Math.sqrt(E*E+D*D);E/=ee,D/=ee,E*=_,D*=_;let te=c,A=(1-te)*2,j=te*2;d||(s.cap===`round`?h+=il(b-E*(A-j)*.5,x-D*(A-j)*.5,b-E*A,x-D*A,b+E*j,x+D*j,p,!0)+2:s.cap===`square`&&(h+=rl(b,x,E,D,A,j,!0,p))),p.push(b-E*A,x-D*A),p.push(b+E*j,x+D*j);for(let t=1;t<m-1;++t){b=e[(t-1)*2],x=e[(t-1)*2+1],S=e[t*2],C=e[t*2+1],w=e[(t+1)*2],T=e[(t+1)*2+1],E=-(x-C),D=b-S,ee=Math.sqrt(E*E+D*D),E/=ee,D/=ee,E*=_,D*=_,O=-(C-T),k=S-w,ee=Math.sqrt(O*O+k*k),O/=ee,k/=ee,O*=_,k*=_;let n=S-b,r=x-C,i=S-w,a=T-C,o=n*i+r*a,c=r*i-a*n,l=c<0;if(Math.abs(c)<.001*Math.abs(o)){p.push(S-E*A,C-D*A),p.push(S+E*j,C+D*j),o>=0&&(s.join===`round`?h+=il(S,C,S-E*A,C-D*A,S-O*A,C-k*A,p,!1)+4:h+=2,p.push(S-O*j,C-k*j),p.push(S+O*A,C+k*A));continue}let u=(-E+b)*(-D+C)-(-E+S)*(-D+x),d=(-O+w)*(-k+C)-(-O+S)*(-k+T),f=(n*d-i*u)/c,m=(a*u-r*d)/c,g=(f-S)*(f-S)+(m-C)*(m-C),te=S+(f-S)*A,ne=C+(m-C)*A,re=S-(f-S)*j,ie=C-(m-C)*j,ae=Math.min(n*n+r*r,i*i+a*a),oe=l?A:j;g<=ae+oe*oe*v?s.join===`bevel`||g/v>y?(l?(p.push(te,ne),p.push(S+E*j,C+D*j),p.push(te,ne),p.push(S+O*j,C+k*j)):(p.push(S-E*A,C-D*A),p.push(re,ie),p.push(S-O*A,C-k*A),p.push(re,ie)),h+=2):s.join===`round`?l?(p.push(te,ne),p.push(S+E*j,C+D*j),h+=il(S,C,S+E*j,C+D*j,S+O*j,C+k*j,p,!0)+4,p.push(te,ne),p.push(S+O*j,C+k*j)):(p.push(S-E*A,C-D*A),p.push(re,ie),h+=il(S,C,S-E*A,C-D*A,S-O*A,C-k*A,p,!1)+4,p.push(S-O*A,C-k*A),p.push(re,ie)):(p.push(te,ne),p.push(re,ie)):(p.push(S-E*A,C-D*A),p.push(S+E*j,C+D*j),s.join===`round`?h+=l?il(S,C,S+E*j,C+D*j,S+O*j,C+k*j,p,!0)+2:il(S,C,S-E*A,C-D*A,S-O*A,C-k*A,p,!1)+2:s.join===`miter`&&g/v<=y&&(l?(p.push(re,ie),p.push(re,ie)):(p.push(te,ne),p.push(te,ne)),h+=2),p.push(S-O*A,C-k*A),p.push(S+O*j,C+k*j),h+=2)}b=e[(m-2)*2],x=e[(m-2)*2+1],S=e[(m-1)*2],C=e[(m-1)*2+1],E=-(x-C),D=b-S,ee=Math.sqrt(E*E+D*D),E/=ee,D/=ee,E*=_,D*=_,p.push(S-E*A,C-D*A),p.push(S+E*j,C+D*j),d||(s.cap===`round`?h+=il(S-E*(A-j)*.5,C-D*(A-j)*.5,S-E*A,C-D*A,S+E*j,C+D*j,p,!1)+2:s.cap===`square`&&(h+=rl(S,C,E,D,A,j,!1,p)));let ne=nl*nl;for(let e=g;e<h+g-2;++e)b=p[e*2],x=p[e*2+1],S=p[(e+1)*2],C=p[(e+1)*2+1],w=p[(e+2)*2],T=p[(e+2)*2+1],Math.abs(b*(C-T)+S*(T-x)+w*(x-C))<ne||a.push(e,e+1,e+2)}function ol(e,t,n,r){let i=tl;if(e.length===0)return;let a=e[0],o=e[1],s=e[e.length-2],c=e[e.length-1],l=t||Math.abs(a-s)<i&&Math.abs(o-c)<i,u=n,d=e.length/2,f=u.length/2;for(let t=0;t<d;t++)u.push(e[t*2]),u.push(e[t*2+1]);for(let e=0;e<d-1;e++)r.push(f+e,f+e+1);l&&r.push(f+d-1,f)}function sl(e,t,n,r,i,a,o){let s=Ho(e,t,2);if(!s)return;for(let e=0;e<s.length;e+=3)a[o++]=s[e]+i,a[o++]=s[e+1]+i,a[o++]=s[e+2]+i;let c=i*r;for(let t=0;t<e.length;t+=2)n[c]=e[t],n[c+1]=e[t+1],c+=r}var cl=[],ll={extension:{type:N.ShapeBuilder,name:`polygon`},build(e,t){for(let n=0;n<e.points.length;n++)t[n]=e.points[n];return!0},triangulate(e,t,n,r,i,a){sl(e,cl,t,n,r,i,a)}},ul={extension:{type:N.ShapeBuilder,name:`rectangle`},build(e,t){let n=e,r=n.x,i=n.y,a=n.width,o=n.height;return a>0&&o>0&&(t[0]=r,t[1]=i,t[2]=r+a,t[3]=i,t[4]=r+a,t[5]=i+o,t[6]=r,t[7]=i+o,!0)},triangulate(e,t,n,r,i,a){let o=0;r*=n,t[r+o]=e[0],t[r+o+1]=e[1],o+=n,t[r+o]=e[2],t[r+o+1]=e[3],o+=n,t[r+o]=e[6],t[r+o+1]=e[7],o+=n,t[r+o]=e[4],t[r+o+1]=e[5],o+=n;let s=r/n;i[a++]=s,i[a++]=s+1,i[a++]=s+2,i[a++]=s+1,i[a++]=s+3,i[a++]=s+2}},dl={extension:{type:N.ShapeBuilder,name:`triangle`},build(e,t){return t[0]=e.x,t[1]=e.y,t[2]=e.x2,t[3]=e.y2,t[4]=e.x3,t[5]=e.y3,!0},triangulate(e,t,n,r,i,a){let o=0;r*=n,t[r+o]=e[0],t[r+o+1]=e[1],o+=n,t[r+o]=e[2],t[r+o+1]=e[3],o+=n,t[r+o]=e[4],t[r+o+1]=e[5];let s=r/n;i[a++]=s,i[a++]=s+1,i[a++]=s+2}},fl=[{offset:0,color:`white`},{offset:1,color:`black`}],pl=class e{constructor(...t){this.uid=I(`fillGradient`),this._tick=0,this.type=`linear`,this.colorStops=[];let n=_l(t);n={...n.type===`radial`?e.defaultRadialOptions:e.defaultLinearOptions,...Wt(n)},this._textureSize=n.textureSize,this._wrapMode=n.wrapMode,n.type===`radial`?(this.center=n.center,this.outerCenter=n.outerCenter??this.center,this.innerRadius=n.innerRadius,this.outerRadius=n.outerRadius,this.scale=n.scale,this.rotation=n.rotation):(this.start=n.start,this.end=n.end),this.textureSpace=n.textureSpace,this.type=n.type,n.colorStops.forEach(e=>{this.addColorStop(e.offset,e.color)})}addColorStop(e,t){return this.colorStops.push({offset:e,color:Vn.shared.setValue(t).toHexa()}),this}buildLinearGradient(){if(this.texture)return;let{x:e,y:t}=this.start,{x:n,y:r}=this.end,i=n-e,a=r-t,o=i<0||a<0;if(this._wrapMode===`clamp-to-edge`){if(i<0){let t=e;e=n,n=t,i*=-1}if(a<0){let e=t;t=r,r=e,a*=-1}}let s=this.colorStops.length?this.colorStops:fl,c=this._textureSize,{canvas:l,context:u}=gl(c,1),d=o?u.createLinearGradient(this._textureSize,0,0,0):u.createLinearGradient(0,0,this._textureSize,0);hl(d,s),u.fillStyle=d,u.fillRect(0,0,c,1),this.texture=new z({source:new ti({resource:l,addressMode:this._wrapMode})});let f=Math.sqrt(i*i+a*a),p=Math.atan2(a,i),m=new P;m.scale(f/c,1),m.rotate(p),m.translate(e,t),this.textureSpace===`local`&&m.scale(c,c),this.transform=m}buildGradient(){this.texture||this._tick++,this.type===`linear`?this.buildLinearGradient():this.buildRadialGradient()}buildRadialGradient(){if(this.texture)return;let e=this.colorStops.length?this.colorStops:fl,t=this._textureSize,{canvas:n,context:r}=gl(t,t),{x:i,y:a}=this.center,{x:o,y:s}=this.outerCenter,c=this.innerRadius,l=this.outerRadius,u=o-l,d=s-l,f=t/(l*2),p=(i-u)*f,m=(a-d)*f,h=r.createRadialGradient(p,m,c*f,(o-u)*f,(s-d)*f,l*f);hl(h,e),r.fillStyle=e[e.length-1].color,r.fillRect(0,0,t,t),r.fillStyle=h,r.translate(p,m),r.rotate(this.rotation),r.scale(1,this.scale),r.translate(-p,-m),r.fillRect(0,0,t,t),this.texture=new z({source:new ti({resource:n,addressMode:this._wrapMode})});let g=new P;this.textureSpace===`local`?g.scale(2*l,2*l):g.scale(1/f,1/f),g.translate(u,d),this.transform=g}destroy(){this.texture?.destroy(!0),this.texture=null,this.transform=null,this.colorStops=[],this.start=null,this.end=null,this.center=null,this.outerCenter=null}get styleKey(){return`fill-gradient-${this.uid}-${this._tick}`}};pl.defaultLinearOptions={start:{x:0,y:0},end:{x:0,y:1},colorStops:[],textureSpace:`local`,type:`linear`,textureSize:256,wrapMode:`clamp-to-edge`},pl.defaultRadialOptions={center:{x:.5,y:.5},innerRadius:0,outerRadius:.5,colorStops:[],scale:1,rotation:0,textureSpace:`local`,type:`radial`,textureSize:256,wrapMode:`clamp-to-edge`};var ml=pl;function hl(e,t){for(let n=0;n<t.length;n++){let r=t[n];e.addColorStop(r.offset,r.color)}}function gl(e,t){let n=$r.get().createCanvas(e,t);return{canvas:n,context:n.getContext(`2d`)}}function _l(e){let t=e[0]??{};return(typeof t==`number`||e[1])&&(R(`8.5.2`,`use options object instead`),t={type:`linear`,start:{x:e[0],y:e[1]},end:{x:e[2],y:e[3]},textureSpace:e[4],textureSize:e[5]??ml.defaultLinearOptions.textureSize}),t}var vl=new P,yl=new Nt,bl=new P;function xl(e,t,n,r){let i=t.matrix?e.copyFrom(t.matrix).invert():e.identity();if(t.textureSpace===`local`){let e=n.getBounds(yl);t.width&&e.pad(t.width);let{x:r,y:a}=e,o=1/e.width,s=1/e.height,c=-r*o,l=-a*s,u=i.a,d=i.b,f=i.c,p=i.d;i.a*=o,i.b*=o,i.c*=s,i.d*=s,i.tx=c*u+l*f+i.tx,i.ty=c*d+l*p+i.ty}else if(t.texture.rotate){let{uvs:e,orig:n}=t.texture;i.scale(1/n.width,1/n.height),i.prepend(bl.set(e.x1-e.x0,e.y1-e.y0,e.x3-e.x0,e.y3-e.y0,e.x0,e.y0))}else i.translate(t.texture.frame.x,t.texture.frame.y),i.scale(1/t.texture.source.width,1/t.texture.source.height);let a=t.texture.source.style;return!(t.fill instanceof ml)&&a.addressMode===`clamp-to-edge`&&(a.addressMode=`repeat`,a.update()),r&&i.append(vl.copyFrom(r).invert()),i}var Sl={};at.handleByMap(N.ShapeBuilder,Sl),at.add(ul,ll,dl,Qc,$c,el);var Cl=new Nt,wl=new P;function Tl(e,t){let{geometryData:n,batches:r}=t;r.length=0,n.indices.length=0,n.vertices.length=0,n.uvs.length=0;for(let t=0;t<e.instructions.length;t++){let i=e.instructions[t];if(i.action===`texture`)El(i.data,r,n);else if(i.action===`fill`||i.action===`stroke`){let e=i.action===`stroke`,t=i.data.path.shapePath,a=i.data.style,o=i.data.hole;e&&o&&Dl(o.shapePath,a,!0,r,n),o&&(t.shapePrimitives[t.shapePrimitives.length-1].holes=o.shapePath.shapePrimitives),Dl(t,a,e,r,n)}}}function El(e,t,n){let r=[],i=Sl.rectangle,a=Cl;a.x=e.dx,a.y=e.dy,a.width=e.dw,a.height=e.dh;let o=e.transform;if(!i.build(a,r))return;let{vertices:s,uvs:c,indices:l}=n,u=l.length,d=s.length/2;o&&Jc(r,o),i.triangulate(r,s,2,d,l,u);let f=e.image,p=f.uvs;c.push(p.x0,p.y0,p.x1,p.y1,p.x3,p.y3,p.x2,p.y2);let m=Jn.get(Zc);m.indexOffset=u,m.indexSize=l.length-u,m.attributeOffset=d,m.attributeSize=s.length/2-d,m.baseColor=e.style,m.alpha=e.alpha,m.texture=f,m.geometryData=n,t.push(m)}function Dl(e,t,n,r,i){let{vertices:a,uvs:o,indices:s}=i;e.shapePrimitives.forEach(({shape:e,transform:c,holes:l})=>{let u=[],d=Sl[e.type];if(!d.build(e,u))return;let f=s.length,p=a.length/2,m=`triangle-list`;if(c&&Jc(u,c),n){let n=e.closePath??!0,r=t;r.pixelLine?(ol(u,n,a,s),m=`line-list`):al(u,r,!1,n,a,s)}else if(l){let e=[],t=u.slice();Ol(l).forEach(n=>{e.push(t.length/2),t.push(...n)}),sl(t,e,a,2,p,s,f)}else d.triangulate(u,a,2,p,s,f);let h=o.length/2,g=t.texture;if(g!==z.WHITE){let n=xl(wl,t,e,c);Kc(a,2,p,o,h,2,a.length/2-p,n)}else qc(o,h,2,a.length/2-p);let _=Jn.get(Zc);_.indexOffset=f,_.indexSize=s.length-f,_.attributeOffset=p,_.attributeSize=a.length/2-p,_.baseColor=t.color,_.alpha=t.alpha,_.texture=g,_.geometryData=i,_.topology=m,r.push(_)})}function Ol(e){let t=[];for(let n=0;n<e.length;n++){let r=e[n].shape,i=[];Sl[r.type].build(r,i)&&t.push(i)}return t}var kl=class extends Wc{constructor(){super(...arguments),this.geometryData={vertices:[],uvs:[],indices:[]}}reset(){super.reset(),this.geometryData.indices.length=0,this.geometryData.vertices.length=0,this.geometryData.uvs.length=0}destroy(){super.destroy(),this.geometryData=null}},Al=class extends Uc{get geometry(){return R(It,`GraphicsContextRenderData#geometry is deprecated, please use batcher.geometry instead.`),this.batcher.geometry}_createBatcher(e){return new Rc({maxTextures:e})}},jl=class e extends Gc{constructor(e){super(e,`graphicsContext`)}init(t){e.defaultOptions.bezierSmoothness=t?.bezierSmoothness??e.defaultOptions.bezierSmoothness}_createGpuContext(){return new kl}_buildContextData(e,t){Tl(e,t)}_getGeometrySize(e){let{vertices:t,indices:n}=e.geometryData;return{attributes:t.length,indices:n.length}}_getRenderData(e){return Jn.get(Al,{maxTextures:e})}};jl.extension={type:[N.WebGLSystem,N.WebGPUSystem],name:`graphicsContext`},jl.defaultOptions={bezierSmoothness:.5};var Ml=jl,Nl=8,Pl=1.1920929e-7,Fl=1;function Il(e,t,n,r,i,a,o,s,c,l){let u=(Fl-Math.min(.99,Math.max(0,l??Ml.defaultOptions.bezierSmoothness)))/1;return u*=u,Ll(t,n,r,i,a,o,s,c,e,u),e}function Ll(e,t,n,r,i,a,o,s,c,l){Rl(e,t,n,r,i,a,o,s,c,l,0),c.push(o,s)}function Rl(e,t,n,r,i,a,o,s,c,l,u){if(u>Nl)return;let d=(e+n)/2,f=(t+r)/2,p=(n+i)/2,m=(r+a)/2,h=(i+o)/2,g=(a+s)/2,_=(d+p)/2,v=(f+m)/2,y=(p+h)/2,b=(m+g)/2,x=(_+y)/2,S=(v+b)/2;if(u>0){let u=o-e,d=s-t,f=Math.abs((n-o)*d-(r-s)*u),p=Math.abs((i-o)*d-(a-s)*u);if(f>Pl&&p>Pl){if((f+p)*(f+p)<=l*(u*u+d*d)){c.push(x,S);return}}else if(f>Pl){if(f*f<=l*(u*u+d*d)){c.push(x,S);return}}else if(p>Pl){if(p*p<=l*(u*u+d*d)){c.push(x,S);return}}else if(u=x-(e+o)/2,d=S-(t+s)/2,u*u+d*d<=l){c.push(x,S);return}}Rl(e,t,d,f,_,v,x,S,c,l,u+1),Rl(x,S,y,b,h,g,o,s,c,l,u+1)}var zl=8,Bl=1.1920929e-7,Vl=1;function Hl(e,t,n,r,i,a,o,s){let c=(Vl-Math.min(.99,Math.max(0,s??Ml.defaultOptions.bezierSmoothness)))/1;return c*=c,Ul(t,n,r,i,a,o,e,c),e}function Ul(e,t,n,r,i,a,o,s){Wl(o,e,t,n,r,i,a,s,0),o.push(i,a)}function Wl(e,t,n,r,i,a,o,s,c){if(c>zl)return;let l=(t+r)/2,u=(n+i)/2,d=(r+a)/2,f=(i+o)/2,p=(l+d)/2,m=(u+f)/2,h=a-t,g=o-n,_=Math.abs((r-a)*g-(i-o)*h);if(_>Bl){if(_*_<=s*(h*h+g*g)){e.push(p,m);return}}else if(h=p-(t+a)/2,g=m-(n+o)/2,h*h+g*g<=s){e.push(p,m);return}Wl(e,t,n,l,u,p,m,s,c+1),Wl(e,p,m,d,f,a,o,s,c+1)}function Gl(e,t,n,r,i,a,o,s){let c=Math.abs(i-a);(!o&&i>a||o&&a>i)&&(c=2*Math.PI-c),s||=Math.max(6,Math.floor(6*r**(1/3)*(c/Math.PI))),s=Math.max(s,3);let l=c/s,u=i;l*=o?-1:1;for(let i=0;i<s+1;i++){let i=Math.cos(u),a=Math.sin(u),o=t+i*r,s=n+a*r;e.push(o,s),u+=l}}function Kl(e,t,n,r,i,a){let o=e[e.length-2],s=e[e.length-1]-n,c=o-t,l=i-n,u=r-t,d=Math.abs(s*u-c*l);if(d<1e-8||a===0){(e[e.length-2]!==t||e[e.length-1]!==n)&&e.push(t,n);return}let f=s*s+c*c,p=l*l+u*u,m=s*l+c*u,h=a*Math.sqrt(f)/d,g=a*Math.sqrt(p)/d,_=h*m/f,v=g*m/p,y=h*u+g*c,b=h*l+g*s,x=c*(g+_),S=s*(g+_),C=u*(h+v),w=l*(h+v),T=Math.atan2(S-b,x-y),E=Math.atan2(w-b,C-y);Gl(e,y+t,b+n,a,T,E,c*l>u*s)}var ql=Math.PI*2,Jl={centerX:0,centerY:0,ang1:0,ang2:0},Yl=({x:e,y:t},n,r,i,a,o,s,c)=>{e*=n,t*=r;let l=i*e-a*t,u=a*e+i*t;return c.x=l+o,c.y=u+s,c};function Xl(e,t){let n=t===-1.5707963267948966?-.551915024494:4/3*Math.tan(t/4),r=t===1.5707963267948966?.551915024494:n,i=Math.cos(e),a=Math.sin(e),o=Math.cos(e+t),s=Math.sin(e+t);return[{x:i-a*r,y:a+i*r},{x:o+s*r,y:s-o*r},{x:o,y:s}]}var Zl=(e,t,n,r)=>{let i=e*r-t*n<0?-1:1,a=e*n+t*r;return a>1&&(a=1),a<-1&&(a=-1),i*Math.acos(a)},Ql=(e,t,n,r,i,a,o,s,c,l,u,d,f)=>{let p=i**2,m=a**2,h=u**2,g=d**2,_=p*m-p*g-m*h;_<0&&(_=0),_/=p*g+m*h,_=Math.sqrt(_)*(o===s?-1:1);let v=_*i/a*d,y=_*-a/i*u,b=l*v-c*y+(e+n)/2,x=c*v+l*y+(t+r)/2,S=(u-v)/i,C=(d-y)/a,w=(-u-v)/i,T=(-d-y)/a,E=Zl(1,0,S,C),D=Zl(S,C,w,T);s===0&&D>0&&(D-=ql),s===1&&D<0&&(D+=ql),f.centerX=b,f.centerY=x,f.ang1=E,f.ang2=D};function $l(e,t,n,r,i,a,o,s=0,c=0,l=0){if(a===0||o===0)return;let u=Math.sin(s*ql/360),d=Math.cos(s*ql/360),f=d*(t-r)/2+u*(n-i)/2,p=-u*(t-r)/2+d*(n-i)/2;if(f===0&&p===0)return;a=Math.abs(a),o=Math.abs(o);let m=f**2/a**2+p**2/o**2;m>1&&(a*=Math.sqrt(m),o*=Math.sqrt(m)),Ql(t,n,r,i,a,o,c,l,u,d,f,p,Jl);let{ang1:h,ang2:g}=Jl,{centerX:_,centerY:v}=Jl,y=Math.abs(g)/(ql/4);Math.abs(1-y)<1e-7&&(y=1);let b=Math.max(Math.ceil(y),1);g/=b;let x=e[e.length-2],S=e[e.length-1],C={x:0,y:0};for(let t=0;t<b;t++){let t=Xl(h,g),{x:n,y:r}=Yl(t[0],a,o,d,u,_,v,C),{x:i,y:s}=Yl(t[1],a,o,d,u,_,v,C),{x:c,y:l}=Yl(t[2],a,o,d,u,_,v,C);Il(e,x,S,n,r,i,s,c,l),x=c,S=l,h+=g}}function eu(e,t,n){let r=(e,t)=>{let n=t.x-e.x,r=t.y-e.y,i=Math.sqrt(n*n+r*r);return{len:i,nx:n/i,ny:r/i}},i=(t,n)=>{t===0?e.moveTo(n.x,n.y):e.lineTo(n.x,n.y)},a=t[t.length-1];for(let o=0;o<t.length;o++){let s=t[o%t.length],c=s.radius??n;if(c<=0){i(o,s),a=s;continue}let l=t[(o+1)%t.length],u=r(s,a),d=r(s,l);if(u.len<1e-4||d.len<1e-4){i(o,s),a=s;continue}let f=Math.asin(u.nx*d.ny-u.ny*d.nx),p=1,m=!1;u.nx*d.nx-u.ny*-d.ny<0?f<0?f=Math.PI+f:(f=Math.PI-f,p=-1,m=!0):f>0&&(p=-1,m=!0);let h=f/2,g,_=Math.abs(Math.cos(h)*c/Math.sin(h));_>Math.min(u.len/2,d.len/2)?(_=Math.min(u.len/2,d.len/2),g=Math.abs(_*Math.sin(h)/Math.cos(h))):g=c;let v=s.x+d.nx*_+-d.ny*g*p,y=s.y+d.ny*_+d.nx*g*p,b=Math.atan2(u.ny,u.nx)+Math.PI/2*p,x=Math.atan2(d.ny,d.nx)-Math.PI/2*p;o===0&&e.moveTo(v+Math.cos(b)*g,y+Math.sin(b)*g),e.arc(v,y,g,b,x,m),a=s}}function tu(e,t,n,r){let i=(e,t)=>Math.sqrt((e.x-t.x)**2+(e.y-t.y)**2),a=(e,t,n)=>({x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n}),o=t.length;for(let s=0;s<o;s++){let c=t[(s+1)%o],l=c.radius??n;if(l<=0){s===0?e.moveTo(c.x,c.y):e.lineTo(c.x,c.y);continue}let u=t[s],d=t[(s+2)%o],f=i(u,c),p;p=f<1e-4?c:a(c,u,Math.min(f/2,l)/f);let m=i(d,c),h;h=m<1e-4?c:a(c,d,Math.min(m/2,l)/m),s===0?e.moveTo(p.x,p.y):e.lineTo(p.x,p.y),e.quadraticCurveTo(c.x,c.y,h.x,h.y,r)}}var nu=new Nt,ru=class{constructor(e){this.shapePrimitives=[],this._currentPoly=null,this._bounds=new an,this._graphicsPath2D=e,this.signed=e.checkForHoles}moveTo(e,t){return this.startPoly(e,t),this}lineTo(e,t){this._ensurePoly();let n=this._currentPoly.points,r=n[n.length-2],i=n[n.length-1];return(r!==e||i!==t)&&n.push(e,t),this}arc(e,t,n,r,i,a){return this._ensurePoly(!1),Gl(this._currentPoly.points,e,t,n,r,i,a),this}arcTo(e,t,n,r,i){return this._ensurePoly(),Kl(this._currentPoly.points,e,t,n,r,i),this}arcToSvg(e,t,n,r,i,a,o){return $l(this._currentPoly.points,this._currentPoly.lastX,this._currentPoly.lastY,a,o,e,t,n,r,i),this}bezierCurveTo(e,t,n,r,i,a,o){this._ensurePoly();let s=this._currentPoly;return Il(this._currentPoly.points,s.lastX,s.lastY,e,t,n,r,i,a,o),this}quadraticCurveTo(e,t,n,r,i){this._ensurePoly();let a=this._currentPoly;return Hl(this._currentPoly.points,a.lastX,a.lastY,e,t,n,r,i),this}closePath(){return this.endPoly(!0),this}addPath(e,t){this.endPoly(),t&&!t.isIdentity()&&(e=e.clone(!0),e.transform(t));let n=this.shapePrimitives,r=n.length;for(let t=0;t<e.instructions.length;t++){let n=e.instructions[t];this[n.action](...n.data)}if(e.checkForHoles&&n.length-r>1){let e=null;for(let t=r;t<n.length;t++){let r=n[t];if(r.shape.type===`polygon`){let i=r.shape,a=e?.shape;a&&a.containsPolygon(i)?(e.holes||(e.holes=[]),e.holes.push(r),n.copyWithin(t,t+1),n.length--,t--):e=r}}}return this}finish(e=!1){this.endPoly(e)}rect(e,t,n,r,i){return this.drawShape(new Nt(e,t,n,r),i),this}circle(e,t,n,r){return this.drawShape(new ps(e,t,n),r),this}poly(e,t,n){let r=new ys(e);return r.closePath=t,this.drawShape(r,n),this}regularPoly(e,t,n,r,i=0,a){r=Math.max(r|0,3);let o=-1*Math.PI/2+i,s=Math.PI*2/r,c=[];for(let i=0;i<r;i++){let r=o-i*s;c.push(e+n*Math.cos(r),t+n*Math.sin(r))}return this.poly(c,!0,a),this}roundPoly(e,t,n,r,i,a=0,o){if(r=Math.max(r|0,3),i<=0)return this.regularPoly(e,t,n,r,a);let s=n*Math.sin(Math.PI/r)-.001;i=Math.min(i,s);let c=-1*Math.PI/2+a,l=Math.PI*2/r,u=(r-2)*Math.PI/r/2;for(let a=0;a<r;a++){let r=a*l+c,s=e+n*Math.cos(r),d=t+n*Math.sin(r),f=r+Math.PI+u,p=r-Math.PI-u,m=s+i*Math.cos(f),h=d+i*Math.sin(f),g=s+i*Math.cos(p),_=d+i*Math.sin(p);a===0?this.moveTo(m,h):this.lineTo(m,h),this.quadraticCurveTo(s,d,g,_,o)}return this.closePath()}roundShape(e,t,n=!1,r){return e.length<3?this:(n?tu(this,e,t,r):eu(this,e,t),this.closePath())}filletRect(e,t,n,r,i){if(i===0)return this.rect(e,t,n,r);let a=Math.min(n,r)/2,o=Math.min(a,Math.max(-a,i)),s=e+n,c=t+r,l=o<0?-o:0,u=Math.abs(o);return this.moveTo(e,t+u).arcTo(e+l,t+l,e+u,t,u).lineTo(s-u,t).arcTo(s-l,t+l,s,t+u,u).lineTo(s,c-u).arcTo(s-l,c-l,e+n-u,c,u).lineTo(e+u,c).arcTo(e+l,c-l,e,c-u,u).closePath()}chamferRect(e,t,n,r,i,a){if(i<=0)return this.rect(e,t,n,r);let o=Math.min(i,Math.min(n,r)/2),s=e+n,c=t+r,l=[e+o,t,s-o,t,s,t+o,s,c-o,s-o,c,e+o,c,e,c-o,e,t+o];for(let e=l.length-1;e>=2;e-=2)l[e]===l[e-2]&&l[e-1]===l[e-3]&&l.splice(e-1,2);return this.poly(l,!0,a)}ellipse(e,t,n,r,i){return this.drawShape(new ms(e,t,n,r),i),this}roundRect(e,t,n,r,i,a){return this.drawShape(new xs(e,t,n,r,i),a),this}drawShape(e,t){return this.endPoly(),this.shapePrimitives.push({shape:e,transform:t}),this}startPoly(e,t){let n=this._currentPoly;return n&&this.endPoly(),n=new ys,n.points.push(e,t),this._currentPoly=n,this}endPoly(e=!1){let t=this._currentPoly;return t&&t.points.length>2&&(t.closePath=e,this.shapePrimitives.push({shape:t})),this._currentPoly=null,this}_ensurePoly(e=!0){if(!this._currentPoly&&(this._currentPoly=new ys,e)){let e=this.shapePrimitives[this.shapePrimitives.length-1];if(e){let t=e.shape.x,n=e.shape.y;if(e.transform&&!e.transform.isIdentity()){let r=e.transform,i=t;t=r.a*t+r.c*n+r.tx,n=r.b*i+r.d*n+r.ty}this._currentPoly.points.push(t,n)}else this._currentPoly.points.push(0,0)}}buildPath(){let e=this._graphicsPath2D;this.shapePrimitives.length=0,this._currentPoly=null;for(let t=0;t<e.instructions.length;t++){let n=e.instructions[t];this[n.action](...n.data)}this.finish()}get bounds(){let e=this._bounds;e.clear();let t=this.shapePrimitives;for(let n=0;n<t.length;n++){let r=t[n],i=r.shape.getBounds(nu);r.transform?e.addRect(i,r.transform):e.addRect(i)}return e}},iu=class e{constructor(e,t=!1){this.instructions=[],this.uid=I(`graphicsPath`),this._dirty=!0,this.checkForHoles=t,typeof e==`string`?fs(e,this):this.instructions=e?.slice()??[]}get shapePath(){return this._shapePath||=new ru(this),this._dirty&&(this._dirty=!1,this._shapePath.buildPath()),this._shapePath}addPath(e,t){return e=e.clone(),this.instructions.push({action:`addPath`,data:[e,t]}),this._dirty=!0,this}arc(...e){return this.instructions.push({action:`arc`,data:e}),this._dirty=!0,this}arcTo(...e){return this.instructions.push({action:`arcTo`,data:e}),this._dirty=!0,this}arcToSvg(...e){return this.instructions.push({action:`arcToSvg`,data:e}),this._dirty=!0,this}bezierCurveTo(...e){return this.instructions.push({action:`bezierCurveTo`,data:e}),this._dirty=!0,this}bezierCurveToShort(e,t,n,r,i){let a=this.instructions[this.instructions.length-1],o=this.getLastPoint(bt.shared),s=0,c=0;if(!a||a.action!==`bezierCurveTo`)s=o.x,c=o.y;else{s=a.data[2],c=a.data[3];let e=o.x,t=o.y;s=e+(e-s),c=t+(t-c)}return this.instructions.push({action:`bezierCurveTo`,data:[s,c,e,t,n,r,i]}),this._dirty=!0,this}closePath(){return this.instructions.push({action:`closePath`,data:[]}),this._dirty=!0,this}ellipse(...e){return this.instructions.push({action:`ellipse`,data:e}),this._dirty=!0,this}lineTo(...e){return this.instructions.push({action:`lineTo`,data:e}),this._dirty=!0,this}moveTo(...e){return this.instructions.push({action:`moveTo`,data:e}),this}quadraticCurveTo(...e){return this.instructions.push({action:`quadraticCurveTo`,data:e}),this._dirty=!0,this}quadraticCurveToShort(e,t,n){let r=this.instructions[this.instructions.length-1],i=this.getLastPoint(bt.shared),a=0,o=0;if(!r||r.action!==`quadraticCurveTo`)a=i.x,o=i.y;else{a=r.data[0],o=r.data[1];let e=i.x,t=i.y;a=e+(e-a),o=t+(t-o)}return this.instructions.push({action:`quadraticCurveTo`,data:[a,o,e,t,n]}),this._dirty=!0,this}rect(e,t,n,r,i){return this.instructions.push({action:`rect`,data:[e,t,n,r,i]}),this._dirty=!0,this}circle(e,t,n,r){return this.instructions.push({action:`circle`,data:[e,t,n,r]}),this._dirty=!0,this}roundRect(...e){return this.instructions.push({action:`roundRect`,data:e}),this._dirty=!0,this}poly(...e){return this.instructions.push({action:`poly`,data:e}),this._dirty=!0,this}regularPoly(...e){return this.instructions.push({action:`regularPoly`,data:e}),this._dirty=!0,this}roundPoly(...e){return this.instructions.push({action:`roundPoly`,data:e}),this._dirty=!0,this}roundShape(...e){return this.instructions.push({action:`roundShape`,data:e}),this._dirty=!0,this}filletRect(...e){return this.instructions.push({action:`filletRect`,data:e}),this._dirty=!0,this}chamferRect(...e){return this.instructions.push({action:`chamferRect`,data:e}),this._dirty=!0,this}star(e,t,n,r,i,a,o){i||=r/2;let s=-1*Math.PI/2+a,c=n*2,l=Math.PI*2/c,u=[];for(let n=0;n<c;n++){let a=n%2?i:r,o=n*l+s;u.push(e+a*Math.cos(o),t+a*Math.sin(o))}return this.poly(u,!0,o),this}clone(t=!1){let n=new e;if(n.checkForHoles=this.checkForHoles,!t)n.instructions=this.instructions.slice();else for(let e=0;e<this.instructions.length;e++){let t=this.instructions[e];n.instructions.push({action:t.action,data:t.data.slice()})}return n}clear(){return this.instructions.length=0,this._dirty=!0,this}transform(e){if(e.isIdentity())return this;let t=e.a,n=e.b,r=e.c,i=e.d,a=e.tx,o=e.ty,s=0,c=0,l=0,u=0,d=0,f=0,p=0,m=0;for(let h=0;h<this.instructions.length;h++){let g=this.instructions[h],_=g.data;switch(g.action){case`moveTo`:case`lineTo`:s=_[0],c=_[1],_[0]=t*s+r*c+a,_[1]=n*s+i*c+o;break;case`bezierCurveTo`:l=_[0],u=_[1],d=_[2],f=_[3],s=_[4],c=_[5],_[0]=t*l+r*u+a,_[1]=n*l+i*u+o,_[2]=t*d+r*f+a,_[3]=n*d+i*f+o,_[4]=t*s+r*c+a,_[5]=n*s+i*c+o;break;case`quadraticCurveTo`:l=_[0],u=_[1],s=_[2],c=_[3],_[0]=t*l+r*u+a,_[1]=n*l+i*u+o,_[2]=t*s+r*c+a,_[3]=n*s+i*c+o;break;case`arcToSvg`:s=_[5],c=_[6],p=_[0],m=_[1],_[0]=t*p+r*m,_[1]=n*p+i*m,_[5]=t*s+r*c+a,_[6]=n*s+i*c+o;break;case`circle`:_[4]=au(_[3],e);break;case`rect`:_[4]=au(_[4],e);break;case`ellipse`:_[8]=au(_[8],e);break;case`roundRect`:_[5]=au(_[5],e);break;case`addPath`:_[0].transform(e);break;case`poly`:_[2]=au(_[2],e);break;case`regularPoly`:case`chamferRect`:_[5]=au(_[5],e);break;case`closePath`:break;default:Gn(`unknown transform action`,g.action)}}return this._dirty=!0,this}get bounds(){return this.shapePath.bounds}getLastPoint(e){let t=this.instructions.length-1,n=this.instructions[t];if(!n)return e.x=0,e.y=0,e;for(;n.action===`closePath`;){if(t--,t<0)return e.x=0,e.y=0,e;n=this.instructions[t]}switch(n.action){case`moveTo`:case`lineTo`:e.x=n.data[0],e.y=n.data[1];break;case`quadraticCurveTo`:e.x=n.data[2],e.y=n.data[3];break;case`bezierCurveTo`:e.x=n.data[4],e.y=n.data[5];break;case`arc`:case`arcToSvg`:e.x=n.data[5],e.y=n.data[6];break;case`addPath`:n.data[0].getLastPoint(e)}return e}};function au(e,t){return e?e.prepend(t):t.clone()}function ou(e,t,n){let r=e.getAttribute(t);return r?Number(r):n}function su(e,t){let n=e.querySelectorAll(`defs`);for(let e=0;e<n.length;e++){let r=n[e];for(let e=0;e<r.children.length;e++){let n=r.children[e];switch(n.nodeName.toLowerCase()){case`lineargradient`:t.defs[n.id]=du(n);break;case`radialgradient`:t.defs[n.id]=fu(n)}}}}function cu(e,t,n){let r=e.getAttribute(t);if(r?.trim().endsWith(`%`)){let e=Number(r.trim().slice(0,-1));return Number.isNaN(e)?n:e/100}return ou(e,t,n)}function lu(e){return(e.getAttribute(`gradientUnits`)||`objectBoundingBox`)===`objectBoundingBox`?`local`:`global`}function uu(e){let t=[];for(let n=0;n<e.children.length;n++){let r=e.children[n],i=cu(r,`offset`,0),a=Vn.shared.setValue(r.getAttribute(`stop-color`)).toNumber();t.push({offset:i,color:a})}return t}function du(e){let t=cu(e,`x1`,0),n=cu(e,`y1`,0),r=cu(e,`x2`,1),i=cu(e,`y2`,0);return new ml({type:`linear`,start:{x:t,y:n},end:{x:r,y:i},textureSpace:lu(e),colorStops:uu(e)})}function fu(e){let t=cu(e,`cx`,.5),n=cu(e,`cy`,.5),r=cu(e,`r`,.5),i=cu(e,`fx`,t),a=cu(e,`fy`,n),o=cu(e,`fr`,0);return new ml({type:`radial`,center:{x:i,y:a},innerRadius:o,outerCenter:{x:t,y:n},outerRadius:r,textureSpace:lu(e),colorStops:uu(e)})}function pu(e){let t=e.match(/url\s*\(\s*['"]?\s*#([^'"\s)]+)\s*['"]?\s*\)/i);return t?t[1]:``}var mu={fill:{type:`paint`,default:0},"fill-opacity":{type:`number`,default:1},stroke:{type:`paint`,default:0},"stroke-width":{type:`number`,default:1},"stroke-opacity":{type:`number`,default:1},"stroke-linecap":{type:`string`,default:`butt`},"stroke-linejoin":{type:`string`,default:`miter`},"stroke-miterlimit":{type:`number`,default:10},"stroke-dasharray":{type:`string`,default:`none`},"stroke-dashoffset":{type:`number`,default:0},opacity:{type:`number`,default:1}};function hu(e,t){let n=e.getAttribute(`style`),r={},i={},a={strokeStyle:r,fillStyle:i,useFill:!1,useStroke:!1};for(let n in mu){let r=e.getAttribute(n);r&&gu(t,a,n,r.trim())}if(n){let e=n.split(`;`);for(let n=0;n<e.length;n++){let[r,i]=e[n].trim().split(`:`);mu[r]&&gu(t,a,r,i.trim())}}return{strokeStyle:a.useStroke?r:null,fillStyle:a.useFill?i:null,useFill:a.useFill,useStroke:a.useStroke}}function gu(e,t,n,r){switch(n){case`stroke`:if(r!==`none`){if(r.startsWith(`url(`)){let n=pu(r);t.strokeStyle.fill=e.defs[n]}else t.strokeStyle.color=Vn.shared.setValue(r).toNumber();t.useStroke=!0}break;case`stroke-width`:t.strokeStyle.width=Number(r);break;case`fill`:if(r!==`none`){if(r.startsWith(`url(`)){let n=pu(r);t.fillStyle.fill=e.defs[n]}else t.fillStyle.color=Vn.shared.setValue(r).toNumber();t.useFill=!0}break;case`fill-opacity`:t.fillStyle.alpha=Number(r);break;case`stroke-opacity`:t.strokeStyle.alpha=Number(r);break;case`opacity`:t.fillStyle.alpha=Number(r),t.strokeStyle.alpha=Number(r)}}function _u(e){if(e.length<=2)return!0;let t=e.map(e=>e.area).sort((e,t)=>t-e),[n,r]=t,i=t[t.length-1],a=n/r,o=r/i;return!(a>3&&o<2)}function vu(e){return e.split(/(?=[Mm])/).filter(e=>e.trim().length>0)}function yu(e){let t=e.match(/[-+]?[0-9]*\.?[0-9]+/g);if(!t||t.length<4)return 0;let n=t.map(Number),r=[],i=[];for(let e=0;e<n.length;e+=2)e+1<n.length&&(r.push(n[e]),i.push(n[e+1]));if(r.length===0||i.length===0)return 0;let a=Math.min(...r),o=Math.max(...r),s=Math.min(...i),c=Math.max(...i);return(o-a)*(c-s)}function bu(e,t){let n=new iu(e,!1);for(let e of n.instructions)t.instructions.push(e)}function xu(e,t){if(typeof e==`string`){let t=document.createElement(`div`);t.innerHTML=e.trim(),e=t.querySelector(`svg`)}let n={context:t,defs:{},path:new iu};su(e,n);let r=e.children,{fillStyle:i,strokeStyle:a}=hu(e,n);for(let e=0;e<r.length;e++){let t=r[e];t.nodeName.toLowerCase()!==`defs`&&Su(t,n,i,a)}return t}function Su(e,t,n,r){let i=e.children,{fillStyle:a,strokeStyle:o}=hu(e,t);a&&n?n={...n,...a}:a&&(n=a),o&&r?r={...r,...o}:o&&(r=o);let s=!n&&!r;s&&(n={color:0});let c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w;switch(e.nodeName.toLowerCase()){case`path`:{x=e.getAttribute(`d`);let i=e.getAttribute(`fill-rule`),a=vu(x),o=i===`evenodd`,s=a.length>1;if(o&&s){let e=a.map(e=>({path:e,area:yu(e)}));if(e.sort((e,t)=>t.area-e.area),a.length>3||!_u(e))for(let i=0;i<e.length;i++){let a=e[i],o=i===0;t.context.beginPath();let s=new iu(void 0,!0);bu(a.path,s),t.context.path(s),o?(n&&t.context.fill(n),r&&t.context.stroke(r)):t.context.cut()}else for(let i=0;i<e.length;i++){let a=e[i],o=i%2==1;t.context.beginPath();let s=new iu(void 0,!0);bu(a.path,s),t.context.path(s),o?t.context.cut():(n&&t.context.fill(n),r&&t.context.stroke(r))}}else S=new iu(x,!i||i===`evenodd`),t.context.path(S),n&&t.context.fill(n),r&&t.context.stroke(r);break}case`circle`:m=ou(e,`cx`,0),h=ou(e,`cy`,0),g=ou(e,`r`,0),t.context.ellipse(m,h,g,g),n&&t.context.fill(n),r&&t.context.stroke(r);break;case`rect`:c=ou(e,`x`,0),l=ou(e,`y`,0),C=ou(e,`width`,0),w=ou(e,`height`,0),_=ou(e,`rx`,0),v=ou(e,`ry`,0),_||v?t.context.roundRect(c,l,C,w,_||v):t.context.rect(c,l,C,w),n&&t.context.fill(n),r&&t.context.stroke(r);break;case`ellipse`:m=ou(e,`cx`,0),h=ou(e,`cy`,0),_=ou(e,`rx`,0),v=ou(e,`ry`,0),t.context.beginPath(),t.context.ellipse(m,h,_,v),n&&t.context.fill(n),r&&t.context.stroke(r);break;case`line`:u=ou(e,`x1`,0),d=ou(e,`y1`,0),f=ou(e,`x2`,0),p=ou(e,`y2`,0),t.context.beginPath(),t.context.moveTo(u,d),t.context.lineTo(f,p),r&&t.context.stroke(r);break;case`polygon`:b=e.getAttribute(`points`),y=b.match(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi).map(Number),t.context.poly(y,!0),n&&t.context.fill(n),r&&t.context.stroke(r);break;case`polyline`:b=e.getAttribute(`points`),y=b.match(/-?\d*\.?\d+(?:e[-+]?\d+)?/gi).map(Number),t.context.poly(y,!1),r&&t.context.stroke(r);break;case`g`:case`svg`:break;default:Gn(`[SVG parser] <${e.nodeName}> elements unsupported`)}s&&(n=null);for(let e=0;e<i.length;e++)Su(i[e],t,n,r)}function Cu(e){return e.texture!==void 0}var wu={repeat:{addressModeU:`repeat`,addressModeV:`repeat`},"repeat-x":{addressModeU:`repeat`,addressModeV:`clamp-to-edge`},"repeat-y":{addressModeU:`clamp-to-edge`,addressModeV:`repeat`},"no-repeat":{addressModeU:`clamp-to-edge`,addressModeV:`clamp-to-edge`}},Tu=class{constructor(e,t){this.uid=I(`fillPattern`),this._tick=0,this.transform=new P;let n=Cu(e)?e:{texture:e,repetition:t};this.texture=n.texture,this.textureSpace=n.textureSpace??`global`;let r=n.repetition;r&&(this.texture.source.style.addressModeU=wu[r].addressModeU,this.texture.source.style.addressModeV=wu[r].addressModeV)}setTransform(e){if(e){if(this.transform.equals(e))return;this.transform.copyFrom(e)}else{if(this.transform.isIdentity())return;this.transform.identity()}this._tick++}get texture(){return this._texture}set texture(e){this._texture!==e&&(this._texture=e,this._tick++)}get styleKey(){return`fill-pattern-${this.uid}-${this._tick}`}destroy(){this.texture.destroy(!0),this.texture=null}};function Eu(e){return Vn.isColorLike(e)}function Du(e){return e instanceof Tu}function Ou(e){return e instanceof ml}function ku(e){return e instanceof z}function Au(e,t,n){let r=Vn.shared.setValue(t??0);return e.color=r.toNumber(),e.alpha=r.alpha===1?n.alpha:r.alpha,e.texture=z.WHITE,{...n,...e}}function ju(e,t,n){return e.texture=t,{...n,...e}}function Mu(e,t,n){return e.fill=t,e.color=0xffffff,e.texture=t.texture,e.matrix=t.transform,e.textureSpace=t.textureSpace,{...n,...e}}function Nu(e,t,n){return t.buildGradient(),e.fill=t,e.color=0xffffff,e.texture=t.texture,e.matrix=t.transform,e.textureSpace=t.textureSpace,{...n,...e}}function Pu(e,t){let n={...t,...e},r=Vn.shared.setValue(n.color);return n.alpha*=r.alpha,n.color=r.toNumber(),n}function Fu(e,t){if(e==null)return null;let n={},r=e;return Eu(e)?Au(n,e,t):ku(e)?ju(n,e,t):Du(e)?Mu(n,e,t):Ou(e)?Nu(n,e,t):r.fill&&Du(r.fill)?Mu(r,r.fill,t):r.fill&&Ou(r.fill)?Nu(r,r.fill,t):Pu(r,t)}function Iu(e,t){let{width:n,alignment:r,miterLimit:i,cap:a,join:o,pixelLine:s,...c}=t,l=Fu(e,c);return l?{width:n,alignment:r,miterLimit:i,cap:a,join:o,pixelLine:s,...l}:null}function Lu(e,t){let n=1,r=e.shapePath.shapePrimitives;for(let e=0;e<r.length;e++){let i=r[e].shape;if(i.type!==`polygon`)continue;let a=i.points,o=a.length;if(o<6)continue;let s=i.closePath;for(let e=0;e<o;e+=2){if(!s&&(e===0||e===o-2))continue;let r=(e-2+o)%o,i=(e+2)%o,c=a[r],l=a[r+1],u=a[e],d=a[e+1],f=a[i],p=a[i+1],m=c-u,h=l-d,g=f-u,_=p-d,v=m*m+h*h,y=g*g+_*_;if(v<1e-12||y<1e-12)continue;let b=(m*g+h*_)/Math.sqrt(v*y);b<-1?b=-1:b>1&&(b=1);let x=Math.sqrt((1-b)*.5);if(x<1e-6)continue;let S=Math.min(1/x,t);S>n&&(n=S)}}return n}var Ru=new bt,zu=new P,Bu=class e extends gt{constructor(){super(...arguments),this._gpuData=Object.create(null),this.autoGarbageCollect=!0,this._gcLastUsed=-1,this.uid=I(`graphicsContext`),this.dirty=!0,this.batchMode=`auto`,this.instructions=[],this.destroyed=!1,this._activePath=new iu,this._transform=new P,this._fillStyle={...e.defaultFillStyle},this._strokeStyle={...e.defaultStrokeStyle},this._stateStack=[],this._tick=0,this._bounds=new an,this._boundsDirty=!0}clone(){let t=new e;return t.batchMode=this.batchMode,t.instructions=this.instructions.slice(),t._activePath=this._activePath.clone(),t._transform=this._transform.clone(),t._fillStyle={...this._fillStyle},t._strokeStyle={...this._strokeStyle},t._stateStack=this._stateStack.slice(),t._bounds=this._bounds.clone(),t._boundsDirty=!0,t}get fillStyle(){return this._fillStyle}set fillStyle(t){this._fillStyle=Fu(t,e.defaultFillStyle)}get strokeStyle(){return this._strokeStyle}set strokeStyle(t){this._strokeStyle=Iu(t,e.defaultStrokeStyle)}setFillStyle(t){return this._fillStyle=Fu(t,e.defaultFillStyle),this}setStrokeStyle(t){return this._strokeStyle=Fu(t,e.defaultStrokeStyle),this}texture(e,t,n,r,i,a){return this.instructions.push({action:`texture`,data:{image:e,dx:n||0,dy:r||0,dw:i||e.frame.width,dh:a||e.frame.height,transform:this._transform.clone(),alpha:this._fillStyle.alpha,style:t||t===0?Vn.shared.setValue(t).toNumber():0xffffff}}),this.onUpdate(),this}beginPath(){return this._activePath=new iu,this}fill(t,n){let r,i=this.instructions[this.instructions.length-1];return r=this._tick===0&&i?.action===`stroke`?i.data.path:this._activePath.clone(),r&&(t!=null&&(n!==void 0&&typeof t==`number`&&(R(L,`GraphicsContext.fill(color, alpha) is deprecated, use GraphicsContext.fill({ color, alpha }) instead`),t={color:t,alpha:n}),this._fillStyle=Fu(t,e.defaultFillStyle)),this.instructions.push({action:`fill`,data:{style:this.fillStyle,path:r}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0),this}_initNextPathLocation(){let{x:e,y:t}=this._activePath.getLastPoint(bt.shared);this._activePath.clear(),this._activePath.moveTo(e,t)}stroke(t){let n,r=this.instructions[this.instructions.length-1];return n=this._tick===0&&r?.action===`fill`?r.data.path:this._activePath.clone(),n&&(t!=null&&(this._strokeStyle=Iu(t,e.defaultStrokeStyle)),this.instructions.push({action:`stroke`,data:{style:this.strokeStyle,path:n}}),this.onUpdate(),this._initNextPathLocation(),this._tick=0),this}cut(){for(let e=0;e<2;e++){let t=this.instructions[this.instructions.length-1-e],n=this._activePath.clone();if(t&&(t.action===`stroke`||t.action===`fill`)){if(t.data.hole)t.data.hole.addPath(n);else{t.data.hole=n;break}}}return this._initNextPathLocation(),this}arc(e,t,n,r,i,a){this._tick++;let o=this._transform;return this._activePath.arc(o.a*e+o.c*t+o.tx,o.b*e+o.d*t+o.ty,n,r,i,a),this}arcTo(e,t,n,r,i){this._tick++;let a=this._transform;return this._activePath.arcTo(a.a*e+a.c*t+a.tx,a.b*e+a.d*t+a.ty,a.a*n+a.c*r+a.tx,a.b*n+a.d*r+a.ty,i),this}arcToSvg(e,t,n,r,i,a,o){this._tick++;let s=this._transform;return this._activePath.arcToSvg(e,t,n,r,i,s.a*a+s.c*o+s.tx,s.b*a+s.d*o+s.ty),this}bezierCurveTo(e,t,n,r,i,a,o){this._tick++;let s=this._transform;return this._activePath.bezierCurveTo(s.a*e+s.c*t+s.tx,s.b*e+s.d*t+s.ty,s.a*n+s.c*r+s.tx,s.b*n+s.d*r+s.ty,s.a*i+s.c*a+s.tx,s.b*i+s.d*a+s.ty,o),this}closePath(){return this._tick++,this._activePath?.closePath(),this}ellipse(e,t,n,r){return this._tick++,this._activePath.ellipse(e,t,n,r,this._transform.clone()),this}circle(e,t,n){return this._tick++,this._activePath.circle(e,t,n,this._transform.clone()),this}path(e){return this._tick++,this._activePath.addPath(e,this._transform.clone()),this}lineTo(e,t){this._tick++;let n=this._transform;return this._activePath.lineTo(n.a*e+n.c*t+n.tx,n.b*e+n.d*t+n.ty),this}moveTo(e,t){this._tick++;let n=this._transform,r=this._activePath.instructions,i=n.a*e+n.c*t+n.tx,a=n.b*e+n.d*t+n.ty;return r.length===1&&r[0].action===`moveTo`?(r[0].data[0]=i,r[0].data[1]=a,this):(this._activePath.moveTo(i,a),this)}quadraticCurveTo(e,t,n,r,i){this._tick++;let a=this._transform;return this._activePath.quadraticCurveTo(a.a*e+a.c*t+a.tx,a.b*e+a.d*t+a.ty,a.a*n+a.c*r+a.tx,a.b*n+a.d*r+a.ty,i),this}rect(e,t,n,r){return this._tick++,this._activePath.rect(e,t,n,r,this._transform.clone()),this}roundRect(e,t,n,r,i){return this._tick++,this._activePath.roundRect(e,t,n,r,i,this._transform.clone()),this}poly(e,t){return this._tick++,this._activePath.poly(e,t,this._transform.clone()),this}regularPoly(e,t,n,r,i=0,a){return this._tick++,this._activePath.regularPoly(e,t,n,r,i,a),this}roundPoly(e,t,n,r,i,a){return this._tick++,this._activePath.roundPoly(e,t,n,r,i,a),this}roundShape(e,t,n,r){return this._tick++,this._activePath.roundShape(e,t,n,r),this}filletRect(e,t,n,r,i){return this._tick++,this._activePath.filletRect(e,t,n,r,i),this}chamferRect(e,t,n,r,i,a){return this._tick++,this._activePath.chamferRect(e,t,n,r,i,a),this}star(e,t,n,r,i=0,a=0){return this._tick++,this._activePath.star(e,t,n,r,i,a,this._transform.clone()),this}svg(e){return this._tick++,xu(e,this),this}restore(){let e=this._stateStack.pop();return e&&(this._transform=e.transform,this._fillStyle=e.fillStyle,this._strokeStyle=e.strokeStyle),this}save(){return this._stateStack.push({transform:this._transform.clone(),fillStyle:{...this._fillStyle},strokeStyle:{...this._strokeStyle}}),this}getTransform(){return this._transform}resetTransform(){return this._transform.identity(),this}rotate(e){return this._transform.rotate(e),this}scale(e,t=e){return this._transform.scale(e,t),this}setTransform(e,t,n,r,i,a){return e instanceof P?(this._transform.set(e.a,e.b,e.c,e.d,e.tx,e.ty),this):(this._transform.set(e,t,n,r,i,a),this)}transform(e,t,n,r,i,a){return e instanceof P?(this._transform.append(e),this):(zu.set(e,t,n,r,i,a),this._transform.append(zu),this)}translate(e,t=e){return this._transform.translate(e,t),this}clear(){return this._activePath.clear(),this.instructions.length=0,this.resetTransform(),this.onUpdate(),this}onUpdate(){this._boundsDirty=!0,this.dirty=!0,this.emit(`update`,this,16)}get bounds(){if(!this._boundsDirty)return this._bounds;this._boundsDirty=!1;let e=this._bounds;e.clear();for(let t=0;t<this.instructions.length;t++){let n=this.instructions[t],r=n.action;if(r===`fill`){let t=n.data;e.addBounds(t.path.bounds)}else if(r===`texture`){let t=n.data;e.addFrame(t.dx,t.dy,t.dx+t.dw,t.dy+t.dh,t.transform)}if(r===`stroke`){let t=n.data,r=t.style.alignment,i=t.style.width*(1-r);t.style.join===`miter`&&(i*=Lu(t.path,t.style.miterLimit));let a=t.path.bounds;e.addFrame(a.minX-i,a.minY-i,a.maxX+i,a.maxY+i)}}return e.isValid||e.set(0,0,0,0),e}containsPoint(e){if(!this.bounds.containsPoint(e.x,e.y))return!1;let t=this.instructions,n=!1;for(let r=0;r<t.length;r++){let i=t[r],a=i.data,o=a.path;if(!i.action||!o)continue;let s=a.style,c=o.shapePath.shapePrimitives;for(let t=0;t<c.length;t++){let r=c[t].shape;if(!s||!r)continue;let o=c[t].transform,l=o?o.applyInverse(e,Ru):e;if(i.action===`fill`)n=r.contains(l.x,l.y);else{let e=s;n=r.strokeContains(l.x,l.y,e.width,e.alignment)}let u=a.hole;if(u){let e=u.shapePath?.shapePrimitives;if(e)for(let t=0;t<e.length;t++)e[t].shape.contains(l.x,l.y)&&(n=!1)}if(n)return!0}}return n}unload(){this.emit(`unload`,this);for(let e in this._gpuData)this._gpuData[e]?.destroy();this._gpuData=Object.create(null)}destroy(e=!1){if(!this.destroyed){if(this.destroyed=!0,this._stateStack.length=0,this._transform=null,this.unload(),this.emit(`destroy`,this),this.removeAllListeners(),typeof e==`boolean`?e:e?.texture){let t=typeof e==`boolean`?e:e?.textureSource;this._fillStyle.texture&&(this._fillStyle.fill&&`uid`in this._fillStyle.fill?this._fillStyle.fill.destroy():this._fillStyle.texture.destroy(t)),this._strokeStyle.texture&&(this._strokeStyle.fill&&`uid`in this._strokeStyle.fill?this._strokeStyle.fill.destroy():this._strokeStyle.texture.destroy(t))}this._fillStyle=null,this._strokeStyle=null,this.instructions=null,this._activePath=null,this._bounds=null,this._stateStack=null,this.customShader=null,this._transform=null}}};Bu.defaultFillStyle={color:0xffffff,alpha:1,texture:z.WHITE,matrix:null,fill:null,textureSpace:`local`},Bu.defaultStrokeStyle={width:1,color:0xffffff,alpha:1,alignment:.5,miterLimit:10,cap:`butt`,join:`miter`,texture:z.WHITE,matrix:null,fill:null,textureSpace:`local`,pixelLine:!1};var Vu=Bu,Hu={5:[.153388,.221461,.250301],7:[.071303,.131514,.189879,.214607],9:[.028532,.067234,.124009,.179044,.20236],11:[.0093,.028002,.065984,.121703,.175713,.198596],13:[.002406,.009255,.027867,.065666,.121117,.174868,.197641],15:[489e-6,.002403,.009246,.02784,.065602,.120999,.174697,.197448]},Uu=`in vec2 vBlurTexCoords[%size%];
|
|
245
|
+
uniform sampler2D uTexture;
|
|
246
|
+
uniform vec4 uInputClamp;
|
|
247
|
+
out vec4 finalColor;
|
|
248
|
+
void main(void)
|
|
249
|
+
{
|
|
250
|
+
%blur%
|
|
251
|
+
}`;function Wu(e){let t=Hu[e],n=t.length,r=``;for(let i=0;i<e;i++){let a=i===0?`finalColor = `:` + `,o=i<n?i:e-i-1,s=`texture(uTexture, clamp(vBlurTexCoords[%index%], uInputClamp.xy, uInputClamp.zw)) * %value%`.replace(`%index%`,i.toString()).replace(`%value%`,t[o].toString());r+=`${a}${s}
|
|
252
|
+
`}return Uu.replace(`%blur%`,`${r};`).replace(`%size%`,e.toString())}var Gu=`
|
|
253
|
+
in vec2 aPosition;
|
|
254
|
+
|
|
255
|
+
uniform float uStrength;
|
|
256
|
+
|
|
257
|
+
out vec2 vBlurTexCoords[%size%];
|
|
258
|
+
|
|
259
|
+
uniform vec4 uInputSize;
|
|
260
|
+
uniform vec4 uOutputFrame;
|
|
261
|
+
uniform vec4 uOutputTexture;
|
|
262
|
+
|
|
263
|
+
vec4 filterVertexPosition( void )
|
|
264
|
+
{
|
|
265
|
+
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
|
266
|
+
|
|
267
|
+
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
|
268
|
+
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
|
269
|
+
|
|
270
|
+
return vec4(position, 0.0, 1.0);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
vec2 filterTextureCoord( void )
|
|
274
|
+
{
|
|
275
|
+
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
void main(void)
|
|
279
|
+
{
|
|
280
|
+
gl_Position = filterVertexPosition();
|
|
281
|
+
|
|
282
|
+
float pixelStrength = uInputSize.%dimension% * uStrength;
|
|
283
|
+
|
|
284
|
+
vec2 textureCoord = filterTextureCoord();
|
|
285
|
+
%blur%
|
|
286
|
+
}`;function Ku(e,t){let n=Math.ceil(e/2),r=Gu,i=``,a;a=t?`vBlurTexCoords[%index%] = textureCoord + vec2(%sampleIndex% * pixelStrength, 0.0);`:`vBlurTexCoords[%index%] = textureCoord + vec2(0.0, %sampleIndex% * pixelStrength);`;for(let t=0;t<e;t++){let e=a.replace(`%index%`,t.toString());e=e.replace(`%sampleIndex%`,`${t-(n-1)}.0`),i+=e,i+=`
|
|
287
|
+
`}return r=r.replace(`%blur%`,i),r=r.replace(`%size%`,e.toString()),r=r.replace(`%dimension%`,t?`z`:`w`),r}function qu(e,t){let n=Ku(t,e),r=Wu(t);return ra.from({vertex:n,fragment:r,name:`blur-${e?`horizontal`:`vertical`}-pass-filter`})}var Ju=`
|
|
288
|
+
|
|
289
|
+
struct GlobalFilterUniforms {
|
|
290
|
+
uInputSize:vec4<f32>,
|
|
291
|
+
uInputPixel:vec4<f32>,
|
|
292
|
+
uInputClamp:vec4<f32>,
|
|
293
|
+
uOutputFrame:vec4<f32>,
|
|
294
|
+
uGlobalFrame:vec4<f32>,
|
|
295
|
+
uOutputTexture:vec4<f32>,
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
struct BlurUniforms {
|
|
299
|
+
uStrength:f32,
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
|
303
|
+
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
|
304
|
+
@group(0) @binding(2) var uSampler : sampler;
|
|
305
|
+
|
|
306
|
+
@group(1) @binding(0) var<uniform> blurUniforms : BlurUniforms;
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
struct VSOutput {
|
|
310
|
+
@builtin(position) position: vec4<f32>,
|
|
311
|
+
%blur-struct%
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
|
315
|
+
{
|
|
316
|
+
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
|
317
|
+
|
|
318
|
+
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
|
319
|
+
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
|
320
|
+
|
|
321
|
+
return vec4(position, 0.0, 1.0);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
|
325
|
+
{
|
|
326
|
+
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
|
330
|
+
{
|
|
331
|
+
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
fn getSize() -> vec2<f32>
|
|
335
|
+
{
|
|
336
|
+
return gfu.uGlobalFrame.zw;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
@vertex
|
|
341
|
+
fn mainVertex(
|
|
342
|
+
@location(0) aPosition : vec2<f32>,
|
|
343
|
+
) -> VSOutput {
|
|
344
|
+
|
|
345
|
+
let filteredCord = filterTextureCoord(aPosition);
|
|
346
|
+
|
|
347
|
+
let pixelStrength = gfu.uInputSize.%dimension% * blurUniforms.uStrength;
|
|
348
|
+
|
|
349
|
+
return VSOutput(
|
|
350
|
+
filterVertexPosition(aPosition),
|
|
351
|
+
%blur-vertex-out%
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
@fragment
|
|
356
|
+
fn mainFragment(
|
|
357
|
+
@builtin(position) position: vec4<f32>,
|
|
358
|
+
%blur-fragment-in%
|
|
359
|
+
) -> @location(0) vec4<f32> {
|
|
360
|
+
|
|
361
|
+
var finalColor = vec4(0.0);
|
|
362
|
+
|
|
363
|
+
%blur-sampling%
|
|
364
|
+
|
|
365
|
+
return finalColor;
|
|
366
|
+
}
|
|
367
|
+
`;function Yu(e,t){let n=Hu[t],r=n.length,i=[],a=[],o=[];for(let s=0;s<t;s++){i[s]=`@location(${s}) offset${s}: vec2<f32>,`,e?a[s]=`filteredCord + vec2(${s-r+1} * pixelStrength, 0.0),`:a[s]=`filteredCord + vec2(0.0, ${s-r+1} * pixelStrength),`;let c=n[s<r?s:t-s-1].toString();o[s]=`finalColor += textureSample(uTexture, uSampler,
|
|
368
|
+
clamp(offset${s}, gfu.uInputClamp.xy, gfu.uInputClamp.zw)) * ${c};`}let s=i.join(`
|
|
369
|
+
`),c=a.join(`
|
|
370
|
+
`),l=o.join(`
|
|
371
|
+
`),u=Ju.replace(`%blur-struct%`,s).replace(`%blur-vertex-out%`,c).replace(`%blur-fragment-in%`,s).replace(`%blur-sampling%`,l).replace(`%dimension%`,e?`z`:`w`);return ya.from({vertex:{source:u,entryPoint:`mainVertex`},fragment:{source:u,entryPoint:`mainFragment`}})}var Xu=class e extends Ha{constructor(t){t={...e.defaultOptions,...t};let n=qu(t.horizontal,t.kernelSize),r=Yu(t.horizontal,t.kernelSize);super({glProgram:n,gpuProgram:r,resources:{blurUniforms:{uStrength:{value:0,type:`f32`}}},...t}),this.horizontal=t.horizontal,this.legacy=t.legacy??!1,this._quality=0,this.quality=t.quality,this.blur=t.strength,this._blurUniforms=this.resources.blurUniforms,this._uniforms=this._blurUniforms.uniforms}apply(e,t,n,r){this.legacy?this._applyLegacy(e,t,n,r):this._applyOptimized(e,t,n,r)}_applyLegacy(e,t,n,r){if(this._uniforms.uStrength=this.strength/this.passes,this.passes===1)e.applyFilter(this,t,n,r);else{let i=Fr.getSameSizeTexture(t),a=t,o=i;this._state.blend=!1;let s=e.renderer.type===Oa.WEBGPU;for(let t=0;t<this.passes-1;t++){e.applyFilter(this,a,o,t===0||s);let n=o;o=a,a=n}this._state.blend=!0,e.applyFilter(this,a,n,r),Fr.returnTexture(i)}}_applyOptimized(e,t,n,r){if(this._uniforms.uStrength=this._calculateInitialStrength(),this.passes===1)e.applyFilter(this,t,n,r);else{let i=Fr.getSameSizeTexture(t),a=t,o=i;this._state.blend=!1;let s=e.renderer,c=s.type===Oa.WEBGPU,l=c?s.renderPipes.uniformBatch:null;for(let t=0;t<this.passes-1;t++){l&&this.groups[1].setResource(l.getUboResource(this._blurUniforms),0),e.applyFilter(this,a,o,c);let t=o;o=a,a=t,this._uniforms.uStrength*=.5}l&&this.groups[1].setResource(l.getUboResource(this._blurUniforms),0),this._state.blend=!0,e.applyFilter(this,a,n,r),Fr.returnTexture(i)}}_calculateInitialStrength(){let e=1,t=.5;for(let n=1;n<this.passes;n++)e+=t*t,t*=.5;return this.strength/Math.sqrt(e)}get blur(){return this.strength}set blur(e){this.padding=1+Math.abs(e)*2,this.strength=e}get quality(){return this._quality}set quality(e){this._quality=e,this.passes=e}};Xu.defaultOptions={strength:8,quality:4,kernelSize:5,legacy:!1};var Zu=Xu,Qu=class extends Ha{constructor(...e){let t=e[0]??{};typeof t==`number`&&(R(L,`BlurFilter constructor params are now options object. See params: { strength, quality, resolution, kernelSize }`),t={strength:t},e[1]!==void 0&&(t.quality=e[1]),e[2]!==void 0&&(t.resolution=e[2]||`inherit`),e[3]!==void 0&&(t.kernelSize=e[3])),t={...Zu.defaultOptions,...t};let{strength:n,strengthX:r,strengthY:i,quality:a,...o}=t;super({...o,compatibleRenderers:Oa.BOTH,resources:{}}),this._repeatEdgePixels=!1,this.blurXFilter=new Zu({horizontal:!0,...t}),this.blurYFilter=new Zu({horizontal:!1,...t}),this.quality=a,this.strengthX=r??n,this.strengthY=i??n,this.repeatEdgePixels=!1}apply(e,t,n,r){let i=Math.abs(this.blurXFilter.strength),a=Math.abs(this.blurYFilter.strength);if(i&&a){let i=Fr.getSameSizeTexture(t);this.blurXFilter.blendMode=`normal`,this.blurXFilter.apply(e,t,i,!0),this.blurYFilter.blendMode=this.blendMode,this.blurYFilter.apply(e,i,n,r),Fr.returnTexture(i)}else a?(this.blurYFilter.blendMode=this.blendMode,this.blurYFilter.apply(e,t,n,r)):(this.blurXFilter.blendMode=this.blendMode,this.blurXFilter.apply(e,t,n,r))}updatePadding(){this.padding=this._repeatEdgePixels?0:Math.max(Math.abs(this.blurXFilter.blur),Math.abs(this.blurYFilter.blur))*2}get strength(){if(this.strengthX!==this.strengthY)throw Error(`BlurFilter's strengthX and strengthY are different`);return this.strengthX}set strength(e){this.blurXFilter.blur=this.blurYFilter.blur=e,this.updatePadding()}get quality(){return this.blurXFilter.quality}set quality(e){this.blurXFilter.quality=this.blurYFilter.quality=e}get strengthX(){return this.blurXFilter.blur}set strengthX(e){this.blurXFilter.blur=e,this.updatePadding()}get strengthY(){return this.blurYFilter.blur}set strengthY(e){this.blurYFilter.blur=e,this.updatePadding()}get blur(){return R(`8.3.0`,`BlurFilter.blur is deprecated, please use BlurFilter.strength instead.`),this.strength}set blur(e){R(`8.3.0`,`BlurFilter.blur is deprecated, please use BlurFilter.strength instead.`),this.strength=e}get blurX(){return R(`8.3.0`,`BlurFilter.blurX is deprecated, please use BlurFilter.strengthX instead.`),this.strengthX}set blurX(e){R(`8.3.0`,`BlurFilter.blurX is deprecated, please use BlurFilter.strengthX instead.`),this.strengthX=e}get blurY(){return R(`8.3.0`,`BlurFilter.blurY is deprecated, please use BlurFilter.strengthY instead.`),this.strengthY}set blurY(e){R(`8.3.0`,`BlurFilter.blurY is deprecated, please use BlurFilter.strengthY instead.`),this.strengthY=e}get repeatEdgePixels(){return this._repeatEdgePixels}set repeatEdgePixels(e){this._repeatEdgePixels=e,this.updatePadding()}};Qu.defaultOptions={strength:8,quality:4,kernelSize:5,legacy:!1};var $u=class{constructor(){this.isBatchable=!1}reset(){this.isBatchable=!1,this.context=null,this.graphicsData&&=(this.graphicsData.destroy(),null)}destroy(){this.reset()}},ed=class{constructor(){this.instructions=new wr}init(){this.instructions.reset()}destroy(){this.instructions.destroy(),this.instructions=null}},td=class e{constructor(e){this._renderer=e,this._managedContexts=new Hc({renderer:e,type:`resource`,name:`graphicsContext`})}init(t){e.defaultOptions.bezierSmoothness=t?.bezierSmoothness??e.defaultOptions.bezierSmoothness}getContextRenderData(e){return this.getGpuContext(e).graphicsData||this._initContextRenderData(e)}updateGpuContext(e){let t=e._gpuData,n=!!t[this._renderer.uid],r=t[this._renderer.uid]||this._initContext(e);return(e.dirty||!n)&&(n&&r.reset(),r.isBatchable=!1,e.dirty=!1),r}getGpuContext(e){return e._gpuData[this._renderer.uid]||this._initContext(e)}_initContextRenderData(e){let t=new ed,n=this.getGpuContext(e);return n.graphicsData=t,t.init(),t}_initContext(e){let t=new $u;return t.context=e,e._gpuData[this._renderer.uid]=t,this._managedContexts.add(e),t}destroy(){this._managedContexts.destroy(),this._renderer=null}};td.extension={type:[N.CanvasSystem],name:`graphicsContext`},td.defaultOptions={bezierSmoothness:.5};var nd=td,rd=class{constructor(e,t){this.state=Ba.for2d(),this.renderer=e,this._adaptor=t,this.renderer.runners.contextChange.add(this),this._managedGraphics=new Hc({renderer:e,type:`renderable`,priority:-1,name:`graphics`})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(e){return!1}addRenderable(e,t){this._managedGraphics.add(e),this.renderer.renderPipes.batch.break(t),t.add(e)}updateRenderable(e){}execute(e){e.isRenderable&&this._adaptor.execute(this,e)}destroy(){this._managedGraphics.destroy(),this.renderer=null,this._adaptor.destroy(),this._adaptor=null}};rd.extension={type:[N.CanvasPipes],name:`graphics`};function id(e,t,n){let r=(e>>24&255)/255;t[n++]=(e&255)/255*r,t[n++]=(e>>8&255)/255*r,t[n++]=(e>>16&255)/255*r,t[n++]=r}var ad=class{constructor(){this.batches=[],this.batched=!1}destroy(){this.batches.forEach(e=>{Jn.return(e)}),this.batches.length=0}},od=class{constructor(e,t,n){this.state=Ba.for2d(),this.renderer=e,this._adaptor=t,this.renderer.runners.contextChange.add(this),this._managedGraphics=new Hc({renderer:e,type:`renderable`,priority:-1,name:n})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(e){let t=e.context,n=!!e._gpuData,r=this._contextSystem.updateGpuContext(t);return!!(r.isBatchable||n!==r.isBatchable)}addRenderable(e,t){let n=this._contextSystem.updateGpuContext(e.context);(e.didViewUpdate||!e._gpuData[this.renderer.uid])&&this._rebuild(e),n.isBatchable?this._addToBatcher(e,t):(this.renderer.renderPipes.batch.break(t),t.add(e))}updateRenderable(e){let t=this._getGpuDataForRenderable(e).batches;for(let e=0;e<t.length;e++){let n=t[e];n._batcher.updateElement(n)}}execute(e){if(!e.isRenderable)return;let t=this.renderer,n=e.context;if(!this._contextSystem.getGpuContext(n).batches.length)return;let r=n.customShader||this._adaptor.shader;this.state.blendMode=e.groupBlendMode;let i=r.resources.localUniforms.uniforms;i.uTransformMatrix=e.groupTransform,i.uRound=t._roundPixels|e._roundPixels,id(e.groupColorAlpha,i.uColor,0),this._adaptor.execute(this,e)}_rebuild(e){let t=this._getGpuDataForRenderable(e),n=this._contextSystem.updateGpuContext(e.context);t.destroy(),n.isBatchable&&this._updateBatchesForRenderable(e,t)}_addToBatcher(e,t){let n=this.renderer.renderPipes.batch,r=this._getGpuDataForRenderable(e).batches;for(let e=0;e<r.length;e++){let i=r[e];n.addToBatch(i,t)}}_getGpuDataForRenderable(e){return e._gpuData[this.renderer.uid]||this._initGpuDataForRenderable(e)}_initGpuDataForRenderable(e){let t=new ad;return e._gpuData[this.renderer.uid]=t,this._managedGraphics.add(e),t}_updateBatchesForRenderable(e,t){let n=this._contextSystem.getGpuContext(e.context),r=this.renderer._roundPixels|e._roundPixels;t.batches=n.batches.map(t=>{let n=Jn.get(this._batchableClass);return t.copyTo(n),n.renderable=e,n.roundPixels=r,n})}destroy(){this._managedGraphics.destroy(),this.renderer=null,this._adaptor.destroy(),this._adaptor=null,this.state=null}},sd=class extends od{constructor(e,t){super(e,t,`graphics`),this._batchableClass=Zc}get _contextSystem(){return this.renderer.graphicsContext}};sd.extension={type:[N.WebGLPipes,N.WebGPUPipes],name:`graphics`},at.add(rd),at.add(sd),at.add(nd),at.add(Ml);var cd=class e extends Ur{constructor(e){e instanceof Vu&&(e={context:e});let{context:t,roundPixels:n,...r}=e||{};super({label:`Graphics`,...r}),this.renderPipeId=`graphics`,t?this.context=t:(this.context=this._ownedContext=new Vu,this.context.autoGarbageCollect=this.autoGarbageCollect),this.didViewUpdate=!0,this.allowChildren=!1,this.roundPixels=n??!1}set context(e){e!==this._context&&(this._context&&(this._context.off(`update`,this.onViewUpdate,this),this._context.off(`unload`,this.unload,this)),this._context=e,this._context.on(`update`,this.onViewUpdate,this),this._context.on(`unload`,this.unload,this),this.onViewUpdate())}get context(){return this._context}get bounds(){return this._context.bounds}updateBounds(){}containsPoint(e){return this._context.containsPoint(e)}destroy(e){this._ownedContext&&!e?this._ownedContext.destroy(e):(e===!0||e?.context===!0)&&this._context.destroy(e),this._context?.off(`update`,this.onViewUpdate,this),this._context?.off(`unload`,this.unload,this),this._ownedContext=null,this._context=null,super.destroy(e)}_onTouch(e){this._gcLastUsed=e,this._context._gcLastUsed=e}_callContextMethod(e,t){return this.context[e](...t),this}setFillStyle(...e){return this._callContextMethod(`setFillStyle`,e)}setStrokeStyle(...e){return this._callContextMethod(`setStrokeStyle`,e)}fill(...e){return this._callContextMethod(`fill`,e)}stroke(...e){return this._callContextMethod(`stroke`,e)}texture(...e){return this._callContextMethod(`texture`,e)}beginPath(){return this._callContextMethod(`beginPath`,[])}cut(){return this._callContextMethod(`cut`,[])}arc(...e){return this._callContextMethod(`arc`,e)}arcTo(...e){return this._callContextMethod(`arcTo`,e)}arcToSvg(...e){return this._callContextMethod(`arcToSvg`,e)}bezierCurveTo(...e){return this._callContextMethod(`bezierCurveTo`,e)}closePath(){return this._callContextMethod(`closePath`,[])}ellipse(...e){return this._callContextMethod(`ellipse`,e)}circle(...e){return this._callContextMethod(`circle`,e)}path(...e){return this._callContextMethod(`path`,e)}lineTo(...e){return this._callContextMethod(`lineTo`,e)}moveTo(...e){return this._callContextMethod(`moveTo`,e)}quadraticCurveTo(...e){return this._callContextMethod(`quadraticCurveTo`,e)}rect(...e){return this._callContextMethod(`rect`,e)}roundRect(...e){return this._callContextMethod(`roundRect`,e)}poly(...e){return this._callContextMethod(`poly`,e)}regularPoly(...e){return this._callContextMethod(`regularPoly`,e)}roundPoly(...e){return this._callContextMethod(`roundPoly`,e)}roundShape(...e){return this._callContextMethod(`roundShape`,e)}filletRect(...e){return this._callContextMethod(`filletRect`,e)}chamferRect(...e){return this._callContextMethod(`chamferRect`,e)}star(...e){return this._callContextMethod(`star`,e)}svg(...e){return this._callContextMethod(`svg`,e)}restore(...e){return this._callContextMethod(`restore`,e)}save(){return this._callContextMethod(`save`,[])}getTransform(){return this.context.getTransform()}resetTransform(){return this._callContextMethod(`resetTransform`,[])}rotateTransform(...e){return this._callContextMethod(`rotate`,e)}scaleTransform(...e){return this._callContextMethod(`scale`,e)}setTransform(...e){return this._callContextMethod(`setTransform`,e)}transform(...e){return this._callContextMethod(`transform`,e)}translateTransform(...e){return this._callContextMethod(`translate`,e)}clear(){return this._callContextMethod(`clear`,[])}get fillStyle(){return this._context.fillStyle}set fillStyle(e){this._context.fillStyle=e}get strokeStyle(){return this._context.strokeStyle}set strokeStyle(e){this._context.strokeStyle=e}clone(t=!1){return t?new e(this._context.clone()):(this._ownedContext=null,new e(this._context))}lineStyle(e,t,n){R(L,`Graphics#lineStyle is no longer needed. Use Graphics#setStrokeStyle to set the stroke style.`);let r={};return e&&(r.width=e),t&&(r.color=t),n&&(r.alpha=n),this.context.strokeStyle=r,this}beginFill(e,t){R(L,`Graphics#beginFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.`);let n={};return e!==void 0&&(n.color=e),t!==void 0&&(n.alpha=t),this.context.fillStyle=n,this}endFill(){R(L,`Graphics#endFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.`),this.context.fill();let e=this.context.strokeStyle;return(e.width!==Vu.defaultStrokeStyle.width||e.color!==Vu.defaultStrokeStyle.color||e.alpha!==Vu.defaultStrokeStyle.alpha)&&this.context.stroke(),this}drawCircle(...e){return R(L,`Graphics#drawCircle has been renamed to Graphics#circle`),this._callContextMethod(`circle`,e)}drawEllipse(...e){return R(L,`Graphics#drawEllipse has been renamed to Graphics#ellipse`),this._callContextMethod(`ellipse`,e)}drawPolygon(...e){return R(L,`Graphics#drawPolygon has been renamed to Graphics#poly`),this._callContextMethod(`poly`,e)}drawRect(...e){return R(L,`Graphics#drawRect has been renamed to Graphics#rect`),this._callContextMethod(`rect`,e)}drawRoundedRect(...e){return R(L,`Graphics#drawRoundedRect has been renamed to Graphics#roundRect`),this._callContextMethod(`roundRect`,e)}drawStar(...e){return R(L,`Graphics#drawStar has been renamed to Graphics#star`),this._callContextMethod(`star`,e)}};at.add(pt,mt);var ld=`in vec2 aPosition;
|
|
372
|
+
out vec2 vTextureCoord;
|
|
373
|
+
|
|
374
|
+
uniform vec4 uInputSize;
|
|
375
|
+
uniform vec4 uOutputFrame;
|
|
376
|
+
uniform vec4 uOutputTexture;
|
|
377
|
+
|
|
378
|
+
vec4 filterVertexPosition( void )
|
|
379
|
+
{
|
|
380
|
+
vec2 position = aPosition * uOutputFrame.zw + uOutputFrame.xy;
|
|
381
|
+
|
|
382
|
+
position.x = position.x * (2.0 / uOutputTexture.x) - 1.0;
|
|
383
|
+
position.y = position.y * (2.0*uOutputTexture.z / uOutputTexture.y) - uOutputTexture.z;
|
|
384
|
+
|
|
385
|
+
return vec4(position, 0.0, 1.0);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
vec2 filterTextureCoord( void )
|
|
389
|
+
{
|
|
390
|
+
return aPosition * (uOutputFrame.zw * uInputSize.zw);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
void main(void)
|
|
394
|
+
{
|
|
395
|
+
gl_Position = filterVertexPosition();
|
|
396
|
+
vTextureCoord = filterTextureCoord();
|
|
397
|
+
}
|
|
398
|
+
`,ud=`struct GlobalFilterUniforms {
|
|
399
|
+
uInputSize:vec4<f32>,
|
|
400
|
+
uInputPixel:vec4<f32>,
|
|
401
|
+
uInputClamp:vec4<f32>,
|
|
402
|
+
uOutputFrame:vec4<f32>,
|
|
403
|
+
uGlobalFrame:vec4<f32>,
|
|
404
|
+
uOutputTexture:vec4<f32>,
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
|
408
|
+
|
|
409
|
+
struct VSOutput {
|
|
410
|
+
@builtin(position) position: vec4<f32>,
|
|
411
|
+
@location(0) uv : vec2<f32>
|
|
412
|
+
};
|
|
413
|
+
|
|
414
|
+
fn filterVertexPosition(aPosition:vec2<f32>) -> vec4<f32>
|
|
415
|
+
{
|
|
416
|
+
var position = aPosition * gfu.uOutputFrame.zw + gfu.uOutputFrame.xy;
|
|
417
|
+
|
|
418
|
+
position.x = position.x * (2.0 / gfu.uOutputTexture.x) - 1.0;
|
|
419
|
+
position.y = position.y * (2.0*gfu.uOutputTexture.z / gfu.uOutputTexture.y) - gfu.uOutputTexture.z;
|
|
420
|
+
|
|
421
|
+
return vec4(position, 0.0, 1.0);
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
fn filterTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
|
425
|
+
{
|
|
426
|
+
return aPosition * (gfu.uOutputFrame.zw * gfu.uInputSize.zw);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
fn globalTextureCoord( aPosition:vec2<f32> ) -> vec2<f32>
|
|
430
|
+
{
|
|
431
|
+
return (aPosition.xy / gfu.uGlobalFrame.zw) + (gfu.uGlobalFrame.xy / gfu.uGlobalFrame.zw);
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
fn getSize() -> vec2<f32>
|
|
435
|
+
{
|
|
436
|
+
return gfu.uGlobalFrame.zw;
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
@vertex
|
|
440
|
+
fn mainVertex(
|
|
441
|
+
@location(0) aPosition : vec2<f32>,
|
|
442
|
+
) -> VSOutput {
|
|
443
|
+
return VSOutput(
|
|
444
|
+
filterVertexPosition(aPosition),
|
|
445
|
+
filterTextureCoord(aPosition)
|
|
446
|
+
);
|
|
447
|
+
}`,dd=`precision highp float;
|
|
448
|
+
in vec2 vTextureCoord;
|
|
449
|
+
out vec4 finalColor;
|
|
450
|
+
|
|
451
|
+
uniform sampler2D uTexture;
|
|
452
|
+
uniform vec2 uVelocity;
|
|
453
|
+
uniform int uKernelSize;
|
|
454
|
+
uniform float uOffset;
|
|
455
|
+
|
|
456
|
+
uniform vec4 uInputSize;
|
|
457
|
+
|
|
458
|
+
const int MAX_KERNEL_SIZE = 2048;
|
|
459
|
+
|
|
460
|
+
// Notice:
|
|
461
|
+
// the perfect way:
|
|
462
|
+
// int kernelSize = min(uKernelSize, MAX_KERNELSIZE);
|
|
463
|
+
// BUT in real use-case , uKernelSize < MAX_KERNELSIZE almost always.
|
|
464
|
+
// So use uKernelSize directly.
|
|
465
|
+
|
|
466
|
+
void main(void)
|
|
467
|
+
{
|
|
468
|
+
vec4 color = texture(uTexture, vTextureCoord);
|
|
469
|
+
|
|
470
|
+
if (uKernelSize == 0)
|
|
471
|
+
{
|
|
472
|
+
finalColor = color;
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
vec2 velocity = uVelocity / uInputSize.xy;
|
|
477
|
+
float offset = -uOffset / length(uVelocity) - 0.5;
|
|
478
|
+
int k = uKernelSize - 1;
|
|
479
|
+
|
|
480
|
+
for(int i = 0; i < MAX_KERNEL_SIZE - 1; i++) {
|
|
481
|
+
if (i == k) {
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
vec2 bias = velocity * (float(i) / float(k) + offset);
|
|
485
|
+
color += texture(uTexture, vTextureCoord + bias);
|
|
486
|
+
}
|
|
487
|
+
finalColor = color / float(uKernelSize);
|
|
488
|
+
}
|
|
489
|
+
`,fd=`struct MotionBlurUniforms {
|
|
490
|
+
uVelocity: vec2<f32>,
|
|
491
|
+
uKernelSize: i32,
|
|
492
|
+
uOffset: f32,
|
|
493
|
+
};
|
|
494
|
+
|
|
495
|
+
struct GlobalFilterUniforms {
|
|
496
|
+
uInputSize:vec4<f32>,
|
|
497
|
+
uInputPixel:vec4<f32>,
|
|
498
|
+
uInputClamp:vec4<f32>,
|
|
499
|
+
uOutputFrame:vec4<f32>,
|
|
500
|
+
uGlobalFrame:vec4<f32>,
|
|
501
|
+
uOutputTexture:vec4<f32>,
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
@group(0) @binding(0) var<uniform> gfu: GlobalFilterUniforms;
|
|
505
|
+
|
|
506
|
+
@group(0) @binding(1) var uTexture: texture_2d<f32>;
|
|
507
|
+
@group(0) @binding(2) var uSampler: sampler;
|
|
508
|
+
@group(1) @binding(0) var<uniform> motionBlurUniforms : MotionBlurUniforms;
|
|
509
|
+
|
|
510
|
+
@fragment
|
|
511
|
+
fn mainFragment(
|
|
512
|
+
@builtin(position) position: vec4<f32>,
|
|
513
|
+
@location(0) uv : vec2<f32>
|
|
514
|
+
) -> @location(0) vec4<f32> {
|
|
515
|
+
let uVelocity = motionBlurUniforms.uVelocity;
|
|
516
|
+
let uKernelSize = motionBlurUniforms.uKernelSize;
|
|
517
|
+
let uOffset = motionBlurUniforms.uOffset;
|
|
518
|
+
|
|
519
|
+
let velocity: vec2<f32> = uVelocity / gfu.uInputSize.xy;
|
|
520
|
+
let offset: f32 = -uOffset / length(uVelocity) - 0.5;
|
|
521
|
+
let k: i32 = min(uKernelSize - 1, MAX_KERNEL_SIZE - 1);
|
|
522
|
+
|
|
523
|
+
var color: vec4<f32> = textureSample(uTexture, uSampler, uv);
|
|
524
|
+
|
|
525
|
+
for(var i: i32 = 0; i < k; i += 1) {
|
|
526
|
+
let bias: vec2<f32> = velocity * (f32(i) / f32(k) + offset);
|
|
527
|
+
color += textureSample(uTexture, uSampler, uv + bias);
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
return select(color / f32(uKernelSize), textureSample(uTexture, uSampler, uv), uKernelSize == 0);
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const MAX_KERNEL_SIZE: i32 = 2048;`,pd=Object.defineProperty,md=(e,t,n)=>t in e?pd(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hd=(e,t,n)=>(md(e,typeof t==`symbol`?t:t+``,n),n),gd=class e extends Ha{constructor(...t){let n=t[0]??{};(Array.isArray(n)||`x`in n&&`y`in n||n instanceof ht)&&(R(`6.0.0`,`MotionBlurFilter constructor params are now options object. See params: { velocity, kernelSize, offset }`),n={velocity:{x:`x`in n?n.x:n[0],y:`y`in n?n.y:n[1]}},t[1]!==void 0&&(n.kernelSize=t[1]),t[2]!==void 0&&(n.offset=t[2])),n={...e.DEFAULT_OPTIONS,...n};let r=ya.from({vertex:{source:ud,entryPoint:`mainVertex`},fragment:{source:fd,entryPoint:`mainFragment`}}),i=ra.from({vertex:ld,fragment:dd,name:`motion-blur-filter`});super({gpuProgram:r,glProgram:i,resources:{motionBlurUniforms:{uVelocity:{value:{x:0,y:0},type:`vec2<f32>`},uKernelSize:{value:Math.trunc(n.kernelSize??5),type:`i32`},uOffset:{value:n.offset,type:`f32`}}}}),hd(this,`uniforms`),hd(this,`_kernelSize`),this.uniforms=this.resources.motionBlurUniforms.uniforms,Object.assign(this,n)}get velocity(){return this.uniforms.uVelocity}set velocity(e){Array.isArray(e)&&(e={x:e[0],y:e[1]}),this.uniforms.uVelocity=e,this._updateDirty()}get velocityX(){return this.velocity.x}set velocityX(e){this.velocity.x=e,this._updateDirty()}get velocityY(){return this.velocity.y}set velocityY(e){this.velocity.y=e,this._updateDirty()}get kernelSize(){return this._kernelSize}set kernelSize(e){this._kernelSize=e,this._updateDirty()}get offset(){return this.uniforms.uOffset}set offset(e){this.uniforms.uOffset=e}_updateDirty(){this.padding=(Math.max(Math.abs(this.velocityX),Math.abs(this.velocityY))|0)+1,this.uniforms.uKernelSize=this.velocityX!==0||this.velocityY!==0?this._kernelSize:0}};hd(gd,`DEFAULT_OPTIONS`,{velocity:{x:0,y:0},kernelSize:5,offset:0});var _d=gd,vd={cx:.5,cy:.5},yd=1015.05,bd=yd*1.5,xd={minFactor:.1,maxFactor:.25,rampDistance:.15,referenceMs:25};function Sd(e,t){if(e.length===0)return null;if(t<=e[0].timeMs)return{cx:e[0].cx,cy:e[0].cy};let n=e[e.length-1];if(t>=n.timeMs)return{cx:n.cx,cy:n.cy};let r=0,i=e.length-1;for(;r<i-1;){let n=r+i>>>1;e[n].timeMs<=t?r=n:i=n}let a=e[r],o=e[i],s=o.timeMs-a.timeMs,c=s>0?(t-a.timeMs)/s:0;return{cx:a.cx+(o.cx-a.cx)*c,cy:a.cy+(o.cy-a.cy)*c}}function Cd(e,t,n){return{cx:t.cx+(e.cx-t.cx)*n,cy:t.cy+(e.cy-t.cy)*n}}function wd(e,t,n,r){return n>0?Cd(t,e,Td(Ed(t,e,r.minFactor,r.maxFactor,r.rampDistance),n,r.referenceMs)):e}function Td(e,t,n){return!(t>0)||!(n>0)?0:1-(1-e)**(t/n)}function Ed(e,t,n,r,i){let a=e.cx-t.cx,o=e.cy-t.cy,s=Math.sqrt(a*a+o*o),c=Math.min(1,s/i);return n+(r-n)*c}function Dd(e,t,n){return Math.max(t,Math.min(n,e))}function Od(e,t){let n=t?.widthRatio??1,r=t?.heightRatio??1,i=Math.min(.5,n/(2*e)),a=Math.min(.5,r/(2*e));return{minX:i,maxX:1-i,minY:a,maxY:1-a}}function kd(e,t,n){let r={cx:Dd(e.cx,0,1),cy:Dd(e.cy,0,1)},i=Od(t,n);return{cx:Dd(r.cx,i.minX,i.maxX),cy:Dd(r.cy,i.minY,i.maxY)}}function Ad(e){return Math.max(0,Math.min(1,e))}function jd(e,t,n){let r=1-n;return 3*e*r*r*n+3*t*r*n*n+n*n*n}function Md(e,t,n){let r=1-n;return 3*e*r*r+6*(t-e)*r*n+3*(1-t)*n*n}function Nd(e,t,n,r,i){let a=Ad(i),o=a;for(let t=0;t<8;t+=1){let t=jd(e,n,o)-a,r=Md(e,n,o);if(Math.abs(t)<1e-6||Math.abs(r)<1e-6)break;o-=t/r}let s=0,c=1;o=Ad(o);for(let t=0;t<10;t+=1){let t=jd(e,n,o);if(Math.abs(t-a)<1e-6)break;t<a?s=o:c=o,o=(s+c)/2}return jd(t,r,o)}function Pd(e){return Nd(.16,1,.3,1,e)}var Fd=1500,Id=1e3,Ld=500;function Rd(e,t,n){return e+(t-e)*n}function zd(e){return Nd(.1,0,.2,1,e)}function Bd(e,t){let n=e.startMs+Ld,r=n-bd,i=e.endMs+yd;return t<r||t>i?0:t<n?Pd((t-r)/bd):t<=e.endMs?1:1-Pd(Ad((t-e.endMs)/yd))}function Vd(e,t,n){return{cx:Rd(e.cx,t.cx,n),cy:Rd(e.cy,t.cy,n)}}function Hd(e,t,n,r,i){let a=e.focus;if(e.focusMode===`auto`&&r&&r.length>0&&n!==void 0){let e=Sd(r,n);e&&(a=e)}return kd(a,t,i)}function Ud(e){let t=[...e].sort((e,t)=>e.startMs-t.startMs),n=[];for(let e=0;e<t.length-1;e+=1){let r=t[e],i=t[e+1];i.startMs-r.endMs>Fd||n.push({currentRegion:r,nextRegion:i,transitionStart:r.endMs,transitionEnd:r.endMs+Id})}return n}function Wd(e,t,n,r,i){let a=e.map(e=>{let r=n.find(t=>t.currentRegion.id===e.id);if(r&&t>r.currentRegion.endMs)return{region:e,strength:0};let i=n.find(t=>t.nextRegion.id===e.id);return i&&t<i.transitionEnd?{region:e,strength:0}:{region:e,strength:Bd(e,t)}}).filter(e=>e.strength>0).sort((e,t)=>t.strength===e.strength?t.region.startMs-e.region.startMs:t.strength-e.strength);if(a.length===0)return null;let o=a[0].region,s=ae(o);return{region:{...o,focus:Hd(o,s,t,r,i)},strength:a[0].strength,blendedScale:null,rotation3D:x(o)}}function Gd(e,t,n,r){for(let i of t)if(e>i.transitionEnd&&e<i.nextRegion.startMs){let t=ae(i.nextRegion);return{region:{...i.nextRegion,focus:Hd(i.nextRegion,t,e,n,r)},strength:1,blendedScale:null,rotation3D:x(i.nextRegion)}}return null}function Kd(e,t,n,r){for(let i of e){let{currentRegion:e,nextRegion:a,transitionStart:o,transitionEnd:s}=i;if(t<o||t>s)continue;let c=zd(Ad((t-o)/Math.max(1,s-o))),l=ae(e),u=ae(a),d=Rd(l,u,c),f=n&&n.length>0?Sd(n,t):null,p=kd(e.focusMode===`auto`&&f?f:e.focus,l,r),m=kd(a.focusMode===`auto`&&f?f:a.focus,u,r),h=Vd(p,m,c),g=C(x(e),x(a),c);return{region:{...a,focus:h},strength:1,blendedScale:d,rotation3D:g,transition:{progress:c,startFocus:p,endFocus:m,startScale:l,endScale:u}}}return null}var qd=null;function Jd(e,t,n={}){let r=!!n.connectZooms,i=n.cursorTelemetry,a=n.viewportRatio,o=Math.round(t);if(qd&&qd.regions===e&&qd.timeMsKey===o&&qd.telemetry===i&&qd.connectZooms===r&&qd.viewportRatio===a)return qd.result;let s=r?Ud(e):[],c;if(r){let n=Kd(s,t,i,a);if(n)c=n;else{let n=Gd(t,s,i,a);if(n)c={...n,transition:null};else{let n=Wd(e,t,s,i,a);c=n?{...n,transition:null}:{region:null,strength:0,blendedScale:null,rotation3D:_,transition:null}}}}else{let n=Wd(e,t,s,i,a);c=n?{...n,transition:null}:{region:null,strength:0,blendedScale:null,rotation3D:_,transition:null}}return qd={regions:e,timeMsKey:o,telemetry:i,connectZooms:r,viewportRatio:a,result:c},c}var Yd=(e,t,n)=>n>t?t:n<e?e:n,Xd=e=>e*1e3,Zd=e=>e/1e3,Qd=(e,t,n=10)=>{let r=``,i=Math.max(Math.round(t/n),2);for(let t=0;t<i;t++)r+=Math.round(e(t/(i-1))*1e4)/1e4+`, `;return`linear(${r.substring(0,r.length-2)})`},$d=2e4;function ef(e){let t=0,n=e.next(t);for(;!n.done&&t<2e4;)t+=50,n=e.next(t);return t>=2e4?1/0:t}function tf(e,t=100,n){let r=n({...e,keyframes:[0,t]}),i=Math.min(ef(r),$d);return{type:`keyframes`,ease:e=>r.next(i*e).value/t,duration:Zd(i)}}var U={stiffness:100,damping:10,mass:1,velocity:0,duration:800,bounce:.3,visualDuration:.3,restSpeed:{granular:.01,default:2},restDelta:{granular:.005,default:.5},minDuration:.01,maxDuration:10,minDamping:.05,maxDamping:1};function nf(e,t){return e*Math.sqrt(1-t*t)}var rf=12;function af(e,t,n){let r=n;for(let n=1;n<rf;n++)r-=e(r)/t(r);return r}var of=.001;function sf({duration:e=U.duration,bounce:t=U.bounce,velocity:n=U.velocity,mass:r=U.mass}){let i,a;U.maxDuration;let o=1-t;o=Yd(U.minDamping,U.maxDamping,o),e=Yd(U.minDuration,U.maxDuration,Zd(e)),o<1?(i=t=>{let r=t*o,i=r*e,a=r-n,s=nf(t,o),c=Math.exp(-i);return of-a/s*c},a=t=>{let r=t*o*e,a=r*n+n,s=o**2*t**2*e,c=Math.exp(-r),l=nf(t**2,o);return(-i(t)+of>0?-1:1)*((a-s)*c)/l}):(i=t=>-.001+Math.exp(-t*e)*((t-n)*e+1),a=t=>Math.exp(-t*e)*((n-t)*(e*e)));let s=5/e,c=af(i,a,s);if(e=Xd(e),isNaN(c))return{stiffness:U.stiffness,damping:U.damping,duration:e};{let t=c**2*r;return{stiffness:t,damping:o*2*Math.sqrt(r*t),duration:e}}}var cf=[`duration`,`bounce`],lf=[`stiffness`,`damping`,`mass`];function uf(e,t){return t.some(t=>e[t]!==void 0)}function df(e){let t={velocity:U.velocity,stiffness:U.stiffness,damping:U.damping,mass:U.mass,isResolvedFromDuration:!1,...e};if(!uf(e,lf)&&uf(e,cf)){if(t.velocity=0,e.visualDuration){let n=e.visualDuration,r=2*Math.PI/(n*1.2),i=r*r,a=2*Yd(.05,1,1-(e.bounce||0))*Math.sqrt(i);t={...t,mass:U.mass,stiffness:i,damping:a}}else{let n=sf({...e,velocity:0});t={...t,...n,mass:U.mass},t.isResolvedFromDuration=!0}}return t}function ff(e=U.visualDuration,t=U.bounce){let n=typeof e==`object`?e:{visualDuration:e,keyframes:[0,1],bounce:t},{restSpeed:r,restDelta:i}=n,a=n.keyframes[0],o=n.keyframes[n.keyframes.length-1],s={done:!1,value:a},{stiffness:c,damping:l,mass:u,duration:d,velocity:f,isResolvedFromDuration:p}=df({...n,velocity:-Zd(n.velocity||0)}),m=f||0,h=l/(2*Math.sqrt(c*u)),g=o-a,_=Zd(Math.sqrt(c/u)),v=Math.abs(g)<5;r||=v?U.restSpeed.granular:U.restSpeed.default,i||=v?U.restDelta.granular:U.restDelta.default;let y,b,x,S,C,w;if(h<1)x=nf(_,h),S=(m+h*_*g)/x,y=e=>{let t=Math.exp(-h*_*e);return o-t*(S*Math.sin(x*e)+g*Math.cos(x*e))},C=h*_*S+g*x,w=h*_*g-S*x,b=e=>Math.exp(-h*_*e)*(C*Math.sin(x*e)+w*Math.cos(x*e));else if(h===1){y=e=>o-Math.exp(-_*e)*(g+(m+_*g)*e);let e=m+_*g;b=t=>Math.exp(-_*t)*(_*e*t-m)}else{let e=_*Math.sqrt(h*h-1);y=t=>{let n=Math.exp(-h*_*t),r=Math.min(e*t,300);return o-n*((m+h*_*g)*Math.sinh(r)+e*g*Math.cosh(r))/e};let t=(m+h*_*g)/e,n=h*_*t-g*e,r=h*_*g-t*e;b=t=>{let i=Math.exp(-h*_*t),a=Math.min(e*t,300);return i*(n*Math.sinh(a)+r*Math.cosh(a))}}let T={calculatedDuration:p&&d||null,velocity:e=>Xd(b(e)),next:e=>{if(!p&&h<1){let t=Math.exp(-h*_*e),n=Math.sin(x*e),a=Math.cos(x*e),c=o-t*(S*n+g*a),l=Xd(t*(C*n+w*a));return s.done=Math.abs(l)<=r&&Math.abs(o-c)<=i,s.value=s.done?o:c,s}let t=y(e);if(p)s.done=e>=d;else{let n=Xd(b(e));s.done=Math.abs(n)<=r&&Math.abs(o-t)<=i}return s.value=s.done?o:t,s},toString:()=>{let e=Math.min(ef(T),$d),t=Qd(t=>T.next(e*t).value,e,30);return e+`ms `+t},toTransition:()=>{}};return T}ff.applyToOptions=e=>{let t=tf(e,100,ff);return e.ease=t.ease,e.duration=Xd(t.duration),e.type=`keyframes`,e};var pf=0,mf=2,hf=.5;function gf(e=0){return{value:e,velocity:0,initialized:!1}}function _f(e,t=1e3/60){return!Number.isFinite(e)||e<=0?t:Math.min(80,Math.max(1,e))}function vf(e,t,n,r){let i=_f(n);if(!e.initialized||!Number.isFinite(e.value))return e.value=t,e.velocity=0,e.initialized=!0,e.value;let a=r.restDelta??5e-4,o=r.restSpeed??.02;if(Math.abs(t-e.value)<=a&&Math.abs(e.velocity)<=o)return e.value=t,e.velocity=0,e.value;let s=e.value,c=ff({keyframes:[e.value,t],velocity:e.velocity,stiffness:r.stiffness,damping:r.damping,mass:r.mass,restDelta:a,restSpeed:o}).next(i);return e.value=c.done?t:c.value,e.velocity=(e.value-s)/i*1e3,c.done&&(e.velocity=0),e.value}function yf(e){let t=Math.min(mf,Math.max(pf,e));if(t<=0)return{stiffness:1e3,damping:100,mass:1,restDelta:1e-4,restSpeed:.001};if(t<=hf){let e=Math.min(1,Math.max(0,(t-pf)/.5));return{stiffness:760-e*420,damping:34+e*24,mass:.55+e*.45,restDelta:2e-4,restSpeed:.01}}let n=Math.min(1,Math.max(0,(t-hf)/1.5));return{stiffness:340-n*180,damping:58+n*22,mass:1+n*.35,restDelta:2e-4,restSpeed:.01}}function bf(){return{stiffness:320,damping:40,mass:.92,restDelta:5e-4,restSpeed:.015}}function xf(){return{scale:gf(1),x:gf(0),y:gf(0)}}function Sf(e,t){for(let[n,r]of[[e.scale,t.scale],[e.x,t.x],[e.y,t.y]])n.value=r,n.velocity=0,n.initialized=!0}function Cf(e,t,n,r){let i=e.initialized?e.value:t,a=vf(e,t,n,r);return i<=t&&a>t||i>=t&&a<t?(e.value=t,e.velocity=0,t):a}function wf(e,t,n){let r=bf();return{scale:Cf(e.scale,t.scale,n,r),x:Cf(e.x,t.x,n,r),y:Cf(e.y,t.y,n,r)}}var Tf=1400,Ef=14,Df=12;function Of(e){let t=Math.min(1,Math.max(0,e));return t*(1+1.2000000000000002*t)}function kf(){return{lastFrameTimeMs:0,prevCamX:0,prevCamY:0,prevCamScale:1,initialized:!1}}function Af({stageSize:e,baseMask:t,zoomScale:n,zoomProgress:r=1,focusX:i,focusY:a}){if(e.width<=0||e.height<=0||t.width<=0||t.height<=0)return{scale:1,x:0,y:0};let o=Math.min(1,Math.max(0,r)),s=i*e.width,c=a*e.height,l=e.width/2,u=e.height/2,d=1+(n-1)*o,f=l-s*n,p=u-c*n;return{scale:d,x:f*o,y:p*o}}function jf({stageSize:e,baseMask:t,zoomScale:n,x:r,y:i}){if(e.width<=0||e.height<=0||t.width<=0||t.height<=0||n<=0)return{cx:.5,cy:.5};let a=e.width/2,o=e.height/2,s=(a-r)/n,c=(o-i)/n;return{cx:s/e.width,cy:c/e.height}}function Mf({cameraContainer:e,blurFilter:t,motionBlurFilter:n,stageSize:r,baseMask:i,zoomScale:a,zoomProgress:o=1,focusX:s,focusY:c,motionIntensity:l,motionVector:u,isPlaying:d,motionBlurAmount:f=0,transformOverride:p,motionBlurState:m,frameTimeMs:h}){if(r.width<=0||r.height<=0||i.width<=0||i.height<=0)return{scale:1,x:0,y:0};let g=p??Af({stageSize:r,baseMask:i,zoomScale:a,zoomProgress:o,focusX:s,focusY:c});if(e.scale.set(g.scale),e.position.set(g.x,g.y),m&&n&&f>0&&d){let e=h??performance.now();if(!m.initialized)m.prevCamX=g.x,m.prevCamY=g.y,m.prevCamScale=g.scale,m.lastFrameTimeMs=e,m.initialized=!0,n.velocity={x:0,y:0},n.kernelSize=5,n.offset=0,t&&(t.blur=0);else{let i=Math.min(80,Math.max(1,e-m.lastFrameTimeMs))/1e3;m.lastFrameTimeMs=e;let a=Of(f),o=g.x-m.prevCamX,s=g.y-m.prevCamY,c=g.scale-m.prevCamScale;m.prevCamX=g.x,m.prevCamY=g.y,m.prevCamScale=g.scale;let l=o/i,u=s/i,d=Math.abs(c/i)*Math.max(r.width,r.height)*.5,p=Math.sqrt(l*l+u*u)+d,h=Math.min(1,p/Tf),_=p<Df?0:h*h*Ef*a,v=Math.sqrt(l*l+u*u)||1,y=_*2.4;n.velocity=_>0?{x:l/v*y,y:u/v*y}:{x:0,y:0},n.kernelSize=_>8?15:_>4?11:7,n.offset=_>.5?-.2:0,t&&(t.blur=0)}}else n&&(n.velocity={x:0,y:0},n.kernelSize=5,n.offset=0),t&&(t.blur=0),m&&(m.initialized=!1);return{scale:g.scale,x:g.x,y:g.y}}var Nf=.35;function Pf(e){return Math.max(Nf,Math.min(1,1/(Number.isFinite(e)&&e>0?e:1)))}function Ff(e){return Math.max(10,Math.min(50,Number.isFinite(e)?e:25))/100}var If=.02,Lf=24,Rf={"picture-in-picture":{label:`Picture in Picture`,transform:{type:`overlay`,marginFraction:If,minMargin:0,minSize:0},borderRadius:{max:Lf,min:12,fraction:.12},shadow:{color:`rgba(0,0,0,0.35)`,blur:24,offsetX:0,offsetY:10}},"vertical-stack":{label:`Vertical Stack`,transform:{type:`stack`,gap:0},borderRadius:{max:0,min:0,fraction:0},shadow:null},"dual-frame":{label:`Dual Frame`,transform:{type:`split`,gapFraction:.02,minGap:12,screenUnits:2,webcamUnits:1},borderRadius:{max:Lf,min:12,fraction:.06},shadow:null},"no-webcam":{label:`No Webcam`,transform:{type:`overlay`,marginFraction:0,minMargin:0,minSize:0},borderRadius:{max:0,min:0,fraction:0},shadow:null}};Object.entries(Rf).map(([e,t])=>({value:e,label:t.label}));function zf(e=`picture-in-picture`){return Rf[e]}function Bf(e){let{canvasSize:t,maxContentSize:n=t,screenSize:r,webcamSize:i,layoutPreset:a=`picture-in-picture`,webcamSizePreset:o=25,webcamPosition:s,webcamMaskShape:c=`rectangle`}=e,{width:l,height:u}=t,{width:d,height:f}=r;if(a===`no-webcam`)return{screenRect:Vf({canvasSize:t,size:r,maxSize:n}),webcamRect:null};let p=i?.width,m=i?.height,h=zf(a),g=Ff(o);if(l<=0||u<=0||d<=0||f<=0)return null;if(h.transform.type===`stack`){if(!p||!m||p<=0||m<=0)return{screenRect:{x:0,y:0,width:l,height:u},webcamRect:null,screenCover:!0};let e=p/m,t=l,n=Math.round(l/e),r=u-n;return{screenRect:{x:0,y:0,width:l,height:Math.max(0,r)},webcamRect:{x:0,y:Math.max(0,r),width:t,height:n,borderRadius:0},screenCover:!0}}if(h.transform.type===`split`){let e=Vf({canvasSize:t,size:r,maxSize:n});if(!p||!m||p<=0||m<=0)return{screenRect:e,webcamRect:null};let i=Math.min(l,Math.max(1,Math.round(n.width))),a=Math.min(u,Math.max(1,Math.round(n.height))),o=Math.max(0,Math.floor((l-i)/2)),s=Math.max(0,Math.floor((u-a)/2)),c=Math.max(h.transform.minGap,Math.round(i*h.transform.gapFraction)),d=h.transform.screenUnits+h.transform.webcamUnits,f=Math.max(1,i-c),g=Math.max(1,Math.round(f*h.transform.screenUnits/d)),_=Math.max(1,f-g),v={x:o,y:s,width:g,height:a},y={x:o+g+c,y:s,width:_,height:a},b=Math.min(h.borderRadius.max,Math.max(h.borderRadius.min,Math.round(Math.min(y.width,y.height)*h.borderRadius.fraction)));return{screenRect:v,screenBorderRadius:b,webcamRect:{x:y.x,y:y.y,width:y.width,height:y.height,borderRadius:b,maskShape:`rectangle`},screenCover:!0}}let _=h.transform,v=Vf({canvasSize:t,size:r,maxSize:n});if(!p||!m||p<=0||m<=0)return{screenRect:v,webcamRect:null};let y=Math.max(_.minMargin,Math.round(Math.min(l,u)*_.marginFraction)),b=Math.sqrt(l*u),x=Math.max(_.minSize,b*g),S=Math.max(_.minSize,b*g),C=Math.min(x/p,S/m),w=Math.round(p*C),T=Math.round(m*C);if(c===`circle`||c===`square`){let e=Math.min(w,T);w=e,T=e}let E,D;s?(E=Math.round(s.cx*l-w/2),D=Math.round(s.cy*u-T/2),E=Math.max(0,Math.min(l-w,E)),D=Math.max(0,Math.min(u-T,D))):(E=Math.max(0,Math.round(l-y-w)),D=Math.max(0,Math.round(u-y-T)));let O;return O=c===`rounded`?Math.round(Math.min(w,T)*.3):c===`circle`?Math.round(Math.min(w,T)/2):Math.min(h.borderRadius.max,Math.max(h.borderRadius.min,Math.round(Math.min(w,T)*h.borderRadius.fraction))),{screenRect:v,webcamRect:{x:E,y:D,width:w,height:T,borderRadius:O,maskShape:c}}}function Vf(e){let{canvasSize:t,size:n,maxSize:r}=e;return Hf({bounds:{x:0,y:0,width:t.width,height:t.height},size:n,maxSize:r})}function Hf(e){let{bounds:t,size:n,maxSize:r}=e,{x:i,y:a,width:o,height:s}=t,{width:c,height:l}=n,{width:u,height:d}=r,f=Math.min(u/c,d/l),p=Math.round(c*f),m=Math.round(l*f);return u>=o&&d>=s&&Math.abs(o-p)<=4&&Math.abs(s-m)<=4?{x:i,y:a,width:o,height:s}:{x:i+Math.max(0,Math.floor((o-p)/2)),y:a+Math.max(0,Math.floor((s-m)/2)),width:p,height:m}}var Uf=1e3/240,Wf=Uf/1e3;function Gf(e,t,n){return Math.min(n,Math.max(t,e))}function Kf(e,t,n){let r=0,i=n,a=-1;for(;r<=i;){let n=r+(i-r>>1);e[n]<=t?(a=n,r=n+1):i=n-1}return a}function qf(e,t){let n=e.length-1;if(t<=e[0].timeMs)return{cx:e[0].cx,cy:e[0].cy};if(t>=e[n].timeMs)return{cx:e[n].cx,cy:e[n].cy};let r=Kf(e.map(e=>e.timeMs),t,n),i=e[r],a=e[r+1]??i,o=a.timeMs-i.timeMs;if(o<=0)return{cx:i.cx,cy:i.cy};let s=(t-i.timeMs)/o;return{cx:i.cx+(a.cx-i.cx)*s,cy:i.cy+(a.cy-i.cy)*s}}function Jf(e,t,n,r){let i=new Float32Array(e.length);if(e.length===0)return i;let a=e[0],o=0;i[0]=a;for(let s=1;s<e.length;s++){let c=(-t*(a-e[s])-n*o)/r;o+=c*Wf,a+=o*Wf,i[s]=a}return i}function Yf(e){let t=[],n=[];for(let r of e)r.visible===!1?(n.length&&t.push(n),n=[]):n.push(r);return n.length&&t.push(n),t}function Xf(e,t,n,r){let i=e[0].timeMs,a=e[e.length-1].timeMs,o=Math.max(1,Math.round((a-i)/Uf))+1,s=new Float32Array(o),c=new Float32Array(o),l=new Float32Array(o);for(let t=0;t<o;t++){let n=t===o-1?a:i+t*Uf;s[t]=n;let r=qf(e,n);c[t]=r.cx,l[t]=r.cy}return{start:i,end:a,times:s,xs:Jf(c,t,n,r),ys:Jf(l,t,n,r)}}function Zf(e,t){let n=e.times.length-1;if(t<=e.times[0])return{cx:e.xs[0],cy:e.ys[0]};if(t>=e.times[n])return{cx:e.xs[n],cy:e.ys[n]};let r=Kf(e.times,t,n),i=e.times[r+1]-e.times[r];if(i<=0)return{cx:e.xs[r],cy:e.ys[r]};let a=(t-e.times[r])/i;return{cx:e.xs[r]+(e.xs[r+1]-e.xs[r])*a,cy:e.ys[r]+(e.ys[r+1]-e.ys[r])*a}}function Qf(e){return{sampleAt(t){for(let n of e)if(t>=n[0].timeMs&&t<=n[n.length-1].timeMs)return qf(n,t);return null}}}function $f(e,t){let n=Yf(e.samples).filter(e=>e.length>0);if(n.length===0)return{sampleAt:()=>null};if(t<=0)return Qf(n);let r=yf(Gf(t,0,1)),i=n.map(e=>e.length<2?{start:e[0].timeMs,end:e[0].timeMs,times:new Float32Array([e[0].timeMs]),xs:new Float32Array([e[0].cx]),ys:new Float32Array([e[0].cy])}:Xf(e,r.stiffness,r.damping,r.mass));return{sampleAt(e){for(let t of i)if(e>=t.start&&e<=t.end)return Zf(t,e);return null}}}var ep=new WeakMap;function tp(e,t){if(!e||e.samples.length===0)return null;let n=(Number.isFinite(t)?Gf(t,0,1):0).toFixed(2),r=ep.get(e);r||(r=new Map,ep.set(e,r));let i=r.get(n);return i||(i=$f(e,Number.parseFloat(n)),r.set(n,i)),i}var np=new URL(`Cursor_App-Starting-zEGhqPJj.svg`,import.meta.url).href,rp=new URL(`Cursor_Cross-BuZZnB_U.svg`,import.meta.url).href,ip=new URL(`Cursor_Default-DkmrqhKh.svg`,import.meta.url).href,ap=new URL(`Cursor_Hand-(Grabbing)-B-Qy-RsV.svg`,import.meta.url).href,op=new URL(`Cursor_Hand-(Open)-DGrW1tFF.svg`,import.meta.url).href,sp=new URL(`Cursor_Hand-(Pointing)-Byy2KbtA.svg`,import.meta.url).href,cp=new URL(`Cursor_Help-D5NcyFpT.svg`,import.meta.url).href,lp=new URL(`Cursor_Move-CerM5f-0.svg`,import.meta.url).href,up=new URL(`Cursor_Not-Allowed-3rttFVa5.svg`,import.meta.url).href,dp=new URL(`Cursor_Resize-North-East-South-West-CBd4tbCA.svg`,import.meta.url).href,fp=new URL(`Cursor_Resize-North-South-DOxgUIwF.svg`,import.meta.url).href,pp=new URL(`Cursor_Resize-North-West-South-East-hzXJFJ2_.svg`,import.meta.url).href,mp=new URL(`Cursor_Resize-West-East-rDJgc6AZ.svg`,import.meta.url).href,hp=new URL(`Cursor_Text-Cursor-Cn9rFLjY.svg`,import.meta.url).href,gp=new URL(`Cursor_Up-Arrow-CYyEN-dA.svg`,import.meta.url).href,_p=new URL(`Cursor_Wait-CK8tq-9y.svg`,import.meta.url).href;function vp(e,t,n){return Math.min(n,Math.max(t,e))}var yp=260,bp=6,xp=new WeakMap;function Sp(e,t){let n=0,r=e.length-1,i=-1;for(;n<=r;){let a=n+Math.floor((r-n)/2);e[a].timeMs<=t?(i=a,n=a+1):r=a-1}return i}function Cp(e){let t=xp.get(e);if(t)return t;let n=new Map(e.assets.map(e=>[e.id,e]));return xp.set(e,n),n}function wp(e,t){return Cp(e).get(t)??null}var Tp={arrow:{imageDataUrl:ip,width:32,height:32,hotspotX:16.25,hotspotY:15.03},text:{imageDataUrl:hp,width:32,height:32,hotspotX:16,hotspotY:16},pointer:{imageDataUrl:sp,width:32,height:33,hotspotX:16.65,hotspotY:14.24},crosshair:{imageDataUrl:rp,width:32,height:32,hotspotX:16,hotspotY:16},"open-hand":{imageDataUrl:op,width:32,height:32,hotspotX:16,hotspotY:9},"closed-hand":{imageDataUrl:ap,width:32,height:32,hotspotX:16,hotspotY:9},"resize-ew":{imageDataUrl:mp,width:32,height:32,hotspotX:16,hotspotY:16},"resize-ns":{imageDataUrl:fp,width:32,height:32,hotspotX:16,hotspotY:16},"resize-nesw":{imageDataUrl:dp,width:32,height:32,hotspotX:16,hotspotY:16},"resize-nwse":{imageDataUrl:pp,width:32,height:32,hotspotX:16,hotspotY:16},move:{imageDataUrl:lp,width:32,height:32,hotspotX:16,hotspotY:16},"not-allowed":{imageDataUrl:up,width:32,height:32,hotspotX:16,hotspotY:16},wait:{imageDataUrl:_p,width:32,height:32,hotspotX:16,hotspotY:16},"app-starting":{imageDataUrl:np,width:32,height:32,hotspotX:7.25,hotspotY:4.03},help:{imageDataUrl:cp,width:32,height:32,hotspotX:7.25,hotspotY:4.03},"up-arrow":{imageDataUrl:gp,width:32,height:32,hotspotX:16,hotspotY:3}},Ep={id:`telemetry-arrow`,platform:`darwin`,imageDataUrl:ip,width:Tp.arrow?.width??32,height:Tp.arrow?.height??32,hotspotX:Tp.arrow?.hotspotX??16,hotspotY:Tp.arrow?.hotspotY??16,cursorType:`arrow`};function Dp(e){let t=e?.cursorType??`arrow`,n=Tp[t]??Tp.arrow;return{...Ep,id:`telemetry-${t}`,imageDataUrl:n?.imageDataUrl??Ep.imageDataUrl,width:n?.width??Ep.width,height:n?.height??Ep.height,hotspotX:n?.hotspotX??Ep.hotspotX,hotspotY:n?.hotspotY??Ep.hotspotY,cursorType:t}}function Op(e){if(e.cursorType||e.width<24||e.width>64||e.height<24||e.height>64)return null;let t=e.hotspotX/e.width,n=e.hotspotY/e.height;return t>=.22&&t<=.55&&n>=.2&&n<=.45?Tp[`open-hand`]??null:null}function kp(e){return!!(e&&e.samples.length>0&&(e.assets.length>0||e.provider===`none`))}function Ap(){return{x:0,y:0,lastTimeMs:null,initialized:!1}}function jp(e){e.x=0,e.y=0,e.lastTimeMs=null,e.initialized=!1}function Mp(e,t){if(!e||e.samples.length===0)return 0;for(let n=Sp(e.samples,t);n>=0;--n){let r=e.samples[n],i=t-r.timeMs;if(i>yp)return 0;if(r.interactionType===`click`)return 1-i/yp}return 0}function Np(e,t){if(t<=0||e<=0)return 1;let n=vp(e,0,5)/5,r=1-vp(t,0,1);return r<.38?1-Math.sin(r/.38*Math.PI)*n*.24:1+Math.sin((r-.38)/.62*Math.PI)*n*.16}function Pp({motionBlur:e,point:t,state:n,timeMs:r}){let i=vp(Number.isFinite(e)?e:0,0,1),a=n.lastTimeMs;if(i<=0||!n.initialized||a===null||r<=a)return n.x=t.x,n.y=t.y,n.lastTimeMs=r,n.initialized=!0,0;let o=Math.max(1,r-a),s=Math.hypot(t.x-n.x,t.y-n.y)/o*1e3;return n.x=t.x,n.y=t.y,n.lastTimeMs=r,vp(s*i*.004,0,bp)}function Fp(e,t){if(t.width<=0||t.height<=0)return null;let n=(e.cx-t.x)/t.width,r=(e.cy-t.y)/t.height;return n<0||n>1||r<0||r>1?null:{cx:vp(n,0,1),cy:vp(r,0,1)}}function Ip(e,t){let n=Fp(e,t);return n?new bt(n.cx,n.cy):null}function Lp(e,t){if(!kp(e))return null;let n=e.samples,r=Sp(n,t);if(r<0)return null;let i=n[r];if(i.visible===!1)return null;let a=i.assetId?wp(e,i.assetId):Dp(i);if(!a)return null;let o=n[r+1];if(!o||o.timeMs<=i.timeMs||o.visible===!1||(o.assetId??null)!==(i.assetId??null)||t<=i.timeMs)return{asset:a,sample:i};let s=vp((t-i.timeMs)/(o.timeMs-i.timeMs),0,1);return{asset:a,sample:{...i,cx:i.cx+(o.cx-i.cx)*s,cy:i.cy+(o.cy-i.cy)*s}}}function Rp({cropRegion:e,maskRect:t,sample:n}){let r=Ip(n,e);return r?new bt(t.x+r.x*t.width,t.y+r.y*t.height):null}function zp(e,t){let n=e.scaleFactor??t??1;return{width:e.width/n,height:e.height/n,hotspotX:e.hotspotX/n,hotspotY:e.hotspotY/n}}function Bp(e,t){let n=t?.cursorType??e.cursorType??null;return n?Tp[n]??null:Op(e)}function Vp(e){if(e.width<=0||e.height<=0)return null;let t=e.hotspotX/e.width,n=e.hotspotY/e.height;return t<.33&&n<.33?`arrow`:n<.4&&t>=.33&&t<=.6?`pointer`:null}function Hp(e,t){if(!e||e==="default")return null;let n=ge(e)?.assets[t];if(!n)return null;try{return{imageDataUrl:Te(n.assetPath),width:n.width,height:n.height,hotspotX:n.hotspotX,hotspotY:n.hotspotY}}catch{return null}}function Up(e,t,n,r){let i=n?.cursorType??e.cursorType??null;if(r&&r!=="default"){let t=i??Vp(e),n=t?Hp(r,t):null;if(n&&t)return{id:`theme:${r}:${t}`,imageDataUrl:n.imageDataUrl,width:n.width,height:n.height,hotspotX:n.hotspotX,hotspotY:n.hotspotY}}let a=Bp(e,n);if(a)return{id:`pretty:${n?.cursorType??e.cursorType}`,imageDataUrl:a.imageDataUrl,width:a.width,height:a.height,hotspotX:a.hotspotX,hotspotY:a.hotspotY};let o=zp(e,t);return{id:e.id,imageDataUrl:e.imageDataUrl,width:o.width,height:o.height,hotspotX:o.hotspotX,hotspotY:o.hotspotY}}function Wp(e,t,n,r,i,a,o){switch(e.beginPath(),a){case`circle`:{let a=t+r/2,o=n+i/2,s=Math.min(r,i)/2;e.arc(a,o,s,0,Math.PI*2);break}default:e.roundRect(t,n,r,i,o)}e.closePath()}var Gp=null,Kp=null,qp=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u,Jp=Intl.Segmenter,Yp=typeof Jp==`function`?new Jp(void 0,{granularity:`grapheme`}):null;function Xp(e){return Yp?Array.from(Yp.segment(e),({segment:e})=>e):Array.from(e)}function Zp(e){let t=[],n=``,r=Array.from(e),i=()=>{n&&=(t.push(...n.split(/(\s+)/).filter(e=>e.length>0)),``)};for(let e of r)qp.test(e)?(i(),t.push(e)):n+=e;return i(),t}var Qp={up:[`M 50 20 L 50 80`,`M 50 20 L 35 35`,`M 50 20 L 65 35`],down:[`M 50 20 L 50 80`,`M 50 80 L 35 65`,`M 50 80 L 65 65`],left:[`M 80 50 L 20 50`,`M 20 50 L 35 35`,`M 20 50 L 35 65`],right:[`M 20 50 L 80 50`,`M 80 50 L 65 35`,`M 80 50 L 65 65`],"up-right":[`M 25 75 L 75 25`,`M 75 25 L 60 30`,`M 75 25 L 70 40`],"up-left":[`M 75 75 L 25 25`,`M 25 25 L 40 30`,`M 25 25 L 30 40`],"down-right":[`M 25 25 L 75 75`,`M 75 75 L 70 60`,`M 75 75 L 60 70`],"down-left":[`M 75 25 L 25 75`,`M 25 75 L 30 60`,`M 25 75 L 40 70`]};function $p(e,t,n){let r=[],i=e.trim().split(/\s+/),a=0;for(;a<i.length;){let e=i[a];if(e===`M`||e===`L`){let o=parseFloat(i[a+1])*t,s=parseFloat(i[a+2])*n;r.push({cmd:e,args:[o,s]}),a+=3}else a++}return r}function em(e,t,n,r,i,a,o,s,c){let l=Qp[t];if(!l)return;e.save(),e.translate(i,a);let u=8*c,d=Math.max(0,o-u*2),f=Math.max(0,s-u*2),p=Math.min(d/100,f/100),m=u+(d-100*p)/2,h=u+(f-100*p)/2;e.translate(m,h),e.shadowColor=`rgba(0, 0, 0, 0.3)`,e.shadowBlur=8*p,e.shadowOffsetX=0,e.shadowOffsetY=4*p,e.strokeStyle=n,e.lineWidth=r*p,e.lineCap=`round`,e.lineJoin=`round`,e.beginPath();for(let t of l){let n=$p(t,p,p);for(let{cmd:t,args:r}of n)t===`M`?e.moveTo(r[0],r[1]):t===`L`&&e.lineTo(r[0],r[1])}e.stroke(),e.restore()}function tm(e,t,n,r,i,a){let o=t.blurData?.shape||`rectangle`;if(o===`rectangle`){e.beginPath(),e.rect(n,r,i,a);return}if(o===`oval`){e.beginPath(),e.ellipse(n+i/2,r+a/2,i/2,a/2,0,0,Math.PI*2);return}let s=t.blurData?.freehandPoints;if(o===`freehand`&&s&&s.length>=3){e.beginPath(),e.moveTo(n+s[0].x/100*i,r+s[0].y/100*a);for(let t=1;t<s.length;t++)e.lineTo(n+s[t].x/100*i,r+s[t].y/100*a);e.closePath()}else e.beginPath(),e.rect(n,r,i,a)}function nm(e,t,n,r,i,a,o){let s=e.canvas,c=se(t.blurData?.type),l=Math.max(1,Math.round(le(t.blurData)*o)),u=c===`mosaic`?Math.max(0,Math.ceil(ue(t.blurData,o))):Math.max(2,Math.ceil(l*2)),d=Math.max(0,Math.floor(n)-u),f=Math.max(0,Math.floor(r)-u),p=Math.min(s.width,Math.ceil(n+i)+u),m=Math.min(s.height,Math.ceil(r+a)+u),h=Math.max(0,p-d),g=Math.max(0,m-f);if(!(h<=0||g<=0)&&(Gp&&Kp||(Gp=document.createElement(`canvas`),Kp=Gp.getContext(`2d`)),Gp&&Kp)){if(Gp.width=h,Gp.height=g,Kp.clearRect(0,0,h,g),Kp.drawImage(s,d,f,h,g,0,0,h,g),c===`mosaic`){let e=Kp.getImageData(0,0,h,g);fe(e,ue(t.blurData,o)),Kp.putImageData(e,0,0)}e.save(),tm(e,t,n,r,i,a),e.clip(),e.filter=c===`mosaic`?`none`:`blur(${l}px)`,e.drawImage(Gp,d,f),e.filter=`none`,e.fillStyle=de(t.blurData),e.fillRect(d,f,h,g),e.restore()}}function rm(e,t,n,r,i,a,o,s){let c=t.style,l=m(t,s);e.save();let u=n+i/2,d=r+a/2;e.translate(u,d),e.translate(l.translateX*o,l.translateY*o),e.scale(l.scale,l.scale),e.translate(-u,-d),e.globalAlpha*=l.opacity,e.beginPath(),e.rect(n,r,i,a),e.clip();let f=c.fontWeight===`bold`?`bold`:`normal`,p=c.fontStyle===`italic`?`italic`:`normal`,h=c.fontSize*o;e.font=`${p} ${f} ${h}px ${c.fontFamily}`,e.textBaseline=`middle`;let g=8*o,_=n,v=r+a/2;c.textAlign===`center`?(_=n+i/2,e.textAlign=`center`):c.textAlign===`right`?(_=n+i-g,e.textAlign=`right`):(_=n+g,e.textAlign=`left`);let y=i-g*2,b=t.content.split(`
|
|
534
|
+
`),x=[];for(let t of b){if(!t){x.push(``);continue}let n=Zp(t),r=``;for(let t of n){let n=r+t;r&&e.measureText(n).width>y?(x.push(r),r=t.trimStart()):r=n}r&&x.push(r)}let S=h*1.4,C=v-(x.length-1)*S/2;x.forEach((t,n)=>{let r=C+n*S,i=l.revealProgress,a=Xp(t),s=Math.ceil(a.length*i),u=i>=1?t:a.slice(0,s).join(``);if(!u&&i<1)return;let d=e.textAlign,f=e.measureText(t),p=_;if(e.textAlign===`center`?(p=_-f.width/2,e.textAlign=`left`):(e.textAlign===`right`||e.textAlign===`end`)&&(p=_-f.width,e.textAlign=`left`),c.backgroundColor&&c.backgroundColor!==`transparent`){let t=e.measureText(u),n=h*.1,i=h*.2,a=4*o,s=p-i,l=t.width+i*2,f=h*1.4+n*2,m=r-f/2;(d===`left`||d===`start`)&&(s=_-i),e.fillStyle=c.backgroundColor,e.beginPath(),e.roundRect(s,m,l,f,a),e.fill()}if(e.fillStyle=c.color,e.fillText(u,p,r),c.textDecoration===`underline`){let t=e.measureText(u),n=p,i=r+h*.15;(d===`left`||d===`start`)&&(n=_),e.strokeStyle=c.color,e.lineWidth=Math.max(1,h/16),e.beginPath(),e.moveTo(n,i),e.lineTo(n+t.width,i),e.stroke()}e.textAlign=d}),e.restore()}async function im(e,t,n,r,i,a){if(t.content&&t.content.startsWith(`data:image`))return new Promise(o=>{let s=new Image;s.onload=()=>{let t=s.width/s.height,c=i/a,l=i,u=a,d=n,f=r;t>c?(u=i/t,f=r+(a-u)/2):(l=a*t,d=n+(i-l)/2),e.drawImage(s,d,f,l,u),o()},s.onerror=()=>{console.error(`[AnnotationRenderer] Failed to load image annotation`),o()},s.src=t.content})}async function am(e,t,n,r,i,a=1){let o=[...t.filter(e=>i>=e.startMs&&i<e.endMs)].sort((e,t)=>e.zIndex-t.zIndex);for(let t of o){let o=t.position.x/100*n,s=t.position.y/100*r,c=t.size.width/100*n,l=t.size.height/100*r;switch(t.type){case`text`:rm(e,t,o,s,c,l,a,i);break;case`image`:await im(e,t,o,s,c,l);break;case`figure`:t.figureData&&em(e,t.figureData.arrowDirection,t.figureData.color,t.figureData.strokeWidth,o,s,c,l,a);break;case`blur`:nm(e,t,o,s,c,l,a)}}}var om=/^(#[0-9a-fA-F]{3,8}|(?:rgba?|hsla?)\([^)]*\)|[a-zA-Z-]+)/;function sm(e){let t=e.match(/^(linear|radial)-gradient\((.*)\)$/i);if(!t)return null;let n=t[1].toLowerCase(),r=dm(t[2]);if(r.length===0)return null;let i=null,a=r;fm(n,r[0])&&(i=r[0],a=r.slice(1));let o=a.map(e=>pm(e)).filter(e=>e!==null);return o.length===0?null:{type:n,descriptor:i,stops:mm(o)}}function cm(e,t,n){let r=e*Math.PI/180,i=Math.sin(r),a=-Math.cos(r),o=(Math.abs(i)*t+Math.abs(a)*n)/2,s=t/2,c=n/2;return{x0:s-i*o,y0:c-a*o,x1:s+i*o,y1:c+a*o}}function lm(e){if(!e)return 180;let t=e.match(/(-?\d*\.?\d+)deg/i);return t?Number.parseFloat(t[1]):{"to top":0,"to top right":45,"to right":90,"to bottom right":135,"to bottom":180,"to bottom left":225,"to left":270,"to top left":315}[e.trim().toLowerCase().replace(/\s+/g,` `)]??180}function um(e,t,n){let r=e?.match(/at\s+(-?\d*\.?\d+)%\s+(-?\d*\.?\d+)%/i),i=r?Number.parseFloat(r[1])/100*t:t/2,a=r?Number.parseFloat(r[2])/100*n:n/2,o=[Math.hypot(i,a),Math.hypot(t-i,a),Math.hypot(i,n-a),Math.hypot(t-i,n-a)];return{cx:i,cy:a,radius:Math.max(...o)}}function dm(e){let t=[],n=``,r=0;for(let i of e)if(i===`(`)r+=1,n+=i;else if(i===`)`)r=Math.max(0,r-1),n+=i;else if(i===`,`&&r===0){let e=n.trim();e&&t.push(e),n=``}else n+=i;let i=n.trim();return i&&t.push(i),t}function fm(e,t){return e===`linear`?/^\s*to\s+/i.test(t)||/-?\d*\.?\d+deg/i.test(t):/\b(circle|ellipse|closest|farthest)\b/i.test(t)||/\bat\b/i.test(t)}function pm(e){let t=e.trim().match(om);if(!t)return null;let n=t[1],r=e.slice(t[0].length).match(/(-?\d*\.?\d+)%/);return{color:n,offset:r?hm(Number.parseFloat(r[1])/100,0,1):null}}function mm(e){if(e.filter(e=>e.offset!==null).length===0)return e.length===1?[{color:e[0].color,offset:0}]:e.map((t,n)=>({color:t.color,offset:n/(e.length-1)}));let t=e.map(e=>e.offset),n=t.findIndex(e=>e!==null),r=gm(t);for(let e=0;e<n;e+=1){let r=t[n]??0;t[e]=n===0?r:r*e/n}for(let e=r+1;e<t.length;e+=1){let n=t[r]??1,i=t.length-1-r;t[e]=i<=0?n:n+(1-n)*(e-r)/i}let i=n;for(;i<r;){let e=t.findIndex((e,t)=>t>i&&e!==null);if(e===-1)break;let n=t[i]??0,r=t[e]??n,a=e-i;for(let o=i+1;o<e;o+=1)t[o]=n+(r-n)*(o-i)/a;i=e}return e.map((e,n)=>({color:e.color,offset:hm(t[n]??0,0,1)}))}function hm(e,t,n){return Math.min(n,Math.max(t,e))}function gm(e){for(let t=e.length-1;t>=0;--t)if(e[t]!==null)return t;return-1}var _m=`#version 300 es
|
|
535
|
+
in vec2 aPos;
|
|
536
|
+
in vec2 aUV;
|
|
537
|
+
out vec2 vUV;
|
|
538
|
+
uniform mat4 uMvp;
|
|
539
|
+
uniform vec2 uSize;
|
|
540
|
+
void main() {
|
|
541
|
+
vUV = aUV;
|
|
542
|
+
vec2 px = (aPos - 0.5) * uSize;
|
|
543
|
+
vec4 clip = uMvp * vec4(px, 0.0, 1.0);
|
|
544
|
+
clip.y = -clip.y;
|
|
545
|
+
gl_Position = clip;
|
|
546
|
+
}
|
|
547
|
+
`,vm=`#version 300 es
|
|
548
|
+
precision highp float;
|
|
549
|
+
in vec2 vUV;
|
|
550
|
+
out vec4 fragColor;
|
|
551
|
+
uniform sampler2D uTex;
|
|
552
|
+
void main() {
|
|
553
|
+
fragColor = texture(uTex, vUV);
|
|
554
|
+
}
|
|
555
|
+
`;function ym(e){return e*Math.PI/180}function bm(e,t){let n=new Float32Array(16);for(let r=0;r<4;r+=1)for(let i=0;i<4;i+=1){let a=0;for(let n=0;n<4;n+=1)a+=e[n*4+i]*t[r*4+n];n[r*4+i]=a}return n}function xm(e){let t=Math.cos(e),n=Math.sin(e);return new Float32Array([1,0,0,0,0,t,n,0,0,-n,t,0,0,0,0,1])}function Sm(e){let t=Math.cos(e),n=Math.sin(e);return new Float32Array([t,0,-n,0,0,1,0,0,n,0,t,0,0,0,0,1])}function Cm(e){let t=Math.cos(e),n=Math.sin(e);return new Float32Array([t,n,0,0,-n,t,0,0,0,0,1,0,0,0,0,1])}function wm(e,t,n){return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,e,t,n,1])}function Tm(e,t,n,r){let i=1/Math.tan(e/2),a=1/(n-r);return new Float32Array([i/t,0,0,0,0,i,0,0,0,0,(r+n)*a,-1,0,0,2*r*n*a,0])}function Em(e){return new Float32Array([e,0,0,0,0,e,0,0,0,0,1,0,0,0,0,1])}function Dm(e,t,n){let r=xm(ym(e.rotationX)),i=Sm(ym(e.rotationY)),a=bm(Cm(ym(e.rotationZ)),bm(i,r)),o=b(t,n),s=bm(a,Em(w(e,t,n,o))),c=o;return bm(Tm(2*Math.atan2(n/2,c),t/n,.1,c*4+Math.max(t,n)),bm(wm(0,0,-c),s))}function Om(e,t,n){let r=e.createShader(t);if(!r)throw Error(`Failed to create shader`);if(e.shaderSource(r,n),e.compileShader(r),!e.getShaderParameter(r,e.COMPILE_STATUS)){let t=e.getShaderInfoLog(r);throw e.deleteShader(r),Error(`Shader compile failed: ${t}`)}return r}function km(e){let t=Om(e,e.VERTEX_SHADER,_m),n=Om(e,e.FRAGMENT_SHADER,vm),r=e.createProgram();if(!r)throw Error(`Failed to create program`);if(e.attachShader(r,t),e.attachShader(r,n),e.linkProgram(r),!e.getProgramParameter(r,e.LINK_STATUS)){let t=e.getProgramInfoLog(r);throw e.deleteProgram(r),Error(`Program link failed: ${t}`)}return e.deleteShader(t),e.deleteShader(n),r}function Am(e,t){let n=document.createElement(`canvas`);n.width=e,n.height=t;let r=n.getContext(`webgl2`,{premultipliedAlpha:!0,alpha:!0});if(!r)throw Error(`WebGL2 not available for 3D pass`);let i=km(r);r.useProgram(i);let a=r.getAttribLocation(i,`aPos`),o=r.getAttribLocation(i,`aUV`),s=r.getUniformLocation(i,`uMvp`),c=r.getUniformLocation(i,`uSize`),l=r.getUniformLocation(i,`uTex`),u=r.createVertexArray();r.bindVertexArray(u);let d=new Float32Array([0,0,0,1,1,0,1,1,0,1,0,0,0,1,0,0,1,0,1,1,1,1,1,0]),f=r.createBuffer();r.bindBuffer(r.ARRAY_BUFFER,f),r.bufferData(r.ARRAY_BUFFER,d,r.STATIC_DRAW),r.enableVertexAttribArray(a),r.vertexAttribPointer(a,2,r.FLOAT,!1,16,0),r.enableVertexAttribArray(o),r.vertexAttribPointer(o,2,r.FLOAT,!1,16,8);let p=r.createTexture();r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,p),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MIN_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_MAG_FILTER,r.LINEAR),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_S,r.CLAMP_TO_EDGE),r.texParameteri(r.TEXTURE_2D,r.TEXTURE_WRAP_T,r.CLAMP_TO_EDGE);let m=r.getExtension(`EXT_texture_filter_anisotropic`)||r.getExtension(`MOZ_EXT_texture_filter_anisotropic`)||r.getExtension(`WEBKIT_EXT_texture_filter_anisotropic`);if(m){let e=r.getParameter(m.MAX_TEXTURE_MAX_ANISOTROPY_EXT);r.texParameterf(r.TEXTURE_2D,m.TEXTURE_MAX_ANISOTROPY_EXT,Math.min(16,e))}r.uniform1i(l,0);let h={width:e,height:t};return{apply:(e,t)=>{r.viewport(0,0,h.width,h.height),r.clearColor(0,0,0,0),r.clear(r.COLOR_BUFFER_BIT),r.useProgram(i),r.bindVertexArray(u),r.activeTexture(r.TEXTURE0),r.bindTexture(r.TEXTURE_2D,p),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,!0),r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,e);let a=S(t)?Dm({rotationX:0,rotationY:0,rotationZ:0},h.width,h.height):Dm(t,h.width,h.height);return r.uniformMatrix4fv(s,!1,a),r.uniform2f(c,h.width,h.height),r.drawArrays(r.TRIANGLES,0,6),n},readPixels:()=>{let e=h.width,t=h.height,n=new Uint8Array(e*t*4);r.readPixels(0,0,e,t,r.RGBA,r.UNSIGNED_BYTE,n);let i=e*4,a=new Uint8ClampedArray(n.length);for(let e=0;e<t;e+=1){let r=(t-1-e)*i,o=e*i;for(let e=0;e<i;e+=4){let t=n[r+e],i=n[r+e+1],s=n[r+e+2],c=n[r+e+3];if(c===0)a[o+e]=0,a[o+e+1]=0,a[o+e+2]=0,a[o+e+3]=0;else if(c===255)a[o+e]=t,a[o+e+1]=i,a[o+e+2]=s,a[o+e+3]=255;else{let n=255/c;a[o+e]=Math.min(255,Math.round(t*n)),a[o+e+1]=Math.min(255,Math.round(i*n)),a[o+e+2]=Math.min(255,Math.round(s*n)),a[o+e+3]=c}}}return a},resize:(e,t)=>{(e!==h.width||t!==h.height)&&(n.width=e,n.height=t,h={width:e,height:t})},destroy:()=>{r.deleteProgram(i),r.deleteBuffer(f),r.deleteVertexArray(u),r.deleteTexture(p)}}}function jm(e,t,n,r,i=!1){if(i){e.save();try{e.translate(r.x+r.width,r.y),e.scale(-1,1),e.drawImage(t,n.x,n.y,n.width,n.height,0,0,r.width,r.height)}finally{e.restore()}}else e.drawImage(t,n.x,n.y,n.width,n.height,r.x,r.y,r.width,r.height)}var Mm=class{app=null;cameraContainer=null;videoContainer=null;videoSprite=null;backgroundSprite=null;maskGraphics=null;blurFilter=null;motionBlurFilter=null;shadowCanvas=null;shadowCtx=null;compositeCanvas=null;compositeCtx=null;foregroundCanvas=null;foregroundCtx=null;rasterCanvas=null;rasterCtx=null;threeDPass=null;currentRotation3D={..._};cursorImageCache=new Map;warnedKeys=new Set;config;animationState;layoutCache=null;currentVideoTime=0;motionBlurState=kf();nativeCursorMotionBlurState=Ap();smoothedAutoFocus=null;prevAnimationTimeMs=null;zoomSpringState=xf();prevTargetProgress=0;isLinux=!1;constructor(e){this.config=e,this.isLinux=e.platform===`linux`,this.animationState={scale:1,focusX:vd.cx,focusY:vd.cy,progress:0,x:0,y:0,appliedScale:1}}async initialize(){let e=document.createElement(`canvas`);e.width=this.config.width,e.height=this.config.height;try{e&&`colorSpace`in e&&(e.colorSpace=`srgb`)}catch(e){console.warn(`[FrameRenderer] colorSpace not supported on this platform:`,e)}if(this.app=new os,await this.app.init({canvas:e,width:this.config.width,height:this.config.height,backgroundAlpha:0,antialias:!0,resolution:1,autoDensity:!0}),this.cameraContainer=new Hr,this.videoContainer=new Hr,this.app.stage.addChild(this.cameraContainer),this.cameraContainer.addChild(this.videoContainer),await this.setupBackground(),this.blurFilter=new Qu,this.blurFilter.quality=5,this.blurFilter.resolution=this.app.renderer.resolution,this.blurFilter.blur=0,this.motionBlurFilter=new _d([0,0],5,0),this.videoContainer.filters=[this.blurFilter,this.motionBlurFilter],this.compositeCanvas=document.createElement(`canvas`),this.compositeCanvas.width=this.config.width,this.compositeCanvas.height=this.config.height,this.compositeCtx=this.compositeCanvas.getContext(`2d`,{willReadFrequently:this.isLinux}),!this.compositeCtx)throw Error(`Failed to get 2D context for composite canvas`);if(this.rasterCanvas=document.createElement(`canvas`),this.rasterCanvas.width=this.config.width,this.rasterCanvas.height=this.config.height,this.rasterCtx=this.rasterCanvas.getContext(`2d`),!this.rasterCtx)throw Error(`Failed to get 2D context for raster canvas`);if(this.foregroundCanvas=document.createElement(`canvas`),this.foregroundCanvas.width=this.config.width,this.foregroundCanvas.height=this.config.height,this.foregroundCtx=this.foregroundCanvas.getContext(`2d`,{willReadFrequently:this.isLinux}),!this.foregroundCtx)throw Error(`Failed to get 2D context for foreground canvas`);if(this.config.showShadow&&(this.shadowCanvas=document.createElement(`canvas`),this.shadowCanvas.width=this.config.width,this.shadowCanvas.height=this.config.height,this.shadowCtx=this.shadowCanvas.getContext(`2d`,{willReadFrequently:!1}),!this.shadowCtx))throw Error(`Failed to get 2D context for shadow canvas`);this.maskGraphics=new cd,this.videoContainer.addChild(this.maskGraphics),this.videoContainer.mask=this.maskGraphics;try{this.threeDPass=Am(this.config.width,this.config.height)}catch(e){console.warn(`[FrameRenderer] 3D pass unavailable, rotation fields will be ignored:`,e),this.threeDPass=null}}async setupBackground(){let e=this.config.wallpaper,t=document.createElement(`canvas`);t.width=this.config.width,t.height=this.config.height;let n=t.getContext(`2d`),r=je(e);if(r.kind===`color`)n.fillStyle=r.value,n.fillRect(0,0,this.config.width,this.config.height);else if(r.kind===`gradient`){let e=sm(r.value);if(!e)throw new Fe(r.value);let t=e.type===`linear`?(()=>{let t=cm(lm(e.descriptor),this.config.width,this.config.height);return n.createLinearGradient(t.x0,t.y0,t.x1,t.y1)})():(()=>{let t=um(e.descriptor,this.config.width,this.config.height);return n.createRadialGradient(t.cx,t.cy,0,t.cx,t.cy,t.radius)})();e.stops.forEach(e=>{t.addColorStop(e.offset,e.color)}),n.fillStyle=t,n.fillRect(0,0,this.config.width,this.config.height)}else{let e=Pe(r.path),t=new Image;e.startsWith(`http`)&&!e.startsWith(window.location.origin)&&(t.crossOrigin=`anonymous`);try{await new Promise((n,r)=>{t.onload=()=>n(),t.onerror=e=>r(e),t.src=e})}catch(t){throw new Fe(e,t)}let i=t.width/t.height,a=this.config.width/this.config.height,o,s,c,l;i>a?(s=this.config.height,o=s*i,c=(this.config.width-o)/2,l=0):(o=this.config.width,s=o/i,c=0,l=(this.config.height-s)/2),n.drawImage(t,c,l,o,s)}this.backgroundSprite=t}async renderFrame(e,t,n){if(!this.app||!this.videoContainer||!this.cameraContainer)throw Error(`Renderer not initialized`);if(this.currentVideoTime=t/1e6,this.videoSprite){let t=this.videoSprite.texture,n=z.from(e);this.videoSprite.texture=n,t.destroy(!0)}else{let t=z.from(e);this.videoSprite=new Wr(t),this.videoContainer.addChild(this.videoSprite)}this.updateLayout(n);let r=this.currentVideoTime*1e3,i=0;for(let e=0;e<1;e++){let e=this.updateAnimationState(r);i=Math.max(i,e)}let a=this.layoutCache;if(!a)throw Error(`Layout cache not initialized`);Mf({cameraContainer:this.cameraContainer,blurFilter:this.blurFilter,motionBlurFilter:this.motionBlurFilter,stageSize:a.stageSize,baseMask:a.maskRect,zoomScale:this.animationState.scale,zoomProgress:this.animationState.progress,focusX:this.animationState.focusX,focusY:this.animationState.focusY,motionIntensity:i,isPlaying:!0,motionBlurAmount:this.config.motionBlurAmount??0,motionBlurState:this.motionBlurState,frameTimeMs:r,transformOverride:{scale:this.animationState.appliedScale,x:this.animationState.x,y:this.animationState.y}}),this.app.renderer.render(this.app.stage);let o=!S(this.currentRotation3D);if(this.compositeWithShadows(n,!o),await this.drawNativeCursor(r),this.config.annotationRegions&&this.config.annotationRegions.length>0&&this.foregroundCtx){let e=this.config.previewWidth??this.config.width,t=this.config.previewHeight??this.config.height,n=(this.config.width/e+this.config.height/t)/2;await am(this.foregroundCtx,this.config.annotationRegions,this.config.width,this.config.height,r,n)}if(o&&this.threeDPass&&this.foregroundCanvas&&this.foregroundCtx){let e=this.threeDPass.apply(this.foregroundCanvas,this.currentRotation3D),t=this.foregroundCanvas.width,n=this.foregroundCanvas.height;if(this.foregroundCtx.clearRect(0,0,t,n),this.isLinux){let e=this.threeDPass.readPixels(),r=this.foregroundCtx.createImageData(t,n);r.data.set(e),this.foregroundCtx.putImageData(r,0,0)}else this.foregroundCtx.drawImage(e,0,0)}if(o&&this.config.showShadow&&this.config.shadowIntensity>0&&this.shadowCanvas&&this.shadowCtx&&this.foregroundCanvas){let e=this.shadowCtx,t=this.foregroundCanvas.width,n=this.foregroundCanvas.height;e.clearRect(0,0,t,n),e.save();let r=this.config.shadowIntensity,i=48*r,a=16*r,o=8*r,s=.7*r,c=.5*r,l=.3*r,u=12*r;e.filter=`drop-shadow(0 ${u}px ${i}px rgba(0,0,0,${s})) drop-shadow(0 ${u/3}px ${a}px rgba(0,0,0,${c})) drop-shadow(0 ${u/6}px ${o}px rgba(0,0,0,${l}))`,e.drawImage(this.foregroundCanvas,0,0,t,n),e.restore(),this.compositeCtx&&this.compositeCtx.drawImage(this.shadowCanvas,0,0)}else this.compositeCtx&&this.foregroundCanvas&&this.compositeCtx.drawImage(this.foregroundCanvas,0,0)}cameraAwareMaskRect(){if(!this.layoutCache)return null;let{x:e,y:t,width:n,height:r}=this.layoutCache.maskRect,i=this.animationState.appliedScale,a=this.animationState.x,o=this.animationState.y;return{x:a+i*e,y:o+i*t,width:i*n,height:i*r,br:this.layoutCache.maskBorderRadius*i}}async drawNativeCursor(e){if(!this.foregroundCtx||!this.layoutCache)return;if((this.config.cursorScale??1)<=0){jp(this.nativeCursorMotionBlurState);return}let t=Lp(this.config.cursorRecordingData,e);if(!t){jp(this.nativeCursorMotionBlurState);return}let n=tp(this.config.cursorRecordingData,this.config.cursorSmoothing??0)?.sampleAt(e),r=n?{...t.sample,cx:n.cx,cy:n.cy}:t.sample,i=Rp({cropRegion:this.config.cropRegion,maskRect:this.layoutCache.maskRect,sample:r});if(!i){jp(this.nativeCursorMotionBlurState);return}let a=Up(t.asset,1,r,this.config.cursorTheme),o;try{o=await this.getCursorImage(a)}catch(e){this.warnOnce(`native-cursor-image-load`,`Failed to load native cursor asset`,e);return}let s=Math.max(0,this.config.cursorScale??1)*Np(this.config.cursorClickBounce??0,Mp(this.config.cursorRecordingData,e)),c=this.animationState.appliedScale,l=this.layoutCache.videoSize.width>0?this.layoutCache.maskRect.width/this.layoutCache.videoSize.width:1,u=i.x*c+this.animationState.x,d=i.y*c+this.animationState.y,f=Pp({motionBlur:this.config.cursorMotionBlur??0,point:{x:u,y:d},state:this.nativeCursorMotionBlurState,timeMs:e}),p=this.config.cursorClipToBounds===!0?this.cameraAwareMaskRect():null;this.foregroundCtx.save(),this.foregroundCtx.beginPath(),p&&(this.foregroundCtx.roundRect(p.x,p.y,p.width,p.height,p.br),this.foregroundCtx.clip());let m=this.foregroundCtx.filter;f>0&&(this.foregroundCtx.filter=`blur(${f.toFixed(2)}px)`),this.foregroundCtx.drawImage(o,u-a.hotspotX*s*c*l,d-a.hotspotY*s*c*l,a.width*s*c*l,a.height*s*c*l),this.foregroundCtx.filter=m,this.foregroundCtx.restore()}async getCursorImage(e){let t=this.cursorImageCache.get(e.id);if(t)return t;let n=new Image;return await new Promise((t,r)=>{n.onload=()=>t(),n.onerror=()=>r(Error(`Failed to load cursor asset ${e.id}`)),n.src=e.imageDataUrl}),this.cursorImageCache.set(e.id,n),n}warnOnce(e,t,n){this.warnedKeys.has(e)||(this.warnedKeys.add(e),console.warn(`[FrameRenderer] ${t}:`,n))}updateLayout(e){if(!this.app||!this.videoSprite||!this.maskGraphics||!this.videoContainer)return;let{width:t,height:n}=this.config,{cropRegion:r,borderRadius:i=0,padding:a=0}=this.config,o=this.config.videoWidth,s=this.config.videoHeight,c=r.x,l=r.y,u=r.x+r.width,d=r.y+r.height,f=o*(u-c),p=s*(d-l),m=1-(this.config.webcamLayoutPreset===`vertical-stack`?0:a)/100*.4,h=t*m,g=n*m,_=Bf({canvasSize:{width:t,height:n},maxContentSize:{width:h,height:g},screenSize:{width:f,height:p},webcamSize:e?this.config.webcamSize:null,layoutPreset:this.config.webcamLayoutPreset,webcamSizePreset:this.config.webcamSizePreset,webcamPosition:this.config.webcamPosition,webcamMaskShape:this.config.webcamMaskShape});if(!_)return;let v=_.screenRect,y;y=_.screenCover?Math.max(v.width/f,v.height/p):v.width/f,this.videoSprite.width=o*y,this.videoSprite.height=s*y;let b=f*y,x=p*y,S=(v.width-b)/2,C=(v.height-x)/2,w=c*o*y,T=l*s*y;this.videoSprite.x=-w+S,this.videoSprite.y=-T+C,this.videoContainer.x=v.x,this.videoContainer.y=v.y;let E=this.config.previewWidth??this.config.width,D=this.config.previewHeight??this.config.height,O=Math.min(t/E,n/D),k=_.screenBorderRadius==null?_.screenCover?0:i*O:_.screenBorderRadius;this.maskGraphics.clear(),this.maskGraphics.roundRect(0,0,v.width,v.height,k),this.maskGraphics.fill({color:0xffffff}),this.layoutCache={stageSize:{width:t,height:n},videoSize:{width:f,height:p},baseScale:y,baseOffset:{x:_.screenRect.x+S-w,y:_.screenRect.y+C-T},maskRect:_.screenRect,maskBorderRadius:k,webcamRect:_.webcamRect}}updateAnimationState(e){if(!this.cameraContainer||!this.layoutCache)return 0;let{region:t,strength:n,blendedScale:r,rotation3D:i,transition:a}=Jd(this.config.zoomRegions,e,{connectZooms:!0,cursorTelemetry:this.config.cursorTelemetry}),o=vd,s=1,c={...o},l=0;if(this.currentRotation3D=t&&n>0?C(_,i,n):{..._},t&&n>0){let i=r??ae(t),o=kd(t.focus,i);if(s=i,c=o,l=n,t.focusMode===`auto`&&!a){let t=c,n=this.prevAnimationTimeMs==null?0:e-this.prevAnimationTimeMs,r=l<.999&&l>=this.prevTargetProgress;if(l>=.999){let e=wd(this.smoothedAutoFocus??t,t,n,xd);this.smoothedAutoFocus=e,c=e}else if(r)this.smoothedAutoFocus=t;else{let e=wd(this.smoothedAutoFocus??t,t,n,xd);this.smoothedAutoFocus=e,c=e}}else t.focusMode!==`auto`&&(this.smoothedAutoFocus=null);if(this.prevTargetProgress=l,a){let e=Af({stageSize:this.layoutCache.stageSize,baseMask:this.layoutCache.maskRect,zoomScale:a.startScale,zoomProgress:1,focusX:a.startFocus.cx,focusY:a.startFocus.cy}),t=Af({stageSize:this.layoutCache.stageSize,baseMask:this.layoutCache.maskRect,zoomScale:a.endScale,zoomProgress:1,focusX:a.endFocus.cx,focusY:a.endFocus.cy}),n={scale:e.scale+(t.scale-e.scale)*a.progress,x:e.x+(t.x-e.x)*a.progress,y:e.y+(t.y-e.y)*a.progress};s=n.scale,c=jf({stageSize:this.layoutCache.stageSize,baseMask:this.layoutCache.maskRect,zoomScale:n.scale,x:n.x,y:n.y}),l=1}}let u=this.animationState,d=u.appliedScale,f=u.x,p=u.y;u.scale=s,u.focusX=c.cx,u.focusY=c.cy,u.progress=l;let m=Af({stageSize:this.layoutCache.stageSize,baseMask:this.layoutCache.maskRect,zoomScale:u.scale,zoomProgress:u.progress,focusX:u.focusX,focusY:u.focusY}),h=this.prevAnimationTimeMs==null?0:e-this.prevAnimationTimeMs,g,v,y;if(this.prevAnimationTimeMs==null||h<=0||h>80)Sf(this.zoomSpringState,m),g=m.scale,v=m.x,y=m.y;else{let e=wf(this.zoomSpringState,m,h);g=e.scale,v=e.x,y=e.y}return u.x=v,u.y=y,u.appliedScale=g,this.prevAnimationTimeMs=e,Math.max(Math.abs(g-d),Math.abs(v-f)/Math.max(1,this.layoutCache.stageSize.width),Math.abs(y-p)/Math.max(1,this.layoutCache.stageSize.height))}readbackVideoCanvas(){let e=this.app.canvas,t=e.getContext(`webgl2`)??e.getContext(`webgl`);if(!t||!this.rasterCanvas||!this.rasterCtx)return e;let n=e.width,r=e.height,i=new Uint8Array(n*r*4);t.readPixels(0,0,n,r,t.RGBA,t.UNSIGNED_BYTE,i);let a=n*4,o=new Uint8Array(a);for(let e=0,t=r-1;e<t;e++,t--){let n=e*a,r=t*a;o.set(i.subarray(n,n+a)),i.copyWithin(n,r,r+a),i.set(o,r)}let s=new ImageData(new Uint8ClampedArray(i.buffer),n,r);return this.rasterCtx.putImageData(s,0,0),this.rasterCanvas}compositeWithShadows(e,t){if(!this.compositeCanvas||!this.compositeCtx||!this.foregroundCanvas||!this.foregroundCtx||!this.app)return;let n=this.isLinux?this.readbackVideoCanvas():this.app.canvas,r=this.compositeCtx,i=this.foregroundCtx,a=this.compositeCanvas.width,o=this.compositeCanvas.height;if(r.clearRect(0,0,a,o),this.backgroundSprite){let e=this.backgroundSprite;this.config.showBlur?(r.save(),r.filter=`blur(6px)`,r.drawImage(e,0,0,a,o),r.restore()):r.drawImage(e,0,0,a,o)}else console.warn(`[FrameRenderer] No background sprite found during compositing!`);if(i.clearRect(0,0,a,o),t&&this.config.showShadow&&this.config.shadowIntensity>0&&this.shadowCanvas&&this.shadowCtx){let e=this.shadowCtx;e.clearRect(0,0,a,o),e.save();let t=this.config.shadowIntensity,r=48*t,s=16*t,c=8*t,l=.7*t,u=.5*t,d=.3*t,f=12*t;e.filter=`drop-shadow(0 ${f}px ${r}px rgba(0,0,0,${l})) drop-shadow(0 ${f/3}px ${s}px rgba(0,0,0,${u})) drop-shadow(0 ${f/6}px ${c}px rgba(0,0,0,${d}))`,e.drawImage(n,0,0,a,o),e.restore(),i.drawImage(this.shadowCanvas,0,0,a,o)}else i.drawImage(n,0,0,a,o);let s=this.layoutCache?.webcamRect??null;if(e&&s){let t=zf(this.config.webcamLayoutPreset),n=s.maskShape??this.config.webcamMaskShape??`rectangle`,r=this.config.webcamReactiveZoom&&this.config.webcamLayoutPreset===`picture-in-picture`?Pf(this.animationState.appliedScale):1,a=this.config.webcamPosition,o=+(!a||a.cx>=.5),c=+(!a||a.cy>=.5),l=r<1?{width:s.width*r,height:s.height*r,x:s.x+s.width*(1-r)*o,y:s.y+s.height*(1-r)*c,borderRadius:s.borderRadius*r}:s,u=(`displayWidth`in e&&e.displayWidth>0?e.displayWidth:e.codedWidth)||s.width,d=(`displayHeight`in e&&e.displayHeight>0?e.displayHeight:e.codedHeight)||s.height,f=u/d,p=s.width/s.height,m=f>p?Math.round(d*p):u,h=f>p?d:Math.round(u/p),g=Math.max(0,Math.round((u-m)/2)),_=Math.max(0,Math.round((d-h)/2));i.save(),Wp(i,l.x,l.y,l.width,l.height,n,l.borderRadius),t.shadow&&(i.shadowColor=t.shadow.color,i.shadowBlur=t.shadow.blur,i.shadowOffsetX=t.shadow.offsetX,i.shadowOffsetY=t.shadow.offsetY),i.fillStyle=`#000000`,i.fill(),i.clip(),jm(i,e,{x:g,y:_,width:m,height:h},{x:l.x,y:l.y,width:l.width,height:l.height},this.config.webcamMirrored),i.restore()}}getCanvas(){if(!this.compositeCanvas)throw Error(`Renderer not initialized`);return this.compositeCanvas}destroy(){this.videoSprite&&=(this.videoSprite.destroy(),null),this.backgroundSprite=null,this.app&&=(this.app.destroy(!0,{children:!0,texture:!0,textureSource:!0}),null),this.cameraContainer=null,this.videoContainer=null,this.maskGraphics=null,this.blurFilter=null,this.motionBlurFilter=null,this.shadowCanvas=null,this.shadowCtx=null,this.compositeCanvas=null,this.compositeCtx=null,this.foregroundCanvas=null,this.foregroundCtx=null,this.rasterCanvas=null,this.rasterCtx=null,this.threeDPass&&=(this.threeDPass.destroy(),null),this.cursorImageCache.clear()}},Nm=null,Pm=async()=>{if(Nm)return Nm;try{let e=await window.electronAPI.getPlatform();return Nm=e,e}catch(e){console.warn(`Failed to get platform from Electron, falling back to navigator:`,e);let t=`win32`;return typeof navigator<`u`&&(/Mac|iPhone|iPad|iPod/.test(navigator.platform)?t=`darwin`:/Linux/.test(navigator.platform)&&(t=`linux`)),Nm=t,t}},Fm=Object.defineProperty,Im=(e,t,n)=>t in e?Fm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Lm=(e,t,n)=>(Im(e,typeof t==`symbol`?t:t+``,n),n),Rm=(e=>(e[e.AVMEDIA_TYPE_UNKNOWN=-1]=`AVMEDIA_TYPE_UNKNOWN`,e[e.AVMEDIA_TYPE_VIDEO=0]=`AVMEDIA_TYPE_VIDEO`,e[e.AVMEDIA_TYPE_AUDIO=1]=`AVMEDIA_TYPE_AUDIO`,e[e.AVMEDIA_TYPE_DATA=2]=`AVMEDIA_TYPE_DATA`,e[e.AVMEDIA_TYPE_SUBTITLE=3]=`AVMEDIA_TYPE_SUBTITLE`,e[e.AVMEDIA_TYPE_ATTACHMENT=4]=`AVMEDIA_TYPE_ATTACHMENT`,e[e.AVMEDIA_TYPE_NB=5]=`AVMEDIA_TYPE_NB`,e))(Rm||{}),zm=(e=>(e[e.AVSEEK_FLAG_BACKWARD=1]=`AVSEEK_FLAG_BACKWARD`,e[e.AVSEEK_FLAG_BYTE=2]=`AVSEEK_FLAG_BYTE`,e[e.AVSEEK_FLAG_ANY=4]=`AVSEEK_FLAG_ANY`,e[e.AVSEEK_FLAG_FRAME=8]=`AVSEEK_FLAG_FRAME`,e))(zm||{}),Bm=(e=>(e.WasmWorkerLoaded=`WasmWorkerLoaded`,e.WASMRuntimeInitialized=`WASMRuntimeInitialized`,e.LoadWASM=`LoadWASM`,e.GetAVPacket=`GetAVPacket`,e.GetAVPackets=`GetAVPackets`,e.GetAVStream=`GetAVStream`,e.GetAVStreams=`GetAVStreams`,e.GetMediaInfo=`GetMediaInfo`,e.ReadAVPacket=`ReadAVPacket`,e.AVPacketStream=`AVPacketStream`,e.ReadNextAVPacket=`ReadNextAVPacket`,e.StopReadAVPacket=`StopReadAVPacket`,e.SetAVLogLevel=`SetAVLogLevel`,e))(Bm||{}),Vm=`video`,Hm=`audio`,Um=`subtitle`,Wm={VIDEO:Vm,AUDIO:Hm,SUBTITLE:Um},Gm={[Vm]:Rm.AVMEDIA_TYPE_VIDEO,[Hm]:Rm.AVMEDIA_TYPE_AUDIO,[Um]:Rm.AVMEDIA_TYPE_SUBTITLE},Km=`KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO3ZhciBBZT0oRT0+KEVbRS5BVk1FRElBX1RZUEVfVU5LTk9XTj0tMV09IkFWTUVESUFfVFlQRV9VTktOT1dOIixFW0UuQVZNRURJQV9UWVBFX1ZJREVPPTBdPSJBVk1FRElBX1RZUEVfVklERU8iLEVbRS5BVk1FRElBX1RZUEVfQVVESU89MV09IkFWTUVESUFfVFlQRV9BVURJTyIsRVtFLkFWTUVESUFfVFlQRV9EQVRBPTJdPSJBVk1FRElBX1RZUEVfREFUQSIsRVtFLkFWTUVESUFfVFlQRV9TVUJUSVRMRT0zXT0iQVZNRURJQV9UWVBFX1NVQlRJVExFIixFW0UuQVZNRURJQV9UWVBFX0FUVEFDSE1FTlQ9NF09IkFWTUVESUFfVFlQRV9BVFRBQ0hNRU5UIixFW0UuQVZNRURJQV9UWVBFX05CPTVdPSJBVk1FRElBX1RZUEVfTkIiLEUpKShBZXx8e30pLEc9KEU9PihFLldhc21Xb3JrZXJMb2FkZWQ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Ipe2NvbnN0e3NvdXJjZTpDLHRpbWU6ZixzdHJlYW1UeXBlOlUsc3RyZWFtSW5kZXg6SCxzZWVrRmxhZzpuZX09RSxhZT1RLmdldEFWUGFja2V0KEMsZixVLEgsbmUpO3NlbGYucG9zdE1lc3NhZ2Uoe3R5cGU6Ry5HZXRBVlBhY2tldCxtc2dJZDpSLHJlc3VsdDphZX0sW2FlLmRhdGEuYnVmZmVyXSl9ZnVuY3Rpb24gZHQoRSxSKXtjb25zdHtzb3VyY2U6Qyx0aW1lOmYsc2Vla0ZsYWc6VX09RSxIPVEuZ2V0QVZQYWNrZXRzKEMsZixVKTtzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOkcuR2V0QVZQYWNrZXRzLG1zZ0lkOlIscmVzdWx0Okh9LEgubWFwKG5lPT5uZS5kYXRhLmJ1ZmZlcikpfWFzeW5jIGZ1bmN0aW9uIHZ0KEUsUil7Y29uc3R7c291cmNlOkMsc3RhcnQ6ZixlbmQ6VSxzdHJlYW1UeXBlOkgsc3RyZWFtSW5kZXg6bmUsc2Vla0ZsYWc6YWV9PUUsRGU9YXdhaXQgUS5yZWFkQVZQYWNrZXQoUixDLGYsVSxILG5lLGFlKTtzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOkcuUmVhZEFWUGFja2V0LG1zZ0lkOlIscmVzdWx0OkRlfSl9ZnVuY3Rpb24gaHQoRSxSKXtjb25zdHtsZXZlbDpDfT1FO1Euc2V0QVZMb2dMZXZlbChDKSxzZWxmLnBvc3RNZXNzYWdlKHt0eXBlOiJTZXRBVkxvZ0xldmVsIixtc2dJZDpSfSl9fSkoKTsK`,qm=typeof window<`u`&&window.Blob&&new Blob([(e=>Uint8Array.from(atob(e),e=>e.charCodeAt(0)))(Km)],{type:`text/javascript;charset=utf-8`});function Jm(e){let t;try{if(t=qm&&(window.URL||window.webkitURL).createObjectURL(qm),!t)throw``;let n=new Worker(t,{name:e?.name});return n.addEventListener(`error`,()=>{(window.URL||window.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker(`data:text/javascript;base64,`+Km,{name:e?.name})}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}var Ym=1e6,Xm=class{constructor(e){Lm(this,`wasmWorker`),Lm(this,`wasmWorkerLoadStatus`),Lm(this,`msgId`),Lm(this,`source`),this.wasmWorker=new Jm({name:`web-demuxer`}),this.wasmWorkerLoadStatus=new Promise((t,n)=>{this.wasmWorker.addEventListener(`message`,r=>{let{type:i,errMsg:a}=r.data;i===Bm.WasmWorkerLoaded&&this.post(Bm.LoadWASM,{wasmFilePath:e?.wasmFilePath}),i===Bm.WASMRuntimeInitialized&&t(),i===Bm.LoadWASM&&a&&n(a)})}),this.msgId=0}post(e,t,n){this.wasmWorker.postMessage({type:e,msgId:n??this.msgId++,data:t})}getFromWorker(e,t){return new Promise((n,r)=>{if(!this.source){r(`source is not loaded. call load() first`);return}let i=this.msgId,a=t=>{let{data:o}=t;o.type===e&&o.msgId===i&&(o.errMsg?r(o.errMsg):n(o.result),this.wasmWorker.removeEventListener(`message`,a))};this.wasmWorker.addEventListener(`message`,a),this.post(e,t,i)})}async load(e){await this.wasmWorkerLoadStatus,this.source=e}destroy(){this.source=void 0,this.wasmWorker.terminate()}getMediaInfo(){return this.getFromWorker(Bm.GetMediaInfo,{source:this.source})}getAVStream(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Rm.AVMEDIA_TYPE_VIDEO,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:-1;return this.getFromWorker(Bm.GetAVStream,{source:this.source,streamType:e,streamIndex:t})}getAVStreams(){return this.getFromWorker(Bm.GetAVStreams,{source:this.source})}getAVPacket(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:Rm.AVMEDIA_TYPE_VIDEO,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:-1,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:zm.AVSEEK_FLAG_BACKWARD;return this.getFromWorker(Bm.GetAVPacket,{source:this.source,time:e,streamType:t,streamIndex:n,seekFlag:r})}getAVPackets(e){let t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:zm.AVSEEK_FLAG_BACKWARD;return this.getFromWorker(Bm.GetAVPackets,{source:this.source,time:e,seekFlag:t})}readAVPacket(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0,t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:Rm.AVMEDIA_TYPE_VIDEO,r=arguments.length>3&&arguments[3]!==void 0?arguments[3]:-1,i=arguments.length>4&&arguments[4]!==void 0?arguments[4]:zm.AVSEEK_FLAG_BACKWARD,a=new CountQueuingStrategy({highWaterMark:1}),o=this.msgId,s=0,c,l;return new ReadableStream({start:a=>{this.source?(c=e=>{let t=e.data;t.type===Bm.ReadAVPacket&&t.msgId===o&&t.errMsg&&(a.error(t.errMsg),this.wasmWorker.removeEventListener(`message`,c)),t.type===Bm.AVPacketStream&&t.msgId===o&&(t.result&&!l?a.enqueue(t.result):(this.wasmWorker.removeEventListener(`message`,c),l?l():a.close()))},this.wasmWorker.addEventListener(`message`,c),this.post(Bm.ReadAVPacket,{source:this.source,start:e,end:t,streamType:n,streamIndex:r,seekFlag:i})):a.error(`source is not loaded. call load() first`)},pull:()=>{s>0&&this.post(Bm.ReadNextAVPacket,void 0,o),s++},cancel:()=>new Promise(e=>{l=e,this.post(Bm.StopReadAVPacket,void 0,o)})},a)}setLogLevel(e){return this.getFromWorker(Bm.SetAVLogLevel,{level:e})}getMediaStream(e,t){return this.getAVStream(Gm[e],t)}seekMediaPacket(e,t,n){return this.getAVPacket(t,Gm[e],void 0,n)}readMediaPacket(e,t,n,r){return this.readAVPacket(t,n,Gm[e],void 0,r)}genDecoderConfig(e,t){return e===Wm.VIDEO?{codec:t.codec_string,codedWidth:t.width,codedHeight:t.height,description:t.extradata?.length>0?t.extradata:void 0,rotation:t.rotation,flip:t.flip}:{codec:t.codec_string||``,sampleRate:t.sample_rate,numberOfChannels:t.channels,description:t.extradata?.length>0?t.extradata:void 0}}genEncodedChunk(e,t){let n={type:t.keyframe===1?`key`:`delta`,timestamp:t.timestamp*Ym,duration:t.duration*Ym,data:t.data};return e===Wm.VIDEO?new EncodedVideoChunk(n):new EncodedAudioChunk(n)}getDecoderConfig(e){return this.getMediaStream(e).then(t=>this.genDecoderConfig(e,t))}seek(e,t,n){return this.seekMediaPacket(e,t,n).then(t=>this.genEncodedChunk(e,t))}read(e,t,n,r){return this.readMediaPacket(e,t,n,r).pipeThrough(new TransformStream({transform:(t,n)=>{let r=this.genEncodedChunk(e,t);n.enqueue(r)}}))}},Zm=6e4,Qm=.001;function $m(e){let t=`av01.0.01M.08`;if(!e)return t;let n=e instanceof ArrayBuffer?new Uint8Array(e):new Uint8Array(e.buffer,e.byteOffset,e.byteLength);if(n.length<4||!(n[0]&128))return t;let r=n[1]>>5&7,i=n[1]&31,a=n[2]>>7&1,o=n[2]>>6&1,s=n[2]>>5&1,c=8;o&&(c=s?12:10);let l=a?`H`:`M`;return`av01.${r}.${i.toString().padStart(2,`0`)}${l}.${c.toString().padStart(2,`0`)}`}var eh=1,th=2,nh=.25,rh=1.5,ih=86400;function ah(e,t){return t<=0?Number.isFinite(e)?Math.max(e,0):0:!Number.isFinite(e)||e<=0||Math.abs(e-t)>rh?t:e}function oh({cancelled:e,lastDecodedFrameSec:t,requiredEndSec:n,streamDurationSec:r}){if(e||n<=0)return!1;if(t===null)return!0;if(n-t<=eh)return!1;if(typeof r!=`number`||!Number.isFinite(r))return!0;let i=n-r,a=Math.abs(t-r)<=nh,o=Math.max(th,n*.01);return!(a&&i>0&&i<=o)}var sh=class e{demuxer=null;decoder=null;cancelled=!1;metadata=null;async loadSourceFile(t){return!/^(https?:|blob:|data:)/i.test(t)&&window.electronAPI?this.withTimeout(e.loadLocalSourceFile(t),Zm,`Timed out while loading the source video.`):this.withTimeout(e.loadRemoteSourceFile(t),Zm,`Timed out while loading the source video.`)}static async loadLocalSourceFile(e){let t=await window.electronAPI.readBinaryFile(e);if(!t.success||!t.data)throw Error(t.message||t.error||`Failed to read source video`);let n=(t.path||e).split(/[\\/]/).pop()||`video`,r=new Blob([t.data]);return{blob:r,file:new File([r],n,{type:r.type||`application/octet-stream`})}}static async loadRemoteSourceFile(e){let t=await fetch(e);if(!t.ok)throw Error(`Failed to fetch source video: ${t.status} ${t.statusText}`);let n=await t.blob(),r=e.split(`/`).pop()||`video`;return{blob:n,file:new File([n],r,{type:n.type})}}async loadMetadata(e){let{file:t}=await this.loadSourceFile(e),n=new URL(`./wasm/web-demuxer.wasm`,window.location.href).href;this.demuxer=new Xm({wasmFilePath:n}),await this.withTimeout(this.demuxer.load(t),Zm,`Timed out while parsing the source video.`);let r=await this.withTimeout(this.demuxer.getMediaInfo(),Zm,`Timed out while reading video metadata.`),i=r.streams.find(e=>e.codec_type_string===`video`),a=60;if(i?.avg_frame_rate){let e=i.avg_frame_rate.split(`/`);if(e.length===2){let t=parseInt(e[0],10),n=parseInt(e[1],10);n>0&&t>0&&(a=t/n)}}let o=r.streams.find(e=>e.codec_type_string===`audio`),s=Number.isFinite(r.duration)?r.duration:0,c=typeof i?.duration==`number`&&Number.isFinite(i.duration)?i.duration:0,l=Math.max(s,c,0),u=l>0?l+.5:ih,d=0,f=this.demuxer.read(`video`,0,u).getReader();try{for(;;){let{done:e,value:t}=await f.read();if(e||!t)break;let n=t.timestamp+(t.duration??0);n>d&&(d=n)}}finally{try{await f.cancel()}catch{}}let p=d/1e6,m=ah(r.duration,p);return this.metadata={width:i?.width||1920,height:i?.height||1080,duration:m,streamDuration:typeof i?.duration==`number`&&Number.isFinite(i.duration)?i.duration:void 0,frameRate:a,codec:i?.codec_string||`unknown`,hasAudio:!!o,audioCodec:o?.codec_string},this.metadata}async decodeAll(e,t,n,r,i){if(!this.demuxer||!this.metadata)throw Error(`Must call loadMetadata() before decodeAll()`);let a=await this.demuxer.getDecoderConfig(`video`);console.log(`[StreamingVideoDecoder] decoderConfig.codec:`,a.codec),console.log(`[StreamingVideoDecoder] decoderConfig.description:`,a.description),/^av01$/i.test(a.codec)&&(a.codec=$m(a.description)),/^vp08$/i.test(a.codec)&&(a.codec=`vp8`),/^vp09$/i.test(a.codec)&&(a.codec=`vp9`),/^avc1$/i.test(a.codec)&&(a.codec=`avc1.640033`),/^h264$/i.test(a.codec)&&(a.codec=`avc1.640033`);let o=a.codec.toLowerCase(),s=o.includes(`av01`)||o.includes(`av1`)||o.includes(`vp09`)||o.includes(`vp9`),c=this.splitBySpeed(this.computeSegments(this.metadata.duration,t),n),l=c[c.length-1]?.endSec??0,u=c.map(t=>Math.ceil((t.endSec-t.startSec-Qm)/t.speed*e)),d=1e6/e,f=[],p=null,m=null,h=!1;this.decoder=new VideoDecoder({output:e=>{if(p){let t=p;p=null,t(e)}else f.push(e)},error:e=>{if(console.warn(`[StreamingVideoDecoder] decoder error for codec "${a.codec}":`,e.message),m=Error(`VideoDecoder error: ${e.message}`),p){let e=p;p=null,e(null)}}});let g=s?{...a,hardwareAcceleration:`prefer-software`}:a;try{let e=await VideoDecoder.isConfigSupported(g);if(console.log(`[StreamingVideoDecoder] isConfigSupported for "${g.codec}":`,e.supported),!e.supported)throw Error(`Unsupported codec: ${g.codec}`);this.decoder.configure(g)}catch(e){if(s)this.decoder.configure(a);else if(/^avc1/i.test(o)){let e={...a,codec:`avc1.640033`};console.warn(`[StreamingVideoDecoder] codec "${o}" unsupported, falling back to "${e.codec}"`),this.decoder.configure(e)}else throw e}let _=()=>{if(m)throw m;return f.length>0?Promise.resolve(f.shift()):h?Promise.resolve(null):new Promise(e=>{p=e})},v=this.metadata.duration+.5,y=this.demuxer.read(`video`,0,v).getReader(),b=(async()=>{try{for(;!this.cancelled;){let{done:e,value:t}=await y.read();if(e||!t)break;for(;(this.decoder.decodeQueueSize>10||f.length>24)&&!this.cancelled;)await new Promise(e=>setTimeout(e,1));if(this.cancelled)break;this.decoder.decode(t)}!this.cancelled&&this.decoder.state===`configured`&&await this.decoder.flush()}catch(e){m=e instanceof Error?e:Error(String(e))}finally{if(h=!0,p){let e=p;p=null,e(null)}}})(),x=0,S=0,C=0,w=null,T=null,E=0,D=async t=>{if(!T)return!1;let n=u[x];if(S>=n)return!1;let i=t.startSec+S/e*t.speed;return i>=t.endSec-Qm?!1:(await r(new VideoFrame(T,{timestamp:T.timestamp}),C*d,i*1e3),S++,C++,!0)};for(;!this.cancelled&&x<c.length;){let t=await _();if(!t)break;let n=t.timestamp/1e6;for(w=n;x<c.length&&n>=c[x].endSec-Qm;){let e=c[x];for(;!this.cancelled&&await D(e););x++,S=0,T&&x<c.length&&E<c[x].startSec-Qm&&(T.close(),T=null)}if(x>=c.length){t.close();continue}let i=c[x];if(n<i.startSec-Qm){t.close();continue}if(!T){T=t,E=n;continue}let a=(E+n)/2;for(;!this.cancelled;){let t=u[x];if(S>=t)break;let n=i.startSec+S/e*i.speed;if(n>=i.endSec-Qm||n>a)break;await r(new VideoFrame(T,{timestamp:T.timestamp}),C*d,n*1e3),S++,C++}T.close(),T=t,E=n}if(T&&x<c.length){for(;!this.cancelled&&x<c.length;){let e=c[x];if(E<e.startSec-Qm)break;for(;!this.cancelled&&await D(e););if(x++,S=0,x<c.length&&E<c[x].startSec-Qm)break}T.close(),T=null}for(;!h;){let e=await _();if(!e)break;e.close()}try{y.cancel()}catch{}await b;for(let e of f)e.close();if(f.length=0,this.decoder?.state===`configured`&&this.decoder.close(),this.decoder=null,oh({cancelled:this.cancelled,lastDecodedFrameSec:w,requiredEndSec:l,streamDurationSec:this.metadata.streamDuration})){let e=`Decode ended early at ${w===null?`no decoded frame`:`${w.toFixed(3)}s`} (needed ${l.toFixed(3)}s) – export may be slightly shorter than expected.`;console.warn(`[StreamingVideoDecoder] ${e}`),i?.(e)}}computeSegments(e,t){if(!t||t.length===0)return[{startSec:0,endSec:e}];let n=[...t].sort((e,t)=>e.startMs-t.startMs),r=[],i=0;for(let e of n){let t=e.startMs/1e3,n=e.endMs/1e3;i<t&&r.push({startSec:i,endSec:t}),i=n}return i<e&&r.push({startSec:i,endSec:e}),r}getExportMetrics(e,t,n){if(!this.metadata)throw Error(`Must call loadMetadata() first`);let r=this.computeSegments(this.metadata.duration,t),i=this.splitBySpeed(r,n);return{effectiveDuration:i.reduce((e,t)=>e+(t.endSec-t.startSec)/t.speed,0),totalFrames:i.reduce((t,n)=>{let r=n.endSec-n.startSec-Qm;return t+Math.max(0,Math.ceil(r/n.speed*e))},0)}}splitBySpeed(e,t){if(!t||t.length===0)return e.map(e=>({...e,speed:1}));let n=[];for(let r of e){let e=t.filter(e=>e.startMs/1e3<r.endSec&&e.endMs/1e3>r.startSec).sort((e,t)=>e.startMs-t.startMs);if(e.length===0){n.push({...r,speed:1});continue}let i=r.startSec;for(let t of e){let e=Math.max(t.startMs/1e3,r.startSec),a=Math.min(t.endMs/1e3,r.endSec);i<e&&n.push({startSec:i,endSec:e,speed:1}),n.push({startSec:e,endSec:a,speed:t.speed}),i=a}i<r.endSec&&n.push({startSec:i,endSec:r.endSec,speed:1})}return n.filter(e=>e.endSec-e.startSec>1e-4)}getDemuxer(){return this.demuxer}cancel(){this.cancelled=!0}destroy(){if(this.cancelled=!0,this.decoder){try{this.decoder.state===`configured`&&this.decoder.close()}catch{}this.decoder=null}if(this.demuxer){try{this.demuxer.destroy()}catch{}this.demuxer=null}}withTimeout(e,t,n){return new Promise((r,i)=>{let a=window.setTimeout(()=>i(Error(n)),t);e.then(e=>{window.clearTimeout(a),r(e)},e=>{window.clearTimeout(a),i(e)})})}},ch=.5,lh=class{frames=[];consumers=[];error=null;closed=!1;heldFrame=null;get length(){return this.frames.length}enqueue(e,t){if(this.closed){e.close();return}this.frames.push({frame:e,sourceTimestampMs:t});let n=this.consumers.splice(0);for(let e of n)e.resolve()}fail(e){this.error=e,this.closed=!0;let t=this.consumers.splice(0);for(let n of t)n.reject(e);this.closeOwnedFrames()}close(){this.closed=!0;let e=this.consumers.splice(0);for(let t of e)t.resolve()}async frameAt(e){for(;;){if(this.error)throw this.error;let t=this.frames[0]??null;if(t&&t.sourceTimestampMs<=e+ch)this.replaceHeldFrame(this.frames.shift()??null);else{if(this.heldFrame&&(t||this.closed||this.heldFrame.sourceTimestampMs>=e-ch))return new VideoFrame(this.heldFrame.frame,{timestamp:this.heldFrame.frame.timestamp});if(t||this.closed)return null;await new Promise((e,t)=>{this.consumers.push({resolve:e,reject:t})})}}}destroy(){this.close(),this.closeOwnedFrames()}replaceHeldFrame(e){this.heldFrame&&this.heldFrame.frame.close(),this.heldFrame=e}closeOwnedFrames(){this.heldFrame&&=(this.heldFrame.frame.close(),null);for(let e of this.frames)e.frame.close();this.frames=[]}},uh=720,dh=1080;function fh(e){return Math.floor(e/2)*2}function ph(e){return Math.max(2,fh(e))}function mh(e,t,n){let r=n?.width??1,i=n?.height??1;return{width:ph(Math.round(e*r)),height:ph(Math.round(t*i))}}function hh(e,t){if(t>=1){let n=fh(e);return{width:fh(n*t),height:n}}let n=fh(e);return{width:n,height:fh(n/t)}}function gh(e,t,n){let r=Math.max(e,t);if(n===1){let n=fh(Math.min(e,t));return{width:n,height:n}}if(n>1){let e=fh(r);for(let t=e;t>=100;t-=2){let e=Math.round(t/n);if(e%2==0&&Math.abs(t/e-n)<1e-4)return{width:t,height:e}}return{width:e,height:fh(e/n)}}let i=fh(r);for(let e=i;e>=100;e-=2){let t=Math.round(e*n);if(t%2==0&&Math.abs(t/e-n)<1e-4)return{width:t,height:e}}return{width:fh(i*n),height:i}}function _h(e,t,n){let r=e*t;return n===`source`?r>3686400?8e7:r>2073600?5e7:3e7:r<=921600?1e7:r<=2073600?2e7:3e7}function vh({quality:e,sourceWidth:t,sourceHeight:n,aspectRatioValue:r}){if(e===`medium`){let t=hh(uh,r);return{...t,bitrate:_h(t.width,t.height,e)}}if(e===`good`){let t=hh(dh,r);return{...t,bitrate:_h(t.width,t.height,e)}}let i=gh(t,n,r);return{...i,bitrate:_h(i.width,i.height,e)}}function W(e){if(!e)throw Error(`Assertion failed.`)}var yh=Math.PI/180,bh=[1,0,0,0,1,0,0,0,1],xh=(e,t,n)=>{let[r,i,,a,o]=e,s=Math.abs(r)*t+Math.abs(a)*n,c=Math.abs(i)*t+Math.abs(o)*n;return Th(Th(Ch(-t/2,-n/2),e),Ch(s/2,c/2))},Sh=e=>{let t=e*yh,n=Math.round(Math.cos(t)),r=Math.round(Math.sin(t));return[n,r,0,-r,n,0,0,0,1]},Ch=(e,t)=>[1,0,0,0,1,0,e,t,1],wh=(e,t)=>[e,0,0,0,t,0,0,0,1],Th=(e,t)=>{let n=Array(9);for(let r=0;r<3;r++)for(let i=0;i<3;i++)n[3*r+i]=e[3*r]*t[i]+e[3*r+1]*t[3+i]+e[3*r+2]*t[6+i];return n},Eh=e=>e&&e[e.length-1],Dh=e=>e>=0&&e<2**32,Oh=e=>e>=-(2**31)&&e<2**31,G=e=>{let t=0;for(;e.readBits(1)===0&&t<32;)t++;if(t>=32)throw Error(`Invalid exponential-Golomb code.`);return 2**t-1+e.readBits(t)},kh=e=>{let t=G(e);return t%2==0?-(t/2):(t+1)/2},Ah=e=>e.constructor===Uint8Array?e:ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e),jh=e=>e.constructor===DataView?e:ArrayBuffer.isView(e)?new DataView(e.buffer,e.byteOffset,e.byteLength):new DataView(e),Mh=new(globalThis.TextEncoder===void 0?class{constructor(){this.encoding=`utf-8`}encode(e=``){let t=new Uint8Array(3*e.length),n=0;for(let r=0;r<e.length;r++){let i=e.charCodeAt(r);if(i<128)t[n++]=i;else if(i<2048)t[n++]=192|i>>6,t[n++]=128|i&63;else if(i<55296||i>57343)t[n++]=224|i>>12,t[n++]=128|i>>6&63,t[n++]=128|i&63;else{let a=r+1<e.length?e.charCodeAt(r+1):0;i<56320&&a>=56320&&a<=57343?(i=65536+(i-55296<<10)+(a-56320),r++,t[n++]=240|i>>18,t[n++]=128|i>>12&63,t[n++]=128|i>>6&63,t[n++]=128|i&63):(t[n++]=239,t[n++]=191,t[n++]=189)}}return t.slice(0,n)}}:globalThis.TextEncoder),Nh={bt709:1,bt470bg:5,smpte170m:6,bt2020:9,smpte432:12},Ph={bt709:1,smpte170m:6,linear:8,"iec61966-2-1":13,pq:16,hlg:18},Fh={rgb:0,bt709:1,bt470bg:5,smpte170m:6,"bt2020-ncl":9},Ih=e=>!e||e.primaries==null&&e.transfer==null&&e.matrix==null&&e.fullRange==null,Lh=e=>e instanceof ArrayBuffer||typeof SharedArrayBuffer<`u`&&e instanceof SharedArrayBuffer||ArrayBuffer.isView(e),Rh=class{constructor(){this.currentPromise=Promise.resolve(),this.pending=0}async acquire(){let e,t=new Promise(t=>{let n=!1;e=()=>{n||=(t(),this.pending--,!0)}}),n=this.currentPromise;return this.currentPromise=t,this.pending++,await n,e}},zh=()=>{let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}},Bh=e=>{throw Error(`Unexpected value: ${e}`)},Vh=(e,t,n,r)=>{n>>>=0,n&=0xffffff,r?(e.setUint8(t,n&255),e.setUint8(t+1,n>>>8&255),e.setUint8(t+2,n>>>16&255)):(e.setUint8(t,n>>>16&255),e.setUint8(t+1,n>>>8&255),e.setUint8(t+2,n&255))},Hh=e=>{let t=0;for(;e!==0;)e&=e-1,t++;return t},Uh=/^[a-z]{3}$/,Wh=e=>Uh.test(e),Gh=1e6*(1+2**-52),Kh=(e,t)=>{let n=e<0?-1:1;e=Math.abs(e);let r=0,i=1,a=1,o=0,s=e;for(;;){let e=Math.floor(s),c=e*a+r,l=e*o+i;if(l>t)return{num:n*a,den:o};if(r=a,i=o,a=c,o=l,s=1/(s-e),!isFinite(s))break}return{num:n*a,den:o}},qh=(async()=>{})().constructor,Jh=e=>e instanceof qh||e instanceof Promise||typeof e?.then==`function`,Yh=function*(e){for(let t in e){let n=e[t];n!==void 0&&(yield{key:t,value:n})}},Xh=e=>typeof e==`number`&&!Number.isNaN(e),Zh=e=>{W(Number.isInteger(e.num)),W(Number.isInteger(e.den)),W(e.den!==0);let t=Math.abs(e.num),n=Math.abs(e.den);for(;n!==0;){let e=t%n;t=n,n=e}let r=t||1;return{num:e.num/r,den:e.den/r}},Qh=e=>Array.isArray(e)?e:[e],$h=class{constructor(){this._listeners=new Map}on(e,t,n){this._listeners.has(e)||this._listeners.set(e,new Set);let r={fn:t,once:n?.once??!1};return this._listeners.get(e).add(r),()=>{this._listeners.get(e)?.delete(r)}}_emit(...e){let[t,n]=e,r=this._listeners.get(t);if(r){for(let e of[...r])if(r.has(e)){e.once&&r.delete(e);try{e.fn(n)}catch(e){console.error(e)}}}}},eg=e=>typeof e==`object`&&!!e&&Object.getPrototypeOf(e)===Object.prototype&&Object.values(e).every(e=>typeof e==`string`),tg;(function(e){e[e.Silent=0]=`Silent`,e[e.Errors=1]=`Errors`,e[e.Warnings=2]=`Warnings`,e[e.Info=3]=`Info`})(tg||={});var ng=class e{constructor(){}static get level(){return e._level}static set level(t){if(t!==tg.Silent&&t!==tg.Errors&&t!==tg.Warnings&&t!==tg.Info)throw TypeError(`Invalid log level. Use one of the values of the LogLevel enum.`);e._level=t}static get _emitter(){return e._emitterInstance??=new $h}static on(t,n,r){return e._emitter.on(t,n,r)}static _error(...t){e._emitter._emit(`error`,t),e._level>=tg.Errors&&console.error(...t)}static _warn(...t){e._emitter._emit(`warn`,t),e._level>=tg.Warnings&&console.warn(...t)}static _info(...t){e._emitter._emit(`info`,t),e._level>=tg.Info&&console.info(...t)}};ng._level=tg.Info,ng._emitterInstance=null;var rg=class{constructor(e,t){if(this.data=e,this.mimeType=t,!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(typeof t!=`string`)throw TypeError(`mimeType must be a string.`)}},ig=class{constructor(e,t,n,r){if(this.data=e,this.mimeType=t,this.name=n,this.description=r,!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(t!==void 0&&typeof t!=`string`)throw TypeError(`mimeType, when provided, must be a string.`);if(n!==void 0&&typeof n!=`string`)throw TypeError(`name, when provided, must be a string.`);if(r!==void 0&&typeof r!=`string`)throw TypeError(`description, when provided, must be a string.`)}},ag=e=>{if(!e||typeof e!=`object`)throw TypeError(`tags must be an object.`);if(e.title!==void 0&&typeof e.title!=`string`)throw TypeError(`tags.title, when provided, must be a string.`);if(e.description!==void 0&&typeof e.description!=`string`)throw TypeError(`tags.description, when provided, must be a string.`);if(e.artist!==void 0&&typeof e.artist!=`string`)throw TypeError(`tags.artist, when provided, must be a string.`);if(e.album!==void 0&&typeof e.album!=`string`)throw TypeError(`tags.album, when provided, must be a string.`);if(e.albumArtist!==void 0&&typeof e.albumArtist!=`string`)throw TypeError(`tags.albumArtist, when provided, must be a string.`);if(e.trackNumber!==void 0&&(!Number.isInteger(e.trackNumber)||e.trackNumber<=0))throw TypeError(`tags.trackNumber, when provided, must be a positive integer.`);if(e.tracksTotal!==void 0&&(!Number.isInteger(e.tracksTotal)||e.tracksTotal<=0))throw TypeError(`tags.tracksTotal, when provided, must be a positive integer.`);if(e.discNumber!==void 0&&(!Number.isInteger(e.discNumber)||e.discNumber<=0))throw TypeError(`tags.discNumber, when provided, must be a positive integer.`);if(e.discsTotal!==void 0&&(!Number.isInteger(e.discsTotal)||e.discsTotal<=0))throw TypeError(`tags.discsTotal, when provided, must be a positive integer.`);if(e.genre!==void 0&&typeof e.genre!=`string`)throw TypeError(`tags.genre, when provided, must be a string.`);if(e.date!==void 0&&(!(e.date instanceof Date)||Number.isNaN(e.date.getTime())))throw TypeError(`tags.date, when provided, must be a valid Date.`);if(e.creationTime!==void 0&&e.creationTime!==null&&(!(e.creationTime instanceof Date)||Number.isNaN(e.creationTime.getTime())))throw TypeError(`tags.creationTime, when provided, must be a valid Date or null.`);if(e.beatsPerMinute!==void 0&&(!Number.isInteger(e.beatsPerMinute)||e.beatsPerMinute<=0))throw TypeError(`tags.beatsPerMinute, when provided, must be a positive integer.`);if(e.lyrics!==void 0&&typeof e.lyrics!=`string`)throw TypeError(`tags.lyrics, when provided, must be a string.`);if(e.images!==void 0){if(!Array.isArray(e.images))throw TypeError(`tags.images, when provided, must be an array.`);for(let t of e.images){if(!t||typeof t!=`object`)throw TypeError(`Each image in tags.images must be an object.`);if(!(t.data instanceof Uint8Array))throw TypeError(`Each image.data must be a Uint8Array.`);if(typeof t.mimeType!=`string`)throw TypeError(`Each image.mimeType must be a string.`);if(![`coverFront`,`coverBack`,`unknown`].includes(t.kind))throw TypeError(`Each image.kind must be 'coverFront', 'coverBack', or 'unknown'.`);if(t.name!==void 0&&typeof t.name!=`string`)throw TypeError(`Each image.name, when provided, must be a string.`);if(t.description!==void 0&&typeof t.description!=`string`)throw TypeError(`Each image.description, when provided, must be a string.`)}}if(e.comment!==void 0&&typeof e.comment!=`string`)throw TypeError(`tags.comment, when provided, must be a string.`);if(e.raw!==void 0){if(!e.raw||typeof e.raw!=`object`)throw TypeError(`tags.raw, when provided, must be an object.`);for(let t of Object.values(e.raw))if(t!==null&&typeof t!=`string`&&!(Array.isArray(t)&&t.every(e=>typeof e==`string`))&&!(t instanceof Uint8Array)&&!(Array.isArray(t)&&t.every(e=>e instanceof Uint8Array))&&!(t instanceof rg)&&!(t instanceof ig)&&!eg(t))throw TypeError(`Each value in tags.raw must be a string, string array, Uint8Array, Uint8Array array, RichImageData, AttachedFile, Record<string, string>, or null.`)}},og=e=>{if(!e||typeof e!=`object`)throw TypeError(`disposition must be an object.`);if(e.default!==void 0&&typeof e.default!=`boolean`)throw TypeError(`disposition.default must be a boolean.`);if(e.primary!==void 0&&typeof e.primary!=`boolean`)throw TypeError(`disposition.primary must be a boolean.`);if(e.forced!==void 0&&typeof e.forced!=`boolean`)throw TypeError(`disposition.forced must be a boolean.`);if(e.original!==void 0&&typeof e.original!=`boolean`)throw TypeError(`disposition.original must be a boolean.`);if(e.commentary!==void 0&&typeof e.commentary!=`boolean`)throw TypeError(`disposition.commentary must be a boolean.`);if(e.hearingImpaired!==void 0&&typeof e.hearingImpaired!=`boolean`)throw TypeError(`disposition.hearingImpaired must be a boolean.`);if(e.visuallyImpaired!==void 0&&typeof e.visuallyImpaired!=`boolean`)throw TypeError(`disposition.visuallyImpaired must be a boolean.`)},sg=class e{constructor(e){this.bytes=e,this.pos=0}seekToByte(e){this.pos=8*e}readBit(){let e=Math.floor(this.pos/8),t=this.bytes[e]??0,n=7-(this.pos&7),r=(t&1<<n)>>n;return this.pos++,r}readBits(e){if(e===1)return this.readBit();let t=0;for(let n=0;n<e;n++)t=2*t+this.readBit();return t}writeBits(e,t){let n=this.pos+e;for(let e=this.pos;e<n;e++){let r=Math.floor(e/8),i=this.bytes[r],a=7-(e&7),o=Math.floor(t/2**(n-e-1))&1;i&=~(1<<a),i|=o<<a,this.bytes[r]=i}this.pos=n}copyBits(e,t){let n=0;for(;n<e-7;n+=8)this.writeBits(8,t.readBits(8));let r=e-n;r>0&&this.writeBits(r,t.readBits(r))}readAlignedByte(){if(this.pos%8!=0)throw Error(`Bitstream is not byte-aligned.`);let e=this.pos/8,t=this.bytes[e]??0;return this.pos+=8,t}skipBits(e){this.pos+=e}getBitsLeft(){return this.bytes.length*8-this.pos}clone(){let t=new e(this.bytes);return t.pos=this.pos,t}},cg=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350],lg=[-1,1,2,3,4,5,6,8],ug=e=>{let t=e.objectType===5||e.objectType===29,n=e.objectType===29,r=t?e.outputSampleRate/2:e.outputSampleRate,i=n?1:e.outputNumberOfChannels,a=e.programConfigElement?0:lg.indexOf(i);if(a===-1)throw TypeError(`Unsupported number of channels: ${e.outputNumberOfChannels}`);let o=16;e.objectType>=32&&(o+=6),pg(r)===15&&(o+=24),t&&(o+=9,pg(e.outputSampleRate)===15&&(o+=24));let s=Math.ceil(o/8)+(e.programConfigElement?mg(e.programConfigElement):0),c=new Uint8Array(s),l=new sg(c);return dg(l,e.objectType),fg(l,r),l.writeBits(4,a),t&&(fg(l,e.outputSampleRate),dg(l,2)),l.writeBits(3,0),e.programConfigElement&&hg(l,e.programConfigElement),c.subarray(0,Math.ceil(l.pos/8))},dg=(e,t)=>{t<32?e.writeBits(5,t):(e.writeBits(5,31),e.writeBits(6,t-32))},fg=(e,t)=>{let n=pg(t);e.writeBits(4,n),n===15&&e.writeBits(24,t)},pg=e=>{let t=cg.indexOf(e);return t===-1?15:t},mg=e=>64+e.comment.byteLength,hg=(e,t)=>{e.writeBits(4,t.elementInstanceTag),e.writeBits(2,t.objectType),e.writeBits(4,t.samplingFrequencyIndex),e.writeBits(4,t.frontElements.length),e.writeBits(4,t.sideElements.length),e.writeBits(4,t.backElements.length),e.writeBits(2,t.lfeElementTags.length),e.writeBits(3,t.assocDataElementTags.length),e.writeBits(4,t.ccElements.length),e.writeBits(1,+(t.monoMixdownElementNumber!==null)),t.monoMixdownElementNumber!==null&&e.writeBits(4,t.monoMixdownElementNumber),e.writeBits(1,+(t.stereoMixdownElementNumber!==null)),t.stereoMixdownElementNumber!==null&&e.writeBits(4,t.stereoMixdownElementNumber),e.writeBits(1,+(t.matrixMixdown!==null)),t.matrixMixdown&&(e.writeBits(2,t.matrixMixdown.index),e.writeBits(1,+t.matrixMixdown.pseudoSurroundEnabled));for(let n of[...t.frontElements,...t.sideElements,...t.backElements])e.writeBits(1,+n.isCpe),e.writeBits(4,n.tagSelect);for(let n of[...t.lfeElementTags,...t.assocDataElementTags])e.writeBits(4,n);for(let n of t.ccElements)e.writeBits(1,+n.isIndependentlySwitched),e.writeBits(4,n.tagSelect);e.pos=8*Math.ceil(e.pos/8),e.writeBits(8,t.comment.byteLength),e.bytes.set(t.comment,e.pos/8),e.pos+=8*t.comment.byteLength},gg=e=>{let t=new sg(e);if(t.readBits(3)!==5)return null;let n=_g(t),r=t.pos/8;if(r>e.byteLength)throw Error(`Invalid ADTS frame: its program config element extends past the end of the frame.`);return{programConfigElement:n,size:r}},_g=e=>{let t=e.readBits(4),n=e.readBits(2),r=e.readBits(4),i=e.readBits(4),a=e.readBits(4),o=e.readBits(4),s=e.readBits(2),c=e.readBits(3),l=e.readBits(4),u=e.readBits(1)?e.readBits(4):null,d=e.readBits(1)?e.readBits(4):null,f=e.readBits(1)?{index:e.readBits(2),pseudoSurroundEnabled:!!e.readBits(1)}:null,p=t=>Array.from({length:t},()=>({isCpe:!!e.readBits(1),tagSelect:e.readBits(4)})),m=p(i),h=p(a),g=p(o),_=Array.from({length:s},()=>e.readBits(4)),v=Array.from({length:c},()=>e.readBits(4)),y=Array.from({length:l},()=>({isIndependentlySwitched:!!e.readBits(1),tagSelect:e.readBits(4)}));e.pos=8*Math.ceil(e.pos/8);let b=e.readBits(8),x=e.bytes.slice(e.pos/8,e.pos/8+b);return e.pos+=8*b,{elementInstanceTag:t,objectType:n,samplingFrequencyIndex:r,frontElements:m,sideElements:h,backElements:g,lfeElementTags:_,assocDataElementTags:v,ccElements:y,monoMixdownElementNumber:u,stereoMixdownElementNumber:d,matrixMixdown:f,comment:x}},vg=e=>[...e.frontElements,...e.sideElements,...e.backElements].reduce((e,t)=>e+(t.isCpe?2:1),e.lfeElementTags.length),yg=[48e3,44100,32e3],bg=[24e3,22050,16e3],xg=`Mediabunny v1.66.5`,Sg;(function(e){e[e.NON_IDR_SLICE=1]=`NON_IDR_SLICE`,e[e.SLICE_DPA=2]=`SLICE_DPA`,e[e.SLICE_DPB=3]=`SLICE_DPB`,e[e.SLICE_DPC=4]=`SLICE_DPC`,e[e.IDR=5]=`IDR`,e[e.SEI=6]=`SEI`,e[e.SPS=7]=`SPS`,e[e.PPS=8]=`PPS`,e[e.AUD=9]=`AUD`,e[e.SPS_EXT=13]=`SPS_EXT`})(Sg||={});var Cg;(function(e){e[e.RASL_N=8]=`RASL_N`,e[e.RASL_R=9]=`RASL_R`,e[e.BLA_W_LP=16]=`BLA_W_LP`,e[e.RSV_IRAP_VCL23=23]=`RSV_IRAP_VCL23`,e[e.VPS_NUT=32]=`VPS_NUT`,e[e.SPS_NUT=33]=`SPS_NUT`,e[e.PPS_NUT=34]=`PPS_NUT`,e[e.AUD_NUT=35]=`AUD_NUT`,e[e.PREFIX_SEI_NUT=39]=`PREFIX_SEI_NUT`,e[e.SUFFIX_SEI_NUT=40]=`SUFFIX_SEI_NUT`})(Cg||={});var wg=function*(e){let t=0,n=-1;for(;t<e.length-2;){let r=e.indexOf(0,t);if(r===-1||r>=e.length-2)break;t=r;let i=0;t+3<e.length&&e[t+1]===0&&e[t+2]===0&&e[t+3]===1?i=4:e[t+1]===0&&e[t+2]===1&&(i=3),i===0?t++:(n!==-1&&t>n&&(yield{offset:n,length:t-n}),n=t+i,t=n)}n!==-1&&n<e.length&&(yield{offset:n,length:e.length-n})},Tg=e=>e&31,Eg=e=>{let t=new Uint8Array(e.length),n=e.length,r=0;for(let i=0;i<n;i++)i+2<n&&e[i]===0&&e[i+1]===0&&e[i+2]===3?(t[r++]=0,t[r++]=0,i+=2):t[r++]=e[i];return t.subarray(0,r)};new Uint8Array([0,0,0,1]);var Dg=(e,t)=>{let n=e.reduce((e,n)=>e+t+n.byteLength,0),r=new Uint8Array(n),i=0;for(let n of e){let e=new DataView(r.buffer,r.byteOffset,r.byteLength);switch(t){case 1:e.setUint8(i,n.byteLength);break;case 2:e.setUint16(i,n.byteLength,!1);break;case 3:Vh(e,i,n.byteLength,!1);break;case 4:e.setUint32(i,n.byteLength,!1)}i+=t,r.set(n,i),i+=n.byteLength}return r},Og=e=>{try{let t=[],n=[],r=[];for(let i of wg(e)){let a=e.subarray(i.offset,i.offset+i.length),o=Tg(a[0]);o===Sg.SPS&&t.length<31?t.push(a):o===Sg.PPS&&n.length<255?n.push(a):o===Sg.SPS_EXT&&r.length<255&&r.push(a)}if(t.length===0||n.length===0)return null;let i=Mg(t[0]);if(!i)return null;let a=Ag(i.profileIdc);return{configurationVersion:1,avcProfileIndication:i.profileIdc,profileCompatibility:i.constraintFlags,avcLevelIndication:i.levelIdc,lengthSizeMinusOne:3,sequenceParameterSets:t,pictureParameterSets:n,chromaFormat:a?i.chromaFormatIdc:null,bitDepthLumaMinus8:a?i.bitDepthLumaMinus8:null,bitDepthChromaMinus8:a?i.bitDepthChromaMinus8:null,sequenceParameterSetExt:a?r:null}}catch(e){return ng._error(`Error building AVC Decoder Configuration Record:`,e),null}},kg=e=>{let t=[];t.push(e.configurationVersion),t.push(e.avcProfileIndication),t.push(e.profileCompatibility),t.push(e.avcLevelIndication),t.push(252|e.lengthSizeMinusOne&3),t.push(224|e.sequenceParameterSets.length&31);for(let n of e.sequenceParameterSets){let e=n.byteLength;t.push(e>>8),t.push(e&255);for(let r=0;r<e;r++)t.push(n[r])}t.push(e.pictureParameterSets.length);for(let n of e.pictureParameterSets){let e=n.byteLength;t.push(e>>8),t.push(e&255);for(let r=0;r<e;r++)t.push(n[r])}if(Ag(e.avcProfileIndication)&&e.chromaFormat!==null){W(e.bitDepthLumaMinus8!==null),W(e.bitDepthChromaMinus8!==null),W(e.sequenceParameterSetExt!==null),t.push(252|e.chromaFormat&3),t.push(248|e.bitDepthLumaMinus8&7),t.push(248|e.bitDepthChromaMinus8&7),t.push(e.sequenceParameterSetExt.length);for(let n of e.sequenceParameterSetExt){let e=n.byteLength;t.push(e>>8),t.push(e&255);for(let r=0;r<e;r++)t.push(n[r])}}return new Uint8Array(t)},Ag=e=>e!==66&&e!==77&&e!==88,jg={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}},Mg=e=>{try{let t=Eg(e),n=new sg(t);if(n.skipBits(1),n.skipBits(2),n.readBits(5)!==7)return null;let r=n.readAlignedByte(),i=n.readAlignedByte(),a=n.readAlignedByte();G(n);let o=1,s=0,c=0,l=0;if((r===100||r===110||r===122||r===244||r===44||r===83||r===86||r===118||r===128||r===138||r===139||r===134||r===135||r===144)&&(o=G(n),o===3&&(l=n.readBits(1)),s=G(n),c=G(n),n.skipBits(1),n.readBits(1))){for(let e=0;e<(o===3?12:8);e++)if(n.readBits(1)){let t=e<6?16:64,r=8,i=8;for(let e=0;e<t;e++){if(i!==0){let e=kh(n);i=(r+e+256)%256}r=i===0?r:i}}}G(n);let u=G(n);if(u===0)G(n);else if(u===1){n.skipBits(1),kh(n),kh(n);let e=G(n);for(let t=0;t<e;t++)kh(n)}let d=G(n);n.skipBits(1);let f=G(n),p=G(n),m=n.readBits(1);m||n.skipBits(1);let h=16*(f+1),g=16*(2-m)*(p+1),_=h,v=g;if(n.skipBits(1),n.readBits(1)){let e=G(n),t=G(n),r=G(n),i=G(n),a,s;if((l===0?o:0)===0)a=1,s=2-m;else{let e=o===3?1:2,t=o===1?2:1;a=e,s=t*(2-m)}_-=a*(e+t),v-=s*(r+i)}if(_<=0||v<=0)return null;let y=2,b=2,x=2,S=0,C={num:1,den:1},w=null,T=null,E=null,D=null,O=n.pos;if(n.readBits(1)){if(n.readBits(1)){let e=n.readBits(8);if(e===255)C={num:n.readBits(16),den:n.readBits(16)};else{let t=jg[e];t&&(C=t)}}n.readBits(1)&&n.skipBits(1),n.readBits(1)&&(n.skipBits(3),S=n.readBits(1),n.readBits(1)&&(y=n.readBits(8),b=n.readBits(8),x=n.readBits(8))),n.readBits(1)&&(G(n),G(n)),n.readBits(1)&&(n.skipBits(32),n.skipBits(32),n.skipBits(1));let e=n.readBits(1);e&&Ng(n);let t=n.readBits(1);t&&Ng(n),(e||t)&&n.skipBits(1),n.skipBits(1),E=n.pos,D=n.readBits(1),D&&(n.skipBits(1),G(n),G(n),G(n),G(n),w=Math.min(G(n),16),T=Math.min(G(n),16))}if(w===null){W(T===null);let e=i&16;if((r===44||r===86||r===100||r===110||r===122||r===244)&&e)w=0,T=0;else{let t=f+1,n=p+1,i=(2-m)*n,o=a===11&&e&&(r===66||r===77||r===88),s=B_.find(e=>e.level>=(o?10:a))??Eh(B_),c=Math.min(Math.floor(s.maxDpbMbs/(t*i)),16);w=c,T=Math.min(Math.max(c,d),16)}}return W(T!==null),{emulationUnpreventedBytes:t,profileIdc:r,constraintFlags:i,levelIdc:a,frameMbsOnlyFlag:m,chromaFormatIdc:o,bitDepthLumaMinus8:s,bitDepthChromaMinus8:c,codedWidth:h,codedHeight:g,displayWidth:_,displayHeight:v,pixelAspectRatio:C,colourPrimaries:y,matrixCoefficients:x,transferCharacteristics:b,fullRangeFlag:S,numReorderFrames:w,maxDecFrameBuffering:T,vuiParametersFlagBitOffset:O,bitstreamRestrictionFlagBitOffset:E,bitstreamRestrictionFlag:D}}catch(e){return ng._error(`Error parsing AVC SPS:`,e),null}},Ng=e=>{let t=G(e);e.skipBits(4),e.skipBits(4);for(let n=0;n<=t;n++)G(e),G(e),e.skipBits(1);e.skipBits(5),e.skipBits(5),e.skipBits(5),e.skipBits(5)},Pg=e=>e>>1&63,Fg=e=>{try{let t=new sg(Eg(e));t.skipBits(16),t.readBits(4);let n=t.readBits(3),r=t.readBits(1),{general_profile_space:i,general_tier_flag:a,general_profile_idc:o,general_profile_compatibility_flags:s,general_constraint_indicator_flags:c,general_level_idc:l}=Lg(t,n);G(t);let u=G(t),d=0;u===3&&(d=t.readBits(1));let f=G(t),p=G(t),m=f,h=p;if(t.readBits(1)){let e=G(t),n=G(t),r=G(t),i=G(t),a=1,o=1,s=d===0?u:0;s===1?(a=2,o=2):s===2&&(a=2,o=1),m-=(e+n)*a,h-=(r+i)*o}if(m<=0||h<=0)return null;let g=G(t),_=G(t),v=G(t),y=t.readBits(1)?0:n,b=0;for(let e=y;e<=n;e++)G(t),b=G(t),G(t);if(G(t),G(t),G(t),G(t),G(t),G(t),t.readBits(1)&&t.readBits(1)&&Rg(t),t.skipBits(1),t.skipBits(1),t.readBits(1)&&(t.skipBits(4),t.skipBits(4),G(t),G(t),t.skipBits(1)),zg(t,G(t)),t.readBits(1)){let e=G(t);for(let n=0;n<e;n++)t.skipBits(v+4),t.skipBits(1)}t.skipBits(1),t.skipBits(1);let x=2,S=2,C=2,w=0,T=0,E={num:1,den:1};if(t.readBits(1)){let e=Vg(t,n);E=e.pixelAspectRatio,x=e.colourPrimaries,S=e.transferCharacteristics,C=e.matrixCoefficients,w=e.fullRangeFlag,T=e.minSpatialSegmentationIdc}return{displayWidth:m,displayHeight:h,pixelAspectRatio:E,colourPrimaries:x,transferCharacteristics:S,matrixCoefficients:C,fullRangeFlag:w,maxDecFrameBuffering:Math.min(b+1,16),spsMaxSubLayersMinus1:n,spsTemporalIdNestingFlag:r,generalProfileSpace:i,generalTierFlag:a,generalProfileIdc:o,generalProfileCompatibilityFlags:s,generalConstraintIndicatorFlags:c,generalLevelIdc:l,chromaFormatIdc:u,bitDepthLumaMinus8:g,bitDepthChromaMinus8:_,minSpatialSegmentationIdc:T}}catch(e){return ng._error(`Error parsing HEVC SPS:`,e),null}},Ig=e=>{try{let t=[],n=[],r=[],i=[],a=[],o=65535;for(let s of wg(e)){let c=e.subarray(s.offset,s.offset+s.length),l=Pg(c[0]);l===Cg.VPS_NUT&&t.length<o?t.push(c):l===Cg.SPS_NUT&&n.length<o?n.push(c):l===Cg.PPS_NUT&&r.length<o?r.push(c):l===Cg.PREFIX_SEI_NUT&&i.length<o?i.push(c):l===Cg.SUFFIX_SEI_NUT&&a.length<o&&a.push(c)}if(n.length===0||r.length===0)return null;let s=Fg(n[0]);if(!s)return null;let c=0;if(r.length>0){let e=new sg(Eg(r[0]));e.skipBits(16),G(e),G(e),e.skipBits(1),e.skipBits(1),e.skipBits(3),e.skipBits(1),e.skipBits(1),G(e),G(e),kh(e),e.skipBits(1),e.skipBits(1),e.readBits(1)&&G(e),kh(e),kh(e),e.skipBits(1),e.skipBits(1),e.skipBits(1),e.skipBits(1);let t=e.readBits(1),n=e.readBits(1);c=!t&&!n?0:t&&!n?2:!t&&n?3:0}let l=[...t.length?[{arrayCompleteness:1,nalUnitType:Cg.VPS_NUT,nalUnits:t}]:[],...n.length?[{arrayCompleteness:1,nalUnitType:Cg.SPS_NUT,nalUnits:n}]:[],...r.length?[{arrayCompleteness:1,nalUnitType:Cg.PPS_NUT,nalUnits:r}]:[],...i.length?[{arrayCompleteness:0,nalUnitType:Cg.PREFIX_SEI_NUT,nalUnits:i}]:[],...a.length?[{arrayCompleteness:0,nalUnitType:Cg.SUFFIX_SEI_NUT,nalUnits:a}]:[]];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:c,chromaFormatIdc:s.chromaFormatIdc,bitDepthLumaMinus8:s.bitDepthLumaMinus8,bitDepthChromaMinus8:s.bitDepthChromaMinus8,avgFrameRate:0,constantFrameRate:0,numTemporalLayers:s.spsMaxSubLayersMinus1+1,temporalIdNested:s.spsTemporalIdNestingFlag,lengthSizeMinusOne:3,arrays:l}}catch(e){return ng._error(`Error building HEVC Decoder Configuration Record:`,e),null}},Lg=(e,t)=>{let n=e.readBits(2),r=e.readBits(1),i=e.readBits(5),a=0;for(let t=0;t<32;t++)a=a<<1|e.readBits(1);let o=new Uint8Array(6);for(let t=0;t<6;t++)o[t]=e.readBits(8);let s=e.readBits(8),c=[],l=[];for(let n=0;n<t;n++)c.push(e.readBits(1)),l.push(e.readBits(1));if(t>0)for(let n=t;n<8;n++)e.skipBits(2);for(let n=0;n<t;n++)c[n]&&e.skipBits(88),l[n]&&e.skipBits(8);return{general_profile_space:n,general_tier_flag:r,general_profile_idc:i,general_profile_compatibility_flags:a,general_constraint_indicator_flags:o,general_level_idc:s}},Rg=e=>{for(let t=0;t<4;t++)for(let n=0;n<(t===3?2:6);n++)if(!e.readBits(1))G(e);else{let n=Math.min(64,1<<4+(t<<1));t>1&&kh(e);for(let t=0;t<n;t++)kh(e)}},zg=(e,t)=>{let n=[];for(let r=0;r<t;r++)n[r]=Bg(e,r,t,n)},Bg=(e,t,n,r)=>{let i=0,a=0,o=0;if(t!==0&&(a=e.readBits(1)),a){o=t===n?t-(G(e)+1):t-1,e.readBits(1),G(e);let a=r[o]??0;for(let t=0;t<=a;t++)(e.readBits(1)||e.readBits(1))&&i++}else{let t=G(e),n=G(e);for(let n=0;n<t;n++)G(e),e.readBits(1);for(let t=0;t<n;t++)G(e),e.readBits(1);i=t+n}return i},Vg=(e,t)=>{let n=2,r=2,i=2,a=0,o=0,s={num:1,den:1};if(e.readBits(1)){let t=e.readBits(8);if(t===255)s={num:e.readBits(16),den:e.readBits(16)};else{let e=jg[t];e&&(s=e)}}return e.readBits(1)&&e.readBits(1),e.readBits(1)&&(e.readBits(3),a=e.readBits(1),e.readBits(1)&&(n=e.readBits(8),r=e.readBits(8),i=e.readBits(8))),e.readBits(1)&&(G(e),G(e)),e.readBits(1),e.readBits(1),e.readBits(1),e.readBits(1)&&(G(e),G(e),G(e),G(e)),e.readBits(1)&&(e.readBits(32),e.readBits(32),e.readBits(1)&&G(e),e.readBits(1)&&Hg(e,!0,t)),e.readBits(1)&&(e.readBits(1),e.readBits(1),e.readBits(1),o=G(e),G(e),G(e),G(e),G(e)),{pixelAspectRatio:s,colourPrimaries:n,transferCharacteristics:r,matrixCoefficients:i,fullRangeFlag:a,minSpatialSegmentationIdc:o}},Hg=(e,t,n)=>{let r=!1,i=!1,a=!1;t&&(r=e.readBits(1)===1,i=e.readBits(1)===1,(r||i)&&(a=e.readBits(1)===1,a&&(e.readBits(8),e.readBits(5),e.readBits(1),e.readBits(5)),e.readBits(4),e.readBits(4),a&&e.readBits(4),e.readBits(5),e.readBits(5),e.readBits(5)));for(let t=0;t<=n;t++){let t=e.readBits(1)===1,n=!0;t||(n=e.readBits(1)===1);let o=!1;n?G(e):o=e.readBits(1)===1;let s=1;o||(s=G(e)+1),r&&Ug(e,s,a),i&&Ug(e,s,a)}},Ug=(e,t,n)=>{for(let r=0;r<t;r++)G(e),G(e),n&&(G(e),G(e)),e.readBits(1)},Wg=e=>{let t=[];t.push(e.configurationVersion),t.push((e.generalProfileSpace&3)<<6|(e.generalTierFlag&1)<<5|e.generalProfileIdc&31),t.push(e.generalProfileCompatibilityFlags>>>24&255),t.push(e.generalProfileCompatibilityFlags>>>16&255),t.push(e.generalProfileCompatibilityFlags>>>8&255),t.push(e.generalProfileCompatibilityFlags&255),t.push(...e.generalConstraintIndicatorFlags),t.push(e.generalLevelIdc&255),t.push(240|e.minSpatialSegmentationIdc>>8&15),t.push(e.minSpatialSegmentationIdc&255),t.push(252|e.parallelismType&3),t.push(252|e.chromaFormatIdc&3),t.push(248|e.bitDepthLumaMinus8&7),t.push(248|e.bitDepthChromaMinus8&7),t.push(e.avgFrameRate>>8&255),t.push(e.avgFrameRate&255),t.push((e.constantFrameRate&3)<<6|(e.numTemporalLayers&7)<<3|(e.temporalIdNested&1)<<2|e.lengthSizeMinusOne&3),t.push(e.arrays.length&255);for(let n of e.arrays){t.push((n.arrayCompleteness&1)<<7|n.nalUnitType&63),t.push(n.nalUnits.length>>8&255),t.push(n.nalUnits.length&255);for(let e of n.nalUnits){t.push(e.length>>8&255),t.push(e.length&255);for(let n=0;n<e.length;n++)t.push(e[n])}}return new Uint8Array(t)},Gg;(function(e){e[e.audAllowed=0]=`audAllowed`,e[e.beforeFirstVcl=1]=`beforeFirstVcl`,e[e.afterFirstVcl=2]=`afterFirstVcl`,e[e.eoBitstreamAllowed=3]=`eoBitstreamAllowed`,e[e.noMoreDataAllowed=4]=`noMoreDataAllowed`})(Gg||={});var Kg=e=>{if(e.byteLength<19)throw Error(`Invalid Opus identification header: too short.`);let t=jh(e),n=t.getUint8(9),r=t.getUint16(10,!0),i=t.getUint32(12,!0),a=t.getInt16(16,!0),o=t.getUint8(18),s=null;return o&&(s=e.subarray(19)),{outputChannelCount:n,preSkip:r,inputSampleRate:i,outputGain:a,channelMappingFamily:o,channelMappingTable:s}},qg=[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],Jg=e=>{let t=e[0]>>3,n=e[0]&3,r;return r=n===0?1:n===1||n===2?2:e[1]&63,{durationInSamples:qg[t]*r}},Yg=(e,t)=>e===`truehd`?(t.byteLength>=8?jh(t).getUint32(4):null)===0xf8726fba?`key`:`delta`:`key`,Xg;(function(e){e[e.STREAMINFO=0]=`STREAMINFO`,e[e.VORBIS_COMMENT=4]=`VORBIS_COMMENT`,e[e.PICTURE=6]=`PICTURE`})(Xg||={});var Zg=e=>{if(e.length<7||e[0]!==11||e[1]!==119)return null;let t=new sg(e);t.skipBits(16),t.skipBits(16);let n=t.readBits(2);if(n===3)return null;let r=t.readBits(6),i=t.readBits(5);if(i>8)return null;let a=t.readBits(3),o=t.readBits(3);return o&1&&o!==1&&t.skipBits(2),o&4&&t.skipBits(2),o===2&&t.skipBits(2),{fscod:n,bsid:i,bsmod:a,acmod:o,lfeon:t.readBits(1),bitRateCode:Math.floor(r/2)}};new Uint8Array([5,4,65,67,45,51]),new Uint8Array([5,4,69,65,67,51]);var Qg=[1,2,3,6],$g=e=>{if(e.length<6||e[0]!==11||e[1]!==119)return null;let t=new sg(e);t.skipBits(16);let n=t.readBits(2);if(t.skipBits(3),n!==0&&n!==2)return null;let r=t.readBits(11),i=t.readBits(2),a=0,o;i===3?(a=t.readBits(2),o=3):o=t.readBits(2);let s=t.readBits(3),c=t.readBits(1),l=t.readBits(5);if(l<11||l>16)return null;let u=Qg[o],d;d=i<3?yg[i]/1e3:bg[a]/1e3;let f=Math.round((r+1)*d/(u*16)),p=0,m=0,h=2*(r+1);for(;h+2<=e.length&&(t.seekToByte(h),t.readBits(16)===2935&&t.readBits(2)===1);){t.skipBits(3);let e=t.readBits(11);t.skipBits(4);let n=t.readBits(3);if(t.skipBits(11),t.readBits(1)&&t.skipBits(8),n===0&&(t.skipBits(5),t.readBits(1)&&t.skipBits(8)),t.readBits(1)){let e=t.readBits(16);for(let t=0;t<8;t++)e&1<<10-t&&(m|=1<<t);e&2&&(m|=256)}p++,h+=2*(e+1)}return{dataRate:f,substreams:[{fscod:i,fscod2:a,bsid:l,bsmod:0,acmod:s,lfeon:c,numDepSub:p,chanLoc:m}]}},e_=e=>{let t=[],n=0;for(;n<e.length;){if(n+6>e.length||e[n]!==11||e[n+1]!==119)return null;let r=e[n+2]>>6,i=(e[n+2]&7)<<8|e[n+3],a=e[n+4]>>6==3?3:e[n+4]>>4&3,o=e[n+5]>>3,s=2*(i+1);if(o<=10||n+s>e.length)return null;if(r===1){let e=Eh(t);if(!e)return null;e.size+=s}else t.push({offset:n,size:s,blockCount:Qg[a]});n+=s}return t},t_=8,n_=[0,8e3,16e3,32e3,0,0,11025,22050,44100,0,0,12e3,24e3,48e3,96e3,192e3],r_=[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],i_=[16,16,20,20,0,24,24,0],a_=[1,2,2,2,2,3,3,4,4,5,6,6,6,7,8,8],o_=[1,2,2,2,2,3,18,19,6,7,518,323,83,519,582,535],s_=8,c_=[32e3,44100,48e3,0],l_=[8e3,16e3,32e3,64e3,128e3,22050,44100,88200,176400,352800,12e3,24e3,48e3,96e3,192e3,384e3],u_=[512,1024,2048,4096],d_=e=>{let t=f_(e),n=jh(e),r=t?Math.ceil(t.frameSize/4)*4:0,i=null;for(;r+4<=e.length&&n.getUint32(r)===0x64582025;){let t=p_(e.subarray(r));if(!t)break;i??=t,r+=t.frameSize}if(t)return{frameSize:i?r:t.frameSize,sampleRate:t.sampleRate,numberOfChannels:t.numberOfChannels,sampleCount:t.sampleCount,channelLayout:t.channelLayout,pcmResolution:t.pcmResolution,bitRate:t.bitRate,core:t,hasExtensions:i!==null};if(!i?.asset)return null;let{asset:a}=i;return{frameSize:r,sampleRate:a.sampleRate,numberOfChannels:a.numberOfChannels,sampleCount:a.sampleCount,channelLayout:a.channelLayout,pcmResolution:a.pcmResolution,bitRate:0,core:null,hasExtensions:!0}},f_=e=>{if(e.length<18||e[0]!==127||e[1]!==254||e[2]!==128||e[3]!==1)return null;let t=new sg(e);if(t.skipBits(32),t.skipBits(1),t.readBits(5)!==31)return null;let n=t.readBits(1),r=t.readBits(7)+1;if(r%t_!==0)return null;let i=t.readBits(14)+1;if(i<96)return null;let a=t.readBits(6);if(a>=a_.length)return null;let o=n_[t.readBits(4)];if(o===0)return null;let s=r_[t.readBits(5)];if(t.readBits(1)!==0)return null;t.skipBits(4);let c=t.readBits(3),l=t.readBits(1);t.skipBits(1);let u=t.readBits(2);if(u===3)return null;t.skipBits(1),n&&t.skipBits(16),t.skipBits(7);let d=i_[t.readBits(3)];if(d===0)return null;let f=u!==0;return{frameSize:i,sampleRate:o,numberOfChannels:a_[a]+ +!!f,sampleCount:r*32,channelLayout:o_[a]|(f?s_:0),amode:a,lfePresent:f,bitRate:s,pcmResolution:d,extAudioId:l?c:null}},p_=e=>{if(e.length<10||e[0]!==100||e[1]!==88||e[2]!==32||e[3]!==37)return null;let t=new sg(e);t.skipBits(32),t.skipBits(8);let n=t.readBits(2),r=t.readBits(1),i=8+4*r,a=16+4*r;t.skipBits(i);let o=t.readBits(a)+1,s={frameSize:o,asset:null};if(!t.readBits(1))return s;let c=c_[t.readBits(2)],l=512*(t.readBits(3)+1);t.readBits(1)&&t.skipBits(36);let u=t.readBits(3)+1,d=t.readBits(3)+1,f=[];for(let e=0;e<u;e++)f.push(t.readBits(n+1));for(let e of f)t.skipBits(8*Hh(e));if(t.readBits(1)){t.skipBits(2);let e=t.readBits(2)+1<<2,n=t.readBits(2)+1;t.skipBits(n*e)}for(let e=0;e<d;e++)t.skipBits(a);t.skipBits(9),t.skipBits(3),t.readBits(1)&&t.skipBits(4),t.readBits(1)&&t.skipBits(24),t.readBits(1)&&t.skipBits(8*(t.readBits(10)+1));let p=t.readBits(5)+1,m=l_[t.readBits(4)],h=t.readBits(8)+1,g=0;if(t.readBits(1)&&(h>2&&t.skipBits(1),h>6&&t.skipBits(1),t.readBits(1))){let e=t.readBits(2)+1<<2;g=t.readBits(e)}return c===0||t.getBitsLeft()<0?s:{frameSize:o,asset:{sampleRate:m,numberOfChannels:h,sampleCount:Math.round(l*m/c),channelLayout:g,pcmResolution:p}}},m_={0:2,2:4,6:3},h_=e=>{let t=new Uint8Array(20),n=jh(t);n.setUint32(0,e.sampleRate),n.setUint32(4,e.bitRate),n.setUint32(8,e.bitRate),t[12]=e.pcmResolution;let r=0;if(e.core&&!e.hasExtensions){let{extAudioId:t}=e.core;r=t===null?1:m_[t]??0}let i=new sg(t);return i.seekToByte(13),i.writeBits(2,Math.max(u_.indexOf(e.sampleCount),0)),i.writeBits(5,r),i.writeBits(1,+!!e.core?.lfePresent),i.writeBits(6,e.core?.amode??0),i.writeBits(14,e.core?e.core.frameSize-1:0),i.writeBits(1,0),i.writeBits(3,0),i.writeBits(16,e.channelLayout),i.writeBits(1,0),i.writeBits(1,0),i.writeBits(1,0),i.writeBits(5,0),t},g_=/<(?:(\d{2,}):)?(\d{2}):(\d{2}).(\d{3})>/g,__=e=>{let t=Math.round(1e3*e),n=Math.floor(t/36e5),r=Math.floor(t%36e5/6e4),i=Math.floor(t%6e4/1e3),a=t%1e3;return n.toString().padStart(2,`0`)+`:`+r.toString().padStart(2,`0`)+`:`+i.toString().padStart(2,`0`)+`.`+a.toString().padStart(3,`0`)},v_=new Uint8Array,y_=class e{constructor(e,t,n,r,i=-1,a,o){if(this.data=e,this.type=t,this.timestamp=n,this.duration=r,this.sequenceNumber=i,e===v_&&a===void 0)throw Error(`Internal error: byteLength must be explicitly provided when constructing metadata-only packets.`);if(a===void 0&&(a=e.byteLength),!(e instanceof Uint8Array))throw TypeError(`data must be a Uint8Array.`);if(t!==`key`&&t!==`delta`)throw TypeError(`type must be either "key" or "delta".`);if(!Number.isFinite(n))throw TypeError(`timestamp must be a number.`);if(!Number.isFinite(r)||r<0)throw TypeError(`duration must be a non-negative number.`);if(!Number.isFinite(i))throw TypeError(`sequenceNumber must be a number.`);if(!Number.isInteger(a)||a<0)throw TypeError(`byteLength must be a non-negative integer.`);if(o!==void 0&&(typeof o!=`object`||!o))throw TypeError(`sideData, when provided, must be an object.`);if(o?.alpha!==void 0&&!(o.alpha instanceof Uint8Array))throw TypeError(`sideData.alpha, when provided, must be a Uint8Array.`);if(o?.alphaByteLength!==void 0&&(!Number.isInteger(o.alphaByteLength)||o.alphaByteLength<0))throw 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===v_}get microsecondTimestamp(){return Math.trunc(Gh*this.timestamp)}get microsecondDuration(){return Math.trunc(Gh*this.duration)}toEncodedVideoChunk(){if(this.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be converted to a video chunk.`);if(typeof EncodedVideoChunk>`u`)throw 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 TypeError(`This packet does not contain alpha side data.`);if(this.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be converted to a video chunk.`);if(typeof EncodedVideoChunk>`u`)throw 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 TypeError(`Metadata-only packets cannot be converted to an audio chunk.`);if(typeof EncodedAudioChunk>`u`)throw 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(t,n){if(!(t instanceof EncodedVideoChunk||t instanceof EncodedAudioChunk))throw TypeError(`chunk must be an EncodedVideoChunk or EncodedAudioChunk.`);let r=new Uint8Array(t.byteLength);return t.copyTo(r),new e(r,t.type,t.timestamp/1e6,(t.duration??0)/1e6,void 0,void 0,n)}clone(t){if(t!==void 0&&(typeof t!=`object`||!t))throw TypeError(`options, when provided, must be an object.`);if(t?.data!==void 0&&!(t.data instanceof Uint8Array))throw TypeError(`options.data, when provided, must be a Uint8Array.`);if(t?.type!==void 0&&t.type!==`key`&&t.type!==`delta`)throw TypeError(`options.type, when provided, must be either "key" or "delta".`);if(t?.timestamp!==void 0&&!Number.isFinite(t.timestamp))throw TypeError(`options.timestamp, when provided, must be a number.`);if(t?.duration!==void 0&&!Number.isFinite(t.duration))throw TypeError(`options.duration, when provided, must be a number.`);if(t?.sequenceNumber!==void 0&&!Number.isFinite(t.sequenceNumber))throw TypeError(`options.sequenceNumber, when provided, must be a number.`);if(t?.sideData!==void 0&&(typeof t.sideData!=`object`||t.sideData===null))throw TypeError(`options.sideData, when provided, must be an object.`);return new e(t?.data??this.data,t?.type??this.type,t?.timestamp??this.timestamp,t?.duration??this.duration,t?.sequenceNumber??this.sequenceNumber,t?.data?.byteLength??this.byteLength,t?.sideData??this.sideData)}},b_=0x7c25b080,x_=e=>{let t=(e.hasVideo?`video/`:e.hasAudio?`audio/`:`application/`)+(e.isQuickTime?`quicktime`:`mp4`);if(e.codecStrings.length>0){let n=[...new Set(e.codecStrings)];t+=`; codecs="${n.join(`, `)}"`}return t},S_=e=>{let t=e.filePos;if(e.remainingLength<7)return null;let n=new sg(E_(e,7));if(n.readBits(12)!==4095||(n.skipBits(1),n.readBits(2)!==0))return null;let r=n.readBits(1),i=n.readBits(2)+1,a=n.readBits(4);if(a>=cg.length)return null;n.skipBits(1);let o=n.readBits(3);n.skipBits(1),n.skipBits(1),n.skipBits(1),n.skipBits(1);let s=n.readBits(13);n.skipBits(11);let c=n.readBits(2)+1;if(c!==1)return null;let l=null;if(r===0){if(e.remainingLength<2)return null;l=D_(e)}return s<e.filePos-t?null:{objectType:i,samplingFrequencyIndex:a,channelConfiguration:o,frameLength:s,numberOfAacFrames:c,crcCheck:l,startPos:t}},C_=o(((e,t)=>{t.exports={}})),w_=class e{constructor(e,t,n,r,i){this.bytes=e,this.view=t,this.offset=n,this.start=r,this.end=i,this.bufferPos=r-n}static tempFromBytes(t){return new e(t,jh(t),0,0,t.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(t,n=this.end-t){if(t<this.start||t+n>this.end)throw RangeError(`Slicing outside of original slice.`);return new e(this.bytes,this.view,this.offset,t,t+n)}},T_=(e,t)=>{if(t<0||e.filePos<e.start||e.filePos+t>e.end)throw RangeError(`Tried reading [${e.filePos}, ${e.filePos+t}), but slice is [${e.start}, ${e.end}). This is likely an internal error, please report it alongside the file that caused it.`)},E_=(e,t)=>{T_(e,t);let n=e.bytes.subarray(e.bufferPos,e.bufferPos+t);return e.bufferPos+=t,n},D_=e=>{T_(e,2);let t=e.view.getUint16(e.bufferPos,!1);return e.bufferPos+=2,t},O_=class{constructor(){this._connectedTrack=null,this._closingPromise=null,this._nominalBitrate=null}_ensureValidAdd(){if(!this._connectedTrack)throw Error(`Source is not connected to an output track.`);if(this._connectedTrack.output.state===`canceled`)throw Error(`Output has been canceled.`);if(this._connectedTrack.output.state===`finalizing`||this._connectedTrack.output.state===`finalized`)throw Error(`Output has been finalized.`);if(this._connectedTrack.output.state===`pending`)throw Error(`Output has not started.`);if(this._closingPromise)throw Error(`Source is closed.`)}async _start(){}async _flushAndClose(e){}close(){if(this._closingPromise)return;let e=this._connectedTrack;if(!e)throw Error(`Cannot call close without connecting the source to an output track.`);if(e.output.state===`pending`)throw Error(`Cannot call close before output has been started.`);this._closingPromise=(async()=>{await this._flushAndClose(!1),e.output.state!==`finalizing`&&e.output.state!==`finalized`&&await e.output._muxer.onTrackClose(e)})(),this._closingPromise.catch(()=>{})}async _flushOrWaitForOngoingClose(e){return this._closingPromise??=this._flushAndClose(e)}},k_=class extends O_{constructor(e){if(super(),!F_.includes(e))throw TypeError(`Invalid video codec '${e}'. Must be one of: ${F_.join(`, `)}.`);this._codec=e}},A_=(e,t)=>{if(e.metadata.hasOnlyKeyPackets&&t.type!==`key`)throw Error(`Cannot add non-key packets to a hasOnlyKeyPackets video track.`)},j_=class extends k_{constructor(e){super(e)}add(e,t){if(!(e instanceof y_))throw TypeError(`packet must be an EncodedPacket.`);if(e.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be added.`);if(t!==void 0&&(!t||typeof t!=`object`))throw TypeError(`meta, when provided, must be an object.`);return this._ensureValidAdd(),A_(this._connectedTrack,e),this._connectedTrack.output._muxer.addEncodedVideoPacket(this._connectedTrack,e,t)}},M_=class extends O_{constructor(e){if(super(),!R_.includes(e))throw TypeError(`Invalid audio codec '${e}'. Must be one of: ${R_.join(`, `)}.`);this._codec=e}},N_=class extends M_{constructor(e){super(e)}add(e,t){if(!(e instanceof y_))throw TypeError(`packet must be an EncodedPacket.`);if(e.isMetadataOnly)throw TypeError(`Metadata-only packets cannot be added.`);if(t!==void 0&&(!t||typeof t!=`object`))throw TypeError(`meta, when provided, must be an object.`);return this._ensureValidAdd(),this._connectedTrack.output._muxer.addEncodedAudioPacket(this._connectedTrack,e,t)}},P_=class extends O_{constructor(e){if(super(),!z_.includes(e))throw TypeError(`Invalid subtitle codec '${e}'. Must be one of: ${z_.join(`, `)}.`);this._codec=e}},F_=[`avc`,`hevc`,`vp9`,`av1`,`vp8`,`prores`],I_=[`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`],L_=[`aac`,`opus`,`mp3`,`vorbis`,`flac`,`ac3`,`eac3`,`dts`,`truehd`],R_=[...L_,...I_],z_=[`webvtt`],B_=[{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}],V_=[`ap4x`,`ap4h`,`apch`,`apcn`,`apcs`,`apco`],H_=[`dtsc`,`dtsh`,`dtsl`,`dtse`],U_=e=>{let t=e.split(`.`),n=Number(t[1]),r=t[2],i=Number(r.slice(0,-1)),a=(n<<5)+i,o=+(r.slice(-1)===`H`),s=Number(t[3]),c=s===8?0:1,l=+(s===12),u=t[4]?Number(t[4]):0,d=t[5]?Number(t[5][0]):1,f=t[5]?Number(t[5][1]):1,p=t[5]?Number(t[5][2]):0;return[129,a,(o<<7)+(c<<6)+(l<<5)+(u<<4)+(d<<3)+(f<<2)+p,0]},W_=48e3,G_=.4,K_=/^pcm-([usf])(\d+)(be)?$/,q_=e=>{if(W(I_.includes(e)),e===`ulaw`)return{dataType:`ulaw`,sampleSize:1,littleEndian:!0,silentValue:255};if(e===`alaw`)return{dataType:`alaw`,sampleSize:1,littleEndian:!0,silentValue:213};let t=K_.exec(e);W(t);let n;n=t[1]===`u`?`unsigned`:t[1]===`s`?`signed`:`float`;let r=Number(t[2])/8,i=t[3]!==`be`;return{dataType:n,sampleSize:r,littleEndian:i,silentValue:e===`pcm-u8`?128:0}},J_=e=>e.startsWith(`avc1`)||e.startsWith(`avc3`)?`avc`:e.startsWith(`hev1`)||e.startsWith(`hvc1`)?`hevc`:e===`vp8`?`vp8`:e.startsWith(`vp09`)?`vp9`:e.startsWith(`av01`)?`av1`:V_.includes(e)?`prores`:e===`mp3`||e===`mp4a.69`||e===`mp4a.6B`||e===`mp4a.6b`||e===`mp4a.40.34`?`mp3`:e.startsWith(`mp4a.40.`)||e===`mp4a.67`?`aac`:e===`opus`||e===`Opus`?`opus`:e===`vorbis`?`vorbis`:e===`flac`||e===`fLaC`?`flac`:e===`ac-3`||e===`ac3`?`ac3`:e===`ec-3`||e===`eac3`?`eac3`:H_.includes(e)?`dts`:e===`mlpa`?`truehd`:e===`ulaw`?`ulaw`:e===`alaw`?`alaw`:K_.test(e)?e:e===`webvtt`?`webvtt`:null,Y_=[`avc1`,`avc3`,`hev1`,`hvc1`,`vp8`,`vp09`,`av01`,...V_],X_=/^(avc1|avc3)\.[0-9a-fA-F]{6}$/,Z_=/^(hev1|hvc1)\.(?:[ABC]?\d+)\.[0-9a-fA-F]{1,8}\.[LH]\d+(?:\.[0-9a-fA-F]{1,2}){0,6}$/,Q_=/^vp09(?:\.\d{2}){3}(?:(?:\.\d{2}){5})?$/,$_=/^av01\.\d\.\d{2}[MH]\.\d{2}(?:\.\d\.\d{3}\.\d{2}\.\d{2}\.\d{2}\.\d)?$/,e1=(e,t)=>{if(!e)throw TypeError(`Video chunk metadata must be provided.`);if(typeof e!=`object`)throw TypeError(`Video chunk metadata must be an object.`);if(!e.decoderConfig)throw TypeError(`Video chunk metadata must include a decoder configuration.`);if(typeof e.decoderConfig!=`object`)throw TypeError(`Video chunk metadata decoder configuration must be an object.`);if(typeof e.decoderConfig.codec!=`string`)throw TypeError(`Video chunk metadata decoder configuration must specify a codec string.`);if(!Y_.some(t=>e.decoderConfig.codec.startsWith(t)))throw TypeError(`Video chunk metadata decoder configuration codec string must be a valid video codec string as specified in the Mediabunny Codec Registry.`);if(!Number.isInteger(e.decoderConfig.codedWidth)||e.decoderConfig.codedWidth<=0)throw TypeError(`Video chunk metadata decoder configuration must specify a valid codedWidth (positive integer).`);if(!Number.isInteger(e.decoderConfig.codedHeight)||e.decoderConfig.codedHeight<=0)throw TypeError(`Video chunk metadata decoder configuration must specify a valid codedHeight (positive integer).`);if(e.decoderConfig.displayAspectWidth!==void 0&&(!Number.isInteger(e.decoderConfig.displayAspectWidth)||e.decoderConfig.displayAspectWidth<=0))throw TypeError(`Video chunk metadata decoder configuration displayAspectWidth, when defined, must be a positive integer.`);if(e.decoderConfig.displayAspectHeight!==void 0&&(!Number.isInteger(e.decoderConfig.displayAspectHeight)||e.decoderConfig.displayAspectHeight<=0))throw TypeError(`Video chunk metadata decoder configuration displayAspectHeight, when defined, must be a positive integer.`);if(e.decoderConfig.displayAspectWidth!==void 0!=(e.decoderConfig.displayAspectHeight!==void 0))throw TypeError(`Video chunk metadata decoder configuration must specify both displayAspectWidth and displayAspectHeight, or neither.`);if(e.decoderConfig.description!==void 0&&!Lh(e.decoderConfig.description))throw TypeError(`Video chunk metadata decoder configuration description, when defined, must be an ArrayBuffer or an ArrayBuffer view.`);if(e.decoderConfig.colorSpace!==void 0){let{colorSpace:t}=e.decoderConfig;if(typeof t!=`object`)throw TypeError(`Video chunk metadata decoder configuration colorSpace, when provided, must be an object.`);let n=Object.keys(Nh);if(t.primaries!=null&&!n.includes(t.primaries))throw TypeError(`Video chunk metadata decoder configuration colorSpace primaries, when defined, must be one of ${n.join(`, `)}.`);let r=Object.keys(Ph);if(t.transfer!=null&&!r.includes(t.transfer))throw TypeError(`Video chunk metadata decoder configuration colorSpace transfer, when defined, must be one of ${r.join(`, `)}.`);let i=Object.keys(Fh);if(t.matrix!=null&&!i.includes(t.matrix))throw TypeError(`Video chunk metadata decoder configuration colorSpace matrix, when defined, must be one of ${i.join(`, `)}.`);if(t.fullRange!=null&&typeof t.fullRange!=`boolean`)throw TypeError(`Video chunk metadata decoder configuration colorSpace fullRange, when defined, must be a boolean.`)}if(e.decoderConfig.codec.startsWith(`avc1`)||e.decoderConfig.codec.startsWith(`avc3`)){if(!X_.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for AVC must be a valid AVC codec string as specified in Section 3.4 of RFC 6381.`)}else if(e.decoderConfig.codec.startsWith(`hev1`)||e.decoderConfig.codec.startsWith(`hvc1`)){if(!Z_.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for HEVC must be a valid HEVC codec string as specified in Section E.3 of ISO 14496-15.`)}else if(e.decoderConfig.codec.startsWith(`vp8`)){if(e.decoderConfig.codec!==`vp8`)throw TypeError(`Video chunk metadata decoder configuration codec string for VP8 must be "vp8".`)}else if(e.decoderConfig.codec.startsWith(`vp09`)){if(!Q_.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for VP9 must be a valid VP9 codec string as specified in Section "Codecs Parameter String" of https://www.webmproject.org/vp9/mp4/.`)}else if(e.decoderConfig.codec.startsWith(`av01`)){if(!$_.test(e.decoderConfig.codec))throw TypeError(`Video chunk metadata decoder configuration codec string for AV1 must be a valid AV1 codec string as specified in Section "Codecs Parameter String" of https://aomediacodec.github.io/av1-isobmff/.`)}else if(V_.some(t=>e.decoderConfig.codec.startsWith(t))&&!V_.some(t=>e.decoderConfig.codec===t))throw TypeError(`Video chunk metadata decoder configuration codec string for ProRes must be one of the valid ProRes four-character codes: ${V_.join(`, `)}.`);if(t!==null&&J_(e.decoderConfig.codec)!==t)throw TypeError(`Video chunk metadata decoder configuration codec string '${e.decoderConfig.codec}' does not fit to the track codec '${t}'.`)},t1=[`mp4a`,`mp3`,`opus`,`vorbis`,`flac`,`ulaw`,`alaw`,`pcm`,`ac-3`,`ec-3`,`dts`,`mlpa`],n1=(e,t)=>{if(!e)throw TypeError(`Audio chunk metadata must be provided.`);if(typeof e!=`object`)throw TypeError(`Audio chunk metadata must be an object.`);if(!e.decoderConfig)throw TypeError(`Audio chunk metadata must include a decoder configuration.`);if(typeof e.decoderConfig!=`object`)throw TypeError(`Audio chunk metadata decoder configuration must be an object.`);if(typeof e.decoderConfig.codec!=`string`)throw TypeError(`Audio chunk metadata decoder configuration must specify a codec string.`);if(!t1.some(t=>e.decoderConfig.codec.startsWith(t)))throw TypeError(`Audio chunk metadata decoder configuration codec string must be a valid audio codec string as specified in the Mediabunny Codec Registry.`);if(!Number.isInteger(e.decoderConfig.sampleRate)||e.decoderConfig.sampleRate<=0)throw TypeError(`Audio chunk metadata decoder configuration must specify a valid sampleRate (positive integer).`);if(!Number.isInteger(e.decoderConfig.numberOfChannels)||e.decoderConfig.numberOfChannels<=0)throw TypeError(`Audio chunk metadata decoder configuration must specify a valid numberOfChannels (positive integer).`);if(e.decoderConfig.description!==void 0&&!Lh(e.decoderConfig.description))throw TypeError(`Audio chunk metadata decoder configuration description, when defined, must be an ArrayBuffer or an ArrayBuffer view.`);if(e.decoderConfig.codec.startsWith(`mp4a`)&&e.decoderConfig.codec!==`mp4a.69`&&e.decoderConfig.codec!==`mp4a.6B`&&e.decoderConfig.codec!==`mp4a.6b`){if(![`mp4a.40.2`,`mp4a.40.02`,`mp4a.40.5`,`mp4a.40.05`,`mp4a.40.29`,`mp4a.40.42`,`mp4a.67`].includes(e.decoderConfig.codec))throw TypeError(`Audio chunk metadata decoder configuration codec string for AAC must be a valid AAC codec string as specified in https://www.w3.org/TR/webcodecs-aac-codec-registration/.`)}else if(e.decoderConfig.codec.startsWith(`mp3`)||e.decoderConfig.codec.startsWith(`mp4a`)){if(e.decoderConfig.codec!==`mp3`&&e.decoderConfig.codec!==`mp4a.69`&&e.decoderConfig.codec!==`mp4a.6B`&&e.decoderConfig.codec!==`mp4a.6b`)throw TypeError(`Audio chunk metadata decoder configuration codec string for MP3 must be "mp3", "mp4a.69" or "mp4a.6B".`)}else if(e.decoderConfig.codec.startsWith(`opus`)){if(e.decoderConfig.codec!==`opus`)throw TypeError(`Audio chunk metadata decoder configuration codec string for Opus must be "opus".`);if(e.decoderConfig.description&&e.decoderConfig.description.byteLength<18)throw TypeError(`Audio chunk metadata decoder configuration description, when specified, is expected to be an Identification Header as specified in Section 5.1 of RFC 7845.`)}else if(e.decoderConfig.codec.startsWith(`vorbis`)){if(e.decoderConfig.codec!==`vorbis`)throw TypeError(`Audio chunk metadata decoder configuration codec string for Vorbis must be "vorbis".`);if(!e.decoderConfig.description)throw TypeError(`Audio chunk metadata decoder configuration for Vorbis must include a description, which is expected to adhere to the format described in https://www.w3.org/TR/webcodecs-vorbis-codec-registration/.`)}else if(e.decoderConfig.codec.startsWith(`flac`)){if(e.decoderConfig.codec!==`flac`)throw TypeError(`Audio chunk metadata decoder configuration codec string for FLAC must be "flac".`);if(!e.decoderConfig.description||e.decoderConfig.description.byteLength<42)throw TypeError(`Audio chunk metadata decoder configuration for FLAC must include a description, which is expected to adhere to the format described in https://www.w3.org/TR/webcodecs-flac-codec-registration/.`)}else if(e.decoderConfig.codec.startsWith(`ac-3`)||e.decoderConfig.codec.startsWith(`ac3`)){if(e.decoderConfig.codec!==`ac-3`)throw TypeError(`Audio chunk metadata decoder configuration codec string for AC-3 must be "ac-3".`)}else if(e.decoderConfig.codec.startsWith(`ec-3`)||e.decoderConfig.codec.startsWith(`eac3`)){if(e.decoderConfig.codec!==`ec-3`)throw TypeError(`Audio chunk metadata decoder configuration codec string for EC-3 must be "ec-3".`)}else if(e.decoderConfig.codec.startsWith(`dts`)){if(!H_.includes(e.decoderConfig.codec))throw TypeError(`Audio chunk metadata decoder configuration codec string for DTS must be one of the following four-character codes: ${H_.join(`, `)}.`)}else if(e.decoderConfig.codec.startsWith(`mlpa`)){if(e.decoderConfig.codec!==`mlpa`)throw TypeError(`Audio chunk metadata decoder configuration codec string for TrueHD must be "mlpa".`)}else if((e.decoderConfig.codec.startsWith(`pcm`)||e.decoderConfig.codec.startsWith(`ulaw`)||e.decoderConfig.codec.startsWith(`alaw`))&&!I_.includes(e.decoderConfig.codec))throw TypeError(`Audio chunk metadata decoder configuration codec string for PCM must be one of the supported PCM codecs (${I_.join(`, `)}).`);if(t!==null&&J_(e.decoderConfig.codec)!==t)throw TypeError(`Audio chunk metadata decoder configuration codec string '${e.decoderConfig.codec}' does not fit to the track codec '${t}'.`)},r1=e=>{if(!e)throw TypeError(`Subtitle metadata must be provided.`);if(typeof e!=`object`)throw TypeError(`Subtitle metadata must be an object.`);if(!e.config)throw TypeError(`Subtitle metadata must include a config object.`);if(typeof e.config!=`object`)throw TypeError(`Subtitle metadata config must be an object.`);if(typeof e.config.description!=`string`)throw TypeError(`Subtitle metadata config description must be a string.`)},i1=class{constructor(e){this.mutex=new Rh,this.trackPacketOrderValidators=new WeakMap,this.output=e}async onTrackClose(e){}validateTimestamp(e,t,n){let r=this.trackPacketOrderValidators.get(e);r||(r=new a1,this.trackPacketOrderValidators.set(e,r));let i=n?`key`:`delta`;if(r.digest(t,i))return;if(r.maxTimestamp===null)throw Error(`First packet must be a key packet.`);let a=i===`key`?r.maxTimestamp:r.maxTimestampBeforeLastKeyPacket;throw Error(`Timestamps cannot be smaller than the largest timestamp of the previous GOP (a GOP begins with a key packet and ends right before the next key packet). Got ${t}s, but largest timestamp is ${a}s.`)}},a1=class{constructor(){this.maxTimestamp=null,this.maxTimestampBeforeLastKeyPacket=null}check(e,t){if(this.maxTimestamp===null)return t===`key`;let n=t===`key`?this.maxTimestamp:this.maxTimestampBeforeLastKeyPacket;return n===null||e>=n}digest(e,t){return this.check(e,t)?(t===`key`&&(this.maxTimestampBeforeLastKeyPacket=this.maxTimestamp),this.maxTimestamp=Math.max(this.maxTimestamp??-1/0,e),!0):!1}},o1=class{constructor(e){this.writer=e,this.helper=new Uint8Array(8),this.helperView=new DataView(this.helper.buffer),this.offsets=new WeakMap}writeU32(e){this.helperView.setUint32(0,e,!1),this.writer.write(this.helper.subarray(0,4))}writeU64(e){this.helperView.setUint32(0,Math.floor(e/2**32),!1),this.helperView.setUint32(4,e,!1),this.writer.write(this.helper.subarray(0,8))}writeAscii(e){for(let t=0;t<e.length;t++)this.helperView.setUint8(t%8,e.charCodeAt(t)),t%8==7&&this.writer.write(this.helper);e.length%8!=0&&this.writer.write(this.helper.subarray(0,e.length%8))}writeBox(e){if(this.offsets.set(e,this.writer.getPos()),e.contents&&!e.children)this.writeBoxHeader(e,e.size??e.contents.byteLength+8),this.writer.write(e.contents);else{let t=this.writer.getPos();if(this.writeBoxHeader(e,0),e.contents&&this.writer.write(e.contents),e.children)for(let t of e.children)t&&this.writeBox(t);let n=this.writer.getPos(),r=e.size??n-t;this.writer.seek(t),this.writeBoxHeader(e,r),this.writer.seek(n)}}writeBoxHeader(e,t){this.writeU32(e.largeSize?1:t),this.writeAscii(e.type),e.largeSize&&this.writeU64(t)}measureBoxHeader(e){return 8+(e.largeSize?8:0)}patchBox(e){let t=this.offsets.get(e);W(t!==void 0);let n=this.writer.getPos();this.writer.seek(t),this.writeBox(e),this.writer.seek(n)}measureBox(e){if(e.contents&&!e.children)return this.measureBoxHeader(e)+e.contents.byteLength;{let t=this.measureBoxHeader(e);if(e.contents&&(t+=e.contents.byteLength),e.children)for(let n of e.children)n&&(t+=this.measureBox(n));return t}}},K=new Uint8Array(8),s1=new DataView(K.buffer),q=e=>[(e%256+256)%256],J=e=>(s1.setUint16(0,e,!1),[K[0],K[1]]),c1=e=>(s1.setInt16(0,e,!1),[K[0],K[1]]),l1=e=>(s1.setUint32(0,e,!1),[K[1],K[2],K[3]]),Y=e=>(s1.setUint32(0,e,!1),[K[0],K[1],K[2],K[3]]),u1=e=>(s1.setInt32(0,e,!1),[K[0],K[1],K[2],K[3]]),d1=e=>(s1.setUint32(0,Math.floor(e/2**32),!1),s1.setUint32(4,e,!1),[K[0],K[1],K[2],K[3],K[4],K[5],K[6],K[7]]),f1=e=>(s1.setInt32(0,Math.floor(e/2**32),!1),s1.setUint32(4,e,!1),[K[0],K[1],K[2],K[3],K[4],K[5],K[6],K[7]]),p1=e=>(s1.setFloat64(0,e,!1),[K[0],K[1],K[2],K[3],K[4],K[5],K[6],K[7]]),m1=e=>(s1.setInt16(0,256*e,!1),[K[0],K[1]]),h1=e=>(s1.setInt32(0,2**16*e,!1),[K[0],K[1],K[2],K[3]]),g1=e=>(s1.setInt32(0,2**30*e,!1),[K[0],K[1],K[2],K[3]]),_1=(e,t)=>{let n=[],r=e;do{let e=r&127;r>>=7,n.length>0&&(e|=128),n.push(e),t!==void 0&&t--}while(r>0||t);return n.reverse()},X=(e,t=!1)=>{let n=Array(e.length).fill(null).map((t,n)=>e.charCodeAt(n));return t&&n.push(0),n},v1=e=>[h1(e[0]),h1(e[1]),g1(e[2]),h1(e[3]),h1(e[4]),g1(e[5]),h1(e[6]),h1(e[7]),g1(e[8])],Z=(e,t,n)=>({type:e,contents:t&&new Uint8Array(t.flat(10)),children:n}),Q=(e,t,n,r,i)=>Z(e,[q(t),l1(n),r??[]],i),y1=e=>e.isQuickTime?Z(`ftyp`,[X(`qt `),Y(512),X(`qt `)]):e.fragmented?e.cmaf?Z(`ftyp`,[X(`iso5`),Y(512),X(`iso5`),X(`iso6`),X(`mp41`),X(`cmfc`),X(`dash`)]):Z(`ftyp`,[X(`iso5`),Y(512),X(`iso5`),X(`iso6`),X(`mp41`)]):Z(`ftyp`,[X(`isom`),Y(512),X(`isom`),e.holdsAvc?X(`avc1`):[],X(`mp41`)]),b1=()=>Z(`styp`,[X(`iso5`),Y(0),X(`iso5`),X(`iso6`),X(`mp41`),X(`cmfc`),X(`dash`)]),x1=(e,t)=>{W(t<2**31);let n=Math.max(0,e.minWrittenTimestamp),r=Math.max(0,e.maxWrittenEndTimestamp-n);Number.isFinite(r)||(r=0);let i=$(r,nv);if(i>=2**32)throw Error(`CMAF segments must be shorter than 20.712612 hours.`);return Q(`sidx`,1,0,[Y(1),Y(nv),d1($(n,nv)),d1(0),J(0),J(1),Y(t),Y(i),Y(0)])},S1=e=>({type:`mdat`,largeSize:e}),C1=e=>({type:`free`,size:e}),w1=e=>Z(`moov`,void 0,[T1(e.creationTime,e.trackDatas),...e.trackDatas.map(t=>E1(t,e.creationTime)),e.isFragmented?v0(e.trackDatas):null,N0(e)]),T1=(e,t)=>{let n=Math.max(0,...t.map(e=>Math.max(0,$(av(e),nv)+$(e.startTimestampOffset??0,nv)))),r=Math.max(0,...t.map(e=>e.track.id))+1,i=!Dh(e)||!Dh(n),a=i?d1:Y;return Q(`mvhd`,+i,0,[a(e),a(e),Y(nv),a(n),h1(1),m1(1),Array(10).fill(0),v1(bh),Array(24).fill(0),Y(r)])},E1=(e,t)=>{let n=iv(e),r=e.startTimestampOffset!==null&&e.startTimestampOffset!==0;return Z(`trak`,void 0,[D1(e,t),r?O1(e):null,k1(e,t),n.name===void 0?null:Z(`udta`,void 0,[Z(`name`,[...Mh.encode(n.name)])])])},D1=(e,t)=>{let n=Math.max(0,$(av(e),nv)+$(e.startTimestampOffset??0,nv)),r=!Dh(t)||!Dh(n),i=r?d1:Y,a;if(e.type===`video`&&e.track.metadata.transformationMatrix)a=e.track.metadata.transformationMatrix;else if(e.type===`video`){let{rotation:t,flip:n}=e.track.metadata;a=xh(Th(Sh(t??0),wh(n?-1:1,1)),e.info.width,e.info.height)}else a=bh;let o=2;e.track.metadata.disposition?.default!==!1&&(o|=1);let s=e.type===`video`?0:e.type===`audio`?1:e.type===`subtitle`?2:Bh(e);return Q(`tkhd`,+r,o,[i(t),i(t),Y(e.track.id),Y(0),i(n),Array(8).fill(0),J(0),J(s),m1(+(e.type===`audio`)),J(0),v1(a),h1(e.type===`video`?e.info.width:0),h1(e.type===`video`?e.info.height:0)])},O1=e=>{let t=e.startTimestampOffset;if(W(t!==null),t>0){let n=$(t,nv),r=$(av(e),nv),i=!Dh(n)||!Dh(r),a=i?d1:Y,o=i?f1:u1;return Z(`edts`,void 0,[Q(`elst`,+!!i,0,[Y(2),a(n),o(-1),h1(1),a(r),o(0),h1(1)])])}{let n=$(-t,e.timescale),r=Math.max(0,$(av(e),nv)+$(t,nv)),i=!Oh(n)||!Dh(r),a=i?d1:Y,o=i?f1:u1;return Z(`edts`,void 0,[Q(`elst`,+!!i,0,[Y(1),a(r),o(n),h1(1)])])}},k1=(e,t)=>Z(`mdia`,void 0,[A1(e,t),N1(!0,j1[e.type],M1[e.type],void 0,e.muxer.isQuickTime),P1(e)]),A1=(e,t)=>{let n=$(av(e),e.timescale),r=!Dh(t)||!Dh(n),i=r?d1:Y;return Q(`mdhd`,+r,0,[i(t),i(t),Y(e.timescale),i(n),J(J0(e.track.metadata.languageCode??`und`)),J(0)])},j1={video:`vide`,audio:`soun`,subtitle:`text`},M1={video:`MediabunnyVideoHandler`,audio:`MediabunnySoundHandler`,subtitle:`MediabunnyTextHandler`},N1=(e,t,n,r=`\0\0\0\0`,i=!1)=>Q(`hdlr`,0,0,[e?X(`mhlr`):Y(0),X(t),X(r),Y(0),Y(0),i?[q(n.length),X(n)]:X(n,!0)]),P1=e=>Z(`minf`,void 0,[F1[e.type](),I1(),z1(e)]),F1={video:()=>Q(`vmhd`,0,1,[J(0),J(0),J(0),J(0)]),audio:()=>Q(`smhd`,0,0,[J(0),J(0)]),subtitle:()=>Q(`nmhd`,0,0)},I1=()=>Z(`dinf`,void 0,[L1()]),L1=()=>Q(`dref`,0,0,[Y(1)],[R1()]),R1=()=>Q(`url `,0,1),z1=e=>{let t=e.compositionTimeOffsetTable.length>1||e.compositionTimeOffsetTable.some(e=>e.sampleCompositionTimeOffset!==0);return Z(`stbl`,void 0,[B1(e),u0(e),t?h0(e):null,t?g0(e):null,f0(e),p0(e),m0(e),d0(e),..._0(e.samples,!1)])},B1=e=>{let t;if(e.type===`video`)t=V1(H0(e.track.source._codec,e.info.decoderConfig.codec),e);else if(e.type===`audio`){let n=W0(e.track.source._codec,e.info.decoderConfig.codec,e.muxer.isQuickTime);W(n),t=Y1(n,e)}else e.type===`subtitle`&&(t=c0(K0[e.track.source._codec],e));return W(t),Q(`stsd`,0,0,[Y(1)],[t])},V1=(e,t)=>Z(e,[[,,,,,,].fill(0),J(1),J(0),J(0),Array(12).fill(0),J(t.info.width),J(t.info.height),Y(4718592),Y(4718592),Y(0),J(1),q(xg.length),X(xg),Array(31-xg.length).fill(0),J(t.info.hasAlphaChannel?32:24),c1(65535)],[U0[t.track.source._codec]?.(t)??null,U1(t),Ih(t.info.decoderConfig.colorSpace)?null:W1(t),H1(t)]),H1=e=>e.avgBitrate===0&&e.maxBitrate===0?null:Z(`btrt`,[Y(0),Y(e.maxBitrate),Y(e.avgBitrate)]),U1=e=>e.info.pixelAspectRatio.num===e.info.pixelAspectRatio.den?null:Z(`pasp`,[Y(e.info.pixelAspectRatio.num),Y(e.info.pixelAspectRatio.den)]),W1=e=>{let t=e.info.decoderConfig.colorSpace;return Z(`colr`,[X(e.muxer.isQuickTime?`nclc`:`nclx`),J(t?.primaries==null?2:Nh[t.primaries]),J(t?.transfer==null?2:Ph[t.transfer]),J(t?.matrix==null?2:Fh[t.matrix]),e.muxer.isQuickTime?[]:q(!!t?.fullRange<<7)])},G1=e=>e.info.decoderConfig&&Z(`avcC`,[...Ah(e.info.decoderConfig.description)]),K1=e=>e.info.decoderConfig&&Z(`hvcC`,[...Ah(e.info.decoderConfig.description)]),q1=e=>{if(!e.info.decoderConfig)return null;let t=e.info.decoderConfig,n=t.codec.split(`.`),r=Number(n[1]),i=Number(n[2]),a=n[3]?Number(n[3]):8,o=n[4]?Number(n[4]):1,s=n[8]?Number(n[8]):Number(t.colorSpace?.fullRange??0),c=(a<<4)+(o<<1)+s,l=n[5]?Number(n[5]):t.colorSpace?.primaries?Nh[t.colorSpace.primaries]:1,u=n[6]?Number(n[6]):t.colorSpace?.transfer?Ph[t.colorSpace.transfer]:1,d=n[7]?Number(n[7]):t.colorSpace?.matrix?Fh[t.colorSpace.matrix]:1;return Q(`vpcC`,1,0,[q(r),q(i),q(c),q(l),q(u),q(d),J(0)])},J1=e=>Z(`av1C`,U_(e.info.decoderConfig.codec)),Y1=(e,t)=>{let n=0,r,i=16,a=t.info.sampleRate,o=G0(t.track.source._codec,t.muxer.isQuickTime)?.(t)??null,s=I_.includes(t.track.source._codec);if(s){let{sampleSize:e}=q_(t.track.source._codec);i=8*e}else if(t.track.source._codec===`flac`){let e=t.info.decoderConfig?.description;W(e);let n=new sg(Ah(e));for(n.skipBits(167),i=n.readBits(5)+1;a>=2**16;)a=Math.floor(a/2)}if(t.muxer.isQuickTime&&t.track.source._codec!==`truehd`&&(n=t.info.sampleRate<2**16&&t.info.numberOfChannels<=2?1:2),n===0)r=[[,,,,,,].fill(0),J(1),J(n),J(0),Y(0),J(t.info.numberOfChannels),J(i),J(0),J(0),t.track.source._codec===`truehd`?Y(t.info.sampleRate):[J(a<2**16?a:0),J(0)]];else if(n===1){let e=s?0:-2;r=[[,,,,,,].fill(0),J(1),J(n),J(0),Y(0),J(t.info.numberOfChannels),J(Math.min(i,16)),c1(e),J(0),J(t.info.sampleRate<2**16?t.info.sampleRate:0),J(0),s?[Y(1),Y(i/8),Y(t.info.numberOfChannels*i/8)]:[Y(0),Y(0),Y(0)],Y(2)]}else if(n===2){let a=0;if(s){let{dataType:n,littleEndian:r}=q_(t.track.source._codec);n!==`ulaw`&&n!==`alaw`&&(e=`lpcm`,o=null,a=n===`float`|(r?0:2)|(n===`signed`?4:0)|8)}r=[[,,,,,,].fill(0),J(1),J(n),J(0),Y(0),J(3),J(16),c1(-2),J(0),Y(65536),Y(72),p1(t.info.sampleRate),Y(t.info.numberOfChannels),Y(0x7f000000),s?[Y(i),Y(a),Y(t.info.numberOfChannels*i/8),Y(1)]:[Y(0),Y(0),Y(0),Y(0)]]}else Bh(n),W(!1);return Z(e,r,[(e===`ipcm`||e===`fpcm`)&&t.info.sampleRate>=2**16?X1(t):null,o,H1(t)])},X1=e=>Q(`srat`,0,0,[Y(e.info.sampleRate)]),Z1=e=>{let t;switch(e.track.source._codec){case`aac`:t=64;break;case`mp3`:t=107;break;case`vorbis`:t=221;break;default:throw Error(`Unhandled audio codec: ${e.track.source._codec}`)}let n=[...q(t),...q(21),...l1(0),...Y(e.maxBitrate),...Y(e.avgBitrate)];if(e.info.decoderConfig.description){let t=Ah(e.info.decoderConfig.description);n=[...n,...q(5),..._1(t.byteLength),...t]}return n=[...J(1),...q(0),...q(4),..._1(n.length),...n,...q(6),...q(1),...q(2)],n=[...q(3),..._1(n.length),...n],Q(`esds`,0,0,n)},Q1=e=>Z(`wave`,void 0,[$1(e),e.track.source._codec===`ac3`?i0(e):e.track.source._codec===`eac3`?a0(e):e0(e),Z(`\0\0\0\0`)]),$1=e=>Z(`frma`,[X(W0(e.track.source._codec,e.info.decoderConfig.codec,e.muxer.isQuickTime))]),e0=e=>{let{littleEndian:t}=q_(e.track.source._codec);return Z(`enda`,[J(+t)])},t0=e=>{let t=e.info.numberOfChannels,n=312,r=e.info.sampleRate,i=0,a=0,o=new Uint8Array,s=e.info.decoderConfig?.description;if(s){W(s.byteLength>=18);let e=Kg(Ah(s));t=e.outputChannelCount,n=e.preSkip,r=e.inputSampleRate,i=e.outputGain,a=e.channelMappingFamily,e.channelMappingTable&&(o=e.channelMappingTable)}return Z(`dOps`,[q(0),q(t),J(n),Y(r),c1(i),q(a),...o])},n0=e=>{let t=e.info.decoderConfig?.description;return W(t),Q(`dfLa`,0,0,[...Ah(t).subarray(4)])},r0=e=>{let{littleEndian:t,sampleSize:n}=q_(e.track.source._codec);return Q(`pcmC`,0,0,[q(+t),q(8*n)])},i0=e=>{W(e.info.primingPacket);let t=Zg(e.info.primingPacket.data);if(!t)throw Error(`Couldn't extract AC-3 frame info from the audio packet. Ensure the packets contain valid AC-3 sync frames (as specified in ETSI TS 102 366).`);let n=new Uint8Array(3),r=new sg(n);return r.writeBits(2,t.fscod),r.writeBits(5,t.bsid),r.writeBits(3,t.bsmod),r.writeBits(3,t.acmod),r.writeBits(1,t.lfeon),r.writeBits(5,t.bitRateCode),r.writeBits(5,0),Z(`dac3`,[...n])},a0=e=>{W(e.info.primingPacket);let t=$g(e.info.primingPacket.data);if(!t)throw Error(`Couldn't extract E-AC-3 frame info from the audio packet. Ensure the packets contain valid E-AC-3 sync frames (as specified in ETSI TS 102 366).`);let n=16;for(let e of t.substreams)n+=23,e.numDepSub>0?n+=9:n+=1;let r=Math.ceil(n/8),i=new Uint8Array(r),a=new sg(i);a.writeBits(13,t.dataRate),a.writeBits(3,t.substreams.length-1);for(let e of t.substreams)a.writeBits(2,e.fscod),a.writeBits(5,e.bsid),a.writeBits(1,0),a.writeBits(1,0),a.writeBits(3,e.bsmod),a.writeBits(3,e.acmod),a.writeBits(1,e.lfeon),a.writeBits(3,0),a.writeBits(4,e.numDepSub),e.numDepSub>0?a.writeBits(9,e.chanLoc):a.writeBits(1,0);return Z(`dec3`,[...i])},o0=e=>{W(e.info.primingPacket);let t=d_(e.info.primingPacket.data);if(!t)throw Error(`Couldn't extract DTS frame info from the audio packet. Ensure the packets contain valid DTS frames as specified in ETSI TS 102 114.`);return Z(`ddts`,[...h_(t)])},s0=e=>{W(e.info.primingPacket);let t=e.info.primingPacket.data;if(Yg(`truehd`,t)!==`key`)throw Error(`Couldn't extract TrueHD stream info from the audio packet. Ensure the first packet is an access unit carrying a major sync.`);let n=jh(t),r=n.getUint32(8),i=n.getUint16(18)&32767;return Z(`dmlp`,[Y(r),J(i<<1),Y(0)])},c0=(e,t)=>Z(e,[[,,,,,,].fill(0),J(1)],[q0[t.track.source._codec](t),H1(t)]),l0=e=>Z(`vttC`,[...Mh.encode(e.info.config.description)]),u0=e=>Q(`stts`,0,0,[Y(e.timeToSampleTable.length),e.timeToSampleTable.map(e=>[Y(e.sampleCount),Y(e.sampleDelta)])]),d0=e=>{if(e.samples.every(e=>e.type===`key`))return null;let t=[...e.samples.entries()].filter(([,e])=>e.type===`key`);return Q(`stss`,0,0,[Y(t.length),t.map(([e])=>Y(e+1))])},f0=e=>Q(`stsc`,0,0,[Y(e.compactlyCodedChunkTable.length),e.compactlyCodedChunkTable.map(e=>[Y(e.firstChunk),Y(e.samplesPerChunk),Y(1)])]),p0=e=>{if(e.type===`audio`&&e.info.requiresPcmTransformation){let{sampleSize:t}=q_(e.track.source._codec);return Q(`stsz`,0,0,[Y(t*e.info.numberOfChannels),Y(e.samples.reduce((t,n)=>t+$(n.duration,e.timescale),0))])}return Q(`stsz`,0,0,[Y(0),Y(e.samples.length),e.samples.map(e=>Y(e.size))])},m0=e=>e.finalizedChunks.length>0&&Eh(e.finalizedChunks).offset>=2**32?Q(`co64`,0,0,[Y(e.finalizedChunks.length),e.finalizedChunks.map(e=>d1(e.offset))]):Q(`stco`,0,0,[Y(e.finalizedChunks.length),e.finalizedChunks.map(e=>Y(e.offset))]),h0=e=>Q(`ctts`,1,0,[Y(e.compositionTimeOffsetTable.length),e.compositionTimeOffsetTable.map(e=>[Y(e.sampleCount),u1(e.sampleCompositionTimeOffset)])]),g0=e=>{if(W(e.compositionTimeOffsetTable.length>0),e.samples.length===0)return null;let t=1/0,n=-1/0,r=1/0,i=-1/0;for(let r=0;r<e.compositionTimeOffsetTable.length;r++){let i=e.compositionTimeOffsetTable[r];t=Math.min(t,i.sampleCompositionTimeOffset),n=Math.max(n,i.sampleCompositionTimeOffset)}for(let t=0;t<e.samples.length;t++){let n=e.samples[t];r=Math.min(r,$(n.timestamp,e.timescale)),i=Math.max(i,$(n.timestamp+n.duration,e.timescale))}let a=Math.max(-t,0);return i>=2**31?null:Q(`cslg`,0,0,[u1(a),u1(t),u1(n),u1(r),u1(i)])},_0=(e,t)=>{let n=[];for(let t of e)if(n.length===0)n.push({sampleCount:1,prerollSamples:t.prerollSamples});else{let e=n[n.length-1];e.prerollSamples===t.prerollSamples?e.sampleCount++:n.push({sampleCount:1,prerollSamples:t.prerollSamples})}let r=n.filter(e=>e.prerollSamples!==0);if(r.length===0)return[];let i=t?65537:1;return[Q(`sgpd`,1,0,[X(`roll`),Y(2),Y(r.length),...r.map(e=>c1(e.prerollSamples))]),Q(`sbgp`,0,0,[X(`roll`),Y(n.length),...n.map(e=>[Y(e.sampleCount),Y(e.prerollSamples===0?0:i++)])])]},v0=e=>Z(`mvex`,void 0,e.map(y0)),y0=e=>Q(`trex`,0,0,[Y(e.track.id),Y(1),Y(0),Y(0),Y(0)]),b0=(e,t)=>Z(`moof`,void 0,[x0(e),...t.map(C0)]),x0=e=>Q(`mfhd`,0,0,[Y(e)]),S0=e=>{let t=0,n=0,r=e.type===`delta`;return n|=+r,t|=r?1:2,t<<24|n<<16},C0=e=>Z(`traf`,void 0,[w0(e),T0(e),E0(e),..._0(e.currentChunk.samples,!0)]),w0=e=>{W(e.currentChunk);let t=0;t|=8,t|=16,t|=32,t|=131072;let n=e.currentChunk.samples[1]??e.currentChunk.samples[0],r={duration:n.timescaleUnitsToNextSample,size:n.size,flags:S0(n)};return Q(`tfhd`,0,t,[Y(e.track.id),Y(r.duration),Y(r.size),Y(r.flags)])},T0=e=>(W(e.currentChunk),Q(`tfdt`,1,0,[d1($(e.currentChunk.samples[0].decodeTimestamp,e.timescale))])),E0=e=>{W(e.currentChunk);let t=e.currentChunk.offset-e.currentChunk.moofOffset||0;W(Oh(t));let n=e.currentChunk.samples.map(e=>e.timescaleUnitsToNextSample),r=e.currentChunk.samples.map(e=>e.size),i=e.currentChunk.samples.map(S0),a=e.currentChunk.samples.map(t=>$(t.timestamp-t.decodeTimestamp,e.timescale)),o=new Set(n),s=new Set(r),c=new Set(i),l=new Set(a),u=c.size===2&&i.lastIndexOf(i[0])===0,d=o.size>1,f=s.size>1,p=!u&&c.size>1,m=l.size>1||[...l].some(e=>e!==0),h=0;return h|=1,h|=4*u,h|=256*d,h|=512*f,h|=1024*p,h|=2048*m,Q(`trun`,1,h,[Y(e.currentChunk.samples.length),u1(t),u?Y(i[0]):[],e.currentChunk.samples.map((e,t)=>[d?Y(n[t]):[],f?Y(r[t]):[],p?Y(i[t]):[],m?u1(a[t]):[]])])},D0=e=>Z(`mfra`,void 0,[...e.map(O0),k0()]),O0=e=>Q(`tfra`,1,0,[Y(e.track.id),Y(63),Y(e.tfraEntries.length),e.tfraEntries.map(t=>[d1($(t.timestamp,e.timescale)),d1(t.moofOffset),Y(t.trafIndex+1),Y(1),Y(t.sampleIndex+1)])]),k0=()=>Q(`mfro`,0,0,[Y(0)]),A0=()=>Z(`vtte`),j0=(e,t,n,r,i)=>Z(`vttc`,void 0,[i===null?null:Z(`vsid`,[u1(i)]),n===null?null:Z(`iden`,[...Mh.encode(n)]),t===null?null:Z(`ctim`,[...Mh.encode(__(t))]),r===null?null:Z(`sttg`,[...Mh.encode(r)]),Z(`payl`,[...Mh.encode(e)])]),M0=e=>Z(`vtta`,[...Mh.encode(e)]),N0=e=>{let t=[],n=e.format._options.metadataFormat??`auto`,r=e.output._metadataTags;if(n===`mdir`||n===`auto`&&!e.isQuickTime){let e=z0(r);e&&t.push(e)}else if(n===`mdta`){let e=B0(r);e&&t.push(e)}else(n===`udta`||n===`auto`&&e.isQuickTime)&&P0(t,e.output._metadataTags);return t.length===0?null:Z(`udta`,void 0,t)},P0=(e,t)=>{for(let{key:n,value:r}of Yh(t))switch(n){case`title`:e.push(F0(`©nam`,r));break;case`description`:e.push(F0(`©des`,r));break;case`artist`:e.push(F0(`©ART`,r));break;case`album`:e.push(F0(`©alb`,r));break;case`albumArtist`:e.push(F0(`albr`,r));break;case`genre`:e.push(F0(`©gen`,r));break;case`date`:e.push(F0(`©day`,r.toISOString().slice(0,10)));break;case`comment`:e.push(F0(`©cmt`,r));break;case`lyrics`:e.push(F0(`©lyr`,r));break;case`raw`:case`creationTime`:case`discNumber`:case`discsTotal`:case`trackNumber`:case`tracksTotal`:case`beatsPerMinute`:case`images`:break;default:Bh(n)}if(t.raw)for(let n in t.raw){let r=t.raw[n];r==null||n.length!==4||e.some(e=>e.type===n)||(typeof r==`string`?e.push(F0(n,r)):r instanceof Uint8Array&&e.push(Z(n,Array.from(r))))}},F0=(e,t)=>{let n=Mh.encode(t);return Z(e,[J(n.length),J(J0(`und`)),Array.from(n)])},I0={"image/jpeg":13,"image/png":14,"image/bmp":27},L0=new Set([`HMMT`,`loci`,`chpl`]),R0=(e,t)=>{let n=[];for(let{key:r,value:i}of Yh(e))switch(r){case`title`:n.push({key:t?`title`:`©nam`,value:V0(i)});break;case`description`:n.push({key:t?`description`:`©des`,value:V0(i)});break;case`artist`:n.push({key:t?`artist`:`©ART`,value:V0(i)});break;case`album`:n.push({key:t?`album`:`©alb`,value:V0(i)});break;case`albumArtist`:n.push({key:t?`album_artist`:`aART`,value:V0(i)});break;case`comment`:n.push({key:t?`comment`:`©cmt`,value:V0(i)});break;case`genre`:n.push({key:t?`genre`:`©gen`,value:V0(i)});break;case`beatsPerMinute`:t||n.push({key:`tmpo`,value:Z(`data`,[Y(21),Y(0),J(i)])});break;case`lyrics`:n.push({key:t?`lyrics`:`©lyr`,value:V0(i)});break;case`date`:n.push({key:t?`date`:`©day`,value:V0(i.toISOString().slice(0,10))});break;case`images`:for(let e of i)e.kind===`coverFront`&&n.push({key:`covr`,value:Z(`data`,[Y(I0[e.mimeType]??0),Y(0),Array.from(e.data)])});break;case`trackNumber`:if(t){let t=e.tracksTotal===void 0?i.toString():`${i}/${e.tracksTotal}`;n.push({key:`track`,value:V0(t)})}else n.push({key:`trkn`,value:Z(`data`,[Y(0),Y(0),J(0),J(i),J(e.tracksTotal??0),J(0)])});break;case`discNumber`:t||n.push({key:`disk`,value:Z(`data`,[Y(0),Y(0),J(0),J(i),J(e.discsTotal??0),J(0)])});break;case`tracksTotal`:case`discsTotal`:case`raw`:case`creationTime`:break;default:Bh(r)}if(e.raw)for(let r in e.raw){let i=e.raw[r];i==null||!t&&(r.length!==4||L0.has(r))||n.some(e=>e.key===r)||(typeof i==`string`?n.push({key:r,value:V0(i)}):i instanceof Uint8Array?n.push({key:r,value:Z(`data`,[Y(0),Y(0),Array.from(i)])}):i instanceof rg&&n.push({key:r,value:Z(`data`,[Y(I0[i.mimeType]??0),Y(0),Array.from(i.data)])}))}return n},z0=e=>{let t=R0(e,!1);return t.length===0?null:Q(`meta`,0,0,void 0,[N1(!1,`mdir`,``,`appl`),Z(`ilst`,void 0,t.map(e=>Z(e.key,void 0,[e.value])))])},B0=e=>{let t=R0(e,!0);return t.length===0?null:Z(`meta`,void 0,[N1(!1,`mdta`,``),Q(`keys`,0,0,[Y(t.length)],t.map(e=>Z(`mdta`,[...Mh.encode(e.key)]))),Z(`ilst`,void 0,t.map((e,t)=>Z(String.fromCharCode(...Y(t+1)),void 0,[e.value])))])},V0=e=>Z(`data`,[Y(1),Y(0),...Mh.encode(e)]),H0=(e,t)=>{switch(e){case`avc`:return t.startsWith(`avc3`)?`avc3`:`avc1`;case`hevc`:return`hvc1`;case`vp8`:return`vp08`;case`vp9`:return`vp09`;case`av1`:return`av01`;case`prores`:return t}},U0={avc:G1,hevc:K1,vp8:q1,vp9:q1,av1:J1,prores:null},W0=(e,t,n)=>{switch(e){case`aac`:return`mp4a`;case`mp3`:return n?`.mp3`:`mp4a`;case`opus`:return`Opus`;case`vorbis`:return`mp4a`;case`flac`:return`fLaC`;case`ulaw`:return`ulaw`;case`alaw`:return`alaw`;case`pcm-u8`:return`raw `;case`pcm-s8`:return`sowt`;case`ac3`:return`ac-3`;case`eac3`:return`ec-3`;case`dts`:return t;case`truehd`:return`mlpa`}if(n)switch(e){case`pcm-s16`:return`sowt`;case`pcm-s16be`:return`twos`;case`pcm-s24`:case`pcm-s24be`:return`in24`;case`pcm-s32`:case`pcm-s32be`:return`in32`;case`pcm-f32`:case`pcm-f32be`:return`fl32`;case`pcm-f64`:case`pcm-f64be`:return`fl64`}else switch(e){case`pcm-s16`:case`pcm-s16be`:case`pcm-s24`:case`pcm-s24be`:case`pcm-s32`:case`pcm-s32be`:return`ipcm`;case`pcm-f32`:case`pcm-f32be`:case`pcm-f64`:case`pcm-f64be`:return`fpcm`}},G0=(e,t)=>{switch(e){case`aac`:return Z1;case`mp3`:return t?null:Z1;case`opus`:return t0;case`vorbis`:return Z1;case`flac`:return n0;case`ac3`:return t?Q1:i0;case`eac3`:return t?Q1:a0;case`dts`:return o0;case`truehd`:return s0}if(t)switch(e){case`pcm-s24`:case`pcm-s24be`:case`pcm-s32`:case`pcm-s32be`:case`pcm-f32`:case`pcm-f32be`:case`pcm-f64`:case`pcm-f64be`:return Q1}else switch(e){case`pcm-s16`:case`pcm-s16be`:case`pcm-s24`:case`pcm-s24be`:case`pcm-s32`:case`pcm-s32be`:case`pcm-f32`:case`pcm-f32be`:case`pcm-f64`:case`pcm-f64be`:return r0}return null},K0={webvtt:`wvtt`},q0={webvtt:l0},J0=e=>{W(e.length===3);let t=0;for(let n=0;n<3;n++)t<<=5,t+=e.charCodeAt(n)-96;return t},Y0=class{constructor(e,t){if(this.finalized=!1,this.started=!1,this.pos=0,this.trackedWrites=null,this.trackedStart=-1,this.trackedEnd=-1,e._writerAcquired)throw Error(`Can't have multiple Writers for the same Target.`);if(e._closed)throw Error(`Can't create a Writer for a Target that has already been closed.`);this.target=e,e._setMonotonicity(t),e._writerAcquired=!0}start(){W(!this.started),this.target._start(),this.started=!0}write(e){W(this.started&&!this.finalized),this.maybeTrackWrites(e),this.target._write(e,this.pos),this.pos+=e.byteLength}seek(e){this.pos=e}getPos(){return this.pos}async flush(){return W(this.started&&!this.finalized),this.target._flush()}async finalize(){W(this.started&&!this.finalized),await this.target._finalize(),this.finalized=!0}maybeTrackWrites(e){if(!this.trackedWrites)return;let t=this.getPos();if(t<this.trackedStart){if(t+e.byteLength<=this.trackedStart)return;e=e.subarray(this.trackedStart-t),t=this.trackedStart}let n=t+e.byteLength-this.trackedStart,r=this.trackedWrites.byteLength;for(;r<n;)r*=2;if(r!==this.trackedWrites.byteLength){let e=new Uint8Array(r);e.set(this.trackedWrites,0),this.trackedWrites=e}this.trackedWrites.set(e,t-this.trackedStart),this.trackedEnd=Math.max(this.trackedEnd,t+e.byteLength)}startTrackingWrites(){this.trackedWrites=new Uint8Array(1024),this.trackedStart=this.getPos(),this.trackedEnd=this.trackedStart}stopTrackingWrites(){if(!this.trackedWrites)throw Error(`Internal error: Can't get tracked writes since nothing was tracked.`);let e={data:this.trackedWrites.subarray(0,this.trackedEnd-this.trackedStart),start:this.trackedStart,end:this.trackedEnd};return this.trackedWrites=null,e}};C_();var X0=class extends $h{constructor(){super(...arguments),this._writerAcquired=!1,this._closed=!1,this._monotonicity=null,this.onwrite=null}_close(){return this._closed=!0,this._release()}_setMonotonicity(e){this._monotonicity!==!1&&(this._monotonicity=e)}_dispatchWrite(e,t){this.onwrite?.(e,t),this._emit(`write`,{start:e,end:t})}slice(e){if(!Number.isInteger(e)||e<0)throw TypeError(`offset must be a non-negative integer.`);return new ev(this,e)}},Z0=2**16,Q0=2**32,$0=class extends X0{constructor(e={}){if(super(),this.buffer=null,this._maxPos=0,!e||typeof e!=`object`)throw TypeError(`BufferTarget options, when provided, must be an object.`);if(e.onFinalize!==void 0&&typeof e.onFinalize!=`function`)throw TypeError(`options.onFinalize, when provided, must be a function.`);if(this._options=e,this._supportsResize=`resize`in new ArrayBuffer(0),this._supportsResize)try{this._buffer=new ArrayBuffer(Z0,{maxByteLength:Q0})}catch{this._buffer=new ArrayBuffer(Z0),this._supportsResize=!1}else this._buffer=new ArrayBuffer(Z0);this._bytes=new Uint8Array(this._buffer)}_ensureSize(e){W(this._buffer),W(this._bytes);let t=this._buffer.byteLength;for(;t<e;)t*=2;if(t!==this._buffer.byteLength){if(t>Q0)throw Error(`ArrayBuffer exceeded maximum size of ${Q0} bytes. Please consider using another target.`);if(this._supportsResize)this._buffer.resize(t);else{let e=new ArrayBuffer(t),n=new Uint8Array(e);n.set(this._bytes,0),this._buffer=e,this._bytes=n}}}_start(){}_write(e,t){W(this._bytes),this._ensureSize(t+e.byteLength),this._bytes.set(e,t),this._maxPos=Math.max(this._maxPos,t+e.byteLength),this._dispatchWrite(t,t+e.byteLength)}async _flush(){}async _finalize(){W(this._buffer),this.buffer=`transferToFixedLength`in this._buffer?this._buffer.transferToFixedLength(this._maxPos):this._buffer.slice(0,this._maxPos),this._buffer=null,this._bytes=null,this._options.onFinalize&&await this._options.onFinalize(this.buffer),this._emit(`finalized`)}async _release(){}_getSlice(e,t){return W(this._bytes),this._bytes.slice(e,t)}},ev=class extends X0{constructor(e,t){super(),this._baseTarget=e,this._offset=t}_start(){}_write(e,t){this._baseTarget._write(e,this._offset+t),this._dispatchWrite(t,t+e.byteLength)}_flush(){return this._baseTarget._flush()}async _finalize(){this._emit(`finalized`)}async _release(){}_setMonotonicity(e){super._setMonotonicity(e),this._baseTarget._setMonotonicity(e)}},tv=class{constructor(e,t){if(this.rootPath=e,this.getTarget=t,typeof e!=`string`)throw TypeError(`rootPath must be a string.`);if(typeof t!=`function`)throw TypeError(`getTarget must be a function.`)}},nv=57600,rv=.5,iv=e=>{let t={},n=e.track;return n.metadata.name!==void 0&&(t.name=n.metadata.name),t},$=(e,t,n=!0)=>{let r=e*t;return n?Math.round(r):r},av=e=>{if(e.samples.length===0)return 0;let t=1/0,n=-1/0;for(let r=0;r<e.samples.length;r++){let i=e.samples[r];i.timestamp<t&&(t=i.timestamp),i.timestamp+i.duration>n&&(n=i.timestamp+i.duration)}return t===1/0?0:n-t},ov=class extends i1{constructor(e,t){super(e),this.writer=null,this.boxWriter=null,this.initWriter=null,this.initBoxWriter=null,this.auxTarget=new $0,this.auxWriter=new Y0(this.auxTarget,!1),this.auxBoxWriter=new o1(this.auxWriter),this.mdat=null,this.ftypSize=null,this.trackDatas=[],this.closedTracks=new Set,this.allTracksKnown=zh(),this.finalizedChunks=[],this.wroteFragmentedHeader=!1,this.nextFragmentNumber=1,this.maxWrittenTimestamp=-1/0,this.minWrittenTimestamp=1/0,this.maxWrittenEndTimestamp=-1/0,this.segmentHeaderSize=null,this.format=t,this.formatOptions={...t._options},this.isQuickTime=t instanceof dv,this.isCmaf=t instanceof uv,this.minimumFragmentDuration=this.formatOptions.minimumFragmentDuration??(t instanceof uv?1/0:1),this.auxWriter.start()}async start(){let e=await this.mutex.acquire();try{let e=this.output._metadataTags.creationTime===void 0?new Date:this.output._metadataTags.creationTime;if(this.creationTime=e?Math.floor(e.getTime()/1e3)+b_:0,e&&this.creationTime<=0)throw Error(`creationTime must be after 1904-01-01T00:00:00Z for MP4/QuickTime files.`);if(this.isCmaf?(this.fastStart=`fragmented`,this.isFragmented=!0):(this.writer=await this.output._getRootWriter(e=>this.formatOptions.fastStart===void 0?e instanceof $0:this.formatOptions.fastStart===`in-memory`||this.formatOptions.fastStart===`fragmented`),this.boxWriter=new o1(this.writer),this.fastStart=this.formatOptions.fastStart??(this.writer.target instanceof $0&&`in-memory`),this.isFragmented=this.fastStart===`fragmented`),this.isCmaf){if(!this.output._hasInitTarget())throw Error(`CMAF outputs require the initTarget field in OutputOptions to be set; the init segment will be written to it.`);let e=new Y0(await this.output._getInitTarget(),!0);e.start(),this.initWriter=e,this.initBoxWriter=new o1(e)}let t=this.output.tracks.some(e=>e.isVideoTrack()&&e.source._codec===`avc`);{let e=this.initBoxWriter??this.boxWriter;if(W(e),this.formatOptions.onFtyp&&e.writer.startTrackingWrites(),e.writeBox(y1({isQuickTime:this.isQuickTime,holdsAvc:t,fragmented:this.isFragmented,cmaf:this.isCmaf})),this.formatOptions.onFtyp){let{data:t,start:n}=e.writer.stopTrackingWrites();this.formatOptions.onFtyp(t,n)}this.ftypSize=e.writer.getPos(),this.isCmaf&&await this.initWriter.flush()}if(this.fastStart!==`in-memory`){if(this.fastStart===`reserve`)for(let e of this.output.tracks){if(e.metadata.maximumPacketCount===void 0)throw Error(`All tracks must specify maximumPacketCount in their metadata when using fastStart: 'reserve'.`);if(e.metadata.maximumPacketCount>2**32-1)throw Error(`Track #${e.id} has a maximumPacketCount of ${e.metadata.maximumPacketCount}, which exceeds the maximum of ${2**32-1} packets per track that a non-fragmented file can hold.`)}else this.isFragmented||(W(this.writer),W(this.boxWriter),this.formatOptions.onMdat&&this.writer.startTrackingWrites(),this.mdat=S1(!0),this.boxWriter.writeBox(this.mdat))}await this.writer?.flush();for(let e of this.output.tracks)e.isVideoTrack()&&e.metadata.decoderConfig?this.getVideoTrackData(e,e.metadata.primingPacket??null,{decoderConfig:e.metadata.decoderConfig}):e.isAudioTrack()&&e.metadata.decoderConfig&&this.getAudioTrackData(e,e.metadata.primingPacket??null,{decoderConfig:e.metadata.decoderConfig})}finally{e()}}allTracksAreKnown(){for(let e of this.output.tracks)if(!this.closedTracks.has(e)&&!this.trackDatas.some(t=>t.track===e))return!1;return!0}async getMimeType(){await this.allTracksKnown.promise;let e=this.trackDatas.map(e=>e.type===`video`||e.type===`audio`?e.info.decoderConfig.codec:{webvtt:`wvtt`}[e.track.source._codec]);return x_({isQuickTime:this.isQuickTime,hasVideo:this.trackDatas.some(e=>e.type===`video`),hasAudio:this.trackDatas.some(e=>e.type===`audio`),codecStrings:e})}getVideoTrackData(e,t,n){let r=this.trackDatas.find(t=>t.track===e);if(r)return r;e1(n,e.source._codec),W(n),W(n.decoderConfig);let i={...n.decoderConfig};W(i.codedWidth!==void 0),W(i.codedHeight!==void 0);let a=!1;if(e.source._codec===`avc`&&!i.description){if(!t)throw Error(`No AVC description provided; you must therefore provide a priming packet.`);let e=Og(t.data);if(!e)throw Error(`Couldn't extract an AVCDecoderConfigurationRecord from the AVC packet. Make sure the packets are in Annex B format (as specified in ITU-T-REC-H.264) when not providing a description, or provide a description (must be an AVCDecoderConfigurationRecord as specified in ISO 14496-15) and ensure the packets are in AVCC format.`);i.description=kg(e),a=!0}else if(e.source._codec===`hevc`&&!i.description){if(!t)throw Error(`No HEVC description provided; you must therefore provide a priming packet.`);let e=Ig(t.data);if(!e)throw Error(`Couldn't extract an HEVCDecoderConfigurationRecord from the HEVC packet. Make sure the packets are in Annex B format (as specified in ITU-T-REC-H.265) when not providing a description, or provide a description (must be an HEVCDecoderConfigurationRecord as specified in ISO 14496-15) and ensure the packets are in HEVC format.`);i.description=Wg(e),a=!0}let o=Kh(1/(e.metadata.frameRate??57600),1e6).den,s=i.displayAspectWidth,c=i.displayAspectHeight,l=s===void 0||c===void 0?{num:1,den:1}:Zh({num:s*i.codedHeight,den:c*i.codedWidth}),u=i.codec===`ap4h`||i.codec===`ap4x`,d={muxer:this,track:e,type:`video`,info:{width:i.codedWidth,height:i.codedHeight,pixelAspectRatio:l,decoderConfig:i,requiresAnnexBTransformation:a,hasAlphaChannel:u},timescale:o,samples:[],sampleQueue:[],timestampProcessingQueue:[],timeToSampleTable:[],compositionTimeOffsetTable:[],lastTimescaleUnits:null,lastSample:null,startTimestampOffset:null,finalizedChunks:[],currentChunk:null,tfraEntries:[],compactlyCodedChunkTable:[],avgBitrate:e.source._nominalBitrate??e.metadata.averageBitrate??0,maxBitrate:e.source._nominalBitrate??e.metadata.bitrate??0};return this.trackDatas.push(d),this.trackDatas.sort((e,t)=>e.track.id-t.track.id),this.allTracksAreKnown()&&this.allTracksKnown.resolve(),d}getAudioTrackData(e,t,n){let r=this.trackDatas.find(t=>t.track===e);if(r)return r;n1(n,e.source._codec),W(n),W(n.decoderConfig);let i={...n.decoderConfig},a=!1;if(e.source._codec===`aac`&&!i.description){if(!t)throw Error(`No AAC description provided; you must therefore provide a priming packet.`);let e=S_(w_.tempFromBytes(t.data));if(!e)throw Error(`Couldn't parse ADTS header from the AAC packet. Make sure the packets are in ADTS format (as specified in ISO 13818-7) when not providing a description, or provide a description (must be an AudioSpecificConfig as specified in ISO 14496-3) and ensure the packets are raw AAC data.`);let n,r=null;if(e.channelConfiguration===0){let i=e.crcCheck===null?7:9,a=gg(t.data.subarray(i));if(!a)throw Error(`ADTS frames with channel configuration 0 must begin with a program config element.`);r=a.programConfigElement,n=vg(r)}else n=lg[e.channelConfiguration];i.description=ug({objectType:e.objectType,outputSampleRate:cg[e.samplingFrequencyIndex],outputNumberOfChannels:n,programConfigElement:r}),a=!0}if(!t){if(e.source._codec===`ac3`||e.source._codec===`eac3`)throw Error(`AC-3/E-AC-3 require a priming packet.`);if(e.source._codec===`dts`)throw Error(`DTS requires a priming packet.`);if(e.source._codec===`truehd`)throw Error(`TrueHD requires a priming packet.`)}let o={muxer:this,track:e,type:`audio`,info:{numberOfChannels:n.decoderConfig.numberOfChannels,sampleRate:n.decoderConfig.sampleRate,decoderConfig:i,requiresPcmTransformation:!this.isFragmented&&I_.includes(e.source._codec),expectedNextPcmPacketTimestamp:null,requiresAdtsStripping:a,primingPacket:t,pendingEac3Packets:[],preroll:{packetCount:0,accumulatedAudioSamples:0,audioSampleDurationHistory:[]}},timescale:i.sampleRate,samples:[],sampleQueue:[],timestampProcessingQueue:[],timeToSampleTable:[],compositionTimeOffsetTable:[],lastTimescaleUnits:null,lastSample:null,startTimestampOffset:null,finalizedChunks:[],currentChunk:null,tfraEntries:[],compactlyCodedChunkTable:[],avgBitrate:e.source._nominalBitrate??e.metadata.averageBitrate??0,maxBitrate:e.source._nominalBitrate??e.metadata.bitrate??0};return this.trackDatas.push(o),this.trackDatas.sort((e,t)=>e.track.id-t.track.id),this.allTracksAreKnown()&&this.allTracksKnown.resolve(),o}getSubtitleTrackData(e,t){let n=this.trackDatas.find(t=>t.track===e);if(n)return n;r1(t),W(t),W(t.config);let r={muxer:this,track:e,type:`subtitle`,info:{config:t.config},timescale:1e3,samples:[],sampleQueue:[],timestampProcessingQueue:[],timeToSampleTable:[],compositionTimeOffsetTable:[],lastTimescaleUnits:null,lastSample:null,startTimestampOffset:null,finalizedChunks:[],currentChunk:null,tfraEntries:[],compactlyCodedChunkTable:[],avgBitrate:e.source._nominalBitrate??e.metadata.averageBitrate??0,maxBitrate:e.source._nominalBitrate??e.metadata.bitrate??0,lastCueEndTimestamp:null,cueQueue:[],nextSourceId:0,cueToSourceId:new WeakMap};return this.trackDatas.push(r),this.trackDatas.sort((e,t)=>e.track.id-t.track.id),this.allTracksAreKnown()&&this.allTracksKnown.resolve(),r}async addEncodedVideoPacket(e,t,n){let r=await this.mutex.acquire();try{let r=this.getVideoTrackData(e,t,n),i=t.data;if(r.info.requiresAnnexBTransformation){let e=[...wg(i)].map(e=>i.subarray(e.offset,e.offset+e.length));if(e.length===0)throw Error(`Failed to transform packet data. Make sure all packets are provided in Annex B format, as specified in ITU-T-REC-H.264 and ITU-T-REC-H.265.`);i=Dg(e,4)}this.validateTimestamp(r.track,t.timestamp,t.type===`key`);let a=this.createSampleForTrack(r,i,t.timestamp,t.duration,t.type,0);await this.registerSample(r,a)}finally{r()}}async addEncodedAudioPacket(e,t,n){let r=await this.mutex.acquire();try{let r=this.getAudioTrackData(e,t,n),i=t.data;if(r.info.requiresAdtsStripping){let e=S_(w_.tempFromBytes(i));if(!e)throw Error(`Expected ADTS frame, didn't get one.`);let t=e.crcCheck===null?7:9;if(i=i.subarray(t),e.channelConfiguration===0){let e=gg(i);e&&(i=i.subarray(e.size))}}if(this.validateTimestamp(r.track,t.timestamp,t.type===`key`),e.source._codec===`eac3`){let e=e_(i),n=e?e.reduce((e,t)=>e+t.blockCount,0):6,a=r.info.pendingEac3Packets,o=a.reduce((e,t)=>e+t.blockCount,0)+n;if(o>6)throw Error(`E-AC-3 frames must add up to exactly six blocks to be muxed into MP4 samples.`);a.push({packet:t,blockCount:n}),o===6&&await this.writePendingEac3Packets(r);return}let a=t.timestamp,o=t.duration;if(r.info.requiresPcmTransformation){let e=q_(r.info.decoderConfig.codec).sampleSize*r.info.numberOfChannels;if(o=i.byteLength/e/r.info.sampleRate,r.info.expectedNextPcmPacketTimestamp!==null){let e=a-r.info.expectedNextPcmPacketTimestamp;if(e<.01)a=r.info.expectedNextPcmPacketTimestamp;else{let t=await this.padWithSilence(r,r.info.expectedNextPcmPacketTimestamp,e);a=r.info.expectedNextPcmPacketTimestamp+t}}r.info.expectedNextPcmPacketTimestamp=a+o}let{preroll:s}=r.info,c=0;if(e.source._codec===`aac`||e.source._codec===`vorbis`)c=-Math.min(1,s.packetCount);else if(e.source._codec===`mp3`)c=-Math.min(2,s.packetCount);else if(e.source._codec===`opus`){let e=Math.round(G_*W_);c=-s.audioSampleDurationHistory.length;let t=Jg(i);for(s.accumulatedAudioSamples+=t.durationInSamples,s.audioSampleDurationHistory.push(t.durationInSamples);s.accumulatedAudioSamples-s.audioSampleDurationHistory[0]>=e;)s.accumulatedAudioSamples-=s.audioSampleDurationHistory.shift(),W(s.audioSampleDurationHistory.length>0)}s.packetCount++;let l=this.createSampleForTrack(r,i,a,o,t.type,c);await this.registerSample(r,l)}finally{r()}}async padWithSilence(e,t,n){let r=$(n,e.timescale),{sampleSize:i,silentValue:a}=q_(e.info.decoderConfig.codec),o=i*e.info.numberOfChannels,s=new Uint8Array(o*Math.min(r,e.timescale)).fill(a);for(let n=0;n<r;n+=e.timescale){let i=Math.min(r-n,e.timescale),a=this.createSampleForTrack(e,s.subarray(0,o*i),t+n/e.timescale,i/e.timescale,`key`,0);await this.registerSample(e,a)}return r/e.timescale}async addSubtitleCue(e,t,n){let r=await this.mutex.acquire();try{let r=this.getSubtitleTrackData(e,n);if(this.validateTimestamp(r.track,t.timestamp,!0),e.source._codec===`webvtt`){let e=$(t.timestamp,r.timescale)/r.timescale,n=$(t.timestamp+t.duration,r.timescale)/r.timescale;n>e&&r.cueQueue.push({cue:t,start:e,end:n}),await this.processWebVTTCues(r,e)}}finally{r()}}async processWebVTTCues(e,t){for(;e.cueQueue.length>0;){e.lastCueEndTimestamp??=Math.min(0,e.cueQueue[0].start);let n=new Set([]);for(let{start:r,end:i}of e.cueQueue)W(r<=t),W(e.lastCueEndTimestamp<=i),n.add(Math.max(r,e.lastCueEndTimestamp)),n.add(i);let r=[...n].sort((e,t)=>e-t),i=r[0],a=r[1]??i;if(t<a)break;if(e.lastCueEndTimestamp<i){this.auxWriter.seek(0);let t=A0();this.auxBoxWriter.writeBox(t);let n=this.auxTarget._getSlice(0,this.auxWriter.getPos()),r=this.createSampleForTrack(e,n,e.lastCueEndTimestamp,i-e.lastCueEndTimestamp,`key`,0);await this.registerSample(e,r),e.lastCueEndTimestamp=i}this.auxWriter.seek(0);for(let t=0;t<e.cueQueue.length;t++){let{cue:n,start:r,end:o}=e.cueQueue[t];if(r>=a)break;g_.lastIndex=0;let s=g_.test(n.text),c=e.cueToSourceId.get(n);if(c===void 0&&a<o&&(c=e.nextSourceId++,e.cueToSourceId.set(n,c)),n.notes){let e=M0(n.notes);this.auxBoxWriter.writeBox(e)}let l=j0(n.text,s?i:null,n.identifier??null,n.settings??null,c??null);this.auxBoxWriter.writeBox(l),o===a&&e.cueQueue.splice(t--,1)}let o=this.auxTarget._getSlice(0,this.auxWriter.getPos()),s=this.createSampleForTrack(e,o,i,a-i,`key`,0);await this.registerSample(e,s),e.lastCueEndTimestamp=a}}createSampleForTrack(e,t,n,r,i,a){return{timestamp:n,decodeTimestamp:n,duration:r,data:t,size:t.byteLength,type:i,timescaleUnitsToNextSample:$(r,e.timescale),prerollSamples:a}}processTimestamps(e,t){if(e.timestampProcessingQueue.length===0)return;if(e.type===`audio`&&e.info.requiresPcmTransformation){W(!this.isFragmented),e.startTimestampOffset??=e.timestampProcessingQueue[0].timestamp;let t=0;for(let n=0;n<e.timestampProcessingQueue.length;n++){let r=$(e.timestampProcessingQueue[n].duration,e.timescale);t+=r}if(e.timeToSampleTable.length===0)e.timeToSampleTable.push({sampleCount:t,sampleDelta:1});else{let n=Eh(e.timeToSampleTable);n.sampleCount+=t}e.timestampProcessingQueue.length=0;return}let n=e.timestampProcessingQueue,r=n.map(e=>e.timestamp).sort((e,t)=>e-t),i=$(r[0],e.timescale);this.isFragmented?e.startTimestampOffset??=Math.min(r[0],0):e.startTimestampOffset??=r[0];let a;e.lastTimescaleUnits===null?a=i:(W(e.lastSample),a=Math.round(e.lastTimescaleUnits)+e.lastSample.timescaleUnitsToNextSample);let o=0;for(let t=0;t<n.length;t++){let s=n[t],c=a+$(r[t],e.timescale)-i;s.decodeTimestamp=c/e.timescale;let l=$(s.timestamp,e.timescale)-c,u=$(s.duration,e.timescale);if(e.lastTimescaleUnits!==null){W(e.lastSample);let t=$(s.decodeTimestamp,e.timescale,!1),n=Math.round(t-e.lastTimescaleUnits);if(W(n>=0),e.lastTimescaleUnits+=n,e.lastSample.timescaleUnitsToNextSample=n,o=n,!this.isFragmented){let t=Eh(e.timeToSampleTable);if(W(t),t.sampleCount===1){t.sampleDelta=n;let r=e.timeToSampleTable[e.timeToSampleTable.length-2];r&&r.sampleDelta===n&&(r.sampleCount++,e.timeToSampleTable.pop(),t=r)}else t.sampleDelta!==n&&(t.sampleCount--,e.timeToSampleTable.push(t={sampleCount:1,sampleDelta:n}));t.sampleDelta===u?t.sampleCount++:e.timeToSampleTable.push({sampleCount:1,sampleDelta:u});let r=Eh(e.compositionTimeOffsetTable);W(r),r.sampleCompositionTimeOffset===l?r.sampleCount++:e.compositionTimeOffsetTable.push({sampleCount:1,sampleCompositionTimeOffset:l})}}else e.lastTimescaleUnits=$(s.decodeTimestamp,e.timescale,!1),this.isFragmented||(e.timeToSampleTable.push({sampleCount:1,sampleDelta:u}),e.compositionTimeOffsetTable.push({sampleCount:1,sampleCompositionTimeOffset:l}));e.lastSample=s}if(e.timestampProcessingQueue.length=0,W(e.lastSample),W(e.lastTimescaleUnits!==null),t){let n=$(t.timestamp,e.timescale);e.lastSample.timescaleUnitsToNextSample=Math.max(n-Math.round(e.lastTimescaleUnits),o)}}async registerSample(e,t){t.type===`key`&&this.processTimestamps(e,t),e.timestampProcessingQueue.push(t),e.sampleQueue.push(t),await this.interleaveSamples()}async addSampleToTrack(e,t){if(!this.isFragmented&&(e.samples.push(t),this.fastStart===`reserve`)){let t=e.track.metadata.maximumPacketCount;if(W(t!==void 0),e.samples.length>t)throw Error(`Track #${e.track.id} has already reached the maximum packet count (${t}). Either add fewer packets or increase the maximum packet count.`)}let n=!1;if(!e.currentChunk)n=!0;else{e.currentChunk.startTimestamp=Math.min(e.currentChunk.startTimestamp,t.timestamp);let r=t.timestamp-e.currentChunk.startTimestamp;if(this.isFragmented){let i=this.trackDatas.every(n=>{if(e===n)return t.type===`key`;let r=n.sampleQueue[0];return r?r.type===`key`:this.closedTracks.has(n.track)}),a=this.wroteFragmentedHeader||this.trackDatas.every(e=>e.startTimestampOffset!==null||this.closedTracks.has(e.track));r>=this.minimumFragmentDuration&&i&&t.timestamp>this.maxWrittenTimestamp&&a&&(n=!0,await this.finalizeFragment())}else n=r>=rv}if(n){if(!this.isFragmented){let e=this.trackDatas.filter(e=>e.currentChunk&&t.timestamp-e.currentChunk.startTimestamp>=rv).sort((e,t)=>e.currentChunk.startTimestamp-t.currentChunk.startTimestamp);for(let t of e)await this.finalizeCurrentChunk(t)}e.currentChunk={startTimestamp:t.timestamp,samples:[],offset:null,moofOffset:null}}W(e.currentChunk),e.currentChunk.samples.push(t),this.isFragmented&&(this.maxWrittenTimestamp=Math.max(this.maxWrittenTimestamp,t.timestamp),this.maxWrittenEndTimestamp=Math.max(this.maxWrittenEndTimestamp,t.timestamp+t.duration),this.minWrittenTimestamp=Math.min(this.minWrittenTimestamp,t.timestamp))}async finalizeCurrentChunk(e){W(!this.isFragmented),W(this.writer);let t=e.currentChunk;W(t),e.currentChunk=null,e.finalizedChunks.push(t);let n=t.samples.length;if(e.type===`audio`&&e.info.requiresPcmTransformation&&(n=t.samples.reduce((t,n)=>t+$(n.duration,e.timescale),0)),(e.compactlyCodedChunkTable.length===0||Eh(e.compactlyCodedChunkTable).samplesPerChunk!==n)&&e.compactlyCodedChunkTable.push({firstChunk:e.finalizedChunks.length,samplesPerChunk:n}),this.fastStart===`in-memory`)t.offset=0,this.finalizedChunks.push(t);else{t.offset=this.writer.getPos();for(let e of t.samples)W(e.data),this.writer.write(e.data),e.data=null;t.samples.length=0,await this.writer.flush()}}async interleaveSamples(e=!1){if(e||this.allTracksAreKnown()){this.fastStart===`reserve`&&!this.mdat&&await this.createFastStartReserveMdat();e:for(;;){let t=null,n=1/0;for(let r of this.trackDatas){if(!e&&r.sampleQueue.length===0&&!this.closedTracks.has(r.track))break e;r.sampleQueue.length>0&&r.sampleQueue[0].timestamp<n&&(t=r,n=r.sampleQueue[0].timestamp)}if(!t)break;let r=t.sampleQueue.shift();await this.addSampleToTrack(t,r)}}}async finalizeFragment(e=!this.isCmaf){if(W(this.isFragmented),!this.wroteFragmentedHeader){this.wroteFragmentedHeader=!0;let e=this.initBoxWriter??this.boxWriter;W(e),this.formatOptions.onMoov&&e.writer.startTrackingWrites(),this.ensureOneEnabledTrack();let t=w1(this);if(e.writeBox(t),this.formatOptions.onMoov){let{data:t,start:n}=e.writer.stopTrackingWrites();this.formatOptions.onMoov(t,n)}if(this.isCmaf){W(this.initWriter),await this.initWriter.flush(),await this.initWriter.finalize(),this.writer=await this.output._getRootWriter(!0),this.boxWriter=new o1(this.writer);let e=this.boxWriter.measureBox(b1()),t=this.boxWriter.measureBox(x1(this,0));this.segmentHeaderSize=e+t,this.writer.seek(this.segmentHeaderSize)}}W(this.writer),W(this.boxWriter);let t=this.trackDatas.filter(e=>e.currentChunk);if(t.length===0){e&&await this.writer.flush();return}let n=this.nextFragmentNumber++,r=b0(n,t),i=this.writer.getPos(),a=i+this.boxWriter.measureBox(r),o=a+8,s=1/0;for(let e=0;e<t.length;e++){let n=t[e];W(n.currentChunk),W(n.startTimestampOffset!==null),s=Math.min(s,n.currentChunk.startTimestamp),n.currentChunk.offset=o,n.currentChunk.moofOffset=i,n.currentChunk.startTimestamp-=n.startTimestampOffset;for(let e of n.currentChunk.samples)o+=e.size,e.timestamp-=n.startTimestampOffset,e.decodeTimestamp-=n.startTimestampOffset}let c=o-a,l=c>=2**32;if(l){for(let e of t)e.currentChunk.offset+=8;c+=8}if(Eh(t).currentChunk.offset-i>=2**31)throw Error(`The data of a fragment's track must start less than 2 GiB after its moof box; use shorter fragments.`);this.formatOptions.onMoof&&this.writer.startTrackingWrites();let u=b0(n,t);if(this.boxWriter.writeBox(u),this.formatOptions.onMoof){let{data:e,start:t}=this.writer.stopTrackingWrites();this.formatOptions.onMoof(e,t,s)}W(this.writer.getPos()===a),this.formatOptions.onMdat&&this.writer.startTrackingWrites();let d=S1(l);d.size=c,this.boxWriter.writeBox(d),this.writer.seek(a+(l?16:8));for(let e of t)for(let t of e.currentChunk.samples)this.writer.write(t.data),t.data=null;if(this.formatOptions.onMdat){let{data:e,start:t}=this.writer.stopTrackingWrites();this.formatOptions.onMdat(e,t)}for(let e=0;e<t.length;e++){let n=t[e];if(W(n.currentChunk),!this.isCmaf){let t=n.currentChunk.samples.findIndex(e=>e.type===`key`);t!==-1&&n.tfraEntries.push({timestamp:n.currentChunk.samples[t].timestamp,moofOffset:i,trafIndex:e,sampleIndex:t})}n.currentChunk=null}e&&await this.writer.flush()}async createFastStartReserveMdat(){W(this.writer),W(this.boxWriter),this.ensureOneEnabledTrack();let e=w1(this),t=this.boxWriter.measureBox(e)+this.computeSampleTableSizeUpperBound()+4096;W(this.ftypSize!==null),this.writer.seek(this.ftypSize+t),this.formatOptions.onMdat&&this.writer.startTrackingWrites(),this.mdat=S1(!0),this.boxWriter.writeBox(this.mdat)}computeSampleTableSizeUpperBound(){W(this.fastStart===`reserve`);let e=0;for(let t of this.trackDatas){let n=t.track.metadata.maximumPacketCount;W(n!==void 0),e+=8*Math.ceil(2/3*n),e+=4*n,e+=8*Math.ceil(2/3*n),e+=12*Math.ceil(2/3*n),e+=4*n,e+=8*n,t.type===`audio`&&(e+=2*n,e+=8*n)}return e}async onTrackClose(e){let t=await this.mutex.acquire();try{let t=this.trackDatas.find(t=>t.track===e);t?.type===`subtitle`&&e.source._codec===`webvtt`&&await this.processWebVTTCues(t,1/0),t?.type===`audio`&&t.info.pendingEac3Packets.length>0&&await this.writePendingEac3Packets(t),this.closedTracks.add(e),t&&this.processTimestamps(t),this.allTracksAreKnown()&&this.allTracksKnown.resolve(),await this.interleaveSamples()}finally{t()}}ensureOneEnabledTrack(){for(let e of[`video`,`audio`,`subtitle`]){let t=this.trackDatas.filter(t=>t.type===e);if(t.length!==0&&!t.some(e=>e.track.metadata.disposition?.default!==!1)){let e=t[0];e.track.metadata.disposition={...e.track.metadata.disposition,default:!0}}}}async forceFragmentFinalization(){W(this.isFragmented);let e=await this.mutex.acquire();try{for(let e of this.trackDatas)e.type===`subtitle`&&e.track.source._codec===`webvtt`&&await this.processWebVTTCues(e,1/0),this.processTimestamps(e);await this.interleaveSamples(!0),await this.finalizeFragment()}finally{e()}}async writePendingEac3Packets(e){let t=e.info.pendingEac3Packets.map(e=>e.packet);e.info.pendingEac3Packets.length=0;let n=t[0].data;if(t.length>1){n=new Uint8Array(t.reduce((e,t)=>e+t.data.byteLength,0));let e=0;for(let r of t)n.set(r.data,e),e+=r.data.byteLength}let r=t.reduce((e,t)=>e+t.duration,0),i=this.createSampleForTrack(e,n,t[0].timestamp,r,`key`,0);await this.registerSample(e,i)}async finalize(){let e=await this.mutex.acquire();this.allTracksKnown.resolve(),this.ensureOneEnabledTrack();for(let e of this.trackDatas)e.type===`subtitle`&&e.track.source._codec===`webvtt`&&await this.processWebVTTCues(e,1/0),e.type===`audio`&&e.info.pendingEac3Packets.length>0&&await this.writePendingEac3Packets(e),this.closedTracks.add(e.track),this.processTimestamps(e);if(await this.interleaveSamples(!0),this.isFragmented)await this.finalizeFragment(!1);else{let e=this.trackDatas.filter(e=>e.currentChunk).sort((e,t)=>e.currentChunk.startTimestamp-t.currentChunk.startTimestamp);for(let t of e)await this.finalizeCurrentChunk(t);for(let e of this.trackDatas){let t=av(e);if(t>0){let n=0;for(let t of e.samples)n+=t.size;e.avgBitrate=Math.round(8*n/t)}else e.avgBitrate=0;let n=0,r=0,i=0;for(let t=0;t<e.samples.length;t++){let a=e.samples[t];for(r+=a.size;a.decodeTimestamp-e.samples[n].decodeTimestamp>=1;)r-=e.samples[n].size,n++;i=Math.max(i,r)}if(e.maxBitrate=8*i,e.startTimestampOffset!==null)for(let t=0;t<e.samples.length;t++){let n=e.samples[t];n.timestamp-=e.startTimestampOffset,n.decodeTimestamp-=e.startTimestampOffset}}}if(W(this.writer),W(this.boxWriter),this.fastStart===`in-memory`){this.mdat=S1(!1);let e,t=null;for(;;){let n=this.boxWriter.measureBox(w1(this)),r=this.boxWriter.measureBox(this.mdat),i=n+r;if(i===t)break;t=i,e=r;let a=this.writer.getPos()+i;for(let t of this.finalizedChunks){t.offset=a;for(let{data:n}of t.samples)W(n),a+=n.byteLength,e+=n.byteLength}e>=2**32&&(this.mdat.largeSize=!0)}this.formatOptions.onMoov&&this.writer.startTrackingWrites();let n=w1(this);if(this.boxWriter.writeBox(n),this.formatOptions.onMoov){let{data:e,start:t}=this.writer.stopTrackingWrites();this.formatOptions.onMoov(e,t)}this.formatOptions.onMdat&&this.writer.startTrackingWrites(),this.mdat.size=e,this.boxWriter.writeBox(this.mdat);for(let e of this.finalizedChunks){for(let t of e.samples)W(t.data),this.writer.write(t.data),t.data=null;await this.writer.flush()}if(this.formatOptions.onMdat){let{data:e,start:t}=this.writer.stopTrackingWrites();this.formatOptions.onMdat(e,t)}}else if(this.isFragmented){if(this.isCmaf){let e=this.segmentHeaderSize===null?0:this.writer.getPos()-this.segmentHeaderSize;if(e>=2**31)throw Error(`CMAF segments must be smaller than 2 GiB, as their sidx box can't index anything larger.`);this.writer.seek(0),this.boxWriter.writeBox(b1()),this.boxWriter.writeBox(x1(this,e))}else{let e=this.writer.getPos(),t=D0(this.trackDatas);this.boxWriter.writeBox(t);let n=this.writer.getPos()-e;this.writer.seek(this.writer.getPos()-4),this.boxWriter.writeU32(n)}}else{W(this.mdat);let e=this.boxWriter.offsets.get(this.mdat);W(e!==void 0);let t=this.writer.getPos()-e;if(this.mdat.size=t,this.mdat.largeSize=t>=2**32,this.boxWriter.patchBox(this.mdat),this.formatOptions.onMdat){let{data:e,start:t}=this.writer.stopTrackingWrites();this.formatOptions.onMdat(e,t)}let n=w1(this);if(this.fastStart===`reserve`){W(this.ftypSize!==null);let e=this.boxWriter.offsets.get(this.mdat)-this.ftypSize,t=this.boxWriter.measureBox(n);if(t+8>e)throw Error(`The moov box (${t} bytes) plus a free box (8 bytes) exceed the space reserved for them (${e} bytes) with fastStart: 'reserve'. This is a bug; please report it.`);this.writer.seek(this.ftypSize+t),this.boxWriter.writeBox(C1(e-t)),this.writer.seek(this.ftypSize)}if(this.formatOptions.onMoov&&this.writer.startTrackingWrites(),this.boxWriter.writeBox(n),this.formatOptions.onMoov){let{data:e,start:t}=this.writer.stopTrackingWrites();this.formatOptions.onMoov(e,t)}}e()}},sv=class{get supportsVideoRotationMetadata(){return this.supportsVideoTransformationMetadata}get requiresMaximumPacketCount(){return!1}getSupportedVideoCodecs(){return this.getSupportedCodecs().filter(e=>F_.includes(e))}getSupportedAudioCodecs(){return this.getSupportedCodecs().filter(e=>R_.includes(e))}getSupportedSubtitleCodecs(){return this.getSupportedCodecs().filter(e=>z_.includes(e))}_codecUnsupportedHint(e){return``}_isFragmentedIsobmff(){return!1}_withoutXingHeader(){return this}},cv=class extends sv{constructor(e={}){if(!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(e.fastStart!==void 0&&![!1,`in-memory`,`reserve`,`fragmented`].includes(e.fastStart))throw TypeError(`options.fastStart, when provided, must be false, 'in-memory', 'reserve', or 'fragmented'.`);if(e.minimumFragmentDuration!==void 0&&(!Xh(e.minimumFragmentDuration)||e.minimumFragmentDuration<0))throw TypeError(`options.minimumFragmentDuration, when provided, must be a non-negative number.`);if(e.onFtyp!==void 0&&typeof e.onFtyp!=`function`)throw TypeError(`options.onFtyp, when provided, must be a function.`);if(e.onMoov!==void 0&&typeof e.onMoov!=`function`)throw TypeError(`options.onMoov, when provided, must be a function.`);if(e.onMdat!==void 0&&typeof e.onMdat!=`function`)throw TypeError(`options.onMdat, when provided, must be a function.`);if(e.onMoof!==void 0&&typeof e.onMoof!=`function`)throw TypeError(`options.onMoof, when provided, must be a function.`);if(e.metadataFormat!==void 0&&![`mdir`,`mdta`,`udta`,`auto`].includes(e.metadataFormat))throw TypeError(`options.metadataFormat, when provided, must be either 'auto', 'mdir', 'mdta', or 'udta'.`);super(),this._options=e}getSupportedTrackCounts(){let e=2**32-1;return{video:{min:0,max:e},audio:{min:0,max:e},subtitle:{min:0,max:e},total:{min:0,max:e}}}get supportsVideoTransformationMetadata(){return!0}get supportsTimestampedMediaData(){return!0}get negativeTimestampSupport(){return`full`}get requiresMaximumPacketCount(){return this._options.fastStart===`reserve`}_createMuxer(e){return new ov(e,this)}_isFragmentedIsobmff(){return this._options.fastStart===`fragmented`}},lv=class extends cv{constructor(e){super(e)}get _name(){return`MP4`}get fileExtension(){return`.mp4`}get mimeType(){return`video/mp4`}getSupportedCodecs(){return[...F_,...L_,`pcm-s16`,`pcm-s16be`,`pcm-s24`,`pcm-s24be`,`pcm-s32`,`pcm-s32be`,`pcm-f32`,`pcm-f32be`,`pcm-f64`,`pcm-f64be`,...z_]}_codecUnsupportedHint(e){return new dv().getSupportedCodecs().includes(e)?` Switching to MOV will grant support for this codec.`:``}},uv=class extends cv{constructor(e){super(e)}get _name(){return`CMAF`}get fileExtension(){return`.m4s`}get mimeType(){return`video/mp4`}getSupportedCodecs(){return[...F_,...L_,`pcm-s16`,`pcm-s16be`,`pcm-s24`,`pcm-s24be`,`pcm-s32`,`pcm-s32be`,`pcm-f32`,`pcm-f32be`,`pcm-f64`,`pcm-f64be`,...z_]}},dv=class extends cv{constructor(e){super(e)}get _name(){return`MOV`}get fileExtension(){return`.mov`}get mimeType(){return`video/quicktime`}getSupportedCodecs(){return[...F_,...R_]}_codecUnsupportedHint(e){return new lv().getSupportedCodecs().includes(e)?` Switching to MP4 will grant support for this codec.`:``}},fv=[`video`,`audio`,`subtitle`],pv=class e{constructor(e,t,n,r,i){this.id=e,this.output=t,this.type=n,this.source=r,this.metadata=i}isVideoTrack(){return this.type===`video`}isAudioTrack(){return this.type===`audio`}isSubtitleTrack(){return this.type===`subtitle`}canBePairedWith(t){if(!(t instanceof e))throw TypeError(`other must be an OutputTrack.`);if(this===t)return!1;let n=Qh(this.metadata.group),r=Qh(t.metadata.group);for(let e of n)if(this.type!==t.type&&r.some(t=>e===t)||r.some(t=>e._pairedGroups.has(t)))return!0;return!1}},mv=class extends pv{constructor(e,t,n,r){super(e,t,`video`,n,r)}},hv=class extends pv{constructor(e,t,n,r){super(e,t,`audio`,n,r)}},gv=class extends pv{constructor(e,t,n,r){super(e,t,`subtitle`,n,r)}},_v=class e{constructor(){this._pairedGroups=new Set}pairWith(t){if(!(t instanceof e))throw TypeError(`other must be an OutputTrackGroup.`);if(this===t)throw TypeError(`Cannot pair a group with itself.`);this._pairedGroups.add(t),t._pairedGroups.add(this)}},vv=e=>{if(!e||typeof e!=`object`)throw TypeError(`metadata must be an object.`);if(e.languageCode!==void 0&&!Wh(e.languageCode))throw TypeError(`metadata.languageCode, when provided, must be a three-letter, ISO 639-2/T language code.`);if(e.name!==void 0&&typeof e.name!=`string`)throw TypeError(`metadata.name, when provided, must be a string.`);if(e.disposition!==void 0&&og(e.disposition),e.maximumPacketCount!==void 0&&(!Number.isInteger(e.maximumPacketCount)||e.maximumPacketCount<0))throw TypeError(`metadata.maximumPacketCount, when provided, must be a non-negative integer.`);if(e.bitrate!==void 0&&(!Number.isFinite(e.bitrate)||e.bitrate<0))throw TypeError(`metadata.bitrate, when provided, must be a non-negative number.`);if(e.averageBitrate!==void 0&&(!Number.isFinite(e.averageBitrate)||e.averageBitrate<0))throw TypeError(`metadata.averageBitrate, when provided, must be a non-negative number.`);if(e.group!==void 0&&!(e.group instanceof _v)&&(!Array.isArray(e.group)||e.group.some(e=>!(e instanceof _v))))throw TypeError(`metadata.group, when provided, must be an OutputTrackGroup instance or an array of OutputTrackGroup instances.`)},yv=class extends $h{get target(){let e=`Output.target cannot be used when using PathedTarget with an async callback. Use the 'target' event instead.`;if(this._rootTargetPromise)throw TypeError(e);let t=this._getRootTarget();if(Jh(t))throw t.catch(()=>{}),TypeError(e);return t}constructor(e){if(super(),this.state=`pending`,this.defaultTrackGroup=new _v,this.tracks=[],this._onFinalize=null,this._unfinalizedTargets=new Set,this._targetsClosed=!1,this._rootWriterPromise=null,this._startPromise=null,this._cancelPromise=null,this._canceled=zh(),this._finalizePromise=null,this._mutex=new Rh,this._metadataTags={},this._rootTarget=null,this._rootTargetPromise=null,this._firstMediaStreamTimestamp=null,!e||typeof e!=`object`)throw TypeError(`options must be an object.`);if(!(e.format instanceof sv))throw TypeError(`options.format must be an OutputFormat.`);if(!(e.target instanceof X0||e.target instanceof tv))throw TypeError(`options.target must be a Target or a PathedTarget.`);if(e.target instanceof X0&&this._rememberTarget(e.target),e.initTarget!==void 0&&!(e.initTarget instanceof X0)&&typeof e.initTarget!=`function`)throw Error(`options.initTarget, when provided, must be a Target or a function that returns or resolves to a Target.`);if(e.onFinalize!==void 0&&typeof e.onFinalize!=`function`)throw TypeError(`options.onFinalize, when provided, must be a function.`);this.format=e.format,this._target=e.target,this._onFinalize=e.onFinalize??null,this._initTarget=e.initTarget??null,this._initTarget instanceof X0&&this._rememberTarget(this._initTarget),this._muxer=e.format._createMuxer(this)}_getTargetValidated(e){W(this._target instanceof tv);let t=this._target.getTarget(e),n=e=>{if(!(e instanceof X0))throw TypeError(`getTarget must return a Target.`);return e};return Jh(t)?t.then(n):n(t)}async _getTarget(e){W(this._target instanceof tv);let t=await this._getTargetValidated(e);if(this._emit(`target`,{target:t,request:e,isRoot:e.isRoot}),this._targetsClosed)throw await t._close(),Error(this.state===`canceled`?`Output has been canceled.`:`Output has already been finalized.`);return this._rememberTarget(t),t}_rememberTarget(e){this._unfinalizedTargets.add(e),e.on(`finalized`,()=>this._unfinalizedTargets.delete(e),{once:!0})}async _getInitTarget(){if(W(this._initTarget!==null),this._initTarget instanceof X0)return this._initTarget;let e=await this._initTarget();if(!(e instanceof X0))throw TypeError(`initTarget must return or resolve to a Target.`);return this._targetsClosed?await e._close():this._rememberTarget(e),e}_hasInitTarget(){return this._initTarget!==null}_getRootTarget(){if(this._rootTarget)return this._rootTarget;if(this._rootTargetPromise)return this._rootTargetPromise;if(this._target instanceof X0)return this._emit(`target`,{target:this._target,request:null,isRoot:!0}),this._rootTarget=this._target,this._target;let e={path:this._target.rootPath,isRoot:!0,mimeType:this.format.mimeType},t=this._getTargetValidated(e),n=t=>(this._targetsClosed?t._close().catch(()=>{}):this._rememberTarget(t),this._emit(`target`,{target:t,request:e,isRoot:!0}),this._rootTarget=t,t);return Jh(t)?this._rootTargetPromise=t.then(n):n(t)}_getRootWriter(e){return this._rootWriterPromise??=(async()=>{let t=await this._getRootTarget(),n=new Y0(t,typeof e==`boolean`?e:e(t));return n.start(),n})()}addVideoTrack(e,t={}){if(!(e instanceof k_))throw TypeError(`source must be a VideoSource.`);if(vv(t),t.rotation!==void 0&&![0,90,180,270].includes(t.rotation))throw TypeError(`Invalid video rotation: ${t.rotation}. Has to be 0, 90, 180 or 270.`);if(t.flip!==void 0&&typeof t.flip!=`boolean`)throw TypeError(`metadata.flip, when provided, must be a boolean.`);if(t.transformationMatrix!==void 0&&(!Array.isArray(t.transformationMatrix)||t.transformationMatrix.length!==9||!t.transformationMatrix.every(e=>Number.isFinite(e))))throw TypeError(`metadata.transformationMatrix, when provided, must be an array of 9 finite numbers.`);if(t.frameRate!==void 0&&(!Number.isFinite(t.frameRate)||t.frameRate<=0))throw TypeError(`Invalid video frame rate: ${t.frameRate}. Must be a positive number.`);if(t.hasOnlyKeyPackets!==void 0&&typeof t.hasOnlyKeyPackets!=`boolean`)throw TypeError(`metadata.hasOnlyKeyPackets, when provided, must be a boolean.`);if(t.canBeTransparent!==void 0&&typeof t.canBeTransparent!=`boolean`)throw TypeError(`metadata.canBeTransparent, when provided, must be a boolean.`);if(t.decoderConfig!==void 0&&e1({decoderConfig:t.decoderConfig},e._codec),t.primingPacket!==void 0){if(!(t.primingPacket instanceof y_))throw TypeError(`metadata.primingPacket, when provided, must be an EncodedPacket.`);if(t.decoderConfig===void 0)throw TypeError(`metadata.primingPacket can only be provided alongside metadata.decoderConfig.`)}let n={...t};return n.group??=this.defaultTrackGroup,this._addTrack(new mv(this.tracks.length+1,this,e,n))}addAudioTrack(e,t={}){if(!(e instanceof M_))throw TypeError(`source must be an AudioSource.`);if(vv(t),t.decoderConfig!==void 0&&n1({decoderConfig:t.decoderConfig},e._codec),t.primingPacket!==void 0){if(!(t.primingPacket instanceof y_))throw TypeError(`metadata.primingPacket, when provided, must be an EncodedPacket.`);if(t.decoderConfig===void 0)throw TypeError(`metadata.primingPacket can only be provided alongside metadata.decoderConfig.`)}let n={...t};return n.group??=this.defaultTrackGroup,this._addTrack(new hv(this.tracks.length+1,this,e,n))}addSubtitleTrack(e,t={}){if(!(e instanceof P_))throw TypeError(`source must be a SubtitleSource.`);vv(t);let n={...t};return n.group??=this.defaultTrackGroup,this._addTrack(new gv(this.tracks.length+1,this,e,n))}setMetadataTags(e){if(ag(e),this.state!==`pending`)throw Error(`Cannot set metadata tags after output has been started or canceled.`);this._metadataTags=e}_addTrack(e){if(this.state!==`pending`)throw Error(`Cannot add track after output has been started or canceled.`);if(e.source._connectedTrack)throw Error(`Source is already used for a track.`);let t=this.format.getSupportedTrackCounts(),n=this.tracks.reduce((t,n)=>t+ +(n.type===e.type),0),r=t[e.type].max;if(n===r)throw Error(r===0?`${this.format._name} does not support ${e.type} tracks.`:`${this.format._name} does not support more than ${r} ${e.type} track${r===1?``:`s`}.`);let i=t.total.max;if(this.tracks.length===i)throw Error(`${this.format._name} does not support more than ${i} track${i===1?``:`s`} in total.`);if(e.isVideoTrack()){let t=this.format.getSupportedVideoCodecs();if(t.length===0)throw Error(`${this.format._name} does not support video tracks.`+this.format._codecUnsupportedHint(e.source._codec));if(!t.includes(e.source._codec))throw Error(`Codec '${e.source._codec}' cannot be contained within ${this.format._name}. Supported video codecs are: ${t.map(e=>`'${e}'`).join(`, `)}.`+this.format._codecUnsupportedHint(e.source._codec))}else if(e.isAudioTrack()){let t=this.format.getSupportedAudioCodecs();if(t.length===0)throw Error(`${this.format._name} does not support audio tracks.`+this.format._codecUnsupportedHint(e.source._codec));if(!t.includes(e.source._codec))throw Error(`Codec '${e.source._codec}' cannot be contained within ${this.format._name}. Supported audio codecs are: ${t.map(e=>`'${e}'`).join(`, `)}.`+this.format._codecUnsupportedHint(e.source._codec))}else if(e.isSubtitleTrack()){let t=this.format.getSupportedSubtitleCodecs();if(t.length===0)throw Error(`${this.format._name} does not support subtitle tracks.`+this.format._codecUnsupportedHint(e.source._codec));if(!t.includes(e.source._codec))throw Error(`Codec '${e.source._codec}' cannot be contained within ${this.format._name}. Supported subtitle codecs are: ${t.map(e=>`'${e}'`).join(`, `)}.`+this.format._codecUnsupportedHint(e.source._codec))}return this.tracks.push(e),e.source._connectedTrack=e,e}hasEnoughTracks(){let e=this.format.getSupportedTrackCounts();for(let t of fv)if(this.tracks.reduce((e,n)=>e+ +(n.type===t),0)<e[t].min)return!1;let t=e.total.min;return!(this.tracks.length<t)}async start(){let e=this.format.getSupportedTrackCounts();for(let t of fv){let n=this.tracks.reduce((e,n)=>e+ +(n.type===t),0),r=e[t].min;if(n<r)throw Error(r===e[t].max?`${this.format._name} requires exactly ${r} ${t} track${r===1?``:`s`}.`:`${this.format._name} requires at least ${r} ${t} track${r===1?``:`s`}.`)}let t=e.total.min;if(this.tracks.length<t)throw Error(t===e.total.max?`${this.format._name} requires exactly ${t} track${t===1?``:`s`}.`:`${this.format._name} requires at least ${t} track${t===1?``:`s`}.`);if(this._cancelPromise||this.state===`canceled`)throw Error(`Output has been canceled.`);return this._startPromise?(ng._warn(`Output has already been started.`),this._startPromise):this._startPromise=(async()=>{this.state=`started`;let e=this._mutex.acquire();try{try{await this._muxer.start();let e=this.tracks.map(e=>e.source._start());await Promise.all(e)}finally{(await e)()}}catch(e){throw await this.cancel(),e}})()}getMimeType(){return Promise.race([this._muxer.getMimeType(),this._canceled.promise.then(()=>{throw Error(`Output has been canceled.`)})])}async cancel(){if(this._cancelPromise||this.state===`canceled`)return this._cancelPromise??void 0;if(this.state===`finalized`)ng._warn(`Output has already been finalized.`);else return this._finalizePromise?this._finalizePromise.catch(()=>{}):this._cancelPromise=(async()=>{let e=await this._mutex.acquire();try{this.state=`canceled`,this._canceled.resolve();let e=this.tracks.map(e=>e.source._flushOrWaitForOngoingClose(!0).catch(()=>{}));await Promise.all(e),this._targetsClosed=!0,await Promise.all([...this._unfinalizedTargets].map(e=>e._close().catch(()=>{}))),this._unfinalizedTargets.clear()}finally{e()}})()}async finalize(){if(this.state===`pending`)throw Error(`Cannot finalize before starting.`);if(this._cancelPromise||this.state===`canceled`)throw Error(`Cannot finalize after canceling.`);return this._finalizePromise?(ng._warn(`Output has already been finalized.`),this._finalizePromise):this._finalizePromise=(async()=>{let e=await this._mutex.acquire();try{this.state=`finalizing`;let e=this.tracks.map(e=>e.source._flushOrWaitForOngoingClose(!1));if(await Promise.all(e),await this._muxer.finalize(),this._rootWriterPromise){let e=await this._rootWriterPromise;e.finalized||(await e.flush(),await e.finalize())}this._onFinalize&&await this._onFinalize(),this.state=`finalized`}catch(e){throw this.state=`canceled`,this._canceled.resolve(),e}finally{this._targetsClosed=!0,await Promise.all([...this._unfinalizedTargets].map(e=>e._close().catch(()=>{}))),this._unfinalizedTargets.clear(),e()}})()}},bv=Symbol.for(`mediabunny loaded`);globalThis[bv]&&ng._error(`[WARNING]
|
|
556
|
+
Mediabunny was loaded twice. This will likely cause Mediabunny not to work correctly. Check if multiple dependencies are importing different versions of Mediabunny, or if something is being bundled incorrectly.`),globalThis[bv]=!0;var xv=class{output=null;videoSource=null;audioSource=null;hasAudio;target=null;config;audioCodec;constructor(e,t=!1,n=`aac`){this.config=e,this.hasAudio=t,this.audioCodec=n}async initialize(){this.target=new $0,this.output=new yv({format:new lv({fastStart:`in-memory`}),target:this.target}),this.videoSource=new j_(`avc`),this.output.addVideoTrack(this.videoSource,{frameRate:this.config.frameRate}),this.hasAudio&&(this.audioSource=new N_(this.audioCodec),this.output.addAudioTrack(this.audioSource)),await this.output.start()}async addVideoChunk(e,t){if(!this.videoSource)throw Error(`Muxer not initialized`);let n=y_.fromEncodedChunk(e);await this.videoSource.add(n,t)}async addAudioChunk(e,t){if(!this.audioSource)throw Error(`Audio not configured for this muxer`);let n=y_.fromEncodedChunk(e);await this.audioSource.add(n,t)}async finalize(){if(!this.output||!this.target)throw Error(`Muxer not initialized`);await this.output.finalize();let e=this.target.buffer;if(!e)throw Error(`Failed to finalize output`);return new Blob([e],{type:`video/mp4`})}},Sv=128e3,Cv=20,wv=1e-4,Tv=5e3,Ev=[{encoderCodec:`mp4a.40.2`,muxerCodec:`aac`,label:`AAC`},{encoderCodec:`opus`,muxerCodec:`opus`,label:`Opus`}];function Dv(e,t){let n=0;for(let r of e)n+=r[t]??0;return n/Math.max(1,e.length)}function Ov(e,t,n){let r=0,i=0;for(let[a,o]of n){let n=e[a]?.[t];typeof n==`number`&&(r+=n*o,i+=o)}return i>0?r/i:Dv(e,t)}function kv(e){let t=Math.SQRT1_2,n=Math.SQRT1_2,r=.5;return e>=8?{left:[[0,1],[2,t],[3,r],[4,n],[6,n]],right:[[1,1],[2,t],[3,r],[5,n],[7,n]]}:e>=6?{left:[[0,1],[2,t],[3,r],[4,n]],right:[[1,1],[2,t],[3,r],[5,n]]}:e>=4?{left:[[0,1],[2,n]],right:[[1,1],[3,n]]}:{left:[[0,1],[2,t]],right:[[1,1],[2,t]]}}function Av(e,t){let n=e[0]?.length??0,r=new Float32Array(n*t);if(t===1){for(let t=0;t<n;t++)r[t]=Dv(e,t);return r}if(t!==2)throw Error(`Unsupported target channel count: ${t}`);if(e.length===1)return r.set(e[0],0),r.set(e[0],n),r;if(e.length===2)return r.set(e[0],0),r.set(e[1],n),r;let i=kv(e.length);for(let t=0;t<n;t++)r[t]=Ov(e,t,i.left),r[n+t]=Ov(e,t,i.right);return r}var jv=class e{cancelled=!1;static async selectSupportedExportCodec(e,t){let n=[t];t>2&&n.push(2),n.includes(1)||n.push(1);for(let t of Ev)for(let r of n)if((await AudioEncoder.isConfigSupported({codec:t.encoderCodec,sampleRate:e,numberOfChannels:r,bitrate:Sv})).supported)return{...t,sampleRate:e,numberOfChannels:r};return null}static async selectSupportedExportCodecForSource(t){let n;try{n=await t.getDecoderConfig(`audio`)}catch{return null}return(await AudioDecoder.isConfigSupported(n)).supported?e.selectSupportedExportCodec(n.sampleRate||48e3,n.numberOfChannels||2):(console.warn(`[AudioProcessor] Audio codec not supported:`,n.codec),null)}async process(e,t,n,r,i,a,o){let s=r?[...r].sort((e,t)=>e.startMs-t.startMs):[],c=i?[...i].filter(e=>e.endMs-e.startMs>wv).sort((e,t)=>e.startMs-t.startMs):[];if(c.length>0){let e=await this.renderPitchPreservedTimelineAudio(n,s,c,a);if(!this.cancelled&&e.size>0){await this.muxRenderedAudioBlob(e,t,o);return}return}let l=a+.5;await this.processTrimOnlyAudio(e,t,s,l,o)}async processTrimOnlyAudio(t,n,r,i,a){let o;try{o=await t.getDecoderConfig(`audio`)}catch{console.warn(`[AudioProcessor] No audio track found, skipping`);return}if(!(await AudioDecoder.isConfigSupported(o)).supported){console.warn(`[AudioProcessor] Audio codec not supported:`,o.codec);return}let s=[],c=new AudioDecoder({output:e=>s.push(e),error:e=>console.error(`[AudioProcessor] Decode error:`,e)});c.configure(o);let l=typeof i==`number`&&Number.isFinite(i)?Math.max(0,i):void 0,u=(l===void 0?t.read(`audio`):t.read(`audio`,0,l)).getReader();try{for(;!this.cancelled;){let{done:e,value:t}=await u.read();if(e||!t)break;let n=t.timestamp/1e3;if(!this.isInTrimRegion(n,r))for(c.decode(t);c.decodeQueueSize>Cv&&!this.cancelled;)await new Promise(e=>setTimeout(e,1))}}finally{try{await u.cancel()}catch{}}if(c.state===`configured`&&(await c.flush(),c.close()),this.cancelled||s.length===0){for(let e of s)e.close();return}let d=[],f=new AudioEncoder({output:(e,t)=>{d.push({chunk:e,meta:t})},error:e=>console.error(`[AudioProcessor] Encode error:`,e)}),p=o.sampleRate||48e3,m=o.numberOfChannels||2,h=a??await e.selectSupportedExportCodec(p,m);if(!h){console.warn(`[AudioProcessor] No supported audio export codec, skipping audio`);for(let e of s)e.close();return}let g=h.sampleRate||p,_=h.numberOfChannels||m,v={codec:h.encoderCodec,sampleRate:g,numberOfChannels:_,bitrate:Sv};if((await AudioEncoder.isConfigSupported(v)).supported){f.configure(v);for(let e of s){if(this.cancelled){e.close();continue}let t=e.timestamp/1e3,n=this.computeTrimOffset(t,r),i=e.timestamp-n*1e3,a=this.cloneForEncoding(e,Math.max(0,i),_);e.close(),f.encode(a),a.close()}f.state===`configured`&&(await f.flush(),f.close());for(let{chunk:e,meta:t}of d){if(this.cancelled)break;await n.addAudioChunk(e,t)}console.log(`[AudioProcessor] Processed ${s.length} audio frames, encoded ${d.length} chunks`)}else{console.warn(`[AudioProcessor] ${h.label} encoding not supported, skipping audio`);for(let e of s)e.close()}}async renderPitchPreservedTimelineAudio(e,t,n,r){let i=document.createElement(`audio`);i.src=e,i.preload=`auto`;let a=i;if(a.preservesPitch=!0,a.mozPreservesPitch=!0,a.webkitPreservesPitch=!0,await this.waitForLoadedMetadata(i),this.cancelled)throw Error(`Export cancelled`);let o=new AudioContext,s=o.createMediaElementSource(i),c=o.createMediaStreamDestination();s.connect(c);let l=null,u=null,d=null;try{o.state===`suspended`&&await o.resume();let e=r,a=0;for(let n=0;n<=t.length;n++){let n=this.findActiveTrimRegion(a*1e3,t);if(!n||(a=n.endMs/1e3,a>=e))break}if(a>=e)return new Blob([],{type:`audio/webm`});await this.seekTo(i,a);let s=this.findActiveSpeedRegion(a*1e3,n);s&&(i.playbackRate=s.speed);let f=this.startAudioRecording(c.stream);u=f.recorder,d=f.recordedBlobPromise,await i.play(),await new Promise((e,a)=>{let o=()=>{l!==null&&(cancelAnimationFrame(l),l=null),i.removeEventListener(`error`,s),i.removeEventListener(`ended`,c)},s=()=>{o(),a(Error(`Failed while rendering speed-adjusted audio timeline`))},c=()=>{o(),e()},d=()=>{if(this.cancelled){o(),e();return}if(i.currentTime>=r){i.pause(),o(),e();return}let s=i.currentTime*1e3,c=this.findActiveTrimRegion(s,t);if(c&&!i.paused&&!i.ended){let t=c.endMs/1e3;if(t>=i.duration||t>=r){i.pause(),o(),e();return}i.pause(),u?.state===`recording`&&u.pause();let n=()=>{clearTimeout(s),this.cancelled?(o(),e()):(u?.state===`paused`&&u.resume(),i.play().then(()=>{this.cancelled||(l=requestAnimationFrame(d))}).catch(e=>{o(),a(Error(`Failed to resume playback after trim seek: ${e instanceof Error?e.message:String(e)}`))}))},s=window.setTimeout(()=>{i.removeEventListener(`seeked`,n),o(),a(Error(`Audio seek timed out while skipping trim region`))},Tv);i.addEventListener(`seeked`,n,{once:!0}),i.currentTime=t;return}let f=this.findActiveSpeedRegion(s,n),p=f?f.speed:1;Math.abs(i.playbackRate-p)>1e-4&&(i.playbackRate=p),!i.paused&&!i.ended?l=requestAnimationFrame(d):(o(),e())};i.addEventListener(`error`,s,{once:!0}),i.addEventListener(`ended`,c,{once:!0}),l=requestAnimationFrame(d)})}finally{l!==null&&cancelAnimationFrame(l),i.pause(),u&&u.state!==`inactive`&&u.stop(),c.stream.getTracks().forEach(e=>e.stop()),s.disconnect(),c.disconnect(),await o.close(),i.src=``,i.load()}if(!d)throw Error(`Audio recorder finished without assigning recordedBlobPromise`);let f=await d;if(this.cancelled)throw Error(`Export cancelled`);return f}async muxRenderedAudioBlob(e,t,n){if(this.cancelled)return;let r=new File([e],`speed-audio.webm`,{type:e.type||`audio/webm`}),i=new Xm({wasmFilePath:new URL(`./wasm/web-demuxer.wasm`,window.location.href).href});try{await i.load(r),await this.processTrimOnlyAudio(i,t,[],void 0,n)}finally{try{i.destroy()}catch{}}}startAudioRecording(e){let t=this.getSupportedAudioMimeType(),n={audioBitsPerSecond:Sv,...t?{mimeType:t}:{}},r=new MediaRecorder(e,n),i=[],a=new Promise((e,n)=>{r.ondataavailable=e=>{e.data&&e.data.size>0&&i.push(e.data)},r.onerror=()=>{n(Error(`MediaRecorder failed while capturing speed-adjusted audio`))},r.onstop=()=>{let n=t||i[0]?.type||`audio/webm`;e(new Blob(i,{type:n}))}});return r.start(),{recorder:r,recordedBlobPromise:a}}getSupportedAudioMimeType(){for(let e of[`audio/webm;codecs=opus`,`audio/webm`])if(MediaRecorder.isTypeSupported(e))return e}waitForLoadedMetadata(e){return Number.isFinite(e.duration)&&e.readyState>=HTMLMediaElement.HAVE_METADATA?Promise.resolve():new Promise((t,n)=>{let r=()=>{a(),t()},i=()=>{a(),n(Error(`Failed to load media metadata for speed-adjusted audio`))},a=()=>{e.removeEventListener(`loadedmetadata`,r),e.removeEventListener(`error`,i)};e.addEventListener(`loadedmetadata`,r),e.addEventListener(`error`,i,{once:!0})})}seekTo(e,t){return Math.abs(e.currentTime-t)<1e-4?Promise.resolve():new Promise((n,r)=>{let i=()=>{o(),n()},a=()=>{o(),r(Error(`Failed to seek media for speed-adjusted audio`))},o=()=>{e.removeEventListener(`seeked`,i),e.removeEventListener(`error`,a)};e.addEventListener(`seeked`,i,{once:!0}),e.addEventListener(`error`,a,{once:!0}),e.currentTime=t})}findActiveTrimRegion(e,t){return t.find(t=>e>=t.startMs&&e<t.endMs)||null}findActiveSpeedRegion(e,t){return t.find(t=>e>=t.startMs&&e<t.endMs)||null}cloneForEncoding(e,t,n){if(n!==e.numberOfChannels)return this.downmixWithTimestamp(e,t,n);if(!e.format)throw Error(`AudioData format is required for cloning`);let r=e.format.includes(`planar`)?e.numberOfChannels:1,i=0;for(let t=0;t<r;t++)i+=e.allocationSize({planeIndex:t});let a=new ArrayBuffer(i),o=0;for(let t=0;t<r;t++){let n=e.allocationSize({planeIndex:t});e.copyTo(new Uint8Array(a,o,n),{planeIndex:t}),o+=n}return new AudioData({format:e.format,sampleRate:e.sampleRate,numberOfFrames:e.numberOfFrames,numberOfChannels:e.numberOfChannels,timestamp:t,data:a})}downmixWithTimestamp(e,t,n){let r=e.numberOfChannels,i=e.numberOfFrames;if(n<1||n>2)throw Error(`Unsupported target channel count: ${n}`);let a=Array.from({length:r},()=>new Float32Array(i));for(let t=0;t<r;t++)e.copyTo(a[t],{format:`f32-planar`,planeIndex:t});let o=Av(a,n);return new AudioData({format:`f32-planar`,sampleRate:e.sampleRate,numberOfFrames:i,numberOfChannels:n,timestamp:t,data:o.buffer instanceof ArrayBuffer?o.buffer:o.slice().buffer})}isInTrimRegion(e,t){return t.some(t=>e>=t.startMs&&e<t.endMs)}computeTrimOffset(e,t){let n=0;for(let r of t)r.endMs<=e&&(n+=r.endMs-r.startMs);return n}cancel(){this.cancelled=!0}},Mv=15e3,Nv=2e4,Pv=1e-4;function Fv(e){return!!e?.some(e=>e.endMs-e.startMs>Pv)}function Iv(e){return!!e?.some(e=>e.endMs-e.startMs>Pv&&Math.abs(e.speed-1)>Pv)}function Lv(e){return(e.cursorScale??0)>0}function Rv(e){return Math.abs(e.x)<=Pv&&Math.abs(e.y)<=Pv&&Math.abs(e.width-1)<=Pv&&Math.abs(e.height-1)<=Pv}function zv(e,t){let n=[];return(e.width!==t.width||e.height!==t.height)&&n.push(`output-size ${e.width}x${e.height} differs from source ${t.width}x${t.height}`),e.webcamVideoUrl&&n.push(`webcam overlay is enabled`),Fv(e.trimRegions)&&n.push(`trim regions are present`),Iv(e.speedRegions)&&n.push(`speed regions are present`),Fv(e.zoomRegions)&&n.push(`zoom regions are present`),Fv(e.annotationRegions)&&n.push(`annotation regions are present`),Lv(e)&&n.push(`editable cursor overlay is enabled`),Rv(e.cropRegion)||n.push(`crop is not default`),(e.padding??0)>Pv&&n.push(`padding is not zero`),(e.videoPadding??0)>Pv&&n.push(`video padding is not zero`),(e.borderRadius??0)>Pv&&n.push(`roundness is not zero`),(e.showShadow||e.shadowIntensity>Pv)&&n.push(`shadow is enabled`),e.showBlur&&n.push(`background blur is enabled`),(e.motionBlurAmount??0)>Pv&&n.push(`motion blur is enabled`),n}function Bv(e,t){if(t.type.toLowerCase().includes(`mp4`))return!0;try{return new URL(e,window.location.href).pathname.toLowerCase().endsWith(`.mp4`)}catch{return e.toLowerCase().split(/[?#]/,1)[0].endsWith(`.mp4`)}}var Vv=class{config;streamingDecoder=null;renderer=null;encoder=null;muxer=null;audioProcessor=null;webcamDecoder=null;cancelled=!1;encodeQueue=0;MAX_ENCODE_QUEUE=120;videoDescription;videoColorSpace;muxingPromises=[];chunkCount=0;lastEncoderOutputAt=0;fatalEncoderError=null;constructor(e){this.config=e}async export(){let e=this.getEncoderPreferences(),t=null;for(let n of e)try{return await this.exportWithEncoderPreference(n)}catch(r){let i=r instanceof Error?r:Error(String(r));if(t=i,this.cancelled)return{success:!1,error:`Export cancelled`};if(i instanceof Fe)throw i;e.length>1&&console.warn(`[VideoExporter] ${n} export attempt failed:`,i)}finally{this.cleanup()}return{success:!1,error:t?.message||`Export failed`}}async exportWithEncoderPreference(e){let t=null,n=!1,r=null,i=null,a=null,o=[],s=e=>o.push(e);this.cleanup(),this.cancelled=!1,this.fatalEncoderError=null;try{let c=await Pm(),l=new sh;this.streamingDecoder=l;let u=await l.loadMetadata(this.config.videoUrl),d=await this.trySourceCopyFastPath(u);if(d)return d;let f=null;this.config.webcamVideoUrl&&(a=new sh,this.webcamDecoder=a,f=await a.loadMetadata(this.config.webcamVideoUrl));let p=new Mm({width:this.config.width,height:this.config.height,wallpaper:this.config.wallpaper,zoomRegions:this.config.zoomRegions,showShadow:this.config.showShadow,shadowIntensity:this.config.shadowIntensity,showBlur:this.config.showBlur,motionBlurAmount:this.config.motionBlurAmount,borderRadius:this.config.borderRadius,padding:this.config.padding,cropRegion:this.config.cropRegion,cursorRecordingData:this.config.cursorRecordingData,cursorScale:this.config.cursorScale,cursorSmoothing:this.config.cursorSmoothing,cursorMotionBlur:this.config.cursorMotionBlur,cursorClickBounce:this.config.cursorClickBounce,cursorClipToBounds:this.config.cursorClipToBounds,cursorTheme:this.config.cursorTheme,videoWidth:u.width,videoHeight:u.height,webcamSize:f?{width:f.width,height:f.height}:null,webcamLayoutPreset:this.config.webcamLayoutPreset,webcamMaskShape:this.config.webcamMaskShape,webcamMirrored:this.config.webcamMirrored,webcamReactiveZoom:this.config.webcamReactiveZoom,webcamSizePreset:this.config.webcamSizePreset,webcamPosition:this.config.webcamPosition,annotationRegions:this.config.annotationRegions,speedRegions:this.config.speedRegions,previewWidth:this.config.previewWidth,previewHeight:this.config.previewHeight,cursorTelemetry:this.config.cursorTelemetry,cursorClickTimestamps:this.config.cursorClickTimestamps,platform:c});this.renderer=p,await p.initialize(),await this.initializeEncoder(e);let m=l.getDemuxer(),h=u.hasAudio&&m?await jv.selectSupportedExportCodecForSource(m):null;u.hasAudio&&!h&&console.warn(`[VideoExporter] No supported audio export codec, exporting video-only.`);let g=!!h,_=new xv(this.config,g,h?.muxerCodec);this.muxer=_,await _.initialize();let{totalFrames:v}=l.getExportMetrics(this.config.frameRate,this.config.trimRegions,this.config.speedRegions),y=1e6/this.config.frameRate,b=0,x=e===`prefer-software`?Math.min(this.MAX_ENCODE_QUEUE,32):this.MAX_ENCODE_QUEUE;if(t=this.config.webcamVideoUrl?new lh:null,i=a&&t?(()=>{let e=t;return a.decodeAll(this.config.frameRate,this.config.trimRegions,this.config.speedRegions,async(t,r,i)=>{for(;e.length>=12&&!this.cancelled&&!n;)await new Promise(e=>setTimeout(e,2));this.cancelled||n?t.close():e.enqueue(t,i)},s).catch(e=>{throw r=e instanceof Error?e:Error(String(e)),r}).finally(()=>{r?e.fail(r):e.close()})})():null,await l.decodeAll(this.config.frameRate,this.config.trimRegions,this.config.speedRegions,async(n,r,i)=>{let a=null;try{if(this.cancelled)return;if(this.fatalEncoderError)throw this.fatalEncoderError;let r=b*y;if(a=t?await t.frameAt(i):null,this.cancelled)return;let o=i*1e3;await p.renderFrame(n,o,a);let s=p.getCanvas(),l;if(c===`linux`){let e=s.getContext(`2d`).getImageData(0,0,s.width,s.height);l=new VideoFrame(e.data.buffer,{format:`RGBA`,codedWidth:s.width,codedHeight:s.height,timestamp:r,duration:y,colorSpace:{primaries:`bt709`,transfer:`iec61966-2-1`,matrix:`rgb`,fullRange:!0}})}else l=new VideoFrame(s,{timestamp:r,duration:y});for(;this.encoder&&this.encoder.encodeQueueSize>=x&&!this.cancelled;){if(Date.now()-this.lastEncoderOutputAt>Mv)throw l.close(),Error(e===`prefer-hardware`?`The hardware video encoder stopped responding. Retrying with a safer encoder.`:`The video encoder stopped responding during export.`);await new Promise(e=>setTimeout(e,5))}this.encoder&&this.encoder.state===`configured`?(this.encodeQueue++,this.encoder.encode(l,{keyFrame:b%150==0})):console.warn(`[Frame ${b}] Encoder not ready! State: ${this.encoder?.state}`),l.close(),b++,this.reportProgress({currentFrame:b,totalFrames:v,percentage:b/v*100,estimatedTimeRemaining:0})}finally{n.close(),a?.close()}},s),this.cancelled)return{success:!1,error:`Export cancelled`};if(this.fatalEncoderError||(n=!0,t?.destroy(),a?.cancel(),await i,this.encoder&&this.encoder.state===`configured`&&await this.withTimeout(this.encoder.flush(),Nv,e===`prefer-hardware`?`The hardware video encoder stopped responding while finalizing the export.`:`The video encoder stopped responding while finalizing the export.`),this.fatalEncoderError))throw this.fatalEncoderError;if(await Promise.all(this.muxingPromises),this.reportProgress({currentFrame:v,totalFrames:v,percentage:100,estimatedTimeRemaining:0,phase:`finalizing`}),g&&h&&!this.cancelled){let e=l.getDemuxer();e&&(console.log(`[VideoExporter] Processing audio track...`),this.audioProcessor=new jv,await this.audioProcessor.process(e,_,this.config.videoUrl,this.config.trimRegions,this.config.speedRegions,u.duration,h))}return{success:!0,blob:await _.finalize(),warnings:o.length>0?o:void 0}}finally{n=!0,t?.destroy(),a?.cancel(),i&&await i.catch(()=>void 0)}}async initializeEncoder(e){this.encodeQueue=0,this.muxingPromises=[],this.chunkCount=0,this.lastEncoderOutputAt=Date.now(),this.fatalEncoderError=null;let t;this.encoder=new VideoEncoder({output:(e,n)=>{if(this.lastEncoderOutputAt=Date.now(),n?.decoderConfig?.description&&!t){let e=n.decoderConfig.description;e instanceof ArrayBuffer||e instanceof SharedArrayBuffer?t=new Uint8Array(e):ArrayBuffer.isView(e)&&(t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength)),this.videoDescription=t}n?.decoderConfig?.colorSpace&&!this.videoColorSpace&&(this.videoColorSpace=n.decoderConfig.colorSpace);let r=this.chunkCount===0;this.chunkCount++;let i=(async()=>{try{if(r&&this.videoDescription){let t=this.videoColorSpace||{primaries:`bt709`,transfer:`iec61966-2-1`,matrix:`rgb`,fullRange:!0},n={decoderConfig:{codec:this.config.codec||`avc1.640033`,codedWidth:this.config.width,codedHeight:this.config.height,description:this.videoDescription,colorSpace:t}};await this.muxer.addVideoChunk(e,n)}else await this.muxer.addVideoChunk(e,n)}catch(e){console.error(`Muxing error:`,e)}})();this.muxingPromises.push(i),this.encodeQueue=Math.max(0,this.encodeQueue-1)},error:e=>{console.error(`[VideoExporter] Encoder error:`,e),this.fatalEncoderError=e instanceof Error?e:Error(`Video encoder error: ${String(e)}`),this.streamingDecoder?.cancel(),this.webcamDecoder?.cancel()}});let n={codec:this.config.codec||`avc1.640033`,width:this.config.width,height:this.config.height,bitrate:this.config.bitrate,framerate:this.config.frameRate,latencyMode:`quality`,bitrateMode:`variable`,hardwareAcceleration:e};if(!(await VideoEncoder.isConfigSupported(n)).supported)throw Error(e===`prefer-hardware`?`Hardware video encoding is not supported on this system.`:`Software video encoding is not supported on this system.`);console.log(`[VideoExporter] Using ${e===`prefer-hardware`?`hardware`:`software`} acceleration`),this.encoder.configure(n)}cancel(){this.cancelled=!0,this.streamingDecoder&&this.streamingDecoder.cancel(),this.webcamDecoder&&this.webcamDecoder.cancel(),this.audioProcessor&&this.audioProcessor.cancel(),this.cleanup()}cleanup(){if(this.encoder){try{this.encoder.state===`configured`&&this.encoder.close()}catch(e){console.warn(`Error closing encoder:`,e)}this.encoder=null}if(this.streamingDecoder){try{this.streamingDecoder.destroy()}catch(e){console.warn(`Error destroying streaming decoder:`,e)}this.streamingDecoder=null}if(this.webcamDecoder){try{this.webcamDecoder.destroy()}catch(e){console.warn(`Error destroying webcam decoder:`,e)}this.webcamDecoder=null}if(this.renderer){try{this.renderer.destroy()}catch(e){console.warn(`Error destroying renderer:`,e)}this.renderer=null}this.audioProcessor=null,this.muxer=null,this.encodeQueue=0,this.muxingPromises=[],this.chunkCount=0,this.videoDescription=void 0,this.videoColorSpace=void 0,this.lastEncoderOutputAt=0,this.fatalEncoderError=null}getEncoderPreferences(){return typeof navigator<`u`&&/\bWindows\b/i.test(navigator.userAgent)?[`prefer-software`,`prefer-hardware`]:[`prefer-hardware`,`prefer-software`]}async trySourceCopyFastPath(e){let t=zv(this.config,e);if(t.length>0)return console.info(`[VideoExporter] source-copy fast path disabled`,{blockers:t,output:{width:this.config.width,height:this.config.height},source:e}),null;let n=await this.loadSourceBlob();return!n||!Bv(this.config.videoUrl,n)?(console.info(`[VideoExporter] source-copy fast path disabled`,{blockers:[`source is not a readable MP4`],source:e}),null):this.cancelled?{success:!1,error:`Export cancelled`}:(this.reportProgress({currentFrame:1,totalFrames:1,percentage:100,estimatedTimeRemaining:0,phase:`finalizing`}),console.info(`[VideoExporter] using source-copy fast path`,{source:e,bytes:n.size}),{success:!0,blob:n.type?n:new Blob([n],{type:`video/mp4`})})}async loadSourceBlob(){let e=this.config.videoUrl;if(!/^(https?:|blob:|data:)/i.test(e)&&window.electronAPI?.readBinaryFile){let t=await window.electronAPI.readBinaryFile(e);if(!t.success||!t.data)return null;let n=e.toLowerCase().split(/[?#]/,1)[0].endsWith(`.mp4`)?`video/mp4`:``;return new Blob([t.data],n?{type:n}:void 0)}let t=await fetch(e);return t.ok?t.blob():null}reportProgress(e){this.config.onProgress?.(e)}withTimeout(e,t,n){return new Promise((r,i)=>{let a=window.setTimeout(()=>i(Error(n)),t);e.then(e=>{window.clearTimeout(a),r(e)},e=>{window.clearTimeout(a),i(e)})})}};function Hv(e){let t=document.getElementById(`status`);t&&(t.textContent=e)}async function Uv(e){let t=document.createElement(`video`);return t.muted=!0,t.preload=`metadata`,t.src=e,await new Promise((n,r)=>{t.onloadedmetadata=()=>n(),t.onerror=()=>r(Error(`cannot load ${e}`))}),{width:t.videoWidth,height:t.videoHeight,duration:t.duration}}window.demoreel={validate(e){let t=et(e);return{valid:t,media:t?tt(e):null,normalized:t?nt(e.editor):null}},async render(e){let t=performance.now();if(!et(e.project))throw Error(`project failed OpenScreen validateProjectData()`);let n=nt(e.project.editor),r=await Uv(e.videoUrl),i=mh(r.width,r.height,n.cropRegion),a=n.aspectRatio===`native`?Be(r.width,r.height,n.cropRegion):ze(n.aspectRatio),{width:o,height:s,bitrate:c}=vh({quality:e.quality??n.exportQuality,sourceWidth:i.width,sourceHeight:i.height,aspectRatioValue:a}),l=e.cursorData,u=l?.samples??[],d=u.map(e=>({timeMs:e.timeMs,cx:e.cx,cy:e.cy,interactionType:e.interactionType})),f=u.filter(e=>e.interactionType===`click`).map(e=>e.timeMs),p=e.cursor??{},m=-1,h=await new Vv({videoUrl:e.videoUrl,width:o,height:s,frameRate:e.frameRate??30,bitrate:c,codec:`avc1.640033`,wallpaper:n.wallpaper,zoomRegions:n.zoomRegions,trimRegions:n.trimRegions,speedRegions:n.speedRegions,showShadow:n.shadowIntensity>0,shadowIntensity:n.shadowIntensity,showBlur:n.showBlur,motionBlurAmount:n.motionBlurAmount,borderRadius:n.borderRadius,padding:n.padding,cropRegion:n.cropRegion,cursorRecordingData:l,cursorScale:p.show===!1?0:p.size??3,cursorSmoothing:p.smoothing??.67,cursorMotionBlur:p.motionBlur??.35,cursorClickBounce:p.clickBounce??2.5,cursorClipToBounds:!1,cursorTheme:n.cursorTheme,annotationRegions:n.annotationRegions,webcamLayoutPreset:n.webcamLayoutPreset,webcamMaskShape:n.webcamMaskShape,webcamMirrored:n.webcamMirrored,webcamReactiveZoom:n.webcamReactiveZoom,webcamSizePreset:n.webcamSizePreset,webcamPosition:n.webcamPosition,previewWidth:e.previewWidth??1280,previewHeight:e.previewHeight??720,cursorTelemetry:d,cursorClickTimestamps:f,onProgress:e=>{let t=Math.floor(e.percentage);t!==m&&(m=t,console.log(`[demoreel] progress ${t}`)),Hv(`exporting ${t}%`)}}).export();if(!h.success||!h.blob)throw Error(h.error??`export failed`);let g=await fetch(`/__demoreel/output`,{method:`POST`,body:h.blob});if(!g.ok)throw Error(`upload failed: ${g.status}`);return{width:o,height:s,bitrate:c,bytes:h.blob.size,warnings:h.warnings??[],renderMs:Math.round(performance.now()-t),source:r}}},window.demoreelReady=!0;export{hr as $,Uo as A,ya as B,ks as C,P as Ct,es as D,at as Dt,ns as E,N as Et,Aa as F,ni as G,ra as H,ka as I,Wr as J,ei as K,Oa as L,Ha as M,Ma as N,qo as O,Ba as P,Tr as Q,Da as R,Vs as S,F as St,Cs as T,gt as Tt,Fi as U,aa as V,ai as W,Ir as X,Hr as Y,Fr as Z,Cc as _,R as _t,xl as a,Xn as at,Ks as b,I as bt,Hc as c,Gn as ct,Pc as d,z as dt,pr as et,jc as f,tn as ft,Sc as g,Vt as gt,Ac as h,Ht as ht,Sl as i,$n as it,Ka as j,Wo as k,Bc as l,Vn as lt,Dc as m,Ut as mt,id as n,ur as nt,ml as o,Jn as ot,Mc as p,Xt as pt,$r as q,Tu as r,sr as rt,al as s,Kn as st,cd as t,fr as tt,Rc as u,an as ut,xc as v,L as vt,Ts as w,bt as wt,Hs as x,Nt as xt,bc as y,Lt as yt,wa as z};
|