shaka-video-element 0.0.5 → 0.6.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/README.md CHANGED
@@ -1,48 +1,56 @@
1
1
  # `<shaka-video>`
2
2
 
3
- A custom element (web component) for [Shaka Player](https://github.com/shaka-project/shaka-player), which supports both HLS and DASH streaming protocols.
3
+ [![NPM Version](https://img.shields.io/npm/v/shaka-video-element?style=flat-square&color=informational)](https://www.npmjs.com/package/shaka-video-element)
4
+ [![NPM Downloads](https://img.shields.io/npm/dm/shaka-video-element?style=flat-square&color=informational&label=npm)](https://www.npmjs.com/package/shaka-video-element)
5
+ [![jsDelivr hits (npm)](https://img.shields.io/jsdelivr/npm/hm/shaka-video-element?style=flat-square&color=%23FF5627)](https://www.jsdelivr.com/package/npm/shaka-video-element)
6
+ [![npm bundle size](https://img.shields.io/bundlephobia/minzip/shaka-video-element?style=flat-square&color=success&label=gzip)](https://bundlephobia.com/result?p=shaka-video-element)
4
7
 
5
- The element API matches the HTML5 `<video>` tag, so it can be easily swapped with other media, and be compatible with other UI components that work with the video tag, including [media chrome](https://www.media-chrome.org/).
8
+ A [custom element](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_custom_elements)
9
+ for [Shaka Player](https://github.com/shaka-project/shaka-player) with an API that matches the
10
+ [`<video>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/video) API.
11
+
12
+ - 🏄‍♂️ Compatible [`HTMLMediaElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement) API
13
+ - 🕺 Seamlessly integrates with [Media Chrome](https://github.com/muxinc/media-chrome)
6
14
 
7
15
  ## Example
8
16
 
17
+ <!-- prettier-ignore -->
9
18
  ```html
10
- <html>
11
- <head>
12
- <script type="module" src="https://unpkg.com/shaka-video-element@0.5"></script>
13
- </head>
14
- <body>
15
-
16
- <shaka-video controls src="https://stream.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe.m3u8"></shaka-video>
17
-
18
- </body>
19
- </html>
19
+ <script type="module" src="https://cdn.jsdelivr.net/npm/shaka-video-element@0/+esm"></script>
20
+ <shaka-video controls src="https://stream.mux.com/r4rOE02cc95tbe3I00302nlrHfT023Q3IedFJW029w018KxZA.m3u8"></shaka-video>
20
21
  ```
21
22
 
22
- ## Installing
23
-
24
- `<shaka-video>` is packaged as a javascript module (es6) only, which is supported by all evergreen browsers and Node v12+.
23
+ ## Install
25
24
 
26
- ### Loading into your HTML using `<script>`
25
+ First install the NPM package:
27
26
 
28
- Note the `type="module"`, that's important.
27
+ ```bash
28
+ npm install shaka-video-element
29
+ ```
29
30
 
30
- > Modules are always loaded asynchronously by the browser, so it's ok to load them in the head :thumbsup:, and best for registering web components quickly.
31
+ Import in your app javascript (e.g. src/App.js):
31
32
 
32
- ```html
33
- <head>
34
- <script type="module" src="https://unpkg.com/shaka-video-element@0.5"></script>
35
- </head>
33
+ ```js
34
+ import 'shaka-video-element';
36
35
  ```
37
36
 
38
- ### Adding to your app via `npm`
37
+ Optionally, you can load the script directly from a CDN using [jsDelivr](https://www.jsdelivr.com/):
39
38
 
40
- ```bash
41
- npm install shaka-video-element --save
39
+ <!-- prettier-ignore -->
40
+ ```html
41
+ <script type="module" src="https://cdn.jsdelivr.net/npm/shaka-video-element@0/+esm"></script>
42
42
  ```
43
43
 
44
- Include in your app javascript (e.g. src/App.js)
45
- ```js
46
- import 'shaka-video-element';
47
- ```
48
44
  This will register the custom elements with the browser so they can be used as HTML.
45
+
46
+ ## Related
47
+
48
+ - [Media Chrome](https://github.com/muxinc/media-chrome) Your media player's dancing suit. 🕺
49
+ - [`<youtube-video>`](https://github.com/muxinc/media-elements/tree/main/packages/youtube-video-element) A custom element for the YouTube player.
50
+ - [`<vimeo-video>`](https://github.com/muxinc/media-elements/tree/main/packages/vimeo-video-element) A custom element for the Vimeo player.
51
+ - [`<videojs-video>`](https://github.com/muxinc/media-elements/tree/main/packages/videojs-video-element) A custom element for Video.js.
52
+ - [`<wistia-video>`](https://github.com/muxinc/media-elements/tree/main/packages/wistia-video-element) A custom element for the Wistia player.
53
+ - [`<jwplayer-video>`](https://github.com/muxinc/media-elements/tree/main/packages/jwplayer-video-element) A custom element for the JW player.
54
+ - [`castable-video`](https://github.com/muxinc/media-elements/tree/main/packages/castable-video) Cast your video element to the big screen with ease!
55
+ - [`<mux-player>`](https://github.com/muxinc/elements/tree/main/packages/mux-player) The official Mux-flavored video player custom element.
56
+ - [`<mux-video>`](https://github.com/muxinc/elements/tree/main/packages/mux-video) A Mux-flavored HTML5 video element w/ hls.js and Mux data builtin.
@@ -0,0 +1,4 @@
1
+ // This file is generated by media-elements/scripts/build-react-wrapper!
2
+ export default React.ForwardRefExoticComponent<
3
+ React.DetailedHTMLProps<React.VideoHTMLAttributes<HTMLVideoElement>, HTMLVideoElement>
4
+ >;
package/dist/react.js ADDED
@@ -0,0 +1,79 @@
1
+ // This file is generated by media-elements/scripts/build-react-wrapper!
2
+ 'use client';
3
+
4
+ import React, { useRef, useEffect } from 'react';
5
+ import Element from '../shaka-video-element.js';
6
+
7
+ export default React.forwardRef(({ children, ...props }, ref) => {
8
+ ref ??= useRef();
9
+
10
+ const attrs = propsToAttrs({ ...props, ref });
11
+
12
+ for (let name in props) {
13
+ if (name[0] === 'o' && name[1] === 'n') {
14
+ const useCapture = name.endsWith('Capture');
15
+ const eventName = name.slice(2, useCapture ? name.length - 7 : undefined);
16
+ const callback = props[name];
17
+
18
+ useEffect(() => {
19
+ const eventTarget = ref?.current;
20
+ if (!eventTarget || typeof callback !== 'function') return;
21
+
22
+ eventTarget.addEventListener(eventName, callback, useCapture);
23
+
24
+ return () => {
25
+ eventTarget.removeEventListener(eventName, callback, useCapture);
26
+ };
27
+ }, [ref?.current, callback]);
28
+ }
29
+ }
30
+
31
+ // Only render the custom element template HTML on the server..
32
+ // The custom element will render itself on the client.
33
+ if (typeof window === 'undefined' && Element?.getTemplateHTML && Element?.shadowRootOptions) {
34
+ const { mode, delegatesFocus } = Element.shadowRootOptions;
35
+
36
+ const templateShadowRoot = React.createElement('template', {
37
+ shadowrootmode: mode,
38
+ shadowrootdelegatesfocus: delegatesFocus,
39
+ dangerouslySetInnerHTML: {
40
+ __html: Element.getTemplateHTML(attrs),
41
+ },
42
+ });
43
+
44
+ children = [templateShadowRoot, children];
45
+ }
46
+
47
+ return React.createElement('shaka-video', attrs, ...[].concat(children));
48
+ });
49
+
50
+ const ReactPropToAttrNameMap = {
51
+ className: 'class',
52
+ classname: 'class',
53
+ htmlFor: 'for',
54
+ viewBox: 'viewBox',
55
+ };
56
+
57
+ function propsToAttrs(props = {}) {
58
+ let attrs = {};
59
+ for (let [propName, propValue] of Object.entries(props)) {
60
+ let attrName = toAttrName(propName, propValue);
61
+ if (attrName) attrs[attrName] = toAttrValue(propValue);
62
+ }
63
+ return attrs;
64
+ }
65
+
66
+ function toAttrName(propName, propValue) {
67
+ if (ReactPropToAttrNameMap[propName]) return ReactPropToAttrNameMap[propName];
68
+ if (typeof propValue == 'undefined') return undefined;
69
+ if (typeof propValue === 'boolean' && !propValue) return undefined;
70
+ if (/^on[A-Z]/.test(propName)) return undefined;
71
+ if (/[A-Z]/.test(propName)) return propName.toLowerCase();
72
+ return propName;
73
+ }
74
+
75
+ function toAttrValue(propValue) {
76
+ if (typeof propValue === 'boolean') return '';
77
+ if (Array.isArray(propValue)) return propValue.join(' ');
78
+ return propValue;
79
+ }