shaka-video-element 0.6.7 → 0.6.8
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 +49 -74
- 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,34 +25904,29 @@ 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
|
-
|
|
25914
|
-
if (this.call) return this.call(prop, ...args);
|
|
25915
|
-
return this.nativeEl[prop].apply(this.nativeEl, args);
|
|
25916
|
-
};
|
|
25917
|
-
return fn();
|
|
25912
|
+
return this.nativeEl?.[prop](...args);
|
|
25918
25913
|
};
|
|
25919
25914
|
} else {
|
|
25920
|
-
|
|
25915
|
+
const config = {
|
|
25921
25916
|
get() {
|
|
25922
25917
|
this.#init();
|
|
25923
|
-
|
|
25918
|
+
const attr = prop.toLowerCase();
|
|
25924
25919
|
if (propsToAttrs.has(attr)) {
|
|
25925
25920
|
const val = this.getAttribute(attr);
|
|
25926
25921
|
return val === null ? false : val === "" ? true : val;
|
|
25927
25922
|
}
|
|
25928
|
-
return this.
|
|
25923
|
+
return this.nativeEl?.[prop];
|
|
25929
25924
|
}
|
|
25930
25925
|
};
|
|
25931
25926
|
if (prop !== prop.toUpperCase()) {
|
|
25932
25927
|
config.set = function(val) {
|
|
25933
25928
|
this.#init();
|
|
25934
|
-
|
|
25929
|
+
const attr = prop.toLowerCase();
|
|
25935
25930
|
if (propsToAttrs.has(attr)) {
|
|
25936
25931
|
if (val === true || val === false || val == null) {
|
|
25937
25932
|
this.toggleAttribute(attr, Boolean(val));
|
|
@@ -25940,27 +25935,27 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25940
25935
|
}
|
|
25941
25936
|
return;
|
|
25942
25937
|
}
|
|
25943
|
-
if (this.
|
|
25944
|
-
this.
|
|
25945
|
-
return;
|
|
25938
|
+
if (this.nativeEl) {
|
|
25939
|
+
this.nativeEl[prop] = val;
|
|
25946
25940
|
}
|
|
25947
|
-
this.nativeEl[prop] = val;
|
|
25948
25941
|
};
|
|
25949
25942
|
}
|
|
25950
25943
|
Object.defineProperty(this.prototype, prop, config);
|
|
25951
25944
|
}
|
|
25952
25945
|
}
|
|
25953
25946
|
}
|
|
25954
|
-
|
|
25955
|
-
#
|
|
25947
|
+
// Private fields
|
|
25948
|
+
#isInit = false;
|
|
25949
|
+
#nativeEl = null;
|
|
25956
25950
|
#childMap = /* @__PURE__ */ new Map();
|
|
25957
25951
|
#childObserver;
|
|
25958
|
-
|
|
25959
|
-
|
|
25960
|
-
|
|
25952
|
+
// If the custom element is defined before the custom element's HTML is parsed
|
|
25953
|
+
// no attributes will be available in the constructor (construction process).
|
|
25954
|
+
// Wait until initializing in the attributeChangedCallback or
|
|
25955
|
+
// connectedCallback or accessing any properties.
|
|
25961
25956
|
get nativeEl() {
|
|
25962
25957
|
this.#init();
|
|
25963
|
-
return this.#nativeEl ?? this.querySelector(":scope > [slot=media]") ?? this.querySelector(tag) ?? this.shadowRoot
|
|
25958
|
+
return this.#nativeEl ?? this.querySelector(":scope > [slot=media]") ?? this.querySelector(tag) ?? this.shadowRoot?.querySelector(tag) ?? null;
|
|
25964
25959
|
}
|
|
25965
25960
|
set nativeEl(val) {
|
|
25966
25961
|
this.#nativeEl = val;
|
|
@@ -25969,7 +25964,7 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25969
25964
|
return this.hasAttribute("muted");
|
|
25970
25965
|
}
|
|
25971
25966
|
set defaultMuted(val) {
|
|
25972
|
-
this.toggleAttribute("muted",
|
|
25967
|
+
this.toggleAttribute("muted", val);
|
|
25973
25968
|
}
|
|
25974
25969
|
get src() {
|
|
25975
25970
|
return this.getAttribute("src");
|
|
@@ -25978,7 +25973,7 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25978
25973
|
this.setAttribute("src", `${val}`);
|
|
25979
25974
|
}
|
|
25980
25975
|
get preload() {
|
|
25981
|
-
return this.getAttribute("preload") ?? this.nativeEl?.preload;
|
|
25976
|
+
return this.getAttribute("preload") ?? this.nativeEl?.getAttribute("preload");
|
|
25982
25977
|
}
|
|
25983
25978
|
set preload(val) {
|
|
25984
25979
|
this.setAttribute("preload", `${val}`);
|
|
@@ -25997,14 +25992,11 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25997
25992
|
this.shadowRoot.innerHTML = this.constructor.getTemplateHTML(attrs);
|
|
25998
25993
|
}
|
|
25999
25994
|
this.nativeEl.muted = this.hasAttribute("muted");
|
|
26000
|
-
|
|
26001
|
-
this.#upgradeProperty(prop);
|
|
26002
|
-
}
|
|
26003
|
-
this.#childObserver = new MutationObserver(this.#syncMediaChildAttribute);
|
|
25995
|
+
this.#childObserver = new MutationObserver(this.#syncMediaChildAttribute.bind(this));
|
|
26004
25996
|
this.shadowRoot.addEventListener("slotchange", this);
|
|
26005
25997
|
this.#syncMediaChildren();
|
|
26006
|
-
for (
|
|
26007
|
-
this.shadowRoot
|
|
25998
|
+
for (const type of this.constructor.Events) {
|
|
25999
|
+
this.shadowRoot?.addEventListener(type, this.handleEvent.bind(this), true);
|
|
26008
26000
|
}
|
|
26009
26001
|
}
|
|
26010
26002
|
handleEvent(event) {
|
|
@@ -26016,22 +26008,19 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
26016
26008
|
this.dispatchEvent(new CustomEvent(event.type, { detail: event.detail }));
|
|
26017
26009
|
}
|
|
26018
26010
|
}
|
|
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
26011
|
#syncMediaChildren() {
|
|
26025
26012
|
const removeNativeChildren = new Map(this.#childMap);
|
|
26026
|
-
this.shadowRoot
|
|
26013
|
+
const defaultSlot = this.shadowRoot?.querySelector("slot:not([name])");
|
|
26014
|
+
const mediaChildren = defaultSlot?.assignedElements({ flatten: true }).filter((el) => ["track", "source"].includes(el.localName));
|
|
26015
|
+
mediaChildren.forEach((el) => {
|
|
26027
26016
|
removeNativeChildren.delete(el);
|
|
26028
26017
|
let clone = this.#childMap.get(el);
|
|
26029
26018
|
if (!clone) {
|
|
26030
26019
|
clone = el.cloneNode();
|
|
26031
26020
|
this.#childMap.set(el, clone);
|
|
26032
|
-
this.#childObserver
|
|
26021
|
+
this.#childObserver?.observe(el, { attributes: true });
|
|
26033
26022
|
}
|
|
26034
|
-
this.nativeEl
|
|
26023
|
+
this.nativeEl?.append(clone);
|
|
26035
26024
|
this.#enableDefaultTrack(clone);
|
|
26036
26025
|
});
|
|
26037
26026
|
removeNativeChildren.forEach((clone, el) => {
|
|
@@ -26039,71 +26028,57 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
26039
26028
|
this.#childMap.delete(el);
|
|
26040
26029
|
});
|
|
26041
26030
|
}
|
|
26042
|
-
#syncMediaChildAttribute
|
|
26043
|
-
for (
|
|
26031
|
+
#syncMediaChildAttribute(mutations) {
|
|
26032
|
+
for (const mutation of mutations) {
|
|
26044
26033
|
if (mutation.type === "attributes") {
|
|
26045
26034
|
const { target, attributeName } = mutation;
|
|
26046
26035
|
const clone = this.#childMap.get(target);
|
|
26047
|
-
clone
|
|
26048
|
-
|
|
26036
|
+
if (clone && attributeName) {
|
|
26037
|
+
clone.setAttribute(attributeName, target.getAttribute(attributeName) ?? "");
|
|
26038
|
+
this.#enableDefaultTrack(clone);
|
|
26039
|
+
}
|
|
26049
26040
|
}
|
|
26050
26041
|
}
|
|
26051
|
-
}
|
|
26042
|
+
}
|
|
26052
26043
|
#enableDefaultTrack(trackEl) {
|
|
26053
|
-
if (trackEl.localName === "track" && trackEl.default && (trackEl.kind === "chapters" || trackEl.kind === "metadata") && trackEl.track.mode === "disabled") {
|
|
26044
|
+
if (trackEl && trackEl.localName === "track" && trackEl.default && (trackEl.kind === "chapters" || trackEl.kind === "metadata") && trackEl.track.mode === "disabled") {
|
|
26054
26045
|
trackEl.track.mode = "hidden";
|
|
26055
26046
|
}
|
|
26056
26047
|
}
|
|
26057
|
-
#upgradeProperty(prop) {
|
|
26058
|
-
if (Object.prototype.hasOwnProperty.call(this, prop)) {
|
|
26059
|
-
const value = this[prop];
|
|
26060
|
-
delete this[prop];
|
|
26061
|
-
this[prop] = value;
|
|
26062
|
-
}
|
|
26063
|
-
}
|
|
26064
26048
|
attributeChangedCallback(attrName, oldValue, newValue) {
|
|
26065
26049
|
this.#init();
|
|
26066
26050
|
this.#forwardAttribute(attrName, oldValue, newValue);
|
|
26067
26051
|
}
|
|
26068
26052
|
#forwardAttribute(attrName, oldValue, newValue) {
|
|
26069
|
-
if (["id", "class"].includes(attrName))
|
|
26070
|
-
return;
|
|
26071
|
-
}
|
|
26053
|
+
if (["id", "class"].includes(attrName)) return;
|
|
26072
26054
|
if (!CustomMedia.observedAttributes.includes(attrName) && this.constructor.observedAttributes.includes(attrName)) {
|
|
26073
26055
|
return;
|
|
26074
26056
|
}
|
|
26075
26057
|
if (newValue === null) {
|
|
26076
|
-
this.nativeEl
|
|
26077
|
-
} else {
|
|
26078
|
-
|
|
26079
|
-
this.nativeEl.setAttribute?.(attrName, newValue);
|
|
26080
|
-
}
|
|
26058
|
+
this.nativeEl?.removeAttribute(attrName);
|
|
26059
|
+
} else if (this.nativeEl?.getAttribute(attrName) !== newValue) {
|
|
26060
|
+
this.nativeEl?.setAttribute(attrName, newValue);
|
|
26081
26061
|
}
|
|
26082
26062
|
}
|
|
26083
26063
|
connectedCallback() {
|
|
26084
26064
|
this.#init();
|
|
26085
26065
|
}
|
|
26086
26066
|
};
|
|
26087
|
-
}
|
|
26067
|
+
}
|
|
26088
26068
|
function getNativeElProps(nativeElTest) {
|
|
26089
|
-
|
|
26069
|
+
const nativeElProps = [];
|
|
26090
26070
|
for (let proto = Object.getPrototypeOf(nativeElTest); proto && proto !== HTMLElement.prototype; proto = Object.getPrototypeOf(proto)) {
|
|
26091
|
-
|
|
26071
|
+
const props = Object.getOwnPropertyNames(proto);
|
|
26072
|
+
nativeElProps.push(...props);
|
|
26092
26073
|
}
|
|
26093
26074
|
return nativeElProps;
|
|
26094
26075
|
}
|
|
26095
26076
|
function serializeAttributes(attrs) {
|
|
26096
|
-
|
|
26097
|
-
for (const key in attrs) {
|
|
26098
|
-
const value = attrs[key];
|
|
26099
|
-
if (value === "") html += ` ${key}`;
|
|
26100
|
-
else html += ` ${key}="${value}"`;
|
|
26101
|
-
}
|
|
26102
|
-
return html;
|
|
26077
|
+
return Object.entries(attrs).map(([key, value]) => value === "" ? ` ${key}` : ` ${key}="${value}"`).join("");
|
|
26103
26078
|
}
|
|
26104
26079
|
function namedNodeMapToObject(namedNodeMap) {
|
|
26105
|
-
|
|
26106
|
-
for (
|
|
26080
|
+
const obj = {};
|
|
26081
|
+
for (const attr of Array.from(namedNodeMap)) {
|
|
26107
26082
|
obj[attr.name] = attr.value;
|
|
26108
26083
|
}
|
|
26109
26084
|
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.8",
|
|
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.0",
|
|
34
34
|
"shaka-player": "~4.8.4"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|