@gjsify/example-dom-three-loader-ldraw 0.49.0 → 0.50.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/gjs.node.mjs CHANGED
@@ -74,7 +74,7 @@ import{createRequire as e}from"node:module";import t from"@gjsify/node-gi/cairo"
74
74
  </method>${e.length>0?`\n${e.join(`
75
75
  `)}`:``}
76
76
  </interface>
77
- </node>`}function isWin32(){return gt.DIR_SEPARATOR===92}function defaultListenAddress(){return isWin32()?`nonce-tcp:host=127.0.0.1`:`unix:tmpdir=${gt.get_tmp_dir()}`}var DevtoolsPeerServerError=class extends Error{constructor(e,t,n,r){super(e),this.address=t,this.reason=n,this.name=`DevtoolsPeerServerError`,this.cause=r}};function isAddressInUse(e){return e instanceof gt.Error&&e.matches(pt.io_error_quark(),pt.IOErrorEnum.ADDRESS_IN_USE)}function unixSocketPath(e){if(!e.startsWith(`unix:`))return null;for(let t of e.slice(5).split(`,`)){let e=t.indexOf(`=`);if(!(e<0||t.slice(0,e)!==`path`))try{return decodeURIComponent(t.slice(e+1))}catch{return null}}return null}function inspectExistingSocket(e){try{if((pt.File.new_for_path(e).query_info(`unix::mode`,pt.FileQueryInfoFlags.NONE,null).get_attribute_uint32(`unix::mode`)&61440)!=49152)return`not-a-socket`}catch{return`not-a-socket`}let t=new pt.SocketClient;t.set_timeout(2);let n;try{n=t.connect(pt.UnixSocketAddress.new(e),null)}catch{return`dead`}return n.close(null),`live`}function clearReclaimableSocket(e){let t=unixSocketPath(e);if(!t||!gt.file_test(t,gt.FileTest.EXISTS))return;let n=inspectExistingSocket(t);if(n===`live`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: another process is already listening there. Stop it, or point ${En} (or options.address) at a different socket — GJSIFY_DEVTOOLS_INSTANCE=<label> lets two devtools-enabled apps run side by side.`,e,`address-in-use`);if(n===`not-a-socket`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} already exists and is not a socket, so it will NOT be removed. Point ${En} (or options.address) at a free path.`,e,`occupied-by-other-file`);try{pt.File.new_for_path(t).delete(null)}catch(n){throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} is a socket nothing listens on, but removing it failed (${n}). Delete it by hand, or point ${En} at a free path.`,e,`address-in-use`,n)}console.log(`[gjsify-devtools] reclaimed the stale socket ${t}: nothing was listening on it (an abnormal exit — Ctrl-C, SIGKILL, a crash — leaves the inode behind).`)}function flagsForAddress(e){return e.startsWith(`tcp:`)||e.startsWith(`nonce-tcp:`)?pt.DBusServerFlags.NONE:pt.DBusServerFlags.AUTHENTICATION_REQUIRE_SAME_USER}function startDevtoolsPeerServer(e,t,n){let r=n&&n!==``?n:defaultListenAddress();clearReclaimableSocket(r);let i;try{i=pt.DBusServer.new_sync(r,flagsForAddress(r),pt.dbus_generate_guid(),null,null)}catch(e){let t=isAddressInUse(e);throw new DevtoolsPeerServerError(t?`cannot listen on ${r}: the address is already in use (${e}). Stop whatever holds it, or point ${En} (or options.address) at a different address.`:`cannot listen on ${r}: ${e}. Check the address form — \`unix:path=/tmp/app.sock\`, \`unix:tmpdir=/tmp\` or \`nonce-tcp:host=127.0.0.1\`.`,r,t?`address-in-use`:`listen-failed`,e)}let a=new Set;i.connect(`new-connection`,(n,r)=>(a.add(r),r.connect(`closed`,()=>{e.unexport(r),a.delete(r)}),e.export(r,t),!0)),i.start();let o=!1;return{address:i.get_client_address(),objectPath:t,get connectionCount(){return a.size},stop(){if(!o){o=!0,i.stop();for(let t of a)e.unexport(t),!t.is_closed()&&t.close(null,(e,t)=>{try{e.close_finish(t)}catch{}});a.clear()}}}}function writeDevtoolsAddressFile(e,t){try{if(gt.mkdir_with_parents(gt.path_get_dirname(e),448),!gt.file_set_contents(e,`${t}\n`))return null}catch(t){return console.error(`[gjsify-devtools] could not publish the peer address to ${e}: ${t}`),null}try{pt.File.new_for_path(e).set_attribute_uint32(`unix::mode`,384,pt.FileQueryInfoFlags.NONE,null)}catch(t){console.error(`[gjsify-devtools] could not restrict ${e} to the current user: ${t}`)}return e}function removeDevtoolsAddressFile(e){try{pt.File.new_for_path(e).delete(null)}catch{}}const Dn=e(import.meta.url);let On;function load$2(){return On===void 0&&(On=Dn(`@gjsify/node-gi/gi`).requireGi(`Graphene`,`1.0`)),On}__name$1(load$2,`load`);var kn=new Proxy(Object.create(null),{get(e,t){return load$2()[t]},has(e,t){return t in load$2()}});function captureWidget(e){let t=e.get_native()?.get_renderer();if(!t)return{png:null,blocker:`no-renderer`};let n=e.get_width(),r=e.get_height();if(n<=0||r<=0)return{png:null,blocker:`zero-size`};let i=Sn.WidgetPaintable.new(e),a=Sn.Snapshot.new();i.snapshot(a,n,r);let o=a.to_node();if(!o)return{png:null,blocker:`empty-snapshot`};let s=new kn.Rect;s.init(0,0,n,r);let c=t.render_texture(o,s).save_to_png_bytes().get_data();return c?{png:new Uint8Array(c)}:{png:null,blocker:`empty-png`}}function dumpGSettings(e){let t=pt.SettingsSchemaSource.get_default()?.lookup(e,!0);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`GSettings schema '${e}' is not installed`));let n=new pt.Settings({settings_schema:t}),r={};for(let e of t.list_keys())r[e]=n.get_value(e).recursiveUnpack();return r}function parseWidgetPath(e){let t=e.split(`/`).filter(e=>e.length>0);if(t.length===0)return null;let n=t[0].match(/^toplevel:(\d+)$/);if(!n)return null;let r=[];for(let e of t.slice(1)){let t=e.match(/^child:(\d+)$/);if(!t)return null;r.push(Number(t[1]))}return{toplevel:Number(n[1]),children:r}}function buildWidgetPath(e,t){return[`toplevel:${e}`,...t.map(e=>`child:${e}`)].join(`/`)}function widgetType(e){return gtypeName(e)??`GtkWidget`}function gtypeName(e){let t=e;return typeof t?.$typeName==`string`&&t.$typeName.length>0?t.$typeName:t?.constructor?.$gtype?.name??null}function activateWidget(e){let t=e;if(typeof t.activate==`function`&&t.activate()===!0)return!0;let n=typeof t.get_parent==`function`?t.get_parent():null;if(n&&widgetType(n)===`GtkListBox`){let t=n,r=!1;return typeof t.select_row==`function`&&(t.select_row(e),r=!0),typeof t.emit==`function`&&(t.emit(`row-activated`,e),r=!0),r}return!1}function sendKeyToWidget(e,t,n){let r=e.observe_controllers(),i=!1;for(let e=0;e<r.get_n_items();e++){let a=r.get_item(e);gtypeName(a)===`GtkEventControllerKey`&&(a.emit(`key-pressed`,t,0,n),i=!0)}return i}function nthChild(e,t){let n=e.get_first_child(),r=0;for(;n&&r<t;)n=n.get_next_sibling(),r++;return r===t?n:null}function listToplevels(){let e=Sn.Window.get_toplevels(),t=e.get_n_items(),n=[];for(let r=0;r<t;r++){let t=e.get_item(r);t&&n.push({path:`toplevel:${r}`,type:widgetType(t),title:t.get_title?.()??null,mapped:t.get_mapped(),focused:t.is_active??!1})}return n}function resolveWidgetPath(e){let t=parseWidgetPath(e);if(!t)return null;let n=Sn.Window.get_toplevels().get_item(t.toplevel);if(!n)return null;for(let e of t.children)if(n=nthChild(n,e),!n)return null;return n}function parseWidgetSelector(e){let t=e.indexOf(`:`),n=(t<0?e:e.slice(0,t)).trim(),r=(t<0?``:e.slice(t+1)).trim();return!n&&!r?null:{type:n,cssClass:r}}function findWidgetPath(e,t,n){if(!e.get_visible()||!e.get_mapped())return null;let r=!t.type||widgetType(e)===t.type,i=!t.cssClass||e.get_css_classes().includes(t.cssClass);if(r&&i)return n;let a=e.get_first_child(),o=0;for(;a;){let e=findWidgetPath(a,t,`${n}/child:${o}`);if(e)return e;a=a.get_next_sibling(),o++}return null}function geometryOf(e){if(!e.get_mapped())return;let t=e.get_allocation(),n=t.width+e.get_margin_start()+e.get_margin_end(),r=t.height+e.get_margin_top()+e.get_margin_bottom(),[i,a]=e.measure(Sn.Orientation.HORIZONTAL,-1),o=n>0?Math.max(n,i):-1,[s,c]=e.measure(Sn.Orientation.VERTICAL,o),l={width:n,height:r,widthRequest:[i,a],heightRequest:[s,c]};return(n<i||r<s)&&(l.short=!0),l}function dumpTree(e,t,n){let r={path:n,type:widgetType(e),name:e.get_name()||null,cssClasses:e.get_css_classes(),mapped:e.get_mapped(),visible:e.get_visible(),children:[]},i=geometryOf(e);if(i!==void 0&&(r.geometry=i),t<=0)return e.get_first_child()&&(r.truncated=!0),r;let a=e.get_first_child(),o=0;for(;a;)r.children.push(dumpTree(a,t-1,`${n}/child:${o}`)),a=a.get_next_sibling(),o++;return r}function jsonSafe(e){let t=typeof e;return e==null||t===`string`||t===`number`||t===`boolean`?e??null:`[${t}]`}function getWidgetProperty(e,t){let n=e,r=t.replace(/-/g,`_`),i=t.replace(/[-_]([a-z])/g,(e,t)=>t.toUpperCase());for(let e of[t,r,i])if(e in n)return jsonSafe(n[e])}function childIndex(e,t){let n=e.get_first_child(),r=0;for(;n;){if(n===t)return r;n=n.get_next_sibling(),r++}return-1}function pathOfWidget(e){let t=[],n=e,r=n.get_parent();for(;r;){let e=childIndex(r,n);if(e<0)return null;t.unshift(e),n=r,r=n.get_parent()}let i=Sn.Window.get_toplevels(),a=i.get_n_items();for(let e=0;e<a;e++)if(i.get_item(e)===n)return buildWidgetPath(e,t);return null}function isActiveWindowScope(e){return!e||e===`window`||e===`active`}function frameDelay(e){return new Promise(t=>{gt.timeout_add(gt.PRIORITY_DEFAULT,e,()=>(t(),gt.SOURCE_REMOVE))})}async function captureWidgetWhenRenderable(e,t=12,n=50){let r=null;for(let i=0;i<t;i++){let t=captureWidget(e);if(t.png)return{png:t.png,blocker:null};r=t.blocker,await frameDelay(n)}let i=captureWidget(e);return{png:i.png,blocker:i.png?null:i.blocker??r}}var DevtoolsService=class{constructor(e,t){this._app=e,this._options=t,this._exported=new Map,this._peer=null,this._addressFile=null,this._kinds=new Map,this._extensions=t.extend??[];for(let[e,t]of Object.entries(Tn))this._kinds.set(e,t);for(let e of this._extensions){for(let[t,n]of Object.entries(e.methodKinds))this._kinds.set(t,n);for(let[t,n]of Object.entries(e.handlers)){let e=n;this[t]=(...n)=>(this._guard(t),e(...n))}}}export(e,t){if(this._exported.has(e))return;let n=buildDevtoolsIfaceXml(this._extensions.flatMap(e=>e.methodsXml??[])),r=pt.DBusExportedObject.wrapJSObject(n,this);r.export(e,t),this._exported.set(e,r)}unexport(e){if(e){this._exported.get(e)?.unexport(),this._exported.delete(e);return}for(let e of this._exported.values())e.unexport();this._exported.clear(),this._peer?.stop(),this._peer=null,this._addressFile&&=(removeDevtoolsAddressFile(this._addressFile),null)}attachPeerServer(e,t){this._peer=e,this._addressFile=t??null}get peerAddress(){return this._peer?.address??null}get addressFile(){return this._addressFile}GetStatus(){let e=this._app.get_active_window(),t={appId:this._app.get_application_id()??`unknown`,instance:this._options.instance??`default`,activeWindow:e?{id:e.get_name()||`window`,title:e.get_title()??``,mapped:e.get_mapped()}:null,toplevelCount:Sn.Window.get_toplevels().get_n_items(),focusedWidget:null,paused:this._isPaused()};for(let e of this._extensions){let n=e.contributeStatus?.();n&&Object.assign(t,n)}return JSON.stringify(t)}async ScreenshotAsync(e,t){try{let n=typeof e?.[0]==`string`?e[0]:``,r=await this._captureScopePng(n);t.return_value(new gt.Variant(`(ay)`,[r]))}catch(e){t.return_dbus_error(`org.gjsify.Devtools.Error.Screenshot`,e instanceof Error?e.message:String(e))}}async _captureScopePng(e){let t=this._resolveRootWidget(e);if(!t){if(isActiveWindowScope(e))return new Uint8Array;throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`))}let n=captureWidget(t.widget);if(n.png)return n.png;let r=t.widget.get_root();r instanceof Sn.Window&&r.present();let i=await captureWidgetWhenRenderable(t.widget);return i.png?i.png:(console.warn(`[devtools] Screenshot('${e}') has no image: ${i.blocker??`unknown`} after 12 tries. Empty bytes follow.`),new Uint8Array)}ListActions(){let e={app:describeActions(this._actionGroup(`app`)),win:describeActions(this._actionGroup(`win`))};return JSON.stringify(e)}ActivateAction(e,t,n){this._guard(`ActivateAction`);let r=this._scope(e);activateAction(this._requireGroup(r,t),t,this._parseValue(n))}ChangeActionState(e,t,n){this._guard(`ChangeActionState`);let r=this._scope(e);changeActionState(this._requireGroup(r,t),t,this._parseValue(n))}PresentWindow(){this._app.get_active_window()?.present()}ResizeWindow(e,t){this._guard(`ResizeWindow`);let n=this._app.get_active_window();if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no active window to resize`));let r=Math.max(1,Math.round(e)),i=Math.max(1,Math.round(t));return n.is_maximized()&&n.unmaximize(),n.is_fullscreen()&&n.unfullscreen(),n.set_default_size(r,i),[r,i]}ListToplevels(){return JSON.stringify(listToplevels())}DumpTree(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e||`active window`}'`));return JSON.stringify(dumpTree(n.widget,t>0?t:40,n.path))}GetProperty(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));let r=getWidgetProperty(n.widget,t);if(r===void 0)throw Error(formatDbusErrorMessage(`not-found`,`widget has no property '${t}'`));return JSON.stringify(r)}GetFocused(){let e=this._app.get_active_window(),t=e?e.get_focus():null;return JSON.stringify(t?{path:pathOfWidget(t),name:t.get_name()||null,type:widgetType(t)}:null)}ActivateWidget(e){this._guard(`ActivateWidget`);let t=this._resolveRootWidget(e);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));return activateWidget(t.widget)}FindWidget(e){let t=parseWidgetSelector(e);if(!t)throw Error(formatDbusErrorMessage(`invalid-params`,`empty selector '${e}'`));let n=this._resolveRootWidget(``);return n?findWidgetPath(n.widget,t,n.path)??``:``}SendKey(e,t){this._guard(`SendKey`);let[n,r,i]=Sn.accelerator_parse(e);if(!n)throw Error(formatDbusErrorMessage(`invalid-params`,`cannot parse accelerator '${e}'`));let a;if(a=t?this._resolveRootWidget(t)?.widget??null:this._app.get_active_window()?.get_focus()??null,!a)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${t||`focus`}'`));return sendKeyToWidget(a,r,i??0)}DumpGSettings(e){return JSON.stringify(dumpGSettings(e))}DumpCss(){return JSON.stringify(dumpCss())}SwapCss(e,t){return this._guard(`SwapCss`),swapCss(e,t)}_resolveRootWidget(e){if(isActiveWindowScope(e)){let e=this._app.get_active_window();return e?{widget:e,path:pathOfWidget(e)??`toplevel:0`}:null}let t=resolveWidgetPath(e);return t?{widget:t,path:e}:null}_isPaused(){return this._options.paused?.()??!1}_guard(e){let t=this._kinds.get(e);if(!t)throw Error(formatDbusErrorMessage(`internal`,`unclassified devtools method '${e}'`));if(t===`mutating`&&this._isPaused())throw Error(formatDbusErrorMessage(`paused`,`${e} rejected — external control is paused. Read-only methods keep working.`))}_scope(e){return e===`app`?`app`:`win`}_actionGroup(e){if(e===`app`)return this._app;if(this._options.winActionGroup)return this._options.winActionGroup;let t=this._app.get_active_window();return t instanceof Sn.ApplicationWindow?t:null}_requireGroup(e,t){let n=this._actionGroup(e);if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no '${e}' action group`));if(!n.has_action(t))throw Error(formatDbusErrorMessage(`not-found`,`unknown action ${e}.${t}`));return n}_parseValue(e){if(!e||e===`null`)return null;try{return JSON.parse(e)}catch{throw Error(formatDbusErrorMessage(`invalid-params`,`value_json is not valid JSON: ${e}`))}}};const An=`DBUS_SESSION_BUS_ADDRESS`,jn=new Set;function envEnabled(){return isDevtoolsEnabledValue(gt.getenv(`GJSIFY_DEVTOOLS`))}function envValue(e){let t=gt.getenv(e);return t&&t!==``?t:null}function sessionBusUsable(){if(!envValue(An))return!1;try{return pt.bus_get_sync(pt.BusType.SESSION,null),!0}catch{return!1}}function chooseDevtoolsTransport(e){return e.requestedAddress?{kind:`peer`,address:e.requestedAddress,reason:`requested`}:e.hasAppConnection?{kind:`session-bus`}:e.sessionBusUsable?{kind:`unregistered`}:{kind:`peer`,address:null,reason:`no-session-bus`}}function describeMissingConnection(e,t){return e?t?`[gjsify-devtools] the session bus answers but this application is not registered on it yet — call installDevtools() from the GtkApplication "startup" handler (the bus connection and object path exist only after registration).`:`[gjsify-devtools] ${An} is set (${e}) but no bus answers there — using the bus-less peer transport instead. On macOS this is the usual state: Homebrew's dbus listens on launchd, so the advertised address only works while that socket is live.`:`[gjsify-devtools] this machine has no session bus (${An} is unset) — using the bus-less peer transport instead. Point the bridge at the address below, or set ${En} on both the app and \`gjsify debug\` to pin it yourself.`}function installDevtools(e,t={}){if(!(t.enabled??envEnabled()))return null;let n=t.instance??envValue(`GJSIFY_DEVTOOLS_INSTANCE`)??void 0,r=new DevtoolsService(e,{...t,instance:n});try{return exportDevtools(e,r,t,n)}catch(e){return r.unexport(),console.error(`[gjsify-devtools] devtools stayed OFF, the app is unaffected — ${describeInstallFailure(e)}`),null}}function describeInstallFailure(e){return e instanceof DevtoolsPeerServerError||e instanceof Error?e.message:String(e)}function exportDevtools(e,t,n,r){let i=e.get_is_registered(),a=i?e.get_dbus_connection():null,o=i?e.get_dbus_object_path():null,s=envValue(An),c=!!(a&&o),l=c||sessionBusUsable(),u=chooseDevtoolsTransport({requestedAddress:n.address??envValue(En),hasAppConnection:c,sessionBusUsable:l}),d=e.get_application_id()??`unknown`,f=`${o??appIdToObjectPath(d)}/devtools`;if((u.kind===`unregistered`||u.kind===`peer`&&u.reason===`no-session-bus`)&&console.error(describeMissingConnection(s,l)),u.kind===`session-bus`&&a)t.export(a,f),console.log(`[gjsify-devtools] exported ${wn} at ${f} (dest ${d})`);else if(u.kind===`peer`){let n=startDevtoolsPeerServer(t,f,u.address??void 0),i=writeDevtoolsAddressFile(devtoolsAddressFilePath(gt.get_user_runtime_dir(),d,r),n.address);t.attachPeerServer(n,i),console.log(`[gjsify-devtools] exported ${wn} at ${f} (peer address ${n.address}${i?`, published to ${i}`:``})`),i&&e.connect(`shutdown`,()=>removeDevtoolsAddressFile(i))}return jn.add(t),t}const Mn=e(import.meta.url);let Nn;function load$1(){return Nn===void 0&&(Nn=Mn(`@gjsify/node-gi/gi`).requireGi(`GObject`,`2.0`)),Nn}__name$1(load$1,`load`);var Pn=new Proxy(Object.create(null),{get(e,t){return load$1()[t]},has(e,t){return t in load$1()}}),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._)}},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}},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)}},WebGLProgram$1=class extends Linkable{static{__name$1(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$1(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)}},WebGLShaderPrecisionFormat=class{constructor(e){this.rangeMin=e.rangeMin,this.rangeMax=e.rangeMax,this.precision=e.precision}},WebGLActiveInfo=class{constructor(e){this.size=e.size,this.type=e.type,this.name=e.name}},EXTBlendMinMax=class{constructor(){this.MIN_EXT=32775,this.MAX_EXT=32776}};function getEXTBlendMinMax(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`EXT_blend_minmax`)>=0&&(t=new EXTBlendMinMax),t}var EXTColorBufferFloat=class{};function getEXTColorBufferFloat(e){let t=e.getSupportedExtensions();return t&&t.indexOf(`EXT_color_buffer_float`)>=0?new EXTColorBufferFloat:null}var EXTColorBufferHalfFloat=class{};function getEXTColorBufferHalfFloat(e){let t=e.getSupportedExtensions();return t&&t.indexOf(`EXT_color_buffer_half_float`)>=0?new EXTColorBufferHalfFloat:null}var EXTTextureFilterAnisotropic=class{constructor(){this.TEXTURE_MAX_ANISOTROPY_EXT=34046,this.MAX_TEXTURE_MAX_ANISOTROPY_EXT=34047}};function getEXTTextureFilterAnisotropic(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`EXT_texture_filter_anisotropic`)>=0&&(t=new EXTTextureFilterAnisotropic),t}var OESElementIndexUint=class{};function getOESElementIndexUint(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_element_index_uint`)>=0&&(t=new OESElementIndexUint),t}var OESStandardDerivatives=class{constructor(){this.FRAGMENT_SHADER_DERIVATIVE_HINT_OES=35723}};function getOESStandardDerivatives(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_standard_derivatives`)>=0&&(t=new OESStandardDerivatives),t}var OESTextureFloatLinear=class{};function getOESTextureFloatLinear(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_texture_float_linear`)>=0&&(t=new OESTextureFloatLinear),t}var OESTextureFloat=class{};function getOESTextureFloat(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_texture_float`)>=0&&(t=new OESTextureFloat),t}var OESTextureHalfFloat=class{constructor(){this.HALF_FLOAT_OES=36193}};function getOESTextureHalfFloat(e){let t=e.getSupportedExtensions();return t&&t.indexOf(`OES_texture_half_float`)>=0||e._native2?new OESTextureHalfFloat:null}var STACKGLDestroyContext=class{constructor(e){this.destroy=e.destroy.bind(e)}};function getSTACKGLDestroyContext(e){return new STACKGLDestroyContext(e)}var STACKGLResizeDrawingBuffer=class{constructor(e){this.resize=e.resize.bind(e)}};function getSTACKGLResizeDrawingBuffer(e){return new STACKGLResizeDrawingBuffer(e)}var WEBGLDebugRendererInfo=class{constructor(){this.UNMASKED_VENDOR_WEBGL=37445,this.UNMASKED_RENDERER_WEBGL=37446}};function getWEBGLDebugRendererInfo(e){return new WEBGLDebugRendererInfo}var WebGLContextAttributes=class{constructor(e,t,n,r,i,a,o,s){this.alpha=e,this.depth=t,this.stencil=n,this.antialias=r,this.premultipliedAlpha=i,this.preserveDrawingBuffer=a,this.preferLowPowerToHighPerformance=o,this.failIfMajorPerformanceCaveat=s}},WebGLTextureUnit=class{constructor(e,t){this._mode=0,this._bind2D=null,this._bindCube=null,this._ctx=e,this._idx=t}},WebGLVertexArrayObjectAttribute=class{constructor(e,t){this._isPointer=!1,this._pointerBuffer=null,this._pointerOffset=0,this._pointerSize=0,this._pointerStride=0,this._pointerType=0,this._pointerNormal=!1,this._divisor=0,this._inputSize=4,this._inputStride=0,this._ctx=e,this._idx=t,this._pointerType=e.FLOAT,this._clear()}_clear(){this._isPointer=!1,this._pointerBuffer=null,this._pointerOffset=0,this._pointerSize=0,this._pointerStride=0,this._pointerType=this._ctx.FLOAT,this._pointerNormal=!1,this._divisor=0,this._inputSize=4,this._inputStride=0}},WebGLVertexArrayGlobalAttribute=class{constructor(e){this._idx=0,this._idx=e,this._data=new Float32Array([0,0,0,1])}},WebGLVertexArrayObjectState=class{constructor(e){this._elementArrayBufferBinding=null;let t=e.getParameter(e.MAX_VERTEX_ATTRIBS);this._attribs=Array.from({length:t});for(let n=0;n<t;++n)this._attribs[n]=new WebGLVertexArrayObjectAttribute(e,n);this._elementArrayBufferBinding=null}setElementArrayBuffer(e){if(e!==null&&!(e instanceof WebGLBuffer))throw TypeError(`setElementArrayBuffer(WebGLBuffer?)`);let t=this._elementArrayBufferBinding;t!==e&&(t&&(--t._refCount,t._checkDelete()),e&&(e._refCount+=1),this._elementArrayBufferBinding=e)}cleanUp(){let e=this._elementArrayBufferBinding;e&&(--e._refCount,e._checkDelete(),this._elementArrayBufferBinding=null);for(let e=0;e<this._attribs.length;++e){let t=this._attribs[e];t._pointerBuffer&&(--t._pointerBuffer._refCount,t._pointerBuffer._checkDelete()),t._clear()}}releaseArrayBuffer(e){if(e)for(let t=0;t<this._attribs.length;++t){let n=this._attribs[t];n._pointerBuffer===e&&(--n._pointerBuffer._refCount,n._pointerBuffer._checkDelete(),n._clear())}}setVertexAttribPointer(e,t,n,r,i,a,o,s,c){let l=this._attribs[t];e!==l._pointerBuffer&&(l._pointerBuffer&&(--l._pointerBuffer._refCount,l._pointerBuffer._checkDelete()),e&&(e._refCount+=1),l._pointerBuffer=e),l._pointerSize=n,l._pointerOffset=r,l._pointerStride=i,l._pointerType=a,l._pointerNormal=o,l._inputStride=s,l._inputSize=c}},WebGLVertexArrayGlobalState=class{constructor(e){this._arrayBufferBinding=null;let t=e.getParameter(e.MAX_VERTEX_ATTRIBS);this._attribs=Array.from({length:t});for(let e=0;e<t;++e)this._attribs[e]=new WebGLVertexArrayGlobalAttribute(e);this._arrayBufferBinding=null}setArrayBuffer(e){if(e!==null&&!(e instanceof WebGLBuffer))throw TypeError(`setArrayBuffer(WebGLBuffer?)`);let t=this._arrayBufferBinding;t!==e&&(t&&(--t._refCount,t._checkDelete()),e&&(e._refCount+=1),this._arrayBufferBinding=e)}};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$1(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 Zt.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}const Fn={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,Fn)}const In={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()){console.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||t===this.VERTEX_ATTRIB_ARRAY_DIVISOR)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,In)}const Ln={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,Ln)}const Rn={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,Rn)}const zn={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,zn)}const Bn={texImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c){let l=0,u=0,d=0,f,p,m=0;if(arguments.length===6)if(s=i,d=r,a instanceof St.Pixbuf)p=a,l=p.get_width(),u=p.get_height(),c=p.get_pixels();else{f=a;let e=extractImageData(f);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);l=e.width,u=e.height,c=e.data}else arguments.length===9&&(l=r,u=i,m=a,d=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,d)||!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 h=this._getTexImage(e);if(!h||d!==n){this.setError(this.INVALID_OPERATION);return}let g=this._computePixelSize(s,d);if(g===0||!this._checkDimensions(e,l,u,t))return;let _=convertPixels(c),v=this._computeRowStride(l,g),y=v*u;if(_&&_.length<y){this.setError(this.INVALID_OPERATION);return}if(m!==0||validCubeTarget(this,e)&&l!==u){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&_&&d===this.RGBA&&(_=premultiplyAlpha(_)),this._unpackFlipY&&_&&l>0&&u>0){let e=new Uint8Array(_.length);for(let t=0;t<u;t++){let n=t*v,r=(u-1-t)*v;e.set(_.subarray(n,n+v),r)}_=e}this._saveError(),this._gl.texImage2D(e,t,n,l,u,m,d,s,Uint8ArrayToVariant(_));let b=this.getError();if(this._restoreError(b),b!==this.NO_ERROR)return;h._levelWidth[t]=l,h._levelHeight[t]=u,h._format=d,h._type=s;let x=this._activeFramebuffer;if(x){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(x._attachments[t[n]]===h){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 l=0,u=0,d=0,f,p;if(arguments.length===7)if(s=a,d=i,o instanceof St.Pixbuf)p=o,l=p.get_width(),u=p.get_height(),c=p.get_pixels();else{f=o;let e=extractImageData(f);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);l=e.width,u=e.height,c=e.data}else l=i,u=a,d=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 m=this._computePixelSize(s,d);if(m===0||!this._checkDimensions(e,l,u,t))return;if(n<0||r<0){this.setError(this.INVALID_VALUE);return}let h=convertPixels(c),g=this._computeRowStride(l,m),_=g*u;if(!h||h.length<_){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&h&&d===this.RGBA&&(h=premultiplyAlpha(h)),this._unpackFlipY&&h&&l>0&&u>0){let e=new Uint8Array(h.length);for(let t=0;t<u;t++){let n=t*g,r=(u-1-t)*g;e.set(h.subarray(n,n+g),r)}h=e}this._gl.texSubImage2D(e,t,n,r,l,u,d,s,Uint8ArrayToVariant(h))}};function installTexImage2DMethods(e){Object.assign(e,Bn)}var Vn=__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 Hn={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&&!(Vn.isPow2(a)&&Vn.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,Hn)}const Un={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,Un)}const Wn={_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,Wn)}function installTextureManagementMethods(e){installTextureLifecycleMethods(e),installTexImage2DMethods(e),installCopyAndCompressedTextureMethods(e),installTextureParameterMethods(e),installTextureIntrospectionMethods(e)}var Gn=__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(`.`)})),Kn=__commonJSMin(((e,t)=>{t.exports=`<<= >>= ++ -- << >> <= >= == != && || += -= *= /= %= &= ^^ ^= |= ( ) [ ] . ! ~ * / % + - < > & ^ | ? : = , ; { }`.split(` `)})),qn=__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(`.`)})),Jn=__commonJSMin(((e,t)=>{t.exports=Gn().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(`.`))})),Yn=__commonJSMin(((e,t)=>{var n=qn();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(`.`))})),Xn=__commonJSMin(((e,t)=>{t.exports=tokenize;var n=Gn(),r=Kn(),i=qn(),a=Jn(),o=Yn(),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,k=0,A=0,ee=!1,te=!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:A,line:O,column:k})}function write(e){t=0,e.toString&&(e=e.toString()),j+=e.replace(/\r\n/g,`
77
+ </node>`}function isWin32(){return gt.DIR_SEPARATOR===92}function defaultListenAddress(){return isWin32()?`nonce-tcp:host=127.0.0.1`:`unix:tmpdir=${gt.get_tmp_dir()}`}var DevtoolsPeerServerError=class extends Error{constructor(e,t,n,r){super(e),this.address=t,this.reason=n,this.name=`DevtoolsPeerServerError`,this.cause=r}};function isAddressInUse(e){return e instanceof gt.Error&&e.matches(pt.io_error_quark(),pt.IOErrorEnum.ADDRESS_IN_USE)}function unixSocketPath(e){if(!e.startsWith(`unix:`))return null;for(let t of e.slice(5).split(`,`)){let e=t.indexOf(`=`);if(!(e<0||t.slice(0,e)!==`path`))try{return decodeURIComponent(t.slice(e+1))}catch{return null}}return null}function inspectExistingSocket(e){try{if((pt.File.new_for_path(e).query_info(`unix::mode`,pt.FileQueryInfoFlags.NONE,null).get_attribute_uint32(`unix::mode`)&61440)!=49152)return`not-a-socket`}catch{return`not-a-socket`}let t=new pt.SocketClient;t.set_timeout(2);let n;try{n=t.connect(pt.UnixSocketAddress.new(e),null)}catch{return`dead`}return n.close(null),`live`}function clearReclaimableSocket(e){let t=unixSocketPath(e);if(!t||!gt.file_test(t,gt.FileTest.EXISTS))return;let n=inspectExistingSocket(t);if(n===`live`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: another process is already listening there. Stop it, or point ${En} (or options.address) at a different socket — GJSIFY_DEVTOOLS_INSTANCE=<label> lets two devtools-enabled apps run side by side.`,e,`address-in-use`);if(n===`not-a-socket`)throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} already exists and is not a socket, so it will NOT be removed. Point ${En} (or options.address) at a free path.`,e,`occupied-by-other-file`);try{pt.File.new_for_path(t).delete(null)}catch(n){throw new DevtoolsPeerServerError(`cannot listen on ${e}: ${t} is a socket nothing listens on, but removing it failed (${n}). Delete it by hand, or point ${En} at a free path.`,e,`address-in-use`,n)}console.log(`[gjsify-devtools] reclaimed the stale socket ${t}: nothing was listening on it (an abnormal exit — Ctrl-C, SIGKILL, a crash — leaves the inode behind).`)}function flagsForAddress(e){return e.startsWith(`tcp:`)||e.startsWith(`nonce-tcp:`)?pt.DBusServerFlags.NONE:pt.DBusServerFlags.AUTHENTICATION_REQUIRE_SAME_USER}function startDevtoolsPeerServer(e,t,n){let r=n&&n!==``?n:defaultListenAddress();clearReclaimableSocket(r);let i;try{i=pt.DBusServer.new_sync(r,flagsForAddress(r),pt.dbus_generate_guid(),null,null)}catch(e){let t=isAddressInUse(e);throw new DevtoolsPeerServerError(t?`cannot listen on ${r}: the address is already in use (${e}). Stop whatever holds it, or point ${En} (or options.address) at a different address.`:`cannot listen on ${r}: ${e}. Check the address form — \`unix:path=/tmp/app.sock\`, \`unix:tmpdir=/tmp\` or \`nonce-tcp:host=127.0.0.1\`.`,r,t?`address-in-use`:`listen-failed`,e)}let a=new Set;i.connect(`new-connection`,(n,r)=>(a.add(r),r.connect(`closed`,()=>{e.unexport(r),a.delete(r)}),e.export(r,t),!0)),i.start();let o=!1;return{address:i.get_client_address(),objectPath:t,get connectionCount(){return a.size},stop(){if(!o){o=!0,i.stop();for(let t of a)e.unexport(t),!t.is_closed()&&t.close(null,(e,t)=>{try{e.close_finish(t)}catch{}});a.clear()}}}}function writeDevtoolsAddressFile(e,t){try{if(gt.mkdir_with_parents(gt.path_get_dirname(e),448),!gt.file_set_contents(e,`${t}\n`))return null}catch(t){return console.error(`[gjsify-devtools] could not publish the peer address to ${e}: ${t}`),null}try{pt.File.new_for_path(e).set_attribute_uint32(`unix::mode`,384,pt.FileQueryInfoFlags.NONE,null)}catch(t){console.error(`[gjsify-devtools] could not restrict ${e} to the current user: ${t}`)}return e}function removeDevtoolsAddressFile(e){try{pt.File.new_for_path(e).delete(null)}catch{}}const Dn=e(import.meta.url);let On;function load$2(){return On===void 0&&(On=Dn(`@gjsify/node-gi/gi`).requireGi(`Graphene`,`1.0`)),On}__name$1(load$2,`load`);var kn=new Proxy(Object.create(null),{get(e,t){return load$2()[t]},has(e,t){return t in load$2()}});function captureWidget(e){let t=e.get_native()?.get_renderer();if(!t)return{png:null,blocker:`no-renderer`};let n=e.get_width(),r=e.get_height();if(n<=0||r<=0)return{png:null,blocker:`zero-size`};let i=Sn.WidgetPaintable.new(e),a=Sn.Snapshot.new();i.snapshot(a,n,r);let o=a.to_node();if(!o)return{png:null,blocker:`empty-snapshot`};let s=new kn.Rect;s.init(0,0,n,r);let c=t.render_texture(o,s).save_to_png_bytes().get_data();return c?{png:new Uint8Array(c)}:{png:null,blocker:`empty-png`}}function dumpGSettings(e){let t=pt.SettingsSchemaSource.get_default()?.lookup(e,!0);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`GSettings schema '${e}' is not installed`));let n=new pt.Settings({settings_schema:t}),r={};for(let e of t.list_keys())r[e]=n.get_value(e).recursiveUnpack();return r}const An=e(import.meta.url);let jn;function load$1(){return jn===void 0&&(jn=An(`@gjsify/node-gi/gi`).requireGi(`GObject`,`2.0`)),jn}__name$1(load$1,`load`);var Mn=new Proxy(Object.create(null),{get(e,t){return load$1()[t]},has(e,t){return t in load$1()}});function parseWidgetPath(e){let t=e.split(`/`).filter(e=>e.length>0);if(t.length===0)return null;let n=t[0].match(/^toplevel:(\d+)$/);if(!n)return null;let r=[];for(let e of t.slice(1)){let t=e.match(/^child:(\d+)$/);if(!t)return null;r.push(Number(t[1]))}return{toplevel:Number(n[1]),children:r}}function buildWidgetPath(e,t){return[`toplevel:${e}`,...t.map(e=>`child:${e}`)].join(`/`)}function widgetType(e){return gtypeName(e)??`GtkWidget`}function gtypeName(e){let t=e;return typeof t?.$typeName==`string`&&t.$typeName.length>0?t.$typeName:t?.constructor?.$gtype?.name??null}function widgetIsA(e,t){let n=gtypeName(e);if(n===null||!t)return!1;if(n===t)return!0;let r=Mn.type_from_name(n),i=Mn.type_from_name(t);return!r||!i?!1:Mn.type_is_a(r,i)}function activateWidget(e){let t=e;if(typeof t.activate==`function`&&t.activate()===!0)return!0;let n=typeof t.get_parent==`function`?t.get_parent():null;if(n&&widgetIsA(n,`GtkListBox`)){let t=n,r=!1;return typeof t.select_row==`function`&&(t.select_row(e),r=!0),typeof t.emit==`function`&&(t.emit(`row-activated`,e),r=!0),r}return!1}function sendKeyToWidget(e,t,n){let r=e.observe_controllers(),i=!1;for(let e=0;e<r.get_n_items();e++){let a=r.get_item(e);widgetIsA(a,`GtkEventControllerKey`)&&(a.emit(`key-pressed`,t,0,n),i=!0)}return i}function nthChild(e,t){let n=e.get_first_child(),r=0;for(;n&&r<t;)n=n.get_next_sibling(),r++;return r===t?n:null}function listToplevels(){let e=Sn.Window.get_toplevels(),t=e.get_n_items(),n=[];for(let r=0;r<t;r++){let t=e.get_item(r);t&&n.push({path:`toplevel:${r}`,type:widgetType(t),title:t.get_title?.()??null,mapped:t.get_mapped(),focused:t.is_active??!1})}return n}function resolveWidgetPath(e){let t=parseWidgetPath(e);if(!t)return null;let n=Sn.Window.get_toplevels().get_item(t.toplevel);if(!n)return null;for(let e of t.children)if(n=nthChild(n,e),!n)return null;return n}function parseWidgetSelector(e){let t=e.indexOf(`:`),n=(t<0?e:e.slice(0,t)).trim(),r=(t<0?``:e.slice(t+1)).trim();return!n&&!r?null:{type:n,cssClass:r}}function findWidgetPath(e,t,n){let r={path:null};return walkForSelector(e,t,n,r)??r.path}function walkForSelector(e,t,n,r){if(!e.get_visible()||!e.get_mapped())return null;if(!t.cssClass||e.get_css_classes().includes(t.cssClass)){if(!t.type||widgetType(e)===t.type)return n;r.path===null&&widgetIsA(e,t.type)&&(r.path=n)}let i=e.get_first_child(),a=0;for(;i;){let e=walkForSelector(i,t,`${n}/child:${a}`,r);if(e)return e;i=i.get_next_sibling(),a++}return null}function geometryOf(e){if(!e.get_mapped())return;let t=e.get_allocation(),n=t.width+e.get_margin_start()+e.get_margin_end(),r=t.height+e.get_margin_top()+e.get_margin_bottom(),[i,a]=e.measure(Sn.Orientation.HORIZONTAL,-1),o=n>0?Math.max(n,i):-1,[s,c]=e.measure(Sn.Orientation.VERTICAL,o),l={width:n,height:r,widthRequest:[i,a],heightRequest:[s,c]};return(n<i||r<s)&&(l.short=!0),l}function dumpTree(e,t,n){let r={path:n,type:widgetType(e),name:e.get_name()||null,cssClasses:e.get_css_classes(),mapped:e.get_mapped(),visible:e.get_visible(),children:[]},i=geometryOf(e);if(i!==void 0&&(r.geometry=i),t<=0)return e.get_first_child()&&(r.truncated=!0),r;let a=e.get_first_child(),o=0;for(;a;)r.children.push(dumpTree(a,t-1,`${n}/child:${o}`)),a=a.get_next_sibling(),o++;return r}function jsonSafe(e){let t=typeof e;return e==null||t===`string`||t===`number`||t===`boolean`?e??null:`[${t}]`}function getWidgetProperty(e,t){let n=e,r=t.replace(/-/g,`_`),i=t.replace(/[-_]([a-z])/g,(e,t)=>t.toUpperCase());for(let e of[t,r,i])if(e in n)return jsonSafe(n[e])}function childIndex(e,t){let n=e.get_first_child(),r=0;for(;n;){if(n===t)return r;n=n.get_next_sibling(),r++}return-1}function pathOfWidget(e){let t=[],n=e,r=n.get_parent();for(;r;){let e=childIndex(r,n);if(e<0)return null;t.unshift(e),n=r,r=n.get_parent()}let i=Sn.Window.get_toplevels(),a=i.get_n_items();for(let e=0;e<a;e++)if(i.get_item(e)===n)return buildWidgetPath(e,t);return null}function isActiveWindowScope(e){return!e||e===`window`||e===`active`}function frameDelay(e){return new Promise(t=>{gt.timeout_add(gt.PRIORITY_DEFAULT,e,()=>(t(),gt.SOURCE_REMOVE))})}async function captureWidgetWhenRenderable(e,t=12,n=50){let r=null;for(let i=0;i<t;i++){let t=captureWidget(e);if(t.png)return{png:t.png,blocker:null};r=t.blocker,await frameDelay(n)}let i=captureWidget(e);return{png:i.png,blocker:i.png?null:i.blocker??r}}var DevtoolsService=class{constructor(e,t){this._app=e,this._options=t,this._exported=new Map,this._peer=null,this._addressFile=null,this._kinds=new Map,this._extensions=t.extend??[];for(let[e,t]of Object.entries(Tn))this._kinds.set(e,t);for(let e of this._extensions){for(let[t,n]of Object.entries(e.methodKinds))this._kinds.set(t,n);for(let[t,n]of Object.entries(e.handlers)){let e=n;this[t]=(...n)=>(this._guard(t),e(...n))}}}export(e,t){if(this._exported.has(e))return;let n=buildDevtoolsIfaceXml(this._extensions.flatMap(e=>e.methodsXml??[])),r=pt.DBusExportedObject.wrapJSObject(n,this);r.export(e,t),this._exported.set(e,r)}unexport(e){if(e){this._exported.get(e)?.unexport(),this._exported.delete(e);return}for(let e of this._exported.values())e.unexport();this._exported.clear(),this._peer?.stop(),this._peer=null,this._addressFile&&=(removeDevtoolsAddressFile(this._addressFile),null)}attachPeerServer(e,t){this._peer=e,this._addressFile=t??null}get peerAddress(){return this._peer?.address??null}get addressFile(){return this._addressFile}GetStatus(){let e=this._app.get_active_window(),t={appId:this._app.get_application_id()??`unknown`,instance:this._options.instance??`default`,activeWindow:e?{id:e.get_name()||`window`,title:e.get_title()??``,mapped:e.get_mapped()}:null,toplevelCount:Sn.Window.get_toplevels().get_n_items(),focusedWidget:null,paused:this._isPaused()};for(let e of this._extensions){let n=e.contributeStatus?.();n&&Object.assign(t,n)}return JSON.stringify(t)}async ScreenshotAsync(e,t){try{let n=typeof e?.[0]==`string`?e[0]:``,r=await this._captureScopePng(n);t.return_value(new gt.Variant(`(ay)`,[r]))}catch(e){t.return_dbus_error(`org.gjsify.Devtools.Error.Screenshot`,e instanceof Error?e.message:String(e))}}async _captureScopePng(e){let t=this._resolveRootWidget(e);if(!t){if(isActiveWindowScope(e))return new Uint8Array;throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`))}let n=captureWidget(t.widget);if(n.png)return n.png;let r=t.widget.get_root();r instanceof Sn.Window&&r.present();let i=await captureWidgetWhenRenderable(t.widget);return i.png?i.png:(console.warn(`[devtools] Screenshot('${e}') has no image: ${i.blocker??`unknown`} after 12 tries. Empty bytes follow.`),new Uint8Array)}ListActions(){let e={app:describeActions(this._actionGroup(`app`)),win:describeActions(this._actionGroup(`win`))};return JSON.stringify(e)}ActivateAction(e,t,n){this._guard(`ActivateAction`);let r=this._scope(e);activateAction(this._requireGroup(r,t),t,this._parseValue(n))}ChangeActionState(e,t,n){this._guard(`ChangeActionState`);let r=this._scope(e);changeActionState(this._requireGroup(r,t),t,this._parseValue(n))}PresentWindow(){this._app.get_active_window()?.present()}ResizeWindow(e,t){this._guard(`ResizeWindow`);let n=this._app.get_active_window();if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no active window to resize`));let r=Math.max(1,Math.round(e)),i=Math.max(1,Math.round(t));return n.is_maximized()&&n.unmaximize(),n.is_fullscreen()&&n.unfullscreen(),n.set_default_size(r,i),[r,i]}ListToplevels(){return JSON.stringify(listToplevels())}DumpTree(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e||`active window`}'`));return JSON.stringify(dumpTree(n.widget,t>0?t:40,n.path))}GetProperty(e,t){let n=this._resolveRootWidget(e);if(!n)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));let r=getWidgetProperty(n.widget,t);if(r===void 0)throw Error(formatDbusErrorMessage(`not-found`,`widget has no property '${t}'`));return JSON.stringify(r)}GetFocused(){let e=this._app.get_active_window(),t=e?e.get_focus():null;return JSON.stringify(t?{path:pathOfWidget(t),name:t.get_name()||null,type:widgetType(t)}:null)}ActivateWidget(e){this._guard(`ActivateWidget`);let t=this._resolveRootWidget(e);if(!t)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${e}'`));return activateWidget(t.widget)}FindWidget(e){let t=parseWidgetSelector(e);if(!t)throw Error(formatDbusErrorMessage(`invalid-params`,`empty selector '${e}'`));let n=this._resolveRootWidget(``);return n?findWidgetPath(n.widget,t,n.path)??``:``}SendKey(e,t){this._guard(`SendKey`);let[n,r,i]=Sn.accelerator_parse(e);if(!n)throw Error(formatDbusErrorMessage(`invalid-params`,`cannot parse accelerator '${e}'`));let a;if(a=t?this._resolveRootWidget(t)?.widget??null:this._app.get_active_window()?.get_focus()??null,!a)throw Error(formatDbusErrorMessage(`not-found`,`no widget at '${t||`focus`}'`));return sendKeyToWidget(a,r,i??0)}DumpGSettings(e){return JSON.stringify(dumpGSettings(e))}DumpCss(){return JSON.stringify(dumpCss())}SwapCss(e,t){return this._guard(`SwapCss`),swapCss(e,t)}_resolveRootWidget(e){if(isActiveWindowScope(e)){let e=this._app.get_active_window();return e?{widget:e,path:pathOfWidget(e)??`toplevel:0`}:null}let t=resolveWidgetPath(e);return t?{widget:t,path:e}:null}_isPaused(){return this._options.paused?.()??!1}_guard(e){let t=this._kinds.get(e);if(!t)throw Error(formatDbusErrorMessage(`internal`,`unclassified devtools method '${e}'`));if(t===`mutating`&&this._isPaused())throw Error(formatDbusErrorMessage(`paused`,`${e} rejected — external control is paused. Read-only methods keep working.`))}_scope(e){return e===`app`?`app`:`win`}_actionGroup(e){if(e===`app`)return this._app;if(this._options.winActionGroup)return this._options.winActionGroup;let t=this._app.get_active_window();return t instanceof Sn.ApplicationWindow?t:null}_requireGroup(e,t){let n=this._actionGroup(e);if(!n)throw Error(formatDbusErrorMessage(`unavailable`,`no '${e}' action group`));if(!n.has_action(t))throw Error(formatDbusErrorMessage(`not-found`,`unknown action ${e}.${t}`));return n}_parseValue(e){if(!e||e===`null`)return null;try{return JSON.parse(e)}catch{throw Error(formatDbusErrorMessage(`invalid-params`,`value_json is not valid JSON: ${e}`))}}};const Nn=`DBUS_SESSION_BUS_ADDRESS`,Pn=new Set;function envEnabled(){return isDevtoolsEnabledValue(gt.getenv(`GJSIFY_DEVTOOLS`))}function envValue(e){let t=gt.getenv(e);return t&&t!==``?t:null}function sessionBusUsable(){if(!envValue(Nn))return!1;try{return pt.bus_get_sync(pt.BusType.SESSION,null),!0}catch{return!1}}function chooseDevtoolsTransport(e){return e.requestedAddress?{kind:`peer`,address:e.requestedAddress,reason:`requested`}:e.hasAppConnection?{kind:`session-bus`}:e.sessionBusUsable?{kind:`unregistered`}:{kind:`peer`,address:null,reason:`no-session-bus`}}function describeMissingConnection(e,t){return e?t?`[gjsify-devtools] the session bus answers but this application is not registered on it yet — call installDevtools() from the GtkApplication "startup" handler (the bus connection and object path exist only after registration).`:`[gjsify-devtools] ${Nn} is set (${e}) but no bus answers there — using the bus-less peer transport instead. On macOS this is the usual state: Homebrew's dbus listens on launchd, so the advertised address only works while that socket is live.`:`[gjsify-devtools] this machine has no session bus (${Nn} is unset) — using the bus-less peer transport instead. Point the bridge at the address below, or set ${En} on both the app and \`gjsify debug\` to pin it yourself.`}function installDevtools(e,t={}){if(!(t.enabled??envEnabled()))return null;let n=t.instance??envValue(`GJSIFY_DEVTOOLS_INSTANCE`)??void 0,r=new DevtoolsService(e,{...t,instance:n});try{return exportDevtools(e,r,t,n)}catch(e){return r.unexport(),console.error(`[gjsify-devtools] devtools stayed OFF, the app is unaffected — ${describeInstallFailure(e)}`),null}}function describeInstallFailure(e){return e instanceof DevtoolsPeerServerError||e instanceof Error?e.message:String(e)}function exportDevtools(e,t,n,r){let i=e.get_is_registered(),a=i?e.get_dbus_connection():null,o=i?e.get_dbus_object_path():null,s=envValue(Nn),c=!!(a&&o),l=c||sessionBusUsable(),u=chooseDevtoolsTransport({requestedAddress:n.address??envValue(En),hasAppConnection:c,sessionBusUsable:l}),d=e.get_application_id()??`unknown`,f=`${o??appIdToObjectPath(d)}/devtools`;if((u.kind===`unregistered`||u.kind===`peer`&&u.reason===`no-session-bus`)&&console.error(describeMissingConnection(s,l)),u.kind===`session-bus`&&a)t.export(a,f),console.log(`[gjsify-devtools] exported ${wn} at ${f} (dest ${d})`);else if(u.kind===`peer`){let n=startDevtoolsPeerServer(t,f,u.address??void 0),i=writeDevtoolsAddressFile(devtoolsAddressFilePath(gt.get_user_runtime_dir(),d,r),n.address);t.attachPeerServer(n,i),console.log(`[gjsify-devtools] exported ${wn} at ${f} (peer address ${n.address}${i?`, published to ${i}`:``})`),i&&e.connect(`shutdown`,()=>removeDevtoolsAddressFile(i))}return Pn.add(t),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._)}},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}},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)}},WebGLProgram$1=class extends Linkable{static{__name$1(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$1(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)}},WebGLShaderPrecisionFormat=class{constructor(e){this.rangeMin=e.rangeMin,this.rangeMax=e.rangeMax,this.precision=e.precision}},WebGLActiveInfo=class{constructor(e){this.size=e.size,this.type=e.type,this.name=e.name}},EXTBlendMinMax=class{constructor(){this.MIN_EXT=32775,this.MAX_EXT=32776}};function getEXTBlendMinMax(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`EXT_blend_minmax`)>=0&&(t=new EXTBlendMinMax),t}var EXTColorBufferFloat=class{};function getEXTColorBufferFloat(e){let t=e.getSupportedExtensions();return t&&t.indexOf(`EXT_color_buffer_float`)>=0?new EXTColorBufferFloat:null}var EXTColorBufferHalfFloat=class{};function getEXTColorBufferHalfFloat(e){let t=e.getSupportedExtensions();return t&&t.indexOf(`EXT_color_buffer_half_float`)>=0?new EXTColorBufferHalfFloat:null}var EXTTextureFilterAnisotropic=class{constructor(){this.TEXTURE_MAX_ANISOTROPY_EXT=34046,this.MAX_TEXTURE_MAX_ANISOTROPY_EXT=34047}};function getEXTTextureFilterAnisotropic(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`EXT_texture_filter_anisotropic`)>=0&&(t=new EXTTextureFilterAnisotropic),t}var OESElementIndexUint=class{};function getOESElementIndexUint(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_element_index_uint`)>=0&&(t=new OESElementIndexUint),t}var OESStandardDerivatives=class{constructor(){this.FRAGMENT_SHADER_DERIVATIVE_HINT_OES=35723}};function getOESStandardDerivatives(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_standard_derivatives`)>=0&&(t=new OESStandardDerivatives),t}var OESTextureFloatLinear=class{};function getOESTextureFloatLinear(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_texture_float_linear`)>=0&&(t=new OESTextureFloatLinear),t}var OESTextureFloat=class{};function getOESTextureFloat(e){let t=null,n=e.getSupportedExtensions();return n&&n.indexOf(`OES_texture_float`)>=0&&(t=new OESTextureFloat),t}var OESTextureHalfFloat=class{constructor(){this.HALF_FLOAT_OES=36193}};function getOESTextureHalfFloat(e){let t=e.getSupportedExtensions();return t&&t.indexOf(`OES_texture_half_float`)>=0||e._native2?new OESTextureHalfFloat:null}var STACKGLDestroyContext=class{constructor(e){this.destroy=e.destroy.bind(e)}};function getSTACKGLDestroyContext(e){return new STACKGLDestroyContext(e)}var STACKGLResizeDrawingBuffer=class{constructor(e){this.resize=e.resize.bind(e)}};function getSTACKGLResizeDrawingBuffer(e){return new STACKGLResizeDrawingBuffer(e)}var WEBGLDebugRendererInfo=class{constructor(){this.UNMASKED_VENDOR_WEBGL=37445,this.UNMASKED_RENDERER_WEBGL=37446}};function getWEBGLDebugRendererInfo(e){return new WEBGLDebugRendererInfo}var WebGLContextAttributes=class{constructor(e,t,n,r,i,a,o,s){this.alpha=e,this.depth=t,this.stencil=n,this.antialias=r,this.premultipliedAlpha=i,this.preserveDrawingBuffer=a,this.preferLowPowerToHighPerformance=o,this.failIfMajorPerformanceCaveat=s}},WebGLTextureUnit=class{constructor(e,t){this._mode=0,this._bind2D=null,this._bindCube=null,this._ctx=e,this._idx=t}},WebGLVertexArrayObjectAttribute=class{constructor(e,t){this._isPointer=!1,this._pointerBuffer=null,this._pointerOffset=0,this._pointerSize=0,this._pointerStride=0,this._pointerType=0,this._pointerNormal=!1,this._divisor=0,this._inputSize=4,this._inputStride=0,this._ctx=e,this._idx=t,this._pointerType=e.FLOAT,this._clear()}_clear(){this._isPointer=!1,this._pointerBuffer=null,this._pointerOffset=0,this._pointerSize=0,this._pointerStride=0,this._pointerType=this._ctx.FLOAT,this._pointerNormal=!1,this._divisor=0,this._inputSize=4,this._inputStride=0}},WebGLVertexArrayGlobalAttribute=class{constructor(e){this._idx=0,this._idx=e,this._data=new Float32Array([0,0,0,1])}},WebGLVertexArrayObjectState=class{constructor(e){this._elementArrayBufferBinding=null;let t=e.getParameter(e.MAX_VERTEX_ATTRIBS);this._attribs=Array.from({length:t});for(let n=0;n<t;++n)this._attribs[n]=new WebGLVertexArrayObjectAttribute(e,n);this._elementArrayBufferBinding=null}setElementArrayBuffer(e){if(e!==null&&!(e instanceof WebGLBuffer))throw TypeError(`setElementArrayBuffer(WebGLBuffer?)`);let t=this._elementArrayBufferBinding;t!==e&&(t&&(--t._refCount,t._checkDelete()),e&&(e._refCount+=1),this._elementArrayBufferBinding=e)}cleanUp(){let e=this._elementArrayBufferBinding;e&&(--e._refCount,e._checkDelete(),this._elementArrayBufferBinding=null);for(let e=0;e<this._attribs.length;++e){let t=this._attribs[e];t._pointerBuffer&&(--t._pointerBuffer._refCount,t._pointerBuffer._checkDelete()),t._clear()}}releaseArrayBuffer(e){if(e)for(let t=0;t<this._attribs.length;++t){let n=this._attribs[t];n._pointerBuffer===e&&(--n._pointerBuffer._refCount,n._pointerBuffer._checkDelete(),n._clear())}}setVertexAttribPointer(e,t,n,r,i,a,o,s,c){let l=this._attribs[t];e!==l._pointerBuffer&&(l._pointerBuffer&&(--l._pointerBuffer._refCount,l._pointerBuffer._checkDelete()),e&&(e._refCount+=1),l._pointerBuffer=e),l._pointerSize=n,l._pointerOffset=r,l._pointerStride=i,l._pointerType=a,l._pointerNormal=o,l._inputStride=s,l._inputSize=c}},WebGLVertexArrayGlobalState=class{constructor(e){this._arrayBufferBinding=null;let t=e.getParameter(e.MAX_VERTEX_ATTRIBS);this._attribs=Array.from({length:t});for(let e=0;e<t;++e)this._attribs[e]=new WebGLVertexArrayGlobalAttribute(e);this._arrayBufferBinding=null}setArrayBuffer(e){if(e!==null&&!(e instanceof WebGLBuffer))throw TypeError(`setArrayBuffer(WebGLBuffer?)`);let t=this._arrayBufferBinding;t!==e&&(t&&(--t._refCount,t._checkDelete()),e&&(e._refCount+=1),this._arrayBufferBinding=e)}};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$1(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 Zt.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}const Fn={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,Fn)}const In={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()){console.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||t===this.VERTEX_ATTRIB_ARRAY_DIVISOR)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,In)}const Ln={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,Ln)}const Rn={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,Rn)}const zn={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,zn)}const Bn={texImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c){let l=0,u=0,d=0,f,p,m=0;if(arguments.length===6)if(s=i,d=r,a instanceof St.Pixbuf)p=a,l=p.get_width(),u=p.get_height(),c=p.get_pixels();else{f=a;let e=extractImageData(f);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);l=e.width,u=e.height,c=e.data}else arguments.length===9&&(l=r,u=i,m=a,d=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,d)||!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 h=this._getTexImage(e);if(!h||d!==n){this.setError(this.INVALID_OPERATION);return}let g=this._computePixelSize(s,d);if(g===0||!this._checkDimensions(e,l,u,t))return;let _=convertPixels(c),v=this._computeRowStride(l,g),y=v*u;if(_&&_.length<y){this.setError(this.INVALID_OPERATION);return}if(m!==0||validCubeTarget(this,e)&&l!==u){this.setError(this.INVALID_VALUE);return}if(this._unpackPremultAlpha&&_&&d===this.RGBA&&(_=premultiplyAlpha(_)),this._unpackFlipY&&_&&l>0&&u>0){let e=new Uint8Array(_.length);for(let t=0;t<u;t++){let n=t*v,r=(u-1-t)*v;e.set(_.subarray(n,n+v),r)}_=e}this._saveError(),this._gl.texImage2D(e,t,n,l,u,m,d,s,Uint8ArrayToVariant(_));let b=this.getError();if(this._restoreError(b),b!==this.NO_ERROR)return;h._levelWidth[t]=l,h._levelHeight[t]=u,h._format=d,h._type=s;let x=this._activeFramebuffer;if(x){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(x._attachments[t[n]]===h){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 l=0,u=0,d=0,f,p;if(arguments.length===7)if(s=a,d=i,o instanceof St.Pixbuf)p=o,l=p.get_width(),u=p.get_height(),c=p.get_pixels();else{f=o;let e=extractImageData(f);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);l=e.width,u=e.height,c=e.data}else l=i,u=a,d=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 m=this._computePixelSize(s,d);if(m===0||!this._checkDimensions(e,l,u,t))return;if(n<0||r<0){this.setError(this.INVALID_VALUE);return}let h=convertPixels(c),g=this._computeRowStride(l,m),_=g*u;if(!h||h.length<_){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&h&&d===this.RGBA&&(h=premultiplyAlpha(h)),this._unpackFlipY&&h&&l>0&&u>0){let e=new Uint8Array(h.length);for(let t=0;t<u;t++){let n=t*g,r=(u-1-t)*g;e.set(h.subarray(n,n+g),r)}h=e}this._gl.texSubImage2D(e,t,n,r,l,u,d,s,Uint8ArrayToVariant(h))}};function installTexImage2DMethods(e){Object.assign(e,Bn)}var Vn=__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 Hn={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&&!(Vn.isPow2(a)&&Vn.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,Hn)}const Un={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,Un)}const Wn={_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,Wn)}function installTextureManagementMethods(e){installTextureLifecycleMethods(e),installTexImage2DMethods(e),installCopyAndCompressedTextureMethods(e),installTextureParameterMethods(e),installTextureIntrospectionMethods(e)}var Gn=__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(`.`)})),Kn=__commonJSMin(((e,t)=>{t.exports=`<<= >>= ++ -- << >> <= >= == != && || += -= *= /= %= &= ^^ ^= |= ( ) [ ] . ! ~ * / % + - < > & ^ | ? : = , ; { }`.split(` `)})),qn=__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(`.`)})),Jn=__commonJSMin(((e,t)=>{t.exports=Gn().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(`.`))})),Yn=__commonJSMin(((e,t)=>{var n=qn();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(`.`))})),Xn=__commonJSMin(((e,t)=>{t.exports=tokenize;var n=Gn(),r=Kn(),i=qn(),a=Jn(),o=Yn(),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,k=0,A=0,ee=!1,te=!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:A,line:O,column:k})}function write(e){t=0,e.toString&&(e=e.toString()),j+=e.replace(/\r\n/g,`
78
78
  `),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`
79
79
  `:k=0,++O;break;default:++k;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===`*`?(A=S+t-1,C=l,T=w,t+1):T===`/`&&w===`/`?(A=S+t-1,C=u,T=w,t+1):w===`#`?(C=d,A=S+t,t):/\s/.test(w)?(C=v,A=S+t,t):(ee=/\d/.test(w),te=/[^\w_]/.test(w),A=S+t,C=ee?p:te?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===`
80
80
  `)&&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),A+=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}}})),Zn=__toESM(__commonJSMin(((e,t)=>{var n=Xn();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 Qn=/\b(attribute|varying|gl_FragColor|gl_FragData|texture2D|texture2DProj|textureCube)\b/,$n=new RegExp([String.raw`^\s*(?:flat\s+|smooth\s+|centroid\s+)*(?:in|out)\s+\w+\s+\w+\s*;`,String.raw`\blayout\s*\(`,String.raw`\b(?:texture|textureProj|textureLod|textureProjLod|textureGrad|textureProjGrad|texelFetch|texelFetchOffset|textureSize|textureOffset)\s*\(`,String.raw`\b(?:isampler|usampler)(?:2D|3D|Cube|2DArray)\b`,String.raw`\b(?:uint|uvec[234])\b`,String.raw`\b(?:gl_VertexID|gl_InstanceID|gl_FragDepth)\b`].join(`|`),`m`);function glslDialectOf(e){return Qn.test(e)?`glsl1`:$n.test(e)?`modern`:`glsl1`}const er={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,Zn.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,Zn.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(`
@@ -84,7 +84,7 @@ import{createRequire as e}from"node:module";import t from"@gjsify/node-gi/cairo"
84
84
  `),n){if(i){let e=t.indexOf(`
85
85
  `);t=e===-1?t+`
86
86
  `+i:t.slice(0,e+1)+i+t.slice(e+1)}}else if(this.canvas){let e=this.canvas.getGlArea().get_use_es(),n=r===`glsl1`?this._getGlsl1Version(e):this._getGlslVersion(e);n?t=`#version `+n+`
87
- `+i+t:i&&(t=i+t)}else i&&(t=i+t);return t}};function installShaderLifecycleMethods(e){Object.assign(e,er)}const tr={createProgram(){let e=this._gl.createProgram();if(e<=0)return null;let t=new WebGLProgram$1(e,this);return this._programs[e]=t,t},deleteProgram(e){this._deleteLinkable(`deleteProgram`,e,WebGLProgram$1)},useProgram(e){if(!checkObject(e))throw TypeError(`useProgram(WebGLProgram)`);if(e)this._checkWrapper(e,WebGLProgram$1)&&(this._activeProgram!==e&&(this._switchActiveProgram(this._activeProgram),this._activeProgram=e,e._refCount+=1),this._gl.useProgram(e._|0));else{this._switchActiveProgram(this._activeProgram),this._activeProgram=null,this._gl.useProgram(0);return}},linkProgram(e){if(!checkObject(e))throw TypeError(`linkProgram(WebGLProgram)`);if(this._checkWrapper(e,WebGLProgram$1)){e._linkCount+=1,e._attributes=[];let t=this.getError();for(let t of e._references)t instanceof WebGLShader$1&&t._needsRecompile&&(this._gl.compileShader(t._|0),t._needsRecompile=!1);this._gl.linkProgram(e._|0);let n=this.getError();n===this.NO_ERROR&&(e._linkStatus=this._fixupLink(e)),this.getError(),this.setError(t||n)}},validateProgram(e){if(this._checkWrapper(e,WebGLProgram$1)){this._gl.validateProgram(e._|0);let t=this.getError();t===this.NO_ERROR&&(e._linkInfoLog=this._gl.getProgramInfoLog(e._|0)),this.getError(),this.setError(t)}},attachShader(e,t){if(!checkObject(e)||!checkObject(t))throw TypeError(`attachShader(WebGLProgram, WebGLShader)`);if(!e||!t){this.setError(this.INVALID_VALUE);return}else if(e instanceof WebGLProgram$1&&t instanceof WebGLShader$1&&this._checkOwns(e)&&this._checkOwns(t)&&!e._linked(t)){this._saveError(),this._gl.attachShader(e._|0,t._|0);let n=this.getError();this._restoreError(n),n===this.NO_ERROR&&e._link(t);return}this.setError(this.INVALID_OPERATION)},detachShader(e,t){if(!checkObject(e)||!checkObject(t))throw TypeError(`detachShader(WebGLProgram, WebGLShader)`);this._checkWrapper(e,WebGLProgram$1)&&this._checkWrapper(t,WebGLShader$1)&&(e._linked(t)?(this._gl.detachShader(e._,t._),e._unlink(t)):this.setError(this.INVALID_OPERATION))},bindAttribLocation(e,t,n){if(!checkObject(e)||typeof n!=`string`)throw TypeError(`bindAttribLocation(WebGLProgram, GLint, String)`);n+=``,!isValidString(n)||n.length>256?this.setError(this.INVALID_VALUE):/^_?webgl_a/.test(n)?this.setError(this.INVALID_OPERATION):this._checkWrapper(e,WebGLProgram$1)&&this._gl.bindAttribLocation(e._|0,t|0,n)},getAttachedShaders(e){if(!checkObject(e)||typeof e==`object`&&e&&!(e instanceof WebGLProgram$1))throw TypeError(`getAttachedShaders(WebGLProgram)`);if(!e)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(e,WebGLProgram$1))return e._references.filter(e=>e instanceof WebGLShader$1);return null},getProgramInfoLog(e){if(!checkObject(e))throw TypeError(`getProgramInfoLog(WebGLProgram)`);return this._checkWrapper(e,WebGLProgram$1)?e._linkInfoLog:null},getProgramParameter(e,t=0){if(!checkObject(e))throw TypeError(`getProgramParameter(WebGLProgram, GLenum)`);if(this._checkWrapper(e,WebGLProgram$1)){switch(t){case this.DELETE_STATUS:return e._pendingDelete;case this.LINK_STATUS:return e._linkStatus;case this.VALIDATE_STATUS:return!!this._gl.getProgramParameter(e._,t);case this.ATTACHED_SHADERS:return this._gl.getProgramParameter(e._,t);case this.ACTIVE_ATTRIBUTES:return e._linkStatus?e._attributes.length:this._gl.getProgramParameter(e._,t);case this.ACTIVE_UNIFORMS:return e._linkStatus?e._uniforms.length:this._gl.getProgramParameter(e._,t)}this.setError(this.INVALID_ENUM)}return null},_switchActiveProgram(e){e&&(--e._refCount,e._checkDelete())},_fixupLink(e){if(!this._gl.getProgramParameter(e._,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let t=this.getProgramParameter(e,this.ACTIVE_ATTRIBUTES),n=Array.from({length:t});e._attributes.length=t;for(let r=0;r<t;++r)n[r]=this.getActiveAttrib(e,r)?.name,e._attributes[r]=this.getAttribLocation(e,n[r])|0;for(let t=0;t<n.length;++t)if(n[t].length>256)return e._linkInfoLog=`attribute `+n[t]+` is too long`,!1;for(let r=0;r<t;++r)e._attributes[r]<0||this._gl.bindAttribLocation(e._|0,e._attributes[r],n[r]);if(this._gl.linkProgram(e._|0),!this._gl.getProgramParameter(e._|0,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let r=this.getProgramParameter(e,this.ACTIVE_UNIFORMS);e._uniforms.length=r;for(let t=0;t<r;++t){let n=this.getActiveUniform(e,t);n&&(e._uniforms[t]=n)}for(let t=0;t<e._uniforms.length;++t)if(e._uniforms[t].name.length>256)return e._linkInfoLog=`uniform `+e._uniforms[t].name+` is too long`,!1;return e._linkInfoLog=``,!0},_deleteLinkable(e,t,n){if(!checkObject(t))throw TypeError(e+`(`+n.name+`)`);if(t instanceof n&&this._checkOwns(t)){t._pendingDelete=!0,t._checkDelete();return}this.setError(this.INVALID_OPERATION)}};function installProgramLifecycleMethods(e){Object.assign(e,tr)}const nr={getActiveAttrib(e,t){if(!checkObject(e))throw TypeError(`getActiveAttrib(WebGLProgram)`);if(!e)throw TypeError(`getActiveAttrib(WebGLProgram, GLuint)`);if(this._checkWrapper(e,WebGLProgram$1)){if(t>=(e._linkStatus?e._attributes.length:this._gl.getProgramParameter(e._|0,this.ACTIVE_ATTRIBUTES)))return this._gl.getError(),this.setError(this.INVALID_VALUE),null;let n=this._gl.getActiveAttrib(e._|0,t|0);if(n)return new WebGLActiveInfo(n)}return null},getActiveUniform(e,t){if(!checkObject(e))throw TypeError(`getActiveUniform(WebGLProgram, GLint)`);if(!e)throw TypeError(`getActiveUniform(WebGLProgram, GLuint)`);if(this._checkWrapper(e,WebGLProgram$1)){if(t>=(e._linkStatus?e._uniforms.length:this._gl.getProgramParameter(e._|0,this.ACTIVE_UNIFORMS)))return this.setError(this.INVALID_VALUE),null;let n=this._gl.getActiveUniform(e._|0,t|0);if(n)return new WebGLActiveInfo(n)}return null},getAttribLocation(e,t){if(!checkObject(e))throw TypeError(`getAttribLocation(WebGLProgram, String)`);if(t+=``,!isValidString(t)||t.length>256)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(e,WebGLProgram$1))return this._gl.getAttribLocation(e._|0,t+``);return-1},getUniform(e,t){if(!checkObject(e)||!checkObject(t))throw TypeError(`getUniform(WebGLProgram, WebGLUniformLocation)`);if(!e)return this.setError(this.INVALID_VALUE),null;if(!t)return null;if(this._checkWrapper(e,WebGLProgram$1)){if(!checkUniform(e,t))return this.setError(this.INVALID_OPERATION),null;let n=this._gl.getUniform(e._|0,t._|0);if(!n)return null;switch(t._activeInfo.type){case this.FLOAT:return n[0];case this.FLOAT_VEC2:return new Float32Array(n.slice(0,2));case this.FLOAT_VEC3:return new Float32Array(n.slice(0,3));case this.FLOAT_VEC4:return new Float32Array(n.slice(0,4));case this.INT:return n[0]|0;case this.INT_VEC2:return new Int32Array(n.slice(0,2));case this.INT_VEC3:return new Int32Array(n.slice(0,3));case this.INT_VEC4:return new Int32Array(n.slice(0,4));case this.BOOL:return!!n[0];case this.BOOL_VEC2:return[!!n[0],!!n[1]];case this.BOOL_VEC3:return[!!n[0],!!n[1],!!n[2]];case this.BOOL_VEC4:return[!!n[0],!!n[1],!!n[2],!!n[3]];case this.FLOAT_MAT2:return new Float32Array(n.slice(0,4));case this.FLOAT_MAT3:return new Float32Array(n.slice(0,9));case this.FLOAT_MAT4:return new Float32Array(n.slice(0,16));case this.SAMPLER_2D:case this.SAMPLER_CUBE:return n[0]|0;default:return null}}return null},getUniformLocation(e,t){if(!checkObject(e))throw TypeError(`getUniformLocation(WebGLProgram, String)`);if(t+=``,!isValidString(t))return this.setError(this.INVALID_VALUE),null;if(this._checkWrapper(e,WebGLProgram$1)){let n=this._gl.getUniformLocation(e._|0,t);if(n!==null&&n>=0){let r=t;/\[\d+\]$/.test(t)&&(r=t.replace(/\[\d+\]$/,`[0]`));let i=r+`[0]`,a=null;for(let t=0;t<e._uniforms.length;++t){let n=e._uniforms[t];if(n.name===r||n.name===i){a={size:n.size,type:n.type,name:n.name};break}}a||={name:r,type:0,size:1};let o=new WebGLUniformLocation(n,e,a),s=t.match(/\[(\d+)\]$/),c=s?+s[1]:-1;if(a.name.endsWith(`[0]`)&&(c===-1||c===0)){let t=a.name.replace(/\[0\]$/,``),n=[];this._saveError();for(let r=0;this.getError()===this.NO_ERROR;++r){let i=this._gl.getUniformLocation(e._|0,t+`[`+r+`]`);if(this.getError()!==this.NO_ERROR||i==null||i<0)break;n.push(i)}this._restoreError(this.NO_ERROR),o._array=n}else if(c>0&&c>=a.size)return null;return o}}return null}};function installIntrospectionMethods(e){Object.assign(e,nr)}const rr={uniform1f(e,t){this._checkUniformValid(e,t,`uniform1f`,1,`f`)&&this._gl.uniform1f(e?._||0,t)},uniform1i(e,t){this._gl.uniform1i(e?._||0,t)},uniform2f(e,t,n){this._checkUniformValid(e,t,`uniform2f`,2,`f`)&&this._gl.uniform2f(e?._||0,t,n)},uniform2i(e,t,n){this._checkUniformValid(e,t,`uniform2i`,2,`i`)&&this._gl.uniform2i(e?._||0,t,n)},uniform3f(e,t,n,r){this._checkUniformValid(e,t,`uniform3f`,3,`f`)&&this._gl.uniform3f(e?._||0,t,n,r)},uniform3i(e,t,n,r){this._checkUniformValid(e,t,`uniform3i`,3,`i`)&&this._gl.uniform3i(e?._||0,t,n,r)},uniform4f(e,t,n,r,i){if(!this._checkUniformValid(e,t,`uniform4f`,4,`f`)){console.error(`uniform4f is not valid!`);return}this._gl.uniform4f(e?._||0,t,n,r,i)},uniform4i(e,t,n,r,i){this._checkUniformValid(e,t,`uniform4i`,4,`i`)&&this._gl.uniform4i(e?._||0,t,n,r,i)},uniform1fv(e,t){if(!(!e||!this._checkUniformValueValid(e,t,`uniform1fv`,1,`f`))){if(e?._array){let n=e._array;for(let e=0;e<n.length&&e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform1f(r,t[e])}return}this._gl.uniform1f(e?._|0,t[0])}},uniform1iv(e,t){if(this._checkUniformValueValid(e,t,`uniform1iv`,1,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform1i(r,t[e])}return}this.uniform1i(e,t[0])}},uniform2fv(e,t){if(this._checkUniformValueValid(e,t,`uniform2fv`,2,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&2*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform2f(r,t[2*e],t[2*e+1])}return}this._gl.uniform2f(e?._||0,t[0],t[1])}},uniform2iv(e,t){if(this._checkUniformValueValid(e,t,`uniform2iv`,2,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&2*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform2i(r,t[2*e],t[2*e+1])}return}this.uniform2i(e,t[0],t[1])}},uniform3fv(e,t){if(this._checkUniformValueValid(e,t,`uniform3fv`,3,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&3*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform3f(r,t[3*e],t[3*e+1],t[3*e+2])}return}this._gl.uniform3f(e?._||0,t[0],t[1],t[2])}},uniform3iv(e,t){if(this._checkUniformValueValid(e,t,`uniform3iv`,3,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&3*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform3i(r,t[3*e],t[3*e+1],t[3*e+2])}return}this.uniform3i(e,t[0],t[1],t[2])}},uniform4fv(e,t){if(this._checkUniformValueValid(e,t,`uniform4fv`,4,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&4*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform4f(r,t[4*e],t[4*e+1],t[4*e+2],t[4*e+3])}return}this._gl.uniform4f(e?._||0,t[0],t[1],t[2],t[3])}},uniform4iv(e,t){if(this._checkUniformValueValid(e,t,`uniform4iv`,4,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&4*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform4i(r,t[4*e],t[4*e+1],t[4*e+2],t[4*e+3])}return}this.uniform4i(e,t[0],t[1],t[2],t[3])}},uniformMatrix2fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix2fv`,2))return;let r=new Float32Array(n);this._gl.uniformMatrix2fv(e?._||0,!!t,listToArray(r))},uniformMatrix3fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix3fv`,3))return;let r=new Float32Array(n);this._gl.uniformMatrix3fv(e?._||0,!!t,listToArray(r))},uniformMatrix4fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix4fv`,4))return;let r=new Float32Array(n);this._gl.uniformMatrix4fv(e?._||0,!!t,listToArray(r))},_checkLocation(e){return e instanceof WebGLUniformLocation?e._program._ctx!==this||e._linkCount!==e._program._linkCount?(this.setError(this.INVALID_OPERATION),!1):!0:(this.setError(this.INVALID_VALUE),!1)},_checkLocationActive(e){return e&&this._checkLocation(e)?e._program===this._activeProgram?!0:(this.setError(this.INVALID_OPERATION),!1):!1},_checkUniformValid(e,t,n,r,i){if(!checkObject(e))throw TypeError(`${n}(WebGLUniformLocation, ...)`);if(!e)return!1;if(this._checkLocationActive(e)){let n=e._activeInfo.type;if(n===this.SAMPLER_2D||n===this.SAMPLER_CUBE){if(r!==1)return this.setError(this.INVALID_VALUE),!1;if(i!==`i`)return this.setError(this.INVALID_OPERATION),!1;if(t<0||t>=this._textureUnits.length)return this.setError(this.INVALID_VALUE),!1}return uniformTypeSize(this,n)>r?(this.setError(this.INVALID_OPERATION),!1):!0}return!1},_checkUniformValueValid(e,t,n,r,i){if(!checkObject(e)||!checkObject(t))throw TypeError(`${n}v(WebGLUniformLocation, Array)`);if(!e||!this._checkLocationActive(e))return!1;if(typeof t!=`object`||!t||typeof t.length!=`number`)throw TypeError(`Second argument to ${n} must be array`);return uniformTypeSize(this,e._activeInfo.type)>r?(this.setError(this.INVALID_OPERATION),!1):t.length>=r&&t.length%r===0?e._array||t.length===r?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)},_checkUniformMatrix(e,t,n,r,i){if(!checkObject(e)||typeof n!=`object`)throw TypeError(r+`(WebGLUniformLocation, Boolean, Array)`);return t||typeof n!=`object`||!n||!n.length||n.length%i*i!==0?(this.setError(this.INVALID_VALUE),!1):!e||!this._checkLocationActive(e)?!1:n.length===i*i||e._array?!0:(this.setError(this.INVALID_VALUE),!1)}};function installUniformsMethods(e){Object.assign(e,rr)}function installShaderProgramMethods(e){installShaderLifecycleMethods(e),installProgramLifecycleMethods(e),installIntrospectionMethods(e),installUniformsMethods(e)}function installAllContextMethods(e){installStateMethods(e),installBufferBindingMethods(e),installTextureManagementMethods(e),installFramebufferMethods(e),installShaderProgramMethods(e),installDrawingMethods(e)}const ir=e(import.meta.url);let ar;function load(){return ar===void 0&&(ar=ir(`@gjsify/node-gi/gi`).requireGi(`Gwebgl`,`0.1`)),ar}var or=new Proxy(Object.create(null),{get(e,t){return load()[t]},has(e,t){return t in load()}});let sr=0;const cr={oes_element_index_uint:getOESElementIndexUint,oes_texture_float:getOESTextureFloat,oes_texture_float_linear:getOESTextureFloatLinear,oes_standard_derivatives:getOESStandardDerivatives,stackgl_destroy_context:getSTACKGLDestroyContext,stackgl_resize_drawingbuffer:getSTACKGLResizeDrawingBuffer,ext_blend_minmax:getEXTBlendMinMax,ext_color_buffer_float:getEXTColorBufferFloat,ext_color_buffer_half_float:getEXTColorBufferHalfFloat,ext_texture_filter_anisotropic:getEXTTextureFilterAnisotropic,oes_texture_half_float:getOESTextureHalfFloat,webgl_debug_renderer_info:getWEBGLDebugRendererInfo};var WebGLContextBase=class{get drawingBufferHeight(){return this.canvas.height||0}get drawingBufferWidth(){return this.canvas.width||0}constructor(e,t={}){this.drawingBufferColorSpace=`srgb`,this.unpackColorSpace=`srgb`,this.RGBA8=32856,this.DEFAULT_ATTACHMENTS=[],this.DEFAULT_COLOR_ATTACHMENTS=[],this._=0,this._extensions={},this._programs={},this._shaders={},this._textures={},this._framebuffers={},this._renderbuffers={},this._buffers={},this._activeProgram=null,this._activeFramebuffer=null,this._activeRenderbuffer=null,this._checkStencil=!1,this._stencilState=!0,this._activeTextureUnit=0,this._errorStack=[],this._maxTextureSize=0,this._maxTextureLevel=0,this._maxCubeMapSize=0,this._maxCubeMapLevel=0,this._maxRenderbufferSize=0,this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this._viewport=new Int32Array([0,0,0,0]),this._scissorBox=new Int32Array([0,0,0,0]),this._gtkFboId=0,this._textureUnits=[],this._drawingBuffer=null,this.canvas=e,this._contextAttributes=new WebGLContextAttributes(flag(t,`alpha`,!0),flag(t,`depth`,!0),flag(t,`stencil`,!1),!1,flag(t,`premultipliedAlpha`,!0),flag(t,`preserveDrawingBuffer`,!1),flag(t,`preferLowPowerToHighPerformance`,!1),flag(t,`failIfMajorPerformanceCaveat`,!1)),this._contextAttributes.premultipliedAlpha=this._contextAttributes.premultipliedAlpha&&this._contextAttributes.alpha}_init(){let e=this._gl.getParameterx(36006);this._gtkFboId=e?.deepUnpack()|0,this._initGLConstants(),this.DEFAULT_ATTACHMENTS=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT],this.DEFAULT_COLOR_ATTACHMENTS=[this.COLOR_ATTACHMENT0];let t=this.drawingBufferWidth||0,n=this.drawingBufferHeight||0;this._=sr++;let r=this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);this._textureUnits=Array.from({length:r});for(let e=0;e<r;++e)this._textureUnits[e]=new WebGLTextureUnit(this,e);this.activeTexture(this.TEXTURE0),this._defaultVertexObjectState=new WebGLVertexArrayObjectState(this),this._vertexObjectState=this._defaultVertexObjectState,this._vertexGlobalState=new WebGLVertexArrayGlobalState(this),this._maxTextureSize=this.getParameter(this.MAX_TEXTURE_SIZE),this._maxTextureLevel=Vn.log2(Vn.nextPow2(this._maxTextureSize)),this._maxCubeMapSize=this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE),this._maxCubeMapLevel=Vn.log2(Vn.nextPow2(this._maxCubeMapSize)),this._maxRenderbufferSize=this.getParameter(this.MAX_RENDERBUFFER_SIZE),this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this.bindBuffer(this.ARRAY_BUFFER,null),this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this.bindFramebuffer(this.FRAMEBUFFER,null),this.bindRenderbuffer(this.RENDERBUFFER,null),this.viewport(0,0,t,n),this.scissor(0,0,t,n),this.clearDepth(1),this.clearColor(0,0,0,0),this.clearStencil(0),this.clear(this.COLOR_BUFFER_BIT|this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),this.disable(this.DEPTH_TEST),this.disable(this.STENCIL_TEST),this.disable(this.BLEND),this.disable(this.CULL_FACE),this.disable(this.POLYGON_OFFSET_FILL),this.disable(this.SCISSOR_TEST),this._gl.colorMask(!0,!0,!0,!0)}_initGLConstants(){let e=new or.WebGLRenderingContextBase().get_webgl_constants();for(let[t,n]of Object.entries(e))Object.defineProperty(this,t,{value:n})}_getGlslVersion(e){return this._getGlsl1Version(e)}_getGlsl1Version(e){return e||this._atLeastGlVersion(4,1)?`100`:`120`}_desktopGlslVersion(){let e=this._gl.getString(35724);if(!e||e.startsWith(`OpenGL ES `))return`130`;let[t,n]=e.split(`.`,2).map(e=>Number.parseInt(e,10));return!Number.isFinite(t)||!Number.isFinite(n)?`130`:String(t*100+(n>=10?n:n*10))}_atLeastGlVersion(e,t){let n=this._gl.getString(7938);if(!n||n.startsWith(`OpenGL ES `))return!1;let[r,i]=n.split(`.`,2).map(e=>Number.parseInt(e,10));return!Number.isFinite(r)||!Number.isFinite(i)?!1:r>e||r===e&&i>=t}_checkOwns(e){return typeof e==`object`&&!!e&&e._ctx===this}_checkValid(e,t){return e instanceof t&&e._!==0}_checkWrapper(e,t){return this._checkValid(e,t)?this._checkOwns(e)?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)}_isObject(e,t,n){if(e!=null&&!(e instanceof n))throw TypeError(t+`(`+n.name+`)`);return!!(this._checkValid(e,n)&&this._checkOwns(e))}_checkStencilState(){return this._checkStencil?(this._checkStencil=!1,this._stencilState=!0,(this.getParameter(this.STENCIL_WRITEMASK)!==this.getParameter(this.STENCIL_BACK_WRITEMASK)||this.getParameter(this.STENCIL_VALUE_MASK)!==this.getParameter(this.STENCIL_BACK_VALUE_MASK)||this.getParameter(this.STENCIL_REF)!==this.getParameter(this.STENCIL_BACK_REF))&&(this.setError(this.INVALID_OPERATION),this._stencilState=!1),this._stencilState):this._stencilState}_validGLSLIdentifier(e){return!(e.indexOf(`webgl_`)===0||e.indexOf(`_webgl_`)===0||e.length>256)}_getParameterDirect(e){return this._gl.getParameterx(e)?.deepUnpack()}getContextAttributes(){return this._contextAttributes}getExtension(e){let t=e.toLowerCase();if(t in this._extensions)return this._extensions[t];let n=cr[t]?cr[t](this):null;return n&&(this._extensions[t]=n),n}getSupportedExtensions(){let e=[`ANGLE_instanced_arrays`,`STACKGL_resize_drawingbuffer`,`STACKGL_destroy_context`,`WEBGL_debug_renderer_info`],t=this._gl.getSupportedExtensions();return t?(t.indexOf(`GL_OES_element_index_uint`)>=0&&e.push(`OES_element_index_uint`),t.indexOf(`GL_OES_standard_derivatives`)>=0&&e.push(`OES_standard_derivatives`),t.indexOf(`GL_OES_texture_float`)>=0&&e.push(`OES_texture_float`),t.indexOf(`GL_OES_texture_float_linear`)>=0&&e.push(`OES_texture_float_linear`),(t.indexOf(`GL_OES_texture_half_float`)>=0||t.indexOf(`GL_ARB_half_float_pixel`)>=0)&&e.push(`OES_texture_half_float`),(t.indexOf(`GL_EXT_color_buffer_float`)>=0||t.indexOf(`GL_ARB_color_buffer_float`)>=0)&&e.push(`EXT_color_buffer_float`),t.indexOf(`GL_EXT_color_buffer_half_float`)>=0&&e.push(`EXT_color_buffer_half_float`),t.indexOf(`EXT_draw_buffers`)>=0&&e.push(`WEBGL_draw_buffers`),t.indexOf(`EXT_blend_minmax`)>=0&&e.push(`EXT_blend_minmax`),t.indexOf(`EXT_texture_filter_anisotropic`)>=0&&e.push(`EXT_texture_filter_anisotropic`),t.indexOf(`GL_OES_vertex_array_object`)>=0&&e.push(`OES_vertex_array_object`),e):e}getParameter(e=0){switch(e){case this.ARRAY_BUFFER_BINDING:return this._vertexGlobalState._arrayBufferBinding;case this.ELEMENT_ARRAY_BUFFER_BINDING:return this._vertexObjectState._elementArrayBufferBinding;case this.CURRENT_PROGRAM:return this._activeProgram;case this.FRAMEBUFFER_BINDING:return this._activeFramebuffer;case this.RENDERBUFFER_BINDING:return this._activeRenderbuffer;case this.TEXTURE_BINDING_2D:return this._getActiveTextureUnit()._bind2D;case this.TEXTURE_BINDING_CUBE_MAP:return this._getActiveTextureUnit()._bindCube;case this.VERSION:return`WebGL 1.0 0.0.1`;case this.VENDOR:return``;case this.RENDERER:return`ANGLE`;case 37445:return this._gl.getString(7936);case 37446:return this._gl.getString(7937);case this.SHADING_LANGUAGE_VERSION:return`WebGL GLSL ES 1.0 `;case this.COMPRESSED_TEXTURE_FORMATS:return new Uint32Array;case this.SCISSOR_BOX:return new Int32Array(this._scissorBox);case this.VIEWPORT:return new Int32Array(this._viewport);case this.MAX_VIEWPORT_DIMS:return new Int32Array([32767,32767]);case this.ALIASED_LINE_WIDTH_RANGE:case this.ALIASED_POINT_SIZE_RANGE:return new Float32Array([1,1]);case this.DEPTH_RANGE:return new Float32Array([0,1]);case this.BLEND_COLOR:case this.COLOR_CLEAR_VALUE:return new Float32Array(this._gl.getParameterfv(e,4));case this.COLOR_WRITEMASK:{let t=this._gl.getParameteriv(e,4);return[!!t[0],!!t[1],!!t[2],!!t[3]]}case this.DEPTH_CLEAR_VALUE:case this.LINE_WIDTH:case this.POLYGON_OFFSET_FACTOR:case this.POLYGON_OFFSET_UNITS:case this.SAMPLE_COVERAGE_VALUE:return this._gl.getParameterf(e);case this.BLEND:case this.CULL_FACE:case this.DEPTH_TEST:case this.DEPTH_WRITEMASK:case this.DITHER:case this.POLYGON_OFFSET_FILL:case this.SAMPLE_COVERAGE_INVERT:case this.SCISSOR_TEST:case this.STENCIL_TEST:case this.UNPACK_PREMULTIPLY_ALPHA_WEBGL:return!!this._gl.getParameteri(e);case this.UNPACK_FLIP_Y_WEBGL:return this._unpackFlipY;case this.ACTIVE_TEXTURE:case this.ALPHA_BITS:case this.BLEND_DST_ALPHA:case this.BLEND_DST_RGB:case this.BLEND_EQUATION_ALPHA:case this.BLEND_EQUATION_RGB:case this.BLEND_SRC_ALPHA:case this.BLEND_SRC_RGB:case this.BLUE_BITS:case this.CULL_FACE_MODE:case this.DEPTH_BITS:case this.DEPTH_FUNC:case this.FRONT_FACE:case this.GENERATE_MIPMAP_HINT:case this.GREEN_BITS:return this._gl.getParameteri(e);case this.MAX_RENDERBUFFER_SIZE:return this._maxRenderbufferSize;case this.MAX_COMBINED_TEXTURE_IMAGE_UNITS:case this.MAX_CUBE_MAP_TEXTURE_SIZE:case this.MAX_FRAGMENT_UNIFORM_VECTORS:case this.MAX_TEXTURE_IMAGE_UNITS:case this.MAX_TEXTURE_SIZE:case this.MAX_VARYING_VECTORS:case this.MAX_VERTEX_ATTRIBS:case this.MAX_VERTEX_TEXTURE_IMAGE_UNITS:case this.MAX_VERTEX_UNIFORM_VECTORS:case this.PACK_ALIGNMENT:case this.RED_BITS:case this.SAMPLE_BUFFERS:case this.SAMPLES:case this.STENCIL_BACK_FAIL:case this.STENCIL_BACK_FUNC:case this.STENCIL_BACK_PASS_DEPTH_FAIL:case this.STENCIL_BACK_PASS_DEPTH_PASS:case this.STENCIL_BACK_REF:case this.STENCIL_BACK_VALUE_MASK:case this.STENCIL_BACK_WRITEMASK:case this.STENCIL_BITS:case this.STENCIL_CLEAR_VALUE:case this.STENCIL_FAIL:case this.STENCIL_FUNC:case this.STENCIL_PASS_DEPTH_FAIL:case this.STENCIL_PASS_DEPTH_PASS:case this.STENCIL_REF:case this.STENCIL_VALUE_MASK:case this.STENCIL_WRITEMASK:case this.SUBPIXEL_BITS:case this.UNPACK_ALIGNMENT:case this.UNPACK_COLORSPACE_CONVERSION_WEBGL:return this._gl.getParameteri(e);case this.IMPLEMENTATION_COLOR_READ_FORMAT:case this.IMPLEMENTATION_COLOR_READ_TYPE:return this._getParameterDirect(e);default:if(this._extensions.webgl_draw_buffers){let t=this._extensions.webgl_draw_buffers;switch(e){case t.DRAW_BUFFER0_WEBGL:case t.DRAW_BUFFER1_WEBGL:case t.DRAW_BUFFER2_WEBGL:case t.DRAW_BUFFER3_WEBGL:case t.DRAW_BUFFER4_WEBGL:case t.DRAW_BUFFER5_WEBGL:case t.DRAW_BUFFER6_WEBGL:case t.DRAW_BUFFER7_WEBGL:case t.DRAW_BUFFER8_WEBGL:case t.DRAW_BUFFER9_WEBGL:case t.DRAW_BUFFER10_WEBGL:case t.DRAW_BUFFER11_WEBGL:case t.DRAW_BUFFER12_WEBGL:case t.DRAW_BUFFER13_WEBGL:case t.DRAW_BUFFER14_WEBGL:case t.DRAW_BUFFER15_WEBGL:return t._buffersState.length===1&&t._buffersState[0]===this.BACK?this.BACK:this._getParameterDirect(e);case t.MAX_DRAW_BUFFERS_WEBGL:case t.MAX_COLOR_ATTACHMENTS_WEBGL:return this._getParameterDirect(e)}}let t=this._extensions.oes_standard_derivatives;if(t&&e===t.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)return this._getParameterDirect(e);let n=this._extensions.ext_texture_filter_anisotropic;if(n&&e===n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)return this._getParameterDirect(e);let r=this._extensions.oes_vertex_array_object;return r&&e===r.VERTEX_ARRAY_BINDING_OES?r._activeVertexArrayObject:(this.setError(this.INVALID_ENUM),null)}}destroy(){warnNotImplemented(`destroy`)}};installAllContextMethods(WebGLContextBase.prototype);var WebGLRenderingContext$1=class extends WebGLContextBase{static{__name$1(this,`WebGLRenderingContext`)}get _gl(){return this._native}constructor(e,t={}){super(e,t),this._attrib0Buffer=null,this._native=new or.WebGLRenderingContext({}),this._init();let n=this.createBuffer();this._attrib0Buffer=n}_beginAttrib0Hack(){this._native.bindBuffer(this.ARRAY_BUFFER,this._attrib0Buffer?._||0);let e=new Uint8Array(this._vertexGlobalState._attribs[0]._data.buffer);this._native.bufferData(this.ARRAY_BUFFER,Uint8ArrayToVariant(e),this.STREAM_DRAW),this._native.enableVertexAttribArray(0),this._native.vertexAttribPointer(0,4,this.FLOAT,!1,0,0),this._native._vertexAttribDivisor(0,1)}_endAttrib0Hack(){let e=this._vertexObjectState._attribs[0];e._pointerBuffer?this._native.bindBuffer(this.ARRAY_BUFFER,e._pointerBuffer._):this._native.bindBuffer(this.ARRAY_BUFFER,0),this._native.vertexAttribPointer(0,e._inputSize,e._pointerType,e._pointerNormal,e._inputStride,e._pointerOffset),this._native._vertexAttribDivisor(0,e._divisor),this._native.disableVertexAttribArray(0),this._vertexGlobalState._arrayBufferBinding?this._native.bindBuffer(this.ARRAY_BUFFER,this._vertexGlobalState._arrayBufferBinding._):this._native.bindBuffer(this.ARRAY_BUFFER,0)}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;if(n>0&&(i=n+t-1>>>0),this._checkVertexAttribState(i)){let n=this._extensions.webgl_draw_buffers;if(this._vertexObjectState._attribs[0]._isPointer||n&&n._buffersState&&n._buffersState.length>0)return this._native.drawArrays(e,t,r);this._beginAttrib0Hack(),this._native._drawArraysInstanced(e,t,r,1),this._endAttrib0Hack()}}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}if(this._checkVertexAttribState(c)&&s>0){if(this._vertexObjectState._attribs[0]._isPointer)return this._native.drawElements(e,s,n,r);this._beginAttrib0Hack(),this._native._drawElementsInstanced(e,s,n,r,1),this._endAttrib0Hack()}}},WebGLQuery=class extends Linkable{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._queries[this._|0],e._native2.deleteQuery(this._|0)}},WebGLSampler=class extends Linkable{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._samplers[this._|0],e._native2.deleteSampler(this._|0)}},WebGLSync=class extends Linkable{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._syncs[this._|0],e._native2.deleteSync(this._|0)}},WebGLTransformFeedback=class extends Linkable{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._transformFeedbacks[this._|0],e._native2.deleteTransformFeedback(this._|0)}},WebGLVertexArrayObject=class extends Linkable{constructor(e,t){super(e),this._ctx=t,this._objectState=new WebGLVertexArrayObjectState(t)}_performDelete(){let e=this._ctx;e._vertexObjectState===this._objectState&&(e._vertexObjectState=e._defaultVertexObjectState),this._objectState.cleanUp(),delete e._vertexArrayObjects[this._|0],e._native2.deleteVertexArray(this._|0)}};const lr={createVertexArray(){let e=this._native2.createVertexArray();if(!e)return null;let t=new WebGLVertexArrayObject(e,this);return this._vertexArrayObjects[e]=t,t},deleteVertexArray(e){!e||!(e instanceof WebGLVertexArrayObject)||(e._pendingDelete=!0,e._checkDelete())},isVertexArray(e){return!e||!(e instanceof WebGLVertexArrayObject)?!1:this._native2.isVertexArray(e._)},bindVertexArray(e){e===null?(this._native2.bindVertexArray(0),this._vertexObjectState=this._defaultVertexObjectState):e instanceof WebGLVertexArrayObject?(this._native2.bindVertexArray(e._),this._vertexObjectState=e._objectState):this.setError(this.INVALID_OPERATION)},createQuery(){let e=this._native2.createQuery();if(!e)return null;let t=new WebGLQuery(e,this);return this._queries[e]=t,t},deleteQuery(e){!e||!(e instanceof WebGLQuery)||(e._pendingDelete=!0,e._checkDelete())},isQuery(e){return!e||!(e instanceof WebGLQuery)?!1:this._native2.isQuery(e._)},beginQuery(e,t){t instanceof WebGLQuery&&this._native2.beginQuery(e,t._)},endQuery(e){this._native2.endQuery(e)},getQuery(e,t){return warnNotImplemented(`WebGL2RenderingContext.getQuery`),null},getQueryParameter(e,t){return e instanceof WebGLQuery?this._native2.getQueryParameter(e._,t):null},createSampler(){let e=this._native2.createSampler();if(!e)return null;let t=new WebGLSampler(e,this);return this._samplers[e]=t,t},deleteSampler(e){!e||!(e instanceof WebGLSampler)||(e._pendingDelete=!0,e._checkDelete())},isSampler(e){return!e||!(e instanceof WebGLSampler)?!1:this._native2.isSampler(e._)},bindSampler(e,t){this._native2.bindSampler(e,t?t._:0)},samplerParameteri(e,t,n){e instanceof WebGLSampler&&this._native2.samplerParameteri(e._,t,n)},samplerParameterf(e,t,n){e instanceof WebGLSampler&&this._native2.samplerParameterf(e._,t,n)},getSamplerParameter(e,t){return e instanceof WebGLSampler?t===33082||t===33083?this._native2.getSamplerParameterf(e._,t):this._native2.getSamplerParameteri(e._,t):null},fenceSync(e,t){let n=this._native2.fenceSync(e,t);if(!n)return null;let r=new WebGLSync(n,this);return this._syncs[n]=r,r},isSync(e){return!e||!(e instanceof WebGLSync)?!1:this._native2.isSync(e._)},deleteSync(e){!e||!(e instanceof WebGLSync)||(e._pendingDelete=!0,e._checkDelete())},clientWaitSync(e,t,n){return e instanceof WebGLSync?this._native2.clientWaitSync(e._,t,n):37148},waitSync(e,t,n){e instanceof WebGLSync&&this._native2.waitSync(e._,t,n)},getSyncParameter(e,t){return e instanceof WebGLSync?this._native2.getSyncParameter(e._,t):null},createTransformFeedback(){let e=this._native2.createTransformFeedback();if(!e)return null;let t=new WebGLTransformFeedback(e,this);return this._transformFeedbacks[e]=t,t},deleteTransformFeedback(e){!e||!(e instanceof WebGLTransformFeedback)||(e._pendingDelete=!0,e._checkDelete())},isTransformFeedback(e){return!e||!(e instanceof WebGLTransformFeedback)?!1:this._native2.isTransformFeedback(e._)},bindTransformFeedback(e,t){this._native2.bindTransformFeedback(e,t?t._:0)},beginTransformFeedback(e){this._native2.beginTransformFeedback(e)},endTransformFeedback(){this._native2.endTransformFeedback()},pauseTransformFeedback(){this._native2.pauseTransformFeedback()},resumeTransformFeedback(){this._native2.resumeTransformFeedback()},transformFeedbackVaryings(e,t,n){this._native2.transformFeedbackVaryings(e._,t,n)},getTransformFeedbackVarying(e,t){let n=this._native2.getTransformFeedbackVarying(e._,t).deepUnpack();return new WebGLActiveInfo({size:n.size,type:n.type,name:n.name})}};function installObjectLifecycleMethods(e){Object.assign(e,lr)}const ur={texImage3D(e,t,n,r,i,a,o,s,c,l){l===null?this._native2.texImage3DNull(e,t,n,r,i,a,o,s,c):this._native2.texImage3D(e,t,n,r,i,a,o,s,c,Uint8ArrayToVariant(new Uint8Array(l.buffer,l.byteOffset,l.byteLength)))},texSubImage3D(e,t,n,r,i,a,o,s,c,l,u){u!==null&&this._native2.texSubImage3D(e,t,n,r,i,a,o,s,c,l,Uint8ArrayToVariant(new Uint8Array(u.buffer,u.byteOffset,u.byteLength)))},compressedTexImage3D(e,t,n,r,i,a,o,s,c){this._native2.compressedTexImage3D(e,t,n,r,i,a,o,Uint8ArrayToVariant(new Uint8Array(c.buffer,c.byteOffset,c.byteLength)))},compressedTexSubImage3D(e,t,n,r,i,a,o,s,c,l,u){this._native2.compressedTexSubImage3D(e,t,n,r,i,a,o,s,c,Uint8ArrayToVariant(new Uint8Array(u.buffer,u.byteOffset,u.byteLength)))},copyTexSubImage3D(e,t,n,r,i,a,o,s,c){this._native2.copyTexSubImage3D(e,t,n,r,i,a,o,s,c)},texStorage2D(e,t,n,r,i){this._native2.texStorage2D(e,t,n,r,i);let a=this._getTexImage(e);if(a){for(let e=0;e<t;e++)a._levelWidth[e]=Math.max(1,r>>e),a._levelHeight[e]=Math.max(1,i>>e);a._format=this.RGBA,a._type=this.UNSIGNED_BYTE}},texStorage3D(e,t,n,r,i,a){this._native2.texStorage3D(e,t,n,r,i,a)}};function installTexImage3DMethods(e){Object.assign(e,ur)}const dr={uniform1ui(e,t){e&&this._native2.uniform1ui(e._,t)},uniform2ui(e,t,n){e&&this._native2.uniform2ui(e._,t,n)},uniform3ui(e,t,n,r){e&&this._native2.uniform3ui(e._,t,n,r)},uniform4ui(e,t,n,r,i){e&&this._native2.uniform4ui(e._,t,n,r,i)},uniform1uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform1uiv(e._,i.length,i)},uniform2uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform2uiv(e._,i.length/2,i)},uniform3uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform3uiv(e._,i.length/3,i)},uniform4uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform4uiv(e._,i.length/4,i)},uniformMatrix2x3fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix2x3fv(e._,t,a)},uniformMatrix3x2fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix3x2fv(e._,t,a)},uniformMatrix2x4fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix2x4fv(e._,t,a)},uniformMatrix4x2fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix4x2fv(e._,t,a)},uniformMatrix3x4fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix3x4fv(e._,t,a)},uniformMatrix4x3fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix4x3fv(e._,t,a)}};function installUniformMethods(e){Object.assign(e,dr)}const fr={clearBufferfv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferfv==`function`){i.clearBufferfv(e,t,Array.from(n));return}let a=n;if(e===6144){let e=this.getParameter(this.COLOR_CLEAR_VALUE);this.clearColor(a[0]??0,a[1]??0,a[2]??0,a[3]??0),this.clear(this.COLOR_BUFFER_BIT),e&&this.clearColor(e[0],e[1],e[2],e[3])}else if(e===6145){let e=this.getParameter(this.DEPTH_CLEAR_VALUE);this.clearDepth(a[0]??1),this.clear(this.DEPTH_BUFFER_BIT),e!==null&&this.clearDepth(e)}},clearBufferiv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferiv==`function`){i.clearBufferiv(e,t,Array.from(n));return}if(e===6146){let e=n,t=this.getParameter(this.STENCIL_CLEAR_VALUE);this.clearStencil(e[0]??0),this.clear(this.STENCIL_BUFFER_BIT),t!==null&&this.clearStencil(t)}},clearBufferuiv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferuiv==`function`){i.clearBufferuiv(e,t,Array.from(n));return}},clearBufferfi(e,t,n,r){let i=this._native2;if(typeof i.clearBufferfi==`function`){i.clearBufferfi(e,t,n,r);return}if(e===34041){let e=this.getParameter(this.DEPTH_CLEAR_VALUE),t=this.getParameter(this.STENCIL_CLEAR_VALUE);this.clearDepth(n),this.clearStencil(r),this.clear(this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),e!==null&&this.clearDepth(e),t!==null&&this.clearStencil(t)}}};function installClearBufferMethods(e){Object.assign(e,fr)}function debugGlEnabled(){return globalThis.__GJSIFY_DEBUG_GL===!0}const pr={drawArraysInstanced(e,t,n,r){if(t<0||n<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=vertexCount(this,e,n);if(i<0){this.setError(this.INVALID_ENUM);return}if(this._framebufferOk()&&!(n===0||r===0)&&this._checkVertexAttribState(n+t-1>>>0)){if(debugGlEnabled()){let e=this,t=e.__drawInstCount=(e.__drawInstCount|0)+1;(t<=5||t%100==0)&&console.log(`[WebGL] drawArraysInstanced #${t} count=${i} instances=${r} fbo=${this._activeFramebuffer?._??`_gtkFbo`}`)}this._native2.drawArraysInstanced(e,t,i,r)}},drawElementsInstanced(e,t,n,r,i){if(t<0||r<0||i<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let a=this._vertexObjectState._elementArrayBufferBinding;if(!a){this.setError(this.INVALID_OPERATION);return}let o=null,s=r;if(n===this.UNSIGNED_SHORT){if(s%2){this.setError(this.INVALID_OPERATION);return}s>>=1,o=new Uint16Array(a._elements.buffer)}else if(n===this.UNSIGNED_INT){if(s%4){this.setError(this.INVALID_OPERATION);return}s>>=2,o=new Uint32Array(a._elements.buffer)}else if(n===this.UNSIGNED_BYTE)o=a._elements;else{this.setError(this.INVALID_ENUM);return}let c=t;switch(e){case this.TRIANGLES:t%3&&(c-=t%3);break;case this.LINES:t%2&&(c-=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(c===0||i===0){this._checkVertexAttribState(0);return}if(c+s>>>0>o.length){this.setError(this.INVALID_OPERATION);return}let l=0;for(let e=s;e<s+c;++e)o[e]>l&&(l=o[e]);this._checkVertexAttribState(l)&&this._native2.drawElementsInstanced(e,c,n,r,i)},vertexAttribDivisor(e,t){this._checkVertexIndex(e)&&(this._native2.vertexAttribDivisor(e,t),this._vertexObjectState._attribs[e]._divisor=t)},vertexAttribIPointer(e,t,n,r,i){this._native2.vertexAttribIPointer(e,t,n,r,i)},drawBuffers(e){let t=!1;for(let n=0;n<e.length;n++)if(e[n]===1029){t=!0;break}if(!t){this._native2.drawBuffers(e);return}this._native2.drawBuffers(e.map(e=>e===1029?this.COLOR_ATTACHMENT0:e))},drawRangeElements(e,t,n,r,i,a){if(r<0||a<0){this.setError(this.INVALID_VALUE);return}if(n<t){this.setError(this.INVALID_VALUE);return}this.drawElements(e,r,i,a)},blitFramebuffer(e,t,n,r,i,a,o,s,c,l){if(debugGlEnabled()){let e=this._gl.getError();e!==0&&console.log(`[WebGL] blitFramebuffer PRE-ERROR 0x${e.toString(16)}`)}if(this._native2.blitFramebuffer(e,t,n,r,i,a,o,s,c,l),debugGlEnabled()){let i=this._gl.getError(),a=this,o=a.__blitCount=(a.__blitCount|0)+1;o<=5&&console.log(`[WebGL] blitFramebuffer #${o} src=(${e},${t},${n},${r}) readFbo=${this._activeReadFramebuffer?._??`_gtkFbo`} err=${i===0?`OK`:`0x`+i.toString(16)}`)}},framebufferTextureLayer(e,t,n,r,i){this._native2.framebufferTextureLayer(e,t,n?n._:0,r,i)},invalidateFramebuffer(e,t){this._native2.invalidateFramebuffer(e,t)},invalidateSubFramebuffer(e,t,n,r,i,a){this._native2.invalidateSubFramebuffer(e,t,n,r,i,a)},readBuffer(e){this._native2.readBuffer(e)},renderbufferStorageMultisample(e,t,n,r,i){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let a=this._activeRenderbuffer;if(!a){this.setError(this.INVALID_OPERATION);return}this._saveError(),this._native2.renderbufferStorageMultisample(e,t,n,r,i);let o=this.getError();this._restoreError(o),o===this.NO_ERROR&&(a._width=r,a._height=i,a._format=n)}};function installInstancedAndFramebufferOpsMethods(e){Object.assign(e,pr)}var mr=class WebGL2RenderingContext extends WebGLContextBase{get _gl(){return this._native2}constructor(e,t={}){super(e,t),this._queries={},this._samplers={},this._transformFeedbacks={},this._vertexArrayObjects={},this._syncs={},this._activeReadFramebuffer=null,this._activeDrawFramebuffer=null,this._native2=new or.WebGL2RenderingContext({}),this._init()}_getGlslVersion(e){return e?`300 es`:this._desktopGlslVersion()}_validFramebufferAttachment(e){return super._validFramebufferAttachment(e)?!0:e>=36065&&e<=36079}static{this._WGL2_ALL_COLOR_ATTACHMENTS=[36064,36065,36066,36067,36068,36069,36070,36071,36072,36073,36074,36075,36076,36077,36078,36079]}_getColorAttachments(){return WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS}_preCheckFramebufferStatus(e){let t=e._attachments,n=0,r=0,i=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT,...WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS];for(let a of i){let i=t[a];if(i){if(i instanceof WebGLTexture){let t=e._attachmentLevel[a]??0,o=i._levelWidth[t]??0,s=i._levelHeight[t]??0;if(o>0&&s>0){n=o,r=s;break}}else if(i instanceof WebGLRenderbuffer&&i._width>0&&i._height>0){n=i._width,r=i._height;break}}}return n>0&&r>0?(e._width=n,e._height=r,this.FRAMEBUFFER_COMPLETE):this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT}_updateFramebufferAttachments(e){if(super._updateFramebufferAttachments(e),e)for(let t=1;t<=15;t++){let n=36064+t;if(!(n in e._attachments))continue;let r=e._attachments[n];if(r instanceof WebGLTexture){let t=e._attachmentFace[n]||this.TEXTURE_2D,i=e._attachmentLevel[n]??0;this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,t,r._|0,i|0)}else r instanceof WebGLRenderbuffer?this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,n,this.RENDERBUFFER,r._|0):this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,this.TEXTURE_2D,0,0)}}bindBuffer(e,t){if(e===35345||e===35982||e===36662||e===36663){let n=t?t._|0:0;this._gl.bindBuffer(e,n);return}super.bindBuffer(e,t)}bindFramebuffer(e,t){if(e===36008||e===36009){if(!checkObject(t))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(t&&t._pendingDelete||t&&!this._checkWrapper(t,WebGLFramebuffer))return;let n=t?t._|0:this._gtkFboId;if(this._gl.bindFramebuffer(e,n),e===36008){let e=this._activeReadFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeReadFramebuffer=t}else{let e=this._activeDrawFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeDrawFramebuffer=t,this._activeFramebuffer=t}return}super.bindFramebuffer(this.FRAMEBUFFER,t),this._activeReadFramebuffer=t,this._activeDrawFramebuffer=t}deleteFramebuffer(e){this._activeReadFramebuffer===e&&this.bindFramebuffer(36008,null),this._activeDrawFramebuffer===e&&this.bindFramebuffer(36009,null),super.deleteFramebuffer(e)}bufferData(e,t,n){let r=e===35345||e===35982||e===36662||e===36663,i=n===35041||n===35043||n===35045||n===35042||n===35044||n===35046?this.STATIC_DRAW:n;if(r){if(typeof t==`number`)t>=0&&this._gl.bufferDataSizeOnly(e,t,i);else if(typeof t==`object`&&t){let n=arrayToUint8Array(t);this._gl.bufferData(e,Uint8ArrayToVariant(n),i)}return}super.bufferData(e,t,i)}bufferSubData(e,t,n){if(e===35345||e===35982||e===36662||e===36663){if(t<0){this.setError(this.INVALID_VALUE);return}if(!n){this.setError(this.INVALID_VALUE);return}let r=arrayToUint8Array(n);this._gl.bufferSubData(e,t,Uint8ArrayToVariant(r));return}super.bufferSubData(e,t,n)}bindTexture(e,t){if(e===32879||e===35866){let n=t,r=n?n._|0:0;this._gl.bindTexture(e,r),n&&(n._binding=e);return}super.bindTexture(e,t)}texParameteri(e,t,n){if(e===32879||e===35866){this._gl.texParameteri(e,t,n);return}if(t===32882||t===34892||t===34893||t===33084||t===33085||t===33083||t===33082){this._gl.texParameteri(e,t,n);return}super.texParameteri(e,t,n)}drawArrays(e,t,n){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}this._framebufferOk()&&n!==0&&this._checkVertexAttribState(n+t-1>>>0)&&this._native2.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(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()||t===0)return;let c=0;for(let e=o;e<o+s;++e)e<a.length&&a[e]>c&&(c=a[e]);this._checkVertexAttribState(c)&&this._native2.drawElements(e,s,n,r)}bindBufferBase(e,t,n){this._native2.bindBufferBase(e,t,n?n._:0)}bindBufferRange(e,t,n,r,i){this._native2.bindBufferRange(e,t,n?n._:0,r,i)}copyBufferSubData(e,t,n,r,i){this._native2.copyBufferSubData(e,t,n,r,i)}getBufferSubData(e,t,n,r,i){let a=i===void 0?n.byteLength-(r??0):i,o=this._native2.getBufferSubData(e,t,a),s=new Uint8Array(n.buffer,n.byteOffset+(r??0)*(n instanceof Uint8Array?1:n.BYTES_PER_ELEMENT??1));s.set(o.subarray(0,s.byteLength))}texImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c){let l=0,u=0,d=0,f=0;if(arguments.length===6)if(s=i,d=r,a instanceof St.Pixbuf){let e=a;l=e.get_width(),u=e.get_height(),c=e.get_pixels()}else{let e=extractImageData(a);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);l=e.width,u=e.height,c=e.data}else arguments.length>=9&&(l=r,u=i,f=a,d=o);let p=this._getTexImage(e);if(!p){this.setError(this.INVALID_OPERATION);return}let m=convertPixels(c);if(this._unpackPremultAlpha&&m&&d===this.RGBA&&(m=premultiplyAlpha(m)),this._unpackFlipY&&m&&l>0&&u>0){let e=this._computePixelSize(s,d);if(e>0){let t=this._computeRowStride(l,e),n=new Uint8Array(m.length);for(let e=0;e<u;e++){let r=e*t,i=(u-1-e)*t;n.set(m.subarray(r,r+t),i)}m=n}}this._saveError(),this._gl.texImage2D(e,t,n,l,u,f,d,s,Uint8ArrayToVariant(m));let h=this.getError();if(this._restoreError(h),h!==this.NO_ERROR)return;p._levelWidth[t]=l,p._levelHeight[t]=u,p._format=d,p._type=s;let g=this._activeFramebuffer;if(g){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(g._attachments[t[n]]===p){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 l=0,u=0,d=0;if(arguments.length===7)if(s=a,d=i,o instanceof St.Pixbuf){let e=o;l=e.get_width(),u=e.get_height(),c=e.get_pixels()}else{let e=extractImageData(o);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);l=e.width,u=e.height,c=e.data}else l=i,u=a,d=o;if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}let f=convertPixels(c);if(!f){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&f&&d===this.RGBA&&(f=premultiplyAlpha(f)),this._unpackFlipY&&f&&l>0&&u>0){let e=this._computePixelSize(s,d);if(e>0){let t=this._computeRowStride(l,e),n=new Uint8Array(f.length);for(let e=0;e<u;e++){let r=e*t,i=(u-1-e)*t;n.set(f.subarray(r,r+t),i)}f=n}}this._gl.texSubImage2D(e,t,n,r,l,u,d,s,Uint8ArrayToVariant(f))}getUniform(e,t){let n=t?._activeInfo?.type,r=5125,i=36294,a=36295,o=n===r||n===i||n===a||n===36296,s=e;if(!o)return super.getUniform(s,t);if(!e||!t)return null;let c=this._native2.getUniformi(s._|0,t._|0);return c?n===r?c[0]>>>0:n===i?new Uint32Array([c[0]>>>0,c[1]>>>0]):n===a?new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0]):new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0,c[3]>>>0]):null}getUniformBlockIndex(e,t){return this._native2.getUniformBlockIndex(e._,t)}uniformBlockBinding(e,t,n){this._native2.uniformBlockBinding(e._,t,n)}getActiveUniformBlockName(e,t){let n=this._native2.getActiveUniformBlockName(e._,t);return n.length>0?n:null}getActiveUniformBlockParameter(e,t,n){return this._native2.getActiveUniformBlockParameter(e._,t,n)}getActiveUniforms(e,t,n){return this._native2.getActiveUniforms(e._,t,n)}getFragDataLocation(e,t){return this._native2.getFragDataLocation(e._,t)}getIndexedParameter(e,t){return this._native2.getIndexedParameteri(e,t)}getInternalformatParameter(e,t,n){return this._native2.getInternalformatParameter(e,t,n)}getParameter(e){if(e===7938)return`WebGL 2.0`;if(e===35724)return`WebGL GLSL ES 3.00`;if(e===7939)return warnNotImplemented(`WebGL2RenderingContext.getParameter(GL_EXTENSIONS)`),``;if(e===36006)return this._activeDrawFramebuffer;if(e===36010)return this._activeReadFramebuffer;switch(e){case 36183:case 35071:case 32883:case 36063:case 34852:case 36203:case 33001:case 33e3:case 37157:case 35373:case 35657:case 35077:case 35978:case 35979:case 35968:case 35376:case 35375:case 35659:case 37154:case 35371:case 35658:case 35379:case 35374:case 35377:case 35076:case 3330:case 3332:case 3331:case 35053:case 35055:case 3074:case 32874:case 35869:case 36389:case 35983:case 35368:case 35380:case 32878:case 3314:case 32877:case 3316:case 3315:case 34045:return this._native2.getParameterx(e)?.deepUnpack()|0;case 35977:case 36388:case 36387:return!!this._native2.getParameterx(e)?.deepUnpack()}return super.getParameter(e)}getStringi(e,t){let n=this._native2.getStringi(e,t);return n.length>0?n:null}renderbufferStorage(e,t,n,r){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(n<0||r<0){this.setError(this.INVALID_VALUE);return}for(;this._gl.getError()!==this.NO_ERROR;);if(this._gl.renderbufferStorage(e,t,n,r),this._gl.getError()!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let a=this._activeFramebuffer;if(a){let e=this._getAttachments(),t=!1;for(let n=0;n<e.length;++n)if(a._attachments[e[n]]===i){t=!0;break}t&&this._updateFramebufferAttachments(a)}}getSupportedExtensions(){let e=super.getSupportedExtensions();for(let t of[`EXT_color_buffer_float`,`EXT_color_buffer_half_float`,`OES_texture_half_float`])e.indexOf(t)===-1&&e.push(t);return e}readPixels(e,t,n,r,i,a,o){if(!o)return;if(n<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._framebufferOk())return;let s=i===6408||i===32856?4:i===6407?3:i===33319?2:1,c=a===5126?4:a===5131||a===36193?2:a===5125||a===5124?4:a===5123||a===5122?2:1,l=n*r*s*c,u=new Uint8Array(l);this._saveError();let d=this._gl.readPixels(e,t,n,r,i,a,Uint8ArrayToVariant(u)),f=this.getError();if(this._restoreError(f),f!==this.NO_ERROR)return;let p=d&&d.length>0?d:u;if(o instanceof Uint8Array)o.set(p);else if(o instanceof Float32Array){let e=new Float32Array(p.buffer,0,o.length);o.set(e)}}_framebufferOk(){return!0}};installObjectLifecycleMethods(mr.prototype),installTexImage3DMethods(mr.prototype),installUniformMethods(mr.prototype),installClearBufferMethods(mr.prototype),installInstancedAndFramebufferOpsMethods(mr.prototype);function notifyElementResize(e,t,n){e._allocatedClientWidth=t,e._allocatedClientHeight=n,e._fireResizeSubscribers(t,n);let r=e.parentNode;for(;r;)r instanceof Element&&(r._allocatedClientWidth=t,r._allocatedClientHeight=n,r._fireResizeSubscribers(t,n)),r=r.parentNode}var HTMLCanvasElement$1=class extends Be{static{__name$1(this,`HTMLCanvasElement`)}constructor(e){super(),this.gtkGlArea=e}get width(){return this.gtkGlArea.get_allocated_width()*this.scaleFactor}set width(e){}get height(){return this.gtkGlArea.get_allocated_height()*this.scaleFactor}set height(e){}get scaleFactor(){return this.gtkGlArea.get_scale_factor()||1}get clientWidth(){return this.gtkGlArea.get_allocated_width()}get clientHeight(){return this.gtkGlArea.get_allocated_height()}get offsetWidth(){return this.clientWidth}get offsetHeight(){return this.clientHeight}getGlArea(){return this.gtkGlArea}_createCloneTarget(){let e=new Be;return e.width=this.width,e.height=this.height,e}getContext(e,t){return e===`webgl`||e===`experimental-webgl`?(this._webgl||=(this.gtkGlArea.make_current(),new WebGLRenderingContext$1(this,t)),this._webgl):e===`webgl2`?(this._webgl2||=(this.gtkGlArea.make_current(),new mr(this,t)),this._webgl2):super.getContext(e,t)}};const hr=[`apple software renderer`,`llvmpipe`,`softpipe`,`swrast`,`swiftshader`,`microsoft basic render driver`,`mesa offscreen`];function isSoftwareRenderer(e){if(!e)return!1;let t=e.toLowerCase();return hr.some(e=>t.includes(e))}const gr={Return:`Enter`,KP_Enter:`Enter`,Tab:`Tab`,ISO_Left_Tab:`Tab`,BackSpace:`Backspace`,Escape:`Escape`,Delete:`Delete`,KP_Delete:`Delete`,Insert:`Insert`,KP_Insert:`Insert`,Home:`Home`,KP_Home:`Home`,End:`End`,KP_End:`End`,Page_Up:`PageUp`,KP_Page_Up:`PageUp`,Page_Down:`PageDown`,KP_Page_Down:`PageDown`,Left:`ArrowLeft`,KP_Left:`ArrowLeft`,Up:`ArrowUp`,KP_Up:`ArrowUp`,Right:`ArrowRight`,KP_Right:`ArrowRight`,Down:`ArrowDown`,KP_Down:`ArrowDown`,Shift_L:`Shift`,Shift_R:`Shift`,Control_L:`Control`,Control_R:`Control`,Alt_L:`Alt`,Alt_R:`Alt`,Super_L:`Meta`,Super_R:`Meta`,Meta_L:`Meta`,Meta_R:`Meta`,Caps_Lock:`CapsLock`,Num_Lock:`NumLock`,Scroll_Lock:`ScrollLock`,Print:`PrintScreen`,Pause:`Pause`,Menu:`ContextMenu`,space:` `,F1:`F1`,F2:`F2`,F3:`F3`,F4:`F4`,F5:`F5`,F6:`F6`,F7:`F7`,F8:`F8`,F9:`F9`,F10:`F10`,F11:`F11`,F12:`F12`,KP_Add:`+`,KP_Subtract:`-`,KP_Multiply:`*`,KP_Divide:`/`,KP_Decimal:`.`,KP_Separator:`,`,KP_0:`0`,KP_1:`1`,KP_2:`2`,KP_3:`3`,KP_4:`4`,KP_5:`5`,KP_6:`6`,KP_7:`7`,KP_8:`8`,KP_9:`9`},_r={Return:`Enter`,KP_Enter:`NumpadEnter`,Tab:`Tab`,ISO_Left_Tab:`Tab`,BackSpace:`Backspace`,Escape:`Escape`,Delete:`Delete`,KP_Delete:`NumpadDecimal`,Insert:`Insert`,KP_Insert:`Numpad0`,Home:`Home`,KP_Home:`Numpad7`,End:`End`,KP_End:`Numpad1`,Page_Up:`PageUp`,KP_Page_Up:`Numpad9`,Page_Down:`PageDown`,KP_Page_Down:`Numpad3`,Left:`ArrowLeft`,KP_Left:`Numpad4`,Up:`ArrowUp`,KP_Up:`Numpad8`,Right:`ArrowRight`,KP_Right:`Numpad6`,Down:`ArrowDown`,KP_Down:`Numpad2`,Shift_L:`ShiftLeft`,Shift_R:`ShiftRight`,Control_L:`ControlLeft`,Control_R:`ControlRight`,Alt_L:`AltLeft`,Alt_R:`AltRight`,Super_L:`MetaLeft`,Super_R:`MetaRight`,Meta_L:`MetaLeft`,Meta_R:`MetaRight`,Caps_Lock:`CapsLock`,Num_Lock:`NumLock`,Scroll_Lock:`ScrollLock`,Print:`PrintScreen`,Pause:`Pause`,Menu:`ContextMenu`,space:`Space`,F1:`F1`,F2:`F2`,F3:`F3`,F4:`F4`,F5:`F5`,F6:`F6`,F7:`F7`,F8:`F8`,F9:`F9`,F10:`F10`,F11:`F11`,F12:`F12`,KP_Add:`NumpadAdd`,KP_Subtract:`NumpadSubtract`,KP_Multiply:`NumpadMultiply`,KP_Divide:`NumpadDivide`,KP_Decimal:`NumpadDecimal`,KP_Separator:`NumpadComma`,KP_0:`Numpad0`,KP_1:`Numpad1`,KP_2:`Numpad2`,KP_3:`Numpad3`,KP_4:`Numpad4`,KP_5:`Numpad5`,KP_6:`Numpad6`,KP_7:`Numpad7`,KP_8:`Numpad8`,KP_9:`Numpad9`};function gdkKeyvalToKey(e){let t=yt.keyval_name(e);if(t&&gr[t])return gr[t];let n=yt.keyval_to_unicode(e);return n>0?String.fromCodePoint(n):t??`Unidentified`}function gdkKeyvalToCode(e){let t=yt.keyval_name(e);if(t&&_r[t])return _r[t];let n=yt.keyval_to_unicode(e);if(n>=97&&n<=122)return`Key`+String.fromCodePoint(n-32);if(n>=65&&n<=90)return`Key`+String.fromCodePoint(n);if(n>=48&&n<=57)return`Digit`+String.fromCodePoint(n);if(t){let e={minus:`Minus`,equal:`Equal`,bracketleft:`BracketLeft`,bracketright:`BracketRight`,backslash:`Backslash`,semicolon:`Semicolon`,apostrophe:`Quote`,grave:`Backquote`,comma:`Comma`,period:`Period`,slash:`Slash`};if(e[t])return e[t]}return t??`Unidentified`}function gdkKeyvalToLocation(e){let t=yt.keyval_name(e);return t?t.startsWith(`KP_`)?3:t.endsWith(`_L`)?1:t.endsWith(`_R`)?2:0:0}const vr=.5;var TouchPointerTranslator=class{constructor(e,t){this.getElement=e,this.getWindowTarget=t,this.active=new Map,this.nextId=2}get activeCount(){return this.active.size}handle(e){switch(e.phase){case`begin`:this.begin(e);break;case`update`:this.update(e);break;case`end`:this.end(e);break;case`cancel`:this.cancel(e);break}}cancelAll(e){for(let[t,n]of this.active)this.cancel({...e,phase:`cancel`,key:t,x:n.lastX,y:n.lastY,isPrimary:n.isPrimary})}begin(e){this.active.has(e.key)&&this.cancel(e);let t=this.getElement();if(!t)return;let n={id:this.nextId++,isPrimary:e.isPrimary,lastX:e.x,lastY:e.y,preventMouse:!1};this.active.set(e.key,n);let r=this.pointerInit(e,n,-1,0,0),i=this.mouseInit(e,0,0);n.isPrimary&&t.dispatchEvent(new MouseEvent(`mousemove`,i)),t.dispatchEvent(new PointerEvent(`pointerover`,r)),t.dispatchEvent(new PointerEvent(`pointerenter`,{...r,bubbles:!1,cancelable:!1})),n.isPrimary&&(t.dispatchEvent(new MouseEvent(`mouseover`,i)),t.dispatchEvent(new MouseEvent(`mouseenter`,{...i,bubbles:!1,cancelable:!1})));let a=new PointerEvent(`pointerdown`,this.pointerInit(e,n,0,1,vr));t.dispatchEvent(a),n.isPrimary&&(n.preventMouse=a.defaultPrevented,n.preventMouse||t.dispatchEvent(new MouseEvent(`mousedown`,{...this.mouseInit(e,0,1),detail:1})))}update(e){let t=this.active.get(e.key);if(!t)return;let n=this.getElement();if(!n)return;let r=e.x-t.lastX,i=e.y-t.lastY;t.lastX=e.x,t.lastY=e.y,n.dispatchEvent(new PointerEvent(`pointermove`,{...this.pointerInit(e,t,-1,1,vr),movementX:r,movementY:i})),t.isPrimary&&!t.preventMouse&&n.dispatchEvent(new MouseEvent(`mousemove`,{...this.mouseInit(e,0,1),movementX:r,movementY:i}))}end(e){let t=this.active.get(e.key);if(!t)return;this.active.delete(e.key);let n=this.getElement();if(!n)return;let r=this.pointerInit(e,t,0,0,0),i=this.mouseInit(e,0,0),a=t.isPrimary&&!t.preventMouse;n.dispatchEvent(new PointerEvent(`pointerup`,r)),a&&n.dispatchEvent(new MouseEvent(`mouseup`,{...i,detail:1})),this.leave(n,t,{...r,button:-1},i),t.isPrimary&&n.dispatchEvent(new PointerEvent(`click`,{...r,detail:1}))}cancel(e){let t=this.active.get(e.key);if(!t)return;this.active.delete(e.key);let n=this.getElement();if(!n)return;let r={...e,x:t.lastX,y:t.lastY},i=this.pointerInit(r,t,-1,0,0),a=this.mouseInit(r,0,0);n.dispatchEvent(new PointerEvent(`pointercancel`,{...i,cancelable:!1})),t.isPrimary&&!t.preventMouse&&this.getWindowTarget()?.dispatchEvent(new MouseEvent(`mouseup`,{...a,detail:1})),this.leave(n,t,i,a)}leave(e,t,n,r){e.dispatchEvent(new PointerEvent(`pointerout`,n)),e.dispatchEvent(new PointerEvent(`pointerleave`,{...n,bubbles:!1,cancelable:!1})),t.isPrimary&&(e.dispatchEvent(new MouseEvent(`mouseout`,r)),e.dispatchEvent(new MouseEvent(`mouseleave`,{...r,bubbles:!1,cancelable:!1})))}mouseInit(e,t,n){return{shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,clientX:e.x,clientY:e.y,offsetX:e.x,offsetY:e.y,screenX:e.x,screenY:e.y,button:t,buttons:n,bubbles:!0,cancelable:!0}}pointerInit(e,t,n,r,i){return{...this.mouseInit(e,n,r),pointerId:t.id,pointerType:`touch`,isPrimary:t.isPrimary,pressure:i}}};const yr=new Map([[yt.EventType.TOUCH_BEGIN,`begin`],[yt.EventType.TOUCH_UPDATE,`update`],[yt.EventType.TOUCH_END,`end`],[yt.EventType.TOUCH_CANCEL,`cancel`]]);function isTouchEvent(e){return e!==null&&yr.has(e.get_event_type())}function pointerTypeOf(e){let t=e?.get_device()?.get_source();return t===yt.InputSource.TOUCHSCREEN?`touch`:t===yt.InputSource.PEN?`pen`:`mouse`}let br=!1;function sequenceKey(e,t){if(e===null)return t?`primary`:`secondary`;let n=String(e),r=n.lastIndexOf(`native@`);return r!==-1&&n.endsWith(`]`)?n.slice(r+7,-1):(br||(br=!0,console.warn(`@gjsify/event-bridge: GdkEventSequence identity is not readable on this runtime; touch pointers are keyed by the emulating-pointer flag, so a third concurrent contact merges with the second.`)),t?`primary`:`secondary`)}function surfaceToWidget(e,t,n){let r=e.get_native(),[i,a]=r.get_surface_transform(),o=t-i,s=n-a,[c,l]=r.compute_point(e,new kn.Point({x:o,y:s}));return c?[l.x,l.y]:[o,s]}function getGlobalEventTarget(){return globalThis.__gjsify_globalEventTarget}const xr={shiftKey:!1,ctrlKey:!1,altKey:!1,metaKey:!1};function modifiersFromState(e){return{shiftKey:!!(e&yt.ModifierType.SHIFT_MASK),ctrlKey:!!(e&yt.ModifierType.CONTROL_MASK),altKey:!!(e&yt.ModifierType.ALT_MASK),metaKey:!!(e&yt.ModifierType.SUPER_MASK)}}function extractModifiers(e){return modifiersFromState(e.get_current_event_state())}function gtkButtonToDom(e){return e===1?0:e===2?1:e===3?2:e-1}function buttonsFromModifiers(e){let t=e.get_current_event_state(),n=0;return t&yt.ModifierType.BUTTON1_MASK&&(n|=1),t&yt.ModifierType.BUTTON3_MASK&&(n|=2),t&yt.ModifierType.BUTTON2_MASK&&(n|=4),n}function attachEventControllers(e,t,n){e.set_focusable(!0),e.set_can_focus(!0);let r={lastX:0,lastY:0,buttonsPressed:0,pressedKeys:new Set},i=new TouchPointerTranslator(t,()=>getGlobalEventTarget()),a=new Sn.EventControllerMotion;a.connect(`motion`,(n,i,o)=>{let s=t();if(!s)return;let c=e.get_allocated_width(),l=e.get_allocated_height(),u=Math.max(0,Math.min(i,c)),d=Math.max(0,Math.min(o,l)),f=u-r.lastX,p=d-r.lastY,m=extractModifiers(a),h=buttonsFromModifiers(a),g={...m,clientX:u,clientY:d,offsetX:u,offsetY:d,screenX:u,screenY:d,movementX:f,movementY:p,buttons:h,button:0,bubbles:!0,cancelable:!0};s.dispatchEvent(new PointerEvent(`pointermove`,{...g,pointerId:1,pointerType:pointerTypeOf(a.get_current_event()),isPrimary:!0})),s.dispatchEvent(new MouseEvent(`mousemove`,g)),r.lastX=u,r.lastY=d}),a.connect(`enter`,(e,n,i)=>{let o=t();if(!o)return;r.lastX=n,r.lastY=i;let s={...extractModifiers(a),clientX:n,clientY:i,offsetX:n,offsetY:i,screenX:n,screenY:i,bubbles:!1,cancelable:!1};o.dispatchEvent(new PointerEvent(`pointerenter`,{...s,pointerId:1,pointerType:pointerTypeOf(a.get_current_event()),isPrimary:!0})),o.dispatchEvent(new MouseEvent(`mouseenter`,s)),o.dispatchEvent(new MouseEvent(`mouseover`,{...s,bubbles:!0}))}),a.connect(`leave`,()=>{let e=t();if(!e)return;let n={...extractModifiers(a),clientX:r.lastX,clientY:r.lastY,bubbles:!1,cancelable:!1};e.dispatchEvent(new PointerEvent(`pointerleave`,{...n,pointerId:1,pointerType:pointerTypeOf(a.get_current_event()),isPrimary:!0})),e.dispatchEvent(new MouseEvent(`mouseleave`,n)),e.dispatchEvent(new MouseEvent(`mouseout`,{...n,bubbles:!0}))}),e.add_controller(a);let o=new Sn.GestureClick;o.set_button(0),o.connect(`pressed`,(n,i,a,s)=>{if(isTouchEvent(o.get_current_event()))return;let c=t();if(!c)return;let l=gtkButtonToDom(o.get_current_button()),u=extractModifiers(o);r.buttonsPressed|=1<<l;let d={...u,clientX:a,clientY:s,offsetX:a,offsetY:s,screenX:a,screenY:s,button:l,buttons:r.buttonsPressed,detail:i,bubbles:!0,cancelable:!0};c.dispatchEvent(new PointerEvent(`pointerdown`,{...d,pointerId:1,pointerType:pointerTypeOf(o.get_current_event()),isPrimary:!0})),c.dispatchEvent(new MouseEvent(`mousedown`,d)),e.grab_focus()}),o.connect(`released`,(e,n,i,a)=>{if(isTouchEvent(o.get_current_event()))return;let s=t();if(!s)return;let c=gtkButtonToDom(o.get_current_button()),l=extractModifiers(o);r.buttonsPressed&=~(1<<c);let u={...l,clientX:i,clientY:a,offsetX:i,offsetY:a,screenX:i,screenY:a,button:c,buttons:r.buttonsPressed,detail:n,bubbles:!0,cancelable:!0};s.dispatchEvent(new PointerEvent(`pointerup`,{...u,pointerId:1,pointerType:pointerTypeOf(o.get_current_event()),isPrimary:!0})),s.dispatchEvent(new MouseEvent(`mouseup`,u)),c===0&&(s.dispatchEvent(new MouseEvent(`click`,u)),n===2&&s.dispatchEvent(new MouseEvent(`dblclick`,u))),c===2&&s.dispatchEvent(new MouseEvent(`contextmenu`,{...u,cancelable:!0}))}),o.connect(`cancel`,(e,n)=>{let i=o.get_last_event(n);if(isTouchEvent(i)||r.buttonsPressed===0)return;r.buttonsPressed=0;let a=t();a&&a.dispatchEvent(new PointerEvent(`pointercancel`,{...extractModifiers(o),clientX:r.lastX,clientY:r.lastY,offsetX:r.lastX,offsetY:r.lastY,screenX:r.lastX,screenY:r.lastY,button:-1,buttons:0,pointerId:1,pointerType:pointerTypeOf(i),isPrimary:!0,bubbles:!0,cancelable:!1}))}),e.add_controller(o);let s=new Sn.EventControllerScroll({flags:Sn.EventControllerScrollFlags.BOTH_AXES});s.connect(`scroll`,(e,n,i)=>{let a=t();if(!a)return;let o=extractModifiers(s),c=s.get_unit()===yt.ScrollUnit.WHEEL,l=c?3:1,u={...o,clientX:r.lastX,clientY:r.lastY,offsetX:r.lastX,offsetY:r.lastY,screenX:r.lastX,screenY:r.lastY,deltaX:n*l,deltaY:i*l,deltaZ:0,deltaMode:c?WheelEvent.DOM_DELTA_LINE:WheelEvent.DOM_DELTA_PIXEL,bubbles:!0,cancelable:!0};return a.dispatchEvent(new WheelEvent(`wheel`,u)),!1}),e.add_controller(s);let c=new Sn.EventControllerKey;c.connect(`key-pressed`,(e,i,a,o)=>{let s=t();if(!s)return!1;let c=r.pressedKeys.has(i);r.pressedKeys.add(i);let l=gdkKeyvalToKey(i),u={key:l,code:gdkKeyvalToCode(i),location:gdkKeyvalToLocation(i),repeat:c,altKey:!!(o&yt.ModifierType.ALT_MASK),ctrlKey:!!(o&yt.ModifierType.CONTROL_MASK),metaKey:!!(o&yt.ModifierType.SUPER_MASK),shiftKey:!!(o&yt.ModifierType.SHIFT_MASK),keyCode:l.length===1?l.toUpperCase().charCodeAt(0):0,which:l.length===1?l.toUpperCase().charCodeAt(0):0,bubbles:!0,cancelable:!0},d=new KeyboardEvent(`keydown`,u);return s.dispatchEvent(d),getGlobalEventTarget()?.dispatchEvent(new KeyboardEvent(`keydown`,u)),n?.captureKeys===!0}),c.connect(`key-released`,(e,n,i,a)=>{let o=t();if(!o)return;r.pressedKeys.delete(n);let s=gdkKeyvalToKey(n),c={key:s,code:gdkKeyvalToCode(n),location:gdkKeyvalToLocation(n),repeat:!1,altKey:!!(a&yt.ModifierType.ALT_MASK),ctrlKey:!!(a&yt.ModifierType.CONTROL_MASK),metaKey:!!(a&yt.ModifierType.SUPER_MASK),shiftKey:!!(a&yt.ModifierType.SHIFT_MASK),keyCode:s.length===1?s.toUpperCase().charCodeAt(0):0,which:s.length===1?s.toUpperCase().charCodeAt(0):0,bubbles:!0,cancelable:!0};o.dispatchEvent(new KeyboardEvent(`keyup`,c)),getGlobalEventTarget()?.dispatchEvent(new KeyboardEvent(`keyup`,c))}),e.add_controller(c);let l=new Sn.EventControllerFocus;l.connect(`enter`,()=>{let e=t();e&&(e.dispatchEvent(new FocusEvent(`focus`,{bubbles:!1,cancelable:!1})),e.dispatchEvent(new FocusEvent(`focusin`,{bubbles:!0,cancelable:!1})))}),l.connect(`leave`,()=>{let e=t();e&&(r.pressedKeys.clear(),e.dispatchEvent(new FocusEvent(`blur`,{bubbles:!1,cancelable:!1})),e.dispatchEvent(new FocusEvent(`focusout`,{bubbles:!0,cancelable:!1})),getGlobalEventTarget()?.dispatchEvent(new FocusEvent(`blur`,{bubbles:!1,cancelable:!1})))}),e.add_controller(l);let u=new Sn.EventControllerLegacy;u.connect(`event`,(t,n)=>{let r=n.get_event_type(),a=yr.get(r);if(a===void 0)return r===yt.EventType.GRAB_BROKEN&&i.activeCount>0&&n.get_grab_surface()!==e.get_native().get_surface()&&i.cancelAll(modifiersFromState(n.get_modifier_state())),!1;let[,o,s]=n.get_position(),[c,l]=surfaceToWidget(e,o,s),u=n.get_emulating_pointer();return i.handle({...modifiersFromState(n.get_modifier_state()),phase:a,key:sequenceKey(n.get_event_sequence(),u),x:c,y:l,isPrimary:u}),a===`begin`&&e.grab_focus(),!1}),e.add_controller(u),e.connect(`unmap`,()=>i.cancelAll(xr)),e.connect(`state-flags-changed`,(t,n)=>{let r=Sn.StateFlags.INSENSITIVE;e.get_state_flags()&r&&!(n&r)&&i.cancelAll(xr)})}const Sr=Pn.registerClass({GTypeName:`GjsifyWebGLBridge`},class WebGLBridge extends Sn.GLArea{constructor(e){super(e),this._canvas=null,this._readyCallbacks=[],this._resizeCallbacks=[],this._renderTag=null,this._tickCallbackId=null,this._frameCallback=null,this._lastFrameCallback=null,this._lastFrameTime=0,this._replaying=!1,this._frameCallbackId=0,this._nextFrameId=1,this._timeOrigin=gt.get_monotonic_time(),this._rendererInfo=null,this.set_allowed_apis(yt.GLAPI.GL|yt.GLAPI.GLES),this.set_required_version(3,2),this.set_has_depth_buffer(!0),this.set_has_stencil_buffer(!0),attachEventControllers(this,()=>this._canvas,{captureKeys:!0}),this._tickCallbackId=this.add_tick_callback((e,t)=>(this._frameCallback!==null&&this.queue_render(),gt.SOURCE_CONTINUE));let t=this.connect(`render`,()=>{this.disconnect(t),this.make_current(),this._canvas=new HTMLCanvasElement$1(this);{let e=globalThis;e.document?.body&&e.document.body.appendChild(this._canvas)}this._canvas.getContext(`webgl2`);let e=this._canvas.getContext(`webgl`);if(e){this._reportRenderer(e);for(let t of this._readyCallbacks)t(this._canvas,e);this._readyCallbacks=[]}return this._renderTag=this.connect(`render`,e=>{let t=(gt.get_monotonic_time()-this._timeOrigin)/1e3;if(this._frameCallback!==null){globalThis.__GJSIFY_DEBUG_RAF===!0&&console.log(`[rAF] frame callback fires t=${t.toFixed(1)}`);let e=this._frameCallback;this._frameCallback=null,this._frameCallbackId=0,this._lastFrameCallback=e,this._lastFrameTime=t,e(t)}else if(this._lastFrameCallback!==null){this._replaying=!0;try{this._lastFrameCallback(this._lastFrameTime)}finally{this._replaying=!1}}return!0}),!0});this.connect(`resize`,()=>{let e=this.get_allocated_width(),t=this.get_allocated_height();this._canvas&&(this._canvas.dispatchEvent(new Event(`resize`)),notifyElementResize(this._canvas,e,t));for(let n of this._resizeCallbacks)n(e,t);this._frameCallback&&this.requestAnimationFrame(this._frameCallback)}),this.connect(`unrealize`,()=>{this._renderTag!==null&&(this.disconnect(this._renderTag),this._renderTag=null),this._tickCallbackId!==null&&(this.remove_tick_callback(this._tickCallbackId),this._tickCallbackId=null),this._frameCallback=null,this._lastFrameCallback=null,this._lastFrameTime=0,this._replaying=!1,this._canvas=null})}get canvas(){return this._canvas}get rendererInfo(){return this._rendererInfo}onReady(e){if(this._canvas){let t=this._canvas.getContext(`webgl`);if(t){e(this._canvas,t);return}}this._readyCallbacks.push(e)}onWebGLReady(e){this.onReady(e)}_reportRenderer(e){let t=e.getExtension(`WEBGL_debug_renderer_info`),n=String(e.getParameter(t.UNMASKED_VENDOR_WEBGL)??``),r=String(e.getParameter(t.UNMASKED_RENDERER_WEBGL)??``);this._rendererInfo={vendor:n,renderer:r},isSoftwareRenderer(r)&&console.warn(`[@gjsify/webgl] GL is rasterised on the CPU by "${r}" (${n}) — this host exposes no usable GPU. Every draw call still works; fill-heavy or continuously animating content will be orders of magnitude slower than on hardware, which can look like a frozen window rather than a slow one. Read it yourself via WebGLBridge.rendererInfo or the WEBGL_debug_renderer_info extension.`)}onResize(e){this._resizeCallbacks.push(e)}requestAnimationFrame(e){let t=this._nextFrameId++;return this._replaying?t:(this._frameCallback=e,this._frameCallbackId=t,this.queue_render(),t)}cancelAnimationFrame(e){e!==0&&e===this._frameCallbackId&&(this._frameCallback=null,this._frameCallbackId=0,this._lastFrameCallback=null,this._lastFrameTime=0)}installGlobals(){let e=globalThis;e.requestAnimationFrame=e=>this.requestAnimationFrame(e),e.cancelAnimationFrame=e=>this.cancelAnimationFrame(e),e.WebGLRenderingContext=WebGLRenderingContext$1,e.WebGL2RenderingContext=mr,Object.defineProperty(globalThis,"devicePixelRatio",{get:()=>this.get_scale_factor()||1,configurable:!0});let t=this._timeOrigin;e.performance={now:()=>(gt.get_monotonic_time()-t)/1e3,timeOrigin:Date.now()}}}),Cr={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},wr={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},Tr=1e3,Er=1001,Dr=1002,Or=1003,kr=1006,Ar=1008,jr=1009,Mr=1012,Nr=1014,Pr=1015,Fr=1016,Ir=1017,Lr=1018,Rr=1020,zr=1023,Br=1026,Vr=1027,Hr=1028,Ur=1029,Wr=1030,Gr=1031,Kr=1033,qr=2300,Jr=2301,Yr=2302,Xr=2303,Zr=2400,Qr=2401,$r=2402,ei=`srgb`,ti=`srgb-linear`,ni=`linear`,ri=`srgb`,ii=7680,ai=2e3
87
+ `+i+t:i&&(t=i+t)}else i&&(t=i+t);return t}};function installShaderLifecycleMethods(e){Object.assign(e,er)}const tr={createProgram(){let e=this._gl.createProgram();if(e<=0)return null;let t=new WebGLProgram$1(e,this);return this._programs[e]=t,t},deleteProgram(e){this._deleteLinkable(`deleteProgram`,e,WebGLProgram$1)},useProgram(e){if(!checkObject(e))throw TypeError(`useProgram(WebGLProgram)`);if(e)this._checkWrapper(e,WebGLProgram$1)&&(this._activeProgram!==e&&(this._switchActiveProgram(this._activeProgram),this._activeProgram=e,e._refCount+=1),this._gl.useProgram(e._|0));else{this._switchActiveProgram(this._activeProgram),this._activeProgram=null,this._gl.useProgram(0);return}},linkProgram(e){if(!checkObject(e))throw TypeError(`linkProgram(WebGLProgram)`);if(this._checkWrapper(e,WebGLProgram$1)){e._linkCount+=1,e._attributes=[];let t=this.getError();for(let t of e._references)t instanceof WebGLShader$1&&t._needsRecompile&&(this._gl.compileShader(t._|0),t._needsRecompile=!1);this._gl.linkProgram(e._|0);let n=this.getError();n===this.NO_ERROR&&(e._linkStatus=this._fixupLink(e)),this.getError(),this.setError(t||n)}},validateProgram(e){if(this._checkWrapper(e,WebGLProgram$1)){this._gl.validateProgram(e._|0);let t=this.getError();t===this.NO_ERROR&&(e._linkInfoLog=this._gl.getProgramInfoLog(e._|0)),this.getError(),this.setError(t)}},attachShader(e,t){if(!checkObject(e)||!checkObject(t))throw TypeError(`attachShader(WebGLProgram, WebGLShader)`);if(!e||!t){this.setError(this.INVALID_VALUE);return}else if(e instanceof WebGLProgram$1&&t instanceof WebGLShader$1&&this._checkOwns(e)&&this._checkOwns(t)&&!e._linked(t)){this._saveError(),this._gl.attachShader(e._|0,t._|0);let n=this.getError();this._restoreError(n),n===this.NO_ERROR&&e._link(t);return}this.setError(this.INVALID_OPERATION)},detachShader(e,t){if(!checkObject(e)||!checkObject(t))throw TypeError(`detachShader(WebGLProgram, WebGLShader)`);this._checkWrapper(e,WebGLProgram$1)&&this._checkWrapper(t,WebGLShader$1)&&(e._linked(t)?(this._gl.detachShader(e._,t._),e._unlink(t)):this.setError(this.INVALID_OPERATION))},bindAttribLocation(e,t,n){if(!checkObject(e)||typeof n!=`string`)throw TypeError(`bindAttribLocation(WebGLProgram, GLint, String)`);n+=``,!isValidString(n)||n.length>256?this.setError(this.INVALID_VALUE):/^_?webgl_a/.test(n)?this.setError(this.INVALID_OPERATION):this._checkWrapper(e,WebGLProgram$1)&&this._gl.bindAttribLocation(e._|0,t|0,n)},getAttachedShaders(e){if(!checkObject(e)||typeof e==`object`&&e&&!(e instanceof WebGLProgram$1))throw TypeError(`getAttachedShaders(WebGLProgram)`);if(!e)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(e,WebGLProgram$1))return e._references.filter(e=>e instanceof WebGLShader$1);return null},getProgramInfoLog(e){if(!checkObject(e))throw TypeError(`getProgramInfoLog(WebGLProgram)`);return this._checkWrapper(e,WebGLProgram$1)?e._linkInfoLog:null},getProgramParameter(e,t=0){if(!checkObject(e))throw TypeError(`getProgramParameter(WebGLProgram, GLenum)`);if(this._checkWrapper(e,WebGLProgram$1)){switch(t){case this.DELETE_STATUS:return e._pendingDelete;case this.LINK_STATUS:return e._linkStatus;case this.VALIDATE_STATUS:return!!this._gl.getProgramParameter(e._,t);case this.ATTACHED_SHADERS:return this._gl.getProgramParameter(e._,t);case this.ACTIVE_ATTRIBUTES:return e._linkStatus?e._attributes.length:this._gl.getProgramParameter(e._,t);case this.ACTIVE_UNIFORMS:return e._linkStatus?e._uniforms.length:this._gl.getProgramParameter(e._,t)}this.setError(this.INVALID_ENUM)}return null},_switchActiveProgram(e){e&&(--e._refCount,e._checkDelete())},_fixupLink(e){if(!this._gl.getProgramParameter(e._,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let t=this.getProgramParameter(e,this.ACTIVE_ATTRIBUTES),n=Array.from({length:t});e._attributes.length=t;for(let r=0;r<t;++r)n[r]=this.getActiveAttrib(e,r)?.name,e._attributes[r]=this.getAttribLocation(e,n[r])|0;for(let t=0;t<n.length;++t)if(n[t].length>256)return e._linkInfoLog=`attribute `+n[t]+` is too long`,!1;for(let r=0;r<t;++r)e._attributes[r]<0||this._gl.bindAttribLocation(e._|0,e._attributes[r],n[r]);if(this._gl.linkProgram(e._|0),!this._gl.getProgramParameter(e._|0,this.LINK_STATUS))return e._linkInfoLog=this._gl.getProgramInfoLog(e._),!1;let r=this.getProgramParameter(e,this.ACTIVE_UNIFORMS);e._uniforms.length=r;for(let t=0;t<r;++t){let n=this.getActiveUniform(e,t);n&&(e._uniforms[t]=n)}for(let t=0;t<e._uniforms.length;++t)if(e._uniforms[t].name.length>256)return e._linkInfoLog=`uniform `+e._uniforms[t].name+` is too long`,!1;return e._linkInfoLog=``,!0},_deleteLinkable(e,t,n){if(!checkObject(t))throw TypeError(e+`(`+n.name+`)`);if(t instanceof n&&this._checkOwns(t)){t._pendingDelete=!0,t._checkDelete();return}this.setError(this.INVALID_OPERATION)}};function installProgramLifecycleMethods(e){Object.assign(e,tr)}const nr={getActiveAttrib(e,t){if(!checkObject(e))throw TypeError(`getActiveAttrib(WebGLProgram)`);if(!e)throw TypeError(`getActiveAttrib(WebGLProgram, GLuint)`);if(this._checkWrapper(e,WebGLProgram$1)){if(t>=(e._linkStatus?e._attributes.length:this._gl.getProgramParameter(e._|0,this.ACTIVE_ATTRIBUTES)))return this._gl.getError(),this.setError(this.INVALID_VALUE),null;let n=this._gl.getActiveAttrib(e._|0,t|0);if(n)return new WebGLActiveInfo(n)}return null},getActiveUniform(e,t){if(!checkObject(e))throw TypeError(`getActiveUniform(WebGLProgram, GLint)`);if(!e)throw TypeError(`getActiveUniform(WebGLProgram, GLuint)`);if(this._checkWrapper(e,WebGLProgram$1)){if(t>=(e._linkStatus?e._uniforms.length:this._gl.getProgramParameter(e._|0,this.ACTIVE_UNIFORMS)))return this.setError(this.INVALID_VALUE),null;let n=this._gl.getActiveUniform(e._|0,t|0);if(n)return new WebGLActiveInfo(n)}return null},getAttribLocation(e,t){if(!checkObject(e))throw TypeError(`getAttribLocation(WebGLProgram, String)`);if(t+=``,!isValidString(t)||t.length>256)this.setError(this.INVALID_VALUE);else if(this._checkWrapper(e,WebGLProgram$1))return this._gl.getAttribLocation(e._|0,t+``);return-1},getUniform(e,t){if(!checkObject(e)||!checkObject(t))throw TypeError(`getUniform(WebGLProgram, WebGLUniformLocation)`);if(!e)return this.setError(this.INVALID_VALUE),null;if(!t)return null;if(this._checkWrapper(e,WebGLProgram$1)){if(!checkUniform(e,t))return this.setError(this.INVALID_OPERATION),null;let n=this._gl.getUniform(e._|0,t._|0);if(!n)return null;switch(t._activeInfo.type){case this.FLOAT:return n[0];case this.FLOAT_VEC2:return new Float32Array(n.slice(0,2));case this.FLOAT_VEC3:return new Float32Array(n.slice(0,3));case this.FLOAT_VEC4:return new Float32Array(n.slice(0,4));case this.INT:return n[0]|0;case this.INT_VEC2:return new Int32Array(n.slice(0,2));case this.INT_VEC3:return new Int32Array(n.slice(0,3));case this.INT_VEC4:return new Int32Array(n.slice(0,4));case this.BOOL:return!!n[0];case this.BOOL_VEC2:return[!!n[0],!!n[1]];case this.BOOL_VEC3:return[!!n[0],!!n[1],!!n[2]];case this.BOOL_VEC4:return[!!n[0],!!n[1],!!n[2],!!n[3]];case this.FLOAT_MAT2:return new Float32Array(n.slice(0,4));case this.FLOAT_MAT3:return new Float32Array(n.slice(0,9));case this.FLOAT_MAT4:return new Float32Array(n.slice(0,16));case this.SAMPLER_2D:case this.SAMPLER_CUBE:return n[0]|0;default:return null}}return null},getUniformLocation(e,t){if(!checkObject(e))throw TypeError(`getUniformLocation(WebGLProgram, String)`);if(t+=``,!isValidString(t))return this.setError(this.INVALID_VALUE),null;if(this._checkWrapper(e,WebGLProgram$1)){let n=this._gl.getUniformLocation(e._|0,t);if(n!==null&&n>=0){let r=t;/\[\d+\]$/.test(t)&&(r=t.replace(/\[\d+\]$/,`[0]`));let i=r+`[0]`,a=null;for(let t=0;t<e._uniforms.length;++t){let n=e._uniforms[t];if(n.name===r||n.name===i){a={size:n.size,type:n.type,name:n.name};break}}a||={name:r,type:0,size:1};let o=new WebGLUniformLocation(n,e,a),s=t.match(/\[(\d+)\]$/),c=s?+s[1]:-1;if(a.name.endsWith(`[0]`)&&(c===-1||c===0)){let t=a.name.replace(/\[0\]$/,``),n=[];this._saveError();for(let r=0;this.getError()===this.NO_ERROR;++r){let i=this._gl.getUniformLocation(e._|0,t+`[`+r+`]`);if(this.getError()!==this.NO_ERROR||i==null||i<0)break;n.push(i)}this._restoreError(this.NO_ERROR),o._array=n}else if(c>0&&c>=a.size)return null;return o}}return null}};function installIntrospectionMethods(e){Object.assign(e,nr)}const rr={uniform1f(e,t){this._checkUniformValid(e,t,`uniform1f`,1,`f`)&&this._gl.uniform1f(e?._||0,t)},uniform1i(e,t){this._gl.uniform1i(e?._||0,t)},uniform2f(e,t,n){this._checkUniformValid(e,t,`uniform2f`,2,`f`)&&this._gl.uniform2f(e?._||0,t,n)},uniform2i(e,t,n){this._checkUniformValid(e,t,`uniform2i`,2,`i`)&&this._gl.uniform2i(e?._||0,t,n)},uniform3f(e,t,n,r){this._checkUniformValid(e,t,`uniform3f`,3,`f`)&&this._gl.uniform3f(e?._||0,t,n,r)},uniform3i(e,t,n,r){this._checkUniformValid(e,t,`uniform3i`,3,`i`)&&this._gl.uniform3i(e?._||0,t,n,r)},uniform4f(e,t,n,r,i){if(!this._checkUniformValid(e,t,`uniform4f`,4,`f`)){console.error(`uniform4f is not valid!`);return}this._gl.uniform4f(e?._||0,t,n,r,i)},uniform4i(e,t,n,r,i){this._checkUniformValid(e,t,`uniform4i`,4,`i`)&&this._gl.uniform4i(e?._||0,t,n,r,i)},uniform1fv(e,t){if(!(!e||!this._checkUniformValueValid(e,t,`uniform1fv`,1,`f`))){if(e?._array){let n=e._array;for(let e=0;e<n.length&&e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform1f(r,t[e])}return}this._gl.uniform1f(e?._|0,t[0])}},uniform1iv(e,t){if(this._checkUniformValueValid(e,t,`uniform1iv`,1,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform1i(r,t[e])}return}this.uniform1i(e,t[0])}},uniform2fv(e,t){if(this._checkUniformValueValid(e,t,`uniform2fv`,2,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&2*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform2f(r,t[2*e],t[2*e+1])}return}this._gl.uniform2f(e?._||0,t[0],t[1])}},uniform2iv(e,t){if(this._checkUniformValueValid(e,t,`uniform2iv`,2,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&2*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform2i(r,t[2*e],t[2*e+1])}return}this.uniform2i(e,t[0],t[1])}},uniform3fv(e,t){if(this._checkUniformValueValid(e,t,`uniform3fv`,3,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&3*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform3f(r,t[3*e],t[3*e+1],t[3*e+2])}return}this._gl.uniform3f(e?._||0,t[0],t[1],t[2])}},uniform3iv(e,t){if(this._checkUniformValueValid(e,t,`uniform3iv`,3,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&3*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform3i(r,t[3*e],t[3*e+1],t[3*e+2])}return}this.uniform3i(e,t[0],t[1],t[2])}},uniform4fv(e,t){if(this._checkUniformValueValid(e,t,`uniform4fv`,4,`f`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&4*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform4f(r,t[4*e],t[4*e+1],t[4*e+2],t[4*e+3])}return}this._gl.uniform4f(e?._||0,t[0],t[1],t[2],t[3])}},uniform4iv(e,t){if(this._checkUniformValueValid(e,t,`uniform4iv`,4,`i`)){if(e?._array){let n=e._array;for(let e=0;e<n.length&&4*e<t.length;++e){let r=n[e];r!=null&&this._gl.uniform4i(r,t[4*e],t[4*e+1],t[4*e+2],t[4*e+3])}return}this.uniform4i(e,t[0],t[1],t[2],t[3])}},uniformMatrix2fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix2fv`,2))return;let r=new Float32Array(n);this._gl.uniformMatrix2fv(e?._||0,!!t,listToArray(r))},uniformMatrix3fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix3fv`,3))return;let r=new Float32Array(n);this._gl.uniformMatrix3fv(e?._||0,!!t,listToArray(r))},uniformMatrix4fv(e,t,n){if(!this._checkUniformMatrix(e,t,n,`uniformMatrix4fv`,4))return;let r=new Float32Array(n);this._gl.uniformMatrix4fv(e?._||0,!!t,listToArray(r))},_checkLocation(e){return e instanceof WebGLUniformLocation?e._program._ctx!==this||e._linkCount!==e._program._linkCount?(this.setError(this.INVALID_OPERATION),!1):!0:(this.setError(this.INVALID_VALUE),!1)},_checkLocationActive(e){return e&&this._checkLocation(e)?e._program===this._activeProgram?!0:(this.setError(this.INVALID_OPERATION),!1):!1},_checkUniformValid(e,t,n,r,i){if(!checkObject(e))throw TypeError(`${n}(WebGLUniformLocation, ...)`);if(!e)return!1;if(this._checkLocationActive(e)){let n=e._activeInfo.type;if(n===this.SAMPLER_2D||n===this.SAMPLER_CUBE){if(r!==1)return this.setError(this.INVALID_VALUE),!1;if(i!==`i`)return this.setError(this.INVALID_OPERATION),!1;if(t<0||t>=this._textureUnits.length)return this.setError(this.INVALID_VALUE),!1}return uniformTypeSize(this,n)>r?(this.setError(this.INVALID_OPERATION),!1):!0}return!1},_checkUniformValueValid(e,t,n,r,i){if(!checkObject(e)||!checkObject(t))throw TypeError(`${n}v(WebGLUniformLocation, Array)`);if(!e||!this._checkLocationActive(e))return!1;if(typeof t!=`object`||!t||typeof t.length!=`number`)throw TypeError(`Second argument to ${n} must be array`);return uniformTypeSize(this,e._activeInfo.type)>r?(this.setError(this.INVALID_OPERATION),!1):t.length>=r&&t.length%r===0?e._array||t.length===r?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)},_checkUniformMatrix(e,t,n,r,i){if(!checkObject(e)||typeof n!=`object`)throw TypeError(r+`(WebGLUniformLocation, Boolean, Array)`);return t||typeof n!=`object`||!n||!n.length||n.length%i*i!==0?(this.setError(this.INVALID_VALUE),!1):!e||!this._checkLocationActive(e)?!1:n.length===i*i||e._array?!0:(this.setError(this.INVALID_VALUE),!1)}};function installUniformsMethods(e){Object.assign(e,rr)}function installShaderProgramMethods(e){installShaderLifecycleMethods(e),installProgramLifecycleMethods(e),installIntrospectionMethods(e),installUniformsMethods(e)}function installAllContextMethods(e){installStateMethods(e),installBufferBindingMethods(e),installTextureManagementMethods(e),installFramebufferMethods(e),installShaderProgramMethods(e),installDrawingMethods(e)}const ir=e(import.meta.url);let ar;function load(){return ar===void 0&&(ar=ir(`@gjsify/node-gi/gi`).requireGi(`Gwebgl`,`0.1`)),ar}var or=new Proxy(Object.create(null),{get(e,t){return load()[t]},has(e,t){return t in load()}});let sr=0;const cr={oes_element_index_uint:getOESElementIndexUint,oes_texture_float:getOESTextureFloat,oes_texture_float_linear:getOESTextureFloatLinear,oes_standard_derivatives:getOESStandardDerivatives,stackgl_destroy_context:getSTACKGLDestroyContext,stackgl_resize_drawingbuffer:getSTACKGLResizeDrawingBuffer,ext_blend_minmax:getEXTBlendMinMax,ext_color_buffer_float:getEXTColorBufferFloat,ext_color_buffer_half_float:getEXTColorBufferHalfFloat,ext_texture_filter_anisotropic:getEXTTextureFilterAnisotropic,oes_texture_half_float:getOESTextureHalfFloat,webgl_debug_renderer_info:getWEBGLDebugRendererInfo};var WebGLContextBase=class{get drawingBufferHeight(){return this.canvas.height||0}get drawingBufferWidth(){return this.canvas.width||0}constructor(e,t={}){this.drawingBufferColorSpace=`srgb`,this.unpackColorSpace=`srgb`,this.RGBA8=32856,this.DEFAULT_ATTACHMENTS=[],this.DEFAULT_COLOR_ATTACHMENTS=[],this._=0,this._extensions={},this._programs={},this._shaders={},this._textures={},this._framebuffers={},this._renderbuffers={},this._buffers={},this._activeProgram=null,this._activeFramebuffer=null,this._activeRenderbuffer=null,this._checkStencil=!1,this._stencilState=!0,this._activeTextureUnit=0,this._errorStack=[],this._maxTextureSize=0,this._maxTextureLevel=0,this._maxCubeMapSize=0,this._maxCubeMapLevel=0,this._maxRenderbufferSize=0,this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this._viewport=new Int32Array([0,0,0,0]),this._scissorBox=new Int32Array([0,0,0,0]),this._gtkFboId=0,this._textureUnits=[],this._drawingBuffer=null,this.canvas=e,this._contextAttributes=new WebGLContextAttributes(flag(t,`alpha`,!0),flag(t,`depth`,!0),flag(t,`stencil`,!1),!1,flag(t,`premultipliedAlpha`,!0),flag(t,`preserveDrawingBuffer`,!1),flag(t,`preferLowPowerToHighPerformance`,!1),flag(t,`failIfMajorPerformanceCaveat`,!1)),this._contextAttributes.premultipliedAlpha=this._contextAttributes.premultipliedAlpha&&this._contextAttributes.alpha}_init(){let e=this._gl.getParameterx(36006);this._gtkFboId=e?.deepUnpack()|0,this._initGLConstants(),this.DEFAULT_ATTACHMENTS=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT],this.DEFAULT_COLOR_ATTACHMENTS=[this.COLOR_ATTACHMENT0];let t=this.drawingBufferWidth||0,n=this.drawingBufferHeight||0;this._=sr++;let r=this.getParameter(this.MAX_COMBINED_TEXTURE_IMAGE_UNITS);this._textureUnits=Array.from({length:r});for(let e=0;e<r;++e)this._textureUnits[e]=new WebGLTextureUnit(this,e);this.activeTexture(this.TEXTURE0),this._defaultVertexObjectState=new WebGLVertexArrayObjectState(this),this._vertexObjectState=this._defaultVertexObjectState,this._vertexGlobalState=new WebGLVertexArrayGlobalState(this),this._maxTextureSize=this.getParameter(this.MAX_TEXTURE_SIZE),this._maxTextureLevel=Vn.log2(Vn.nextPow2(this._maxTextureSize)),this._maxCubeMapSize=this.getParameter(this.MAX_CUBE_MAP_TEXTURE_SIZE),this._maxCubeMapLevel=Vn.log2(Vn.nextPow2(this._maxCubeMapSize)),this._maxRenderbufferSize=this.getParameter(this.MAX_RENDERBUFFER_SIZE),this._unpackAlignment=4,this._packAlignment=4,this._unpackFlipY=!1,this._unpackPremultAlpha=!1,this.bindBuffer(this.ARRAY_BUFFER,null),this.bindBuffer(this.ELEMENT_ARRAY_BUFFER,null),this.bindFramebuffer(this.FRAMEBUFFER,null),this.bindRenderbuffer(this.RENDERBUFFER,null),this.viewport(0,0,t,n),this.scissor(0,0,t,n),this.clearDepth(1),this.clearColor(0,0,0,0),this.clearStencil(0),this.clear(this.COLOR_BUFFER_BIT|this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),this.disable(this.DEPTH_TEST),this.disable(this.STENCIL_TEST),this.disable(this.BLEND),this.disable(this.CULL_FACE),this.disable(this.POLYGON_OFFSET_FILL),this.disable(this.SCISSOR_TEST),this._gl.colorMask(!0,!0,!0,!0)}_initGLConstants(){let e=new or.WebGLRenderingContextBase().get_webgl_constants();for(let[t,n]of Object.entries(e))Object.defineProperty(this,t,{value:n})}_getGlslVersion(e){return this._getGlsl1Version(e)}_getGlsl1Version(e){return e||this._atLeastGlVersion(4,1)?`100`:`120`}_desktopGlslVersion(){let e=this._gl.getString(35724);if(!e||e.startsWith(`OpenGL ES `))return`130`;let[t,n]=e.split(`.`,2).map(e=>Number.parseInt(e,10));return!Number.isFinite(t)||!Number.isFinite(n)?`130`:String(t*100+(n>=10?n:n*10))}_atLeastGlVersion(e,t){let n=this._gl.getString(7938);if(!n||n.startsWith(`OpenGL ES `))return!1;let[r,i]=n.split(`.`,2).map(e=>Number.parseInt(e,10));return!Number.isFinite(r)||!Number.isFinite(i)?!1:r>e||r===e&&i>=t}_checkOwns(e){return typeof e==`object`&&!!e&&e._ctx===this}_checkValid(e,t){return e instanceof t&&e._!==0}_checkWrapper(e,t){return this._checkValid(e,t)?this._checkOwns(e)?!0:(this.setError(this.INVALID_OPERATION),!1):(this.setError(this.INVALID_VALUE),!1)}_isObject(e,t,n){if(e!=null&&!(e instanceof n))throw TypeError(t+`(`+n.name+`)`);return!!(this._checkValid(e,n)&&this._checkOwns(e))}_checkStencilState(){return this._checkStencil?(this._checkStencil=!1,this._stencilState=!0,(this.getParameter(this.STENCIL_WRITEMASK)!==this.getParameter(this.STENCIL_BACK_WRITEMASK)||this.getParameter(this.STENCIL_VALUE_MASK)!==this.getParameter(this.STENCIL_BACK_VALUE_MASK)||this.getParameter(this.STENCIL_REF)!==this.getParameter(this.STENCIL_BACK_REF))&&(this.setError(this.INVALID_OPERATION),this._stencilState=!1),this._stencilState):this._stencilState}_validGLSLIdentifier(e){return!(e.indexOf(`webgl_`)===0||e.indexOf(`_webgl_`)===0||e.length>256)}_getParameterDirect(e){return this._gl.getParameterx(e)?.deepUnpack()}getContextAttributes(){return this._contextAttributes}getExtension(e){let t=e.toLowerCase();if(t in this._extensions)return this._extensions[t];let n=cr[t]?cr[t](this):null;return n&&(this._extensions[t]=n),n}getSupportedExtensions(){let e=[`ANGLE_instanced_arrays`,`STACKGL_resize_drawingbuffer`,`STACKGL_destroy_context`,`WEBGL_debug_renderer_info`],t=this._gl.getSupportedExtensions();return t?(t.indexOf(`GL_OES_element_index_uint`)>=0&&e.push(`OES_element_index_uint`),t.indexOf(`GL_OES_standard_derivatives`)>=0&&e.push(`OES_standard_derivatives`),t.indexOf(`GL_OES_texture_float`)>=0&&e.push(`OES_texture_float`),t.indexOf(`GL_OES_texture_float_linear`)>=0&&e.push(`OES_texture_float_linear`),(t.indexOf(`GL_OES_texture_half_float`)>=0||t.indexOf(`GL_ARB_half_float_pixel`)>=0)&&e.push(`OES_texture_half_float`),(t.indexOf(`GL_EXT_color_buffer_float`)>=0||t.indexOf(`GL_ARB_color_buffer_float`)>=0)&&e.push(`EXT_color_buffer_float`),t.indexOf(`GL_EXT_color_buffer_half_float`)>=0&&e.push(`EXT_color_buffer_half_float`),t.indexOf(`EXT_draw_buffers`)>=0&&e.push(`WEBGL_draw_buffers`),t.indexOf(`EXT_blend_minmax`)>=0&&e.push(`EXT_blend_minmax`),t.indexOf(`EXT_texture_filter_anisotropic`)>=0&&e.push(`EXT_texture_filter_anisotropic`),t.indexOf(`GL_OES_vertex_array_object`)>=0&&e.push(`OES_vertex_array_object`),e):e}getParameter(e=0){switch(e){case this.ARRAY_BUFFER_BINDING:return this._vertexGlobalState._arrayBufferBinding;case this.ELEMENT_ARRAY_BUFFER_BINDING:return this._vertexObjectState._elementArrayBufferBinding;case this.CURRENT_PROGRAM:return this._activeProgram;case this.FRAMEBUFFER_BINDING:return this._activeFramebuffer;case this.RENDERBUFFER_BINDING:return this._activeRenderbuffer;case this.TEXTURE_BINDING_2D:return this._getActiveTextureUnit()._bind2D;case this.TEXTURE_BINDING_CUBE_MAP:return this._getActiveTextureUnit()._bindCube;case this.VERSION:return`WebGL 1.0 0.0.1`;case this.VENDOR:return``;case this.RENDERER:return`ANGLE`;case 37445:return this._gl.getString(7936);case 37446:return this._gl.getString(7937);case this.SHADING_LANGUAGE_VERSION:return`WebGL GLSL ES 1.0 `;case this.COMPRESSED_TEXTURE_FORMATS:return new Uint32Array;case this.SCISSOR_BOX:return new Int32Array(this._scissorBox);case this.VIEWPORT:return new Int32Array(this._viewport);case this.MAX_VIEWPORT_DIMS:return new Int32Array([32767,32767]);case this.ALIASED_LINE_WIDTH_RANGE:case this.ALIASED_POINT_SIZE_RANGE:return new Float32Array([1,1]);case this.DEPTH_RANGE:return new Float32Array([0,1]);case this.BLEND_COLOR:case this.COLOR_CLEAR_VALUE:return new Float32Array(this._gl.getParameterfv(e,4));case this.COLOR_WRITEMASK:{let t=this._gl.getParameteriv(e,4);return[!!t[0],!!t[1],!!t[2],!!t[3]]}case this.DEPTH_CLEAR_VALUE:case this.LINE_WIDTH:case this.POLYGON_OFFSET_FACTOR:case this.POLYGON_OFFSET_UNITS:case this.SAMPLE_COVERAGE_VALUE:return this._gl.getParameterf(e);case this.BLEND:case this.CULL_FACE:case this.DEPTH_TEST:case this.DEPTH_WRITEMASK:case this.DITHER:case this.POLYGON_OFFSET_FILL:case this.SAMPLE_COVERAGE_INVERT:case this.SCISSOR_TEST:case this.STENCIL_TEST:case this.UNPACK_PREMULTIPLY_ALPHA_WEBGL:return!!this._gl.getParameteri(e);case this.UNPACK_FLIP_Y_WEBGL:return this._unpackFlipY;case this.ACTIVE_TEXTURE:case this.ALPHA_BITS:case this.BLEND_DST_ALPHA:case this.BLEND_DST_RGB:case this.BLEND_EQUATION_ALPHA:case this.BLEND_EQUATION_RGB:case this.BLEND_SRC_ALPHA:case this.BLEND_SRC_RGB:case this.BLUE_BITS:case this.CULL_FACE_MODE:case this.DEPTH_BITS:case this.DEPTH_FUNC:case this.FRONT_FACE:case this.GENERATE_MIPMAP_HINT:case this.GREEN_BITS:return this._gl.getParameteri(e);case this.MAX_RENDERBUFFER_SIZE:return this._maxRenderbufferSize;case this.MAX_COMBINED_TEXTURE_IMAGE_UNITS:case this.MAX_CUBE_MAP_TEXTURE_SIZE:case this.MAX_FRAGMENT_UNIFORM_VECTORS:case this.MAX_TEXTURE_IMAGE_UNITS:case this.MAX_TEXTURE_SIZE:case this.MAX_VARYING_VECTORS:case this.MAX_VERTEX_ATTRIBS:case this.MAX_VERTEX_TEXTURE_IMAGE_UNITS:case this.MAX_VERTEX_UNIFORM_VECTORS:case this.PACK_ALIGNMENT:case this.RED_BITS:case this.SAMPLE_BUFFERS:case this.SAMPLES:case this.STENCIL_BACK_FAIL:case this.STENCIL_BACK_FUNC:case this.STENCIL_BACK_PASS_DEPTH_FAIL:case this.STENCIL_BACK_PASS_DEPTH_PASS:case this.STENCIL_BACK_REF:case this.STENCIL_BACK_VALUE_MASK:case this.STENCIL_BACK_WRITEMASK:case this.STENCIL_BITS:case this.STENCIL_CLEAR_VALUE:case this.STENCIL_FAIL:case this.STENCIL_FUNC:case this.STENCIL_PASS_DEPTH_FAIL:case this.STENCIL_PASS_DEPTH_PASS:case this.STENCIL_REF:case this.STENCIL_VALUE_MASK:case this.STENCIL_WRITEMASK:case this.SUBPIXEL_BITS:case this.UNPACK_ALIGNMENT:case this.UNPACK_COLORSPACE_CONVERSION_WEBGL:return this._gl.getParameteri(e);case this.IMPLEMENTATION_COLOR_READ_FORMAT:case this.IMPLEMENTATION_COLOR_READ_TYPE:return this._getParameterDirect(e);default:if(this._extensions.webgl_draw_buffers){let t=this._extensions.webgl_draw_buffers;switch(e){case t.DRAW_BUFFER0_WEBGL:case t.DRAW_BUFFER1_WEBGL:case t.DRAW_BUFFER2_WEBGL:case t.DRAW_BUFFER3_WEBGL:case t.DRAW_BUFFER4_WEBGL:case t.DRAW_BUFFER5_WEBGL:case t.DRAW_BUFFER6_WEBGL:case t.DRAW_BUFFER7_WEBGL:case t.DRAW_BUFFER8_WEBGL:case t.DRAW_BUFFER9_WEBGL:case t.DRAW_BUFFER10_WEBGL:case t.DRAW_BUFFER11_WEBGL:case t.DRAW_BUFFER12_WEBGL:case t.DRAW_BUFFER13_WEBGL:case t.DRAW_BUFFER14_WEBGL:case t.DRAW_BUFFER15_WEBGL:return t._buffersState.length===1&&t._buffersState[0]===this.BACK?this.BACK:this._getParameterDirect(e);case t.MAX_DRAW_BUFFERS_WEBGL:case t.MAX_COLOR_ATTACHMENTS_WEBGL:return this._getParameterDirect(e)}}let t=this._extensions.oes_standard_derivatives;if(t&&e===t.FRAGMENT_SHADER_DERIVATIVE_HINT_OES)return this._getParameterDirect(e);let n=this._extensions.ext_texture_filter_anisotropic;if(n&&e===n.MAX_TEXTURE_MAX_ANISOTROPY_EXT)return this._getParameterDirect(e);let r=this._extensions.oes_vertex_array_object;return r&&e===r.VERTEX_ARRAY_BINDING_OES?r._activeVertexArrayObject:(this.setError(this.INVALID_ENUM),null)}}destroy(){warnNotImplemented(`destroy`)}};installAllContextMethods(WebGLContextBase.prototype);var WebGLRenderingContext$1=class extends WebGLContextBase{static{__name$1(this,`WebGLRenderingContext`)}get _gl(){return this._native}constructor(e,t={}){super(e,t),this._attrib0Buffer=null,this._native=new or.WebGLRenderingContext({}),this._init();let n=this.createBuffer();this._attrib0Buffer=n}_beginAttrib0Hack(){this._native.bindBuffer(this.ARRAY_BUFFER,this._attrib0Buffer?._||0);let e=new Uint8Array(this._vertexGlobalState._attribs[0]._data.buffer);this._native.bufferData(this.ARRAY_BUFFER,Uint8ArrayToVariant(e),this.STREAM_DRAW),this._native.enableVertexAttribArray(0),this._native.vertexAttribPointer(0,4,this.FLOAT,!1,0,0),this._native._vertexAttribDivisor(0,1)}_endAttrib0Hack(){let e=this._vertexObjectState._attribs[0];e._pointerBuffer?this._native.bindBuffer(this.ARRAY_BUFFER,e._pointerBuffer._):this._native.bindBuffer(this.ARRAY_BUFFER,0),this._native.vertexAttribPointer(0,e._inputSize,e._pointerType,e._pointerNormal,e._inputStride,e._pointerOffset),this._native._vertexAttribDivisor(0,e._divisor),this._native.disableVertexAttribArray(0),this._vertexGlobalState._arrayBufferBinding?this._native.bindBuffer(this.ARRAY_BUFFER,this._vertexGlobalState._arrayBufferBinding._):this._native.bindBuffer(this.ARRAY_BUFFER,0)}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;if(n>0&&(i=n+t-1>>>0),this._checkVertexAttribState(i)){let n=this._extensions.webgl_draw_buffers;if(this._vertexObjectState._attribs[0]._isPointer||n&&n._buffersState&&n._buffersState.length>0)return this._native.drawArrays(e,t,r);this._beginAttrib0Hack(),this._native._drawArraysInstanced(e,t,r,1),this._endAttrib0Hack()}}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}if(this._checkVertexAttribState(c)&&s>0){if(this._vertexObjectState._attribs[0]._isPointer)return this._native.drawElements(e,s,n,r);this._beginAttrib0Hack(),this._native._drawElementsInstanced(e,s,n,r,1),this._endAttrib0Hack()}}},WebGLQuery=class extends Linkable{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._queries[this._|0],e._native2.deleteQuery(this._|0)}},WebGLSampler=class extends Linkable{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._samplers[this._|0],e._native2.deleteSampler(this._|0)}},WebGLSync=class extends Linkable{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._syncs[this._|0],e._native2.deleteSync(this._|0)}},WebGLTransformFeedback=class extends Linkable{constructor(e,t){super(e),this._ctx=t}_performDelete(){let e=this._ctx;delete e._transformFeedbacks[this._|0],e._native2.deleteTransformFeedback(this._|0)}},WebGLVertexArrayObject=class extends Linkable{constructor(e,t){super(e),this._ctx=t,this._objectState=new WebGLVertexArrayObjectState(t)}_performDelete(){let e=this._ctx;e._vertexObjectState===this._objectState&&(e._vertexObjectState=e._defaultVertexObjectState),this._objectState.cleanUp(),delete e._vertexArrayObjects[this._|0],e._native2.deleteVertexArray(this._|0)}};const lr={createVertexArray(){let e=this._native2.createVertexArray();if(!e)return null;let t=new WebGLVertexArrayObject(e,this);return this._vertexArrayObjects[e]=t,t},deleteVertexArray(e){!e||!(e instanceof WebGLVertexArrayObject)||(e._pendingDelete=!0,e._checkDelete())},isVertexArray(e){return!e||!(e instanceof WebGLVertexArrayObject)?!1:this._native2.isVertexArray(e._)},bindVertexArray(e){e===null?(this._native2.bindVertexArray(0),this._vertexObjectState=this._defaultVertexObjectState):e instanceof WebGLVertexArrayObject?(this._native2.bindVertexArray(e._),this._vertexObjectState=e._objectState):this.setError(this.INVALID_OPERATION)},createQuery(){let e=this._native2.createQuery();if(!e)return null;let t=new WebGLQuery(e,this);return this._queries[e]=t,t},deleteQuery(e){!e||!(e instanceof WebGLQuery)||(e._pendingDelete=!0,e._checkDelete())},isQuery(e){return!e||!(e instanceof WebGLQuery)?!1:this._native2.isQuery(e._)},beginQuery(e,t){t instanceof WebGLQuery&&this._native2.beginQuery(e,t._)},endQuery(e){this._native2.endQuery(e)},getQuery(e,t){return warnNotImplemented(`WebGL2RenderingContext.getQuery`),null},getQueryParameter(e,t){return e instanceof WebGLQuery?this._native2.getQueryParameter(e._,t):null},createSampler(){let e=this._native2.createSampler();if(!e)return null;let t=new WebGLSampler(e,this);return this._samplers[e]=t,t},deleteSampler(e){!e||!(e instanceof WebGLSampler)||(e._pendingDelete=!0,e._checkDelete())},isSampler(e){return!e||!(e instanceof WebGLSampler)?!1:this._native2.isSampler(e._)},bindSampler(e,t){this._native2.bindSampler(e,t?t._:0)},samplerParameteri(e,t,n){e instanceof WebGLSampler&&this._native2.samplerParameteri(e._,t,n)},samplerParameterf(e,t,n){e instanceof WebGLSampler&&this._native2.samplerParameterf(e._,t,n)},getSamplerParameter(e,t){return e instanceof WebGLSampler?t===33082||t===33083?this._native2.getSamplerParameterf(e._,t):this._native2.getSamplerParameteri(e._,t):null},fenceSync(e,t){let n=this._native2.fenceSync(e,t);if(!n)return null;let r=new WebGLSync(n,this);return this._syncs[n]=r,r},isSync(e){return!e||!(e instanceof WebGLSync)?!1:this._native2.isSync(e._)},deleteSync(e){!e||!(e instanceof WebGLSync)||(e._pendingDelete=!0,e._checkDelete())},clientWaitSync(e,t,n){return e instanceof WebGLSync?this._native2.clientWaitSync(e._,t,n):37148},waitSync(e,t,n){e instanceof WebGLSync&&this._native2.waitSync(e._,t,n)},getSyncParameter(e,t){return e instanceof WebGLSync?this._native2.getSyncParameter(e._,t):null},createTransformFeedback(){let e=this._native2.createTransformFeedback();if(!e)return null;let t=new WebGLTransformFeedback(e,this);return this._transformFeedbacks[e]=t,t},deleteTransformFeedback(e){!e||!(e instanceof WebGLTransformFeedback)||(e._pendingDelete=!0,e._checkDelete())},isTransformFeedback(e){return!e||!(e instanceof WebGLTransformFeedback)?!1:this._native2.isTransformFeedback(e._)},bindTransformFeedback(e,t){this._native2.bindTransformFeedback(e,t?t._:0)},beginTransformFeedback(e){this._native2.beginTransformFeedback(e)},endTransformFeedback(){this._native2.endTransformFeedback()},pauseTransformFeedback(){this._native2.pauseTransformFeedback()},resumeTransformFeedback(){this._native2.resumeTransformFeedback()},transformFeedbackVaryings(e,t,n){this._native2.transformFeedbackVaryings(e._,t,n)},getTransformFeedbackVarying(e,t){let n=this._native2.getTransformFeedbackVarying(e._,t).deepUnpack();return new WebGLActiveInfo({size:n.size,type:n.type,name:n.name})}};function installObjectLifecycleMethods(e){Object.assign(e,lr)}const ur={texImage3D(e,t,n,r,i,a,o,s,c,l){l===null?this._native2.texImage3DNull(e,t,n,r,i,a,o,s,c):this._native2.texImage3D(e,t,n,r,i,a,o,s,c,Uint8ArrayToVariant(new Uint8Array(l.buffer,l.byteOffset,l.byteLength)))},texSubImage3D(e,t,n,r,i,a,o,s,c,l,u){u!==null&&this._native2.texSubImage3D(e,t,n,r,i,a,o,s,c,l,Uint8ArrayToVariant(new Uint8Array(u.buffer,u.byteOffset,u.byteLength)))},compressedTexImage3D(e,t,n,r,i,a,o,s,c){this._native2.compressedTexImage3D(e,t,n,r,i,a,o,Uint8ArrayToVariant(new Uint8Array(c.buffer,c.byteOffset,c.byteLength)))},compressedTexSubImage3D(e,t,n,r,i,a,o,s,c,l,u){this._native2.compressedTexSubImage3D(e,t,n,r,i,a,o,s,c,Uint8ArrayToVariant(new Uint8Array(u.buffer,u.byteOffset,u.byteLength)))},copyTexSubImage3D(e,t,n,r,i,a,o,s,c){this._native2.copyTexSubImage3D(e,t,n,r,i,a,o,s,c)},texStorage2D(e,t,n,r,i){this._native2.texStorage2D(e,t,n,r,i);let a=this._getTexImage(e);if(a){for(let e=0;e<t;e++)a._levelWidth[e]=Math.max(1,r>>e),a._levelHeight[e]=Math.max(1,i>>e);a._format=this.RGBA,a._type=this.UNSIGNED_BYTE}},texStorage3D(e,t,n,r,i,a){this._native2.texStorage3D(e,t,n,r,i,a)}};function installTexImage3DMethods(e){Object.assign(e,ur)}const dr={uniform1ui(e,t){e&&this._native2.uniform1ui(e._,t)},uniform2ui(e,t,n){e&&this._native2.uniform2ui(e._,t,n)},uniform3ui(e,t,n,r){e&&this._native2.uniform3ui(e._,t,n,r)},uniform4ui(e,t,n,r,i){e&&this._native2.uniform4ui(e._,t,n,r,i)},uniform1uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform1uiv(e._,i.length,i)},uniform2uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform2uiv(e._,i.length/2,i)},uniform3uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform3uiv(e._,i.length/3,i)},uniform4uiv(e,t,n,r){if(!e)return;let i=t instanceof Uint32Array?t:new Uint32Array(t);this._native2.uniform4uiv(e._,i.length/4,i)},uniformMatrix2x3fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix2x3fv(e._,t,a)},uniformMatrix3x2fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix3x2fv(e._,t,a)},uniformMatrix2x4fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix2x4fv(e._,t,a)},uniformMatrix4x2fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix4x2fv(e._,t,a)},uniformMatrix3x4fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix3x4fv(e._,t,a)},uniformMatrix4x3fv(e,t,n,r,i){if(!e)return;let a=n instanceof Float32Array?n:new Float32Array(n);this._native2.uniformMatrix4x3fv(e._,t,a)}};function installUniformMethods(e){Object.assign(e,dr)}const fr={clearBufferfv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferfv==`function`){i.clearBufferfv(e,t,Array.from(n));return}let a=n;if(e===6144){let e=this.getParameter(this.COLOR_CLEAR_VALUE);this.clearColor(a[0]??0,a[1]??0,a[2]??0,a[3]??0),this.clear(this.COLOR_BUFFER_BIT),e&&this.clearColor(e[0],e[1],e[2],e[3])}else if(e===6145){let e=this.getParameter(this.DEPTH_CLEAR_VALUE);this.clearDepth(a[0]??1),this.clear(this.DEPTH_BUFFER_BIT),e!==null&&this.clearDepth(e)}},clearBufferiv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferiv==`function`){i.clearBufferiv(e,t,Array.from(n));return}if(e===6146){let e=n,t=this.getParameter(this.STENCIL_CLEAR_VALUE);this.clearStencil(e[0]??0),this.clear(this.STENCIL_BUFFER_BIT),t!==null&&this.clearStencil(t)}},clearBufferuiv(e,t,n,r){let i=this._native2;if(typeof i.clearBufferuiv==`function`){i.clearBufferuiv(e,t,Array.from(n));return}},clearBufferfi(e,t,n,r){let i=this._native2;if(typeof i.clearBufferfi==`function`){i.clearBufferfi(e,t,n,r);return}if(e===34041){let e=this.getParameter(this.DEPTH_CLEAR_VALUE),t=this.getParameter(this.STENCIL_CLEAR_VALUE);this.clearDepth(n),this.clearStencil(r),this.clear(this.DEPTH_BUFFER_BIT|this.STENCIL_BUFFER_BIT),e!==null&&this.clearDepth(e),t!==null&&this.clearStencil(t)}}};function installClearBufferMethods(e){Object.assign(e,fr)}function debugGlEnabled(){return globalThis.__GJSIFY_DEBUG_GL===!0}const pr={drawArraysInstanced(e,t,n,r){if(t<0||n<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let i=vertexCount(this,e,n);if(i<0){this.setError(this.INVALID_ENUM);return}if(this._framebufferOk()&&!(n===0||r===0)&&this._checkVertexAttribState(n+t-1>>>0)){if(debugGlEnabled()){let e=this,t=e.__drawInstCount=(e.__drawInstCount|0)+1;(t<=5||t%100==0)&&console.log(`[WebGL] drawArraysInstanced #${t} count=${i} instances=${r} fbo=${this._activeFramebuffer?._??`_gtkFbo`}`)}this._native2.drawArraysInstanced(e,t,i,r)}},drawElementsInstanced(e,t,n,r,i){if(t<0||r<0||i<0){this.setError(this.INVALID_VALUE);return}if(!this._checkStencilState())return;let a=this._vertexObjectState._elementArrayBufferBinding;if(!a){this.setError(this.INVALID_OPERATION);return}let o=null,s=r;if(n===this.UNSIGNED_SHORT){if(s%2){this.setError(this.INVALID_OPERATION);return}s>>=1,o=new Uint16Array(a._elements.buffer)}else if(n===this.UNSIGNED_INT){if(s%4){this.setError(this.INVALID_OPERATION);return}s>>=2,o=new Uint32Array(a._elements.buffer)}else if(n===this.UNSIGNED_BYTE)o=a._elements;else{this.setError(this.INVALID_ENUM);return}let c=t;switch(e){case this.TRIANGLES:t%3&&(c-=t%3);break;case this.LINES:t%2&&(c-=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(c===0||i===0){this._checkVertexAttribState(0);return}if(c+s>>>0>o.length){this.setError(this.INVALID_OPERATION);return}let l=0;for(let e=s;e<s+c;++e)o[e]>l&&(l=o[e]);this._checkVertexAttribState(l)&&this._native2.drawElementsInstanced(e,c,n,r,i)},vertexAttribDivisor(e,t){this._checkVertexIndex(e)&&(this._native2.vertexAttribDivisor(e,t),this._vertexObjectState._attribs[e]._divisor=t)},vertexAttribIPointer(e,t,n,r,i){this._native2.vertexAttribIPointer(e,t,n,r,i)},drawBuffers(e){let t=!1;for(let n=0;n<e.length;n++)if(e[n]===1029){t=!0;break}if(!t){this._native2.drawBuffers(e);return}this._native2.drawBuffers(e.map(e=>e===1029?this.COLOR_ATTACHMENT0:e))},drawRangeElements(e,t,n,r,i,a){if(r<0||a<0){this.setError(this.INVALID_VALUE);return}if(n<t){this.setError(this.INVALID_VALUE);return}this.drawElements(e,r,i,a)},blitFramebuffer(e,t,n,r,i,a,o,s,c,l){if(debugGlEnabled()){let e=this._gl.getError();e!==0&&console.log(`[WebGL] blitFramebuffer PRE-ERROR 0x${e.toString(16)}`)}if(this._native2.blitFramebuffer(e,t,n,r,i,a,o,s,c,l),debugGlEnabled()){let i=this._gl.getError(),a=this,o=a.__blitCount=(a.__blitCount|0)+1;o<=5&&console.log(`[WebGL] blitFramebuffer #${o} src=(${e},${t},${n},${r}) readFbo=${this._activeReadFramebuffer?._??`_gtkFbo`} err=${i===0?`OK`:`0x`+i.toString(16)}`)}},framebufferTextureLayer(e,t,n,r,i){this._native2.framebufferTextureLayer(e,t,n?n._:0,r,i)},invalidateFramebuffer(e,t){this._native2.invalidateFramebuffer(e,t)},invalidateSubFramebuffer(e,t,n,r,i,a){this._native2.invalidateSubFramebuffer(e,t,n,r,i,a)},readBuffer(e){this._native2.readBuffer(e)},renderbufferStorageMultisample(e,t,n,r,i){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let a=this._activeRenderbuffer;if(!a){this.setError(this.INVALID_OPERATION);return}this._saveError(),this._native2.renderbufferStorageMultisample(e,t,n,r,i);let o=this.getError();this._restoreError(o),o===this.NO_ERROR&&(a._width=r,a._height=i,a._format=n)}};function installInstancedAndFramebufferOpsMethods(e){Object.assign(e,pr)}var mr=class WebGL2RenderingContext extends WebGLContextBase{get _gl(){return this._native2}constructor(e,t={}){super(e,t),this._queries={},this._samplers={},this._transformFeedbacks={},this._vertexArrayObjects={},this._syncs={},this._activeReadFramebuffer=null,this._activeDrawFramebuffer=null,this._native2=new or.WebGL2RenderingContext({}),this._init()}_getGlslVersion(e){return e?`300 es`:this._desktopGlslVersion()}_validFramebufferAttachment(e){return super._validFramebufferAttachment(e)?!0:e>=36065&&e<=36079}static{this._WGL2_ALL_COLOR_ATTACHMENTS=[36064,36065,36066,36067,36068,36069,36070,36071,36072,36073,36074,36075,36076,36077,36078,36079]}_getColorAttachments(){return WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS}_preCheckFramebufferStatus(e){let t=e._attachments,n=0,r=0,i=[this.COLOR_ATTACHMENT0,this.DEPTH_ATTACHMENT,this.STENCIL_ATTACHMENT,this.DEPTH_STENCIL_ATTACHMENT,...WebGL2RenderingContext._WGL2_ALL_COLOR_ATTACHMENTS];for(let a of i){let i=t[a];if(i){if(i instanceof WebGLTexture){let t=e._attachmentLevel[a]??0,o=i._levelWidth[t]??0,s=i._levelHeight[t]??0;if(o>0&&s>0){n=o,r=s;break}}else if(i instanceof WebGLRenderbuffer&&i._width>0&&i._height>0){n=i._width,r=i._height;break}}}return n>0&&r>0?(e._width=n,e._height=r,this.FRAMEBUFFER_COMPLETE):this.FRAMEBUFFER_INCOMPLETE_ATTACHMENT}_updateFramebufferAttachments(e){if(super._updateFramebufferAttachments(e),e)for(let t=1;t<=15;t++){let n=36064+t;if(!(n in e._attachments))continue;let r=e._attachments[n];if(r instanceof WebGLTexture){let t=e._attachmentFace[n]||this.TEXTURE_2D,i=e._attachmentLevel[n]??0;this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,t,r._|0,i|0)}else r instanceof WebGLRenderbuffer?this._gl.framebufferRenderbuffer(this.FRAMEBUFFER,n,this.RENDERBUFFER,r._|0):this._gl.framebufferTexture2D(this.FRAMEBUFFER,n,this.TEXTURE_2D,0,0)}}bindBuffer(e,t){if(e===35345||e===35982||e===36662||e===36663){let n=t?t._|0:0;this._gl.bindBuffer(e,n);return}super.bindBuffer(e,t)}bindFramebuffer(e,t){if(e===36008||e===36009){if(!checkObject(t))throw TypeError(`bindFramebuffer(GLenum, WebGLFramebuffer)`);if(t&&t._pendingDelete||t&&!this._checkWrapper(t,WebGLFramebuffer))return;let n=t?t._|0:this._gtkFboId;if(this._gl.bindFramebuffer(e,n),e===36008){let e=this._activeReadFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeReadFramebuffer=t}else{let e=this._activeDrawFramebuffer;e!==t&&(e&&(--e._refCount,e._checkDelete()),t&&(t._refCount+=1)),this._activeDrawFramebuffer=t,this._activeFramebuffer=t}return}super.bindFramebuffer(this.FRAMEBUFFER,t),this._activeReadFramebuffer=t,this._activeDrawFramebuffer=t}deleteFramebuffer(e){this._activeReadFramebuffer===e&&this.bindFramebuffer(36008,null),this._activeDrawFramebuffer===e&&this.bindFramebuffer(36009,null),super.deleteFramebuffer(e)}bufferData(e,t,n){let r=e===35345||e===35982||e===36662||e===36663,i=n===35041||n===35043||n===35045||n===35042||n===35044||n===35046?this.STATIC_DRAW:n;if(r){if(typeof t==`number`)t>=0&&this._gl.bufferDataSizeOnly(e,t,i);else if(typeof t==`object`&&t){let n=arrayToUint8Array(t);this._gl.bufferData(e,Uint8ArrayToVariant(n),i)}return}super.bufferData(e,t,i)}bufferSubData(e,t,n){if(e===35345||e===35982||e===36662||e===36663){if(t<0){this.setError(this.INVALID_VALUE);return}if(!n){this.setError(this.INVALID_VALUE);return}let r=arrayToUint8Array(n);this._gl.bufferSubData(e,t,Uint8ArrayToVariant(r));return}super.bufferSubData(e,t,n)}bindTexture(e,t){if(e===32879||e===35866){let n=t,r=n?n._|0:0;this._gl.bindTexture(e,r),n&&(n._binding=e);return}super.bindTexture(e,t)}texParameteri(e,t,n){if(e===32879||e===35866){this._gl.texParameteri(e,t,n);return}if(t===32882||t===34892||t===34893||t===33084||t===33085||t===33083||t===33082){this._gl.texParameteri(e,t,n);return}super.texParameteri(e,t,n)}drawArrays(e,t,n){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}this._framebufferOk()&&n!==0&&this._checkVertexAttribState(n+t-1>>>0)&&this._native2.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(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()||t===0)return;let c=0;for(let e=o;e<o+s;++e)e<a.length&&a[e]>c&&(c=a[e]);this._checkVertexAttribState(c)&&this._native2.drawElements(e,s,n,r)}bindBufferBase(e,t,n){this._native2.bindBufferBase(e,t,n?n._:0)}bindBufferRange(e,t,n,r,i){this._native2.bindBufferRange(e,t,n?n._:0,r,i)}copyBufferSubData(e,t,n,r,i){this._native2.copyBufferSubData(e,t,n,r,i)}getBufferSubData(e,t,n,r,i){let a=i===void 0?n.byteLength-(r??0):i,o=this._native2.getBufferSubData(e,t,a),s=new Uint8Array(n.buffer,n.byteOffset+(r??0)*(n instanceof Uint8Array?1:n.BYTES_PER_ELEMENT??1));s.set(o.subarray(0,s.byteLength))}texImage2D(e=0,t=0,n=0,r=0,i=0,a=0,o=0,s=0,c){let l=0,u=0,d=0,f=0;if(arguments.length===6)if(s=i,d=r,a instanceof St.Pixbuf){let e=a;l=e.get_width(),u=e.get_height(),c=e.get_pixels()}else{let e=extractImageData(a);if(e==null)throw TypeError(`texImage2D(GLenum, GLint, GLenum, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);l=e.width,u=e.height,c=e.data}else arguments.length>=9&&(l=r,u=i,f=a,d=o);let p=this._getTexImage(e);if(!p){this.setError(this.INVALID_OPERATION);return}let m=convertPixels(c);if(this._unpackPremultAlpha&&m&&d===this.RGBA&&(m=premultiplyAlpha(m)),this._unpackFlipY&&m&&l>0&&u>0){let e=this._computePixelSize(s,d);if(e>0){let t=this._computeRowStride(l,e),n=new Uint8Array(m.length);for(let e=0;e<u;e++){let r=e*t,i=(u-1-e)*t;n.set(m.subarray(r,r+t),i)}m=n}}this._saveError(),this._gl.texImage2D(e,t,n,l,u,f,d,s,Uint8ArrayToVariant(m));let h=this.getError();if(this._restoreError(h),h!==this.NO_ERROR)return;p._levelWidth[t]=l,p._levelHeight[t]=u,p._format=d,p._type=s;let g=this._activeFramebuffer;if(g){let e=!1,t=this._getAttachments();for(let n=0;n<t.length;++n)if(g._attachments[t[n]]===p){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 l=0,u=0,d=0;if(arguments.length===7)if(s=a,d=i,o instanceof St.Pixbuf){let e=o;l=e.get_width(),u=e.get_height(),c=e.get_pixels()}else{let e=extractImageData(o);if(e==null)throw TypeError(`texSubImage2D(GLenum, GLint, GLint, GLint, GLenum, GLenum, ImageData | HTMLImageElement | HTMLCanvasElement | HTMLVideoElement)`);l=e.width,u=e.height,c=e.data}else l=i,u=a,d=o;if(!this._getTexImage(e)){this.setError(this.INVALID_OPERATION);return}let f=convertPixels(c);if(!f){this.setError(this.INVALID_OPERATION);return}if(this._unpackPremultAlpha&&f&&d===this.RGBA&&(f=premultiplyAlpha(f)),this._unpackFlipY&&f&&l>0&&u>0){let e=this._computePixelSize(s,d);if(e>0){let t=this._computeRowStride(l,e),n=new Uint8Array(f.length);for(let e=0;e<u;e++){let r=e*t,i=(u-1-e)*t;n.set(f.subarray(r,r+t),i)}f=n}}this._gl.texSubImage2D(e,t,n,r,l,u,d,s,Uint8ArrayToVariant(f))}getUniform(e,t){let n=t?._activeInfo?.type,r=5125,i=36294,a=36295,o=n===r||n===i||n===a||n===36296,s=e;if(!o)return super.getUniform(s,t);if(!e||!t)return null;let c=this._native2.getUniformi(s._|0,t._|0);return c?n===r?c[0]>>>0:n===i?new Uint32Array([c[0]>>>0,c[1]>>>0]):n===a?new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0]):new Uint32Array([c[0]>>>0,c[1]>>>0,c[2]>>>0,c[3]>>>0]):null}getUniformBlockIndex(e,t){return this._native2.getUniformBlockIndex(e._,t)}uniformBlockBinding(e,t,n){this._native2.uniformBlockBinding(e._,t,n)}getActiveUniformBlockName(e,t){let n=this._native2.getActiveUniformBlockName(e._,t);return n.length>0?n:null}getActiveUniformBlockParameter(e,t,n){return this._native2.getActiveUniformBlockParameter(e._,t,n)}getActiveUniforms(e,t,n){return this._native2.getActiveUniforms(e._,t,n)}getFragDataLocation(e,t){return this._native2.getFragDataLocation(e._,t)}getIndexedParameter(e,t){return this._native2.getIndexedParameteri(e,t)}getInternalformatParameter(e,t,n){return this._native2.getInternalformatParameter(e,t,n)}getParameter(e){if(e===7938)return`WebGL 2.0`;if(e===35724)return`WebGL GLSL ES 3.00`;if(e===7939)return warnNotImplemented(`WebGL2RenderingContext.getParameter(GL_EXTENSIONS)`),``;if(e===36006)return this._activeDrawFramebuffer;if(e===36010)return this._activeReadFramebuffer;switch(e){case 36183:case 35071:case 32883:case 36063:case 34852:case 36203:case 33001:case 33e3:case 37157:case 35373:case 35657:case 35077:case 35978:case 35979:case 35968:case 35376:case 35375:case 35659:case 37154:case 35371:case 35658:case 35379:case 35374:case 35377:case 35076:case 3330:case 3332:case 3331:case 35053:case 35055:case 3074:case 32874:case 35869:case 36389:case 35983:case 35368:case 35380:case 32878:case 3314:case 32877:case 3316:case 3315:case 34045:return this._native2.getParameterx(e)?.deepUnpack()|0;case 35977:case 36388:case 36387:return!!this._native2.getParameterx(e)?.deepUnpack()}return super.getParameter(e)}getStringi(e,t){let n=this._native2.getStringi(e,t);return n.length>0?n:null}renderbufferStorage(e,t,n,r){if(e!==this.RENDERBUFFER){this.setError(this.INVALID_ENUM);return}let i=this._activeRenderbuffer;if(!i){this.setError(this.INVALID_OPERATION);return}if(n<0||r<0){this.setError(this.INVALID_VALUE);return}for(;this._gl.getError()!==this.NO_ERROR;);if(this._gl.renderbufferStorage(e,t,n,r),this._gl.getError()!==this.NO_ERROR)return;i._width=n,i._height=r,i._format=t;let a=this._activeFramebuffer;if(a){let e=this._getAttachments(),t=!1;for(let n=0;n<e.length;++n)if(a._attachments[e[n]]===i){t=!0;break}t&&this._updateFramebufferAttachments(a)}}getSupportedExtensions(){let e=super.getSupportedExtensions();for(let t of[`EXT_color_buffer_float`,`EXT_color_buffer_half_float`,`OES_texture_half_float`])e.indexOf(t)===-1&&e.push(t);return e}readPixels(e,t,n,r,i,a,o){if(!o)return;if(n<0||r<0){this.setError(this.INVALID_VALUE);return}if(!this._framebufferOk())return;let s=i===6408||i===32856?4:i===6407?3:i===33319?2:1,c=a===5126?4:a===5131||a===36193?2:a===5125||a===5124?4:a===5123||a===5122?2:1,l=n*r*s*c,u=new Uint8Array(l);this._saveError();let d=this._gl.readPixels(e,t,n,r,i,a,Uint8ArrayToVariant(u)),f=this.getError();if(this._restoreError(f),f!==this.NO_ERROR)return;let p=d&&d.length>0?d:u;if(o instanceof Uint8Array)o.set(p);else if(o instanceof Float32Array){let e=new Float32Array(p.buffer,0,o.length);o.set(e)}}_framebufferOk(){return!0}};installObjectLifecycleMethods(mr.prototype),installTexImage3DMethods(mr.prototype),installUniformMethods(mr.prototype),installClearBufferMethods(mr.prototype),installInstancedAndFramebufferOpsMethods(mr.prototype);function notifyElementResize(e,t,n){e._allocatedClientWidth=t,e._allocatedClientHeight=n,e._fireResizeSubscribers(t,n);let r=e.parentNode;for(;r;)r instanceof Element&&(r._allocatedClientWidth=t,r._allocatedClientHeight=n,r._fireResizeSubscribers(t,n)),r=r.parentNode}var HTMLCanvasElement$1=class extends Be{static{__name$1(this,`HTMLCanvasElement`)}constructor(e){super(),this.gtkGlArea=e}get width(){return this.gtkGlArea.get_allocated_width()*this.scaleFactor}set width(e){}get height(){return this.gtkGlArea.get_allocated_height()*this.scaleFactor}set height(e){}get scaleFactor(){return this.gtkGlArea.get_scale_factor()||1}get clientWidth(){return this.gtkGlArea.get_allocated_width()}get clientHeight(){return this.gtkGlArea.get_allocated_height()}get offsetWidth(){return this.clientWidth}get offsetHeight(){return this.clientHeight}getGlArea(){return this.gtkGlArea}_createCloneTarget(){let e=new Be;return e.width=this.width,e.height=this.height,e}getContext(e,t){return e===`webgl`||e===`experimental-webgl`?(this._webgl||=(this.gtkGlArea.make_current(),new WebGLRenderingContext$1(this,t)),this._webgl):e===`webgl2`?(this._webgl2||=(this.gtkGlArea.make_current(),new mr(this,t)),this._webgl2):super.getContext(e,t)}};const hr=[`apple software renderer`,`llvmpipe`,`softpipe`,`swrast`,`swiftshader`,`microsoft basic render driver`,`mesa offscreen`];function isSoftwareRenderer(e){if(!e)return!1;let t=e.toLowerCase();return hr.some(e=>t.includes(e))}const gr={Return:`Enter`,KP_Enter:`Enter`,Tab:`Tab`,ISO_Left_Tab:`Tab`,BackSpace:`Backspace`,Escape:`Escape`,Delete:`Delete`,KP_Delete:`Delete`,Insert:`Insert`,KP_Insert:`Insert`,Home:`Home`,KP_Home:`Home`,End:`End`,KP_End:`End`,Page_Up:`PageUp`,KP_Page_Up:`PageUp`,Page_Down:`PageDown`,KP_Page_Down:`PageDown`,Left:`ArrowLeft`,KP_Left:`ArrowLeft`,Up:`ArrowUp`,KP_Up:`ArrowUp`,Right:`ArrowRight`,KP_Right:`ArrowRight`,Down:`ArrowDown`,KP_Down:`ArrowDown`,Shift_L:`Shift`,Shift_R:`Shift`,Control_L:`Control`,Control_R:`Control`,Alt_L:`Alt`,Alt_R:`Alt`,Super_L:`Meta`,Super_R:`Meta`,Meta_L:`Meta`,Meta_R:`Meta`,Caps_Lock:`CapsLock`,Num_Lock:`NumLock`,Scroll_Lock:`ScrollLock`,Print:`PrintScreen`,Pause:`Pause`,Menu:`ContextMenu`,space:` `,F1:`F1`,F2:`F2`,F3:`F3`,F4:`F4`,F5:`F5`,F6:`F6`,F7:`F7`,F8:`F8`,F9:`F9`,F10:`F10`,F11:`F11`,F12:`F12`,KP_Add:`+`,KP_Subtract:`-`,KP_Multiply:`*`,KP_Divide:`/`,KP_Decimal:`.`,KP_Separator:`,`,KP_0:`0`,KP_1:`1`,KP_2:`2`,KP_3:`3`,KP_4:`4`,KP_5:`5`,KP_6:`6`,KP_7:`7`,KP_8:`8`,KP_9:`9`},_r={Return:`Enter`,KP_Enter:`NumpadEnter`,Tab:`Tab`,ISO_Left_Tab:`Tab`,BackSpace:`Backspace`,Escape:`Escape`,Delete:`Delete`,KP_Delete:`NumpadDecimal`,Insert:`Insert`,KP_Insert:`Numpad0`,Home:`Home`,KP_Home:`Numpad7`,End:`End`,KP_End:`Numpad1`,Page_Up:`PageUp`,KP_Page_Up:`Numpad9`,Page_Down:`PageDown`,KP_Page_Down:`Numpad3`,Left:`ArrowLeft`,KP_Left:`Numpad4`,Up:`ArrowUp`,KP_Up:`Numpad8`,Right:`ArrowRight`,KP_Right:`Numpad6`,Down:`ArrowDown`,KP_Down:`Numpad2`,Shift_L:`ShiftLeft`,Shift_R:`ShiftRight`,Control_L:`ControlLeft`,Control_R:`ControlRight`,Alt_L:`AltLeft`,Alt_R:`AltRight`,Super_L:`MetaLeft`,Super_R:`MetaRight`,Meta_L:`MetaLeft`,Meta_R:`MetaRight`,Caps_Lock:`CapsLock`,Num_Lock:`NumLock`,Scroll_Lock:`ScrollLock`,Print:`PrintScreen`,Pause:`Pause`,Menu:`ContextMenu`,space:`Space`,F1:`F1`,F2:`F2`,F3:`F3`,F4:`F4`,F5:`F5`,F6:`F6`,F7:`F7`,F8:`F8`,F9:`F9`,F10:`F10`,F11:`F11`,F12:`F12`,KP_Add:`NumpadAdd`,KP_Subtract:`NumpadSubtract`,KP_Multiply:`NumpadMultiply`,KP_Divide:`NumpadDivide`,KP_Decimal:`NumpadDecimal`,KP_Separator:`NumpadComma`,KP_0:`Numpad0`,KP_1:`Numpad1`,KP_2:`Numpad2`,KP_3:`Numpad3`,KP_4:`Numpad4`,KP_5:`Numpad5`,KP_6:`Numpad6`,KP_7:`Numpad7`,KP_8:`Numpad8`,KP_9:`Numpad9`};function gdkKeyvalToKey(e){let t=yt.keyval_name(e);if(t&&gr[t])return gr[t];let n=yt.keyval_to_unicode(e);return n>0?String.fromCodePoint(n):t??`Unidentified`}function gdkKeyvalToCode(e){let t=yt.keyval_name(e);if(t&&_r[t])return _r[t];let n=yt.keyval_to_unicode(e);if(n>=97&&n<=122)return`Key`+String.fromCodePoint(n-32);if(n>=65&&n<=90)return`Key`+String.fromCodePoint(n);if(n>=48&&n<=57)return`Digit`+String.fromCodePoint(n);if(t){let e={minus:`Minus`,equal:`Equal`,bracketleft:`BracketLeft`,bracketright:`BracketRight`,backslash:`Backslash`,semicolon:`Semicolon`,apostrophe:`Quote`,grave:`Backquote`,comma:`Comma`,period:`Period`,slash:`Slash`};if(e[t])return e[t]}return t??`Unidentified`}function gdkKeyvalToLocation(e){let t=yt.keyval_name(e);return t?t.startsWith(`KP_`)?3:t.endsWith(`_L`)?1:t.endsWith(`_R`)?2:0:0}const vr=.5;var TouchPointerTranslator=class{constructor(e,t){this.getElement=e,this.getWindowTarget=t,this.active=new Map,this.nextId=2}get activeCount(){return this.active.size}handle(e){switch(e.phase){case`begin`:this.begin(e);break;case`update`:this.update(e);break;case`end`:this.end(e);break;case`cancel`:this.cancel(e);break}}cancelAll(e){for(let[t,n]of this.active)this.cancel({...e,phase:`cancel`,key:t,x:n.lastX,y:n.lastY,isPrimary:n.isPrimary})}begin(e){this.active.has(e.key)&&this.cancel(e);let t=this.getElement();if(!t)return;let n={id:this.nextId++,isPrimary:e.isPrimary,lastX:e.x,lastY:e.y,preventMouse:!1};this.active.set(e.key,n);let r=this.pointerInit(e,n,-1,0,0),i=this.mouseInit(e,0,0);n.isPrimary&&t.dispatchEvent(new MouseEvent(`mousemove`,i)),t.dispatchEvent(new PointerEvent(`pointerover`,r)),t.dispatchEvent(new PointerEvent(`pointerenter`,{...r,bubbles:!1,cancelable:!1})),n.isPrimary&&(t.dispatchEvent(new MouseEvent(`mouseover`,i)),t.dispatchEvent(new MouseEvent(`mouseenter`,{...i,bubbles:!1,cancelable:!1})));let a=new PointerEvent(`pointerdown`,this.pointerInit(e,n,0,1,vr));t.dispatchEvent(a),n.isPrimary&&(n.preventMouse=a.defaultPrevented,n.preventMouse||t.dispatchEvent(new MouseEvent(`mousedown`,{...this.mouseInit(e,0,1),detail:1})))}update(e){let t=this.active.get(e.key);if(!t)return;let n=this.getElement();if(!n)return;let r=e.x-t.lastX,i=e.y-t.lastY;t.lastX=e.x,t.lastY=e.y,n.dispatchEvent(new PointerEvent(`pointermove`,{...this.pointerInit(e,t,-1,1,vr),movementX:r,movementY:i})),t.isPrimary&&!t.preventMouse&&n.dispatchEvent(new MouseEvent(`mousemove`,{...this.mouseInit(e,0,1),movementX:r,movementY:i}))}end(e){let t=this.active.get(e.key);if(!t)return;this.active.delete(e.key);let n=this.getElement();if(!n)return;let r=this.pointerInit(e,t,0,0,0),i=this.mouseInit(e,0,0),a=t.isPrimary&&!t.preventMouse;n.dispatchEvent(new PointerEvent(`pointerup`,r)),a&&n.dispatchEvent(new MouseEvent(`mouseup`,{...i,detail:1})),this.leave(n,t,{...r,button:-1},i),t.isPrimary&&n.dispatchEvent(new PointerEvent(`click`,{...r,detail:1}))}cancel(e){let t=this.active.get(e.key);if(!t)return;this.active.delete(e.key);let n=this.getElement();if(!n)return;let r={...e,x:t.lastX,y:t.lastY},i=this.pointerInit(r,t,-1,0,0),a=this.mouseInit(r,0,0);n.dispatchEvent(new PointerEvent(`pointercancel`,{...i,cancelable:!1})),t.isPrimary&&!t.preventMouse&&this.getWindowTarget()?.dispatchEvent(new MouseEvent(`mouseup`,{...a,detail:1})),this.leave(n,t,i,a)}leave(e,t,n,r){e.dispatchEvent(new PointerEvent(`pointerout`,n)),e.dispatchEvent(new PointerEvent(`pointerleave`,{...n,bubbles:!1,cancelable:!1})),t.isPrimary&&(e.dispatchEvent(new MouseEvent(`mouseout`,r)),e.dispatchEvent(new MouseEvent(`mouseleave`,{...r,bubbles:!1,cancelable:!1})))}mouseInit(e,t,n){return{shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey,clientX:e.x,clientY:e.y,offsetX:e.x,offsetY:e.y,screenX:e.x,screenY:e.y,button:t,buttons:n,bubbles:!0,cancelable:!0}}pointerInit(e,t,n,r,i){return{...this.mouseInit(e,n,r),pointerId:t.id,pointerType:`touch`,isPrimary:t.isPrimary,pressure:i}}};const yr=new Map([[yt.EventType.TOUCH_BEGIN,`begin`],[yt.EventType.TOUCH_UPDATE,`update`],[yt.EventType.TOUCH_END,`end`],[yt.EventType.TOUCH_CANCEL,`cancel`]]);function isTouchEvent(e){return e!==null&&yr.has(e.get_event_type())}function pointerTypeOf(e){let t=e?.get_device()?.get_source();return t===yt.InputSource.TOUCHSCREEN?`touch`:t===yt.InputSource.PEN?`pen`:`mouse`}let br=!1;function sequenceKey(e,t){if(e===null)return t?`primary`:`secondary`;let n=String(e),r=n.lastIndexOf(`native@`);return r!==-1&&n.endsWith(`]`)?n.slice(r+7,-1):(br||(br=!0,console.warn(`@gjsify/event-bridge: GdkEventSequence identity is not readable on this runtime; touch pointers are keyed by the emulating-pointer flag, so a third concurrent contact merges with the second.`)),t?`primary`:`secondary`)}function surfaceToWidget(e,t,n){let r=e.get_native(),[i,a]=r.get_surface_transform(),o=t-i,s=n-a,[c,l]=r.compute_point(e,new kn.Point({x:o,y:s}));return c?[l.x,l.y]:[o,s]}function getGlobalEventTarget(){return globalThis.__gjsify_globalEventTarget}const xr={shiftKey:!1,ctrlKey:!1,altKey:!1,metaKey:!1};function modifiersFromState(e){return{shiftKey:!!(e&yt.ModifierType.SHIFT_MASK),ctrlKey:!!(e&yt.ModifierType.CONTROL_MASK),altKey:!!(e&yt.ModifierType.ALT_MASK),metaKey:!!(e&yt.ModifierType.SUPER_MASK)}}function extractModifiers(e){return modifiersFromState(e.get_current_event_state())}function gtkButtonToDom(e){return e===1?0:e===2?1:e===3?2:e-1}function buttonsFromModifiers(e){let t=e.get_current_event_state(),n=0;return t&yt.ModifierType.BUTTON1_MASK&&(n|=1),t&yt.ModifierType.BUTTON3_MASK&&(n|=2),t&yt.ModifierType.BUTTON2_MASK&&(n|=4),n}function attachEventControllers(e,t,n){e.set_focusable(!0),e.set_can_focus(!0);let r={lastX:0,lastY:0,buttonsPressed:0,pressedKeys:new Set},i=new TouchPointerTranslator(t,()=>getGlobalEventTarget()),a=new Sn.EventControllerMotion;a.connect(`motion`,(n,i,o)=>{let s=t();if(!s)return;let c=e.get_allocated_width(),l=e.get_allocated_height(),u=Math.max(0,Math.min(i,c)),d=Math.max(0,Math.min(o,l)),f=u-r.lastX,p=d-r.lastY,m=extractModifiers(a),h=buttonsFromModifiers(a),g={...m,clientX:u,clientY:d,offsetX:u,offsetY:d,screenX:u,screenY:d,movementX:f,movementY:p,buttons:h,button:0,bubbles:!0,cancelable:!0};s.dispatchEvent(new PointerEvent(`pointermove`,{...g,pointerId:1,pointerType:pointerTypeOf(a.get_current_event()),isPrimary:!0})),s.dispatchEvent(new MouseEvent(`mousemove`,g)),r.lastX=u,r.lastY=d}),a.connect(`enter`,(e,n,i)=>{let o=t();if(!o)return;r.lastX=n,r.lastY=i;let s={...extractModifiers(a),clientX:n,clientY:i,offsetX:n,offsetY:i,screenX:n,screenY:i,bubbles:!1,cancelable:!1};o.dispatchEvent(new PointerEvent(`pointerenter`,{...s,pointerId:1,pointerType:pointerTypeOf(a.get_current_event()),isPrimary:!0})),o.dispatchEvent(new MouseEvent(`mouseenter`,s)),o.dispatchEvent(new MouseEvent(`mouseover`,{...s,bubbles:!0}))}),a.connect(`leave`,()=>{let e=t();if(!e)return;let n={...extractModifiers(a),clientX:r.lastX,clientY:r.lastY,bubbles:!1,cancelable:!1};e.dispatchEvent(new PointerEvent(`pointerleave`,{...n,pointerId:1,pointerType:pointerTypeOf(a.get_current_event()),isPrimary:!0})),e.dispatchEvent(new MouseEvent(`mouseleave`,n)),e.dispatchEvent(new MouseEvent(`mouseout`,{...n,bubbles:!0}))}),e.add_controller(a);let o=new Sn.GestureClick;o.set_button(0),o.connect(`pressed`,(n,i,a,s)=>{if(isTouchEvent(o.get_current_event()))return;let c=t();if(!c)return;let l=gtkButtonToDom(o.get_current_button()),u=extractModifiers(o);r.buttonsPressed|=1<<l;let d={...u,clientX:a,clientY:s,offsetX:a,offsetY:s,screenX:a,screenY:s,button:l,buttons:r.buttonsPressed,detail:i,bubbles:!0,cancelable:!0};c.dispatchEvent(new PointerEvent(`pointerdown`,{...d,pointerId:1,pointerType:pointerTypeOf(o.get_current_event()),isPrimary:!0})),c.dispatchEvent(new MouseEvent(`mousedown`,d)),e.grab_focus()}),o.connect(`released`,(e,n,i,a)=>{if(isTouchEvent(o.get_current_event()))return;let s=t();if(!s)return;let c=gtkButtonToDom(o.get_current_button()),l=extractModifiers(o);r.buttonsPressed&=~(1<<c);let u={...l,clientX:i,clientY:a,offsetX:i,offsetY:a,screenX:i,screenY:a,button:c,buttons:r.buttonsPressed,detail:n,bubbles:!0,cancelable:!0};s.dispatchEvent(new PointerEvent(`pointerup`,{...u,pointerId:1,pointerType:pointerTypeOf(o.get_current_event()),isPrimary:!0})),s.dispatchEvent(new MouseEvent(`mouseup`,u)),c===0&&(s.dispatchEvent(new MouseEvent(`click`,u)),n===2&&s.dispatchEvent(new MouseEvent(`dblclick`,u))),c===2&&s.dispatchEvent(new MouseEvent(`contextmenu`,{...u,cancelable:!0}))}),o.connect(`cancel`,(e,n)=>{let i=o.get_last_event(n);if(isTouchEvent(i)||r.buttonsPressed===0)return;r.buttonsPressed=0;let a=t();a&&a.dispatchEvent(new PointerEvent(`pointercancel`,{...extractModifiers(o),clientX:r.lastX,clientY:r.lastY,offsetX:r.lastX,offsetY:r.lastY,screenX:r.lastX,screenY:r.lastY,button:-1,buttons:0,pointerId:1,pointerType:pointerTypeOf(i),isPrimary:!0,bubbles:!0,cancelable:!1}))}),e.add_controller(o);let s=new Sn.EventControllerScroll({flags:Sn.EventControllerScrollFlags.BOTH_AXES});s.connect(`scroll`,(e,n,i)=>{let a=t();if(!a)return;let o=extractModifiers(s),c=s.get_unit()===yt.ScrollUnit.WHEEL,l=c?3:1,u={...o,clientX:r.lastX,clientY:r.lastY,offsetX:r.lastX,offsetY:r.lastY,screenX:r.lastX,screenY:r.lastY,deltaX:n*l,deltaY:i*l,deltaZ:0,deltaMode:c?WheelEvent.DOM_DELTA_LINE:WheelEvent.DOM_DELTA_PIXEL,bubbles:!0,cancelable:!0};return a.dispatchEvent(new WheelEvent(`wheel`,u)),!1}),e.add_controller(s);let c=new Sn.EventControllerKey;c.connect(`key-pressed`,(e,i,a,o)=>{let s=t();if(!s)return!1;let c=r.pressedKeys.has(i);r.pressedKeys.add(i);let l=gdkKeyvalToKey(i),u={key:l,code:gdkKeyvalToCode(i),location:gdkKeyvalToLocation(i),repeat:c,altKey:!!(o&yt.ModifierType.ALT_MASK),ctrlKey:!!(o&yt.ModifierType.CONTROL_MASK),metaKey:!!(o&yt.ModifierType.SUPER_MASK),shiftKey:!!(o&yt.ModifierType.SHIFT_MASK),keyCode:l.length===1?l.toUpperCase().charCodeAt(0):0,which:l.length===1?l.toUpperCase().charCodeAt(0):0,bubbles:!0,cancelable:!0},d=new KeyboardEvent(`keydown`,u);return s.dispatchEvent(d),getGlobalEventTarget()?.dispatchEvent(new KeyboardEvent(`keydown`,u)),n?.captureKeys===!0}),c.connect(`key-released`,(e,n,i,a)=>{let o=t();if(!o)return;r.pressedKeys.delete(n);let s=gdkKeyvalToKey(n),c={key:s,code:gdkKeyvalToCode(n),location:gdkKeyvalToLocation(n),repeat:!1,altKey:!!(a&yt.ModifierType.ALT_MASK),ctrlKey:!!(a&yt.ModifierType.CONTROL_MASK),metaKey:!!(a&yt.ModifierType.SUPER_MASK),shiftKey:!!(a&yt.ModifierType.SHIFT_MASK),keyCode:s.length===1?s.toUpperCase().charCodeAt(0):0,which:s.length===1?s.toUpperCase().charCodeAt(0):0,bubbles:!0,cancelable:!0};o.dispatchEvent(new KeyboardEvent(`keyup`,c)),getGlobalEventTarget()?.dispatchEvent(new KeyboardEvent(`keyup`,c))}),e.add_controller(c);let l=new Sn.EventControllerFocus;l.connect(`enter`,()=>{let e=t();e&&(e.dispatchEvent(new FocusEvent(`focus`,{bubbles:!1,cancelable:!1})),e.dispatchEvent(new FocusEvent(`focusin`,{bubbles:!0,cancelable:!1})))}),l.connect(`leave`,()=>{let e=t();e&&(r.pressedKeys.clear(),e.dispatchEvent(new FocusEvent(`blur`,{bubbles:!1,cancelable:!1})),e.dispatchEvent(new FocusEvent(`focusout`,{bubbles:!0,cancelable:!1})),getGlobalEventTarget()?.dispatchEvent(new FocusEvent(`blur`,{bubbles:!1,cancelable:!1})))}),e.add_controller(l);let u=new Sn.EventControllerLegacy;u.connect(`event`,(t,n)=>{let r=n.get_event_type(),a=yr.get(r);if(a===void 0)return r===yt.EventType.GRAB_BROKEN&&i.activeCount>0&&n.get_grab_surface()!==e.get_native().get_surface()&&i.cancelAll(modifiersFromState(n.get_modifier_state())),!1;let[,o,s]=n.get_position(),[c,l]=surfaceToWidget(e,o,s),u=n.get_emulating_pointer();return i.handle({...modifiersFromState(n.get_modifier_state()),phase:a,key:sequenceKey(n.get_event_sequence(),u),x:c,y:l,isPrimary:u}),a===`begin`&&e.grab_focus(),!1}),e.add_controller(u),e.connect(`unmap`,()=>i.cancelAll(xr)),e.connect(`state-flags-changed`,(t,n)=>{let r=Sn.StateFlags.INSENSITIVE;e.get_state_flags()&r&&!(n&r)&&i.cancelAll(xr)})}const Sr=Mn.registerClass({GTypeName:`GjsifyWebGLBridge`},class WebGLBridge extends Sn.GLArea{constructor(e){super(e),this._canvas=null,this._readyCallbacks=[],this._resizeCallbacks=[],this._renderTag=null,this._tickCallbackId=null,this._frameCallback=null,this._lastFrameCallback=null,this._lastFrameTime=0,this._replaying=!1,this._frameCallbackId=0,this._nextFrameId=1,this._timeOrigin=gt.get_monotonic_time(),this._rendererInfo=null,this.set_allowed_apis(yt.GLAPI.GL|yt.GLAPI.GLES),this.set_required_version(3,2),this.set_has_depth_buffer(!0),this.set_has_stencil_buffer(!0),attachEventControllers(this,()=>this._canvas,{captureKeys:!0}),this._tickCallbackId=this.add_tick_callback((e,t)=>(this._frameCallback!==null&&this.queue_render(),gt.SOURCE_CONTINUE));let t=this.connect(`render`,()=>{this.disconnect(t),this.make_current(),this._canvas=new HTMLCanvasElement$1(this);{let e=globalThis;e.document?.body&&e.document.body.appendChild(this._canvas)}this._canvas.getContext(`webgl2`);let e=this._canvas.getContext(`webgl`);if(e){this._reportRenderer(e);for(let t of this._readyCallbacks)t(this._canvas,e);this._readyCallbacks=[]}return this._renderTag=this.connect(`render`,e=>{let t=(gt.get_monotonic_time()-this._timeOrigin)/1e3;if(this._frameCallback!==null){globalThis.__GJSIFY_DEBUG_RAF===!0&&console.log(`[rAF] frame callback fires t=${t.toFixed(1)}`);let e=this._frameCallback;this._frameCallback=null,this._frameCallbackId=0,this._lastFrameCallback=e,this._lastFrameTime=t,e(t)}else if(this._lastFrameCallback!==null){this._replaying=!0;try{this._lastFrameCallback(this._lastFrameTime)}finally{this._replaying=!1}}return!0}),!0});this.connect(`resize`,()=>{let e=this.get_allocated_width(),t=this.get_allocated_height();this._canvas&&(this._canvas.dispatchEvent(new Event(`resize`)),notifyElementResize(this._canvas,e,t));for(let n of this._resizeCallbacks)n(e,t);this._frameCallback&&this.requestAnimationFrame(this._frameCallback)}),this.connect(`unrealize`,()=>{this._renderTag!==null&&(this.disconnect(this._renderTag),this._renderTag=null),this._tickCallbackId!==null&&(this.remove_tick_callback(this._tickCallbackId),this._tickCallbackId=null),this._frameCallback=null,this._lastFrameCallback=null,this._lastFrameTime=0,this._replaying=!1,this._canvas=null})}get canvas(){return this._canvas}get rendererInfo(){return this._rendererInfo}onReady(e){if(this._canvas){let t=this._canvas.getContext(`webgl`);if(t){e(this._canvas,t);return}}this._readyCallbacks.push(e)}onWebGLReady(e){this.onReady(e)}_reportRenderer(e){let t=e.getExtension(`WEBGL_debug_renderer_info`),n=String(e.getParameter(t.UNMASKED_VENDOR_WEBGL)??``),r=String(e.getParameter(t.UNMASKED_RENDERER_WEBGL)??``);this._rendererInfo={vendor:n,renderer:r},isSoftwareRenderer(r)&&console.warn(`[@gjsify/webgl] GL is rasterised on the CPU by "${r}" (${n}) — this host exposes no usable GPU. Every draw call still works; fill-heavy or continuously animating content will be orders of magnitude slower than on hardware, which can look like a frozen window rather than a slow one. Read it yourself via WebGLBridge.rendererInfo or the WEBGL_debug_renderer_info extension.`)}onResize(e){this._resizeCallbacks.push(e)}requestAnimationFrame(e){let t=this._nextFrameId++;return this._replaying?t:(this._frameCallback=e,this._frameCallbackId=t,this.queue_render(),t)}cancelAnimationFrame(e){e!==0&&e===this._frameCallbackId&&(this._frameCallback=null,this._frameCallbackId=0,this._lastFrameCallback=null,this._lastFrameTime=0)}installGlobals(){let e=globalThis;e.requestAnimationFrame=e=>this.requestAnimationFrame(e),e.cancelAnimationFrame=e=>this.cancelAnimationFrame(e),e.WebGLRenderingContext=WebGLRenderingContext$1,e.WebGL2RenderingContext=mr,Object.defineProperty(globalThis,"devicePixelRatio",{get:()=>this.get_scale_factor()||1,configurable:!0});let t=this._timeOrigin;e.performance={now:()=>(gt.get_monotonic_time()-t)/1e3,timeOrigin:Date.now()}}}),Cr={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},wr={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},Tr=1e3,Er=1001,Dr=1002,Or=1003,kr=1006,Ar=1008,jr=1009,Mr=1012,Nr=1014,Pr=1015,Fr=1016,Ir=1017,Lr=1018,Rr=1020,zr=1023,Br=1026,Vr=1027,Hr=1028,Ur=1029,Wr=1030,Gr=1031,Kr=1033,qr=2300,Jr=2301,Yr=2302,Xr=2303,Zr=2400,Qr=2401,$r=2402,ei=`srgb`,ti=`srgb-linear`,ni=`linear`,ri=`srgb`,ii=7680,ai=2e3
88
88
  /**
89
89
  * @license
90
90
  * Copyright 2010-2026 Three.js Authors
@@ -4388,4 +4388,4 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
4388
4388
  </object>
4389
4389
  </property>
4390
4390
  </template>
4391
- </interface>`;function __assignType(e,t){return e.__type=t,e}var LDrawWindow=class extends yn.ApplicationWindow{static{Pn.registerClass({GTypeName:`LDrawWindow`,Template:UA,InternalChildren:[`glAreaContainer`,`modelRow`,`flatColorsRow`,`mergeModelRow`,`smoothNormalsRow`,`buildingStepRow`,`displayLinesRow`,`conditionalLinesRow`]},this)}constructor(e){super({application:e}),this._modelRow.set_model(Sn.StringList.new(cc.map(__assignType(e=>e.name,[`m`,``,`P"2!"/"`])))),this._modelRow.set_selected(0),this._buildingStepRow.set_adjustment(new Sn.Adjustment({lower:0,upper:0,step_increment:1,value:0}));let t=new Sr;t.set_hexpand(!0),t.set_vexpand(!0),t.installGlobals(),this._glAreaContainer.append(t),Object.defineProperty(globalThis,"innerWidth",{get:()=>t.get_allocated_width(),configurable:!0}),Object.defineProperty(globalThis,"innerHeight",{get:()=>t.get_allocated_height(),configurable:!0}),t.onReady(__assignType(e=>{let t=new URL(`./`,import.meta.url).href,n=start(e,{assetBase:t},__assignType(e=>{let t=this._buildingStepRow.get_adjustment();t.set_upper(e-1),t.set_value(e-1)},[`numSteps`,``,`P"2!"/"`]));this.connectControls(n)},[`canvas`,``,`P"2!"/"`]))}connectControls(e){this._modelRow.connect(`notify::selected`,()=>{e.effectController.modelIndex=this._modelRow.selected,e.reloadObject(!0)}),this._flatColorsRow.connect(`notify::active`,()=>{e.effectController.flatColors=this._flatColorsRow.active,e.reloadObject(!1)}),this._mergeModelRow.connect(`notify::active`,()=>{e.effectController.mergeModel=this._mergeModelRow.active,e.reloadObject(!1)}),this._smoothNormalsRow.connect(`notify::active`,()=>{e.effectController.smoothNormals=this._smoothNormalsRow.active,e.reloadObject(!1)}),this._buildingStepRow.connect(`notify::value`,()=>{e.effectController.buildingStep=this._buildingStepRow.get_value(),e.updateVisibility()}),this._displayLinesRow.connect(`notify::active`,()=>{e.effectController.displayLines=this._displayLinesRow.active,e.updateVisibility()}),this._conditionalLinesRow.connect(`notify::active`,()=>{e.effectController.conditionalLines=this._conditionalLinesRow.active,e.updateVisibility()})}static __type=[()=>yn.ApplicationWindow,`_glAreaContainer`,`_modelRow`,`_flatColorsRow`,`_mergeModelRow`,`_smoothNormalsRow`,`_buildingStepRow`,`_displayLinesRow`,`_conditionalLinesRow`,`application`,`constructor`,`LDrawDemo`,`demo`,`connectControls`,`LDrawWindow`,`P7!!3";!3#;!3$;!3%;!3&;!3';!3(;!3);!P!2*"0+P"w,2-"0.;5w/`]};const WA=new yn.Application({application_id:`gjsify.examples.three-loader-ldraw`,flags:pt.ApplicationFlags.FLAGS_NONE});WA.connect(`startup`,()=>installDevtools(WA)),WA.connect(`activate`,()=>{let e=WA.get_active_window();e||=new LDrawWindow(WA),e.present()}),await WA.runAsync([]);export{};
4391
+ </interface>`;function __assignType(e,t){return e.__type=t,e}var LDrawWindow=class extends yn.ApplicationWindow{static{Mn.registerClass({GTypeName:`LDrawWindow`,Template:UA,InternalChildren:[`glAreaContainer`,`modelRow`,`flatColorsRow`,`mergeModelRow`,`smoothNormalsRow`,`buildingStepRow`,`displayLinesRow`,`conditionalLinesRow`]},this)}constructor(e){super({application:e}),this._modelRow.set_model(Sn.StringList.new(cc.map(__assignType(e=>e.name,[`m`,``,`P"2!"/"`])))),this._modelRow.set_selected(0),this._buildingStepRow.set_adjustment(new Sn.Adjustment({lower:0,upper:0,step_increment:1,value:0}));let t=new Sr;t.set_hexpand(!0),t.set_vexpand(!0),t.installGlobals(),this._glAreaContainer.append(t),Object.defineProperty(globalThis,"innerWidth",{get:()=>t.get_allocated_width(),configurable:!0}),Object.defineProperty(globalThis,"innerHeight",{get:()=>t.get_allocated_height(),configurable:!0}),t.onReady(__assignType(e=>{let t=new URL(`./`,import.meta.url).href,n=start(e,{assetBase:t},__assignType(e=>{let t=this._buildingStepRow.get_adjustment();t.set_upper(e-1),t.set_value(e-1)},[`numSteps`,``,`P"2!"/"`]));this.connectControls(n)},[`canvas`,``,`P"2!"/"`]))}connectControls(e){this._modelRow.connect(`notify::selected`,()=>{e.effectController.modelIndex=this._modelRow.selected,e.reloadObject(!0)}),this._flatColorsRow.connect(`notify::active`,()=>{e.effectController.flatColors=this._flatColorsRow.active,e.reloadObject(!1)}),this._mergeModelRow.connect(`notify::active`,()=>{e.effectController.mergeModel=this._mergeModelRow.active,e.reloadObject(!1)}),this._smoothNormalsRow.connect(`notify::active`,()=>{e.effectController.smoothNormals=this._smoothNormalsRow.active,e.reloadObject(!1)}),this._buildingStepRow.connect(`notify::value`,()=>{e.effectController.buildingStep=this._buildingStepRow.get_value(),e.updateVisibility()}),this._displayLinesRow.connect(`notify::active`,()=>{e.effectController.displayLines=this._displayLinesRow.active,e.updateVisibility()}),this._conditionalLinesRow.connect(`notify::active`,()=>{e.effectController.conditionalLines=this._conditionalLinesRow.active,e.updateVisibility()})}static __type=[()=>yn.ApplicationWindow,`_glAreaContainer`,`_modelRow`,`_flatColorsRow`,`_mergeModelRow`,`_smoothNormalsRow`,`_buildingStepRow`,`_displayLinesRow`,`_conditionalLinesRow`,`application`,`constructor`,`LDrawDemo`,`demo`,`connectControls`,`LDrawWindow`,`P7!!3";!3#;!3$;!3%;!3&;!3';!3(;!3);!P!2*"0+P"w,2-"0.;5w/`]};const WA=new yn.Application({application_id:`gjsify.examples.three-loader-ldraw`,flags:pt.ApplicationFlags.FLAGS_NONE});WA.connect(`startup`,()=>installDevtools(WA)),WA.connect(`activate`,()=>{let e=WA.get_active_window();e||=new LDrawWindow(WA),e.present()}),await WA.runAsync([]);export{};