@needle-tools/engine 3.41.1-alpha → 3.41.1-alpha.1

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.
@@ -4344,7 +4344,7 @@ Open this page to get the console: `+A.toString())}const g=Bs()||Sk()&&Ce();if((
4344
4344
  #__vconsole .vc-mask {
4345
4345
  overflow: hidden;
4346
4346
  }
4347
- `,Xo==null||Xo.prepend(t),g===!0&&aJ()<=0&&o3(),console.log("🌵 Debug console has loaded")}},A.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(A)}function RgA(){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 a='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';e(a)}),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"),Is==null||Is.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 UgA(){const g=document.querySelector("#__vconsole .vc-switch");return g||null}function FgA(){const g=document.querySelector("#__vconsole");return g||null}const a3=gA("debugdefines");Wl('if(!globalThis[""3.41.1-alpha""]) globalThis[""3.41.1-alpha""] = "0.0.0";');Wl('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');Wl('if(!globalThis[""Mon Jun 24 2024 12:27:47 GMT+0200 (Central European Summer Time)""]) globalThis[""Mon Jun 24 2024 12:27:47 GMT+0200 (Central European Summer Time)""] = "unknown";');Wl('globalThis["__NEEDLE_ENGINE_VERSION__"] = "3.41.1-alpha";');Wl('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');Wl('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Jun 24 2024 12:27:47 GMT+0200 (Central European Summer Time)";');const Hs="3.41.1-alpha",Uk="undefined",HJ="Mon Jun 24 2024 12:27:47 GMT+0200 (Central European Summer Time)";a3&&console.log(`Engine version: ${Hs} (generator: ${Uk})
4347
+ `,Xo==null||Xo.prepend(t),g===!0&&aJ()<=0&&o3(),console.log("🌵 Debug console has loaded")}},A.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(A)}function RgA(){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 a='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';e(a)}),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"),Is==null||Is.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 UgA(){const g=document.querySelector("#__vconsole .vc-switch");return g||null}function FgA(){const g=document.querySelector("#__vconsole");return g||null}const a3=gA("debugdefines");Wl('if(!globalThis[""3.41.1-alpha.1""]) globalThis[""3.41.1-alpha.1""] = "0.0.0";');Wl('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');Wl('if(!globalThis[""Mon Jun 24 2024 16:20:52 GMT+0200 (Central European Summer Time)""]) globalThis[""Mon Jun 24 2024 16:20:52 GMT+0200 (Central European Summer Time)""] = "unknown";');Wl('globalThis["__NEEDLE_ENGINE_VERSION__"] = "3.41.1-alpha.1";');Wl('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');Wl('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Jun 24 2024 16:20:52 GMT+0200 (Central European Summer Time)";');const Hs="3.41.1-alpha.1",Uk="undefined",HJ="Mon Jun 24 2024 16:20:52 GMT+0200 (Central European Summer Time)";a3&&console.log(`Engine version: ${Hs} (generator: ${Uk})
4348
4348
  Project built at ${HJ}`);const Yr="needle_isActiveInHierarchy",xQ="builtin_components",dp="needle_editor_guid";function Wl(g){try{(0,eval)(g)}catch(A){a3&&console.error(A)}}const NgA='<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>',bgA=btoa(NgA),KgA="data:image/svg+xml;base64,"+bgA,JgA=KgA,xgA=`<?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(xgA);const vgA='<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>',qgA=btoa(vgA),LgA="data:image/svg+xml;charset=utf-8;base64,"+qgA,_gA=LgA,qs=gA("debuglicense");let ic="basic";qs&&console.log("License Type: "+ic);function uB(){switch(ic){case"pro":case"enterprise":return!0}return!1}function YJ(){switch(ic){case"indie":return!0}return!1}function Or(){return uB()||YJ()}const r3=[];function TgA(g){if(uB()||YJ())return g(!0);r3.push(g)}function HgA(g){for(const A of r3)try{A(g)}catch{}}Qt.registerCallback(Gt.ContextRegistered,g=>{PgA(g.context),jgA(),OgA(g.context)});let pB,UN=!1,Nu="";async function YgA(){if(pB)return pB;if(ic==="basic")try{const g="https://engine.needle.tools/licensing/check?location="+encodeURIComponent(window.location.href)+"&version="+Hs+"&generator="+encodeURIComponent(Uk),A=await fetch(g,{method:"GET"}).catch(e=>{qs&&console.error("License check failed",e)});(A==null?void 0:A.status)===200?(UN=!1,qs&&console.log("License check succeeded"),ic="pro",HgA(!0)):(A==null?void 0:A.status)===403?(UN=!0,Nu=await A.text()):qs&&console.log("License check failed with status "+(A==null?void 0:A.status))}catch(g){qs&&console.error("License check failed",g)}else qs&&console.log('Runtime license check is skipped because license is already applied as "'+ic+'"')}pB=YgA();async function OgA(g){function A(){const i=document.createElement("div");i.className="needle-forbidden",i.style.cssText=`
4349
4349
  position: fixed;
4350
4350
  top: 0;
@@ -5234,7 +5234,7 @@ a=extmap-allow-mixed`)!==-1){const I=i.sdp.split(`
5234
5234
  isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},g}()),FY={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"},KQA=function(){function g(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=FY,this.browser=cu.getBrowser(),this.browserVersion=cu.getVersion(),this.supports=function(){var A={browser:cu.isBrowserSupported(),webRTC:cu.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!A.webRTC)return A;var e;try{e=new RTCPeerConnection(FY),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=!cu.isIOS}catch{}}catch{}finally{t&&t.close()}}catch{}finally{e&&e.close()}return A}(),this.pack=fY.pack,this.unpack=fY.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/Mt.chunkedMTU),I=0,o=0;o<t;){var s=Math.min(t,o+Mt.chunkedMTU),n=A.slice(o,s),a={__peerData:this._dataCount,n:I,data:n,total:i};e.push(a),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}(),Mt=new KQA,rj={};Ta(rj,"Peer",()=>kb,g=>kb=g);var dD={},JQA=Object.prototype.hasOwnProperty,ho="~";function yf(){}Object.create&&(yf.prototype=Object.create(null),new yf().__proto__||(ho=!1));function xQA(g,A,e){this.fn=g,this.context=A,this.once=e||!1}function Cj(g,A,e,t,i){if(typeof e!="function")throw new TypeError("The listener must be a function");var I=new xQA(e,t||g,i),o=ho?ho+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 s0(g,A){--g._eventsCount===0?g._events=new yf:delete g._events[A]}function LI(){this._events=new yf,this._eventsCount=0}LI.prototype.eventNames=function(){var A=[],e,t;if(this._eventsCount===0)return A;for(t in e=this._events)JQA.call(e,t)&&A.push(ho?t.slice(1):t);return Object.getOwnPropertySymbols?A.concat(Object.getOwnPropertySymbols(e)):A};LI.prototype.listeners=function(A){var e=ho?ho+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};LI.prototype.listenerCount=function(A){var e=ho?ho+A:A,t=this._events[e];return t?t.fn?1:t.length:0};LI.prototype.emit=function(A,e,t,i,I,o){var s=ho?ho+A:A;if(!this._events[s])return!1;var n=this._events[s],a=arguments.length,r,C;if(n.fn){switch(n.once&&this.removeListener(A,n.fn,void 0,!0),a){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,r=new Array(a-1);C<a;C++)r[C-1]=arguments[C];n.fn.apply(n.context,r)}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),a){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(!r)for(c=1,r=new Array(a-1);c<a;c++)r[c-1]=arguments[c];n[C].fn.apply(n[C].context,r)}}return!0};LI.prototype.on=function(A,e,t){return Cj(this,A,e,t,!1)};LI.prototype.once=function(A,e,t){return Cj(this,A,e,t,!0)};LI.prototype.removeListener=function(A,e,t,i){var I=ho?ho+A:A;if(!this._events[I])return this;if(!e)return s0(this,I),this;var o=this._events[I];if(o.fn)o.fn===e&&(!i||o.once)&&(!t||o.context===t)&&s0(this,I);else{for(var s=0,n=[],a=o.length;s<a;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:s0(this,I)}return this};LI.prototype.removeAllListeners=function(A){var e;return A?(e=ho?ho+A:A,this._events[e]&&s0(this,e)):(this._events=new yf,this._eventsCount=0),this};LI.prototype.off=LI.prototype.removeListener;LI.prototype.addListener=LI.prototype.on;LI.prefixed=ho;LI.EventEmitter=LI;dD=LI;var Ee={};Ta(Ee,"LogLevel",()=>yo,g=>yo=g);Ta(Ee,"default",()=>NY,g=>NY=g);var wQ=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},yQ=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))},vQA="PeerJS: ",yo;(function(g){g[g.Disabled=0]="Disabled",g[g.Errors=1]="Errors",g[g.Warnings=2]="Warnings",g[g.All=3]="All"})(yo||(yo={}));var qQA=function(){function g(){this._logLevel=yo.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>=yo.All&&this._print.apply(this,yQ([yo.All],wQ(A),!1))},g.prototype.warn=function(){for(var A=[],e=0;e<arguments.length;e++)A[e]=arguments[e];this._logLevel>=yo.Warnings&&this._print.apply(this,yQ([yo.Warnings],wQ(A),!1))},g.prototype.error=function(){for(var A=[],e=0;e<arguments.length;e++)A[e]=arguments[e];this._logLevel>=yo.Errors&&this._print.apply(this,yQ([yo.Errors],wQ(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=yQ([vQA],wQ(e),!1);for(var I in i)i[I]instanceof Error&&(i[I]="("+i[I].name+") "+i[I].message);A>=yo.All?console.log.apply(console,yQ([],wQ(i),!1)):A>=yo.Warnings?console.warn.apply(console,yQ(["WARNING"],wQ(i),!1)):A>=yo.Errors&&console.error.apply(console,yQ(["ERROR"],wQ(i),!1))},g}(),NY=new qQA,Bj={};Ta(Bj,"Socket",()=>bY,g=>bY=g);var Rn;(function(g){g.Data="data",g.Media="media"})(Rn||(Rn={}));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 wr;(function(g){g.Binary="binary",g.BinaryUTF8="binary-utf8",g.JSON="json"})(wr||(wr={}));var qr;(function(g){g.Message="message",g.Disconnected="disconnected",g.Error="error",g.Close="close"})(qr||(qr={}));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 bx={};bx=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 LQA=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)}}(),_QA=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},TQA=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))},HQA=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.")},bY=function(g){LQA(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 a=e?"wss://":"ws://";return n._baseUrl=a+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="+bx.version),this._disconnected=!1,this._socket.onmessage=function(o){var s;try{s=JSON.parse(o.data),Ee.default.log("Server message received:",s)}catch{Ee.default.log("Invalid server message",o.data);return}i.emit(qr.Message,s)},this._socket.onclose=function(o){i._disconnected||(Ee.default.log("Socket closed.",o),i._cleanup(),i._disconnected=!0,i.emit(qr.Disconnected))},this._socket.onopen=function(){i._disconnected||(i._sendQueuedMessages(),Ee.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()){Ee.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=TQA([],_QA(this._messagesQueue),!1);this._messagesQueue=[];try{for(var I=HQA(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(qr.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}(dD.EventEmitter),Sb={};Ta(Sb,"MediaConnection",()=>xY,g=>xY=g);var Kx={};Ta(Kx,"Negotiator",()=>KY,g=>KY=g);var gm=function(){return gm=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},gm.apply(this,arguments)},Xy=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(r){try{a(t.next(r))}catch(C){o(C)}}function n(r){try{a(t.throw(r))}catch(C){o(C)}}function a(r){r.done?I(r.value):i(r.value).then(s,n)}a((t=t.apply(g,A||[])).next())})},$y=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(a){return function(r){return n([a,r])}}function n(a){if(t)throw new TypeError("Generator is already executing.");for(;e;)try{if(t=1,i&&(I=a[0]&2?i.return:a[0]?i.throw||((I=i.return)&&I.call(i),0):i.next)&&!(I=I.call(i,a[1])).done)return I;switch(i=0,I&&(a=[a[0]&2,I.value]),a[0]){case 0:case 1:I=a;break;case 4:return e.label++,{value:a[1],done:!1};case 5:e.label++,i=a[1],a=[0];continue;case 7:a=e.ops.pop(),e.trys.pop();continue;default:if(I=e.trys,!(I=I.length>0&&I[I.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!I||a[1]>I[0]&&a[1]<I[3])){e.label=a[1];break}if(a[0]===6&&e.label<I[1]){e.label=I[1],I=a;break}if(I&&e.label<I[2]){e.label=I[2],e.ops.push(a);break}I[2]&&e.ops.pop(),e.trys.pop();continue}a=A.call(g,e)}catch(r){a=[6,r],i=0}finally{t=I=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},KY=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===Rn.Media&&A._stream&&this._addTracksToConnection(A._stream,e),A.originator){if(this.connection.type===Rn.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(){Ee.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;Ee.default.log("Listening for ICE candidates."),A.onicecandidate=function(s){!s.candidate||!s.candidate.candidate||(Ee.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":Ee.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":Ee.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":Ee.default.log("iceConnectionState changed to disconnected on the connection with "+t);break;case"completed":A.onicecandidate=Mt.noop;break}e.connection.emit("iceStateChanged",A.iceConnectionState)},Ee.default.log("Listening for data channel"),A.ondatachannel=function(s){Ee.default.log("Received data channel");var n=s.channel,a=o.getConnection(t,i);a.initialize(n)},Ee.default.log("Listening for remote stream"),A.ontrack=function(s){Ee.default.log("Received remote stream");var n=s.streams[0],a=o.getConnection(t,i);if(a.type===Rn.Media){var r=a;e._addStreamToMediaConnection(n,r)}}},g.prototype.cleanup=function(){Ee.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===Rn.Data){var i=this.connection,I=i.dataChannel;I&&(t=!!I.readyState&&I.readyState!=="closed")}(e||t)&&A.close()}},g.prototype._makeOffer=function(){return Xy(this,void 0,Promise,function(){var A,e,t,i,I,o,s;return $y(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(),Ee.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(),Ee.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:Mt.browser},this.connection.type===Rn.Data&&(I=this.connection,i=gm(gm({},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),Ee.default.log("Failed to setLocalDescription, ",o)),[3,6];case 6:return[3,8];case 7:return s=n.sent(),e.emitError(eg.WebRTC,s),Ee.default.log("Failed to createOffer, ",s),[3,8];case 8:return[2]}})})},g.prototype._makeAnswer=function(){return Xy(this,void 0,Promise,function(){var A,e,t,i,I;return $y(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(),Ee.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(),Ee.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:Mt.browser},dst:this.connection.peer}),[3,6];case 5:return i=o.sent(),e.emitError(eg.WebRTC,i),Ee.default.log("Failed to setLocalDescription, ",i),[3,6];case 6:return[3,8];case 7:return I=o.sent(),e.emitError(eg.WebRTC,I),Ee.default.log("Failed to create answer, ",I),[3,8];case 8:return[2]}})})},g.prototype.handleSDP=function(A,e){return Xy(this,void 0,Promise,function(){var t,i,I,o;return $y(this,function(s){switch(s.label){case 0:e=new RTCSessionDescription(e),t=this.connection.peerConnection,i=this.connection.provider,Ee.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(),Ee.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),Ee.default.log("Failed to setRemoteDescription, ",o),[3,6];case 6:return[2]}})})},g.prototype.handleCandidate=function(A){return Xy(this,void 0,Promise,function(){var e,t,i,I,o,s;return $y(this,function(n){switch(n.label){case 0:Ee.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(),Ee.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return s=n.sent(),o.emitError(eg.WebRTC,s),Ee.default.log("Failed to handleCandidate, ",s),[3,4];case 4:return[2]}})})},g.prototype._addTracksToConnection=function(A,e){if(Ee.default.log("add tracks from stream ".concat(A.id," to peer connection")),!e.addTrack)return Ee.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){Ee.default.log("add stream ".concat(A.id," to media connection ").concat(e.connectionId)),e.addStream(A)},g}(),Jx={};Ta(Jx,"BaseConnection",()=>JY,g=>JY=g);var YQA=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)}}(),JY=function(g){YQA(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}(dD.EventEmitter),OQA=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)}}(),Im=function(){return Im=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},Im.apply(this,arguments)},PQA=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.")},xY=function(g){OQA(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+Mt.randomToken(),I._negotiator=new Kx.Negotiator(I),I._localStream&&I._negotiator.startConnection({_stream:I._localStream,originator:!0}),I}return Object.defineProperty(A.prototype,"type",{get:function(){return Rn.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){Ee.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:Ee.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){Ee.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(Im(Im({},this.options._payload),{_stream:e}));var o=this.provider._getMessages(this.connectionId);try{for(var s=PQA(o),n=s.next();!n.done;n=s.next()){var a=n.value;this.handleMessage(a)}}catch(r){i={error:r}}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}(Jx.BaseConnection),mb={};Ta(mb,"DataConnection",()=>qY,g=>qY=g);var Qj={};Ta(Qj,"EncodingQueue",()=>vY,g=>vY=g);var WQA=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)}}(),vY=function(g){WQA(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){Ee.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}(dD.EventEmitter),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)}}(),ZQA=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.")},qY=function(g){jQA(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 Qj.EncodingQueue,I.connectionId=I.options.connectionId||A.ID_PREFIX+Mt.randomToken(),I.label=I.options.label||I.connectionId,I.serialization=I.options.serialization||wr.Binary,I.reliable=!!I.options.reliable,I._encodingQueue.on("done",function(o){I._bufferedSend(o)}),I._encodingQueue.on("error",function(){Ee.default.error("DC#".concat(I.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),I.close()}),I._negotiator=new Kx.Negotiator(I),I._negotiator.startConnection(I.options._payload||{originator:!0}),I}return Object.defineProperty(A.prototype,"type",{get:function(){return Rn.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;(!Mt.supports.binaryBlob||Mt.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){Ee.default.log("DC#".concat(e.connectionId," dc connection success")),e._open=!0,e.emit("open")},this.dataChannel.onmessage=function(t){Ee.default.log("DC#".concat(e.connectionId," dc onmessage:"),t.data),e._handleDataMessage(t)},this.dataChannel.onclose=function(){Ee.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===wr.Binary||this.serialization===wr.BinaryUTF8,s=i;if(o){if(I===Blob){Mt.blobToArrayBuffer(i,function(a){var r=Mt.unpack(a);t.emit("data",r)});return}else if(I===ArrayBuffer)s=Mt.unpack(i);else if(I===String){var n=Mt.binaryStringToArrayBuffer(i);s=Mt.unpack(n)}}else this.serialization===wr.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===wr.JSON)this._bufferedSend(this.stringify(e));else if(this.serialization===wr.Binary||this.serialization===wr.BinaryUTF8){var i=Mt.pack(e);if(!t&&i.size>Mt.chunkedMTU){this._sendChunks(i);return}Mt.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 Ee.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=Mt.chunk(e);Ee.default.log("DC#".concat(this.connectionId," Try to send ").concat(I.length," chunks..."));try{for(var o=ZQA(I),s=o.next();!s.done;s=o.next()){var n=s.value;this.send(n,!0)}}catch(a){t={error:a}}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:Ee.default.warn("Unrecognized message type:",e.type,"from peer:",this.peer);break}},A.ID_PREFIX="dc_",A.MAX_BUFFERED_AMOUNT=8388608,A}(Jx.BaseConnection),cj={};Ta(cj,"API",()=>TY,g=>TY=g);var LY=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(r){try{a(t.next(r))}catch(C){o(C)}}function n(r){try{a(t.throw(r))}catch(C){o(C)}}function a(r){r.done?I(r.value):i(r.value).then(s,n)}a((t=t.apply(g,A||[])).next())})},_Y=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(a){return function(r){return n([a,r])}}function n(a){if(t)throw new TypeError("Generator is already executing.");for(;e;)try{if(t=1,i&&(I=a[0]&2?i.return:a[0]?i.throw||((I=i.return)&&I.call(i),0):i.next)&&!(I=I.call(i,a[1])).done)return I;switch(i=0,I&&(a=[a[0]&2,I.value]),a[0]){case 0:case 1:I=a;break;case 4:return e.label++,{value:a[1],done:!1};case 5:e.label++,i=a[1],a=[0];continue;case 7:a=e.ops.pop(),e.trys.pop();continue;default:if(I=e.trys,!(I=I.length>0&&I[I.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!I||a[1]>I[0]&&a[1]<I[3])){e.label=a[1];break}if(a[0]===6&&e.label<I[1]){e.label=I[1],I=a;break}if(I&&e.label<I[2]){e.label=I[2],e.ops.push(a);break}I[2]&&e.ops.pop(),e.trys.pop();continue}a=A.call(g,e)}catch(r){a=[6,r],i=0}finally{t=I=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}},TY=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",bx.version),fetch(n.href,{referrerPolicy:this._options.referrerPolicy})},g.prototype.retrieveId=function(){return LY(this,void 0,Promise,function(){var A,e,t;return _Y(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(),Ee.default.error("Error retrieving ID",e),t="",this._options.path==="/"&&this._options.host!==Mt.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 LY(this,void 0,Promise,function(){var A,e,t;return _Y(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===Mt.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(),Ee.default.error("Error retrieving list peers",t),new Error("Could not get list peers from the server."+t);case 3:return[2]}})})},g}(),VQA=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)}}(),Rp=function(){return Rp=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},Rp.apply(this,arguments)},Eu=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.")},zQA=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},kb=function(g){VQA(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=Rp({debug:0,host:Mt.CLOUD_HOST,port:Mt.CLOUD_PORT,path:"/",key:A.DEFAULT_KEY,token:Mt.randomToken(),config:Mt.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!==Mt.CLOUD_HOST?i._options.secure=Mt.isSecure():i._options.host==Mt.CLOUD_HOST&&(i._options.secure=!0),i._options.logFunction&&Ee.default.setLogFunction(i._options.logFunction),Ee.default.logLevel=i._options.debug||0,i._api=new cj.API(t),i._socket=i._createServerConnection(),!Mt.supports.audioVideo&&!Mt.supports.data?(i._delayedAbort(eg.BrowserIncompatible,"The current browser does not support WebRTC"),i):I&&!Mt.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=Eu(this._connections),o=I.next();!o.done;o=I.next()){var s=zQA(o.value,2),n=s[0],a=s[1];i[n]=a}}catch(r){e={error:r}}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 Bj.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return t.on(qr.Message,function(i){e._handleMessage(i)}),t.on(qr.Error,function(i){e._abort(eg.SocketError,i)}),t.on(qr.Disconnected,function(){e.disconnected||(e.emitError(eg.Network,"Lost connection to server."),e.disconnect())}),t.on(qr.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:Ee.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,d=this.getConnection(s,E);if(d&&(d.close(),Ee.default.warn("Offer received for existing Connection ID:".concat(E))),o.type===Rn.Media){var n=new Sb.MediaConnection(s,this,{connectionId:E,_payload:o,metadata:o.metadata});d=n,this._addConnection(s,d),this.emit("call",n)}else if(o.type===Rn.Data){var a=new mb.DataConnection(s,this,{connectionId:E,_payload:o,metadata:o.metadata,label:o.label,serialization:o.serialization,reliable:o.reliable});d=a,this._addConnection(s,d),this.emit("connection",a)}else{Ee.default.warn("Received malformed connection type:".concat(o.type));return}var r=this._getMessages(E);try{for(var C=Eu(r),Q=C.next();!Q.done;Q=C.next()){var c=Q.value;d.handleMessage(c)}}catch(h){t={error:h}}finally{try{Q&&!Q.done&&(i=C.return)&&i.call(C)}finally{if(t)throw t.error}}break;default:if(!o){Ee.default.warn("You received a malformed message from ".concat(s," of type ").concat(I));return}var E=o.connectionId,d=this.getConnection(s,E);d&&d.peerConnection?d.handleMessage(e):E?this._storeMessage(E,e):Ee.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){Ee.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 mb.DataConnection(e,this,t);return this._addConnection(e,i),i},A.prototype.call=function(e,t,i){if(i===void 0&&(i={}),this.disconnected){Ee.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){Ee.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var I=new Sb.MediaConnection(e,this,Rp(Rp({},i),{_stream:t}));return this._addConnection(e,I),I},A.prototype._addConnection=function(e,t){Ee.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=Eu(o),n=s.next();!n.done;n=s.next()){var a=n.value;if(a.connectionId===t)return a}}catch(r){i={error:r}}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){Ee.default.error("Aborting!"),this.emitError(e,t),this._lastServerId?this.disconnect():this.destroy()},A.prototype.emitError=function(e,t){Ee.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||(Ee.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=Eu(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=Eu(I),s=o.next();!s.done;s=o.next()){var n=s.value;n.close()}}catch(a){t={error:a}}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;Ee.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)Ee.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)Ee.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}(dD.EventEmitter),Gb=rj.Peer;const XQA=Object.freeze(Object.defineProperty({__proto__:null,get Peer(){return kb},default:Gb,util:Mt},Symbol.toStringTag,{value:"Module"}));let xx;function $QA(){return xx}function AcA(g){xx=g}function Ej(g,A){return A||(A={}),A={...xx,...A},g?new Gb(g,A):new Gb(A)}async function HY(){const g=await Promise.resolve().then(()=>XQA);return console.log(g),g.default===void 0?g:g.default}class hj{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 HY(),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 tcA(t)})}async trySetupClient(A){const e=await HY();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 ecA{constructor(A){B(this,"_peer");this._peer=A}}class tcA extends ecA{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 YY="https://urls.needle.tools/default-networking-backend/index";let LC="wss://needle-tiny-starter.glitch.me/socket";const go=!!gA("debugnet"),Zu=!!(go||gA("debugowner")),OY=gA("debugnetbin");var lj=(g=>(g.ConnectionInfo="connection-start-info",g))(lj||{}),nt=(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))(nt||{});class icA{constructor(){B(this,"room");B(this,"viewId");B(this,"allowEditing");B(this,"inRoom")}}class gcA{constructor(){B(this,"room")}}class IcA{constructor(){B(this,"userId")}}var dj=(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))(dj||{});class vx{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||(Zu&&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 Zu&&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?(Zu&&console.log("GAINED OWNERSHIP",this.guid),this._hasOwnership=!0):this._hasOwnership=!1)}onLostOwnership(A){A===this.guid&&(Zu&&console.log("LOST OWNERSHIP",this.guid),this._hasOwnership=!1,this._isOwned=!1)}}class uj{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 hj),this._peer}tryGetState(A){return A==="invalid"?null:this._state[A]}get connectionId(){return this._connectionId}get isDebugEnabled(){return go}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(),go&&console.log("join: "+A),this.send("join-room",{room:A,viewOnly:e},Js.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=Js.Queued){if(e===null&&(e={}),t===Js.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;OY&&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,Js.Immediate);break}const o=this.toMessage(I.key,I.value);this._defaultMessagesBufferArray.push(o)}if(this._defaultMessagesBuffer.length=0,this._defaultMessagesBufferArray.length>0&&go&&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);go&&console.log("connecting");const A=(e=this.netWebSocketUrlProvider)==null?void 0:e.getWebsocketUrl();return A?LC=A:PP()&&(LC="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 n;let t=!1;const i=a=>{t||(t=!0,A(a))};if(LC===void 0&&(console.log("Fetch default backend url: "+YY),LC=await(await fetch(YY)).text()),LC===void 0){i(!1);return}console.log(`⊡ Connecting to networking backend on
5235
5235
  `+LC);const I=await Promise.resolve().then(()=>yyA),o=((n=I.default)==null?void 0:n.WebsocketBuilder)??I.WebsocketBuilder,s=new o(LC).onOpen(()=>{this._connectingToWebsocketPromise=null,this._ws=s,this.connected=!0,console.log(`⊞ Connected to networking backend
5236
5236
  `+LC),i(!0),this.onSendQueued(Js.OnConnection)}).onClose(a=>{this._connectingToWebsocketPromise=null,this.connected=!1,this._isInRoom=!1,i(!1)}).onError((a,r)=>{console.error("⊠ Websocket error",a,r),i(!1)}).onRetry(()=>{console.log("Retry connecting to networking websocket")}).build();s.addEventListener(I.WebsocketEvent.message,(a,r)=>{this.onMessage(a,r)})})}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){go&&t==="pong"?console.log("<<",t):Ce()&&console.error("Failed to parse message",i)}}async handleIncomingBinaryMessage(A){OY&&console.log("<< bin",this.context.time.frame);const e=await A.arrayBuffer();var t=new Uint8Array(e);const i=new wf(t),I=i.getBufferIdentifier(),o=this._listenersBinary[I],s=yW(i),n=SW(s);if(n&&typeof n=="string"&&(this._state[n]=s),!o)return;const a=s??i;for(const r of o)r(a)}handleIncomingStringMessage(A){var i,I;if(go&&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(go&&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),go&&console.log("joined room with",this._currentInRoom,this.context.alias??"");const a=new URL(window.location.href);a.searchParams.has("room")&&a.searchParams.delete("room"),a.searchParams.set("view",this._currentRoomViewId),console.log("Room view id: "+this._currentRoomViewId+`
5237
- `+a.href)}this.onSendQueued(Js.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),go&&console.log(n.userId+" joined","now in room:",this._currentInRoom)}break;case"user-left-room":if(A.data){const n=A.data,a=this._currentInRoom.indexOf(n.userId);a>=0&&(go&&console.log(n.userId+" left","now in room:",this._currentInRoom),this._currentInRoom.splice(a,1)),n.userId===this.connectionId&&console.log("you left the room")}break;case"all-room-state-deleted":go&&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),go&&console.log("Current latency: "+this._currentDelay.toFixed(1)+" sec","Clients in room: "+((I=this._currentInRoom)==null?void 0:I.length));break}let e=this._listeners[A.key];if(e){e=[...e];for(const o of e)try{o(A.data)}catch(s){console.error('Error invoking callback for "'+A.key+'"',s)}}const t=A.data;t&&(this._state[t.guid]=t)}toMessage(A,e){return{key:A,data:e}}sendWithWebsocket(A,e,t=Js.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));go&&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 Up=gA("debugwebxr");class NU{constructor(A,e){B(this,"controllerStates",[]);B(this,"userId");B(this,"context");B(this,"userStateEvtName");B(this,"onReceivedControllerState",A=>{Up&&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||(Up&&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),Up&&console.log(`XRSync: ${t.type} ${t.handedness} added`,t.index)}}}class pj{constructor(A){B(this,"context");B(this,"onJoinedRoom",()=>{if(this.context.connection.connectionId){this._states.has(this.context.connection.connectionId)||(Up&&console.log("XRSync: Local user joined room",this.context.connection.connectionId),this._states.set(this.context.connection.connectionId,new NU(this.context.connection.connectionId,this.context)));for(const A of this.context.connection.usersInRoom())this._states.has(A)||this._states.set(A,new NU(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)||(Up&&console.log("XRSync: Remote user joined room",e),this._states.set(e,new NU(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(nt.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(nt.LeftRoom,this.onLeftRoom),this.context.connection.beginListen(nt.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.beginListen(nt.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(nt.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(nt.LeftRoom,this.onLeftRoom),this.context.connection.stopListen(nt.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.stopListen(nt.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 PY{constructor(){B(this,"_fadeToColorQuad");B(this,"_fadeToColorMaterial");B(this,"_requestedFadeValue",0);B(this,"_transitionPromise",null);B(this,"_transitionResolve",null);this._fadeToColorMaterial=new It({color:0,transparent:!0,depthTest:!1,fog:!1,side:yt}),this._fadeToColorQuad=new dA(new dg(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=ie.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 Fc=(g=>(g[g.Quad=0]="Quad",g[g.Cube=1]="Cube",g[g.Sphere=2]="Sphere",g))(Fc||{});class uD{static createPrimitive(A,e){let t;switch(A){case"Quad":case 0:{const I=new dg(1,1,1,1),o=(e==null?void 0:e.material)??new vI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new dA(I,o)}break;case"Cube":case 1:{const I=new ti(1,1,1),o=(e==null?void 0:e.material)??new vI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new dA(I,o)}break;case"Sphere":case 2:{const I=new Hn(.5,16,16),o=(e==null?void 0:e.material)??new vI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new dA(I,o)}break}return this.applyDefaultObjectOptions(t,e),t}static createSprite(A){const t=new Ak({color:16777215});A!=null&&A.texture&&"map"in t&&(t.map=A.texture);const i=new NK(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 _q=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 gC({alpha:!0}),this._renderer.setAnimationLoop(this.onFrame),this._renderer.xr.setSession(t),this._renderer.xr.enabled=!0,this._camera=new Le,this._scene=new EI,this._scene.fog=new $m(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 _q(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 Ka(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 Ka(1e3),this._scene.clear()}setupScene(){this._scene.background=new wA(0),this._scene.add(new wk(5,10,1118481,1118481));const A=new yc(16777215,1);A.position.set(0,20,0),A.castShadow=!1,this._scene.add(A);const e=new yc(16777215,1);e.position.set(0,-1,0),e.castShadow=!1,this._scene.add(e);const t=new wc(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 vI({color:2236962,metalness:1,roughness:.8});this.isAR&&(o.emissive=new wA(Math.random(),Math.random(),Math.random()),o.emissiveIntensity=Math.random());const s=ie.random(0,1)>.5?Fc.Sphere:Fc.Cube,n=uD.createPrimitive(s,{material:o});n.position.x=ie.random(-i,i),n.position.y=ie.random(-2,i),n.position.z=ie.random(-i,i),n.rotation.x=ie.random(0,Math.PI*2),n.rotation.y=ie.random(0,Math.PI*2),n.rotation.z=ie.random(0,Math.PI*2),n.scale.multiplyScalar(.5+Math.random()*10);const a=n.position.distanceTo(this._camera.position)-n.scale.x;a<1&&n.position.multiplyScalar(1+1/a),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 BB=_q;B(BB,"_active",null),B(BB,"_requestInFlight",!1);const Jg=gA("debugwebxr"),ocA=gA("stats");function scA(g){let A=null;const e=g;return e.getAROverlayContainer?A=e.getAROverlayContainer():A=g,A}ncA();async function ncA(){var g;if(gA("debugasap")){let A=globalThis["needle:XRSession"];if(A instanceof Promise){delete globalThis["needle:XRSession"],Qt.addContextCreatedCallback(async e=>{if(!A)return;yl(!0);const t=await A;if(t){const i=me.getDefaultSessionInit("immersive-vr");me.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()=>{yl(!0),console.log("Received Session Granted..."),await Ka(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(fj()&&(await BB.start(A||"immersive-vr",t||me.getDefaultSessionInit("immersive-vr")),await CcA(),i=await BB.handoff()),i)me.setSession(i.mode,i.session,i.init,Ke.Current);else if(A&&e){console.log("Session Granted: Restore last session");const I=JSON.parse(e);me.start(A,I).catch(o=>console.warn(o))}else me.start("immersive-vr").catch(I=>console.warn("Session Granted failed:",I))},{once:!0})}}function acA(g,A){sessionStorage.setItem("needle_xr_session_mode",g),sessionStorage.setItem("needle_xr_session_init",JSON.stringify(A))}function rcA(){sessionStorage.removeItem("needle_xr_session_mode"),sessionStorage.removeItem("needle_xr_session_init")}const qx=new Set;Qt.registerCallback(Gt.ContextCreationStart,async g=>{qx.add(g.context)});Qt.registerCallback(Gt.ContextCreated,async g=>{qx.delete(g.context)});function fj(){return qx.size>0}function CcA(){return new Promise(g=>{const A=Date.now(),e=setInterval(()=>{(!fj()||Date.now()-A>6e4)&&(clearInterval(e),g())},100)})}Sc()&&Ce()&&window.addEventListener("keydown",g=>{(g.key==="x"||g.key==="Escape")&&me.active&&me.stop()});const Sr=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 Mx(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"),rcA(),this.onAfterRender(),this.revertCustomForward(),this._didStart=!1,this._previousCameraParent=null,YB(this.onBefore,gi.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()}),fW({session:this});for(const s of Sr._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&&qI(this.context.mainCamera,this._originalCameraWorldPosition),this._originalCameraWorldRotation&&Zs(this.context.mainCamera,this._originalCameraWorldRotation),this._originalCameraWorldScale&&cf(this.context.mainCamera,this._originalCameraWorldScale)),this.context.requestSizeUpdate(),this._defaultRig.gameObject.removeFromParent(),yl(!1)});B(this,"_didStart",!1);B(this,"onBefore",A=>{var i,I,o,s,n,a,r,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||((a=E.supportsXR)==null?void 0:a.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 d of this.controllers)this.invokeCallback_ControllerAdded(E,d)}}}}else{this._didStart=!0,pW({session:this});for(const c of Sr._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&&((r=c.onLeaveXR)==null||r.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(),Sc()){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 MA);B(this,"_transformPosition",new m);B(this,"_transition");var I,o;acA(A,i.init),this.session=e,this.mode=A,this.context=t,(Jg||gA("console"))&&yl(!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,HB(this.onBefore,gi.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,a;return(a=(n=e.requestHitTestSource)==null?void 0:n.call(e,{space:s}))==null?void 0:a.then(r=>this._viewerHitTestSource=r)}).catch(s=>console.warn(s)),this.context.mainCamera&&(this._originalCameraWorldPosition=Te(this.context.mainCamera,new m),this._originalCameraWorldRotation=Ht(this.context.mainCamera,new MA),this._originalCameraWorldScale=ni(this.context.mainCamera,new m),this._originalCameraParent=this.context.mainCamera.parent),this._defaultRig=new cQA,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 pj(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=>Sr.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,a;if(Ce()&&gA("debugxrpreroom"))return console.warn("Debug: Starting temporary XR session"),await BB.start(A,e||Sr.getDefaultSessionInit(A)),null;if(this._currentSessionRequest)return console.warn("A XRSession is already being requested"),(Jg||Ce())&&Vt("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=Ke.Current),t||(t=Qt.All[0]),!t)throw new Error("No Needle Engine Context found");switch(e||(e={}),e.optionalFeatures??(e.optionalFeatures=[]),e.requiredFeatures??(e.requiredFeatures=[]),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=scA(t.domElement);Q&&!Sk()&&(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}await BB.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 r of i)r.onBeforeXR&&r.onBeforeXR(A,e);for(const r of this._sessionRequestStartListeners)r({mode:A,init:e});Jg&&Ri("Requesting "+A+" session ("+Date.now()+")"),this._currentSessionRequest=(n=navigator.xr)==null?void 0:n.requestSession(A,e),this._currentSessionRequestMode=A;const I=await((a=this._currentSessionRequest)==null?void 0:a.catch(r=>{console.error(r,"Code: "+r.code),r.code===9&&Vt("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:"&&Vt("XR requires a secure connection (HTTPS)")}));this._currentSessionRequest=void 0,this._currentSessionRequestMode=null;for(const r of this._sessionRequestEndListeners)r({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 Sr(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 Sr._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")||Ce()&&Sc()&&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&&Nc(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(Nc(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=Pi(t.transform.position),I=WQ(t.transform.orientation),o=this.context.mainCamera;if((o==null?void 0:o.parent)!==this._cameraRenderParent&&i.applyMatrix4(im),o!=null&&o.parent){i.applyMatrix4(o.parent.matrixWorld),I.multiply(Ns);const s=Ht(o.parent);s.premultiply(Ns),I.premultiply(s)}return{hit:A,position:i,quaternion:I}}return null}convertSpace(A){const e=Pi(A.position);e.applyMatrix4(im);const t=WQ(A.orientation);return t.premultiply(Ns),{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||ocA)&&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+=`
5237
+ `+a.href)}this.onSendQueued(Js.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),go&&console.log(n.userId+" joined","now in room:",this._currentInRoom)}break;case"user-left-room":if(A.data){const n=A.data,a=this._currentInRoom.indexOf(n.userId);a>=0&&(go&&console.log(n.userId+" left","now in room:",this._currentInRoom),this._currentInRoom.splice(a,1)),n.userId===this.connectionId&&console.log("you left the room")}break;case"all-room-state-deleted":go&&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),go&&console.log("Current latency: "+this._currentDelay.toFixed(1)+" sec","Clients in room: "+((I=this._currentInRoom)==null?void 0:I.length));break}let e=this._listeners[A.key];if(e){e=[...e];for(const o of e)try{o(A.data)}catch(s){console.error('Error invoking callback for "'+A.key+'"',s)}}const t=A.data;t&&(this._state[t.guid]=t)}toMessage(A,e){return{key:A,data:e}}sendWithWebsocket(A,e,t=Js.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));go&&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 Up=gA("debugwebxr");class NU{constructor(A,e){B(this,"controllerStates",[]);B(this,"userId");B(this,"context");B(this,"userStateEvtName");B(this,"onReceivedControllerState",A=>{Up&&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||(Up&&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),Up&&console.log(`XRSync: ${t.type} ${t.handedness} added`,t.index)}}}class pj{constructor(A){B(this,"context");B(this,"onJoinedRoom",()=>{if(this.context.connection.connectionId){this._states.has(this.context.connection.connectionId)||(Up&&console.log("XRSync: Local user joined room",this.context.connection.connectionId),this._states.set(this.context.connection.connectionId,new NU(this.context.connection.connectionId,this.context)));for(const A of this.context.connection.usersInRoom())this._states.has(A)||this._states.set(A,new NU(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)||(Up&&console.log("XRSync: Remote user joined room",e),this._states.set(e,new NU(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(nt.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(nt.LeftRoom,this.onLeftRoom),this.context.connection.beginListen(nt.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.beginListen(nt.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(nt.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(nt.LeftRoom,this.onLeftRoom),this.context.connection.stopListen(nt.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.stopListen(nt.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 PY{constructor(){B(this,"_fadeToColorQuad");B(this,"_fadeToColorMaterial");B(this,"_requestedFadeValue",0);B(this,"_transitionPromise",null);B(this,"_transitionResolve",null);this._fadeToColorMaterial=new It({color:0,transparent:!0,depthTest:!1,fog:!1,side:yt}),this._fadeToColorQuad=new dA(new dg(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=ie.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 Fc=(g=>(g[g.Quad=0]="Quad",g[g.Cube=1]="Cube",g[g.Sphere=2]="Sphere",g))(Fc||{});class uD{static createPrimitive(A,e){let t;switch(A){case"Quad":case 0:{const I=new dg(1,1,1,1),o=(e==null?void 0:e.material)??new vI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new dA(I,o)}break;case"Cube":case 1:{const I=new ti(1,1,1),o=(e==null?void 0:e.material)??new vI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new dA(I,o)}break;case"Sphere":case 2:{const I=new Hn(.5,16,16),o=(e==null?void 0:e.material)??new vI({color:16777215});e!=null&&e.texture&&"map"in o&&(o.map=e.texture),t=new dA(I,o)}break}return this.applyDefaultObjectOptions(t,e),t}static createSprite(A){const t=new Ak({color:16777215});A!=null&&A.texture&&"map"in t&&(t.map=A.texture);const i=new NK(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 _q=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 gC({alpha:!0}),this._renderer.setAnimationLoop(this.onFrame),this._renderer.xr.setSession(t),this._renderer.xr.enabled=!0,this._camera=new Le,this._scene=new EI,this._scene.fog=new $m(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 _q(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 Ka(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 Ka(1e3),this._scene.clear()}setupScene(){this._scene.background=new wA(0),this._scene.add(new wk(5,10,1118481,1118481));const A=new yc(16777215,1);A.position.set(0,20,0),A.castShadow=!1,this._scene.add(A);const e=new yc(16777215,1);e.position.set(0,-1,0),e.castShadow=!1,this._scene.add(e);const t=new wc(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 vI({color:2236962,metalness:1,roughness:.8});this.isAR&&(o.emissive=new wA(Math.random(),Math.random(),Math.random()),o.emissiveIntensity=Math.random());const s=ie.random(0,1)>.5?Fc.Sphere:Fc.Cube,n=uD.createPrimitive(s,{material:o});n.position.x=ie.random(-i,i),n.position.y=ie.random(-2,i),n.position.z=ie.random(-i,i),n.rotation.x=ie.random(0,Math.PI*2),n.rotation.y=ie.random(0,Math.PI*2),n.rotation.z=ie.random(0,Math.PI*2),n.scale.multiplyScalar(.5+Math.random()*10);const a=n.position.distanceTo(this._camera.position)-n.scale.x;a<1&&n.position.multiplyScalar(1+1/a),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 BB=_q;B(BB,"_active",null),B(BB,"_requestInFlight",!1);const Jg=gA("debugwebxr"),ocA=gA("stats");function scA(g){let A=null;const e=g;return e.getAROverlayContainer?A=e.getAROverlayContainer():A=g,A}ncA();async function ncA(){var g;if(gA("debugasap")){let A=globalThis["needle:XRSession"];if(A instanceof Promise){delete globalThis["needle:XRSession"],Qt.addContextCreatedCallback(async e=>{if(!A)return;yl(!0);const t=await A;if(t){const i=me.getDefaultSessionInit("immersive-vr");me.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()=>{yl(!0),console.log("Received Session Granted..."),await Ka(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(fj()&&(await BB.start(A||"immersive-vr",t||me.getDefaultSessionInit("immersive-vr")),await CcA(),i=await BB.handoff()),i)me.setSession(i.mode,i.session,i.init,Ke.Current);else if(A&&e){console.log("Session Granted: Restore last session");const I=JSON.parse(e);me.start(A,I).catch(o=>console.warn(o))}else me.start("immersive-vr").catch(I=>console.warn("Session Granted failed:",I))},{once:!0})}}function acA(g,A){sessionStorage.setItem("needle_xr_session_mode",g),sessionStorage.setItem("needle_xr_session_init",JSON.stringify(A))}function rcA(){sessionStorage.removeItem("needle_xr_session_mode"),sessionStorage.removeItem("needle_xr_session_init")}const qx=new Set;Qt.registerCallback(Gt.ContextCreationStart,async g=>{qx.add(g.context)});Qt.registerCallback(Gt.ContextCreated,async g=>{qx.delete(g.context)});function fj(){return qx.size>0}function CcA(){return new Promise(g=>{const A=Date.now(),e=setInterval(()=>{(!fj()||Date.now()-A>6e4)&&(clearInterval(e),g())},100)})}Sc()&&Ce()&&window.addEventListener("keydown",g=>{(g.key==="x"||g.key==="Escape")&&me.active&&me.stop()});const Sr=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 Mx(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"),rcA(),this.onAfterRender(),this.revertCustomForward(),this._didStart=!1,this._previousCameraParent=null,YB(this.onBefore,gi.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()}),fW({session:this});for(const s of Sr._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&&qI(this.context.mainCamera,this._originalCameraWorldPosition),this._originalCameraWorldRotation&&Zs(this.context.mainCamera,this._originalCameraWorldRotation),this._originalCameraWorldScale&&cf(this.context.mainCamera,this._originalCameraWorldScale)),this.context.requestSizeUpdate(),this._defaultRig.gameObject.removeFromParent(),yl(!1)});B(this,"_didStart",!1);B(this,"onBefore",A=>{var i,I,o,s,n,a,r,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||((a=E.supportsXR)==null?void 0:a.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 d of this.controllers)this.invokeCallback_ControllerAdded(E,d)}}}}else{this._didStart=!0,pW({session:this});for(const c of Sr._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&&((r=c.onLeaveXR)==null||r.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(),Sc()){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 MA);B(this,"_transformPosition",new m);B(this,"_transition");var I,o;acA(A,i.init),this.session=e,this.mode=A,this.context=t,(Jg||gA("console"))&&yl(!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,HB(this.onBefore,gi.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,a;return(a=(n=e.requestHitTestSource)==null?void 0:n.call(e,{space:s}))==null?void 0:a.then(r=>this._viewerHitTestSource=r)}).catch(s=>console.warn(s)),this.context.mainCamera&&(this._originalCameraWorldPosition=Te(this.context.mainCamera,new m),this._originalCameraWorldRotation=Ht(this.context.mainCamera,new MA),this._originalCameraWorldScale=ni(this.context.mainCamera,new m),this._originalCameraParent=this.context.mainCamera.parent),this._defaultRig=new cQA,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 pj(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=>Sr.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,a;if(Ce()&&gA("debugxrpreroom"))return console.warn("Debug: Starting temporary XR session"),await BB.start(A,e||Sr.getDefaultSessionInit(A)),null;if(this._currentSessionRequest)return console.warn("A XRSession is already being requested"),(Jg||Ce())&&Vt("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=Ke.Current),t||(t=Qt.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=scA(t.domElement);Q&&!Sk()&&(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 BB.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 r of i)r.onBeforeXR&&r.onBeforeXR(A,e);for(const r of this._sessionRequestStartListeners)r({mode:A,init:e});Jg&&Ri("Requesting "+A+" session ("+Date.now()+")"),this._currentSessionRequest=(n=navigator.xr)==null?void 0:n.requestSession(A,e),this._currentSessionRequestMode=A;const I=await((a=this._currentSessionRequest)==null?void 0:a.catch(r=>{console.error(r,"Code: "+r.code),r.code===9&&Vt("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:"&&Vt("XR requires a secure connection (HTTPS)")}));this._currentSessionRequest=void 0,this._currentSessionRequestMode=null;for(const r of this._sessionRequestEndListeners)r({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 Sr(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 Sr._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")||Ce()&&Sc()&&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&&Nc(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(Nc(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=Pi(t.transform.position),I=WQ(t.transform.orientation),o=this.context.mainCamera;if((o==null?void 0:o.parent)!==this._cameraRenderParent&&i.applyMatrix4(im),o!=null&&o.parent){i.applyMatrix4(o.parent.matrixWorld),I.multiply(Ns);const s=Ht(o.parent);s.premultiply(Ns),I.premultiply(s)}return{hit:A,position:i,quaternion:I}}return null}convertSpace(A){const e=Pi(A.position);e.applyMatrix4(im);const t=WQ(A.orientation);return t.premultiply(Ns),{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||ocA)&&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+=`
5238
5238
  ${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=ni(this.rig.gameObject);e*=t.x}this._camera instanceof Le&&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 Le&&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 PY),this._transition}fadeTransition(){return this._transition||(this._transition=new PY),this._transition.fadeTransition()}updateFade(A){this._transition&&A instanceof Le&&this._transition.update(A,this.context.time.deltaTime)}onUpdateFade_PostRender(){var A;(A=this._transition)==null||A.remove()}};let me=Sr;B(me,"_sync",null),B(me,"_currentSessionRequestMode",null),B(me,"_currentSessionRequest"),B(me,"_activeSession"),B(me,"_sessionRequestStartListeners",[]),B(me,"_sessionRequestEndListeners",[]),B(me,"_xrStartListeners",[]),B(me,"_xrEndListeners",[]),B(me,"_controllerAddedListeners",[]),B(me,"_controllerRemovedListeners",[]),B(me,"onEnd",()=>{Jg&&console.log("XR Session ended"),Sr._activeSession=null});const bU=gA("debugwebxr");class Dj{static tryFindAvatarObjects(A,e,t){if(t.head&&t.leftHand&&t.rightHand)return;const i=A.name.toLocaleLowerCase();!t.head&&i.includes("head")&&(bU&&console.log("FOUND AVATAR HEAD",A.name),t.head=new et("",e,A)),i.includes("hand")&&(!t.leftHand&&i.includes("left")&&(bU&&console.log("FOUND AVATAR LEFT HAND",A.name),t.leftHand=new et("",e,A)),!t.rightHand&&i.includes("right")&&(bU&&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 om=(g=>(g.Visible="application-visible",g.Hidden="application-hidden",g.MuteChanged="application-mutechanged",g))(om||{});let sm=!1;const Oh=[];function Ad(){if(sm)return;Ce()&&console.debug("User interaction registered: audio can now be played"),sm=!0;const g=[...Oh];Oh.length=0,g.forEach(A=>A())}document.addEventListener("pointerdown",Ad);document.addEventListener("click",Ad);document.addEventListener("dragstart",Ad);document.addEventListener("touchstart",Ad);document.addEventListener("keydown",Ad);me.onXRSessionStart(()=>{Ad()});const Tq=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 sm}static registerWaitForInteraction(e){if(e!==null){if(sm){e();return}Oh.indexOf(e)===-1&&Oh.push(e)}}static unregisterWaitForInteraction(e){const t=Oh.indexOf(e);t!==-1&&Oh.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 Ra=Tq;B(Ra,"registerWaitForAllowAudio",Tq.registerWaitForInteraction);function*wj(g,A=null){const e=A?A.time:Ke.Current.time,t=e.time;for(;e.time-t<g;)yield}function*BcA(g){for(let A=0;A<g;A++)yield}function*yj(g){let A=!0;for(g.then(()=>A=!1),g.catch(()=>A=!1);A;)yield}class Sf extends ZK{constructor(A){super(A),this.type=Fi}parse(A){const F=Math.pow(2.7182818,2.2);function S(N,_){let $=0;for(let T=0;T<65536;++T)(T==0||N[T>>3]&1<<(T&7))&&(_[$++]=T);const U=$-1;for(;$<65536;)_[$++]=0;return U}function R(N){for(let _=0;_<16384;_++)N[_]={},N[_].len=0,N[_].lit=0,N[_].p=null}const v={l:0,c:0,lc:0};function q(N,_,$,U,T){for(;$<N;)_=_<<8|VA(U,T),$+=8;$-=N,v.l=_>>$&(1<<N)-1,v.c=_,v.lc=$}const K=new Array(59);function Y(N){for(let $=0;$<=58;++$)K[$]=0;for(let $=0;$<65537;++$)K[N[$]]+=1;let _=0;for(let $=58;$>0;--$){const U=_+K[$]>>1;K[$]=_,_=U}for(let $=0;$<65537;++$){const U=N[$];U>0&&(N[$]=U|K[U]++<<6)}}function b(N,_,$,U,T,O){const V=_;let z=0,lA=0;for(;U<=T;U++){if(V.value-_.value>$)return!1;q(6,z,lA,N,V);const cA=v.l;if(z=v.c,lA=v.lc,O[U]=cA,cA==63){if(V.value-_.value>$)throw new Error("Something wrong with hufUnpackEncTable");q(8,z,lA,N,V);let SA=v.l+6;if(z=v.c,lA=v.lc,U+SA>T+1)throw new Error("Something wrong with hufUnpackEncTable");for(;SA--;)O[U++]=0;U--}else if(cA>=59){let SA=cA-59+2;if(U+SA>T+1)throw new Error("Something wrong with hufUnpackEncTable");for(;SA--;)O[U++]=0;U--}}Y(O)}function x(N){return N&63}function L(N){return N>>6}function W(N,_,$,U){for(;_<=$;_++){const T=L(N[_]),O=x(N[_]);if(T>>O)throw new Error("Invalid table entry");if(O>14){const V=U[T>>O-14];if(V.len)throw new Error("Invalid table entry");if(V.lit++,V.p){const z=V.p;V.p=new Array(V.lit);for(let lA=0;lA<V.lit-1;++lA)V.p[lA]=z[lA]}else V.p=new Array(1);V.p[V.lit-1]=_}else if(O){let V=0;for(let z=1<<14-O;z>0;z--){const lA=U[(T<<14-O)+V];if(lA.len||lA.p)throw new Error("Invalid table entry");lA.len=O,lA.lit=_,V++}}}return!0}const Z={c:0,lc:0};function oA(N,_,$,U){N=N<<8|VA($,U),_+=8,Z.c=N,Z.lc=_}const CA={c:0,lc:0};function UA(N,_,$,U,T,O,V,z,lA){if(N==_){U<8&&(oA($,U,T,O),$=Z.c,U=Z.lc),U-=8;let cA=$>>U;if(cA=new Uint8Array([cA])[0],z.value+cA>lA)return!1;const SA=V[z.value-1];for(;cA-- >0;)V[z.value++]=SA}else if(z.value<lA)V[z.value++]=N;else return!1;CA.c=$,CA.lc=U}function IA(N){return N&65535}function pA(N){const _=IA(N);return _>32767?_-65536:_}const GA={a:0,b:0};function vA(N,_){const $=pA(N),T=pA(_),O=$+(T&1)+(T>>1),V=O,z=O-T;GA.a=V,GA.b=z}function jA(N,_){const $=IA(N),U=IA(_),T=$-(U>>1)&65535,O=U+T-32768&65535;GA.a=O,GA.b=T}function OA(N,_,$,U,T,O,V){const z=V<16384,lA=$>T?T:$;let cA=1,SA,KA;for(;cA<=lA;)cA<<=1;for(cA>>=1,SA=cA,cA>>=1;cA>=1;){KA=0;const xA=KA+O*(T-SA),WA=O*cA,XA=O*SA,ee=U*cA,re=U*SA;let ke,St,We,Re;for(;KA<=xA;KA+=XA){let Lt=KA;const ye=KA+U*($-SA);for(;Lt<=ye;Lt+=re){const Pt=Lt+ee,WI=Lt+WA,ci=WI+ee;z?(vA(N[Lt+_],N[WI+_]),ke=GA.a,We=GA.b,vA(N[Pt+_],N[ci+_]),St=GA.a,Re=GA.b,vA(ke,St),N[Lt+_]=GA.a,N[Pt+_]=GA.b,vA(We,Re),N[WI+_]=GA.a,N[ci+_]=GA.b):(jA(N[Lt+_],N[WI+_]),ke=GA.a,We=GA.b,jA(N[Pt+_],N[ci+_]),St=GA.a,Re=GA.b,jA(ke,St),N[Lt+_]=GA.a,N[Pt+_]=GA.b,jA(We,Re),N[WI+_]=GA.a,N[ci+_]=GA.b)}if($&cA){const Pt=Lt+WA;z?vA(N[Lt+_],N[Pt+_]):jA(N[Lt+_],N[Pt+_]),ke=GA.a,N[Pt+_]=GA.b,N[Lt+_]=ke}}if(T&cA){let Lt=KA;const ye=KA+U*($-SA);for(;Lt<=ye;Lt+=re){const Pt=Lt+ee;z?vA(N[Lt+_],N[Pt+_]):jA(N[Lt+_],N[Pt+_]),ke=GA.a,N[Pt+_]=GA.b,N[Lt+_]=ke}}SA=cA,cA>>=1}return KA}function le(N,_,$,U,T,O,V,z,lA){let cA=0,SA=0;const KA=V,xA=Math.trunc(U.value+(T+7)/8);for(;U.value<xA;)for(oA(cA,SA,$,U),cA=Z.c,SA=Z.lc;SA>=14;){const XA=cA>>SA-14&16383,ee=_[XA];if(ee.len)SA-=ee.len,UA(ee.lit,O,cA,SA,$,U,z,lA,KA),cA=CA.c,SA=CA.lc;else{if(!ee.p)throw new Error("hufDecode issues");let re;for(re=0;re<ee.lit;re++){const ke=x(N[ee.p[re]]);for(;SA<ke&&U.value<xA;)oA(cA,SA,$,U),cA=Z.c,SA=Z.lc;if(SA>=ke&&L(N[ee.p[re]])==(cA>>SA-ke&(1<<ke)-1)){SA-=ke,UA(ee.p[re],O,cA,SA,$,U,z,lA,KA),cA=CA.c,SA=CA.lc;break}}if(re==ee.lit)throw new Error("hufDecode issues")}}const WA=8-T&7;for(cA>>=WA,SA-=WA;SA>0;){const XA=_[cA<<14-SA&16383];if(XA.len)SA-=XA.len,UA(XA.lit,O,cA,SA,$,U,z,lA,KA),cA=CA.c,SA=CA.lc;else throw new Error("hufDecode issues")}return!0}function oe(N,_,$,U,T,O){const V={value:0},z=$.value,lA=Qe(_,$),cA=Qe(_,$);$.value+=4;const SA=Qe(_,$);if($.value+=4,lA<0||lA>=65537||cA<0||cA>=65537)throw new Error("Something wrong with HUF_ENCSIZE");const KA=new Array(65537),xA=new Array(16384);R(xA);const WA=U-($.value-z);if(b(N,$,WA,lA,cA,KA),SA>8*(U-($.value-z)))throw new Error("Something wrong with hufUncompress");W(KA,lA,cA,xA),le(KA,xA,N,$,SA,cA,O,T,V)}function j(N,_,$){for(let U=0;U<$;++U)_[U]=N[_[U]]}function HA(N){for(let _=1;_<N.length;_++){const $=N[_-1]+N[_]-128;N[_]=$}}function mA(N,_){let $=0,U=Math.floor((N.length+1)/2),T=0;const O=N.length-1;for(;!(T>O||(_[T++]=N[$++],T>O));)_[T++]=N[U++]}function _A(N){let _=N.byteLength;const $=new Array;let U=0;const T=new DataView(N);for(;_>0;){const O=T.getInt8(U++);if(O<0){const V=-O;_-=V+1;for(let z=0;z<V;z++)$.push(T.getUint8(U++))}else{const V=O;_-=2;const z=T.getUint8(U++);for(let lA=0;lA<V+1;lA++)$.push(z)}}return $}function RA(N,_,$,U,T,O){let V=new DataView(O.buffer);const z=$[N.idx[0]].width,lA=$[N.idx[0]].height,cA=3,SA=Math.floor(z/8),KA=Math.ceil(z/8),xA=Math.ceil(lA/8),WA=z-(KA-1)*8,XA=lA-(xA-1)*8,ee={value:0},re=new Array(cA),ke=new Array(cA),St=new Array(cA),We=new Array(cA),Re=new Array(cA);for(let ye=0;ye<cA;++ye)Re[ye]=_[N.idx[ye]],re[ye]=ye<1?0:re[ye-1]+KA*xA,ke[ye]=new Float32Array(64),St[ye]=new Uint16Array(64),We[ye]=new Uint16Array(KA*64);for(let ye=0;ye<xA;++ye){let Pt=8;ye==xA-1&&(Pt=XA);let WI=8;for(let Dt=0;Dt<KA;++Dt){Dt==KA-1&&(WI=WA);for(let Ze=0;Ze<cA;++Ze)St[Ze].fill(0),St[Ze][0]=T[re[Ze]++],te(ee,U,St[Ze]),Ae(St[Ze],ke[Ze]),ne(ke[Ze]);Je(ke);for(let Ze=0;Ze<cA;++Ze)H(ke[Ze],We[Ze],Dt*64)}let ci=0;for(let Dt=0;Dt<cA;++Dt){const Ze=$[N.idx[Dt]].type;for(let Xg=8*ye;Xg<8*ye+Pt;++Xg){ci=Re[Dt][Xg];for(let za=0;za<SA;++za){const mi=za*64+(Xg&7)*8;V.setUint16(ci+0*2*Ze,We[Dt][mi+0],!0),V.setUint16(ci+1*2*Ze,We[Dt][mi+1],!0),V.setUint16(ci+2*2*Ze,We[Dt][mi+2],!0),V.setUint16(ci+3*2*Ze,We[Dt][mi+3],!0),V.setUint16(ci+4*2*Ze,We[Dt][mi+4],!0),V.setUint16(ci+5*2*Ze,We[Dt][mi+5],!0),V.setUint16(ci+6*2*Ze,We[Dt][mi+6],!0),V.setUint16(ci+7*2*Ze,We[Dt][mi+7],!0),ci+=8*2*Ze}}if(SA!=KA)for(let Xg=8*ye;Xg<8*ye+Pt;++Xg){const za=Re[Dt][Xg]+8*SA*2*Ze,mi=SA*64+(Xg&7)*8;for(let lC=0;lC<WI;++lC)V.setUint16(za+lC*2*Ze,We[Dt][mi+lC],!0)}}}const Lt=new Uint16Array(z);V=new DataView(O.buffer);for(let ye=0;ye<cA;++ye){$[N.idx[ye]].decoded=!0;const Pt=$[N.idx[ye]].type;if($[ye].type==2)for(let WI=0;WI<lA;++WI){const ci=Re[ye][WI];for(let Dt=0;Dt<z;++Dt)Lt[Dt]=V.getUint16(ci+Dt*2*Pt,!0);for(let Dt=0;Dt<z;++Dt)V.setFloat32(ci+Dt*2*Pt,BA(Lt[Dt]),!0)}}}function te(N,_,$){let U,T=1;for(;T<64;)U=_[N.value],U==65280?T=64:U>>8==255?T+=U&255:($[T]=U,T++),N.value++}function Ae(N,_){_[0]=BA(N[0]),_[1]=BA(N[1]),_[2]=BA(N[5]),_[3]=BA(N[6]),_[4]=BA(N[14]),_[5]=BA(N[15]),_[6]=BA(N[27]),_[7]=BA(N[28]),_[8]=BA(N[2]),_[9]=BA(N[4]),_[10]=BA(N[7]),_[11]=BA(N[13]),_[12]=BA(N[16]),_[13]=BA(N[26]),_[14]=BA(N[29]),_[15]=BA(N[42]),_[16]=BA(N[3]),_[17]=BA(N[8]),_[18]=BA(N[12]),_[19]=BA(N[17]),_[20]=BA(N[25]),_[21]=BA(N[30]),_[22]=BA(N[41]),_[23]=BA(N[43]),_[24]=BA(N[9]),_[25]=BA(N[11]),_[26]=BA(N[18]),_[27]=BA(N[24]),_[28]=BA(N[31]),_[29]=BA(N[40]),_[30]=BA(N[44]),_[31]=BA(N[53]),_[32]=BA(N[10]),_[33]=BA(N[19]),_[34]=BA(N[23]),_[35]=BA(N[32]),_[36]=BA(N[39]),_[37]=BA(N[45]),_[38]=BA(N[52]),_[39]=BA(N[54]),_[40]=BA(N[20]),_[41]=BA(N[22]),_[42]=BA(N[33]),_[43]=BA(N[38]),_[44]=BA(N[46]),_[45]=BA(N[51]),_[46]=BA(N[55]),_[47]=BA(N[60]),_[48]=BA(N[21]),_[49]=BA(N[34]),_[50]=BA(N[37]),_[51]=BA(N[47]),_[52]=BA(N[50]),_[53]=BA(N[56]),_[54]=BA(N[59]),_[55]=BA(N[61]),_[56]=BA(N[35]),_[57]=BA(N[36]),_[58]=BA(N[48]),_[59]=BA(N[49]),_[60]=BA(N[57]),_[61]=BA(N[58]),_[62]=BA(N[62]),_[63]=BA(N[63])}function ne(N){const _=.5*Math.cos(.7853975),$=.5*Math.cos(3.14159/16),U=.5*Math.cos(3.14159/8),T=.5*Math.cos(3*3.14159/16),O=.5*Math.cos(5*3.14159/16),V=.5*Math.cos(3*3.14159/8),z=.5*Math.cos(7*3.14159/16),lA=new Array(4),cA=new Array(4),SA=new Array(4),KA=new Array(4);for(let xA=0;xA<8;++xA){const WA=xA*8;lA[0]=U*N[WA+2],lA[1]=V*N[WA+2],lA[2]=U*N[WA+6],lA[3]=V*N[WA+6],cA[0]=$*N[WA+1]+T*N[WA+3]+O*N[WA+5]+z*N[WA+7],cA[1]=T*N[WA+1]-z*N[WA+3]-$*N[WA+5]-O*N[WA+7],cA[2]=O*N[WA+1]-$*N[WA+3]+z*N[WA+5]+T*N[WA+7],cA[3]=z*N[WA+1]-O*N[WA+3]+T*N[WA+5]-$*N[WA+7],SA[0]=_*(N[WA+0]+N[WA+4]),SA[3]=_*(N[WA+0]-N[WA+4]),SA[1]=lA[0]+lA[3],SA[2]=lA[1]-lA[2],KA[0]=SA[0]+SA[1],KA[1]=SA[3]+SA[2],KA[2]=SA[3]-SA[2],KA[3]=SA[0]-SA[1],N[WA+0]=KA[0]+cA[0],N[WA+1]=KA[1]+cA[1],N[WA+2]=KA[2]+cA[2],N[WA+3]=KA[3]+cA[3],N[WA+4]=KA[3]-cA[3],N[WA+5]=KA[2]-cA[2],N[WA+6]=KA[1]-cA[1],N[WA+7]=KA[0]-cA[0]}for(let xA=0;xA<8;++xA)lA[0]=U*N[16+xA],lA[1]=V*N[16+xA],lA[2]=U*N[48+xA],lA[3]=V*N[48+xA],cA[0]=$*N[8+xA]+T*N[24+xA]+O*N[40+xA]+z*N[56+xA],cA[1]=T*N[8+xA]-z*N[24+xA]-$*N[40+xA]-O*N[56+xA],cA[2]=O*N[8+xA]-$*N[24+xA]+z*N[40+xA]+T*N[56+xA],cA[3]=z*N[8+xA]-O*N[24+xA]+T*N[40+xA]-$*N[56+xA],SA[0]=_*(N[xA]+N[32+xA]),SA[3]=_*(N[xA]-N[32+xA]),SA[1]=lA[0]+lA[3],SA[2]=lA[1]-lA[2],KA[0]=SA[0]+SA[1],KA[1]=SA[3]+SA[2],KA[2]=SA[3]-SA[2],KA[3]=SA[0]-SA[1],N[0+xA]=KA[0]+cA[0],N[8+xA]=KA[1]+cA[1],N[16+xA]=KA[2]+cA[2],N[24+xA]=KA[3]+cA[3],N[32+xA]=KA[3]-cA[3],N[40+xA]=KA[2]-cA[2],N[48+xA]=KA[1]-cA[1],N[56+xA]=KA[0]-cA[0]}function Je(N){for(let _=0;_<64;++_){const $=N[0][_],U=N[1][_],T=N[2][_];N[0][_]=$+1.5747*T,N[1][_]=$-.1873*U-.4682*T,N[2][_]=$+1.8556*U}}function H(N,_,$){for(let U=0;U<64;++U)_[$+U]=OQ.toHalfFloat(J(N[U]))}function J(N){return N<=1?Math.sign(N)*Math.pow(Math.abs(N),2.2):Math.sign(N)*Math.pow(F,Math.abs(N)-1)}function uA(N){return new DataView(N.array.buffer,N.offset.value,N.size)}function yA(N){const _=N.viewer.buffer.slice(N.offset.value,N.offset.value+N.size),$=new Uint8Array(_A(_)),U=new Uint8Array($.length);return HA($),mA($,U),new DataView(U.buffer)}function bA(N){const _=N.array.slice(N.offset.value,N.offset.value+N.size),$=qu(_),U=new Uint8Array($.length);return HA($),mA($,U),new DataView(U.buffer)}function FA(N){const _=N.viewer,$={value:N.offset.value},U=new Uint16Array(N.width*N.scanlineBlockSize*(N.channels*N.type)),T=new Uint8Array(8192);let O=0;const V=new Array(N.channels);for(let XA=0;XA<N.channels;XA++)V[XA]={},V[XA].start=O,V[XA].end=V[XA].start,V[XA].nx=N.width,V[XA].ny=N.lines,V[XA].size=N.type,O+=V[XA].nx*V[XA].ny*V[XA].size;const z=AA(_,$),lA=AA(_,$);if(lA>=8192)throw new Error("Something is wrong with PIZ_COMPRESSION BITMAP_SIZE");if(z<=lA)for(let XA=0;XA<lA-z+1;XA++)T[XA+z]=ce(_,$);const cA=new Uint16Array(65536),SA=S(T,cA),KA=Qe(_,$);oe(N.array,_,$,KA,U,O);for(let XA=0;XA<N.channels;++XA){const ee=V[XA];for(let re=0;re<V[XA].size;++re)OA(U,ee.start+re,ee.nx,ee.size,ee.ny,ee.nx*ee.size,SA)}j(cA,U,O);let xA=0;const WA=new Uint8Array(U.buffer.byteLength);for(let XA=0;XA<N.lines;XA++)for(let ee=0;ee<N.channels;ee++){const re=V[ee],ke=re.nx*re.size,St=new Uint8Array(U.buffer,re.end*2,ke*2);WA.set(St,xA),xA+=ke*2,re.end+=ke}return new DataView(WA.buffer)}function pe(N){const _=N.array.slice(N.offset.value,N.offset.value+N.size),$=qu(_),U=N.lines*N.channels*N.width,T=N.type==1?new Uint16Array(U):new Uint32Array(U);let O=0,V=0;const z=new Array(4);for(let lA=0;lA<N.lines;lA++)for(let cA=0;cA<N.channels;cA++){let SA=0;switch(N.type){case 1:z[0]=O,z[1]=z[0]+N.width,O=z[1]+N.width;for(let KA=0;KA<N.width;++KA){const xA=$[z[0]++]<<8|$[z[1]++];SA+=xA,T[V]=SA,V++}break;case 2:z[0]=O,z[1]=z[0]+N.width,z[2]=z[1]+N.width,O=z[2]+N.width;for(let KA=0;KA<N.width;++KA){const xA=$[z[0]++]<<24|$[z[1]++]<<16|$[z[2]++]<<8;SA+=xA,T[V]=SA,V++}break}}return new DataView(T.buffer)}function Be(N){const _=N.viewer,$={value:N.offset.value},U=new Uint8Array(N.width*N.lines*(N.channels*N.type*2)),T={version:se(_,$),unknownUncompressedSize:se(_,$),unknownCompressedSize:se(_,$),acCompressedSize:se(_,$),dcCompressedSize:se(_,$),rleCompressedSize:se(_,$),rleUncompressedSize:se(_,$),rleRawSize:se(_,$),totalAcUncompressedCount:se(_,$),totalDcUncompressedCount:se(_,$),acCompression:se(_,$)};if(T.version<2)throw new Error("EXRLoader.parse: "+hC.compression+" version "+T.version+" is unsupported");const O=new Array;let V=AA(_,$)-2;for(;V>0;){const ee=qA(_.buffer,$),re=ce(_,$),ke=re>>2&3,St=(re>>4)-1,We=new Int8Array([St])[0],Re=ce(_,$);O.push({name:ee,index:We,type:Re,compression:ke}),V-=ee.length+3}const z=hC.channels,lA=new Array(N.channels);for(let ee=0;ee<N.channels;++ee){const re=lA[ee]={},ke=z[ee];re.name=ke.name,re.compression=0,re.decoded=!1,re.type=ke.pixelType,re.pLinear=ke.pLinear,re.width=N.width,re.height=N.lines}const cA={idx:new Array(3)};for(let ee=0;ee<N.channels;++ee){const re=lA[ee];for(let ke=0;ke<O.length;++ke){const St=O[ke];re.name==St.name&&(re.compression=St.compression,St.index>=0&&(cA.idx[St.index]=ee),re.offset=ee)}}let SA,KA,xA;if(T.acCompressedSize>0)switch(T.acCompression){case 0:SA=new Uint16Array(T.totalAcUncompressedCount),oe(N.array,_,$,T.acCompressedSize,SA,T.totalAcUncompressedCount);break;case 1:const ee=N.array.slice($.value,$.value+T.totalAcUncompressedCount),re=qu(ee);SA=new Uint16Array(re.buffer),$.value+=T.totalAcUncompressedCount;break}if(T.dcCompressedSize>0){const ee={array:N.array,offset:$,size:T.dcCompressedSize};KA=new Uint16Array(bA(ee).buffer),$.value+=T.dcCompressedSize}if(T.rleRawSize>0){const ee=N.array.slice($.value,$.value+T.rleCompressedSize),re=qu(ee);xA=_A(re.buffer),$.value+=T.rleCompressedSize}let WA=0;const XA=new Array(lA.length);for(let ee=0;ee<XA.length;++ee)XA[ee]=new Array;for(let ee=0;ee<N.lines;++ee)for(let re=0;re<lA.length;++re)XA[re].push(WA),WA+=lA[re].width*N.type*2;RA(cA,XA,lA,SA,KA,U);for(let ee=0;ee<lA.length;++ee){const re=lA[ee];if(!re.decoded)switch(re.compression){case 2:let ke=0,St=0;for(let We=0;We<N.lines;++We){let Re=XA[ee][ke];for(let Lt=0;Lt<re.width;++Lt){for(let ye=0;ye<2*re.type;++ye)U[Re++]=xA[St+ye*re.width*re.height];St++}ke++}break;case 1:default:throw new Error("EXRLoader.parse: unsupported channel compression")}}return new DataView(U.buffer)}function qA(N,_){const $=new Uint8Array(N);let U=0;for(;$[_.value+U]!=0;)U+=1;const T=new TextDecoder().decode($.slice(_.value,_.value+U));return _.value=_.value+U+1,T}function PA(N,_,$){const U=new TextDecoder().decode(new Uint8Array(N).slice(_.value,_.value+$));return _.value=_.value+$,U}function we(N,_){const $=tt(N,_),U=Qe(N,_);return[$,U]}function LA(N,_){const $=Qe(N,_),U=Qe(N,_);return[$,U]}function tt(N,_){const $=N.getInt32(_.value,!0);return _.value=_.value+4,$}function Qe(N,_){const $=N.getUint32(_.value,!0);return _.value=_.value+4,$}function VA(N,_){const $=N[_.value];return _.value=_.value+1,$}function ce(N,_){const $=N.getUint8(_.value);return _.value=_.value+1,$}const se=function(N,_){let $;return"getBigInt64"in DataView.prototype?$=Number(N.getBigInt64(_.value,!0)):$=N.getUint32(_.value+4,!0)+Number(N.getUint32(_.value,!0)<<32),_.value+=8,$};function Fe(N,_){const $=N.getFloat32(_.value,!0);return _.value+=4,$}function P(N,_){return OQ.toHalfFloat(Fe(N,_))}function BA(N){const _=(N&31744)>>10,$=N&1023;return(N>>15?-1:1)*(_?_===31?$?NaN:1/0:Math.pow(2,_-15)*(1+$/1024):6103515625e-14*($/1024))}function AA(N,_){const $=N.getUint16(_.value,!0);return _.value+=2,$}function JA(N,_){return BA(AA(N,_))}function QA(N,_,$,U){const T=$.value,O=[];for(;$.value<T+U-1;){const V=qA(_,$),z=tt(N,$),lA=ce(N,$);$.value+=3;const cA=tt(N,$),SA=tt(N,$);O.push({name:V,pixelType:z,pLinear:lA,xSampling:cA,ySampling:SA})}return $.value+=1,O}function YA(N,_){const $=Fe(N,_),U=Fe(N,_),T=Fe(N,_),O=Fe(N,_),V=Fe(N,_),z=Fe(N,_),lA=Fe(N,_),cA=Fe(N,_);return{redX:$,redY:U,greenX:T,greenY:O,blueX:V,blueY:z,whiteX:lA,whiteY:cA}}function zA(N,_){const $=["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"],U=ce(N,_);return $[U]}function it(N,_){const $=Qe(N,_),U=Qe(N,_),T=Qe(N,_),O=Qe(N,_);return{xMin:$,yMin:U,xMax:T,yMax:O}}function bt(N,_){const $=["INCREASING_Y"],U=ce(N,_);return $[U]}function Bi(N,_){const $=Fe(N,_),U=Fe(N,_);return[$,U]}function Qi(N,_){const $=Fe(N,_),U=Fe(N,_),T=Fe(N,_);return[$,U,T]}function ot(N,_,$,U,T){if(U==="string"||U==="stringvector"||U==="iccProfile")return PA(_,$,T);if(U==="chlist")return QA(N,_,$,T);if(U==="chromaticities")return YA(N,$);if(U==="compression")return zA(N,$);if(U==="box2i")return it(N,$);if(U==="lineOrder")return bt(N,$);if(U==="float")return Fe(N,$);if(U==="v2f")return Bi(N,$);if(U==="v3f")return Qi(N,$);if(U==="int")return tt(N,$);if(U==="rational")return we(N,$);if(U==="timecode")return LA(N,$);if(U==="preview")return $.value+=T,"skipped";$.value+=T}function Si(N,_,$){const U={};if(N.getUint32(0,!0)!=20000630)throw new Error("THREE.EXRLoader: Provided file doesn't appear to be in OpenEXR format.");U.version=N.getUint8(4);const T=N.getUint8(5);U.spec={singleTile:!!(T&2),longName:!!(T&4),deepFormat:!!(T&8),multiPart:!!(T&16)},$.value=8;let O=!0;for(;O;){const V=qA(_,$);if(V==0)O=!1;else{const z=qA(_,$),lA=Qe(N,$),cA=ot(N,_,$,z,lA);cA===void 0?console.warn(`THREE.EXRLoader: Skipped unknown header attribute type '${z}'.`):U[V]=cA}}if(T&-5)throw console.error("THREE.EXRHeader:",U),new Error("THREE.EXRLoader: Provided file is currently unsupported.");return U}function qi(N,_,$,U,T){const O={size:0,viewer:_,array:$,offset:U,width:N.dataWindow.xMax-N.dataWindow.xMin+1,height:N.dataWindow.yMax-N.dataWindow.yMin+1,channels:N.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:N.channels[0].pixelType,uncompress:null,getter:null,format:null,colorSpace:Nt};switch(N.compression){case"NO_COMPRESSION":O.lines=1,O.uncompress=uA;break;case"RLE_COMPRESSION":O.lines=1,O.uncompress=yA;break;case"ZIPS_COMPRESSION":O.lines=1,O.uncompress=bA;break;case"ZIP_COMPRESSION":O.lines=16,O.uncompress=bA;break;case"PIZ_COMPRESSION":O.lines=32,O.uncompress=FA;break;case"PXR24_COMPRESSION":O.lines=16,O.uncompress=pe;break;case"DWAA_COMPRESSION":O.lines=32,O.uncompress=Be;break;case"DWAB_COMPRESSION":O.lines=256,O.uncompress=Be;break;default:throw new Error("EXRLoader.parse: "+N.compression+" is unsupported")}if(O.scanlineBlockSize=O.lines,O.type==1)switch(T){case ai:O.getter=JA,O.inputSize=2;break;case Fi:O.getter=AA,O.inputSize=2;break}else if(O.type==2)switch(T){case ai:O.getter=Fe,O.inputSize=4;break;case Fi:O.getter=P,O.inputSize=4}else throw new Error("EXRLoader.parse: unsupported pixelType "+O.type+" for "+N.compression+".");O.blockCount=(N.dataWindow.yMax+1)/O.scanlineBlockSize;for(let z=0;z<O.blockCount;z++)se(_,U);O.outputChannels=O.channels==3?4:O.channels;const V=O.width*O.height*O.outputChannels;switch(T){case ai:O.byteArray=new Float32Array(V),O.channels<O.outputChannels&&O.byteArray.fill(1,0,V);break;case Fi:O.byteArray=new Uint16Array(V),O.channels<O.outputChannels&&O.byteArray.fill(15360,0,V);break;default:console.error("THREE.EXRLoader: unsupported type: ",T);break}return O.bytesPerLine=O.width*O.inputSize*O.channels,O.outputChannels==4?(O.format=Ut,O.colorSpace=Nt):(O.format=Fn,O.colorSpace=JI),O}const Lo=new DataView(A),EC=new Uint8Array(A),_o={value:0},hC=Si(Lo,A,_o),At=qi(hC,Lo,EC,_o,this.type),bd={value:0},Qw={R:0,G:1,B:2,A:3,Y:0};for(let N=0;N<At.height/At.scanlineBlockSize;N++){const _=Qe(Lo,_o);At.size=Qe(Lo,_o),At.lines=_+At.scanlineBlockSize>At.height?At.height-_:At.scanlineBlockSize;const U=At.size<At.lines*At.bytesPerLine?At.uncompress(At):uA(At);_o.value+=At.size;for(let T=0;T<At.scanlineBlockSize;T++){const O=T+N*At.scanlineBlockSize;if(O>=At.height)break;for(let V=0;V<At.channels;V++){const z=Qw[hC.channels[V].name];for(let lA=0;lA<At.width;lA++){bd.value=(T*(At.channels*At.width)+V*At.width+lA)*At.inputSize;const cA=(At.height-1-O)*(At.width*At.outputChannels)+lA*At.outputChannels+z;At.byteArray[cA]=At.getter(U,bd)}}}}return{header:hC,width:At.width,height:At.height,data:At.byteArray,format:At.format,colorSpace:At.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=Ue,o.magFilter=Ue,o.generateMipmaps=!1,o.flipY=!1,e&&e(o,s)}return super.load(A,I,t,i)}}const QcA=Object.freeze(Object.defineProperty({__proto__:null,EXRLoader:Sf},Symbol.toStringTag,{value:"Module"}));class nm extends ZK{constructor(A){super(A),this.type=Fi}parse(A){const o=function(M,F){switch(M){case 1:throw new Error("THREE.RGBELoader: Read Error: "+(F||""));case 2:throw new Error("THREE.RGBELoader: Write Error: "+(F||""));case 3:throw new Error("THREE.RGBELoader: Bad File Format: "+(F||""));default:case 4:throw new Error("THREE.RGBELoader: Memory Error: "+(F||""))}},r=`
5239
5239
  `,C=function(M,F,S){F=F||1024;let v=M.pos,q=-1,K=0,Y="",b=String.fromCharCode.apply(null,new Uint16Array(M.subarray(v,v+128)));for(;0>(q=b.indexOf(r))&&K<F&&v<M.byteLength;)Y+=b,K+=b.length,v+=128,b+=String.fromCharCode.apply(null,new Uint16Array(M.subarray(v,v+128)));return-1<q?(S!==!1&&(M.pos+=K+q+1),Y+b.slice(0,q)):!1},Q=function(M){const F=/^#\?(\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*$/,K={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let Y,b;for((M.pos>=M.byteLength||!(Y=C(M)))&&o(1,"no header found"),(b=Y.match(F))||o(3,"bad initial token"),K.valid|=1,K.programtype=b[1],K.string+=Y+`
5240
5240
  `;Y=C(M),Y!==!1;){if(K.string+=Y+`
@@ -326,10 +326,6 @@ export class NeedleXRSession {
326
326
  // setup session init args, make sure we have default values
327
327
  if (!init)
328
328
  init = {};
329
- // Fix: define these here because VariantLauncher crashes otherwise. Spec: https://immersive-web.github.io/webxr/#feature-dependencies
330
- // Issue: https://linear.app/needle/issue/NE-5136
331
- init.optionalFeatures ??= [];
332
- init.requiredFeatures ??= [];
333
329
  switch (mode) {
334
330
  // Setup VR initialization parameters
335
331
  case "immersive-ar":
@@ -370,6 +366,10 @@ export class NeedleXRSession {
370
366
  console.warn("No default session init for mode", mode);
371
367
  break;
372
368
  }
369
+ // Fix: define these here because VariantLauncher crashes otherwise. Spec: https://immersive-web.github.io/webxr/#feature-dependencies
370
+ // Issue: https://linear.app/needle/issue/NE-5136
371
+ init.optionalFeatures ??= [];
372
+ init.requiredFeatures ??= [];
373
373
  // we stop a temporary session here (if any runs)
374
374
  await TemporaryXRContext.stop();
375
375
  const scripts = mode == "immersive-ar" ? context.scripts_immersive_ar : context.scripts_immersive_vr;