@mattebox/player 0.13.1 → 0.14.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.
@@ -1,17 +1,28 @@
1
1
  // src/controls/pip.ts
2
- function watching(target, names) {
2
+ /** The attribute that turns picture in picture off for one video. */
3
+ const DISABLE = "disablepictureinpicture";
4
+ /** Watches `names` on the video, and the attribute that turns the feature off. */
5
+ function watching(video, names) {
3
6
  return (fn) => {
4
- for (const name of names) target.addEventListener(name, fn);
7
+ for (const name of names) video.addEventListener(name, fn);
8
+ const observer = new MutationObserver(fn);
9
+ observer.observe(video, {
10
+ attributes: true,
11
+ attributeFilter: [DISABLE]
12
+ });
5
13
  return () => {
6
- for (const name of names) target.removeEventListener(name, fn);
14
+ for (const name of names) video.removeEventListener(name, fn);
15
+ observer.disconnect();
7
16
  };
8
17
  };
9
18
  }
10
19
  function pictureInPicture(video) {
11
20
  var _safari$webkitSupport;
12
21
  const safari = video;
22
+ const allowed = () => !video.hasAttribute(DISABLE);
13
23
  if (typeof video.requestPictureInPicture === "function" && document.pictureInPictureEnabled) return {
14
24
  supported: true,
25
+ allowed,
15
26
  active: () => document.pictureInPictureElement === video,
16
27
  toggle() {
17
28
  (document.pictureInPictureElement === video ? document.exitPictureInPicture() : video.requestPictureInPicture()).catch(() => void 0);
@@ -20,6 +31,7 @@ function pictureInPicture(video) {
20
31
  };
21
32
  if (typeof safari.webkitSetPresentationMode === "function" && ((_safari$webkitSupport = safari.webkitSupportsPresentationMode) === null || _safari$webkitSupport === void 0 ? void 0 : _safari$webkitSupport.call(safari, "picture-in-picture")) === true) return {
22
33
  supported: true,
34
+ allowed,
23
35
  active: () => safari.webkitPresentationMode === "picture-in-picture",
24
36
  toggle() {
25
37
  var _safari$webkitSetPres;
@@ -30,6 +42,7 @@ function pictureInPicture(video) {
30
42
  };
31
43
  return {
32
44
  supported: false,
45
+ allowed,
33
46
  active: () => false,
34
47
  toggle() {},
35
48
  watch: () => () => {}
@@ -21,12 +21,17 @@ import { createPlayer, inferType, matteboxHandler, nativeHandler, preferNativeHl
21
21
  * fullscreen then work as Apple built them. Changing it reloads.
22
22
  */
23
23
  const NATIVE_HLS = "native-hls";
24
- /** Attributes forwarded onto the video as attributes, never as properties. */
24
+ /**
25
+ * Attributes forwarded onto the video as attributes, never as properties.
26
+ * `disablepictureinpicture` also hides the browser's own picture-in-picture
27
+ * toggle, which Firefox draws over every video that lacks it.
28
+ */
25
29
  const FORWARDED = [
26
30
  "autoplay",
27
31
  "muted",
28
32
  "poster",
29
- "crossorigin"
33
+ "crossorigin",
34
+ "disablepictureinpicture"
30
35
  ];
31
36
  const LICENSE_URL = "license-url";
32
37
  /** The language the page chose, over the nearest `lang`. */
@@ -5,7 +5,8 @@ import { pictureInPicture } from "../controls/pip.js";
5
5
  // src/elements/pip-button.ts
6
6
  /**
7
7
  * <mbx-pip-button>: picture in picture, through whichever API the browser
8
- * has, and hidden where there is none. The glyph is `icon-enter` or
8
+ * has, and hidden where there is none or the player has
9
+ * `disablepictureinpicture`. The glyph is `icon-enter` or
9
10
  * `icon-exit`, the name `label-enter` or `label-exit`, and the element
10
11
  * sets `pip` on the player while the video is in the floating window.
11
12
  */
@@ -32,7 +33,6 @@ var MbxPipButton = class extends Component {
32
33
  attach(player) {
33
34
  const api = pictureInPicture(player.video);
34
35
  this.api = api;
35
- this.hidden = !api.supported;
36
36
  this.keep(api.watch(() => {
37
37
  this.render();
38
38
  }));
@@ -46,6 +46,7 @@ var MbxPipButton = class extends Component {
46
46
  const player = this.player;
47
47
  if (player === null || this.api === null) return;
48
48
  const active = this.api.active();
49
+ this.hidden = !this.api.supported || !this.api.allowed() && !active;
49
50
  show(this.slots, active ? "exit" : "enter");
50
51
  this.button.setAttribute("aria-label", active ? this.word("label-exit", "exitPip", "Leave picture in picture") : this.word("label-enter", "enterPip", "Picture in picture"));
51
52
  player.toggleAttribute("pip", active);
@@ -2,9 +2,8 @@
2
2
  * The trackers of one player: what the page added, started at each
3
3
  * programme and stopped at its end. The page decides which trackers run,
4
4
  * and when it adds or removes them; the player only starts and stops them.
5
- * The lifecycle is pillarbox-apple's `PlayerItemTracker`, enable at the
6
- * start of an item and disable at its end, without its tracking switch:
7
- * consent is the page's to decide.
5
+ * A tracker is enabled at the start of a programme and disabled at its
6
+ * end. The player has no tracking switch: consent is the page's to decide.
8
7
  */
9
8
  import type { Programme } from '@mattebox/player-core';
10
9
  import type { PlayerHost, Tracker, Trackers } from './host.js';
@@ -1 +1 @@
1
- {"version":3,"file":"trackers.d.ts","sourceRoot":"","sources":["../src/trackers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE/D,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAElC,8EAA8E;AAC9E,MAAM,WAAW,aAAc,SAAQ,QAAQ;IAC7C,KAAK,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;CAC1C;AAaD,2FAA2F;AAC3F,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,aAAa,CA8BnF"}
1
+ {"version":3,"file":"trackers.d.ts","sourceRoot":"","sources":["../src/trackers.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,KAAK,EAAE,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE/D,YAAY,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;AAElC,8EAA8E;AAC9E,MAAM,WAAW,aAAc,SAAQ,QAAQ;IAC7C,KAAK,CAAC,SAAS,EAAE,SAAS,GAAG,IAAI,GAAG,IAAI,CAAC;CAC1C;AAaD,2FAA2F;AAC3F,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,IAAI,GAAG,aAAa,CA8BnF"}
@@ -1 +1 @@
1
- {"version":3,"file":"trackers.js","names":[],"sources":["../src/trackers.ts"],"sourcesContent":["/**\n * The trackers of one player: what the page added, started at each\n * programme and stopped at its end. The page decides which trackers run,\n * and when it adds or removes them; the player only starts and stops them.\n * The lifecycle is pillarbox-apple's `PlayerItemTracker`, enable at the\n * start of an item and disable at its end, without its tracking switch:\n * consent is the page's to decide.\n */\nimport type { Programme } from '@mattebox/player-core';\nimport type { PlayerHost, Tracker, Trackers } from './host.js';\n\nexport type { Tracker, Trackers };\n\n/** What the element drives: the programme that starts, or null at its end. */\nexport interface TrackerRunner extends Trackers {\n begin(programme: Programme | null): void;\n}\n\n/** Runs `fn`, and throws its error on a task of its own: one tracker's bug stops neither playback nor the others. */\nfunction guard(fn: () => void): void {\n try {\n fn();\n } catch (error) {\n setTimeout(() => {\n throw error;\n });\n }\n}\n\n/** The trackers of `host`. `changed` runs after each start, stop, addition and removal. */\nexport function createTrackers(host: PlayerHost, changed: () => void): TrackerRunner {\n const set = new Set<Tracker>();\n let current: Programme | null = null;\n return {\n add(tracker) {\n if (set.has(tracker)) return;\n set.add(tracker);\n const programme = current;\n if (programme !== null) guard(() => tracker.start(programme, host));\n changed();\n },\n delete(tracker) {\n if (!set.delete(tracker)) return false;\n if (current !== null) guard(() => tracker.stop());\n changed();\n return true;\n },\n has: (tracker) => set.has(tracker),\n get list() {\n return [...set];\n },\n begin(programme) {\n if (current === null && programme === null) return;\n if (current !== null) for (const tracker of set) guard(() => tracker.stop());\n current = programme;\n if (programme !== null)\n for (const tracker of set) guard(() => tracker.start(programme, host));\n changed();\n },\n };\n}\n"],"mappings":";;AAmBA,SAAS,MAAM,IAAsB;CACnC,IAAI;EACF,GAAG;CACL,SAAS,OAAO;EACd,iBAAiB;GACf,MAAM;EACR,CAAC;CACH;AACF;;AAGA,SAAgB,eAAe,MAAkB,SAAoC;CACnF,MAAM,sBAAM,IAAI,IAAa;CAC7B,IAAI,UAA4B;CAChC,OAAO;EACL,IAAI,SAAS;GACX,IAAI,IAAI,IAAI,OAAO,GAAG;GACtB,IAAI,IAAI,OAAO;GACf,MAAM,YAAY;GAClB,IAAI,cAAc,MAAM,YAAY,QAAQ,MAAM,WAAW,IAAI,CAAC;GAClE,QAAQ;EACV;EACA,OAAO,SAAS;GACd,IAAI,CAAC,IAAI,OAAO,OAAO,GAAG,OAAO;GACjC,IAAI,YAAY,MAAM,YAAY,QAAQ,KAAK,CAAC;GAChD,QAAQ;GACR,OAAO;EACT;EACA,MAAM,YAAY,IAAI,IAAI,OAAO;EACjC,IAAI,OAAO;GACT,OAAO,CAAC,GAAG,GAAG;EAChB;EACA,MAAM,WAAW;GACf,IAAI,YAAY,QAAQ,cAAc,MAAM;GAC5C,IAAI,YAAY,MAAM,KAAK,MAAM,WAAW,KAAK,YAAY,QAAQ,KAAK,CAAC;GAC3E,UAAU;GACV,IAAI,cAAc,MAChB,KAAK,MAAM,WAAW,KAAK,YAAY,QAAQ,MAAM,WAAW,IAAI,CAAC;GACvE,QAAQ;EACV;CACF;AACF"}
1
+ {"version":3,"file":"trackers.js","names":[],"sources":["../src/trackers.ts"],"sourcesContent":["/**\n * The trackers of one player: what the page added, started at each\n * programme and stopped at its end. The page decides which trackers run,\n * and when it adds or removes them; the player only starts and stops them.\n * A tracker is enabled at the start of a programme and disabled at its\n * end. The player has no tracking switch: consent is the page's to decide.\n */\nimport type { Programme } from '@mattebox/player-core';\nimport type { PlayerHost, Tracker, Trackers } from './host.js';\n\nexport type { Tracker, Trackers };\n\n/** What the element drives: the programme that starts, or null at its end. */\nexport interface TrackerRunner extends Trackers {\n begin(programme: Programme | null): void;\n}\n\n/** Runs `fn`, and throws its error on a task of its own: one tracker's bug stops neither playback nor the others. */\nfunction guard(fn: () => void): void {\n try {\n fn();\n } catch (error) {\n setTimeout(() => {\n throw error;\n });\n }\n}\n\n/** The trackers of `host`. `changed` runs after each start, stop, addition and removal. */\nexport function createTrackers(host: PlayerHost, changed: () => void): TrackerRunner {\n const set = new Set<Tracker>();\n let current: Programme | null = null;\n return {\n add(tracker) {\n if (set.has(tracker)) return;\n set.add(tracker);\n const programme = current;\n if (programme !== null) guard(() => tracker.start(programme, host));\n changed();\n },\n delete(tracker) {\n if (!set.delete(tracker)) return false;\n if (current !== null) guard(() => tracker.stop());\n changed();\n return true;\n },\n has: (tracker) => set.has(tracker),\n get list() {\n return [...set];\n },\n begin(programme) {\n if (current === null && programme === null) return;\n if (current !== null) for (const tracker of set) guard(() => tracker.stop());\n current = programme;\n if (programme !== null)\n for (const tracker of set) guard(() => tracker.start(programme, host));\n changed();\n },\n };\n}\n"],"mappings":";;AAkBA,SAAS,MAAM,IAAsB;CACnC,IAAI;EACF,GAAG;CACL,SAAS,OAAO;EACd,iBAAiB;GACf,MAAM;EACR,CAAC;CACH;AACF;;AAGA,SAAgB,eAAe,MAAkB,SAAoC;CACnF,MAAM,sBAAM,IAAI,IAAa;CAC7B,IAAI,UAA4B;CAChC,OAAO;EACL,IAAI,SAAS;GACX,IAAI,IAAI,IAAI,OAAO,GAAG;GACtB,IAAI,IAAI,OAAO;GACf,MAAM,YAAY;GAClB,IAAI,cAAc,MAAM,YAAY,QAAQ,MAAM,WAAW,IAAI,CAAC;GAClE,QAAQ;EACV;EACA,OAAO,SAAS;GACd,IAAI,CAAC,IAAI,OAAO,OAAO,GAAG,OAAO;GACjC,IAAI,YAAY,MAAM,YAAY,QAAQ,KAAK,CAAC;GAChD,QAAQ;GACR,OAAO;EACT;EACA,MAAM,YAAY,IAAI,IAAI,OAAO;EACjC,IAAI,OAAO;GACT,OAAO,CAAC,GAAG,GAAG;EAChB;EACA,MAAM,WAAW;GACf,IAAI,YAAY,QAAQ,cAAc,MAAM;GAC5C,IAAI,YAAY,MAAM,KAAK,MAAM,WAAW,KAAK,YAAY,QAAQ,KAAK,CAAC;GAC3E,UAAU;GACV,IAAI,cAAc,MAChB,KAAK,MAAM,WAAW,KAAK,YAAY,QAAQ,MAAM,WAAW,IAAI,CAAC;GACvE,QAAQ;EACV;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mattebox/player",
3
- "version": "0.13.1",
3
+ "version": "0.14.0",
4
4
  "description": "A <mattebox-player> custom element over @mattebox/player-core.",
5
5
  "author": "Josep Boix Requesens",
6
6
  "repository": {