@videts/vide 0.8.0 → 0.9.3

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 (147) hide show
  1. package/README.md +11 -11
  2. package/dist/chunk-2OVLZ27V.mjs +1 -0
  3. package/dist/chunk-3RDTWUHH.mjs +1 -0
  4. package/dist/chunk-6DWWYSH4.mjs +1 -0
  5. package/dist/chunk-G74QBLVV.mjs +1 -0
  6. package/dist/chunk-JRU2FKRB.mjs +2 -0
  7. package/dist/chunk-LPSJOF2I.mjs +2 -0
  8. package/dist/chunk-NA4C7W64.mjs +2 -0
  9. package/dist/chunk-UY5CGRNN.mjs +1 -0
  10. package/dist/chunk-VPH4JIJV.mjs +1 -0
  11. package/dist/chunk-WINCDUN5.mjs +1 -0
  12. package/dist/dash/index.d.ts +3 -9
  13. package/dist/dash/index.js +1 -0
  14. package/dist/dash/index.mjs +1 -2
  15. package/dist/drm/index.d.ts +4 -31
  16. package/dist/drm/index.js +1 -0
  17. package/dist/drm/index.mjs +1 -1
  18. package/dist/hls/index.d.ts +3 -9
  19. package/dist/hls/index.js +1 -0
  20. package/dist/hls/index.mjs +1 -2
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.js +1 -0
  23. package/dist/index.mjs +1 -1
  24. package/dist/omid/index.d.ts +2 -2
  25. package/dist/omid/index.js +2 -0
  26. package/dist/react/index.d.ts +240 -0
  27. package/dist/react/index.js +2 -0
  28. package/dist/react/index.mjs +2 -0
  29. package/dist/simid/index.d.ts +2 -2
  30. package/dist/simid/index.js +1 -0
  31. package/dist/ssai/index.d.ts +4 -40
  32. package/dist/ssai/index.js +1 -0
  33. package/dist/ssai/index.mjs +1 -1
  34. package/dist/svelte/DashPlugin.svelte +23 -0
  35. package/dist/svelte/DashPlugin.svelte.d.ts +4 -0
  36. package/dist/svelte/DrmPlugin.svelte +20 -0
  37. package/dist/svelte/DrmPlugin.svelte.d.ts +4 -0
  38. package/dist/svelte/HlsPlugin.svelte +23 -0
  39. package/dist/svelte/HlsPlugin.svelte.d.ts +4 -0
  40. package/dist/svelte/SsaiPlugin.svelte +23 -0
  41. package/dist/svelte/SsaiPlugin.svelte.d.ts +4 -0
  42. package/dist/svelte/VastPlugin.svelte +20 -0
  43. package/dist/svelte/VastPlugin.svelte.d.ts +4 -0
  44. package/dist/svelte/VideControls.svelte +22 -0
  45. package/dist/svelte/VideControls.svelte.d.ts +8 -0
  46. package/dist/svelte/VideUI.svelte +49 -0
  47. package/dist/svelte/VideUI.svelte.d.ts +9 -0
  48. package/dist/svelte/Video.svelte +31 -0
  49. package/dist/svelte/Video.svelte.d.ts +10 -0
  50. package/dist/svelte/VmapPlugin.svelte +20 -0
  51. package/dist/svelte/VmapPlugin.svelte.d.ts +4 -0
  52. package/dist/svelte/components/AdCountdown.svelte +37 -0
  53. package/dist/svelte/components/AdCountdown.svelte.d.ts +7 -0
  54. package/dist/svelte/components/AdLabel.svelte +26 -0
  55. package/dist/svelte/components/AdLabel.svelte.d.ts +8 -0
  56. package/dist/svelte/components/AdLearnMore.svelte +42 -0
  57. package/dist/svelte/components/AdLearnMore.svelte.d.ts +9 -0
  58. package/dist/svelte/components/AdOverlay.svelte +46 -0
  59. package/dist/svelte/components/AdOverlay.svelte.d.ts +8 -0
  60. package/dist/svelte/components/AdSkip.svelte +67 -0
  61. package/dist/svelte/components/AdSkip.svelte.d.ts +8 -0
  62. package/dist/svelte/components/BigPlayButton.svelte +46 -0
  63. package/dist/svelte/components/BigPlayButton.svelte.d.ts +8 -0
  64. package/dist/svelte/components/ClickPlay.svelte +76 -0
  65. package/dist/svelte/components/ClickPlay.svelte.d.ts +7 -0
  66. package/dist/svelte/components/ErrorDisplay.svelte +27 -0
  67. package/dist/svelte/components/ErrorDisplay.svelte.d.ts +6 -0
  68. package/dist/svelte/components/FullscreenButton.svelte +65 -0
  69. package/dist/svelte/components/FullscreenButton.svelte.d.ts +9 -0
  70. package/dist/svelte/components/Loader.svelte +11 -0
  71. package/dist/svelte/components/Loader.svelte.d.ts +6 -0
  72. package/dist/svelte/components/MuteButton.svelte +57 -0
  73. package/dist/svelte/components/MuteButton.svelte.d.ts +8 -0
  74. package/dist/svelte/components/PlayButton.svelte +63 -0
  75. package/dist/svelte/components/PlayButton.svelte.d.ts +8 -0
  76. package/dist/svelte/components/Poster.svelte +13 -0
  77. package/dist/svelte/components/Poster.svelte.d.ts +8 -0
  78. package/dist/svelte/components/Progress.svelte +101 -0
  79. package/dist/svelte/components/Progress.svelte.d.ts +6 -0
  80. package/dist/svelte/components/TimeDisplay.svelte +33 -0
  81. package/dist/svelte/components/TimeDisplay.svelte.d.ts +7 -0
  82. package/dist/svelte/components/Volume.svelte +117 -0
  83. package/dist/svelte/components/Volume.svelte.d.ts +8 -0
  84. package/dist/svelte/context.d.ts +6 -0
  85. package/dist/svelte/context.js +10 -0
  86. package/dist/svelte/create-vide-player.svelte.d.ts +2 -0
  87. package/dist/svelte/create-vide-player.svelte.js +22 -0
  88. package/dist/svelte/helpers.d.ts +17 -0
  89. package/dist/svelte/helpers.js +31 -0
  90. package/dist/svelte/icons/IconFullscreenEnter.svelte +3 -0
  91. package/dist/svelte/icons/IconFullscreenEnter.svelte.d.ts +26 -0
  92. package/dist/svelte/icons/IconFullscreenExit.svelte +3 -0
  93. package/dist/svelte/icons/IconFullscreenExit.svelte.d.ts +26 -0
  94. package/dist/svelte/icons/IconPause.svelte +3 -0
  95. package/dist/svelte/icons/IconPause.svelte.d.ts +26 -0
  96. package/dist/svelte/icons/IconPlay.svelte +3 -0
  97. package/dist/svelte/icons/IconPlay.svelte.d.ts +26 -0
  98. package/dist/svelte/icons/IconVolumeHigh.svelte +3 -0
  99. package/dist/svelte/icons/IconVolumeHigh.svelte.d.ts +26 -0
  100. package/dist/svelte/icons/IconVolumeLow.svelte +3 -0
  101. package/dist/svelte/icons/IconVolumeLow.svelte.d.ts +26 -0
  102. package/dist/svelte/icons/IconVolumeMute.svelte +3 -0
  103. package/dist/svelte/icons/IconVolumeMute.svelte.d.ts +26 -0
  104. package/dist/svelte/index.d.ts +42 -0
  105. package/dist/svelte/index.js +39 -0
  106. package/dist/svelte/use-ad-state.svelte.d.ts +7 -0
  107. package/dist/svelte/use-ad-state.svelte.js +40 -0
  108. package/dist/svelte/use-autohide.svelte.d.ts +2 -0
  109. package/dist/svelte/use-autohide.svelte.js +68 -0
  110. package/dist/svelte/use-keyboard.svelte.d.ts +7 -0
  111. package/dist/svelte/use-keyboard.svelte.js +96 -0
  112. package/dist/svelte/use-plugin.svelte.d.ts +15 -0
  113. package/dist/svelte/use-plugin.svelte.js +40 -0
  114. package/dist/svelte/use-vide-event.svelte.d.ts +3 -0
  115. package/dist/svelte/use-vide-event.svelte.js +9 -0
  116. package/dist/{types-vxIcXgJz.d.ts → types-BsEF8iWC.d.ts} +106 -1
  117. package/dist/types-C1_eVsFF.d.ts +49 -0
  118. package/dist/types-C6XFF6w_.d.ts +30 -0
  119. package/dist/types-COeag8fU.d.ts +173 -0
  120. package/dist/types-CwjR99DL.d.ts +10 -0
  121. package/dist/types-DsixuzNX.d.ts +52 -0
  122. package/dist/types-DzY1cmXC.d.ts +10 -0
  123. package/dist/types-SuT99_Z3.d.ts +40 -0
  124. package/dist/ui/index.d.ts +7 -37
  125. package/dist/ui/index.js +1 -0
  126. package/dist/ui/index.mjs +1 -2
  127. package/dist/ui/theme.css +138 -46
  128. package/dist/vast/index.d.ts +188 -4
  129. package/dist/vast/index.js +1 -0
  130. package/dist/vast/index.mjs +1 -1
  131. package/dist/vide.core.global.js +1 -1
  132. package/dist/vide.global.js +2 -2
  133. package/dist/vide.ssai.global.js +1 -1
  134. package/dist/vide.ui.css +138 -46
  135. package/dist/vide.ui.global.js +1 -1
  136. package/dist/vide.vast.global.js +1 -1
  137. package/dist/vide.vmap.global.js +1 -1
  138. package/dist/vmap/index.d.ts +5 -49
  139. package/dist/vmap/index.js +1 -0
  140. package/dist/vmap/index.mjs +1 -1
  141. package/dist/vue/index.d.ts +354 -0
  142. package/dist/vue/index.js +2 -0
  143. package/dist/vue/index.mjs +2 -0
  144. package/package.json +47 -6
  145. package/dist/chunk-726XNUGZ.mjs +0 -1
  146. package/dist/chunk-G4Q7R3SH.mjs +0 -1
  147. package/dist/types-CAJmacV6.d.ts +0 -98
@@ -0,0 +1,49 @@
1
+ <script lang="ts">
2
+ import { getContext } from "svelte";
3
+ import type { Snippet } from "svelte";
4
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "./context.js";
5
+ import { stateToClass } from "./helpers.js";
6
+ import type { PlayerState } from "./helpers.js";
7
+
8
+ interface Props {
9
+ class?: string;
10
+ children?: Snippet;
11
+ onmount?: (el: HTMLDivElement) => void;
12
+ }
13
+
14
+ const { class: className, children, onmount }: Props = $props();
15
+
16
+ const rootEl: HTMLDivElement | undefined = $state();
17
+
18
+ $effect(() => {
19
+ if (rootEl && onmount) onmount(rootEl);
20
+ });
21
+
22
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
23
+ let stateClass = $state("");
24
+
25
+ $effect(() => {
26
+ const p = getPlayer();
27
+ if (!p) {
28
+ stateClass = "";
29
+ return;
30
+ }
31
+ stateClass = stateToClass(p.state);
32
+ const handler = ({ to }: { from: PlayerState; to: PlayerState }) => {
33
+ stateClass = stateToClass(to);
34
+ };
35
+ p.on("statechange", handler);
36
+ return () => p.off("statechange", handler);
37
+ });
38
+ </script>
39
+
40
+ <div
41
+ bind:this={rootEl}
42
+ class={["vide-ui", stateClass, className].filter(Boolean).join(" ")}
43
+ role="region"
44
+ aria-label="Video player"
45
+ >
46
+ {#if children}
47
+ {@render children()}
48
+ {/if}
49
+ </div>
@@ -0,0 +1,9 @@
1
+ import type { Snippet } from "svelte";
2
+ interface Props {
3
+ class?: string;
4
+ children?: Snippet;
5
+ onmount?: (el: HTMLDivElement) => void;
6
+ }
7
+ declare const VideUI: import("svelte").Component<Props, {}, "">;
8
+ type VideUI = ReturnType<typeof VideUI>;
9
+ export default VideUI;
@@ -0,0 +1,31 @@
1
+ <script lang="ts">
2
+ import { getContext, onMount } from "svelte";
3
+ import type { Snippet } from "svelte";
4
+ import { type RegisterFn, VIDE_REGISTER_KEY } from "./context.js";
5
+ import type { MediaElement } from "./helpers.js";
6
+
7
+ interface Props {
8
+ src?: string;
9
+ class?: string;
10
+ children?: Snippet;
11
+ [key: string]: unknown;
12
+ }
13
+
14
+ const { class: className, children, ...videoAttrs }: Props = $props();
15
+ let videoEl: HTMLVideoElement;
16
+
17
+ const registerEl = getContext<RegisterFn>(VIDE_REGISTER_KEY);
18
+
19
+ onMount(() => {
20
+ if (videoEl && registerEl) {
21
+ registerEl(videoEl as MediaElement);
22
+ }
23
+ });
24
+ </script>
25
+
26
+ <div class={className}>
27
+ <video bind:this={videoEl} {...videoAttrs}></video>
28
+ {#if children}
29
+ {@render children()}
30
+ {/if}
31
+ </div>
@@ -0,0 +1,10 @@
1
+ import type { Snippet } from "svelte";
2
+ interface Props {
3
+ src?: string;
4
+ class?: string;
5
+ children?: Snippet;
6
+ [key: string]: unknown;
7
+ }
8
+ declare const Video: import("svelte").Component<Props, {}, "">;
9
+ type Video = ReturnType<typeof Video>;
10
+ export default Video;
@@ -0,0 +1,20 @@
1
+ <script lang="ts">
2
+ import { getContext } from "svelte";
3
+ import { vmap } from "../vmap/index.js";
4
+ import type { VmapPluginOptions } from "../vmap/types.js";
5
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "./context.js";
6
+
7
+ const { url, timeout, vastOptions, adPlugins }: VmapPluginOptions = $props();
8
+
9
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
10
+
11
+ $effect(() => {
12
+ const p = getPlayer();
13
+ if (!p) return;
14
+ const plugin = vmap({ url, timeout, vastOptions, adPlugins });
15
+ const cleanup = plugin.setup(p);
16
+ return () => {
17
+ cleanup?.();
18
+ };
19
+ });
20
+ </script>
@@ -0,0 +1,4 @@
1
+ import type { VmapPluginOptions } from "../vmap/types.js";
2
+ declare const VmapPlugin: import("svelte").Component<VmapPluginOptions, {}, "">;
3
+ type VmapPlugin = ReturnType<typeof VmapPlugin>;
4
+ export default VmapPlugin;
@@ -0,0 +1,37 @@
1
+ <script lang="ts">
2
+ import { getContext } from "svelte";
3
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "../context.js";
4
+ import { useAdState } from "../use-ad-state.svelte.js";
5
+
6
+ interface Props {
7
+ class?: string;
8
+ format?: (remaining: number) => string;
9
+ }
10
+
11
+ const { class: className, format }: Props = $props();
12
+
13
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
14
+ const adState = useAdState(getPlayer);
15
+ let remaining = $state(0);
16
+
17
+ $effect(() => {
18
+ const p = getPlayer();
19
+ if (!p) return;
20
+
21
+ const onTimeUpdate = ({ currentTime }: { currentTime: number }) => {
22
+ if (!adState.active || !adState.meta) return;
23
+ const duration =
24
+ adState.meta.duration ?? (Number.isFinite(p.duration) ? p.duration : 0);
25
+ remaining = Math.max(0, Math.ceil(duration - currentTime));
26
+ };
27
+
28
+ p.on("timeupdate", onTimeUpdate);
29
+ return () => p.off("timeupdate", onTimeUpdate);
30
+ });
31
+ </script>
32
+
33
+ {#if adState.active}
34
+ <div class={["vide-ad-countdown", className].filter(Boolean).join(" ")}>
35
+ {format ? format(remaining) : `Ad \u00b7 ${remaining}s`}
36
+ </div>
37
+ {/if}
@@ -0,0 +1,7 @@
1
+ interface Props {
2
+ class?: string;
3
+ format?: (remaining: number) => string;
4
+ }
5
+ declare const AdCountdown: import("svelte").Component<Props, {}, "">;
6
+ type AdCountdown = ReturnType<typeof AdCountdown>;
7
+ export default AdCountdown;
@@ -0,0 +1,26 @@
1
+ <script lang="ts">
2
+ import { getContext } from "svelte";
3
+ import type { Snippet } from "svelte";
4
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "../context.js";
5
+ import { useAdState } from "../use-ad-state.svelte.js";
6
+
7
+ interface Props {
8
+ class?: string;
9
+ children?: Snippet;
10
+ }
11
+
12
+ const { class: className, children }: Props = $props();
13
+
14
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
15
+ const adState = useAdState(getPlayer);
16
+ </script>
17
+
18
+ {#if adState.active}
19
+ <div class={["vide-ad-label", className].filter(Boolean).join(" ")}>
20
+ {#if children}
21
+ {@render children()}
22
+ {:else}
23
+ Ad
24
+ {/if}
25
+ </div>
26
+ {/if}
@@ -0,0 +1,8 @@
1
+ import type { Snippet } from "svelte";
2
+ interface Props {
3
+ class?: string;
4
+ children?: Snippet;
5
+ }
6
+ declare const AdLabel: import("svelte").Component<Props, {}, "">;
7
+ type AdLabel = ReturnType<typeof AdLabel>;
8
+ export default AdLabel;
@@ -0,0 +1,42 @@
1
+ <script lang="ts">
2
+ import { getContext } from "svelte";
3
+ import type { Snippet } from "svelte";
4
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "../context.js";
5
+ import { useAdState } from "../use-ad-state.svelte.js";
6
+
7
+ interface Props {
8
+ class?: string;
9
+ children?: Snippet;
10
+ showTitle?: boolean;
11
+ }
12
+
13
+ const { class: className, children, showTitle = false }: Props = $props();
14
+
15
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
16
+ const adState = useAdState(getPlayer);
17
+
18
+ function onClick() {
19
+ const p = getPlayer();
20
+ if (!p || !adState.meta?.clickThrough) return;
21
+ p.el.click();
22
+ window.open(adState.meta.clickThrough, "_blank");
23
+ p.el.pause();
24
+ }
25
+ </script>
26
+
27
+ {#if adState.active && adState.meta?.clickThrough}
28
+ <button
29
+ type="button"
30
+ class={["vide-ad-cta", className].filter(Boolean).join(" ")}
31
+ onclick={onClick}
32
+ >
33
+ {#if showTitle && adState.meta.adTitle}
34
+ <span class="vide-ad-cta__title">{adState.meta.adTitle}</span>
35
+ {/if}
36
+ {#if children}
37
+ {@render children()}
38
+ {:else}
39
+ Learn More
40
+ {/if}
41
+ </button>
42
+ {/if}
@@ -0,0 +1,9 @@
1
+ import type { Snippet } from "svelte";
2
+ interface Props {
3
+ class?: string;
4
+ children?: Snippet;
5
+ showTitle?: boolean;
6
+ }
7
+ declare const AdLearnMore: import("svelte").Component<Props, {}, "">;
8
+ type AdLearnMore = ReturnType<typeof AdLearnMore>;
9
+ export default AdLearnMore;
@@ -0,0 +1,46 @@
1
+ <script lang="ts">
2
+ import { getContext } from "svelte";
3
+ import type { Snippet } from "svelte";
4
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "../context.js";
5
+ import { useAdState } from "../use-ad-state.svelte.js";
6
+
7
+ interface Props {
8
+ class?: string;
9
+ children?: Snippet;
10
+ }
11
+
12
+ const { class: className, children }: Props = $props();
13
+
14
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
15
+ const adState = useAdState(getPlayer);
16
+
17
+ function onClick() {
18
+ const p = getPlayer();
19
+ if (!p) return;
20
+ p.el.click();
21
+ const url = adState.meta?.clickThrough;
22
+ if (url) {
23
+ window.open(url, "_blank");
24
+ p.el.pause();
25
+ } else {
26
+ if (p.el.paused) {
27
+ Promise.resolve(p.el.play()).catch(() => {});
28
+ } else {
29
+ p.el.pause();
30
+ }
31
+ }
32
+ }
33
+ </script>
34
+
35
+ {#if adState.active}
36
+ <div
37
+ class={["vide-ad-overlay", className].filter(Boolean).join(" ")}
38
+ onclick={onClick}
39
+ role="button"
40
+ tabindex="-1"
41
+ >
42
+ {#if children}
43
+ {@render children()}
44
+ {/if}
45
+ </div>
46
+ {/if}
@@ -0,0 +1,8 @@
1
+ import type { Snippet } from "svelte";
2
+ interface Props {
3
+ class?: string;
4
+ children?: Snippet;
5
+ }
6
+ declare const AdOverlay: import("svelte").Component<Props, {}, "">;
7
+ type AdOverlay = ReturnType<typeof AdOverlay>;
8
+ export default AdOverlay;
@@ -0,0 +1,67 @@
1
+ <script lang="ts">
2
+ import { getContext } from "svelte";
3
+ import type { Snippet } from "svelte";
4
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "../context.js";
5
+ import { useAdState } from "../use-ad-state.svelte.js";
6
+
7
+ interface Props {
8
+ class?: string;
9
+ children?: Snippet;
10
+ }
11
+
12
+ const { class: className, children }: Props = $props();
13
+
14
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
15
+ const adState = useAdState(getPlayer);
16
+ let canSkip = $state(false);
17
+ let countdown = $state(0);
18
+
19
+ $effect(() => {
20
+ const p = getPlayer();
21
+ if (!p) return;
22
+
23
+ const onTimeUpdate = ({ currentTime }: { currentTime: number }) => {
24
+ if (
25
+ !adState.active ||
26
+ !adState.meta ||
27
+ adState.meta.skipOffset === undefined
28
+ )
29
+ return;
30
+ if (currentTime >= adState.meta.skipOffset) {
31
+ canSkip = true;
32
+ } else {
33
+ canSkip = false;
34
+ countdown = Math.max(0, Math.ceil(adState.meta.skipOffset - currentTime));
35
+ }
36
+ };
37
+
38
+ p.on("timeupdate", onTimeUpdate);
39
+ return () => p.off("timeupdate", onTimeUpdate);
40
+ });
41
+
42
+ function onClick() {
43
+ const p = getPlayer();
44
+ if (!p || !canSkip || !adState.meta) return;
45
+ p.emit("ad:skip", { adId: adState.meta.adId });
46
+ }
47
+ </script>
48
+
49
+ {#if adState.active && adState.meta && adState.meta.skipOffset !== undefined}
50
+ <button
51
+ type="button"
52
+ class={["vide-skip", !canSkip && "vide-skip--disabled", className].filter(Boolean).join(" ")}
53
+ aria-label="Skip ad"
54
+ onclick={onClick}
55
+ disabled={!canSkip}
56
+ >
57
+ {#if canSkip}
58
+ {#if children}
59
+ {@render children()}
60
+ {:else}
61
+ Skip Ad
62
+ {/if}
63
+ {:else}
64
+ Skip in {countdown}s
65
+ {/if}
66
+ </button>
67
+ {/if}
@@ -0,0 +1,8 @@
1
+ import type { Snippet } from "svelte";
2
+ interface Props {
3
+ class?: string;
4
+ children?: Snippet;
5
+ }
6
+ declare const AdSkip: import("svelte").Component<Props, {}, "">;
7
+ type AdSkip = ReturnType<typeof AdSkip>;
8
+ export default AdSkip;
@@ -0,0 +1,46 @@
1
+ <script lang="ts">
2
+ import { getContext } from "svelte";
3
+ import type { Snippet } from "svelte";
4
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "../context.js";
5
+ import IconPlay from "../icons/IconPlay.svelte";
6
+
7
+ interface Props {
8
+ class?: string;
9
+ children?: Snippet;
10
+ }
11
+
12
+ const { class: className, children }: Props = $props();
13
+
14
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
15
+
16
+ function onClick() {
17
+ const p = getPlayer();
18
+ if (!p) return;
19
+ if (p.state === "ended") {
20
+ function onReady({ to }: { from: string; to: string }): void {
21
+ if (to === "ready") {
22
+ p.off("statechange", onReady);
23
+ p.play().catch(() => {});
24
+ }
25
+ }
26
+ p.on("statechange", onReady);
27
+ p.el.currentTime = 0;
28
+ p.el.load();
29
+ return;
30
+ }
31
+ p.play().catch(() => {});
32
+ }
33
+ </script>
34
+
35
+ <button
36
+ type="button"
37
+ class={["vide-bigplay", className].filter(Boolean).join(" ")}
38
+ aria-label="Play video"
39
+ onclick={onClick}
40
+ >
41
+ {#if children}
42
+ {@render children()}
43
+ {:else}
44
+ <IconPlay />
45
+ {/if}
46
+ </button>
@@ -0,0 +1,8 @@
1
+ import type { Snippet } from "svelte";
2
+ interface Props {
3
+ class?: string;
4
+ children?: Snippet;
5
+ }
6
+ declare const BigPlayButton: import("svelte").Component<Props, {}, "">;
7
+ type BigPlayButton = ReturnType<typeof BigPlayButton>;
8
+ export default BigPlayButton;
@@ -0,0 +1,76 @@
1
+ <script lang="ts">
2
+ import { getContext, onDestroy } from "svelte";
3
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "../context.js";
4
+ import { isAdState } from "../helpers.js";
5
+
6
+ const DBLCLICK_DELAY = 200;
7
+
8
+ interface Props {
9
+ class?: string;
10
+ enableFullscreen?: boolean;
11
+ }
12
+
13
+ const { class: className, enableFullscreen = true }: Props = $props();
14
+
15
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
16
+ let clickTimer: ReturnType<typeof setTimeout> | null = null;
17
+
18
+ function togglePlay(): void {
19
+ const p = getPlayer();
20
+ if (!p) return;
21
+ if (p.state === "playing" || p.state === "ad:playing") {
22
+ p.pause();
23
+ } else {
24
+ p.play().catch(() => {});
25
+ }
26
+ }
27
+
28
+ function toggleFullscreen(): void {
29
+ if (!enableFullscreen) return;
30
+ const p = getPlayer();
31
+ const target =
32
+ (p?.el.closest(".vide-ui") as HTMLElement | null) ?? p?.el.parentElement;
33
+ if (!target) return;
34
+ if (document.fullscreenElement != null) {
35
+ document.exitFullscreen().catch(() => {});
36
+ } else if (target.requestFullscreen) {
37
+ target.requestFullscreen().catch(() => {});
38
+ }
39
+ }
40
+
41
+ function onClick(): void {
42
+ const p = getPlayer();
43
+ if (!p) return;
44
+
45
+ if (isAdState(p.state)) {
46
+ p.el.click();
47
+ togglePlay();
48
+ return;
49
+ }
50
+
51
+ if (clickTimer !== null) {
52
+ clearTimeout(clickTimer);
53
+ clickTimer = null;
54
+ toggleFullscreen();
55
+ return;
56
+ }
57
+
58
+ clickTimer = setTimeout(() => {
59
+ clickTimer = null;
60
+ togglePlay();
61
+ }, DBLCLICK_DELAY);
62
+ }
63
+
64
+ onDestroy(() => {
65
+ if (clickTimer !== null) {
66
+ clearTimeout(clickTimer);
67
+ clickTimer = null;
68
+ }
69
+ });
70
+ </script>
71
+
72
+ <div
73
+ class={["vide-clickplay", className].filter(Boolean).join(" ")}
74
+ onclick={onClick}
75
+ role="presentation"
76
+ ></div>
@@ -0,0 +1,7 @@
1
+ interface Props {
2
+ class?: string;
3
+ enableFullscreen?: boolean;
4
+ }
5
+ declare const ClickPlay: import("svelte").Component<Props, {}, "">;
6
+ type ClickPlay = ReturnType<typeof ClickPlay>;
7
+ export default ClickPlay;
@@ -0,0 +1,27 @@
1
+ <script lang="ts">
2
+ import { getContext } from "svelte";
3
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "../context.js";
4
+
5
+ interface Props {
6
+ class?: string;
7
+ }
8
+
9
+ const { class: className }: Props = $props();
10
+
11
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
12
+ let message = $state("");
13
+
14
+ $effect(() => {
15
+ const p = getPlayer();
16
+ if (!p) return;
17
+ const handler = ({ message: msg }: { message: string }) => {
18
+ message = msg;
19
+ };
20
+ p.on("error", handler);
21
+ return () => p.off("error", handler);
22
+ });
23
+ </script>
24
+
25
+ <div class={["vide-error", className].filter(Boolean).join(" ")}>
26
+ <span class="vide-error__message">{message}</span>
27
+ </div>
@@ -0,0 +1,6 @@
1
+ interface Props {
2
+ class?: string;
3
+ }
4
+ declare const ErrorDisplay: import("svelte").Component<Props, {}, "">;
5
+ type ErrorDisplay = ReturnType<typeof ErrorDisplay>;
6
+ export default ErrorDisplay;
@@ -0,0 +1,65 @@
1
+ <script lang="ts">
2
+ import { getContext, onDestroy, onMount } from "svelte";
3
+ import type { Snippet } from "svelte";
4
+ import { type PlayerGetter, VIDE_PLAYER_KEY } from "../context.js";
5
+ import IconFullscreenEnter from "../icons/IconFullscreenEnter.svelte";
6
+ import IconFullscreenExit from "../icons/IconFullscreenExit.svelte";
7
+
8
+ interface Props {
9
+ class?: string;
10
+ target?: HTMLElement | null;
11
+ children?: Snippet;
12
+ }
13
+
14
+ const { class: className, target = null, children }: Props = $props();
15
+
16
+ const getPlayer = getContext<PlayerGetter>(VIDE_PLAYER_KEY);
17
+ let active = $state(false);
18
+
19
+ function onChange() {
20
+ active =
21
+ document.fullscreenElement != null ||
22
+ // biome-ignore lint/suspicious/noExplicitAny: webkit prefix
23
+ (document as any).webkitFullscreenElement != null;
24
+ }
25
+
26
+ onMount(() => {
27
+ document.addEventListener("fullscreenchange", onChange);
28
+ document.addEventListener("webkitfullscreenchange", onChange);
29
+ });
30
+
31
+ onDestroy(() => {
32
+ document.removeEventListener("fullscreenchange", onChange);
33
+ document.removeEventListener("webkitfullscreenchange", onChange);
34
+ });
35
+
36
+ function onClick() {
37
+ const p = getPlayer();
38
+ const fsTarget =
39
+ target ??
40
+ (p?.el.closest(".vide-ui") as HTMLElement | null) ??
41
+ p?.el.parentElement;
42
+ if (!fsTarget) return;
43
+ if (document.fullscreenElement) {
44
+ document.exitFullscreen().catch(() => {});
45
+ } else {
46
+ fsTarget.requestFullscreen().catch(() => {});
47
+ }
48
+ }
49
+ </script>
50
+
51
+ <button
52
+ type="button"
53
+ class={["vide-fullscreen", className].filter(Boolean).join(" ")}
54
+ aria-label={active ? "Exit fullscreen" : "Fullscreen"}
55
+ data-fullscreen={active || undefined}
56
+ onclick={onClick}
57
+ >
58
+ {#if children}
59
+ {@render children()}
60
+ {:else if active}
61
+ <IconFullscreenExit />
62
+ {:else}
63
+ <IconFullscreenEnter />
64
+ {/if}
65
+ </button>
@@ -0,0 +1,9 @@
1
+ import type { Snippet } from "svelte";
2
+ interface Props {
3
+ class?: string;
4
+ target?: HTMLElement | null;
5
+ children?: Snippet;
6
+ }
7
+ declare const FullscreenButton: import("svelte").Component<Props, {}, "">;
8
+ type FullscreenButton = ReturnType<typeof FullscreenButton>;
9
+ export default FullscreenButton;
@@ -0,0 +1,11 @@
1
+ <script lang="ts">
2
+ interface Props {
3
+ class?: string;
4
+ }
5
+
6
+ const { class: className }: Props = $props();
7
+ </script>
8
+
9
+ <div class={["vide-loader", className].filter(Boolean).join(" ")}>
10
+ <div class="vide-loader__spinner"></div>
11
+ </div>
@@ -0,0 +1,6 @@
1
+ interface Props {
2
+ class?: string;
3
+ }
4
+ declare const Loader: import("svelte").Component<Props, {}, "">;
5
+ type Loader = ReturnType<typeof Loader>;
6
+ export default Loader;