@flapsdk/vault-runtime 0.1.32-next.0 → 0.1.32-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,7 @@
1
- import { shortenAddress } from './chunk-GA5VEHC2.js';
2
- import { resolveIpfsImageUrls, resolveIpfsImageUrl } from './chunk-3FQFRANQ.js';
3
- import { Loader2, ExternalLink, AlertTriangle, CheckCircle2, Info, X, ShieldCheck } from 'lucide-react';
1
+ import { shortenAddress, isValidAddress, ZERO_ADDRESS } from './chunk-B4WKI3EW.js';
2
+ import { isIpfsImageCid, resolveIpfsImageUrls, resolveIpfsImageUrl } from './chunk-SAG36LUR.js';
3
+ import { getTaxVaultHostChainConfig } from './chunk-FUOBTZMQ.js';
4
+ import { Loader2, ExternalLink, AlertTriangle, CheckCircle2, Info, X, ShieldCheck, SkipBack, ChevronLeft, ChevronRight, SkipForward } from 'lucide-react';
4
5
  import { clsx } from 'clsx';
5
6
  import { twMerge } from 'tailwind-merge';
6
7
  import * as React5 from 'react';
@@ -9,6 +10,61 @@ import { Slot } from '@radix-ui/react-slot';
9
10
  import { cva } from 'class-variance-authority';
10
11
  import { createPortal } from 'react-dom';
11
12
 
13
+ // src/sdk/videoSession.ts
14
+ var videoProviderAbi = [
15
+ { type: "function", name: "getVideoSessionLength", stateMutability: "view", inputs: [{ name: "user", type: "address" }], outputs: [{ type: "uint256" }] },
16
+ { type: "function", name: "getVideoSessionSlice", stateMutability: "view", inputs: [{ name: "user", type: "address" }, { name: "start", type: "uint256" }, { name: "count", type: "uint256" }], outputs: [{ name: "clips", type: "tuple[]", components: [
17
+ { name: "requestId", type: "uint256" },
18
+ { name: "videoCid", type: "string" },
19
+ { name: "lastFrameCid", type: "string" },
20
+ { name: "durationMs", type: "uint32" },
21
+ { name: "startPtsMs", type: "uint64" },
22
+ { name: "createdAt", type: "uint64" },
23
+ { name: "referenceType", type: "uint8" }
24
+ ] }] }
25
+ ];
26
+ var VideoSessionReadError = class extends Error {
27
+ constructor(code, message) {
28
+ super(message);
29
+ this.code = code;
30
+ this.name = "VideoSessionReadError";
31
+ }
32
+ };
33
+ var MAX_SLICE = 50;
34
+ function providerTarget(sdk, consumer) {
35
+ if (!isValidAddress(consumer) || consumer.toLowerCase() === ZERO_ADDRESS) {
36
+ throw new VideoSessionReadError("invalid", "Invalid video consumer address.");
37
+ }
38
+ const provider = getTaxVaultHostChainConfig(sdk.context.chainId)?.aiProvider;
39
+ if (!provider) throw new VideoSessionReadError("unsupported", "Video sessions are not configured for this chain.");
40
+ return provider;
41
+ }
42
+ async function readVideoSessionLength(sdk, consumer) {
43
+ const value = await sdk.readContract({ address: providerTarget(sdk, consumer), abi: videoProviderAbi, functionName: "getVideoSessionLength", args: [consumer] });
44
+ if (typeof value !== "bigint" || value < 0n || value > BigInt(Number.MAX_SAFE_INTEGER)) {
45
+ throw new VideoSessionReadError("invalid", "Invalid video session length.");
46
+ }
47
+ return Number(value);
48
+ }
49
+ async function readVideoSessionSlice(sdk, consumer, start, count) {
50
+ const address = providerTarget(sdk, consumer);
51
+ if (!Number.isSafeInteger(start) || start < 0 || !Number.isSafeInteger(count) || count < 1 || count > MAX_SLICE || !Number.isSafeInteger(start + count)) {
52
+ throw new VideoSessionReadError("invalid", "Video slice must contain 1 to 50 clips at a valid index.");
53
+ }
54
+ const value = await sdk.readContract({ address, abi: videoProviderAbi, functionName: "getVideoSessionSlice", args: [consumer, BigInt(start), BigInt(count)] });
55
+ if (!Array.isArray(value) || value.length > count) throw new VideoSessionReadError("invalid", "Invalid video session slice.");
56
+ return value.map((item, offset) => {
57
+ if (!item || typeof item !== "object") throw new VideoSessionReadError("invalid", "Invalid video clip.");
58
+ const clip = item;
59
+ if (typeof clip.videoCid !== "string" || !isIpfsImageCid(clip.videoCid) || !Number.isSafeInteger(clip.durationMs) || clip.durationMs <= 0 || clip.durationMs > 4294967295 || typeof clip.startPtsMs !== "bigint" || clip.startPtsMs < 0n || clip.startPtsMs > 0xffffffffffffffffn || typeof clip.requestId !== "bigint" || clip.requestId < 0n || typeof clip.createdAt !== "bigint" || clip.createdAt < 0n || typeof clip.lastFrameCid !== "string" || clip.lastFrameCid.length > 128 || !Number.isInteger(clip.referenceType) || clip.referenceType < 0 || clip.referenceType > 255) {
60
+ throw new VideoSessionReadError("invalid", "Invalid video clip metadata.");
61
+ }
62
+ return { index: start + offset, requestId: clip.requestId, videoCid: clip.videoCid, lastFrameCid: clip.lastFrameCid, durationMs: clip.durationMs, startPtsMs: clip.startPtsMs, createdAt: clip.createdAt, referenceType: clip.referenceType };
63
+ });
64
+ }
65
+ function createConsumerVideoSessionReader(sdk, consumer) {
66
+ return { readLength: () => readVideoSessionLength(sdk, consumer), readSlice: (start, count) => readVideoSessionSlice(sdk, consumer, start, count) };
67
+ }
12
68
  function AddressLink({ address, explorerBaseUrl, label }) {
13
69
  if (!address) return /* @__PURE__ */ React.createElement("span", null, "-");
14
70
  const href = explorerBaseUrl ? `${explorerBaseUrl.replace(/\/$/, "")}/address/${address}` : void 0;
@@ -588,9 +644,9 @@ var VideoSessionController = class {
588
644
  this.segments = [];
589
645
  this.generation = 0;
590
646
  }
591
- async update(clips, autoPlay = false) {
647
+ async update(clips, autoPlay = false, playback) {
592
648
  const segments = videoSessionSegments(clips);
593
- const key = JSON.stringify(segments);
649
+ const key = JSON.stringify([segments, playback?.revision]);
594
650
  if (key === this.key) return;
595
651
  this.key = key;
596
652
  const generation = ++this.generation;
@@ -600,6 +656,10 @@ var VideoSessionController = class {
600
656
  this.onState(segments ? "empty" : "invalid");
601
657
  return;
602
658
  }
659
+ const isAppend = !playback && this.player !== null && this.segments.length <= segments.length && this.segments.every((segment, index) => segment.url === segments[index].url && segment.duration === segments[index].duration);
660
+ const resumeAt = playback ? Math.max(0, playback.resumeAt) : isAppend ? this.video.currentTime : 0;
661
+ const shouldPlay = isAppend ? this.video.ended || !this.video.paused : autoPlay;
662
+ this.destroyPlayer();
603
663
  this.onState("loading");
604
664
  try {
605
665
  const mpegts = await this.loadMpegts();
@@ -609,10 +669,6 @@ var VideoSessionController = class {
609
669
  this.onState("unsupported");
610
670
  return;
611
671
  }
612
- const isAppend = this.player !== null && this.segments.length <= segments.length && this.segments.every((segment, index) => segment.url === segments[index].url && segment.duration === segments[index].duration);
613
- const resumeAt = isAppend ? this.video.currentTime : 0;
614
- const shouldPlay = isAppend ? this.video.ended || !this.video.paused : autoPlay;
615
- this.destroyPlayer();
616
672
  const player = mpegts.createPlayer(
617
673
  { type: "mse", isLive: false, cors: true, withCredentials: false, segments },
618
674
  {
@@ -701,11 +757,396 @@ var VideoSessionController = class {
701
757
  }
702
758
  };
703
759
 
760
+ // src/ui/consumerVideoSession.ts
761
+ var VIDEO_WINDOW_SIZE = 4;
762
+ var VIDEO_PICKER_PAGE_SIZE = 20;
763
+ var VIDEO_SESSION_POLL_MS = 8e3;
764
+ var MAX_CACHED_CLIPS = 128;
765
+ function resolveVideoClipIndex(index, length) {
766
+ if (!Number.isSafeInteger(index) || !Number.isSafeInteger(length) || length < 0) throw new VideoSessionReadError("invalid", "Invalid video clip index.");
767
+ return length === 0 ? null : Math.max(0, Math.min(length - 1, index < 0 ? length + index : index));
768
+ }
769
+ function videoClipPosition(clips, timeSeconds) {
770
+ if (!clips.length) return null;
771
+ const elapsedMs = Math.max(0, Number.isFinite(timeSeconds) ? timeSeconds * 1e3 : 0);
772
+ let clip = clips[0];
773
+ for (const candidate of clips) {
774
+ if (Number(candidate.startPtsMs - clips[0].startPtsMs) <= elapsedMs) clip = candidate;
775
+ else break;
776
+ }
777
+ const time = Math.max(0, Math.min(clip.durationMs, elapsedMs - Number(clip.startPtsMs - clips[0].startPtsMs))) / 1e3;
778
+ return { index: clip.index, time, duration: clip.durationMs / 1e3 };
779
+ }
780
+ var ConsumerVideoSession = class {
781
+ constructor(reader, emit) {
782
+ this.reader = reader;
783
+ this.emit = emit;
784
+ this.cache = /* @__PURE__ */ new Map();
785
+ this.generation = 0;
786
+ this.disposed = false;
787
+ this.refreshing = false;
788
+ this.advancing = false;
789
+ this.initialIndex = 0;
790
+ this.started = false;
791
+ this.snapshot = { state: "loading", total: 0, start: 0, clips: [], revision: 0, resumeAt: 0, play: false, refreshFailed: false, preservePosition: false };
792
+ }
793
+ publish(value) {
794
+ if (this.disposed) return;
795
+ this.snapshot = { ...this.snapshot, ...value };
796
+ this.emit(this.snapshot);
797
+ }
798
+ async refresh(initialIndex, play = false) {
799
+ if (this.disposed || this.refreshing) return;
800
+ this.refreshing = true;
801
+ if (initialIndex !== void 0) this.initialIndex = initialIndex;
802
+ try {
803
+ const total = await this.reader.readLength();
804
+ if (this.disposed) return;
805
+ if (!Number.isSafeInteger(total) || total < 0) throw new VideoSessionReadError("invalid", "Invalid video session length.");
806
+ const previous = this.snapshot.total;
807
+ const shrank = total < previous;
808
+ if (shrank) this.cache.clear();
809
+ this.publish({ total, refreshFailed: false });
810
+ if (total === 0) {
811
+ ++this.generation;
812
+ this.publish({ state: "empty", clips: [], start: 0 });
813
+ } else if (initialIndex !== void 0 || previous === 0 || shrank || this.snapshot.state === "error") {
814
+ await this.seek(this.started ? this.snapshot.start : this.initialIndex, 0, play);
815
+ }
816
+ } catch (error) {
817
+ if (this.snapshot.clips.length) this.publish({ refreshFailed: true });
818
+ else this.fail(error);
819
+ } finally {
820
+ this.refreshing = false;
821
+ }
822
+ }
823
+ async seek(index, resumeAt = 0, play = false) {
824
+ const generation = ++this.generation;
825
+ this.advancing = false;
826
+ try {
827
+ const start = resolveVideoClipIndex(index, this.snapshot.total);
828
+ if (start === null) {
829
+ this.publish({ state: "empty", clips: [] });
830
+ return;
831
+ }
832
+ this.started = true;
833
+ this.publish({ state: "loading", start, clips: [], resumeAt: 0, preservePosition: false, revision: this.snapshot.revision + 1 });
834
+ const clips = await this.readWindow(start);
835
+ if (this.disposed || generation !== this.generation) return;
836
+ this.publish({ state: "ready", start, clips, resumeAt, play, refreshFailed: false, revision: this.snapshot.revision + 1 });
837
+ } catch (error) {
838
+ if (generation === this.generation) this.fail(error);
839
+ }
840
+ }
841
+ /** Roll forward at the current clip; never grow an unbounded mpegts segment list. */
842
+ async advance(index) {
843
+ if (this.disposed || this.advancing || this.snapshot.refreshFailed || this.snapshot.state !== "ready" || index < this.snapshot.start || this.snapshot.start + this.snapshot.clips.length >= this.snapshot.total) return;
844
+ const generation = this.generation;
845
+ this.advancing = true;
846
+ try {
847
+ const clips = await this.readWindow(index);
848
+ if (this.disposed || generation !== this.generation) return;
849
+ this.publish({ state: "ready", start: index, clips, preservePosition: true, refreshFailed: false, revision: this.snapshot.revision + 1 });
850
+ } catch {
851
+ if (generation === this.generation) this.publish({ refreshFailed: true });
852
+ } finally {
853
+ if (generation === this.generation) this.advancing = false;
854
+ }
855
+ }
856
+ async readWindow(start) {
857
+ const generation = this.generation;
858
+ const end = Math.min(this.snapshot.total, start + VIDEO_WINDOW_SIZE);
859
+ for (let index = start; index < end; ) {
860
+ if (this.cache.has(index)) {
861
+ index++;
862
+ continue;
863
+ }
864
+ let count = 1;
865
+ while (index + count < end && !this.cache.has(index + count)) count++;
866
+ const values = await this.reader.readSlice(index, count);
867
+ if (this.disposed || generation !== this.generation) return [];
868
+ if (values.length !== count || values.some((clip, offset) => clip.index !== index + offset)) throw new VideoSessionReadError("invalid", "Incomplete video session window.");
869
+ for (const clip of values) this.cache.set(clip.index, clip);
870
+ index += count;
871
+ }
872
+ const clips = Array.from({ length: end - start }, (_, offset) => this.cache.get(start + offset));
873
+ for (let index = 1; index < clips.length; index++) {
874
+ if (clips[index].startPtsMs !== clips[index - 1].startPtsMs + BigInt(clips[index - 1].durationMs)) throw new VideoSessionReadError("invalid", "Discontinuous video session timestamps.");
875
+ }
876
+ for (const clip of clips) {
877
+ this.cache.delete(clip.index);
878
+ this.cache.set(clip.index, clip);
879
+ }
880
+ while (this.cache.size > MAX_CACHED_CLIPS) this.cache.delete(this.cache.keys().next().value);
881
+ return clips;
882
+ }
883
+ fail(error) {
884
+ if (error instanceof VideoSessionReadError && error.code === "invalid") this.cache.clear();
885
+ this.publish({ state: error instanceof VideoSessionReadError ? error.code : "error", clips: [] });
886
+ }
887
+ dispose() {
888
+ this.disposed = true;
889
+ ++this.generation;
890
+ this.cache.clear();
891
+ }
892
+ };
893
+
894
+ // src/ui/videoPlayerMessages.ts
895
+ var videoPlayerMessages = {
896
+ en: {
897
+ loading: "Loading video\u2026",
898
+ buffering: "Buffering\u2026",
899
+ previous: "Previous clip",
900
+ next: "Next clip",
901
+ first: "First clip",
902
+ latest: "Latest clip",
903
+ previousPage: "Previous page of clips",
904
+ nextPage: "Next page of clips",
905
+ clip: "Clip {index}",
906
+ position: "Clip {index} / {total}",
907
+ page: "{first}\u2013{last} / {total}",
908
+ time: "Time within the current clip",
909
+ retry: "Retry",
910
+ refreshFailed: "Could not refresh the session. Playback is still available; try again.",
911
+ jump: "Go to clip",
912
+ go: "Go"
913
+ },
914
+ zh: {
915
+ loading: "\u6B63\u5728\u8F7D\u5165\u89C6\u9891\u2026",
916
+ buffering: "\u6B63\u5728\u7F13\u51B2\u2026",
917
+ previous: "\u4E0A\u4E00\u6BB5",
918
+ next: "\u4E0B\u4E00\u6BB5",
919
+ first: "\u7B2C\u4E00\u6BB5",
920
+ latest: "\u6700\u65B0\u4E00\u6BB5",
921
+ previousPage: "\u4E0A\u4E00\u9875\u7247\u6BB5",
922
+ nextPage: "\u4E0B\u4E00\u9875\u7247\u6BB5",
923
+ clip: "\u7B2C {index} \u6BB5",
924
+ position: "\u7B2C {index} / {total} \u6BB5",
925
+ page: "{first}\u2013{last} / {total}",
926
+ time: "\u5F53\u524D\u7247\u6BB5\u7684\u64AD\u653E\u8FDB\u5EA6",
927
+ retry: "\u91CD\u8BD5",
928
+ refreshFailed: "\u6682\u65F6\u65E0\u6CD5\u66F4\u65B0\u89C6\u9891\u5E8F\u5217\uFF0C\u4ECD\u53EF\u7EE7\u7EED\u64AD\u653E\uFF0C\u8BF7\u7A0D\u540E\u91CD\u8BD5\u3002",
929
+ jump: "\u8DF3\u8F6C\u5230\u7247\u6BB5",
930
+ go: "\u8DF3\u8F6C"
931
+ },
932
+ ko: {
933
+ loading: "\uB3D9\uC601\uC0C1 \uBD88\uB7EC\uC624\uB294 \uC911\u2026",
934
+ buffering: "\uBC84\uD37C\uB9C1 \uC911\u2026",
935
+ previous: "\uC774\uC804 \uD074\uB9BD",
936
+ next: "\uB2E4\uC74C \uD074\uB9BD",
937
+ first: "\uCCAB \uD074\uB9BD",
938
+ latest: "\uCD5C\uC2E0 \uD074\uB9BD",
939
+ previousPage: "\uC774\uC804 \uD074\uB9BD \uD398\uC774\uC9C0",
940
+ nextPage: "\uB2E4\uC74C \uD074\uB9BD \uD398\uC774\uC9C0",
941
+ clip: "\uD074\uB9BD {index}",
942
+ position: "\uD074\uB9BD {index} / {total}",
943
+ page: "{first}\u2013{last} / {total}",
944
+ time: "\uD604\uC7AC \uD074\uB9BD \uC7AC\uC0DD \uC704\uCE58",
945
+ retry: "\uB2E4\uC2DC \uC2DC\uB3C4",
946
+ refreshFailed: "\uC138\uC158\uC744 \uC5C5\uB370\uC774\uD2B8\uD558\uC9C0 \uBABB\uD588\uC2B5\uB2C8\uB2E4. \uC7AC\uC0DD\uC740 \uACC4\uC18D\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4. \uB2E4\uC2DC \uC2DC\uB3C4\uD558\uC138\uC694.",
947
+ jump: "\uD074\uB9BD\uC73C\uB85C \uC774\uB3D9",
948
+ go: "\uC774\uB3D9"
949
+ }
950
+ };
951
+
952
+ // src/ui/ConsumerVideoSessionPlayer.tsx
953
+ var initialSnapshot = { state: "loading", total: 0, start: 0, clips: [], revision: 0, resumeAt: 0, play: false, refreshFailed: false, preservePosition: false };
954
+ var clock = (seconds) => `${Math.floor(seconds / 60)}:${Math.floor(seconds % 60).toString().padStart(2, "0")}`;
955
+ function ConsumerVideoSessionPlayer({ consumer, startClip = 0, label, fallback = null, className, autoPlay = false, muted = false }) {
956
+ const sdk = useFlapSdk();
957
+ const { chainId } = sdk.context;
958
+ const readContract = sdk.readContract;
959
+ const reader = React5.useMemo(() => createConsumerVideoSessionReader({ context: { chainId }, readContract }, consumer), [chainId, readContract, consumer]);
960
+ const sessionRef = React5.useRef(null);
961
+ const controllerRef = React5.useRef(null);
962
+ const videoRef = React5.useRef(null);
963
+ const previousWindow = React5.useRef([]);
964
+ const playIntent = React5.useRef(autoPlay);
965
+ const autoPlayRef = React5.useRef(autoPlay);
966
+ autoPlayRef.current = autoPlay;
967
+ const [snapshot, setSnapshot] = React5.useState(initialSnapshot);
968
+ const [mediaState, setMediaState] = React5.useState("loading");
969
+ const [time, setTime] = React5.useState(0);
970
+ const [buffering, setBuffering] = React5.useState(false);
971
+ const [page, setPage] = React5.useState(0);
972
+ const [jump, setJump] = React5.useState("");
973
+ const position = videoClipPosition(snapshot.clips, time);
974
+ const activeIndex = position?.index ?? snapshot.start;
975
+ const strings = videoPlayerMessages[sdk.i18n.locale.split("-")[0]] ?? videoPlayerMessages.en;
976
+ const text = (key, params) => sdk.i18n.t(`runtime.video.${key}`, strings[key], params);
977
+ React5.useEffect(() => {
978
+ const session = new ConsumerVideoSession(reader, setSnapshot);
979
+ sessionRef.current = session;
980
+ setSnapshot(initialSnapshot);
981
+ setTime(0);
982
+ playIntent.current = autoPlayRef.current;
983
+ void session.refresh(startClip, autoPlayRef.current);
984
+ const timer = window.setInterval(() => {
985
+ void session.refresh();
986
+ }, VIDEO_SESSION_POLL_MS);
987
+ return () => {
988
+ window.clearInterval(timer);
989
+ session.dispose();
990
+ sessionRef.current = null;
991
+ };
992
+ }, [reader, startClip]);
993
+ React5.useEffect(() => {
994
+ if (!videoRef.current) return;
995
+ const controller = new VideoSessionController(videoRef.current, async () => (await import('./mpegts-536UQHCG.js')).default, setMediaState);
996
+ controllerRef.current = controller;
997
+ return () => {
998
+ controller.dispose();
999
+ controllerRef.current = null;
1000
+ };
1001
+ }, []);
1002
+ React5.useEffect(() => {
1003
+ const video = videoRef.current;
1004
+ const previous = previousWindow.current;
1005
+ let resumeAt = snapshot.resumeAt;
1006
+ let play = snapshot.play;
1007
+ if (snapshot.preservePosition && previous.length && snapshot.clips.length && video) {
1008
+ resumeAt = Math.max(0, video.currentTime - Number(snapshot.clips[0].startPtsMs - previous[0].startPtsMs) / 1e3);
1009
+ play = !video.paused || video.ended && playIntent.current;
1010
+ }
1011
+ previousWindow.current = snapshot.clips;
1012
+ setTime(resumeAt);
1013
+ void controllerRef.current?.update(snapshot.clips, play, { revision: snapshot.revision, resumeAt });
1014
+ }, [snapshot.clips, snapshot.revision, snapshot.resumeAt, snapshot.play, snapshot.preservePosition]);
1015
+ React5.useEffect(() => {
1016
+ setPage(Math.floor(activeIndex / VIDEO_PICKER_PAGE_SIZE));
1017
+ }, [activeIndex]);
1018
+ const advance = () => {
1019
+ const video = videoRef.current;
1020
+ const current = videoClipPosition(snapshot.clips, video?.currentTime ?? 0);
1021
+ if (video && current && (current.index >= snapshot.start + snapshot.clips.length - 2 || video.ended)) {
1022
+ void sessionRef.current?.advance(current.index);
1023
+ }
1024
+ };
1025
+ React5.useEffect(() => {
1026
+ const video = videoRef.current;
1027
+ const current = videoClipPosition(snapshot.clips, video?.currentTime ?? 0);
1028
+ if (video && current && (current.index >= snapshot.start + snapshot.clips.length - 2 || video.ended)) void sessionRef.current?.advance(current.index);
1029
+ }, [snapshot.total, snapshot.start, snapshot.clips]);
1030
+ function seek(index) {
1031
+ const video = videoRef.current;
1032
+ const play = video ? !video.paused || video.ended && playIntent.current : playIntent.current;
1033
+ void sessionRef.current?.seek(index, 0, play);
1034
+ }
1035
+ const state = snapshot.state === "ready" ? mediaState : snapshot.state;
1036
+ const showVideo = state === "loading" || state === "ready";
1037
+ const first = page * VIDEO_PICKER_PAGE_SIZE;
1038
+ const count = Math.max(0, Math.min(VIDEO_PICKER_PAGE_SIZE, snapshot.total - first));
1039
+ return /* @__PURE__ */ React5.createElement(
1040
+ "div",
1041
+ {
1042
+ className: cn("w-full min-w-0 space-y-3", className),
1043
+ "data-flap-video-session-state": state,
1044
+ "data-flap-video-consumer": consumer,
1045
+ "data-flap-video-window-start": snapshot.start,
1046
+ "data-flap-video-window-size": snapshot.clips.length,
1047
+ onKeyDown: (event) => {
1048
+ if (event.ctrlKey || event.altKey || event.metaKey || /^(INPUT|TEXTAREA|SELECT|BUTTON)$/.test(event.target.tagName)) return;
1049
+ const video = videoRef.current;
1050
+ if (!video) return;
1051
+ if (event.key === " ") {
1052
+ event.preventDefault();
1053
+ if (video.paused) void video.play().catch(() => void 0);
1054
+ else video.pause();
1055
+ }
1056
+ if (event.key.toLowerCase() === "m") {
1057
+ event.preventDefault();
1058
+ video.muted = !video.muted;
1059
+ }
1060
+ if (event.key.toLowerCase() === "n") {
1061
+ event.preventDefault();
1062
+ seek(activeIndex + 1);
1063
+ }
1064
+ if (event.key.toLowerCase() === "p") {
1065
+ event.preventDefault();
1066
+ seek(Math.max(0, activeIndex - 1));
1067
+ }
1068
+ }
1069
+ },
1070
+ /* @__PURE__ */ React5.createElement("div", { className: "relative overflow-hidden rounded-lg border border-[#303236] bg-black" }, /* @__PURE__ */ React5.createElement(
1071
+ "video",
1072
+ {
1073
+ ref: videoRef,
1074
+ "aria-label": label,
1075
+ controls: true,
1076
+ playsInline: true,
1077
+ disablePictureInPicture: true,
1078
+ disableRemotePlayback: true,
1079
+ preload: "metadata",
1080
+ muted,
1081
+ className: showVideo ? "block aspect-video w-full object-contain" : "hidden",
1082
+ onTimeUpdate: () => {
1083
+ setTime(videoRef.current?.currentTime ?? 0);
1084
+ advance();
1085
+ },
1086
+ onPlay: () => {
1087
+ playIntent.current = true;
1088
+ },
1089
+ onPause: () => {
1090
+ if (!videoRef.current?.ended && mediaState === "ready") playIntent.current = false;
1091
+ },
1092
+ onEnded: () => advance(),
1093
+ onWaiting: () => setBuffering(true),
1094
+ onStalled: () => setBuffering(true),
1095
+ onCanPlay: () => setBuffering(false),
1096
+ onPlaying: () => setBuffering(false)
1097
+ }
1098
+ ), (state === "loading" || buffering && showVideo) && /* @__PURE__ */ React5.createElement("p", { className: "pointer-events-none absolute inset-x-0 top-3 text-center text-sm text-white", role: "status" }, text(state === "loading" ? "loading" : "buffering")), !showVideo && /* @__PURE__ */ React5.createElement("div", { className: "p-4" }, fallback)),
1099
+ snapshot.total > 0 && /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("div", { className: "flex flex-wrap items-center justify-between gap-2 text-xs text-[#D4D4D4]" }, /* @__PURE__ */ React5.createElement("span", { role: "status" }, text("position", { index: activeIndex + 1, total: snapshot.total })), /* @__PURE__ */ React5.createElement("span", null, clock(position?.time ?? 0), " / ", clock(position?.duration ?? 0))), /* @__PURE__ */ React5.createElement(
1100
+ "input",
1101
+ {
1102
+ type: "range",
1103
+ "aria-label": text("time"),
1104
+ min: 0,
1105
+ max: position?.duration ?? 0,
1106
+ step: 0.05,
1107
+ value: position?.time ?? 0,
1108
+ disabled: !position || state !== "ready",
1109
+ className: "block min-h-6 w-full accent-[#D0FF00]",
1110
+ onChange: (event) => {
1111
+ const video = videoRef.current;
1112
+ const clip = snapshot.clips.find((item) => item.index === activeIndex);
1113
+ if (video && clip) {
1114
+ video.currentTime = Number(clip.startPtsMs - snapshot.clips[0].startPtsMs) / 1e3 + Number(event.target.value);
1115
+ setTime(video.currentTime);
1116
+ }
1117
+ }
1118
+ }
1119
+ ), /* @__PURE__ */ React5.createElement("div", { className: "flex flex-wrap gap-2" }, /* @__PURE__ */ React5.createElement(Button, { type: "button", variant: "outline", disabled: activeIndex === 0, onClick: () => seek(0), "aria-label": text("first") }, /* @__PURE__ */ React5.createElement(SkipBack, { "aria-hidden": "true", className: "h-4 w-4" }), text("first")), /* @__PURE__ */ React5.createElement(Button, { type: "button", variant: "outline", disabled: activeIndex === 0, onClick: () => seek(activeIndex - 1), "aria-label": text("previous") }, /* @__PURE__ */ React5.createElement(ChevronLeft, { "aria-hidden": "true", className: "h-4 w-4" }), text("previous")), /* @__PURE__ */ React5.createElement(Button, { type: "button", variant: "outline", disabled: activeIndex >= snapshot.total - 1, onClick: () => seek(activeIndex + 1), "aria-label": text("next") }, text("next"), /* @__PURE__ */ React5.createElement(ChevronRight, { "aria-hidden": "true", className: "h-4 w-4" })), /* @__PURE__ */ React5.createElement(Button, { type: "button", variant: "outline", disabled: activeIndex >= snapshot.total - 1, onClick: () => seek(-1), "aria-label": text("latest") }, text("latest"), /* @__PURE__ */ React5.createElement(SkipForward, { "aria-hidden": "true", className: "h-4 w-4" }))), /* @__PURE__ */ React5.createElement("div", { className: "flex flex-wrap gap-1.5", role: "group", "aria-label": label }, Array.from({ length: count }, (_, offset) => first + offset).map((index) => /* @__PURE__ */ React5.createElement(
1120
+ "button",
1121
+ {
1122
+ key: index,
1123
+ type: "button",
1124
+ "aria-label": text("clip", { index: index + 1 }),
1125
+ "aria-pressed": index === activeIndex,
1126
+ className: cn("min-h-11 min-w-11 rounded-md border px-2 text-sm", index === activeIndex ? "border-[#D0FF00] bg-[#D0FF00] text-black" : "border-[#303236] bg-[#171717] text-white hover:border-[#D0FF00]", "focus-visible:outline focus-visible:outline-2 focus-visible:outline-[#D0FF00]"),
1127
+ onClick: () => seek(index)
1128
+ },
1129
+ index + 1
1130
+ ))), /* @__PURE__ */ React5.createElement("form", { className: "flex flex-wrap items-end gap-2", onSubmit: (event) => {
1131
+ event.preventDefault();
1132
+ if (Number.isSafeInteger(Number(jump)) && Number(jump) >= 1 && Number(jump) <= snapshot.total) seek(Number(jump) - 1);
1133
+ } }, /* @__PURE__ */ React5.createElement("label", { className: "min-w-0 flex-1 space-y-1 text-xs text-[#84888C]" }, /* @__PURE__ */ React5.createElement("span", null, text("jump")), /* @__PURE__ */ React5.createElement(Input, { type: "number", min: 1, max: snapshot.total, step: 1, value: jump, onChange: (event) => setJump(event.target.value) })), /* @__PURE__ */ React5.createElement(Button, { type: "submit", variant: "outline", disabled: !Number.isSafeInteger(Number(jump)) || Number(jump) < 1 || Number(jump) > snapshot.total }, text("go"))), snapshot.total > VIDEO_PICKER_PAGE_SIZE && /* @__PURE__ */ React5.createElement("div", { className: "flex items-center justify-between gap-2" }, /* @__PURE__ */ React5.createElement(Button, { type: "button", variant: "ghost", disabled: page === 0, onClick: () => setPage((value) => value - 1), "aria-label": text("previousPage") }, /* @__PURE__ */ React5.createElement(ChevronLeft, { "aria-hidden": "true", className: "h-4 w-4" })), /* @__PURE__ */ React5.createElement("span", { className: "text-xs text-[#84888C]" }, text("page", { first: first + 1, last: first + count, total: snapshot.total })), /* @__PURE__ */ React5.createElement(Button, { type: "button", variant: "ghost", disabled: first + count >= snapshot.total, onClick: () => setPage((value) => value + 1), "aria-label": text("nextPage") }, /* @__PURE__ */ React5.createElement(ChevronRight, { "aria-hidden": "true", className: "h-4 w-4" })))),
1134
+ snapshot.refreshFailed && /* @__PURE__ */ React5.createElement("p", { className: "text-sm text-[#FFB35C]", role: "status" }, text("refreshFailed")),
1135
+ (snapshot.refreshFailed || state === "error" || state === "invalid") && /* @__PURE__ */ React5.createElement(Button, { type: "button", variant: "outline", onClick: () => {
1136
+ if (snapshot.total) seek(activeIndex);
1137
+ else void sessionRef.current?.refresh(startClip, playIntent.current);
1138
+ } }, text("retry"))
1139
+ );
1140
+ }
1141
+
704
1142
  // src/ui/VideoSessionPlayer.tsx
1143
+ function VideoSessionPlayer(props) {
1144
+ return "consumer" in props && props.consumer !== void 0 ? /* @__PURE__ */ React5.createElement(ConsumerVideoSessionPlayer, { ...props }) : /* @__PURE__ */ React5.createElement(VideoClipSessionPlayer, { ...props });
1145
+ }
705
1146
  async function loadMpegts() {
706
1147
  return (await import('./mpegts-536UQHCG.js')).default;
707
1148
  }
708
- function VideoSessionPlayer({ clips, label, fallback = null, className, autoPlay = false, muted = false }) {
1149
+ function VideoClipSessionPlayer({ clips, label, fallback = null, className, autoPlay = false, muted = false }) {
709
1150
  const videoRef = React5.useRef(null);
710
1151
  const controllerRef = React5.useRef(null);
711
1152
  const [state, setState] = React5.useState("loading");
@@ -738,6 +1179,6 @@ function VideoSessionPlayer({ clips, label, fallback = null, className, autoPlay
738
1179
  ), !showVideo && fallback);
739
1180
  }
740
1181
 
741
- export { AddressLink, Alert, BinanceImage, Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Countdown, DataRow, DetailTile, ExternalLink2 as ExternalLink, Input, IpfsBackground, IpfsImage, Metric, NftMetadataImage, ReviewedFrame, RuntimeContext, StatusBadge, TxButton, VaultBanner, VideoSessionPlayer, buttonVariants, useFlapI18n, useFlapNotify, useFlapSdk, useVaultContext };
742
- //# sourceMappingURL=chunk-XSEWCRU4.js.map
743
- //# sourceMappingURL=chunk-XSEWCRU4.js.map
1182
+ export { AddressLink, Alert, BinanceImage, Button, Card, CardContent, CardDescription, CardHeader, CardTitle, Countdown, DataRow, DetailTile, ExternalLink2 as ExternalLink, Input, IpfsBackground, IpfsImage, Metric, NftMetadataImage, ReviewedFrame, RuntimeContext, StatusBadge, TxButton, VaultBanner, VideoSessionPlayer, VideoSessionReadError, buttonVariants, createConsumerVideoSessionReader, readVideoSessionLength, readVideoSessionSlice, useFlapI18n, useFlapNotify, useFlapSdk, useVaultContext };
1183
+ //# sourceMappingURL=chunk-F6QSV3Y7.js.map
1184
+ //# sourceMappingURL=chunk-F6QSV3Y7.js.map