@hanifhan1f/vidstack 1.12.19 → 1.12.24

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 (107) hide show
  1. package/cdn/chunks/vidstack-BF7lZRtq.js +3 -0
  2. package/cdn/chunks/vidstack-BYpysj84.js +1 -0
  3. package/cdn/chunks/vidstack-C1FlyyzK.js +1 -0
  4. package/cdn/chunks/vidstack-Cj0I-Rec.js +1 -0
  5. package/cdn/chunks/vidstack-D84Fzc__.js +16 -0
  6. package/cdn/chunks/vidstack-DQvyz7Mm.js +1 -0
  7. package/cdn/chunks/vidstack-Dd9fqVv6.js +1 -0
  8. package/cdn/chunks/vidstack-uMxrPflF.js +1 -0
  9. package/cdn/chunks/vidstack-zemsqC5d.js +1 -0
  10. package/cdn/providers/vidstack-audio-BOGYlExy.js +1 -0
  11. package/cdn/providers/vidstack-dash-D4ZARr66.js +1 -0
  12. package/cdn/providers/vidstack-hls-8-552IuX.js +1 -0
  13. package/cdn/providers/vidstack-html-BvVaN2VT.js +1 -0
  14. package/cdn/providers/vidstack-video-BnwQZKER.js +1 -0
  15. package/cdn/providers/vidstack-vimeo-gJmBqtLK.js +1 -0
  16. package/cdn/providers/vidstack-youtube-Chl_dTAz.js +1 -0
  17. package/cdn/vidstack.js +1 -1
  18. package/cdn/with-layouts/chunks/vidstack-4liSokT6.js +1 -0
  19. package/cdn/with-layouts/chunks/vidstack-B97B8XDc.js +3 -0
  20. package/cdn/with-layouts/chunks/vidstack-BbFHhcVG.js +1 -0
  21. package/cdn/with-layouts/chunks/vidstack-CXEcXyBI.js +1 -0
  22. package/cdn/with-layouts/chunks/vidstack-Ciq-n5rg.js +1 -0
  23. package/cdn/with-layouts/chunks/vidstack-CmuGllcj.js +1 -0
  24. package/cdn/with-layouts/chunks/vidstack-CyNByJUW.js +912 -0
  25. package/cdn/with-layouts/chunks/vidstack-DhNpv7SU.js +1 -0
  26. package/cdn/with-layouts/providers/vidstack-audio-CwoQJvl2.js +1 -0
  27. package/cdn/with-layouts/providers/vidstack-dash-CJsKJfLI.js +1 -0
  28. package/cdn/with-layouts/providers/vidstack-hls-ji26kFdQ.js +1 -0
  29. package/cdn/with-layouts/providers/vidstack-html-BvHMxtoe.js +1 -0
  30. package/cdn/with-layouts/providers/vidstack-video-1Uj5cNP2.js +1 -0
  31. package/cdn/with-layouts/providers/vidstack-vimeo-DACTbJaQ.js +1 -0
  32. package/cdn/with-layouts/providers/vidstack-youtube-RoLp-I6u.js +1 -0
  33. package/cdn/with-layouts/vidstack.js +1 -1
  34. package/dev/chunks/vidstack-0XhA3AD_.js +5181 -0
  35. package/dev/chunks/vidstack-5oWWZmVl.js +58 -0
  36. package/dev/chunks/vidstack-BnBLcaA5.js +115 -0
  37. package/dev/chunks/vidstack-Bo8BNFJ2.js +2986 -0
  38. package/dev/chunks/vidstack-C3N4zIuV.js +254 -0
  39. package/dev/chunks/vidstack-CAL4iu_K.js +1482 -0
  40. package/dev/chunks/vidstack-CGyAjz8G.js +58 -0
  41. package/dev/chunks/vidstack-CJCnHmKE.js +104 -0
  42. package/dev/chunks/vidstack-CzCQJ29U.js +107 -0
  43. package/dev/chunks/vidstack-DD_3HszA.js +1520 -0
  44. package/dev/chunks/vidstack-DV4g4XvL.js +33 -0
  45. package/dev/chunks/vidstack-D_LvMxPr.js +204 -0
  46. package/dev/chunks/vidstack-DdTXMZro.js +66 -0
  47. package/dev/chunks/vidstack-DrczgsqN.js +297 -0
  48. package/dev/chunks/vidstack-gF_qqvCK.js +109 -0
  49. package/dev/define/plyr-layout.js +7 -7
  50. package/dev/define/templates/plyr-layout.js +2 -2
  51. package/dev/define/templates/vidstack-audio-layout.js +3 -3
  52. package/dev/define/templates/vidstack-video-layout.js +7 -9
  53. package/dev/define/vidstack-player-default-layout.js +3 -3
  54. package/dev/define/vidstack-player-layouts.js +3 -3
  55. package/dev/define/vidstack-player-ui.js +9 -9
  56. package/dev/define/vidstack-player.js +5 -5
  57. package/dev/global/plyr.js +9 -9
  58. package/dev/global/vidstack-player.js +6 -6
  59. package/dev/providers/vidstack-audio.js +2 -2
  60. package/dev/providers/vidstack-dash.js +4 -4
  61. package/dev/providers/vidstack-hls.js +4 -4
  62. package/dev/providers/vidstack-html.js +1 -1
  63. package/dev/providers/vidstack-video.js +4 -4
  64. package/dev/providers/vidstack-vimeo.js +4 -4
  65. package/dev/providers/vidstack-youtube.js +3 -3
  66. package/dev/vidstack-elements.js +12 -12
  67. package/dev/vidstack.js +9 -9
  68. package/package.json +1 -1
  69. package/player/styles/default/layouts/video.css +113 -79
  70. package/prod/chunks/vidstack-BAqdCFIm.js +4771 -0
  71. package/prod/chunks/vidstack-BRnfTkxi.js +297 -0
  72. package/prod/chunks/vidstack-BexQYZop.js +2976 -0
  73. package/prod/chunks/vidstack-Bf1Q6kqO.js +109 -0
  74. package/prod/chunks/vidstack-Bn9yLryd.js +58 -0
  75. package/prod/chunks/vidstack-C4PTiuot.js +107 -0
  76. package/prod/chunks/vidstack-DMDDSV3t.js +104 -0
  77. package/prod/chunks/vidstack-Dg71uhRc.js +58 -0
  78. package/prod/chunks/vidstack-DlLwMLBL.js +33 -0
  79. package/prod/chunks/vidstack-KShKSmYu.js +66 -0
  80. package/prod/chunks/vidstack-ShUhyBfI.js +201 -0
  81. package/prod/chunks/vidstack-V9U6gsde.js +1482 -0
  82. package/prod/chunks/vidstack-kdaDngIm.js +1520 -0
  83. package/prod/chunks/vidstack-oNEzlviH.js +246 -0
  84. package/prod/chunks/vidstack-wTTCvdqe.js +115 -0
  85. package/prod/define/plyr-layout.js +7 -7
  86. package/prod/define/templates/plyr-layout.js +2 -2
  87. package/prod/define/templates/vidstack-audio-layout.js +3 -3
  88. package/prod/define/templates/vidstack-video-layout.js +7 -9
  89. package/prod/define/vidstack-player-default-layout.js +3 -3
  90. package/prod/define/vidstack-player-layouts.js +3 -3
  91. package/prod/define/vidstack-player-ui.js +9 -9
  92. package/prod/define/vidstack-player.js +5 -5
  93. package/prod/global/plyr.js +9 -9
  94. package/prod/global/vidstack-player.js +6 -6
  95. package/prod/providers/vidstack-audio.js +2 -2
  96. package/prod/providers/vidstack-dash.js +4 -4
  97. package/prod/providers/vidstack-hls.js +4 -4
  98. package/prod/providers/vidstack-html.js +1 -1
  99. package/prod/providers/vidstack-video.js +4 -4
  100. package/prod/providers/vidstack-vimeo.js +4 -4
  101. package/prod/providers/vidstack-youtube.js +3 -3
  102. package/prod/vidstack-elements.js +12 -12
  103. package/prod/vidstack.js +9 -9
  104. package/server/chunks/vidstack-B2Bc9g7_.js +2000 -0
  105. package/server/define/vidstack-player-default-layout.js +1 -1
  106. package/server/define/vidstack-player-layouts.js +1 -1
  107. package/server/vidstack-elements.js +1 -1
@@ -0,0 +1,109 @@
1
+ import { IS_CHROME, IS_IOS, canGoogleCastSrc } from './vidstack-wTTCvdqe.js';
2
+ import { loadScript } from './vidstack-KShKSmYu.js';
3
+ import { getCastContext, getCastSession, isCastConnected, hasLoadedCastFramework, getCastFrameworkURL, isCastAvailable, getCastErrorMessage, getDefaultCastOptions } from './vidstack-9_r3lWNO.js';
4
+ import { peek } from './vidstack-BNpgCJJ1.js';
5
+
6
+ class GoogleCastLoader {
7
+ name = "google-cast";
8
+ target;
9
+ #player;
10
+ /**
11
+ * @see {@link https://developers.google.com/cast/docs/reference/web_sender/cast.framework.CastContext}
12
+ */
13
+ get cast() {
14
+ return getCastContext();
15
+ }
16
+ mediaType() {
17
+ return "video";
18
+ }
19
+ canPlay(src) {
20
+ return IS_CHROME && !IS_IOS && canGoogleCastSrc(src);
21
+ }
22
+ async prompt(ctx) {
23
+ let loadEvent, openEvent, errorEvent;
24
+ try {
25
+ loadEvent = await this.#loadCastFramework(ctx);
26
+ if (!this.#player) {
27
+ this.#player = new cast.framework.RemotePlayer();
28
+ new cast.framework.RemotePlayerController(this.#player);
29
+ }
30
+ openEvent = ctx.player.createEvent("google-cast-prompt-open", {
31
+ trigger: loadEvent
32
+ });
33
+ ctx.player.dispatchEvent(openEvent);
34
+ this.#notifyRemoteStateChange(ctx, "connecting", openEvent);
35
+ await this.#showPrompt(peek(ctx.$props.googleCast));
36
+ ctx.$state.remotePlaybackInfo.set({
37
+ deviceName: getCastSession()?.getCastDevice().friendlyName
38
+ });
39
+ if (isCastConnected()) this.#notifyRemoteStateChange(ctx, "connected", openEvent);
40
+ } catch (code) {
41
+ const error = code instanceof Error ? code : this.#createError(
42
+ (code + "").toUpperCase(),
43
+ "Prompt failed."
44
+ );
45
+ errorEvent = ctx.player.createEvent("google-cast-prompt-error", {
46
+ detail: error,
47
+ trigger: openEvent ?? loadEvent,
48
+ cancelable: true
49
+ });
50
+ ctx.player.dispatch(errorEvent);
51
+ this.#notifyRemoteStateChange(
52
+ ctx,
53
+ isCastConnected() ? "connected" : "disconnected",
54
+ errorEvent
55
+ );
56
+ throw error;
57
+ } finally {
58
+ ctx.player.dispatch("google-cast-prompt-close", {
59
+ trigger: errorEvent ?? openEvent ?? loadEvent
60
+ });
61
+ }
62
+ }
63
+ async load(ctx) {
64
+ if (!this.#player) {
65
+ throw Error("[vidstack] google cast player was not initialized");
66
+ }
67
+ return new (await import('../providers/vidstack-google-cast.js')).GoogleCastProvider(this.#player, ctx);
68
+ }
69
+ async #loadCastFramework(ctx) {
70
+ if (hasLoadedCastFramework()) return;
71
+ const loadStartEvent = ctx.player.createEvent("google-cast-load-start");
72
+ ctx.player.dispatch(loadStartEvent);
73
+ await loadScript(getCastFrameworkURL());
74
+ await customElements.whenDefined("google-cast-launcher");
75
+ const loadedEvent = ctx.player.createEvent("google-cast-loaded", { trigger: loadStartEvent });
76
+ ctx.player.dispatch(loadedEvent);
77
+ if (!isCastAvailable()) {
78
+ throw this.#createError("CAST_NOT_AVAILABLE", "Google Cast not available on this platform.");
79
+ }
80
+ return loadedEvent;
81
+ }
82
+ async #showPrompt(options) {
83
+ this.#setOptions(options);
84
+ const errorCode = await this.cast.requestSession();
85
+ if (errorCode) {
86
+ throw this.#createError(
87
+ errorCode.toUpperCase(),
88
+ getCastErrorMessage(errorCode)
89
+ );
90
+ }
91
+ }
92
+ #setOptions(options) {
93
+ this.cast?.setOptions({
94
+ ...getDefaultCastOptions(),
95
+ ...options
96
+ });
97
+ }
98
+ #notifyRemoteStateChange(ctx, state, trigger) {
99
+ const detail = { type: "google-cast", state };
100
+ ctx.notify("remote-playback-change", detail, trigger);
101
+ }
102
+ #createError(code, message) {
103
+ const error = Error(message);
104
+ error.code = code;
105
+ return error;
106
+ }
107
+ }
108
+
109
+ export { GoogleCastLoader };
@@ -0,0 +1,58 @@
1
+ import { signal, effect, listenEvent, EventsController } from './vidstack-BNpgCJJ1.js';
2
+ import './vidstack-wTTCvdqe.js';
3
+
4
+ class HTMLRemotePlaybackAdapter {
5
+ #media;
6
+ #ctx;
7
+ #state;
8
+ #supported = signal(false);
9
+ get supported() {
10
+ return this.#supported();
11
+ }
12
+ constructor(media, ctx) {
13
+ this.#media = media;
14
+ this.#ctx = ctx;
15
+ this.#setup();
16
+ }
17
+ #setup() {
18
+ if (!this.#media?.remote || !this.canPrompt) return;
19
+ this.#media.remote.watchAvailability((available) => {
20
+ this.#supported.set(available);
21
+ }).catch(() => {
22
+ this.#supported.set(false);
23
+ });
24
+ effect(this.#watchSupported.bind(this));
25
+ }
26
+ #watchSupported() {
27
+ if (!this.#supported()) return;
28
+ const events = ["connecting", "connect", "disconnect"], onStateChange = this.#onStateChange.bind(this);
29
+ onStateChange();
30
+ listenEvent(this.#media, "playing", onStateChange);
31
+ const remoteEvents = new EventsController(this.#media.remote);
32
+ for (const type of events) {
33
+ remoteEvents.add(type, onStateChange);
34
+ }
35
+ }
36
+ async prompt() {
37
+ if (!this.supported) throw Error("Not supported on this platform.");
38
+ if (this.type === "airplay" && this.#media.webkitShowPlaybackTargetPicker) {
39
+ return this.#media.webkitShowPlaybackTargetPicker();
40
+ }
41
+ return this.#media.remote.prompt();
42
+ }
43
+ #onStateChange(event) {
44
+ const state = this.#media.remote.state;
45
+ if (state === this.#state) return;
46
+ const detail = { type: this.type, state };
47
+ this.#ctx.notify("remote-playback-change", detail, event);
48
+ this.#state = state;
49
+ }
50
+ }
51
+ class HTMLAirPlayAdapter extends HTMLRemotePlaybackAdapter {
52
+ type = "airplay";
53
+ get canPrompt() {
54
+ return "WebKitPlaybackTargetAvailabilityEvent" in window;
55
+ }
56
+ }
57
+
58
+ export { HTMLAirPlayAdapter };
@@ -0,0 +1,107 @@
1
+ import { Component, State, effect, isNull, setAttribute, EventsController } from './vidstack-BNpgCJJ1.js';
2
+ import { useMediaContext } from './vidstack-tt3O1zL6.js';
3
+ import { preconnect } from './vidstack-KShKSmYu.js';
4
+
5
+ class Poster extends Component {
6
+ static props = {
7
+ src: null,
8
+ alt: null,
9
+ crossOrigin: null
10
+ };
11
+ static state = new State({
12
+ img: null,
13
+ src: null,
14
+ alt: null,
15
+ crossOrigin: null,
16
+ loading: true,
17
+ error: null,
18
+ hidden: false
19
+ });
20
+ #media;
21
+ onSetup() {
22
+ this.#media = useMediaContext();
23
+ this.#watchSrc();
24
+ this.#watchAlt();
25
+ this.#watchCrossOrigin();
26
+ this.#watchHidden();
27
+ }
28
+ onAttach(el) {
29
+ el.style.setProperty("pointer-events", "none");
30
+ effect(this.#watchImg.bind(this));
31
+ effect(this.#watchSrc.bind(this));
32
+ effect(this.#watchAlt.bind(this));
33
+ effect(this.#watchCrossOrigin.bind(this));
34
+ effect(this.#watchHidden.bind(this));
35
+ const { started } = this.#media.$state;
36
+ this.setAttributes({
37
+ "data-visible": () => !started() && !this.$state.hidden(),
38
+ "data-loading": this.#isLoading.bind(this),
39
+ "data-error": this.#hasError.bind(this),
40
+ "data-hidden": this.$state.hidden
41
+ });
42
+ }
43
+ onConnect(el) {
44
+ effect(this.#onPreconnect.bind(this));
45
+ effect(this.#onLoadStart.bind(this));
46
+ }
47
+ #hasError() {
48
+ const { error } = this.$state;
49
+ return !isNull(error());
50
+ }
51
+ #onPreconnect() {
52
+ const { canLoadPoster, poster } = this.#media.$state;
53
+ if (!canLoadPoster() && poster()) preconnect(poster(), "preconnect");
54
+ }
55
+ #watchHidden() {
56
+ const { src } = this.$props, { poster, nativeControls } = this.#media.$state;
57
+ this.el && setAttribute(this.el, "display", nativeControls() ? "none" : null);
58
+ this.$state.hidden.set(this.#hasError() || !(src() || poster()) || nativeControls());
59
+ }
60
+ #isLoading() {
61
+ const { loading, hidden } = this.$state;
62
+ return !hidden() && loading();
63
+ }
64
+ #watchImg() {
65
+ const img = this.$state.img();
66
+ if (!img) return;
67
+ new EventsController(img).add("load", this.#onLoad.bind(this)).add("error", this.#onError.bind(this));
68
+ if (img.complete) this.#onLoad();
69
+ }
70
+ #prevSrc = "";
71
+ #watchSrc() {
72
+ const { poster: defaultPoster } = this.#media.$props, { canLoadPoster, providedPoster, inferredPoster } = this.#media.$state;
73
+ const src = this.$props.src() || "", poster = src || defaultPoster() || inferredPoster();
74
+ if (this.#prevSrc === providedPoster()) {
75
+ providedPoster.set(src);
76
+ }
77
+ this.$state.src.set(canLoadPoster() && poster.length ? poster : null);
78
+ this.#prevSrc = src;
79
+ }
80
+ #watchAlt() {
81
+ const { src } = this.$props, { alt } = this.$state, { poster } = this.#media.$state;
82
+ alt.set(src() || poster() ? this.$props.alt() : null);
83
+ }
84
+ #watchCrossOrigin() {
85
+ const { crossOrigin: crossOriginProp } = this.$props, { crossOrigin: crossOriginState } = this.$state, { crossOrigin: mediaCrossOrigin, poster: src } = this.#media.$state, crossOrigin = crossOriginProp() !== null ? crossOriginProp() : mediaCrossOrigin();
86
+ crossOriginState.set(
87
+ /ytimg\.com|vimeo/.test(src() || "") ? null : crossOrigin === true ? "anonymous" : crossOrigin
88
+ );
89
+ }
90
+ #onLoadStart() {
91
+ const { loading, error } = this.$state, { canLoadPoster, poster } = this.#media.$state;
92
+ loading.set(canLoadPoster() && !!poster());
93
+ error.set(null);
94
+ }
95
+ #onLoad() {
96
+ const { loading, error } = this.$state;
97
+ loading.set(false);
98
+ error.set(null);
99
+ }
100
+ #onError(event) {
101
+ const { loading, error } = this.$state;
102
+ loading.set(false);
103
+ error.set(event);
104
+ }
105
+ }
106
+
107
+ export { Poster };
@@ -0,0 +1,104 @@
1
+ import { Host, effect, computed, setAttribute } from './vidstack-BNpgCJJ1.js';
2
+ import { MediaProvider, MediaPlayer } from './vidstack-BAqdCFIm.js';
3
+ import { useMediaContext } from './vidstack-tt3O1zL6.js';
4
+
5
+ class MediaProviderElement extends Host(HTMLElement, MediaProvider) {
6
+ static tagName = "media-provider";
7
+ #media;
8
+ #target = null;
9
+ #blocker = null;
10
+ onSetup() {
11
+ this.#media = useMediaContext();
12
+ this.setAttribute("keep-alive", "");
13
+ }
14
+ onDestroy() {
15
+ this.#blocker?.remove();
16
+ this.#blocker = null;
17
+ this.#target?.remove();
18
+ this.#target = null;
19
+ }
20
+ onConnect() {
21
+ effect(() => {
22
+ const loader = this.$state.loader(), isYouTubeEmbed = loader?.name === "youtube", isVimeoEmbed = loader?.name === "vimeo", isEmbed = isYouTubeEmbed || isVimeoEmbed, isGoogleCast = loader?.name === "google-cast";
23
+ const target = loader ? isGoogleCast ? this.#createGoogleCastContainer() : isEmbed ? this.#createIFrame() : loader.mediaType() === "audio" ? this.#createAudio() : this.#createVideo() : null;
24
+ if (this.#target !== target) {
25
+ const parent = this.#target?.parentElement ?? this;
26
+ this.#target?.remove();
27
+ this.#target = target;
28
+ if (target) parent.prepend(target);
29
+ if (isEmbed && target) {
30
+ effect(() => {
31
+ const { nativeControls, viewType } = this.#media.$state, showNativeControls = nativeControls(), isAudioView = viewType() === "audio", showBlocker = !showNativeControls && !isAudioView;
32
+ if (showBlocker) {
33
+ this.#blocker = this.querySelector(".vds-blocker");
34
+ if (!this.#blocker) {
35
+ this.#blocker = document.createElement("div");
36
+ this.#blocker.classList.add("vds-blocker");
37
+ target.after(this.#blocker);
38
+ }
39
+ } else {
40
+ this.#blocker?.remove();
41
+ this.#blocker = null;
42
+ }
43
+ setAttribute(target, "data-no-controls", !showNativeControls);
44
+ });
45
+ }
46
+ }
47
+ if (isYouTubeEmbed) target?.classList.add("vds-youtube");
48
+ else if (isVimeoEmbed) target?.classList.add("vds-vimeo");
49
+ if (!isEmbed) {
50
+ this.#blocker?.remove();
51
+ this.#blocker = null;
52
+ }
53
+ this.load(target);
54
+ });
55
+ }
56
+ #createAudio() {
57
+ const audio = this.#target instanceof HTMLAudioElement ? this.#target : document.createElement("audio");
58
+ const { controls, crossOrigin } = this.#media.$state;
59
+ effect(() => {
60
+ setAttribute(audio, "controls", controls());
61
+ setAttribute(audio, "crossorigin", crossOrigin());
62
+ });
63
+ return audio;
64
+ }
65
+ #createVideo() {
66
+ const video = this.#target instanceof HTMLVideoElement ? this.#target : document.createElement("video");
67
+ const { crossOrigin, poster, nativeControls } = this.#media.$state, $controls = computed(() => nativeControls() ? "true" : null), $poster = computed(() => poster() && nativeControls() ? poster() : null);
68
+ effect(() => {
69
+ setAttribute(video, "controls", $controls());
70
+ setAttribute(video, "crossorigin", crossOrigin());
71
+ setAttribute(video, "poster", $poster());
72
+ });
73
+ return video;
74
+ }
75
+ #createIFrame() {
76
+ const iframe = this.#target instanceof HTMLIFrameElement ? this.#target : document.createElement("iframe"), { nativeControls } = this.#media.$state;
77
+ effect(() => setAttribute(iframe, "tabindex", !nativeControls() ? -1 : null));
78
+ return iframe;
79
+ }
80
+ #createGoogleCastContainer() {
81
+ if (this.#target?.classList.contains("vds-google-cast")) {
82
+ return this.#target;
83
+ }
84
+ const container = document.createElement("div");
85
+ container.classList.add("vds-google-cast");
86
+ import('./vidstack-Oq65llxr.js').then(({ insertContent }) => {
87
+ insertContent(container, this.#media.$state);
88
+ });
89
+ return container;
90
+ }
91
+ }
92
+
93
+ class MediaPlayerElement extends Host(HTMLElement, MediaPlayer) {
94
+ static tagName = "media-player";
95
+ static attrs = {
96
+ autoPlay: "autoplay",
97
+ crossOrigin: "crossorigin",
98
+ playsInline: "playsinline",
99
+ preferNativeHLS: "prefer-native-hls",
100
+ minLiveDVRWindow: "min-live-dvr-window"
101
+ };
102
+ }
103
+
104
+ export { MediaPlayerElement, MediaProviderElement };
@@ -0,0 +1,58 @@
1
+ import { signal, listenEvent, effect, peek, isString } from './vidstack-BNpgCJJ1.js';
2
+ import { appendParamsToURL } from './vidstack-KShKSmYu.js';
3
+
4
+ class EmbedProvider {
5
+ #iframe;
6
+ src = signal("");
7
+ /**
8
+ * Defines which referrer is sent when fetching the resource.
9
+ *
10
+ * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/HTMLIFrameElement/referrerPolicy}
11
+ */
12
+ referrerPolicy = null;
13
+ get iframe() {
14
+ return this.#iframe;
15
+ }
16
+ constructor(iframe) {
17
+ this.#iframe = iframe;
18
+ iframe.setAttribute("frameBorder", "0");
19
+ iframe.setAttribute("aria-hidden", "true");
20
+ iframe.setAttribute(
21
+ "allow",
22
+ "autoplay; fullscreen; encrypted-media; picture-in-picture; accelerometer; gyroscope"
23
+ );
24
+ if (this.referrerPolicy !== null) {
25
+ iframe.setAttribute("referrerpolicy", this.referrerPolicy);
26
+ }
27
+ }
28
+ setup() {
29
+ listenEvent(window, "message", this.#onWindowMessage.bind(this));
30
+ listenEvent(this.#iframe, "load", this.onLoad.bind(this));
31
+ effect(this.#watchSrc.bind(this));
32
+ }
33
+ #watchSrc() {
34
+ const src = this.src();
35
+ if (!src.length) {
36
+ this.#iframe.setAttribute("src", "");
37
+ return;
38
+ }
39
+ const params = peek(() => this.buildParams());
40
+ this.#iframe.setAttribute("src", appendParamsToURL(src, params));
41
+ }
42
+ postMessage(message, target) {
43
+ this.#iframe.contentWindow?.postMessage(JSON.stringify(message), target ?? "*");
44
+ }
45
+ #onWindowMessage(event) {
46
+ const origin = this.getOrigin(), isOriginMatch = (event.source === null || event.source === this.#iframe?.contentWindow) && (!isString(origin) || origin === event.origin);
47
+ if (!isOriginMatch) return;
48
+ try {
49
+ const message = JSON.parse(event.data);
50
+ if (message) this.onMessage(message, event);
51
+ return;
52
+ } catch (e) {
53
+ }
54
+ if (event.data) this.onMessage(event.data, event);
55
+ }
56
+ }
57
+
58
+ export { EmbedProvider };
@@ -0,0 +1,33 @@
1
+ import { Host, effect, setAttribute } from './vidstack-BNpgCJJ1.js';
2
+ import { Poster } from './vidstack-C4PTiuot.js';
3
+ import './vidstack-tt3O1zL6.js';
4
+ import './vidstack-KShKSmYu.js';
5
+ import './vidstack-wTTCvdqe.js';
6
+
7
+ class MediaPosterElement extends Host(HTMLElement, Poster) {
8
+ static tagName = "media-poster";
9
+ static attrs = {
10
+ crossOrigin: "crossorigin"
11
+ };
12
+ #img = document.createElement("img");
13
+ onSetup() {
14
+ this.$state.img.set(this.#img);
15
+ }
16
+ onConnect() {
17
+ const { src, alt, crossOrigin } = this.$state;
18
+ effect(() => {
19
+ const { loading, hidden } = this.$state;
20
+ this.#img.style.display = loading() || hidden() ? "none" : "";
21
+ });
22
+ effect(() => {
23
+ setAttribute(this.#img, "alt", alt());
24
+ setAttribute(this.#img, "crossorigin", crossOrigin());
25
+ setAttribute(this.#img, "src", src());
26
+ });
27
+ if (this.#img.parentNode !== this) {
28
+ this.prepend(this.#img);
29
+ }
30
+ }
31
+ }
32
+
33
+ export { MediaPosterElement };
@@ -0,0 +1,66 @@
1
+ import { isNull, isString, deferredPromise, isBoolean } from './vidstack-BNpgCJJ1.js';
2
+ import { isAudioSrc, isVideoSrc } from './vidstack-wTTCvdqe.js';
3
+
4
+ function appendParamsToURL(baseUrl, params) {
5
+ const url = new URL(baseUrl);
6
+ for (const key of Object.keys(params)) {
7
+ url.searchParams.set(key, params[key] + "");
8
+ }
9
+ return url.toString();
10
+ }
11
+ function preconnect(url, rel = "preconnect") {
12
+ const exists = document.querySelector(`link[href="${url}"]`);
13
+ if (!isNull(exists)) return true;
14
+ const link = document.createElement("link");
15
+ link.rel = rel;
16
+ link.href = url;
17
+ link.crossOrigin = "true";
18
+ document.head.append(link);
19
+ return true;
20
+ }
21
+ const pendingRequests = {};
22
+ function loadScript(src) {
23
+ if (pendingRequests[src]) return pendingRequests[src].promise;
24
+ const promise = deferredPromise(), exists = document.querySelector(`script[src="${src}"]`);
25
+ if (!isNull(exists)) {
26
+ promise.resolve();
27
+ return promise.promise;
28
+ }
29
+ pendingRequests[src] = promise;
30
+ const script = document.createElement("script");
31
+ script.src = src;
32
+ script.onload = () => {
33
+ promise.resolve();
34
+ delete pendingRequests[src];
35
+ };
36
+ script.onerror = () => {
37
+ promise.reject();
38
+ delete pendingRequests[src];
39
+ };
40
+ setTimeout(() => document.head.append(script), 0);
41
+ return promise.promise;
42
+ }
43
+ function getRequestCredentials(crossOrigin) {
44
+ return crossOrigin === "use-credentials" ? "include" : isString(crossOrigin) ? "same-origin" : void 0;
45
+ }
46
+ function getDownloadFile({
47
+ title,
48
+ src,
49
+ download
50
+ }) {
51
+ const url = isBoolean(download) || download === "" ? src.src : isString(download) ? download : download?.url;
52
+ if (!isValidFileDownload({ url, src, download })) return null;
53
+ return {
54
+ url,
55
+ name: !isBoolean(download) && !isString(download) && download?.filename || title.toLowerCase() || "media"
56
+ };
57
+ }
58
+ function isValidFileDownload({
59
+ url,
60
+ src,
61
+ download
62
+ }) {
63
+ return isString(url) && (download && download !== true || isAudioSrc(src) || isVideoSrc(src));
64
+ }
65
+
66
+ export { appendParamsToURL, getDownloadFile, getRequestCredentials, loadScript, preconnect };