-
Notifications
You must be signed in to change notification settings - Fork 59
feat(skin): implement default and minimal skins for HTML player #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| .media-minimal-skin { | ||
| color: var(--media-color, red); | ||
| } | ||
|
|
||
| audio-player { | ||
| display: contents; | ||
| } | ||
|
|
||
| audio-minimal-skin { | ||
| display: contents; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { ReactiveElement } from '@videojs/element'; | ||
|
|
||
| function getTemplateHTML() { | ||
| return /*html*/ `<div></div>`; | ||
|
sampotts marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export class MinimalAudioSkinElement extends ReactiveElement { | ||
| static readonly tagName = 'audio-minimal-skin'; | ||
| static getTemplateHTML = getTemplateHTML; | ||
|
|
||
| constructor() { | ||
| super(); | ||
| const children = [...this.childNodes]; | ||
| this.innerHTML = getTemplateHTML(); | ||
| const container = this.firstElementChild; | ||
| if (container) for (const child of children) container.append(child); | ||
| } | ||
|
sampotts marked this conversation as resolved.
|
||
| } | ||
|
|
||
| customElements.define(MinimalAudioSkinElement.tagName, MinimalAudioSkinElement); | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| [MinimalAudioSkinElement.tagName]: MinimalAudioSkinElement; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| @import "@videojs/skins/audio/default.css"; | ||
|
|
||
| audio-player { | ||
| display: contents; | ||
| } | ||
|
|
||
| audio-skin { | ||
| display: contents; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,26 @@ | ||
| // TODO: Implement AudioSkinElement and then register it here | ||
| import { ReactiveElement } from '@videojs/element'; | ||
|
|
||
| function getTemplateHTML() { | ||
| return /*html*/ `<div></div>`; | ||
|
sampotts marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export class AudioSkinElement extends ReactiveElement { | ||
| static readonly tagName = 'audio-skin'; | ||
| static getTemplateHTML = getTemplateHTML; | ||
|
|
||
| constructor() { | ||
| super(); | ||
| const children = [...this.childNodes]; | ||
| this.innerHTML = getTemplateHTML(); | ||
| const container = this.firstElementChild; | ||
| if (container) for (const child of children) container.append(child); | ||
|
sampotts marked this conversation as resolved.
|
||
| } | ||
| } | ||
|
|
||
| customElements.define(AudioSkinElement.tagName, AudioSkinElement); | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| [AudioSkinElement.tagName]: AudioSkinElement; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import type { ReactiveElement } from '@videojs/element'; | ||
| import type { Constructor } from '@videojs/utils/types'; | ||
|
|
||
| /** | ||
| * Mixin for skin elements that renders the template from a static | ||
| * `getTemplateHTML` method and resolves `<slot name="media">` placeholders | ||
| * by replacing them with the actual media element children. | ||
| */ | ||
| export function SkinMixin<Base extends Constructor<ReactiveElement>>(BaseClass: Base): Base { | ||
| class SkinElement extends (BaseClass as Constructor<ReactiveElement>) { | ||
| constructor(...args: any[]) { | ||
| super(...args); | ||
|
|
||
| const ctor = this.constructor as { getTemplateHTML?: () => string }; | ||
|
|
||
| if (ctor.getTemplateHTML) { | ||
| const children = [...this.childNodes]; | ||
| this.innerHTML = ctor.getTemplateHTML(); | ||
| this.#resolveSlots(children); | ||
| } | ||
| } | ||
|
|
||
| override connectedCallback(): void { | ||
| // During innerHTML parsing, children aren't available in the constructor. | ||
| // Resolve any remaining slotted elements before the container connects. | ||
| this.#resolveSlots(); | ||
| super.connectedCallback(); | ||
| } | ||
|
|
||
| #resolveSlots(nodes?: ChildNode[]): void { | ||
| const slot = this.querySelector('slot[name="media"]'); | ||
| if (!slot) return; | ||
|
|
||
| // Collect media from either the provided node list (constructor) or | ||
| // from direct children that haven't been placed yet (connectedCallback). | ||
| const media = nodes | ||
| ? nodes.filter((n): n is HTMLElement => n instanceof HTMLElement && n.getAttribute('slot') === 'media') | ||
| : [...this.querySelectorAll<HTMLElement>(':scope > [slot="media"]')]; | ||
|
|
||
| for (const el of media) slot.before(el); | ||
| slot.remove(); | ||
| } | ||
| } | ||
|
|
||
| return SkinElement as unknown as Base; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| @import "@videojs/skins/video/minimal.css"; |
152 changes: 152 additions & 0 deletions
152
packages/html/src/define/video/minimal-skin.tailwind.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import { ReactiveElement } from '@videojs/element'; | ||
| import { renderIcon } from '@videojs/icons/render/minimal'; | ||
| import { | ||
| bufferingIndicator, | ||
| button, | ||
| buttonGroup, | ||
| controls, | ||
| error, | ||
| icon, | ||
| iconContainer, | ||
| iconFlipped, | ||
| iconState, | ||
| overlay, | ||
| popup, | ||
| root, | ||
| seek, | ||
| slider, | ||
| time, | ||
| } from '@videojs/skins/video/minimal.tailwind'; | ||
| import { cn } from '@videojs/utils/style'; | ||
| import { SkinMixin } from '../skin-mixin'; | ||
|
|
||
| // Side-effect imports: register all custom elements used in the template. | ||
| import '../media/container'; | ||
| import '../ui/buffering-indicator'; | ||
| import '../ui/controls'; | ||
| import '../ui/fullscreen-button'; | ||
| import '../ui/mute-button'; | ||
| import '../ui/pip-button'; | ||
| import '../ui/play-button'; | ||
| import '../ui/playback-rate-button'; | ||
| import '../ui/popover'; | ||
| import '../ui/seek-button'; | ||
| import '../ui/time'; | ||
| import '../ui/time-slider'; | ||
| import '../ui/volume-slider'; | ||
| import { playbackRate } from '@videojs/skins/video/default.tailwind'; | ||
|
|
||
| const SEEK_TIME = 10; | ||
|
|
||
| function getTemplateHTML() { | ||
| return /*html*/ ` | ||
| <media-container class="${root}"> | ||
| <media-buffering-indicator class="${bufferingIndicator}"> | ||
| ${renderIcon('spinner')} | ||
| </media-buffering-indicator> | ||
|
|
||
| <div class="${error.root}" role="alertdialog" aria-labelledby="media-error-title" aria-describedby="media-error-description"> | ||
| <div class="${error.dialog}"> | ||
| <div class="${error.content}"> | ||
| <p id="media-error-title" class="${error.title}">Something went wrong.</p> | ||
| <p id="media-error-description">An error occurred while trying to play the video. Please try again.</p> | ||
| </div> | ||
| <div class="${error.actions}"> | ||
| <button type="button" class="${cn(button.base, button.default)}">OK</button> | ||
| </div> | ||
| </div> | ||
| </div> | ||
|
|
||
| <media-controls data-controls="" class="${controls}"> | ||
| <span class="${buttonGroup}"> | ||
| <media-play-button class="${cn(button.base, button.icon, iconState.play.button)}"> | ||
| ${renderIcon('restart', { class: cn(icon, iconState.play.restart) })} | ||
| ${renderIcon('play', { class: cn(icon, iconState.play.play) })} | ||
| ${renderIcon('pause', { class: cn(icon, iconState.play.pause) })} | ||
| </media-play-button> | ||
|
|
||
| <media-seek-button seconds="${-SEEK_TIME}" class="${cn(button.base, button.icon, seek.button)}"> | ||
| <span class="${iconContainer}"> | ||
| ${renderIcon('seek', { class: cn(icon, iconFlipped) })} | ||
| <span class="${cn(seek.label, seek.labelBackward)}">${SEEK_TIME}</span> | ||
| </span> | ||
| </media-seek-button> | ||
|
|
||
| <media-seek-button seconds="${SEEK_TIME}" class="${cn(button.base, button.icon, seek.button)}"> | ||
| <span class="${iconContainer}"> | ||
| ${renderIcon('seek', { class: icon })} | ||
| <span class="${cn(seek.label, seek.labelForward)}">${SEEK_TIME}</span> | ||
| </span> | ||
| </media-seek-button> | ||
| </span> | ||
|
|
||
| <span class="${time.controls}"> | ||
| <media-time-group class="${time.group}"> | ||
| <media-time type="current" class="${time.current}"></media-time> | ||
| <media-time-separator class="${time.separator}"></media-time-separator> | ||
| <media-time type="duration" class="${time.duration}"></media-time> | ||
| </media-time-group> | ||
|
|
||
| <media-time-slider class="${slider.root}"> | ||
| <media-slider-track class="${slider.track}"> | ||
| <media-slider-fill class="${cn(slider.fill.base, slider.fill.fill)}"></media-slider-fill> | ||
| <media-slider-buffer class="${cn(slider.fill.base, slider.fill.buffer)}"></media-slider-buffer> | ||
| </media-slider-track> | ||
| <media-slider-thumb class="${cn(slider.thumb.base, slider.thumb.interactive)}"></media-slider-thumb> | ||
| </media-time-slider> | ||
| </span> | ||
|
|
||
| <span class="${buttonGroup}"> | ||
| <media-playback-rate-button class="${cn(button.base, button.icon, playbackRate.button)}"> | ||
| </media-playback-rate-button> | ||
|
|
||
| <media-mute-button commandfor="volume-popover" class="${cn(button.base, button.icon, iconState.mute.button)}"> | ||
| ${renderIcon('volume-off', { class: cn(icon, iconState.mute.volumeOff) })} | ||
| ${renderIcon('volume-low', { class: cn(icon, iconState.mute.volumeLow) })} | ||
| ${renderIcon('volume-high', { class: cn(icon, iconState.mute.volumeHigh) })} | ||
| </media-mute-button> | ||
|
|
||
| <media-popover id="volume-popover" open-on-hover delay="200" close-delay="100" side="top" class="${cn(popup.base, popup.volume)}"> | ||
| <media-volume-slider class="${slider.root}" orientation="vertical" thumb-alignment="edge"> | ||
| <media-slider-track class="${slider.track}"> | ||
| <media-slider-fill class="${cn(slider.fill.base, slider.fill.fill)}"></media-slider-fill> | ||
| </media-slider-track> | ||
| <media-slider-thumb class="${slider.thumb.base}"></media-slider-thumb> | ||
| </media-volume-slider> | ||
| </media-popover> | ||
|
|
||
| <!--<button type="button" class="${cn(button.base, button.icon)}" aria-label="Captions"> | ||
| ${renderIcon('captions-off', { class: icon })} | ||
| ${renderIcon('captions-on', { class: icon })} | ||
| </button>--> | ||
|
|
||
| <media-pip-button class="${cn(button.base, button.icon)}"> | ||
| ${renderIcon('pip', { class: icon })} | ||
| </media-pip-button> | ||
|
|
||
| <media-fullscreen-button class="${cn(button.base, button.icon, iconState.fullscreen.button)}"> | ||
| ${renderIcon('fullscreen-enter', { class: cn(icon, iconState.fullscreen.enter) })} | ||
| ${renderIcon('fullscreen-exit', { class: cn(icon, iconState.fullscreen.exit) })} | ||
| </media-fullscreen-button> | ||
| </span> | ||
| </media-controls> | ||
|
|
||
| <div class="${overlay}"></div> | ||
|
|
||
| <slot name="media"></slot> | ||
| </media-container> | ||
| `; | ||
| } | ||
|
|
||
| export class MinimalVideoSkinTailwindElement extends SkinMixin(ReactiveElement) { | ||
| static readonly tagName = 'video-minimal-skin-tailwind'; | ||
| static getTemplateHTML = getTemplateHTML; | ||
| } | ||
|
|
||
| customElements.define(MinimalVideoSkinTailwindElement.tagName, MinimalVideoSkinTailwindElement); | ||
|
sampotts marked this conversation as resolved.
|
||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| [MinimalVideoSkinTailwindElement.tagName]: MinimalVideoSkinTailwindElement; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.