- Viewer ignores taps, swipes, pinch/double-tap zoom, long-press menus, keys and Back; hold the top-left corner 3 s to show controls, which re-lock after 6 s or via the Lock button - Back is trapped with a guard history entry; Close unwinds it - Plain grey moved above 'This screen' - Tips for OS-level lock (iOS Guided Access, Android app pinning) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+206
-57
@@ -68,11 +68,39 @@ const subscribeHash = subscribe(["popstate", "hashchange", HASH_EVENT]);
|
|||||||
const subscribeMode = subscribe(["storage", MODE_EVENT]);
|
const subscribeMode = subscribe(["storage", MODE_EVENT]);
|
||||||
const subscribeScreen = subscribe(["resize", "orientationchange"]);
|
const subscribeScreen = subscribe(["resize", "orientationchange"]);
|
||||||
|
|
||||||
|
// History entries pushed while the viewer is open. While it is open, Back is trapped
|
||||||
|
// (a stray press of Android's back button must not drop the marker mid-take), so
|
||||||
|
// closing has to unwind all of them.
|
||||||
|
let viewerDepth = 0;
|
||||||
|
let closingViewer = false;
|
||||||
|
|
||||||
function setHash(hash: string, push: boolean) {
|
function setHash(hash: string, push: boolean) {
|
||||||
|
if (push) viewerDepth++;
|
||||||
history[push ? "pushState" : "replaceState"]({ marker: Boolean(hash) }, "", hash || location.pathname);
|
history[push ? "pushState" : "replaceState"]({ marker: Boolean(hash) }, "", hash || location.pathname);
|
||||||
window.dispatchEvent(new Event(HASH_EVENT));
|
window.dispatchEvent(new Event(HASH_EVENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function closeViewer() {
|
||||||
|
closingViewer = true;
|
||||||
|
if (viewerDepth > 0) {
|
||||||
|
const n = viewerDepth;
|
||||||
|
viewerDepth = 0;
|
||||||
|
history.go(-n); // the popstate handler below finishes the job
|
||||||
|
} else {
|
||||||
|
closingViewer = false;
|
||||||
|
setHash("", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof window !== "undefined") {
|
||||||
|
window.addEventListener("popstate", () => {
|
||||||
|
if (!closingViewer) return;
|
||||||
|
closingViewer = false;
|
||||||
|
// Opened from a direct link: the entry we land on still carries the hash
|
||||||
|
if (location.hash) setHash("", false);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function readMode(): Mode {
|
function readMode(): Mode {
|
||||||
try {
|
try {
|
||||||
return localStorage.getItem(MODE_KEY) === "edge" ? "edge" : "full";
|
return localStorage.getItem(MODE_KEY) === "edge" ? "edge" : "full";
|
||||||
@@ -180,10 +208,7 @@ export default function MarkerPicker({ screens, extras }: { screens: MarkerScree
|
|||||||
setHash(`#${e.id}`, true);
|
setHash(`#${e.id}`, true);
|
||||||
requestFullscreen();
|
requestFullscreen();
|
||||||
};
|
};
|
||||||
const close = useCallback(() => {
|
const close = useCallback(() => closeViewer(), []);
|
||||||
if (history.state?.marker) history.back();
|
|
||||||
else setHash("", false);
|
|
||||||
}, []);
|
|
||||||
const switchMode = useCallback(
|
const switchMode = useCallback(
|
||||||
(m: Mode) => {
|
(m: Mode) => {
|
||||||
writeMode(m);
|
writeMode(m);
|
||||||
@@ -235,6 +260,31 @@ export default function MarkerPicker({ screens, extras }: { screens: MarkerScree
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Plain grey and other non-device images */}
|
||||||
|
{extras.length > 0 && (
|
||||||
|
<section className="mt-6">
|
||||||
|
<ul className="divide-y divide-white/10 overflow-hidden rounded-xl bg-white/[0.04]">
|
||||||
|
{extras.map((e) => (
|
||||||
|
<li key={e.id}>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={() => showExtra(e)}
|
||||||
|
className="flex min-h-16 w-full items-center gap-4 px-4 py-3 text-left active:bg-white/10"
|
||||||
|
>
|
||||||
|
<span className="flex h-10 w-10 shrink-0 items-center justify-center">
|
||||||
|
<span className="block h-7 w-7 rounded-[3px] bg-[#808080]" />
|
||||||
|
</span>
|
||||||
|
<span className="flex-1 text-base">{e.name}</span>
|
||||||
|
<span className="text-xl text-muted" aria-hidden="true">
|
||||||
|
›
|
||||||
|
</span>
|
||||||
|
</button>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
)}
|
||||||
|
|
||||||
{/* This screen */}
|
{/* This screen */}
|
||||||
{match && device && (
|
{match && device && (
|
||||||
<section className="mt-6">
|
<section className="mt-6">
|
||||||
@@ -299,33 +349,21 @@ export default function MarkerPicker({ screens, extras }: { screens: MarkerScree
|
|||||||
</section>
|
</section>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
{extras.length > 0 && (
|
<details className="mt-8 rounded-xl bg-white/[0.04] px-4 py-3 text-sm leading-relaxed text-muted">
|
||||||
<section className="mt-8">
|
<summary className="cursor-pointer py-2 text-fg">Lock the whole device (blocks home swipe & notifications)</summary>
|
||||||
<h2 className="mb-2 font-mono text-[11px] tracking-[0.25em] text-muted uppercase">Other</h2>
|
<p className="mt-2">
|
||||||
<ul className="divide-y divide-white/10 overflow-hidden rounded-xl bg-white/[0.04]">
|
<span className="text-fg">iPhone / iPad:</span> Settings → Accessibility → Guided Access → on. Open a marker,
|
||||||
{extras.map((e) => (
|
triple-click the side (or home) button, turn <span className="text-fg">Touch</span> off in Options, then
|
||||||
<li key={e.id}>
|
Start. Triple-click again to end.
|
||||||
<button
|
</p>
|
||||||
type="button"
|
<p className="mt-2 pb-1">
|
||||||
onClick={() => showExtra(e)}
|
<span className="text-fg">Android:</span> Settings → Security → App pinning (Screen pinning) → on. Open a
|
||||||
className="flex min-h-16 w-full items-center gap-4 px-4 py-3 text-left active:bg-white/10"
|
marker, open Recents, tap the app icon → Pin. Hold Back + Overview to unpin.
|
||||||
>
|
</p>
|
||||||
<span className="flex h-10 w-10 shrink-0 items-center justify-center">
|
</details>
|
||||||
<span className="block h-7 w-7 rounded-[3px] bg-[#808080]" />
|
|
||||||
</span>
|
|
||||||
<span className="flex-1 text-base">{e.name}</span>
|
|
||||||
<span className="text-xl text-muted" aria-hidden="true">
|
|
||||||
›
|
|
||||||
</span>
|
|
||||||
</button>
|
|
||||||
</li>
|
|
||||||
))}
|
|
||||||
</ul>
|
|
||||||
</section>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<p className="mt-10 text-center text-xs leading-relaxed text-muted">
|
<p className="mt-10 text-center text-xs leading-relaxed text-muted">
|
||||||
Tap the image for controls · Back or Esc to close · Screen stays awake while showing
|
Touch is locked while a marker is up · hold the top-left corner 3 s for controls · screen stays awake
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{showing && (
|
{showing && (
|
||||||
@@ -335,6 +373,11 @@ export default function MarkerPicker({ screens, extras }: { screens: MarkerScree
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const HOLD_MS = 3000; // how long to hold the corner to unlock
|
||||||
|
const HOLD_SHOW_MS = 500; // ring only appears after this, so brushes show nothing
|
||||||
|
const CORNER = 80; // px, top-left hot zone
|
||||||
|
const CONTROLS_MS = 6000; // controls re-lock after this
|
||||||
|
|
||||||
function Viewer({
|
function Viewer({
|
||||||
showing,
|
showing,
|
||||||
mode,
|
mode,
|
||||||
@@ -346,9 +389,14 @@ function Viewer({
|
|||||||
onMode: (m: Mode) => void;
|
onMode: (m: Mode) => void;
|
||||||
onClose: () => void;
|
onClose: () => void;
|
||||||
}) {
|
}) {
|
||||||
|
// Touch-locked by default: only a 3 s hold in the top-left corner shows controls.
|
||||||
const [controls, setControls] = useState(false);
|
const [controls, setControls] = useState(false);
|
||||||
|
const [hold, setHold] = useState(0); // 0..1 progress of the corner hold
|
||||||
|
const [hint, setHint] = useState(true);
|
||||||
const [fullscreen, setFullscreen] = useState(false);
|
const [fullscreen, setFullscreen] = useState(false);
|
||||||
const hideTimer = useRef<number | undefined>(undefined);
|
const hideTimer = useRef<number | undefined>(undefined);
|
||||||
|
const holdRef = useRef<{ id: number; raf: number } | null>(null);
|
||||||
|
|
||||||
// Stretch to fill when the image's shape is close to the visible area (markers sit on
|
// Stretch to fill when the image's shape is close to the visible area (markers sit on
|
||||||
// the real screen edges); otherwise fit it whole so the dots stay round.
|
// the real screen edges); otherwise fit it whole so the dots stay round.
|
||||||
const viewport = useSyncExternalStore(subscribeScreen, () => `${innerWidth}x${innerHeight}`, () => "1x1");
|
const viewport = useSyncExternalStore(subscribeScreen, () => `${innerWidth}x${innerHeight}`, () => "1x1");
|
||||||
@@ -360,71 +408,165 @@ function Viewer({
|
|||||||
}, [showing.screen, viewport]);
|
}, [showing.screen, viewport]);
|
||||||
const canFullscreen = typeof document !== "undefined" && document.fullscreenEnabled;
|
const canFullscreen = typeof document !== "undefined" && document.fullscreenEnabled;
|
||||||
|
|
||||||
|
const showControls = useCallback(() => {
|
||||||
|
window.clearTimeout(hideTimer.current);
|
||||||
|
setControls(true);
|
||||||
|
setHint(false);
|
||||||
|
hideTimer.current = window.setTimeout(() => setControls(false), CONTROLS_MS);
|
||||||
|
}, []);
|
||||||
|
const lock = () => {
|
||||||
|
window.clearTimeout(hideTimer.current);
|
||||||
|
setControls(false);
|
||||||
|
};
|
||||||
|
|
||||||
// Keep the screen awake while a marker is up
|
// Keep the screen awake while a marker is up
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let lock: WakeLockSentinel | null = null;
|
let wake: WakeLockSentinel | null = null;
|
||||||
const acquire = async () => {
|
const acquire = async () => {
|
||||||
try {
|
try {
|
||||||
lock = (await navigator.wakeLock?.request("screen")) ?? null;
|
wake = (await navigator.wakeLock?.request("screen")) ?? null;
|
||||||
} catch {}
|
} catch {}
|
||||||
};
|
};
|
||||||
const onVisible = () => document.visibilityState === "visible" && acquire();
|
const onVisible = () => document.visibilityState === "visible" && acquire();
|
||||||
acquire();
|
acquire();
|
||||||
document.addEventListener("visibilitychange", onVisible);
|
document.addEventListener("visibilitychange", onVisible);
|
||||||
document.body.style.overflow = "hidden";
|
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener("visibilitychange", onVisible);
|
document.removeEventListener("visibilitychange", onVisible);
|
||||||
document.body.style.overflow = "";
|
wake?.release().catch(() => {});
|
||||||
lock?.release().catch(() => {});
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
// Swallow everything the browser would otherwise do with stray input:
|
||||||
|
// scrolling, pull-to-refresh, pinch/double-tap zoom, long-press menus, Back.
|
||||||
|
useEffect(() => {
|
||||||
|
const root = document.documentElement;
|
||||||
|
const prev = { overflow: document.body.style.overflow, overscroll: root.style.overscrollBehavior };
|
||||||
|
document.body.style.overflow = "hidden";
|
||||||
|
root.style.overscrollBehavior = "none";
|
||||||
|
|
||||||
|
const block = (e: Event) => e.preventDefault();
|
||||||
|
const blockTouch = (e: TouchEvent) => {
|
||||||
|
if (!(e.target as Element).closest?.("[data-controls]")) e.preventDefault();
|
||||||
|
};
|
||||||
|
document.addEventListener("touchmove", blockTouch, { passive: false });
|
||||||
|
document.addEventListener("gesturestart", block); // iOS pinch
|
||||||
|
document.addEventListener("contextmenu", block);
|
||||||
|
document.addEventListener("dblclick", block);
|
||||||
|
|
||||||
|
// Guard entry so Back stays on the marker; re-armed every time it is used
|
||||||
|
viewerDepth++;
|
||||||
|
history.pushState({ marker: true }, "", location.hash);
|
||||||
|
const onPop = () => {
|
||||||
|
if (closingViewer || !location.hash) return;
|
||||||
|
history.pushState({ marker: true }, "", location.hash);
|
||||||
|
};
|
||||||
|
window.addEventListener("popstate", onPop);
|
||||||
|
|
||||||
|
const hintTimer = window.setTimeout(() => setHint(false), 4000);
|
||||||
|
return () => {
|
||||||
|
document.body.style.overflow = prev.overflow;
|
||||||
|
root.style.overscrollBehavior = prev.overscroll;
|
||||||
|
document.removeEventListener("touchmove", blockTouch);
|
||||||
|
document.removeEventListener("gesturestart", block);
|
||||||
|
document.removeEventListener("contextmenu", block);
|
||||||
|
document.removeEventListener("dblclick", block);
|
||||||
|
window.removeEventListener("popstate", onPop);
|
||||||
|
window.clearTimeout(hintTimer);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const onFs = () => setFullscreen(Boolean(document.fullscreenElement));
|
const onFs = () => setFullscreen(Boolean(document.fullscreenElement));
|
||||||
onFs();
|
|
||||||
document.addEventListener("fullscreenchange", onFs);
|
document.addEventListener("fullscreenchange", onFs);
|
||||||
const onKey = (e: KeyboardEvent) => {
|
const onKey = (e: KeyboardEvent) => {
|
||||||
if (e.key === "Escape" && !document.fullscreenElement) onClose();
|
// Locked: keys do nothing (a prop laptop keyboard may get typed on mid-take).
|
||||||
if (e.key === "f") onMode("full");
|
// The browser itself still leaves full screen on Esc; that cannot be blocked.
|
||||||
if (e.key === "e") onMode("edge");
|
if (!controls) {
|
||||||
if (e.key === " ") setControls((v) => !v);
|
e.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (e.key === "Escape") onClose();
|
||||||
};
|
};
|
||||||
document.addEventListener("keydown", onKey);
|
document.addEventListener("keydown", onKey);
|
||||||
return () => {
|
return () => {
|
||||||
document.removeEventListener("fullscreenchange", onFs);
|
document.removeEventListener("fullscreenchange", onFs);
|
||||||
document.removeEventListener("keydown", onKey);
|
document.removeEventListener("keydown", onKey);
|
||||||
};
|
};
|
||||||
}, [onClose, onMode]);
|
}, [controls, onClose]);
|
||||||
|
|
||||||
const poke = () => {
|
// --- corner hold -------------------------------------------------------
|
||||||
window.clearTimeout(hideTimer.current);
|
const cancelHold = () => {
|
||||||
setControls((v) => {
|
if (holdRef.current) cancelAnimationFrame(holdRef.current.raf);
|
||||||
if (!v) hideTimer.current = window.setTimeout(() => setControls(false), 4000);
|
holdRef.current = null;
|
||||||
return !v;
|
setHold(0);
|
||||||
});
|
};
|
||||||
|
const onPointerDown = (e: React.PointerEvent) => {
|
||||||
|
if (canFullscreen && !document.fullscreenElement) document.documentElement.requestFullscreen?.().catch(() => {});
|
||||||
|
if (controls || e.clientX > CORNER || e.clientY > CORNER) return;
|
||||||
|
const start = performance.now();
|
||||||
|
const tick = () => {
|
||||||
|
if (!holdRef.current) return;
|
||||||
|
const t = performance.now() - start;
|
||||||
|
setHold(t < HOLD_SHOW_MS ? 0 : Math.min(1, (t - HOLD_SHOW_MS) / (HOLD_MS - HOLD_SHOW_MS)));
|
||||||
|
if (t >= HOLD_MS) {
|
||||||
|
cancelHold();
|
||||||
|
showControls();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
holdRef.current.raf = requestAnimationFrame(tick);
|
||||||
|
};
|
||||||
|
holdRef.current = { id: e.pointerId, raf: requestAnimationFrame(tick) };
|
||||||
|
};
|
||||||
|
const onPointerMove = (e: React.PointerEvent) => {
|
||||||
|
if (holdRef.current?.id === e.pointerId && (e.clientX > CORNER * 1.5 || e.clientY > CORNER * 1.5)) cancelHold();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`fixed inset-0 z-[100] bg-black ${controls ? "" : "cursor-none"}`}
|
className={`fixed inset-0 z-[100] touch-none bg-black select-none [-webkit-touch-callout:none] ${controls ? "" : "cursor-none"}`}
|
||||||
onClick={() => {
|
onPointerDown={onPointerDown}
|
||||||
if (canFullscreen && !document.fullscreenElement) document.documentElement.requestFullscreen?.().catch(() => {});
|
onPointerMove={onPointerMove}
|
||||||
poke();
|
onPointerUp={cancelHold}
|
||||||
}}
|
onPointerCancel={cancelHold}
|
||||||
|
onPointerLeave={cancelHold}
|
||||||
>
|
>
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
<img src={showing.src} alt={showing.label} className={`h-full w-full select-none ${fit}`} draggable={false} />
|
<img src={showing.src} alt={showing.label} className={`pointer-events-none h-full w-full ${fit}`} draggable={false} />
|
||||||
|
|
||||||
{canFullscreen && !fullscreen && !controls && (
|
{/* Corner-hold progress ring */}
|
||||||
<p className="pointer-events-none absolute inset-x-0 bottom-6 text-center font-mono text-xs text-white/70">
|
{hold > 0 && (
|
||||||
Tap for full screen
|
<svg className="pointer-events-none absolute top-3 left-3 h-14 w-14 -rotate-90" viewBox="0 0 36 36" aria-hidden="true">
|
||||||
</p>
|
<circle cx="18" cy="18" r="15" fill="rgba(0,0,0,.6)" stroke="rgba(255,255,255,.25)" strokeWidth="3" />
|
||||||
|
<circle
|
||||||
|
cx="18"
|
||||||
|
cy="18"
|
||||||
|
r="15"
|
||||||
|
fill="none"
|
||||||
|
stroke="var(--accent)"
|
||||||
|
strokeWidth="3"
|
||||||
|
strokeDasharray={`${hold * 94.25} 94.25`}
|
||||||
|
strokeLinecap="round"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{hint && !controls && (
|
||||||
|
<div className="pointer-events-none absolute inset-x-0 bottom-[max(1.5rem,env(safe-area-inset-bottom))] flex justify-center px-4">
|
||||||
|
<p className="rounded-full bg-black/75 px-4 py-2 text-center font-mono text-xs text-white/85">
|
||||||
|
🔒 Touch locked · hold top-left corner 3 s for controls
|
||||||
|
{canFullscreen && !fullscreen ? " · tap for full screen" : ""}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{controls && (
|
{controls && (
|
||||||
<div
|
<div
|
||||||
|
data-controls
|
||||||
className="absolute inset-x-0 top-0 flex flex-wrap items-center gap-2 bg-black/85 px-3 pt-[max(0.75rem,env(safe-area-inset-top))] pb-3"
|
className="absolute inset-x-0 top-0 flex flex-wrap items-center gap-2 bg-black/85 px-3 pt-[max(0.75rem,env(safe-area-inset-top))] pb-3"
|
||||||
onClick={(e) => e.stopPropagation()}
|
onPointerDown={(e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
showControls(); // keep them up while being used
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
@@ -457,6 +599,13 @@ function Viewer({
|
|||||||
>
|
>
|
||||||
Save
|
Save
|
||||||
</a>
|
</a>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
onClick={lock}
|
||||||
|
className="min-h-12 rounded-lg bg-accent px-4 text-sm font-semibold text-ink active:opacity-80"
|
||||||
|
>
|
||||||
|
🔒 Lock
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user