@v360-tech/v360-player 1.7.0 → 1.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/README.md CHANGED
@@ -6,12 +6,14 @@ A lightweight, customizable HLS video player web component with built-in control
6
6
 
7
7
  - HLS (HTTP Live Streaming) video playback
8
8
  - Built-in controls with optimized icons
9
- - Responsive design with aspect ratio support
9
+ - Responsive design
10
10
  - Dynamic controls handling based on video background color (dark or light)
11
11
  - Customizable playback speeds
12
12
  - Time display options
13
13
  - Progress bar with seek functionality
14
- - Fullscreen support
14
+ - Fullscreen of the whole player, controls included, with an overlay slot for a logo
15
+ - Optional mute/volume control; muted autoplay by default
16
+ - Attributes can change at any time, for example `video-src` to switch videos
15
17
  - Optional auto-hiding controls that appear on mouse movement or tap, and stay up while paused
16
18
  - Cross-browser compatibility with native HLS fallback for Safari
17
19
 
@@ -21,7 +23,7 @@ A lightweight, customizable HLS video player web component with built-in control
21
23
 
22
24
  ```bash
23
25
  # Install the package and its peer dependencies
24
- yarn add @v360-tech/v360-player hls.js jquery
26
+ yarn add @v360-tech/v360-player hls.js
25
27
  ```
26
28
 
27
29
  ```typescript
@@ -44,9 +46,9 @@ import "@v360-tech/v360-player";
44
46
 
45
47
  ```html
46
48
  <!-- Include from CDN (all dependencies bundled) -->
47
- <script src="https://unpkg.com/@v360-tech/v360-player@1.2.1/dist/v360-player.browser.js"></script>
49
+ <script src="https://unpkg.com/@v360-tech/v360-player@1.8.0/dist/v360-player.browser.js"></script>
48
50
  <!-- OR -->
49
- <script src="https://cdn.jsdelivr.net/npm/@v360-tech/v360-player@1.2.1/dist/v360-player.browser.js"></script>
51
+ <script src="https://cdn.jsdelivr.net/npm/@v360-tech/v360-player@1.8.0/dist/v360-player.browser.js"></script>
50
52
 
51
53
  <!-- Use immediately -->
52
54
  <v360-player
@@ -71,10 +73,14 @@ import "@v360-tech/v360-player";
71
73
  show-speed-control
72
74
  playback-speeds="0.5,1,1.5,2"
73
75
  default-speed="1"
74
- progress-bar-style="DualLayer"
76
+ progress-bar-style="dual-layer"
75
77
  background="dark"
76
78
  auto-hide-controls
79
+ show-volume-control
80
+ unmuted
81
+ no-loop
77
82
  >
83
+ <img slot="overlay" src="path/to/logo.png" alt="" class="player-logo" />
78
84
  </v360-player>
79
85
  ```
80
86
 
@@ -88,26 +94,82 @@ import "@v360-tech/v360-player";
88
94
  | `auto-play` | boolean | `false` | Enable autoplay | Present to enable (no value) |
89
95
  | `show-time-display` | boolean | `false` | Show current time and duration | Present to enable (no value) |
90
96
  | `show-speed-control` | boolean | `false` | Show playback speed control | Present to enable (no value) |
97
+ | `show-volume-control` | boolean | `false` | Show mute button and volume slider | Present to enable (no value) |
98
+ | `unmuted` | boolean | `false` | Start with sound (see below) | Present to enable (no value) |
99
+ | `no-loop` | boolean | `false` | Play once instead of looping | Present to enable (no value) |
100
+ | `hide-fullscreen` | boolean | `false` | Hide the fullscreen button | Present to enable (no value) |
91
101
  | `playback-speeds` | string | `"0.25,0.5,0.75,1,1.25,1.5,2"` | Comma-separated list of speeds | Comma-separated numbers |
92
- | `default-speed` | string | `"1"` | Default playback speed | One of the values from `playback-speeds` |
102
+ | `default-speed` | string | `"1"` | Default playback speed (see below) | One of the values from `playback-speeds` |
93
103
  | `default-quality` | string | `"-1"` | Default HLS quality (-1 for auto) | `-1` or positive integer |
94
104
  | `progress-bar-style` | string | `"none"` | Progress bar style variant | `"none"`, `"dual-layer"`, `"segments"`, `"minimal-wave"` |
95
105
  | `background` | string | `dark` | Video background | `dark`, `light` |
96
106
  | `auto-hide-controls` | boolean | `false` | Auto-hide controls (see below) | Present to enable (no value) |
107
+ | `debug` | boolean | `false` | Log diagnostics (see below) | Present to enable (no value) |
97
108
 
98
109
  Boolean attributes are enabled by being present, for example `<v360-player auto-play>`. Any value, including `"false"`, still enables them; remove the attribute to disable.
99
110
 
100
- Each boolean attribute also has a JS property that adds or removes it: `autoPlay`, `showTimeDisplay`, `showSpeedControl` and `autoHideControls`, for example `player.autoHideControls = false`. In a framework, bind the property, or pass `null`/`undefined` to leave the attribute out. Binding `false` to the attribute renders `="false"`, which enables it.
111
+ Each boolean attribute also has a JS property that adds or removes it: `autoPlay`, `showTimeDisplay`, `showSpeedControl`, `showVolumeControl`, `unmuted`, `noLoop`, `hideFullscreen`, `autoHideControls` and `debug`, for example `player.autoHideControls = false`. In a framework, bind the property, or pass `null`/`undefined` to leave the attribute out. Binding `false` to the attribute renders `="false"`, which enables it.
101
112
 
102
113
  With `auto-hide-controls`, the controls are hidden until the mouse moves over the player and hide again after 3 seconds without movement or when the mouse leaves. On touch devices, a tap shows them for 3 seconds. They stay visible while the video is paused, while the mouse rests on them, and while a control has keyboard focus.
103
114
 
115
+ Invalid entries in `playback-speeds` are ignored. If `default-speed` is not one of the listed speeds, the player starts at 1x, or at the first listed speed when 1x is not listed.
116
+
117
+ ### Changing attributes
118
+
119
+ Attributes can be changed after the player is on the page; there's no need to remove and re-add it.
120
+
121
+ - `video-src` loads the new video into the same player. If a video was playing, or `auto-play` is set, the new one starts playing.
122
+ - `poster-src`, `width`, `background`, `progress-bar-style`, `unmuted`, `no-loop` and the control attributes (`show-time-display`, `show-speed-control`, `show-volume-control`, `hide-fullscreen`) apply immediately, without interrupting playback.
123
+ - `playback-speeds` and `default-speed` apply immediately and reset the speed to the default.
124
+ - `auto-play` and `default-quality` apply to the next `video-src` load.
125
+
126
+ ### Fullscreen
127
+
128
+ The fullscreen button makes the whole player fullscreen, so the controls and the overlay stay visible.
129
+
130
+ - On iPhone, which can only show the video itself fullscreen, the button opens the native iOS player; the player's own controls and overlay aren't shown there.
131
+ - The button is hidden where fullscreen isn't allowed, such as in a cross-origin iframe without `allow="fullscreen"`. Add `hide-fullscreen` to hide it everywhere.
132
+
133
+ ### Overlay
134
+
135
+ Content in the `overlay` slot is shown over the video, below the controls, and stays visible in fullscreen. Position it with your own CSS:
136
+
137
+ ```html
138
+ <v360-player video-src="video.m3u8">
139
+ <img slot="overlay" src="logo.png" alt="" class="player-logo" />
140
+ </v360-player>
141
+
142
+ <style>
143
+ .player-logo {
144
+ position: absolute;
145
+ top: 12px;
146
+ right: 12px;
147
+ width: 64px;
148
+ }
149
+ </style>
150
+ ```
151
+
152
+ Clicks pass through the overlay to the player. Give the slotted element `pointer-events: auto` to make it clickable, for example a link.
153
+
154
+ ### Sound and autoplay
155
+
156
+ The player is muted by default, because browsers block autoplay with sound.
157
+
158
+ - `unmuted` starts with sound. With `auto-play`, if the browser still blocks sound, the player plays muted instead; with `show-volume-control`, the button then shows as muted so the viewer can tap it. Without `auto-play`, the viewer's click on play allows sound.
159
+ - `show-volume-control` adds a mute/unmute button and a volume slider. iOS doesn't let pages change the volume, so there's only the button.
160
+ - `no-loop` plays the video once; by default it loops.
161
+
162
+ ### Debugging
163
+
164
+ `debug` is off by default. When on, the player logs its startup, HLS events, recovery attempts and autoplay results with `console.debug`. Without it, the player logs only one `console.error`, when playback finally fails; the player then shows "Video unavailable" over the poster.
165
+
104
166
  ## Build Types
105
167
 
106
168
  This package provides two optimized builds:
107
169
 
108
170
  1. **ES Module Build** (`v360-player.js`):
109
171
  - For use with modern bundlers (Vite, Webpack, Rollup, etc.)
110
- - External dependencies (hls.js, jquery) for better tree-shaking
172
+ - External dependency (hls.js) for better tree-shaking
111
173
  - Smaller bundle size when used with bundlers
112
174
 
113
175
  2. **Browser Build** (`v360-player.browser.js`):
@@ -286,7 +348,6 @@ The player uses:
286
348
  - Progress bar with seek functionality
287
349
  - Fullscreen mode support
288
350
  - Dynamic controls handling based on video background color (dark or light)
289
- - Dynamic aspect ratio handling
290
351
 
291
352
  ## License
292
353
 
@@ -0,0 +1,63 @@
1
+ export declare class V360Player extends HTMLElement {
2
+ private readonly autoHide;
3
+ private _video?;
4
+ private _stream?;
5
+ private _speeds;
6
+ private _speedIndex;
7
+ private _fullscreenMode;
8
+ constructor();
9
+ private static readonly booleanProperties;
10
+ get autoPlay(): boolean;
11
+ set autoPlay(value: boolean);
12
+ get showTimeDisplay(): boolean;
13
+ set showTimeDisplay(value: boolean);
14
+ get showSpeedControl(): boolean;
15
+ set showSpeedControl(value: boolean);
16
+ get showVolumeControl(): boolean;
17
+ set showVolumeControl(value: boolean);
18
+ get autoHideControls(): boolean;
19
+ set autoHideControls(value: boolean);
20
+ get hideFullscreen(): boolean;
21
+ set hideFullscreen(value: boolean);
22
+ get unmuted(): boolean;
23
+ set unmuted(value: boolean);
24
+ get noLoop(): boolean;
25
+ set noLoop(value: boolean);
26
+ get debug(): boolean;
27
+ set debug(value: boolean);
28
+ private get progressBarStyle();
29
+ private log;
30
+ private fail;
31
+ private clearError;
32
+ private upgradeProperties;
33
+ static get observedAttributes(): string[];
34
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
35
+ connectedCallback(): void;
36
+ disconnectedCallback(): void;
37
+ private render;
38
+ private loadSource;
39
+ private applyPoster;
40
+ private applyWidth;
41
+ private applyTheme;
42
+ private applyMuted;
43
+ private applySpeeds;
44
+ private setSpeed;
45
+ private renderControlBar;
46
+ private renderProgressBar;
47
+ private applyProgressStyles;
48
+ private listenToVideo;
49
+ private listenToControls;
50
+ private play;
51
+ private pause;
52
+ private step;
53
+ private seek;
54
+ private nextSpeed;
55
+ private toggleMute;
56
+ private toggleFullscreen;
57
+ private updatePlayPauseButton;
58
+ private updateProgress;
59
+ private updateDuration;
60
+ private updateSpeedButton;
61
+ private updateVolumeControl;
62
+ private syncFullscreenButton;
63
+ }
@@ -4,6 +4,9 @@ export declare const icons: {
4
4
  forward: string;
5
5
  backward: string;
6
6
  fullscreen: string;
7
+ exitFullscreen: string;
8
+ volume: string;
9
+ volumeMuted: string;
7
10
  'speed-0.50': string;
8
11
  'speed-1.00': string;
9
12
  'speed-1.50': string;
@@ -1,3 +1,3 @@
1
1
  import './style.css';
2
- import './components/V360Player';
3
- export { V360Player } from './components/V360Player';
2
+ import './components/v360-player';
3
+ export { V360Player } from './components/v360-player';
@@ -0,0 +1,17 @@
1
+ export interface AutoHideOptions {
2
+ enabled: () => boolean;
3
+ paused: () => boolean;
4
+ }
5
+ export declare class AutoHideController {
6
+ private static readonly hideDelay;
7
+ private readonly root;
8
+ private readonly options;
9
+ private timer?;
10
+ private pointerOverControls;
11
+ constructor(root: ShadowRoot, options: AutoHideOptions);
12
+ show(): void;
13
+ schedule(): void;
14
+ hide(): void;
15
+ cancel(): void;
16
+ private container;
17
+ }
@@ -0,0 +1 @@
1
+ export declare function formatTime(seconds: number): string;
@@ -0,0 +1,4 @@
1
+ export type FullscreenMode = 'element' | 'video' | 'none';
2
+ export declare function fullscreenMode(host: HTMLElement, video: HTMLVideoElement): FullscreenMode;
3
+ export declare function isFullscreen(host: HTMLElement): boolean;
4
+ export declare function toggleFullscreen(host: HTMLElement, video: HTMLVideoElement, mode: FullscreenMode): Promise<void>;
@@ -0,0 +1,4 @@
1
+ import type { Logger } from './types';
2
+ export declare const defaultSpeeds: number[];
3
+ export declare function parseSpeeds(attr: string | null, log: Logger): number[];
4
+ export declare function initialSpeedIndex(speeds: number[], defaultSpeedAttr: string | null): number;
@@ -0,0 +1,29 @@
1
+ import type { Logger } from './types';
2
+ export interface StreamOptions {
3
+ autoPlay: boolean;
4
+ startLevel: number;
5
+ }
6
+ export interface StreamCallbacks {
7
+ log: Logger;
8
+ onFail: (reason: string) => void;
9
+ }
10
+ export declare class StreamController {
11
+ private readonly video;
12
+ private readonly callbacks;
13
+ private options;
14
+ private hls?;
15
+ private loadId;
16
+ private failed;
17
+ private manifestParsed;
18
+ private networkRetried;
19
+ private mediaRecoveries;
20
+ private streamLoaded;
21
+ constructor(video: HTMLVideoElement, callbacks: StreamCallbacks);
22
+ load(src: string, options: StreamOptions): void;
23
+ unload(): void;
24
+ startLoad(): void;
25
+ destroy(): void;
26
+ autoplay(): void;
27
+ private fail;
28
+ private loadHls;
29
+ }
@@ -0,0 +1 @@
1
+ export declare const baseStyles = "\n :host {\n display: block;\n }\n .video-container {\n position: relative;\n width: 100%;\n background: var(--player-bg, #000);\n overflow: hidden;\n margin: 0 auto;\n }\n /* Always in the accessibility tree (no display: none) so the role=\"alert\" text\n set by fail() is announced. Empty and transparent until then. */\n .error-message {\n position: absolute;\n inset: 0;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 16px;\n text-align: center;\n color: #fff;\n font-family: system-ui, -apple-system, sans-serif;\n font-size: 16px;\n z-index: 2;\n pointer-events: none;\n }\n /* Holds the overlay slot (e.g. a logo) above the video and below the controls.\n Clicks pass through unless the slotted element sets pointer-events itself. */\n .overlay {\n position: absolute;\n inset: 0;\n z-index: 1;\n pointer-events: none;\n }\n /* The whole player is the fullscreen element, so the controls and overlay stay.\n The prefixed rule is separate: a selector list with an unknown pseudo-class is dropped. */\n :host(:fullscreen) .video-container {\n max-width: none !important;\n height: 100%;\n }\n :host(:-webkit-full-screen) .video-container {\n max-width: none !important;\n height: 100%;\n }\n .video-container.has-error .error-message {\n background: rgba(0, 0, 0, 0.6);\n }\n .video-container.has-error #control-bar {\n display: none;\n }\n .video-container svg {\n fill: #fff;\n }\n .video-container img {\n filter: invert(1) brightness(100);\n }\n .video-container.light-theme {\n --player-bg: #fff;\n background: var(--player-bg);\n }\n .video-container.light-theme svg {\n fill: #000;\n }\n .video-container.light-theme img {\n filter: none;\n }\n .video-container.light-theme #control-bar {\n background: linear-gradient(transparent, rgba(255, 255, 255, 0.7));\n }\n .video-container:not(.light-theme) #control-bar {\n background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));\n }\n video {\n width: 100%;\n height: 100%;\n object-fit: contain;\n }\n #control-bar {\n position: absolute;\n bottom: 0;\n left: 0;\n right: 0;\n display: flex;\n flex-direction: column;\n padding: 10px;\n background: linear-gradient(transparent, var(--control-bg));\n gap: 10px;\n z-index: 1;\n transition: opacity 0.3s ease, transform 0.3s ease;\n }\n /* opacity + pointer-events (not visibility: hidden) so the buttons stay\n keyboard-focusable and :focus-visible can reveal the bar. */\n :host([auto-hide-controls]) #control-bar {\n opacity: 0;\n pointer-events: none;\n transform: translateY(8px);\n }\n /* .controls-visible is toggled by setupAutoHide() for mouse movement and taps. */\n :host([auto-hide-controls]) .video-container.controls-visible #control-bar {\n opacity: 1;\n pointer-events: auto;\n transform: none;\n }\n /* Kept in its own rule: browsers without :has() drop the whole selector list,\n which would also disable the rule above.\n :focus-visible (not :focus-within) so a mouse click on a button doesn't pin the bar open. */\n :host([auto-hide-controls]) .video-container:has(:focus-visible) #control-bar {\n opacity: 1;\n pointer-events: auto;\n transform: none;\n }\n @media (prefers-reduced-motion: reduce) {\n #control-bar {\n transform: none !important;\n }\n }\n #progress-row {\n display: flex;\n align-items: center;\n gap: 10px;\n width: 100%;\n color: var(--control-color);\n font-size: 14px;\n }\n /* Wrapper so the progress bar can be redrawn alone; display: contents keeps\n .progress-bar a flex item of #progress-row. */\n .progress-track {\n display: contents;\n }\n #controls-row {\n display: flex;\n justify-content: space-between;\n align-items: center;\n width: 100%;\n }\n .button {\n background: transparent;\n border: none;\n cursor: pointer;\n padding: 5px;\n display: flex;\n align-items: center;\n }\n .button svg {\n width: 24px;\n height: 24px;\n display: block;\n }\n .button:hover {\n opacity: 0.8;\n }\n .time-display {\n color: #fff;\n font-size: 14px;\n font-family: system-ui, -apple-system, sans-serif;\n opacity: 0.9;\n }\n .light-theme .time-display {\n color: #000;\n }\n .video-controls {\n display: flex;\n align-items: center;\n gap: 8px;\n }\n .speed-control {\n justify-content: center;\n min-width: 34px;\n min-height: 34px;\n border-radius: 4px;\n color: #fff;\n font-size: 14px;\n font-family: system-ui, -apple-system, sans-serif;\n }\n .light-theme .speed-control {\n color: #000;\n }\n .speed-control img,\n .speed-control svg {\n width: 24px;\n height: 24px;\n display: block;\n transition: opacity 0.2s;\n }\n .speed-control:hover img,\n .speed-control:hover svg {\n opacity: 0.7;\n }\n .volume-control {\n display: flex;\n align-items: center;\n gap: 4px;\n }\n .volume-slider {\n width: 80px;\n margin: 0;\n accent-color: #0A84FF;\n cursor: pointer;\n }\n";
@@ -0,0 +1,12 @@
1
+ import { ProgressBarStyle } from '../styles/progress-bar';
2
+ export declare function progressBarTemplate(style: ProgressBarStyle): string;
3
+ export interface ControlBarOptions {
4
+ progressBarStyle: ProgressBarStyle;
5
+ showTimeDisplay: boolean;
6
+ showSpeedControl: boolean;
7
+ showVolumeControl: boolean;
8
+ showVolumeSlider: boolean;
9
+ showFullscreen: boolean;
10
+ }
11
+ export declare function controlBarTemplate(options: ControlBarOptions): string;
12
+ export declare function shellTemplate(): string;
@@ -0,0 +1 @@
1
+ export type Logger = (...args: unknown[]) => void;
@@ -0,0 +1 @@
1
+ export declare function canAdjustVolume(): boolean;