@mattebox/player-spatial-nav 0.1.2 → 0.3.0

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 (45) hide show
  1. package/README.md +22 -11
  2. package/dist/cdn/mattebox-player-spatial-nav-gamepad.min.js +1 -0
  3. package/dist/cdn/mattebox-player-spatial-nav.min.js +1 -1
  4. package/dist/component.js +40 -44
  5. package/dist/component.js.map +1 -1
  6. package/dist/es2015/component.js +2 -2
  7. package/dist/es2015/gamepad-help.js +139 -0
  8. package/dist/es2015/gamepad-index.js +17 -0
  9. package/dist/es2015/gamepad.js +321 -0
  10. package/dist/es2015/host.js +10 -1
  11. package/dist/es2015/index.js +3 -0
  12. package/dist/es2015/pad.js +157 -0
  13. package/dist/es2015/spatial-nav.js +2 -7
  14. package/dist/gamepad-help.d.ts +30 -0
  15. package/dist/gamepad-help.d.ts.map +1 -0
  16. package/dist/gamepad-help.js +137 -0
  17. package/dist/gamepad-help.js.map +1 -0
  18. package/dist/gamepad-index.d.ts +24 -0
  19. package/dist/gamepad-index.d.ts.map +1 -0
  20. package/dist/gamepad-index.js +19 -0
  21. package/dist/gamepad-index.js.map +1 -0
  22. package/dist/gamepad.d.ts +98 -0
  23. package/dist/gamepad.d.ts.map +1 -0
  24. package/dist/gamepad.js +316 -0
  25. package/dist/gamepad.js.map +1 -0
  26. package/dist/host.d.ts +2 -0
  27. package/dist/host.d.ts.map +1 -1
  28. package/dist/host.js +23 -14
  29. package/dist/host.js.map +1 -1
  30. package/dist/index.d.ts +3 -0
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +14 -11
  33. package/dist/index.js.map +1 -1
  34. package/dist/keys.js +31 -30
  35. package/dist/keys.js.map +1 -1
  36. package/dist/navigate.js +78 -85
  37. package/dist/navigate.js.map +1 -1
  38. package/dist/pad.d.ts +48 -0
  39. package/dist/pad.d.ts.map +1 -0
  40. package/dist/pad.js +157 -0
  41. package/dist/pad.js.map +1 -0
  42. package/dist/spatial-nav.d.ts.map +1 -1
  43. package/dist/spatial-nav.js +173 -201
  44. package/dist/spatial-nav.js.map +1 -1
  45. package/package.json +12 -6
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gamepad.js","names":[],"sources":["../src/gamepad.ts"],"sourcesContent":["/**\n * <mbx-gamepad>: a game controller drives the player. Placed inside the\n * player beside <mbx-spatial-nav>, it renders nothing.\n *\n * The Gamepad API has no button events, so the element reads the pads once\n * a frame, on `requestAnimationFrame`. It reads them only while one is\n * connected and the page is visible: a page without a pad pays nothing\n * after `attach`.\n *\n * Each press of a button takes the action the mapping gives it (`pad.ts`).\n * The element fires `gamepadaction` first, cancellable, so the page can\n * take any action, or one of its own name. Nobody took it: the element\n * sends the player the key a remote would send.\n *\n * - The directions are the arrows, which <mbx-spatial-nav> turns into\n * moves of focus. They repeat while held.\n * - `activate` is Enter on the focused control. With no control focused,\n * or the bar asleep, it plays or pauses.\n * - `back` is the remote's Back. With no control focused, it leaves\n * fullscreen first; after that, Back is the application's.\n * - `rewind` and `fast-forward` seek a step at each press, and again while\n * held, faster the harder the trigger is pressed.\n * - `previous` and `next` go to the chapter before or after, when the\n * programme has chapters, else to the playlist's item.\n *\n * A press sets `focus-ring` on the player, and a pointer's press takes it\n * off. The keys the element sends are synthetic, and after them the\n * browser shows no `:focus-visible`, so without it the focus would not show.\n *\n * Edge on Xbox drives a mouse cursor with the pad unless the page asks for\n * the pad itself, so the element asks, where the browser has the switch.\n */\nimport { Component } from './component.js';\nimport type { PlayerHost } from './host.js';\nimport { focusedIn } from './host.js';\nimport type { PadButton, PadKind, PadMap } from './pad.js';\nimport { BUTTONS, kindOf, mapping, parseMap } from './pad.js';\n\n/** The help bubble's tag: `help` opens it. */\nconst HELP = 'mbx-gamepad-help';\n\n/** The player's attribute that shows the focus a pad gave. */\nconst RING = 'focus-ring';\n\n/** The left stick leans a direction past this much. */\nconst DEAD_ZONE = 0.5;\n\n/** A trigger counts as pressed past this much of its travel. */\nconst TRIGGER = 0.15;\n\n/** A held direction repeats after this long, in ms, then every `STEP_MS`. */\nconst DELAY_MS = 400;\nconst STEP_MS = 120;\n\n/** A held trigger seeks again after this long, in ms, then every `SCAN_MS` at full press. */\nconst SCAN_DELAY_MS = 300;\nconst SCAN_MS = 100;\n\n/** Back to the start of the chapter, not the one before, this far into it, in seconds. */\nconst RESTART_S = 3;\n\n/** The seconds a step seeks where no control bar answers the media keys. */\nconst STEP_S = 5;\n\n/** The keys the directions send. */\nconst ARROWS: Readonly<Record<string, string>> = {\n up: 'ArrowUp',\n down: 'ArrowDown',\n left: 'ArrowLeft',\n right: 'ArrowRight',\n};\n\n/** The actions that repeat while their button is held. */\nconst REPEATING = new Set(['up', 'down', 'left', 'right', 'rewind', 'fast-forward']);\n\n/** What `gamepadaction` carries. */\nexport interface GamepadActionDetail {\n readonly action: string;\n readonly button: PadButton;\n readonly kind: PadKind;\n}\n\n/** A held button: when it acts again. */\ninterface Held {\n next: number;\n}\n\nexport class MbxGamepad extends Component {\n /** The buttons down on each pad, by the pad's index. */\n declare private held: Map<number, Map<PadButton, Held>>;\n /** The animation frame asked for, or 0 while the loop sleeps. */\n declare private frame: number;\n /** The mapping the page set from script, over the attribute's. */\n declare private own: PadMap;\n /** The make of the pad used last. */\n declare private last: PadKind;\n\n constructor() {\n super();\n this.held = new Map();\n this.frame = 0;\n this.own = {};\n this.last = 'xbox';\n }\n\n /** The overrides set from script, over the defaults and the `map` attribute. Null unbinds a button. */\n get map(): PadMap {\n return Object.assign({}, this.own);\n }\n\n set map(value: PadMap) {\n // Object.assign, not a spread: the ES2015 build would lower a spread into a helper.\n this.own = Object.assign({}, value);\n }\n\n /** The make of the pad used last, `xbox` before any. */\n get kind(): PadKind {\n return this.last;\n }\n\n /** What each button does on `kind`: the defaults, the `map` attribute, then `map`. */\n bindings(kind: PadKind = this.last): Record<PadButton, string | null> {\n return mapping(kind, parseMap(this.getAttribute('map')), this.own);\n }\n\n override disconnectedCallback(): void {\n this.stop();\n this.player?.removeAttribute(RING);\n super.disconnectedCallback();\n }\n\n protected override attach(player: PlayerHost): void {\n const nav = navigator as Navigator & { gamepadInputEmulation?: string };\n if ('gamepadInputEmulation' in nav) nav.gamepadInputEmulation = 'gamepad';\n this.on(window, 'gamepadconnected', (event) => {\n const pad = (event as GamepadEvent).gamepad;\n this.last = kindOf(pad.id);\n this.tell('gamepadconnect', pad);\n this.start(player);\n });\n this.on(window, 'gamepaddisconnected', (event) => {\n const pad = (event as GamepadEvent).gamepad;\n this.held.delete(pad.index);\n this.tell('gamepaddisconnect', pad);\n });\n this.on(document, 'visibilitychange', () => this.start(player));\n this.on(player, 'pointerdown', () => player.removeAttribute(RING), { capture: true });\n this.start(player);\n }\n\n /** Fires `name` on the element, bubbling and composed, with the pad's make and id. */\n private tell(name: string, pad: Gamepad): void {\n const detail = { kind: kindOf(pad.id), id: pad.id };\n this.dispatchEvent(new CustomEvent(name, { detail, bubbles: true, composed: true }));\n }\n\n /** The connected pads. Chromium lists empty slots as null. */\n private pads(): Gamepad[] {\n if (typeof navigator.getGamepads !== 'function') return [];\n const out: Gamepad[] = [];\n for (const pad of navigator.getGamepads()) if (pad?.connected === true) out.push(pad);\n return out;\n }\n\n /** Starts the loop, unless it runs, the page is hidden, or no pad is connected. */\n private start(player: PlayerHost): void {\n if (this.frame !== 0 || document.hidden || this.pads().length === 0) return;\n this.frame = requestAnimationFrame((now) => this.tick(player, now));\n }\n\n private stop(): void {\n if (this.frame !== 0) cancelAnimationFrame(this.frame);\n this.frame = 0;\n this.held.clear();\n }\n\n private tick(player: PlayerHost, now: number): void {\n this.frame = 0;\n const pads = this.pads();\n if (pads.length === 0 || document.hidden || this.player !== player) {\n this.held.clear();\n return;\n }\n for (const pad of pads) this.read(player, pad, now);\n this.frame = requestAnimationFrame((next) => this.tick(player, next));\n }\n\n /** Compares one pad with the frame before, and acts on what went down or is held. */\n private read(player: PlayerHost, pad: Gamepad, now: number): void {\n const kind = kindOf(pad.id);\n let held = this.held.get(pad.index);\n if (held === undefined) {\n held = new Map();\n this.held.set(pad.index, held);\n }\n const map = this.bindings(kind);\n for (const [index, button] of BUTTONS.entries()) {\n const value = this.value(pad, index, button);\n const was = held.get(button);\n if (value === 0) {\n held.delete(button);\n continue;\n }\n const action = map[button];\n if (was === undefined) {\n this.last = kind;\n held.set(button, {\n next: now + (action === 'rewind' || action === 'fast-forward' ? SCAN_DELAY_MS : DELAY_MS),\n });\n if (action != null) this.act(player, action, button, kind);\n } else if (action != null && REPEATING.has(action) && now >= was.next) {\n const scan = action === 'rewind' || action === 'fast-forward';\n was.next = now + (scan ? SCAN_MS + (1 - value) * SCAN_DELAY_MS : STEP_MS);\n this.act(player, action, button, kind);\n }\n }\n }\n\n /**\n * How far `button` is pressed, from 0 to 1, or 0 when it is not. The\n * directions read the left stick too, past the dead zone.\n */\n private value(pad: Gamepad, index: number, button: PadButton): number {\n const own = pad.buttons[index];\n const trigger = button === 'lt' || button === 'rt';\n let value = own === undefined ? 0 : own.pressed ? Math.max(own.value, 0.5) : own.value;\n if (value < (trigger ? TRIGGER : 0.5)) value = 0;\n const x = pad.axes[0] ?? 0;\n const y = pad.axes[1] ?? 0;\n const lean =\n button === 'left'\n ? -x\n : button === 'right'\n ? x\n : button === 'up'\n ? -y\n : button === 'down'\n ? y\n : 0;\n return lean > DEAD_ZONE ? Math.max(value, 1) : value;\n }\n\n /** Asks the page with `gamepadaction`, then does the action nobody took. */\n private act(player: PlayerHost, action: string, button: PadButton, kind: PadKind): void {\n const detail: GamepadActionDetail = { action, button, kind };\n const asked = new CustomEvent('gamepadaction', {\n detail,\n bubbles: true,\n composed: true,\n cancelable: true,\n });\n if (!this.dispatchEvent(asked)) return;\n player.toggleAttribute(RING, true);\n this.run(player, action);\n }\n\n private run(player: PlayerHost, action: string): void {\n const media = player.media;\n const arrow = ARROWS[action];\n if (arrow !== undefined) {\n this.key(focusedIn(player) ?? player, arrow);\n return;\n }\n switch (action) {\n case 'activate':\n this.activate(player);\n break;\n case 'back':\n this.back(player);\n break;\n case 'play-pause':\n if (this.key(player, 'MediaPlayPause')) toggle(media);\n break;\n case 'rewind':\n if (this.key(player, 'MediaRewind'))\n media.currentTime = Math.max(0, media.currentTime - STEP_S);\n break;\n case 'fast-forward':\n if (this.key(player, 'MediaFastForward')) media.currentTime += STEP_S;\n break;\n case 'previous':\n this.skip(player, -1);\n break;\n case 'next':\n this.skip(player, 1);\n break;\n case 'subtitles':\n this.press(player, 'mbx-subtitles-menu');\n break;\n case 'mute':\n if (this.key(player, 'm')) media.muted = !media.muted;\n break;\n case 'fullscreen':\n this.key(player, 'f');\n break;\n case 'help':\n player.querySelector(HELP)?.toggleAttribute('open');\n break;\n default:\n // A name of the page's own: `gamepadaction` was all of it.\n break;\n }\n }\n\n /**\n * Enter on the focused control. A native button clicks itself only on a\n * real Enter, so a button nobody took is clicked here. No control\n * focused, or the bar asleep: play or pause, as on a console's player.\n */\n private activate(player: PlayerHost): void {\n const current = focusedIn(player);\n if (current === null || player.hasAttribute('idle')) {\n if (this.key(player, 'MediaPlayPause')) toggle(player.media);\n return;\n }\n if (this.key(current, 'Enter') && current instanceof HTMLButtonElement) current.click();\n }\n\n /** The remote's Back, which <mbx-spatial-nav> reads. With nothing focused, fullscreen ends first. */\n private back(player: PlayerHost): void {\n const current = focusedIn(player);\n if (current === null && player.hasAttribute('fullscreen')) {\n this.key(player, 'f');\n return;\n }\n this.key(current ?? player, 'GoBack');\n }\n\n /**\n * The chapter before or after, else the playlist's item. Previous goes\n * to the start of the chapter that plays first, past its first seconds,\n * as a remote's previous does.\n */\n private skip(player: PlayerHost, by: 1 | -1): void {\n const media = player.media;\n // A player before 0.16 has no `chapters`: the playlist's item, then.\n const list = player.chapters ?? [];\n const now = media.currentTime;\n let at = -1;\n for (const [i, chapter] of list.entries()) if (chapter.start <= now) at = i;\n const target =\n by === 1\n ? list[at + 1]\n : at >= 0 && now - (list[at]?.start ?? 0) > RESTART_S\n ? list[at]\n : list[at - 1];\n if (target !== undefined) {\n media.currentTime = target.start;\n return;\n }\n this.press(player, by === 1 ? 'mbx-next-button' : 'mbx-previous-button');\n }\n\n /** Clicks the button of the control `tag` in the player, when it shows. */\n private press(player: PlayerHost, tag: string): void {\n const button = player.querySelector(tag)?.shadowRoot?.querySelector('button');\n if (button == null || button.getClientRects().length === 0) return;\n button.click();\n }\n\n /** Sends `name` as a keydown on `target`; true when nobody took it. */\n private key(target: EventTarget, name: string): boolean {\n return target.dispatchEvent(\n new KeyboardEvent('keydown', { key: name, bubbles: true, composed: true, cancelable: true }),\n );\n }\n}\n\n/** Plays a paused video, pauses a playing one. */\nfunction toggle(media: HTMLVideoElement): void {\n if (media.paused) void media.play().catch(() => undefined);\n else media.pause();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAM,OAAO;;AAGb,MAAM,OAAO;;AAGb,MAAM,YAAY;;AAGlB,MAAM,UAAU;;AAGhB,MAAM,WAAW;AACjB,MAAM,UAAU;;AAGhB,MAAM,gBAAgB;AACtB,MAAM,UAAU;;AAGhB,MAAM,YAAY;;AAGlB,MAAM,SAAS;;AAGf,MAAM,SAA2C;CAC/C,IAAI;CACJ,MAAM;CACN,MAAM;CACN,OAAO;AACT;;AAGA,MAAM,4BAAY,IAAI,IAAI;CAAC;CAAM;CAAQ;CAAQ;CAAS;CAAU;AAAc,CAAC;AAcnF,IAAa,aAAb,cAAgC,UAAU;CAUxC,cAAc;EACZ,MAAM;EACN,KAAK,uBAAO,IAAI,IAAI;EACpB,KAAK,QAAQ;EACb,KAAK,MAAM,CAAC;EACZ,KAAK,OAAO;CACd;;CAGA,IAAI,MAAc;EAChB,OAAO,OAAO,OAAO,CAAC,GAAG,KAAK,GAAG;CACnC;CAEA,IAAI,IAAI,OAAe;EAErB,KAAK,MAAM,OAAO,OAAO,CAAC,GAAG,KAAK;CACpC;;CAGA,IAAI,OAAgB;EAClB,OAAO,KAAK;CACd;;CAGA,SAAS,OAAgB,KAAK,MAAwC;E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MAAM,KAAK,OAAO,KAAK,GAAG,EAAE,SAAS,KAAK,YACxC,KAAK,MACL,KAAK,KAAK;EAClB,IAAI,WAAW,KAAA,GAAW;GACxB,MAAM,cAAc,OAAO;GAC3B;EACF;EACA,KAAK,MAAM,QAAQ,OAAO,IAAI,oBAAoB,qBAAqB;CACzE;;CAGQ,MAAM,QAAoB,KAAmB;EACnD,MAAM,SAAS,OAAO,cAAc,GAAG,CAAC,EAAE,YAAY,cAAc,QAAQ;EAC5E,IAAI,UAAU,QAAQ,OAAO,eAAe,CAAC,CAAC,WAAW,GAAG;EAC5D,OAAO,MAAM;CACf;;CAGQ,IAAI,QAAqB,MAAuB;EACtD,OAAO,OAAO,cACZ,IAAI,cAAc,WAAW;GAAE,KAAK;GAAM,SAAS;GAAM,UAAU;GAAM,YAAY;EAAK,CAAC,CAC7F;CACF;AACF;;AAGA,SAAS,OAAO,OAA+B;CAC7C,IAAI,MAAM,QAAa,MAAM,KAAK,CAAC,CAAC,YAAY,KAAA,CAAS;MACpD,MAAM,MAAM;AACnB"}
package/dist/host.d.ts CHANGED
@@ -11,4 +11,6 @@ export declare const PLAYER = "mattebox-player";
11
11
  export declare function above(node: Node): Node | null;
12
12
  /** The nearest player above `node`, or null outside one. It may not be upgraded yet. */
13
13
  export declare function findPlayer(node: Node): HTMLElement | null;
14
+ /** The element focused inside `player`, through shadow roots, or null when focus is elsewhere. */
15
+ export declare function focusedIn(player: HTMLElement): HTMLElement | null;
14
16
  //# sourceMappingURL=host.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,eAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,0FAA0F;AAC1F,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAI7C;AAED,wFAAwF;AACxF,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,IAAI,CAOzD"}
1
+ {"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,eAAO,MAAM,MAAM,oBAAoB,CAAC;AAExC,0FAA0F;AAC1F,wBAAgB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI,CAI7C;AAED,wFAAwF;AACxF,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,IAAI,CAOzD;AAED,kGAAkG;AAClG,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAQjE"}
package/dist/host.js CHANGED
@@ -1,19 +1,28 @@
1
- export const PLAYER = 'mattebox-player';
1
+ // src/host.ts
2
+ const PLAYER = "mattebox-player";
2
3
  /** The parent, or the host of the shadow root `node` sits in, or null at the document. */
3
- export function above(node) {
4
- const parent = node.parentNode;
5
- if (parent !== null)
6
- return parent;
7
- return node instanceof ShadowRoot ? node.host : null;
4
+ function above(node) {
5
+ const parent = node.parentNode;
6
+ if (parent !== null) return parent;
7
+ return node instanceof ShadowRoot ? node.host : null;
8
8
  }
9
9
  /** The nearest player above `node`, or null outside one. It may not be upgraded yet. */
10
- export function findPlayer(node) {
11
- let current = node;
12
- while (current !== null) {
13
- if (current instanceof HTMLElement && current.localName === PLAYER)
14
- return current;
15
- current = above(current);
16
- }
17
- return null;
10
+ function findPlayer(node) {
11
+ let current = node;
12
+ while (current !== null) {
13
+ if (current instanceof HTMLElement && current.localName === "mattebox-player") return current;
14
+ current = above(current);
15
+ }
16
+ return null;
18
17
  }
18
+ /** The element focused inside `player`, through shadow roots, or null when focus is elsewhere. */
19
+ function focusedIn(player) {
20
+ let active = document.activeElement;
21
+ while (active?.shadowRoot?.activeElement != null) active = active.shadowRoot.activeElement;
22
+ if (!(active instanceof HTMLElement) || active === player) return null;
23
+ for (let node = active; node !== null; node = above(node)) if (node === player) return active;
24
+ return null;
25
+ }
26
+ export { PLAYER, above, findPlayer, focusedIn };
27
+
19
28
  //# sourceMappingURL=host.js.map
package/dist/host.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"host.js","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,MAAM,GAAG,iBAAiB,CAAC;AAExC,0FAA0F;AAC1F,MAAM,UAAU,KAAK,CAAC,IAAU;IAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,UAAU,CAAC;IAC/B,IAAI,MAAM,KAAK,IAAI;QAAE,OAAO,MAAM,CAAC;IACnC,OAAO,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;AACvD,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,UAAU,CAAC,IAAU;IACnC,IAAI,OAAO,GAAgB,IAAI,CAAC;IAChC,OAAO,OAAO,KAAK,IAAI,EAAE,CAAC;QACxB,IAAI,OAAO,YAAY,WAAW,IAAI,OAAO,CAAC,SAAS,KAAK,MAAM;YAAE,OAAO,OAAO,CAAC;QACnF,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
1
+ {"version":3,"file":"host.js","names":[],"sources":["../src/host.ts"],"sourcesContent":["/**\n * The contract of a control of the page's own, as guide chapter 03 of the\n * player states it: the nearest <mattebox-player> above, through shadow\n * hosts. This package implements the contract from outside, as the cast\n * package does: the player exports no base class.\n */\nimport type { PlayerHost } from '@mattebox/player';\n\nexport type { PlayerHost };\n\nexport const PLAYER = 'mattebox-player';\n\n/** The parent, or the host of the shadow root `node` sits in, or null at the document. */\nexport function above(node: Node): Node | null {\n const parent = node.parentNode;\n if (parent !== null) return parent;\n return node instanceof ShadowRoot ? node.host : null;\n}\n\n/** The nearest player above `node`, or null outside one. It may not be upgraded yet. */\nexport function findPlayer(node: Node): HTMLElement | null {\n let current: Node | null = node;\n while (current !== null) {\n if (current instanceof HTMLElement && current.localName === PLAYER) return current;\n current = above(current);\n }\n return null;\n}\n\n/** The element focused inside `player`, through shadow roots, or null when focus is elsewhere. */\nexport function focusedIn(player: HTMLElement): HTMLElement | null {\n let active = document.activeElement;\n while (active?.shadowRoot?.activeElement != null) active = active.shadowRoot.activeElement;\n if (!(active instanceof HTMLElement) || active === player) return null;\n for (let node: Node | null = active; node !== null; node = above(node)) {\n if (node === player) return active;\n }\n return null;\n}\n"],"mappings":";AAUA,MAAa,SAAS;;AAGtB,SAAgB,MAAM,MAAyB;CAC7C,MAAM,SAAS,KAAK;CACpB,IAAI,WAAW,MAAM,OAAO;CAC5B,OAAO,gBAAgB,aAAa,KAAK,OAAO;AAClD;;AAGA,SAAgB,WAAW,MAAgC;CACzD,IAAI,UAAuB;CAC3B,OAAO,YAAY,MAAM;EACvB,IAAI,mBAAmB,eAAe,QAAQ,cAAA,mBAAsB,OAAO;EAC3E,UAAU,MAAM,OAAO;CACzB;CACA,OAAO;AACT;;AAGA,SAAgB,UAAU,QAAyC;CACjE,IAAI,SAAS,SAAS;CACtB,OAAO,QAAQ,YAAY,iBAAiB,MAAM,SAAS,OAAO,WAAW;CAC7E,IAAI,EAAE,kBAAkB,gBAAgB,WAAW,QAAQ,OAAO;CAClE,KAAK,IAAI,OAAoB,QAAQ,SAAS,MAAM,OAAO,MAAM,IAAI,GACnE,IAAI,SAAS,QAAQ,OAAO;CAE9B,OAAO;AACT"}
package/dist/index.d.ts CHANGED
@@ -3,6 +3,9 @@
3
3
  * on a TV. Importing this module registers the element; that is the
4
4
  * package's one side effect. It is a package of its own because most pages
5
5
  * never run on a TV, and a page that does not pays nothing for it.
6
+ *
7
+ * The game controller is the `./gamepad` entry, so a page with a remote
8
+ * alone pays nothing for it.
6
9
  */
7
10
  import { MbxSpatialNav } from './spatial-nav.js';
8
11
  export { MbxSpatialNav } from './spatial-nav.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,eAAO,MAAM,WAAW,oBAAoB,CAAC;AAM7C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,iBAAiB,EAAE,aAAa,CAAC;KAClC;CACF"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,eAAO,MAAM,WAAW,oBAAoB,CAAC;AAM7C,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,qBAAqB;QAC7B,iBAAiB,EAAE,aAAa,CAAC;KAClC;CACF"}
package/dist/index.js CHANGED
@@ -1,13 +1,16 @@
1
+ import { MbxSpatialNav } from "./spatial-nav.js";
2
+ // src/index.ts
1
3
  /**
2
- * @mattebox/player-spatial-nav: <mbx-spatial-nav>, the remote control for the player
3
- * on a TV. Importing this module registers the element; that is the
4
- * package's one side effect. It is a package of its own because most pages
5
- * never run on a TV, and a page that does not pays nothing for it.
6
- */
7
- import { MbxSpatialNav } from './spatial-nav.js';
8
- export { MbxSpatialNav } from './spatial-nav.js';
9
- export const SPATIAL_NAV = 'mbx-spatial-nav';
10
- if (customElements.get(SPATIAL_NAV) === undefined) {
11
- customElements.define(SPATIAL_NAV, MbxSpatialNav);
12
- }
4
+ * @mattebox/player-spatial-nav: <mbx-spatial-nav>, the remote control for the player
5
+ * on a TV. Importing this module registers the element; that is the
6
+ * package's one side effect. It is a package of its own because most pages
7
+ * never run on a TV, and a page that does not pays nothing for it.
8
+ *
9
+ * The game controller is the `./gamepad` entry, so a page with a remote
10
+ * alone pays nothing for it.
11
+ */
12
+ const SPATIAL_NAV = "mbx-spatial-nav";
13
+ if (customElements.get("mbx-spatial-nav") === void 0) customElements.define(SPATIAL_NAV, MbxSpatialNav);
14
+ export { MbxSpatialNav, SPATIAL_NAV };
15
+
13
16
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,MAAM,CAAC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAE7C,IAAI,cAAc,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,SAAS,EAAE,CAAC;IAClD,cAAc,CAAC,MAAM,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;AACpD,CAAC"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/**\n * @mattebox/player-spatial-nav: <mbx-spatial-nav>, the remote control for the player\n * on a TV. Importing this module registers the element; that is the\n * package's one side effect. It is a package of its own because most pages\n * never run on a TV, and a page that does not pays nothing for it.\n *\n * The game controller is the `./gamepad` entry, so a page with a remote\n * alone pays nothing for it.\n */\nimport { MbxSpatialNav } from './spatial-nav.js';\n\nexport { MbxSpatialNav } from './spatial-nav.js';\n\nexport const SPATIAL_NAV = 'mbx-spatial-nav';\n\nif (customElements.get(SPATIAL_NAV) === undefined) {\n customElements.define(SPATIAL_NAV, MbxSpatialNav);\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'mbx-spatial-nav': MbxSpatialNav;\n }\n}\n"],"mappings":";;;;;;;;;;;AAaA,MAAa,cAAc;AAE3B,IAAI,eAAe,IAAA,iBAAe,MAAM,KAAA,GACtC,eAAe,OAAO,aAAa,aAAa"}
package/dist/keys.js CHANGED
@@ -1,41 +1,42 @@
1
+ // src/keys.ts
1
2
  /**
2
- * The keys of a TV remote, as the standard `KeyboardEvent.key` names the
3
- * player reads. Tizen and webOS report several remote keys by `keyCode`
4
- * alone, with an empty, `Unidentified`, or vendor `key`. The arrows and
5
- * Enter come the same way on older sets.
6
- *
7
- * Back: 10009 on Tizen, 461 on webOS. Media keys: Samsung's Tizen TV key
8
- * list and LG's webOS TV key codes. The codes shared with a desktop
9
- * keyboard (the arrows, Enter) map only when `key` names nothing.
10
- */
3
+ * The keys of a TV remote, as the standard `KeyboardEvent.key` names the
4
+ * player reads. Tizen and webOS report several remote keys by `keyCode`
5
+ * alone, with an empty, `Unidentified`, or vendor `key`. The arrows and
6
+ * Enter come the same way on older sets.
7
+ *
8
+ * Back: 10009 on Tizen, 461 on webOS. Media keys: Samsung's Tizen TV key
9
+ * list and LG's webOS TV key codes. The codes shared with a desktop
10
+ * keyboard (the arrows, Enter) map only when `key` names nothing.
11
+ */
11
12
  const BY_CODE = {
12
- 10009: 'GoBack',
13
- 461: 'GoBack',
14
- 10252: 'MediaPlayPause',
15
- 415: 'MediaPlay',
16
- 19: 'MediaPause',
17
- 413: 'MediaStop',
18
- 417: 'MediaFastForward',
19
- 412: 'MediaRewind',
13
+ 10009: "GoBack",
14
+ 461: "GoBack",
15
+ 10252: "MediaPlayPause",
16
+ 415: "MediaPlay",
17
+ 19: "MediaPause",
18
+ 413: "MediaStop",
19
+ 417: "MediaFastForward",
20
+ 412: "MediaRewind"
20
21
  };
21
22
  /** Keys a desktop keyboard also sends, by code, for sets that leave `key` empty. */
22
23
  const PLAIN = {
23
- 13: 'Enter',
24
- 37: 'ArrowLeft',
25
- 38: 'ArrowUp',
26
- 39: 'ArrowRight',
27
- 40: 'ArrowDown',
24
+ 13: "Enter",
25
+ 37: "ArrowLeft",
26
+ 38: "ArrowUp",
27
+ 39: "ArrowRight",
28
+ 40: "ArrowDown"
28
29
  };
29
30
  /** The standard name of the key `event` reports: its own `key` when it has one the player reads. */
30
- export function keyOf(event) {
31
- const remote = BY_CODE[event.keyCode];
32
- if (remote !== undefined)
33
- return remote;
34
- const named = event.key !== '' && event.key !== 'Unidentified';
35
- return named ? event.key : (PLAIN[event.keyCode] ?? event.key);
31
+ function keyOf(event) {
32
+ const remote = BY_CODE[event.keyCode];
33
+ if (remote !== void 0) return remote;
34
+ return event.key !== "" && event.key !== "Unidentified" ? event.key : PLAIN[event.keyCode] ?? event.key;
36
35
  }
37
36
  /** The keys that go back: the remote's Back, the browser's, and Escape. */
38
- export function isBack(key) {
39
- return key === 'GoBack' || key === 'BrowserBack' || key === 'Escape';
37
+ function isBack(key) {
38
+ return key === "GoBack" || key === "BrowserBack" || key === "Escape";
40
39
  }
40
+ export { isBack, keyOf };
41
+
41
42
  //# sourceMappingURL=keys.js.map
package/dist/keys.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,OAAO,GAAqC;IAChD,KAAK,EAAE,QAAQ;IACf,GAAG,EAAE,QAAQ;IACb,KAAK,EAAE,gBAAgB;IACvB,GAAG,EAAE,WAAW;IAChB,EAAE,EAAE,YAAY;IAChB,GAAG,EAAE,WAAW;IAChB,GAAG,EAAE,kBAAkB;IACvB,GAAG,EAAE,aAAa;CACnB,CAAC;AAEF,oFAAoF;AACpF,MAAM,KAAK,GAAqC;IAC9C,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,SAAS;IACb,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,WAAW;CAChB,CAAC;AAEF,oGAAoG;AACpG,MAAM,UAAU,KAAK,CAAC,KAAoB;IACxC,MAAM,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IACtC,IAAI,MAAM,KAAK,SAAS;QAAE,OAAO,MAAM,CAAC;IACxC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,EAAE,IAAI,KAAK,CAAC,GAAG,KAAK,cAAc,CAAC;IAC/D,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACjE,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,MAAM,CAAC,GAAW;IAChC,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,aAAa,IAAI,GAAG,KAAK,QAAQ,CAAC;AACvE,CAAC"}
1
+ {"version":3,"file":"keys.js","names":[],"sources":["../src/keys.ts"],"sourcesContent":["/**\n * The keys of a TV remote, as the standard `KeyboardEvent.key` names the\n * player reads. Tizen and webOS report several remote keys by `keyCode`\n * alone, with an empty, `Unidentified`, or vendor `key`. The arrows and\n * Enter come the same way on older sets.\n *\n * Back: 10009 on Tizen, 461 on webOS. Media keys: Samsung's Tizen TV key\n * list and LG's webOS TV key codes. The codes shared with a desktop\n * keyboard (the arrows, Enter) map only when `key` names nothing.\n */\nconst BY_CODE: Readonly<Record<number, string>> = {\n 10009: 'GoBack',\n 461: 'GoBack',\n 10252: 'MediaPlayPause',\n 415: 'MediaPlay',\n 19: 'MediaPause',\n 413: 'MediaStop',\n 417: 'MediaFastForward',\n 412: 'MediaRewind',\n};\n\n/** Keys a desktop keyboard also sends, by code, for sets that leave `key` empty. */\nconst PLAIN: Readonly<Record<number, string>> = {\n 13: 'Enter',\n 37: 'ArrowLeft',\n 38: 'ArrowUp',\n 39: 'ArrowRight',\n 40: 'ArrowDown',\n};\n\n/** The standard name of the key `event` reports: its own `key` when it has one the player reads. */\nexport function keyOf(event: KeyboardEvent): string {\n const remote = BY_CODE[event.keyCode];\n if (remote !== undefined) return remote;\n const named = event.key !== '' && event.key !== 'Unidentified';\n return named ? event.key : (PLAIN[event.keyCode] ?? event.key);\n}\n\n/** The keys that go back: the remote's Back, the browser's, and Escape. */\nexport function isBack(key: string): boolean {\n return key === 'GoBack' || key === 'BrowserBack' || key === 'Escape';\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,UAA4C;CAChD,OAAO;CACP,KAAK;CACL,OAAO;CACP,KAAK;CACL,IAAI;CACJ,KAAK;CACL,KAAK;CACL,KAAK;AACP;;AAGA,MAAM,QAA0C;CAC9C,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,IAAI;AACN;;AAGA,SAAgB,MAAM,OAA8B;CAClD,MAAM,SAAS,QAAQ,MAAM;CAC7B,IAAI,WAAW,KAAA,GAAW,OAAO;CAEjC,OADc,MAAM,QAAQ,MAAM,MAAM,QAAQ,iBACjC,MAAM,MAAO,MAAM,MAAM,YAAY,MAAM;AAC5D;;AAGA,SAAgB,OAAO,KAAsB;CAC3C,OAAO,QAAQ,YAAY,QAAQ,iBAAiB,QAAQ;AAC9D"}
package/dist/navigate.js CHANGED
@@ -1,100 +1,93 @@
1
- export const DIRECTIONS = {
2
- ArrowUp: 'up',
3
- ArrowDown: 'down',
4
- ArrowLeft: 'left',
5
- ArrowRight: 'right',
1
+ // src/navigate.ts
2
+ const DIRECTIONS = {
3
+ ArrowUp: "up",
4
+ ArrowDown: "down",
5
+ ArrowLeft: "left",
6
+ ArrowRight: "right"
6
7
  };
7
- export const OPPOSITE = {
8
- up: 'down',
9
- down: 'up',
10
- left: 'right',
11
- right: 'left',
8
+ const OPPOSITE = {
9
+ up: "down",
10
+ down: "up",
11
+ left: "right",
12
+ right: "left"
12
13
  };
13
14
  function focusable(element) {
14
- if (!(element instanceof HTMLElement))
15
- return false;
16
- if (element instanceof HTMLButtonElement)
17
- return !element.disabled;
18
- if (element.getAttribute('role') === 'slider')
19
- return true;
20
- return element.hasAttribute('tabindex') && element.tabIndex >= 0;
15
+ if (!(element instanceof HTMLElement)) return false;
16
+ if (element instanceof HTMLButtonElement) return !element.disabled;
17
+ if (element.getAttribute("role") === "slider") return true;
18
+ return element.hasAttribute("tabindex") && element.tabIndex >= 0;
21
19
  }
22
20
  /** The focusable elements under `root`, in composed tree order, `root` itself left out. */
23
- export function candidates(root) {
24
- const out = [];
25
- const visit = (node) => {
26
- if (node !== root && focusable(node) && node.getClientRects().length > 0)
27
- out.push(node);
28
- const children = node instanceof HTMLSlotElement
29
- ? node.assignedElements({ flatten: true })
30
- : [...(node.shadowRoot?.children ?? []), ...(node.shadowRoot ? [] : node.children)];
31
- for (const child of children)
32
- visit(child);
33
- };
34
- visit(root);
35
- return out;
21
+ function candidates(root) {
22
+ const out = [];
23
+ const visit = (node) => {
24
+ if (node !== root && focusable(node) && node.getClientRects().length > 0) out.push(node);
25
+ const children = node instanceof HTMLSlotElement ? node.assignedElements({ flatten: true }) : [...node.shadowRoot?.children ?? [], ...node.shadowRoot ? [] : node.children];
26
+ for (const child of children) visit(child);
27
+ };
28
+ visit(root);
29
+ return out;
36
30
  }
37
31
  /** The gap between two spans on one axis: zero when they overlap. */
38
32
  function gap(a0, a1, b0, b1) {
39
- return Math.max(0, b0 - a1, a0 - b1);
33
+ return Math.max(0, b0 - a1, a0 - b1);
40
34
  }
41
- /** How far a control may overlap the edge it lies beyond, for rounding in layout. */
42
- const SLACK = 1;
43
35
  /**
44
- * The candidate nearest `from` on the side of `direction`, or null. A
45
- * candidate is on that side when it lies wholly beyond `from`'s edge, as in
46
- * the W3C CSS Spatial Navigation draft: the seek bar above a row of buttons
47
- * spans the row, and is up from each button, never right of one.
48
- *
49
- * Left and right stay in the row: only a candidate that overlaps `from`
50
- * vertically counts, so the arrows never jump to the row above because a
51
- * control there happens to start past this one's edge. Up and down prefer a
52
- * candidate in line, overlapping `from` horizontally, and take the nearest
53
- * other one when there is none, so a button at the end of a row still
54
- * reaches the bar above it.
55
- *
56
- * Among the candidates, the nearest along the arrow wins, then the nearest
57
- * across it; the earlier in the tree breaks a tie.
58
- */
59
- export function nearest(from, list, direction) {
60
- const row = direction === 'left' || direction === 'right';
61
- let best = null;
62
- let bestKey = [2, 0, 0];
63
- for (const element of list) {
64
- const to = element.getBoundingClientRect();
65
- let along;
66
- if (direction === 'right')
67
- along = to.left - from.right;
68
- else if (direction === 'left')
69
- along = from.left - to.right;
70
- else if (direction === 'down')
71
- along = to.top - from.bottom;
72
- else
73
- along = from.top - to.bottom;
74
- if (along < -SLACK)
75
- continue;
76
- const side = row
77
- ? gap(from.top, from.bottom, to.top, to.bottom)
78
- : gap(from.left, from.right, to.left, to.right);
79
- const inLine = side === 0 ? 0 : 1;
80
- if (row && inLine === 1)
81
- continue;
82
- const key = [inLine, Math.max(0, along), side];
83
- if (before(key, bestKey)) {
84
- best = element;
85
- bestKey = key;
86
- }
87
- }
88
- return best;
36
+ * The candidate nearest `from` on the side of `direction`, or null. A
37
+ * candidate is on that side when it lies wholly beyond `from`'s edge, as in
38
+ * the W3C CSS Spatial Navigation draft: the seek bar above a row of buttons
39
+ * spans the row, and is up from each button, never right of one.
40
+ *
41
+ * Left and right stay in the row: only a candidate that overlaps `from`
42
+ * vertically counts, so the arrows never jump to the row above because a
43
+ * control there happens to start past this one's edge. Up and down prefer a
44
+ * candidate in line, overlapping `from` horizontally, and take the nearest
45
+ * other one when there is none, so a button at the end of a row still
46
+ * reaches the bar above it.
47
+ *
48
+ * Among the candidates, the nearest along the arrow wins, then the nearest
49
+ * across it; the earlier in the tree breaks a tie.
50
+ */
51
+ function nearest(from, list, direction) {
52
+ const row = direction === "left" || direction === "right";
53
+ let best = null;
54
+ let bestKey = [
55
+ 2,
56
+ 0,
57
+ 0
58
+ ];
59
+ for (const element of list) {
60
+ const to = element.getBoundingClientRect();
61
+ let along;
62
+ if (direction === "right") along = to.left - from.right;
63
+ else if (direction === "left") along = from.left - to.right;
64
+ else if (direction === "down") along = to.top - from.bottom;
65
+ else along = from.top - to.bottom;
66
+ if (along < -1) continue;
67
+ const side = row ? gap(from.top, from.bottom, to.top, to.bottom) : gap(from.left, from.right, to.left, to.right);
68
+ const inLine = side === 0 ? 0 : 1;
69
+ if (row && inLine === 1) continue;
70
+ const key = [
71
+ inLine,
72
+ Math.max(0, along),
73
+ side
74
+ ];
75
+ if (before(key, bestKey)) {
76
+ best = element;
77
+ bestKey = key;
78
+ }
79
+ }
80
+ return best;
89
81
  }
90
82
  /** Whether `a` ranks before `b`: compared item by item. */
91
83
  function before(a, b) {
92
- for (let i = 0; i < a.length; i += 1) {
93
- const x = a[i] ?? 0;
94
- const y = b[i] ?? 0;
95
- if (x !== y)
96
- return x < y;
97
- }
98
- return false;
84
+ for (let i = 0; i < a.length; i += 1) {
85
+ const x = a[i] ?? 0;
86
+ const y = b[i] ?? 0;
87
+ if (x !== y) return x < y;
88
+ }
89
+ return false;
99
90
  }
91
+ export { DIRECTIONS, OPPOSITE, candidates, nearest };
92
+
100
93
  //# sourceMappingURL=navigate.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"navigate.js","sourceRoot":"","sources":["../src/navigate.ts"],"names":[],"mappings":"AAaA,MAAM,CAAC,MAAM,UAAU,GAAwC;IAC7D,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,MAAM;IACjB,SAAS,EAAE,MAAM;IACjB,UAAU,EAAE,OAAO;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAA2C;IAC9D,EAAE,EAAE,MAAM;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,MAAM;CACd,CAAC;AAEF,SAAS,SAAS,CAAC,OAAgB;IACjC,IAAI,CAAC,CAAC,OAAO,YAAY,WAAW,CAAC;QAAE,OAAO,KAAK,CAAC;IACpD,IAAI,OAAO,YAAY,iBAAiB;QAAE,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC;IACnE,IAAI,OAAO,CAAC,YAAY,CAAC,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,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,IAAI,CAAU,CAAC;QACxD,IAAI,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;YACzB,IAAI,GAAG,OAAO,CAAC;YACf,OAAO,GAAG,GAAG,CAAC;QAChB,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,2DAA2D;AAC3D,SAAS,MAAM,CAAC,CAAoB,EAAE,CAAoB;IACxD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC;QACrC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACpB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACpB,IAAI,CAAC,KAAK,CAAC;YAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"navigate.js","names":[],"sources":["../src/navigate.ts"],"sourcesContent":["/**\n * Where focus goes on an arrow: the candidates, and the nearest one on the\n * side of the arrow.\n *\n * The candidates are every focusable element in the player's composed tree:\n * through open shadow roots, which hold each control's button, and through\n * slot assignment, which is how the controls are placed. Focusable means a\n * `button`, a `role=\"slider\"`, or a `tabindex` of zero or more; disabled,\n * and not laid out, which covers `hidden`, `display: none`, and a collapsed\n * control, rules one out.\n */\nexport type Direction = 'up' | 'down' | 'left' | 'right';\n\nexport const DIRECTIONS: Readonly<Record<string, Direction>> = {\n ArrowUp: 'up',\n ArrowDown: 'down',\n ArrowLeft: 'left',\n ArrowRight: 'right',\n};\n\nexport const OPPOSITE: Readonly<Record<Direction, Direction>> = {\n up: 'down',\n down: 'up',\n left: 'right',\n right: 'left',\n};\n\nfunction focusable(element: Element): element is HTMLElement {\n if (!(element instanceof HTMLElement)) return false;\n if (element instanceof HTMLButtonElement) return !element.disabled;\n if (element.getAttribute('role') === 'slider') return true;\n return element.hasAttribute('tabindex') && element.tabIndex >= 0;\n}\n\n/** The focusable elements under `root`, in composed tree order, `root` itself left out. */\nexport function candidates(root: Element): HTMLElement[] {\n const out: HTMLElement[] = [];\n const visit = (node: Element): void => {\n if (node !== root && focusable(node) && node.getClientRects().length > 0) out.push(node);\n const children =\n node instanceof HTMLSlotElement\n ? node.assignedElements({ flatten: true })\n : [...(node.shadowRoot?.children ?? []), ...(node.shadowRoot ? [] : node.children)];\n for (const child of children) visit(child);\n };\n visit(root);\n return out;\n}\n\n/** The gap between two spans on one axis: zero when they overlap. */\nfunction gap(a0: number, a1: number, b0: number, b1: number): number {\n return Math.max(0, b0 - a1, a0 - b1);\n}\n\n/** How far a control may overlap the edge it lies beyond, for rounding in layout. */\nconst SLACK = 1;\n\n/**\n * The candidate nearest `from` on the side of `direction`, or null. A\n * candidate is on that side when it lies wholly beyond `from`'s edge, as in\n * the W3C CSS Spatial Navigation draft: the seek bar above a row of buttons\n * spans the row, and is up from each button, never right of one.\n *\n * Left and right stay in the row: only a candidate that overlaps `from`\n * vertically counts, so the arrows never jump to the row above because a\n * control there happens to start past this one's edge. Up and down prefer a\n * candidate in line, overlapping `from` horizontally, and take the nearest\n * other one when there is none, so a button at the end of a row still\n * reaches the bar above it.\n *\n * Among the candidates, the nearest along the arrow wins, then the nearest\n * across it; the earlier in the tree breaks a tie.\n */\nexport function nearest(\n from: DOMRect,\n list: readonly HTMLElement[],\n direction: Direction,\n): HTMLElement | null {\n const row = direction === 'left' || direction === 'right';\n let best: HTMLElement | null = null;\n let bestKey: readonly [number, number, number] = [2, 0, 0];\n for (const element of list) {\n const to = element.getBoundingClientRect();\n let along: number;\n if (direction === 'right') along = to.left - from.right;\n else if (direction === 'left') along = from.left - to.right;\n else if (direction === 'down') along = to.top - from.bottom;\n else along = from.top - to.bottom;\n if (along < -SLACK) continue;\n const side = row\n ? gap(from.top, from.bottom, to.top, to.bottom)\n : gap(from.left, from.right, to.left, to.right);\n const inLine = side === 0 ? 0 : 1;\n if (row && inLine === 1) continue;\n const key = [inLine, Math.max(0, along), side] as const;\n if (before(key, bestKey)) {\n best = element;\n bestKey = key;\n }\n }\n return best;\n}\n\n/** Whether `a` ranks before `b`: compared item by item. */\nfunction before(a: readonly number[], b: readonly number[]): boolean {\n for (let i = 0; i < a.length; i += 1) {\n const x = a[i] ?? 0;\n const y = b[i] ?? 0;\n if (x !== y) return x < y;\n }\n return false;\n}\n"],"mappings":";AAaA,MAAa,aAAkD;CAC7D,SAAS;CACT,WAAW;CACX,WAAW;CACX,YAAY;AACd;AAEA,MAAa,WAAmD;CAC9D,IAAI;CACJ,MAAM;CACN,MAAM;CACN,OAAO;AACT;AAEA,SAAS,UAAU,SAA0C;CAC3D,IAAI,EAAE,mBAAmB,cAAc,OAAO;CAC9C,IAAI,mBAAmB,mBAAmB,OAAO,CAAC,QAAQ;CAC1D,IAAI,QAAQ,aAAa,MAAM,MAAM,UAAU,OAAO;CACtD,OAAO,QAAQ,aAAa,UAAU,KAAK,QAAQ,YAAY;AACjE;;AAGA,SAAgB,WAAW,MAA8B;CACvD,MAAM,MAAqB,CAAC;CAC5B,MAAM,SAAS,SAAwB;EACrC,IAAI,SAAS,QAAQ,UAAU,IAAI,KAAK,KAAK,eAAe,CAAC,CAAC,SAAS,GAAG,IAAI,KAAK,IAAI;EACvF,MAAM,WACJ,gBAAgB,kBACZ,KAAK,iBAAiB,EAAE,SAAS,KAAK,CAAC,IACvC,CAAC,GAAI,KAAK,YAAY,YAAY,CAAC,GAAI,GAAI,KAAK,aAAa,CAAC,IAAI,KAAK,QAAS;EACtF,KAAK,MAAM,SAAS,UAAU,MAAM,KAAK;CAC3C;CACA,MAAM,IAAI;CACV,OAAO;AACT;;AAGA,SAAS,IAAI,IAAY,IAAY,IAAY,IAAoB;CACnE,OAAO,KAAK,IAAI,GAAG,KAAK,IAAI,KAAK,EAAE;AACrC;;;;;;;;;;;;;;;;;AAqBA,SAAgB,QACd,MACA,MACA,WACoB;CACpB,MAAM,MAAM,cAAc,UAAU,cAAc;CAClD,IAAI,OAA2B;CAC/B,IAAI,UAA6C;EAAC;EAAG;EAAG;CAAC;CACzD,KAAK,MAAM,WAAW,MAAM;EAC1B,MAAM,KAAK,QAAQ,sBAAsB;EACzC,IAAI;EACJ,IAAI,cAAc,SAAS,QAAQ,GAAG,OAAO,KAAK;OAC7C,IAAI,cAAc,QAAQ,QAAQ,KAAK,OAAO,GAAG;OACjD,IAAI,cAAc,QAAQ,QAAQ,GAAG,MAAM,KAAK;OAChD,QAAQ,KAAK,MAAM,GAAG;EAC3B,IAAI,QAAQ,IAAQ;EACpB,MAAM,OAAO,MACT,IAAI,KAAK,KAAK,KAAK,QAAQ,GAAG,KAAK,GAAG,MAAM,IAC5C,IAAI,KAAK,MAAM,KAAK,OAAO,GAAG,MAAM,GAAG,KAAK;EAChD,MAAM,SAAS,SAAS,IAAI,IAAI;EAChC,IAAI,OAAO,WAAW,GAAG;EACzB,MAAM,MAAM;GAAC;GAAQ,KAAK,IAAI,GAAG,KAAK;GAAG;EAAI;EAC7C,IAAI,OAAO,KAAK,OAAO,GAAG;GACxB,OAAO;GACP,UAAU;EACZ;CACF;CACA,OAAO;AACT;;AAGA,SAAS,OAAO,GAAsB,GAA+B;CACnE,KAAK,IAAI,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK,GAAG;EACpC,MAAM,IAAI,EAAE,MAAM;EAClB,MAAM,IAAI,EAAE,MAAM;EAClB,IAAI,MAAM,GAAG,OAAO,IAAI;CAC1B;CACA,OAAO;AACT"}
package/dist/pad.d.ts ADDED
@@ -0,0 +1,48 @@
1
+ /**
2
+ * The buttons of a game controller, the makes the player tells apart, and
3
+ * the default mapping from buttons to the player's actions.
4
+ *
5
+ * Buttons are named by place, not by letter: `south` is the lower face
6
+ * button on every make, A on an Xbox pad, Cross on a PlayStation pad and B
7
+ * on a Nintendo pad. The indices are the Gamepad API's `standard` layout.
8
+ *
9
+ * No console maker publishes a mapping for a video player. The defaults
10
+ * follow what their own video apps share: the lower face button selects and
11
+ * the right one goes back, Nintendo's the other way round as its letters
12
+ * are; the shoulders go to the previous and next item; the triggers scan
13
+ * while held.
14
+ */
15
+ /** A button of a controller in the standard layout, by place. */
16
+ export type PadButton = 'south' | 'east' | 'west' | 'north' | 'lb' | 'rb' | 'lt' | 'rt' | 'select' | 'start' | 'ls' | 'rs' | 'up' | 'down' | 'left' | 'right';
17
+ /** Every button, in the standard layout's order: the index is the button's. */
18
+ export declare const BUTTONS: readonly PadButton[];
19
+ /** An action of the player a button can take. A page may name its own, which only fires the event. */
20
+ export type PadAction = 'up' | 'down' | 'left' | 'right' | 'activate' | 'back' | 'play-pause' | 'previous' | 'next' | 'rewind' | 'fast-forward' | 'subtitles' | 'mute' | 'fullscreen' | 'help';
21
+ /**
22
+ * A mapping from buttons to actions: a `PadAction`, or a name of the
23
+ * page's own, which only fires `gamepadaction`. Null unbinds a button.
24
+ */
25
+ export type PadMap = Partial<Record<PadButton, string | null>>;
26
+ /** The makes of controller whose buttons are drawn differently. */
27
+ export type PadKind = 'xbox' | 'playstation' | 'nintendo';
28
+ /** The default mapping for `kind`: a Nintendo pad selects with the right face button, its A. */
29
+ export declare function defaults(kind: PadKind): Record<PadButton, PadAction | null>;
30
+ /**
31
+ * The make of a pad, from the id the browser reports: Chromium writes
32
+ * `Vendor: 054c`, Firefox starts the id with `054c-`. Any other pad is
33
+ * taken for an Xbox pad, the layout most pads follow.
34
+ */
35
+ export declare function kindOf(id: string): PadKind;
36
+ /** What each make prints on each button, for the controls bubble. */
37
+ export declare const GLYPHS: Readonly<Record<PadKind, Readonly<Record<PadButton, string>>>>;
38
+ /** The PlayStation symbols by name, for a screen reader, which may not read the symbol. */
39
+ export declare const SPOKEN: Readonly<Record<string, string>>;
40
+ /**
41
+ * The overrides in a `map` attribute: `button:action` pairs apart by spaces,
42
+ * as `rb:fast-forward west:mute select:none`. `none` unbinds the button. A
43
+ * pair with an unknown button is left out.
44
+ */
45
+ export declare function parseMap(text: string | null): PadMap;
46
+ /** The mapping for `kind` with the overrides on top. */
47
+ export declare function mapping(kind: PadKind, ...overrides: readonly PadMap[]): Record<PadButton, string | null>;
48
+ //# sourceMappingURL=pad.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pad.d.ts","sourceRoot":"","sources":["../src/pad.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,iEAAiE;AACjE,MAAM,MAAM,SAAS,GACjB,OAAO,GACP,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,QAAQ,GACR,OAAO,GACP,IAAI,GACJ,IAAI,GACJ,IAAI,GACJ,MAAM,GACN,MAAM,GACN,OAAO,CAAC;AAEZ,+EAA+E;AAC/E,eAAO,MAAM,OAAO,EAAE,SAAS,SAAS,EAiBvC,CAAC;AAEF,sGAAsG;AACtG,MAAM,MAAM,SAAS,GACjB,IAAI,GACJ,MAAM,GACN,MAAM,GACN,OAAO,GACP,UAAU,GACV,MAAM,GACN,YAAY,GACZ,UAAU,GACV,MAAM,GACN,QAAQ,GACR,cAAc,GACd,WAAW,GACX,MAAM,GACN,YAAY,GACZ,MAAM,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC;AAE/D,mEAAmE;AACnE,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,aAAa,GAAG,UAAU,CAAC;AAsB1D,gGAAgG;AAChG,wBAAgB,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,CAAC,CAQ3E;AAWD;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAM1C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