shaka-video-element 0.6.9 → 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
+ */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shaka-video-element",
3
- "version": "0.6.9",
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"
@@ -34,9 +36,9 @@
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
+ }