shaka-video-element 0.6.8 → 0.6.10

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/dist/react.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- // This file is generated by media-elements/scripts/build-react-wrapper!
2
- declare const VideoComponent: React.ForwardRefExoticComponent<
3
- React.DetailedHTMLProps<React.VideoHTMLAttributes<HTMLVideoElement>, HTMLVideoElement>
4
- >;
5
- export default VideoComponent;
1
+ import React from 'react';
2
+ import CustomMediaElement from '../shaka-video-element.js';
3
+
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
+
6
+ export { _default as default };
package/dist/react.js CHANGED
@@ -1,95 +1,160 @@
1
- // This file is generated by media-elements/scripts/build-react-wrapper!
2
- 'use client';
1
+ "use client";
3
2
 
4
- import React from 'react';
5
- import Element from '../shaka-video-element.js';
3
+ // dist/react.ts
4
+ import React from "react";
5
+ import CustomMediaElement from "../shaka-video-element.js";
6
6
 
7
- export default React.forwardRef((allProps, ref) => {
8
- let { children, suppressHydrationWarning, ...props } = allProps;
9
- const elementRef = React.useRef(null);
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).toLowerCase();
15
- const callback = props[name];
16
-
17
- React.useEffect(() => {
18
- const eventTarget = elementRef?.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
- }, [elementRef?.current, callback]);
7
+ // ../../node_modules/ce-la-react/dist/ce-la-react.js
8
+ var reservedReactProps = /* @__PURE__ */ new Set([
9
+ "style",
10
+ "children",
11
+ "ref",
12
+ "key",
13
+ "suppressContentEditableWarning",
14
+ "suppressHydrationWarning",
15
+ "dangerouslySetInnerHTML"
16
+ ]);
17
+ var reactPropToAttrNameMap = {
18
+ className: "class",
19
+ htmlFor: "for"
20
+ };
21
+ function defaultToAttributeName(propName) {
22
+ return propName.toLowerCase();
23
+ }
24
+ function defaultToAttributeValue(propValue) {
25
+ if (typeof propValue === "boolean") return propValue ? "" : void 0;
26
+ if (typeof propValue === "function") return void 0;
27
+ if (typeof propValue === "object" && propValue !== null) return void 0;
28
+ return propValue;
29
+ }
30
+ function createComponent({
31
+ react: React2,
32
+ tagName,
33
+ elementClass,
34
+ events,
35
+ displayName,
36
+ toAttributeName = defaultToAttributeName,
37
+ toAttributeValue = defaultToAttributeValue
38
+ }) {
39
+ const IS_REACT_19_OR_NEWER = Number.parseInt(React2.version) >= 19;
40
+ const ReactComponent = React2.forwardRef((props, ref) => {
41
+ var _a, _b;
42
+ const elementRef = React2.useRef(null);
43
+ const prevElemPropsRef = React2.useRef(/* @__PURE__ */ new Map());
44
+ const eventProps = {};
45
+ const attrs = {};
46
+ const reactProps = {};
47
+ const elementProps = {};
48
+ for (const [k, v] of Object.entries(props)) {
49
+ if (reservedReactProps.has(k)) {
50
+ reactProps[k] = v;
51
+ continue;
52
+ }
53
+ const attrName = toAttributeName(reactPropToAttrNameMap[k] ?? k);
54
+ 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))) {
55
+ elementProps[k] = v;
56
+ continue;
57
+ }
58
+ if (k.startsWith("on")) {
59
+ eventProps[k] = v;
60
+ continue;
61
+ }
62
+ const attrValue = toAttributeValue(v);
63
+ if (attrName && attrValue != null) {
64
+ attrs[attrName] = String(attrValue);
65
+ if (!IS_REACT_19_OR_NEWER) {
66
+ reactProps[attrName] = attrValue;
67
+ }
68
+ }
69
+ if (attrName && IS_REACT_19_OR_NEWER) {
70
+ reactProps[attrName] = v;
71
+ }
27
72
  }
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: React.useCallback(
51
- (node) => {
52
- elementRef.current = node;
53
- if (typeof ref === 'function') {
54
- ref(node);
55
- } else if (ref !== null) {
56
- ref.current = node;
73
+ if (typeof window !== "undefined") {
74
+ for (const propName in eventProps) {
75
+ const callback = eventProps[propName];
76
+ const useCapture = propName.endsWith("Capture");
77
+ const eventName = ((events == null ? void 0 : events[propName]) ?? propName.slice(2).toLowerCase()).slice(
78
+ 0,
79
+ useCapture ? -7 : void 0
80
+ );
81
+ React2.useLayoutEffect(() => {
82
+ const eventTarget = elementRef == null ? void 0 : elementRef.current;
83
+ if (!eventTarget || typeof callback !== "function") return;
84
+ eventTarget.addEventListener(eventName, callback, useCapture);
85
+ return () => {
86
+ eventTarget.removeEventListener(eventName, callback, useCapture);
87
+ };
88
+ }, [elementRef == null ? void 0 : elementRef.current, callback]);
89
+ }
90
+ React2.useLayoutEffect(() => {
91
+ if (elementRef.current === null) return;
92
+ const newElemProps = /* @__PURE__ */ new Map();
93
+ for (const key in elementProps) {
94
+ setProperty(elementRef.current, key, elementProps[key]);
95
+ prevElemPropsRef.current.delete(key);
96
+ newElemProps.set(key, elementProps[key]);
97
+ }
98
+ for (const [key, _value] of prevElemPropsRef.current) {
99
+ setProperty(elementRef.current, key, void 0);
100
+ }
101
+ prevElemPropsRef.current = newElemProps;
102
+ });
103
+ }
104
+ if (typeof window === "undefined" && (elementClass == null ? void 0 : elementClass.getTemplateHTML) && (elementClass == null ? void 0 : elementClass.shadowRootOptions)) {
105
+ const { mode, delegatesFocus } = elementClass.shadowRootOptions;
106
+ const templateShadowRoot = React2.createElement("template", {
107
+ shadowrootmode: mode,
108
+ shadowrootdelegatesfocus: delegatesFocus,
109
+ dangerouslySetInnerHTML: {
110
+ __html: elementClass.getTemplateHTML(attrs)
57
111
  }
58
- },
59
- [ref]
60
- ),
61
- children,
62
- suppressHydrationWarning,
112
+ });
113
+ reactProps.children = [templateShadowRoot, reactProps.children];
114
+ }
115
+ return React2.createElement(tagName, {
116
+ ...reactProps,
117
+ ref: React2.useCallback(
118
+ (node) => {
119
+ elementRef.current = node;
120
+ if (typeof ref === "function") {
121
+ ref(node);
122
+ } else if (ref !== null) {
123
+ ref.current = node;
124
+ }
125
+ },
126
+ [ref]
127
+ )
128
+ });
63
129
  });
64
- });
65
-
66
- const ReactPropToAttrNameMap = {
67
- className: 'class',
68
- classname: 'class',
69
- htmlFor: 'for',
70
- viewBox: 'viewBox',
71
- };
72
-
73
- function propsToAttrs(props = {}) {
74
- let attrs = {};
75
- for (let [propName, propValue] of Object.entries(props)) {
76
- let attrName = toAttrName(propName, propValue);
77
- if (attrName) attrs[attrName] = toAttrValue(propValue);
130
+ ReactComponent.displayName = displayName ?? elementClass.name;
131
+ return ReactComponent;
132
+ }
133
+ function setProperty(node, name, value) {
134
+ var _a;
135
+ node[name] = value;
136
+ if (value == null && name in (((_a = globalThis.HTMLElement) == null ? void 0 : _a.prototype) ?? {})) {
137
+ node.removeAttribute(name);
78
138
  }
79
- return attrs;
80
139
  }
81
140
 
82
- function toAttrName(propName, propValue) {
83
- if (ReactPropToAttrNameMap[propName]) return ReactPropToAttrNameMap[propName];
84
- if (typeof propValue == 'undefined') return undefined;
85
- if (typeof propValue === 'boolean' && !propValue) return undefined;
86
- if (propName.startsWith('on') && typeof propValue === 'function') return undefined;
87
- if (/[A-Z]/.test(propName)) return propName.toLowerCase();
88
- return propName;
89
- }
141
+ // dist/react.ts
142
+ var react_default = createComponent({
143
+ react: React,
144
+ tagName: "shaka-video",
145
+ elementClass: CustomMediaElement
146
+ });
147
+ export {
148
+ react_default as default
149
+ };
150
+ /*! Bundled license information:
90
151
 
91
- function toAttrValue(propValue) {
92
- if (typeof propValue === 'boolean') return '';
93
- if (Array.isArray(propValue)) return propValue.join(' ');
94
- return propValue;
95
- }
152
+ ce-la-react/dist/ce-la-react.js:
153
+ (**
154
+ * @license
155
+ * Copyright 2018 Google LLC
156
+ * SPDX-License-Identifier: BSD-3-Clause
157
+ *
158
+ * Modified version of `@lit/react` for vanilla custom elements with support for SSR.
159
+ *)
160
+ */
@@ -25909,7 +25909,12 @@ function CustomMediaMixin(superclass, { tag, is }) {
25909
25909
  if (typeof nativeElTest[prop] === "function") {
25910
25910
  this.prototype[prop] = function(...args) {
25911
25911
  this.#init();
25912
- return this.nativeEl?.[prop](...args);
25912
+ const fn = () => {
25913
+ if (this.call) return this.call(prop, ...args);
25914
+ const nativeFn = this.nativeEl?.[prop];
25915
+ return nativeFn?.apply(this.nativeEl, args);
25916
+ };
25917
+ return fn();
25913
25918
  };
25914
25919
  } else {
25915
25920
  const config = {
@@ -25920,7 +25925,7 @@ function CustomMediaMixin(superclass, { tag, is }) {
25920
25925
  const val = this.getAttribute(attr);
25921
25926
  return val === null ? false : val === "" ? true : val;
25922
25927
  }
25923
- return this.nativeEl?.[prop];
25928
+ return this.get?.(prop) ?? this.nativeEl?.[prop];
25924
25929
  }
25925
25930
  };
25926
25931
  if (prop !== prop.toUpperCase()) {
@@ -25935,6 +25940,10 @@ function CustomMediaMixin(superclass, { tag, is }) {
25935
25940
  }
25936
25941
  return;
25937
25942
  }
25943
+ if (this.set) {
25944
+ this.set(prop, val);
25945
+ return;
25946
+ }
25938
25947
  if (this.nativeEl) {
25939
25948
  this.nativeEl[prop] = val;
25940
25949
  }
@@ -25949,6 +25958,9 @@ function CustomMediaMixin(superclass, { tag, is }) {
25949
25958
  #nativeEl = null;
25950
25959
  #childMap = /* @__PURE__ */ new Map();
25951
25960
  #childObserver;
25961
+ get;
25962
+ set;
25963
+ call;
25952
25964
  // If the custom element is defined before the custom element's HTML is parsed
25953
25965
  // no attributes will be available in the constructor (construction process).
25954
25966
  // Wait until initializing in the attributeChangedCallback or
@@ -25973,7 +25985,7 @@ function CustomMediaMixin(superclass, { tag, is }) {
25973
25985
  this.setAttribute("src", `${val}`);
25974
25986
  }
25975
25987
  get preload() {
25976
- return this.getAttribute("preload") ?? this.nativeEl?.getAttribute("preload");
25988
+ return this.getAttribute("preload") ?? this.nativeEl?.preload;
25977
25989
  }
25978
25990
  set preload(val) {
25979
25991
  this.setAttribute("preload", `${val}`);
@@ -25992,11 +26004,14 @@ function CustomMediaMixin(superclass, { tag, is }) {
25992
26004
  this.shadowRoot.innerHTML = this.constructor.getTemplateHTML(attrs);
25993
26005
  }
25994
26006
  this.nativeEl.muted = this.hasAttribute("muted");
26007
+ for (const prop of nativeElProps) {
26008
+ this.#upgradeProperty(prop);
26009
+ }
25995
26010
  this.#childObserver = new MutationObserver(this.#syncMediaChildAttribute.bind(this));
25996
26011
  this.shadowRoot.addEventListener("slotchange", this);
25997
26012
  this.#syncMediaChildren();
25998
26013
  for (const type of this.constructor.Events) {
25999
- this.shadowRoot?.addEventListener(type, this.handleEvent.bind(this), true);
26014
+ this.shadowRoot?.addEventListener(type, this, true);
26000
26015
  }
26001
26016
  }
26002
26017
  handleEvent(event) {
@@ -26045,6 +26060,13 @@ function CustomMediaMixin(superclass, { tag, is }) {
26045
26060
  trackEl.track.mode = "hidden";
26046
26061
  }
26047
26062
  }
26063
+ #upgradeProperty(prop) {
26064
+ if (Object.prototype.hasOwnProperty.call(this, prop)) {
26065
+ const value = this[prop];
26066
+ delete this[prop];
26067
+ this[prop] = value;
26068
+ }
26069
+ }
26048
26070
  attributeChangedCallback(attrName, oldValue, newValue) {
26049
26071
  this.#init();
26050
26072
  this.#forwardAttribute(attrName, oldValue, newValue);
@@ -26074,11 +26096,17 @@ function getNativeElProps(nativeElTest) {
26074
26096
  return nativeElProps;
26075
26097
  }
26076
26098
  function serializeAttributes(attrs) {
26077
- return Object.entries(attrs).map(([key, value]) => value === "" ? ` ${key}` : ` ${key}="${value}"`).join("");
26099
+ let html = "";
26100
+ for (const key in attrs) {
26101
+ const value = attrs[key];
26102
+ if (value === "") html += ` ${key}`;
26103
+ else html += ` ${key}="${value}"`;
26104
+ }
26105
+ return html;
26078
26106
  }
26079
26107
  function namedNodeMapToObject(namedNodeMap) {
26080
26108
  const obj = {};
26081
- for (const attr of Array.from(namedNodeMap)) {
26109
+ for (const attr of namedNodeMap) {
26082
26110
  obj[attr.name] = attr.value;
26083
26111
  }
26084
26112
  return obj;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shaka-video-element",
3
- "version": "0.6.8",
3
+ "version": "0.6.10",
4
4
  "description": "Custom element (web component) for Shaka Player",
5
5
  "author": "@muxinc",
6
6
  "license": "MIT",
@@ -14,10 +14,12 @@
14
14
  "directory": "packages/shaka-video-element"
15
15
  },
16
16
  "files": [
17
+ "shaka-video-element.d.ts",
17
18
  "dist"
18
19
  ],
19
20
  "type": "module",
20
21
  "main": "shaka-video-element.js",
22
+ "types": "shaka-video-element.d.ts",
21
23
  "exports": {
22
24
  ".": "./shaka-video-element.js",
23
25
  "./react": "./dist/react.js"
@@ -30,13 +32,13 @@
30
32
  "build": "run-s build:*"
31
33
  },
32
34
  "dependencies": {
33
- "custom-media-element": "^1.4.0",
35
+ "custom-media-element": "^1.4.1",
34
36
  "shaka-player": "~4.8.4"
35
37
  },
36
38
  "devDependencies": {
37
- "build-react-wrapper": "^0.1.6",
39
+ "build-react-wrapper": "^0.1.7",
38
40
  "npm-run-all": "^4.1.5",
39
- "wet-run": "^1.2.2"
41
+ "wet-run": "^1.2.5"
40
42
  },
41
43
  "keywords": [
42
44
  "shaka",
@@ -0,0 +1,10 @@
1
+ export default 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
+ }