@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.
package/CHANGELOG.md CHANGED
@@ -4,7 +4,7 @@ All notable changes to this package will be documented in this file.
4
4
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
5
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [3.41.1-alpha] - 2024-06-22
7
+ ## [3.41.1-alpha.1] - 2024-06-22
8
8
  - Add: `<needle-engine tone-mapping>` attribute. Possible values are `none`, `linear`, `neutral` or `agx`.
9
9
  - Change: Camera fitting near and far planes are now tighter to reduce z-fighting in some cases
10
10
 
@@ -29575,13 +29575,13 @@ function VtA() {
29575
29575
  return g || null;
29576
29576
  }
29577
29577
  const PP = IA("debugdefines");
29578
- Ql('if(!globalThis[""3.41.1-alpha""]) globalThis[""3.41.1-alpha""] = "0.0.0";');
29578
+ Ql('if(!globalThis[""3.41.1-alpha.1""]) globalThis[""3.41.1-alpha.1""] = "0.0.0";');
29579
29579
  Ql('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');
29580
- Ql('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";');
29581
- Ql('globalThis["__NEEDLE_ENGINE_VERSION__"] = "3.41.1-alpha";');
29580
+ Ql('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";');
29581
+ Ql('globalThis["__NEEDLE_ENGINE_VERSION__"] = "3.41.1-alpha.1";');
29582
29582
  Ql('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');
29583
- Ql('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Jun 24 2024 12:27:47 GMT+0200 (Central European Summer Time)";');
29584
- const dn = "3.41.1-alpha", _K = "undefined", WP = "Mon Jun 24 2024 12:27:47 GMT+0200 (Central European Summer Time)";
29583
+ Ql('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Jun 24 2024 16:20:52 GMT+0200 (Central European Summer Time)";');
29584
+ const dn = "3.41.1-alpha.1", _K = "undefined", WP = "Mon Jun 24 2024 16:20:52 GMT+0200 (Central European Summer Time)";
29585
29585
  PP && console.log(`Engine version: ${dn} (generator: ${_K})
29586
29586
  Project built at ${WP}`);
29587
29587
  const gB = "needle_isActiveInHierarchy", _c = "builtin_components", Zy = "needle_editor_guid";
@@ -65043,7 +65043,7 @@ const ar = class {
65043
65043
  return console.error("A XRSession is already running"), this._activeSession;
65044
65044
  if (t || (t = Je.Current), t || (t = dt.All[0]), !t)
65045
65045
  throw new Error("No Needle Engine Context found");
65046
- switch (e || (e = {}), e.optionalFeatures ?? (e.optionalFeatures = []), e.requiredFeatures ?? (e.requiredFeatures = []), A) {
65046
+ switch (e || (e = {}), A) {
65047
65047
  case "immersive-ar":
65048
65048
  {
65049
65049
  if (await ((o = this.xrSystem) == null ? void 0 : o.isSessionSupported("immersive-ar")) !== !0)
@@ -65069,7 +65069,7 @@ const ar = class {
65069
65069
  console.warn("No default session init for mode", A);
65070
65070
  break;
65071
65071
  }
65072
- await zC.stop();
65072
+ e.optionalFeatures ?? (e.optionalFeatures = []), e.requiredFeatures ?? (e.requiredFeatures = []), await zC.stop();
65073
65073
  const i = A == "immersive-ar" ? t.scripts_immersive_ar : t.scripts_immersive_vr;
65074
65074
  Ng ? console.log(`%cRequesting ${A} session`, "font-weight:bold;", e, i) : console.log(`%cRequesting ${A} session`, "font-weight:bold;");
65075
65075
  for (const r of i)
@@ -29575,13 +29575,13 @@ function vte() {
29575
29575
  return s || null;
29576
29576
  }
29577
29577
  const hH = ne("debugdefines");
29578
- Um('if(!globalThis[""3.41.1-alpha""]) globalThis[""3.41.1-alpha""] = "0.0.0";');
29578
+ Um('if(!globalThis[""3.41.1-alpha.1""]) globalThis[""3.41.1-alpha.1""] = "0.0.0";');
29579
29579
  Um('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";');
29580
- Um('if(!globalThis[""Mon Jun 24 2024 12:28:00 GMT+0200 (Central European Summer Time)""]) globalThis[""Mon Jun 24 2024 12:28:00 GMT+0200 (Central European Summer Time)""] = "unknown";');
29581
- Um('globalThis["__NEEDLE_ENGINE_VERSION__"] = "3.41.1-alpha";');
29580
+ Um('if(!globalThis[""Mon Jun 24 2024 16:21:06 GMT+0200 (Central European Summer Time)""]) globalThis[""Mon Jun 24 2024 16:21:06 GMT+0200 (Central European Summer Time)""] = "unknown";');
29581
+ Um('globalThis["__NEEDLE_ENGINE_VERSION__"] = "3.41.1-alpha.1";');
29582
29582
  Um('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";');
29583
- Um('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Jun 24 2024 12:28:00 GMT+0200 (Central European Summer Time)";');
29584
- const nc = "3.41.1-alpha", BD = "undefined", uH = "Mon Jun 24 2024 12:28:00 GMT+0200 (Central European Summer Time)";
29583
+ Um('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Jun 24 2024 16:21:06 GMT+0200 (Central European Summer Time)";');
29584
+ const nc = "3.41.1-alpha.1", BD = "undefined", uH = "Mon Jun 24 2024 16:21:06 GMT+0200 (Central European Summer Time)";
29585
29585
  hH && console.log(`Engine version: ${nc} (generator: ${BD})
29586
29586
  Project built at ${uH}`);
29587
29587
  const Uu = "needle_isActiveInHierarchy", Ag = "builtin_components", lw = "needle_editor_guid";
@@ -65043,7 +65043,7 @@ const Xl = class {
65043
65043
  return console.error("A XRSession is already running"), this._activeSession;
65044
65044
  if (i || (i = kt.Current), i || (i = gi.All[0]), !i)
65045
65045
  throw new Error("No Needle Engine Context found");
65046
- switch (t || (t = {}), t.optionalFeatures ?? (t.optionalFeatures = []), t.requiredFeatures ?? (t.requiredFeatures = []), e) {
65046
+ switch (t || (t = {}), e) {
65047
65047
  case "immersive-ar":
65048
65048
  {
65049
65049
  if (await ((o = this.xrSystem) == null ? void 0 : o.isSessionSupported("immersive-ar")) !== !0)
@@ -65069,7 +65069,7 @@ const Xl = class {
65069
65069
  console.warn("No default session init for mode", e);
65070
65070
  break;
65071
65071
  }
65072
- await Pu.stop();
65072
+ t.optionalFeatures ?? (t.optionalFeatures = []), t.requiredFeatures ?? (t.requiredFeatures = []), await Pu.stop();
65073
65073
  const n = e == "immersive-ar" ? i.scripts_immersive_ar : i.scripts_immersive_vr;
65074
65074
  _s ? console.log(`%cRequesting ${e} session`, "font-weight:bold;", t, n) : console.log(`%cRequesting ${e} session`, "font-weight:bold;");
65075
65075
  for (const h of n)
@@ -4344,7 +4344,7 @@ Open this page to get the console: `+e.toString())}const i=Io()||Y_()&&st();if((
4344
4344
  #__vconsole .vc-mask {
4345
4345
  overflow: hidden;
4346
4346
  }
4347
- `,la?.prepend(n),i===!0&&fT()<=0&&tQ(),console.log("\u{1F335} Debug console has loaded")}},e.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(e)}function $ie(){const i=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),e=()=>document.querySelector("#__vc_plug_"+i._id+" iframe");return i.on("renderTab",function(t){const n=globalThis["needle:codegen_files"];if(!n||n.length===0)return;let r=globalThis["needle:codegen_files"][0];const s=r.indexOf("?");s>-1&&(r=r.substring(0,s));const o=location.protocol+"//"+location.host+location.pathname+"/"+r,a=encodeURIComponent(o);i.fullUrl="https://viewer.needle.tools?inspect&file="+a;var l='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';t(l)}),i.on("show",function(){const t=e();t&&t.src!==i.fullUrl&&(t.src=i.fullUrl)}),i.on("hide",function(){const t=e();t&&(t.src="")}),i.on("addTopBar",function(t){var n=new Array;n.push({name:"Open in new window \u2197",onClick:function(r){window.open(i.fullUrl,"_blank"),aa?.hide()}}),n.push({name:"Reload",onClick:function(r){const s=e();s&&(s.src=i.fullUrl)}}),n.push({name:"Fullscreen",onClick:function(r){const s=e();s.requestFullscreen?s.requestFullscreen():s.webkitRequestFullscreen instanceof Function&&s.webkitRequestFullscreen()}}),t(n)}),i}function ene(){return document.querySelector("#__vconsole .vc-switch")||null}function tne(){return document.querySelector("#__vconsole")||null}const sQ=ee("debugdefines");Tm('if(!globalThis[""3.41.1-alpha""]) globalThis[""3.41.1-alpha""] = "0.0.0";'),Tm('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";'),Tm('if(!globalThis[""Mon Jun 24 2024 12:28:00 GMT+0200 (Central European Summer Time)""]) globalThis[""Mon Jun 24 2024 12:28:00 GMT+0200 (Central European Summer Time)""] = "unknown";'),Tm('globalThis["__NEEDLE_ENGINE_VERSION__"] = "3.41.1-alpha";'),Tm('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),Tm('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Jun 24 2024 12:28:00 GMT+0200 (Central European Summer Time)";');const Za="3.41.1-alpha",mw="undefined",dB="Mon Jun 24 2024 12:28:00 GMT+0200 (Central European Summer Time)";sQ&&console.log(`Engine version: ${Za} (generator: ${mw})
4347
+ `,la?.prepend(n),i===!0&&fT()<=0&&tQ(),console.log("\u{1F335} Debug console has loaded")}},e.src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js",document.body.appendChild(e)}function $ie(){const i=new VConsole.VConsolePlugin("needle-console","\u{1F335} Inspect glTF"),e=()=>document.querySelector("#__vc_plug_"+i._id+" iframe");return i.on("renderTab",function(t){const n=globalThis["needle:codegen_files"];if(!n||n.length===0)return;let r=globalThis["needle:codegen_files"][0];const s=r.indexOf("?");s>-1&&(r=r.substring(0,s));const o=location.protocol+"//"+location.host+location.pathname+"/"+r,a=encodeURIComponent(o);i.fullUrl="https://viewer.needle.tools?inspect&file="+a;var l='<iframe src="" style="width: 100%; height: 99%; border: none;"></iframe>';t(l)}),i.on("show",function(){const t=e();t&&t.src!==i.fullUrl&&(t.src=i.fullUrl)}),i.on("hide",function(){const t=e();t&&(t.src="")}),i.on("addTopBar",function(t){var n=new Array;n.push({name:"Open in new window \u2197",onClick:function(r){window.open(i.fullUrl,"_blank"),aa?.hide()}}),n.push({name:"Reload",onClick:function(r){const s=e();s&&(s.src=i.fullUrl)}}),n.push({name:"Fullscreen",onClick:function(r){const s=e();s.requestFullscreen?s.requestFullscreen():s.webkitRequestFullscreen instanceof Function&&s.webkitRequestFullscreen()}}),t(n)}),i}function ene(){return document.querySelector("#__vconsole .vc-switch")||null}function tne(){return document.querySelector("#__vconsole")||null}const sQ=ee("debugdefines");Tm('if(!globalThis[""3.41.1-alpha.1""]) globalThis[""3.41.1-alpha.1""] = "0.0.0";'),Tm('if(!globalThis[""undefined""]) globalThis[""undefined""] = "unknown";'),Tm('if(!globalThis[""Mon Jun 24 2024 16:21:06 GMT+0200 (Central European Summer Time)""]) globalThis[""Mon Jun 24 2024 16:21:06 GMT+0200 (Central European Summer Time)""] = "unknown";'),Tm('globalThis["__NEEDLE_ENGINE_VERSION__"] = "3.41.1-alpha.1";'),Tm('globalThis["__NEEDLE_ENGINE_GENERATOR__"] = "undefined";'),Tm('globalThis["__NEEDLE_PROJECT_BUILD_TIME__"] = "Mon Jun 24 2024 16:21:06 GMT+0200 (Central European Summer Time)";');const Za="3.41.1-alpha.1",mw="undefined",dB="Mon Jun 24 2024 16:21:06 GMT+0200 (Central European Summer Time)";sQ&&console.log(`Engine version: ${Za} (generator: ${mw})
4348
4348
  Project built at ${dB}`);const qc="needle_isActiveInHierarchy",pp="builtin_components",G0="needle_editor_guid";function Tm(i){try{(0,eval)(i)}catch(e){sQ&&console.error(e)}}const ine='<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>',nne=btoa(ine),rne="data:image/svg+xml;base64,"+nne,sne=rne,one=`<?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(one);const ane='<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>',lne=btoa(ane),cne="data:image/svg+xml;charset=utf-8;base64,"+lne,hne=cne,ca=ee("debuglicense");let fp="basic";ca&&console.log("License Type: "+fp);function lu(){switch(fp){case"pro":case"enterprise":return!0}return!1}function pB(){switch(fp){case"indie":return!0}return!1}function Xc(){return lu()||pB()}const oQ=[];function une(i){if(lu()||pB())return i(!0);oQ.push(i)}function dne(i){for(const e of oQ)try{e(i)}catch{}}hi.registerCallback(Ei.ContextRegistered,i=>{mne(i.context),Ane(),fne(i.context)});let mp,fB=!1,gw="";async function pne(){if(mp)return mp;if(fp==="basic")try{const i="https://engine.needle.tools/licensing/check?location="+encodeURIComponent(window.location.href)+"&version="+Za+"&generator="+encodeURIComponent(mw),e=await fetch(i,{method:"GET"}).catch(t=>{ca&&console.error("License check failed",t)});e?.status===200?(fB=!1,ca&&console.log("License check succeeded"),fp="pro",dne(!0)):e?.status===403?(fB=!0,gw=await e.text()):ca&&console.log("License check failed with status "+e?.status)}catch(i){ca&&console.error("License check failed",i)}else ca&&console.log('Runtime license check is skipped because license is already applied as "'+fp+'"')}mp=pne();async function fne(i){function e(){const r=document.createElement("div");r.className="needle-forbidden",r.style.cssText=`
4349
4349
  position: fixed;
4350
4350
  top: 0;
@@ -5234,7 +5234,7 @@ a=extmap-allow-mixed`)!==-1){const r=n.sdp.split(`
5234
5234
  isUnifiedPlanSupported:`).concat(this.isUnifiedPlanSupported())},i}()),z5={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"},rde=function(){function i(){this.CLOUD_HOST="0.peerjs.com",this.CLOUD_PORT=443,this.chunkedBrowsers={Chrome:1,chrome:1},this.chunkedMTU=16300,this.defaultConfig=z5,this.browser=Vv.getBrowser(),this.browserVersion=Vv.getVersion(),this.supports=function(){var e={browser:Vv.isBrowserSupported(),webRTC:Vv.isWebRTCSupported(),audioVideo:!1,data:!1,binaryBlob:!1,reliable:!1};if(!e.webRTC)return e;var t;try{t=new RTCPeerConnection(z5),e.audioVideo=!0;var n=void 0;try{n=t.createDataChannel("_PEERJSTEST",{ordered:!0}),e.data=!0,e.reliable=!!n.ordered;try{n.binaryType="blob",e.binaryBlob=!Vv.isIOS}catch{}}catch{}finally{n&&n.close()}}catch{}finally{t&&t.close()}return e}(),this.pack=XG.pack,this.unpack=XG.unpack,this._dataCount=1}return i.prototype.noop=function(){},i.prototype.validateId=function(e){return!e||/^[A-Za-z0-9]+(?:[ _-][A-Za-z0-9]+)*$/.test(e)},i.prototype.chunk=function(e){for(var t=[],n=e.size,r=Math.ceil(n/_i.chunkedMTU),s=0,o=0;o<n;){var a=Math.min(n,o+_i.chunkedMTU),l=e.slice(o,a),c={__peerData:this._dataCount,n:s,data:l,total:r};t.push(c),o=a,s++}return this._dataCount++,t},i.prototype.blobToArrayBuffer=function(e,t){var n=new FileReader;return n.onload=function(r){r.target&&t(r.target.result)},n.readAsArrayBuffer(e),n},i.prototype.binaryStringToArrayBuffer=function(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;n++)t[n]=e.charCodeAt(n)&255;return t.buffer},i.prototype.randomToken=function(){return Math.random().toString(36).slice(2)},i.prototype.isSecure=function(){return location.protocol==="https:"},i}(),_i=new rde,j5={};ql(j5,"Peer",()=>TD,i=>TD=i);var Wv={},sde=Object.prototype.hasOwnProperty,Js="~";function qv(){}Object.create&&(qv.prototype=Object.create(null),new qv().__proto__||(Js=!1));function ode(i,e,t){this.fn=i,this.context=e,this.once=t||!1}function G5(i,e,t,n,r){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new ode(t,n||i,r),o=Js?Js+e:e;return i._events[o]?i._events[o].fn?i._events[o]=[i._events[o],s]:i._events[o].push(s):(i._events[o]=s,i._eventsCount++),i}function Y1(i,e){--i._eventsCount===0?i._events=new qv:delete i._events[e]}function bs(){this._events=new qv,this._eventsCount=0}bs.prototype.eventNames=function(){var i=[],e,t;if(this._eventsCount===0)return i;for(t in e=this._events)sde.call(e,t)&&i.push(Js?t.slice(1):t);return Object.getOwnPropertySymbols?i.concat(Object.getOwnPropertySymbols(e)):i},bs.prototype.listeners=function(i){var e=Js?Js+i:i,t=this._events[e];if(!t)return[];if(t.fn)return[t.fn];for(var n=0,r=t.length,s=new Array(r);n<r;n++)s[n]=t[n].fn;return s},bs.prototype.listenerCount=function(i){var e=Js?Js+i:i,t=this._events[e];return t?t.fn?1:t.length:0},bs.prototype.emit=function(i,e,t,n,r,s){var o=Js?Js+i:i;if(!this._events[o])return!1;var a=this._events[o],l=arguments.length,c,h;if(a.fn){switch(a.once&&this.removeListener(i,a.fn,void 0,!0),l){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,e),!0;case 3:return a.fn.call(a.context,e,t),!0;case 4:return a.fn.call(a.context,e,t,n),!0;case 5:return a.fn.call(a.context,e,t,n,r),!0;case 6:return a.fn.call(a.context,e,t,n,r,s),!0}for(h=1,c=new Array(l-1);h<l;h++)c[h-1]=arguments[h];a.fn.apply(a.context,c)}else{var d=a.length,p;for(h=0;h<d;h++)switch(a[h].once&&this.removeListener(i,a[h].fn,void 0,!0),l){case 1:a[h].fn.call(a[h].context);break;case 2:a[h].fn.call(a[h].context,e);break;case 3:a[h].fn.call(a[h].context,e,t);break;case 4:a[h].fn.call(a[h].context,e,t,n);break;default:if(!c)for(p=1,c=new Array(l-1);p<l;p++)c[p-1]=arguments[p];a[h].fn.apply(a[h].context,c)}}return!0},bs.prototype.on=function(i,e,t){return G5(this,i,e,t,!1)},bs.prototype.once=function(i,e,t){return G5(this,i,e,t,!0)},bs.prototype.removeListener=function(i,e,t,n){var r=Js?Js+i:i;if(!this._events[r])return this;if(!e)return Y1(this,r),this;var s=this._events[r];if(s.fn)s.fn===e&&(!n||s.once)&&(!t||s.context===t)&&Y1(this,r);else{for(var o=0,a=[],l=s.length;o<l;o++)(s[o].fn!==e||n&&!s[o].once||t&&s[o].context!==t)&&a.push(s[o]);a.length?this._events[r]=a.length===1?a[0]:a:Y1(this,r)}return this},bs.prototype.removeAllListeners=function(i){var e;return i?(e=Js?Js+i:i,this._events[e]&&Y1(this,e)):(this._events=new qv,this._eventsCount=0),this},bs.prototype.off=bs.prototype.removeListener,bs.prototype.addListener=bs.prototype.on,bs.prefixed=Js,bs.EventEmitter=bs,Wv=bs;var ut={};ql(ut,"LogLevel",()=>go,i=>go=i),ql(ut,"default",()=>H5,i=>H5=i);var Np=function(i,e){var t=typeof Symbol=="function"&&i[Symbol.iterator];if(!t)return i;var n=t.call(i),r,s=[],o;try{for(;(e===void 0||e-- >0)&&!(r=n.next()).done;)s.push(r.value)}catch(a){o={error:a}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(o)throw o.error}}return s},Qp=function(i,e,t){if(t||arguments.length===2)for(var n=0,r=e.length,s;n<r;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return i.concat(s||Array.prototype.slice.call(e))},ade="PeerJS: ",go;(function(i){i[i.Disabled=0]="Disabled",i[i.Errors=1]="Errors",i[i.Warnings=2]="Warnings",i[i.All=3]="All"})(go||(go={}));var lde=function(){function i(){this._logLevel=go.Disabled}return Object.defineProperty(i.prototype,"logLevel",{get:function(){return this._logLevel},set:function(e){this._logLevel=e},enumerable:!1,configurable:!0}),i.prototype.log=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=go.All&&this._print.apply(this,Qp([go.All],Np(e),!1))},i.prototype.warn=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=go.Warnings&&this._print.apply(this,Qp([go.Warnings],Np(e),!1))},i.prototype.error=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];this._logLevel>=go.Errors&&this._print.apply(this,Qp([go.Errors],Np(e),!1))},i.prototype.setLogFunction=function(e){this._print=e},i.prototype._print=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=Qp([ade],Np(t),!1);for(var s in r)r[s]instanceof Error&&(r[s]="("+r[s].name+") "+r[s].message);e>=go.All?console.log.apply(console,Qp([],Np(r),!1)):e>=go.Warnings?console.warn.apply(console,Qp(["WARNING"],Np(r),!1)):e>=go.Errors&&console.error.apply(console,Qp(["ERROR"],Np(r),!1))},i}(),H5=new lde,V5={};ql(V5,"Socket",()=>W5,i=>W5=i);var ul;(function(i){i.Data="data",i.Media="media"})(ul||(ul={}));var Fn;(function(i){i.BrowserIncompatible="browser-incompatible",i.Disconnected="disconnected",i.InvalidID="invalid-id",i.InvalidKey="invalid-key",i.Network="network",i.PeerUnavailable="peer-unavailable",i.SslUnavailable="ssl-unavailable",i.ServerError="server-error",i.SocketError="socket-error",i.SocketClosed="socket-closed",i.UnavailableID="unavailable-id",i.WebRTC="webrtc"})(Fn||(Fn={}));var dh;(function(i){i.Binary="binary",i.BinaryUTF8="binary-utf8",i.JSON="json"})(dh||(dh={}));var ph;(function(i){i.Message="message",i.Disconnected="disconnected",i.Error="error",i.Close="close"})(ph||(ph={}));var jr;(function(i){i.Heartbeat="HEARTBEAT",i.Candidate="CANDIDATE",i.Offer="OFFER",i.Answer="ANSWER",i.Open="OPEN",i.Error="ERROR",i.IdTaken="ID-TAKEN",i.InvalidKey="INVALID-KEY",i.Leave="LEAVE",i.Expire="EXPIRE"})(jr||(jr={}));var CD={};CD=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\xFCckler <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>","So\u0308ren 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 cde=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),hde=function(i,e){var t=typeof Symbol=="function"&&i[Symbol.iterator];if(!t)return i;var n=t.call(i),r,s=[],o;try{for(;(e===void 0||e-- >0)&&!(r=n.next()).done;)s.push(r.value)}catch(a){o={error:a}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(o)throw o.error}}return s},ude=function(i,e,t){if(t||arguments.length===2)for(var n=0,r=e.length,s;n<r;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return i.concat(s||Array.prototype.slice.call(e))},dde=function(i){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&i[e],n=0;if(t)return t.call(i);if(i&&typeof i.length=="number")return{next:function(){return i&&n>=i.length&&(i=void 0),{value:i&&i[n++],done:!i}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},W5=function(i){cde(e,i);function e(t,n,r,s,o,a){a===void 0&&(a=5e3);var l=i.call(this)||this;l.pingInterval=a,l._disconnected=!0,l._messagesQueue=[];var c=t?"wss://":"ws://";return l._baseUrl=c+n+":"+r+s+"peerjs?key="+o,l}return e.prototype.start=function(t,n){var r=this;this._id=t;var s="".concat(this._baseUrl,"&id=").concat(t,"&token=").concat(n);this._socket||!this._disconnected||(this._socket=new WebSocket(s+"&version="+CD.version),this._disconnected=!1,this._socket.onmessage=function(o){var a;try{a=JSON.parse(o.data),ut.default.log("Server message received:",a)}catch{ut.default.log("Invalid server message",o.data);return}r.emit(ph.Message,a)},this._socket.onclose=function(o){r._disconnected||(ut.default.log("Socket closed.",o),r._cleanup(),r._disconnected=!0,r.emit(ph.Disconnected))},this._socket.onopen=function(){r._disconnected||(r._sendQueuedMessages(),ut.default.log("Socket open"),r._scheduleHeartbeat())})},e.prototype._scheduleHeartbeat=function(){var t=this;this._wsPingTimer=setTimeout(function(){t._sendHeartbeat()},this.pingInterval)},e.prototype._sendHeartbeat=function(){if(!this._wsOpen()){ut.default.log("Cannot send heartbeat, because socket closed");return}var t=JSON.stringify({type:jr.Heartbeat});this._socket.send(t),this._scheduleHeartbeat()},e.prototype._wsOpen=function(){return!!this._socket&&this._socket.readyState===1},e.prototype._sendQueuedMessages=function(){var t,n,r=ude([],hde(this._messagesQueue),!1);this._messagesQueue=[];try{for(var s=dde(r),o=s.next();!o.done;o=s.next()){var a=o.value;this.send(a)}}catch(l){t={error:l}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}},e.prototype.send=function(t){if(!this._disconnected){if(!this._id){this._messagesQueue.push(t);return}if(!t.type){this.emit(ph.Error,"Invalid message");return}if(this._wsOpen()){var n=JSON.stringify(t);this._socket.send(n)}}},e.prototype.close=function(){this._disconnected||(this._cleanup(),this._disconnected=!0)},e.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)},e}(Wv.EventEmitter),ED={};ql(ED,"MediaConnection",()=>Y5,i=>Y5=i);var SD={};ql(SD,"Negotiator",()=>q5,i=>q5=i);var J1=function(){return J1=Object.assign||function(i){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(i[r]=e[r])}return i},J1.apply(this,arguments)},K1=function(i,e,t,n){function r(s){return s instanceof t?s:new t(function(o){o(s)})}return new(t||(t=Promise))(function(s,o){function a(h){try{c(n.next(h))}catch(d){o(d)}}function l(h){try{c(n.throw(h))}catch(d){o(d)}}function c(h){h.done?s(h.value):r(h.value).then(a,l)}c((n=n.apply(i,e||[])).next())})},Z1=function(i,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,r,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(h){return l([c,h])}}function l(c){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,r&&(s=c[0]&2?r.return:c[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,c[1])).done)return s;switch(r=0,s&&(c=[c[0]&2,s.value]),c[0]){case 0:case 1:s=c;break;case 4:return t.label++,{value:c[1],done:!1};case 5:t.label++,r=c[1],c=[0];continue;case 7:c=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(c[0]===6||c[0]===2)){t=0;continue}if(c[0]===3&&(!s||c[1]>s[0]&&c[1]<s[3])){t.label=c[1];break}if(c[0]===6&&t.label<s[1]){t.label=s[1],s=c;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(c);break}s[2]&&t.ops.pop(),t.trys.pop();continue}c=e.call(i,t)}catch(h){c=[6,h],r=0}finally{n=s=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}},q5=function(){function i(e){this.connection=e}return i.prototype.startConnection=function(e){var t=this._startPeerConnection();if(this.connection.peerConnection=t,this.connection.type===ul.Media&&e._stream&&this._addTracksToConnection(e._stream,t),e.originator){if(this.connection.type===ul.Data){var n=this.connection,r={ordered:!!e.reliable},s=t.createDataChannel(n.label,r);n.initialize(s)}this._makeOffer()}else this.handleSDP("OFFER",e.sdp)},i.prototype._startPeerConnection=function(){ut.default.log("Creating RTCPeerConnection.");var e=new RTCPeerConnection(this.connection.provider.options.config);return this._setupListeners(e),e},i.prototype._setupListeners=function(e){var t=this,n=this.connection.peer,r=this.connection.connectionId,s=this.connection.type,o=this.connection.provider;ut.default.log("Listening for ICE candidates."),e.onicecandidate=function(a){!a.candidate||!a.candidate.candidate||(ut.default.log("Received ICE candidates for ".concat(n,":"),a.candidate),o.socket.send({type:jr.Candidate,payload:{candidate:a.candidate,type:s,connectionId:r},dst:n}))},e.oniceconnectionstatechange=function(){switch(e.iceConnectionState){case"failed":ut.default.log("iceConnectionState is failed, closing connections to "+n),t.connection.emit("error",new Error("Negotiation of connection to "+n+" failed.")),t.connection.close();break;case"closed":ut.default.log("iceConnectionState is closed, closing connections to "+n),t.connection.emit("error",new Error("Connection to "+n+" closed.")),t.connection.close();break;case"disconnected":ut.default.log("iceConnectionState changed to disconnected on the connection with "+n);break;case"completed":e.onicecandidate=_i.noop;break}t.connection.emit("iceStateChanged",e.iceConnectionState)},ut.default.log("Listening for data channel"),e.ondatachannel=function(a){ut.default.log("Received data channel");var l=a.channel,c=o.getConnection(n,r);c.initialize(l)},ut.default.log("Listening for remote stream"),e.ontrack=function(a){ut.default.log("Received remote stream");var l=a.streams[0],c=o.getConnection(n,r);if(c.type===ul.Media){var h=c;t._addStreamToMediaConnection(l,h)}}},i.prototype.cleanup=function(){ut.default.log("Cleaning up PeerConnection to "+this.connection.peer);var e=this.connection.peerConnection;if(e){this.connection.peerConnection=null,e.onicecandidate=e.oniceconnectionstatechange=e.ondatachannel=e.ontrack=function(){};var t=e.signalingState!=="closed",n=!1;if(this.connection.type===ul.Data){var r=this.connection,s=r.dataChannel;s&&(n=!!s.readyState&&s.readyState!=="closed")}(t||n)&&e.close()}},i.prototype._makeOffer=function(){return K1(this,void 0,Promise,function(){var e,t,n,r,s,o,a;return Z1(this,function(l){switch(l.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,l.label=1;case 1:return l.trys.push([1,7,,8]),[4,e.createOffer(this.connection.options.constraints)];case 2:n=l.sent(),ut.default.log("Created offer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),l.label=3;case 3:return l.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return l.sent(),ut.default.log("Set localDescription:",n,"for:".concat(this.connection.peer)),r={sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,metadata:this.connection.metadata,browser:_i.browser},this.connection.type===ul.Data&&(s=this.connection,r=J1(J1({},r),{label:s.label,reliable:s.reliable,serialization:s.serialization})),t.socket.send({type:jr.Offer,payload:r,dst:this.connection.peer}),[3,6];case 5:return o=l.sent(),o!="OperationError: Failed to set local offer sdp: Called in wrong state: kHaveRemoteOffer"&&(t.emitError(Fn.WebRTC,o),ut.default.log("Failed to setLocalDescription, ",o)),[3,6];case 6:return[3,8];case 7:return a=l.sent(),t.emitError(Fn.WebRTC,a),ut.default.log("Failed to createOffer, ",a),[3,8];case 8:return[2]}})})},i.prototype._makeAnswer=function(){return K1(this,void 0,Promise,function(){var e,t,n,r,s;return Z1(this,function(o){switch(o.label){case 0:e=this.connection.peerConnection,t=this.connection.provider,o.label=1;case 1:return o.trys.push([1,7,,8]),[4,e.createAnswer()];case 2:n=o.sent(),ut.default.log("Created answer."),this.connection.options.sdpTransform&&typeof this.connection.options.sdpTransform=="function"&&(n.sdp=this.connection.options.sdpTransform(n.sdp)||n.sdp),o.label=3;case 3:return o.trys.push([3,5,,6]),[4,e.setLocalDescription(n)];case 4:return o.sent(),ut.default.log("Set localDescription:",n,"for:".concat(this.connection.peer)),t.socket.send({type:jr.Answer,payload:{sdp:n,type:this.connection.type,connectionId:this.connection.connectionId,browser:_i.browser},dst:this.connection.peer}),[3,6];case 5:return r=o.sent(),t.emitError(Fn.WebRTC,r),ut.default.log("Failed to setLocalDescription, ",r),[3,6];case 6:return[3,8];case 7:return s=o.sent(),t.emitError(Fn.WebRTC,s),ut.default.log("Failed to create answer, ",s),[3,8];case 8:return[2]}})})},i.prototype.handleSDP=function(e,t){return K1(this,void 0,Promise,function(){var n,r,s,o;return Z1(this,function(a){switch(a.label){case 0:t=new RTCSessionDescription(t),n=this.connection.peerConnection,r=this.connection.provider,ut.default.log("Setting remote description",t),s=this,a.label=1;case 1:return a.trys.push([1,5,,6]),[4,n.setRemoteDescription(t)];case 2:return a.sent(),ut.default.log("Set remoteDescription:".concat(e," for:").concat(this.connection.peer)),e!=="OFFER"?[3,4]:[4,s._makeAnswer()];case 3:a.sent(),a.label=4;case 4:return[3,6];case 5:return o=a.sent(),r.emitError(Fn.WebRTC,o),ut.default.log("Failed to setRemoteDescription, ",o),[3,6];case 6:return[2]}})})},i.prototype.handleCandidate=function(e){return K1(this,void 0,Promise,function(){var t,n,r,s,o,a;return Z1(this,function(l){switch(l.label){case 0:ut.default.log("handleCandidate:",e),t=e.candidate,n=e.sdpMLineIndex,r=e.sdpMid,s=this.connection.peerConnection,o=this.connection.provider,l.label=1;case 1:return l.trys.push([1,3,,4]),[4,s.addIceCandidate(new RTCIceCandidate({sdpMid:r,sdpMLineIndex:n,candidate:t}))];case 2:return l.sent(),ut.default.log("Added ICE candidate for:".concat(this.connection.peer)),[3,4];case 3:return a=l.sent(),o.emitError(Fn.WebRTC,a),ut.default.log("Failed to handleCandidate, ",a),[3,4];case 4:return[2]}})})},i.prototype._addTracksToConnection=function(e,t){if(ut.default.log("add tracks from stream ".concat(e.id," to peer connection")),!t.addTrack)return ut.default.error("Your browser does't support RTCPeerConnection#addTrack. Ignored.");e.getTracks().forEach(function(n){t.addTrack(n,e)})},i.prototype._addStreamToMediaConnection=function(e,t){ut.default.log("add stream ".concat(e.id," to media connection ").concat(t.connectionId)),t.addStream(e)},i}(),ID={};ql(ID,"BaseConnection",()=>X5,i=>X5=i);var pde=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),X5=function(i){pde(e,i);function e(t,n,r){var s=i.call(this)||this;return s.peer=t,s.provider=n,s.options=r,s._open=!1,s.metadata=r.metadata,s}return Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),e}(Wv.EventEmitter),fde=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),$1=function(){return $1=Object.assign||function(i){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(i[r]=e[r])}return i},$1.apply(this,arguments)},mde=function(i){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&i[e],n=0;if(t)return t.call(i);if(i&&typeof i.length=="number")return{next:function(){return i&&n>=i.length&&(i=void 0),{value:i&&i[n++],done:!i}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Y5=function(i){fde(e,i);function e(t,n,r){var s=i.call(this,t,n,r)||this;return s._localStream=s.options._stream,s.connectionId=s.options.connectionId||e.ID_PREFIX+_i.randomToken(),s._negotiator=new SD.Negotiator(s),s._localStream&&s._negotiator.startConnection({_stream:s._localStream,originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return ul.Media},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"localStream",{get:function(){return this._localStream},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"remoteStream",{get:function(){return this._remoteStream},enumerable:!1,configurable:!0}),e.prototype.addStream=function(t){ut.default.log("Receiving stream",t),this._remoteStream=t,i.prototype.emit.call(this,"stream",t)},e.prototype.handleMessage=function(t){var n=t.type,r=t.payload;switch(t.type){case jr.Answer:this._negotiator.handleSDP(n,r.sdp),this._open=!0;break;case jr.Candidate:this._negotiator.handleCandidate(r.candidate);break;default:ut.default.warn("Unrecognized message type:".concat(n," from peer:").concat(this.peer));break}},e.prototype.answer=function(t,n){var r,s;if(n===void 0&&(n={}),this._localStream){ut.default.warn("Local stream already exists on this MediaConnection. Are you answering a call twice?");return}this._localStream=t,n&&n.sdpTransform&&(this.options.sdpTransform=n.sdpTransform),this._negotiator.startConnection($1($1({},this.options._payload),{_stream:t}));var o=this.provider._getMessages(this.connectionId);try{for(var a=mde(o),l=a.next();!l.done;l=a.next()){var c=l.value;this.handleMessage(c)}}catch(h){r={error:h}}finally{try{l&&!l.done&&(s=a.return)&&s.call(a)}finally{if(r)throw r.error}}this._open=!0},e.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,i.prototype.emit.call(this,"close"))},e.ID_PREFIX="mc_",e}(ID.BaseConnection),MD={};ql(MD,"DataConnection",()=>Z5,i=>Z5=i);var J5={};ql(J5,"EncodingQueue",()=>K5,i=>K5=i);var gde=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),K5=function(i){gde(e,i);function e(){var t=i.call(this)||this;return t.fileReader=new FileReader,t._queue=[],t._processing=!1,t.fileReader.onload=function(n){t._processing=!1,n.target&&t.emit("done",n.target.result),t.doNextTask()},t.fileReader.onerror=function(n){ut.default.error("EncodingQueue error:",n),t._processing=!1,t.destroy(),t.emit("error",n)},t}return Object.defineProperty(e.prototype,"queue",{get:function(){return this._queue},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"size",{get:function(){return this.queue.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"processing",{get:function(){return this._processing},enumerable:!1,configurable:!0}),e.prototype.enque=function(t){this.queue.push(t),!this.processing&&this.doNextTask()},e.prototype.destroy=function(){this.fileReader.abort(),this._queue=[]},e.prototype.doNextTask=function(){this.size!==0&&(this.processing||(this._processing=!0,this.fileReader.readAsArrayBuffer(this.queue.shift())))},e}(Wv.EventEmitter),Ade=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),vde=function(i){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&i[e],n=0;if(t)return t.call(i);if(i&&typeof i.length=="number")return{next:function(){return i&&n>=i.length&&(i=void 0),{value:i&&i[n++],done:!i}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Z5=function(i){Ade(e,i);function e(t,n,r){var s=i.call(this,t,n,r)||this;return s.stringify=JSON.stringify,s.parse=JSON.parse,s._buffer=[],s._bufferSize=0,s._buffering=!1,s._chunkedData={},s._encodingQueue=new J5.EncodingQueue,s.connectionId=s.options.connectionId||e.ID_PREFIX+_i.randomToken(),s.label=s.options.label||s.connectionId,s.serialization=s.options.serialization||dh.Binary,s.reliable=!!s.options.reliable,s._encodingQueue.on("done",function(o){s._bufferedSend(o)}),s._encodingQueue.on("error",function(){ut.default.error("DC#".concat(s.connectionId,": Error occured in encoding from blob to arraybuffer, close DC")),s.close()}),s._negotiator=new SD.Negotiator(s),s._negotiator.startConnection(s.options._payload||{originator:!0}),s}return Object.defineProperty(e.prototype,"type",{get:function(){return ul.Data},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dataChannel",{get:function(){return this._dc},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"bufferSize",{get:function(){return this._bufferSize},enumerable:!1,configurable:!0}),e.prototype.initialize=function(t){this._dc=t,this._configureDataChannel()},e.prototype._configureDataChannel=function(){var t=this;(!_i.supports.binaryBlob||_i.supports.reliable)&&(this.dataChannel.binaryType="arraybuffer"),this.dataChannel.onopen=function(){ut.default.log("DC#".concat(t.connectionId," dc connection success")),t._open=!0,t.emit("open")},this.dataChannel.onmessage=function(n){ut.default.log("DC#".concat(t.connectionId," dc onmessage:"),n.data),t._handleDataMessage(n)},this.dataChannel.onclose=function(){ut.default.log("DC#".concat(t.connectionId," dc closed for:"),t.peer),t.close()}},e.prototype._handleDataMessage=function(t){var n=this,r=t.data,s=r.constructor,o=this.serialization===dh.Binary||this.serialization===dh.BinaryUTF8,a=r;if(o){if(s===Blob){_i.blobToArrayBuffer(r,function(c){var h=_i.unpack(c);n.emit("data",h)});return}else if(s===ArrayBuffer)a=_i.unpack(r);else if(s===String){var l=_i.binaryStringToArrayBuffer(r);a=_i.unpack(l)}}else this.serialization===dh.JSON&&(a=this.parse(r));if(a.__peerData){this._handleChunk(a);return}i.prototype.emit.call(this,"data",a)},e.prototype._handleChunk=function(t){var n=t.__peerData,r=this._chunkedData[n]||{data:[],count:0,total:t.total};if(r.data[t.n]=t.data,r.count++,this._chunkedData[n]=r,r.total===r.count){delete this._chunkedData[n];var s=new Blob(r.data);this._handleDataMessage({data:s})}},e.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,i.prototype.emit.call(this,"close"))},e.prototype.send=function(t,n){if(!this.open){i.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===dh.JSON)this._bufferedSend(this.stringify(t));else if(this.serialization===dh.Binary||this.serialization===dh.BinaryUTF8){var r=_i.pack(t);if(!n&&r.size>_i.chunkedMTU){this._sendChunks(r);return}_i.supports.binaryBlob?this._bufferedSend(r):this._encodingQueue.enque(r)}else this._bufferedSend(t)},e.prototype._bufferedSend=function(t){(this._buffering||!this._trySend(t))&&(this._buffer.push(t),this._bufferSize=this._buffer.length)},e.prototype._trySend=function(t){var n=this;if(!this.open)return!1;if(this.dataChannel.bufferedAmount>e.MAX_BUFFERED_AMOUNT)return this._buffering=!0,setTimeout(function(){n._buffering=!1,n._tryBuffer()},50),!1;try{this.dataChannel.send(t)}catch(r){return ut.default.error("DC#:".concat(this.connectionId," Error when sending:"),r),this._buffering=!0,this.close(),!1}return!0},e.prototype._tryBuffer=function(){if(this.open&&this._buffer.length!==0){var t=this._buffer[0];this._trySend(t)&&(this._buffer.shift(),this._bufferSize=this._buffer.length,this._tryBuffer())}},e.prototype._sendChunks=function(t){var n,r,s=_i.chunk(t);ut.default.log("DC#".concat(this.connectionId," Try to send ").concat(s.length," chunks..."));try{for(var o=vde(s),a=o.next();!a.done;a=o.next()){var l=a.value;this.send(l,!0)}}catch(c){n={error:c}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},e.prototype.handleMessage=function(t){var n=t.payload;switch(t.type){case jr.Answer:this._negotiator.handleSDP(t.type,n.sdp);break;case jr.Candidate:this._negotiator.handleCandidate(n.candidate);break;default:ut.default.warn("Unrecognized message type:",t.type,"from peer:",this.peer);break}},e.ID_PREFIX="dc_",e.MAX_BUFFERED_AMOUNT=8388608,e}(ID.BaseConnection),$5={};ql($5,"API",()=>iH,i=>iH=i);var eH=function(i,e,t,n){function r(s){return s instanceof t?s:new t(function(o){o(s)})}return new(t||(t=Promise))(function(s,o){function a(h){try{c(n.next(h))}catch(d){o(d)}}function l(h){try{c(n.throw(h))}catch(d){o(d)}}function c(h){h.done?s(h.value):r(h.value).then(a,l)}c((n=n.apply(i,e||[])).next())})},tH=function(i,e){var t={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,r,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(c){return function(h){return l([c,h])}}function l(c){if(n)throw new TypeError("Generator is already executing.");for(;t;)try{if(n=1,r&&(s=c[0]&2?r.return:c[0]?r.throw||((s=r.return)&&s.call(r),0):r.next)&&!(s=s.call(r,c[1])).done)return s;switch(r=0,s&&(c=[c[0]&2,s.value]),c[0]){case 0:case 1:s=c;break;case 4:return t.label++,{value:c[1],done:!1};case 5:t.label++,r=c[1],c=[0];continue;case 7:c=t.ops.pop(),t.trys.pop();continue;default:if(s=t.trys,!(s=s.length>0&&s[s.length-1])&&(c[0]===6||c[0]===2)){t=0;continue}if(c[0]===3&&(!s||c[1]>s[0]&&c[1]<s[3])){t.label=c[1];break}if(c[0]===6&&t.label<s[1]){t.label=s[1],s=c;break}if(s&&t.label<s[2]){t.label=s[2],t.ops.push(c);break}s[2]&&t.ops.pop(),t.trys.pop();continue}c=e.call(i,t)}catch(h){c=[6,h],r=0}finally{n=s=0}if(c[0]&5)throw c[1];return{value:c[0]?c[1]:void 0,done:!0}}},iH=function(){function i(e){this._options=e}return i.prototype._buildRequest=function(e){var t=this._options.secure?"https":"http",n=this._options,r=n.host,s=n.port,o=n.path,a=n.key,l=new URL("".concat(t,"://").concat(r,":").concat(s).concat(o).concat(a,"/").concat(e));return l.searchParams.set("ts","".concat(Date.now()).concat(Math.random())),l.searchParams.set("version",CD.version),fetch(l.href,{referrerPolicy:this._options.referrerPolicy})},i.prototype.retrieveId=function(){return eH(this,void 0,Promise,function(){var e,t,n;return tH(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._buildRequest("id")];case 1:if(e=r.sent(),e.status!==200)throw new Error("Error. Status:".concat(e.status));return[2,e.text()];case 2:throw t=r.sent(),ut.default.error("Error retrieving ID",t),n="",this._options.path==="/"&&this._options.host!==_i.CLOUD_HOST&&(n=" 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."+n);case 3:return[2]}})})},i.prototype.listAllPeers=function(){return eH(this,void 0,Promise,function(){var e,t,n;return tH(this,function(r){switch(r.label){case 0:return r.trys.push([0,2,,3]),[4,this._buildRequest("peers")];case 1:if(e=r.sent(),e.status!==200)throw e.status===401?(t="",this._options.host===_i.CLOUD_HOST?t="It looks like you're using the cloud server. You can email team@peerjs.com to enable peer listing for your API key.":t="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. "+t)):new Error("Error. Status:".concat(e.status));return[2,e.json()];case 2:throw n=r.sent(),ut.default.error("Error retrieving list peers",n),new Error("Could not get list peers from the server."+n);case 3:return[2]}})})},i}(),yde=function(){var i=function(e,t){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(n[s]=r[s])},i(e,t)};return function(e,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");i(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}}(),Xv=function(){return Xv=Object.assign||function(i){for(var e,t=1,n=arguments.length;t<n;t++){e=arguments[t];for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(i[r]=e[r])}return i},Xv.apply(this,arguments)},Yv=function(i){var e=typeof Symbol=="function"&&Symbol.iterator,t=e&&i[e],n=0;if(t)return t.call(i);if(i&&typeof i.length=="number")return{next:function(){return i&&n>=i.length&&(i=void 0),{value:i&&i[n++],done:!i}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},bde=function(i,e){var t=typeof Symbol=="function"&&i[Symbol.iterator];if(!t)return i;var n=t.call(i),r,s=[],o;try{for(;(e===void 0||e-- >0)&&!(r=n.next()).done;)s.push(r.value)}catch(a){o={error:a}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(o)throw o.error}}return s},TD=function(i){yde(e,i);function e(t,n){var r=i.call(this)||this;r._id=null,r._lastServerId=null,r._destroyed=!1,r._disconnected=!1,r._open=!1,r._connections=new Map,r._lostMessages=new Map;var s;return t&&t.constructor==Object?n=t:t&&(s=t.toString()),n=Xv({debug:0,host:_i.CLOUD_HOST,port:_i.CLOUD_PORT,path:"/",key:e.DEFAULT_KEY,token:_i.randomToken(),config:_i.defaultConfig,referrerPolicy:"strict-origin-when-cross-origin"},n),r._options=n,r._options.host==="/"&&(r._options.host=window.location.hostname),r._options.path&&(r._options.path[0]!=="/"&&(r._options.path="/"+r._options.path),r._options.path[r._options.path.length-1]!=="/"&&(r._options.path+="/")),r._options.secure===void 0&&r._options.host!==_i.CLOUD_HOST?r._options.secure=_i.isSecure():r._options.host==_i.CLOUD_HOST&&(r._options.secure=!0),r._options.logFunction&&ut.default.setLogFunction(r._options.logFunction),ut.default.logLevel=r._options.debug||0,r._api=new $5.API(n),r._socket=r._createServerConnection(),!_i.supports.audioVideo&&!_i.supports.data?(r._delayedAbort(Fn.BrowserIncompatible,"The current browser does not support WebRTC"),r):s&&!_i.validateId(s)?(r._delayedAbort(Fn.InvalidID,'ID "'.concat(s,'" is invalid')),r):(s?r._initialize(s):r._api.retrieveId().then(function(o){return r._initialize(o)}).catch(function(o){return r._abort(Fn.ServerError,o)}),r)}return Object.defineProperty(e.prototype,"id",{get:function(){return this._id},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this._options},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"open",{get:function(){return this._open},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"socket",{get:function(){return this._socket},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"connections",{get:function(){var t,n,r=Object.create(null);try{for(var s=Yv(this._connections),o=s.next();!o.done;o=s.next()){var a=bde(o.value,2),l=a[0],c=a[1];r[l]=c}}catch(h){t={error:h}}finally{try{o&&!o.done&&(n=s.return)&&n.call(s)}finally{if(t)throw t.error}}return r},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"destroyed",{get:function(){return this._destroyed},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"disconnected",{get:function(){return this._disconnected},enumerable:!1,configurable:!0}),e.prototype._createServerConnection=function(){var t=this,n=new V5.Socket(this._options.secure,this._options.host,this._options.port,this._options.path,this._options.key,this._options.pingInterval);return n.on(ph.Message,function(r){t._handleMessage(r)}),n.on(ph.Error,function(r){t._abort(Fn.SocketError,r)}),n.on(ph.Disconnected,function(){t.disconnected||(t.emitError(Fn.Network,"Lost connection to server."),t.disconnect())}),n.on(ph.Close,function(){t.disconnected||t._abort(Fn.SocketClosed,"Underlying socket is already closed.")}),n},e.prototype._initialize=function(t){this._id=t,this.socket.start(t,this._options.token)},e.prototype._handleMessage=function(t){var n,r,s=t.type,o=t.payload,a=t.src;switch(s){case jr.Open:this._lastServerId=this.id,this._open=!0,this.emit("open",this.id);break;case jr.Error:this._abort(Fn.ServerError,o.msg);break;case jr.IdTaken:this._abort(Fn.UnavailableID,'ID "'.concat(this.id,'" is taken'));break;case jr.InvalidKey:this._abort(Fn.InvalidKey,'API KEY "'.concat(this._options.key,'" is invalid'));break;case jr.Leave:ut.default.log("Received leave message from ".concat(a)),this._cleanupPeer(a),this._connections.delete(a);break;case jr.Expire:this.emitError(Fn.PeerUnavailable,"Could not connect to peer ".concat(a));break;case jr.Offer:var m=o.connectionId,A=this.getConnection(a,m);if(A&&(A.close(),ut.default.warn("Offer received for existing Connection ID:".concat(m))),o.type===ul.Media){var l=new ED.MediaConnection(a,this,{connectionId:m,_payload:o,metadata:o.metadata});A=l,this._addConnection(a,A),this.emit("call",l)}else if(o.type===ul.Data){var c=new MD.DataConnection(a,this,{connectionId:m,_payload:o,metadata:o.metadata,label:o.label,serialization:o.serialization,reliable:o.reliable});A=c,this._addConnection(a,A),this.emit("connection",c)}else{ut.default.warn("Received malformed connection type:".concat(o.type));return}var h=this._getMessages(m);try{for(var d=Yv(h),p=d.next();!p.done;p=d.next()){var f=p.value;A.handleMessage(f)}}catch(v){n={error:v}}finally{try{p&&!p.done&&(r=d.return)&&r.call(d)}finally{if(n)throw n.error}}break;default:if(!o){ut.default.warn("You received a malformed message from ".concat(a," of type ").concat(s));return}var m=o.connectionId,A=this.getConnection(a,m);A&&A.peerConnection?A.handleMessage(t):m?this._storeMessage(m,t):ut.default.warn("You received an unrecognized message:",t);break}},e.prototype._storeMessage=function(t,n){this._lostMessages.has(t)||this._lostMessages.set(t,[]),this._lostMessages.get(t).push(n)},e.prototype._getMessages=function(t){var n=this._lostMessages.get(t);return n?(this._lostMessages.delete(t),n):[]},e.prototype.connect=function(t,n){if(n===void 0&&(n={}),this.disconnected){ut.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(Fn.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}var r=new MD.DataConnection(t,this,n);return this._addConnection(t,r),r},e.prototype.call=function(t,n,r){if(r===void 0&&(r={}),this.disconnected){ut.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(Fn.Disconnected,"Cannot connect to new Peer after disconnecting from server.");return}if(!n){ut.default.error("To call a peer, you must provide a stream from your browser's `getUserMedia`.");return}var s=new ED.MediaConnection(t,this,Xv(Xv({},r),{_stream:n}));return this._addConnection(t,s),s},e.prototype._addConnection=function(t,n){ut.default.log("add connection ".concat(n.type,":").concat(n.connectionId," to peerId:").concat(t)),this._connections.has(t)||this._connections.set(t,[]),this._connections.get(t).push(n)},e.prototype._removeConnection=function(t){var n=this._connections.get(t.peer);if(n){var r=n.indexOf(t);r!==-1&&n.splice(r,1)}this._lostMessages.delete(t.connectionId)},e.prototype.getConnection=function(t,n){var r,s,o=this._connections.get(t);if(!o)return null;try{for(var a=Yv(o),l=a.next();!l.done;l=a.next()){var c=l.value;if(c.connectionId===n)return c}}catch(h){r={error:h}}finally{try{l&&!l.done&&(s=a.return)&&s.call(a)}finally{if(r)throw r.error}}return null},e.prototype._delayedAbort=function(t,n){var r=this;setTimeout(function(){r._abort(t,n)},0)},e.prototype._abort=function(t,n){ut.default.error("Aborting!"),this.emitError(t,n),this._lastServerId?this.disconnect():this.destroy()},e.prototype.emitError=function(t,n){ut.default.error("Error:",n);var r;typeof n=="string"?r=new Error(n):r=n,r.type=t,this.emit("error",r)},e.prototype.destroy=function(){this.destroyed||(ut.default.log("Destroy peer with ID:".concat(this.id)),this.disconnect(),this._cleanup(),this._destroyed=!0,this.emit("close"))},e.prototype._cleanup=function(){var t,n;try{for(var r=Yv(this._connections.keys()),s=r.next();!s.done;s=r.next()){var o=s.value;this._cleanupPeer(o),this._connections.delete(o)}}catch(a){t={error:a}}finally{try{s&&!s.done&&(n=r.return)&&n.call(r)}finally{if(t)throw t.error}}this.socket.removeAllListeners()},e.prototype._cleanupPeer=function(t){var n,r,s=this._connections.get(t);if(s)try{for(var o=Yv(s),a=o.next();!a.done;a=o.next()){var l=a.value;l.close()}}catch(c){n={error:c}}finally{try{a&&!a.done&&(r=o.return)&&r.call(o)}finally{if(n)throw n.error}}},e.prototype.disconnect=function(){if(!this.disconnected){var t=this.id;ut.default.log("Disconnect peer with ID:".concat(t)),this._disconnected=!0,this._open=!1,this.socket.close(),this._lastServerId=t,this._id=null,this.emit("disconnected",t)}},e.prototype.reconnect=function(){if(this.disconnected&&!this.destroyed)ut.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)ut.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!"))}},e.prototype.listAllPeers=function(t){var n=this;t===void 0&&(t=function(r){}),this._api.listAllPeers().then(function(r){return t(r)}).catch(function(r){return n._abort(Fn.ServerError,r)})},e.DEFAULT_KEY="peerjs",e}(Wv.EventEmitter),BD=j5.Peer;const xde=Object.freeze(Object.defineProperty({__proto__:null,get Peer(){return TD},default:BD,util:_i},Symbol.toStringTag,{value:"Module"}));let RD;function _de(){return RD}function wde(i){RD=i}function nH(i,e){return e||(e={}),e={...RD,...e},i?new BD(i,e):new BD(e)}async function rH(){const i=await Promise.resolve().then(()=>xde);return console.log(i),i.default===void 0?i:i.default}class sH{constructor(){u(this,"_host"),u(this,"_client"),u(this,"_clientData"),this.onEnable()}get isHost(){return this._host!==void 0}onEnable(){const e="HOST-5980e65c-8438-453e-8b35-f13c736dcd81";this.trySetupHost(e)}async trySetupHost(e){const t=await rH(),n=new t(e);n.on("error",r=>{console.error(r),this._host=void 0,this.trySetupClient(e)}),n.on("open",r=>{this._host=new Ede(n)})}async trySetupClient(e){const t=await rH();this._client=new t,this._client.on("error",n=>{console.error("Client error",n)}),this._client.on("open",n=>{console.log("client connected",n),this._clientData=this._client.connect(e,{metadata:{id:n}}),this._clientData.on("open",()=>{console.log("Connected to host")}),this._clientData.on("data",r=>{console.log("<<",r)})})}}class Cde{constructor(e){u(this,"_peer"),this._peer=e}}class Ede extends Cde{constructor(e){var t;super(e),u(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(n=>{var r;return(r=n.metadata)==null?void 0:r.id}).filter(n=>n!==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 n=this._peer.connections[t];if(n)if(Array.isArray(n))for(const r of n)r&&r.send(e);else console.warn(n)}}}}const oH="https://urls.needle.tools/default-networking-backend/index";let Qu="wss://needle-tiny-starter.glitch.me/socket";const Ks=!!ee("debugnet"),Jv=!!(Ks||ee("debugowner")),aH=ee("debugnetbin");var lH=(i=>(i.ConnectionInfo="connection-start-info",i))(lH||{}),ti=(i=>(i.Join="join-room",i.Leave="leave-room",i.JoinedRoom="joined-room",i.LeftRoom="left-room",i.UserJoinedRoom="user-joined-room",i.UserLeftRoom="user-left-room",i.RoomStateSent="room-state-sent",i))(ti||{});class Sde{constructor(){u(this,"room"),u(this,"viewId"),u(this,"allowEditing"),u(this,"inRoom")}}class Ide{constructor(){u(this,"room")}}class Mde{constructor(){u(this,"userId")}}var cH=(i=>(i.RequestHasOwner="request-has-owner",i.ResponseHasOwner="response-has-owner",i.RequestIsOwner="request-is-owner",i.ResponseIsOwner="response-is-owner",i.RequestOwnership="request-ownership",i.GainedOwnership="gained-ownership",i.RemoveOwnership="remove-ownership",i.LostOwnership="lost-ownership",i.GainedOwnershipBroadcast="gained-ownership-broadcast",i.LostOwnershipBroadcast="lost-ownership-broadcast",i))(cH||{});class DD{constructor(e,t){u(this,"guid"),u(this,"connection"),u(this,"_hasOwnership",!1),u(this,"_isOwned"),u(this,"_gainSubscription"),u(this,"_lostSubscription"),u(this,"_hasOwnerResponse"),u(this,"_isWaitingForOwnershipResponseCallback",null),this.connection=e,this.guid=t,this._gainSubscription=this.onGainedOwnership.bind(this),this._lostSubscription=this.onLostOwnership.bind(this),e.beginListen("lost-ownership",this._lostSubscription),e.beginListen("gained-ownership-broadcast",this._gainSubscription),this._hasOwnerResponse=this.onHasOwnerResponse.bind(this),e.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(e){e.guid===this.guid&&(this._isOwned=e.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(e){e.guid===this.guid&&(this._isWaitingForOwnershipResponseCallback&&(this.connection.stopListen("response-has-owner",this._isWaitingForOwnershipResponseCallback),this._isWaitingForOwnershipResponseCallback=null),this._isOwned=e.value,e.value||(Jv&&console.log("request ownership",this.guid),this.requestOwnership()))}requestOwnershipAsync(){return new Promise((e,t)=>{this.requestOwnership();let n=0;const r=()=>{if(n++>10)return t("Timeout");setTimeout(()=>{this.hasOwnership?e(this):r()},100)};r()})}requestOwnership(){return Jv&&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(e){e.guid===this.guid&&(this._isOwned=!0,this.connection.connectionId===e.owner?(Jv&&console.log("GAINED OWNERSHIP",this.guid),this._hasOwnership=!0):this._hasOwnership=!1)}onLostOwnership(e){e===this.guid&&(Jv&&console.log("LOST OWNERSHIP",this.guid),this._hasOwnership=!1,this._isOwned=!1)}}class hH{constructor(e){u(this,"context"),u(this,"_peer",null),u(this,"_usersInRoomCopy",[]),u(this,"_defaultMessagesBuffer",[]),u(this,"_defaultMessagesBufferArray",[]),u(this,"netWebSocketUrlProvider"),u(this,"_listeners",{}),u(this,"_listenersBinary",{}),u(this,"connected",!1),u(this,"channelId"),u(this,"_connectionId",null),u(this,"_ws"),u(this,"_waitingForSocket",{}),u(this,"_isInRoom",!1),u(this,"_currentRoomName",null),u(this,"_currentRoomViewId",null),u(this,"_currentRoomAllowEditing",!0),u(this,"_currentInRoom",[]),u(this,"_state",{}),u(this,"_currentDelay",-1),u(this,"_connectingToWebsocketPromise",null),this.context=e}get peer(){return this._peer||(this._peer=new sH),this._peer}tryGetState(e){return e==="invalid"?null:this._state[e]}get connectionId(){return this._connectionId}get isDebugEnabled(){return Ks}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 e=new URL(window.location.href);return e.searchParams.set("view",this.currentRoomViewId),e.href}get isInRoom(){return this._isInRoom}get currentLatency(){return this._currentDelay}get currentServerUrl(){var e;return((e=this._ws)==null?void 0:e.url)??null}sendPing(){this.send("ping",{time:this.context.time.time})}userIsInRoom(e){return this._currentInRoom.indexOf(e)!==-1}usersInRoom(e=null){e||(e=this._usersInRoomCopy),e.length=0;for(const t of this._currentInRoom)e.push(t);return e}joinRoom(e,t=!1){return e?e.length>1024?(console.error('Room name too long, can not join: "'+e+'". Max length is 1024 characters.'),!1):(this.connect(),Ks&&console.log("join: "+e),this.send("join-room",{room:e,viewOnly:t},ya.OnConnection),!0):(console.error('Missing room name, can not join: "'+e+'"'),!1)}leaveRoom(e=null){return e||(e=this.currentRoomName),e?(this.send("leave-room",{room:e}),!0):(console.error('Missing room name, can not join: "'+e+'"'),!1)}send(e,t=null,n=ya.Queued){if(t===null&&(t={}),n===ya.Queued){this._defaultMessagesBuffer.push({key:e,value:t});return}return this.sendWithWebsocket(e,t,n)}sendDeleteRemoteState(e){this.send("delete-state",{guid:e,dontSave:!0}),delete this._state[e]}sendDeleteRemoteStateAll(){this.send("delete-all-state"),this._state={}}sendBinary(e){var t;aH&&console.log("<< send binary",this.context.time.frame,e.length/1024+" KB"),(t=this._ws)==null||t.send(e)}sendBufferedMessagesNow(){var e;if(!this._ws)return;this._defaultMessagesBufferArray.length=0;const t=Object.keys(this._defaultMessagesBuffer).length;for(const r in this._defaultMessagesBuffer){const s=this._defaultMessagesBuffer[r];if(t<=1){this.sendWithWebsocket(s.key,s.value,ya.Immediate);break}const o=this.toMessage(s.key,s.value);this._defaultMessagesBufferArray.push(o)}if(this._defaultMessagesBuffer.length=0,this._defaultMessagesBufferArray.length>0&&Ks&&console.log("SEND BUFFERED",this._defaultMessagesBufferArray.length),this._defaultMessagesBufferArray.length<=0)return;const n=JSON.stringify(this._defaultMessagesBufferArray);(e=this._ws)==null||e.send(n)}beginListen(e,t){return this._listeners[e]||(this._listeners[e]=[]),this._listeners[e].push(t),t}stopListening(e,t){return this.stopListen(e,t)}stopListen(e,t){if(!t||!this._listeners[e])return;const n=this._listeners[e].indexOf(t);n>=0&&this._listeners[e].splice(n,1)}beginListenBinary(e,t){return this._listenersBinary[e]||(this._listenersBinary[e]=[]),this._listenersBinary[e].push(t),t}stopListenBinary(e,t){if(!this._listenersBinary[e])return;const n=this._listenersBinary[e].indexOf(t);n>=0&&this._listenersBinary[e].splice(n,1)}registerProvider(e){this.netWebSocketUrlProvider=e}async connect(){var e;if(this.connected)return Promise.resolve(!0);Ks&&console.log("connecting");const t=(e=this.netWebSocketUrlProvider)==null?void 0:e.getWebsocketUrl();return t?Qu=t:_N()&&(Qu="wss://"+window.location.host+"/socket"),this.connectWebsocket()}disconnect(){var e;(e=this._ws)==null||e.close(),this._ws=void 0}connectWebsocket(){return this._connectingToWebsocketPromise?this._connectingToWebsocketPromise:this._connectingToWebsocketPromise=new Promise(async(e,t)=>{var n;let r=!1;const s=c=>{r||(r=!0,e(c))};if(Qu===void 0&&(console.log("Fetch default backend url: "+oH),Qu=await(await fetch(oH)).text()),Qu===void 0){s(!1);return}console.log(`\u22A1 Connecting to networking backend on
5235
5235
  `+Qu);const o=await Promise.resolve().then(()=>Xxe),a=((n=o.default)==null?void 0:n.WebsocketBuilder)??o.WebsocketBuilder,l=new a(Qu).onOpen(()=>{this._connectingToWebsocketPromise=null,this._ws=l,this.connected=!0,console.log(`\u229E Connected to networking backend
5236
5236
  `+Qu),s(!0),this.onSendQueued(ya.OnConnection)}).onClose(c=>{this._connectingToWebsocketPromise=null,this.connected=!1,this._isInRoom=!1,s(!1)}).onError((c,h)=>{console.error("\u22A0 Websocket error",c,h),s(!1)}).onRetry(()=>{console.log("Retry connecting to networking websocket")}).build();l.addEventListener(o.WebsocketEvent.message,(c,h)=>{this.onMessage(c,h)})})}onMessage(e,t){const n=t.data;try{if(typeof n!="string"){n.size&&this.handleIncomingBinaryMessage(n);return}const r=JSON.parse(n);if(Array.isArray(r))for(const s of r)this.handleIncomingStringMessage(s);else this.handleIncomingStringMessage(r);return}catch(r){Ks&&n==="pong"?console.log("<<",n):st()&&console.error("Failed to parse message",r)}}async handleIncomingBinaryMessage(e){aH&&console.log("<< bin",this.context.time.frame);const t=await e.arrayBuffer();var n=new Uint8Array(t);const r=new Yb(n),s=r.getBufferIdentifier(),o=this._listenersBinary[s],a=GG(r),l=HG(a);if(l&&typeof l=="string"&&(this._state[l]=a),!o)return;const c=a??r;for(const h of o)h(c)}handleIncomingStringMessage(e){var t,n;if(Ks&&console.log("<<",e.key??e),e.key)switch(e.key){case"connection-start-info":if(e.data){const a=e.data;a&&(console.assert(a.id!==void 0&&a.id!==null&&a.id.length>0,"server did not send connection id",a.id),console.log("Your id is: "+a.id,this.context.alias??""),this._connectionId=a.id)}else console.warn("Expected connection id in "+e.key);break;case"joined-room":if(Ks&&console.log(e),e){this._isInRoom=!0;const a=e;this._currentRoomName=a.room,this._currentRoomViewId=a.viewId,this._currentRoomAllowEditing=a.allowEditing??!0,this._currentInRoom.length=0,this._currentInRoom.push(...a.inRoom),Ks&&console.log("joined room with",this._currentInRoom,this.context.alias??"");const l=new URL(window.location.href);l.searchParams.has("room")&&l.searchParams.delete("room"),l.searchParams.set("view",this._currentRoomViewId),console.log("Room view id: "+this._currentRoomViewId+`
5237
- `+l.href)}this.onSendQueued(ya.OnRoomJoin);break;case"left-room":e.room===this.currentRoomName&&(this._isInRoom=!1,this._currentRoomName=null,this._currentInRoom.length=0);break;case"user-joined-room":if(e.data){const a=e.data;this._currentInRoom.push(a.userId),Ks&&console.log(a.userId+" joined","now in room:",this._currentInRoom)}break;case"user-left-room":if(e.data){const a=e.data,l=this._currentInRoom.indexOf(a.userId);l>=0&&(Ks&&console.log(a.userId+" left","now in room:",this._currentInRoom),this._currentInRoom.splice(l,1)),a.userId===this.connectionId&&console.log("you left the room")}break;case"all-room-state-deleted":Ks&&console.log("RECEIVED all-room-state-deleted"),this._state={};break;case"ping":case"pong":const o=(t=e.data)==null?void 0:t.time;o&&(this._currentDelay=this.context.time.time-o),Ks&&console.log("Current latency: "+this._currentDelay.toFixed(1)+" sec","Clients in room: "+((n=this._currentInRoom)==null?void 0:n.length));break}let r=this._listeners[e.key];if(r){r=[...r];for(const o of r)try{o(e.data)}catch(a){console.error('Error invoking callback for "'+e.key+'"',a)}}const s=e.data;s&&(this._state[s.guid]=s)}toMessage(e,t){return{key:e,data:t}}sendWithWebsocket(e,t,n=ya.OnRoomJoin){if(!this._ws){const s=this._waitingForSocket[n]||[];s.push(()=>this.sendWithWebsocket(e,t,n)),this._waitingForSocket[n]=s;return}const r=JSON.stringify(this.toMessage(e,t));Ks&&console.log(">>",e),this._ws.send(r)}onSendQueued(e){const t=this._waitingForSocket[e];if(t){for(const n of t)n();t.length=0}}}const Kv=ee("debugwebxr");class PD{constructor(e,t){u(this,"controllerStates",[]),u(this,"userId"),u(this,"context"),u(this,"userStateEvtName"),u(this,"onReceivedControllerState",n=>{Kv&&console.log(`XRSync: Received change for ${this.userId}: ${n.type} ${n.handedness}; tracked=${n.isTracking}`);let r=!1;for(let s=0;s<this.controllerStates.length;s++)if(this.controllerStates[s].index===n.index){this.controllerStates[s]=n,r=!0;break}r||this.controllerStates.push(n)}),this.userId=e,this.context=t,this.userStateEvtName="xr-sync-user-state-"+e,this.context.connection.beginListen(this.userStateEvtName,this.onReceivedControllerState)}dispose(){this.context.connection.stopListen(this.userStateEvtName,this.onReceivedControllerState)}update(e){if(this.context.connection.isConnected!=!1){for(let t=this.controllerStates.length-1;t>=0;t--){const n=this.controllerStates[t];let r=!1;for(let s=0;s<e.controllers.length;s++)e.controllers[s].index===n.index&&(r=!0);r||(Kv&&console.log(`XRSync: ${n.type} ${n.handedness} removed`,n.index),this.controllerStates.splice(t,1),this.sendControllerRemoved(n))}for(const t of e.controllers)this.updateControllerStates(t)}}onExitXR(e){for(const t of this.controllerStates)this.sendControllerRemoved(t);this.controllerStates.length=0}sendControllerRemoved(e){e.isTracking=!1,e.guid="",this.context.connection.send(this.userStateEvtName,e),this.context.connection.sendDeleteRemoteState(e.guid)}updateControllerStates(e){const t=this.controllerStates.find(n=>n.index===e.index);if(t){let n=!1;n||(n=t.isTracking!=e.isTracking),n&&(t.isTracking=e.isTracking,this.context.connection.send(this.userStateEvtName,t))}else{const n={guid:this.userId+"-"+e.index,isTracking:e.isTracking,handedness:e.side,index:e.index,type:e.hand?"hand":"controller"};this.controllerStates.push(n),this.context.connection.send(this.userStateEvtName,n),Kv&&console.log(`XRSync: ${n.type} ${n.handedness} added`,n.index)}}}class uH{constructor(e){u(this,"context"),u(this,"onJoinedRoom",()=>{if(this.context.connection.connectionId){this._states.has(this.context.connection.connectionId)||(Kv&&console.log("XRSync: Local user joined room",this.context.connection.connectionId),this._states.set(this.context.connection.connectionId,new PD(this.context.connection.connectionId,this.context)));for(const t of this.context.connection.usersInRoom())this._states.has(t)||this._states.set(t,new PD(t,this.context))}}),u(this,"onLeftRoom",()=>{if(this.context.connection.connectionId&&!this._states.has(this.context.connection.connectionId)){const t=this._states.get(this.context.connection.connectionId);t?.dispose(),this._states.delete(this.context.connection.connectionId)}}),u(this,"onOtherUserJoinedRoom",t=>{const n=t.userId;this._states.has(n)||(Kv&&console.log("XRSync: Remote user joined room",n),this._states.set(n,new PD(n,this.context)))}),u(this,"onOtherUserLeftRoom",t=>{const n=t.userId;if(!this._states.has(n)){const r=this._states.get(n);r?.dispose(),this._states.delete(n)}}),u(this,"_states",new Map),this.context=e,this.context.connection.beginListen(ti.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ti.LeftRoom,this.onLeftRoom),this.context.connection.beginListen(ti.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.beginListen(ti.UserLeftRoom,this.onOtherUserLeftRoom)}hasState(e){return e?this._states.has(e):!1}isTracking(e,t){if(!e)return;const n=this._states.get(e);if(!n)return;const r=n.controllerStates.find(s=>s.handedness===t);return r?.isTracking||!1}getDeviceType(e,t){if(!e)return;const n=this._states.get(e);if(!n)return;const r=n.controllerStates.find(s=>s.handedness===t);return r?.type||"unknown"}destroy(){this.context.connection.stopListen(ti.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ti.LeftRoom,this.onLeftRoom),this.context.connection.stopListen(ti.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.stopListen(ti.UserLeftRoom,this.onOtherUserLeftRoom)}onUpdate(e){if(this.context.connection.isConnected&&this.context.connection.connectionId){const t=this._states.get(this.context.connection.connectionId);t?.update(e)}}onExitXR(e){if(this.context.connection.isConnected&&this.context.connection.connectionId){const t=this._states.get(this.context.connection.connectionId);t?.onExitXR(e)}}}class dH{constructor(){u(this,"_fadeToColorQuad"),u(this,"_fadeToColorMaterial"),u(this,"_requestedFadeValue",0),u(this,"_transitionPromise",null),u(this,"_transitionResolve",null),this._fadeToColorMaterial=new Kt({color:0,transparent:!0,depthTest:!1,fog:!1,side:mi}),this._fadeToColorQuad=new pe(new tr(10,10),this._fadeToColorMaterial)}dispose(){this._fadeToColorQuad.geometry.dispose(),this._fadeToColorMaterial.dispose()}update(e,t){const n=this._fadeToColorQuad,r=this._fadeToColorMaterial;n.parent!==e&&r.opacity>0?e.add(n):r.opacity===0&&n.removeFromParent(),n.layers.set(2),n.material=this._fadeToColorMaterial,n.position.z=-1,n.renderOrder=1/0;const s=this._requestedFadeValue;r.opacity=$e.lerp(r.opacity,s,t/.03),Math.abs(r.opacity-s)<=.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 e=new Promise(t=>{this._transitionResolve=t});return this._transitionPromise=e,e}}var zp=(i=>(i[i.Quad=0]="Quad",i[i.Cube=1]="Cube",i[i.Sphere=2]="Sphere",i))(zp||{});class Zv{static createPrimitive(e,t){let n;switch(e){case"Quad":case 0:{const r=new tr(1,1,1,1),s=t?.material??new ds({color:16777215});t!=null&&t.texture&&"map"in s&&(s.map=t.texture),n=new pe(r,s)}break;case"Cube":case 1:{const r=new Vi(1,1,1),s=t?.material??new ds({color:16777215});t!=null&&t.texture&&"map"in s&&(s.map=t.texture),n=new pe(r,s)}break;case"Sphere":case 2:{const r=new _l(.5,16,16),s=t?.material??new ds({color:16777215});t!=null&&t.texture&&"map"in s&&(s.map=t.texture),n=new pe(r,s)}break}return this.applyDefaultObjectOptions(n,t),n}static createSprite(e){const t=new r_({color:16777215});e!=null&&e.texture&&"map"in t&&(t.map=e.texture);const n=new pM(t);return this.applyDefaultObjectOptions(n,e),n}static applyDefaultObjectOptions(e,t){t!=null&&t.name&&(e.name=t.name),t!=null&&t.position&&e.position.set(t.position.x,t.position.y,t.position.z),t!=null&&t.rotation&&e.rotation.set(t.rotation.x,t.rotation.y,t.rotation.z),t!=null&&t.scale&&e.scale.set(t.scale.x,t.scale.y,t.scale.z)}}const pH=class{constructor(i,e,t){u(this,"_session"),u(this,"_mode"),u(this,"_init"),u(this,"_renderer"),u(this,"_camera"),u(this,"_scene"),u(this,"onEnd",()=>{var n;(n=this._session)==null||n.removeEventListener("end",this.onEnd),this._renderer.setAnimationLoop(null),this._renderer.dispose(),this._scene.clear()}),u(this,"_lastTime",0),u(this,"onFrame",(n,r)=>{const s=n-this._lastTime;this.update(n,s),this._camera.parent!==this._scene&&this._scene.add(this._camera),this._renderer.render(this._scene,this._camera)}),u(this,"_objects",[]),this._mode=i,this._init=e,this._session=t,this._session.addEventListener("end",this.onEnd),this._renderer=new Qc({alpha:!0}),this._renderer.setAnimationLoop(this.onFrame),this._renderer.xr.setSession(t),this._renderer.xr.enabled=!0,this._camera=new Rt,this._scene=new Lr,this._scene.fog=new n_(4473924,10,250),this._scene.add(this._camera),this.setupScene()}static get active(){return this._active}static async start(i,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(i,e);return t.addEventListener("end",()=>{this._active=null}),this._requestInFlight?(this._requestInFlight=!1,this._active=new pH(i,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 kl(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 i={session:this._session,mode:this._mode,init:this._init};return await this.onBeforeHandoff(),this.onEnd(),this._session=null,i}async onBeforeHandoff(){await kl(1e3),this._scene.clear()}setupScene(){this._scene.background=new _e(0),this._scene.add(new Q_(5,10,1118481,1118481));const i=new Zd(16777215,1);i.position.set(0,20,0),i.castShadow=!1,this._scene.add(i);const e=new Zd(16777215,1);e.position.set(0,-1,0),e.castShadow=!1,this._scene.add(e);const t=new Kd(16777215,1,100,1);t.position.set(0,2,0),t.castShadow=!1,t.distance=200,this._scene.add(t);const n=50;for(let r=0;r<100;r++){const s=new ds({color:2236962,metalness:1,roughness:.8});this.isAR&&(s.emissive=new _e(Math.random(),Math.random(),Math.random()),s.emissiveIntensity=Math.random());const o=$e.random(0,1)>.5?zp.Sphere:zp.Cube,a=Zv.createPrimitive(o,{material:s});a.position.x=$e.random(-n,n),a.position.y=$e.random(-2,n),a.position.z=$e.random(-n,n),a.rotation.x=$e.random(0,Math.PI*2),a.rotation.y=$e.random(0,Math.PI*2),a.rotation.z=$e.random(0,Math.PI*2),a.scale.multiplyScalar(.5+Math.random()*10);const l=a.position.distanceTo(this._camera.position)-a.scale.x;l<1&&a.position.multiplyScalar(1+1/l),this._objects.push(a),this._scene.add(a)}}update(i,e){const t=i*4e-4;for(let n=0;n<this._objects.length;n++){const r=this._objects[n];r.position.y+=Math.sin(t+n*.5)*.005,r.rotateY(.002)}}};let wg=pH;u(wg,"_active",null),u(wg,"_requestInFlight",!1);const wr=ee("debugwebxr"),Tde=ee("stats");function Bde(i){let e=null;const t=i;return t.getAROverlayContainer?e=t.getAROverlayContainer():e=i,e}Rde();async function Rde(){var i;if(ee("debugasap")){let e=globalThis["needle:XRSession"];if(e instanceof Promise){delete globalThis["needle:XRSession"],hi.addContextCreatedCallback(async t=>{if(!e)return;Mm(!0);const n=await e;if(n){const r=_t.getDefaultSessionInit("immersive-vr");_t.setSession("immersive-vr",n,r,t.context)}else console.error("NeedleXRSession: ASAP session was rejected");e=void 0});return}}if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent)){console.warn("WebXRViewer does not support addEventListener");return}(i=navigator.xr)==null||i.addEventListener("sessiongranted",async()=>{Mm(!0),console.log("Received Session Granted..."),await kl(100);const e=sessionStorage.getItem("needle_xr_session_mode"),t=sessionStorage.getItem("needle_xr_session_init")??null,n=t?JSON.parse(t):null;let r=null;if(fH()&&(await wg.start(e||"immersive-vr",n||_t.getDefaultSessionInit("immersive-vr")),await kde(),r=await wg.handoff()),r)_t.setSession(r.mode,r.session,r.init,Pt.Current);else if(e&&t){console.log("Session Granted: Restore last session");const s=JSON.parse(t);_t.start(e,s).catch(o=>console.warn(o))}else _t.start("immersive-vr").catch(s=>console.warn("Session Granted failed:",s))},{once:!0})}}function Dde(i,e){sessionStorage.setItem("needle_xr_session_mode",i),sessionStorage.setItem("needle_xr_session_init",JSON.stringify(e))}function Pde(){sessionStorage.removeItem("needle_xr_session_mode"),sessionStorage.removeItem("needle_xr_session_init")}const kD=new Set;hi.registerCallback(Ei.ContextCreationStart,async i=>{kD.add(i.context)}),hi.registerCallback(Ei.ContextCreated,async i=>{kD.delete(i.context)});function fH(){return kD.size>0}function kde(){return new Promise(i=>{const e=Date.now(),t=setInterval(()=>{(!fH()||Date.now()-e>6e4)&&(clearInterval(t),i())},100)})}sp()&&st()&&window.addEventListener("keydown",i=>{(i.key==="x"||i.key==="Escape")&&_t.active&&_t.stop()});const zu=class{constructor(i,e,t,n){u(this,"context"),u(this,"session"),u(this,"mode"),u(this,"controllers",[]),u(this,"_rigScale",1),u(this,"_lastRigScaleUpdate",-1),u(this,"_rigs",[]),u(this,"_viewerHitTestSource",null),u(this,"_defaultRig"),u(this,"_xr_scripts"),u(this,"_xr_update_scripts",[]),u(this,"_inactive_scripts",[]),u(this,"_controllerAdded"),u(this,"_controllerRemoved"),u(this,"_originalCameraWorldPosition"),u(this,"_originalCameraWorldRotation"),u(this,"_originalCameraWorldScale"),u(this,"_originalCameraParent"),u(this,"_mainCamera",null),u(this,"onRendererSessionSet",()=>{var o;this.running&&(this.context.renderer.xr.enabled=!0,this.context.renderer.xr.updateCamera(this.context.mainCamera),(o=this.context.mainCameraComponent)==null||o.applyClearFlags())}),u(this,"onInputSourceAdded",o=>{if(o.targetRayMode==="screen")return;let a=0;for(let c=0;c<this.session.inputSources.length;c++)if(this.session.inputSources[c]===o){a=c;break}if(this.controllers.find(c=>c.inputSource===o)){console.warn("Controller already exists for input source",a);return}wr&&console.log("Adding controller",a);const l=new lD(this,o,a);this._newControllers.push(l)}),u(this,"_ended",!1),u(this,"_newControllers",[]),u(this,"onEnd",o=>{var a,l,c;if(this._ended)return;this._ended=!0,wr&&console.log("XR Session ended"),Pde(),this.onAfterRender(),this.revertCustomForward(),this._didStart=!1,this._previousCameraParent=null,Uu(this.onBefore,ji.LateUpdate);const h=this.context.pre_render_callbacks.indexOf(this.onBeforeRender);h>=0&&this.context.pre_render_callbacks.splice(h,1);const d=this.context.post_render_callbacks.indexOf(this.onAfterRender);d>=0&&this.context.post_render_callbacks.splice(d,1),this.context.xr=null,this.context.renderer.xr.enabled=!1,this.context.pre_update_oneshot_callbacks.push(()=>{var p;(p=this.context.mainCameraComponent)==null||p.applyClearFlags()}),kG({session:this});for(const p of zu._xrEndListeners)p({xr:this});for(let p=0;p<this.controllers.length;p++)this.disconnectInputSource(this.controllers[p].inputSource);for(const p of this._xr_scripts)(a=p?.onLeaveXR)==null||a.call(p,{xr:this});(l=this.sync)==null||l.onExitXR(this),this.context.mainCamera&&((c=this._originalCameraParent)==null||c.add(this.context.mainCamera),this._originalCameraWorldPosition&&ps(this.context.mainCamera,this._originalCameraWorldPosition),this._originalCameraWorldRotation&&oa(this.context.mainCamera,this._originalCameraWorldRotation),this._originalCameraWorldScale&&L0(this.context.mainCamera,this._originalCameraWorldScale)),this.context.requestSizeUpdate(),this._defaultRig.gameObject.removeFromParent(),Mm(!1)}),u(this,"_didStart",!1),u(this,"onBefore",o=>{var a,l,c,h,d,p,f,m;const A=o.xrFrame;if(!A)return;this.context.xr=this,this.context.mainCameraComponent&&this.context.mainCameraComponent!==this._mainCamera&&(this._mainCamera=this.context.mainCameraComponent),((a=this.rig)==null?void 0:a.isActive)==!1&&(wr&&console.warn("Latest rig is not active - trying to activate a different rig",this.rig),this.updateActiveXRRig()),this.rig&&(l=this._mainCamera)!=null&&l.gameObject&&((h=(c=this._mainCamera)==null?void 0:c.gameObject)==null?void 0:h.parent)!==this.rig.gameObject&&this.rig.gameObject.add((d=this._mainCamera)==null?void 0:d.gameObject),this.internalUpdateState(),this.applyCustomForward();const v={xr:this};if(this._didStart){if(this.context.new_scripts_xr.length>0){const g=[...this.context.new_scripts_xr];for(let b=0;b<g.length;b++){const y=this.context.new_scripts_xr[b];if(!y||y.destroyed||((p=y.supportsXR)==null?void 0:p.call(y,this.mode))==!1){this.context.new_scripts_xr.splice(b,1);continue}if(!y.activeAndEnabled){this.context.new_scripts_xr.splice(b,1),this.markInactive(y);continue}if(this.addScript(y)){this.invokeCallback_EnterXR(y);for(const x of this.controllers)this.invokeCallback_ControllerAdded(y,x)}}}}else{this._didStart=!0,PG({session:this});for(const b of zu._xrStartListeners)b(v);const g=[...this._xr_scripts];wr&&console.log("NeedleXRSession start, handle scripts:",g);for(const b of g){if(b.destroyed){this._script_to_remove.push(b);continue}if(!b.activeAndEnabled){this.markInactive(b);continue}this.invokeCallback_EnterXR(b);for(const y of this.controllers)this.invokeCallback_ControllerAdded(b,y)}}this.syncCameraCullingMask();for(const g of this.controllers)g.onUpdate(A);if(this._newControllers.length>0){const g=[...this._newControllers];this._newControllers.length=0;for(const b of g)if(b.connected){this.controllers.push(b);for(const y of this._xr_scripts){if(y.destroyed){this._script_to_remove.push(y);continue}y.activeAndEnabled!==!1&&this.invokeCallback_ControllerAdded(y,b)}}this.controllers.sort((b,y)=>b.index-y.index)}for(const g of this._xr_update_scripts){if(g.destroyed===!0){this._script_to_remove.push(g);continue}if(g.activeAndEnabled===!1){this.markInactive(g);continue}g.onUpdateXR&&g.onUpdateXR(v)}if(this.handleInactiveScripts(),this._script_to_remove.length>0){const g=[...new Set(this._script_to_remove)];this._script_to_remove.length=0;for(const b of g)!b.destroyed&&this.running&&((f=b.onLeaveXR)==null||f.call(b,v)),this.removeScript(b)}(m=this.sync)==null||m.onUpdate(this),this.onRenderDebug()}),u(this,"onBeforeRender",()=>{this.context.mainCamera&&this.updateFade(this.context.mainCamera)}),u(this,"onAfterRender",()=>{if(this.onUpdateFade_PostRender(),sp()){const o=this.context.renderer;if(o.xr.isPresenting&&this.context.mainCamera){const a=o.xr.enabled,l=o.getRenderTarget();o.xr.enabled=!1,o.setRenderTarget(null),o.render(this.context.scene,this.context.mainCamera),o.xr.enabled=a,o.setRenderTarget(l)}}}),u(this,"_script_to_remove",[]),u(this,"_camera"),u(this,"_cameraRenderParent",new ve().rotateY(Math.PI)),u(this,"_previousCameraParent"),u(this,"_customforward",!0),u(this,"originalCameraNearPlane"),u(this,"_viewerPose"),u(this,"_transformOrientation",new Ce),u(this,"_transformPosition",new E),u(this,"_transition");var r,s;Dde(i,n.init),this.session=e,this.mode=i,this.context=t,(wr||ee("console"))&&Mm(!0),this._xr_scripts=[...n.scripts],this._xr_update_scripts=this._xr_scripts.filter(o=>typeof o.onUpdateXR=="function"),this._controllerAdded=n.controller_added,this._controllerRemoved=n.controller_removed,Fu(this.onBefore,ji.LateUpdate),this.context.pre_render_callbacks.push(this.onBeforeRender),this.context.post_render_callbacks.push(this.onAfterRender),((r=n.init.optionalFeatures)!=null&&r.includes("hit-test")||(s=n.init.requiredFeatures)!=null&&s.includes("hit-test"))&&e.requestReferenceSpace("viewer").then(o=>{var a,l;return(l=(a=e.requestHitTestSource)==null?void 0:a.call(e,{space:o}))==null?void 0:l.then(c=>this._viewerHitTestSource=c)}).catch(o=>console.warn(o)),this.context.mainCamera&&(this._originalCameraWorldPosition=Lt(this.context.mainCamera,new E),this._originalCameraWorldRotation=Ti(this.context.mainCamera,new Ce),this._originalCameraWorldScale=Xi(this.context.mainCamera,new E),this._originalCameraParent=this.context.mainCamera.parent),this._defaultRig=new Fue,this.context.scene.add(this._defaultRig.gameObject),this.addRig(this._defaultRig);for(let o=0;o<e.inputSources.length;o++){const a=e.inputSources[o];if(!a.handedness){console.warn("Input source in xr session has no handedness - ignoring",o);continue}this.onInputSourceAdded(a)}this.session.addEventListener("end",this.onEnd),this.session.addEventListener("inputsourceschange",o=>{for(const a of o.removed)this.disconnectInputSource(a);for(const a of o.added)this.onInputSourceAdded(a)}),this.context.xr=this,this.context.renderer.xr.setSession(this.session).then(this.onRendererSessionSet)}static getXRSync(i){return this._sync||(this._sync=new uH(i)),this._sync}static get currentSessionRequest(){return this._currentSessionRequestMode}static get active(){return this._activeSession}static get activeMode(){var i;return((i=this._activeSession)==null?void 0:i.mode)??null}static get xrSystem(){return"xr"in navigator?navigator.xr:void 0}static isXRSupported(){return Promise.all([this.isVRSupported(),this.isARSupported()]).then(i=>i.some(e=>e)).catch(()=>!1)}static isVRSupported(){return this.isSessionSupported("immersive-vr")}static isARSupported(){return this.isSessionSupported("immersive-ar")}static isSessionSupported(i){var e;return((e=this.xrSystem)==null?void 0:e.isSessionSupported(i).catch(t=>(wr&&console.error(t),!1)))??Promise.resolve(!1)}static onSessionRequestStart(i){this._sessionRequestStartListeners.push(i)}static offSessionRequestStart(i){const e=this._sessionRequestStartListeners.indexOf(i);e>=0&&this._sessionRequestStartListeners.splice(e,1)}static onSessionRequestEnd(i){this._sessionRequestEndListeners.push(i)}static offSessionRequestEnd(i){const e=this._sessionRequestEndListeners.indexOf(i);e>=0&&this._sessionRequestEndListeners.splice(e,1)}static onXRSessionStart(i){this._xrStartListeners.push(i)}static offXRSessionStart(i){const e=this._xrStartListeners.indexOf(i);e>=0&&this._xrStartListeners.splice(e,1)}static onXRSessionEnd(i){this._xrEndListeners.push(i)}static offXRSessionEnd(i){const e=this._xrEndListeners.indexOf(i);e>=0&&this._xrEndListeners.splice(e,1)}static onControllerAdded(i){this._controllerAddedListeners.push(i)}static offControllerAdded(i){const e=this._controllerAddedListeners.indexOf(i);e>=0&&this._controllerAddedListeners.splice(e,1)}static onControllerRemoved(i){this._controllerRemovedListeners.push(i)}static offControllerRemoved(i){const e=this._controllerRemovedListeners.indexOf(i);e>=0&&this._controllerRemovedListeners.splice(e,1)}static offerSession(i,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: "+i),e=="default"&&(e=this.getDefaultSessionInit(i)),navigator.xr.offerSession(i,{...e}).then(n=>zu.setSession(i,n,e,t)).catch(n=>{console.log("XRSession offer rejected (perhaps because another call to offerSession was made or a call to requestSession was made)")})),!0):!1}static getDefaultSessionInit(i){switch(i){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",i),{}}}static async start(i,e,t){var n,r,s,o;if(st()&&ee("debugxrpreroom"))return console.warn("Debug: Starting temporary XR session"),await wg.start(i,e||zu.getDefaultSessionInit(i)),null;if(this._currentSessionRequest)return console.warn("A XRSession is already being requested"),(wr||st())&&Fi("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=Pt.Current),t||(t=hi.All[0]),!t)throw new Error("No Needle Engine Context found");switch(e||(e={}),e.optionalFeatures??(e.optionalFeatures=[]),e.requiredFeatures??(e.requiredFeatures=[]),i){case"immersive-ar":{if(await((n=this.xrSystem)==null?void 0:n.isSessionSupported("immersive-ar"))!==!0)return console.error(i+" is not supported by this browser."),null;const c=this.getDefaultSessionInit(i),h=Bde(t.domElement);h&&!Y_()&&(c.domOverlay={root:h},c.optionalFeatures.push("dom-overlay")),e={...c,...e}}break;case"immersive-vr":{if(await((r=this.xrSystem)==null?void 0:r.isSessionSupported("immersive-vr"))!==!0)return console.error(i+" is not supported by this browser."),null;e={...this.getDefaultSessionInit(i),...e}}break;default:console.warn("No default session init for mode",i);break}await wg.stop();const a=i=="immersive-ar"?t.scripts_immersive_ar:t.scripts_immersive_vr;wr?console.log(`%cRequesting ${i} session`,"font-weight:bold;",e,a):console.log(`%cRequesting ${i} session`,"font-weight:bold;");for(const c of a)c.onBeforeXR&&c.onBeforeXR(i,e);for(const c of this._sessionRequestStartListeners)c({mode:i,init:e});wr&&pn("Requesting "+i+" session ("+Date.now()+")"),this._currentSessionRequest=(s=navigator.xr)==null?void 0:s.requestSession(i,e),this._currentSessionRequestMode=i;const l=await((o=this._currentSessionRequest)==null?void 0:o.catch(c=>{console.error(c,"Code: "+c.code),c.code===9&&Fi("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:"&&Fi("XR requires a secure connection (HTTPS)")}));this._currentSessionRequest=void 0,this._currentSessionRequestMode=null;for(const c of this._sessionRequestEndListeners)c({mode:i,init:e,newSession:l||null});return l?this.setSession(i,l,e,t):(console.warn("XR Session request was rejected"),null)}static setSession(i,e,t,n){if(this._activeSession)return console.error("A XRSession is already running"),this._activeSession;const r=i=="immersive-ar"?n.scripts_immersive_ar:n.scripts_immersive_vr;return this._activeSession=new zu(i,e,n,{scripts:r,controller_added:this._controllerAddedListeners,controller_removed:this._controllerRemovedListeners,init:t}),e.addEventListener("end",this.onEnd),wr?console.log(`%cStarted ${i} session`,"font-weight:bold;",r):console.log(`%cStarted ${i} session`,"font-weight:bold;"),this._activeSession}static stop(){var i;(i=this._activeSession)==null||i.end()}get sync(){return zu._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(i=>i.isLeft)}get rightController(){return this.controllers.find(i=>i.isRight)}getController(i){return typeof i=="number"?this.controllers[i]||null:this.controllers.find(e=>e.side===i)||null}get isPassThrough(){return!!(this.environmentBlendMode!=="opaque"&&this.interactionMode==="world-space"||this.mode==="immersive-ar"&&this.environmentBlendMode!=="opaque"&&this.controllers.some(i=>i.inputSource.targetRayMode==="tracked-pointer")||st()&&sp()&&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 i=this.frame.getImageTrackingResults();for(const e of i)if(e.trackingState==="tracked")return!0}catch{return!1}return!1}get rig(){const i=this._rigs[0]??null;return i!=null&&i.gameObject&&jp(i.gameObject)||i?.isActive===!1?(this.updateActiveXRRig(),this._rigs[0]??null):i}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(i){this._rigs.indexOf(i)>=0||(i.priority===void 0&&(i.priority=0),this._rigs.push(i),this.updateActiveXRRig())}removeRig(i){const e=this._rigs.indexOf(i);e!==-1&&(this._rigs.splice(e,1),this.updateActiveXRRig())}setRigActive(i){const e=this._rigs.indexOf(i);this._rigs.splice(e,1),this._rigs.unshift(i),this.updateActiveXRRig()}updateActiveXRRig(){const i=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 n=this._rigs[t];if(n.isActive){if(jp(n.gameObject)){this._rigs.splice(t,1),t--;continue}(!e||e.isActive===!1||n.priority!==void 0&&n.priority>e.priority)&&(e=n)}}if(i!==e){const t=this._rigs.indexOf(e);t>=0&&this._rigs.splice(t,1),this._rigs.unshift(e)}wr&&(i===e?console.log("Updated Active XR Rig:",e,"prev:",i):console.log("Updated Active XRRig:",e," (the same as before)"))}getHitTest(i){if(i)return this.getControllerHitTest(i);if(!this._viewerHitTestSource)return null;const e=this._viewerHitTestSource,t=this.frame.getHitTestResults(e);if(t.length>0){const n=t[0];return this.convertHitTestResult(n)}return null}getControllerHitTest(i){const e=i.hitTestSource;if(!e)return null;const t=this.frame.getHitTestResultsForTransientInput(e);for(const n of t)if(n.inputSource===i.inputSource)for(const r of n.results)return this.convertHitTestResult(r);return null}convertHitTestResult(i){const e=this.context.renderer.xr.getReferenceSpace(),t=e&&i.getPose(e);if(t){const n=En(t.transform.position),r=hp(t.transform.orientation),s=this.context.mainCamera;if(s?.parent!==this._cameraRenderParent&&n.applyMatrix4(Q1),s!=null&&s.parent){n.applyMatrix4(s.parent.matrixWorld),r.multiply(xa);const o=Ti(s.parent);o.premultiply(xa),r.premultiply(o)}return{hit:i,position:n,quaternion:r}}return null}convertSpace(i){const e=En(i.position);e.applyMatrix4(Q1);const t=hp(i.orientation);return t.premultiply(xa),{position:e,quaternion:t}}disconnectInputSource(i){const e=(t,n,r)=>{if(t.inputSource===i){wr&&console.log("Disconnecting controller",t.index),this.controllers.splice(r,1),this.invokeControllerEvent(t,this._controllerRemoved,"removed");const s={xr:this,controller:t,change:"removed"};for(const o of this._xr_scripts)o.onXRControllerRemoved&&o.onXRControllerRemoved(s);t.onDisconnected()}};for(let t=this.controllers.length-1;t>=0;t--){const n=this.controllers[t];e(n,this.controllers,t)}for(let t=this._newControllers.length-1;t>=0;t--){const n=this._newControllers[t];e(n,this._newControllers,t)}}end(){this._ended||this.session.end().catch(i=>console.warn(i))}onRenderDebug(){if(wr)for(const i of this.controllers)i.onRenderDebug();if((wr||Tde)&&this.rig){const i=this.rig.gameObject.worldPosition,e=this.rig.gameObject.worldForward;i.add(e.multiplyScalar(1.5));const t=this.rig.gameObject.worldUp;i.add(t.multiplyScalar(2.5));let n="";if(n+=this.context.time.smoothedFps.toFixed(1),wr)for(const r of this.controllers)n+=`
5237
+ `+l.href)}this.onSendQueued(ya.OnRoomJoin);break;case"left-room":e.room===this.currentRoomName&&(this._isInRoom=!1,this._currentRoomName=null,this._currentInRoom.length=0);break;case"user-joined-room":if(e.data){const a=e.data;this._currentInRoom.push(a.userId),Ks&&console.log(a.userId+" joined","now in room:",this._currentInRoom)}break;case"user-left-room":if(e.data){const a=e.data,l=this._currentInRoom.indexOf(a.userId);l>=0&&(Ks&&console.log(a.userId+" left","now in room:",this._currentInRoom),this._currentInRoom.splice(l,1)),a.userId===this.connectionId&&console.log("you left the room")}break;case"all-room-state-deleted":Ks&&console.log("RECEIVED all-room-state-deleted"),this._state={};break;case"ping":case"pong":const o=(t=e.data)==null?void 0:t.time;o&&(this._currentDelay=this.context.time.time-o),Ks&&console.log("Current latency: "+this._currentDelay.toFixed(1)+" sec","Clients in room: "+((n=this._currentInRoom)==null?void 0:n.length));break}let r=this._listeners[e.key];if(r){r=[...r];for(const o of r)try{o(e.data)}catch(a){console.error('Error invoking callback for "'+e.key+'"',a)}}const s=e.data;s&&(this._state[s.guid]=s)}toMessage(e,t){return{key:e,data:t}}sendWithWebsocket(e,t,n=ya.OnRoomJoin){if(!this._ws){const s=this._waitingForSocket[n]||[];s.push(()=>this.sendWithWebsocket(e,t,n)),this._waitingForSocket[n]=s;return}const r=JSON.stringify(this.toMessage(e,t));Ks&&console.log(">>",e),this._ws.send(r)}onSendQueued(e){const t=this._waitingForSocket[e];if(t){for(const n of t)n();t.length=0}}}const Kv=ee("debugwebxr");class PD{constructor(e,t){u(this,"controllerStates",[]),u(this,"userId"),u(this,"context"),u(this,"userStateEvtName"),u(this,"onReceivedControllerState",n=>{Kv&&console.log(`XRSync: Received change for ${this.userId}: ${n.type} ${n.handedness}; tracked=${n.isTracking}`);let r=!1;for(let s=0;s<this.controllerStates.length;s++)if(this.controllerStates[s].index===n.index){this.controllerStates[s]=n,r=!0;break}r||this.controllerStates.push(n)}),this.userId=e,this.context=t,this.userStateEvtName="xr-sync-user-state-"+e,this.context.connection.beginListen(this.userStateEvtName,this.onReceivedControllerState)}dispose(){this.context.connection.stopListen(this.userStateEvtName,this.onReceivedControllerState)}update(e){if(this.context.connection.isConnected!=!1){for(let t=this.controllerStates.length-1;t>=0;t--){const n=this.controllerStates[t];let r=!1;for(let s=0;s<e.controllers.length;s++)e.controllers[s].index===n.index&&(r=!0);r||(Kv&&console.log(`XRSync: ${n.type} ${n.handedness} removed`,n.index),this.controllerStates.splice(t,1),this.sendControllerRemoved(n))}for(const t of e.controllers)this.updateControllerStates(t)}}onExitXR(e){for(const t of this.controllerStates)this.sendControllerRemoved(t);this.controllerStates.length=0}sendControllerRemoved(e){e.isTracking=!1,e.guid="",this.context.connection.send(this.userStateEvtName,e),this.context.connection.sendDeleteRemoteState(e.guid)}updateControllerStates(e){const t=this.controllerStates.find(n=>n.index===e.index);if(t){let n=!1;n||(n=t.isTracking!=e.isTracking),n&&(t.isTracking=e.isTracking,this.context.connection.send(this.userStateEvtName,t))}else{const n={guid:this.userId+"-"+e.index,isTracking:e.isTracking,handedness:e.side,index:e.index,type:e.hand?"hand":"controller"};this.controllerStates.push(n),this.context.connection.send(this.userStateEvtName,n),Kv&&console.log(`XRSync: ${n.type} ${n.handedness} added`,n.index)}}}class uH{constructor(e){u(this,"context"),u(this,"onJoinedRoom",()=>{if(this.context.connection.connectionId){this._states.has(this.context.connection.connectionId)||(Kv&&console.log("XRSync: Local user joined room",this.context.connection.connectionId),this._states.set(this.context.connection.connectionId,new PD(this.context.connection.connectionId,this.context)));for(const t of this.context.connection.usersInRoom())this._states.has(t)||this._states.set(t,new PD(t,this.context))}}),u(this,"onLeftRoom",()=>{if(this.context.connection.connectionId&&!this._states.has(this.context.connection.connectionId)){const t=this._states.get(this.context.connection.connectionId);t?.dispose(),this._states.delete(this.context.connection.connectionId)}}),u(this,"onOtherUserJoinedRoom",t=>{const n=t.userId;this._states.has(n)||(Kv&&console.log("XRSync: Remote user joined room",n),this._states.set(n,new PD(n,this.context)))}),u(this,"onOtherUserLeftRoom",t=>{const n=t.userId;if(!this._states.has(n)){const r=this._states.get(n);r?.dispose(),this._states.delete(n)}}),u(this,"_states",new Map),this.context=e,this.context.connection.beginListen(ti.JoinedRoom,this.onJoinedRoom),this.context.connection.beginListen(ti.LeftRoom,this.onLeftRoom),this.context.connection.beginListen(ti.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.beginListen(ti.UserLeftRoom,this.onOtherUserLeftRoom)}hasState(e){return e?this._states.has(e):!1}isTracking(e,t){if(!e)return;const n=this._states.get(e);if(!n)return;const r=n.controllerStates.find(s=>s.handedness===t);return r?.isTracking||!1}getDeviceType(e,t){if(!e)return;const n=this._states.get(e);if(!n)return;const r=n.controllerStates.find(s=>s.handedness===t);return r?.type||"unknown"}destroy(){this.context.connection.stopListen(ti.JoinedRoom,this.onJoinedRoom),this.context.connection.stopListen(ti.LeftRoom,this.onLeftRoom),this.context.connection.stopListen(ti.UserJoinedRoom,this.onOtherUserJoinedRoom),this.context.connection.stopListen(ti.UserLeftRoom,this.onOtherUserLeftRoom)}onUpdate(e){if(this.context.connection.isConnected&&this.context.connection.connectionId){const t=this._states.get(this.context.connection.connectionId);t?.update(e)}}onExitXR(e){if(this.context.connection.isConnected&&this.context.connection.connectionId){const t=this._states.get(this.context.connection.connectionId);t?.onExitXR(e)}}}class dH{constructor(){u(this,"_fadeToColorQuad"),u(this,"_fadeToColorMaterial"),u(this,"_requestedFadeValue",0),u(this,"_transitionPromise",null),u(this,"_transitionResolve",null),this._fadeToColorMaterial=new Kt({color:0,transparent:!0,depthTest:!1,fog:!1,side:mi}),this._fadeToColorQuad=new pe(new tr(10,10),this._fadeToColorMaterial)}dispose(){this._fadeToColorQuad.geometry.dispose(),this._fadeToColorMaterial.dispose()}update(e,t){const n=this._fadeToColorQuad,r=this._fadeToColorMaterial;n.parent!==e&&r.opacity>0?e.add(n):r.opacity===0&&n.removeFromParent(),n.layers.set(2),n.material=this._fadeToColorMaterial,n.position.z=-1,n.renderOrder=1/0;const s=this._requestedFadeValue;r.opacity=$e.lerp(r.opacity,s,t/.03),Math.abs(r.opacity-s)<=.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 e=new Promise(t=>{this._transitionResolve=t});return this._transitionPromise=e,e}}var zp=(i=>(i[i.Quad=0]="Quad",i[i.Cube=1]="Cube",i[i.Sphere=2]="Sphere",i))(zp||{});class Zv{static createPrimitive(e,t){let n;switch(e){case"Quad":case 0:{const r=new tr(1,1,1,1),s=t?.material??new ds({color:16777215});t!=null&&t.texture&&"map"in s&&(s.map=t.texture),n=new pe(r,s)}break;case"Cube":case 1:{const r=new Vi(1,1,1),s=t?.material??new ds({color:16777215});t!=null&&t.texture&&"map"in s&&(s.map=t.texture),n=new pe(r,s)}break;case"Sphere":case 2:{const r=new _l(.5,16,16),s=t?.material??new ds({color:16777215});t!=null&&t.texture&&"map"in s&&(s.map=t.texture),n=new pe(r,s)}break}return this.applyDefaultObjectOptions(n,t),n}static createSprite(e){const t=new r_({color:16777215});e!=null&&e.texture&&"map"in t&&(t.map=e.texture);const n=new pM(t);return this.applyDefaultObjectOptions(n,e),n}static applyDefaultObjectOptions(e,t){t!=null&&t.name&&(e.name=t.name),t!=null&&t.position&&e.position.set(t.position.x,t.position.y,t.position.z),t!=null&&t.rotation&&e.rotation.set(t.rotation.x,t.rotation.y,t.rotation.z),t!=null&&t.scale&&e.scale.set(t.scale.x,t.scale.y,t.scale.z)}}const pH=class{constructor(i,e,t){u(this,"_session"),u(this,"_mode"),u(this,"_init"),u(this,"_renderer"),u(this,"_camera"),u(this,"_scene"),u(this,"onEnd",()=>{var n;(n=this._session)==null||n.removeEventListener("end",this.onEnd),this._renderer.setAnimationLoop(null),this._renderer.dispose(),this._scene.clear()}),u(this,"_lastTime",0),u(this,"onFrame",(n,r)=>{const s=n-this._lastTime;this.update(n,s),this._camera.parent!==this._scene&&this._scene.add(this._camera),this._renderer.render(this._scene,this._camera)}),u(this,"_objects",[]),this._mode=i,this._init=e,this._session=t,this._session.addEventListener("end",this.onEnd),this._renderer=new Qc({alpha:!0}),this._renderer.setAnimationLoop(this.onFrame),this._renderer.xr.setSession(t),this._renderer.xr.enabled=!0,this._camera=new Rt,this._scene=new Lr,this._scene.fog=new n_(4473924,10,250),this._scene.add(this._camera),this.setupScene()}static get active(){return this._active}static async start(i,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(i,e);return t.addEventListener("end",()=>{this._active=null}),this._requestInFlight?(this._requestInFlight=!1,this._active=new pH(i,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 kl(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 i={session:this._session,mode:this._mode,init:this._init};return await this.onBeforeHandoff(),this.onEnd(),this._session=null,i}async onBeforeHandoff(){await kl(1e3),this._scene.clear()}setupScene(){this._scene.background=new _e(0),this._scene.add(new Q_(5,10,1118481,1118481));const i=new Zd(16777215,1);i.position.set(0,20,0),i.castShadow=!1,this._scene.add(i);const e=new Zd(16777215,1);e.position.set(0,-1,0),e.castShadow=!1,this._scene.add(e);const t=new Kd(16777215,1,100,1);t.position.set(0,2,0),t.castShadow=!1,t.distance=200,this._scene.add(t);const n=50;for(let r=0;r<100;r++){const s=new ds({color:2236962,metalness:1,roughness:.8});this.isAR&&(s.emissive=new _e(Math.random(),Math.random(),Math.random()),s.emissiveIntensity=Math.random());const o=$e.random(0,1)>.5?zp.Sphere:zp.Cube,a=Zv.createPrimitive(o,{material:s});a.position.x=$e.random(-n,n),a.position.y=$e.random(-2,n),a.position.z=$e.random(-n,n),a.rotation.x=$e.random(0,Math.PI*2),a.rotation.y=$e.random(0,Math.PI*2),a.rotation.z=$e.random(0,Math.PI*2),a.scale.multiplyScalar(.5+Math.random()*10);const l=a.position.distanceTo(this._camera.position)-a.scale.x;l<1&&a.position.multiplyScalar(1+1/l),this._objects.push(a),this._scene.add(a)}}update(i,e){const t=i*4e-4;for(let n=0;n<this._objects.length;n++){const r=this._objects[n];r.position.y+=Math.sin(t+n*.5)*.005,r.rotateY(.002)}}};let wg=pH;u(wg,"_active",null),u(wg,"_requestInFlight",!1);const wr=ee("debugwebxr"),Tde=ee("stats");function Bde(i){let e=null;const t=i;return t.getAROverlayContainer?e=t.getAROverlayContainer():e=i,e}Rde();async function Rde(){var i;if(ee("debugasap")){let e=globalThis["needle:XRSession"];if(e instanceof Promise){delete globalThis["needle:XRSession"],hi.addContextCreatedCallback(async t=>{if(!e)return;Mm(!0);const n=await e;if(n){const r=_t.getDefaultSessionInit("immersive-vr");_t.setSession("immersive-vr",n,r,t.context)}else console.error("NeedleXRSession: ASAP session was rejected");e=void 0});return}}if("xr"in navigator){if(/WebXRViewer\//i.test(navigator.userAgent)){console.warn("WebXRViewer does not support addEventListener");return}(i=navigator.xr)==null||i.addEventListener("sessiongranted",async()=>{Mm(!0),console.log("Received Session Granted..."),await kl(100);const e=sessionStorage.getItem("needle_xr_session_mode"),t=sessionStorage.getItem("needle_xr_session_init")??null,n=t?JSON.parse(t):null;let r=null;if(fH()&&(await wg.start(e||"immersive-vr",n||_t.getDefaultSessionInit("immersive-vr")),await kde(),r=await wg.handoff()),r)_t.setSession(r.mode,r.session,r.init,Pt.Current);else if(e&&t){console.log("Session Granted: Restore last session");const s=JSON.parse(t);_t.start(e,s).catch(o=>console.warn(o))}else _t.start("immersive-vr").catch(s=>console.warn("Session Granted failed:",s))},{once:!0})}}function Dde(i,e){sessionStorage.setItem("needle_xr_session_mode",i),sessionStorage.setItem("needle_xr_session_init",JSON.stringify(e))}function Pde(){sessionStorage.removeItem("needle_xr_session_mode"),sessionStorage.removeItem("needle_xr_session_init")}const kD=new Set;hi.registerCallback(Ei.ContextCreationStart,async i=>{kD.add(i.context)}),hi.registerCallback(Ei.ContextCreated,async i=>{kD.delete(i.context)});function fH(){return kD.size>0}function kde(){return new Promise(i=>{const e=Date.now(),t=setInterval(()=>{(!fH()||Date.now()-e>6e4)&&(clearInterval(t),i())},100)})}sp()&&st()&&window.addEventListener("keydown",i=>{(i.key==="x"||i.key==="Escape")&&_t.active&&_t.stop()});const zu=class{constructor(i,e,t,n){u(this,"context"),u(this,"session"),u(this,"mode"),u(this,"controllers",[]),u(this,"_rigScale",1),u(this,"_lastRigScaleUpdate",-1),u(this,"_rigs",[]),u(this,"_viewerHitTestSource",null),u(this,"_defaultRig"),u(this,"_xr_scripts"),u(this,"_xr_update_scripts",[]),u(this,"_inactive_scripts",[]),u(this,"_controllerAdded"),u(this,"_controllerRemoved"),u(this,"_originalCameraWorldPosition"),u(this,"_originalCameraWorldRotation"),u(this,"_originalCameraWorldScale"),u(this,"_originalCameraParent"),u(this,"_mainCamera",null),u(this,"onRendererSessionSet",()=>{var o;this.running&&(this.context.renderer.xr.enabled=!0,this.context.renderer.xr.updateCamera(this.context.mainCamera),(o=this.context.mainCameraComponent)==null||o.applyClearFlags())}),u(this,"onInputSourceAdded",o=>{if(o.targetRayMode==="screen")return;let a=0;for(let c=0;c<this.session.inputSources.length;c++)if(this.session.inputSources[c]===o){a=c;break}if(this.controllers.find(c=>c.inputSource===o)){console.warn("Controller already exists for input source",a);return}wr&&console.log("Adding controller",a);const l=new lD(this,o,a);this._newControllers.push(l)}),u(this,"_ended",!1),u(this,"_newControllers",[]),u(this,"onEnd",o=>{var a,l,c;if(this._ended)return;this._ended=!0,wr&&console.log("XR Session ended"),Pde(),this.onAfterRender(),this.revertCustomForward(),this._didStart=!1,this._previousCameraParent=null,Uu(this.onBefore,ji.LateUpdate);const h=this.context.pre_render_callbacks.indexOf(this.onBeforeRender);h>=0&&this.context.pre_render_callbacks.splice(h,1);const d=this.context.post_render_callbacks.indexOf(this.onAfterRender);d>=0&&this.context.post_render_callbacks.splice(d,1),this.context.xr=null,this.context.renderer.xr.enabled=!1,this.context.pre_update_oneshot_callbacks.push(()=>{var p;(p=this.context.mainCameraComponent)==null||p.applyClearFlags()}),kG({session:this});for(const p of zu._xrEndListeners)p({xr:this});for(let p=0;p<this.controllers.length;p++)this.disconnectInputSource(this.controllers[p].inputSource);for(const p of this._xr_scripts)(a=p?.onLeaveXR)==null||a.call(p,{xr:this});(l=this.sync)==null||l.onExitXR(this),this.context.mainCamera&&((c=this._originalCameraParent)==null||c.add(this.context.mainCamera),this._originalCameraWorldPosition&&ps(this.context.mainCamera,this._originalCameraWorldPosition),this._originalCameraWorldRotation&&oa(this.context.mainCamera,this._originalCameraWorldRotation),this._originalCameraWorldScale&&L0(this.context.mainCamera,this._originalCameraWorldScale)),this.context.requestSizeUpdate(),this._defaultRig.gameObject.removeFromParent(),Mm(!1)}),u(this,"_didStart",!1),u(this,"onBefore",o=>{var a,l,c,h,d,p,f,m;const A=o.xrFrame;if(!A)return;this.context.xr=this,this.context.mainCameraComponent&&this.context.mainCameraComponent!==this._mainCamera&&(this._mainCamera=this.context.mainCameraComponent),((a=this.rig)==null?void 0:a.isActive)==!1&&(wr&&console.warn("Latest rig is not active - trying to activate a different rig",this.rig),this.updateActiveXRRig()),this.rig&&(l=this._mainCamera)!=null&&l.gameObject&&((h=(c=this._mainCamera)==null?void 0:c.gameObject)==null?void 0:h.parent)!==this.rig.gameObject&&this.rig.gameObject.add((d=this._mainCamera)==null?void 0:d.gameObject),this.internalUpdateState(),this.applyCustomForward();const v={xr:this};if(this._didStart){if(this.context.new_scripts_xr.length>0){const g=[...this.context.new_scripts_xr];for(let b=0;b<g.length;b++){const y=this.context.new_scripts_xr[b];if(!y||y.destroyed||((p=y.supportsXR)==null?void 0:p.call(y,this.mode))==!1){this.context.new_scripts_xr.splice(b,1);continue}if(!y.activeAndEnabled){this.context.new_scripts_xr.splice(b,1),this.markInactive(y);continue}if(this.addScript(y)){this.invokeCallback_EnterXR(y);for(const x of this.controllers)this.invokeCallback_ControllerAdded(y,x)}}}}else{this._didStart=!0,PG({session:this});for(const b of zu._xrStartListeners)b(v);const g=[...this._xr_scripts];wr&&console.log("NeedleXRSession start, handle scripts:",g);for(const b of g){if(b.destroyed){this._script_to_remove.push(b);continue}if(!b.activeAndEnabled){this.markInactive(b);continue}this.invokeCallback_EnterXR(b);for(const y of this.controllers)this.invokeCallback_ControllerAdded(b,y)}}this.syncCameraCullingMask();for(const g of this.controllers)g.onUpdate(A);if(this._newControllers.length>0){const g=[...this._newControllers];this._newControllers.length=0;for(const b of g)if(b.connected){this.controllers.push(b);for(const y of this._xr_scripts){if(y.destroyed){this._script_to_remove.push(y);continue}y.activeAndEnabled!==!1&&this.invokeCallback_ControllerAdded(y,b)}}this.controllers.sort((b,y)=>b.index-y.index)}for(const g of this._xr_update_scripts){if(g.destroyed===!0){this._script_to_remove.push(g);continue}if(g.activeAndEnabled===!1){this.markInactive(g);continue}g.onUpdateXR&&g.onUpdateXR(v)}if(this.handleInactiveScripts(),this._script_to_remove.length>0){const g=[...new Set(this._script_to_remove)];this._script_to_remove.length=0;for(const b of g)!b.destroyed&&this.running&&((f=b.onLeaveXR)==null||f.call(b,v)),this.removeScript(b)}(m=this.sync)==null||m.onUpdate(this),this.onRenderDebug()}),u(this,"onBeforeRender",()=>{this.context.mainCamera&&this.updateFade(this.context.mainCamera)}),u(this,"onAfterRender",()=>{if(this.onUpdateFade_PostRender(),sp()){const o=this.context.renderer;if(o.xr.isPresenting&&this.context.mainCamera){const a=o.xr.enabled,l=o.getRenderTarget();o.xr.enabled=!1,o.setRenderTarget(null),o.render(this.context.scene,this.context.mainCamera),o.xr.enabled=a,o.setRenderTarget(l)}}}),u(this,"_script_to_remove",[]),u(this,"_camera"),u(this,"_cameraRenderParent",new ve().rotateY(Math.PI)),u(this,"_previousCameraParent"),u(this,"_customforward",!0),u(this,"originalCameraNearPlane"),u(this,"_viewerPose"),u(this,"_transformOrientation",new Ce),u(this,"_transformPosition",new E),u(this,"_transition");var r,s;Dde(i,n.init),this.session=e,this.mode=i,this.context=t,(wr||ee("console"))&&Mm(!0),this._xr_scripts=[...n.scripts],this._xr_update_scripts=this._xr_scripts.filter(o=>typeof o.onUpdateXR=="function"),this._controllerAdded=n.controller_added,this._controllerRemoved=n.controller_removed,Fu(this.onBefore,ji.LateUpdate),this.context.pre_render_callbacks.push(this.onBeforeRender),this.context.post_render_callbacks.push(this.onAfterRender),((r=n.init.optionalFeatures)!=null&&r.includes("hit-test")||(s=n.init.requiredFeatures)!=null&&s.includes("hit-test"))&&e.requestReferenceSpace("viewer").then(o=>{var a,l;return(l=(a=e.requestHitTestSource)==null?void 0:a.call(e,{space:o}))==null?void 0:l.then(c=>this._viewerHitTestSource=c)}).catch(o=>console.warn(o)),this.context.mainCamera&&(this._originalCameraWorldPosition=Lt(this.context.mainCamera,new E),this._originalCameraWorldRotation=Ti(this.context.mainCamera,new Ce),this._originalCameraWorldScale=Xi(this.context.mainCamera,new E),this._originalCameraParent=this.context.mainCamera.parent),this._defaultRig=new Fue,this.context.scene.add(this._defaultRig.gameObject),this.addRig(this._defaultRig);for(let o=0;o<e.inputSources.length;o++){const a=e.inputSources[o];if(!a.handedness){console.warn("Input source in xr session has no handedness - ignoring",o);continue}this.onInputSourceAdded(a)}this.session.addEventListener("end",this.onEnd),this.session.addEventListener("inputsourceschange",o=>{for(const a of o.removed)this.disconnectInputSource(a);for(const a of o.added)this.onInputSourceAdded(a)}),this.context.xr=this,this.context.renderer.xr.setSession(this.session).then(this.onRendererSessionSet)}static getXRSync(i){return this._sync||(this._sync=new uH(i)),this._sync}static get currentSessionRequest(){return this._currentSessionRequestMode}static get active(){return this._activeSession}static get activeMode(){var i;return((i=this._activeSession)==null?void 0:i.mode)??null}static get xrSystem(){return"xr"in navigator?navigator.xr:void 0}static isXRSupported(){return Promise.all([this.isVRSupported(),this.isARSupported()]).then(i=>i.some(e=>e)).catch(()=>!1)}static isVRSupported(){return this.isSessionSupported("immersive-vr")}static isARSupported(){return this.isSessionSupported("immersive-ar")}static isSessionSupported(i){var e;return((e=this.xrSystem)==null?void 0:e.isSessionSupported(i).catch(t=>(wr&&console.error(t),!1)))??Promise.resolve(!1)}static onSessionRequestStart(i){this._sessionRequestStartListeners.push(i)}static offSessionRequestStart(i){const e=this._sessionRequestStartListeners.indexOf(i);e>=0&&this._sessionRequestStartListeners.splice(e,1)}static onSessionRequestEnd(i){this._sessionRequestEndListeners.push(i)}static offSessionRequestEnd(i){const e=this._sessionRequestEndListeners.indexOf(i);e>=0&&this._sessionRequestEndListeners.splice(e,1)}static onXRSessionStart(i){this._xrStartListeners.push(i)}static offXRSessionStart(i){const e=this._xrStartListeners.indexOf(i);e>=0&&this._xrStartListeners.splice(e,1)}static onXRSessionEnd(i){this._xrEndListeners.push(i)}static offXRSessionEnd(i){const e=this._xrEndListeners.indexOf(i);e>=0&&this._xrEndListeners.splice(e,1)}static onControllerAdded(i){this._controllerAddedListeners.push(i)}static offControllerAdded(i){const e=this._controllerAddedListeners.indexOf(i);e>=0&&this._controllerAddedListeners.splice(e,1)}static onControllerRemoved(i){this._controllerRemovedListeners.push(i)}static offControllerRemoved(i){const e=this._controllerRemovedListeners.indexOf(i);e>=0&&this._controllerRemovedListeners.splice(e,1)}static offerSession(i,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: "+i),e=="default"&&(e=this.getDefaultSessionInit(i)),navigator.xr.offerSession(i,{...e}).then(n=>zu.setSession(i,n,e,t)).catch(n=>{console.log("XRSession offer rejected (perhaps because another call to offerSession was made or a call to requestSession was made)")})),!0):!1}static getDefaultSessionInit(i){switch(i){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",i),{}}}static async start(i,e,t){var n,r,s,o;if(st()&&ee("debugxrpreroom"))return console.warn("Debug: Starting temporary XR session"),await wg.start(i,e||zu.getDefaultSessionInit(i)),null;if(this._currentSessionRequest)return console.warn("A XRSession is already being requested"),(wr||st())&&Fi("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=Pt.Current),t||(t=hi.All[0]),!t)throw new Error("No Needle Engine Context found");switch(e||(e={}),i){case"immersive-ar":{if(await((n=this.xrSystem)==null?void 0:n.isSessionSupported("immersive-ar"))!==!0)return console.error(i+" is not supported by this browser."),null;const c=this.getDefaultSessionInit(i),h=Bde(t.domElement);h&&!Y_()&&(c.domOverlay={root:h},c.optionalFeatures.push("dom-overlay")),e={...c,...e}}break;case"immersive-vr":{if(await((r=this.xrSystem)==null?void 0:r.isSessionSupported("immersive-vr"))!==!0)return console.error(i+" is not supported by this browser."),null;e={...this.getDefaultSessionInit(i),...e}}break;default:console.warn("No default session init for mode",i);break}e.optionalFeatures??(e.optionalFeatures=[]),e.requiredFeatures??(e.requiredFeatures=[]),await wg.stop();const a=i=="immersive-ar"?t.scripts_immersive_ar:t.scripts_immersive_vr;wr?console.log(`%cRequesting ${i} session`,"font-weight:bold;",e,a):console.log(`%cRequesting ${i} session`,"font-weight:bold;");for(const c of a)c.onBeforeXR&&c.onBeforeXR(i,e);for(const c of this._sessionRequestStartListeners)c({mode:i,init:e});wr&&pn("Requesting "+i+" session ("+Date.now()+")"),this._currentSessionRequest=(s=navigator.xr)==null?void 0:s.requestSession(i,e),this._currentSessionRequestMode=i;const l=await((o=this._currentSessionRequest)==null?void 0:o.catch(c=>{console.error(c,"Code: "+c.code),c.code===9&&Fi("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:"&&Fi("XR requires a secure connection (HTTPS)")}));this._currentSessionRequest=void 0,this._currentSessionRequestMode=null;for(const c of this._sessionRequestEndListeners)c({mode:i,init:e,newSession:l||null});return l?this.setSession(i,l,e,t):(console.warn("XR Session request was rejected"),null)}static setSession(i,e,t,n){if(this._activeSession)return console.error("A XRSession is already running"),this._activeSession;const r=i=="immersive-ar"?n.scripts_immersive_ar:n.scripts_immersive_vr;return this._activeSession=new zu(i,e,n,{scripts:r,controller_added:this._controllerAddedListeners,controller_removed:this._controllerRemovedListeners,init:t}),e.addEventListener("end",this.onEnd),wr?console.log(`%cStarted ${i} session`,"font-weight:bold;",r):console.log(`%cStarted ${i} session`,"font-weight:bold;"),this._activeSession}static stop(){var i;(i=this._activeSession)==null||i.end()}get sync(){return zu._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(i=>i.isLeft)}get rightController(){return this.controllers.find(i=>i.isRight)}getController(i){return typeof i=="number"?this.controllers[i]||null:this.controllers.find(e=>e.side===i)||null}get isPassThrough(){return!!(this.environmentBlendMode!=="opaque"&&this.interactionMode==="world-space"||this.mode==="immersive-ar"&&this.environmentBlendMode!=="opaque"&&this.controllers.some(i=>i.inputSource.targetRayMode==="tracked-pointer")||st()&&sp()&&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 i=this.frame.getImageTrackingResults();for(const e of i)if(e.trackingState==="tracked")return!0}catch{return!1}return!1}get rig(){const i=this._rigs[0]??null;return i!=null&&i.gameObject&&jp(i.gameObject)||i?.isActive===!1?(this.updateActiveXRRig(),this._rigs[0]??null):i}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(i){this._rigs.indexOf(i)>=0||(i.priority===void 0&&(i.priority=0),this._rigs.push(i),this.updateActiveXRRig())}removeRig(i){const e=this._rigs.indexOf(i);e!==-1&&(this._rigs.splice(e,1),this.updateActiveXRRig())}setRigActive(i){const e=this._rigs.indexOf(i);this._rigs.splice(e,1),this._rigs.unshift(i),this.updateActiveXRRig()}updateActiveXRRig(){const i=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 n=this._rigs[t];if(n.isActive){if(jp(n.gameObject)){this._rigs.splice(t,1),t--;continue}(!e||e.isActive===!1||n.priority!==void 0&&n.priority>e.priority)&&(e=n)}}if(i!==e){const t=this._rigs.indexOf(e);t>=0&&this._rigs.splice(t,1),this._rigs.unshift(e)}wr&&(i===e?console.log("Updated Active XR Rig:",e,"prev:",i):console.log("Updated Active XRRig:",e," (the same as before)"))}getHitTest(i){if(i)return this.getControllerHitTest(i);if(!this._viewerHitTestSource)return null;const e=this._viewerHitTestSource,t=this.frame.getHitTestResults(e);if(t.length>0){const n=t[0];return this.convertHitTestResult(n)}return null}getControllerHitTest(i){const e=i.hitTestSource;if(!e)return null;const t=this.frame.getHitTestResultsForTransientInput(e);for(const n of t)if(n.inputSource===i.inputSource)for(const r of n.results)return this.convertHitTestResult(r);return null}convertHitTestResult(i){const e=this.context.renderer.xr.getReferenceSpace(),t=e&&i.getPose(e);if(t){const n=En(t.transform.position),r=hp(t.transform.orientation),s=this.context.mainCamera;if(s?.parent!==this._cameraRenderParent&&n.applyMatrix4(Q1),s!=null&&s.parent){n.applyMatrix4(s.parent.matrixWorld),r.multiply(xa);const o=Ti(s.parent);o.premultiply(xa),r.premultiply(o)}return{hit:i,position:n,quaternion:r}}return null}convertSpace(i){const e=En(i.position);e.applyMatrix4(Q1);const t=hp(i.orientation);return t.premultiply(xa),{position:e,quaternion:t}}disconnectInputSource(i){const e=(t,n,r)=>{if(t.inputSource===i){wr&&console.log("Disconnecting controller",t.index),this.controllers.splice(r,1),this.invokeControllerEvent(t,this._controllerRemoved,"removed");const s={xr:this,controller:t,change:"removed"};for(const o of this._xr_scripts)o.onXRControllerRemoved&&o.onXRControllerRemoved(s);t.onDisconnected()}};for(let t=this.controllers.length-1;t>=0;t--){const n=this.controllers[t];e(n,this.controllers,t)}for(let t=this._newControllers.length-1;t>=0;t--){const n=this._newControllers[t];e(n,this._newControllers,t)}}end(){this._ended||this.session.end().catch(i=>console.warn(i))}onRenderDebug(){if(wr)for(const i of this.controllers)i.onRenderDebug();if((wr||Tde)&&this.rig){const i=this.rig.gameObject.worldPosition,e=this.rig.gameObject.worldForward;i.add(e.multiplyScalar(1.5));const t=this.rig.gameObject.worldUp;i.add(t.multiplyScalar(2.5));let n="";if(n+=this.context.time.smoothedFps.toFixed(1),wr)for(const r of this.controllers)n+=`
5238
5238
  ${r.hand?"hand":"ctrl"} ${r.inputSource.handedness}[${r.index}] con:${r.connected} tr:${r.isTracking}`;bt.DrawLabel(i,n)}}addScript(i){return this._xr_scripts.includes(i)?!1:(wr&&console.log("Register new XRScript",i),this._xr_scripts.push(i),typeof i.onUpdateXR=="function"&&this._xr_update_scripts.push(i),!0)}markInactive(i){if(!(this._inactive_scripts.indexOf(i)>=0)){this.removeScript(i,!1),this._inactive_scripts.push(i);for(const e of this.controllers)this.invokeCallback_ControllerRemoved(i,e);this.invokeCallback_LeaveXR(i)}}handleInactiveScripts(){if(this._inactive_scripts.length>0)for(let i=this._inactive_scripts.length-1;i>=0;i--){const e=this._inactive_scripts[i];if(e.activeAndEnabled){this._inactive_scripts.splice(i,1),this.addScript(e),this.invokeCallback_EnterXR(e);for(const t of this.controllers)this.invokeCallback_ControllerAdded(e,t)}}}removeScript(i,e=!0){wr&&console.log("Remove XRScript",i);const t=this._xr_scripts.indexOf(i);t>=0&&this._xr_scripts.splice(t,1);const n=this._xr_update_scripts.indexOf(i);if(n>=0&&this._xr_update_scripts.splice(n,1),e){const r=this._inactive_scripts.indexOf(i);r>=0&&this._inactive_scripts.splice(r,1)}}invokeCallback_EnterXR(i){i.onEnterXR&&i.onEnterXR({xr:this})}invokeCallback_ControllerAdded(i,e){i.onXRControllerAdded&&i.onXRControllerAdded({xr:this,controller:e,change:"added"})}invokeCallback_ControllerRemoved(i,e){i.onXRControllerRemoved&&i.onXRControllerRemoved({xr:this,controller:e,change:"removed"})}invokeCallback_LeaveXR(i){i.onLeaveXR&&!i.destroyed&&i.onLeaveXR({xr:this})}syncCameraCullingMask(){var i;const e=this.context.xrCamera,t=(i=this.context.mainCameraComponent)==null?void 0:i.cullingMask;if(e&&t!==void 0){for(const n of e.cameras)n.layers.mask=t;e.layers.mask=t}else if(e){for(const n of e.cameras)n.layers.enableAll();e.layers.enableAll()}}invokeControllerEvent(i,e,t){for(let n=e.length-1;n>=0;n--){const r=e[n];if(r)try{r({xr:this,controller:i,change:t})}catch(s){console.error(s)}}}applyCustomForward(){var i;if(this.context.mainCamera&&this._customforward){this._camera=this.context.mainCamera,this._camera.parent!==this._cameraRenderParent&&(this._previousCameraParent=this._camera.parent,(i=this._previousCameraParent)==null||i.add(this._cameraRenderParent)),this._cameraRenderParent.name="XR Camera Render Parent",this._cameraRenderParent.add(this._camera);let e=.02;if(this.rig){const t=Xi(this.rig.gameObject);e*=t.x}this._camera instanceof Rt&&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 Rt&&this.originalCameraNearPlane!=null&&(this._camera.near=this.originalCameraNearPlane)}internalUpdateState(){const i=this.context.renderer.xr.getReferenceSpace();if(!i){this._viewerPose=void 0;return}if(this._viewerPose=this.frame.getViewerPose(i),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 dH),this._transition}fadeTransition(){return this._transition||(this._transition=new dH),this._transition.fadeTransition()}updateFade(i){this._transition&&i instanceof Rt&&this._transition.update(i,this.context.time.deltaTime)}onUpdateFade_PostRender(){var i;(i=this._transition)==null||i.remove()}};let _t=zu;u(_t,"_sync",null),u(_t,"_currentSessionRequestMode",null),u(_t,"_currentSessionRequest"),u(_t,"_activeSession"),u(_t,"_sessionRequestStartListeners",[]),u(_t,"_sessionRequestEndListeners",[]),u(_t,"_xrStartListeners",[]),u(_t,"_xrEndListeners",[]),u(_t,"_controllerAddedListeners",[]),u(_t,"_controllerRemovedListeners",[]),u(_t,"onEnd",()=>{wr&&console.log("XR Session ended"),zu._activeSession=null});const OD=ee("debugwebxr");class mH{static tryFindAvatarObjects(e,t,n){if(n.head&&n.leftHand&&n.rightHand)return;const r=e.name.toLocaleLowerCase();!n.head&&r.includes("head")&&(OD&&console.log("FOUND AVATAR HEAD",e.name),n.head=new ei("",t,e)),r.includes("hand")&&(!n.leftHand&&r.includes("left")&&(OD&&console.log("FOUND AVATAR LEFT HAND",e.name),n.leftHand=new ei("",t,e)),!n.rightHand&&r.includes("right")&&(OD&&console.log("FOUND AVATAR RIGHT HAND",e.name),n.rightHand=new ei("",t,e)));for(let s=0;s<e.children.length;s++){if(n.head&&n.leftHand&&n.rightHand)return;const o=e.children[s];this.tryFindAvatarObjects(o,t,n)}}}var eC=(i=>(i.Visible="application-visible",i.Hidden="application-hidden",i.MuteChanged="application-mutechanged",i))(eC||{});let tC=!1;const Cg=[];function Eg(){if(tC)return;st()&&console.debug("User interaction registered: audio can now be played"),tC=!0;const i=[...Cg];Cg.length=0,i.forEach(e=>e())}document.addEventListener("pointerdown",Eg),document.addEventListener("click",Eg),document.addEventListener("dragstart",Eg),document.addEventListener("touchstart",Eg),document.addEventListener("keydown",Eg),_t.onXRSessionStart(()=>{Eg()});const gH=class extends EventTarget{constructor(i){super(),u(this,"_mute",!1),u(this,"context"),u(this,"_isVisible",!0),this.context=i,window.addEventListener("visibilitychange",this.onVisiblityChanged.bind(this),!1)}static get userInteractionRegistered(){return tC}static registerWaitForInteraction(i){if(i!==null){if(tC){i();return}Cg.indexOf(i)===-1&&Cg.push(i)}}static unregisterWaitForInteraction(i){const e=Cg.indexOf(i);e!==-1&&Cg.splice(e,1)}get muted(){return this._mute}set muted(i){i!==this._mute&&(this._mute=i,this.dispatchEvent(new Event("application-mutechanged")))}get hasFocus(){return document.hasFocus()}get isVisible(){return this._isVisible}onVisiblityChanged(i){switch(i.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 ju=gH;u(ju,"registerWaitForAllowAudio",gH.registerWaitForInteraction);function*AH(i,e=null){const t=e?e.time:Pt.Current.time,n=t.time;for(;t.time-n<i;)yield}function*Ode(i){for(let e=0;e<i;e++)yield}function*vH(i){let e=!0;for(i.then(()=>e=!1),i.catch(()=>e=!1);e;)yield}class $v extends jM{constructor(e){super(e),this.type=un}parse(e){const t=Math.pow(2.7182818,2.2);function n(C,R){let z=0;for(let N=0;N<65536;++N)(N==0||C[N>>3]&1<<(N&7))&&(R[z++]=N);const Z=z-1;for(;z<65536;)R[z++]=0;return Z}function r(C){for(let R=0;R<16384;R++)C[R]={},C[R].len=0,C[R].lit=0,C[R].p=null}const s={l:0,c:0,lc:0};function o(C,R,z,Z,N){for(;z<C;)R=R<<8|W(Z,N),z+=8;z-=C,s.l=R>>z&(1<<C)-1,s.c=R,s.lc=z}const a=new Array(59);function l(C){for(let z=0;z<=58;++z)a[z]=0;for(let z=0;z<65537;++z)a[C[z]]+=1;let R=0;for(let z=58;z>0;--z){const Z=R+a[z]>>1;a[z]=R,R=Z}for(let z=0;z<65537;++z){const Z=C[z];Z>0&&(C[z]=Z|a[Z]++<<6)}}function c(C,R,z,Z,N,J){const V=R;let oe=0,le=0;for(;Z<=N;Z++){if(V.value-R.value>z)return!1;o(6,oe,le,C,V);const xe=s.l;if(oe=s.c,le=s.lc,J[Z]=xe,xe==63){if(V.value-R.value>z)throw new Error("Something wrong with hufUnpackEncTable");o(8,oe,le,C,V);let Te=s.l+6;if(oe=s.c,le=s.lc,Z+Te>N+1)throw new Error("Something wrong with hufUnpackEncTable");for(;Te--;)J[Z++]=0;Z--}else if(xe>=59){let Te=xe-59+2;if(Z+Te>N+1)throw new Error("Something wrong with hufUnpackEncTable");for(;Te--;)J[Z++]=0;Z--}}l(J)}function h(C){return C&63}function d(C){return C>>6}function p(C,R,z,Z){for(;R<=z;R++){const N=d(C[R]),J=h(C[R]);if(N>>J)throw new Error("Invalid table entry");if(J>14){const V=Z[N>>J-14];if(V.len)throw new Error("Invalid table entry");if(V.lit++,V.p){const oe=V.p;V.p=new Array(V.lit);for(let le=0;le<V.lit-1;++le)V.p[le]=oe[le]}else V.p=new Array(1);V.p[V.lit-1]=R}else if(J){let V=0;for(let oe=1<<14-J;oe>0;oe--){const le=Z[(N<<14-J)+V];if(le.len||le.p)throw new Error("Invalid table entry");le.len=J,le.lit=R,V++}}}return!0}const f={c:0,lc:0};function m(C,R,z,Z){C=C<<8|W(z,Z),R+=8,f.c=C,f.lc=R}const A={c:0,lc:0};function v(C,R,z,Z,N,J,V,oe,le){if(C==R){Z<8&&(m(z,Z,N,J),z=f.c,Z=f.lc),Z-=8;let xe=z>>Z;if(xe=new Uint8Array([xe])[0],oe.value+xe>le)return!1;const Te=V[oe.value-1];for(;xe-- >0;)V[oe.value++]=Te}else if(oe.value<le)V[oe.value++]=C;else return!1;A.c=z,A.lc=Z}function g(C){return C&65535}function b(C){const R=g(C);return R>32767?R-65536:R}const y={a:0,b:0};function x(C,R){const z=b(C),Z=b(R),N=z+(Z&1)+(Z>>1),J=N,V=N-Z;y.a=J,y.b=V}function w(C,R){const z=g(C),Z=g(R),N=z-(Z>>1)&65535,J=Z+N-32768&65535;y.a=J,y.b=N}function I(C,R,z,Z,N,J,V){const oe=V<16384,le=z>N?N:z;let xe=1,Te,We;for(;xe<=le;)xe<<=1;for(xe>>=1,Te=xe,xe>>=1;xe>=1;){We=0;const Ve=We+J*(N-Te),Ye=J*xe,ft=J*Te,it=Z*xe,yt=Z*Te;let Xt,Oi,$i,dr;for(;We<=Ve;We+=ft){let Di=We;const ri=We+Z*(z-Te);for(;Di<=ri;Di+=yt){const Bn=Di+it,no=Di+Ye,Gn=no+it;oe?(x(C[Di+R],C[no+R]),Xt=y.a,$i=y.b,x(C[Bn+R],C[Gn+R]),Oi=y.a,dr=y.b,x(Xt,Oi),C[Di+R]=y.a,C[Bn+R]=y.b,x($i,dr),C[no+R]=y.a,C[Gn+R]=y.b):(w(C[Di+R],C[no+R]),Xt=y.a,$i=y.b,w(C[Bn+R],C[Gn+R]),Oi=y.a,dr=y.b,w(Xt,Oi),C[Di+R]=y.a,C[Bn+R]=y.b,w($i,dr),C[no+R]=y.a,C[Gn+R]=y.b)}if(z&xe){const Bn=Di+Ye;oe?x(C[Di+R],C[Bn+R]):w(C[Di+R],C[Bn+R]),Xt=y.a,C[Bn+R]=y.b,C[Di+R]=Xt}}if(N&xe){let Di=We;const ri=We+Z*(z-Te);for(;Di<=ri;Di+=yt){const Bn=Di+it;oe?x(C[Di+R],C[Bn+R]):w(C[Di+R],C[Bn+R]),Xt=y.a,C[Bn+R]=y.b,C[Di+R]=Xt}}Te=xe,xe>>=1}return We}function M(C,R,z,Z,N,J,V,oe,le){let xe=0,Te=0;const We=V,Ve=Math.trunc(Z.value+(N+7)/8);for(;Z.value<Ve;)for(m(xe,Te,z,Z),xe=f.c,Te=f.lc;Te>=14;){const ft=xe>>Te-14&16383,it=R[ft];if(it.len)Te-=it.len,v(it.lit,J,xe,Te,z,Z,oe,le,We),xe=A.c,Te=A.lc;else{if(!it.p)throw new Error("hufDecode issues");let yt;for(yt=0;yt<it.lit;yt++){const Xt=h(C[it.p[yt]]);for(;Te<Xt&&Z.value<Ve;)m(xe,Te,z,Z),xe=f.c,Te=f.lc;if(Te>=Xt&&d(C[it.p[yt]])==(xe>>Te-Xt&(1<<Xt)-1)){Te-=Xt,v(it.p[yt],J,xe,Te,z,Z,oe,le,We),xe=A.c,Te=A.lc;break}}if(yt==it.lit)throw new Error("hufDecode issues")}}const Ye=8-N&7;for(xe>>=Ye,Te-=Ye;Te>0;){const ft=R[xe<<14-Te&16383];if(ft.len)Te-=ft.len,v(ft.lit,J,xe,Te,z,Z,oe,le,We),xe=A.c,Te=A.lc;else throw new Error("hufDecode issues")}return!0}function T(C,R,z,Z,N,J){const V={value:0},oe=z.value,le=fe(R,z),xe=fe(R,z);z.value+=4;const Te=fe(R,z);if(z.value+=4,le<0||le>=65537||xe<0||xe>=65537)throw new Error("Something wrong with HUF_ENCSIZE");const We=new Array(65537),Ve=new Array(16384);r(Ve);const Ye=Z-(z.value-oe);if(c(C,z,Ye,le,xe,We),Te>8*(Z-(z.value-oe)))throw new Error("Something wrong with hufUncompress");p(We,le,xe,Ve),M(We,Ve,C,z,Te,xe,J,N,V)}function D(C,R,z){for(let Z=0;Z<z;++Z)R[Z]=C[R[Z]]}function S(C){for(let R=1;R<C.length;R++){const z=C[R-1]+C[R]-128;C[R]=z}}function B(C,R){let z=0,Z=Math.floor((C.length+1)/2),N=0;const J=C.length-1;for(;!(N>J||(R[N++]=C[z++],N>J));)R[N++]=C[Z++]}function U(C){let R=C.byteLength;const z=new Array;let Z=0;const N=new DataView(C);for(;R>0;){const J=N.getInt8(Z++);if(J<0){const V=-J;R-=V+1;for(let oe=0;oe<V;oe++)z.push(N.getUint8(Z++))}else{const V=J;R-=2;const oe=N.getUint8(Z++);for(let le=0;le<V+1;le++)z.push(oe)}}return z}function j(C,R,z,Z,N,J){let V=new DataView(J.buffer);const oe=z[C.idx[0]].width,le=z[C.idx[0]].height,xe=3,Te=Math.floor(oe/8),We=Math.ceil(oe/8),Ve=Math.ceil(le/8),Ye=oe-(We-1)*8,ft=le-(Ve-1)*8,it={value:0},yt=new Array(xe),Xt=new Array(xe),Oi=new Array(xe),$i=new Array(xe),dr=new Array(xe);for(let ri=0;ri<xe;++ri)dr[ri]=R[C.idx[ri]],yt[ri]=ri<1?0:yt[ri-1]+We*Ve,Xt[ri]=new Float32Array(64),Oi[ri]=new Uint16Array(64),$i[ri]=new Uint16Array(We*64);for(let ri=0;ri<Ve;++ri){let Bn=8;ri==Ve-1&&(Bn=ft);let no=8;for(let F=0;F<We;++F){F==We-1&&(no=Ye);for(let ie=0;ie<xe;++ie)Oi[ie].fill(0),Oi[ie][0]=N[yt[ie]++],L(it,Z,Oi[ie]),H(Oi[ie],Xt[ie]),P(Xt[ie]);O(Xt);for(let ie=0;ie<xe;++ie)Q(Xt[ie],$i[ie],F*64)}let Gn=0;for(let F=0;F<xe;++F){const ie=z[C.idx[F]].type;for(let de=8*ri;de<8*ri+Bn;++de){Gn=dr[F][de];for(let me=0;me<Te;++me){const ae=me*64+(de&7)*8;V.setUint16(Gn+0*2*ie,$i[F][ae+0],!0),V.setUint16(Gn+1*2*ie,$i[F][ae+1],!0),V.setUint16(Gn+2*2*ie,$i[F][ae+2],!0),V.setUint16(Gn+3*2*ie,$i[F][ae+3],!0),V.setUint16(Gn+4*2*ie,$i[F][ae+4],!0),V.setUint16(Gn+5*2*ie,$i[F][ae+5],!0),V.setUint16(Gn+6*2*ie,$i[F][ae+6],!0),V.setUint16(Gn+7*2*ie,$i[F][ae+7],!0),Gn+=8*2*ie}}if(Te!=We)for(let de=8*ri;de<8*ri+Bn;++de){const me=dr[F][de]+8*Te*2*ie,ae=Te*64+(de&7)*8;for(let Je=0;Je<no;++Je)V.setUint16(me+Je*2*ie,$i[F][ae+Je],!0)}}}const Di=new Uint16Array(oe);V=new DataView(J.buffer);for(let ri=0;ri<xe;++ri){z[C.idx[ri]].decoded=!0;const Bn=z[C.idx[ri]].type;if(z[ri].type==2)for(let no=0;no<le;++no){const Gn=dr[ri][no];for(let F=0;F<oe;++F)Di[F]=V.getUint16(Gn+F*2*Bn,!0);for(let F=0;F<oe;++F)V.setFloat32(Gn+F*2*Bn,Ae(Di[F]),!0)}}}function L(C,R,z){let Z,N=1;for(;N<64;)Z=R[C.value],Z==65280?N=64:Z>>8==255?N+=Z&255:(z[N]=Z,N++),C.value++}function H(C,R){R[0]=Ae(C[0]),R[1]=Ae(C[1]),R[2]=Ae(C[5]),R[3]=Ae(C[6]),R[4]=Ae(C[14]),R[5]=Ae(C[15]),R[6]=Ae(C[27]),R[7]=Ae(C[28]),R[8]=Ae(C[2]),R[9]=Ae(C[4]),R[10]=Ae(C[7]),R[11]=Ae(C[13]),R[12]=Ae(C[16]),R[13]=Ae(C[26]),R[14]=Ae(C[29]),R[15]=Ae(C[42]),R[16]=Ae(C[3]),R[17]=Ae(C[8]),R[18]=Ae(C[12]),R[19]=Ae(C[17]),R[20]=Ae(C[25]),R[21]=Ae(C[30]),R[22]=Ae(C[41]),R[23]=Ae(C[43]),R[24]=Ae(C[9]),R[25]=Ae(C[11]),R[26]=Ae(C[18]),R[27]=Ae(C[24]),R[28]=Ae(C[31]),R[29]=Ae(C[40]),R[30]=Ae(C[44]),R[31]=Ae(C[53]),R[32]=Ae(C[10]),R[33]=Ae(C[19]),R[34]=Ae(C[23]),R[35]=Ae(C[32]),R[36]=Ae(C[39]),R[37]=Ae(C[45]),R[38]=Ae(C[52]),R[39]=Ae(C[54]),R[40]=Ae(C[20]),R[41]=Ae(C[22]),R[42]=Ae(C[33]),R[43]=Ae(C[38]),R[44]=Ae(C[46]),R[45]=Ae(C[51]),R[46]=Ae(C[55]),R[47]=Ae(C[60]),R[48]=Ae(C[21]),R[49]=Ae(C[34]),R[50]=Ae(C[37]),R[51]=Ae(C[47]),R[52]=Ae(C[50]),R[53]=Ae(C[56]),R[54]=Ae(C[59]),R[55]=Ae(C[61]),R[56]=Ae(C[35]),R[57]=Ae(C[36]),R[58]=Ae(C[48]),R[59]=Ae(C[49]),R[60]=Ae(C[57]),R[61]=Ae(C[58]),R[62]=Ae(C[62]),R[63]=Ae(C[63])}function P(C){const R=.5*Math.cos(.7853975),z=.5*Math.cos(3.14159/16),Z=.5*Math.cos(3.14159/8),N=.5*Math.cos(3*3.14159/16),J=.5*Math.cos(5*3.14159/16),V=.5*Math.cos(3*3.14159/8),oe=.5*Math.cos(7*3.14159/16),le=new Array(4),xe=new Array(4),Te=new Array(4),We=new Array(4);for(let Ve=0;Ve<8;++Ve){const Ye=Ve*8;le[0]=Z*C[Ye+2],le[1]=V*C[Ye+2],le[2]=Z*C[Ye+6],le[3]=V*C[Ye+6],xe[0]=z*C[Ye+1]+N*C[Ye+3]+J*C[Ye+5]+oe*C[Ye+7],xe[1]=N*C[Ye+1]-oe*C[Ye+3]-z*C[Ye+5]-J*C[Ye+7],xe[2]=J*C[Ye+1]-z*C[Ye+3]+oe*C[Ye+5]+N*C[Ye+7],xe[3]=oe*C[Ye+1]-J*C[Ye+3]+N*C[Ye+5]-z*C[Ye+7],Te[0]=R*(C[Ye+0]+C[Ye+4]),Te[3]=R*(C[Ye+0]-C[Ye+4]),Te[1]=le[0]+le[3],Te[2]=le[1]-le[2],We[0]=Te[0]+Te[1],We[1]=Te[3]+Te[2],We[2]=Te[3]-Te[2],We[3]=Te[0]-Te[1],C[Ye+0]=We[0]+xe[0],C[Ye+1]=We[1]+xe[1],C[Ye+2]=We[2]+xe[2],C[Ye+3]=We[3]+xe[3],C[Ye+4]=We[3]-xe[3],C[Ye+5]=We[2]-xe[2],C[Ye+6]=We[1]-xe[1],C[Ye+7]=We[0]-xe[0]}for(let Ve=0;Ve<8;++Ve)le[0]=Z*C[16+Ve],le[1]=V*C[16+Ve],le[2]=Z*C[48+Ve],le[3]=V*C[48+Ve],xe[0]=z*C[8+Ve]+N*C[24+Ve]+J*C[40+Ve]+oe*C[56+Ve],xe[1]=N*C[8+Ve]-oe*C[24+Ve]-z*C[40+Ve]-J*C[56+Ve],xe[2]=J*C[8+Ve]-z*C[24+Ve]+oe*C[40+Ve]+N*C[56+Ve],xe[3]=oe*C[8+Ve]-J*C[24+Ve]+N*C[40+Ve]-z*C[56+Ve],Te[0]=R*(C[Ve]+C[32+Ve]),Te[3]=R*(C[Ve]-C[32+Ve]),Te[1]=le[0]+le[3],Te[2]=le[1]-le[2],We[0]=Te[0]+Te[1],We[1]=Te[3]+Te[2],We[2]=Te[3]-Te[2],We[3]=Te[0]-Te[1],C[0+Ve]=We[0]+xe[0],C[8+Ve]=We[1]+xe[1],C[16+Ve]=We[2]+xe[2],C[24+Ve]=We[3]+xe[3],C[32+Ve]=We[3]-xe[3],C[40+Ve]=We[2]-xe[2],C[48+Ve]=We[1]-xe[1],C[56+Ve]=We[0]-xe[0]}function O(C){for(let R=0;R<64;++R){const z=C[0][R],Z=C[1][R],N=C[2][R];C[0][R]=z+1.5747*N,C[1][R]=z-.1873*Z-.4682*N,C[2][R]=z+1.8556*Z}}function Q(C,R,z){for(let Z=0;Z<64;++Z)R[z+Z]=Ld.toHalfFloat(X(C[Z]))}function X(C){return C<=1?Math.sign(C)*Math.pow(Math.abs(C),2.2):Math.sign(C)*Math.pow(t,Math.abs(C)-1)}function Y(C){return new DataView(C.array.buffer,C.offset.value,C.size)}function ne(C){const R=C.viewer.buffer.slice(C.offset.value,C.offset.value+C.size),z=new Uint8Array(U(R)),Z=new Uint8Array(z.length);return S(z),B(z,Z),new DataView(Z.buffer)}function ye(C){const R=C.array.slice(C.offset.value,C.offset.value+C.size),z=_v(R),Z=new Uint8Array(z.length);return S(z),B(z,Z),new DataView(Z.buffer)}function Pe(C){const R=C.viewer,z={value:C.offset.value},Z=new Uint16Array(C.width*C.scanlineBlockSize*(C.channels*C.type)),N=new Uint8Array(8192);let J=0;const V=new Array(C.channels);for(let ft=0;ft<C.channels;ft++)V[ft]={},V[ft].start=J,V[ft].end=V[ft].start,V[ft].nx=C.width,V[ft].ny=C.lines,V[ft].size=C.type,J+=V[ft].nx*V[ft].ny*V[ft].size;const oe=Ze(R,z),le=Ze(R,z);if(le>=8192)throw new Error("Something is wrong with PIZ_COMPRESSION BITMAP_SIZE");if(oe<=le)for(let ft=0;ft<le-oe+1;ft++)N[ft+oe]=Ne(R,z);const xe=new Uint16Array(65536),Te=n(N,xe),We=fe(R,z);T(C.array,R,z,We,Z,J);for(let ft=0;ft<C.channels;++ft){const it=V[ft];for(let yt=0;yt<V[ft].size;++yt)I(Z,it.start+yt,it.nx,it.size,it.ny,it.nx*it.size,Te)}D(xe,Z,J);let Ve=0;const Ye=new Uint8Array(Z.buffer.byteLength);for(let ft=0;ft<C.lines;ft++)for(let it=0;it<C.channels;it++){const yt=V[it],Xt=yt.nx*yt.size,Oi=new Uint8Array(Z.buffer,yt.end*2,Xt*2);Ye.set(Oi,Ve),Ve+=Xt*2,yt.end+=Xt}return new DataView(Ye.buffer)}function se(C){const R=C.array.slice(C.offset.value,C.offset.value+C.size),z=_v(R),Z=C.lines*C.channels*C.width,N=C.type==1?new Uint16Array(Z):new Uint32Array(Z);let J=0,V=0;const oe=new Array(4);for(let le=0;le<C.lines;le++)for(let xe=0;xe<C.channels;xe++){let Te=0;switch(C.type){case 1:oe[0]=J,oe[1]=oe[0]+C.width,J=oe[1]+C.width;for(let We=0;We<C.width;++We){const Ve=z[oe[0]++]<<8|z[oe[1]++];Te+=Ve,N[V]=Te,V++}break;case 2:oe[0]=J,oe[1]=oe[0]+C.width,oe[2]=oe[1]+C.width,J=oe[2]+C.width;for(let We=0;We<C.width;++We){const Ve=z[oe[0]++]<<24|z[oe[1]++]<<16|z[oe[2]++]<<8;Te+=Ve,N[V]=Te,V++}break}}return new DataView(N.buffer)}function be(C){const R=C.viewer,z={value:C.offset.value},Z=new Uint8Array(C.width*C.lines*(C.channels*C.type*2)),N={version:Ie(R,z),unknownUncompressedSize:Ie(R,z),unknownCompressedSize:Ie(R,z),acCompressedSize:Ie(R,z),dcCompressedSize:Ie(R,z),rleCompressedSize:Ie(R,z),rleUncompressedSize:Ie(R,z),rleRawSize:Ie(R,z),totalAcUncompressedCount:Ie(R,z),totalDcUncompressedCount:Ie(R,z),acCompression:Ie(R,z)};if(N.version<2)throw new Error("EXRLoader.parse: "+Wt.compression+" version "+N.version+" is unsupported");const J=new Array;let V=Ze(R,z)-2;for(;V>0;){const it=Me(R.buffer,z),yt=Ne(R,z),Xt=yt>>2&3,Oi=(yt>>4)-1,$i=new Int8Array([Oi])[0],dr=Ne(R,z);J.push({name:it,index:$i,type:dr,compression:Xt}),V-=it.length+3}const oe=Wt.channels,le=new Array(C.channels);for(let it=0;it<C.channels;++it){const yt=le[it]={},Xt=oe[it];yt.name=Xt.name,yt.compression=0,yt.decoded=!1,yt.type=Xt.pixelType,yt.pLinear=Xt.pLinear,yt.width=C.width,yt.height=C.lines}const xe={idx:new Array(3)};for(let it=0;it<C.channels;++it){const yt=le[it];for(let Xt=0;Xt<J.length;++Xt){const Oi=J[Xt];yt.name==Oi.name&&(yt.compression=Oi.compression,Oi.index>=0&&(xe.idx[Oi.index]=it),yt.offset=it)}}let Te,We,Ve;if(N.acCompressedSize>0)switch(N.acCompression){case 0:Te=new Uint16Array(N.totalAcUncompressedCount),T(C.array,R,z,N.acCompressedSize,Te,N.totalAcUncompressedCount);break;case 1:const it=C.array.slice(z.value,z.value+N.totalAcUncompressedCount),yt=_v(it);Te=new Uint16Array(yt.buffer),z.value+=N.totalAcUncompressedCount;break}if(N.dcCompressedSize>0){const it={array:C.array,offset:z,size:N.dcCompressedSize};We=new Uint16Array(ye(it).buffer),z.value+=N.dcCompressedSize}if(N.rleRawSize>0){const it=C.array.slice(z.value,z.value+N.rleCompressedSize),yt=_v(it);Ve=U(yt.buffer),z.value+=N.rleCompressedSize}let Ye=0;const ft=new Array(le.length);for(let it=0;it<ft.length;++it)ft[it]=new Array;for(let it=0;it<C.lines;++it)for(let yt=0;yt<le.length;++yt)ft[yt].push(Ye),Ye+=le[yt].width*C.type*2;j(xe,ft,le,Te,We,Z);for(let it=0;it<le.length;++it){const yt=le[it];if(!yt.decoded)switch(yt.compression){case 2:let Xt=0,Oi=0;for(let $i=0;$i<C.lines;++$i){let dr=ft[it][Xt];for(let Di=0;Di<yt.width;++Di){for(let ri=0;ri<2*yt.type;++ri)Z[dr++]=Ve[Oi+ri*yt.width*yt.height];Oi++}Xt++}break;case 1:default:throw new Error("EXRLoader.parse: unsupported channel compression")}}return new DataView(Z.buffer)}function Me(C,R){const z=new Uint8Array(C);let Z=0;for(;z[R.value+Z]!=0;)Z+=1;const N=new TextDecoder().decode(z.slice(R.value,R.value+Z));return R.value=R.value+Z+1,N}function Xe(C,R,z){const Z=new TextDecoder().decode(new Uint8Array(C).slice(R.value,R.value+z));return R.value=R.value+z,Z}function Ke(C,R){const z=ot(C,R),Z=fe(C,R);return[z,Z]}function ke(C,R){const z=fe(C,R),Z=fe(C,R);return[z,Z]}function ot(C,R){const z=C.getInt32(R.value,!0);return R.value=R.value+4,z}function fe(C,R){const z=C.getUint32(R.value,!0);return R.value=R.value+4,z}function W(C,R){const z=C[R.value];return R.value=R.value+1,z}function Ne(C,R){const z=C.getUint8(R.value);return R.value=R.value+1,z}const Ie=function(C,R){let z;return"getBigInt64"in DataView.prototype?z=Number(C.getBigInt64(R.value,!0)):z=C.getUint32(R.value+4,!0)+Number(C.getUint32(R.value,!0)<<32),R.value+=8,z};function Se(C,R){const z=C.getFloat32(R.value,!0);return R.value+=4,z}function Ge(C,R){return Ld.toHalfFloat(Se(C,R))}function Ae(C){const R=(C&31744)>>10,z=C&1023;return(C>>15?-1:1)*(R?R===31?z?NaN:1/0:Math.pow(2,R-15)*(1+z/1024):6103515625e-14*(z/1024))}function Ze(C,R){const z=C.getUint16(R.value,!0);return R.value+=2,z}function at(C,R){return Ae(Ze(C,R))}function Et(C,R,z,Z){const N=z.value,J=[];for(;z.value<N+Z-1;){const V=Me(R,z),oe=ot(C,z),le=Ne(C,z);z.value+=3;const xe=ot(C,z),Te=ot(C,z);J.push({name:V,pixelType:oe,pLinear:le,xSampling:xe,ySampling:Te})}return z.value+=1,J}function G(C,R){const z=Se(C,R),Z=Se(C,R),N=Se(C,R),J=Se(C,R),V=Se(C,R),oe=Se(C,R),le=Se(C,R),xe=Se(C,R);return{redX:z,redY:Z,greenX:N,greenY:J,blueX:V,blueY:oe,whiteX:le,whiteY:xe}}function k(C,R){const z=["NO_COMPRESSION","RLE_COMPRESSION","ZIPS_COMPRESSION","ZIP_COMPRESSION","PIZ_COMPRESSION","PXR24_COMPRESSION","B44_COMPRESSION","B44A_COMPRESSION","DWAA_COMPRESSION","DWAB_COMPRESSION"],Z=Ne(C,R);return z[Z]}function ce(C,R){const z=fe(C,R),Z=fe(C,R),N=fe(C,R),J=fe(C,R);return{xMin:z,yMin:Z,xMax:N,yMax:J}}function Ee(C,R){const z=["INCREASING_Y"],Z=Ne(C,R);return z[Z]}function Oe(C,R){const z=Se(C,R),Z=Se(C,R);return[z,Z]}function Be(C,R){const z=Se(C,R),Z=Se(C,R),N=Se(C,R);return[z,Z,N]}function mt(C,R,z,Z,N){if(Z==="string"||Z==="stringvector"||Z==="iccProfile")return Xe(R,z,N);if(Z==="chlist")return Et(C,R,z,N);if(Z==="chromaticities")return G(C,z);if(Z==="compression")return k(C,z);if(Z==="box2i")return ce(C,z);if(Z==="lineOrder")return Ee(C,z);if(Z==="float")return Se(C,z);if(Z==="v2f")return Oe(C,z);if(Z==="v3f")return Be(C,z);if(Z==="int")return ot(C,z);if(Z==="rational")return Ke(C,z);if(Z==="timecode")return ke(C,z);if(Z==="preview")return z.value+=N,"skipped";z.value+=N}function lt(C,R,z){const Z={};if(C.getUint32(0,!0)!=20000630)throw new Error("THREE.EXRLoader: Provided file doesn't appear to be in OpenEXR format.");Z.version=C.getUint8(4);const N=C.getUint8(5);Z.spec={singleTile:!!(N&2),longName:!!(N&4),deepFormat:!!(N&8),multiPart:!!(N&16)},z.value=8;let J=!0;for(;J;){const V=Me(R,z);if(V==0)J=!1;else{const oe=Me(R,z),le=fe(C,z),xe=mt(C,R,z,oe,le);xe===void 0?console.warn(`THREE.EXRLoader: Skipped unknown header attribute type '${oe}'.`):Z[V]=xe}}if(N&-5)throw console.error("THREE.EXRHeader:",Z),new Error("THREE.EXRLoader: Provided file is currently unsupported.");return Z}function Qe(C,R,z,Z,N){const J={size:0,viewer:R,array:z,offset:Z,width:C.dataWindow.xMax-C.dataWindow.xMin+1,height:C.dataWindow.yMax-C.dataWindow.yMin+1,channels:C.channels.length,bytesPerLine:null,lines:null,inputSize:null,type:C.channels[0].pixelType,uncompress:null,getter:null,format:null,colorSpace:bi};switch(C.compression){case"NO_COMPRESSION":J.lines=1,J.uncompress=Y;break;case"RLE_COMPRESSION":J.lines=1,J.uncompress=ne;break;case"ZIPS_COMPRESSION":J.lines=1,J.uncompress=ye;break;case"ZIP_COMPRESSION":J.lines=16,J.uncompress=ye;break;case"PIZ_COMPRESSION":J.lines=32,J.uncompress=Pe;break;case"PXR24_COMPRESSION":J.lines=16,J.uncompress=se;break;case"DWAA_COMPRESSION":J.lines=32,J.uncompress=be;break;case"DWAB_COMPRESSION":J.lines=256,J.uncompress=be;break;default:throw new Error("EXRLoader.parse: "+C.compression+" is unsupported")}if(J.scanlineBlockSize=J.lines,J.type==1)switch(N){case Wi:J.getter=at,J.inputSize=2;break;case un:J.getter=Ze,J.inputSize=2;break}else if(J.type==2)switch(N){case Wi:J.getter=Se,J.inputSize=4;break;case un:J.getter=Ge,J.inputSize=4}else throw new Error("EXRLoader.parse: unsupported pixelType "+J.type+" for "+C.compression+".");J.blockCount=(C.dataWindow.yMax+1)/J.scanlineBlockSize;for(let oe=0;oe<J.blockCount;oe++)Ie(R,Z);J.outputChannels=J.channels==3?4:J.channels;const V=J.width*J.height*J.outputChannels;switch(N){case Wi:J.byteArray=new Float32Array(V),J.channels<J.outputChannels&&J.byteArray.fill(1,0,V);break;case un:J.byteArray=new Uint16Array(V),J.channels<J.outputChannels&&J.byteArray.fill(15360,0,V);break;default:console.error("THREE.EXRLoader: unsupported type: ",N);break}return J.bytesPerLine=J.width*J.inputSize*J.channels,J.outputChannels==4?(J.format=yi,J.colorSpace=bi):(J.format=Ga,J.colorSpace=Ps),J}const je=new DataView(e),xt=new Uint8Array(e),Fe={value:0},Wt=lt(je,e,Fe),Le=Qe(Wt,je,xt,Fe,this.type),vt={value:0},ct={R:0,G:1,B:2,A:3,Y:0};for(let C=0;C<Le.height/Le.scanlineBlockSize;C++){const R=fe(je,Fe);Le.size=fe(je,Fe),Le.lines=R+Le.scanlineBlockSize>Le.height?Le.height-R:Le.scanlineBlockSize;const z=Le.size<Le.lines*Le.bytesPerLine?Le.uncompress(Le):Y(Le);Fe.value+=Le.size;for(let Z=0;Z<Le.scanlineBlockSize;Z++){const N=Z+C*Le.scanlineBlockSize;if(N>=Le.height)break;for(let J=0;J<Le.channels;J++){const V=ct[Wt.channels[J].name];for(let oe=0;oe<Le.width;oe++){vt.value=(Z*(Le.channels*Le.width)+J*Le.width+oe)*Le.inputSize;const le=(Le.height-1-N)*(Le.width*Le.outputChannels)+oe*Le.outputChannels+V;Le.byteArray[le]=Le.getter(z,vt)}}}}return{header:Wt,width:Le.width,height:Le.height,data:Le.byteArray,format:Le.format,colorSpace:Le.colorSpace,type:this.type}}setDataType(e){return this.type=e,this}load(e,t,n,r){function s(o,a){o.colorSpace=a.colorSpace,o.minFilter=St,o.magFilter=St,o.generateMipmaps=!1,o.flipY=!1,t&&t(o,a)}return super.load(e,s,n,r)}}const Lde=Object.freeze(Object.defineProperty({__proto__:null,EXRLoader:$v},Symbol.toStringTag,{value:"Module"}));class iC extends jM{constructor(e){super(e),this.type=un}parse(e){const t=function(g,b){switch(g){case 1:throw new Error("THREE.RGBELoader: Read Error: "+(b||""));case 2:throw new Error("THREE.RGBELoader: Write Error: "+(b||""));case 3:throw new Error("THREE.RGBELoader: Bad File Format: "+(b||""));default:case 4:throw new Error("THREE.RGBELoader: Memory Error: "+(b||""))}},n=`
5239
5239
  `,r=function(g,b,y){b=b||1024;let x=g.pos,w=-1,I=0,M="",T=String.fromCharCode.apply(null,new Uint16Array(g.subarray(x,x+128)));for(;0>(w=T.indexOf(n))&&I<b&&x<g.byteLength;)M+=T,I+=T.length,x+=128,T+=String.fromCharCode.apply(null,new Uint16Array(g.subarray(x,x+128)));return-1<w?(y!==!1&&(g.pos+=I+w+1),M+T.slice(0,w)):!1},s=function(g){const b=/^#\?(\S+)/,y=/^\s*GAMMA\s*=\s*(\d+(\.\d+)?)\s*$/,x=/^\s*EXPOSURE\s*=\s*(\d+(\.\d+)?)\s*$/,w=/^\s*FORMAT=(\S+)\s*$/,I=/^\s*\-Y\s+(\d+)\s+\+X\s+(\d+)\s*$/,M={valid:0,string:"",comments:"",programtype:"RGBE",format:"",gamma:1,exposure:1,width:0,height:0};let T,D;for((g.pos>=g.byteLength||!(T=r(g)))&&t(1,"no header found"),(D=T.match(b))||t(3,"bad initial token"),M.valid|=1,M.programtype=D[1],M.string+=T+`
5240
5240
  `;T=r(g),T!==!1;){if(M.string+=T+`