@ray-js/robot-map-sdk 0.0.9 → 0.0.10

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 (134) hide show
  1. package/dist/index.d.ts +355 -3818
  2. package/dist-docs/404.html +3 -3
  3. package/dist-docs/assets/{app.BJnAJzet.js → app.Dqj628zE.js} +1 -1
  4. package/dist-docs/assets/chunks/@localSearchIndexroot.5wY6DA9h.js +1 -0
  5. package/dist-docs/assets/chunks/BitmapFont.BXsyt1Ko.js +4 -0
  6. package/dist-docs/assets/chunks/BufferResource.8pzc1eMm.js +155 -0
  7. package/dist-docs/assets/chunks/CanvasRenderer.DpOhlsYI.js +1 -0
  8. package/dist-docs/assets/chunks/RenderTargetSystem.CWKFKvEe.js +172 -0
  9. package/dist-docs/assets/chunks/{VPLocalSearchBox.D9iYIKMO.js → VPLocalSearchBox.D1fbUxUi.js} +2 -2
  10. package/dist-docs/assets/chunks/WebGLRenderer.BlPSqrND.js +156 -0
  11. package/dist-docs/assets/chunks/WebGPURenderer.szL5hbKh.js +41 -0
  12. package/dist-docs/assets/chunks/browserAll.BxwMP9Gg.js +14 -0
  13. package/dist-docs/assets/chunks/framework.CBLqO2Q1.js +18 -0
  14. package/dist-docs/assets/chunks/index.nS-neZH_.js +744 -0
  15. package/dist-docs/assets/chunks/json-editor-vue.CBQvp8j1.js +3882 -0
  16. package/dist-docs/assets/chunks/mapValues.D2X8cRgC.js +1 -0
  17. package/dist-docs/assets/chunks/theme.B9FcKggM.js +4 -0
  18. package/dist-docs/assets/chunks/vanilla-picker.B6E6ObS_.js +8 -0
  19. package/dist-docs/assets/chunks/webworkerAll.BXgPGAoF.js +56 -0
  20. package/dist-docs/assets/doubleBed.CzextF6m.png +0 -0
  21. package/dist-docs/assets/{guide_advanced-usage.md.BPrKHNKt.js → guide_advanced-usage.md.COVLyRkA.js} +96 -3
  22. package/dist-docs/assets/guide_advanced-usage.md.COVLyRkA.lean.js +1 -0
  23. package/dist-docs/assets/{guide_concepts.md.DBFk-g-l.js → guide_concepts.md.CJ87tk-r.js} +1 -1
  24. package/dist-docs/assets/{guide_concepts.md.DBFk-g-l.lean.js → guide_concepts.md.CJ87tk-r.lean.js} +1 -1
  25. package/dist-docs/assets/{guide_getting-started.md.Zvm4buzY.js → guide_getting-started.md.B8rkVqGP.js} +1 -1
  26. package/dist-docs/assets/{guide_getting-started.md.Zvm4buzY.lean.js → guide_getting-started.md.B8rkVqGP.lean.js} +1 -1
  27. package/dist-docs/assets/{guide_mcp.md.1UIpY4E0.js → guide_mcp.md.CabCiX8Z.js} +1 -1
  28. package/dist-docs/assets/{guide_mcp.md.1UIpY4E0.lean.js → guide_mcp.md.CabCiX8Z.lean.js} +1 -1
  29. package/dist-docs/assets/{index.md.Sm6vD2Gl.js → index.md.wTsFvv0N.js} +1 -1
  30. package/dist-docs/assets/{index.md.Sm6vD2Gl.lean.js → index.md.wTsFvv0N.lean.js} +1 -1
  31. package/dist-docs/assets/{plans_2026-03-04-detected-objects-visibility-design.md.530AI9zE.js → plans_2026-03-04-detected-objects-visibility-design.md.Dqboot5W.js} +1 -1
  32. package/dist-docs/assets/{plans_2026-03-04-detected-objects-visibility-design.md.530AI9zE.lean.js → plans_2026-03-04-detected-objects-visibility-design.md.Dqboot5W.lean.js} +1 -1
  33. package/dist-docs/assets/{plans_2026-03-04-show-detected-objects-implementation-plan.md.foeG7qiK.js → plans_2026-03-04-show-detected-objects-implementation-plan.md.CDWwQtWj.js} +1 -1
  34. package/dist-docs/assets/{plans_2026-03-04-show-detected-objects-implementation-plan.md.foeG7qiK.lean.js → plans_2026-03-04-show-detected-objects-implementation-plan.md.CDWwQtWj.lean.js} +1 -1
  35. package/dist-docs/assets/plans_2026-03-10-simulator-debug-design.md.BZibn7uw.js +1 -0
  36. package/dist-docs/assets/plans_2026-03-10-simulator-debug-design.md.BZibn7uw.lean.js +1 -0
  37. package/dist-docs/assets/plans_2026-03-10-simulator-events-console-design.md.BVmEzCbR.js +8 -0
  38. package/dist-docs/assets/plans_2026-03-10-simulator-events-console-design.md.BVmEzCbR.lean.js +1 -0
  39. package/dist-docs/assets/plans_2026-03-10-simulator-events-console-implementation-plan.md.S2f1zs9-.js +1 -0
  40. package/dist-docs/assets/plans_2026-03-10-simulator-events-console-implementation-plan.md.S2f1zs9-.lean.js +1 -0
  41. package/dist-docs/assets/plans_2026-03-10-simulator-runtime-controls-design.md.mqeNaYgg.js +1 -0
  42. package/dist-docs/assets/plans_2026-03-10-simulator-runtime-controls-design.md.mqeNaYgg.lean.js +1 -0
  43. package/dist-docs/assets/plans_2026-03-10-simulator-runtime-controls-implementation-plan.md.BXG1UWFt.js +1 -0
  44. package/dist-docs/assets/plans_2026-03-10-simulator-runtime-controls-implementation-plan.md.BXG1UWFt.lean.js +1 -0
  45. package/dist-docs/assets/{records_bugs_2026-02-28-fix-pixi-bindgroup-webgpu-snapshot-whitescreen-bugfix.md.BT3816jW.js → records_bugs_2026-02-28-fix-pixi-bindgroup-webgpu-snapshot-whitescreen-bugfix.md.BbQpA41Y.js} +1 -1
  46. package/dist-docs/assets/{records_bugs_2026-02-28-fix-pixi-bindgroup-webgpu-snapshot-whitescreen-bugfix.md.BT3816jW.lean.js → records_bugs_2026-02-28-fix-pixi-bindgroup-webgpu-snapshot-whitescreen-bugfix.md.BbQpA41Y.lean.js} +1 -1
  47. package/dist-docs/assets/records_bugs_2026-03-10-events-drawer-toolbar-scroll-bugfix.md.DbHxPv4D.js +1 -0
  48. package/dist-docs/assets/records_bugs_2026-03-10-events-drawer-toolbar-scroll-bugfix.md.DbHxPv4D.lean.js +1 -0
  49. package/dist-docs/assets/records_bugs_2026-03-10-simulator-initial-render-layout-bugfix.md.w7--2hvH.js +1 -0
  50. package/dist-docs/assets/records_bugs_2026-03-10-simulator-initial-render-layout-bugfix.md.w7--2hvH.lean.js +1 -0
  51. package/dist-docs/assets/records_bugs_2026-03-10-simulator-wheel-scroll-leak-bugfix.md.B6gIem2P.js +1 -0
  52. package/dist-docs/assets/records_bugs_2026-03-10-simulator-wheel-scroll-leak-bugfix.md.B6gIem2P.lean.js +1 -0
  53. package/dist-docs/assets/{records_plans_2026-03-02-furniture-feature-plan.md.DkXKivuL.js → records_plans_2026-03-02-furniture-feature-plan.md.CqSsyNDo.js} +1 -1
  54. package/dist-docs/assets/{records_plans_2026-03-02-furniture-feature-plan.md.DkXKivuL.lean.js → records_plans_2026-03-02-furniture-feature-plan.md.CqSsyNDo.lean.js} +1 -1
  55. package/dist-docs/assets/records_plans_2026-03-10-simulator-events-console-plan.md.CfHLEHcc.js +1 -0
  56. package/dist-docs/assets/records_plans_2026-03-10-simulator-events-console-plan.md.CfHLEHcc.lean.js +1 -0
  57. package/dist-docs/assets/records_plans_2026-03-10-simulator-last-successful-combo-cache-plan.md.Z2RoK239.js +1 -0
  58. package/dist-docs/assets/records_plans_2026-03-10-simulator-last-successful-combo-cache-plan.md.Z2RoK239.lean.js +1 -0
  59. package/dist-docs/assets/records_plans_2026-03-10-simulator-map-parsed-view-plan.md.S9jPz75o.js +1 -0
  60. package/dist-docs/assets/records_plans_2026-03-10-simulator-map-parsed-view-plan.md.S9jPz75o.lean.js +1 -0
  61. package/dist-docs/assets/records_plans_2026-03-10-simulator-map-playground-refactor-plan.md.BuILlmcV.js +1 -0
  62. package/dist-docs/assets/records_plans_2026-03-10-simulator-map-playground-refactor-plan.md.BuILlmcV.lean.js +1 -0
  63. package/dist-docs/assets/records_plans_2026-03-10-simulator-playground-plan.md.CQAR-T7p.js +1 -0
  64. package/dist-docs/assets/records_plans_2026-03-10-simulator-playground-plan.md.CQAR-T7p.lean.js +1 -0
  65. package/dist-docs/assets/records_plans_2026-03-10-simulator-runtime-controls-plan.md.DSVD-qCa.js +1 -0
  66. package/dist-docs/assets/records_plans_2026-03-10-simulator-runtime-controls-plan.md.DSVD-qCa.lean.js +1 -0
  67. package/dist-docs/assets/records_plans_2026-03-11-simulator-src-migration-implementation.md.FnB5Cx6R.js +1 -0
  68. package/dist-docs/assets/records_plans_2026-03-11-simulator-src-migration-implementation.md.FnB5Cx6R.lean.js +1 -0
  69. package/dist-docs/assets/records_plans_2026-03-11-simulator-src-migration-plan.md.BBfaeRrq.js +1 -0
  70. package/dist-docs/assets/records_plans_2026-03-11-simulator-src-migration-plan.md.BBfaeRrq.lean.js +1 -0
  71. package/dist-docs/assets/{reference_callbacks.md.CwvDSJWk.js → reference_callbacks.md.BIwuGR3s.js} +16 -2
  72. package/dist-docs/assets/reference_callbacks.md.BIwuGR3s.lean.js +1 -0
  73. package/dist-docs/assets/{reference_config.md.CK4ueBig.js → reference_config.md.DHynhVxG.js} +1 -1
  74. package/dist-docs/assets/{reference_config.md.CK4ueBig.lean.js → reference_config.md.DHynhVxG.lean.js} +1 -1
  75. package/dist-docs/assets/{reference_data.md.DciSLVC8.js → reference_data.md.B_XpUFrn.js} +38 -2
  76. package/dist-docs/assets/reference_data.md.B_XpUFrn.lean.js +1 -0
  77. package/dist-docs/assets/{reference_methods.md.CL2sjTJ7.js → reference_methods.md.eH-UCMbE.js} +23 -3
  78. package/dist-docs/assets/reference_methods.md.eH-UCMbE.lean.js +1 -0
  79. package/dist-docs/assets/{reference_runtime.md.aDpGKfHs.js → reference_runtime.md.BEy8BhSZ.js} +2 -2
  80. package/dist-docs/assets/reference_runtime.md.BEy8BhSZ.lean.js +1 -0
  81. package/dist-docs/assets/{reference_types.md.D2IglsHQ.js → reference_types.md.hikiO8Cq.js} +20 -3
  82. package/dist-docs/assets/reference_types.md.hikiO8Cq.lean.js +1 -0
  83. package/dist-docs/assets/{reference_utils.md.CSshxnp0.js → reference_utils.md.Dy6XKVWh.js} +1 -1
  84. package/dist-docs/assets/{reference_utils.md.CSshxnp0.lean.js → reference_utils.md.Dy6XKVWh.lean.js} +1 -1
  85. package/dist-docs/assets/robot.CSiuukeH.png +0 -0
  86. package/dist-docs/assets/simulator_index.md.CF95Y_c9.js +1 -0
  87. package/dist-docs/assets/simulator_index.md.CF95Y_c9.lean.js +1 -0
  88. package/dist-docs/assets/sleep.CRKZ3XeQ.png +0 -0
  89. package/dist-docs/assets/sleep.C_YKDk6M.json +879 -0
  90. package/dist-docs/assets/{style.CN_tJoU2.css → style.DrlDtCux.css} +1 -1
  91. package/dist-docs/guide/advanced-usage.html +102 -9
  92. package/dist-docs/guide/concepts.html +7 -7
  93. package/dist-docs/guide/getting-started.html +7 -7
  94. package/dist-docs/guide/mcp.html +7 -7
  95. package/dist-docs/hashmap.json +1 -1
  96. package/dist-docs/index.html +7 -7
  97. package/dist-docs/plans/2026-03-04-detected-objects-visibility-design.html +7 -7
  98. package/dist-docs/plans/2026-03-04-show-detected-objects-implementation-plan.html +7 -7
  99. package/dist-docs/plans/2026-03-10-simulator-debug-design.html +25 -0
  100. package/dist-docs/plans/2026-03-10-simulator-events-console-design.html +32 -0
  101. package/dist-docs/plans/2026-03-10-simulator-events-console-implementation-plan.html +25 -0
  102. package/dist-docs/plans/2026-03-10-simulator-runtime-controls-design.html +25 -0
  103. package/dist-docs/plans/2026-03-10-simulator-runtime-controls-implementation-plan.html +25 -0
  104. package/dist-docs/records/bugs/2026-02-28-fix-pixi-bindgroup-webgpu-snapshot-whitescreen-bugfix.html +7 -7
  105. package/dist-docs/records/bugs/2026-03-10-events-drawer-toolbar-scroll-bugfix.html +25 -0
  106. package/dist-docs/records/bugs/2026-03-10-simulator-initial-render-layout-bugfix.html +25 -0
  107. package/dist-docs/records/bugs/2026-03-10-simulator-wheel-scroll-leak-bugfix.html +25 -0
  108. package/dist-docs/records/plans/2026-03-02-furniture-feature-plan.html +7 -7
  109. package/dist-docs/records/plans/2026-03-10-simulator-events-console-plan.html +25 -0
  110. package/dist-docs/records/plans/2026-03-10-simulator-last-successful-combo-cache-plan.html +25 -0
  111. package/dist-docs/records/plans/2026-03-10-simulator-map-parsed-view-plan.html +25 -0
  112. package/dist-docs/records/plans/2026-03-10-simulator-map-playground-refactor-plan.html +25 -0
  113. package/dist-docs/records/plans/2026-03-10-simulator-playground-plan.html +25 -0
  114. package/dist-docs/records/plans/2026-03-10-simulator-runtime-controls-plan.html +25 -0
  115. package/dist-docs/records/plans/2026-03-11-simulator-src-migration-implementation.html +25 -0
  116. package/dist-docs/records/plans/2026-03-11-simulator-src-migration-plan.html +25 -0
  117. package/dist-docs/reference/callbacks.html +22 -8
  118. package/dist-docs/reference/config.html +7 -7
  119. package/dist-docs/reference/data.html +44 -8
  120. package/dist-docs/reference/methods.html +29 -9
  121. package/dist-docs/reference/runtime.html +8 -8
  122. package/dist-docs/reference/types.html +26 -9
  123. package/dist-docs/reference/utils.html +7 -7
  124. package/dist-docs/simulator/index.html +25 -0
  125. package/package.json +8 -4
  126. package/dist-docs/assets/chunks/@localSearchIndexroot.HZmZuAtg.js +0 -1
  127. package/dist-docs/assets/chunks/framework.DRADY2L-.js +0 -18
  128. package/dist-docs/assets/chunks/theme.D78lSkQK.js +0 -2
  129. package/dist-docs/assets/guide_advanced-usage.md.BPrKHNKt.lean.js +0 -1
  130. package/dist-docs/assets/reference_callbacks.md.CwvDSJWk.lean.js +0 -1
  131. package/dist-docs/assets/reference_data.md.DciSLVC8.lean.js +0 -1
  132. package/dist-docs/assets/reference_methods.md.CL2sjTJ7.lean.js +0 -1
  133. package/dist-docs/assets/reference_runtime.md.aDpGKfHs.lean.js +0 -1
  134. package/dist-docs/assets/reference_types.md.D2IglsHQ.lean.js +0 -1
@@ -0,0 +1,156 @@
1
+ import{V as R,Y as F,p as d,_ as P,k as B,w as p,j as z,af as ye,aa as O,T as S,aA as Ce,a3 as q,aB as Ne,S as g,R as V,Q as y,a2 as C,a4 as M,M as Z,aC as Q,aD as De,aE as Ie,aF as J,aG as ee,aH as Ge,W as Ue,X as Fe,x as A}from"./index.nS-neZH_.js";import{e as Pe,G as Oe,c as Me,a as Le,U as we,B as te,b as N,d as He}from"./BufferResource.8pzc1eMm.js";import{R as Ve,S as Xe,d as ke}from"./RenderTargetSystem.CWKFKvEe.js";import"./framework.CBLqO2Q1.js";import"./mapValues.D2X8cRgC.js";import"./theme.B9FcKggM.js";function We(){const{userAgent:t}=R.get().getNavigator();return/^((?!chrome|android).)*safari/i.test(t)}class re{constructor(){this._tempState=F.for2d(),this._didUploadHash={}}init(e){e.renderer.runners.contextChange.add(this)}contextChange(){this._didUploadHash={}}start(e,r,n){const s=e.renderer,i=this._didUploadHash[n.uid];s.shader.bind(n,i),i||(this._didUploadHash[n.uid]=!0),s.shader.updateUniformGroup(s.globalUniforms.uniformGroup),s.geometry.bind(r,n.glProgram)}execute(e,r){const n=e.renderer;this._tempState.blendMode=r.blendMode,n.state.set(this._tempState);const s=r.textures.textures;for(let i=0;i<r.textures.count;i++)n.texture.bind(s[i],i);n.geometry.draw(r.topology,r.size,r.start)}}re.extension={type:[d.WebGLPipesAdaptor],name:"batch"};var v=(t=>(t[t.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",t[t.ARRAY_BUFFER=34962]="ARRAY_BUFFER",t[t.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",t))(v||{});class je{constructor(e,r){this._lastBindBaseLocation=-1,this._lastBindCallId=-1,this.buffer=e||null,this.updateID=-1,this.byteLength=-1,this.type=r}destroy(){this.buffer=null,this.updateID=-1,this.byteLength=-1,this.type=-1,this._lastBindBaseLocation=-1,this._lastBindCallId=-1}}class ne{constructor(e){this._boundBufferBases=Object.create(null),this._minBaseLocation=0,this._nextBindBaseIndex=this._minBaseLocation,this._bindCallId=0,this._renderer=e,this._managedBuffers=new P({renderer:e,type:"resource",onUnload:this.onBufferUnload.bind(this),name:"glBuffer"})}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gl=null,this._boundBufferBases={}}contextChange(){this._gl=this._renderer.gl,this.destroyAll(!0),this._maxBindings=this._renderer.limits.maxUniformBindings}getGlBuffer(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this.createGLBuffer(e)}bind(e){const{_gl:r}=this,n=this.getGlBuffer(e);r.bindBuffer(n.type,n.buffer)}bindBufferBase(e,r){const{_gl:n}=this;this._boundBufferBases[r]!==e&&(this._boundBufferBases[r]=e,e._lastBindBaseLocation=r,n.bindBufferBase(n.UNIFORM_BUFFER,r,e.buffer))}nextBindBase(e){this._bindCallId++,this._minBaseLocation=0,e&&(this._boundBufferBases[0]=null,this._minBaseLocation=1,this._nextBindBaseIndex<1&&(this._nextBindBaseIndex=1))}freeLocationForBufferBase(e){let r=this.getLastBindBaseLocation(e);if(r>=this._minBaseLocation)return e._lastBindCallId=this._bindCallId,r;let n=0,s=this._nextBindBaseIndex;for(;n<2;){s>=this._maxBindings&&(s=this._minBaseLocation,n++);const i=this._boundBufferBases[s];if(i&&i._lastBindCallId===this._bindCallId){s++;continue}break}return r=s,this._nextBindBaseIndex=s+1,n>=2?-1:(e._lastBindCallId=this._bindCallId,this._boundBufferBases[r]=null,r)}getLastBindBaseLocation(e){const r=e._lastBindBaseLocation;return this._boundBufferBases[r]===e?r:-1}bindBufferRange(e,r,n,s){const{_gl:i}=this;n||(n=0),r||(r=0),this._boundBufferBases[r]=null,i.bindBufferRange(i.UNIFORM_BUFFER,r||0,e.buffer,n*256,s||256)}updateBuffer(e){const{_gl:r}=this,n=this.getGlBuffer(e);if(e._updateID===n.updateID)return n;n.updateID=e._updateID,r.bindBuffer(n.type,n.buffer);const s=e.data,i=e.descriptor.usage&B.STATIC?r.STATIC_DRAW:r.DYNAMIC_DRAW;return s?n.byteLength>=s.byteLength?r.bufferSubData(n.type,0,s,0,e._updateSize/s.BYTES_PER_ELEMENT):(n.byteLength=s.byteLength,r.bufferData(n.type,s,i)):(n.byteLength=e.descriptor.size,r.bufferData(n.type,n.byteLength,i)),n}destroyAll(e=!1){this._managedBuffers.removeAll(e)}onBufferUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];n&&(r||this._gl.deleteBuffer(n.buffer))}createGLBuffer(e){const{_gl:r}=this;let n=v.ARRAY_BUFFER;e.descriptor.usage&B.INDEX?n=v.ELEMENT_ARRAY_BUFFER:e.descriptor.usage&B.UNIFORM&&(n=v.UNIFORM_BUFFER);const s=new je(r.createBuffer(),n);return e._gpuData[this._renderer.uid]=s,this._managedBuffers.add(e),s}resetState(){this._boundBufferBases=Object.create(null)}}ne.extension={type:[d.WebGLSystem],name:"buffer"};const L=class se{constructor(e){this.supports={uint32Indices:!0,uniformBufferObject:!0,vertexArrayObject:!0,srgbTextures:!0,nonPowOf2wrapping:!0,msaa:!0,nonPowOf2mipmaps:!0},this._renderer=e,this.extensions=Object.create(null),this.handleContextLost=this.handleContextLost.bind(this),this.handleContextRestored=this.handleContextRestored.bind(this)}get isLost(){return!this.gl||this.gl.isContextLost()}contextChange(e){this.gl=e,this._renderer.gl=e}init(e){e={...se.defaultOptions,...e};let r=this.multiView=e.multiView;if(e.context&&r&&(p("Renderer created with both a context and multiview enabled. Disabling multiView as both cannot work together."),r=!1),r?this.canvas=R.get().createCanvas(this._renderer.canvas.width,this._renderer.canvas.height):this.canvas=this._renderer.view.canvas,e.context)this.initFromContext(e.context);else{const n=this._renderer.background.alpha<1,s=e.premultipliedAlpha??!0,i=e.antialias&&!this._renderer.backBuffer.useBackBuffer;this.createContext(e.preferWebGLVersion,{alpha:n,premultipliedAlpha:s,antialias:i,stencil:!0,preserveDrawingBuffer:e.preserveDrawingBuffer,powerPreference:e.powerPreference??"default"})}}ensureCanvasSize(e){if(!this.multiView){e!==this.canvas&&p("multiView is disabled, but targetCanvas is not the main canvas");return}const{canvas:r}=this;(r.width<e.width||r.height<e.height)&&(r.width=Math.max(e.width,e.width),r.height=Math.max(e.height,e.height))}initFromContext(e){this.gl=e,this.webGLVersion=e instanceof R.get().getWebGLRenderingContext()?1:2,this.getExtensions(),this.validateContext(e),this._renderer.runners.contextChange.emit(e);const r=this._renderer.view.canvas;r.addEventListener("webglcontextlost",this.handleContextLost,!1),r.addEventListener("webglcontextrestored",this.handleContextRestored,!1)}createContext(e,r){let n;const s=this.canvas;if(e===2&&(n=s.getContext("webgl2",r)),!n&&(n=s.getContext("webgl",r),!n))throw new Error("This browser does not support WebGL. Try using the canvas renderer");this.gl=n,this.initFromContext(this.gl)}getExtensions(){const{gl:e}=this,r={anisotropicFiltering:e.getExtension("EXT_texture_filter_anisotropic"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),s3tc:e.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:e.getExtension("WEBGL_compressed_texture_s3tc_srgb"),etc:e.getExtension("WEBGL_compressed_texture_etc"),etc1:e.getExtension("WEBGL_compressed_texture_etc1"),pvrtc:e.getExtension("WEBGL_compressed_texture_pvrtc")||e.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),atc:e.getExtension("WEBGL_compressed_texture_atc"),astc:e.getExtension("WEBGL_compressed_texture_astc"),bptc:e.getExtension("EXT_texture_compression_bptc"),rgtc:e.getExtension("EXT_texture_compression_rgtc"),loseContext:e.getExtension("WEBGL_lose_context")};if(this.webGLVersion===1)this.extensions={...r,drawBuffers:e.getExtension("WEBGL_draw_buffers"),depthTexture:e.getExtension("WEBGL_depth_texture"),vertexArrayObject:e.getExtension("OES_vertex_array_object")||e.getExtension("MOZ_OES_vertex_array_object")||e.getExtension("WEBKIT_OES_vertex_array_object"),uint32ElementIndex:e.getExtension("OES_element_index_uint"),floatTexture:e.getExtension("OES_texture_float"),floatTextureLinear:e.getExtension("OES_texture_float_linear"),textureHalfFloat:e.getExtension("OES_texture_half_float"),textureHalfFloatLinear:e.getExtension("OES_texture_half_float_linear"),vertexAttribDivisorANGLE:e.getExtension("ANGLE_instanced_arrays"),srgb:e.getExtension("EXT_sRGB")};else{this.extensions={...r,colorBufferFloat:e.getExtension("EXT_color_buffer_float")};const n=e.getExtension("WEBGL_provoking_vertex");n&&n.provokingVertexWEBGL(n.FIRST_VERTEX_CONVENTION_WEBGL)}}handleContextLost(e){e.preventDefault(),this._contextLossForced&&(this._contextLossForced=!1,setTimeout(()=>{var r;this.gl.isContextLost()&&((r=this.extensions.loseContext)==null||r.restoreContext())},0))}handleContextRestored(){this.getExtensions(),this._renderer.runners.contextChange.emit(this.gl)}destroy(){var r;const e=this._renderer.view.canvas;this._renderer=null,e.removeEventListener("webglcontextlost",this.handleContextLost),e.removeEventListener("webglcontextrestored",this.handleContextRestored),this.gl.useProgram(null),(r=this.extensions.loseContext)==null||r.loseContext()}forceContextLoss(){var e;(e=this.extensions.loseContext)==null||e.loseContext(),this._contextLossForced=!0}validateContext(e){const r=e.getContextAttributes();r&&!r.stencil&&p("Provided WebGL context does not have a stencil buffer, masks may not render correctly");const n=this.supports,s=this.webGLVersion===2,i=this.extensions;n.uint32Indices=s||!!i.uint32ElementIndex,n.uniformBufferObject=s,n.vertexArrayObject=s||!!i.vertexArrayObject,n.srgbTextures=s||!!i.srgb,n.nonPowOf2wrapping=s,n.nonPowOf2mipmaps=s,n.msaa=s,n.uint32Indices||p("Provided WebGL context does not support 32 index buffer, large scenes may not render correctly")}};L.extension={type:[d.WebGLSystem],name:"context"};L.defaultOptions={context:null,premultipliedAlpha:!0,preserveDrawingBuffer:!1,powerPreference:void 0,preferWebGLVersion:2,multiView:!1};let Ke=L;var G=(t=>(t[t.RGBA=6408]="RGBA",t[t.RGB=6407]="RGB",t[t.RG=33319]="RG",t[t.RED=6403]="RED",t[t.RGBA_INTEGER=36249]="RGBA_INTEGER",t[t.RGB_INTEGER=36248]="RGB_INTEGER",t[t.RG_INTEGER=33320]="RG_INTEGER",t[t.RED_INTEGER=36244]="RED_INTEGER",t[t.ALPHA=6406]="ALPHA",t[t.LUMINANCE=6409]="LUMINANCE",t[t.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",t[t.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",t[t.DEPTH_STENCIL=34041]="DEPTH_STENCIL",t))(G||{}),w=(t=>(t[t.TEXTURE_2D=3553]="TEXTURE_2D",t[t.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",t[t.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",t[t.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",t[t.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",t[t.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",t[t.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",t[t.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",t))(w||{}),l=(t=>(t[t.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",t[t.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",t[t.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",t[t.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",t[t.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",t[t.UNSIGNED_INT=5125]="UNSIGNED_INT",t[t.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",t[t.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",t[t.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",t[t.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",t[t.BYTE=5120]="BYTE",t[t.SHORT=5122]="SHORT",t[t.INT=5124]="INT",t[t.FLOAT=5126]="FLOAT",t[t.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",t[t.HALF_FLOAT=36193]="HALF_FLOAT",t))(l||{});const X={uint8x2:l.UNSIGNED_BYTE,uint8x4:l.UNSIGNED_BYTE,sint8x2:l.BYTE,sint8x4:l.BYTE,unorm8x2:l.UNSIGNED_BYTE,unorm8x4:l.UNSIGNED_BYTE,snorm8x2:l.BYTE,snorm8x4:l.BYTE,uint16x2:l.UNSIGNED_SHORT,uint16x4:l.UNSIGNED_SHORT,sint16x2:l.SHORT,sint16x4:l.SHORT,unorm16x2:l.UNSIGNED_SHORT,unorm16x4:l.UNSIGNED_SHORT,snorm16x2:l.SHORT,snorm16x4:l.SHORT,float16x2:l.HALF_FLOAT,float16x4:l.HALF_FLOAT,float32:l.FLOAT,float32x2:l.FLOAT,float32x3:l.FLOAT,float32x4:l.FLOAT,uint32:l.UNSIGNED_INT,uint32x2:l.UNSIGNED_INT,uint32x3:l.UNSIGNED_INT,uint32x4:l.UNSIGNED_INT,sint32:l.INT,sint32x2:l.INT,sint32x3:l.INT,sint32x4:l.INT};function $e(t){return X[t]??X.float32}const Ye={"point-list":0,"line-list":1,"line-strip":3,"triangle-list":4,"triangle-strip":5};class ze{constructor(){this.vaoCache=Object.create(null)}destroy(){this.vaoCache=Object.create(null)}}class ie{constructor(e){this._renderer=e,this._activeGeometry=null,this._activeVao=null,this.hasVao=!0,this.hasInstance=!0,this._managedGeometries=new P({renderer:e,type:"resource",onUnload:this.onGeometryUnload.bind(this),name:"glGeometry"})}contextChange(){const e=this.gl=this._renderer.gl;if(!this._renderer.context.supports.vertexArrayObject)throw new Error("[PixiJS] Vertex Array Objects are not supported on this device");this.destroyAll(!0);const r=this._renderer.context.extensions.vertexArrayObject;r&&(e.createVertexArray=()=>r.createVertexArrayOES(),e.bindVertexArray=s=>r.bindVertexArrayOES(s),e.deleteVertexArray=s=>r.deleteVertexArrayOES(s));const n=this._renderer.context.extensions.vertexAttribDivisorANGLE;n&&(e.drawArraysInstanced=(s,i,a,o)=>{n.drawArraysInstancedANGLE(s,i,a,o)},e.drawElementsInstanced=(s,i,a,o,u)=>{n.drawElementsInstancedANGLE(s,i,a,o,u)},e.vertexAttribDivisor=(s,i)=>n.vertexAttribDivisorANGLE(s,i)),this._activeGeometry=null,this._activeVao=null}bind(e,r){const n=this.gl;this._activeGeometry=e;const s=this.getVao(e,r);this._activeVao!==s&&(this._activeVao=s,n.bindVertexArray(s)),this.updateBuffers()}resetState(){this.unbind()}updateBuffers(){const e=this._activeGeometry,r=this._renderer.buffer;for(let n=0;n<e.buffers.length;n++){const s=e.buffers[n];r.updateBuffer(s)}e._gcLastUsed=this._renderer.gc.now}checkCompatibility(e,r){const n=e.attributes,s=r._attributeData;for(const i in s)if(!n[i])throw new Error(`shader and geometry incompatible, geometry missing the "${i}" attribute`)}getSignature(e,r){const n=e.attributes,s=r._attributeData,i=["g",e.uid];for(const a in n)s[a]&&i.push(a,s[a].location);return i.join("-")}getVao(e,r){var n;return((n=e._gpuData[this._renderer.uid])==null?void 0:n.vaoCache[r._key])||this.initGeometryVao(e,r)}initGeometryVao(e,r,n=!0){const s=this._renderer.gl,i=this._renderer.buffer;this._renderer.shader._getProgramData(r),this.checkCompatibility(e,r);const a=this.getSignature(e,r);let o=e._gpuData[this._renderer.uid];o||(o=new ze,e._gpuData[this._renderer.uid]=o,this._managedGeometries.add(e));const u=o.vaoCache;let c=u[a];if(c)return u[r._key]=c,c;Pe(e,r._attributeData);const _=e.buffers;c=s.createVertexArray(),s.bindVertexArray(c);for(let f=0;f<_.length;f++){const h=_[f];i.bind(h)}return this.activateVao(e,r),u[r._key]=c,u[a]=c,s.bindVertexArray(null),c}onGeometryUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];if(!n)return;const s=n.vaoCache;if(!r)for(const i in s)this._activeVao!==s[i]&&this.resetState(),this.gl.deleteVertexArray(s[i])}destroyAll(e=!1){this._managedGeometries.removeAll(e)}activateVao(e,r){var o;const n=this._renderer.gl,s=this._renderer.buffer,i=e.attributes;e.indexBuffer&&s.bind(e.indexBuffer);let a=null;for(const u in i){const c=i[u],_=c.buffer,f=s.getGlBuffer(_),h=r._attributeData[u];if(h){a!==f&&(s.bind(_),a=f);const m=h.location;n.enableVertexAttribArray(m);const b=z(c.format),E=$e(c.format);if(((o=h.format)==null?void 0:o.substring(1,4))==="int"?n.vertexAttribIPointer(m,b.size,E,c.stride,c.offset):n.vertexAttribPointer(m,b.size,E,b.normalised,c.stride,c.offset),c.instance)if(this.hasInstance){const Be=c.divisor??1;n.vertexAttribDivisor(m,Be)}else throw new Error("geometry error, GPU Instancing is not supported on this device")}}}draw(e,r,n,s){const{gl:i}=this._renderer,a=this._activeGeometry,o=Ye[e||a.topology];if(s??(s=a.instanceCount),a.indexBuffer){const u=a.indexBuffer.data.BYTES_PER_ELEMENT,c=u===2?i.UNSIGNED_SHORT:i.UNSIGNED_INT;s!==1?i.drawElementsInstanced(o,r||a.indexBuffer.data.length,c,(n||0)*u,s):i.drawElements(o,r||a.indexBuffer.data.length,c,(n||0)*u)}else s!==1?i.drawArraysInstanced(o,n||0,r||a.getSize(),s):i.drawArrays(o,n||0,r||a.getSize());return this}unbind(){this.gl.bindVertexArray(null),this._activeVao=null,this._activeGeometry=null}destroy(){this._managedGeometries.destroy(),this._renderer=null,this.gl=null,this._activeVao=null,this._activeGeometry=null}}ie.extension={type:[d.WebGLSystem],name:"geometry"};const qe=new Ce({attributes:{aPosition:[-1,-1,3,-1,-1,3]}}),H=class ae{constructor(e){this.useBackBuffer=!1,this._useBackBufferThisRender=!1,this._renderer=e}init(e={}){const{useBackBuffer:r,antialias:n}={...ae.defaultOptions,...e};this.useBackBuffer=r,this._antialias=n,this._renderer.context.supports.msaa||(p("antialiasing, is not supported on when using the back buffer"),this._antialias=!1),this._state=F.for2d();const s=new ye({vertex:`
2
+ attribute vec2 aPosition;
3
+ out vec2 vUv;
4
+
5
+ void main() {
6
+ gl_Position = vec4(aPosition, 0.0, 1.0);
7
+
8
+ vUv = (aPosition + 1.0) / 2.0;
9
+
10
+ // flip dem UVs
11
+ vUv.y = 1.0 - vUv.y;
12
+ }`,fragment:`
13
+ in vec2 vUv;
14
+ out vec4 finalColor;
15
+
16
+ uniform sampler2D uTexture;
17
+
18
+ void main() {
19
+ finalColor = texture(uTexture, vUv);
20
+ }`,name:"big-triangle"});this._bigTriangleShader=new O({glProgram:s,resources:{uTexture:S.WHITE.source}})}renderStart(e){const r=this._renderer.renderTarget.getRenderTarget(e.target);if(this._useBackBufferThisRender=this.useBackBuffer&&!!r.isRoot,this._useBackBufferThisRender){const n=this._renderer.renderTarget.getRenderTarget(e.target);this._targetTexture=n.colorTexture,e.target=this._getBackBufferTexture(n.colorTexture)}}renderEnd(){this._presentBackBuffer()}_presentBackBuffer(){const e=this._renderer;e.renderTarget.finishRenderPass(),this._useBackBufferThisRender&&(e.renderTarget.bind(this._targetTexture,!1),this._bigTriangleShader.resources.uTexture=this._backBufferTexture.source,e.encoder.draw({geometry:qe,shader:this._bigTriangleShader,state:this._state}))}_getBackBufferTexture(e){return this._backBufferTexture=this._backBufferTexture||new S({source:new q({width:e.width,height:e.height,resolution:e._resolution,antialias:this._antialias})}),this._backBufferTexture.source.resize(e.width,e.height,e._resolution),this._backBufferTexture}destroy(){this._backBufferTexture&&(this._backBufferTexture.destroy(),this._backBufferTexture=null)}};H.extension={type:[d.WebGLSystem],name:"backBuffer",priority:1};H.defaultOptions={useBackBuffer:!1};let Ze=H;class oe{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.gl.colorMask(!!(e&8),!!(e&4),!!(e&2),!!(e&1)))}}oe.extension={type:[d.WebGLSystem],name:"colorMask"};class ce{constructor(e){this.commandFinished=Promise.resolve(),this._renderer=e}setGeometry(e,r){this._renderer.geometry.bind(e,r.glProgram)}finishRenderPass(){}draw(e){const r=this._renderer,{geometry:n,shader:s,state:i,skipSync:a,topology:o,size:u,start:c,instanceCount:_}=e;r.shader.bind(s,a),r.geometry.bind(n,r.shader._activeProgram),i&&r.state.set(i),r.geometry.draw(o,u,c,_??n.instanceCount)}destroy(){this._renderer=null}}ce.extension={type:[d.WebGLSystem],name:"encoder"};class ue{constructor(e){this._renderer=e}contextChange(){const e=this._renderer.gl;this.maxTextures=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.maxBatchableTextures=Ne(this.maxTextures,e);const r=this._renderer.context.webGLVersion===2;this.maxUniformBindings=r?e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS):0}destroy(){}}ue.extension={type:[d.WebGLSystem],name:"limits"};class Qe{constructor(){this.width=-1,this.height=-1,this.msaa=!1,this._attachedMipLevel=0,this._attachedLayer=0,this.msaaRenderBuffer=[]}}class _e{constructor(e){this._stencilCache={enabled:!1,stencilReference:0,stencilMode:g.NONE},this._renderTargetStencilState=Object.create(null),e.renderTarget.onRenderTargetChange.add(this)}contextChange(e){this._gl=e,this._comparisonFuncMapping={always:e.ALWAYS,never:e.NEVER,equal:e.EQUAL,"not-equal":e.NOTEQUAL,less:e.LESS,"less-equal":e.LEQUAL,greater:e.GREATER,"greater-equal":e.GEQUAL},this._stencilOpsMapping={keep:e.KEEP,zero:e.ZERO,replace:e.REPLACE,invert:e.INVERT,"increment-clamp":e.INCR,"decrement-clamp":e.DECR,"increment-wrap":e.INCR_WRAP,"decrement-wrap":e.DECR_WRAP},this.resetState()}onRenderTargetChange(e){if(this._activeRenderTarget===e)return;this._activeRenderTarget=e;let r=this._renderTargetStencilState[e.uid];r||(r=this._renderTargetStencilState[e.uid]={stencilMode:g.DISABLED,stencilReference:0}),this.setStencilMode(r.stencilMode,r.stencilReference)}resetState(){this._stencilCache.enabled=!1,this._stencilCache.stencilMode=g.NONE,this._stencilCache.stencilReference=0}setStencilMode(e,r){const n=this._renderTargetStencilState[this._activeRenderTarget.uid],s=this._gl,i=Oe[e],a=this._stencilCache;if(n.stencilMode=e,n.stencilReference=r,e===g.DISABLED){this._stencilCache.enabled&&(this._stencilCache.enabled=!1,s.disable(s.STENCIL_TEST));return}this._stencilCache.enabled||(this._stencilCache.enabled=!0,s.enable(s.STENCIL_TEST)),(e!==a.stencilMode||a.stencilReference!==r)&&(a.stencilMode=e,a.stencilReference=r,s.stencilFunc(this._comparisonFuncMapping[i.stencilBack.compare],r,255),s.stencilOp(s.KEEP,s.KEEP,this._stencilOpsMapping[i.stencilBack.passOp]))}}_e.extension={type:[d.WebGLSystem],name:"stencil"};const fe={f32:4,i32:4,"vec2<f32>":8,"vec3<f32>":12,"vec4<f32>":16,"vec2<i32>":8,"vec3<i32>":12,"vec4<i32>":16,"mat2x2<f32>":16*2,"mat3x3<f32>":16*3,"mat4x4<f32>":16*4};function Je(t){const e=t.map(i=>({data:i,offset:0,size:0})),r=16;let n=0,s=0;for(let i=0;i<e.length;i++){const a=e[i];if(n=fe[a.data.type],!n)throw new Error(`Unknown type ${a.data.type}`);a.data.size>1&&(n=Math.max(n,r)*a.data.size);const o=n===12?16:n;a.size=n;const u=s%r;u>0&&r-u<o?s+=(r-u)%16:s+=(n-u%n)%n,a.offset=s,s+=n}return s=Math.ceil(s/16)*16,{uboElements:e,size:s}}function et(t,e){const r=Math.max(fe[t.data.type]/16,1),n=t.data.value.length/t.data.size,s=(4-n%4)%4,i=t.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
21
+ v = uv.${t.data.name};
22
+ offset += ${e};
23
+
24
+ arrayOffset = offset;
25
+
26
+ t = 0;
27
+
28
+ for(var i=0; i < ${t.data.size*r}; i++)
29
+ {
30
+ for(var j = 0; j < ${n}; j++)
31
+ {
32
+ ${i}[arrayOffset++] = v[t++];
33
+ }
34
+ ${s!==0?`arrayOffset += ${s};`:""}
35
+ }
36
+ `}function tt(t){return Me(t,"uboStd40",et,Le)}class he extends we{constructor(){super({createUboElements:Je,generateUboSync:tt})}}he.extension={type:[d.WebGLSystem],name:"ubo"};class rt{constructor(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new V}init(e,r){this._renderer=e,this._renderTargetSystem=r,e.runners.contextChange.add(this)}contextChange(){this._clearColorCache=[0,0,0,0],this._viewPortCache=new V;const e=this._renderer.gl;this._drawBuffersCache=[];for(let r=1;r<=16;r++)this._drawBuffersCache[r]=Array.from({length:r},(n,s)=>e.COLOR_ATTACHMENT0+s)}copyToTexture(e,r,n,s,i){const a=this._renderTargetSystem,o=this._renderer,u=a.getGpuRenderTarget(e),c=o.gl;return this.finishRenderPass(e),c.bindFramebuffer(c.FRAMEBUFFER,u.resolveTargetFramebuffer),o.texture.bind(r,0),c.copyTexSubImage2D(c.TEXTURE_2D,0,i.x,i.y,n.x,n.y,s.width,s.height),r}startRenderPass(e,r=!0,n,s,i=0,a=0){const o=this._renderTargetSystem,u=e.colorTexture,c=o.getGpuRenderTarget(e);if(a!==0&&this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to array layers requires WebGL2.");if(i>0){if(c.msaa)throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to mip levels requires WebGL2.")}let _=s.y;e.isRoot&&(_=u.pixelHeight-s.height-s.y),e.colorTextures.forEach(m=>{this._renderer.texture.unbind(m)});const f=this._renderer.gl;f.bindFramebuffer(f.FRAMEBUFFER,c.framebuffer),!e.isRoot&&(c._attachedMipLevel!==i||c._attachedLayer!==a)&&(e.colorTextures.forEach((m,b)=>{const E=this._renderer.texture.getGlSource(m);if(E.target===f.TEXTURE_2D){if(a!==0)throw new Error("[RenderTargetSystem] layer must be 0 when rendering to 2D textures in WebGL.");f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+b,f.TEXTURE_2D,E.texture,i)}else if(E.target===f.TEXTURE_2D_ARRAY){if(this._renderer.context.webGLVersion<2)throw new Error("[RenderTargetSystem] Rendering to 2D array textures requires WebGL2.");f.framebufferTextureLayer(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+b,E.texture,i,a)}else if(E.target===f.TEXTURE_CUBE_MAP){if(a<0||a>5)throw new Error("[RenderTargetSystem] Cube map layer must be between 0 and 5.");f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0+b,f.TEXTURE_CUBE_MAP_POSITIVE_X+a,E.texture,i)}else throw new Error("[RenderTargetSystem] Unsupported texture target for render-to-layer in WebGL.")}),c._attachedMipLevel=i,c._attachedLayer=a),e.colorTextures.length>1&&this._setDrawBuffers(e,f);const h=this._viewPortCache;(h.x!==s.x||h.y!==_||h.width!==s.width||h.height!==s.height)&&(h.x=s.x,h.y=_,h.width=s.width,h.height=s.height,f.viewport(s.x,_,s.width,s.height)),!c.depthStencilRenderBuffer&&(e.stencil||e.depth)&&this._initStencil(c),this.clear(e,r,n)}finishRenderPass(e){const n=this._renderTargetSystem.getGpuRenderTarget(e);if(!n.msaa)return;const s=this._renderer.gl;s.bindFramebuffer(s.FRAMEBUFFER,n.resolveTargetFramebuffer),s.bindFramebuffer(s.READ_FRAMEBUFFER,n.framebuffer),s.blitFramebuffer(0,0,n.width,n.height,0,0,n.width,n.height,s.COLOR_BUFFER_BIT,s.NEAREST),s.bindFramebuffer(s.FRAMEBUFFER,n.framebuffer)}initGpuRenderTarget(e){const n=this._renderer.gl,s=new Qe;return s._attachedMipLevel=0,s._attachedLayer=0,e.colorTexture instanceof y?(this._renderer.context.ensureCanvasSize(e.colorTexture.resource),s.framebuffer=null,s):(this._initColor(e,s),n.bindFramebuffer(n.FRAMEBUFFER,null),s)}destroyGpuRenderTarget(e){const r=this._renderer.gl;e.framebuffer&&(r.deleteFramebuffer(e.framebuffer),e.framebuffer=null),e.resolveTargetFramebuffer&&(r.deleteFramebuffer(e.resolveTargetFramebuffer),e.resolveTargetFramebuffer=null),e.depthStencilRenderBuffer&&(r.deleteRenderbuffer(e.depthStencilRenderBuffer),e.depthStencilRenderBuffer=null),e.msaaRenderBuffer.forEach(n=>{r.deleteRenderbuffer(n)}),e.msaaRenderBuffer=null}clear(e,r,n,s,i=0,a=0){if(!r)return;if(a!==0)throw new Error("[RenderTargetSystem] Clearing array layers is not supported in WebGL renderer.");const o=this._renderTargetSystem;typeof r=="boolean"&&(r=r?C.ALL:C.NONE);const u=this._renderer.gl;if(r&C.COLOR){n??(n=o.defaultClearColor);const c=this._clearColorCache,_=n;(c[0]!==_[0]||c[1]!==_[1]||c[2]!==_[2]||c[3]!==_[3])&&(c[0]=_[0],c[1]=_[1],c[2]=_[2],c[3]=_[3],u.clearColor(_[0],_[1],_[2],_[3]))}u.clear(r)}resizeGpuRenderTarget(e){if(e.isRoot)return;const n=this._renderTargetSystem.getGpuRenderTarget(e);this._resizeColor(e,n),(e.stencil||e.depth)&&this._resizeStencil(n)}_initColor(e,r){const n=this._renderer,s=n.gl,i=s.createFramebuffer();if(r.resolveTargetFramebuffer=i,s.bindFramebuffer(s.FRAMEBUFFER,i),r.width=e.colorTexture.source.pixelWidth,r.height=e.colorTexture.source.pixelHeight,e.colorTextures.forEach((o,u)=>{const c=o.source;c.antialias&&(n.context.supports.msaa?r.msaa=!0:p("[RenderTexture] Antialiasing on textures is not supported in WebGL1")),n.texture.bindSource(c,0);const _=n.texture.getGlSource(c),f=_.texture;if(_.target===s.TEXTURE_2D)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+u,s.TEXTURE_2D,f,0);else if(_.target===s.TEXTURE_2D_ARRAY){if(n.context.webGLVersion<2)throw new Error("[RenderTargetSystem] TEXTURE_2D_ARRAY requires WebGL2.");s.framebufferTextureLayer(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+u,f,0,0)}else if(_.target===s.TEXTURE_CUBE_MAP)s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0+u,s.TEXTURE_CUBE_MAP_POSITIVE_X,f,0);else throw new Error("[RenderTargetSystem] Unsupported texture target for framebuffer attachment.")}),r.msaa){const o=s.createFramebuffer();r.framebuffer=o,s.bindFramebuffer(s.FRAMEBUFFER,o),e.colorTextures.forEach((u,c)=>{const _=s.createRenderbuffer();r.msaaRenderBuffer[c]=_})}else r.framebuffer=i;this._resizeColor(e,r)}_resizeColor(e,r){const n=e.colorTexture.source;if(r.width=n.pixelWidth,r.height=n.pixelHeight,r._attachedMipLevel=0,r._attachedLayer=0,e.colorTextures.forEach((s,i)=>{i!==0&&s.source.resize(n.width,n.height,n._resolution)}),r.msaa){const s=this._renderer,i=s.gl,a=r.framebuffer;i.bindFramebuffer(i.FRAMEBUFFER,a),e.colorTextures.forEach((o,u)=>{const c=o.source;s.texture.bindSource(c,0);const f=s.texture.getGlSource(c).internalFormat,h=r.msaaRenderBuffer[u];i.bindRenderbuffer(i.RENDERBUFFER,h),i.renderbufferStorageMultisample(i.RENDERBUFFER,4,f,c.pixelWidth,c.pixelHeight),i.framebufferRenderbuffer(i.FRAMEBUFFER,i.COLOR_ATTACHMENT0+u,i.RENDERBUFFER,h)})}}_initStencil(e){if(e.framebuffer===null)return;const r=this._renderer.gl,n=r.createRenderbuffer();e.depthStencilRenderBuffer=n,r.bindRenderbuffer(r.RENDERBUFFER,n),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_STENCIL_ATTACHMENT,r.RENDERBUFFER,n),this._resizeStencil(e)}_resizeStencil(e){const r=this._renderer.gl;r.bindRenderbuffer(r.RENDERBUFFER,e.depthStencilRenderBuffer),e.msaa?r.renderbufferStorageMultisample(r.RENDERBUFFER,4,r.DEPTH24_STENCIL8,e.width,e.height):r.renderbufferStorage(r.RENDERBUFFER,this._renderer.context.webGLVersion===2?r.DEPTH24_STENCIL8:r.DEPTH_STENCIL,e.width,e.height)}prerender(e){const r=e.colorTexture.resource;this._renderer.context.multiView&&y.test(r)&&this._renderer.context.ensureCanvasSize(r)}postrender(e){if(this._renderer.context.multiView&&y.test(e.colorTexture.resource)){const r=this._renderer.context.canvas,n=e.colorTexture;n.context2D.drawImage(r,0,n.pixelHeight-r.height)}}_setDrawBuffers(e,r){const n=e.colorTextures.length,s=this._drawBuffersCache[n];if(this._renderer.context.webGLVersion===1){const i=this._renderer.context.extensions.drawBuffers;i?i.drawBuffersWEBGL(s):p("[RenderTexture] This WebGL1 context does not support rendering to multiple targets")}else r.drawBuffers(s)}}class le extends Ve{constructor(e){super(e),this.adaptor=new rt,this.adaptor.init(e,this)}}le.extension={type:[d.WebGLSystem],name:"renderTarget"};function nt(t,e){const r=[],n=[`
37
+ var g = s.groups;
38
+ var sS = r.shader;
39
+ var p = s.glProgram;
40
+ var ugS = r.uniformGroup;
41
+ var resources;
42
+ `];let s=!1,i=0;const a=e._getProgramData(t.glProgram);for(const u in t.groups){const c=t.groups[u];r.push(`
43
+ resources = g[${u}].resources;
44
+ `);for(const _ in c.resources){const f=c.resources[_];if(f instanceof M)if(f.ubo){const h=t._uniformBindMap[u][Number(_)];r.push(`
45
+ sS.bindUniformBlock(
46
+ resources[${_}],
47
+ '${h}',
48
+ ${t.glProgram._uniformBlockData[h].index}
49
+ );
50
+ `)}else r.push(`
51
+ ugS.updateUniformGroup(resources[${_}], p, sD);
52
+ `);else if(f instanceof te){const h=t._uniformBindMap[u][Number(_)];r.push(`
53
+ sS.bindUniformBlock(
54
+ resources[${_}],
55
+ '${h}',
56
+ ${t.glProgram._uniformBlockData[h].index}
57
+ );
58
+ `)}else if(f instanceof q){const h=t._uniformBindMap[u][_],m=a.uniformData[h];m&&(s||(s=!0,n.push(`
59
+ var tS = r.texture;
60
+ `)),e._gl.uniform1i(m.location,i),r.push(`
61
+ tS.bind(resources[${_}], ${i});
62
+ `),i++)}}}const o=[...n,...r].join(`
63
+ `);return new Function("r","s","sD",o)}class st{constructor(e,r){this.program=e,this.uniformData=r,this.uniformGroups={},this.uniformDirtyGroups={},this.uniformBlockBindings={}}destroy(){this.uniformData=null,this.uniformGroups=null,this.uniformDirtyGroups=null,this.uniformBlockBindings=null,this.program=null}}function k(t,e,r){const n=t.createShader(e);return t.shaderSource(n,r),t.compileShader(n),n}function D(t){const e=new Array(t);for(let r=0;r<e.length;r++)e[r]=!1;return e}function de(t,e){switch(t){case"float":return 0;case"vec2":return new Float32Array(2*e);case"vec3":return new Float32Array(3*e);case"vec4":return new Float32Array(4*e);case"int":case"uint":case"sampler2D":case"sampler2DArray":return 0;case"ivec2":return new Int32Array(2*e);case"ivec3":return new Int32Array(3*e);case"ivec4":return new Int32Array(4*e);case"uvec2":return new Uint32Array(2*e);case"uvec3":return new Uint32Array(3*e);case"uvec4":return new Uint32Array(4*e);case"bool":return!1;case"bvec2":return D(2*e);case"bvec3":return D(3*e);case"bvec4":return D(4*e);case"mat2":return new Float32Array([1,0,0,1]);case"mat3":return new Float32Array([1,0,0,0,1,0,0,0,1]);case"mat4":return new Float32Array([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1])}return null}let T=null;const W={FLOAT:"float",FLOAT_VEC2:"vec2",FLOAT_VEC3:"vec3",FLOAT_VEC4:"vec4",INT:"int",INT_VEC2:"ivec2",INT_VEC3:"ivec3",INT_VEC4:"ivec4",UNSIGNED_INT:"uint",UNSIGNED_INT_VEC2:"uvec2",UNSIGNED_INT_VEC3:"uvec3",UNSIGNED_INT_VEC4:"uvec4",BOOL:"bool",BOOL_VEC2:"bvec2",BOOL_VEC3:"bvec3",BOOL_VEC4:"bvec4",FLOAT_MAT2:"mat2",FLOAT_MAT3:"mat3",FLOAT_MAT4:"mat4",SAMPLER_2D:"sampler2D",INT_SAMPLER_2D:"sampler2D",UNSIGNED_INT_SAMPLER_2D:"sampler2D",SAMPLER_CUBE:"samplerCube",INT_SAMPLER_CUBE:"samplerCube",UNSIGNED_INT_SAMPLER_CUBE:"samplerCube",SAMPLER_2D_ARRAY:"sampler2DArray",INT_SAMPLER_2D_ARRAY:"sampler2DArray",UNSIGNED_INT_SAMPLER_2D_ARRAY:"sampler2DArray"},it={float:"float32",vec2:"float32x2",vec3:"float32x3",vec4:"float32x4",int:"sint32",ivec2:"sint32x2",ivec3:"sint32x3",ivec4:"sint32x4",uint:"uint32",uvec2:"uint32x2",uvec3:"uint32x3",uvec4:"uint32x4",bool:"uint32",bvec2:"uint32x2",bvec3:"uint32x3",bvec4:"uint32x4"};function me(t,e){if(!T){const r=Object.keys(W);T={};for(let n=0;n<r.length;++n){const s=r[n];T[t[s]]=W[s]}}return T[e]}function at(t,e){const r=me(t,e);return it[r]||"float32"}function ot(t,e,r=!1){const n={},s=e.getProgramParameter(t,e.ACTIVE_ATTRIBUTES);for(let a=0;a<s;a++){const o=e.getActiveAttrib(t,a);if(o.name.startsWith("gl_"))continue;const u=at(e,o.type);n[o.name]={location:0,format:u,stride:z(u).stride,offset:0,instance:!1,start:0}}const i=Object.keys(n);if(r){i.sort((a,o)=>a>o?1:-1);for(let a=0;a<i.length;a++)n[i[a]].location=a,e.bindAttribLocation(t,a,i[a]);e.linkProgram(t)}else for(let a=0;a<i.length;a++)n[i[a]].location=e.getAttribLocation(t,i[a]);return n}function ct(t,e){if(!e.ACTIVE_UNIFORM_BLOCKS)return{};const r={},n=e.getProgramParameter(t,e.ACTIVE_UNIFORM_BLOCKS);for(let s=0;s<n;s++){const i=e.getActiveUniformBlockName(t,s),a=e.getUniformBlockIndex(t,i),o=e.getActiveUniformBlockParameter(t,s,e.UNIFORM_BLOCK_DATA_SIZE);r[i]={name:i,index:a,size:o}}return r}function ut(t,e){const r={},n=e.getProgramParameter(t,e.ACTIVE_UNIFORMS);for(let s=0;s<n;s++){const i=e.getActiveUniform(t,s),a=i.name.replace(/\[.*?\]$/,""),o=!!i.name.match(/\[.*?\]$/),u=me(e,i.type);r[a]={name:a,index:s,type:u,size:i.size,isArray:o,value:de(u,i.size)}}return r}function j(t,e){const r=t.getShaderSource(e).split(`
64
+ `).map((c,_)=>`${_}: ${c}`),n=t.getShaderInfoLog(e),s=n.split(`
65
+ `),i={},a=s.map(c=>parseFloat(c.replace(/^ERROR\: 0\:([\d]+)\:.*$/,"$1"))).filter(c=>c&&!i[c]?(i[c]=!0,!0):!1),o=[""];a.forEach(c=>{r[c-1]=`%c${r[c-1]}%c`,o.push("background: #FF0000; color:#FFFFFF; font-size: 10px","font-size: 10px")});const u=r.join(`
66
+ `);o[0]=u,console.error(n),console.groupCollapsed("click to view full shader code"),console.warn(...o),console.groupEnd()}function _t(t,e,r,n){t.getProgramParameter(e,t.LINK_STATUS)||(t.getShaderParameter(r,t.COMPILE_STATUS)||j(t,r),t.getShaderParameter(n,t.COMPILE_STATUS)||j(t,n),console.error("PixiJS Error: Could not initialize shader."),t.getProgramInfoLog(e)!==""&&console.warn("PixiJS Warning: gl.getProgramInfoLog()",t.getProgramInfoLog(e)))}function ft(t,e){const r=k(t,t.VERTEX_SHADER,e.vertex),n=k(t,t.FRAGMENT_SHADER,e.fragment),s=t.createProgram();t.attachShader(s,r),t.attachShader(s,n);const i=e.transformFeedbackVaryings;i&&(typeof t.transformFeedbackVaryings!="function"?p("TransformFeedback is not supported but TransformFeedbackVaryings are given."):t.transformFeedbackVaryings(s,i.names,i.bufferMode==="separate"?t.SEPARATE_ATTRIBS:t.INTERLEAVED_ATTRIBS)),t.linkProgram(s),t.getProgramParameter(s,t.LINK_STATUS)||_t(t,s,r,n),e._attributeData=ot(s,t,!/^[ \t]*#[ \t]*version[ \t]+300[ \t]+es[ \t]*$/m.test(e.vertex)),e._uniformData=ut(s,t),e._uniformBlockData=ct(s,t),t.deleteShader(r),t.deleteShader(n);const a={};for(const u in e._uniformData){const c=e._uniformData[u];a[u]={location:t.getUniformLocation(s,u),value:de(c.type,c.size)}}return new st(s,a)}const x={textureCount:0,blockIndex:0};class Ee{constructor(e){this._activeProgram=null,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._renderer=e}contextChange(e){this._gl=e,this._programDataHash=Object.create(null),this._shaderSyncFunctions=Object.create(null),this._activeProgram=null}bind(e,r){if(this._setProgram(e.glProgram),r)return;x.textureCount=0,x.blockIndex=0;let n=this._shaderSyncFunctions[e.glProgram._key];n||(n=this._shaderSyncFunctions[e.glProgram._key]=this._generateShaderSync(e,this)),this._renderer.buffer.nextBindBase(!!e.glProgram.transformFeedbackVaryings),n(this._renderer,e,x)}updateUniformGroup(e){this._renderer.uniformGroup.updateUniformGroup(e,this._activeProgram,x)}bindUniformBlock(e,r,n=0){const s=this._renderer.buffer,i=this._getProgramData(this._activeProgram),a=e._bufferResource;a||this._renderer.ubo.updateUniformGroup(e);const o=e.buffer,u=s.updateBuffer(o),c=s.freeLocationForBufferBase(u);if(a){const{offset:f,size:h}=e;f===0&&h===o.data.byteLength?s.bindBufferBase(u,c):s.bindBufferRange(u,c,f)}else s.getLastBindBaseLocation(u)!==c&&s.bindBufferBase(u,c);const _=this._activeProgram._uniformBlockData[r].index;i.uniformBlockBindings[n]!==c&&(i.uniformBlockBindings[n]=c,this._renderer.gl.uniformBlockBinding(i.program,_,c))}_setProgram(e){if(this._activeProgram===e)return;this._activeProgram=e;const r=this._getProgramData(e);this._gl.useProgram(r.program)}_getProgramData(e){return this._programDataHash[e._key]||this._createProgramData(e)}_createProgramData(e){const r=e._key;return this._programDataHash[r]=ft(this._gl,e),this._programDataHash[r]}destroy(){for(const e of Object.keys(this._programDataHash))this._programDataHash[e].destroy();this._programDataHash=null,this._shaderSyncFunctions=null,this._activeProgram=null,this._renderer=null,this._gl=null}_generateShaderSync(e,r){return nt(e,r)}resetState(){this._activeProgram=null}}Ee.extension={type:[d.WebGLSystem],name:"shader"};const ht={f32:`if (cv !== v) {
67
+ cu.value = v;
68
+ gl.uniform1f(location, v);
69
+ }`,"vec2<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
70
+ cv[0] = v[0];
71
+ cv[1] = v[1];
72
+ gl.uniform2f(location, v[0], v[1]);
73
+ }`,"vec3<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
74
+ cv[0] = v[0];
75
+ cv[1] = v[1];
76
+ cv[2] = v[2];
77
+ gl.uniform3f(location, v[0], v[1], v[2]);
78
+ }`,"vec4<f32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
79
+ cv[0] = v[0];
80
+ cv[1] = v[1];
81
+ cv[2] = v[2];
82
+ cv[3] = v[3];
83
+ gl.uniform4f(location, v[0], v[1], v[2], v[3]);
84
+ }`,i32:`if (cv !== v) {
85
+ cu.value = v;
86
+ gl.uniform1i(location, v);
87
+ }`,"vec2<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
88
+ cv[0] = v[0];
89
+ cv[1] = v[1];
90
+ gl.uniform2i(location, v[0], v[1]);
91
+ }`,"vec3<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
92
+ cv[0] = v[0];
93
+ cv[1] = v[1];
94
+ cv[2] = v[2];
95
+ gl.uniform3i(location, v[0], v[1], v[2]);
96
+ }`,"vec4<i32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
97
+ cv[0] = v[0];
98
+ cv[1] = v[1];
99
+ cv[2] = v[2];
100
+ cv[3] = v[3];
101
+ gl.uniform4i(location, v[0], v[1], v[2], v[3]);
102
+ }`,u32:`if (cv !== v) {
103
+ cu.value = v;
104
+ gl.uniform1ui(location, v);
105
+ }`,"vec2<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
106
+ cv[0] = v[0];
107
+ cv[1] = v[1];
108
+ gl.uniform2ui(location, v[0], v[1]);
109
+ }`,"vec3<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
110
+ cv[0] = v[0];
111
+ cv[1] = v[1];
112
+ cv[2] = v[2];
113
+ gl.uniform3ui(location, v[0], v[1], v[2]);
114
+ }`,"vec4<u32>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
115
+ cv[0] = v[0];
116
+ cv[1] = v[1];
117
+ cv[2] = v[2];
118
+ cv[3] = v[3];
119
+ gl.uniform4ui(location, v[0], v[1], v[2], v[3]);
120
+ }`,bool:`if (cv !== v) {
121
+ cu.value = v;
122
+ gl.uniform1i(location, v);
123
+ }`,"vec2<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1]) {
124
+ cv[0] = v[0];
125
+ cv[1] = v[1];
126
+ gl.uniform2i(location, v[0], v[1]);
127
+ }`,"vec3<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2]) {
128
+ cv[0] = v[0];
129
+ cv[1] = v[1];
130
+ cv[2] = v[2];
131
+ gl.uniform3i(location, v[0], v[1], v[2]);
132
+ }`,"vec4<bool>":`if (cv[0] !== v[0] || cv[1] !== v[1] || cv[2] !== v[2] || cv[3] !== v[3]) {
133
+ cv[0] = v[0];
134
+ cv[1] = v[1];
135
+ cv[2] = v[2];
136
+ cv[3] = v[3];
137
+ gl.uniform4i(location, v[0], v[1], v[2], v[3]);
138
+ }`,"mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);"},lt={f32:"gl.uniform1fv(location, v);","vec2<f32>":"gl.uniform2fv(location, v);","vec3<f32>":"gl.uniform3fv(location, v);","vec4<f32>":"gl.uniform4fv(location, v);","mat2x2<f32>":"gl.uniformMatrix2fv(location, false, v);","mat3x3<f32>":"gl.uniformMatrix3fv(location, false, v);","mat4x4<f32>":"gl.uniformMatrix4fv(location, false, v);",i32:"gl.uniform1iv(location, v);","vec2<i32>":"gl.uniform2iv(location, v);","vec3<i32>":"gl.uniform3iv(location, v);","vec4<i32>":"gl.uniform4iv(location, v);",u32:"gl.uniform1iv(location, v);","vec2<u32>":"gl.uniform2iv(location, v);","vec3<u32>":"gl.uniform3iv(location, v);","vec4<u32>":"gl.uniform4iv(location, v);",bool:"gl.uniform1iv(location, v);","vec2<bool>":"gl.uniform2iv(location, v);","vec3<bool>":"gl.uniform3iv(location, v);","vec4<bool>":"gl.uniform4iv(location, v);"};function dt(t,e){const r=[`
139
+ var v = null;
140
+ var cv = null;
141
+ var cu = null;
142
+ var t = 0;
143
+ var gl = renderer.gl;
144
+ var name = null;
145
+ `];for(const n in t.uniforms){if(!e[n]){t.uniforms[n]instanceof M?t.uniforms[n].ubo?r.push(`
146
+ renderer.shader.bindUniformBlock(uv.${n}, "${n}");
147
+ `):r.push(`
148
+ renderer.shader.updateUniformGroup(uv.${n});
149
+ `):t.uniforms[n]instanceof te&&r.push(`
150
+ renderer.shader.bindBufferResource(uv.${n}, "${n}");
151
+ `);continue}const s=t.uniformStructures[n];let i=!1;for(let a=0;a<N.length;a++){const o=N[a];if(s.type===o.type&&o.test(s)){r.push(`name = "${n}";`,N[a].uniform),i=!0;break}}if(!i){const o=(s.size===1?ht:lt)[s.type].replace("location",`ud["${n}"].location`);r.push(`
152
+ cu = ud["${n}"];
153
+ cv = cu.value;
154
+ v = uv["${n}"];
155
+ ${o};`)}}return new Function("ud","uv","renderer","syncData",r.join(`
156
+ `))}class be{constructor(e){this._cache={},this._uniformGroupSyncHash={},this._renderer=e,this.gl=null,this._cache={}}contextChange(e){this.gl=e}updateUniformGroup(e,r,n){const s=this._renderer.shader._getProgramData(r);(!e.isStatic||e._dirtyId!==s.uniformDirtyGroups[e.uid])&&(s.uniformDirtyGroups[e.uid]=e._dirtyId,this._getUniformSyncFunction(e,r)(s.uniformData,e.uniforms,this._renderer,n))}_getUniformSyncFunction(e,r){var n;return((n=this._uniformGroupSyncHash[e._signature])==null?void 0:n[r._key])||this._createUniformSyncFunction(e,r)}_createUniformSyncFunction(e,r){const n=this._uniformGroupSyncHash[e._signature]||(this._uniformGroupSyncHash[e._signature]={}),s=this._getSignature(e,r._uniformData,"u");return this._cache[s]||(this._cache[s]=this._generateUniformsSync(e,r._uniformData)),n[r._key]=this._cache[s],n[r._key]}_generateUniformsSync(e,r){return dt(e,r)}_getSignature(e,r,n){const s=e.uniforms,i=[`${n}-`];for(const a in s)i.push(a),r[a]&&i.push(r[a].type);return i.join("-")}destroy(){this._renderer=null,this._cache=null}}be.extension={type:[d.WebGLSystem],name:"uniformGroup"};function mt(t){const e={};if(e.normal=[t.ONE,t.ONE_MINUS_SRC_ALPHA],e.add=[t.ONE,t.ONE],e.multiply=[t.DST_COLOR,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.screen=[t.ONE,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.none=[0,0],e["normal-npm"]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_ALPHA,t.ONE,t.ONE_MINUS_SRC_ALPHA],e["add-npm"]=[t.SRC_ALPHA,t.ONE,t.ONE,t.ONE],e["screen-npm"]=[t.SRC_ALPHA,t.ONE_MINUS_SRC_COLOR,t.ONE,t.ONE_MINUS_SRC_ALPHA],e.erase=[t.ZERO,t.ONE_MINUS_SRC_ALPHA],!(t instanceof R.get().getWebGLRenderingContext()))e.min=[t.ONE,t.ONE,t.ONE,t.ONE,t.MIN,t.MIN],e.max=[t.ONE,t.ONE,t.ONE,t.ONE,t.MAX,t.MAX];else{const n=t.getExtension("EXT_blend_minmax");n&&(e.min=[t.ONE,t.ONE,t.ONE,t.ONE,n.MIN_EXT,n.MIN_EXT],e.max=[t.ONE,t.ONE,t.ONE,t.ONE,n.MAX_EXT,n.MAX_EXT])}return e}const Et=0,bt=1,pt=2,St=3,Rt=4,gt=5,pe=class U{constructor(e){this._invertFrontFace=!1,this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode="none",this._blendEq=!1,this.map=[],this.map[Et]=this.setBlend,this.map[bt]=this.setOffset,this.map[pt]=this.setCullFace,this.map[St]=this.setDepthTest,this.map[Rt]=this.setFrontFace,this.map[gt]=this.setDepthMask,this.checks=[],this.defaultState=F.for2d(),e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){this._invertFrontFace=!e.isRoot,this._cullFace?this.setFrontFace(this._frontFace):this._frontFaceDirty=!0}contextChange(e){this.gl=e,this.blendModesMap=mt(e),this.resetState()}set(e){if(e||(e=this.defaultState),this.stateId!==e.data){let r=this.stateId^e.data,n=0;for(;r;)r&1&&this.map[n].call(this,!!(e.data&1<<n)),r>>=1,n++;this.stateId=e.data}for(let r=0;r<this.checks.length;r++)this.checks[r](this,e)}forceState(e){e||(e=this.defaultState);for(let r=0;r<this.map.length;r++)this.map[r].call(this,!!(e.data&1<<r));for(let r=0;r<this.checks.length;r++)this.checks[r](this,e);this.stateId=e.data}setBlend(e){this._updateCheck(U._checkBlendMode,e),this.gl[e?"enable":"disable"](this.gl.BLEND)}setOffset(e){this._updateCheck(U._checkPolygonOffset,e),this.gl[e?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(e){this.gl[e?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(e){this.gl.depthMask(e)}setCullFace(e){this._cullFace=e,this.gl[e?"enable":"disable"](this.gl.CULL_FACE),this._cullFace&&this._frontFaceDirty&&this.setFrontFace(this._frontFace)}setFrontFace(e){this._frontFace=e,this._frontFaceDirty=!1;const r=this._invertFrontFace?!e:e;this._glFrontFace!==r&&(this._glFrontFace=r,this.gl.frontFace(this.gl[r?"CW":"CCW"]))}setBlendMode(e){if(this.blendModesMap[e]||(e="normal"),e===this.blendMode)return;this.blendMode=e;const r=this.blendModesMap[e],n=this.gl;r.length===2?n.blendFunc(r[0],r[1]):n.blendFuncSeparate(r[0],r[1],r[2],r[3]),r.length===6?(this._blendEq=!0,n.blendEquationSeparate(r[4],r[5])):this._blendEq&&(this._blendEq=!1,n.blendEquationSeparate(n.FUNC_ADD,n.FUNC_ADD))}setPolygonOffset(e,r){this.gl.polygonOffset(e,r)}resetState(){this._glFrontFace=!1,this._frontFace=!1,this._cullFace=!1,this._frontFaceDirty=!1,this._invertFrontFace=!1,this.gl.frontFace(this.gl.CCW),this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode="",this.setBlendMode("normal")}_updateCheck(e,r){const n=this.checks.indexOf(e);r&&n===-1?this.checks.push(e):!r&&n!==-1&&this.checks.splice(n,1)}static _checkBlendMode(e,r){e.setBlendMode(r.blendMode)}static _checkPolygonOffset(e,r){e.setPolygonOffset(1,r.polygonOffset)}destroy(){this.gl=null,this.checks.length=0}};pe.extension={type:[d.WebGLSystem],name:"state"};let Tt=pe;class xt{constructor(e){this.target=w.TEXTURE_2D,this._layerInitMask=0,this.texture=e,this.width=-1,this.height=-1,this.type=l.UNSIGNED_BYTE,this.internalFormat=G.RGBA,this.format=G.RGBA,this.samplerType=0}destroy(){}}const vt={id:"buffer",upload(t,e,r,n,s,i=!1){const a=s||e.target;!i&&e.width===t.width&&e.height===t.height?r.texSubImage2D(a,0,0,0,t.width,t.height,e.format,e.type,t.resource):r.texImage2D(a,0,e.internalFormat,t.width,t.height,0,e.format,e.type,t.resource),e.width=t.width,e.height=t.height}},At={"bc1-rgba-unorm":!0,"bc1-rgba-unorm-srgb":!0,"bc2-rgba-unorm":!0,"bc2-rgba-unorm-srgb":!0,"bc3-rgba-unorm":!0,"bc3-rgba-unorm-srgb":!0,"bc4-r-unorm":!0,"bc4-r-snorm":!0,"bc5-rg-unorm":!0,"bc5-rg-snorm":!0,"bc6h-rgb-ufloat":!0,"bc6h-rgb-float":!0,"bc7-rgba-unorm":!0,"bc7-rgba-unorm-srgb":!0,"etc2-rgb8unorm":!0,"etc2-rgb8unorm-srgb":!0,"etc2-rgb8a1unorm":!0,"etc2-rgb8a1unorm-srgb":!0,"etc2-rgba8unorm":!0,"etc2-rgba8unorm-srgb":!0,"eac-r11unorm":!0,"eac-r11snorm":!0,"eac-rg11unorm":!0,"eac-rg11snorm":!0,"astc-4x4-unorm":!0,"astc-4x4-unorm-srgb":!0,"astc-5x4-unorm":!0,"astc-5x4-unorm-srgb":!0,"astc-5x5-unorm":!0,"astc-5x5-unorm-srgb":!0,"astc-6x5-unorm":!0,"astc-6x5-unorm-srgb":!0,"astc-6x6-unorm":!0,"astc-6x6-unorm-srgb":!0,"astc-8x5-unorm":!0,"astc-8x5-unorm-srgb":!0,"astc-8x6-unorm":!0,"astc-8x6-unorm-srgb":!0,"astc-8x8-unorm":!0,"astc-8x8-unorm-srgb":!0,"astc-10x5-unorm":!0,"astc-10x5-unorm-srgb":!0,"astc-10x6-unorm":!0,"astc-10x6-unorm-srgb":!0,"astc-10x8-unorm":!0,"astc-10x8-unorm-srgb":!0,"astc-10x10-unorm":!0,"astc-10x10-unorm-srgb":!0,"astc-12x10-unorm":!0,"astc-12x10-unorm-srgb":!0,"astc-12x12-unorm":!0,"astc-12x12-unorm-srgb":!0},Bt={id:"compressed",upload(t,e,r,n,s,i){const a=s??e.target;r.pixelStorei(r.UNPACK_ALIGNMENT,4);let o=t.pixelWidth,u=t.pixelHeight;const c=!!At[t.format];for(let _=0;_<t.resource.length;_++){const f=t.resource[_];c?r.compressedTexImage2D(a,_,e.internalFormat,o,u,0,f):r.texImage2D(a,_,e.internalFormat,o,u,0,e.format,e.type,f),o=Math.max(o>>1,1),u=Math.max(u>>1,1)}}},K=["right","left","top","bottom","front","back"];function yt(t){return{id:"cube",upload(e,r,n,s){const i=e.faces;for(let a=0;a<K.length;a++){const o=K[a],u=i[o];(t[u.uploadMethodId]||t.image).upload(u,r,n,s,w.TEXTURE_CUBE_MAP_POSITIVE_X+a,(r._layerInitMask&1<<a)===0),r._layerInitMask|=1<<a}r.width=e.pixelWidth,r.height=e.pixelHeight}}}const Se={id:"image",upload(t,e,r,n,s,i=!1){const a=s||e.target,o=t.pixelWidth,u=t.pixelHeight,c=t.resourceWidth,_=t.resourceHeight,f=n===2,h=i||e.width!==o||e.height!==u,m=c>=o&&_>=u,b=t.resource;(f?Ct:Nt)(r,a,e,o,u,c,_,b,h,m),e.width=o,e.height=u}};function Ct(t,e,r,n,s,i,a,o,u,c){if(!c){u&&t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,null),t.texSubImage2D(e,0,0,0,i,a,r.format,r.type,o);return}if(!u){t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,o)}function Nt(t,e,r,n,s,i,a,o,u,c){if(!c){u&&t.texImage2D(e,0,r.internalFormat,n,s,0,r.format,r.type,null),t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}if(!u){t.texSubImage2D(e,0,0,0,r.format,r.type,o);return}t.texImage2D(e,0,r.internalFormat,r.format,r.type,o)}const Dt=We(),It={id:"video",upload(t,e,r,n,s,i=Dt){if(!t.isValid){const a=s??e.target;r.texImage2D(a,0,e.internalFormat,1,1,0,e.format,e.type,null);return}Se.upload(t,e,r,n,s,i)}},$={linear:9729,nearest:9728},Gt={linear:{linear:9987,nearest:9985},nearest:{linear:9986,nearest:9984}},I={"clamp-to-edge":33071,repeat:10497,"mirror-repeat":33648},Ut={never:512,less:513,equal:514,"less-equal":515,greater:516,"not-equal":517,"greater-equal":518,always:519};function Y(t,e,r,n,s,i,a,o){const u=i;if(!o||t.addressModeU!=="repeat"||t.addressModeV!=="repeat"||t.addressModeW!=="repeat"){const c=I[a?"clamp-to-edge":t.addressModeU],_=I[a?"clamp-to-edge":t.addressModeV],f=I[a?"clamp-to-edge":t.addressModeW];e[s](u,e.TEXTURE_WRAP_S,c),e[s](u,e.TEXTURE_WRAP_T,_),e.TEXTURE_WRAP_R&&e[s](u,e.TEXTURE_WRAP_R,f)}if((!o||t.magFilter!=="linear")&&e[s](u,e.TEXTURE_MAG_FILTER,$[t.magFilter]),r){if(!o||t.mipmapFilter!=="linear"){const c=Gt[t.minFilter][t.mipmapFilter];e[s](u,e.TEXTURE_MIN_FILTER,c)}}else e[s](u,e.TEXTURE_MIN_FILTER,$[t.minFilter]);if(n&&t.maxAnisotropy>1){const c=Math.min(t.maxAnisotropy,e.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));e[s](u,n.TEXTURE_MAX_ANISOTROPY_EXT,c)}t.compare&&e[s](u,e.TEXTURE_COMPARE_FUNC,Ut[t.compare])}function Ft(t){return{r8unorm:t.RED,r8snorm:t.RED,r8uint:t.RED,r8sint:t.RED,r16uint:t.RED,r16sint:t.RED,r16float:t.RED,rg8unorm:t.RG,rg8snorm:t.RG,rg8uint:t.RG,rg8sint:t.RG,r32uint:t.RED,r32sint:t.RED,r32float:t.RED,rg16uint:t.RG,rg16sint:t.RG,rg16float:t.RG,rgba8unorm:t.RGBA,"rgba8unorm-srgb":t.RGBA,rgba8snorm:t.RGBA,rgba8uint:t.RGBA,rgba8sint:t.RGBA,bgra8unorm:t.RGBA,"bgra8unorm-srgb":t.RGBA,rgb9e5ufloat:t.RGB,rgb10a2unorm:t.RGBA,rg11b10ufloat:t.RGB,rg32uint:t.RG,rg32sint:t.RG,rg32float:t.RG,rgba16uint:t.RGBA,rgba16sint:t.RGBA,rgba16float:t.RGBA,rgba32uint:t.RGBA,rgba32sint:t.RGBA,rgba32float:t.RGBA,stencil8:t.STENCIL_INDEX8,depth16unorm:t.DEPTH_COMPONENT,depth24plus:t.DEPTH_COMPONENT,"depth24plus-stencil8":t.DEPTH_STENCIL,depth32float:t.DEPTH_COMPONENT,"depth32float-stencil8":t.DEPTH_STENCIL}}function Pt(t,e){let r={},n=t.RGBA;return t instanceof R.get().getWebGLRenderingContext()?e.srgb&&(r={"rgba8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT,"bgra8unorm-srgb":e.srgb.SRGB8_ALPHA8_EXT}):(r={"rgba8unorm-srgb":t.SRGB8_ALPHA8,"bgra8unorm-srgb":t.SRGB8_ALPHA8},n=t.RGBA8),{r8unorm:t.R8,r8snorm:t.R8_SNORM,r8uint:t.R8UI,r8sint:t.R8I,r16uint:t.R16UI,r16sint:t.R16I,r16float:t.R16F,rg8unorm:t.RG8,rg8snorm:t.RG8_SNORM,rg8uint:t.RG8UI,rg8sint:t.RG8I,r32uint:t.R32UI,r32sint:t.R32I,r32float:t.R32F,rg16uint:t.RG16UI,rg16sint:t.RG16I,rg16float:t.RG16F,rgba8unorm:t.RGBA,...r,rgba8snorm:t.RGBA8_SNORM,rgba8uint:t.RGBA8UI,rgba8sint:t.RGBA8I,bgra8unorm:n,rgb9e5ufloat:t.RGB9_E5,rgb10a2unorm:t.RGB10_A2,rg11b10ufloat:t.R11F_G11F_B10F,rg32uint:t.RG32UI,rg32sint:t.RG32I,rg32float:t.RG32F,rgba16uint:t.RGBA16UI,rgba16sint:t.RGBA16I,rgba16float:t.RGBA16F,rgba32uint:t.RGBA32UI,rgba32sint:t.RGBA32I,rgba32float:t.RGBA32F,stencil8:t.STENCIL_INDEX8,depth16unorm:t.DEPTH_COMPONENT16,depth24plus:t.DEPTH_COMPONENT24,"depth24plus-stencil8":t.DEPTH24_STENCIL8,depth32float:t.DEPTH_COMPONENT32F,"depth32float-stencil8":t.DEPTH32F_STENCIL8,...e.s3tc?{"bc1-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT1_EXT,"bc2-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT3_EXT,"bc3-rgba-unorm":e.s3tc.COMPRESSED_RGBA_S3TC_DXT5_EXT}:{},...e.s3tc_sRGB?{"bc1-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,"bc2-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,"bc3-rgba-unorm-srgb":e.s3tc_sRGB.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT}:{},...e.rgtc?{"bc4-r-unorm":e.rgtc.COMPRESSED_RED_RGTC1_EXT,"bc4-r-snorm":e.rgtc.COMPRESSED_SIGNED_RED_RGTC1_EXT,"bc5-rg-unorm":e.rgtc.COMPRESSED_RED_GREEN_RGTC2_EXT,"bc5-rg-snorm":e.rgtc.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT}:{},...e.bptc?{"bc6h-rgb-float":e.bptc.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,"bc6h-rgb-ufloat":e.bptc.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,"bc7-rgba-unorm":e.bptc.COMPRESSED_RGBA_BPTC_UNORM_EXT,"bc7-rgba-unorm-srgb":e.bptc.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT}:{},...e.etc?{"etc2-rgb8unorm":e.etc.COMPRESSED_RGB8_ETC2,"etc2-rgb8unorm-srgb":e.etc.COMPRESSED_SRGB8_ETC2,"etc2-rgb8a1unorm":e.etc.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgb8a1unorm-srgb":e.etc.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2,"etc2-rgba8unorm":e.etc.COMPRESSED_RGBA8_ETC2_EAC,"etc2-rgba8unorm-srgb":e.etc.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC,"eac-r11unorm":e.etc.COMPRESSED_R11_EAC,"eac-rg11unorm":e.etc.COMPRESSED_SIGNED_RG11_EAC}:{},...e.astc?{"astc-4x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_4x4_KHR,"astc-4x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR,"astc-5x4-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x4_KHR,"astc-5x4-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR,"astc-5x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_5x5_KHR,"astc-5x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR,"astc-6x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x5_KHR,"astc-6x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR,"astc-6x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_6x6_KHR,"astc-6x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR,"astc-8x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x5_KHR,"astc-8x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR,"astc-8x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x6_KHR,"astc-8x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR,"astc-8x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_8x8_KHR,"astc-8x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR,"astc-10x5-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x5_KHR,"astc-10x5-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR,"astc-10x6-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x6_KHR,"astc-10x6-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR,"astc-10x8-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x8_KHR,"astc-10x8-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR,"astc-10x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_10x10_KHR,"astc-10x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR,"astc-12x10-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x10_KHR,"astc-12x10-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR,"astc-12x12-unorm":e.astc.COMPRESSED_RGBA_ASTC_12x12_KHR,"astc-12x12-unorm-srgb":e.astc.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR}:{}}}function Ot(t){return{r8unorm:t.UNSIGNED_BYTE,r8snorm:t.BYTE,r8uint:t.UNSIGNED_BYTE,r8sint:t.BYTE,r16uint:t.UNSIGNED_SHORT,r16sint:t.SHORT,r16float:t.HALF_FLOAT,rg8unorm:t.UNSIGNED_BYTE,rg8snorm:t.BYTE,rg8uint:t.UNSIGNED_BYTE,rg8sint:t.BYTE,r32uint:t.UNSIGNED_INT,r32sint:t.INT,r32float:t.FLOAT,rg16uint:t.UNSIGNED_SHORT,rg16sint:t.SHORT,rg16float:t.HALF_FLOAT,rgba8unorm:t.UNSIGNED_BYTE,"rgba8unorm-srgb":t.UNSIGNED_BYTE,rgba8snorm:t.BYTE,rgba8uint:t.UNSIGNED_BYTE,rgba8sint:t.BYTE,bgra8unorm:t.UNSIGNED_BYTE,"bgra8unorm-srgb":t.UNSIGNED_BYTE,rgb9e5ufloat:t.UNSIGNED_INT_5_9_9_9_REV,rgb10a2unorm:t.UNSIGNED_INT_2_10_10_10_REV,rg11b10ufloat:t.UNSIGNED_INT_10F_11F_11F_REV,rg32uint:t.UNSIGNED_INT,rg32sint:t.INT,rg32float:t.FLOAT,rgba16uint:t.UNSIGNED_SHORT,rgba16sint:t.SHORT,rgba16float:t.HALF_FLOAT,rgba32uint:t.UNSIGNED_INT,rgba32sint:t.INT,rgba32float:t.FLOAT,stencil8:t.UNSIGNED_BYTE,depth16unorm:t.UNSIGNED_SHORT,depth24plus:t.UNSIGNED_INT,"depth24plus-stencil8":t.UNSIGNED_INT_24_8,depth32float:t.FLOAT,"depth32float-stencil8":t.FLOAT_32_UNSIGNED_INT_24_8_REV}}function Mt(t){return{"2d":t.TEXTURE_2D,cube:t.TEXTURE_CUBE_MAP,"1d":null,"3d":(t==null?void 0:t.TEXTURE_3D)||null,"2d-array":(t==null?void 0:t.TEXTURE_2D_ARRAY)||null,"cube-array":(t==null?void 0:t.TEXTURE_CUBE_MAP_ARRAY)||null}}const Lt=4;class Re{constructor(e){this._glSamplers=Object.create(null),this._boundTextures=[],this._activeTextureLocation=-1,this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1,this._useSeparateSamplers=!1,this._renderer=e,this._managedTextures=new P({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"glTexture"});const r={image:Se,buffer:vt,video:It,compressed:Bt};this._uploads={...r,cube:yt(r)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gl=e,this._mapFormatToInternalFormat||(this._mapFormatToInternalFormat=Pt(e,this._renderer.context.extensions),this._mapFormatToType=Ot(e),this._mapFormatToFormat=Ft(e),this._mapViewDimensionToGlTarget=Mt(e)),this._managedTextures.removeAll(!0),this._glSamplers=Object.create(null),this._boundSamplers=Object.create(null),this._premultiplyAlpha=!1;for(let r=0;r<16;r++)this.bind(S.EMPTY,r)}initSource(e){this.bind(e)}bind(e,r=0){const n=e.source;e?(this.bindSource(n,r),this._useSeparateSamplers&&this._bindSampler(n.style,r)):(this.bindSource(null,r),this._useSeparateSamplers&&this._bindSampler(null,r))}bindSource(e,r=0){const n=this._gl;if(e._gcLastUsed=this._renderer.gc.now,this._boundTextures[r]!==e){this._boundTextures[r]=e,this._activateLocation(r),e||(e=S.EMPTY.source);const s=this.getGlSource(e);n.bindTexture(s.target,s.texture)}}_bindSampler(e,r=0){const n=this._gl;if(!e){this._boundSamplers[r]=null,n.bindSampler(r,null);return}const s=this._getGlSampler(e);this._boundSamplers[r]!==s&&(this._boundSamplers[r]=s,n.bindSampler(r,s))}unbind(e){const r=e.source,n=this._boundTextures,s=this._gl;for(let i=0;i<n.length;i++)if(n[i]===r){this._activateLocation(i);const a=this.getGlSource(r);s.bindTexture(a.target,null),n[i]=null}}_activateLocation(e){this._activeTextureLocation!==e&&(this._activeTextureLocation=e,this._gl.activeTexture(this._gl.TEXTURE0+e))}_initSource(e){const r=this._gl,n=new xt(r.createTexture());if(n.type=this._mapFormatToType[e.format],n.internalFormat=this._mapFormatToInternalFormat[e.format],n.format=this._mapFormatToFormat[e.format],n.target=this._mapViewDimensionToGlTarget[e.viewDimension],n.target===null)throw new Error(`Unsupported view dimension: ${e.viewDimension} with this webgl version: ${this._renderer.context.webGLVersion}`);if(e.uploadMethodId==="cube"&&(n.target=r.TEXTURE_CUBE_MAP),e.autoGenerateMipmaps&&(this._renderer.context.supports.nonPowOf2mipmaps||e.isPowerOfTwo)){const i=Math.max(e.width,e.height);e.mipLevelCount=Math.floor(Math.log2(i))+1}return e._gpuData[this._renderer.uid]=n,this._managedTextures.add(e)&&(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceUpdate,this),e.on("styleChange",this.onStyleChange,this),e.on("updateMipmaps",this.onUpdateMipmaps,this)),this.onSourceUpdate(e),this.updateStyle(e,!1),n}onStyleChange(e){this.updateStyle(e,!1)}updateStyle(e,r){const n=this._gl,s=this.getGlSource(e);n.bindTexture(s.target,s.texture),this._boundTextures[this._activeTextureLocation]=e,Y(e.style,n,e.mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"texParameteri",s.target,!this._renderer.context.supports.nonPowOf2wrapping&&!e.isPowerOfTwo,r)}onSourceUnload(e,r=!1){const n=e._gpuData[this._renderer.uid];n&&(r||(this.unbind(e),this._gl.deleteTexture(n.texture)),e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceUpdate,this),e.off("styleChange",this.onStyleChange,this),e.off("updateMipmaps",this.onUpdateMipmaps,this))}onSourceUpdate(e){const r=this._gl,n=this.getGlSource(e);r.bindTexture(n.target,n.texture),this._boundTextures[this._activeTextureLocation]=e;const s=e.alphaMode==="premultiply-alpha-on-upload";if(this._premultiplyAlpha!==s&&(this._premultiplyAlpha=s,r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)),this._uploads[e.uploadMethodId])this._uploads[e.uploadMethodId].upload(e,n,r,this._renderer.context.webGLVersion);else if(n.target===r.TEXTURE_2D)this._initEmptyTexture2D(n,e);else if(n.target===r.TEXTURE_2D_ARRAY)this._initEmptyTexture2DArray(n,e);else if(n.target===r.TEXTURE_CUBE_MAP)this._initEmptyTextureCube(n,e);else throw new Error("[GlTextureSystem] Unsupported texture target for empty allocation.");this._applyMipRange(n,e),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e,!1)}onUpdateMipmaps(e,r=!0){r&&this.bindSource(e,0);const n=this.getGlSource(e);this._gl.generateMipmap(n.target)}_initEmptyTexture2D(e,r){const n=this._gl;n.texImage2D(n.TEXTURE_2D,0,e.internalFormat,r.pixelWidth,r.pixelHeight,0,e.format,e.type,null);let s=Math.max(r.pixelWidth>>1,1),i=Math.max(r.pixelHeight>>1,1);for(let a=1;a<r.mipLevelCount;a++)n.texImage2D(n.TEXTURE_2D,a,e.internalFormat,s,i,0,e.format,e.type,null),s=Math.max(s>>1,1),i=Math.max(i>>1,1)}_initEmptyTexture2DArray(e,r){if(this._renderer.context.webGLVersion!==2)throw new Error("[GlTextureSystem] TEXTURE_2D_ARRAY requires WebGL2.");const n=this._gl,s=Math.max(r.arrayLayerCount|0,1);n.texImage3D(n.TEXTURE_2D_ARRAY,0,e.internalFormat,r.pixelWidth,r.pixelHeight,s,0,e.format,e.type,null);let i=Math.max(r.pixelWidth>>1,1),a=Math.max(r.pixelHeight>>1,1);for(let o=1;o<r.mipLevelCount;o++)n.texImage3D(n.TEXTURE_2D_ARRAY,o,e.internalFormat,i,a,s,0,e.format,e.type,null),i=Math.max(i>>1,1),a=Math.max(a>>1,1)}_initEmptyTextureCube(e,r){const n=this._gl,s=6;for(let o=0;o<s;o++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+o,0,e.internalFormat,r.pixelWidth,r.pixelHeight,0,e.format,e.type,null);let i=Math.max(r.pixelWidth>>1,1),a=Math.max(r.pixelHeight>>1,1);for(let o=1;o<r.mipLevelCount;o++){for(let u=0;u<s;u++)n.texImage2D(n.TEXTURE_CUBE_MAP_POSITIVE_X+u,o,e.internalFormat,i,a,0,e.format,e.type,null);i=Math.max(i>>1,1),a=Math.max(a>>1,1)}}_applyMipRange(e,r){if(this._renderer.context.webGLVersion!==2)return;const n=this._gl,s=Math.max((r.mipLevelCount|0)-1,0);n.texParameteri(e.target,n.TEXTURE_BASE_LEVEL,0),n.texParameteri(e.target,n.TEXTURE_MAX_LEVEL,s)}_initSampler(e){const r=this._gl,n=this._gl.createSampler();return this._glSamplers[e._resourceId]=n,Y(e,r,this._boundTextures[this._activeTextureLocation].mipLevelCount>1,this._renderer.context.extensions.anisotropicFiltering,"samplerParameteri",n,!1,!0),this._glSamplers[e._resourceId]}_getGlSampler(e){return this._glSamplers[e._resourceId]||this._initSampler(e)}getGlSource(e){return e._gcLastUsed=this._renderer.gc.now,e._gpuData[this._renderer.uid]||this._initSource(e)}generateCanvas(e){const{pixels:r,width:n,height:s}=this.getPixels(e),i=R.get().createCanvas();i.width=n,i.height=s;const a=i.getContext("2d");if(a){const o=a.createImageData(n,s);o.data.set(r),a.putImageData(o,0,0)}return i}getPixels(e){const r=e.source.resolution,n=e.frame,s=Math.max(Math.round(n.width*r),1),i=Math.max(Math.round(n.height*r),1),a=new Uint8Array(Lt*s*i),o=this._renderer,u=o.renderTarget.getRenderTarget(e),c=o.renderTarget.getGpuRenderTarget(u),_=o.gl;return _.bindFramebuffer(_.FRAMEBUFFER,c.resolveTargetFramebuffer),_.readPixels(Math.round(n.x*r),Math.round(n.y*r),s,i,_.RGBA,_.UNSIGNED_BYTE,a),{pixels:new Uint8ClampedArray(a.buffer),width:s,height:i}}destroy(){this._managedTextures.destroy(),this._glSamplers=null,this._boundTextures=null,this._boundSamplers=null,this._mapFormatToInternalFormat=null,this._mapFormatToType=null,this._mapFormatToFormat=null,this._uploads=null,this._renderer=null}resetState(){this._activeTextureLocation=-1,this._boundTextures.fill(S.EMPTY.source),this._boundSamplers=Object.create(null);const e=this._gl;this._premultiplyAlpha=!1,e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,this._premultiplyAlpha)}}Re.extension={type:[d.WebGLSystem],name:"texture"};class ge{contextChange(e){const r=new M({uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uTransformMatrix:{value:new Z,type:"mat3x3<f32>"},uRound:{value:0,type:"f32"}}),n=e.limits.maxBatchableTextures,s=Q({name:"graphics",bits:[De,Ie(n),J,ee]});this.shader=new O({glProgram:s,resources:{localUniforms:r,batchSamplers:Ge(n)}})}execute(e,r){const n=r.context,s=n.customShader||this.shader,i=e.renderer,a=i.graphicsContext,{batcher:o,instructions:u}=a.getContextRenderData(n);s.groups[0]=i.globalUniforms.bindGroup,i.state.set(e.state),i.shader.bind(s),i.geometry.bind(o.geometry,s.glProgram);const c=u.instructions;for(let _=0;_<u.instructionSize;_++){const f=c[_];if(f.size){for(let h=0;h<f.textures.count;h++)i.texture.bind(f.textures.textures[h],h);i.geometry.draw(f.topology,f.size,f.start)}}}destroy(){this.shader.destroy(!0),this.shader=null}}ge.extension={type:[d.WebGLPipesAdaptor],name:"graphics"};class Te{init(){const e=Q({name:"mesh",bits:[J,He,ee]});this._shader=new O({glProgram:e,resources:{uTexture:S.EMPTY.source,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new Z}}}})}execute(e,r){const n=e.renderer;let s=r._shader;if(s){if(!s.glProgram){p("Mesh shader has no glProgram",r.shader);return}}else{s=this._shader;const i=r.texture,a=i.source;s.resources.uTexture=a,s.resources.uSampler=a.style,s.resources.textureUniforms.uniforms.uTextureMatrix=i.textureMatrix.mapCoord}s.groups[100]=n.globalUniforms.bindGroup,s.groups[101]=e.localUniformsBindGroup,n.encoder.draw({geometry:r._geometry,shader:s,state:r.state})}destroy(){this._shader.destroy(!0),this._shader=null}}Te.extension={type:[d.WebGLPipesAdaptor],name:"mesh"};const wt=[...Xe,he,Ze,Ke,ue,ne,Re,le,ie,be,Ee,ce,Tt,_e,oe],Ht=[...ke],Vt=[re,Te,ge],xe=[],ve=[],Ae=[];A.handleByNamedList(d.WebGLSystem,xe);A.handleByNamedList(d.WebGLPipes,ve);A.handleByNamedList(d.WebGLPipesAdaptor,Ae);A.add(...wt,...Ht,...Vt);class Yt extends Ue{constructor(){const e={name:"webgl",type:Fe.WEBGL,systems:xe,renderPipes:ve,renderPipeAdaptors:Ae};super(e)}}export{Yt as WebGLRenderer};
@@ -0,0 +1,41 @@
1
+ import{Y as L,Z as A,p as l,_ as D,m as ce,$ as de,V as B,S as C,k as T,B as he,a0 as k,a1 as w,w as v,a2 as y,Q as pe,a3 as le,a4 as z,b as M,M as F,a5 as O,a6 as fe,a7 as ge,a8 as me,a9 as I,aa as W,ab as _e,T as R,W as be,X as ye,x as S}from"./index.nS-neZH_.js";import{c as xe,u as Ge,U as Pe,B as Be,G as Se,e as Te,t as Ce}from"./BufferResource.8pzc1eMm.js";import{R as ve,S as Ue,d as we}from"./RenderTargetSystem.CWKFKvEe.js";import"./framework.CBLqO2Q1.js";import"./mapValues.D2X8cRgC.js";import"./theme.B9FcKggM.js";const G=L.for2d();class H{start(e,t,r){const s=e.renderer,i=s.encoder,n=r.gpuProgram;this._shader=r,this._geometry=t,i.setGeometry(t,n),G.blendMode="normal",s.pipeline.getPipeline(t,n,G);const o=s.globalUniforms.bindGroup;i.resetBindGroup(1),i.setBindGroup(0,o,n)}execute(e,t){const r=this._shader.gpuProgram,s=e.renderer,i=s.encoder;if(!t.bindGroup){const u=t.textures;t.bindGroup=A(u.textures,u.count,s.limits.maxBatchableTextures)}G.blendMode=t.blendMode;const n=s.bindGroup.getBindGroup(t.bindGroup,r,1),o=s.pipeline.getPipeline(this._geometry,r,G,t.topology);t.bindGroup._touch(s.gc.now,s.tick),i.setPipeline(o),i.renderPassEncoder.setBindGroup(1,n),i.renderPassEncoder.drawIndexed(t.size,1,t.start)}}H.extension={type:[l.WebGPUPipesAdaptor],name:"batch"};class V{constructor(e){this._hash=Object.create(null),this._renderer=e}contextChange(e){this._gpu=e}getBindGroup(e,t,r){return e._updateKey(),this._hash[e._key]||this._createBindGroup(e,t,r)}_createBindGroup(e,t,r){const s=this._gpu.device,i=t.layout[r],n=[],o=this._renderer;for(const f in i){const h=e.resources[f]??e.resources[i[f]];let p;if(h._resourceType==="uniformGroup"){const d=h;o.ubo.updateUniformGroup(d);const g=d.buffer;p={buffer:o.buffer.getGPUBuffer(g),offset:0,size:g.descriptor.size}}else if(h._resourceType==="buffer"){const d=h;p={buffer:o.buffer.getGPUBuffer(d),offset:0,size:d.descriptor.size}}else if(h._resourceType==="bufferResource"){const d=h;p={buffer:o.buffer.getGPUBuffer(d.buffer),offset:d.offset,size:d.size}}else if(h._resourceType==="textureSampler"){const d=h;p=o.texture.getGpuSampler(d)}else if(h._resourceType==="textureSource"){const d=h;p=o.texture.getTextureView(d)}n.push({binding:i[f],resource:p})}const u=o.shader.getProgramData(t).bindGroups[r],c=s.createBindGroup({layout:u,entries:n});return this._hash[e._key]=c,c}destroy(){this._hash=null,this._renderer=null}}V.extension={type:[l.WebGPUSystem],name:"bindGroup"};class Me{constructor(e){this.gpuBuffer=e}destroy(){this.gpuBuffer.destroy(),this.gpuBuffer=null}}class N{constructor(e){this._renderer=e,this._managedBuffers=new D({renderer:e,type:"resource",onUnload:this.onBufferUnload.bind(this),name:"gpuBuffer"})}contextChange(e){this._gpu=e}getGPUBuffer(e){var t;return e._gcLastUsed=this._renderer.gc.now,((t=e._gpuData[this._renderer.uid])==null?void 0:t.gpuBuffer)||this.createGPUBuffer(e)}updateBuffer(e){const t=this.getGPUBuffer(e),r=e.data;return e._updateID&&r&&(e._updateID=0,this._gpu.device.queue.writeBuffer(t,0,r.buffer,0,(e._updateSize||r.byteLength)+3&-4)),t}destroyAll(){this._managedBuffers.removeAll()}onBufferUnload(e){e.off("update",this.updateBuffer,this),e.off("change",this.onBufferChange,this)}createGPUBuffer(e){const t=this._gpu.device.createBuffer(e.descriptor);return e._updateID=0,e._resourceId=ce("resource"),e.data&&(de(e.data.buffer,t.getMappedRange(),e.data.byteOffset,e.data.byteLength),t.unmap()),e._gpuData[this._renderer.uid]=new Me(t),this._managedBuffers.add(e)&&(e.on("update",this.updateBuffer,this),e.on("change",this.onBufferChange,this)),t}onBufferChange(e){this._managedBuffers.remove(e),e._updateID=0,this.createGPUBuffer(e)}destroy(){this._managedBuffers.destroy(),this._renderer=null,this._gpu=null}}N.extension={type:[l.WebGPUSystem],name:"buffer"};class Re{constructor({minUniformOffsetAlignment:e}){this._minUniformOffsetAlignment=256,this.byteIndex=0,this._minUniformOffsetAlignment=e,this.data=new Float32Array(65535)}clear(){this.byteIndex=0}addEmptyGroup(e){if(e>this._minUniformOffsetAlignment/4)throw new Error(`UniformBufferBatch: array is too large: ${e*4}`);const t=this.byteIndex;let r=t+e*4;if(r=Math.ceil(r/this._minUniformOffsetAlignment)*this._minUniformOffsetAlignment,r>this.data.length*4)throw new Error("UniformBufferBatch: ubo batch got too big");return this.byteIndex=r,t}addGroup(e){const t=this.addEmptyGroup(e.length);for(let r=0;r<e.length;r++)this.data[t/4+r]=e[r];return t}destroy(){this.data=null}}class j{constructor(e){this._colorMaskCache=15,this._renderer=e}setMask(e){this._colorMaskCache!==e&&(this._colorMaskCache=e,this._renderer.pipeline.setColorMask(e))}destroy(){this._renderer=null,this._colorMaskCache=null}}j.extension={type:[l.WebGPUSystem],name:"colorMask"};class U{constructor(e){this._renderer=e}async init(e){return this._initPromise?this._initPromise:(this._initPromise=(e.gpu?Promise.resolve(e.gpu):this._createDeviceAndAdaptor(e)).then(t=>{this.gpu=t,this._renderer.runners.contextChange.emit(this.gpu)}),this._initPromise)}contextChange(e){this._renderer.gpu=e}async _createDeviceAndAdaptor(e){const t=await B.get().getNavigator().gpu.requestAdapter({powerPreference:e.powerPreference,forceFallbackAdapter:e.forceFallbackAdapter}),r=["texture-compression-bc","texture-compression-astc","texture-compression-etc2"].filter(i=>t.features.has(i)),s=await t.requestDevice({requiredFeatures:r});return{adapter:t,device:s}}destroy(){this.gpu=null,this._renderer=null}}U.extension={type:[l.WebGPUSystem],name:"device"};U.defaultOptions={powerPreference:void 0,forceFallbackAdapter:!1};class K{constructor(e){this._boundBindGroup=Object.create(null),this._boundVertexBuffer=Object.create(null),this._renderer=e}renderStart(){this.commandFinished=new Promise(e=>{this._resolveCommandFinished=e}),this.commandEncoder=this._renderer.gpu.device.createCommandEncoder()}beginRenderPass(e){this.endRenderPass(),this._clearCache(),this.renderPassEncoder=this.commandEncoder.beginRenderPass(e.descriptor)}endRenderPass(){this.renderPassEncoder&&this.renderPassEncoder.end(),this.renderPassEncoder=null}setViewport(e){this.renderPassEncoder.setViewport(e.x,e.y,e.width,e.height,0,1)}setPipelineFromGeometryProgramAndState(e,t,r,s){const i=this._renderer.pipeline.getPipeline(e,t,r,s);this.setPipeline(i)}setPipeline(e){this._boundPipeline!==e&&(this._boundPipeline=e,this.renderPassEncoder.setPipeline(e))}_setVertexBuffer(e,t){this._boundVertexBuffer[e]!==t&&(this._boundVertexBuffer[e]=t,this.renderPassEncoder.setVertexBuffer(e,this._renderer.buffer.updateBuffer(t)))}_setIndexBuffer(e){if(this._boundIndexBuffer===e)return;this._boundIndexBuffer=e;const t=e.data.BYTES_PER_ELEMENT===2?"uint16":"uint32";this.renderPassEncoder.setIndexBuffer(this._renderer.buffer.updateBuffer(e),t)}resetBindGroup(e){this._boundBindGroup[e]=null}setBindGroup(e,t,r){if(this._boundBindGroup[e]===t)return;this._boundBindGroup[e]=t,t._touch(this._renderer.gc.now,this._renderer.tick);const s=this._renderer.bindGroup.getBindGroup(t,r,e);this.renderPassEncoder.setBindGroup(e,s)}setGeometry(e,t){const r=this._renderer.pipeline.getBufferNamesToBind(e,t);for(const s in r)this._setVertexBuffer(parseInt(s,10),e.attributes[r[s]].buffer);e.indexBuffer&&this._setIndexBuffer(e.indexBuffer)}_setShaderBindGroups(e,t){for(const r in e.groups){const s=e.groups[r];t||this._syncBindGroup(s),this.setBindGroup(r,s,e.gpuProgram)}}_syncBindGroup(e){for(const t in e.resources){const r=e.resources[t];r.isUniformGroup&&this._renderer.ubo.updateUniformGroup(r)}}draw(e){const{geometry:t,shader:r,state:s,topology:i,size:n,start:o,instanceCount:u,skipSync:c}=e;this.setPipelineFromGeometryProgramAndState(t,r.gpuProgram,s,i),this.setGeometry(t,r.gpuProgram),this._setShaderBindGroups(r,c),t.indexBuffer?this.renderPassEncoder.drawIndexed(n||t.indexBuffer.data.length,u??t.instanceCount,o||0):this.renderPassEncoder.draw(n||t.getSize(),u??t.instanceCount,o||0)}finishRenderPass(){this.renderPassEncoder&&(this.renderPassEncoder.end(),this.renderPassEncoder=null)}postrender(){this.finishRenderPass(),this._gpu.device.queue.submit([this.commandEncoder.finish()]),this._resolveCommandFinished(),this.commandEncoder=null}restoreRenderPass(){const e=this._renderer.renderTarget.adaptor.getDescriptor(this._renderer.renderTarget.renderTarget,!1,[0,0,0,1],this._renderer.renderTarget.mipLevel,this._renderer.renderTarget.layer);this.renderPassEncoder=this.commandEncoder.beginRenderPass(e);const t=this._boundPipeline,r={...this._boundVertexBuffer},s=this._boundIndexBuffer,i={...this._boundBindGroup};this._clearCache();const n=this._renderer.renderTarget.viewport;this.renderPassEncoder.setViewport(n.x,n.y,n.width,n.height,0,1),this.setPipeline(t);for(const o in r)this._setVertexBuffer(o,r[o]);for(const o in i)this.setBindGroup(o,i[o],null);this._setIndexBuffer(s)}_clearCache(){for(let e=0;e<16;e++)this._boundBindGroup[e]=null,this._boundVertexBuffer[e]=null;this._boundIndexBuffer=null,this._boundPipeline=null}destroy(){this._renderer=null,this._gpu=null,this._boundBindGroup=null,this._boundVertexBuffer=null,this._boundIndexBuffer=null,this._boundPipeline=null}contextChange(e){this._gpu=e}}K.extension={type:[l.WebGPUSystem],name:"encoder",priority:1};class q{constructor(e){this._renderer=e}contextChange(){this.maxTextures=this._renderer.device.gpu.device.limits.maxSampledTexturesPerShaderStage,this.maxBatchableTextures=this.maxTextures}destroy(){}}q.extension={type:[l.WebGPUSystem],name:"limits"};class Y{constructor(e){this._renderTargetStencilState=Object.create(null),this._renderer=e,e.renderTarget.onRenderTargetChange.add(this)}onRenderTargetChange(e){let t=this._renderTargetStencilState[e.uid];t||(t=this._renderTargetStencilState[e.uid]={stencilMode:C.DISABLED,stencilReference:0}),this._activeRenderTarget=e,this.setStencilMode(t.stencilMode,t.stencilReference)}setStencilMode(e,t){const r=this._renderTargetStencilState[this._activeRenderTarget.uid];r.stencilMode=e,r.stencilReference=t;const s=this._renderer;s.pipeline.setStencilMode(e),s.encoder.renderPassEncoder.setStencilReference(t)}destroy(){this._renderer.renderTarget.onRenderTargetChange.remove(this),this._renderer=null,this._activeRenderTarget=null,this._renderTargetStencilState=null}}Y.extension={type:[l.WebGPUSystem],name:"stencil"};const P={i32:{align:4,size:4},u32:{align:4,size:4},f32:{align:4,size:4},f16:{align:2,size:2},"vec2<i32>":{align:8,size:8},"vec2<u32>":{align:8,size:8},"vec2<f32>":{align:8,size:8},"vec2<f16>":{align:4,size:4},"vec3<i32>":{align:16,size:12},"vec3<u32>":{align:16,size:12},"vec3<f32>":{align:16,size:12},"vec3<f16>":{align:8,size:6},"vec4<i32>":{align:16,size:16},"vec4<u32>":{align:16,size:16},"vec4<f32>":{align:16,size:16},"vec4<f16>":{align:8,size:8},"mat2x2<f32>":{align:8,size:16},"mat2x2<f16>":{align:4,size:8},"mat3x2<f32>":{align:8,size:24},"mat3x2<f16>":{align:4,size:12},"mat4x2<f32>":{align:8,size:32},"mat4x2<f16>":{align:4,size:16},"mat2x3<f32>":{align:16,size:32},"mat2x3<f16>":{align:8,size:16},"mat3x3<f32>":{align:16,size:48},"mat3x3<f16>":{align:8,size:24},"mat4x3<f32>":{align:16,size:64},"mat4x3<f16>":{align:8,size:32},"mat2x4<f32>":{align:16,size:32},"mat2x4<f16>":{align:8,size:16},"mat3x4<f32>":{align:16,size:48},"mat3x4<f16>":{align:8,size:24},"mat4x4<f32>":{align:16,size:64},"mat4x4<f16>":{align:8,size:32}};function Ee(a){const e=a.map(r=>({data:r,offset:0,size:0}));let t=0;for(let r=0;r<e.length;r++){const s=e[r];let i=P[s.data.type].size;const n=P[s.data.type].align;if(!P[s.data.type])throw new Error(`[Pixi.js] WebGPU UniformBuffer: Unknown type ${s.data.type}`);s.data.size>1&&(i=Math.max(i,n)*s.data.size),t=Math.ceil(t/n)*n,s.size=i,s.offset=t,t+=i}return t=Math.ceil(t/16)*16,{uboElements:e,size:t}}function Le(a,e){const{size:t,align:r}=P[a.data.type],s=(r-t)/4,i=a.data.type.indexOf("i32")>=0?"dataInt32":"data";return`
2
+ v = uv.${a.data.name};
3
+ ${e!==0?`offset += ${e};`:""}
4
+
5
+ arrayOffset = offset;
6
+
7
+ t = 0;
8
+
9
+ for(var i=0; i < ${a.data.size*(t/4)}; i++)
10
+ {
11
+ for(var j = 0; j < ${t/4}; j++)
12
+ {
13
+ ${i}[arrayOffset++] = v[t++];
14
+ }
15
+ ${s!==0?`arrayOffset += ${s};`:""}
16
+ }
17
+ `}function Ae(a){return xe(a,"uboWgsl",Le,Ge)}class $ extends Pe{constructor(){super({createUboElements:Ee,generateUboSync:Ae})}}$.extension={type:[l.WebGPUSystem],name:"ubo"};const b=128;class X{constructor(e){this._bindGroupHash=Object.create(null),this._buffers=[],this._bindGroups=[],this._bufferResources=[],this._renderer=e,this._batchBuffer=new Re({minUniformOffsetAlignment:b});const t=256/b;for(let r=0;r<t;r++){let s=T.UNIFORM|T.COPY_DST;r===0&&(s|=T.COPY_SRC),this._buffers.push(new he({data:this._batchBuffer.data,usage:s}))}}renderEnd(){this._uploadBindGroups(),this._resetBindGroups()}_resetBindGroups(){this._bindGroupHash=Object.create(null),this._batchBuffer.clear()}getUniformBindGroup(e,t){if(!t&&this._bindGroupHash[e.uid])return this._bindGroupHash[e.uid];this._renderer.ubo.ensureUniformGroup(e);const r=e.buffer.data,s=this._batchBuffer.addEmptyGroup(r.length);return this._renderer.ubo.syncUniformGroup(e,this._batchBuffer.data,s/4),this._bindGroupHash[e.uid]=this._getBindGroup(s/b),this._bindGroupHash[e.uid]}getUboResource(e){this._renderer.ubo.updateUniformGroup(e);const t=e.buffer.data,r=this._batchBuffer.addGroup(t);return this._getBufferResource(r/b)}getArrayBindGroup(e){const t=this._batchBuffer.addGroup(e);return this._getBindGroup(t/b)}getArrayBufferResource(e){const r=this._batchBuffer.addGroup(e)/b;return this._getBufferResource(r)}_getBufferResource(e){if(!this._bufferResources[e]){const t=this._buffers[e%2];this._bufferResources[e]=new Be({buffer:t,offset:(e/2|0)*256,size:b})}return this._bufferResources[e]}_getBindGroup(e){if(!this._bindGroups[e]){const t=new k({0:this._getBufferResource(e)});this._bindGroups[e]=t}return this._bindGroups[e]}_uploadBindGroups(){const e=this._renderer.buffer,t=this._buffers[0];t.update(this._batchBuffer.byteIndex),e.updateBuffer(t);const r=this._renderer.gpu.device.createCommandEncoder();for(let s=1;s<this._buffers.length;s++){const i=this._buffers[s];r.copyBufferToBuffer(e.getGPUBuffer(t),b,e.getGPUBuffer(i),0,this._batchBuffer.byteIndex)}this._renderer.gpu.device.queue.submit([r.finish()])}destroy(){var e;for(let t=0;t<this._bindGroups.length;t++)(e=this._bindGroups[t])==null||e.destroy();this._bindGroups=null,this._bindGroupHash=null;for(let t=0;t<this._buffers.length;t++)this._buffers[t].destroy();this._buffers=null;for(let t=0;t<this._bufferResources.length;t++)this._bufferResources[t].destroy();this._bufferResources=null,this._batchBuffer.destroy(),this._renderer=null}}X.extension={type:[l.WebGPUPipes],name:"uniformBatch"};const De={"point-list":0,"line-list":1,"line-strip":2,"triangle-list":3,"triangle-strip":4};function ke(a,e,t,r,s){return a<<24|e<<16|t<<10|r<<5|s}function ze(a,e,t,r,s){return t<<8|a<<5|r<<3|s<<1|e}class Z{constructor(e){this._moduleCache=Object.create(null),this._bufferLayoutsCache=Object.create(null),this._bindingNamesCache=Object.create(null),this._pipeCache=Object.create(null),this._pipeStateCaches=Object.create(null),this._colorMask=15,this._multisampleCount=1,this._colorTargetCount=1,this._renderer=e}contextChange(e){this._gpu=e,this.setStencilMode(C.DISABLED),this._updatePipeHash()}setMultisampleCount(e){this._multisampleCount!==e&&(this._multisampleCount=e,this._updatePipeHash())}setRenderTarget(e){this._multisampleCount=e.msaaSamples,this._depthStencilAttachment=e.descriptor.depthStencilAttachment?1:0,this._colorTargetCount=e.colorTargetCount,this._updatePipeHash()}setColorMask(e){this._colorMask!==e&&(this._colorMask=e,this._updatePipeHash())}setStencilMode(e){this._stencilMode!==e&&(this._stencilMode=e,this._stencilState=Se[e],this._updatePipeHash())}setPipeline(e,t,r,s){const i=this.getPipeline(e,t,r);s.setPipeline(i)}getPipeline(e,t,r,s){e._layoutKey||(Te(e,t.attributeData),this._generateBufferKey(e)),s||(s=e.topology);const i=ke(e._layoutKey,t._layoutKey,r.data,r._blendModeId,De[s]);return this._pipeCache[i]?this._pipeCache[i]:(this._pipeCache[i]=this._createPipeline(e,t,r,s),this._pipeCache[i])}_createPipeline(e,t,r,s){const i=this._gpu.device,n=this._createVertexBufferLayouts(e,t),o=this._renderer.state.getColorTargets(r,this._colorTargetCount),u=this._stencilMode===C.RENDERING_MASK_ADD?0:this._colorMask;for(let p=0;p<o.length;p++)o[p].writeMask=u;const c=this._renderer.shader.getProgramData(t).pipeline,f={vertex:{module:this._getModule(t.vertex.source),entryPoint:t.vertex.entryPoint,buffers:n},fragment:{module:this._getModule(t.fragment.source),entryPoint:t.fragment.entryPoint,targets:o},primitive:{topology:s,cullMode:r.cullMode},layout:c,multisample:{count:this._multisampleCount},label:"PIXI Pipeline"};return this._depthStencilAttachment&&(f.depthStencil={...this._stencilState,format:"depth24plus-stencil8",depthWriteEnabled:r.depthTest,depthCompare:r.depthTest?"less":"always"}),i.createRenderPipeline(f)}_getModule(e){return this._moduleCache[e]||this._createModule(e)}_createModule(e){const t=this._gpu.device;return this._moduleCache[e]=t.createShaderModule({code:e}),this._moduleCache[e]}_generateBufferKey(e){const t=[];let r=0;const s=Object.keys(e.attributes).sort();for(let n=0;n<s.length;n++){const o=e.attributes[s[n]];t[r++]=o.offset,t[r++]=o.format,t[r++]=o.stride,t[r++]=o.instance}const i=t.join("|");return e._layoutKey=w(i,"geometry"),e._layoutKey}_generateAttributeLocationsKey(e){const t=[];let r=0;const s=Object.keys(e.attributeData).sort();for(let n=0;n<s.length;n++){const o=e.attributeData[s[n]];t[r++]=o.location}const i=t.join("|");return e._attributeLocationsKey=w(i,"programAttributes"),e._attributeLocationsKey}getBufferNamesToBind(e,t){const r=e._layoutKey<<16|t._attributeLocationsKey;if(this._bindingNamesCache[r])return this._bindingNamesCache[r];const s=this._createVertexBufferLayouts(e,t),i=Object.create(null),n=t.attributeData;for(let o=0;o<s.length;o++){const c=Object.values(s[o].attributes)[0].shaderLocation;for(const f in n)if(n[f].location===c){i[o]=f;break}}return this._bindingNamesCache[r]=i,i}_createVertexBufferLayouts(e,t){t._attributeLocationsKey||this._generateAttributeLocationsKey(t);const r=e._layoutKey<<16|t._attributeLocationsKey;if(this._bufferLayoutsCache[r])return this._bufferLayoutsCache[r];const s=[];return e.buffers.forEach(i=>{const n={arrayStride:0,stepMode:"vertex",attributes:[]},o=n.attributes;for(const u in t.attributeData){const c=e.attributes[u];(c.divisor??1)!==1&&v(`Attribute ${u} has an invalid divisor value of '${c.divisor}'. WebGPU only supports a divisor value of 1`),c.buffer===i&&(n.arrayStride=c.stride,n.stepMode=c.instance?"instance":"vertex",o.push({shaderLocation:t.attributeData[u].location,offset:c.offset,format:c.format}))}o.length&&s.push(n)}),this._bufferLayoutsCache[r]=s,s}_updatePipeHash(){const e=ze(this._stencilMode,this._multisampleCount,this._colorMask,this._depthStencilAttachment,this._colorTargetCount);this._pipeStateCaches[e]||(this._pipeStateCaches[e]=Object.create(null)),this._pipeCache=this._pipeStateCaches[e]}destroy(){this._renderer=null,this._bufferLayoutsCache=null}}Z.extension={type:[l.WebGPUSystem],name:"pipeline"};class Fe{constructor(){this.contexts=[],this.msaaTextures=[],this.msaaSamples=1}}class Oe{init(e,t){this._renderer=e,this._renderTargetSystem=t}copyToTexture(e,t,r,s,i){const n=this._renderer,o=this._getGpuColorTexture(e),u=n.texture.getGpuSource(t.source);return n.encoder.commandEncoder.copyTextureToTexture({texture:o,origin:r},{texture:u,origin:i},s),t}startRenderPass(e,t=!0,r,s,i=0,n=0){var f,h;const u=this._renderTargetSystem.getGpuRenderTarget(e);if(n!==0&&((f=u.msaaTextures)!=null&&f.length))throw new Error("[RenderTargetSystem] Rendering to array layers is not supported with MSAA render targets.");if(i>0&&((h=u.msaaTextures)!=null&&h.length))throw new Error("[RenderTargetSystem] Rendering to mip levels is not supported with MSAA render targets.");const c=this.getDescriptor(e,t,r,i,n);u.descriptor=c,this._renderer.pipeline.setRenderTarget(u),this._renderer.encoder.beginRenderPass(u),this._renderer.encoder.setViewport(s)}finishRenderPass(){this._renderer.encoder.endRenderPass()}_getGpuColorTexture(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);return t.contexts[0]?t.contexts[0].getCurrentTexture():this._renderer.texture.getGpuSource(e.colorTextures[0].source)}getDescriptor(e,t,r,s=0,i=0){typeof t=="boolean"&&(t=t?y.ALL:y.NONE);const n=this._renderTargetSystem,o=n.getGpuRenderTarget(e),u=e.colorTextures.map((h,p)=>{const d=o.contexts[p];let g,m;if(d){if(i!==0)throw new Error("[RenderTargetSystem] Rendering to array layers is not supported for canvas targets.");g=d.getCurrentTexture().createView()}else g=this._renderer.texture.getGpuSource(h).createView({dimension:"2d",baseMipLevel:s,mipLevelCount:1,baseArrayLayer:i,arrayLayerCount:1});o.msaaTextures[p]&&(m=g,g=this._renderer.texture.getTextureView(o.msaaTextures[p]));const x=t&y.COLOR?"clear":"load";return r??(r=n.defaultClearColor),{view:g,resolveTarget:m,clearValue:r,storeOp:"store",loadOp:x}});let c;if((e.stencil||e.depth)&&!e.depthStencilTexture&&(e.ensureDepthStencilTexture(),e.depthStencilTexture.source.sampleCount=o.msaa?4:1),e.depthStencilTexture){const h=t&y.STENCIL?"clear":"load",p=t&y.DEPTH?"clear":"load";c={view:this._renderer.texture.getGpuSource(e.depthStencilTexture.source).createView({dimension:"2d",baseMipLevel:s,mipLevelCount:1,baseArrayLayer:i,arrayLayerCount:1}),stencilStoreOp:"store",stencilLoadOp:h,depthClearValue:1,depthLoadOp:p,depthStoreOp:"store"}}return{colorAttachments:u,depthStencilAttachment:c}}clear(e,t=!0,r,s,i=0,n=0){if(!t)return;const{gpu:o,encoder:u}=this._renderer,c=o.device;if(u.commandEncoder===null){const h=c.createCommandEncoder(),p=this.getDescriptor(e,t,r,i,n),d=h.beginRenderPass(p);d.setViewport(s.x,s.y,s.width,s.height,0,1),d.end();const g=h.finish();c.queue.submit([g])}else this.startRenderPass(e,t,r,s,i,n)}initGpuRenderTarget(e){e.isRoot=!0;const t=new Fe;return t.colorTargetCount=e.colorTextures.length,e.colorTextures.forEach((r,s)=>{if(r instanceof pe){const i=r.resource.getContext("webgpu"),n=r.transparent?"premultiplied":"opaque";try{i.configure({device:this._renderer.gpu.device,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT|GPUTextureUsage.COPY_SRC,format:"bgra8unorm",alphaMode:n})}catch(o){console.error(o)}t.contexts[s]=i}if(t.msaa=r.source.antialias,r.source.antialias){const i=new le({width:0,height:0,sampleCount:4,arrayLayerCount:r.source.arrayLayerCount});t.msaaTextures[s]=i}}),t.msaa&&(t.msaaSamples=4,e.depthStencilTexture&&(e.depthStencilTexture.source.sampleCount=4)),t}destroyGpuRenderTarget(e){e.contexts.forEach(t=>{t.unconfigure()}),e.msaaTextures.forEach(t=>{t.destroy()}),e.msaaTextures.length=0,e.contexts.length=0}ensureDepthStencilTexture(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);e.depthStencilTexture&&t.msaa&&(e.depthStencilTexture.source.sampleCount=4)}resizeGpuRenderTarget(e){const t=this._renderTargetSystem.getGpuRenderTarget(e);t.width=e.width,t.height=e.height,t.msaa&&e.colorTextures.forEach((r,s)=>{const i=t.msaaTextures[s];i==null||i.resize(r.source.width,r.source.height,r.source._resolution)})}}class Q extends ve{constructor(e){super(e),this.adaptor=new Oe,this.adaptor.init(e,this)}}Q.extension={type:[l.WebGPUSystem],name:"renderTarget"};class J{constructor(){this._gpuProgramData=Object.create(null)}contextChange(e){this._gpu=e}getProgramData(e){return this._gpuProgramData[e._layoutKey]||this._createGPUProgramData(e)}_createGPUProgramData(e){const t=this._gpu.device,r=e.gpuLayout.map(i=>t.createBindGroupLayout({entries:i})),s={bindGroupLayouts:r};return this._gpuProgramData[e._layoutKey]={bindGroups:r,pipeline:t.createPipelineLayout(s)},this._gpuProgramData[e._layoutKey]}destroy(){this._gpu=null,this._gpuProgramData=null}}J.extension={type:[l.WebGPUSystem],name:"shader"};const _={};_.normal={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"}};_.add={alpha:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one",operation:"add"}};_.multiply={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"dst",dstFactor:"one-minus-src-alpha",operation:"add"}};_.screen={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}};_.overlay={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"one",dstFactor:"one-minus-src",operation:"add"}};_.none={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"zero",operation:"add"}};_["normal-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha",operation:"add"}};_["add-npm"]={alpha:{srcFactor:"one",dstFactor:"one",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one",operation:"add"}};_["screen-npm"]={alpha:{srcFactor:"one",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"src-alpha",dstFactor:"one-minus-src",operation:"add"}};_.erase={alpha:{srcFactor:"zero",dstFactor:"one-minus-src-alpha",operation:"add"},color:{srcFactor:"zero",dstFactor:"one-minus-src",operation:"add"}};_.min={alpha:{srcFactor:"one",dstFactor:"one",operation:"min"},color:{srcFactor:"one",dstFactor:"one",operation:"min"}};_.max={alpha:{srcFactor:"one",dstFactor:"one",operation:"max"},color:{srcFactor:"one",dstFactor:"one",operation:"max"}};class ee{constructor(){this.defaultState=new L,this.defaultState.blend=!0}contextChange(e){this.gpu=e}getColorTargets(e,t){const r=_[e.blendMode]||_.normal,s=[],i={format:"bgra8unorm",writeMask:0,blend:r};for(let n=0;n<t;n++)s[n]=i;return s}destroy(){this.gpu=null}}ee.extension={type:[l.WebGPUSystem],name:"state"};const Ie={type:"image",upload(a,e,t,r=0){const s=a.resource,i=(a.pixelWidth|0)*(a.pixelHeight|0),n=s.byteLength/i;t.device.queue.writeTexture({texture:e,origin:{x:0,y:0,z:r}},s,{offset:0,rowsPerImage:a.pixelHeight,bytesPerRow:a.pixelWidth*n},{width:a.pixelWidth,height:a.pixelHeight,depthOrArrayLayers:1})}},te={"bc1-rgba-unorm":{blockBytes:8,blockWidth:4,blockHeight:4},"bc2-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"bc3-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"bc7-rgba-unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"etc1-rgb-unorm":{blockBytes:8,blockWidth:4,blockHeight:4},"etc2-rgba8unorm":{blockBytes:16,blockWidth:4,blockHeight:4},"astc-4x4-unorm":{blockBytes:16,blockWidth:4,blockHeight:4}},We={blockBytes:4,blockWidth:1,blockHeight:1},He={type:"compressed",upload(a,e,t,r=0){let s=a.pixelWidth,i=a.pixelHeight;const n=te[a.format]||We;for(let o=0;o<a.resource.length;o++){const u=a.resource[o],c=Math.ceil(s/n.blockWidth)*n.blockBytes;t.device.queue.writeTexture({texture:e,mipLevel:o,origin:{x:0,y:0,z:r}},u,{offset:0,bytesPerRow:c},{width:Math.ceil(s/n.blockWidth)*n.blockWidth,height:Math.ceil(i/n.blockHeight)*n.blockHeight,depthOrArrayLayers:1}),s=Math.max(s>>1,1),i=Math.max(i>>1,1)}}},E=["right","left","top","bottom","front","back"];function Ve(a){return{type:"cube",upload(e,t,r){const s=e.faces;for(let i=0;i<E.length;i++){const n=E[i],o=s[n];(a[o.uploadMethodId]||a.image).upload(o,t,r,i)}}}}const re={type:"image",upload(a,e,t,r=0){const s=a.resource;if(!s)return;if(globalThis.HTMLImageElement&&s instanceof HTMLImageElement){const u=B.get().createCanvas(s.width,s.height);u.getContext("2d").drawImage(s,0,0,s.width,s.height),a.resource=u,v("ImageSource: Image element passed, converting to canvas and replacing resource.")}const i=Math.min(e.width,a.resourceWidth||a.pixelWidth),n=Math.min(e.height,a.resourceHeight||a.pixelHeight),o=a.alphaMode==="premultiply-alpha-on-upload";t.device.queue.copyExternalImageToTexture({source:s},{texture:e,origin:{x:0,y:0,z:r},premultipliedAlpha:o},{width:i,height:n})}},Ne={type:"video",upload(a,e,t,r){re.upload(a,e,t,r)}};class je{constructor(e){this.device=e,this.sampler=e.createSampler({minFilter:"linear"}),this.pipelines={}}_getMipmapPipeline(e){let t=this.pipelines[e];return t||(this.mipmapShaderModule||(this.mipmapShaderModule=this.device.createShaderModule({code:`
18
+ var<private> pos : array<vec2<f32>, 3> = array<vec2<f32>, 3>(
19
+ vec2<f32>(-1.0, -1.0), vec2<f32>(-1.0, 3.0), vec2<f32>(3.0, -1.0));
20
+
21
+ struct VertexOutput {
22
+ @builtin(position) position : vec4<f32>,
23
+ @location(0) texCoord : vec2<f32>,
24
+ };
25
+
26
+ @vertex
27
+ fn vertexMain(@builtin(vertex_index) vertexIndex : u32) -> VertexOutput {
28
+ var output : VertexOutput;
29
+ output.texCoord = pos[vertexIndex] * vec2<f32>(0.5, -0.5) + vec2<f32>(0.5);
30
+ output.position = vec4<f32>(pos[vertexIndex], 0.0, 1.0);
31
+ return output;
32
+ }
33
+
34
+ @group(0) @binding(0) var imgSampler : sampler;
35
+ @group(0) @binding(1) var img : texture_2d<f32>;
36
+
37
+ @fragment
38
+ fn fragmentMain(@location(0) texCoord : vec2<f32>) -> @location(0) vec4<f32> {
39
+ return textureSample(img, imgSampler, texCoord);
40
+ }
41
+ `})),t=this.device.createRenderPipeline({layout:"auto",vertex:{module:this.mipmapShaderModule,entryPoint:"vertexMain"},fragment:{module:this.mipmapShaderModule,entryPoint:"fragmentMain",targets:[{format:e}]}}),this.pipelines[e]=t),t}generateMipmap(e){const t=this._getMipmapPipeline(e.format);if(e.dimension==="3d"||e.dimension==="1d")throw new Error("Generating mipmaps for non-2d textures is currently unsupported!");let r=e;const s=e.depthOrArrayLayers||1,i=e.usage&GPUTextureUsage.RENDER_ATTACHMENT;if(!i){const u={size:{width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:s},format:e.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_SRC|GPUTextureUsage.RENDER_ATTACHMENT,mipLevelCount:e.mipLevelCount-1};r=this.device.createTexture(u)}const n=this.device.createCommandEncoder({}),o=t.getBindGroupLayout(0);for(let u=0;u<s;++u){let c=e.createView({baseMipLevel:0,mipLevelCount:1,dimension:"2d",baseArrayLayer:u,arrayLayerCount:1}),f=i?1:0;for(let h=1;h<e.mipLevelCount;++h){const p=r.createView({baseMipLevel:f++,mipLevelCount:1,dimension:"2d",baseArrayLayer:u,arrayLayerCount:1}),d=n.beginRenderPass({colorAttachments:[{view:p,storeOp:"store",loadOp:"clear",clearValue:{r:0,g:0,b:0,a:0}}]}),g=this.device.createBindGroup({layout:o,entries:[{binding:0,resource:this.sampler},{binding:1,resource:c}]});d.setPipeline(t),d.setBindGroup(0,g),d.draw(3,1,0,0),d.end(),c=p}}if(!i){const u={width:Math.ceil(e.width/2),height:Math.ceil(e.height/2),depthOrArrayLayers:s};for(let c=1;c<e.mipLevelCount;++c)n.copyTextureToTexture({texture:r,mipLevel:c-1},{texture:e,mipLevel:c},u),u.width=Math.ceil(u.width/2),u.height=Math.ceil(u.height/2)}return this.device.queue.submit([n.finish()]),i||r.destroy(),e}}class Ke{constructor(e){this.textureView=null,this.gpuTexture=e}destroy(){this.gpuTexture.destroy(),this.textureView=null,this.gpuTexture=null}}class se{constructor(e){this._gpuSamplers=Object.create(null),this._bindGroupHash=Object.create(null),this._renderer=e,e.gc.addCollection(this,"_bindGroupHash","hash"),this._managedTextures=new D({renderer:e,type:"resource",onUnload:this.onSourceUnload.bind(this),name:"gpuTextureSource"});const t={image:re,buffer:Ie,video:Ne,compressed:He};this._uploads={...t,cube:Ve(t)}}get managedTextures(){return Object.values(this._managedTextures.items)}contextChange(e){this._gpu=e}initSource(e){var t;return((t=e._gpuData[this._renderer.uid])==null?void 0:t.gpuTexture)||this._initSource(e)}_initSource(e){if(e.autoGenerateMipmaps){const c=Math.max(e.pixelWidth,e.pixelHeight);e.mipLevelCount=Math.floor(Math.log2(c))+1}let t=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST;e.uploadMethodId!=="compressed"&&(t|=GPUTextureUsage.RENDER_ATTACHMENT,t|=GPUTextureUsage.COPY_SRC);const r=te[e.format]||{blockWidth:1,blockHeight:1},s=Math.ceil(e.pixelWidth/r.blockWidth)*r.blockWidth,i=Math.ceil(e.pixelHeight/r.blockHeight)*r.blockHeight,n={label:e.label,size:{width:s,height:i,depthOrArrayLayers:e.arrayLayerCount},format:e.format,sampleCount:e.sampleCount,mipLevelCount:e.mipLevelCount,dimension:e.dimension,usage:t},o=this._gpu.device.createTexture(n);return e._gpuData[this._renderer.uid]=new Ke(o),this._managedTextures.add(e)&&(e.on("update",this.onSourceUpdate,this),e.on("resize",this.onSourceResize,this),e.on("updateMipmaps",this.onUpdateMipmaps,this)),this.onSourceUpdate(e),o}onSourceUpdate(e){const t=this.getGpuSource(e);t&&(this._uploads[e.uploadMethodId]&&this._uploads[e.uploadMethodId].upload(e,t,this._gpu),e.autoGenerateMipmaps&&e.mipLevelCount>1&&this.onUpdateMipmaps(e))}onUpdateMipmaps(e){this._mipmapGenerator||(this._mipmapGenerator=new je(this._gpu.device));const t=this.getGpuSource(e);this._mipmapGenerator.generateMipmap(t)}onSourceUnload(e){e.off("update",this.onSourceUpdate,this),e.off("resize",this.onSourceResize,this),e.off("updateMipmaps",this.onUpdateMipmaps,this)}onSourceResize(e){e._gcLastUsed=this._renderer.gc.now;const t=e._gpuData[this._renderer.uid],r=t==null?void 0:t.gpuTexture;r?(r.width!==e.pixelWidth||r.height!==e.pixelHeight)&&(t.destroy(),this._bindGroupHash[e.uid]=null,e._gpuData[this._renderer.uid]=null,this.initSource(e)):this.initSource(e)}_initSampler(e){return this._gpuSamplers[e._resourceId]=this._gpu.device.createSampler(e),this._gpuSamplers[e._resourceId]}getGpuSampler(e){return this._gpuSamplers[e._resourceId]||this._initSampler(e)}getGpuSource(e){var t;return e._gcLastUsed=this._renderer.gc.now,((t=e._gpuData[this._renderer.uid])==null?void 0:t.gpuTexture)||this.initSource(e)}getTextureBindGroup(e){return this._bindGroupHash[e.uid]||this._createTextureBindGroup(e)}_createTextureBindGroup(e){const t=e.source;return this._bindGroupHash[e.uid]=new k({0:t,1:t.style,2:new z({uTextureMatrix:{type:"mat3x3<f32>",value:e.textureMatrix.mapCoord}})}),this._bindGroupHash[e.uid]}getTextureView(e){const t=e.source;t._gcLastUsed=this._renderer.gc.now;let r=t._gpuData[this._renderer.uid];return r||(this.initSource(t),r=t._gpuData[this._renderer.uid]),r.textureView||(r.textureView=r.gpuTexture.createView({dimension:t.viewDimension})),r.textureView}generateCanvas(e){const t=this._renderer,r=t.gpu.device.createCommandEncoder(),s=B.get().createCanvas();s.width=e.source.pixelWidth,s.height=e.source.pixelHeight;const i=s.getContext("webgpu");return i.configure({device:t.gpu.device,usage:GPUTextureUsage.COPY_DST|GPUTextureUsage.COPY_SRC,format:B.get().getNavigator().gpu.getPreferredCanvasFormat(),alphaMode:"premultiplied"}),r.copyTextureToTexture({texture:t.texture.getGpuSource(e.source),origin:{x:0,y:0}},{texture:i.getCurrentTexture()},{width:s.width,height:s.height}),t.gpu.device.queue.submit([r.finish()]),s}getPixels(e){const t=this.generateCanvas(e),r=M.getOptimalCanvasAndContext(t.width,t.height),s=r.context;s.drawImage(t,0,0);const{width:i,height:n}=t,o=s.getImageData(0,0,i,n),u=new Uint8ClampedArray(o.data.buffer);return M.returnCanvasAndContext(r),{pixels:u,width:i,height:n}}destroy(){this._managedTextures.destroy();for(const e of Object.keys(this._bindGroupHash)){const t=Number(e),r=this._bindGroupHash[t];r==null||r.destroy()}this._renderer=null,this._gpu=null,this._mipmapGenerator=null,this._gpuSamplers=null,this._bindGroupHash=null}}se.extension={type:[l.WebGPUSystem],name:"texture"};class ie{constructor(){this._maxTextures=0}contextChange(e){const t=new z({uTransformMatrix:{value:new F,type:"mat3x3<f32>"},uColor:{value:new Float32Array([1,1,1,1]),type:"vec4<f32>"},uRound:{value:0,type:"f32"}});this._maxTextures=e.limits.maxBatchableTextures;const r=O({name:"graphics",bits:[fe,ge(this._maxTextures),me,I]});this.shader=new W({gpuProgram:r,resources:{localUniforms:t}})}execute(e,t){const r=t.context,s=r.customShader||this.shader,i=e.renderer,n=i.graphicsContext,{batcher:o,instructions:u}=n.getContextRenderData(r),c=i.encoder;c.setGeometry(o.geometry,s.gpuProgram);const f=i.globalUniforms.bindGroup;c.setBindGroup(0,f,s.gpuProgram);const h=i.renderPipes.uniformBatch.getUniformBindGroup(s.resources.localUniforms,!0);c.setBindGroup(2,h,s.gpuProgram);const p=u.instructions;let d=null;for(let g=0;g<u.instructionSize;g++){const m=p[g];if(m.topology!==d&&(d=m.topology,c.setPipelineFromGeometryProgramAndState(o.geometry,s.gpuProgram,e.state,m.topology)),s.groups[1]=m.bindGroup,!m.gpuBindGroup){const x=m.textures;m.bindGroup=A(x.textures,x.count,this._maxTextures),m.gpuBindGroup=i.bindGroup.getBindGroup(m.bindGroup,s.gpuProgram,1)}c.setBindGroup(1,m.bindGroup,s.gpuProgram),c.renderPassEncoder.drawIndexed(m.size,1,m.start)}}destroy(){this.shader.destroy(!1),this.shader=null}}ie.extension={type:[l.WebGPUPipesAdaptor],name:"graphics"};class ne{init(){const e=O({name:"mesh",bits:[_e,Ce,I]});this._shader=new W({gpuProgram:e,resources:{uTexture:R.EMPTY._source,uSampler:R.EMPTY._source.style,textureUniforms:{uTextureMatrix:{type:"mat3x3<f32>",value:new F}}}})}execute(e,t){const r=e.renderer;let s=t._shader;if(!s)s=this._shader,s.groups[2]=r.texture.getTextureBindGroup(t.texture);else if(!s.gpuProgram){v("Mesh shader has no gpuProgram",t.shader);return}const i=s.gpuProgram;if(i.autoAssignGlobalUniforms&&(s.groups[0]=r.globalUniforms.bindGroup),i.autoAssignLocalUniforms){const n=e.localUniforms;s.groups[1]=r.renderPipes.uniformBatch.getUniformBindGroup(n,!0)}r.encoder.draw({geometry:t._geometry,shader:s,state:t.state})}destroy(){this._shader.destroy(!1),this._shader=null}}ne.extension={type:[l.WebGPUPipesAdaptor],name:"mesh"};const qe=[...Ue,$,K,U,q,N,se,Q,J,ee,Z,j,Y,V],Ye=[...we,X],$e=[H,ne,ie],oe=[],ae=[],ue=[];S.handleByNamedList(l.WebGPUSystem,oe);S.handleByNamedList(l.WebGPUPipes,ae);S.handleByNamedList(l.WebGPUPipesAdaptor,ue);S.add(...qe,...Ye,...$e);class it extends be{constructor(){const e={name:"webgpu",type:ye.WEBGPU,systems:oe,renderPipes:ae,renderPipeAdaptors:ue};super(e)}}export{it as WebGPURenderer};
@@ -0,0 +1,14 @@
1
+ import{n as S,o as U,r as R,F as k,p as E,q as w,U as F,s as T,E as H,w as _,P as L,t as u,x as b,y as x}from"./index.nS-neZH_.js";import"./webworkerAll.BXgPGAoF.js";import"./framework.CBLqO2Q1.js";import"./mapValues.D2X8cRgC.js";import"./theme.B9FcKggM.js";const X=9,D=100,Y=0,j=0,I=2,A=1,K=-1e3,N=-1e3,G=2,O=class B{constructor(e,t=S){this._mobileInfo=t,this.debug=!1,this._activateOnTab=!0,this._deactivateOnMouseMove=!0,this._isActive=!1,this._isMobileAccessibility=!1,this._div=null,this._pools={},this._renderId=0,this._children=[],this._androidUpdateCount=0,this._androidUpdateFrequency=500,this._isRunningTests=!1,this._boundOnKeyDown=this._onKeyDown.bind(this),this._boundOnMouseMove=this._onMouseMove.bind(this),this._hookDiv=null,(t.tablet||t.phone)&&this._createTouchHook(),this._renderer=e}get isActive(){return this._isActive}get isMobileAccessibility(){return this._isMobileAccessibility}get hookDiv(){return this._hookDiv}get div(){return this._div}_createTouchHook(){const e=document.createElement("button");e.style.width=`${A}px`,e.style.height=`${A}px`,e.style.position="absolute",e.style.top=`${K}px`,e.style.left=`${N}px`,e.style.zIndex=G.toString(),e.style.backgroundColor="#FF0000",e.title="select to enable accessibility for this content",e.addEventListener("focus",()=>{this._isMobileAccessibility=!0,this._activate(),this._destroyTouchHook()}),document.body.appendChild(e),this._hookDiv=e}_destroyTouchHook(){this._hookDiv&&(document.body.removeChild(this._hookDiv),this._hookDiv=null)}_activate(){if(this._isActive)return;this._isActive=!0,this._div||(this._div=document.createElement("div"),this._div.style.position="absolute",this._div.style.top=`${Y}px`,this._div.style.left=`${j}px`,this._div.style.pointerEvents="none",this._div.style.zIndex=I.toString(),this._canvasObserver=new U({domElement:this._div,renderer:this._renderer})),this._activateOnTab&&globalThis.addEventListener("keydown",this._boundOnKeyDown,!1),this._deactivateOnMouseMove&&globalThis.document.addEventListener("mousemove",this._boundOnMouseMove,!0);const e=this._renderer.view.canvas;if(e.parentNode)this._canvasObserver.ensureAttached(),this._initAccessibilitySetup();else{const t=new MutationObserver(()=>{e.parentNode&&(t.disconnect(),this._canvasObserver.ensureAttached(),this._initAccessibilitySetup())});t.observe(document.body,{childList:!0,subtree:!0})}}_initAccessibilitySetup(){this._renderer.runners.postrender.add(this),this._renderer.lastObjectRendered&&this._updateAccessibleObjects(this._renderer.lastObjectRendered)}_deactivate(){var e,t;if(!(!this._isActive||this._isMobileAccessibility)){this._isActive=!1,globalThis.document.removeEventListener("mousemove",this._boundOnMouseMove,!0),this._activateOnTab&&globalThis.addEventListener("keydown",this._boundOnKeyDown,!1),this._renderer.runners.postrender.remove(this);for(const i of this._children)(e=i._accessibleDiv)!=null&&e.parentNode&&(i._accessibleDiv.parentNode.removeChild(i._accessibleDiv),i._accessibleDiv=null),i._accessibleActive=!1;for(const i in this._pools)this._pools[i].forEach(s=>{s.parentNode&&s.parentNode.removeChild(s)}),delete this._pools[i];(t=this._div)!=null&&t.parentNode&&this._div.parentNode.removeChild(this._div),this._pools={},this._children=[]}}_updateAccessibleObjects(e){if(!e.visible||!e.accessibleChildren)return;e.accessible&&(e._accessibleActive||this._addChild(e),e._renderId=this._renderId);const t=e.children;if(t)for(let i=0;i<t.length;i++)this._updateAccessibleObjects(t[i])}init(e){const i={accessibilityOptions:{...B.defaultOptions,...(e==null?void 0:e.accessibilityOptions)||{}}};this.debug=i.accessibilityOptions.debug,this._activateOnTab=i.accessibilityOptions.activateOnTab,this._deactivateOnMouseMove=i.accessibilityOptions.deactivateOnMouseMove,i.accessibilityOptions.enabledByDefault&&this._activate(),this._renderer.runners.postrender.remove(this)}postrender(){const e=performance.now();if(this._mobileInfo.android.device&&e<this._androidUpdateCount||(this._androidUpdateCount=e+this._androidUpdateFrequency,(!this._renderer.renderingToScreen||!this._renderer.view.canvas)&&!this._isRunningTests))return;const t=new Set;if(this._renderer.lastObjectRendered){this._updateAccessibleObjects(this._renderer.lastObjectRendered);for(const i of this._children)i._renderId===this._renderId&&t.add(this._children.indexOf(i))}for(let i=this._children.length-1;i>=0;i--){const n=this._children[i];t.has(i)||(n._accessibleDiv&&n._accessibleDiv.parentNode&&(n._accessibleDiv.parentNode.removeChild(n._accessibleDiv),this._getPool(n.accessibleType).push(n._accessibleDiv),n._accessibleDiv=null),n._accessibleActive=!1,R(this._children,i,1))}this._renderer.renderingToScreen&&this._canvasObserver.ensureAttached();for(let i=0;i<this._children.length;i++){const n=this._children[i];if(!n._accessibleActive||!n._accessibleDiv)continue;const s=n._accessibleDiv,o=n.hitArea||n.getBounds().rectangle;if(n.hitArea){const r=n.worldTransform;s.style.left=`${r.tx+o.x*r.a}px`,s.style.top=`${r.ty+o.y*r.d}px`,s.style.width=`${o.width*r.a}px`,s.style.height=`${o.height*r.d}px`}else this._capHitArea(o),s.style.left=`${o.x}px`,s.style.top=`${o.y}px`,s.style.width=`${o.width}px`,s.style.height=`${o.height}px`}this._renderId++}_updateDebugHTML(e){e.innerHTML=`type: ${e.type}</br> title : ${e.title}</br> tabIndex: ${e.tabIndex}`}_capHitArea(e){e.x<0&&(e.width+=e.x,e.x=0),e.y<0&&(e.height+=e.y,e.y=0);const{width:t,height:i}=this._renderer;e.x+e.width>t&&(e.width=t-e.x),e.y+e.height>i&&(e.height=i-e.y)}_addChild(e){let i=this._getPool(e.accessibleType).pop();i?(i.innerHTML="",i.removeAttribute("title"),i.removeAttribute("aria-label"),i.tabIndex=0):(e.accessibleType==="button"?i=document.createElement("button"):(i=document.createElement(e.accessibleType),i.style.cssText=`
2
+ color: transparent;
3
+ pointer-events: none;
4
+ padding: 0;
5
+ margin: 0;
6
+ border: 0;
7
+ outline: 0;
8
+ background: transparent;
9
+ box-sizing: border-box;
10
+ user-select: none;
11
+ -webkit-user-select: none;
12
+ -moz-user-select: none;
13
+ -ms-user-select: none;
14
+ `,e.accessibleText&&(i.innerText=e.accessibleText)),i.style.width=`${D}px`,i.style.height=`${D}px`,i.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",i.style.position="absolute",i.style.zIndex=I.toString(),i.style.borderStyle="none",navigator.userAgent.toLowerCase().includes("chrome")?i.setAttribute("aria-live","off"):i.setAttribute("aria-live","polite"),navigator.userAgent.match(/rv:.*Gecko\//)?i.setAttribute("aria-relevant","additions"):i.setAttribute("aria-relevant","text"),i.addEventListener("click",this._onClick.bind(this)),i.addEventListener("focus",this._onFocus.bind(this)),i.addEventListener("focusout",this._onFocusOut.bind(this))),i.style.pointerEvents=e.accessiblePointerEvents,i.type=e.accessibleType,e.accessibleTitle&&e.accessibleTitle!==null?i.title=e.accessibleTitle:(!e.accessibleHint||e.accessibleHint===null)&&(i.title=`container ${e.tabIndex}`),e.accessibleHint&&e.accessibleHint!==null&&i.setAttribute("aria-label",e.accessibleHint),e.interactive?i.tabIndex=e.tabIndex:i.tabIndex=0,this.debug&&this._updateDebugHTML(i),e._accessibleActive=!0,e._accessibleDiv=i,i.container=e,this._children.push(e),this._div.appendChild(e._accessibleDiv)}_dispatchEvent(e,t){const{container:i}=e.target,n=this._renderer.events.rootBoundary,s=Object.assign(new k(n),{target:i});n.rootTarget=this._renderer.lastObjectRendered,t.forEach(o=>n.dispatchEvent(s,o))}_onClick(e){this._dispatchEvent(e,["click","pointertap","tap"])}_onFocus(e){e.target.getAttribute("aria-live")||e.target.setAttribute("aria-live","assertive"),this._dispatchEvent(e,["mouseover"])}_onFocusOut(e){e.target.getAttribute("aria-live")||e.target.setAttribute("aria-live","polite"),this._dispatchEvent(e,["mouseout"])}_onKeyDown(e){e.keyCode!==X||!this._activateOnTab||this._activate()}_onMouseMove(e){e.movementX===0&&e.movementY===0||this._deactivate()}destroy(){var e;this._deactivate(),this._destroyTouchHook(),(e=this._canvasObserver)==null||e.destroy(),this._canvasObserver=null,this._div=null,this._pools=null,this._children=null,this._renderer=null,this._hookDiv=null,globalThis.removeEventListener("keydown",this._boundOnKeyDown),this._boundOnKeyDown=null,globalThis.document.removeEventListener("mousemove",this._boundOnMouseMove,!0),this._boundOnMouseMove=null}setAccessibilityEnabled(e){e?this._activate():this._deactivate()}_getPool(e){return this._pools[e]||(this._pools[e]=[]),this._pools[e]}};O.extension={type:[E.WebGLSystem,E.WebGPUSystem],name:"accessibility"};O.defaultOptions={enabledByDefault:!1,debug:!1,activateOnTab:!0,deactivateOnMouseMove:!0};let W=O;const $={accessible:!1,accessibleTitle:null,accessibleHint:null,tabIndex:0,accessibleType:"button",accessibleText:null,accessiblePointerEvents:"auto",accessibleChildren:!0,_accessibleActive:!1,_accessibleDiv:null,_renderId:-1};class z{constructor(){this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}init(e){this.removeTickerListener(),this.events=e,this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}get pauseUpdate(){return this._pauseUpdate}set pauseUpdate(e){this._pauseUpdate=e}addTickerListener(){this._tickerAdded||!this.domElement||(w.system.add(this._tickerUpdate,this,F.INTERACTION),this._tickerAdded=!0)}removeTickerListener(){this._tickerAdded&&(w.system.remove(this._tickerUpdate,this),this._tickerAdded=!1)}pointerMoved(){this._didMove=!0}_update(){if(!this.domElement||this._pauseUpdate)return;if(this._didMove){this._didMove=!1;return}const e=this.events._rootPointerEvent;this.events.supportsTouchEvents&&e.pointerType==="touch"||globalThis.document.dispatchEvent(this.events.supportsPointerEvents?new PointerEvent("pointermove",{clientX:e.clientX,clientY:e.clientY,pointerType:e.pointerType,pointerId:e.pointerId}):new MouseEvent("mousemove",{clientX:e.clientX,clientY:e.clientY}))}_tickerUpdate(e){this._deltaTime+=e.deltaTime,!(this._deltaTime<this.interactionFrequency)&&(this._deltaTime=0,this._update())}destroy(){this.removeTickerListener(),this.events=null,this.domElement=null,this._deltaTime=0,this._didMove=!1,this._tickerAdded=!1,this._pauseUpdate=!0}}const m=new z;class y extends T{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}y.DOM_DELTA_PIXEL=0;y.DOM_DELTA_LINE=1;y.DOM_DELTA_PAGE=2;const Z=2048,V=new L,g=new L;class q{constructor(e){this.dispatch=new H,this.moveOnAll=!1,this.enableGlobalMoveEvents=!0,this.mappingState={trackingData:{}},this.eventPool=new Map,this._allInteractiveElements=[],this._hitElements=[],this._isPointerMoveEvent=!1,this.rootTarget=e,this.hitPruneFn=this.hitPruneFn.bind(this),this.hitTestFn=this.hitTestFn.bind(this),this.mapPointerDown=this.mapPointerDown.bind(this),this.mapPointerMove=this.mapPointerMove.bind(this),this.mapPointerOut=this.mapPointerOut.bind(this),this.mapPointerOver=this.mapPointerOver.bind(this),this.mapPointerUp=this.mapPointerUp.bind(this),this.mapPointerUpOutside=this.mapPointerUpOutside.bind(this),this.mapWheel=this.mapWheel.bind(this),this.mappingTable={},this.addEventMapping("pointerdown",this.mapPointerDown),this.addEventMapping("pointermove",this.mapPointerMove),this.addEventMapping("pointerout",this.mapPointerOut),this.addEventMapping("pointerleave",this.mapPointerOut),this.addEventMapping("pointerover",this.mapPointerOver),this.addEventMapping("pointerup",this.mapPointerUp),this.addEventMapping("pointerupoutside",this.mapPointerUpOutside),this.addEventMapping("wheel",this.mapWheel)}addEventMapping(e,t){this.mappingTable[e]||(this.mappingTable[e]=[]),this.mappingTable[e].push({fn:t,priority:0}),this.mappingTable[e].sort((i,n)=>i.priority-n.priority)}dispatchEvent(e,t){e.propagationStopped=!1,e.propagationImmediatelyStopped=!1,this.propagate(e,t),this.dispatch.emit(t||e.type,e)}mapEvent(e){if(!this.rootTarget)return;const t=this.mappingTable[e.type];if(t)for(let i=0,n=t.length;i<n;i++)t[i].fn(e);else _(`[EventBoundary]: Event mapping not defined for ${e.type}`)}hitTest(e,t){m.pauseUpdate=!0;const n=this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive",s=this[n](this.rootTarget,this.rootTarget.eventMode,V.set(e,t),this.hitTestFn,this.hitPruneFn);return s&&s[0]}propagate(e,t){if(!e.target)return;const i=e.composedPath();e.eventPhase=e.CAPTURING_PHASE;for(let n=0,s=i.length-1;n<s;n++)if(e.currentTarget=i[n],this.notifyTarget(e,t),e.propagationStopped||e.propagationImmediatelyStopped)return;if(e.eventPhase=e.AT_TARGET,e.currentTarget=e.target,this.notifyTarget(e,t),!(e.propagationStopped||e.propagationImmediatelyStopped)){e.eventPhase=e.BUBBLING_PHASE;for(let n=i.length-2;n>=0;n--)if(e.currentTarget=i[n],this.notifyTarget(e,t),e.propagationStopped||e.propagationImmediatelyStopped)return}}all(e,t,i=this._allInteractiveElements){if(i.length===0)return;e.eventPhase=e.BUBBLING_PHASE;const n=Array.isArray(t)?t:[t];for(let s=i.length-1;s>=0;s--)n.forEach(o=>{e.currentTarget=i[s],this.notifyTarget(e,o)})}propagationPath(e){const t=[e];for(let i=0;i<Z&&e!==this.rootTarget&&e.parent;i++){if(!e.parent)throw new Error("Cannot find propagation path to disconnected target");t.push(e.parent),e=e.parent}return t.reverse(),t}hitTestMoveRecursive(e,t,i,n,s,o=!1){let r=!1;if(this._interactivePrune(e))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(m.pauseUpdate=!1),e.interactiveChildren&&e.children){const v=e.children;for(let d=v.length-1;d>=0;d--){const a=v[d],f=this.hitTestMoveRecursive(a,this._isInteractive(t)?t:a.eventMode,i,n,s,o||s(e,i));if(f){if(f.length>0&&!f[f.length-1].parent)continue;const c=e.isInteractive();(f.length>0||c)&&(c&&this._allInteractiveElements.push(e),f.push(e)),this._hitElements.length===0&&(this._hitElements=f),r=!0}}}const h=this._isInteractive(t),p=e.isInteractive();return p&&p&&this._allInteractiveElements.push(e),o||this._hitElements.length>0?null:r?this._hitElements:h&&!s(e,i)&&n(e,i)?p?[e]:[]:null}hitTestRecursive(e,t,i,n,s){if(this._interactivePrune(e)||s(e,i))return null;if((e.eventMode==="dynamic"||t==="dynamic")&&(m.pauseUpdate=!1),e.interactiveChildren&&e.children){const h=e.children,p=i;for(let v=h.length-1;v>=0;v--){const d=h[v],a=this.hitTestRecursive(d,this._isInteractive(t)?t:d.eventMode,p,n,s);if(a){if(a.length>0&&!a[a.length-1].parent)continue;const f=e.isInteractive();return(a.length>0||f)&&a.push(e),a}}}const o=this._isInteractive(t),r=e.isInteractive();return o&&n(e,i)?r?[e]:[]:null}_isInteractive(e){return e==="static"||e==="dynamic"}_interactivePrune(e){return!e||!e.visible||!e.renderable||!e.measurable||e.eventMode==="none"||e.eventMode==="passive"&&!e.interactiveChildren}hitPruneFn(e,t){if(e.hitArea&&(e.worldTransform.applyInverse(t,g),!e.hitArea.contains(g.x,g.y)))return!0;if(e.effects&&e.effects.length)for(let i=0;i<e.effects.length;i++){const n=e.effects[i];if(n.containsPoint&&!n.containsPoint(t,this.hitTestFn))return!0}return!1}hitTestFn(e,t){return e.hitArea?!0:e!=null&&e.containsPoint?(e.worldTransform.applyInverse(t,g),e.containsPoint(g)):!1}notifyTarget(e,t){var s,o;if(!e.currentTarget.isInteractive())return;t??(t=e.type);const i=`on${t}`;(o=(s=e.currentTarget)[i])==null||o.call(s,e);const n=e.eventPhase===e.CAPTURING_PHASE||e.eventPhase===e.AT_TARGET?`${t}capture`:t;this._notifyListeners(e,n),e.eventPhase===e.AT_TARGET&&this._notifyListeners(e,t)}mapPointerDown(e){if(!(e instanceof u)){_("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.createPointerEvent(e);if(this.dispatchEvent(t,"pointerdown"),t.pointerType==="touch")this.dispatchEvent(t,"touchstart");else if(t.pointerType==="mouse"||t.pointerType==="pen"){const n=t.button===2;this.dispatchEvent(t,n?"rightdown":"mousedown")}const i=this.trackingData(e.pointerId);i.pressTargetsByButton[e.button]=t.composedPath(),this.freeEvent(t)}mapPointerMove(e){var h,p;if(!(e instanceof u)){_("EventBoundary cannot map a non-pointer event as a pointer event");return}this._allInteractiveElements.length=0,this._hitElements.length=0,this._isPointerMoveEvent=!0;const t=this.createPointerEvent(e);this._isPointerMoveEvent=!1;const i=t.pointerType==="mouse"||t.pointerType==="pen",n=this.trackingData(e.pointerId),s=this.findMountedTarget(n.overTargets);if(((h=n.overTargets)==null?void 0:h.length)>0&&s!==t.target){const v=e.type==="mousemove"?"mouseout":"pointerout",d=this.createPointerEvent(e,v,s);if(this.dispatchEvent(d,"pointerout"),i&&this.dispatchEvent(d,"mouseout"),!t.composedPath().includes(s)){const a=this.createPointerEvent(e,"pointerleave",s);for(a.eventPhase=a.AT_TARGET;a.target&&!t.composedPath().includes(a.target);)a.currentTarget=a.target,this.notifyTarget(a),i&&this.notifyTarget(a,"mouseleave"),a.target=a.target.parent;this.freeEvent(a)}this.freeEvent(d)}if(s!==t.target){const v=e.type==="mousemove"?"mouseover":"pointerover",d=this.clonePointerEvent(t,v);this.dispatchEvent(d,"pointerover"),i&&this.dispatchEvent(d,"mouseover");let a=s==null?void 0:s.parent;for(;a&&a!==this.rootTarget.parent&&a!==t.target;)a=a.parent;if(!a||a===this.rootTarget.parent){const c=this.clonePointerEvent(t,"pointerenter");for(c.eventPhase=c.AT_TARGET;c.target&&c.target!==s&&c.target!==this.rootTarget.parent;)c.currentTarget=c.target,this.notifyTarget(c),i&&this.notifyTarget(c,"mouseenter"),c.target=c.target.parent;this.freeEvent(c)}this.freeEvent(d)}const o=[],r=this.enableGlobalMoveEvents??!0;this.moveOnAll?o.push("pointermove"):this.dispatchEvent(t,"pointermove"),r&&o.push("globalpointermove"),t.pointerType==="touch"&&(this.moveOnAll?o.splice(1,0,"touchmove"):this.dispatchEvent(t,"touchmove"),r&&o.push("globaltouchmove")),i&&(this.moveOnAll?o.splice(1,0,"mousemove"):this.dispatchEvent(t,"mousemove"),r&&o.push("globalmousemove"),this.cursor=(p=t.target)==null?void 0:p.cursor),o.length>0&&this.all(t,o),this._allInteractiveElements.length=0,this._hitElements.length=0,n.overTargets=t.composedPath(),this.freeEvent(t)}mapPointerOver(e){var o;if(!(e instanceof u)){_("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),i=this.createPointerEvent(e),n=i.pointerType==="mouse"||i.pointerType==="pen";this.dispatchEvent(i,"pointerover"),n&&this.dispatchEvent(i,"mouseover"),i.pointerType==="mouse"&&(this.cursor=(o=i.target)==null?void 0:o.cursor);const s=this.clonePointerEvent(i,"pointerenter");for(s.eventPhase=s.AT_TARGET;s.target&&s.target!==this.rootTarget.parent;)s.currentTarget=s.target,this.notifyTarget(s),n&&this.notifyTarget(s,"mouseenter"),s.target=s.target.parent;t.overTargets=i.composedPath(),this.freeEvent(i),this.freeEvent(s)}mapPointerOut(e){if(!(e instanceof u)){_("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId);if(t.overTargets){const i=e.pointerType==="mouse"||e.pointerType==="pen",n=this.findMountedTarget(t.overTargets),s=this.createPointerEvent(e,"pointerout",n);this.dispatchEvent(s),i&&this.dispatchEvent(s,"mouseout");const o=this.createPointerEvent(e,"pointerleave",n);for(o.eventPhase=o.AT_TARGET;o.target&&o.target!==this.rootTarget.parent;)o.currentTarget=o.target,this.notifyTarget(o),i&&this.notifyTarget(o,"mouseleave"),o.target=o.target.parent;t.overTargets=null,this.freeEvent(s),this.freeEvent(o)}this.cursor=null}mapPointerUp(e){if(!(e instanceof u)){_("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=performance.now(),i=this.createPointerEvent(e);if(this.dispatchEvent(i,"pointerup"),i.pointerType==="touch")this.dispatchEvent(i,"touchend");else if(i.pointerType==="mouse"||i.pointerType==="pen"){const r=i.button===2;this.dispatchEvent(i,r?"rightup":"mouseup")}const n=this.trackingData(e.pointerId),s=this.findMountedTarget(n.pressTargetsByButton[e.button]);let o=s;if(s&&!i.composedPath().includes(s)){let r=s;for(;r&&!i.composedPath().includes(r);){if(i.currentTarget=r,this.notifyTarget(i,"pointerupoutside"),i.pointerType==="touch")this.notifyTarget(i,"touchendoutside");else if(i.pointerType==="mouse"||i.pointerType==="pen"){const h=i.button===2;this.notifyTarget(i,h?"rightupoutside":"mouseupoutside")}r=r.parent}delete n.pressTargetsByButton[e.button],o=r}if(o){const r=this.clonePointerEvent(i,"click");r.target=o,r.path=null,n.clicksByButton[e.button]||(n.clicksByButton[e.button]={clickCount:0,target:r.target,timeStamp:t});const h=n.clicksByButton[e.button];if(h.target===r.target&&t-h.timeStamp<200?++h.clickCount:h.clickCount=1,h.target=r.target,h.timeStamp=t,r.detail=h.clickCount,r.pointerType==="mouse"){const p=r.button===2;this.dispatchEvent(r,p?"rightclick":"click")}else r.pointerType==="touch"&&this.dispatchEvent(r,"tap");this.dispatchEvent(r,"pointertap"),this.freeEvent(r)}this.freeEvent(i)}mapPointerUpOutside(e){if(!(e instanceof u)){_("EventBoundary cannot map a non-pointer event as a pointer event");return}const t=this.trackingData(e.pointerId),i=this.findMountedTarget(t.pressTargetsByButton[e.button]),n=this.createPointerEvent(e);if(i){let s=i;for(;s;)n.currentTarget=s,this.notifyTarget(n,"pointerupoutside"),n.pointerType==="touch"?this.notifyTarget(n,"touchendoutside"):(n.pointerType==="mouse"||n.pointerType==="pen")&&this.notifyTarget(n,n.button===2?"rightupoutside":"mouseupoutside"),s=s.parent;delete t.pressTargetsByButton[e.button]}this.freeEvent(n)}mapWheel(e){if(!(e instanceof y)){_("EventBoundary cannot map a non-wheel event as a wheel event");return}const t=this.createWheelEvent(e);this.dispatchEvent(t),this.freeEvent(t)}findMountedTarget(e){if(!e)return null;let t=e[0];for(let i=1;i<e.length&&e[i].parent===t;i++)t=e[i];return t}createPointerEvent(e,t,i){const n=this.allocateEvent(u);return this.copyPointerData(e,n),this.copyMouseData(e,n),this.copyData(e,n),n.nativeEvent=e.nativeEvent,n.originalEvent=e,n.target=i??this.hitTest(n.global.x,n.global.y)??this._hitElements[0],typeof t=="string"&&(n.type=t),n}createWheelEvent(e){const t=this.allocateEvent(y);return this.copyWheelData(e,t),this.copyMouseData(e,t),this.copyData(e,t),t.nativeEvent=e.nativeEvent,t.originalEvent=e,t.target=this.hitTest(t.global.x,t.global.y),t}clonePointerEvent(e,t){const i=this.allocateEvent(u);return i.nativeEvent=e.nativeEvent,i.originalEvent=e.originalEvent,this.copyPointerData(e,i),this.copyMouseData(e,i),this.copyData(e,i),i.target=e.target,i.path=e.composedPath().slice(),i.type=t??i.type,i}copyWheelData(e,t){t.deltaMode=e.deltaMode,t.deltaX=e.deltaX,t.deltaY=e.deltaY,t.deltaZ=e.deltaZ}copyPointerData(e,t){e instanceof u&&t instanceof u&&(t.pointerId=e.pointerId,t.width=e.width,t.height=e.height,t.isPrimary=e.isPrimary,t.pointerType=e.pointerType,t.pressure=e.pressure,t.tangentialPressure=e.tangentialPressure,t.tiltX=e.tiltX,t.tiltY=e.tiltY,t.twist=e.twist)}copyMouseData(e,t){e instanceof T&&t instanceof T&&(t.altKey=e.altKey,t.button=e.button,t.buttons=e.buttons,t.client.copyFrom(e.client),t.ctrlKey=e.ctrlKey,t.metaKey=e.metaKey,t.movement.copyFrom(e.movement),t.screen.copyFrom(e.screen),t.shiftKey=e.shiftKey,t.global.copyFrom(e.global))}copyData(e,t){t.isTrusted=e.isTrusted,t.srcElement=e.srcElement,t.timeStamp=performance.now(),t.type=e.type,t.detail=e.detail,t.view=e.view,t.which=e.which,t.layer.copyFrom(e.layer),t.page.copyFrom(e.page)}trackingData(e){return this.mappingState.trackingData[e]||(this.mappingState.trackingData[e]={pressTargetsByButton:{},clicksByButton:{},overTarget:null}),this.mappingState.trackingData[e]}allocateEvent(e){this.eventPool.has(e)||this.eventPool.set(e,[]);const t=this.eventPool.get(e).pop()||new e(this);return t.eventPhase=t.NONE,t.currentTarget=null,t.defaultPrevented=!1,t.path=null,t.target=null,t}freeEvent(e){if(e.manager!==this)throw new Error("It is illegal to free an event not managed by this EventBoundary!");const t=e.constructor;this.eventPool.has(t)||this.eventPool.set(t,[]),this.eventPool.get(t).push(e)}_notifyListeners(e,t){const i=e.currentTarget._events[t];if(i)if("fn"in i)i.once&&e.currentTarget.removeListener(t,i.fn,void 0,!0),i.fn.call(i.context,e);else for(let n=0,s=i.length;n<s&&!e.propagationImmediatelyStopped;n++)i[n].once&&e.currentTarget.removeListener(t,i[n].fn,void 0,!0),i[n].fn.call(i[n].context,e)}}const J=1,Q={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},M=class P{constructor(e){this.supportsTouchEvents="ontouchstart"in globalThis,this.supportsPointerEvents=!!globalThis.PointerEvent,this.domElement=null,this.resolution=1,this.renderer=e,this.rootBoundary=new q(null),m.init(this),this.autoPreventDefault=!0,this._eventsAdded=!1,this._rootPointerEvent=new u(null),this._rootWheelEvent=new y(null),this.cursorStyles={default:"inherit",pointer:"pointer"},this.features=new Proxy({...P.defaultEventFeatures},{set:(t,i,n)=>(i==="globalMove"&&(this.rootBoundary.enableGlobalMoveEvents=n),t[i]=n,!0)}),this._onPointerDown=this._onPointerDown.bind(this),this._onPointerMove=this._onPointerMove.bind(this),this._onPointerUp=this._onPointerUp.bind(this),this._onPointerOverOut=this._onPointerOverOut.bind(this),this.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(e){const{canvas:t,resolution:i}=this.renderer;this.setTargetElement(t),this.resolution=i,P._defaultEventMode=e.eventMode??"passive",Object.assign(this.features,e.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(e){this.resolution=e}destroy(){m.destroy(),this.setTargetElement(null),this.renderer=null,this._currentCursor=null}setCursor(e){e||(e="default");let t=!0;if(globalThis.OffscreenCanvas&&this.domElement instanceof OffscreenCanvas&&(t=!1),this._currentCursor===e)return;this._currentCursor=e;const i=this.cursorStyles[e];if(i)switch(typeof i){case"string":t&&(this.domElement.style.cursor=i);break;case"function":i(e);break;case"object":t&&Object.assign(this.domElement.style,i);break}else t&&typeof e=="string"&&!Object.prototype.hasOwnProperty.call(this.cursorStyles,e)&&(this.domElement.style.cursor=e)}get pointer(){return this._rootPointerEvent}_onPointerDown(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const t=this._normalizeToPointerData(e);this.autoPreventDefault&&t[0].isNormalized&&(e.cancelable||!("cancelable"in e))&&e.preventDefault();for(let i=0,n=t.length;i<n;i++){const s=t[i],o=this._bootstrapEvent(this._rootPointerEvent,s);this.rootBoundary.mapEvent(o)}this.setCursor(this.rootBoundary.cursor)}_onPointerMove(e){if(!this.features.move)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,m.pointerMoved();const t=this._normalizeToPointerData(e);for(let i=0,n=t.length;i<n;i++){const s=this._bootstrapEvent(this._rootPointerEvent,t[i]);this.rootBoundary.mapEvent(s)}this.setCursor(this.rootBoundary.cursor)}_onPointerUp(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;let t=e.target;e.composedPath&&e.composedPath().length>0&&(t=e.composedPath()[0]);const i=t!==this.domElement?"outside":"",n=this._normalizeToPointerData(e);for(let s=0,o=n.length;s<o;s++){const r=this._bootstrapEvent(this._rootPointerEvent,n[s]);r.type+=i,this.rootBoundary.mapEvent(r)}this.setCursor(this.rootBoundary.cursor)}_onPointerOverOut(e){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const t=this._normalizeToPointerData(e);for(let i=0,n=t.length;i<n;i++){const s=this._bootstrapEvent(this._rootPointerEvent,t[i]);this.rootBoundary.mapEvent(s)}this.setCursor(this.rootBoundary.cursor)}onWheel(e){if(!this.features.wheel)return;const t=this.normalizeWheelEvent(e);this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,this.rootBoundary.mapEvent(t)}setTargetElement(e){this._removeEvents(),this.domElement=e,m.domElement=e,this._addEvents()}_addEvents(){if(this._eventsAdded||!this.domElement)return;m.addTickerListener();const e=this.domElement.style;e&&(globalThis.navigator.msPointerEnabled?(e.msContentZooming="none",e.msTouchAction="none"):this.supportsPointerEvents&&(e.touchAction="none")),this.supportsPointerEvents?(globalThis.document.addEventListener("pointermove",this._onPointerMove,!0),this.domElement.addEventListener("pointerdown",this._onPointerDown,!0),this.domElement.addEventListener("pointerleave",this._onPointerOverOut,!0),this.domElement.addEventListener("pointerover",this._onPointerOverOut,!0),globalThis.addEventListener("pointerup",this._onPointerUp,!0)):(globalThis.document.addEventListener("mousemove",this._onPointerMove,!0),this.domElement.addEventListener("mousedown",this._onPointerDown,!0),this.domElement.addEventListener("mouseout",this._onPointerOverOut,!0),this.domElement.addEventListener("mouseover",this._onPointerOverOut,!0),globalThis.addEventListener("mouseup",this._onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.addEventListener("touchstart",this._onPointerDown,!0),this.domElement.addEventListener("touchend",this._onPointerUp,!0),this.domElement.addEventListener("touchmove",this._onPointerMove,!0))),this.domElement.addEventListener("wheel",this.onWheel,{passive:!0,capture:!0}),this._eventsAdded=!0}_removeEvents(){if(!this._eventsAdded||!this.domElement)return;m.removeTickerListener();const e=this.domElement.style;e&&(globalThis.navigator.msPointerEnabled?(e.msContentZooming="",e.msTouchAction=""):this.supportsPointerEvents&&(e.touchAction="")),this.supportsPointerEvents?(globalThis.document.removeEventListener("pointermove",this._onPointerMove,!0),this.domElement.removeEventListener("pointerdown",this._onPointerDown,!0),this.domElement.removeEventListener("pointerleave",this._onPointerOverOut,!0),this.domElement.removeEventListener("pointerover",this._onPointerOverOut,!0),globalThis.removeEventListener("pointerup",this._onPointerUp,!0)):(globalThis.document.removeEventListener("mousemove",this._onPointerMove,!0),this.domElement.removeEventListener("mousedown",this._onPointerDown,!0),this.domElement.removeEventListener("mouseout",this._onPointerOverOut,!0),this.domElement.removeEventListener("mouseover",this._onPointerOverOut,!0),globalThis.removeEventListener("mouseup",this._onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.removeEventListener("touchstart",this._onPointerDown,!0),this.domElement.removeEventListener("touchend",this._onPointerUp,!0),this.domElement.removeEventListener("touchmove",this._onPointerMove,!0))),this.domElement.removeEventListener("wheel",this.onWheel,!0),this.domElement=null,this._eventsAdded=!1}mapPositionToPoint(e,t,i){const n=this.domElement.isConnected?this.domElement.getBoundingClientRect():{width:this.domElement.width,height:this.domElement.height,left:0,top:0},s=1/this.resolution;e.x=(t-n.left)*(this.domElement.width/n.width)*s,e.y=(i-n.top)*(this.domElement.height/n.height)*s}_normalizeToPointerData(e){const t=[];if(this.supportsTouchEvents&&e instanceof TouchEvent)for(let i=0,n=e.changedTouches.length;i<n;i++){const s=e.changedTouches[i];typeof s.button>"u"&&(s.button=0),typeof s.buttons>"u"&&(s.buttons=1),typeof s.isPrimary>"u"&&(s.isPrimary=e.touches.length===1&&e.type==="touchstart"),typeof s.width>"u"&&(s.width=s.radiusX||1),typeof s.height>"u"&&(s.height=s.radiusY||1),typeof s.tiltX>"u"&&(s.tiltX=0),typeof s.tiltY>"u"&&(s.tiltY=0),typeof s.pointerType>"u"&&(s.pointerType="touch"),typeof s.pointerId>"u"&&(s.pointerId=s.identifier||0),typeof s.pressure>"u"&&(s.pressure=s.force||.5),typeof s.twist>"u"&&(s.twist=0),typeof s.tangentialPressure>"u"&&(s.tangentialPressure=0),typeof s.layerX>"u"&&(s.layerX=s.offsetX=s.clientX),typeof s.layerY>"u"&&(s.layerY=s.offsetY=s.clientY),s.isNormalized=!0,s.type=e.type,t.push(s)}else if(!globalThis.MouseEvent||e instanceof MouseEvent&&(!this.supportsPointerEvents||!(e instanceof globalThis.PointerEvent))){const i=e;typeof i.isPrimary>"u"&&(i.isPrimary=!0),typeof i.width>"u"&&(i.width=1),typeof i.height>"u"&&(i.height=1),typeof i.tiltX>"u"&&(i.tiltX=0),typeof i.tiltY>"u"&&(i.tiltY=0),typeof i.pointerType>"u"&&(i.pointerType="mouse"),typeof i.pointerId>"u"&&(i.pointerId=J),typeof i.pressure>"u"&&(i.pressure=.5),typeof i.twist>"u"&&(i.twist=0),typeof i.tangentialPressure>"u"&&(i.tangentialPressure=0),i.isNormalized=!0,t.push(i)}else t.push(e);return t}normalizeWheelEvent(e){const t=this._rootWheelEvent;return this._transferMouseData(t,e),t.deltaX=e.deltaX,t.deltaY=e.deltaY,t.deltaZ=e.deltaZ,t.deltaMode=e.deltaMode,this.mapPositionToPoint(t.screen,e.clientX,e.clientY),t.global.copyFrom(t.screen),t.offset.copyFrom(t.screen),t.nativeEvent=e,t.type=e.type,t}_bootstrapEvent(e,t){return e.originalEvent=null,e.nativeEvent=t,e.pointerId=t.pointerId,e.width=t.width,e.height=t.height,e.isPrimary=t.isPrimary,e.pointerType=t.pointerType,e.pressure=t.pressure,e.tangentialPressure=t.tangentialPressure,e.tiltX=t.tiltX,e.tiltY=t.tiltY,e.twist=t.twist,this._transferMouseData(e,t),this.mapPositionToPoint(e.screen,t.clientX,t.clientY),e.global.copyFrom(e.screen),e.offset.copyFrom(e.screen),e.isTrusted=t.isTrusted,e.type==="pointerleave"&&(e.type="pointerout"),e.type.startsWith("mouse")&&(e.type=e.type.replace("mouse","pointer")),e.type.startsWith("touch")&&(e.type=Q[e.type]||e.type),e}_transferMouseData(e,t){e.isTrusted=t.isTrusted,e.srcElement=t.srcElement,e.timeStamp=performance.now(),e.type=t.type,e.altKey=t.altKey,e.button=t.button,e.buttons=t.buttons,e.client.x=t.clientX,e.client.y=t.clientY,e.ctrlKey=t.ctrlKey,e.metaKey=t.metaKey,e.movement.x=t.movementX,e.movement.y=t.movementY,e.page.x=t.pageX,e.page.y=t.pageY,e.relatedTarget=null,e.shiftKey=t.shiftKey}};M.extension={name:"events",type:[E.WebGLSystem,E.CanvasSystem,E.WebGPUSystem],priority:-1};M.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let C=M;const ee={onclick:null,onmousedown:null,onmouseenter:null,onmouseleave:null,onmousemove:null,onglobalmousemove:null,onmouseout:null,onmouseover:null,onmouseup:null,onmouseupoutside:null,onpointercancel:null,onpointerdown:null,onpointerenter:null,onpointerleave:null,onpointermove:null,onglobalpointermove:null,onpointerout:null,onpointerover:null,onpointertap:null,onpointerup:null,onpointerupoutside:null,onrightclick:null,onrightdown:null,onrightup:null,onrightupoutside:null,ontap:null,ontouchcancel:null,ontouchend:null,ontouchendoutside:null,ontouchmove:null,onglobaltouchmove:null,ontouchstart:null,onwheel:null,get interactive(){return this.eventMode==="dynamic"||this.eventMode==="static"},set interactive(l){this.eventMode=l?"static":"passive"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??C.defaultEventMode},set eventMode(l){this._internalEventMode=l},isInteractive(){return this.eventMode==="static"||this.eventMode==="dynamic"},interactiveChildren:!0,hitArea:null,addEventListener(l,e,t){const i=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,n=typeof t=="object"?t.signal:void 0,s=typeof t=="object"?t.once===!0:!1,o=typeof e=="function"?void 0:e;l=i?`${l}capture`:l;const r=typeof e=="function"?e:e.handleEvent,h=this;n&&n.addEventListener("abort",()=>{h.off(l,r,o)}),s?h.once(l,r,o):h.on(l,r,o)},removeEventListener(l,e,t){const i=typeof t=="boolean"&&t||typeof t=="object"&&t.capture,n=typeof e=="function"?void 0:e;l=i?`${l}capture`:l,e=typeof e=="function"?e:e.handleEvent,this.off(l,e,n)},dispatchEvent(l){if(!(l instanceof k))throw new Error("Container cannot propagate events outside of the Federated Events API");return l.defaultPrevented=!1,l.path=null,l.target=this,l.manager.dispatchEvent(l),!l.defaultPrevented}};b.add(W);b.mixin(x,$);b.add(C);b.mixin(x,ee);