@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.
Files changed (127) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -2
  3. package/dist/ad-info.d.ts +25 -0
  4. package/dist/ad-info.d.ts.map +1 -0
  5. package/dist/ad-info.js +80 -0
  6. package/dist/ad-info.js.map +1 -0
  7. package/dist/ad-link.d.ts +19 -0
  8. package/dist/ad-link.d.ts.map +1 -0
  9. package/dist/ad-link.js +51 -0
  10. package/dist/ad-link.js.map +1 -0
  11. package/dist/ad-progress.d.ts +18 -0
  12. package/dist/ad-progress.d.ts.map +1 -0
  13. package/dist/ad-progress.js +51 -0
  14. package/dist/ad-progress.js.map +1 -0
  15. package/dist/ad-skip-button.d.ts +21 -0
  16. package/dist/ad-skip-button.d.ts.map +1 -0
  17. package/dist/ad-skip-button.js +66 -0
  18. package/dist/ad-skip-button.js.map +1 -0
  19. package/dist/beacons.d.ts +29 -0
  20. package/dist/beacons.d.ts.map +1 -0
  21. package/dist/beacons.js +44 -0
  22. package/dist/beacons.js.map +1 -0
  23. package/dist/cdn/mattebox-player-ads.min.js +1 -0
  24. package/dist/component.d.ts +54 -0
  25. package/dist/component.d.ts.map +1 -0
  26. package/dist/component.js +95 -0
  27. package/dist/component.js.map +1 -0
  28. package/dist/controller.d.ts +200 -0
  29. package/dist/controller.d.ts.map +1 -0
  30. package/dist/controller.js +830 -0
  31. package/dist/controller.js.map +1 -0
  32. package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/asyncToGenerator.js +26 -0
  33. package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/defineProperty.js +11 -0
  34. package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/objectSpread2.js +24 -0
  35. package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPrimitive.js +13 -0
  36. package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/toPropertyKey.js +8 -0
  37. package/dist/es2015/_virtual/_@oxc-project_runtime@0.158.0/helpers/esm/typeof.js +10 -0
  38. package/dist/es2015/ad-info.js +79 -0
  39. package/dist/es2015/ad-link.js +53 -0
  40. package/dist/es2015/ad-progress.js +51 -0
  41. package/dist/es2015/ad-skip-button.js +68 -0
  42. package/dist/es2015/beacons.js +42 -0
  43. package/dist/es2015/component.js +94 -0
  44. package/dist/es2015/controller.js +854 -0
  45. package/dist/es2015/host.js +18 -0
  46. package/dist/es2015/index.js +72 -0
  47. package/dist/es2015/locales/ar.js +13 -0
  48. package/dist/es2015/locales/ca.js +13 -0
  49. package/dist/es2015/locales/de.js +13 -0
  50. package/dist/es2015/locales/es.js +13 -0
  51. package/dist/es2015/locales/fr.js +13 -0
  52. package/dist/es2015/locales/hi.js +13 -0
  53. package/dist/es2015/locales/it.js +13 -0
  54. package/dist/es2015/locales/ja.js +13 -0
  55. package/dist/es2015/locales/ko.js +13 -0
  56. package/dist/es2015/locales/pt.js +13 -0
  57. package/dist/es2015/locales/zh.js +13 -0
  58. package/dist/es2015/shared.js +26 -0
  59. package/dist/es2015/vast.js +255 -0
  60. package/dist/es2015/vmap.js +73 -0
  61. package/dist/host.d.ts +14 -0
  62. package/dist/host.d.ts.map +1 -0
  63. package/dist/host.js +20 -0
  64. package/dist/host.js.map +1 -0
  65. package/dist/index.d.ts +40 -0
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/index.js +74 -0
  68. package/dist/index.js.map +1 -0
  69. package/dist/locales/ar.d.ts +13 -0
  70. package/dist/locales/ar.d.ts.map +1 -0
  71. package/dist/locales/ar.js +15 -0
  72. package/dist/locales/ar.js.map +1 -0
  73. package/dist/locales/ca.d.ts +13 -0
  74. package/dist/locales/ca.d.ts.map +1 -0
  75. package/dist/locales/ca.js +15 -0
  76. package/dist/locales/ca.js.map +1 -0
  77. package/dist/locales/de.d.ts +13 -0
  78. package/dist/locales/de.d.ts.map +1 -0
  79. package/dist/locales/de.js +15 -0
  80. package/dist/locales/de.js.map +1 -0
  81. package/dist/locales/es.d.ts +13 -0
  82. package/dist/locales/es.d.ts.map +1 -0
  83. package/dist/locales/es.js +15 -0
  84. package/dist/locales/es.js.map +1 -0
  85. package/dist/locales/fr.d.ts +13 -0
  86. package/dist/locales/fr.d.ts.map +1 -0
  87. package/dist/locales/fr.js +15 -0
  88. package/dist/locales/fr.js.map +1 -0
  89. package/dist/locales/hi.d.ts +13 -0
  90. package/dist/locales/hi.d.ts.map +1 -0
  91. package/dist/locales/hi.js +15 -0
  92. package/dist/locales/hi.js.map +1 -0
  93. package/dist/locales/it.d.ts +13 -0
  94. package/dist/locales/it.d.ts.map +1 -0
  95. package/dist/locales/it.js +15 -0
  96. package/dist/locales/it.js.map +1 -0
  97. package/dist/locales/ja.d.ts +13 -0
  98. package/dist/locales/ja.d.ts.map +1 -0
  99. package/dist/locales/ja.js +15 -0
  100. package/dist/locales/ja.js.map +1 -0
  101. package/dist/locales/ko.d.ts +13 -0
  102. package/dist/locales/ko.d.ts.map +1 -0
  103. package/dist/locales/ko.js +15 -0
  104. package/dist/locales/ko.js.map +1 -0
  105. package/dist/locales/pt.d.ts +13 -0
  106. package/dist/locales/pt.d.ts.map +1 -0
  107. package/dist/locales/pt.js +15 -0
  108. package/dist/locales/pt.js.map +1 -0
  109. package/dist/locales/zh.d.ts +13 -0
  110. package/dist/locales/zh.d.ts.map +1 -0
  111. package/dist/locales/zh.js +15 -0
  112. package/dist/locales/zh.js.map +1 -0
  113. package/dist/messages.d.ts +30 -0
  114. package/dist/messages.d.ts.map +1 -0
  115. package/dist/shared.d.ts +7 -0
  116. package/dist/shared.d.ts.map +1 -0
  117. package/dist/shared.js +25 -0
  118. package/dist/shared.js.map +1 -0
  119. package/dist/vast.d.ts +94 -0
  120. package/dist/vast.d.ts.map +1 -0
  121. package/dist/vast.js +254 -0
  122. package/dist/vast.js.map +1 -0
  123. package/dist/vmap.d.ts +31 -0
  124. package/dist/vmap.d.ts.map +1 -0
  125. package/dist/vmap.js +71 -0
  126. package/dist/vmap.js.map +1 -0
  127. package/package.json +52 -6
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Josep Boix Requesens
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,37 @@
1
- # @mattebox/player-ads
1
+ <h1>
2
+ <img src="https://raw.githubusercontent.com/jboix/mattebox-player/main/docs/logo.svg" width="44" height="44" align="absmiddle" alt="">
3
+ @mattebox/player-ads
4
+ </h1>
2
5
 
3
- This version reserves the name and contains no code. Install a later version.
6
+ Ads for the [Mattebox player](https://github.com/jboix/mattebox-player).
7
+
8
+ - It adds the engine's `interstitials` stage to every player: HLS interstitials, DASH alternative MPD events and SCTE-35 cue-outs play and show as ads.
9
+ - It reads VAST 2 to 4.3 and VMAP 1.0.1, follows wrappers, plays pods, and sends every beacon.
10
+ - `<mbx-ad-info>`, `<mbx-ad-skip-button>` and `<mbx-ad-link>` show the ad, its countdown, the skip and the advertiser's page.
11
+ - An ad with an HLS or DASH file plays on the player's own video. An ad with only an MP4 plays over it.
12
+
13
+ ```sh
14
+ npm install @mattebox/player-ads @mattebox/player mattebox
15
+ ```
16
+
17
+ ```html
18
+ <mattebox-player controls="custom" src="https://example.com/vod/master.m3u8"
19
+ ad-schedule="https://ads.example.com/vmap.xml">
20
+ <mbx-ad-info></mbx-ad-info>
21
+ <mbx-ad-skip-button></mbx-ad-skip-button>
22
+ <mbx-ad-link></mbx-ad-link>
23
+ <mbx-control-bar>
24
+ <mbx-play-button></mbx-play-button>
25
+ <mbx-seek-bar></mbx-seek-bar>
26
+ </mbx-control-bar>
27
+ </mattebox-player>
28
+
29
+ <script type="module">
30
+ import { MatteboxPlayerElement } from '@mattebox/player';
31
+ import { ads } from '@mattebox/player-ads';
32
+
33
+ MatteboxPlayerElement.define({ addons: [ads()] });
34
+ </script>
35
+ ```
36
+
37
+ The [player guide, chapter 14](https://github.com/jboix/mattebox-player/blob/main/docs/guide/14-ads.md) explains the schedule, the beacons and the events.
@@ -0,0 +1,25 @@
1
+ /**
2
+ * <mbx-ad-info>: "Ad" or "Promo", or "Ad 2 of 3", and the time left in the
3
+ * break, at the top left while an ad plays. For a break the stream plays
4
+ * with the controls kept, a line under it shows how far it has played,
5
+ * since the seek bar still shows the programme. A screen reader hears "Ad
6
+ * break, 30 seconds" when a break starts. `label`, `label-count`,
7
+ * `label-promo`, `label-promo-count` and `label-break` replace the words.
8
+ */
9
+ import { Component } from './component.js';
10
+ import type { PlayerHost } from './host.js';
11
+ export declare class MbxAdInfo extends Component {
12
+ static get observedAttributes(): readonly string[];
13
+ private readonly label;
14
+ private readonly time;
15
+ private readonly line;
16
+ private readonly lineFill;
17
+ private readonly live;
18
+ private ads;
19
+ private told;
20
+ constructor();
21
+ protected attach(player: PlayerHost): void;
22
+ protected detach(): void;
23
+ protected render(): void;
24
+ }
25
+ //# sourceMappingURL=ad-info.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ad-info.d.ts","sourceRoot":"","sources":["../src/ad-info.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C,qBAAa,SAAU,SAAQ,SAAS;IACtC,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,KAAK,CAAkB;IAChD,iBAAyB,IAAI,CAAkB;IAC/C,iBAAyB,IAAI,CAAiB;IAC9C,iBAAyB,QAAQ,CAAiB;IAClD,iBAAyB,IAAI,CAAkB;IAC/C,QAAgB,GAAG,CAAoB;IACvC,QAAgB,IAAI,CAAgB;;cA4BjB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAMhC,MAAM,IAAI,IAAI;cAId,MAAM,IAAI,IAAI;CAoClC"}
@@ -0,0 +1,80 @@
1
+ import { Component } from "./component.js";
2
+ import { controllerFor } from "./controller.js";
3
+ import { clock, fill, style } from "./shared.js";
4
+ // src/ad-info.ts
5
+ /**
6
+ * <mbx-ad-info>: "Ad" or "Promo", or "Ad 2 of 3", and the time left in the
7
+ * break, at the top left while an ad plays. For a break the stream plays
8
+ * with the controls kept, a line under it shows how far it has played,
9
+ * since the seek bar still shows the programme. A screen reader hears "Ad
10
+ * break, 30 seconds" when a break starts. `label`, `label-count`,
11
+ * `label-promo`, `label-promo-count` and `label-break` replace the words.
12
+ */
13
+ var MbxAdInfo = class extends Component {
14
+ static get observedAttributes() {
15
+ return [
16
+ "label",
17
+ "label-count",
18
+ "label-promo",
19
+ "label-promo-count",
20
+ "label-break"
21
+ ];
22
+ }
23
+ constructor() {
24
+ super();
25
+ this.ads = null;
26
+ this.told = null;
27
+ const root = this.attachShadow({ mode: "open" });
28
+ const panel = document.createElement("div");
29
+ panel.setAttribute("part", "panel");
30
+ const row = document.createElement("div");
31
+ row.setAttribute("part", "row");
32
+ this.label = document.createElement("span");
33
+ this.label.setAttribute("part", "label");
34
+ this.time = document.createElement("span");
35
+ this.time.setAttribute("part", "time");
36
+ row.append(this.label, this.time);
37
+ this.line = document.createElement("div");
38
+ this.line.setAttribute("part", "line");
39
+ this.lineFill = document.createElement("div");
40
+ this.lineFill.setAttribute("part", "line-fill");
41
+ this.line.append(this.lineFill);
42
+ panel.append(row, this.line);
43
+ this.live = document.createElement("span");
44
+ this.live.setAttribute("part", "live");
45
+ this.live.setAttribute("role", "status");
46
+ root.append(style("top:0.875em;left:1em"), panel, this.live);
47
+ }
48
+ attach(player) {
49
+ this.ads = controllerFor(player);
50
+ this.keep(this.ads.watch(() => this.render()));
51
+ this.render();
52
+ }
53
+ detach() {
54
+ this.ads = null;
55
+ }
56
+ render() {
57
+ const state = this.ads?.state ?? null;
58
+ this.hidden = state === null;
59
+ if (state === null) {
60
+ this.told = null;
61
+ return;
62
+ }
63
+ const promo = state.role === "promo";
64
+ this.label.textContent = state.total > 1 ? fill(promo ? this.word("label-promo-count", "adPromoCount", "Promo {index} of {total}") : this.word("label-count", "adCount", "Ad {index} of {total}"), {
65
+ index: state.index,
66
+ total: state.total
67
+ }) : promo ? this.word("label-promo", "adPromo", "Promo") : this.word("label", "adLabel", "Ad");
68
+ this.time.textContent = Number.isFinite(state.remaining) ? `· ${clock(state.remaining)}` : "";
69
+ this.line.hidden = !state.free;
70
+ const share = Number.isFinite(state.duration) && state.duration > 0 ? Math.min(1, Math.max(0, state.currentTime / state.duration)) : 0;
71
+ this.lineFill.style.width = `${(share * 100).toFixed(2)}%`;
72
+ if (this.told !== state.breakId && Number.isFinite(state.remaining)) {
73
+ this.told = state.breakId;
74
+ this.live.textContent = fill(this.word("label-break", "adBreak", "Ad break, {seconds} seconds"), { seconds: Math.ceil(state.remaining) });
75
+ }
76
+ }
77
+ };
78
+ export { MbxAdInfo };
79
+
80
+ //# sourceMappingURL=ad-info.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ad-info.js","names":[],"sources":["../src/ad-info.ts"],"sourcesContent":["/**\n * <mbx-ad-info>: \"Ad\" or \"Promo\", or \"Ad 2 of 3\", and the time left in the\n * break, at the top left while an ad plays. For a break the stream plays\n * with the controls kept, a line under it shows how far it has played,\n * since the seek bar still shows the programme. A screen reader hears \"Ad\n * break, 30 seconds\" when a break starts. `label`, `label-count`,\n * `label-promo`, `label-promo-count` and `label-break` replace the words.\n */\n\nimport { Component } from './component.js';\nimport type { Controller } from './controller.js';\nimport { controllerFor } from './controller.js';\nimport type { PlayerHost } from './host.js';\nimport { clock, fill, style } from './shared.js';\n\nexport class MbxAdInfo extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-count', 'label-promo', 'label-promo-count', 'label-break'];\n }\n\n declare private readonly label: HTMLSpanElement;\n declare private readonly time: HTMLSpanElement;\n declare private readonly line: HTMLDivElement;\n declare private readonly lineFill: HTMLDivElement;\n declare private readonly live: HTMLSpanElement;\n declare private ads: Controller | null;\n declare private told: string | null;\n\n constructor() {\n super();\n this.ads = null;\n this.told = null;\n const root = this.attachShadow({ mode: 'open' });\n const panel = document.createElement('div');\n panel.setAttribute('part', 'panel');\n const row = document.createElement('div');\n row.setAttribute('part', 'row');\n this.label = document.createElement('span');\n this.label.setAttribute('part', 'label');\n this.time = document.createElement('span');\n this.time.setAttribute('part', 'time');\n row.append(this.label, this.time);\n this.line = document.createElement('div');\n this.line.setAttribute('part', 'line');\n this.lineFill = document.createElement('div');\n this.lineFill.setAttribute('part', 'line-fill');\n this.line.append(this.lineFill);\n panel.append(row, this.line);\n this.live = document.createElement('span');\n this.live.setAttribute('part', 'live');\n this.live.setAttribute('role', 'status');\n root.append(style('top:0.875em;left:1em'), panel, this.live);\n }\n\n protected override attach(player: PlayerHost): void {\n this.ads = controllerFor(player);\n this.keep(this.ads.watch(() => this.render()));\n this.render();\n }\n\n protected override detach(): void {\n this.ads = null;\n }\n\n protected override render(): void {\n const state = this.ads?.state ?? null;\n this.hidden = state === null;\n if (state === null) {\n this.told = null;\n return;\n }\n const promo = state.role === 'promo';\n this.label.textContent =\n state.total > 1\n ? fill(\n promo\n ? this.word('label-promo-count', 'adPromoCount', 'Promo {index} of {total}')\n : this.word('label-count', 'adCount', 'Ad {index} of {total}'),\n { index: state.index, total: state.total },\n )\n : promo\n ? this.word('label-promo', 'adPromo', 'Promo')\n : this.word('label', 'adLabel', 'Ad');\n this.time.textContent = Number.isFinite(state.remaining) ? `· ${clock(state.remaining)}` : '';\n this.line.hidden = !state.free;\n const share =\n Number.isFinite(state.duration) && state.duration > 0\n ? Math.min(1, Math.max(0, state.currentTime / state.duration))\n : 0;\n this.lineFill.style.width = `${(share * 100).toFixed(2)}%`;\n if (this.told !== state.breakId && Number.isFinite(state.remaining)) {\n this.told = state.breakId;\n this.live.textContent = fill(\n this.word('label-break', 'adBreak', 'Ad break, {seconds} seconds'),\n {\n seconds: Math.ceil(state.remaining),\n },\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAeA,IAAa,YAAb,cAA+B,UAAU;CACvC,WAAW,qBAAwC;EACjD,OAAO;GAAC;GAAS;GAAe;GAAe;GAAqB;EAAa;CACnF;CAUA,cAAc;EACZ,MAAM;EACN,KAAK,MAAM;EACX,KAAK,OAAO;EACZ,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,MAAM,QAAQ,SAAS,cAAc,KAAK;EAC1C,MAAM,aAAa,QAAQ,OAAO;EAClC,MAAM,MAAM,SAAS,cAAc,KAAK;EACxC,IAAI,aAAa,QAAQ,KAAK;EAC9B,KAAK,QAAQ,SAAS,cAAc,MAAM;EAC1C,KAAK,MAAM,aAAa,QAAQ,OAAO;EACvC,KAAK,OAAO,SAAS,cAAc,MAAM;EACzC,KAAK,KAAK,aAAa,QAAQ,MAAM;EACrC,IAAI,OAAO,KAAK,OAAO,KAAK,IAAI;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AAM,QAAQ,CAAC,IAC3D;EACN,KAAK,SAAS,MAAM,QAAQ,IAAI,QAAQ,IAAA,CAAK,QAAQ,CAAC,EAAE;EACxD,IAAI,KAAK,SAAS,MAAM,WAAW,OAAO,SAAS,MAAM,SAAS,GAAG;GACnE,KAAK,OAAO,MAAM;GAClB,KAAK,KAAK,cAAc,KACtB,KAAK,KAAK,eAAe,WAAW,6BAA6B,GACjE,EACE,SAAS,KAAK,KAAK,MAAM,SAAS,EACpC,CACF;EACF;CACF;AACF"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * <mbx-ad-link>: an info button at the top right while an ad with a page of
3
+ * its own plays, named "Learn more" for a screen reader and in its tooltip.
4
+ * It opens the page in a new tab, pauses the ad, and reports the click.
5
+ * `label` replaces the words; a page's own SVG in `slot="icon"` replaces the
6
+ * glyph.
7
+ */
8
+ import { Component } from './component.js';
9
+ import type { PlayerHost } from './host.js';
10
+ export declare class MbxAdLink extends Component {
11
+ static get observedAttributes(): readonly string[];
12
+ private readonly button;
13
+ private ads;
14
+ constructor();
15
+ protected attach(player: PlayerHost): void;
16
+ protected detach(): void;
17
+ protected render(): void;
18
+ }
19
+ //# sourceMappingURL=ad-link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ad-link.d.ts","sourceRoot":"","sources":["../src/ad-link.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C,qBAAa,SAAU,SAAQ,SAAS;IACtC,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,MAAM,CAAoB;IACnD,QAAgB,GAAG,CAAoB;;cAsBpB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAMhC,MAAM,IAAI,IAAI;cAId,MAAM,IAAI,IAAI;CAOlC"}
@@ -0,0 +1,51 @@
1
+ import { Component } from "./component.js";
2
+ import { controllerFor } from "./controller.js";
3
+ import { style } from "./shared.js";
4
+ // src/ad-link.ts
5
+ /**
6
+ * <mbx-ad-link>: an info button at the top right while an ad with a page of
7
+ * its own plays, named "Learn more" for a screen reader and in its tooltip.
8
+ * It opens the page in a new tab, pauses the ad, and reports the click.
9
+ * `label` replaces the words; a page's own SVG in `slot="icon"` replaces the
10
+ * glyph.
11
+ */
12
+ var MbxAdLink = class extends Component {
13
+ static get observedAttributes() {
14
+ return ["label"];
15
+ }
16
+ constructor() {
17
+ super();
18
+ this.ads = null;
19
+ const root = this.attachShadow({ mode: "open" });
20
+ this.button = document.createElement("button");
21
+ this.button.type = "button";
22
+ this.button.setAttribute("part", "icon-button");
23
+ const glyph = document.createElement("slot");
24
+ glyph.name = "icon";
25
+ glyph.innerHTML = "<svg part=\"icon\" viewBox=\"0 0 32 32\" aria-hidden=\"true\"><path fill-rule=\"evenodd\" d=\"M16 3a13 13 0 1 1 0 26a13 13 0 1 1 0-26zM16 5.5a10.5 10.5 0 1 0 0 21a10.5 10.5 0 1 0 0-21zM14.5 14h3v9h-3zM14.5 9h3v3h-3z\"/></svg>";
26
+ const disc = document.createElement("span");
27
+ disc.setAttribute("part", "disc");
28
+ disc.append(glyph);
29
+ this.button.append(disc);
30
+ this.button.addEventListener("click", () => this.ads?.click());
31
+ root.append(style("top:0.5em;right:0.75em"), this.button);
32
+ }
33
+ attach(player) {
34
+ this.ads = controllerFor(player);
35
+ this.keep(this.ads.watch(() => this.render()));
36
+ this.render();
37
+ }
38
+ detach() {
39
+ this.ads = null;
40
+ }
41
+ render() {
42
+ const state = this.ads?.state ?? null;
43
+ this.hidden = state?.clickThrough === void 0;
44
+ const label = this.word("label", "adLearnMore", "Learn more");
45
+ this.button.setAttribute("aria-label", label);
46
+ this.button.title = label;
47
+ }
48
+ };
49
+ export { MbxAdLink };
50
+
51
+ //# sourceMappingURL=ad-link.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ad-link.js","names":[],"sources":["../src/ad-link.ts"],"sourcesContent":["/**\n * <mbx-ad-link>: an info button at the top right while an ad with a page of\n * its own plays, named \"Learn more\" for a screen reader and in its tooltip.\n * It opens the page in a new tab, pauses the ad, and reports the click.\n * `label` replaces the words; a page's own SVG in `slot=\"icon\"` replaces the\n * glyph.\n */\n\nimport { Component } from './component.js';\nimport type { Controller } from './controller.js';\nimport { controllerFor } from './controller.js';\nimport type { PlayerHost } from './host.js';\nimport { style } from './shared.js';\n\nexport class MbxAdLink extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label'];\n }\n\n declare private readonly button: HTMLButtonElement;\n declare private ads: Controller | null;\n\n constructor() {\n super();\n this.ads = null;\n const root = this.attachShadow({ mode: 'open' });\n this.button = document.createElement('button');\n this.button.type = 'button';\n this.button.setAttribute('part', 'icon-button');\n // A circle with an i: drawn even-odd on the player's 32-unit grid.\n const glyph = document.createElement('slot');\n glyph.name = 'icon';\n glyph.innerHTML =\n '<svg part=\"icon\" viewBox=\"0 0 32 32\" aria-hidden=\"true\"><path fill-rule=\"evenodd\" d=\"M16 3a13 13 0 1 1 0 26a13 13 0 1 1 0-26zM16 5.5a10.5 10.5 0 1 0 0 21a10.5 10.5 0 1 0 0-21zM14.5 14h3v9h-3zM14.5 9h3v3h-3z\"/></svg>';\n const disc = document.createElement('span');\n disc.setAttribute('part', 'disc');\n disc.append(glyph);\n this.button.append(disc);\n this.button.addEventListener('click', () => this.ads?.click());\n root.append(style('top:0.5em;right:0.75em'), this.button);\n }\n\n protected override attach(player: PlayerHost): void {\n this.ads = controllerFor(player);\n this.keep(this.ads.watch(() => this.render()));\n this.render();\n }\n\n protected override detach(): void {\n this.ads = null;\n }\n\n protected override render(): void {\n const state = this.ads?.state ?? null;\n this.hidden = state?.clickThrough === undefined;\n const label = this.word('label', 'adLearnMore', 'Learn more');\n this.button.setAttribute('aria-label', label);\n this.button.title = label;\n }\n}\n"],"mappings":";;;;;;;;;;;AAcA,IAAa,YAAb,cAA+B,UAAU;CACvC,WAAW,qBAAwC;EACjD,OAAO,CAAC,OAAO;CACjB;CAKA,cAAc;EACZ,MAAM;EACN,KAAK,MAAM;EACX,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,KAAK,SAAS,SAAS,cAAc,QAAQ;EAC7C,KAAK,OAAO,OAAO;EACnB,KAAK,OAAO,aAAa,QAAQ,aAAa;EAE9C,MAAM,QAAQ,SAAS,cAAc,MAAM;EAC3C,MAAM,OAAO;EACb,MAAM,YACJ;EACF,MAAM,OAAO,SAAS,cAAc,MAAM;EAC1C,KAAK,aAAa,QAAQ,MAAM;EAChC,KAAK,OAAO,KAAK;EACjB,KAAK,OAAO,OAAO,IAAI;EACvB,KAAK,OAAO,iBAAiB,eAAe,KAAK,KAAK,MAAM,CAAC;EAC7D,KAAK,OAAO,MAAM,wBAAwB,GAAG,KAAK,MAAM;CAC1D;CAEmB,OAAO,QAA0B;EAClD,KAAK,MAAM,cAAc,MAAM;EAC/B,KAAK,KAAK,KAAK,IAAI,YAAY,KAAK,OAAO,CAAC,CAAC;EAC7C,KAAK,OAAO;CACd;CAEmB,SAAe;EAChC,KAAK,MAAM;CACb;CAEmB,SAAe;EAChC,MAAM,QAAQ,KAAK,KAAK,SAAS;EACjC,KAAK,SAAS,OAAO,iBAAiB,KAAA;EACtC,MAAM,QAAQ,KAAK,KAAK,SAAS,eAAe,YAAY;EAC5D,KAAK,OAAO,aAAa,cAAc,KAAK;EAC5C,KAAK,OAAO,QAAQ;CACtB;AACF"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * <mbx-ad-progress>: how far the ad has played, as a bar in the seek bar's
3
+ * place while an ad plays, as YouTube shows it. Put it beside the seek bar,
4
+ * in the bar's seek row; it is hidden outside ads, and the seek bar during
5
+ * them.
6
+ */
7
+ import { Component } from './component.js';
8
+ import type { PlayerHost } from './host.js';
9
+ export declare class MbxAdProgress extends Component {
10
+ private readonly fill;
11
+ private readonly rail;
12
+ private ads;
13
+ constructor();
14
+ protected attach(player: PlayerHost): void;
15
+ protected detach(): void;
16
+ protected render(): void;
17
+ }
18
+ //# sourceMappingURL=ad-progress.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ad-progress.d.ts","sourceRoot":"","sources":["../src/ad-progress.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAG5C,qBAAa,aAAc,SAAQ,SAAS;IAC1C,iBAAyB,IAAI,CAAc;IAC3C,iBAAyB,IAAI,CAAc;IAC3C,QAAgB,GAAG,CAAoB;;cAsBpB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAUhC,MAAM,IAAI,IAAI;cAId,MAAM,IAAI,IAAI;CAalC"}
@@ -0,0 +1,51 @@
1
+ import { Component } from "./component.js";
2
+ import { controllerFor } from "./controller.js";
3
+ // src/ad-progress.ts
4
+ /**
5
+ * <mbx-ad-progress>: how far the ad has played, as a bar in the seek bar's
6
+ * place while an ad plays, as YouTube shows it. Put it beside the seek bar,
7
+ * in the bar's seek row; it is hidden outside ads, and the seek bar during
8
+ * them.
9
+ */
10
+ const PROGRESS_CSS = ":host{flex:1;display:block}:host([hidden]){display:none}[part~=rail]{height:2.5em;margin:0 .5em;position:relative}[part~=track]{background:#ffffff59;border-radius:2px;height:.25em;position:absolute;top:50%;left:0;right:0;overflow:hidden;transform:translateY(-50%)}[part~=fill]{background:var(--mbx-ad,#f5c518);position:absolute;top:0;bottom:0;left:0}";
11
+ var MbxAdProgress = class extends Component {
12
+ constructor() {
13
+ super();
14
+ this.ads = null;
15
+ const root = this.attachShadow({ mode: "open" });
16
+ const style = document.createElement("style");
17
+ style.textContent = PROGRESS_CSS;
18
+ this.rail = document.createElement("div");
19
+ this.rail.setAttribute("part", "rail");
20
+ this.rail.setAttribute("role", "progressbar");
21
+ this.rail.setAttribute("aria-valuemin", "0");
22
+ this.rail.setAttribute("aria-valuemax", "100");
23
+ const track = document.createElement("div");
24
+ track.setAttribute("part", "track");
25
+ this.fill = document.createElement("div");
26
+ this.fill.setAttribute("part", "fill");
27
+ track.append(this.fill);
28
+ this.rail.append(track);
29
+ root.append(style, this.rail);
30
+ }
31
+ attach(player) {
32
+ if (this.parentElement?.localName === "mbx-control-bar" && !this.hasAttribute("slot")) this.setAttribute("slot", "seek");
33
+ this.ads = controllerFor(player);
34
+ this.keep(this.ads.watch(() => this.render()));
35
+ this.render();
36
+ }
37
+ detach() {
38
+ this.ads = null;
39
+ }
40
+ render() {
41
+ const state = this.ads?.state ?? null;
42
+ this.hidden = state === null || state.free;
43
+ if (state === null) return;
44
+ const share = Number.isFinite(state.duration) && state.duration > 0 ? Math.min(1, Math.max(0, state.currentTime / state.duration)) : 0;
45
+ this.fill.style.width = `${(share * 100).toFixed(2)}%`;
46
+ this.rail.setAttribute("aria-valuenow", String(Math.round(share * 100)));
47
+ }
48
+ };
49
+ export { MbxAdProgress };
50
+
51
+ //# sourceMappingURL=ad-progress.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ad-progress.js","names":[],"sources":["../src/ad-progress.ts"],"sourcesContent":["/**\n * <mbx-ad-progress>: how far the ad has played, as a bar in the seek bar's\n * place while an ad plays, as YouTube shows it. Put it beside the seek bar,\n * in the bar's seek row; it is hidden outside ads, and the seek bar during\n * them.\n */\n\nimport { Component } from './component.js';\nimport type { Controller } from './controller.js';\nimport { controllerFor } from './controller.js';\nimport type { PlayerHost } from './host.js';\nimport PROGRESS_CSS from './progress.css?inline';\n\nexport class MbxAdProgress extends Component {\n declare private readonly fill: HTMLElement;\n declare private readonly rail: HTMLElement;\n declare private ads: Controller | null;\n\n constructor() {\n super();\n this.ads = null;\n const root = this.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = PROGRESS_CSS;\n this.rail = document.createElement('div');\n this.rail.setAttribute('part', 'rail');\n this.rail.setAttribute('role', 'progressbar');\n this.rail.setAttribute('aria-valuemin', '0');\n this.rail.setAttribute('aria-valuemax', '100');\n const track = document.createElement('div');\n track.setAttribute('part', 'track');\n this.fill = document.createElement('div');\n this.fill.setAttribute('part', 'fill');\n track.append(this.fill);\n this.rail.append(track);\n root.append(style, this.rail);\n }\n\n protected override attach(player: PlayerHost): void {\n // The bar's seek row, as the seek bar it stands in for.\n if (this.parentElement?.localName === 'mbx-control-bar' && !this.hasAttribute('slot')) {\n this.setAttribute('slot', 'seek');\n }\n this.ads = controllerFor(player);\n this.keep(this.ads.watch(() => this.render()));\n this.render();\n }\n\n protected override detach(): void {\n this.ads = null;\n }\n\n protected override render(): void {\n const state = this.ads?.state ?? null;\n // A break with the controls kept leaves the seek bar in place: its\n // label carries the progress instead.\n this.hidden = state === null || state.free;\n if (state === null) return;\n const share =\n Number.isFinite(state.duration) && state.duration > 0\n ? Math.min(1, Math.max(0, state.currentTime / state.duration))\n : 0;\n this.fill.style.width = `${(share * 100).toFixed(2)}%`;\n this.rail.setAttribute('aria-valuenow', String(Math.round(share * 100)));\n }\n}\n"],"mappings":";;;;;;;;;AAWA,MAAA,eAAA;AAEA,IAAa,gBAAb,cAAmC,UAAU;CAK3C,cAAc;EACZ,MAAM;EACN,KAAK,MAAM;EACX,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;EAC/C,MAAM,QAAQ,SAAS,cAAc,OAAO;EAC5C,MAAM,cAAc;EACpB,KAAK,OAAO,SAAS,cAAc,KAAK;EACxC,KAAK,KAAK,aAAa,QAAQ,MAAM;EACrC,KAAK,KAAK,aAAa,QAAQ,aAAa;EAC5C,KAAK,KAAK,aAAa,iBAAiB,GAAG;EAC3C,KAAK,KAAK,aAAa,iBAAiB,KAAK;EAC7C,MAAM,QAAQ,SAAS,cAAc,KAAK;EAC1C,MAAM,aAAa,QAAQ,OAAO;EAClC,KAAK,OAAO,SAAS,cAAc,KAAK;EACxC,KAAK,KAAK,aAAa,QAAQ,MAAM;EACrC,MAAM,OAAO,KAAK,IAAI;EACtB,KAAK,KAAK,OAAO,KAAK;EACtB,KAAK,OAAO,OAAO,KAAK,IAAI;CAC9B;CAEmB,OAAO,QAA0B;EAElD,IAAI,KAAK,eAAe,cAAc,qBAAqB,CAAC,KAAK,aAAa,MAAM,GAClF,KAAK,aAAa,QAAQ,MAAM;EAElC,KAAK,MAAM,cAAc,MAAM;EAC/B,KAAK,KAAK,KAAK,IAAI,YAAY,KAAK,OAAO,CAAC,CAAC;EAC7C,KAAK,OAAO;CACd;CAEmB,SAAe;EAChC,KAAK,MAAM;CACb;CAEmB,SAAe;EAChC,MAAM,QAAQ,KAAK,KAAK,SAAS;EAGjC,KAAK,SAAS,UAAU,QAAQ,MAAM;EACtC,IAAI,UAAU,MAAM;EACpB,MAAM,QACJ,OAAO,SAAS,MAAM,QAAQ,KAAK,MAAM,WAAW,IAChD,KAAK,IAAI,GAAG,KAAK,IAAI,GAAG,MAAM,cAAc,MAAM,QAAQ,CAAC,IAC3D;EACN,KAAK,KAAK,MAAM,QAAQ,IAAI,QAAQ,IAAA,CAAK,QAAQ,CAAC,EAAE;EACpD,KAAK,KAAK,aAAa,iBAAiB,OAAO,KAAK,MAAM,QAAQ,GAAG,CAAC,CAAC;CACzE;AACF"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * <mbx-ad-skip-button>: "Skip in 5" while the ad may not be skipped yet,
3
+ * then "Skip ad" or "Skip promo", at the bottom right above the bar. Hidden
4
+ * for an ad that cannot be skipped. A break the stream plays with the
5
+ * controls kept skips at once, to its end. `label`, `label-promo` and
6
+ * `label-wait` replace the words.
7
+ */
8
+ import { Component } from './component.js';
9
+ import type { PlayerHost } from './host.js';
10
+ export declare class MbxAdSkipButton extends Component {
11
+ static get observedAttributes(): readonly string[];
12
+ private readonly button;
13
+ private readonly text;
14
+ private readonly chevron;
15
+ private ads;
16
+ constructor();
17
+ protected attach(player: PlayerHost): void;
18
+ protected detach(): void;
19
+ protected render(): void;
20
+ }
21
+ //# sourceMappingURL=ad-skip-button.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ad-skip-button.d.ts","sourceRoot":"","sources":["../src/ad-skip-button.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAK5C,qBAAa,eAAgB,SAAQ,SAAS;IAC5C,MAAM,KAAK,kBAAkB,IAAI,SAAS,MAAM,EAAE,CAEjD;IAED,iBAAyB,MAAM,CAAoB;IACnD,iBAAyB,IAAI,CAAkB;IAC/C,iBAAyB,OAAO,CAAgB;IAChD,QAAgB,GAAG,CAAoB;;cA2BpB,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;cAMhC,MAAM,IAAI,IAAI;cAId,MAAM,IAAI,IAAI;CAgBlC"}
@@ -0,0 +1,66 @@
1
+ import { Component } from "./component.js";
2
+ import { controllerFor } from "./controller.js";
3
+ import { fill, style } from "./shared.js";
4
+ // src/ad-skip-button.ts
5
+ /**
6
+ * <mbx-ad-skip-button>: "Skip in 5" while the ad may not be skipped yet,
7
+ * then "Skip ad" or "Skip promo", at the bottom right above the bar. Hidden
8
+ * for an ad that cannot be skipped. A break the stream plays with the
9
+ * controls kept skips at once, to its end. `label`, `label-promo` and
10
+ * `label-wait` replace the words.
11
+ */
12
+ const SVG = "http://www.w3.org/2000/svg";
13
+ var MbxAdSkipButton = class extends Component {
14
+ static get observedAttributes() {
15
+ return [
16
+ "label",
17
+ "label-promo",
18
+ "label-wait"
19
+ ];
20
+ }
21
+ constructor() {
22
+ super();
23
+ this.ads = null;
24
+ const root = this.attachShadow({ mode: "open" });
25
+ this.button = document.createElement("button");
26
+ this.button.type = "button";
27
+ this.button.setAttribute("part", "button");
28
+ this.text = document.createElement("span");
29
+ this.chevron = document.createElementNS(SVG, "svg");
30
+ this.chevron.setAttribute("viewBox", "0 0 32 32");
31
+ this.chevron.setAttribute("aria-hidden", "true");
32
+ this.chevron.setAttribute("part", "chevron");
33
+ const path = document.createElementNS(SVG, "path");
34
+ path.setAttribute("d", "M12 8l8 8l-8 8");
35
+ path.setAttribute("fill", "none");
36
+ path.setAttribute("stroke", "currentColor");
37
+ path.setAttribute("stroke-width", "3");
38
+ path.setAttribute("stroke-linecap", "round");
39
+ path.setAttribute("stroke-linejoin", "round");
40
+ this.chevron.append(path);
41
+ this.button.append(this.text, this.chevron);
42
+ this.button.addEventListener("click", () => this.ads?.skip());
43
+ root.append(style("right:1em;bottom:calc(var(--mbx-bar-rows, 6.5em) + 0.75em)"), this.button);
44
+ }
45
+ attach(player) {
46
+ this.ads = controllerFor(player);
47
+ this.keep(this.ads.watch(() => this.render()));
48
+ this.render();
49
+ }
50
+ detach() {
51
+ this.ads = null;
52
+ }
53
+ render() {
54
+ const state = this.ads?.state ?? null;
55
+ const skipIn = state?.skipIn ?? null;
56
+ this.hidden = state === null || skipIn === null;
57
+ if (state === null || skipIn === null) return;
58
+ const waiting = skipIn > 0;
59
+ this.button.disabled = waiting;
60
+ this.chevron.toggleAttribute("hidden", waiting);
61
+ this.text.textContent = waiting ? fill(this.word("label-wait", "adSkipIn", "Skip in {seconds}"), { seconds: Math.ceil(skipIn) }) : state.role === "promo" ? this.word("label-promo", "adSkipPromo", "Skip promo") : this.word("label", "adSkip", "Skip ad");
62
+ }
63
+ };
64
+ export { MbxAdSkipButton };
65
+
66
+ //# sourceMappingURL=ad-skip-button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ad-skip-button.js","names":[],"sources":["../src/ad-skip-button.ts"],"sourcesContent":["/**\n * <mbx-ad-skip-button>: \"Skip in 5\" while the ad may not be skipped yet,\n * then \"Skip ad\" or \"Skip promo\", at the bottom right above the bar. Hidden\n * for an ad that cannot be skipped. A break the stream plays with the\n * controls kept skips at once, to its end. `label`, `label-promo` and\n * `label-wait` replace the words.\n */\n\nimport { Component } from './component.js';\nimport type { Controller } from './controller.js';\nimport { controllerFor } from './controller.js';\nimport type { PlayerHost } from './host.js';\nimport { fill, style } from './shared.js';\n\nconst SVG = 'http://www.w3.org/2000/svg';\n\nexport class MbxAdSkipButton extends Component {\n static get observedAttributes(): readonly string[] {\n return ['label', 'label-promo', 'label-wait'];\n }\n\n declare private readonly button: HTMLButtonElement;\n declare private readonly text: HTMLSpanElement;\n declare private readonly chevron: SVGSVGElement;\n declare private ads: Controller | null;\n\n constructor() {\n super();\n this.ads = null;\n const root = this.attachShadow({ mode: 'open' });\n this.button = document.createElement('button');\n this.button.type = 'button';\n this.button.setAttribute('part', 'button');\n this.text = document.createElement('span');\n this.chevron = document.createElementNS(SVG, 'svg');\n this.chevron.setAttribute('viewBox', '0 0 32 32');\n this.chevron.setAttribute('aria-hidden', 'true');\n this.chevron.setAttribute('part', 'chevron');\n const path = document.createElementNS(SVG, 'path');\n path.setAttribute('d', 'M12 8l8 8l-8 8');\n path.setAttribute('fill', 'none');\n path.setAttribute('stroke', 'currentColor');\n path.setAttribute('stroke-width', '3');\n path.setAttribute('stroke-linecap', 'round');\n path.setAttribute('stroke-linejoin', 'round');\n this.chevron.append(path);\n this.button.append(this.text, this.chevron);\n this.button.addEventListener('click', () => this.ads?.skip());\n root.append(style('right:1em;bottom:calc(var(--mbx-bar-rows, 6.5em) + 0.75em)'), this.button);\n }\n\n protected override attach(player: PlayerHost): void {\n this.ads = controllerFor(player);\n this.keep(this.ads.watch(() => this.render()));\n this.render();\n }\n\n protected override detach(): void {\n this.ads = null;\n }\n\n protected override render(): void {\n const state = this.ads?.state ?? null;\n const skipIn = state?.skipIn ?? null;\n this.hidden = state === null || skipIn === null;\n if (state === null || skipIn === null) return;\n const waiting = skipIn > 0;\n this.button.disabled = waiting;\n this.chevron.toggleAttribute('hidden', waiting);\n this.text.textContent = waiting\n ? fill(this.word('label-wait', 'adSkipIn', 'Skip in {seconds}'), {\n seconds: Math.ceil(skipIn),\n })\n : state.role === 'promo'\n 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AM,QAAQ,KAAK,KAAK,SAAS;EACjC,MAAM,SAAS,OAAO,UAAU;EAChC,KAAK,SAAS,UAAU,QAAQ,WAAW;EAC3C,IAAI,UAAU,QAAQ,WAAW,MAAM;EACvC,MAAM,UAAU,SAAS;EACzB,KAAK,OAAO,WAAW;EACvB,KAAK,QAAQ,gBAAgB,UAAU,OAAO;EAC9C,KAAK,KAAK,cAAc,UACpB,KAAK,KAAK,KAAK,cAAc,YAAY,mBAAmB,GAAG,EAC7D,SAAS,KAAK,KAAK,MAAM,EAC3B,CAAC,IACD,MAAM,SAAS,UACb,KAAK,KAAK,eAAe,eAAe,YAAY,IACpD,KAAK,KAAK,SAAS,UAAU,SAAS;CAC9C;AACF"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Beacons: the URLs an ad asks the player to request when something
3
+ * happens, with their macros filled (VAST 4.3 §6). Each is sent once, and
4
+ * its answer is not read.
5
+ */
6
+ /** What the macros of a beacon read. */
7
+ export interface MacroValues {
8
+ /** VAST error code, for `[ERRORCODE]`. */
9
+ readonly errorCode?: number;
10
+ /** Seconds into the programme, for `[MEDIAPLAYHEAD]` and VAST 3's `[CONTENTPLAYHEAD]`. */
11
+ readonly mediaPlayhead?: number;
12
+ /** Seconds into the ad, for `[ADPLAYHEAD]`. */
13
+ readonly adPlayhead?: number;
14
+ /** The media file that plays, for `[ASSETURI]`. */
15
+ readonly assetUri?: string;
16
+ /** 1 before the programme, 2 during it, 3 after it, for `[BREAKPOSITION]`. */
17
+ readonly breakPosition?: 1 | 2 | 3;
18
+ /** The player's width and height in CSS pixels, for `[PLAYERSIZE]`. */
19
+ readonly playerSize?: readonly [number, number];
20
+ }
21
+ /** The beacon URL with every macro filled. A macro the player cannot fill becomes -1, as VAST 4.3 §6.1 asks. */
22
+ export declare function expand(url: string, values: MacroValues): string;
23
+ /**
24
+ * Requests a beacon. `no-cors`, because an ad server rarely answers with
25
+ * CORS headers, and `keepalive`, so one sent as the page closes still
26
+ * goes.
27
+ */
28
+ export declare function send(url: string): void;
29
+ //# sourceMappingURL=beacons.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beacons.d.ts","sourceRoot":"","sources":["../src/beacons.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,wCAAwC;AACxC,MAAM,WAAW,WAAW;IAC1B,0CAA0C;IAC1C,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,0FAA0F;IAC1F,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,+CAA+C;IAC/C,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,mDAAmD;IACnD,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,8EAA8E;IAC9E,QAAQ,CAAC,aAAa,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACnC,uEAAuE;IACvE,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjD;AASD,gHAAgH;AAChH,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,WAAW,GAAG,MAAM,CA2B/D;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAMtC"}
@@ -0,0 +1,44 @@
1
+ // src/beacons.ts
2
+ /** `HH:MM:SS.mmm`, the time form VAST macros take. */
3
+ function timecode(seconds) {
4
+ const ms = Math.max(0, Math.round(seconds * 1e3));
5
+ const pad = (n, width = 2) => String(n).padStart(width, "0");
6
+ return `${pad(Math.floor(ms / 36e5))}:${pad(Math.floor(ms / 6e4) % 60)}:${pad(Math.floor(ms / 1e3) % 60)}.${pad(ms % 1e3, 3)}`;
7
+ }
8
+ /** The beacon URL with every macro filled. A macro the player cannot fill becomes -1, as VAST 4.3 §6.1 asks. */
9
+ function expand(url, values) {
10
+ return url.replace(/\[([A-Z_]+)\]/g, (_, name) => {
11
+ const value = (() => {
12
+ switch (name) {
13
+ case "CACHEBUSTING": return String(Math.floor(1e7 + Math.random() * 89999999));
14
+ case "TIMESTAMP": return (/* @__PURE__ */ new Date()).toISOString();
15
+ case "ERRORCODE": return values.errorCode === void 0 ? void 0 : String(values.errorCode);
16
+ case "MEDIAPLAYHEAD":
17
+ case "CONTENTPLAYHEAD": return values.mediaPlayhead === void 0 ? void 0 : timecode(values.mediaPlayhead);
18
+ case "ADPLAYHEAD": return values.adPlayhead === void 0 ? void 0 : timecode(values.adPlayhead);
19
+ case "ASSETURI": return values.assetUri;
20
+ case "BREAKPOSITION": return values.breakPosition === void 0 ? void 0 : String(values.breakPosition);
21
+ case "PLAYERSIZE": return values.playerSize === void 0 ? void 0 : values.playerSize.join(",");
22
+ default: return;
23
+ }
24
+ })();
25
+ return encodeURIComponent(value ?? "-1");
26
+ });
27
+ }
28
+ /**
29
+ * Requests a beacon. `no-cors`, because an ad server rarely answers with
30
+ * CORS headers, and `keepalive`, so one sent as the page closes still
31
+ * goes.
32
+ */
33
+ function send(url) {
34
+ try {
35
+ fetch(url, {
36
+ mode: "no-cors",
37
+ keepalive: true,
38
+ credentials: "include"
39
+ }).catch(() => {});
40
+ } catch {}
41
+ }
42
+ export { expand, send };
43
+
44
+ //# sourceMappingURL=beacons.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"beacons.js","names":[],"sources":["../src/beacons.ts"],"sourcesContent":["/**\n * Beacons: the URLs an ad asks the player to request when something\n * happens, with their macros filled (VAST 4.3 §6). Each is sent once, and\n * its answer is not read.\n */\n\n/** What the macros of a beacon read. */\nexport interface MacroValues {\n /** VAST error code, for `[ERRORCODE]`. */\n readonly errorCode?: number;\n /** Seconds into the programme, for `[MEDIAPLAYHEAD]` and VAST 3's `[CONTENTPLAYHEAD]`. */\n readonly mediaPlayhead?: number;\n /** Seconds into the ad, for `[ADPLAYHEAD]`. */\n readonly adPlayhead?: number;\n /** The media file that plays, for `[ASSETURI]`. */\n readonly assetUri?: string;\n /** 1 before the programme, 2 during it, 3 after it, for `[BREAKPOSITION]`. */\n readonly breakPosition?: 1 | 2 | 3;\n /** The player's width and height in CSS pixels, for `[PLAYERSIZE]`. */\n readonly playerSize?: readonly [number, number];\n}\n\n/** `HH:MM:SS.mmm`, the time form VAST macros take. */\nfunction timecode(seconds: number): string {\n const ms = Math.max(0, Math.round(seconds * 1000));\n const pad = (n: number, width = 2): string => String(n).padStart(width, '0');\n return `${pad(Math.floor(ms / 3_600_000))}:${pad(Math.floor(ms / 60_000) % 60)}:${pad(Math.floor(ms / 1000) % 60)}.${pad(ms % 1000, 3)}`;\n}\n\n/** The beacon URL with every macro filled. A macro the player cannot fill becomes -1, as VAST 4.3 §6.1 asks. */\nexport function expand(url: string, values: MacroValues): string {\n return url.replace(/\\[([A-Z_]+)\\]/g, (_, name: string) => {\n const value = ((): string | undefined => {\n switch (name) {\n case 'CACHEBUSTING':\n return String(Math.floor(10_000_000 + Math.random() * 89_999_999));\n case 'TIMESTAMP':\n return new Date().toISOString();\n case 'ERRORCODE':\n return values.errorCode === undefined ? undefined : String(values.errorCode);\n case 'MEDIAPLAYHEAD':\n case 'CONTENTPLAYHEAD':\n return values.mediaPlayhead === undefined ? undefined : timecode(values.mediaPlayhead);\n case 'ADPLAYHEAD':\n return values.adPlayhead === undefined ? undefined : timecode(values.adPlayhead);\n case 'ASSETURI':\n return values.assetUri;\n case 'BREAKPOSITION':\n return values.breakPosition === undefined ? undefined : String(values.breakPosition);\n case 'PLAYERSIZE':\n return values.playerSize === undefined ? undefined : values.playerSize.join(',');\n default:\n return undefined;\n }\n })();\n return encodeURIComponent(value ?? '-1');\n });\n}\n\n/**\n * Requests a beacon. `no-cors`, because an ad server rarely answers with\n * CORS headers, and `keepalive`, so one sent as the page closes still\n * goes.\n */\nexport function send(url: string): void {\n try {\n void fetch(url, { mode: 'no-cors', keepalive: true, credentials: 'include' }).catch(() => {});\n } catch {\n // A URL fetch refuses is the ad server's mistake; the ad plays on.\n }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