UNPKG

@vime/core

Version:

Customizable, extensible, accessible and framework agnostic media player.

240 lines (239 loc) 6.32 kB
import { Component, Event, h, Prop, State, Watch, } from '@stencil/core'; import { withComponentRegistry } from '../../core/player/withComponentRegistry'; import { withPlayerContext } from '../../core/player/withPlayerContext'; import { Provider } from '../../providers/Provider'; /** * Displays a loading indicator when the video is `buffering`. * * ## Visual * * <img * src="https://raw.githubusercontent.com/vime-js/vime/master/packages/core/src/components/ui/spinner/spinner.png" * alt="Vime spinner component" * /> */ export class Spinner { constructor() { this.blacklist = [Provider.YouTube]; this.isHidden = true; this.isActive = false; /** @internal */ this.isVideoView = false; /** * Whether the spinner should be active when the player is booting or media is loading. */ this.showWhenMediaLoading = false; /** @internal */ this.playbackReady = false; /** @internal */ this.buffering = false; withComponentRegistry(this); withPlayerContext(this, [ 'isVideoView', 'buffering', 'playbackReady', 'currentProvider', ]); } onVideoViewChange() { this.isHidden = !this.isVideoView; this.onVisiblityChange(); } onActiveChange() { this.isActive = this.buffering || (this.showWhenMediaLoading && !this.playbackReady); this.onVisiblityChange(); } onVisiblityChange() { !this.isHidden && this.isActive ? this.vmWillShow.emit() : this.vmWillHide.emit(); } render() { return (h("div", { class: { spinner: true, hidden: this.isHidden || this.blacklist.includes(this.currentProvider), active: this.isActive, } }, h("div", { class: { spin: true, active: this.isActive, } }, "Loading..."))); } static get is() { return "vm-spinner"; } static get encapsulation() { return "shadow"; } static get originalStyleUrls() { return { "$": ["spinner.css"] }; } static get styleUrls() { return { "$": ["spinner.css"] }; } static get properties() { return { "isVideoView": { "type": "boolean", "mutable": false, "complexType": { "original": "PlayerProps['isVideoView']", "resolved": "boolean", "references": { "PlayerProps": { "location": "import", "path": "../../core/player/PlayerProps" } } }, "required": false, "optional": false, "docs": { "tags": [{ "text": undefined, "name": "internal" }], "text": "" }, "attribute": "is-video-view", "reflect": false, "defaultValue": "false" }, "currentProvider": { "type": "string", "mutable": false, "complexType": { "original": "PlayerProps['currentProvider']", "resolved": "Provider.Audio | Provider.Dailymotion | Provider.Dash | Provider.HLS | Provider.Video | Provider.Vimeo | Provider.YouTube | undefined", "references": { "PlayerProps": { "location": "import", "path": "../../core/player/PlayerProps" } } }, "required": false, "optional": true, "docs": { "tags": [{ "text": undefined, "name": "internal" }], "text": "" }, "attribute": "current-provider", "reflect": false }, "showWhenMediaLoading": { "type": "boolean", "mutable": false, "complexType": { "original": "boolean", "resolved": "boolean", "references": {} }, "required": false, "optional": false, "docs": { "tags": [], "text": "Whether the spinner should be active when the player is booting or media is loading." }, "attribute": "show-when-media-loading", "reflect": false, "defaultValue": "false" }, "playbackReady": { "type": "boolean", "mutable": false, "complexType": { "original": "PlayerProps['playbackReady']", "resolved": "boolean", "references": { "PlayerProps": { "location": "import", "path": "../../core/player/PlayerProps" } } }, "required": false, "optional": false, "docs": { "tags": [{ "text": undefined, "name": "internal" }], "text": "" }, "attribute": "playback-ready", "reflect": false, "defaultValue": "false" }, "buffering": { "type": "boolean", "mutable": false, "complexType": { "original": "PlayerProps['buffering']", "resolved": "boolean", "references": { "PlayerProps": { "location": "import", "path": "../../core/player/PlayerProps" } } }, "required": false, "optional": false, "docs": { "tags": [{ "text": undefined, "name": "internal" }], "text": "" }, "attribute": "buffering", "reflect": false, "defaultValue": "false" } }; } static get states() { return { "isHidden": {}, "isActive": {} }; } static get events() { return [{ "method": "vmWillShow", "name": "vmWillShow", "bubbles": false, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "Emitted when the spinner will be shown." }, "complexType": { "original": "void", "resolved": "void", "references": {} } }, { "method": "vmWillHide", "name": "vmWillHide", "bubbles": false, "cancelable": true, "composed": true, "docs": { "tags": [], "text": "Emitted when the spinner will be hidden." }, "complexType": { "original": "void", "resolved": "void", "references": {} } }]; } static get watchers() { return [{ "propName": "isVideoView", "methodName": "onVideoViewChange" }, { "propName": "buffering", "methodName": "onActiveChange" }, { "propName": "playbackReady", "methodName": "onActiveChange" }]; } }