shaka-video-element 0.6.7 → 0.6.9
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/shaka-video-element.js +52 -49
- package/package.json +2 -2
|
@@ -25784,7 +25784,7 @@ var require_shaka_player_compiled = __commonJS({
|
|
|
25784
25784
|
}
|
|
25785
25785
|
});
|
|
25786
25786
|
|
|
25787
|
-
// ../custom-media-element/custom-media-element.js
|
|
25787
|
+
// ../custom-media-element/dist/custom-media-element.js
|
|
25788
25788
|
var Events = [
|
|
25789
25789
|
"abort",
|
|
25790
25790
|
"canplay",
|
|
@@ -25871,14 +25871,14 @@ function getVideoTemplateHTML(attrs) {
|
|
|
25871
25871
|
`
|
|
25872
25872
|
);
|
|
25873
25873
|
}
|
|
25874
|
-
|
|
25874
|
+
function CustomMediaMixin(superclass, { tag, is }) {
|
|
25875
25875
|
const nativeElTest = globalThis.document?.createElement?.(tag, { is });
|
|
25876
25876
|
const nativeElProps = nativeElTest ? getNativeElProps(nativeElTest) : [];
|
|
25877
25877
|
return class CustomMedia extends superclass {
|
|
25878
25878
|
static getTemplateHTML = tag.endsWith("audio") ? getAudioTemplateHTML : getVideoTemplateHTML;
|
|
25879
25879
|
static shadowRootOptions = { mode: "open" };
|
|
25880
25880
|
static Events = Events;
|
|
25881
|
-
static #isDefined;
|
|
25881
|
+
static #isDefined = false;
|
|
25882
25882
|
static get observedAttributes() {
|
|
25883
25883
|
CustomMedia.#define();
|
|
25884
25884
|
const natAttrs = nativeElTest?.constructor?.observedAttributes ?? [];
|
|
@@ -25904,23 +25904,23 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25904
25904
|
this.#isDefined = true;
|
|
25905
25905
|
const propsToAttrs = new Set(this.observedAttributes);
|
|
25906
25906
|
propsToAttrs.delete("muted");
|
|
25907
|
-
for (
|
|
25907
|
+
for (const prop of nativeElProps) {
|
|
25908
25908
|
if (prop in this.prototype) continue;
|
|
25909
|
-
|
|
25910
|
-
if (type == "function") {
|
|
25909
|
+
if (typeof nativeElTest[prop] === "function") {
|
|
25911
25910
|
this.prototype[prop] = function(...args) {
|
|
25912
25911
|
this.#init();
|
|
25913
25912
|
const fn = () => {
|
|
25914
25913
|
if (this.call) return this.call(prop, ...args);
|
|
25915
|
-
|
|
25914
|
+
const nativeFn = this.nativeEl?.[prop];
|
|
25915
|
+
return nativeFn?.apply(this.nativeEl, args);
|
|
25916
25916
|
};
|
|
25917
25917
|
return fn();
|
|
25918
25918
|
};
|
|
25919
25919
|
} else {
|
|
25920
|
-
|
|
25920
|
+
const config = {
|
|
25921
25921
|
get() {
|
|
25922
25922
|
this.#init();
|
|
25923
|
-
|
|
25923
|
+
const attr = prop.toLowerCase();
|
|
25924
25924
|
if (propsToAttrs.has(attr)) {
|
|
25925
25925
|
const val = this.getAttribute(attr);
|
|
25926
25926
|
return val === null ? false : val === "" ? true : val;
|
|
@@ -25931,7 +25931,7 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25931
25931
|
if (prop !== prop.toUpperCase()) {
|
|
25932
25932
|
config.set = function(val) {
|
|
25933
25933
|
this.#init();
|
|
25934
|
-
|
|
25934
|
+
const attr = prop.toLowerCase();
|
|
25935
25935
|
if (propsToAttrs.has(attr)) {
|
|
25936
25936
|
if (val === true || val === false || val == null) {
|
|
25937
25937
|
this.toggleAttribute(attr, Boolean(val));
|
|
@@ -25944,23 +25944,30 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25944
25944
|
this.set(prop, val);
|
|
25945
25945
|
return;
|
|
25946
25946
|
}
|
|
25947
|
-
this.nativeEl
|
|
25947
|
+
if (this.nativeEl) {
|
|
25948
|
+
this.nativeEl[prop] = val;
|
|
25949
|
+
}
|
|
25948
25950
|
};
|
|
25949
25951
|
}
|
|
25950
25952
|
Object.defineProperty(this.prototype, prop, config);
|
|
25951
25953
|
}
|
|
25952
25954
|
}
|
|
25953
25955
|
}
|
|
25954
|
-
|
|
25955
|
-
#
|
|
25956
|
+
// Private fields
|
|
25957
|
+
#isInit = false;
|
|
25958
|
+
#nativeEl = null;
|
|
25956
25959
|
#childMap = /* @__PURE__ */ new Map();
|
|
25957
25960
|
#childObserver;
|
|
25958
|
-
|
|
25959
|
-
|
|
25960
|
-
|
|
25961
|
+
get;
|
|
25962
|
+
set;
|
|
25963
|
+
call;
|
|
25964
|
+
// If the custom element is defined before the custom element's HTML is parsed
|
|
25965
|
+
// no attributes will be available in the constructor (construction process).
|
|
25966
|
+
// Wait until initializing in the attributeChangedCallback or
|
|
25967
|
+
// connectedCallback or accessing any properties.
|
|
25961
25968
|
get nativeEl() {
|
|
25962
25969
|
this.#init();
|
|
25963
|
-
return this.#nativeEl ?? this.querySelector(":scope > [slot=media]") ?? this.querySelector(tag) ?? this.shadowRoot
|
|
25970
|
+
return this.#nativeEl ?? this.querySelector(":scope > [slot=media]") ?? this.querySelector(tag) ?? this.shadowRoot?.querySelector(tag) ?? null;
|
|
25964
25971
|
}
|
|
25965
25972
|
set nativeEl(val) {
|
|
25966
25973
|
this.#nativeEl = val;
|
|
@@ -25969,7 +25976,7 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25969
25976
|
return this.hasAttribute("muted");
|
|
25970
25977
|
}
|
|
25971
25978
|
set defaultMuted(val) {
|
|
25972
|
-
this.toggleAttribute("muted",
|
|
25979
|
+
this.toggleAttribute("muted", val);
|
|
25973
25980
|
}
|
|
25974
25981
|
get src() {
|
|
25975
25982
|
return this.getAttribute("src");
|
|
@@ -25997,14 +26004,14 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25997
26004
|
this.shadowRoot.innerHTML = this.constructor.getTemplateHTML(attrs);
|
|
25998
26005
|
}
|
|
25999
26006
|
this.nativeEl.muted = this.hasAttribute("muted");
|
|
26000
|
-
for (
|
|
26007
|
+
for (const prop of nativeElProps) {
|
|
26001
26008
|
this.#upgradeProperty(prop);
|
|
26002
26009
|
}
|
|
26003
|
-
this.#childObserver = new MutationObserver(this.#syncMediaChildAttribute);
|
|
26010
|
+
this.#childObserver = new MutationObserver(this.#syncMediaChildAttribute.bind(this));
|
|
26004
26011
|
this.shadowRoot.addEventListener("slotchange", this);
|
|
26005
26012
|
this.#syncMediaChildren();
|
|
26006
|
-
for (
|
|
26007
|
-
this.shadowRoot
|
|
26013
|
+
for (const type of this.constructor.Events) {
|
|
26014
|
+
this.shadowRoot?.addEventListener(type, this, true);
|
|
26008
26015
|
}
|
|
26009
26016
|
}
|
|
26010
26017
|
handleEvent(event) {
|
|
@@ -26016,22 +26023,19 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
26016
26023
|
this.dispatchEvent(new CustomEvent(event.type, { detail: event.detail }));
|
|
26017
26024
|
}
|
|
26018
26025
|
}
|
|
26019
|
-
/**
|
|
26020
|
-
* Keep some native child elements like track and source in sync.
|
|
26021
|
-
* An unnamed <slot> will be filled with all of the custom element's
|
|
26022
|
-
* top-level child nodes that do not have the slot attribute.
|
|
26023
|
-
*/
|
|
26024
26026
|
#syncMediaChildren() {
|
|
26025
26027
|
const removeNativeChildren = new Map(this.#childMap);
|
|
26026
|
-
this.shadowRoot
|
|
26028
|
+
const defaultSlot = this.shadowRoot?.querySelector("slot:not([name])");
|
|
26029
|
+
const mediaChildren = defaultSlot?.assignedElements({ flatten: true }).filter((el) => ["track", "source"].includes(el.localName));
|
|
26030
|
+
mediaChildren.forEach((el) => {
|
|
26027
26031
|
removeNativeChildren.delete(el);
|
|
26028
26032
|
let clone = this.#childMap.get(el);
|
|
26029
26033
|
if (!clone) {
|
|
26030
26034
|
clone = el.cloneNode();
|
|
26031
26035
|
this.#childMap.set(el, clone);
|
|
26032
|
-
this.#childObserver
|
|
26036
|
+
this.#childObserver?.observe(el, { attributes: true });
|
|
26033
26037
|
}
|
|
26034
|
-
this.nativeEl
|
|
26038
|
+
this.nativeEl?.append(clone);
|
|
26035
26039
|
this.#enableDefaultTrack(clone);
|
|
26036
26040
|
});
|
|
26037
26041
|
removeNativeChildren.forEach((clone, el) => {
|
|
@@ -26039,18 +26043,20 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
26039
26043
|
this.#childMap.delete(el);
|
|
26040
26044
|
});
|
|
26041
26045
|
}
|
|
26042
|
-
#syncMediaChildAttribute
|
|
26043
|
-
for (
|
|
26046
|
+
#syncMediaChildAttribute(mutations) {
|
|
26047
|
+
for (const mutation of mutations) {
|
|
26044
26048
|
if (mutation.type === "attributes") {
|
|
26045
26049
|
const { target, attributeName } = mutation;
|
|
26046
26050
|
const clone = this.#childMap.get(target);
|
|
26047
|
-
clone
|
|
26048
|
-
|
|
26051
|
+
if (clone && attributeName) {
|
|
26052
|
+
clone.setAttribute(attributeName, target.getAttribute(attributeName) ?? "");
|
|
26053
|
+
this.#enableDefaultTrack(clone);
|
|
26054
|
+
}
|
|
26049
26055
|
}
|
|
26050
26056
|
}
|
|
26051
|
-
}
|
|
26057
|
+
}
|
|
26052
26058
|
#enableDefaultTrack(trackEl) {
|
|
26053
|
-
if (trackEl.localName === "track" && trackEl.default && (trackEl.kind === "chapters" || trackEl.kind === "metadata") && trackEl.track.mode === "disabled") {
|
|
26059
|
+
if (trackEl && trackEl.localName === "track" && trackEl.default && (trackEl.kind === "chapters" || trackEl.kind === "metadata") && trackEl.track.mode === "disabled") {
|
|
26054
26060
|
trackEl.track.mode = "hidden";
|
|
26055
26061
|
}
|
|
26056
26062
|
}
|
|
@@ -26066,29 +26072,26 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
26066
26072
|
this.#forwardAttribute(attrName, oldValue, newValue);
|
|
26067
26073
|
}
|
|
26068
26074
|
#forwardAttribute(attrName, oldValue, newValue) {
|
|
26069
|
-
if (["id", "class"].includes(attrName))
|
|
26070
|
-
return;
|
|
26071
|
-
}
|
|
26075
|
+
if (["id", "class"].includes(attrName)) return;
|
|
26072
26076
|
if (!CustomMedia.observedAttributes.includes(attrName) && this.constructor.observedAttributes.includes(attrName)) {
|
|
26073
26077
|
return;
|
|
26074
26078
|
}
|
|
26075
26079
|
if (newValue === null) {
|
|
26076
|
-
this.nativeEl
|
|
26077
|
-
} else {
|
|
26078
|
-
|
|
26079
|
-
this.nativeEl.setAttribute?.(attrName, newValue);
|
|
26080
|
-
}
|
|
26080
|
+
this.nativeEl?.removeAttribute(attrName);
|
|
26081
|
+
} else if (this.nativeEl?.getAttribute(attrName) !== newValue) {
|
|
26082
|
+
this.nativeEl?.setAttribute(attrName, newValue);
|
|
26081
26083
|
}
|
|
26082
26084
|
}
|
|
26083
26085
|
connectedCallback() {
|
|
26084
26086
|
this.#init();
|
|
26085
26087
|
}
|
|
26086
26088
|
};
|
|
26087
|
-
}
|
|
26089
|
+
}
|
|
26088
26090
|
function getNativeElProps(nativeElTest) {
|
|
26089
|
-
|
|
26091
|
+
const nativeElProps = [];
|
|
26090
26092
|
for (let proto = Object.getPrototypeOf(nativeElTest); proto && proto !== HTMLElement.prototype; proto = Object.getPrototypeOf(proto)) {
|
|
26091
|
-
|
|
26093
|
+
const props = Object.getOwnPropertyNames(proto);
|
|
26094
|
+
nativeElProps.push(...props);
|
|
26092
26095
|
}
|
|
26093
26096
|
return nativeElProps;
|
|
26094
26097
|
}
|
|
@@ -26102,8 +26105,8 @@ function serializeAttributes(attrs) {
|
|
|
26102
26105
|
return html;
|
|
26103
26106
|
}
|
|
26104
26107
|
function namedNodeMapToObject(namedNodeMap) {
|
|
26105
|
-
|
|
26106
|
-
for (
|
|
26108
|
+
const obj = {};
|
|
26109
|
+
for (const attr of namedNodeMap) {
|
|
26107
26110
|
obj[attr.name] = attr.value;
|
|
26108
26111
|
}
|
|
26109
26112
|
return obj;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "shaka-video-element",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "Custom element (web component) for Shaka Player",
|
|
5
5
|
"author": "@muxinc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"build": "run-s build:*"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"custom-media-element": "^1.
|
|
33
|
+
"custom-media-element": "^1.4.1",
|
|
34
34
|
"shaka-player": "~4.8.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|