@mattebox/player-spatial-nav 0.2.0 → 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.
- package/README.md +22 -11
- package/dist/cdn/mattebox-player-spatial-nav-gamepad.min.js +1 -0
- package/dist/cdn/mattebox-player-spatial-nav.min.js +1 -1
- package/dist/component.js +40 -44
- package/dist/component.js.map +1 -1
- package/dist/es2015/gamepad-help.js +139 -0
- package/dist/es2015/gamepad-index.js +17 -0
- package/dist/es2015/gamepad.js +321 -0
- package/dist/es2015/host.js +10 -1
- package/dist/es2015/index.js +3 -0
- package/dist/es2015/pad.js +157 -0
- package/dist/es2015/spatial-nav.js +2 -7
- package/dist/gamepad-help.d.ts +30 -0
- package/dist/gamepad-help.d.ts.map +1 -0
- package/dist/gamepad-help.js +137 -0
- package/dist/gamepad-help.js.map +1 -0
- package/dist/gamepad-index.d.ts +24 -0
- package/dist/gamepad-index.d.ts.map +1 -0
- package/dist/gamepad-index.js +19 -0
- package/dist/gamepad-index.js.map +1 -0
- package/dist/gamepad.d.ts +98 -0
- package/dist/gamepad.d.ts.map +1 -0
- package/dist/gamepad.js +316 -0
- package/dist/gamepad.js.map +1 -0
- package/dist/host.d.ts +2 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +23 -14
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -11
- package/dist/index.js.map +1 -1
- package/dist/keys.js +31 -30
- package/dist/keys.js.map +1 -1
- package/dist/navigate.js +78 -85
- package/dist/navigate.js.map +1 -1
- package/dist/pad.d.ts +48 -0
- package/dist/pad.d.ts.map +1 -0
- package/dist/pad.js +157 -0
- package/dist/pad.js.map +1 -0
- package/dist/spatial-nav.d.ts.map +1 -1
- package/dist/spatial-nav.js +173 -201
- package/dist/spatial-nav.js.map +1 -1
- package/package.json +12 -6
package/README.md
CHANGED
|
@@ -3,16 +3,20 @@
|
|
|
3
3
|
@mattebox/player-spatial-nav
|
|
4
4
|
</h1>
|
|
5
5
|
|
|
6
|
-
`<mbx-spatial-nav>` for the
|
|
6
|
+
`<mbx-spatial-nav>` and `<mbx-gamepad>` for the
|
|
7
7
|
[Mattebox player](https://github.com/jboix/mattebox-player): the remote
|
|
8
|
-
control on a TV.
|
|
8
|
+
control on a TV, and a game controller anywhere.
|
|
9
9
|
|
|
10
10
|
- The arrows move focus to the nearest control on their side. The opposite arrow goes back.
|
|
11
11
|
- On a slider, left and right seek or set the volume. In an open menu, every arrow is the menu's.
|
|
12
12
|
- The remote's Back goes back a step: the menu, then the controls, then your application.
|
|
13
13
|
- The remote's media keys reach the player under their standard names, on Tizen and webOS too.
|
|
14
|
+
- A game controller moves focus, selects, goes back, plays, scans and skips chapters. You change any button.
|
|
15
|
+
- `<mbx-gamepad-help>` lists what each button does, as the make of the pad prints it.
|
|
14
16
|
|
|
15
|
-
The import registers
|
|
17
|
+
The import registers `<mbx-spatial-nav>`. The `/gamepad` entry registers it
|
|
18
|
+
with `<mbx-gamepad>` and `<mbx-gamepad-help>`, so a page with a remote alone
|
|
19
|
+
pays nothing for the controller. It is a package of its own because most
|
|
16
20
|
pages never run on a TV.
|
|
17
21
|
|
|
18
22
|
```sh
|
|
@@ -22,6 +26,8 @@ npm install @mattebox/player-spatial-nav @mattebox/player mattebox
|
|
|
22
26
|
```html
|
|
23
27
|
<mattebox-player src="https://example.com/vod/master.m3u8" controls="custom">
|
|
24
28
|
<mbx-spatial-nav></mbx-spatial-nav>
|
|
29
|
+
<mbx-gamepad map="west:mute"></mbx-gamepad>
|
|
30
|
+
<mbx-gamepad-help></mbx-gamepad-help>
|
|
25
31
|
<mbx-control-bar>
|
|
26
32
|
<mbx-seek-bar key-mode="preview"></mbx-seek-bar>
|
|
27
33
|
<mbx-play-button></mbx-play-button>
|
|
@@ -32,23 +38,28 @@ npm install @mattebox/player-spatial-nav @mattebox/player mattebox
|
|
|
32
38
|
|
|
33
39
|
<script type="module">
|
|
34
40
|
import '@mattebox/player';
|
|
35
|
-
import '@mattebox/player-spatial-nav';
|
|
41
|
+
import '@mattebox/player-spatial-nav/gamepad';
|
|
36
42
|
</script>
|
|
37
43
|
```
|
|
38
44
|
|
|
39
|
-
| Attribute
|
|
40
|
-
|
|
|
41
|
-
| `initial`
|
|
45
|
+
| Element | Attribute | What it does |
|
|
46
|
+
| ------------------ | ------------------------------- | -------------------------------------------------------------------------- |
|
|
47
|
+
| `mbx-spatial-nav` | `initial` | The tag of the control the first key focuses. `mbx-play-button` by default |
|
|
48
|
+
| `mbx-gamepad` | `map` | Buttons to change, as `button:action` pairs. `none` unbinds one |
|
|
49
|
+
| `mbx-gamepad-help` | `manual`, `close-ms`, `label-*` | Opens only on the help action; closes after; names the actions |
|
|
42
50
|
|
|
43
|
-
| Event
|
|
44
|
-
|
|
|
45
|
-
| `navigateout`
|
|
51
|
+
| Event | When |
|
|
52
|
+
| ------------------- | -------------------------------------------------------------------------------------------------- |
|
|
53
|
+
| `navigateout` | An arrow finds no control on its side. `detail` is the direction. Your application moves focus out |
|
|
54
|
+
| `gamepadaction` | A button is pressed, before its action. Cancel it to take the action |
|
|
55
|
+
| `gamepadconnect` | A pad connects. `detail` holds its `kind` and `id` |
|
|
56
|
+
| `gamepaddisconnect` | A pad goes |
|
|
46
57
|
|
|
47
58
|
Your application registers the remote's media keys with the platform, for
|
|
48
59
|
example `tizen.tvinputdevice.registerKey` on Tizen. The player never does.
|
|
49
60
|
|
|
50
61
|
The [player guide](https://github.com/jboix/mattebox-player/blob/main/docs/guide/06-tv.md)
|
|
51
|
-
covers the
|
|
62
|
+
covers the elements in chapter 06.
|
|
52
63
|
|
|
53
64
|
## License
|
|
54
65
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var matteboxPlayerSpatialNav=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){let t=e.parentNode;return t===null?e instanceof ShadowRoot?e.host:null:t}function n(e){let n=e;for(;n!==null;){if(n instanceof HTMLElement&&n.localName===`mattebox-player`)return n;n=t(n)}return null}function r(e){var n;let r=document.activeElement;for(;(r==null||(n=r.shadowRoot)==null?void 0:n.activeElement)!=null;)r=r.shadowRoot.activeElement;if(!(r instanceof HTMLElement)||r===e)return null;for(let n=r;n!==null;n=t(n))if(n===e)return r;return null}var i=class extends HTMLElement{constructor(){super(),this.player=null,this.offs=[],this.epoch=0}connectedCallback(){let e=n(this);if(e===null)return;this.epoch+=1;let t=this.epoch,r=()=>{t===this.epoch&&this.isConnected&&(customElements.upgrade(e),`media`in e&&(this.player=e,this.attach(this.player)))};`media`in e?r():customElements.whenDefined(`mattebox-player`).then(r)}disconnectedCallback(){this.epoch+=1;for(let e of this.offs)e();this.offs=[],this.player=null}on(e,t,n,r){e.addEventListener(t,n,r),this.offs.push(()=>{e.removeEventListener(t,n,r)})}};let a=[`south`,`east`,`west`,`north`,`lb`,`rb`,`lt`,`rt`,`select`,`start`,`ls`,`rs`,`up`,`down`,`left`,`right`],o={up:`up`,down:`down`,left:`left`,right:`right`,south:`activate`,east:`back`,west:null,north:`subtitles`,lb:`previous`,rb:`next`,lt:`rewind`,rt:`fast-forward`,select:`help`,start:`play-pause`,ls:null,rs:null};function s(e){let t=Object.assign({},o);return e===`nintendo`&&(t.south=`back`,t.east=`activate`),t}let c={"054c":`playstation`,"057e":`nintendo`},l=[[/dualsense|dualshock|playstation|\bps[345]\b/i,`playstation`],[/nintendo|switch|joy-?con|pro controller/i,`nintendo`]];function u(e){var t,n,r;let i=(t=/vendor:\s*([0-9a-f]{4})/i.exec(e))==null?/^([0-9a-f]{4})-[0-9a-f]{4}-/i.exec(e):t,a=i==null||(n=i[1])==null?void 0:n.toLowerCase();if(a!==void 0)return(r=c[a])==null?`xbox`:r;for(let[t,n]of l)if(t.test(e))return n;return`xbox`}let d={xbox:{south:`A`,east:`B`,west:`X`,north:`Y`,lb:`LB`,rb:`RB`,lt:`LT`,rt:`RT`,select:`View`,start:`Menu`,ls:`LS`,rs:`RS`,up:`↑`,down:`↓`,left:`←`,right:`→`},playstation:{south:`✕`,east:`○`,west:`□`,north:`△`,lb:`L1`,rb:`R1`,lt:`L2`,rt:`R2`,select:`Create`,start:`Options`,ls:`L3`,rs:`R3`,up:`↑`,down:`↓`,left:`←`,right:`→`},nintendo:{south:`B`,east:`A`,west:`Y`,north:`X`,lb:`L`,rb:`R`,lt:`ZL`,rt:`ZR`,select:`−`,start:`+`,ls:`LS`,rs:`RS`,up:`↑`,down:`↓`,left:`←`,right:`→`}},f={"✕":`Cross`,"○":`Circle`,"□":`Square`,"△":`Triangle`};function p(e){let t={};for(let n of(e==null?``:e).split(/\s+/)){let[e,r]=n.split(`:`);e!==void 0&&r!==void 0&&r!==``&&a.includes(e)&&(t[e]=r===`none`?null:r)}return t}function m(e,...t){let n=s(e);for(let e of t)for(let t of a){let r=e[t];r!==void 0&&(n[t]=r)}return n}let h=`focus-ring`,g={up:`ArrowUp`,down:`ArrowDown`,left:`ArrowLeft`,right:`ArrowRight`},_=/* @__PURE__ */ new Set([`up`,`down`,`left`,`right`,`rewind`,`fast-forward`]);var v=class extends i{constructor(){super(),this.held=/* @__PURE__ */ new Map,this.frame=0,this.own={},this.last=`xbox`}get map(){return Object.assign({},this.own)}set map(e){this.own=Object.assign({},e)}get kind(){return this.last}bindings(e=this.last){return m(e,p(this.getAttribute(`map`)),this.own)}disconnectedCallback(){var e;this.stop(),(e=this.player)==null||e.removeAttribute(h),super.disconnectedCallback()}attach(e){let t=navigator;`gamepadInputEmulation`in t&&(t.gamepadInputEmulation=`gamepad`),this.on(window,`gamepadconnected`,t=>{let n=t.gamepad;this.last=u(n.id),this.tell(`gamepadconnect`,n),this.start(e)}),this.on(window,`gamepaddisconnected`,e=>{let t=e.gamepad;this.held.delete(t.index),this.tell(`gamepaddisconnect`,t)}),this.on(document,`visibilitychange`,()=>this.start(e)),this.on(e,`pointerdown`,()=>e.removeAttribute(h),{capture:!0}),this.start(e)}tell(e,t){let n={kind:u(t.id),id:t.id};this.dispatchEvent(new CustomEvent(e,{detail:n,bubbles:!0,composed:!0}))}pads(){if(typeof navigator.getGamepads!=`function`)return[];let e=[];for(let t of navigator.getGamepads())(t==null?void 0:t.connected)===!0&&e.push(t);return e}start(e){this.frame!==0||document.hidden||this.pads().length===0||(this.frame=requestAnimationFrame(t=>this.tick(e,t)))}stop(){this.frame!==0&&cancelAnimationFrame(this.frame),this.frame=0,this.held.clear()}tick(e,t){this.frame=0;let n=this.pads();if(n.length===0||document.hidden||this.player!==e)this.held.clear();else{for(let r of n)this.read(e,r,t);this.frame=requestAnimationFrame(t=>this.tick(e,t))}}read(e,t,n){let r=u(t.id),i=this.held.get(t.index);i===void 0&&(i=/* @__PURE__ */ new Map,this.held.set(t.index,i));let o=this.bindings(r);for(let[s,c]of a.entries()){let a=this.value(t,s,c),l=i.get(c);if(a===0){i.delete(c);continue}let u=o[c];l===void 0?(this.last=r,i.set(c,{next:n+(u===`rewind`||u===`fast-forward`?300:400)}),u!=null&&this.act(e,u,c,r)):u!=null&&_.has(u)&&n>=l.next&&(l.next=n+(u===`rewind`||u===`fast-forward`?100+(1-a)*300:120),this.act(e,u,c,r))}}value(e,t,n){var r,i;let a=e.buttons[t],o=n===`lt`||n===`rt`,s=a===void 0?0:a.pressed?Math.max(a.value,.5):a.value;s<(o?.15:.5)&&(s=0);let c=(r=e.axes[0])==null?0:r,l=(i=e.axes[1])==null?0:i;return(n===`left`?-c:n===`right`?c:n===`up`?-l:n===`down`?l:0)>.5?Math.max(s,1):s}act(e,t,n,r){let i=new CustomEvent(`gamepadaction`,{detail:{action:t,button:n,kind:r},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(i)&&(e.toggleAttribute(h,!0),this.run(e,t))}run(e,t){let n=e.media,i=g[t];if(i!==void 0){var a;this.key((a=r(e))==null?e:a,i)}else switch(t){case`activate`:this.activate(e);break;case`back`:this.back(e);break;case`play-pause`:this.key(e,`MediaPlayPause`)&&y(n);break;case`rewind`:this.key(e,`MediaRewind`)&&(n.currentTime=Math.max(0,n.currentTime-5));break;case`fast-forward`:this.key(e,`MediaFastForward`)&&(n.currentTime+=5);break;case`previous`:this.skip(e,-1);break;case`next`:this.skip(e,1);break;case`subtitles`:this.press(e,`mbx-subtitles-menu`);break;case`mute`:this.key(e,`m`)&&(n.muted=!n.muted);break;case`fullscreen`:this.key(e,`f`);break;case`help`:var o;(o=e.querySelector(`mbx-gamepad-help`))==null||o.toggleAttribute(`open`)}}activate(e){let t=r(e);t===null||e.hasAttribute(`idle`)?this.key(e,`MediaPlayPause`)&&y(e.media):this.key(t,`Enter`)&&t instanceof HTMLButtonElement&&t.click()}back(e){let t=r(e);t===null&&e.hasAttribute(`fullscreen`)?this.key(e,`f`):this.key(t==null?e:t,`GoBack`)}skip(e,t){var n,r,i;let a=e.media,o=(n=e.chapters)==null?[]:n,s=a.currentTime,c=-1;for(let[e,t]of o.entries())t.start<=s&&(c=e);let l=t===1?o[c+1]:c>=0&&s-((r=(i=o[c])==null?void 0:i.start)==null?0:r)>3?o[c]:o[c-1];l===void 0?this.press(e,t===1?`mbx-next-button`:`mbx-previous-button`):a.currentTime=l.start}press(e,t){var n;let r=(n=e.querySelector(t))==null||(n=n.shadowRoot)==null?void 0:n.querySelector(`button`);r!=null&&r.getClientRects().length!==0&&r.click()}key(e,t){return e.dispatchEvent(new KeyboardEvent(`keydown`,{key:t,bubbles:!0,composed:!0,cancelable:!0}))}};function y(e){e.paused?e.play().catch(()=>void 0):e.pause()}let b=[[`move`,`Move`],[`activate`,`Select`],[`back`,`Back`],[`play-pause`,`Play or pause`],[`rewind`,`Rewind`],[`fast-forward`,`Fast forward`],[`previous`,`Previous`],[`next`,`Next`],[`subtitles`,`Subtitles`],[`mute`,`Mute`],[`fullscreen`,`Fullscreen`],[`help`,`Controls`]],x=/* @__PURE__ */ new Set([`up`,`down`,`left`,`right`]);var S=class extends i{static get observedAttributes(){return[`open`]}constructor(){super();let e=this.attachShadow({mode:`open`}),t=document.createElement(`style`);t.textContent=`:host{right:var(--mbx-gap,12px);z-index:3;max-width:calc(100% - 2 * var(--mbx-gap,12px));color:var(--mbx-text,#fff);font-family:var(--mbx-font,system-ui, sans-serif);pointer-events:none;font-size:14px;display:none;position:absolute;bottom:72px}:host([open]){display:block}[part~=bubble]{padding:var(--mbx-pad,12px) calc(var(--mbx-pad,12px) * 1.5);border-radius:var(--mbx-radius,8px);background:#000000d1}[part~=heading]{margin:0 0 8px;font-size:14px;font-weight:600}[part~=list]{grid-template-columns:auto auto;align-items:center;gap:6px 16px;margin:0;display:grid}dt{text-align:right;white-space:nowrap}dd{margin:0}[part~=button]{text-align:center;border:1px solid #ffffff80;border-radius:4px;min-width:1.6em;padding:1px 6px;font-family:inherit;font-size:12px;line-height:18px;display:inline-block}dt [part~=button]+[part~=button]{margin-left:4px}`;let n=document.createElement(`section`);n.setAttribute(`part`,`bubble`),this.heading=document.createElement(`h2`),this.heading.setAttribute(`part`,`heading`),this.heading.id=`heading`,n.setAttribute(`aria-labelledby`,`heading`),this.list=document.createElement(`dl`),this.list.setAttribute(`part`,`list`),n.append(this.heading,this.list),e.append(t,n),this.timer=void 0}attributeChangedCallback(){clearTimeout(this.timer),this.hasAttribute(`open`)&&this.render()}disconnectedCallback(){clearTimeout(this.timer),super.disconnectedCallback()}attach(e){this.on(e,`gamepadconnect`,()=>{this.hasAttribute(`manual`)||(this.setAttribute(`open`,``),this.timer=setTimeout(()=>this.removeAttribute(`open`),w(this,`close-ms`)))}),this.on(e,`gamepadaction`,e=>{let{action:t}=e.detail;t===`back`&&this.hasAttribute(`open`)&&(e.preventDefault(),this.removeAttribute(`open`))}),this.hasAttribute(`open`)&&this.render()}pad(){var e,t;return(e=(t=this.player)==null?void 0:t.querySelector(`mbx-gamepad`))==null?null:e}render(){var e,t,n;let r=this.pad(),i=(e=r==null?void 0:r.kind)==null?`xbox`:e;this.heading.textContent=(t=this.getAttribute(`label`))==null?`Controller`:t,this.setAttribute(`kind`,i);let o=(n=r==null?void 0:r.bindings(i))==null?null:n,s=/* @__PURE__ */ new Map;if(o!==null)for(let e of a){var c;let t=o[e];if(t==null)continue;let n=x.has(t)&&t===e?`move`:t;s.set(n,[...(c=s.get(n))==null?[]:c,e])}let l=[],u=new Set(b.map(([e])=>e)),f=[...b.map(([e])=>e),...[...s.keys()].filter(e=>!u.has(e))];for(let e of f){var p,m;let t=s.get(e);if(t===void 0)continue;let n=(p=b.find(([t])=>t===e))==null?void 0:p[1],r=(m=this.getAttribute(`label-${e}`))==null?n:m;if(r===void 0)continue;let a=document.createElement(`dt`);for(let e of t)a.append(C(d[i][e]));let o=document.createElement(`dd`);o.textContent=r,l.push(a,o)}for(;this.list.firstChild!==null;)this.list.removeChild(this.list.firstChild);for(let e of l)this.list.append(e)}};function C(e){let t=document.createElement(`kbd`);t.setAttribute(`part`,`button`),t.textContent=e;let n=f[e];return n!==void 0&&t.setAttribute(`aria-label`,n),t}function w(e,t){let n=Number(e.getAttribute(t));return e.hasAttribute(t)&&Number.isFinite(n)?n:6e3}let T={10009:`GoBack`,461:`GoBack`,10252:`MediaPlayPause`,415:`MediaPlay`,19:`MediaPause`,413:`MediaStop`,417:`MediaFastForward`,412:`MediaRewind`},E={13:`Enter`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`};function D(e){var t;let n=T[e.keyCode];return n===void 0?e.key!==``&&e.key!==`Unidentified`||(t=E[e.keyCode])==null?e.key:t:n}function O(e){return e===`GoBack`||e===`BrowserBack`||e===`Escape`}let k={ArrowUp:`up`,ArrowDown:`down`,ArrowLeft:`left`,ArrowRight:`right`},A={up:`down`,down:`up`,left:`right`,right:`left`};function j(e){return e instanceof HTMLElement?e instanceof HTMLButtonElement?!e.disabled:e.getAttribute(`role`)===`slider`||e.hasAttribute(`tabindex`)&&e.tabIndex>=0:!1}function M(e){let t=[],n=r=>{var i,a;r!==e&&j(r)&&r.getClientRects().length>0&&t.push(r);let o=r instanceof HTMLSlotElement?r.assignedElements({flatten:!0}):[...(i=(a=r.shadowRoot)==null?void 0:a.children)==null?[]:i,...r.shadowRoot?[]:r.children];for(let e of o)n(e)};return n(e),t}function N(e,t,n,r){return Math.max(0,n-t,e-r)}function P(e,t,n){let r=n===`left`||n===`right`,i=null,a=[2,0,0];for(let o of t){let t=o.getBoundingClientRect(),s;if(s=n===`right`?t.left-e.right:n===`left`?e.left-t.right:n===`down`?t.top-e.bottom:e.top-t.bottom,s<-1)continue;let c=r?N(e.top,e.bottom,t.top,t.bottom):N(e.left,e.right,t.left,t.right),l=c===0?0:1;if(r&&l===1)continue;let u=[l,Math.max(0,s),c];F(u,a)&&(i=o,a=u)}return i}function F(e,t){for(let i=0;i<e.length;i+=1){var n,r;let a=(n=e[i])==null?0:n,o=(r=t[i])==null?0:r;if(a!==o)return a<o}return!1}var I=class extends i{constructor(){super(),this.last=null,this.move=null,this.pointed=null,this.resting=!1,this.sending=null}attach(e){this.on(e,`keydown`,t=>this.key(e,t),{capture:!0}),this.on(e,`pointermove`,t=>{this.resting=!0;let n=M(e),r=t.composedPath().find(e=>n.includes(e));r!==void 0&&(this.pointed=r)}),this.on(e,`focusin`,()=>{let t=this.focused(e);t!==null&&(this.last=t)})}focused(e){return r(e)}inOpen(e,n){for(let r=n;r!==null&&r!==e;r=t(r))if(r instanceof HTMLElement&&r.hasAttribute(`open`))return!0;return!1}start(e){var t,n,r;let i=M(e);for(let e of[this.pointed,this.last])if(e!==null&&i.includes(e))return e;let a=e.querySelector((t=this.getAttribute(`initial`))==null?`mbx-play-button`:t);return(n=(r=i.find(e=>{var t;return(a==null?void 0:a.contains(e))||(a==null||(t=a.shadowRoot)==null?void 0:t.contains(e))}))==null?i[0]:r)==null?null:n}key(e,t){if(t===this.sending||t.defaultPrevented||t.altKey||t.ctrlKey||t.metaKey)return;let n=D(t),r=k[n];if(r===void 0&&n!==`Enter`){O(n)?this.back(e,t):n!==t.key&&this.again(t,n);return}let i=this.focused(e);if(i===null||this.resting||e.hasAttribute(`idle`)){this.resting=!1;let n=this.start(e);if(n===null)return;t.preventDefault(),n.focus();return}if(this.inOpen(e,i))return;if(r===void 0){if(i instanceof HTMLButtonElement&&n===t.key||i.getAttribute(`role`)===`slider`)return;t.preventDefault(),i.click();return}if(i.getAttribute(`role`)===`slider`&&(r===`left`||r===`right`)){n!==t.key&&this.again(t,n);return}let a=M(e).filter(e=>e!==i),o=this.move,s=o!==null&&o.to===i&&o.direction===A[r]&&a.includes(o.from)?o.from:P(i.getBoundingClientRect(),a,r);t.preventDefault(),s===null?this.dispatchEvent(new CustomEvent(`navigateout`,{detail:r,bubbles:!0,composed:!0})):(this.move={from:i,to:s,direction:r},s.focus())}back(e,t){let n=this.focused(e);if(n===null)return;let r=new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0,composed:!0,cancelable:!0});t.stopPropagation(),t.preventDefault(),this.send(n,r)&&n.blur()}again(e,t){let n=e.composedPath()[0];n!==void 0&&(e.stopPropagation(),e.preventDefault(),this.send(n,new KeyboardEvent(`keydown`,{key:t,bubbles:!0,composed:!0,cancelable:!0})))}send(e,t){this.sending=t;try{return e.dispatchEvent(t)}finally{this.sending=null}}};let L=`mbx-spatial-nav`;customElements.get(`mbx-spatial-nav`)===void 0&&customElements.define(L,I);let R=`mbx-gamepad`,z=`mbx-gamepad-help`;return customElements.get(`mbx-gamepad`)===void 0&&customElements.define(R,v),customElements.get(`mbx-gamepad-help`)===void 0&&customElements.define(z,S),e.GAMEPAD=R,e.GAMEPAD_HELP=z,e.MbxGamepad=v,e.MbxGamepadHelp=S,e.MbxSpatialNav=I,e.SPATIAL_NAV=L,e})({});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var matteboxPlayerSpatialNav=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){let t=e.parentNode;return t===null?e instanceof ShadowRoot?e.host:null:t}function n(e){let n=e;for(;n!==null;){if(n instanceof HTMLElement&&n.localName===`mattebox-player`)return n;n=t(n)}return null}var r=class extends HTMLElement{constructor(){super(),this.player=null,this.offs=[],this.epoch=0}connectedCallback(){let e=n(this);if(e===null)return;this.epoch+=1;let t=this.epoch,r=()=>{t===this.epoch&&this.isConnected&&(customElements.upgrade(e),`media`in e&&(this.player=e,this.attach(this.player)))};`media`in e?r():customElements.whenDefined(`mattebox-player`).then(r)}disconnectedCallback(){this.epoch+=1;for(let e of this.offs)e();this.offs=[],this.player=null}on(e,t,n,r){e.addEventListener(t,n,r),this.offs.push(()=>{e.removeEventListener(t,n,r)})}};let
|
|
1
|
+
var matteboxPlayerSpatialNav=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});function t(e){let t=e.parentNode;return t===null?e instanceof ShadowRoot?e.host:null:t}function n(e){let n=e;for(;n!==null;){if(n instanceof HTMLElement&&n.localName===`mattebox-player`)return n;n=t(n)}return null}function r(e){var n;let r=document.activeElement;for(;(r==null||(n=r.shadowRoot)==null?void 0:n.activeElement)!=null;)r=r.shadowRoot.activeElement;if(!(r instanceof HTMLElement)||r===e)return null;for(let n=r;n!==null;n=t(n))if(n===e)return r;return null}var i=class extends HTMLElement{constructor(){super(),this.player=null,this.offs=[],this.epoch=0}connectedCallback(){let e=n(this);if(e===null)return;this.epoch+=1;let t=this.epoch,r=()=>{t===this.epoch&&this.isConnected&&(customElements.upgrade(e),`media`in e&&(this.player=e,this.attach(this.player)))};`media`in e?r():customElements.whenDefined(`mattebox-player`).then(r)}disconnectedCallback(){this.epoch+=1;for(let e of this.offs)e();this.offs=[],this.player=null}on(e,t,n,r){e.addEventListener(t,n,r),this.offs.push(()=>{e.removeEventListener(t,n,r)})}};let a={10009:`GoBack`,461:`GoBack`,10252:`MediaPlayPause`,415:`MediaPlay`,19:`MediaPause`,413:`MediaStop`,417:`MediaFastForward`,412:`MediaRewind`},o={13:`Enter`,37:`ArrowLeft`,38:`ArrowUp`,39:`ArrowRight`,40:`ArrowDown`};function s(e){var t;let n=a[e.keyCode];return n===void 0?e.key!==``&&e.key!==`Unidentified`||(t=o[e.keyCode])==null?e.key:t:n}function c(e){return e===`GoBack`||e===`BrowserBack`||e===`Escape`}let l={ArrowUp:`up`,ArrowDown:`down`,ArrowLeft:`left`,ArrowRight:`right`},u={up:`down`,down:`up`,left:`right`,right:`left`};function d(e){return e instanceof HTMLElement?e instanceof HTMLButtonElement?!e.disabled:e.getAttribute(`role`)===`slider`||e.hasAttribute(`tabindex`)&&e.tabIndex>=0:!1}function f(e){let t=[],n=r=>{var i,a;r!==e&&d(r)&&r.getClientRects().length>0&&t.push(r);let o=r instanceof HTMLSlotElement?r.assignedElements({flatten:!0}):[...(i=(a=r.shadowRoot)==null?void 0:a.children)==null?[]:i,...r.shadowRoot?[]:r.children];for(let e of o)n(e)};return n(e),t}function p(e,t,n,r){return Math.max(0,n-t,e-r)}function m(e,t,n){let r=n===`left`||n===`right`,i=null,a=[2,0,0];for(let o of t){let t=o.getBoundingClientRect(),s;if(s=n===`right`?t.left-e.right:n===`left`?e.left-t.right:n===`down`?t.top-e.bottom:e.top-t.bottom,s<-1)continue;let c=r?p(e.top,e.bottom,t.top,t.bottom):p(e.left,e.right,t.left,t.right),l=c===0?0:1;if(r&&l===1)continue;let u=[l,Math.max(0,s),c];h(u,a)&&(i=o,a=u)}return i}function h(e,t){for(let i=0;i<e.length;i+=1){var n,r;let a=(n=e[i])==null?0:n,o=(r=t[i])==null?0:r;if(a!==o)return a<o}return!1}var g=class extends i{constructor(){super(),this.last=null,this.move=null,this.pointed=null,this.resting=!1,this.sending=null}attach(e){this.on(e,`keydown`,t=>this.key(e,t),{capture:!0}),this.on(e,`pointermove`,t=>{this.resting=!0;let n=f(e),r=t.composedPath().find(e=>n.includes(e));r!==void 0&&(this.pointed=r)}),this.on(e,`focusin`,()=>{let t=this.focused(e);t!==null&&(this.last=t)})}focused(e){return r(e)}inOpen(e,n){for(let r=n;r!==null&&r!==e;r=t(r))if(r instanceof HTMLElement&&r.hasAttribute(`open`))return!0;return!1}start(e){var t,n,r;let i=f(e);for(let e of[this.pointed,this.last])if(e!==null&&i.includes(e))return e;let a=e.querySelector((t=this.getAttribute(`initial`))==null?`mbx-play-button`:t);return(n=(r=i.find(e=>{var t;return(a==null?void 0:a.contains(e))||(a==null||(t=a.shadowRoot)==null?void 0:t.contains(e))}))==null?i[0]:r)==null?null:n}key(e,t){if(t===this.sending||t.defaultPrevented||t.altKey||t.ctrlKey||t.metaKey)return;let n=s(t),r=l[n];if(r===void 0&&n!==`Enter`){c(n)?this.back(e,t):n!==t.key&&this.again(t,n);return}let i=this.focused(e);if(i===null||this.resting||e.hasAttribute(`idle`)){this.resting=!1;let n=this.start(e);if(n===null)return;t.preventDefault(),n.focus();return}if(this.inOpen(e,i))return;if(r===void 0){if(i instanceof HTMLButtonElement&&n===t.key||i.getAttribute(`role`)===`slider`)return;t.preventDefault(),i.click();return}if(i.getAttribute(`role`)===`slider`&&(r===`left`||r===`right`)){n!==t.key&&this.again(t,n);return}let a=f(e).filter(e=>e!==i),o=this.move,d=o!==null&&o.to===i&&o.direction===u[r]&&a.includes(o.from)?o.from:m(i.getBoundingClientRect(),a,r);t.preventDefault(),d===null?this.dispatchEvent(new CustomEvent(`navigateout`,{detail:r,bubbles:!0,composed:!0})):(this.move={from:i,to:d,direction:r},d.focus())}back(e,t){let n=this.focused(e);if(n===null)return;let r=new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0,composed:!0,cancelable:!0});t.stopPropagation(),t.preventDefault(),this.send(n,r)&&n.blur()}again(e,t){let n=e.composedPath()[0];n!==void 0&&(e.stopPropagation(),e.preventDefault(),this.send(n,new KeyboardEvent(`keydown`,{key:t,bubbles:!0,composed:!0,cancelable:!0})))}send(e,t){this.sending=t;try{return e.dispatchEvent(t)}finally{this.sending=null}}};let _=`mbx-spatial-nav`;return customElements.get(`mbx-spatial-nav`)===void 0&&customElements.define(_,g),e.MbxSpatialNav=g,e.SPATIAL_NAV=_,e})({});
|
package/dist/component.js
CHANGED
|
@@ -1,45 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
target.removeEventListener(name, fn, options);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
1
|
+
import { PLAYER, findPlayer } from "./host.js";
|
|
2
|
+
// src/component.ts
|
|
3
|
+
var Component = class extends HTMLElement {
|
|
4
|
+
constructor() {
|
|
5
|
+
super();
|
|
6
|
+
this.player = null;
|
|
7
|
+
this.offs = [];
|
|
8
|
+
this.epoch = 0;
|
|
9
|
+
}
|
|
10
|
+
connectedCallback() {
|
|
11
|
+
const found = findPlayer(this);
|
|
12
|
+
if (found === null) return;
|
|
13
|
+
this.epoch += 1;
|
|
14
|
+
const epoch = this.epoch;
|
|
15
|
+
const attach = () => {
|
|
16
|
+
if (epoch !== this.epoch || !this.isConnected) return;
|
|
17
|
+
customElements.upgrade(found);
|
|
18
|
+
if (!("media" in found)) return;
|
|
19
|
+
this.player = found;
|
|
20
|
+
this.attach(this.player);
|
|
21
|
+
};
|
|
22
|
+
if ("media" in found) attach();
|
|
23
|
+
else customElements.whenDefined(PLAYER).then(attach);
|
|
24
|
+
}
|
|
25
|
+
disconnectedCallback() {
|
|
26
|
+
this.epoch += 1;
|
|
27
|
+
for (const off of this.offs) off();
|
|
28
|
+
this.offs = [];
|
|
29
|
+
this.player = null;
|
|
30
|
+
}
|
|
31
|
+
/** Adds `fn` for `name` on `target`, removed on detach. */
|
|
32
|
+
on(target, name, fn, options) {
|
|
33
|
+
target.addEventListener(name, fn, options);
|
|
34
|
+
this.offs.push(() => {
|
|
35
|
+
target.removeEventListener(name, fn, options);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
export { Component };
|
|
40
|
+
|
|
45
41
|
//# sourceMappingURL=component.js.map
|
package/dist/component.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","
|
|
1
|
+
{"version":3,"file":"component.js","names":[],"sources":["../src/component.ts"],"sourcesContent":["/**\n * Finding the player, and letting go of it: the part of the player's own\n * control base this package needs. The player exports no base class, so a\n * control of the page's own, this one included, implements the contract\n * from outside (player guide, chapter 03).\n *\n * The control attaches when it is connected inside a player, once the\n * player is defined and upgraded, and detaches when it is removed. What it\n * adds goes through `keep`, so detaching drops it all.\n *\n * No class fields: the ES2015 build would lower them into helpers, and the\n * emit check bans helpers. State is declared, then assigned in the\n * constructor.\n */\nimport type { PlayerHost } from './host.js';\nimport { findPlayer, PLAYER } from './host.js';\n\nexport abstract class Component extends HTMLElement {\n declare protected player: PlayerHost | null;\n declare private offs: Array<() => void>;\n /** Bumped on every connect and disconnect, so a late upgrade attaches only to the current connection. */\n declare private epoch: number;\n\n constructor() {\n super();\n this.player = null;\n this.offs = [];\n this.epoch = 0;\n }\n\n connectedCallback(): void {\n const found = findPlayer(this);\n if (found === null) return;\n this.epoch += 1;\n const epoch = this.epoch;\n const attach = (): void => {\n if (epoch !== this.epoch || !this.isConnected) return;\n // Defined, and this instance upgraded: `media` is on the prototype.\n customElements.upgrade(found);\n if (!('media' in found)) return;\n this.player = found as PlayerHost;\n this.attach(this.player);\n };\n if ('media' in found) attach();\n else void customElements.whenDefined(PLAYER).then(attach);\n }\n\n disconnectedCallback(): void {\n this.epoch += 1;\n for (const off of this.offs) off();\n this.offs = [];\n this.player = null;\n }\n\n /** Adds `fn` for `name` on `target`, removed on detach. */\n protected on(\n target: EventTarget,\n name: string,\n fn: (event: Event) => void,\n options?: AddEventListenerOptions,\n ): void {\n target.addEventListener(name, fn, options);\n this.offs.push(() => {\n target.removeEventListener(name, fn, options);\n });\n }\n\n /** The control is connected inside an upgraded player. Subscribe. */\n protected abstract attach(player: PlayerHost): void;\n}\n"],"mappings":";;AAiBA,IAAsB,YAAtB,cAAwC,YAAY;CAMlD,cAAc;EACZ,MAAM;EACN,KAAK,SAAS;EACd,KAAK,OAAO,CAAC;EACb,KAAK,QAAQ;CACf;CAEA,oBAA0B;EACxB,MAAM,QAAQ,WAAW,IAAI;EAC7B,IAAI,UAAU,MAAM;EACpB,KAAK,SAAS;EACd,MAAM,QAAQ,KAAK;EACnB,MAAM,eAAqB;GACzB,IAAI,UAAU,KAAK,SAAS,CAAC,KAAK,aAAa;GAE/C,eAAe,QAAQ,KAAK;GAC5B,IAAI,EAAE,WAAW,QAAQ;GACzB,KAAK,SAAS;GACd,KAAK,OAAO,KAAK,MAAM;EACzB;EACA,IAAI,WAAW,OAAO,OAAO;OACnB,eAAe,YAAY,MAAM,CAAC,CAAC,KAAK,MAAM;CAC1D;CAEA,uBAA6B;EAC3B,KAAK,SAAS;EACd,KAAK,MAAM,OAAO,KAAK,MAAM,IAAI;EACjC,KAAK,OAAO,CAAC;EACb,KAAK,SAAS;CAChB;;CAGU,GACR,QACA,MACA,IACA,SACM;EACN,OAAO,iBAAiB,MAAM,IAAI,OAAO;EACzC,KAAK,KAAK,WAAW;GACnB,OAAO,oBAAoB,MAAM,IAAI,OAAO;EAC9C,CAAC;CACH;AAIF"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { Component } from "./component.js";
|
|
2
|
+
import { BUTTONS, GLYPHS, SPOKEN } from "./pad.js";
|
|
3
|
+
// src/gamepad-help.ts
|
|
4
|
+
/**
|
|
5
|
+
* <mbx-gamepad-help>: a bubble over the video that lists what each button
|
|
6
|
+
* of the controller does. It reads the mapping from the player's
|
|
7
|
+
* <mbx-gamepad>, overrides included, and draws the buttons as the make of
|
|
8
|
+
* the pad in use prints them.
|
|
9
|
+
*
|
|
10
|
+
* - It opens when a pad connects, and closes by itself after `close-ms`
|
|
11
|
+
* (6000 by default). `manual` keeps it closed until the `help` action.
|
|
12
|
+
* - The `help` action opens and closes it. Back closes it.
|
|
13
|
+
* - `label` names the bubble ("Controller"). `label-<action>` names an
|
|
14
|
+
* action, such as `label-next="Next episode"`; an action of the page's
|
|
15
|
+
* own shows only with a label.
|
|
16
|
+
*/
|
|
17
|
+
const STYLE = ":host{right:var(--mbx-gap,12px);z-index:3;max-width:calc(100% - 2 * var(--mbx-gap,12px));color:var(--mbx-text,#fff);font-family:var(--mbx-font,system-ui, sans-serif);pointer-events:none;font-size:14px;display:none;position:absolute;bottom:72px}:host([open]){display:block}[part~=bubble]{padding:var(--mbx-pad,12px) calc(var(--mbx-pad,12px) * 1.5);border-radius:var(--mbx-radius,8px);background:#000000d1}[part~=heading]{margin:0 0 8px;font-size:14px;font-weight:600}[part~=list]{grid-template-columns:auto auto;align-items:center;gap:6px 16px;margin:0;display:grid}dt{text-align:right;white-space:nowrap}dd{margin:0}[part~=button]{text-align:center;border:1px solid #ffffff80;border-radius:4px;min-width:1.6em;padding:1px 6px;font-family:inherit;font-size:12px;line-height:18px;display:inline-block}dt [part~=button]+[part~=button]{margin-left:4px}";
|
|
18
|
+
const CLOSE_MS = 6e3;
|
|
19
|
+
/** The words of each action, in the order the bubble lists them. */
|
|
20
|
+
const WORDS = [
|
|
21
|
+
["move", "Move"],
|
|
22
|
+
["activate", "Select"],
|
|
23
|
+
["back", "Back"],
|
|
24
|
+
["play-pause", "Play or pause"],
|
|
25
|
+
["rewind", "Rewind"],
|
|
26
|
+
["fast-forward", "Fast forward"],
|
|
27
|
+
["previous", "Previous"],
|
|
28
|
+
["next", "Next"],
|
|
29
|
+
["subtitles", "Subtitles"],
|
|
30
|
+
["mute", "Mute"],
|
|
31
|
+
["fullscreen", "Fullscreen"],
|
|
32
|
+
["help", "Controls"]
|
|
33
|
+
];
|
|
34
|
+
const DIRECTIONS = /* @__PURE__ */ new Set([
|
|
35
|
+
"up",
|
|
36
|
+
"down",
|
|
37
|
+
"left",
|
|
38
|
+
"right"
|
|
39
|
+
]);
|
|
40
|
+
var MbxGamepadHelp = class extends Component {
|
|
41
|
+
static get observedAttributes() {
|
|
42
|
+
return ["open"];
|
|
43
|
+
}
|
|
44
|
+
constructor() {
|
|
45
|
+
super();
|
|
46
|
+
const root = this.attachShadow({ mode: "open" });
|
|
47
|
+
const style = document.createElement("style");
|
|
48
|
+
style.textContent = STYLE;
|
|
49
|
+
const bubble = document.createElement("section");
|
|
50
|
+
bubble.setAttribute("part", "bubble");
|
|
51
|
+
this.heading = document.createElement("h2");
|
|
52
|
+
this.heading.setAttribute("part", "heading");
|
|
53
|
+
this.heading.id = "heading";
|
|
54
|
+
bubble.setAttribute("aria-labelledby", "heading");
|
|
55
|
+
this.list = document.createElement("dl");
|
|
56
|
+
this.list.setAttribute("part", "list");
|
|
57
|
+
bubble.append(this.heading, this.list);
|
|
58
|
+
root.append(style, bubble);
|
|
59
|
+
this.timer = void 0;
|
|
60
|
+
}
|
|
61
|
+
attributeChangedCallback() {
|
|
62
|
+
clearTimeout(this.timer);
|
|
63
|
+
if (this.hasAttribute("open")) this.render();
|
|
64
|
+
}
|
|
65
|
+
disconnectedCallback() {
|
|
66
|
+
clearTimeout(this.timer);
|
|
67
|
+
super.disconnectedCallback();
|
|
68
|
+
}
|
|
69
|
+
attach(player) {
|
|
70
|
+
this.on(player, "gamepadconnect", () => {
|
|
71
|
+
if (this.hasAttribute("manual")) return;
|
|
72
|
+
this.setAttribute("open", "");
|
|
73
|
+
this.timer = setTimeout(() => this.removeAttribute("open"), number(this, "close-ms"));
|
|
74
|
+
});
|
|
75
|
+
this.on(player, "gamepadaction", (event) => {
|
|
76
|
+
const { action } = event.detail;
|
|
77
|
+
if (action === "back" && this.hasAttribute("open")) {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
this.removeAttribute("open");
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
if (this.hasAttribute("open")) this.render();
|
|
83
|
+
}
|
|
84
|
+
/** The player's <mbx-gamepad>, or null. */
|
|
85
|
+
pad() {
|
|
86
|
+
var _this$player$querySel, _this$player;
|
|
87
|
+
return (_this$player$querySel = (_this$player = this.player) === null || _this$player === void 0 ? void 0 : _this$player.querySelector("mbx-gamepad")) !== null && _this$player$querySel !== void 0 ? _this$player$querySel : null;
|
|
88
|
+
}
|
|
89
|
+
/** Lists each action the mapping binds, with its buttons as the make in use prints them. */
|
|
90
|
+
render() {
|
|
91
|
+
var _pad$kind, _this$getAttribute, _pad$bindings;
|
|
92
|
+
const pad = this.pad();
|
|
93
|
+
const kind = (_pad$kind = pad === null || pad === void 0 ? void 0 : pad.kind) !== null && _pad$kind !== void 0 ? _pad$kind : "xbox";
|
|
94
|
+
this.heading.textContent = (_this$getAttribute = this.getAttribute("label")) !== null && _this$getAttribute !== void 0 ? _this$getAttribute : "Controller";
|
|
95
|
+
this.setAttribute("kind", kind);
|
|
96
|
+
const bindings = (_pad$bindings = pad === null || pad === void 0 ? void 0 : pad.bindings(kind)) !== null && _pad$bindings !== void 0 ? _pad$bindings : null;
|
|
97
|
+
const by = /* @__PURE__ */ new Map();
|
|
98
|
+
if (bindings !== null) for (const button of BUTTONS) {
|
|
99
|
+
var _by$get;
|
|
100
|
+
const action = bindings[button];
|
|
101
|
+
if (action == null) continue;
|
|
102
|
+
const key = DIRECTIONS.has(action) && action === button ? "move" : action;
|
|
103
|
+
by.set(key, [...(_by$get = by.get(key)) !== null && _by$get !== void 0 ? _by$get : [], button]);
|
|
104
|
+
}
|
|
105
|
+
const rows = [];
|
|
106
|
+
const known = new Set(WORDS.map(([action]) => action));
|
|
107
|
+
const order = [...WORDS.map(([action]) => action), ...[...by.keys()].filter((a) => !known.has(a))];
|
|
108
|
+
for (const action of order) {
|
|
109
|
+
var _WORDS$find, _this$getAttribute2;
|
|
110
|
+
const buttons = by.get(action);
|
|
111
|
+
if (buttons === void 0) continue;
|
|
112
|
+
const own = (_WORDS$find = WORDS.find(([name]) => name === action)) === null || _WORDS$find === void 0 ? void 0 : _WORDS$find[1];
|
|
113
|
+
const words = (_this$getAttribute2 = this.getAttribute(`label-${action}`)) !== null && _this$getAttribute2 !== void 0 ? _this$getAttribute2 : own;
|
|
114
|
+
if (words === void 0) continue;
|
|
115
|
+
const term = document.createElement("dt");
|
|
116
|
+
for (const button of buttons) term.append(glyph(GLYPHS[kind][button]));
|
|
117
|
+
const description = document.createElement("dd");
|
|
118
|
+
description.textContent = words;
|
|
119
|
+
rows.push(term, description);
|
|
120
|
+
}
|
|
121
|
+
while (this.list.firstChild !== null) this.list.removeChild(this.list.firstChild);
|
|
122
|
+
for (const row of rows) this.list.append(row);
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
/** A button as its make prints it, named for a screen reader where the print is a symbol. */
|
|
126
|
+
function glyph(text) {
|
|
127
|
+
const kbd = document.createElement("kbd");
|
|
128
|
+
kbd.setAttribute("part", "button");
|
|
129
|
+
kbd.textContent = text;
|
|
130
|
+
const spoken = SPOKEN[text];
|
|
131
|
+
if (spoken !== void 0) kbd.setAttribute("aria-label", spoken);
|
|
132
|
+
return kbd;
|
|
133
|
+
}
|
|
134
|
+
/** The element's number attribute `name`, or the default. */
|
|
135
|
+
function number(element, name) {
|
|
136
|
+
const value = Number(element.getAttribute(name));
|
|
137
|
+
return element.hasAttribute(name) && Number.isFinite(value) ? value : CLOSE_MS;
|
|
138
|
+
}
|
|
139
|
+
export { MbxGamepadHelp };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { MbxSpatialNav } from "./spatial-nav.js";
|
|
2
|
+
import { MbxGamepad } from "./gamepad.js";
|
|
3
|
+
import { MbxGamepadHelp } from "./gamepad-help.js";
|
|
4
|
+
import { SPATIAL_NAV } from "./index.js";
|
|
5
|
+
// src/gamepad-index.ts
|
|
6
|
+
/**
|
|
7
|
+
* @mattebox/player-spatial-nav/gamepad: <mbx-gamepad> and
|
|
8
|
+
* <mbx-gamepad-help>, a game controller for the player. Importing this
|
|
9
|
+
* module registers both, and <mbx-spatial-nav>, which moves focus for the
|
|
10
|
+
* controller. A page with a remote alone imports the package's main entry
|
|
11
|
+
* and pays nothing for the controller.
|
|
12
|
+
*/
|
|
13
|
+
const GAMEPAD = "mbx-gamepad";
|
|
14
|
+
const GAMEPAD_HELP = "mbx-gamepad-help";
|
|
15
|
+
if (customElements.get("mbx-gamepad") === void 0) customElements.define(GAMEPAD, MbxGamepad);
|
|
16
|
+
if (customElements.get("mbx-gamepad-help") === void 0) customElements.define(GAMEPAD_HELP, MbxGamepadHelp);
|
|
17
|
+
export { GAMEPAD, GAMEPAD_HELP, MbxGamepad, MbxGamepadHelp, MbxSpatialNav, SPATIAL_NAV };
|