tangram-core 0.3.0__cp310-cp310-manylinux_2_28_aarch64.whl

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.
Files changed (162) hide show
  1. tangram_core/App.vue +441 -0
  2. tangram_core/CommandPalette.vue +200 -0
  3. tangram_core/HighlightText.vue +32 -0
  4. tangram_core/__Timeline.vue +300 -0
  5. tangram_core/__init__.py +5 -0
  6. tangram_core/__main__.py +331 -0
  7. tangram_core/_core.cpython-310-aarch64-linux-gnu.so +0 -0
  8. tangram_core/_core.pyi +38 -0
  9. tangram_core/api.ts +652 -0
  10. tangram_core/backend.py +458 -0
  11. tangram_core/components.ts +2 -0
  12. tangram_core/config.py +167 -0
  13. tangram_core/dist-frontend/aggregation-layers.js +521 -0
  14. tangram_core/dist-frontend/aggregation-layers.js.map +1 -0
  15. tangram_core/dist-frontend/assets/_commonjsHelpers-CqkleIqs.js +2 -0
  16. tangram_core/dist-frontend/assets/_commonjsHelpers-CqkleIqs.js.map +1 -0
  17. tangram_core/dist-frontend/assets/array-utils-flat-BBMak426.js +11 -0
  18. tangram_core/dist-frontend/assets/array-utils-flat-BBMak426.js.map +1 -0
  19. tangram_core/dist-frontend/assets/assert-cyW4mg7q.js +3 -0
  20. tangram_core/dist-frontend/assets/assert-cyW4mg7q.js.map +1 -0
  21. tangram_core/dist-frontend/assets/b612-latin-400-italic-DePNXA0a.woff +0 -0
  22. tangram_core/dist-frontend/assets/b612-latin-400-italic-a-4GLPtl.woff2 +0 -0
  23. tangram_core/dist-frontend/assets/b612-latin-400-normal-CC98FVm_.woff2 +0 -0
  24. tangram_core/dist-frontend/assets/b612-latin-400-normal-JbZ7xwUX.woff +0 -0
  25. tangram_core/dist-frontend/assets/b612-latin-700-normal-B_Snq1wd.woff +0 -0
  26. tangram_core/dist-frontend/assets/b612-latin-700-normal-BinQrnoB.woff2 +0 -0
  27. tangram_core/dist-frontend/assets/clip-extension-D-rbmFPj.js +26 -0
  28. tangram_core/dist-frontend/assets/clip-extension-D-rbmFPj.js.map +1 -0
  29. tangram_core/dist-frontend/assets/color-CUNNsFV-.js +17 -0
  30. tangram_core/dist-frontend/assets/color-CUNNsFV-.js.map +1 -0
  31. tangram_core/dist-frontend/assets/cube-geometry-v0HQ793i.js +2 -0
  32. tangram_core/dist-frontend/assets/cube-geometry-v0HQ793i.js.map +1 -0
  33. tangram_core/dist-frontend/assets/deep-equal-BTW2ZN6S.js +2 -0
  34. tangram_core/dist-frontend/assets/deep-equal-BTW2ZN6S.js.map +1 -0
  35. tangram_core/dist-frontend/assets/fly-to-interpolator-CIXGjOdo.js +2 -0
  36. tangram_core/dist-frontend/assets/fly-to-interpolator-CIXGjOdo.js.map +1 -0
  37. tangram_core/dist-frontend/assets/geojson-layer-DgMOQ4Qu.js +1010 -0
  38. tangram_core/dist-frontend/assets/geojson-layer-DgMOQ4Qu.js.map +1 -0
  39. tangram_core/dist-frontend/assets/globe-view-Day_n1iB.js +94 -0
  40. tangram_core/dist-frontend/assets/globe-view-Day_n1iB.js.map +1 -0
  41. tangram_core/dist-frontend/assets/globe-viewport-tqhQW7C4.js +2 -0
  42. tangram_core/dist-frontend/assets/globe-viewport-tqhQW7C4.js.map +1 -0
  43. tangram_core/dist-frontend/assets/image-loader-hHJsndO6.js +2 -0
  44. tangram_core/dist-frontend/assets/image-loader-hHJsndO6.js.map +1 -0
  45. tangram_core/dist-frontend/assets/inconsolata-latin-400-normal-DTZQ6lD6.woff2 +0 -0
  46. tangram_core/dist-frontend/assets/inconsolata-latin-400-normal-HYADljCo.woff +0 -0
  47. tangram_core/dist-frontend/assets/inconsolata-latin-700-normal-ByjKuJjN.woff2 +0 -0
  48. tangram_core/dist-frontend/assets/inconsolata-latin-700-normal-DzgUY3Rl.woff +0 -0
  49. tangram_core/dist-frontend/assets/inconsolata-latin-ext-400-normal-BaHVOdFB.woff2 +0 -0
  50. tangram_core/dist-frontend/assets/inconsolata-latin-ext-400-normal-yvPjCxxx.woff +0 -0
  51. tangram_core/dist-frontend/assets/inconsolata-latin-ext-700-normal-D0Kpgs_9.woff2 +0 -0
  52. tangram_core/dist-frontend/assets/inconsolata-latin-ext-700-normal-Dlt-daqV.woff +0 -0
  53. tangram_core/dist-frontend/assets/inconsolata-vietnamese-400-normal-ByiM2lek.woff +0 -0
  54. tangram_core/dist-frontend/assets/inconsolata-vietnamese-400-normal-DfC_iMic.woff2 +0 -0
  55. tangram_core/dist-frontend/assets/inconsolata-vietnamese-700-normal-DLCFFAUf.woff +0 -0
  56. tangram_core/dist-frontend/assets/inconsolata-vietnamese-700-normal-DuasYmn8.woff2 +0 -0
  57. tangram_core/dist-frontend/assets/index-CcogpxdD.js +824 -0
  58. tangram_core/dist-frontend/assets/index-CcogpxdD.js.map +1 -0
  59. tangram_core/dist-frontend/assets/index-SSLdizTv.css +1 -0
  60. tangram_core/dist-frontend/assets/layer-DPcO4AXQ.js +555 -0
  61. tangram_core/dist-frontend/assets/layer-DPcO4AXQ.js.map +1 -0
  62. tangram_core/dist-frontend/assets/layer-extension-CYwTXf73.js +2 -0
  63. tangram_core/dist-frontend/assets/layer-extension-CYwTXf73.js.map +1 -0
  64. tangram_core/dist-frontend/assets/mesh-layers-wiqredoy.js +1123 -0
  65. tangram_core/dist-frontend/assets/mesh-layers-wiqredoy.js.map +1 -0
  66. tangram_core/dist-frontend/assets/orthographic-viewport-B4nCj5tn.js +2 -0
  67. tangram_core/dist-frontend/assets/orthographic-viewport-B4nCj5tn.js.map +1 -0
  68. tangram_core/dist-frontend/assets/pick-layers-pass-C-3k0wbN.js +2 -0
  69. tangram_core/dist-frontend/assets/pick-layers-pass-C-3k0wbN.js.map +1 -0
  70. tangram_core/dist-frontend/assets/project-BTjD2Imj.js +760 -0
  71. tangram_core/dist-frontend/assets/project-BTjD2Imj.js.map +1 -0
  72. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-400-italic-4qS3_zkX.woff2 +0 -0
  73. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-400-italic-CDK-EZBY.woff +0 -0
  74. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-400-normal-Bgns473E.woff +0 -0
  75. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-400-normal-_T2aQlWs.woff2 +0 -0
  76. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-500-normal-CvEVpWxD.woff +0 -0
  77. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-500-normal-s4PklZE0.woff2 +0 -0
  78. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-700-normal-9RN-Z7cI.woff2 +0 -0
  79. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-700-normal-BGMkBBYx.woff +0 -0
  80. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-400-italic-C7erd-g8.woff +0 -0
  81. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-400-italic-DR5R5TWx.woff2 +0 -0
  82. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-400-normal-DGo1Ayjq.woff2 +0 -0
  83. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-400-normal-WtM1l1qc.woff +0 -0
  84. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-500-normal-C8FNIdXm.woff2 +0 -0
  85. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-500-normal-TLDmfi3Q.woff +0 -0
  86. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-700-normal-CTXjXnze.woff2 +0 -0
  87. tangram_core/dist-frontend/assets/roboto-condensed-cyrillic-ext-700-normal-CWPRiRXS.woff +0 -0
  88. tangram_core/dist-frontend/assets/roboto-condensed-greek-400-italic-CR6qj4Z4.woff2 +0 -0
  89. tangram_core/dist-frontend/assets/roboto-condensed-greek-400-italic-DHRaIs10.woff +0 -0
  90. tangram_core/dist-frontend/assets/roboto-condensed-greek-400-normal-D5vBSIyg.woff2 +0 -0
  91. tangram_core/dist-frontend/assets/roboto-condensed-greek-400-normal-FabMgVmk.woff +0 -0
  92. tangram_core/dist-frontend/assets/roboto-condensed-greek-500-normal-BIN62cw9.woff +0 -0
  93. tangram_core/dist-frontend/assets/roboto-condensed-greek-500-normal-Hsn-wDIp.woff2 +0 -0
  94. tangram_core/dist-frontend/assets/roboto-condensed-greek-700-normal-89Up2Xly.woff +0 -0
  95. tangram_core/dist-frontend/assets/roboto-condensed-greek-700-normal-DWMOA2VK.woff2 +0 -0
  96. tangram_core/dist-frontend/assets/roboto-condensed-latin-400-italic-D_BR-3LG.woff2 +0 -0
  97. tangram_core/dist-frontend/assets/roboto-condensed-latin-400-italic-om57GXsO.woff +0 -0
  98. tangram_core/dist-frontend/assets/roboto-condensed-latin-400-normal-BICmKrXV.woff2 +0 -0
  99. tangram_core/dist-frontend/assets/roboto-condensed-latin-400-normal-D2e7XwB1.woff +0 -0
  100. tangram_core/dist-frontend/assets/roboto-condensed-latin-500-normal-3p2daRJW.woff2 +0 -0
  101. tangram_core/dist-frontend/assets/roboto-condensed-latin-500-normal-Dc9bsamC.woff +0 -0
  102. tangram_core/dist-frontend/assets/roboto-condensed-latin-700-normal-BOl6B_hI.woff +0 -0
  103. tangram_core/dist-frontend/assets/roboto-condensed-latin-700-normal-DRbp0YnP.woff2 +0 -0
  104. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-400-italic-BXrkWnoY.woff +0 -0
  105. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-400-italic-Bhem1d5z.woff2 +0 -0
  106. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-400-normal-DT8nEsYA.woff +0 -0
  107. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-400-normal-OHaX69iP.woff2 +0 -0
  108. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-500-normal-CcSTXKtO.woff2 +0 -0
  109. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-500-normal-JgPl2bDS.woff +0 -0
  110. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-700-normal-B004qtqu.woff2 +0 -0
  111. tangram_core/dist-frontend/assets/roboto-condensed-latin-ext-700-normal-O6H_RRvN.woff +0 -0
  112. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-400-italic-BwUYFJ2t.woff2 +0 -0
  113. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-400-italic-DV8QogUk.woff +0 -0
  114. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-400-normal-0o1laQ-g.woff2 +0 -0
  115. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-400-normal-CPsdS8_S.woff +0 -0
  116. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-500-normal-G9shSJ2z.woff +0 -0
  117. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-500-normal-TFWhjk13.woff2 +0 -0
  118. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-700-normal-BtNeb9D6.woff +0 -0
  119. tangram_core/dist-frontend/assets/roboto-condensed-vietnamese-700-normal-D35V1G0s.woff2 +0 -0
  120. tangram_core/dist-frontend/assets/shader-Cbdysp2j.js +843 -0
  121. tangram_core/dist-frontend/assets/shader-Cbdysp2j.js.map +1 -0
  122. tangram_core/dist-frontend/assets/solid-polygon-layer-DJFl_7Ca.js +392 -0
  123. tangram_core/dist-frontend/assets/solid-polygon-layer-DJFl_7Ca.js.map +1 -0
  124. tangram_core/dist-frontend/assets/tesselator-CENyUZ2p.js +2 -0
  125. tangram_core/dist-frontend/assets/tesselator-CENyUZ2p.js.map +1 -0
  126. tangram_core/dist-frontend/assets/webgl-developer-tools-utTNOsNf.js +7 -0
  127. tangram_core/dist-frontend/assets/webgl-developer-tools-utTNOsNf.js.map +1 -0
  128. tangram_core/dist-frontend/assets/webgl-device-BYRB-GQX.js +3 -0
  129. tangram_core/dist-frontend/assets/webgl-device-BYRB-GQX.js.map +1 -0
  130. tangram_core/dist-frontend/assets/widget-BjgEeHAL.js +2 -0
  131. tangram_core/dist-frontend/assets/widget-BjgEeHAL.js.map +1 -0
  132. tangram_core/dist-frontend/core.js +60 -0
  133. tangram_core/dist-frontend/core.js.map +1 -0
  134. tangram_core/dist-frontend/extensions.js +609 -0
  135. tangram_core/dist-frontend/extensions.js.map +1 -0
  136. tangram_core/dist-frontend/favicon.ico +0 -0
  137. tangram_core/dist-frontend/favicon.png +0 -0
  138. tangram_core/dist-frontend/geo-layers.js +115 -0
  139. tangram_core/dist-frontend/geo-layers.js.map +1 -0
  140. tangram_core/dist-frontend/index.html +39 -0
  141. tangram_core/dist-frontend/json.js +3 -0
  142. tangram_core/dist-frontend/json.js.map +1 -0
  143. tangram_core/dist-frontend/layers.js +268 -0
  144. tangram_core/dist-frontend/layers.js.map +1 -0
  145. tangram_core/dist-frontend/mapbox.js +2 -0
  146. tangram_core/dist-frontend/mapbox.js.map +1 -0
  147. tangram_core/dist-frontend/mesh-layers.js +2 -0
  148. tangram_core/dist-frontend/mesh-layers.js.map +1 -0
  149. tangram_core/dist-frontend/widgets.js +3 -0
  150. tangram_core/dist-frontend/widgets.js.map +1 -0
  151. tangram_core/main.ts +28 -0
  152. tangram_core/package.json +62 -0
  153. tangram_core/plugin.py +109 -0
  154. tangram_core/plugin.ts +47 -0
  155. tangram_core/redis.py +89 -0
  156. tangram_core/user.css +114 -0
  157. tangram_core/utils.ts +143 -0
  158. tangram_core/vite-plugin-tangram.mjs +155 -0
  159. tangram_core-0.3.0.dist-info/METADATA +101 -0
  160. tangram_core-0.3.0.dist-info/RECORD +162 -0
  161. tangram_core-0.3.0.dist-info/WHEEL +4 -0
  162. tangram_core-0.3.0.dist-info/entry_points.txt +2 -0
@@ -0,0 +1,3 @@
1
+ import{t as Ee,b as Oe,c as $e,D as ce}from"./assert-cyW4mg7q.js";import{a6 as Ae,am as ze,an as Ve,E as Ue,R as w,y as g,B as L,a2 as Ne,$ as Xe}from"./deep-equal-BTW2ZN6S.js";import{T as E,e as He,S as Qe,b as qe,c as je,g as Ye,R as Ke,f as Ze}from"./array-utils-flat-BBMak426.js";import{m as Je,n as et}from"./webgl-developer-tools-utTNOsNf.js";function tt(r){return Ae()?ze()?"Electron":(Ve.userAgent||"").indexOf("Edge")>-1?"Edge":globalThis.chrome?"Chrome":globalThis.safari?"Safari":globalThis.mozInnerScreenX?"Firefox":"Unknown":"Node"}function rt(){let r,e;return{promise:new Promise((i,n)=>{r=i,e=n}),resolve:r,reject:e}}class A{static isHTMLCanvas(e){return typeof HTMLCanvasElement<"u"&&e instanceof HTMLCanvasElement}static isOffscreenCanvas(e){return typeof OffscreenCanvas<"u"&&e instanceof OffscreenCanvas}static defaultProps={id:void 0,canvas:null,width:800,height:600,useDevicePixels:!0,autoResize:!0,container:null,visible:!0,alphaMode:"opaque",colorSpace:"srgb",trackPosition:!1};id;props;canvas;htmlCanvas;offscreenCanvas;type;initialized;isInitialized=!1;isVisible=!0;cssWidth;cssHeight;devicePixelRatio;devicePixelWidth;devicePixelHeight;drawingBufferWidth;drawingBufferHeight;_initializedResolvers=rt();_resizeObserver;_intersectionObserver;_position;destroyed=!1;toString(){return`${this[Symbol.toStringTag]}(${this.id})`}constructor(e){if(this.props={...A.defaultProps,...e},e=this.props,this.initialized=this._initializedResolvers.promise,Ae()?e.canvas?typeof e.canvas=="string"?this.canvas=nt(e.canvas):this.canvas=e.canvas:this.canvas=st(e):this.canvas={width:e.width||1,height:e.height||1},A.isHTMLCanvas(this.canvas)?(this.id=e.id||this.canvas.id,this.type="html-canvas",this.htmlCanvas=this.canvas):A.isOffscreenCanvas(this.canvas)?(this.id=e.id||"offscreen-canvas",this.type="offscreen-canvas",this.offscreenCanvas=this.canvas):(this.id=e.id||"node-canvas-context",this.type="node"),this.cssWidth=this.htmlCanvas?.clientWidth||this.canvas.width,this.cssHeight=this.htmlCanvas?.clientHeight||this.canvas.height,this.devicePixelWidth=this.canvas.width,this.devicePixelHeight=this.canvas.height,this.drawingBufferWidth=this.canvas.width,this.drawingBufferHeight=this.canvas.height,this.devicePixelRatio=globalThis.devicePixelRatio||1,this._position=[0,0],A.isHTMLCanvas(this.canvas)){this._intersectionObserver=new IntersectionObserver(t=>this._handleIntersection(t)),this._intersectionObserver.observe(this.canvas),this._resizeObserver=new ResizeObserver(t=>this._handleResize(t));try{this._resizeObserver.observe(this.canvas,{box:"device-pixel-content-box"})}catch{this._resizeObserver.observe(this.canvas,{box:"content-box"})}setTimeout(()=>this._observeDevicePixelRatio(),0),this.props.trackPosition&&this._trackPosition()}}destroy(){this.destroyed=!0}setProps(e){return"useDevicePixels"in e&&(this.props.useDevicePixels=e.useDevicePixels||!1,this._updateDrawingBufferSize()),this}getCSSSize(){return[this.cssWidth,this.cssHeight]}getPosition(){return this._position}getDevicePixelSize(){return[this.devicePixelWidth,this.devicePixelHeight]}getDrawingBufferSize(){return[this.drawingBufferWidth,this.drawingBufferHeight]}getMaxDrawingBufferSize(){const e=this.device.limits.maxTextureDimension2D;return[e,e]}setDrawingBufferSize(e,t){this.canvas.width=e,this.canvas.height=t,this.drawingBufferWidth=e,this.drawingBufferHeight=t}getDevicePixelRatio(){return typeof window<"u"&&window.devicePixelRatio||1}cssToDevicePixels(e,t=!0){const i=this.cssToDeviceRatio(),[n,s]=this.getDrawingBufferSize();return at(e,i,n,s,t)}getPixelSize(){return this.getDevicePixelSize()}getAspect(){const[e,t]=this.getDevicePixelSize();return e/t}cssToDeviceRatio(){try{const[e]=this.getDrawingBufferSize(),[t]=this.getCSSSize();return t?e/t:1}catch{return 1}}resize(e){this.setDrawingBufferSize(e.width,e.height)}_setAutoCreatedCanvasId(e){this.htmlCanvas?.id==="lumagl-auto-created-canvas"&&(this.htmlCanvas.id=e)}_handleIntersection(e){const t=e.find(n=>n.target===this.canvas);if(!t)return;const i=t.isIntersecting;this.isVisible!==i&&(this.isVisible=i,this.device.props.onVisibilityChange(this))}_handleResize(e){const t=e.find(c=>c.target===this.canvas);if(!t)return;this.cssWidth=t.contentBoxSize[0].inlineSize,this.cssHeight=t.contentBoxSize[0].blockSize;const i=this.getDevicePixelSize(),n=t.devicePixelContentBoxSize?.[0].inlineSize||t.contentBoxSize[0].inlineSize*devicePixelRatio,s=t.devicePixelContentBoxSize?.[0].blockSize||t.contentBoxSize[0].blockSize*devicePixelRatio,[a,o]=this.getMaxDrawingBufferSize();this.devicePixelWidth=Math.max(1,Math.min(n,a)),this.devicePixelHeight=Math.max(1,Math.min(s,o)),this._updateDrawingBufferSize(),this.device.props.onResize(this,{oldPixelSize:i})}_updateDrawingBufferSize(){if(this.props.autoResize){if(typeof this.props.useDevicePixels=="number"){const e=this.props.useDevicePixels;this.setDrawingBufferSize(this.cssWidth*e,this.cssHeight*e)}else this.props.useDevicePixels?this.setDrawingBufferSize(this.devicePixelWidth,this.devicePixelHeight):this.setDrawingBufferSize(this.cssWidth,this.cssHeight);this._updateDevice()}this._initializedResolvers.resolve(),this.isInitialized=!0,this.updatePosition()}_observeDevicePixelRatio(){const e=this.devicePixelRatio;this.devicePixelRatio=window.devicePixelRatio,this.updatePosition(),this.device.props.onDevicePixelRatioChange(this,{oldRatio:e}),matchMedia(`(resolution: ${this.devicePixelRatio}dppx)`).addEventListener("change",()=>this._observeDevicePixelRatio(),{once:!0})}_trackPosition(e=100){const t=setInterval(()=>{this.destroyed?clearInterval(t):this.updatePosition()},e)}updatePosition(){const e=this.htmlCanvas?.getBoundingClientRect();if(e){const t=[e.left,e.top];if(this._position??=t,t[0]!==this._position[0]||t[1]!==this._position[1]){const n=this._position;this._position=t,this.device.props.onPositionChange?.(this,{oldPosition:n})}}}}function it(r){if(typeof r=="string"){const e=document.getElementById(r);if(!e)throw new Error(`${r} is not an HTML element`);return e}return r||document.body}function nt(r){const e=document.getElementById(r);if(!A.isHTMLCanvas(e))throw new Error("Object is not a canvas element");return e}function st(r){const{width:e,height:t}=r,i=document.createElement("canvas");i.id=Ue("lumagl-auto-created-canvas"),i.width=e||1,i.height=t||1,i.style.width=Number.isFinite(e)?`${e}px`:"100%",i.style.height=Number.isFinite(t)?`${t}px`:"100%",r?.visible||(i.style.visibility="hidden");const n=it(r?.container||null);return n.insertBefore(i,n.firstChild),i}function at(r,e,t,i,n){const s=r,a=le(s[0],e,t);let o=ue(s[1],e,i,n),c=le(s[0]+1,e,t);const l=c===t-1?c:c-1;c=ue(s[1]+1,e,i,n);let u;return n?(c=c===0?c:c+1,u=o,o=c):u=c===i-1?c:c-1,{x:a,y:o,width:Math.max(l-a+1,1),height:Math.max(u-o+1,1)}}function le(r,e,t){return Math.min(Math.round(r*e),t-1)}function ue(r,e,t,i){return i?Math.max(0,t-1-Math.round(r*e)):Math.min(Math.round(r*e),t-1)}class N extends w{get[Symbol.toStringTag](){return"Framebuffer"}width;height;constructor(e,t={}){super(e,t,N.defaultProps),this.width=this.props.width,this.height=this.props.height}clone(e){const t=this.colorAttachments.map(n=>n.texture.clone(e)),i=this.depthStencilAttachment&&this.depthStencilAttachment.texture.clone(e);return this.device.createFramebuffer({...this.props,colorAttachments:t,depthStencilAttachment:i})}resize(e){let t=!e;if(e){const[i,n]=Array.isArray(e)?e:[e.width,e.height];t=t||n!==this.height||i!==this.width,this.width=i,this.height=n}t&&(g.log(2,`Resizing framebuffer ${this.id} to ${this.width}x${this.height}`)(),this.resizeAttachments(this.width,this.height))}autoCreateAttachmentTextures(){if(this.props.colorAttachments.length===0&&!this.props.depthStencilAttachment)throw new Error("Framebuffer has noattachments");this.colorAttachments=this.props.colorAttachments.map((t,i)=>{if(typeof t=="string"){const n=this.createColorTexture(t,i);return this.attachResource(n),n.view}return t instanceof E?t.view:t});const e=this.props.depthStencilAttachment;if(e)if(typeof e=="string"){const t=this.createDepthStencilTexture(e);this.attachResource(t),this.depthStencilAttachment=t.view}else e instanceof E?this.depthStencilAttachment=e.view:this.depthStencilAttachment=e}createColorTexture(e,t){return this.device.createTexture({id:`${this.id}-color-attachment-${t}`,usage:E.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height,sampler:{magFilter:"linear",minFilter:"linear"}})}createDepthStencilTexture(e){return this.device.createTexture({id:`${this.id}-depth-stencil-attachment`,usage:E.RENDER_ATTACHMENT,format:e,width:this.width,height:this.height})}resizeAttachments(e,t){for(let i=0;i<this.colorAttachments.length;++i)if(this.colorAttachments[i]){const n=this.colorAttachments[i].texture.clone({width:e,height:t});this.destroyAttachedResource(this.colorAttachments[i]),this.colorAttachments[i]=n.view,this.attachResource(n.view)}if(this.depthStencilAttachment){const i=this.depthStencilAttachment.texture.clone({width:e,height:t});this.destroyAttachedResource(this.depthStencilAttachment),this.depthStencilAttachment=i.view,this.attachResource(i)}this.updateAttachments()}static defaultProps={...w.defaultProps,width:1,height:1,colorAttachments:[],depthStencilAttachment:null}}class P extends w{static defaultClearColor=[0,0,0,1];static defaultClearDepth=1;static defaultClearStencil=0;get[Symbol.toStringTag](){return"RenderPass"}constructor(e,t){t=P.normalizeProps(e,t),super(e,t,P.defaultProps)}static normalizeProps(e,t){return t}static defaultProps={...w.defaultProps,framebuffer:null,parameters:void 0,clearColor:P.defaultClearColor,clearColors:void 0,clearDepth:P.defaultClearDepth,clearStencil:P.defaultClearStencil,depthReadOnly:!1,stencilReadOnly:!1,discard:!1,occlusionQuerySet:void 0,timestampQuerySet:void 0,beginTimestampIndex:void 0,endTimestampIndex:void 0}}class K extends w{get[Symbol.toStringTag](){return"CommandEncoder"}constructor(e,t){super(e,t,K.defaultProps)}static defaultProps={...w.defaultProps,measureExecutionTime:void 0}}class Z extends w{get[Symbol.toStringTag](){return"CommandBuffer"}constructor(e,t){super(e,t,Z.defaultProps)}static defaultProps={...w.defaultProps}}class J extends w{static defaultProps={...w.defaultProps,shaderLayout:void 0,bufferLayout:[]};get[Symbol.toStringTag](){return"VertexArray"}maxVertexAttributes;attributeInfos;indexBuffer=null;attributes;constructor(e,t){super(e,t,J.defaultProps),this.maxVertexAttributes=e.limits.maxVertexAttributes,this.attributes=new Array(this.maxVertexAttributes).fill(null),this.attributeInfos=He(t.shaderLayout,t.bufferLayout,this.maxVertexAttributes)}setConstantWebGL(e,t){this.device.reportError(new Error("constant attributes not supported"),this)()}}class ee extends w{static defaultProps={...w.defaultProps,layout:void 0,buffers:{}};get[Symbol.toStringTag](){return"TransformFeedback"}constructor(e,t){super(e,t,ee.defaultProps)}}class te extends w{get[Symbol.toStringTag](){return"QuerySet"}constructor(e,t){super(e,t,te.defaultProps)}static defaultProps={...w.defaultProps,type:void 0,count:void 0}}const re={3042:!1,32773:new Float32Array([0,0,0,0]),32777:32774,34877:32774,32969:1,32968:0,32971:1,32970:0,3106:new Float32Array([0,0,0,0]),3107:[!0,!0,!0,!0],2884:!1,2885:1029,2929:!1,2931:1,2932:513,2928:new Float32Array([0,1]),2930:!0,3024:!0,35725:null,36006:null,36007:null,34229:null,34964:null,2886:2305,33170:4352,2849:1,32823:!1,32824:0,10752:0,32926:!1,32928:!1,32938:1,32939:!1,3089:!1,3088:new Int32Array([0,0,1024,1024]),2960:!1,2961:0,2968:4294967295,36005:4294967295,2962:519,2967:0,2963:4294967295,34816:519,36003:0,36004:4294967295,2964:7680,2965:7680,2966:7680,34817:7680,34818:7680,34819:7680,2978:[0,0,1024,1024],36389:null,36662:null,36663:null,35053:null,35055:null,35723:4352,36010:null,35977:!1,3333:4,3317:4,37440:!1,37441:!1,37443:37444,3330:0,3332:0,3331:0,3314:0,32878:0,3316:0,3315:0,32877:0},x=(r,e,t)=>e?r.enable(t):r.disable(t),he=(r,e,t)=>r.hint(t,e),v=(r,e,t)=>r.pixelStorei(t,e),fe=(r,e,t)=>{const i=t===36006?36009:36008;return r.bindFramebuffer(i,e)},W=(r,e,t)=>{const n={34964:34962,36662:36662,36663:36663,35053:35051,35055:35052}[t];r.bindBuffer(n,e)};function X(r){return Array.isArray(r)||ArrayBuffer.isView(r)&&!(r instanceof DataView)}const ot={3042:x,32773:(r,e)=>r.blendColor(...e),32777:"blendEquation",34877:"blendEquation",32969:"blendFunc",32968:"blendFunc",32971:"blendFunc",32970:"blendFunc",3106:(r,e)=>r.clearColor(...e),3107:(r,e)=>r.colorMask(...e),2884:x,2885:(r,e)=>r.cullFace(e),2929:x,2931:(r,e)=>r.clearDepth(e),2932:(r,e)=>r.depthFunc(e),2928:(r,e)=>r.depthRange(...e),2930:(r,e)=>r.depthMask(e),3024:x,35723:he,35725:(r,e)=>r.useProgram(e),36007:(r,e)=>r.bindRenderbuffer(36161,e),36389:(r,e)=>r.bindTransformFeedback?.(36386,e),34229:(r,e)=>r.bindVertexArray(e),36006:fe,36010:fe,34964:W,36662:W,36663:W,35053:W,35055:W,2886:(r,e)=>r.frontFace(e),33170:he,2849:(r,e)=>r.lineWidth(e),32823:x,32824:"polygonOffset",10752:"polygonOffset",35977:x,32926:x,32928:x,32938:"sampleCoverage",32939:"sampleCoverage",3089:x,3088:(r,e)=>r.scissor(...e),2960:x,2961:(r,e)=>r.clearStencil(e),2968:(r,e)=>r.stencilMaskSeparate(1028,e),36005:(r,e)=>r.stencilMaskSeparate(1029,e),2962:"stencilFuncFront",2967:"stencilFuncFront",2963:"stencilFuncFront",34816:"stencilFuncBack",36003:"stencilFuncBack",36004:"stencilFuncBack",2964:"stencilOpFront",2965:"stencilOpFront",2966:"stencilOpFront",34817:"stencilOpBack",34818:"stencilOpBack",34819:"stencilOpBack",2978:(r,e)=>r.viewport(...e),34383:x,10754:x,12288:x,12289:x,12290:x,12291:x,12292:x,12293:x,12294:x,12295:x,3333:v,3317:v,37440:v,37441:v,37443:v,3330:v,3332:v,3331:v,3314:v,32878:v,3316:v,3315:v,32877:v,framebuffer:(r,e)=>{const t=e&&"handle"in e?e.handle:e;return r.bindFramebuffer(36160,t)},blend:(r,e)=>e?r.enable(3042):r.disable(3042),blendColor:(r,e)=>r.blendColor(...e),blendEquation:(r,e)=>{const t=typeof e=="number"?[e,e]:e;r.blendEquationSeparate(...t)},blendFunc:(r,e)=>{const t=e?.length===2?[...e,...e]:e;r.blendFuncSeparate(...t)},clearColor:(r,e)=>r.clearColor(...e),clearDepth:(r,e)=>r.clearDepth(e),clearStencil:(r,e)=>r.clearStencil(e),colorMask:(r,e)=>r.colorMask(...e),cull:(r,e)=>e?r.enable(2884):r.disable(2884),cullFace:(r,e)=>r.cullFace(e),depthTest:(r,e)=>e?r.enable(2929):r.disable(2929),depthFunc:(r,e)=>r.depthFunc(e),depthMask:(r,e)=>r.depthMask(e),depthRange:(r,e)=>r.depthRange(...e),dither:(r,e)=>e?r.enable(3024):r.disable(3024),derivativeHint:(r,e)=>{r.hint(35723,e)},frontFace:(r,e)=>r.frontFace(e),mipmapHint:(r,e)=>r.hint(33170,e),lineWidth:(r,e)=>r.lineWidth(e),polygonOffsetFill:(r,e)=>e?r.enable(32823):r.disable(32823),polygonOffset:(r,e)=>r.polygonOffset(...e),sampleCoverage:(r,e)=>r.sampleCoverage(e[0],e[1]||!1),scissorTest:(r,e)=>e?r.enable(3089):r.disable(3089),scissor:(r,e)=>r.scissor(...e),stencilTest:(r,e)=>e?r.enable(2960):r.disable(2960),stencilMask:(r,e)=>{e=X(e)?e:[e,e];const[t,i]=e;r.stencilMaskSeparate(1028,t),r.stencilMaskSeparate(1029,i)},stencilFunc:(r,e)=>{e=X(e)&&e.length===3?[...e,...e]:e;const[t,i,n,s,a,o]=e;r.stencilFuncSeparate(1028,t,i,n),r.stencilFuncSeparate(1029,s,a,o)},stencilOp:(r,e)=>{e=X(e)&&e.length===3?[...e,...e]:e;const[t,i,n,s,a,o]=e;r.stencilOpSeparate(1028,t,i,n),r.stencilOpSeparate(1029,s,a,o)},viewport:(r,e)=>r.viewport(...e)};function m(r,e,t){return e[r]!==void 0?e[r]:t[r]}const ct={blendEquation:(r,e,t)=>r.blendEquationSeparate(m(32777,e,t),m(34877,e,t)),blendFunc:(r,e,t)=>r.blendFuncSeparate(m(32969,e,t),m(32968,e,t),m(32971,e,t),m(32970,e,t)),polygonOffset:(r,e,t)=>r.polygonOffset(m(32824,e,t),m(10752,e,t)),sampleCoverage:(r,e,t)=>r.sampleCoverage(m(32938,e,t),m(32939,e,t)),stencilFuncFront:(r,e,t)=>r.stencilFuncSeparate(1028,m(2962,e,t),m(2967,e,t),m(2963,e,t)),stencilFuncBack:(r,e,t)=>r.stencilFuncSeparate(1029,m(34816,e,t),m(36003,e,t),m(36004,e,t)),stencilOpFront:(r,e,t)=>r.stencilOpSeparate(1028,m(2964,e,t),m(2965,e,t),m(2966,e,t)),stencilOpBack:(r,e,t)=>r.stencilOpSeparate(1029,m(34817,e,t),m(34818,e,t),m(34819,e,t))},de={enable:(r,e)=>r({[e]:!0}),disable:(r,e)=>r({[e]:!1}),pixelStorei:(r,e,t)=>r({[e]:t}),hint:(r,e,t)=>r({[e]:t}),useProgram:(r,e)=>r({35725:e}),bindRenderbuffer:(r,e,t)=>r({36007:t}),bindTransformFeedback:(r,e,t)=>r({36389:t}),bindVertexArray:(r,e)=>r({34229:e}),bindFramebuffer:(r,e,t)=>{switch(e){case 36160:return r({36006:t,36010:t});case 36009:return r({36006:t});case 36008:return r({36010:t});default:return null}},bindBuffer:(r,e,t)=>{const i={34962:[34964],36662:[36662],36663:[36663],35051:[35053],35052:[35055]}[e];return i?r({[i]:t}):{valueChanged:!0}},blendColor:(r,e,t,i,n)=>r({32773:new Float32Array([e,t,i,n])}),blendEquation:(r,e)=>r({32777:e,34877:e}),blendEquationSeparate:(r,e,t)=>r({32777:e,34877:t}),blendFunc:(r,e,t)=>r({32969:e,32968:t,32971:e,32970:t}),blendFuncSeparate:(r,e,t,i,n)=>r({32969:e,32968:t,32971:i,32970:n}),clearColor:(r,e,t,i,n)=>r({3106:new Float32Array([e,t,i,n])}),clearDepth:(r,e)=>r({2931:e}),clearStencil:(r,e)=>r({2961:e}),colorMask:(r,e,t,i,n)=>r({3107:[e,t,i,n]}),cullFace:(r,e)=>r({2885:e}),depthFunc:(r,e)=>r({2932:e}),depthRange:(r,e,t)=>r({2928:new Float32Array([e,t])}),depthMask:(r,e)=>r({2930:e}),frontFace:(r,e)=>r({2886:e}),lineWidth:(r,e)=>r({2849:e}),polygonOffset:(r,e,t)=>r({32824:e,10752:t}),sampleCoverage:(r,e,t)=>r({32938:e,32939:t}),scissor:(r,e,t,i,n)=>r({3088:new Int32Array([e,t,i,n])}),stencilMask:(r,e)=>r({2968:e,36005:e}),stencilMaskSeparate:(r,e,t)=>r({[e===1028?2968:36005]:t}),stencilFunc:(r,e,t,i)=>r({2962:e,2967:t,2963:i,34816:e,36003:t,36004:i}),stencilFuncSeparate:(r,e,t,i,n)=>r({[e===1028?2962:34816]:t,[e===1028?2967:36003]:i,[e===1028?2963:36004]:n}),stencilOp:(r,e,t,i)=>r({2964:e,2965:t,2966:i,34817:e,34818:t,34819:i}),stencilOpSeparate:(r,e,t,i,n)=>r({[e===1028?2964:34817]:t,[e===1028?2965:34818]:i,[e===1028?2966:34819]:n}),viewport:(r,e,t,i,n)=>r({2978:[e,t,i,n]})},_=(r,e)=>r.isEnabled(e),ge={3042:_,2884:_,2929:_,3024:_,32823:_,32926:_,32928:_,3089:_,2960:_,35977:_},lt=new Set([34016,36388,36387,35983,35368,34965,35739,35738,3074,34853,34854,34855,34856,34857,34858,34859,34860,34861,34862,34863,34864,34865,34866,34867,34868,35097,32873,35869,32874,34068]);function M(r,e){if(ht(e))return;const t={};for(const n in e){const s=Number(n),a=ot[n];a&&(typeof a=="string"?t[a]=!0:a(r,e[n],s))}const i=r.state&&r.state.cache;if(i)for(const n in t){const s=ct[n];s(r,e,i)}}function Le(r,e=re){if(typeof e=="number"){const n=e,s=ge[n];return s?s(r,n):r.getParameter(n)}const t=Array.isArray(e)?e:Object.keys(e),i={};for(const n of t){const s=ge[n];i[n]=s?s(r,Number(n)):r.getParameter(Number(n))}return i}function ut(r){M(r,re)}function ht(r){for(const e in r)return!1;return!0}function ft(r,e){if(r===e)return!0;if(be(r)&&be(e)&&r.length===e.length){for(let t=0;t<r.length;++t)if(r[t]!==e[t])return!1;return!0}return!1}function be(r){return Array.isArray(r)||ArrayBuffer.isView(r)}class B{static get(e){return e.state}gl;program=null;stateStack=[];enable=!0;cache=null;log;initialized=!1;constructor(e,t){this.gl=e,this.log=t?.log||(()=>{}),this._updateCache=this._updateCache.bind(this),Object.seal(this)}push(e={}){this.stateStack.push({})}pop(){const e=this.stateStack[this.stateStack.length-1];M(this.gl,e),this.stateStack.pop()}trackState(e,t){if(this.cache=t?.copyState?Le(e):Object.assign({},re),this.initialized)throw new Error("WebGLStateTracker");this.initialized=!0,this.gl.state=this,gt(e);for(const i in de){const n=de[i];dt(e,i,n)}me(e,"getParameter"),me(e,"isEnabled")}_updateCache(e){let t=!1,i;const n=this.stateStack.length>0?this.stateStack[this.stateStack.length-1]:null;for(const s in e){const a=e[s],o=this.cache[s];ft(a,o)||(t=!0,i=o,n&&!(s in n)&&(n[s]=o),this.cache[s]=a)}return{valueChanged:t,oldValue:i}}}function me(r,e){const t=r[e].bind(r);r[e]=function(n){if(n===void 0||lt.has(n))return t(n);const s=B.get(r);return n in s.cache||(s.cache[n]=t(n)),s.enable?s.cache[n]:t(n)},Object.defineProperty(r[e],"name",{value:`${e}-from-cache`,configurable:!1})}function dt(r,e,t){if(!r[e])return;const i=r[e].bind(r);r[e]=function(...s){const a=B.get(r),{valueChanged:o,oldValue:c}=t(a._updateCache,...s);return o&&i(...s),c},Object.defineProperty(r[e],"name",{value:`${e}-to-cache`,configurable:!1})}function gt(r){const e=r.useProgram.bind(r);r.useProgram=function(i){const n=B.get(r);n.program!==i&&(e(i),n.program=i)}}function bt(r,e,t){let i="";const n={preserveDrawingBuffer:!0,...t};let s=null;if(s||=r.getContext("webgl2",n),n.failIfMajorPerformanceCaveat&&(i||="Only software GPU is available. Set `failIfMajorPerformanceCaveat: false` to allow."),!s&&!t.failIfMajorPerformanceCaveat&&(n.failIfMajorPerformanceCaveat=!1,s=r.getContext("webgl2",n),s.luma||={},s.luma.softwareRenderer=!0),s||(s=r.getContext("webgl",{}),s&&(s=null,i||="Your browser only supports WebGL1")),!s)throw i||="Your browser does not support WebGL",new Error(`Failed to create WebGL context: ${i}`);const{onContextLost:a,onContextRestored:o}=e;return r.addEventListener("webglcontextlost",c=>a(c),!1),r.addEventListener("webglcontextrestored",c=>o(c),!1),s.luma||={},s}function G(r,e,t){return t[e]===void 0&&(t[e]=r.getExtension(e)||null),t[e]}function mt(r,e){const t=r.getParameter(7936),i=r.getParameter(7937);G(r,"WEBGL_debug_renderer_info",e);const n=e.WEBGL_debug_renderer_info,s=r.getParameter(n?n.UNMASKED_VENDOR_WEBGL:7936),a=r.getParameter(n?n.UNMASKED_RENDERER_WEBGL:7937),o=s||t,c=a||i,l=r.getParameter(7938),u=Be(o,c),f=pt(o,c),h=xt(o,c);return{type:"webgl",gpu:u,gpuType:h,gpuBackend:f,vendor:o,renderer:c,version:l,shadingLanguage:"glsl",shadingLanguageVersion:300}}function Be(r,e){return/NVIDIA/i.exec(r)||/NVIDIA/i.exec(e)?"nvidia":/INTEL/i.exec(r)||/INTEL/i.exec(e)?"intel":/Apple/i.exec(r)||/Apple/i.exec(e)?"apple":/AMD/i.exec(r)||/AMD/i.exec(e)||/ATI/i.exec(r)||/ATI/i.exec(e)?"amd":/SwiftShader/i.exec(r)||/SwiftShader/i.exec(e)?"software":"unknown"}function pt(r,e){return/Metal/i.exec(r)||/Metal/i.exec(e)?"metal":/ANGLE/i.exec(r)||/ANGLE/i.exec(e)?"opengl":"unknown"}function xt(r,e){if(/SwiftShader/i.exec(r)||/SwiftShader/i.exec(e))return"cpu";switch(Be(r,e)){case"intel":return"integrated";case"software":return"cpu";case"unknown":return"unknown";default:return"discrete"}}function Fe(r){switch(r){case"uint8":return 5121;case"sint8":return 5120;case"unorm8":return 5121;case"snorm8":return 5120;case"uint16":return 5123;case"sint16":return 5122;case"unorm16":return 5123;case"snorm16":return 5122;case"uint32":return 5125;case"sint32":return 5124;case"float16":return 5131;case"float32":return 5126}throw new Error(String(r))}const R="WEBGL_compressed_texture_s3tc",I="WEBGL_compressed_texture_s3tc_srgb",C="EXT_texture_compression_rgtc",k="EXT_texture_compression_bptc",yt="WEBGL_compressed_texture_etc",wt="WEBGL_compressed_texture_astc",vt="WEBGL_compressed_texture_etc1",St="WEBGL_compressed_texture_pvrtc",Tt="WEBGL_compressed_texture_atc",pe="EXT_texture_norm16",xe="EXT_render_snorm",_t="EXT_color_buffer_float",ie={"float32-renderable-webgl":["EXT_color_buffer_float"],"float16-renderable-webgl":["EXT_color_buffer_half_float"],"rgb9e5ufloat-renderable-webgl":["WEBGL_render_shared_exponent"],"snorm8-renderable-webgl":[xe],"norm16-renderable-webgl":[pe],"snorm16-renderable-webgl":[pe,xe],"float32-filterable":["OES_texture_float_linear"],"float16-filterable-webgl":["OES_texture_half_float_linear"],"texture-filterable-anisotropic-webgl":["EXT_texture_filter_anisotropic"],"texture-blend-float-webgl":["EXT_float_blend"],"texture-compression-bc":[R,I,C,k],"texture-compression-bc5-webgl":[C],"texture-compression-bc7-webgl":[k],"texture-compression-etc2":[yt],"texture-compression-astc":[wt],"texture-compression-etc1-webgl":[vt],"texture-compression-pvrtc-webgl":[St],"texture-compression-atc-webgl":[Tt]};function Pt(r){return r in ie}function Et(r,e,t){return(ie[e]||[]).every(n=>G(r,n,t))}const ne={r8unorm:{gl:33321,rb:!0},r8snorm:{gl:36756},r8uint:{gl:33330,rb:!0},r8sint:{gl:33329,rb:!0},rg8unorm:{gl:33323,rb:!0},rg8snorm:{gl:36757},rg8uint:{gl:33336,rb:!0},rg8sint:{gl:33335,rb:!0},r16uint:{gl:33332,rb:!0},r16sint:{gl:33331,rb:!0},r16float:{gl:33325,rb:!0},r16unorm:{gl:33322,rb:!0},r16snorm:{gl:36760},"rgba4unorm-webgl":{gl:32854,rb:!0},"rgb565unorm-webgl":{gl:36194,rb:!0},"rgb5a1unorm-webgl":{gl:32855,rb:!0},"rgb8unorm-webgl":{gl:32849},"rgb8snorm-webgl":{gl:36758},rgba8unorm:{gl:32856},"rgba8unorm-srgb":{gl:35907},rgba8snorm:{gl:36759},rgba8uint:{gl:36220},rgba8sint:{gl:36238},bgra8unorm:{},"bgra8unorm-srgb":{},rg16uint:{gl:33338},rg16sint:{gl:33337},rg16float:{gl:33327,rb:!0},rg16unorm:{gl:33324},rg16snorm:{gl:36761},r32uint:{gl:33334,rb:!0},r32sint:{gl:33333,rb:!0},r32float:{gl:33326},rgb9e5ufloat:{gl:35901},rg11b10ufloat:{gl:35898,rb:!0},rgb10a2unorm:{gl:32857,rb:!0},rgb10a2uint:{gl:36975,rb:!0},"rgb16unorm-webgl":{gl:32852},"rgb16snorm-webgl":{gl:36762},rg32uint:{gl:33340,rb:!0},rg32sint:{gl:33339,rb:!0},rg32float:{gl:33328,rb:!0},rgba16uint:{gl:36214,rb:!0},rgba16sint:{gl:36232,rb:!0},rgba16float:{gl:34842},rgba16unorm:{gl:32859,rb:!0},rgba16snorm:{gl:36763},"rgb32float-webgl":{gl:34837,x:_t,dataFormat:6407,types:[5126]},rgba32uint:{gl:36208,rb:!0},rgba32sint:{gl:36226,rb:!0},rgba32float:{gl:34836,rb:!0},stencil8:{gl:36168,rb:!0},depth16unorm:{gl:33189,dataFormat:6402,types:[5123],rb:!0},depth24plus:{gl:33190,dataFormat:6402,types:[5125]},depth32float:{gl:36012,dataFormat:6402,types:[5126],rb:!0},"depth24plus-stencil8":{gl:35056,rb:!0,depthTexture:!0,dataFormat:34041,types:[34042]},"depth32float-stencil8":{gl:36013,dataFormat:34041,types:[36269],rb:!0},"bc1-rgb-unorm-webgl":{gl:33776,x:R},"bc1-rgb-unorm-srgb-webgl":{gl:35916,x:I},"bc1-rgba-unorm":{gl:33777,x:R},"bc1-rgba-unorm-srgb":{gl:35916,x:I},"bc2-rgba-unorm":{gl:33778,x:R},"bc2-rgba-unorm-srgb":{gl:35918,x:I},"bc3-rgba-unorm":{gl:33779,x:R},"bc3-rgba-unorm-srgb":{gl:35919,x:I},"bc4-r-unorm":{gl:36283,x:C},"bc4-r-snorm":{gl:36284,x:C},"bc5-rg-unorm":{gl:36285,x:C},"bc5-rg-snorm":{gl:36286,x:C},"bc6h-rgb-ufloat":{gl:36495,x:k},"bc6h-rgb-float":{gl:36494,x:k},"bc7-rgba-unorm":{gl:36492,x:k},"bc7-rgba-unorm-srgb":{gl:36493,x:k},"etc2-rgb8unorm":{gl:37492},"etc2-rgb8unorm-srgb":{gl:37494},"etc2-rgb8a1unorm":{gl:37496},"etc2-rgb8a1unorm-srgb":{gl:37497},"etc2-rgba8unorm":{gl:37493},"etc2-rgba8unorm-srgb":{gl:37495},"eac-r11unorm":{gl:37488},"eac-r11snorm":{gl:37489},"eac-rg11unorm":{gl:37490},"eac-rg11snorm":{gl:37491},"astc-4x4-unorm":{gl:37808},"astc-4x4-unorm-srgb":{gl:37840},"astc-5x4-unorm":{gl:37809},"astc-5x4-unorm-srgb":{gl:37841},"astc-5x5-unorm":{gl:37810},"astc-5x5-unorm-srgb":{gl:37842},"astc-6x5-unorm":{gl:37811},"astc-6x5-unorm-srgb":{gl:37843},"astc-6x6-unorm":{gl:37812},"astc-6x6-unorm-srgb":{gl:37844},"astc-8x5-unorm":{gl:37813},"astc-8x5-unorm-srgb":{gl:37845},"astc-8x6-unorm":{gl:37814},"astc-8x6-unorm-srgb":{gl:37846},"astc-8x8-unorm":{gl:37815},"astc-8x8-unorm-srgb":{gl:37847},"astc-10x5-unorm":{gl:37819},"astc-10x5-unorm-srgb":{gl:37851},"astc-10x6-unorm":{gl:37817},"astc-10x6-unorm-srgb":{gl:37849},"astc-10x8-unorm":{gl:37818},"astc-10x8-unorm-srgb":{gl:37850},"astc-10x10-unorm":{gl:37819},"astc-10x10-unorm-srgb":{gl:37851},"astc-12x10-unorm":{gl:37820},"astc-12x10-unorm-srgb":{gl:37852},"astc-12x12-unorm":{gl:37821},"astc-12x12-unorm-srgb":{gl:37853},"pvrtc-rgb4unorm-webgl":{gl:35840},"pvrtc-rgba4unorm-webgl":{gl:35842},"pvrtc-rbg2unorm-webgl":{gl:35841},"pvrtc-rgba2unorm-webgl":{gl:35843},"etc1-rbg-unorm-webgl":{gl:36196},"atc-rgb-unorm-webgl":{gl:35986},"atc-rgba-unorm-webgl":{gl:35986},"atc-rgbai-unorm-webgl":{gl:34798}};function At(r,e,t){let i=e.create;const n=ne[e.format];return n?.gl===void 0&&(i=!1),n?.x&&(i=i&&!!G(r,n.x,t)),{format:e.format,create:i&&e.create,render:i&&e.render,filter:i&&e.filter,blend:i&&e.blend,store:i&&e.store}}function Ce(r){const e=ne[r],t=Ft(r),i=Ee.getInfo(r);return i.compressed&&(e.dataFormat=t),{internalFormat:t,format:e?.dataFormat||Bt(i.channels,i.integer,i.normalized,t),type:i.dataType?Fe(i.dataType):e?.types?.[0]||5121,compressed:i.compressed||!1}}function Lt(r){switch(Ee.getInfo(r).attachment){case"depth":return 36096;case"stencil":return 36128;case"depth-stencil":return 33306;default:throw new Error(`Not a depth stencil format: ${r}`)}}function Bt(r,e,t,i){if(i===6408||i===6407)return i;switch(r){case"r":return e&&!t?36244:6403;case"rg":return e&&!t?33320:33319;case"rgb":return e&&!t?36248:6407;case"rgba":return e&&!t?36249:6408;case"bgra":throw new Error("bgra pixels not supported by WebGL");default:return 6408}}function Ft(r){const t=ne[r]?.gl;if(t===void 0)throw new Error(`Unsupported texture format ${r}`);return t}const ye={"depth-clip-control":"EXT_depth_clamp","timer-query-webgl":"EXT_disjoint_timer_query_webgl2","compilation-status-async-webgl":"KHR_parallel_shader_compile","polygon-mode-webgl":"WEBGL_polygon_mode","provoking-vertex-webgl":"WEBGL_provoking_vertex","shader-clip-cull-distance-webgl":"WEBGL_clip_cull_distance","shader-noperspective-interpolation-webgl":"NV_shader_noperspective_interpolation","shader-conservative-depth-webgl":"EXT_conservative_depth"};class Ct extends Oe{gl;extensions;testedFeatures=new Set;constructor(e,t,i){super([],i),this.gl=e,this.extensions=t,G(e,"EXT_color_buffer_float",t)}*[Symbol.iterator](){const e=this.getFeatures();for(const t of e)this.has(t)&&(yield t);return[]}has(e){return this.disabledFeatures?.[e]?!1:(this.testedFeatures.has(e)||(this.testedFeatures.add(e),Pt(e)&&Et(this.gl,e,this.extensions)&&this.features.add(e),this.getWebGLFeature(e)&&this.features.add(e)),this.features.has(e))}initializeFeatures(){const e=this.getFeatures().filter(t=>t!=="polygon-mode-webgl");for(const t of e)this.has(t)}getFeatures(){return[...Object.keys(ye),...Object.keys(ie)]}getWebGLFeature(e){const t=ye[e];return typeof t=="string"?!!G(this.gl,t,this.extensions):!!t}}class kt extends $e{get maxTextureDimension1D(){return 0}get maxTextureDimension2D(){return this.getParameter(3379)}get maxTextureDimension3D(){return this.getParameter(32883)}get maxTextureArrayLayers(){return this.getParameter(35071)}get maxBindGroups(){return 0}get maxDynamicUniformBuffersPerPipelineLayout(){return 0}get maxDynamicStorageBuffersPerPipelineLayout(){return 0}get maxSampledTexturesPerShaderStage(){return this.getParameter(35660)}get maxSamplersPerShaderStage(){return this.getParameter(35661)}get maxStorageBuffersPerShaderStage(){return 0}get maxStorageTexturesPerShaderStage(){return 0}get maxUniformBuffersPerShaderStage(){return this.getParameter(35375)}get maxUniformBufferBindingSize(){return this.getParameter(35376)}get maxStorageBufferBindingSize(){return 0}get minUniformBufferOffsetAlignment(){return this.getParameter(35380)}get minStorageBufferOffsetAlignment(){return 0}get maxVertexBuffers(){return 16}get maxVertexAttributes(){return this.getParameter(34921)}get maxVertexBufferArrayStride(){return 2048}get maxInterStageShaderVariables(){return this.getParameter(35659)}get maxComputeWorkgroupStorageSize(){return 0}get maxComputeInvocationsPerWorkgroup(){return 0}get maxComputeWorkgroupSizeX(){return 0}get maxComputeWorkgroupSizeY(){return 0}get maxComputeWorkgroupSizeZ(){return 0}get maxComputeWorkgroupsPerDimension(){return 0}gl;limits={};constructor(e){super(),this.gl=e}getParameter(e){return this.limits[e]===void 0&&(this.limits[e]=this.gl.getParameter(e)),this.limits[e]||0}}class O extends N{device;gl;handle;colorAttachments=[];depthStencilAttachment=null;constructor(e,t){super(e,t);const i=t.handle===null;this.device=e,this.gl=e.gl,this.handle=this.props.handle||i?this.props.handle:this.gl.createFramebuffer(),i||(e._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),this.autoCreateAttachmentTextures(),this.updateAttachments())}destroy(){super.destroy(),!this.destroyed&&this.handle!==null&&this.gl.deleteFramebuffer(this.handle)}updateAttachments(){const e=this.gl.bindFramebuffer(36160,this.handle);for(let t=0;t<this.colorAttachments.length;++t){const i=this.colorAttachments[t];if(i){const n=36064+t;this._attachTextureView(n,i)}}if(this.depthStencilAttachment){const t=Lt(this.depthStencilAttachment.props.format);this._attachTextureView(t,this.depthStencilAttachment)}if(this.device.props.debug){const t=this.gl.checkFramebufferStatus(36160);if(t!==36053)throw new Error(`Framebuffer ${Gt(t)}`)}this.gl.bindFramebuffer(36160,e)}_attachTextureView(e,t){const{gl:i}=this.device,{texture:n}=t,s=t.props.baseMipLevel,a=t.props.baseArrayLayer;switch(i.bindTexture(n.glTarget,n.handle),n.glTarget){case 35866:case 32879:i.framebufferTextureLayer(36160,e,n.handle,s,a);break;case 34067:const o=Dt(a);i.framebufferTexture2D(36160,e,o,n.handle,s);break;case 3553:i.framebufferTexture2D(36160,e,3553,n.handle,s);break;default:throw new Error("Illegal texture type")}i.bindTexture(n.glTarget,null)}}function Dt(r){return r<34069?r+34069:r}function Gt(r){switch(r){case 36053:return"success";case 36054:return"Mismatched attachments";case 36055:return"No attachments";case 36057:return"Height/width mismatch";case 36061:return"Unsupported or split attachments";case 36182:return"Samples mismatch";default:return`${r}`}}class Mt extends A{device;handle=null;_framebuffer=null;get[Symbol.toStringTag](){return"WebGLCanvasContext"}constructor(e,t){super(t),this.device=e,this._setAutoCreatedCanvasId(`${this.device.id}-canvas`),this._updateDevice()}getCurrentFramebuffer(){return this._framebuffer=this._framebuffer||new O(this.device,{handle:null}),this._framebuffer}_updateDevice(){}}const H={};function Wt(r="id"){H[r]=H[r]||1;const e=H[r]++;return`${r}-${e}`}class $ extends L{device;gl;handle;glTarget;glUsage;glIndexType=5123;byteLength=0;bytesUsed=0;constructor(e,t={}){super(e,t),this.device=e,this.gl=this.device.gl;const i=typeof t=="object"?t.handle:void 0;this.handle=i||this.gl.createBuffer(),e._setWebGLDebugMetadata(this.handle,this,{spector:{...this.props,data:typeof this.props.data}}),this.glTarget=Rt(this.props.usage),this.glUsage=It(this.props.usage),this.glIndexType=this.props.indexType==="uint32"?5125:5123,t.data?this._initWithData(t.data,t.byteOffset,t.byteLength):this._initWithByteLength(t.byteLength||0)}destroy(){!this.destroyed&&this.handle&&(this.removeStats(),this.trackDeallocatedMemory(),this.gl.deleteBuffer(this.handle),this.destroyed=!0,this.handle=null)}_initWithData(e,t=0,i=e.byteLength+t){const n=this.glTarget;this.gl.bindBuffer(n,this.handle),this.gl.bufferData(n,i,this.glUsage),this.gl.bufferSubData(n,t,e),this.gl.bindBuffer(n,null),this.bytesUsed=i,this.byteLength=i,this._setDebugData(e,t,i),this.trackAllocatedMemory(i)}_initWithByteLength(e){let t=e;e===0&&(t=new Float32Array(0));const i=this.glTarget;return this.gl.bindBuffer(i,this.handle),this.gl.bufferData(i,t,this.glUsage),this.gl.bindBuffer(i,null),this.bytesUsed=e,this.byteLength=e,this._setDebugData(null,0,e),this.trackAllocatedMemory(e),this}write(e,t=0){const i=ArrayBuffer.isView(e)?e:new Uint8Array(e),n=36663;this.gl.bindBuffer(n,this.handle),this.gl.bufferSubData(n,t,i),this.gl.bindBuffer(n,null),this._setDebugData(e,t,e.byteLength)}async mapAndWriteAsync(e,t=0,i=this.byteLength-t){const n=new ArrayBuffer(i);await e(n,"copied"),this.write(n,t)}async readAsync(e=0,t){return this.readSyncWebGL(e,t)}async mapAndReadAsync(e,t=0,i){const n=await this.readAsync(t,i);return await e(n.buffer,"copied")}readSyncWebGL(e=0,t){t=t??this.byteLength-e;const i=new Uint8Array(t),n=0;return this.gl.bindBuffer(36662,this.handle),this.gl.getBufferSubData(36662,e,i,n,t),this.gl.bindBuffer(36662,null),this._setDebugData(i,e,t),i}}function Rt(r){return r&L.INDEX?34963:r&L.VERTEX?34962:r&L.UNIFORM?35345:34962}function It(r){return r&L.INDEX||r&L.VERTEX?35044:r&L.UNIFORM?35048:35044}function Ot(r){const e=r.split(/\r?\n/),t=[];for(const i of e){if(i.length<=1)continue;const n=i.split(":");if(n.length===2){const[f,h]=n;t.push({message:h.trim(),type:we(f),lineNum:0,linePos:0});continue}const[s,a,o,...c]=n;let l=parseInt(o,10);isNaN(l)&&(l=0);let u=parseInt(a,10);isNaN(u)&&(u=0),t.push({message:c.join(":").trim(),type:we(s),lineNum:l,linePos:u})}return t}function we(r){const e=["warning","error","info"],t=r.toLowerCase();return e.includes(t)?t:"info"}class $t extends Qe{device;handle;constructor(e,t){switch(super(e,t),this.device=e,this.props.stage){case"vertex":this.handle=this.props.handle||this.device.gl.createShader(35633);break;case"fragment":this.handle=this.props.handle||this.device.gl.createShader(35632);break;default:throw new Error(this.props.stage)}e._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),this._compile(this.source)}destroy(){this.handle&&(this.removeStats(),this.device.gl.deleteShader(this.handle),this.destroyed=!0,this.handle.destroyed=!0)}get asyncCompilationStatus(){return this._waitForCompilationComplete().then(()=>(this._getCompilationStatus(),this.compilationStatus))}async getCompilationInfo(){return await this._waitForCompilationComplete(),this.getCompilationInfoSync()}getCompilationInfoSync(){const e=this.device.gl.getShaderInfoLog(this.handle);return e?Ot(e):[]}getTranslatedSource(){return this.device.getExtension("WEBGL_debug_shaders").WEBGL_debug_shaders?.getTranslatedShaderSource(this.handle)||null}async _compile(e){e=e.startsWith("#version ")?e:`#version 300 es
2
+ ${e}`;const{gl:t}=this.device;if(t.shaderSource(this.handle,e),t.compileShader(this.handle),!this.device.props.debug){this.compilationStatus="pending";return}if(!this.device.features.has("compilation-status-async-webgl")){if(this._getCompilationStatus(),this.debugShader(),this.compilationStatus==="error")throw new Error(`GLSL compilation errors in ${this.props.stage} shader ${this.props.id}`);return}g.once(1,"Shader compilation is asynchronous")(),await this._waitForCompilationComplete(),g.info(2,`Shader ${this.id} - async compilation complete: ${this.compilationStatus}`)(),this._getCompilationStatus(),this.debugShader()}async _waitForCompilationComplete(){const e=async n=>await new Promise(s=>setTimeout(s,n));if(!this.device.features.has("compilation-status-async-webgl")){await e(10);return}const{gl:i}=this.device;for(;;){if(i.getShaderParameter(this.handle,37297))return;await e(10)}}_getCompilationStatus(){this.compilationStatus=this.device.gl.getShaderParameter(this.handle,35713)?"success":"error"}}function zt(r,e,t,i){if(Xt(e))return i(r);const n=r;n.pushState();try{return Vt(r,e),M(n.gl,t),i(r)}finally{n.popState()}}function Vt(r,e){const t=r,{gl:i}=t;if(e.cullMode)switch(e.cullMode){case"none":i.disable(2884);break;case"front":i.enable(2884),i.cullFace(1028);break;case"back":i.enable(2884),i.cullFace(1029);break}if(e.frontFace&&i.frontFace(F("frontFace",e.frontFace,{ccw:2305,cw:2304})),e.unclippedDepth&&r.features.has("depth-clip-control")&&i.enable(34383),e.depthBias!==void 0&&(i.enable(32823),i.polygonOffset(e.depthBias,e.depthBiasSlopeScale||0)),e.provokingVertex&&r.features.has("provoking-vertex-webgl")){const s=t.getExtension("WEBGL_provoking_vertex").WEBGL_provoking_vertex,a=F("provokingVertex",e.provokingVertex,{first:36429,last:36430});s?.provokingVertexWEBGL(a)}if((e.polygonMode||e.polygonOffsetLine)&&r.features.has("polygon-mode-webgl")){if(e.polygonMode){const s=t.getExtension("WEBGL_polygon_mode").WEBGL_polygon_mode,a=F("polygonMode",e.polygonMode,{fill:6914,line:6913});s?.polygonModeWEBGL(1028,a),s?.polygonModeWEBGL(1029,a)}e.polygonOffsetLine&&i.enable(10754)}if(r.features.has("shader-clip-cull-distance-webgl")&&(e.clipDistance0&&i.enable(12288),e.clipDistance1&&i.enable(12289),e.clipDistance2&&i.enable(12290),e.clipDistance3&&i.enable(12291),e.clipDistance4&&i.enable(12292),e.clipDistance5&&i.enable(12293),e.clipDistance6&&i.enable(12294),e.clipDistance7&&i.enable(12295)),e.depthWriteEnabled!==void 0&&i.depthMask(Nt("depthWriteEnabled",e.depthWriteEnabled)),e.depthCompare&&(e.depthCompare!=="always"?i.enable(2929):i.disable(2929),i.depthFunc(j("depthCompare",e.depthCompare))),e.stencilWriteMask){const n=e.stencilWriteMask;i.stencilMaskSeparate(1028,n),i.stencilMaskSeparate(1029,n)}if(e.stencilReadMask&&g.warn("stencilReadMask not supported under WebGL"),e.stencilCompare){const n=e.stencilReadMask||4294967295,s=j("depthCompare",e.stencilCompare);e.stencilCompare!=="always"?i.enable(2960):i.disable(2960),i.stencilFuncSeparate(1028,s,0,n),i.stencilFuncSeparate(1029,s,0,n)}if(e.stencilPassOperation&&e.stencilFailOperation&&e.stencilDepthFailOperation){const n=Q("stencilPassOperation",e.stencilPassOperation),s=Q("stencilFailOperation",e.stencilFailOperation),a=Q("stencilDepthFailOperation",e.stencilDepthFailOperation);i.stencilOpSeparate(1028,s,a,n),i.stencilOpSeparate(1029,s,a,n)}switch(e.blend){case!0:i.enable(3042);break;case!1:i.disable(3042);break}if(e.blendColorOperation||e.blendAlphaOperation){const n=ve("blendColorOperation",e.blendColorOperation||"add"),s=ve("blendAlphaOperation",e.blendAlphaOperation||"add");i.blendEquationSeparate(n,s);const a=U("blendColorSrcFactor",e.blendColorSrcFactor||"one"),o=U("blendColorDstFactor",e.blendColorDstFactor||"zero"),c=U("blendAlphaSrcFactor",e.blendAlphaSrcFactor||"one"),l=U("blendAlphaDstFactor",e.blendAlphaDstFactor||"zero");i.blendFuncSeparate(a,o,c,l)}}function j(r,e){return F(r,e,{never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519})}function Q(r,e){return F(r,e,{keep:7680,zero:0,replace:7681,invert:5386,"increment-clamp":7682,"decrement-clamp":7683,"increment-wrap":34055,"decrement-wrap":34056})}function ve(r,e){return F(r,e,{add:32774,subtract:32778,"reverse-subtract":32779,min:32775,max:32776})}function U(r,e,t="color"){return F(r,e,{one:1,zero:0,src:768,"one-minus-src":769,dst:774,"one-minus-dst":775,"src-alpha":770,"one-minus-src-alpha":771,"dst-alpha":772,"one-minus-dst-alpha":773,"src-alpha-saturated":776,constant:t==="color"?32769:32771,"one-minus-constant":t==="color"?32770:32772,src1:768,"one-minus-src1":769,"src1-alpha":770,"one-minus-src1-alpha":771})}function Ut(r,e){return`Illegal parameter ${e} for ${r}`}function F(r,e,t){if(!(e in t))throw new Error(Ut(r,e));return t[e]}function Nt(r,e){return e}function Xt(r){let e=!0;for(const t in r){e=!1;break}return e}function ke(r){const e={};return r.addressModeU&&(e[10242]=q(r.addressModeU)),r.addressModeV&&(e[10243]=q(r.addressModeV)),r.addressModeW&&(e[32882]=q(r.addressModeW)),r.magFilter&&(e[10240]=Y(r.magFilter)),(r.minFilter||r.mipmapFilter)&&(e[10241]=Ht(r.minFilter||"linear",r.mipmapFilter)),r.lodMinClamp!==void 0&&(e[33082]=r.lodMinClamp),r.lodMaxClamp!==void 0&&(e[33083]=r.lodMaxClamp),r.type==="comparison-sampler"&&(e[34892]=34894),r.compare&&(e[34893]=j("compare",r.compare)),r.maxAnisotropy&&(e[34046]=r.maxAnisotropy),e}function q(r){switch(r){case"clamp-to-edge":return 33071;case"repeat":return 10497;case"mirror-repeat":return 33648}}function Y(r){switch(r){case"nearest":return 9728;case"linear":return 9729}}function Ht(r,e="none"){if(!e)return Y(r);switch(e){case"none":return Y(r);case"nearest":switch(r){case"nearest":return 9984;case"linear":return 9985}break;case"linear":switch(r){case"nearest":return 9986;case"linear":return 9987}}}class Qt extends qe{device;handle;parameters;constructor(e,t){super(e,t),this.device=e,this.parameters=ke(t),this.handle=t.handle||this.device.gl.createSampler(),this._setSamplerParameters(this.parameters)}destroy(){this.handle&&(this.device.gl.deleteSampler(this.handle),this.handle=void 0)}toString(){return`Sampler(${this.id},${JSON.stringify(this.props)})`}_setSamplerParameters(e){for(const[t,i]of Object.entries(e)){const n=Number(t);switch(n){case 33082:case 33083:this.device.gl.samplerParameterf(this.handle,n,i);break;default:this.device.gl.samplerParameteri(this.handle,n,i);break}}}}function V(r,e,t){if(qt(e))return t(r);const{nocatch:i=!0}=e,n=B.get(r);n.push(),M(r,e);let s;if(i)s=t(r),n.pop();else try{s=t(r)}finally{n.pop()}return s}function qt(r){for(const e in r)return!1;return!0}class D extends je{device;gl;handle;texture;constructor(e,t){super(e,{...E.defaultProps,...t}),this.device=e,this.gl=this.device.gl,this.handle=null,this.texture=t.texture}}class z extends E{device;gl;handle;sampler=void 0;view;glTarget;glFormat;glType;glInternalFormat;compressed;_textureUnit=0;constructor(e,t){super(e,t),this.device=e,this.gl=this.device.gl;const i=Ce(this.props.format);this.glTarget=jt(this.props.dimension),this.glInternalFormat=i.internalFormat,this.glFormat=i.format,this.glType=i.type,this.compressed=i.compressed,this.handle=this.props.handle||this.gl.createTexture(),this.device._setWebGLDebugMetadata(this.handle,this,{spector:this.props}),this.gl.bindTexture(this.glTarget,this.handle);const{dimension:n,width:s,height:a,depth:o,mipLevels:c,glTarget:l,glInternalFormat:u}=this;switch(n){case"2d":case"cube":this.gl.texStorage2D(l,c,u,s,a);break;case"2d-array":case"3d":this.gl.texStorage3D(l,c,u,s,a,o);break;default:throw new Error(n)}this.gl.bindTexture(this.glTarget,null),this._initializeData(t.data),this.setSampler(this.props.sampler),this.view=new D(this.device,{...this.props,texture:this}),Object.seal(this)}destroy(){this.handle&&(this.gl.deleteTexture(this.handle),this.removeStats(),this.trackDeallocatedMemory("Texture"),this.destroyed=!0)}createView(e){return new D(this.device,{...e,texture:this})}setSampler(e={}){super.setSampler(e);const t=ke(this.sampler.props);this._setSamplerParameters(t)}copyImageData(e){const t=this._normalizeCopyImageDataOptions(e),i=t.data,{width:n,height:s,depth:a}=this,{mipLevel:o=0,byteOffset:c=0,x:l=0,y:u=0,z:f=0}=t,{glFormat:h,glType:d,compressed:b}=this,p=Se(this.glTarget,this.dimension,f);let S;if(!this.compressed){const{bytesPerPixel:T}=this.device.getTextureFormatInfo(this.format);if(T){if(t.bytesPerRow%T!==0)throw new Error(`bytesPerRow (${t.bytesPerRow}) must be a multiple of bytesPerPixel (${T}) for ${this.format}`);S=t.bytesPerRow/T}}const y=this.compressed?{}:{...S!==void 0?{3314:S}:{},32878:t.rowsPerImage};this.gl.bindTexture(p,this.handle),V(this.gl,y,()=>{switch(this.dimension){case"2d":case"cube":b?this.gl.compressedTexSubImage2D(p,o,l,u,n,s,h,i,c):this.gl.texSubImage2D(p,o,l,u,n,s,h,d,i,c);break;case"2d-array":case"3d":b?this.gl.compressedTexSubImage3D(p,o,l,u,f,n,s,a,h,i,c):this.gl.texSubImage3D(p,o,l,u,f,n,s,a,h,d,i,c);break;default:}}),this.gl.bindTexture(p,null)}copyExternalImage(e){const t=this._normalizeCopyExternalImageOptions(e);if(t.sourceX||t.sourceY)throw new Error("WebGL does not support sourceX/sourceY)");const{glFormat:i,glType:n}=this,{image:s,depth:a,mipLevel:o,x:c,y:l,z:u,width:f,height:h}=t,d=Se(this.glTarget,this.dimension,a),b=t.flipY?{37440:!0}:{};return this.gl.bindTexture(this.glTarget,this.handle),V(this.gl,b,()=>{switch(this.dimension){case"2d":case"cube":this.gl.texSubImage2D(d,o,c,l,f,h,i,n,s);break;case"2d-array":case"3d":this.gl.texSubImage3D(d,o,c,l,u,f,h,a,i,n,s);break;default:}}),this.gl.bindTexture(this.glTarget,null),{width:t.width,height:t.height}}generateMipmapsWebGL(e){if(!(!(this.device.isTextureFormatRenderable(this.props.format)&&this.device.isTextureFormatFilterable(this.props.format))&&(g.warn(`${this} is not renderable or filterable, may not be able to generate mipmaps`)(),!e?.force)))try{this.gl.bindTexture(this.glTarget,this.handle),this.gl.generateMipmap(this.glTarget)}catch(i){g.warn(`Error generating mipmap for ${this}: ${i.message}`)()}finally{this.gl.bindTexture(this.glTarget,null)}}_setSamplerParameters(e){g.log(2,`${this.id} sampler parameters`,this.device.getGLKeys(e))(),this.gl.bindTexture(this.glTarget,this.handle);for(const[t,i]of Object.entries(e)){const n=Number(t),s=i;switch(n){case 33082:case 33083:this.gl.texParameterf(this.glTarget,n,s);break;case 10240:case 10241:this.gl.texParameteri(this.glTarget,n,s);break;case 10242:case 10243:case 32882:this.gl.texParameteri(this.glTarget,n,s);break;case 34046:this.device.features.has("texture-filterable-anisotropic-webgl")&&this.gl.texParameteri(this.glTarget,n,s);break;case 34892:case 34893:this.gl.texParameteri(this.glTarget,n,s);break}}this.gl.bindTexture(this.glTarget,null)}_getActiveUnit(){return this.gl.getParameter(34016)-33984}_bind(e){const{gl:t}=this;return e!==void 0&&(this._textureUnit=e,t.activeTexture(33984+e)),t.bindTexture(this.glTarget,this.handle),e}_unbind(e){const{gl:t}=this;return e!==void 0&&(this._textureUnit=e,t.activeTexture(33984+e)),t.bindTexture(this.glTarget,null),e}}function jt(r){switch(r){case"1d":break;case"2d":return 3553;case"3d":return 32879;case"cube":return 34067;case"2d-array":return 35866}throw new Error(r)}function Se(r,e,t){return e==="cube"?34069+t:r}function Yt(r){return er[r]}function se(r){return Jt[r]}function Kt(r){return!!De[r]}function Zt(r){return De[r]}const Jt={5126:"f32",35664:"vec2<f32>",35665:"vec3<f32>",35666:"vec4<f32>",5124:"i32",35667:"vec2<i32>",35668:"vec3<i32>",35669:"vec4<i32>",5125:"u32",36294:"vec2<u32>",36295:"vec3<u32>",36296:"vec4<u32>",35670:"f32",35671:"vec2<f32>",35672:"vec3<f32>",35673:"vec4<f32>",35674:"mat2x2<f32>",35685:"mat2x3<f32>",35686:"mat2x4<f32>",35687:"mat3x2<f32>",35675:"mat3x3<f32>",35688:"mat3x4<f32>",35689:"mat4x2<f32>",35690:"mat4x3<f32>",35676:"mat4x4<f32>"},De={35678:{viewDimension:"2d",sampleType:"float"},35680:{viewDimension:"cube",sampleType:"float"},35679:{viewDimension:"3d",sampleType:"float"},35682:{viewDimension:"3d",sampleType:"depth"},36289:{viewDimension:"2d-array",sampleType:"float"},36292:{viewDimension:"2d-array",sampleType:"depth"},36293:{viewDimension:"cube",sampleType:"float"},36298:{viewDimension:"2d",sampleType:"sint"},36299:{viewDimension:"3d",sampleType:"sint"},36300:{viewDimension:"cube",sampleType:"sint"},36303:{viewDimension:"2d-array",sampleType:"uint"},36306:{viewDimension:"2d",sampleType:"uint"},36307:{viewDimension:"3d",sampleType:"uint"},36308:{viewDimension:"cube",sampleType:"uint"},36311:{viewDimension:"2d-array",sampleType:"uint"}},er={uint8:5121,sint8:5120,unorm8:5121,snorm8:5120,uint16:5123,sint16:5122,unorm16:5123,snorm16:5122,uint32:5125,sint32:5124,float16:5131,float32:5126};function tr(r,e){const t={attributes:[],bindings:[]};t.attributes=rr(r,e);const i=sr(r,e);for(const o of i){const c=o.uniforms.map(l=>({name:l.name,format:l.format,byteOffset:l.byteOffset,byteStride:l.byteStride,arrayLength:l.arrayLength}));t.bindings.push({type:"uniform",name:o.name,group:0,location:o.location,visibility:(o.vertex?1:0)&(o.fragment?2:0),minBindingSize:o.byteLength,uniforms:c})}const n=nr(r,e);let s=0;for(const o of n)if(Kt(o.type)){const{viewDimension:c,sampleType:l}=Zt(o.type);t.bindings.push({type:"texture",name:o.name,group:0,location:s,viewDimension:c,sampleType:l}),o.textureUnit=s,s+=1}n.length&&(t.uniforms=n);const a=ir(r,e);return a?.length&&(t.varyings=a),t}function rr(r,e){const t=[],i=r.getProgramParameter(e,35721);for(let n=0;n<i;n++){const s=r.getActiveAttrib(e,n);if(!s)throw new Error("activeInfo");const{name:a,type:o}=s,c=r.getAttribLocation(e,a);if(c>=0){const l=se(o),u=/instance/i.test(a)?"instance":"vertex";t.push({name:a,location:c,stepMode:u,type:l})}}return t.sort((n,s)=>n.location-s.location),t}function ir(r,e){const t=[],i=r.getProgramParameter(e,35971);for(let n=0;n<i;n++){const s=r.getTransformFeedbackVarying(e,n);if(!s)throw new Error("activeInfo");const{name:a,type:o,size:c}=s,l=se(o),{type:u,components:f}=Ye(l);t.push({location:n,name:a,type:u,size:c*f})}return t.sort((n,s)=>n.location-s.location),t}function nr(r,e){const t=[],i=r.getProgramParameter(e,35718);for(let n=0;n<i;n++){const s=r.getActiveUniform(e,n);if(!s)throw new Error("activeInfo");const{name:a,size:o,type:c}=s,{name:l,isArray:u}=ar(a);let f=r.getUniformLocation(e,l);const h={location:f,name:l,size:o,type:c,isArray:u};if(t.push(h),h.size>1)for(let d=0;d<h.size;d++){const b=`${l}[${d}]`;f=r.getUniformLocation(e,b);const p={...h,name:b,location:f};t.push(p)}}return t}function sr(r,e){const t=(s,a)=>r.getActiveUniformBlockParameter(e,s,a),i=[],n=r.getProgramParameter(e,35382);for(let s=0;s<n;s++){const a={name:r.getActiveUniformBlockName(e,s)||"",location:t(s,35391),byteLength:t(s,35392),vertex:t(s,35396),fragment:t(s,35398),uniformCount:t(s,35394),uniforms:[]},o=t(s,35395)||[],c=r.getActiveUniforms(e,o,35383),l=r.getActiveUniforms(e,o,35384),u=r.getActiveUniforms(e,o,35387),f=r.getActiveUniforms(e,o,35388);for(let h=0;h<a.uniformCount;++h){const d=r.getActiveUniform(e,o[h]);if(!d)throw new Error("activeInfo");const b=se(c[h]);a.uniforms.push({name:d.name,format:b,type:c[h],arrayLength:l[h],byteOffset:u[h],byteStride:f[h]})}i.push(a)}return i.sort((s,a)=>s.location-a.location),i}function ar(r){if(r[r.length-1]!=="]")return{name:r,length:1,isArray:!1};const t=/([^[]*)(\[[0-9]+\])?/.exec(r);if(!t||t.length<2)throw new Error(`Failed to parse GLSL uniform name ${r}`);return{name:t[1],length:t[2]?1:0,isArray:!!t[2]}}function or(r,e,t,i){const n=r;let s=i;s===!0&&(s=1),s===!1&&(s=0);const a=typeof s=="number"?[s]:s;switch(t){case 35678:case 35680:case 35679:case 35682:case 36289:case 36292:case 36293:case 36298:case 36299:case 36300:case 36303:case 36306:case 36307:case 36308:case 36311:if(typeof i!="number")throw new Error("samplers must be set to integers");return r.uniform1i(e,i);case 5126:return r.uniform1fv(e,a);case 35664:return r.uniform2fv(e,a);case 35665:return r.uniform3fv(e,a);case 35666:return r.uniform4fv(e,a);case 5124:return r.uniform1iv(e,a);case 35667:return r.uniform2iv(e,a);case 35668:return r.uniform3iv(e,a);case 35669:return r.uniform4iv(e,a);case 35670:return r.uniform1iv(e,a);case 35671:return r.uniform2iv(e,a);case 35672:return r.uniform3iv(e,a);case 35673:return r.uniform4iv(e,a);case 5125:return n.uniform1uiv(e,a,1);case 36294:return n.uniform2uiv(e,a,2);case 36295:return n.uniform3uiv(e,a,3);case 36296:return n.uniform4uiv(e,a,4);case 35674:return r.uniformMatrix2fv(e,!1,a);case 35675:return r.uniformMatrix3fv(e,!1,a);case 35676:return r.uniformMatrix4fv(e,!1,a);case 35685:return n.uniformMatrix2x3fv(e,!1,a);case 35686:return n.uniformMatrix2x4fv(e,!1,a);case 35687:return n.uniformMatrix3x2fv(e,!1,a);case 35688:return n.uniformMatrix3x4fv(e,!1,a);case 35689:return n.uniformMatrix4x2fv(e,!1,a);case 35690:return n.uniformMatrix4x3fv(e,!1,a)}throw new Error("Illegal uniform")}function cr(r){switch(r){case"point-list":return 0;case"line-list":return 1;case"line-strip":return 3;case"triangle-list":return 4;case"triangle-strip":return 5;default:throw new Error(r)}}function lr(r){switch(r){case"point-list":return 0;case"line-list":return 1;case"line-strip":return 1;case"triangle-list":return 4;case"triangle-strip":return 4;default:throw new Error(r)}}const Te=4;class ur extends Ke{device;handle;vs;fs;introspectedLayout;uniforms={};bindings={};varyings=null;_uniformCount=0;_uniformSetters={};get[Symbol.toStringTag](){return"WEBGLRenderPipeline"}constructor(e,t){super(e,t),this.device=e,this.handle=this.props.handle||this.device.gl.createProgram(),this.device._setWebGLDebugMetadata(this.handle,this,{spector:{id:this.props.id}}),this.vs=t.vs,this.fs=t.fs;const{varyings:i,bufferMode:n=35981}=t;i&&i.length>0&&(this.varyings=i,this.device.gl.transformFeedbackVaryings(this.handle,i,n)),this._linkShaders(),g.time(3,`RenderPipeline ${this.id} - shaderLayout introspection`)(),this.introspectedLayout=tr(this.device.gl,this.handle),g.timeEnd(3,`RenderPipeline ${this.id} - shaderLayout introspection`)(),this.shaderLayout=t.shaderLayout?hr(this.introspectedLayout,t.shaderLayout):this.introspectedLayout}destroy(){this.handle&&(this.device.gl.useProgram(null),this.device.gl.deleteProgram(this.handle),this.destroyed=!0,this.handle.destroyed=!0,this.handle=null)}setBindings(e,t){for(const[i,n]of Object.entries(e)){const s=this.shaderLayout.bindings.find(a=>a.name===i)||this.shaderLayout.bindings.find(a=>a.name===`${i}Uniforms`);if(!s){const a=this.shaderLayout.bindings.map(o=>`"${o.name}"`).join(", ");t?.disableWarnings||g.warn(`No binding "${i}" in render pipeline "${this.id}", expected one of ${a}`,n)();continue}switch(n||g.warn(`Unsetting binding "${i}" in render pipeline "${this.id}"`)(),s.type){case"uniform":if(!(n instanceof $)&&!(n.buffer instanceof $))throw new Error("buffer value");break;case"texture":if(!(n instanceof D||n instanceof z||n instanceof O))throw new Error(`${this} Bad texture binding for ${i}`);break;case"sampler":g.warn(`Ignoring sampler ${i}`)();break;default:throw new Error(s.type)}this.bindings[i]=n}}draw(e){const{renderPass:t,parameters:i=this.props.parameters,topology:n=this.props.topology,vertexArray:s,vertexCount:a,instanceCount:o,isInstanced:c=!1,firstVertex:l=0,transformFeedback:u}=e,f=cr(n),h=!!s.indexBuffer,d=s.indexBuffer?.glIndexType;if(this.linkStatus!=="success")return g.info(2,`RenderPipeline:${this.id}.draw() aborted - waiting for shader linking`)(),!1;if(!this._areTexturesRenderable())return g.info(2,`RenderPipeline:${this.id}.draw() aborted - textures not yet loaded`)(),!1;this.device.gl.useProgram(this.handle),s.bindBeforeRender(t),u&&u.begin(this.props.topology),this._applyBindings(),this._applyUniforms();const b=t;return zt(this.device,i,b.glParameters,()=>{h&&c?this.device.gl.drawElementsInstanced(f,a||0,d,l,o||0):h?this.device.gl.drawElements(f,a||0,d,l):c?this.device.gl.drawArraysInstanced(f,l,a||0,o||0):this.device.gl.drawArrays(f,l,a||0),u&&u.end()}),s.unbindAfterRender(t),!0}async _linkShaders(){const{gl:e}=this.device;if(e.attachShader(this.handle,this.vs.handle),e.attachShader(this.handle,this.fs.handle),g.time(Te,`linkProgram for ${this.id}`)(),e.linkProgram(this.handle),g.timeEnd(Te,`linkProgram for ${this.id}`)(),g.level,!this.device.features.has("compilation-status-async-webgl")){const i=this._getLinkStatus();this._reportLinkStatus(i);return}g.once(1,"RenderPipeline linking is asynchronous")(),await this._waitForLinkComplete(),g.info(2,`RenderPipeline ${this.id} - async linking complete: ${this.linkStatus}`)();const t=this._getLinkStatus();this._reportLinkStatus(t)}async _reportLinkStatus(e){switch(e){case"success":return;default:const t=e==="link-error"?"Link error":"Validation error";switch(this.vs.compilationStatus){case"error":throw this.vs.debugShader(),new Error(`${this} ${t} during compilation of ${this.vs}`);case"pending":await this.vs.asyncCompilationStatus,this.vs.debugShader();break}switch(this.fs?.compilationStatus){case"error":throw this.fs.debugShader(),new Error(`${this} ${t} during compilation of ${this.fs}`);case"pending":await this.fs.asyncCompilationStatus,this.fs.debugShader();break}const i=this.device.gl.getProgramInfoLog(this.handle);this.device.reportError(new Error(`${t} during ${e}: ${i}`),this)(),this.device.debug()}}_getLinkStatus(){const{gl:e}=this.device;return e.getProgramParameter(this.handle,35714)?(e.validateProgram(this.handle),e.getProgramParameter(this.handle,35715)?(this.linkStatus="success","success"):(this.linkStatus="error","validation-error")):(this.linkStatus="error","link-error")}async _waitForLinkComplete(){const e=async n=>await new Promise(s=>setTimeout(s,n));if(!this.device.features.has("compilation-status-async-webgl")){await e(10);return}const{gl:i}=this.device;for(;;){if(i.getProgramParameter(this.handle,37297))return;await e(10)}}_areTexturesRenderable(){let e=!0;for(const t of this.shaderLayout.bindings)!this.bindings[t.name]&&!this.bindings[t.name.replace(/Uniforms$/,"")]&&(g.warn(`Binding ${t.name} not found in ${this.id}`)(),e=!1);return e}_applyBindings(){if(this.linkStatus!=="success")return;const{gl:e}=this.device;e.useProgram(this.handle);let t=0,i=0;for(const n of this.shaderLayout.bindings){const s=this.bindings[n.name]||this.bindings[n.name.replace(/Uniforms$/,"")];if(!s)throw new Error(`No value for binding ${n.name} in ${this.id}`);switch(n.type){case"uniform":const{name:a}=n,o=e.getUniformBlockIndex(this.handle,a);if(o===4294967295)throw new Error(`Invalid uniform block name ${a}`);e.uniformBlockBinding(this.handle,i,o),s instanceof $?e.bindBufferBase(35345,i,s.handle):e.bindBufferRange(35345,i,s.buffer.handle,s.offset||0,s.size||s.buffer.byteLength-s.offset),i+=1;break;case"texture":if(!(s instanceof D||s instanceof z||s instanceof O))throw new Error("texture");let c;if(s instanceof D)c=s.texture;else if(s instanceof z)c=s;else if(s instanceof O&&s.colorAttachments[0]instanceof D)g.warn("Passing framebuffer in texture binding may be deprecated. Use fbo.colorAttachments[0] instead")(),c=s.colorAttachments[0].texture;else throw new Error("No texture");e.activeTexture(33984+t),e.bindTexture(c.glTarget,c.handle),t+=1;break;case"sampler":break;case"storage":case"read-only-storage":throw new Error(`binding type '${n.type}' not supported in WebGL`)}}}_applyUniforms(){for(const e of this.shaderLayout.uniforms||[]){const{name:t,location:i,type:n,textureUnit:s}=e,a=this.uniforms[t]??s;a!==void 0&&or(this.device.gl,i,n,a)}}}function hr(r,e){const t={...r,attributes:r.attributes.map(i=>({...i}))};for(const i of e?.attributes||[]){const n=t.attributes.find(s=>s.name===i.name);n?(n.type=i.type||n.type,n.stepMode=i.stepMode||n.stepMode):g.warn(`shader layout attribute ${i.name} not present in shader`)}return t}class fr extends Z{device;handle=null;commands=[];constructor(e){super(e,{}),this.device=e}_executeCommands(e=this.commands){for(const t of e)switch(t.name){case"copy-buffer-to-buffer":dr(this.device,t.options);break;case"copy-buffer-to-texture":gr(this.device,t.options);break;case"copy-texture-to-buffer":br(this.device,t.options);break;case"copy-texture-to-texture":mr(this.device,t.options);break;default:throw new Error(t.name)}}}function dr(r,e){const t=e.sourceBuffer,i=e.destinationBuffer;r.gl.bindBuffer(36662,t.handle),r.gl.bindBuffer(36663,i.handle),r.gl.copyBufferSubData(36662,36663,e.sourceOffset??0,e.destinationOffset??0,e.size),r.gl.bindBuffer(36662,null),r.gl.bindBuffer(36663,null)}function gr(r,e){throw new Error("Not implemented")}function br(r,e){const{sourceTexture:t,mipLevel:i=0,aspect:n="all",width:s=e.sourceTexture.width,height:a=e.sourceTexture.height,depthOrArrayLayers:o=0,origin:c=[0,0],destinationBuffer:l,byteOffset:u=0,bytesPerRow:f,rowsPerImage:h}=e;if(n!=="all")throw new Error("aspect not supported in WebGL");if(i!==0||o!==0||f||h)throw new Error("not implemented");const{framebuffer:d,destroyFramebuffer:b}=Ge(t);let p;try{const S=l,y=s||d.width,T=a||d.height,oe=Ce(d.colorAttachments[0].texture.props.format),Re=oe.format,Ie=oe.type;r.gl.bindBuffer(35051,S.handle),p=r.gl.bindFramebuffer(36160,d.handle),r.gl.readPixels(c[0],c[1],y,T,Re,Ie,u)}finally{r.gl.bindBuffer(35051,null),p!==void 0&&r.gl.bindFramebuffer(36160,p),b&&d.destroy()}}function mr(r,e){const{sourceTexture:t,destinationMipLevel:i=0,origin:n=[0,0],destinationOrigin:s=[0,0],destinationTexture:a}=e;let{width:o=e.destinationTexture.width,height:c=e.destinationTexture.height}=e;const{framebuffer:l,destroyFramebuffer:u}=Ge(t),[f,h]=n,[d,b,p]=s,S=r.gl.bindFramebuffer(36160,l.handle);let y,T;if(a instanceof z)y=a,o=Number.isFinite(o)?o:y.width,c=Number.isFinite(c)?c:y.height,y._bind(0),T=y.glTarget;else throw new Error("invalid destination");switch(T){case 3553:case 34067:r.gl.copyTexSubImage2D(T,i,d,b,f,h,o,c);break;case 35866:case 32879:r.gl.copyTexSubImage3D(T,i,d,b,p,f,h,o,c);break}y&&y._unbind(),r.gl.bindFramebuffer(36160,S),u&&l.destroy()}function Ge(r){if(r instanceof E){const{width:e,height:t,id:i}=r;return{framebuffer:r.device.createFramebuffer({id:`framebuffer-for-${i}`,width:e,height:t,colorAttachments:[r]}),destroyFramebuffer:!0}}return{framebuffer:r,destroyFramebuffer:!1}}const pr=[1,2,4,8];class xr extends P{device;handle=null;glParameters={};constructor(e,t){super(e,t),this.device=e;let i;if(!t?.parameters?.viewport)if(t?.framebuffer){const{width:s,height:a}=t.framebuffer;i=[0,0,s,a]}else{const[s,a]=e.getDefaultCanvasContext().getDrawingBufferSize();i=[0,0,s,a]}this.device.pushState(),this.setParameters({viewport:i,...this.props.parameters});const n=this.props.framebuffer;if(this.props.framebuffer&&n?.handle){const s=this.props.framebuffer.colorAttachments.map((a,o)=>36064+o);this.device.gl.drawBuffers(s)}else this.device.gl.drawBuffers([1029]);this.clear()}end(){this.device.popState()}pushDebugGroup(e){}popDebugGroup(){}insertDebugMarker(e){}setParameters(e={}){const t={...this.glParameters};t.framebuffer=this.props.framebuffer||null,this.props.depthReadOnly&&(t.depthMask=!this.props.depthReadOnly),t.stencilMask=this.props.stencilReadOnly?0:1,t[35977]=this.props.discard,e.viewport&&(e.viewport.length>=6?(t.viewport=e.viewport.slice(0,4),t.depthRange=[e.viewport[4],e.viewport[5]]):t.viewport=e.viewport),e.scissorRect&&(t.scissorTest=!0,t.scissor=e.scissorRect),e.blendConstant&&(t.blendColor=e.blendConstant),e.stencilReference&&(console.warn("RenderPassParameters.stencilReference not yet implemented in WebGL"),t[2967]=e.stencilReference),"colorMask"in e&&(t.colorMask=pr.map(i=>!!(i&e.colorMask))),this.glParameters=t,M(this.device.gl,t)}beginOcclusionQuery(e){this.props.occlusionQuerySet?.beginOcclusionQuery()}endOcclusionQuery(){this.props.occlusionQuerySet?.endOcclusionQuery()}clear(){const e={...this.glParameters};let t=0;this.props.clearColors&&this.props.clearColors.forEach((i,n)=>{i&&this.clearColorBuffer(n,i)}),this.props.clearColor!==!1&&this.props.clearColors===void 0&&(t|=16384,e.clearColor=this.props.clearColor),this.props.clearDepth!==!1&&(t|=256,e.clearDepth=this.props.clearDepth),this.props.clearStencil!==!1&&(t|=1024,e.clearStencil=this.props.clearStencil),t!==0&&V(this.device.gl,e,()=>{this.device.gl.clear(t)})}clearColorBuffer(e=0,t=[0,0,0,0]){V(this.device.gl,{framebuffer:this.props.framebuffer},()=>{switch(t.constructor){case Int8Array:case Int16Array:case Int32Array:this.device.gl.clearBufferiv(6144,e,t);break;case Uint8Array:case Uint8ClampedArray:case Uint16Array:case Uint32Array:this.device.gl.clearBufferuiv(6144,e,t);break;case Float32Array:this.device.gl.clearBufferfv(6144,e,t);break;default:throw new Error("clearColorBuffer: color must be typed array")}})}}class _e extends K{device;handle=null;commandBuffer;constructor(e,t){super(e,t),this.device=e,this.commandBuffer=new fr(e)}destroy(){}finish(){return this.commandBuffer}beginRenderPass(e){return new xr(this.device,e)}beginComputePass(e){throw new Error("ComputePass not supported in WebGL")}copyBufferToBuffer(e){this.commandBuffer.commands.push({name:"copy-buffer-to-buffer",options:e})}copyBufferToTexture(e){this.commandBuffer.commands.push({name:"copy-buffer-to-texture",options:e})}copyTextureToBuffer(e){this.commandBuffer.commands.push({name:"copy-texture-to-buffer",options:e})}copyTextureToTexture(e){this.commandBuffer.commands.push({name:"copy-texture-to-texture",options:e})}pushDebugGroup(e){}popDebugGroup(){}insertDebugMarker(e){}resolveQuerySet(e,t,i){}}function yr(r){const{target:e,source:t,start:i=0,count:n=1}=r,s=t.length,a=n*s;let o=0;for(let c=i;o<s;o++)e[c++]=t[o];for(;o<a;)o<a-o?(e.copyWithin(i+o,i,i+o),o*=2):(e.copyWithin(i+o,i,i+a-o),o=a);return r.target}class ae extends J{get[Symbol.toStringTag](){return"VertexArray"}device;handle;buffer=null;bufferValue=null;static isConstantAttributeZeroSupported(e){return tt()==="Chrome"}constructor(e,t){super(e,t),this.device=e,this.handle=this.device.gl.createVertexArray()}destroy(){super.destroy(),this.buffer&&this.buffer?.destroy(),this.handle&&(this.device.gl.deleteVertexArray(this.handle),this.handle=void 0)}setIndexBuffer(e){const t=e;if(t&&t.glTarget!==34963)throw new Error("Use .setBuffer()");this.device.gl.bindVertexArray(this.handle),this.device.gl.bindBuffer(34963,t?t.handle:null),this.indexBuffer=t,this.device.gl.bindVertexArray(null)}setBuffer(e,t){const i=t;if(i.glTarget===34963)throw new Error("Use .setIndexBuffer()");const{size:n,type:s,stride:a,offset:o,normalized:c,integer:l,divisor:u}=this._getAccessor(e);this.device.gl.bindVertexArray(this.handle),this.device.gl.bindBuffer(34962,i.handle),l?this.device.gl.vertexAttribIPointer(e,n,s,a,o):this.device.gl.vertexAttribPointer(e,n,s,c,a,o),this.device.gl.bindBuffer(34962,null),this.device.gl.enableVertexAttribArray(e),this.device.gl.vertexAttribDivisor(e,u||0),this.attributes[e]=i,this.device.gl.bindVertexArray(null)}setConstantWebGL(e,t){this._enable(e,!1),this.attributes[e]=t}bindBeforeRender(){this.device.gl.bindVertexArray(this.handle),this._applyConstantAttributes()}unbindAfterRender(){this.device.gl.bindVertexArray(null)}_applyConstantAttributes(){for(let e=0;e<this.maxVertexAttributes;++e){const t=this.attributes[e];ArrayBuffer.isView(t)&&this.device.setConstantAttributeWebGL(e,t)}}_getAccessor(e){const t=this.attributeInfos[e];if(!t)throw new Error(`Unknown attribute location ${e}`);const i=Fe(t.bufferDataType);return{size:t.bufferComponents,type:i,stride:t.byteStride,offset:t.byteOffset,normalized:t.normalized,integer:t.integer,divisor:t.stepMode==="instance"?1:0}}_enable(e,t=!0){const n=ae.isConstantAttributeZeroSupported(this.device)||e!==0;(t||n)&&(e=Number(e),this.device.gl.bindVertexArray(this.handle),t?this.device.gl.enableVertexAttribArray(e):this.device.gl.disableVertexAttribArray(e),this.device.gl.bindVertexArray(null))}getConstantBuffer(e,t){const i=wr(t),n=i.byteLength*e,s=i.length*e;if(this.buffer&&n!==this.buffer.byteLength)throw new Error(`Buffer size is immutable, byte length ${n} !== ${this.buffer.byteLength}.`);let a=!this.buffer;if(this.buffer=this.buffer||this.device.createBuffer({byteLength:n}),a||=!vr(i,this.bufferValue),a){const o=Ze(t.constructor,s);yr({target:o,source:i,start:0,count:s}),this.buffer.write(o),this.bufferValue=t}return this.buffer}}function wr(r){return Array.isArray(r)?new Float32Array(r):r}function vr(r,e){if(!r||!e||r.length!==e.length||r.constructor!==e.constructor)return!1;for(let t=0;t<r.length;++t)if(r[t]!==e[t])return!1;return!0}class Sr extends ee{device;gl;handle;layout;buffers={};unusedBuffers={};bindOnUse=!0;_bound=!1;constructor(e,t){super(e,t),this.device=e,this.gl=e.gl,this.handle=this.props.handle||this.gl.createTransformFeedback(),this.layout=this.props.layout,t.buffers&&this.setBuffers(t.buffers),Object.seal(this)}destroy(){this.gl.deleteTransformFeedback(this.handle),super.destroy()}begin(e="point-list"){this.gl.bindTransformFeedback(36386,this.handle),this.bindOnUse&&this._bindBuffers(),this.gl.beginTransformFeedback(lr(e))}end(){this.gl.endTransformFeedback(),this.bindOnUse&&this._unbindBuffers(),this.gl.bindTransformFeedback(36386,null)}setBuffers(e){this.buffers={},this.unusedBuffers={},this.bind(()=>{for(const t in e)this.setBuffer(t,e[t])})}setBuffer(e,t){const i=this._getVaryingIndex(e),{buffer:n,byteLength:s,byteOffset:a}=this._getBufferRange(t);if(i<0){this.unusedBuffers[e]=n,g.warn(`${this.id} unusedBuffers varying buffer ${e}`)();return}this.buffers[i]={buffer:n,byteLength:s,byteOffset:a},this.bindOnUse||this._bindBuffer(i,n,a,s)}getBuffer(e){if(Pe(e))return this.buffers[e]||null;const t=this._getVaryingIndex(e);return t>=0?this.buffers[t]:null}bind(e=this.handle){if(typeof e!="function")return this.gl.bindTransformFeedback(36386,e),this;let t;return this._bound?t=e():(this.gl.bindTransformFeedback(36386,this.handle),this._bound=!0,t=e(),this._bound=!1,this.gl.bindTransformFeedback(36386,null)),t}unbind(){this.bind(null)}_getBufferRange(e){if(e instanceof $)return{buffer:e,byteOffset:0,byteLength:e.byteLength};const{buffer:t,byteOffset:i=0,byteLength:n=e.buffer.byteLength}=e;return{buffer:t,byteOffset:i,byteLength:n}}_getVaryingIndex(e){if(Pe(e))return Number(e);for(const t of this.layout.varyings||[])if(e===t.name)return t.location;return-1}_bindBuffers(){for(const e in this.buffers){const{buffer:t,byteLength:i,byteOffset:n}=this._getBufferRange(this.buffers[e]);this._bindBuffer(Number(e),t,n,i)}}_unbindBuffers(){for(const e in this.buffers)this.gl.bindBufferBase(35982,Number(e),null)}_bindBuffer(e,t,i=0,n){const s=t&&t.handle;!s||n===void 0?this.gl.bindBufferBase(35982,e,s):this.gl.bindBufferRange(35982,e,s,i,n)}}function Pe(r){return typeof r=="number"?Number.isInteger(r):/^\d+$/.test(r)}class Tr extends te{device;handle;target=null;_queryPending=!1;_pollingPromise=null;get[Symbol.toStringTag](){return"Query"}constructor(e,t){if(super(e,t),this.device=e,t.count>1)throw new Error("WebGL QuerySet can only have one value");const i=this.device.gl.createQuery();if(!i)throw new Error("WebGL query not supported");this.handle=i,Object.seal(this)}destroy(){this.device.gl.deleteQuery(this.handle)}beginTimestampQuery(){return this._begin(35007)}endTimestampQuery(){this._end()}beginOcclusionQuery(e){return this._begin(e?.conservative?36202:35887)}endOcclusionQuery(){this._end()}beginTransformFeedbackQuery(){return this._begin(35976)}endTransformFeedbackQuery(){this._end()}async resolveQuery(){return[await this.pollQuery()]}_begin(e){this._queryPending||(this.target=e,this.device.gl.beginQuery(this.target,this.handle))}_end(){this._queryPending||this.target&&(this.device.gl.endQuery(this.target),this.target=null,this._queryPending=!0)}isResultAvailable(){if(!this._queryPending)return!1;const e=this.device.gl.getQueryParameter(this.handle,34919);return e&&(this._queryPending=!1),e}isTimerDisjoint(){return this.device.gl.getParameter(36795)}getResult(){return this.device.gl.getQueryParameter(this.handle,34918)}getTimerMilliseconds(){return this.getResult()/1e6}pollQuery(e=Number.POSITIVE_INFINITY){if(this._pollingPromise)return this._pollingPromise;let t=0;return this._pollingPromise=new Promise((i,n)=>{const s=()=>{this.isResultAvailable()?(i(this.getResult()),this._pollingPromise=null):t++>e?(n("Timed out"),this._pollingPromise=null):requestAnimationFrame(s)};requestAnimationFrame(s)}),this._pollingPromise}}function Me(r){switch(r){case 6406:case 33326:case 6403:case 36244:return 1;case 33339:case 33340:case 33328:case 33320:case 33319:return 2;case 6407:case 36248:case 34837:return 3;case 6408:case 36249:case 34836:return 4;default:return 0}}function _r(r){switch(r){case 5121:return 1;case 33635:case 32819:case 32820:return 2;case 5126:return 4;default:return 0}}function Pr(r){return Er[r]}const Er={5124:"sint32",5125:"uint32",5122:"sint16",5123:"uint16",5120:"sint8",5121:"uint8",5126:"float32",5131:"float16",33635:"uint16",32819:"uint16",32820:"uint16",33640:"uint32",35899:"uint32",35902:"uint32",34042:"uint32",36269:"uint32"};function Ar(r,e){const{sourceX:t=0,sourceY:i=0,sourceAttachment:n=0}=e||{};let{target:s=null,sourceWidth:a,sourceHeight:o,sourceDepth:c,sourceFormat:l,sourceType:u}=e||{};const{framebuffer:f,deleteFramebuffer:h}=We(r),{gl:d,handle:b}=f;a||=f.width,o||=f.height;const p=f.colorAttachments[n]?.texture;if(!p)throw new Error(`Invalid framebuffer attachment ${n}`);c=p?.depth||1,l||=p?.glFormat||6408,u||=p?.glType||5121,s=Fr(s,u,l,a,o);const S=Ne(s);u=u||Yt(S);const y=d.bindFramebuffer(36160,b);return d.readBuffer(36064+n),d.readPixels(t,i,a,o,l,u,s),d.readBuffer(36064),d.bindFramebuffer(36160,y||null),h&&f.destroy(),s}function Lr(r,e){const{target:t,sourceX:i=0,sourceY:n=0,sourceFormat:s=6408,targetByteOffset:a=0}=e||{};let{sourceWidth:o,sourceHeight:c,sourceType:l}=e||{};const{framebuffer:u,deleteFramebuffer:f}=We(r);o=o||u.width,c=c||u.height;const h=u;l=l||5121;let d=t;if(!d){const p=Me(s),S=_r(l),y=a+o*c*p*S;d=h.device.createBuffer({byteLength:y})}const b=r.device.createCommandEncoder();return b.copyTextureToBuffer({sourceTexture:r,width:o,height:c,origin:[i,n],destinationBuffer:d,byteOffset:a}),b.destroy(),f&&u.destroy(),d}function We(r){return r instanceof N?{framebuffer:r,deleteFramebuffer:!1}:{framebuffer:Br(r),deleteFramebuffer:!0}}function Br(r,e){const{device:t,width:i,height:n,id:s}=r;return t.createFramebuffer({...e,id:`framebuffer-for-${s}`,width:i,height:n,colorAttachments:[r]})}function Fr(r,e,t,i,n,s){if(r)return r;e||=5121;const a=Pr(e),o=Xe(a),c=Me(t);return new o(i*n*c)}class Or extends ce{type="webgl";handle;features;limits;info;canvasContext;preferredColorFormat="rgba8unorm";preferredDepthFormat="depth24plus";commandEncoder;lost;_resolveContextLost;gl;_constants;_extensions={};_polyfilled=!1;spectorJS;get[Symbol.toStringTag](){return"WebGLDevice"}toString(){return`${this[Symbol.toStringTag]}(${this.id})`}isVertexFormatSupported(e){return e!=="unorm8x4-bgra"}constructor(e){super({...e,id:e.id||Wt("webgl-device")});const t=ce._getCanvasContextProps(e);if(!t)throw new Error("WebGLDevice requires props.createCanvasContext to be set");let i=t.canvas?.gl?.device;if(i)throw new Error(`WebGL context already attached to device ${i.id}`);this.canvasContext=new Mt(this,t),this.lost=new Promise(u=>{this._resolveContextLost=u});const n={...e.webgl};t.alphaMode==="premultiplied"&&(n.premultipliedAlpha=!0),e.powerPreference!==void 0&&(n.powerPreference=e.powerPreference);const a=this.props._handle||bt(this.canvasContext.canvas,{onContextLost:u=>this._resolveContextLost?.({reason:"destroyed",message:"Entered sleep mode, or too many apps or browser tabs are using the GPU."}),onContextRestored:u=>console.log("WebGL context restored")},n);if(!a)throw new Error("WebGL context creation failed");if(i=a.device,i){if(e._reuseDevices)return g.log(1,`Not creating a new Device, instead returning a reference to Device ${i.id} already attached to WebGL context`,i)(),i._reused=!0,i;throw new Error(`WebGL context already attached to device ${i.id}`)}this.handle=a,this.gl=a,this.spectorJS=Je({...this.props,gl:this.handle}),this.gl.device=this,this.gl._version=2,this.info=mt(this.gl,this._extensions),this.limits=new kt(this.gl),this.features=new Ct(this.gl,this._extensions,this.props._disabledFeatures),this.props._initializeFeatures&&this.features.initializeFeatures(),new B(this.gl,{log:(...u)=>g.log(1,...u)()}).trackState(this.gl,{copyState:!1});const c=e.debugWebGL||e.debug,l=e.debugWebGL;c&&(this.gl=et(this.gl,{debugWebGL:c,traceWebGL:l}),g.warn("WebGL debug mode activated. Performance reduced.")(),e.debugWebGL&&(g.level=Math.max(g.level,1))),this.commandEncoder=new _e(this,{id:`${this}-command-encoder`})}destroy(){!this.props._reuseDevices&&!this._reused&&delete this.gl.device}get isLost(){return this.gl.isContextLost()}getTextureByteAlignment(){return 4}createCanvasContext(e){throw new Error("WebGL only supports a single canvas")}createBuffer(e){const t=this._normalizeBufferProps(e);return new $(this,t)}createTexture(e){return new z(this,e)}createExternalTexture(e){throw new Error("createExternalTexture() not implemented")}createSampler(e){return new Qt(this,e)}createShader(e){return new $t(this,e)}createFramebuffer(e){return new O(this,e)}createVertexArray(e){return new ae(this,e)}createTransformFeedback(e){return new Sr(this,e)}createQuerySet(e){return new Tr(this,e)}createRenderPipeline(e){return new ur(this,e)}createComputePipeline(e){throw new Error("ComputePipeline not supported in WebGL")}createCommandEncoder(e={}){return new _e(this,e)}submit(e){e||(e=this.commandEncoder.finish(),this.commandEncoder.destroy(),this.commandEncoder=this.createCommandEncoder({id:`${this.id}-default-encoder`})),e._executeCommands()}readPixelsToArrayWebGL(e,t){return Ar(e,t)}readPixelsToBufferWebGL(e,t){return Lr(e,t)}setParametersWebGL(e){M(this.gl,e)}getParametersWebGL(e){return Le(this.gl,e)}withParametersWebGL(e,t){return V(this.gl,e,t)}resetWebGL(){g.warn("WebGLDevice.resetWebGL is deprecated, use only for debugging")(),ut(this.gl)}_getDeviceSpecificTextureFormatCapabilities(e){return At(this.gl,e,this._extensions)}loseDevice(){let e=!1;const i=this.getExtension("WEBGL_lose_context").WEBGL_lose_context;return i&&(e=!0,i.loseContext()),this._resolveContextLost?.({reason:"destroyed",message:"Application triggered context loss"}),e}pushState(){B.get(this.gl).push()}popState(){B.get(this.gl).pop()}getGLKey(e,t){const i=Number(e);for(const n in this.gl)if(this.gl[n]===i)return`GL.${n}`;return t?.emptyIfUnknown?"":String(e)}getGLKeys(e){const t={emptyIfUnknown:!0};return Object.entries(e).reduce((i,[n,s])=>(i[`${n}:${this.getGLKey(n,t)}`]=`${s}:${this.getGLKey(s,t)}`,i),{})}setConstantAttributeWebGL(e,t){const i=this.limits.maxVertexAttributes;this._constants=this._constants||new Array(i).fill(null);const n=this._constants[e];switch(n&&Gr(n,t)&&g.info(1,`setConstantAttributeWebGL(${e}) could have been skipped, value unchanged`)(),this._constants[e]=t,t.constructor){case Float32Array:Cr(this,e,t);break;case Int32Array:kr(this,e,t);break;case Uint32Array:Dr(this,e,t);break;default:throw new Error("constant")}}getExtension(e){return G(this.gl,e,this._extensions),this._extensions}_setWebGLDebugMetadata(e,t,i){e.luma=t;const n={props:i.spector,id:i.spector.id};e.__SPECTOR_Metadata=n}}function Cr(r,e,t){switch(t.length){case 1:r.gl.vertexAttrib1fv(e,t);break;case 2:r.gl.vertexAttrib2fv(e,t);break;case 3:r.gl.vertexAttrib3fv(e,t);break;case 4:r.gl.vertexAttrib4fv(e,t);break}}function kr(r,e,t){r.gl.vertexAttribI4iv(e,t)}function Dr(r,e,t){r.gl.vertexAttribI4uiv(e,t)}function Gr(r,e){if(!r||!e||r.length!==e.length||r.constructor!==e.constructor)return!1;for(let t=0;t<r.length;++t)if(r[t]!==e[t])return!1;return!0}export{Or as WebGLDevice};
3
+ //# sourceMappingURL=webgl-device-BYRB-GQX.js.map