@textadventures/quest-viva-wasmplayer 6.1.1 → 6.2.0-beta.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.
Files changed (38) hide show
  1. package/_framework/Common.wasm +0 -0
  2. package/_framework/Engine.wasm +0 -0
  3. package/_framework/ExtendedNumerics.BigDecimal.wasm +0 -0
  4. package/_framework/Legacy.wasm +0 -0
  5. package/_framework/Microsoft.Extensions.Logging.Abstractions.wasm +0 -0
  6. package/_framework/NCalc.Core.wasm +0 -0
  7. package/_framework/NCalc.Domain.wasm +0 -0
  8. package/_framework/NCalc.Parser.wasm +0 -0
  9. package/_framework/Parlot.wasm +0 -0
  10. package/_framework/PlayerCore.wasm +0 -0
  11. package/_framework/System.Collections.Immutable.wasm +0 -0
  12. package/_framework/System.Linq.wasm +0 -0
  13. package/_framework/System.Net.Http.wasm +0 -0
  14. package/_framework/System.Private.CoreLib.wasm +0 -0
  15. package/_framework/System.Private.Xml.Linq.wasm +0 -0
  16. package/_framework/System.Private.Xml.wasm +0 -0
  17. package/_framework/System.Runtime.Numerics.wasm +0 -0
  18. package/_framework/System.Text.RegularExpressions.wasm +0 -0
  19. package/_framework/WasmPlayer.wasm +0 -0
  20. package/_framework/dotnet.js +36 -42
  21. package/_framework/dotnet.native.wasm +0 -0
  22. package/chrome.css +1 -1
  23. package/export-manifest.json +1 -1
  24. package/game-saver.js +5 -1
  25. package/gamepad.js +668 -0
  26. package/index.html +53 -11
  27. package/legacy/adapter.js +14 -0
  28. package/legacy/grid.js +4 -0
  29. package/legacy/player.js +14 -0
  30. package/legacy/playercore.js +8 -1
  31. package/legacy/questui.js +5 -1
  32. package/package.json +1 -1
  33. package/v2/map.js +1 -1
  34. package/v2/player.htm +2 -0
  35. package/v2/v2.css +1 -1
  36. package/v2/v2.js +1 -1
  37. package/wasm-player.js +135 -13
  38. package/_framework/System.Linq.Expressions.wasm +0 -0
package/v2/v2.js CHANGED
@@ -1 +1 @@
1
- "use strict";(()=>{var s={autoScroll:!0,warnedAboutScript:!1,animateScroll:!0,fadePreviousOutput:!1,continueOnClick:!1,commandPlaceholder:null,compassDirections:[],interfaceStrings:new Map,gameFinished:!1,soundWait:!1,waiting:!1,pausing:!1,inDialog:!1,turnPending:!0,hasUnsavedProgress:!1,canSave:!1},F=new Map;function zt(t,e){if(typeof e!="function")return;let n=F.get(t);n||F.set(t,n=new Set),n.add(e)}function Gt(t,e){F.get(t)?.delete(e)}function b(t,e){for(let n of F.get(t)??[])try{n(e)}catch(o){console.error(o)}}function Kt(){s.autoScroll=!0,s.warnedAboutScript=!1,s.fadePreviousOutput=!1,s.continueOnClick=!1,s.commandPlaceholder=null,s.interfaceStrings.clear(),s.compassDirections=[],s.gameFinished=!1,s.soundWait=!1,s.waiting=!1,s.pausing=!1,s.inDialog=!1,s.turnPending=!0,s.hasUnsavedProgress=!1,F.clear()}var pn={inventory:"inventoryChanged",objects:"objectsChanged",exits:"exitsChanged",status:"statusChanged"},tt={inventory:[],objects:[],exits:[],status:[]},bt=new Set;function Yt(){return structuredClone(tt)}function _t(){tt={inventory:[],objects:[],exits:[],status:[]},bt.clear()}function P(t,e){if(bt.has(t)&&JSON.stringify(e)===JSON.stringify(tt[t]))return;bt.add(t),tt[t]=e;let n=structuredClone(e);b(pn[t],t==="exits"?{exits:n}:{items:n})}function Jt(t){return{text:String(t.Text??""),name:String(t.ElementName??""),elementId:String(t.ElementId??""),verbs:(t.Verbs??[]).map(String)}}var C=typeof HTMLElement.prototype.showPopover=="function";function H(t){for(let e of t.querySelectorAll("a.cmdlink, a[data-qv-event]"))e.hasAttribute("tabindex")||(e.tabIndex=0),e.setAttribute("role","button"),e.classList.contains("elementmenu")&&(e.setAttribute("aria-haspopup","menu"),e.setAttribute("aria-expanded","false")),e.toggleAttribute("aria-disabled",e.classList.contains("disabled"));for(let e of t.querySelectorAll("[data-qv-popup]"))e.setAttribute("aria-controls",e.dataset.qvPopup??""),e.setAttribute("aria-expanded","false")}function Xt(t){for(let e of t.querySelectorAll("[data-qv-popup-content].qv-popup-open"))e.classList.remove("qv-popup-open");for(let e of t.querySelectorAll('[aria-expanded="true"]'))e.setAttribute("aria-expanded","false")}function M(t,e){t.classList.toggle("disabled",!e),e?t.removeAttribute("aria-disabled"):t.setAttribute("aria-disabled","true")}var k=t=>t.classList.contains("disabled");function yt(t){t.setAttribute("data-qv-deactivated",""),M(t,!1)}function Zt(t){return Array.isArray(t)?t.map(String):[]}function te(t,e,n){if(e==="object"){let o=n&&typeof n=="object"?n:{};for(let r of t.querySelectorAll("a.elementmenu")){let i=o[r.dataset.elementid??""];i&&(r.dataset.verbs=String(i)),M(r,!!i)}}else if(e==="exit"){let o=Zt(n);for(let r of t.querySelectorAll("a.exitlink"))M(r,o.includes(r.dataset.elementid??""))}else if(e==="command"){let o=Zt(n);for(let r of t.querySelectorAll("a.commandlink:not([data-qv-deactivated])")){let i=r.dataset.elementid??"";M(r,i===""||o.includes(i))}}}function ee(t,e,n){let o=document.getElementById(t);o&&(o.classList.add("cmdlink","elementmenu"),o.dataset.verbs=e,o.dataset.elementid||(o.dataset.elementid=n),H(o.parentElement??o))}function ne(t,e){let n=t.target instanceof Element?t.target:null;if(!n)return;let o=n.closest("[data-qv-popup]");if(o){t.preventDefault(),gn(o);return}let r=n.closest("[data-qv-direction]");if(r){r.disabled||g(r.dataset.qvDirection??"");return}let i=n.closest(".qv-pane-item");if(i){e?.toggle(i);return}let l=n.closest("[data-qv-popup-content]");l&&re(l);let c=n.closest("a");c&&(c.matches(".cmdlink, [data-qv-event]")?fn(t,c,e):c.hasAttribute("href")&&hn(t,c))}function fn(t,e,n){if(e.dataset.qvEvent!==void 0){if(t.preventDefault(),k(e))return;if(e.dataset.qvEvent==="ShowMenuResponse")for(let o of e.ownerDocument.querySelectorAll('a[data-qv-event="ShowMenuResponse"]'))M(o,!1);E(e.dataset.qvEvent,e.dataset.qvParam??"")}else if(e.classList.contains("elementmenu"))t.preventDefault(),k(e)||n?.toggle(e);else if(e.classList.contains("exitlink"))t.preventDefault(),k(e)||g(e.dataset.command??"");else if(e.classList.contains("commandlink")){if(t.preventDefault(),k(e)||!Q())return;e.dataset.deactivateonclick==="true"&&yt(e),g(e.dataset.command??"")}}function hn(t,e){let n=e.getAttribute("href")??"";n.startsWith("#")||/^\s*javascript:/i.test(n)||(t.preventDefault(),window.open(e.href,"_blank","noopener"))}function oe(t){if(t.key!=="Enter"&&t.key!==" ")return;let e=t.target instanceof HTMLAnchorElement?t.target:null;e?.matches(".cmdlink, [data-qv-event]")&&(t.preventDefault(),e.click())}function vn(t){let e=document.getElementById(t.dataset.qvPopup??"");return e?.hasAttribute("data-qv-popup-content")?e:null}function gn(t){let e=vn(t);if(e){if(e.classList.contains("qv-popup-open")){re(e);return}C&&!e.popover&&(e.popover="auto",e.addEventListener("beforetoggle",n=>{n.newState==="closed"&&St(e,!1)})),St(e,!0),C&&e.showPopover()}}function re(t){C&&t.matches(":popover-open")&&t.hidePopover(),St(t,!1)}function St(t,e){t.classList.toggle("qv-popup-open",e);for(let n of document.querySelectorAll(`[data-qv-popup="${CSS.escape(t.id)}"]`))n.setAttribute("aria-expanded",String(e))}var Et=["inventory","objects","status","compass","commands","customstatus"],bn={InventoryLabel:"inventory",PlacesObjectsLabel:"objects",StatusLabel:"status",CompassLabel:"compass"},et=class extends HTMLElement{#e;#t;#n;connectedCallback(){this.#e||(this.dataset.qvPart="pane",this.#e=document.createElement("details"),this.#e.open=!0,this.#t=document.createElement("summary"),this.#t.className="qv-pane-heading",this.#t.textContent=this.getAttribute("label")??"",this.#n=document.createElement("div"),this.#n.className="qv-pane-body",this.#n.append(...this.childNodes),this.#e.append(this.#t,this.#n),this.append(this.#e))}get name(){return this.dataset.qvPane??""}get body(){return this.#n}setLabel(e){this.#t.innerHTML=e}setContent(e){this.#n.innerHTML=e,H(this.#n)}};function f(t){return a()?.querySelector(`qv-pane[data-qv-pane="${CSS.escape(t)}"]`)??null}var Sn={inventory:"inventory",placesobjects:"objects"};function ie(t,e){let n=Sn[t];if(!n)return;let o=new Set(s.compassDirections),r=Object.values(e).map(c=>JSON.parse(c)).filter(c=>t!=="placesobjects"||!o.has(c.Text));P(n,r.map(Jt));let i=f(n);if(!i)return;let l=document.createElement("ul");l.className="qv-pane-list";for(let c of r){let u=document.createElement("button");u.type="button",u.className="qv-pane-item",u.innerHTML=c.Text,u.setAttribute("aria-haspopup","menu"),u.setAttribute("aria-expanded","false"),u.dataset.verbs=(c.Verbs??[]).join("/"),u.dataset.qvName=c.ElementName,c.ElementId&&(u.dataset.elementid=c.ElementId);let p=document.createElement("li");p.append(u),l.append(p)}if(l.childElementCount)i.body.replaceChildren(l);else{let c=document.createElement("p");c.className="qv-pane-empty",c.innerHTML=s.interfaceStrings.get(n==="inventory"?"InventoryEmptyLabel":"PlacesObjectsEmptyLabel")??s.interfaceStrings.get("EmptyListLabel")??"",i.body.replaceChildren(c)}a()?.verbMenu?.closeIfStale()}function ae(t){let e=f("commands");if(!e)return;let o=(Array.isArray(t)?t.map(String):String(t??"").split(";")).filter(r=>r.trim()).map(r=>{let[i,l]=r.split(":"),c=u=>u.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;");return`<a class="cmdlink commandlink" data-elementid="" data-command="${c((l??i).trim().toLowerCase())}">${c(i.trim())}</a>`}).join(" ");e.setContent(o)}function le(t,e){t==="map"||t!=="customstatus"&&Et.includes(t)||f(t)?.setContent(e)}function ce(t,e,n){let o=a()?.panes;if(!t||t==="map"||!o||f(t))return;let r=document.createElement("qv-pane");r.dataset.qvPane=t,r.setAttribute("label",e??t),o.append(r),r.setContent(n??"")}function ue(t){let e=a()?.panes;if(!e)return;let n=Array.isArray(t)?t.map(String):String(t??"").split(";");for(let o of[...n].reverse()){let r=f(o);r&&e.prepend(r)}}function de(t,e){let n=bn[t];return n?(f(n)?.setLabel(e),!0):!1}function nt(){return!!a()?.panes?.classList.contains("qv-drawer-open")}function L(t,{restoreFocus:e=!0}={}){let n=a(),o=n?.panes,r=n?.panesButton;!o||!r||t===nt()||(o.classList.toggle("qv-drawer-open",t),r.setAttribute("aria-expanded",String(t)),t?(document.addEventListener("pointerdown",se,!0),o.querySelector('summary, button, a[href], [tabindex="0"]')?.focus()):(document.removeEventListener("pointerdown",se,!0),e&&o.contains(document.activeElement)&&r.focus()))}function se(t){let e=a(),n=t.target instanceof Node?t.target:null;!n||e?.panes?.contains(n)||e?.panesButton?.contains(n)||e?.verbMenu?.contains(n)||L(!1,{restoreFocus:!1})}var yn=["northwest","north","northeast","west","east","southwest","south","southeast","up","down","in","out"],pe=[315,0,45,270,90,225,180,135,null,null,null,null],me="http://www.w3.org/2000/svg",Lt=[[1,1],[1,2],[1,3],[2,1],[2,3],[3,1],[3,2],[3,3]],V=[];function ot(){return s.compassDirections.length===12?s.compassDirections:yn}function fe(t){let e=ot()[t];return t===10?wt(s.interfaceStrings.get("InButtonLabel"))||e:t===11&&wt(s.interfaceStrings.get("OutButtonLabel"))||e}function wt(t){if(!t)return"";let e=document.createElement("template");return e.innerHTML=t,e.content.textContent?.trim()??""}function he(t,e){let n=ot()[t],o=document.createElement("button");o.type="button",o.className=e,o.dataset.qvDirection=n;let r=pe[t];return r!=null&&o.append(En(r)),o}function En(t){let e=document.createElementNS(me,"svg");e.setAttribute("class","qv-direction-arrow"),e.setAttribute("viewBox","0 0 24 24"),e.setAttribute("aria-hidden","true"),e.setAttribute("fill","none"),e.setAttribute("stroke","currentColor"),e.setAttribute("stroke-width","2"),e.setAttribute("stroke-linecap","round"),e.setAttribute("stroke-linejoin","round");let n=document.createElementNS(me,"path");return n.setAttribute("d","M12 19V5M5 12l7-7 7 7"),n.setAttribute("transform",`rotate(${t} 12 12)`),e.append(n),e}function I(){let t=f("compass");if(t){let e=document.createElement("div");e.className="qv-compass-points";let n=document.createElement("div");n.className="qv-compass-others",ot().forEach((r,i)=>{let l=he(i,"qv-compass-button"),c=fe(i);l.setAttribute("aria-label",c),l.title=c,pe[i]==null&&l.append(c),l.disabled=!V.includes(r),Lt[i]?(l.style.gridRow=String(Lt[i][0]),l.style.gridColumn=String(Lt[i][1]),e.append(l)):n.append(l)});let o=document.createElement("div");o.className="qv-compass",o.append(e,n),t.body.replaceChildren(o)}h()}function ve(t){V=String(t??"").split("/").filter(Boolean),P("exits",[...V]),I()}function ge(){V=[]}function h(){let t=a(),e=t?.exits;if(!t||!e)return;let n=f("compass"),o=!!n&&!n.hidden&&!t.panes?.hidden,r=!s.turnPending&&!s.waiting&&!s.pausing&&!s.inDialog&&!s.gameFinished,i=[];o&&r&&ot().forEach((l,c)=>{if(!V.includes(l))return;let u=he(c,"qv-exit");u.append(fe(c)),i.push(u)}),e.replaceChildren(...i),e.setAttribute("aria-label",wt(s.interfaceStrings.get("CompassLabel"))||(WebPlayer.chromeStrings?.CompassLabel??"Compass")),e.classList.toggle("qv-exits-active",i.length>0)}var B=[];function qt(t){B=Array.isArray(t)?t.filter(e=>e&&typeof e=="object"):[],P("status",B),xt()}function be(t){qt(String(t??"").split(/\r?\n|<br\s*\/?>/i).filter(e=>e.trim()).map(e=>({text:e})))}function Se(){B=[]}function Ln(t){let e=Number(t.value),n=Number(t.max);return t.value==null||t.max==null||!Number.isFinite(e)||!Number.isFinite(n)||n<=0?null:{value:Math.min(Math.max(e,0),n),max:n}}var wn=0;function ye(t,e){let n=document.createElement(e);n.className="qv-status-item",t.name&&(n.dataset.qvStatus=String(t.name));let o=document.createElement("span");o.className="qv-status-text",o.id=`qv-status-${++wn}`,o.innerHTML=String(t.text??""),n.append(o);let r=Ln(t);if(r){let i=document.createElement("span");i.className="qv-status-meter",i.setAttribute("role","meter"),i.setAttribute("aria-valuemin","0"),i.setAttribute("aria-valuemax",String(r.max)),i.setAttribute("aria-valuenow",String(r.value)),i.setAttribute("aria-labelledby",o.id);let l=document.createElement("span");l.className="qv-status-meter-fill",l.style.width=`${r.value/r.max*100}%`,i.append(l),n.append(i)}return n}function xt(){let t=f("status");if(t){let e=document.createElement("ul");e.className="qv-status-list",e.append(...B.map(n=>ye(n,"li"))),t.body.replaceChildren(e),t.toggleAttribute("data-qv-empty",B.length===0)}rt()}function rt(){let t=a(),e=t?.statusBar;if(!t||!e)return;let n=f("status"),r=!!n&&!n.hidden&&!t.panes?.hidden?B.filter(i=>i.pinned):[];e.replaceChildren(...r.map(i=>ye(i,"span"))),e.classList.toggle("qv-status-bar-active",r.length>0),t.updateTopbar()}var st=document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"",Tt=null,N=null,it=null,j=[],at=0,Mt=!0,$=!1,Ct="header",W=(t,e)=>WebPlayer.chromeStrings?.[t]??e,qn={gridSquareClicked:(t,e)=>{E("JS_GridSquareClick",`${t};${e}`)},animate:()=>s.animateScroll&&!matchMedia("(prefers-reduced-motion: reduce)").matches,strings:()=>({map:W("MapLabel","Map"),zoomIn:W("MapZoomIn","Zoom in"),zoomOut:W("MapZoomOut","Zoom out")})};function xn(){return window.QuestUIV2Map?Promise.resolve():(Tt??=new Promise((t,e)=>{let n=new URL(st?"map.js":"v2/map.js",st||document.baseURI);st&&(n.search=new URL(st).search);let o=document.createElement("script");o.src=n.href,o.onload=()=>t(),o.onerror=()=>{Tt=null,e(new Error(`Failed to load ${n.href}`))},document.head.append(o)}),Tt)}function Ee(){return a()?.map?.querySelector(".qv-map-view")??null}function Tn(){let t=Ee();if(!t||!window.QuestUIV2Map)return;(!N||it!==t)&&(N=window.QuestUIV2Map.create(t,qn),it=t);let e=j;j=[];for(let[n,o]of e)try{N.call(n,o)}catch(r){console.error(r)}}function At(t,e){if(a()?.map){if(t==="show"){let n=typeof e[0]=="number"?e[0]:parseFloat(String(e[0]));at=Number.isFinite(n)?n:0,w()}if(N&&it===Ee()&&j.length===0){N.call(t,e);return}j.push([t,e]),xn().then(Tn,n=>console.error(n))}}function Le(t){Mt=t,w()}function we(t){t!=="header"&&t!=="panes"||(Ct=t,w())}function w(){let t=a(),e=t?.map;if(!t||!e)return;e.hidden=!(at>0&&Mt),e.style.setProperty("--qv-map-height",`${at}px`),e.classList.toggle("qv-map-collapsed",$);let n=Mn(e),o=t.mapButton;if(o){o.hidden=e.hidden||n||!t.hasAttribute("data-qv-narrow");let r=o.querySelector(".qv-button-label");r&&(r.textContent=W("MapLabel","Map")),o.setAttribute("aria-expanded",String(!$))}t.updateTopbar()}function Mn(t){let e=a();if(!e)return!1;let n=Ct==="panes"&&e.layout!=="none"&&!!e.panes&&!e.panes.hidden,o=f("map");if(n&&!o&&e.panes&&(o=document.createElement("qv-pane"),o.dataset.qvPane="map",o.setAttribute("label",W("MapLabel","Map")),e.panes.prepend(o)),n&&o)t.parentElement!==o.body&&o.body.append(t),o.hidden=t.hidden;else{let r=e.querySelector(".qv-header");r&&t.parentElement!==r&&r.append(t),o&&(o.hidden=!0)}return n}function qe(){$=!$,w()}function xe(){N=null,it=null,j=[],at=0,Mt=!0,$=!1,Ct="header"}var Pt="questviva-colour-scheme",Cn=["system","light","dark"],z=An(),Me=typeof matchMedia=="function"?matchMedia("(prefers-color-scheme: dark)"):null;function An(){try{let t=window.electronPlayerSettings?window.electronPlayerSettings.getColourScheme():localStorage.getItem(Pt);if(t&&Cn.includes(t))return t}catch{}return"system"}function Pn(t){try{window.electronPlayerSettings?window.electronPlayerSettings.setColourScheme(t).catch(()=>{}):t==="system"?localStorage.removeItem(Pt):localStorage.setItem(Pt,t)}catch{}}function kn(t){return!t.style.getPropertyValue("--qv-bg")}function Hn(t){let e=document.createElement("span");e.style.color=t.style.getPropertyValue("--qv-bg"),e.hidden=!0,t.append(e);let n=/rgba?\(([\d.]+),\s*([\d.]+),\s*([\d.]+)/.exec(getComputedStyle(e).color);if(e.remove(),!n)return!1;let[o,r,i]=n.slice(1,4).map(l=>{let c=Number(l)/255;return c<=.03928?c/12.92:((c+.055)/1.055)**2.4});return .2126*o+.7152*r+.0722*i<.18}function G(t){let e=kn(t),n=e?z==="dark"||z==="system"&&!!Me?.matches:Hn(t);t.setAttribute("data-qv-scheme",n?"dark":"light"),t.toggleAttribute("data-qv-fixed-scheme",!e),document.documentElement.setAttribute("data-qv-scheme",n?"dark":"light");let o=t.querySelector(".qv-scheme");if(o){o.hidden===e&&(o.hidden=!e,e||A(t,!1));for(let r of o.querySelectorAll("[data-qv-scheme-icon]"))r.hidden=r.dataset.qvSchemeIcon!==z;for(let r of o.querySelectorAll("[data-qv-scheme-choice]"))r.setAttribute("aria-checked",String(r.dataset.qvSchemeChoice===z))}}function In(t,e){z=e,Pn(e),G(t)}function It(t){return t.querySelector(".qv-scheme-menu")}function kt(t){return[...t.querySelectorAll("[data-qv-scheme-choice]")]}function Te(t){let e=It(t),n=t.querySelector(".qv-scheme-button");if(!e||!n)return;e.hidden=!1,n.setAttribute("aria-expanded","true"),(kt(e).find(r=>r.getAttribute("aria-checked")==="true")??kt(e)[0])?.focus()}function A(t,e){let n=It(t),o=t.querySelector(".qv-scheme-button");!n||n.hidden||(n.hidden=!0,o?.setAttribute("aria-expanded","false"),e&&o?.focus())}var Ht=null;Me?.addEventListener("change",()=>{Ht?.isConnected&&G(Ht)});function Ce(t){Ht=t,G(t);let e=t.querySelector(".qv-scheme-button"),n=It(t);!e||!n||(e.addEventListener("click",()=>{n.hidden?Te(t):A(t,!0)}),e.addEventListener("keydown",o=>{(o.key==="ArrowDown"||o.key==="ArrowUp")&&(o.preventDefault(),Te(t))}),n.addEventListener("click",o=>{let r=o.target instanceof Element?o.target.closest("[data-qv-scheme-choice]"):null;r&&(In(t,r.dataset.qvSchemeChoice),A(t,!0))}),n.addEventListener("keydown",o=>{let r=kt(n),i=r.indexOf(document.activeElement),l=-1;if(o.key==="ArrowDown")l=(i+1)%r.length;else if(o.key==="ArrowUp")l=(i-1+r.length)%r.length;else if(o.key==="Home")l=0;else if(o.key==="End")l=r.length-1;else if(o.key==="Escape"){o.preventDefault(),o.stopPropagation(),A(t,!0);return}else if(o.key==="Tab"){A(t,!1);return}l>=0&&(o.preventDefault(),r[l]?.focus())}),document.addEventListener("pointerdown",o=>{!n.hidden&&o.target instanceof Node&&!n.contains(o.target)&&!e.contains(o.target)&&A(t,!1)}),n.addEventListener("focusout",o=>{o.relatedTarget instanceof Node&&!n.contains(o.relatedTarget)&&o.relatedTarget!==e&&A(t,!1)}))}var Ae=["sidepanes","nopanes","bottombar"],Bn=900,Nn=new Set(["--qv-font-size","--qv-output-width","--qv-padding-top","--qv-padding-bottom","--qv-padding-left","--qv-padding-right","--qv-menu-font-size","--qv-radius","--qv-space"]),lt=class extends HTMLElement{#e=!1;#t="sidepanes";#n="sidepanes";connectedCallback(){if(this.#e)return;this.#e=!0,this.addEventListener("click",n=>ne(n,this.verbMenu)),this.addEventListener("keydown",oe);for(let n of this.querySelectorAll(".qv-panes-button"))n.addEventListener("click",()=>L(!nt()));this.mapButton?.addEventListener("click",qe),Ce(this),new ResizeObserver(()=>this.#r()).observe(this),this.panes?.addEventListener("keydown",n=>{n.key==="Escape"&&nt()&&!this.verbMenu?.isOpen&&(n.preventDefault(),L(!1))});let e=this.querySelector(".qv-toolbar");e&&(new MutationObserver(()=>{ke(e),this.updateTopbar()}).observe(e,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["style","hidden"]}),ke(e)),this.addEventListener("pointerover",n=>{let o=n.target instanceof Element?n.target.closest("button"):null;if(!o?.querySelector(":scope > .qv-icon"))return;let r=o.querySelector(".qv-button-label")?.textContent?.trim()||o.getAttribute("aria-label");r&&(o.title=r)}),this.#r(),this.#s()}get topbar(){return this.querySelector(".qv-topbar")}get saveButton(){return this.querySelector("#cmdSave")}get panes(){return this.querySelector('[data-qv-part="panes"]')}get exits(){return this.querySelector('[data-qv-part="exits"]')}get statusBar(){return this.querySelector('[data-qv-part="status-bar"]')}get panesButton(){return this.querySelector(this.layout==="sheet"?".qv-footer .qv-panes-button":".qv-topbar .qv-panes-button")}get layout(){return this.dataset.qvLayout??"side"}setLayoutPreset(e,n){if(e==="gamebook"){this.toggleAttribute("data-qv-gamebook",!0),this.#t=this.#n="nopanes",this.setVisible("command-bar",!1),this.setVisible("location",!1),this.#r();return}Ae.includes(e)&&(this.removeAttribute("data-qv-gamebook"),this.#t=e,this.#n=n!=null&&Ae.includes(n)?n:e,this.#r())}#r(){let e=this.clientWidth<Bn;e!==this.hasAttribute("data-qv-narrow")&&(this.toggleAttribute("data-qv-narrow",e),w());let n=e?this.#n:this.#t,o=n==="nopanes"?"none":n==="bottombar"?"sheet":e?"drawer":"side";this.dataset.qvLayout!==o&&(L(!1,{restoreFocus:!1}),this.toggleAttribute("data-qv-layout-changing",!0),this.dataset.qvLayout=o,w(),requestAnimationFrame(()=>requestAnimationFrame(()=>this.removeAttribute("data-qv-layout-changing"))),h(),rt(),this.updateTopbar())}updateTopbar(){let e=this.topbar;if(!e)return;let n=this.location,o=[...e.querySelectorAll(".qv-toolbar > button, .qv-toolbar > .qv-scheme:not([hidden]) > button")].some(l=>!l.hidden&&l.style.display!=="none"&&getComputedStyle(l).display!=="none"),r=this.statusBar,i=!!r&&!r.hidden&&r.classList.contains("qv-status-bar-active")&&getComputedStyle(r).display!=="none";e.hidden=(!n||n.hidden)&&!o&&!i}focusFirstChoice(){if(!this.hasAttribute("data-qv-gamebook"))return;let e=document.activeElement;if(e&&e!==document.body&&this.contains(e)&&!e.closest(".qv-hiding")&&!e.classList.contains("disabled"))return;[...this.querySelectorAll('[data-qv-part="output"] [data-qv-sections] a.commandlink:not(.disabled)')].find(o=>!o.closest(".qv-hiding"))?.focus({preventScroll:!0})}get verbMenu(){return this.querySelector("qv-verb-menu")}updateLinks(e,n){te(this,e,n),this.verbMenu?.closeIfStale()}get output(){return this.querySelector("qv-output")}get commandBar(){return this.querySelector("qv-command-bar")}get location(){return this.querySelector('[data-qv-part="location"]')}get pictureFrame(){return this.querySelector('[data-qv-part="picture-frame"]')}get map(){return this.querySelector('[data-qv-part="map"]')}get mapButton(){return this.querySelector(".qv-map-button")}get frame(){return this.querySelector('[data-qv-part="border"]')}setVisible(e,n){switch(e){case"output":this.#o(this.output,!n);break;case"command-bar":this.#o(this.commandBar,!n);break;case"location":this.#o(this.location,!n),this.updateTopbar();break;case"border":this.frame?.classList.toggle("qv-borderless",!n);break;case"picture-frame":this.#o(this.pictureFrame,!n);break;case"exits":this.#o(this.exits,!n);break;case"map":Le(n);break;case"status-bar":this.#o(this.statusBar,!n);break;case"panes":this.#o(this.panes,!n),n||L(!1,{restoreFocus:!1}),w(),this.#s();break;default:(Et.includes(e)||f(e))&&(this.#o(f(e),!n),this.#s())}h(),rt()}#s(){let e=this.panes;if(!e)return;let n=[...e.querySelectorAll("qv-pane")].some(o=>!o.hidden&&!o.hasAttribute("data-qv-empty"));for(let o of this.querySelectorAll(".qv-panes-button"))o.hidden=e.hidden||!n;this.updateTopbar()}#o(e,n){e&&(e.hidden=n)}setTokens(e){for(let[n,o]of Object.entries(e)){if(!n.startsWith("--"))continue;let r=o==null?"":String(o).trim();if(r===""){this.style.removeProperty(n);continue}Nn.has(n)&&/^-?(\d+\.?\d*|\.\d+)$/.test(r)&&(r+="px"),this.style.setProperty(n,r)}this.toggleAttribute("data-qv-own-accent",!!this.style.getPropertyValue("--qv-accent")),this.toggleAttribute("data-qv-own-background",["--qv-bg","--qv-bg-light","--qv-bg-dark"].some(n=>!!this.style.getPropertyValue(n))),this.toggleAttribute("data-qv-own-border",["--qv-border-colour","--qv-border-colour-light","--qv-border-colour-dark"].some(n=>!!this.style.getPropertyValue(n))),G(this),this.updateTopbar()}setLocation(e){let n=this.location;n&&(n.innerHTML=e,n.classList.toggle("qv-empty",e.trim()===""))}},Pe="http://www.w3.org/2000/svg";function ke(t){let e=t.querySelector("#cmdRestart");if(!e||e.querySelector(".qv-icon"))return;let n=document.createElement("span");n.className="qv-button-label",n.textContent=e.textContent;let o=document.createElementNS(Pe,"svg");o.setAttribute("class","qv-icon"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("aria-hidden","true");for(let r of["M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8","M3 3v5h5"]){let i=document.createElementNS(Pe,"path");i.setAttribute("d",r),o.append(i)}e.replaceChildren(o,n)}function a(){return document.querySelector("qv-player")}var ct=0,Bt=0,K,He=!1;function Ie(t){Bt=t,Dn()}function Nt(){return D(),ct}function Be(){He=!0,D()}function D(){K!==void 0&&(clearInterval(K),K=void 0)}function Dn(){He||K!==void 0||(ct=0,K=setInterval(async()=>{ct++,Bt>0&&ct>=Bt&&await WebPlayer.uiTick(Nt())},1e3))}function Q(){return window.canSendCommand&&!s.gameFinished&&!s.soundWait&&!s.waiting&&!s.pausing&&!s.inDialog}function g(t,e){if(!Q())return!1;window.canSendCommand=!1,a()?.output?.markScrollPosition(),s.hasUnsavedProgress=!0;let n=Nt();return setTimeout(()=>{WebPlayer.sendCommand(t,n,e??null)},0),!0}function E(t,e){s.hasUnsavedProgress=!0;let n=""+e;return setTimeout(()=>{WebPlayer.uiSendEvent(t,n)},1),!0}var ut=new Set;function U(t,e){e?ut.add(t):ut.delete(t),a()?.toggleAttribute("data-qv-input-held",ut.size>0)}function De(){ut.clear(),clearTimeout(Dt)}function Ue(){s.waiting=!0,h(),a()?.commandBar?.setMode("continue"),a()?.output?.markScrollPosition()}function Y(){s.waiting&&(s.waiting=!1,a()?.commandBar?.setMode("none"),s.hasUnsavedProgress=!0,sendEndWait())}function Oe(){h(),!s.waiting&&Ot()}var Dt;function Re(t){s.pausing=!0,h(),U("pause",!0),clearTimeout(Dt),Dt=setTimeout(On,t)}function On(){s.pausing&&(s.pausing=!1,sendEndPause())}function Fe(){h(),!s.pausing&&(U("pause",!1),Ot())}function Ot(){let t=a()?.commandBar;!t||s.gameFinished||s.waiting||s.inDialog||(t.setMode("input"),t.focusInput())}var Ut={cancel:"Cancel",yes:"Yes",no:"No"},Ne=0;function Qe(t,e,n){let o=a();if(!o)return;let r=++Ne;o.querySelector("dialog.qv-dialog")?.remove();let i=document.createElement("dialog");i.className="qv-dialog",i.dataset.qvPart="menu";let l="qv-dialog-caption";i.setAttribute("aria-labelledby",l);let c=document.createElement("div");c.id=l,c.className="qv-dialog-caption",c.innerHTML=t;let u=document.createElement("div");u.className="qv-dialog-choices";let p=!1,x=m=>{p||(p=!0,i.close(),i.remove(),s.hasUnsavedProgress=!0,setTimeout(async()=>{try{await m()}finally{Ne===r&&(s.inDialog=!1,h(),Ot())}},100))};for(let m of e){let T=document.createElement("button");T.type="button",T.textContent=m.label,T.addEventListener("click",()=>x(m.choose)),u.append(T)}if(i.append(c,u),n){let m=document.createElement("button");m.type="button",m.className="qv-dialog-cancel",m.textContent=Ut.cancel,m.addEventListener("click",()=>x(n)),i.append(m)}i.addEventListener("cancel",m=>{m.preventDefault(),n&&x(n)}),i.addEventListener("close",()=>{!p&&i.isConnected&&i.showModal()}),s.inDialog=!0,h(),o.commandBar?.setMode("none"),o.append(i),i.showModal(),u.querySelector("button")?.focus()}function Ve(t,e,n){let o=Object.entries(e).map(([r,i])=>({label:i,choose:()=>WebPlayer.uiChoice(r)}));Qe(t,o,n?()=>WebPlayer.uiChoiceCancel():null)}function We(t){Qe(t,[{label:Ut.yes,choose:()=>WebPlayer.uiSetQuestionResponse(!0)},{label:Ut.no,choose:()=>WebPlayer.uiSetQuestionResponse(!1)}],null)}var $e=typeof matchMedia=="function"&&matchMedia("(pointer: coarse)").matches;document.addEventListener("pointerdown",t=>{$e=t.pointerType!=="mouse"&&!(t.target instanceof Element&&t.target.closest(".qv-command-input"))},!0);var dt=class extends HTMLElement{#e;#t;#n;#r;#s="input";#o=[];#i=0;#a="";connectedCallback(){if(this.#t)return;let e=this.#e=document.createElement("form");e.className="qv-command-form",this.#n=document.createElement("span"),this.#n.className="qv-command-prompt",this.#n.setAttribute("aria-hidden","true"),this.#t=document.createElement("input"),this.#t.type="text",this.#t.className="qv-command-input",this.#t.autocomplete="off",this.#t.spellcheck=!1,this.#t.setAttribute("autocapitalize","off"),this.#t.setAttribute("enterkeyhint","send"),this.#t.dataset.chromeKeyAriaLabel="CommandInputLabel",this.#t.setAttribute("aria-label","Type your command"),e.append(this.#n,this.#t),this.#r=document.createElement("button"),this.#r.type="button",this.#r.className="qv-continue",this.#r.hidden=!0,this.#r.addEventListener("click",Y),this.append(e,this.#r),e.addEventListener("submit",n=>{n.preventDefault(),this.#l()}),this.#t.addEventListener("keydown",n=>this.#c(n)),this.updatePlaceholder(),this.updateContinueLabel()}setMode(e){this.#s=e,this.#e.hidden=e!=="input",this.#r.hidden=e!=="continue",e==="continue"&&this.#r.focus({preventScroll:!0})}get input(){return this.#t}focusInput(){if(this.hidden)return;let e=this.#s==="input"?this.#t:this.#s==="continue"?this.#r:null;e===this.#t&&$e||e&&document.activeElement!==e&&e.focus({preventScroll:!0})}setPrompt(e){this.#n.innerHTML=e}setStyle(e){this.#t.style.cssText=e}setPreset(e){(e==="borderless"||e==="shadow")&&(this.dataset.qvPreset=e)}updateContinueLabel(){this.#r.textContent=je(s.interfaceStrings.get("ContinueLabel")??"")||"Continue"}updatePlaceholder(){this.#t.placeholder=s.commandPlaceholder??je(s.interfaceStrings.get("TypeHereLabel")??"")}#l(){let e=this.#t.value;e.length===0||!Q()||g(e)&&(this.#o.at(-1)!==e&&this.#o.push(e),this.#i=this.#o.length,this.#a="",this.#t.value="")}#c(e){if(e.key!=="ArrowUp"&&e.key!=="ArrowDown"||e.altKey||e.ctrlKey||e.metaKey||e.shiftKey)return;let n=this.#i+(e.key==="ArrowUp"?-1:1);if(n<0||n>this.#o.length)return;e.preventDefault(),this.#i===this.#o.length&&(this.#a=this.#t.value),this.#i=n,this.#t.value=n===this.#o.length?this.#a:this.#o[n];let o=this.#t.value.length;this.#t.setSelectionRange(o,o)}};function je(t){let e=document.createElement("template");return e.innerHTML=t,e.content.textContent??""}var Rt=new Set;function mt(t,e){let n=typeof t=="number"?t:parseFloat(String(t));return Number.isFinite(n)?n:e}function Fn(t){let e=document.createElement("template");return e.innerHTML=String(t??""),e.content.textContent??""}function ze(){let t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";return t[Math.floor(Math.random()*t.length)]}function Qn(t){for(let e=t.length-1;e>0;e--){let n=Math.floor(Math.random()*(e+1));[t[e],t[n]]=[t[n],t[e]]}}function Ge(t,e){if(t!=="typewriter"&&t!=="unscramble")return;let n=a()?.output;if(!n)return;let o=Fn(e[0]),r=Math.max(0,mt(e[1],100)),i=t==="unscramble"?Math.max(1,Math.floor(mt(e[2],1))):0,[l,c,u]=(t==="unscramble"?e.slice(3,6):e.slice(2,5)).map(v=>v==null?"":String(v).trim()),p=document.createElement("span");p.className="qv-text-effect",p.dataset.qvEffect=t,l&&p.style.setProperty("font-family",l),c&&p.style.setProperty("color",c),u&&mt(u,0)>0&&p.style.setProperty("font-size",`${mt(u,0)}pt`);let x=document.createElement("span");x.className="qv-text-effect-full",x.textContent=o;let m=document.createElement("span");m.className="qv-text-effect-shown",m.setAttribute("aria-hidden","true"),p.append(x,m);let T=document.createElement("span");if(T.textContent=o,n.addNodes([p,document.createElement("br")],`${T.innerHTML}<br/>`),!(s.animateScroll&&!matchMedia("(prefers-reduced-motion: reduce)").matches)||o===""){Ft(p);return}p.classList.add("qv-text-effect-running");let gt;if(t==="typewriter"){let v=0;gt=()=>(v++,m.textContent=o.substring(0,v)+(v%2===1&&v<o.length?"_":""),v>=o.length)}else{let v=[...o],R=v.flatMap((y,X)=>/\s/.test(y)?[]:[X]);Qn(R);let Z=v.map(y=>/\s/.test(y)?y:ze());m.textContent=Z.join(""),gt=()=>{for(let y=0;y<i&&R.length;y++){let X=R.pop();Z[X]=v[X]}for(let y of R)Z[y]=ze();return m.textContent=Z.join(""),R.length===0}}let O={timer:0,finish:()=>{clearInterval(O.timer),Rt.delete(O),Ft(p)}};O.timer=window.setInterval(()=>{(!p.isConnected||gt())&&O.finish()},r),Rt.add(O)}function Ft(t){let e=t.querySelector(".qv-text-effect-shown");e&&(e.textContent=t.querySelector(".qv-text-effect-full")?.textContent??""),t.classList.remove("qv-text-effect-running")}function pt(){for(let t of[...Rt])t.finish()}function Ke(t){for(let e of t.querySelectorAll(".qv-text-effect"))Ft(e)}document.addEventListener("keydown",()=>pt(),!0);document.addEventListener("pointerdown",()=>pt(),!0);var _e=(t,e)=>WebPlayer.chromeStrings?.[t]??e;function Ye(t){return t.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}function Je(t,e,n,o=""){let r=a()?.output;r&&r.addText(`<iframe class="qv-video" data-qv-video="${t}" src="${Ye(e.href)}" title="${Ye(n)}" allow="autoplay; fullscreen; picture-in-picture; encrypted-media" allowfullscreen${o}></iframe>`)}function Ze(t){let e=new URL(`https://www.youtube-nocookie.com/embed/${encodeURIComponent(t.trim())}`);e.searchParams.set("autoplay","1"),e.searchParams.set("rel","0"),Je("youtube",e,_e("YouTubeVideoTitle","YouTube video"))}function Xe(t){let[e,n]=t.trim().split("/"),o=new URL(`https://player.vimeo.com/video/${encodeURIComponent(e)}`);n&&o.searchParams.set("h",n),o.searchParams.set("autoplay","1"),o.searchParams.set("dnt","1"),Je("vimeo",o,_e("VimeoVideoTitle","Vimeo video"),' sandbox="allow-same-origin allow-scripts allow-popups allow-presentation"')}function tn(t){for(let e of t.querySelectorAll("iframe[data-qv-video]")){let n;try{n=new URL(e.getAttribute("src")??"")}catch{continue}n.searchParams.has("autoplay")&&(n.searchParams.delete("autoplay"),e.setAttribute("src",n.href))}}function ft(t){let e=a()?.pictureFrame;if(e){e.innerHTML=t,e.classList.toggle("qv-empty",t.trim()==="");for(let n of e.querySelectorAll("img"))n.hasAttribute("alt")||(n.alt=""),n.complete||(n.addEventListener("load",Qt,{once:!0}),n.addEventListener("error",Qt,{once:!0}));Qt()}}function en(){let t=a()?.pictureFrame;return!t||t.hidden||t.classList.contains("qv-empty")?!1:[...t.querySelectorAll("img")].some(e=>!e.complete)}function Qt(){a()?.output?.rescroll(!0)}var rn=new Map;function sn(t,e,n){rn.set(t,{width:e,height:n})}var Vn=8;function Wn(t){s.warnedAboutScript||!/<script[\s>\/]/i.test(t)||(s.warnedAboutScript=!0,console.warn(`[Quest] This game printed a <script> element, which doesn't run in the new player interface. Call your own JavaScript with JS.yourFunction () or JS.eval instead, or tick "Use the classic interface" on the game's Interface tab.`))}var ht=class extends HTMLElement{#e=null;#t=[];#n=0;#r=0;#s=!0;#o=0;connectedCallback(){this.setAttribute("role","log"),this.setAttribute("aria-live","polite"),this.addEventListener("load",this.#i,!0),this.addEventListener("error",this.#i,!0)}disconnectedCallback(){this.removeEventListener("load",this.#i,!0),this.removeEventListener("error",this.#i,!0)}#i=e=>{e.target instanceof HTMLImageElement&&this.rescroll()};addText(e){Wn(e);let n=this.#e??this.setAlignment("left");n.insertAdjacentHTML("beforeend",e),jn(n),$n(n),H(n),this.#s=!0,WebPlayer.transcript?.write(e),b("outputAdded",{html:e})}addNodes(e,n){(this.#e??this.setAlignment("left")).append(...e),this.#s=!0,WebPlayer.transcript?.write(n),b("outputAdded",{html:n})}setAlignment(e){this.#e&&!this.#e.hasChildNodes()&&this.#e.remove();let n=document.createElement("div");return n.className="qv-block",n.style.textAlign=e,this.#t.length&&(n.dataset.qvSections=this.#t.join(" ")),this.append(n),this.#e=n,n}clearScreen(){this.replaceChildren(),this.#e=null,this.setAlignment("left"),this.#n=0,this.#s=!0;let e=this.#u();window.scrollY>e&&window.scrollTo({top:e,behavior:"instant"})}loadHtml(e){let n=document.createElement("template");n.innerHTML=e,tn(n.content),Ke(n.content),this.replaceChildren(n.content),this.#s=!0,H(this),Xt(this),requestAnimationFrame(()=>{let o=document.scrollingElement??document.documentElement;window.scrollTo({top:o.scrollHeight,behavior:"instant"})}),this.#e=null,this.#t=[]}getHtml(){return this.innerHTML}reset(){this.replaceChildren(),this.#e=null,this.#t=[],this.#n=0,this.#r=0,this.#s=!0,this.#o=0}startSection(e){this.#t.includes(e)||(this.#t.push(e),this.setAlignment("left"))}endSection(e){let n=this.#t.indexOf(e);n!==-1&&(this.#t.splice(n,1),this.setAlignment("left"))}hideSection(e){this.endSection(e);let n=this.getBoundingClientRect().top;for(let o of this.#a(e)){let r=o.getBoundingClientRect();r.bottom-n<=this.#n+1&&(this.#n=Math.max(0,this.#n-r.height)),o.classList.add("qv-hiding"),on(o),setTimeout(()=>o.remove(),250)}}disableSection(e){for(let n of this.#a(e))on(n)}disableCommandLinks(){for(let e of this.querySelectorAll("a.commandlink"))yt(e);a()?.verbMenu?.closeIfStale()}#a(e){return[...this.querySelectorAll("[data-qv-sections]")].filter(n=>n.dataset.qvSections.split(" ").includes(e))}beginTurn(){if(s.fadePreviousOutput)for(let e of this.children)e.classList.add("qv-previous-output")}clearPreviousOutputFade(){for(let e of this.querySelectorAll(".qv-previous-output"))e.classList.remove("qv-previous-output")}markScrollPosition(){this.#n=this.#l()}#l(){let e=this.lastElementChild;return e?e.getBoundingClientRect().bottom-this.getBoundingClientRect().top:0}scrollToEnd(){let e=this.#l();!this.#s&&e<=this.#o+1||(this.#s=!1,this.#o=e,this.#c(this.#n))}rescroll(e=!1){this.#c(this.#r,e)}#c(e,n=!1){if(!s.autoScroll||(this.#r=e,en()))return;let r=(document.scrollingElement??document.documentElement).scrollHeight-window.innerHeight,i=s.animateScroll?Math.min(this.#u()+e-nn()-Vn,r):r,l=this.#u()+e-window.scrollY,c=n&&l>=0&&l<nn();if(i<=window.scrollY&&!c)return;let u=s.animateScroll&&!matchMedia("(prefers-reduced-motion: reduce)").matches;window.scrollTo({top:i,behavior:u?"smooth":"instant"})}#u(){return this.getBoundingClientRect().top+window.scrollY}};function nn(){return document.querySelector("qv-player .qv-header")?.offsetHeight??0}function on(t){for(let e of t.querySelectorAll("a.cmdlink, a[data-qv-event]"))M(e,!1);a()?.verbMenu?.closeIfStale()}function jn(t){for(let e of t.querySelectorAll("img:not([alt])"))e.setAttribute("alt","")}function $n(t){for(let e of t.querySelectorAll("img:not([width]):not([height]):not([style])")){let n=rn.get(e.getAttribute("src")??"");n&&(e.setAttribute("width",String(n.width)),e.setAttribute("height",String(n.height)),e.classList.add("qv-sized"))}}var q=()=>WebPlayer.transcript;function an(t){let e=a()?.output;e?.addText(t),e?.scrollToEnd()}var ln={write:t=>q()?.write(String(t??"")),enable:t=>q()?.enable(t==null?void 0:String(t)),disable:()=>q()?.disable(),kill:()=>q()?.kill(),revive:()=>q()?.revive(),setName:t=>q()?.setName(String(t??"")),setPrefix:()=>{},stampDateAndTime:()=>an(`<b>DATE AND TIME:</b> ${new Date().toLocaleString(navigator.language,{timeZoneName:"short"})}`),promptForName:()=>{let t=a()?.commandBar?.input;t&&(t.value=q()?.name||document.title,t.focus({preventScroll:!0}))},show:(t,e)=>{let n=document.createElement("a");n.href=q()?.viewerUrl??"TranscriptViewer/index.html",n.target="_blank",n.textContent=e==null||e===""?"Your Transcripts":String(e);let o=t==null||t===""?"Your transcripts are saved to the localStorage in your browser. You can view, download, or delete them here:":String(t);an(`${o} ${n.outerHTML}<br/>`)}};var d=t=>(...e)=>At(t,e),zn={show:d("show"),respondToClicks:d("respondToClicks"),setInteractive:d("setInteractive"),setScale:d("setScale"),setCentre:d("setCentre"),drawBox:d("drawBox"),drawLabel:d("drawLabel"),drawPlayer:d("drawPlayer"),drawLine:d("drawLine"),drawArrow:d("drawArrow"),drawSquare:d("drawSquare"),drawShape:d("drawShape"),addShapePoint:d("addShapePoint"),drawImage:d("drawImage"),drawSvg:d("drawSvg"),loadSvg:d("loadSvg"),drawGridLines:d("drawGridLines"),showCustomLayer:d("showCustomLayer"),clearCustomLayer:d("clearCustomLayer"),clearAllLayers:d("clearAllLayers")};function _(t){return typeof t=="string"?JSON.parse(t):t}function Vt(t){let e=t??"";a()?.setLocation(e),b("locationChanged",{location:e})}function Wt(t,e){s.interfaceStrings.set(t,e),t==="EmptyListLabel"&&(s.interfaceStrings.delete("InventoryEmptyLabel"),s.interfaceStrings.delete("PlacesObjectsEmptyLabel")),de(t,e),(t==="InButtonLabel"||t==="OutButtonLabel"||t==="CompassLabel")&&I(),t==="TypeHereLabel"&&a()?.commandBar?.updatePlaceholder(),t==="ContinueLabel"&&a()?.commandBar?.updateContinueLabel()}function jt(t){s.compassDirections=Array.isArray(t)?t.map(String):String(t??"").split(";"),I()}var cn={sendCommand:g,sendEvent:E,restart:()=>window.RestartGame?.(),addText:t=>a()?.output?.addText(String(t)),clearScreen:()=>a()?.output?.clearScreen(),setAlignment:t=>{a()?.output?.setAlignment(String(t))},startSection:t=>a()?.output?.startSection(String(t)),endSection:t=>a()?.output?.endSection(String(t)),hideSection:t=>a()?.output?.hideSection(String(t)),disableSection:t=>a()?.output?.disableSection(String(t)),disableCommandLinks:()=>a()?.output?.disableCommandLinks(),updateLinks:(t,e)=>a()?.updateLinks(String(t),_(e)),scrollToEnd:()=>a()?.output?.scrollToEnd(),addYouTube:t=>Ze(String(t??"")),addVimeo:t=>Xe(String(t??"")),textEffect:(t,...e)=>Ge(String(t),e),setVisible:(t,e)=>a()?.setVisible(String(t),!!e),setPaneOrder:t=>ue(_(t)),setLayoutPreset:(t,e)=>a()?.setLayoutPreset(String(t),e==null?void 0:String(e)),setMapPosition:t=>we(String(t??"")),setPictureFrame:t=>ft(String(t??"")),setInterfaceString:Wt,setCompassDirections:t=>jt(_(t)),setLocation:Vt,setStatusAttributes:t=>qt(_(t)),setTokens:t=>a()?.setTokens(_(t)??{}),setCommandBarStyle:t=>a()?.commandBar?.setStyle(String(t??"")),setCommandBarPreset:t=>a()?.commandBar?.setPreset(String(t??"")),setCommandPrompt:t=>a()?.commandBar?.setPrompt(String(t??"")),addStylesheet:t=>addExternalStylesheet(String(t)),map:zn,transcript:ln,addPane:(t,e,n)=>ce(String(t),e==null?void 0:String(e),n==null?void 0:String(n)),setPaneContent:(t,e)=>le(String(t),String(e??"")),setCommands:t=>ae(t),setAutoScroll:t=>{s.autoScroll=!!t},setContinueOnClick:t=>{s.continueOnClick=!!t},fadePreviousOutput:t=>{s.fadePreviousOutput=!!t,s.fadePreviousOutput||a()?.output?.clearPreviousOutputFade()},setCommandPlaceholder:t=>{s.commandPlaceholder=t==null?null:String(t),a()?.commandBar?.updatePlaceholder()},setMapInteractive:t=>At("setInteractive",[t]),lists:Yt,on:zt,off:Gt};function un(t){return(t.dataset.qvName??t.textContent??"").trim()}var $t=4,J=8,vt=class extends HTMLElement{#e=null;connectedCallback(){this.setAttribute("role","menu"),C&&(this.popover="manual"),this.addEventListener("click",this.#n),this.addEventListener("keydown",this.#r)}get isOpen(){return this.#e!==null}toggle(e){if(this.#e===e){this.close();return}let n=(e.dataset.verbs??"").split("/").map(r=>r.trim()).filter(Boolean);if(!n.length)return;this.close({restoreFocus:!1});let o=un(e);this.setAttribute("aria-label",(e.textContent??"").trim()),this.replaceChildren(...n.map(r=>{let i=document.createElement("button");return i.type="button",i.setAttribute("role","menuitem"),i.textContent=r,i.dataset.command=`${r.toLowerCase()} ${o}`,i})),this.#e=e,e.setAttribute("aria-expanded","true"),this.classList.add("qv-open"),C&&this.showPopover(),this.#i(),this.querySelector("button")?.focus({preventScroll:!0}),document.addEventListener("pointerdown",this.#s,!0),window.addEventListener("scroll",this.#o,{passive:!0}),window.addEventListener("resize",this.#o)}close({restoreFocus:e=!0}={}){let n=this.#e;if(!n)return;this.#e=null,n.setAttribute("aria-expanded","false");let o=this.contains(document.activeElement);this.classList.remove("qv-open"),C&&this.matches(":popover-open")&&this.hidePopover(),this.replaceChildren(),document.removeEventListener("pointerdown",this.#s,!0),window.removeEventListener("scroll",this.#o),window.removeEventListener("resize",this.#o),e&&o&&n.isConnected&&n.focus({preventScroll:!0})}closeIfStale(){this.#e&&(!this.#e.isConnected||k(this.#e))&&this.close({restoreFocus:!1})}#t(e){let n=this.#e;if(!n)return;let o=un(n),r={};n.dataset.elementid&&(r[o]=n.dataset.elementid),this.close({restoreFocus:!1}),g(e.dataset.command??"",r)}#n=e=>{let n=e.target instanceof Element?e.target.closest('[role="menuitem"]'):null;n&&this.#t(n)};#r=e=>{let n=[...this.querySelectorAll('[role="menuitem"]')],o=n.indexOf(document.activeElement),r=null;switch(e.key){case"Escape":e.preventDefault(),this.close();return;case"Tab":this.close({restoreFocus:!1});return;case"ArrowDown":r=(o+1)%n.length;break;case"ArrowUp":r=(o-1+n.length)%n.length;break;case"Home":r=0;break;case"End":r=n.length-1;break;default:return}e.preventDefault(),n[r]?.focus()};#s=e=>{let n=e.target instanceof Node?e.target:null;n&&(this.contains(n)||this.#e?.contains(n))||this.close({restoreFocus:!1})};#o=()=>{this.closeIfStale(),this.#e&&this.#i()};#i(){if(!this.#e)return;let e=this.#e.getBoundingClientRect(),{offsetWidth:n,offsetHeight:o}=this,r=e.bottom+$t;r+o>window.innerHeight-J&&e.top-$t-o>=J&&(r=e.top-$t-o);let i=Math.max(J,Math.min(e.left,window.innerWidth-n-J));this.style.top=`${Math.max(J,r)}px`,this.style.left=`${i}px`}};customElements.define("qv-player",lt);customElements.define("qv-output",ht);customElements.define("qv-command-bar",dt);customElements.define("qv-verb-menu",vt);customElements.define("qv-pane",et);window.QuestUI=cn;window.sendCommand=(t,e)=>{g(t,e)};window.ASLEvent=E;window.canSendCommand=!0;window.notifyQuestUITurn=t=>{let e=a()?.output;t?(L(!1,{restoreFocus:!1}),e?.beginTurn(),e?.setAttribute("aria-busy","true"),b("turnStarted")):(e?.removeAttribute("aria-busy"),b("turnEnded"),a()?.commandBar?.focusInput(),a()?.focusFirstChoice())};window.resetQuestUIState=()=>{Kt(),D(),De(),ge(),Se(),_t(),xe(),pt()};document.addEventListener("keydown",t=>{!s.waiting||t.repeat||["Tab","Shift","Control","Alt","Meta"].includes(t.key)||t.target instanceof Element&&t.target.closest("input, textarea, select, [contenteditable], dialog")||(t.preventDefault(),Y())});window.addEventListener("beforeunload",t=>{!s.hasUnsavedProgress||!s.canSave||!a()||(t.preventDefault(),t.returnValue="")});document.addEventListener("click",t=>{!s.waiting||!s.continueOnClick||t.target instanceof Element&&t.target.closest("a, button, input, textarea, select, summary, dialog")||Y()});var S=()=>a()?.output;function dn(){let t=a()?.saveButton;t&&(t.disabled=s.turnPending)}var Gn=()=>{},mn={"#gamePanes":"panes","#location":"location","#txtCommandDiv":"command-bar"},Kn={addTextAndScroll(t){S()?.addText(t),S()?.scrollToEnd()},createNewDiv:t=>{S()?.setAlignment(t)},bindMenu:(t,e,n,o)=>ee(t,e,o),showMenu:Ve,showQuestion:We,beginWait:Ue,setTurnPending(t){s.turnPending=t,dn(),h()},beginPause:Re,updateLocation:Vt,setGameName(t){document.title=t},clearScreen:()=>S()?.clearScreen(),panesVisible:t=>a()?.setVisible("panes",t),updateStatus:be,setBackground:t=>a()?.setTokens({"--qv-bg":t}),setForeground:Gn,updateList:ie,updateCompass:ve,updateObjectLinks:t=>a()?.updateLinks("object",t),gameFinished(){s.gameFinished=!0,D(),s.waiting=!1,U("finished",!0),h()},requestNextTimerTick:Ie,uiShow:t=>a()?.setVisible(mn[t]??"",!0),uiHide:t=>a()?.setVisible(mn[t]??"",!1),setCompassDirections:jt,setInterfaceString:Wt,setPanelContents:ft,loadHtml:t=>S()?.loadHtml(t),markScrollPosition:()=>S()?.markScrollPosition(),scrollToEnd:()=>S()?.scrollToEnd(),requestSave(){GameSaver.saveRequested()},start(){a()?.saveButton?.addEventListener("click",()=>{WebPlayer.onSaveClick?WebPlayer.onSaveClick():GameSaver.save()}),dn(),I(),xt(),a()?.commandBar?.focusInput()},resetOutput(){S()?.reset(),D(),s.hasUnsavedProgress=!1},useManualClock:Be,getOutputHtml:()=>S()?.getHtml()??"",getLocation:()=>a()?.location?.textContent?.trim()??"",gameSaved(){S()?.addText(`<span data-qv-save-notice>${WebPlayer.chromeStrings?.GameSaved??"Game saved."}<br></span>`),s.hasUnsavedProgress=!1},clearUnsavedProgress(){s.hasUnsavedProgress=!1},setCanSave(t){s.canSave=t},waitEnded:Oe,pauseEnded:Fe,beginSoundWait(){let t=!a()?.commandBar?.hidden;return s.soundWait=!0,U("sound",!0),t},endSoundWait(){s.soundWait=!1,setTimeout(async()=>{U("sound",!1),await WebPlayer.uiEndWait()},100)},rememberImageSize:sn,setAnimateScroll(t){s.animateScroll=t}};window.QuestPlayerUis=window.QuestPlayerUis??{};window.QuestPlayerUis.v2=Kn;})();
1
+ "use strict";(()=>{var s={autoScroll:!0,warnedAboutScript:!1,animateScroll:!0,fadePreviousOutput:!1,continueOnClick:!1,commandPlaceholder:null,commands:[],commandsInExitStrip:!1,compassDirections:[],interfaceStrings:new Map,gameFinished:!1,soundWait:!1,waiting:!1,pausing:!1,inDialog:!1,turnPending:!0,hasUnsavedProgress:!1,canSave:!1},V=new Map;function te(e,t){if(typeof t!="function")return;let n=V.get(e);n||V.set(e,n=new Set),n.add(t)}function ee(e,t){V.get(e)?.delete(t)}function y(e,t){for(let n of V.get(e)??[])try{n(t)}catch(o){console.error(o)}}function ne(){s.autoScroll=!0,s.warnedAboutScript=!1,s.fadePreviousOutput=!1,s.continueOnClick=!1,s.commandPlaceholder=null,s.interfaceStrings.clear(),s.compassDirections=[],s.commands=[],s.commandsInExitStrip=!1,s.gameFinished=!1,s.soundWait=!1,s.waiting=!1,s.pausing=!1,s.inDialog=!1,s.turnPending=!0,s.hasUnsavedProgress=!1,V.clear()}var qn={inventory:"inventoryChanged",objects:"objectsChanged",exits:"exitsChanged",status:"statusChanged"},ot={inventory:[],objects:[],exits:[],status:[]},qt=new Set;function oe(){return structuredClone(ot)}function re(){ot={inventory:[],objects:[],exits:[],status:[]},qt.clear()}function P(e,t){if(qt.has(e)&&JSON.stringify(t)===JSON.stringify(ot[e]))return;qt.add(e),ot[e]=t;let n=structuredClone(t);y(qn[e],e==="exits"?{exits:n}:{items:n})}function se(e){return{text:String(e.Text??""),name:String(e.ElementName??""),elementId:String(e.ElementId??""),verbs:(e.Verbs??[]).map(String)}}var C=typeof HTMLElement.prototype.showPopover=="function";function H(e){for(let t of e.querySelectorAll("a.cmdlink, a[data-qv-event]"))t.hasAttribute("tabindex")||(t.tabIndex=0),t.setAttribute("role","button"),t.classList.contains("elementmenu")&&(t.setAttribute("aria-haspopup","menu"),t.setAttribute("aria-expanded","false")),t.toggleAttribute("aria-disabled",t.classList.contains("disabled"));for(let t of e.querySelectorAll("[data-qv-popup]"))t.setAttribute("aria-controls",t.dataset.qvPopup??""),t.setAttribute("aria-expanded","false")}function ae(e){for(let t of e.querySelectorAll("[data-qv-popup-content].qv-popup-open"))t.classList.remove("qv-popup-open");for(let t of e.querySelectorAll('[aria-expanded="true"]'))t.setAttribute("aria-expanded","false")}function M(e,t){e.classList.toggle("disabled",!t),t?e.removeAttribute("aria-disabled"):e.setAttribute("aria-disabled","true")}var k=e=>e.classList.contains("disabled");function rt(e){e.setAttribute("data-qv-deactivated",""),M(e,!1)}function ie(e){return Array.isArray(e)?e.map(String):[]}function le(e,t,n){if(t==="object"){let o=n&&typeof n=="object"?n:{};for(let r of e.querySelectorAll("a.elementmenu")){let i=o[r.dataset.elementid??""];i&&(r.dataset.verbs=String(i)),M(r,!!i)}}else if(t==="exit"){let o=ie(n);for(let r of e.querySelectorAll("a.exitlink"))M(r,o.includes(r.dataset.elementid??""))}else if(t==="command"){let o=ie(n);for(let r of e.querySelectorAll("a.commandlink:not([data-qv-deactivated])")){let i=r.dataset.elementid??"";M(r,i===""||o.includes(i))}}}function ce(e,t,n){let o=document.getElementById(e);o&&(o.classList.add("cmdlink","elementmenu"),o.dataset.verbs=t,o.dataset.elementid||(o.dataset.elementid=n),H(o.parentElement??o))}function ue(e,t){let n=e.target instanceof Element?e.target:null;if(!n)return;let o=n.closest("[data-qv-popup]");if(o){e.preventDefault(),Cn(o);return}let r=n.closest("[data-qv-direction]");if(r){r.disabled||g(r.dataset.qvDirection??"");return}let i=n.closest("[data-qv-command]");if(i){g(i.dataset.qvCommand??"");return}let l=n.closest(".qv-pane-verb");if(l){fe(l);return}let u=n.closest(".qv-pane-item");if(u){pe(u);return}let d=n.closest("[data-qv-popup-content]");d&&me(d);let c=n.closest("a");c&&(c.matches(".cmdlink, [data-qv-event]")?xn(e,c,t):c.hasAttribute("href")&&Tn(e,c))}function xn(e,t,n){if(t.dataset.qvEvent!==void 0){if(e.preventDefault(),k(t))return;if(t.dataset.qvEvent==="ShowMenuResponse")for(let o of t.ownerDocument.querySelectorAll('a[data-qv-event="ShowMenuResponse"]'))M(o,!1);L(t.dataset.qvEvent,t.dataset.qvParam??"")}else if(t.classList.contains("elementmenu"))e.preventDefault(),k(t)||n?.toggle(t);else if(t.classList.contains("exitlink"))e.preventDefault(),k(t)||g(t.dataset.command??"");else if(t.classList.contains("commandlink")){if(e.preventDefault(),k(t)||!Q())return;t.dataset.deactivateonclick==="true"&&rt(t),g(t.dataset.command??"")}}function Tn(e,t){let n=t.getAttribute("href")??"";n.startsWith("#")||/^\s*javascript:/i.test(n)||(e.preventDefault(),window.open(t.href,"_blank","noopener"))}function de(e){if(e.key!=="Enter"&&e.key!==" ")return;let t=e.target instanceof HTMLAnchorElement?e.target:null;t?.matches(".cmdlink, [data-qv-event]")&&(e.preventDefault(),t.click())}function Mn(e){let t=document.getElementById(e.dataset.qvPopup??"");return t?.hasAttribute("data-qv-popup-content")?t:null}function Cn(e){let t=Mn(e);if(t){if(t.classList.contains("qv-popup-open")){me(t);return}C&&!t.popover&&(t.popover="auto",t.addEventListener("beforetoggle",n=>{n.newState==="closed"&&xt(t,!1)})),xt(t,!0),C&&t.showPopover()}}function me(e){C&&e.matches(":popover-open")&&e.hidePopover(),xt(e,!1)}function xt(e,t){e.classList.toggle("qv-popup-open",t);for(let n of document.querySelectorAll(`[data-qv-popup="${CSS.escape(e.id)}"]`))n.setAttribute("aria-expanded",String(t))}var Mt=["inventory","objects","status","compass","commands","customstatus"],An={InventoryLabel:"inventory",PlacesObjectsLabel:"objects",StatusLabel:"status",CompassLabel:"compass"},st=class extends HTMLElement{#e;#t;#n;connectedCallback(){this.#e||(this.dataset.qvPart="pane",this.#e=document.createElement("details"),this.#e.open=!0,this.#t=document.createElement("summary"),this.#t.className="qv-pane-heading",this.#t.textContent=this.getAttribute("label")??"",this.#n=document.createElement("div"),this.#n.className="qv-pane-body",this.#n.append(...this.childNodes),this.#e.append(this.#t,this.#n),this.append(this.#e))}get name(){return this.dataset.qvPane??""}get body(){return this.#n}setLabel(t){this.#t.innerHTML=t}setContent(t){this.#n.innerHTML=t,H(this.#n)}};function h(e){return a()?.querySelector(`qv-pane[data-qv-pane="${CSS.escape(e)}"]`)??null}var Pn={inventory:"inventory",placesobjects:"objects"};function ve(e,t){let n=Pn[e];if(!n)return;let o=new Set(s.compassDirections),r=Object.values(t).map(d=>JSON.parse(d)).filter(d=>e!=="placesobjects"||!o.has(d.Text));P(n,r.map(se));let i=h(n);if(!i)return;let l=I.get(n);l!==void 0&&!r.some(d=>Tt(d)===l)&&I.delete(n);let u=document.createElement("ul");if(u.className="qv-pane-list",r.forEach((d,c)=>u.append(kn(n,d,`qv-${n}-verbs-${c}`))),u.childElementCount)i.body.replaceChildren(u);else{let d=document.createElement("p");d.className="qv-pane-empty",d.innerHTML=s.interfaceStrings.get(n==="inventory"?"InventoryEmptyLabel":"PlacesObjectsEmptyLabel")??s.interfaceStrings.get("EmptyListLabel")??"",i.body.replaceChildren(d)}a()?.verbMenu?.closeIfStale()}var I=new Map,Tt=e=>e.ElementId||e.ElementName;function ge(){I.clear(),Ct=[]}function kn(e,t,n){let o=document.createElement("li"),r=document.createElement("button");r.type="button",r.className="qv-pane-item",r.innerHTML=t.Text,r.dataset.qvKey=Tt(t),o.append(r);let i=(t.Verbs??[]).map(String).map(d=>d.trim()).filter(Boolean);if(!i.length)return o;let l=document.createElement("div");l.id=n,l.className="qv-pane-verbs",l.setAttribute("role","group"),l.setAttribute("aria-label",r.textContent?.trim()??"");for(let d of i){let c=document.createElement("button");c.type="button",c.className="qv-pane-verb",c.textContent=d,c.dataset.command=`${d.toLowerCase()} ${t.ElementName}`,c.dataset.qvName=t.ElementName,t.ElementId&&(c.dataset.elementid=t.ElementId),l.append(c)}let u=I.get(e)===Tt(t);return l.hidden=!u,r.setAttribute("aria-expanded",String(u)),r.setAttribute("aria-controls",n),o.append(l),o}function pe(e){let t=e.closest("qv-pane"),n=e.nextElementSibling;if(!t||!n?.classList.contains("qv-pane-verbs"))return;let o=n.hidden;for(let r of t.body.querySelectorAll('.qv-pane-item[aria-expanded="true"]'))r.setAttribute("aria-expanded","false"),r.nextElementSibling.hidden=!0;o?(n.hidden=!1,e.setAttribute("aria-expanded","true"),I.set(t.name,e.dataset.qvKey??""),n.scrollIntoView({block:"nearest"})):I.delete(t.name)}function fe(e){let t=e.dataset.qvName??"",n={};e.dataset.elementid&&(n[t]=e.dataset.elementid),g(e.dataset.command??"",n)}function be(e){let t=(Array.isArray(e)?e.map(String):String(e??"").split(";")).filter(o=>o.trim());s.commands=t.map(o=>{let[r,i]=o.split(":");return{label:r.trim(),command:(i??r).trim().toLowerCase()}});let n=o=>o.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;");h("commands")?.setContent(s.commands.map(({label:o,command:r})=>`<a class="cmdlink commandlink" data-elementid="" data-command="${n(r)}">${n(o)}</a>`).join(" ")),f()}function Se(e,t){e==="map"||e!=="customstatus"&&Mt.includes(e)||h(e)?.setContent(t)}function ye(e,t,n){let o=a()?.panes;if(!e||e==="map"||!o||h(e))return;let r=document.createElement("qv-pane");r.dataset.qvPane=e,r.setAttribute("label",t??e),o.append(r),r.setContent(n??"")}var Ct=[];function Ee(e){Ct=Array.isArray(e)?e.map(String):String(e??"").split(";"),At()}function At(){let e=a()?.panes;if(e)for(let t of[...Ct].reverse()){let n=h(t);n&&e.prepend(n)}}function Le(e,t){let n=An[e];return n?(h(n)?.setLabel(t),!0):!1}function it(){return!!a()?.panes?.classList.contains("qv-drawer-open")}function w(e,{restoreFocus:t=!0}={}){let n=a(),o=n?.panes,r=n?.panesButton;!o||!r||e===it()||(o.classList.toggle("qv-drawer-open",e),r.setAttribute("aria-expanded",String(e)),e?(document.addEventListener("pointerdown",he,!0),o.querySelector('summary, button, a[href], [tabindex="0"]')?.focus()):(document.removeEventListener("pointerdown",he,!0),t&&o.contains(document.activeElement)&&r.focus()))}function he(e){let t=a(),n=e.target instanceof Node?e.target:null;!n||t?.panes?.contains(n)||t?.panesButton?.contains(n)||t?.verbMenu?.contains(n)||w(!1,{restoreFocus:!1})}var Hn=["northwest","north","northeast","west","east","southwest","south","southeast","up","down","in","out"],qe=[315,0,45,270,90,225,180,135,null,null,null,null],we="http://www.w3.org/2000/svg",Pt=[[1,1],[1,2],[1,3],[2,1],[2,3],[3,1],[3,2],[3,3]],W=[];function at(){return s.compassDirections.length===12?s.compassDirections:Hn}function xe(e){let t=at()[e];return e===10?kt(s.interfaceStrings.get("InButtonLabel"))||t:e===11&&kt(s.interfaceStrings.get("OutButtonLabel"))||t}function kt(e){if(!e)return"";let t=document.createElement("template");return t.innerHTML=e,t.content.textContent?.trim()??""}function Te(e,t){let n=at()[e],o=document.createElement("button");o.type="button",o.className=t,o.dataset.qvDirection=n;let r=qe[e];return r!=null&&o.append(In(r)),o}function In(e){let t=document.createElementNS(we,"svg");t.setAttribute("class","qv-direction-arrow"),t.setAttribute("viewBox","0 0 24 24"),t.setAttribute("aria-hidden","true"),t.setAttribute("fill","none"),t.setAttribute("stroke","currentColor"),t.setAttribute("stroke-width","2"),t.setAttribute("stroke-linecap","round"),t.setAttribute("stroke-linejoin","round");let n=document.createElementNS(we,"path");return n.setAttribute("d","M12 19V5M5 12l7-7 7 7"),n.setAttribute("transform",`rotate(${e} 12 12)`),t.append(n),t}function B(){let e=h("compass");if(e){let t=document.createElement("div");t.className="qv-compass-points";let n=document.createElement("div");n.className="qv-compass-others",at().forEach((r,i)=>{let l=Te(i,"qv-compass-button"),u=xe(i);l.setAttribute("aria-label",u),l.title=u,qe[i]==null&&l.append(u),l.disabled=!W.includes(r),Pt[i]?(l.style.gridRow=String(Pt[i][0]),l.style.gridColumn=String(Pt[i][1]),t.append(l)):n.append(l)});let o=document.createElement("div");o.className="qv-compass",o.append(t,n),e.body.replaceChildren(o)}f()}function Me(e){W=String(e??"").split("/").filter(Boolean),P("exits",[...W]),B()}function Ce(){W=[]}function f(){let e=a(),t=e?.exits;if(!e||!t)return;let n=h("compass"),o=!!n&&!n.hidden&&!e.panes?.hidden,r=!s.turnPending&&!s.waiting&&!s.pausing&&!s.inDialog&&!s.gameFinished,i=[];o&&r&&at().forEach((d,c)=>{if(!W.includes(d))return;let v=Te(c,"qv-exit");v.append(xe(c)),i.push(v)});let l=h("commands");s.commandsInExitStrip&&l&&!l.hidden&&!e.panes?.hidden&&r&&s.commands.forEach(({label:d,command:c},v)=>{let m=document.createElement("button");m.type="button",m.className=v===0&&i.length>0?"qv-exit qv-exit-command qv-exit-command-first":"qv-exit qv-exit-command",m.dataset.qvCommand=c,m.append(d),i.push(m)}),t.replaceChildren(...i),t.setAttribute("aria-label",kt(s.interfaceStrings.get("CompassLabel"))||(WebPlayer.chromeStrings?.CompassLabel??"Compass")),t.classList.toggle("qv-exits-active",i.length>0)}var N=[];function Ht(e){N=Array.isArray(e)?e.filter(t=>t&&typeof t=="object"):[],P("status",N),$()}function Pe(e){Ht(String(e??"").split(/\r?\n|<br\s*\/?>/i).filter(t=>t.trim()).map(t=>({text:t})))}function ke(){N=[]}function Bn(e){let t=Number(e.value),n=Number(e.max);return e.value==null||e.max==null||!Number.isFinite(t)||!Number.isFinite(n)||n<=0?null:{value:Math.min(Math.max(t,0),n),max:n}}var Nn=0;function Ae(e,t){let n=document.createElement(t);n.className="qv-status-item",e.name&&(n.dataset.qvStatus=String(e.name));let o=document.createElement("span");o.className="qv-status-text",o.id=`qv-status-${++Nn}`,o.innerHTML=String(e.text??""),n.append(o);let r=Bn(e);if(r){let i=document.createElement("span");i.className="qv-status-meter",i.setAttribute("role","meter"),i.setAttribute("aria-valuemin","0"),i.setAttribute("aria-valuemax",String(r.max)),i.setAttribute("aria-valuenow",String(r.value)),i.setAttribute("aria-labelledby",o.id);let l=document.createElement("span");l.className="qv-status-meter-fill",l.style.width=`${r.value/r.max*100}%`,i.append(l),n.append(i)}return n}function $(){let e=a(),t=e?.statusBar??null,n=!!t&&!t.hidden&&!e?.hasAttribute("data-qv-gamebook"),o=n?N.filter(l=>l.pinned):[],r=n?N.filter(l=>!l.pinned):N,i=h("status");if(i){let l=document.createElement("ul");l.className="qv-status-list",l.append(...r.map(u=>Ae(u,"li"))),i.body.replaceChildren(l),i.hasAttribute("data-qv-empty")!==(r.length===0)&&(i.toggleAttribute("data-qv-empty",r.length===0),e?.updatePanesButton())}t&&(t.replaceChildren(...o.map(l=>Ae(l,"span"))),t.classList.toggle("qv-status-bar-active",o.length>0)),e?.updateTopbar()}var lt=document.currentScript instanceof HTMLScriptElement?document.currentScript.src:"",It=null,D=null,ct=null,z=[],ut=0,Bt=!0,K=!1,Nt="header",j=(e,t)=>WebPlayer.chromeStrings?.[e]??t,Dn={gridSquareClicked:(e,t)=>{L("JS_GridSquareClick",`${e};${t}`)},animate:()=>s.animateScroll&&!matchMedia("(prefers-reduced-motion: reduce)").matches,strings:()=>({map:j("MapLabel","Map"),zoomIn:j("MapZoomIn","Zoom in"),zoomOut:j("MapZoomOut","Zoom out")})};function On(){return window.QuestUIV2Map?Promise.resolve():(It??=new Promise((e,t)=>{let n=new URL(lt?"map.js":"v2/map.js",lt||document.baseURI);lt&&(n.search=new URL(lt).search);let o=document.createElement("script");o.src=n.href,o.onload=()=>e(),o.onerror=()=>{It=null,t(new Error(`Failed to load ${n.href}`))},document.head.append(o)}),It)}function He(){return a()?.map?.querySelector(".qv-map-view")??null}function Rn(){let e=He();if(!e||!window.QuestUIV2Map)return;(!D||ct!==e)&&(D=window.QuestUIV2Map.create(e,Dn),ct=e);let t=z;z=[];for(let[n,o]of t)try{D.call(n,o)}catch(r){console.error(r)}}function Dt(e,t){if(a()?.map){if(e==="show"){let n=typeof t[0]=="number"?t[0]:parseFloat(String(t[0]));ut=Number.isFinite(n)?n:0,q()}if(D&&ct===He()&&z.length===0){D.call(e,t);return}z.push([e,t]),On().then(Rn,n=>console.error(n))}}function Ie(e){Bt=e,q()}function Be(e){e!=="header"&&e!=="panes"||(Nt=e,q())}function q(){let e=a(),t=e?.map;if(!e||!t)return;t.hidden=!(ut>0&&Bt),t.style.setProperty("--qv-map-height",`${ut}px`),t.classList.toggle("qv-map-collapsed",K);let n=Un(t),o=e.mapButton;if(o){o.hidden=t.hidden||n||!e.hasAttribute("data-qv-narrow");let r=o.querySelector(".qv-button-label");r&&(r.textContent=j("MapLabel","Map")),o.setAttribute("aria-expanded",String(!K))}e.updateTopbar()}function Un(e){let t=a();if(!t)return!1;let n=Nt==="panes"&&t.layout!=="none"&&!!t.panes&&!t.panes.hidden,o=h("map");if(n&&!o&&t.panes&&(o=document.createElement("qv-pane"),o.dataset.qvPane="map",o.setAttribute("label",j("MapLabel","Map")),t.panes.prepend(o),At()),n&&o)e.parentElement!==o.body&&o.body.append(e),o.hidden=e.hidden;else{let r=t.querySelector(".qv-header");r&&e.parentElement!==r&&r.append(e),o&&(o.hidden=!0)}return n}function Ne(){K=!K,q()}function De(){D=null,ct=null,z=[],ut=0,Bt=!0,K=!1,Nt="header"}var Ot="questviva-colour-scheme",Fn=["system","light","dark"],G=Vn(),Re=typeof matchMedia=="function"?matchMedia("(prefers-color-scheme: dark)"):null;function Vn(){try{let e=window.electronPlayerSettings?window.electronPlayerSettings.getColourScheme():localStorage.getItem(Ot);if(e&&Fn.includes(e))return e}catch{}return"system"}function Qn(e){try{window.electronPlayerSettings?window.electronPlayerSettings.setColourScheme(e).catch(()=>{}):e==="system"?localStorage.removeItem(Ot):localStorage.setItem(Ot,e)}catch{}}function Wn(e){return!e.style.getPropertyValue("--qv-bg")}function $n(e){let t=document.createElement("span");t.style.color=e.style.getPropertyValue("--qv-bg"),t.hidden=!0,e.append(t);let n=/rgba?\(([\d.]+),\s*([\d.]+),\s*([\d.]+)/.exec(getComputedStyle(t).color);if(t.remove(),!n)return!1;let[o,r,i]=n.slice(1,4).map(l=>{let u=Number(l)/255;return u<=.03928?u/12.92:((u+.055)/1.055)**2.4});return .2126*o+.7152*r+.0722*i<.18}function Y(e){let t=Wn(e),n=t?G==="dark"||G==="system"&&!!Re?.matches:$n(e);e.setAttribute("data-qv-scheme",n?"dark":"light"),e.toggleAttribute("data-qv-fixed-scheme",!t),document.documentElement.setAttribute("data-qv-scheme",n?"dark":"light");let o=e.querySelector(".qv-scheme");if(o){o.hidden===t&&(o.hidden=!t,t||A(e,!1));for(let r of o.querySelectorAll("[data-qv-scheme-icon]"))r.hidden=r.dataset.qvSchemeIcon!==G;for(let r of o.querySelectorAll("[data-qv-scheme-choice]"))r.setAttribute("aria-checked",String(r.dataset.qvSchemeChoice===G))}}function jn(e,t){G=t,Qn(t),Y(e)}function Ft(e){return e.querySelector(".qv-scheme-menu")}function Rt(e){return[...e.querySelectorAll("[data-qv-scheme-choice]")]}function Oe(e){let t=Ft(e),n=e.querySelector(".qv-scheme-button");if(!t||!n)return;t.hidden=!1,n.setAttribute("aria-expanded","true"),(Rt(t).find(r=>r.getAttribute("aria-checked")==="true")??Rt(t)[0])?.focus()}function A(e,t){let n=Ft(e),o=e.querySelector(".qv-scheme-button");!n||n.hidden||(n.hidden=!0,o?.setAttribute("aria-expanded","false"),t&&o?.focus())}var Ut=null;Re?.addEventListener("change",()=>{Ut?.isConnected&&Y(Ut)});function Ue(e){Ut=e,Y(e);let t=e.querySelector(".qv-scheme-button"),n=Ft(e);!t||!n||(t.addEventListener("click",()=>{n.hidden?Oe(e):A(e,!0)}),t.addEventListener("keydown",o=>{(o.key==="ArrowDown"||o.key==="ArrowUp")&&(o.preventDefault(),Oe(e))}),n.addEventListener("click",o=>{let r=o.target instanceof Element?o.target.closest("[data-qv-scheme-choice]"):null;r&&(jn(e,r.dataset.qvSchemeChoice),A(e,!0))}),n.addEventListener("keydown",o=>{let r=Rt(n),i=r.indexOf(document.activeElement),l=-1;if(o.key==="ArrowDown")l=(i+1)%r.length;else if(o.key==="ArrowUp")l=(i-1+r.length)%r.length;else if(o.key==="Home")l=0;else if(o.key==="End")l=r.length-1;else if(o.key==="Escape"){o.preventDefault(),o.stopPropagation(),A(e,!0);return}else if(o.key==="Tab"){A(e,!1);return}l>=0&&(o.preventDefault(),r[l]?.focus())}),document.addEventListener("pointerdown",o=>{!n.hidden&&o.target instanceof Node&&!n.contains(o.target)&&!t.contains(o.target)&&A(e,!1)}),n.addEventListener("focusout",o=>{o.relatedTarget instanceof Node&&!n.contains(o.relatedTarget)&&o.relatedTarget!==t&&A(e,!1)}))}var Fe=["sidepanes","nopanes","bottombar"],zn=900,Kn=new Set(["--qv-font-size","--qv-output-width","--qv-padding-top","--qv-padding-bottom","--qv-padding-left","--qv-padding-right","--qv-menu-font-size","--qv-radius","--qv-space"]),dt=class extends HTMLElement{#e=!1;#t="sidepanes";#n="sidepanes";connectedCallback(){if(this.#e)return;this.#e=!0,this.addEventListener("click",n=>ue(n,this.verbMenu)),this.addEventListener("keydown",de);for(let n of this.querySelectorAll(".qv-panes-button"))n.addEventListener("click",()=>w(!it()));this.mapButton?.addEventListener("click",Ne),Ue(this),new ResizeObserver(()=>this.#r()).observe(this),this.panes?.addEventListener("keydown",n=>{n.key==="Escape"&&it()&&!this.verbMenu?.isOpen&&(n.preventDefault(),w(!1))});let t=this.querySelector(".qv-toolbar");t&&(new MutationObserver(()=>{Qe(t),this.updateTopbar()}).observe(t,{subtree:!0,childList:!0,attributes:!0,attributeFilter:["style","hidden"]}),Qe(t)),this.addEventListener("pointerover",n=>{let o=n.target instanceof Element?n.target.closest("button"):null;if(!o?.querySelector(":scope > .qv-icon"))return;let r=o.querySelector(".qv-button-label")?.textContent?.trim()||o.getAttribute("aria-label");r&&(o.title=r)}),this.#r(),this.updatePanesButton()}get topbar(){return this.querySelector(".qv-topbar")}get saveButton(){return this.querySelector("#cmdSave")}get panes(){return this.querySelector('[data-qv-part="panes"]')}get exits(){return this.querySelector('[data-qv-part="exits"]')}get statusBar(){return this.querySelector('[data-qv-part="status-bar"]')}get panesButton(){return this.querySelector(this.layout==="sheet"?".qv-footer .qv-panes-button":".qv-topbar .qv-panes-button")}get layout(){return this.dataset.qvLayout??"side"}setLayoutPreset(t,n){if(t==="gamebook"){this.toggleAttribute("data-qv-gamebook",!0),this.#t=this.#n="nopanes",this.setVisible("command-bar",!1),this.setVisible("location",!1),this.#r();return}Fe.includes(t)&&(this.removeAttribute("data-qv-gamebook"),this.#t=t,this.#n=n!=null&&Fe.includes(n)?n:t,this.#r())}#r(){let t=this.clientWidth<zn;t!==this.hasAttribute("data-qv-narrow")&&(this.toggleAttribute("data-qv-narrow",t),q());let n=t?this.#n:this.#t,o=n==="nopanes"?"none":n==="bottombar"?"sheet":t?"drawer":"side";this.dataset.qvLayout!==o&&(w(!1,{restoreFocus:!1}),this.toggleAttribute("data-qv-layout-changing",!0),this.dataset.qvLayout=o,q(),requestAnimationFrame(()=>requestAnimationFrame(()=>this.removeAttribute("data-qv-layout-changing"))),f(),this.updateTopbar())}updateTopbar(){let t=this.topbar;if(!t)return;let n=this.location,o=[...t.querySelectorAll(".qv-toolbar > button, .qv-toolbar > .qv-scheme:not([hidden]) > button")].some(l=>!l.hidden&&l.style.display!=="none"&&getComputedStyle(l).display!=="none"),r=this.statusBar,i=!!r&&!r.hidden&&r.classList.contains("qv-status-bar-active")&&getComputedStyle(r).display!=="none";t.hidden=(!n||n.hidden)&&!o&&!i}focusFirstChoice(){if(!this.hasAttribute("data-qv-gamebook"))return;let t=document.activeElement;if(t&&t!==document.body&&this.contains(t)&&!t.closest(".qv-hiding")&&!t.classList.contains("disabled"))return;[...this.querySelectorAll('[data-qv-part="output"] [data-qv-sections] a.commandlink:not(.disabled)')].find(o=>!o.closest(".qv-hiding"))?.focus({preventScroll:!0})}get verbMenu(){return this.querySelector("qv-verb-menu")}updateLinks(t,n){le(this,t,n),this.verbMenu?.closeIfStale()}get output(){return this.querySelector("qv-output")}get commandBar(){return this.querySelector("qv-command-bar")}get location(){return this.querySelector('[data-qv-part="location"]')}get pictureFrame(){return this.querySelector('[data-qv-part="picture-frame"]')}get map(){return this.querySelector('[data-qv-part="map"]')}get mapButton(){return this.querySelector(".qv-map-button")}get frame(){return this.querySelector('[data-qv-part="border"]')}setVisible(t,n){switch(t){case"output":this.#o(this.output,!n);break;case"command-bar":this.#o(this.commandBar,!n);break;case"location":this.#o(this.location,!n),this.updateTopbar();break;case"border":this.frame?.classList.toggle("qv-borderless",!n);break;case"picture-frame":this.#o(this.pictureFrame,!n);break;case"exits":this.#o(this.exits,!n);break;case"map":Ie(n);break;case"status-bar":this.#o(this.statusBar,!n);break;case"panes":this.#o(this.panes,!n),n||w(!1,{restoreFocus:!1}),q(),this.updatePanesButton();break;default:(Mt.includes(t)||h(t))&&(this.#o(h(t),!n),this.updatePanesButton())}f(),$()}updatePanesButton(){let t=this.panes;if(!t)return;let n=[...t.querySelectorAll("qv-pane")].some(o=>!o.hidden&&!o.hasAttribute("data-qv-empty"));for(let o of this.querySelectorAll(".qv-panes-button"))o.hidden=t.hidden||!n;this.updateTopbar()}#o(t,n){t&&(t.hidden=n)}setTokens(t){for(let[n,o]of Object.entries(t)){if(!n.startsWith("--"))continue;let r=o==null?"":String(o).trim();if(r===""){this.style.removeProperty(n);continue}Kn.has(n)&&/^-?(\d+\.?\d*|\.\d+)$/.test(r)&&(r+="px"),this.style.setProperty(n,r)}this.toggleAttribute("data-qv-own-accent",!!this.style.getPropertyValue("--qv-accent")),this.toggleAttribute("data-qv-own-background",["--qv-bg","--qv-bg-light","--qv-bg-dark"].some(n=>!!this.style.getPropertyValue(n))),this.toggleAttribute("data-qv-own-border",["--qv-border-colour","--qv-border-colour-light","--qv-border-colour-dark"].some(n=>!!this.style.getPropertyValue(n))),Y(this),this.updateTopbar()}setLocation(t){let n=this.location;n&&(n.innerHTML=t,n.classList.toggle("qv-empty",t.trim()===""))}},Ve="http://www.w3.org/2000/svg";function Qe(e){let t=e.querySelector("#cmdRestart");if(!t||t.querySelector(".qv-icon"))return;let n=document.createElement("span");n.className="qv-button-label",n.textContent=t.textContent;let o=document.createElementNS(Ve,"svg");o.setAttribute("class","qv-icon"),o.setAttribute("viewBox","0 0 24 24"),o.setAttribute("aria-hidden","true");for(let r of["M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8","M3 3v5h5"]){let i=document.createElementNS(Ve,"path");i.setAttribute("d",r),o.append(i)}t.replaceChildren(o,n)}function a(){return document.querySelector("qv-player")}var mt=0,Vt=0,_,We=!1;function $e(e){Vt=e,Gn()}function Qt(){return O(),mt}function je(){We=!0,O()}function O(){_!==void 0&&(clearInterval(_),_=void 0)}function Gn(){We||_!==void 0||(mt=0,_=setInterval(async()=>{mt++,Vt>0&&mt>=Vt&&await WebPlayer.uiTick(Qt())},1e3))}function Q(){return window.canSendCommand&&!s.gameFinished&&!s.soundWait&&!s.waiting&&!s.pausing&&!s.inDialog}function g(e,t){if(!Q())return!1;window.canSendCommand=!1,a()?.output?.markScrollPosition(),s.hasUnsavedProgress=!0;let n=Qt();return setTimeout(()=>{WebPlayer.sendCommand(e,n,t??null)},0),!0}function L(e,t){s.hasUnsavedProgress=!0;let n=""+t;return setTimeout(()=>{WebPlayer.uiSendEvent(e,n)},1),!0}var pt=new Set;function R(e,t){t?pt.add(e):pt.delete(e),a()?.toggleAttribute("data-qv-input-held",pt.size>0)}function Ke(){pt.clear(),clearTimeout(ft),J=null}function Ge(){s.waiting=!0,f(),a()?.commandBar?.setMode("continue"),a()?.output?.markScrollPosition()}function Z(){s.waiting&&(s.waiting=!1,a()?.commandBar?.setMode("none"),s.hasUnsavedProgress=!0,sendEndWait())}function $t(){f(),!s.waiting&&ht()}var ft;function Ye(e){s.pausing=!0,f(),R("pause",!0),clearTimeout(ft),ft=setTimeout(_n,e)}function _n(){s.pausing&&(s.pausing=!1,sendEndPause())}function jt(){f(),!s.pausing&&(R("pause",!1),ht())}function _e(){s.waiting&&(s.waiting=!1,$t()),s.pausing&&(clearTimeout(ft),s.pausing=!1,jt()),J?.()}function ht(){let e=a()?.commandBar;!e||s.gameFinished||s.waiting||s.inDialog||(e.setMode("input"),e.focusInput())}var Wt={cancel:"Cancel",yes:"Yes",no:"No"},ze=0,J=null;function Je(e,t,n){let o=a();if(!o)return;let r=++ze;o.querySelector("dialog.qv-dialog")?.remove();let i=document.createElement("dialog");i.className="qv-dialog",i.dataset.qvPart="menu";let l="qv-dialog-caption";i.setAttribute("aria-labelledby",l);let u=document.createElement("div");u.id=l,u.className="qv-dialog-caption",u.innerHTML=e;let d=document.createElement("div");d.className="qv-dialog-choices";let c=!1,v=m=>{c||(c=!0,J=null,i.close(),i.remove(),s.hasUnsavedProgress=!0,setTimeout(async()=>{try{await m()}finally{ze===r&&(s.inDialog=!1,f(),ht())}},100))};for(let m of t){let T=document.createElement("button");T.type="button",T.textContent=m.label,T.addEventListener("click",()=>v(m.choose)),d.append(T)}if(i.append(u,d),n){let m=document.createElement("button");m.type="button",m.className="qv-dialog-cancel",m.textContent=Wt.cancel,m.addEventListener("click",()=>v(n)),i.append(m)}i.addEventListener("cancel",m=>{m.preventDefault(),n&&v(n)}),i.addEventListener("close",()=>{!c&&i.isConnected&&i.showModal()}),J=()=>{c=!0,J=null,i.close(),i.remove(),s.inDialog=!1,f(),ht()},s.inDialog=!0,f(),o.commandBar?.setMode("none"),o.append(i),i.showModal(),d.querySelector("button")?.focus()}function Ze(e,t,n){let o=Object.entries(t).map(([r,i])=>({label:i,choose:()=>WebPlayer.uiChoice(r)}));Je(e,o,n?()=>WebPlayer.uiChoiceCancel():null)}function Xe(e){Je(e,[{label:Wt.yes,choose:()=>WebPlayer.uiSetQuestionResponse(!0)},{label:Wt.no,choose:()=>WebPlayer.uiSetQuestionResponse(!1)}],null)}var en=typeof matchMedia=="function"&&matchMedia("(pointer: coarse)").matches;document.addEventListener("pointerdown",e=>{en=e.pointerType!=="mouse"&&!(e.target instanceof Element&&e.target.closest(".qv-command-input"))},!0);var vt=class extends HTMLElement{#e;#t;#n;#r;#o="input";#s=[];#i=0;#a="";connectedCallback(){if(this.#t)return;let t=this.#e=document.createElement("form");t.className="qv-command-form",this.#n=document.createElement("span"),this.#n.className="qv-command-prompt",this.#n.setAttribute("aria-hidden","true"),this.#t=document.createElement("input"),this.#t.type="text",this.#t.className="qv-command-input",this.#t.autocomplete="off",this.#t.spellcheck=!1,this.#t.setAttribute("autocapitalize","off"),this.#t.setAttribute("enterkeyhint","send"),this.#t.dataset.chromeKeyAriaLabel="CommandInputLabel",this.#t.setAttribute("aria-label","Type your command"),t.append(this.#n,this.#t),this.#r=document.createElement("button"),this.#r.type="button",this.#r.className="qv-continue",this.#r.hidden=!0,this.#r.addEventListener("click",Z),this.append(t,this.#r),t.addEventListener("submit",n=>{n.preventDefault(),this.#c()}),this.#t.addEventListener("keydown",n=>this.#l(n)),this.updatePlaceholder(),this.updateContinueLabel()}setMode(t){this.#o=t,this.#e.hidden=t!=="input",this.#r.hidden=t!=="continue",t==="continue"&&this.#r.focus({preventScroll:!0})}get input(){return this.#t}focusInput(){if(this.hidden)return;let t=this.#o==="input"?this.#t:this.#o==="continue"?this.#r:null;t===this.#t&&en||t&&document.activeElement!==t&&t.focus({preventScroll:!0})}setPrompt(t){this.#n.innerHTML=t}setStyle(t){this.#t.style.cssText=t}setPreset(t){(t==="borderless"||t==="shadow")&&(this.dataset.qvPreset=t)}updateContinueLabel(){this.#r.textContent=tn(s.interfaceStrings.get("ContinueLabel")??"")||"Continue"}updatePlaceholder(){this.#t.placeholder=s.commandPlaceholder??tn(s.interfaceStrings.get("TypeHereLabel")??"")}#c(){let t=this.#t.value;t.length===0||!Q()||g(t)&&(this.#s.at(-1)!==t&&this.#s.push(t),this.#i=this.#s.length,this.#a="",this.#t.value="")}#l(t){if(t.key!=="ArrowUp"&&t.key!=="ArrowDown"||t.altKey||t.ctrlKey||t.metaKey||t.shiftKey)return;let n=this.#i+(t.key==="ArrowUp"?-1:1);if(n<0||n>this.#s.length)return;t.preventDefault(),this.#i===this.#s.length&&(this.#a=this.#t.value),this.#i=n,this.#t.value=n===this.#s.length?this.#a:this.#s[n];let o=this.#t.value.length;this.#t.setSelectionRange(o,o)}};function tn(e){let t=document.createElement("template");return t.innerHTML=e,t.content.textContent??""}var zt=new Set;function gt(e,t){let n=typeof e=="number"?e:parseFloat(String(e));return Number.isFinite(n)?n:t}function Zn(e){let t=document.createElement("template");return t.innerHTML=String(e??""),t.content.textContent??""}function nn(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";return e[Math.floor(Math.random()*e.length)]}function Xn(e){for(let t=e.length-1;t>0;t--){let n=Math.floor(Math.random()*(t+1));[e[t],e[n]]=[e[n],e[t]]}}function on(e,t){if(e!=="typewriter"&&e!=="unscramble")return;let n=a()?.output;if(!n)return;let o=Zn(t[0]),r=Math.max(0,gt(t[1],100)),i=e==="unscramble"?Math.max(1,Math.floor(gt(t[2],1))):0,[l,u,d]=(e==="unscramble"?t.slice(3,6):t.slice(2,5)).map(b=>b==null?"":String(b).trim()),c=document.createElement("span");c.className="qv-text-effect",c.dataset.qvEffect=e,l&&c.style.setProperty("font-family",l),u&&c.style.setProperty("color",u),d&&gt(d,0)>0&&c.style.setProperty("font-size",`${gt(d,0)}pt`);let v=document.createElement("span");v.className="qv-text-effect-full",v.textContent=o;let m=document.createElement("span");m.className="qv-text-effect-shown",m.setAttribute("aria-hidden","true"),c.append(v,m);let T=document.createElement("span");if(T.textContent=o,n.addNodes([c,document.createElement("br")],`${T.innerHTML}<br/>`),!(s.animateScroll&&!matchMedia("(prefers-reduced-motion: reduce)").matches)||o===""){Kt(c);return}c.classList.add("qv-text-effect-running");let wt;if(e==="typewriter"){let b=0;wt=()=>(b++,m.textContent=o.substring(0,b)+(b%2===1&&b<o.length?"_":""),b>=o.length)}else{let b=[...o],F=b.flatMap((E,nt)=>/\s/.test(E)?[]:[nt]);Xn(F);let et=b.map(E=>/\s/.test(E)?E:nn());m.textContent=et.join(""),wt=()=>{for(let E=0;E<i&&F.length;E++){let nt=F.pop();et[nt]=b[nt]}for(let E of F)et[E]=nn();return m.textContent=et.join(""),F.length===0}}let U={timer:0,finish:()=>{clearInterval(U.timer),zt.delete(U),Kt(c)}};U.timer=window.setInterval(()=>{(!c.isConnected||wt())&&U.finish()},r),zt.add(U)}function Kt(e){let t=e.querySelector(".qv-text-effect-shown");t&&(t.textContent=e.querySelector(".qv-text-effect-full")?.textContent??""),e.classList.remove("qv-text-effect-running")}function bt(){for(let e of[...zt])e.finish()}function rn(e){for(let t of e.querySelectorAll(".qv-text-effect"))Kt(t)}document.addEventListener("keydown",()=>bt(),!0);document.addEventListener("pointerdown",()=>bt(),!0);var sn=4,to=150,eo=8,St=class extends HTMLElement{#e=null;#t=0;#n=0;#r=null;#o=null;#s=!1;connectedCallback(){this.#e=this.querySelector("button"),this.#e?.addEventListener("click",this.#l),window.addEventListener("scroll",this.#i,{passive:!0}),window.addEventListener("resize",this.#i,{passive:!0}),this.#r=new ResizeObserver(this.#i);let t=a();for(let n of[t?.output,t?.commandBar,t?.querySelector(".qv-footer"),t?.querySelector(".qv-header")])n&&this.#r.observe(n);this.#o=new MutationObserver(n=>{n.some(o=>o.type==="characterData"||o.addedNodes.length>0)&&(this.#s=!1,this.#i())}),t?.output&&this.#o.observe(t.output,{childList:!0,characterData:!0,subtree:!0}),this.#i()}disconnectedCallback(){this.#e?.removeEventListener("click",this.#l),window.removeEventListener("scroll",this.#i),window.removeEventListener("resize",this.#i),this.#r?.disconnect(),this.#r=null,this.#o?.disconnect(),this.#o=null,cancelAnimationFrame(this.#t),clearTimeout(this.#n),this.#t=this.#n=0}#i=()=>{this.#t||(this.#t=requestAnimationFrame(()=>{this.#t=0,this.#a()}))};#a(){let t=this.#e;if(!t)return;let n=Gt();if(!n||this.#s){n||(this.#s=!0),clearTimeout(this.#n),this.#n=0,this.#c();return}this.style.setProperty("--qv-more-bottom",`${window.innerHeight-n.limit+eo}px`),this.style.setProperty("--qv-more-x",`${n.centre}px`),t.hidden&&(clearTimeout(this.#n),this.#n=window.setTimeout(()=>{this.#n=0,!this.#s&&Gt()&&(t.hidden=!1)},to))}#c(){let t=this.#e;if(!t||t.hidden)return;let n=t.contains(document.activeElement);t.hidden=!0,n&&(a()?.commandBar?.focusInput(),document.activeElement===t&&t.blur())}#l=()=>{let t=Gt();if(!t)return;let n=document.querySelector("qv-player .qv-header"),o=Math.max(0,n?.getBoundingClientRect().bottom??0),r=a()?.output,i=r&&parseFloat(getComputedStyle(r).lineHeight)||24,l=Math.max(i,t.limit-o-2*i),u=!matchMedia("(prefers-reduced-motion: reduce)").matches;window.scrollBy({top:l,behavior:u?"smooth":"instant"})}};function Gt(){let e=a(),t=e?.output;if(!e||!t||t.hidden||!t.isConnected)return null;let n=window.innerHeight,o=e.querySelector(".qv-footer"),r=o&&getComputedStyle(o).display!=="contents"?o:e.commandBar,i=r&&!r.hidden&&r.offsetHeight>0?r.getBoundingClientRect():null,l=i?Math.min(n,i.top):n,u=t.lastElementChild;if(!((u?u.getBoundingClientRect().bottom:t.getBoundingClientRect().top)>l+sn||i!=null&&i.bottom>n+sn))return null;let v=t.getBoundingClientRect();return{limit:l,centre:v.left+v.width/2}}var ln=(e,t)=>WebPlayer.chromeStrings?.[e]??t;function an(e){return e.replace(/&/g,"&amp;").replace(/"/g,"&quot;").replace(/</g,"&lt;")}function cn(e,t,n,o=""){let r=a()?.output;r&&r.addText(`<iframe class="qv-video" data-qv-video="${e}" src="${an(t.href)}" title="${an(n)}" allow="autoplay; fullscreen; picture-in-picture; encrypted-media" allowfullscreen${o}></iframe>`)}function un(e){let t=new URL(`https://www.youtube-nocookie.com/embed/${encodeURIComponent(e.trim())}`);t.searchParams.set("autoplay","1"),t.searchParams.set("rel","0"),cn("youtube",t,ln("YouTubeVideoTitle","YouTube video"))}function dn(e){let[t,n]=e.trim().split("/"),o=new URL(`https://player.vimeo.com/video/${encodeURIComponent(t)}`);n&&o.searchParams.set("h",n),o.searchParams.set("autoplay","1"),o.searchParams.set("dnt","1"),cn("vimeo",o,ln("VimeoVideoTitle","Vimeo video"),' sandbox="allow-same-origin allow-scripts allow-popups allow-presentation"')}function mn(e){for(let t of e.querySelectorAll("iframe[data-qv-video]")){let n;try{n=new URL(t.getAttribute("src")??"")}catch{continue}n.searchParams.has("autoplay")&&(n.searchParams.delete("autoplay"),t.setAttribute("src",n.href))}}function yt(e){let t=a()?.pictureFrame;if(t){t.innerHTML=e,t.classList.toggle("qv-empty",e.trim()==="");for(let n of t.querySelectorAll("img"))n.hasAttribute("alt")||(n.alt=""),n.complete||(n.addEventListener("load",Yt,{once:!0}),n.addEventListener("error",Yt,{once:!0}));Yt()}}function pn(){let e=a()?.pictureFrame;return!e||e.hidden||e.classList.contains("qv-empty")?!1:[...e.querySelectorAll("img")].some(t=>!t.complete)}function Yt(){a()?.output?.rescroll(!0)}var vn=new Map;function gn(e,t,n){vn.set(e,{width:t,height:n})}var no=8;function oo(e){s.warnedAboutScript||!/<script[\s>\/]/i.test(e)||(s.warnedAboutScript=!0,console.warn(`[Quest] This game printed a <script> element, which doesn't run in the new player interface. Call your own JavaScript with JS.yourFunction () or JS.eval instead, or tick "Use the classic interface" on the game's Interface tab.`))}var Et=class extends HTMLElement{#e=null;#t=[];#n=0;#r=0;#o=!0;#s=0;connectedCallback(){this.setAttribute("role","log"),this.setAttribute("aria-live","polite"),this.addEventListener("load",this.#i,!0),this.addEventListener("error",this.#i,!0)}disconnectedCallback(){this.removeEventListener("load",this.#i,!0),this.removeEventListener("error",this.#i,!0)}#i=t=>{t.target instanceof HTMLImageElement&&this.rescroll()};addText(t){oo(t);let n=this.#e??this.setAlignment("left");n.insertAdjacentHTML("beforeend",t),ro(n),so(n),H(n),this.#o=!0,WebPlayer.transcript?.write(t),y("outputAdded",{html:t})}addNodes(t,n){(this.#e??this.setAlignment("left")).append(...t),this.#o=!0,WebPlayer.transcript?.write(n),y("outputAdded",{html:n})}setAlignment(t){this.#e&&!this.#e.hasChildNodes()&&this.#e.remove();let n=document.createElement("div");return n.className="qv-block",n.style.textAlign=t,this.#t.length&&(n.dataset.qvSections=this.#t.join(" ")),this.append(n),this.#e=n,n}clearScreen(){this.replaceChildren(),this.#e=null,this.setAlignment("left"),this.#n=0,this.#o=!0;let t=this.#u();window.scrollY>t&&window.scrollTo({top:t,behavior:"instant"})}loadHtml(t){let n=document.createElement("template");n.innerHTML=t,mn(n.content),rn(n.content),this.replaceChildren(n.content),this.#o=!0,H(this),ae(this),requestAnimationFrame(()=>{let o=document.scrollingElement??document.documentElement;window.scrollTo({top:o.scrollHeight,behavior:"instant"})}),this.#e=null,this.#t=[]}getHtml(){return this.innerHTML}reset(){this.replaceChildren(),this.#e=null,this.#t=[],this.#n=0,this.#r=0,this.#o=!0,this.#s=0}startSection(t){this.#t.includes(t)||(this.#t.push(t),this.setAlignment("left"))}endSection(t){let n=this.#t.indexOf(t);n!==-1&&(this.#t.splice(n,1),this.setAlignment("left"))}hideSection(t){this.endSection(t);let n=this.getBoundingClientRect().top;for(let o of this.#a(t)){let r=o.getBoundingClientRect();r.bottom-n<=this.#n+1&&(this.#n=Math.max(0,this.#n-r.height)),o.classList.add("qv-hiding"),hn(o),setTimeout(()=>o.remove(),250)}}disableSection(t){for(let n of this.#a(t))hn(n)}disableCommandLinks(){for(let t of this.querySelectorAll("a.commandlink"))rt(t);a()?.verbMenu?.closeIfStale()}#a(t){return[...this.querySelectorAll("[data-qv-sections]")].filter(n=>n.dataset.qvSections.split(" ").includes(t))}beginTurn(){if(s.fadePreviousOutput)for(let t of this.children)t.classList.add("qv-previous-output")}clearPreviousOutputFade(){for(let t of this.querySelectorAll(".qv-previous-output"))t.classList.remove("qv-previous-output")}markScrollPosition(){this.#n=this.#c()}#c(){let t=this.lastElementChild;return t?t.getBoundingClientRect().bottom-this.getBoundingClientRect().top:0}scrollToEnd(){let t=this.#c();!this.#o&&t<=this.#s+1||(this.#o=!1,this.#s=t,this.#l(this.#n))}rescroll(t=!1){this.#l(this.#r,t)}#l(t,n=!1){if(!s.autoScroll||(this.#r=t,pn()))return;let r=(document.scrollingElement??document.documentElement).scrollHeight-window.innerHeight,i=s.animateScroll?Math.min(this.#u()+t-fn()-no,r):r,l=this.#u()+t-window.scrollY,u=n&&l>=0&&l<fn();if(i<=window.scrollY&&!u)return;let d=s.animateScroll&&!matchMedia("(prefers-reduced-motion: reduce)").matches;window.scrollTo({top:i,behavior:d?"smooth":"instant"})}#u(){return this.getBoundingClientRect().top+window.scrollY}};function fn(){return document.querySelector("qv-player .qv-header")?.offsetHeight??0}function hn(e){for(let t of e.querySelectorAll("a.cmdlink, a[data-qv-event]"))t.classList.contains("commandlink")?rt(t):M(t,!1);a()?.verbMenu?.closeIfStale()}function ro(e){for(let t of e.querySelectorAll("img:not([alt])"))t.setAttribute("alt","")}function so(e){for(let t of e.querySelectorAll("img:not([width]):not([height]):not([style])")){let n=vn.get(t.getAttribute("src")??"");n&&(t.setAttribute("width",String(n.width)),t.setAttribute("height",String(n.height)),t.classList.add("qv-sized"))}}var x=()=>WebPlayer.transcript;function bn(e){let t=a()?.output;t?.addText(e),t?.scrollToEnd()}var Sn={write:e=>x()?.write(String(e??"")),enable:e=>x()?.enable(e==null?void 0:String(e)),disable:()=>x()?.disable(),kill:()=>x()?.kill(),revive:()=>x()?.revive(),setName:e=>x()?.setName(String(e??"")),setPrefix:()=>{},stampDateAndTime:()=>bn(`<b>DATE AND TIME:</b> ${new Date().toLocaleString(navigator.language,{timeZoneName:"short"})}`),promptForName:()=>{let e=a()?.commandBar?.input;e&&(e.value=x()?.name||document.title,e.focus({preventScroll:!0}))},show:(e,t)=>{let n=document.createElement("a");n.href=x()?.viewerUrl??"TranscriptViewer/index.html",n.target="_blank",n.textContent=t==null||t===""?"Your Transcripts":String(t);let o=e==null||e===""?"Your transcripts are saved to the localStorage in your browser. You can view, download, or delete them here:":String(e);bn(`${o} ${n.outerHTML}<br/>`)}};var p=e=>(...t)=>Dt(e,t),io={show:p("show"),respondToClicks:p("respondToClicks"),setInteractive:p("setInteractive"),setScale:p("setScale"),setCentre:p("setCentre"),drawBox:p("drawBox"),drawLabel:p("drawLabel"),drawPlayer:p("drawPlayer"),drawLine:p("drawLine"),drawArrow:p("drawArrow"),drawSquare:p("drawSquare"),drawShape:p("drawShape"),addShapePoint:p("addShapePoint"),drawImage:p("drawImage"),drawSvg:p("drawSvg"),loadSvg:p("loadSvg"),drawGridLines:p("drawGridLines"),showCustomLayer:p("showCustomLayer"),clearCustomLayer:p("clearCustomLayer"),removeDrawing:p("removeDrawing"),clearAllLayers:p("clearAllLayers"),setLevel:p("setLevel")};function X(e){return typeof e=="string"?JSON.parse(e):e}function _t(e){let t=e??"";a()?.setLocation(t),y("locationChanged",{location:t})}function Jt(e,t){s.interfaceStrings.set(e,t),e==="EmptyListLabel"&&(s.interfaceStrings.delete("InventoryEmptyLabel"),s.interfaceStrings.delete("PlacesObjectsEmptyLabel")),Le(e,t),(e==="InButtonLabel"||e==="OutButtonLabel"||e==="CompassLabel")&&B(),e==="TypeHereLabel"&&a()?.commandBar?.updatePlaceholder(),e==="ContinueLabel"&&a()?.commandBar?.updateContinueLabel()}function Zt(e){s.compassDirections=Array.isArray(e)?e.map(String):String(e??"").split(";"),B()}var yn={sendCommand:g,sendEvent:L,restart:()=>window.RestartGame?.(),addText:e=>a()?.output?.addText(String(e)),clearScreen:()=>a()?.output?.clearScreen(),setAlignment:e=>{a()?.output?.setAlignment(String(e))},startSection:e=>a()?.output?.startSection(String(e)),endSection:e=>a()?.output?.endSection(String(e)),hideSection:e=>a()?.output?.hideSection(String(e)),disableSection:e=>a()?.output?.disableSection(String(e)),disableCommandLinks:()=>a()?.output?.disableCommandLinks(),updateLinks:(e,t)=>a()?.updateLinks(String(e),X(t)),scrollToEnd:()=>a()?.output?.scrollToEnd(),addYouTube:e=>un(String(e??"")),addVimeo:e=>dn(String(e??"")),textEffect:(e,...t)=>on(String(e),t),setVisible:(e,t)=>a()?.setVisible(String(e),!!t),setPaneOrder:e=>Ee(X(e)),setLayoutPreset:(e,t)=>a()?.setLayoutPreset(String(e),t==null?void 0:String(t)),setMapPosition:e=>Be(String(e??"")),setPictureFrame:e=>yt(String(e??"")),setInterfaceString:Jt,setCompassDirections:e=>Zt(X(e)),setLocation:_t,setStatusAttributes:e=>Ht(X(e)),setTokens:e=>a()?.setTokens(X(e)??{}),setCommandBarStyle:e=>a()?.commandBar?.setStyle(String(e??"")),setCommandBarPreset:e=>a()?.commandBar?.setPreset(String(e??"")),setCommandPrompt:e=>a()?.commandBar?.setPrompt(String(e??"")),addStylesheet:e=>addExternalStylesheet(String(e)),map:io,transcript:Sn,addPane:(e,t,n)=>ye(String(e),t==null?void 0:String(t),n==null?void 0:String(n)),setPaneContent:(e,t)=>Se(String(e),String(t??"")),setCommands:e=>be(e),setCommandsInExitStrip:e=>{s.commandsInExitStrip=!!e,f()},setAutoScroll:e=>{s.autoScroll=!!e},setContinueOnClick:e=>{s.continueOnClick=!!e},fadePreviousOutput:e=>{s.fadePreviousOutput=!!e,s.fadePreviousOutput||a()?.output?.clearPreviousOutputFade()},setCommandPlaceholder:e=>{s.commandPlaceholder=e==null?null:String(e),a()?.commandBar?.updatePlaceholder()},setMapInteractive:e=>Dt("setInteractive",[e]),lists:oe,on:te,off:ee};function En(e){return(e.dataset.qvName??e.textContent??"").trim()}var Xt=4,tt=8,Lt=class extends HTMLElement{#e=null;connectedCallback(){this.setAttribute("role","menu"),C&&(this.popover="manual"),this.addEventListener("click",this.#n),this.addEventListener("keydown",this.#r)}get isOpen(){return this.#e!==null}toggle(t){if(this.#e===t){this.close();return}let n=(t.dataset.verbs??"").split("/").map(r=>r.trim()).filter(Boolean);if(!n.length)return;this.close({restoreFocus:!1});let o=En(t);this.setAttribute("aria-label",(t.textContent??"").trim()),this.replaceChildren(...n.map(r=>{let i=document.createElement("button");return i.type="button",i.setAttribute("role","menuitem"),i.textContent=r,i.dataset.command=`${r.toLowerCase()} ${o}`,i})),this.#e=t,t.setAttribute("aria-expanded","true"),this.classList.add("qv-open"),C&&this.showPopover(),this.#i(),this.querySelector("button")?.focus({preventScroll:!0}),document.addEventListener("pointerdown",this.#o,!0),window.addEventListener("scroll",this.#s,{passive:!0}),window.addEventListener("resize",this.#s)}close({restoreFocus:t=!0}={}){let n=this.#e;if(!n)return;this.#e=null,n.setAttribute("aria-expanded","false");let o=this.contains(document.activeElement);this.classList.remove("qv-open"),C&&this.matches(":popover-open")&&this.hidePopover(),this.replaceChildren(),document.removeEventListener("pointerdown",this.#o,!0),window.removeEventListener("scroll",this.#s),window.removeEventListener("resize",this.#s),t&&o&&n.isConnected&&n.focus({preventScroll:!0})}closeIfStale(){this.#e&&(!this.#e.isConnected||k(this.#e))&&this.close({restoreFocus:!1})}#t(t){let n=this.#e;if(!n)return;let o=En(n),r={};n.dataset.elementid&&(r[o]=n.dataset.elementid),this.close({restoreFocus:!1}),g(t.dataset.command??"",r)}#n=t=>{let n=t.target instanceof Element?t.target.closest('[role="menuitem"]'):null;n&&this.#t(n)};#r=t=>{let n=[...this.querySelectorAll('[role="menuitem"]')],o=n.indexOf(document.activeElement),r=null;switch(t.key){case"Escape":t.preventDefault(),this.close();return;case"Tab":this.close({restoreFocus:!1});return;case"ArrowDown":r=(o+1)%n.length;break;case"ArrowUp":r=(o-1+n.length)%n.length;break;case"Home":r=0;break;case"End":r=n.length-1;break;default:return}t.preventDefault(),n[r]?.focus()};#o=t=>{let n=t.target instanceof Node?t.target:null;n&&(this.contains(n)||this.#e?.contains(n))||this.close({restoreFocus:!1})};#s=()=>{this.closeIfStale(),this.#e&&this.#i()};#i(){if(!this.#e)return;let t=this.#e.getBoundingClientRect(),{offsetWidth:n,offsetHeight:o}=this,r=t.bottom+Xt;r+o>window.innerHeight-tt&&t.top-Xt-o>=tt&&(r=t.top-Xt-o);let i=Math.max(tt,Math.min(t.left,window.innerWidth-n-tt));this.style.top=`${Math.max(tt,r)}px`,this.style.left=`${i}px`}};customElements.define("qv-player",dt);customElements.define("qv-output",Et);customElements.define("qv-command-bar",vt);customElements.define("qv-verb-menu",Lt);customElements.define("qv-pane",st);customElements.define("qv-more",St);window.QuestUI=yn;window.sendCommand=(e,t)=>{g(e,t)};window.ASLEvent=L;window.canSendCommand=!0;window.notifyQuestUITurn=e=>{let t=a()?.output;e?(w(!1,{restoreFocus:!1}),t?.beginTurn(),t?.setAttribute("aria-busy","true"),y("turnStarted")):(t?.removeAttribute("aria-busy"),y("turnEnded"),a()?.commandBar?.focusInput(),a()?.focusFirstChoice())};window.resetQuestUIState=()=>{ne(),O(),Ke(),Ce(),ke(),re(),ge(),De(),bt()};document.addEventListener("keydown",e=>{!s.waiting||e.repeat||["Tab","Shift","Control","Alt","Meta"].includes(e.key)||e.target instanceof Element&&e.target.closest("input, textarea, select, [contenteditable], dialog")||(e.preventDefault(),Z())});window.addEventListener("beforeunload",e=>{!s.hasUnsavedProgress||!s.canSave||!a()||(e.preventDefault(),e.returnValue="")});document.addEventListener("click",e=>{!s.waiting||!s.continueOnClick||e.target instanceof Element&&e.target.closest("a, button, input, textarea, select, summary, dialog")||Z()});var S=()=>a()?.output;function Ln(){let e=a()?.saveButton;e&&(e.disabled=s.turnPending)}var ao=()=>{},wn={"#gamePanes":"panes","#location":"location","#txtCommandDiv":"command-bar"},lo={addTextAndScroll(e){S()?.addText(e),S()?.scrollToEnd()},createNewDiv:e=>{S()?.setAlignment(e)},bindMenu:(e,t,n,o)=>ce(e,t,o),showMenu:Ze,showQuestion:Xe,beginWait:Ge,setTurnPending(e){s.turnPending=e,Ln(),f()},beginPause:Ye,updateLocation:_t,setGameName(e){document.title=e},clearScreen:()=>S()?.clearScreen(),panesVisible:e=>a()?.setVisible("panes",e),updateStatus:Pe,setBackground:e=>a()?.setTokens({"--qv-bg":e}),setForeground:ao,updateList:ve,updateCompass:Me,updateObjectLinks:e=>a()?.updateLinks("object",e),gameFinished(){s.gameFinished=!0,O(),s.waiting=!1,R("finished",!0),f()},requestNextTimerTick:$e,uiShow:e=>a()?.setVisible(wn[e]??"",!0),uiHide:e=>a()?.setVisible(wn[e]??"",!1),setCompassDirections:Zt,setInterfaceString:Jt,setPanelContents:yt,loadHtml:e=>S()?.loadHtml(e),markScrollPosition:()=>S()?.markScrollPosition(),scrollToEnd:()=>S()?.scrollToEnd(),requestSave(){GameSaver.saveRequested()},start(){a()?.saveButton?.addEventListener("click",()=>{WebPlayer.onSaveClick?WebPlayer.onSaveClick():GameSaver.save()}),Ln(),B(),$(),a()?.commandBar?.focusInput()},resetOutput(){S()?.reset(),O(),s.hasUnsavedProgress=!1},useManualClock:je,getOutputHtml:()=>S()?.getHtml()??"",getLocation:()=>a()?.location?.textContent?.trim()??"",getOutputElement:()=>S()??null,gameSaved(){S()?.addText(`<span data-qv-save-notice>${WebPlayer.chromeStrings?.GameSaved??"Game saved."}<br></span>`),s.hasUnsavedProgress=!1},clearUnsavedProgress(){s.hasUnsavedProgress=!1},setCanSave(e){s.canSave=e},waitEnded:$t,pauseEnded:jt,dismissPrompt:_e,beginSoundWait(){let e=!a()?.commandBar?.hidden;return s.soundWait=!0,R("sound",!0),e},endSoundWait(){s.soundWait=!1,setTimeout(async()=>{R("sound",!1),await WebPlayer.uiEndWait()},100)},rememberImageSize:gn,setAnimateScroll(e){s.animateScroll=e}};window.QuestPlayerUis=window.QuestPlayerUis??{};window.QuestPlayerUis.v2=lo;})();
package/wasm-player.js CHANGED
@@ -367,6 +367,7 @@ function stageAdjacentFiles(files) {
367
367
  function ui_init() { }
368
368
 
369
369
  function sendEndWait() {
370
+ window.QuestGamepad?.endWait();
370
371
  // The short delay lets the browser paint endWait()'s hidden Continue link
371
372
  // before the engine resumes and (in the WASM build, which runs it on the
372
373
  // one UI thread) blocks painting for the rest of the turn.
@@ -790,6 +791,7 @@ window.WebPlayer = {
790
791
  },
791
792
 
792
793
  setCanSave(value) {
794
+ currentCanSave = value;
793
795
  const cmdSave = document.getElementById("cmdSave");
794
796
  if (cmdSave) cmdSave.style.display = value ? "initial" : "none";
795
797
  playerUi.setCanSave(value);
@@ -842,12 +844,18 @@ window.WebPlayer = {
842
844
  return Bridge.GetSaveGameBytes();
843
845
  },
844
846
 
847
+ // The game's reason for refusing a save right now (game.cansave false), or null.
848
+ saveRefusal() {
849
+ return Bridge?.GetSaveRefusal?.() ?? null;
850
+ },
851
+
845
852
  };
846
853
 
847
854
  // One engine round trip started by the player, bracketed for QuestUI's turnStarted/turnEnded
848
855
  // events (legacy/questui.js).
849
856
  async function playerTurn(run) {
850
857
  window.notifyQuestUITurn?.(true);
858
+ window.QuestGamepad?.markTurnStart();
851
859
  turnsInFlight++;
852
860
  try {
853
861
  // A live interface change being applied finishes first (applyInterfaceChanges).
@@ -866,6 +874,30 @@ async function playerTurn(run) {
866
874
  // change waits for both to be over.
867
875
  let turnsInFlight = 0;
868
876
  let turnPending = false;
877
+ let currentCanSave = false;
878
+
879
+ // A game controller (gamepad.js): what it needs of the host.
880
+ window.QuestGamepad?.attach({
881
+ sendCommand(text) {
882
+ if (typeof window.sendCommand === 'function') window.sendCommand(text);
883
+ },
884
+ commandWord(name) {
885
+ try {
886
+ return Bridge?.GetCommandWord(name) ?? '';
887
+ } catch {
888
+ return '';
889
+ }
890
+ },
891
+ outputElement: () => playerUi?.getOutputElement() ?? null,
892
+ // The controller menu's Saved games button, which works as the Save / Load button does: not
893
+ // mid-turn, and not at all where saving is turned off.
894
+ savedGames() {
895
+ if (!currentCanSave || !WebPlayer.onSaveClick) return 'off';
896
+ return turnPending || turnsInFlight > 0 ? 'busy' : 'ready';
897
+ },
898
+ openSavedGames: () => WebPlayer.onSaveClick?.(),
899
+ chromeString: (key, fallback) => WebPlayer.chromeStrings?.[key] ?? fallback,
900
+ });
869
901
 
870
902
  // Whoever is waiting for the turn to be over (whenTurnOver): a save a game's script asks for waits
871
903
  // until then, so it has the whole turn rather than however much had run when it was asked for.
@@ -988,7 +1020,7 @@ function setGameStylesheet(css) {
988
1020
  // ── Player UIs ──────────────────────────────────────────────────────────────
989
1021
  //
990
1022
  // Each player UI is a bundle of markup (swapped into the page for each game and restart),
991
- // stylesheets and classic scripts, loaded only once a game needs it: the legacy UI (today's, frozen) and v2 (docs/ui-v2-plan.md). The last script
1023
+ // stylesheets and classic scripts, loaded only once a game needs it: the legacy UI (today's, frozen) and v2 (docs/archive/ui-v2-plan.md). The last script
992
1024
  // registers the UI's adapter as window.QuestPlayerUis[name], which is the only way the host
993
1025
  // talks to it. Paths are relative to this page and get the ?v= cache key.
994
1026
  const playerUiBundles = {
@@ -1130,6 +1162,8 @@ function swapInPlayerUi() {
1130
1162
  const debuggerDialogEl = document.getElementById('questVivaDebugger');
1131
1163
  const restartingEl = document.getElementById('qv-restarting');
1132
1164
  const recordingEl = document.getElementById('qv-recording');
1165
+ const controllerEls = ['qv-controller-menu', 'qv-controller-help', 'qv-controller-toast']
1166
+ .map(id => document.getElementById(id)).filter(Boolean);
1133
1167
  startScreenEl?.remove();
1134
1168
  savesDialogEl?.remove();
1135
1169
  debuggerDialogEl?.remove();
@@ -1143,6 +1177,7 @@ function swapInPlayerUi() {
1143
1177
  if (debuggerDialogEl) document.body.appendChild(debuggerDialogEl);
1144
1178
  if (restartingEl) document.body.appendChild(restartingEl);
1145
1179
  if (recordingEl) document.body.appendChild(recordingEl);
1180
+ for (const el of controllerEls) document.body.appendChild(el);
1146
1181
  // This is a genuinely fresh chrome (see above) — addExternalScript's
1147
1182
  // dedupe-by-URL must not carry over, or the game's external
1148
1183
  // scripts silently no-op against it on the very next Initialise() call
@@ -1231,6 +1266,7 @@ function preloadRuntime() {
1231
1266
  async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null, isPreview = false, recordWalkthrough = null, runWalkthrough = null, adjacentFiles = null, allowDebug = false) {
1232
1267
  currentIsPreview = isPreview;
1233
1268
  currentAllowDebug = allowDebug;
1269
+ window.QuestGamepad?.reset();
1234
1270
  prefetchPlayerUi(playerUiOverride() ?? (isPreview ? 'v2' : 'legacy'));
1235
1271
  const builder = await loadRuntimeBuilder();
1236
1272
  const runtime = await builder.create();
@@ -1244,13 +1280,20 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1244
1280
  bindMenu: (linkId, verbs, text, elementId) => playerUi.bindMenu(linkId, verbs, text, elementId),
1245
1281
  showMenu: (caption, optionsJson, allowCancel) => playerUi.showMenu(caption, JSON.parse(optionsJson), allowCancel),
1246
1282
  showQuestion: (caption) => playerUi.showQuestion(caption),
1247
- beginWait: () => playerUi.beginWait(),
1283
+ beginWait: () => {
1284
+ window.QuestGamepad?.beginWait();
1285
+ playerUi.beginWait();
1286
+ },
1248
1287
  setTurnPending: (pending) => {
1249
1288
  turnPending = pending;
1250
1289
  playerUi.setTurnPending(pending);
1251
1290
  if (!pending) scheduleInterfaceChanges();
1252
1291
  },
1253
1292
  beginPause: (ms) => whenClockRuns(() => playerUi.beginPause(ms)),
1293
+ dismissPrompt: () => {
1294
+ window.QuestGamepad?.endWait();
1295
+ playerUi.dismissPrompt();
1296
+ },
1254
1297
  updateLocation: (loc) => playerUi.updateLocation(loc),
1255
1298
  setGameName: (name) => {
1256
1299
  currentGameName = name;
@@ -1263,7 +1306,10 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1263
1306
  setBackground: (colour) => playerUi.setBackground(colour),
1264
1307
  setForeground: (colour) => playerUi.setForeground(colour),
1265
1308
  updateList: (listName, itemsJson) => playerUi.updateList(listName, JSON.parse(itemsJson)),
1266
- updateCompass: (data) => playerUi.updateCompass(data),
1309
+ updateCompass: (data) => {
1310
+ window.QuestGamepad?.updateCompass(data);
1311
+ playerUi.updateCompass(data);
1312
+ },
1267
1313
  updateObjectLinks: (verbsJson) => playerUi.updateObjectLinks(JSON.parse(verbsJson)),
1268
1314
  gameFinished: () => playerUi.gameFinished(),
1269
1315
  requestNextTimerTick: (seconds) => whenClockRuns(() => playerUi.requestNextTimerTick(seconds)),
@@ -1284,7 +1330,11 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1284
1330
  try { globalEval(call); } catch (e) { console.error(e); }
1285
1331
  },
1286
1332
  jsYield: () => new Promise(resolve => setTimeout(resolve, 0)),
1287
- setCompassDirections: (dirsJson) => playerUi.setCompassDirections(JSON.parse(dirsJson)),
1333
+ setCompassDirections: (dirsJson) => {
1334
+ const directions = JSON.parse(dirsJson);
1335
+ window.QuestGamepad?.setCompassDirections(directions);
1336
+ playerUi.setCompassDirections(directions);
1337
+ },
1288
1338
  setInterfaceString: (name, text) => playerUi.setInterfaceString(name, text),
1289
1339
  setPanelContents: (html) => playerUi.setPanelContents(html),
1290
1340
  consoleError: (msg) => console.error('[Quest]', msg),
@@ -1375,11 +1425,11 @@ async function initWasmPlayer(gameBytes, filename, bc = null, saveBytes = null,
1375
1425
  // BroadcastChannel (to hand off the picked file's bytes and answer
1376
1426
  // resource requests) but is a real play session and should offer saving.
1377
1427
  WebPlayer.setCanSave(!isPreview);
1378
- // Shown in editor-preview sessions, and also in a source=local play
1379
- // session for a raw .aslx file specifically (allowDebug — see the
1380
- // source=local boot branch below, which is the only caller that ever
1381
- // passes it true) — never for any other normal play session, even
1382
- // though the loaded game itself might have DebugEnabled true.
1428
+ // Shown in editor-preview sessions, and also in a play session for a raw
1429
+ // .aslx file specifically (allowDebug — passed by the source=local,
1430
+ // source=qv and ?url= boot branches below) — never for any other normal
1431
+ // play session, even though the loaded game itself might have
1432
+ // DebugEnabled true.
1383
1433
  WebPlayer.setCanDebug((isPreview || allowDebug) && Bridge.IsDebugEnabled());
1384
1434
 
1385
1435
  // The game's start runs behind the start screen, so a sound it plays can wait for a click
@@ -1932,10 +1982,27 @@ let renamingSave = null;
1932
1982
  let currentSaves = [];
1933
1983
 
1934
1984
  async function refreshSavesList(mode = 'manage') {
1985
+ updateSaveRefusal();
1935
1986
  currentSaves = await listSavesOrReportBlocked(WebPlayer.gameId);
1936
1987
  renderSavesList(currentSaves, mode);
1937
1988
  }
1938
1989
 
1990
+ // A game can refuse saves for a while (game.cansave false), for example while the player is in a
1991
+ // dungeon. The dialog then hides what would make a new save and says why, but loading stays (#3026).
1992
+ // Returns whether saving is refused.
1993
+ function updateSaveRefusal() {
1994
+ const dlg = document.getElementById('qv-saves');
1995
+ const refusal = WebPlayer.saveRefusal();
1996
+ const notice = document.getElementById('qv-saves-refused');
1997
+ if (refusal) {
1998
+ dlg.dataset.saveRefused = '';
1999
+ if (notice) notice.textContent = refusal;
2000
+ } else {
2001
+ delete dlg.dataset.saveRefused;
2002
+ }
2003
+ return !!refusal;
2004
+ }
2005
+
1939
2006
  // Lists the game's saves, or, when the browser won't open IndexedDB at all (a Firefox private
1940
2007
  // window, all site data blocked, a privacy add-on), says in the dialog that saving here isn't
1941
2008
  // available and hides the Save form, instead of the dialog failing to open. Save to file and Load
@@ -1978,6 +2045,7 @@ function downloadSaveBytes(bytes) {
1978
2045
  }
1979
2046
 
1980
2047
  async function downloadSaveToFile() {
2048
+ if (updateSaveRefusal()) return;
1981
2049
  const bytes = await WebPlayer.uiSaveGame(GameSaver.outputHtmlForSave());
1982
2050
  downloadSaveBytes(bytes);
1983
2051
  playerUi.clearUnsavedProgress();
@@ -2088,7 +2156,7 @@ function ensureSavesDialogWired() {
2088
2156
  (cs().OverwriteSaveConfirm ?? 'Overwrite "[name]"?').replace('[name]', saveTitle(slotIndex)),
2089
2157
  cs().OverwriteSave ?? 'Overwrite');
2090
2158
  if (!ok) { opener?.focus(); return; }
2091
- await GameSaver.overwrite(slotIndex);
2159
+ if (!await GameSaver.overwrite(slotIndex)) { await refreshSavesList(); return; }
2092
2160
  await refreshSavesList();
2093
2161
  document.querySelector(`#qv-saves-list [data-slot="${slotIndex}"]`)?.focus();
2094
2162
  } else if (action === 'rename') {
@@ -2135,10 +2203,12 @@ function ensureSavesDialogWired() {
2135
2203
  e.preventDefault();
2136
2204
  const input = document.getElementById('qv-saves-name-input');
2137
2205
  const button = document.getElementById('qv-saves-save-new');
2206
+ let saved = null;
2138
2207
  await withBusyButton(button, cs().SavingBusy ?? 'Saving…', async () => {
2139
- await GameSaver.save(input.value.trim() || undefined);
2208
+ saved = await GameSaver.save(input.value.trim() || undefined);
2140
2209
  });
2141
- input.value = '';
2210
+ // Not saved: the game started refusing saves while the dialog was open.
2211
+ if (saved) input.value = '';
2142
2212
  await refreshSavesList();
2143
2213
  });
2144
2214
 
@@ -2217,6 +2287,7 @@ async function openSavesDialog(mode, gameId = WebPlayer.gameId) {
2217
2287
  saveMenu.hidePopover();
2218
2288
  }
2219
2289
  dlg.dataset.mode = mode;
2290
+ updateSaveRefusal();
2220
2291
  dlg.setAttribute('aria-labelledby', mode === 'boot' ? 'qv-saves-heading-boot' : 'qv-saves-heading-manage');
2221
2292
  currentSaves = await listSavesOrReportBlocked(gameId);
2222
2293
  renderSavesList(currentSaves, mode);
@@ -3027,6 +3098,39 @@ function showFileProtocolError() {
3027
3098
  errorEl.style.display = 'block';
3028
3099
  }
3029
3100
 
3101
+ // The .NET runtime this player is built on can't start in Safari 17 or older, on Mac or iOS:
3102
+ // JavaScriptCore there fails to parse its scripts, and the load mostly hangs with nothing shown
3103
+ // (#3153). Every browser on iOS is WebKit underneath, so there the iOS version is what counts;
3104
+ // on a Mac it's Safari's own version (Chrome, Edge and Firefox bring their own engines). Returns
3105
+ // a short name for the browser, such as "Safari 17" or "iOS 16", or null when it's fine.
3106
+ function unsupportedWebKit(ua = navigator.userAgent) {
3107
+ const ios = /(?:iPhone|iPad|iPod).* OS (\d+)_/.exec(ua);
3108
+ if (ios) return Number(ios[1]) < 18 ? `iOS ${ios[1]}` : null;
3109
+ // A Mac, or an iPad asking for desktop sites, which reports Safari's version the same way.
3110
+ if (!ua.includes('Macintosh') || /Chrome|Chromium|CriOS|FxiOS|Firefox|Edg|Electron/.test(ua)) return null;
3111
+ const safari = /Version\/(\d+)[.\d]* (?:Mobile\/\S+ )?Safari\//.exec(ua);
3112
+ return safari && Number(safari[1]) < 18 ? `Safari ${safari[1]}` : null;
3113
+ }
3114
+
3115
+ function showUnsupportedBrowserError() {
3116
+ document.documentElement.classList.remove('qv-booting');
3117
+ const pickers = document.getElementById('qv-pickers');
3118
+ const msg = document.getElementById('qv-loading-msg');
3119
+ const errorEl = document.getElementById('qv-error');
3120
+ if (msg) msg.style.display = 'none';
3121
+ if (pickers) pickers.style.display = 'none';
3122
+ if (!errorEl) return;
3123
+ const isIos = /iPhone|iPad|iPod/.test(navigator.userAgent)
3124
+ || (navigator.userAgent.includes('Macintosh') && navigator.maxTouchPoints > 1);
3125
+ errorEl.innerHTML = '<strong>This browser is too old to play Quest games.</strong> '
3126
+ + (isIos
3127
+ ? 'Please update your iPhone or iPad to iOS 18 or later (in Settings, General, Software Update), '
3128
+ : 'Please update Safari to version 18 or later (macOS updates it through System Settings, '
3129
+ + 'General, Software Update), or use another browser such as Chrome, Edge or Firefox, ')
3130
+ + 'then open this page again.';
3131
+ errorEl.style.display = 'block';
3132
+ }
3133
+
3030
3134
  // The AppShell tab that was going to hand over game bytes (see the
3031
3135
  // `source=local` boot branch below) turned out not to be there to answer —
3032
3136
  // closed, navigated away, or superseded by a newer Start click in that same
@@ -3293,6 +3397,21 @@ async function fetchGameBytes(url) {
3293
3397
  return;
3294
3398
  }
3295
3399
 
3400
+ // Before anything starts downloading: the runtime won't start here anyway. For a game from
3401
+ // textadventures.co.uk, still report it as failed, so these loads show up in its data.
3402
+ const unsupported = unsupportedWebKit();
3403
+ if (unsupported) {
3404
+ const id = new URLSearchParams(window.location.search).get('id');
3405
+ if (id) {
3406
+ const apiRoot = window.QuestVivaConfig?.textAdventuresApiRoot
3407
+ ?? 'https://textadventures.co.uk/api/';
3408
+ progressUrl = `${apiRoot}gameprogress/${encodeURIComponent(id)}`;
3409
+ reportProgress('failed', `Unsupported browser: ${unsupported}`);
3410
+ }
3411
+ document.addEventListener('DOMContentLoaded', showUnsupportedBrowserError);
3412
+ return;
3413
+ }
3414
+
3296
3415
  // Single-file export (see PlayerExport in src/PlayerCore): the game bytes are
3297
3416
  // inlined as base64 by a <script> tag before this one, so there's nothing
3298
3417
  // to fetch at all — decode and hand straight to the same startGame() every
@@ -3470,7 +3589,10 @@ async function fetchGameBytes(url) {
3470
3589
  showLoading();
3471
3590
  try {
3472
3591
  const { bytes, filename } = await gamePromise;
3473
- await startGame(bytes, filename);
3592
+ // An .aslx is an author's source file, so Debug is on for it as for source=local
3593
+ // and source=qv; a published .quest, .asl or .cas gets none.
3594
+ await startGame(bytes, filename, null, null, false, null, null, null,
3595
+ /\.aslx$/i.test(filename));
3474
3596
  } catch (err) {
3475
3597
  showError(gameUrl, false, err);
3476
3598
  }