@mattebox/player 0.8.0 → 0.9.1
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/cues.d.ts.map +1 -1
- package/dist/controls/cues.js +11 -5
- package/dist/controls/cues.js.map +1 -1
- package/dist/controls/icons.d.ts +5 -30
- package/dist/controls/icons.d.ts.map +1 -1
- package/dist/controls/icons.js +38 -29
- package/dist/controls/icons.js.map +1 -1
- package/dist/controls/menu.d.ts +20 -0
- package/dist/controls/menu.d.ts.map +1 -1
- package/dist/controls/menu.js +83 -14
- package/dist/controls/menu.js.map +1 -1
- package/dist/element.d.ts +36 -2
- package/dist/element.d.ts.map +1 -1
- package/dist/element.js +140 -24
- package/dist/element.js.map +1 -1
- package/dist/elements/audio-menu.d.ts.map +1 -1
- package/dist/elements/audio-menu.js +3 -1
- package/dist/elements/audio-menu.js.map +1 -1
- package/dist/elements/component.d.ts.map +1 -1
- package/dist/elements/component.js +10 -0
- package/dist/elements/component.js.map +1 -1
- package/dist/elements/control-bar.d.ts +2 -0
- package/dist/elements/control-bar.d.ts.map +1 -1
- package/dist/elements/control-bar.js +23 -7
- package/dist/elements/control-bar.js.map +1 -1
- package/dist/elements/current-time.d.ts.map +1 -1
- package/dist/elements/current-time.js +1 -1
- package/dist/elements/current-time.js.map +1 -1
- package/dist/elements/drm-badge.js +1 -1
- package/dist/elements/duration.d.ts.map +1 -1
- package/dist/elements/duration.js +6 -2
- package/dist/elements/duration.js.map +1 -1
- package/dist/elements/error-screen.js +1 -1
- package/dist/elements/live-button.js +1 -1
- package/dist/elements/marker-button.d.ts +3 -3
- package/dist/elements/marker-button.d.ts.map +1 -1
- package/dist/elements/marker-button.js +18 -22
- package/dist/elements/marker-button.js.map +1 -1
- package/dist/elements/menu-element.d.ts.map +1 -1
- package/dist/elements/menu-element.js +2 -1
- package/dist/elements/menu-element.js.map +1 -1
- package/dist/elements/quality-menu.js +1 -1
- package/dist/elements/quality-menu.js.map +1 -1
- package/dist/elements/scan-button.js +1 -1
- package/dist/elements/seek-bar.d.ts.map +1 -1
- package/dist/elements/seek-bar.js +5 -4
- package/dist/elements/seek-bar.js.map +1 -1
- package/dist/elements/shared.js +3 -3
- package/dist/elements/skip-button.js +2 -2
- package/dist/elements/skip-button.js.map +1 -1
- package/dist/elements/spinner.js +1 -1
- package/dist/elements/start-button.d.ts +8 -0
- package/dist/elements/start-button.d.ts.map +1 -1
- package/dist/elements/start-button.js +18 -2
- package/dist/elements/start-button.js.map +1 -1
- package/dist/elements/subtitles-menu.d.ts +5 -1
- package/dist/elements/subtitles-menu.d.ts.map +1 -1
- package/dist/elements/subtitles-menu.js +29 -11
- package/dist/elements/subtitles-menu.js.map +1 -1
- package/dist/elements/title.d.ts.map +1 -1
- package/dist/elements/title.js +3 -1
- package/dist/elements/title.js.map +1 -1
- package/dist/elements/volume-slider.js +1 -1
- package/dist/elements/volume.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/asyncToGenerator.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/defineProperty.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/objectSpread2.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPrimitive.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/toPropertyKey.js +1 -1
- package/dist/es2015/_virtual/{_@oxc-project_runtime@0.152.0 → _@oxc-project_runtime@0.153.0}/helpers/esm/typeof.js +1 -1
- package/dist/es2015/controls/chapters.js +1 -1
- package/dist/es2015/controls/cues.js +11 -5
- package/dist/es2015/controls/icons.js +38 -29
- package/dist/es2015/controls/menu.js +89 -17
- package/dist/es2015/element.js +144 -30
- package/dist/es2015/elements/audio-menu.js +4 -1
- package/dist/es2015/elements/component.js +10 -0
- package/dist/es2015/elements/control-bar.js +23 -7
- package/dist/es2015/elements/current-time.js +1 -1
- package/dist/es2015/elements/drm-badge.js +1 -1
- package/dist/es2015/elements/duration.js +6 -2
- package/dist/es2015/elements/error-screen.js +1 -1
- package/dist/es2015/elements/live-button.js +1 -1
- package/dist/es2015/elements/marker-button.js +19 -23
- package/dist/es2015/elements/menu-element.js +2 -1
- package/dist/es2015/elements/quality-menu.js +1 -1
- package/dist/es2015/elements/scan-button.js +1 -1
- package/dist/es2015/elements/seek-bar.js +5 -4
- package/dist/es2015/elements/shared.js +3 -3
- package/dist/es2015/elements/skip-button.js +2 -2
- package/dist/es2015/elements/spinner.js +1 -1
- package/dist/es2015/elements/start-button.js +18 -2
- package/dist/es2015/elements/subtitles-menu.js +35 -17
- package/dist/es2015/elements/title.js +3 -1
- package/dist/es2015/elements/volume-slider.js +1 -1
- package/dist/es2015/elements/volume.js +1 -1
- package/dist/es2015/presets.js +1 -1
- package/dist/es2015/style.js +1 -1
- package/dist/style.js +1 -1
- package/package.json +4 -5
- package/NOTICE +0 -24
|
@@ -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, 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,OAAq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AW,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"}
|
|
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 /** The label names the group for a screen reader, and no heading is drawn. */\n readonly hideLabel?: boolean;\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 * The badges drawn as a glyph, by their text. The text stays in the\n * badge for a screen reader and as its tooltip.\n */\n readonly badgeGlyphs?: Readonly<Record<string, () => SVGSVGElement>>;\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 /** A glyph drawn before the label of the item that opens the page. */\n readonly glyph?: () => SVGSVGElement;\n /** A detail drawn at the end of that item, such as the value chosen on the page. */\n readonly detail?: string;\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 /**\n * The player, whose whole box a compact player's sheet fills from the\n * foot. The box can be taller than the picture: a video letterboxed in\n * its player leaves bars the controls sit over. The menu watches its\n * size while it is open.\n */\n readonly frame: () => Element | 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 dim over the picture behind a compact player's sheet. A press on it closes the menu. */\n readonly backdrop: 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: the title and 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 */\n/* In em of the menu's own font size. */\nconst MAX_HEIGHT = 22;\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 const backdrop = el('div', 'backdrop');\n backdrop.hidden = true;\n backdrop.addEventListener('click', () => {\n close();\n });\n\n let open = false;\n /**\n * While the menu is open it follows its player: a change of tier draws\n * the page again, as a popup or as a sheet, and a change of size places\n * it again. A page that resizes with a menu open sees it keep up.\n */\n const tiers =\n typeof MutationObserver === 'undefined'\n ? null\n : new MutationObserver(() => {\n if (!open) return;\n // The rows are drawn again, so the focus goes back to one of them.\n const held = popup.contains(focused());\n render();\n if (held) (checked() ?? items()[0])?.focus();\n });\n const sizes =\n typeof ResizeObserver === 'undefined'\n ? null\n : new ResizeObserver(() => {\n if (open) fit();\n });\n /** Whether the page drawn last was drawn for a compact player. */\n let drawnCompact = 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 compact = host.getAttribute('layout') === 'compact';\n const picture = compact\n ? (options.frame()?.getBoundingClientRect() ?? null)\n : options.picture();\n backdrop.hidden = !(open && compact && picture !== null);\n for (const node of [popup, backdrop]) {\n node.style.left = node.style.bottom = node.style.width = '';\n }\n backdrop.style.height = '';\n if (picture === null) return;\n // A compact player's menu is a sheet from the foot of the player, as wide\n // as the player and never taller, over the controls. It stays inside the\n // player: a page around a small player keeps its own space. The dim\n // covers the rest of the player.\n if (compact) {\n const box = host.getBoundingClientRect();\n for (const node of [popup, backdrop]) {\n node.style.left = `${picture.left - box.left}px`;\n node.style.bottom = `${box.bottom - picture.bottom}px`;\n node.style.width = `${picture.width}px`;\n }\n backdrop.style.height = `${picture.height}px`;\n popup.style.maxHeight = `${Math.max(0, Math.floor(picture.height - AIR))}px`;\n popup.style.maxWidth = '';\n return;\n }\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 * (Number.parseFloat(getComputedStyle(host).fontSize) || 16);\n popup.style.maxHeight = `${Math.max(0, Math.floor(Math.min(most, 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 // The first page starts with the menu's name. On a compact player the\n // menu is a sheet over the controls, so the name is the way back: a\n // press on it closes the sheet. Elsewhere it is a title, and the popup\n // already carries the name for a screen reader.\n drawnCompact = host.getAttribute('layout') === 'compact';\n if (stack.length === 1 && name !== '' && drawnCompact) {\n const leave = item('item back-item', name, () => {\n close();\n button.focus();\n });\n leave.setAttribute('role', 'menuitem');\n leave.setAttribute('aria-label', options.back(name));\n popup.append(leave);\n } else if (stack.length === 1 && name !== '') {\n const title = el('div', 'title', name);\n title.setAttribute('aria-hidden', 'true');\n popup.append(title);\n }\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 if (entry.glyph !== undefined) {\n link.prepend(entry.glyph());\n state(link, `item page-item ${entry.name}-item`, { 'glyph-item': true });\n }\n if (entry.detail !== undefined) link.append(el('span', 'item-detail', entry.detail));\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 if (entry.hideLabel !== true) {\n section.append(el('div', `section-label ${entry.name}-label`, entry.label));\n }\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 ?? []) {\n const glyph = entry.badgeGlyphs?.[badge];\n if (glyph === undefined) {\n choice.append(el('span', 'item-badge', badge));\n continue;\n }\n // The glyph is what a viewer sees, and the text is what a screen reader says.\n const drawn = el('span', 'item-badge item-glyph');\n drawn.title = badge;\n drawn.append(glyph(), el('span', 'badge-text', badge));\n choice.append(drawn);\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 tiers?.disconnect();\n sizes?.disconnect();\n popup.hidden = true;\n backdrop.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 // The tier may have changed since the page was drawn: its first row differs.\n if ((host.getAttribute('layout') === 'compact') !== drawnCompact) render();\n popup.hidden = false;\n button.setAttribute('aria-expanded', 'true');\n host.setAttribute('open', '');\n document.addEventListener('pointerdown', outside, true);\n tiers?.observe(host, { attributes: true, attributeFilter: ['layout'] });\n const frame = options.frame();\n if (frame !== null) sizes?.observe(frame);\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 backdrop,\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":";;;;;;;;;;;;;;;;;;;;;;;;;AA2FA,MAAM,MAAM;;;;;;AAQZ,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,aAAa,QAAQ,MAAM;CACjC,MAAM,SAAS;CACf,MAAM,WAAW,GAAG,OAAO,UAAU;CACrC,SAAS,SAAS;CAClB,SAAS,iBAAiB,eAAe;EACvC,MAAM;CACR,CAAC;CAED,IAAI,OAAO;;;;;;CAMX,MAAM,QACJ,OAAO,qBAAqB,cACxB,OACA,IAAI,uBAAuB;EACzB,IAAI,CAAC,MAAM;EAEX,MAAM,OAAO,MAAM,SAAS,QAAQ,CAAC;EACrC,OAAO;EACP,IAAI,MAAM,CAAC,QAAQ,KAAK,MAAM,CAAC,CAAC,GAAA,EAAK,MAAM;CAC7C,CAAC;CACP,MAAM,QACJ,OAAO,mBAAmB,cACtB,OACA,IAAI,qBAAqB;EACvB,IAAI,MAAM,IAAI;CAChB,CAAC;;CAEP,IAAI,eAAe;CACnB,IAAI,OAAO;CACX,IAAI,QAA8B,CAAC;;CAEnC,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vC,MAAM,iBAAiB,WAAW,GAAG;CAErC,OAAO;EACL;EACA;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"}
|
package/dist/element.d.ts
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
* them into runtime helpers, and the emit check bans helpers. Statics are
|
|
18
18
|
* getters and instance state is declared, then assigned in the constructor.
|
|
19
19
|
*/
|
|
20
|
-
import type { Handler, Player, PlayerError, Session } from '@mattebox/player-core';
|
|
20
|
+
import type { Handler, Player, PlayerError, Session, Source } from '@mattebox/player-core';
|
|
21
21
|
import type { KernelConfig, Mattebox, Stage } from 'mattebox';
|
|
22
22
|
import type { AttachEmeOptions } from 'mattebox/eme';
|
|
23
23
|
import type { Marker, Markers } from './controls/markers.js';
|
|
@@ -29,6 +29,8 @@ import type { PlayerHost } from './host.js';
|
|
|
29
29
|
*/
|
|
30
30
|
export interface MatteboxPlayerEventMap {
|
|
31
31
|
sourcechange: CustomEvent<Session | null>;
|
|
32
|
+
/** The size tier changed: `compact`, `regular` or `wide`. */
|
|
33
|
+
layoutchange: CustomEvent<string>;
|
|
32
34
|
error: CustomEvent<PlayerError>;
|
|
33
35
|
/** The markers changed: set by the page, or cleared by a new source. */
|
|
34
36
|
markerschange: CustomEvent<readonly Marker[]>;
|
|
@@ -88,12 +90,21 @@ export declare class MatteboxPlayerElement extends HTMLElement implements Player
|
|
|
88
90
|
private track;
|
|
89
91
|
/** The chapters URL the current session's engine was given, or null. */
|
|
90
92
|
private given;
|
|
91
|
-
|
|
93
|
+
/** The sources the page set from script, or null. */
|
|
94
|
+
private list;
|
|
95
|
+
/** The sources of the last run, as text: what tells a new `<source>` child from the ones already tried. */
|
|
96
|
+
private tried;
|
|
97
|
+
/** The options this element was constructed with, or null for the ones `define()` recorded. */
|
|
98
|
+
private readonly own;
|
|
92
99
|
private core;
|
|
93
100
|
private current;
|
|
94
101
|
private failure;
|
|
95
102
|
/** Whether an attribute change is the element's own reflection, which must not write back to the video. */
|
|
96
103
|
private reflecting;
|
|
104
|
+
/** Watches the element's box for `layout`, while connected. */
|
|
105
|
+
private sizes;
|
|
106
|
+
/** Whether the page wrote `layout`, so the element leaves it alone. */
|
|
107
|
+
private fixed;
|
|
97
108
|
/** The video has played once since its source was set: `started`, which tells a first play from a pause. */
|
|
98
109
|
private started;
|
|
99
110
|
/** The video waits for data: `waiting`, set on `waiting` and `stalled`, cleared once it can play. */
|
|
@@ -108,6 +119,13 @@ export declare class MatteboxPlayerElement extends HTMLElement implements Player
|
|
|
108
119
|
get video(): HTMLVideoElement;
|
|
109
120
|
/** The ranges the page named in this source: credits to skip, parts that must not play. */
|
|
110
121
|
get markers(): Markers;
|
|
122
|
+
/**
|
|
123
|
+
* The sources to try in order, set from script. The `src` attribute wins
|
|
124
|
+
* over them, and they win over the `<source>` children. Setting them
|
|
125
|
+
* loads, and null returns to the children.
|
|
126
|
+
*/
|
|
127
|
+
get sources(): readonly Source[] | null;
|
|
128
|
+
set sources(value: readonly Source[] | null);
|
|
111
129
|
/** The core, or null until the first source has been set up: resolving a preset is asynchronous. */
|
|
112
130
|
get player(): Player | null;
|
|
113
131
|
/** The engine feeding the video, or null for a native session and before the first load. */
|
|
@@ -120,6 +138,8 @@ export declare class MatteboxPlayerElement extends HTMLElement implements Player
|
|
|
120
138
|
*/
|
|
121
139
|
get error(): PlayerError | null;
|
|
122
140
|
connectedCallback(): void;
|
|
141
|
+
/** Sets `layout` from the element's box, unless the page fixed it. */
|
|
142
|
+
private measure;
|
|
123
143
|
/** The two states the video does not hold: whether it has played once, and whether it waits for data. */
|
|
124
144
|
private note;
|
|
125
145
|
/** The video's state on the element, for `mattebox-player[paused]` and the like. */
|
|
@@ -153,7 +173,21 @@ export declare class MatteboxPlayerElement extends HTMLElement implements Player
|
|
|
153
173
|
private emit;
|
|
154
174
|
private report;
|
|
155
175
|
private run;
|
|
176
|
+
/**
|
|
177
|
+
* What to load, ranked as a video ranks them: the `src` attribute, then
|
|
178
|
+
* the `sources` property, then the `<source>` children in their order.
|
|
179
|
+
* A child carries its own `license-url` and `certificate-url`.
|
|
180
|
+
*/
|
|
181
|
+
private wanted;
|
|
182
|
+
/** Sets a session up. It runs for every session, the one that replaces a failed source included. */
|
|
183
|
+
private adopt;
|
|
156
184
|
private ensure;
|
|
185
|
+
/**
|
|
186
|
+
* Read at each use, not once in the constructor. Importing the package
|
|
187
|
+
* registers the element, and the parser's elements are constructed then,
|
|
188
|
+
* before the page's own `define()` call can run.
|
|
189
|
+
*/
|
|
190
|
+
private get options();
|
|
157
191
|
private chain;
|
|
158
192
|
/**
|
|
159
193
|
* The DRM a native session attaches: the page's `drm` option, the
|
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,
|
|
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,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAQ3F,OAAO,K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;IAoCd,oGAAoG;IACpG,OAAO,CAAC,KAAK;YAYC,MAAM;IAmBpB;;;;OAIG;IACH,OAAO,KAAK,OAAO,GAElB;YAEa,KAAK;IAiCnB;;;;OAIG;IACH,OAAO,CAAC,GAAG;IAeX,8EAA8E;IAC9E,OAAO,CAAC,SAAS;IA6BjB,OAAO,CAAC,OAAO;YAID,QAAQ;IAKtB,mFAAmF;YACrE,OAAO;CAMtB"}
|
package/dist/element.js
CHANGED
|
@@ -19,13 +19,15 @@ const FORWARDED = [
|
|
|
19
19
|
"poster",
|
|
20
20
|
"crossorigin"
|
|
21
21
|
];
|
|
22
|
+
const LICENSE_URL = "license-url";
|
|
23
|
+
const CERTIFICATE_URL = "certificate-url";
|
|
22
24
|
/** Everything else the element watches. Changing any of them reloads. */
|
|
23
25
|
const OWN = [
|
|
24
26
|
"src",
|
|
25
27
|
"type",
|
|
26
28
|
"preset",
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
LICENSE_URL,
|
|
30
|
+
CERTIFICATE_URL,
|
|
29
31
|
"thumbnails",
|
|
30
32
|
NATIVE_HLS
|
|
31
33
|
];
|
|
@@ -53,6 +55,27 @@ const CONTROLS = "controls";
|
|
|
53
55
|
* control the page placed shows. Changing it never reloads.
|
|
54
56
|
*/
|
|
55
57
|
const PLAYSINLINE = "playsinline";
|
|
58
|
+
/**
|
|
59
|
+
* The size tier the controls draw for: `compact` on a small player, such
|
|
60
|
+
* as a phone held upright, `wide` on a large one, such as a TV or
|
|
61
|
+
* fullscreen, and `regular` between. The element measures itself and sets
|
|
62
|
+
* the attribute, so a stylesheet matches `mattebox-player[layout="compact"]`.
|
|
63
|
+
* A page that writes one of the three values fixes it, and removing the
|
|
64
|
+
* attribute hands it back. The player's own box decides, not the screen:
|
|
65
|
+
* a small embed on a desktop is compact, and a phone in fullscreen is not.
|
|
66
|
+
*/
|
|
67
|
+
const LAYOUT = "layout";
|
|
68
|
+
const LAYOUTS = [
|
|
69
|
+
"compact",
|
|
70
|
+
"regular",
|
|
71
|
+
"wide"
|
|
72
|
+
];
|
|
73
|
+
/** Under either, the player is compact. */
|
|
74
|
+
const COMPACT_WIDTH = 480;
|
|
75
|
+
const COMPACT_HEIGHT = 320;
|
|
76
|
+
/** From both, the player is wide. */
|
|
77
|
+
const WIDE_WIDTH = 1280;
|
|
78
|
+
const WIDE_HEIGHT = 700;
|
|
56
79
|
/** The video's state, as attributes on the element, read on the events the video fires for it. */
|
|
57
80
|
const STATE_EVENTS = [
|
|
58
81
|
"play",
|
|
@@ -91,7 +114,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
91
114
|
...OWN,
|
|
92
115
|
CONTROLS,
|
|
93
116
|
CHAPTERS,
|
|
94
|
-
PLAYSINLINE
|
|
117
|
+
PLAYSINLINE,
|
|
118
|
+
LAYOUT
|
|
95
119
|
];
|
|
96
120
|
}
|
|
97
121
|
/**
|
|
@@ -106,14 +130,18 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
106
130
|
}
|
|
107
131
|
constructor(options) {
|
|
108
132
|
super();
|
|
109
|
-
this.
|
|
133
|
+
this.own = options ?? null;
|
|
110
134
|
this.focusable = false;
|
|
111
135
|
this.track = null;
|
|
112
136
|
this.given = null;
|
|
137
|
+
this.list = null;
|
|
138
|
+
this.tried = "";
|
|
113
139
|
this.core = null;
|
|
114
140
|
this.current = null;
|
|
115
141
|
this.failure = null;
|
|
116
142
|
this.reflecting = false;
|
|
143
|
+
this.sizes = null;
|
|
144
|
+
this.fixed = false;
|
|
117
145
|
this.started = false;
|
|
118
146
|
this.waiting = false;
|
|
119
147
|
this.offs = [];
|
|
@@ -132,7 +160,11 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
132
160
|
this.marks = createMarkers(this.media, (name, detail) => this.emit(name, detail));
|
|
133
161
|
this.stage = document.createElement("div");
|
|
134
162
|
this.stage.setAttribute("part", "stage");
|
|
135
|
-
|
|
163
|
+
const slot = document.createElement("slot");
|
|
164
|
+
slot.addEventListener("slotchange", () => {
|
|
165
|
+
if (this.current === null && JSON.stringify(this.wanted()) !== this.tried) this.reload();
|
|
166
|
+
});
|
|
167
|
+
this.stage.append(slot);
|
|
136
168
|
this.surface = errorSurface(() => {
|
|
137
169
|
this.reload();
|
|
138
170
|
});
|
|
@@ -149,6 +181,19 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
149
181
|
get markers() {
|
|
150
182
|
return this.marks;
|
|
151
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* The sources to try in order, set from script. The `src` attribute wins
|
|
186
|
+
* over them, and they win over the `<source>` children. Setting them
|
|
187
|
+
* loads, and null returns to the children.
|
|
188
|
+
*/
|
|
189
|
+
get sources() {
|
|
190
|
+
return this.list;
|
|
191
|
+
}
|
|
192
|
+
set sources(value) {
|
|
193
|
+
this.list = value;
|
|
194
|
+
if (this.marks.list.length > 0) this.marks.set([]);
|
|
195
|
+
this.reload();
|
|
196
|
+
}
|
|
152
197
|
/** The core, or null until the first source has been set up: resolving a preset is asynchronous. */
|
|
153
198
|
get player() {
|
|
154
199
|
return this.core;
|
|
@@ -170,8 +215,28 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
170
215
|
if (this.media.parentNode !== this) this.append(this.media);
|
|
171
216
|
for (const name of FORWARDED) this.forward(name);
|
|
172
217
|
this.reflect();
|
|
218
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
219
|
+
this.sizes = new ResizeObserver(() => {
|
|
220
|
+
this.measure();
|
|
221
|
+
});
|
|
222
|
+
this.sizes.observe(this);
|
|
223
|
+
}
|
|
224
|
+
this.measure();
|
|
173
225
|
this.reload();
|
|
174
226
|
}
|
|
227
|
+
/** Sets `layout` from the element's box, unless the page fixed it. */
|
|
228
|
+
measure() {
|
|
229
|
+
if (this.fixed) return;
|
|
230
|
+
const width = this.clientWidth;
|
|
231
|
+
const height = this.clientHeight;
|
|
232
|
+
if (width === 0 || height === 0) return;
|
|
233
|
+
const layout = width < COMPACT_WIDTH || height < COMPACT_HEIGHT ? "compact" : width >= WIDE_WIDTH && height >= WIDE_HEIGHT ? "wide" : "regular";
|
|
234
|
+
if (this.getAttribute(LAYOUT) === layout) return;
|
|
235
|
+
this.reflecting = true;
|
|
236
|
+
this.setAttribute(LAYOUT, layout);
|
|
237
|
+
this.reflecting = false;
|
|
238
|
+
this.emit("layoutchange", layout);
|
|
239
|
+
}
|
|
175
240
|
/** The two states the video does not hold: whether it has played once, and whether it waits for data. */
|
|
176
241
|
note(event) {
|
|
177
242
|
if (event === "playing") {
|
|
@@ -211,6 +276,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
211
276
|
return (this.getAttribute("type") ?? (src === null ? void 0 : inferType(src)))?.startsWith("audio/") === true;
|
|
212
277
|
}
|
|
213
278
|
disconnectedCallback() {
|
|
279
|
+
this.sizes?.disconnect();
|
|
280
|
+
this.sizes = null;
|
|
214
281
|
this.enqueue(() => this.teardown());
|
|
215
282
|
}
|
|
216
283
|
attributeChangedCallback(name) {
|
|
@@ -226,6 +293,14 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
226
293
|
this.chapters();
|
|
227
294
|
return;
|
|
228
295
|
}
|
|
296
|
+
if (name === LAYOUT) {
|
|
297
|
+
if (this.reflecting) return;
|
|
298
|
+
const value = this.getAttribute(LAYOUT);
|
|
299
|
+
this.fixed = value !== null && LAYOUTS.includes(value);
|
|
300
|
+
if (this.fixed) this.emit("layoutchange", value);
|
|
301
|
+
else this.measure();
|
|
302
|
+
return;
|
|
303
|
+
}
|
|
229
304
|
if (name === PLAYSINLINE) {
|
|
230
305
|
this.media.toggleAttribute(PLAYSINLINE, this.getAttribute(PLAYSINLINE) !== "false");
|
|
231
306
|
return;
|
|
@@ -321,27 +396,58 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
321
396
|
async run() {
|
|
322
397
|
this.unmount();
|
|
323
398
|
if (!this.isConnected) return;
|
|
324
|
-
const
|
|
325
|
-
|
|
399
|
+
const sources = this.wanted();
|
|
400
|
+
this.tried = JSON.stringify(sources);
|
|
401
|
+
if (sources.length === 0) return;
|
|
326
402
|
const core = await this.ensure();
|
|
327
|
-
const type = this.getAttribute("type");
|
|
328
|
-
const source = type === null ? { url } : {
|
|
329
|
-
url,
|
|
330
|
-
type
|
|
331
|
-
};
|
|
332
403
|
this.failure = null;
|
|
333
404
|
this.surface.clear();
|
|
334
|
-
let session;
|
|
335
405
|
try {
|
|
336
|
-
|
|
406
|
+
await core.load(sources);
|
|
337
407
|
} catch {
|
|
338
408
|
return;
|
|
339
409
|
}
|
|
340
|
-
if (!this.isConnected)
|
|
341
|
-
|
|
342
|
-
|
|
410
|
+
if (!this.isConnected) await core.unload();
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* What to load, ranked as a video ranks them: the `src` attribute, then
|
|
414
|
+
* the `sources` property, then the `<source>` children in their order.
|
|
415
|
+
* A child carries its own `license-url` and `certificate-url`.
|
|
416
|
+
*/
|
|
417
|
+
wanted() {
|
|
418
|
+
const url = this.getAttribute("src");
|
|
419
|
+
if (url !== null) {
|
|
420
|
+
const type = this.getAttribute("type");
|
|
421
|
+
return [type === null ? { url } : {
|
|
422
|
+
url,
|
|
423
|
+
type
|
|
424
|
+
}];
|
|
343
425
|
}
|
|
344
|
-
|
|
426
|
+
const eme = drmGuard().without === void 0;
|
|
427
|
+
if (this.list !== null) return eme ? this.list : this.list.map(({ url, type }) => type === void 0 ? { url } : {
|
|
428
|
+
url,
|
|
429
|
+
type
|
|
430
|
+
});
|
|
431
|
+
const found = [];
|
|
432
|
+
for (const child of Array.from(this.children)) {
|
|
433
|
+
const src = child.localName === "source" ? child.getAttribute("src") : null;
|
|
434
|
+
if (src === null) continue;
|
|
435
|
+
const type = child.getAttribute("type");
|
|
436
|
+
const license = child.getAttribute(LICENSE_URL);
|
|
437
|
+
const certificate = child.getAttribute(CERTIFICATE_URL);
|
|
438
|
+
found.push({
|
|
439
|
+
url: src,
|
|
440
|
+
...type === null ? {} : { type },
|
|
441
|
+
...!eme || license === null && certificate === null ? {} : { drm: {
|
|
442
|
+
...license === null ? {} : { licenseUrl: license },
|
|
443
|
+
...certificate === null ? {} : { certificateUrl: certificate }
|
|
444
|
+
} }
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
return found;
|
|
448
|
+
}
|
|
449
|
+
/** Sets a session up. It runs for every session, the one that replaces a failed source included. */
|
|
450
|
+
adopt(session) {
|
|
345
451
|
this.given = null;
|
|
346
452
|
this.configure(session);
|
|
347
453
|
this.chapters();
|
|
@@ -351,6 +457,7 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
351
457
|
const core = createPlayer(this.media, { handlers: await this.chain() });
|
|
352
458
|
this.offs.push(core.on("sourcechange", (session) => {
|
|
353
459
|
this.current = session;
|
|
460
|
+
if (session !== null && this.isConnected) this.adopt(session);
|
|
354
461
|
this.emit("sourcechange", session);
|
|
355
462
|
}), core.on("error", (error) => {
|
|
356
463
|
this.report(error);
|
|
@@ -358,6 +465,14 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
358
465
|
this.core = core;
|
|
359
466
|
return core;
|
|
360
467
|
}
|
|
468
|
+
/**
|
|
469
|
+
* Read at each use, not once in the constructor. Importing the package
|
|
470
|
+
* registers the element, and the parser's elements are constructed then,
|
|
471
|
+
* before the page's own `define()` call can run.
|
|
472
|
+
*/
|
|
473
|
+
get options() {
|
|
474
|
+
return this.own ?? defaults;
|
|
475
|
+
}
|
|
361
476
|
async chain() {
|
|
362
477
|
if (this.options.handlers !== void 0) return this.options.handlers;
|
|
363
478
|
const config = this.options.config === void 0 ? {} : { config: this.options.config };
|
|
@@ -396,8 +511,8 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
396
511
|
drm(stages) {
|
|
397
512
|
if (drmGuard().without !== void 0) return void 0;
|
|
398
513
|
const keySystems = stages().filter((stage) => KEY_SYSTEMS.includes(stage.name));
|
|
399
|
-
const license = this.getAttribute(
|
|
400
|
-
const certificate = this.getAttribute(
|
|
514
|
+
const license = this.getAttribute(LICENSE_URL);
|
|
515
|
+
const certificate = this.getAttribute(CERTIFICATE_URL);
|
|
401
516
|
const page = this.options.drm;
|
|
402
517
|
if (keySystems.length === 0 && license === null && page === void 0) return void 0;
|
|
403
518
|
return {
|
|
@@ -412,10 +527,11 @@ var MatteboxPlayerElement = class MatteboxPlayerElement extends HTMLElement {
|
|
|
412
527
|
const engine = session.engine;
|
|
413
528
|
if (engine === null) return;
|
|
414
529
|
const optional = namespaces(engine);
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
530
|
+
const own = session.source.drm;
|
|
531
|
+
const license = this.getAttribute(LICENSE_URL);
|
|
532
|
+
if (license !== null && own?.licenseUrl === void 0) optional.drm?.setLicenseUrl(license);
|
|
533
|
+
const certificate = this.getAttribute(CERTIFICATE_URL);
|
|
534
|
+
if (certificate !== null && own?.certificateUrl === void 0) optional.drm?.setCertificateUrl(certificate);
|
|
419
535
|
const track = this.getAttribute("thumbnails");
|
|
420
536
|
if (track !== null && optional.thumbnails !== void 0) optional.thumbnails.load(track).catch(() => void 0);
|
|
421
537
|
}
|