payload-video-streaming 0.0.0-stage → 0.2.0-beta.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 (252) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +658 -2
  3. package/dist/bin/args.d.ts +24 -0
  4. package/dist/bin/args.js +96 -0
  5. package/dist/bin/args.js.map +1 -0
  6. package/dist/bin/cli.d.ts +2 -0
  7. package/dist/bin/cli.js +17 -0
  8. package/dist/bin/cli.js.map +1 -0
  9. package/dist/bin/fake.d.ts +2 -0
  10. package/dist/bin/fake.js +14 -0
  11. package/dist/bin/fake.js.map +1 -0
  12. package/dist/bin/migrate.d.ts +5 -0
  13. package/dist/bin/migrate.js +47 -0
  14. package/dist/bin/migrate.js.map +1 -0
  15. package/dist/bin/runFake.d.ts +2 -0
  16. package/dist/bin/runFake.js +24 -0
  17. package/dist/bin/runFake.js.map +1 -0
  18. package/dist/blocks.d.ts +42 -0
  19. package/dist/blocks.js +150 -0
  20. package/dist/blocks.js.map +1 -0
  21. package/dist/collection.d.ts +10 -0
  22. package/dist/collection.js +550 -0
  23. package/dist/collection.js.map +1 -0
  24. package/dist/components/CaptionsManager.d.ts +9 -0
  25. package/dist/components/CaptionsManager.js +174 -0
  26. package/dist/components/CaptionsManager.js.map +1 -0
  27. package/dist/components/DownloadsPanel.d.ts +9 -0
  28. package/dist/components/DownloadsPanel.js +147 -0
  29. package/dist/components/DownloadsPanel.js.map +1 -0
  30. package/dist/components/ListUploader.d.ts +11 -0
  31. package/dist/components/ListUploader.js +116 -0
  32. package/dist/components/ListUploader.js.map +1 -0
  33. package/dist/components/ThumbnailCell.d.ts +5 -0
  34. package/dist/components/ThumbnailCell.js +28 -0
  35. package/dist/components/ThumbnailCell.js.map +1 -0
  36. package/dist/components/Uploader.d.ts +17 -0
  37. package/dist/components/Uploader.js +162 -0
  38. package/dist/components/Uploader.js.map +1 -0
  39. package/dist/components/VideoBlockLabel.d.ts +11 -0
  40. package/dist/components/VideoBlockLabel.js +86 -0
  41. package/dist/components/VideoBlockLabel.js.map +1 -0
  42. package/dist/components/VideoField.d.ts +17 -0
  43. package/dist/components/VideoField.js +418 -0
  44. package/dist/components/VideoField.js.map +1 -0
  45. package/dist/components/api.d.ts +46 -0
  46. package/dist/components/api.js +74 -0
  47. package/dist/components/api.js.map +1 -0
  48. package/dist/components/chunkedUpload.d.ts +28 -0
  49. package/dist/components/chunkedUpload.js +49 -0
  50. package/dist/components/chunkedUpload.js.map +1 -0
  51. package/dist/components/styles.d.ts +95 -0
  52. package/dist/components/styles.js +148 -0
  53. package/dist/components/styles.js.map +1 -0
  54. package/dist/components/usePluginApi.d.ts +41 -0
  55. package/dist/components/usePluginApi.js +21 -0
  56. package/dist/components/usePluginApi.js.map +1 -0
  57. package/dist/components/useVideoUpload.d.ts +37 -0
  58. package/dist/components/useVideoUpload.js +181 -0
  59. package/dist/components/useVideoUpload.js.map +1 -0
  60. package/dist/core/errors.d.ts +27 -0
  61. package/dist/core/errors.js +29 -0
  62. package/dist/core/errors.js.map +1 -0
  63. package/dist/core/provider.d.ts +331 -0
  64. package/dist/core/provider.js +13 -0
  65. package/dist/core/provider.js.map +1 -0
  66. package/dist/core/registry.d.ts +17 -0
  67. package/dist/core/registry.js +110 -0
  68. package/dist/core/registry.js.map +1 -0
  69. package/dist/core/status.d.ts +15 -0
  70. package/dist/core/status.js +29 -0
  71. package/dist/core/status.js.map +1 -0
  72. package/dist/endpoints/index.d.ts +3 -0
  73. package/dist/endpoints/index.js +464 -0
  74. package/dist/endpoints/index.js.map +1 -0
  75. package/dist/env.d.ts +40 -0
  76. package/dist/env.js +105 -0
  77. package/dist/env.js.map +1 -0
  78. package/dist/exports/bunny.d.ts +16 -0
  79. package/dist/exports/bunny.js +13 -0
  80. package/dist/exports/bunny.js.map +1 -0
  81. package/dist/exports/client.d.ts +13 -0
  82. package/dist/exports/client.js +13 -0
  83. package/dist/exports/client.js.map +1 -0
  84. package/dist/exports/cloudflare.d.ts +18 -0
  85. package/dist/exports/cloudflare.js +15 -0
  86. package/dist/exports/cloudflare.js.map +1 -0
  87. package/dist/exports/mux.d.ts +18 -0
  88. package/dist/exports/mux.js +15 -0
  89. package/dist/exports/mux.js.map +1 -0
  90. package/dist/exports/react.d.ts +13 -0
  91. package/dist/exports/react.js +11 -0
  92. package/dist/exports/react.js.map +1 -0
  93. package/dist/exports/rsc.d.ts +1 -0
  94. package/dist/exports/rsc.js +4 -0
  95. package/dist/exports/rsc.js.map +1 -0
  96. package/dist/exports/testing.d.ts +13 -0
  97. package/dist/exports/testing.js +9 -0
  98. package/dist/exports/testing.js.map +1 -0
  99. package/dist/fields.d.ts +13 -0
  100. package/dist/fields.js +13 -0
  101. package/dist/fields.js.map +1 -0
  102. package/dist/frontend/ClientVideo.d.ts +14 -0
  103. package/dist/frontend/ClientVideo.js +43 -0
  104. package/dist/frontend/ClientVideo.js.map +1 -0
  105. package/dist/frontend/Video.d.ts +32 -0
  106. package/dist/frontend/Video.js +73 -0
  107. package/dist/frontend/Video.js.map +1 -0
  108. package/dist/frontend/VideoIframe.d.ts +35 -0
  109. package/dist/frontend/VideoIframe.js +60 -0
  110. package/dist/frontend/VideoIframe.js.map +1 -0
  111. package/dist/frontend/constants.d.ts +10 -0
  112. package/dist/frontend/constants.js +10 -0
  113. package/dist/frontend/constants.js.map +1 -0
  114. package/dist/frontend/converters.d.ts +25 -0
  115. package/dist/frontend/converters.js +24 -0
  116. package/dist/frontend/converters.js.map +1 -0
  117. package/dist/frontend/source.d.ts +80 -0
  118. package/dist/frontend/source.js +159 -0
  119. package/dist/frontend/source.js.map +1 -0
  120. package/dist/frontend/useVideoSource.d.ts +27 -0
  121. package/dist/frontend/useVideoSource.js +108 -0
  122. package/dist/frontend/useVideoSource.js.map +1 -0
  123. package/dist/index.d.ts +20 -0
  124. package/dist/index.js +14 -0
  125. package/dist/index.js.map +1 -0
  126. package/dist/migrate/cfStream.d.ts +108 -0
  127. package/dist/migrate/cfStream.js +418 -0
  128. package/dist/migrate/cfStream.js.map +1 -0
  129. package/dist/options.d.ts +4 -0
  130. package/dist/options.js +90 -0
  131. package/dist/options.js.map +1 -0
  132. package/dist/plugin.d.ts +9 -0
  133. package/dist/plugin.js +98 -0
  134. package/dist/plugin.js.map +1 -0
  135. package/dist/providers/bunny/client.d.ts +78 -0
  136. package/dist/providers/bunny/client.js +231 -0
  137. package/dist/providers/bunny/client.js.map +1 -0
  138. package/dist/providers/bunny/env.d.ts +18 -0
  139. package/dist/providers/bunny/env.js +31 -0
  140. package/dist/providers/bunny/env.js.map +1 -0
  141. package/dist/providers/bunny/mapping.d.ts +39 -0
  142. package/dist/providers/bunny/mapping.js +123 -0
  143. package/dist/providers/bunny/mapping.js.map +1 -0
  144. package/dist/providers/bunny/options.d.ts +92 -0
  145. package/dist/providers/bunny/options.js +85 -0
  146. package/dist/providers/bunny/options.js.map +1 -0
  147. package/dist/providers/bunny/provider.d.ts +69 -0
  148. package/dist/providers/bunny/provider.js +472 -0
  149. package/dist/providers/bunny/provider.js.map +1 -0
  150. package/dist/providers/bunny/signing.d.ts +61 -0
  151. package/dist/providers/bunny/signing.js +144 -0
  152. package/dist/providers/bunny/signing.js.map +1 -0
  153. package/dist/providers/bunny/types.d.ts +153 -0
  154. package/dist/providers/bunny/types.js +64 -0
  155. package/dist/providers/bunny/types.js.map +1 -0
  156. package/dist/providers/bunny/urls.d.ts +49 -0
  157. package/dist/providers/bunny/urls.js +70 -0
  158. package/dist/providers/bunny/urls.js.map +1 -0
  159. package/dist/providers/bunny/webhook.d.ts +32 -0
  160. package/dist/providers/bunny/webhook.js +75 -0
  161. package/dist/providers/bunny/webhook.js.map +1 -0
  162. package/dist/providers/cloudflare/client.d.ts +93 -0
  163. package/dist/providers/cloudflare/client.js +436 -0
  164. package/dist/providers/cloudflare/client.js.map +1 -0
  165. package/dist/providers/cloudflare/env.d.ts +22 -0
  166. package/dist/providers/cloudflare/env.js +57 -0
  167. package/dist/providers/cloudflare/env.js.map +1 -0
  168. package/dist/providers/cloudflare/mapping.d.ts +15 -0
  169. package/dist/providers/cloudflare/mapping.js +95 -0
  170. package/dist/providers/cloudflare/mapping.js.map +1 -0
  171. package/dist/providers/cloudflare/options.d.ts +104 -0
  172. package/dist/providers/cloudflare/options.js +91 -0
  173. package/dist/providers/cloudflare/options.js.map +1 -0
  174. package/dist/providers/cloudflare/provider.d.ts +62 -0
  175. package/dist/providers/cloudflare/provider.js +434 -0
  176. package/dist/providers/cloudflare/provider.js.map +1 -0
  177. package/dist/providers/cloudflare/signing.d.ts +41 -0
  178. package/dist/providers/cloudflare/signing.js +97 -0
  179. package/dist/providers/cloudflare/signing.js.map +1 -0
  180. package/dist/providers/cloudflare/tus.d.ts +24 -0
  181. package/dist/providers/cloudflare/tus.js +55 -0
  182. package/dist/providers/cloudflare/tus.js.map +1 -0
  183. package/dist/providers/cloudflare/types.d.ts +156 -0
  184. package/dist/providers/cloudflare/types.js +14 -0
  185. package/dist/providers/cloudflare/types.js.map +1 -0
  186. package/dist/providers/cloudflare/urls.d.ts +55 -0
  187. package/dist/providers/cloudflare/urls.js +87 -0
  188. package/dist/providers/cloudflare/urls.js.map +1 -0
  189. package/dist/providers/cloudflare/webhook.d.ts +36 -0
  190. package/dist/providers/cloudflare/webhook.js +83 -0
  191. package/dist/providers/cloudflare/webhook.js.map +1 -0
  192. package/dist/providers/mux/client.d.ts +82 -0
  193. package/dist/providers/mux/client.js +283 -0
  194. package/dist/providers/mux/client.js.map +1 -0
  195. package/dist/providers/mux/env.d.ts +21 -0
  196. package/dist/providers/mux/env.js +61 -0
  197. package/dist/providers/mux/env.js.map +1 -0
  198. package/dist/providers/mux/mapping.d.ts +38 -0
  199. package/dist/providers/mux/mapping.js +111 -0
  200. package/dist/providers/mux/mapping.js.map +1 -0
  201. package/dist/providers/mux/options.d.ts +96 -0
  202. package/dist/providers/mux/options.js +83 -0
  203. package/dist/providers/mux/options.js.map +1 -0
  204. package/dist/providers/mux/provider.d.ts +62 -0
  205. package/dist/providers/mux/provider.js +546 -0
  206. package/dist/providers/mux/provider.js.map +1 -0
  207. package/dist/providers/mux/signing.d.ts +45 -0
  208. package/dist/providers/mux/signing.js +84 -0
  209. package/dist/providers/mux/signing.js.map +1 -0
  210. package/dist/providers/mux/types.d.ts +173 -0
  211. package/dist/providers/mux/types.js +42 -0
  212. package/dist/providers/mux/types.js.map +1 -0
  213. package/dist/providers/mux/urls.d.ts +58 -0
  214. package/dist/providers/mux/urls.js +59 -0
  215. package/dist/providers/mux/urls.js.map +1 -0
  216. package/dist/providers/mux/webhook.d.ts +38 -0
  217. package/dist/providers/mux/webhook.js +115 -0
  218. package/dist/providers/mux/webhook.js.map +1 -0
  219. package/dist/service.d.ts +166 -0
  220. package/dist/service.js +857 -0
  221. package/dist/service.js.map +1 -0
  222. package/dist/testing/bunny.d.ts +113 -0
  223. package/dist/testing/bunny.js +776 -0
  224. package/dist/testing/bunny.js.map +1 -0
  225. package/dist/testing/cloudflare.d.ts +101 -0
  226. package/dist/testing/cloudflare.js +913 -0
  227. package/dist/testing/cloudflare.js.map +1 -0
  228. package/dist/testing/index.d.ts +45 -0
  229. package/dist/testing/index.js +42 -0
  230. package/dist/testing/index.js.map +1 -0
  231. package/dist/testing/mux.d.ts +139 -0
  232. package/dist/testing/mux.js +1053 -0
  233. package/dist/testing/mux.js.map +1 -0
  234. package/dist/testing/types.d.ts +90 -0
  235. package/dist/testing/types.js +9 -0
  236. package/dist/testing/types.js.map +1 -0
  237. package/dist/types.d.ts +250 -0
  238. package/dist/types.js +3 -0
  239. package/dist/types.js.map +1 -0
  240. package/dist/utils/access.d.ts +22 -0
  241. package/dist/utils/access.js +66 -0
  242. package/dist/utils/access.js.map +1 -0
  243. package/dist/utils/localReq.d.ts +11 -0
  244. package/dist/utils/localReq.js +23 -0
  245. package/dist/utils/localReq.js.map +1 -0
  246. package/dist/utils/request.d.ts +12 -0
  247. package/dist/utils/request.js +55 -0
  248. package/dist/utils/request.js.map +1 -0
  249. package/dist/utils/version.d.ts +5 -0
  250. package/dist/utils/version.js +7 -0
  251. package/dist/utils/version.js.map +1 -0
  252. package/package.json +174 -4
@@ -0,0 +1,35 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { VideoPlayerOptions, VideoSource } from './source.js';
3
+ /** Props every player component receives: pass any component with this shape as `player`. */
4
+ export type VideoPlayerProps = {
5
+ className?: string;
6
+ options: VideoPlayerOptions;
7
+ source: VideoSource;
8
+ /** Accessible name for the player (the video's title, or "Video"). */
9
+ title: string;
10
+ };
11
+ /**
12
+ * A player component, e.g. `({ source, options }) => <MediaPlayer src={source.hls} autoPlay={options.autoplay} />`.
13
+ * When videos may need to be fetched in the browser (unpopulated relationships, or private videos
14
+ * without a signing key) and you render from a Server Component, make it a Client Component.
15
+ */
16
+ export type VideoPlayerComponent = (props: VideoPlayerProps) => ReactNode;
17
+ /** Wraps a player in a box with the video's aspect ratio. */
18
+ export declare const VideoFrame: ({ children, className, options, source, }: {
19
+ children?: ReactNode;
20
+ className?: string;
21
+ options?: VideoPlayerOptions;
22
+ source: null | VideoSource;
23
+ }) => import("react").JSX.Element;
24
+ /**
25
+ * The provider's iframe player – the default player. No client-side JavaScript; works in Server
26
+ * Components. The provider handles adaptive bitrate, captions, audio tracks and accessibility.
27
+ */
28
+ export declare const VideoIframe: ({ className, options, source, title }: VideoPlayerProps) => import("react").JSX.Element;
29
+ /** Shown while a video is processing or its source is loading. */
30
+ export declare const VideoPlaceholder: ({ className, label, options, source, }: {
31
+ className?: string;
32
+ label: string;
33
+ options?: VideoPlayerOptions;
34
+ source: null | VideoSource;
35
+ }) => import("react").JSX.Element;
@@ -0,0 +1,60 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { videoAspectRatio, videoIframeSrc } from './source.js';
3
+ const frame = {
4
+ border: 0,
5
+ height: '100%',
6
+ inset: 0,
7
+ position: 'absolute',
8
+ width: '100%'
9
+ };
10
+ /** Wraps a player in a box with the video's aspect ratio. */ export const VideoFrame = ({ children, className, options, source })=>/*#__PURE__*/ _jsx("div", {
11
+ className: className,
12
+ "data-video-frame": "",
13
+ style: {
14
+ aspectRatio: videoAspectRatio(source, options),
15
+ background: '#000',
16
+ position: 'relative',
17
+ width: '100%'
18
+ },
19
+ children: children
20
+ });
21
+ /**
22
+ * The provider's iframe player – the default player. No client-side JavaScript; works in Server
23
+ * Components. The provider handles adaptive bitrate, captions, audio tracks and accessibility.
24
+ */ export const VideoIframe = ({ className, options = {}, source, title })=>/*#__PURE__*/ _jsx(VideoFrame, {
25
+ className: className,
26
+ options: options,
27
+ source: source,
28
+ children: /*#__PURE__*/ _jsx("iframe", {
29
+ allow: "accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture; fullscreen",
30
+ allowFullScreen: true,
31
+ loading: "lazy",
32
+ src: videoIframeSrc(source, options),
33
+ style: frame,
34
+ title: title
35
+ })
36
+ });
37
+ /** Shown while a video is processing or its source is loading. */ export const VideoPlaceholder = ({ className, label, options, source })=>/*#__PURE__*/ _jsx(VideoFrame, {
38
+ className: className,
39
+ options: options,
40
+ source: source,
41
+ children: /*#__PURE__*/ _jsx("div", {
42
+ "aria-live": "polite",
43
+ "data-video-placeholder": "",
44
+ role: "status",
45
+ style: {
46
+ ...frame,
47
+ alignItems: 'center',
48
+ backgroundImage: source?.ready === false ? undefined : source ? `url("${source.poster}")` : undefined,
49
+ backgroundPosition: 'center',
50
+ backgroundSize: 'cover',
51
+ color: '#eee',
52
+ display: 'flex',
53
+ font: '14px system-ui, sans-serif',
54
+ justifyContent: 'center'
55
+ },
56
+ children: label
57
+ })
58
+ });
59
+
60
+ //# sourceMappingURL=VideoIframe.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/frontend/VideoIframe.tsx"],"sourcesContent":["import type { CSSProperties, ReactNode } from 'react'\n\nimport type { VideoPlayerOptions, VideoSource } from './source.js'\n\nimport { videoAspectRatio, videoIframeSrc } from './source.js'\n\n/** Props every player component receives: pass any component with this shape as `player`. */\nexport type VideoPlayerProps = {\n className?: string\n options: VideoPlayerOptions\n source: VideoSource\n /** Accessible name for the player (the video's title, or \"Video\"). */\n title: string\n}\n\n/**\n * A player component, e.g. `({ source, options }) => <MediaPlayer src={source.hls} autoPlay={options.autoplay} />`.\n * When videos may need to be fetched in the browser (unpopulated relationships, or private videos\n * without a signing key) and you render from a Server Component, make it a Client Component.\n */\nexport type VideoPlayerComponent = (props: VideoPlayerProps) => ReactNode\n\nconst frame: CSSProperties = { border: 0, height: '100%', inset: 0, position: 'absolute', width: '100%' }\n\n/** Wraps a player in a box with the video's aspect ratio. */\nexport const VideoFrame = ({\n children,\n className,\n options,\n source,\n}: {\n children?: ReactNode\n className?: string\n options?: VideoPlayerOptions\n source: null | VideoSource\n}) => (\n <div\n className={className}\n data-video-frame=\"\"\n style={{ aspectRatio: videoAspectRatio(source, options), background: '#000', position: 'relative', width: '100%' }}\n >\n {children}\n </div>\n)\n\n/**\n * The provider's iframe player – the default player. No client-side JavaScript; works in Server\n * Components. The provider handles adaptive bitrate, captions, audio tracks and accessibility.\n */\nexport const VideoIframe = ({ className, options = {}, source, title }: VideoPlayerProps) => (\n <VideoFrame className={className} options={options} source={source}>\n <iframe\n allow=\"accelerometer; gyroscope; autoplay; encrypted-media; picture-in-picture; fullscreen\"\n allowFullScreen\n loading=\"lazy\"\n src={videoIframeSrc(source, options)}\n style={frame}\n title={title}\n />\n </VideoFrame>\n)\n\n/** Shown while a video is processing or its source is loading. */\nexport const VideoPlaceholder = ({\n className,\n label,\n options,\n source,\n}: {\n className?: string\n label: string\n options?: VideoPlayerOptions\n source: null | VideoSource\n}) => (\n <VideoFrame className={className} options={options} source={source}>\n <div\n aria-live=\"polite\"\n data-video-placeholder=\"\"\n role=\"status\"\n style={{\n ...frame,\n alignItems: 'center',\n backgroundImage: source?.ready === false ? undefined : source ? `url(\"${source.poster}\")` : undefined,\n backgroundPosition: 'center',\n backgroundSize: 'cover',\n color: '#eee',\n display: 'flex',\n font: '14px system-ui, sans-serif',\n justifyContent: 'center',\n }}\n >\n {label}\n </div>\n </VideoFrame>\n)\n"],"names":["videoAspectRatio","videoIframeSrc","frame","border","height","inset","position","width","VideoFrame","children","className","options","source","div","data-video-frame","style","aspectRatio","background","VideoIframe","title","iframe","allow","allowFullScreen","loading","src","VideoPlaceholder","label","aria-live","data-video-placeholder","role","alignItems","backgroundImage","ready","undefined","poster","backgroundPosition","backgroundSize","color","display","font","justifyContent"],"mappings":";AAIA,SAASA,gBAAgB,EAAEC,cAAc,QAAQ,cAAa;AAkB9D,MAAMC,QAAuB;IAAEC,QAAQ;IAAGC,QAAQ;IAAQC,OAAO;IAAGC,UAAU;IAAYC,OAAO;AAAO;AAExG,2DAA2D,GAC3D,OAAO,MAAMC,aAAa,CAAC,EACzBC,QAAQ,EACRC,SAAS,EACTC,OAAO,EACPC,MAAM,EAMP,iBACC,KAACC;QACCH,WAAWA;QACXI,oBAAiB;QACjBC,OAAO;YAAEC,aAAahB,iBAAiBY,QAAQD;YAAUM,YAAY;YAAQX,UAAU;YAAYC,OAAO;QAAO;kBAEhHE;OAEJ;AAED;;;CAGC,GACD,OAAO,MAAMS,cAAc,CAAC,EAAER,SAAS,EAAEC,UAAU,CAAC,CAAC,EAAEC,MAAM,EAAEO,KAAK,EAAoB,iBACtF,KAACX;QAAWE,WAAWA;QAAWC,SAASA;QAASC,QAAQA;kBAC1D,cAAA,KAACQ;YACCC,OAAM;YACNC,eAAe;YACfC,SAAQ;YACRC,KAAKvB,eAAeW,QAAQD;YAC5BI,OAAOb;YACPiB,OAAOA;;OAGZ;AAED,gEAAgE,GAChE,OAAO,MAAMM,mBAAmB,CAAC,EAC/Bf,SAAS,EACTgB,KAAK,EACLf,OAAO,EACPC,MAAM,EAMP,iBACC,KAACJ;QAAWE,WAAWA;QAAWC,SAASA;QAASC,QAAQA;kBAC1D,cAAA,KAACC;YACCc,aAAU;YACVC,0BAAuB;YACvBC,MAAK;YACLd,OAAO;gBACL,GAAGb,KAAK;gBACR4B,YAAY;gBACZC,iBAAiBnB,QAAQoB,UAAU,QAAQC,YAAYrB,SAAS,CAAC,KAAK,EAAEA,OAAOsB,MAAM,CAAC,EAAE,CAAC,GAAGD;gBAC5FE,oBAAoB;gBACpBC,gBAAgB;gBAChBC,OAAO;gBACPC,SAAS;gBACTC,MAAM;gBACNC,gBAAgB;YAClB;sBAECd;;OAGN"}
@@ -0,0 +1,10 @@
1
+ /** Default slug of the video block (`videoBlock()`). */
2
+ export declare const DEFAULT_VIDEO_BLOCK_SLUG = "video";
3
+ /** Aspect ratio choices stored on the video block, and the CSS `aspect-ratio` each maps to. */
4
+ export declare const VIDEO_BLOCK_ASPECT_RATIOS: {
5
+ readonly auto: "auto";
6
+ readonly landscape: "16 / 9";
7
+ readonly portrait: "9 / 16";
8
+ readonly square: "1 / 1";
9
+ readonly standard: "4 / 3";
10
+ };
@@ -0,0 +1,10 @@
1
+ /** Default slug of the video block (`videoBlock()`). */ export const DEFAULT_VIDEO_BLOCK_SLUG = 'video';
2
+ /** Aspect ratio choices stored on the video block, and the CSS `aspect-ratio` each maps to. */ export const VIDEO_BLOCK_ASPECT_RATIOS = {
3
+ auto: 'auto',
4
+ landscape: '16 / 9',
5
+ portrait: '9 / 16',
6
+ square: '1 / 1',
7
+ standard: '4 / 3'
8
+ };
9
+
10
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/frontend/constants.ts"],"sourcesContent":["/** Default slug of the video block (`videoBlock()`). */\nexport const DEFAULT_VIDEO_BLOCK_SLUG = 'video'\n\n/** Aspect ratio choices stored on the video block, and the CSS `aspect-ratio` each maps to. */\nexport const VIDEO_BLOCK_ASPECT_RATIOS = {\n auto: 'auto',\n landscape: '16 / 9',\n portrait: '9 / 16',\n square: '1 / 1',\n standard: '4 / 3',\n} as const\n"],"names":["DEFAULT_VIDEO_BLOCK_SLUG","VIDEO_BLOCK_ASPECT_RATIOS","auto","landscape","portrait","square","standard"],"mappings":"AAAA,sDAAsD,GACtD,OAAO,MAAMA,2BAA2B,QAAO;AAE/C,6FAA6F,GAC7F,OAAO,MAAMC,4BAA4B;IACvCC,MAAM;IACNC,WAAW;IACXC,UAAU;IACVC,QAAQ;IACRC,UAAU;AACZ,EAAU"}
@@ -0,0 +1,25 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { VideoBlockProps } from './Video.js';
3
+ export type VideoJSXConvertersArgs = {
4
+ /** Block slug if you changed it in `videoBlock({ slug })`. Default `video`. */
5
+ slug?: string;
6
+ } & Omit<VideoBlockProps, 'block'>;
7
+ /**
8
+ * Lexical JSX converters for the video block, for `RichText` from `@payloadcms/richtext-lexical/react`:
9
+ *
10
+ * ```tsx
11
+ * <RichText data={post.content} converters={({ defaultConverters }) => ({
12
+ * ...defaultConverters,
13
+ * blocks: { ...defaultConverters.blocks, ...videoJSXConverters({ player: MyPlayer }).blocks },
14
+ * })} />
15
+ * ```
16
+ *
17
+ * Typed loosely so it works with the converter types of every Payload version.
18
+ */
19
+ export declare const videoJSXConverters: ({ slug, ...props }?: VideoJSXConvertersArgs) => {
20
+ blocks: Record<string, (args: {
21
+ node: {
22
+ fields?: unknown;
23
+ };
24
+ }) => ReactNode>;
25
+ };
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { DEFAULT_VIDEO_BLOCK_SLUG } from './constants.js';
3
+ import { VideoBlock } from './Video.js';
4
+ /**
5
+ * Lexical JSX converters for the video block, for `RichText` from `@payloadcms/richtext-lexical/react`:
6
+ *
7
+ * ```tsx
8
+ * <RichText data={post.content} converters={({ defaultConverters }) => ({
9
+ * ...defaultConverters,
10
+ * blocks: { ...defaultConverters.blocks, ...videoJSXConverters({ player: MyPlayer }).blocks },
11
+ * })} />
12
+ * ```
13
+ *
14
+ * Typed loosely so it works with the converter types of every Payload version.
15
+ */ export const videoJSXConverters = ({ slug = DEFAULT_VIDEO_BLOCK_SLUG, ...props } = {})=>({
16
+ blocks: {
17
+ [slug]: ({ node })=>/*#__PURE__*/ _jsx(VideoBlock, {
18
+ ...props,
19
+ block: node.fields
20
+ })
21
+ }
22
+ });
23
+
24
+ //# sourceMappingURL=converters.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/frontend/converters.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\n\nimport type { VideoBlockProps } from './Video.js'\n\nimport { DEFAULT_VIDEO_BLOCK_SLUG } from './constants.js'\nimport { VideoBlock } from './Video.js'\n\nexport type VideoJSXConvertersArgs = {\n /** Block slug if you changed it in `videoBlock({ slug })`. Default `video`. */\n slug?: string\n} & Omit<VideoBlockProps, 'block'>\n\n/**\n * Lexical JSX converters for the video block, for `RichText` from `@payloadcms/richtext-lexical/react`:\n *\n * ```tsx\n * <RichText data={post.content} converters={({ defaultConverters }) => ({\n * ...defaultConverters,\n * blocks: { ...defaultConverters.blocks, ...videoJSXConverters({ player: MyPlayer }).blocks },\n * })} />\n * ```\n *\n * Typed loosely so it works with the converter types of every Payload version.\n */\nexport const videoJSXConverters = ({\n slug = DEFAULT_VIDEO_BLOCK_SLUG,\n ...props\n}: VideoJSXConvertersArgs = {}): { blocks: Record<string, (args: { node: { fields?: unknown } }) => ReactNode> } => ({\n blocks: {\n [slug]: ({ node }) => <VideoBlock {...props} block={node.fields} />,\n },\n})\n"],"names":["DEFAULT_VIDEO_BLOCK_SLUG","VideoBlock","videoJSXConverters","slug","props","blocks","node","block","fields"],"mappings":";AAIA,SAASA,wBAAwB,QAAQ,iBAAgB;AACzD,SAASC,UAAU,QAAQ,aAAY;AAOvC;;;;;;;;;;;CAWC,GACD,OAAO,MAAMC,qBAAqB,CAAC,EACjCC,OAAOH,wBAAwB,EAC/B,GAAGI,OACoB,GAAG,CAAC,CAAC,GAAuF,CAAA;QACnHC,QAAQ;YACN,CAACF,KAAK,EAAE,CAAC,EAAEG,IAAI,EAAE,iBAAK,KAACL;oBAAY,GAAGG,KAAK;oBAAEG,OAAOD,KAAKE,MAAM;;QACjE;IACF,CAAA,EAAE"}
@@ -0,0 +1,80 @@
1
+ /** Everything a video player needs, as plain strings. Pass `hls` (or `dash`) to any compatible player. */
2
+ export type VideoSource = {
3
+ /** The provider's asset id. */
4
+ assetId: string;
5
+ /** Caption tracks published at the provider (also embedded in the HLS/DASH manifests). */
6
+ captions: {
7
+ generated?: boolean;
8
+ label: string;
9
+ language: string;
10
+ }[];
11
+ /** DASH manifest, for Shaka Player, dash.js… Only some providers (Cloudflare) have one. */
12
+ dash?: string;
13
+ /** Duration in seconds, when known. */
14
+ duration?: number;
15
+ /** ISO timestamp when the signed token in these URLs expires (private videos only). */
16
+ expiresAt?: string;
17
+ /** HLS manifest, for hls.js, Video.js, Vidstack, native Safari/iOS, ExoPlayer… */
18
+ hls: string;
19
+ height?: number;
20
+ /** Payload document id, when known. */
21
+ id?: number | string;
22
+ /** The provider's iframe player. */
23
+ iframe: string;
24
+ /** Poster image (the video's thumbnail). */
25
+ poster: string;
26
+ /** Id of the provider that serves the video, e.g. `cloudflare`. */
27
+ provider: string;
28
+ /** False while the provider is still processing the video. */
29
+ ready: boolean;
30
+ /** True when the URLs carry a signed token (private video). */
31
+ signed: boolean;
32
+ title?: string;
33
+ /** The provider's hosted watch page, when it has one. */
34
+ watch?: string;
35
+ width?: number;
36
+ };
37
+ /** Player settings, e.g. from a video block. Every player maps these to its own props. */
38
+ export type VideoPlayerOptions = {
39
+ /** CSS aspect ratio such as `16 / 9`; `auto` uses the video's own dimensions. */
40
+ aspectRatio?: string;
41
+ autoplay?: boolean;
42
+ controls?: boolean;
43
+ /** BCP 47 language tag of the caption track to show by default. */
44
+ defaultTextTrack?: string;
45
+ loop?: boolean;
46
+ /** Start muted. Autoplay always plays muted, because browsers block unmuted autoplay. */
47
+ muted?: boolean;
48
+ /** Override the poster image URL. */
49
+ poster?: string;
50
+ preload?: 'auto' | 'metadata' | 'none';
51
+ /** Start position in seconds. */
52
+ startTime?: number;
53
+ };
54
+ /**
55
+ * The id of a video relationship value: the id itself when the relationship isn't populated, or the
56
+ * populated document's `id`.
57
+ */
58
+ export declare const videoDocId: (video: unknown) => null | number | string;
59
+ /**
60
+ * Turns a populated video document (or its `playback` field, or the `GET /:id/playback` response)
61
+ * into a {@link VideoSource}. Returns null when there are no playback URLs: the relationship isn't
62
+ * populated (query with `depth >= 1`), the video hasn't been uploaded, or it's private and this
63
+ * reader didn't receive a token (fetch it in the browser with `useVideoSource`).
64
+ */
65
+ export declare const getVideoSource: (video: unknown) => null | VideoSource;
66
+ /** True when the source's signed token expires within `marginSeconds` (default 60). */
67
+ export declare const isVideoSourceExpired: (source: VideoSource, marginSeconds?: number, now?: number) => boolean;
68
+ type IframeParams = (options: VideoPlayerOptions) => Record<string, string | undefined>;
69
+ /**
70
+ * How each provider's iframe player takes the player options, keyed by `source.provider`. Pure data,
71
+ * so a new provider is one more row. Unknown providers get the iframe URL unchanged.
72
+ */
73
+ export declare const IFRAME_PARAMS: Record<string, IframeParams>;
74
+ /** The provider's iframe player URL with the given options applied (autoplay, muted, startTime…). */
75
+ export declare const videoIframeSrc: (source: VideoSource, options?: VideoPlayerOptions) => string;
76
+ /** CSS `aspect-ratio` for a source: the option when set, else the video's dimensions, else 16 / 9. */
77
+ export declare const videoAspectRatio: (source: null | VideoSource, options?: VideoPlayerOptions) => string;
78
+ /** Reads the player settings stored on a video block (see `videoBlock`). */
79
+ export declare const blockPlayerOptions: (block: unknown) => VideoPlayerOptions;
80
+ export {};
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Player-agnostic playback sources. Pure functions with no Payload, React or Next.js imports, so
3
+ * they run anywhere: React Server Components, route handlers, the browser, or plain Node.
4
+ */ import { VIDEO_BLOCK_ASPECT_RATIOS } from './constants.js';
5
+ const isObject = (value)=>typeof value === 'object' && value !== null;
6
+ const isPlayback = (value)=>isObject(value) && typeof value.assetId === 'string' && 'urls' in value && 'readyToStream' in value;
7
+ /**
8
+ * The id of a video relationship value: the id itself when the relationship isn't populated, or the
9
+ * populated document's `id`.
10
+ */ export const videoDocId = (video)=>{
11
+ if (typeof video === 'string' || typeof video === 'number') {
12
+ return video;
13
+ }
14
+ if (isObject(video) && (typeof video.id === 'string' || typeof video.id === 'number')) {
15
+ return video.id;
16
+ }
17
+ return null;
18
+ };
19
+ /**
20
+ * Turns a populated video document (or its `playback` field, or the `GET /:id/playback` response)
21
+ * into a {@link VideoSource}. Returns null when there are no playback URLs: the relationship isn't
22
+ * populated (query with `depth >= 1`), the video hasn't been uploaded, or it's private and this
23
+ * reader didn't receive a token (fetch it in the browser with `useVideoSource`).
24
+ */ export const getVideoSource = (video)=>{
25
+ if (!isObject(video)) {
26
+ return null;
27
+ }
28
+ const doc = isPlayback(video) ? {
29
+ playback: video
30
+ } : video;
31
+ const playback = doc.playback;
32
+ if (!isPlayback(playback) || !playback.urls) {
33
+ return null;
34
+ }
35
+ const { urls } = playback;
36
+ return {
37
+ assetId: playback.assetId,
38
+ captions: (doc.captions ?? []).filter((c)=>Boolean(c?.language)).map((c)=>({
39
+ ...typeof c.generated === 'boolean' ? {
40
+ generated: c.generated
41
+ } : {},
42
+ label: c.label || c.language,
43
+ language: c.language
44
+ })),
45
+ ...urls.dash ? {
46
+ dash: urls.dash
47
+ } : {},
48
+ ...typeof doc.duration === 'number' && doc.duration > 0 ? {
49
+ duration: doc.duration
50
+ } : {},
51
+ ...playback.expiresAt ? {
52
+ expiresAt: playback.expiresAt
53
+ } : {},
54
+ hls: urls.hls,
55
+ ...typeof doc.height === 'number' ? {
56
+ height: doc.height
57
+ } : {},
58
+ ...doc.id !== undefined ? {
59
+ id: doc.id
60
+ } : {},
61
+ iframe: urls.iframe,
62
+ poster: urls.thumbnail,
63
+ provider: playback.provider,
64
+ ready: Boolean(playback.readyToStream),
65
+ signed: Boolean(playback.signed),
66
+ ...doc.title ? {
67
+ title: doc.title
68
+ } : {},
69
+ ...urls.watch ? {
70
+ watch: urls.watch
71
+ } : {},
72
+ ...typeof doc.width === 'number' ? {
73
+ width: doc.width
74
+ } : {}
75
+ };
76
+ };
77
+ /** True when the source's signed token expires within `marginSeconds` (default 60). */ export const isVideoSourceExpired = (source, marginSeconds = 60, now = Date.now())=>Boolean(source.expiresAt) && Date.parse(source.expiresAt) - marginSeconds * 1000 <= now;
78
+ /**
79
+ * How each provider's iframe player takes the player options, keyed by `source.provider`. Pure data,
80
+ * so a new provider is one more row. Unknown providers get the iframe URL unchanged.
81
+ */ export const IFRAME_PARAMS = {
82
+ cloudflare: (options)=>({
83
+ autoplay: options.autoplay ? 'true' : undefined,
84
+ // Browsers block unmuted autoplay, so autoplay always plays muted.
85
+ muted: options.muted || options.autoplay ? 'true' : undefined,
86
+ loop: options.loop ? 'true' : undefined,
87
+ controls: options.controls === false ? 'false' : undefined,
88
+ startTime: options.startTime ? `${options.startTime}s` : undefined,
89
+ preload: options.preload,
90
+ defaultTextTrack: options.defaultTextTrack,
91
+ poster: options.poster
92
+ }),
93
+ // Bunny's player autoplays by default, so autoplay is always explicit. It has no `controls` or
94
+ // `poster` parameter.
95
+ bunny: (options)=>({
96
+ autoplay: options.autoplay ? 'true' : 'false',
97
+ muted: options.muted || options.autoplay ? 'true' : undefined,
98
+ loop: options.loop ? 'true' : undefined,
99
+ t: options.startTime ? `${options.startTime}s` : undefined,
100
+ preload: options.preload === undefined ? undefined : options.preload === 'none' ? 'false' : 'true',
101
+ captions: options.defaultTextTrack
102
+ }),
103
+ // https://player.mux.com/reference.md – booleans are on when present; no default-caption parameter.
104
+ mux: (options)=>({
105
+ autoplay: options.autoplay ? 'true' : undefined,
106
+ muted: options.muted || options.autoplay ? 'true' : undefined,
107
+ loop: options.loop ? 'true' : undefined,
108
+ controls: options.controls === false ? 'false' : undefined,
109
+ 'start-time': options.startTime ? String(options.startTime) : undefined,
110
+ preload: options.preload,
111
+ poster: options.poster
112
+ })
113
+ };
114
+ /** The provider's iframe player URL with the given options applied (autoplay, muted, startTime…). */ export const videoIframeSrc = (source, options = {})=>{
115
+ const params = IFRAME_PARAMS[source.provider];
116
+ if (!params) {
117
+ return source.iframe;
118
+ }
119
+ const url = new URL(source.iframe);
120
+ for (const [key, value] of Object.entries(params(options))){
121
+ if (value !== undefined) {
122
+ url.searchParams.set(key, value);
123
+ }
124
+ }
125
+ return url.toString();
126
+ };
127
+ /** CSS `aspect-ratio` for a source: the option when set, else the video's dimensions, else 16 / 9. */ export const videoAspectRatio = (source, options = {})=>{
128
+ if (options.aspectRatio && options.aspectRatio !== 'auto') {
129
+ return options.aspectRatio;
130
+ }
131
+ if (source?.width && source.height) {
132
+ return `${source.width} / ${source.height}`;
133
+ }
134
+ return '16 / 9';
135
+ };
136
+ /** Reads the player settings stored on a video block (see `videoBlock`). */ export const blockPlayerOptions = (block)=>{
137
+ if (!isObject(block)) {
138
+ return {};
139
+ }
140
+ const bool = (key)=>typeof block[key] === 'boolean' ? block[key] : undefined;
141
+ const options = {};
142
+ const assign = (key, value)=>{
143
+ if (value !== undefined) {
144
+ options[key] = value;
145
+ }
146
+ };
147
+ assign('autoplay', bool('autoplay'));
148
+ assign('muted', bool('muted'));
149
+ assign('loop', bool('loop'));
150
+ assign('controls', bool('controls'));
151
+ assign('startTime', typeof block.startTime === 'number' && block.startTime > 0 ? block.startTime : undefined);
152
+ const ratio = block.aspectRatio;
153
+ assign('aspectRatio', typeof ratio === 'string' && ratio ? VIDEO_BLOCK_ASPECT_RATIOS[ratio] ?? ratio : undefined);
154
+ assign('defaultTextTrack', typeof block.defaultTextTrack === 'string' && block.defaultTextTrack ? block.defaultTextTrack : undefined);
155
+ assign('preload', block.preload === 'auto' || block.preload === 'metadata' || block.preload === 'none' ? block.preload : undefined);
156
+ return options;
157
+ };
158
+
159
+ //# sourceMappingURL=source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/frontend/source.ts"],"sourcesContent":["/**\n * Player-agnostic playback sources. Pure functions with no Payload, React or Next.js imports, so\n * they run anywhere: React Server Components, route handlers, the browser, or plain Node.\n */\nimport type { VideoPlayback } from '../types.js'\n\nimport { VIDEO_BLOCK_ASPECT_RATIOS } from './constants.js'\n\n/** Everything a video player needs, as plain strings. Pass `hls` (or `dash`) to any compatible player. */\nexport type VideoSource = {\n /** The provider's asset id. */\n assetId: string\n /** Caption tracks published at the provider (also embedded in the HLS/DASH manifests). */\n captions: { generated?: boolean; label: string; language: string }[]\n /** DASH manifest, for Shaka Player, dash.js… Only some providers (Cloudflare) have one. */\n dash?: string\n /** Duration in seconds, when known. */\n duration?: number\n /** ISO timestamp when the signed token in these URLs expires (private videos only). */\n expiresAt?: string\n /** HLS manifest, for hls.js, Video.js, Vidstack, native Safari/iOS, ExoPlayer… */\n hls: string\n height?: number\n /** Payload document id, when known. */\n id?: number | string\n /** The provider's iframe player. */\n iframe: string\n /** Poster image (the video's thumbnail). */\n poster: string\n /** Id of the provider that serves the video, e.g. `cloudflare`. */\n provider: string\n /** False while the provider is still processing the video. */\n ready: boolean\n /** True when the URLs carry a signed token (private video). */\n signed: boolean\n title?: string\n /** The provider's hosted watch page, when it has one. */\n watch?: string\n width?: number\n}\n\n/** Player settings, e.g. from a video block. Every player maps these to its own props. */\nexport type VideoPlayerOptions = {\n /** CSS aspect ratio such as `16 / 9`; `auto` uses the video's own dimensions. */\n aspectRatio?: string\n autoplay?: boolean\n controls?: boolean\n /** BCP 47 language tag of the caption track to show by default. */\n defaultTextTrack?: string\n loop?: boolean\n /** Start muted. Autoplay always plays muted, because browsers block unmuted autoplay. */\n muted?: boolean\n /** Override the poster image URL. */\n poster?: string\n preload?: 'auto' | 'metadata' | 'none'\n /** Start position in seconds. */\n startTime?: number\n}\n\ntype VideoLike = {\n captions?: null | { generated?: boolean | null; label?: null | string; language?: null | string }[]\n duration?: null | number\n height?: null | number\n id?: number | string\n playback?: null | VideoPlayback\n title?: null | string\n width?: null | number\n}\n\nconst isObject = (value: unknown): value is Record<string, unknown> => typeof value === 'object' && value !== null\n\nconst isPlayback = (value: unknown): value is VideoPlayback =>\n isObject(value) && typeof value.assetId === 'string' && 'urls' in value && 'readyToStream' in value\n\n/**\n * The id of a video relationship value: the id itself when the relationship isn't populated, or the\n * populated document's `id`.\n */\nexport const videoDocId = (video: unknown): null | number | string => {\n if (typeof video === 'string' || typeof video === 'number') {\n return video\n }\n if (isObject(video) && (typeof video.id === 'string' || typeof video.id === 'number')) {\n return video.id\n }\n return null\n}\n\n/**\n * Turns a populated video document (or its `playback` field, or the `GET /:id/playback` response)\n * into a {@link VideoSource}. Returns null when there are no playback URLs: the relationship isn't\n * populated (query with `depth >= 1`), the video hasn't been uploaded, or it's private and this\n * reader didn't receive a token (fetch it in the browser with `useVideoSource`).\n */\nexport const getVideoSource = (video: unknown): null | VideoSource => {\n if (!isObject(video)) {\n return null\n }\n const doc = (isPlayback(video) ? { playback: video } : video) as VideoLike\n const playback = doc.playback\n if (!isPlayback(playback) || !playback.urls) {\n return null\n }\n const { urls } = playback\n return {\n assetId: playback.assetId,\n captions: (doc.captions ?? [])\n .filter((c): c is { generated?: boolean | null; label?: null | string; language: string } => Boolean(c?.language))\n .map((c) => ({\n ...(typeof c.generated === 'boolean' ? { generated: c.generated } : {}),\n label: c.label || c.language,\n language: c.language,\n })),\n ...(urls.dash ? { dash: urls.dash } : {}),\n ...(typeof doc.duration === 'number' && doc.duration > 0 ? { duration: doc.duration } : {}),\n ...(playback.expiresAt ? { expiresAt: playback.expiresAt } : {}),\n hls: urls.hls,\n ...(typeof doc.height === 'number' ? { height: doc.height } : {}),\n ...(doc.id !== undefined ? { id: doc.id } : {}),\n iframe: urls.iframe,\n poster: urls.thumbnail,\n provider: playback.provider,\n ready: Boolean(playback.readyToStream),\n signed: Boolean(playback.signed),\n ...(doc.title ? { title: doc.title } : {}),\n ...(urls.watch ? { watch: urls.watch } : {}),\n ...(typeof doc.width === 'number' ? { width: doc.width } : {}),\n }\n}\n\n/** True when the source's signed token expires within `marginSeconds` (default 60). */\nexport const isVideoSourceExpired = (source: VideoSource, marginSeconds = 60, now = Date.now()): boolean =>\n Boolean(source.expiresAt) && Date.parse(source.expiresAt!) - marginSeconds * 1000 <= now\n\ntype IframeParams = (options: VideoPlayerOptions) => Record<string, string | undefined>\n\n/**\n * How each provider's iframe player takes the player options, keyed by `source.provider`. Pure data,\n * so a new provider is one more row. Unknown providers get the iframe URL unchanged.\n */\nexport const IFRAME_PARAMS: Record<string, IframeParams> = {\n cloudflare: (options) => ({\n autoplay: options.autoplay ? 'true' : undefined,\n // Browsers block unmuted autoplay, so autoplay always plays muted.\n muted: options.muted || options.autoplay ? 'true' : undefined,\n loop: options.loop ? 'true' : undefined,\n controls: options.controls === false ? 'false' : undefined,\n startTime: options.startTime ? `${options.startTime}s` : undefined,\n preload: options.preload,\n defaultTextTrack: options.defaultTextTrack,\n poster: options.poster,\n }),\n // Bunny's player autoplays by default, so autoplay is always explicit. It has no `controls` or\n // `poster` parameter.\n bunny: (options) => ({\n autoplay: options.autoplay ? 'true' : 'false',\n muted: options.muted || options.autoplay ? 'true' : undefined,\n loop: options.loop ? 'true' : undefined,\n t: options.startTime ? `${options.startTime}s` : undefined,\n preload: options.preload === undefined ? undefined : options.preload === 'none' ? 'false' : 'true',\n captions: options.defaultTextTrack,\n }),\n // https://player.mux.com/reference.md – booleans are on when present; no default-caption parameter.\n mux: (options) => ({\n autoplay: options.autoplay ? 'true' : undefined,\n muted: options.muted || options.autoplay ? 'true' : undefined,\n loop: options.loop ? 'true' : undefined,\n controls: options.controls === false ? 'false' : undefined,\n 'start-time': options.startTime ? String(options.startTime) : undefined,\n preload: options.preload,\n poster: options.poster,\n }),\n}\n\n/** The provider's iframe player URL with the given options applied (autoplay, muted, startTime…). */\nexport const videoIframeSrc = (source: VideoSource, options: VideoPlayerOptions = {}): string => {\n const params = IFRAME_PARAMS[source.provider]\n if (!params) {\n return source.iframe\n }\n const url = new URL(source.iframe)\n for (const [key, value] of Object.entries(params(options))) {\n if (value !== undefined) {\n url.searchParams.set(key, value)\n }\n }\n return url.toString()\n}\n\n/** CSS `aspect-ratio` for a source: the option when set, else the video's dimensions, else 16 / 9. */\nexport const videoAspectRatio = (source: null | VideoSource, options: VideoPlayerOptions = {}): string => {\n if (options.aspectRatio && options.aspectRatio !== 'auto') {\n return options.aspectRatio\n }\n if (source?.width && source.height) {\n return `${source.width} / ${source.height}`\n }\n return '16 / 9'\n}\n\n/** Reads the player settings stored on a video block (see `videoBlock`). */\nexport const blockPlayerOptions = (block: unknown): VideoPlayerOptions => {\n if (!isObject(block)) {\n return {}\n }\n const bool = (key: string) => (typeof block[key] === 'boolean' ? (block[key] as boolean) : undefined)\n const options: VideoPlayerOptions = {}\n const assign = <K extends keyof VideoPlayerOptions>(key: K, value: undefined | VideoPlayerOptions[K]) => {\n if (value !== undefined) {\n options[key] = value\n }\n }\n assign('autoplay', bool('autoplay'))\n assign('muted', bool('muted'))\n assign('loop', bool('loop'))\n assign('controls', bool('controls'))\n assign('startTime', typeof block.startTime === 'number' && block.startTime > 0 ? block.startTime : undefined)\n const ratio = block.aspectRatio\n assign(\n 'aspectRatio',\n typeof ratio === 'string' && ratio\n ? ((VIDEO_BLOCK_ASPECT_RATIOS as Record<string, string>)[ratio] ?? ratio)\n : undefined,\n )\n assign('defaultTextTrack', typeof block.defaultTextTrack === 'string' && block.defaultTextTrack ? block.defaultTextTrack : undefined)\n assign(\n 'preload',\n block.preload === 'auto' || block.preload === 'metadata' || block.preload === 'none' ? block.preload : undefined,\n )\n return options\n}\n"],"names":["VIDEO_BLOCK_ASPECT_RATIOS","isObject","value","isPlayback","assetId","videoDocId","video","id","getVideoSource","doc","playback","urls","captions","filter","c","Boolean","language","map","generated","label","dash","duration","expiresAt","hls","height","undefined","iframe","poster","thumbnail","provider","ready","readyToStream","signed","title","watch","width","isVideoSourceExpired","source","marginSeconds","now","Date","parse","IFRAME_PARAMS","cloudflare","options","autoplay","muted","loop","controls","startTime","preload","defaultTextTrack","bunny","t","mux","String","videoIframeSrc","params","url","URL","key","Object","entries","searchParams","set","toString","videoAspectRatio","aspectRatio","blockPlayerOptions","block","bool","assign","ratio"],"mappings":"AAAA;;;CAGC,GAGD,SAASA,yB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B;IACnG,MAAM+C,QAAQH,MAAMF,WAAW;IAC/BI,OACE,eACA,OAAOC,UAAU,YAAYA,QACxB,AAACxE,yBAAoD,CAACwE,MAAM,IAAIA,QACjE/C;IAEN8C,OAAO,oBAAoB,OAAOF,MAAMlB,gBAAgB,KAAK,YAAYkB,MAAMlB,gBAAgB,GAAGkB,MAAMlB,gBAAgB,GAAG1B;IAC3H8C,OACE,WACAF,MAAMnB,OAAO,KAAK,UAAUmB,MAAMnB,OAAO,KAAK,cAAcmB,MAAMnB,OAAO,KAAK,SAASmB,MAAMnB,OAAO,GAAGzB;IAEzG,OAAOmB;AACT,EAAC"}
@@ -0,0 +1,27 @@
1
+ import type { VideoSource } from './source.js';
2
+ export type UseVideoSourceOptions = {
3
+ /** Payload's REST API base path. Default `/api`. */
4
+ apiBase?: string;
5
+ /** Slug of the videos collection if you changed it. Default `videos`. */
6
+ collectionSlug?: string;
7
+ /** Custom fetch (e.g. to add headers). Requests use `credentials: 'include'` by default. */
8
+ fetch?: typeof fetch;
9
+ };
10
+ export type UseVideoSourceResult = {
11
+ error: Error | null;
12
+ loading: boolean;
13
+ /** Fetches fresh URLs (and a fresh token for private videos). */
14
+ refresh: () => Promise<void>;
15
+ source: null | VideoSource;
16
+ };
17
+ /**
18
+ * Resolves a video relationship value (a populated document, or just its id) into a
19
+ * {@link VideoSource} in the browser.
20
+ *
21
+ * - Populated documents with playback URLs are used as-is, without a request.
22
+ * - Ids, and private videos whose URLs weren't signed on the server, are fetched from the REST API
23
+ * with the visitor's session, so `access.read` and `access.playback` apply.
24
+ * - Expired tokens are refreshed when the page becomes visible again. Tokens are signed to outlast
25
+ * the video, so a playing video never needs a new URL.
26
+ */
27
+ export declare const useVideoSource: (video: unknown, options?: UseVideoSourceOptions) => UseVideoSourceResult;
@@ -0,0 +1,108 @@
1
+ 'use client';
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
+ import { getVideoSource, isVideoSourceExpired, videoDocId } from './source.js';
4
+ /**
5
+ * Resolves a video relationship value (a populated document, or just its id) into a
6
+ * {@link VideoSource} in the browser.
7
+ *
8
+ * - Populated documents with playback URLs are used as-is, without a request.
9
+ * - Ids, and private videos whose URLs weren't signed on the server, are fetched from the REST API
10
+ * with the visitor's session, so `access.read` and `access.playback` apply.
11
+ * - Expired tokens are refreshed when the page becomes visible again. Tokens are signed to outlast
12
+ * the video, so a playing video never needs a new URL.
13
+ */ export const useVideoSource = (video, options = {})=>{
14
+ const { apiBase = '/api', collectionSlug = 'videos' } = options;
15
+ const fetchRef = useRef(options.fetch);
16
+ fetchRef.current = options.fetch;
17
+ const initial = useMemo(()=>getVideoSource(video), [
18
+ video
19
+ ]);
20
+ const id = videoDocId(video);
21
+ const [fetched, setFetched] = useState(null);
22
+ const [error, setError] = useState(null);
23
+ const [loading, setLoading] = useState(false);
24
+ const source = fetched ?? initial;
25
+ const refresh = useCallback(async ()=>{
26
+ if (id === null) {
27
+ return;
28
+ }
29
+ const doFetch = fetchRef.current ?? fetch;
30
+ const base = `${apiBase.replace(/\/$/, '')}/${collectionSlug}/${encodeURIComponent(String(id))}`;
31
+ setLoading(true);
32
+ try {
33
+ const docRes = await doFetch(`${base}?depth=0`, {
34
+ credentials: 'include'
35
+ });
36
+ if (!docRes.ok) {
37
+ throw new Error(docRes.status === 404 ? 'Video not found' : `Could not load video (${docRes.status})`);
38
+ }
39
+ const doc = await docRes.json();
40
+ let next = getVideoSource(doc);
41
+ if (!next || isVideoSourceExpired(next)) {
42
+ // Private video without server-side signing: ask the playback endpoint for a token.
43
+ const playbackRes = await doFetch(`${base}/playback`, {
44
+ credentials: 'include'
45
+ });
46
+ if (!playbackRes.ok) {
47
+ throw new Error(playbackRes.status === 403 ? 'You may not watch this video' : `Could not load playback (${playbackRes.status})`);
48
+ }
49
+ next = getVideoSource({
50
+ ...doc,
51
+ playback: await playbackRes.json()
52
+ });
53
+ }
54
+ if (!next) {
55
+ throw new Error('This video has no playback URLs yet');
56
+ }
57
+ setFetched(next);
58
+ setError(null);
59
+ } catch (err) {
60
+ setError(err instanceof Error ? err : new Error(String(err)));
61
+ } finally{
62
+ setLoading(false);
63
+ }
64
+ }, [
65
+ apiBase,
66
+ collectionSlug,
67
+ id
68
+ ]);
69
+ const needsFetch = id !== null && (!source || isVideoSourceExpired(source));
70
+ useEffect(()=>{
71
+ setFetched(null);
72
+ }, [
73
+ initial
74
+ ]);
75
+ useEffect(()=>{
76
+ if (needsFetch && !loading && !error) {
77
+ void refresh();
78
+ }
79
+ }, [
80
+ error,
81
+ loading,
82
+ needsFetch,
83
+ refresh
84
+ ]);
85
+ useEffect(()=>{
86
+ if (!source?.expiresAt || typeof document === 'undefined') {
87
+ return;
88
+ }
89
+ const onVisible = ()=>{
90
+ if (document.visibilityState === 'visible' && isVideoSourceExpired(source)) {
91
+ void refresh();
92
+ }
93
+ };
94
+ document.addEventListener('visibilitychange', onVisible);
95
+ return ()=>document.removeEventListener('visibilitychange', onVisible);
96
+ }, [
97
+ refresh,
98
+ source
99
+ ]);
100
+ return {
101
+ error,
102
+ loading: loading || needsFetch && !error,
103
+ refresh,
104
+ source: source && !isVideoSourceExpired(source, 0) ? source : null
105
+ };
106
+ };
107
+
108
+ //# sourceMappingURL=useVideoSource.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/frontend/useVideoSource.ts"],"sourcesContent":["'use client'\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\n\nimport type { VideoSource } from './source.js'\n\nimport { getVideoSource, isVideoSourceExpired, videoDocId } from './source.js'\n\nexport type UseVideoSourceOptions = {\n /** Payload's REST API base path. Default `/api`. */\n apiBase?: string\n /** Slug of the videos collection if you changed it. Default `videos`. */\n collectionSlug?: string\n /** Custom fetch (e.g. to add headers). Requests use `credentials: 'include'` by default. */\n fetch?: typeof fetch\n}\n\nexport type UseVideoSourceResult = {\n error: Error | null\n loading: boolean\n /** Fetches fresh URLs (and a fresh token for private videos). */\n refresh: () => Promise<void>\n source: null | VideoSource\n}\n\n/**\n * Resolves a video relationship value (a populated document, or just its id) into a\n * {@link VideoSource} in the browser.\n *\n * - Populated documents with playback URLs are used as-is, without a request.\n * - Ids, and private videos whose URLs weren't signed on the server, are fetched from the REST API\n * with the visitor's session, so `access.read` and `access.playback` apply.\n * - Expired tokens are refreshed when the page becomes visible again. Tokens are signed to outlast\n * the video, so a playing video never needs a new URL.\n */\nexport const useVideoSource = (video: unknown, options: UseVideoSourceOptions = {}): UseVideoSourceResult => {\n const { apiBase = '/api', collectionSlug = 'videos' } = options\n const fetchRef = useRef(options.fetch)\n fetchRef.current = options.fetch\n const initial = useMemo(() => getVideoSource(video), [video])\n const id = videoDocId(video)\n const [fetched, setFetched] = useState<null | VideoSource>(null)\n const [error, setError] = useState<Error | null>(null)\n const [loading, setLoading] = useState(false)\n\n const source = fetched ?? initial\n\n const refresh = useCallback(async () => {\n if (id === null) {\n return\n }\n const doFetch = fetchRef.current ?? fetch\n const base = `${apiBase.replace(/\\/$/, '')}/${collectionSlug}/${encodeURIComponent(String(id))}`\n setLoading(true)\n try {\n const docRes = await doFetch(`${base}?depth=0`, { credentials: 'include' })\n if (!docRes.ok) {\n throw new Error(docRes.status === 404 ? 'Video not found' : `Could not load video (${docRes.status})`)\n }\n const doc = (await docRes.json()) as Record<string, unknown>\n let next = getVideoSource(doc)\n if (!next || isVideoSourceExpired(next)) {\n // Private video without server-side signing: ask the playback endpoint for a token.\n const playbackRes = await doFetch(`${base}/playback`, { credentials: 'include' })\n if (!playbackRes.ok) {\n throw new Error(playbackRes.status === 403 ? 'You may not watch this video' : `Could not load playback (${playbackRes.status})`)\n }\n next = getVideoSource({ ...doc, playback: await playbackRes.json() })\n }\n if (!next) {\n throw new Error('This video has no playback URLs yet')\n }\n setFetched(next)\n setError(null)\n } catch (err) {\n setError(err instanceof Error ? err : new Error(String(err)))\n } finally {\n setLoading(false)\n }\n }, [apiBase, collectionSlug, id])\n\n const needsFetch = id !== null && (!source || isVideoSourceExpired(source))\n\n useEffect(() => {\n setFetched(null)\n }, [initial])\n\n useEffect(() => {\n if (needsFetch && !loading && !error) {\n void refresh()\n }\n }, [error, loading, needsFetch, refresh])\n\n useEffect(() => {\n if (!source?.expiresAt || typeof document === 'undefined') {\n return\n }\n const onVisible = () => {\n if (document.visibilityState === 'visible' && isVideoSourceExpired(source)) {\n void refresh()\n }\n }\n document.addEventListener('visibilitychange', onVisible)\n return () => document.removeEventListener('visibilitychange', onVisible)\n }, [refresh, source])\n\n return { error, loading: loading || (needsFetch && !error), refresh, source: source && !isVideoSourceExpired(source, 0) ? source : null }\n}\n"],"names":["useCallback","useEffect","useMemo","useRef","useState","getVideoSource","isVideoSourceExpired","videoDocId","useVideoSource","video","options","apiBase","collectionSlug","fetchRef","fetch","current","initial","id","fetched","setFetched","error","setError","loading","setLoading","source","refresh","doFetch","base","replace","encodeURIComponent","String","docRes","credentials","ok","Error","status","doc","json","next","playbackRes","playback","err","needsFetch","expiresAt","document","onVisible","visibilityState","addEventListener","removeEventListener"],"mappings":"AAAA;AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAIzE,SAASC,cAAc,EAAEC,oBAAoB,EAAEC,UAAU,QAAQ,cAAa;AAmB9E;;;;;;;;;CASC,GACD,OAAO,MAAMC,iBAAiB,CAACC,OAAgBC,UAAiC,CAAC,CAAC;IAChF,MAAM,EAAEC,UAAU,MAAM,EAAEC,iBAAiB,QAAQ,EAAE,GAAGF;IACxD,MAAMG,WAAWV,OAAOO,QAAQI,KAAK;IACrCD,SAASE,OAAO,GAAGL,QAAQI,KAAK;IAChC,MAAME,UAAUd,QAAQ,IAAMG,eAAeI,QAAQ;QAACA;KAAM;IAC5D,MAAMQ,KAAKV,WAAWE;IACtB,MAAM,CAACS,SAASC,WAAW,GAAGf,SAA6B;IAC3D,MAAM,CAACgB,OAAOC,SAAS,GAAGjB,SAAuB;IACjD,MAAM,CAACkB,SAASC,WAAW,GAAGnB,SAAS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