latest changes before manual submissions redesign

This commit is contained in:
Joren de Graaf
2026-10-06 19:31:30 +02:00
parent 46ad514a70
commit c13a405d96
124 changed files with 1023 additions and 112 deletions
+1
View File
@@ -3,6 +3,7 @@ import "../styles/pages/fireworks-home.css";
import "../styles/pages/map.css";
import "../styles/pages/dashboard.css";
import "../styles/components/burst-listener.css";
import "../styles/components/manual-compass.css";
import "../styles/theme.css";
import "../scripts/theme.js";
import "../scripts/manual-report.js";
+1
View File
@@ -1,5 +1,6 @@
import "../styles/pages/home.css";
import "../styles/components/burst-listener.css";
import "../styles/components/manual-compass.css";
import "../styles/theme.css";
import "../scripts/theme.js";
import "../scripts/manual-report.js";
+1
View File
@@ -1,4 +1,5 @@
import "../styles/pages/settings.css";
import "../styles/components/fireworks-navigation.css";
import "../styles/theme.css";
import "../scripts/theme.js";
import "../scripts/user-settings.js";
+26
View File
@@ -11,11 +11,15 @@
const captureDirectionButton = document.querySelector("#manual-capture-direction");
const directionStatus = document.querySelector("#manual-direction-status");
const directionPanel = document.querySelector("#manual-direction-panel");
const compass = document.querySelector("#manual-compass");
const compassRose = document.querySelector("#manual-compass-rose");
const compassHeading = document.querySelector("#manual-compass-heading");
const isMobileDevice = /Android|iPhone|iPad|iPod|IEMobile|Opera Mini/.test(navigator.userAgent)
|| (navigator.userAgent.includes("Macintosh") && navigator.maxTouchPoints > 1);
if (isMobileDevice) directionPanel.hidden = false;
let orientationListener;
let compassUnavailableTimeout;
let compassRotation = null;
const burstListener = createBurstListener();
const isUsableNumber = (value) => Number.isFinite(value);
@@ -27,6 +31,27 @@
window.clearTimeout(compassUnavailableTimeout);
orientationListener = null;
compassUnavailableTimeout = null;
compass.hidden = true;
compassRotation = null;
};
const updateCompass = (heading) => {
const targetRotation = -heading;
if (compassRotation === null) {
compassRotation = targetRotation;
compassRose.style.transition = "none";
compassRose.style.transform = `rotate(${compassRotation}deg)`;
// Restore the short rotation animation after the initial reading.
compassRose.offsetWidth;
compassRose.style.transition = "";
} else {
const change = ((targetRotation - compassRotation + 540) % 360) - 180;
compassRotation += change;
compassRose.style.transform = `rotate(${compassRotation}deg)`;
}
compassHeading.textContent = `${displayDegrees(heading)}° · ${cardinalDirection(heading)}`;
compass.setAttribute("aria-label", `${t.compassDirection || "Compass direction"} ${displayDegrees(heading)}° ${cardinalDirection(heading)}`);
compass.hidden = false;
};
const showCapturedDirection = (heading, accuracy) => {
@@ -53,6 +78,7 @@
directionDegrees.value = heading;
directionAccuracy.value = accuracy === null ? "" : accuracy;
showCapturedDirection(heading, accuracy);
updateCompass(heading);
window.clearTimeout(compassUnavailableTimeout);
};
window.addEventListener("deviceorientation", orientationListener);
+10 -1
View File
@@ -1 +1,10 @@
document.querySelector("#ntfy-url").addEventListener("input", () => { document.querySelector("#ntfy-test-result").replaceChildren(); });
document.querySelector("#ntfy-url")?.addEventListener("input", () => {
document.querySelector("#ntfy-test-result")?.replaceChildren();
});
document.addEventListener("click", async (event) => {
const button = event.target.closest("[data-copy-sensor-token]");
if (!button) return;
const token = document.querySelector("#sensor-token")?.textContent;
if (token) await navigator.clipboard.writeText(token);
});
@@ -37,7 +37,8 @@
background: #111a31d9;
box-shadow: 0 .5rem 1.5rem #03071440;
}
.fireworks-nav a {
.fireworks-nav a,
.fireworks-nav button {
padding: .5rem .75rem;
border-radius: .5rem;
color: var(--muted, var(--m, #aab9d8));
@@ -45,7 +46,10 @@
font-weight: 750;
text-decoration: none;
}
.fireworks-nav a:hover { color: var(--ink, var(--i, #eef3ff)); background: #20345f; }
.fireworks-nav form { display: flex; margin: 0; }
.fireworks-nav button { border: 0; background: transparent; font: inherit; cursor: pointer; }
.fireworks-nav a:hover,
.fireworks-nav button:hover { color: var(--ink, var(--i, #eef3ff)); background: #20345f; }
.fireworks-nav a[aria-current="page"] { color: var(--ink, var(--i, #eef3ff)); background: #2a3b67; }
.theme-toggle--inline {
position: static;
@@ -59,8 +63,10 @@
background: #edf4ff;
box-shadow: 0 .45rem 1.25rem rgba(34, 68, 117, .12);
}
:root[data-theme="light"] .fireworks-nav a { color: #47617f; }
:root[data-theme="light"] .fireworks-nav a:hover { color: #234a7b; background: #dceaff; }
:root[data-theme="light"] .fireworks-nav a,
:root[data-theme="light"] .fireworks-nav button { color: #47617f; }
:root[data-theme="light"] .fireworks-nav a:hover,
:root[data-theme="light"] .fireworks-nav button:hover { color: #234a7b; background: #dceaff; }
:root[data-theme="light"] .fireworks-nav a[aria-current="page"] {
color: #173d6a;
background: #cfe3ff;
@@ -89,6 +95,10 @@
.fireworks-header__controls { display: none; flex-basis: 100%; width: 100%; flex-direction: column; align-items: stretch; }
.fireworks-menu-toggle[aria-expanded="true"] ~ .fireworks-header__controls { display: flex; }
.fireworks-nav { flex-direction: column; }
.fireworks-nav a { padding: .75rem; }
.fireworks-nav a,
.fireworks-nav button { padding: .75rem; }
.fireworks-nav form,
.fireworks-nav button { width: 100%; }
.fireworks-nav button { text-align: left; }
.theme-toggle--inline { width: 100%; }
}
@@ -0,0 +1,55 @@
.manual-compass {
display: grid;
justify-items: center;
width: 7rem;
margin: .6rem 0 0 auto;
color: #fff3d7;
font-size: .78rem;
font-weight: 850;
font-variant-numeric: tabular-nums;
}
.manual-compass[hidden] { display: none; }
.manual-compass__dial {
position: relative;
width: 5.75rem;
aspect-ratio: 1;
border: 2px solid #f2d7a8;
border-radius: 50%;
background: radial-gradient(circle, #342441 0 28%, #211a32 75%);
box-shadow: 0 .35rem 1rem #09061566, inset 0 0 0 .25rem #ffffff12;
}
.manual-compass__rose { position: absolute; inset: 0; transition: transform 120ms ease-out; }
.manual-compass__rose span { position: absolute; line-height: 1; }
.manual-compass__north { top: .38rem; left: 50%; color: #ff9e78; transform: translateX(-50%); }
.manual-compass__east { right: .47rem; top: 50%; transform: translateY(-50%); }
.manual-compass__south { bottom: .38rem; left: 50%; transform: translateX(-50%); }
.manual-compass__west { left: .47rem; top: 50%; transform: translateY(-50%); }
.manual-compass__pointer {
position: absolute;
top: -.55rem;
left: 50%;
width: 0;
height: 0;
border-right: .37rem solid transparent;
border-bottom: .65rem solid #ffbd62;
border-left: .37rem solid transparent;
transform: translateX(-50%);
filter: drop-shadow(0 .1rem .15rem #160d1b);
}
.manual-compass__center {
position: absolute;
top: 50%;
left: 50%;
width: .5rem;
aspect-ratio: 1;
border-radius: 50%;
background: #ffbd62;
transform: translate(-50%, -50%);
}
.manual-compass__heading { margin-top: .5rem; white-space: nowrap; }
:root[data-theme="light"] .manual-compass { color: #43243d; }
:root[data-theme="light"] .manual-compass__dial { border-color: #996a9b; background: radial-gradient(circle, #f8ebf8 0 28%, #e8d7e9 75%); }
:root[data-theme="light"] .manual-compass__east,
:root[data-theme="light"] .manual-compass__south,
:root[data-theme="light"] .manual-compass__west { color: #43243d; }
@media (prefers-reduced-motion: reduce) { .manual-compass__rose { transition: none; } }
+51 -11
View File
@@ -1,11 +1,51 @@
body{min-width:320px;margin:0;padding:2rem;color:#eef3ff;font-family:Inter,system-ui,sans-serif;background:#090e1d}.card{width:min(100%,42rem);margin:auto;padding:2rem;border:1px solid #2b3d68;border-radius:1rem;background:#172443}h1{margin-top:0}h2{margin:0}.intro,.help{color:#aab9d8;line-height:1.5}.section{margin-top:2rem;padding-top:1.5rem;border-top:1px solid #2b3d68}label{display:block;margin:.9rem 0 .35rem;font-weight:700}input[type=url]{width:100%;min-height:2.8rem;padding:.65rem;border:1px solid #526b9f;border-radius:.55rem;color:#eef3ff;font:inherit;background:#0a1123}.check{display:flex;gap:.6rem;align-items:center}.check label{margin:0}.button{min-height:2.8rem;margin-top:1rem;padding:.6rem 1rem;border:0;border-radius:.55rem;color:#17132b;font:inherit;font-weight:800;background:#a6ccff;cursor:pointer}.button--secondary{margin-right:.7rem;background:#d8c1fb}.alert,.errorlist{margin-top:1rem;padding:.75rem;border-radius:.55rem}.alert--success{color:#d1fae5;background:#14532d}.alert--error,.errorlist{color:#fee2e2;background:#7f1d1d}.messages{padding:0;list-style:none}@media(max-width:32rem){body{padding:1rem}.card{padding:1.4rem}}
.sensor-card{margin:1rem 0;padding:1rem;border:1px solid var(--theme-line);border-radius:.7rem;background:var(--theme-surface-raised)}
.sensor-card p{margin:.5rem 0;color:var(--theme-muted)}
.sensor-card .button{display:inline-block;text-decoration:none}
.sensor-status{display:inline-block;margin-left:.5rem;color:#ef4444;font-weight:700}
.sensor-status--online{color:#22c55e}.sensor-status--delayed{color:#f59e0b}
input[type=text]{box-sizing:border-box;width:100%;min-height:2.8rem;padding:.65rem;border:1px solid var(--theme-line);border-radius:.55rem;color:var(--theme-ink);font:inherit;background:var(--theme-input)}
.token-once{margin:1rem 0;padding:1rem;border:1px solid #f59e0b;border-radius:.7rem;background:var(--theme-surface-raised)}
.token-once code{display:block;overflow-wrap:anywhere;margin-top:.7rem;padding:.7rem;border-radius:.4rem;background:var(--theme-input);user-select:all}
.button--danger{color:#fff;background:#991b1b}
:root[data-theme=light] .sensor-status:not(.sensor-status--online):not(.sensor-status--delayed){color:#b91c1c}
/* Settings cards follow the shared blue and violet theme. */
*{box-sizing:border-box}
body{min-height:100vh;padding:0;color:var(--theme-ink);background:var(--theme-bg)}
.settings-shell{width:min(100% - 3.5rem,73.75rem);margin:auto;padding:4rem 0 5rem}
.settings-content{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:2.25rem 2rem;width:100%}
.settings-heading,.messages{grid-column:1/-1}
.settings-heading{margin-bottom:0}
.eyebrow{margin:0 0 .7rem;color:#9fc5ff;font-size:.74rem;font-weight:800;letter-spacing:.1em;text-transform:uppercase}
h1,h2{font-family:Georgia,ui-serif,serif;font-weight:700}
h1{margin:0;font-size:clamp(2.3rem,4vw,3.5rem);letter-spacing:-.045em;line-height:1.12}
h2{margin:0 0 .45rem;font-size:1.5rem;letter-spacing:-.02em}
.intro,.help{margin:.45rem 0 0;color:var(--theme-muted);line-height:1.55}
.card{min-width:0;width:100%;margin:0;padding:1.75rem;border:1px solid var(--theme-line);border-radius:1.125rem;background:var(--theme-surface);box-shadow:0 1.125rem 2.8rem #02071429}
.settings-form{display:flex;flex-direction:column;gap:1rem}.settings-form h2+.field{margin-top:.4rem}
.settings-form>.button[type=submit]{margin-top:auto}
.field label{display:block;margin:0 0 .375rem;font-size:.85rem;font-weight:700}
.field input,.field select{display:block;width:100%;min-height:2.625rem;padding:.55rem .625rem;border:1px solid var(--theme-line);border-radius:.56rem;color:var(--theme-ink);background:var(--theme-input);font:inherit}
.field input:focus-visible,.field select:focus-visible,.button:focus-visible,.switch-control input:focus-visible+.switch-track{outline:3px solid #80b6ff;outline-offset:3px}
.errorlist{margin:.5rem 0 0;padding:.7rem .9rem;border-radius:.55rem;color:#fee2e2;background:#7f1d1d}
.button{display:inline-flex;align-items:center;justify-content:center;width:100%;min-height:2.875rem;margin:0;padding:.65rem 1.2rem;border:1px solid transparent;border-radius:999px;color:#111c30;background:#a6ccff;font:inherit;font-size:.9rem;font-weight:800;text-align:center;text-decoration:none;cursor:pointer;transition:transform .16s ease,box-shadow .16s ease,background .16s ease}
.button:hover{transform:translateY(-1px);background:#c0ddff;box-shadow:0 .45rem 1rem #5899f733}
.button--secondary{border-color:#6386bd;color:#d7e8ff;background:#223755}.button--secondary:hover{color:#111c30;background:#a6ccff}
.switch-row{display:flex;align-items:center;justify-content:space-between;gap:1.125rem;min-height:4.375rem;padding:.8rem 1rem;border:1px solid #3d5879;border-radius:.94rem;background:#1a2a43;cursor:pointer}
.switch-row:hover{border-color:#739ad0;background:#203554}.switch-copy{display:grid;gap:.2rem;min-width:0}.switch-copy strong{font-size:.92rem}.switch-copy small{color:var(--theme-muted);font-size:.77rem;line-height:1.35}
.switch-control{position:relative;display:block;flex:0 0 3.1875rem;width:3.1875rem;height:1.9375rem}.switch-control input{position:absolute;width:100%;height:100%;margin:0;opacity:0;cursor:pointer}.switch-track{display:block;width:100%;height:100%;border-radius:999px;background:#62758b;pointer-events:none;transition:background .16s ease}
.switch-track::after{content:"";position:absolute;top:2px;left:2px;width:27px;height:27px;border-radius:50%;background:#fff;box-shadow:0 1px 4px #0004;transition:transform .16s ease}.switch-control input:checked+.switch-track{background:#34c76a}.switch-control input:checked+.switch-track::after{transform:translateX(20px)}
.messages{margin:0;padding:0;list-style:none}.alert{margin:.5rem 0 0;padding:.75rem 1rem;border-radius:.65rem;line-height:1.45}#ntfy-test-result:empty{display:none}
.sensor-list__intro{padding-bottom:1.25rem;border-bottom:1px solid var(--theme-line)}.sensor-list__intro .eyebrow{margin-bottom:.35rem}
.sensor-list{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem;margin:1.5rem 0}.sensor-card{display:flex;flex-direction:column;min-width:0;margin:0;padding:1.3rem;border:1px solid var(--theme-line);border-radius:1rem;background:var(--theme-surface-raised)}
.sensor-card__heading{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:.5rem 1rem}.sensor-card__heading h3{margin:0;font-family:Georgia,ui-serif,serif;font-size:1.25rem;overflow-wrap:anywhere}.sensor-card .sensor-status{display:inline-flex;padding:.32rem .65rem;border-radius:999px;background:var(--theme-input);font-size:.78rem;white-space:nowrap}
.sensor-status{color:var(--theme-muted);font-weight:700}.sensor-status--online{color:#64dca0}.sensor-status--delayed{color:#f5c46b}.sensor-status--offline{color:#f49aa7}
.sensor-access{align-self:flex-start;margin-top:.7rem;padding:.25rem .55rem;border:1px solid #3d806b;border-radius:999px;color:#8be0b9;font-size:.72rem;font-weight:800}.sensor-access--off{border-color:#806b75;color:#d4b9c5}
.sensor-card__facts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:.8rem 1rem;margin:1.3rem 0}.sensor-card__facts div{min-width:0}.sensor-card__facts dt{margin-bottom:.25rem;color:var(--theme-muted);font-size:.75rem;font-weight:700}.sensor-card__facts dd{margin:0;font-size:.88rem;font-weight:600;overflow-wrap:anywhere}.sensor-card__facts code{font:inherit}.sensor-card__facts div:last-child{grid-column:1/-1}
.sensor-card .button{margin-top:auto}.sensor-empty{grid-column:1/-1;margin:0;padding:1.5rem;border:1px dashed var(--theme-line);border-radius:1rem;color:var(--theme-muted);text-align:center;line-height:1.5}
.sensor-form{margin-top:1.5rem;padding:1.3rem;border:1px dashed #6386bd;border-radius:1rem;background:var(--theme-surface-raised)}.sensor-form h3{margin:0;font-family:Georgia,ui-serif,serif;font-size:1.2rem}.sensor-form .help{margin-top:.3rem}.sensor-form__controls{display:grid;grid-template-columns:minmax(0,1fr) 11rem;align-items:end;gap:1rem}
.settings-content>#sensor-card{grid-column:1/-1}
.sensor-detail__header{display:flex;align-items:start;justify-content:space-between;gap:1rem;padding-bottom:1.2rem;border-bottom:1px solid var(--theme-line)}.sensor-detail__header .eyebrow{margin-bottom:.35rem}.sensor-detail__header h2{margin:0;font-size:clamp(1.6rem,3vw,2rem);overflow-wrap:anywhere}.sensor-close{display:inline-flex;align-items:center;gap:.35rem;flex:none;padding:.45rem .85rem;border:1px solid var(--theme-line);border-radius:999px;color:var(--theme-ink);background:var(--theme-surface-raised);font-size:.85rem;font-weight:700;text-decoration:none}.sensor-close:hover{border-color:#86ade0;background:#2b4266}.sensor-close:focus-visible{outline:3px solid #80b6ff;outline-offset:3px}
.sensor-detail__overview{margin:1.25rem 0 1.5rem;padding:1.2rem;border:1px solid var(--theme-line);border-radius:1rem;background:var(--theme-surface-raised)}.sensor-detail__overview>.sensor-status{display:inline-flex;margin:0 0 1rem;padding:.35rem .7rem;border-radius:999px;background:var(--theme-input);font-size:.85rem}
.sensor-detail__facts{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem 1.5rem;margin:0}.sensor-detail__facts div{min-width:0}.sensor-detail__facts dt{margin:0 0 .3rem;color:var(--theme-muted);font-size:.78rem;font-weight:700}.sensor-detail__facts dd{margin:0;overflow-wrap:anywhere;font-size:.92rem;font-weight:600}.sensor-detail__facts code{font:inherit}
.sensor-detail__actions{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:1rem}.sensor-detail__section{display:flex;flex-direction:column;min-width:0;padding:1.2rem;border:1px solid var(--theme-line);border-radius:1rem;background:var(--theme-surface-raised)}.sensor-detail__section h3{margin:0 0 .35rem;font-family:Georgia,ui-serif,serif;font-size:1.15rem}.sensor-detail__section>.help{margin:0}.sensor-detail__section form{display:flex;flex:1;flex-direction:column;gap:.8rem;margin-top:1rem}.sensor-detail__section form .button{margin-top:auto}.sensor-detail__section .field{width:100%}.sensor-detail__section:last-child{border-color:#945f68;background:#392432}.sensor-detail__section:last-child .button--danger{border-color:#dc7b89;color:#fff;background:#a43c50}.sensor-detail__section:last-child .button--danger:hover{background:#bd4a60}
.sensor-confirm{display:flex;align-items:start;gap:.6rem;line-height:1.4;font-size:.82rem;cursor:pointer}.sensor-confirm input{flex:none;width:1.1rem;height:1.1rem;margin:.15rem 0 0;accent-color:#84baff}.sensor-confirm input:focus-visible{outline:3px solid #80b6ff;outline-offset:3px}
.sensor-messages{margin-top:1rem}.token-once{margin:1.25rem 0;padding:1rem;border:1px solid #e4ad55;border-radius:.8rem;background:var(--theme-surface-raised)}.token-once code{display:block;margin:.75rem 0;padding:.7rem;border-radius:.5rem;background:var(--theme-input);overflow-wrap:anywhere;user-select:all}
.button--danger{color:#fff;background:#991b1b}.button--danger:hover{color:#fff;background:#b91c1c}
:root[data-theme=light] .eyebrow{color:#23578d}:root[data-theme=light] .card{box-shadow:0 1.125rem 2.8rem #20365c1a}:root[data-theme=light] .button:not(.button--secondary):not(.button--danger){color:#fff;background:#245b96}:root[data-theme=light] .button:not(.button--secondary):not(.button--danger):hover{background:#174877}:root[data-theme=light] .button--secondary{border-color:#9cc0ed;color:#245b96;background:#edf4ff}:root[data-theme=light] .button--secondary:hover{color:#fff;background:#245b96}:root[data-theme=light] .switch-row{border-color:#d4e0ef;background:#f2f7fe}:root[data-theme=light] .switch-row:hover{border-color:#9cc0ed;background:#eaf3ff}:root[data-theme=light] .switch-track{background:#c1cbd8}:root[data-theme=light] .switch-control input:checked+.switch-track{background:#34c76a}
:root[data-theme=light] .sensor-close:hover{background:#e4efff}:root[data-theme=light] .sensor-detail__section:last-child{border-color:#ecc6cb;background:#fff5f6}:root[data-theme=light] .sensor-detail__section:last-child .button--danger{color:#fff;background:#a43c50}
:root[data-theme=light] .sensor-access{border-color:#b8dfca;color:#256147;background:#ecf8f0}:root[data-theme=light] .sensor-access--off{border-color:#dbcbd3;color:#80556a;background:#fbf4f7}:root[data-theme=light] .sensor-form{border-color:#9cc0ed}
@media(max-width:48rem){.settings-content{grid-template-columns:minmax(0,1fr)}.settings-shell{width:min(100% - 2.25rem,73.75rem);padding:2.5rem 0 3rem}}
@media(max-width:48rem){.sensor-detail__actions,.sensor-list{grid-template-columns:minmax(0,1fr)}}
@media(max-width:30rem){.sensor-detail__facts{grid-template-columns:minmax(0,1fr)}.sensor-detail__header{align-items:start}.sensor-close span{display:none}}
@media(max-width:35rem){.card{padding:1.25rem}.sensor-form__controls{grid-template-columns:minmax(0,1fr)}}
@media(prefers-reduced-motion:reduce){.button,.switch-track,.switch-track::after{transition:none}.button:hover{transform:none}}
+60
View File
@@ -0,0 +1,60 @@
import assert from "node:assert/strict";
import test from "node:test";
import { JSDOM } from "jsdom";
test("compass stays hidden until permission and a heading, then rotates and hides when stopped", async () => {
const dom = new JSDOM(`<!doctype html><html><body>
<form id="manual-report-form" action="/submit">
<input id="manual-latitude"><input id="manual-longitude">
<input id="manual-direction-degrees"><input id="manual-direction-accuracy">
<div id="manual-direction-panel" hidden><button id="manual-capture-direction" type="button"></button><div id="manual-direction-status"></div></div>
<button id="manual-submit" type="button"></button>
<button id="burst-start" type="button"></button><div id="burst-panel"></div><strong id="burst-heading"></strong>
<div id="burst-detail"></div><canvas id="burst-waveform"></canvas><audio id="burst-preview"></audio>
<button id="burst-resume" type="button"></button><button id="burst-discard" type="button"></button>
<button id="burst-stop" type="button"></button><p id="burst-error"></p>
</form>
<div id="manual-submission"></div>
<div id="manual-compass" hidden><div id="manual-compass-rose"></div><span id="manual-compass-heading"></span></div>
</body></html>`, { url: "https://example.test/" });
const { window } = dom;
Object.defineProperty(window, "isSecureContext", { value: true });
let resolvePermission;
class MockOrientation {}
MockOrientation.requestPermission = () => new Promise((resolve) => { resolvePermission = resolve; });
window.DeviceOrientationEvent = MockOrientation;
const previous = Object.fromEntries(["window", "document", "navigator", "DeviceOrientationEvent"].map((key) => [key, Object.getOwnPropertyDescriptor(globalThis, key)]));
for (const [key, value] of Object.entries({ window, document: window.document, navigator: window.navigator, DeviceOrientationEvent: MockOrientation })) {
Object.defineProperty(globalThis, key, { configurable: true, writable: true, value });
}
try {
await import("../src/scripts/manual-report.js?compass=visual");
const compass = window.document.querySelector("#manual-compass");
const rose = window.document.querySelector("#manual-compass-rose");
const button = window.document.querySelector("#manual-capture-direction");
assert.equal(compass.hidden, true);
button.click();
assert.equal(compass.hidden, true);
resolvePermission("granted");
await new Promise((resolve) => setTimeout(resolve, 0));
const reading = (heading) => {
const event = new window.Event("deviceorientation");
Object.defineProperty(event, "webkitCompassHeading", { value: heading });
window.dispatchEvent(event);
};
reading(359);
assert.equal(compass.hidden, false);
assert.equal(rose.style.transform, "rotate(-359deg)");
reading(1);
assert.equal(rose.style.transform, "rotate(-361deg)");
assert.equal(window.document.querySelector("#manual-direction-degrees").value, "1");
button.click();
assert.equal(compass.hidden, true);
} finally {
for (const [key, descriptor] of Object.entries(previous)) {
if (descriptor === undefined) delete globalThis[key];
else Object.defineProperty(globalThis, key, descriptor);
}
dom.window.close();
}
});