shaka-video-element 0.6.6 → 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 +68 -70
- 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,26 +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
|
-
|
|
25958
|
-
|
|
25959
|
-
|
|
25951
|
+
#childObserver;
|
|
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.
|
|
25960
25956
|
get nativeEl() {
|
|
25961
25957
|
this.#init();
|
|
25962
|
-
return this.#nativeEl ?? this.
|
|
25958
|
+
return this.#nativeEl ?? this.querySelector(":scope > [slot=media]") ?? this.querySelector(tag) ?? this.shadowRoot?.querySelector(tag) ?? null;
|
|
25963
25959
|
}
|
|
25964
25960
|
set nativeEl(val) {
|
|
25965
25961
|
this.#nativeEl = val;
|
|
@@ -25968,7 +25964,7 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25968
25964
|
return this.hasAttribute("muted");
|
|
25969
25965
|
}
|
|
25970
25966
|
set defaultMuted(val) {
|
|
25971
|
-
this.toggleAttribute("muted",
|
|
25967
|
+
this.toggleAttribute("muted", val);
|
|
25972
25968
|
}
|
|
25973
25969
|
get src() {
|
|
25974
25970
|
return this.getAttribute("src");
|
|
@@ -25977,7 +25973,7 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25977
25973
|
this.setAttribute("src", `${val}`);
|
|
25978
25974
|
}
|
|
25979
25975
|
get preload() {
|
|
25980
|
-
return this.getAttribute("preload") ?? this.nativeEl?.preload;
|
|
25976
|
+
return this.getAttribute("preload") ?? this.nativeEl?.getAttribute("preload");
|
|
25981
25977
|
}
|
|
25982
25978
|
set preload(val) {
|
|
25983
25979
|
this.setAttribute("preload", `${val}`);
|
|
@@ -25996,13 +25992,11 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
25996
25992
|
this.shadowRoot.innerHTML = this.constructor.getTemplateHTML(attrs);
|
|
25997
25993
|
}
|
|
25998
25994
|
this.nativeEl.muted = this.hasAttribute("muted");
|
|
25999
|
-
|
|
26000
|
-
this.#upgradeProperty(prop);
|
|
26001
|
-
}
|
|
25995
|
+
this.#childObserver = new MutationObserver(this.#syncMediaChildAttribute.bind(this));
|
|
26002
25996
|
this.shadowRoot.addEventListener("slotchange", this);
|
|
26003
25997
|
this.#syncMediaChildren();
|
|
26004
|
-
for (
|
|
26005
|
-
this.shadowRoot
|
|
25998
|
+
for (const type of this.constructor.Events) {
|
|
25999
|
+
this.shadowRoot?.addEventListener(type, this.handleEvent.bind(this), true);
|
|
26006
26000
|
}
|
|
26007
26001
|
}
|
|
26008
26002
|
handleEvent(event) {
|
|
@@ -26014,32 +26008,41 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
26014
26008
|
this.dispatchEvent(new CustomEvent(event.type, { detail: event.detail }));
|
|
26015
26009
|
}
|
|
26016
26010
|
}
|
|
26017
|
-
/**
|
|
26018
|
-
* Keep some native child elements like track and source in sync.
|
|
26019
|
-
* An unnamed <slot> will be filled with all of the custom element's
|
|
26020
|
-
* top-level child nodes that do not have the slot attribute.
|
|
26021
|
-
*/
|
|
26022
26011
|
#syncMediaChildren() {
|
|
26023
26012
|
const removeNativeChildren = new Map(this.#childMap);
|
|
26024
|
-
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) => {
|
|
26025
26016
|
removeNativeChildren.delete(el);
|
|
26026
26017
|
let clone = this.#childMap.get(el);
|
|
26027
26018
|
if (!clone) {
|
|
26028
26019
|
clone = el.cloneNode();
|
|
26029
26020
|
this.#childMap.set(el, clone);
|
|
26021
|
+
this.#childObserver?.observe(el, { attributes: true });
|
|
26030
26022
|
}
|
|
26031
|
-
this.nativeEl
|
|
26032
|
-
|
|
26033
|
-
clone.track.mode = "hidden";
|
|
26034
|
-
}
|
|
26023
|
+
this.nativeEl?.append(clone);
|
|
26024
|
+
this.#enableDefaultTrack(clone);
|
|
26035
26025
|
});
|
|
26036
|
-
removeNativeChildren.forEach((el) =>
|
|
26026
|
+
removeNativeChildren.forEach((clone, el) => {
|
|
26027
|
+
clone.remove();
|
|
26028
|
+
this.#childMap.delete(el);
|
|
26029
|
+
});
|
|
26030
|
+
}
|
|
26031
|
+
#syncMediaChildAttribute(mutations) {
|
|
26032
|
+
for (const mutation of mutations) {
|
|
26033
|
+
if (mutation.type === "attributes") {
|
|
26034
|
+
const { target, attributeName } = mutation;
|
|
26035
|
+
const clone = this.#childMap.get(target);
|
|
26036
|
+
if (clone && attributeName) {
|
|
26037
|
+
clone.setAttribute(attributeName, target.getAttribute(attributeName) ?? "");
|
|
26038
|
+
this.#enableDefaultTrack(clone);
|
|
26039
|
+
}
|
|
26040
|
+
}
|
|
26041
|
+
}
|
|
26037
26042
|
}
|
|
26038
|
-
#
|
|
26039
|
-
if (
|
|
26040
|
-
|
|
26041
|
-
delete this[prop];
|
|
26042
|
-
this[prop] = value;
|
|
26043
|
+
#enableDefaultTrack(trackEl) {
|
|
26044
|
+
if (trackEl && trackEl.localName === "track" && trackEl.default && (trackEl.kind === "chapters" || trackEl.kind === "metadata") && trackEl.track.mode === "disabled") {
|
|
26045
|
+
trackEl.track.mode = "hidden";
|
|
26043
26046
|
}
|
|
26044
26047
|
}
|
|
26045
26048
|
attributeChangedCallback(attrName, oldValue, newValue) {
|
|
@@ -26047,52 +26050,47 @@ var CustomMediaMixin = (superclass, { tag, is }) => {
|
|
|
26047
26050
|
this.#forwardAttribute(attrName, oldValue, newValue);
|
|
26048
26051
|
}
|
|
26049
26052
|
#forwardAttribute(attrName, oldValue, newValue) {
|
|
26050
|
-
if (["id", "class"].includes(attrName))
|
|
26051
|
-
return;
|
|
26052
|
-
}
|
|
26053
|
+
if (["id", "class"].includes(attrName)) return;
|
|
26053
26054
|
if (!CustomMedia.observedAttributes.includes(attrName) && this.constructor.observedAttributes.includes(attrName)) {
|
|
26054
26055
|
return;
|
|
26055
26056
|
}
|
|
26056
26057
|
if (newValue === null) {
|
|
26057
|
-
this.nativeEl
|
|
26058
|
-
} else {
|
|
26059
|
-
|
|
26060
|
-
this.nativeEl.setAttribute?.(attrName, newValue);
|
|
26061
|
-
}
|
|
26058
|
+
this.nativeEl?.removeAttribute(attrName);
|
|
26059
|
+
} else if (this.nativeEl?.getAttribute(attrName) !== newValue) {
|
|
26060
|
+
this.nativeEl?.setAttribute(attrName, newValue);
|
|
26062
26061
|
}
|
|
26063
26062
|
}
|
|
26064
26063
|
connectedCallback() {
|
|
26065
26064
|
this.#init();
|
|
26066
26065
|
}
|
|
26067
26066
|
};
|
|
26068
|
-
}
|
|
26067
|
+
}
|
|
26069
26068
|
function getNativeElProps(nativeElTest) {
|
|
26070
|
-
|
|
26069
|
+
const nativeElProps = [];
|
|
26071
26070
|
for (let proto = Object.getPrototypeOf(nativeElTest); proto && proto !== HTMLElement.prototype; proto = Object.getPrototypeOf(proto)) {
|
|
26072
|
-
|
|
26071
|
+
const props = Object.getOwnPropertyNames(proto);
|
|
26072
|
+
nativeElProps.push(...props);
|
|
26073
26073
|
}
|
|
26074
26074
|
return nativeElProps;
|
|
26075
26075
|
}
|
|
26076
26076
|
function serializeAttributes(attrs) {
|
|
26077
|
-
|
|
26078
|
-
for (const key in attrs) {
|
|
26079
|
-
const value = attrs[key];
|
|
26080
|
-
if (value === "") html += ` ${key}`;
|
|
26081
|
-
else html += ` ${key}="${value}"`;
|
|
26082
|
-
}
|
|
26083
|
-
return html;
|
|
26077
|
+
return Object.entries(attrs).map(([key, value]) => value === "" ? ` ${key}` : ` ${key}="${value}"`).join("");
|
|
26084
26078
|
}
|
|
26085
26079
|
function namedNodeMapToObject(namedNodeMap) {
|
|
26086
|
-
|
|
26087
|
-
for (
|
|
26080
|
+
const obj = {};
|
|
26081
|
+
for (const attr of Array.from(namedNodeMap)) {
|
|
26088
26082
|
obj[attr.name] = attr.value;
|
|
26089
26083
|
}
|
|
26090
26084
|
return obj;
|
|
26091
26085
|
}
|
|
26092
26086
|
var CustomVideoElement = CustomMediaMixin(globalThis.HTMLElement ?? class {
|
|
26093
|
-
}, {
|
|
26087
|
+
}, {
|
|
26088
|
+
tag: "video"
|
|
26089
|
+
});
|
|
26094
26090
|
var CustomAudioElement = CustomMediaMixin(globalThis.HTMLElement ?? class {
|
|
26095
|
-
}, {
|
|
26091
|
+
}, {
|
|
26092
|
+
tag: "audio"
|
|
26093
|
+
});
|
|
26096
26094
|
|
|
26097
26095
|
// shaka-video-element.js
|
|
26098
26096
|
var import_shaka_player = __toESM(require_shaka_player_compiled(), 1);
|
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": {
|