@needle-tools/engine 3.45.2-beta.1 → 3.45.2-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/needle-engine.js +11 -7
- package/dist/needle-engine.light.js +11 -7
- package/dist/needle-engine.light.min.js +28 -28
- package/dist/needle-engine.light.umd.cjs +4 -4
- package/dist/needle-engine.min.js +4 -4
- package/dist/needle-engine.umd.cjs +4 -4
- package/lib/engine/engine_input.d.ts +5 -0
- package/lib/engine/engine_input.js +7 -0
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_physics.js +3 -0
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/xr/NeedleXRSession.js +1 -1
- package/lib/engine/xr/NeedleXRSession.js.map +1 -1
- package/package.json +2 -2
- package/plugins/common/license.cjs +1 -1
- package/src/engine/engine_input.ts +9 -0
- package/src/engine/engine_physics.ts +2 -0
- package/src/engine/xr/NeedleXRSession.ts +1 -1
|
@@ -4344,7 +4344,7 @@ Open this page to get the console: `+A.toString())}const g=In()||bk()&&ae();if((
|
|
|
4344
4344
|
#__vconsole .vc-mask {
|
|
4345
4345
|
overflow: hidden;
|
|
4346
4346
|
}
|
|
4347
|
-
`,As==null||As.prepend(t),g===!0&&yJ()<=0&&h3(),console.log("🌵 Debug console has loaded")}},A.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(A)}function JgA(){const g=new VConsole.VConsolePlugin("needle-console","🌵 Inspect glTF"),A=()=>document.querySelector("#__vc_plug_"+g._id+" iframe");return g.on("renderTab",function(e){const t=globalThis["needle:codegen_files"];if(!t||t.length===0)return;let i=globalThis["needle:codegen_files"][0];const I=i.indexOf("?");I>-1&&(i=i.substring(0,I));const s=location.protocol+"//"+location.host+location.pathname+"/"+i,n=encodeURIComponent(s);g.fullUrl="https://viewer.needle.tools?inspect&file="+n;var r='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';e(r)}),g.on("show",function(){const e=A();e&&e.src!==g.fullUrl&&(e.src=g.fullUrl)}),g.on("hide",function(){const e=A();e&&(e.src="")}),g.on("addTopBar",function(e){var t=new Array;t.push({name:"Open in new window ↗",onClick:function(i){window.open(g.fullUrl,"_blank"),os==null||os.hide()}}),t.push({name:"Reload",onClick:function(i){const I=A();I&&(I.src=g.fullUrl)}}),t.push({name:"Fullscreen",onClick:function(i){const I=A();I.requestFullscreen?I.requestFullscreen():I.webkitRequestFullscreen instanceof Function&&I.webkitRequestFullscreen()}}),e(t)}),g}function xgA(){const g=document.querySelector("#__vconsole .vc-switch");return g||null}function vgA(){const g=document.querySelector("#__vconsole");return g||null}const p3=gA("debugdefines");gd('if(!globalThis[""3.45.2-beta.
|
|
4347
|
+
`,As==null||As.prepend(t),g===!0&&yJ()<=0&&h3(),console.log("🌵 Debug console has loaded")}},A.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(A)}function JgA(){const g=new VConsole.VConsolePlugin("needle-console","🌵 Inspect glTF"),A=()=>document.querySelector("#__vc_plug_"+g._id+" iframe");return g.on("renderTab",function(e){const t=globalThis["needle:codegen_files"];if(!t||t.length===0)return;let i=globalThis["needle:codegen_files"][0];const I=i.indexOf("?");I>-1&&(i=i.substring(0,I));const s=location.protocol+"//"+location.host+location.pathname+"/"+i,n=encodeURIComponent(s);g.fullUrl="https://viewer.needle.tools?inspect&file="+n;var r='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';e(r)}),g.on("show",function(){const e=A();e&&e.src!==g.fullUrl&&(e.src=g.fullUrl)}),g.on("hide",function(){const e=A();e&&(e.src="")}),g.on("addTopBar",function(e){var t=new Array;t.push({name:"Open in new window ↗",onClick:function(i){window.open(g.fullUrl,"_blank"),os==null||os.hide()}}),t.push({name:"Reload",onClick:function(i){const I=A();I&&(I.src=g.fullUrl)}}),t.push({name:"Fullscreen",onClick:function(i){const I=A();I.requestFullscreen?I.requestFullscreen():I.webkitRequestFullscreen instanceof Function&&I.webkitRequestFullscreen()}}),e(t)}),g}function xgA(){const g=document.querySelector("#__vconsole .vc-switch");return g||null}function vgA(){const g=document.querySelector("#__vconsole");return g||null}const p3=gA("debugdefines");gd('if(!globalThis[""3.45.2-beta.3""]) globalThis[""3.45.2-beta.3""] = "0.0.0";');gd('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');gd('if(!globalThis[""Thu Jul 18 2024 13:36:22 GMT+0200 (Central European Summer Time)""]) globalThis[""Thu Jul 18 2024 13:36:22 GMT+0200 (Central European Summer Time)""] = "unknown";');gd('globalThis["__NEEDLE_ENGINE_VERSION__"] = "3.45.2-beta.3";');gd('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');gd('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Thu Jul 18 2024 13:36:22 GMT+0200 (Central European Summer Time)";');const Os="3.45.2-beta.3",_k="undefined",gx="Thu Jul 18 2024 13:36:22 GMT+0200 (Central European Summer Time)";p3&&console.log(`Engine version: ${Os} (generator: ${_k})
|
|
4348
4348
|
Project built at ${gx}`);const ja="needle_isActiveInHierarchy",ZQ="builtin_components",Sp="needle_editor_guid";function gd(g){try{(0,eval)(g)}catch(A){p3&&console.error(A)}}const qgA='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 160 187.74"><defs><linearGradient id="a" x1="89.64" y1="184.81" x2="90.48" y2="21.85" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#62d399"/><stop offset=".51" stop-color="#acd842"/><stop offset=".9" stop-color="#d7db0a"/></linearGradient><linearGradient id="b" x1="69.68" y1="178.9" x2="68.08" y2="16.77" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#0ba398"/><stop offset=".5" stop-color="#4ca352"/><stop offset="1" stop-color="#76a30a"/></linearGradient><linearGradient id="c" x1="36.6" y1="152.17" x2="34.7" y2="84.19" gradientUnits="userSpaceOnUse"><stop offset=".19" stop-color="#36a382"/><stop offset=".54" stop-color="#49a459"/><stop offset="1" stop-color="#76a30b"/></linearGradient><linearGradient id="d" x1="15.82" y1="153.24" x2="18" y2="90.86" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#267880"/><stop offset=".51" stop-color="#457a5c"/><stop offset="1" stop-color="#717516"/></linearGradient><linearGradient id="e" x1="135.08" y1="135.43" x2="148.93" y2="63.47" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#b0d939"/><stop offset="1" stop-color="#eadb04"/></linearGradient><linearGradient id="f" x1="-4163.25" y1="2285.12" x2="-4160.81" y2="2215.34" gradientTransform="rotate(20 4088.49 13316.712)" gradientUnits="userSpaceOnUse"><stop offset=".17" stop-color="#74af52"/><stop offset=".48" stop-color="#99be32"/><stop offset="1" stop-color="#c0c40a"/></linearGradient><symbol id="g" viewBox="0 0 160 187.74"><path style="fill:url(#a)" d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75z"/><path style="fill:url(#b)" d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98z"/><path style="fill:url(#c)" d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z"/><path style="fill:url(#d)" d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04z"/><path style="fill:#9c3" d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5z"/><path style="fill:url(#e)" d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59z"/><path style="fill:url(#f)" d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z"/><path style="fill:#ffe113" d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1z"/><path style="fill:#f3e600" d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75z"/></symbol></defs><use width="160" height="187.74" xlink:href="#g"/></svg>',LgA=btoa(qgA),_gA="data:image/svg+xml;base64,"+LgA,TgA=_gA,HgA=`<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'> <svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" version="1.1" viewBox="0 0 1014 282" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m665.95 132.73v44.88l-10.56-8.4c-0.8-0.64-1.2-1.44-1.2-2.4v-32.4c0-6.48-4.12-9.72-12.36-9.72-2.16 0-4.18 0.4-6.06 1.2s-3.54 1.8-4.98 3-2.56 2.5-3.36 3.9-1.2 2.7-1.2 3.9v40.92l-10.68-8.4c-0.72-0.64-1.08-1.44-1.08-2.4v-53.76l10.92 8.52c0.32 0.24 0.56 0.44 0.72 0.6s0.36 0.32 0.6 0.48c0.96-1.2 2.14-2.28 3.54-3.24s2.92-1.76 4.56-2.4 3.34-1.14 5.1-1.5 3.44-0.54 5.04-0.54c1.44 0 2.92 0.04 4.44 0.12s2.84 0.28 3.96 0.6c4.56 1.12 7.8 3.12 9.72 6s2.88 6.56 2.88 11.04z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m732.38 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m795.93 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m858.57 97.21c0.64 0.48 0.96 1.16 0.96 2.04v74.88c-0.08 1.04-0.12 2.12-0.12 3.24-1.84-1.52-3.56-2.92-5.16-4.2-1.36-1.12-2.66-2.18-3.9-3.18s-2.06-1.66-2.46-1.98c-1.76 2.48-4.26 4.44-7.5 5.88s-7.02 2.16-11.34 2.16c-3.84 0-7.4-0.7-10.68-2.1s-6.14-3.44-8.58-6.12-4.34-5.94-5.7-9.78-2.04-8.16-2.04-12.96c0-4.32 0.78-8.34 2.34-12.06s3.6-6.92 6.12-9.6 5.38-4.78 8.58-6.3 6.48-2.28 9.84-2.28c2.56 0 4.82 0.22 6.78 0.66s3.68 1.06 5.16 1.86 2.78 1.74 3.9 2.82 2.16 2.22 3.12 3.42v-35.04l10.68 8.64zm-27.96 67.92c3.6 0 6.52-0.68 8.76-2.04s3.98-3.06 5.22-5.1 2.1-4.22 2.58-6.54 0.72-4.44 0.72-6.36v-1.2c0-1.12-0.22-2.7-0.66-4.74s-1.28-4.06-2.52-6.06-3-3.7-5.28-5.1-5.22-2.02-8.82-1.86c-3.44 0-6.26 0.74-8.46 2.22s-3.96 3.26-5.28 5.34-2.24 4.2-2.76 6.36-0.78 3.92-0.78 5.28c0 1.84 0.24 3.92 0.72 6.24s1.36 4.48 2.64 6.48 3.04 3.68 5.28 5.04 5.12 2.04 8.64 2.04z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m882.81 97.09c0.64 0.48 0.96 1.12 0.96 1.92l-0.12 41.04v37.08l-10.56-8.4c-0.72-0.64-1.08-1.44-1.08-2.4v-77.88l10.8 8.64z" fill-rule="nonzero"/> </g> <g transform="matrix(1.008 0 0 1.008 -2.239 .61874)"> <path d="m950.36 146.05c0 0.88 0.02 1.5 0.06 1.86s-0.02 0.98-0.18 1.86h-7.08c-2.08 0-4.44-0.02-7.08-0.06s-5.36-0.06-8.16-0.06h-22.08c0 2.88 0.56 5.36 1.68 7.44s2.6 3.8 4.44 5.16 3.94 2.36 6.3 3 4.74 0.96 7.14 0.96c3.04 0 5.9-0.76 8.58-2.28s4.94-3.52 6.78-6c0.64 0.56 1.54 1.48 2.7 2.76s2.94 3.2 5.34 5.76c-2.8 3.36-6.22 6.02-10.26 7.98s-8.42 2.94-13.14 2.94-8.92-0.64-12.84-1.92-7.32-3.24-10.2-5.88-5.12-5.98-6.72-10.02-2.4-8.82-2.4-14.34c0-4.96 0.66-9.42 1.98-13.38s3.22-7.32 5.7-10.08 5.44-4.9 8.88-6.42 7.32-2.28 11.64-2.28c5.76 0 10.52 0.88 14.28 2.64s6.72 4.16 8.88 7.2 3.66 6.54 4.5 10.5 1.26 8.18 1.26 12.66zm-29.4-22.8c-2.16 0.16-4.16 0.72-6 1.68s-3.42 2.2-4.74 3.72-2.36 3.28-3.12 5.28-1.14 4.12-1.14 6.36h33.12c0-2-0.22-4.06-0.66-6.18s-1.3-4.02-2.58-5.7-3.1-3.02-5.46-4.02-5.5-1.38-9.42-1.14z" fill-rule="nonzero"/> </g> <g transform="matrix(1.8559 0 0 .7642 45.348 36.475)"> <g transform="translate(2.7114)"> <path d="m3.935 173.02c-0.331 0-0.497-0.402-0.497-1.207v-51.002c0-0.738 0.138-1.107 0.414-1.107h1.781c0.277 0 0.415 0.335 0.415 1.006v5.935c0 0.336 0.027 0.553 0.083 0.654 0.055 0.101 0.151-0.017 0.289-0.352 0.912-1.744 1.754-3.236 2.527-4.477 0.773-1.24 1.554-2.179 2.341-2.816s1.65-0.956 2.588-0.956c1.685 0 3.011 0.922 3.977 2.766 0.967 1.845 1.602 3.84 1.905 5.986 0.056 0.268 0.139 0.369 0.249 0.302s0.221-0.235 0.331-0.503c0.939-1.811 1.802-3.353 2.589-4.628 0.787-1.274 1.581-2.246 2.382-2.917s1.671-1.006 2.61-1.006c2.016 0 3.569 1.392 4.66 4.175 1.09 2.783 1.636 6.421 1.636 10.915v37.925c0 0.871-0.18 1.307-0.539 1.307h-1.739c-0.138 0-0.249-0.1-0.332-0.301-0.083-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.338-6.321-1.015-8.3-0.676-1.978-1.76-2.967-3.251-2.967-0.884 0-1.726 0.386-2.527 1.157s-1.519 1.727-2.154 2.867-1.201 2.213-1.699 3.219c-0.248 0.469-0.421 0.905-0.517 1.308-0.097 0.402-0.145 0.972-0.145 1.71v37.221c0 0.871-0.166 1.307-0.497 1.307h-1.74c-0.166 0-0.29-0.1-0.373-0.301-0.083-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.332-6.321-0.994-8.3-0.663-1.978-1.754-2.967-3.273-2.967-1.242 0-2.375 0.704-3.396 2.112-1.022 1.409-2.223 3.555-3.604 6.439v39.031c0 0.805-0.18 1.207-0.539 1.207h-1.698z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m53.642 166.28c-1.077 2.549-2.237 4.477-3.479 5.785-1.243 1.307-2.61 1.961-4.101 1.961-2.154 0-3.853-1.324-5.095-3.973-1.243-2.649-1.864-6.187-1.864-10.613 0-3.488 0.4-6.489 1.201-9.004s1.988-4.51 3.562-5.985c1.574-1.476 3.521-2.414 5.841-2.817l3.686-0.704c0.221-0.067 0.394-0.218 0.518-0.453 0.124-0.234 0.187-0.587 0.187-1.056v-2.917c0-3.89-0.504-6.975-1.512-9.255s-2.354-3.42-4.039-3.42c-1.298 0-2.472 0.72-3.521 2.162s-2.002 3.572-2.858 6.388c-0.083 0.268-0.159 0.453-0.228 0.554-0.069 0.1-0.172 0.083-0.311-0.051l-1.698-1.71c-0.083-0.134-0.138-0.285-0.166-0.453-0.027-0.167 0.014-0.452 0.125-0.855 0.856-3.353 2.009-6.052 3.459-8.098 1.449-2.045 3.224-3.068 5.322-3.068 1.74 0 3.211 0.687 4.412 2.062s2.112 3.37 2.734 5.986c0.621 2.615 0.932 5.7 0.932 9.255v35.712c0 0.536-0.035 0.888-0.104 1.056s-0.2 0.251-0.393 0.251h-1.533c-0.166 0-0.29-0.117-0.373-0.352-0.083-0.234-0.124-0.553-0.124-0.955l-0.083-5.231c-0.055-0.939-0.221-1.006-0.497-0.202zm0.456-19.314c0-1.14-0.194-1.643-0.58-1.509l-3.107 0.603c-1.436 0.202-2.686 0.638-3.749 1.308-1.063 0.671-1.953 1.543-2.671 2.616s-1.257 2.33-1.616 3.772-0.538 3.102-0.538 4.98c0 3.152 0.455 5.616 1.367 7.393 0.911 1.778 2.14 2.666 3.686 2.666 0.939 0 1.85-0.419 2.734-1.257s1.671-1.895 2.361-3.169c0.663-1.408 1.181-2.85 1.553-4.326 0.373-1.475 0.56-2.883 0.56-4.225v-8.852z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m79.034 173.02c-0.166 0-0.297-0.117-0.394-0.352-0.096-0.234-0.145-0.553-0.145-0.955v-4.628c0-0.536-0.041-0.838-0.124-0.905s-0.207 0.1-0.373 0.503c-0.276 0.67-0.69 1.593-1.242 2.766-0.553 1.174-1.271 2.23-2.154 3.169-0.884 0.939-1.961 1.408-3.231 1.408-1.74 0-3.314-0.989-4.722-2.967-1.409-1.979-2.534-4.963-3.376-8.953-0.843-3.991-1.264-8.937-1.264-14.838 0-5.701 0.415-10.68 1.243-14.939s1.988-7.595 3.479-10.009c1.492-2.415 3.204-3.622 5.137-3.622 1.436 0 2.616 0.57 3.541 1.71 0.926 1.14 1.719 2.381 2.382 3.722 0.249 0.47 0.414 0.637 0.497 0.503s0.125-0.536 0.125-1.207v-23.841c0-0.805 0.151-1.208 0.455-1.208h1.864c0.276 0 0.414 0.369 0.414 1.107v72.128c0 0.537-0.041 0.905-0.124 1.107-0.083 0.201-0.235 0.301-0.455 0.301h-1.533zm-0.621-42.049c-0.939-2.213-1.885-3.94-2.838-5.181s-2.009-1.861-3.169-1.861c-1.463 0-2.768 0.889-3.914 2.666s-2.044 4.376-2.693 7.796-0.973 7.578-0.973 12.474c0 5.097 0.338 9.272 1.015 12.524 0.676 3.253 1.567 5.651 2.672 7.193 1.104 1.543 2.305 2.314 3.603 2.314 1.188 0 2.258-0.704 3.211-2.113 0.952-1.408 1.705-3.118 2.257-5.13s0.829-3.957 0.829-5.835v-24.847z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m89.514 149.38c0 3.42 0.345 6.606 1.035 9.557 0.691 2.951 1.609 5.315 2.755 7.092s2.437 2.666 3.873 2.666c1.519 0 2.837-0.738 3.956-2.213 1.118-1.476 2.064-3.655 2.837-6.539 0.083-0.336 0.166-0.52 0.249-0.554 0.083-0.033 0.179 0.017 0.29 0.151l1.408 1.912c0.221 0.268 0.235 0.67 0.041 1.207-0.69 2.548-1.47 4.661-2.34 6.337-0.87 1.677-1.857 2.935-2.962 3.773-1.104 0.838-2.319 1.257-3.645 1.257-2.043 0-3.838-1.14-5.385-3.42-1.546-2.28-2.761-5.482-3.645-9.607-0.884-4.124-1.325-8.836-1.325-14.134 0-5.901 0.455-10.931 1.367-15.089 0.911-4.158 2.14-7.377 3.686-9.658 1.547-2.28 3.3-3.42 5.261-3.42 1.988 0 3.714 1.073 5.178 3.219 1.463 2.146 2.595 5.231 3.396 9.255s1.201 8.886 1.201 14.587c0 0.469-0.02 0.939-0.062 1.408-0.041 0.469-0.214 0.704-0.517 0.704h-16.362c-0.083 0-0.152 0.151-0.207 0.453-0.056 0.302-0.083 0.654-0.083 1.056zm13.752-6.237c0.304 0 0.497-0.1 0.58-0.302 0.083-0.201 0.124-0.57 0.124-1.106 0-3.219-0.283-6.187-0.849-8.903s-1.367-4.896-2.402-6.539c-1.036-1.643-2.272-2.464-3.708-2.464-1.629 0-2.996 0.955-4.101 2.867-1.104 1.911-1.94 4.342-2.506 7.293s-0.849 6.002-0.849 9.154h13.711z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m148.54 119.7c0.165 0 0.283 0.117 0.352 0.352s0.076 0.52 0.02 0.855l-6.254 50.902c-0.028 0.47-0.104 0.788-0.228 0.956s-0.297 0.251-0.518 0.251h-1.615c-0.442 0-0.718-0.402-0.829-1.207l-5.26-40.138c-0.111-0.604-0.201-0.905-0.27-0.905s-0.131 0.301-0.186 0.905l-5.012 40.138c-0.028 0.47-0.097 0.788-0.207 0.956-0.111 0.168-0.277 0.251-0.497 0.251h-1.74c-0.442 0-0.718-0.402-0.829-1.207l-6.503-50.801c-0.055-0.403-0.048-0.721 0.021-0.956s0.2-0.352 0.393-0.352h1.823c0.166 0 0.297 0.067 0.393 0.201 0.097 0.134 0.159 0.403 0.187 0.805l5.302 41.848c0.083 0.671 0.179 0.989 0.29 0.956 0.11-0.034 0.207-0.386 0.29-1.056l5.219-41.949c0.055-0.268 0.124-0.47 0.207-0.604s0.193-0.201 0.331-0.201h1.533c0.138 0 0.262 0.067 0.373 0.201 0.11 0.134 0.179 0.403 0.207 0.805l5.468 41.848c0.083 0.671 0.179 0.989 0.29 0.956 0.11-0.034 0.207-0.386 0.29-1.056l5.053-41.849c0.055-0.335 0.138-0.57 0.249-0.704 0.11-0.134 0.234-0.201 0.373-0.201h1.284z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m156.49 171.51c0 0.604-0.042 1.006-0.125 1.208-0.082 0.201-0.262 0.301-0.538 0.301h-1.533c-0.221 0-0.366-0.083-0.435-0.251s-0.103-0.486-0.103-0.956v-50.902c0-0.805 0.152-1.207 0.456-1.207h1.822c0.304 0 0.456 0.402 0.456 1.207v50.6zm0.165-63.979c0 1.207-0.207 1.811-0.621 1.811h-1.905c-0.221 0-0.366-0.135-0.435-0.403s-0.104-0.67-0.104-1.207v-7.847c0-1.006 0.18-1.509 0.539-1.509h1.988c0.359 0 0.538 0.47 0.538 1.409v7.746z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m168.3 124.83c-0.221 0-0.331 0.269-0.331 0.805v33.801c0 3.42 0.221 5.667 0.663 6.74 0.441 1.073 1.09 1.609 1.946 1.609h3.024c0.138 0 0.242 0.084 0.311 0.252 0.069 0.167 0.103 0.419 0.103 0.754v2.716c0 0.537-0.138 0.906-0.414 1.107-0.248 0.067-0.614 0.134-1.098 0.201-0.483 0.067-0.959 0.118-1.429 0.151-0.469 0.034-0.828 0.05-1.077 0.05-1.712 0-2.934-0.955-3.665-2.867-0.732-1.911-1.098-5.013-1.098-9.305v-35.108c0-0.604-0.124-0.906-0.373-0.906h-3.521c-0.248 0-0.373-0.268-0.373-0.804v-3.521c0-0.537 0.111-0.805 0.332-0.805h3.686c0.166 0 0.263-0.268 0.29-0.805l0.415-16.095c0-0.805 0.124-1.207 0.372-1.207h1.492c0.303 0 0.455 0.436 0.455 1.307v15.995c0 0.537 0.097 0.805 0.29 0.805h5.468c0.221 0 0.331 0.268 0.331 0.805v3.521c0 0.536-0.124 0.804-0.373 0.804h-5.426z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> <g transform="translate(2.7114)"> <path d="m179.4 173.02c-0.331 0-0.497-0.402-0.497-1.207v-72.329c0-0.738 0.138-1.107 0.414-1.107h1.782c0.276 0 0.414 0.336 0.414 1.006v27.162c0 0.335 0.034 0.536 0.103 0.603s0.159-0.033 0.27-0.302c0.994-1.81 1.898-3.319 2.713-4.526 0.814-1.208 1.629-2.113 2.444-2.717 0.814-0.603 1.691-0.905 2.63-0.905 2.182 0 3.839 1.375 4.971 4.125 1.132 2.749 1.698 6.404 1.698 10.965v37.925c0 0.871-0.166 1.307-0.497 1.307h-1.74c-0.165 0-0.29-0.1-0.373-0.301-0.082-0.202-0.124-0.503-0.124-0.906v-36.315c0-3.555-0.366-6.321-1.097-8.3-0.732-1.978-1.899-2.967-3.501-2.967-0.883 0-1.705 0.318-2.464 0.956-0.76 0.637-1.526 1.576-2.299 2.816-0.773 1.241-1.643 2.834-2.61 4.779v39.031c0 0.805-0.179 1.207-0.538 1.207h-1.699z" fill-rule="nonzero" stroke="#000" stroke-width=".7px"/> </g> </g> <g transform="matrix(.80638 0 0 .80638 452.53 65.421)" fill-rule="nonzero"> <path d="m79.32 36.98v150.76l15.68-13.2 6.59-156.31-22.27 18.75z" fill="url(#f)"/> <path d="m79.32 36.98-22.27-18.75 6.59 156.31 15.68 13.2v-150.76z" fill="url(#e)"/> <path d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33z" fill="url(#d)"/> <path d="m25.19 104.83-25.19-14.59 16.97 53.86 16.85 9.77-8.63-49.04z" fill="url(#c)"/> <path d="M43.86,82.5L18.69,67.98L0,90.24L25.18,104.83L43.86,82.5Z" fill="#9c3"/> <path d="m134.82 78.69-9.97 56.5 15.58-9.04 19.57-62.05-25.18 14.59z" fill="url(#b)"/> <path d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5z" fill="url(#a)"/> <path d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33 25.19-14.59z" fill="#ffe113"/> <path d="M101.59,18.23L79.32,0L57.05,18.23L79.32,36.98L101.59,18.23Z" fill="#f3e600"/> </g> <defs> <linearGradient id="f" x2="1" gradientTransform="matrix(.84 -162.96 162.96 .84 89.64 184.81)" gradientUnits="userSpaceOnUse"><stop stop-color="#62d399" offset="0"/><stop stop-color="#acd842" offset=".51"/><stop stop-color="#d7db0a" offset=".9"/><stop stop-color="#d7db0a" offset="1"/></linearGradient> <linearGradient id="e" x2="1" gradientTransform="matrix(-1.6,-162.13,162.13,-1.6,69.68,178.9)" gradientUnits="userSpaceOnUse"><stop stop-color="#0ba398" offset="0"/><stop stop-color="#4ca352" offset=".5"/><stop stop-color="#76a30a" offset="1"/></linearGradient> <linearGradient id="d" x2="1" gradientTransform="matrix(-1.9,-67.98,67.98,-1.9,36.6,152.17)" gradientUnits="userSpaceOnUse"><stop stop-color="#36a382" offset="0"/><stop stop-color="#36a382" offset=".19"/><stop stop-color="#49a459" offset=".54"/><stop stop-color="#76a30b" offset="1"/></linearGradient> <linearGradient id="c" x2="1" gradientTransform="matrix(2.18,-62.38,62.38,2.18,15.82,153.24)" gradientUnits="userSpaceOnUse"><stop stop-color="#267880" offset="0"/><stop stop-color="#457a5c" offset=".51"/><stop stop-color="#717516" offset="1"/></linearGradient> <linearGradient id="b" x2="1" gradientTransform="matrix(13.85,-71.96,71.96,13.85,135.08,135.43)" gradientUnits="userSpaceOnUse"><stop stop-color="#b0d939" offset="0"/><stop stop-color="#eadb04" offset="1"/></linearGradient> <linearGradient id="a" x2="1" gradientTransform="matrix(26.159 -64.737 64.737 26.159 107.42 128.14)" gradientUnits="userSpaceOnUse"><stop stop-color="#74af52" offset="0"/><stop stop-color="#74af52" offset=".17"/><stop stop-color="#99be32" offset=".48"/><stop stop-color="#c0c40a" offset="1"/></linearGradient> </defs> </svg>`;btoa(HgA);const YgA='<svg viewBox="0 0 509 154" xmlns="http://www.w3.org/2000/svg" xml:space="preserve" style="fill-rule:evenodd;clip-rule:evenodd;stroke-linejoin:round;stroke-miterlimit:2"><path d="M665.95 132.73v44.88l-10.56-8.4c-.8-.64-1.2-1.44-1.2-2.4v-32.4c0-6.48-4.12-9.72-12.36-9.72-2.16 0-4.18.4-6.06 1.2-1.88.8-3.54 1.8-4.98 3-1.44 1.2-2.56 2.5-3.36 3.9-.8 1.4-1.2 2.7-1.2 3.9v40.92l-10.68-8.4c-.72-.64-1.08-1.44-1.08-2.4v-53.76l10.92 8.52c.32.24.56.44.72.6.16.16.36.32.6.48.96-1.2 2.14-2.28 3.54-3.24 1.4-.96 2.92-1.76 4.56-2.4 1.64-.64 3.34-1.14 5.1-1.5 1.76-.36 3.44-.54 5.04-.54 1.44 0 2.92.04 4.44.12 1.52.08 2.84.28 3.96.6 4.56 1.12 7.8 3.12 9.72 6 1.92 2.88 2.88 6.56 2.88 11.04ZM732.38 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14ZM795.93 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14ZM858.57 97.21c.64.48.96 1.16.96 2.04v74.88c-.08 1.04-.12 2.12-.12 3.24-1.84-1.52-3.56-2.92-5.16-4.2-1.36-1.12-2.66-2.18-3.9-3.18-1.24-1-2.06-1.66-2.46-1.98-1.76 2.48-4.26 4.44-7.5 5.88-3.24 1.44-7.02 2.16-11.34 2.16-3.84 0-7.4-.7-10.68-2.1-3.28-1.4-6.14-3.44-8.58-6.12-2.44-2.68-4.34-5.94-5.7-9.78-1.36-3.84-2.04-8.16-2.04-12.96 0-4.32.78-8.34 2.34-12.06 1.56-3.72 3.6-6.92 6.12-9.6 2.52-2.68 5.38-4.78 8.58-6.3 3.2-1.52 6.48-2.28 9.84-2.28 2.56 0 4.82.22 6.78.66 1.96.44 3.68 1.06 5.16 1.86s2.78 1.74 3.9 2.82a35.92 35.92 0 0 1 3.12 3.42V88.57l10.68 8.64Zm-27.96 67.92c3.6 0 6.52-.68 8.76-2.04 2.24-1.36 3.98-3.06 5.22-5.1a20.5 20.5 0 0 0 2.58-6.54c.48-2.32.72-4.44.72-6.36v-1.2c0-1.12-.22-2.7-.66-4.74-.44-2.04-1.28-4.06-2.52-6.06s-3-3.7-5.28-5.1c-2.28-1.4-5.22-2.02-8.82-1.86-3.44 0-6.26.74-8.46 2.22-2.2 1.48-3.96 3.26-5.28 5.34-1.32 2.08-2.24 4.2-2.76 6.36-.52 2.16-.78 3.92-.78 5.28 0 1.84.24 3.92.72 6.24.48 2.32 1.36 4.48 2.64 6.48s3.04 3.68 5.28 5.04c2.24 1.36 5.12 2.04 8.64 2.04ZM882.81 97.09c.64.48.96 1.12.96 1.92l-.12 41.04v37.08l-10.56-8.4c-.72-.64-1.08-1.44-1.08-2.4V88.45l10.8 8.64ZM950.36 146.05c0 .88.02 1.5.06 1.86.04.36-.02.98-.18 1.86h-7.08c-2.08 0-4.44-.02-7.08-.06-2.64-.04-5.36-.06-8.16-.06h-22.08c0 2.88.56 5.36 1.68 7.44 1.12 2.08 2.6 3.8 4.44 5.16 1.84 1.36 3.94 2.36 6.3 3 2.36.64 4.74.96 7.14.96 3.04 0 5.9-.76 8.58-2.28 2.68-1.52 4.94-3.52 6.78-6 .64.56 1.54 1.48 2.7 2.76 1.16 1.28 2.94 3.2 5.34 5.76-2.8 3.36-6.22 6.02-10.26 7.98-4.04 1.96-8.42 2.94-13.14 2.94-4.72 0-8.92-.64-12.84-1.92-3.92-1.28-7.32-3.24-10.2-5.88-2.88-2.64-5.12-5.98-6.72-10.02-1.6-4.04-2.4-8.82-2.4-14.34 0-4.96.66-9.42 1.98-13.38 1.32-3.96 3.22-7.32 5.7-10.08s5.44-4.9 8.88-6.42c3.44-1.52 7.32-2.28 11.64-2.28 5.76 0 10.52.88 14.28 2.64 3.76 1.76 6.72 4.16 8.88 7.2 2.16 3.04 3.66 6.54 4.5 10.5.84 3.96 1.26 8.18 1.26 12.66Zm-29.4-22.8c-2.16.16-4.16.72-6 1.68-1.84.96-3.42 2.2-4.74 3.72-1.32 1.52-2.36 3.28-3.12 5.28-.76 2-1.14 4.12-1.14 6.36h33.12c0-2-.22-4.06-.66-6.18-.44-2.12-1.3-4.02-2.58-5.7-1.28-1.68-3.1-3.02-5.46-4.02-2.36-1-5.5-1.38-9.42-1.14Z" style="fill-rule:nonzero" transform="translate(-452.406 -63.709) scale(1.00797)"/><path d="M79.32 36.98v150.76L95 174.54l6.59-156.31-22.27 18.75Z" style="fill:url(#a);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M79.32 36.98 57.05 18.23l6.59 156.31 15.68 13.2V36.98Z" style="fill:url(#b);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m25.19 104.83 8.63 49.04 12.5-14.95-2.46-56.42-18.67 22.33Z" style="fill:url(#c);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M25.19 104.83 0 90.24l16.97 53.86 16.85 9.77-8.63-49.04Z" style="fill:url(#d);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M43.86 82.5 18.69 67.98 0 90.24l25.18 14.59L43.86 82.5Z" style="fill:#9c3;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m134.82 78.69-9.97 56.5 15.58-9.04L160 64.1l-25.18 14.59Z" style="fill:url(#e);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m134.82 78.69-18.68-22.33-2.86 65 11.57 13.83 9.97-56.5Z" style="fill:url(#f);fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="m160 64.1-18.69-22.26-25.17 14.52 18.67 22.33L160 64.1Z" style="fill:#ffe113;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><path d="M101.59 18.23 79.32 0 57.05 18.23l22.27 18.75 22.27-18.75Z" style="fill:#f3e600;fill-rule:nonzero" transform="matrix(.80638 0 0 .80638 2.361 1.094)"/><defs><linearGradient id="a" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="matrix(.84 -162.96 162.96 .84 89.64 184.81)"><stop offset="0" style="stop-color:#62d399;stop-opacity:1"/><stop offset=".51" style="stop-color:#acd842;stop-opacity:1"/><stop offset=".9" style="stop-color:#d7db0a;stop-opacity:1"/><stop offset="1" style="stop-color:#d7db0a;stop-opacity:1"/></linearGradient><linearGradient id="b" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-90.565 123.412 54.953) scale(162.14)"><stop offset="0" style="stop-color:#0ba398;stop-opacity:1"/><stop offset=".5" style="stop-color:#4ca352;stop-opacity:1"/><stop offset="1" style="stop-color:#76a30a;stop-opacity:1"/></linearGradient><linearGradient id="c" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="scale(-68) rotate(88.4 .881 -1.396)"><stop offset="0" style="stop-color:#36a382;stop-opacity:1"/><stop offset=".19" style="stop-color:#36a382;stop-opacity:1"/><stop offset=".54" style="stop-color:#49a459;stop-opacity:1"/><stop offset="1" style="stop-color:#76a30b;stop-opacity:1"/></linearGradient><linearGradient id="d" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-88 87.255 68.431) scale(62.42)"><stop offset="0" style="stop-color:#267880;stop-opacity:1"/><stop offset=".51" style="stop-color:#457a5c;stop-opacity:1"/><stop offset="1" style="stop-color:#717516;stop-opacity:1"/></linearGradient><linearGradient id="e" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-79.1 149.53 -14.065) scale(73.28)"><stop offset="0" style="stop-color:#b0d939;stop-opacity:1"/><stop offset="1" style="stop-color:#eadb04;stop-opacity:1"/></linearGradient><linearGradient id="f" x1="0" y1="0" x2="1" y2="0" gradientUnits="userSpaceOnUse" gradientTransform="rotate(-67.997 148.705 -15.558) scale(69.8226)"><stop offset="0" style="stop-color:#74af52;stop-opacity:1"/><stop offset=".17" style="stop-color:#74af52;stop-opacity:1"/><stop offset=".48" style="stop-color:#99be32;stop-opacity:1"/><stop offset="1" style="stop-color:#c0c40a;stop-opacity:1"/></linearGradient></defs></svg>',OgA=btoa(YgA),PgA="data:image/svg+xml;charset=utf-8;base64,"+OgA,WgA=PgA,_s=gA("debuglicense");let hc="basic";_s&&console.log("License Type: "+hc);function fB(){switch(hc){case"pro":case"enterprise":return!0}return!1}function Ix(){switch(hc){case"indie":return!0}return!1}function za(){return fB()||Ix()}const f3=[];function ZgA(g){if(fB()||Ix())return g(!0);f3.push(g)}function jgA(g){for(const A of f3)try{A(g)}catch{}}Et.registerCallback(Gt.ContextRegistered,g=>{XgA(g.context),AIA(),VgA(g.context)});let DB,WF=!1,Pu="";async function zgA(){if(DB)return DB;if(hc==="basic")try{const g="https://engine.needle.tools/licensing/check?location="+encodeURIComponent(window.location.href)+"&version="+Os+"&generator="+encodeURIComponent(_k),A=await fetch(g,{method:"GET"}).catch(e=>{_s&&console.error("License check failed",e)});(A==null?void 0:A.status)===200?(WF=!1,_s&&console.log("License check succeeded"),hc="pro",jgA(!0)):(A==null?void 0:A.status)===403?(WF=!0,Pu=await A.text()):_s&&console.log("License check failed with status "+(A==null?void 0:A.status))}catch(g){_s&&console.error("License check failed",g)}else _s&&console.log('Runtime license check is skipped because license is already applied as "'+hc+'"')}DB=zgA();async function VgA(g){function A(){const i=document.createElement("div");i.className="needle-forbidden",i.style.cssText=`
|
|
4349
4349
|
position: fixed;
|
|
4350
4350
|
top: 0;
|
|
@@ -5148,7 +5148,7 @@ in script ${t}.ts
|
|
|
5148
5148
|
*
|
|
5149
5149
|
* @author Feross Aboukhadijeh <https://feross.org>
|
|
5150
5150
|
* @license MIT
|
|
5151
|
-
*/var KBA=function(g){return g!=null&&(QW(g)||bBA(g)||!!g._isBuffer)};function QW(g){return!!g.constructor&&typeof g.constructor.isBuffer=="function"&&g.constructor.isBuffer(g)}function bBA(g){return typeof g.readFloatLE=="function"&&typeof g.slice=="function"&&QW(g.slice(0,0))}(function(){var g=FBA,A=DY.utf8,e=KBA,t=DY.bin,i=function(I,o){I.constructor==String?o&&o.encoding==="binary"?I=t.stringToBytes(I):I=A.stringToBytes(I):e(I)?I=Array.prototype.slice.call(I,0):!Array.isArray(I)&&I.constructor!==Uint8Array&&(I=I.toString());for(var s=g.bytesToWords(I),n=I.length*8,r=1732584193,a=-271733879,C=-1732584194,Q=271733878,c=0;c<s.length;c++)s[c]=(s[c]<<8|s[c]>>>24)&16711935|(s[c]<<24|s[c]>>>8)&4278255360;s[n>>>5]|=128<<n%32,s[(n+64>>>9<<4)+14]=n;for(var E=i._ff,h=i._gg,l=i._hh,d=i._ii,c=0;c<s.length;c+=16){var p=r,u=a,f=C,w=Q;r=E(r,a,C,Q,s[c+0],7,-680876936),Q=E(Q,r,a,C,s[c+1],12,-389564586),C=E(C,Q,r,a,s[c+2],17,606105819),a=E(a,C,Q,r,s[c+3],22,-1044525330),r=E(r,a,C,Q,s[c+4],7,-176418897),Q=E(Q,r,a,C,s[c+5],12,1200080426),C=E(C,Q,r,a,s[c+6],17,-1473231341),a=E(a,C,Q,r,s[c+7],22,-45705983),r=E(r,a,C,Q,s[c+8],7,1770035416),Q=E(Q,r,a,C,s[c+9],12,-1958414417),C=E(C,Q,r,a,s[c+10],17,-42063),a=E(a,C,Q,r,s[c+11],22,-1990404162),r=E(r,a,C,Q,s[c+12],7,1804603682),Q=E(Q,r,a,C,s[c+13],12,-40341101),C=E(C,Q,r,a,s[c+14],17,-1502002290),a=E(a,C,Q,r,s[c+15],22,1236535329),r=h(r,a,C,Q,s[c+1],5,-165796510),Q=h(Q,r,a,C,s[c+6],9,-1069501632),C=h(C,Q,r,a,s[c+11],14,643717713),a=h(a,C,Q,r,s[c+0],20,-373897302),r=h(r,a,C,Q,s[c+5],5,-701558691),Q=h(Q,r,a,C,s[c+10],9,38016083),C=h(C,Q,r,a,s[c+15],14,-660478335),a=h(a,C,Q,r,s[c+4],20,-405537848),r=h(r,a,C,Q,s[c+9],5,568446438),Q=h(Q,r,a,C,s[c+14],9,-1019803690),C=h(C,Q,r,a,s[c+3],14,-187363961),a=h(a,C,Q,r,s[c+8],20,1163531501),r=h(r,a,C,Q,s[c+13],5,-1444681467),Q=h(Q,r,a,C,s[c+2],9,-51403784),C=h(C,Q,r,a,s[c+7],14,1735328473),a=h(a,C,Q,r,s[c+12],20,-1926607734),r=l(r,a,C,Q,s[c+5],4,-378558),Q=l(Q,r,a,C,s[c+8],11,-2022574463),C=l(C,Q,r,a,s[c+11],16,1839030562),a=l(a,C,Q,r,s[c+14],23,-35309556),r=l(r,a,C,Q,s[c+1],4,-1530992060),Q=l(Q,r,a,C,s[c+4],11,1272893353),C=l(C,Q,r,a,s[c+7],16,-155497632),a=l(a,C,Q,r,s[c+10],23,-1094730640),r=l(r,a,C,Q,s[c+13],4,681279174),Q=l(Q,r,a,C,s[c+0],11,-358537222),C=l(C,Q,r,a,s[c+3],16,-722521979),a=l(a,C,Q,r,s[c+6],23,76029189),r=l(r,a,C,Q,s[c+9],4,-640364487),Q=l(Q,r,a,C,s[c+12],11,-421815835),C=l(C,Q,r,a,s[c+15],16,530742520),a=l(a,C,Q,r,s[c+2],23,-995338651),r=d(r,a,C,Q,s[c+0],6,-198630844),Q=d(Q,r,a,C,s[c+7],10,1126891415),C=d(C,Q,r,a,s[c+14],15,-1416354905),a=d(a,C,Q,r,s[c+5],21,-57434055),r=d(r,a,C,Q,s[c+12],6,1700485571),Q=d(Q,r,a,C,s[c+3],10,-1894986606),C=d(C,Q,r,a,s[c+10],15,-1051523),a=d(a,C,Q,r,s[c+1],21,-2054922799),r=d(r,a,C,Q,s[c+8],6,1873313359),Q=d(Q,r,a,C,s[c+15],10,-30611744),C=d(C,Q,r,a,s[c+6],15,-1560198380),a=d(a,C,Q,r,s[c+13],21,1309151649),r=d(r,a,C,Q,s[c+4],6,-145523070),Q=d(Q,r,a,C,s[c+11],10,-1120210379),C=d(C,Q,r,a,s[c+2],15,718787259),a=d(a,C,Q,r,s[c+9],21,-343485551),r=r+p>>>0,a=a+u>>>0,C=C+f>>>0,Q=Q+w>>>0}return g.endian([r,a,C,Q])};i._ff=function(I,o,s,n,r,a,C){var Q=I+(o&s|~o&n)+(r>>>0)+C;return(Q<<a|Q>>>32-a)+o},i._gg=function(I,o,s,n,r,a,C){var Q=I+(o&n|s&~n)+(r>>>0)+C;return(Q<<a|Q>>>32-a)+o},i._hh=function(I,o,s,n,r,a,C){var Q=I+(o^s^n)+(r>>>0)+C;return(Q<<a|Q>>>32-a)+o},i._ii=function(I,o,s,n,r,a,C){var Q=I+(s^(o|~n))+(r>>>0)+C;return(Q<<a|Q>>>32-a)+o},i._blocksize=16,i._digestsize=16,CW.exports=function(I,o){if(I==null)throw new Error("Illegal argument "+I);var s=g.wordsToBytes(i(I,o));return o&&o.asBytes?s:o&&o.asString?t.bytesToString(s):g.bytesToHex(s)}})();var JBA=CW.exports;const xBA=tM(JBA);class kK{constructor(A,e,t,i){B(this,"success");B(this,"filename");B(this,"hash");B(this,"size");B(this,"url");this.success=A,this.filename=e,this.hash=t,this.size=i}}async function cW(g,A){const e=await g.arrayBuffer(),t=Lx(e),i=g.name.split(".").pop(),I=t+"."+i,o=g.name.split(".").shift();console.assert(o!==void 0);const s={alias:o,filename:I},r=await(await fetch(A+"/exists",{method:"POST",body:JSON.stringify(s)})).json();if(r.success||console.warn("exists check did fail"),r.exists)return console.log("file already exists",t),new kK(!0,I,t,g.size);console.log("begin uploading file",o,g.size);const a=new FormData;a.append("file",g);const C={};C.filesize=g.size,o&&(C.alias=o);const c=await(await fetch(A+"/upload/file",{method:"POST",body:a,headers:C})).json();if((c==null?void 0:c.success)===!1)return c.message!==void 0?console.error("Upload failed:",c.message):console.error("Upload failed"),null;console.assert(c.hash_sum===t,"hash sum did not match","received:",c.hash_sum,"expected:",t),c.success&&console.log("successfully uploaded",t,c.id);const E=new kK(c.success,I,t,g.size);return E.url=A,E}function Lx(g){return xBA(new Uint8Array(g))}async function _x(g,A,e,t,i=!1){try{const I=await fetch(t+"/download/file",{method:"POST",body:g});if(I.status!==200)return console.error("download failed",I),null;const o=await I.blob(),s=await o.arrayBuffer();i||console.assert(o.size===e,"size mismatch","expected:",e,"got:",o.size);const n=Lx(s);return i||console.assert(n===A,"hash mismatch, downloaded file is invalid"),o.arrayBuffer()}catch(I){console.error(I)}return null}async function EW(g,A){var a;const e=await fetch(g),t=(a=e.body)==null?void 0:a.getReader(),i=e.headers.get("Content-Length"),I=i?parseInt(i):0;if(!t)return null;let o=0;const s=[];for(;;){const{done:C,value:Q}=await t.read();if(Q&&(s.push(Q),o+=Q.length,A.call(null,new ProgressEvent("progress",{loaded:o,total:I}))),C)break}const n=new Uint8Array(o);let r=0;for(const C of s)n.set(C,r),r+=C.length;return n}const _C=gA("debugaddressables");class lW{constructor(A){B(this,"_context");B(this,"_assetReferences",{});B(this,"preUpdate",()=>{});this._context=A,this._context.pre_update_callbacks.push(this.preUpdate)}dispose(){const A=this._context.pre_update_callbacks.indexOf(this.preUpdate);A>=0&&this._context.pre_update_callbacks.splice(A,1);for(const e in this._assetReferences){const t=this._assetReferences[e];t==null||t.unload()}this._assetReferences={}}findAssetReference(A){return this._assetReferences[A]||null}registerAssetReference(A){return A.uri&&(this._assetReferences[A.uri]?console.warn("Asset reference already registered",A):this._assetReferences[A.uri]=A),A}unregisterAssetReference(A){A.uri&&delete this._assetReferences[A.uri]}}const bU=Symbol("assetReference"),XQ=class{constructor(A,e,t=null){B(this,"_loading");B(this,"_asset");B(this,"_glbRoot");B(this,"_url");B(this,"_progressListeners",[]);B(this,"_hash");B(this,"_hashedUri");B(this,"_isLoadingRawBinary",!1);B(this,"_rawBinary");this._url=A,this._hash=e,A.includes("?v=")?this._hashedUri=A:this._hashedUri=e?A+"?v="+e:A,t!==null&&(this.asset=t),LZ(this._url,this.onResolvePrefab.bind(this))}static getOrCreateFromUrl(A,e){if(!e&&(e=be.Current,!e))throw new Error('Context is required when sourceId is a string. When you call this method from a component you can call it with "getOrCreate(this, url)" where "this" is the component.');const t=e.addressables,i=t.findAssetReference(A);if(i)return i;const I=new XQ(A,e.hash);return t.registerAssetReference(I),I}static getOrCreate(A,e,t){if(typeof A=="string"){if(!t&&(t=be.Current,!t))throw new Error('Context is required when sourceId is a string. When you call this method from a component you can call it with "getOrCreate(this, url)" where "this" is the component.')}else t=A.context,A=A.sourceId;const i=OB(A,e);_C&&console.log("GetOrCreate Addressable from",A,e,"FinalPath=",i);const I=t.addressables,o=I.findAssetReference(i);if(o)return o;const s=new XQ(i,t.hash);return I.registerAssetReference(s),s}get asset(){return this._glbRoot??this._asset}set asset(A){this._asset=A}get uri(){return this._url}get url(){return this._url}get hasUrl(){return this._url!==void 0&&(this._url.startsWith("http")||this._url.startsWith("blob:")||this._url.startsWith("www.")||this._url.includes("/"))}get rawAsset(){return this._asset}async onResolvePrefab(A){return A===this.uri&&(this.mustLoad&&await this.loadAssetAsync(),this.asset)?this.asset:null}get mustLoad(){return!this.asset||this.asset.__destroyed===!0||Yc(this.asset)===!0}isLoaded(){return this._rawBinary||this.asset!==void 0}unload(){this.asset&&(_C&&console.log("Unload",this.asset),this.asset.scene&&Vs(this.asset.scene,!0,!0),Vs(this.asset,!0,!0)),this.asset=null,this._rawBinary=void 0,this._glbRoot=null,this._loading=void 0,be.Current&&be.Current.addressables.unregisterAssetReference(this)}async preload(){if(!this.mustLoad||this._isLoadingRawBinary)return null;if(this._rawBinary!==void 0)return this._rawBinary;this._isLoadingRawBinary=!0,_C&&console.log("Preload",this._hashedUri);const A=await EW(this._hashedUri,e=>{this.raiseProgressEvent(e)});return this._rawBinary=(A==null?void 0:A.buffer)??null,this._isLoadingRawBinary=!1,this._rawBinary}async loadAssetAsync(A){if(_C&&console.log("loadAssetAsync",this.uri),!this.mustLoad)return this.asset;if(A&&this._progressListeners.push(A),this._loading!==void 0)return this._loading.then(i=>this.asset);const e=be.Current;this._rawBinary?(this._loading=Ln().parseSync(e,this._rawBinary,this.uri,null),this.raiseProgressEvent(new ProgressEvent("progress",{loaded:this._rawBinary.byteLength,total:this._rawBinary.byteLength}))):(_C&&console.log("Load async",this.uri),this._loading=Ln().loadSync(e,this._hashedUri,this.uri,null,i=>{this.raiseProgressEvent(i)}));const t=await this._loading;if(this._progressListeners.length=0,this._glbRoot=this.tryGetActualGameObjectRoot(t),this._loading=void 0,t)return t[bU]=this,this._glbRoot&&(this._glbRoot[bU]=this),this.asset&&(this.asset[bU]=this),nm(e),t.scene!==void 0&&(this.asset=t),this.asset}async instantiate(A){return this.onInstantiate(A,!1)}async instantiateSynced(A,e=!0){return this.onInstantiate(A,!0,e)}beginListenDownload(A){this._progressListeners.indexOf(A)<0&&this._progressListeners.push(A)}endListenDownload(A){const e=this._progressListeners.indexOf(A);e>=0&&this._progressListeners.splice(e,1)}raiseProgressEvent(A){for(const e of this._progressListeners)e(this,A)}async onInstantiate(A,e=!1,t){const i=be.Current,I=new Wn;if(A instanceof DA?I.parent=A:A&&(Object.assign(I,A),I.cloneAssign(A)),I.parent||(I.parent=i.scene),this.mustLoad&&await this.loadAssetAsync(),_C&&console.log("Instantiate",this.uri,"parent:",A),this.asset){_C&&console.log("Add to scene",this.asset);let o=XQ.currentlyInstantiating.get(this.uri);if(o!==void 0&&o>=1e4)return console.error("Recursive or too many instantiations of "+this.uri+" in the same frame ("+o+")"),null;try{if(o===void 0&&(o=0),o+=1,XQ.currentlyInstantiating.set(this.uri,o),e){I.context=i;const s=this.asset;s.guid=this.uri;const n=iv(s,I,void 0,t);if(n)return n}else{const s=Qd(this.asset,I);if(s)return s}}finally{i.post_render_callbacks.push(()=>{o===void 0||o<0?o=0:o-=1,XQ.currentlyInstantiating.set(this.uri,o)})}}else _C&&console.warn("Failed to load asset",this.uri);return null}tryGetActualGameObjectRoot(A){if(A&&A.scene){const e=A.scene;return e.isGroup&&e.children.length===1&&e.children[0].name+"glb"===e.name?e.children[0]:e}return null}};let et=XQ;B(et,"currentlyInstantiating",new Map);class vBA extends on{constructor(){super([et],"AssetReferenceSerializer")}onSerialize(A,e){if(A&&A.uri!==void 0&&typeof A.uri=="string")return A.uri}onDeserialize(A,e){if(typeof A=="string")return e.context?e.gltfId?et.getOrCreate(e.gltfId,A,e.context):(console.error("Missing source id"),null):(console.error("Missing context"),null);if(A instanceof DA){if(!e.context)return console.error("Missing context"),null;if(!e.gltfId)return console.error("Missing source id"),null;const t=A,i=e.context,I=t.guid??t.uuid,o=i.addressables.findAssetReference(I);if(o)return o;const s=new et(I,void 0,t);return i.addressables.registerAssetReference(s),s}return null}}new vBA;const qBA=Promise.resolve(null),Zp=class{constructor(A){B(this,"url");B(this,"_bitmap");B(this,"_bitmapObject");B(this,"loader",null);this.url=A}static getOrCreate(A){let e=Zp.imageReferences.get(A);return e||(e=new Zp(A),Zp.imageReferences.set(A,e)),e}dispose(){this._bitmapObject&&this._bitmapObject.close(),this._bitmap=void 0}createHTMLImage(){const A=new Image;return A.src=this.url,A}createTexture(){return this.url?(this.loader||(this.loader=new Rr),this.loader.setCrossOrigin("anonymous"),this.loader.loadAsync(this.url)):qBA}getBitmap(){return this._bitmap?this._bitmap:(this._bitmap=new Promise((A,e)=>{const t=document.createElement("img");t.addEventListener("load",()=>{this._bitmap=createImageBitmap(t).then(i=>(this._bitmapObject=i,A(i),i))}),t.addEventListener("error",i=>{console.error("Failed to load image:"+this.url,i),A(null)}),t.src=this.url}),this._bitmap)}};let lh=Zp;B(lh,"imageReferences",new Map);class hW extends on{constructor(){super([lh],"ImageReferenceSerializer")}onSerialize(A,e){return null}onDeserialize(A,e){if(typeof A=="string"){const t=OB(e.gltfId,A);return lh.getOrCreate(t)}}}new hW;const jp=class{constructor(A){B(this,"url");B(this,"res");this.url=A}static getOrCreate(A){let e=jp.cache.get(A);return e||(e=new jp(A),jp.cache.set(A,e)),e}async loadRaw(){return this.res||(this.res=fetch(this.url)),this.res.then(A=>A.blob())}async loadText(){return this.res||(this.res=fetch(this.url)),this.res.then(A=>A.text())}};let hh=jp;B(hh,"cache",new Map);class dW extends on{constructor(){super([hh],"FileReferenceSerializer")}onSerialize(A,e){return null}onDeserialize(A,e){if(typeof A=="string"){const t=OB(e.gltfId,A);return hh.getOrCreate(t)}}}new dW;class LBA{constructor(A){B(this,"context");B(this,"mixers",[]);this.context=A}onDestroy(){this.mixers.forEach(A=>A.stopAllAction()),this.mixers.length=0}registerAnimationMixer(A){if(!A){console.warn("AnimationsRegistry.registerAnimationMixer called with null or undefined mixer");return}this.mixers.includes(A)||this.mixers.push(A)}unregisterAnimationMixer(A){if(!A)return;const e=this.mixers.indexOf(A);e!==-1&&this.mixers.splice(e,1)}}class vh{static tryGetActionsFromMixer(A){const e=A._actions;return e||null}static tryGetAnimationClipsFromObjectHierarchy(A,e){if(e||(e=new Array),A)A.animations&&e.push(...A.animations);else return e;if(A.children)for(const t of A.children)this.tryGetAnimationClipsFromObjectHierarchy(t,e);return e}static assignAnimationsFromFile(A,e){if(!A||!A.animations)return;for(let i=0;i<A.animations.length;i++){const I=A.animations[i];if(!(!I.tracks||I.tracks.length<=0))for(const o in I.tracks){const s=I.tracks[o],n=Xe.parseTrackName(s.name);let r=Xe.findNode(A.scene,n.nodeName);if(!r){const C=s.__objectName??s.name.substring(0,s.name.indexOf("."));if(r=A.scene.getObjectByProperty("uuid",C),!r)continue}let a=t(r);if(!a){if(!(e!=null&&e.createAnimationComponent)){console.warn("No AnimationComponent found in parent hierarchy of object and no 'createAnimationComponent' callback was provided in options.");continue}a=e.createAnimationComponent(A.scene,I)}a.addClip&&a.addClip(I)}}function t(i){var o;if(!i)return null;const I=(o=i.userData)==null?void 0:o.components;if(I&&I.length>0){for(let s=0;s<I.length;s++)if(I[s].isAnimationComponent===!0)return i}return t(i.parent)}}}const qh=[];function iM(g){qh.indexOf(g)===-1&&qh.push(g)}function _BA(g){const A=qh.indexOf(g);A!==-1&&qh.splice(A,1)}const Lh=[];function Tx(g){Lh.indexOf(g)===-1&&Lh.push(g)}function TBA(g){const A=Lh.indexOf(g);A!==-1&&Lh.splice(A,1)}function uW(g){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:g}));for(let A=0;A<qh.length;A++)qh[A](g)}function pW(g){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:g}));for(let A=0;A<Lh.length;A++)Lh[A](g)}const Yg={Handedness:Object.freeze({NONE:"none",LEFT:"left",RIGHT:"right"}),ComponentState:Object.freeze({DEFAULT:"default",TOUCHED:"touched",PRESSED:"pressed"}),ComponentProperty:Object.freeze({BUTTON:"button",X_AXIS:"xAxis",Y_AXIS:"yAxis",STATE:"state"}),ComponentType:Object.freeze({TRIGGER:"trigger",SQUEEZE:"squeeze",TOUCHPAD:"touchpad",THUMBSTICK:"thumbstick",BUTTON:"button"}),ButtonTouchThreshold:.05,AxisTouchThreshold:.1,VisualResponseProperty:Object.freeze({TRANSFORM:"transform",VISIBILITY:"visibility"})};async function fW(g){const A=await fetch(g);if(A.ok)return A.json();throw new Error(A.statusText)}async function HBA(g){if(!g)throw new Error("No basePath supplied");return await fW(`${g}/profilesList.json`)}async function YBA(g,A,e=null,t=!0){if(!g)throw new Error("No xrInputSource supplied");if(!A)throw new Error("No basePath supplied");const i=await HBA(A);let I;if(g.profiles.some(n=>{const r=i[n];return r&&(I={profileId:n,profilePath:`${A}/${r.path}`,deprecated:!!r.deprecated}),!!I}),!I){if(!e)throw new Error("No matching profile name found");const n=i[e];if(!n)throw new Error(`No matching profile name found and default profile "${e}" missing.`);I={profileId:e,profilePath:`${A}/${n.path}`,deprecated:!!n.deprecated}}const o=await fW(I.profilePath);let s;if(t){let n;if(g.handedness==="any"?n=o.layouts[Object.keys(o.layouts)[0]]:n=o.layouts[g.handedness],!n)throw new Error(`No matching handedness, ${g.handedness}, in profile ${I.profileId}`);n.assetPath&&(s=I.profilePath.replace("profile.json",n.assetPath))}return{profile:o,assetPath:s}}const OBA={xAxis:0,yAxis:0,button:0,state:Yg.ComponentState.DEFAULT};function PBA(g=0,A=0){let e=g,t=A;if(Math.sqrt(g*g+A*A)>1){const o=Math.atan2(A,g);e=Math.cos(o),t=Math.sin(o)}return{normalizedXAxis:e*.5+.5,normalizedYAxis:t*.5+.5}}let WBA=class{constructor(A){this.componentProperty=A.componentProperty,this.states=A.states,this.valueNodeName=A.valueNodeName,this.valueNodeProperty=A.valueNodeProperty,this.valueNodeProperty===Yg.VisualResponseProperty.TRANSFORM&&(this.minNodeName=A.minNodeName,this.maxNodeName=A.maxNodeName),this.value=0,this.updateFromComponent(OBA)}updateFromComponent({xAxis:A,yAxis:e,button:t,state:i}){const{normalizedXAxis:I,normalizedYAxis:o}=PBA(A,e);switch(this.componentProperty){case Yg.ComponentProperty.X_AXIS:this.value=this.states.includes(i)?I:.5;break;case Yg.ComponentProperty.Y_AXIS:this.value=this.states.includes(i)?o:.5;break;case Yg.ComponentProperty.BUTTON:this.value=this.states.includes(i)?t:0;break;case Yg.ComponentProperty.STATE:this.valueNodeProperty===Yg.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(i):this.value=this.states.includes(i)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}},ZBA=class{constructor(A,e){if(!A||!e||!e.visualResponses||!e.gamepadIndices||Object.keys(e.gamepadIndices).length===0)throw new Error("Invalid arguments supplied");this.id=A,this.type=e.type,this.rootNodeName=e.rootNodeName,this.touchPointNodeName=e.touchPointNodeName,this.visualResponses={},Object.keys(e.visualResponses).forEach(t=>{const i=new WBA(e.visualResponses[t]);this.visualResponses[t]=i}),this.gamepadIndices=Object.assign({},e.gamepadIndices),this.values={state:Yg.ComponentState.DEFAULT,button:this.gamepadIndices.button!==void 0?0:void 0,xAxis:this.gamepadIndices.xAxis!==void 0?0:void 0,yAxis:this.gamepadIndices.yAxis!==void 0?0:void 0}}get data(){return{id:this.id,...this.values}}updateFromGamepad(A){if(this.values.state=Yg.ComponentState.DEFAULT,this.gamepadIndices.button!==void 0&&A.buttons.length>this.gamepadIndices.button){const e=A.buttons[this.gamepadIndices.button];this.values.button=e.value,this.values.button=this.values.button<0?0:this.values.button,this.values.button=this.values.button>1?1:this.values.button,e.pressed||this.values.button===1?this.values.state=Yg.ComponentState.PRESSED:(e.touched||this.values.button>Yg.ButtonTouchThreshold)&&(this.values.state=Yg.ComponentState.TOUCHED)}this.gamepadIndices.xAxis!==void 0&&A.axes.length>this.gamepadIndices.xAxis&&(this.values.xAxis=A.axes[this.gamepadIndices.xAxis],this.values.xAxis=this.values.xAxis<-1?-1:this.values.xAxis,this.values.xAxis=this.values.xAxis>1?1:this.values.xAxis,this.values.state===Yg.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>Yg.AxisTouchThreshold&&(this.values.state=Yg.ComponentState.TOUCHED)),this.gamepadIndices.yAxis!==void 0&&A.axes.length>this.gamepadIndices.yAxis&&(this.values.yAxis=A.axes[this.gamepadIndices.yAxis],this.values.yAxis=this.values.yAxis<-1?-1:this.values.yAxis,this.values.yAxis=this.values.yAxis>1?1:this.values.yAxis,this.values.state===Yg.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>Yg.AxisTouchThreshold&&(this.values.state=Yg.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(e=>{e.updateFromComponent(this.values)})}},jBA=class{constructor(A,e,t){if(!A)throw new Error("No xrInputSource supplied");if(!e)throw new Error("No profile supplied");this.xrInputSource=A,this.assetUrl=t,this.id=e.profileId,this.layoutDescription=e.layouts[A.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(i=>{const I=this.layoutDescription.components[i];this.components[i]=new ZBA(i,I)}),this.updateFromGamepad()}get gripSpace(){return this.xrInputSource.gripSpace}get targetRaySpace(){return this.xrInputSource.targetRaySpace}get data(){const A=[];return Object.values(this.components).forEach(e=>{A.push(e.data)}),A}updateFromGamepad(){Object.values(this.components).forEach(A=>{A.updateFromGamepad(this.xrInputSource.gamepad)})}};const to=new y,yY=new y,wY=new GA,zBA=gA("debuggizmos"),$n=8947848,mn=class{constructor(){}static isGizmo(A){return A[MK]!==void 0}static DrawLabel(A,e,t=.05,i=0,I,o,s){var a;if(!mn.enabled)return null;I||(I=$n);const n=((a=ye.active)==null?void 0:a.rigScale)??1,r=Ti.getTextLabel(i,e,t*n,I,o);return s instanceof DA&&s.add(r),r.position.x=A.x,r.position.y=A.y,r.position.z=A.z,r}static DrawRay(A,e,t=$n,i=0,I=!0){if(!mn.enabled)return;const o=Ti.getLine(i),s=o.geometry.getAttribute("position");s.setXYZ(0,A.x,A.y,A.z),to.set(e.x,e.y,e.z).multiplyScalar(999999999),s.setXYZ(1,A.x+to.x,A.y+to.y,A.z+to.z),s.needsUpdate=!0,o.material.color.set(t),o.material.depthTest=I,o.material.depthWrite=!1}static DrawDirection(A,e,t=$n,i=0,I=!0,o=1){if(!mn.enabled)return;const s=Ti.getLine(i),n=s.geometry.getAttribute("position");n.setXYZ(0,A.x,A.y,A.z),e.w!==void 0?(to.set(0,0,-o),wY.set(e.x,e.y,e.z,e.w),to.applyQuaternion(wY)):(to.set(e.x,e.y,e.z),to.multiplyScalar(o)),n.setXYZ(1,A.x+to.x,A.y+to.y,A.z+to.z),n.needsUpdate=!0,s.material.color.set(t),s.material.depthTest=I,s.material.depthWrite=!1}static DrawLine(A,e,t=$n,i=0,I=!0){if(!mn.enabled)return;const o=Ti.getLine(i),s=o.geometry.getAttribute("position");s.setXYZ(0,A.x,A.y,A.z),s.setXYZ(1,e.x,e.y,e.z),s.needsUpdate=!0,o.material.color.set(t),o.material.depthTest=I,o.material.depthWrite=!1,o.material.fog=!1}static DrawWireSphere(A,e,t=$n,i=0,I=!0){if(!mn.enabled)return;const o=Ti.getSphere(e,i,!0);Tc(o,A.x,A.y,A.z),o.material.color.set(t),o.material.depthTest=I,o.material.depthWrite=!1,o.material.fog=!1}static DrawSphere(A,e,t=$n,i=0,I=!0){if(!mn.enabled)return;const o=Ti.getSphere(e,i,!1);Tc(o,A.x,A.y,A.z),o.material.color.set(t),o.material.depthTest=I,o.material.depthWrite=!1}static DrawWireBox(A,e,t=$n,i=0,I=!0){if(!mn.enabled)return;const o=Ti.getBox(i);o.position.set(A.x,A.y,A.z),o.scale.set(e.x,e.y,e.z),o.material.color.set(t),o.material.depthTest=I,o.material.wireframe=!0,o.material.depthWrite=!1,o.material.fog=!1}static DrawWireBox3(A,e=$n,t=0,i=!0){if(!mn.enabled)return;const I=Ti.getBox(t);I.position.copy(A.getCenter(to)),I.scale.copy(A.getSize(to)),I.material.color.set(e),I.material.depthTest=i,I.material.wireframe=!0,I.material.depthWrite=!1,I.material.fog=!1}static DrawArrow(A,e,t=$n,i=0,I=!0,o=!1){if(!mn.enabled)return;const s=Ti.getArrowHead(i);s.position.set(e.x,e.y,e.z),s.quaternion.setFromUnitVectors(this._up.set(0,1,0),to.set(e.x,e.y,e.z).sub(yY.set(A.x,A.y,A.z)).normalize());const r=to.set(e.x,e.y,e.z).sub(yY.set(A.x,A.y,A.z)).length()*.1;s.scale.set(r,r,r),s.material.color.set(t),s.material.depthTest=I,s.material.wireframe=o,this.DrawLine(A,e,t,i,I)}static DrawWireMesh(A){const e=Ti.getMesh(A.duration??0);"mesh"in A?(e.geometry=A.mesh.geometry,e.matrix.copy(A.mesh.matrixWorld)):(e.geometry=A.geometry,e.matrix.copy(A.matrix)),e.matrixAutoUpdate=!1,e.matrixWorldAutoUpdate=!1,e.material.color.set(A.color??$n),e.material.depthTest=A.depthTest??!0,e.material.wireframe=!0}};let fe=mn;B(fe,"enabled",!0),B(fe,"_up",new y(0,1,0));const VBA=new ti(1,1,1);function Hx(g=null){const A=new yA(g??14540253),e=new IJ(VBA);return new TI(e,new Ii({color:A}))}const MK=Symbol("GizmoCache");class Ti{static ensureFont(){let A=Vt.FontLibrary.getFontFamily(this.familyName);if(!A){A=Vt.FontLibrary.addFontFamily(this.familyName);const e=A.addVariant("normal","normal","https://uploads.needle.tools/include/font-msdf.json","https://uploads.needle.tools/include/font.png");e==null||e.addEventListener("ready",()=>{Vt.update()})}}static getTextLabel(A,e,t,i,I){this.ensureFont();let o=this.textLabelCache.pop(),s=1;I&&typeof I=="string"&&(I==null?void 0:I.length)>=8&&I.startsWith("#")?(s=parseInt(I.substring(7),16)/255,I=I.substring(0,7),zBA&&console.log(I,s)):typeof I=="object"&&I.a!==void 0&&(s=I.a);const n={boxSizing:"border-box",fontFamily:this.familyName,width:"auto",fontSize:t,color:i,lineHeight:1,backgroundColor:I??void 0,backgroundOpacity:s,textContent:e,borderRadius:.5*t,padding:.8*t,whiteSpace:"pre"};if(o)o.set(n);else{o=new WJ(n);const r=this,a=o;a.setText=function(C){this.set({textContent:C}),r.tmuiNeedsUpdate=!0}}return this.tmuiNeedsUpdate=!0,this.registerTimedObject(be.Current,o,A,this.textLabelCache),o}static getBox(A){let e=this.boxesCache.pop();if(!e){const t=new ti(1,1,1);e=new hA(t)}return this.registerTimedObject(be.Current,e,A,this.boxesCache),e}static getLine(A){let e=this.linesCache.pop();if(!e){e=new Oi;let t=e.geometry.getAttribute("position");t||(t=new ne(new Float32Array(2*3),3),e.geometry.setAttribute("position",t))}return e.frustumCulled=!1,this.registerTimedObject(be.Current,e,A,this.linesCache),e}static getSphere(A,e,t){let i=this.spheresCache.pop();return i||(i=new hA(new gn(1,8,8))),i.scale.set(A,A,A),i.material.wireframe=t,this.registerTimedObject(be.Current,i,e,this.spheresCache),i}static getArrowHead(A){let e=this.arrowHeadsCache.pop();return e||(e=new hA(new Ag(0,.5,1,8))),this.registerTimedObject(be.Current,e,A,this.arrowHeadsCache),e}static getMesh(A){let e=this.mesh.pop();return e||(e=new hA,e.material=new ot),this.registerTimedObject(be.Current,e,A,this.mesh),e}static registerTimedObject(A,e,t,i){const I=this.contextBeforeRenderCallbacks.get(A),o=this.contextPostRenderCallbacks.get(A);if(I){if(A.pre_render_callbacks[A.pre_render_callbacks.length-1]!==I){const s=A.pre_render_callbacks.indexOf(I);s>=0&&A.pre_render_callbacks.splice(s,1),A.pre_render_callbacks.push(I)}}else{const s=()=>{this.onBeforeRender(A,this.timedObjectsBuffer)};this.contextBeforeRenderCallbacks.set(A,s),A.pre_render_callbacks.push(s)}if(o){if(A.post_render_callbacks[A.post_render_callbacks.length-1]!==o){const s=A.post_render_callbacks.indexOf(o);s>=0&&A.post_render_callbacks.splice(s,1),A.post_render_callbacks.push(o)}}else{const s=()=>{this.onPostRender(A,this.timedObjectsBuffer,this.timesBuffer)};this.contextPostRenderCallbacks.set(A,s),A.post_render_callbacks.push(s)}e.traverse(s=>{s.layers.disableAll(),s.layers.enable(2)}),e.renderOrder=999999,e[MK]=i,e.isGizmo=!0,this.timedObjectsBuffer.push(e),t<=0&&A.currentFrameEvent>=oi.OnBeforeRender?this.timesBuffer.push(0):this.timesBuffer.push(be.Current.time.realtimeSinceStartup+t),A.scene.add(e)}static onBeforeRender(A,e){this.tmuiNeedsUpdate&&Vt.update();for(let t=0;t<e.length;t++){const i=e[t];if(A.mainCamera&&i instanceof Vt.MeshUIBaseElement){if(Yc(i))continue;const I=A.isInVR,o=!1,s=!I;hD(i,A.mainCamera,o,s)}}}static onPostRender(A,e,t){const i=A.time.realtimeSinceStartup;for(let I=e.length-1;I>=0;I--){const o=e[I];i>t[I]&&(e.splice(I,1),t.splice(I,1),o.removeFromParent(),Yc(o)!=!0&&o[MK].push(o))}}}B(Ti,"familyName","needle-gizmos"),B(Ti,"linesCache",[]),B(Ti,"spheresCache",[]),B(Ti,"boxesCache",[]),B(Ti,"arrowHeadsCache",[]),B(Ti,"mesh",[]),B(Ti,"textLabelCache",[]),B(Ti,"timedObjectsBuffer",new Array),B(Ti,"timesBuffer",new Array),B(Ti,"contextPostRenderCallbacks",new Map),B(Ti,"contextBeforeRenderCallbacks",new Map),B(Ti,"tmuiNeedsUpdate",!1);const Dg=gA("debuginput");var gM=(g=>(g.Mouse="mouse",g.Touch="touch",g.Controller="controller",g.Hand="hand",g))(gM||{}),pi=(g=>(g.PointerDown="pointerdown",g.PointerUp="pointerup",g.PointerMove="pointermove",g.KeyDown="keydown",g.KeyUp="keyup",g.KeyPressed="keypress",g))(pi||{});class ma extends PointerEvent{constructor(e,t,i){super(e,i);B(this,"deviceIndex");B(this,"origin");B(this,"source");B(this,"mode");B(this,"_ray");B(this,"space");B(this,"isClick",!1);B(this,"isDoubleClick",!1);B(this,"_used",!1);B(this,"_pointerid");B(this,"_pointerType");B(this,"_type");B(this,"metadata",{});B(this,"intersections",new Array);B(this,"_immediatePropagationStopped",!1);B(this,"_propagationStopped",!1);this._pointerid=i.pointerId,this._pointerType=i.pointerType,this._type=e,this.deviceIndex=i.deviceIndex,this.origin=i.origin,this.source=t,this.mode=i.mode,this._ray=i.ray,this.space=i.device}get ray(){return this._ray||(this._ray=new xo(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(e){this._ray=e}get hasRay(){return this._ray!==void 0}get used(){return this._used}use(){this._used=!0}get pointerId(){return this._pointerid}get pointerType(){return this._pointerType}get type(){return this._type}get immediatePropagationStopped(){return this._immediatePropagationStopped}get propagationStopped(){return this._immediatePropagationStopped||this._propagationStopped}stopImmediatePropagation(){var e;this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}stopPropagation(){var e;this._propagationStopped=!0,super.stopPropagation(),(e=this.source)==null||e.stopPropagation(),Dg&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class ep extends KeyboardEvent{constructor(e,t,i){super(e,i);B(this,"source");this.source=t}stopImmediatePropagation(){var e;super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}}class XBA{constructor(A){B(this,"key");B(this,"keyType");B(this,"source");this.key=A.key,this.keyType=A.type,this.source=A}}var cr=(g=>(g[g.Early=-100]="Early",g[g.Default=0]="Default",g[g.Late=100]="Late",g))(cr||{});class DW{constructor(A){B(this,"_eventListeners",{});B(this,"_doubleClickTimeThreshold",.2);B(this,"_longPressTimeThreshold",1);B(this,"_specialCursorTrigger",0);B(this,"context");B(this,"_pointerDown",[!1]);B(this,"_pointerUp",[!1]);B(this,"_pointerClick",[!1]);B(this,"_pointerDoubleClick",[!1]);B(this,"_pointerPressed",[!1]);B(this,"_pointerPositions",[new tA]);B(this,"_pointerPositionsLastFrame",[new tA]);B(this,"_pointerPositionsDelta",[new tA]);B(this,"_pointerPositionsRC",[new tA]);B(this,"_pointerPositionDown",[new tA]);B(this,"_pointerDownTime",[]);B(this,"_pointerUpTime",[]);B(this,"_pointerUpTimestamp",[]);B(this,"_pointerIds",[]);B(this,"_pointerTypes",[""]);B(this,"_mouseWheelChanged",[!1]);B(this,"_mouseWheelDeltaY",[0]);B(this,"_pointerEvent",[]);B(this,"_pointerUsed",[]);B(this,"_pointerSpace",[]);B(this,"_pressedStack",new Map);B(this,"_htmlEventSource");B(this,"onLostFocus",()=>{for(const A in this.keysPressed)this.keysPressed[A].pressed=!1});B(this,"onEndOfFrame",()=>{for(let A=0;A<this._pointerUp.length;A++)this._pointerUp[A]=!1;for(let A=0;A<this._pointerDown.length;A++)this._pointerDown[A]=!1;for(let A=0;A<this._pointerClick.length;A++)this._pointerClick[A]=!1;for(let A=0;A<this._pointerDoubleClick.length;A++)this._pointerDoubleClick[A]=!1;for(const A of this._pointerPositionsDelta)A.set(0,0);for(let A=0;A<this._mouseWheelChanged.length;A++)this._mouseWheelChanged[A]=!1;for(let A=0;A<this._mouseWheelDeltaY.length;A++)this._mouseWheelDeltaY[A]=0});B(this,"onContextMenu",A=>{this.canReceiveInput(A)!==!1&&A instanceof PointerEvent&&A.pointerType});B(this,"keysPressed",{});B(this,"onKeyDown",A=>{if(Dg&&console.log(`key down ${A.code}, ${this.context.application.hasFocus}`,A),!this.context.application.hasFocus)return;const e=this.keysPressed[A.code];if(e&&e.pressed)return;this.keysPressed[A.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:A.key,code:A.code};const t=new ep("keydown",A,A);this.onDispatchEvent(t)});B(this,"onKeyPressed",A=>{if(!this.context.application.hasFocus)return;const e=this.keysPressed[A.code];if(!e)return;e.pressed=!0,e.frame=this.context.time.frameCount+1;const t=new ep("keypress",A,A);this.onDispatchEvent(t)});B(this,"onKeyUp",A=>{if(!this.context.application.hasFocus)return;const e=this.keysPressed[A.code];if(!e)return;e.pressed=!1,e.frame=this.context.time.frameCount+1;const t=new ep("keyup",A,A);this.onDispatchEvent(t)});B(this,"onWheelWindow",A=>{document.pointerLockElement&&this.onMouseWheel(A)});B(this,"onMouseWheel",A=>{if(this.canReceiveInput(A)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const e=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=e+A.deltaY});B(this,"onPointerDown",A=>{if(this.context.isInAR||this.canReceiveInput(A)===!1)return;A.target instanceof HTMLElement&&A.target.setPointerCapture(A.pointerId);const e=this.getPointerId(A);Dg&&fi(`pointer down #${e}, identifier:${A.pointerId}`);const t=this.getAndUpdateSpatialObjectForScreenPosition(e,A.clientX,A.clientY),i=new ma("pointerdown",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:e,button:A.button,clientX:A.clientX,clientY:A.clientY,pointerType:A.pointerType,buttonName:this.getButtonName(A),device:t,pressure:A.pressure});this.onDown(i)});B(this,"onPointerMove",A=>{if(this.context.isInAR)return;let e=A.button;A.pointerType==="mouse"&&(e=this.getFirstPressedButtonForPointer(0)??0);const t=this.getPointerId(A,e);e===-1&&(e=t);const i=this.getAndUpdateSpatialObjectForScreenPosition(t,A.clientX,A.clientY),I=new ma("pointermove",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:t,button:e,clientX:A.clientX,clientY:A.clientY,pointerType:A.pointerType,buttonName:this.getButtonName(A),device:i,pressure:A.pressure});this.onMove(I)});B(this,"onPointerCancel",A=>{this.context.isInAR||(Dg&&console.log("Pointer cancel",A),this.onPointerUp(A))});B(this,"onPointerUp",A=>{if(this.context.isInAR)return;A.target instanceof HTMLElement&&A.target.releasePointerCapture(A.pointerId);const e=this.getPointerId(A),t=new ma("pointerup",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:e,button:A.button,clientX:A.clientX,clientY:A.clientY,pointerType:A.pointerType,buttonName:this.getButtonName(A),device:this.getAndUpdateSpatialObjectForScreenPosition(e,A.clientX,A.clientY),pressure:A.pressure});this.onUp(t),this._pointerIds[e]=-1,Dg&&console.log("ID="+e,"PointerId="+A.pointerId,"ALL:",[...this._pointerIds])});B(this,"onTouchStart",A=>{if(this.context.isInAR)for(let e=0;e<A.changedTouches.length;e++){const t=A.changedTouches[e],i=this.getPointerIndex(t.identifier),I=this.getAndUpdateSpatialObjectForScreenPosition(i,t.clientX,t.clientY),o=new ma("pointerdown",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:i,button:0,clientX:t.clientX,clientY:t.clientY,pointerType:"touch",buttonName:"unknown",device:I,pressure:t.force});this.onDown(o)}});B(this,"onTouchMove",A=>{if(this.context.isInAR)for(let e=0;e<A.changedTouches.length;e++){const t=A.changedTouches[e],i=this.getPointerIndex(t.identifier),I=this.getAndUpdateSpatialObjectForScreenPosition(i,t.clientX,t.clientY),o=new ma("pointermove",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:i,button:0,clientX:t.clientX,clientY:t.clientY,pointerType:"touch",buttonName:"unknown",device:I,pressure:t.force});this.onMove(o)}});B(this,"onTouchEnd",A=>{if(this.context.isInAR)for(let e=0;e<A.changedTouches.length;e++){const t=A.changedTouches[e],i=this.getPointerIndex(t.identifier),I=new ma("pointerup",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:i,button:0,clientX:t.clientX,clientY:t.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(i,t.clientX,t.clientY),pressure:t.force});this.onUp(I),this._pointerIds[i]=-1}});B(this,"tempNearPlaneVector",new y);B(this,"tempFarPlaneVector",new y);B(this,"tempLookMatrix",new fA);this.context=A,this.context.post_render_callbacks.push(this.onEndOfFrame)}addEventListener(A,e,t){if(this._eventListeners[A]||(this._eventListeners[A]=[]),!e||typeof e!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}t?t={...t}:t={};let i=0;(t==null?void 0:t.queue)!=null&&(i=t.queue);const I=this._eventListeners[A],o=I.find(s=>s.priority===i);o?o.listeners.push({callback:e,options:t}):(I.push({priority:i,listeners:[{callback:e,options:t}]}),I.sort((s,n)=>s.priority-n.priority))}removeEventListener(A,e,t){if(!this._eventListeners[A]||!e)return;const i=this._eventListeners[A];if((t==null?void 0:t.queue)!=null){const I=i.find(s=>s.priority===t.queue);if(!I)return;const o=I.listeners.findIndex(s=>s.callback===e);o>=0&&I.listeners.splice(o,1)}else for(const I of i){const o=I.listeners.findIndex(s=>s.callback===e);o>=0&&I.listeners.splice(o,1)}}dispatchEvent(A){var t,i,I,o;let e=!1;if(A instanceof ep){const s=this._eventListeners[A.type];if(s)for(const n of s)for(let r=0;r<n.listeners.length;r++){const a=n.listeners[r];if((i=(t=a.options)==null?void 0:t.signal)!=null&&i.aborted){n.listeners.splice(r,1),r--;continue}a.options.once&&(n.listeners.splice(r,1),r--),a.callback(A)}}if(A instanceof ma){const s=this._eventListeners[A.type];if(s)for(const n of s){if(e)break;for(let r=0;r<n.listeners.length;r++){const a=n.listeners[r];if((o=(I=a.options)==null?void 0:I.signal)!=null&&o.aborted){n.listeners.splice(r,1),r--;continue}if(A.immediatePropagationStopped){e=!0,Dg&&console.log("immediatePropagationStopped",A.type);break}else A.propagationStopped&&(e=!0,Dg&&console.log("propagationStopped",A.type));a.options.once&&(n.listeners.splice(r,1),r--),a.callback(A)}}}}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}setCursorPointer(){this._specialCursorTrigger+=1,this.context.domElement.style.cursor="pointer"}setCursorNormal(){this._specialCursorTrigger-=1,this._specialCursorTrigger=Math.max(0,this._specialCursorTrigger),this._specialCursorTrigger===0&&(this.context.domElement.style.cursor="default")}setPointerUsed(A,e=!0){if(A>=this._pointerUsed.length){if(A>=this._pointerIds.length)return;for(;this._pointerUsed.length<=A;)this._pointerUsed.push(!1)}this._pointerUsed[A]=e}getPointerUsed(A){return A>=this._pointerUsed.length?!1:this._pointerUsed[A]}getPointerPressedCount(){let A=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&A++;return A}getPointerPosition(A){return A>=this._pointerPositions.length?null:this._pointerPositions[A]}getPointerPositionLastFrame(A){return A>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[A]}getPointerPositionDelta(A){return A>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[A]}getPointerPositionRC(A){return A>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[A]}getPointerDown(A){return A>=this._pointerDown.length?!1:this._pointerDown[A]}getPointerUp(A){return A>=this._pointerUp.length?!1:this._pointerUp[A]}getPointerPressed(A){return A>=this._pointerPressed.length?!1:this._pointerPressed[A]}getPointerClicked(A){return A>=this._pointerClick.length?!1:this._pointerClick[A]}getPointerDoubleClicked(A){return A>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[A]}getPointerDownTime(A){return A>=this._pointerDownTime.length?-1:this._pointerDownTime[A]}getPointerUpTime(A){return A>=this._pointerUpTime.length?-1:this._pointerUpTime[A]}getPointerLongPress(A){return A>=this._pointerDownTime.length?!1:this.getPointerPressed(A)&&this.context.time.time-this._pointerDownTime[A]>this._longPressTimeThreshold}getIsMouse(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="mouse"}getIsTouch(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="touch"}getTouchesPressedCount(){let A=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&this.getIsTouch(e)&&A++;return A}getMouseWheelChanged(A=0){return A>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[A]}getMouseWheelDeltaY(A=0){return A>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[A]}getPointerEvent(A){if(!(A>=this._pointerEvent.length))return this._pointerEvent[A]??void 0}*foreachPointerId(A){for(let e=0;e<this._pointerTypes.length;e++)if(this._pointerIsActive(e)){if(A!==void 0){const t=this._pointerTypes[e];if(Array.isArray(A)){let i=!1;for(const I of A)if(t===I){i=!0;break}if(!i)continue}else if(A!==t)continue}yield e}}*foreachTouchId(){for(let A=0;A<this._pointerTypes.length;A++)this._pointerTypes[A]==="touch"&&this._pointerIsActive[A]&&(yield A)}_pointerIsActive(A){return A<0?!1:this._pointerPressed[A]||this._pointerDown[A]||this._pointerUp[A]}onDownButton(A,e){let t=this._pressedStack.get(A);t||(t=[],this._pressedStack.set(A,t)),t.push(e)}onReleaseButton(A,e){const t=this._pressedStack.get(A);if(!t)return;const i=t.indexOf(e);i>=0&&t.splice(i,1)}getFirstPressedButtonForPointer(A){const e=this._pressedStack.get(A);if(e)return e[0]}getLatestPressedButtonForPointer(A){const e=this._pressedStack.get(A);if(e)return e[e.length-1]}getKeyDown(){for(const A in this.keysPressed){const e=this.keysPressed[A];if(e.startFrame===this.context.time.frameCount)return e.key}return null}getKeyPressed(){for(const A in this.keysPressed){const e=this.keysPressed[A];if(e.pressed)return e.key}return null}isKeyDown(A){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyDown(i))return!0;return!1}return((t=this.keysPressed[A])==null?void 0:t.startFrame)===this.context.time.frameCount&&this.keysPressed[A].pressed}isKeyUp(A){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyUp(i))return!0;return!1}return((t=this.keysPressed[A])==null?void 0:t.frame)===this.context.time.frameCount&&!this.keysPressed[A].pressed}isKeyPressed(A){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyPressed(i))return!0;return!1}return(t=this.keysPressed[A])==null?void 0:t.pressed}getCodeForCommonKeyName(A){if(A.length===1){if(A>="0"&&A<="9")return["Digit"+A];if(A>="a"&&A<="z")return["Key"+A.toUpperCase()];if(A==" ")return["Space"]}switch(A){case"shift":case"Shift":return["ShiftLeft","ShiftRight"];case"control":case"Control":return["ControlLeft","ControlRight"];case"alt":case"Alt":return["AltLeft","AltRight"]}return null}createInputEvent(A){switch(A.type){case"pointerdown":Dg&&fi("Create Pointer down"),this.onDownButton(A.deviceIndex,A.button),this.onDown(A);break;case"pointermove":Dg&&fi("Create Pointer move"),this.onMove(A);break;case"pointerup":Dg&&fi("Create Pointer up"),this.onUp(A),this.onReleaseButton(A.deviceIndex,A.button);break}}convertScreenspaceToRaycastSpace(A){return A.x=(A.x-this.context.domX)/this.context.domWidth*2-1,A.y=-((A.y-this.context.domY)/this.context.domHeight)*2+1,A}bindEvents(){this.unbindEvents(),this._htmlEventSource=this.context.renderer.domElement,window.addEventListener("contextmenu",this.onContextMenu),this._htmlEventSource.addEventListener("pointerdown",this.onPointerDown,{passive:!0}),window.addEventListener("pointermove",this.onPointerMove,{passive:!0,capture:!0}),window.addEventListener("pointerup",this.onPointerUp,{passive:!0}),window.addEventListener("pointercancel",this.onPointerCancel,{passive:!0}),window.addEventListener("touchstart",this.onTouchStart,{passive:!0}),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchEnd,{passive:!0}),this._htmlEventSource.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("wheel",this.onWheelWindow,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}unbindEvents(){var A,e;window.removeEventListener("contextmenu",this.onContextMenu),(A=this._htmlEventSource)==null||A.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerCancel),(e=this._htmlEventSource)==null||e.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("wheel",this.onWheelWindow,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}dispose(){const A=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);A>=0&&this.context.post_render_callbacks.splice(A,1),this.unbindEvents()}canReceiveInput(A){var e;return A.target===((e=this.context.renderer)==null?void 0:e.domElement)||A.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&A.target===document.body&&Ec()?!0:(Dg&&console.warn("CanReceiveInput:False for",A.target),!1)}getPointerId(A,e){return A.pointerType==="mouse"?0+(e??A.button):this.getPointerIndex(A.pointerId)}getButtonName(A){const e=A.button;if(A.pointerType==="mouse")switch(e){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}getAndUpdateSpatialObjectForScreenPosition(A,e,t){let i=this._pointerSpace[A];i||(i=new DA,this._pointerSpace[A]=i),this._pointerSpace[A]=i;const I=this.context.mainCamera;if(I){const o=this.tempNearPlaneVector.set(e,t,-1);this.convertScreenspaceToRaycastSpace(o);const s=this.tempFarPlaneVector.set(o.x,o.y,1);o.unproject(I),s.unproject(I);const n=I.worldUp||dt(0,1,0).applyQuaternion(Jt(I));this.tempLookMatrix.lookAt(s,o,n),i.position.set(o.x,o.y,o.z),i.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return i}isInRect(A){if(this.context.isInXR)return!0;const e=this.context.domElement.getBoundingClientRect(),t=A.clientX,i=A.clientY,I=t>=e.x&&t<=e.right&&i>=e.y&&i<=e.bottom;return Dg&&!I&&console.log("Not in rect",e,t,i),I}onDown(A){const e=A.pointerId;if(this.getPointerPressed(e)&&console.warn(`pointerId is already pressed: ${e}`,Dg?A:""),Dg&&console.log(A.pointerType,"DOWN",e),!!this.isInRect(A)){for(this.setPointerState(e,this._pointerPressed,!0),this.setPointerState(e,this._pointerDown,!0),this.setPointerStateT(e,this._pointerEvent,A.source);e>=this._pointerTypes.length;)this._pointerTypes.push(A.pointerType);for(this._pointerTypes[e]=A.pointerType;e>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new tA);for(this._pointerPositionDown[e].set(A.clientX,A.clientY);e>=this._pointerPositions.length;)this._pointerPositions.push(new tA);this._pointerPositions[e].set(A.clientX,A.clientY),e>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[e]=this.context.time.time,this.updatePointerPosition(A),this.onDispatchEvent(A)}}onMove(A){const e=A.pointerId,t=this.getPointerPressed(e);t===!1&&!this.isInRect(A)||A.pointerType==="touch"&&!t||(this.updatePointerPosition(A),this.setPointerStateT(e,this._pointerEvent,A.source),this.onDispatchEvent(A))}onUp(A){const e=A.pointerId;if(!this.getPointerPressed(e)){Dg&&console.log(A.pointerType,"UP",e,"was not down");return}for(Dg&&console.log(A.pointerType,"UP",e),this.setPointerState(e,this._pointerPressed,!1),this.setPointerStateT(e,this._pointerEvent,A.source),this.setPointerState(e,this._pointerUp,!0);e>=this._pointerUsed.length;)this._pointerUsed.push(!1);if(this.setPointerState(e,this._pointerUsed,!1),this.updatePointerPosition(A),!this._pointerPositionDown[e]){Dg&&Ot("Received pointer up event without matching down event for button: "+e),console.warn("Received pointer up event without matching down event for button: "+e);return}const i=A.clientX-this._pointerPositionDown[e].x,I=A.clientY-this._pointerPositionDown[e].y;if(e>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),Math.abs(i)<5&&Math.abs(I)<5){Dg&&console.log("CLICK",e),this.setPointerState(e,this._pointerClick,!0),A.isClick=!0;const o=this._pointerUpTime[e],s=this.context.time.time-o;s<this._doubleClickTimeThreshold&&s>0&&(this.setPointerState(e,this._pointerDoubleClick,!0),A.isDoubleClick=!0)}this._pointerUpTime[e]=this.context.time.time,this.onDispatchEvent(A)}updatePointerPosition(A){const e=A.pointerId;for(;e>=this._pointerPositions.length;)this._pointerPositions.push(new tA);for(;e>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new tA);for(;e>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new tA);const t=this._pointerPositionsLastFrame[e];t.copy(this._pointerPositions[e]);const i=this._pointerPositionsDelta[e];let I=A.clientX-t.x,o=A.clientY-t.y;if(A.source instanceof MouseEvent||A.source instanceof TouchEvent){const a=A.source;I===0&&a.movementX!==0&&(I=a.movementX||0),o===0&&a.movementY!==0&&(o=a.movementY||0)}i.x+=I,i.y+=o,this._pointerPositions[e].x=A.clientX,this._pointerPositions[e].y=A.clientY;const s=A.clientX,n=A.clientY;for(;e>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new tA);const r=this._pointerPositionsRC[e];r.set(s,n),this.convertScreenspaceToRaycastSpace(r)}getPointerIndex(A){let e=-1;for(let t=0;t<this._pointerIds.length;t++){if(this._pointerIds[t]===A)return t;e===-1&&this._pointerIds[t]===-1&&(e=t)}return e!==-1?(this._pointerIds[e]=A,e):(Dg&&console.log("PUSH pointerId:",A),this._pointerIds.push(A),this._pointerIds.length-1)}setPointerState(A,e,t){e[A]=t}setPointerStateT(A,e,t){return e[A]=t,t}onDispatchEvent(A){const e=be.Current;try{be.Current=this.context,this.dispatchEvent(A)}finally{be.Current=e}}}const Bm=new fA().makeRotationY(Math.PI),bs=new GA().setFromAxisAngle(new y(0,1,0),Math.PI),$BA=gA("debugwebxr");class AQA{constructor(){B(this,"priority",-1e5);B(this,"gameObject");if(this.gameObject=new DA,this.gameObject.name="Implicit XR Rig",$BA){const A=Hx(16733661);A.position.y+=.5,this.gameObject.add(A)}}isXRRig(){return!0}get isActive(){return this.gameObject.visible}}const TC=gA("debugwebxr"),gS=gA("debugcustomgesture"),eQA="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",tQA="generic-trigger";class Yx{constructor(A,e,t){B(this,"xr");B(this,"inputSource");B(this,"index",0);B(this,"emitEvents",!0);B(this,"_connected",!0);B(this,"_isTracking",!1);B(this,"_hitTestSource");B(this,"_hasSelectEvent",!1);B(this,"_handJointPoses",new Map);B(this,"_gripPosition",new y);B(this,"_gripQuaternion",new GA);B(this,"_linearVelocity",new y);B(this,"_rayPosition",new y);B(this,"_rayQuaternion",new GA);B(this,"_gripWorldPosition",new y);B(this,"_gripWorldQuaternion",new GA);B(this,"_rayWorldPosition",new y);B(this,"_rayWorldQuaternion",new GA);B(this,"_ray");B(this,"_object");B(this,"model",null);B(this,"_debugAxesHelper",new Qs(.2));B(this,"onPointerHits",A=>{});B(this,"_needleGamepadButtons",{});B(this,"_buttonMap",new Map);B(this,"_motioncontroller");B(this,"_layout");B(this,"getMotionController");B(this,"_selectButtonIndex");B(this,"_squeezeButtonIndex");B(this,"onSelectStart",A=>{var i,I,o,s;if(this.inputSource!==A.inputSource)return;this.onUpdateFrame(A.frame),this._hasSelectEvent=!0;const e=(i=this._layout)==null?void 0:i.selectComponentId,t=(s=(o=(I=this._layout)==null?void 0:I.components[e])==null?void 0:o.gamepadIndices)==null?void 0:s.button;t!==void 0&&(this._selectButtonIndex=t),!gS&&(TC&&fe.DrawDirection(this.rayWorldPosition,dt(0,.01,1).applyQuaternion(this.rayWorldQuaternion),16711680,10),this.emitPointerEvent(pi.PointerDown,this._selectButtonIndex||0,"xr-standard-trigger",!0,A))});B(this,"onSelectEnd",A=>{gS||this.inputSource===A.inputSource&&this.emitPointerEvent(pi.PointerUp,this._selectButtonIndex||0,"xr-standard-trigger",!0,A)});B(this,"onSequeezeStart",A=>{var e,t,i;this.inputSource===A.inputSource&&(this._squeezeButtonIndex=(i=(t=(e=this._layout)==null?void 0:e.components["xr-standard-squeeze"])==null?void 0:t.gamepadIndices)==null?void 0:i.button,this._squeezeButtonIndex!==void 0&&(TC&&fe.DrawDirection(this.rayWorldPosition,dt(0,.01,1).applyQuaternion(this.rayWorldQuaternion),255,10),this.emitPointerEvent(pi.PointerDown,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,A)))});B(this,"onSequeezeEnd",A=>{this.inputSource===A.inputSource&&this._squeezeButtonIndex!==void 0&&this.emitPointerEvent(pi.PointerUp,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,A)});B(this,"states",{});B(this,"_didMoveLastFrame",!1);B(this,"_lastPointerMovePosition",new y);B(this,"_lastPointerMoveQuaternion",new GA);B(this,"pointerInit");var i,I,o;this.xr=A,this.inputSource=e,this.index=t,this._object=new DA,TC&&this._object.add(this._debugAxesHelper),this.xr.context.scene.add(this._object),this._ray=new xo,this.pointerInit={origin:this,pointerType:this.hand?"hand":"controller",deviceIndex:this.index,pointerId:-1,mode:this.inputSource.targetRayMode,ray:this._ray,device:this._object,buttonName:"none"},this.initialize(),this.subscribeEvents(),this.xr.mode==="immersive-ar"&&this.inputSource.targetRayMode==="tracked-pointer"&&((o=(I=(i=this.xr.session).requestHitTestSourceForTransientInput)==null?void 0:I.call(i,{profile:this.inputSource.profiles[0],offsetRay:new XRRay}))==null||o.then(s=>this._hitTestSource=s))}get context(){return this.xr.context}get connected(){return this._connected}get isTracking(){return this._isTracking}get gamepad(){return this.inputSource.gamepad}get isHand(){return this.inputSource.hand!=null}get hand(){return this.inputSource.hand}get handObject(){return this.context.renderer.xr.getHand(this.index)}get profiles(){return this.inputSource.profiles}get layout(){return this._layout}get targetRayMode(){return this.inputSource.targetRayMode}get targetRaySpace(){return this.inputSource.targetRaySpace}get gripSpace(){return this.inputSource.gripSpace}get side(){return this.inputSource.handedness}get isRight(){return this.side==="right"}get isLeft(){return this.side==="left"}get hitTestSource(){return this._hitTestSource}get hasSelectEvent(){return this._hasSelectEvent}getHitTest(){return this.xr.getHitTest(this)}getHandJointPose(A){var t,i;if(!this.hand||!((t=this.xr.frame)!=null&&t.getJointPose)||!this.xr.referenceSpace)return null;let e=(i=this._handJointPoses)==null?void 0:i.get(A);return e||(e=this.xr.frame.getJointPose(A,this.xr.referenceSpace),e&&this._handJointPoses.set(A,e),e)}get gripPosition(){return dt(this._gripPosition).applyMatrix4(Bm)}get gripQuaternion(){return gc(this._gripQuaternion).premultiply(bs)}get gripLinearVelocity(){return dt(this._linearVelocity).applyQuaternion(bs)}get rayPosition(){return dt(this._rayPosition).applyMatrix4(Bm)}get rayQuaternion(){return gc(this._rayQuaternion).premultiply(bs)}get gripWorldPosition(){return dt(this._gripWorldPosition)}get gripWorldQuaternion(){return gc(this._gripWorldQuaternion)}get rayWorldPosition(){return dt(this._rayWorldPosition)}updateRayWorldPosition(){var e;const A=(e=this.xr.context.mainCamera)==null?void 0:e.parent;this._rayWorldPosition.copy(this._rayPosition),A&&this._rayWorldPosition.applyMatrix4(A.matrixWorld)}get rayWorldQuaternion(){return gc(this._rayWorldQuaternion)}updateRayWorldQuaternion(){var t;const A=(t=this.xr.context.mainCamera)==null?void 0:t.parent,e=A?Jt(A):void 0;this._rayWorldQuaternion.copy(this._rayQuaternion).multiply(bs),e&&this._rayWorldQuaternion.premultiply(e)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy(dt(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}get object(){return this._object}async getModelUrl(){var A;return(A=this.getMotionController)==null?void 0:A.then(e=>(e==null?void 0:e.assetUrl)||null)}onUpdate(A){this.onUpdateFrame(A),this.updateInputEvents(),this.onUpdateMove()}onRenderDebug(){var i;fe.DrawWireSphere(this.rayWorldPosition,.02),fe.DrawDirection(this.rayWorldPosition,dt(0,0,10).applyQuaternion(this.rayWorldQuaternion));const A=this.gripWorldPosition.sub(this.object.worldForward.multiplyScalar(.1)),e=this.inputSource.profiles.join(`
|
|
5151
|
+
*/var KBA=function(g){return g!=null&&(QW(g)||bBA(g)||!!g._isBuffer)};function QW(g){return!!g.constructor&&typeof g.constructor.isBuffer=="function"&&g.constructor.isBuffer(g)}function bBA(g){return typeof g.readFloatLE=="function"&&typeof g.slice=="function"&&QW(g.slice(0,0))}(function(){var g=FBA,A=DY.utf8,e=KBA,t=DY.bin,i=function(I,o){I.constructor==String?o&&o.encoding==="binary"?I=t.stringToBytes(I):I=A.stringToBytes(I):e(I)?I=Array.prototype.slice.call(I,0):!Array.isArray(I)&&I.constructor!==Uint8Array&&(I=I.toString());for(var s=g.bytesToWords(I),n=I.length*8,r=1732584193,a=-271733879,C=-1732584194,Q=271733878,c=0;c<s.length;c++)s[c]=(s[c]<<8|s[c]>>>24)&16711935|(s[c]<<24|s[c]>>>8)&4278255360;s[n>>>5]|=128<<n%32,s[(n+64>>>9<<4)+14]=n;for(var E=i._ff,h=i._gg,l=i._hh,d=i._ii,c=0;c<s.length;c+=16){var p=r,u=a,f=C,w=Q;r=E(r,a,C,Q,s[c+0],7,-680876936),Q=E(Q,r,a,C,s[c+1],12,-389564586),C=E(C,Q,r,a,s[c+2],17,606105819),a=E(a,C,Q,r,s[c+3],22,-1044525330),r=E(r,a,C,Q,s[c+4],7,-176418897),Q=E(Q,r,a,C,s[c+5],12,1200080426),C=E(C,Q,r,a,s[c+6],17,-1473231341),a=E(a,C,Q,r,s[c+7],22,-45705983),r=E(r,a,C,Q,s[c+8],7,1770035416),Q=E(Q,r,a,C,s[c+9],12,-1958414417),C=E(C,Q,r,a,s[c+10],17,-42063),a=E(a,C,Q,r,s[c+11],22,-1990404162),r=E(r,a,C,Q,s[c+12],7,1804603682),Q=E(Q,r,a,C,s[c+13],12,-40341101),C=E(C,Q,r,a,s[c+14],17,-1502002290),a=E(a,C,Q,r,s[c+15],22,1236535329),r=h(r,a,C,Q,s[c+1],5,-165796510),Q=h(Q,r,a,C,s[c+6],9,-1069501632),C=h(C,Q,r,a,s[c+11],14,643717713),a=h(a,C,Q,r,s[c+0],20,-373897302),r=h(r,a,C,Q,s[c+5],5,-701558691),Q=h(Q,r,a,C,s[c+10],9,38016083),C=h(C,Q,r,a,s[c+15],14,-660478335),a=h(a,C,Q,r,s[c+4],20,-405537848),r=h(r,a,C,Q,s[c+9],5,568446438),Q=h(Q,r,a,C,s[c+14],9,-1019803690),C=h(C,Q,r,a,s[c+3],14,-187363961),a=h(a,C,Q,r,s[c+8],20,1163531501),r=h(r,a,C,Q,s[c+13],5,-1444681467),Q=h(Q,r,a,C,s[c+2],9,-51403784),C=h(C,Q,r,a,s[c+7],14,1735328473),a=h(a,C,Q,r,s[c+12],20,-1926607734),r=l(r,a,C,Q,s[c+5],4,-378558),Q=l(Q,r,a,C,s[c+8],11,-2022574463),C=l(C,Q,r,a,s[c+11],16,1839030562),a=l(a,C,Q,r,s[c+14],23,-35309556),r=l(r,a,C,Q,s[c+1],4,-1530992060),Q=l(Q,r,a,C,s[c+4],11,1272893353),C=l(C,Q,r,a,s[c+7],16,-155497632),a=l(a,C,Q,r,s[c+10],23,-1094730640),r=l(r,a,C,Q,s[c+13],4,681279174),Q=l(Q,r,a,C,s[c+0],11,-358537222),C=l(C,Q,r,a,s[c+3],16,-722521979),a=l(a,C,Q,r,s[c+6],23,76029189),r=l(r,a,C,Q,s[c+9],4,-640364487),Q=l(Q,r,a,C,s[c+12],11,-421815835),C=l(C,Q,r,a,s[c+15],16,530742520),a=l(a,C,Q,r,s[c+2],23,-995338651),r=d(r,a,C,Q,s[c+0],6,-198630844),Q=d(Q,r,a,C,s[c+7],10,1126891415),C=d(C,Q,r,a,s[c+14],15,-1416354905),a=d(a,C,Q,r,s[c+5],21,-57434055),r=d(r,a,C,Q,s[c+12],6,1700485571),Q=d(Q,r,a,C,s[c+3],10,-1894986606),C=d(C,Q,r,a,s[c+10],15,-1051523),a=d(a,C,Q,r,s[c+1],21,-2054922799),r=d(r,a,C,Q,s[c+8],6,1873313359),Q=d(Q,r,a,C,s[c+15],10,-30611744),C=d(C,Q,r,a,s[c+6],15,-1560198380),a=d(a,C,Q,r,s[c+13],21,1309151649),r=d(r,a,C,Q,s[c+4],6,-145523070),Q=d(Q,r,a,C,s[c+11],10,-1120210379),C=d(C,Q,r,a,s[c+2],15,718787259),a=d(a,C,Q,r,s[c+9],21,-343485551),r=r+p>>>0,a=a+u>>>0,C=C+f>>>0,Q=Q+w>>>0}return g.endian([r,a,C,Q])};i._ff=function(I,o,s,n,r,a,C){var Q=I+(o&s|~o&n)+(r>>>0)+C;return(Q<<a|Q>>>32-a)+o},i._gg=function(I,o,s,n,r,a,C){var Q=I+(o&n|s&~n)+(r>>>0)+C;return(Q<<a|Q>>>32-a)+o},i._hh=function(I,o,s,n,r,a,C){var Q=I+(o^s^n)+(r>>>0)+C;return(Q<<a|Q>>>32-a)+o},i._ii=function(I,o,s,n,r,a,C){var Q=I+(s^(o|~n))+(r>>>0)+C;return(Q<<a|Q>>>32-a)+o},i._blocksize=16,i._digestsize=16,CW.exports=function(I,o){if(I==null)throw new Error("Illegal argument "+I);var s=g.wordsToBytes(i(I,o));return o&&o.asBytes?s:o&&o.asString?t.bytesToString(s):g.bytesToHex(s)}})();var JBA=CW.exports;const xBA=tM(JBA);class kK{constructor(A,e,t,i){B(this,"success");B(this,"filename");B(this,"hash");B(this,"size");B(this,"url");this.success=A,this.filename=e,this.hash=t,this.size=i}}async function cW(g,A){const e=await g.arrayBuffer(),t=Lx(e),i=g.name.split(".").pop(),I=t+"."+i,o=g.name.split(".").shift();console.assert(o!==void 0);const s={alias:o,filename:I},r=await(await fetch(A+"/exists",{method:"POST",body:JSON.stringify(s)})).json();if(r.success||console.warn("exists check did fail"),r.exists)return console.log("file already exists",t),new kK(!0,I,t,g.size);console.log("begin uploading file",o,g.size);const a=new FormData;a.append("file",g);const C={};C.filesize=g.size,o&&(C.alias=o);const c=await(await fetch(A+"/upload/file",{method:"POST",body:a,headers:C})).json();if((c==null?void 0:c.success)===!1)return c.message!==void 0?console.error("Upload failed:",c.message):console.error("Upload failed"),null;console.assert(c.hash_sum===t,"hash sum did not match","received:",c.hash_sum,"expected:",t),c.success&&console.log("successfully uploaded",t,c.id);const E=new kK(c.success,I,t,g.size);return E.url=A,E}function Lx(g){return xBA(new Uint8Array(g))}async function _x(g,A,e,t,i=!1){try{const I=await fetch(t+"/download/file",{method:"POST",body:g});if(I.status!==200)return console.error("download failed",I),null;const o=await I.blob(),s=await o.arrayBuffer();i||console.assert(o.size===e,"size mismatch","expected:",e,"got:",o.size);const n=Lx(s);return i||console.assert(n===A,"hash mismatch, downloaded file is invalid"),o.arrayBuffer()}catch(I){console.error(I)}return null}async function EW(g,A){var a;const e=await fetch(g),t=(a=e.body)==null?void 0:a.getReader(),i=e.headers.get("Content-Length"),I=i?parseInt(i):0;if(!t)return null;let o=0;const s=[];for(;;){const{done:C,value:Q}=await t.read();if(Q&&(s.push(Q),o+=Q.length,A.call(null,new ProgressEvent("progress",{loaded:o,total:I}))),C)break}const n=new Uint8Array(o);let r=0;for(const C of s)n.set(C,r),r+=C.length;return n}const _C=gA("debugaddressables");class lW{constructor(A){B(this,"_context");B(this,"_assetReferences",{});B(this,"preUpdate",()=>{});this._context=A,this._context.pre_update_callbacks.push(this.preUpdate)}dispose(){const A=this._context.pre_update_callbacks.indexOf(this.preUpdate);A>=0&&this._context.pre_update_callbacks.splice(A,1);for(const e in this._assetReferences){const t=this._assetReferences[e];t==null||t.unload()}this._assetReferences={}}findAssetReference(A){return this._assetReferences[A]||null}registerAssetReference(A){return A.uri&&(this._assetReferences[A.uri]?console.warn("Asset reference already registered",A):this._assetReferences[A.uri]=A),A}unregisterAssetReference(A){A.uri&&delete this._assetReferences[A.uri]}}const bU=Symbol("assetReference"),XQ=class{constructor(A,e,t=null){B(this,"_loading");B(this,"_asset");B(this,"_glbRoot");B(this,"_url");B(this,"_progressListeners",[]);B(this,"_hash");B(this,"_hashedUri");B(this,"_isLoadingRawBinary",!1);B(this,"_rawBinary");this._url=A,this._hash=e,A.includes("?v=")?this._hashedUri=A:this._hashedUri=e?A+"?v="+e:A,t!==null&&(this.asset=t),LZ(this._url,this.onResolvePrefab.bind(this))}static getOrCreateFromUrl(A,e){if(!e&&(e=be.Current,!e))throw new Error('Context is required when sourceId is a string. When you call this method from a component you can call it with "getOrCreate(this, url)" where "this" is the component.');const t=e.addressables,i=t.findAssetReference(A);if(i)return i;const I=new XQ(A,e.hash);return t.registerAssetReference(I),I}static getOrCreate(A,e,t){if(typeof A=="string"){if(!t&&(t=be.Current,!t))throw new Error('Context is required when sourceId is a string. When you call this method from a component you can call it with "getOrCreate(this, url)" where "this" is the component.')}else t=A.context,A=A.sourceId;const i=OB(A,e);_C&&console.log("GetOrCreate Addressable from",A,e,"FinalPath=",i);const I=t.addressables,o=I.findAssetReference(i);if(o)return o;const s=new XQ(i,t.hash);return I.registerAssetReference(s),s}get asset(){return this._glbRoot??this._asset}set asset(A){this._asset=A}get uri(){return this._url}get url(){return this._url}get hasUrl(){return this._url!==void 0&&(this._url.startsWith("http")||this._url.startsWith("blob:")||this._url.startsWith("www.")||this._url.includes("/"))}get rawAsset(){return this._asset}async onResolvePrefab(A){return A===this.uri&&(this.mustLoad&&await this.loadAssetAsync(),this.asset)?this.asset:null}get mustLoad(){return!this.asset||this.asset.__destroyed===!0||Yc(this.asset)===!0}isLoaded(){return this._rawBinary||this.asset!==void 0}unload(){this.asset&&(_C&&console.log("Unload",this.asset),this.asset.scene&&Vs(this.asset.scene,!0,!0),Vs(this.asset,!0,!0)),this.asset=null,this._rawBinary=void 0,this._glbRoot=null,this._loading=void 0,be.Current&&be.Current.addressables.unregisterAssetReference(this)}async preload(){if(!this.mustLoad||this._isLoadingRawBinary)return null;if(this._rawBinary!==void 0)return this._rawBinary;this._isLoadingRawBinary=!0,_C&&console.log("Preload",this._hashedUri);const A=await EW(this._hashedUri,e=>{this.raiseProgressEvent(e)});return this._rawBinary=(A==null?void 0:A.buffer)??null,this._isLoadingRawBinary=!1,this._rawBinary}async loadAssetAsync(A){if(_C&&console.log("loadAssetAsync",this.uri),!this.mustLoad)return this.asset;if(A&&this._progressListeners.push(A),this._loading!==void 0)return this._loading.then(i=>this.asset);const e=be.Current;this._rawBinary?(this._loading=Ln().parseSync(e,this._rawBinary,this.uri,null),this.raiseProgressEvent(new ProgressEvent("progress",{loaded:this._rawBinary.byteLength,total:this._rawBinary.byteLength}))):(_C&&console.log("Load async",this.uri),this._loading=Ln().loadSync(e,this._hashedUri,this.uri,null,i=>{this.raiseProgressEvent(i)}));const t=await this._loading;if(this._progressListeners.length=0,this._glbRoot=this.tryGetActualGameObjectRoot(t),this._loading=void 0,t)return t[bU]=this,this._glbRoot&&(this._glbRoot[bU]=this),this.asset&&(this.asset[bU]=this),nm(e),t.scene!==void 0&&(this.asset=t),this.asset}async instantiate(A){return this.onInstantiate(A,!1)}async instantiateSynced(A,e=!0){return this.onInstantiate(A,!0,e)}beginListenDownload(A){this._progressListeners.indexOf(A)<0&&this._progressListeners.push(A)}endListenDownload(A){const e=this._progressListeners.indexOf(A);e>=0&&this._progressListeners.splice(e,1)}raiseProgressEvent(A){for(const e of this._progressListeners)e(this,A)}async onInstantiate(A,e=!1,t){const i=be.Current,I=new Wn;if(A instanceof DA?I.parent=A:A&&(Object.assign(I,A),I.cloneAssign(A)),I.parent||(I.parent=i.scene),this.mustLoad&&await this.loadAssetAsync(),_C&&console.log("Instantiate",this.uri,"parent:",A),this.asset){_C&&console.log("Add to scene",this.asset);let o=XQ.currentlyInstantiating.get(this.uri);if(o!==void 0&&o>=1e4)return console.error("Recursive or too many instantiations of "+this.uri+" in the same frame ("+o+")"),null;try{if(o===void 0&&(o=0),o+=1,XQ.currentlyInstantiating.set(this.uri,o),e){I.context=i;const s=this.asset;s.guid=this.uri;const n=iv(s,I,void 0,t);if(n)return n}else{const s=Qd(this.asset,I);if(s)return s}}finally{i.post_render_callbacks.push(()=>{o===void 0||o<0?o=0:o-=1,XQ.currentlyInstantiating.set(this.uri,o)})}}else _C&&console.warn("Failed to load asset",this.uri);return null}tryGetActualGameObjectRoot(A){if(A&&A.scene){const e=A.scene;return e.isGroup&&e.children.length===1&&e.children[0].name+"glb"===e.name?e.children[0]:e}return null}};let et=XQ;B(et,"currentlyInstantiating",new Map);class vBA extends on{constructor(){super([et],"AssetReferenceSerializer")}onSerialize(A,e){if(A&&A.uri!==void 0&&typeof A.uri=="string")return A.uri}onDeserialize(A,e){if(typeof A=="string")return e.context?e.gltfId?et.getOrCreate(e.gltfId,A,e.context):(console.error("Missing source id"),null):(console.error("Missing context"),null);if(A instanceof DA){if(!e.context)return console.error("Missing context"),null;if(!e.gltfId)return console.error("Missing source id"),null;const t=A,i=e.context,I=t.guid??t.uuid,o=i.addressables.findAssetReference(I);if(o)return o;const s=new et(I,void 0,t);return i.addressables.registerAssetReference(s),s}return null}}new vBA;const qBA=Promise.resolve(null),Zp=class{constructor(A){B(this,"url");B(this,"_bitmap");B(this,"_bitmapObject");B(this,"loader",null);this.url=A}static getOrCreate(A){let e=Zp.imageReferences.get(A);return e||(e=new Zp(A),Zp.imageReferences.set(A,e)),e}dispose(){this._bitmapObject&&this._bitmapObject.close(),this._bitmap=void 0}createHTMLImage(){const A=new Image;return A.src=this.url,A}createTexture(){return this.url?(this.loader||(this.loader=new Rr),this.loader.setCrossOrigin("anonymous"),this.loader.loadAsync(this.url)):qBA}getBitmap(){return this._bitmap?this._bitmap:(this._bitmap=new Promise((A,e)=>{const t=document.createElement("img");t.addEventListener("load",()=>{this._bitmap=createImageBitmap(t).then(i=>(this._bitmapObject=i,A(i),i))}),t.addEventListener("error",i=>{console.error("Failed to load image:"+this.url,i),A(null)}),t.src=this.url}),this._bitmap)}};let lh=Zp;B(lh,"imageReferences",new Map);class hW extends on{constructor(){super([lh],"ImageReferenceSerializer")}onSerialize(A,e){return null}onDeserialize(A,e){if(typeof A=="string"){const t=OB(e.gltfId,A);return lh.getOrCreate(t)}}}new hW;const jp=class{constructor(A){B(this,"url");B(this,"res");this.url=A}static getOrCreate(A){let e=jp.cache.get(A);return e||(e=new jp(A),jp.cache.set(A,e)),e}async loadRaw(){return this.res||(this.res=fetch(this.url)),this.res.then(A=>A.blob())}async loadText(){return this.res||(this.res=fetch(this.url)),this.res.then(A=>A.text())}};let hh=jp;B(hh,"cache",new Map);class dW extends on{constructor(){super([hh],"FileReferenceSerializer")}onSerialize(A,e){return null}onDeserialize(A,e){if(typeof A=="string"){const t=OB(e.gltfId,A);return hh.getOrCreate(t)}}}new dW;class LBA{constructor(A){B(this,"context");B(this,"mixers",[]);this.context=A}onDestroy(){this.mixers.forEach(A=>A.stopAllAction()),this.mixers.length=0}registerAnimationMixer(A){if(!A){console.warn("AnimationsRegistry.registerAnimationMixer called with null or undefined mixer");return}this.mixers.includes(A)||this.mixers.push(A)}unregisterAnimationMixer(A){if(!A)return;const e=this.mixers.indexOf(A);e!==-1&&this.mixers.splice(e,1)}}class vh{static tryGetActionsFromMixer(A){const e=A._actions;return e||null}static tryGetAnimationClipsFromObjectHierarchy(A,e){if(e||(e=new Array),A)A.animations&&e.push(...A.animations);else return e;if(A.children)for(const t of A.children)this.tryGetAnimationClipsFromObjectHierarchy(t,e);return e}static assignAnimationsFromFile(A,e){if(!A||!A.animations)return;for(let i=0;i<A.animations.length;i++){const I=A.animations[i];if(!(!I.tracks||I.tracks.length<=0))for(const o in I.tracks){const s=I.tracks[o],n=Xe.parseTrackName(s.name);let r=Xe.findNode(A.scene,n.nodeName);if(!r){const C=s.__objectName??s.name.substring(0,s.name.indexOf("."));if(r=A.scene.getObjectByProperty("uuid",C),!r)continue}let a=t(r);if(!a){if(!(e!=null&&e.createAnimationComponent)){console.warn("No AnimationComponent found in parent hierarchy of object and no 'createAnimationComponent' callback was provided in options.");continue}a=e.createAnimationComponent(A.scene,I)}a.addClip&&a.addClip(I)}}function t(i){var o;if(!i)return null;const I=(o=i.userData)==null?void 0:o.components;if(I&&I.length>0){for(let s=0;s<I.length;s++)if(I[s].isAnimationComponent===!0)return i}return t(i.parent)}}}const qh=[];function iM(g){qh.indexOf(g)===-1&&qh.push(g)}function _BA(g){const A=qh.indexOf(g);A!==-1&&qh.splice(A,1)}const Lh=[];function Tx(g){Lh.indexOf(g)===-1&&Lh.push(g)}function TBA(g){const A=Lh.indexOf(g);A!==-1&&Lh.splice(A,1)}function uW(g){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-start",{detail:g}));for(let A=0;A<qh.length;A++)qh[A](g)}function pW(g){globalThis.dispatchEvent(new CustomEvent("needle-xrsession-end",{detail:g}));for(let A=0;A<Lh.length;A++)Lh[A](g)}const Yg={Handedness:Object.freeze({NONE:"none",LEFT:"left",RIGHT:"right"}),ComponentState:Object.freeze({DEFAULT:"default",TOUCHED:"touched",PRESSED:"pressed"}),ComponentProperty:Object.freeze({BUTTON:"button",X_AXIS:"xAxis",Y_AXIS:"yAxis",STATE:"state"}),ComponentType:Object.freeze({TRIGGER:"trigger",SQUEEZE:"squeeze",TOUCHPAD:"touchpad",THUMBSTICK:"thumbstick",BUTTON:"button"}),ButtonTouchThreshold:.05,AxisTouchThreshold:.1,VisualResponseProperty:Object.freeze({TRANSFORM:"transform",VISIBILITY:"visibility"})};async function fW(g){const A=await fetch(g);if(A.ok)return A.json();throw new Error(A.statusText)}async function HBA(g){if(!g)throw new Error("No basePath supplied");return await fW(`${g}/profilesList.json`)}async function YBA(g,A,e=null,t=!0){if(!g)throw new Error("No xrInputSource supplied");if(!A)throw new Error("No basePath supplied");const i=await HBA(A);let I;if(g.profiles.some(n=>{const r=i[n];return r&&(I={profileId:n,profilePath:`${A}/${r.path}`,deprecated:!!r.deprecated}),!!I}),!I){if(!e)throw new Error("No matching profile name found");const n=i[e];if(!n)throw new Error(`No matching profile name found and default profile "${e}" missing.`);I={profileId:e,profilePath:`${A}/${n.path}`,deprecated:!!n.deprecated}}const o=await fW(I.profilePath);let s;if(t){let n;if(g.handedness==="any"?n=o.layouts[Object.keys(o.layouts)[0]]:n=o.layouts[g.handedness],!n)throw new Error(`No matching handedness, ${g.handedness}, in profile ${I.profileId}`);n.assetPath&&(s=I.profilePath.replace("profile.json",n.assetPath))}return{profile:o,assetPath:s}}const OBA={xAxis:0,yAxis:0,button:0,state:Yg.ComponentState.DEFAULT};function PBA(g=0,A=0){let e=g,t=A;if(Math.sqrt(g*g+A*A)>1){const o=Math.atan2(A,g);e=Math.cos(o),t=Math.sin(o)}return{normalizedXAxis:e*.5+.5,normalizedYAxis:t*.5+.5}}let WBA=class{constructor(A){this.componentProperty=A.componentProperty,this.states=A.states,this.valueNodeName=A.valueNodeName,this.valueNodeProperty=A.valueNodeProperty,this.valueNodeProperty===Yg.VisualResponseProperty.TRANSFORM&&(this.minNodeName=A.minNodeName,this.maxNodeName=A.maxNodeName),this.value=0,this.updateFromComponent(OBA)}updateFromComponent({xAxis:A,yAxis:e,button:t,state:i}){const{normalizedXAxis:I,normalizedYAxis:o}=PBA(A,e);switch(this.componentProperty){case Yg.ComponentProperty.X_AXIS:this.value=this.states.includes(i)?I:.5;break;case Yg.ComponentProperty.Y_AXIS:this.value=this.states.includes(i)?o:.5;break;case Yg.ComponentProperty.BUTTON:this.value=this.states.includes(i)?t:0;break;case Yg.ComponentProperty.STATE:this.valueNodeProperty===Yg.VisualResponseProperty.VISIBILITY?this.value=this.states.includes(i):this.value=this.states.includes(i)?1:0;break;default:throw new Error(`Unexpected visualResponse componentProperty ${this.componentProperty}`)}}},ZBA=class{constructor(A,e){if(!A||!e||!e.visualResponses||!e.gamepadIndices||Object.keys(e.gamepadIndices).length===0)throw new Error("Invalid arguments supplied");this.id=A,this.type=e.type,this.rootNodeName=e.rootNodeName,this.touchPointNodeName=e.touchPointNodeName,this.visualResponses={},Object.keys(e.visualResponses).forEach(t=>{const i=new WBA(e.visualResponses[t]);this.visualResponses[t]=i}),this.gamepadIndices=Object.assign({},e.gamepadIndices),this.values={state:Yg.ComponentState.DEFAULT,button:this.gamepadIndices.button!==void 0?0:void 0,xAxis:this.gamepadIndices.xAxis!==void 0?0:void 0,yAxis:this.gamepadIndices.yAxis!==void 0?0:void 0}}get data(){return{id:this.id,...this.values}}updateFromGamepad(A){if(this.values.state=Yg.ComponentState.DEFAULT,this.gamepadIndices.button!==void 0&&A.buttons.length>this.gamepadIndices.button){const e=A.buttons[this.gamepadIndices.button];this.values.button=e.value,this.values.button=this.values.button<0?0:this.values.button,this.values.button=this.values.button>1?1:this.values.button,e.pressed||this.values.button===1?this.values.state=Yg.ComponentState.PRESSED:(e.touched||this.values.button>Yg.ButtonTouchThreshold)&&(this.values.state=Yg.ComponentState.TOUCHED)}this.gamepadIndices.xAxis!==void 0&&A.axes.length>this.gamepadIndices.xAxis&&(this.values.xAxis=A.axes[this.gamepadIndices.xAxis],this.values.xAxis=this.values.xAxis<-1?-1:this.values.xAxis,this.values.xAxis=this.values.xAxis>1?1:this.values.xAxis,this.values.state===Yg.ComponentState.DEFAULT&&Math.abs(this.values.xAxis)>Yg.AxisTouchThreshold&&(this.values.state=Yg.ComponentState.TOUCHED)),this.gamepadIndices.yAxis!==void 0&&A.axes.length>this.gamepadIndices.yAxis&&(this.values.yAxis=A.axes[this.gamepadIndices.yAxis],this.values.yAxis=this.values.yAxis<-1?-1:this.values.yAxis,this.values.yAxis=this.values.yAxis>1?1:this.values.yAxis,this.values.state===Yg.ComponentState.DEFAULT&&Math.abs(this.values.yAxis)>Yg.AxisTouchThreshold&&(this.values.state=Yg.ComponentState.TOUCHED)),Object.values(this.visualResponses).forEach(e=>{e.updateFromComponent(this.values)})}},jBA=class{constructor(A,e,t){if(!A)throw new Error("No xrInputSource supplied");if(!e)throw new Error("No profile supplied");this.xrInputSource=A,this.assetUrl=t,this.id=e.profileId,this.layoutDescription=e.layouts[A.handedness],this.components={},Object.keys(this.layoutDescription.components).forEach(i=>{const I=this.layoutDescription.components[i];this.components[i]=new ZBA(i,I)}),this.updateFromGamepad()}get gripSpace(){return this.xrInputSource.gripSpace}get targetRaySpace(){return this.xrInputSource.targetRaySpace}get data(){const A=[];return Object.values(this.components).forEach(e=>{A.push(e.data)}),A}updateFromGamepad(){Object.values(this.components).forEach(A=>{A.updateFromGamepad(this.xrInputSource.gamepad)})}};const to=new y,yY=new y,wY=new GA,zBA=gA("debuggizmos"),$n=8947848,mn=class{constructor(){}static isGizmo(A){return A[MK]!==void 0}static DrawLabel(A,e,t=.05,i=0,I,o,s){var a;if(!mn.enabled)return null;I||(I=$n);const n=((a=ye.active)==null?void 0:a.rigScale)??1,r=Ti.getTextLabel(i,e,t*n,I,o);return s instanceof DA&&s.add(r),r.position.x=A.x,r.position.y=A.y,r.position.z=A.z,r}static DrawRay(A,e,t=$n,i=0,I=!0){if(!mn.enabled)return;const o=Ti.getLine(i),s=o.geometry.getAttribute("position");s.setXYZ(0,A.x,A.y,A.z),to.set(e.x,e.y,e.z).multiplyScalar(999999999),s.setXYZ(1,A.x+to.x,A.y+to.y,A.z+to.z),s.needsUpdate=!0,o.material.color.set(t),o.material.depthTest=I,o.material.depthWrite=!1}static DrawDirection(A,e,t=$n,i=0,I=!0,o=1){if(!mn.enabled)return;const s=Ti.getLine(i),n=s.geometry.getAttribute("position");n.setXYZ(0,A.x,A.y,A.z),e.w!==void 0?(to.set(0,0,-o),wY.set(e.x,e.y,e.z,e.w),to.applyQuaternion(wY)):(to.set(e.x,e.y,e.z),to.multiplyScalar(o)),n.setXYZ(1,A.x+to.x,A.y+to.y,A.z+to.z),n.needsUpdate=!0,s.material.color.set(t),s.material.depthTest=I,s.material.depthWrite=!1}static DrawLine(A,e,t=$n,i=0,I=!0){if(!mn.enabled)return;const o=Ti.getLine(i),s=o.geometry.getAttribute("position");s.setXYZ(0,A.x,A.y,A.z),s.setXYZ(1,e.x,e.y,e.z),s.needsUpdate=!0,o.material.color.set(t),o.material.depthTest=I,o.material.depthWrite=!1,o.material.fog=!1}static DrawWireSphere(A,e,t=$n,i=0,I=!0){if(!mn.enabled)return;const o=Ti.getSphere(e,i,!0);Tc(o,A.x,A.y,A.z),o.material.color.set(t),o.material.depthTest=I,o.material.depthWrite=!1,o.material.fog=!1}static DrawSphere(A,e,t=$n,i=0,I=!0){if(!mn.enabled)return;const o=Ti.getSphere(e,i,!1);Tc(o,A.x,A.y,A.z),o.material.color.set(t),o.material.depthTest=I,o.material.depthWrite=!1}static DrawWireBox(A,e,t=$n,i=0,I=!0){if(!mn.enabled)return;const o=Ti.getBox(i);o.position.set(A.x,A.y,A.z),o.scale.set(e.x,e.y,e.z),o.material.color.set(t),o.material.depthTest=I,o.material.wireframe=!0,o.material.depthWrite=!1,o.material.fog=!1}static DrawWireBox3(A,e=$n,t=0,i=!0){if(!mn.enabled)return;const I=Ti.getBox(t);I.position.copy(A.getCenter(to)),I.scale.copy(A.getSize(to)),I.material.color.set(e),I.material.depthTest=i,I.material.wireframe=!0,I.material.depthWrite=!1,I.material.fog=!1}static DrawArrow(A,e,t=$n,i=0,I=!0,o=!1){if(!mn.enabled)return;const s=Ti.getArrowHead(i);s.position.set(e.x,e.y,e.z),s.quaternion.setFromUnitVectors(this._up.set(0,1,0),to.set(e.x,e.y,e.z).sub(yY.set(A.x,A.y,A.z)).normalize());const r=to.set(e.x,e.y,e.z).sub(yY.set(A.x,A.y,A.z)).length()*.1;s.scale.set(r,r,r),s.material.color.set(t),s.material.depthTest=I,s.material.wireframe=o,this.DrawLine(A,e,t,i,I)}static DrawWireMesh(A){const e=Ti.getMesh(A.duration??0);"mesh"in A?(e.geometry=A.mesh.geometry,e.matrix.copy(A.mesh.matrixWorld)):(e.geometry=A.geometry,e.matrix.copy(A.matrix)),e.matrixAutoUpdate=!1,e.matrixWorldAutoUpdate=!1,e.material.color.set(A.color??$n),e.material.depthTest=A.depthTest??!0,e.material.wireframe=!0}};let fe=mn;B(fe,"enabled",!0),B(fe,"_up",new y(0,1,0));const VBA=new ti(1,1,1);function Hx(g=null){const A=new yA(g??14540253),e=new IJ(VBA);return new TI(e,new Ii({color:A}))}const MK=Symbol("GizmoCache");class Ti{static ensureFont(){let A=Vt.FontLibrary.getFontFamily(this.familyName);if(!A){A=Vt.FontLibrary.addFontFamily(this.familyName);const e=A.addVariant("normal","normal","https://uploads.needle.tools/include/font-msdf.json","https://uploads.needle.tools/include/font.png");e==null||e.addEventListener("ready",()=>{Vt.update()})}}static getTextLabel(A,e,t,i,I){this.ensureFont();let o=this.textLabelCache.pop(),s=1;I&&typeof I=="string"&&(I==null?void 0:I.length)>=8&&I.startsWith("#")?(s=parseInt(I.substring(7),16)/255,I=I.substring(0,7),zBA&&console.log(I,s)):typeof I=="object"&&I.a!==void 0&&(s=I.a);const n={boxSizing:"border-box",fontFamily:this.familyName,width:"auto",fontSize:t,color:i,lineHeight:1,backgroundColor:I??void 0,backgroundOpacity:s,textContent:e,borderRadius:.5*t,padding:.8*t,whiteSpace:"pre"};if(o)o.set(n);else{o=new WJ(n);const r=this,a=o;a.setText=function(C){this.set({textContent:C}),r.tmuiNeedsUpdate=!0}}return this.tmuiNeedsUpdate=!0,this.registerTimedObject(be.Current,o,A,this.textLabelCache),o}static getBox(A){let e=this.boxesCache.pop();if(!e){const t=new ti(1,1,1);e=new hA(t)}return this.registerTimedObject(be.Current,e,A,this.boxesCache),e}static getLine(A){let e=this.linesCache.pop();if(!e){e=new Oi;let t=e.geometry.getAttribute("position");t||(t=new ne(new Float32Array(2*3),3),e.geometry.setAttribute("position",t))}return e.frustumCulled=!1,this.registerTimedObject(be.Current,e,A,this.linesCache),e}static getSphere(A,e,t){let i=this.spheresCache.pop();return i||(i=new hA(new gn(1,8,8))),i.scale.set(A,A,A),i.material.wireframe=t,this.registerTimedObject(be.Current,i,e,this.spheresCache),i}static getArrowHead(A){let e=this.arrowHeadsCache.pop();return e||(e=new hA(new Ag(0,.5,1,8))),this.registerTimedObject(be.Current,e,A,this.arrowHeadsCache),e}static getMesh(A){let e=this.mesh.pop();return e||(e=new hA,e.material=new ot),this.registerTimedObject(be.Current,e,A,this.mesh),e}static registerTimedObject(A,e,t,i){const I=this.contextBeforeRenderCallbacks.get(A),o=this.contextPostRenderCallbacks.get(A);if(I){if(A.pre_render_callbacks[A.pre_render_callbacks.length-1]!==I){const s=A.pre_render_callbacks.indexOf(I);s>=0&&A.pre_render_callbacks.splice(s,1),A.pre_render_callbacks.push(I)}}else{const s=()=>{this.onBeforeRender(A,this.timedObjectsBuffer)};this.contextBeforeRenderCallbacks.set(A,s),A.pre_render_callbacks.push(s)}if(o){if(A.post_render_callbacks[A.post_render_callbacks.length-1]!==o){const s=A.post_render_callbacks.indexOf(o);s>=0&&A.post_render_callbacks.splice(s,1),A.post_render_callbacks.push(o)}}else{const s=()=>{this.onPostRender(A,this.timedObjectsBuffer,this.timesBuffer)};this.contextPostRenderCallbacks.set(A,s),A.post_render_callbacks.push(s)}e.traverse(s=>{s.layers.disableAll(),s.layers.enable(2)}),e.renderOrder=999999,e[MK]=i,e.isGizmo=!0,this.timedObjectsBuffer.push(e),t<=0&&A.currentFrameEvent>=oi.OnBeforeRender?this.timesBuffer.push(0):this.timesBuffer.push(be.Current.time.realtimeSinceStartup+t),A.scene.add(e)}static onBeforeRender(A,e){this.tmuiNeedsUpdate&&Vt.update();for(let t=0;t<e.length;t++){const i=e[t];if(A.mainCamera&&i instanceof Vt.MeshUIBaseElement){if(Yc(i))continue;const I=A.isInVR,o=!1,s=!I;hD(i,A.mainCamera,o,s)}}}static onPostRender(A,e,t){const i=A.time.realtimeSinceStartup;for(let I=e.length-1;I>=0;I--){const o=e[I];i>t[I]&&(e.splice(I,1),t.splice(I,1),o.removeFromParent(),Yc(o)!=!0&&o[MK].push(o))}}}B(Ti,"familyName","needle-gizmos"),B(Ti,"linesCache",[]),B(Ti,"spheresCache",[]),B(Ti,"boxesCache",[]),B(Ti,"arrowHeadsCache",[]),B(Ti,"mesh",[]),B(Ti,"textLabelCache",[]),B(Ti,"timedObjectsBuffer",new Array),B(Ti,"timesBuffer",new Array),B(Ti,"contextPostRenderCallbacks",new Map),B(Ti,"contextBeforeRenderCallbacks",new Map),B(Ti,"tmuiNeedsUpdate",!1);const Dg=gA("debuginput");var gM=(g=>(g.Mouse="mouse",g.Touch="touch",g.Controller="controller",g.Hand="hand",g))(gM||{}),pi=(g=>(g.PointerDown="pointerdown",g.PointerUp="pointerup",g.PointerMove="pointermove",g.KeyDown="keydown",g.KeyUp="keyup",g.KeyPressed="keypress",g))(pi||{});class ma extends PointerEvent{constructor(e,t,i){super(e,i);B(this,"deviceIndex");B(this,"origin");B(this,"source");B(this,"mode");B(this,"_ray");B(this,"space");B(this,"isClick",!1);B(this,"isDoubleClick",!1);B(this,"_used",!1);B(this,"_pointerid");B(this,"_pointerType");B(this,"_type");B(this,"metadata",{});B(this,"intersections",new Array);B(this,"_immediatePropagationStopped",!1);B(this,"_propagationStopped",!1);this._pointerid=i.pointerId,this._pointerType=i.pointerType,this._type=e,this.deviceIndex=i.deviceIndex,this.origin=i.origin,this.source=t,this.mode=i.mode,this._ray=i.ray,this.space=i.device}get isSpatial(){return this.mode!="screen"}get ray(){return this._ray||(this._ray=new xo(this.space.worldPosition.clone(),this.space.worldForward.clone())),this._ray}set ray(e){this._ray=e}get hasRay(){return this._ray!==void 0}get used(){return this._used}use(){this._used=!0}get pointerId(){return this._pointerid}get pointerType(){return this._pointerType}get type(){return this._type}get immediatePropagationStopped(){return this._immediatePropagationStopped}get propagationStopped(){return this._immediatePropagationStopped||this._propagationStopped}stopImmediatePropagation(){var e;this._immediatePropagationStopped=!0,super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}stopPropagation(){var e;this._propagationStopped=!0,super.stopPropagation(),(e=this.source)==null||e.stopPropagation(),Dg&&console.warn("Stop propagation...",this.pointerId,this.pointerType)}}class ep extends KeyboardEvent{constructor(e,t,i){super(e,i);B(this,"source");this.source=t}stopImmediatePropagation(){var e;super.stopImmediatePropagation(),(e=this.source)==null||e.stopImmediatePropagation()}}class XBA{constructor(A){B(this,"key");B(this,"keyType");B(this,"source");this.key=A.key,this.keyType=A.type,this.source=A}}var cr=(g=>(g[g.Early=-100]="Early",g[g.Default=0]="Default",g[g.Late=100]="Late",g))(cr||{});class DW{constructor(A){B(this,"_eventListeners",{});B(this,"_doubleClickTimeThreshold",.2);B(this,"_longPressTimeThreshold",1);B(this,"_specialCursorTrigger",0);B(this,"context");B(this,"_pointerDown",[!1]);B(this,"_pointerUp",[!1]);B(this,"_pointerClick",[!1]);B(this,"_pointerDoubleClick",[!1]);B(this,"_pointerPressed",[!1]);B(this,"_pointerPositions",[new tA]);B(this,"_pointerPositionsLastFrame",[new tA]);B(this,"_pointerPositionsDelta",[new tA]);B(this,"_pointerPositionsRC",[new tA]);B(this,"_pointerPositionDown",[new tA]);B(this,"_pointerDownTime",[]);B(this,"_pointerUpTime",[]);B(this,"_pointerUpTimestamp",[]);B(this,"_pointerIds",[]);B(this,"_pointerTypes",[""]);B(this,"_mouseWheelChanged",[!1]);B(this,"_mouseWheelDeltaY",[0]);B(this,"_pointerEvent",[]);B(this,"_pointerUsed",[]);B(this,"_pointerSpace",[]);B(this,"_pressedStack",new Map);B(this,"_htmlEventSource");B(this,"onLostFocus",()=>{for(const A in this.keysPressed)this.keysPressed[A].pressed=!1});B(this,"onEndOfFrame",()=>{for(let A=0;A<this._pointerUp.length;A++)this._pointerUp[A]=!1;for(let A=0;A<this._pointerDown.length;A++)this._pointerDown[A]=!1;for(let A=0;A<this._pointerClick.length;A++)this._pointerClick[A]=!1;for(let A=0;A<this._pointerDoubleClick.length;A++)this._pointerDoubleClick[A]=!1;for(const A of this._pointerPositionsDelta)A.set(0,0);for(let A=0;A<this._mouseWheelChanged.length;A++)this._mouseWheelChanged[A]=!1;for(let A=0;A<this._mouseWheelDeltaY.length;A++)this._mouseWheelDeltaY[A]=0});B(this,"onContextMenu",A=>{this.canReceiveInput(A)!==!1&&A instanceof PointerEvent&&A.pointerType});B(this,"keysPressed",{});B(this,"onKeyDown",A=>{if(Dg&&console.log(`key down ${A.code}, ${this.context.application.hasFocus}`,A),!this.context.application.hasFocus)return;const e=this.keysPressed[A.code];if(e&&e.pressed)return;this.keysPressed[A.code]={pressed:!0,frame:this.context.time.frameCount+1,startFrame:this.context.time.frameCount+1,key:A.key,code:A.code};const t=new ep("keydown",A,A);this.onDispatchEvent(t)});B(this,"onKeyPressed",A=>{if(!this.context.application.hasFocus)return;const e=this.keysPressed[A.code];if(!e)return;e.pressed=!0,e.frame=this.context.time.frameCount+1;const t=new ep("keypress",A,A);this.onDispatchEvent(t)});B(this,"onKeyUp",A=>{if(!this.context.application.hasFocus)return;const e=this.keysPressed[A.code];if(!e)return;e.pressed=!1,e.frame=this.context.time.frameCount+1;const t=new ep("keyup",A,A);this.onDispatchEvent(t)});B(this,"onWheelWindow",A=>{document.pointerLockElement&&this.onMouseWheel(A)});B(this,"onMouseWheel",A=>{if(this.canReceiveInput(A)===!1)return;this._mouseWheelDeltaY.length<=0&&this._mouseWheelDeltaY.push(0),this._mouseWheelChanged.length<=0&&this._mouseWheelChanged.push(!1),this._mouseWheelChanged[0]=!0;const e=this._mouseWheelDeltaY[0];this._mouseWheelDeltaY[0]=e+A.deltaY});B(this,"onPointerDown",A=>{if(this.context.isInAR||this.canReceiveInput(A)===!1)return;A.target instanceof HTMLElement&&A.target.setPointerCapture(A.pointerId);const e=this.getPointerId(A);Dg&&fi(`pointer down #${e}, identifier:${A.pointerId}`);const t=this.getAndUpdateSpatialObjectForScreenPosition(e,A.clientX,A.clientY),i=new ma("pointerdown",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:e,button:A.button,clientX:A.clientX,clientY:A.clientY,pointerType:A.pointerType,buttonName:this.getButtonName(A),device:t,pressure:A.pressure});this.onDown(i)});B(this,"onPointerMove",A=>{if(this.context.isInAR)return;let e=A.button;A.pointerType==="mouse"&&(e=this.getFirstPressedButtonForPointer(0)??0);const t=this.getPointerId(A,e);e===-1&&(e=t);const i=this.getAndUpdateSpatialObjectForScreenPosition(t,A.clientX,A.clientY),I=new ma("pointermove",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:t,button:e,clientX:A.clientX,clientY:A.clientY,pointerType:A.pointerType,buttonName:this.getButtonName(A),device:i,pressure:A.pressure});this.onMove(I)});B(this,"onPointerCancel",A=>{this.context.isInAR||(Dg&&console.log("Pointer cancel",A),this.onPointerUp(A))});B(this,"onPointerUp",A=>{if(this.context.isInAR)return;A.target instanceof HTMLElement&&A.target.releasePointerCapture(A.pointerId);const e=this.getPointerId(A),t=new ma("pointerup",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:e,button:A.button,clientX:A.clientX,clientY:A.clientY,pointerType:A.pointerType,buttonName:this.getButtonName(A),device:this.getAndUpdateSpatialObjectForScreenPosition(e,A.clientX,A.clientY),pressure:A.pressure});this.onUp(t),this._pointerIds[e]=-1,Dg&&console.log("ID="+e,"PointerId="+A.pointerId,"ALL:",[...this._pointerIds])});B(this,"onTouchStart",A=>{if(this.context.isInAR)for(let e=0;e<A.changedTouches.length;e++){const t=A.changedTouches[e],i=this.getPointerIndex(t.identifier),I=this.getAndUpdateSpatialObjectForScreenPosition(i,t.clientX,t.clientY),o=new ma("pointerdown",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:i,button:0,clientX:t.clientX,clientY:t.clientY,pointerType:"touch",buttonName:"unknown",device:I,pressure:t.force});this.onDown(o)}});B(this,"onTouchMove",A=>{if(this.context.isInAR)for(let e=0;e<A.changedTouches.length;e++){const t=A.changedTouches[e],i=this.getPointerIndex(t.identifier),I=this.getAndUpdateSpatialObjectForScreenPosition(i,t.clientX,t.clientY),o=new ma("pointermove",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:i,button:0,clientX:t.clientX,clientY:t.clientY,pointerType:"touch",buttonName:"unknown",device:I,pressure:t.force});this.onMove(o)}});B(this,"onTouchEnd",A=>{if(this.context.isInAR)for(let e=0;e<A.changedTouches.length;e++){const t=A.changedTouches[e],i=this.getPointerIndex(t.identifier),I=new ma("pointerup",A,{origin:this,mode:"screen",deviceIndex:0,pointerId:i,button:0,clientX:t.clientX,clientY:t.clientY,pointerType:"touch",buttonName:"unknown",device:this.getAndUpdateSpatialObjectForScreenPosition(i,t.clientX,t.clientY),pressure:t.force});this.onUp(I),this._pointerIds[i]=-1}});B(this,"tempNearPlaneVector",new y);B(this,"tempFarPlaneVector",new y);B(this,"tempLookMatrix",new fA);this.context=A,this.context.post_render_callbacks.push(this.onEndOfFrame)}addEventListener(A,e,t){if(this._eventListeners[A]||(this._eventListeners[A]=[]),!e||typeof e!="function"){console.error("Invalid call to addEventListener: callback is required and must be a function!");return}t?t={...t}:t={};let i=0;(t==null?void 0:t.queue)!=null&&(i=t.queue);const I=this._eventListeners[A],o=I.find(s=>s.priority===i);o?o.listeners.push({callback:e,options:t}):(I.push({priority:i,listeners:[{callback:e,options:t}]}),I.sort((s,n)=>s.priority-n.priority))}removeEventListener(A,e,t){if(!this._eventListeners[A]||!e)return;const i=this._eventListeners[A];if((t==null?void 0:t.queue)!=null){const I=i.find(s=>s.priority===t.queue);if(!I)return;const o=I.listeners.findIndex(s=>s.callback===e);o>=0&&I.listeners.splice(o,1)}else for(const I of i){const o=I.listeners.findIndex(s=>s.callback===e);o>=0&&I.listeners.splice(o,1)}}dispatchEvent(A){var t,i,I,o;let e=!1;if(A instanceof ep){const s=this._eventListeners[A.type];if(s)for(const n of s)for(let r=0;r<n.listeners.length;r++){const a=n.listeners[r];if((i=(t=a.options)==null?void 0:t.signal)!=null&&i.aborted){n.listeners.splice(r,1),r--;continue}a.options.once&&(n.listeners.splice(r,1),r--),a.callback(A)}}if(A instanceof ma){const s=this._eventListeners[A.type];if(s)for(const n of s){if(e)break;for(let r=0;r<n.listeners.length;r++){const a=n.listeners[r];if((o=(I=a.options)==null?void 0:I.signal)!=null&&o.aborted){n.listeners.splice(r,1),r--;continue}if(A.immediatePropagationStopped){e=!0,Dg&&console.log("immediatePropagationStopped",A.type);break}else A.propagationStopped&&(e=!0,Dg&&console.log("propagationStopped",A.type));a.options.once&&(n.listeners.splice(r,1),r--),a.callback(A)}}}}get mousePosition(){return this._pointerPositions[0]}get mousePositionRC(){return this._pointerPositionsRC[0]}get mouseDown(){return this._pointerDown[0]}get mouseUp(){return this._pointerUp[0]}get mouseClick(){return this._pointerClick[0]}get mouseDoubleClick(){return this._pointerDoubleClick[0]}get mousePressed(){return this._pointerPressed[0]}get mouseWheelChanged(){return this.getMouseWheelChanged(0)}setCursorPointer(){this._specialCursorTrigger+=1,this.context.domElement.style.cursor="pointer"}setCursorNormal(){this._specialCursorTrigger-=1,this._specialCursorTrigger=Math.max(0,this._specialCursorTrigger),this._specialCursorTrigger===0&&(this.context.domElement.style.cursor="default")}setPointerUsed(A,e=!0){if(A>=this._pointerUsed.length){if(A>=this._pointerIds.length)return;for(;this._pointerUsed.length<=A;)this._pointerUsed.push(!1)}this._pointerUsed[A]=e}getPointerUsed(A){return A>=this._pointerUsed.length?!1:this._pointerUsed[A]}getPointerPressedCount(){let A=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&A++;return A}getPointerPosition(A){return A>=this._pointerPositions.length?null:this._pointerPositions[A]}getPointerPositionLastFrame(A){return A>=this._pointerPositionsLastFrame.length?null:this._pointerPositionsLastFrame[A]}getPointerPositionDelta(A){return A>=this._pointerPositionsDelta.length?null:this._pointerPositionsDelta[A]}getPointerPositionRC(A){return A>=this._pointerPositionsRC.length?null:this._pointerPositionsRC[A]}getPointerDown(A){return A>=this._pointerDown.length?!1:this._pointerDown[A]}getPointerUp(A){return A>=this._pointerUp.length?!1:this._pointerUp[A]}getPointerPressed(A){return A>=this._pointerPressed.length?!1:this._pointerPressed[A]}getPointerClicked(A){return A>=this._pointerClick.length?!1:this._pointerClick[A]}getPointerDoubleClicked(A){return A>=this._pointerDoubleClick.length?!1:this._pointerDoubleClick[A]}getPointerDownTime(A){return A>=this._pointerDownTime.length?-1:this._pointerDownTime[A]}getPointerUpTime(A){return A>=this._pointerUpTime.length?-1:this._pointerUpTime[A]}getPointerLongPress(A){return A>=this._pointerDownTime.length?!1:this.getPointerPressed(A)&&this.context.time.time-this._pointerDownTime[A]>this._longPressTimeThreshold}getIsMouse(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="mouse"}getIsTouch(A){return A<0||A>=this._pointerTypes.length?!1:this._pointerTypes[A]==="touch"}getTouchesPressedCount(){let A=0;for(let e=0;e<this._pointerPressed.length;e++)this._pointerPressed[e]&&this.getIsTouch(e)&&A++;return A}getMouseWheelChanged(A=0){return A>=this._mouseWheelChanged.length?!1:this._mouseWheelChanged[A]}getMouseWheelDeltaY(A=0){return A>=this._mouseWheelDeltaY.length?0:this._mouseWheelDeltaY[A]}getPointerEvent(A){if(!(A>=this._pointerEvent.length))return this._pointerEvent[A]??void 0}*foreachPointerId(A){for(let e=0;e<this._pointerTypes.length;e++)if(this._pointerIsActive(e)){if(A!==void 0){const t=this._pointerTypes[e];if(Array.isArray(A)){let i=!1;for(const I of A)if(t===I){i=!0;break}if(!i)continue}else if(A!==t)continue}yield e}}*foreachTouchId(){for(let A=0;A<this._pointerTypes.length;A++)this._pointerTypes[A]==="touch"&&this._pointerIsActive[A]&&(yield A)}_pointerIsActive(A){return A<0?!1:this._pointerPressed[A]||this._pointerDown[A]||this._pointerUp[A]}onDownButton(A,e){let t=this._pressedStack.get(A);t||(t=[],this._pressedStack.set(A,t)),t.push(e)}onReleaseButton(A,e){const t=this._pressedStack.get(A);if(!t)return;const i=t.indexOf(e);i>=0&&t.splice(i,1)}getFirstPressedButtonForPointer(A){const e=this._pressedStack.get(A);if(e)return e[0]}getLatestPressedButtonForPointer(A){const e=this._pressedStack.get(A);if(e)return e[e.length-1]}getKeyDown(){for(const A in this.keysPressed){const e=this.keysPressed[A];if(e.startFrame===this.context.time.frameCount)return e.key}return null}getKeyPressed(){for(const A in this.keysPressed){const e=this.keysPressed[A];if(e.pressed)return e.key}return null}isKeyDown(A){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyDown(i))return!0;return!1}return((t=this.keysPressed[A])==null?void 0:t.startFrame)===this.context.time.frameCount&&this.keysPressed[A].pressed}isKeyUp(A){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyUp(i))return!0;return!1}return((t=this.keysPressed[A])==null?void 0:t.frame)===this.context.time.frameCount&&!this.keysPressed[A].pressed}isKeyPressed(A){var t;if(!this.context.application.isVisible||!this.context.application.hasFocus)return!1;const e=this.getCodeForCommonKeyName(A);if(e!==null){for(const i of e)if(this.isKeyPressed(i))return!0;return!1}return(t=this.keysPressed[A])==null?void 0:t.pressed}getCodeForCommonKeyName(A){if(A.length===1){if(A>="0"&&A<="9")return["Digit"+A];if(A>="a"&&A<="z")return["Key"+A.toUpperCase()];if(A==" ")return["Space"]}switch(A){case"shift":case"Shift":return["ShiftLeft","ShiftRight"];case"control":case"Control":return["ControlLeft","ControlRight"];case"alt":case"Alt":return["AltLeft","AltRight"]}return null}createInputEvent(A){switch(A.type){case"pointerdown":Dg&&fi("Create Pointer down"),this.onDownButton(A.deviceIndex,A.button),this.onDown(A);break;case"pointermove":Dg&&fi("Create Pointer move"),this.onMove(A);break;case"pointerup":Dg&&fi("Create Pointer up"),this.onUp(A),this.onReleaseButton(A.deviceIndex,A.button);break}}convertScreenspaceToRaycastSpace(A){return A.x=(A.x-this.context.domX)/this.context.domWidth*2-1,A.y=-((A.y-this.context.domY)/this.context.domHeight)*2+1,A}bindEvents(){this.unbindEvents(),this._htmlEventSource=this.context.renderer.domElement,window.addEventListener("contextmenu",this.onContextMenu),this._htmlEventSource.addEventListener("pointerdown",this.onPointerDown,{passive:!0}),window.addEventListener("pointermove",this.onPointerMove,{passive:!0,capture:!0}),window.addEventListener("pointerup",this.onPointerUp,{passive:!0}),window.addEventListener("pointercancel",this.onPointerCancel,{passive:!0}),window.addEventListener("touchstart",this.onTouchStart,{passive:!0}),window.addEventListener("touchmove",this.onTouchMove,{passive:!0}),window.addEventListener("touchend",this.onTouchEnd,{passive:!0}),this._htmlEventSource.addEventListener("wheel",this.onMouseWheel,{passive:!0}),window.addEventListener("wheel",this.onWheelWindow,{passive:!0}),window.addEventListener("keydown",this.onKeyDown,!1),window.addEventListener("keypress",this.onKeyPressed,!1),window.addEventListener("keyup",this.onKeyUp,!1),window.addEventListener("blur",this.onLostFocus)}unbindEvents(){var A,e;window.removeEventListener("contextmenu",this.onContextMenu),(A=this._htmlEventSource)==null||A.removeEventListener("pointerdown",this.onPointerDown),window.removeEventListener("pointermove",this.onPointerMove),window.removeEventListener("pointerup",this.onPointerUp),window.removeEventListener("pointercancel",this.onPointerCancel),(e=this._htmlEventSource)==null||e.removeEventListener("wheel",this.onMouseWheel,!1),window.removeEventListener("wheel",this.onWheelWindow,!1),window.removeEventListener("keydown",this.onKeyDown,!1),window.removeEventListener("keypress",this.onKeyPressed,!1),window.removeEventListener("keyup",this.onKeyUp,!1),window.removeEventListener("blur",this.onLostFocus)}dispose(){const A=this.context.post_render_callbacks.indexOf(this.onEndOfFrame);A>=0&&this.context.post_render_callbacks.splice(A,1),this.unbindEvents()}canReceiveInput(A){var e;return A.target===((e=this.context.renderer)==null?void 0:e.domElement)||A.target===this.context.domElement||this.context.isInAR||this.context.isInAR&&A.target===document.body&&Ec()?!0:(Dg&&console.warn("CanReceiveInput:False for",A.target),!1)}getPointerId(A,e){return A.pointerType==="mouse"?0+(e??A.button):this.getPointerIndex(A.pointerId)}getButtonName(A){const e=A.button;if(A.pointerType==="mouse")switch(e){case 0:return"left";case 1:return"middle";case 2:return"right"}return"unknown"}getAndUpdateSpatialObjectForScreenPosition(A,e,t){let i=this._pointerSpace[A];i||(i=new DA,this._pointerSpace[A]=i),this._pointerSpace[A]=i;const I=this.context.mainCamera;if(I){const o=this.tempNearPlaneVector.set(e,t,-1);this.convertScreenspaceToRaycastSpace(o);const s=this.tempFarPlaneVector.set(o.x,o.y,1);o.unproject(I),s.unproject(I);const n=I.worldUp||dt(0,1,0).applyQuaternion(Jt(I));this.tempLookMatrix.lookAt(s,o,n),i.position.set(o.x,o.y,o.z),i.quaternion.setFromRotationMatrix(this.tempLookMatrix)}return i}isInRect(A){if(this.context.isInXR)return!0;const e=this.context.domElement.getBoundingClientRect(),t=A.clientX,i=A.clientY,I=t>=e.x&&t<=e.right&&i>=e.y&&i<=e.bottom;return Dg&&!I&&console.log("Not in rect",e,t,i),I}onDown(A){const e=A.pointerId;if(this.getPointerPressed(e)&&console.warn(`pointerId is already pressed: ${e}`,Dg?A:""),Dg&&console.log(A.pointerType,"DOWN",e),!!this.isInRect(A)){for(this.setPointerState(e,this._pointerPressed,!0),this.setPointerState(e,this._pointerDown,!0),this.setPointerStateT(e,this._pointerEvent,A.source);e>=this._pointerTypes.length;)this._pointerTypes.push(A.pointerType);for(this._pointerTypes[e]=A.pointerType;e>=this._pointerPositionDown.length;)this._pointerPositionDown.push(new tA);for(this._pointerPositionDown[e].set(A.clientX,A.clientY);e>=this._pointerPositions.length;)this._pointerPositions.push(new tA);this._pointerPositions[e].set(A.clientX,A.clientY),e>=this._pointerDownTime.length&&this._pointerDownTime.push(0),this._pointerDownTime[e]=this.context.time.time,this.updatePointerPosition(A),this.onDispatchEvent(A)}}onMove(A){const e=A.pointerId,t=this.getPointerPressed(e);t===!1&&!this.isInRect(A)||A.pointerType==="touch"&&!t||(this.updatePointerPosition(A),this.setPointerStateT(e,this._pointerEvent,A.source),this.onDispatchEvent(A))}onUp(A){const e=A.pointerId;if(!this.getPointerPressed(e)){Dg&&console.log(A.pointerType,"UP",e,"was not down");return}for(Dg&&console.log(A.pointerType,"UP",e),this.setPointerState(e,this._pointerPressed,!1),this.setPointerStateT(e,this._pointerEvent,A.source),this.setPointerState(e,this._pointerUp,!0);e>=this._pointerUsed.length;)this._pointerUsed.push(!1);if(this.setPointerState(e,this._pointerUsed,!1),this.updatePointerPosition(A),!this._pointerPositionDown[e]){Dg&&Ot("Received pointer up event without matching down event for button: "+e),console.warn("Received pointer up event without matching down event for button: "+e);return}const i=A.clientX-this._pointerPositionDown[e].x,I=A.clientY-this._pointerPositionDown[e].y;if(e>=this._pointerUpTime.length&&this._pointerUpTime.push(-99),Math.abs(i)<5&&Math.abs(I)<5){Dg&&console.log("CLICK",e),this.setPointerState(e,this._pointerClick,!0),A.isClick=!0;const o=this._pointerUpTime[e],s=this.context.time.time-o;s<this._doubleClickTimeThreshold&&s>0&&(this.setPointerState(e,this._pointerDoubleClick,!0),A.isDoubleClick=!0)}this._pointerUpTime[e]=this.context.time.time,this.onDispatchEvent(A)}updatePointerPosition(A){const e=A.pointerId;for(;e>=this._pointerPositions.length;)this._pointerPositions.push(new tA);for(;e>=this._pointerPositionsLastFrame.length;)this._pointerPositionsLastFrame.push(new tA);for(;e>=this._pointerPositionsDelta.length;)this._pointerPositionsDelta.push(new tA);const t=this._pointerPositionsLastFrame[e];t.copy(this._pointerPositions[e]);const i=this._pointerPositionsDelta[e];let I=A.clientX-t.x,o=A.clientY-t.y;if(A.source instanceof MouseEvent||A.source instanceof TouchEvent){const a=A.source;I===0&&a.movementX!==0&&(I=a.movementX||0),o===0&&a.movementY!==0&&(o=a.movementY||0)}i.x+=I,i.y+=o,this._pointerPositions[e].x=A.clientX,this._pointerPositions[e].y=A.clientY;const s=A.clientX,n=A.clientY;for(;e>=this._pointerPositionsRC.length;)this._pointerPositionsRC.push(new tA);const r=this._pointerPositionsRC[e];r.set(s,n),this.convertScreenspaceToRaycastSpace(r)}getPointerIndex(A){let e=-1;for(let t=0;t<this._pointerIds.length;t++){if(this._pointerIds[t]===A)return t;e===-1&&this._pointerIds[t]===-1&&(e=t)}return e!==-1?(this._pointerIds[e]=A,e):(Dg&&console.log("PUSH pointerId:",A),this._pointerIds.push(A),this._pointerIds.length-1)}setPointerState(A,e,t){e[A]=t}setPointerStateT(A,e,t){return e[A]=t,t}onDispatchEvent(A){const e=be.Current;try{be.Current=this.context,this.dispatchEvent(A)}finally{be.Current=e}}}const Bm=new fA().makeRotationY(Math.PI),bs=new GA().setFromAxisAngle(new y(0,1,0),Math.PI),$BA=gA("debugwebxr");class AQA{constructor(){B(this,"priority",-1e5);B(this,"gameObject");if(this.gameObject=new DA,this.gameObject.name="Implicit XR Rig",$BA){const A=Hx(16733661);A.position.y+=.5,this.gameObject.add(A)}}isXRRig(){return!0}get isActive(){return this.gameObject.visible}}const TC=gA("debugwebxr"),gS=gA("debugcustomgesture"),eQA="https://cdn.jsdelivr.net/npm/@webxr-input-profiles/assets@1.0/dist/profiles",tQA="generic-trigger";class Yx{constructor(A,e,t){B(this,"xr");B(this,"inputSource");B(this,"index",0);B(this,"emitEvents",!0);B(this,"_connected",!0);B(this,"_isTracking",!1);B(this,"_hitTestSource");B(this,"_hasSelectEvent",!1);B(this,"_handJointPoses",new Map);B(this,"_gripPosition",new y);B(this,"_gripQuaternion",new GA);B(this,"_linearVelocity",new y);B(this,"_rayPosition",new y);B(this,"_rayQuaternion",new GA);B(this,"_gripWorldPosition",new y);B(this,"_gripWorldQuaternion",new GA);B(this,"_rayWorldPosition",new y);B(this,"_rayWorldQuaternion",new GA);B(this,"_ray");B(this,"_object");B(this,"model",null);B(this,"_debugAxesHelper",new Qs(.2));B(this,"onPointerHits",A=>{});B(this,"_needleGamepadButtons",{});B(this,"_buttonMap",new Map);B(this,"_motioncontroller");B(this,"_layout");B(this,"getMotionController");B(this,"_selectButtonIndex");B(this,"_squeezeButtonIndex");B(this,"onSelectStart",A=>{var i,I,o,s;if(this.inputSource!==A.inputSource)return;this.onUpdateFrame(A.frame),this._hasSelectEvent=!0;const e=(i=this._layout)==null?void 0:i.selectComponentId,t=(s=(o=(I=this._layout)==null?void 0:I.components[e])==null?void 0:o.gamepadIndices)==null?void 0:s.button;t!==void 0&&(this._selectButtonIndex=t),!gS&&(TC&&fe.DrawDirection(this.rayWorldPosition,dt(0,.01,1).applyQuaternion(this.rayWorldQuaternion),16711680,10),this.emitPointerEvent(pi.PointerDown,this._selectButtonIndex||0,"xr-standard-trigger",!0,A))});B(this,"onSelectEnd",A=>{gS||this.inputSource===A.inputSource&&this.emitPointerEvent(pi.PointerUp,this._selectButtonIndex||0,"xr-standard-trigger",!0,A)});B(this,"onSequeezeStart",A=>{var e,t,i;this.inputSource===A.inputSource&&(this._squeezeButtonIndex=(i=(t=(e=this._layout)==null?void 0:e.components["xr-standard-squeeze"])==null?void 0:t.gamepadIndices)==null?void 0:i.button,this._squeezeButtonIndex!==void 0&&(TC&&fe.DrawDirection(this.rayWorldPosition,dt(0,.01,1).applyQuaternion(this.rayWorldQuaternion),255,10),this.emitPointerEvent(pi.PointerDown,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,A)))});B(this,"onSequeezeEnd",A=>{this.inputSource===A.inputSource&&this._squeezeButtonIndex!==void 0&&this.emitPointerEvent(pi.PointerUp,this._squeezeButtonIndex||0,"xr-standard-squeeze",!0,A)});B(this,"states",{});B(this,"_didMoveLastFrame",!1);B(this,"_lastPointerMovePosition",new y);B(this,"_lastPointerMoveQuaternion",new GA);B(this,"pointerInit");var i,I,o;this.xr=A,this.inputSource=e,this.index=t,this._object=new DA,TC&&this._object.add(this._debugAxesHelper),this.xr.context.scene.add(this._object),this._ray=new xo,this.pointerInit={origin:this,pointerType:this.hand?"hand":"controller",deviceIndex:this.index,pointerId:-1,mode:this.inputSource.targetRayMode,ray:this._ray,device:this._object,buttonName:"none"},this.initialize(),this.subscribeEvents(),this.xr.mode==="immersive-ar"&&this.inputSource.targetRayMode==="tracked-pointer"&&((o=(I=(i=this.xr.session).requestHitTestSourceForTransientInput)==null?void 0:I.call(i,{profile:this.inputSource.profiles[0],offsetRay:new XRRay}))==null||o.then(s=>this._hitTestSource=s))}get context(){return this.xr.context}get connected(){return this._connected}get isTracking(){return this._isTracking}get gamepad(){return this.inputSource.gamepad}get isHand(){return this.inputSource.hand!=null}get hand(){return this.inputSource.hand}get handObject(){return this.context.renderer.xr.getHand(this.index)}get profiles(){return this.inputSource.profiles}get layout(){return this._layout}get targetRayMode(){return this.inputSource.targetRayMode}get targetRaySpace(){return this.inputSource.targetRaySpace}get gripSpace(){return this.inputSource.gripSpace}get side(){return this.inputSource.handedness}get isRight(){return this.side==="right"}get isLeft(){return this.side==="left"}get hitTestSource(){return this._hitTestSource}get hasSelectEvent(){return this._hasSelectEvent}getHitTest(){return this.xr.getHitTest(this)}getHandJointPose(A){var t,i;if(!this.hand||!((t=this.xr.frame)!=null&&t.getJointPose)||!this.xr.referenceSpace)return null;let e=(i=this._handJointPoses)==null?void 0:i.get(A);return e||(e=this.xr.frame.getJointPose(A,this.xr.referenceSpace),e&&this._handJointPoses.set(A,e),e)}get gripPosition(){return dt(this._gripPosition).applyMatrix4(Bm)}get gripQuaternion(){return gc(this._gripQuaternion).premultiply(bs)}get gripLinearVelocity(){return dt(this._linearVelocity).applyQuaternion(bs)}get rayPosition(){return dt(this._rayPosition).applyMatrix4(Bm)}get rayQuaternion(){return gc(this._rayQuaternion).premultiply(bs)}get gripWorldPosition(){return dt(this._gripWorldPosition)}get gripWorldQuaternion(){return gc(this._gripWorldQuaternion)}get rayWorldPosition(){return dt(this._rayWorldPosition)}updateRayWorldPosition(){var e;const A=(e=this.xr.context.mainCamera)==null?void 0:e.parent;this._rayWorldPosition.copy(this._rayPosition),A&&this._rayWorldPosition.applyMatrix4(A.matrixWorld)}get rayWorldQuaternion(){return gc(this._rayWorldQuaternion)}updateRayWorldQuaternion(){var t;const A=(t=this.xr.context.mainCamera)==null?void 0:t.parent,e=A?Jt(A):void 0;this._rayWorldQuaternion.copy(this._rayQuaternion).multiply(bs),e&&this._rayWorldQuaternion.premultiply(e)}get ray(){return this._ray.origin.copy(this.rayWorldPosition),this._ray.direction.copy(dt(0,0,1).applyQuaternion(this.rayWorldQuaternion)),this._ray}get object(){return this._object}async getModelUrl(){var A;return(A=this.getMotionController)==null?void 0:A.then(e=>(e==null?void 0:e.assetUrl)||null)}onUpdate(A){this.onUpdateFrame(A),this.updateInputEvents(),this.onUpdateMove()}onRenderDebug(){var i;fe.DrawWireSphere(this.rayWorldPosition,.02),fe.DrawDirection(this.rayWorldPosition,dt(0,0,10).applyQuaternion(this.rayWorldQuaternion));const A=this.gripWorldPosition.sub(this.object.worldForward.multiplyScalar(.1)),e=this.inputSource.profiles.join(`
|
|
5152
5152
|
`);let t=`Controller[${this.index}] ${this.side}
|
|
5153
5153
|
C:${this.connected?"yes":"no"} T:${this.isTracking?"yes":"no"} Hand:${this.inputSource.hand?"yes":"no"}`;this.inputSource.hand&&(t+=`
|
|
5154
5154
|
Pinch: ${(i=this.getGesture("pinch"))==null?void 0:i.value.toFixed(3)}`),t+=`
|
|
@@ -5232,7 +5232,7 @@ a=extmap-allow-mixed`)!==-1){const I=i.sdp.split(`
|
|
|
5232
5232
|
isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},g}()),_Y={iceServers:[{urls:"stun:stun.l.google.com:19302"},{urls:["turn:eu-0.turn.peerjs.com:3478","turn:us-0.turn.peerjs.com:3478"],username:"peerjs",credential:"peerjsp"}],sdpSemantics:"unified-plan"},fQA=function(){function g(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=_Y,this.browser=mu.getBrowser(),this.browserVersion=mu.getVersion(),this.supports=function(){var A={browser:mu.isBrowserSupported(),webRTC:mu.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!A.webRTC)return A;var e;try{e=new RTCPeerConnection(_Y),A.audioVideo=!0;var t=void 0;try{t=e.createDataChannel("_PEERJSTEST",{ordered:!0}),A.data=!0,A.reliable=!!t.ordered;try{t.binaryType="blob",A.binaryBlob=!mu.isIOS}catch{}}catch{}finally{t&&t.close()}}catch{}finally{e&&e.close()}return A}(),this.pack=RY.pack,this.unpack=RY.unpack,this._dataCount=1}return g.prototype.noop=function(){},g.prototype.validateId=function(A){return!A||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(A)},g.prototype.chunk=function(A){for(var e=[],t=A.size,i=Math.ceil(t/Rt.chunkedMTU),I=0,o=0;o<t;){var s=Math.min(t,o+Rt.chunkedMTU),n=A.slice(o,s),r={__peerData:this._dataCount,n:I,data:n,total:i};e.push(r),o=s,I++}return this._dataCount++,e},g.prototype.blobToArrayBuffer=function(A,e){var t=new FileReader;return t.onload=function(i){i.target&&e(i.target.result)},t.readAsArrayBuffer(A),t},g.prototype.binaryStringToArrayBuffer=function(A){for(var e=new Uint8Array(A.length),t=0;t<A.length;t++)e[t]=A.charCodeAt(t)&255;return e.buffer},g.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},g.prototype.isSecure=function(){return location.protocol==="https:"},g}(),Rt=new fQA,rZ={};Or(rZ,"Peer",()=>vK,g=>vK=g);var kD={},DQA=Object.prototype.hasOwnProperty,lo="~";function Gf(){}Object.create&&(Gf.prototype=Object.create(null),new Gf().__proto__||(lo=!1));function yQA(g,A,e){this.fn=g,this.context=A,this.once=e||!1}function aZ(g,A,e,t,i){if(typeof e!="function")throw new TypeError("The listener must be a function");var I=new yQA(e,t||g,i),o=lo?lo+A:A;return g._events[o]?g._events[o].fn?g._events[o]=[g._events[o],I]:g._events[o].push(I):(g._events[o]=I,g._eventsCount++),g}function u0(g,A){--g._eventsCount===0?g._events=new Gf:delete g._events[A]}function YI(){this._events=new Gf,this._eventsCount=0}YI.prototype.eventNames=function(){var A=[],e,t;if(this._eventsCount===0)return A;for(t in e=this._events)DQA.call(e,t)&&A.push(lo?t.slice(1):t);return Object.getOwnPropertySymbols?A.concat(Object.getOwnPropertySymbols(e)):A};YI.prototype.listeners=function(A){var e=lo?lo+A:A,t=this._events[e];if(!t)return[];if(t.fn)return[t.fn];for(var i=0,I=t.length,o=new Array(I);i<I;i++)o[i]=t[i].fn;return o};YI.prototype.listenerCount=function(A){var e=lo?lo+A:A,t=this._events[e];return t?t.fn?1:t.length:0};YI.prototype.emit=function(A,e,t,i,I,o){var s=lo?lo+A:A;if(!this._events[s])return!1;var n=this._events[s],r=arguments.length,a,C;if(n.fn){switch(n.once&&this.removeListener(A,n.fn,void 0,!0),r){case 1:return n.fn.call(n.context),!0;case 2:return n.fn.call(n.context,e),!0;case 3:return n.fn.call(n.context,e,t),!0;case 4:return n.fn.call(n.context,e,t,i),!0;case 5:return n.fn.call(n.context,e,t,i,I),!0;case 6:return n.fn.call(n.context,e,t,i,I,o),!0}for(C=1,a=new Array(r-1);C<r;C++)a[C-1]=arguments[C];n.fn.apply(n.context,a)}else{var Q=n.length,c;for(C=0;C<Q;C++)switch(n[C].once&&this.removeListener(A,n[C].fn,void 0,!0),r){case 1:n[C].fn.call(n[C].context);break;case 2:n[C].fn.call(n[C].context,e);break;case 3:n[C].fn.call(n[C].context,e,t);break;case 4:n[C].fn.call(n[C].context,e,t,i);break;default:if(!a)for(c=1,a=new Array(r-1);c<r;c++)a[c-1]=arguments[c];n[C].fn.apply(n[C].context,a)}}return!0};YI.prototype.on=function(A,e,t){return aZ(this,A,e,t,!1)};YI.prototype.once=function(A,e,t){return aZ(this,A,e,t,!0)};YI.prototype.removeListener=function(A,e,t,i){var I=lo?lo+A:A;if(!this._events[I])return this;if(!e)return u0(this,I),this;var o=this._events[I];if(o.fn)o.fn===e&&(!i||o.once)&&(!t||o.context===t)&&u0(this,I);else{for(var s=0,n=[],r=o.length;s<r;s++)(o[s].fn!==e||i&&!o[s].once||t&&o[s].context!==t)&&n.push(o[s]);n.length?this._events[I]=n.length===1?n[0]:n:u0(this,I)}return this};YI.prototype.removeAllListeners=function(A){var e;return A?(e=lo?lo+A:A,this._events[e]&&u0(this,e)):(this._events=new Gf,this._eventsCount=0),this};YI.prototype.off=YI.prototype.removeListener;YI.prototype.addListener=YI.prototype.on;YI.prefixed=lo;YI.EventEmitter=YI;kD=YI;var le={};Or(le,"LogLevel",()=>So,g=>So=g);Or(le,"default",()=>TY,g=>TY=g);var UQ=function(g,A){var e=typeof Symbol=="function"&&g[Symbol.iterator];if(!e)return g;var t=e.call(g),i,I=[],o;try{for(;(A===void 0||A-- >0)&&!(i=t.next()).done;)I.push(i.value)}catch(s){o={error:s}}finally{try{i&&!i.done&&(e=t.return)&&e.call(t)}finally{if(o)throw o.error}}return I},NQ=function(g,A,e){if(e||arguments.length===2)for(var t=0,i=A.length,I;t<i;t++)(I||!(t in A))&&(I||(I=Array.prototype.slice.call(A,0,t)),I[t]=A[t]);return g.concat(I||Array.prototype.slice.call(A))},wQA="PeerJS: ",So;(function(g){g[g.Disabled=0]="Disabled",g[g.Errors=1]="Errors",g[g.Warnings=2]="Warnings",g[g.All=3]="All"})(So||(So={}));var SQA=function(){function g(){this._logLevel=So.Disabled}return Object.defineProperty(g.prototype,"logLevel",{get:function(){return this._logLevel},set:function(A){this._logLevel=A},enumerable:!1,configurable:!0}),g.prototype.log=function(){for(var A=[],e=0;e<arguments.length;e++)A[e]=arguments[e];this._logLevel>=So.All&&this._print.apply(this,NQ([So.All],UQ(A),!1))},g.prototype.warn=function(){for(var A=[],e=0;e<arguments.length;e++)A[e]=arguments[e];this._logLevel>=So.Warnings&&this._print.apply(this,NQ([So.Warnings],UQ(A),!1))},g.prototype.error=function(){for(var A=[],e=0;e<arguments.length;e++)A[e]=arguments[e];this._logLevel>=So.Errors&&this._print.apply(this,NQ([So.Errors],UQ(A),!1))},g.prototype.setLogFunction=function(A){this._print=A},g.prototype._print=function(A){for(var e=[],t=1;t<arguments.length;t++)e[t-1]=arguments[t];var i=NQ([wQA],UQ(e),!1);for(var I in i)i[I]instanceof Error&&(i[I]="("+i[I].name+") "+i[I].message);A>=So.All?console.log.apply(console,NQ([],UQ(i),!1)):A>=So.Warnings?console.warn.apply(console,NQ(["WARNING"],UQ(i),!1)):A>=So.Errors&&console.error.apply(console,NQ(["ERROR"],UQ(i),!1))},g}(),TY=new SQA,CZ={};Or(CZ,"Socket",()=>HY,g=>HY=g);var Fn;(function(g){g.Data="data",g.Media="media"})(Fn||(Fn={}));var eg;(function(g){g.BrowserIncompatible="browser-incompatible",g.Disconnected="disconnected",g.InvalidID="invalid-id",g.InvalidKey="invalid-key",g.Network="network",g.PeerUnavailable="peer-unavailable",g.SslUnavailable="ssl-unavailable",g.ServerError="server-error",g.SocketError="socket-error",g.SocketClosed="socket-closed",g.UnavailableID="unavailable-id",g.WebRTC="webrtc"})(eg||(eg={}));var ka;(function(g){g.Binary="binary",g.BinaryUTF8="binary-utf8",g.JSON="json"})(ka||(ka={}));var Ya;(function(g){g.Message="message",g.Disconnected="disconnected",g.Error="error",g.Close="close"})(Ya||(Ya={}));var aI;(function(g){g.Heartbeat="HEARTBEAT",g.Candidate="CANDIDATE",g.Offer="OFFER",g.Answer="ANSWER",g.Open="OPEN",g.Error="ERROR",g.IdTaken="ID-TAKEN",g.InvalidKey="INVALID-KEY",g.Leave="LEAVE",g.Expire="EXPIRE"})(aI||(aI={}));var jx={};jx=JSON.parse('{"name":"peerjs","version":"1.4.7","keywords":["peerjs","webrtc","p2p","rtc"],"description":"PeerJS client","homepage":"https://peerjs.com","bugs":{"url":"https://github.com/peers/peerjs/issues"},"repository":{"type":"git","url":"https://github.com/peers/peerjs"},"license":"MIT","contributors":["Michelle Bu <michelle@michellebu.com>","afrokick <devbyru@gmail.com>","ericz <really.ez@gmail.com>","Jairo <kidandcat@gmail.com>","Jonas Gloning <34194370+jonasgloning@users.noreply.github.com>","Jairo Caro-Accino Viciana <jairo@galax.be>","Carlos Caballero <carlos.caballero.gonzalez@gmail.com>","hc <hheennrryy@gmail.com>","Muhammad Asif <capripio@gmail.com>","PrashoonB <prashoonbhattacharjee@gmail.com>","Harsh Bardhan Mishra <47351025+HarshCasper@users.noreply.github.com>","akotynski <aleksanderkotbury@gmail.com>","lmb <i@lmb.io>","Jairooo <jairocaro@msn.com>","Moritz Stückler <moritz.stueckler@gmail.com>","Simon <crydotsnakegithub@gmail.com>","Denis Lukov <denismassters@gmail.com>","Philipp Hancke <fippo@andyet.net>","Hans Oksendahl <hansoksendahl@gmail.com>","Jess <jessachandler@gmail.com>","khankuan <khankuan@gmail.com>","DUODVK <kurmanov.work@gmail.com>","XiZhao <kwang1imsa@gmail.com>","Matthias Lohr <matthias@lohr.me>","=frank tree <=frnktrb@googlemail.com>","Andre Eckardt <aeckardt@outlook.com>","Chris Cowan <agentme49@gmail.com>","Alex Chuev <alex@chuev.com>","alxnull <alxnull@e.mail.de>","Yemel Jardi <angel.jardi@gmail.com>","Ben Parnell <benjaminparnell.94@gmail.com>","Benny Lichtner <bennlich@gmail.com>","fresheneesz <bitetrudpublic@gmail.com>","bob.barstead@exaptive.com <bob.barstead@exaptive.com>","chandika <chandika@gmail.com>","emersion <contact@emersion.fr>","Christopher Van <cvan@users.noreply.github.com>","eddieherm <edhermoso@gmail.com>","Eduardo Pinho <enet4mikeenet@gmail.com>","Evandro Zanatta <ezanatta@tray.net.br>","Gardner Bickford <gardner@users.noreply.github.com>","Gian Luca <gianluca.cecchi@cynny.com>","PatrickJS <github@gdi2290.com>","jonnyf <github@jonathanfoss.co.uk>","Hizkia Felix <hizkifw@gmail.com>","Hristo Oskov <hristo.oskov@gmail.com>","Isaac Madwed <i.madwed@gmail.com>","Ilya Konanykhin <ilya.konanykhin@gmail.com>","jasonbarry <jasbarry@me.com>","Jonathan Burke <jonathan.burke.1311@googlemail.com>","Josh Hamit <josh.hamit@gmail.com>","Jordan Austin <jrax86@gmail.com>","Joel Wetzell <jwetzell@yahoo.com>","xizhao <kevin.wang@cloudera.com>","Alberto Torres <kungfoobar@gmail.com>","Jonathan Mayol <mayoljonathan@gmail.com>","Jefferson Felix <me@jsfelix.dev>","Rolf Erik Lekang <me@rolflekang.com>","Kevin Mai-Husan Chia <mhchia@users.noreply.github.com>","Pepijn de Vos <pepijndevos@gmail.com>","JooYoung <qkdlql@naver.com>","Tobias Speicher <rootcommander@gmail.com>","Steve Blaurock <sblaurock@gmail.com>","Kyrylo Shegeda <shegeda@ualberta.ca>","Diwank Singh Tomer <singh@diwank.name>","Sören Balko <Soeren.Balko@gmail.com>","Arpit Solanki <solankiarpit1997@gmail.com>","Yuki Ito <yuki@gnnk.net>","Artur Zayats <zag2art@gmail.com>"],"funding":{"type":"opencollective","url":"https://opencollective.com/peer"},"collective":{"type":"opencollective","url":"https://opencollective.com/peer"},"files":["dist/*"],"sideEffects":["lib/global.ts","lib/supports.ts"],"main":"dist/bundler.cjs","module":"dist/bundler.mjs","browser-minified":"dist/peerjs.min.js","browser-unminified":"dist/peerjs.js","types":"dist/types.d.ts","engines":{"node":">= 10"},"targets":{"types":{"source":"lib/exports.ts"},"main":{"source":"lib/exports.ts","sourceMap":{"inlineSources":true}},"module":{"source":"lib/exports.ts","includeNodeModules":["eventemitter3"],"sourceMap":{"inlineSources":true}},"browser-minified":{"context":"browser","outputFormat":"global","optimize":true,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"},"browser-unminified":{"context":"browser","outputFormat":"global","optimize":false,"engines":{"browsers":"cover 99%, not dead"},"source":"lib/global.ts"}},"scripts":{"contributors":"git-authors-cli --print=false && prettier --write package.json && git add package.json package-lock.json && git commit -m \\"chore(contributors): update and sort contributors list\\"","check":"tsc --noEmit","watch":"parcel watch","build":"rm -rf dist && parcel build","prepublishOnly":"npm run build","test":"mocha -r ts-node/register -r jsdom-global/register test/**/*.ts","format":"prettier --write .","semantic-release":"semantic-release"},"devDependencies":{"@parcel/config-default":"^2.5.0","@parcel/packager-ts":"^2.5.0","@parcel/transformer-typescript-tsc":"^2.5.0","@parcel/transformer-typescript-types":"^2.5.0","@semantic-release/changelog":"^6.0.1","@semantic-release/git":"^10.0.1","@types/chai":"^4.3.0","@types/mocha":"^9.1.0","@types/node":"^17.0.18","chai":"^4.3.6","git-authors-cli":"^1.0.40","jsdom":"^19.0.0","jsdom-global":"^3.0.2","mocha":"^9.2.0","mock-socket":"8.0.5","parcel":"^2.5.0","parcel-transformer-tsc-sourcemaps":"^1.0.2","prettier":"^2.6.2","semantic-release":"^19.0.2","standard":"^16.0.4","ts-node":"^10.5.0","typescript":"^4.5.5"},"dependencies":{"@swc/helpers":"^0.3.13","eventemitter3":"^4.0.7","peerjs-js-binarypack":"1.0.1","webrtc-adapter":"^7.7.1"}}');var mQA=function(){var g=function(A,e){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var I in i)Object.prototype.hasOwnProperty.call(i,I)&&(t[I]=i[I])},g(A,e)};return function(A,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");g(A,e);function t(){this.constructor=A}A.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}}(),kQA=function(g,A){var e=typeof Symbol=="function"&&g[Symbol.iterator];if(!e)return g;var t=e.call(g),i,I=[],o;try{for(;(A===void 0||A-- >0)&&!(i=t.next()).done;)I.push(i.value)}catch(s){o={error:s}}finally{try{i&&!i.done&&(e=t.return)&&e.call(t)}finally{if(o)throw o.error}}return I},MQA=function(g,A,e){if(e||arguments.length===2)for(var t=0,i=A.length,I;t<i;t++)(I||!(t in A))&&(I||(I=Array.prototype.slice.call(A,0,t)),I[t]=A[t]);return g.concat(I||Array.prototype.slice.call(A))},GQA=function(g){var A=typeof Symbol=="function"&&Symbol.iterator,e=A&&g[A],t=0;if(e)return e.call(g);if(g&&typeof g.length=="number")return{next:function(){return g&&t>=g.length&&(g=void 0),{value:g&&g[t++],done:!g}}};throw new TypeError(A?"Object is not iterable.":"Symbol.iterator is not defined.")},HY=function(g){mQA(A,g);function A(e,t,i,I,o,s){s===void 0&&(s=5e3);var n=g.call(this)||this;n.pingInterval=s,n._disconnected=!0,n._messagesQueue=[];var r=e?"wss://":"ws://";return n._baseUrl=r+t+":"+i+I+"peerjs?key="+o,n}return A.prototype.start=function(e,t){var i=this;this._id=e;var I="".concat(this._baseUrl,"&id=").concat(e,"&token=").concat(t);this._socket||!this._disconnected||(this._socket=new WebSocket(I+"&version="+jx.version),this._disconnected=!1,this._socket.onmessage=function(o){var s;try{s=JSON.parse(o.data),le.default.log("Server message received:",s)}catch{le.default.log("Invalid server message",o.data);return}i.emit(Ya.Message,s)},this._socket.onclose=function(o){i._disconnected||(le.default.log("Socket closed.",o),i._cleanup(),i._disconnected=!0,i.emit(Ya.Disconnected))},this._socket.onopen=function(){i._disconnected||(i._sendQueuedMessages(),le.default.log("Socket open"),i._scheduleHeartbeat())})},A.prototype._scheduleHeartbeat=function(){var e=this;this._wsPingTimer=setTimeout(function(){e._sendHeartbeat()},this.pingInterval)},A.prototype._sendHeartbeat=function(){if(!this._wsOpen()){le.default.log("Cannot send heartbeat, because socket closed");return}var e=JSON.stringify({type:aI.Heartbeat});this._socket.send(e),this._scheduleHeartbeat()},A.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},A.prototype._sendQueuedMessages=function(){var e,t,i=MQA([],kQA(this._messagesQueue),!1);this._messagesQueue=[];try{for(var I=GQA(i),o=I.next();!o.done;o=I.next()){var s=o.value;this.send(s)}}catch(n){e={error:n}}finally{try{o&&!o.done&&(t=I.return)&&t.call(I)}finally{if(e)throw e.error}}},A.prototype.send=function(e){if(!this._disconnected){if(!this._id){this._messagesQueue.push(e);return}if(!e.type){this.emit(Ya.Error,"Invalid message");return}if(this._wsOpen()){var t=JSON.stringify(e);this._socket.send(t)}}},A.prototype.close=function(){this._disconnected||(this._cleanup(),this._disconnected=!0)},A.prototype._cleanup=function(){this._socket&&(this._socket.onopen=this._socket.onmessage=this._socket.onclose=null,this._socket.close(),this._socket=void 0),clearTimeout(this._wsPingTimer)},A}(kD.EventEmitter),JK={};Or(JK,"MediaConnection",()=>PY,g=>PY=g);var zx={};Or(zx,"Negotiator",()=>YY,g=>YY=g);var Qm=function(){return Qm=Object.assign||function(g){for(var A,e=1,t=arguments.length;e<t;e++){A=arguments[e];for(var i in A)Object.prototype.hasOwnProperty.call(A,i)&&(g[i]=A[i])}return g},Qm.apply(this,arguments)},nS=function(g,A,e,t){function i(I){return I instanceof e?I:new e(function(o){o(I)})}return new(e||(e=Promise))(function(I,o){function s(a){try{r(t.next(a))}catch(C){o(C)}}function n(a){try{r(t.throw(a))}catch(C){o(C)}}function r(a){a.done?I(a.value):i(a.value).then(s,n)}r((t=t.apply(g,A||[])).next())})},rS=function(g,A){var e={label:0,sent:function(){if(I[0]&1)throw I[1];return I[1]},trys:[],ops:[]},t,i,I,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function s(r){return function(a){return n([r,a])}}function n(r){if(t)throw new TypeError("Generator is already executing.");for(;e;)try{if(t=1,i&&(I=r[0]&2?i.return:r[0]?i.throw||((I=i.return)&&I.call(i),0):i.next)&&!(I=I.call(i,r[1])).done)return I;switch(i=0,I&&(r=[r[0]&2,I.value]),r[0]){case 0:case 1:I=r;break;case 4:return e.label++,{value:r[1],done:!1};case 5:e.label++,i=r[1],r=[0];continue;case 7:r=e.ops.pop(),e.trys.pop();continue;default:if(I=e.trys,!(I=I.length>0&&I[I.length-1])&&(r[0]===6||r[0]===2)){e=0;continue}if(r[0]===3&&(!I||r[1]>I[0]&&r[1]<I[3])){e.label=r[1];break}if(r[0]===6&&e.label<I[1]){e.label=I[1],I=r;break}if(I&&e.label<I[2]){e.label=I[2],e.ops.push(r);break}I[2]&&e.ops.pop(),e.trys.pop();continue}r=A.call(g,e)}catch(a){r=[6,a],i=0}finally{t=I=0}if(r[0]&5)throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}},YY=function(){function g(A){this.connection=A}return g.prototype.startConnection=function(A){var e=this._startPeerConnection();if(this.connection.peerConnection=e,this.connection.type===Fn.Media&&A._stream&&this._addTracksToConnection(A._stream,e),A.originator){if(this.connection.type===Fn.Data){var t=this.connection,i={ordered:!!A.reliable},I=e.createDataChannel(t.label,i);t.initialize(I)}this._makeOffer()}else this.handleSDP("OFFER",A.sdp)},g.prototype._startPeerConnection=function(){le.default.log("Creating RTCPeerConnection.");var A=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(A),A},g.prototype._setupListeners=function(A){var e=this,t=this.connection.peer,i=this.connection.connectionId,I=this.connection.type,o=this.connection.provider;le.default.log("Listening for ICE candidates."),A.onicecandidate=function(s){!s.candidate||!s.candidate.candidate||(le.default.log("Received ICE candidates for ".concat(t,":"),s.candidate),o.socket.send({type:aI.Candidate,payload:{candidate:s.candidate,type:I,connectionId:i},dst:t}))},A.oniceconnectionstatechange=function(){switch(A.iceConnectionState){case"failed":le.default.log("iceConnectionState is failed, closing connections to "+t),e.connection.emit("error",new Error("Negotiation of connection to "+t+" failed.")),e.connection.close();break;case"closed":le.default.log("iceConnectionState is closed, closing connections to "+t),e.connection.emit("error",new Error("Connection to "+t+" closed.")),e.connection.close();break;case"disconnected":le.default.log("iceConnectionState changed to disconnected on the connection with "+t);break;case"completed":A.onicecandidate=Rt.noop;break}e.connection.emit("iceStateChanged",A.iceConnectionState)},le.default.log("Listening for data channel"),A.ondatachannel=function(s){le.default.log("Received data channel");var n=s.channel,r=o.getConnection(t,i);r.initialize(n)},le.default.log("Listening for remote stream"),A.ontrack=function(s){le.default.log("Received remote stream");var n=s.streams[0],r=o.getConnection(t,i);if(r.type===Fn.Media){var a=r;e._addStreamToMediaConnection(n,a)}}},g.prototype.cleanup=function(){le.default.log("Cleaning up PeerConnection to "+this.connection.peer);var A=this.connection.peerConnection;if(A){this.connection.peerConnection=null,A.onicecandidate=A.oniceconnectionstatechange=A.ondatachannel=A.ontrack=function(){};var e=A.signalingState!=="closed",t=!1;if(this.connection.type===Fn.Data){var i=this.connection,I=i.dataChannel;I&&(t=!!I.readyState&&I.readyState!=="closed")}(e||t)&&A.close()}},g.prototype._makeOffer=function(){return nS(this,void 0,Promise,function(){var A,e,t,i,I,o,s;return rS(this,function(n){switch(n.label){case 0:A=this.connection.peerConnection,e=this.connection.provider,n.label=1;case 1:return n.trys.push([1,7,,8]),[4,A.createOffer(this.connection.options.constraints)];case 2:t=n.sent(),le.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(t.sdp=this.connection.options.sdpTransform(t.sdp)||t.sdp),n.label=3;case 3:return n.trys.push([3,5,,6]),[4,A.setLocalDescription(t)];case 4:return n.sent(),le.default.log("Set localDescription:",t,"for:".concat(this.connection.peer)),i={sdp:t,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:Rt.browser},this.connection.type===Fn.Data&&(I=this.connection,i=Qm(Qm({},i),{label:I.label,reliable:I.reliable,serialization:I.serialization})),e.socket.send({type:aI.Offer,payload:i,dst:this.connection.peer}),[3,6];case 5:return o=n.sent(),o!="OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"&&(e.emitError(eg.WebRTC,o),le.default.log("Failed to setLocalDescription, ",o)),[3,6];case 6:return[3,8];case 7:return s=n.sent(),e.emitError(eg.WebRTC,s),le.default.log("Failed to createOffer, ",s),[3,8];case 8:return[2]}})})},g.prototype._makeAnswer=function(){return nS(this,void 0,Promise,function(){var A,e,t,i,I;return rS(this,function(o){switch(o.label){case 0:A=this.connection.peerConnection,e=this.connection.provider,o.label=1;case 1:return o.trys.push([1,7,,8]),[4,A.createAnswer()];case 2:t=o.sent(),le.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(t.sdp=this.connection.options.sdpTransform(t.sdp)||t.sdp),o.label=3;case 3:return o.trys.push([3,5,,6]),[4,A.setLocalDescription(t)];case 4:return o.sent(),le.default.log("Set localDescription:",t,"for:".concat(this.connection.peer)),e.socket.send({type:aI.Answer,payload:{sdp:t,type:this.connection.type,connectionId:this.connection.connectionId,browser:Rt.browser},dst:this.connection.peer}),[3,6];case 5:return i=o.sent(),e.emitError(eg.WebRTC,i),le.default.log("Failed to setLocalDescription, ",i),[3,6];case 6:return[3,8];case 7:return I=o.sent(),e.emitError(eg.WebRTC,I),le.default.log("Failed to create answer, ",I),[3,8];case 8:return[2]}})})},g.prototype.handleSDP=function(A,e){return nS(this,void 0,Promise,function(){var t,i,I,o;return rS(this,function(s){switch(s.label){case 0:e=new RTCSessionDescription(e),t=this.connection.peerConnection,i=this.connection.provider,le.default.log("Setting remote description",e),I=this,s.label=1;case 1:return s.trys.push([1,5,,6]),[4,t.setRemoteDescription(e)];case 2:return s.sent(),le.default.log("Set remoteDescription:".concat(A," for:").concat(this.connection.peer)),A!=="OFFER"?[3,4]:[4,I._makeAnswer()];case 3:s.sent(),s.label=4;case 4:return[3,6];case 5:return o=s.sent(),i.emitError(eg.WebRTC,o),le.default.log("Failed to setRemoteDescription, ",o),[3,6];case 6:return[2]}})})},g.prototype.handleCandidate=function(A){return nS(this,void 0,Promise,function(){var e,t,i,I,o,s;return rS(this,function(n){switch(n.label){case 0:le.default.log("handleCandidate:",A),e=A.candidate,t=A.sdpMLineIndex,i=A.sdpMid,I=this.connection.peerConnection,o=this.connection.provider,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,I.addIceCandidate(new RTCIceCandidate({sdpMid:i,sdpMLineIndex:t,candidate:e}))];case 2:return n.sent(),le.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return s=n.sent(),o.emitError(eg.WebRTC,s),le.default.log("Failed to handleCandidate, ",s),[3,4];case 4:return[2]}})})},g.prototype._addTracksToConnection=function(A,e){if(le.default.log("add tracks from stream ".concat(A.id," to peer connection")),!e.addTrack)return le.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");A.getTracks().forEach(function(t){e.addTrack(t,A)})},g.prototype._addStreamToMediaConnection=function(A,e){le.default.log("add stream ".concat(A.id," to media connection ").concat(e.connectionId)),e.addStream(A)},g}(),Vx={};Or(Vx,"BaseConnection",()=>OY,g=>OY=g);var RQA=function(){var g=function(A,e){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var I in i)Object.prototype.hasOwnProperty.call(i,I)&&(t[I]=i[I])},g(A,e)};return function(A,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");g(A,e);function t(){this.constructor=A}A.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}}(),OY=function(g){RQA(A,g);function A(e,t,i){var I=g.call(this)||this;return I.peer=e,I.provider=t,I.options=i,I._open=!1,I.metadata=i.metadata,I}return Object.defineProperty(A.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),A}(kD.EventEmitter),UQA=function(){var g=function(A,e){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var I in i)Object.prototype.hasOwnProperty.call(i,I)&&(t[I]=i[I])},g(A,e)};return function(A,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");g(A,e);function t(){this.constructor=A}A.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}}(),cm=function(){return cm=Object.assign||function(g){for(var A,e=1,t=arguments.length;e<t;e++){A=arguments[e];for(var i in A)Object.prototype.hasOwnProperty.call(A,i)&&(g[i]=A[i])}return g},cm.apply(this,arguments)},NQA=function(g){var A=typeof Symbol=="function"&&Symbol.iterator,e=A&&g[A],t=0;if(e)return e.call(g);if(g&&typeof g.length=="number")return{next:function(){return g&&t>=g.length&&(g=void 0),{value:g&&g[t++],done:!g}}};throw new TypeError(A?"Object is not iterable.":"Symbol.iterator is not defined.")},PY=function(g){UQA(A,g);function A(e,t,i){var I=g.call(this,e,t,i)||this;return I._localStream=I.options._stream,I.connectionId=I.options.connectionId||A.ID_PREFIX+Rt.randomToken(),I._negotiator=new zx.Negotiator(I),I._localStream&&I._negotiator.startConnection({_stream:I._localStream,originator:!0}),I}return Object.defineProperty(A.prototype,"type",{get:function(){return Fn.Media},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"localStream",{get:function(){return this._localStream},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"remoteStream",{get:function(){return this._remoteStream},enumerable:!1,configurable:!0}),A.prototype.addStream=function(e){le.default.log("Receiving stream",e),this._remoteStream=e,g.prototype.emit.call(this,"stream",e)},A.prototype.handleMessage=function(e){var t=e.type,i=e.payload;switch(e.type){case aI.Answer:this._negotiator.handleSDP(t,i.sdp),this._open=!0;break;case aI.Candidate:this._negotiator.handleCandidate(i.candidate);break;default:le.default.warn("Unrecognized message type:".concat(t," from peer:").concat(this.peer));break}},A.prototype.answer=function(e,t){var i,I;if(t===void 0&&(t={}),this._localStream){le.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=e,t&&t.sdpTransform&&(this.options.sdpTransform=t.sdpTransform),this._negotiator.startConnection(cm(cm({},this.options._payload),{_stream:e}));var o=this.provider._getMessages(this.connectionId);try{for(var s=NQA(o),n=s.next();!n.done;n=s.next()){var r=n.value;this.handleMessage(r)}}catch(a){i={error:a}}finally{try{n&&!n.done&&(I=s.return)&&I.call(s)}finally{if(i)throw i.error}}this._open=!0},A.prototype.close=function(){this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this._localStream=null,this._remoteStream=null,this.provider&&(this.provider._removeConnection(this),this.provider=null),this.options&&this.options._stream&&(this.options._stream=null),this.open&&(this._open=!1,g.prototype.emit.call(this,"close"))},A.ID_PREFIX="mc_",A}(Vx.BaseConnection),xK={};Or(xK,"DataConnection",()=>ZY,g=>ZY=g);var BZ={};Or(BZ,"EncodingQueue",()=>WY,g=>WY=g);var FQA=function(){var g=function(A,e){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var I in i)Object.prototype.hasOwnProperty.call(i,I)&&(t[I]=i[I])},g(A,e)};return function(A,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");g(A,e);function t(){this.constructor=A}A.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}}(),WY=function(g){FQA(A,g);function A(){var e=g.call(this)||this;return e.fileReader=new FileReader,e._queue=[],e._processing=!1,e.fileReader.onload=function(t){e._processing=!1,t.target&&e.emit("done",t.target.result),e.doNextTask()},e.fileReader.onerror=function(t){le.default.error("EncodingQueue error:",t),e._processing=!1,e.destroy(),e.emit("error",t)},e}return Object.defineProperty(A.prototype,"queue",{get:function(){return this._queue},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"size",{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"processing",{get:function(){return this._processing},enumerable:!1,configurable:!0}),A.prototype.enque=function(e){this.queue.push(e),!this.processing&&this.doNextTask()},A.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},A.prototype.doNextTask=function(){this.size!==0&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},A}(kD.EventEmitter),KQA=function(){var g=function(A,e){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var I in i)Object.prototype.hasOwnProperty.call(i,I)&&(t[I]=i[I])},g(A,e)};return function(A,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");g(A,e);function t(){this.constructor=A}A.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}}(),bQA=function(g){var A=typeof Symbol=="function"&&Symbol.iterator,e=A&&g[A],t=0;if(e)return e.call(g);if(g&&typeof g.length=="number")return{next:function(){return g&&t>=g.length&&(g=void 0),{value:g&&g[t++],done:!g}}};throw new TypeError(A?"Object is not iterable.":"Symbol.iterator is not defined.")},ZY=function(g){KQA(A,g);function A(e,t,i){var I=g.call(this,e,t,i)||this;return I.stringify=JSON.stringify,I.parse=JSON.parse,I._buffer=[],I._bufferSize=0,I._buffering=!1,I._chunkedData={},I._encodingQueue=new BZ.EncodingQueue,I.connectionId=I.options.connectionId||A.ID_PREFIX+Rt.randomToken(),I.label=I.options.label||I.connectionId,I.serialization=I.options.serialization||ka.Binary,I.reliable=!!I.options.reliable,I._encodingQueue.on("done",function(o){I._bufferedSend(o)}),I._encodingQueue.on("error",function(){le.default.error("DC#".concat(I.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),I.close()}),I._negotiator=new zx.Negotiator(I),I._negotiator.startConnection(I.options._payload||{originator:!0}),I}return Object.defineProperty(A.prototype,"type",{get:function(){return Fn.Data},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"dataChannel",{get:function(){return this._dc},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"bufferSize",{get:function(){return this._bufferSize},enumerable:!1,configurable:!0}),A.prototype.initialize=function(e){this._dc=e,this._configureDataChannel()},A.prototype._configureDataChannel=function(){var e=this;(!Rt.supports.binaryBlob||Rt.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){le.default.log("DC#".concat(e.connectionId," dc connection success")),e._open=!0,e.emit("open")},this.dataChannel.onmessage=function(t){le.default.log("DC#".concat(e.connectionId," dc onmessage:"),t.data),e._handleDataMessage(t)},this.dataChannel.onclose=function(){le.default.log("DC#".concat(e.connectionId," dc closed for:"),e.peer),e.close()}},A.prototype._handleDataMessage=function(e){var t=this,i=e.data,I=i.constructor,o=this.serialization===ka.Binary||this.serialization===ka.BinaryUTF8,s=i;if(o){if(I===Blob){Rt.blobToArrayBuffer(i,function(r){var a=Rt.unpack(r);t.emit("data",a)});return}else if(I===ArrayBuffer)s=Rt.unpack(i);else if(I===String){var n=Rt.binaryStringToArrayBuffer(i);s=Rt.unpack(n)}}else this.serialization===ka.JSON&&(s=this.parse(i));if(s.__peerData){this._handleChunk(s);return}g.prototype.emit.call(this,"data",s)},A.prototype._handleChunk=function(e){var t=e.__peerData,i=this._chunkedData[t]||{data:[],count:0,total:e.total};if(i.data[e.n]=e.data,i.count++,this._chunkedData[t]=i,i.total===i.count){delete this._chunkedData[t];var I=new Blob(i.data);this._handleDataMessage({data:I})}},A.prototype.close=function(){this._buffer=[],this._bufferSize=0,this._chunkedData={},this._negotiator&&(this._negotiator.cleanup(),this._negotiator=null),this.provider&&(this.provider._removeConnection(this),this.provider=null),this.dataChannel&&(this.dataChannel.onopen=null,this.dataChannel.onmessage=null,this.dataChannel.onclose=null,this._dc=null),this._encodingQueue&&(this._encodingQueue.destroy(),this._encodingQueue.removeAllListeners(),this._encodingQueue=null),this.open&&(this._open=!1,g.prototype.emit.call(this,"close"))},A.prototype.send=function(e,t){if(!this.open){g.prototype.emit.call(this,"error",new Error("Connection is not open. You should listen for the `open` event before sending messages."));return}if(this.serialization===ka.JSON)this._bufferedSend(this.stringify(e));else if(this.serialization===ka.Binary||this.serialization===ka.BinaryUTF8){var i=Rt.pack(e);if(!t&&i.size>Rt.chunkedMTU){this._sendChunks(i);return}Rt.supports.binaryBlob?this._bufferedSend(i):this._encodingQueue.enque(i)}else this._bufferedSend(e)},A.prototype._bufferedSend=function(e){(this._buffering||!this._trySend(e))&&(this._buffer.push(e),this._bufferSize=this._buffer.length)},A.prototype._trySend=function(e){var t=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>A.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){t._buffering=!1,t._tryBuffer()},50),!1;try{this.dataChannel.send(e)}catch(i){return le.default.error("DC#:".concat(this.connectionId," Error when sending:"),i),this._buffering=!0,this.close(),!1}return!0},A.prototype._tryBuffer=function(){if(this.open&&this._buffer.length!==0){var e=this._buffer[0];this._trySend(e)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}},A.prototype._sendChunks=function(e){var t,i,I=Rt.chunk(e);le.default.log("DC#".concat(this.connectionId," Try to send ").concat(I.length," chunks..."));try{for(var o=bQA(I),s=o.next();!s.done;s=o.next()){var n=s.value;this.send(n,!0)}}catch(r){t={error:r}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}},A.prototype.handleMessage=function(e){var t=e.payload;switch(e.type){case aI.Answer:this._negotiator.handleSDP(e.type,t.sdp);break;case aI.Candidate:this._negotiator.handleCandidate(t.candidate);break;default:le.default.warn("Unrecognized message type:",e.type,"from peer:",this.peer);break}},A.ID_PREFIX="dc_",A.MAX_BUFFERED_AMOUNT=8388608,A}(Vx.BaseConnection),QZ={};Or(QZ,"API",()=>VY,g=>VY=g);var jY=function(g,A,e,t){function i(I){return I instanceof e?I:new e(function(o){o(I)})}return new(e||(e=Promise))(function(I,o){function s(a){try{r(t.next(a))}catch(C){o(C)}}function n(a){try{r(t.throw(a))}catch(C){o(C)}}function r(a){a.done?I(a.value):i(a.value).then(s,n)}r((t=t.apply(g,A||[])).next())})},zY=function(g,A){var e={label:0,sent:function(){if(I[0]&1)throw I[1];return I[1]},trys:[],ops:[]},t,i,I,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function s(r){return function(a){return n([r,a])}}function n(r){if(t)throw new TypeError("Generator is already executing.");for(;e;)try{if(t=1,i&&(I=r[0]&2?i.return:r[0]?i.throw||((I=i.return)&&I.call(i),0):i.next)&&!(I=I.call(i,r[1])).done)return I;switch(i=0,I&&(r=[r[0]&2,I.value]),r[0]){case 0:case 1:I=r;break;case 4:return e.label++,{value:r[1],done:!1};case 5:e.label++,i=r[1],r=[0];continue;case 7:r=e.ops.pop(),e.trys.pop();continue;default:if(I=e.trys,!(I=I.length>0&&I[I.length-1])&&(r[0]===6||r[0]===2)){e=0;continue}if(r[0]===3&&(!I||r[1]>I[0]&&r[1]<I[3])){e.label=r[1];break}if(r[0]===6&&e.label<I[1]){e.label=I[1],I=r;break}if(I&&e.label<I[2]){e.label=I[2],e.ops.push(r);break}I[2]&&e.ops.pop(),e.trys.pop();continue}r=A.call(g,e)}catch(a){r=[6,a],i=0}finally{t=I=0}if(r[0]&5)throw r[1];return{value:r[0]?r[1]:void 0,done:!0}}},VY=function(){function g(A){this._options=A}return g.prototype._buildRequest=function(A){var e=this._options.secure?"https":"http",t=this._options,i=t.host,I=t.port,o=t.path,s=t.key,n=new URL("".concat(e,"://").concat(i,":").concat(I).concat(o).concat(s,"/").concat(A));return n.searchParams.set("ts","".concat(Date.now()).concat(Math.random())),n.searchParams.set("version",jx.version),fetch(n.href,{referrerPolicy:this._options.referrerPolicy})},g.prototype.retrieveId=function(){return jY(this,void 0,Promise,function(){var A,e,t;return zY(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._buildRequest("id")];case 1:if(A=i.sent(),A.status!==200)throw new Error("Error. Status:".concat(A.status));return[2,A.text()];case 2:throw e=i.sent(),le.default.error("Error retrieving ID",e),t="",this._options.path==="/"&&this._options.host!==Rt.CLOUD_HOST&&(t=" If you passed in a `path` to your self-hosted PeerServer, you'll also need to pass in that same path when creating a new Peer."),new Error("Could not get an ID from the server."+t);case 3:return[2]}})})},g.prototype.listAllPeers=function(){return jY(this,void 0,Promise,function(){var A,e,t;return zY(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this._buildRequest("peers")];case 1:if(A=i.sent(),A.status!==200)throw A.status===401?(e="",this._options.host===Rt.CLOUD_HOST?e="It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":e="You need to enable `allow_discovery` on your self-hosted PeerServer to use this feature.",new Error("It doesn't look like you have permission to list peers IDs. "+e)):new Error("Error. Status:".concat(A.status));return[2,A.json()];case 2:throw t=i.sent(),le.default.error("Error retrieving list peers",t),new Error("Could not get list peers from the server."+t);case 3:return[2]}})})},g}(),JQA=function(){var g=function(A,e){return g=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var I in i)Object.prototype.hasOwnProperty.call(i,I)&&(t[I]=i[I])},g(A,e)};return function(A,e){if(typeof e!="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");g(A,e);function t(){this.constructor=A}A.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}}(),Jp=function(){return Jp=Object.assign||function(g){for(var A,e=1,t=arguments.length;e<t;e++){A=arguments[e];for(var i in A)Object.prototype.hasOwnProperty.call(A,i)&&(g[i]=A[i])}return g},Jp.apply(this,arguments)},ku=function(g){var A=typeof Symbol=="function"&&Symbol.iterator,e=A&&g[A],t=0;if(e)return e.call(g);if(g&&typeof g.length=="number")return{next:function(){return g&&t>=g.length&&(g=void 0),{value:g&&g[t++],done:!g}}};throw new TypeError(A?"Object is not iterable.":"Symbol.iterator is not defined.")},xQA=function(g,A){var e=typeof Symbol=="function"&&g[Symbol.iterator];if(!e)return g;var t=e.call(g),i,I=[],o;try{for(;(A===void 0||A-- >0)&&!(i=t.next()).done;)I.push(i.value)}catch(s){o={error:s}}finally{try{i&&!i.done&&(e=t.return)&&e.call(t)}finally{if(o)throw o.error}}return I},vK=function(g){JQA(A,g);function A(e,t){var i=g.call(this)||this;i._id=null,i._lastServerId=null,i._destroyed=!1,i._disconnected=!1,i._open=!1,i._connections=new Map,i._lostMessages=new Map;var I;return e&&e.constructor==Object?t=e:e&&(I=e.toString()),t=Jp({debug:0,host:Rt.CLOUD_HOST,port:Rt.CLOUD_PORT,path:"/",key:A.DEFAULT_KEY,token:Rt.randomToken(),config:Rt.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},t),i._options=t,i._options.host==="/"&&(i._options.host=window.location.hostname),i._options.path&&(i._options.path[0]!=="/"&&(i._options.path="/"+i._options.path),i._options.path[i._options.path.length-1]!=="/"&&(i._options.path+="/")),i._options.secure===void 0&&i._options.host!==Rt.CLOUD_HOST?i._options.secure=Rt.isSecure():i._options.host==Rt.CLOUD_HOST&&(i._options.secure=!0),i._options.logFunction&&le.default.setLogFunction(i._options.logFunction),le.default.logLevel=i._options.debug||0,i._api=new QZ.API(t),i._socket=i._createServerConnection(),!Rt.supports.audioVideo&&!Rt.supports.data?(i._delayedAbort(eg.BrowserIncompatible,"The current browser does not support WebRTC"),i):I&&!Rt.validateId(I)?(i._delayedAbort(eg.InvalidID,'ID "'.concat(I,'" is invalid')),i):(I?i._initialize(I):i._api.retrieveId().then(function(o){return i._initialize(o)}).catch(function(o){return i._abort(eg.ServerError,o)}),i)}return Object.defineProperty(A.prototype,"id",{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"socket",{get:function(){return this._socket},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"connections",{get:function(){var e,t,i=Object.create(null);try{for(var I=ku(this._connections),o=I.next();!o.done;o=I.next()){var s=xQA(o.value,2),n=s[0],r=s[1];i[n]=r}}catch(a){e={error:a}}finally{try{o&&!o.done&&(t=I.return)&&t.call(I)}finally{if(e)throw e.error}}return i},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"destroyed",{get:function(){return this._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(A.prototype,"disconnected",{get:function(){return this._disconnected},enumerable:!1,configurable:!0}),A.prototype._createServerConnection=function(){var e=this,t=new CZ.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return t.on(Ya.Message,function(i){e._handleMessage(i)}),t.on(Ya.Error,function(i){e._abort(eg.SocketError,i)}),t.on(Ya.Disconnected,function(){e.disconnected||(e.emitError(eg.Network,"Lost connection to server."),e.disconnect())}),t.on(Ya.Close,function(){e.disconnected||e._abort(eg.SocketClosed,"Underlying socket is already closed.")}),t},A.prototype._initialize=function(e){this._id=e,this.socket.start(e,this._options.token)},A.prototype._handleMessage=function(e){var t,i,I=e.type,o=e.payload,s=e.src;switch(I){case aI.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case aI.Error:this._abort(eg.ServerError,o.msg);break;case aI.IdTaken:this._abort(eg.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case aI.InvalidKey:this._abort(eg.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case aI.Leave:le.default.log("Received leave message from ".concat(s)),this._cleanupPeer(s),this._connections.delete(s);break;case aI.Expire:this.emitError(eg.PeerUnavailable,"Could not connect to peer ".concat(s));break;case aI.Offer:var E=o.connectionId,h=this.getConnection(s,E);if(h&&(h.close(),le.default.warn("Offer received for existing Connection ID:".concat(E))),o.type===Fn.Media){var n=new JK.MediaConnection(s,this,{connectionId:E,_payload:o,metadata:o.metadata});h=n,this._addConnection(s,h),this.emit("call",n)}else if(o.type===Fn.Data){var r=new xK.DataConnection(s,this,{connectionId:E,_payload:o,metadata:o.metadata,label:o.label,serialization:o.serialization,reliable:o.reliable});h=r,this._addConnection(s,h),this.emit("connection",r)}else{le.default.warn("Received malformed connection type:".concat(o.type));return}var a=this._getMessages(E);try{for(var C=ku(a),Q=C.next();!Q.done;Q=C.next()){var c=Q.value;h.handleMessage(c)}}catch(l){t={error:l}}finally{try{Q&&!Q.done&&(i=C.return)&&i.call(C)}finally{if(t)throw t.error}}break;default:if(!o){le.default.warn("You received a malformed message from ".concat(s," of type ").concat(I));return}var E=o.connectionId,h=this.getConnection(s,E);h&&h.peerConnection?h.handleMessage(e):E?this._storeMessage(E,e):le.default.warn("You received an unrecognized message:",e);break}},A.prototype._storeMessage=function(e,t){this._lostMessages.has(e)||this._lostMessages.set(e,[]),this._lostMessages.get(e).push(t)},A.prototype._getMessages=function(e){var t=this._lostMessages.get(e);return t?(this._lostMessages.delete(e),t):[]},A.prototype.connect=function(e,t){if(t===void 0&&(t={}),this.disconnected){le.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect, or call reconnect on this peer if you believe its ID to still be available."),this.emitError(eg.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var i=new xK.DataConnection(e,this,t);return this._addConnection(e,i),i},A.prototype.call=function(e,t,i){if(i===void 0&&(i={}),this.disconnected){le.default.warn("You cannot connect to a new Peer because you called .disconnect() on this Peer and ended your connection with the server. You can create a new Peer to reconnect."),this.emitError(eg.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!t){le.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var I=new JK.MediaConnection(e,this,Jp(Jp({},i),{_stream:t}));return this._addConnection(e,I),I},A.prototype._addConnection=function(e,t){le.default.log("add connection ".concat(t.type,":").concat(t.connectionId," to peerId:").concat(e)),this._connections.has(e)||this._connections.set(e,[]),this._connections.get(e).push(t)},A.prototype._removeConnection=function(e){var t=this._connections.get(e.peer);if(t){var i=t.indexOf(e);i!==-1&&t.splice(i,1)}this._lostMessages.delete(e.connectionId)},A.prototype.getConnection=function(e,t){var i,I,o=this._connections.get(e);if(!o)return null;try{for(var s=ku(o),n=s.next();!n.done;n=s.next()){var r=n.value;if(r.connectionId===t)return r}}catch(a){i={error:a}}finally{try{n&&!n.done&&(I=s.return)&&I.call(s)}finally{if(i)throw i.error}}return null},A.prototype._delayedAbort=function(e,t){var i=this;setTimeout(function(){i._abort(e,t)},0)},A.prototype._abort=function(e,t){le.default.error("Aborting!"),this.emitError(e,t),this._lastServerId?this.disconnect():this.destroy()},A.prototype.emitError=function(e,t){le.default.error("Error:",t);var i;typeof t=="string"?i=new Error(t):i=t,i.type=e,this.emit("error",i)},A.prototype.destroy=function(){this.destroyed||(le.default.log("Destroy peer with ID:".concat(this.id)),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit("close"))},A.prototype._cleanup=function(){var e,t;try{for(var i=ku(this._connections.keys()),I=i.next();!I.done;I=i.next()){var o=I.value;this._cleanupPeer(o),this._connections.delete(o)}}catch(s){e={error:s}}finally{try{I&&!I.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}this.socket.removeAllListeners()},A.prototype._cleanupPeer=function(e){var t,i,I=this._connections.get(e);if(I)try{for(var o=ku(I),s=o.next();!s.done;s=o.next()){var n=s.value;n.close()}}catch(r){t={error:r}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(t)throw t.error}}},A.prototype.disconnect=function(){if(!this.disconnected){var e=this.id;le.default.log("Disconnect peer with ID:".concat(e)),this._disconnected=!0,this._open=!1,this.socket.close(),this._lastServerId=e,this._id=null,this.emit("disconnected",e)}},A.prototype.reconnect=function(){if(this.disconnected&&!this.destroyed)le.default.log("Attempting reconnection to server with ID ".concat(this._lastServerId)),this._disconnected=!1,this._initialize(this._lastServerId);else{if(this.destroyed)throw new Error("This peer cannot reconnect to the server. It has already been destroyed.");if(!this.disconnected&&!this.open)le.default.error("In a hurry? We're still trying to make the initial connection!");else throw new Error("Peer ".concat(this.id," cannot reconnect because it is not disconnected from the server!"))}},A.prototype.listAllPeers=function(e){var t=this;e===void 0&&(e=function(i){}),this._api.listAllPeers().then(function(i){return e(i)}).catch(function(i){return t._abort(eg.ServerError,i)})},A.DEFAULT_KEY="peerjs",A}(kD.EventEmitter),qK=rZ.Peer;const vQA=Object.freeze(Object.defineProperty({__proto__:null,get Peer(){return vK},default:qK,util:Rt},Symbol.toStringTag,{value:"Module"}));let Xx;function qQA(){return Xx}function LQA(g){Xx=g}function cZ(g,A){return A||(A={}),A={...Xx,...A},g?new qK(g,A):new qK(A)}async function XY(){const g=await Promise.resolve().then(()=>vQA);return console.log(g),g.default===void 0?g:g.default}class EZ{constructor(){B(this,"_host");B(this,"_client");B(this,"_clientData");this.onEnable()}get isHost(){return this._host!==void 0}onEnable(){const A="HOST-5980e65c-8438-453e-8b35-f13c736dcd81";this.trySetupHost(A)}async trySetupHost(A){const e=await XY(),t=new e(A);t.on("error",i=>{console.error(i),this._host=void 0,this.trySetupClient(A)}),t.on("open",i=>{this._host=new TQA(t)})}async trySetupClient(A){const e=await XY();this._client=new e,this._client.on("error",t=>{console.error("Client error",t)}),this._client.on("open",t=>{console.log("client connected",t),this._clientData=this._client.connect(A,{metadata:{id:t}}),this._clientData.on("open",()=>{console.log("Connected to host")}),this._clientData.on("data",i=>{console.log("<<",i)})})}}class _QA{constructor(A){B(this,"_peer");this._peer=A}}class TQA extends _QA{constructor(e){var t;super(e);B(this,"_connections",[]);console.log("I AM THE HOST"),(t=this._peer)==null||t.on("connection",this.onConnection.bind(this)),this._peer.on("close",()=>{this.broadcast("BYE")}),setInterval(()=>{this.broadcast("HELLO")},2e3)}get isHost(){return!0}onConnection(e){console.log("host connection",e),e.on("open",()=>{this._connections.push(e),this.broadcastConnection(e)})}broadcastConnection(e){const t=this._connections.map(i=>{var I;return(I=i.metadata)==null?void 0:I.id}).filter(i=>i!==void 0);this.broadcast({type:"connection-list",connections:t})}broadcast(e){if(e!=null){console.log(">>",e);for(const t in this._peer.connections){const i=this._peer.connections[t];if(i)if(Array.isArray(i))for(const I of i)I&&I.send(e);else console.warn(i)}}}}const $Y="https://urls.needle.tools/default-networking-backend/index";let HC="wss://needle-tiny-starter.glitch.me/socket";const oo=!!gA("debugnet"),Ip=!!(oo||gA("debugowner")),A2=gA("debugnetbin");var lZ=(g=>(g.ConnectionInfo="connection-start-info",g))(lZ||{}),ze=(g=>(g.Join="join-room",g.Leave="leave-room",g.JoinedRoom="joined-room",g.LeftRoom="left-room",g.UserJoinedRoom="user-joined-room",g.UserLeftRoom="user-left-room",g.RoomStateSent="room-state-sent",g))(ze||{});class HQA{constructor(){B(this,"room");B(this,"viewId");B(this,"allowEditing");B(this,"inRoom")}}class YQA{constructor(){B(this,"room")}}class OQA{constructor(){B(this,"userId")}}var hZ=(g=>(g.RequestHasOwner="request-has-owner",g.ResponseHasOwner="response-has-owner",g.RequestIsOwner="request-is-owner",g.ResponseIsOwner="response-is-owner",g.RequestOwnership="request-ownership",g.GainedOwnership="gained-ownership",g.RemoveOwnership="remove-ownership",g.LostOwnership="lost-ownership",g.GainedOwnershipBroadcast="gained-ownership-broadcast",g.LostOwnershipBroadcast="lost-ownership-broadcast",g))(hZ||{});class $x{constructor(A,e){B(this,"guid");B(this,"connection");B(this,"_hasOwnership",!1);B(this,"_isOwned");B(this,"_gainSubscription");B(this,"_lostSubscription");B(this,"_hasOwnerResponse");B(this,"_isWaitingForOwnershipResponseCallback",null);this.connection=A,this.guid=e,this._gainSubscription=this.onGainedOwnership.bind(this),this._lostSubscription=this.onLostOwnership.bind(this),A.beginListen("lost-ownership",this._lostSubscription),A.beginListen("gained-ownership-broadcast",this._gainSubscription),this._hasOwnerResponse=this.onHasOwnerResponse.bind(this),A.beginListen("response-has-owner",this._hasOwnerResponse)}get hasOwnership(){return this._hasOwnership}get isOwned(){return this._isOwned}get isConnected(){return this.connection.isConnected}updateIsOwned(){this.connection.send("request-has-owner",{guid:this.guid})}onHasOwnerResponse(A){A.guid===this.guid&&(this._isOwned=A.value)}requestOwnershipIfNotOwned(){return this._isWaitingForOwnershipResponseCallback!==null?this:(this._isWaitingForOwnershipResponseCallback=this.waitForHasOwnershipRequestResponse.bind(this),this.connection.beginListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this.connection.send("request-has-owner",{guid:this.guid}),this)}waitForHasOwnershipRequestResponse(A){A.guid===this.guid&&(this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null),this._isOwned=A.value,A.value||(Ip&&console.log("request ownership",this.guid),this.requestOwnership()))}requestOwnershipAsync(){return new Promise((A,e)=>{this.requestOwnership();let t=0;const i=()=>{if(t++>10)return e("Timeout");setTimeout(()=>{this.hasOwnership?A(this):i()},100)};i()})}requestOwnership(){return Ip&&console.log("Request ownership",this.guid),this.connection.send("request-ownership",{guid:this.guid}),this}freeOwnership(){return this.connection.send("remove-ownership",{guid:this.guid}),this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null),this}destroy(){this.connection.stopListen("gained-ownership",this._gainSubscription),this.connection.stopListen("lost-ownership",this._lostSubscription),this.connection.stopListen("response-has-owner",this._hasOwnerResponse),this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null)}onGainedOwnership(A){A.guid===this.guid&&(this._isOwned=!0,this.connection.connectionId===A.owner?(Ip&&console.log("GAINED OWNERSHIP",this.guid),this._hasOwnership=!0):this._hasOwnership=!1)}onLostOwnership(A){A===this.guid&&(Ip&&console.log("LOST OWNERSHIP",this.guid),this._hasOwnership=!1,this._isOwned=!1)}}class dZ{constructor(A){B(this,"context");B(this,"_peer",null);B(this,"_usersInRoomCopy",[]);B(this,"_defaultMessagesBuffer",[]);B(this,"_defaultMessagesBufferArray",[]);B(this,"netWebSocketUrlProvider");B(this,"_listeners",{});B(this,"_listenersBinary",{});B(this,"connected",!1);B(this,"channelId");B(this,"_connectionId",null);B(this,"_ws");B(this,"_waitingForSocket",{});B(this,"_isInRoom",!1);B(this,"_currentRoomName",null);B(this,"_currentRoomViewId",null);B(this,"_currentRoomAllowEditing",!0);B(this,"_currentInRoom",[]);B(this,"_state",{});B(this,"_currentDelay",-1);B(this,"_connectingToWebsocketPromise",null);this.context=A}get peer(){return this._peer||(this._peer=new EZ),this._peer}tryGetState(A){return A==="invalid"?null:this._state[A]}get connectionId(){return this._connectionId}get isDebugEnabled(){return oo}get isConnected(){return this.connected}get currentRoomName(){return this._currentRoomName}get allowEditing(){return this._currentRoomAllowEditing}get currentRoomViewId(){return this._currentRoomViewId}getViewOnlyUrl(){if(this.currentRoomViewId===null)return null;const A=new URL(window.location.href);return A.searchParams.set("view",this.currentRoomViewId),A.href}get isInRoom(){return this._isInRoom}get currentLatency(){return this._currentDelay}get currentServerUrl(){var A;return((A=this._ws)==null?void 0:A.url)??null}sendPing(){this.send("ping",{time:this.context.time.time})}userIsInRoom(A){return this._currentInRoom.indexOf(A)!==-1}usersInRoom(A=null){A||(A=this._usersInRoomCopy),A.length=0;for(const e of this._currentInRoom)A.push(e);return A}joinRoom(A,e=!1){return A?A.length>1024?(console.error('Room name too long, can not join: "'+A+'". Max length is 1024 characters.'),!1):(this.connect(),oo&&console.log("join: "+A),this.send("join-room",{room:A,viewOnly:e},Gn.OnConnection),!0):(console.error('Missing room name, can not join: "'+A+'"'),!1)}leaveRoom(A=null){return A||(A=this.currentRoomName),A?(this.send("leave-room",{room:A}),!0):(console.error('Missing room name, can not join: "'+A+'"'),!1)}send(A,e=null,t=Gn.Queued){if(e===null&&(e={}),t===Gn.Queued){this._defaultMessagesBuffer.push({key:A,value:e});return}return this.sendWithWebsocket(A,e,t)}sendDeleteRemoteState(A){this.send("delete-state",{guid:A,dontSave:!0}),delete this._state[A]}sendDeleteRemoteStateAll(){this.send("delete-all-state"),this._state={}}sendBinary(A){var e;A2&&console.log("<< send binary",this.context.time.frame,A.length/1024+" KB"),(e=this._ws)==null||e.send(A)}sendBufferedMessagesNow(){var t;if(!this._ws)return;this._defaultMessagesBufferArray.length=0;const A=Object.keys(this._defaultMessagesBuffer).length;for(const i in this._defaultMessagesBuffer){const I=this._defaultMessagesBuffer[i];if(A<=1){this.sendWithWebsocket(I.key,I.value,Gn.Immediate);break}const o=this.toMessage(I.key,I.value);this._defaultMessagesBufferArray.push(o)}if(this._defaultMessagesBuffer.length=0,this._defaultMessagesBufferArray.length>0&&oo&&console.log("SEND BUFFERED",this._defaultMessagesBufferArray.length),this._defaultMessagesBufferArray.length<=0)return;const e=JSON.stringify(this._defaultMessagesBufferArray);(t=this._ws)==null||t.send(e)}beginListen(A,e){return this._listeners[A]||(this._listeners[A]=[]),this._listeners[A].push(e),e}stopListening(A,e){return this.stopListen(A,e)}stopListen(A,e){if(!e||!this._listeners[A])return;const t=this._listeners[A].indexOf(e);t>=0&&this._listeners[A].splice(t,1)}beginListenBinary(A,e){return this._listenersBinary[A]||(this._listenersBinary[A]=[]),this._listenersBinary[A].push(e),e}stopListenBinary(A,e){if(!this._listenersBinary[A])return;const t=this._listenersBinary[A].indexOf(e);t>=0&&this._listenersBinary[A].splice(t,1)}registerProvider(A){this.netWebSocketUrlProvider=A}async connect(){var e;if(this.connected)return Promise.resolve(!0);oo&&console.log("connecting");const A=(e=this.netWebSocketUrlProvider)==null?void 0:e.getWebsocketUrl();return A?HC=A:t4()&&(HC="wss://"+window.location.host+"/socket"),this.connectWebsocket()}disconnect(){var A;(A=this._ws)==null||A.close(),this._ws=void 0}connectWebsocket(){return this._connectingToWebsocketPromise?this._connectingToWebsocketPromise:this._connectingToWebsocketPromise=new Promise(async(A,e)=>{var r,a;let t=!1;const i=C=>{t||(t=!0,A(C))};if(HC===void 0&&(console.log("Fetch default backend url: "+$Y),HC=await(await fetch($Y)).text()),HC===void 0){i(!1);return}console.log(`⊡ Connecting to networking backend on
|
|
5233
5233
|
`+HC);const I=await Promise.resolve().then(()=>mwA),o=((r=I.default)==null?void 0:r.WebsocketBuilder)??I.WebsocketBuilder,s=((a=I.default)==null?void 0:a.ExponentialBackoff)??I.ExponentialBackoff,n=new o(HC).withMaxRetries(3).withBackoff(new s(2e3,2)).onOpen(()=>{this._connectingToWebsocketPromise=null,this._ws=n,this.connected=!0,console.log(`⊞ Connected to networking backend
|
|
5234
5234
|
`+HC),i(!0),this.onSendQueued(Gn.OnConnection)}).onClose(C=>{this._connectingToWebsocketPromise=null,this.connected=!1,this._isInRoom=!1,i(!1)}).onError(C=>{console.error("⊠ Websocket error"),i(!1)}).onRetry(()=>{console.log("Retry connecting to networking websocket")}).build();n.addEventListener(I.WebsocketEvent.message,(C,Q)=>{this.onMessage(C,Q)})})}onMessage(A,e){const t=e.data;try{if(typeof t!="string"){t.size&&this.handleIncomingBinaryMessage(t);return}const i=JSON.parse(t);if(Array.isArray(i))for(const I of i)this.handleIncomingStringMessage(I);else this.handleIncomingStringMessage(i);return}catch(i){oo&&t==="pong"?console.log("<<",t):ae()&&console.error("Failed to parse message",i)}}async handleIncomingBinaryMessage(A){A2&&console.log("<< bin",this.context.time.frame);const e=await A.arrayBuffer();var t=new Uint8Array(e);const i=new Mf(t),I=i.getBufferIdentifier(),o=this._listenersBinary[I],s=yW(i),n=wW(s);if(n&&typeof n=="string"&&(this._state[n]=s),!o)return;const r=s??i;for(const a of o)a(r)}handleIncomingStringMessage(A){var i,I;if(oo&&console.log("<<",A.key??A),A.key)switch(A.key){case"connection-start-info":if(A.data){const n=A.data;n&&(console.assert(n.id!==void 0&&n.id!==null&&n.id.length>0,"server did not send connection id",n.id),console.log("Your id is: "+n.id,this.context.alias??""),this._connectionId=n.id)}else console.warn("Expected connection id in "+A.key);break;case"joined-room":if(oo&&console.log(A),A){this._isInRoom=!0;const n=A;this._currentRoomName=n.room,this._currentRoomViewId=n.viewId,this._currentRoomAllowEditing=n.allowEditing??!0,this._currentInRoom.length=0,this._currentInRoom.push(...n.inRoom),oo&&console.log("joined room with",this._currentInRoom,this.context.alias??"");const r=new URL(window.location.href);r.searchParams.has("room")&&r.searchParams.delete("room"),r.searchParams.set("view",this._currentRoomViewId),console.log("Room view id: "+this._currentRoomViewId+`
|
|
5235
|
-
`+r.href)}this.onSendQueued(Gn.OnRoomJoin);break;case"left-room":A.room===this.currentRoomName&&(this._isInRoom=!1,this._currentRoomName=null,this._currentInRoom.length=0);break;case"user-joined-room":if(A.data){const n=A.data;this._currentInRoom.push(n.userId),oo&&console.log(n.userId+" joined","now in room:",this._currentInRoom)}break;case"user-left-room":if(A.data){const n=A.data,r=this._currentInRoom.indexOf(n.userId);r>=0&&(oo&&console.log(n.userId+" left","now in room:",this._currentInRoom),this._currentInRoom.splice(r,1)),n.userId===this.connectionId&&console.log("you left the room")}break;case"all-room-state-deleted":oo&&console.log("RECEIVED all-room-state-deleted"),this._state={};break;case"ping":case"pong":const s=(i=A.data)==null?void 0:i.time;s&&(this._currentDelay=this.context.time.time-s),oo&&console.log("Current latency: "+this._currentDelay.toFixed(4)+" sec","Clients in room: "+((I=this._currentInRoom)==null?void 0:I.length));break}const e=A.data;e&&(this._state[e.guid]=e);let t=this._listeners[A.key];if(t){t=[...t];for(const o of t)try{o(A.data)}catch(s){console.error('Error invoking callback for "'+A.key+'"',s)}}}toMessage(A,e){return{key:A,data:e}}sendWithWebsocket(A,e,t=Gn.OnRoomJoin){if(!this._ws){const I=this._waitingForSocket[t]||[];I.push(()=>this.sendWithWebsocket(A,e,t)),this._waitingForSocket[t]=I;return}const i=JSON.stringify(this.toMessage(A,e));oo&&console.log(">>",A),this._ws.send(i)}onSendQueued(A){const e=this._waitingForSocket[A];if(e){for(const t of e)t();e.length=0}}}const xp=gA("debugwebxr");class LU{constructor(A,e){B(this,"controllerStates",[]);B(this,"userId");B(this,"context");B(this,"userStateEvtName");B(this,"onReceivedControllerState",A=>{xp&&console.log(`XRSync: Received change for ${this.userId}: ${A.type} ${A.handedness}; tracked=${A.isTracking}`);let e=!1;for(let t=0;t<this.controllerStates.length;t++)if(this.controllerStates[t].index===A.index){this.controllerStates[t]=A,e=!0;break}e||this.controllerStates.push(A)});this.userId=A,this.context=e,this.userStateEvtName="xr-sync-user-state-"+A,this.context.connection.beginListen(this.userStateEvtName,this.onReceivedControllerState)}dispose(){this.context.connection.stopListen(this.userStateEvtName,this.onReceivedControllerState)}update(A){if(this.context.connection.isConnected!=!1){for(let e=this.controllerStates.length-1;e>=0;e--){const t=this.controllerStates[e];let i=!1;for(let I=0;I<A.controllers.length;I++)A.controllers[I].index===t.index&&(i=!0);i||(xp&&console.log(`XRSync: ${t.type} ${t.handedness} removed`,t.index),this.controllerStates.splice(e,1),this.sendControllerRemoved(t))}for(const e of A.controllers)this.updateControllerStates(e)}}onExitXR(A){for(const e of this.controllerStates)this.sendControllerRemoved(e);this.controllerStates.length=0}sendControllerRemoved(A){A.isTracking=!1,A.guid="",this.context.connection.send(this.userStateEvtName,A),this.context.connection.sendDeleteRemoteState(A.guid)}updateControllerStates(A){const e=this.controllerStates.find(t=>t.index===A.index);if(e){let t=!1;t||(t=e.isTracking!=A.isTracking),t&&(e.isTracking=A.isTracking,this.context.connection.send(this.userStateEvtName,e))}else{const t={guid:this.userId+"-"+A.index,isTracking:A.isTracking,handedness:A.side,index:A.index,type:A.hand?"hand":"controller"};this.controllerStates.push(t),this.context.connection.send(this.userStateEvtName,t),xp&&console.log(`XRSync: ${t.type} ${t.handedness} added`,t.index)}}}class uZ{constructor(A){B(this,"context");B(this,"onJoinedRoom",()=>{if(this.context.connection.connectionId){this._states.has(this.context.connection.connectionId)||(xp&&console.log("XRSync: Local user joined room",this.context.connection.connectionId),this._states.set(this.context.connection.connectionId,new LU(this.context.connection.connectionId,this.context)));for(const A of this.context.connection.usersInRoom())this._states.has(A)||this._states.set(A,new LU(A,this.context))}});B(this,"onLeftRoom",()=>{if(this.context.connection.connectionId&&!this._states.has(this.context.connection.connectionId)){const A=this._states.get(this.context.connection.connectionId);A==null||A.dispose(),this._states.delete(this.context.connection.connectionId)}});B(this,"onOtherUserJoinedRoom",A=>{const e=A.userId;this._states.has(e)||(xp&&console.log("XRSync: Remote user joined room",e),this._states.set(e,new LU(e,this.context)))});B(this,"onOtherUserLeftRoom",A=>{const e=A.userId;if(!this._states.has(e)){const t=this._states.get(e);t==null||t.dispose(),this._states.delete(e)}});B(this,"_states",new Map);this.context=A,this.context.connection.beginListen(ze.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ze.LeftRoom,this.onLeftRoom),this.context.connection.beginListen(ze.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.beginListen(ze.UserLeftRoom,this.onOtherUserLeftRoom)}hasState(A){return A?this._states.has(A):!1}isTracking(A,e){if(!A)return;const t=this._states.get(A);if(!t)return;const i=t.controllerStates.find(I=>I.handedness===e);return(i==null?void 0:i.isTracking)||!1}getDeviceType(A,e){if(!A)return;const t=this._states.get(A);if(!t)return;const i=t.controllerStates.find(I=>I.handedness===e);return(i==null?void 0:i.type)||"unknown"}destroy(){this.context.connection.stopListen(ze.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ze.LeftRoom,this.onLeftRoom),this.context.connection.stopListen(ze.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.stopListen(ze.UserLeftRoom,this.onOtherUserLeftRoom)}onUpdate(A){if(this.context.connection.isConnected&&this.context.connection.connectionId){const e=this._states.get(this.context.connection.connectionId);e==null||e.update(A)}}onExitXR(A){if(this.context.connection.isConnected&&this.context.connection.connectionId){const e=this._states.get(this.context.connection.connectionId);e==null||e.onExitXR(A)}}}class e2{constructor(){B(this,"_fadeToColorQuad");B(this,"_fadeToColorMaterial");B(this,"_requestedFadeValue",0);B(this,"_transitionPromise",null);B(this,"_transitionResolve",null);this._fadeToColorMaterial=new ot({color:0,transparent:!0,depthTest:!1,fog:!1,side:kt}),this._fadeToColorQuad=new hA(new hg(10,10),this._fadeToColorMaterial)}dispose(){this._fadeToColorQuad.geometry.dispose(),this._fadeToColorMaterial.dispose()}update(A,e){const t=this._fadeToColorQuad,i=this._fadeToColorMaterial;t.parent!==A&&i.opacity>0?A.add(t):i.opacity===0&&t.removeFromParent(),t.layers.set(2),t.material=this._fadeToColorMaterial,t.position.z=-1,t.renderOrder=1/0;const I=this._requestedFadeValue;i.opacity=ge.lerp(i.opacity,I,e/.03),Math.abs(i.opacity-I)<=.01&&this._transitionResolve&&(this._transitionResolve(),this._transitionResolve=null,this._transitionPromise=null,this._requestedFadeValue=0)}remove(){this._fadeToColorQuad.removeFromParent()}fadeTransition(){if(this._transitionPromise)return this._transitionPromise;this._requestedFadeValue=1;const A=new Promise(e=>{this._transitionResolve=e});return this._transitionPromise=A,A}}var Hc=(g=>(g[g.Quad=0]="Quad",g[g.Cube=1]="Cube",g[g.Sphere=2]="Sphere",g))(Hc||{});class MD{static createPrimitive(A,e){let t;switch(A){case"Quad":case 0:{const I=new hg(1,1,1,1),o=(e==null?void 0:e.material)??new LI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new hA(I,o)}break;case"Cube":case 1:{const I=new ti(1,1,1),o=(e==null?void 0:e.material)??new LI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new hA(I,o)}break;case"Sphere":case 2:{const I=new gn(.5,16,16),o=(e==null?void 0:e.material)??new LI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new hA(I,o)}break}return this.applyDefaultObjectOptions(t,e),t}static createSprite(A){const t=new rk({color:16777215});A!=null&&A.texture&&"map"in t&&(t.map=A.texture);const i=new Zb(t);return this.applyDefaultObjectOptions(i,A),i}static applyDefaultObjectOptions(A,e){e!=null&&e.name&&(A.name=e.name),e!=null&&e.position&&A.position.set(e.position.x,e.position.y,e.position.z),e!=null&&e.rotation&&A.rotation.set(e.rotation.x,e.rotation.y,e.rotation.z),e!=null&&e.scale&&A.scale.set(e.scale.x,e.scale.y,e.scale.z)}}const AL=class{constructor(A,e,t){B(this,"_session");B(this,"_mode");B(this,"_init");B(this,"_renderer");B(this,"_camera");B(this,"_scene");B(this,"onEnd",()=>{var A;(A=this._session)==null||A.removeEventListener("end",this.onEnd),this._renderer.setAnimationLoop(null),this._renderer.dispose(),this._scene.clear()});B(this,"_lastTime",0);B(this,"onFrame",(A,e)=>{const t=A-this._lastTime;this.update(A,t),this._camera.parent!==this._scene&&this._scene.add(this._camera),this._renderer.render(this._scene,this._camera)});B(this,"_objects",[]);this._mode=A,this._init=e,this._session=t,this._session.addEventListener("end",this.onEnd),this._renderer=new nC({alpha:!0}),this._renderer.setAnimationLoop(this.onFrame),this._renderer.xr.setSession(t),this._renderer.xr.enabled=!0,this._camera=new He,this._scene=new lI,this._scene.fog=new nk(4473924,10,250),this._scene.add(this._camera),this.setupScene()}static get active(){return this._active}static async start(A,e){if(this._active)return console.error("Cannot start a new XR session while one is already active"),null;if(this._requestInFlight)return console.error("Cannot start a new XR session while a request is already in flight"),null;if("xr"in navigator&&navigator.xr){if(!e)return console.error("XRSessionInit must be provided"),null;this._requestInFlight=!0;const t=await navigator.xr.requestSession(A,e);return t.addEventListener("end",()=>{this._active=null}),this._requestInFlight?(this._requestInFlight=!1,this._active=new AL(A,e,t),this._active):(t.end(),null)}return null}static async handoff(){return this._active?this._active.handoff():null}static async stop(){this._requestInFlight=!1,this._active&&(await this._active.end(),await vr(100)),this._active=null}get isAR(){return this._mode==="immersive-ar"}end(){return this._session?this._session.end():Promise.resolve()}async handoff(){if(!this._session)throw new Error("Cannot handoff a session that has already ended");const A={session:this._session,mode:this._mode,init:this._init};return await this.onBeforeHandoff(),this.onEnd(),this._session=null,A}async onBeforeHandoff(){await vr(1e3),this._scene.clear()}setupScene(){this._scene.background=new yA(0),this._scene.add(new Fk(5,10,1118481,1118481));const A=new vc(16777215,1);A.position.set(0,20,0),A.castShadow=!1,this._scene.add(A);const e=new vc(16777215,1);e.position.set(0,-1,0),e.castShadow=!1,this._scene.add(e);const t=new xc(16777215,1,100,1);t.position.set(0,2,0),t.castShadow=!1,t.distance=200,this._scene.add(t);const i=50;for(let I=0;I<100;I++){const o=new LI({color:2236962,metalness:1,roughness:.8});this.isAR&&(o.emissive=new yA(Math.random(),Math.random(),Math.random()),o.emissiveIntensity=Math.random());const s=ge.random(0,1)>.5?Hc.Sphere:Hc.Cube,n=MD.createPrimitive(s,{material:o});n.position.x=ge.random(-i,i),n.position.y=ge.random(-2,i),n.position.z=ge.random(-i,i),n.rotation.x=ge.random(0,Math.PI*2),n.rotation.y=ge.random(0,Math.PI*2),n.rotation.z=ge.random(0,Math.PI*2),n.scale.multiplyScalar(.5+Math.random()*10);const r=n.position.distanceTo(this._camera.position)-n.scale.x;r<1&&n.position.multiplyScalar(1+1/r),this._objects.push(n),this._scene.add(n)}}update(A,e){const t=A*4e-4;for(let i=0;i<this._objects.length;i++){const I=this._objects[i];I.position.y+=Math.sin(t+i*.5)*.005,I.rotateY(.002)}}};let QB=AL;B(QB,"_active",null),B(QB,"_requestInFlight",!1);const Jg=gA("debugwebxr"),PQA=gA("stats");function WQA(g){let A=null;const e=g;return e.getAROverlayContainer?A=e.getAROverlayContainer():A=g,A}ZQA();async function ZQA(){var g;if(gA("debugasap")){let A=globalThis["needle:XRSession"];if(A instanceof Promise){delete globalThis["needle:XRSession"],Et.addContextCreatedCallback(async e=>{if(!A)return;Nh(!0);const t=await A;if(t){const i=ye.getDefaultSessionInit("immersive-vr");ye.setSession("immersive-vr",t,i,e.context)}else console.error("NeedleXRSession: ASAP session was rejected");A=void 0});return}}if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent)){console.warn("WebXRViewer does not support addEventListener");return}(g=navigator.xr)==null||g.addEventListener("sessiongranted",async()=>{Nh(!0),console.log("Received Session Granted..."),await vr(100);const A=sessionStorage.getItem("needle_xr_session_mode"),e=sessionStorage.getItem("needle_xr_session_init")??null,t=e?JSON.parse(e):null;let i=null;if(pZ()&&(await QB.start(A||"immersive-vr",t||ye.getDefaultSessionInit("immersive-vr")),await VQA(),i=await QB.handoff()),i)ye.setSession(i.mode,i.session,i.init,be.Current);else if(A&&e){console.log("Session Granted: Restore last session");const I=JSON.parse(e);ye.start(A,I).catch(o=>console.warn(o))}else ye.start("immersive-vr").catch(I=>console.warn("Session Granted failed:",I))},{once:!0})}}function jQA(g,A){sessionStorage.setItem("needle_xr_session_mode",g),sessionStorage.setItem("needle_xr_session_init",JSON.stringify(A))}function zQA(){sessionStorage.removeItem("needle_xr_session_mode"),sessionStorage.removeItem("needle_xr_session_init")}const Av=new Set;Et.registerCallback(Gt.ContextCreationStart,async g=>{Av.add(g.context)});Et.registerCallback(Gt.ContextCreated,async g=>{Av.delete(g.context)});function pZ(){return Av.size>0}function VQA(){return new Promise(g=>{const A=Date.now(),e=setInterval(()=>{(!pZ()||Date.now()-A>6e4)&&(clearInterval(e),g())},100)})}qc()&&ae()&&window.addEventListener("keydown",g=>{(g.key==="x"||g.key==="Escape")&&ye.active&&ye.stop()});const Ga=class{constructor(A,e,t,i){B(this,"context");B(this,"session");B(this,"mode");B(this,"controllers",[]);B(this,"_rigScale",1);B(this,"_lastRigScaleUpdate",-1);B(this,"_rigs",[]);B(this,"_viewerHitTestSource",null);B(this,"_defaultRig");B(this,"_xr_scripts");B(this,"_xr_update_scripts",[]);B(this,"_inactive_scripts",[]);B(this,"_controllerAdded");B(this,"_controllerRemoved");B(this,"_originalCameraWorldPosition");B(this,"_originalCameraWorldRotation");B(this,"_originalCameraWorldScale");B(this,"_originalCameraParent");B(this,"_mainCamera",null);B(this,"onRendererSessionSet",()=>{var A;this.running&&(this.context.renderer.xr.enabled=!0,this.context.renderer.xr.updateCamera(this.context.mainCamera),(A=this.context.mainCameraComponent)==null||A.applyClearFlags())});B(this,"onInputSourceAdded",A=>{if(A.targetRayMode==="screen")return;let e=0;for(let i=0;i<this.session.inputSources.length;i++)if(this.session.inputSources[i]===A){e=i;break}if(this.controllers.find(i=>i.inputSource===A)){console.warn("Controller already exists for input source",e);return}Jg&&console.log("Adding controller",e);const t=new Yx(this,A,e);this._newControllers.push(t)});B(this,"_ended",!1);B(this,"_newControllers",[]);B(this,"onEnd",A=>{var i,I,o;if(this._ended)return;this._ended=!0,Jg&&console.log("XR Session ended"),zQA(),this.onAfterRender(),this.revertCustomForward(),this._didStart=!1,this._previousCameraParent=null,jB(this.onBefore,oi.LateUpdate);const e=this.context.pre_render_callbacks.indexOf(this.onBeforeRender);e>=0&&this.context.pre_render_callbacks.splice(e,1);const t=this.context.post_render_callbacks.indexOf(this.onAfterRender);t>=0&&this.context.post_render_callbacks.splice(t,1),this.context.xr=null,this.context.renderer.xr.enabled=!1,this.context.pre_update_oneshot_callbacks.push(()=>{var s;(s=this.context.mainCameraComponent)==null||s.applyClearFlags()}),pW({session:this});for(const s of Ga._xrEndListeners)s({xr:this});for(let s=0;s<this.controllers.length;s++)this.disconnectInputSource(this.controllers[s].inputSource);for(const s of this._xr_scripts)(i=s==null?void 0:s.onLeaveXR)==null||i.call(s,{xr:this});(I=this.sync)==null||I.onExitXR(this),this.context.mainCamera&&((o=this._originalCameraParent)==null||o.add(this.context.mainCamera),this._originalCameraWorldPosition&&Mg(this.context.mainCamera,this._originalCameraWorldPosition),this._originalCameraWorldRotation&&zs(this.context.mainCamera,this._originalCameraWorldRotation),this._originalCameraWorldScale&&Uh(this.context.mainCamera,this._originalCameraWorldScale)),this.context.requestSizeUpdate(),this._defaultRig.gameObject.removeFromParent(),Nh(!1)});B(this,"_didStart",!1);B(this,"onBefore",A=>{var i,I,o,s,n,r,a,C;const e=A.xrFrame;if(!e)return;this.context.xr=this,this.context.mainCameraComponent&&this.context.mainCameraComponent!==this._mainCamera&&(this._mainCamera=this.context.mainCameraComponent),((i=this.rig)==null?void 0:i.isActive)==!1&&(Jg&&console.warn("Latest rig is not active - trying to activate a different rig",this.rig),this.updateActiveXRRig()),this.rig&&((I=this._mainCamera)!=null&&I.gameObject)&&((s=(o=this._mainCamera)==null?void 0:o.gameObject)==null?void 0:s.parent)!==this.rig.gameObject&&this.rig.gameObject.add((n=this._mainCamera)==null?void 0:n.gameObject),this.internalUpdateState(),this.applyCustomForward();const t={xr:this};if(this._didStart){if(this.context.new_scripts_xr.length>0){const Q=[...this.context.new_scripts_xr];for(let c=0;c<Q.length;c++){const E=this.context.new_scripts_xr[c];if(!E||E.destroyed||((r=E.supportsXR)==null?void 0:r.call(E,this.mode))==!1){this.context.new_scripts_xr.splice(c,1);continue}if(!E.activeAndEnabled){this.context.new_scripts_xr.splice(c,1),this.markInactive(E);continue}if(this.addScript(E)){this.invokeCallback_EnterXR(E);for(const h of this.controllers)this.invokeCallback_ControllerAdded(E,h)}}}}else{if(this._didStart=!0,this.mode==="immersive-vr"){const c=qr(this.context.scene.children);if(c){const E=c.getSize(dt());if(E.length()>0){const h=this._defaultRig.gameObject;h.position.set(c.min.x+E.x*.5,c.min.y,c.max.z+E.z*.5+1.5);const l=c.getCenter(dt());l.y=h.position.y,h.lookAt(l)}}}uW({session:this});for(const c of Ga._xrStartListeners)c(t);const Q=[...this._xr_scripts];Jg&&console.log("NeedleXRSession start, handle scripts:",Q);for(const c of Q){if(c.destroyed){this._script_to_remove.push(c);continue}if(!c.activeAndEnabled){this.markInactive(c);continue}this.invokeCallback_EnterXR(c);for(const E of this.controllers)this.invokeCallback_ControllerAdded(c,E)}}this.syncCameraCullingMask();for(const Q of this.controllers)Q.onUpdate(e);if(this._newControllers.length>0){const Q=[...this._newControllers];this._newControllers.length=0;for(const c of Q)if(c.connected){this.controllers.push(c);for(const E of this._xr_scripts){if(E.destroyed){this._script_to_remove.push(E);continue}E.activeAndEnabled!==!1&&this.invokeCallback_ControllerAdded(E,c)}}this.controllers.sort((c,E)=>c.index-E.index)}for(const Q of this._xr_update_scripts){if(Q.destroyed===!0){this._script_to_remove.push(Q);continue}if(Q.activeAndEnabled===!1){this.markInactive(Q);continue}Q.onUpdateXR&&Q.onUpdateXR(t)}if(this.handleInactiveScripts(),this._script_to_remove.length>0){const Q=[...new Set(this._script_to_remove)];this._script_to_remove.length=0;for(const c of Q)!c.destroyed&&this.running&&((a=c.onLeaveXR)==null||a.call(c,t)),this.removeScript(c)}(C=this.sync)==null||C.onUpdate(this),this.onRenderDebug()});B(this,"onBeforeRender",()=>{this.context.mainCamera&&this.updateFade(this.context.mainCamera)});B(this,"onAfterRender",()=>{if(this.onUpdateFade_PostRender(),qc()){const A=this.context.renderer;if(A.xr.isPresenting&&this.context.mainCamera){const e=A.xr.enabled,t=A.getRenderTarget();A.xr.enabled=!1,A.setRenderTarget(null),A.render(this.context.scene,this.context.mainCamera),A.xr.enabled=e,A.setRenderTarget(t)}}});B(this,"_script_to_remove",[]);B(this,"_camera");B(this,"_cameraRenderParent",new DA().rotateY(Math.PI));B(this,"_previousCameraParent");B(this,"_customforward",!0);B(this,"originalCameraNearPlane");B(this,"_viewerPose");B(this,"_transformOrientation",new GA);B(this,"_transformPosition",new y);B(this,"_transition");var I,o;jQA(A,i.init),this.session=e,this.mode=A,this.context=t,(Jg||gA("console"))&&Nh(!0),this._xr_scripts=[...i.scripts],this._xr_update_scripts=this._xr_scripts.filter(s=>typeof s.onUpdateXR=="function"),this._controllerAdded=i.controller_added,this._controllerRemoved=i.controller_removed,ZB(this.onBefore,oi.LateUpdate),this.context.pre_render_callbacks.push(this.onBeforeRender),this.context.post_render_callbacks.push(this.onAfterRender),((I=i.init.optionalFeatures)!=null&&I.includes("hit-test")||(o=i.init.requiredFeatures)!=null&&o.includes("hit-test"))&&e.requestReferenceSpace("viewer").then(s=>{var n,r;return(r=(n=e.requestHitTestSource)==null?void 0:n.call(e,{space:s}))==null?void 0:r.then(a=>this._viewerHitTestSource=a)}).catch(s=>console.warn(s)),this.context.mainCamera&&(this._originalCameraWorldPosition=ve(this.context.mainCamera,new y),this._originalCameraWorldRotation=Jt(this.context.mainCamera,new GA),this._originalCameraWorldScale=ii(this.context.mainCamera,new y),this._originalCameraParent=this.context.mainCamera.parent),this._defaultRig=new AQA,this.context.scene.add(this._defaultRig.gameObject),this.addRig(this._defaultRig);for(let s=0;s<e.inputSources.length;s++){const n=e.inputSources[s];if(!n.handedness){console.warn("Input source in xr session has no handedness - ignoring",s);continue}this.onInputSourceAdded(n)}this.session.addEventListener("end",this.onEnd),this.session.addEventListener("inputsourceschange",s=>{for(const n of s.removed)this.disconnectInputSource(n);for(const n of s.added)this.onInputSourceAdded(n)}),this.context.xr=this,this.context.renderer.xr.setSession(this.session).then(this.onRendererSessionSet)}static getXRSync(A){return this._sync||(this._sync=new uZ(A)),this._sync}static get currentSessionRequest(){return this._currentSessionRequestMode}static get active(){return this._activeSession}static get activeMode(){var A;return((A=this._activeSession)==null?void 0:A.mode)??null}static get xrSystem(){return"xr"in navigator?navigator.xr:void 0}static isXRSupported(){return Promise.all([this.isVRSupported(),this.isARSupported()]).then(A=>A.some(e=>e)).catch(()=>!1)}static isVRSupported(){return this.isSessionSupported("immersive-vr")}static isARSupported(){return this.isSessionSupported("immersive-ar")}static isSessionSupported(A){var e;return((e=this.xrSystem)==null?void 0:e.isSessionSupported(A).catch(t=>(Jg&&console.error(t),!1)))??Promise.resolve(!1)}static onSessionRequestStart(A){this._sessionRequestStartListeners.push(A)}static offSessionRequestStart(A){const e=this._sessionRequestStartListeners.indexOf(A);e>=0&&this._sessionRequestStartListeners.splice(e,1)}static onSessionRequestEnd(A){this._sessionRequestEndListeners.push(A)}static offSessionRequestEnd(A){const e=this._sessionRequestEndListeners.indexOf(A);e>=0&&this._sessionRequestEndListeners.splice(e,1)}static onXRSessionStart(A){this._xrStartListeners.push(A)}static offXRSessionStart(A){const e=this._xrStartListeners.indexOf(A);e>=0&&this._xrStartListeners.splice(e,1)}static onXRSessionEnd(A){this._xrEndListeners.push(A)}static offXRSessionEnd(A){const e=this._xrEndListeners.indexOf(A);e>=0&&this._xrEndListeners.splice(e,1)}static onControllerAdded(A){this._controllerAddedListeners.push(A)}static offControllerAdded(A){const e=this._controllerAddedListeners.indexOf(A);e>=0&&this._controllerAddedListeners.splice(e,1)}static onControllerRemoved(A){this._controllerRemovedListeners.push(A)}static offControllerRemoved(A){const e=this._controllerRemovedListeners.indexOf(A);e>=0&&this._controllerRemovedListeners.splice(e,1)}static offerSession(A,e,t){return"xr"in navigator&&navigator.xr&&"offerSession"in navigator.xr?(typeof navigator.xr.offerSession=="function"&&(console.log("WebXR offerSession is available - requesting mode: "+A),e=="default"&&(e=this.getDefaultSessionInit(A)),navigator.xr.offerSession(A,{...e}).then(i=>Ga.setSession(A,i,e,t)).catch(i=>{console.log("XRSession offer rejected (perhaps because another call to offerSession was made or a call to requestSession was made)")})),!0):!1}static getDefaultSessionInit(A){switch(A){case"immersive-ar":return{optionalFeatures:["anchors","local-floor","hand-tracking","layers","dom-overlay","hit-test"]};case"immersive-vr":return{optionalFeatures:["local-floor","bounded-floor","hand-tracking","high-fixed-foveation-level","layers"]};default:return console.warn("No default session init for mode",A),{}}}static async start(A,e,t){var o,s,n,r;if(ae()&&gA("debugxrpreroom"))return console.warn("Debug: Starting temporary XR session"),await QB.start(A,e||Ga.getDefaultSessionInit(A)),null;if(this._currentSessionRequest)return console.warn("A XRSession is already being requested"),(Jg||ae())&&Ot("A XRSession is already being requested"),this._currentSessionRequest.then(()=>this._activeSession);if(this._activeSession)return console.error("A XRSession is already running"),this._activeSession;if(t||(t=be.Current),t||(t=Et.All[0]),!t)throw new Error("No Needle Engine Context found");switch(e||(e={}),A){case"immersive-ar":{if(await((o=this.xrSystem)==null?void 0:o.isSessionSupported("immersive-ar"))!==!0)return console.error(A+" is not supported by this browser."),null;const C=this.getDefaultSessionInit(A),Q=WQA(t.domElement);Q&&!bk()&&(C.domOverlay={root:Q},C.optionalFeatures.push("dom-overlay")),e={...C,...e}}break;case"immersive-vr":{if(await((s=this.xrSystem)==null?void 0:s.isSessionSupported("immersive-vr"))!==!0)return console.error(A+" is not supported by this browser."),null;e={...this.getDefaultSessionInit(A),...e}}break;default:console.warn("No default session init for mode",A);break}e.optionalFeatures??(e.optionalFeatures=[]),e.requiredFeatures??(e.requiredFeatures=[]),await QB.stop();const i=A=="immersive-ar"?t.scripts_immersive_ar:t.scripts_immersive_vr;Jg?console.log(`%cRequesting ${A} session`,"font-weight:bold;",e,i):console.log(`%cRequesting ${A} session`,"font-weight:bold;");for(const a of i)a.onBeforeXR&&a.onBeforeXR(A,e);for(const a of this._sessionRequestStartListeners)a({mode:A,init:e});Jg&&fi("Requesting "+A+" session ("+Date.now()+")"),this._currentSessionRequest=(n=navigator.xr)==null?void 0:n.requestSession(A,e),this._currentSessionRequestMode=A;const I=await((r=this._currentSessionRequest)==null?void 0:r.catch(a=>{console.error(a,"Code: "+a.code),a.code===9&&Ot("Make sure your device has the required permissions (e.g. camera access)"),console.log("If the specified XR configuration is not supported (e.g. entering AR doesnt work) - make sure you access the website on a secure connection (HTTPS) and your device has the required permissions (e.g. camera access)"),location.protocol==="http:"&&Ot("XR requires a secure connection (HTTPS)")}));this._currentSessionRequest=void 0,this._currentSessionRequestMode=null;for(const a of this._sessionRequestEndListeners)a({mode:A,init:e,newSession:I||null});return I?this.setSession(A,I,e,t):(console.warn("XR Session request was rejected"),null)}static setSession(A,e,t,i){if(this._activeSession)return console.error("A XRSession is already running"),this._activeSession;const I=A=="immersive-ar"?i.scripts_immersive_ar:i.scripts_immersive_vr;return this._activeSession=new Ga(A,e,i,{scripts:I,controller_added:this._controllerAddedListeners,controller_removed:this._controllerRemovedListeners,init:t}),e.addEventListener("end",this.onEnd),Jg?console.log(`%cStarted ${A} session`,"font-weight:bold;",I):console.log(`%cStarted ${A} session`,"font-weight:bold;"),this._activeSession}static stop(){var A;(A=this._activeSession)==null||A.end()}get sync(){return Ga._sync}get running(){return!this._ended&&this.session!=null}get interactionMode(){return this.session.interactionMode}get visibilityState(){return this.session.visibilityState}get environmentBlendMode(){return this.session.environmentBlendMode}get frame(){return this.context.xrFrame}get leftController(){return this.controllers.find(A=>A.isLeft)}get rightController(){return this.controllers.find(A=>A.isRight)}getController(A){return typeof A=="number"?this.controllers[A]||null:this.controllers.find(e=>e.side===A)||null}get isPassThrough(){return!!(this.environmentBlendMode!=="opaque"&&this.interactionMode==="world-space"||this.mode==="immersive-ar"&&this.environmentBlendMode!=="opaque"&&this.controllers.some(A=>A.inputSource.targetRayMode==="tracked-pointer")||ae()&&qc()&&this.mode==="immersive-ar")}get isAR(){return this.mode==="immersive-ar"}get isVR(){return this.mode==="immersive-vr"}get isScreenBasedAR(){return this.isAR&&!this.isPassThrough}get posePosition(){return this._transformPosition}get poseOrientation(){return this._transformOrientation}get referenceSpace(){return this.context.renderer.xr.getReferenceSpace()}get viewerPose(){return this._viewerPose}get isTrackingImages(){if(this.frame&&"getImageTrackingResults"in this.frame&&typeof this.frame.getImageTrackingResults=="function")try{const A=this.frame.getImageTrackingResults();for(const e of A)if(e.trackingState==="tracked")return!0}catch{return!1}return!1}get rig(){const A=this._rigs[0]??null;return A!=null&&A.gameObject&&Yc(A.gameObject)||(A==null?void 0:A.isActive)===!1?(this.updateActiveXRRig(),this._rigs[0]??null):A}get rigScale(){return this._rigs[0]?(this._lastRigScaleUpdate!==this.context.time.frame&&(this._lastRigScaleUpdate=this.context.time.frame,this._rigScale=this._rigs[0].gameObject.worldScale.x),this._rigScale):1}addRig(A){this._rigs.indexOf(A)>=0||(A.priority===void 0&&(A.priority=0),this._rigs.push(A),this.updateActiveXRRig())}removeRig(A){const e=this._rigs.indexOf(A);e!==-1&&(this._rigs.splice(e,1),this.updateActiveXRRig())}setRigActive(A){const e=this._rigs.indexOf(A);this._rigs.splice(e,1),this._rigs.unshift(A),this.updateActiveXRRig()}updateActiveXRRig(){const A=this._rigs[0]??null;this._defaultRig.gameObject.parent!==this.context.scene&&this.context.scene.add(this._defaultRig.gameObject),this._defaultRig.gameObject.visible=!0,this._rigs.includes(this._defaultRig)||this._rigs.push(this._defaultRig);let e=this._rigs[0];e&&e.priority===void 0&&(e.priority=0);for(let t=1;t<this._rigs.length;t++){const i=this._rigs[t];if(i.isActive){if(Yc(i.gameObject)){this._rigs.splice(t,1),t--;continue}(!e||e.isActive===!1||i.priority!==void 0&&i.priority>e.priority)&&(e=i)}}if(A!==e){const t=this._rigs.indexOf(e);t>=0&&this._rigs.splice(t,1),this._rigs.unshift(e)}Jg&&(A===e?console.log("Updated Active XR Rig:",e,"prev:",A):console.log("Updated Active XRRig:",e," (the same as before)"))}getHitTest(A){if(A)return this.getControllerHitTest(A);if(!this._viewerHitTestSource)return null;const e=this._viewerHitTestSource,t=this.frame.getHitTestResults(e);if(t.length>0){const i=t[0];return this.convertHitTestResult(i)}return null}getControllerHitTest(A){const e=A.hitTestSource;if(!e)return null;const t=this.frame.getHitTestResultsForTransientInput(e);for(const i of t)if(i.inputSource===A.inputSource)for(const I of i.results)return this.convertHitTestResult(I);return null}convertHitTestResult(A){const e=this.context.renderer.xr.getReferenceSpace(),t=e&&A.getPose(e);if(t){const i=dt(t.transform.position),I=gc(t.transform.orientation),o=this.context.mainCamera;if((o==null?void 0:o.parent)!==this._cameraRenderParent&&i.applyMatrix4(Bm),o!=null&&o.parent){i.applyMatrix4(o.parent.matrixWorld),I.multiply(bs);const s=Jt(o.parent);s.premultiply(bs),I.premultiply(s)}return{hit:A,position:i,quaternion:I}}return null}convertSpace(A){const e=dt(A.position);e.applyMatrix4(Bm);const t=gc(A.orientation);return t.premultiply(bs),{position:e,quaternion:t}}disconnectInputSource(A){const e=(t,i,I)=>{if(t.inputSource===A){Jg&&console.log("Disconnecting controller",t.index),this.controllers.splice(I,1),this.invokeControllerEvent(t,this._controllerRemoved,"removed");const o={xr:this,controller:t,change:"removed"};for(const s of this._xr_scripts)s.onXRControllerRemoved&&s.onXRControllerRemoved(o);t.onDisconnected()}};for(let t=this.controllers.length-1;t>=0;t--){const i=this.controllers[t];e(i,this.controllers,t)}for(let t=this._newControllers.length-1;t>=0;t--){const i=this._newControllers[t];e(i,this._newControllers,t)}}end(){this._ended||this.session.end().catch(A=>console.warn(A))}onRenderDebug(){if(Jg)for(const A of this.controllers)A.onRenderDebug();if((Jg||PQA)&&this.rig){const A=this.rig.gameObject.worldPosition,e=this.rig.gameObject.worldForward;A.add(e.multiplyScalar(1.5));const t=this.rig.gameObject.worldUp;A.add(t.multiplyScalar(2.5));let i="";if(i+=this.context.time.smoothedFps.toFixed(1),Jg)for(const I of this.controllers)i+=`
|
|
5235
|
+
`+r.href)}this.onSendQueued(Gn.OnRoomJoin);break;case"left-room":A.room===this.currentRoomName&&(this._isInRoom=!1,this._currentRoomName=null,this._currentInRoom.length=0);break;case"user-joined-room":if(A.data){const n=A.data;this._currentInRoom.push(n.userId),oo&&console.log(n.userId+" joined","now in room:",this._currentInRoom)}break;case"user-left-room":if(A.data){const n=A.data,r=this._currentInRoom.indexOf(n.userId);r>=0&&(oo&&console.log(n.userId+" left","now in room:",this._currentInRoom),this._currentInRoom.splice(r,1)),n.userId===this.connectionId&&console.log("you left the room")}break;case"all-room-state-deleted":oo&&console.log("RECEIVED all-room-state-deleted"),this._state={};break;case"ping":case"pong":const s=(i=A.data)==null?void 0:i.time;s&&(this._currentDelay=this.context.time.time-s),oo&&console.log("Current latency: "+this._currentDelay.toFixed(4)+" sec","Clients in room: "+((I=this._currentInRoom)==null?void 0:I.length));break}const e=A.data;e&&(this._state[e.guid]=e);let t=this._listeners[A.key];if(t){t=[...t];for(const o of t)try{o(A.data)}catch(s){console.error('Error invoking callback for "'+A.key+'"',s)}}}toMessage(A,e){return{key:A,data:e}}sendWithWebsocket(A,e,t=Gn.OnRoomJoin){if(!this._ws){const I=this._waitingForSocket[t]||[];I.push(()=>this.sendWithWebsocket(A,e,t)),this._waitingForSocket[t]=I;return}const i=JSON.stringify(this.toMessage(A,e));oo&&console.log(">>",A),this._ws.send(i)}onSendQueued(A){const e=this._waitingForSocket[A];if(e){for(const t of e)t();e.length=0}}}const xp=gA("debugwebxr");class LU{constructor(A,e){B(this,"controllerStates",[]);B(this,"userId");B(this,"context");B(this,"userStateEvtName");B(this,"onReceivedControllerState",A=>{xp&&console.log(`XRSync: Received change for ${this.userId}: ${A.type} ${A.handedness}; tracked=${A.isTracking}`);let e=!1;for(let t=0;t<this.controllerStates.length;t++)if(this.controllerStates[t].index===A.index){this.controllerStates[t]=A,e=!0;break}e||this.controllerStates.push(A)});this.userId=A,this.context=e,this.userStateEvtName="xr-sync-user-state-"+A,this.context.connection.beginListen(this.userStateEvtName,this.onReceivedControllerState)}dispose(){this.context.connection.stopListen(this.userStateEvtName,this.onReceivedControllerState)}update(A){if(this.context.connection.isConnected!=!1){for(let e=this.controllerStates.length-1;e>=0;e--){const t=this.controllerStates[e];let i=!1;for(let I=0;I<A.controllers.length;I++)A.controllers[I].index===t.index&&(i=!0);i||(xp&&console.log(`XRSync: ${t.type} ${t.handedness} removed`,t.index),this.controllerStates.splice(e,1),this.sendControllerRemoved(t))}for(const e of A.controllers)this.updateControllerStates(e)}}onExitXR(A){for(const e of this.controllerStates)this.sendControllerRemoved(e);this.controllerStates.length=0}sendControllerRemoved(A){A.isTracking=!1,A.guid="",this.context.connection.send(this.userStateEvtName,A),this.context.connection.sendDeleteRemoteState(A.guid)}updateControllerStates(A){const e=this.controllerStates.find(t=>t.index===A.index);if(e){let t=!1;t||(t=e.isTracking!=A.isTracking),t&&(e.isTracking=A.isTracking,this.context.connection.send(this.userStateEvtName,e))}else{const t={guid:this.userId+"-"+A.index,isTracking:A.isTracking,handedness:A.side,index:A.index,type:A.hand?"hand":"controller"};this.controllerStates.push(t),this.context.connection.send(this.userStateEvtName,t),xp&&console.log(`XRSync: ${t.type} ${t.handedness} added`,t.index)}}}class uZ{constructor(A){B(this,"context");B(this,"onJoinedRoom",()=>{if(this.context.connection.connectionId){this._states.has(this.context.connection.connectionId)||(xp&&console.log("XRSync: Local user joined room",this.context.connection.connectionId),this._states.set(this.context.connection.connectionId,new LU(this.context.connection.connectionId,this.context)));for(const A of this.context.connection.usersInRoom())this._states.has(A)||this._states.set(A,new LU(A,this.context))}});B(this,"onLeftRoom",()=>{if(this.context.connection.connectionId&&!this._states.has(this.context.connection.connectionId)){const A=this._states.get(this.context.connection.connectionId);A==null||A.dispose(),this._states.delete(this.context.connection.connectionId)}});B(this,"onOtherUserJoinedRoom",A=>{const e=A.userId;this._states.has(e)||(xp&&console.log("XRSync: Remote user joined room",e),this._states.set(e,new LU(e,this.context)))});B(this,"onOtherUserLeftRoom",A=>{const e=A.userId;if(!this._states.has(e)){const t=this._states.get(e);t==null||t.dispose(),this._states.delete(e)}});B(this,"_states",new Map);this.context=A,this.context.connection.beginListen(ze.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ze.LeftRoom,this.onLeftRoom),this.context.connection.beginListen(ze.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.beginListen(ze.UserLeftRoom,this.onOtherUserLeftRoom)}hasState(A){return A?this._states.has(A):!1}isTracking(A,e){if(!A)return;const t=this._states.get(A);if(!t)return;const i=t.controllerStates.find(I=>I.handedness===e);return(i==null?void 0:i.isTracking)||!1}getDeviceType(A,e){if(!A)return;const t=this._states.get(A);if(!t)return;const i=t.controllerStates.find(I=>I.handedness===e);return(i==null?void 0:i.type)||"unknown"}destroy(){this.context.connection.stopListen(ze.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ze.LeftRoom,this.onLeftRoom),this.context.connection.stopListen(ze.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.stopListen(ze.UserLeftRoom,this.onOtherUserLeftRoom)}onUpdate(A){if(this.context.connection.isConnected&&this.context.connection.connectionId){const e=this._states.get(this.context.connection.connectionId);e==null||e.update(A)}}onExitXR(A){if(this.context.connection.isConnected&&this.context.connection.connectionId){const e=this._states.get(this.context.connection.connectionId);e==null||e.onExitXR(A)}}}class e2{constructor(){B(this,"_fadeToColorQuad");B(this,"_fadeToColorMaterial");B(this,"_requestedFadeValue",0);B(this,"_transitionPromise",null);B(this,"_transitionResolve",null);this._fadeToColorMaterial=new ot({color:0,transparent:!0,depthTest:!1,fog:!1,side:kt}),this._fadeToColorQuad=new hA(new hg(10,10),this._fadeToColorMaterial)}dispose(){this._fadeToColorQuad.geometry.dispose(),this._fadeToColorMaterial.dispose()}update(A,e){const t=this._fadeToColorQuad,i=this._fadeToColorMaterial;t.parent!==A&&i.opacity>0?A.add(t):i.opacity===0&&t.removeFromParent(),t.layers.set(2),t.material=this._fadeToColorMaterial,t.position.z=-1,t.renderOrder=1/0;const I=this._requestedFadeValue;i.opacity=ge.lerp(i.opacity,I,e/.03),Math.abs(i.opacity-I)<=.01&&this._transitionResolve&&(this._transitionResolve(),this._transitionResolve=null,this._transitionPromise=null,this._requestedFadeValue=0)}remove(){this._fadeToColorQuad.removeFromParent()}fadeTransition(){if(this._transitionPromise)return this._transitionPromise;this._requestedFadeValue=1;const A=new Promise(e=>{this._transitionResolve=e});return this._transitionPromise=A,A}}var Hc=(g=>(g[g.Quad=0]="Quad",g[g.Cube=1]="Cube",g[g.Sphere=2]="Sphere",g))(Hc||{});class MD{static createPrimitive(A,e){let t;switch(A){case"Quad":case 0:{const I=new hg(1,1,1,1),o=(e==null?void 0:e.material)??new LI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new hA(I,o)}break;case"Cube":case 1:{const I=new ti(1,1,1),o=(e==null?void 0:e.material)??new LI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new hA(I,o)}break;case"Sphere":case 2:{const I=new gn(.5,16,16),o=(e==null?void 0:e.material)??new LI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new hA(I,o)}break}return this.applyDefaultObjectOptions(t,e),t}static createSprite(A){const t=new rk({color:16777215});A!=null&&A.texture&&"map"in t&&(t.map=A.texture);const i=new Zb(t);return this.applyDefaultObjectOptions(i,A),i}static applyDefaultObjectOptions(A,e){e!=null&&e.name&&(A.name=e.name),e!=null&&e.position&&A.position.set(e.position.x,e.position.y,e.position.z),e!=null&&e.rotation&&A.rotation.set(e.rotation.x,e.rotation.y,e.rotation.z),e!=null&&e.scale&&A.scale.set(e.scale.x,e.scale.y,e.scale.z)}}const AL=class{constructor(A,e,t){B(this,"_session");B(this,"_mode");B(this,"_init");B(this,"_renderer");B(this,"_camera");B(this,"_scene");B(this,"onEnd",()=>{var A;(A=this._session)==null||A.removeEventListener("end",this.onEnd),this._renderer.setAnimationLoop(null),this._renderer.dispose(),this._scene.clear()});B(this,"_lastTime",0);B(this,"onFrame",(A,e)=>{const t=A-this._lastTime;this.update(A,t),this._camera.parent!==this._scene&&this._scene.add(this._camera),this._renderer.render(this._scene,this._camera)});B(this,"_objects",[]);this._mode=A,this._init=e,this._session=t,this._session.addEventListener("end",this.onEnd),this._renderer=new nC({alpha:!0}),this._renderer.setAnimationLoop(this.onFrame),this._renderer.xr.setSession(t),this._renderer.xr.enabled=!0,this._camera=new He,this._scene=new lI,this._scene.fog=new nk(4473924,10,250),this._scene.add(this._camera),this.setupScene()}static get active(){return this._active}static async start(A,e){if(this._active)return console.error("Cannot start a new XR session while one is already active"),null;if(this._requestInFlight)return console.error("Cannot start a new XR session while a request is already in flight"),null;if("xr"in navigator&&navigator.xr){if(!e)return console.error("XRSessionInit must be provided"),null;this._requestInFlight=!0;const t=await navigator.xr.requestSession(A,e);return t.addEventListener("end",()=>{this._active=null}),this._requestInFlight?(this._requestInFlight=!1,this._active=new AL(A,e,t),this._active):(t.end(),null)}return null}static async handoff(){return this._active?this._active.handoff():null}static async stop(){this._requestInFlight=!1,this._active&&(await this._active.end(),await vr(100)),this._active=null}get isAR(){return this._mode==="immersive-ar"}end(){return this._session?this._session.end():Promise.resolve()}async handoff(){if(!this._session)throw new Error("Cannot handoff a session that has already ended");const A={session:this._session,mode:this._mode,init:this._init};return await this.onBeforeHandoff(),this.onEnd(),this._session=null,A}async onBeforeHandoff(){await vr(1e3),this._scene.clear()}setupScene(){this._scene.background=new yA(0),this._scene.add(new Fk(5,10,1118481,1118481));const A=new vc(16777215,1);A.position.set(0,20,0),A.castShadow=!1,this._scene.add(A);const e=new vc(16777215,1);e.position.set(0,-1,0),e.castShadow=!1,this._scene.add(e);const t=new xc(16777215,1,100,1);t.position.set(0,2,0),t.castShadow=!1,t.distance=200,this._scene.add(t);const i=50;for(let I=0;I<100;I++){const o=new LI({color:2236962,metalness:1,roughness:.8});this.isAR&&(o.emissive=new yA(Math.random(),Math.random(),Math.random()),o.emissiveIntensity=Math.random());const s=ge.random(0,1)>.5?Hc.Sphere:Hc.Cube,n=MD.createPrimitive(s,{material:o});n.position.x=ge.random(-i,i),n.position.y=ge.random(-2,i),n.position.z=ge.random(-i,i),n.rotation.x=ge.random(0,Math.PI*2),n.rotation.y=ge.random(0,Math.PI*2),n.rotation.z=ge.random(0,Math.PI*2),n.scale.multiplyScalar(.5+Math.random()*10);const r=n.position.distanceTo(this._camera.position)-n.scale.x;r<1&&n.position.multiplyScalar(1+1/r),this._objects.push(n),this._scene.add(n)}}update(A,e){const t=A*4e-4;for(let i=0;i<this._objects.length;i++){const I=this._objects[i];I.position.y+=Math.sin(t+i*.5)*.005,I.rotateY(.002)}}};let QB=AL;B(QB,"_active",null),B(QB,"_requestInFlight",!1);const Jg=gA("debugwebxr"),PQA=gA("stats");function WQA(g){let A=null;const e=g;return e.getAROverlayContainer?A=e.getAROverlayContainer():A=g,A}ZQA();async function ZQA(){var g;if(gA("debugasap")){let A=globalThis["needle:XRSession"];if(A instanceof Promise){delete globalThis["needle:XRSession"],Et.addContextCreatedCallback(async e=>{if(!A)return;Nh(!0);const t=await A;if(t){const i=ye.getDefaultSessionInit("immersive-vr");ye.setSession("immersive-vr",t,i,e.context)}else console.error("NeedleXRSession: ASAP session was rejected");A=void 0});return}}if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent)){console.warn("WebXRViewer does not support addEventListener");return}(g=navigator.xr)==null||g.addEventListener("sessiongranted",async()=>{Nh(!0),console.log("Received Session Granted..."),await vr(100);const A=sessionStorage.getItem("needle_xr_session_mode"),e=sessionStorage.getItem("needle_xr_session_init")??null,t=e?JSON.parse(e):null;let i=null;if(pZ()&&(await QB.start(A||"immersive-vr",t||ye.getDefaultSessionInit("immersive-vr")),await VQA(),i=await QB.handoff()),i)ye.setSession(i.mode,i.session,i.init,be.Current);else if(A&&e){console.log("Session Granted: Restore last session");const I=JSON.parse(e);ye.start(A,I).catch(o=>console.warn(o))}else ye.start("immersive-vr").catch(I=>console.warn("Session Granted failed:",I))},{once:!0})}}function jQA(g,A){sessionStorage.setItem("needle_xr_session_mode",g),sessionStorage.setItem("needle_xr_session_init",JSON.stringify(A))}function zQA(){sessionStorage.removeItem("needle_xr_session_mode"),sessionStorage.removeItem("needle_xr_session_init")}const Av=new Set;Et.registerCallback(Gt.ContextCreationStart,async g=>{Av.add(g.context)});Et.registerCallback(Gt.ContextCreated,async g=>{Av.delete(g.context)});function pZ(){return Av.size>0}function VQA(){return new Promise(g=>{const A=Date.now(),e=setInterval(()=>{(!pZ()||Date.now()-A>6e4)&&(clearInterval(e),g())},100)})}qc()&&ae()&&window.addEventListener("keydown",g=>{(g.key==="x"||g.key==="Escape")&&ye.active&&ye.stop()});const Ga=class{constructor(A,e,t,i){B(this,"context");B(this,"session");B(this,"mode");B(this,"controllers",[]);B(this,"_rigScale",1);B(this,"_lastRigScaleUpdate",-1);B(this,"_rigs",[]);B(this,"_viewerHitTestSource",null);B(this,"_defaultRig");B(this,"_xr_scripts");B(this,"_xr_update_scripts",[]);B(this,"_inactive_scripts",[]);B(this,"_controllerAdded");B(this,"_controllerRemoved");B(this,"_originalCameraWorldPosition");B(this,"_originalCameraWorldRotation");B(this,"_originalCameraWorldScale");B(this,"_originalCameraParent");B(this,"_mainCamera",null);B(this,"onRendererSessionSet",()=>{var A;this.running&&(this.context.renderer.xr.enabled=!0,this.context.renderer.xr.updateCamera(this.context.mainCamera),(A=this.context.mainCameraComponent)==null||A.applyClearFlags())});B(this,"onInputSourceAdded",A=>{if(A.targetRayMode==="screen")return;let e=0;for(let i=0;i<this.session.inputSources.length;i++)if(this.session.inputSources[i]===A){e=i;break}if(this.controllers.find(i=>i.inputSource===A)){console.warn("Controller already exists for input source",e);return}Jg&&console.log("Adding controller",e);const t=new Yx(this,A,e);this._newControllers.push(t)});B(this,"_ended",!1);B(this,"_newControllers",[]);B(this,"onEnd",A=>{var i,I,o;if(this._ended)return;this._ended=!0,Jg&&console.log("XR Session ended"),zQA(),this.onAfterRender(),this.revertCustomForward(),this._didStart=!1,this._previousCameraParent=null,jB(this.onBefore,oi.LateUpdate);const e=this.context.pre_render_callbacks.indexOf(this.onBeforeRender);e>=0&&this.context.pre_render_callbacks.splice(e,1);const t=this.context.post_render_callbacks.indexOf(this.onAfterRender);t>=0&&this.context.post_render_callbacks.splice(t,1),this.context.xr=null,this.context.renderer.xr.enabled=!1,this.context.pre_update_oneshot_callbacks.push(()=>{var s;(s=this.context.mainCameraComponent)==null||s.applyClearFlags()}),pW({session:this});for(const s of Ga._xrEndListeners)s({xr:this});for(let s=0;s<this.controllers.length;s++)this.disconnectInputSource(this.controllers[s].inputSource);for(const s of this._xr_scripts)(i=s==null?void 0:s.onLeaveXR)==null||i.call(s,{xr:this});(I=this.sync)==null||I.onExitXR(this),this.context.mainCamera&&((o=this._originalCameraParent)==null||o.add(this.context.mainCamera),this._originalCameraWorldPosition&&Mg(this.context.mainCamera,this._originalCameraWorldPosition),this._originalCameraWorldRotation&&zs(this.context.mainCamera,this._originalCameraWorldRotation),this._originalCameraWorldScale&&Uh(this.context.mainCamera,this._originalCameraWorldScale)),this.context.requestSizeUpdate(),this._defaultRig.gameObject.removeFromParent(),Nh(!1)});B(this,"_didStart",!1);B(this,"onBefore",A=>{var i,I,o,s,n,r,a,C;const e=A.xrFrame;if(!e)return;this.context.xr=this,this.context.mainCameraComponent&&this.context.mainCameraComponent!==this._mainCamera&&(this._mainCamera=this.context.mainCameraComponent),((i=this.rig)==null?void 0:i.isActive)==!1&&(Jg&&console.warn("Latest rig is not active - trying to activate a different rig",this.rig),this.updateActiveXRRig()),this.rig&&((I=this._mainCamera)!=null&&I.gameObject)&&((s=(o=this._mainCamera)==null?void 0:o.gameObject)==null?void 0:s.parent)!==this.rig.gameObject&&this.rig.gameObject.add((n=this._mainCamera)==null?void 0:n.gameObject),this.internalUpdateState(),this.applyCustomForward();const t={xr:this};if(this._didStart){if(this.context.new_scripts_xr.length>0){const Q=[...this.context.new_scripts_xr];for(let c=0;c<Q.length;c++){const E=this.context.new_scripts_xr[c];if(!E||E.destroyed||((r=E.supportsXR)==null?void 0:r.call(E,this.mode))==!1){this.context.new_scripts_xr.splice(c,1);continue}if(!E.activeAndEnabled){this.context.new_scripts_xr.splice(c,1),this.markInactive(E);continue}if(this.addScript(E)){this.invokeCallback_EnterXR(E);for(const h of this.controllers)this.invokeCallback_ControllerAdded(E,h)}}}}else{if(this._didStart=!0,this.mode==="immersive-vr"){const c=qr(this.context.scene.children);if(c){const E=c.getSize(dt());if(E.length()>0){const h=this._defaultRig.gameObject;h.position.set(c.min.x+E.x*.5,c.min.y,c.max.z+E.z*.5+1.5);const l=c.getCenter(dt());l.y=h.position.y,h.lookAt(l)}}}uW({session:this});for(const c of Ga._xrStartListeners)c(t);const Q=[...this._xr_scripts];Jg&&console.log("NeedleXRSession start, handle scripts:",Q);for(const c of Q){if(c.destroyed){this._script_to_remove.push(c);continue}if(!c.activeAndEnabled){this.markInactive(c);continue}this.invokeCallback_EnterXR(c);for(const E of this.controllers)this.invokeCallback_ControllerAdded(c,E)}}this.syncCameraCullingMask();for(const Q of this.controllers)Q.onUpdate(e);if(this._newControllers.length>0){const Q=[...this._newControllers];this._newControllers.length=0;for(const c of Q)if(c.connected){this.controllers.push(c);for(const E of this._xr_scripts){if(E.destroyed){this._script_to_remove.push(E);continue}E.activeAndEnabled!==!1&&this.invokeCallback_ControllerAdded(E,c)}}this.controllers.sort((c,E)=>c.index-E.index)}for(const Q of this._xr_update_scripts){if(Q.destroyed===!0){this._script_to_remove.push(Q);continue}if(Q.activeAndEnabled===!1){this.markInactive(Q);continue}Q.onUpdateXR&&Q.onUpdateXR(t)}if(this.handleInactiveScripts(),this._script_to_remove.length>0){const Q=[...new Set(this._script_to_remove)];this._script_to_remove.length=0;for(const c of Q)!c.destroyed&&this.running&&((a=c.onLeaveXR)==null||a.call(c,t)),this.removeScript(c)}(C=this.sync)==null||C.onUpdate(this),this.onRenderDebug()});B(this,"onBeforeRender",()=>{this.context.mainCamera&&this.updateFade(this.context.mainCamera)});B(this,"onAfterRender",()=>{if(this.onUpdateFade_PostRender(),qc()){const A=this.context.renderer;if(A.xr.isPresenting&&this.context.mainCamera){const e=A.xr.enabled,t=A.getRenderTarget();A.xr.enabled=!1,A.setRenderTarget(null),A.render(this.context.scene,this.context.mainCamera),A.xr.enabled=e,A.setRenderTarget(t)}}});B(this,"_script_to_remove",[]);B(this,"_camera");B(this,"_cameraRenderParent",new DA().rotateY(Math.PI));B(this,"_previousCameraParent");B(this,"_customforward",!0);B(this,"originalCameraNearPlane");B(this,"_viewerPose");B(this,"_transformOrientation",new GA);B(this,"_transformPosition",new y);B(this,"_transition");var I,o;jQA(A,i.init),this.session=e,this.mode=A,this.context=t,(Jg||gA("console"))&&Nh(!0),this._xr_scripts=[...i.scripts],this._xr_update_scripts=this._xr_scripts.filter(s=>typeof s.onUpdateXR=="function"),this._controllerAdded=i.controller_added,this._controllerRemoved=i.controller_removed,ZB(this.onBefore,oi.LateUpdate),this.context.pre_render_callbacks.push(this.onBeforeRender),this.context.post_render_callbacks.push(this.onAfterRender),((I=i.init.optionalFeatures)!=null&&I.includes("hit-test")||(o=i.init.requiredFeatures)!=null&&o.includes("hit-test"))&&e.requestReferenceSpace("viewer").then(s=>{var n,r;return(r=(n=e.requestHitTestSource)==null?void 0:n.call(e,{space:s}))==null?void 0:r.then(a=>this._viewerHitTestSource=a)}).catch(s=>console.warn(s)),this.context.mainCamera&&(this._originalCameraWorldPosition=ve(this.context.mainCamera,new y),this._originalCameraWorldRotation=Jt(this.context.mainCamera,new GA),this._originalCameraWorldScale=ii(this.context.mainCamera,new y),this._originalCameraParent=this.context.mainCamera.parent),this._defaultRig=new AQA,this.context.scene.add(this._defaultRig.gameObject),this.addRig(this._defaultRig);for(let s=0;s<e.inputSources.length;s++){const n=e.inputSources[s];if(!n.handedness){console.warn("Input source in xr session has no handedness - ignoring",s);continue}this.onInputSourceAdded(n)}this.session.addEventListener("end",this.onEnd),this.session.addEventListener("inputsourceschange",s=>{for(const n of s.removed)this.disconnectInputSource(n);for(const n of s.added)this.onInputSourceAdded(n)}),this.context.xr=this,this.context.renderer.xr.setSession(this.session).then(this.onRendererSessionSet)}static getXRSync(A){return this._sync||(this._sync=new uZ(A)),this._sync}static get currentSessionRequest(){return this._currentSessionRequestMode}static get active(){return this._activeSession}static get activeMode(){var A;return((A=this._activeSession)==null?void 0:A.mode)??null}static get xrSystem(){return"xr"in navigator?navigator.xr:void 0}static isXRSupported(){return Promise.all([this.isVRSupported(),this.isARSupported()]).then(A=>A.some(e=>e)).catch(()=>!1)}static isVRSupported(){return this.isSessionSupported("immersive-vr")}static isARSupported(){return this.isSessionSupported("immersive-ar")}static isSessionSupported(A){var e;return((e=this.xrSystem)==null?void 0:e.isSessionSupported(A).catch(t=>(Jg&&console.error(t),!1)))??Promise.resolve(!1)}static onSessionRequestStart(A){this._sessionRequestStartListeners.push(A)}static offSessionRequestStart(A){const e=this._sessionRequestStartListeners.indexOf(A);e>=0&&this._sessionRequestStartListeners.splice(e,1)}static onSessionRequestEnd(A){this._sessionRequestEndListeners.push(A)}static offSessionRequestEnd(A){const e=this._sessionRequestEndListeners.indexOf(A);e>=0&&this._sessionRequestEndListeners.splice(e,1)}static onXRSessionStart(A){this._xrStartListeners.push(A)}static offXRSessionStart(A){const e=this._xrStartListeners.indexOf(A);e>=0&&this._xrStartListeners.splice(e,1)}static onXRSessionEnd(A){this._xrEndListeners.push(A)}static offXRSessionEnd(A){const e=this._xrEndListeners.indexOf(A);e>=0&&this._xrEndListeners.splice(e,1)}static onControllerAdded(A){this._controllerAddedListeners.push(A)}static offControllerAdded(A){const e=this._controllerAddedListeners.indexOf(A);e>=0&&this._controllerAddedListeners.splice(e,1)}static onControllerRemoved(A){this._controllerRemovedListeners.push(A)}static offControllerRemoved(A){const e=this._controllerRemovedListeners.indexOf(A);e>=0&&this._controllerRemovedListeners.splice(e,1)}static offerSession(A,e,t){return"xr"in navigator&&navigator.xr&&"offerSession"in navigator.xr?(typeof navigator.xr.offerSession=="function"&&(console.log("WebXR offerSession is available - requesting mode: "+A),e=="default"&&(e=this.getDefaultSessionInit(A)),navigator.xr.offerSession(A,{...e}).then(i=>Ga.setSession(A,i,e,t)).catch(i=>{console.log("XRSession offer rejected (perhaps because another call to offerSession was made or a call to requestSession was made)")})),!0):!1}static getDefaultSessionInit(A){switch(A){case"immersive-ar":return{optionalFeatures:["anchors","local-floor","hand-tracking","layers","dom-overlay","hit-test","unbounded"]};case"immersive-vr":return{optionalFeatures:["local-floor","bounded-floor","hand-tracking","high-fixed-foveation-level","layers"]};default:return console.warn("No default session init for mode",A),{}}}static async start(A,e,t){var o,s,n,r;if(ae()&&gA("debugxrpreroom"))return console.warn("Debug: Starting temporary XR session"),await QB.start(A,e||Ga.getDefaultSessionInit(A)),null;if(this._currentSessionRequest)return console.warn("A XRSession is already being requested"),(Jg||ae())&&Ot("A XRSession is already being requested"),this._currentSessionRequest.then(()=>this._activeSession);if(this._activeSession)return console.error("A XRSession is already running"),this._activeSession;if(t||(t=be.Current),t||(t=Et.All[0]),!t)throw new Error("No Needle Engine Context found");switch(e||(e={}),A){case"immersive-ar":{if(await((o=this.xrSystem)==null?void 0:o.isSessionSupported("immersive-ar"))!==!0)return console.error(A+" is not supported by this browser."),null;const C=this.getDefaultSessionInit(A),Q=WQA(t.domElement);Q&&!bk()&&(C.domOverlay={root:Q},C.optionalFeatures.push("dom-overlay")),e={...C,...e}}break;case"immersive-vr":{if(await((s=this.xrSystem)==null?void 0:s.isSessionSupported("immersive-vr"))!==!0)return console.error(A+" is not supported by this browser."),null;e={...this.getDefaultSessionInit(A),...e}}break;default:console.warn("No default session init for mode",A);break}e.optionalFeatures??(e.optionalFeatures=[]),e.requiredFeatures??(e.requiredFeatures=[]),await QB.stop();const i=A=="immersive-ar"?t.scripts_immersive_ar:t.scripts_immersive_vr;Jg?console.log(`%cRequesting ${A} session`,"font-weight:bold;",e,i):console.log(`%cRequesting ${A} session`,"font-weight:bold;");for(const a of i)a.onBeforeXR&&a.onBeforeXR(A,e);for(const a of this._sessionRequestStartListeners)a({mode:A,init:e});Jg&&fi("Requesting "+A+" session ("+Date.now()+")"),this._currentSessionRequest=(n=navigator.xr)==null?void 0:n.requestSession(A,e),this._currentSessionRequestMode=A;const I=await((r=this._currentSessionRequest)==null?void 0:r.catch(a=>{console.error(a,"Code: "+a.code),a.code===9&&Ot("Make sure your device has the required permissions (e.g. camera access)"),console.log("If the specified XR configuration is not supported (e.g. entering AR doesnt work) - make sure you access the website on a secure connection (HTTPS) and your device has the required permissions (e.g. camera access)"),location.protocol==="http:"&&Ot("XR requires a secure connection (HTTPS)")}));this._currentSessionRequest=void 0,this._currentSessionRequestMode=null;for(const a of this._sessionRequestEndListeners)a({mode:A,init:e,newSession:I||null});return I?this.setSession(A,I,e,t):(console.warn("XR Session request was rejected"),null)}static setSession(A,e,t,i){if(this._activeSession)return console.error("A XRSession is already running"),this._activeSession;const I=A=="immersive-ar"?i.scripts_immersive_ar:i.scripts_immersive_vr;return this._activeSession=new Ga(A,e,i,{scripts:I,controller_added:this._controllerAddedListeners,controller_removed:this._controllerRemovedListeners,init:t}),e.addEventListener("end",this.onEnd),Jg?console.log(`%cStarted ${A} session`,"font-weight:bold;",I):console.log(`%cStarted ${A} session`,"font-weight:bold;"),this._activeSession}static stop(){var A;(A=this._activeSession)==null||A.end()}get sync(){return Ga._sync}get running(){return!this._ended&&this.session!=null}get interactionMode(){return this.session.interactionMode}get visibilityState(){return this.session.visibilityState}get environmentBlendMode(){return this.session.environmentBlendMode}get frame(){return this.context.xrFrame}get leftController(){return this.controllers.find(A=>A.isLeft)}get rightController(){return this.controllers.find(A=>A.isRight)}getController(A){return typeof A=="number"?this.controllers[A]||null:this.controllers.find(e=>e.side===A)||null}get isPassThrough(){return!!(this.environmentBlendMode!=="opaque"&&this.interactionMode==="world-space"||this.mode==="immersive-ar"&&this.environmentBlendMode!=="opaque"&&this.controllers.some(A=>A.inputSource.targetRayMode==="tracked-pointer")||ae()&&qc()&&this.mode==="immersive-ar")}get isAR(){return this.mode==="immersive-ar"}get isVR(){return this.mode==="immersive-vr"}get isScreenBasedAR(){return this.isAR&&!this.isPassThrough}get posePosition(){return this._transformPosition}get poseOrientation(){return this._transformOrientation}get referenceSpace(){return this.context.renderer.xr.getReferenceSpace()}get viewerPose(){return this._viewerPose}get isTrackingImages(){if(this.frame&&"getImageTrackingResults"in this.frame&&typeof this.frame.getImageTrackingResults=="function")try{const A=this.frame.getImageTrackingResults();for(const e of A)if(e.trackingState==="tracked")return!0}catch{return!1}return!1}get rig(){const A=this._rigs[0]??null;return A!=null&&A.gameObject&&Yc(A.gameObject)||(A==null?void 0:A.isActive)===!1?(this.updateActiveXRRig(),this._rigs[0]??null):A}get rigScale(){return this._rigs[0]?(this._lastRigScaleUpdate!==this.context.time.frame&&(this._lastRigScaleUpdate=this.context.time.frame,this._rigScale=this._rigs[0].gameObject.worldScale.x),this._rigScale):1}addRig(A){this._rigs.indexOf(A)>=0||(A.priority===void 0&&(A.priority=0),this._rigs.push(A),this.updateActiveXRRig())}removeRig(A){const e=this._rigs.indexOf(A);e!==-1&&(this._rigs.splice(e,1),this.updateActiveXRRig())}setRigActive(A){const e=this._rigs.indexOf(A);this._rigs.splice(e,1),this._rigs.unshift(A),this.updateActiveXRRig()}updateActiveXRRig(){const A=this._rigs[0]??null;this._defaultRig.gameObject.parent!==this.context.scene&&this.context.scene.add(this._defaultRig.gameObject),this._defaultRig.gameObject.visible=!0,this._rigs.includes(this._defaultRig)||this._rigs.push(this._defaultRig);let e=this._rigs[0];e&&e.priority===void 0&&(e.priority=0);for(let t=1;t<this._rigs.length;t++){const i=this._rigs[t];if(i.isActive){if(Yc(i.gameObject)){this._rigs.splice(t,1),t--;continue}(!e||e.isActive===!1||i.priority!==void 0&&i.priority>e.priority)&&(e=i)}}if(A!==e){const t=this._rigs.indexOf(e);t>=0&&this._rigs.splice(t,1),this._rigs.unshift(e)}Jg&&(A===e?console.log("Updated Active XR Rig:",e,"prev:",A):console.log("Updated Active XRRig:",e," (the same as before)"))}getHitTest(A){if(A)return this.getControllerHitTest(A);if(!this._viewerHitTestSource)return null;const e=this._viewerHitTestSource,t=this.frame.getHitTestResults(e);if(t.length>0){const i=t[0];return this.convertHitTestResult(i)}return null}getControllerHitTest(A){const e=A.hitTestSource;if(!e)return null;const t=this.frame.getHitTestResultsForTransientInput(e);for(const i of t)if(i.inputSource===A.inputSource)for(const I of i.results)return this.convertHitTestResult(I);return null}convertHitTestResult(A){const e=this.context.renderer.xr.getReferenceSpace(),t=e&&A.getPose(e);if(t){const i=dt(t.transform.position),I=gc(t.transform.orientation),o=this.context.mainCamera;if((o==null?void 0:o.parent)!==this._cameraRenderParent&&i.applyMatrix4(Bm),o!=null&&o.parent){i.applyMatrix4(o.parent.matrixWorld),I.multiply(bs);const s=Jt(o.parent);s.premultiply(bs),I.premultiply(s)}return{hit:A,position:i,quaternion:I}}return null}convertSpace(A){const e=dt(A.position);e.applyMatrix4(Bm);const t=gc(A.orientation);return t.premultiply(bs),{position:e,quaternion:t}}disconnectInputSource(A){const e=(t,i,I)=>{if(t.inputSource===A){Jg&&console.log("Disconnecting controller",t.index),this.controllers.splice(I,1),this.invokeControllerEvent(t,this._controllerRemoved,"removed");const o={xr:this,controller:t,change:"removed"};for(const s of this._xr_scripts)s.onXRControllerRemoved&&s.onXRControllerRemoved(o);t.onDisconnected()}};for(let t=this.controllers.length-1;t>=0;t--){const i=this.controllers[t];e(i,this.controllers,t)}for(let t=this._newControllers.length-1;t>=0;t--){const i=this._newControllers[t];e(i,this._newControllers,t)}}end(){this._ended||this.session.end().catch(A=>console.warn(A))}onRenderDebug(){if(Jg)for(const A of this.controllers)A.onRenderDebug();if((Jg||PQA)&&this.rig){const A=this.rig.gameObject.worldPosition,e=this.rig.gameObject.worldForward;A.add(e.multiplyScalar(1.5));const t=this.rig.gameObject.worldUp;A.add(t.multiplyScalar(2.5));let i="";if(i+=this.context.time.smoothedFps.toFixed(1),Jg)for(const I of this.controllers)i+=`
|
|
5236
5236
|
${I.hand?"hand":"ctrl"} ${I.inputSource.handedness}[${I.index}] con:${I.connected} tr:${I.isTracking}`;fe.DrawLabel(A,i)}}addScript(A){return this._xr_scripts.includes(A)?!1:(Jg&&console.log("Register new XRScript",A),this._xr_scripts.push(A),typeof A.onUpdateXR=="function"&&this._xr_update_scripts.push(A),!0)}markInactive(A){if(!(this._inactive_scripts.indexOf(A)>=0)){this.removeScript(A,!1),this._inactive_scripts.push(A);for(const e of this.controllers)this.invokeCallback_ControllerRemoved(A,e);this.invokeCallback_LeaveXR(A)}}handleInactiveScripts(){if(this._inactive_scripts.length>0)for(let A=this._inactive_scripts.length-1;A>=0;A--){const e=this._inactive_scripts[A];if(e.activeAndEnabled){this._inactive_scripts.splice(A,1),this.addScript(e),this.invokeCallback_EnterXR(e);for(const t of this.controllers)this.invokeCallback_ControllerAdded(e,t)}}}removeScript(A,e=!0){Jg&&console.log("Remove XRScript",A);const t=this._xr_scripts.indexOf(A);t>=0&&this._xr_scripts.splice(t,1);const i=this._xr_update_scripts.indexOf(A);if(i>=0&&this._xr_update_scripts.splice(i,1),e){const I=this._inactive_scripts.indexOf(A);I>=0&&this._inactive_scripts.splice(I,1)}}invokeCallback_EnterXR(A){A.onEnterXR&&A.onEnterXR({xr:this})}invokeCallback_ControllerAdded(A,e){A.onXRControllerAdded&&A.onXRControllerAdded({xr:this,controller:e,change:"added"})}invokeCallback_ControllerRemoved(A,e){A.onXRControllerRemoved&&A.onXRControllerRemoved({xr:this,controller:e,change:"removed"})}invokeCallback_LeaveXR(A){A.onLeaveXR&&!A.destroyed&&A.onLeaveXR({xr:this})}syncCameraCullingMask(){var t;const A=this.context.xrCamera,e=(t=this.context.mainCameraComponent)==null?void 0:t.cullingMask;if(A&&e!==void 0){for(const i of A.cameras)i.layers.mask=e;A.layers.mask=e}else if(A){for(const i of A.cameras)i.layers.enableAll();A.layers.enableAll()}}invokeControllerEvent(A,e,t){for(let i=e.length-1;i>=0;i--){const I=e[i];if(I)try{I({xr:this,controller:A,change:t})}catch(o){console.error(o)}}}applyCustomForward(){var A;if(this.context.mainCamera&&this._customforward){this._camera=this.context.mainCamera,this._camera.parent!==this._cameraRenderParent&&(this._previousCameraParent=this._camera.parent,(A=this._previousCameraParent)==null||A.add(this._cameraRenderParent)),this._cameraRenderParent.name="XR Camera Render Parent",this._cameraRenderParent.add(this._camera);let e=.02;if(this.rig){const t=ii(this.rig.gameObject);e*=t.x}this._camera instanceof He&&this._camera.near>e&&(this.originalCameraNearPlane=this._camera.near,this._camera.near=e)}}revertCustomForward(){this._camera&&this._previousCameraParent&&this._previousCameraParent.add(this._camera),this._previousCameraParent=null,this._camera instanceof He&&this.originalCameraNearPlane!=null&&(this._camera.near=this.originalCameraNearPlane)}internalUpdateState(){const A=this.context.renderer.xr.getReferenceSpace();if(!A){this._viewerPose=void 0;return}if(this._viewerPose=this.frame.getViewerPose(A),this._viewerPose){const e=this._viewerPose.transform;this._transformPosition.set(e.position.x,e.position.y,e.position.z),this._transformOrientation.set(e.orientation.x,e.orientation.y,e.orientation.z,e.orientation.w)}}get transition(){return this._transition||(this._transition=new e2),this._transition}fadeTransition(){return this._transition||(this._transition=new e2),this._transition.fadeTransition()}updateFade(A){this._transition&&A instanceof He&&this._transition.update(A,this.context.time.deltaTime)}onUpdateFade_PostRender(){var A;(A=this._transition)==null||A.remove()}};let ye=Ga;B(ye,"_sync",null),B(ye,"_currentSessionRequestMode",null),B(ye,"_currentSessionRequest"),B(ye,"_activeSession"),B(ye,"_sessionRequestStartListeners",[]),B(ye,"_sessionRequestEndListeners",[]),B(ye,"_xrStartListeners",[]),B(ye,"_xrEndListeners",[]),B(ye,"_controllerAddedListeners",[]),B(ye,"_controllerRemovedListeners",[]),B(ye,"onEnd",()=>{Jg&&console.log("XR Session ended"),Ga._activeSession=null});const _U=gA("debugwebxr");class fZ{static tryFindAvatarObjects(A,e,t){if(t.head&&t.leftHand&&t.rightHand)return;const i=A.name.toLocaleLowerCase();!t.head&&i.includes("head")&&(_U&&console.log("FOUND AVATAR HEAD",A.name),t.head=new et("",e,A)),i.includes("hand")&&(!t.leftHand&&i.includes("left")&&(_U&&console.log("FOUND AVATAR LEFT HAND",A.name),t.leftHand=new et("",e,A)),!t.rightHand&&i.includes("right")&&(_U&&console.log("FOUND AVATAR RIGHT HAND",A.name),t.rightHand=new et("",e,A)));for(let I=0;I<A.children.length;I++){if(t.head&&t.leftHand&&t.rightHand)return;const o=A.children[I];this.tryFindAvatarObjects(o,e,t)}}}var Em=(g=>(g.Visible="application-visible",g.Hidden="application-hidden",g.MuteChanged="application-mutechanged",g))(Em||{});let lm=!1;const Ah=[];function Cd(){if(lm)return;ae()&&console.debug("User interaction registered: audio can now be played"),lm=!0;const g=[...Ah];Ah.length=0,g.forEach(A=>A())}document.addEventListener("pointerdown",Cd);document.addEventListener("click",Cd);document.addEventListener("dragstart",Cd);document.addEventListener("touchstart",Cd);document.addEventListener("keydown",Cd);ye.onXRSessionStart(()=>{Cd()});const eL=class extends EventTarget{constructor(e){super();B(this,"_mute",!1);B(this,"context");B(this,"_isVisible",!0);this.context=e,window.addEventListener("visibilitychange",this.onVisiblityChanged.bind(this),!1)}static get userInteractionRegistered(){return lm}static registerWaitForInteraction(e){if(e!==null){if(lm){e();return}Ah.indexOf(e)===-1&&Ah.push(e)}}static unregisterWaitForInteraction(e){const t=Ah.indexOf(e);t!==-1&&Ah.splice(t,1)}get muted(){return this._mute}set muted(e){e!==this._mute&&(this._mute=e,this.dispatchEvent(new Event("application-mutechanged")))}get hasFocus(){return document.hasFocus()}get isVisible(){return this._isVisible}onVisiblityChanged(e){switch(e.target.visibilityState){case"hidden":this._isVisible=!1,this.dispatchEvent(new Event("application-hidden"));break;case"visible":this._isVisible=!0,this.dispatchEvent(new Event("application-visible"));break}}};let Fr=eL;B(Fr,"registerWaitForAllowAudio",eL.registerWaitForInteraction);function*DZ(g,A=null){const e=A?A.time:be.Current.time,t=e.time;for(;e.time-t<g;)yield}function*XQA(g){for(let A=0;A<g;A++)yield}function*yZ(g){let A=!0;for(g.then(()=>A=!1),g.catch(()=>A=!1);A;)yield}class Rf extends aJ{constructor(A){super(A),this.type=kg}parse(A){const U=Math.pow(2.7182818,2.2);function S(F,L){let $=0;for(let T=0;T<65536;++T)(T==0||F[T>>3]&1<<(T&7))&&(L[$++]=T);const N=$-1;for(;$<65536;)L[$++]=0;return N}function R(F){for(let L=0;L<16384;L++)F[L]={},F[L].len=0,F[L].lit=0,F[L].p=null}const v={l:0,c:0,lc:0};function q(F,L,$,N,T){for(;$<F;)L=L<<8|zA(N,T),$+=8;$-=F,v.l=L>>$&(1<<F)-1,v.c=L,v.lc=$}const b=new Array(59);function O(F){for(let $=0;$<=58;++$)b[$]=0;for(let $=0;$<65537;++$)b[F[$]]+=1;let L=0;for(let $=58;$>0;--$){const N=L+b[$]>>1;b[$]=L,L=N}for(let $=0;$<65537;++$){const N=F[$];N>0&&(F[$]=N|b[N]++<<6)}}function K(F,L,$,N,T,Y){const z=L;let V=0,dA=0;for(;N<=T;N++){if(z.value-L.value>$)return!1;q(6,V,dA,F,z);const cA=v.l;if(V=v.c,dA=v.lc,Y[N]=cA,cA==63){if(z.value-L.value>$)throw new Error("Something wrong with hufUnpackEncTable");q(8,V,dA,F,z);let SA=v.l+6;if(V=v.c,dA=v.lc,N+SA>T+1)throw new Error("Something wrong with hufUnpackEncTable");for(;SA--;)Y[N++]=0;N--}else if(cA>=59){let SA=cA-59+2;if(N+SA>T+1)throw new Error("Something wrong with hufUnpackEncTable");for(;SA--;)Y[N++]=0;N--}}O(Y)}function x(F){return F&63}function _(F){return F>>6}function Z(F,L,$,N){for(;L<=$;L++){const T=_(F[L]),Y=x(F[L]);if(T>>Y)throw new Error("Invalid table entry");if(Y>14){const z=N[T>>Y-14];if(z.len)throw new Error("Invalid table entry");if(z.lit++,z.p){const V=z.p;z.p=new Array(z.lit);for(let dA=0;dA<z.lit-1;++dA)z.p[dA]=V[dA]}else z.p=new Array(1);z.p[z.lit-1]=L}else if(Y){let z=0;for(let V=1<<14-Y;V>0;V--){const dA=N[(T<<14-Y)+z];if(dA.len||dA.p)throw new Error("Invalid table entry");dA.len=Y,dA.lit=L,z++}}}return!0}const j={c:0,lc:0};function oA(F,L,$,N){F=F<<8|zA($,N),L+=8,j.c=F,j.lc=L}const BA={c:0,lc:0};function UA(F,L,$,N,T,Y,z,V,dA){if(F==L){N<8&&(oA($,N,T,Y),$=j.c,N=j.lc),N-=8;let cA=$>>N;if(cA=new Uint8Array([cA])[0],V.value+cA>dA)return!1;const SA=z[V.value-1];for(;cA-- >0;)z[V.value++]=SA}else if(V.value<dA)z[V.value++]=F;else return!1;BA.c=$,BA.lc=N}function IA(F){return F&65535}function pA(F){const L=IA(F);return L>32767?L-65536:L}const MA={a:0,b:0};function vA(F,L){const $=pA(F),T=pA(L),Y=$+(T&1)+(T>>1),z=Y,V=Y-T;MA.a=z,MA.b=V}function ZA(F,L){const $=IA(F),N=IA(L),T=$-(N>>1)&65535,Y=N+T-32768&65535;MA.a=Y,MA.b=T}function OA(F,L,$,N,T,Y,z){const V=z<16384,dA=$>T?T:$;let cA=1,SA,bA;for(;cA<=dA;)cA<<=1;for(cA>>=1,SA=cA,cA>>=1;cA>=1;){bA=0;const xA=bA+Y*(T-SA),WA=Y*cA,$A=Y*SA,te=N*cA,Be=N*SA;let Me,St,We,Ne;for(;bA<=xA;bA+=$A){let Lt=bA;const me=bA+N*($-SA);for(;Lt<=me;Lt+=Be){const Zt=Lt+te,zI=Lt+WA,ci=zI+te;V?(vA(F[Lt+L],F[zI+L]),Me=MA.a,We=MA.b,vA(F[Zt+L],F[ci+L]),St=MA.a,Ne=MA.b,vA(Me,St),F[Lt+L]=MA.a,F[Zt+L]=MA.b,vA(We,Ne),F[zI+L]=MA.a,F[ci+L]=MA.b):(ZA(F[Lt+L],F[zI+L]),Me=MA.a,We=MA.b,ZA(F[Zt+L],F[ci+L]),St=MA.a,Ne=MA.b,ZA(Me,St),F[Lt+L]=MA.a,F[Zt+L]=MA.b,ZA(We,Ne),F[zI+L]=MA.a,F[ci+L]=MA.b)}if($&cA){const Zt=Lt+WA;V?vA(F[Lt+L],F[Zt+L]):ZA(F[Lt+L],F[Zt+L]),Me=MA.a,F[Zt+L]=MA.b,F[Lt+L]=Me}}if(T&cA){let Lt=bA;const me=bA+N*($-SA);for(;Lt<=me;Lt+=Be){const Zt=Lt+te;V?vA(F[Lt+L],F[Zt+L]):ZA(F[Lt+L],F[Zt+L]),Me=MA.a,F[Zt+L]=MA.b,F[Lt+L]=Me}}SA=cA,cA>>=1}return bA}function he(F,L,$,N,T,Y,z,V,dA){let cA=0,SA=0;const bA=z,xA=Math.trunc(N.value+(T+7)/8);for(;N.value<xA;)for(oA(cA,SA,$,N),cA=j.c,SA=j.lc;SA>=14;){const $A=cA>>SA-14&16383,te=L[$A];if(te.len)SA-=te.len,UA(te.lit,Y,cA,SA,$,N,V,dA,bA),cA=BA.c,SA=BA.lc;else{if(!te.p)throw new Error("hufDecode issues");let Be;for(Be=0;Be<te.lit;Be++){const Me=x(F[te.p[Be]]);for(;SA<Me&&N.value<xA;)oA(cA,SA,$,N),cA=j.c,SA=j.lc;if(SA>=Me&&_(F[te.p[Be]])==(cA>>SA-Me&(1<<Me)-1)){SA-=Me,UA(te.p[Be],Y,cA,SA,$,N,V,dA,bA),cA=BA.c,SA=BA.lc;break}}if(Be==te.lit)throw new Error("hufDecode issues")}}const WA=8-T&7;for(cA>>=WA,SA-=WA;SA>0;){const $A=L[cA<<14-SA&16383];if($A.len)SA-=$A.len,UA($A.lit,Y,cA,SA,$,N,V,dA,bA),cA=BA.c,SA=BA.lc;else throw new Error("hufDecode issues")}return!0}function oe(F,L,$,N,T,Y){const z={value:0},V=$.value,dA=ce(L,$),cA=ce(L,$);$.value+=4;const SA=ce(L,$);if($.value+=4,dA<0||dA>=65537||cA<0||cA>=65537)throw new Error("Something wrong with HUF_ENCSIZE");const bA=new Array(65537),xA=new Array(16384);R(xA);const WA=N-($.value-V);if(K(F,$,WA,dA,cA,bA),SA>8*(N-($.value-V)))throw new Error("Something wrong with hufUncompress");Z(bA,dA,cA,xA),he(bA,xA,F,$,SA,cA,Y,T,z)}function W(F,L,$){for(let N=0;N<$;++N)L[N]=F[L[N]]}function HA(F){for(let L=1;L<F.length;L++){const $=F[L-1]+F[L]-128;F[L]=$}}function mA(F,L){let $=0,N=Math.floor((F.length+1)/2),T=0;const Y=F.length-1;for(;!(T>Y||(L[T++]=F[$++],T>Y));)L[T++]=F[N++]}function _A(F){let L=F.byteLength;const $=new Array;let N=0;const T=new DataView(F);for(;L>0;){const Y=T.getInt8(N++);if(Y<0){const z=-Y;L-=z+1;for(let V=0;V<z;V++)$.push(T.getUint8(N++))}else{const z=Y;L-=2;const V=T.getUint8(N++);for(let dA=0;dA<z+1;dA++)$.push(V)}}return $}function RA(F,L,$,N,T,Y){let z=new DataView(Y.buffer);const V=$[F.idx[0]].width,dA=$[F.idx[0]].height,cA=3,SA=Math.floor(V/8),bA=Math.ceil(V/8),xA=Math.ceil(dA/8),WA=V-(bA-1)*8,$A=dA-(xA-1)*8,te={value:0},Be=new Array(cA),Me=new Array(cA),St=new Array(cA),We=new Array(cA),Ne=new Array(cA);for(let me=0;me<cA;++me)Ne[me]=L[F.idx[me]],Be[me]=me<1?0:Be[me-1]+bA*xA,Me[me]=new Float32Array(64),St[me]=new Uint16Array(64),We[me]=new Uint16Array(bA*64);for(let me=0;me<xA;++me){let Zt=8;me==xA-1&&(Zt=$A);let zI=8;for(let yt=0;yt<bA;++yt){yt==bA-1&&(zI=WA);for(let je=0;je<cA;++je)St[je].fill(0),St[je][0]=T[Be[je]++],ie(te,N,St[je]),ee(St[je],Me[je]),re(Me[je]);qe(Me);for(let je=0;je<cA;++je)H(Me[je],We[je],yt*64)}let ci=0;for(let yt=0;yt<cA;++yt){const je=$[F.idx[yt]].type;for(let $g=8*me;$g<8*me+Zt;++$g){ci=Ne[yt][$g];for(let ea=0;ea<SA;++ea){const ki=ea*64+($g&7)*8;z.setUint16(ci+0*2*je,We[yt][ki+0],!0),z.setUint16(ci+1*2*je,We[yt][ki+1],!0),z.setUint16(ci+2*2*je,We[yt][ki+2],!0),z.setUint16(ci+3*2*je,We[yt][ki+3],!0),z.setUint16(ci+4*2*je,We[yt][ki+4],!0),z.setUint16(ci+5*2*je,We[yt][ki+5],!0),z.setUint16(ci+6*2*je,We[yt][ki+6],!0),z.setUint16(ci+7*2*je,We[yt][ki+7],!0),ci+=8*2*je}}if(SA!=bA)for(let $g=8*me;$g<8*me+Zt;++$g){const ea=Ne[yt][$g]+8*SA*2*je,ki=SA*64+($g&7)*8;for(let pC=0;pC<zI;++pC)z.setUint16(ea+pC*2*je,We[yt][ki+pC],!0)}}}const Lt=new Uint16Array(V);z=new DataView(Y.buffer);for(let me=0;me<cA;++me){$[F.idx[me]].decoded=!0;const Zt=$[F.idx[me]].type;if($[me].type==2)for(let zI=0;zI<dA;++zI){const ci=Ne[me][zI];for(let yt=0;yt<V;++yt)Lt[yt]=z.getUint16(ci+yt*2*Zt,!0);for(let yt=0;yt<V;++yt)z.setFloat32(ci+yt*2*Zt,CA(Lt[yt]),!0)}}}function ie(F,L,$){let N,T=1;for(;T<64;)N=L[F.value],N==65280?T=64:N>>8==255?T+=N&255:($[T]=N,T++),F.value++}function ee(F,L){L[0]=CA(F[0]),L[1]=CA(F[1]),L[2]=CA(F[5]),L[3]=CA(F[6]),L[4]=CA(F[14]),L[5]=CA(F[15]),L[6]=CA(F[27]),L[7]=CA(F[28]),L[8]=CA(F[2]),L[9]=CA(F[4]),L[10]=CA(F[7]),L[11]=CA(F[13]),L[12]=CA(F[16]),L[13]=CA(F[26]),L[14]=CA(F[29]),L[15]=CA(F[42]),L[16]=CA(F[3]),L[17]=CA(F[8]),L[18]=CA(F[12]),L[19]=CA(F[17]),L[20]=CA(F[25]),L[21]=CA(F[30]),L[22]=CA(F[41]),L[23]=CA(F[43]),L[24]=CA(F[9]),L[25]=CA(F[11]),L[26]=CA(F[18]),L[27]=CA(F[24]),L[28]=CA(F[31]),L[29]=CA(F[40]),L[30]=CA(F[44]),L[31]=CA(F[53]),L[32]=CA(F[10]),L[33]=CA(F[19]),L[34]=CA(F[23]),L[35]=CA(F[32]),L[36]=CA(F[39]),L[37]=CA(F[45]),L[38]=CA(F[52]),L[39]=CA(F[54]),L[40]=CA(F[20]),L[41]=CA(F[22]),L[42]=CA(F[33]),L[43]=CA(F[38]),L[44]=CA(F[46]),L[45]=CA(F[51]),L[46]=CA(F[55]),L[47]=CA(F[60]),L[48]=CA(F[21]),L[49]=CA(F[34]),L[50]=CA(F[37]),L[51]=CA(F[47]),L[52]=CA(F[50]),L[53]=CA(F[56]),L[54]=CA(F[59]),L[55]=CA(F[61]),L[56]=CA(F[35]),L[57]=CA(F[36]),L[58]=CA(F[48]),L[59]=CA(F[49]),L[60]=CA(F[57]),L[61]=CA(F[58]),L[62]=CA(F[62]),L[63]=CA(F[63])}function re(F){const L=.5*Math.cos(.7853975),$=.5*Math.cos(3.14159/16),N=.5*Math.cos(3.14159/8),T=.5*Math.cos(3*3.14159/16),Y=.5*Math.cos(5*3.14159/16),z=.5*Math.cos(3*3.14159/8),V=.5*Math.cos(7*3.14159/16),dA=new Array(4),cA=new Array(4),SA=new Array(4),bA=new Array(4);for(let xA=0;xA<8;++xA){const WA=xA*8;dA[0]=N*F[WA+2],dA[1]=z*F[WA+2],dA[2]=N*F[WA+6],dA[3]=z*F[WA+6],cA[0]=$*F[WA+1]+T*F[WA+3]+Y*F[WA+5]+V*F[WA+7],cA[1]=T*F[WA+1]-V*F[WA+3]-$*F[WA+5]-Y*F[WA+7],cA[2]=Y*F[WA+1]-$*F[WA+3]+V*F[WA+5]+T*F[WA+7],cA[3]=V*F[WA+1]-Y*F[WA+3]+T*F[WA+5]-$*F[WA+7],SA[0]=L*(F[WA+0]+F[WA+4]),SA[3]=L*(F[WA+0]-F[WA+4]),SA[1]=dA[0]+dA[3],SA[2]=dA[1]-dA[2],bA[0]=SA[0]+SA[1],bA[1]=SA[3]+SA[2],bA[2]=SA[3]-SA[2],bA[3]=SA[0]-SA[1],F[WA+0]=bA[0]+cA[0],F[WA+1]=bA[1]+cA[1],F[WA+2]=bA[2]+cA[2],F[WA+3]=bA[3]+cA[3],F[WA+4]=bA[3]-cA[3],F[WA+5]=bA[2]-cA[2],F[WA+6]=bA[1]-cA[1],F[WA+7]=bA[0]-cA[0]}for(let xA=0;xA<8;++xA)dA[0]=N*F[16+xA],dA[1]=z*F[16+xA],dA[2]=N*F[48+xA],dA[3]=z*F[48+xA],cA[0]=$*F[8+xA]+T*F[24+xA]+Y*F[40+xA]+V*F[56+xA],cA[1]=T*F[8+xA]-V*F[24+xA]-$*F[40+xA]-Y*F[56+xA],cA[2]=Y*F[8+xA]-$*F[24+xA]+V*F[40+xA]+T*F[56+xA],cA[3]=V*F[8+xA]-Y*F[24+xA]+T*F[40+xA]-$*F[56+xA],SA[0]=L*(F[xA]+F[32+xA]),SA[3]=L*(F[xA]-F[32+xA]),SA[1]=dA[0]+dA[3],SA[2]=dA[1]-dA[2],bA[0]=SA[0]+SA[1],bA[1]=SA[3]+SA[2],bA[2]=SA[3]-SA[2],bA[3]=SA[0]-SA[1],F[0+xA]=bA[0]+cA[0],F[8+xA]=bA[1]+cA[1],F[16+xA]=bA[2]+cA[2],F[24+xA]=bA[3]+cA[3],F[32+xA]=bA[3]-cA[3],F[40+xA]=bA[2]-cA[2],F[48+xA]=bA[1]-cA[1],F[56+xA]=bA[0]-cA[0]}function qe(F){for(let L=0;L<64;++L){const $=F[0][L],N=F[1][L],T=F[2][L];F[0][L]=$+1.5747*T,F[1][L]=$-.1873*N-.4682*T,F[2][L]=$+1.8556*N}}function H(F,L,$){for(let N=0;N<64;++N)L[$+N]=tc.toHalfFloat(J(F[N]))}function J(F){return F<=1?Math.sign(F)*Math.pow(Math.abs(F),2.2):Math.sign(F)*Math.pow(U,Math.abs(F)-1)}function uA(F){return new DataView(F.array.buffer,F.offset.value,F.size)}function wA(F){const L=F.viewer.buffer.slice(F.offset.value,F.offset.value+F.size),$=new Uint8Array(_A(L)),N=new Uint8Array($.length);return HA($),mA($,N),new DataView(N.buffer)}function KA(F){const L=F.array.slice(F.offset.value,F.offset.value+F.size),$=ju(L),N=new Uint8Array($.length);return HA($),mA($,N),new DataView(N.buffer)}function NA(F){const L=F.viewer,$={value:F.offset.value},N=new Uint16Array(F.width*F.scanlineBlockSize*(F.channels*F.type)),T=new Uint8Array(8192);let Y=0;const z=new Array(F.channels);for(let $A=0;$A<F.channels;$A++)z[$A]={},z[$A].start=Y,z[$A].end=z[$A].start,z[$A].nx=F.width,z[$A].ny=F.lines,z[$A].size=F.type,Y+=z[$A].nx*z[$A].ny*z[$A].size;const V=AA(L,$),dA=AA(L,$);if(dA>=8192)throw new Error("Something is wrong with PIZ_COMPRESSION BITMAP_SIZE");if(V<=dA)for(let $A=0;$A<dA-V+1;$A++)T[$A+V]=Ee(L,$);const cA=new Uint16Array(65536),SA=S(T,cA),bA=ce(L,$);oe(F.array,L,$,bA,N,Y);for(let $A=0;$A<F.channels;++$A){const te=z[$A];for(let Be=0;Be<z[$A].size;++Be)OA(N,te.start+Be,te.nx,te.size,te.ny,te.nx*te.size,SA)}W(cA,N,Y);let xA=0;const WA=new Uint8Array(N.buffer.byteLength);for(let $A=0;$A<F.lines;$A++)for(let te=0;te<F.channels;te++){const Be=z[te],Me=Be.nx*Be.size,St=new Uint8Array(N.buffer,Be.end*2,Me*2);WA.set(St,xA),xA+=Me*2,Be.end+=Me}return new DataView(WA.buffer)}function De(F){const L=F.array.slice(F.offset.value,F.offset.value+F.size),$=ju(L),N=F.lines*F.channels*F.width,T=F.type==1?new Uint16Array(N):new Uint32Array(N);let Y=0,z=0;const V=new Array(4);for(let dA=0;dA<F.lines;dA++)for(let cA=0;cA<F.channels;cA++){let SA=0;switch(F.type){case 1:V[0]=Y,V[1]=V[0]+F.width,Y=V[1]+F.width;for(let bA=0;bA<F.width;++bA){const xA=$[V[0]++]<<8|$[V[1]++];SA+=xA,T[z]=SA,z++}break;case 2:V[0]=Y,V[1]=V[0]+F.width,V[2]=V[1]+F.width,Y=V[2]+F.width;for(let bA=0;bA<F.width;++bA){const xA=$[V[0]++]<<24|$[V[1]++]<<16|$[V[2]++]<<8;SA+=xA,T[z]=SA,z++}break}}return new DataView(T.buffer)}function Qe(F){const L=F.viewer,$={value:F.offset.value},N=new Uint8Array(F.width*F.lines*(F.channels*F.type*2)),T={version:se(L,$),unknownUncompressedSize:se(L,$),unknownCompressedSize:se(L,$),acCompressedSize:se(L,$),dcCompressedSize:se(L,$),rleCompressedSize:se(L,$),rleUncompressedSize:se(L,$),rleRawSize:se(L,$),totalAcUncompressedCount:se(L,$),totalDcUncompressedCount:se(L,$),acCompression:se(L,$)};if(T.version<2)throw new Error("EXRLoader.parse: "+uC.compression+" version "+T.version+" is unsupported");const Y=new Array;let z=AA(L,$)-2;for(;z>0;){const te=qA(L.buffer,$),Be=Ee(L,$),Me=Be>>2&3,St=(Be>>4)-1,We=new Int8Array([St])[0],Ne=Ee(L,$);Y.push({name:te,index:We,type:Ne,compression:Me}),z-=te.length+3}const V=uC.channels,dA=new Array(F.channels);for(let te=0;te<F.channels;++te){const Be=dA[te]={},Me=V[te];Be.name=Me.name,Be.compression=0,Be.decoded=!1,Be.type=Me.pixelType,Be.pLinear=Me.pLinear,Be.width=F.width,Be.height=F.lines}const cA={idx:new Array(3)};for(let te=0;te<F.channels;++te){const Be=dA[te];for(let Me=0;Me<Y.length;++Me){const St=Y[Me];Be.name==St.name&&(Be.compression=St.compression,St.index>=0&&(cA.idx[St.index]=te),Be.offset=te)}}let SA,bA,xA;if(T.acCompressedSize>0)switch(T.acCompression){case 0:SA=new Uint16Array(T.totalAcUncompressedCount),oe(F.array,L,$,T.acCompressedSize,SA,T.totalAcUncompressedCount);break;case 1:const te=F.array.slice($.value,$.value+T.totalAcUncompressedCount),Be=ju(te);SA=new Uint16Array(Be.buffer),$.value+=T.totalAcUncompressedCount;break}if(T.dcCompressedSize>0){const te={array:F.array,offset:$,size:T.dcCompressedSize};bA=new Uint16Array(KA(te).buffer),$.value+=T.dcCompressedSize}if(T.rleRawSize>0){const te=F.array.slice($.value,$.value+T.rleCompressedSize),Be=ju(te);xA=_A(Be.buffer),$.value+=T.rleCompressedSize}let WA=0;const $A=new Array(dA.length);for(let te=0;te<$A.length;++te)$A[te]=new Array;for(let te=0;te<F.lines;++te)for(let Be=0;Be<dA.length;++Be)$A[Be].push(WA),WA+=dA[Be].width*F.type*2;RA(cA,$A,dA,SA,bA,N);for(let te=0;te<dA.length;++te){const Be=dA[te];if(!Be.decoded)switch(Be.compression){case 2:let Me=0,St=0;for(let We=0;We<F.lines;++We){let Ne=$A[te][Me];for(let Lt=0;Lt<Be.width;++Lt){for(let me=0;me<2*Be.type;++me)N[Ne++]=xA[St+me*Be.width*Be.height];St++}Me++}break;case 1:default:throw new Error("EXRLoader.parse: unsupported channel compression")}}return new DataView(N.buffer)}function qA(F,L){const $=new Uint8Array(F);let N=0;for(;$[L.value+N]!=0;)N+=1;const T=new TextDecoder().decode($.slice(L.value,L.value+N));return L.value=L.value+N+1,T}function PA(F,L,$){const N=new TextDecoder().decode(new Uint8Array(F).slice(L.value,L.value+$));return L.value=L.value+$,N}function Se(F,L){const $=it(F,L),N=ce(F,L);return[$,N]}function LA(F,L){const $=ce(F,L),N=ce(F,L);return[$,N]}function it(F,L){const $=F.getInt32(L.value,!0);return L.value=L.value+4,$}function ce(F,L){const $=F.getUint32(L.value,!0);return L.value=L.value+4,$}function zA(F,L){const $=F[L.value];return L.value=L.value+1,$}function Ee(F,L){const $=F.getUint8(L.value);return L.value=L.value+1,$}const se=function(F,L){let $;return"getBigInt64"in DataView.prototype?$=Number(F.getBigInt64(L.value,!0)):$=F.getUint32(L.value+4,!0)+Number(F.getUint32(L.value,!0)<<32),L.value+=8,$};function Fe(F,L){const $=F.getFloat32(L.value,!0);return L.value+=4,$}function P(F,L){return tc.toHalfFloat(Fe(F,L))}function CA(F){const L=(F&31744)>>10,$=F&1023;return(F>>15?-1:1)*(L?L===31?$?NaN:1/0:Math.pow(2,L-15)*(1+$/1024):6103515625e-14*($/1024))}function AA(F,L){const $=F.getUint16(L.value,!0);return L.value+=2,$}function JA(F,L){return CA(AA(F,L))}function QA(F,L,$,N){const T=$.value,Y=[];for(;$.value<T+N-1;){const z=qA(L,$),V=it(F,$),dA=Ee(F,$);$.value+=3;const cA=it(F,$),SA=it(F,$);Y.push({name:z,pixelType:V,pLinear:dA,xSampling:cA,ySampling:SA})}return $.value+=1,Y}function YA(F,L){const $=Fe(F,L),N=Fe(F,L),T=Fe(F,L),Y=Fe(F,L),z=Fe(F,L),V=Fe(F,L),dA=Fe(F,L),cA=Fe(F,L);return{redX:$,redY:N,greenX:T,greenY:Y,blueX:z,blueY:V,whiteX:dA,whiteY:cA}}function VA(F,L){const $=["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"],N=Ee(F,L);return $[N]}function gt(F,L){const $=ce(F,L),N=ce(F,L),T=ce(F,L),Y=ce(F,L);return{xMin:$,yMin:N,xMax:T,yMax:Y}}function Kt(F,L){const $=["INCREASING_Y"],N=Ee(F,L);return $[N]}function Bi(F,L){const $=Fe(F,L),N=Fe(F,L);return[$,N]}function Qi(F,L){const $=Fe(F,L),N=Fe(F,L),T=Fe(F,L);return[$,N,T]}function st(F,L,$,N,T){if(N==="string"||N==="stringvector"||N==="iccProfile")return PA(L,$,T);if(N==="chlist")return QA(F,L,$,T);if(N==="chromaticities")return YA(F,$);if(N==="compression")return VA(F,$);if(N==="box2i")return gt(F,$);if(N==="lineOrder")return Kt(F,$);if(N==="float")return Fe(F,$);if(N==="v2f")return Bi(F,$);if(N==="v3f")return Qi(F,$);if(N==="int")return it(F,$);if(N==="rational")return Se(F,$);if(N==="timecode")return LA(F,$);if(N==="preview")return $.value+=T,"skipped";$.value+=T}function mi(F,L,$){const N={};if(F.getUint32(0,!0)!=20000630)throw new Error("THREE.EXRLoader: Provided file doesn't appear to be in OpenEXR format.");N.version=F.getUint8(4);const T=F.getUint8(5);N.spec={singleTile:!!(T&2),longName:!!(T&4),deepFormat:!!(T&8),multiPart:!!(T&16)},$.value=8;let Y=!0;for(;Y;){const z=qA(L,$);if(z==0)Y=!1;else{const V=qA(L,$),dA=ce(F,$),cA=st(F,L,$,V,dA);cA===void 0?console.warn(`THREE.EXRLoader: Skipped unknown header attribute type '${V}'.`):N[z]=cA}}if(T&-5)throw console.error("THREE.EXRHeader:",N),new Error("THREE.EXRLoader: Provided file is currently unsupported.");return N}function vi(F,L,$,N,T){const Y={size:0,viewer:L,array:$,offset:N,width:F.dataWindow.xMax-F.dataWindow.xMin+1,height:F.dataWindow.yMax-F.dataWindow.yMin+1,channels:F.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:F.channels[0].pixelType,uncompress:null,getter:null,format:null,colorSpace:Ht};switch(F.compression){case"NO_COMPRESSION":Y.lines=1,Y.uncompress=uA;break;case"RLE_COMPRESSION":Y.lines=1,Y.uncompress=wA;break;case"ZIPS_COMPRESSION":Y.lines=1,Y.uncompress=KA;break;case"ZIP_COMPRESSION":Y.lines=16,Y.uncompress=KA;break;case"PIZ_COMPRESSION":Y.lines=32,Y.uncompress=NA;break;case"PXR24_COMPRESSION":Y.lines=16,Y.uncompress=De;break;case"DWAA_COMPRESSION":Y.lines=32,Y.uncompress=Qe;break;case"DWAB_COMPRESSION":Y.lines=256,Y.uncompress=Qe;break;default:throw new Error("EXRLoader.parse: "+F.compression+" is unsupported")}if(Y.scanlineBlockSize=Y.lines,Y.type==1)switch(T){case gg:Y.getter=JA,Y.inputSize=2;break;case kg:Y.getter=AA,Y.inputSize=2;break}else if(Y.type==2)switch(T){case gg:Y.getter=Fe,Y.inputSize=4;break;case kg:Y.getter=P,Y.inputSize=4}else throw new Error("EXRLoader.parse: unsupported pixelType "+Y.type+" for "+F.compression+".");Y.blockCount=(F.dataWindow.yMax+1)/Y.scanlineBlockSize;for(let V=0;V<Y.blockCount;V++)se(L,N);Y.outputChannels=Y.channels==3?4:Y.channels;const z=Y.width*Y.height*Y.outputChannels;switch(T){case gg:Y.byteArray=new Float32Array(z),Y.channels<Y.outputChannels&&Y.byteArray.fill(1,0,z);break;case kg:Y.byteArray=new Uint16Array(z),Y.channels<Y.outputChannels&&Y.byteArray.fill(15360,0,z);break;default:console.error("THREE.EXRLoader: unsupported type: ",T);break}return Y.bytesPerLine=Y.width*Y.inputSize*Y.channels,Y.outputChannels==4?(Y.format=ai,Y.colorSpace=Ht):(Y.format=$h,Y.colorSpace=Mo),Y}const To=new DataView(A),dC=new Uint8Array(A),Ho={value:0},uC=mi(To,A,Ho),tt=vi(uC,To,dC,Ho,this.type),Pd={value:0},Dy={R:0,G:1,B:2,A:3,Y:0};for(let F=0;F<tt.height/tt.scanlineBlockSize;F++){const L=ce(To,Ho);tt.size=ce(To,Ho),tt.lines=L+tt.scanlineBlockSize>tt.height?tt.height-L:tt.scanlineBlockSize;const N=tt.size<tt.lines*tt.bytesPerLine?tt.uncompress(tt):uA(tt);Ho.value+=tt.size;for(let T=0;T<tt.scanlineBlockSize;T++){const Y=T+F*tt.scanlineBlockSize;if(Y>=tt.height)break;for(let z=0;z<tt.channels;z++){const V=Dy[uC.channels[z].name];for(let dA=0;dA<tt.width;dA++){Pd.value=(T*(tt.channels*tt.width)+z*tt.width+dA)*tt.inputSize;const cA=(tt.height-1-Y)*(tt.width*tt.outputChannels)+dA*tt.outputChannels+V;tt.byteArray[cA]=tt.getter(N,Pd)}}}}return{header:uC,width:tt.width,height:tt.height,data:tt.byteArray,format:tt.format,colorSpace:tt.colorSpace,type:this.type}}setDataType(A){return this.type=A,this}load(A,e,t,i){function I(o,s){o.colorSpace=s.colorSpace,o.minFilter=xe,o.magFilter=xe,o.generateMipmaps=!1,o.flipY=!1,e&&e(o,s)}return super.load(A,I,t,i)}}const $QA=Object.freeze(Object.defineProperty({__proto__:null,EXRLoader:Rf},Symbol.toStringTag,{value:"Module"}));class hm extends aJ{constructor(A){super(A),this.type=kg}parse(A){const o=function(G,U){switch(G){case 1:throw new Error("THREE.RGBELoader: Read Error: "+(U||""));case 2:throw new Error("THREE.RGBELoader: Write Error: "+(U||""));case 3:throw new Error("THREE.RGBELoader: Bad File Format: "+(U||""));default:case 4:throw new Error("THREE.RGBELoader: Memory Error: "+(U||""))}},a=`
|
|
5237
5237
|
`,C=function(G,U,S){U=U||1024;let v=G.pos,q=-1,b=0,O="",K=String.fromCharCode.apply(null,new Uint16Array(G.subarray(v,v+128)));for(;0>(q=K.indexOf(a))&&b<U&&v<G.byteLength;)O+=K,b+=K.length,v+=128,K+=String.fromCharCode.apply(null,new Uint16Array(G.subarray(v,v+128)));return-1<q?(S!==!1&&(G.pos+=b+q+1),O+K.slice(0,q)):!1},Q=function(G){const U=/^#\?(\S+)/,S=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,R=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,v=/^\s*FORMAT=(\S+)\s*$/,q=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,b={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let O,K;for((G.pos>=G.byteLength||!(O=C(G)))&&o(1,"no header found"),(K=O.match(U))||o(3,"bad initial token"),b.valid|=1,b.programtype=K[1],b.string+=O+`
|
|
5238
5238
|
`;O=C(G),O!==!1;){if(b.string+=O+`
|
|
@@ -5266,7 +5266,7 @@ TEX `+t.texture_lod;if(TU=="density"&&(p+=`
|
|
|
5266
5266
|
`+(d/i.lastScreenCoverage).toFixed(0)+` dens
|
|
5267
5267
|
`+(i.lastScreenCoverage*100).toFixed(1)+`% cov
|
|
5268
5268
|
`+(i.lastCentrality*100).toFixed(1)+`% centr
|
|
5269
|
-
`+(aS.min.x.toFixed(2)+"-"+aS.max.x.toFixed(2)+"x"+aS.min.y.toFixed(2)+"-"+aS.max.y.toFixed(2))+" scr"),i.lastScreenCoverage>.1){const u=A,f=u.worldForward,w=u.worldPosition,M=dt(f).multiplyScalar(Q*.7).add(C),G=M.distanceTo(w),U=c[Math.min(c.length-1,Math.max(0,I))]+"88",S=this.context.domHeight>0?screen.height/this.context.domHeight:1,R=A.isPerspectiveCamera?Math.tan(A.fov*Math.PI/180/2):1;fe.DrawLabel(M,p,G*.012*S*R,void 0,16777215,U)}}}}}const BS=gA("debugphysics"),g2=new qI;class Yn{constructor(){B(this,"ray");B(this,"cam");B(this,"screenPoint");B(this,"raycaster");B(this,"results");B(this,"targets");B(this,"recursive",!0);B(this,"minDistance");B(this,"maxDistance");B(this,"lineThreshold");B(this,"layerMask");B(this,"ignore");B(this,"testObject")}screenPointFromOffset(A,e){this.screenPoint===void 0&&(this.screenPoint=new tA),this.screenPoint.x=A/window.innerWidth*2-1,this.screenPoint.y=-(e/window.innerHeight)*2+1}setLayer(A){g2.set(A),this.layerMask=g2}setMask(A){this.layerMask||(this.layerMask=new qI);const e=this.layerMask;e?e.mask=A:this.layerMask=A}}B(Yn,"AllLayers",4294967295);class wZ{constructor(A,e,t){B(this,"distance");B(this,"point");B(this,"object");this.object=A,this.distance=e,this.point=t}}class SZ{constructor(A){B(this,"context");B(this,"engine");B(this,"raycaster",new AE);B(this,"defaultRaycastOptions",new Yn);B(this,"targetBuffer",new Array(1));B(this,"defaultThresholds",{Mesh:{},Line:{threshold:-1},LOD:{},Points:{threshold:0},Sprite:{}});B(this,"sphereResults",new Array);B(this,"sphereMask",new qI);B(this,"tempBoundingBox",new Nt);this.context=A}raycastPhysicsFast(A,e=void 0,t=1/0,i=!0){var I;return((I=this.context.physics.engine)==null?void 0:I.raycast(A,e,{maxDistance:t,solid:i}))??null}raycastPhysicsFastAndGetNormal(A,e=void 0,t=1/0,i=!0){var I;return((I=this.context.physics.engine)==null?void 0:I.raycastAndGetNormal(A,e,{maxDistance:t,solid:i}))??null}sphereOverlapPhysics(A,e){var t;return((t=this.context.physics.engine)==null?void 0:t.sphereOverlap(A,e))??null}sphereOverlap(A,e,t=!0){if(this.sphereResults.length=0,!this.context.scene)return this.sphereResults;const i=new Zi(A,e),I=this.sphereMask;I.enableAll(),I.disable(2);for(const o of this.context.scene.children)this.onSphereOverlap(o,i,I,this.sphereResults,t);return this.sphereResults.sort((o,s)=>o.distance-s.distance)}onSphereOverlap(A,e,t,i,I){if(A.type==="Mesh"&&A.layers.test(t)&&!fe.isGizmo(A)){const o=A,s=o.geometry;if(s&&(s.boundingBox||s.computeBoundingBox(),s.boundingBox)){o.matrixWorldNeedsUpdate&&o.updateMatrixWorld();const n=this.tempBoundingBox.copy(s.boundingBox).applyMatrix4(o.matrixWorld);if(e.intersectsBox(n)){const r=ve(A),a=r.distanceTo(e.center),C=new wZ(A,a,r);if(i.push(C),!I)return}}}if(A.children)for(const o of A.children){const s=i.length;if(this.onSphereOverlap(o,e,t,i,I),s!=i.length&&!I)return}}raycastFromRay(A,e=null){const t=e??this.defaultRaycastOptions;t.ray=A;const i=this.raycast(t);return t===this.defaultRaycastOptions&&(t.ray=void 0),i}raycast(A=null){A||(A=this.defaultRaycastOptions);const e=A.screenPoint??this.context.input.mousePositionRC,t=A.raycaster??this.raycaster;if(t.near=A.minDistance??0,t.far=A.maxDistance??1/0,t.params=this.defaultThresholds,A.lineThreshold===void 0&&(A.lineThreshold=-1),t.params.Line={threshold:A.lineThreshold},A.ray)t.ray.copy(A.ray);else{const s=A.cam??this.context.mainCamera;if(!s)return BS&&console.error("Can not perform raycast - no main camera found"),this.defaultRaycastOptions.results&&(this.defaultRaycastOptions.results.length=0),this.defaultRaycastOptions.results??[];const n=this.context.xrCamera;this.context.isInXR&&n instanceof Wb&&n.cameras.length>0?t.setFromCamera(e,n.cameras[0]):t.setFromCamera(e,s)}let i=A.targets;i||(i=this.targetBuffer,i.length=1,i[0]=this.context.scene);let I=A.results;this.defaultRaycastOptions.results&&(this.defaultRaycastOptions.results.length=0),I||(this.defaultRaycastOptions.results||(this.defaultRaycastOptions.results=new Array),I=this.defaultRaycastOptions.results),A.layerMask!==void 0?A.layerMask instanceof qI?t.layers.mask=A.layerMask.mask:t.layers.mask=A.layerMask:(t.layers.enableAll(),t.layers.disable(2)),BS&&(fe.DrawRay(t.ray.origin,t.ray.direction,16711680,2),console.time("raycast")),I.length=0,this.intersect(this.raycaster,i,I,A),I.sort((s,n)=>s.distance-n.distance);const o=A.ignore;return o!==void 0&&o.length>0&&(I=I.filter(s=>!o.includes(s.object))),BS&&(console.timeEnd("raycast"),console.warn("#"+this.context.time.frame+", hits:",I!=null&&I.length?[...I]:"nothing")),I}intersect(A,e,t,i){var I;for(const o of e){if(o.visible===!1||fe.isGizmo(o)||i.lineThreshold!==void 0&&i.lineThreshold<0&&o instanceof Oi)continue;const s=(I=i.testObject)==null?void 0:I.call(i,o);if(s===!1)continue;if(s!=="continue in children"){const r=o,a=r.geometry;if(a){const C=DD(o);C&&(r.geometry=C);const Q=t.length;A.intersectObject(o,!1,t),BS&&t.length!=Q&&fe.DrawWireMesh({mesh:o,depthTest:!1,duration:.2,color:C?8969557:7798784}),r.geometry=a}}i.recursive!==!1&&this.intersect(A,o.children,t,i)}return t}}const gcA=gA("debugplayerview");var SB=(g=>(g.Browser="browser",g.Headset="headset",g.Handheld="handheld",g))(SB||{});class mZ{constructor(A,e){B(this,"userId");B(this,"context");B(this,"viewDevice","browser");B(this,"removed",!1);B(this,"_object");this.userId=A,this.context=e}get currentObject(){return this._object}set currentObject(A){this._object=A}get isConnected(){return this.context.connection.userIsInRoom(this.userId)}}class kZ{constructor(A){B(this,"context");B(this,"playerViews",new Map);this.context=A}setPlayerView(A,e,t){let i=this.playerViews.get(A);i||(i=new mZ(A,this.context),this.playerViews.set(A,i)),i.viewDevice=t,i.currentObject=e,i.removed=!1}getPlayerView(A){if(!A)return;if(!this.context.connection.userIsInRoom(A)){this.playerViews.delete(A);return}return this.playerViews.get(A)}removePlayerView(A,e){const t=this.playerViews.get(A);(t==null?void 0:t.viewDevice)===e&&(gcA&&console.log("REMOVE",A),t.removed=!0,this.playerViews.delete(A))}}new HI;const GD=new Uint8Array(4);GD[0]=255;GD[1]=255;GD[2]=255;GD[3]=255;const IcA=new rs(GD,1,1,ai);function ev(g,A=1){const e="alpha"in g,t=A*A,i=new Uint8Array(4*t),I=Math.floor(g.r*255),o=Math.floor(g.g*255),s=Math.floor(g.b*255);for(let r=0;r<t;r++){const a=r*4;i[a+0]=I,i[a+1]=o,i[a+2]=s,e?i[a+3]=Math.floor(g.alpha*255):i[a+3]=255}const n=new rs(i,A,A);return n.needsUpdate=!0,n}function ocA(g,A,e,t=1,i=3){const o=t*i,s=[g,A,e],n=s.length,r=new Uint8Array(4*n*o),a=new yA;for(let Q=0;Q<i;Q++){const c=Math.floor(Q/i*n),E=ge.clamp(c+1,0,n-1),h=s[c],l=s[E],d=Q/i*n%1;a.lerpColors(h,l,d);const p=Math.floor(a.r*255),u=Math.floor(a.g*255),f=Math.floor(a.b*255);for(let w=0;w<t;w++){const m=(Q*t+w)*4;r[m+0]=p,r[m+1]=u,r[m+2]=f,r[m+3]=255}}const C=new rs(r,t,i);return C.needsUpdate=!0,C}function dm(g,A){const e=g.elements;A||(A=[]),A.length=0;for(let t=0;t<16;t+=4){const i=e[t],I=e[t+1],o=e[t+2],s=e[t+3],n=new Ae(i,I,o,s);A.push(n)}return A}const HU=[],I2=[];function scA(g,A){if(HU.length===0)for(let e=0;e<27;e++)HU.push(0);A||(A=HU);for(let e=0;e<27;e++)I2[e]=A[e];A=I2,g.unity_SHAr={value:new Ae(A[9],A[3],A[6],A[0])},g.unity_SHBr={value:new Ae(A[12],A[15],A[18],A[21])},g.unity_SHAg={value:new Ae(A[10],A[4],A[7],A[1])},g.unity_SHBg={value:new Ae(A[13],A[16],A[19],A[22])},g.unity_SHAb={value:new Ae(A[11],A[5],A[8],A[2])},g.unity_SHBb={value:new Ae(A[14],A[17],A[20],A[23])},g.unity_SHC={value:new Ae(A[24],A[25],A[26],1)}}class ncA{constructor(A,e,t){B(this,"vertexShader");B(this,"fragmentShader");B(this,"technique");this.vertexShader=A,this.fragmentShader=e,this.technique=t}}async function rcA(g,A){if(!g)return console.error("Can not find technique: no shader data"),null;const e=g.programs[A],t=e.vertexShader,i=e.fragmentShader;if(t!==void 0&&i!==void 0){const I=g.shaders[t],o=g.shaders[i];if(I.uri&&o.uri||I.code&&o.code){if(!I.code&&I.uri&&await o2(I),!o.code&&o.uri&&await o2(o),!I.code||!o.code)return null;const s=g.techniques[A];return new ncA(I.code,o.code,s)}}return console.error("Shader technique not found",A),null}async function o2(g){const A=g.uri;if(A)if(A.endsWith(".glsl")){const t=await new HI().loadAsync(A);g.code=t.toString()}else g.code=acA(g.uri)}function acA(g){return decodeURIComponent(Array.prototype.map.call(atob(g),function(A){return"%"+("00"+A.charCodeAt(0).toString(16)).slice(-2)}).join(""))}const Dn=gA("debugenvlight");var dh=(g=>(g[g.Skybox=0]="Skybox",g[g.Trilight=1]="Trilight",g[g.Flat=3]="Flat",g[g.Custom=4]="Custom",g))(dh||{}),um=(g=>(g[g.Skybox=0]="Skybox",g[g.Custom=1]="Custom",g))(um||{});class MZ{constructor(A){B(this,"context");B(this,"_currentLightSettingsId");B(this,"_sceneLightSettings");B(this,"_timevec4",new Ae);B(this,"__currentReflectionId",null);B(this,"_lighting",{});this.context=A,this.context.pre_update_callbacks.push(this.preUpdate.bind(this))}preUpdate(){const A=this.context.time;this._timevec4.x=A.time,this._timevec4.y=Math.sin(A.time),this._timevec4.z=Math.cos(A.time),this._timevec4.w=A.deltaTime}get timeVec4(){return this._timevec4}get environmentIntensity(){if(!this._sceneLightSettings||!this._currentLightSettingsId)return 1;const A=this._sceneLightSettings.get(this._currentLightSettingsId);return A?A.ambientIntensity:1}get sceneLightSettings(){var A;return(A=this._sceneLightSettings)==null?void 0:A.values()}enable(A){var t;A instanceof et&&(A=A.uri);const e=(t=this._sceneLightSettings)==null?void 0:t.get(A);return e?(Dn&&console.log("Enable scene light settings",A,e),A!==this._currentLightSettingsId&&this._currentLightSettingsId&&this.disable(this._currentLightSettingsId),this._currentLightSettingsId=A,e.enabled=!0,!0):(Dn&&console.warn("No light settings found for",A),!1)}disable(A){var t;if(A instanceof et&&(A=A.uri),A==null)return!1;const e=(t=this._sceneLightSettings)==null?void 0:t.get(A);return e?(Dn&&console.log("Disable scene light settings",A,e),e.enabled=!1,!0):!1}disableCurrent(){if(this._currentLightSettingsId){const A=this._currentLightSettingsId;return this.disable(this._currentLightSettingsId),A}return null}internalRegisterSceneLightSettings(A){const e=A.sourceId;if(!e){console.error("Missing source id for scene light settings, can not register:",A);return}Dn&&console.log("Register "+(A==null?void 0:A.sourceId)+" lighting",A),this._sceneLightSettings||(this._sceneLightSettings=new Map),this._sceneLightSettings.set(e,A)}internalUnregisterSceneLightSettings(A){const e=A.sourceId;if(!e){console.error("Missing source id for scene light settings, can not unregister:",A);return}Dn&&console.log("Unregister "+(A==null?void 0:A.sourceId)+" lighting",A),this._sceneLightSettings&&this._sceneLightSettings.delete(e)}internalRegisterReflection(A,e){Dn&&console.log("Register reflection",A,e);const t=new GZ(this.context,e,1);this._lighting[A]=t}internalGetReflection(A){return this._lighting[A]}internalEnableReflection(A){var t;this.__currentReflectionId=A;const e=(t=this._sceneLightSettings)==null?void 0:t.get(A);switch(Dn&&console.log("Enable reflection",A,e?dh[e.ambientMode]:"Unknown ambient mode",e),e==null?void 0:e.ambientMode){case 0:case 4:const i=this.internalGetReflection(A);if(i&&i.Source){Dn&&console.log("Setting environment reflection",i);const I=this.context.scene,o=i.Source;o.mapping=No,I.environment=o;return}else Dn&&console.warn("Could not find reflection for source",A);break}if((e==null?void 0:e.environmentReflectionSource)===1)switch(e==null?void 0:e.ambientMode){case 1:if(e.ambientTrilight){const i=e.ambientTrilight,I=ocA(i[0],i[1],i[2],64,64);I.colorSpace=pe,I.mapping=No,this.context.scene.environment=I}else console.error("Missing ambient trilight",e.sourceId);return;case 3:if(e.ambientLight){const i=ev(e.ambientLight,64);i.colorSpace=pe,i.mapping=No,this.context.scene.environment=i}else console.error("Missing ambientlight",e.sourceId);return;default:return}}internalDisableReflection(A){if(A&&A!==this.__currentReflectionId){Dn&&console.log("Not disabling reflection for",A,"because it is not the current light settings id",this.__currentReflectionId);return}Dn&&console.log("Disable reflection",A);const e=this.context.scene;e.environment=null}}class GZ{constructor(A,e,t=1){B(this,"_source");this._source=e,e.mapping=No}get Source(){return this._source}}const s2=gA("timescale");let LK=1;typeof s2=="number"&&(LK=s2);class RZ{constructor(){B(this,"_time",0);B(this,"_deltaTime",0);B(this,"_deltaTimeUnscaled",0);B(this,"timeScale",1);B(this,"_frame",0);B(this,"clock",new QJ);B(this,"_smoothedFps",0);B(this,"_smoothedDeltaTime",0);B(this,"_fpsSamples",[]);B(this,"_fpsSampleIndex",0);typeof LK=="number"&&(this.timeScale=LK)}get time(){return this._time}set time(A){this._time=A}get deltaTime(){return this._deltaTime}set deltaTime(A){this._deltaTime=A}get deltaTimeUnscaled(){return this._deltaTimeUnscaled}get frame(){return this._frame}set frame(A){this._frame=A}get frameCount(){return this.frame}get realtimeSinceStartup(){return this.clock.elapsedTime}get smoothedFps(){return this._smoothedFps}get smoothedDeltaTime(){return 1/this._smoothedFps}update(){this.deltaTime=this.clock.getDelta(),this.deltaTime=Math.min(.1,this.deltaTime),this._deltaTimeUnscaled=this.deltaTime,this.deltaTime<=0&&(this.deltaTime=1e-12),this.deltaTime*=this.timeScale,this.frame+=1,this.time+=this.deltaTime,this._fpsSamples.length<60?this._fpsSamples.push(this.deltaTime):this._fpsSamples[this._fpsSampleIndex++%60]=this.deltaTime;let A=0;for(let e=0;e<this._fpsSamples.length;e++)A+=this._fpsSamples[e];this._smoothedDeltaTime=A/this._fpsSamples.length,this._smoothedFps=1/this._smoothedDeltaTime}}let n2=!1;function UZ(g){n2||(n2=!0,CcA(),BcA())}UZ();function CcA(){const g=`
|
|
5269
|
+
`+(aS.min.x.toFixed(2)+"-"+aS.max.x.toFixed(2)+"x"+aS.min.y.toFixed(2)+"-"+aS.max.y.toFixed(2))+" scr"),i.lastScreenCoverage>.1){const u=A,f=u.worldForward,w=u.worldPosition,M=dt(f).multiplyScalar(Q*.7).add(C),G=M.distanceTo(w),U=c[Math.min(c.length-1,Math.max(0,I))]+"88",S=this.context.domHeight>0?screen.height/this.context.domHeight:1,R=A.isPerspectiveCamera?Math.tan(A.fov*Math.PI/180/2):1;fe.DrawLabel(M,p,G*.012*S*R,void 0,16777215,U)}}}}}const BS=gA("debugphysics"),g2=new qI;class Yn{constructor(){B(this,"ray");B(this,"cam");B(this,"screenPoint");B(this,"raycaster");B(this,"results");B(this,"targets");B(this,"recursive",!0);B(this,"minDistance");B(this,"maxDistance");B(this,"lineThreshold");B(this,"layerMask");B(this,"ignore");B(this,"testObject")}screenPointFromOffset(A,e){this.screenPoint===void 0&&(this.screenPoint=new tA),this.screenPoint.x=A/window.innerWidth*2-1,this.screenPoint.y=-(e/window.innerHeight)*2+1}setLayer(A){g2.set(A),this.layerMask=g2}setMask(A){this.layerMask||(this.layerMask=new qI);const e=this.layerMask;e?e.mask=A:this.layerMask=A}}B(Yn,"AllLayers",4294967295);class wZ{constructor(A,e,t){B(this,"distance");B(this,"point");B(this,"object");this.object=A,this.distance=e,this.point=t}}class SZ{constructor(A){B(this,"context");B(this,"engine");B(this,"raycaster",new AE);B(this,"defaultRaycastOptions",new Yn);B(this,"targetBuffer",new Array(1));B(this,"defaultThresholds",{Mesh:{},Line:{threshold:-1},LOD:{},Points:{threshold:0},Sprite:{}});B(this,"sphereResults",new Array);B(this,"sphereMask",new qI);B(this,"tempBoundingBox",new Nt);this.context=A}raycastPhysicsFast(A,e=void 0,t=1/0,i=!0){var I;return((I=this.context.physics.engine)==null?void 0:I.raycast(A,e,{maxDistance:t,solid:i}))??null}raycastPhysicsFastAndGetNormal(A,e=void 0,t=1/0,i=!0){var I;return((I=this.context.physics.engine)==null?void 0:I.raycastAndGetNormal(A,e,{maxDistance:t,solid:i}))??null}sphereOverlapPhysics(A,e){var t;return((t=this.context.physics.engine)==null?void 0:t.sphereOverlap(A,e))??null}sphereOverlap(A,e,t=!0){if(this.sphereResults.length=0,!this.context.scene)return this.sphereResults;const i=new Zi(A,e),I=this.sphereMask;I.enableAll(),I.disable(2);for(const o of this.context.scene.children)this.onSphereOverlap(o,i,I,this.sphereResults,t);return this.sphereResults.sort((o,s)=>o.distance-s.distance)}onSphereOverlap(A,e,t,i,I){if(A.type==="Mesh"&&A.layers.test(t)&&!fe.isGizmo(A)){const o=A,s=o.geometry;if(s&&(s.boundingBox||s.computeBoundingBox(),s.boundingBox)){o.matrixWorldNeedsUpdate&&o.updateMatrixWorld();const n=this.tempBoundingBox.copy(s.boundingBox).applyMatrix4(o.matrixWorld);if(e.intersectsBox(n)){const r=ve(A),a=r.distanceTo(e.center),C=new wZ(A,a,r);if(i.push(C),!I)return}}}if(A.children)for(const o of A.children){const s=i.length;if(this.onSphereOverlap(o,e,t,i,I),s!=i.length&&!I)return}}raycastFromRay(A,e=null){const t=e??this.defaultRaycastOptions;t.ray=A;const i=this.raycast(t);return t===this.defaultRaycastOptions&&(t.ray=void 0),i}raycast(A=null){A||(A=this.defaultRaycastOptions);const e=A.screenPoint??this.context.input.mousePositionRC,t=A.raycaster??this.raycaster;if(t.near=A.minDistance??0,t.far=A.maxDistance??1/0,t.params=this.defaultThresholds,A.lineThreshold===void 0&&(A.lineThreshold=-1),t.params.Line={threshold:A.lineThreshold},A.ray)t.ray.copy(A.ray);else{const s=A.cam??this.context.mainCamera;if(!s)return BS&&console.error("Can not perform raycast - no main camera found"),this.defaultRaycastOptions.results&&(this.defaultRaycastOptions.results.length=0),this.defaultRaycastOptions.results??[];const n=this.context.xrCamera;this.context.isInXR&&n instanceof Wb&&n.cameras.length>0?t.setFromCamera(e,n.cameras[0]):t.setFromCamera(e,s)}let i=A.targets;i||(i=this.targetBuffer,i.length=1,i[0]=this.context.scene);let I=A.results;this.defaultRaycastOptions.results&&(this.defaultRaycastOptions.results.length=0),I||(this.defaultRaycastOptions.results||(this.defaultRaycastOptions.results=new Array),I=this.defaultRaycastOptions.results),A.layerMask!==void 0?A.layerMask instanceof qI?t.layers.mask=A.layerMask.mask:t.layers.mask=A.layerMask:(t.layers.enableAll(),t.layers.disable(2)),BS&&(fe.DrawRay(t.ray.origin,t.ray.direction,16711680,2),console.time("raycast")),I.length=0,this.intersect(this.raycaster,i,I,A),I.sort((s,n)=>s.distance-n.distance);const o=A.ignore;return o!==void 0&&o.length>0&&(I=I.filter(s=>!o.includes(s.object))),BS&&(console.timeEnd("raycast"),console.warn("#"+this.context.time.frame+", hits:",I!=null&&I.length?[...I]:"nothing")),I}intersect(A,e,t,i){var I;for(const o of e){if(!o||o.visible===!1||fe.isGizmo(o)||i.lineThreshold!==void 0&&i.lineThreshold<0&&o instanceof Oi)continue;const s=(I=i.testObject)==null?void 0:I.call(i,o);if(s===!1)continue;if(s!=="continue in children"){const r=o,a=r.geometry;if(a){const C=DD(o);C&&(r.geometry=C);const Q=t.length;A.intersectObject(o,!1,t),BS&&t.length!=Q&&fe.DrawWireMesh({mesh:o,depthTest:!1,duration:.2,color:C?8969557:7798784}),r.geometry=a}}i.recursive!==!1&&this.intersect(A,o.children,t,i)}return t}}const gcA=gA("debugplayerview");var SB=(g=>(g.Browser="browser",g.Headset="headset",g.Handheld="handheld",g))(SB||{});class mZ{constructor(A,e){B(this,"userId");B(this,"context");B(this,"viewDevice","browser");B(this,"removed",!1);B(this,"_object");this.userId=A,this.context=e}get currentObject(){return this._object}set currentObject(A){this._object=A}get isConnected(){return this.context.connection.userIsInRoom(this.userId)}}class kZ{constructor(A){B(this,"context");B(this,"playerViews",new Map);this.context=A}setPlayerView(A,e,t){let i=this.playerViews.get(A);i||(i=new mZ(A,this.context),this.playerViews.set(A,i)),i.viewDevice=t,i.currentObject=e,i.removed=!1}getPlayerView(A){if(!A)return;if(!this.context.connection.userIsInRoom(A)){this.playerViews.delete(A);return}return this.playerViews.get(A)}removePlayerView(A,e){const t=this.playerViews.get(A);(t==null?void 0:t.viewDevice)===e&&(gcA&&console.log("REMOVE",A),t.removed=!0,this.playerViews.delete(A))}}new HI;const GD=new Uint8Array(4);GD[0]=255;GD[1]=255;GD[2]=255;GD[3]=255;const IcA=new rs(GD,1,1,ai);function ev(g,A=1){const e="alpha"in g,t=A*A,i=new Uint8Array(4*t),I=Math.floor(g.r*255),o=Math.floor(g.g*255),s=Math.floor(g.b*255);for(let r=0;r<t;r++){const a=r*4;i[a+0]=I,i[a+1]=o,i[a+2]=s,e?i[a+3]=Math.floor(g.alpha*255):i[a+3]=255}const n=new rs(i,A,A);return n.needsUpdate=!0,n}function ocA(g,A,e,t=1,i=3){const o=t*i,s=[g,A,e],n=s.length,r=new Uint8Array(4*n*o),a=new yA;for(let Q=0;Q<i;Q++){const c=Math.floor(Q/i*n),E=ge.clamp(c+1,0,n-1),h=s[c],l=s[E],d=Q/i*n%1;a.lerpColors(h,l,d);const p=Math.floor(a.r*255),u=Math.floor(a.g*255),f=Math.floor(a.b*255);for(let w=0;w<t;w++){const m=(Q*t+w)*4;r[m+0]=p,r[m+1]=u,r[m+2]=f,r[m+3]=255}}const C=new rs(r,t,i);return C.needsUpdate=!0,C}function dm(g,A){const e=g.elements;A||(A=[]),A.length=0;for(let t=0;t<16;t+=4){const i=e[t],I=e[t+1],o=e[t+2],s=e[t+3],n=new Ae(i,I,o,s);A.push(n)}return A}const HU=[],I2=[];function scA(g,A){if(HU.length===0)for(let e=0;e<27;e++)HU.push(0);A||(A=HU);for(let e=0;e<27;e++)I2[e]=A[e];A=I2,g.unity_SHAr={value:new Ae(A[9],A[3],A[6],A[0])},g.unity_SHBr={value:new Ae(A[12],A[15],A[18],A[21])},g.unity_SHAg={value:new Ae(A[10],A[4],A[7],A[1])},g.unity_SHBg={value:new Ae(A[13],A[16],A[19],A[22])},g.unity_SHAb={value:new Ae(A[11],A[5],A[8],A[2])},g.unity_SHBb={value:new Ae(A[14],A[17],A[20],A[23])},g.unity_SHC={value:new Ae(A[24],A[25],A[26],1)}}class ncA{constructor(A,e,t){B(this,"vertexShader");B(this,"fragmentShader");B(this,"technique");this.vertexShader=A,this.fragmentShader=e,this.technique=t}}async function rcA(g,A){if(!g)return console.error("Can not find technique: no shader data"),null;const e=g.programs[A],t=e.vertexShader,i=e.fragmentShader;if(t!==void 0&&i!==void 0){const I=g.shaders[t],o=g.shaders[i];if(I.uri&&o.uri||I.code&&o.code){if(!I.code&&I.uri&&await o2(I),!o.code&&o.uri&&await o2(o),!I.code||!o.code)return null;const s=g.techniques[A];return new ncA(I.code,o.code,s)}}return console.error("Shader technique not found",A),null}async function o2(g){const A=g.uri;if(A)if(A.endsWith(".glsl")){const t=await new HI().loadAsync(A);g.code=t.toString()}else g.code=acA(g.uri)}function acA(g){return decodeURIComponent(Array.prototype.map.call(atob(g),function(A){return"%"+("00"+A.charCodeAt(0).toString(16)).slice(-2)}).join(""))}const Dn=gA("debugenvlight");var dh=(g=>(g[g.Skybox=0]="Skybox",g[g.Trilight=1]="Trilight",g[g.Flat=3]="Flat",g[g.Custom=4]="Custom",g))(dh||{}),um=(g=>(g[g.Skybox=0]="Skybox",g[g.Custom=1]="Custom",g))(um||{});class MZ{constructor(A){B(this,"context");B(this,"_currentLightSettingsId");B(this,"_sceneLightSettings");B(this,"_timevec4",new Ae);B(this,"__currentReflectionId",null);B(this,"_lighting",{});this.context=A,this.context.pre_update_callbacks.push(this.preUpdate.bind(this))}preUpdate(){const A=this.context.time;this._timevec4.x=A.time,this._timevec4.y=Math.sin(A.time),this._timevec4.z=Math.cos(A.time),this._timevec4.w=A.deltaTime}get timeVec4(){return this._timevec4}get environmentIntensity(){if(!this._sceneLightSettings||!this._currentLightSettingsId)return 1;const A=this._sceneLightSettings.get(this._currentLightSettingsId);return A?A.ambientIntensity:1}get sceneLightSettings(){var A;return(A=this._sceneLightSettings)==null?void 0:A.values()}enable(A){var t;A instanceof et&&(A=A.uri);const e=(t=this._sceneLightSettings)==null?void 0:t.get(A);return e?(Dn&&console.log("Enable scene light settings",A,e),A!==this._currentLightSettingsId&&this._currentLightSettingsId&&this.disable(this._currentLightSettingsId),this._currentLightSettingsId=A,e.enabled=!0,!0):(Dn&&console.warn("No light settings found for",A),!1)}disable(A){var t;if(A instanceof et&&(A=A.uri),A==null)return!1;const e=(t=this._sceneLightSettings)==null?void 0:t.get(A);return e?(Dn&&console.log("Disable scene light settings",A,e),e.enabled=!1,!0):!1}disableCurrent(){if(this._currentLightSettingsId){const A=this._currentLightSettingsId;return this.disable(this._currentLightSettingsId),A}return null}internalRegisterSceneLightSettings(A){const e=A.sourceId;if(!e){console.error("Missing source id for scene light settings, can not register:",A);return}Dn&&console.log("Register "+(A==null?void 0:A.sourceId)+" lighting",A),this._sceneLightSettings||(this._sceneLightSettings=new Map),this._sceneLightSettings.set(e,A)}internalUnregisterSceneLightSettings(A){const e=A.sourceId;if(!e){console.error("Missing source id for scene light settings, can not unregister:",A);return}Dn&&console.log("Unregister "+(A==null?void 0:A.sourceId)+" lighting",A),this._sceneLightSettings&&this._sceneLightSettings.delete(e)}internalRegisterReflection(A,e){Dn&&console.log("Register reflection",A,e);const t=new GZ(this.context,e,1);this._lighting[A]=t}internalGetReflection(A){return this._lighting[A]}internalEnableReflection(A){var t;this.__currentReflectionId=A;const e=(t=this._sceneLightSettings)==null?void 0:t.get(A);switch(Dn&&console.log("Enable reflection",A,e?dh[e.ambientMode]:"Unknown ambient mode",e),e==null?void 0:e.ambientMode){case 0:case 4:const i=this.internalGetReflection(A);if(i&&i.Source){Dn&&console.log("Setting environment reflection",i);const I=this.context.scene,o=i.Source;o.mapping=No,I.environment=o;return}else Dn&&console.warn("Could not find reflection for source",A);break}if((e==null?void 0:e.environmentReflectionSource)===1)switch(e==null?void 0:e.ambientMode){case 1:if(e.ambientTrilight){const i=e.ambientTrilight,I=ocA(i[0],i[1],i[2],64,64);I.colorSpace=pe,I.mapping=No,this.context.scene.environment=I}else console.error("Missing ambient trilight",e.sourceId);return;case 3:if(e.ambientLight){const i=ev(e.ambientLight,64);i.colorSpace=pe,i.mapping=No,this.context.scene.environment=i}else console.error("Missing ambientlight",e.sourceId);return;default:return}}internalDisableReflection(A){if(A&&A!==this.__currentReflectionId){Dn&&console.log("Not disabling reflection for",A,"because it is not the current light settings id",this.__currentReflectionId);return}Dn&&console.log("Disable reflection",A);const e=this.context.scene;e.environment=null}}class GZ{constructor(A,e,t=1){B(this,"_source");this._source=e,e.mapping=No}get Source(){return this._source}}const s2=gA("timescale");let LK=1;typeof s2=="number"&&(LK=s2);class RZ{constructor(){B(this,"_time",0);B(this,"_deltaTime",0);B(this,"_deltaTimeUnscaled",0);B(this,"timeScale",1);B(this,"_frame",0);B(this,"clock",new QJ);B(this,"_smoothedFps",0);B(this,"_smoothedDeltaTime",0);B(this,"_fpsSamples",[]);B(this,"_fpsSampleIndex",0);typeof LK=="number"&&(this.timeScale=LK)}get time(){return this._time}set time(A){this._time=A}get deltaTime(){return this._deltaTime}set deltaTime(A){this._deltaTime=A}get deltaTimeUnscaled(){return this._deltaTimeUnscaled}get frame(){return this._frame}set frame(A){this._frame=A}get frameCount(){return this.frame}get realtimeSinceStartup(){return this.clock.elapsedTime}get smoothedFps(){return this._smoothedFps}get smoothedDeltaTime(){return 1/this._smoothedFps}update(){this.deltaTime=this.clock.getDelta(),this.deltaTime=Math.min(.1,this.deltaTime),this._deltaTimeUnscaled=this.deltaTime,this.deltaTime<=0&&(this.deltaTime=1e-12),this.deltaTime*=this.timeScale,this.frame+=1,this.time+=this.deltaTime,this._fpsSamples.length<60?this._fpsSamples.push(this.deltaTime):this._fpsSamples[this._fpsSampleIndex++%60]=this.deltaTime;let A=0;for(let e=0;e<this._fpsSamples.length;e++)A+=this._fpsSamples[e];this._smoothedDeltaTime=A/this._fpsSamples.length,this._smoothedFps=1/this._smoothedDeltaTime}}let n2=!1;function UZ(g){n2||(n2=!0,CcA(),BcA())}UZ();function CcA(){const g=`
|
|
5270
5270
|
float startCompression = 0.8;
|
|
5271
5271
|
float desaturation = 0.5;
|
|
5272
5272
|
// Patched tonemapping function
|