shaka-video-element 0.0.6 → 0.6.2
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 +37 -29
- package/dist/react.d.ts +4 -0
- package/dist/react.js +85 -0
- package/dist/shaka-video-element.js +28095 -25
- package/package.json +32 -29
- package/shaka-video-element.js +87 -0
- package/LICENSE +0 -19
- package/index.html +0 -38
package/README.md
CHANGED
|
@@ -1,48 +1,56 @@
|
|
|
1
1
|
# `<shaka-video>`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/shaka-video-element)
|
|
4
|
+
[](https://www.npmjs.com/package/shaka-video-element)
|
|
5
|
+
[](https://www.jsdelivr.com/package/npm/shaka-video-element)
|
|
6
|
+
[](https://bundlephobia.com/result?p=shaka-video-element)
|
|
4
7
|
|
|
5
|
-
|
|
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
|
-
<
|
|
11
|
-
<
|
|
12
|
-
<script type="module" src="https://unpkg.com/shaka-video-element@0.6"></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
|
-
##
|
|
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
|
-
|
|
25
|
+
First install the NPM package:
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
```bash
|
|
28
|
+
npm install shaka-video-element
|
|
29
|
+
```
|
|
29
30
|
|
|
30
|
-
|
|
31
|
+
Import in your app javascript (e.g. src/App.js):
|
|
31
32
|
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
<script type="module" src="https://unpkg.com/shaka-video-element@0.6"></script>
|
|
35
|
-
</head>
|
|
33
|
+
```js
|
|
34
|
+
import 'shaka-video-element';
|
|
36
35
|
```
|
|
37
36
|
|
|
38
|
-
|
|
37
|
+
Optionally, you can load the script directly from a CDN using [jsDelivr](https://www.jsdelivr.com/):
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
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.
|
package/dist/react.d.ts
ADDED
package/dist/react.js
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
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((allProps, ref) => {
|
|
8
|
+
let { children, suppressHydrationWarning, ...props } = allProps;
|
|
9
|
+
ref ??= useRef();
|
|
10
|
+
|
|
11
|
+
for (let name in props) {
|
|
12
|
+
if (name[0] === 'o' && name[1] === 'n') {
|
|
13
|
+
const useCapture = name.endsWith('Capture');
|
|
14
|
+
const eventName = name.slice(2, useCapture ? name.length - 7 : undefined);
|
|
15
|
+
const callback = props[name];
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
const eventTarget = ref?.current;
|
|
19
|
+
if (!eventTarget || typeof callback !== 'function') return;
|
|
20
|
+
|
|
21
|
+
eventTarget.addEventListener(eventName, callback, useCapture);
|
|
22
|
+
|
|
23
|
+
return () => {
|
|
24
|
+
eventTarget.removeEventListener(eventName, callback, useCapture);
|
|
25
|
+
};
|
|
26
|
+
}, [ref?.current, callback]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const attrs = propsToAttrs(props);
|
|
31
|
+
|
|
32
|
+
// Only render the custom element template HTML on the server..
|
|
33
|
+
// The custom element will render itself on the client.
|
|
34
|
+
if (typeof window === 'undefined' && Element?.getTemplateHTML && Element?.shadowRootOptions) {
|
|
35
|
+
const { mode, delegatesFocus } = Element.shadowRootOptions;
|
|
36
|
+
|
|
37
|
+
const templateShadowRoot = React.createElement('template', {
|
|
38
|
+
shadowrootmode: mode,
|
|
39
|
+
shadowrootdelegatesfocus: delegatesFocus,
|
|
40
|
+
dangerouslySetInnerHTML: {
|
|
41
|
+
__html: Element.getTemplateHTML(attrs),
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
children = [templateShadowRoot, children];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return React.createElement('shaka-video', {
|
|
49
|
+
...attrs,
|
|
50
|
+
ref,
|
|
51
|
+
children,
|
|
52
|
+
suppressHydrationWarning,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const ReactPropToAttrNameMap = {
|
|
57
|
+
className: 'class',
|
|
58
|
+
classname: 'class',
|
|
59
|
+
htmlFor: 'for',
|
|
60
|
+
viewBox: 'viewBox',
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function propsToAttrs(props = {}) {
|
|
64
|
+
let attrs = {};
|
|
65
|
+
for (let [propName, propValue] of Object.entries(props)) {
|
|
66
|
+
let attrName = toAttrName(propName, propValue);
|
|
67
|
+
if (attrName) attrs[attrName] = toAttrValue(propValue);
|
|
68
|
+
}
|
|
69
|
+
return attrs;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function toAttrName(propName, propValue) {
|
|
73
|
+
if (ReactPropToAttrNameMap[propName]) return ReactPropToAttrNameMap[propName];
|
|
74
|
+
if (typeof propValue == 'undefined') return undefined;
|
|
75
|
+
if (typeof propValue === 'boolean' && !propValue) return undefined;
|
|
76
|
+
if (propName.startsWith('on') && typeof propValue === 'function') return undefined;
|
|
77
|
+
if (/[A-Z]/.test(propName)) return propName.toLowerCase();
|
|
78
|
+
return propName;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function toAttrValue(propValue) {
|
|
82
|
+
if (typeof propValue === 'boolean') return '';
|
|
83
|
+
if (Array.isArray(propValue)) return propValue.join(' ');
|
|
84
|
+
return propValue;
|
|
85
|
+
}
|