shaka-video-element 0.6.10 → 0.6.11

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.
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,189 @@
1
+ "use client";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // dist/react.ts
31
+ var react_exports = {};
32
+ __export(react_exports, {
33
+ default: () => react_default
34
+ });
35
+ module.exports = __toCommonJS(react_exports);
36
+ var import_react = __toESM(require("react"), 1);
37
+ var import_shaka_video_element = __toESM(require("./shaka-video-element.js"), 1);
38
+
39
+ // ../../node_modules/ce-la-react/dist/ce-la-react.js
40
+ var reservedReactProps = /* @__PURE__ */ new Set([
41
+ "style",
42
+ "children",
43
+ "ref",
44
+ "key",
45
+ "suppressContentEditableWarning",
46
+ "suppressHydrationWarning",
47
+ "dangerouslySetInnerHTML"
48
+ ]);
49
+ var reactPropToAttrNameMap = {
50
+ className: "class",
51
+ htmlFor: "for"
52
+ };
53
+ function defaultToAttributeName(propName) {
54
+ return propName.toLowerCase();
55
+ }
56
+ function defaultToAttributeValue(propValue) {
57
+ if (typeof propValue === "boolean") return propValue ? "" : void 0;
58
+ if (typeof propValue === "function") return void 0;
59
+ if (typeof propValue === "object" && propValue !== null) return void 0;
60
+ return propValue;
61
+ }
62
+ function createComponent({
63
+ react: React2,
64
+ tagName,
65
+ elementClass,
66
+ events,
67
+ displayName,
68
+ toAttributeName = defaultToAttributeName,
69
+ toAttributeValue = defaultToAttributeValue
70
+ }) {
71
+ const IS_REACT_19_OR_NEWER = Number.parseInt(React2.version) >= 19;
72
+ const ReactComponent = React2.forwardRef((props, ref) => {
73
+ var _a, _b;
74
+ const elementRef = React2.useRef(null);
75
+ const prevElemPropsRef = React2.useRef(/* @__PURE__ */ new Map());
76
+ const eventProps = {};
77
+ const attrs = {};
78
+ const reactProps = {};
79
+ const elementProps = {};
80
+ for (const [k, v] of Object.entries(props)) {
81
+ if (reservedReactProps.has(k)) {
82
+ reactProps[k] = v;
83
+ continue;
84
+ }
85
+ const attrName = toAttributeName(reactPropToAttrNameMap[k] ?? k);
86
+ if (k in elementClass.prototype && !(k in (((_a = globalThis.HTMLElement) == null ? void 0 : _a.prototype) ?? {})) && !((_b = elementClass.observedAttributes) == null ? void 0 : _b.some((attr) => attr === attrName))) {
87
+ elementProps[k] = v;
88
+ continue;
89
+ }
90
+ if (k.startsWith("on")) {
91
+ eventProps[k] = v;
92
+ continue;
93
+ }
94
+ const attrValue = toAttributeValue(v);
95
+ if (attrName && attrValue != null) {
96
+ attrs[attrName] = String(attrValue);
97
+ if (!IS_REACT_19_OR_NEWER) {
98
+ reactProps[attrName] = attrValue;
99
+ }
100
+ }
101
+ if (attrName && IS_REACT_19_OR_NEWER) {
102
+ reactProps[attrName] = v;
103
+ }
104
+ }
105
+ if (typeof window !== "undefined") {
106
+ for (const propName in eventProps) {
107
+ const callback = eventProps[propName];
108
+ const useCapture = propName.endsWith("Capture");
109
+ const eventName = ((events == null ? void 0 : events[propName]) ?? propName.slice(2).toLowerCase()).slice(
110
+ 0,
111
+ useCapture ? -7 : void 0
112
+ );
113
+ React2.useLayoutEffect(() => {
114
+ const eventTarget = elementRef == null ? void 0 : elementRef.current;
115
+ if (!eventTarget || typeof callback !== "function") return;
116
+ eventTarget.addEventListener(eventName, callback, useCapture);
117
+ return () => {
118
+ eventTarget.removeEventListener(eventName, callback, useCapture);
119
+ };
120
+ }, [elementRef == null ? void 0 : elementRef.current, callback]);
121
+ }
122
+ React2.useLayoutEffect(() => {
123
+ if (elementRef.current === null) return;
124
+ const newElemProps = /* @__PURE__ */ new Map();
125
+ for (const key in elementProps) {
126
+ setProperty(elementRef.current, key, elementProps[key]);
127
+ prevElemPropsRef.current.delete(key);
128
+ newElemProps.set(key, elementProps[key]);
129
+ }
130
+ for (const [key, _value] of prevElemPropsRef.current) {
131
+ setProperty(elementRef.current, key, void 0);
132
+ }
133
+ prevElemPropsRef.current = newElemProps;
134
+ });
135
+ }
136
+ if (typeof window === "undefined" && (elementClass == null ? void 0 : elementClass.getTemplateHTML) && (elementClass == null ? void 0 : elementClass.shadowRootOptions)) {
137
+ const { mode, delegatesFocus } = elementClass.shadowRootOptions;
138
+ const templateShadowRoot = React2.createElement("template", {
139
+ shadowrootmode: mode,
140
+ shadowrootdelegatesfocus: delegatesFocus,
141
+ dangerouslySetInnerHTML: {
142
+ __html: elementClass.getTemplateHTML(attrs)
143
+ }
144
+ });
145
+ reactProps.children = [templateShadowRoot, reactProps.children];
146
+ }
147
+ return React2.createElement(tagName, {
148
+ ...reactProps,
149
+ ref: React2.useCallback(
150
+ (node) => {
151
+ elementRef.current = node;
152
+ if (typeof ref === "function") {
153
+ ref(node);
154
+ } else if (ref !== null) {
155
+ ref.current = node;
156
+ }
157
+ },
158
+ [ref]
159
+ )
160
+ });
161
+ });
162
+ ReactComponent.displayName = displayName ?? elementClass.name;
163
+ return ReactComponent;
164
+ }
165
+ function setProperty(node, name, value) {
166
+ var _a;
167
+ node[name] = value;
168
+ if (value == null && name in (((_a = globalThis.HTMLElement) == null ? void 0 : _a.prototype) ?? {})) {
169
+ node.removeAttribute(name);
170
+ }
171
+ }
172
+
173
+ // dist/react.ts
174
+ var react_default = createComponent({
175
+ react: import_react.default,
176
+ tagName: "shaka-video",
177
+ elementClass: import_shaka_video_element.default
178
+ });
179
+ /*! Bundled license information:
180
+
181
+ ce-la-react/dist/ce-la-react.js:
182
+ (**
183
+ * @license
184
+ * Copyright 2018 Google LLC
185
+ * SPDX-License-Identifier: BSD-3-Clause
186
+ *
187
+ * Modified version of `@lit/react` for vanilla custom elements with support for SSR.
188
+ *)
189
+ */
@@ -0,0 +1,90 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var shaka_video_element_exports = {};
29
+ __export(shaka_video_element_exports, {
30
+ default: () => shaka_video_element_default
31
+ });
32
+ module.exports = __toCommonJS(shaka_video_element_exports);
33
+ var import_custom_media_element = require("custom-media-element");
34
+ var import_shaka_player = __toESM(require("shaka-player"), 1);
35
+ function onErrorEvent(event) {
36
+ onError(event.detail);
37
+ }
38
+ function onError(error) {
39
+ console.error("Error code", error.code, "object", error);
40
+ }
41
+ class ShakaVideoElement extends import_custom_media_element.CustomVideoElement {
42
+ static shadowRootOptions = { ...import_custom_media_element.CustomVideoElement.shadowRootOptions };
43
+ static getTemplateHTML = (attrs) => {
44
+ const { src, ...rest } = attrs;
45
+ return import_custom_media_element.CustomVideoElement.getTemplateHTML(rest);
46
+ };
47
+ constructor() {
48
+ super();
49
+ if (import_shaka_player.default.Player.isBrowserSupported()) {
50
+ this.api = new import_shaka_player.default.Player();
51
+ this.api.addEventListener("error", onErrorEvent);
52
+ } else {
53
+ console.error("Browser does not support Shaka Player");
54
+ }
55
+ }
56
+ attributeChangedCallback(attrName, oldValue, newValue) {
57
+ if (attrName !== "src") {
58
+ super.attributeChangedCallback(attrName, oldValue, newValue);
59
+ }
60
+ if (attrName === "src" && oldValue != newValue) {
61
+ this.load();
62
+ }
63
+ }
64
+ get src() {
65
+ return this.getAttribute("src");
66
+ }
67
+ set src(val) {
68
+ if (val !== this.src) {
69
+ this.setAttribute("src", val);
70
+ }
71
+ }
72
+ async load() {
73
+ if (!this.api) return;
74
+ await Promise.resolve();
75
+ await this.api.attach(this.nativeEl);
76
+ if (!this.src) {
77
+ this.api.unload();
78
+ } else {
79
+ try {
80
+ await this.api.load(this.src);
81
+ } catch (e) {
82
+ onError(e);
83
+ }
84
+ }
85
+ }
86
+ }
87
+ if (globalThis.customElements && !globalThis.customElements.get("shaka-video")) {
88
+ globalThis.customElements.define("shaka-video", ShakaVideoElement);
89
+ }
90
+ var shaka_video_element_default = ShakaVideoElement;
package/dist/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import CustomMediaElement from '../shaka-video-element.js';
2
+ import CustomMediaElement from './shaka-video-element.js';
3
3
 
4
4
  declare const _default: React.ForwardRefExoticComponent<Omit<React.HTMLAttributes<CustomMediaElement>, "disablePictureInPicture" | "height" | "onenterpictureinpicture" | "onleavepictureinpicture" | "playsInline" | "poster" | "videoHeight" | "videoWidth" | "width" | "cancelVideoFrameCallback" | "getVideoPlaybackQuality" | "requestPictureInPicture" | "requestVideoFrameCallback" | "autoplay" | "buffered" | "controls" | "crossOrigin" | "currentSrc" | "currentTime" | "defaultMuted" | "defaultPlaybackRate" | "disableRemotePlayback" | "duration" | "ended" | "error" | "loop" | "mediaKeys" | "muted" | "networkState" | "onencrypted" | "onwaitingforkey" | "paused" | "playbackRate" | "played" | "preload" | "preservesPitch" | "readyState" | "remote" | "seekable" | "seeking" | "sinkId" | "src" | "srcObject" | "textTracks" | "volume" | "addTextTrack" | "canPlayType" | "fastSeek" | "load" | "pause" | "play" | "setMediaKeys" | "setSinkId" | "NETWORK_EMPTY" | "NETWORK_IDLE" | "NETWORK_LOADING" | "NETWORK_NO_SOURCE" | "HAVE_NOTHING" | "HAVE_METADATA" | "HAVE_CURRENT_DATA" | "HAVE_FUTURE_DATA" | "HAVE_ENOUGH_DATA"> & {} & Partial<Omit<CustomMediaElement, keyof HTMLElement | "connectedCallback" | "disconnectedCallback" | "attributeChangedCallback" | "adoptedCallback">> & React.RefAttributes<CustomMediaElement>>;
5
5
 
package/dist/react.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  // dist/react.ts
4
4
  import React from "react";
5
- import CustomMediaElement from "../shaka-video-element.js";
5
+ import CustomMediaElement from "./shaka-video-element.js";
6
6
 
7
7
  // ../../node_modules/ce-la-react/dist/ce-la-react.js
8
8
  var reservedReactProps = /* @__PURE__ */ new Set([
@@ -0,0 +1,12 @@
1
+ declare class CustomVideoElement extends HTMLVideoElement {
2
+ static readonly observedAttributes: string[];
3
+ attributeChangedCallback(
4
+ attrName: string,
5
+ oldValue?: string | null,
6
+ newValue?: string | null
7
+ ): void;
8
+ connectedCallback(): void;
9
+ disconnectedCallback(): void;
10
+ }
11
+
12
+ export { CustomVideoElement as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shaka-video-element",
3
- "version": "0.6.10",
3
+ "version": "0.6.11",
4
4
  "description": "Custom element (web component) for Shaka Player",
5
5
  "author": "@muxinc",
6
6
  "license": "MIT",
@@ -18,11 +18,31 @@
18
18
  "dist"
19
19
  ],
20
20
  "type": "module",
21
- "main": "shaka-video-element.js",
22
- "types": "shaka-video-element.d.ts",
21
+ "types": "./dist/shaka-video-element.d.ts",
22
+ "main": "./dist/shaka-video-element.js",
23
23
  "exports": {
24
- ".": "./shaka-video-element.js",
25
- "./react": "./dist/react.js"
24
+ ".": {
25
+ "types": "./dist/shaka-video-element.d.ts",
26
+ "import": "./dist/shaka-video-element.js",
27
+ "require": "./dist/cjs/shaka-video-element.js",
28
+ "default": "./dist/shaka-video-element.js"
29
+ },
30
+ "./react": {
31
+ "types": "./dist/react.d.ts",
32
+ "import": "./dist/react.js",
33
+ "require": "./dist/cjs/react.js",
34
+ "default": "./dist/react.js"
35
+ }
36
+ },
37
+ "typesVersions": {
38
+ "*": {
39
+ "react": [
40
+ "./dist/react.d.ts"
41
+ ],
42
+ "*": [
43
+ "./dist/shaka-video-element.d.ts"
44
+ ]
45
+ }
26
46
  },
27
47
  "scripts": {
28
48
  "lint": "eslint *.js",
@@ -36,7 +56,7 @@
36
56
  "shaka-player": "~4.8.4"
37
57
  },
38
58
  "devDependencies": {
39
- "build-react-wrapper": "^0.1.7",
59
+ "build-react-wrapper": "^0.1.8",
40
60
  "npm-run-all": "^4.1.5",
41
61
  "wet-run": "^1.2.5"
42
62
  },
@@ -1,87 +0,0 @@
1
- import { CustomVideoElement } from 'custom-media-element';
2
- import shaka from 'shaka-player';
3
-
4
- function onErrorEvent(event) {
5
- // Extract the shaka.util.Error object from the event.
6
- onError(event.detail);
7
- }
8
-
9
- function onError(error) {
10
- // Log the error.
11
- console.error('Error code', error.code, 'object', error);
12
- }
13
-
14
- class ShakaVideoElement extends CustomVideoElement {
15
- static shadowRootOptions = { ...CustomVideoElement.shadowRootOptions };
16
-
17
- static getTemplateHTML = (attrs) => {
18
- const { src, ...rest } = attrs; // eslint-disable-line no-unused-vars
19
- return CustomVideoElement.getTemplateHTML(rest);
20
- };
21
-
22
- constructor() {
23
- super();
24
-
25
- if (shaka.Player.isBrowserSupported()) {
26
- this.api = new shaka.Player();
27
- // Listen for error events.
28
- this.api.addEventListener('error', onErrorEvent);
29
- } else {
30
- // This browser does not have the minimum set of APIs we need.
31
- console.error('Browser does not support Shaka Player');
32
- }
33
- }
34
-
35
- attributeChangedCallback(attrName, oldValue, newValue) {
36
- if (attrName !== 'src') {
37
- super.attributeChangedCallback(attrName, oldValue, newValue);
38
- }
39
-
40
- if (attrName === 'src' && oldValue != newValue) {
41
- this.load();
42
- }
43
- }
44
-
45
- get src() {
46
- // Use the attribute value as the source of truth.
47
- // No need to store it in two places.
48
- // This avoids needing a to read the attribute initially and update the src.
49
- return this.getAttribute('src');
50
- }
51
-
52
- set src(val) {
53
- // If being set by attributeChangedCallback,
54
- // dont' cause an infinite loop
55
- if (val !== this.src) {
56
- this.setAttribute('src', val);
57
- }
58
- }
59
-
60
- async load() {
61
- if (!this.api) return;
62
-
63
- // Wait 1 tick to allow other attributes to be set.
64
- await Promise.resolve();
65
-
66
- await this.api.attach(this.nativeEl);
67
-
68
- if (!this.src) {
69
- this.api.unload();
70
- } else {
71
- // Try to load a manifest.
72
- // This is an asynchronous process.
73
- try {
74
- await this.api.load(this.src);
75
- } catch (e) {
76
- // onError is executed if the asynchronous load fails.
77
- onError(e);
78
- }
79
- }
80
- }
81
- }
82
-
83
- if (globalThis.customElements && !globalThis.customElements.get('shaka-video')) {
84
- globalThis.customElements.define('shaka-video', ShakaVideoElement);
85
- }
86
-
87
- export default ShakaVideoElement;