import { on } from "svelte/events"; import { createSubscriber } from "svelte/reactivity"; let held = false; const subscribe = createSubscriber((update) => { const set = (next: boolean) => { if (held === next) return; held = next; update(); }; const track = (event: KeyboardEvent) => set(event.shiftKey); const offs = [ on(window, "keydown", track), on(window, "keyup", track), on(window, "blur", () => set(false)) ]; return () => { for (const off of offs) off(); held = false; }; }); export const shiftKey = { get held() { subscribe(); return held; } };