@mattebox/player-ads 0.0.0 → 1.1.0
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/LICENSE +21 -0
- package/README.md +36 -2
- package/dist/ad-info.d.ts +25 -0
- package/dist/ad-info.d.ts.map +1 -0
- package/dist/ad-info.js +80 -0
- package/dist/ad-info.js.map +1 -0
- package/dist/ad-link.d.ts +19 -0
- package/dist/ad-link.d.ts.map +1 -0
- package/dist/ad-link.js +51 -0
- package/dist/ad-link.js.map +1 -0
- package/dist/ad-progress.d.ts +18 -0
- package/dist/ad-progress.d.ts.map +1 -0
- package/dist/ad-progress.js +51 -0
- package/dist/ad-progress.js.map +1 -0
- package/dist/ad-skip-button.d.ts +21 -0
- package/dist/ad-skip-button.d.ts.map +1 -0
- package/dist/ad-skip-button.js +66 -0
- package/dist/ad-skip-button.js.map +1 -0
- package/dist/beacons.d.ts +29 -0
- package/dist/beacons.d.ts.map +1 -0
- package/dist/beacons.js +44 -0
- package/dist/beacons.js.map +1 -0
- package/dist/cdn/mattebox-player-ads.min.js +1 -0
- package/dist/component.d.ts +54 -0
- package/dist/component.d.ts.map +1 -0
- package/dist/component.js +95 -0
- package/dist/component.js.map +1 -0
- package/dist/controller.d.ts +200 -0
- package/dist/controller.d.ts.map +1 -0
- package/dist/controller.js +830 -0
- package/dist/controller.js.map +1 -0
- package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/asyncToGenerator.js +26 -0
- package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.js +11 -0
- package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js +24 -0
- package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
- package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.js +8 -0
- package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.js +10 -0
- package/dist/es2015/ad-info.js +79 -0
- package/dist/es2015/ad-link.js +53 -0
- package/dist/es2015/ad-progress.js +51 -0
- package/dist/es2015/ad-skip-button.js +68 -0
- package/dist/es2015/beacons.js +42 -0
- package/dist/es2015/component.js +94 -0
- package/dist/es2015/controller.js +854 -0
- package/dist/es2015/host.js +18 -0
- package/dist/es2015/index.js +72 -0
- package/dist/es2015/locales/ar.js +13 -0
- package/dist/es2015/locales/ca.js +13 -0
- package/dist/es2015/locales/de.js +13 -0
- package/dist/es2015/locales/es.js +13 -0
- package/dist/es2015/locales/fr.js +13 -0
- package/dist/es2015/locales/hi.js +13 -0
- package/dist/es2015/locales/it.js +13 -0
- package/dist/es2015/locales/ja.js +13 -0
- package/dist/es2015/locales/ko.js +13 -0
- package/dist/es2015/locales/pt.js +13 -0
- package/dist/es2015/locales/zh.js +13 -0
- package/dist/es2015/shared.js +26 -0
- package/dist/es2015/vast.js +255 -0
- package/dist/es2015/vmap.js +73 -0
- package/dist/host.d.ts +14 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +20 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +40 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +74 -0
- package/dist/index.js.map +1 -0
- package/dist/locales/ar.d.ts +13 -0
- package/dist/locales/ar.d.ts.map +1 -0
- package/dist/locales/ar.js +15 -0
- package/dist/locales/ar.js.map +1 -0
- package/dist/locales/ca.d.ts +13 -0
- package/dist/locales/ca.d.ts.map +1 -0
- package/dist/locales/ca.js +15 -0
- package/dist/locales/ca.js.map +1 -0
- package/dist/locales/de.d.ts +13 -0
- package/dist/locales/de.d.ts.map +1 -0
- package/dist/locales/de.js +15 -0
- package/dist/locales/de.js.map +1 -0
- package/dist/locales/es.d.ts +13 -0
- package/dist/locales/es.d.ts.map +1 -0
- package/dist/locales/es.js +15 -0
- package/dist/locales/es.js.map +1 -0
- package/dist/locales/fr.d.ts +13 -0
- package/dist/locales/fr.d.ts.map +1 -0
- package/dist/locales/fr.js +15 -0
- package/dist/locales/fr.js.map +1 -0
- package/dist/locales/hi.d.ts +13 -0
- package/dist/locales/hi.d.ts.map +1 -0
- package/dist/locales/hi.js +15 -0
- package/dist/locales/hi.js.map +1 -0
- package/dist/locales/it.d.ts +13 -0
- package/dist/locales/it.d.ts.map +1 -0
- package/dist/locales/it.js +15 -0
- package/dist/locales/it.js.map +1 -0
- package/dist/locales/ja.d.ts +13 -0
- package/dist/locales/ja.d.ts.map +1 -0
- package/dist/locales/ja.js +15 -0
- package/dist/locales/ja.js.map +1 -0
- package/dist/locales/ko.d.ts +13 -0
- package/dist/locales/ko.d.ts.map +1 -0
- package/dist/locales/ko.js +15 -0
- package/dist/locales/ko.js.map +1 -0
- package/dist/locales/pt.d.ts +13 -0
- package/dist/locales/pt.d.ts.map +1 -0
- package/dist/locales/pt.js +15 -0
- package/dist/locales/pt.js.map +1 -0
- package/dist/locales/zh.d.ts +13 -0
- package/dist/locales/zh.d.ts.map +1 -0
- package/dist/locales/zh.js +15 -0
- package/dist/locales/zh.js.map +1 -0
- package/dist/messages.d.ts +30 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/shared.d.ts +7 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +25 -0
- package/dist/shared.js.map +1 -0
- package/dist/vast.d.ts +94 -0
- package/dist/vast.d.ts.map +1 -0
- package/dist/vast.js +254 -0
- package/dist/vast.js.map +1 -0
- package/dist/vmap.d.ts +31 -0
- package/dist/vmap.d.ts.map +1 -0
- package/dist/vmap.js +71 -0
- package/dist/vmap.js.map +1 -0
- package/package.json +52 -6
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// src/host.ts
|
|
2
|
+
const PLAYER = "mattebox-player";
|
|
3
|
+
/** The parent, or the host of the shadow root `node` sits in, or null at the document. */
|
|
4
|
+
function above(node) {
|
|
5
|
+
const parent = node.parentNode;
|
|
6
|
+
if (parent !== null) return parent;
|
|
7
|
+
return node instanceof ShadowRoot ? node.host : null;
|
|
8
|
+
}
|
|
9
|
+
/** The nearest player above `node`, or null outside one. It may not be upgraded yet. */
|
|
10
|
+
function findPlayer(node) {
|
|
11
|
+
let current = node;
|
|
12
|
+
while (current !== null) {
|
|
13
|
+
if (current instanceof HTMLElement && current.localName === "mattebox-player") return current;
|
|
14
|
+
current = above(current);
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
export { PLAYER, findPlayer };
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { MbxAdInfo } from "./ad-info.js";
|
|
2
|
+
import { MbxAdLink } from "./ad-link.js";
|
|
3
|
+
import { MbxAdProgress } from "./ad-progress.js";
|
|
4
|
+
import { MbxAdSkipButton } from "./ad-skip-button.js";
|
|
5
|
+
import { controllerFor } from "./controller.js";
|
|
6
|
+
import { resolveVast } from "./vast.js";
|
|
7
|
+
import interstitials from "mattebox/stages/interstitials";
|
|
8
|
+
// src/index.ts
|
|
9
|
+
const AD_INFO = "mbx-ad-info";
|
|
10
|
+
const AD_SKIP_BUTTON = "mbx-ad-skip-button";
|
|
11
|
+
const AD_LINK = "mbx-ad-link";
|
|
12
|
+
const AD_PROGRESS = "mbx-ad-progress";
|
|
13
|
+
/**
|
|
14
|
+
* While an ad plays the player carries `ad`: the seek bar, the times, the
|
|
15
|
+
* menus and the programme's title would describe what does not play. Play,
|
|
16
|
+
* pause, volume and fullscreen stay, and drive the ad. Plain selectors, not
|
|
17
|
+
* `:is()`, which a 2021 TV lacks.
|
|
18
|
+
*/
|
|
19
|
+
const DURING_AD = [
|
|
20
|
+
"mbx-seek-bar",
|
|
21
|
+
"mbx-current-time",
|
|
22
|
+
"mbx-duration",
|
|
23
|
+
"mbx-remaining-time",
|
|
24
|
+
"mbx-chapters-menu",
|
|
25
|
+
"mbx-marker-button",
|
|
26
|
+
"mbx-quality-menu",
|
|
27
|
+
"mbx-audio-menu",
|
|
28
|
+
"mbx-subtitles-menu",
|
|
29
|
+
"mbx-video-menu",
|
|
30
|
+
"mbx-speed-menu",
|
|
31
|
+
"mbx-live-button",
|
|
32
|
+
"mbx-scan-button",
|
|
33
|
+
"mbx-skip-button",
|
|
34
|
+
"mbx-title",
|
|
35
|
+
"mbx-up-next"
|
|
36
|
+
];
|
|
37
|
+
const AD_ELEMENTS = [
|
|
38
|
+
"mbx-ad-info",
|
|
39
|
+
"mbx-ad-skip-button",
|
|
40
|
+
"mbx-ad-link",
|
|
41
|
+
"mbx-ad-progress"
|
|
42
|
+
];
|
|
43
|
+
const HIDDEN = `${[...DURING_AD.map((name) => `mattebox-player[ad]:not([ad="stitched"]):not([scrubbing]) ${name}`), ...AD_ELEMENTS.map((name) => `mattebox-player:not([ad]) ${name}`)].join(",")}{display:none}`;
|
|
44
|
+
function addStyle() {
|
|
45
|
+
if (document.getElementById("mbx-ads-style") !== null) return;
|
|
46
|
+
const node = document.createElement("style");
|
|
47
|
+
node.id = "mbx-ads-style";
|
|
48
|
+
node.textContent = HIDDEN;
|
|
49
|
+
document.head.append(node);
|
|
50
|
+
}
|
|
51
|
+
/** The add-on: pass it in `addons`. */
|
|
52
|
+
function ads(options = {}) {
|
|
53
|
+
return {
|
|
54
|
+
name: "ads",
|
|
55
|
+
stages: () => [interstitials()],
|
|
56
|
+
engine: true,
|
|
57
|
+
attach(player) {
|
|
58
|
+
addStyle();
|
|
59
|
+
return controllerFor(player, options).attach();
|
|
60
|
+
},
|
|
61
|
+
remoteData: (player) => controllerFor(player).remoteData()
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
/** The ads of `player`: its schedule, the ad that plays, skip and click. */
|
|
65
|
+
function adsOf(player) {
|
|
66
|
+
return controllerFor(player);
|
|
67
|
+
}
|
|
68
|
+
if (customElements.get("mbx-ad-info") === void 0) customElements.define(AD_INFO, MbxAdInfo);
|
|
69
|
+
if (customElements.get("mbx-ad-skip-button") === void 0) customElements.define(AD_SKIP_BUTTON, MbxAdSkipButton);
|
|
70
|
+
if (customElements.get("mbx-ad-link") === void 0) customElements.define(AD_LINK, MbxAdLink);
|
|
71
|
+
if (customElements.get("mbx-ad-progress") === void 0) customElements.define(AD_PROGRESS, MbxAdProgress);
|
|
72
|
+
export { AD_INFO, AD_LINK, AD_PROGRESS, AD_SKIP_BUTTON, MbxAdInfo, MbxAdLink, MbxAdProgress, MbxAdSkipButton, ads, adsOf, resolveVast };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/ar.ts
|
|
2
|
+
var ar_default = {
|
|
3
|
+
adLabel: "إعلان",
|
|
4
|
+
adCount: "إعلان {index} من {total}",
|
|
5
|
+
adSkip: "تخطي الإعلان",
|
|
6
|
+
adSkipIn: "تخطٍّ بعد {seconds}",
|
|
7
|
+
adLearnMore: "اعرف المزيد",
|
|
8
|
+
adBreak: "فاصل إعلاني، {seconds} ثانية",
|
|
9
|
+
adPromo: "ترويج",
|
|
10
|
+
adPromoCount: "ترويج {index} من {total}",
|
|
11
|
+
adSkipPromo: "تخطي الترويج"
|
|
12
|
+
};
|
|
13
|
+
export { ar_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/ca.ts
|
|
2
|
+
var ca_default = {
|
|
3
|
+
adLabel: "Anunci",
|
|
4
|
+
adCount: "Anunci {index} de {total}",
|
|
5
|
+
adSkip: "Omet l'anunci",
|
|
6
|
+
adSkipIn: "Omet en {seconds}",
|
|
7
|
+
adLearnMore: "Més informació",
|
|
8
|
+
adBreak: "Pausa publicitària, {seconds} segons",
|
|
9
|
+
adPromo: "Promoció",
|
|
10
|
+
adPromoCount: "Promoció {index} de {total}",
|
|
11
|
+
adSkipPromo: "Omet la promoció"
|
|
12
|
+
};
|
|
13
|
+
export { ca_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/de.ts
|
|
2
|
+
var de_default = {
|
|
3
|
+
adLabel: "Werbung",
|
|
4
|
+
adCount: "Werbung {index} von {total}",
|
|
5
|
+
adSkip: "Werbung überspringen",
|
|
6
|
+
adSkipIn: "Überspringen in {seconds}",
|
|
7
|
+
adLearnMore: "Mehr erfahren",
|
|
8
|
+
adBreak: "Werbepause, {seconds} Sekunden",
|
|
9
|
+
adPromo: "Promo",
|
|
10
|
+
adPromoCount: "Promo {index} von {total}",
|
|
11
|
+
adSkipPromo: "Promo überspringen"
|
|
12
|
+
};
|
|
13
|
+
export { de_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/es.ts
|
|
2
|
+
var es_default = {
|
|
3
|
+
adLabel: "Anuncio",
|
|
4
|
+
adCount: "Anuncio {index} de {total}",
|
|
5
|
+
adSkip: "Omitir anuncio",
|
|
6
|
+
adSkipIn: "Omitir en {seconds}",
|
|
7
|
+
adLearnMore: "Más información",
|
|
8
|
+
adBreak: "Pausa publicitaria, {seconds} segundos",
|
|
9
|
+
adPromo: "Promoción",
|
|
10
|
+
adPromoCount: "Promoción {index} de {total}",
|
|
11
|
+
adSkipPromo: "Omitir promoción"
|
|
12
|
+
};
|
|
13
|
+
export { es_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/fr.ts
|
|
2
|
+
var fr_default = {
|
|
3
|
+
adLabel: "Publicité",
|
|
4
|
+
adCount: "Publicité {index} sur {total}",
|
|
5
|
+
adSkip: "Passer la publicité",
|
|
6
|
+
adSkipIn: "Passer dans {seconds}",
|
|
7
|
+
adLearnMore: "En savoir plus",
|
|
8
|
+
adBreak: "Pause publicitaire, {seconds} secondes",
|
|
9
|
+
adPromo: "Promo",
|
|
10
|
+
adPromoCount: "Promo {index} sur {total}",
|
|
11
|
+
adSkipPromo: "Passer la promo"
|
|
12
|
+
};
|
|
13
|
+
export { fr_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/hi.ts
|
|
2
|
+
var hi_default = {
|
|
3
|
+
adLabel: "विज्ञापन",
|
|
4
|
+
adCount: "विज्ञापन {index} / {total}",
|
|
5
|
+
adSkip: "विज्ञापन छोड़ें",
|
|
6
|
+
adSkipIn: "{seconds} में छोड़ें",
|
|
7
|
+
adLearnMore: "और जानें",
|
|
8
|
+
adBreak: "विज्ञापन ब्रेक, {seconds} सेकंड",
|
|
9
|
+
adPromo: "प्रोमो",
|
|
10
|
+
adPromoCount: "प्रोमो {index} / {total}",
|
|
11
|
+
adSkipPromo: "प्रोमो छोड़ें"
|
|
12
|
+
};
|
|
13
|
+
export { hi_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/it.ts
|
|
2
|
+
var it_default = {
|
|
3
|
+
adLabel: "Annuncio",
|
|
4
|
+
adCount: "Annuncio {index} di {total}",
|
|
5
|
+
adSkip: "Salta annuncio",
|
|
6
|
+
adSkipIn: "Salta tra {seconds}",
|
|
7
|
+
adLearnMore: "Scopri di più",
|
|
8
|
+
adBreak: "Pausa pubblicitaria, {seconds} secondi",
|
|
9
|
+
adPromo: "Promo",
|
|
10
|
+
adPromoCount: "Promo {index} di {total}",
|
|
11
|
+
adSkipPromo: "Salta promo"
|
|
12
|
+
};
|
|
13
|
+
export { it_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/ja.ts
|
|
2
|
+
var ja_default = {
|
|
3
|
+
adLabel: "広告",
|
|
4
|
+
adCount: "広告 {index}/{total}",
|
|
5
|
+
adSkip: "広告をスキップ",
|
|
6
|
+
adSkipIn: "{seconds} 秒後にスキップ",
|
|
7
|
+
adLearnMore: "詳細",
|
|
8
|
+
adBreak: "広告、{seconds} 秒",
|
|
9
|
+
adPromo: "プロモーション",
|
|
10
|
+
adPromoCount: "プロモーション {index}/{total}",
|
|
11
|
+
adSkipPromo: "プロモーションをスキップ"
|
|
12
|
+
};
|
|
13
|
+
export { ja_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/ko.ts
|
|
2
|
+
var ko_default = {
|
|
3
|
+
adLabel: "광고",
|
|
4
|
+
adCount: "광고 {index}/{total}",
|
|
5
|
+
adSkip: "광고 건너뛰기",
|
|
6
|
+
adSkipIn: "{seconds}초 후 건너뛰기",
|
|
7
|
+
adLearnMore: "자세히 알아보기",
|
|
8
|
+
adBreak: "광고 시간, {seconds}초",
|
|
9
|
+
adPromo: "프로모션",
|
|
10
|
+
adPromoCount: "프로모션 {index}/{total}",
|
|
11
|
+
adSkipPromo: "프로모션 건너뛰기"
|
|
12
|
+
};
|
|
13
|
+
export { ko_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/pt.ts
|
|
2
|
+
var pt_default = {
|
|
3
|
+
adLabel: "Anúncio",
|
|
4
|
+
adCount: "Anúncio {index} de {total}",
|
|
5
|
+
adSkip: "Pular anúncio",
|
|
6
|
+
adSkipIn: "Pular em {seconds}",
|
|
7
|
+
adLearnMore: "Saiba mais",
|
|
8
|
+
adBreak: "Intervalo comercial, {seconds} segundos",
|
|
9
|
+
adPromo: "Promoção",
|
|
10
|
+
adPromoCount: "Promoção {index} de {total}",
|
|
11
|
+
adSkipPromo: "Pular promoção"
|
|
12
|
+
};
|
|
13
|
+
export { pt_default as default };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/locales/zh.ts
|
|
2
|
+
var zh_default = {
|
|
3
|
+
adLabel: "广告",
|
|
4
|
+
adCount: "广告 {index}/{total}",
|
|
5
|
+
adSkip: "跳过广告",
|
|
6
|
+
adSkipIn: "{seconds} 秒后可跳过",
|
|
7
|
+
adLearnMore: "了解详情",
|
|
8
|
+
adBreak: "广告时间,{seconds} 秒",
|
|
9
|
+
adPromo: "推广",
|
|
10
|
+
adPromoCount: "推广 {index}/{total}",
|
|
11
|
+
adSkipPromo: "跳过推广"
|
|
12
|
+
};
|
|
13
|
+
export { zh_default as default };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// src/shared.ts
|
|
2
|
+
/**
|
|
3
|
+
* What the ad elements share: their style, the text of a template, and the
|
|
4
|
+
* time of the ad. The tokens come through the `--mbx-*` custom properties
|
|
5
|
+
* the player sets, which inherit into every control.
|
|
6
|
+
*/
|
|
7
|
+
const AD_CSS = ":host{z-index:2;color:var(--mbx-text);font:500 .875em / 1.2 var(--mbx-font);display:inline-flex;position:absolute}:host([hidden]){display:none}[part~=panel]{border-radius:var(--mbx-radius);backdrop-filter:blur(12px);background:#1c1c20b8;flex-direction:column;display:inline-flex;overflow:hidden}[part~=row]{white-space:nowrap;align-items:center;height:2.25em;padding:0 .85em;font-weight:600;display:inline-flex}[part~=time]{color:#d6d0c6;font-variant-numeric:tabular-nums;margin-inline-start:.4em;font-weight:500}[part~=line]{background:#ffffff2e;height:3px}[part~=line][hidden]{display:none}[part~=line-fill]{background:var(--mbx-ad,#f5c518);height:3px}[part~=button]{border-radius:var(--mbx-radius);backdrop-filter:blur(12px);height:2.75em;color:inherit;font:inherit;white-space:nowrap;cursor:pointer;background:#1c1c20b8;border:0;align-items:center;padding:0 .85em 0 1.1em;font-size:1.07em;font-weight:600;display:inline-flex}[part~=button]:hover:not(:disabled){background:#1c1c20e6}[part~=button]:disabled{cursor:default;color:#d6d0c6;padding-inline-end:1.1em}[part~=button]:focus{outline:2px solid var(--mbx-accent);outline-offset:2px}[part~=button]:focus:not(:focus-visible){outline:none}[part~=chevron]{width:1.25em;height:1.25em;margin-inline-start:.3em}[part~=chevron][hidden]{display:none}[part~=icon-button]{width:2.75em;height:2.75em;color:inherit;cursor:pointer;background:0 0;border:0;justify-content:center;align-items:center;padding:0;display:inline-flex}[part~=disc]{backdrop-filter:blur(12px);background:#1c1c20b8;border-radius:50%;justify-content:center;align-items:center;width:2.25em;height:2.25em;display:inline-flex}[part~=icon-button]:hover [part~=disc]{background:#1c1c20e6}[part~=icon-button]:focus{outline:2px solid var(--mbx-accent);outline-offset:-2px;border-radius:50%}[part~=icon-button]:focus:not(:focus-visible){outline:none}[part~=icon],::slotted([slot=icon]){fill:currentColor;width:1.5em;height:1.5em}[part~=live]{clip:rect(0 0 0 0);white-space:nowrap;width:1px;height:1px;position:absolute;overflow:hidden}";
|
|
8
|
+
/** A `<style>` with the ad elements' style and the element's own placement. */
|
|
9
|
+
function style(placement) {
|
|
10
|
+
const node = document.createElement("style");
|
|
11
|
+
node.textContent = `${AD_CSS}:host{${placement}}`;
|
|
12
|
+
return node;
|
|
13
|
+
}
|
|
14
|
+
/** `text` with each `{name}` replaced by its value. */
|
|
15
|
+
function fill(text, values) {
|
|
16
|
+
return text.replace(/\{(\w+)\}/g, (match, name) => {
|
|
17
|
+
var _values$name;
|
|
18
|
+
return String((_values$name = values[name]) !== null && _values$name !== void 0 ? _values$name : match);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/** `m:ss`, the time an ad counts down in. */
|
|
22
|
+
function clock(seconds) {
|
|
23
|
+
const whole = Math.max(0, Math.ceil(seconds));
|
|
24
|
+
return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, "0")}`;
|
|
25
|
+
}
|
|
26
|
+
export { clock, fill, style };
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import _objectSpread2 from "./_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js";
|
|
2
|
+
import _asyncToGenerator from "./_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/asyncToGenerator.js";
|
|
3
|
+
/** Milliseconds a VAST request may take before error 301. */
|
|
4
|
+
const TIMEOUT = 5e3;
|
|
5
|
+
const children = (parent, name) => Array.from(parent.children).filter((child) => child.localName === name);
|
|
6
|
+
const child = (parent, name) => children(parent, name)[0];
|
|
7
|
+
const text = (element) => {
|
|
8
|
+
var _element$textContent;
|
|
9
|
+
const value = element === null || element === void 0 || (_element$textContent = element.textContent) === null || _element$textContent === void 0 ? void 0 : _element$textContent.trim();
|
|
10
|
+
return value === void 0 || value === "" ? void 0 : value;
|
|
11
|
+
};
|
|
12
|
+
const texts = (parent, name) => parent === void 0 ? [] : children(parent, name).flatMap((e) => {
|
|
13
|
+
var _text;
|
|
14
|
+
return (_text = text(e)) !== null && _text !== void 0 ? _text : [];
|
|
15
|
+
});
|
|
16
|
+
const numberOf = (element, name) => {
|
|
17
|
+
const value = Number(element.getAttribute(name));
|
|
18
|
+
return element.hasAttribute(name) && Number.isFinite(value) ? value : void 0;
|
|
19
|
+
};
|
|
20
|
+
/** Seconds of `HH:MM:SS` or `HH:MM:SS.mmm`, or undefined. */
|
|
21
|
+
function clock(value) {
|
|
22
|
+
var _value$trim;
|
|
23
|
+
const match = /^(\d+):(\d{2}):(\d{2}(?:\.\d+)?)$/.exec((_value$trim = value === null || value === void 0 ? void 0 : value.trim()) !== null && _value$trim !== void 0 ? _value$trim : "");
|
|
24
|
+
if (match === null) return void 0;
|
|
25
|
+
return Number(match[1]) * 3600 + Number(match[2]) * 60 + Number(match[3]);
|
|
26
|
+
}
|
|
27
|
+
/** Seconds of an offset: a clock time, or a percentage of `duration`. */
|
|
28
|
+
function offsetOf(value, duration) {
|
|
29
|
+
var _value$trim2;
|
|
30
|
+
const trimmed = (_value$trim2 = value === null || value === void 0 ? void 0 : value.trim()) !== null && _value$trim2 !== void 0 ? _value$trim2 : "";
|
|
31
|
+
if (trimmed.endsWith("%")) {
|
|
32
|
+
const percent = Number(trimmed.slice(0, -1));
|
|
33
|
+
return Number.isFinite(percent) ? duration * percent / 100 : void 0;
|
|
34
|
+
}
|
|
35
|
+
return clock(trimmed);
|
|
36
|
+
}
|
|
37
|
+
function layerOf(ad, body) {
|
|
38
|
+
var _child2;
|
|
39
|
+
const creatives = child(body, "Creatives");
|
|
40
|
+
const linears = creatives === void 0 ? [] : children(creatives, "Creative").flatMap((c) => children(c, "Linear"));
|
|
41
|
+
const tracking = [];
|
|
42
|
+
const clickTracking = [];
|
|
43
|
+
for (const linear of linears) {
|
|
44
|
+
var _clock, _child;
|
|
45
|
+
const duration = (_clock = clock(text(child(linear, "Duration")))) !== null && _clock !== void 0 ? _clock : 0;
|
|
46
|
+
for (const entry of children((_child = child(linear, "TrackingEvents")) !== null && _child !== void 0 ? _child : linear, "Tracking")) {
|
|
47
|
+
const url = text(entry);
|
|
48
|
+
const event = entry.getAttribute("event");
|
|
49
|
+
if (url === void 0 || event === null) continue;
|
|
50
|
+
const offset = event === "progress" ? offsetOf(entry.getAttribute("offset"), duration) : void 0;
|
|
51
|
+
tracking.push(_objectSpread2({
|
|
52
|
+
event,
|
|
53
|
+
url
|
|
54
|
+
}, offset !== void 0 ? { offset } : {}));
|
|
55
|
+
}
|
|
56
|
+
clickTracking.push(...texts(child(linear, "VideoClicks"), "ClickTracking"));
|
|
57
|
+
}
|
|
58
|
+
const viewable = child(body, "ViewableImpression");
|
|
59
|
+
const verifications = (_child2 = child(body, "AdVerifications")) !== null && _child2 !== void 0 ? _child2 : child(ad, "AdVerifications");
|
|
60
|
+
return {
|
|
61
|
+
impressions: texts(body, "Impression"),
|
|
62
|
+
errors: texts(body, "Error"),
|
|
63
|
+
tracking,
|
|
64
|
+
clickTracking,
|
|
65
|
+
viewable: texts(viewable, "Viewable"),
|
|
66
|
+
notViewable: texts(viewable, "NotViewable"),
|
|
67
|
+
verifications: verifications === void 0 ? [] : children(verifications, "Verification").map((v) => {
|
|
68
|
+
const vendor = v.getAttribute("vendor");
|
|
69
|
+
const script = text(child(v, "JavaScriptResource"));
|
|
70
|
+
const parameters = text(child(v, "VerificationParameters"));
|
|
71
|
+
return _objectSpread2(_objectSpread2(_objectSpread2({}, vendor !== null ? { vendor } : {}), script !== void 0 ? { script } : {}), parameters !== void 0 ? { parameters } : {});
|
|
72
|
+
})
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function companionsOf(body) {
|
|
76
|
+
const out = [];
|
|
77
|
+
const creatives = child(body, "Creatives");
|
|
78
|
+
for (const creative of creatives === void 0 ? [] : children(creatives, "Creative")) {
|
|
79
|
+
const set = child(creative, "CompanionAds");
|
|
80
|
+
for (const companion of set === void 0 ? [] : children(set, "Companion")) {
|
|
81
|
+
const width = numberOf(companion, "width");
|
|
82
|
+
const height = numberOf(companion, "height");
|
|
83
|
+
const found = [
|
|
84
|
+
["static", "StaticResource"],
|
|
85
|
+
["iframe", "IFrameResource"],
|
|
86
|
+
["html", "HTMLResource"]
|
|
87
|
+
].find(([, name]) => child(companion, name) !== void 0);
|
|
88
|
+
const resource = found === void 0 ? void 0 : text(child(companion, found[1]));
|
|
89
|
+
const clickThrough = text(child(companion, "CompanionClickThrough"));
|
|
90
|
+
out.push(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, width !== void 0 ? { width } : {}), height !== void 0 ? { height } : {}), resource !== void 0 && found !== void 0 ? {
|
|
91
|
+
resource,
|
|
92
|
+
kind: found[0]
|
|
93
|
+
} : {}), clickThrough !== void 0 ? { clickThrough } : {}));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return out;
|
|
97
|
+
}
|
|
98
|
+
/** The ad of an `<InLine>`, without what wrappers add, or null without a linear creative. */
|
|
99
|
+
function inlineAd(ad, inline) {
|
|
100
|
+
var _clock2, _child3;
|
|
101
|
+
const creatives = child(inline, "Creatives");
|
|
102
|
+
const linear = (creatives === void 0 ? [] : children(creatives, "Creative")).flatMap((c) => children(c, "Linear"))[0];
|
|
103
|
+
if (linear === void 0) return null;
|
|
104
|
+
const duration = (_clock2 = clock(text(child(linear, "Duration")))) !== null && _clock2 !== void 0 ? _clock2 : 0;
|
|
105
|
+
const skipOffset = offsetOf(linear.getAttribute("skipoffset"), duration);
|
|
106
|
+
const files = child(linear, "MediaFiles");
|
|
107
|
+
const mediaFiles = (files === void 0 ? [] : children(files, "MediaFile")).flatMap((file) => {
|
|
108
|
+
var _file$getAttribute;
|
|
109
|
+
const url = text(file);
|
|
110
|
+
if (url === void 0) return [];
|
|
111
|
+
const width = numberOf(file, "width");
|
|
112
|
+
const height = numberOf(file, "height");
|
|
113
|
+
const bitrate = numberOf(file, "bitrate");
|
|
114
|
+
const api = file.getAttribute("apiFramework");
|
|
115
|
+
return [_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
|
|
116
|
+
url,
|
|
117
|
+
type: (_file$getAttribute = file.getAttribute("type")) !== null && _file$getAttribute !== void 0 ? _file$getAttribute : "",
|
|
118
|
+
delivery: file.getAttribute("delivery") === "streaming" ? "streaming" : "progressive"
|
|
119
|
+
}, width !== void 0 ? { width } : {}), height !== void 0 ? { height } : {}), bitrate !== void 0 ? { bitrate } : {}), api !== null ? { apiFramework: api } : {})];
|
|
120
|
+
});
|
|
121
|
+
const layer = layerOf(ad, inline);
|
|
122
|
+
const id = ad.getAttribute("id");
|
|
123
|
+
const sequence = numberOf(ad, "sequence");
|
|
124
|
+
const system = text(child(inline, "AdSystem"));
|
|
125
|
+
const title = text(child(inline, "AdTitle"));
|
|
126
|
+
const clickThrough = text(child((_child3 = child(linear, "VideoClicks")) !== null && _child3 !== void 0 ? _child3 : linear, "ClickThrough"));
|
|
127
|
+
const extensions = child(inline, "Extensions");
|
|
128
|
+
return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({}, id !== null ? { id } : {}), sequence !== void 0 ? { sequence } : {}), system !== void 0 ? { system } : {}), title !== void 0 ? { title } : {}), {}, { duration }, skipOffset !== void 0 ? { skipOffset } : {}), layer), {}, { mediaFiles }, clickThrough !== void 0 ? { clickThrough } : {}), {}, {
|
|
129
|
+
companions: companionsOf(inline),
|
|
130
|
+
extensions: extensions === void 0 ? [] : children(extensions, "Extension").map((e) => new XMLSerializer().serializeToString(e))
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/** Adds a wrapper's beacons to an ad it led to. */
|
|
134
|
+
function merged(ad, layer) {
|
|
135
|
+
return _objectSpread2(_objectSpread2({}, ad), {}, {
|
|
136
|
+
impressions: [...layer.impressions, ...ad.impressions],
|
|
137
|
+
errors: [...layer.errors, ...ad.errors],
|
|
138
|
+
tracking: [...layer.tracking, ...ad.tracking],
|
|
139
|
+
clickTracking: [...layer.clickTracking, ...ad.clickTracking],
|
|
140
|
+
viewable: [...layer.viewable, ...ad.viewable],
|
|
141
|
+
notViewable: [...layer.notViewable, ...ad.notViewable],
|
|
142
|
+
verifications: [...layer.verifications, ...ad.verifications]
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
const fetchText = function() {
|
|
146
|
+
var _ref = _asyncToGenerator(function* (url, signal) {
|
|
147
|
+
const response = yield fetch(url, {
|
|
148
|
+
credentials: "include",
|
|
149
|
+
signal
|
|
150
|
+
});
|
|
151
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
152
|
+
return response.text();
|
|
153
|
+
});
|
|
154
|
+
return function fetchText(_x, _x2) {
|
|
155
|
+
return _ref.apply(this, arguments);
|
|
156
|
+
};
|
|
157
|
+
}();
|
|
158
|
+
/**
|
|
159
|
+
* The ads a VAST document leads to. A pod (ads with a `sequence`) plays in
|
|
160
|
+
* order; without one, the first standalone ad plays. Wrappers are followed
|
|
161
|
+
* up to `WRAPPER_LIMIT` deep.
|
|
162
|
+
*/
|
|
163
|
+
function resolveVast(_x3) {
|
|
164
|
+
return _resolveVast.apply(this, arguments);
|
|
165
|
+
}
|
|
166
|
+
function _resolveVast() {
|
|
167
|
+
_resolveVast = _asyncToGenerator(function* (source, load = fetchText, depth = 0, wrappers = true) {
|
|
168
|
+
var _code;
|
|
169
|
+
let xml;
|
|
170
|
+
if ("xml" in source) xml = source.xml;
|
|
171
|
+
else {
|
|
172
|
+
const controller = new AbortController();
|
|
173
|
+
const timer = setTimeout(() => controller.abort(), TIMEOUT);
|
|
174
|
+
try {
|
|
175
|
+
xml = yield load(source.url, controller.signal);
|
|
176
|
+
} catch (_unused) {
|
|
177
|
+
return {
|
|
178
|
+
ads: [],
|
|
179
|
+
errors: [],
|
|
180
|
+
code: depth > 0 ? 301 : 900
|
|
181
|
+
};
|
|
182
|
+
} finally {
|
|
183
|
+
clearTimeout(timer);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const doc = new DOMParser().parseFromString(xml, "application/xml");
|
|
187
|
+
const root = doc.documentElement;
|
|
188
|
+
if (root === null || root.localName !== "VAST" || doc.getElementsByTagName("parsererror").length > 0) return {
|
|
189
|
+
ads: [],
|
|
190
|
+
errors: [],
|
|
191
|
+
code: 100
|
|
192
|
+
};
|
|
193
|
+
const nodes = children(root, "Ad");
|
|
194
|
+
if (nodes.length === 0) return {
|
|
195
|
+
ads: [],
|
|
196
|
+
errors: texts(root, "Error"),
|
|
197
|
+
code: 303
|
|
198
|
+
};
|
|
199
|
+
const pod = nodes.filter((ad) => ad.hasAttribute("sequence"));
|
|
200
|
+
const chosen = pod.length > 0 ? pod.sort((a, b) => {
|
|
201
|
+
var _numberOf, _numberOf2;
|
|
202
|
+
return ((_numberOf = numberOf(a, "sequence")) !== null && _numberOf !== void 0 ? _numberOf : 0) - ((_numberOf2 = numberOf(b, "sequence")) !== null && _numberOf2 !== void 0 ? _numberOf2 : 0);
|
|
203
|
+
}) : nodes.slice(0, 1);
|
|
204
|
+
const ads = [];
|
|
205
|
+
const errors = [];
|
|
206
|
+
let code;
|
|
207
|
+
for (const ad of chosen) {
|
|
208
|
+
const inline = child(ad, "InLine");
|
|
209
|
+
if (inline !== void 0) {
|
|
210
|
+
const found = inlineAd(ad, inline);
|
|
211
|
+
if (found === null) code = 201;
|
|
212
|
+
else ads.push(found);
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const wrapper = child(ad, "Wrapper");
|
|
216
|
+
const next = text(wrapper === void 0 ? void 0 : child(wrapper, "VASTAdTagURI"));
|
|
217
|
+
if (wrapper === void 0 || next === void 0) {
|
|
218
|
+
code = 300;
|
|
219
|
+
continue;
|
|
220
|
+
}
|
|
221
|
+
const layer = layerOf(ad, wrapper);
|
|
222
|
+
if (depth + 1 > 5 || !wrappers) {
|
|
223
|
+
errors.push(...layer.errors);
|
|
224
|
+
code = 302;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
const base = "xml" in source ? location.href : source.url;
|
|
228
|
+
const follow = wrapper.getAttribute("followAdditionalWrappers") !== "false";
|
|
229
|
+
const result = yield resolveVast({ url: new URL(next, base).href }, load, depth + 1, follow);
|
|
230
|
+
if (result.ads.length === 0) {
|
|
231
|
+
var _result$code;
|
|
232
|
+
errors.push(...layer.errors, ...result.errors);
|
|
233
|
+
code = (_result$code = result.code) !== null && _result$code !== void 0 ? _result$code : 303;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
const single = wrapper.getAttribute("allowMultipleAds") === "false";
|
|
237
|
+
ads.push(...(single ? result.ads.slice(0, 1) : result.ads).map((found) => merged(found, layer)));
|
|
238
|
+
}
|
|
239
|
+
if (ads.length === 0 && pod.length > 0) {
|
|
240
|
+
const standalone = nodes.filter((ad) => !ad.hasAttribute("sequence"))[0];
|
|
241
|
+
const inline = standalone === void 0 ? void 0 : child(standalone, "InLine");
|
|
242
|
+
const found = standalone === void 0 || inline === void 0 ? null : inlineAd(standalone, inline);
|
|
243
|
+
if (found !== null) return {
|
|
244
|
+
ads: [found],
|
|
245
|
+
errors: []
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return _objectSpread2({
|
|
249
|
+
ads,
|
|
250
|
+
errors
|
|
251
|
+
}, ads.length === 0 ? { code: (_code = code) !== null && _code !== void 0 ? _code : 303 } : {});
|
|
252
|
+
});
|
|
253
|
+
return _resolveVast.apply(this, arguments);
|
|
254
|
+
}
|
|
255
|
+
export { TIMEOUT, clock, fetchText, offsetOf, resolveVast };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { clock } from "./vast.js";
|
|
2
|
+
// src/vmap.ts
|
|
3
|
+
/**
|
|
4
|
+
* VMAP 1.0.1, the IAB's Video Multiple Ad Playlist: when the breaks of a
|
|
5
|
+
* programme go, and which VAST each one asks for. Only linear breaks are
|
|
6
|
+
* read; a nonlinear or display break is left out.
|
|
7
|
+
*/
|
|
8
|
+
/** The offset of `timeOffset` (VMAP 1.0.1 §2.4). */
|
|
9
|
+
function breakOffset(value) {
|
|
10
|
+
var _value$trim;
|
|
11
|
+
const trimmed = (_value$trim = value === null || value === void 0 ? void 0 : value.trim()) !== null && _value$trim !== void 0 ? _value$trim : "";
|
|
12
|
+
if (trimmed === "start" || trimmed === "end") return trimmed;
|
|
13
|
+
if (trimmed.endsWith("%")) {
|
|
14
|
+
const percent = Number(trimmed.slice(0, -1));
|
|
15
|
+
return Number.isFinite(percent) ? { percent } : null;
|
|
16
|
+
}
|
|
17
|
+
if (trimmed.startsWith("#")) {
|
|
18
|
+
const position = Number(trimmed.slice(1));
|
|
19
|
+
return Number.isInteger(position) ? { position } : null;
|
|
20
|
+
}
|
|
21
|
+
const time = clock(trimmed);
|
|
22
|
+
return time === void 0 ? null : { time };
|
|
23
|
+
}
|
|
24
|
+
/** The breaks of a VMAP document, in document order, or null when the text is not VMAP. */
|
|
25
|
+
function parseVmap(xml, base) {
|
|
26
|
+
const root = new DOMParser().parseFromString(xml, "application/xml").documentElement;
|
|
27
|
+
if (root === null || root.localName !== "VMAP") return null;
|
|
28
|
+
const out = [];
|
|
29
|
+
let index = 0;
|
|
30
|
+
for (const entry of Array.from(root.children).filter((e) => e.localName === "AdBreak")) {
|
|
31
|
+
var _entry$getAttribute, _tag$textContent, _entry$getAttribute2;
|
|
32
|
+
index += 1;
|
|
33
|
+
const types = ((_entry$getAttribute = entry.getAttribute("breakType")) !== null && _entry$getAttribute !== void 0 ? _entry$getAttribute : "linear").split(",");
|
|
34
|
+
const offset = breakOffset(entry.getAttribute("timeOffset"));
|
|
35
|
+
if (!types.includes("linear") || offset === null) continue;
|
|
36
|
+
const source = Array.from(entry.children).find((e) => e.localName === "AdSource");
|
|
37
|
+
const tag = source === void 0 ? void 0 : Array.from(source.children).find((e) => e.localName === "AdTagURI");
|
|
38
|
+
const data = source === void 0 ? void 0 : Array.from(source.children).find((e) => e.localName === "VASTAdData");
|
|
39
|
+
const vastElement = data === void 0 ? void 0 : Array.from(data.children).find((e) => e.localName === "VAST");
|
|
40
|
+
const url = tag === null || tag === void 0 || (_tag$textContent = tag.textContent) === null || _tag$textContent === void 0 ? void 0 : _tag$textContent.trim();
|
|
41
|
+
let vast = null;
|
|
42
|
+
if (url !== void 0 && url !== "") vast = { url: new URL(url, base).href };
|
|
43
|
+
else if (vastElement !== void 0) vast = { xml: new XMLSerializer().serializeToString(vastElement) };
|
|
44
|
+
if (vast === null) continue;
|
|
45
|
+
const events = Array.from(entry.children).find((e) => e.localName === "TrackingEvents");
|
|
46
|
+
const tracking = (events === void 0 ? [] : Array.from(events.children)).flatMap((e) => {
|
|
47
|
+
var _e$textContent;
|
|
48
|
+
const event = e.getAttribute("event");
|
|
49
|
+
const target = (_e$textContent = e.textContent) === null || _e$textContent === void 0 ? void 0 : _e$textContent.trim();
|
|
50
|
+
return event === null || target === void 0 || target === "" ? [] : [{
|
|
51
|
+
event,
|
|
52
|
+
url: target
|
|
53
|
+
}];
|
|
54
|
+
});
|
|
55
|
+
out.push({
|
|
56
|
+
id: (_entry$getAttribute2 = entry.getAttribute("breakId")) !== null && _entry$getAttribute2 !== void 0 ? _entry$getAttribute2 : `break-${index}`,
|
|
57
|
+
offset,
|
|
58
|
+
vast,
|
|
59
|
+
tracking
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return out;
|
|
63
|
+
}
|
|
64
|
+
/** The programme time of an offset, or null when it needs what is not known yet. */
|
|
65
|
+
function offsetTime(offset, duration, chapters = []) {
|
|
66
|
+
var _chapters;
|
|
67
|
+
if (offset === "start") return 0;
|
|
68
|
+
if (offset === "end") return Number.isFinite(duration) ? duration : null;
|
|
69
|
+
if ("time" in offset) return offset.time;
|
|
70
|
+
if ("percent" in offset) return Number.isFinite(duration) ? duration * offset.percent / 100 : null;
|
|
71
|
+
return (_chapters = chapters[offset.position - 1]) !== null && _chapters !== void 0 ? _chapters : null;
|
|
72
|
+
}
|
|
73
|
+
export { breakOffset, offsetTime, parseVmap };
|
package/dist/host.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The contract of a control of the page's own, as guide chapter 03 of the
|
|
3
|
+
* player states it: the nearest <mattebox-player> above, through shadow
|
|
4
|
+
* hosts, then read for `media`, `engine`, `player` and `error`, with
|
|
5
|
+
* `sourcechange` heard on it. This package implements the contract from
|
|
6
|
+
* outside, on purpose: the player exports no base class, and a control that
|
|
7
|
+
* needs more than this surface has found a gap in the player's API.
|
|
8
|
+
*/
|
|
9
|
+
import type { PlayerHost } from '@mattebox/player';
|
|
10
|
+
export type { PlayerHost };
|
|
11
|
+
export declare const PLAYER = "mattebox-player";
|
|
12
|
+
/** The nearest player above `node`, or null outside one. It may not be upgraded yet. */
|
|
13
|
+
export declare function findPlayer(node: Node): HTMLElement | null;
|
|
14
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../src/host.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,YAAY,EAAE,UAAU,EAAE,CAAC;AAE3B,eAAO,MAAM,MAAM,oBAAoB,CAAC;AASxC,wFAAwF;AACxF,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,WAAW,GAAG,IAAI,CAOzD"}
|
package/dist/host.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/host.ts
|
|
2
|
+
const PLAYER = "mattebox-player";
|
|
3
|
+
/** The parent, or the host of the shadow root `node` sits in, or null at the document. */
|
|
4
|
+
function above(node) {
|
|
5
|
+
const parent = node.parentNode;
|
|
6
|
+
if (parent !== null) return parent;
|
|
7
|
+
return node instanceof ShadowRoot ? node.host : null;
|
|
8
|
+
}
|
|
9
|
+
/** The nearest player above `node`, or null outside one. It may not be upgraded yet. */
|
|
10
|
+
function findPlayer(node) {
|
|
11
|
+
let current = node;
|
|
12
|
+
while (current !== null) {
|
|
13
|
+
if (current instanceof HTMLElement && current.localName === "mattebox-player") return current;
|
|
14
|
+
current = above(current);
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
export { PLAYER, findPlayer };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=host.js.map
|
package/dist/host.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","names":[],"sources":["../src/host.ts"],"sourcesContent":["/**\n * The contract of a control of the page's own, as guide chapter 03 of the\n * player states it: the nearest <mattebox-player> above, through shadow\n * hosts, then read for `media`, `engine`, `player` and `error`, with\n * `sourcechange` heard on it. This package implements the contract from\n * outside, on purpose: the player exports no base class, and a control that\n * needs more than this surface has found a gap in the player's API.\n */\nimport type { PlayerHost } from '@mattebox/player';\n\nexport type { PlayerHost };\n\nexport const PLAYER = 'mattebox-player';\n\n/** The parent, or the host of the shadow root `node` sits in, or null at the document. */\nfunction above(node: Node): Node | null {\n const parent = node.parentNode;\n if (parent !== null) return parent;\n return node instanceof ShadowRoot ? node.host : null;\n}\n\n/** The nearest player above `node`, or null outside one. It may not be upgraded yet. */\nexport function findPlayer(node: Node): HTMLElement | null {\n let current: Node | null = node;\n while (current !== null) {\n if (current instanceof HTMLElement && current.localName === PLAYER) return current;\n current = above(current);\n }\n return null;\n}\n"],"mappings":";AAYA,MAAa,SAAS;;AAGtB,SAAS,MAAM,MAAyB;CACtC,MAAM,SAAS,KAAK;CACpB,IAAI,WAAW,MAAM,OAAO;CAC5B,OAAO,gBAAgB,aAAa,KAAK,OAAO;AAClD;;AAGA,SAAgB,WAAW,MAAgC;CACzD,IAAI,UAAuB;CAC3B,OAAO,YAAY,MAAM;EACvB,IAAI,mBAAmB,eAAe,QAAQ,cAAA,mBAAsB,OAAO;EAC3E,UAAU,MAAM,OAAO;CACzB;CACA,OAAO;AACT"}
|