@mattebox/player 0.7.0 → 0.8.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/dist/cdn/mattebox-player.min.js +3 -3
- package/dist/controls/icons.d.ts +3 -1
- package/dist/controls/icons.d.ts.map +1 -1
- package/dist/controls/icons.js +27 -27
- package/dist/controls/icons.js.map +1 -1
- package/dist/controls/markers.d.ts +39 -0
- package/dist/controls/markers.d.ts.map +1 -0
- package/dist/controls/markers.js +38 -0
- package/dist/controls/markers.js.map +1 -0
- package/dist/controls/menu.d.ts +3 -2
- package/dist/controls/menu.d.ts.map +1 -1
- package/dist/controls/menu.js +23 -3
- package/dist/controls/menu.js.map +1 -1
- package/dist/controls/native-tracks.d.ts +28 -0
- package/dist/controls/native-tracks.d.ts.map +1 -0
- package/dist/controls/native-tracks.js +30 -0
- package/dist/controls/native-tracks.js.map +1 -0
- package/dist/controls/quality-names.d.ts +15 -0
- package/dist/controls/quality-names.d.ts.map +1 -0
- package/dist/controls/quality-names.js +62 -0
- package/dist/controls/quality-names.js.map +1 -0
- package/dist/controls/track-names.d.ts +40 -0
- package/dist/controls/track-names.d.ts.map +1 -0
- package/dist/controls/track-names.js +59 -0
- package/dist/controls/track-names.js.map +1 -0
- package/dist/element.d.ts +24 -0
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +47 -4
- package/dist/element.js.map +1 -1
- package/dist/elements/audio-menu.d.ts +19 -8
- package/dist/elements/audio-menu.d.ts.map +1 -1
- package/dist/elements/audio-menu.js +57 -18
- package/dist/elements/audio-menu.js.map +1 -1
- package/dist/elements/drm-badge.d.ts +3 -2
- package/dist/elements/drm-badge.d.ts.map +1 -1
- package/dist/elements/drm-badge.js +10 -8
- package/dist/elements/drm-badge.js.map +1 -1
- package/dist/elements/marker-button.d.ts +22 -0
- package/dist/elements/marker-button.d.ts.map +1 -0
- package/dist/elements/marker-button.js +99 -0
- package/dist/elements/marker-button.js.map +1 -0
- package/dist/elements/quality-menu.d.ts +4 -0
- package/dist/elements/quality-menu.d.ts.map +1 -1
- package/dist/elements/quality-menu.js +21 -7
- package/dist/elements/quality-menu.js.map +1 -1
- package/dist/elements/seek-bar.d.ts +6 -1
- package/dist/elements/seek-bar.d.ts.map +1 -1
- package/dist/elements/seek-bar.js +33 -22
- package/dist/elements/seek-bar.js.map +1 -1
- package/dist/elements/shared.js +1 -1
- package/dist/elements/subtitles-menu.d.ts +2 -0
- package/dist/elements/subtitles-menu.d.ts.map +1 -1
- package/dist/elements/subtitles-menu.js +33 -9
- package/dist/elements/subtitles-menu.js.map +1 -1
- package/dist/entries/marker-button.d.ts +5 -0
- package/dist/entries/marker-button.d.ts.map +1 -0
- package/dist/entries/marker-button.js +9 -0
- package/dist/entries/marker-button.js.map +1 -0
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/asyncToGenerator.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/defineProperty.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/objectSpread2.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/toPrimitive.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/toPropertyKey.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.150.0 → _@oxc-project_runtime@0.152.0}/helpers/esm/typeof.js +1 -1
- package/dist/es2015/controls/chapters.js +1 -1
- package/dist/es2015/controls/icons.js +27 -27
- package/dist/es2015/controls/markers.js +36 -0
- package/dist/es2015/controls/menu.js +24 -4
- package/dist/es2015/controls/native-tracks.js +29 -0
- package/dist/es2015/controls/quality-names.js +67 -0
- package/dist/es2015/controls/track-names.js +57 -0
- package/dist/es2015/element.js +48 -6
- package/dist/es2015/elements/audio-menu.js +62 -19
- package/dist/es2015/elements/drm-badge.js +11 -8
- package/dist/es2015/elements/marker-button.js +100 -0
- package/dist/es2015/elements/quality-menu.js +22 -7
- package/dist/es2015/elements/seek-bar.js +38 -26
- package/dist/es2015/elements/shared.js +1 -1
- package/dist/es2015/elements/subtitles-menu.js +39 -11
- package/dist/es2015/entries/marker-button.js +7 -0
- package/dist/es2015/index.js +3 -1
- package/dist/es2015/presets.js +1 -1
- package/dist/es2015/style.js +1 -1
- package/dist/es2015/tags.js +2 -1
- package/dist/host.d.ts +3 -0
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js.map +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/style.js +1 -1
- package/dist/tags.d.ts +1 -0
- package/dist/tags.d.ts.map +1 -1
- package/dist/tags.js +2 -1
- package/dist/tags.js.map +1 -1
- package/package.json +3 -3
package/dist/controls/menu.js
CHANGED
|
@@ -24,6 +24,12 @@ import { el, setChildren, state } from "../dom.js";
|
|
|
24
24
|
*/
|
|
25
25
|
/** Air between the popup's top and the picture's. */
|
|
26
26
|
const AIR = 8;
|
|
27
|
+
/**
|
|
28
|
+
* The tallest a popup grows, in pixels: about seven and a half rows, so
|
|
29
|
+
* the half row at the foot says the list goes on. A page sets its own
|
|
30
|
+
* with `--mbx-menu-max-height`.
|
|
31
|
+
*/
|
|
32
|
+
const MAX_HEIGHT = 264;
|
|
27
33
|
/** An item's picture. Decorative: the item's text names it. Loaded when the popup first shows it. */
|
|
28
34
|
function picture(url) {
|
|
29
35
|
const node = el("img", "item-image");
|
|
@@ -43,6 +49,9 @@ function menu(options) {
|
|
|
43
49
|
button.setAttribute("aria-haspopup", "menu");
|
|
44
50
|
button.setAttribute("aria-expanded", "false");
|
|
45
51
|
const popup = el("div", "popup");
|
|
52
|
+
popup.addEventListener("scroll", () => {
|
|
53
|
+
more();
|
|
54
|
+
});
|
|
46
55
|
popup.setAttribute("role", "menu");
|
|
47
56
|
popup.hidden = true;
|
|
48
57
|
let open = false;
|
|
@@ -64,15 +73,25 @@ function menu(options) {
|
|
|
64
73
|
function outside(event) {
|
|
65
74
|
if (!event.composedPath().includes(host)) close();
|
|
66
75
|
}
|
|
67
|
-
/**
|
|
76
|
+
/**
|
|
77
|
+
* The popup's height: its maximum, or the room above the button if that
|
|
78
|
+
* is less, so the popup never leaves the picture. Its width: the room
|
|
79
|
+
* left of its right edge.
|
|
80
|
+
*/
|
|
68
81
|
function fit() {
|
|
69
82
|
const picture = options.picture();
|
|
70
83
|
if (picture === null) return;
|
|
71
84
|
const room = button.getBoundingClientRect().top - picture.top - AIR;
|
|
72
|
-
|
|
85
|
+
const most = Number.parseFloat(getComputedStyle(host).getPropertyValue("--mbx-menu-max-height")) || MAX_HEIGHT;
|
|
86
|
+
popup.style.maxHeight = `${Math.max(0, Math.floor(Math.min(most, room)))}px`;
|
|
87
|
+
more();
|
|
73
88
|
const wide = host.getBoundingClientRect().right - picture.left - AIR;
|
|
74
89
|
popup.style.maxWidth = `${Math.max(0, Math.floor(wide))}px`;
|
|
75
90
|
}
|
|
91
|
+
/** `more` on the popup while rows wait below its foot, which then fades out. */
|
|
92
|
+
function more() {
|
|
93
|
+
popup.toggleAttribute("more", popup.scrollTop + popup.clientHeight < popup.scrollHeight - 1);
|
|
94
|
+
}
|
|
76
95
|
function clear() {
|
|
77
96
|
for (const item of items()) {
|
|
78
97
|
const handler = handlers.get(item);
|
|
@@ -122,12 +141,13 @@ function menu(options) {
|
|
|
122
141
|
section.setAttribute("aria-label", entry.label);
|
|
123
142
|
section.append(el("div", `section-label ${entry.name}-label`, entry.label));
|
|
124
143
|
}
|
|
125
|
-
for (const [id, text, detail, image] of entry.items) {
|
|
144
|
+
for (const [id, text, detail, image, badges] of entry.items) {
|
|
126
145
|
const choice = item(`item ${entry.name}-item`, text, () => {
|
|
127
146
|
close();
|
|
128
147
|
button.focus();
|
|
129
148
|
entry.onSelect(id);
|
|
130
149
|
});
|
|
150
|
+
for (const badge of badges ?? []) choice.append(el("span", "item-badge", badge));
|
|
131
151
|
if (detail !== void 0) choice.append(el("span", "item-detail", detail));
|
|
132
152
|
if (image !== void 0) {
|
|
133
153
|
const [, ...rest] = choice.childNodes;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.js","names":[],"sources":["../../src/controls/menu.ts"],"sourcesContent":["/**\n * The menu primitive the quality, audio, subtitles and speed menus share: a\n * button that opens a popup of radio items above it, in one or more groups\n * with a heading each, and pages behind entries that open them. The button\n * carries the name and `aria-expanded`; the popup is `role=\"menu\"`, every\n * choice a `menuitemradio` with `aria-checked`, the checked one also\n * carrying `checked` on its part name, because an item inside a shadow\n * root has no other seam a page can style; an entry that opens a page is\n * a `menuitem` with `aria-haspopup`, and the page starts with a Back.\n *\n * Open on click. Inside, the arrows move focus across every item, Home and\n * End jump, Enter and Space choose, Escape goes back a page or closes and\n * hands focus to the button. A choice closes the popup. A pointer down\n * anywhere else closes it too.\n *\n * The popup never leaves the picture: on opening it takes the room above\n * the button up to the top of `picture()` as its height and scrolls past\n * that, and the room from its right edge to the picture's left as its\n * width, where a long item ends in an ellipsis. The\n * element that owns the menu carries `open` while the popup shows, which\n * the bar reads to hold its fade.\n */\nimport { el, setChildren, state } from '../dom.js';\n\nexport interface MenuGroup {\n /** The part suffix: `track`, `size`. */\n readonly name: string;\n /** A heading, or none for a menu of one group. */\n readonly label?: string;\n /**\n * Each item's id, its text, a detail drawn at its end, such as a chapter's\n * time, and the URL of a picture drawn at its start.\n */\n readonly items: ReadonlyArray<readonly [string, string, string?, string?]>;\n readonly value: string;\n readonly onSelect: (value: string) => void;\n}\n\n/** An entry that opens a page of groups, with a Back at its top. */\nexport interface MenuPage {\n readonly name: string;\n readonly label: string;\n readonly entries: readonly MenuEntry[];\n}\n\nexport type MenuEntry = MenuGroup | MenuPage;\n\nexport interface MenuOptions {\n /** The element the menu belongs to: it carries `open`, and a pointer inside it is not outside. */\n readonly host: HTMLElement;\n /** The picture, in viewport pixels, which the popup never leaves. */\n readonly picture: () => DOMRect | null;\n /** The name of the Back item, from the page it leaves: \"Back from {page}\". */\n readonly back: (page: string) => string;\n}\n\nexport interface Menu {\n readonly button: HTMLButtonElement;\n readonly popup: HTMLElement;\n /** The accessible name of the button and the popup. */\n label(text: string): void;\n /** Replaces the entries, back at the first page. */\n fill(entries: readonly MenuEntry[]): void;\n close(): void;\n dispose(): void;\n}\n\n/** Air between the popup's top and the picture's. */\nconst AIR = 8;\n\n/** An item's picture. Decorative: the item's text names it. Loaded when the popup first shows it. */\nfunction picture(url: string): HTMLImageElement {\n const node = el('img', 'item-image');\n node.alt = '';\n node.loading = 'lazy';\n node.decoding = 'async';\n node.src = url;\n return node;\n}\n\nfunction isPage(entry: MenuEntry): entry is MenuPage {\n return 'entries' in entry;\n}\n\nexport function menu(options: MenuOptions): Menu {\n const { host } = options;\n const button = el('button', 'button');\n button.type = 'button';\n button.setAttribute('aria-haspopup', 'menu');\n button.setAttribute('aria-expanded', 'false');\n const popup = el('div', 'popup');\n popup.setAttribute('role', 'menu');\n popup.hidden = true;\n\n let open = false;\n let name = '';\n let first: readonly MenuEntry[] = [];\n /** The pages opened, the first being the menu itself. */\n let stack: MenuPage[] = [];\n const handlers = new WeakMap<HTMLButtonElement, () => void>();\n\n function items(): HTMLButtonElement[] {\n return [...popup.querySelectorAll('button')];\n }\n\n function checked(): HTMLButtonElement | undefined {\n return items().find((item) => item.getAttribute('aria-checked') === 'true');\n }\n\n /** The focused element as this tree sees it: inside shadow DOM, `document.activeElement` is the host. */\n function focused(): Element | null {\n return (popup.getRootNode() as Document | ShadowRoot).activeElement;\n }\n\n function outside(event: PointerEvent): void {\n if (!event.composedPath().includes(host)) close();\n }\n\n /** Whatever room there is above the button and left of the popup's right edge, so the popup never leaves the picture. */\n function fit(): void {\n const picture = options.picture();\n if (picture === null) return;\n const room = button.getBoundingClientRect().top - picture.top - AIR;\n popup.style.maxHeight = `${Math.max(0, Math.floor(room))}px`;\n // The popup is anchored at the host's right edge and grows leftwards.\n const wide = host.getBoundingClientRect().right - picture.left - AIR;\n popup.style.maxWidth = `${Math.max(0, Math.floor(wide))}px`;\n }\n\n function clear(): void {\n for (const item of items()) {\n const handler = handlers.get(item);\n if (handler !== undefined) item.removeEventListener('click', handler);\n }\n setChildren(popup);\n }\n\n function item(part: string, text: string, handler: () => void): HTMLButtonElement {\n const node = el('button', part, text);\n node.type = 'button';\n node.tabIndex = -1;\n handlers.set(node, handler);\n node.addEventListener('click', handler);\n return node;\n }\n\n /** Draws the page on top of the stack. */\n function render(): void {\n clear();\n const page = stack[stack.length - 1];\n if (page === undefined) return;\n let tab = true;\n if (stack.length > 1) {\n const back = item('item back-item', page.label, () => {\n stack.pop();\n render();\n items()[0]?.focus();\n });\n back.setAttribute('role', 'menuitem');\n back.setAttribute('aria-label', options.back(page.label));\n popup.append(back);\n }\n for (const entry of page.entries) {\n if (isPage(entry)) {\n const link = item(`item page-item ${entry.name}-item`, entry.label, () => {\n stack.push(entry);\n render();\n items()[0]?.focus();\n });\n link.setAttribute('role', 'menuitem');\n link.setAttribute('aria-haspopup', 'menu');\n popup.append(link);\n continue;\n }\n const section = el('div', `section ${entry.name}-section`);\n section.setAttribute('role', 'group');\n if (entry.label !== undefined) {\n section.setAttribute('aria-label', entry.label);\n section.append(el('div', `section-label ${entry.name}-label`, entry.label));\n }\n for (const [id, text, detail, image] of entry.items) {\n const choice = item(`item ${entry.name}-item`, text, () => {\n close();\n button.focus();\n entry.onSelect(id);\n });\n if (detail !== undefined) choice.append(el('span', 'item-detail', detail));\n if (image !== undefined) {\n // The text in a box of its own, so a long title ends in an ellipsis beside the picture.\n const [, ...rest] = choice.childNodes;\n setChildren(choice, el('span', 'item-text', text), ...rest);\n choice.prepend(picture(image));\n }\n choice.value = id;\n choice.setAttribute('role', 'menuitemradio');\n const on = id === entry.value;\n choice.setAttribute('aria-checked', String(on));\n state(choice, `item ${entry.name}-item`, { checked: on });\n // One tab stop: the first checked item.\n if (on && tab) {\n choice.tabIndex = 0;\n tab = false;\n }\n section.append(choice);\n }\n popup.append(section);\n }\n fit();\n }\n\n function close(): void {\n if (!open) return;\n open = false;\n popup.hidden = true;\n button.setAttribute('aria-expanded', 'false');\n host.removeAttribute('open');\n document.removeEventListener('pointerdown', outside, true);\n if (stack.length > 1) {\n stack = stack.slice(0, 1);\n render();\n }\n }\n\n function show(): void {\n if (open) return;\n open = true;\n popup.hidden = false;\n button.setAttribute('aria-expanded', 'true');\n host.setAttribute('open', '');\n document.addEventListener('pointerdown', outside, true);\n fit();\n (checked() ?? items()[0])?.focus();\n }\n\n function toggle(): void {\n if (open) close();\n else show();\n }\n\n function key(event: KeyboardEvent): void {\n // Handled already, by a handler that decides first.\n if (event.defaultPrevented) return;\n const list = items();\n const index = list.indexOf(focused() as HTMLButtonElement);\n let next: number;\n switch (event.key) {\n case 'ArrowDown':\n next = (index + 1) % list.length;\n break;\n case 'ArrowUp':\n next = (index - 1 + list.length) % list.length;\n break;\n case 'Home':\n next = 0;\n break;\n case 'End':\n next = list.length - 1;\n break;\n case 'Escape':\n event.preventDefault();\n if (stack.length > 1) {\n stack.pop();\n render();\n items()[0]?.focus();\n return;\n }\n close();\n button.focus();\n return;\n default:\n return;\n }\n event.preventDefault();\n list[next]?.focus();\n }\n\n button.addEventListener('click', toggle);\n popup.addEventListener('keydown', key);\n\n return {\n button,\n popup,\n label(text: string): void {\n name = text;\n button.setAttribute('aria-label', text);\n popup.setAttribute('aria-label', text);\n const root = stack[0];\n if (root !== undefined) stack[0] = { ...root, label: text };\n },\n fill(entries): void {\n first = entries;\n stack = [{ name: 'menu', label: name, entries: first }];\n render();\n },\n close,\n dispose(): void {\n close();\n clear();\n button.removeEventListener('click', toggle);\n popup.removeEventListener('keydown', key);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,MAAM;;AAGZ,SAAS,QAA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N,OAAO,oBAAoB,SAAS,MAAM;GAC1C,MAAM,oBAAoB,WAAW,GAAG;EAC1C;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"menu.js","names":[],"sources":["../../src/controls/menu.ts"],"sourcesContent":["/**\n * The menu primitive the quality, audio, subtitles and speed menus share: a\n * button that opens a popup of radio items above it, in one or more groups\n * with a heading each, and pages behind entries that open them. The button\n * carries the name and `aria-expanded`; the popup is `role=\"menu\"`, every\n * choice a `menuitemradio` with `aria-checked`, the checked one also\n * carrying `checked` on its part name, because an item inside a shadow\n * root has no other seam a page can style; an entry that opens a page is\n * a `menuitem` with `aria-haspopup`, and the page starts with a Back.\n *\n * Open on click. Inside, the arrows move focus across every item, Home and\n * End jump, Enter and Space choose, Escape goes back a page or closes and\n * hands focus to the button. A choice closes the popup. A pointer down\n * anywhere else closes it too.\n *\n * The popup never leaves the picture: on opening it takes the room above\n * the button up to the top of `picture()` as its height and scrolls past\n * that, and the room from its right edge to the picture's left as its\n * width, where a long item ends in an ellipsis. The\n * element that owns the menu carries `open` while the popup shows, which\n * the bar reads to hold its fade.\n */\nimport { el, setChildren, state } from '../dom.js';\n\nexport interface MenuGroup {\n /** The part suffix: `track`, `size`. */\n readonly name: string;\n /** A heading, or none for a menu of one group. */\n readonly label?: string;\n /**\n * Each item's id, its text, a detail drawn at its end, such as a chapter's\n * time, the URL of a picture drawn at its start, and short badges drawn\n * after the text, such as \"AD\" on an audio description track.\n */\n readonly items: ReadonlyArray<\n readonly [string, string, (string | undefined)?, (string | undefined)?, (readonly string[])?]\n >;\n readonly value: string;\n readonly onSelect: (value: string) => void;\n}\n\n/** An entry that opens a page of groups, with a Back at its top. */\nexport interface MenuPage {\n readonly name: string;\n readonly label: string;\n readonly entries: readonly MenuEntry[];\n}\n\nexport type MenuEntry = MenuGroup | MenuPage;\n\nexport interface MenuOptions {\n /** The element the menu belongs to: it carries `open`, and a pointer inside it is not outside. */\n readonly host: HTMLElement;\n /** The picture, in viewport pixels, which the popup never leaves. */\n readonly picture: () => DOMRect | null;\n /** The name of the Back item, from the page it leaves: \"Back from {page}\". */\n readonly back: (page: string) => string;\n}\n\nexport interface Menu {\n readonly button: HTMLButtonElement;\n readonly popup: HTMLElement;\n /** The accessible name of the button and the popup. */\n label(text: string): void;\n /** Replaces the entries, back at the first page. */\n fill(entries: readonly MenuEntry[]): void;\n close(): void;\n dispose(): void;\n}\n\n/** Air between the popup's top and the picture's. */\nconst AIR = 8;\n\n/**\n * The tallest a popup grows, in pixels: about seven and a half rows, so\n * the half row at the foot says the list goes on. A page sets its own\n * with `--mbx-menu-max-height`.\n */\nconst MAX_HEIGHT = 264;\n\n/** An item's picture. Decorative: the item's text names it. Loaded when the popup first shows it. */\nfunction picture(url: string): HTMLImageElement {\n const node = el('img', 'item-image');\n node.alt = '';\n node.loading = 'lazy';\n node.decoding = 'async';\n node.src = url;\n return node;\n}\n\nfunction isPage(entry: MenuEntry): entry is MenuPage {\n return 'entries' in entry;\n}\n\nexport function menu(options: MenuOptions): Menu {\n const { host } = options;\n const button = el('button', 'button');\n button.type = 'button';\n button.setAttribute('aria-haspopup', 'menu');\n button.setAttribute('aria-expanded', 'false');\n const popup = el('div', 'popup');\n popup.addEventListener('scroll', () => {\n more();\n });\n popup.setAttribute('role', 'menu');\n popup.hidden = true;\n\n let open = false;\n let name = '';\n let first: readonly MenuEntry[] = [];\n /** The pages opened, the first being the menu itself. */\n let stack: MenuPage[] = [];\n const handlers = new WeakMap<HTMLButtonElement, () => void>();\n\n function items(): HTMLButtonElement[] {\n return [...popup.querySelectorAll('button')];\n }\n\n function checked(): HTMLButtonElement | undefined {\n return items().find((item) => item.getAttribute('aria-checked') === 'true');\n }\n\n /** The focused element as this tree sees it: inside shadow DOM, `document.activeElement` is the host. */\n function focused(): Element | null {\n return (popup.getRootNode() as Document | ShadowRoot).activeElement;\n }\n\n function outside(event: PointerEvent): void {\n if (!event.composedPath().includes(host)) close();\n }\n\n /**\n * The popup's height: its maximum, or the room above the button if that\n * is less, so the popup never leaves the picture. Its width: the room\n * left of its right edge.\n */\n function fit(): void {\n const picture = options.picture();\n if (picture === null) return;\n const room = button.getBoundingClientRect().top - picture.top - AIR;\n const most =\n Number.parseFloat(getComputedStyle(host).getPropertyValue('--mbx-menu-max-height')) ||\n MAX_HEIGHT;\n popup.style.maxHeight = `${Math.max(0, Math.floor(Math.min(most, room)))}px`;\n more();\n // The popup is anchored at the host's right edge and grows leftwards.\n const wide = host.getBoundingClientRect().right - picture.left - AIR;\n popup.style.maxWidth = `${Math.max(0, Math.floor(wide))}px`;\n }\n\n /** `more` on the popup while rows wait below its foot, which then fades out. */\n function more(): void {\n popup.toggleAttribute('more', popup.scrollTop + popup.clientHeight < popup.scrollHeight - 1);\n }\n\n function clear(): void {\n for (const item of items()) {\n const handler = handlers.get(item);\n if (handler !== undefined) item.removeEventListener('click', handler);\n }\n setChildren(popup);\n }\n\n function item(part: string, text: string, handler: () => void): HTMLButtonElement {\n const node = el('button', part, text);\n node.type = 'button';\n node.tabIndex = -1;\n handlers.set(node, handler);\n node.addEventListener('click', handler);\n return node;\n }\n\n /** Draws the page on top of the stack. */\n function render(): void {\n clear();\n const page = stack[stack.length - 1];\n if (page === undefined) return;\n let tab = true;\n if (stack.length > 1) {\n const back = item('item back-item', page.label, () => {\n stack.pop();\n render();\n items()[0]?.focus();\n });\n back.setAttribute('role', 'menuitem');\n back.setAttribute('aria-label', options.back(page.label));\n popup.append(back);\n }\n for (const entry of page.entries) {\n if (isPage(entry)) {\n const link = item(`item page-item ${entry.name}-item`, entry.label, () => {\n stack.push(entry);\n render();\n items()[0]?.focus();\n });\n link.setAttribute('role', 'menuitem');\n link.setAttribute('aria-haspopup', 'menu');\n popup.append(link);\n continue;\n }\n const section = el('div', `section ${entry.name}-section`);\n section.setAttribute('role', 'group');\n if (entry.label !== undefined) {\n section.setAttribute('aria-label', entry.label);\n section.append(el('div', `section-label ${entry.name}-label`, entry.label));\n }\n for (const [id, text, detail, image, badges] of entry.items) {\n const choice = item(`item ${entry.name}-item`, text, () => {\n close();\n button.focus();\n entry.onSelect(id);\n });\n for (const badge of badges ?? []) choice.append(el('span', 'item-badge', badge));\n if (detail !== undefined) choice.append(el('span', 'item-detail', detail));\n if (image !== undefined) {\n // The text in a box of its own, so a long title ends in an ellipsis beside the picture.\n const [, ...rest] = choice.childNodes;\n setChildren(choice, el('span', 'item-text', text), ...rest);\n choice.prepend(picture(image));\n }\n choice.value = id;\n choice.setAttribute('role', 'menuitemradio');\n const on = id === entry.value;\n choice.setAttribute('aria-checked', String(on));\n state(choice, `item ${entry.name}-item`, { checked: on });\n // One tab stop: the first checked item.\n if (on && tab) {\n choice.tabIndex = 0;\n tab = false;\n }\n section.append(choice);\n }\n popup.append(section);\n }\n fit();\n }\n\n function close(): void {\n if (!open) return;\n open = false;\n popup.hidden = true;\n button.setAttribute('aria-expanded', 'false');\n host.removeAttribute('open');\n document.removeEventListener('pointerdown', outside, true);\n if (stack.length > 1) {\n stack = stack.slice(0, 1);\n render();\n }\n }\n\n function show(): void {\n if (open) return;\n open = true;\n popup.hidden = false;\n button.setAttribute('aria-expanded', 'true');\n host.setAttribute('open', '');\n document.addEventListener('pointerdown', outside, true);\n fit();\n (checked() ?? items()[0])?.focus();\n }\n\n function toggle(): void {\n if (open) close();\n else show();\n }\n\n function key(event: KeyboardEvent): void {\n // Handled already, by a handler that decides first.\n if (event.defaultPrevented) return;\n const list = items();\n const index = list.indexOf(focused() as HTMLButtonElement);\n let next: number;\n switch (event.key) {\n case 'ArrowDown':\n next = (index + 1) % list.length;\n break;\n case 'ArrowUp':\n next = (index - 1 + list.length) % list.length;\n break;\n case 'Home':\n next = 0;\n break;\n case 'End':\n next = list.length - 1;\n break;\n case 'Escape':\n event.preventDefault();\n if (stack.length > 1) {\n stack.pop();\n render();\n items()[0]?.focus();\n return;\n }\n close();\n button.focus();\n return;\n default:\n return;\n }\n event.preventDefault();\n list[next]?.focus();\n }\n\n button.addEventListener('click', toggle);\n popup.addEventListener('keydown', key);\n\n return {\n button,\n popup,\n label(text: string): void {\n name = text;\n button.setAttribute('aria-label', text);\n popup.setAttribute('aria-label', text);\n const root = stack[0];\n if (root !== undefined) stack[0] = { ...root, label: text };\n },\n fill(entries): void {\n first = entries;\n stack = [{ name: 'menu', label: name, entries: first }];\n render();\n },\n close,\n dispose(): void {\n close();\n clear();\n button.removeEventListener('click', toggle);\n popup.removeEventListener('keydown', key);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,MAAM,MAAM;;;;;;AAOZ,MAAM,aAAa;;AAGnB,SAAS,QAAQ,KAA+B;CAC9C,MAAM,OAAO,GAAG,OAAO,YAAY;CACnC,KAAK,MAAM;CACX,KAAK,UAAU;CACf,KAAK,WAAW;CAChB,KAAK,MAAM;CACX,OAAO;AACT;AAEA,SAAS,OAAO,OAAqC;CACnD,OAAO,aAAa;AACtB;AAEA,SAAgB,KAAK,SAA4B;CAC/C,MAAM,EAAE,SAAS;CACjB,MAAM,SAAS,GAAG,UAAU,QAAQ;CACpC,OAAO,OAAO;CACd,OAAO,aAAa,iBAAiB,MAAM;CAC3C,OAAO,aAAa,iBAAiB,OAAO;CAC5C,MAAM,QAAQ,GAAG,OAAO,OAAO;CAC/B,MAAM,iBAAiB,gBAAgB;EACrC,KAAK;CACP,CAAC;CACD,MAAM,aAAa,QAAQ,MAAM;CACjC,MAAM,SAAS;CAEf,IAAI,OAAO;CACX,IAAI,OAAO;CACX,IAAI,QAA8B,CAAC;;CAEnC,IAAI,QAAoB,CAAC;CACzB,MAAM,2BAAW,IAAI,QAAuC;CAE5D,SAAS,QAA6B;EACpC,OAAO,CAAC,GAAG,MAAM,iBAAiB,QAAQ,CAAC;CAC7C;CAEA,SAAS,UAAyC;EAChD,OAAO,MAAM,CAAC,CAAC,MAAM,SAAS,KAAK,aAAa,cAAc,MAAM,MAAM;CAC5E;;CAGA,SAAS,UAA0B;EACjC,OAAQ,MAAM,YAAY,CAAC,CAA2B;CACxD;CAEA,S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AK;IACH,OAAO;IACP;GACF,KAAK;IACH,OAAO,KAAK,SAAS;IACrB;GACF,KAAK;IACH,MAAM,eAAe;IACrB,IAAI,MAAM,SAAS,GAAG;KACpB,MAAM,IAAI;KACV,OAAO;KACP,MAAM,CAAC,CAAC,EAAE,EAAE,MAAM;KAClB;IACF;IACA,MAAM;IACN,OAAO,MAAM;IACb;GACF,SACE;EACJ;EACA,MAAM,eAAe;EACrB,KAAK,KAAK,EAAE,MAAM;CACpB;CAEA,OAAO,iBAAiB,SAAS,MAAM;CACvC,MAAM,iBAAiB,WAAW,GAAG;CAErC,OAAO;EACL;EACA;EACA,MAAM,MAAoB;GACxB,OAAO;GACP,OAAO,aAAa,cAAc,IAAI;GACtC,MAAM,aAAa,cAAc,IAAI;GACrC,MAAM,OAAO,MAAM;GACnB,IAAI,SAAS,KAAA,GAAW,MAAM,KAAK;IAAE,GAAG;IAAM,OAAO;GAAK;EAC5D;EACA,KAAK,SAAe;GAClB,QAAQ;GACR,QAAQ,CAAC;IAAE,MAAM;IAAQ,OAAO;IAAM,SAAS;GAAM,CAAC;GACtD,OAAO;EACT;EACA;EACA,UAAgB;GACd,MAAM;GACN,MAAM;GACN,OAAO,oBAAoB,SAAS,MAAM;GAC1C,MAAM,oBAAoB,WAAW,GAAG;EAC1C;CACF;AACF"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The element's own track lists, for the audio and subtitles menus of a
|
|
3
|
+
* native session. Safari lists the renditions of an HLS stream it plays
|
|
4
|
+
* itself in `audioTracks` and `textTracks`. No engine-shaped object goes
|
|
5
|
+
* over them: the menus read the lists and write `enabled` and `mode`.
|
|
6
|
+
* Each list is feature-tested, so a browser without it keeps the menu hidden.
|
|
7
|
+
*/
|
|
8
|
+
import type { PlayerHost } from '../host.js';
|
|
9
|
+
/** What the menus read of an `AudioTrack` or a `TextTrack`. */
|
|
10
|
+
export interface NativeTrack {
|
|
11
|
+
readonly kind: string;
|
|
12
|
+
readonly label: string;
|
|
13
|
+
readonly language: string;
|
|
14
|
+
}
|
|
15
|
+
/** An `AudioTrackList` or a `TextTrackList`. lib.dom has no `AudioTrackList`. */
|
|
16
|
+
export interface NativeTrackList<T extends NativeTrack> extends EventTarget {
|
|
17
|
+
readonly length: number;
|
|
18
|
+
readonly [index: number]: T;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The video's `audioTracks` or `textTracks` during a native session, or
|
|
22
|
+
* undefined: an engine session has its own tracks, and Chromium has no
|
|
23
|
+
* `audioTracks` without a flag.
|
|
24
|
+
*/
|
|
25
|
+
export declare function nativeTracks<T extends NativeTrack>(player: PlayerHost, name: 'audioTracks' | 'textTracks'): T[] | undefined;
|
|
26
|
+
/** Calls `tick` when the video's list of `name` changes, and answers the unsubscribe. */
|
|
27
|
+
export declare function onNativeTracks(video: HTMLVideoElement, name: 'audioTracks' | 'textTracks', tick: () => void): (() => void) | undefined;
|
|
28
|
+
//# sourceMappingURL=native-tracks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-tracks.d.ts","sourceRoot":"","sources":["../../src/controls/native-tracks.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE7C,+DAA+D;AAC/D,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B;AAED,iFAAiF;AACjF,MAAM,WAAW,eAAe,CAAC,CAAC,SAAS,WAAW,CAAE,SAAQ,WAAW;IACzE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;CAC7B;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,SAAS,WAAW,EAChD,MAAM,EAAE,UAAU,EAClB,IAAI,EAAE,aAAa,GAAG,YAAY,GACjC,CAAC,EAAE,GAAG,SAAS,CAKjB;AAED,yFAAyF;AACzF,wBAAgB,cAAc,CAC5B,KAAK,EAAE,gBAAgB,EACvB,IAAI,EAAE,aAAa,GAAG,YAAY,EAClC,IAAI,EAAE,MAAM,IAAI,GACf,CAAC,MAAM,IAAI,CAAC,GAAG,SAAS,CAQ1B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
//#region src/controls/native-tracks.ts
|
|
2
|
+
/**
|
|
3
|
+
* The video's `audioTracks` or `textTracks` during a native session, or
|
|
4
|
+
* undefined: an engine session has its own tracks, and Chromium has no
|
|
5
|
+
* `audioTracks` without a flag.
|
|
6
|
+
*/
|
|
7
|
+
function nativeTracks(player, name) {
|
|
8
|
+
const session = player.player?.session;
|
|
9
|
+
if (session == null || session.engine !== null) return void 0;
|
|
10
|
+
const list = player.video[name];
|
|
11
|
+
return list === void 0 ? void 0 : Array.from(list);
|
|
12
|
+
}
|
|
13
|
+
/** Calls `tick` when the video's list of `name` changes, and answers the unsubscribe. */
|
|
14
|
+
function onNativeTracks(video, name, tick) {
|
|
15
|
+
const list = video[name];
|
|
16
|
+
if (list === void 0) return void 0;
|
|
17
|
+
const events = [
|
|
18
|
+
"change",
|
|
19
|
+
"addtrack",
|
|
20
|
+
"removetrack"
|
|
21
|
+
];
|
|
22
|
+
for (const event of events) list.addEventListener(event, tick);
|
|
23
|
+
return () => {
|
|
24
|
+
for (const event of events) list.removeEventListener(event, tick);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { nativeTracks, onNativeTracks };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=native-tracks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-tracks.js","names":[],"sources":["../../src/controls/native-tracks.ts"],"sourcesContent":["/**\n * The element's own track lists, for the audio and subtitles menus of a\n * native session. Safari lists the renditions of an HLS stream it plays\n * itself in `audioTracks` and `textTracks`. No engine-shaped object goes\n * over them: the menus read the lists and write `enabled` and `mode`.\n * Each list is feature-tested, so a browser without it keeps the menu hidden.\n */\nimport type { PlayerHost } from '../host.js';\n\n/** What the menus read of an `AudioTrack` or a `TextTrack`. */\nexport interface NativeTrack {\n readonly kind: string;\n readonly label: string;\n readonly language: string;\n}\n\n/** An `AudioTrackList` or a `TextTrackList`. lib.dom has no `AudioTrackList`. */\nexport interface NativeTrackList<T extends NativeTrack> extends EventTarget {\n readonly length: number;\n readonly [index: number]: T;\n}\n\n/**\n * The video's `audioTracks` or `textTracks` during a native session, or\n * undefined: an engine session has its own tracks, and Chromium has no\n * `audioTracks` without a flag.\n */\nexport function nativeTracks<T extends NativeTrack>(\n player: PlayerHost,\n name: 'audioTracks' | 'textTracks',\n): T[] | undefined {\n const session = player.player?.session;\n if (session == null || session.engine !== null) return undefined;\n const list = (player.video as unknown as Record<string, NativeTrackList<T> | undefined>)[name];\n return list === undefined ? undefined : Array.from(list);\n}\n\n/** Calls `tick` when the video's list of `name` changes, and answers the unsubscribe. */\nexport function onNativeTracks(\n video: HTMLVideoElement,\n name: 'audioTracks' | 'textTracks',\n tick: () => void,\n): (() => void) | undefined {\n const list = (video as unknown as Record<string, EventTarget | undefined>)[name];\n if (list === undefined) return undefined;\n const events = ['change', 'addtrack', 'removetrack'];\n for (const event of events) list.addEventListener(event, tick);\n return () => {\n for (const event of events) list.removeEventListener(event, tick);\n };\n}\n"],"mappings":";;;;;;AA2BA,SAAgB,aACd,QACA,MACiB;CACjB,MAAM,UAAU,OAAO,QAAQ;CAC/B,IAAI,WAAW,QAAQ,QAAQ,WAAW,MAAM,OAAO,KAAA;CACvD,MAAM,OAAQ,OAAO,MAAoE;CACzF,OAAO,SAAS,KAAA,IAAY,KAAA,IAAY,MAAM,KAAK,IAAI;AACzD;;AAGA,SAAgB,eACd,OACA,MACA,MAC0B;CAC1B,MAAM,OAAQ,MAA6D;CAC3E,IAAI,SAAS,KAAA,GAAW,OAAO,KAAA;CAC/B,MAAM,SAAS;EAAC;EAAU;EAAY;CAAa;CACnD,KAAK,MAAM,SAAS,QAAQ,KAAK,iBAAiB,OAAO,IAAI;CAC7D,aAAa;EACX,KAAK,MAAM,SAAS,QAAQ,KAAK,oBAAoB,OAAO,IAAI;CAClE;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words the quality menu shows for each rendition, best first. Pure,
|
|
3
|
+
* node-tested.
|
|
4
|
+
*
|
|
5
|
+
* A label grows only as far as it must to tell entries apart: the height,
|
|
6
|
+
* the frame rate above 30, Dolby Vision or HDR, then the bitrate where two
|
|
7
|
+
* entries read the same, then the codec where they still do. Entries that
|
|
8
|
+
* read the same after that are one choice for a viewer, and show once.
|
|
9
|
+
*/
|
|
10
|
+
import type { Rendition } from 'mattebox';
|
|
11
|
+
/** The label of every rendition, best first, twins included. */
|
|
12
|
+
export declare function qualityLabels(renditions: readonly Rendition[]): Array<readonly [id: string, label: string]>;
|
|
13
|
+
/** The label of each rendition, best first, one entry per distinct label. */
|
|
14
|
+
export declare function qualityNames(renditions: readonly Rendition[]): Array<readonly [id: string, label: string]>;
|
|
15
|
+
//# sourceMappingURL=quality-names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quality-names.d.ts","sourceRoot":"","sources":["../../src/controls/quality-names.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAqC1C,gEAAgE;AAChE,wBAAgB,aAAa,CAC3B,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CA8B7C;AAED,6EAA6E;AAC7E,wBAAgB,YAAY,CAC1B,UAAU,EAAE,SAAS,SAAS,EAAE,GAC/B,KAAK,CAAC,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC,CAO7C"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
//#region src/controls/quality-names.ts
|
|
2
|
+
/** The codec families a viewer may recognise, by their RFC 6381 prefix. */
|
|
3
|
+
const CODECS = [
|
|
4
|
+
[/^av(c1|c3)/, "H.264"],
|
|
5
|
+
[/^h(vc1|ev1)/, "HEVC"],
|
|
6
|
+
[/^vp0?9/, "VP9"],
|
|
7
|
+
[/^av01/, "AV1"]
|
|
8
|
+
];
|
|
9
|
+
/** Dolby Vision, in the codec itself or as a layer over it. */
|
|
10
|
+
function dolbyVision(rendition) {
|
|
11
|
+
const codecs = `${rendition.codecs ?? ""},${rendition.supplementalCodecs ?? ""}`;
|
|
12
|
+
return /(^|[,/])\s*(dvh1|dvhe|dav1|dva1)/.test(codecs);
|
|
13
|
+
}
|
|
14
|
+
/** 0 for SDR, 1 for HDR, 2 for Dolby Vision: the sort order and the word. */
|
|
15
|
+
function range(rendition) {
|
|
16
|
+
if (dolbyVision(rendition)) return 2;
|
|
17
|
+
return rendition.videoRange === "PQ" || rendition.videoRange === "HLG" ? 1 : 0;
|
|
18
|
+
}
|
|
19
|
+
function rate(rendition) {
|
|
20
|
+
return Math.round(rendition.frameRate ?? 0);
|
|
21
|
+
}
|
|
22
|
+
/** The average bitrate where the manifest gives one: closer to what plays. */
|
|
23
|
+
function bitrate(rendition) {
|
|
24
|
+
const bps = rendition.averageBitrate ?? rendition.bitrate;
|
|
25
|
+
return bps < 1e6 ? `${Math.round(bps / 1e3)} kbps` : `${(bps / 1e6).toFixed(1)} Mbps`;
|
|
26
|
+
}
|
|
27
|
+
function codec(rendition) {
|
|
28
|
+
const codecs = rendition.codecs ?? "";
|
|
29
|
+
return CODECS.find(([pattern]) => pattern.test(codecs))?.[1];
|
|
30
|
+
}
|
|
31
|
+
/** The label of every rendition, best first, twins included. */
|
|
32
|
+
function qualityLabels(renditions) {
|
|
33
|
+
const sorted = [...renditions].sort((a, b) => (b.height ?? 0) - (a.height ?? 0) || rate(b) - rate(a) || range(b) - range(a) || (b.averageBitrate ?? b.bitrate) - (a.averageBitrate ?? a.bitrate));
|
|
34
|
+
const bases = sorted.map((r) => {
|
|
35
|
+
return `${r.height === void 0 ? bitrate(r) : `${r.height}p`}${rate(r) > 30 ? String(rate(r)) : ""}${[
|
|
36
|
+
"",
|
|
37
|
+
" HDR",
|
|
38
|
+
" Dolby Vision"
|
|
39
|
+
][range(r)]}`;
|
|
40
|
+
});
|
|
41
|
+
let labels = bases;
|
|
42
|
+
for (const part of [bitrate, codec]) labels = labels.map((label, i) => {
|
|
43
|
+
const twin = labels.some((other, j) => j !== i && other === label);
|
|
44
|
+
const extra = part(sorted[i]);
|
|
45
|
+
return twin && extra !== void 0 && !label.endsWith(extra) ? `${label} · ${extra}` : label;
|
|
46
|
+
});
|
|
47
|
+
labels = labels.map((label, i) => bases.every((base, j) => base !== bases[i] || labels[j] === label) ? bases[i] : label);
|
|
48
|
+
return sorted.map((r, i) => [r.id, labels[i]]);
|
|
49
|
+
}
|
|
50
|
+
/** The label of each rendition, best first, one entry per distinct label. */
|
|
51
|
+
function qualityNames(renditions) {
|
|
52
|
+
const seen = /* @__PURE__ */ new Set();
|
|
53
|
+
return qualityLabels(renditions).filter(([, label]) => {
|
|
54
|
+
if (seen.has(label)) return false;
|
|
55
|
+
seen.add(label);
|
|
56
|
+
return true;
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
export { qualityLabels, qualityNames };
|
|
61
|
+
|
|
62
|
+
//# sourceMappingURL=quality-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quality-names.js","names":[],"sources":["../../src/controls/quality-names.ts"],"sourcesContent":["/**\n * The words the quality menu shows for each rendition, best first. Pure,\n * node-tested.\n *\n * A label grows only as far as it must to tell entries apart: the height,\n * the frame rate above 30, Dolby Vision or HDR, then the bitrate where two\n * entries read the same, then the codec where they still do. Entries that\n * read the same after that are one choice for a viewer, and show once.\n */\nimport type { Rendition } from 'mattebox';\n\n/** The codec families a viewer may recognise, by their RFC 6381 prefix. */\nconst CODECS: ReadonlyArray<readonly [RegExp, string]> = [\n [/^av(c1|c3)/, 'H.264'],\n [/^h(vc1|ev1)/, 'HEVC'],\n [/^vp0?9/, 'VP9'],\n [/^av01/, 'AV1'],\n];\n\n/** Dolby Vision, in the codec itself or as a layer over it. */\nfunction dolbyVision(rendition: Rendition): boolean {\n const codecs = `${rendition.codecs ?? ''},${rendition.supplementalCodecs ?? ''}`;\n return /(^|[,/])\\s*(dvh1|dvhe|dav1|dva1)/.test(codecs);\n}\n\n/** 0 for SDR, 1 for HDR, 2 for Dolby Vision: the sort order and the word. */\nfunction range(rendition: Rendition): number {\n if (dolbyVision(rendition)) return 2;\n return rendition.videoRange === 'PQ' || rendition.videoRange === 'HLG' ? 1 : 0;\n}\n\nfunction rate(rendition: Rendition): number {\n return Math.round(rendition.frameRate ?? 0);\n}\n\n/** The average bitrate where the manifest gives one: closer to what plays. */\nfunction bitrate(rendition: Rendition): string {\n const bps = rendition.averageBitrate ?? rendition.bitrate;\n return bps < 1e6 ? `${Math.round(bps / 1000)} kbps` : `${(bps / 1e6).toFixed(1)} Mbps`;\n}\n\nfunction codec(rendition: Rendition): string | undefined {\n const codecs = rendition.codecs ?? '';\n return CODECS.find(([pattern]) => pattern.test(codecs))?.[1];\n}\n\n/** The label of every rendition, best first, twins included. */\nexport function qualityLabels(\n renditions: readonly Rendition[],\n): Array<readonly [id: string, label: string]> {\n const sorted = [...renditions].sort(\n (a, b) =>\n (b.height ?? 0) - (a.height ?? 0) ||\n rate(b) - rate(a) ||\n range(b) - range(a) ||\n (b.averageBitrate ?? b.bitrate) - (a.averageBitrate ?? a.bitrate),\n );\n const bases = sorted.map((r) => {\n const base = r.height === undefined ? bitrate(r) : `${r.height}p`;\n const fps = rate(r) > 30 ? String(rate(r)) : '';\n return `${base}${fps}${['', ' HDR', ' Dolby Vision'][range(r)]}`;\n });\n // Each step adds its part only to the entries that still share a label.\n let labels = bases;\n for (const part of [bitrate, codec]) {\n labels = labels.map((label, i) => {\n const twin = labels.some((other, j) => j !== i && other === label);\n const extra = part(sorted[i] as Rendition);\n return twin && extra !== undefined && !label.endsWith(extra) ? `${label} · ${extra}` : label;\n });\n }\n // Where nothing told a group apart (one stream on two CDNs), the parts\n // added are noise: the group keeps its base label.\n labels = labels.map((label, i) =>\n bases.every((base, j) => base !== bases[i] || labels[j] === label)\n ? (bases[i] as string)\n : label,\n );\n return sorted.map((r, i) => [r.id, labels[i] as string] as const);\n}\n\n/** The label of each rendition, best first, one entry per distinct label. */\nexport function qualityNames(\n renditions: readonly Rendition[],\n): Array<readonly [id: string, label: string]> {\n const seen = new Set<string>();\n return qualityLabels(renditions).filter(([, label]) => {\n if (seen.has(label)) return false;\n seen.add(label);\n return true;\n });\n}\n"],"mappings":";;AAYA,MAAM,SAAmD;CACvD,CAAC,cAAc,OAAO;CACtB,CAAC,eAAe,MAAM;CACtB,CAAC,UAAU,KAAK;CAChB,CAAC,SAAS,KAAK;AACjB;;AAGA,SAAS,YAAY,WAA+B;CAClD,MAAM,SAAS,GAAG,UAAU,UAAU,GAAG,GAAG,UAAU,sBAAsB;CAC5E,OAAO,mCAAmC,KAAK,MAAM;AACvD;;AAGA,SAAS,MAAM,WAA8B;CAC3C,IAAI,YAAY,SAAS,GAAG,OAAO;CACnC,OAAO,UAAU,eAAe,QAAQ,UAAU,eAAe,QAAQ,IAAI;AAC/E;AAEA,SAAS,KAAK,WAA8B;CAC1C,OAAO,KAAK,MAAM,UAAU,aAAa,CAAC;AAC5C;;AAGA,SAAS,QAAQ,WAA8B;CAC7C,MAAM,MAAM,UAAU,kBAAkB,UAAU;CAClD,OAAO,MAAM,MAAM,GAAG,KAAK,MAAM,MAAM,GAAI,EAAE,SAAS,IAAI,MAAM,IAAA,CAAK,QAAQ,CAAC,EAAE;AACl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AAC,QAAQ,GAAG,WAAW;EACrD,IAAI,KAAK,IAAI,KAAK,GAAG,OAAO;EAC5B,KAAK,IAAI,KAAK;EACd,OAAO;CACT,CAAC;AACH"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words the audio and subtitles menus show for a track, for an engine
|
|
3
|
+
* session and a native one alike. Pure, node-tested.
|
|
4
|
+
*/
|
|
5
|
+
import type { MenuGroup } from './menu.js';
|
|
6
|
+
/**
|
|
7
|
+
* One menu entry: its value, the stream's name for it, its language code,
|
|
8
|
+
* its badges, and the hints that tell it from a twin, in the order they
|
|
9
|
+
* are tried.
|
|
10
|
+
*/
|
|
11
|
+
export type TrackEntry = readonly [
|
|
12
|
+
value: string,
|
|
13
|
+
name: string | undefined,
|
|
14
|
+
lang: string | undefined,
|
|
15
|
+
badges: readonly string[],
|
|
16
|
+
hints: ReadonlyArray<string | undefined>
|
|
17
|
+
];
|
|
18
|
+
/**
|
|
19
|
+
* The language's name in `locale`, with a capital first letter as the
|
|
20
|
+
* browsers' own menus show it: French gives "anglais", the menu shows
|
|
21
|
+
* "Anglais". Undefined without `Intl.DisplayNames` (Chromium 81, so not on
|
|
22
|
+
* Tizen 6 or webOS 6), for a code it does not know, and for a locale or a
|
|
23
|
+
* code it rejects.
|
|
24
|
+
*/
|
|
25
|
+
export declare function languageName(lang: string, locale?: string): string | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* The audio layout of an HLS CHANNELS value (RFC 8216bis §4.4.6.1): "2"
|
|
28
|
+
* reads Stereo, "6" reads 5.1, a "/JOC" suffix reads Dolby Atmos. Any
|
|
29
|
+
* other count reads as written.
|
|
30
|
+
*/
|
|
31
|
+
export declare function layout(channels: string | undefined): string | undefined;
|
|
32
|
+
/**
|
|
33
|
+
* The entries as menu items. Each reads as its name, else its language's
|
|
34
|
+
* name, else its language code, else `word` ("Track") and its place. An
|
|
35
|
+
* entry that would read like another, badges included, takes in
|
|
36
|
+
* parentheses its first hint that differs from the other's, and at last
|
|
37
|
+
* its place.
|
|
38
|
+
*/
|
|
39
|
+
export declare function trackNames(entries: readonly TrackEntry[], word: string | null, locale?: string): MenuGroup['items'];
|
|
40
|
+
//# sourceMappingURL=track-names.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track-names.d.ts","sourceRoot":"","sources":["../../src/controls/track-names.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAE3C;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,SAAS;IAChC,KAAK,EAAE,MAAM;IACb,IAAI,EAAE,MAAM,GAAG,SAAS;IACxB,IAAI,EAAE,MAAM,GAAG,SAAS;IACxB,MAAM,EAAE,SAAS,MAAM,EAAE;IACzB,KAAK,EAAE,aAAa,CAAC,MAAM,GAAG,SAAS,CAAC;CACzC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAW9E;AAID;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAEvE;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,SAAS,UAAU,EAAE,EAC9B,IAAI,EAAE,MAAM,GAAG,IAAI,EACnB,MAAM,GAAE,MAA4D,GACnE,SAAS,CAAC,OAAO,CAAC,CA2BpB"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/controls/track-names.ts
|
|
2
|
+
/**
|
|
3
|
+
* The language's name in `locale`, with a capital first letter as the
|
|
4
|
+
* browsers' own menus show it: French gives "anglais", the menu shows
|
|
5
|
+
* "Anglais". Undefined without `Intl.DisplayNames` (Chromium 81, so not on
|
|
6
|
+
* Tizen 6 or webOS 6), for a code it does not know, and for a locale or a
|
|
7
|
+
* code it rejects.
|
|
8
|
+
*/
|
|
9
|
+
function languageName(lang, locale) {
|
|
10
|
+
try {
|
|
11
|
+
const name = new Intl.DisplayNames(locale, {
|
|
12
|
+
type: "language",
|
|
13
|
+
fallback: "none"
|
|
14
|
+
}).of(lang);
|
|
15
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
16
|
+
} catch {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const LAYOUTS = {
|
|
21
|
+
1: "Mono",
|
|
22
|
+
2: "Stereo",
|
|
23
|
+
6: "5.1",
|
|
24
|
+
8: "7.1"
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* The audio layout of an HLS CHANNELS value (RFC 8216bis §4.4.6.1): "2"
|
|
28
|
+
* reads Stereo, "6" reads 5.1, a "/JOC" suffix reads Dolby Atmos. Any
|
|
29
|
+
* other count reads as written.
|
|
30
|
+
*/
|
|
31
|
+
function layout(channels) {
|
|
32
|
+
return channels && (/\/JOC$/.test(channels) ? "Dolby Atmos" : LAYOUTS[channels] || channels);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* The entries as menu items. Each reads as its name, else its language's
|
|
36
|
+
* name, else its language code, else `word` ("Track") and its place. An
|
|
37
|
+
* entry that would read like another, badges included, takes in
|
|
38
|
+
* parentheses its first hint that differs from the other's, and at last
|
|
39
|
+
* its place.
|
|
40
|
+
*/
|
|
41
|
+
function trackNames(entries, word, locale = document.documentElement.lang || navigator.language) {
|
|
42
|
+
let texts = entries.map(([, name, lang], index) => name || lang && (languageName(lang, locale) || lang) || `${word || "Track"} ${index + 1}`);
|
|
43
|
+
for (let round = 0; round < 3; round++) {
|
|
44
|
+
const keys = texts.map((text, index) => text + entries[index][3]);
|
|
45
|
+
const hint = (index) => round < 2 ? entries[index][4][round] : String(index + 1);
|
|
46
|
+
texts = texts.map((text, index) => hint(index) && keys.some((key, other) => other !== index && key === keys[index] && hint(other) !== hint(index)) ? `${text} (${hint(index)})` : text);
|
|
47
|
+
}
|
|
48
|
+
return entries.map(([value, , , badges], index) => [
|
|
49
|
+
value,
|
|
50
|
+
texts[index],
|
|
51
|
+
void 0,
|
|
52
|
+
void 0,
|
|
53
|
+
badges
|
|
54
|
+
]);
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
export { languageName, layout, trackNames };
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=track-names.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"track-names.js","names":[],"sources":["../../src/controls/track-names.ts"],"sourcesContent":["/**\n * The words the audio and subtitles menus show for a track, for an engine\n * session and a native one alike. Pure, node-tested.\n */\nimport type { MenuGroup } from './menu.js';\n\n/**\n * One menu entry: its value, the stream's name for it, its language code,\n * its badges, and the hints that tell it from a twin, in the order they\n * are tried.\n */\nexport type TrackEntry = readonly [\n value: string,\n name: string | undefined,\n lang: string | undefined,\n badges: readonly string[],\n hints: ReadonlyArray<string | undefined>,\n];\n\n/**\n * The language's name in `locale`, with a capital first letter as the\n * browsers' own menus show it: French gives \"anglais\", the menu shows\n * \"Anglais\". Undefined without `Intl.DisplayNames` (Chromium 81, so not on\n * Tizen 6 or webOS 6), for a code it does not know, and for a locale or a\n * code it rejects.\n */\nexport function languageName(lang: string, locale?: string): string | undefined {\n try {\n // lib.dom types `Intl.DisplayNames` as always present.\n const name = new (Intl as { DisplayNames: typeof Intl.DisplayNames }).DisplayNames(locale, {\n type: 'language',\n fallback: 'none',\n }).of(lang) as string;\n return name.charAt(0).toUpperCase() + name.slice(1);\n } catch {\n return undefined;\n }\n}\n\nconst LAYOUTS: Readonly<Record<string, string>> = { 1: 'Mono', 2: 'Stereo', 6: '5.1', 8: '7.1' };\n\n/**\n * The audio layout of an HLS CHANNELS value (RFC 8216bis §4.4.6.1): \"2\"\n * reads Stereo, \"6\" reads 5.1, a \"/JOC\" suffix reads Dolby Atmos. Any\n * other count reads as written.\n */\nexport function layout(channels: string | undefined): string | undefined {\n return channels && (/\\/JOC$/.test(channels) ? 'Dolby Atmos' : LAYOUTS[channels] || channels);\n}\n\n/**\n * The entries as menu items. Each reads as its name, else its language's\n * name, else its language code, else `word` (\"Track\") and its place. An\n * entry that would read like another, badges included, takes in\n * parentheses its first hint that differs from the other's, and at last\n * its place.\n */\nexport function trackNames(\n entries: readonly TrackEntry[],\n word: string | null,\n locale: string = document.documentElement.lang || navigator.language,\n): MenuGroup['items'] {\n let texts = entries.map(\n ([, name, lang], index) =>\n name || (lang && (languageName(lang, locale) || lang)) || `${word || 'Track'} ${index + 1}`,\n );\n // Two rounds of hints at most (the audio menu's layout and role), then the place.\n for (let round = 0; round < 3; round++) {\n const keys = texts.map((text, index) => text + (entries[index] as TrackEntry)[3]);\n const hint = (index: number): string | undefined =>\n round < 2 ? (entries[index] as TrackEntry)[4][round] : String(index + 1);\n // A hint the twins share tells nothing apart, so the next round tries another.\n texts = texts.map((text, index) =>\n hint(index) &&\n keys.some(\n (key, other) => other !== index && key === keys[index] && hint(other) !== hint(index),\n )\n ? `${text} (${hint(index)})`\n : text,\n );\n }\n return entries.map(([value, , , badges], index) => [\n value,\n texts[index] as string,\n undefined,\n undefined,\n badges,\n ]);\n}\n"],"mappings":";;;;;;;;AA0BA,SAAgB,aAAa,MAAc,QAAqC;CAC9E,IAAI;EAEF,MAAM,OAAO,IAAK,KAAoD,aAAa,QAAQ;GACzF,MAAM;GACN,UAAU;EACZ,CAAC,CAAC,CAAC,GAAG,IAAI;EACV,OAAO,KAAK,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI,KAAK,MAAM,CAAC;CACpD,QAAQ;EACN;CACF;AACF;AAEA,MAAM,UAA4C;CAAE,GAAG;CAAQ,GAAG;CAAU,GAAG;CAAO,GAAG;AAAM;;;;;;AAO/F,SAAgB,OAAO,UAAkD;CACvE,OAAO,aAAa,SAAS,KAAK,QAAQ,IAAI,gBAAgB,QAAQ,aAAa;AACrF;;;;;;;;AASA,SAAgB,WACd,SACA,MACA,SAAiB,SAAS,gBAAgB,QAAQ,UAAU,UACxC;CACpB,IAAI,QAAQ,QAAQ,KACjB,GAAG,MAAM,OAAO,UACf,QAAS,SAAS,aAAa,MAAM,MAAM,KAAK,SAAU,GAAG,QAAQ,QAAQ,GAAG,QAAQ,GAC5F;CAEA,KAAK,IAAI,QAAQ,GAAG,QAAQ,GAAG,SAAS;EACtC,MAAM,OAAO,MAAM,KAAK,MAAM,UAAU,OAAQ,QAAQ,MAAM,CAAgB,EAAE;EAChF,MAAM,QAAQ,UACZ,QAAQ,IAAK,QAAQ,MAAM,CAAgB,EAAE,CAAC,SAAS,OAAO,QAAQ,CAAC;EAEzE,QAAQ,MAAM,KAAK,MAAM,UACvB,KAAK,KAAK,KACV,KAAK,MACF,KAAK,UAAU,UAAU,SAAS,QAAQ,KAAK,UAAU,KAAK,KAAK,MAAM,KAAK,KAAK,CACtF,IACI,GAAG,KAAK,IAAI,KAAK,KAAK,EAAE,KACxB,IACN;CACF;CACA,OAAO,QAAQ,KAAK,CAAC,WAAW,SAAS,UAAU;EACjD;EACA,MAAM;EACN,KAAA;EACA,KAAA;EACA;CACF,CAAC;AACH"}
|
package/dist/element.d.ts
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import type { Handler, Player, PlayerError, Session } from '@mattebox/player-core';
|
|
21
21
|
import type { KernelConfig, Mattebox, Stage } from 'mattebox';
|
|
22
|
+
import type { AttachEmeOptions } from 'mattebox/eme';
|
|
23
|
+
import type { Marker, Markers } from './controls/markers.js';
|
|
22
24
|
import type { PlayerHost } from './host.js';
|
|
23
25
|
/**
|
|
24
26
|
* What the element dispatches. `error` is also a standard DOM event name, so
|
|
@@ -28,6 +30,10 @@ import type { PlayerHost } from './host.js';
|
|
|
28
30
|
export interface MatteboxPlayerEventMap {
|
|
29
31
|
sourcechange: CustomEvent<Session | null>;
|
|
30
32
|
error: CustomEvent<PlayerError>;
|
|
33
|
+
/** The markers changed: set by the page, or cleared by a new source. */
|
|
34
|
+
markerschange: CustomEvent<readonly Marker[]>;
|
|
35
|
+
/** Playback reached a blocked range and moved past it. */
|
|
36
|
+
blocked: CustomEvent<Marker>;
|
|
31
37
|
}
|
|
32
38
|
export interface MatteboxPlayerElement {
|
|
33
39
|
addEventListener<K extends keyof MatteboxPlayerEventMap>(type: K, listener: (this: MatteboxPlayerElement, event: MatteboxPlayerEventMap[K]) => void, options?: boolean | AddEventListenerOptions): void;
|
|
@@ -46,6 +52,15 @@ export interface MatteboxPlayerOptions {
|
|
|
46
52
|
* `handlers`, which carry their own.
|
|
47
53
|
*/
|
|
48
54
|
readonly config?: Partial<KernelConfig>;
|
|
55
|
+
/**
|
|
56
|
+
* DRM for a native session, as `attachEme` from `mattebox/eme` takes it:
|
|
57
|
+
* `keySystems`, `licenseUrl`, `licenseUrls`, `requestHook`. Without
|
|
58
|
+
* `keySystems` the session offers the key-system stages of the engine's
|
|
59
|
+
* stack. The `license-url` attribute overrides `licenseUrl`, and
|
|
60
|
+
* `certificate-url` gives the FairPlay certificate. Ignored
|
|
61
|
+
* with `handlers`, which carry their own.
|
|
62
|
+
*/
|
|
63
|
+
readonly drm?: AttachEmeOptions;
|
|
49
64
|
}
|
|
50
65
|
/**
|
|
51
66
|
* The interface above merges only `addEventListener` and `removeEventListener`
|
|
@@ -68,6 +83,7 @@ export declare class MatteboxPlayerElement extends HTMLElement implements Player
|
|
|
68
83
|
/** Whether the element gave itself a tabindex for the bar, to take back with it. */
|
|
69
84
|
private focusable;
|
|
70
85
|
private readonly surface;
|
|
86
|
+
private readonly marks;
|
|
71
87
|
/** The chapters track element, while the `chapters` attribute names one and the engine takes none. */
|
|
72
88
|
private track;
|
|
73
89
|
/** The chapters URL the current session's engine was given, or null. */
|
|
@@ -90,6 +106,8 @@ export declare class MatteboxPlayerElement extends HTMLElement implements Player
|
|
|
90
106
|
constructor(options?: MatteboxPlayerOptions);
|
|
91
107
|
/** The media element. Everything the browser already does is here. */
|
|
92
108
|
get video(): HTMLVideoElement;
|
|
109
|
+
/** The ranges the page named in this source: credits to skip, parts that must not play. */
|
|
110
|
+
get markers(): Markers;
|
|
93
111
|
/** The core, or null until the first source has been set up: resolving a preset is asynchronous. */
|
|
94
112
|
get player(): Player | null;
|
|
95
113
|
/** The engine feeding the video, or null for a native session and before the first load. */
|
|
@@ -137,6 +155,12 @@ export declare class MatteboxPlayerElement extends HTMLElement implements Player
|
|
|
137
155
|
private run;
|
|
138
156
|
private ensure;
|
|
139
157
|
private chain;
|
|
158
|
+
/**
|
|
159
|
+
* The DRM a native session attaches: the page's `drm` option, the
|
|
160
|
+
* key-system stages of the engine's stack, and the `license-url`
|
|
161
|
+
* attribute. None on a browser without EME, as for the engine.
|
|
162
|
+
*/
|
|
163
|
+
private drm;
|
|
140
164
|
/** What the attributes ask of the session's namespaces, once there is one. */
|
|
141
165
|
private configure;
|
|
142
166
|
private unmount;
|
package/dist/element.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAU,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../src/element.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAU,MAAM,uBAAuB,CAAC;AAQ3F,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAE7D,OAAO,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AI,QAAQ,GAAG,IAAI,CAE5B;IAED;;;;;OAKG;IACH,IAAI,KAAK,IAAI,WAAW,GAAG,IAAI,CAE9B;IAED,iBAAiB,IAAI,IAAI;IAOzB,yGAAyG;IACzG,OAAO,CAAC,IAAI;IAeZ,oFAAoF;IACpF,OAAO,CAAC,OAAO;IAgBf;;;;;;OAMG;IACH,OAAO,CAAC,KAAK;IAUb,oBAAoB,IAAI,IAAI;IAM5B,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IA8B5C;;;;OAIG;IACH,OAAO,CAAC,IAAI;IAkBZ,0GAA0G;IAC1G,OAAO,CAAC,QAAQ;IAmChB,OAAO,CAAC,OAAO;IAUf,OAAO,CAAC,OAAO;IAIf;;;;OAIG;IACH,OAAO,CAAC,MAAM;IASd,OAAO,CAAC,IAAI;IAIZ,OAAO,CAAC,MAAM;YAUA,GAAG;YAoCH,MAAM;YAkBN,KAAK;IAiCnB;;;;OAIG;IACH,OAAO,CAAC,GAAG;IAeX,8EAA8E;IAC9E,OAAO,CAAC,SAAS;IAwBjB,OAAO,CAAC,OAAO;YAID,QAAQ;IAKtB,mFAAmF;YACrE,OAAO;CAMtB"}
|
package/dist/element.js
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
+
import { createMarkers } from "./controls/markers.js";
|
|
1
2
|
import { namespaces } from "./namespaces.js";
|
|
2
3
|
import { drmGuard, resolvePreset } from "./presets.js";
|
|
3
4
|
import { STYLE } from "./style.js";
|
|
4
5
|
import { errorSurface } from "./surface.js";
|
|
5
6
|
import { PLAYER } from "./tags.js";
|
|
6
|
-
import { createPlayer, inferType, matteboxHandler, nativeHandler } from "@mattebox/player-core";
|
|
7
|
+
import { createPlayer, inferType, matteboxHandler, nativeHandler, preferNativeHls } from "@mattebox/player-core";
|
|
7
8
|
//#region src/element.ts
|
|
9
|
+
/**
|
|
10
|
+
* `off` keeps HLS on the engine in Safari. Anything else lets Safari play
|
|
11
|
+
* HLS itself: FairPlay, AirPlay, Low-Latency HLS and the platform's
|
|
12
|
+
* fullscreen then work as Apple built them. Changing it reloads.
|
|
13
|
+
*/
|
|
14
|
+
const NATIVE_HLS = "native-hls";
|
|
8
15
|
/** Attributes forwarded onto the video as attributes, never as properties. */
|
|
9
16
|
const FORWARDED = [
|
|
10
17
|
"autoplay",
|
|
@@ -18,7 +25,9 @@ const OWN = [
|
|
|
18
25
|
"type",
|
|
19
26
|
"preset",
|
|
20
27
|
"license-url",
|
|
21
|
-
"
|
|
28
|
+
"certificate-url",
|
|
29
|
+
"thumbnails",
|
|
30
|
+
NATIVE_HLS
|
|
22
31
|
];
|
|
23
32
|
/**
|
|
24
33
|
* The chapters file URL. A session with the engine's `chapters` namespace
|
|
@@ -49,6 +58,7 @@ const STATE_EVENTS = [
|
|
|
49
58
|
"play",
|
|
50
59
|
"pause",
|
|
51
60
|
"ended",
|
|
61
|
+
"seeked",
|
|
52
62
|
"emptied",
|
|
53
63
|
"volumechange",
|
|
54
64
|
"loadedmetadata",
|
|
@@ -58,6 +68,8 @@ const STATE_EVENTS = [
|
|
|
58
68
|
"stalled",
|
|
59
69
|
"canplay"
|
|
60
70
|
];
|
|
71
|
+
/** The stages that register a key system, which a native session's DRM offers. */
|
|
72
|
+
const KEY_SYSTEMS = ["eme-fairplay", "eme-cenc"];
|
|
61
73
|
/** Every stage the engine ships. A narrower preset is optimization. */
|
|
62
74
|
const DEFAULT_PRESET = "full";
|
|
63
75
|
/**
|
|
@@ -117,6 +129,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
117
129
|
this.media.addEventListener("playing", () => {
|
|
118
130
|
this.failure = null;
|
|
119
131
|
});
|
|
132
|
+
this.marks = createMarkers(this.media, (name, detail) => this.emit(name, detail));
|
|
120
133
|
this.stage = document.createElement("div");
|
|
121
134
|
this.stage.setAttribute("part", "stage");
|
|
122
135
|
this.stage.append(document.createElement("slot"));
|
|
@@ -132,6 +145,10 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
132
145
|
get video() {
|
|
133
146
|
return this.media;
|
|
134
147
|
}
|
|
148
|
+
/** The ranges the page named in this source: credits to skip, parts that must not play. */
|
|
149
|
+
get markers() {
|
|
150
|
+
return this.marks;
|
|
151
|
+
}
|
|
135
152
|
/** The core, or null until the first source has been set up: resolving a preset is asynchronous. */
|
|
136
153
|
get player() {
|
|
137
154
|
return this.core;
|
|
@@ -215,6 +232,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
215
232
|
}
|
|
216
233
|
if (name === "preset") this.enqueue(() => this.discard());
|
|
217
234
|
if (name === "src" || name === "type") this.toggleAttribute("audio", this.audio());
|
|
235
|
+
if (name === "src" && this.marks.list.length > 0) this.marks.set([]);
|
|
218
236
|
this.reload();
|
|
219
237
|
}
|
|
220
238
|
/**
|
|
@@ -343,10 +361,14 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
343
361
|
async chain() {
|
|
344
362
|
if (this.options.handlers !== void 0) return this.options.handlers;
|
|
345
363
|
const config = this.options.config === void 0 ? {} : { config: this.options.config };
|
|
364
|
+
const native = (stages) => nativeHandler({
|
|
365
|
+
prefer: (source, env) => this.getAttribute(NATIVE_HLS) !== "off" && preferNativeHls(source, env),
|
|
366
|
+
drm: () => this.drm(stages)
|
|
367
|
+
});
|
|
346
368
|
if (this.options.stages !== void 0) return [matteboxHandler({
|
|
347
369
|
stages: this.options.stages,
|
|
348
370
|
...config
|
|
349
|
-
}),
|
|
371
|
+
}), native(() => this.options.stages ?? [])];
|
|
350
372
|
const name = this.getAttribute("preset") ?? DEFAULT_PRESET;
|
|
351
373
|
const preset = await resolvePreset(name);
|
|
352
374
|
if (preset === null) {
|
|
@@ -364,7 +386,26 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
364
386
|
preset,
|
|
365
387
|
...config,
|
|
366
388
|
...drmGuard()
|
|
367
|
-
}),
|
|
389
|
+
}), native(() => preset.stages())];
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* The DRM a native session attaches: the page's `drm` option, the
|
|
393
|
+
* key-system stages of the engine's stack, and the `license-url`
|
|
394
|
+
* attribute. None on a browser without EME, as for the engine.
|
|
395
|
+
*/
|
|
396
|
+
drm(stages) {
|
|
397
|
+
if (drmGuard().without !== void 0) return void 0;
|
|
398
|
+
const keySystems = stages().filter((stage) => KEY_SYSTEMS.includes(stage.name));
|
|
399
|
+
const license = this.getAttribute("license-url");
|
|
400
|
+
const certificate = this.getAttribute("certificate-url");
|
|
401
|
+
const page = this.options.drm;
|
|
402
|
+
if (keySystems.length === 0 && license === null && page === void 0) return void 0;
|
|
403
|
+
return {
|
|
404
|
+
keySystems,
|
|
405
|
+
...page,
|
|
406
|
+
...license === null ? {} : { licenseUrl: license },
|
|
407
|
+
...certificate === null ? {} : { certificateUrl: certificate }
|
|
408
|
+
};
|
|
368
409
|
}
|
|
369
410
|
/** What the attributes ask of the session's namespaces, once there is one. */
|
|
370
411
|
configure(session) {
|
|
@@ -373,6 +414,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
373
414
|
const optional = namespaces(engine);
|
|
374
415
|
const license = this.getAttribute("license-url");
|
|
375
416
|
if (license !== null && optional.drm !== void 0) optional.drm.setLicenseUrl(license);
|
|
417
|
+
const certificate = this.getAttribute("certificate-url");
|
|
418
|
+
if (certificate !== null) optional.drm?.setCertificateUrl(certificate);
|
|
376
419
|
const track = this.getAttribute("thumbnails");
|
|
377
420
|
if (track !== null && optional.thumbnails !== void 0) optional.thumbnails.load(track).catch(() => void 0);
|
|
378
421
|
}
|