@flapsdk/vault-runtime 0.1.31 → 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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/{chunk-VUIWNFCV.js → chunk-B4WKI3EW.js} +38 -127
  3. package/chunk-B4WKI3EW.js.map +1 -0
  4. package/chunk-BUSYA2B4.js +8 -0
  5. package/chunk-BUSYA2B4.js.map +1 -0
  6. package/chunk-F6QSV3Y7.js +1184 -0
  7. package/chunk-F6QSV3Y7.js.map +1 -0
  8. package/{chunk-CPAMDXX7.js → chunk-FUOBTZMQ.js} +4 -2
  9. package/chunk-FUOBTZMQ.js.map +1 -0
  10. package/{chunk-QCBH6G4Q.js → chunk-PU7VEZWA.js} +67 -3
  11. package/chunk-PU7VEZWA.js.map +1 -0
  12. package/chunk-SAG36LUR.js +35 -0
  13. package/chunk-SAG36LUR.js.map +1 -0
  14. package/{chunk-WX6B7JWO.js → chunk-SDCB3RJS.js} +3 -3
  15. package/{chunk-WX6B7JWO.js.map → chunk-SDCB3RJS.js.map} +1 -1
  16. package/chunk-T6XKFZLH.js +129 -0
  17. package/chunk-T6XKFZLH.js.map +1 -0
  18. package/host.d.mts +4 -4
  19. package/host.js +8 -6
  20. package/host.js.map +1 -1
  21. package/{hostRuntimeConfig-C1sOrw9C.d.mts → hostRuntimeConfig-BC459T5W.d.mts} +3 -1
  22. package/mpegts-536UQHCG.js +5164 -0
  23. package/mpegts-536UQHCG.js.map +1 -0
  24. package/package.json +4 -3
  25. package/runtime-contract.json +1 -1
  26. package/sdk.d.mts +49 -5
  27. package/sdk.js +24 -10
  28. package/sdk.js.map +1 -1
  29. package/server.d.mts +15 -4
  30. package/server.js +162 -5
  31. package/server.js.map +1 -1
  32. package/{txError-CBveO4Df.d.mts → txError-CJnmiLnM.d.mts} +1 -1
  33. package/{types-I7JxlbLk.d.mts → types-BfzRFcjZ.d.mts} +21 -1
  34. package/ui.d.mts +37 -1
  35. package/ui.js +5 -3
  36. package/chunk-4S6TVBHU.js +0 -600
  37. package/chunk-4S6TVBHU.js.map +0 -1
  38. package/chunk-CPAMDXX7.js.map +0 -1
  39. package/chunk-GA5VEHC2.js +0 -40
  40. package/chunk-GA5VEHC2.js.map +0 -1
  41. package/chunk-QCBH6G4Q.js.map +0 -1
  42. package/chunk-VUIWNFCV.js.map +0 -1
@@ -0,0 +1,1184 @@
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';
5
+ import { clsx } from 'clsx';
6
+ import { twMerge } from 'tailwind-merge';
7
+ import * as React5 from 'react';
8
+ import { createContext, useState, useEffect, useMemo, useContext } from 'react';
9
+ import { Slot } from '@radix-ui/react-slot';
10
+ import { cva } from 'class-variance-authority';
11
+ import { createPortal } from 'react-dom';
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
+ }
68
+ function AddressLink({ address, explorerBaseUrl, label }) {
69
+ if (!address) return /* @__PURE__ */ React.createElement("span", null, "-");
70
+ const href = explorerBaseUrl ? `${explorerBaseUrl.replace(/\/$/, "")}/address/${address}` : void 0;
71
+ const content = /* @__PURE__ */ React.createElement("span", { className: "inline-flex min-w-0 items-center gap-1 text-primary" }, /* @__PURE__ */ React.createElement("span", { className: "truncate" }, label || shortenAddress(address)), href ? /* @__PURE__ */ React.createElement(ExternalLink, { className: "h-3.5 w-3.5 shrink-0" }) : null);
72
+ return href ? /* @__PURE__ */ React.createElement("a", { href, target: "_blank", rel: "noreferrer" }, content) : content;
73
+ }
74
+ function cn(...inputs) {
75
+ return twMerge(clsx(inputs));
76
+ }
77
+
78
+ // src/ui/Alert.tsx
79
+ var toneClass = {
80
+ info: "border-[#303236] bg-black text-[#D4D4D4]",
81
+ success: "border-[#D0FF00]/45 bg-[#101400] text-[#D0FF00]",
82
+ warning: "border-[#FFD166]/45 bg-[#1A1305] text-[#FFD166]",
83
+ danger: "border-[#FF4A55]/55 bg-[#1D0709] text-[#FF8A91]"
84
+ };
85
+ var iconMap = {
86
+ info: Info,
87
+ success: CheckCircle2,
88
+ warning: AlertTriangle,
89
+ danger: AlertTriangle
90
+ };
91
+ function Alert({ children, tone = "info", className }) {
92
+ const Icon = iconMap[tone];
93
+ return /* @__PURE__ */ React.createElement("div", { "data-flap-ui": "alert", className: cn("flex gap-3 rounded-[6px] border p-3 text-sm font-medium leading-6", toneClass[tone], className) }, /* @__PURE__ */ React.createElement(Icon, { className: "mt-0.5 h-4 w-4 shrink-0 opacity-90" }), /* @__PURE__ */ React.createElement("div", { className: "min-w-0 break-words" }, children));
94
+ }
95
+ var buttonVariants = cva(
96
+ "inline-flex items-center justify-center gap-2 whitespace-nowrap text-sm font-semibold uppercase leading-[1.4] tracking-normal duration-0 hover:transition-colors hover:duration-150 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#D0FF00]/45 disabled:pointer-events-none disabled:opacity-50",
97
+ {
98
+ variants: {
99
+ variant: {
100
+ default: "ui20-connect-chamfer text-[#070808] [--ui20-chamfer-bg:#D0FF00] [--ui20-chamfer-border:#D0FF00] hover:[--ui20-chamfer-bg:#BDE800] hover:[--ui20-chamfer-border:#BDE800]",
101
+ secondary: "ui20-connect-chamfer text-white [--ui20-chamfer-bg:#262626] [--ui20-chamfer-border:#262626] hover:text-[#D0FF00] hover:[--ui20-chamfer-bg:#303030] hover:[--ui20-chamfer-border:#303030]",
102
+ outline: "ui20-connect-chamfer text-[#D4D4D4] [--ui20-chamfer-bg:#000000] [--ui20-chamfer-border:#303236] hover:text-[#D0FF00] hover:[--ui20-chamfer-border:#D0FF00]",
103
+ ghost: "rounded-[6px] text-[#D4D4D4] hover:bg-[#131516] hover:text-[#D0FF00]",
104
+ destructive: "ui20-connect-chamfer text-[#FF4A55] [--ui20-chamfer-bg:#000000] [--ui20-chamfer-border:#FF4A55] hover:text-black hover:[--ui20-chamfer-bg:#FF4A55]"
105
+ },
106
+ size: {
107
+ default: "h-10 px-4",
108
+ sm: "h-8 px-3 text-xs",
109
+ lg: "h-12 px-5",
110
+ icon: "h-10 w-10 px-0"
111
+ }
112
+ },
113
+ defaultVariants: {
114
+ variant: "default",
115
+ size: "default"
116
+ }
117
+ }
118
+ );
119
+ var Button = React5.forwardRef(
120
+ ({ className, variant, size, asChild = false, loading = false, disabled, children, ...props }, ref) => {
121
+ const Comp = asChild ? Slot : "button";
122
+ if (asChild) {
123
+ return /* @__PURE__ */ React5.createElement(Comp, { "data-flap-ui": "button", className: cn(buttonVariants({ variant, size, className })), ref, ...props }, children);
124
+ }
125
+ return /* @__PURE__ */ React5.createElement(
126
+ Comp,
127
+ {
128
+ "data-flap-ui": "button",
129
+ className: cn(buttonVariants({ variant, size, className })),
130
+ ref,
131
+ disabled: disabled || loading,
132
+ ...props
133
+ },
134
+ loading ? /* @__PURE__ */ React5.createElement(Loader2, { className: "relative z-10 h-4 w-4 animate-spin" }) : null,
135
+ /* @__PURE__ */ React5.createElement("span", { className: "relative z-10 inline-flex min-w-0 items-center justify-center gap-2" }, children)
136
+ );
137
+ }
138
+ );
139
+ Button.displayName = "Button";
140
+
141
+ // src/ui/binanceImageUrl.ts
142
+ var BINANCE_IMAGE_HOSTNAME = "bin.bnbstatic.com";
143
+ var MAX_BINANCE_IMAGE_URL_LENGTH = 4096;
144
+ var CONTROL_CHARACTER_RE = /[\u0000-\u001F\u007F]/u;
145
+ function normalizeBinanceImageUrl(value) {
146
+ if (typeof value !== "string" || !value || value.length > MAX_BINANCE_IMAGE_URL_LENGTH) return null;
147
+ if (value !== value.trim() || CONTROL_CHARACTER_RE.test(value)) return null;
148
+ try {
149
+ const parsed = new URL(value);
150
+ if (parsed.protocol !== "https:") return null;
151
+ if (parsed.hostname.toLowerCase() !== BINANCE_IMAGE_HOSTNAME) return null;
152
+ if (parsed.username || parsed.password || parsed.port) return null;
153
+ return parsed.href;
154
+ } catch {
155
+ return null;
156
+ }
157
+ }
158
+
159
+ // src/ui/BinanceImage.tsx
160
+ function BinanceImage({ alt, src, fallback = null, className, onError, ...props }) {
161
+ const safeSrc = React5.useMemo(() => normalizeBinanceImageUrl(src), [src]);
162
+ const [failedSrc, setFailedSrc] = React5.useState(null);
163
+ const {
164
+ alt: _unsafeAlt,
165
+ decoding: _unsafeDecoding,
166
+ loading: _unsafeLoading,
167
+ referrerPolicy: _unsafeReferrerPolicy,
168
+ src: _unsafeSrc,
169
+ srcSet: _unsafeSrcSet,
170
+ ...imageProps
171
+ } = props;
172
+ if (!safeSrc || failedSrc === safeSrc) {
173
+ return /* @__PURE__ */ React5.createElement("span", { className: cn("block", className), "data-flap-binance-image-state": safeSrc ? "error" : "invalid" }, fallback);
174
+ }
175
+ return (
176
+ // eslint-disable-next-line @next/next/no-img-element -- BinanceImage owns the exact-host runtime boundary and browser loading policy.
177
+ /* @__PURE__ */ React5.createElement(
178
+ "img",
179
+ {
180
+ ...imageProps,
181
+ alt,
182
+ className: cn("block max-w-full", className),
183
+ "data-flap-binance-image-state": "ready",
184
+ decoding: "async",
185
+ loading: "lazy",
186
+ onError: (event) => {
187
+ setFailedSrc(safeSrc);
188
+ onError?.(event);
189
+ },
190
+ referrerPolicy: "no-referrer",
191
+ src: safeSrc
192
+ }
193
+ )
194
+ );
195
+ }
196
+ var Card = React5.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React5.createElement(
197
+ "div",
198
+ {
199
+ "data-flap-ui": "card",
200
+ ref,
201
+ className: cn(
202
+ "rounded-[8px] border border-[#303236] bg-[#070808] text-white shadow-[0_18px_60px_-42px_rgba(208,255,0,0.45)]",
203
+ className
204
+ ),
205
+ ...props
206
+ }
207
+ ));
208
+ Card.displayName = "Card";
209
+ var CardHeader = React5.forwardRef(
210
+ ({ className, ...props }, ref) => /* @__PURE__ */ React5.createElement("div", { "data-flap-ui": "card-header", ref, className: cn("flex flex-col gap-1.5 p-4 sm:p-5", className), ...props })
211
+ );
212
+ CardHeader.displayName = "CardHeader";
213
+ var CardTitle = React5.forwardRef(
214
+ ({ className, ...props }, ref) => /* @__PURE__ */ React5.createElement("h3", { "data-flap-ui": "card-title", ref, className: cn("text-base font-semibold uppercase leading-tight tracking-normal text-white sm:text-lg", className), ...props })
215
+ );
216
+ CardTitle.displayName = "CardTitle";
217
+ var CardDescription = React5.forwardRef(
218
+ ({ className, ...props }, ref) => /* @__PURE__ */ React5.createElement("p", { "data-flap-ui": "card-description", ref, className: cn("text-sm leading-6 text-[#84888C]", className), ...props })
219
+ );
220
+ CardDescription.displayName = "CardDescription";
221
+ var CardContent = React5.forwardRef(
222
+ ({ className, ...props }, ref) => /* @__PURE__ */ React5.createElement("div", { "data-flap-ui": "card-content", ref, className: cn("p-4 pt-0 sm:p-5 sm:pt-0", className), ...props })
223
+ );
224
+ CardContent.displayName = "CardContent";
225
+ function formatMs(ms) {
226
+ const safe = Math.max(0, ms);
227
+ const totalSeconds = Math.floor(safe / 1e3);
228
+ const days = Math.floor(totalSeconds / 86400);
229
+ const hours = Math.floor(totalSeconds % 86400 / 3600);
230
+ const minutes = Math.floor(totalSeconds % 3600 / 60);
231
+ const seconds = totalSeconds % 60;
232
+ if (days > 0) return `${days}d ${hours}h ${minutes}m`;
233
+ if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`;
234
+ return `${minutes}m ${seconds}s`;
235
+ }
236
+ function Countdown({ targetTimeMs, fallback = "-" }) {
237
+ const [now, setNow] = useState(() => Date.now());
238
+ useEffect(() => {
239
+ const timer = window.setInterval(() => setNow(Date.now()), 1e3);
240
+ return () => window.clearInterval(timer);
241
+ }, []);
242
+ const text = useMemo(() => {
243
+ if (!targetTimeMs) return fallback;
244
+ return formatMs(targetTimeMs - now);
245
+ }, [fallback, now, targetTimeMs]);
246
+ return /* @__PURE__ */ React.createElement("span", null, text);
247
+ }
248
+
249
+ // src/ui/DataRow.tsx
250
+ function DataRow({ label, value, detail, className }) {
251
+ return /* @__PURE__ */ React.createElement("div", { className: cn("flex items-start justify-between gap-4 border-b border-white/8 py-3 last:border-0", className) }, /* @__PURE__ */ React.createElement("div", { className: "min-w-0 text-sm text-white/54" }, label), /* @__PURE__ */ React.createElement("div", { className: "min-w-0 text-right" }, /* @__PURE__ */ React.createElement("div", { className: "break-words text-sm font-semibold text-white" }, value), detail ? /* @__PURE__ */ React.createElement("div", { className: "mt-1 text-xs text-white/42" }, detail) : null));
252
+ }
253
+
254
+ // src/ui/DetailTile.tsx
255
+ var toneClass2 = {
256
+ default: "border-[#303236] bg-[#0B0D0E]",
257
+ primary: "border-[#D0FF00]/70 bg-[#101400]",
258
+ success: "border-[#2EDEDB]/45 bg-[#061615]",
259
+ warning: "border-[#FFD166]/45 bg-[#1A1305]",
260
+ muted: "border-[#303236] bg-black"
261
+ };
262
+ function DetailTile({ label, value, detail, icon, tone = "default", className, valueClassName }) {
263
+ return /* @__PURE__ */ React.createElement("div", { "data-flap-ui": "detail-tile", className: cn("min-w-0 rounded-[6px] border p-3", toneClass2[tone], className) }, /* @__PURE__ */ React.createElement("div", { className: "flex min-w-0 items-center gap-2 text-xs font-medium uppercase leading-[1.4] text-[#84888C]" }, icon ? /* @__PURE__ */ React.createElement("span", { className: "shrink-0 text-[#D0FF00]" }, icon) : null, /* @__PURE__ */ React.createElement("span", { className: "min-w-0 truncate" }, label)), /* @__PURE__ */ React.createElement("div", { className: cn("mt-2 min-w-0 break-words text-base font-semibold leading-snug text-white", valueClassName) }, value), detail ? /* @__PURE__ */ React.createElement("div", { className: "mt-1 min-w-0 break-words text-xs leading-5 text-[#84888C]" }, detail) : null);
264
+ }
265
+ var COPY = {
266
+ en: {
267
+ title: "THIRD-PARTY WARNING",
268
+ heading: "YOU ARE LEAVING FLAP",
269
+ description: "You are about to visit a third-party page maintained by an external developer. This site is not operated by FLAP and may contain unknown security or privacy risks.",
270
+ destinationLabel: "Destination",
271
+ invalidDestination: "Unsupported destination",
272
+ acknowledge: "I understand the risks and want to proceed",
273
+ cancel: "CLOSE",
274
+ proceed: "CONTINUE"
275
+ },
276
+ zh: {
277
+ title: "\u7B2C\u4E09\u65B9\u98CE\u9669\u63D0\u793A",
278
+ heading: "\u60A8\u5373\u5C06\u79BB\u5F00 FLAP",
279
+ description: "\u60A8\u5373\u5C06\u8BBF\u95EE\u7531\u5916\u90E8\u5F00\u53D1\u8005\u7EF4\u62A4\u7684\u7B2C\u4E09\u65B9\u9875\u9762\u3002\u8BE5\u7AD9\u70B9\u4E0D\u7531 FLAP \u8FD0\u8425\uFF0C\u53EF\u80FD\u5B58\u5728\u672A\u77E5\u7684\u5B89\u5168\u6216\u9690\u79C1\u98CE\u9669\u3002",
280
+ destinationLabel: "\u76EE\u6807\u5730\u5740",
281
+ invalidDestination: "\u4E0D\u652F\u6301\u7684\u76EE\u6807\u5730\u5740",
282
+ acknowledge: "\u6211\u5DF2\u4E86\u89E3\u98CE\u9669\u5E76\u5E0C\u671B\u7EE7\u7EED",
283
+ cancel: "\u5173\u95ED",
284
+ proceed: "\u7EE7\u7EED"
285
+ }
286
+ };
287
+ function resolveLocale(locale) {
288
+ return locale && locale.toLowerCase().startsWith("zh") ? "zh" : "en";
289
+ }
290
+ function normalizeExternalUrl(url) {
291
+ try {
292
+ const parsed = new URL(url);
293
+ if (parsed.protocol !== "https:" || parsed.username || parsed.password) return null;
294
+ return parsed.href;
295
+ } catch {
296
+ return null;
297
+ }
298
+ }
299
+ function WarningIcon({ className }) {
300
+ return /* @__PURE__ */ React5.createElement("svg", { viewBox: "0 0 80 80", fill: "currentColor", "aria-hidden": "true", shapeRendering: "crispEdges", className }, /* @__PURE__ */ React5.createElement("rect", { x: "32.4395", y: "11.7969", width: "2.62997", height: "6.57492" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "6.57492", transform: "matrix(-1 0 0 1 47.5605 11.7969)" }), /* @__PURE__ */ React5.createElement("rect", { x: "35.0693", y: "9.16699", width: "2.62997", height: "5.25994" }), /* @__PURE__ */ React5.createElement("rect", { x: "37.6982", y: "9.16699", width: "4.60245", height: "2.62997" }), /* @__PURE__ */ React5.createElement("rect", { x: "38.333", y: "6.66699", width: "3.33333", height: "2.5" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "5.25994", transform: "matrix(-1 0 0 1 44.9307 9.16699)" }), /* @__PURE__ */ React5.createElement("rect", { x: "29.8086", y: "16.3989", width: "2.62997", height: "6.57492" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "6.57492", transform: "matrix(-1 0 0 1 50.1914 16.3989)" }), /* @__PURE__ */ React5.createElement("rect", { x: "27.1787", y: "21.6592", width: "2.62997", height: "5.91743" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "5.91743", transform: "matrix(-1 0 0 1 52.8213 21.6592)" }), /* @__PURE__ */ React5.createElement("rect", { x: "24.5488", y: "24.2891", width: "2.62997", height: "7.23242" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "7.23242", transform: "matrix(-1 0 0 1 55.4512 24.2891)" }), /* @__PURE__ */ React5.createElement("rect", { x: "21.9189", y: "29.5488", width: "2.62997", height: "7.23242" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "7.23242", transform: "matrix(-1 0 0 1 58.0811 29.5488)" }), /* @__PURE__ */ React5.createElement("rect", { x: "19.2891", y: "34.8086", width: "2.62997", height: "7.23242" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "7.23242", transform: "matrix(-1 0 0 1 60.7109 34.8086)" }), /* @__PURE__ */ React5.createElement("rect", { x: "16.6592", y: "40.0693", width: "2.62997", height: "5.91743" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "5.91743", transform: "matrix(-1 0 0 1 63.3408 40.0693)" }), /* @__PURE__ */ React5.createElement("rect", { x: "14.0293", y: "44.6709", width: "2.62997", height: "5.91743" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "5.91743", transform: "matrix(-1 0 0 1 65.9707 44.6709)" }), /* @__PURE__ */ React5.createElement("rect", { x: "11.3984", y: "48.6165", width: "2.62997", height: "5.91743" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "5.91743", transform: "matrix(-1 0 0 1 68.6016 48.6165)" }), /* @__PURE__ */ React5.createElement("rect", { x: "8.76855", y: "53.8762", width: "2.62997", height: "5.91743" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "5.91743", transform: "matrix(-1 0 0 1 71.2314 53.8762)" }), /* @__PURE__ */ React5.createElement("rect", { x: "6.13965", y: "58.4783", width: "2.62997", height: "5.91743" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "5.91743", transform: "matrix(-1 0 0 1 73.8604 58.4783)" }), /* @__PURE__ */ React5.createElement("rect", { x: "4.16699", y: "62.4236", width: "2.62997", height: "5.91743" }), /* @__PURE__ */ React5.createElement("rect", { width: "2.62997", height: "5.91743", transform: "matrix(-1 0 0 1 75.833 62.4236)" }), /* @__PURE__ */ React5.createElement("rect", { x: "6.79688", y: "68.3406", width: "2.62997", height: "2.62997" }), /* @__PURE__ */ React5.createElement("rect", { x: "70.5742", y: "68.3406", width: "2.62997", height: "2.62997" }), /* @__PURE__ */ React5.createElement("rect", { x: "9.42578", y: "70.9709", width: "61.1468", height: "2.62997" }), /* @__PURE__ */ React5.createElement("rect", { x: "38.333", y: "30.833", width: "4.16667", height: "22.5" }), /* @__PURE__ */ React5.createElement("rect", { x: "38.333", y: "57.5", width: "4.16667", height: "4.16667" }));
301
+ }
302
+ function ExternalLink2({ url, children, locale, className, copy }) {
303
+ const [open, setOpen] = React5.useState(false);
304
+ const [acknowledged, setAcknowledged] = React5.useState(false);
305
+ const [mounted, setMounted] = React5.useState(false);
306
+ const text = { ...COPY[resolveLocale(locale)], ...copy };
307
+ const safeUrl = React5.useMemo(() => normalizeExternalUrl(url), [url]);
308
+ const canProceed = acknowledged && Boolean(safeUrl);
309
+ React5.useEffect(() => {
310
+ setMounted(true);
311
+ }, []);
312
+ const close = React5.useCallback(() => {
313
+ setOpen(false);
314
+ setAcknowledged(false);
315
+ }, []);
316
+ React5.useEffect(() => {
317
+ if (!open) return;
318
+ const onKey = (event) => {
319
+ if (event.key === "Escape") close();
320
+ };
321
+ document.addEventListener("keydown", onKey);
322
+ const previousOverflow = document.body.style.overflow;
323
+ document.body.style.overflow = "hidden";
324
+ return () => {
325
+ document.removeEventListener("keydown", onKey);
326
+ document.body.style.overflow = previousOverflow;
327
+ };
328
+ }, [open, close]);
329
+ const proceed = () => {
330
+ if (!canProceed || !safeUrl) return;
331
+ window.open(safeUrl, "_blank", "noopener,noreferrer");
332
+ close();
333
+ };
334
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
335
+ "button",
336
+ {
337
+ type: "button",
338
+ "data-flap-ui": "external-link",
339
+ onClick: () => setOpen(true),
340
+ className: cn("inline-flex min-w-0 items-center gap-1 text-[#d0ff00] hover:underline", className)
341
+ },
342
+ /* @__PURE__ */ React5.createElement("span", { className: "truncate" }, children),
343
+ /* @__PURE__ */ React5.createElement(ExternalLink, { className: "h-3.5 w-3.5 shrink-0", "aria-hidden": "true" })
344
+ ), open && mounted ? createPortal(
345
+ /* @__PURE__ */ React5.createElement(
346
+ "div",
347
+ {
348
+ className: "fixed inset-0 z-[2147483647] flex items-center justify-center bg-black/70 p-4 backdrop-blur-sm",
349
+ style: { zIndex: 2147483647 },
350
+ onClick: close
351
+ },
352
+ /* @__PURE__ */ React5.createElement(
353
+ "div",
354
+ {
355
+ role: "dialog",
356
+ "aria-modal": "true",
357
+ "aria-label": text.title,
358
+ onClick: (event) => event.stopPropagation(),
359
+ style: {
360
+ width: "min(540px, 100%)",
361
+ maxHeight: "calc(100vh - 2rem)",
362
+ fontFamily: "'JetBrains Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace",
363
+ backgroundColor: "#070808",
364
+ border: "1px solid #414141"
365
+ },
366
+ className: "flex w-[min(540px,100%)] max-h-[calc(100vh-2rem)] flex-col overflow-hidden rounded-[4px] text-white shadow-panel"
367
+ },
368
+ /* @__PURE__ */ React5.createElement(
369
+ "div",
370
+ {
371
+ className: "flex items-center justify-between border-b border-[#484b51] px-6 py-[14px]",
372
+ style: { boxSizing: "border-box", height: "49px", lineHeight: 1 }
373
+ },
374
+ /* @__PURE__ */ React5.createElement(
375
+ "span",
376
+ {
377
+ className: "truncate text-[18px] font-medium uppercase leading-none tracking-[-0.4px]",
378
+ style: { lineHeight: 1 }
379
+ },
380
+ /* @__PURE__ */ React5.createElement("span", { className: "text-[#d0ff00]" }, "//"),
381
+ text.title
382
+ ),
383
+ /* @__PURE__ */ React5.createElement(
384
+ "button",
385
+ {
386
+ type: "button",
387
+ onClick: close,
388
+ "aria-label": text.cancel,
389
+ className: "flex size-5 shrink-0 items-center justify-center border border-[#484b51] text-white/80 hover:text-white"
390
+ },
391
+ /* @__PURE__ */ React5.createElement(X, { className: "h-3.5 w-3.5" })
392
+ )
393
+ ),
394
+ /* @__PURE__ */ React5.createElement("div", { className: "flex flex-col gap-6 overflow-y-auto p-6" }, /* @__PURE__ */ React5.createElement("div", { className: "flex flex-col items-center gap-5" }, /* @__PURE__ */ React5.createElement(WarningIcon, { className: "h-20 w-20 text-[#f68f15]" }), /* @__PURE__ */ React5.createElement("h2", { className: "text-center text-[18px] font-medium uppercase leading-[1.4] tracking-[-0.4px]" }, text.heading)), /* @__PURE__ */ React5.createElement("p", { className: "text-[14px] leading-[1.4] tracking-[-0.4px] text-[#a0a3a7]" }, text.description), /* @__PURE__ */ React5.createElement("div", { className: "min-w-0 border border-[#262626] bg-[#0a0a0a] px-3 py-2 text-[13px]" }, /* @__PURE__ */ React5.createElement("div", { className: "mb-1 uppercase tracking-[-0.4px] text-[#6b7280]" }, text.destinationLabel), /* @__PURE__ */ React5.createElement("div", { className: "truncate text-[#d4d4d4]", title: safeUrl ?? url }, safeUrl ? new URL(safeUrl).host : text.invalidDestination)), /* @__PURE__ */ React5.createElement("label", { className: "flex cursor-pointer items-center gap-2 text-[14px] leading-[1.4] tracking-[-0.4px] text-white" }, /* @__PURE__ */ React5.createElement(
395
+ "input",
396
+ {
397
+ type: "checkbox",
398
+ checked: acknowledged,
399
+ onChange: (event) => setAcknowledged(event.target.checked),
400
+ className: "sr-only"
401
+ }
402
+ ), /* @__PURE__ */ React5.createElement(
403
+ "span",
404
+ {
405
+ "aria-hidden": "true",
406
+ className: cn(
407
+ "flex size-4 shrink-0 items-center justify-center border",
408
+ acknowledged ? "border-[#d0ff00] bg-[#d0ff00] text-[#070808]" : "border-[#a0a3a7] bg-transparent"
409
+ )
410
+ },
411
+ acknowledged ? /* @__PURE__ */ React5.createElement("svg", { viewBox: "0 0 12 12", className: "h-3 w-3", fill: "none", stroke: "currentColor", strokeWidth: 2 }, /* @__PURE__ */ React5.createElement("path", { d: "M2 6.5 L5 9 L10 3", strokeLinecap: "square" })) : null
412
+ ), /* @__PURE__ */ React5.createElement("span", { className: "min-w-0" }, text.acknowledge)), /* @__PURE__ */ React5.createElement("div", { className: "flex gap-6" }, /* @__PURE__ */ React5.createElement(
413
+ "button",
414
+ {
415
+ type: "button",
416
+ onClick: close,
417
+ className: "flex flex-1 items-center justify-center rounded-[2px] border border-[#84888c] bg-transparent py-3 text-[14px] font-bold uppercase tracking-[-0.4px] text-white transition-colors hover:border-white"
418
+ },
419
+ text.cancel
420
+ ), /* @__PURE__ */ React5.createElement(
421
+ "button",
422
+ {
423
+ type: "button",
424
+ onClick: proceed,
425
+ disabled: !canProceed,
426
+ style: { backgroundColor: canProceed ? "#d0ff00" : "#536600", color: "#070808" },
427
+ className: "flex flex-1 items-center justify-center rounded-[2px] py-3 text-[14px] font-bold uppercase tracking-[-0.4px] transition-colors"
428
+ },
429
+ text.proceed
430
+ )))
431
+ )
432
+ ),
433
+ document.body
434
+ ) : null);
435
+ }
436
+ var Input = React5.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ React5.createElement(
437
+ "input",
438
+ {
439
+ "data-flap-ui": "input",
440
+ ref,
441
+ className: cn(
442
+ "flex h-11 w-full rounded-[6px] border border-[#303236] bg-black px-3 py-2 text-sm font-semibold text-white caret-[#D0FF00] shadow-[inset_0_1px_0_rgba(255,255,255,0.04)] outline-none duration-0 selection:bg-[#D0FF00]/35 selection:text-white placeholder:text-[#84888C] focus:border-[#D0FF00] focus:ring-2 focus:ring-[#D0FF00]/25 disabled:cursor-not-allowed disabled:bg-[#131516] disabled:text-[#84888C] disabled:opacity-80",
443
+ className
444
+ ),
445
+ ...props
446
+ }
447
+ ));
448
+ Input.displayName = "Input";
449
+ function IpfsImage({ alt, cid, path, validationPath, className, decoding = "async", loading = "lazy", onError, ...props }) {
450
+ const urls = React5.useMemo(() => resolveIpfsImageUrls(cid, 56, path), [cid, path]);
451
+ const [urlIndex, setUrlIndex] = React5.useState(0);
452
+ const src = urls[urlIndex];
453
+ React5.useEffect(() => {
454
+ setUrlIndex(0);
455
+ }, [cid, path]);
456
+ if (!src) return null;
457
+ return (
458
+ // eslint-disable-next-line @next/next/no-img-element -- IpfsImage owns CID-to-gateway fallback; next/image cannot represent this boundary.
459
+ /* @__PURE__ */ React5.createElement(
460
+ "img",
461
+ {
462
+ ...props,
463
+ alt,
464
+ className: cn("block max-w-full", className),
465
+ decoding,
466
+ loading,
467
+ onError: (event) => {
468
+ if (urlIndex < urls.length - 1) {
469
+ setUrlIndex((index) => Math.min(index + 1, urls.length - 1));
470
+ return;
471
+ }
472
+ onError?.(event);
473
+ },
474
+ src
475
+ }
476
+ )
477
+ );
478
+ }
479
+ function IpfsBackground({ cid, className, imageClassName, overlayClassName, ...props }) {
480
+ return /* @__PURE__ */ React5.createElement("div", { ...props, "aria-hidden": "true", className: cn("pointer-events-none absolute inset-0 overflow-hidden", className) }, /* @__PURE__ */ React5.createElement(IpfsImage, { alt: "", cid, className: cn("h-full w-full object-cover", imageClassName), loading: "eager" }), overlayClassName ? /* @__PURE__ */ React5.createElement("div", { className: cn("absolute inset-0", overlayClassName) }) : null);
481
+ }
482
+ var RuntimeContext = createContext(null);
483
+ function useFlapSdk() {
484
+ const sdk = useContext(RuntimeContext);
485
+ if (!sdk) throw new Error("useFlapSdk must be used within VaultRuntimeProvider.");
486
+ return sdk;
487
+ }
488
+ function useVaultContext() {
489
+ return useFlapSdk().context;
490
+ }
491
+ function useFlapI18n() {
492
+ return useFlapSdk().i18n;
493
+ }
494
+ function useFlapNotify() {
495
+ return useFlapSdk().notify;
496
+ }
497
+ function NftMetadataImage({ alt, tokenId, fallback = null, className, decoding = "async", loading = "lazy", onError, ...props }) {
498
+ const sdk = useFlapSdk();
499
+ const [metadata, setMetadata] = React5.useState(null);
500
+ const [state, setState] = React5.useState("loading");
501
+ React5.useEffect(() => {
502
+ let cancelled = false;
503
+ setState("loading");
504
+ setMetadata(null);
505
+ sdk.readNftMetadata({ tokenId }).then((nextMetadata) => {
506
+ if (cancelled) return;
507
+ setMetadata(nextMetadata);
508
+ setState("ready");
509
+ }).catch(() => {
510
+ if (!cancelled) setState("error");
511
+ });
512
+ return () => {
513
+ cancelled = true;
514
+ };
515
+ }, [sdk, sdk.refetchNonce, tokenId]);
516
+ if (state !== "ready" || !metadata) {
517
+ return /* @__PURE__ */ React5.createElement("span", { "data-flap-nft-media-state": state, className: cn("block", className) }, fallback);
518
+ }
519
+ return (
520
+ // eslint-disable-next-line @next/next/no-img-element -- shared runtime resolves tokenURI metadata to a validated, size-limited data image.
521
+ /* @__PURE__ */ React5.createElement(
522
+ "img",
523
+ {
524
+ ...props,
525
+ alt,
526
+ className: cn("block max-w-full", className),
527
+ "data-flap-nft-media-source": metadata.source,
528
+ "data-flap-nft-media-state": state,
529
+ decoding,
530
+ loading,
531
+ onError: (event) => {
532
+ setState("error");
533
+ onError?.(event);
534
+ },
535
+ src: metadata.imageDataUrl
536
+ }
537
+ )
538
+ );
539
+ }
540
+
541
+ // src/ui/Metric.tsx
542
+ var toneClass3 = {
543
+ default: "border-[#303236] bg-[#0B0D0E]",
544
+ primary: "border-[#D0FF00]/70 bg-[#101400]",
545
+ success: "border-[#2EDEDB]/45 bg-[#061615]",
546
+ warning: "border-[#FFD166]/45 bg-[#1A1305]",
547
+ muted: "border-[#303236] bg-black"
548
+ };
549
+ var valueToneClass = {
550
+ default: "text-white",
551
+ primary: "text-[#D0FF00]",
552
+ success: "text-[#2EDEDB]",
553
+ warning: "text-[#FFD166]",
554
+ muted: "text-white"
555
+ };
556
+ function Metric({ label, value, hint, tone = "default", className }) {
557
+ return /* @__PURE__ */ React.createElement("div", { "data-flap-ui": "metric", className: cn("rounded-[6px] border p-3", toneClass3[tone], className) }, /* @__PURE__ */ React.createElement("div", { className: "truncate text-xs font-medium uppercase leading-[1.4] text-[#84888C]" }, label), /* @__PURE__ */ React.createElement("div", { className: cn("mt-2 break-words text-xl font-semibold tracking-normal", valueToneClass[tone]) }, value), hint ? /* @__PURE__ */ React.createElement("div", { className: "mt-1 truncate text-xs text-[#D4D4D4]" }, hint) : null);
558
+ }
559
+ function ReviewedFrame({ className, frameId, provider, src, title, ...props }) {
560
+ const {
561
+ allow: _allow,
562
+ referrerPolicy: _referrerPolicy,
563
+ sandbox: _sandbox,
564
+ src: _src,
565
+ srcDoc: _srcDoc,
566
+ title: _title,
567
+ ...safeProps
568
+ } = props;
569
+ return /* @__PURE__ */ React5.createElement(
570
+ "iframe",
571
+ {
572
+ ...safeProps,
573
+ "data-frame-id": frameId,
574
+ "data-frame-provider": provider,
575
+ src,
576
+ title,
577
+ loading: "lazy",
578
+ referrerPolicy: "no-referrer",
579
+ sandbox: "allow-scripts allow-same-origin",
580
+ className: cn("min-h-[360px] w-full rounded-lg border border-[#3a4d66] bg-[#0b111a]", className)
581
+ }
582
+ );
583
+ }
584
+
585
+ // src/ui/StatusBadge.tsx
586
+ var toneClass4 = {
587
+ neutral: "border-[#303236] bg-black text-[#D4D4D4]",
588
+ success: "border-[#D0FF00]/65 bg-[#101400] text-[#D0FF00]",
589
+ warning: "border-[#FFD166]/55 bg-[#1A1305] text-[#FFD166]",
590
+ danger: "border-[#FF4A55]/65 bg-[#1D0709] text-[#FF8A91]"
591
+ };
592
+ function StatusBadge({ children, tone = "neutral" }) {
593
+ return /* @__PURE__ */ React.createElement("span", { "data-flap-ui": "status-badge", className: cn("inline-flex items-center rounded-[6px] border px-2.5 py-1 text-xs font-semibold uppercase leading-none", toneClass4[tone]) }, children);
594
+ }
595
+
596
+ // src/ui/TxButton.tsx
597
+ var labels = {
598
+ idle: "",
599
+ validating: "Validating",
600
+ approving: "Approving",
601
+ approval_confirming: "Confirming approval",
602
+ simulating: "Simulating",
603
+ writing: "Sending",
604
+ confirming: "Confirming",
605
+ success: "Done",
606
+ failed: "Retry"
607
+ };
608
+ function TxButton({ state = "idle", idleLabel, children, ...props }) {
609
+ const loading = ["validating", "approving", "approval_confirming", "simulating", "writing", "confirming"].includes(state);
610
+ return /* @__PURE__ */ React.createElement(Button, { loading, ...props }, children || labels[state] || idleLabel);
611
+ }
612
+ function VaultBanner({ title, description, badges, meta, action, icon, className }) {
613
+ return /* @__PURE__ */ React.createElement(
614
+ "section",
615
+ {
616
+ className: cn(
617
+ "rounded-lg border border-[#3b82f6] bg-[#172a5a] p-4 shadow-[inset_0_1px_0_rgba(255,255,255,0.08)]",
618
+ className
619
+ )
620
+ },
621
+ /* @__PURE__ */ React.createElement("div", { className: "flex flex-col gap-4 sm:flex-row sm:items-start sm:justify-between" }, /* @__PURE__ */ React.createElement("div", { className: "min-w-0" }, /* @__PURE__ */ React.createElement("div", { className: "flex flex-wrap items-center gap-3" }, /* @__PURE__ */ React.createElement("span", { className: "inline-flex h-4 w-4 shrink-0 items-center justify-center text-[#8fc8ff]" }, icon ?? /* @__PURE__ */ React.createElement(ShieldCheck, { className: "h-4 w-4" })), /* @__PURE__ */ React.createElement("h3", { className: "min-w-0 text-base font-semibold leading-tight text-white" }, title), badges), /* @__PURE__ */ React.createElement("p", { className: "mt-3 max-w-3xl text-sm font-medium leading-6 text-[#d8e2ef]" }, description), meta ? /* @__PURE__ */ React.createElement("div", { className: "mt-2 text-xs font-medium leading-5 text-[#92a4bd]" }, meta) : null), action ? /* @__PURE__ */ React.createElement("div", { className: "shrink-0" }, action) : null)
622
+ );
623
+ }
624
+
625
+ // src/ui/videoSession.ts
626
+ function videoSessionSegments(clips) {
627
+ if (!Array.isArray(clips)) return null;
628
+ const segments = [];
629
+ for (const clip of clips) {
630
+ if (!clip || typeof clip.videoCid !== "string" || clip.videoCid.length > 128 || !Number.isSafeInteger(clip.durationMs) || clip.durationMs <= 0) return null;
631
+ const url = resolveIpfsImageUrl(clip.videoCid);
632
+ if (!url) return null;
633
+ segments.push({ url, duration: clip.durationMs });
634
+ }
635
+ return segments;
636
+ }
637
+ var VideoSessionController = class {
638
+ constructor(video, loadMpegts2, onState) {
639
+ this.video = video;
640
+ this.loadMpegts = loadMpegts2;
641
+ this.onState = onState;
642
+ this.player = null;
643
+ this.removeListeners = null;
644
+ this.segments = [];
645
+ this.generation = 0;
646
+ }
647
+ async update(clips, autoPlay = false, playback) {
648
+ const segments = videoSessionSegments(clips);
649
+ const key = JSON.stringify([segments, playback?.revision]);
650
+ if (key === this.key) return;
651
+ this.key = key;
652
+ const generation = ++this.generation;
653
+ if (!segments?.length) {
654
+ this.destroyPlayer();
655
+ this.segments = [];
656
+ this.onState(segments ? "empty" : "invalid");
657
+ return;
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();
663
+ this.onState("loading");
664
+ try {
665
+ const mpegts = await this.loadMpegts();
666
+ if (generation !== this.generation) return;
667
+ if (!mpegts.isSupported()) {
668
+ this.destroyPlayer();
669
+ this.onState("unsupported");
670
+ return;
671
+ }
672
+ const player = mpegts.createPlayer(
673
+ { type: "mse", isLive: false, cors: true, withCredentials: false, segments },
674
+ {
675
+ enableWorker: false,
676
+ enableWorkerForMSE: false,
677
+ accurateSeek: true,
678
+ // Load far enough to restore a paused viewer without an early,
679
+ // unbuffered TS seek snapping to a different keyframe.
680
+ lazyLoadMaxDuration: Math.max(180, Math.ceil(resumeAt) + 30),
681
+ referrerPolicy: "no-referrer"
682
+ }
683
+ );
684
+ this.player = player;
685
+ this.segments = segments;
686
+ const isCurrent = () => generation === this.generation && this.player === player;
687
+ const onError = () => {
688
+ if (!isCurrent()) return;
689
+ this.destroyPlayer();
690
+ this.onState("error");
691
+ };
692
+ let metadataLoaded = false;
693
+ let restored = false;
694
+ const restorePlayback = () => {
695
+ if (!isCurrent() || !metadataLoaded || restored) return;
696
+ let target = resumeAt;
697
+ if (target > 0) {
698
+ const buffered = this.video.buffered;
699
+ let available = false;
700
+ for (let index = 0; index < buffered.length; index++) {
701
+ const start = buffered.start(index);
702
+ if (target >= start - 0.25 && target < buffered.end(index)) {
703
+ target = Math.max(target, start);
704
+ available = true;
705
+ break;
706
+ }
707
+ }
708
+ if (!available) return;
709
+ }
710
+ restored = true;
711
+ this.video.removeEventListener("progress", restorePlayback);
712
+ try {
713
+ if (target > 0) player.currentTime = target;
714
+ this.onState("ready");
715
+ if (shouldPlay) {
716
+ player.play()?.catch(() => void 0);
717
+ }
718
+ } catch {
719
+ onError();
720
+ }
721
+ };
722
+ const onMetadata = () => {
723
+ metadataLoaded = true;
724
+ restorePlayback();
725
+ };
726
+ player.on(mpegts.Events.ERROR, onError);
727
+ this.video.addEventListener("error", onError);
728
+ this.video.addEventListener("loadedmetadata", onMetadata, { once: true });
729
+ this.video.addEventListener("progress", restorePlayback);
730
+ this.removeListeners = () => {
731
+ player.off(mpegts.Events.ERROR, onError);
732
+ this.video.removeEventListener("error", onError);
733
+ this.video.removeEventListener("loadedmetadata", onMetadata);
734
+ this.video.removeEventListener("progress", restorePlayback);
735
+ };
736
+ player.attachMediaElement(this.video);
737
+ player.load();
738
+ } catch {
739
+ if (generation !== this.generation) return;
740
+ this.destroyPlayer();
741
+ this.onState("error");
742
+ }
743
+ }
744
+ dispose() {
745
+ ++this.generation;
746
+ this.destroyPlayer();
747
+ }
748
+ destroyPlayer() {
749
+ this.removeListeners?.();
750
+ this.removeListeners = null;
751
+ const player = this.player;
752
+ this.player = null;
753
+ try {
754
+ player?.destroy();
755
+ } catch {
756
+ }
757
+ }
758
+ };
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
+
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
+ }
1146
+ async function loadMpegts() {
1147
+ return (await import('./mpegts-536UQHCG.js')).default;
1148
+ }
1149
+ function VideoClipSessionPlayer({ clips, label, fallback = null, className, autoPlay = false, muted = false }) {
1150
+ const videoRef = React5.useRef(null);
1151
+ const controllerRef = React5.useRef(null);
1152
+ const [state, setState] = React5.useState("loading");
1153
+ React5.useEffect(() => {
1154
+ if (!videoRef.current) return;
1155
+ const controller = new VideoSessionController(videoRef.current, loadMpegts, setState);
1156
+ controllerRef.current = controller;
1157
+ return () => {
1158
+ controller.dispose();
1159
+ controllerRef.current = null;
1160
+ };
1161
+ }, []);
1162
+ React5.useEffect(() => {
1163
+ void controllerRef.current?.update(clips, autoPlay);
1164
+ }, [clips, autoPlay]);
1165
+ const showVideo = state === "loading" || state === "ready";
1166
+ return /* @__PURE__ */ React5.createElement("div", { className: cn("w-full", className), "data-flap-video-session-state": state }, /* @__PURE__ */ React5.createElement(
1167
+ "video",
1168
+ {
1169
+ ref: videoRef,
1170
+ "aria-label": label,
1171
+ className: showVideo ? "block w-full" : "hidden",
1172
+ controls: true,
1173
+ playsInline: true,
1174
+ disablePictureInPicture: true,
1175
+ disableRemotePlayback: true,
1176
+ preload: "metadata",
1177
+ muted
1178
+ }
1179
+ ), !showVideo && fallback);
1180
+ }
1181
+
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