@gjsify/example-dom-three-geometry-teapot 0.31.0 → 0.33.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/dist/browser.js +857 -319
- package/dist/gjs.js +1 -1
- package/package.json +7 -7
package/dist/gjs.js
CHANGED
|
@@ -3,7 +3,7 @@ if(globalThis.__gjsifyBundleUrl??=import.meta.url,Symbol.dispose||(Symbol.dispos
|
|
|
3
3
|
`).slice(1).join(`
|
|
4
4
|
`)||``;this._write(`stderr`,`Trace:`,...e,`
|
|
5
5
|
`+t)}profile(e){}profileEnd(e){}timeStamp(e){}};const O=new Console,ee=__name((...e)=>O.log(...e),`log`),info=(...e)=>O.info(...e),debug=(...e)=>O.debug(...e),k=__name((...e)=>O.warn(...e),`warn`),te=__name((...e)=>O.error(...e),`error`),dir=(e,t)=>O.dir(e,t),dirxml=(...e)=>O.dirxml(...e),table=(e,t)=>O.table(e,t),clear=()=>O.clear(),assert=(e,...t)=>O.assert(e,...t),trace=(...e)=>O.trace(...e),time=e=>O.time(e),timeEnd=e=>O.timeEnd(e),timeLog=(e,...t)=>O.timeLog(e,...t),count=e=>O.count(e),countReset=e=>O.countReset(e),group=(...e)=>O.group(...e),groupCollapsed=(...e)=>O.groupCollapsed(...e),groupEnd=()=>O.groupEnd(),profile=e=>{},profileEnd=e=>{},timeStamp=e=>{},A={log:ee,info,debug,warn:k,error:te,dir,dirxml,table,time,timeEnd,timeLog,trace,assert,clear,count,countReset,group,groupCollapsed,groupEnd,profile,profileEnd,timeStamp},warnNotImplemented=e=>{let t=e?`Not implemented: ${e}`:`Not implemented`;return A.warn(t),t},j=__name(e=>{Promise.resolve().then(e)},`queueMicrotask`);function mapSysname(e){let t=e.trim();switch(t){case`Linux`:return`linux`;case`Darwin`:return`darwin`;case`FreeBSD`:return`freebsd`;case`OpenBSD`:return`openbsd`;case`NetBSD`:return`netbsd`;case`SunOS`:return`sunos`;case`AIX`:return`aix`;case`Haiku`:return`haiku`;default:return/^CYGWIN/i.test(t)?`cygwin`:/^(MINGW|MSYS|Windows)/i.test(t)?`win32`:void 0}}function mapMachine(e){let t=e.trim().toLowerCase();switch(t){case`x86_64`:case`amd64`:return`x64`;case`aarch64`:case`arm64`:return`arm64`;case`i386`:case`i486`:case`i586`:case`i686`:return`ia32`;case`ppc64le`:case`ppc64`:return`ppc64`;case`s390x`:return`s390x`;case`riscv64`:return`riscv64`;case`loongarch64`:return`loong64`;case`mipsel`:return`mipsel`;case`mips`:return`mips`;default:return t.startsWith(`arm`)?`arm`:void 0}}const{toString:ne}=Object.prototype;function classOf(e){return ne.call(e).slice(8,-1)}function throwDataCloneError(e){let t=globalThis.DOMException;if(typeof t==`function`)throw new t(e,`DataCloneError`);let n=Error(e);throw n.name=`DataCloneError`,n}const re={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError},ie=new Set([`Int8Array`,`Uint8Array`,`Uint8ClampedArray`,`Int16Array`,`Uint16Array`,`Int32Array`,`Uint32Array`,`Float32Array`,`Float64Array`,`BigInt64Array`,`BigUint64Array`]);function internalClone(e,t,n){if(e==null)return e;let r=typeof e;if(r===`boolean`||r===`number`||r===`string`||r===`bigint`)return e;r===`symbol`&&throwDataCloneError(`Symbol cannot be cloned`),r===`function`&&throwDataCloneError(`Function cannot be cloned`);let i=e;if(t.has(i))return t.get(i);let a=classOf(i);if(a===`Date`)return new Date(i.getTime());if(a===`RegExp`)return new RegExp(i.source,i.flags);if(a===`Boolean`||a===`Number`||a===`String`)return Object(i.valueOf());if(a===`BigInt`)return Object(BigInt.prototype.valueOf.call(i));if(i instanceof Error){let e=i,r=e.constructor?.name,a=new(r&&re[r]||re[e.name]||Error)(e.message);return a.name=e.name,`cause`in e&&Object.defineProperty(a,"cause",{value:internalClone(e.cause,t,n),writable:!0,enumerable:!1,configurable:!0}),a}if(a===`DOMException`){let e=globalThis.DOMException;if(typeof e==`function`){let t=i;return new e(t.message,t.name)}}if(a===`ArrayBuffer`){let e=i;if(n&&n.transferred.has(e)){let r=n.transferred.get(e);return t.set(i,r),r}(e.detached===!0||e.byteLength===0&&e.detached)&&throwDataCloneError(`ArrayBuffer is detached and cannot be cloned`);let r=e.slice(0);return t.set(i,r),r}if(a===`SharedArrayBuffer`||i&&typeof i==`object`&&i.constructor?.name===`SharedBuffer`)return i;if(a===`DataView`){let e=i,r=n?.viewSnapshots.get(i),a=internalClone(e.buffer,t,n),o=r?r.byteOffset:e.byteOffset,s=r?r.byteLength:e.byteLength,c=new DataView(a,o,s);return t.set(i,c),c}if(ie.has(a)){let e=i,r=n?.viewSnapshots.get(i),a=internalClone(e.buffer,t,n),o=e.constructor,s=new o(a,r?r.byteOffset:e.byteOffset,r?r.length:e.length);return t.set(i,s),s}if(a===`Map`){let e=new Map;t.set(i,e);for(let[r,a]of i)e.set(internalClone(r,t,n),internalClone(a,t,n));return e}if(a===`Set`){let e=new Set;t.set(i,e);for(let r of i)e.add(internalClone(r,t,n));return e}{let e=globalThis,t=e.Blob,n=e.File;if(typeof n==`function`&&i instanceof n){let e=i;return new n([i],e.name,{type:e.type,lastModified:e.lastModified})}if(typeof t==`function`&&i instanceof t)return new t([i],{type:i.type})}if(i instanceof WeakMap&&throwDataCloneError(`WeakMap cannot be cloned`),i instanceof WeakSet&&throwDataCloneError(`WeakSet cannot be cloned`),i instanceof WeakRef&&throwDataCloneError(`WeakRef cannot be cloned`),typeof globalThis.Promise==`function`&&i instanceof Promise&&throwDataCloneError(`Promise cannot be cloned`),a===`Array`){let e=i,r=[];t.set(i,r);for(let i=0;i<e.length;i++)i in e&&(r[i]=internalClone(e[i],t,n));return r}if(a===`Object`||typeof i==`object`){let e={};t.set(i,e);for(let r of Object.keys(i))e[r]=internalClone(i[r],t,n);return e}throwDataCloneError(`${a} cannot be cloned`)}function structuredClone$1(e,t){let n=t?.transfer;if(!n||n.length===0)return internalClone(e,new Map);let r=new Set;for(let e of n)if(classOf(e)===`ArrayBuffer`){let t=e;t.detached===!0&&throwDataCloneError(`ArrayBuffer in transfer list is detached`),r.add(t)}let i=new Map;r.size>0&&snapshotViewsBackedByTransferredBuffers(e,r,i,new Set);let a=new Map;for(let e of r){let t=e;typeof t.transfer!=`function`&&throwDataCloneError(`ArrayBuffer.prototype.transfer() not available — runtime is not SM140+`),a.set(e,t.transfer())}return internalClone(e,new Map,{transferred:a,viewSnapshots:i})}__name(structuredClone$1,`structuredClone`);function snapshotViewsBackedByTransferredBuffers(e,t,n,r){if(typeof e!=`object`||!e)return;let i=e;if(r.has(i))return;r.add(i);let a=classOf(i);if(a===`DataView`){let e=i;t.has(e.buffer)&&n.set(i,{byteOffset:e.byteOffset,length:0,byteLength:e.byteLength});return}if(ie.has(a)){let e=i;t.has(e.buffer)&&n.set(i,{byteOffset:e.byteOffset,length:e.length,byteLength:e.byteLength});return}if(Array.isArray(i)){for(let e=0;e<i.length;e++)e in i&&snapshotViewsBackedByTransferredBuffers(i[e],t,n,r);return}if(a===`Map`){for(let[e,a]of i)snapshotViewsBackedByTransferredBuffers(e,t,n,r),snapshotViewsBackedByTransferredBuffers(a,t,n,r);return}if(a===`Set`){for(let e of i)snapshotViewsBackedByTransferredBuffers(e,t,n,r);return}if(a===`Object`)for(let e of Object.keys(i))snapshotViewsBackedByTransferredBuffers(i[e],t,n,r)}function hostGlib(){try{return globalThis.imports?.gi?.GLib}catch{return}}function readText(e,t){try{let[n,r]=e.file_get_contents(t);return!n||!r?null:new TextDecoder().decode(r)}catch{return null}}function shellOut(e,t){try{let[n,r]=e.spawn_command_line_sync(t);if(!n||!r)return null;let i=new TextDecoder().decode(r).trim();return i.length>0?i:null}catch{return null}}function hasProcfs(){let e=hostGlib();if(!e)return!1;try{return e.file_test(`/proc/self/status`,16)}catch{return!1}}let ae=null;function hostPid(){if(ae!==null)return ae>0?ae:void 0;let e=hostGlib();if(!e)return;let t=0,n=hasProcfs()?readText(e,`/proc/self/stat`):null;if(n)t=parseInt(n,10);else{let n=shellOut(e,`sh -c 'echo $PPID'`);n&&(t=parseInt(n,10))}return ae=Number.isInteger(t)&&t>0?t:0,ae>0?ae:void 0}function hostPpid(){let e=hostGlib();if(!e)return;let t=hasProcfs()?readText(e,`/proc/self/status`):null;if(t){let e=/PPid:\s+(\d+)/.exec(t);if(e){let t=parseInt(e[1],10);return Number.isInteger(t)?t:void 0}}let n=hostPid();if(n===void 0)return;let r=shellOut(e,`ps -o ppid= -p ${n}`);if(!r)return;let i=parseInt(r,10);return Number.isInteger(i)?i:void 0}function hostExecPath(){let e=hostGlib();if(e){if(hasProcfs())try{let t=e.file_read_link(`/proc/self/exe`);if(t)return t}catch{}try{let t=e.get_prgname();if(t){let n=e.find_program_in_path(t);if(n)return n}}catch{return}}}function readProcessMemory(){let e=hostGlib();if(!e)return null;let t=hasProcfs()?readText(e,`/proc/self/status`):null;if(t){let e=new Map;for(let n of t.split(`
|
|
6
|
-
`)){let t=/^(\w+):\s+(\d+)(\s+kB)?/.exec(n);t&&e.set(t[1],parseInt(t[2],10)*(t[3]?1024:1))}if(e.size>0)return{virtual:e.get(`VmSize`)??0,resident:e.get(`VmRSS`)??0,data:e.get(`VmData`)??0,peak:e.get(`VmPeak`)??0}}let n=shellOut(e,`sh -c 'ps -o rss=,vsz= -p $PPID'`);if(!n)return null;let r=/^(\d+)\s+(\d+)$/.exec(n);return r?{virtual:parseInt(r[2],10)*1024,resident:parseInt(r[1],10)*1024,data:0,peak:0}:null}let oe=!1,se=null;function ensureMainLoop(){let e=globalThis.imports;if(!e)return;if(oe)return se;let t=e.gi?.GLib;if(t)return se=new t.MainLoop(null,!1),oe=!0,t.main_depth()===0&&se.runAsync().catch(()=>{}),se}function quitMainLoop(){se&&=(se.quit(),oe=!1,null)}registerGlobal(`Blob`,T),registerGlobal(`File`,E);const ce={aliceblue:`#f0f8ff`,antiquewhite:`#faebd7`,aqua:`#00ffff`,aquamarine:`#7fffd4`,azure:`#f0ffff`,beige:`#f5f5dc`,bisque:`#ffe4c4`,black:`#000000`,blanchedalmond:`#ffebcd`,blue:`#0000ff`,blueviolet:`#8a2be2`,brown:`#a52a2a`,burlywood:`#deb887`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,cornflowerblue:`#6495ed`,cornsilk:`#fff8dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkgrey:`#a9a9a9`,darkkhaki:`#bdb76b`,darkmagenta:`#8b008b`,darkolivegreen:`#556b2f`,darkorange:`#ff8c00`,darkorchid:`#9932cc`,darkred:`#8b0000`,darksalmon:`#e9967a`,darkseagreen:`#8fbc8f`,darkslateblue:`#483d8b`,darkslategray:`#2f4f4f`,darkslategrey:`#2f4f4f`,darkturquoise:`#00ced1`,darkviolet:`#9400d3`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,dimgray:`#696969`,dimgrey:`#696969`,dodgerblue:`#1e90ff`,firebrick:`#b22222`,floralwhite:`#fffaf0`,forestgreen:`#228b22`,fuchsia:`#ff00ff`,gainsboro:`#dcdcdc`,ghostwhite:`#f8f8ff`,gold:`#ffd700`,goldenrod:`#daa520`,gray:`#808080`,green:`#008000`,greenyellow:`#adff2f`,grey:`#808080`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,indianred:`#cd5c5c`,indigo:`#4b0082`,ivory:`#fffff0`,khaki:`#f0e68c`,lavender:`#e6e6fa`,lavenderblush:`#fff0f5`,lawngreen:`#7cfc00`,lemonchiffon:`#fffacd`,lightblue:`#add8e6`,lightcoral:`#f08080`,lightcyan:`#e0ffff`,lightgoldenrodyellow:`#fafad2`,lightgray:`#d3d3d3`,lightgreen:`#90ee90`,lightgrey:`#d3d3d3`,lightpink:`#ffb6c1`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,lightskyblue:`#87cefa`,lightslategray:`#778899`,lightslategrey:`#778899`,lightsteelblue:`#b0c4de`,lightyellow:`#ffffe0`,lime:`#00ff00`,limegreen:`#32cd32`,linen:`#faf0e6`,magenta:`#ff00ff`,maroon:`#800000`,mediumaquamarine:`#66cdaa`,mediumblue:`#0000cd`,mediumorchid:`#ba55d3`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumslateblue:`#7b68ee`,mediumspringgreen:`#00fa9a`,mediumturquoise:`#48d1cc`,mediumvioletred:`#c71585`,midnightblue:`#191970`,mintcream:`#f5fffa`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,navajowhite:`#ffdead`,navy:`#000080`,oldlace:`#fdf5e6`,olive:`#808000`,olivedrab:`#6b8e23`,orange:`#ffa500`,orangered:`#ff4500`,orchid:`#da70d6`,palegoldenrod:`#eee8aa`,palegreen:`#98fb98`,paleturquoise:`#afeeee`,palevioletred:`#db7093`,papayawhip:`#ffefd5`,peachpuff:`#ffdab9`,peru:`#cd853f`,pink:`#ffc0cb`,plum:`#dda0dd`,powderblue:`#b0e0e6`,purple:`#800080`,rebeccapurple:`#663399`,red:`#ff0000`,rosybrown:`#bc8f8f`,royalblue:`#4169e1`,saddlebrown:`#8b4513`,salmon:`#fa8072`,sandybrown:`#f4a460`,seagreen:`#2e8b57`,seashell:`#fff5ee`,sienna:`#a0522d`,silver:`#c0c0c0`,skyblue:`#87ceeb`,slateblue:`#6a5acd`,slategray:`#708090`,slategrey:`#708090`,snow:`#fffafa`,springgreen:`#00ff7f`,steelblue:`#4682b4`,tan:`#d2b48c`,teal:`#008080`,thistle:`#d8bfd8`,tomato:`#ff6347`,turquoise:`#40e0d0`,violet:`#ee82ee`,wheat:`#f5deb3`,white:`#ffffff`,whitesmoke:`#f5f5f5`,yellow:`#ffff00`,yellowgreen:`#9acd32`,transparent:`#00000000`};function parseColor(e){if(!e||typeof e!=`string`)return null;let t=e.trim().toLowerCase(),n=ce[t];if(n)return parseHex(n);if(t.startsWith(`#`))return parseHex(t);let r=t.match(/^rgba?\(\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);if(r)return{r:parseComponent(r[1],255)/255,g:parseComponent(r[2],255)/255,b:parseComponent(r[3],255)/255,a:r[4]===void 0?1:parseComponent(r[4],1)};let i=t.match(/^hsla?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);if(i){let e=parseFloat(i[1]),t=parseFloat(i[2]),n=i[3]===`%`,r=parseFloat(i[4]),a=i[5]===`%`,o=i[6]===void 0?1:parseComponent(i[6],1);return e>1&&(e/=360),(n||t>1)&&(t/=100),(a||r>1)&&(r/=100),hslToRGBA(e,t,r,Math.max(0,Math.min(1,o)))}return null}function parseHex(e){let t=e.slice(1),n,r,i,a=1;if(t.length===3)n=parseInt(t[0]+t[0],16)/255,r=parseInt(t[1]+t[1],16)/255,i=parseInt(t[2]+t[2],16)/255;else if(t.length===4)n=parseInt(t[0]+t[0],16)/255,r=parseInt(t[1]+t[1],16)/255,i=parseInt(t[2]+t[2],16)/255,a=parseInt(t[3]+t[3],16)/255;else if(t.length===6)n=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,i=parseInt(t.slice(4,6),16)/255;else if(t.length===8)n=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,i=parseInt(t.slice(4,6),16)/255,a=parseInt(t.slice(6,8),16)/255;else return null;return{r:n,g:r,b:i,a}}function parseComponent(e,t){return e.endsWith(`%`)?parseFloat(e)/100*t:parseFloat(e)}function hue2rgb$1(e,t,n){return n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e}__name(hue2rgb$1,`hue2rgb`);function hslToRGBA(e,t,n,r){let i,a,o;if(t===0)i=a=o=n;else{let r=n<.5?n*(1+t):n+t-n*t,s=2*n-r;i=hue2rgb$1(s,r,e+1/3),a=hue2rgb$1(s,r,e),o=hue2rgb$1(s,r,e-1/3)}return{r:i,g:a,b:o,a:r}}const le={r:0,g:0,b:0,a:1};var CanvasGradient=class{constructor(t,n,r,i,a,o,s){t===`radial`?this._pattern=new e.RadialGradient(n,r,o,i,a,s):this._pattern=new e.LinearGradient(n,r,i,a)}addColorStop(e,t){let n=parseColor(t);n&&this._pattern.addColorStopRGBA(e,n.r,n.g,n.b,n.a)}_getCairoPattern(){return this._pattern}};function quadraticToCubic(e,t,n,r,i,a){return{cp1x:e+2/3*(n-e),cp1y:t+2/3*(r-t),cp2x:i+2/3*(n-i),cp2y:a+2/3*(r-a)}}function computeArcTo(e,t,n,r,i,a,o){let s=e-n,c=t-r,l=i-n,u=a-r,d=Math.sqrt(s*s+c*c),f=Math.sqrt(l*l+u*u);if(d===0||f===0)return null;let p=s/d,m=c/d,h=l/f,g=u/f,_=p*g-m*h;if(Math.abs(_)<1e-10)return null;let v=p*h+m*g,y=Math.acos(Math.max(-1,Math.min(1,v)))/2,b=o/Math.tan(y),x=n+p*b,S=r+m*b,C=n+h*b,w=r+g*b,T=o/Math.sin(y),E=(p+h)/2,D=(m+g)/2,O=Math.sqrt(E*E+D*D),ee=n+E/O*T,k=r+D/O*T;return{tx0:x,ty0:S,tx1:C,ty1:w,cx:ee,cy:k,startAngle:Math.atan2(S-k,x-ee),endAngle:Math.atan2(w-k,C-ee),counterclockwise:_>0}}function cairoArcTo(e,t,n,r,i,a,o,s){let c=computeArcTo(t,n,r,i,a,o,s);if(!c){e.lineTo(r,i);return}let{tx0:l,ty0:u,cx:d,cy:f,startAngle:p,endAngle:m,counterclockwise:h}=c;e.lineTo(l,u),h?e.arcNegative(d,f,s,p,m):e.arc(d,f,s,p,m)}function cairoEllipse(e,t,n,r,i,a,o,s,c){e.save(),e.translate(t,n),e.rotate(a),e.scale(r,i),c?e.arcNegative(0,0,1,o,s):e.arc(0,0,1,o,s),e.restore()}function cairoRoundRect(e,t,n,r,i,a){let o,s,c,l;typeof a==`number`?o=s=c=l=a:a.length===1?o=s=c=l=a[0]:a.length===2?(o=c=a[0],s=l=a[1]):a.length===3?(o=a[0],s=l=a[1],c=a[2]):(o=a[0],s=a[1],c=a[2],l=a[3]);let u=Math.min(r/2,i/2);o=Math.min(o,u),s=Math.min(s,u),c=Math.min(c,u),l=Math.min(l,u);let d=Math.PI/2;e.newSubPath(),e.arc(t+o,n+o,o,Math.PI,Math.PI+d),e.arc(t+r-s,n+s,s,-d,0),e.arc(t+r-c,n+i-c,c,0,d),e.arc(t+l,n+i-l,l,d,Math.PI),e.closePath()}const ue={"source-over":2,"source-in":3,"source-out":4,"source-atop":5,"destination-over":7,"destination-in":8,"destination-out":9,"destination-atop":10,lighter:12,copy:1,xor:11,multiply:14,screen:15,overlay:16,darken:17,lighten:18,"color-dodge":19,"color-burn":20,"hard-light":21,"soft-light":22,difference:23,exclusion:24,hue:25,saturation:26,color:27,luminosity:28},de={butt:0,round:1,square:2},fe={miter:0,round:1,bevel:2};var pe=class Path2D{constructor(e){this._ops=[],e instanceof Path2D&&(this._ops=[...e._ops])}addPath(e){this._ops.push(...e._ops)}moveTo(e,t){this._ops.push({type:`moveTo`,x:e,y:t})}lineTo(e,t){this._ops.push({type:`lineTo`,x:e,y:t})}closePath(){this._ops.push({type:`closePath`})}bezierCurveTo(e,t,n,r,i,a){this._ops.push({type:`bezierCurveTo`,cp1x:e,cp1y:t,cp2x:n,cp2y:r,x:i,y:a})}quadraticCurveTo(e,t,n,r){this._ops.push({type:`quadraticCurveTo`,cpx:e,cpy:t,x:n,y:r})}arc(e,t,n,r,i,a=!1){this._ops.push({type:`arc`,x:e,y:t,radius:n,startAngle:r,endAngle:i,ccw:a})}ellipse(e,t,n,r,i,a,o,s=!1){if(n<0||r<0)throw RangeError(`The radii provided are negative`);this._ops.push({type:`ellipse`,x:e,y:t,rx:n,ry:r,rotation:i,startAngle:a,endAngle:o,ccw:s})}rect(e,t,n,r){this._ops.push({type:`rect`,x:e,y:t,w:n,h:r})}roundRect(e,t,n,r,i=0){this._ops.push({type:`roundRect`,x:e,y:t,w:n,h:r,radii:i})}_replayOnCairo(e){let t=0,n=0;for(let r of this._ops)switch(r.type){case`moveTo`:e.moveTo(r.x,r.y),t=r.x,n=r.y;break;case`lineTo`:e.lineTo(r.x,r.y),t=r.x,n=r.y;break;case`closePath`:e.closePath();break;case`bezierCurveTo`:e.curveTo(r.cp1x,r.cp1y,r.cp2x,r.cp2y,r.x,r.y),t=r.x,n=r.y;break;case`quadraticCurveTo`:{let{cp1x:i,cp1y:a,cp2x:o,cp2y:s}=quadraticToCubic(t,n,r.cpx,r.cpy,r.x,r.y);e.curveTo(i,a,o,s,r.x,r.y),t=r.x,n=r.y;break}case`arc`:r.ccw?e.arcNegative(r.x,r.y,r.radius,r.startAngle,r.endAngle):e.arc(r.x,r.y,r.radius,r.startAngle,r.endAngle);break;case`ellipse`:e.save(),e.translate(r.x,r.y),e.rotate(r.rotation),e.scale(r.rx,r.ry),r.ccw?e.arcNegative(0,0,1,r.startAngle,r.endAngle):e.arc(0,0,1,r.startAngle,r.endAngle),e.restore();break;case`rect`:e.rectangle(r.x,r.y,r.w,r.h);break;case`roundRect`:cairoRoundRect(e,r.x,r.y,r.w,r.h,r.radii);break}}};function asCairoPattern(e){if(!e)return null;let t=e;return typeof t.setFilter!=`function`||typeof t.setExtend!=`function`?null:t}function isPixbufImageSource(e){return typeof e!=`object`||!e?!1:typeof e.isPixbuf==`function`&&e.isPixbuf()}function isCanvasImageSource(e){return typeof e!=`object`||!e?!1:typeof e.getContext==`function`}let me=null;function setCanvasPixelBridge(e){me=e}function getCanvasPixelBridge(){if(!me)throw TypeError(`@gjsify/canvas2d-core: no pixel bridge registered — pixel operations (getImageData / putImageData / drawImage / createPattern) need a platform backend. On GJS, import '@gjsify/canvas2d-core/gdk' (or use '@gjsify/dom-elements' / '@gjsify/canvas2d', which register it for you).`);return me}var he=class CanvasPattern{constructor(t,n){let r=asCairoPattern(new e.SurfacePattern(t));if(!r)throw TypeError(`CanvasPattern: cairo SurfacePattern is missing setExtend at runtime — incompatible Cairo binding`);switch(this._pattern=r,n){case`repeat`:case``:case null:r.setExtend(e.Extend.REPEAT);break;case`repeat-x`:case`repeat-y`:r.setExtend(e.Extend.REPEAT);break;case`no-repeat`:r.setExtend(e.Extend.NONE);break}}static create(t,n){if(isPixbufImageSource(t)){let r=t._pixbuf,i=r.get_width(),a=r.get_height(),o=new e.ImageSurface(e.Format.ARGB32,i,a),s=new e.Context(o);return getCanvasPixelBridge().setSourceImage(s,r,0,0),s.paint(),s.$dispose(),new CanvasPattern(o,n)}if(isCanvasImageSource(t)){let r=t.getContext(`2d`);if(r&&typeof r._getSurface==`function`){let t=r._getSurface(),i=t.getWidth(),a=t.getHeight(),o=new e.ImageSurface(e.Format.ARGB32,i,a),s=new e.Context(o);return s.setSourceSurface(t,0,0),s.paint(),s.$dispose(),new CanvasPattern(o,n)}}return null}_getCairoPattern(){return this._pattern}},OurImageData=class{constructor(e,t,n){if(this.colorSpace=`srgb`,typeof e==`number`)this.width=e,this.height=t,this.data=new Uint8ClampedArray(this.width*this.height*4);else if(this.data=e,this.width=t,this.height=n??this.data.length/(4*this.width),this.data.length!==this.width*this.height*4)throw RangeError(`Source data length ${this.data.length} is not a multiple of (4 * width=${this.width})`)}};const ge={translate(e,t){this._ensureSurface(),this._ctx.translate(e,t)},rotate(e){this._ensureSurface(),this._ctx.rotate(e)},scale(e,t){this._ensureSurface(),this._ctx.scale(e,t)},transform(e,t,n,r,i,a){if(this._ensureSurface(),!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(a))return;let o=i,s=a,c=Math.hypot(e,t),l=Math.hypot(n,r),u=Math.atan2(t,e);this._ctx.translate(o,s),u!==0&&this._ctx.rotate(u),(c!==1||l!==1)&&this._ctx.scale(c,l)},setTransform(e,t,n,r,i,a){if(this._ensureSurface(),typeof e==`object`&&e){let t=e;this._ctx.identityMatrix(),this.transform(t.a??t.m11??1,t.b??t.m12??0,t.c??t.m21??0,t.d??t.m22??1,t.e??t.m41??0,t.f??t.m42??0)}else typeof e==`number`?(this._ctx.identityMatrix(),this.transform(e,t,n,r,i,a)):this._ctx.identityMatrix()},getTransform(){let e=this._ctx.userToDevice(0,0),t=this._ctx.userToDevice(1,0),n=this._ctx.userToDevice(0,1),r=e[0]??0,i=e[1]??0,a=(t[0]??0)-r,o=(t[1]??0)-i,s=(n[0]??0)-r,c=(n[1]??0)-i,l=globalThis.DOMMatrix;return typeof l==`function`?new l([a,o,s,c,r,i]):{a,b:o,c:s,d:c,e:r,f:i,m11:a,m12:o,m13:0,m14:0,m21:s,m22:c,m23:0,m24:0,m31:0,m32:0,m33:1,m34:0,m41:r,m42:i,m43:0,m44:1,is2D:!0,isIdentity:a===1&&o===0&&s===0&&c===1&&r===0&&i===0}},resetTransform(){this._ensureSurface(),this._ctx.identityMatrix()}};function installTransformMethods(e){Object.assign(e,ge)}const _e={beginPath(){this._ensureSurface(),this._ctx.newPath()},moveTo(e,t){this._ensureSurface(),this._ctx.moveTo(e,t)},lineTo(e,t){this._ensureSurface(),this._ctx.lineTo(e,t)},closePath(){this._ensureSurface(),this._ctx.closePath()},bezierCurveTo(e,t,n,r,i,a){this._ensureSurface(),this._ctx.curveTo(e,t,n,r,i,a)},quadraticCurveTo(e,t,n,r){this._ensureSurface();let i,a;this._ctx.hasCurrentPoint()?[i,a]=this._ctx.getCurrentPoint():(i=e,a=t);let{cp1x:o,cp1y:s,cp2x:c,cp2y:l}=quadraticToCubic(i,a,e,t,n,r);this._ctx.curveTo(o,s,c,l,n,r)},arc(e,t,n,r,i,a=!1){if(this._ensureSurface(),Math.abs(i-r)>=2*Math.PI){this._ctx.arc(e,t,n,0,2*Math.PI);return}a?this._ctx.arcNegative(e,t,n,r,i):this._ctx.arc(e,t,n,r,i)},arcTo(e,t,n,r,i){this._ensureSurface();let a,o;this._ctx.hasCurrentPoint()?[a,o]=this._ctx.getCurrentPoint():(a=e,o=t,this._ctx.moveTo(e,t)),cairoArcTo(this._ctx,a,o,e,t,n,r,i)},ellipse(e,t,n,r,i,a,o,s=!1){if(this._ensureSurface(),n<0||r<0)throw RangeError(`The radii provided are negative`);cairoEllipse(this._ctx,e,t,n,r,i,a,o,s)},rect(e,t,n,r){this._ensureSurface(),this._ctx.rectangle(e,t,n,r)},roundRect(e,t,n,r,i=0){this._ensureSurface(),cairoRoundRect(this._ctx,e,t,n,r,i)}};function installPathMethods(e){Object.assign(e,_e)}function getDrawImageSource(e){if(isPixbufImageSource(e)){let t=e._pixbuf;return{pixbuf:t,imgWidth:t.get_width(),imgHeight:t.get_height()}}if(isCanvasImageSource(e)){let t=e.width??0,n=e.height??0;if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=e.getContext(`2d`);if(r&&typeof r._getSurface==`function`){let e=r._getSurface();e.flush();let i=getCanvasPixelBridge().imageFromSurface(e,0,0,t,n);if(i)return{pixbuf:i,imgWidth:t,imgHeight:n}}}return null}const ve={fill(t,n){this._ensureSurface(),this._applyCompositing(),this._applyFillStyle();let r;t instanceof pe?(this._ctx.newPath(),t._replayOnCairo(this._ctx),r=n):r=t,this._ctx.setFillRule(r===`evenodd`?e.FillRule.EVEN_ODD:e.FillRule.WINDING),this._ctx.fillPreserve()},stroke(e){this._ensureSurface(),this._applyCompositing(),this._applyStrokeStyle(),this._applyLineStyle(),e instanceof pe&&(this._ctx.newPath(),e._replayOnCairo(this._ctx)),this._ctx.strokePreserve()},fillRect(e,t,n,r){this._ensureSurface(),this._applyCompositing();let i=this._ctx.copyPath();this._hasShadow()&&this._renderShadow(()=>{this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.fill()}),this._applyFillStyle(),this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.fill(),this._ctx.newPath(),this._ctx.appendPath(i)},strokeRect(e,t,n,r){this._ensureSurface(),this._applyCompositing();let i=this._ctx.copyPath();this._hasShadow()&&this._renderShadow(()=>{this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.stroke()}),this._applyStrokeStyle(),this._applyLineStyle(),this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.stroke(),this._ctx.newPath(),this._ctx.appendPath(i)},clearRect(t,n,r,i){this._ensureSurface();let a=this._ctx.copyPath();this._ctx.save(),this._ctx.setOperator(e.Operator.CLEAR),this._ctx.newPath(),this._ctx.rectangle(t,n,r,i),this._ctx.fill(),this._ctx.restore(),this._ctx.newPath(),this._ctx.appendPath(a)},clip(t,n){this._ensureSurface();let r;t instanceof pe?(this._ctx.newPath(),t._replayOnCairo(this._ctx),r=n):r=t,this._ctx.setFillRule(r===`evenodd`?e.FillRule.EVEN_ODD:e.FillRule.WINDING),this._ctx.clip()},isPointInPath(t,n,r,i){this._ensureSurface();let a,o,s;return t instanceof pe?(this._ctx.newPath(),t._replayOnCairo(this._ctx),a=n,o=r,s=i):(a=t,o=n,s=r),this._ctx.setFillRule(s===`evenodd`?e.FillRule.EVEN_ODD:e.FillRule.WINDING),this._ctx.inFill(a,o)},isPointInStroke(e,t,n){return this._ensureSurface(),this._applyLineStyle(),e instanceof pe?(this._ctx.newPath(),e._replayOnCairo(this._ctx),this._ctx.inStroke(t,n)):this._ctx.inStroke(e,t)},drawImage(t,n,r,i,a,o,s,c,l){this._ensureSurface(),this._applyCompositing();let u,d,f,p,m,h,g,_,v=getDrawImageSource(t);if(!v)return;let{pixbuf:y,imgWidth:b,imgHeight:x}=v;if(i===void 0?(u=0,d=0,f=b,p=x,m=n,h=r,g=b,_=x):o===void 0?(u=0,d=0,f=b,p=x,m=n,h=r,g=i,_=a):(u=n,d=r,f=i,p=a,m=o,h=s,g=c,_=l),!Number.isFinite(u)||!Number.isFinite(d)||!Number.isFinite(f)||!Number.isFinite(p)||!Number.isFinite(m)||!Number.isFinite(h)||!Number.isFinite(g)||!Number.isFinite(_)||f===0||p===0||g===0||_===0)return;this._ctx.save(),this._ctx.rectangle(m,h,g,_),this._ctx.clip(),this._ctx.translate(m,h),this._ctx.scale(g/f,_/p),this._ctx.translate(-u,-d),getCanvasPixelBridge().setSourceImage(this._ctx,y,0,0);let S=asCairoPattern(this._ctx.getSource?.());if(S){let t;t=this._state.imageSmoothingEnabled?this._state.imageSmoothingQuality===`high`?e.Filter.BEST:e.Filter.BILINEAR:e.Filter.NEAREST,S.setFilter(t)}this._state.globalAlpha<1?this._ctx.paintWithAlpha(this._state.globalAlpha):this._ctx.paint(),this._ctx.restore()}};function installDrawingMethods$1(e){Object.assign(e,ve)}__name(installDrawingMethods$1,`installDrawingMethods`);const ye={createImageData(e,t){return typeof e==`number`?new OurImageData(Math.abs(e),Math.abs(t)):new OurImageData(e.width,e.height)},getImageData(e,t,n,r){this._ensureSurface(),this._surface.flush();let i=getCanvasPixelBridge().imageFromSurface(this._surface,e,t,n,r);if(!i)return new OurImageData(n,r);let a=i.get_pixels(),o=i.get_has_alpha(),s=i.get_rowstride(),c=i.get_n_channels(),l=new Uint8ClampedArray(n*r*4);for(let e=0;e<r;e++)for(let t=0;t<n;t++){let r=e*s+t*c,i=(e*n+t)*4;l[i]=a[r],l[i+1]=a[r+1],l[i+2]=a[r+2],l[i+3]=o?a[r+3]:255}return new OurImageData(l,n,r)},putImageData(t,n,r,i,a,o,s){this._ensureSurface();let c=i??0,l=a??0,u=o??t.width,d=s??t.height,f=t.data,p=t.width,m=new Uint8Array(u*d*4);for(let e=0;e<d;e++)for(let t=0;t<u;t++){let n=((l+e)*p+(c+t))*4,r=(e*u+t)*4;m[r]=f[n],m[r+1]=f[n+1],m[r+2]=f[n+2],m[r+3]=f[n+3]}this._ctx.save(),this._ctx.setOperator(e.Operator.SOURCE),getCanvasPixelBridge().setSourcePixels(this._ctx,m,u,d,n+c,r+l),this._ctx.rectangle(n+c,r+l,u,d),this._ctx.fill(),this._ctx.restore()}};function installPixelMethods(e){Object.assign(e,ye)}function parseFontToDescription(e){let n=e.match(/^\s*(italic|oblique|normal)?\s*(small-caps|normal)?\s*(bold|bolder|lighter|[1-9]00|normal)?\s*(\d+(?:\.\d+)?)(px|pt|em|rem|%)?\s*(?:\/\S+)?\s*(.+)?$/i);if(!n)return t.font_description_from_string(e);let r=n[1]||``,i=n[3]||``,a=parseFloat(n[4])||10,o=(n[5]||`px`).toLowerCase(),s=(n[6]||`sans-serif`).replace(/['"]/g,``).trim();o===`pt`?a=a*96/72:o===`em`||o===`rem`?a*=16:o===`%`&&(a=a/100*16);let c=s;r===`italic`?c+=` Italic`:r===`oblique`&&(c+=` Oblique`),i===`bold`||i===`bolder`||parseInt(i)>=600?c+=` Bold`:(i===`lighter`||parseInt(i)>0&&parseInt(i)<=300)&&(c+=` Light`);let l=t.font_description_from_string(c);return l.set_absolute_size(a*t.SCALE),l}function createTextLayout(e,r){let i=n.create_layout(e._ctx);i.set_text(r,-1),i.get_context().set_base_dir(t.Direction.LTR),i.context_changed();let a=parseFontToDescription(e._state.font);return i.set_font_description(a),i}function getTextAlignOffset(e,t){let[,n]=t.get_pixel_extents(),r=n.width;switch(e._state.textAlign){case`center`:return-r/2;case`right`:case`end`:return-r;default:return 0}}function getTextBaselineOffset(e,n){let r=n.get_font_description()||parseFontToDescription(e._state.font),i=n.get_context().get_metrics(r,null),a=i.get_ascent()/t.SCALE,o=i.get_descent()/t.SCALE,s=a+o;switch(e._state.textBaseline){case`top`:return 0;case`hanging`:return-(a*.2);case`middle`:return-(s/2);case`alphabetic`:return-a;case`ideographic`:return-(a+o*.5);case`bottom`:return-s;default:return-a}}const be={fillText(t,r,i,a){this._ensureSurface(),this._applyCompositing();let o=createTextLayout(this,t),s=getTextAlignOffset(this,o),c=getTextBaselineOffset(this,o);if(this._hasShadow()){let t=parseColor(this._state.shadowColor);if(t){let[a,l]=this._deviceToUserDistance(this._state.shadowOffsetX,this._state.shadowOffsetY),u=this._state.shadowBlur,d;if(u>0){let[e]=this._deviceToUserDistance(u,0),[,n]=this._deviceToUserDistance(0,u);d=[[a,l,t.a],[a+e,l,t.a*.5],[a-e,l,t.a*.5],[a,l+n,t.a*.5],[a,l-n,t.a*.5]]}else d=[[a,l,t.a]];let f=this._state.imageSmoothingEnabled?e.Antialias.DEFAULT:e.Antialias.NONE;for(let[e,a,l]of d)this._ctx.save(),this._ctx.setAntialias(f),this._ctx.setSourceRGBA(t.r,t.g,t.b,l),this._ctx.moveTo(r+s+e,i+c+a),n.show_layout(this._ctx,o),this._ctx.restore()}}this._applyFillStyle(),this._ctx.save(),this._ctx.setAntialias(this._state.imageSmoothingEnabled?e.Antialias.DEFAULT:e.Antialias.NONE),this._ctx.moveTo(r+s,i+c),n.show_layout(this._ctx,o),this._ctx.restore()},strokeText(t,r,i,a){this._ensureSurface(),this._applyCompositing(),this._applyStrokeStyle(),this._applyLineStyle();let o=createTextLayout(this,t),s=getTextAlignOffset(this,o),c=getTextBaselineOffset(this,o);this._ctx.save(),this._ctx.setAntialias(this._state.imageSmoothingEnabled?e.Antialias.DEFAULT:e.Antialias.NONE),this._ctx.moveTo(r+s,i+c),n.layout_path(this._ctx,o),this._ctx.stroke(),this._ctx.restore()},measureText(e){this._ensureSurface();let n=createTextLayout(this,e),[r,i]=n.get_pixel_extents(),a=n.get_baseline()/t.SCALE,o=Math.max(0,a-r.y),s=Math.max(0,r.y+r.height-a),c=n.get_font_description()||parseFontToDescription(this._state.font),l=n.get_context().get_metrics(c,null),u=l.get_ascent()/t.SCALE,d=l.get_descent()/t.SCALE;return{width:i.width,actualBoundingBoxAscent:o,actualBoundingBoxDescent:s,actualBoundingBoxLeft:Math.max(0,-r.x),actualBoundingBoxRight:r.x+r.width,fontBoundingBoxAscent:u,fontBoundingBoxDescent:d,alphabeticBaseline:0,emHeightAscent:u,emHeightDescent:d,hangingBaseline:u*.8,ideographicBaseline:-d}}};function installTextMethods(e){Object.assign(e,be)}const xe={createLinearGradient(e,t,n,r){return new CanvasGradient(`linear`,e,t,n,r)},createRadialGradient(e,t,n,r,i,a){return new CanvasGradient(`radial`,e,t,r,i,n,a)},createPattern(e,t){return he.create(e,t)}};function installFactoryMethods(e){Object.assign(e,xe)}function installAllContextMethods$1(e){installTransformMethods(e),installPathMethods(e),installDrawingMethods$1(e),installPixelMethods(e),installTextMethods(e),installFactoryMethods(e)}__name(installAllContextMethods$1,`installAllContextMethods`);function createDefaultState(){return{fillStyle:`#000000`,fillColor:{...le},strokeStyle:`#000000`,strokeColor:{...le},lineWidth:1,lineCap:`butt`,lineJoin:`miter`,miterLimit:10,lineDash:[],lineDashOffset:0,globalAlpha:1,globalCompositeOperation:`source-over`,shadowColor:`rgba(0, 0, 0, 0)`,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,font:`10px sans-serif`,textAlign:`start`,textBaseline:`alphabetic`,direction:`ltr`,imageSmoothingEnabled:!0,imageSmoothingQuality:`low`}}function cloneState(e){return{...e,fillColor:{...e.fillColor},strokeColor:{...e.strokeColor},lineDash:[...e.lineDash]}}var CanvasRenderingContext2D=class{constructor(t,n){this._stateStack=[],this.canvas=t,this._surfaceWidth=t.width||300,this._surfaceHeight=t.height||150,this._surface=new e.ImageSurface(e.Format.ARGB32,this._surfaceWidth,this._surfaceHeight),this._ctx=new e.Context(this._surface),this._state=createDefaultState()}_ensureSurface(){let t=this.canvas.width||300,n=this.canvas.height||150;(t!==this._surfaceWidth||n!==this._surfaceHeight)&&(this._ctx.$dispose(),this._surface.finish(),this._surfaceWidth=t,this._surfaceHeight=n,this._surface=new e.ImageSurface(e.Format.ARGB32,t,n),this._ctx=new e.Context(this._surface),this._stateStack=[])}_resetState(){this._state=createDefaultState(),this._stateStack=[]}_applyFillStyle(){let e=this._state.fillStyle;if(typeof e==`string`){let e=this._state.fillColor,t=e.a*this._state.globalAlpha;this._ctx.setSourceRGBA(e.r,e.g,e.b,t)}else e instanceof CanvasGradient?this._ctx.setSource(e._getCairoPattern()):e instanceof he&&(this._ctx.setSource(e._getCairoPattern()),this._applyPatternFilter())}_applyStrokeStyle(){let e=this._state.strokeStyle;if(typeof e==`string`){let e=this._state.strokeColor,t=e.a*this._state.globalAlpha;this._ctx.setSourceRGBA(e.r,e.g,e.b,t)}else e instanceof CanvasGradient?this._ctx.setSource(e._getCairoPattern()):e instanceof he&&(this._ctx.setSource(e._getCairoPattern()),this._applyPatternFilter())}_applyPatternFilter(){let t=asCairoPattern(this._ctx.getSource?.());if(!t)return;let n;n=this._state.imageSmoothingEnabled?this._state.imageSmoothingQuality===`high`?e.Filter.BEST:e.Filter.BILINEAR:e.Filter.NEAREST,t.setFilter(n)}_applyLineStyle(){this._ctx.setLineWidth(this._state.lineWidth),this._ctx.setLineCap(de[this._state.lineCap]),this._ctx.setLineJoin(fe[this._state.lineJoin]),this._ctx.setMiterLimit(this._state.miterLimit),this._ctx.setDash(this._state.lineDash,this._state.lineDashOffset)}_applyCompositing(){let e=ue[this._state.globalCompositeOperation];e!==void 0&&this._ctx.setOperator(e)}_getSurface(){return this._surface}_hasShadow(){if(this._state.shadowBlur===0&&this._state.shadowOffsetX===0&&this._state.shadowOffsetY===0)return!1;let e=parseColor(this._state.shadowColor);return e!==null&&e.a>0}_deviceToUserDistance(e,t){let n=this._ctx.userToDevice(0,0),r=this._ctx.userToDevice(1,0),i=this._ctx.userToDevice(0,1),a=(r[0]??0)-(n[0]??0),o=(r[1]??0)-(n[1]??0),s=(i[0]??0)-(n[0]??0),c=(i[1]??0)-(n[1]??0),l=a*c-o*s;return Math.abs(l)<1e-10?[e,t]:[(c*e-s*t)/l,(-o*e+a*t)/l]}_renderShadow(e){}save(){this._ensureSurface(),this._stateStack.push(cloneState(this._state)),this._ctx.save()}restore(){this._ensureSurface();let e=this._stateStack.pop();e&&(this._state=e,this._ctx.restore())}get fillStyle(){return this._state.fillStyle}set fillStyle(e){if(typeof e==`string`){let t=parseColor(e);t&&(this._state.fillStyle=e,this._state.fillColor=t)}else this._state.fillStyle=e}get strokeStyle(){return this._state.strokeStyle}set strokeStyle(e){if(typeof e==`string`){let t=parseColor(e);t&&(this._state.strokeStyle=e,this._state.strokeColor=t)}else this._state.strokeStyle=e}get lineWidth(){return this._state.lineWidth}set lineWidth(e){e>0&&isFinite(e)&&(this._state.lineWidth=e)}get lineCap(){return this._state.lineCap}set lineCap(e){(e===`butt`||e===`round`||e===`square`)&&(this._state.lineCap=e)}get lineJoin(){return this._state.lineJoin}set lineJoin(e){(e===`miter`||e===`round`||e===`bevel`)&&(this._state.lineJoin=e)}get miterLimit(){return this._state.miterLimit}set miterLimit(e){e>0&&isFinite(e)&&(this._state.miterLimit=e)}get globalAlpha(){return this._state.globalAlpha}set globalAlpha(e){e>=0&&e<=1&&isFinite(e)&&(this._state.globalAlpha=e)}get globalCompositeOperation(){return this._state.globalCompositeOperation}set globalCompositeOperation(e){ue[e]!==void 0&&(this._state.globalCompositeOperation=e)}get imageSmoothingEnabled(){return this._state.imageSmoothingEnabled}set imageSmoothingEnabled(e){this._state.imageSmoothingEnabled=!!e}get imageSmoothingQuality(){return this._state.imageSmoothingQuality}set imageSmoothingQuality(e){(e===`low`||e===`medium`||e===`high`)&&(this._state.imageSmoothingQuality=e)}setLineDash(e){e.some(e=>e<0||!isFinite(e))||(this._state.lineDash=[...e])}getLineDash(){return[...this._state.lineDash]}get lineDashOffset(){return this._state.lineDashOffset}set lineDashOffset(e){isFinite(e)&&(this._state.lineDashOffset=e)}get shadowColor(){return this._state.shadowColor}set shadowColor(e){this._state.shadowColor=e}get shadowBlur(){return this._state.shadowBlur}set shadowBlur(e){e>=0&&isFinite(e)&&(this._state.shadowBlur=e)}get shadowOffsetX(){return this._state.shadowOffsetX}set shadowOffsetX(e){isFinite(e)&&(this._state.shadowOffsetX=e)}get shadowOffsetY(){return this._state.shadowOffsetY}set shadowOffsetY(e){isFinite(e)&&(this._state.shadowOffsetY=e)}get font(){return this._state.font}set font(e){this._state.font=e}get textAlign(){return this._state.textAlign}set textAlign(e){this._state.textAlign=e}get textBaseline(){return this._state.textBaseline}set textBaseline(e){this._state.textBaseline=e}get direction(){return this._state.direction}set direction(e){this._state.direction=e}_toDataURL(e,t){this._surface.flush();let[,n]=i.file_open_tmp(`canvas-XXXXXX.png`);try{this._surface.writeToPNG(n);let[,e]=r.File.new_for_path(n).load_contents(null);return`data:image/png;base64,${i.base64_encode(e)}`}finally{i.unlink(n)}}_dispose(){this._ctx.$dispose(),this._surface.finish()}};installAllContextMethods$1(CanvasRenderingContext2D.prototype);var Se=Object.defineProperty,__exportAll=(e,t)=>{let n={};for(var r in e)Se(n,r,{get:e[r],enumerable:!0});return t||Se(n,Symbol.toStringTag,{value:`Module`}),n};__exportAll({attributes:()=>Ae,childNodesList:()=>M,elementChildren:()=>Te,isConnected:()=>Ee,localName:()=>De,name:()=>je,namespaceURI:()=>Oe,nodeType:()=>Ce,ownerElement:()=>Ne,parentNode:()=>we,prefix:()=>ke,propertyEventListeners:()=>P,tagName:()=>N,value:()=>Me});const Ce=Symbol(`nodeType`),we=Symbol(`parentNode`),M=Symbol(`childNodesList`),Te=Symbol(`elementChildren`),Ee=Symbol(`isConnected`),N=Symbol(`tagName`),De=Symbol(`localName`),Oe=Symbol(`namespaceURI`),ke=Symbol(`prefix`),Ae=Symbol(`attributes`),P=Symbol(`propertyEventListeners`),je=Symbol(`name`),Me=Symbol(`value`),Ne=Symbol(`ownerElement`),Pe={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11};var NodeList=class{constructor(e){this._items=e}get length(){return this._items.length}item(e){return this._items[e]??null}forEach(e,t){for(let n=0;n<this._items.length;n++)e.call(t,this._items[n],n,this)}entries(){return this._items.entries()}keys(){return this._items.keys()}values(){return this._items.values()}[Symbol.iterator](){return this._items[Symbol.iterator]()}get[Symbol.toStringTag](){return`NodeList`}};const Fe={IndexSizeError:1,HierarchyRequestError:3,WrongDocumentError:4,InvalidCharacterError:5,NoModificationAllowedError:7,NotFoundError:8,NotSupportedError:9,InUseAttributeError:10,InvalidStateError:11,SyntaxError:12,InvalidModificationError:13,NamespaceError:14,InvalidAccessError:15,TypeMismatchError:17,SecurityError:18,NetworkError:19,AbortError:20,URLMismatchError:21,QuotaExceededError:22,TimeoutError:23,InvalidNodeTypeError:24,DataCloneError:25};var _DOMExceptionPolyfill=class extends Error{code;constructor(e,t){super(e),this.name=t||`Error`,this.code=Object.hasOwn(Fe,this.name)?Fe[this.name]:0}};const Ie=globalThis.DOMException===void 0?_DOMExceptionPolyfill:globalThis.DOMException,Le=Symbol(`type`),Re=Symbol(`bubbles`),ze=Symbol(`cancelable`),Be=Symbol(`composed`),Ve=Symbol(`target`),He=Symbol(`currentTarget`),Ue=Symbol(`eventPhase`),We=Symbol(`defaultPrevented`),Ge=Symbol(`isTrusted`),Ke=Symbol(`timeStamp`),qe=Symbol(`stop`),Je=Symbol(`immediateStop`),Ye=Symbol(`dispatching`),Xe=Symbol(`inPassiveListener`);var Event=class{[Le];[Re];[ze];[Be];[Ve]=null;[He]=null;[Ue]=0;[We]=!1;[Ge]=!1;[Ke];[qe]=!1;[Je]=!1;[Ye]=!1;[Xe]=!1;get type(){return this[Le]}get bubbles(){return this[Re]}get cancelable(){return this[ze]}get composed(){return this[Be]}get target(){return this[Ve]}get currentTarget(){return this[He]}get eventPhase(){return this[Ue]}get defaultPrevented(){return this[We]}get timeStamp(){return this[Ke]}get cancelBubble(){return this[qe]}set cancelBubble(e){e&&this.stopPropagation()}get returnValue(){return!this[We]}set returnValue(e){e||this.preventDefault()}get srcElement(){return this[Ve]}static NONE=0;static CAPTURING_PHASE=1;static AT_TARGET=2;static BUBBLING_PHASE=3;get[Symbol.toStringTag](){return`Event`}constructor(e,t){this[Le]=e,this[Re]=t?.bubbles??!1,this[ze]=t?.cancelable??!1,this[Be]=t?.composed??!1,this[Ke]=Date.now(),Object.defineProperty(this,"isTrusted",{get:()=>this[Ge],enumerable:!0,configurable:!1})}composedPath(){return this[He]?[this[He]]:[]}preventDefault(){this[ze]&&!this[Xe]&&(this[We]=!0)}stopPropagation(){this[qe]=!0}stopImmediatePropagation(){this[qe]=!0,this[Je]=!0}},CustomEvent$1=class extends Event{static{__name(this,`CustomEvent`)}detail;constructor(e,t){super(e,t),this.detail=t?.detail}},MessageEvent=class extends Event{data;origin;lastEventId;source;ports;constructor(e,t){super(e,t),this.data=t?.data??null,this.origin=t?.origin??``,this.lastEventId=t?.lastEventId??``,this.source=t?.source??null,this.ports=t?.ports??[]}get[Symbol.toStringTag](){return`MessageEvent`}},ErrorEvent=class extends Event{message;filename;lineno;colno;error;constructor(e,t){super(e,t),this.message=t?.message??``,this.filename=t?.filename??``,this.lineno=t?.lineno??0,this.colno=t?.colno??0,this.error=t?.error??null}get[Symbol.toStringTag](){return`ErrorEvent`}},CloseEvent=class extends Event{code;reason;wasClean;constructor(e,t){super(e,t),this.code=t?.code??0,this.reason=t?.reason??``,this.wasClean=t?.wasClean??!1}get[Symbol.toStringTag](){return`CloseEvent`}},ProgressEvent$1=class extends Event{static{__name(this,`ProgressEvent`)}lengthComputable;loaded;total;constructor(e,t){super(e,t),this.lengthComputable=t?.lengthComputable??!1,this.loaded=t?.loaded??0,this.total=t?.total??0}get[Symbol.toStringTag](){return`ProgressEvent`}},EventTarget=class{#e=new Map;get[Symbol.toStringTag](){return`EventTarget`}addEventListener(e,t,n){if(t===null)return;let r=typeof n==`boolean`?n:n?.capture??!1,i=typeof n==`object`?n?.once??!1:!1,a=typeof n==`object`?n?.passive??!1:!1,o=this.#e.get(e);o||(o=[],this.#e.set(e,o));for(let e of o)if(e.listener===t&&e.capture===r)return;let s={listener:t,capture:r,once:i,passive:a,removed:!1};o.push(s),typeof n==`object`&&n?.signal&&n.signal.addEventListener(`abort`,()=>{this.removeEventListener(e,t,{capture:r})},{once:!0})}removeEventListener(e,t,n){if(t===null)return;let r=typeof n==`boolean`?n:n?.capture??!1,i=this.#e.get(e);if(!i)return;let a=i.findIndex(e=>e.listener===t&&e.capture===r);a!==-1&&(i[a].removed=!0,i.splice(a,1),i.length===0&&this.#e.delete(e))}dispatchEvent(e){let t=e;if(t[Ye])throw new Ie(`The event is already being dispatched.`,`InvalidStateError`);t[Ye]=!0,t[Ve]=this,t[He]=this,t[Ue]=Event.AT_TARGET;try{let n=this.#e.get(e.type);if(n){let r=[...n];for(let n of r)if(!n.removed){if(t[Je]||t[qe])break;n.once&&this.removeEventListener(e.type,n.listener,{capture:n.capture});try{n.passive&&(t[Xe]=!0),typeof n.listener==`function`?n.listener.call(this,e):typeof n.listener.handleEvent==`function`&&n.listener.handleEvent.call(n.listener,e)}catch(e){reportListenerException(e)}finally{t[Xe]=!1}}}}finally{t[Ue]=Event.NONE,t[He]=null,t[Ye]=!1}return!e.defaultPrevented}};function reportListenerException(e){try{let t=globalThis;if(typeof t.reportError==`function`)t.reportError(e);else if(e instanceof Error){let t=`${e.name}: ${e.message}`;A.error(e.stack?`${t}\n${e.stack}`:t)}else A.error(String(e))}catch{}}for(let[e,t]of[[`NONE`,0],[`CAPTURING_PHASE`,1],[`AT_TARGET`,2],[`BUBBLING_PHASE`,3]])Object.defineProperty(Event.prototype,e,{value:t,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(Event,e,{value:t,writable:!1,enumerable:!0,configurable:!1});var UIEvent=class extends Event{detail;view;constructor(e,t){super(e,t),this.detail=t?.detail??0,this.view=null}get[Symbol.toStringTag](){return`UIEvent`}},MouseEvent=class extends UIEvent{altKey;button;buttons;clientX;clientY;ctrlKey;metaKey;movementX;movementY;offsetX;offsetY;screenX;screenY;shiftKey;relatedTarget;get pageX(){return this.clientX}get pageY(){return this.clientY}get x(){return this.clientX}get y(){return this.clientY}constructor(e,t){super(e,t),this.altKey=t?.altKey??!1,this.button=t?.button??0,this.buttons=t?.buttons??0,this.clientX=t?.clientX??0,this.clientY=t?.clientY??0,this.ctrlKey=t?.ctrlKey??!1,this.metaKey=t?.metaKey??!1,this.movementX=t?.movementX??0,this.movementY=t?.movementY??0,this.offsetX=t?.offsetX??0,this.offsetY=t?.offsetY??0,this.screenX=t?.screenX??0,this.screenY=t?.screenY??0,this.shiftKey=t?.shiftKey??!1,this.relatedTarget=t?.relatedTarget??null}getModifierState(e){switch(e){case`Alt`:return this.altKey;case`Control`:return this.ctrlKey;case`Meta`:return this.metaKey;case`Shift`:return this.shiftKey;default:return!1}}get[Symbol.toStringTag](){return`MouseEvent`}},PointerEvent=class extends MouseEvent{pointerId;width;height;pressure;tangentialPressure;tiltX;tiltY;twist;altitudeAngle;azimuthAngle;pointerType;isPrimary;constructor(e,t){super(e,t),this.pointerId=t?.pointerId??0,this.width=t?.width??1,this.height=t?.height??1,this.pressure=t?.pressure??0,this.tangentialPressure=t?.tangentialPressure??0,this.tiltX=t?.tiltX??0,this.tiltY=t?.tiltY??0,this.twist=t?.twist??0,this.altitudeAngle=t?.altitudeAngle??Math.PI/2,this.azimuthAngle=t?.azimuthAngle??0,this.pointerType=t?.pointerType??``,this.isPrimary=t?.isPrimary??!1}getCoalescedEvents(){return[]}getPredictedEvents(){return[]}get[Symbol.toStringTag](){return`PointerEvent`}},KeyboardEvent=class extends UIEvent{altKey;code;ctrlKey;isComposing;key;location;metaKey;repeat;shiftKey;keyCode;which;static DOM_KEY_LOCATION_STANDARD=0;static DOM_KEY_LOCATION_LEFT=1;static DOM_KEY_LOCATION_RIGHT=2;static DOM_KEY_LOCATION_NUMPAD=3;constructor(e,t){super(e,t),this.altKey=t?.altKey??!1,this.code=t?.code??``,this.ctrlKey=t?.ctrlKey??!1,this.isComposing=t?.isComposing??!1,this.key=t?.key??``,this.location=t?.location??0,this.metaKey=t?.metaKey??!1,this.repeat=t?.repeat??!1,this.shiftKey=t?.shiftKey??!1,this.keyCode=t?.keyCode??0,this.which=t?.which??0}getModifierState(e){switch(e){case`Alt`:return this.altKey;case`Control`:return this.ctrlKey;case`Meta`:return this.metaKey;case`Shift`:return this.shiftKey;default:return!1}}get[Symbol.toStringTag](){return`KeyboardEvent`}},WheelEvent=class extends MouseEvent{deltaX;deltaY;deltaZ;deltaMode;static DOM_DELTA_PIXEL=0;static DOM_DELTA_LINE=1;static DOM_DELTA_PAGE=2;constructor(e,t){super(e,t),this.deltaX=t?.deltaX??0,this.deltaY=t?.deltaY??0,this.deltaZ=t?.deltaZ??0,this.deltaMode=t?.deltaMode??0}get[Symbol.toStringTag](){return`WheelEvent`}},FocusEvent=class extends UIEvent{relatedTarget;constructor(e,t){super(e,t),this.relatedTarget=t?.relatedTarget??null}get[Symbol.toStringTag](){return`FocusEvent`}};let Ze,Qe,$e,et,tt;var nt=class Node extends EventTarget{constructor(...e){super(...e),this.ELEMENT_NODE=Pe.ELEMENT_NODE,this.ATTRIBUTE_NODE=Pe.ATTRIBUTE_NODE,this.TEXT_NODE=Pe.TEXT_NODE,this.CDATA_SECTION_NODE=Pe.CDATA_SECTION_NODE,this.PROCESSING_INSTRUCTION_NODE=Pe.PROCESSING_INSTRUCTION_NODE,this.COMMENT_NODE=Pe.COMMENT_NODE,this.DOCUMENT_NODE=Pe.DOCUMENT_NODE,this.DOCUMENT_TYPE_NODE=Pe.DOCUMENT_TYPE_NODE,this.DOCUMENT_FRAGMENT_NODE=Pe.DOCUMENT_FRAGMENT_NODE,this[Ze]=Pe.ELEMENT_NODE,this[Qe]=null,this[$e]=[],this[et]=[],this[tt]=!1}static{this.ELEMENT_NODE=Pe.ELEMENT_NODE}static{this.ATTRIBUTE_NODE=Pe.ATTRIBUTE_NODE}static{this.TEXT_NODE=Pe.TEXT_NODE}static{this.CDATA_SECTION_NODE=Pe.CDATA_SECTION_NODE}static{this.PROCESSING_INSTRUCTION_NODE=Pe.PROCESSING_INSTRUCTION_NODE}static{this.COMMENT_NODE=Pe.COMMENT_NODE}static{this.DOCUMENT_NODE=Pe.DOCUMENT_NODE}static{this.DOCUMENT_TYPE_NODE=Pe.DOCUMENT_TYPE_NODE}static{this.DOCUMENT_FRAGMENT_NODE=Pe.DOCUMENT_FRAGMENT_NODE}static{this.DOCUMENT_POSITION_DISCONNECTED=1}static{this.DOCUMENT_POSITION_PRECEDING=2}static{this.DOCUMENT_POSITION_FOLLOWING=4}static{this.DOCUMENT_POSITION_CONTAINS=8}static{this.DOCUMENT_POSITION_CONTAINED_BY=16}static{this.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC=32}get nodeType(){return this[Ce]}get nodeName(){return``}get parentNode(){return this[we]}get parentElement(){let e=this[we];return e&&e[Ce]===Pe.ELEMENT_NODE?e:null}get childNodes(){return new NodeList(this[M])}get firstChild(){return this[M][0]??null}get lastChild(){let e=this[M];return e[e.length-1]??null}get previousSibling(){let e=this[we];if(!e)return null;let t=e[M],n=t.indexOf(this);return n>0?t[n-1]:null}get nextSibling(){let e=this[we];if(!e)return null;let t=e[M],n=t.indexOf(this);return n!==-1&&n<t.length-1?t[n+1]:null}get textContent(){return null}set textContent(e){}get nodeValue(){return null}set nodeValue(e){}get ownerDocument(){let e=this;for(;e[we];)e=e[we];let t=globalThis.document;return e===t?t:null}get isConnected(){return this[Ee]}hasChildNodes(){return this[M].length>0}contains(e){if(e===null)return!1;if(e===this)return!0;let t=e;for(;t;){if(t===this)return!0;t=t[we]}return!1}getRootNode(){let e=this;for(;e[we];)e=e[we];return e}appendChild(e){return e[we]&&e[we].removeChild(e),e[we]=this,this[M].push(e),e[Ce]===Pe.ELEMENT_NODE&&this[Te].push(e),e}removeChild(e){let t=this[M],n=t.indexOf(e);if(n===-1)throw new DOMException(`Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.`,`NotFoundError`);if(t.splice(n,1),e[we]=null,e[Ce]===Pe.ELEMENT_NODE){let t=this[Te].indexOf(e);t!==-1&&this[Te].splice(t,1)}return e}insertBefore(e,t){if(t===null)return this.appendChild(e);let n=this[M],r=n.indexOf(t);if(r===-1)throw new DOMException(`Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.`,`NotFoundError`);if(e[we]&&e[we].removeChild(e),e[we]=this,n.splice(r,0,e),e[Ce]===Pe.ELEMENT_NODE){let t=this[Te],i=t.length;for(let a=r;a<n.length;a++)if(n[a][Ce]===Pe.ELEMENT_NODE&&n[a]!==e){i=t.indexOf(n[a]);break}t.splice(i,0,e)}return e}replaceChild(e,t){return this.insertBefore(e,t),this.removeChild(t),t}cloneNode(e=!1){let t=new this.constructor;if(t[Ce]=this[Ce],e)for(let e of this[M])t.appendChild(e.cloneNode(!0));return t}dispatchEvent(e){let t=super.dispatchEvent(e);if(e.bubbles&&!e.cancelBubble){let t=this[we];for(;t&&(Object.getPrototypeOf(Node.prototype).dispatchEvent.call(t,e),!e.cancelBubble);)t=t[we]}return t}get[(Ze=Ce,Qe=we,$e=M,et=Te,tt=Ee,Symbol.toStringTag)](){return`Node`}};const rt={html:`http://www.w3.org/1999/xhtml`,svg:`http://www.w3.org/2000/svg`,mathML:`http://www.w3.org/1998/Math/MathML`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};var Attr=class{constructor(e,t,n=null,r=null,i=null){this.specified=!0,this[je]=e,this[Me]=t,this[Ne]=i,this.namespaceURI=n,this.prefix=r;let a=e.indexOf(`:`);this.localName=a===-1?e:e.slice(a+1)}get name(){return this[je]}get value(){return this[Me]}set value(e){this[Me]=e}get ownerElement(){return this[Ne]}get[Symbol.toStringTag](){return`Attr`}},NamedNodeMap=class{constructor(e){this._items=[],this._ownerElement=e}get length(){return this._items.length}item(e){return this._items[e]??null}getNamedItem(e){return this._findByName(e)}getNamedItemNS(e,t){let n=e===``?null:e;for(let e of this._items)if(e.namespaceURI===n&&e.localName===t)return e;return null}setNamedItem(e){return this._setAttr(e)}setNamedItemNS(e){return this._setAttr(e)}removeNamedItem(e){let t=this._findByName(e);if(!t)throw new DOMException(`Failed to execute 'removeNamedItem' on 'NamedNodeMap': No item with name '${e}' was found.`,`NotFoundError`);return this._removeAttr(t),t}removeNamedItemNS(e,t){let n=this.getNamedItemNS(e,t);if(!n)throw new DOMException(`Failed to execute 'removeNamedItemNS' on 'NamedNodeMap': No item with namespace '${e}' and localName '${t}' was found.`,`NotFoundError`);return this._removeAttr(n),n}[Symbol.iterator](){return this._items[Symbol.iterator]()}get[Symbol.toStringTag](){return`NamedNodeMap`}_setNamedItem(e,t,n=null,r=null){let i=n===null?this._findByName(e):this.getNamedItemNS(n,e.includes(`:`)?e.split(`:`)[1]:e);if(i)i.value=t;else{let i=new Attr(e,t,n,r,this._ownerElement);this._items.push(i)}}_removeNamedItem(e){let t=this._findByName(e);return t?(this._removeAttr(t),!0):!1}_removeNamedItemNS(e,t){let n=this.getNamedItemNS(e,t);return n?(this._removeAttr(n),!0):!1}_findByName(e){let t=this._ownerElement.namespaceURI===rt.html,n=t?e.toLowerCase():e;for(let e of this._items)if((t?e.name.toLowerCase():e.name)===n)return e;return null}_setAttr(e){let t=null;if(t=e.namespaceURI===null?this._findByName(e.name):this.getNamedItemNS(e.namespaceURI,e.localName),t){let n=new Attr(t.name,t.value,t.namespaceURI,t.prefix,t.ownerElement);return t.value=e.value,n}return this._items.push(e),null}_removeAttr(e){let t=this._items.indexOf(e);t!==-1&&this._items.splice(t,1)}};let it,at,ot,st,ct,lt;var Element=class extends nt{constructor(){super(),this[it]=``,this[at]=``,this[ot]=rt.html,this[st]=null,this[ct]=new NamedNodeMap(this),this[lt]=new Map,this._resizeSubscribers=null,this._allocatedClientWidth=0,this._allocatedClientHeight=0,this._pointerCaptures=new Set,this[Ce]=Pe.ELEMENT_NODE}get tagName(){return this[N]}get localName(){return this[De]}get namespaceURI(){return this[Oe]}get prefix(){return this[ke]}get nodeName(){return this[N]}get attributes(){return this[Ae]}get id(){return this.getAttribute(`id`)??``}set id(e){this.setAttribute(`id`,e)}get className(){return this.getAttribute(`class`)??``}set className(e){this.setAttribute(`class`,e)}get children(){return this[Te]}get childElementCount(){return this[Te].length}get firstElementChild(){return this[Te][0]??null}get lastElementChild(){let e=this[Te];return e[e.length-1]??null}get previousElementSibling(){let e=this[we];if(!e)return null;let t=e[Te],n=t.indexOf(this);return n>0?t[n-1]:null}get nextElementSibling(){let e=this[we];if(!e)return null;let t=e[Te],n=t.indexOf(this);return n!==-1&&n<t.length-1?t[n+1]:null}get textContent(){let e=``;for(let t of this[M])t.textContent!==null&&(e+=t.textContent);return e}set textContent(e){let t=this[M];for(;t.length>0;)this.removeChild(t[0])}getAttribute(e){let t=this[Ae].getNamedItem(e);return t?t.value:null}getAttributeNS(e,t){let n=this[Ae].getNamedItemNS(e,t);return n?n.value:null}setAttribute(e,t){this[Ae]._setNamedItem(e,String(t))}setAttributeNS(e,t,n){let r=e===``?null:e,i=t.split(`:`),a=i.length>1?i[0]:null;this[Ae]._setNamedItem(t,String(n),r,a)}removeAttribute(e){this[Ae]._removeNamedItem(e)}removeAttributeNS(e,t){let n=e===``?null:e;this[Ae]._removeNamedItemNS(n,t)}hasAttribute(e){return this[Ae].getNamedItem(e)!==null}hasAttributeNS(e,t){return this[Ae].getNamedItemNS(e,t)!==null}getAttributeNode(e){return this[Ae].getNamedItem(e)}setAttributeNode(e){return this[Ae].setNamedItem(e)}removeAttributeNode(e){let t=this[Ae].getNamedItem(e.name);if(!t)throw new DOMException(`Failed to execute 'removeAttributeNode' on 'Element': The attribute is not owned by this element.`,`NotFoundError`);return this[Ae].removeNamedItem(t.name),t}toggleAttribute(e,t){return t===void 0?this.hasAttribute(e)?(this.removeAttribute(e),!1):(this.setAttribute(e,``),!0):t?(this.setAttribute(e,``),!0):(this.removeAttribute(e),!1)}hasAttributes(){return this[Ae].length>0}dispatchEvent(e){let t=super.dispatchEvent(e),n=this[P].get(`on`+e.type);return typeof n==`function`&&n.call(this,e),t}querySelector(e){return null}querySelectorAll(e){return[]}matches(e){return!1}closest(e){return null}getElementsByTagName(e){let t=[],n=e.toUpperCase(),walk=r=>{for(let i of r[M])if(i[Ce]===Pe.ELEMENT_NODE){let r=i;(e===`*`||r[N]===n)&&t.push(r),walk(r)}};return walk(this),t}getElementsByClassName(e){let t=[],n=e.split(/\s+/).filter(Boolean),walk=e=>{for(let r of e[M])if(r[Ce]===Pe.ELEMENT_NODE){let e=r,i=e.className.split(/\s+/);n.every(e=>i.includes(e))&&t.push(e),walk(e)}};return walk(this),t}cloneNode(e=!1){let t=super.cloneNode(!1);t[N]=this[N],t[De]=this[De],t[Oe]=this[Oe],t[ke]=this[ke];for(let e of this[Ae])t.setAttributeNS(e.namespaceURI,e.name,e.value);if(e)for(let e of this[M])t.appendChild(e.cloneNode(!0));return t}_onResize(e){let t=this._resizeSubscribers??=new Set;return t.add(e),()=>{t.delete(e),t.size===0&&(this._resizeSubscribers=null)}}_fireResizeSubscribers(e,t){let n=this._resizeSubscribers;if(!(!n||n.size===0))for(let r of[...n])try{r(e,t)}catch(e){A.error(`ResizeObserver subscriber threw:`,e)}}setPointerCapture(e){this._pointerCaptures.add(e)}releasePointerCapture(e){this._pointerCaptures.delete(e)}hasPointerCapture(e){return this._pointerCaptures.has(e)}get[(it=N,at=De,ot=Oe,st=ke,ct=Ae,lt=P,Symbol.toStringTag)](){return`Element`}},CSSStyleDeclaration=class{constructor(){this._cssText=``}get cssText(){return this._cssText}set cssText(e){this._cssText=e;for(let t of e.split(`;`)){let e=t.indexOf(`:`);if(e===-1)continue;let n=t.slice(0,e).trim(),r=t.slice(e+1).trim();if(!n)continue;let i=n.replace(/-([a-z])/g,(e,t)=>t.toUpperCase());this[i]=r}}setProperty(e,t,n){this[e]=t}getPropertyValue(e){let t=this[e];return typeof t==`string`?t:``}removeProperty(e){let t=this[e];return delete this[e],typeof t==`string`?t:``}getPropertyPriority(e){return``}},HTMLElement=class extends Element{constructor(...e){super(...e),this.style=new CSSStyleDeclaration}get dataset(){let e=this;return new Proxy({},{get(t,n){if(typeof n!=`string`)return;let r=`data-`+n.replace(/[A-Z]/g,e=>`-`+e.toLowerCase());return e.getAttribute(r)??void 0},set(t,n,r){if(typeof n!=`string`)return!1;let i=`data-`+n.replace(/[A-Z]/g,e=>`-`+e.toLowerCase());return e.setAttribute(i,String(r)),!0},deleteProperty(t,n){if(typeof n!=`string`)return!1;let r=`data-`+n.replace(/[A-Z]/g,e=>`-`+e.toLowerCase());return e.removeAttribute(r),!0},has(t,n){if(typeof n!=`string`)return!1;let r=`data-`+n.replace(/[A-Z]/g,e=>`-`+e.toLowerCase());return e.hasAttribute(r)}})}get title(){return this.getAttribute(`title`)??``}set title(e){this.setAttribute(`title`,e)}get lang(){return this.getAttribute(`lang`)??``}set lang(e){this.setAttribute(`lang`,e)}get dir(){return this.getAttribute(`dir`)??``}set dir(e){this.setAttribute(`dir`,e)}get accessKey(){return this.getAttribute(`accesskey`)??``}set accessKey(e){this.setAttribute(`accesskey`,e)}get accessKeyLabel(){return this.getAttribute(`accesskey`)??``}get hidden(){return this.hasAttribute(`hidden`)}set hidden(e){e?this.setAttribute(`hidden`,``):this.removeAttribute(`hidden`)}get draggable(){return this.getAttribute(`draggable`)===`true`}set draggable(e){this.setAttribute(`draggable`,String(e))}get spellcheck(){let e=this.getAttribute(`spellcheck`);return e===`false`?!1:e!==null}set spellcheck(e){this.setAttribute(`spellcheck`,String(e))}get translate(){return this.getAttribute(`translate`)!==`no`}set translate(e){this.setAttribute(`translate`,e?`yes`:`no`)}get tabIndex(){let e=this.getAttribute(`tabindex`);return e===null?-1:Number(e)}set tabIndex(e){this.setAttribute(`tabindex`,String(e))}get contentEditable(){let e=this.getAttribute(`contenteditable`);return e===``||e===`true`?`true`:e===`false`?`false`:`inherit`}set contentEditable(e){e===`inherit`?this.removeAttribute(`contenteditable`):this.setAttribute(`contenteditable`,e)}get isContentEditable(){return this.contentEditable===`true`}get offsetHeight(){return this._allocatedClientHeight}get offsetWidth(){return this._allocatedClientWidth}get offsetLeft(){return 0}get offsetTop(){return 0}get offsetParent(){return null}get clientHeight(){return this._allocatedClientHeight}get clientWidth(){return this._allocatedClientWidth}get clientLeft(){return 0}get clientTop(){return 0}get scrollHeight(){return this._allocatedClientHeight}get scrollWidth(){return this._allocatedClientWidth}get scrollTop(){return 0}set scrollTop(e){}get scrollLeft(){return 0}set scrollLeft(e){}getBoundingClientRect(){let e=this.clientWidth,t=this.clientHeight;return{x:0,y:0,top:0,left:0,right:e,bottom:t,width:e,height:t,toJSON(){return this}}}click(){this.dispatchEvent(new Event(`click`,{bubbles:!0,cancelable:!0}))}blur(){this.dispatchEvent(new Event(`blur`))}focus(){this.dispatchEvent(new Event(`focus`))}get onclick(){return this[P].get(`onclick`)??null}set onclick(e){this[P].set(`onclick`,e)}get ondblclick(){return this[P].get(`ondblclick`)??null}set ondblclick(e){this[P].set(`ondblclick`,e)}get onload(){return this[P].get(`onload`)??null}set onload(e){this[P].set(`onload`,e)}get onerror(){return this[P].get(`onerror`)??null}set onerror(e){this[P].set(`onerror`,e)}get onabort(){return this[P].get(`onabort`)??null}set onabort(e){this[P].set(`onabort`,e)}get onfocus(){return this[P].get(`onfocus`)??null}set onfocus(e){this[P].set(`onfocus`,e)}get onblur(){return this[P].get(`onblur`)??null}set onblur(e){this[P].set(`onblur`,e)}get onchange(){return this[P].get(`onchange`)??null}set onchange(e){this[P].set(`onchange`,e)}get oninput(){return this[P].get(`oninput`)??null}set oninput(e){this[P].set(`oninput`,e)}get onsubmit(){return this[P].get(`onsubmit`)??null}get onreset(){return this[P].get(`onreset`)??null}set onreset(e){this[P].set(`onreset`,e)}get onscroll(){return this[P].get(`onscroll`)??null}set onscroll(e){this[P].set(`onscroll`,e)}get onresize(){return this[P].get(`onresize`)??null}set onresize(e){this[P].set(`onresize`,e)}get onmousedown(){return this[P].get(`onmousedown`)??null}set onmousedown(e){this[P].set(`onmousedown`,e)}get onmouseup(){return this[P].get(`onmouseup`)??null}set onmouseup(e){this[P].set(`onmouseup`,e)}get onmousemove(){return this[P].get(`onmousemove`)??null}set onmousemove(e){this[P].set(`onmousemove`,e)}get onmouseover(){return this[P].get(`onmouseover`)??null}set onmouseover(e){this[P].set(`onmouseover`,e)}get onmouseout(){return this[P].get(`onmouseout`)??null}set onmouseout(e){this[P].set(`onmouseout`,e)}get onmouseenter(){return this[P].get(`onmouseenter`)??null}set onmouseenter(e){this[P].set(`onmouseenter`,e)}get onmouseleave(){return this[P].get(`onmouseleave`)??null}set onmouseleave(e){this[P].set(`onmouseleave`,e)}get oncontextmenu(){return this[P].get(`oncontextmenu`)??null}set oncontextmenu(e){this[P].set(`oncontextmenu`,e)}get onwheel(){return this[P].get(`onwheel`)??null}set onwheel(e){this[P].set(`onwheel`,e)}get onkeydown(){return this[P].get(`onkeydown`)??null}set onkeydown(e){this[P].set(`onkeydown`,e)}get onkeyup(){return this[P].get(`onkeyup`)??null}set onkeyup(e){this[P].set(`onkeyup`,e)}get ontouchstart(){return this[P].get(`ontouchstart`)??null}set ontouchstart(e){this[P].set(`ontouchstart`,e)}get ontouchend(){return this[P].get(`ontouchend`)??null}set ontouchend(e){this[P].set(`ontouchend`,e)}get ontouchmove(){return this[P].get(`ontouchmove`)??null}set ontouchmove(e){this[P].set(`ontouchmove`,e)}get onpointerdown(){return this[P].get(`onpointerdown`)??null}set onpointerdown(e){this[P].set(`onpointerdown`,e)}get onpointerup(){return this[P].get(`onpointerup`)??null}set onpointerup(e){this[P].set(`onpointerup`,e)}get onpointermove(){return this[P].get(`onpointermove`)??null}set onpointermove(e){this[P].set(`onpointermove`,e)}cloneNode(e=!1){return super.cloneNode(e)}get[Symbol.toStringTag](){return`HTMLElement`}},ut=class HTMLCanvasElement extends HTMLElement{constructor(...e){super(...e),this.oncontextlost=null,this.oncontextrestored=null,this.onwebglcontextcreationerror=null,this.onwebglcontextlost=null,this.onwebglcontextrestored=null}static{this._contextFactories=new Map}static registerContextFactory(e,t){HTMLCanvasElement._contextFactories.set(e,t)}get width(){let e=this.getAttribute(`width`);return e===null?300:Number(e)}set width(e){this.setAttribute(`width`,String(e))}get height(){let e=this.getAttribute(`height`);return e===null?150:Number(e)}set height(e){this.setAttribute(`height`,String(e))}getContext(e,t){let n=HTMLCanvasElement._contextFactories.get(e);return n?n(this,t):null}toDataURL(e,t){let n=this.getContext(`2d`);return n&&typeof n._toDataURL==`function`?n._toDataURL(e,t):``}toBlob(e,t,n){let r=this.toDataURL(t,n);if(!r){e(null);return}let[i,a]=r.split(`,`),o=i.split(`:`)[1].split(`;`)[0],s=atob(a),c=new Uint8Array(s.length);for(let e=0;e<s.length;e++)c[e]=s.charCodeAt(e);e(new Blob([c],{type:o}))}captureStream(e){return{}}},dt=class DOMMatrix{constructor(e){this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this.m11=1,this.m12=0,this.m13=0,this.m14=0,this.m21=0,this.m22=1,this.m23=0,this.m24=0,this.m31=0,this.m32=0,this.m33=1,this.m34=0,this.m41=0,this.m42=0,this.m43=0,this.m44=1,this.is2D=!0,this.isIdentity=!0,Array.isArray(e)&&(e.length===6?(this.a=this.m11=e[0],this.b=this.m12=e[1],this.c=this.m21=e[2],this.d=this.m22=e[3],this.e=this.m41=e[4],this.f=this.m42=e[5],this.is2D=!0):e.length===16&&(this.m11=e[0],this.m12=e[1],this.m13=e[2],this.m14=e[3],this.m21=e[4],this.m22=e[5],this.m23=e[6],this.m24=e[7],this.m31=e[8],this.m32=e[9],this.m33=e[10],this.m34=e[11],this.m41=e[12],this.m42=e[13],this.m43=e[14],this.m44=e[15],this.a=this.m11,this.b=this.m12,this.c=this.m21,this.d=this.m22,this.e=this.m41,this.f=this.m42,this.is2D=!1),this.isIdentity=this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.e===0&&this.f===0)}multiply(e){let t=this.a*e.a+this.c*e.b,n=this.b*e.a+this.d*e.b,r=this.a*e.c+this.c*e.d,i=this.b*e.c+this.d*e.d,a=this.a*e.e+this.c*e.f+this.e,o=this.b*e.e+this.d*e.f+this.f;return new DOMMatrix([t,n,r,i,a,o])}multiplySelf(e){let t=this.multiply(e);return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.e=t.e,this.f=t.f,this.m11=this.a,this.m12=this.b,this.m21=this.c,this.m22=this.d,this.m41=this.e,this.m42=this.f,this.isIdentity=!1,this}inverse(){let e=this.a*this.d-this.b*this.c;if(e===0)return new DOMMatrix([1,0,0,1,0,0]);let t=1/e;return new DOMMatrix([this.d*t,-this.b*t,-this.c*t,this.a*t,(this.c*this.f-this.d*this.e)*t,(this.b*this.e-this.a*this.f)*t])}translate(e=0,t=0){return this.multiply({a:1,b:0,c:0,d:1,e,f:t})}scale(e=1,t=e){return this.multiply({a:e,b:0,c:0,d:t,e:0,f:0})}};const ft=dt;function defineGlobal(e,t){Object.defineProperty(globalThis,e,{value:t,writable:!0,configurable:!0})}function defineGlobalIfMissing$2(e,t){globalThis[e]===void 0&&defineGlobal(e,t)}__name(defineGlobalIfMissing$2,`defineGlobalIfMissing`),setCanvasPixelBridge({imageFromSurface(e,t,n,r,i){return a.pixbuf_get_from_surface(e,t,n,r,i)},setSourceImage(e,t,n,r){a.cairo_set_source_pixbuf(e,t,n,r)},setSourcePixels(e,t,n,r,i,s){let c=o.Pixbuf.new_from_bytes(t,o.Colorspace.RGB,!0,8,n,r,n*4);a.cairo_set_source_pixbuf(e,c,i,s)}}),defineGlobal(`HTMLCanvasElement`,ut),defineGlobal(`CanvasRenderingContext2D`,CanvasRenderingContext2D),defineGlobal(`DOMMatrix`,dt),defineGlobal(`DOMMatrixReadOnly`,ft);const pt=Symbol.for(`gjsify_canvas2d_context`);ut.registerContextFactory(`2d`,(e,t)=>{let n=e,r=n[pt];if(r)return r;let i=new CanvasRenderingContext2D(e,t);return n[pt]=i,i});function defineGlobalIfMissing$1(e,t){globalThis[e]===void 0&&Object.defineProperty(globalThis,e,{value:t,writable:!0,configurable:!0})}__name(defineGlobalIfMissing$1,`defineGlobalIfMissing`),defineGlobalIfMissing$1(`ImageData`,OurImageData),defineGlobalIfMissing$1(`Path2D`,pe);var CharacterData=class extends nt{constructor(e=``){super(),this[Ce]=Pe.TEXT_NODE,this._data=e}get data(){return this._data}set data(e){this._data=e}get textContent(){return this._data}set textContent(e){this._data=e}get nodeValue(){return this._data}set nodeValue(e){this._data=e}get length(){return this._data.length}appendData(e){this._data+=e}deleteData(e,t){this._data=this._data.substring(0,e)+this._data.substring(e+t)}insertData(e,t){this._data=this._data.substring(0,e)+t+this._data.substring(e)}replaceData(e,t,n){this._data=this._data.substring(0,e)+n+this._data.substring(e+t)}substringData(e,t){return this._data.substring(e,e+t)}cloneNode(e=!1){return new this.constructor(this._data)}get[Symbol.toStringTag](){return`CharacterData`}},mt=class Comment extends CharacterData{constructor(e=``){super(e),this[Ce]=Pe.COMMENT_NODE}get nodeName(){return`#comment`}cloneNode(e=!1){return new Comment(this.data)}get[Symbol.toStringTag](){return`Comment`}},ht=class Text extends CharacterData{constructor(e=``){super(e),this[Ce]=Pe.TEXT_NODE}get nodeName(){return`#text`}get wholeText(){let e=this.data,t=this.previousSibling;for(;t&&t instanceof Text;)e=t.data+e,t=t.previousSibling;let n=this.nextSibling;for(;n&&n instanceof Text;)e+=n.data,n=n.nextSibling;return e}splitText(e){let t=this.data.substring(e);this.data=this.data.substring(0,e);let n=new Text(t);return this.parentNode&&this.parentNode.insertBefore(n,this.nextSibling),n}cloneNode(e=!1){return new Text(this.data)}get[Symbol.toStringTag](){return`Text`}},gt=class DocumentFragment extends nt{constructor(){super(),this[Ce]=Pe.DOCUMENT_FRAGMENT_NODE}get nodeName(){return`#document-fragment`}get children(){return this[Te]}get childElementCount(){return this[Te].length}get firstElementChild(){return this[Te][0]??null}get lastElementChild(){let e=this[Te];return e[e.length-1]??null}get textContent(){let e=``;for(let t of this.childNodes)t.textContent!==null&&(e+=t.textContent);return e}set textContent(e){for(;this.firstChild;)this.removeChild(this.firstChild);e&&this.appendChild(new ht(e))}append(...e){for(let t of e)typeof t==`string`?this.appendChild(new ht(t)):this.appendChild(t)}prepend(...e){let t=this.firstChild;for(let n of e)typeof n==`string`?this.insertBefore(new ht(n),t):this.insertBefore(n,t)}replaceChildren(...e){for(;this.firstChild;)this.removeChild(this.firstChild);this.append(...e)}getElementById(e){for(let t of this.children){if(t.id===e)return t;let n=this._findById(t,e);if(n)return n}return null}_findById(e,t){for(let n of e.children){if(n.id===t)return n;let e=this._findById(n,t);if(e)return e}return null}cloneNode(e=!1){let t=new DocumentFragment;if(e)for(let e of this.childNodes)t.appendChild(e.cloneNode(!0));return t}get[Symbol.toStringTag](){return`DocumentFragment`}},_t=s,vt=c,yt=l,HTMLImageElement$1=class extends HTMLElement{static{__name(this,`HTMLImageElement`)}constructor(){super(),this._complete=!1,this._naturalHeight=0,this._naturalWidth=0,this[N]=`IMG`,this[De]=`img`,this[Oe]=rt.html}get complete(){return this._complete}get naturalHeight(){return this._naturalHeight}get naturalWidth(){return this._naturalWidth}get currentSrc(){return this.src}get x(){return 0}get y(){return 0}get alt(){return this.getAttribute(`alt`)??``}set alt(e){this.setAttribute(`alt`,e)}get crossOrigin(){return this.getAttribute(`crossorigin`)}set crossOrigin(e){e===null?this.removeAttribute(`crossorigin`):this.setAttribute(`crossorigin`,e)}get decoding(){return this.getAttribute(`decoding`)??`auto`}set decoding(e){this.setAttribute(`decoding`,e)}get loading(){let e=this.getAttribute(`loading`);return e===`lazy`||e===`eager`?e:`auto`}set loading(e){this.setAttribute(`loading`,e)}get referrerPolicy(){return this.getAttribute(`referrerpolicy`)??``}set referrerPolicy(e){this.setAttribute(`referrerpolicy`,e)}get sizes(){return this.getAttribute(`sizes`)??``}set sizes(e){this.setAttribute(`sizes`,e)}get src(){return this.getAttribute(`src`)??``}set src(e){this.setAttribute(`src`,e);let t=globalThis.__GJSIFY_DEBUG_IMG===!0;if(e.startsWith(`data:`)){let n=e.indexOf(`,`);if(n===-1){this._complete=!0,this.dispatchEvent(new Event(`error`));return}let r=e.slice(5,n),i=e.slice(n+1),a=r.includes(`;base64`);try{let e;e=a?_t.base64_decode(i):new TextEncoder().encode(decodeURIComponent(i));let n=_t.Bytes.new(e),r=vt.MemoryInputStream.new_from_bytes(n);this._pixbuf=yt.Pixbuf.new_from_stream(r,null),this._naturalWidth=this._pixbuf.get_width(),this._naturalHeight=this._pixbuf.get_height(),this._complete=!0,t&&A.log(`[img] ok data: (${this._naturalWidth}x${this._naturalHeight})`),this.dispatchEvent(new Event(`load`))}catch(e){t&&A.warn(`[img] error data:: ${e instanceof Error?e.message:String(e)}`),this._complete=!0,this.dispatchEvent(new Event(`error`))}return}let n;if(e.startsWith(`file://`))n=_t.filename_from_uri(e)[0];else if(e.startsWith(`http://`)||e.startsWith(`https://`)){this._complete=!0,this.dispatchEvent(new Event(`error`));return}else{let t=_t.path_get_dirname(u.programInvocationName);n=_t.build_filenamev([t,e])}try{t&&A.log(`[img] load ${n}`),this._pixbuf=yt.Pixbuf.new_from_file(n),this._naturalWidth=this._pixbuf.get_width(),this._naturalHeight=this._pixbuf.get_height(),this._complete=!0,t&&A.log(`[img] ok ${n} (${this._naturalWidth}x${this._naturalHeight})`),this.dispatchEvent(new Event(`load`))}catch(e){t&&A.warn(`[img] error ${n}: ${e instanceof Error?e.message:String(e)}`),this._complete=!0,this.dispatchEvent(new Event(`error`))}}get srcset(){return this.getAttribute(`srcset`)??``}set srcset(e){this.setAttribute(`srcset`,e)}get useMap(){return this.getAttribute(`usemap`)??``}set useMap(e){this.setAttribute(`usemap`,e)}get height(){if(this._pixbuf)return this._pixbuf.get_height();let e=this.getAttribute(`height`);return e===null?0:Number(e)}set height(e){this.setAttribute(`height`,String(e))}get width(){if(this._pixbuf)return this._pixbuf.get_width();let e=this.getAttribute(`width`);return e===null?0:Number(e)}set width(e){this.setAttribute(`width`,String(e))}get isMap(){return this.hasAttribute(`ismap`)}set isMap(e){e?this.setAttribute(`ismap`,``):this.removeAttribute(`ismap`)}decode(){return Promise.resolve()}cloneNode(e=!1){return super.cloneNode(e)}getImageData(){if(!this._pixbuf)return null;let e=this._pixbuf.get_has_alpha()?this._pixbuf:this._pixbuf.add_alpha(!1,0,0,0)??this._pixbuf;return{colorSpace:`srgb`,data:new Uint8ClampedArray(e.get_pixels()),height:e.get_height(),width:e.get_width()}}isPixbuf(){return!!this._pixbuf}get[Symbol.toStringTag](){return`HTMLImageElement`}},HTMLMediaElement=class extends HTMLElement{constructor(...e){super(...e),this._src=``,this._srcObject=null,this.currentTime=0,this.duration=NaN,this.paused=!0,this.ended=!1,this.volume=1,this.muted=!1,this.defaultMuted=!1,this.loop=!1,this.autoplay=!1,this.preload=``,this.playbackRate=1,this.defaultPlaybackRate=1,this.readyState=0,this.networkState=0}get buffered(){return{length:0,start:()=>0,end:()=>0}}get seekable(){return{length:0,start:()=>0,end:()=>0}}get played(){return{length:0,start:()=>0,end:()=>0}}get src(){return this._src}set src(e){this._src=e,this._srcObject=null,this.dispatchEvent(new Event(`srcchange`))}get srcObject(){return this._srcObject}set srcObject(e){this._srcObject=e,this._src=``,this.dispatchEvent(new Event(`srcobjectchange`))}play(){return this.paused=!1,this.ended=!1,this.dispatchEvent(new Event(`play`)),Promise.resolve()}pause(){this.paused=!0,this.dispatchEvent(new Event(`pause`))}load(){this.readyState=0,this.networkState=2,this.dispatchEvent(new Event(`loadstart`))}canPlayType(e){return``}static{this.HAVE_NOTHING=0}static{this.HAVE_METADATA=1}static{this.HAVE_CURRENT_DATA=2}static{this.HAVE_FUTURE_DATA=3}static{this.HAVE_ENOUGH_DATA=4}static{this.NETWORK_EMPTY=0}static{this.NETWORK_IDLE=1}static{this.NETWORK_LOADING=2}static{this.NETWORK_NO_SOURCE=3}get[Symbol.toStringTag](){return`HTMLMediaElement`}};const bt=1e9;function secondsToGstTime(e){return BigInt(Math.round(e*bt))}function gstTimeToSeconds(e){return Number(e)/bt}var HTMLVideoElement$1=class extends HTMLMediaElement{static{__name(this,`HTMLVideoElement`)}constructor(){super(),this._pipeline=null,this._videoWidth=0,this._videoHeight=0,this.poster=``,this[N]=`VIDEO`,this[De]=`video`,this[Oe]=rt.html;let e=this;Object.defineProperty(this,"paused",{get(){if(!e._pipeline)return!0;let[,t]=e._pipeline.get_state(0n);return t!==4},configurable:!0,enumerable:!0}),Object.defineProperty(this,"currentTime",{get(){if(!e._pipeline)return 0;let[t,n]=e._pipeline.query_position(3);return t?gstTimeToSeconds(n):0},set(t){e._pipeline?.seek(1,3,5,1,secondsToGstTime(t),0,-1n)},configurable:!0,enumerable:!0}),Object.defineProperty(this,"duration",{get(){if(!e._pipeline)return NaN;let[t,n]=e._pipeline.query_duration(3);return t&&Number(n)>0?gstTimeToSeconds(n):NaN},configurable:!0,enumerable:!0}),Object.defineProperty(this,"volume",{get(){return e._playbin()?.volume??1},set(t){let n=e._playbin();n&&(n.volume=Math.max(0,Math.min(1,t)))},configurable:!0,enumerable:!0}),Object.defineProperty(this,"muted",{get(){return e._playbin()?.mute??!1},set(t){let n=e._playbin();n&&(n.mute=t)},configurable:!0,enumerable:!0})}async play(){this._pipeline?.set_state(4),this.dispatchEvent(new Event(`play`)),this.dispatchEvent(new Event(`playing`))}pause(){this._pipeline?.set_state(3),this.dispatchEvent(new Event(`pause`))}get videoWidth(){return this._videoWidth}set videoWidth(e){this._videoWidth=e}get videoHeight(){return this._videoHeight}set videoHeight(e){this._videoHeight=e}get[Symbol.toStringTag](){return`HTMLVideoElement`}_playbin(){return this._pipeline?.get_by_name(`playbin`)??null}};const xt=new class Document extends nt{static{this._elementFactories=new Map}constructor(){super(),this.body=new HTMLElement,this.head=new HTMLElement,this.documentElement=new HTMLElement,this.appendChild(this.documentElement),this.documentElement.appendChild(this.body)}static registerElementFactory(e,t){Document._elementFactories.set(e.toLowerCase(),t)}createElementNS(e,t){let n=t.toLowerCase();switch(n){case`img`:return new HTMLImageElement$1;case`video`:return new HTMLVideoElement$1;case`canvas`:return new ut;default:{let e=Document._elementFactories.get(n);return e?e():new HTMLElement}}}createElement(e){return this.createElementNS(`http://www.w3.org/1999/xhtml`,e)}createTextNode(e){return new ht(e)}createComment(e){return new mt(e)}createDocumentFragment(){return new gt}createEvent(e){return new Event(e)}getElementById(e){return this._findById(this.body,e)}_findById(e,t){if(e.id===t)return e;for(let n of e.children){let e=this._findById(n,t);if(e)return e}return null}get[Symbol.toStringTag](){return`Document`}};var DOMTokenList=class{constructor(e,t){this._ownerElement=e,this._attributeName=t}_getTokens(){let e=this._ownerElement.getAttribute(this._attributeName);return e?e.split(/\s+/).filter(e=>e.length>0):[]}_setTokens(e){let t=e.join(` `);t?this._ownerElement.setAttribute(this._attributeName,t):this._ownerElement.removeAttribute(this._attributeName)}get length(){return this._getTokens().length}get value(){return this._ownerElement.getAttribute(this._attributeName)??``}set value(e){e?this._ownerElement.setAttribute(this._attributeName,e):this._ownerElement.removeAttribute(this._attributeName)}item(e){let t=this._getTokens();return e>=0&&e<t.length?t[e]:null}contains(e){return this._getTokens().includes(e)}add(...e){let t=this._getTokens();for(let n of e)n&&!t.includes(n)&&t.push(n);this._setTokens(t)}remove(...e){let t=this._getTokens().filter(t=>!e.includes(t));this._setTokens(t)}toggle(e,t){let n=this.contains(e);return t===void 0?n?(this.remove(e),!1):(this.add(e),!0):t?(this.add(e),!0):(this.remove(e),!1)}replace(e,t){let n=this._getTokens(),r=n.indexOf(e);return r===-1?!1:(n[r]=t,this._setTokens(n),!0)}supports(e){return!0}forEach(e){let t=this._getTokens();for(let n=0;n<t.length;n++)e(t[n],n,this)}keys(){return this._getTokens().keys()}values(){return this._getTokens().values()}entries(){return this._getTokens().entries()}[Symbol.iterator](){return this._getTokens().values()}toString(){return this.value}get[Symbol.toStringTag](){return`DOMTokenList`}};function installWindowEventBus(e){if(e.__gjsify_globalEventTarget)return e.__gjsify_globalEventTarget;let t=new EventTarget,n=typeof e.addEventListener==`function`?e.addEventListener.bind(e):null,r=typeof e.removeEventListener==`function`?e.removeEventListener.bind(e):null;e.__gjsify_globalEventTarget=t;let define=(t,n)=>Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0});return define(`addEventListener`,(e,r,i)=>{t.addEventListener(e,r,i),n?.(e,r,i)}),define(`removeEventListener`,(e,n,i)=>{t.removeEventListener(e,n,i),r?.(e,n,i)}),define(`dispatchEvent`,e=>t.dispatchEvent(e)),t}defineGlobal(`Text`,ht),defineGlobal(`Comment`,mt),defineGlobal(`DocumentFragment`,gt),defineGlobal(`DOMTokenList`,DOMTokenList),defineGlobal(`document`,xt),defineGlobalIfMissing$2(`self`,globalThis);var Window=class{static[Symbol.hasInstance](e){return e===globalThis}};defineGlobalIfMissing$2(`Window`,Window),defineGlobalIfMissing$2(`window`,globalThis),defineGlobalIfMissing$2(`focus`,()=>{}),defineGlobalIfMissing$2(`blur`,()=>{}),installWindowEventBus(globalThis),defineGlobalIfMissing$2(`devicePixelRatio`,1),defineGlobalIfMissing$2(`scrollX`,0),defineGlobalIfMissing$2(`scrollY`,0),defineGlobalIfMissing$2(`pageXOffset`,0),defineGlobalIfMissing$2(`pageYOffset`,0),defineGlobalIfMissing$2(`alert`,(...e)=>A.error(`alert:`,...e)),globalThis.top===void 0&&Object.defineProperty(globalThis,"top",{get:()=>globalThis,configurable:!0});var Image=class extends HTMLImageElement$1{constructor(e=null,t=null){super(),e!==null&&(this.width=e),t!==null&&(this.height=t)}};defineGlobal(`HTMLImageElement`,HTMLImageElement$1),defineGlobal(`Image`,Image),globalThis.navigator===void 0&&(globalThis.navigator={});const St=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,Ct=new Uint8Array(256);for(let e=0;e<64;e++)Ct[St.charCodeAt(e)]=e;function btoaPolyfill(e){if(typeof globalThis.btoa==`function`)return globalThis.btoa(e);let t=``,n=0;for(;n+2<e.length;n+=3){let r=e.charCodeAt(n)<<16|e.charCodeAt(n+1)<<8|e.charCodeAt(n+2);t+=St[r>>18&63]+St[r>>12&63]+St[r>>6&63]+St[r&63]}if(n+1===e.length){let r=e.charCodeAt(n)<<16;t+=St[r>>18&63]+St[r>>12&63]+`==`}else if(n+2===e.length){let r=e.charCodeAt(n)<<16|e.charCodeAt(n+1)<<8;t+=St[r>>18&63]+St[r>>12&63]+St[r>>6&63]+`=`}return t}function base64Decode(e){let t=e.replace(/[=\s]/g,``),n=new Uint8Array(t.length*3>>2),r=0,i=0,a=0;for(let e=0;e<t.length;e++)r=r<<6|Ct[t.charCodeAt(e)],i+=6,i>=8&&(i-=8,n[a++]=r>>i&255);return n.subarray(0,a)}function base64Encode(e){let t=``,n=e.length;for(let r=0;r<n;r+=3){let i=e[r],a=r+1<n?e[r+1]:0,o=r+2<n?e[r+2]:0;t+=St[i>>2],t+=St[(i&3)<<4|a>>4],t+=r+1<n?St[(a&15)<<2|o>>6]:`=`,t+=r+2<n?St[o&63]:`=`}return t}const wt=[`utf8`,`ascii`,`latin1`,`binary`,`base64`,`base64url`,`hex`,`ucs2`,`utf16le`];function normalizeEncoding(e){if(!e||e===`utf8`||e===`utf-8`)return`utf8`;switch((``+e).toLowerCase().replace(/-/g,``)){case`utf8`:return`utf8`;case`ascii`:return`ascii`;case`latin1`:case`binary`:return`latin1`;case`base64`:return`base64`;case`base64url`:return`base64url`;case`hex`:return`hex`;case`ucs2`:case`utf16le`:return`utf16le`;default:return`utf8`}}function checkEncoding(e){let t=(``+e).toLowerCase().replace(/-/g,``);if(!wt.includes(t))throw TypeError(`Unknown encoding: ${e}`)}let Tt,Et;const textEncoder=()=>Tt??=new TextEncoder,textDecoder=()=>Et??=new TextDecoder;function encodeString(e,t){switch(t){case`utf8`:return textEncoder().encode(e);case`ascii`:{let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&127;return t}case`latin1`:{let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t}case`base64`:return base64Decode(e.replace(/-/g,`+`).replace(/_/g,`/`));case`base64url`:return encodeString(e.replace(/-/g,`+`).replace(/_/g,`/`),`base64`);case`hex`:{let t=e.length>>>1,n=new Uint8Array(t);for(let r=0;r<t;r++){let t=parseInt(e[r*2],16),i=parseInt(e[r*2+1],16);if(Number.isNaN(t)||Number.isNaN(i))break;n[r]=t<<4|i}return n}case`utf16le`:{let t=new Uint8Array(e.length*2);for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t[n*2]=r&255,t[n*2+1]=r>>8&255}return t}default:return textEncoder().encode(e)}}function decodeString(e,t,n,r){let i=n!==void 0||r!==void 0?e.subarray(n??0,r??e.length):e;switch(t){case`utf8`:return textDecoder().decode(i);case`ascii`:{let e=``;for(let t=0;t<i.length;t++)e+=String.fromCharCode(i[t]&127);return e}case`latin1`:{let e=``;for(let t=0;t<i.length;t++)e+=String.fromCharCode(i[t]);return e}case`base64`:{let e=``;for(let t=0;t<i.length;t++)e+=String.fromCharCode(i[t]);return btoaPolyfill(e)}case`base64url`:return decodeString(i,`base64`).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``);case`hex`:{let e=``;for(let t=0;t<i.length;t++)e+=i[t].toString(16).padStart(2,`0`);return e}case`utf16le`:{let e=``;for(let t=0;t+1<i.length;t+=2)e+=String.fromCharCode(i[t]|i[t+1]<<8);return e}default:return textDecoder().decode(i)}}function checkOffset(e,t,n){if(e+t>n)throw RangeError(`Attempt to access memory outside buffer bounds`)}const Dt=typeof SharedArrayBuffer<`u`;var Ot=class Buffer extends Uint8Array{static _isBuffer=!0;static alloc(e,t,n){if(typeof e!=`number`)throw TypeError(`The "size" argument must be of type number. Received type ${typeof e}`);if(e<0)throw RangeError(`The value "${e}" is invalid for option "size"`);let r=new Buffer(e);return t!==void 0&&t!==0&&r.fill(t,0,e,n),r}static allocUnsafe(e){if(typeof e!=`number`)throw TypeError(`The "size" argument must be of type number. Received type ${typeof e}`);return new Buffer(e)}static allocUnsafeSlow(e){return Buffer.allocUnsafe(e)}static from(e,t,n){if(typeof e==`string`){let n=normalizeEncoding(t);if(t&&typeof t==`string`){let e=(``+t).toLowerCase().replace(/-/g,``);[`utf8`,`ascii`,`latin1`,`binary`,`base64`,`base64url`,`hex`,`ucs2`,`utf16le`,``].includes(e)||checkEncoding(t)}let r=encodeString(e,n);return new Buffer(r.buffer,r.byteOffset,r.byteLength)}if(ArrayBuffer.isView(e)){let t=new Buffer(e.buffer,e.byteOffset,e.byteLength),n=new Buffer(t.length);return n.set(t),n}if(e instanceof ArrayBuffer){let r=t||0,i=n===void 0?e.byteLength-r:n;return new Buffer(e,r,i)}if(Dt&&e instanceof SharedArrayBuffer){let r=t||0,i=n===void 0?e.byteLength-r:n;return new Buffer(new Uint8Array(e,r,i))}if(typeof e==`object`&&e&&typeof e.viewBytes==`function`&&typeof e.byteLength==`number`&&e.constructor?.name===`SharedBuffer`){let r=e,i=t||0,a=n===void 0?r.byteLength-i:n,o=r.viewBytes(i,a);return new Buffer(o.buffer,o.byteOffset,o.byteLength)}if(Array.isArray(e)){let t=new Buffer(e.length);for(let n=0;n<e.length;n++)t[n]=e[n]&255;return t}throw TypeError(`The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array`)}static isBuffer(e){return e instanceof Buffer}static isEncoding(e){if(typeof e!=`string`)return!1;let t=e.toLowerCase().replace(/-/g,``);return[`utf8`,`ascii`,`latin1`,`binary`,`base64`,`base64url`,`hex`,`ucs2`,`utf16le`].includes(t)}static byteLength(e,t){if(typeof e!=`string`){if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer||Dt&&e instanceof SharedArrayBuffer)return e.byteLength;throw TypeError(`The "string" argument must be one of type string, Buffer, or ArrayBuffer`)}switch(normalizeEncoding(t)){case`utf8`:return new TextEncoder().encode(e).byteLength;case`ascii`:case`latin1`:return e.length;case`base64`:case`base64url`:{let t=e.length;for(;t>0&&(e[t-1]===`=`||e[t-1]===` `);)t--;return t*3>>>2}case`hex`:return e.length>>>1;case`utf16le`:return e.length*2;default:return new TextEncoder().encode(e).byteLength}}static compare(e,t){if(!(e instanceof Uint8Array)||!(t instanceof Uint8Array))throw TypeError(`Arguments must be Buffers or Uint8Arrays`);let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){if(e[r]<t[r])return-1;if(e[r]>t[r])return 1}return e.length<t.length?-1:+(e.length>t.length)}static concat(e,t){if(e.length===0)return Buffer.alloc(0);if(t===void 0){t=0;for(let n=0;n<e.length;n++)t+=e[n].length}let n=Buffer.alloc(t),r=0;for(let i=0;i<e.length;i++){let a=e[i],o=Math.min(a.length,t-r);o<=0||(n.set(a.subarray(0,o),r),r+=o)}return n}static poolSize=65536;toString(e,t,n){let r=normalizeEncoding(e);return decodeString(this,r,t,n)}toJSON(){return{type:`Buffer`,data:Array.from(this)}}equals(e){if(!(e instanceof Uint8Array))throw TypeError(`Argument must be a Buffer or Uint8Array`);if(this.length!==e.length)return!1;for(let t=0;t<this.length;t++)if(this[t]!==e[t])return!1;return!0}compare(e,t,n,r,i){if(!(e instanceof Uint8Array))throw TypeError(`Argument must be a Buffer or Uint8Array`);let a=r!==void 0||i!==void 0?this.subarray(r??0,i??this.length):this,o=t!==void 0||n!==void 0?e.subarray(t??0,n??e.length):e;return Buffer.compare(a,o)}copy(e,t=0,n=0,r){let i=r??this.length,a=Math.min(i-n,e.length-t);return a<=0?0:(e.set(this.subarray(n,n+a),t),a)}slice(e,t){let n=e??0,r=t??this.length,i=super.subarray(n,r);return new Buffer(i.buffer,i.byteOffset,i.byteLength)}subarray(e,t){let n=super.subarray(e,t);return new Buffer(n.buffer,n.byteOffset,n.byteLength)}write(e,t,n,r){t??=0;let i=encodeString(e,normalizeEncoding(r||(typeof n==`string`?n:void 0))),a=n!==void 0&&typeof n==`number`?Math.min(n,this.length-t):this.length-t,o=Math.min(i.length,a);return this.set(i.subarray(0,o),t),o}fill(e,t,n,r){let i=t??0,a=n??this.length;if(typeof e==`number`)super.fill(e&255,i,a);else if(typeof e==`string`){let t=encodeString(e,normalizeEncoding(r));if(t.length===0)super.fill(0,i,a);else if(t.length===1)super.fill(t[0],i,a);else for(let e=i;e<a;e++)this[e]=t[(e-i)%t.length]}else if(e instanceof Uint8Array)if(e.length===0)super.fill(0,i,a);else for(let t=i;t<a;t++)this[t]=e[(t-i)%e.length];return this}indexOf(e,t,n){if(typeof e==`number`)return super.indexOf(e&255,t);let r=typeof e==`string`?encodeString(e,normalizeEncoding(n)):e,i=t??0;outer:for(let e=i;e<=this.length-r.length;e++){for(let t=0;t<r.length;t++)if(this[e+t]!==r[t])continue outer;return e}return-1}lastIndexOf(e,t,n){if(typeof e==`number`)return t===void 0?super.lastIndexOf(e&255):super.lastIndexOf(e&255,t);let r=typeof e==`string`?encodeString(e,normalizeEncoding(n)):e,i=t===void 0?this.length-r.length:Math.min(t,this.length-r.length);outer:for(let e=i;e>=0;e--){for(let t=0;t<r.length;t++)if(this[e+t]!==r[t])continue outer;return e}return-1}includes(e,t,n){return this.indexOf(e,t,n)!==-1}readUInt8(e=0){return checkOffset(e,1,this.length),this[e]}readUInt16BE(e=0){return checkOffset(e,2,this.length),this[e]<<8|this[e+1]}readUInt16LE(e=0){return checkOffset(e,2,this.length),this[e]|this[e+1]<<8}readUInt32BE(e=0){return checkOffset(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])}readUInt32LE(e=0){return checkOffset(e,4,this.length),this[e+3]*16777216+(this[e+2]<<16|this[e+1]<<8|this[e])>>>0}readInt8(e=0){return checkOffset(e,1,this.length),this[e]|(this[e]&128?4294967040:0)}readInt16BE(e=0){checkOffset(e,2,this.length);let t=this[e]<<8|this[e+1];return t&32768?t|4294901760:t}readInt16LE(e=0){checkOffset(e,2,this.length);let t=this[e]|this[e+1]<<8;return t&32768?t|4294901760:t}readInt32BE(e=0){return checkOffset(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]}readInt32LE(e=0){return checkOffset(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24}readFloatBE(e=0){return checkOffset(e,4,this.length),new DataView(this.buffer,this.byteOffset+e,4).getFloat32(0,!1)}readFloatLE(e=0){return checkOffset(e,4,this.length),new DataView(this.buffer,this.byteOffset+e,4).getFloat32(0,!0)}readDoubleBE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getFloat64(0,!1)}readDoubleLE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getFloat64(0,!0)}readBigInt64BE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getBigInt64(0,!1)}readBigInt64LE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getBigInt64(0,!0)}readBigUInt64BE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getBigUint64(0,!1)}readBigUInt64LE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getBigUint64(0,!0)}readUIntBE(e,t){checkOffset(e,t,this.length);let n=0;for(let r=0;r<t;r++)n=n*256+this[e+r];return n}readUIntLE(e,t){checkOffset(e,t,this.length);let n=0,r=1;for(let i=0;i<t;i++)n+=this[e+i]*r,r*=256;return n}readIntBE(e,t){checkOffset(e,t,this.length);let n=0;for(let r=0;r<t;r++)n=n*256+this[e+r];return n>=2**(8*t-1)&&(n-=2**(8*t)),n}readIntLE(e,t){checkOffset(e,t,this.length);let n=0,r=1;for(let i=0;i<t;i++)n+=this[e+i]*r,r*=256;return n>=2**(8*t-1)&&(n-=2**(8*t)),n}writeUInt8(e,t=0){return checkOffset(t,1,this.length),this[t]=e&255,t+1}writeUInt16BE(e,t=0){return checkOffset(t,2,this.length),this[t]=e>>>8&255,this[t+1]=e&255,t+2}writeUInt16LE(e,t=0){return checkOffset(t,2,this.length),this[t]=e&255,this[t+1]=e>>>8&255,t+2}writeUInt32BE(e,t=0){return checkOffset(t,4,this.length),this[t]=e>>>24&255,this[t+1]=e>>>16&255,this[t+2]=e>>>8&255,this[t+3]=e&255,t+4}writeUInt32LE(e,t=0){return checkOffset(t,4,this.length),this[t]=e&255,this[t+1]=e>>>8&255,this[t+2]=e>>>16&255,this[t+3]=e>>>24&255,t+4}writeInt8(e,t=0){return checkOffset(t,1,this.length),e<0&&(e=255+e+1),this[t]=e&255,t+1}writeInt16BE(e,t=0){return checkOffset(t,2,this.length),this[t]=e>>>8&255,this[t+1]=e&255,t+2}writeInt16LE(e,t=0){return checkOffset(t,2,this.length),this[t]=e&255,this[t+1]=e>>>8&255,t+2}writeInt32BE(e,t=0){return checkOffset(t,4,this.length),this[t]=e>>>24&255,this[t+1]=e>>>16&255,this[t+2]=e>>>8&255,this[t+3]=e&255,t+4}writeInt32LE(e,t=0){return checkOffset(t,4,this.length),this[t]=e&255,this[t+1]=e>>>8&255,this[t+2]=e>>>16&255,this[t+3]=e>>>24&255,t+4}writeFloatBE(e,t=0){return checkOffset(t,4,this.length),new DataView(this.buffer,this.byteOffset+t,4).setFloat32(0,e,!1),t+4}writeFloatLE(e,t=0){return checkOffset(t,4,this.length),new DataView(this.buffer,this.byteOffset+t,4).setFloat32(0,e,!0),t+4}writeDoubleBE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setFloat64(0,e,!1),t+8}writeDoubleLE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setFloat64(0,e,!0),t+8}writeBigInt64BE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setBigInt64(0,e,!1),t+8}writeBigInt64LE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setBigInt64(0,e,!0),t+8}writeBigUInt64BE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setBigUint64(0,e,!1),t+8}writeBigUInt64LE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setBigUint64(0,e,!0),t+8}swap16(){let e=this.length;if(e%2!=0)throw RangeError(`Buffer size must be a multiple of 16-bits`);for(let t=0;t<e;t+=2){let e=this[t];this[t]=this[t+1],this[t+1]=e}return this}swap32(){let e=this.length;if(e%4!=0)throw RangeError(`Buffer size must be a multiple of 32-bits`);for(let t=0;t<e;t+=4){let e=this[t],n=this[t+1];this[t]=this[t+3],this[t+1]=this[t+2],this[t+2]=n,this[t+3]=e}return this}swap64(){let e=this.length;if(e%8!=0)throw RangeError(`Buffer size must be a multiple of 64-bits`);for(let t=0;t<e;t+=8){let e=this[t],n=this[t+1],r=this[t+2],i=this[t+3];this[t]=this[t+7],this[t+1]=this[t+6],this[t+2]=this[t+5],this[t+3]=this[t+4],this[t+4]=i,this[t+5]=r,this[t+6]=n,this[t+7]=e}return this}};`Buffer`in globalThis||Object.defineProperty(globalThis,"Buffer",{value:Ot,enumerable:!1,writable:!0,configurable:!0}),typeof globalThis.btoa!=`function`&&Object.defineProperty(globalThis,"btoa",{value:function btoa(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return _t.base64_encode(t)},enumerable:!0,writable:!0,configurable:!0}),typeof globalThis.atob!=`function`&&Object.defineProperty(globalThis,"atob",{value:function atob(e){let t=_t.base64_decode(e),n=``;for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return n},enumerable:!0,writable:!0,configurable:!0}),typeof queueMicrotask!=`function`&&Object.defineProperty(globalThis,"queueMicrotask",{value:j,enumerable:!0,writable:!0,configurable:!0});function getGjsGlobal(){return globalThis}function getGioNamespace(){let e=getGjsGlobal().imports?.gi;if(!e)return null;let t=null;try{t=e.GioUnix??null}catch{}if(!t)try{t=e.Gio??null}catch{}return t}function getMonotonicTime(){try{let e=getGjsGlobal().imports?.gi?.GLib;if(e?.get_monotonic_time)return BigInt(e.get_monotonic_time())*1000n}catch{}return typeof performance?.now==`function`?BigInt(Math.round(performance.now()*1e6)):BigInt(Date.now())*1000000n}const kt=getMonotonicTime();function hrtime(e){let t=getMonotonicTime()-kt,n=Number(t/1000000000n),r=Number(t%1000000000n);if(e){let t=n-e[0],i=r-e[1];return i<0&&(t--,i+=1e9),[t,i]}return[n,r]}function hrtimeBigint(){return getMonotonicTime()-kt}let At;function probeUname(){if(At!==void 0)return At;At=null;try{let e=getGjsGlobal().imports?.gi?.GLib;if(!e)return At;let t=e.spawn_sync,n=e.SpawnFlags?.SEARCH_PATH;if(!t||n===void 0)return At;let[r,i]=t(null,[`uname`,`-sm`],null,n,null);if(!r||!i)return At;let a=new TextDecoder().decode(i).trim().split(/\s+/);if(a.length<2)return At;let o=mapSysname(a[0]),s=mapMachine(a[a.length-1]);if(!o||!s)return At;At={platform:o,arch:s}}catch{}return At}function detectGjsVersion(){try{let e=getGjsGlobal().imports?.system;if(e?.version!==void 0){let t=Number(e.version);return`${Math.floor(t/1e4)}.${Math.floor(t%1e4/100)}.${t%100}`}}catch{}}function detectNodeVersion(){if(typeof globalThis.process?.versions?.node==`string`)return globalThis.process.versions.node}function detectVersionInfo(){if(detectNodeVersion())return{version:globalThis.process.version,versions:{...globalThis.process.versions},title:globalThis.process?.title||`node`};let e=detectGjsVersion(),t={node:`20.0.0`};return e&&(t.gjs=e),{version:`v20.0.0`,versions:t,title:`gjs`}}function detectPpid(){return!onGjs()&&typeof globalThis.process?.ppid==`number`?globalThis.process.ppid:hostPpid()??0}function onGjs(){try{return getGjsGlobal().imports?.gi!==void 0}catch{return!1}}function detectPlatform(){if(onGjs()){let e=probeUname();return e?e.platform:`linux`}let e=globalThis.process;return typeof e?.platform==`string`?e.platform:`linux`}function detectArch(){if(onGjs()){let e=probeUname();return e?e.arch:`x64`}let e=globalThis.process;return typeof e?.arch==`string`?e.arch:`x64`}function getPid(){return!onGjs()&&typeof globalThis.process?.pid==`number`?globalThis.process.pid:hostPid()??0}function getEnvProxy(){if(typeof globalThis.process?.env==`object`)return globalThis.process.env;try{let e=getGjsGlobal().imports?.gi?.GLib;if(e)return new Proxy({},{get(t,n){if(typeof n==`string`)return e.getenv(n)??void 0},set(t,n,r){return typeof n==`string`?(e.setenv(n,String(r),!0),!0):!1},deleteProperty(t,n){return typeof n==`string`?(e.unsetenv(n),!0):!1},has(t,n){return typeof n==`string`?e.getenv(n)!==null:!1},ownKeys(t){return e.listenv()},getOwnPropertyDescriptor(t,n){if(typeof n!=`string`)return;let r=e.getenv(n);if(r!==null)return{configurable:!0,enumerable:!0,writable:!0,value:r}}})}catch{}return{}}function getArgv(){if(globalThis.process?.argv!==void 0)return globalThis.process.argv;try{let e=getGjsGlobal().imports?.system;if(e?.programArgs)return[`gjs`,e.programInvocationName||``,...e.programArgs]}catch{}return[`gjs`]}function getExecPath(){let e=globalThis.process;return!isGjsHost()&&typeof e?.execPath==`string`?e.execPath:hostExecPath()??`/usr/bin/gjs`}function isGjsHost(){try{return getGjsGlobal().imports?.gi!==void 0}catch{return!1}}function getCwd(){try{let e=getGjsGlobal().imports?.gi?.GLib;if(e?.get_current_dir)return e.get_current_dir()}catch{}return`/`}function chdir(e){let t=getGjsGlobal().imports?.gi?.GLib;try{if(t?.chdir){if(!t.file_test(e,16)){let t=Error(`ENOENT: no such file or directory, chdir '${e}'`);throw t.code=`ENOENT`,t.syscall=`chdir`,t.path=e,t}t.chdir(e);return}}catch(e){if(e&&typeof e==`object`&&e.code===`ENOENT`)throw e}if(!t){let t=globalThis.process;if(t&&typeof t.chdir==`function`){t.chdir(e);return}}throw Error(`process.chdir() is not supported in this environment`)}function exitProcess(e){let t=getGjsGlobal().imports,n=t?.gi?.GLib,r=t?.system,i=n?.idle_add,a=n?.SOURCE_REMOVE,o=n?.PRIORITY_DEFAULT;if(r?.exit&&i&&typeof o==`number`&&typeof a==`boolean`)return ensureMainLoop(),i(o,()=>(quitMainLoop(),r.exit(e),a)),new Promise(()=>{});try{r?.exit&&r.exit(e)}catch{}let s=globalThis.process;throw s&&typeof s.exit==`function`&&s.exit(e),Error(`process.exit(${e})`)}function isGjs(){return getGjsGlobal().imports?.gi?.GLib!==void 0}function killPid(e,t){try{let n=getGjsGlobal().imports?.gi?.GLib;if(n){let r=typeof t==`number`?String(t):t||`SIGTERM`,i=r.startsWith(`SIG`)?`-${r.slice(3)}`:`-${r}`;return n.spawn_command_line_sync(`kill ${i} ${e}`),!0}}catch{}if(!isGjs()){let n=globalThis.process;if(n&&typeof n.kill==`function`)return n.kill(e,t)}throw Error(`process.kill() is not supported in this environment`)}function memoryUsage(){let e=readProcessMemory();if(e)return{rss:e.resident,heapTotal:e.resident,heapUsed:e.resident,external:0,arrayBuffers:0};if(!isGjs()){let e=globalThis.process;if(e&&typeof e.memoryUsage==`function`)return e.memoryUsage()}return{rss:0,heapTotal:0,heapUsed:0,external:0,arrayBuffers:0}}function cpuUsage(e){if(!isGjs()){let t=globalThis.process;if(t&&typeof t.cpuUsage==`function`)return t.cpuUsage(e)}return{user:0,system:0}}let jt=null;const Mt=globalThis.imports?.gi;if(Mt)try{jt=Mt.GjsifyTerminal}catch{}const Nt=jt,Pt=Symbol(`kCapture`),Ft=Symbol.for(`nodejs.rejection`);function onceWrapper(){let{target:e,type:t,listener:n}=this;return this.wrapperFn&&e.removeListener(t,this.wrapperFn),n.apply(e,Array.from(arguments))}function _onceWrap(e,t,n){let r={target:e,type:t,listener:n,wrapperFn:void 0},i=onceWrapper.bind(r);return r.wrapperFn=i,i.listener=n,i}function arrayClone(e){switch(e.length){case 0:return[];case 1:return[e[0]];case 2:return[e[0],e[1]];case 3:return[e[0],e[1],e[2]];default:return e.slice()}}function checkListener(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}function validateNumber(e,t){if(typeof e!=`number`||e!==e)throw TypeError(`The "${t}" argument must be of type number. Received type ${typeof e}`)}function spliceOne(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}var It=class EventEmitter{static defaultMaxListeners=10;static errorMonitor=Symbol(`events.errorMonitor`);static captureRejectionSymbol=Ft;static _captureRejections=!1;static get captureRejections(){return EventEmitter._captureRejections}static set captureRejections(e){if(typeof e!=`boolean`)throw TypeError(`The "captureRejections" argument must be of type boolean.`);EventEmitter._captureRejections=e}_events;_eventsCount;_maxListeners;[Pt];constructor(e){this._events=Object.create(null),this._eventsCount=0,this._maxListeners=void 0,this[Pt]=e?.captureRejections??EventEmitter._captureRejections}setMaxListeners(e){if(validateNumber(e,`n`),e<0)throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e);return this._maxListeners=e,this}getMaxListeners(){return this._maxListeners??EventEmitter.defaultMaxListeners}emit(e,...t){let n=this._events,r=e===`error`;if(n!==void 0)r&&n[EventEmitter.errorMonitor]!==void 0&&this.emit(EventEmitter.errorMonitor,...t),r&&=n.error===void 0;else if(!r)return!1;if(r){let e;if(e=t.length>0?t[0]:Error(`Unhandled error.`),e instanceof Error)throw e;let n=Error(`Unhandled error. (`+e+`)`);throw n.context=e,n}let i=n[e];if(i===void 0)return!1;if(typeof i==`function`){let n=i.apply(this,t);n!=null&&this[Pt]&&this._addCatch(n,e,t)}else{let n=arrayClone(i),r=n.length;for(let i=0;i<r;++i){let r=n[i].apply(this,t);r!=null&&this[Pt]&&this._addCatch(r,e,t)}}return!0}_addCatch(e,t,n){typeof e?.then==`function`&&e.then(void 0,e=>{let r=this[Ft];if(typeof r==`function`)r.call(this,e,t,...n);else{let t=this[Pt];try{this[Pt]=!1,this.emit(`error`,e)}finally{this[Pt]=t}}})}addListener(e,t){return this._addListener(e,t,!1)}on(e,t){return this._addListener(e,t,!1)}prependListener(e,t){return this._addListener(e,t,!0)}_addListener(e,t,n){checkListener(t);let r=this._events;r===void 0?(r=this._events=Object.create(null),this._eventsCount=0):r.newListener!==void 0&&(this.emit(`newListener`,e,t.listener??t),r=this._events);let i=r[e];i===void 0?(r[e]=t,++this._eventsCount):typeof i==`function`?r[e]=n?[t,i]:[i,t]:n?i.unshift(t):i.push(t);let a=this.getMaxListeners();if(a>0){let t=typeof r[e]==`function`?1:r[e].length;if(t>a&&!r[e].warned){typeof r[e]!=`function`&&(r[e].warned=!0);let n=Error(`Possible EventEmitter memory leak detected. ${t} ${String(e)} listeners added to [${this.constructor.name}]. Use emitter.setMaxListeners() to increase limit`);n.name=`MaxListenersExceededWarning`,A.warn(n.message)}}return this}once(e,t){return checkListener(t),this.on(e,_onceWrap(this,e,t)),this}prependOnceListener(e,t){return checkListener(t),this.prependListener(e,_onceWrap(this,e,t)),this}removeListener(e,t){checkListener(t);let n=this._events;if(n===void 0)return this;let r=n[e];if(r===void 0)return this;if(r===t||r.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit(`removeListener`,e,r.listener??t));else if(typeof r!=`function`){let i=-1;for(let e=r.length-1;e>=0;e--)if(r[e]===t||r[e].listener===t){i=e;break}if(i<0)return this;i===0?r.shift():spliceOne(r,i),r.length===1&&(n[e]=r[0]),n.removeListener!==void 0&&this.emit(`removeListener`,e,t.listener??t)}return this}off(e,t){return this.removeListener(e,t)}removeAllListeners(e){let t=this._events;if(t===void 0)return this;if(t.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):t[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete t[e]),this;if(arguments.length===0){let e=Object.keys(t);for(let t=0;t<e.length;++t){let n=e[t];n!==`removeListener`&&this.removeAllListeners(n)}return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}let n=t[e];if(typeof n==`function`)this.removeListener(e,n);else if(n!==void 0)for(let t=n.length-1;t>=0;t--)this.removeListener(e,n[t]);return this}listeners(e){let t=this._events;if(t===void 0)return[];let n=t[e];return n===void 0?[]:typeof n==`function`?[n.listener??n]:unwrapListeners(n)}rawListeners(e){let t=this._events;if(t===void 0)return[];let n=t[e];return n===void 0?[]:typeof n==`function`?[n]:arrayClone(n)}listenerCount(e){let t=this._events;if(t===void 0)return 0;let n=t[e];return n===void 0?0:typeof n==`function`?1:n.length}eventNames(){return(this._eventsCount??0)>0?Reflect.ownKeys(this._events):[]}static once(e,t,n){return new Promise((r,i)=>{let a=n?.signal;if(a?.aborted){i(createAbortError$1(a));return}if(typeof e.addEventListener==`function`){let n=e,handler=(...e)=>{a&&a.removeEventListener(`abort`,abortHandler),r(e)},errorHandler=e=>{a&&a.removeEventListener(`abort`,abortHandler),n.removeEventListener(`error`,errorHandler),i(e)},abortHandler=()=>{n.removeEventListener(t,handler),n.removeEventListener(`error`,errorHandler),i(createAbortError$1(a))};n.addEventListener(t,handler,{once:!0}),t!==`error`&&n.addEventListener(`error`,errorHandler,{once:!0}),a&&a.addEventListener(`abort`,abortHandler,{once:!0});return}let o=e,eventHandler=(...e)=>{a&&a.removeEventListener(`abort`,abortHandler),errorHandler!==void 0&&o.removeListener(`error`,errorHandler),r(e)},errorHandler;t!==`error`&&(errorHandler=e=>{o.removeListener(t,eventHandler),a&&a.removeEventListener(`abort`,abortHandler),i(e)},o.once(`error`,errorHandler)),o.once(t,eventHandler);let abortHandler=()=>{o.removeListener(t,eventHandler),errorHandler&&o.removeListener(`error`,errorHandler),i(createAbortError$1(a))};a&&a.addEventListener(`abort`,abortHandler,{once:!0})})}static on(e,t,n){let r=n?.signal;if(r?.aborted)throw createAbortError$1(r);let i=n?.highWaterMark??2**53-1,a=n?.lowWaterMark??1;validateNumber(i,`highWaterMark`),validateNumber(a,`lowWaterMark`);let o=[],s=[],c=null,l=!1,u=!1,eventHandler=(...t)=>{if(s.length>0){let{resolve:e}=s.shift();e({value:t,done:!1})}else o.push(t),o.length>=i&&!u&&(u=!0,typeof e.pause==`function`&&e.pause())},errorHandler=e=>{if(c=e,s.length>0){let{reject:t}=s.shift();t(e)}d.return()},abortHandler=()=>{errorHandler(createAbortError$1(r))};e.on(t,eventHandler),t!==`error`&&e.on(`error`,errorHandler),r&&r.addEventListener(`abort`,abortHandler,{once:!0});let cleanup=()=>{e.removeListener(t,eventHandler),e.removeListener(`error`,errorHandler),r&&r.removeEventListener(`abort`,abortHandler),l=!0;for(let{resolve:e}of s)e({value:void 0,done:!0});s.length=0,o.length=0},d={next(){if(o.length>0){let t=o.shift();return u&&o.length<a&&(u=!1,typeof e.resume==`function`&&e.resume()),Promise.resolve({value:t,done:!1})}if(c){let e=Promise.reject(c);return c=null,e}return l?Promise.resolve({value:void 0,done:!0}):new Promise((e,t)=>{s.push({resolve:e,reject:t})})},return(){return cleanup(),Promise.resolve({value:void 0,done:!0})},throw(e){return l||(c=e,cleanup()),Promise.reject(e)},[Symbol.asyncIterator](){return this}};return d}static listenerCount(e,t){return e.listenerCount(t)}static getEventListeners(e,t){return typeof e.listeners==`function`?e.listeners(t):[]}static setMaxListeners(e,...t){if(validateNumber(e,`n`),e<0)throw RangeError(`The value of "n" is out of range.`);if(t.length===0)EventEmitter.defaultMaxListeners=e;else for(let n of t)typeof n.setMaxListeners==`function`&&n.setMaxListeners(e)}static getMaxListeners(e){return typeof e.getMaxListeners==`function`?e.getMaxListeners():EventEmitter.defaultMaxListeners}static addAbortListener(e,t){e.aborted&&Promise.resolve().then(()=>t());let handler=()=>t();return e.addEventListener(`abort`,handler,{once:!0}),{[Symbol.dispose](){e.removeEventListener(`abort`,handler)}}}};It.EventEmitter=It;for(let e of[`setMaxListeners`,`getMaxListeners`,`emit`,`addListener`,`on`,`prependListener`,`once`,`prependOnceListener`,`removeListener`,`off`,`removeAllListeners`,`listeners`,`rawListeners`,`listenerCount`,`eventNames`]){let t=It.prototype[e];typeof t==`function`&&Object.defineProperty(It.prototype,e,{enumerable:!0,configurable:!0,writable:!0,value:t})}Object.defineProperty(It.prototype,"_events",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(It.prototype,"_eventsCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(It.prototype,"_maxListeners",{enumerable:!0,configurable:!0,writable:!0,value:void 0});function unwrapListeners(e){let t=Array.from({length:e.length});for(let n=0;n<t.length;++n)t[n]=e[n].listener??e[n];return t}function createAbortError$1(e){let t=Error(`The operation was aborted`);return t.name=`AbortError`,t.code=`ABORT_ERR`,e?.reason&&(t.cause=e.reason),t}__name(createAbortError$1,`createAbortError`);const Lt=makeCallable(It);Lt.EventEmitter=Lt,Lt.captureRejectionSymbol,Lt.errorMonitor,Lt.defaultMaxListeners,Lt.setMaxListeners,Lt.getMaxListeners,Lt.once,Lt.on,Lt.getEventListeners,Lt.listenerCount,Lt.addAbortListener;function normalizeAndValidateEncoding(e){return e&&checkEncoding(e),normalizeEncoding(e)}function utf8DecodeMaximalSubpart(e,t,n){let r=``,i=t;for(;i<n;){let t=e[i];if(t<=127){r+=String.fromCharCode(t),i++;continue}if(t>=194&&t<=223){i+1<n&&e[i+1]>=128&&e[i+1]<=191?(r+=String.fromCharCode((t&31)<<6|e[i+1]&63),i+=2):(r+=`�`,i++);continue}if(t>=224&&t<=239){let a,o;if(t===224?(a=160,o=191):t===237?(a=128,o=159):(a=128,o=191),i+1>=n){r+=`�`,i++;continue}let s=e[i+1];if(s<a||s>o){r+=`�`,i++;continue}if(i+2>=n){r+=`�`,i+=2;continue}let c=e[i+2];if(c<128||c>191){r+=`�`,i+=2;continue}let l=(t&15)<<12|(s&63)<<6|c&63;r+=String.fromCharCode(l),i+=3;continue}if(t>=240&&t<=244){let a,o;if(t===240?(a=144,o=191):t===244?(a=128,o=143):(a=128,o=191),i+1>=n){r+=`�`,i++;continue}let s=e[i+1];if(s<a||s>o){r+=`�`,i++;continue}if(i+2>=n){r+=`�`,i+=2;continue}let c=e[i+2];if(c<128||c>191){r+=`�`,i+=2;continue}if(i+3>=n){r+=`�`,i+=3;continue}let l=e[i+3];if(l<128||l>191){r+=`�`,i+=3;continue}let u=(t&7)<<18|(s&63)<<12|(c&63)<<6|l&63;r+=String.fromCharCode(55296+(u-65536>>10),56320+(u-65536&1023)),i+=4;continue}r+=`�`,i++}return r}function utf8CharLength(e){return e&128?e>=194&&e<=223?2:e>=224&&e<=239?3:e>=240&&e<=244?4:0:1}function isValidContinuation(e,t,n,r){if(n===1){if(t===3)return e===224?r>=160&&r<=191:e===237?r>=128&&r<=159:r>=128&&r<=191;if(t===4)return e===240?r>=144&&r<=191:e===244?r>=128&&r<=143:r>=128&&r<=191}return r>=128&&r<=191}const Rt=function StringDecoder(e){this.encoding=normalizeAndValidateEncoding(e),this._lastNeed=0,this._lastTotal=0,this._lastLeadByte=0,this.encoding===`utf8`||this.encoding===`utf16le`?this._lastChar=new Uint8Array(4):this.encoding===`base64`?this._lastChar=new Uint8Array(3):this._lastChar=new Uint8Array};Rt.prototype.write=function write(e){if(e.length===0)return``;switch(this.encoding){case`utf8`:return writeUtf8(this,e);case`utf16le`:return writeUtf16le(this,e);case`base64`:return writeBase64(this,e);case`ascii`:return decodeAscii(e);case`latin1`:return decodeLatin1(e);case`hex`:return decodeHex(e);default:return decodeAscii(e)}},Rt.prototype.end=function end(e){let t=``;if(e&&e.length>0&&(t=this.write(e)),this.encoding===`utf8`&&this._lastNeed>0)t+=`�`,this._lastNeed=0,this._lastTotal=0;else if(this.encoding===`utf16le`&&this._lastNeed>0){let e=this._lastTotal-this._lastNeed;for(let n=0;n+1<e;n+=2)t+=String.fromCharCode(this._lastChar[n]|this._lastChar[n+1]<<8);this._lastNeed=0,this._lastTotal=0}else if(this.encoding===`base64`&&this._lastNeed>0){let e=this._lastChar.subarray(0,this._lastTotal-this._lastNeed);t+=base64Encode(e),this._lastNeed=0,this._lastTotal=0}return t};function writeUtf8(e,t){let n=0,r=``;if(e._lastNeed>0){for(;n<t.length&&e._lastNeed>0;){let i=t[n],a=e._lastTotal-e._lastNeed;if(isValidContinuation(e._lastLeadByte,e._lastTotal,a,i))e._lastChar[a]=i,e._lastNeed--,n++;else{r+=`�`,e._lastNeed=0,e._lastTotal=0,e._lastLeadByte=0;break}}if(e._lastNeed===0&&e._lastTotal>0&&(r+=utf8DecodeMaximalSubpart(e._lastChar,0,e._lastTotal),e._lastTotal=0,e._lastLeadByte=0),e._lastNeed>0)return r}let i=t.length;for(let r=0;r<Math.min(4,t.length-n);r++){let a=t.length-1-r;if(a<n)break;let o=t[a];if((o&192)!=128){let n=utf8CharLength(o);if(n>0&&o>=128){let r=t.length-a;if(r<n){let s=!0;for(let e=1;e<r;e++)if(!isValidContinuation(o,n,e,t[a+e])){s=!1;break}if(s){i=a;for(let n=0;n<r;n++)e._lastChar[n]=t[a+n];e._lastNeed=n-r,e._lastTotal=n,e._lastLeadByte=o}}}break}}return i>n&&(r+=utf8DecodeMaximalSubpart(t,n,i)),r}function writeUtf16le(e,t){let n=``,r=0;if(e._lastNeed>0){let i=e._lastTotal-e._lastNeed,a=Math.min(e._lastNeed,t.length);for(let n=0;n<a;n++)e._lastChar[i+n]=t[n];if(e._lastNeed-=a,r=a,e._lastNeed>0)return``;let o=e._lastTotal,s=0;for(;s+1<o;){let i=e._lastChar[s]|e._lastChar[s+1]<<8;if(s+=2,i>=55296&&i<=56319){if(s+1<o){let t=e._lastChar[s]|e._lastChar[s+1]<<8;if(t>=56320&&t<=57343){n+=String.fromCharCode(i,t),s+=2;continue}}if(r+1<t.length){let e=t[r]|t[r+1]<<8;if(e>=56320&&e<=57343){n+=String.fromCharCode(i,e),r+=2;continue}}else if(r>=t.length)return e._lastChar[0]=e._lastChar[s-2],e._lastChar[1]=e._lastChar[s-1],e._lastNeed=2,e._lastTotal=4,n}n+=String.fromCharCode(i)}e._lastTotal=0}for(;r+1<t.length;){let i=t[r]|t[r+1]<<8;if(r+=2,i>=55296&&i<=56319)if(r+1<t.length){let e=t[r]|t[r+1]<<8;if(e>=56320&&e<=57343){n+=String.fromCharCode(i,e),r+=2;continue}}else if(r<t.length)return n+=String.fromCharCode(i),e._lastChar[0]=t[r],e._lastNeed=1,e._lastTotal=2,n;else return e._lastChar[0]=t[r-2],e._lastChar[1]=t[r-1],e._lastNeed=2,e._lastTotal=4,n;n+=String.fromCharCode(i)}return r<t.length&&(e._lastChar[0]=t[r],e._lastNeed=1,e._lastTotal=2),n}function writeBase64(e,t){let n=0;if(e._lastNeed>0){let r=Math.min(e._lastNeed,t.length);for(let n=0;n<r;n++)e._lastChar[e._lastTotal-e._lastNeed+n]=t[n],e._lastNeed--;if(n=r,e._lastNeed>0)return``}let r=t.length-n,i=r-r%3,a=``;e._lastTotal>0&&e._lastNeed===0&&(a+=base64Encode(e._lastChar.subarray(0,e._lastTotal)),e._lastTotal=0),i>0&&(a+=base64Encode(t.subarray(n,n+i)));let o=r-i;if(o>0){for(let r=0;r<o;r++)e._lastChar[r]=t[n+i+r];e._lastNeed=3-o,e._lastTotal=3}return a}function decodeAscii(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]&127);return t}function decodeLatin1(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return t}function decodeHex(e){let t=``;for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,`0`);return t}const zt=new TextEncoder;var ProcessWriteStream=class extends Lt{fd;writable=!0;_outGio=null;constructor(e){super(),this.fd=e;let t=getGioNamespace();if(t){let e=t.UnixOutputStream??t.OutputStream;if(e)try{this._outGio=e.new(this.fd,!1)}catch{}}}write(e){if(this._outGio)try{let t=typeof e==`string`?zt.encode(e):e;return this._outGio.write_all(t,null),!0}catch{}return this.fd===2?A.error(e):A.log(e),!0}get isTTY(){if(Nt)return Nt.Terminal.is_tty(this.fd);try{let e=getGjsGlobal().imports?.gi?.GLib;if(e)return!!e.log_writer_supports_color(this.fd)}catch{}return!1}get columns(){if(Nt){let[e,,t]=Nt.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=getGjsGlobal().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`COLUMNS`)??`0`,10);if(t>0)return t}}catch{}return 80}end(){}destroy(){}get rows(){if(Nt){let[e,t]=Nt.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=getGjsGlobal().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`LINES`)??`0`,10);if(t>0)return t}}catch{}return 24}},ProcessReadStream=class extends Lt{fd;isRaw=!1;_gio=null;_stdinGio=null;_reading=!1;_flowing=!1;_sttyCleanupRegistered=!1;_mainLoopHeld=!1;_pendingRead=!1;_decoder=null;constructor(e){super(),this.fd=e,this._gio=getGioNamespace()}get isTTY(){return Nt?Nt.Terminal.is_tty(this.fd):!1}setRawMode(e){return Nt&&Nt.Terminal.set_raw_mode(this.fd,e)?(this.isRaw=e,this):(this._setRawModeViaStty(e),this.isRaw=e,this)}_setRawModeViaStty(e){try{let t=globalThis.imports?.gi,n=t?.Gio??t?.Gio;if(!n)return;let r=n.SubprocessFlags?.STDIN_INHERIT??2,i=e?[`stty`,`-icanon`,`-echo`,`-icrnl`,`-isig`,`min`,`1`,`time`,`0`]:[`stty`,`icanon`,`echo`,`icrnl`,`isig`];if(new n.SubprocessLauncher({flags:r}).spawnv(i).wait(null),e&&!this._sttyCleanupRegistered){this._sttyCleanupRegistered=!0;let e=globalThis.process;e?.once&&typeof e.once==`function`&&e.once(`exit`,()=>this._setRawModeViaStty(!1))}}catch{}}setEncoding(e){return this._decoder=new Rt(e),this}_pushData(e){if(this._decoder){let t=this._decoder.write(e);t.length>0&&this.emit(`data`,t)}else this.emit(`data`,e)}on(e,t){let n=e===`data`&&this.listenerCount(`data`)===0;return super.on(e,t),n&&e===`data`&&this.resume(),this}addListener(e,t){return this.on(e,t)}once(e,t){return super.once(e,t),this}removeListener(e,t){return super.removeListener(e,t),e===`data`&&this.listenerCount(`data`)===0&&this.pause(),this}off(e,t){return this.removeListener(e,t)}removeAllListeners(e){let t=e===void 0||e===`data`?this.listenerCount(`data`)>0:!1;return super.removeAllListeners(e),t&&this.listenerCount(`data`)===0&&this.pause(),this}resume(){return this._flowing=!0,this._gio&&this.fd===0&&!this._reading&&this._startReading(),this}pause(){if(this._flowing=!1,this._reading=!1,this._mainLoopHeld){this._mainLoopHeld=!1;let e=globalThis.imports?.gi,t=e?.GLib??e?.GLib;t?.idle_add?t.idle_add(300,()=>(this._mainLoopHeld||quitMainLoop(),!1)):quitMainLoop()}return this}read(){return null}_startReading(){if(!this._gio||this._reading)return;if(this._pendingRead){this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,ensureMainLoop());return}if(this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,ensureMainLoop()),!this._stdinGio){let e=this._gio.UnixInputStream??this._gio.InputStream;if(!e){this._reading=!1;return}try{this._stdinGio=e.new(this.fd,!1)}catch{this._reading=!1;return}}let loop=()=>{if(!this._reading){this._pendingRead=!1;return}this._pendingRead=!0,this._stdinGio.read_bytes_async(4096,0,null,(e,t)=>{this._pendingRead=!1;try{let n=e.read_bytes_finish(t)?.get_data?.()??null;if(n&&n.byteLength>0)this._pushData(Buffer.from(n));else if(n!==null&&n.byteLength===0){if(this._reading=!1,this._decoder){let e=this._decoder.end();e.length>0&&this.emit(`data`,e)}this.emit(`end`);return}}catch{this._reading=!1;return}this._reading&&loop()})};loop()}};const Bt=Date.now();function defineLazy(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){let r=n();return Object.defineProperty(e,t,{value:r,configurable:!0,enumerable:!0,writable:!1}),r}})}var Process=class extends Lt{platform;arch;env;argv;argv0;execPath;pid;ppid;version;versions;title;execArgv;config;exitCode;constructor(){super(),defineLazy(this,`platform`,detectPlatform),defineLazy(this,`arch`,detectArch),this.env=getEnvProxy(),this.argv=getArgv(),this.argv0=this.argv[0]||`gjs`,this.execPath=getExecPath(),this.execArgv=globalThis.process?.execArgv??[],this.config=globalThis.process?.config??{target_defaults:{},variables:{}},this.pid=getPid(),this.ppid=detectPpid();let e=detectVersionInfo();this.version=e.version,this.versions=e.versions,this.title=e.title}cwd(){return getCwd()}chdir(e){chdir(e)}kill(e,t){return killPid(e,t)}exit(e){return this.exitCode=e??this.exitCode??0,this.emit(`exit`,this.exitCode),exitProcess(this.exitCode)}nextTick(e,...t){typeof queueMicrotask==`function`?queueMicrotask(()=>e(...t)):Promise.resolve().then(()=>e(...t))}hrtime(e){return hrtime(e)}uptime(){return(Date.now()-Bt)/1e3}memoryUsage(){return memoryUsage()}cpuUsage(e){return cpuUsage(e)}stdout=new ProcessWriteStream(1);stderr=new ProcessWriteStream(2);stdin=new ProcessReadStream(0);abort(){this.exit(1)}umask(e){return 18}emitWarning(e,t){A.warn(typeof e==`string`?`(${t||`Warning`}): ${e}`:e.message)}};Process.prototype.hrtime.bigint=function(){return hrtimeBigint()};const Vt=new Process;if(Nt)try{let e=new Nt.ResizeWatcher;e.connect(`resized`,(e,t,n)=>{Vt.stdout.emit(`resize`),Vt.stderr.emit(`resize`)}),e.start()}catch{}Vt.platform,Vt.arch,Vt.env,Vt.argv,Vt.argv0,Vt.execPath,Vt.pid,Vt.ppid,Vt.version,Vt.versions,Vt.cwd.bind(Vt),Vt.chdir.bind(Vt),Vt.exit.bind(Vt),Vt.nextTick.bind(Vt),Object.assign(Vt.hrtime.bind(Vt),{bigint:hrtimeBigint}),Vt.uptime.bind(Vt),Vt.memoryUsage.bind(Vt),Vt.cpuUsage.bind(Vt),Vt.kill.bind(Vt),Vt.abort.bind(Vt),Vt.umask.bind(Vt),Vt.emitWarning.bind(Vt),Vt.execArgv,Vt.config,Vt.stdout,Vt.stderr,Vt.stdin,typeof Promise.withResolvers!=`function`&&(Promise.withResolvers=function(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}),initErrorV8Methods(Error),`global`in globalThis||Object.defineProperty(globalThis,"global",{value:globalThis,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(globalThis,"process",{value:Vt,enumerable:!1,writable:!0,configurable:!0}),typeof globalThis.structuredClone!=`function`&&Object.defineProperty(globalThis,"structuredClone",{value:structuredClone$1,enumerable:!0,writable:!0,configurable:!0});function getGLib(){return globalThis.imports?.gi?.GLib}const Ht=getGLib()!==void 0;var GjsifyTimeout=class{_id=null;_refed=!0;_callback;_delay;_args;_repeat;constructor(e,t,n,r){this._callback=e,this._delay=t,this._args=n,this._repeat=r,this._schedule()}_schedule(){let e=getGLib();if(!e)return;let t=e.timeout_add.bind(e);this._id=t(e.PRIORITY_DEFAULT,this._delay,()=>{try{this._callback.apply(globalThis,this._args)}catch(e){setTimeout(()=>{throw e},0)}return this._repeat?e.SOURCE_CONTINUE:(this._id=null,e.SOURCE_REMOVE)})}ref(){return this._refed=!0,this}unref(){return this._refed=!1,this}hasRef(){return this._refed}refresh(){return this._cancel(),this._schedule(),this}_cancel(){this._id!==null&&(getGLib()?.Source.remove(this._id),this._id=null)}[Symbol.toPrimitive](){return this._id}[Symbol.dispose](){this._cancel()}};function removeById(e){e instanceof GjsifyTimeout?e._cancel():typeof e==`number`&&getGLib()?.Source.remove(e)}if(Ht){let setT=(e,t=0,...n)=>new GjsifyTimeout(e,Math.max(0,t|0),n,!1),setI=(e,t=0,...n)=>new GjsifyTimeout(e,Math.max(0,t|0),n,!0),e=globalThis;e.setTimeout=setT,e.clearTimeout=removeById,e.setInterval=setI,e.clearInterval=removeById}function setImmediate(e,...t){return setTimeout(e,0,...t)}function clearImmediate(e){clearTimeout(e)}`setImmediate`in globalThis||Object.defineProperty(globalThis,"setImmediate",{value:setImmediate,enumerable:!0,writable:!0,configurable:!0}),`clearImmediate`in globalThis||Object.defineProperty(globalThis,"clearImmediate",{value:clearImmediate,enumerable:!0,writable:!0,configurable:!0});const Ut=_t.UriFlags.HAS_PASSWORD|_t.UriFlags.ENCODED|_t.UriFlags.SCHEME_NORMALIZE;var Wt=class URLSearchParams{_entries=[];constructor(e){if(e)if(typeof e==`string`){let t=e.startsWith(`?`)?e.slice(1):e;if(t)for(let e of t.split(`&`)){let t=e.indexOf(`=`);t===-1?this._entries.push([decodeComponent(e),``]):this._entries.push([decodeComponent(e.slice(0,t)),decodeComponent(e.slice(t+1))])}}else if(Array.isArray(e))for(let[t,n]of e)this._entries.push([String(t),String(n)]);else if(e instanceof URLSearchParams)this._entries=e._entries.map(([e,t])=>[e,t]);else for(let t of Object.keys(e))this._entries.push([t,String(e[t])])}get(e){for(let[t,n]of this._entries)if(t===e)return n;return null}getAll(e){return this._entries.filter(([t])=>t===e).map(([,e])=>e)}set(e,t){let n=!1;if(this._entries=this._entries.filter(([t])=>t===e?n?!1:(n=!0,!0):!0),n){for(let n=0;n<this._entries.length;n++)if(this._entries[n][0]===e){this._entries[n][1]=t;break}}else this._entries.push([e,t])}has(e){return this._entries.some(([t])=>t===e)}delete(e){this._entries=this._entries.filter(([t])=>t!==e)}append(e,t){this._entries.push([e,t])}sort(){this._entries.sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0]))}toString(){return this._entries.map(([e,t])=>encodeComponent(e)+`=`+encodeComponent(t)).join(`&`)}forEach(e){for(let[t,n]of this._entries)e(n,t,this)}*entries(){yield*this._entries}*keys(){for(let[e]of this._entries)yield e}*values(){for(let[,e]of this._entries)yield e}[Symbol.iterator](){return this.entries()}get size(){return this._entries.length}};function decodeComponent(e){try{return decodeURIComponent(e.replace(/\+/g,` `))}catch{return e}}function encodeComponent(e){return encodeURIComponent(e).replace(/%20/g,`+`)}var Gt=class URL{#e;#t;constructor(e,t){let n=e instanceof URL?e.href:String(e);try{if(t!==void 0){let e=t instanceof URL?t.href:String(t),r=_t.Uri.parse(e,Ut);this.#e=r.parse_relative(n,Ut)}else this.#e=_t.Uri.parse(n,Ut)}catch{throw TypeError(`Invalid URL: ${n}`)}if(!this.#e)throw TypeError(`Invalid URL: ${n}`);this.#t=new Wt(this.#e.get_query()||``)}get protocol(){return this.#e.get_scheme()+`:`}get hostname(){return(this.#e.get_host()||``).toLowerCase()}get port(){let e=this.#e.get_port();if(e===-1)return``;let t=this.#e.get_scheme();return(t===`http`||t===`ws`)&&e===80||(t===`https`||t===`wss`)&&e===443||t===`ftp`&&e===21?``:String(e)}get host(){let e=this.hostname,t=this.port;return t?`${e}:${t}`:e}get pathname(){return this.#e.get_path()||`/`}get search(){let e=this.#e.get_query();return e?`?`+e:``}get hash(){let e=this.#e.get_fragment();return e?`#`+e:``}get origin(){let e=this.protocol;return e===`http:`||e===`https:`||e===`ftp:`?`${e}//${this.host}`:`null`}get username(){return this.#e.get_user()||``}get password(){return this.#e.get_password()||``}get href(){let e=this.protocol,t=this.#e.get_scheme();(t===`http`||t===`https`||t===`ftp`||t===`file`||t===`ws`||t===`wss`||this.hostname)&&(e+=`//`);let n=this.username,r=this.password;n&&(e+=n,r&&(e+=`:`+r),e+=`@`),e+=this.hostname,this.port&&(e+=`:`+this.port);let i=this.pathname;return e+=i,e+=this.search,e+=this.hash,e}get searchParams(){return this.#t}toString(){return this.href}toJSON(){return this.href}static _objectURLPaths=new Map;static _objectURLCounter=0;static createObjectURL(e){let t=e?._tmpPath;if(typeof t==`string`&&t.length>0){let e=`file://${t}`;return URL._objectURLPaths.set(e,t),e}return`file:///dev/null`}static revokeObjectURL(e){let t=URL._objectURLPaths.get(e);t&&(_t.unlink(t),URL._objectURLPaths.delete(e))}};typeof globalThis.URL!=`function`&&Object.defineProperty(globalThis,"URL",{value:Gt,enumerable:!1,writable:!0,configurable:!0}),typeof globalThis.URLSearchParams!=`function`&&Object.defineProperty(globalThis,"URLSearchParams",{value:Wt,enumerable:!1,writable:!0,configurable:!0});let Kt;if(globalThis.performance)Kt=globalThis.performance;else{let e,_now;try{let t=globalThis.imports?.gi?.GLib;if(!t)throw Error(`GJS imports.gi.GLib not available`);e=t.get_monotonic_time(),_now=()=>(t.get_monotonic_time()-e)/1e3}catch{let t=Date.now();e=0,_now=()=>Date.now()-t}let t=[],n=Date.now()-_now();Kt={timeOrigin:n,now:_now,mark(e){let n={name:e,entryType:`mark`,startTime:_now(),duration:0};return t.push(n),n},measure(e,n,r){let i=0,a=_now();if(n){let e=t.find(e=>e.entryType===`mark`&&e.name===n);e&&(i=e.startTime)}if(r){let e=t.find(e=>e.entryType===`mark`&&e.name===r);e&&(a=e.startTime)}let o={name:e,entryType:`measure`,startTime:i,duration:a-i};return t.push(o),o},getEntries(){return[...t]},getEntriesByName(e){return t.filter(t=>t.name===e)},getEntriesByType(e){return t.filter(t=>t.entryType===e)},clearMarks(e){for(let n=t.length-1;n>=0;n--)t[n].entryType===`mark`&&(!e||t[n].name===e)&&t.splice(n,1)},clearMeasures(e){for(let n=t.length-1;n>=0;n--)t[n].entryType===`measure`&&(!e||t[n].name===e)&&t.splice(n,1)},clearResourceTimings(){},setResourceTimingBufferSize(){},toJSON(){return{timeOrigin:n}}}}var PerformanceObserverStub=class{_callback;constructor(e){this._callback=e}observe(e){}disconnect(){}takeRecords(){return[]}};const qt=globalThis,Jt=qt.PerformanceObserver||PerformanceObserverStub;qt.PerformanceEntry,qt.PerformanceObserverEntryList,qt.PerformanceMark,qt.PerformanceMeasure;const Yt=globalThis;globalThis.performance===void 0&&(Yt.performance=Kt),typeof Yt.PerformanceObserver!=`function`&&(Yt.PerformanceObserver=Jt);var WebGLUniformLocation=class{constructor(e,t,n){this._linkCount=0,this._array=null,this._=e,this._program=t,this._linkCount=t._linkCount,this._activeInfo=n,this._array=null}};function checkObject(e){return typeof e==`object`||e===void 0}function checkUniform(e,t){return t instanceof WebGLUniformLocation&&t._program===e&&t._linkCount===e._linkCount}function isTypedArray$1(e){return e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int8Array||e instanceof Uint16Array||e instanceof Int16Array||e instanceof Uint32Array||e instanceof Int32Array||e instanceof Float32Array||e instanceof Float64Array}__name(isTypedArray$1,`isTypedArray`);function isValidString(e){let t=e.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm,``);return!/["$`@\\'\0]/.test(t)}function vertexCount(e,t,n){switch(t){case e.TRIANGLES:return n-n%3;case e.LINES:return n-n%2;case e.LINE_LOOP:case e.POINTS:return n;case e.TRIANGLE_FAN:case e.LINE_STRIP:return n<2?0:n;case e.TRIANGLE_STRIP:return n<3?0:n;default:return-1}}function typeSize(e,t){switch(t){case e.UNSIGNED_BYTE:case e.BYTE:return 1;case e.UNSIGNED_SHORT:case e.SHORT:return 2;case e.UNSIGNED_INT:case e.INT:case e.FLOAT:return 4}return 0}function uniformTypeSize(e,t){switch(t){case e.BOOL_VEC4:case e.INT_VEC4:case e.FLOAT_VEC4:return 4;case e.BOOL_VEC3:case e.INT_VEC3:case e.FLOAT_VEC3:return 3;case e.BOOL_VEC2:case e.INT_VEC2:case e.FLOAT_VEC2:return 2;case e.BOOL:case e.INT:case e.FLOAT:case e.SAMPLER_2D:case e.SAMPLER_CUBE:return 1;default:return 0}}const listToArray=e=>{let t=[];for(let n of e.values())t.push(n);return t};function arrayToUint8Array(e){if(isTypedArray$1(e))return new Uint8Array(e.buffer).subarray(e.byteOffset,e.byteLength+e.byteOffset);if(Array.isArray(e)||e instanceof ArrayBuffer)return new Uint8Array(e);if(typeof e.values==`function`)return new Uint8Array(listToArray(e));throw Error(`Can't unpack typed array!`)}function Uint8ArrayToVariant(e){return new _t.Variant(`ay`,e)}const extractImageData=e=>{let t=e.width,n=e.height;if(typeof e==`object`&&t!==void 0&&n!==void 0){if(e.data!==void 0)return e;let r=null;if(typeof e.getContext==`function`)r=e.getContext(`2d`);else if(typeof e.isPixbuf==`function`&&e.isPixbuf())return e.getImageData();else if(e.src!==void 0&&typeof document==`object`&&typeof document.createElement==`function`){let i=document.createElement(`canvas`);typeof i==`object`&&typeof i.getContext==`function`&&(i.width=t,i.height=n,r=i.getContext(`2d`),r!==null&&r.drawImage(e,0,0))}if(r!==null)return r.getImageData(0,0,t,n)}return null};function formatSize(e,t){switch(t){case e.ALPHA:case e.LUMINANCE:return 1;case e.LUMINANCE_ALPHA:return 2;case e.RGB:return 3;case e.RGBA:return 4}return 0}function convertPixels(e){if(typeof e==`object`&&e){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint8ClampedArray||e instanceof Float32Array)return arrayToUint8Array(e);if(e instanceof Buffer)return new Uint8Array(e)}return null}function checkFormat(e,t){return t===e.ALPHA||t===e.LUMINANCE_ALPHA||t===e.LUMINANCE||t===e.RGB||t===e.RGBA}function validCubeTarget(e,t){return t===e.TEXTURE_CUBE_MAP_POSITIVE_X||t===e.TEXTURE_CUBE_MAP_NEGATIVE_X||t===e.TEXTURE_CUBE_MAP_POSITIVE_Y||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Y||t===e.TEXTURE_CUBE_MAP_POSITIVE_Z||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Z}function flag(e,t,n){return!e||typeof e!=`object`||!(t in e)?n:!!e[t]}function premultiplyAlpha(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=4){let r=e[n+3]/255;t[n]=Math.round(e[n]*r),t[n+1]=Math.round(e[n+1]*r),t[n+2]=Math.round(e[n+2]*r),t[n+3]=e[n+3]}return t}var Linkable=class{constructor(e){this._=0,this._references=[],this._refCount=0,this._pendingDelete=!1,this._binding=0,this._=e,this._references=[],this._refCount=0,this._pendingDelete=!1,this._binding=0}_link(e){return this._references.push(e),e._refCount+=1,!0}_unlink(e){let t=this._references.indexOf(e);if(t<0)return!1;for(;t>=0;)this._references[t]=this._references[this._references.length-1],this._references.pop(),--e._refCount,e._checkDelete(),t=this._references.indexOf(e);return!0}_linked(e){return this._references.indexOf(e)>=0}_checkDelete(){if(this._refCount<=0&&this._pendingDelete&&this._!==0){for(;this._references.length>0;)this._unlink(this._references[0]);this._performDelete(),this._=0}}_performDelete(){}},WebGLBuffer=class extends Linkable{constructor(e,t){super(e),this._size=0,this._elements=new Uint8Array,this._ctx=t}_performDelete(){let e=this._ctx;delete e._buffers[this._|0],e._gl.deleteBuffer(this._)}};const Xt={bindBuffer(e=0,t){if(!checkObject(t))throw TypeError(`bindBuffer(GLenum, WebGLBuffer)`);if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}if(!t)t=null,this._gl.bindBuffer(e,0);else if(t._pendingDelete)return;else if(this._checkWrapper(t,WebGLBuffer)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e|0,this._gl.bindBuffer(e,t._|0)}else return;e===this.ARRAY_BUFFER?this._vertexGlobalState.setArrayBuffer(t):this._vertexObjectState.setElementArrayBuffer(t)},bufferData(e=0,t,n=0){let r=0,i=null;if(typeof t==`number`?r=t:typeof t==`object`&&(i=t),n!==this.STREAM_DRAW&&n!==this.STATIC_DRAW&&n!==this.DYNAMIC_DRAW){this.setError(this.INVALID_ENUM);return}if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}let a=this._getActiveBuffer(e);if(!a){this.setError(this.INVALID_OPERATION);return}if(i){let t=null;if(isTypedArray$1(i)||i instanceof DataView||i instanceof ArrayBuffer)t=arrayToUint8Array(i);else{this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.bufferData(e,Uint8ArrayToVariant(t),n);let r=this.getError();if(this._restoreError(r),r!==this.NO_ERROR)return;a._size=t.length,e===this.ELEMENT_ARRAY_BUFFER&&(a._elements=new Uint8Array(t))}else if(typeof t==`number`){if(r<0){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.bufferDataSizeOnly(e,r,n);let t=this.getError();if(this._restoreError(t),t!==this.NO_ERROR)return;a._size=r,e===this.ELEMENT_ARRAY_BUFFER&&(a._elements=new Uint8Array(r))}else this.setError(this.INVALID_VALUE)},bufferSubData(e=0,t=0,n){if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}if(typeof n!=`object`||!n)throw TypeError(`bufferSubData: data must be a BufferSource`);let r=this._getActiveBuffer(e);if(!r){this.setError(this.INVALID_OPERATION);return}if(t<0||t>=r._size){this.setError(this.INVALID_VALUE);return}let i=null;if(isTypedArray$1(n)||n instanceof DataView||n instanceof ArrayBuffer)i=arrayToUint8Array(n);else{this.setError(this.INVALID_VALUE);return}if(t+i.length>r._size){this.setError(this.INVALID_VALUE);return}e===this.ELEMENT_ARRAY_BUFFER&&r._elements.set(i,t),this._gl.bufferSubData(e,t,Uint8ArrayToVariant(i))},createBuffer(){let e=this._gl.createBuffer();if(!e||e<=0)return null;let t=new WebGLBuffer(e,this);return this._buffers[e]=t,t},deleteBuffer(e){if(!checkObject(e)||e!==null&&!(e instanceof WebGLBuffer))throw TypeError(`deleteBuffer(WebGLBuffer)`);if(!(e instanceof WebGLBuffer&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._vertexGlobalState._arrayBufferBinding===e&&this.bindBuffer(this.ARRAY_BUFFER,null),this._vertexObjectState._elementArrayBufferBinding===e&&this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this._vertexObjectState===this._defaultVertexObjectState&&this._vertexObjectState.releaseArrayBuffer(e),e._pendingDelete=!0,e._checkDelete()},getBufferParameter(e=0,t=0){if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER)return this.setError(this.INVALID_ENUM),null;switch(t){case this.BUFFER_SIZE:case this.BUFFER_USAGE:return this._gl.getBufferParameteriv(e|0,t|0)[0];default:return this.setError(this.INVALID_ENUM),null}},_getActiveBuffer(e){return e===this.ARRAY_BUFFER?this._vertexGlobalState._arrayBufferBinding:e===this.ELEMENT_ARRAY_BUFFER?this._vertexObjectState._elementArrayBufferBinding:null}};function installBufferBindingMethods(e){Object.assign(e,Xt)}const Zt={drawArrays(e=0,t=0,n=0){if(t<0||n<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let r=vertexCount(this,e,n);if(r<0){this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk()||n===0)return;let i=t;n>0&&(i=n+t-1>>>0),this._checkVertexAttribState(i)&&this._gl.drawArrays(e,t,r)},drawElements(e=0,t=0,n=0,r=0){if(t<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=this._vertexObjectState._elementArrayBufferBinding;if(!i){this.setError(this.INVALID_OPERATION);return}let a=null,o=r;if(n===this.UNSIGNED_SHORT){if(o%2){this.setError(this.INVALID_OPERATION);return}o>>=1,a=new Uint16Array(i._elements.buffer)}else if(this._extensions.oes_element_index_uint&&n===this.UNSIGNED_INT){if(o%4){this.setError(this.INVALID_OPERATION);return}o>>=2,a=new Uint32Array(i._elements.buffer)}else if(n===this.UNSIGNED_BYTE)a=i._elements;else{this.setError(this.INVALID_ENUM);return}let s=t;switch(e){case this.TRIANGLES:t%3&&(s-=t%3);break;case this.LINES:t%2&&(s-=t%2);break;case this.POINTS:break;case this.LINE_LOOP:case this.LINE_STRIP:if(t<2){this.setError(this.INVALID_OPERATION);return}break;case this.TRIANGLE_FAN:case this.TRIANGLE_STRIP:if(t<3){this.setError(this.INVALID_OPERATION);return}break;default:this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk())return;if(t===0){this._checkVertexAttribState(0);return}if(t+o>>>0>a.length){this.setError(this.INVALID_OPERATION);return}let c=-1;for(let e=o;e<o+t;++e)c=Math.max(c,a[e]);if(c<0){this._checkVertexAttribState(0);return}this._checkVertexAttribState(c)&&s>0&&this._gl.drawElements(e,s,n,r)},viewport(e,t,n,r){this._viewport[0]=e|0,this._viewport[1]=t|0,this._viewport[2]=n|0,this._viewport[3]=r|0,this._gl.viewport(e,t,n,r)},scissor(e,t,n,r){this._scissorBox[0]=e|0,this._scissorBox[1]=t|0,this._scissorBox[2]=n|0,this._scissorBox[3]=r|0,this._gl.scissor(e|0,t|0,n|0,r|0)},readPixels(e=0,t=0,n=0,r=0,i=0,a=0,o){if(!o)return;if(!(this._extensions.oes_texture_float&&a===this.FLOAT&&i===this.RGBA)){if(i===this.RGB||i===this.ALPHA||a!==this.UNSIGNED_BYTE){this.setError(this.INVALID_OPERATION);return}else if(i!==this.RGBA){this.setError(this.INVALID_ENUM);return}else if(n<0||r<0||!(o instanceof Uint8Array)){this.setError(this.INVALID_VALUE);return}}if(!this._framebufferOk()){A.error(`framebuffer is not okay!`);return}let s=n*4;s%this._packAlignment!==0&&(s+=this._packAlignment-s%this._packAlignment);let c=s*(r-1)+n*4;if(c<=0)return;if((o.length||o.byteLength||0)<c){this.setError(this.INVALID_VALUE);return}let l=this.drawingBufferWidth,u=this.drawingBufferHeight;this._activeFramebuffer&&(l=this._activeFramebuffer._width,u=this._activeFramebuffer._height);let d=arrayToUint8Array(o);if(e>=l||e+n<=0||t>=u||t+r<=0)for(let e=0;e<d.length;++e)d[e]=0;else if(e<0||e+n>l||t<0||t+r>u){for(let e=0;e<d.length;++e)d[e]=0;let o=e,c=n;e<0&&(c+=e,o=0),o+n>l&&(c=l-o);let f=t,p=r;t<0&&(p+=t,f=0),f+r>u&&(p=u-f);let m=c*4;if(m%this._packAlignment!==0&&(m+=this._packAlignment-m%this._packAlignment),c>0&&p>0){let n=new Uint8Array(m*p),r=this._gl.readPixels(o,f,c,p,i,a,Uint8ArrayToVariant(n)),l=r&&r.length>0?r:n,u=4*(o-e)+(f-t)*s;for(let e=0;e<p;++e)for(let t=0;t<c;++t)for(let n=0;n<4;++n)d[u+e*s+4*t+n]=l[e*m+4*t+n]}}else{let o=this._gl.readPixels(e,t,n,r,i,a,Uint8ArrayToVariant(d));o&&o.length>0&&d.set(o)}},enableVertexAttribArray(e){if(e<0||e>=this._vertexObjectState._attribs.length){this.setError(this.INVALID_VALUE);return}this._gl.enableVertexAttribArray(e),this._vertexObjectState._attribs[e]._isPointer=!0},disableVertexAttribArray(e=0){if(e<0||e>=this._vertexObjectState._attribs.length){this.setError(this.INVALID_VALUE);return}this._gl.disableVertexAttribArray(e),this._vertexObjectState._attribs[e]._isPointer=!1},vertexAttrib1f(e,t){if(e|=0,!this._checkVertexIndex(e))return;let n=this._vertexGlobalState._attribs[e]._data;n[3]=1,n[1]=n[2]=0,n[0]=t,this._gl.vertexAttrib1f(e|0,+t)},vertexAttrib1fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<1){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;n[3]=1,n[2]=0,n[1]=0,n[0]=t[0],this._gl.vertexAttrib1f(e|0,+t[0])},vertexAttrib2f(e,t,n){if(e|=0,!this._checkVertexIndex(e))return;let r=this._vertexGlobalState._attribs[e]._data;r[3]=1,r[2]=0,r[1]=n,r[0]=t,this._gl.vertexAttrib2f(e|0,+t,+n)},vertexAttrib2fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<2){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;n[3]=1,n[2]=0,n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib2f(e|0,+t[0],+t[1])},vertexAttrib3f(e,t,n,r){if(e|=0,!this._checkVertexIndex(e))return;let i=this._vertexGlobalState._attribs[e]._data;i[3]=1,i[2]=r,i[1]=n,i[0]=t,this._gl.vertexAttrib3f(e|0,+t,+n,+r)},vertexAttrib3fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<3){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;n[3]=1,n[2]=t[2],n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib3f(e|0,+t[0],+t[1],+t[2])},vertexAttrib4f(e=0,t,n,r,i){if(!this._checkVertexIndex(e))return;let a=this._vertexGlobalState._attribs[e]._data;a[3]=i,a[2]=r,a[1]=n,a[0]=t,this._gl.vertexAttrib4f(e|0,+t,+n,+r,+i)},vertexAttrib4fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<4){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;n[3]=t[3],n[2]=t[2],n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib4f(e|0,+t[0],+t[1],+t[2],+t[3])},vertexAttribPointer(e=0,t=0,n=0,r=!1,i=0,a=0){if(i<0||a<0){this.setError(this.INVALID_VALUE);return}if(i<0||a<0||e<0||e>=this._vertexObjectState._attribs.length||!(t===1||t===2||t===3||t===4)){this.setError(this.INVALID_VALUE);return}if(this._vertexGlobalState._arrayBufferBinding===null){this.setError(this.INVALID_OPERATION);return}let o=typeSize(this,n);if(o===0||n===this.INT||n===this.UNSIGNED_INT){this.setError(this.INVALID_ENUM);return}if(i>255||i<0){this.setError(this.INVALID_VALUE);return}if(i%o!==0||a%o!==0){this.setError(this.INVALID_OPERATION);return}this._gl.vertexAttribPointer(e,t,n,r,i,a),this._vertexObjectState.setVertexAttribPointer(this._vertexGlobalState._arrayBufferBinding,e,t*o,a,i||t*o,n,r,i,t)},getVertexAttrib(e=0,t=0){if(e<0||e>=this._vertexObjectState._attribs.length)return this.setError(this.INVALID_VALUE),null;let n=this._vertexObjectState._attribs[e],r=this._vertexGlobalState._attribs[e]._data,i=this._extensions.angle_instanced_arrays;if(i&&t===i.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE)return n._divisor;switch(t){case this.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:return n._pointerBuffer;case this.VERTEX_ATTRIB_ARRAY_ENABLED:return n._isPointer;case this.VERTEX_ATTRIB_ARRAY_SIZE:return n._inputSize;case this.VERTEX_ATTRIB_ARRAY_STRIDE:return n._inputStride;case this.VERTEX_ATTRIB_ARRAY_TYPE:return n._pointerType;case this.VERTEX_ATTRIB_ARRAY_NORMALIZED:return n._pointerNormal;case this.CURRENT_VERTEX_ATTRIB:return new Float32Array(r);default:return this.setError(this.INVALID_ENUM),null}},getVertexAttribOffset(e=0,t=0){return e<0||e>=this._vertexObjectState._attribs.length?(this.setError(this.INVALID_VALUE),-1):t===this.VERTEX_ATTRIB_ARRAY_POINTER?this._vertexObjectState._attribs[e]._pointerOffset:(this.setError(this.INVALID_ENUM),-1)},_checkVertexAttribState(e){let t=this._activeProgram;if(!t)return this.setError(this.INVALID_OPERATION),!1;let n=this._vertexObjectState._attribs;for(let r=0;r<n.length;++r){let i=n[r];if(i._isPointer){let n=i._pointerBuffer;if(!n)return this.setError(this.INVALID_OPERATION),!1;if(t._attributes.indexOf(r)>=0){let t=0;if(t=i._divisor?i._pointerSize+i._pointerOffset:i._pointerStride*e+i._pointerSize+i._pointerOffset,t>n._size)return this.setError(this.INVALID_OPERATION),!1}}}return!0},_checkVertexIndex(e){return e<0||e>=this._vertexObjectState._attribs.length?(this.setError(this.INVALID_VALUE),!1):!0}};function installDrawingMethods(e){Object.assign(e,Zt)}var WebGLDrawingBufferWrapper=class{constructor(e,t,n){this._framebuffer=e,this._color=t,this._depthStencil=n}},WebGLFramebuffer=class extends Linkable{constructor(e,t){if(super(e),this._binding=0,this._width=0,this._height=0,this._status=null,this._ctx=t,this._attachments={},this._attachments[t.COLOR_ATTACHMENT0]=null,this._attachments[t.DEPTH_ATTACHMENT]=null,this._attachments[t.STENCIL_ATTACHMENT]=null,this._attachments[t.DEPTH_STENCIL_ATTACHMENT]=null,this._attachmentLevel={},this._attachmentLevel[t.COLOR_ATTACHMENT0]=0,this._attachmentLevel[t.DEPTH_ATTACHMENT]=0,this._attachmentLevel[t.STENCIL_ATTACHMENT]=0,this._attachmentLevel[t.DEPTH_STENCIL_ATTACHMENT]=0,this._attachmentFace={},this._attachmentFace[t.COLOR_ATTACHMENT0]=0,this._attachmentFace[t.DEPTH_ATTACHMENT]=0,this._attachmentFace[t.STENCIL_ATTACHMENT]=0,this._attachmentFace[t.DEPTH_STENCIL_ATTACHMENT]=0,t._extensions.webgl_draw_buffers){let e=t._extensions.webgl_draw_buffers;this._attachments[e.COLOR_ATTACHMENT1_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT2_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT3_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT4_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT5_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT6_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT7_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT8_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT9_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT10_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT11_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT12_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT13_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT14_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT15_WEBGL]=null,this._attachments[t.NONE]=null,this._attachments[t.BACK]=null,this._attachmentLevel[e.COLOR_ATTACHMENT1_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT2_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT3_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT4_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT5_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT6_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT7_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT8_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT9_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT10_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT11_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT12_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT13_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT14_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT15_WEBGL]=0,this._attachmentLevel[t.NONE]=null,this._attachmentLevel[t.BACK]=null,this._attachmentFace[e.COLOR_ATTACHMENT1_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT2_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT3_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT4_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT5_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT6_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT7_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT8_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT9_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT10_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT11_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT12_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT13_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT14_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT15_WEBGL]=0,this._attachmentFace[t.NONE]=null,this._attachmentFace[t.BACK]=null}}_clearAttachment(e){let t=this._attachments[e];t&&(this._attachments[e]=null,this._unlink(t))}_setAttachment(e,t){this._attachments[t]!==e&&(this._clearAttachment(t),e&&(this._attachments[t]=e,this._link(e)))}_performDelete(){let e=this._ctx;delete e._framebuffers[this._|0],e._gl.deleteFramebuffer(this._|0)}},WebGLRenderbuffer=class extends Linkable{constructor(e,t){super(e),this._binding=0,this._width=0,this._height=0,this._format=0,this._ctx=t,this._binding=0,this._width=0,this._height=0,this._format=0}_performDelete(){let e=this._ctx;delete e._renderbuffers[this._|0],e._gl.deleteRenderbuffer(this._)}},WebGLTexture=class extends Linkable{constructor(e,t){super(e),this._binding=0,this._levelWidth=new Int32Array(32),this._levelHeight=new Int32Array(32),this._format=0,this._type=0,this._complete=!0,this._ctx=t}_performDelete(){let e=this._ctx;delete e._textures[this._|0],e._gl.deleteTexture(this._|0)}};const Qt={bindFramebuffer(e,t){if(!checkObject(t))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(e!==this.FRAMEBUFFER){this.setError(this.INVALID_ENUM);return}if(!t)this._gl.bindFramebuffer(this.FRAMEBUFFER,this._gtkFboId);else if(t._pendingDelete)return;else if(this._checkWrapper(t,WebGLFramebuffer))this._gl.bindFramebuffer(this.FRAMEBUFFER,t._|0);else return;let n=this._activeFramebuffer;n!==t&&(n&&(--n._refCount,n._checkDelete()),t&&(t._refCount+=1)),this._activeFramebuffer=t,t&&this._updateFramebufferAttachments(t)},bindRenderbuffer(e,t){if(!checkObject(t))throw TypeError(`bindRenderbuffer(GLenum, WebGLRenderbuffer)`);if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}if(!t)this._gl.bindRenderbuffer(e|0,0);else if(t._pendingDelete)return;else if(this._checkWrapper(t,WebGLRenderbuffer))this._gl.bindRenderbuffer(e|0,t._|0);else return;let n=this._activeRenderbuffer;n!==t&&(n&&(--n._refCount,n._checkDelete()),t&&(t._refCount+=1)),this._activeRenderbuffer=t},framebufferRenderbuffer(e,t,n,r){if(!checkObject(r))throw TypeError(`framebufferRenderbuffer(GLenum, GLenum, GLenum, WebGLRenderbuffer)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t)||n!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeFramebuffer;if(!i){this.setError(this.INVALID_OPERATION);return}r&&!this._checkWrapper(r,WebGLRenderbuffer)||(i._setAttachment(r,t),this._updateFramebufferAttachments(i))},framebufferTexture2D(e,t,n,r,i=0){if(e|=0,t|=0,n|=0,i|=0,!checkObject(r))throw TypeError(`framebufferTexture2D(GLenum, GLenum, GLenum, WebGLTexture, GLint)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t)){this.setError(this.INVALID_ENUM);return}if(i!==0){this.setError(this.INVALID_VALUE);return}if(r&&!this._checkWrapper(r,WebGLTexture))return;if(n===this.TEXTURE_2D){if(r&&r._binding!==this.TEXTURE_2D){this.setError(this.INVALID_OPERATION);return}}else if(this._validCubeTarget(n)){if(r&&r._binding!==this.TEXTURE_CUBE_MAP){this.setError(this.INVALID_OPERATION);return}}else{this.setError(this.INVALID_ENUM);return}let a=this._activeFramebuffer;if(!a){this.setError(this.INVALID_OPERATION);return}a._attachmentLevel[t]=i,a._attachmentFace[t]=n,a._setAttachment(r,t),this._updateFramebufferAttachments(a)},createFramebuffer(){let e=this._gl.createFramebuffer();if(e<=0)return null;let t=new WebGLFramebuffer(e,this);return this._framebuffers[e]=t,t},deleteFramebuffer(e){if(!checkObject(e))throw TypeError(`deleteFramebuffer(WebGLFramebuffer)`);if(!(e instanceof WebGLFramebuffer&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeFramebuffer===e&&this.bindFramebuffer(this.FRAMEBUFFER,null),e._pendingDelete=!0,e._checkDelete()},createRenderbuffer(){let e=this._gl.createRenderbuffer();if(e<=0)return null;let t=new WebGLRenderbuffer(e,this);return this._renderbuffers[e]=t,t},deleteRenderbuffer(e){if(!checkObject(e))throw TypeError(`deleteRenderbuffer(WebGLRenderbuffer)`);if(!(e instanceof WebGLRenderbuffer&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeRenderbuffer===e&&this.bindRenderbuffer(this.RENDERBUFFER,null),this._detachRenderbufferFromAllFramebuffers(e),e._pendingDelete=!0,e._checkDelete()},renderbufferStorage(e=0,t=0,n=0,r=0){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(t!==this.RGBA4&&t!==this.RGB565&&t!==this.RGB5_A1&&t!==this.DEPTH_COMPONENT16&&t!==this.STENCIL_INDEX&&t!==this.STENCIL_INDEX8&&t!==this.DEPTH_STENCIL){this.setError(this.INVALID_ENUM);return}this._saveError(),this._gl.renderbufferStorage(e,t,n,r);let a=this.getError();if(this._restoreError(a),a!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let o=this._activeFramebuffer;if(o){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(o._attachments[t[n]]===i){e=!0;break}e&&this._updateFramebufferAttachments(this._activeFramebuffer)}},getFramebufferAttachmentParameter(e=0,t=0,n=0){if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t))return this.setError(this.INVALID_ENUM),null;let r=this._activeFramebuffer;if(!r)return this.setError(this.INVALID_OPERATION),null;let i=r._attachments[t];if(i===null){if(n===this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)return this.NONE}else if(i instanceof WebGLTexture)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return i;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.TEXTURE;case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:return r._attachmentLevel[t];case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:{let e=r._attachmentFace[t];return e===this.TEXTURE_2D?0:e}}else if(i instanceof WebGLRenderbuffer)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return i;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.RENDERBUFFER}return this.setError(this.INVALID_ENUM),null},getRenderbufferParameter(e=0,t=0){if(e!==this.RENDERBUFFER)return this.setError(this.INVALID_ENUM),null;let n=this._activeRenderbuffer;if(!n)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.RENDERBUFFER_INTERNAL_FORMAT:return n._format;case this.RENDERBUFFER_WIDTH:return n._width;case this.RENDERBUFFER_HEIGHT:return n._height;case this.MAX_RENDERBUFFER_SIZE:return this._maxRenderbufferSize;case this.RENDERBUFFER_RED_SIZE:case this.RENDERBUFFER_GREEN_SIZE:case this.RENDERBUFFER_BLUE_SIZE:case this.RENDERBUFFER_ALPHA_SIZE:case this.RENDERBUFFER_DEPTH_SIZE:case this.RENDERBUFFER_STENCIL_SIZE:return this._gl.getRenderbufferParameter(e,t)}return this.setError(this.INVALID_ENUM),null},checkFramebufferStatus(e){if(e!==this.FRAMEBUFFER)return this.setError(this.INVALID_ENUM),0;let t=this._activeFramebuffer;return t?this._preCheckFramebufferStatus(t):this.FRAMEBUFFER_COMPLETE},_preCheckFramebufferStatus(e){let t=e._attachments,n=[],r=[],i=t[this.DEPTH_ATTACHMENT],a=t[this.DEPTH_STENCIL_ATTACHMENT],o=t[this.STENCIL_ATTACHMENT];if(a&&(o||i)||o&&i)return this.FRAMEBUFFER_UNSUPPORTED;let s=this._getColorAttachments(),c=0;for(let e in t)t[e]&&s.indexOf(Number(e))!==-1&&c++;if(c===0)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(a instanceof WebGLTexture)return this.FRAMEBUFFER_UNSUPPORTED;if(a instanceof WebGLRenderbuffer){if(a._format!==this.DEPTH_STENCIL)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(a._width),r.push(a._height)}if(i instanceof WebGLTexture)return this.FRAMEBUFFER_UNSUPPORTED;if(i instanceof WebGLRenderbuffer){if(i._format!==this.DEPTH_COMPONENT16)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(i._width),r.push(i._height)}if(o instanceof WebGLTexture)return this.FRAMEBUFFER_UNSUPPORTED;if(o instanceof WebGLRenderbuffer){if(o._format!==this.STENCIL_INDEX8)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(o._width),r.push(o._height)}let l=!1;for(let i=0;i<s.length;++i){let a=t[s[i]];if(a instanceof WebGLTexture){if(a._format!==this.RGBA||!(a._type===this.UNSIGNED_BYTE||a._type===this.FLOAT))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;l=!0;let t=e._attachmentLevel[this.COLOR_ATTACHMENT0];if(t===null)throw TypeError(`level is null!`);n.push(a._levelWidth[t]),r.push(a._levelHeight[t])}else if(a instanceof WebGLRenderbuffer){let e=a._format;if(e!==this.RGBA4&&e!==this.RGB565&&e!==this.RGB5_A1)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;l=!0,n.push(a._width),r.push(a._height)}}if(!l&&!o&&!i&&!a)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(n.length<=0||r.length<=0)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;for(let e=1;e<n.length;++e)if(n[e-1]!==n[e]||r[e-1]!==r[e])return this.FRAMEBUFFER_INCOMPLETE_DIMENSIONS;return n[0]===0||r[0]===0?this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:(e._width=n[0],e._height=r[0],this.FRAMEBUFFER_COMPLETE)},_framebufferOk(){let e=this._activeFramebuffer;return e&&this._preCheckFramebufferStatus(e)!==this.FRAMEBUFFER_COMPLETE?(this.setError(this.INVALID_FRAMEBUFFER_OPERATION),!1):!0},_validFramebufferAttachment(e){switch(e){case this.DEPTH_ATTACHMENT:case this.STENCIL_ATTACHMENT:case this.DEPTH_STENCIL_ATTACHMENT:case this.COLOR_ATTACHMENT0:return!0}if(this._extensions.webgl_draw_buffers){let t=this._extensions.webgl_draw_buffers;return e<t.COLOR_ATTACHMENT0_WEBGL+t._maxDrawBuffers}return!1},_updateFramebufferAttachments(e){if(!e)return;let t=e._status,n=this._getAttachments();if(e._status=this._preCheckFramebufferStatus(e),e._status!==this.FRAMEBUFFER_COMPLETE){if(t===this.FRAMEBUFFER_COMPLETE)for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}return}for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}for(let t=0;t<n.length;++t){let r=n[t],i=e._attachments[r];i instanceof WebGLTexture?this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,i._|0,e._attachmentLevel[r]||0):i instanceof WebGLRenderbuffer&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,r,this.RENDERBUFFER,i._|0)}},_tryDetachFramebuffer(e,t){if(e&&e._linked(t)){let n=this._getAttachments();for(let r=0;r<n.length;++r)e._attachments[n[r]]===t&&this.framebufferTexture2D(this.FRAMEBUFFER,n[r]|0,this.TEXTURE_2D,null)}},_detachRenderbufferFromAllFramebuffers(e){let t=this._activeFramebuffer,n=this._getAttachments(),r=!1;for(let i in this._framebuffers){let a=this._framebuffers[i];if(!(!a||!a._linked(e))){a!==t&&(this._gl.bindFramebuffer(this.FRAMEBUFFER,a._|0),r=!0);for(let t=0;t<n.length;++t){let r=n[t];a._attachments[r]===e&&(this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,r,this.RENDERBUFFER,0),a._setAttachment(null,r))}}}r&&this._gl.bindFramebuffer(this.FRAMEBUFFER,t?t._|0:this._gtkFboId)},_getAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_ATTACHMENTS:this.DEFAULT_ATTACHMENTS},_getColorAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_COLOR_ATTACHMENTS:this.DEFAULT_COLOR_ATTACHMENTS},_resizeDrawingBuffer(e,t){let n=this._activeFramebuffer,r=this._getActiveTexture(this.TEXTURE_2D),i=this._activeRenderbuffer,a=this._contextAttributes,o=this._drawingBuffer;o?._framebuffer&&this._gl.bindFramebuffer(this.FRAMEBUFFER,o?._framebuffer);let s=this._getAttachments();for(let e=0;e<s.length;++e)this._gl.framebufferTexture2D(this.FRAMEBUFFER,s[e],this.TEXTURE_2D,0,0);o?._color&&this._gl.bindTexture(this.TEXTURE_2D,o?._color);let c=a.alpha?this.RGBA:this.RGB;this._gl.texImage2D(this.TEXTURE_2D,0,c,e,t,0,c,this.UNSIGNED_BYTE,Uint8ArrayToVariant(null)),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MIN_FILTER,this.NEAREST),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MAG_FILTER,this.NEAREST),o?._color&&this._gl.framebufferTexture2D(this.FRAMEBUFFER,this.COLOR_ATTACHMENT0,this.TEXTURE_2D,o?._color,0);let l=0,u=0;a.depth&&a.stencil?(l=this.DEPTH_STENCIL,u=this.DEPTH_STENCIL_ATTACHMENT):a.depth?(l=33191,u=this.DEPTH_ATTACHMENT):a.stencil&&(l=this.STENCIL_INDEX8,u=this.STENCIL_ATTACHMENT),l&&(o?._depthStencil&&this._gl.bindRenderbuffer(this.RENDERBUFFER,o?._depthStencil),this._gl.renderbufferStorage(this.RENDERBUFFER,l,e,t),o?._depthStencil&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,u,this.RENDERBUFFER,o?._depthStencil)),this.bindFramebuffer(this.FRAMEBUFFER,n),this.bindTexture(this.TEXTURE_2D,r),this.bindRenderbuffer(this.RENDERBUFFER,i)},_allocateDrawingBuffer(e,t){this._drawingBuffer=new WebGLDrawingBufferWrapper(this._gl.createFramebuffer(),this._gl.createTexture(),this._gl.createRenderbuffer()),this._resizeDrawingBuffer(e,t)},resize(e=0,t=0){if(e|=0,t|=0,e>0&&t>0)(e!==this.drawingBufferWidth||t!==this.drawingBufferHeight)&&this._resizeDrawingBuffer(e,t);else throw Error(`Invalid surface dimensions`)}};function installFramebufferMethods(e){Object.assign(e,Qt)}var WebGLProgram$1=class extends Linkable{static{__name(this,`WebGLProgram`)}constructor(e,t){super(e),this._linkCount=0,this._linkStatus=!1,this._linkInfoLog=`not linked`,this._attributes=[],this._uniforms=[],this._ctx=t,this._linkCount=0,this._linkStatus=!1,this._linkInfoLog=`not linked`,this._attributes=[],this._uniforms=[]}_performDelete(){let e=this._ctx;delete e._programs[this._|0],e._gl.deleteProgram(this._|0)}},WebGLShader$1=class extends Linkable{static{__name(this,`WebGLShader`)}constructor(e,t,n){super(e),this._source=``,this._compileStatus=!1,this._compileInfo=``,this._needsRecompile=!1,this._type=n,this._ctx=t,this._source=``,this._compileStatus=!1,this._compileInfo=``}_performDelete(){let e=this._ctx;delete e._shaders[this._|0],e._gl.deleteShader(this._|0)}};const $t={enable(e=0){this._gl.enable(e)},disable(e=0){if(this._gl.disable(e),e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP){let t=this._getActiveTextureUnit();t._mode===e&&(t._mode=0)}},cullFace(e){this._gl.cullFace(e|0)},depthFunc(e){switch(e|=0,e){case this.NEVER:case this.LESS:case this.EQUAL:case this.LEQUAL:case this.GREATER:case this.NOTEQUAL:case this.GEQUAL:case this.ALWAYS:this._gl.depthFunc(e);return;default:this.setError(this.INVALID_ENUM)}},depthMask(e){this._gl.depthMask(!!e)},depthRange(e,t){if(e=+e,t=+t,e<=t){this._gl.depthRange(e,t);return}this.setError(this.INVALID_OPERATION)},frontFace(e=0){this._gl.frontFace(e)},lineWidth(e){if(isNaN(e)){this.setError(this.INVALID_VALUE);return}this._gl.lineWidth(+e)},polygonOffset(e,t){this._gl.polygonOffset(+e,+t)},sampleCoverage(e,t){this._gl.sampleCoverage(+e,!!t)},hint(e=0,t=0){let n=this._extensions.oes_standard_derivatives;if(!(e===this.GENERATE_MIPMAP_HINT||n&&e===n.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)){this.setError(this.INVALID_ENUM);return}if(t!==this.FASTEST&&t!==this.NICEST&&t!==this.DONT_CARE){this.setError(this.INVALID_ENUM);return}this._gl.hint(e,t)},finish(){this._gl.finish()},flush(){this._gl.flush()},blendColor(e=0,t=0,n=0,r=0){this._gl.blendColor(+e,+t,+n,+r)},blendEquation(e=0){if(this._validBlendMode(e)){this._gl.blendEquation(e);return}this.setError(this.INVALID_ENUM)},blendEquationSeparate(e=0,t=0){if(this._validBlendMode(e)&&this._validBlendMode(t)){this._gl.blendEquationSeparate(e,t);return}this.setError(this.INVALID_ENUM)},blendFunc(e=0,t=0){if(!this._validBlendFunc(e)||!this._validBlendFunc(t)){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFunc(e,t)},blendFuncSeparate(e=0,t=0,n=0,r=0){if(!(this._validBlendFunc(e)&&this._validBlendFunc(t)&&this._validBlendFunc(n)&&this._validBlendFunc(r))){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)||this._isConstantBlendFunc(n)&&this._isConstantBlendFunc(r)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFuncSeparate(e,t,n,r)},clear(e=0){this._framebufferOk()&&this._gl.clear(e)},clearColor(e,t,n,r){this._gl.clearColor(+e,+t,+n,+r)},clearDepth(e){this._gl.clearDepth(+e)},clearStencil(e=0){this._checkStencil=!1,this._gl.clearStencil(e)},colorMask(e,t,n,r){this._gl.colorMask(!!e,!!t,!!n,!!r)},stencilFunc(e,t,n){this._checkStencil=!0,this._gl.stencilFunc(e|0,t|0,n|0)},stencilFuncSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilFuncSeparate(e|0,t|0,n|0,r|0)},stencilMask(e){this._checkStencil=!0,this._gl.stencilMask(e>>>0)},stencilMaskSeparate(e,t){this._checkStencil=!0,this._gl.stencilMaskSeparate(e|0,t>>>0)},stencilOp(e,t,n){this._checkStencil=!0,this._gl.stencilOp(e|0,t|0,n|0)},stencilOpSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilOpSeparate(e|0,t|0,n|0,r|0)},isEnabled(e=0){return this._gl.isEnabled(e)},isContextLost(){return!1},getError(){return this._gl.getError()},setError(e){this._gl.setError(e)},isBuffer(e){return this._isObject(e,`isBuffer`,WebGLBuffer)?this._gl.isBuffer(e?._):!1},isFramebuffer(e){return this._isObject(e,`isFramebuffer`,WebGLFramebuffer)?this._gl.isFramebuffer(e?._):!1},isProgram(e){return this._isObject(e,`isProgram`,WebGLProgram$1)?this._gl.isProgram(e?._):!1},isRenderbuffer(e){return this._isObject(e,`isRenderbuffer`,WebGLRenderbuffer)?this._gl.isRenderbuffer(e?._):!1},isShader(e){return this._isObject(e,`isShader`,WebGLShader$1)?this._gl.isShader(e?._):!1},isTexture(e){return this._isObject(e,`isTexture`,WebGLTexture)?this._gl.isTexture(e?._):!1},generateMipmap(e=0){this._gl.generateMipmap(e)},_validBlendFunc(e){return e===this.ZERO||e===this.ONE||e===this.SRC_COLOR||e===this.ONE_MINUS_SRC_COLOR||e===this.DST_COLOR||e===this.ONE_MINUS_DST_COLOR||e===this.SRC_ALPHA||e===this.ONE_MINUS_SRC_ALPHA||e===this.DST_ALPHA||e===this.ONE_MINUS_DST_ALPHA||e===this.SRC_ALPHA_SATURATE||e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_validBlendMode(e){let t=this._extensions.ext_blend_minmax;return e===this.FUNC_ADD||e===this.FUNC_SUBTRACT||e===this.FUNC_REVERSE_SUBTRACT||!!(t&&(e===t.MIN_EXT||e===t.MAX_EXT))},_isConstantBlendFunc(e){return e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_saveError(){this._errorStack.push(this.getError())},_restoreError(e){let t=this._errorStack.pop();t===this.NO_ERROR?this.setError(e):t!==void 0&&this.setError(t)}};function installStateMethods(e){Object.assign(e,$t)}const en={activeTexture(e=0){let t=e-this.TEXTURE0;if(t>=0&&t<this._textureUnits.length){this._activeTextureUnit=t,this._gl.activeTexture(e);return}this.setError(this.INVALID_ENUM)},bindTexture(e=0,t){if(!checkObject(t))throw TypeError(`bindTexture(GLenum, WebGLTexture)`);if(!this._validTextureTarget(e)){this.setError(this.INVALID_ENUM);return}let n=0;if(!t)t=null;else if(t instanceof WebGLTexture&&t._pendingDelete)return;else if(this._checkWrapper(t,WebGLTexture)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e,t._complete&&(n=t._|0)}else return;this._saveError(),this._gl.bindTexture(e,n);let r=this.getError();if(this._restoreError(r),r!==this.NO_ERROR)return;let i=this._getActiveTextureUnit(),a=this._getActiveTexture(e);a!==t&&(a&&(--a._refCount,a._checkDelete()),t&&(t._refCount+=1)),e===this.TEXTURE_2D?i._bind2D=t:e===this.TEXTURE_CUBE_MAP&&(i._bindCube=t)},createTexture(){let e=this._gl.createTexture();if(e<=0)return null;let t=new WebGLTexture(e,this);return this._textures[e]=t,t},deleteTexture(e){if(!checkObject(e))throw TypeError(`deleteTexture(WebGLTexture)`);if(e instanceof WebGLTexture){if(!this._checkOwns(e)){this.setError(this.INVALID_OPERATION);return}}else return;let t=this._activeTextureUnit;for(let t=0;t<this._textureUnits.length;++t){let n=this._textureUnits[t];n._bind2D===e?(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_2D,null)):n._bindCube===e&&(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_CUBE_MAP,null))}this.activeTexture(this.TEXTURE0+t),this._detachTextureFromAllFramebuffers(e),e._pendingDelete=!0,e._checkDelete()},_detachTextureFromAllFramebuffers(e){let t=this._activeFramebuffer,n=this._getAttachments(),r=!1;for(let i in this._framebuffers){let a=this._framebuffers[i];if(!(!a||!a._linked(e))){a!==t&&(this._gl.bindFramebuffer(this.FRAMEBUFFER,a._|0),r=!0);for(let t=0;t<n.length;++t){let r=n[t];a._attachments[r]===e&&(this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,a._attachmentFace[r]||this.TEXTURE_2D,0,a._attachmentLevel[r]||0),a._setAttachment(null,r))}}}r&&this._gl.bindFramebuffer(this.FRAMEBUFFER,t?t._|0:this._gtkFboId)},pixelStorei(e=0,t=0){if(typeof t==`boolean`&&(t=t===!1?0:1),e===this.UNPACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._unpackAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.PACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._packAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.UNPACK_COLORSPACE_CONVERSION_WEBGL){if(!(t===this.NONE||t===this.BROWSER_DEFAULT_WEBGL)){this.setError(this.INVALID_VALUE);return}}else if(e===this.UNPACK_FLIP_Y_WEBGL){this._unpackFlipY=!!t;return}else if(e===this.UNPACK_PREMULTIPLY_ALPHA_WEBGL){this._unpackPremultAlpha=!!t;return}this._gl.pixelStorei(e,t)}};function installTextureLifecycleMethods(e){Object.assign(e,en)}const tn={texImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c){let u=0,d=0,f=0,p,m,h=0;if(arguments.length===6)if(s=i,f=r,a instanceof l.Pixbuf)m=a,u=m.get_width(),d=m.get_height(),c=m.get_pixels();else{p=a;let e=extractImageData(p);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);u=e.width,d=e.height,c=e.data}else arguments.length===9&&(u=r,d=i,h=a,f=o,c=c);if(typeof c!=`object`&&c!==void 0)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!checkFormat(this,f)||!checkFormat(this,n)){this.setError(this.INVALID_ENUM);return}if(s===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let g=this._getTexImage(e);if(!g||f!==n){this.setError(this.INVALID_OPERATION);return}let _=this._computePixelSize(s,f);if(_===0||!this._checkDimensions(e,u,d,t))return;let v=convertPixels(c),y=this._computeRowStride(u,_),b=y*d;if(v&&v.length<b){this.setError(this.INVALID_OPERATION);return}if(h!==0||validCubeTarget(this,e)&&u!==d){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&v&&f===this.RGBA&&(v=premultiplyAlpha(v)),this._unpackFlipY&&v&&u>0&&d>0){let e=new Uint8Array(v.length);for(let t=0;t<d;t++){let n=t*y,r=(d-1-t)*y;e.set(v.subarray(n,n+y),r)}v=e}this._saveError(),this._gl.texImage2D(e,t,n,u,d,h,f,s,Uint8ArrayToVariant(v));let x=this.getError();if(this._restoreError(x),x!==this.NO_ERROR)return;g._levelWidth[t]=u,g._levelHeight[t]=d,g._format=f,g._type=s;let S=this._activeFramebuffer;if(S){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(S._attachments[t[n]]===g){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}},texSubImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c){let u=0,d=0,f=0,p,m;if(arguments.length===7)if(s=a,f=i,o instanceof l.Pixbuf)m=o,u=m.get_width(),d=m.get_height(),c=m.get_pixels();else{p=o;let e=extractImageData(p);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);u=e.width,d=e.height,c=e.data}else u=i,d=a,f=o;if(typeof c!=`object`)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(s===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let h=this._computePixelSize(s,f);if(h===0||!this._checkDimensions(e,u,d,t))return;if(n<0||r<0){this.setError(this.INVALID_VALUE);return}let g=convertPixels(c),_=this._computeRowStride(u,h),v=_*d;if(!g||g.length<v){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&g&&f===this.RGBA&&(g=premultiplyAlpha(g)),this._unpackFlipY&&g&&u>0&&d>0){let e=new Uint8Array(g.length);for(let t=0;t<d;t++){let n=t*_,r=(d-1-t)*_;e.set(g.subarray(n,n+_),r)}g=e}this._gl.texSubImage2D(e,t,n,r,u,d,f,s,Uint8ArrayToVariant(g))}};function installTexImage2DMethods(e){Object.assign(e,tn)}var nn=__toESM(__commonJSMin((e=>{e.INT_MIN=-1<<31,e.isPow2=function(e){return!(e&e-1)&&!!e},e.log2=function(e){var t=(e>65535)<<4,n;return e>>>=t,n=(e>255)<<3,e>>>=n,t|=n,n=(e>15)<<2,e>>>=n,t|=n,n=(e>3)<<1,e>>>=n,t|=n,t|e>>1},e.nextPow2=function(e){return e+=e===0,--e,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e+1},(function(e){for(var t=0;t<256;++t){var n=t,r=t,i=7;for(n>>>=1;n;n>>>=1)r<<=1,r|=n&1,--i;e[t]=r<<i&255}})(Array(256))}))(),1);const rn={copyTexImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){let c=this._getTexImage(e);if(!c){this.setError(this.INVALID_OPERATION);return}if(n!==this.RGBA&&n!==this.RGB&&n!==this.ALPHA&&n!==this.LUMINANCE&&n!==this.LUMINANCE_ALPHA){this.setError(this.INVALID_ENUM);return}if(t<0||a<0||o<0||s!==0){this.setError(this.INVALID_VALUE);return}if(t>0&&!(nn.isPow2(a)&&nn.isPow2(o))){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.copyTexImage2D(e,t,n,r,i,a,o,s);let l=this.getError();this._restoreError(l),l===this.NO_ERROR&&(c._levelWidth[t]=a,c._levelHeight[t]=o,c._format=this.RGBA,c._type=this.UNSIGNED_BYTE)},copyTexSubImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(o<0||s<0||n<0||r<0||t<0){this.setError(this.INVALID_VALUE);return}this._gl.copyTexSubImage2D(e,t,n,r,i,a,o,s)},compressedTexImage2D(e,t,n,r,i,a,o){this._gl.compressedTexImage2D(e,t,n,r,i,a,Uint8ArrayToVariant(arrayToUint8Array(o)))},compressedTexSubImage2D(e,t,n,r,i,a,o,s){this._gl.compressedTexSubImage2D(e,t,n,r,i,a,o,Uint8ArrayToVariant(arrayToUint8Array(s)))}};function installCopyAndCompressedTextureMethods(e){Object.assign(e,rn)}const an={texParameterf(e=0,t=0,n){if(n=+n,this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameterf(e,t,n);return}let r=this._extensions.ext_texture_filter_anisotropic;if(r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameterf(e,t,n);return}this.setError(this.INVALID_ENUM)}},texParameteri(e=0,t=0,n=0){if(this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameteri(e,t,n);return}let r=this._extensions.ext_texture_filter_anisotropic;if(r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameteri(e,t,n);return}this.setError(this.INVALID_ENUM)}},getTexParameter(e=0,t=0){if(!this._checkTextureTarget(e))return null;let n=this._getActiveTextureUnit();if(e===this.TEXTURE_2D&&!n._bind2D||e===this.TEXTURE_CUBE_MAP&&!n._bindCube)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.TEXTURE_MAG_FILTER:case this.TEXTURE_MIN_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._getTexParameterDirect(e,t)}let r=this._extensions.ext_texture_filter_anisotropic;return r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT?this._getTexParameterDirect(e,t):(this.setError(this.INVALID_ENUM),null)},_getTexParameterDirect(e=0,t=0){return this._gl.getTexParameterx(e,t)?.unpack()}};function installTextureParameterMethods(e){Object.assign(e,an)}const on={_getActiveTextureUnit(){return this._textureUnits[this._activeTextureUnit]},_getActiveTexture(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:e===this.TEXTURE_CUBE_MAP?t._bindCube:null},_getTexImage(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:validCubeTarget(this,e)?t._bindCube:(this.setError(this.INVALID_ENUM),null)},_checkTextureTarget(e){let t=this._getActiveTextureUnit(),n=null;if(e===this.TEXTURE_2D)n=t._bind2D;else if(e===this.TEXTURE_CUBE_MAP)n=t._bindCube;else return this.setError(this.INVALID_ENUM),!1;return n?!0:(this.setError(this.INVALID_OPERATION),!1)},_validTextureTarget(e){return e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP},_validCubeTarget(e){return e===this.TEXTURE_CUBE_MAP_POSITIVE_X||e===this.TEXTURE_CUBE_MAP_NEGATIVE_X||e===this.TEXTURE_CUBE_MAP_POSITIVE_Y||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Y||e===this.TEXTURE_CUBE_MAP_POSITIVE_Z||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Z},_verifyTextureCompleteness(e,t,n){let r=this._getActiveTextureUnit(),i=null;if(e===this.TEXTURE_2D?i=r._bind2D:this._validCubeTarget(e)&&(i=r._bindCube),this._extensions.oes_texture_float&&!this._extensions.oes_texture_float_linear&&i&&i._type===this.FLOAT&&(t===this.TEXTURE_MAG_FILTER||t===this.TEXTURE_MIN_FILTER)&&(n===this.LINEAR||n===this.LINEAR_MIPMAP_NEAREST||n===this.NEAREST_MIPMAP_LINEAR||n===this.LINEAR_MIPMAP_LINEAR)){i._complete=!1,this.bindTexture(e,i);return}i&&i._complete===!1&&(i._complete=!0,this.bindTexture(e,i))},_computePixelSize(e,t){let n=formatSize(this,t);if(n===0)return this.setError(this.INVALID_ENUM),0;switch(e){case this.UNSIGNED_BYTE:return n;case this.UNSIGNED_SHORT_5_6_5:if(t!==this.RGB){this.setError(this.INVALID_OPERATION);break}return 2;case this.UNSIGNED_SHORT_4_4_4_4:case this.UNSIGNED_SHORT_5_5_5_1:if(t!==this.RGBA){this.setError(this.INVALID_OPERATION);break}return 2;case this.FLOAT:return 1}return this.setError(this.INVALID_ENUM),0},_computeRowStride(e,t){let n=e*t;return n%this._unpackAlignment&&(n+=this._unpackAlignment-n%this._unpackAlignment),n},_checkDimensions(e,t,n,r){if(r<0||t<0||n<0)return this.setError(this.INVALID_VALUE),!1;if(e===this.TEXTURE_2D){if(t>this._maxTextureSize||n>this._maxTextureSize||r>this._maxTextureLevel)return this.setError(this.INVALID_VALUE),!1}else if(this._validCubeTarget(e)){if(t>this._maxCubeMapSize||n>this._maxCubeMapSize||r>this._maxCubeMapLevel)return this.setError(this.INVALID_VALUE),!1}else return this.setError(this.INVALID_ENUM),!1;return!0}};function installTextureIntrospectionMethods(e){Object.assign(e,on)}function installTextureManagementMethods(e){installTextureLifecycleMethods(e),installTexImage2DMethods(e),installCopyAndCompressedTextureMethods(e),installTextureParameterMethods(e),installTextureIntrospectionMethods(e)}var WebGLShaderPrecisionFormat=class{constructor(e){this.rangeMin=e.rangeMin,this.rangeMax=e.rangeMax,this.precision=e.precision}},sn=__commonJSMin(((e,t)=>{t.exports=`precision.highp.mediump.lowp.attribute.const.uniform.varying.break.continue.do.for.while.if.else.in.out.inout.float.int.uint.void.bool.true.false.discard.return.mat2.mat3.mat4.vec2.vec3.vec4.ivec2.ivec3.ivec4.bvec2.bvec3.bvec4.sampler1D.sampler2D.sampler3D.samplerCube.sampler1DShadow.sampler2DShadow.struct.asm.class.union.enum.typedef.template.this.packed.goto.switch.default.inline.noinline.volatile.public.static.extern.external.interface.long.short.double.half.fixed.unsigned.input.output.hvec2.hvec3.hvec4.dvec2.dvec3.dvec4.fvec2.fvec3.fvec4.sampler2DRect.sampler3DRect.sampler2DRectShadow.sizeof.cast.namespace.using`.split(`.`)})),cn=__commonJSMin(((e,t)=>{t.exports=`<<= >>= ++ -- << >> <= >= == != && || += -= *= /= %= &= ^^ ^= |= ( ) [ ] . ! ~ * / % + - < > & ^ | ? : = , ; { }`.split(` `)})),ln=__commonJSMin(((e,t)=>{t.exports=`abs.acos.all.any.asin.atan.ceil.clamp.cos.cross.dFdx.dFdy.degrees.distance.dot.equal.exp.exp2.faceforward.floor.fract.gl_BackColor.gl_BackLightModelProduct.gl_BackLightProduct.gl_BackMaterial.gl_BackSecondaryColor.gl_ClipPlane.gl_ClipVertex.gl_Color.gl_DepthRange.gl_DepthRangeParameters.gl_EyePlaneQ.gl_EyePlaneR.gl_EyePlaneS.gl_EyePlaneT.gl_Fog.gl_FogCoord.gl_FogFragCoord.gl_FogParameters.gl_FragColor.gl_FragCoord.gl_FragData.gl_FragDepth.gl_FragDepthEXT.gl_FrontColor.gl_FrontFacing.gl_FrontLightModelProduct.gl_FrontLightProduct.gl_FrontMaterial.gl_FrontSecondaryColor.gl_LightModel.gl_LightModelParameters.gl_LightModelProducts.gl_LightProducts.gl_LightSource.gl_LightSourceParameters.gl_MaterialParameters.gl_MaxClipPlanes.gl_MaxCombinedTextureImageUnits.gl_MaxDrawBuffers.gl_MaxFragmentUniformComponents.gl_MaxLights.gl_MaxTextureCoords.gl_MaxTextureImageUnits.gl_MaxTextureUnits.gl_MaxVaryingFloats.gl_MaxVertexAttribs.gl_MaxVertexTextureImageUnits.gl_MaxVertexUniformComponents.gl_ModelViewMatrix.gl_ModelViewMatrixInverse.gl_ModelViewMatrixInverseTranspose.gl_ModelViewMatrixTranspose.gl_ModelViewProjectionMatrix.gl_ModelViewProjectionMatrixInverse.gl_ModelViewProjectionMatrixInverseTranspose.gl_ModelViewProjectionMatrixTranspose.gl_MultiTexCoord0.gl_MultiTexCoord1.gl_MultiTexCoord2.gl_MultiTexCoord3.gl_MultiTexCoord4.gl_MultiTexCoord5.gl_MultiTexCoord6.gl_MultiTexCoord7.gl_Normal.gl_NormalMatrix.gl_NormalScale.gl_ObjectPlaneQ.gl_ObjectPlaneR.gl_ObjectPlaneS.gl_ObjectPlaneT.gl_Point.gl_PointCoord.gl_PointParameters.gl_PointSize.gl_Position.gl_ProjectionMatrix.gl_ProjectionMatrixInverse.gl_ProjectionMatrixInverseTranspose.gl_ProjectionMatrixTranspose.gl_SecondaryColor.gl_TexCoord.gl_TextureEnvColor.gl_TextureMatrix.gl_TextureMatrixInverse.gl_TextureMatrixInverseTranspose.gl_TextureMatrixTranspose.gl_Vertex.greaterThan.greaterThanEqual.inversesqrt.length.lessThan.lessThanEqual.log.log2.matrixCompMult.max.min.mix.mod.normalize.not.notEqual.pow.radians.reflect.refract.sign.sin.smoothstep.sqrt.step.tan.texture2D.texture2DLod.texture2DProj.texture2DProjLod.textureCube.textureCubeLod.texture2DLodEXT.texture2DProjLodEXT.textureCubeLodEXT.texture2DGradEXT.texture2DProjGradEXT.textureCubeGradEXT`.split(`.`)})),un=__commonJSMin(((e,t)=>{t.exports=sn().slice().concat(`layout.centroid.smooth.case.mat2x2.mat2x3.mat2x4.mat3x2.mat3x3.mat3x4.mat4x2.mat4x3.mat4x4.uvec2.uvec3.uvec4.samplerCubeShadow.sampler2DArray.sampler2DArrayShadow.isampler2D.isampler3D.isamplerCube.isampler2DArray.usampler2D.usampler3D.usamplerCube.usampler2DArray.coherent.restrict.readonly.writeonly.resource.atomic_uint.noperspective.patch.sample.subroutine.common.partition.active.filter.image1D.image2D.image3D.imageCube.iimage1D.iimage2D.iimage3D.iimageCube.uimage1D.uimage2D.uimage3D.uimageCube.image1DArray.image2DArray.iimage1DArray.iimage2DArray.uimage1DArray.uimage2DArray.image1DShadow.image2DShadow.image1DArrayShadow.image2DArrayShadow.imageBuffer.iimageBuffer.uimageBuffer.sampler1DArray.sampler1DArrayShadow.isampler1D.isampler1DArray.usampler1D.usampler1DArray.isampler2DRect.usampler2DRect.samplerBuffer.isamplerBuffer.usamplerBuffer.sampler2DMS.isampler2DMS.usampler2DMS.sampler2DMSArray.isampler2DMSArray.usampler2DMSArray`.split(`.`))})),dn=__commonJSMin(((e,t)=>{var n=ln();n=n.slice().filter(function(e){return!/^(gl\_|texture)/.test(e)}),t.exports=n.concat(`gl_VertexID.gl_InstanceID.gl_Position.gl_PointSize.gl_FragCoord.gl_FrontFacing.gl_FragDepth.gl_PointCoord.gl_MaxVertexAttribs.gl_MaxVertexUniformVectors.gl_MaxVertexOutputVectors.gl_MaxFragmentInputVectors.gl_MaxVertexTextureImageUnits.gl_MaxCombinedTextureImageUnits.gl_MaxTextureImageUnits.gl_MaxFragmentUniformVectors.gl_MaxDrawBuffers.gl_MinProgramTexelOffset.gl_MaxProgramTexelOffset.gl_DepthRangeParameters.gl_DepthRange.trunc.round.roundEven.isnan.isinf.floatBitsToInt.floatBitsToUint.intBitsToFloat.uintBitsToFloat.packSnorm2x16.unpackSnorm2x16.packUnorm2x16.unpackUnorm2x16.packHalf2x16.unpackHalf2x16.outerProduct.transpose.determinant.inverse.texture.textureSize.textureProj.textureLod.textureOffset.texelFetch.texelFetchOffset.textureProjOffset.textureLodOffset.textureProjLod.textureProjLodOffset.textureGrad.textureGradOffset.textureProjGrad.textureProjGradOffset`.split(`.`))})),fn=__commonJSMin(((e,t)=>{t.exports=tokenize;var n=sn(),r=cn(),i=ln(),a=un(),o=dn(),s=999,c=9999,l=0,u=1,d=2,f=3,p=4,m=5,h=6,g=7,_=8,v=9,y=10,b=11,x=[`block-comment`,`line-comment`,`preprocessor`,`operator`,`integer`,`float`,`ident`,`builtin`,`keyword`,`whitespace`,`eof`,`integer`];function tokenize(e){var t=0,S=0,C=s,w,T,E=[],D=[],O=1,ee=0,k=0,te=!1,A=!1,j=``,ne;e||={};var re=i,ie=n;e.version===`300 es`&&(re=o,ie=a);for(var ae={},oe={},t=0;t<re.length;t++)ae[re[t]]=!0;for(var t=0;t<ie.length;t++)oe[ie[t]]=!0;return function(e){return D=[],e===null?end():write(e)};function token(e){e.length&&D.push({type:x[C],data:e,position:k,line:O,column:ee})}function write(e){t=0,e.toString&&(e=e.toString()),j+=e.replace(/\r\n/g,`
|
|
6
|
+
`)){let t=/^(\w+):\s+(\d+)(\s+kB)?/.exec(n);t&&e.set(t[1],parseInt(t[2],10)*(t[3]?1024:1))}if(e.size>0)return{virtual:e.get(`VmSize`)??0,resident:e.get(`VmRSS`)??0,data:e.get(`VmData`)??0,peak:e.get(`VmPeak`)??0}}let n=shellOut(e,`sh -c 'ps -o rss=,vsz= -p $PPID'`);if(!n)return null;let r=/^(\d+)\s+(\d+)$/.exec(n);return r?{virtual:parseInt(r[2],10)*1024,resident:parseInt(r[1],10)*1024,data:0,peak:0}:null}let oe=!1,se=null;function ensureMainLoop(){let e=globalThis.imports;if(!e)return;if(oe)return se;let t=e.gi?.GLib;if(t)return se=new t.MainLoop(null,!1),oe=!0,t.main_depth()===0&&se.runAsync().catch(()=>{}),se}function quitMainLoop(){se&&=(se.quit(),oe=!1,null)}registerGlobal(`Blob`,T),registerGlobal(`File`,E);const ce={aliceblue:`#f0f8ff`,antiquewhite:`#faebd7`,aqua:`#00ffff`,aquamarine:`#7fffd4`,azure:`#f0ffff`,beige:`#f5f5dc`,bisque:`#ffe4c4`,black:`#000000`,blanchedalmond:`#ffebcd`,blue:`#0000ff`,blueviolet:`#8a2be2`,brown:`#a52a2a`,burlywood:`#deb887`,cadetblue:`#5f9ea0`,chartreuse:`#7fff00`,chocolate:`#d2691e`,coral:`#ff7f50`,cornflowerblue:`#6495ed`,cornsilk:`#fff8dc`,crimson:`#dc143c`,cyan:`#00ffff`,darkblue:`#00008b`,darkcyan:`#008b8b`,darkgoldenrod:`#b8860b`,darkgray:`#a9a9a9`,darkgreen:`#006400`,darkgrey:`#a9a9a9`,darkkhaki:`#bdb76b`,darkmagenta:`#8b008b`,darkolivegreen:`#556b2f`,darkorange:`#ff8c00`,darkorchid:`#9932cc`,darkred:`#8b0000`,darksalmon:`#e9967a`,darkseagreen:`#8fbc8f`,darkslateblue:`#483d8b`,darkslategray:`#2f4f4f`,darkslategrey:`#2f4f4f`,darkturquoise:`#00ced1`,darkviolet:`#9400d3`,deeppink:`#ff1493`,deepskyblue:`#00bfff`,dimgray:`#696969`,dimgrey:`#696969`,dodgerblue:`#1e90ff`,firebrick:`#b22222`,floralwhite:`#fffaf0`,forestgreen:`#228b22`,fuchsia:`#ff00ff`,gainsboro:`#dcdcdc`,ghostwhite:`#f8f8ff`,gold:`#ffd700`,goldenrod:`#daa520`,gray:`#808080`,green:`#008000`,greenyellow:`#adff2f`,grey:`#808080`,honeydew:`#f0fff0`,hotpink:`#ff69b4`,indianred:`#cd5c5c`,indigo:`#4b0082`,ivory:`#fffff0`,khaki:`#f0e68c`,lavender:`#e6e6fa`,lavenderblush:`#fff0f5`,lawngreen:`#7cfc00`,lemonchiffon:`#fffacd`,lightblue:`#add8e6`,lightcoral:`#f08080`,lightcyan:`#e0ffff`,lightgoldenrodyellow:`#fafad2`,lightgray:`#d3d3d3`,lightgreen:`#90ee90`,lightgrey:`#d3d3d3`,lightpink:`#ffb6c1`,lightsalmon:`#ffa07a`,lightseagreen:`#20b2aa`,lightskyblue:`#87cefa`,lightslategray:`#778899`,lightslategrey:`#778899`,lightsteelblue:`#b0c4de`,lightyellow:`#ffffe0`,lime:`#00ff00`,limegreen:`#32cd32`,linen:`#faf0e6`,magenta:`#ff00ff`,maroon:`#800000`,mediumaquamarine:`#66cdaa`,mediumblue:`#0000cd`,mediumorchid:`#ba55d3`,mediumpurple:`#9370db`,mediumseagreen:`#3cb371`,mediumslateblue:`#7b68ee`,mediumspringgreen:`#00fa9a`,mediumturquoise:`#48d1cc`,mediumvioletred:`#c71585`,midnightblue:`#191970`,mintcream:`#f5fffa`,mistyrose:`#ffe4e1`,moccasin:`#ffe4b5`,navajowhite:`#ffdead`,navy:`#000080`,oldlace:`#fdf5e6`,olive:`#808000`,olivedrab:`#6b8e23`,orange:`#ffa500`,orangered:`#ff4500`,orchid:`#da70d6`,palegoldenrod:`#eee8aa`,palegreen:`#98fb98`,paleturquoise:`#afeeee`,palevioletred:`#db7093`,papayawhip:`#ffefd5`,peachpuff:`#ffdab9`,peru:`#cd853f`,pink:`#ffc0cb`,plum:`#dda0dd`,powderblue:`#b0e0e6`,purple:`#800080`,rebeccapurple:`#663399`,red:`#ff0000`,rosybrown:`#bc8f8f`,royalblue:`#4169e1`,saddlebrown:`#8b4513`,salmon:`#fa8072`,sandybrown:`#f4a460`,seagreen:`#2e8b57`,seashell:`#fff5ee`,sienna:`#a0522d`,silver:`#c0c0c0`,skyblue:`#87ceeb`,slateblue:`#6a5acd`,slategray:`#708090`,slategrey:`#708090`,snow:`#fffafa`,springgreen:`#00ff7f`,steelblue:`#4682b4`,tan:`#d2b48c`,teal:`#008080`,thistle:`#d8bfd8`,tomato:`#ff6347`,turquoise:`#40e0d0`,violet:`#ee82ee`,wheat:`#f5deb3`,white:`#ffffff`,whitesmoke:`#f5f5f5`,yellow:`#ffff00`,yellowgreen:`#9acd32`,transparent:`#00000000`};function parseColor(e){if(!e||typeof e!=`string`)return null;let t=e.trim().toLowerCase(),n=ce[t];if(n)return parseHex(n);if(t.startsWith(`#`))return parseHex(t);let r=t.match(/^rgba?\(\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*[,\s]\s*(\d+(?:\.\d+)?%?)\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);if(r)return{r:parseComponent(r[1],255)/255,g:parseComponent(r[2],255)/255,b:parseComponent(r[3],255)/255,a:r[4]===void 0?1:parseComponent(r[4],1)};let i=t.match(/^hsla?\(\s*(\d+(?:\.\d+)?)\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*[,\s]\s*(\d+(?:\.\d+)?)(%)?\s*(?:[,/]\s*(\d+(?:\.\d+)?%?))?\s*\)$/);if(i){let e=parseFloat(i[1]),t=parseFloat(i[2]),n=i[3]===`%`,r=parseFloat(i[4]),a=i[5]===`%`,o=i[6]===void 0?1:parseComponent(i[6],1);return e>1&&(e/=360),(n||t>1)&&(t/=100),(a||r>1)&&(r/=100),hslToRGBA(e,t,r,Math.max(0,Math.min(1,o)))}return null}function parseHex(e){let t=e.slice(1),n,r,i,a=1;if(t.length===3)n=parseInt(t[0]+t[0],16)/255,r=parseInt(t[1]+t[1],16)/255,i=parseInt(t[2]+t[2],16)/255;else if(t.length===4)n=parseInt(t[0]+t[0],16)/255,r=parseInt(t[1]+t[1],16)/255,i=parseInt(t[2]+t[2],16)/255,a=parseInt(t[3]+t[3],16)/255;else if(t.length===6)n=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,i=parseInt(t.slice(4,6),16)/255;else if(t.length===8)n=parseInt(t.slice(0,2),16)/255,r=parseInt(t.slice(2,4),16)/255,i=parseInt(t.slice(4,6),16)/255,a=parseInt(t.slice(6,8),16)/255;else return null;return{r:n,g:r,b:i,a}}function parseComponent(e,t){return e.endsWith(`%`)?parseFloat(e)/100*t:parseFloat(e)}function hue2rgb$1(e,t,n){return n<0&&(n+=1),n>1&&--n,n<1/6?e+(t-e)*6*n:n<1/2?t:n<2/3?e+(t-e)*(2/3-n)*6:e}__name(hue2rgb$1,`hue2rgb`);function hslToRGBA(e,t,n,r){let i,a,o;if(t===0)i=a=o=n;else{let r=n<.5?n*(1+t):n+t-n*t,s=2*n-r;i=hue2rgb$1(s,r,e+1/3),a=hue2rgb$1(s,r,e),o=hue2rgb$1(s,r,e-1/3)}return{r:i,g:a,b:o,a:r}}const le={r:0,g:0,b:0,a:1};var CanvasGradient=class{constructor(t,n,r,i,a,o,s){t===`radial`?this._pattern=new e.RadialGradient(n,r,o,i,a,s):this._pattern=new e.LinearGradient(n,r,i,a)}addColorStop(e,t){let n=parseColor(t);n&&this._pattern.addColorStopRGBA(e,n.r,n.g,n.b,n.a)}_getCairoPattern(){return this._pattern}};function quadraticToCubic(e,t,n,r,i,a){return{cp1x:e+2/3*(n-e),cp1y:t+2/3*(r-t),cp2x:i+2/3*(n-i),cp2y:a+2/3*(r-a)}}function computeArcTo(e,t,n,r,i,a,o){let s=e-n,c=t-r,l=i-n,u=a-r,d=Math.sqrt(s*s+c*c),f=Math.sqrt(l*l+u*u);if(d===0||f===0)return null;let p=s/d,m=c/d,h=l/f,g=u/f,_=p*g-m*h;if(Math.abs(_)<1e-10)return null;let v=p*h+m*g,y=Math.acos(Math.max(-1,Math.min(1,v)))/2,b=o/Math.tan(y),x=n+p*b,S=r+m*b,C=n+h*b,w=r+g*b,T=o/Math.sin(y),E=(p+h)/2,D=(m+g)/2,O=Math.sqrt(E*E+D*D),ee=n+E/O*T,k=r+D/O*T;return{tx0:x,ty0:S,tx1:C,ty1:w,cx:ee,cy:k,startAngle:Math.atan2(S-k,x-ee),endAngle:Math.atan2(w-k,C-ee),counterclockwise:_>0}}function cairoArcTo(e,t,n,r,i,a,o,s){let c=computeArcTo(t,n,r,i,a,o,s);if(!c){e.lineTo(r,i);return}let{tx0:l,ty0:u,cx:d,cy:f,startAngle:p,endAngle:m,counterclockwise:h}=c;e.lineTo(l,u),h?e.arcNegative(d,f,s,p,m):e.arc(d,f,s,p,m)}function cairoEllipse(e,t,n,r,i,a,o,s,c){e.save(),e.translate(t,n),e.rotate(a),e.scale(r,i),c?e.arcNegative(0,0,1,o,s):e.arc(0,0,1,o,s),e.restore()}function cairoRoundRect(e,t,n,r,i,a){let o,s,c,l;typeof a==`number`?o=s=c=l=a:a.length===1?o=s=c=l=a[0]:a.length===2?(o=c=a[0],s=l=a[1]):a.length===3?(o=a[0],s=l=a[1],c=a[2]):(o=a[0],s=a[1],c=a[2],l=a[3]);let u=Math.min(r/2,i/2);o=Math.min(o,u),s=Math.min(s,u),c=Math.min(c,u),l=Math.min(l,u);let d=Math.PI/2;e.newSubPath(),e.arc(t+o,n+o,o,Math.PI,Math.PI+d),e.arc(t+r-s,n+s,s,-d,0),e.arc(t+r-c,n+i-c,c,0,d),e.arc(t+l,n+i-l,l,d,Math.PI),e.closePath()}const ue={"source-over":2,"source-in":3,"source-out":4,"source-atop":5,"destination-over":7,"destination-in":8,"destination-out":9,"destination-atop":10,lighter:12,copy:1,xor:11,multiply:14,screen:15,overlay:16,darken:17,lighten:18,"color-dodge":19,"color-burn":20,"hard-light":21,"soft-light":22,difference:23,exclusion:24,hue:25,saturation:26,color:27,luminosity:28},de={butt:0,round:1,square:2},fe={miter:0,round:1,bevel:2};var pe=class Path2D{constructor(e){this._ops=[],e instanceof Path2D&&(this._ops=[...e._ops])}addPath(e){this._ops.push(...e._ops)}moveTo(e,t){this._ops.push({type:`moveTo`,x:e,y:t})}lineTo(e,t){this._ops.push({type:`lineTo`,x:e,y:t})}closePath(){this._ops.push({type:`closePath`})}bezierCurveTo(e,t,n,r,i,a){this._ops.push({type:`bezierCurveTo`,cp1x:e,cp1y:t,cp2x:n,cp2y:r,x:i,y:a})}quadraticCurveTo(e,t,n,r){this._ops.push({type:`quadraticCurveTo`,cpx:e,cpy:t,x:n,y:r})}arc(e,t,n,r,i,a=!1){this._ops.push({type:`arc`,x:e,y:t,radius:n,startAngle:r,endAngle:i,ccw:a})}ellipse(e,t,n,r,i,a,o,s=!1){if(n<0||r<0)throw RangeError(`The radii provided are negative`);this._ops.push({type:`ellipse`,x:e,y:t,rx:n,ry:r,rotation:i,startAngle:a,endAngle:o,ccw:s})}rect(e,t,n,r){this._ops.push({type:`rect`,x:e,y:t,w:n,h:r})}roundRect(e,t,n,r,i=0){this._ops.push({type:`roundRect`,x:e,y:t,w:n,h:r,radii:i})}_replayOnCairo(e){let t=0,n=0;for(let r of this._ops)switch(r.type){case`moveTo`:e.moveTo(r.x,r.y),t=r.x,n=r.y;break;case`lineTo`:e.lineTo(r.x,r.y),t=r.x,n=r.y;break;case`closePath`:e.closePath();break;case`bezierCurveTo`:e.curveTo(r.cp1x,r.cp1y,r.cp2x,r.cp2y,r.x,r.y),t=r.x,n=r.y;break;case`quadraticCurveTo`:{let{cp1x:i,cp1y:a,cp2x:o,cp2y:s}=quadraticToCubic(t,n,r.cpx,r.cpy,r.x,r.y);e.curveTo(i,a,o,s,r.x,r.y),t=r.x,n=r.y;break}case`arc`:r.ccw?e.arcNegative(r.x,r.y,r.radius,r.startAngle,r.endAngle):e.arc(r.x,r.y,r.radius,r.startAngle,r.endAngle);break;case`ellipse`:e.save(),e.translate(r.x,r.y),e.rotate(r.rotation),e.scale(r.rx,r.ry),r.ccw?e.arcNegative(0,0,1,r.startAngle,r.endAngle):e.arc(0,0,1,r.startAngle,r.endAngle),e.restore();break;case`rect`:e.rectangle(r.x,r.y,r.w,r.h);break;case`roundRect`:cairoRoundRect(e,r.x,r.y,r.w,r.h,r.radii);break}}};function asCairoPattern(e){if(!e)return null;let t=e;return typeof t.setFilter!=`function`||typeof t.setExtend!=`function`?null:t}function isPixbufImageSource(e){return typeof e!=`object`||!e?!1:typeof e.isPixbuf==`function`&&e.isPixbuf()}function isCanvasImageSource(e){return typeof e!=`object`||!e?!1:typeof e.getContext==`function`}let me=null;function setCanvasPixelBridge(e){me=e}function getCanvasPixelBridge(){if(!me)throw TypeError(`@gjsify/canvas2d-core: no pixel bridge registered — pixel operations (getImageData / putImageData / drawImage / createPattern) need a platform backend. On GJS, import '@gjsify/canvas2d-core/gdk' (or use '@gjsify/dom-elements' / '@gjsify/canvas2d', which register it for you).`);return me}var he=class CanvasPattern{constructor(t,n){let r=asCairoPattern(new e.SurfacePattern(t));if(!r)throw TypeError(`CanvasPattern: cairo SurfacePattern is missing setExtend at runtime — incompatible Cairo binding`);switch(this._pattern=r,n){case`repeat`:case``:case null:r.setExtend(e.Extend.REPEAT);break;case`repeat-x`:case`repeat-y`:r.setExtend(e.Extend.REPEAT);break;case`no-repeat`:r.setExtend(e.Extend.NONE);break}}static create(t,n){if(isPixbufImageSource(t)){let r=t._pixbuf,i=r.get_width(),a=r.get_height(),o=new e.ImageSurface(e.Format.ARGB32,i,a),s=new e.Context(o);return getCanvasPixelBridge().setSourceImage(s,r,0,0),s.paint(),s.$dispose(),new CanvasPattern(o,n)}if(isCanvasImageSource(t)){let r=t.getContext(`2d`);if(r&&typeof r._getSurface==`function`){let t=r._getSurface(),i=t.getWidth(),a=t.getHeight(),o=new e.ImageSurface(e.Format.ARGB32,i,a),s=new e.Context(o);return s.setSourceSurface(t,0,0),s.paint(),s.$dispose(),new CanvasPattern(o,n)}}return null}_getCairoPattern(){return this._pattern}},OurImageData=class{constructor(e,t,n){if(this.colorSpace=`srgb`,typeof e==`number`)this.width=e,this.height=t,this.data=new Uint8ClampedArray(this.width*this.height*4);else if(this.data=e,this.width=t,this.height=n??this.data.length/(4*this.width),this.data.length!==this.width*this.height*4)throw RangeError(`Source data length ${this.data.length} is not a multiple of (4 * width=${this.width})`)}};const ge={translate(e,t){this._ensureSurface(),this._ctx.translate(e,t)},rotate(e){this._ensureSurface(),this._ctx.rotate(e)},scale(e,t){this._ensureSurface(),this._ctx.scale(e,t)},transform(e,t,n,r,i,a){if(this._ensureSurface(),!Number.isFinite(e)||!Number.isFinite(t)||!Number.isFinite(n)||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(a))return;let o=i,s=a,c=Math.hypot(e,t),l=Math.hypot(n,r),u=Math.atan2(t,e);this._ctx.translate(o,s),u!==0&&this._ctx.rotate(u),(c!==1||l!==1)&&this._ctx.scale(c,l)},setTransform(e,t,n,r,i,a){if(this._ensureSurface(),typeof e==`object`&&e){let t=e;this._ctx.identityMatrix(),this.transform(t.a??t.m11??1,t.b??t.m12??0,t.c??t.m21??0,t.d??t.m22??1,t.e??t.m41??0,t.f??t.m42??0)}else typeof e==`number`?(this._ctx.identityMatrix(),this.transform(e,t,n,r,i,a)):this._ctx.identityMatrix()},getTransform(){let e=this._ctx.userToDevice(0,0),t=this._ctx.userToDevice(1,0),n=this._ctx.userToDevice(0,1),r=e[0]??0,i=e[1]??0,a=(t[0]??0)-r,o=(t[1]??0)-i,s=(n[0]??0)-r,c=(n[1]??0)-i,l=globalThis.DOMMatrix;return typeof l==`function`?new l([a,o,s,c,r,i]):{a,b:o,c:s,d:c,e:r,f:i,m11:a,m12:o,m13:0,m14:0,m21:s,m22:c,m23:0,m24:0,m31:0,m32:0,m33:1,m34:0,m41:r,m42:i,m43:0,m44:1,is2D:!0,isIdentity:a===1&&o===0&&s===0&&c===1&&r===0&&i===0}},resetTransform(){this._ensureSurface(),this._ctx.identityMatrix()}};function installTransformMethods(e){Object.assign(e,ge)}const _e={beginPath(){this._ensureSurface(),this._ctx.newPath()},moveTo(e,t){this._ensureSurface(),this._ctx.moveTo(e,t)},lineTo(e,t){this._ensureSurface(),this._ctx.lineTo(e,t)},closePath(){this._ensureSurface(),this._ctx.closePath()},bezierCurveTo(e,t,n,r,i,a){this._ensureSurface(),this._ctx.curveTo(e,t,n,r,i,a)},quadraticCurveTo(e,t,n,r){this._ensureSurface();let i,a;this._ctx.hasCurrentPoint()?[i,a]=this._ctx.getCurrentPoint():(i=e,a=t);let{cp1x:o,cp1y:s,cp2x:c,cp2y:l}=quadraticToCubic(i,a,e,t,n,r);this._ctx.curveTo(o,s,c,l,n,r)},arc(e,t,n,r,i,a=!1){if(this._ensureSurface(),Math.abs(i-r)>=2*Math.PI){this._ctx.arc(e,t,n,0,2*Math.PI);return}a?this._ctx.arcNegative(e,t,n,r,i):this._ctx.arc(e,t,n,r,i)},arcTo(e,t,n,r,i){this._ensureSurface();let a,o;this._ctx.hasCurrentPoint()?[a,o]=this._ctx.getCurrentPoint():(a=e,o=t,this._ctx.moveTo(e,t)),cairoArcTo(this._ctx,a,o,e,t,n,r,i)},ellipse(e,t,n,r,i,a,o,s=!1){if(this._ensureSurface(),n<0||r<0)throw RangeError(`The radii provided are negative`);cairoEllipse(this._ctx,e,t,n,r,i,a,o,s)},rect(e,t,n,r){this._ensureSurface(),this._ctx.rectangle(e,t,n,r)},roundRect(e,t,n,r,i=0){this._ensureSurface(),cairoRoundRect(this._ctx,e,t,n,r,i)}};function installPathMethods(e){Object.assign(e,_e)}function getDrawImageSource(e){if(isPixbufImageSource(e)){let t=e._pixbuf;return{pixbuf:t,imgWidth:t.get_width(),imgHeight:t.get_height()}}if(isCanvasImageSource(e)){let t=e.width??0,n=e.height??0;if(!Number.isFinite(t)||!Number.isFinite(n)||t<=0||n<=0)return null;let r=e.getContext(`2d`);if(r&&typeof r._getSurface==`function`){let e=r._getSurface();e.flush();let i=getCanvasPixelBridge().imageFromSurface(e,0,0,t,n);if(i)return{pixbuf:i,imgWidth:t,imgHeight:n}}}return null}const ve={fill(t,n){this._ensureSurface(),this._applyCompositing(),this._applyFillStyle();let r;t instanceof pe?(this._ctx.newPath(),t._replayOnCairo(this._ctx),r=n):r=t,this._ctx.setFillRule(r===`evenodd`?e.FillRule.EVEN_ODD:e.FillRule.WINDING),this._ctx.fillPreserve()},stroke(e){this._ensureSurface(),this._applyCompositing(),this._applyStrokeStyle(),this._applyLineStyle(),e instanceof pe&&(this._ctx.newPath(),e._replayOnCairo(this._ctx)),this._ctx.strokePreserve()},fillRect(e,t,n,r){this._ensureSurface(),this._applyCompositing();let i=this._ctx.copyPath();this._hasShadow()&&this._renderShadow(()=>{this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.fill()}),this._applyFillStyle(),this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.fill(),this._ctx.newPath(),this._ctx.appendPath(i)},strokeRect(e,t,n,r){this._ensureSurface(),this._applyCompositing();let i=this._ctx.copyPath();this._hasShadow()&&this._renderShadow(()=>{this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.stroke()}),this._applyStrokeStyle(),this._applyLineStyle(),this._ctx.newPath(),this._ctx.rectangle(e,t,n,r),this._ctx.stroke(),this._ctx.newPath(),this._ctx.appendPath(i)},clearRect(t,n,r,i){this._ensureSurface();let a=this._ctx.copyPath();this._ctx.save(),this._ctx.setOperator(e.Operator.CLEAR),this._ctx.newPath(),this._ctx.rectangle(t,n,r,i),this._ctx.fill(),this._ctx.restore(),this._ctx.newPath(),this._ctx.appendPath(a)},clip(t,n){this._ensureSurface();let r;t instanceof pe?(this._ctx.newPath(),t._replayOnCairo(this._ctx),r=n):r=t,this._ctx.setFillRule(r===`evenodd`?e.FillRule.EVEN_ODD:e.FillRule.WINDING),this._ctx.clip()},isPointInPath(t,n,r,i){this._ensureSurface();let a,o,s;return t instanceof pe?(this._ctx.newPath(),t._replayOnCairo(this._ctx),a=n,o=r,s=i):(a=t,o=n,s=r),this._ctx.setFillRule(s===`evenodd`?e.FillRule.EVEN_ODD:e.FillRule.WINDING),this._ctx.inFill(a,o)},isPointInStroke(e,t,n){return this._ensureSurface(),this._applyLineStyle(),e instanceof pe?(this._ctx.newPath(),e._replayOnCairo(this._ctx),this._ctx.inStroke(t,n)):this._ctx.inStroke(e,t)},drawImage(t,n,r,i,a,o,s,c,l){this._ensureSurface(),this._applyCompositing();let u,d,f,p,m,h,g,_,v=getDrawImageSource(t);if(!v)return;let{pixbuf:y,imgWidth:b,imgHeight:x}=v;if(i===void 0?(u=0,d=0,f=b,p=x,m=n,h=r,g=b,_=x):o===void 0?(u=0,d=0,f=b,p=x,m=n,h=r,g=i,_=a):(u=n,d=r,f=i,p=a,m=o,h=s,g=c,_=l),!Number.isFinite(u)||!Number.isFinite(d)||!Number.isFinite(f)||!Number.isFinite(p)||!Number.isFinite(m)||!Number.isFinite(h)||!Number.isFinite(g)||!Number.isFinite(_)||f===0||p===0||g===0||_===0)return;this._ctx.save(),this._ctx.rectangle(m,h,g,_),this._ctx.clip(),this._ctx.translate(m,h),this._ctx.scale(g/f,_/p),this._ctx.translate(-u,-d),getCanvasPixelBridge().setSourceImage(this._ctx,y,0,0);let S=asCairoPattern(this._ctx.getSource?.());if(S){let t;t=this._state.imageSmoothingEnabled?this._state.imageSmoothingQuality===`high`?e.Filter.BEST:e.Filter.BILINEAR:e.Filter.NEAREST,S.setFilter(t)}this._state.globalAlpha<1?this._ctx.paintWithAlpha(this._state.globalAlpha):this._ctx.paint(),this._ctx.restore()}};function installDrawingMethods$1(e){Object.assign(e,ve)}__name(installDrawingMethods$1,`installDrawingMethods`);const ye={createImageData(e,t){return typeof e==`number`?new OurImageData(Math.abs(e),Math.abs(t)):new OurImageData(e.width,e.height)},getImageData(e,t,n,r){this._ensureSurface(),this._surface.flush();let i=getCanvasPixelBridge().imageFromSurface(this._surface,e,t,n,r);if(!i)return new OurImageData(n,r);let a=i.get_pixels(),o=i.get_has_alpha(),s=i.get_rowstride(),c=i.get_n_channels(),l=new Uint8ClampedArray(n*r*4);for(let e=0;e<r;e++)for(let t=0;t<n;t++){let r=e*s+t*c,i=(e*n+t)*4;l[i]=a[r],l[i+1]=a[r+1],l[i+2]=a[r+2],l[i+3]=o?a[r+3]:255}return new OurImageData(l,n,r)},putImageData(t,n,r,i,a,o,s){this._ensureSurface();let c=i??0,l=a??0,u=o??t.width,d=s??t.height,f=t.data,p=t.width,m=new Uint8Array(u*d*4);for(let e=0;e<d;e++)for(let t=0;t<u;t++){let n=((l+e)*p+(c+t))*4,r=(e*u+t)*4;m[r]=f[n],m[r+1]=f[n+1],m[r+2]=f[n+2],m[r+3]=f[n+3]}this._ctx.save(),this._ctx.setOperator(e.Operator.SOURCE),getCanvasPixelBridge().setSourcePixels(this._ctx,m,u,d,n+c,r+l),this._ctx.rectangle(n+c,r+l,u,d),this._ctx.fill(),this._ctx.restore()}};function installPixelMethods(e){Object.assign(e,ye)}function parseFontToDescription(e){let n=e.match(/^\s*(italic|oblique|normal)?\s*(small-caps|normal)?\s*(bold|bolder|lighter|[1-9]00|normal)?\s*(\d+(?:\.\d+)?)(px|pt|em|rem|%)?\s*(?:\/\S+)?\s*(.+)?$/i);if(!n)return t.font_description_from_string(e);let r=n[1]||``,i=n[3]||``,a=parseFloat(n[4])||10,o=(n[5]||`px`).toLowerCase(),s=(n[6]||`sans-serif`).replace(/['"]/g,``).trim();o===`pt`?a=a*96/72:o===`em`||o===`rem`?a*=16:o===`%`&&(a=a/100*16);let c=s;r===`italic`?c+=` Italic`:r===`oblique`&&(c+=` Oblique`),i===`bold`||i===`bolder`||parseInt(i)>=600?c+=` Bold`:(i===`lighter`||parseInt(i)>0&&parseInt(i)<=300)&&(c+=` Light`);let l=t.font_description_from_string(c);return l.set_absolute_size(a*t.SCALE),l}function createTextLayout(e,r){let i=n.create_layout(e._ctx);i.set_text(r,-1),i.get_context().set_base_dir(t.Direction.LTR),i.context_changed();let a=parseFontToDescription(e._state.font);return i.set_font_description(a),i}function getTextAlignOffset(e,t){let[,n]=t.get_pixel_extents(),r=n.width;switch(e._state.textAlign){case`center`:return-r/2;case`right`:case`end`:return-r;default:return 0}}function getTextBaselineOffset(e,n){let r=n.get_font_description()||parseFontToDescription(e._state.font),i=n.get_context().get_metrics(r,null),a=i.get_ascent()/t.SCALE,o=i.get_descent()/t.SCALE,s=a+o;switch(e._state.textBaseline){case`top`:return 0;case`hanging`:return-(a*.2);case`middle`:return-(s/2);case`alphabetic`:return-a;case`ideographic`:return-(a+o*.5);case`bottom`:return-s;default:return-a}}const be={fillText(t,r,i,a){this._ensureSurface(),this._applyCompositing();let o=createTextLayout(this,t),s=getTextAlignOffset(this,o),c=getTextBaselineOffset(this,o);if(this._hasShadow()){let t=parseColor(this._state.shadowColor);if(t){let[a,l]=this._deviceToUserDistance(this._state.shadowOffsetX,this._state.shadowOffsetY),u=this._state.shadowBlur,d;if(u>0){let[e]=this._deviceToUserDistance(u,0),[,n]=this._deviceToUserDistance(0,u);d=[[a,l,t.a],[a+e,l,t.a*.5],[a-e,l,t.a*.5],[a,l+n,t.a*.5],[a,l-n,t.a*.5]]}else d=[[a,l,t.a]];let f=this._state.imageSmoothingEnabled?e.Antialias.DEFAULT:e.Antialias.NONE;for(let[e,a,l]of d)this._ctx.save(),this._ctx.setAntialias(f),this._ctx.setSourceRGBA(t.r,t.g,t.b,l),this._ctx.moveTo(r+s+e,i+c+a),n.show_layout(this._ctx,o),this._ctx.restore()}}this._applyFillStyle(),this._ctx.save(),this._ctx.setAntialias(this._state.imageSmoothingEnabled?e.Antialias.DEFAULT:e.Antialias.NONE),this._ctx.moveTo(r+s,i+c),n.show_layout(this._ctx,o),this._ctx.restore()},strokeText(t,r,i,a){this._ensureSurface(),this._applyCompositing(),this._applyStrokeStyle(),this._applyLineStyle();let o=createTextLayout(this,t),s=getTextAlignOffset(this,o),c=getTextBaselineOffset(this,o);this._ctx.save(),this._ctx.setAntialias(this._state.imageSmoothingEnabled?e.Antialias.DEFAULT:e.Antialias.NONE),this._ctx.moveTo(r+s,i+c),n.layout_path(this._ctx,o),this._ctx.stroke(),this._ctx.restore()},measureText(e){this._ensureSurface();let n=createTextLayout(this,e),[r,i]=n.get_pixel_extents(),a=n.get_baseline()/t.SCALE,o=Math.max(0,a-r.y),s=Math.max(0,r.y+r.height-a),c=n.get_font_description()||parseFontToDescription(this._state.font),l=n.get_context().get_metrics(c,null),u=l.get_ascent()/t.SCALE,d=l.get_descent()/t.SCALE;return{width:i.width,actualBoundingBoxAscent:o,actualBoundingBoxDescent:s,actualBoundingBoxLeft:Math.max(0,-r.x),actualBoundingBoxRight:r.x+r.width,fontBoundingBoxAscent:u,fontBoundingBoxDescent:d,alphabeticBaseline:0,emHeightAscent:u,emHeightDescent:d,hangingBaseline:u*.8,ideographicBaseline:-d}}};function installTextMethods(e){Object.assign(e,be)}const xe={createLinearGradient(e,t,n,r){return new CanvasGradient(`linear`,e,t,n,r)},createRadialGradient(e,t,n,r,i,a){return new CanvasGradient(`radial`,e,t,r,i,n,a)},createPattern(e,t){return he.create(e,t)}};function installFactoryMethods(e){Object.assign(e,xe)}function installAllContextMethods$1(e){installTransformMethods(e),installPathMethods(e),installDrawingMethods$1(e),installPixelMethods(e),installTextMethods(e),installFactoryMethods(e)}__name(installAllContextMethods$1,`installAllContextMethods`);function createDefaultState(){return{fillStyle:`#000000`,fillColor:{...le},strokeStyle:`#000000`,strokeColor:{...le},lineWidth:1,lineCap:`butt`,lineJoin:`miter`,miterLimit:10,lineDash:[],lineDashOffset:0,globalAlpha:1,globalCompositeOperation:`source-over`,shadowColor:`rgba(0, 0, 0, 0)`,shadowBlur:0,shadowOffsetX:0,shadowOffsetY:0,font:`10px sans-serif`,textAlign:`start`,textBaseline:`alphabetic`,direction:`ltr`,imageSmoothingEnabled:!0,imageSmoothingQuality:`low`}}function cloneState(e){return{...e,fillColor:{...e.fillColor},strokeColor:{...e.strokeColor},lineDash:[...e.lineDash]}}var CanvasRenderingContext2D=class{constructor(t,n){this._stateStack=[],this.canvas=t,this._surfaceWidth=t.width||300,this._surfaceHeight=t.height||150,this._surface=new e.ImageSurface(e.Format.ARGB32,this._surfaceWidth,this._surfaceHeight),this._ctx=new e.Context(this._surface),this._state=createDefaultState()}_ensureSurface(){let t=this.canvas.width||300,n=this.canvas.height||150;(t!==this._surfaceWidth||n!==this._surfaceHeight)&&(this._ctx.$dispose(),this._surface.finish(),this._surfaceWidth=t,this._surfaceHeight=n,this._surface=new e.ImageSurface(e.Format.ARGB32,t,n),this._ctx=new e.Context(this._surface),this._stateStack=[])}_resetState(){this._state=createDefaultState(),this._stateStack=[]}_applyFillStyle(){let e=this._state.fillStyle;if(typeof e==`string`){let e=this._state.fillColor,t=e.a*this._state.globalAlpha;this._ctx.setSourceRGBA(e.r,e.g,e.b,t)}else e instanceof CanvasGradient?this._ctx.setSource(e._getCairoPattern()):e instanceof he&&(this._ctx.setSource(e._getCairoPattern()),this._applyPatternFilter())}_applyStrokeStyle(){let e=this._state.strokeStyle;if(typeof e==`string`){let e=this._state.strokeColor,t=e.a*this._state.globalAlpha;this._ctx.setSourceRGBA(e.r,e.g,e.b,t)}else e instanceof CanvasGradient?this._ctx.setSource(e._getCairoPattern()):e instanceof he&&(this._ctx.setSource(e._getCairoPattern()),this._applyPatternFilter())}_applyPatternFilter(){let t=asCairoPattern(this._ctx.getSource?.());if(!t)return;let n;n=this._state.imageSmoothingEnabled?this._state.imageSmoothingQuality===`high`?e.Filter.BEST:e.Filter.BILINEAR:e.Filter.NEAREST,t.setFilter(n)}_applyLineStyle(){this._ctx.setLineWidth(this._state.lineWidth),this._ctx.setLineCap(de[this._state.lineCap]),this._ctx.setLineJoin(fe[this._state.lineJoin]),this._ctx.setMiterLimit(this._state.miterLimit),this._ctx.setDash(this._state.lineDash,this._state.lineDashOffset)}_applyCompositing(){let e=ue[this._state.globalCompositeOperation];e!==void 0&&this._ctx.setOperator(e)}_getSurface(){return this._surface}_hasShadow(){if(this._state.shadowBlur===0&&this._state.shadowOffsetX===0&&this._state.shadowOffsetY===0)return!1;let e=parseColor(this._state.shadowColor);return e!==null&&e.a>0}_deviceToUserDistance(e,t){let n=this._ctx.userToDevice(0,0),r=this._ctx.userToDevice(1,0),i=this._ctx.userToDevice(0,1),a=(r[0]??0)-(n[0]??0),o=(r[1]??0)-(n[1]??0),s=(i[0]??0)-(n[0]??0),c=(i[1]??0)-(n[1]??0),l=a*c-o*s;return Math.abs(l)<1e-10?[e,t]:[(c*e-s*t)/l,(-o*e+a*t)/l]}_renderShadow(e){}save(){this._ensureSurface(),this._stateStack.push(cloneState(this._state)),this._ctx.save()}restore(){this._ensureSurface();let e=this._stateStack.pop();e&&(this._state=e,this._ctx.restore())}get fillStyle(){return this._state.fillStyle}set fillStyle(e){if(typeof e==`string`){let t=parseColor(e);t&&(this._state.fillStyle=e,this._state.fillColor=t)}else this._state.fillStyle=e}get strokeStyle(){return this._state.strokeStyle}set strokeStyle(e){if(typeof e==`string`){let t=parseColor(e);t&&(this._state.strokeStyle=e,this._state.strokeColor=t)}else this._state.strokeStyle=e}get lineWidth(){return this._state.lineWidth}set lineWidth(e){e>0&&isFinite(e)&&(this._state.lineWidth=e)}get lineCap(){return this._state.lineCap}set lineCap(e){(e===`butt`||e===`round`||e===`square`)&&(this._state.lineCap=e)}get lineJoin(){return this._state.lineJoin}set lineJoin(e){(e===`miter`||e===`round`||e===`bevel`)&&(this._state.lineJoin=e)}get miterLimit(){return this._state.miterLimit}set miterLimit(e){e>0&&isFinite(e)&&(this._state.miterLimit=e)}get globalAlpha(){return this._state.globalAlpha}set globalAlpha(e){e>=0&&e<=1&&isFinite(e)&&(this._state.globalAlpha=e)}get globalCompositeOperation(){return this._state.globalCompositeOperation}set globalCompositeOperation(e){ue[e]!==void 0&&(this._state.globalCompositeOperation=e)}get imageSmoothingEnabled(){return this._state.imageSmoothingEnabled}set imageSmoothingEnabled(e){this._state.imageSmoothingEnabled=!!e}get imageSmoothingQuality(){return this._state.imageSmoothingQuality}set imageSmoothingQuality(e){(e===`low`||e===`medium`||e===`high`)&&(this._state.imageSmoothingQuality=e)}setLineDash(e){e.some(e=>e<0||!isFinite(e))||(this._state.lineDash=[...e])}getLineDash(){return[...this._state.lineDash]}get lineDashOffset(){return this._state.lineDashOffset}set lineDashOffset(e){isFinite(e)&&(this._state.lineDashOffset=e)}get shadowColor(){return this._state.shadowColor}set shadowColor(e){this._state.shadowColor=e}get shadowBlur(){return this._state.shadowBlur}set shadowBlur(e){e>=0&&isFinite(e)&&(this._state.shadowBlur=e)}get shadowOffsetX(){return this._state.shadowOffsetX}set shadowOffsetX(e){isFinite(e)&&(this._state.shadowOffsetX=e)}get shadowOffsetY(){return this._state.shadowOffsetY}set shadowOffsetY(e){isFinite(e)&&(this._state.shadowOffsetY=e)}get font(){return this._state.font}set font(e){this._state.font=e}get textAlign(){return this._state.textAlign}set textAlign(e){this._state.textAlign=e}get textBaseline(){return this._state.textBaseline}set textBaseline(e){this._state.textBaseline=e}get direction(){return this._state.direction}set direction(e){this._state.direction=e}_toDataURL(e,t){this._surface.flush();let[,n]=i.file_open_tmp(`canvas-XXXXXX.png`);try{this._surface.writeToPNG(n);let[,e]=r.File.new_for_path(n).load_contents(null);return`data:image/png;base64,${i.base64_encode(e)}`}finally{i.unlink(n)}}_dispose(){this._ctx.$dispose(),this._surface.finish()}};installAllContextMethods$1(CanvasRenderingContext2D.prototype);var Se=Object.defineProperty,__exportAll=(e,t)=>{let n={};for(var r in e)Se(n,r,{get:e[r],enumerable:!0});return t||Se(n,Symbol.toStringTag,{value:`Module`}),n};__exportAll({attributes:()=>Ae,childNodesList:()=>M,elementChildren:()=>Te,isConnected:()=>Ee,localName:()=>De,name:()=>je,namespaceURI:()=>Oe,nodeType:()=>Ce,ownerElement:()=>Ne,parentNode:()=>we,prefix:()=>ke,propertyEventListeners:()=>P,tagName:()=>N,value:()=>Me});const Ce=Symbol(`nodeType`),we=Symbol(`parentNode`),M=Symbol(`childNodesList`),Te=Symbol(`elementChildren`),Ee=Symbol(`isConnected`),N=Symbol(`tagName`),De=Symbol(`localName`),Oe=Symbol(`namespaceURI`),ke=Symbol(`prefix`),Ae=Symbol(`attributes`),P=Symbol(`propertyEventListeners`),je=Symbol(`name`),Me=Symbol(`value`),Ne=Symbol(`ownerElement`),Pe={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11};var NodeList=class{constructor(e){this._items=e}get length(){return this._items.length}item(e){return this._items[e]??null}forEach(e,t){for(let n=0;n<this._items.length;n++)e.call(t,this._items[n],n,this)}entries(){return this._items.entries()}keys(){return this._items.keys()}values(){return this._items.values()}[Symbol.iterator](){return this._items[Symbol.iterator]()}get[Symbol.toStringTag](){return`NodeList`}};const Fe={IndexSizeError:1,HierarchyRequestError:3,WrongDocumentError:4,InvalidCharacterError:5,NoModificationAllowedError:7,NotFoundError:8,NotSupportedError:9,InUseAttributeError:10,InvalidStateError:11,SyntaxError:12,InvalidModificationError:13,NamespaceError:14,InvalidAccessError:15,TypeMismatchError:17,SecurityError:18,NetworkError:19,AbortError:20,URLMismatchError:21,QuotaExceededError:22,TimeoutError:23,InvalidNodeTypeError:24,DataCloneError:25};var _DOMExceptionPolyfill=class extends Error{code;constructor(e,t){super(e),this.name=t||`Error`,this.code=Object.hasOwn(Fe,this.name)?Fe[this.name]:0}};const Ie=globalThis.DOMException===void 0?_DOMExceptionPolyfill:globalThis.DOMException,Le=Symbol(`type`),Re=Symbol(`bubbles`),ze=Symbol(`cancelable`),Be=Symbol(`composed`),Ve=Symbol(`target`),He=Symbol(`currentTarget`),Ue=Symbol(`eventPhase`),We=Symbol(`defaultPrevented`),Ge=Symbol(`isTrusted`),Ke=Symbol(`timeStamp`),qe=Symbol(`stop`),Je=Symbol(`immediateStop`),Ye=Symbol(`dispatching`),Xe=Symbol(`inPassiveListener`);var Event=class{[Le];[Re];[ze];[Be];[Ve]=null;[He]=null;[Ue]=0;[We]=!1;[Ge]=!1;[Ke];[qe]=!1;[Je]=!1;[Ye]=!1;[Xe]=!1;get type(){return this[Le]}get bubbles(){return this[Re]}get cancelable(){return this[ze]}get composed(){return this[Be]}get target(){return this[Ve]}get currentTarget(){return this[He]}get eventPhase(){return this[Ue]}get defaultPrevented(){return this[We]}get timeStamp(){return this[Ke]}get cancelBubble(){return this[qe]}set cancelBubble(e){e&&this.stopPropagation()}get returnValue(){return!this[We]}set returnValue(e){e||this.preventDefault()}get srcElement(){return this[Ve]}static NONE=0;static CAPTURING_PHASE=1;static AT_TARGET=2;static BUBBLING_PHASE=3;get[Symbol.toStringTag](){return`Event`}constructor(e,t){this[Le]=e,this[Re]=t?.bubbles??!1,this[ze]=t?.cancelable??!1,this[Be]=t?.composed??!1,this[Ke]=Date.now(),Object.defineProperty(this,"isTrusted",{get:()=>this[Ge],enumerable:!0,configurable:!1})}composedPath(){return this[He]?[this[He]]:[]}preventDefault(){this[ze]&&!this[Xe]&&(this[We]=!0)}stopPropagation(){this[qe]=!0}stopImmediatePropagation(){this[qe]=!0,this[Je]=!0}},CustomEvent$1=class extends Event{static{__name(this,`CustomEvent`)}detail;constructor(e,t){super(e,t),this.detail=t?.detail}},MessageEvent=class extends Event{data;origin;lastEventId;source;ports;constructor(e,t){super(e,t),this.data=t?.data??null,this.origin=t?.origin??``,this.lastEventId=t?.lastEventId??``,this.source=t?.source??null,this.ports=t?.ports??[]}get[Symbol.toStringTag](){return`MessageEvent`}},ErrorEvent=class extends Event{message;filename;lineno;colno;error;constructor(e,t){super(e,t),this.message=t?.message??``,this.filename=t?.filename??``,this.lineno=t?.lineno??0,this.colno=t?.colno??0,this.error=t?.error??null}get[Symbol.toStringTag](){return`ErrorEvent`}},CloseEvent=class extends Event{code;reason;wasClean;constructor(e,t){super(e,t),this.code=t?.code??0,this.reason=t?.reason??``,this.wasClean=t?.wasClean??!1}get[Symbol.toStringTag](){return`CloseEvent`}},ProgressEvent$1=class extends Event{static{__name(this,`ProgressEvent`)}lengthComputable;loaded;total;constructor(e,t){super(e,t),this.lengthComputable=t?.lengthComputable??!1,this.loaded=t?.loaded??0,this.total=t?.total??0}get[Symbol.toStringTag](){return`ProgressEvent`}},EventTarget=class{#e=new Map;get[Symbol.toStringTag](){return`EventTarget`}addEventListener(e,t,n){if(t===null)return;let r=typeof n==`boolean`?n:n?.capture??!1,i=typeof n==`object`?n?.once??!1:!1,a=typeof n==`object`?n?.passive??!1:!1,o=this.#e.get(e);o||(o=[],this.#e.set(e,o));for(let e of o)if(e.listener===t&&e.capture===r)return;let s={listener:t,capture:r,once:i,passive:a,removed:!1};o.push(s),typeof n==`object`&&n?.signal&&n.signal.addEventListener(`abort`,()=>{this.removeEventListener(e,t,{capture:r})},{once:!0})}removeEventListener(e,t,n){if(t===null)return;let r=typeof n==`boolean`?n:n?.capture??!1,i=this.#e.get(e);if(!i)return;let a=i.findIndex(e=>e.listener===t&&e.capture===r);a!==-1&&(i[a].removed=!0,i.splice(a,1),i.length===0&&this.#e.delete(e))}dispatchEvent(e){let t=e;if(t[Ye])throw new Ie(`The event is already being dispatched.`,`InvalidStateError`);t[Ye]=!0,t[Ve]=this,t[He]=this,t[Ue]=Event.AT_TARGET;try{let n=this.#e.get(e.type);if(n){let r=[...n];for(let n of r)if(!n.removed){if(t[Je]||t[qe])break;n.once&&this.removeEventListener(e.type,n.listener,{capture:n.capture});try{n.passive&&(t[Xe]=!0),typeof n.listener==`function`?n.listener.call(this,e):typeof n.listener.handleEvent==`function`&&n.listener.handleEvent.call(n.listener,e)}catch(e){reportListenerException(e)}finally{t[Xe]=!1}}}}finally{t[Ue]=Event.NONE,t[He]=null,t[Ye]=!1}return!e.defaultPrevented}};function reportListenerException(e){try{let t=globalThis;if(typeof t.reportError==`function`)t.reportError(e);else if(e instanceof Error){let t=`${e.name}: ${e.message}`;A.error(e.stack?`${t}\n${e.stack}`:t)}else A.error(String(e))}catch{}}for(let[e,t]of[[`NONE`,0],[`CAPTURING_PHASE`,1],[`AT_TARGET`,2],[`BUBBLING_PHASE`,3]])Object.defineProperty(Event.prototype,e,{value:t,writable:!1,enumerable:!0,configurable:!1}),Object.defineProperty(Event,e,{value:t,writable:!1,enumerable:!0,configurable:!1});var UIEvent=class extends Event{detail;view;constructor(e,t){super(e,t),this.detail=t?.detail??0,this.view=null}get[Symbol.toStringTag](){return`UIEvent`}},MouseEvent=class extends UIEvent{altKey;button;buttons;clientX;clientY;ctrlKey;metaKey;movementX;movementY;offsetX;offsetY;screenX;screenY;shiftKey;relatedTarget;get pageX(){return this.clientX}get pageY(){return this.clientY}get x(){return this.clientX}get y(){return this.clientY}constructor(e,t){super(e,t),this.altKey=t?.altKey??!1,this.button=t?.button??0,this.buttons=t?.buttons??0,this.clientX=t?.clientX??0,this.clientY=t?.clientY??0,this.ctrlKey=t?.ctrlKey??!1,this.metaKey=t?.metaKey??!1,this.movementX=t?.movementX??0,this.movementY=t?.movementY??0,this.offsetX=t?.offsetX??0,this.offsetY=t?.offsetY??0,this.screenX=t?.screenX??0,this.screenY=t?.screenY??0,this.shiftKey=t?.shiftKey??!1,this.relatedTarget=t?.relatedTarget??null}getModifierState(e){switch(e){case`Alt`:return this.altKey;case`Control`:return this.ctrlKey;case`Meta`:return this.metaKey;case`Shift`:return this.shiftKey;default:return!1}}get[Symbol.toStringTag](){return`MouseEvent`}},PointerEvent=class extends MouseEvent{pointerId;width;height;pressure;tangentialPressure;tiltX;tiltY;twist;altitudeAngle;azimuthAngle;pointerType;isPrimary;constructor(e,t){super(e,t),this.pointerId=t?.pointerId??0,this.width=t?.width??1,this.height=t?.height??1,this.pressure=t?.pressure??0,this.tangentialPressure=t?.tangentialPressure??0,this.tiltX=t?.tiltX??0,this.tiltY=t?.tiltY??0,this.twist=t?.twist??0,this.altitudeAngle=t?.altitudeAngle??Math.PI/2,this.azimuthAngle=t?.azimuthAngle??0,this.pointerType=t?.pointerType??``,this.isPrimary=t?.isPrimary??!1}getCoalescedEvents(){return[]}getPredictedEvents(){return[]}get[Symbol.toStringTag](){return`PointerEvent`}},KeyboardEvent=class extends UIEvent{altKey;code;ctrlKey;isComposing;key;location;metaKey;repeat;shiftKey;keyCode;which;static DOM_KEY_LOCATION_STANDARD=0;static DOM_KEY_LOCATION_LEFT=1;static DOM_KEY_LOCATION_RIGHT=2;static DOM_KEY_LOCATION_NUMPAD=3;constructor(e,t){super(e,t),this.altKey=t?.altKey??!1,this.code=t?.code??``,this.ctrlKey=t?.ctrlKey??!1,this.isComposing=t?.isComposing??!1,this.key=t?.key??``,this.location=t?.location??0,this.metaKey=t?.metaKey??!1,this.repeat=t?.repeat??!1,this.shiftKey=t?.shiftKey??!1,this.keyCode=t?.keyCode??0,this.which=t?.which??0}getModifierState(e){switch(e){case`Alt`:return this.altKey;case`Control`:return this.ctrlKey;case`Meta`:return this.metaKey;case`Shift`:return this.shiftKey;default:return!1}}get[Symbol.toStringTag](){return`KeyboardEvent`}},WheelEvent=class extends MouseEvent{deltaX;deltaY;deltaZ;deltaMode;static DOM_DELTA_PIXEL=0;static DOM_DELTA_LINE=1;static DOM_DELTA_PAGE=2;constructor(e,t){super(e,t),this.deltaX=t?.deltaX??0,this.deltaY=t?.deltaY??0,this.deltaZ=t?.deltaZ??0,this.deltaMode=t?.deltaMode??0}get[Symbol.toStringTag](){return`WheelEvent`}},FocusEvent=class extends UIEvent{relatedTarget;constructor(e,t){super(e,t),this.relatedTarget=t?.relatedTarget??null}get[Symbol.toStringTag](){return`FocusEvent`}};let Ze,Qe,$e,et,tt;var nt=class Node extends EventTarget{constructor(...e){super(...e),this.ELEMENT_NODE=Pe.ELEMENT_NODE,this.ATTRIBUTE_NODE=Pe.ATTRIBUTE_NODE,this.TEXT_NODE=Pe.TEXT_NODE,this.CDATA_SECTION_NODE=Pe.CDATA_SECTION_NODE,this.PROCESSING_INSTRUCTION_NODE=Pe.PROCESSING_INSTRUCTION_NODE,this.COMMENT_NODE=Pe.COMMENT_NODE,this.DOCUMENT_NODE=Pe.DOCUMENT_NODE,this.DOCUMENT_TYPE_NODE=Pe.DOCUMENT_TYPE_NODE,this.DOCUMENT_FRAGMENT_NODE=Pe.DOCUMENT_FRAGMENT_NODE,this[Ze]=Pe.ELEMENT_NODE,this[Qe]=null,this[$e]=[],this[et]=[],this[tt]=!1}static{this.ELEMENT_NODE=Pe.ELEMENT_NODE}static{this.ATTRIBUTE_NODE=Pe.ATTRIBUTE_NODE}static{this.TEXT_NODE=Pe.TEXT_NODE}static{this.CDATA_SECTION_NODE=Pe.CDATA_SECTION_NODE}static{this.PROCESSING_INSTRUCTION_NODE=Pe.PROCESSING_INSTRUCTION_NODE}static{this.COMMENT_NODE=Pe.COMMENT_NODE}static{this.DOCUMENT_NODE=Pe.DOCUMENT_NODE}static{this.DOCUMENT_TYPE_NODE=Pe.DOCUMENT_TYPE_NODE}static{this.DOCUMENT_FRAGMENT_NODE=Pe.DOCUMENT_FRAGMENT_NODE}static{this.DOCUMENT_POSITION_DISCONNECTED=1}static{this.DOCUMENT_POSITION_PRECEDING=2}static{this.DOCUMENT_POSITION_FOLLOWING=4}static{this.DOCUMENT_POSITION_CONTAINS=8}static{this.DOCUMENT_POSITION_CONTAINED_BY=16}static{this.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC=32}get nodeType(){return this[Ce]}get nodeName(){return``}get parentNode(){return this[we]}get parentElement(){let e=this[we];return e&&e[Ce]===Pe.ELEMENT_NODE?e:null}get childNodes(){return new NodeList(this[M])}get firstChild(){return this[M][0]??null}get lastChild(){let e=this[M];return e[e.length-1]??null}get previousSibling(){let e=this[we];if(!e)return null;let t=e[M],n=t.indexOf(this);return n>0?t[n-1]:null}get nextSibling(){let e=this[we];if(!e)return null;let t=e[M],n=t.indexOf(this);return n!==-1&&n<t.length-1?t[n+1]:null}get textContent(){return null}set textContent(e){}get nodeValue(){return null}set nodeValue(e){}get ownerDocument(){let e=this;for(;e[we];)e=e[we];let t=globalThis.document;return e===t?t:null}get isConnected(){return this[Ee]}hasChildNodes(){return this[M].length>0}contains(e){if(e===null)return!1;if(e===this)return!0;let t=e;for(;t;){if(t===this)return!0;t=t[we]}return!1}getRootNode(){let e=this;for(;e[we];)e=e[we];return e}appendChild(e){return e[we]&&e[we].removeChild(e),e[we]=this,this[M].push(e),e[Ce]===Pe.ELEMENT_NODE&&this[Te].push(e),e}removeChild(e){let t=this[M],n=t.indexOf(e);if(n===-1)throw new DOMException(`Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.`,`NotFoundError`);if(t.splice(n,1),e[we]=null,e[Ce]===Pe.ELEMENT_NODE){let t=this[Te].indexOf(e);t!==-1&&this[Te].splice(t,1)}return e}insertBefore(e,t){if(t===null)return this.appendChild(e);let n=this[M],r=n.indexOf(t);if(r===-1)throw new DOMException(`Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node.`,`NotFoundError`);if(e[we]&&e[we].removeChild(e),e[we]=this,n.splice(r,0,e),e[Ce]===Pe.ELEMENT_NODE){let t=this[Te],i=t.length;for(let a=r;a<n.length;a++)if(n[a][Ce]===Pe.ELEMENT_NODE&&n[a]!==e){i=t.indexOf(n[a]);break}t.splice(i,0,e)}return e}replaceChild(e,t){return this.insertBefore(e,t),this.removeChild(t),t}cloneNode(e=!1){let t=new this.constructor;if(t[Ce]=this[Ce],e)for(let e of this[M])t.appendChild(e.cloneNode(!0));return t}dispatchEvent(e){let t=super.dispatchEvent(e);if(e.bubbles&&!e.cancelBubble){let t=this[we];for(;t&&(Object.getPrototypeOf(Node.prototype).dispatchEvent.call(t,e),!e.cancelBubble);)t=t[we]}return t}get[(Ze=Ce,Qe=we,$e=M,et=Te,tt=Ee,Symbol.toStringTag)](){return`Node`}};const rt={html:`http://www.w3.org/1999/xhtml`,svg:`http://www.w3.org/2000/svg`,mathML:`http://www.w3.org/1998/Math/MathML`,xml:`http://www.w3.org/XML/1998/namespace`,xmlns:`http://www.w3.org/2000/xmlns/`};var Attr=class{constructor(e,t,n=null,r=null,i=null){this.specified=!0,this[je]=e,this[Me]=t,this[Ne]=i,this.namespaceURI=n,this.prefix=r;let a=e.indexOf(`:`);this.localName=a===-1?e:e.slice(a+1)}get name(){return this[je]}get value(){return this[Me]}set value(e){this[Me]=e}get ownerElement(){return this[Ne]}get[Symbol.toStringTag](){return`Attr`}},NamedNodeMap=class{constructor(e){this._items=[],this._ownerElement=e}get length(){return this._items.length}item(e){return this._items[e]??null}getNamedItem(e){return this._findByName(e)}getNamedItemNS(e,t){let n=e===``?null:e;for(let e of this._items)if(e.namespaceURI===n&&e.localName===t)return e;return null}setNamedItem(e){return this._setAttr(e)}setNamedItemNS(e){return this._setAttr(e)}removeNamedItem(e){let t=this._findByName(e);if(!t)throw new DOMException(`Failed to execute 'removeNamedItem' on 'NamedNodeMap': No item with name '${e}' was found.`,`NotFoundError`);return this._removeAttr(t),t}removeNamedItemNS(e,t){let n=this.getNamedItemNS(e,t);if(!n)throw new DOMException(`Failed to execute 'removeNamedItemNS' on 'NamedNodeMap': No item with namespace '${e}' and localName '${t}' was found.`,`NotFoundError`);return this._removeAttr(n),n}[Symbol.iterator](){return this._items[Symbol.iterator]()}get[Symbol.toStringTag](){return`NamedNodeMap`}_setNamedItem(e,t,n=null,r=null){let i=n===null?this._findByName(e):this.getNamedItemNS(n,e.includes(`:`)?e.split(`:`)[1]:e);if(i)i.value=t;else{let i=new Attr(e,t,n,r,this._ownerElement);this._items.push(i)}}_removeNamedItem(e){let t=this._findByName(e);return t?(this._removeAttr(t),!0):!1}_removeNamedItemNS(e,t){let n=this.getNamedItemNS(e,t);return n?(this._removeAttr(n),!0):!1}_findByName(e){let t=this._ownerElement.namespaceURI===rt.html,n=t?e.toLowerCase():e;for(let e of this._items)if((t?e.name.toLowerCase():e.name)===n)return e;return null}_setAttr(e){let t=null;if(t=e.namespaceURI===null?this._findByName(e.name):this.getNamedItemNS(e.namespaceURI,e.localName),t){let n=new Attr(t.name,t.value,t.namespaceURI,t.prefix,t.ownerElement);return t.value=e.value,n}return this._items.push(e),null}_removeAttr(e){let t=this._items.indexOf(e);t!==-1&&this._items.splice(t,1)}};let it,at,ot,st,ct,lt;var Element=class extends nt{constructor(){super(),this[it]=``,this[at]=``,this[ot]=rt.html,this[st]=null,this[ct]=new NamedNodeMap(this),this[lt]=new Map,this._resizeSubscribers=null,this._allocatedClientWidth=0,this._allocatedClientHeight=0,this._pointerCaptures=new Set,this[Ce]=Pe.ELEMENT_NODE}get tagName(){return this[N]}get localName(){return this[De]}get namespaceURI(){return this[Oe]}get prefix(){return this[ke]}get nodeName(){return this[N]}get attributes(){return this[Ae]}get id(){return this.getAttribute(`id`)??``}set id(e){this.setAttribute(`id`,e)}get className(){return this.getAttribute(`class`)??``}set className(e){this.setAttribute(`class`,e)}get children(){return this[Te]}get childElementCount(){return this[Te].length}get firstElementChild(){return this[Te][0]??null}get lastElementChild(){let e=this[Te];return e[e.length-1]??null}get previousElementSibling(){let e=this[we];if(!e)return null;let t=e[Te],n=t.indexOf(this);return n>0?t[n-1]:null}get nextElementSibling(){let e=this[we];if(!e)return null;let t=e[Te],n=t.indexOf(this);return n!==-1&&n<t.length-1?t[n+1]:null}get textContent(){let e=``;for(let t of this[M])t.textContent!==null&&(e+=t.textContent);return e}set textContent(e){let t=this[M];for(;t.length>0;)this.removeChild(t[0])}getAttribute(e){let t=this[Ae].getNamedItem(e);return t?t.value:null}getAttributeNS(e,t){let n=this[Ae].getNamedItemNS(e,t);return n?n.value:null}setAttribute(e,t){this[Ae]._setNamedItem(e,String(t))}setAttributeNS(e,t,n){let r=e===``?null:e,i=t.split(`:`),a=i.length>1?i[0]:null;this[Ae]._setNamedItem(t,String(n),r,a)}removeAttribute(e){this[Ae]._removeNamedItem(e)}removeAttributeNS(e,t){let n=e===``?null:e;this[Ae]._removeNamedItemNS(n,t)}hasAttribute(e){return this[Ae].getNamedItem(e)!==null}hasAttributeNS(e,t){return this[Ae].getNamedItemNS(e,t)!==null}getAttributeNode(e){return this[Ae].getNamedItem(e)}setAttributeNode(e){return this[Ae].setNamedItem(e)}removeAttributeNode(e){let t=this[Ae].getNamedItem(e.name);if(!t)throw new DOMException(`Failed to execute 'removeAttributeNode' on 'Element': The attribute is not owned by this element.`,`NotFoundError`);return this[Ae].removeNamedItem(t.name),t}toggleAttribute(e,t){return t===void 0?this.hasAttribute(e)?(this.removeAttribute(e),!1):(this.setAttribute(e,``),!0):t?(this.setAttribute(e,``),!0):(this.removeAttribute(e),!1)}hasAttributes(){return this[Ae].length>0}dispatchEvent(e){let t=super.dispatchEvent(e),n=this[P].get(`on`+e.type);return typeof n==`function`&&n.call(this,e),t}querySelector(e){return null}querySelectorAll(e){return[]}matches(e){return!1}closest(e){return null}getElementsByTagName(e){let t=[],n=e.toUpperCase(),walk=r=>{for(let i of r[M])if(i[Ce]===Pe.ELEMENT_NODE){let r=i;(e===`*`||r[N]===n)&&t.push(r),walk(r)}};return walk(this),t}getElementsByClassName(e){let t=[],n=e.split(/\s+/).filter(Boolean),walk=e=>{for(let r of e[M])if(r[Ce]===Pe.ELEMENT_NODE){let e=r,i=e.className.split(/\s+/);n.every(e=>i.includes(e))&&t.push(e),walk(e)}};return walk(this),t}cloneNode(e=!1){let t=super.cloneNode(!1);t[N]=this[N],t[De]=this[De],t[Oe]=this[Oe],t[ke]=this[ke];for(let e of this[Ae])t.setAttributeNS(e.namespaceURI,e.name,e.value);if(e)for(let e of this[M])t.appendChild(e.cloneNode(!0));return t}_onResize(e){let t=this._resizeSubscribers??=new Set;return t.add(e),()=>{t.delete(e),t.size===0&&(this._resizeSubscribers=null)}}_fireResizeSubscribers(e,t){let n=this._resizeSubscribers;if(!(!n||n.size===0))for(let r of[...n])try{r(e,t)}catch(e){A.error(`ResizeObserver subscriber threw:`,e)}}setPointerCapture(e){this._pointerCaptures.add(e)}releasePointerCapture(e){this._pointerCaptures.delete(e)}hasPointerCapture(e){return this._pointerCaptures.has(e)}get[(it=N,at=De,ot=Oe,st=ke,ct=Ae,lt=P,Symbol.toStringTag)](){return`Element`}},CSSStyleDeclaration=class{constructor(){this._cssText=``}get cssText(){return this._cssText}set cssText(e){this._cssText=e;for(let t of e.split(`;`)){let e=t.indexOf(`:`);if(e===-1)continue;let n=t.slice(0,e).trim(),r=t.slice(e+1).trim();if(!n)continue;let i=n.replace(/-([a-z])/g,(e,t)=>t.toUpperCase());this[i]=r}}setProperty(e,t,n){this[e]=t}getPropertyValue(e){let t=this[e];return typeof t==`string`?t:``}removeProperty(e){let t=this[e];return delete this[e],typeof t==`string`?t:``}getPropertyPriority(e){return``}},HTMLElement=class extends Element{constructor(...e){super(...e),this.style=new CSSStyleDeclaration}get dataset(){let e=this;return new Proxy({},{get(t,n){if(typeof n!=`string`)return;let r=`data-`+n.replace(/[A-Z]/g,e=>`-`+e.toLowerCase());return e.getAttribute(r)??void 0},set(t,n,r){if(typeof n!=`string`)return!1;let i=`data-`+n.replace(/[A-Z]/g,e=>`-`+e.toLowerCase());return e.setAttribute(i,String(r)),!0},deleteProperty(t,n){if(typeof n!=`string`)return!1;let r=`data-`+n.replace(/[A-Z]/g,e=>`-`+e.toLowerCase());return e.removeAttribute(r),!0},has(t,n){if(typeof n!=`string`)return!1;let r=`data-`+n.replace(/[A-Z]/g,e=>`-`+e.toLowerCase());return e.hasAttribute(r)}})}get title(){return this.getAttribute(`title`)??``}set title(e){this.setAttribute(`title`,e)}get lang(){return this.getAttribute(`lang`)??``}set lang(e){this.setAttribute(`lang`,e)}get dir(){return this.getAttribute(`dir`)??``}set dir(e){this.setAttribute(`dir`,e)}get accessKey(){return this.getAttribute(`accesskey`)??``}set accessKey(e){this.setAttribute(`accesskey`,e)}get accessKeyLabel(){return this.getAttribute(`accesskey`)??``}get hidden(){return this.hasAttribute(`hidden`)}set hidden(e){e?this.setAttribute(`hidden`,``):this.removeAttribute(`hidden`)}get draggable(){return this.getAttribute(`draggable`)===`true`}set draggable(e){this.setAttribute(`draggable`,String(e))}get spellcheck(){let e=this.getAttribute(`spellcheck`);return e===`false`?!1:e!==null}set spellcheck(e){this.setAttribute(`spellcheck`,String(e))}get translate(){return this.getAttribute(`translate`)!==`no`}set translate(e){this.setAttribute(`translate`,e?`yes`:`no`)}get tabIndex(){let e=this.getAttribute(`tabindex`);return e===null?-1:Number(e)}set tabIndex(e){this.setAttribute(`tabindex`,String(e))}get contentEditable(){let e=this.getAttribute(`contenteditable`);return e===``||e===`true`?`true`:e===`false`?`false`:`inherit`}set contentEditable(e){e===`inherit`?this.removeAttribute(`contenteditable`):this.setAttribute(`contenteditable`,e)}get isContentEditable(){return this.contentEditable===`true`}get offsetHeight(){return this._allocatedClientHeight}get offsetWidth(){return this._allocatedClientWidth}get offsetLeft(){return 0}get offsetTop(){return 0}get offsetParent(){return null}get clientHeight(){return this._allocatedClientHeight}get clientWidth(){return this._allocatedClientWidth}get clientLeft(){return 0}get clientTop(){return 0}get scrollHeight(){return this._allocatedClientHeight}get scrollWidth(){return this._allocatedClientWidth}get scrollTop(){return 0}set scrollTop(e){}get scrollLeft(){return 0}set scrollLeft(e){}getBoundingClientRect(){let e=this.clientWidth,t=this.clientHeight;return{x:0,y:0,top:0,left:0,right:e,bottom:t,width:e,height:t,toJSON(){return this}}}click(){this.dispatchEvent(new Event(`click`,{bubbles:!0,cancelable:!0}))}blur(){this.dispatchEvent(new Event(`blur`))}focus(){this.dispatchEvent(new Event(`focus`))}get onclick(){return this[P].get(`onclick`)??null}set onclick(e){this[P].set(`onclick`,e)}get ondblclick(){return this[P].get(`ondblclick`)??null}set ondblclick(e){this[P].set(`ondblclick`,e)}get onload(){return this[P].get(`onload`)??null}set onload(e){this[P].set(`onload`,e)}get onerror(){return this[P].get(`onerror`)??null}set onerror(e){this[P].set(`onerror`,e)}get onabort(){return this[P].get(`onabort`)??null}set onabort(e){this[P].set(`onabort`,e)}get onfocus(){return this[P].get(`onfocus`)??null}set onfocus(e){this[P].set(`onfocus`,e)}get onblur(){return this[P].get(`onblur`)??null}set onblur(e){this[P].set(`onblur`,e)}get onchange(){return this[P].get(`onchange`)??null}set onchange(e){this[P].set(`onchange`,e)}get oninput(){return this[P].get(`oninput`)??null}set oninput(e){this[P].set(`oninput`,e)}get onsubmit(){return this[P].get(`onsubmit`)??null}get onreset(){return this[P].get(`onreset`)??null}set onreset(e){this[P].set(`onreset`,e)}get onscroll(){return this[P].get(`onscroll`)??null}set onscroll(e){this[P].set(`onscroll`,e)}get onresize(){return this[P].get(`onresize`)??null}set onresize(e){this[P].set(`onresize`,e)}get onmousedown(){return this[P].get(`onmousedown`)??null}set onmousedown(e){this[P].set(`onmousedown`,e)}get onmouseup(){return this[P].get(`onmouseup`)??null}set onmouseup(e){this[P].set(`onmouseup`,e)}get onmousemove(){return this[P].get(`onmousemove`)??null}set onmousemove(e){this[P].set(`onmousemove`,e)}get onmouseover(){return this[P].get(`onmouseover`)??null}set onmouseover(e){this[P].set(`onmouseover`,e)}get onmouseout(){return this[P].get(`onmouseout`)??null}set onmouseout(e){this[P].set(`onmouseout`,e)}get onmouseenter(){return this[P].get(`onmouseenter`)??null}set onmouseenter(e){this[P].set(`onmouseenter`,e)}get onmouseleave(){return this[P].get(`onmouseleave`)??null}set onmouseleave(e){this[P].set(`onmouseleave`,e)}get oncontextmenu(){return this[P].get(`oncontextmenu`)??null}set oncontextmenu(e){this[P].set(`oncontextmenu`,e)}get onwheel(){return this[P].get(`onwheel`)??null}set onwheel(e){this[P].set(`onwheel`,e)}get onkeydown(){return this[P].get(`onkeydown`)??null}set onkeydown(e){this[P].set(`onkeydown`,e)}get onkeyup(){return this[P].get(`onkeyup`)??null}set onkeyup(e){this[P].set(`onkeyup`,e)}get ontouchstart(){return this[P].get(`ontouchstart`)??null}set ontouchstart(e){this[P].set(`ontouchstart`,e)}get ontouchend(){return this[P].get(`ontouchend`)??null}set ontouchend(e){this[P].set(`ontouchend`,e)}get ontouchmove(){return this[P].get(`ontouchmove`)??null}set ontouchmove(e){this[P].set(`ontouchmove`,e)}get onpointerdown(){return this[P].get(`onpointerdown`)??null}set onpointerdown(e){this[P].set(`onpointerdown`,e)}get onpointerup(){return this[P].get(`onpointerup`)??null}set onpointerup(e){this[P].set(`onpointerup`,e)}get onpointermove(){return this[P].get(`onpointermove`)??null}set onpointermove(e){this[P].set(`onpointermove`,e)}cloneNode(e=!1){return super.cloneNode(e)}get[Symbol.toStringTag](){return`HTMLElement`}},ut=class HTMLCanvasElement extends HTMLElement{constructor(...e){super(...e),this.oncontextlost=null,this.oncontextrestored=null,this.onwebglcontextcreationerror=null,this.onwebglcontextlost=null,this.onwebglcontextrestored=null}static{this._contextFactories=new Map}static registerContextFactory(e,t){HTMLCanvasElement._contextFactories.set(e,t)}get width(){let e=this.getAttribute(`width`);return e===null?300:Number(e)}set width(e){this.setAttribute(`width`,String(e))}get height(){let e=this.getAttribute(`height`);return e===null?150:Number(e)}set height(e){this.setAttribute(`height`,String(e))}getContext(e,t){let n=HTMLCanvasElement._contextFactories.get(e);return n?n(this,t):null}toDataURL(e,t){let n=this.getContext(`2d`);return n&&typeof n._toDataURL==`function`?n._toDataURL(e,t):``}toBlob(e,t,n){let r=this.toDataURL(t,n);if(!r){e(null);return}let[i,a]=r.split(`,`),o=i.split(`:`)[1].split(`;`)[0],s=atob(a),c=new Uint8Array(s.length);for(let e=0;e<s.length;e++)c[e]=s.charCodeAt(e);e(new Blob([c],{type:o}))}captureStream(e){return{}}},dt=class DOMMatrix{constructor(e){this.a=1,this.b=0,this.c=0,this.d=1,this.e=0,this.f=0,this.m11=1,this.m12=0,this.m13=0,this.m14=0,this.m21=0,this.m22=1,this.m23=0,this.m24=0,this.m31=0,this.m32=0,this.m33=1,this.m34=0,this.m41=0,this.m42=0,this.m43=0,this.m44=1,this.is2D=!0,this.isIdentity=!0,Array.isArray(e)&&(e.length===6?(this.a=this.m11=e[0],this.b=this.m12=e[1],this.c=this.m21=e[2],this.d=this.m22=e[3],this.e=this.m41=e[4],this.f=this.m42=e[5],this.is2D=!0):e.length===16&&(this.m11=e[0],this.m12=e[1],this.m13=e[2],this.m14=e[3],this.m21=e[4],this.m22=e[5],this.m23=e[6],this.m24=e[7],this.m31=e[8],this.m32=e[9],this.m33=e[10],this.m34=e[11],this.m41=e[12],this.m42=e[13],this.m43=e[14],this.m44=e[15],this.a=this.m11,this.b=this.m12,this.c=this.m21,this.d=this.m22,this.e=this.m41,this.f=this.m42,this.is2D=!1),this.isIdentity=this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.e===0&&this.f===0)}multiply(e){let t=this.a*e.a+this.c*e.b,n=this.b*e.a+this.d*e.b,r=this.a*e.c+this.c*e.d,i=this.b*e.c+this.d*e.d,a=this.a*e.e+this.c*e.f+this.e,o=this.b*e.e+this.d*e.f+this.f;return new DOMMatrix([t,n,r,i,a,o])}multiplySelf(e){let t=this.multiply(e);return this.a=t.a,this.b=t.b,this.c=t.c,this.d=t.d,this.e=t.e,this.f=t.f,this.m11=this.a,this.m12=this.b,this.m21=this.c,this.m22=this.d,this.m41=this.e,this.m42=this.f,this.isIdentity=!1,this}inverse(){let e=this.a*this.d-this.b*this.c;if(e===0)return new DOMMatrix([1,0,0,1,0,0]);let t=1/e;return new DOMMatrix([this.d*t,-this.b*t,-this.c*t,this.a*t,(this.c*this.f-this.d*this.e)*t,(this.b*this.e-this.a*this.f)*t])}translate(e=0,t=0){return this.multiply({a:1,b:0,c:0,d:1,e,f:t})}scale(e=1,t=e){return this.multiply({a:e,b:0,c:0,d:t,e:0,f:0})}};const ft=dt;function defineGlobal(e,t){Object.defineProperty(globalThis,e,{value:t,writable:!0,configurable:!0})}function defineGlobalIfMissing$2(e,t){globalThis[e]===void 0&&defineGlobal(e,t)}__name(defineGlobalIfMissing$2,`defineGlobalIfMissing`),setCanvasPixelBridge({imageFromSurface(e,t,n,r,i){return a.pixbuf_get_from_surface(e,t,n,r,i)},setSourceImage(e,t,n,r){a.cairo_set_source_pixbuf(e,t,n,r)},setSourcePixels(e,t,n,r,i,s){let c=o.Pixbuf.new_from_bytes(t,o.Colorspace.RGB,!0,8,n,r,n*4);a.cairo_set_source_pixbuf(e,c,i,s)}}),defineGlobal(`HTMLCanvasElement`,ut),defineGlobal(`CanvasRenderingContext2D`,CanvasRenderingContext2D),defineGlobal(`DOMMatrix`,dt),defineGlobal(`DOMMatrixReadOnly`,ft);const pt=Symbol.for(`gjsify_canvas2d_context`);ut.registerContextFactory(`2d`,(e,t)=>{let n=e,r=n[pt];if(r)return r;let i=new CanvasRenderingContext2D(e,t);return n[pt]=i,i});function defineGlobalIfMissing$1(e,t){globalThis[e]===void 0&&Object.defineProperty(globalThis,e,{value:t,writable:!0,configurable:!0})}__name(defineGlobalIfMissing$1,`defineGlobalIfMissing`),defineGlobalIfMissing$1(`ImageData`,OurImageData),defineGlobalIfMissing$1(`Path2D`,pe);var CharacterData=class extends nt{constructor(e=``){super(),this[Ce]=Pe.TEXT_NODE,this._data=e}get data(){return this._data}set data(e){this._data=e}get textContent(){return this._data}set textContent(e){this._data=e}get nodeValue(){return this._data}set nodeValue(e){this._data=e}get length(){return this._data.length}appendData(e){this._data+=e}deleteData(e,t){this._data=this._data.substring(0,e)+this._data.substring(e+t)}insertData(e,t){this._data=this._data.substring(0,e)+t+this._data.substring(e)}replaceData(e,t,n){this._data=this._data.substring(0,e)+n+this._data.substring(e+t)}substringData(e,t){return this._data.substring(e,e+t)}cloneNode(e=!1){return new this.constructor(this._data)}get[Symbol.toStringTag](){return`CharacterData`}},mt=class Comment extends CharacterData{constructor(e=``){super(e),this[Ce]=Pe.COMMENT_NODE}get nodeName(){return`#comment`}cloneNode(e=!1){return new Comment(this.data)}get[Symbol.toStringTag](){return`Comment`}},ht=class Text extends CharacterData{constructor(e=``){super(e),this[Ce]=Pe.TEXT_NODE}get nodeName(){return`#text`}get wholeText(){let e=this.data,t=this.previousSibling;for(;t&&t instanceof Text;)e=t.data+e,t=t.previousSibling;let n=this.nextSibling;for(;n&&n instanceof Text;)e+=n.data,n=n.nextSibling;return e}splitText(e){let t=this.data.substring(e);this.data=this.data.substring(0,e);let n=new Text(t);return this.parentNode&&this.parentNode.insertBefore(n,this.nextSibling),n}cloneNode(e=!1){return new Text(this.data)}get[Symbol.toStringTag](){return`Text`}},gt=class DocumentFragment extends nt{constructor(){super(),this[Ce]=Pe.DOCUMENT_FRAGMENT_NODE}get nodeName(){return`#document-fragment`}get children(){return this[Te]}get childElementCount(){return this[Te].length}get firstElementChild(){return this[Te][0]??null}get lastElementChild(){let e=this[Te];return e[e.length-1]??null}get textContent(){let e=``;for(let t of this.childNodes)t.textContent!==null&&(e+=t.textContent);return e}set textContent(e){for(;this.firstChild;)this.removeChild(this.firstChild);e&&this.appendChild(new ht(e))}append(...e){for(let t of e)typeof t==`string`?this.appendChild(new ht(t)):this.appendChild(t)}prepend(...e){let t=this.firstChild;for(let n of e)typeof n==`string`?this.insertBefore(new ht(n),t):this.insertBefore(n,t)}replaceChildren(...e){for(;this.firstChild;)this.removeChild(this.firstChild);this.append(...e)}getElementById(e){for(let t of this.children){if(t.id===e)return t;let n=this._findById(t,e);if(n)return n}return null}_findById(e,t){for(let n of e.children){if(n.id===t)return n;let e=this._findById(n,t);if(e)return e}return null}cloneNode(e=!1){let t=new DocumentFragment;if(e)for(let e of this.childNodes)t.appendChild(e.cloneNode(!0));return t}get[Symbol.toStringTag](){return`DocumentFragment`}},_t=s,vt=c,yt=l,HTMLImageElement$1=class extends HTMLElement{static{__name(this,`HTMLImageElement`)}constructor(){super(),this._complete=!1,this._naturalHeight=0,this._naturalWidth=0,this[N]=`IMG`,this[De]=`img`,this[Oe]=rt.html}get complete(){return this._complete}get naturalHeight(){return this._naturalHeight}get naturalWidth(){return this._naturalWidth}get currentSrc(){return this.src}get x(){return 0}get y(){return 0}get alt(){return this.getAttribute(`alt`)??``}set alt(e){this.setAttribute(`alt`,e)}get crossOrigin(){return this.getAttribute(`crossorigin`)}set crossOrigin(e){e===null?this.removeAttribute(`crossorigin`):this.setAttribute(`crossorigin`,e)}get decoding(){return this.getAttribute(`decoding`)??`auto`}set decoding(e){this.setAttribute(`decoding`,e)}get loading(){let e=this.getAttribute(`loading`);return e===`lazy`||e===`eager`?e:`auto`}set loading(e){this.setAttribute(`loading`,e)}get referrerPolicy(){return this.getAttribute(`referrerpolicy`)??``}set referrerPolicy(e){this.setAttribute(`referrerpolicy`,e)}get sizes(){return this.getAttribute(`sizes`)??``}set sizes(e){this.setAttribute(`sizes`,e)}get src(){return this.getAttribute(`src`)??``}set src(e){this.setAttribute(`src`,e);let t=globalThis.__GJSIFY_DEBUG_IMG===!0;if(e.startsWith(`data:`)){let n=e.indexOf(`,`);if(n===-1){this._complete=!0,this.dispatchEvent(new Event(`error`));return}let r=e.slice(5,n),i=e.slice(n+1),a=r.includes(`;base64`);try{let e;e=a?_t.base64_decode(i):new TextEncoder().encode(decodeURIComponent(i));let n=_t.Bytes.new(e),r=vt.MemoryInputStream.new_from_bytes(n);this._pixbuf=yt.Pixbuf.new_from_stream(r,null),this._naturalWidth=this._pixbuf.get_width(),this._naturalHeight=this._pixbuf.get_height(),this._complete=!0,t&&A.log(`[img] ok data: (${this._naturalWidth}x${this._naturalHeight})`),this.dispatchEvent(new Event(`load`))}catch(e){t&&A.warn(`[img] error data:: ${e instanceof Error?e.message:String(e)}`),this._complete=!0,this.dispatchEvent(new Event(`error`))}return}let n;if(e.startsWith(`file://`))n=_t.filename_from_uri(e)[0];else if(e.startsWith(`http://`)||e.startsWith(`https://`)){this._complete=!0,this.dispatchEvent(new Event(`error`));return}else{let t=_t.path_get_dirname(u.programInvocationName);n=_t.build_filenamev([t,e])}try{t&&A.log(`[img] load ${n}`),this._pixbuf=yt.Pixbuf.new_from_file(n),this._naturalWidth=this._pixbuf.get_width(),this._naturalHeight=this._pixbuf.get_height(),this._complete=!0,t&&A.log(`[img] ok ${n} (${this._naturalWidth}x${this._naturalHeight})`),this.dispatchEvent(new Event(`load`))}catch(e){t&&A.warn(`[img] error ${n}: ${e instanceof Error?e.message:String(e)}`),this._complete=!0,this.dispatchEvent(new Event(`error`))}}get srcset(){return this.getAttribute(`srcset`)??``}set srcset(e){this.setAttribute(`srcset`,e)}get useMap(){return this.getAttribute(`usemap`)??``}set useMap(e){this.setAttribute(`usemap`,e)}get height(){if(this._pixbuf)return this._pixbuf.get_height();let e=this.getAttribute(`height`);return e===null?0:Number(e)}set height(e){this.setAttribute(`height`,String(e))}get width(){if(this._pixbuf)return this._pixbuf.get_width();let e=this.getAttribute(`width`);return e===null?0:Number(e)}set width(e){this.setAttribute(`width`,String(e))}get isMap(){return this.hasAttribute(`ismap`)}set isMap(e){e?this.setAttribute(`ismap`,``):this.removeAttribute(`ismap`)}decode(){return Promise.resolve()}cloneNode(e=!1){return super.cloneNode(e)}getImageData(){if(!this._pixbuf)return null;let e=this._pixbuf.get_has_alpha()?this._pixbuf:this._pixbuf.add_alpha(!1,0,0,0)??this._pixbuf;return{colorSpace:`srgb`,data:new Uint8ClampedArray(e.get_pixels()),height:e.get_height(),width:e.get_width()}}isPixbuf(){return!!this._pixbuf}get[Symbol.toStringTag](){return`HTMLImageElement`}},HTMLMediaElement=class extends HTMLElement{constructor(...e){super(...e),this._src=``,this._srcObject=null,this.currentTime=0,this.duration=NaN,this.paused=!0,this.ended=!1,this.volume=1,this.muted=!1,this.defaultMuted=!1,this.loop=!1,this.autoplay=!1,this.preload=``,this.playbackRate=1,this.defaultPlaybackRate=1,this.readyState=0,this.networkState=0}get buffered(){return{length:0,start:()=>0,end:()=>0}}get seekable(){return{length:0,start:()=>0,end:()=>0}}get played(){return{length:0,start:()=>0,end:()=>0}}get src(){return this._src}set src(e){this._src=e,this._srcObject=null,this.dispatchEvent(new Event(`srcchange`))}get srcObject(){return this._srcObject}set srcObject(e){this._srcObject=e,this._src=``,this.dispatchEvent(new Event(`srcobjectchange`))}play(){return this.paused=!1,this.ended=!1,this.dispatchEvent(new Event(`play`)),Promise.resolve()}pause(){this.paused=!0,this.dispatchEvent(new Event(`pause`))}load(){this.readyState=0,this.networkState=2,this.dispatchEvent(new Event(`loadstart`))}canPlayType(e){return``}static{this.HAVE_NOTHING=0}static{this.HAVE_METADATA=1}static{this.HAVE_CURRENT_DATA=2}static{this.HAVE_FUTURE_DATA=3}static{this.HAVE_ENOUGH_DATA=4}static{this.NETWORK_EMPTY=0}static{this.NETWORK_IDLE=1}static{this.NETWORK_LOADING=2}static{this.NETWORK_NO_SOURCE=3}get[Symbol.toStringTag](){return`HTMLMediaElement`}};const bt=1e9;function secondsToGstTime(e){return BigInt(Math.round(e*bt))}function gstTimeToSeconds(e){return Number(e)/bt}var HTMLVideoElement$1=class extends HTMLMediaElement{static{__name(this,`HTMLVideoElement`)}constructor(){super(),this._pipeline=null,this._videoWidth=0,this._videoHeight=0,this.poster=``,this[N]=`VIDEO`,this[De]=`video`,this[Oe]=rt.html;let e=this;Object.defineProperty(this,"paused",{get(){if(!e._pipeline)return!0;let[,t]=e._pipeline.get_state(0n);return t!==4},configurable:!0,enumerable:!0}),Object.defineProperty(this,"currentTime",{get(){if(!e._pipeline)return 0;let[t,n]=e._pipeline.query_position(3);return t?gstTimeToSeconds(n):0},set(t){e._pipeline?.seek(1,3,5,1,secondsToGstTime(t),0,-1n)},configurable:!0,enumerable:!0}),Object.defineProperty(this,"duration",{get(){if(!e._pipeline)return NaN;let[t,n]=e._pipeline.query_duration(3);return t&&Number(n)>0?gstTimeToSeconds(n):NaN},configurable:!0,enumerable:!0}),Object.defineProperty(this,"volume",{get(){return e._playbin()?.volume??1},set(t){let n=e._playbin();n&&(n.volume=Math.max(0,Math.min(1,t)))},configurable:!0,enumerable:!0}),Object.defineProperty(this,"muted",{get(){return e._playbin()?.mute??!1},set(t){let n=e._playbin();n&&(n.mute=t)},configurable:!0,enumerable:!0})}async play(){this._pipeline?.set_state(4),this.dispatchEvent(new Event(`play`)),this.dispatchEvent(new Event(`playing`))}pause(){this._pipeline?.set_state(3),this.dispatchEvent(new Event(`pause`))}get videoWidth(){return this._videoWidth}set videoWidth(e){this._videoWidth=e}get videoHeight(){return this._videoHeight}set videoHeight(e){this._videoHeight=e}get[Symbol.toStringTag](){return`HTMLVideoElement`}_playbin(){return this._pipeline?.get_by_name(`playbin`)??null}};const xt=new class Document extends nt{static{this._elementFactories=new Map}constructor(){super(),this.body=new HTMLElement,this.head=new HTMLElement,this.documentElement=new HTMLElement,this.appendChild(this.documentElement),this.documentElement.appendChild(this.body)}static registerElementFactory(e,t){Document._elementFactories.set(e.toLowerCase(),t)}createElementNS(e,t){let n=t.toLowerCase();switch(n){case`img`:return new HTMLImageElement$1;case`video`:return new HTMLVideoElement$1;case`canvas`:return new ut;default:{let e=Document._elementFactories.get(n);return e?e():new HTMLElement}}}createElement(e){return this.createElementNS(`http://www.w3.org/1999/xhtml`,e)}createTextNode(e){return new ht(e)}createComment(e){return new mt(e)}createDocumentFragment(){return new gt}createEvent(e){return new Event(e)}getElementById(e){return this._findById(this.body,e)}_findById(e,t){if(e.id===t)return e;for(let n of e.children){let e=this._findById(n,t);if(e)return e}return null}get[Symbol.toStringTag](){return`Document`}};var DOMTokenList=class{constructor(e,t){this._ownerElement=e,this._attributeName=t}_getTokens(){let e=this._ownerElement.getAttribute(this._attributeName);return e?e.split(/\s+/).filter(e=>e.length>0):[]}_setTokens(e){let t=e.join(` `);t?this._ownerElement.setAttribute(this._attributeName,t):this._ownerElement.removeAttribute(this._attributeName)}get length(){return this._getTokens().length}get value(){return this._ownerElement.getAttribute(this._attributeName)??``}set value(e){e?this._ownerElement.setAttribute(this._attributeName,e):this._ownerElement.removeAttribute(this._attributeName)}item(e){let t=this._getTokens();return e>=0&&e<t.length?t[e]:null}contains(e){return this._getTokens().includes(e)}add(...e){let t=this._getTokens();for(let n of e)n&&!t.includes(n)&&t.push(n);this._setTokens(t)}remove(...e){let t=this._getTokens().filter(t=>!e.includes(t));this._setTokens(t)}toggle(e,t){let n=this.contains(e);return t===void 0?n?(this.remove(e),!1):(this.add(e),!0):t?(this.add(e),!0):(this.remove(e),!1)}replace(e,t){let n=this._getTokens(),r=n.indexOf(e);return r===-1?!1:(n[r]=t,this._setTokens(n),!0)}supports(e){return!0}forEach(e){let t=this._getTokens();for(let n=0;n<t.length;n++)e(t[n],n,this)}keys(){return this._getTokens().keys()}values(){return this._getTokens().values()}entries(){return this._getTokens().entries()}[Symbol.iterator](){return this._getTokens().values()}toString(){return this.value}get[Symbol.toStringTag](){return`DOMTokenList`}};function installWindowEventBus(e){if(e.__gjsify_globalEventTarget)return e.__gjsify_globalEventTarget;let t=new EventTarget,n=typeof e.addEventListener==`function`?e.addEventListener.bind(e):null,r=typeof e.removeEventListener==`function`?e.removeEventListener.bind(e):null;e.__gjsify_globalEventTarget=t;let define=(t,n)=>Object.defineProperty(e,t,{value:n,writable:!0,configurable:!0});return define(`addEventListener`,(e,r,i)=>{t.addEventListener(e,r,i),n?.(e,r,i)}),define(`removeEventListener`,(e,n,i)=>{t.removeEventListener(e,n,i),r?.(e,n,i)}),define(`dispatchEvent`,e=>t.dispatchEvent(e)),t}defineGlobal(`Text`,ht),defineGlobal(`Comment`,mt),defineGlobal(`DocumentFragment`,gt),defineGlobal(`DOMTokenList`,DOMTokenList),defineGlobal(`document`,xt),defineGlobalIfMissing$2(`self`,globalThis);var Window=class{static[Symbol.hasInstance](e){return e===globalThis}};defineGlobalIfMissing$2(`Window`,Window),defineGlobalIfMissing$2(`window`,globalThis),defineGlobalIfMissing$2(`focus`,()=>{}),defineGlobalIfMissing$2(`blur`,()=>{}),installWindowEventBus(globalThis),defineGlobalIfMissing$2(`devicePixelRatio`,1),defineGlobalIfMissing$2(`scrollX`,0),defineGlobalIfMissing$2(`scrollY`,0),defineGlobalIfMissing$2(`pageXOffset`,0),defineGlobalIfMissing$2(`pageYOffset`,0),defineGlobalIfMissing$2(`alert`,(...e)=>A.error(`alert:`,...e)),globalThis.top===void 0&&Object.defineProperty(globalThis,"top",{get:()=>globalThis,configurable:!0});var Image=class extends HTMLImageElement$1{constructor(e=null,t=null){super(),e!==null&&(this.width=e),t!==null&&(this.height=t)}};defineGlobal(`HTMLImageElement`,HTMLImageElement$1),defineGlobal(`Image`,Image),globalThis.navigator===void 0&&(globalThis.navigator={});const St=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,Ct=new Uint8Array(256);for(let e=0;e<64;e++)Ct[St.charCodeAt(e)]=e;function btoaPolyfill(e){if(typeof globalThis.btoa==`function`)return globalThis.btoa(e);let t=``,n=0;for(;n+2<e.length;n+=3){let r=e.charCodeAt(n)<<16|e.charCodeAt(n+1)<<8|e.charCodeAt(n+2);t+=St[r>>18&63]+St[r>>12&63]+St[r>>6&63]+St[r&63]}if(n+1===e.length){let r=e.charCodeAt(n)<<16;t+=St[r>>18&63]+St[r>>12&63]+`==`}else if(n+2===e.length){let r=e.charCodeAt(n)<<16|e.charCodeAt(n+1)<<8;t+=St[r>>18&63]+St[r>>12&63]+St[r>>6&63]+`=`}return t}function base64Decode(e){let t=e.replace(/[=\s]/g,``),n=new Uint8Array(t.length*3>>2),r=0,i=0,a=0;for(let e=0;e<t.length;e++)r=r<<6|Ct[t.charCodeAt(e)],i+=6,i>=8&&(i-=8,n[a++]=r>>i&255);return n.subarray(0,a)}function base64Encode(e){let t=``,n=e.length;for(let r=0;r<n;r+=3){let i=e[r],a=r+1<n?e[r+1]:0,o=r+2<n?e[r+2]:0;t+=St[i>>2],t+=St[(i&3)<<4|a>>4],t+=r+1<n?St[(a&15)<<2|o>>6]:`=`,t+=r+2<n?St[o&63]:`=`}return t}const wt=[`utf8`,`ascii`,`latin1`,`binary`,`base64`,`base64url`,`hex`,`ucs2`,`utf16le`];function normalizeEncoding(e){if(!e||e===`utf8`||e===`utf-8`)return`utf8`;switch((``+e).toLowerCase().replace(/-/g,``)){case`utf8`:return`utf8`;case`ascii`:return`ascii`;case`latin1`:case`binary`:return`latin1`;case`base64`:return`base64`;case`base64url`:return`base64url`;case`hex`:return`hex`;case`ucs2`:case`utf16le`:return`utf16le`;default:return`utf8`}}function checkEncoding(e){let t=(``+e).toLowerCase().replace(/-/g,``);if(!wt.includes(t))throw TypeError(`Unknown encoding: ${e}`)}let Tt,Et;const textEncoder=()=>Tt??=new TextEncoder,textDecoder=()=>Et??=new TextDecoder;function encodeString(e,t){switch(t){case`utf8`:return textEncoder().encode(e);case`ascii`:{let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&127;return t}case`latin1`:{let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t}case`base64`:return base64Decode(e.replace(/-/g,`+`).replace(/_/g,`/`));case`base64url`:return encodeString(e.replace(/-/g,`+`).replace(/_/g,`/`),`base64`);case`hex`:{let t=e.length>>>1,n=new Uint8Array(t);for(let r=0;r<t;r++){let t=parseInt(e[r*2],16),i=parseInt(e[r*2+1],16);if(Number.isNaN(t)||Number.isNaN(i))break;n[r]=t<<4|i}return n}case`utf16le`:{let t=new Uint8Array(e.length*2);for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t[n*2]=r&255,t[n*2+1]=r>>8&255}return t}default:return textEncoder().encode(e)}}function decodeString(e,t,n,r){let i=n!==void 0||r!==void 0?e.subarray(n??0,r??e.length):e;switch(t){case`utf8`:return textDecoder().decode(i);case`ascii`:{let e=``;for(let t=0;t<i.length;t++)e+=String.fromCharCode(i[t]&127);return e}case`latin1`:{let e=``;for(let t=0;t<i.length;t++)e+=String.fromCharCode(i[t]);return e}case`base64`:{let e=``;for(let t=0;t<i.length;t++)e+=String.fromCharCode(i[t]);return btoaPolyfill(e)}case`base64url`:return decodeString(i,`base64`).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``);case`hex`:{let e=``;for(let t=0;t<i.length;t++)e+=i[t].toString(16).padStart(2,`0`);return e}case`utf16le`:{let e=``;for(let t=0;t+1<i.length;t+=2)e+=String.fromCharCode(i[t]|i[t+1]<<8);return e}default:return textDecoder().decode(i)}}function checkOffset(e,t,n){if(e+t>n)throw RangeError(`Attempt to access memory outside buffer bounds`)}const Dt=typeof SharedArrayBuffer<`u`;var Ot=class Buffer extends Uint8Array{static _isBuffer=!0;static alloc(e,t,n){if(typeof e!=`number`)throw TypeError(`The "size" argument must be of type number. Received type ${typeof e}`);if(e<0)throw RangeError(`The value "${e}" is invalid for option "size"`);let r=new Buffer(e);return t!==void 0&&t!==0&&r.fill(t,0,e,n),r}static allocUnsafe(e){if(typeof e!=`number`)throw TypeError(`The "size" argument must be of type number. Received type ${typeof e}`);return new Buffer(e)}static allocUnsafeSlow(e){return Buffer.allocUnsafe(e)}static from(e,t,n){if(typeof e==`string`){let n=normalizeEncoding(t);if(t&&typeof t==`string`){let e=(``+t).toLowerCase().replace(/-/g,``);[`utf8`,`ascii`,`latin1`,`binary`,`base64`,`base64url`,`hex`,`ucs2`,`utf16le`,``].includes(e)||checkEncoding(t)}let r=encodeString(e,n);return new Buffer(r.buffer,r.byteOffset,r.byteLength)}if(ArrayBuffer.isView(e)){let t=new Buffer(e.buffer,e.byteOffset,e.byteLength),n=new Buffer(t.length);return n.set(t),n}if(e instanceof ArrayBuffer){let r=t||0,i=n===void 0?e.byteLength-r:n;return new Buffer(e,r,i)}if(Dt&&e instanceof SharedArrayBuffer){let r=t||0,i=n===void 0?e.byteLength-r:n;return new Buffer(new Uint8Array(e,r,i))}if(typeof e==`object`&&e&&typeof e.viewBytes==`function`&&typeof e.byteLength==`number`&&e.constructor?.name===`SharedBuffer`){let r=e,i=t||0,a=n===void 0?r.byteLength-i:n,o=r.viewBytes(i,a);return new Buffer(o.buffer,o.byteOffset,o.byteLength)}if(Array.isArray(e)){let t=new Buffer(e.length);for(let n=0;n<e.length;n++)t[n]=e[n]&255;return t}throw TypeError(`The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array`)}static isBuffer(e){return e instanceof Buffer}static isEncoding(e){if(typeof e!=`string`)return!1;let t=e.toLowerCase().replace(/-/g,``);return[`utf8`,`ascii`,`latin1`,`binary`,`base64`,`base64url`,`hex`,`ucs2`,`utf16le`].includes(t)}static byteLength(e,t){if(typeof e!=`string`){if(ArrayBuffer.isView(e)||e instanceof ArrayBuffer||Dt&&e instanceof SharedArrayBuffer)return e.byteLength;throw TypeError(`The "string" argument must be one of type string, Buffer, or ArrayBuffer`)}switch(normalizeEncoding(t)){case`utf8`:return new TextEncoder().encode(e).byteLength;case`ascii`:case`latin1`:return e.length;case`base64`:case`base64url`:{let t=e.length;for(;t>0&&(e[t-1]===`=`||e[t-1]===` `);)t--;return t*3>>>2}case`hex`:return e.length>>>1;case`utf16le`:return e.length*2;default:return new TextEncoder().encode(e).byteLength}}static compare(e,t){if(!(e instanceof Uint8Array)||!(t instanceof Uint8Array))throw TypeError(`Arguments must be Buffers or Uint8Arrays`);let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){if(e[r]<t[r])return-1;if(e[r]>t[r])return 1}return e.length<t.length?-1:+(e.length>t.length)}static concat(e,t){if(e.length===0)return Buffer.alloc(0);if(t===void 0){t=0;for(let n=0;n<e.length;n++)t+=e[n].length}let n=Buffer.alloc(t),r=0;for(let i=0;i<e.length;i++){let a=e[i],o=Math.min(a.length,t-r);o<=0||(n.set(a.subarray(0,o),r),r+=o)}return n}static poolSize=65536;toString(e,t,n){let r=normalizeEncoding(e);return decodeString(this,r,t,n)}toJSON(){return{type:`Buffer`,data:Array.from(this)}}equals(e){if(!(e instanceof Uint8Array))throw TypeError(`Argument must be a Buffer or Uint8Array`);if(this.length!==e.length)return!1;for(let t=0;t<this.length;t++)if(this[t]!==e[t])return!1;return!0}compare(e,t,n,r,i){if(!(e instanceof Uint8Array))throw TypeError(`Argument must be a Buffer or Uint8Array`);let a=r!==void 0||i!==void 0?this.subarray(r??0,i??this.length):this,o=t!==void 0||n!==void 0?e.subarray(t??0,n??e.length):e;return Buffer.compare(a,o)}copy(e,t=0,n=0,r){let i=r??this.length,a=Math.min(i-n,e.length-t);return a<=0?0:(e.set(this.subarray(n,n+a),t),a)}slice(e,t){let n=e??0,r=t??this.length,i=super.subarray(n,r);return new Buffer(i.buffer,i.byteOffset,i.byteLength)}subarray(e,t){let n=super.subarray(e,t);return new Buffer(n.buffer,n.byteOffset,n.byteLength)}write(e,t,n,r){t??=0;let i=encodeString(e,normalizeEncoding(r||(typeof n==`string`?n:void 0))),a=n!==void 0&&typeof n==`number`?Math.min(n,this.length-t):this.length-t,o=Math.min(i.length,a);return this.set(i.subarray(0,o),t),o}fill(e,t,n,r){let i=t??0,a=n??this.length;if(typeof e==`number`)super.fill(e&255,i,a);else if(typeof e==`string`){let t=encodeString(e,normalizeEncoding(r));if(t.length===0)super.fill(0,i,a);else if(t.length===1)super.fill(t[0],i,a);else for(let e=i;e<a;e++)this[e]=t[(e-i)%t.length]}else if(e instanceof Uint8Array)if(e.length===0)super.fill(0,i,a);else for(let t=i;t<a;t++)this[t]=e[(t-i)%e.length];return this}indexOf(e,t,n){if(typeof e==`number`)return super.indexOf(e&255,t);let r=typeof e==`string`?encodeString(e,normalizeEncoding(n)):e,i=t??0;outer:for(let e=i;e<=this.length-r.length;e++){for(let t=0;t<r.length;t++)if(this[e+t]!==r[t])continue outer;return e}return-1}lastIndexOf(e,t,n){if(typeof e==`number`)return t===void 0?super.lastIndexOf(e&255):super.lastIndexOf(e&255,t);let r=typeof e==`string`?encodeString(e,normalizeEncoding(n)):e,i=t===void 0?this.length-r.length:Math.min(t,this.length-r.length);outer:for(let e=i;e>=0;e--){for(let t=0;t<r.length;t++)if(this[e+t]!==r[t])continue outer;return e}return-1}includes(e,t,n){return this.indexOf(e,t,n)!==-1}readUInt8(e=0){return checkOffset(e,1,this.length),this[e]}readUInt16BE(e=0){return checkOffset(e,2,this.length),this[e]<<8|this[e+1]}readUInt16LE(e=0){return checkOffset(e,2,this.length),this[e]|this[e+1]<<8}readUInt32BE(e=0){return checkOffset(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])}readUInt32LE(e=0){return checkOffset(e,4,this.length),this[e+3]*16777216+(this[e+2]<<16|this[e+1]<<8|this[e])>>>0}readInt8(e=0){return checkOffset(e,1,this.length),this[e]|(this[e]&128?4294967040:0)}readInt16BE(e=0){checkOffset(e,2,this.length);let t=this[e]<<8|this[e+1];return t&32768?t|4294901760:t}readInt16LE(e=0){checkOffset(e,2,this.length);let t=this[e]|this[e+1]<<8;return t&32768?t|4294901760:t}readInt32BE(e=0){return checkOffset(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]}readInt32LE(e=0){return checkOffset(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24}readFloatBE(e=0){return checkOffset(e,4,this.length),new DataView(this.buffer,this.byteOffset+e,4).getFloat32(0,!1)}readFloatLE(e=0){return checkOffset(e,4,this.length),new DataView(this.buffer,this.byteOffset+e,4).getFloat32(0,!0)}readDoubleBE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getFloat64(0,!1)}readDoubleLE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getFloat64(0,!0)}readBigInt64BE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getBigInt64(0,!1)}readBigInt64LE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getBigInt64(0,!0)}readBigUInt64BE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getBigUint64(0,!1)}readBigUInt64LE(e=0){return checkOffset(e,8,this.length),new DataView(this.buffer,this.byteOffset+e,8).getBigUint64(0,!0)}readUIntBE(e,t){checkOffset(e,t,this.length);let n=0;for(let r=0;r<t;r++)n=n*256+this[e+r];return n}readUIntLE(e,t){checkOffset(e,t,this.length);let n=0,r=1;for(let i=0;i<t;i++)n+=this[e+i]*r,r*=256;return n}readIntBE(e,t){checkOffset(e,t,this.length);let n=0;for(let r=0;r<t;r++)n=n*256+this[e+r];return n>=2**(8*t-1)&&(n-=2**(8*t)),n}readIntLE(e,t){checkOffset(e,t,this.length);let n=0,r=1;for(let i=0;i<t;i++)n+=this[e+i]*r,r*=256;return n>=2**(8*t-1)&&(n-=2**(8*t)),n}writeUInt8(e,t=0){return checkOffset(t,1,this.length),this[t]=e&255,t+1}writeUInt16BE(e,t=0){return checkOffset(t,2,this.length),this[t]=e>>>8&255,this[t+1]=e&255,t+2}writeUInt16LE(e,t=0){return checkOffset(t,2,this.length),this[t]=e&255,this[t+1]=e>>>8&255,t+2}writeUInt32BE(e,t=0){return checkOffset(t,4,this.length),this[t]=e>>>24&255,this[t+1]=e>>>16&255,this[t+2]=e>>>8&255,this[t+3]=e&255,t+4}writeUInt32LE(e,t=0){return checkOffset(t,4,this.length),this[t]=e&255,this[t+1]=e>>>8&255,this[t+2]=e>>>16&255,this[t+3]=e>>>24&255,t+4}writeInt8(e,t=0){return checkOffset(t,1,this.length),e<0&&(e=255+e+1),this[t]=e&255,t+1}writeInt16BE(e,t=0){return checkOffset(t,2,this.length),this[t]=e>>>8&255,this[t+1]=e&255,t+2}writeInt16LE(e,t=0){return checkOffset(t,2,this.length),this[t]=e&255,this[t+1]=e>>>8&255,t+2}writeInt32BE(e,t=0){return checkOffset(t,4,this.length),this[t]=e>>>24&255,this[t+1]=e>>>16&255,this[t+2]=e>>>8&255,this[t+3]=e&255,t+4}writeInt32LE(e,t=0){return checkOffset(t,4,this.length),this[t]=e&255,this[t+1]=e>>>8&255,this[t+2]=e>>>16&255,this[t+3]=e>>>24&255,t+4}writeFloatBE(e,t=0){return checkOffset(t,4,this.length),new DataView(this.buffer,this.byteOffset+t,4).setFloat32(0,e,!1),t+4}writeFloatLE(e,t=0){return checkOffset(t,4,this.length),new DataView(this.buffer,this.byteOffset+t,4).setFloat32(0,e,!0),t+4}writeDoubleBE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setFloat64(0,e,!1),t+8}writeDoubleLE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setFloat64(0,e,!0),t+8}writeBigInt64BE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setBigInt64(0,e,!1),t+8}writeBigInt64LE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setBigInt64(0,e,!0),t+8}writeBigUInt64BE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setBigUint64(0,e,!1),t+8}writeBigUInt64LE(e,t=0){return checkOffset(t,8,this.length),new DataView(this.buffer,this.byteOffset+t,8).setBigUint64(0,e,!0),t+8}swap16(){let e=this.length;if(e%2!=0)throw RangeError(`Buffer size must be a multiple of 16-bits`);for(let t=0;t<e;t+=2){let e=this[t];this[t]=this[t+1],this[t+1]=e}return this}swap32(){let e=this.length;if(e%4!=0)throw RangeError(`Buffer size must be a multiple of 32-bits`);for(let t=0;t<e;t+=4){let e=this[t],n=this[t+1];this[t]=this[t+3],this[t+1]=this[t+2],this[t+2]=n,this[t+3]=e}return this}swap64(){let e=this.length;if(e%8!=0)throw RangeError(`Buffer size must be a multiple of 64-bits`);for(let t=0;t<e;t+=8){let e=this[t],n=this[t+1],r=this[t+2],i=this[t+3];this[t]=this[t+7],this[t+1]=this[t+6],this[t+2]=this[t+5],this[t+3]=this[t+4],this[t+4]=i,this[t+5]=r,this[t+6]=n,this[t+7]=e}return this}};`Buffer`in globalThis||Object.defineProperty(globalThis,"Buffer",{value:Ot,enumerable:!1,writable:!0,configurable:!0}),typeof globalThis.btoa!=`function`&&Object.defineProperty(globalThis,"btoa",{value:function btoa(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return _t.base64_encode(t)},enumerable:!0,writable:!0,configurable:!0}),typeof globalThis.atob!=`function`&&Object.defineProperty(globalThis,"atob",{value:function atob(e){let t=_t.base64_decode(e),n=``;for(let e=0;e<t.length;e++)n+=String.fromCharCode(t[e]);return n},enumerable:!0,writable:!0,configurable:!0}),typeof queueMicrotask!=`function`&&Object.defineProperty(globalThis,"queueMicrotask",{value:j,enumerable:!0,writable:!0,configurable:!0});function getGjsGlobal(){return globalThis}function getGioNamespace(){let e=getGjsGlobal().imports?.gi;if(!e)return null;let t=null;try{t=e.GioUnix??null}catch{}if(!t)try{t=e.Gio??null}catch{}return t}function getMonotonicTime(){try{let e=getGjsGlobal().imports?.gi?.GLib;if(e?.get_monotonic_time)return BigInt(e.get_monotonic_time())*1000n}catch{}return typeof performance?.now==`function`?BigInt(Math.round(performance.now()*1e6)):BigInt(Date.now())*1000000n}const kt=getMonotonicTime();function hrtime(e){let t=getMonotonicTime()-kt,n=Number(t/1000000000n),r=Number(t%1000000000n);if(e){let t=n-e[0],i=r-e[1];return i<0&&(t--,i+=1e9),[t,i]}return[n,r]}function hrtimeBigint(){return getMonotonicTime()-kt}let At;function probeUname(){if(At!==void 0)return At;At=null;try{let e=getGjsGlobal().imports?.gi?.GLib;if(!e)return At;let t=e.spawn_sync,n=e.SpawnFlags?.SEARCH_PATH;if(!t||n===void 0)return At;let[r,i]=t(null,[`uname`,`-sm`],null,n,null);if(!r||!i)return At;let a=new TextDecoder().decode(i).trim().split(/\s+/);if(a.length<2)return At;let o=mapSysname(a[0]),s=mapMachine(a[a.length-1]);if(!o||!s)return At;At={platform:o,arch:s}}catch{}return At}function detectGjsVersion(){try{let e=getGjsGlobal().imports?.system;if(e?.version!==void 0){let t=Number(e.version);return`${Math.floor(t/1e4)}.${Math.floor(t%1e4/100)}.${t%100}`}}catch{}}function detectNodeVersion(){if(typeof globalThis.process?.versions?.node==`string`)return globalThis.process.versions.node}function detectVersionInfo(){if(detectNodeVersion())return{version:globalThis.process.version,versions:{...globalThis.process.versions},title:globalThis.process?.title||`node`};let e=detectGjsVersion(),t={node:`20.0.0`};return e&&(t.gjs=e),{version:`v20.0.0`,versions:t,title:`gjs`}}function detectPpid(){return!onGjs()&&typeof globalThis.process?.ppid==`number`?globalThis.process.ppid:hostPpid()??0}function onGjs(){try{return getGjsGlobal().imports?.gi!==void 0}catch{return!1}}function detectPlatform(){if(onGjs()){let e=probeUname();return e?e.platform:`linux`}let e=globalThis.process;return typeof e?.platform==`string`?e.platform:`linux`}function detectArch(){if(onGjs()){let e=probeUname();return e?e.arch:`x64`}let e=globalThis.process;return typeof e?.arch==`string`?e.arch:`x64`}function getPid(){return!onGjs()&&typeof globalThis.process?.pid==`number`?globalThis.process.pid:hostPid()??0}function getEnvProxy(){if(typeof globalThis.process?.env==`object`)return globalThis.process.env;try{let e=getGjsGlobal().imports?.gi?.GLib;if(e)return new Proxy({},{get(t,n){if(typeof n==`string`)return e.getenv(n)??void 0},set(t,n,r){return typeof n==`string`?(e.setenv(n,String(r),!0),!0):!1},deleteProperty(t,n){return typeof n==`string`?(e.unsetenv(n),!0):!1},has(t,n){return typeof n==`string`?e.getenv(n)!==null:!1},ownKeys(t){return e.listenv()},getOwnPropertyDescriptor(t,n){if(typeof n!=`string`)return;let r=e.getenv(n);if(r!==null)return{configurable:!0,enumerable:!0,writable:!0,value:r}}})}catch{}return{}}function getArgv(){if(globalThis.process?.argv!==void 0)return globalThis.process.argv;try{let e=getGjsGlobal().imports?.system;if(e?.programArgs)return[`gjs`,e.programInvocationName||``,...e.programArgs]}catch{}return[`gjs`]}function getExecPath(){let e=globalThis.process;return!isGjsHost()&&typeof e?.execPath==`string`?e.execPath:hostExecPath()??`/usr/bin/gjs`}function isGjsHost(){try{return getGjsGlobal().imports?.gi!==void 0}catch{return!1}}function getCwd(){try{let e=getGjsGlobal().imports?.gi?.GLib;if(e?.get_current_dir)return e.get_current_dir()}catch{}return`/`}function chdir(e){let t=getGjsGlobal().imports?.gi?.GLib;try{if(t?.chdir){if(!t.file_test(e,16)){let t=Error(`ENOENT: no such file or directory, chdir '${e}'`);throw t.code=`ENOENT`,t.syscall=`chdir`,t.path=e,t}t.chdir(e);return}}catch(e){if(e&&typeof e==`object`&&e.code===`ENOENT`)throw e}if(!t){let t=globalThis.process;if(t&&typeof t.chdir==`function`){t.chdir(e);return}}throw Error(`process.chdir() is not supported in this environment`)}function exitProcess(e){let t=getGjsGlobal().imports,n=t?.gi?.GLib,r=t?.system,i=n?.idle_add,a=n?.SOURCE_REMOVE,o=n?.PRIORITY_DEFAULT;if(r?.exit&&i&&typeof o==`number`&&typeof a==`boolean`)return ensureMainLoop(),i(o,()=>(quitMainLoop(),r.exit(e),a)),new Promise(()=>{});try{r?.exit&&r.exit(e)}catch{}let s=globalThis.process;throw s&&typeof s.exit==`function`&&s.exit(e),Error(`process.exit(${e})`)}function isGjs(){return getGjsGlobal().imports?.gi?.GLib!==void 0}function killPid(e,t){try{let n=getGjsGlobal().imports?.gi?.GLib;if(n){let r=typeof t==`number`?String(t):t||`SIGTERM`,i=r.startsWith(`SIG`)?`-${r.slice(3)}`:`-${r}`;return n.spawn_command_line_sync(`kill ${i} ${e}`),!0}}catch{}if(!isGjs()){let n=globalThis.process;if(n&&typeof n.kill==`function`)return n.kill(e,t)}throw Error(`process.kill() is not supported in this environment`)}function memoryUsage(){let e=readProcessMemory();if(e)return{rss:e.resident,heapTotal:e.resident,heapUsed:e.resident,external:0,arrayBuffers:0};if(!isGjs()){let e=globalThis.process;if(e&&typeof e.memoryUsage==`function`)return e.memoryUsage()}return{rss:0,heapTotal:0,heapUsed:0,external:0,arrayBuffers:0}}function cpuUsage(e){if(!isGjs()){let t=globalThis.process;if(t&&typeof t.cpuUsage==`function`)return t.cpuUsage(e)}return{user:0,system:0}}function readUmask(){try{let e=getGjsGlobal().imports?.gi?.GLib;if(e){let[t,n]=e.file_get_contents(`/proc/self/status`);if(t){let e=/^Umask:\s*([0-7]+)/m.exec(new TextDecoder().decode(n));if(e)return parseInt(e[1],8)}}}catch{}return 18}let jt=null;const Mt=globalThis.imports?.gi;if(Mt)try{jt=Mt.GjsifyTerminal}catch{}const Nt=jt,Pt=Symbol(`kCapture`),Ft=Symbol.for(`nodejs.rejection`);function onceWrapper(){let{target:e,type:t,listener:n}=this;return this.wrapperFn&&e.removeListener(t,this.wrapperFn),n.apply(e,Array.from(arguments))}function _onceWrap(e,t,n){let r={target:e,type:t,listener:n,wrapperFn:void 0},i=onceWrapper.bind(r);return r.wrapperFn=i,i.listener=n,i}function arrayClone(e){switch(e.length){case 0:return[];case 1:return[e[0]];case 2:return[e[0],e[1]];case 3:return[e[0],e[1],e[2]];default:return e.slice()}}function checkListener(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}function validateNumber(e,t){if(typeof e!=`number`||e!==e)throw TypeError(`The "${t}" argument must be of type number. Received type ${typeof e}`)}function spliceOne(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}var It=class EventEmitter{static defaultMaxListeners=10;static errorMonitor=Symbol(`events.errorMonitor`);static captureRejectionSymbol=Ft;static _captureRejections=!1;static get captureRejections(){return EventEmitter._captureRejections}static set captureRejections(e){if(typeof e!=`boolean`)throw TypeError(`The "captureRejections" argument must be of type boolean.`);EventEmitter._captureRejections=e}_events;_eventsCount;_maxListeners;[Pt];constructor(e){this._events=Object.create(null),this._eventsCount=0,this._maxListeners=void 0,this[Pt]=e?.captureRejections??EventEmitter._captureRejections}setMaxListeners(e){if(validateNumber(e,`n`),e<0)throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e);return this._maxListeners=e,this}getMaxListeners(){return this._maxListeners??EventEmitter.defaultMaxListeners}emit(e,...t){let n=this._events,r=e===`error`;if(n!==void 0)r&&n[EventEmitter.errorMonitor]!==void 0&&this.emit(EventEmitter.errorMonitor,...t),r&&=n.error===void 0;else if(!r)return!1;if(r){let e;if(e=t.length>0?t[0]:Error(`Unhandled error.`),e instanceof Error)throw e;let n=Error(`Unhandled error. (`+e+`)`);throw n.context=e,n}let i=n[e];if(i===void 0)return!1;if(typeof i==`function`){let n=i.apply(this,t);n!=null&&this[Pt]&&this._addCatch(n,e,t)}else{let n=arrayClone(i),r=n.length;for(let i=0;i<r;++i){let r=n[i].apply(this,t);r!=null&&this[Pt]&&this._addCatch(r,e,t)}}return!0}_addCatch(e,t,n){typeof e?.then==`function`&&e.then(void 0,e=>{let r=this[Ft];if(typeof r==`function`)r.call(this,e,t,...n);else{let t=this[Pt];try{this[Pt]=!1,this.emit(`error`,e)}finally{this[Pt]=t}}})}addListener(e,t){return this._addListener(e,t,!1)}on(e,t){return this._addListener(e,t,!1)}prependListener(e,t){return this._addListener(e,t,!0)}_addListener(e,t,n){checkListener(t);let r=this._events;r===void 0?(r=this._events=Object.create(null),this._eventsCount=0):r.newListener!==void 0&&(this.emit(`newListener`,e,t.listener??t),r=this._events);let i=r[e];i===void 0?(r[e]=t,++this._eventsCount):typeof i==`function`?r[e]=n?[t,i]:[i,t]:n?i.unshift(t):i.push(t);let a=this.getMaxListeners();if(a>0){let t=typeof r[e]==`function`?1:r[e].length;if(t>a&&!r[e].warned){typeof r[e]!=`function`&&(r[e].warned=!0);let n=Error(`Possible EventEmitter memory leak detected. ${t} ${String(e)} listeners added to [${this.constructor.name}]. Use emitter.setMaxListeners() to increase limit`);n.name=`MaxListenersExceededWarning`,A.warn(n.message)}}return this}once(e,t){return checkListener(t),this.on(e,_onceWrap(this,e,t)),this}prependOnceListener(e,t){return checkListener(t),this.prependListener(e,_onceWrap(this,e,t)),this}removeListener(e,t){checkListener(t);let n=this._events;if(n===void 0)return this;let r=n[e];if(r===void 0)return this;if(r===t||r.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit(`removeListener`,e,r.listener??t));else if(typeof r!=`function`){let i=-1;for(let e=r.length-1;e>=0;e--)if(r[e]===t||r[e].listener===t){i=e;break}if(i<0)return this;i===0?r.shift():spliceOne(r,i),r.length===1&&(n[e]=r[0]),n.removeListener!==void 0&&this.emit(`removeListener`,e,t.listener??t)}return this}off(e,t){return this.removeListener(e,t)}removeAllListeners(e){let t=this._events;if(t===void 0)return this;if(t.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):t[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete t[e]),this;if(arguments.length===0){let e=Object.keys(t);for(let t=0;t<e.length;++t){let n=e[t];n!==`removeListener`&&this.removeAllListeners(n)}return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}let n=t[e];if(typeof n==`function`)this.removeListener(e,n);else if(n!==void 0)for(let t=n.length-1;t>=0;t--)this.removeListener(e,n[t]);return this}listeners(e){let t=this._events;if(t===void 0)return[];let n=t[e];return n===void 0?[]:typeof n==`function`?[n.listener??n]:unwrapListeners(n)}rawListeners(e){let t=this._events;if(t===void 0)return[];let n=t[e];return n===void 0?[]:typeof n==`function`?[n]:arrayClone(n)}listenerCount(e){let t=this._events;if(t===void 0)return 0;let n=t[e];return n===void 0?0:typeof n==`function`?1:n.length}eventNames(){return(this._eventsCount??0)>0?Reflect.ownKeys(this._events):[]}static once(e,t,n){return new Promise((r,i)=>{let a=n?.signal;if(a?.aborted){i(createAbortError$1(a));return}if(typeof e.addEventListener==`function`){let n=e,handler=(...e)=>{a&&a.removeEventListener(`abort`,abortHandler),r(e)},errorHandler=e=>{a&&a.removeEventListener(`abort`,abortHandler),n.removeEventListener(`error`,errorHandler),i(e)},abortHandler=()=>{n.removeEventListener(t,handler),n.removeEventListener(`error`,errorHandler),i(createAbortError$1(a))};n.addEventListener(t,handler,{once:!0}),t!==`error`&&n.addEventListener(`error`,errorHandler,{once:!0}),a&&a.addEventListener(`abort`,abortHandler,{once:!0});return}let o=e,eventHandler=(...e)=>{a&&a.removeEventListener(`abort`,abortHandler),errorHandler!==void 0&&o.removeListener(`error`,errorHandler),r(e)},errorHandler;t!==`error`&&(errorHandler=e=>{o.removeListener(t,eventHandler),a&&a.removeEventListener(`abort`,abortHandler),i(e)},o.once(`error`,errorHandler)),o.once(t,eventHandler);let abortHandler=()=>{o.removeListener(t,eventHandler),errorHandler&&o.removeListener(`error`,errorHandler),i(createAbortError$1(a))};a&&a.addEventListener(`abort`,abortHandler,{once:!0})})}static on(e,t,n){let r=n?.signal;if(r?.aborted)throw createAbortError$1(r);let i=n?.highWaterMark??2**53-1,a=n?.lowWaterMark??1;validateNumber(i,`highWaterMark`),validateNumber(a,`lowWaterMark`);let o=[],s=[],c=null,l=!1,u=!1,eventHandler=(...t)=>{if(s.length>0){let{resolve:e}=s.shift();e({value:t,done:!1})}else o.push(t),o.length>=i&&!u&&(u=!0,typeof e.pause==`function`&&e.pause())},errorHandler=e=>{if(c=e,s.length>0){let{reject:t}=s.shift();t(e)}d.return()},abortHandler=()=>{errorHandler(createAbortError$1(r))};e.on(t,eventHandler),t!==`error`&&e.on(`error`,errorHandler),r&&r.addEventListener(`abort`,abortHandler,{once:!0});let cleanup=()=>{e.removeListener(t,eventHandler),e.removeListener(`error`,errorHandler),r&&r.removeEventListener(`abort`,abortHandler),l=!0;for(let{resolve:e}of s)e({value:void 0,done:!0});s.length=0,o.length=0},d={next(){if(o.length>0){let t=o.shift();return u&&o.length<a&&(u=!1,typeof e.resume==`function`&&e.resume()),Promise.resolve({value:t,done:!1})}if(c){let e=Promise.reject(c);return c=null,e}return l?Promise.resolve({value:void 0,done:!0}):new Promise((e,t)=>{s.push({resolve:e,reject:t})})},return(){return cleanup(),Promise.resolve({value:void 0,done:!0})},throw(e){return l||(c=e,cleanup()),Promise.reject(e)},[Symbol.asyncIterator](){return this}};return d}static listenerCount(e,t){return e.listenerCount(t)}static getEventListeners(e,t){return typeof e.listeners==`function`?e.listeners(t):[]}static setMaxListeners(e,...t){if(validateNumber(e,`n`),e<0)throw RangeError(`The value of "n" is out of range.`);if(t.length===0)EventEmitter.defaultMaxListeners=e;else for(let n of t)typeof n.setMaxListeners==`function`&&n.setMaxListeners(e)}static getMaxListeners(e){return typeof e.getMaxListeners==`function`?e.getMaxListeners():EventEmitter.defaultMaxListeners}static addAbortListener(e,t){e.aborted&&Promise.resolve().then(()=>t());let handler=()=>t();return e.addEventListener(`abort`,handler,{once:!0}),{[Symbol.dispose](){e.removeEventListener(`abort`,handler)}}}};It.EventEmitter=It;for(let e of[`setMaxListeners`,`getMaxListeners`,`emit`,`addListener`,`on`,`prependListener`,`once`,`prependOnceListener`,`removeListener`,`off`,`removeAllListeners`,`listeners`,`rawListeners`,`listenerCount`,`eventNames`]){let t=It.prototype[e];typeof t==`function`&&Object.defineProperty(It.prototype,e,{enumerable:!0,configurable:!0,writable:!0,value:t})}Object.defineProperty(It.prototype,"_events",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(It.prototype,"_eventsCount",{enumerable:!0,configurable:!0,writable:!0,value:0}),Object.defineProperty(It.prototype,"_maxListeners",{enumerable:!0,configurable:!0,writable:!0,value:void 0});function unwrapListeners(e){let t=Array.from({length:e.length});for(let n=0;n<t.length;++n)t[n]=e[n].listener??e[n];return t}function createAbortError$1(e){let t=Error(`The operation was aborted`);return t.name=`AbortError`,t.code=`ABORT_ERR`,e?.reason&&(t.cause=e.reason),t}__name(createAbortError$1,`createAbortError`);const Lt=makeCallable(It);Lt.EventEmitter=Lt,Lt.captureRejectionSymbol,Lt.errorMonitor,Lt.defaultMaxListeners,Lt.setMaxListeners,Lt.getMaxListeners,Lt.once,Lt.on,Lt.getEventListeners,Lt.listenerCount,Lt.addAbortListener;function normalizeAndValidateEncoding(e){return e&&checkEncoding(e),normalizeEncoding(e)}function utf8DecodeMaximalSubpart(e,t,n){let r=``,i=t;for(;i<n;){let t=e[i];if(t<=127){r+=String.fromCharCode(t),i++;continue}if(t>=194&&t<=223){i+1<n&&e[i+1]>=128&&e[i+1]<=191?(r+=String.fromCharCode((t&31)<<6|e[i+1]&63),i+=2):(r+=`�`,i++);continue}if(t>=224&&t<=239){let a,o;if(t===224?(a=160,o=191):t===237?(a=128,o=159):(a=128,o=191),i+1>=n){r+=`�`,i++;continue}let s=e[i+1];if(s<a||s>o){r+=`�`,i++;continue}if(i+2>=n){r+=`�`,i+=2;continue}let c=e[i+2];if(c<128||c>191){r+=`�`,i+=2;continue}let l=(t&15)<<12|(s&63)<<6|c&63;r+=String.fromCharCode(l),i+=3;continue}if(t>=240&&t<=244){let a,o;if(t===240?(a=144,o=191):t===244?(a=128,o=143):(a=128,o=191),i+1>=n){r+=`�`,i++;continue}let s=e[i+1];if(s<a||s>o){r+=`�`,i++;continue}if(i+2>=n){r+=`�`,i+=2;continue}let c=e[i+2];if(c<128||c>191){r+=`�`,i+=2;continue}if(i+3>=n){r+=`�`,i+=3;continue}let l=e[i+3];if(l<128||l>191){r+=`�`,i+=3;continue}let u=(t&7)<<18|(s&63)<<12|(c&63)<<6|l&63;r+=String.fromCharCode(55296+(u-65536>>10),56320+(u-65536&1023)),i+=4;continue}r+=`�`,i++}return r}function utf8CharLength(e){return e&128?e>=194&&e<=223?2:e>=224&&e<=239?3:e>=240&&e<=244?4:0:1}function isValidContinuation(e,t,n,r){if(n===1){if(t===3)return e===224?r>=160&&r<=191:e===237?r>=128&&r<=159:r>=128&&r<=191;if(t===4)return e===240?r>=144&&r<=191:e===244?r>=128&&r<=143:r>=128&&r<=191}return r>=128&&r<=191}const Rt=function StringDecoder(e){this.encoding=normalizeAndValidateEncoding(e),this._lastNeed=0,this._lastTotal=0,this._lastLeadByte=0,this.encoding===`utf8`||this.encoding===`utf16le`?this._lastChar=new Uint8Array(4):this.encoding===`base64`?this._lastChar=new Uint8Array(3):this._lastChar=new Uint8Array};Rt.prototype.write=function write(e){if(e.length===0)return``;switch(this.encoding){case`utf8`:return writeUtf8(this,e);case`utf16le`:return writeUtf16le(this,e);case`base64`:return writeBase64(this,e);case`ascii`:return decodeAscii(e);case`latin1`:return decodeLatin1(e);case`hex`:return decodeHex(e);default:return decodeAscii(e)}},Rt.prototype.end=function end(e){let t=``;if(e&&e.length>0&&(t=this.write(e)),this.encoding===`utf8`&&this._lastNeed>0)t+=`�`,this._lastNeed=0,this._lastTotal=0;else if(this.encoding===`utf16le`&&this._lastNeed>0){let e=this._lastTotal-this._lastNeed;for(let n=0;n+1<e;n+=2)t+=String.fromCharCode(this._lastChar[n]|this._lastChar[n+1]<<8);this._lastNeed=0,this._lastTotal=0}else if(this.encoding===`base64`&&this._lastNeed>0){let e=this._lastChar.subarray(0,this._lastTotal-this._lastNeed);t+=base64Encode(e),this._lastNeed=0,this._lastTotal=0}return t};function writeUtf8(e,t){let n=0,r=``;if(e._lastNeed>0){for(;n<t.length&&e._lastNeed>0;){let i=t[n],a=e._lastTotal-e._lastNeed;if(isValidContinuation(e._lastLeadByte,e._lastTotal,a,i))e._lastChar[a]=i,e._lastNeed--,n++;else{r+=`�`,e._lastNeed=0,e._lastTotal=0,e._lastLeadByte=0;break}}if(e._lastNeed===0&&e._lastTotal>0&&(r+=utf8DecodeMaximalSubpart(e._lastChar,0,e._lastTotal),e._lastTotal=0,e._lastLeadByte=0),e._lastNeed>0)return r}let i=t.length;for(let r=0;r<Math.min(4,t.length-n);r++){let a=t.length-1-r;if(a<n)break;let o=t[a];if((o&192)!=128){let n=utf8CharLength(o);if(n>0&&o>=128){let r=t.length-a;if(r<n){let s=!0;for(let e=1;e<r;e++)if(!isValidContinuation(o,n,e,t[a+e])){s=!1;break}if(s){i=a;for(let n=0;n<r;n++)e._lastChar[n]=t[a+n];e._lastNeed=n-r,e._lastTotal=n,e._lastLeadByte=o}}}break}}return i>n&&(r+=utf8DecodeMaximalSubpart(t,n,i)),r}function writeUtf16le(e,t){let n=``,r=0;if(e._lastNeed>0){let i=e._lastTotal-e._lastNeed,a=Math.min(e._lastNeed,t.length);for(let n=0;n<a;n++)e._lastChar[i+n]=t[n];if(e._lastNeed-=a,r=a,e._lastNeed>0)return``;let o=e._lastTotal,s=0;for(;s+1<o;){let i=e._lastChar[s]|e._lastChar[s+1]<<8;if(s+=2,i>=55296&&i<=56319){if(s+1<o){let t=e._lastChar[s]|e._lastChar[s+1]<<8;if(t>=56320&&t<=57343){n+=String.fromCharCode(i,t),s+=2;continue}}if(r+1<t.length){let e=t[r]|t[r+1]<<8;if(e>=56320&&e<=57343){n+=String.fromCharCode(i,e),r+=2;continue}}else if(r>=t.length)return e._lastChar[0]=e._lastChar[s-2],e._lastChar[1]=e._lastChar[s-1],e._lastNeed=2,e._lastTotal=4,n}n+=String.fromCharCode(i)}e._lastTotal=0}for(;r+1<t.length;){let i=t[r]|t[r+1]<<8;if(r+=2,i>=55296&&i<=56319)if(r+1<t.length){let e=t[r]|t[r+1]<<8;if(e>=56320&&e<=57343){n+=String.fromCharCode(i,e),r+=2;continue}}else if(r<t.length)return n+=String.fromCharCode(i),e._lastChar[0]=t[r],e._lastNeed=1,e._lastTotal=2,n;else return e._lastChar[0]=t[r-2],e._lastChar[1]=t[r-1],e._lastNeed=2,e._lastTotal=4,n;n+=String.fromCharCode(i)}return r<t.length&&(e._lastChar[0]=t[r],e._lastNeed=1,e._lastTotal=2),n}function writeBase64(e,t){let n=0;if(e._lastNeed>0){let r=Math.min(e._lastNeed,t.length);for(let n=0;n<r;n++)e._lastChar[e._lastTotal-e._lastNeed+n]=t[n],e._lastNeed--;if(n=r,e._lastNeed>0)return``}let r=t.length-n,i=r-r%3,a=``;e._lastTotal>0&&e._lastNeed===0&&(a+=base64Encode(e._lastChar.subarray(0,e._lastTotal)),e._lastTotal=0),i>0&&(a+=base64Encode(t.subarray(n,n+i)));let o=r-i;if(o>0){for(let r=0;r<o;r++)e._lastChar[r]=t[n+i+r];e._lastNeed=3-o,e._lastTotal=3}return a}function decodeAscii(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]&127);return t}function decodeLatin1(e){let t=``;for(let n=0;n<e.length;n++)t+=String.fromCharCode(e[n]);return t}function decodeHex(e){let t=``;for(let n=0;n<e.length;n++)t+=e[n].toString(16).padStart(2,`0`);return t}const zt=new TextEncoder;var ProcessWriteStream=class extends Lt{fd;writable=!0;_outGio=null;constructor(e){super(),this.fd=e;let t=getGioNamespace();if(t){let e=t.UnixOutputStream??t.OutputStream;if(e)try{this._outGio=e.new(this.fd,!1)}catch{}}}write(e){if(this._outGio)try{let t=typeof e==`string`?zt.encode(e):e;return this._outGio.write_all(t,null),!0}catch{}return this.fd===2?A.error(e):A.log(e),!0}get isTTY(){if(Nt)return Nt.Terminal.is_tty(this.fd);try{let e=getGjsGlobal().imports?.gi?.GLib;if(e)return!!e.log_writer_supports_color(this.fd)}catch{}return!1}get columns(){if(Nt){let[e,,t]=Nt.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=getGjsGlobal().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`COLUMNS`)??`0`,10);if(t>0)return t}}catch{}return 80}end(){}destroy(){}get rows(){if(Nt){let[e,t]=Nt.Terminal.get_size(this.fd);if(e&&t>0)return t}try{let e=getGjsGlobal().imports?.gi?.GLib;if(e){let t=parseInt(e.getenv(`LINES`)??`0`,10);if(t>0)return t}}catch{}return 24}},ProcessReadStream=class extends Lt{fd;isRaw=!1;_gio=null;_stdinGio=null;_reading=!1;_flowing=!1;_sttyCleanupRegistered=!1;_mainLoopHeld=!1;_pendingRead=!1;_decoder=null;constructor(e){super(),this.fd=e,this._gio=getGioNamespace()}get isTTY(){return Nt?Nt.Terminal.is_tty(this.fd):!1}setRawMode(e){return Nt&&Nt.Terminal.set_raw_mode(this.fd,e)?(this.isRaw=e,this):(this._setRawModeViaStty(e),this.isRaw=e,this)}_setRawModeViaStty(e){try{let t=globalThis.imports?.gi,n=t?.Gio??t?.Gio;if(!n)return;let r=n.SubprocessFlags?.STDIN_INHERIT??2,i=e?[`stty`,`-icanon`,`-echo`,`-icrnl`,`-isig`,`min`,`1`,`time`,`0`]:[`stty`,`icanon`,`echo`,`icrnl`,`isig`];if(new n.SubprocessLauncher({flags:r}).spawnv(i).wait(null),e&&!this._sttyCleanupRegistered){this._sttyCleanupRegistered=!0;let e=globalThis.process;e?.once&&typeof e.once==`function`&&e.once(`exit`,()=>this._setRawModeViaStty(!1))}}catch{}}setEncoding(e){return this._decoder=new Rt(e),this}_pushData(e){if(this._decoder){let t=this._decoder.write(e);t.length>0&&this.emit(`data`,t)}else this.emit(`data`,e)}on(e,t){let n=e===`data`&&this.listenerCount(`data`)===0;return super.on(e,t),n&&e===`data`&&this.resume(),this}addListener(e,t){return this.on(e,t)}once(e,t){return super.once(e,t),this}removeListener(e,t){return super.removeListener(e,t),e===`data`&&this.listenerCount(`data`)===0&&this.pause(),this}off(e,t){return this.removeListener(e,t)}removeAllListeners(e){let t=e===void 0||e===`data`?this.listenerCount(`data`)>0:!1;return super.removeAllListeners(e),t&&this.listenerCount(`data`)===0&&this.pause(),this}resume(){return this._flowing=!0,this._gio&&this.fd===0&&!this._reading&&this._startReading(),this}pause(){if(this._flowing=!1,this._reading=!1,this._mainLoopHeld){this._mainLoopHeld=!1;let e=globalThis.imports?.gi,t=e?.GLib??e?.GLib;t?.idle_add?t.idle_add(300,()=>(this._mainLoopHeld||quitMainLoop(),!1)):quitMainLoop()}return this}read(){return null}_startReading(){if(!this._gio||this._reading)return;if(this._pendingRead){this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,ensureMainLoop());return}if(this._reading=!0,this._mainLoopHeld||(this._mainLoopHeld=!0,ensureMainLoop()),!this._stdinGio){let e=this._gio.UnixInputStream??this._gio.InputStream;if(!e){this._reading=!1;return}try{this._stdinGio=e.new(this.fd,!1)}catch{this._reading=!1;return}}let loop=()=>{if(!this._reading){this._pendingRead=!1;return}this._pendingRead=!0,this._stdinGio.read_bytes_async(4096,0,null,(e,t)=>{this._pendingRead=!1;try{let n=e.read_bytes_finish(t)?.get_data?.()??null;if(n&&n.byteLength>0)this._pushData(Buffer.from(n));else if(n!==null&&n.byteLength===0){if(this._reading=!1,this._decoder){let e=this._decoder.end();e.length>0&&this.emit(`data`,e)}this.emit(`end`);return}}catch{this._reading=!1;return}this._reading&&loop()})};loop()}};const Bt=Date.now();function defineLazy(e,t,n){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){let r=n();return Object.defineProperty(e,t,{value:r,configurable:!0,enumerable:!0,writable:!1}),r}})}var Process=class extends Lt{platform;arch;env;argv;argv0;execPath;pid;ppid;version;versions;title;execArgv;config;exitCode;constructor(){super(),defineLazy(this,`platform`,detectPlatform),defineLazy(this,`arch`,detectArch),this.env=getEnvProxy(),this.argv=getArgv(),this.argv0=this.argv[0]||`gjs`,this.execPath=getExecPath(),this.execArgv=globalThis.process?.execArgv??[],this.config=globalThis.process?.config??{target_defaults:{},variables:{}},this.pid=getPid(),this.ppid=detectPpid();let e=detectVersionInfo();this.version=e.version,this.versions=e.versions,this.title=e.title}cwd(){return getCwd()}chdir(e){chdir(e)}kill(e,t){return killPid(e,t)}exit(e){return this.exitCode=e??this.exitCode??0,this.emit(`exit`,this.exitCode),exitProcess(this.exitCode)}nextTick(e,...t){typeof queueMicrotask==`function`?queueMicrotask(()=>e(...t)):Promise.resolve().then(()=>e(...t))}hrtime(e){return hrtime(e)}uptime(){return(Date.now()-Bt)/1e3}memoryUsage(){return memoryUsage()}cpuUsage(e){return cpuUsage(e)}stdout=new ProcessWriteStream(1);stderr=new ProcessWriteStream(2);stdin=new ProcessReadStream(0);abort(){this.exit(1)}umask(e){let t=readUmask();return e!==void 0&&!this._umaskWarned&&(this._umaskWarned=!0,this.emitWarning(`process.umask(0${e.toString(8)}) cannot change the file-creation mask under GJS — there is no umask(2) binding, so the mask is UNCHANGED. Pass an explicit \`mode\` to open/mkdir/writeFile instead; the kernel applies it atomically at creation.`,`UnsupportedWarning`)),t}_umaskWarned=!1;emitWarning(e,t){A.warn(typeof e==`string`?`(${t||`Warning`}): ${e}`:e.message)}};Process.prototype.hrtime.bigint=function(){return hrtimeBigint()};const Vt=new Process;if(Nt)try{let e=new Nt.ResizeWatcher;e.connect(`resized`,(e,t,n)=>{Vt.stdout.emit(`resize`),Vt.stderr.emit(`resize`)}),e.start()}catch{}Vt.platform,Vt.arch,Vt.env,Vt.argv,Vt.argv0,Vt.execPath,Vt.pid,Vt.ppid,Vt.version,Vt.versions,Vt.cwd.bind(Vt),Vt.chdir.bind(Vt),Vt.exit.bind(Vt),Vt.nextTick.bind(Vt),Object.assign(Vt.hrtime.bind(Vt),{bigint:hrtimeBigint}),Vt.uptime.bind(Vt),Vt.memoryUsage.bind(Vt),Vt.cpuUsage.bind(Vt),Vt.kill.bind(Vt),Vt.abort.bind(Vt),Vt.umask.bind(Vt),Vt.emitWarning.bind(Vt),Vt.execArgv,Vt.config,Vt.stdout,Vt.stderr,Vt.stdin,typeof Promise.withResolvers!=`function`&&(Promise.withResolvers=function(){let e,t;return{promise:new Promise((n,r)=>{e=n,t=r}),resolve:e,reject:t}}),initErrorV8Methods(Error),`global`in globalThis||Object.defineProperty(globalThis,"global",{value:globalThis,writable:!1,enumerable:!1,configurable:!0}),Object.defineProperty(globalThis,"process",{value:Vt,enumerable:!1,writable:!0,configurable:!0}),typeof globalThis.structuredClone!=`function`&&Object.defineProperty(globalThis,"structuredClone",{value:structuredClone$1,enumerable:!0,writable:!0,configurable:!0});function getGLib(){return globalThis.imports?.gi?.GLib}const Ht=getGLib()!==void 0;var GjsifyTimeout=class{_id=null;_refed=!0;_callback;_delay;_args;_repeat;constructor(e,t,n,r){this._callback=e,this._delay=t,this._args=n,this._repeat=r,this._schedule()}_schedule(){let e=getGLib();if(!e)return;let t=e.timeout_add.bind(e);this._id=t(e.PRIORITY_DEFAULT,this._delay,()=>{try{this._callback.apply(globalThis,this._args)}catch(e){setTimeout(()=>{throw e},0)}return this._repeat?e.SOURCE_CONTINUE:(this._id=null,e.SOURCE_REMOVE)})}ref(){return this._refed=!0,this}unref(){return this._refed=!1,this}hasRef(){return this._refed}refresh(){return this._cancel(),this._schedule(),this}_cancel(){this._id!==null&&(getGLib()?.Source.remove(this._id),this._id=null)}[Symbol.toPrimitive](){return this._id}[Symbol.dispose](){this._cancel()}};function removeById(e){e instanceof GjsifyTimeout?e._cancel():typeof e==`number`&&getGLib()?.Source.remove(e)}if(Ht){let setT=(e,t=0,...n)=>new GjsifyTimeout(e,Math.max(0,t|0),n,!1),setI=(e,t=0,...n)=>new GjsifyTimeout(e,Math.max(0,t|0),n,!0),e=globalThis;e.setTimeout=setT,e.clearTimeout=removeById,e.setInterval=setI,e.clearInterval=removeById}function setImmediate(e,...t){return setTimeout(e,0,...t)}function clearImmediate(e){clearTimeout(e)}`setImmediate`in globalThis||Object.defineProperty(globalThis,"setImmediate",{value:setImmediate,enumerable:!0,writable:!0,configurable:!0}),`clearImmediate`in globalThis||Object.defineProperty(globalThis,"clearImmediate",{value:clearImmediate,enumerable:!0,writable:!0,configurable:!0});const Ut=_t.UriFlags.HAS_PASSWORD|_t.UriFlags.ENCODED|_t.UriFlags.SCHEME_NORMALIZE;var Wt=class URLSearchParams{_entries=[];constructor(e){if(e)if(typeof e==`string`){let t=e.startsWith(`?`)?e.slice(1):e;if(t)for(let e of t.split(`&`)){let t=e.indexOf(`=`);t===-1?this._entries.push([decodeComponent(e),``]):this._entries.push([decodeComponent(e.slice(0,t)),decodeComponent(e.slice(t+1))])}}else if(Array.isArray(e))for(let[t,n]of e)this._entries.push([String(t),String(n)]);else if(e instanceof URLSearchParams)this._entries=e._entries.map(([e,t])=>[e,t]);else for(let t of Object.keys(e))this._entries.push([t,String(e[t])])}get(e){for(let[t,n]of this._entries)if(t===e)return n;return null}getAll(e){return this._entries.filter(([t])=>t===e).map(([,e])=>e)}set(e,t){let n=!1;if(this._entries=this._entries.filter(([t])=>t===e?n?!1:(n=!0,!0):!0),n){for(let n=0;n<this._entries.length;n++)if(this._entries[n][0]===e){this._entries[n][1]=t;break}}else this._entries.push([e,t])}has(e){return this._entries.some(([t])=>t===e)}delete(e){this._entries=this._entries.filter(([t])=>t!==e)}append(e,t){this._entries.push([e,t])}sort(){this._entries.sort((e,t)=>e[0]<t[0]?-1:+(e[0]>t[0]))}toString(){return this._entries.map(([e,t])=>encodeComponent(e)+`=`+encodeComponent(t)).join(`&`)}forEach(e){for(let[t,n]of this._entries)e(n,t,this)}*entries(){yield*this._entries}*keys(){for(let[e]of this._entries)yield e}*values(){for(let[,e]of this._entries)yield e}[Symbol.iterator](){return this.entries()}get size(){return this._entries.length}};function decodeComponent(e){try{return decodeURIComponent(e.replace(/\+/g,` `))}catch{return e}}function encodeComponent(e){return encodeURIComponent(e).replace(/%20/g,`+`)}var Gt=class URL{#e;#t;constructor(e,t){let n=e instanceof URL?e.href:String(e);try{if(t!==void 0){let e=t instanceof URL?t.href:String(t),r=_t.Uri.parse(e,Ut);this.#e=r.parse_relative(n,Ut)}else this.#e=_t.Uri.parse(n,Ut)}catch{throw TypeError(`Invalid URL: ${n}`)}if(!this.#e)throw TypeError(`Invalid URL: ${n}`);this.#t=new Wt(this.#e.get_query()||``)}get protocol(){return this.#e.get_scheme()+`:`}get hostname(){return(this.#e.get_host()||``).toLowerCase()}get port(){let e=this.#e.get_port();if(e===-1)return``;let t=this.#e.get_scheme();return(t===`http`||t===`ws`)&&e===80||(t===`https`||t===`wss`)&&e===443||t===`ftp`&&e===21?``:String(e)}get host(){let e=this.hostname,t=this.port;return t?`${e}:${t}`:e}get pathname(){return this.#e.get_path()||`/`}get search(){let e=this.#e.get_query();return e?`?`+e:``}get hash(){let e=this.#e.get_fragment();return e?`#`+e:``}get origin(){let e=this.protocol;return e===`http:`||e===`https:`||e===`ftp:`?`${e}//${this.host}`:`null`}get username(){return this.#e.get_user()||``}get password(){return this.#e.get_password()||``}get href(){let e=this.protocol,t=this.#e.get_scheme();(t===`http`||t===`https`||t===`ftp`||t===`file`||t===`ws`||t===`wss`||this.hostname)&&(e+=`//`);let n=this.username,r=this.password;n&&(e+=n,r&&(e+=`:`+r),e+=`@`),e+=this.hostname,this.port&&(e+=`:`+this.port);let i=this.pathname;return e+=i,e+=this.search,e+=this.hash,e}get searchParams(){return this.#t}toString(){return this.href}toJSON(){return this.href}static _objectURLPaths=new Map;static _objectURLCounter=0;static createObjectURL(e){let t=e?._tmpPath;if(typeof t==`string`&&t.length>0){let e=`file://${t}`;return URL._objectURLPaths.set(e,t),e}return`file:///dev/null`}static revokeObjectURL(e){let t=URL._objectURLPaths.get(e);t&&(_t.unlink(t),URL._objectURLPaths.delete(e))}};typeof globalThis.URL!=`function`&&Object.defineProperty(globalThis,"URL",{value:Gt,enumerable:!1,writable:!0,configurable:!0}),typeof globalThis.URLSearchParams!=`function`&&Object.defineProperty(globalThis,"URLSearchParams",{value:Wt,enumerable:!1,writable:!0,configurable:!0});let Kt;if(globalThis.performance)Kt=globalThis.performance;else{let e,_now;try{let t=globalThis.imports?.gi?.GLib;if(!t)throw Error(`GJS imports.gi.GLib not available`);e=t.get_monotonic_time(),_now=()=>(t.get_monotonic_time()-e)/1e3}catch{let t=Date.now();e=0,_now=()=>Date.now()-t}let t=[],n=Date.now()-_now();Kt={timeOrigin:n,now:_now,mark(e){let n={name:e,entryType:`mark`,startTime:_now(),duration:0};return t.push(n),n},measure(e,n,r){let i=0,a=_now();if(n){let e=t.find(e=>e.entryType===`mark`&&e.name===n);e&&(i=e.startTime)}if(r){let e=t.find(e=>e.entryType===`mark`&&e.name===r);e&&(a=e.startTime)}let o={name:e,entryType:`measure`,startTime:i,duration:a-i};return t.push(o),o},getEntries(){return[...t]},getEntriesByName(e){return t.filter(t=>t.name===e)},getEntriesByType(e){return t.filter(t=>t.entryType===e)},clearMarks(e){for(let n=t.length-1;n>=0;n--)t[n].entryType===`mark`&&(!e||t[n].name===e)&&t.splice(n,1)},clearMeasures(e){for(let n=t.length-1;n>=0;n--)t[n].entryType===`measure`&&(!e||t[n].name===e)&&t.splice(n,1)},clearResourceTimings(){},setResourceTimingBufferSize(){},toJSON(){return{timeOrigin:n}}}}var PerformanceObserverStub=class{_callback;constructor(e){this._callback=e}observe(e){}disconnect(){}takeRecords(){return[]}};const qt=globalThis,Jt=qt.PerformanceObserver||PerformanceObserverStub;qt.PerformanceEntry,qt.PerformanceObserverEntryList,qt.PerformanceMark,qt.PerformanceMeasure;const Yt=globalThis;globalThis.performance===void 0&&(Yt.performance=Kt),typeof Yt.PerformanceObserver!=`function`&&(Yt.PerformanceObserver=Jt);var WebGLUniformLocation=class{constructor(e,t,n){this._linkCount=0,this._array=null,this._=e,this._program=t,this._linkCount=t._linkCount,this._activeInfo=n,this._array=null}};function checkObject(e){return typeof e==`object`||e===void 0}function checkUniform(e,t){return t instanceof WebGLUniformLocation&&t._program===e&&t._linkCount===e._linkCount}function isTypedArray$1(e){return e instanceof Uint8Array||e instanceof Uint8ClampedArray||e instanceof Int8Array||e instanceof Uint16Array||e instanceof Int16Array||e instanceof Uint32Array||e instanceof Int32Array||e instanceof Float32Array||e instanceof Float64Array}__name(isTypedArray$1,`isTypedArray`);function isValidString(e){let t=e.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm,``);return!/["$`@\\'\0]/.test(t)}function vertexCount(e,t,n){switch(t){case e.TRIANGLES:return n-n%3;case e.LINES:return n-n%2;case e.LINE_LOOP:case e.POINTS:return n;case e.TRIANGLE_FAN:case e.LINE_STRIP:return n<2?0:n;case e.TRIANGLE_STRIP:return n<3?0:n;default:return-1}}function typeSize(e,t){switch(t){case e.UNSIGNED_BYTE:case e.BYTE:return 1;case e.UNSIGNED_SHORT:case e.SHORT:return 2;case e.UNSIGNED_INT:case e.INT:case e.FLOAT:return 4}return 0}function uniformTypeSize(e,t){switch(t){case e.BOOL_VEC4:case e.INT_VEC4:case e.FLOAT_VEC4:return 4;case e.BOOL_VEC3:case e.INT_VEC3:case e.FLOAT_VEC3:return 3;case e.BOOL_VEC2:case e.INT_VEC2:case e.FLOAT_VEC2:return 2;case e.BOOL:case e.INT:case e.FLOAT:case e.SAMPLER_2D:case e.SAMPLER_CUBE:return 1;default:return 0}}const listToArray=e=>{let t=[];for(let n of e.values())t.push(n);return t};function arrayToUint8Array(e){if(isTypedArray$1(e))return new Uint8Array(e.buffer).subarray(e.byteOffset,e.byteLength+e.byteOffset);if(Array.isArray(e)||e instanceof ArrayBuffer)return new Uint8Array(e);if(typeof e.values==`function`)return new Uint8Array(listToArray(e));throw Error(`Can't unpack typed array!`)}function Uint8ArrayToVariant(e){return new _t.Variant(`ay`,e)}const extractImageData=e=>{let t=e.width,n=e.height;if(typeof e==`object`&&t!==void 0&&n!==void 0){if(e.data!==void 0)return e;let r=null;if(typeof e.getContext==`function`)r=e.getContext(`2d`);else if(typeof e.isPixbuf==`function`&&e.isPixbuf())return e.getImageData();else if(e.src!==void 0&&typeof document==`object`&&typeof document.createElement==`function`){let i=document.createElement(`canvas`);typeof i==`object`&&typeof i.getContext==`function`&&(i.width=t,i.height=n,r=i.getContext(`2d`),r!==null&&r.drawImage(e,0,0))}if(r!==null)return r.getImageData(0,0,t,n)}return null};function formatSize(e,t){switch(t){case e.ALPHA:case e.LUMINANCE:return 1;case e.LUMINANCE_ALPHA:return 2;case e.RGB:return 3;case e.RGBA:return 4}return 0}function convertPixels(e){if(typeof e==`object`&&e){if(e instanceof ArrayBuffer)return new Uint8Array(e);if(e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint8ClampedArray||e instanceof Float32Array)return arrayToUint8Array(e);if(e instanceof Buffer)return new Uint8Array(e)}return null}function checkFormat(e,t){return t===e.ALPHA||t===e.LUMINANCE_ALPHA||t===e.LUMINANCE||t===e.RGB||t===e.RGBA}function validCubeTarget(e,t){return t===e.TEXTURE_CUBE_MAP_POSITIVE_X||t===e.TEXTURE_CUBE_MAP_NEGATIVE_X||t===e.TEXTURE_CUBE_MAP_POSITIVE_Y||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Y||t===e.TEXTURE_CUBE_MAP_POSITIVE_Z||t===e.TEXTURE_CUBE_MAP_NEGATIVE_Z}function flag(e,t,n){return!e||typeof e!=`object`||!(t in e)?n:!!e[t]}function premultiplyAlpha(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n+=4){let r=e[n+3]/255;t[n]=Math.round(e[n]*r),t[n+1]=Math.round(e[n+1]*r),t[n+2]=Math.round(e[n+2]*r),t[n+3]=e[n+3]}return t}var Linkable=class{constructor(e){this._=0,this._references=[],this._refCount=0,this._pendingDelete=!1,this._binding=0,this._=e,this._references=[],this._refCount=0,this._pendingDelete=!1,this._binding=0}_link(e){return this._references.push(e),e._refCount+=1,!0}_unlink(e){let t=this._references.indexOf(e);if(t<0)return!1;for(;t>=0;)this._references[t]=this._references[this._references.length-1],this._references.pop(),--e._refCount,e._checkDelete(),t=this._references.indexOf(e);return!0}_linked(e){return this._references.indexOf(e)>=0}_checkDelete(){if(this._refCount<=0&&this._pendingDelete&&this._!==0){for(;this._references.length>0;)this._unlink(this._references[0]);this._performDelete(),this._=0}}_performDelete(){}},WebGLBuffer=class extends Linkable{constructor(e,t){super(e),this._size=0,this._elements=new Uint8Array,this._ctx=t}_performDelete(){let e=this._ctx;delete e._buffers[this._|0],e._gl.deleteBuffer(this._)}};const Xt={bindBuffer(e=0,t){if(!checkObject(t))throw TypeError(`bindBuffer(GLenum, WebGLBuffer)`);if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}if(!t)t=null,this._gl.bindBuffer(e,0);else if(t._pendingDelete)return;else if(this._checkWrapper(t,WebGLBuffer)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e|0,this._gl.bindBuffer(e,t._|0)}else return;e===this.ARRAY_BUFFER?this._vertexGlobalState.setArrayBuffer(t):this._vertexObjectState.setElementArrayBuffer(t)},bufferData(e=0,t,n=0){let r=0,i=null;if(typeof t==`number`?r=t:typeof t==`object`&&(i=t),n!==this.STREAM_DRAW&&n!==this.STATIC_DRAW&&n!==this.DYNAMIC_DRAW){this.setError(this.INVALID_ENUM);return}if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}let a=this._getActiveBuffer(e);if(!a){this.setError(this.INVALID_OPERATION);return}if(i){let t=null;if(isTypedArray$1(i)||i instanceof DataView||i instanceof ArrayBuffer)t=arrayToUint8Array(i);else{this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.bufferData(e,Uint8ArrayToVariant(t),n);let r=this.getError();if(this._restoreError(r),r!==this.NO_ERROR)return;a._size=t.length,e===this.ELEMENT_ARRAY_BUFFER&&(a._elements=new Uint8Array(t))}else if(typeof t==`number`){if(r<0){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.bufferDataSizeOnly(e,r,n);let t=this.getError();if(this._restoreError(t),t!==this.NO_ERROR)return;a._size=r,e===this.ELEMENT_ARRAY_BUFFER&&(a._elements=new Uint8Array(r))}else this.setError(this.INVALID_VALUE)},bufferSubData(e=0,t=0,n){if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER){this.setError(this.INVALID_ENUM);return}if(typeof n!=`object`||!n)throw TypeError(`bufferSubData: data must be a BufferSource`);let r=this._getActiveBuffer(e);if(!r){this.setError(this.INVALID_OPERATION);return}if(t<0||t>=r._size){this.setError(this.INVALID_VALUE);return}let i=null;if(isTypedArray$1(n)||n instanceof DataView||n instanceof ArrayBuffer)i=arrayToUint8Array(n);else{this.setError(this.INVALID_VALUE);return}if(t+i.length>r._size){this.setError(this.INVALID_VALUE);return}e===this.ELEMENT_ARRAY_BUFFER&&r._elements.set(i,t),this._gl.bufferSubData(e,t,Uint8ArrayToVariant(i))},createBuffer(){let e=this._gl.createBuffer();if(!e||e<=0)return null;let t=new WebGLBuffer(e,this);return this._buffers[e]=t,t},deleteBuffer(e){if(!checkObject(e)||e!==null&&!(e instanceof WebGLBuffer))throw TypeError(`deleteBuffer(WebGLBuffer)`);if(!(e instanceof WebGLBuffer&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._vertexGlobalState._arrayBufferBinding===e&&this.bindBuffer(this.ARRAY_BUFFER,null),this._vertexObjectState._elementArrayBufferBinding===e&&this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this._vertexObjectState===this._defaultVertexObjectState&&this._vertexObjectState.releaseArrayBuffer(e),e._pendingDelete=!0,e._checkDelete()},getBufferParameter(e=0,t=0){if(e!==this.ARRAY_BUFFER&&e!==this.ELEMENT_ARRAY_BUFFER)return this.setError(this.INVALID_ENUM),null;switch(t){case this.BUFFER_SIZE:case this.BUFFER_USAGE:return this._gl.getBufferParameteriv(e|0,t|0)[0];default:return this.setError(this.INVALID_ENUM),null}},_getActiveBuffer(e){return e===this.ARRAY_BUFFER?this._vertexGlobalState._arrayBufferBinding:e===this.ELEMENT_ARRAY_BUFFER?this._vertexObjectState._elementArrayBufferBinding:null}};function installBufferBindingMethods(e){Object.assign(e,Xt)}const Zt={drawArrays(e=0,t=0,n=0){if(t<0||n<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let r=vertexCount(this,e,n);if(r<0){this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk()||n===0)return;let i=t;n>0&&(i=n+t-1>>>0),this._checkVertexAttribState(i)&&this._gl.drawArrays(e,t,r)},drawElements(e=0,t=0,n=0,r=0){if(t<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=this._vertexObjectState._elementArrayBufferBinding;if(!i){this.setError(this.INVALID_OPERATION);return}let a=null,o=r;if(n===this.UNSIGNED_SHORT){if(o%2){this.setError(this.INVALID_OPERATION);return}o>>=1,a=new Uint16Array(i._elements.buffer)}else if(this._extensions.oes_element_index_uint&&n===this.UNSIGNED_INT){if(o%4){this.setError(this.INVALID_OPERATION);return}o>>=2,a=new Uint32Array(i._elements.buffer)}else if(n===this.UNSIGNED_BYTE)a=i._elements;else{this.setError(this.INVALID_ENUM);return}let s=t;switch(e){case this.TRIANGLES:t%3&&(s-=t%3);break;case this.LINES:t%2&&(s-=t%2);break;case this.POINTS:break;case this.LINE_LOOP:case this.LINE_STRIP:if(t<2){this.setError(this.INVALID_OPERATION);return}break;case this.TRIANGLE_FAN:case this.TRIANGLE_STRIP:if(t<3){this.setError(this.INVALID_OPERATION);return}break;default:this.setError(this.INVALID_ENUM);return}if(!this._framebufferOk())return;if(t===0){this._checkVertexAttribState(0);return}if(t+o>>>0>a.length){this.setError(this.INVALID_OPERATION);return}let c=-1;for(let e=o;e<o+t;++e)c=Math.max(c,a[e]);if(c<0){this._checkVertexAttribState(0);return}this._checkVertexAttribState(c)&&s>0&&this._gl.drawElements(e,s,n,r)},viewport(e,t,n,r){this._viewport[0]=e|0,this._viewport[1]=t|0,this._viewport[2]=n|0,this._viewport[3]=r|0,this._gl.viewport(e,t,n,r)},scissor(e,t,n,r){this._scissorBox[0]=e|0,this._scissorBox[1]=t|0,this._scissorBox[2]=n|0,this._scissorBox[3]=r|0,this._gl.scissor(e|0,t|0,n|0,r|0)},readPixels(e=0,t=0,n=0,r=0,i=0,a=0,o){if(!o)return;if(!(this._extensions.oes_texture_float&&a===this.FLOAT&&i===this.RGBA)){if(i===this.RGB||i===this.ALPHA||a!==this.UNSIGNED_BYTE){this.setError(this.INVALID_OPERATION);return}else if(i!==this.RGBA){this.setError(this.INVALID_ENUM);return}else if(n<0||r<0||!(o instanceof Uint8Array)){this.setError(this.INVALID_VALUE);return}}if(!this._framebufferOk()){A.error(`framebuffer is not okay!`);return}let s=n*4;s%this._packAlignment!==0&&(s+=this._packAlignment-s%this._packAlignment);let c=s*(r-1)+n*4;if(c<=0)return;if((o.length||o.byteLength||0)<c){this.setError(this.INVALID_VALUE);return}let l=this.drawingBufferWidth,u=this.drawingBufferHeight;this._activeFramebuffer&&(l=this._activeFramebuffer._width,u=this._activeFramebuffer._height);let d=arrayToUint8Array(o);if(e>=l||e+n<=0||t>=u||t+r<=0)for(let e=0;e<d.length;++e)d[e]=0;else if(e<0||e+n>l||t<0||t+r>u){for(let e=0;e<d.length;++e)d[e]=0;let o=e,c=n;e<0&&(c+=e,o=0),o+n>l&&(c=l-o);let f=t,p=r;t<0&&(p+=t,f=0),f+r>u&&(p=u-f);let m=c*4;if(m%this._packAlignment!==0&&(m+=this._packAlignment-m%this._packAlignment),c>0&&p>0){let n=new Uint8Array(m*p),r=this._gl.readPixels(o,f,c,p,i,a,Uint8ArrayToVariant(n)),l=r&&r.length>0?r:n,u=4*(o-e)+(f-t)*s;for(let e=0;e<p;++e)for(let t=0;t<c;++t)for(let n=0;n<4;++n)d[u+e*s+4*t+n]=l[e*m+4*t+n]}}else{let o=this._gl.readPixels(e,t,n,r,i,a,Uint8ArrayToVariant(d));o&&o.length>0&&d.set(o)}},enableVertexAttribArray(e){if(e<0||e>=this._vertexObjectState._attribs.length){this.setError(this.INVALID_VALUE);return}this._gl.enableVertexAttribArray(e),this._vertexObjectState._attribs[e]._isPointer=!0},disableVertexAttribArray(e=0){if(e<0||e>=this._vertexObjectState._attribs.length){this.setError(this.INVALID_VALUE);return}this._gl.disableVertexAttribArray(e),this._vertexObjectState._attribs[e]._isPointer=!1},vertexAttrib1f(e,t){if(e|=0,!this._checkVertexIndex(e))return;let n=this._vertexGlobalState._attribs[e]._data;n[3]=1,n[1]=n[2]=0,n[0]=t,this._gl.vertexAttrib1f(e|0,+t)},vertexAttrib1fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<1){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;n[3]=1,n[2]=0,n[1]=0,n[0]=t[0],this._gl.vertexAttrib1f(e|0,+t[0])},vertexAttrib2f(e,t,n){if(e|=0,!this._checkVertexIndex(e))return;let r=this._vertexGlobalState._attribs[e]._data;r[3]=1,r[2]=0,r[1]=n,r[0]=t,this._gl.vertexAttrib2f(e|0,+t,+n)},vertexAttrib2fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<2){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;n[3]=1,n[2]=0,n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib2f(e|0,+t[0],+t[1])},vertexAttrib3f(e,t,n,r){if(e|=0,!this._checkVertexIndex(e))return;let i=this._vertexGlobalState._attribs[e]._data;i[3]=1,i[2]=r,i[1]=n,i[0]=t,this._gl.vertexAttrib3f(e|0,+t,+n,+r)},vertexAttrib3fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<3){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;n[3]=1,n[2]=t[2],n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib3f(e|0,+t[0],+t[1],+t[2])},vertexAttrib4f(e=0,t,n,r,i){if(!this._checkVertexIndex(e))return;let a=this._vertexGlobalState._attribs[e]._data;a[3]=i,a[2]=r,a[1]=n,a[0]=t,this._gl.vertexAttrib4f(e|0,+t,+n,+r,+i)},vertexAttrib4fv(e,t){if(e|=0,!this._checkVertexIndex(e))return;if(typeof t!=`object`||!t||t.length<4){this.setError(this.INVALID_OPERATION);return}let n=this._vertexGlobalState._attribs[e]._data;n[3]=t[3],n[2]=t[2],n[1]=t[1],n[0]=t[0],this._gl.vertexAttrib4f(e|0,+t[0],+t[1],+t[2],+t[3])},vertexAttribPointer(e=0,t=0,n=0,r=!1,i=0,a=0){if(i<0||a<0){this.setError(this.INVALID_VALUE);return}if(i<0||a<0||e<0||e>=this._vertexObjectState._attribs.length||!(t===1||t===2||t===3||t===4)){this.setError(this.INVALID_VALUE);return}if(this._vertexGlobalState._arrayBufferBinding===null){this.setError(this.INVALID_OPERATION);return}let o=typeSize(this,n);if(o===0||n===this.INT||n===this.UNSIGNED_INT){this.setError(this.INVALID_ENUM);return}if(i>255||i<0){this.setError(this.INVALID_VALUE);return}if(i%o!==0||a%o!==0){this.setError(this.INVALID_OPERATION);return}this._gl.vertexAttribPointer(e,t,n,r,i,a),this._vertexObjectState.setVertexAttribPointer(this._vertexGlobalState._arrayBufferBinding,e,t*o,a,i||t*o,n,r,i,t)},getVertexAttrib(e=0,t=0){if(e<0||e>=this._vertexObjectState._attribs.length)return this.setError(this.INVALID_VALUE),null;let n=this._vertexObjectState._attribs[e],r=this._vertexGlobalState._attribs[e]._data,i=this._extensions.angle_instanced_arrays;if(i&&t===i.VERTEX_ATTRIB_ARRAY_DIVISOR_ANGLE)return n._divisor;switch(t){case this.VERTEX_ATTRIB_ARRAY_BUFFER_BINDING:return n._pointerBuffer;case this.VERTEX_ATTRIB_ARRAY_ENABLED:return n._isPointer;case this.VERTEX_ATTRIB_ARRAY_SIZE:return n._inputSize;case this.VERTEX_ATTRIB_ARRAY_STRIDE:return n._inputStride;case this.VERTEX_ATTRIB_ARRAY_TYPE:return n._pointerType;case this.VERTEX_ATTRIB_ARRAY_NORMALIZED:return n._pointerNormal;case this.CURRENT_VERTEX_ATTRIB:return new Float32Array(r);default:return this.setError(this.INVALID_ENUM),null}},getVertexAttribOffset(e=0,t=0){return e<0||e>=this._vertexObjectState._attribs.length?(this.setError(this.INVALID_VALUE),-1):t===this.VERTEX_ATTRIB_ARRAY_POINTER?this._vertexObjectState._attribs[e]._pointerOffset:(this.setError(this.INVALID_ENUM),-1)},_checkVertexAttribState(e){let t=this._activeProgram;if(!t)return this.setError(this.INVALID_OPERATION),!1;let n=this._vertexObjectState._attribs;for(let r=0;r<n.length;++r){let i=n[r];if(i._isPointer){let n=i._pointerBuffer;if(!n)return this.setError(this.INVALID_OPERATION),!1;if(t._attributes.indexOf(r)>=0){let t=0;if(t=i._divisor?i._pointerSize+i._pointerOffset:i._pointerStride*e+i._pointerSize+i._pointerOffset,t>n._size)return this.setError(this.INVALID_OPERATION),!1}}}return!0},_checkVertexIndex(e){return e<0||e>=this._vertexObjectState._attribs.length?(this.setError(this.INVALID_VALUE),!1):!0}};function installDrawingMethods(e){Object.assign(e,Zt)}var WebGLDrawingBufferWrapper=class{constructor(e,t,n){this._framebuffer=e,this._color=t,this._depthStencil=n}},WebGLFramebuffer=class extends Linkable{constructor(e,t){if(super(e),this._binding=0,this._width=0,this._height=0,this._status=null,this._ctx=t,this._attachments={},this._attachments[t.COLOR_ATTACHMENT0]=null,this._attachments[t.DEPTH_ATTACHMENT]=null,this._attachments[t.STENCIL_ATTACHMENT]=null,this._attachments[t.DEPTH_STENCIL_ATTACHMENT]=null,this._attachmentLevel={},this._attachmentLevel[t.COLOR_ATTACHMENT0]=0,this._attachmentLevel[t.DEPTH_ATTACHMENT]=0,this._attachmentLevel[t.STENCIL_ATTACHMENT]=0,this._attachmentLevel[t.DEPTH_STENCIL_ATTACHMENT]=0,this._attachmentFace={},this._attachmentFace[t.COLOR_ATTACHMENT0]=0,this._attachmentFace[t.DEPTH_ATTACHMENT]=0,this._attachmentFace[t.STENCIL_ATTACHMENT]=0,this._attachmentFace[t.DEPTH_STENCIL_ATTACHMENT]=0,t._extensions.webgl_draw_buffers){let e=t._extensions.webgl_draw_buffers;this._attachments[e.COLOR_ATTACHMENT1_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT2_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT3_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT4_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT5_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT6_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT7_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT8_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT9_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT10_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT11_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT12_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT13_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT14_WEBGL]=null,this._attachments[e.COLOR_ATTACHMENT15_WEBGL]=null,this._attachments[t.NONE]=null,this._attachments[t.BACK]=null,this._attachmentLevel[e.COLOR_ATTACHMENT1_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT2_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT3_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT4_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT5_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT6_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT7_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT8_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT9_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT10_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT11_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT12_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT13_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT14_WEBGL]=0,this._attachmentLevel[e.COLOR_ATTACHMENT15_WEBGL]=0,this._attachmentLevel[t.NONE]=null,this._attachmentLevel[t.BACK]=null,this._attachmentFace[e.COLOR_ATTACHMENT1_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT2_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT3_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT4_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT5_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT6_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT7_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT8_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT9_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT10_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT11_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT12_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT13_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT14_WEBGL]=0,this._attachmentFace[e.COLOR_ATTACHMENT15_WEBGL]=0,this._attachmentFace[t.NONE]=null,this._attachmentFace[t.BACK]=null}}_clearAttachment(e){let t=this._attachments[e];t&&(this._attachments[e]=null,this._unlink(t))}_setAttachment(e,t){this._attachments[t]!==e&&(this._clearAttachment(t),e&&(this._attachments[t]=e,this._link(e)))}_performDelete(){let e=this._ctx;delete e._framebuffers[this._|0],e._gl.deleteFramebuffer(this._|0)}},WebGLRenderbuffer=class extends Linkable{constructor(e,t){super(e),this._binding=0,this._width=0,this._height=0,this._format=0,this._ctx=t,this._binding=0,this._width=0,this._height=0,this._format=0}_performDelete(){let e=this._ctx;delete e._renderbuffers[this._|0],e._gl.deleteRenderbuffer(this._)}},WebGLTexture=class extends Linkable{constructor(e,t){super(e),this._binding=0,this._levelWidth=new Int32Array(32),this._levelHeight=new Int32Array(32),this._format=0,this._type=0,this._complete=!0,this._ctx=t}_performDelete(){let e=this._ctx;delete e._textures[this._|0],e._gl.deleteTexture(this._|0)}};const Qt={bindFramebuffer(e,t){if(!checkObject(t))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(e!==this.FRAMEBUFFER){this.setError(this.INVALID_ENUM);return}if(!t)this._gl.bindFramebuffer(this.FRAMEBUFFER,this._gtkFboId);else if(t._pendingDelete)return;else if(this._checkWrapper(t,WebGLFramebuffer))this._gl.bindFramebuffer(this.FRAMEBUFFER,t._|0);else return;let n=this._activeFramebuffer;n!==t&&(n&&(--n._refCount,n._checkDelete()),t&&(t._refCount+=1)),this._activeFramebuffer=t,t&&this._updateFramebufferAttachments(t)},bindRenderbuffer(e,t){if(!checkObject(t))throw TypeError(`bindRenderbuffer(GLenum, WebGLRenderbuffer)`);if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}if(!t)this._gl.bindRenderbuffer(e|0,0);else if(t._pendingDelete)return;else if(this._checkWrapper(t,WebGLRenderbuffer))this._gl.bindRenderbuffer(e|0,t._|0);else return;let n=this._activeRenderbuffer;n!==t&&(n&&(--n._refCount,n._checkDelete()),t&&(t._refCount+=1)),this._activeRenderbuffer=t},framebufferRenderbuffer(e,t,n,r){if(!checkObject(r))throw TypeError(`framebufferRenderbuffer(GLenum, GLenum, GLenum, WebGLRenderbuffer)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t)||n!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeFramebuffer;if(!i){this.setError(this.INVALID_OPERATION);return}r&&!this._checkWrapper(r,WebGLRenderbuffer)||(i._setAttachment(r,t),this._updateFramebufferAttachments(i))},framebufferTexture2D(e,t,n,r,i=0){if(e|=0,t|=0,n|=0,i|=0,!checkObject(r))throw TypeError(`framebufferTexture2D(GLenum, GLenum, GLenum, WebGLTexture, GLint)`);if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t)){this.setError(this.INVALID_ENUM);return}if(i!==0){this.setError(this.INVALID_VALUE);return}if(r&&!this._checkWrapper(r,WebGLTexture))return;if(n===this.TEXTURE_2D){if(r&&r._binding!==this.TEXTURE_2D){this.setError(this.INVALID_OPERATION);return}}else if(this._validCubeTarget(n)){if(r&&r._binding!==this.TEXTURE_CUBE_MAP){this.setError(this.INVALID_OPERATION);return}}else{this.setError(this.INVALID_ENUM);return}let a=this._activeFramebuffer;if(!a){this.setError(this.INVALID_OPERATION);return}a._attachmentLevel[t]=i,a._attachmentFace[t]=n,a._setAttachment(r,t),this._updateFramebufferAttachments(a)},createFramebuffer(){let e=this._gl.createFramebuffer();if(e<=0)return null;let t=new WebGLFramebuffer(e,this);return this._framebuffers[e]=t,t},deleteFramebuffer(e){if(!checkObject(e))throw TypeError(`deleteFramebuffer(WebGLFramebuffer)`);if(!(e instanceof WebGLFramebuffer&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeFramebuffer===e&&this.bindFramebuffer(this.FRAMEBUFFER,null),e._pendingDelete=!0,e._checkDelete()},createRenderbuffer(){let e=this._gl.createRenderbuffer();if(e<=0)return null;let t=new WebGLRenderbuffer(e,this);return this._renderbuffers[e]=t,t},deleteRenderbuffer(e){if(!checkObject(e))throw TypeError(`deleteRenderbuffer(WebGLRenderbuffer)`);if(!(e instanceof WebGLRenderbuffer&&this._checkOwns(e))){this.setError(this.INVALID_OPERATION);return}this._activeRenderbuffer===e&&this.bindRenderbuffer(this.RENDERBUFFER,null),this._detachRenderbufferFromAllFramebuffers(e),e._pendingDelete=!0,e._checkDelete()},renderbufferStorage(e=0,t=0,n=0,r=0){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(t!==this.RGBA4&&t!==this.RGB565&&t!==this.RGB5_A1&&t!==this.DEPTH_COMPONENT16&&t!==this.STENCIL_INDEX&&t!==this.STENCIL_INDEX8&&t!==this.DEPTH_STENCIL){this.setError(this.INVALID_ENUM);return}this._saveError(),this._gl.renderbufferStorage(e,t,n,r);let a=this.getError();if(this._restoreError(a),a!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let o=this._activeFramebuffer;if(o){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(o._attachments[t[n]]===i){e=!0;break}e&&this._updateFramebufferAttachments(this._activeFramebuffer)}},getFramebufferAttachmentParameter(e=0,t=0,n=0){if(e!==this.FRAMEBUFFER||!this._validFramebufferAttachment(t))return this.setError(this.INVALID_ENUM),null;let r=this._activeFramebuffer;if(!r)return this.setError(this.INVALID_OPERATION),null;let i=r._attachments[t];if(i===null){if(n===this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE)return this.NONE}else if(i instanceof WebGLTexture)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return i;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.TEXTURE;case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL:return r._attachmentLevel[t];case this.FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE:{let e=r._attachmentFace[t];return e===this.TEXTURE_2D?0:e}}else if(i instanceof WebGLRenderbuffer)switch(n){case this.FRAMEBUFFER_ATTACHMENT_OBJECT_NAME:return i;case this.FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE:return this.RENDERBUFFER}return this.setError(this.INVALID_ENUM),null},getRenderbufferParameter(e=0,t=0){if(e!==this.RENDERBUFFER)return this.setError(this.INVALID_ENUM),null;let n=this._activeRenderbuffer;if(!n)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.RENDERBUFFER_INTERNAL_FORMAT:return n._format;case this.RENDERBUFFER_WIDTH:return n._width;case this.RENDERBUFFER_HEIGHT:return n._height;case this.MAX_RENDERBUFFER_SIZE:return this._maxRenderbufferSize;case this.RENDERBUFFER_RED_SIZE:case this.RENDERBUFFER_GREEN_SIZE:case this.RENDERBUFFER_BLUE_SIZE:case this.RENDERBUFFER_ALPHA_SIZE:case this.RENDERBUFFER_DEPTH_SIZE:case this.RENDERBUFFER_STENCIL_SIZE:return this._gl.getRenderbufferParameter(e,t)}return this.setError(this.INVALID_ENUM),null},checkFramebufferStatus(e){if(e!==this.FRAMEBUFFER)return this.setError(this.INVALID_ENUM),0;let t=this._activeFramebuffer;return t?this._preCheckFramebufferStatus(t):this.FRAMEBUFFER_COMPLETE},_preCheckFramebufferStatus(e){let t=e._attachments,n=[],r=[],i=t[this.DEPTH_ATTACHMENT],a=t[this.DEPTH_STENCIL_ATTACHMENT],o=t[this.STENCIL_ATTACHMENT];if(a&&(o||i)||o&&i)return this.FRAMEBUFFER_UNSUPPORTED;let s=this._getColorAttachments(),c=0;for(let e in t)t[e]&&s.indexOf(Number(e))!==-1&&c++;if(c===0)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(a instanceof WebGLTexture)return this.FRAMEBUFFER_UNSUPPORTED;if(a instanceof WebGLRenderbuffer){if(a._format!==this.DEPTH_STENCIL)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(a._width),r.push(a._height)}if(i instanceof WebGLTexture)return this.FRAMEBUFFER_UNSUPPORTED;if(i instanceof WebGLRenderbuffer){if(i._format!==this.DEPTH_COMPONENT16)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(i._width),r.push(i._height)}if(o instanceof WebGLTexture)return this.FRAMEBUFFER_UNSUPPORTED;if(o instanceof WebGLRenderbuffer){if(o._format!==this.STENCIL_INDEX8)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;n.push(o._width),r.push(o._height)}let l=!1;for(let i=0;i<s.length;++i){let a=t[s[i]];if(a instanceof WebGLTexture){if(a._format!==this.RGBA||!(a._type===this.UNSIGNED_BYTE||a._type===this.FLOAT))return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;l=!0;let t=e._attachmentLevel[this.COLOR_ATTACHMENT0];if(t===null)throw TypeError(`level is null!`);n.push(a._levelWidth[t]),r.push(a._levelHeight[t])}else if(a instanceof WebGLRenderbuffer){let e=a._format;if(e!==this.RGBA4&&e!==this.RGB565&&e!==this.RGB5_A1)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;l=!0,n.push(a._width),r.push(a._height)}}if(!l&&!o&&!i&&!a)return this.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;if(n.length<=0||r.length<=0)return this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT;for(let e=1;e<n.length;++e)if(n[e-1]!==n[e]||r[e-1]!==r[e])return this.FRAMEBUFFER_INCOMPLETE_DIMENSIONS;return n[0]===0||r[0]===0?this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT:(e._width=n[0],e._height=r[0],this.FRAMEBUFFER_COMPLETE)},_framebufferOk(){let e=this._activeFramebuffer;return e&&this._preCheckFramebufferStatus(e)!==this.FRAMEBUFFER_COMPLETE?(this.setError(this.INVALID_FRAMEBUFFER_OPERATION),!1):!0},_validFramebufferAttachment(e){switch(e){case this.DEPTH_ATTACHMENT:case this.STENCIL_ATTACHMENT:case this.DEPTH_STENCIL_ATTACHMENT:case this.COLOR_ATTACHMENT0:return!0}if(this._extensions.webgl_draw_buffers){let t=this._extensions.webgl_draw_buffers;return e<t.COLOR_ATTACHMENT0_WEBGL+t._maxDrawBuffers}return!1},_updateFramebufferAttachments(e){if(!e)return;let t=e._status,n=this._getAttachments();if(e._status=this._preCheckFramebufferStatus(e),e._status!==this.FRAMEBUFFER_COMPLETE){if(t===this.FRAMEBUFFER_COMPLETE)for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}return}for(let t=0;t<n.length;++t){let r=n[t];this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,0,e._attachmentLevel[r]||0)}for(let t=0;t<n.length;++t){let r=n[t],i=e._attachments[r];i instanceof WebGLTexture?this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,e._attachmentFace[r]||0,i._|0,e._attachmentLevel[r]||0):i instanceof WebGLRenderbuffer&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,r,this.RENDERBUFFER,i._|0)}},_tryDetachFramebuffer(e,t){if(e&&e._linked(t)){let n=this._getAttachments();for(let r=0;r<n.length;++r)e._attachments[n[r]]===t&&this.framebufferTexture2D(this.FRAMEBUFFER,n[r]|0,this.TEXTURE_2D,null)}},_detachRenderbufferFromAllFramebuffers(e){let t=this._activeFramebuffer,n=this._getAttachments(),r=!1;for(let i in this._framebuffers){let a=this._framebuffers[i];if(!(!a||!a._linked(e))){a!==t&&(this._gl.bindFramebuffer(this.FRAMEBUFFER,a._|0),r=!0);for(let t=0;t<n.length;++t){let r=n[t];a._attachments[r]===e&&(this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,r,this.RENDERBUFFER,0),a._setAttachment(null,r))}}}r&&this._gl.bindFramebuffer(this.FRAMEBUFFER,t?t._|0:this._gtkFboId)},_getAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_ATTACHMENTS:this.DEFAULT_ATTACHMENTS},_getColorAttachments(){return this._extensions.webgl_draw_buffers?this._extensions.webgl_draw_buffers._ALL_COLOR_ATTACHMENTS:this.DEFAULT_COLOR_ATTACHMENTS},_resizeDrawingBuffer(e,t){let n=this._activeFramebuffer,r=this._getActiveTexture(this.TEXTURE_2D),i=this._activeRenderbuffer,a=this._contextAttributes,o=this._drawingBuffer;o?._framebuffer&&this._gl.bindFramebuffer(this.FRAMEBUFFER,o?._framebuffer);let s=this._getAttachments();for(let e=0;e<s.length;++e)this._gl.framebufferTexture2D(this.FRAMEBUFFER,s[e],this.TEXTURE_2D,0,0);o?._color&&this._gl.bindTexture(this.TEXTURE_2D,o?._color);let c=a.alpha?this.RGBA:this.RGB;this._gl.texImage2D(this.TEXTURE_2D,0,c,e,t,0,c,this.UNSIGNED_BYTE,Uint8ArrayToVariant(null)),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MIN_FILTER,this.NEAREST),this._gl.texParameteri(this.TEXTURE_2D,this.TEXTURE_MAG_FILTER,this.NEAREST),o?._color&&this._gl.framebufferTexture2D(this.FRAMEBUFFER,this.COLOR_ATTACHMENT0,this.TEXTURE_2D,o?._color,0);let l=0,u=0;a.depth&&a.stencil?(l=this.DEPTH_STENCIL,u=this.DEPTH_STENCIL_ATTACHMENT):a.depth?(l=33191,u=this.DEPTH_ATTACHMENT):a.stencil&&(l=this.STENCIL_INDEX8,u=this.STENCIL_ATTACHMENT),l&&(o?._depthStencil&&this._gl.bindRenderbuffer(this.RENDERBUFFER,o?._depthStencil),this._gl.renderbufferStorage(this.RENDERBUFFER,l,e,t),o?._depthStencil&&this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,u,this.RENDERBUFFER,o?._depthStencil)),this.bindFramebuffer(this.FRAMEBUFFER,n),this.bindTexture(this.TEXTURE_2D,r),this.bindRenderbuffer(this.RENDERBUFFER,i)},_allocateDrawingBuffer(e,t){this._drawingBuffer=new WebGLDrawingBufferWrapper(this._gl.createFramebuffer(),this._gl.createTexture(),this._gl.createRenderbuffer()),this._resizeDrawingBuffer(e,t)},resize(e=0,t=0){if(e|=0,t|=0,e>0&&t>0)(e!==this.drawingBufferWidth||t!==this.drawingBufferHeight)&&this._resizeDrawingBuffer(e,t);else throw Error(`Invalid surface dimensions`)}};function installFramebufferMethods(e){Object.assign(e,Qt)}var WebGLProgram$1=class extends Linkable{static{__name(this,`WebGLProgram`)}constructor(e,t){super(e),this._linkCount=0,this._linkStatus=!1,this._linkInfoLog=`not linked`,this._attributes=[],this._uniforms=[],this._ctx=t,this._linkCount=0,this._linkStatus=!1,this._linkInfoLog=`not linked`,this._attributes=[],this._uniforms=[]}_performDelete(){let e=this._ctx;delete e._programs[this._|0],e._gl.deleteProgram(this._|0)}},WebGLShader$1=class extends Linkable{static{__name(this,`WebGLShader`)}constructor(e,t,n){super(e),this._source=``,this._compileStatus=!1,this._compileInfo=``,this._needsRecompile=!1,this._type=n,this._ctx=t,this._source=``,this._compileStatus=!1,this._compileInfo=``}_performDelete(){let e=this._ctx;delete e._shaders[this._|0],e._gl.deleteShader(this._|0)}};const $t={enable(e=0){this._gl.enable(e)},disable(e=0){if(this._gl.disable(e),e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP){let t=this._getActiveTextureUnit();t._mode===e&&(t._mode=0)}},cullFace(e){this._gl.cullFace(e|0)},depthFunc(e){switch(e|=0,e){case this.NEVER:case this.LESS:case this.EQUAL:case this.LEQUAL:case this.GREATER:case this.NOTEQUAL:case this.GEQUAL:case this.ALWAYS:this._gl.depthFunc(e);return;default:this.setError(this.INVALID_ENUM)}},depthMask(e){this._gl.depthMask(!!e)},depthRange(e,t){if(e=+e,t=+t,e<=t){this._gl.depthRange(e,t);return}this.setError(this.INVALID_OPERATION)},frontFace(e=0){this._gl.frontFace(e)},lineWidth(e){if(isNaN(e)){this.setError(this.INVALID_VALUE);return}this._gl.lineWidth(+e)},polygonOffset(e,t){this._gl.polygonOffset(+e,+t)},sampleCoverage(e,t){this._gl.sampleCoverage(+e,!!t)},hint(e=0,t=0){let n=this._extensions.oes_standard_derivatives;if(!(e===this.GENERATE_MIPMAP_HINT||n&&e===n.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)){this.setError(this.INVALID_ENUM);return}if(t!==this.FASTEST&&t!==this.NICEST&&t!==this.DONT_CARE){this.setError(this.INVALID_ENUM);return}this._gl.hint(e,t)},finish(){this._gl.finish()},flush(){this._gl.flush()},blendColor(e=0,t=0,n=0,r=0){this._gl.blendColor(+e,+t,+n,+r)},blendEquation(e=0){if(this._validBlendMode(e)){this._gl.blendEquation(e);return}this.setError(this.INVALID_ENUM)},blendEquationSeparate(e=0,t=0){if(this._validBlendMode(e)&&this._validBlendMode(t)){this._gl.blendEquationSeparate(e,t);return}this.setError(this.INVALID_ENUM)},blendFunc(e=0,t=0){if(!this._validBlendFunc(e)||!this._validBlendFunc(t)){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFunc(e,t)},blendFuncSeparate(e=0,t=0,n=0,r=0){if(!(this._validBlendFunc(e)&&this._validBlendFunc(t)&&this._validBlendFunc(n)&&this._validBlendFunc(r))){this.setError(this.INVALID_ENUM);return}if(this._isConstantBlendFunc(e)&&this._isConstantBlendFunc(t)||this._isConstantBlendFunc(n)&&this._isConstantBlendFunc(r)){this.setError(this.INVALID_OPERATION);return}this._gl.blendFuncSeparate(e,t,n,r)},clear(e=0){this._framebufferOk()&&this._gl.clear(e)},clearColor(e,t,n,r){this._gl.clearColor(+e,+t,+n,+r)},clearDepth(e){this._gl.clearDepth(+e)},clearStencil(e=0){this._checkStencil=!1,this._gl.clearStencil(e)},colorMask(e,t,n,r){this._gl.colorMask(!!e,!!t,!!n,!!r)},stencilFunc(e,t,n){this._checkStencil=!0,this._gl.stencilFunc(e|0,t|0,n|0)},stencilFuncSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilFuncSeparate(e|0,t|0,n|0,r|0)},stencilMask(e){this._checkStencil=!0,this._gl.stencilMask(e>>>0)},stencilMaskSeparate(e,t){this._checkStencil=!0,this._gl.stencilMaskSeparate(e|0,t>>>0)},stencilOp(e,t,n){this._checkStencil=!0,this._gl.stencilOp(e|0,t|0,n|0)},stencilOpSeparate(e,t,n,r){this._checkStencil=!0,this._gl.stencilOpSeparate(e|0,t|0,n|0,r|0)},isEnabled(e=0){return this._gl.isEnabled(e)},isContextLost(){return!1},getError(){return this._gl.getError()},setError(e){this._gl.setError(e)},isBuffer(e){return this._isObject(e,`isBuffer`,WebGLBuffer)?this._gl.isBuffer(e?._):!1},isFramebuffer(e){return this._isObject(e,`isFramebuffer`,WebGLFramebuffer)?this._gl.isFramebuffer(e?._):!1},isProgram(e){return this._isObject(e,`isProgram`,WebGLProgram$1)?this._gl.isProgram(e?._):!1},isRenderbuffer(e){return this._isObject(e,`isRenderbuffer`,WebGLRenderbuffer)?this._gl.isRenderbuffer(e?._):!1},isShader(e){return this._isObject(e,`isShader`,WebGLShader$1)?this._gl.isShader(e?._):!1},isTexture(e){return this._isObject(e,`isTexture`,WebGLTexture)?this._gl.isTexture(e?._):!1},generateMipmap(e=0){this._gl.generateMipmap(e)},_validBlendFunc(e){return e===this.ZERO||e===this.ONE||e===this.SRC_COLOR||e===this.ONE_MINUS_SRC_COLOR||e===this.DST_COLOR||e===this.ONE_MINUS_DST_COLOR||e===this.SRC_ALPHA||e===this.ONE_MINUS_SRC_ALPHA||e===this.DST_ALPHA||e===this.ONE_MINUS_DST_ALPHA||e===this.SRC_ALPHA_SATURATE||e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_validBlendMode(e){let t=this._extensions.ext_blend_minmax;return e===this.FUNC_ADD||e===this.FUNC_SUBTRACT||e===this.FUNC_REVERSE_SUBTRACT||!!(t&&(e===t.MIN_EXT||e===t.MAX_EXT))},_isConstantBlendFunc(e){return e===this.CONSTANT_COLOR||e===this.ONE_MINUS_CONSTANT_COLOR||e===this.CONSTANT_ALPHA||e===this.ONE_MINUS_CONSTANT_ALPHA},_saveError(){this._errorStack.push(this.getError())},_restoreError(e){let t=this._errorStack.pop();t===this.NO_ERROR?this.setError(e):t!==void 0&&this.setError(t)}};function installStateMethods(e){Object.assign(e,$t)}const en={activeTexture(e=0){let t=e-this.TEXTURE0;if(t>=0&&t<this._textureUnits.length){this._activeTextureUnit=t,this._gl.activeTexture(e);return}this.setError(this.INVALID_ENUM)},bindTexture(e=0,t){if(!checkObject(t))throw TypeError(`bindTexture(GLenum, WebGLTexture)`);if(!this._validTextureTarget(e)){this.setError(this.INVALID_ENUM);return}let n=0;if(!t)t=null;else if(t instanceof WebGLTexture&&t._pendingDelete)return;else if(this._checkWrapper(t,WebGLTexture)){if(t._binding&&t._binding!==e){this.setError(this.INVALID_OPERATION);return}t._binding=e,t._complete&&(n=t._|0)}else return;this._saveError(),this._gl.bindTexture(e,n);let r=this.getError();if(this._restoreError(r),r!==this.NO_ERROR)return;let i=this._getActiveTextureUnit(),a=this._getActiveTexture(e);a!==t&&(a&&(--a._refCount,a._checkDelete()),t&&(t._refCount+=1)),e===this.TEXTURE_2D?i._bind2D=t:e===this.TEXTURE_CUBE_MAP&&(i._bindCube=t)},createTexture(){let e=this._gl.createTexture();if(e<=0)return null;let t=new WebGLTexture(e,this);return this._textures[e]=t,t},deleteTexture(e){if(!checkObject(e))throw TypeError(`deleteTexture(WebGLTexture)`);if(e instanceof WebGLTexture){if(!this._checkOwns(e)){this.setError(this.INVALID_OPERATION);return}}else return;let t=this._activeTextureUnit;for(let t=0;t<this._textureUnits.length;++t){let n=this._textureUnits[t];n._bind2D===e?(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_2D,null)):n._bindCube===e&&(this.activeTexture(this.TEXTURE0+t),this.bindTexture(this.TEXTURE_CUBE_MAP,null))}this.activeTexture(this.TEXTURE0+t),this._detachTextureFromAllFramebuffers(e),e._pendingDelete=!0,e._checkDelete()},_detachTextureFromAllFramebuffers(e){let t=this._activeFramebuffer,n=this._getAttachments(),r=!1;for(let i in this._framebuffers){let a=this._framebuffers[i];if(!(!a||!a._linked(e))){a!==t&&(this._gl.bindFramebuffer(this.FRAMEBUFFER,a._|0),r=!0);for(let t=0;t<n.length;++t){let r=n[t];a._attachments[r]===e&&(this._gl.framebufferTexture2D(this.FRAMEBUFFER,r,a._attachmentFace[r]||this.TEXTURE_2D,0,a._attachmentLevel[r]||0),a._setAttachment(null,r))}}}r&&this._gl.bindFramebuffer(this.FRAMEBUFFER,t?t._|0:this._gtkFboId)},pixelStorei(e=0,t=0){if(typeof t==`boolean`&&(t=t===!1?0:1),e===this.UNPACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._unpackAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.PACK_ALIGNMENT)if(t===1||t===2||t===4||t===8)this._packAlignment=t;else{this.setError(this.INVALID_VALUE);return}else if(e===this.UNPACK_COLORSPACE_CONVERSION_WEBGL){if(!(t===this.NONE||t===this.BROWSER_DEFAULT_WEBGL)){this.setError(this.INVALID_VALUE);return}}else if(e===this.UNPACK_FLIP_Y_WEBGL){this._unpackFlipY=!!t;return}else if(e===this.UNPACK_PREMULTIPLY_ALPHA_WEBGL){this._unpackPremultAlpha=!!t;return}this._gl.pixelStorei(e,t)}};function installTextureLifecycleMethods(e){Object.assign(e,en)}const tn={texImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c){let u=0,d=0,f=0,p,m,h=0;if(arguments.length===6)if(s=i,f=r,a instanceof l.Pixbuf)m=a,u=m.get_width(),d=m.get_height(),c=m.get_pixels();else{p=a;let e=extractImageData(p);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);u=e.width,d=e.height,c=e.data}else arguments.length===9&&(u=r,d=i,h=a,f=o,c=c);if(typeof c!=`object`&&c!==void 0)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!checkFormat(this,f)||!checkFormat(this,n)){this.setError(this.INVALID_ENUM);return}if(s===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let g=this._getTexImage(e);if(!g||f!==n){this.setError(this.INVALID_OPERATION);return}let _=this._computePixelSize(s,f);if(_===0||!this._checkDimensions(e,u,d,t))return;let v=convertPixels(c),y=this._computeRowStride(u,_),b=y*d;if(v&&v.length<b){this.setError(this.INVALID_OPERATION);return}if(h!==0||validCubeTarget(this,e)&&u!==d){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&v&&f===this.RGBA&&(v=premultiplyAlpha(v)),this._unpackFlipY&&v&&u>0&&d>0){let e=new Uint8Array(v.length);for(let t=0;t<d;t++){let n=t*y,r=(d-1-t)*y;e.set(v.subarray(n,n+y),r)}v=e}this._saveError(),this._gl.texImage2D(e,t,n,u,d,h,f,s,Uint8ArrayToVariant(v));let x=this.getError();if(this._restoreError(x),x!==this.NO_ERROR)return;g._levelWidth[t]=u,g._levelHeight[t]=d,g._format=f,g._type=s;let S=this._activeFramebuffer;if(S){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(S._attachments[t[n]]===g){e=!0;break}e&&this._activeFramebuffer&&this._updateFramebufferAttachments(this._activeFramebuffer)}},texSubImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c){let u=0,d=0,f=0,p,m;if(arguments.length===7)if(s=a,f=i,o instanceof l.Pixbuf)m=o,u=m.get_width(),d=m.get_height(),c=m.get_pixels();else{p=o;let e=extractImageData(p);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);u=e.width,d=e.height,c=e.data}else u=i,d=a,f=o;if(typeof c!=`object`)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLint, GLint, GLenum, GLenum, Uint8Array)`);if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(s===this.FLOAT&&!this._extensions.oes_texture_float){this.setError(this.INVALID_ENUM);return}let h=this._computePixelSize(s,f);if(h===0||!this._checkDimensions(e,u,d,t))return;if(n<0||r<0){this.setError(this.INVALID_VALUE);return}let g=convertPixels(c),_=this._computeRowStride(u,h),v=_*d;if(!g||g.length<v){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&g&&f===this.RGBA&&(g=premultiplyAlpha(g)),this._unpackFlipY&&g&&u>0&&d>0){let e=new Uint8Array(g.length);for(let t=0;t<d;t++){let n=t*_,r=(d-1-t)*_;e.set(g.subarray(n,n+_),r)}g=e}this._gl.texSubImage2D(e,t,n,r,u,d,f,s,Uint8ArrayToVariant(g))}};function installTexImage2DMethods(e){Object.assign(e,tn)}var nn=__toESM(__commonJSMin((e=>{e.INT_MIN=-1<<31,e.isPow2=function(e){return!(e&e-1)&&!!e},e.log2=function(e){var t=(e>65535)<<4,n;return e>>>=t,n=(e>255)<<3,e>>>=n,t|=n,n=(e>15)<<2,e>>>=n,t|=n,n=(e>3)<<1,e>>>=n,t|=n,t|e>>1},e.nextPow2=function(e){return e+=e===0,--e,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e+1},(function(e){for(var t=0;t<256;++t){var n=t,r=t,i=7;for(n>>>=1;n;n>>>=1)r<<=1,r|=n&1,--i;e[t]=r<<i&255}})(Array(256))}))(),1);const rn={copyTexImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){let c=this._getTexImage(e);if(!c){this.setError(this.INVALID_OPERATION);return}if(n!==this.RGBA&&n!==this.RGB&&n!==this.ALPHA&&n!==this.LUMINANCE&&n!==this.LUMINANCE_ALPHA){this.setError(this.INVALID_ENUM);return}if(t<0||a<0||o<0||s!==0){this.setError(this.INVALID_VALUE);return}if(t>0&&!(nn.isPow2(a)&&nn.isPow2(o))){this.setError(this.INVALID_VALUE);return}this._saveError(),this._gl.copyTexImage2D(e,t,n,r,i,a,o,s);let l=this.getError();this._restoreError(l),l===this.NO_ERROR&&(c._levelWidth[t]=a,c._levelHeight[t]=o,c._format=this.RGBA,c._type=this.UNSIGNED_BYTE)},copyTexSubImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0){if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}if(o<0||s<0||n<0||r<0||t<0){this.setError(this.INVALID_VALUE);return}this._gl.copyTexSubImage2D(e,t,n,r,i,a,o,s)},compressedTexImage2D(e,t,n,r,i,a,o){this._gl.compressedTexImage2D(e,t,n,r,i,a,Uint8ArrayToVariant(arrayToUint8Array(o)))},compressedTexSubImage2D(e,t,n,r,i,a,o,s){this._gl.compressedTexSubImage2D(e,t,n,r,i,a,o,Uint8ArrayToVariant(arrayToUint8Array(s)))}};function installCopyAndCompressedTextureMethods(e){Object.assign(e,rn)}const an={texParameterf(e=0,t=0,n){if(n=+n,this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameterf(e,t,n);return}let r=this._extensions.ext_texture_filter_anisotropic;if(r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameterf(e,t,n);return}this.setError(this.INVALID_ENUM)}},texParameteri(e=0,t=0,n=0){if(this._checkTextureTarget(e)){switch(this._verifyTextureCompleteness(e,t,n),t){case this.TEXTURE_MIN_FILTER:case this.TEXTURE_MAG_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:this._gl.texParameteri(e,t,n);return}let r=this._extensions.ext_texture_filter_anisotropic;if(r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT){this._gl.texParameteri(e,t,n);return}this.setError(this.INVALID_ENUM)}},getTexParameter(e=0,t=0){if(!this._checkTextureTarget(e))return null;let n=this._getActiveTextureUnit();if(e===this.TEXTURE_2D&&!n._bind2D||e===this.TEXTURE_CUBE_MAP&&!n._bindCube)return this.setError(this.INVALID_OPERATION),null;switch(t){case this.TEXTURE_MAG_FILTER:case this.TEXTURE_MIN_FILTER:case this.TEXTURE_WRAP_S:case this.TEXTURE_WRAP_T:return this._getTexParameterDirect(e,t)}let r=this._extensions.ext_texture_filter_anisotropic;return r&&t===r.TEXTURE_MAX_ANISOTROPY_EXT?this._getTexParameterDirect(e,t):(this.setError(this.INVALID_ENUM),null)},_getTexParameterDirect(e=0,t=0){return this._gl.getTexParameterx(e,t)?.unpack()}};function installTextureParameterMethods(e){Object.assign(e,an)}const on={_getActiveTextureUnit(){return this._textureUnits[this._activeTextureUnit]},_getActiveTexture(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:e===this.TEXTURE_CUBE_MAP?t._bindCube:null},_getTexImage(e){let t=this._getActiveTextureUnit();return e===this.TEXTURE_2D?t._bind2D:validCubeTarget(this,e)?t._bindCube:(this.setError(this.INVALID_ENUM),null)},_checkTextureTarget(e){let t=this._getActiveTextureUnit(),n=null;if(e===this.TEXTURE_2D)n=t._bind2D;else if(e===this.TEXTURE_CUBE_MAP)n=t._bindCube;else return this.setError(this.INVALID_ENUM),!1;return n?!0:(this.setError(this.INVALID_OPERATION),!1)},_validTextureTarget(e){return e===this.TEXTURE_2D||e===this.TEXTURE_CUBE_MAP},_validCubeTarget(e){return e===this.TEXTURE_CUBE_MAP_POSITIVE_X||e===this.TEXTURE_CUBE_MAP_NEGATIVE_X||e===this.TEXTURE_CUBE_MAP_POSITIVE_Y||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Y||e===this.TEXTURE_CUBE_MAP_POSITIVE_Z||e===this.TEXTURE_CUBE_MAP_NEGATIVE_Z},_verifyTextureCompleteness(e,t,n){let r=this._getActiveTextureUnit(),i=null;if(e===this.TEXTURE_2D?i=r._bind2D:this._validCubeTarget(e)&&(i=r._bindCube),this._extensions.oes_texture_float&&!this._extensions.oes_texture_float_linear&&i&&i._type===this.FLOAT&&(t===this.TEXTURE_MAG_FILTER||t===this.TEXTURE_MIN_FILTER)&&(n===this.LINEAR||n===this.LINEAR_MIPMAP_NEAREST||n===this.NEAREST_MIPMAP_LINEAR||n===this.LINEAR_MIPMAP_LINEAR)){i._complete=!1,this.bindTexture(e,i);return}i&&i._complete===!1&&(i._complete=!0,this.bindTexture(e,i))},_computePixelSize(e,t){let n=formatSize(this,t);if(n===0)return this.setError(this.INVALID_ENUM),0;switch(e){case this.UNSIGNED_BYTE:return n;case this.UNSIGNED_SHORT_5_6_5:if(t!==this.RGB){this.setError(this.INVALID_OPERATION);break}return 2;case this.UNSIGNED_SHORT_4_4_4_4:case this.UNSIGNED_SHORT_5_5_5_1:if(t!==this.RGBA){this.setError(this.INVALID_OPERATION);break}return 2;case this.FLOAT:return 1}return this.setError(this.INVALID_ENUM),0},_computeRowStride(e,t){let n=e*t;return n%this._unpackAlignment&&(n+=this._unpackAlignment-n%this._unpackAlignment),n},_checkDimensions(e,t,n,r){if(r<0||t<0||n<0)return this.setError(this.INVALID_VALUE),!1;if(e===this.TEXTURE_2D){if(t>this._maxTextureSize||n>this._maxTextureSize||r>this._maxTextureLevel)return this.setError(this.INVALID_VALUE),!1}else if(this._validCubeTarget(e)){if(t>this._maxCubeMapSize||n>this._maxCubeMapSize||r>this._maxCubeMapLevel)return this.setError(this.INVALID_VALUE),!1}else return this.setError(this.INVALID_ENUM),!1;return!0}};function installTextureIntrospectionMethods(e){Object.assign(e,on)}function installTextureManagementMethods(e){installTextureLifecycleMethods(e),installTexImage2DMethods(e),installCopyAndCompressedTextureMethods(e),installTextureParameterMethods(e),installTextureIntrospectionMethods(e)}var WebGLShaderPrecisionFormat=class{constructor(e){this.rangeMin=e.rangeMin,this.rangeMax=e.rangeMax,this.precision=e.precision}},sn=__commonJSMin(((e,t)=>{t.exports=`precision.highp.mediump.lowp.attribute.const.uniform.varying.break.continue.do.for.while.if.else.in.out.inout.float.int.uint.void.bool.true.false.discard.return.mat2.mat3.mat4.vec2.vec3.vec4.ivec2.ivec3.ivec4.bvec2.bvec3.bvec4.sampler1D.sampler2D.sampler3D.samplerCube.sampler1DShadow.sampler2DShadow.struct.asm.class.union.enum.typedef.template.this.packed.goto.switch.default.inline.noinline.volatile.public.static.extern.external.interface.long.short.double.half.fixed.unsigned.input.output.hvec2.hvec3.hvec4.dvec2.dvec3.dvec4.fvec2.fvec3.fvec4.sampler2DRect.sampler3DRect.sampler2DRectShadow.sizeof.cast.namespace.using`.split(`.`)})),cn=__commonJSMin(((e,t)=>{t.exports=`<<= >>= ++ -- << >> <= >= == != && || += -= *= /= %= &= ^^ ^= |= ( ) [ ] . ! ~ * / % + - < > & ^ | ? : = , ; { }`.split(` `)})),ln=__commonJSMin(((e,t)=>{t.exports=`abs.acos.all.any.asin.atan.ceil.clamp.cos.cross.dFdx.dFdy.degrees.distance.dot.equal.exp.exp2.faceforward.floor.fract.gl_BackColor.gl_BackLightModelProduct.gl_BackLightProduct.gl_BackMaterial.gl_BackSecondaryColor.gl_ClipPlane.gl_ClipVertex.gl_Color.gl_DepthRange.gl_DepthRangeParameters.gl_EyePlaneQ.gl_EyePlaneR.gl_EyePlaneS.gl_EyePlaneT.gl_Fog.gl_FogCoord.gl_FogFragCoord.gl_FogParameters.gl_FragColor.gl_FragCoord.gl_FragData.gl_FragDepth.gl_FragDepthEXT.gl_FrontColor.gl_FrontFacing.gl_FrontLightModelProduct.gl_FrontLightProduct.gl_FrontMaterial.gl_FrontSecondaryColor.gl_LightModel.gl_LightModelParameters.gl_LightModelProducts.gl_LightProducts.gl_LightSource.gl_LightSourceParameters.gl_MaterialParameters.gl_MaxClipPlanes.gl_MaxCombinedTextureImageUnits.gl_MaxDrawBuffers.gl_MaxFragmentUniformComponents.gl_MaxLights.gl_MaxTextureCoords.gl_MaxTextureImageUnits.gl_MaxTextureUnits.gl_MaxVaryingFloats.gl_MaxVertexAttribs.gl_MaxVertexTextureImageUnits.gl_MaxVertexUniformComponents.gl_ModelViewMatrix.gl_ModelViewMatrixInverse.gl_ModelViewMatrixInverseTranspose.gl_ModelViewMatrixTranspose.gl_ModelViewProjectionMatrix.gl_ModelViewProjectionMatrixInverse.gl_ModelViewProjectionMatrixInverseTranspose.gl_ModelViewProjectionMatrixTranspose.gl_MultiTexCoord0.gl_MultiTexCoord1.gl_MultiTexCoord2.gl_MultiTexCoord3.gl_MultiTexCoord4.gl_MultiTexCoord5.gl_MultiTexCoord6.gl_MultiTexCoord7.gl_Normal.gl_NormalMatrix.gl_NormalScale.gl_ObjectPlaneQ.gl_ObjectPlaneR.gl_ObjectPlaneS.gl_ObjectPlaneT.gl_Point.gl_PointCoord.gl_PointParameters.gl_PointSize.gl_Position.gl_ProjectionMatrix.gl_ProjectionMatrixInverse.gl_ProjectionMatrixInverseTranspose.gl_ProjectionMatrixTranspose.gl_SecondaryColor.gl_TexCoord.gl_TextureEnvColor.gl_TextureMatrix.gl_TextureMatrixInverse.gl_TextureMatrixInverseTranspose.gl_TextureMatrixTranspose.gl_Vertex.greaterThan.greaterThanEqual.inversesqrt.length.lessThan.lessThanEqual.log.log2.matrixCompMult.max.min.mix.mod.normalize.not.notEqual.pow.radians.reflect.refract.sign.sin.smoothstep.sqrt.step.tan.texture2D.texture2DLod.texture2DProj.texture2DProjLod.textureCube.textureCubeLod.texture2DLodEXT.texture2DProjLodEXT.textureCubeLodEXT.texture2DGradEXT.texture2DProjGradEXT.textureCubeGradEXT`.split(`.`)})),un=__commonJSMin(((e,t)=>{t.exports=sn().slice().concat(`layout.centroid.smooth.case.mat2x2.mat2x3.mat2x4.mat3x2.mat3x3.mat3x4.mat4x2.mat4x3.mat4x4.uvec2.uvec3.uvec4.samplerCubeShadow.sampler2DArray.sampler2DArrayShadow.isampler2D.isampler3D.isamplerCube.isampler2DArray.usampler2D.usampler3D.usamplerCube.usampler2DArray.coherent.restrict.readonly.writeonly.resource.atomic_uint.noperspective.patch.sample.subroutine.common.partition.active.filter.image1D.image2D.image3D.imageCube.iimage1D.iimage2D.iimage3D.iimageCube.uimage1D.uimage2D.uimage3D.uimageCube.image1DArray.image2DArray.iimage1DArray.iimage2DArray.uimage1DArray.uimage2DArray.image1DShadow.image2DShadow.image1DArrayShadow.image2DArrayShadow.imageBuffer.iimageBuffer.uimageBuffer.sampler1DArray.sampler1DArrayShadow.isampler1D.isampler1DArray.usampler1D.usampler1DArray.isampler2DRect.usampler2DRect.samplerBuffer.isamplerBuffer.usamplerBuffer.sampler2DMS.isampler2DMS.usampler2DMS.sampler2DMSArray.isampler2DMSArray.usampler2DMSArray`.split(`.`))})),dn=__commonJSMin(((e,t)=>{var n=ln();n=n.slice().filter(function(e){return!/^(gl\_|texture)/.test(e)}),t.exports=n.concat(`gl_VertexID.gl_InstanceID.gl_Position.gl_PointSize.gl_FragCoord.gl_FrontFacing.gl_FragDepth.gl_PointCoord.gl_MaxVertexAttribs.gl_MaxVertexUniformVectors.gl_MaxVertexOutputVectors.gl_MaxFragmentInputVectors.gl_MaxVertexTextureImageUnits.gl_MaxCombinedTextureImageUnits.gl_MaxTextureImageUnits.gl_MaxFragmentUniformVectors.gl_MaxDrawBuffers.gl_MinProgramTexelOffset.gl_MaxProgramTexelOffset.gl_DepthRangeParameters.gl_DepthRange.trunc.round.roundEven.isnan.isinf.floatBitsToInt.floatBitsToUint.intBitsToFloat.uintBitsToFloat.packSnorm2x16.unpackSnorm2x16.packUnorm2x16.unpackUnorm2x16.packHalf2x16.unpackHalf2x16.outerProduct.transpose.determinant.inverse.texture.textureSize.textureProj.textureLod.textureOffset.texelFetch.texelFetchOffset.textureProjOffset.textureLodOffset.textureProjLod.textureProjLodOffset.textureGrad.textureGradOffset.textureProjGrad.textureProjGradOffset`.split(`.`))})),fn=__commonJSMin(((e,t)=>{t.exports=tokenize;var n=sn(),r=cn(),i=ln(),a=un(),o=dn(),s=999,c=9999,l=0,u=1,d=2,f=3,p=4,m=5,h=6,g=7,_=8,v=9,y=10,b=11,x=[`block-comment`,`line-comment`,`preprocessor`,`operator`,`integer`,`float`,`ident`,`builtin`,`keyword`,`whitespace`,`eof`,`integer`];function tokenize(e){var t=0,S=0,C=s,w,T,E=[],D=[],O=1,ee=0,k=0,te=!1,A=!1,j=``,ne;e||={};var re=i,ie=n;e.version===`300 es`&&(re=o,ie=a);for(var ae={},oe={},t=0;t<re.length;t++)ae[re[t]]=!0;for(var t=0;t<ie.length;t++)oe[ie[t]]=!0;return function(e){return D=[],e===null?end():write(e)};function token(e){e.length&&D.push({type:x[C],data:e,position:k,line:O,column:ee})}function write(e){t=0,e.toString&&(e=e.toString()),j+=e.replace(/\r\n/g,`
|
|
7
7
|
`),ne=j.length;for(var n;w=j[t],t<ne;){switch(n=t,C){case l:t=block_comment();break;case u:t=line_comment();break;case d:t=preprocessor();break;case f:t=operator();break;case p:t=integer();break;case b:t=hex();break;case m:t=decimal();break;case c:t=readtoken();break;case v:t=whitespace();break;case s:t=normal();break}if(n!==t)switch(j[n]){case`
|
|
8
8
|
`:ee=0,++O;break;default:++ee;break}}return S+=t,j=j.slice(t),D}function end(e){return E.length&&token(E.join(``)),C=y,token(`(eof)`),D}function normal(){return E=E.length?[]:E,T===`/`&&w===`*`?(k=S+t-1,C=l,T=w,t+1):T===`/`&&w===`/`?(k=S+t-1,C=u,T=w,t+1):w===`#`?(C=d,k=S+t,t):/\s/.test(w)?(C=v,k=S+t,t):(te=/\d/.test(w),A=/[^\w_]/.test(w),k=S+t,C=te?p:A?f:c,t)}function whitespace(){return/[^\s]/g.test(w)?(token(E.join(``)),C=s,t):(E.push(w),T=w,t+1)}function preprocessor(){return(w===`\r`||w===`
|
|
9
9
|
`)&&T!==`\\`?(token(E.join(``)),C=s,t):(E.push(w),T=w,t+1)}function line_comment(){return preprocessor()}function block_comment(){return w===`/`&&T===`*`?(E.push(w),token(E.join(``)),C=s,t+1):(E.push(w),T=w,t+1)}function operator(){if(T===`.`&&/\d/.test(w))return C=m,t;if(T===`/`&&w===`*`)return C=l,t;if(T===`/`&&w===`/`)return C=u,t;if(w===`.`&&E.length){for(;determine_operator(E););return C=m,t}if(w===`;`||w===`)`||w===`(`){if(E.length)for(;determine_operator(E););return token(w),C=s,t+1}var e=E.length===2&&w!==`=`;if(/[\w_\d\s]/.test(w)||e){for(;determine_operator(E););return C=s,t}return E.push(w),T=w,t+1}function determine_operator(e){var t=0,n,i;do{if(n=r.indexOf(e.slice(0,e.length+t).join(``)),i=r[n],n===-1){if(t--+e.length>0)continue;i=e.slice(0,1).join(``)}return token(i),k+=i.length,E=E.slice(i.length),E.length}while(1)}function hex(){return/[^a-fA-F0-9]/.test(w)?(token(E.join(``)),C=s,t):(E.push(w),T=w,t+1)}function integer(){return w===`.`||/[eE]/.test(w)?(E.push(w),C=m,T=w,t+1):w===`x`&&E.length===1&&E[0]===`0`?(C=b,E.push(w),T=w,t+1):/[^\d]/.test(w)?(token(E.join(``)),C=s,t):(E.push(w),T=w,t+1)}function decimal(){return w===`f`&&(E.push(w),T=w,t+=1),/[eE]/.test(w)||(w===`-`||w===`+`)&&/[eE]/.test(T)?(E.push(w),T=w,t+1):/[^\d]/.test(w)?(token(E.join(``)),C=s,t):(E.push(w),T=w,t+1)}function readtoken(){if(/[^\d\w_]/.test(w)){var e=E.join(``);return C=oe[e]?_:ae[e]?g:h,token(E.join(``)),C=s,t}return E.push(w),T=w,t+1}}})),pn=__toESM(__commonJSMin(((e,t)=>{var n=fn();t.exports=tokenizeString;function tokenizeString(e,t){var r=n(t),i=[];return i=i.concat(r(e)),i=i.concat(r(null)),i}}))(),1);const mn={createShader(e=0){if(e!==this.FRAGMENT_SHADER&&e!==this.VERTEX_SHADER)return this.setError(this.INVALID_ENUM),null;let t=this._gl.createShader(e);if(t<0)return null;let n=new WebGLShader$1(t,this,e);return this._shaders[t]=n,n},deleteShader(e){this._deleteLinkable(`deleteShader`,e,WebGLShader$1)},compileShader(e){if(!checkObject(e))throw TypeError(`compileShader(WebGLShader)`);if(this._checkWrapper(e,WebGLShader$1)&&this._checkShaderSource(e)){let t=this.getError();this._gl.compileShader(e._|0),e._needsRecompile=!1;let n=this.getError();e._compileStatus=!!this._gl.getShaderParameter(e._|0,this.COMPILE_STATUS),e._compileInfo=this._gl.getShaderInfoLog(e._|0)||`null`,this.getError(),this.setError(t||n)}},shaderSource(e,t){if(!checkObject(e))throw TypeError(`shaderSource(WebGLShader, String)`);if(!e||!t&&typeof t!=`string`){this.setError(this.INVALID_VALUE);return}isValidString(t)?this._checkWrapper(e,WebGLShader$1)&&(t=this._wrapShader(e._type,t),this._gl.shaderSource(e._|0,t),e._source=t,e._needsRecompile=!0):this.setError(this.INVALID_VALUE)},getShaderInfoLog(e){if(!checkObject(e))throw TypeError(`getShaderInfoLog(WebGLShader)`);return this._checkWrapper(e,WebGLShader$1)?e._compileInfo:null},getShaderParameter(e,t=0){if(!checkObject(e))throw TypeError(`getShaderParameter(WebGLShader, GLenum)`);if(this._checkWrapper(e,WebGLShader$1)){switch(t){case this.DELETE_STATUS:return e._pendingDelete;case this.COMPILE_STATUS:return e._compileStatus;case this.SHADER_TYPE:return e._type}this.setError(this.INVALID_ENUM)}return null},getShaderPrecisionFormat(e=0,t=0){if(!(e===this.FRAGMENT_SHADER||e===this.VERTEX_SHADER)||!(t===this.LOW_FLOAT||t===this.MEDIUM_FLOAT||t===this.HIGH_FLOAT||t===this.LOW_INT||t===this.MEDIUM_INT||t===this.HIGH_INT))return this.setError(this.INVALID_ENUM),null;let n=this._gl.getShaderPrecisionFormat(e,t);return n?new WebGLShaderPrecisionFormat(n):null},getShaderSource(e){if(!checkObject(e))throw TypeError(`Input to getShaderSource must be an object`);return this._checkWrapper(e,WebGLShader$1)?e._source:null},_checkShaderSource(e){let t=e._source,n=(0,pn.default)(t),r=!1,i=[];for(let e=0;e<n.length;++e){let t=n[e];if(t)switch(t.type){case`ident`:this._validGLSLIdentifier(t.data)||(r=!0,i.push(t.line+`:`+t.column+` invalid identifier - `+t.data));break;case`preprocessor`:{let e=t.data.match(/^\s*#\s*(.*)$/);if(!e||e?.length<2)break;let n=(0,pn.default)(e[1]);for(let e=0;e<n.length;++e){let a=n[e];(a.type===`ident`||a.type===void 0)&&(this._validGLSLIdentifier(a.data)||(r=!0,i.push(t.line+`:`+a.column+` invalid identifier - `+a.data)))}break}case`keyword`:switch(t.data){case`do`:r=!0,i.push(t.line+`:`+t.column+` do not supported`);break}break;case`builtin`:switch(t.data){case`dFdx`:case`dFdy`:case`fwidth`:!this._extensions.oes_standard_derivatives&&this._getGlslVersion(!0)===`100`&&(r=!0,i.push(t.line+`:`+t.column+` `+t.data+` not supported`));break}}}return r&&(e._compileInfo=i.join(`
|