@livo-tv/blocks 0.0.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.
- package/README.md +64 -0
- package/dist/avatar.cjs +88 -0
- package/dist/avatar.cjs.map +1 -0
- package/dist/avatar.d.cts +18 -0
- package/dist/avatar.d.ts +18 -0
- package/dist/avatar.js +84 -0
- package/dist/avatar.js.map +1 -0
- package/dist/index.cjs +3685 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +690 -0
- package/dist/index.d.ts +690 -0
- package/dist/index.js +3621 -0
- package/dist/index.js.map +1 -0
- package/package.json +146 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3621 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import * as React3 from 'react';
|
|
3
|
+
import { createContext, useContext, useState, useRef, useId, useEffect, useCallback, useLayoutEffect } from 'react';
|
|
4
|
+
import { Loader2, AlertTriangle, Inbox, Monitor, Sun, Moon, Languages, Upload, Move, ZoomOut, ZoomIn, RotateCcw, RotateCw, Grid3X3, RefreshCw, X, User, Pencil, Check, Play, AlertCircle, VolumeX, Pause, Volume1, Volume2, Settings, PictureInPicture2, Minimize, Maximize, XIcon } from 'lucide-react';
|
|
5
|
+
import { clsx } from 'clsx';
|
|
6
|
+
import { twMerge } from 'tailwind-merge';
|
|
7
|
+
import { cva } from 'class-variance-authority';
|
|
8
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
9
|
+
import * as AlertDialogPrimitive from '@radix-ui/react-alert-dialog';
|
|
10
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
11
|
+
import { useTheme } from 'next-themes';
|
|
12
|
+
import { useReducedMotion, AnimatePresence, motion } from 'framer-motion';
|
|
13
|
+
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
|
14
|
+
import * as SliderPrimitive from '@radix-ui/react-slider';
|
|
15
|
+
import * as TogglePrimitive from '@radix-ui/react-toggle';
|
|
16
|
+
import * as DialogPrimitive from '@radix-ui/react-dialog';
|
|
17
|
+
import { Drawer as Drawer$1 } from 'vaul';
|
|
18
|
+
|
|
19
|
+
var LanguageContext = createContext(null);
|
|
20
|
+
function useLanguageContext() {
|
|
21
|
+
return useContext(LanguageContext);
|
|
22
|
+
}
|
|
23
|
+
function cn(...inputs) {
|
|
24
|
+
return twMerge(clsx(inputs));
|
|
25
|
+
}
|
|
26
|
+
function Empty({ className, ...props }) {
|
|
27
|
+
return /* @__PURE__ */ jsx(
|
|
28
|
+
"div",
|
|
29
|
+
{
|
|
30
|
+
"data-slot": "empty",
|
|
31
|
+
className: cn(
|
|
32
|
+
"flex min-w-0 flex-1 flex-col items-center justify-center gap-6 rounded-lg p-6 text-center text-balance md:p-12",
|
|
33
|
+
className
|
|
34
|
+
),
|
|
35
|
+
...props
|
|
36
|
+
}
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
function EmptyHeader({ className, ...props }) {
|
|
40
|
+
return /* @__PURE__ */ jsx(
|
|
41
|
+
"div",
|
|
42
|
+
{
|
|
43
|
+
"data-slot": "empty-header",
|
|
44
|
+
className: cn(
|
|
45
|
+
"flex max-w-sm flex-col items-center gap-2 text-center",
|
|
46
|
+
className
|
|
47
|
+
),
|
|
48
|
+
...props
|
|
49
|
+
}
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
var emptyMediaVariants = cva(
|
|
53
|
+
"mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
54
|
+
{
|
|
55
|
+
variants: {
|
|
56
|
+
variant: {
|
|
57
|
+
default: "bg-transparent",
|
|
58
|
+
icon: "flex size-10 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-6"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
defaultVariants: {
|
|
62
|
+
variant: "default"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
function EmptyMedia({
|
|
67
|
+
className,
|
|
68
|
+
variant = "default",
|
|
69
|
+
...props
|
|
70
|
+
}) {
|
|
71
|
+
return /* @__PURE__ */ jsx(
|
|
72
|
+
"div",
|
|
73
|
+
{
|
|
74
|
+
"data-slot": "empty-icon",
|
|
75
|
+
"data-variant": variant,
|
|
76
|
+
className: cn(emptyMediaVariants({ variant, className })),
|
|
77
|
+
...props
|
|
78
|
+
}
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
function EmptyTitle({ className, ...props }) {
|
|
82
|
+
return /* @__PURE__ */ jsx(
|
|
83
|
+
"div",
|
|
84
|
+
{
|
|
85
|
+
"data-slot": "empty-title",
|
|
86
|
+
className: cn("text-lg font-medium tracking-tight", className),
|
|
87
|
+
...props
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
function EmptyDescription({ className, ...props }) {
|
|
92
|
+
return /* @__PURE__ */ jsx(
|
|
93
|
+
"div",
|
|
94
|
+
{
|
|
95
|
+
"data-slot": "empty-description",
|
|
96
|
+
className: cn(
|
|
97
|
+
"text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary",
|
|
98
|
+
className
|
|
99
|
+
),
|
|
100
|
+
...props
|
|
101
|
+
}
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
function EmptyContent({ className, ...props }) {
|
|
105
|
+
return /* @__PURE__ */ jsx(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
"data-slot": "empty-content",
|
|
109
|
+
className: cn(
|
|
110
|
+
"flex w-full max-w-sm min-w-0 flex-col items-center gap-4 text-sm text-balance",
|
|
111
|
+
className
|
|
112
|
+
),
|
|
113
|
+
...props
|
|
114
|
+
}
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
function LoadingState({
|
|
118
|
+
label = "Loading\u2026",
|
|
119
|
+
className
|
|
120
|
+
}) {
|
|
121
|
+
return /* @__PURE__ */ jsxs(
|
|
122
|
+
"div",
|
|
123
|
+
{
|
|
124
|
+
role: "status",
|
|
125
|
+
"aria-live": "polite",
|
|
126
|
+
className: cn(
|
|
127
|
+
"flex items-center justify-center gap-2 py-12 text-sm text-muted-foreground",
|
|
128
|
+
className
|
|
129
|
+
),
|
|
130
|
+
children: [
|
|
131
|
+
/* @__PURE__ */ jsx(Loader2, { className: "size-4 animate-spin", "aria-hidden": "true" }),
|
|
132
|
+
/* @__PURE__ */ jsx("span", { children: label })
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function ErrorState({
|
|
138
|
+
title = "Something went wrong",
|
|
139
|
+
description,
|
|
140
|
+
action,
|
|
141
|
+
className
|
|
142
|
+
}) {
|
|
143
|
+
return /* @__PURE__ */ jsxs(
|
|
144
|
+
"div",
|
|
145
|
+
{
|
|
146
|
+
role: "alert",
|
|
147
|
+
className: cn(
|
|
148
|
+
"flex flex-col items-center gap-3 rounded-xl border border-dashed border-destructive/40 bg-destructive/5 py-12 text-center",
|
|
149
|
+
className
|
|
150
|
+
),
|
|
151
|
+
children: [
|
|
152
|
+
/* @__PURE__ */ jsx(AlertTriangle, { className: "size-6 text-destructive", "aria-hidden": "true" }),
|
|
153
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
154
|
+
/* @__PURE__ */ jsx("p", { className: "font-medium", children: title }),
|
|
155
|
+
description ? /* @__PURE__ */ jsx("p", { className: "mt-1 text-sm text-muted-foreground", children: description }) : null
|
|
156
|
+
] }),
|
|
157
|
+
action
|
|
158
|
+
]
|
|
159
|
+
}
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
function EmptyState({
|
|
163
|
+
title,
|
|
164
|
+
description,
|
|
165
|
+
action,
|
|
166
|
+
icon: Icon = Inbox,
|
|
167
|
+
variant = "default",
|
|
168
|
+
className
|
|
169
|
+
}) {
|
|
170
|
+
const isCompact = variant === "compact";
|
|
171
|
+
return /* @__PURE__ */ jsxs(
|
|
172
|
+
Empty,
|
|
173
|
+
{
|
|
174
|
+
className: cn(
|
|
175
|
+
"gap-3",
|
|
176
|
+
isCompact ? "flex-none rounded-none px-4 py-6" : "flex-none rounded-xl border border-dashed px-6 py-12",
|
|
177
|
+
className
|
|
178
|
+
),
|
|
179
|
+
children: [
|
|
180
|
+
/* @__PURE__ */ jsxs(EmptyHeader, { className: "gap-3", children: [
|
|
181
|
+
/* @__PURE__ */ jsx(
|
|
182
|
+
EmptyMedia,
|
|
183
|
+
{
|
|
184
|
+
variant: "icon",
|
|
185
|
+
className: cn(
|
|
186
|
+
"mb-0 bg-transparent text-muted-foreground",
|
|
187
|
+
isCompact ? "size-auto [&_svg:not([class*='size-'])]:size-8 [&_svg]:opacity-50" : "size-auto [&_svg:not([class*='size-'])]:size-6"
|
|
188
|
+
),
|
|
189
|
+
children: /* @__PURE__ */ jsx(Icon, { "aria-hidden": "true" })
|
|
190
|
+
}
|
|
191
|
+
),
|
|
192
|
+
/* @__PURE__ */ jsx(
|
|
193
|
+
EmptyTitle,
|
|
194
|
+
{
|
|
195
|
+
className: cn(
|
|
196
|
+
"font-medium tracking-normal",
|
|
197
|
+
isCompact ? "text-sm" : "text-base"
|
|
198
|
+
),
|
|
199
|
+
children: title
|
|
200
|
+
}
|
|
201
|
+
),
|
|
202
|
+
description ? /* @__PURE__ */ jsx(EmptyDescription, { className: "mt-0", children: description }) : null
|
|
203
|
+
] }),
|
|
204
|
+
action ? /* @__PURE__ */ jsx(EmptyContent, { className: "gap-0", children: action }) : null
|
|
205
|
+
]
|
|
206
|
+
}
|
|
207
|
+
);
|
|
208
|
+
}
|
|
209
|
+
var buttonVariants = cva(
|
|
210
|
+
"inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
|
|
211
|
+
{
|
|
212
|
+
variants: {
|
|
213
|
+
variant: {
|
|
214
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/90",
|
|
215
|
+
destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
|
|
216
|
+
outline: "border bg-background text-foreground shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:text-foreground dark:hover:bg-muted dark:hover:text-foreground",
|
|
217
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
|
|
218
|
+
ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50 dark:hover:text-foreground",
|
|
219
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
220
|
+
},
|
|
221
|
+
size: {
|
|
222
|
+
default: "h-9 px-4 py-2 has-[>svg]:px-3",
|
|
223
|
+
sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
|
|
224
|
+
lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
|
|
225
|
+
icon: "size-9",
|
|
226
|
+
"icon-sm": "size-8",
|
|
227
|
+
"icon-lg": "size-10"
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
defaultVariants: {
|
|
231
|
+
variant: "default",
|
|
232
|
+
size: "default"
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
);
|
|
236
|
+
function Button({
|
|
237
|
+
className,
|
|
238
|
+
variant = "default",
|
|
239
|
+
size = "default",
|
|
240
|
+
asChild = false,
|
|
241
|
+
...props
|
|
242
|
+
}) {
|
|
243
|
+
const Comp = asChild ? Slot : "button";
|
|
244
|
+
return /* @__PURE__ */ jsx(
|
|
245
|
+
Comp,
|
|
246
|
+
{
|
|
247
|
+
"data-slot": "button",
|
|
248
|
+
"data-variant": variant,
|
|
249
|
+
"data-size": size,
|
|
250
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
251
|
+
...props
|
|
252
|
+
}
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
function AlertDialog({
|
|
256
|
+
...props
|
|
257
|
+
}) {
|
|
258
|
+
return /* @__PURE__ */ jsx(AlertDialogPrimitive.Root, { "data-slot": "alert-dialog", ...props });
|
|
259
|
+
}
|
|
260
|
+
function AlertDialogPortal({
|
|
261
|
+
...props
|
|
262
|
+
}) {
|
|
263
|
+
return /* @__PURE__ */ jsx(AlertDialogPrimitive.Portal, { "data-slot": "alert-dialog-portal", ...props });
|
|
264
|
+
}
|
|
265
|
+
function AlertDialogOverlay({
|
|
266
|
+
className,
|
|
267
|
+
...props
|
|
268
|
+
}) {
|
|
269
|
+
return /* @__PURE__ */ jsx(
|
|
270
|
+
AlertDialogPrimitive.Overlay,
|
|
271
|
+
{
|
|
272
|
+
"data-slot": "alert-dialog-overlay",
|
|
273
|
+
className: cn(
|
|
274
|
+
"fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
|
|
275
|
+
className
|
|
276
|
+
),
|
|
277
|
+
...props
|
|
278
|
+
}
|
|
279
|
+
);
|
|
280
|
+
}
|
|
281
|
+
function AlertDialogContent({
|
|
282
|
+
className,
|
|
283
|
+
size = "default",
|
|
284
|
+
...props
|
|
285
|
+
}) {
|
|
286
|
+
return /* @__PURE__ */ jsxs(AlertDialogPortal, { children: [
|
|
287
|
+
/* @__PURE__ */ jsx(AlertDialogOverlay, {}),
|
|
288
|
+
/* @__PURE__ */ jsx(
|
|
289
|
+
AlertDialogPrimitive.Content,
|
|
290
|
+
{
|
|
291
|
+
"data-slot": "alert-dialog-content",
|
|
292
|
+
"data-size": size,
|
|
293
|
+
className: cn(
|
|
294
|
+
"group/alert-dialog-content fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 data-[size=sm]:max-w-xs data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[size=default]:sm:max-w-lg",
|
|
295
|
+
className
|
|
296
|
+
),
|
|
297
|
+
...props
|
|
298
|
+
}
|
|
299
|
+
)
|
|
300
|
+
] });
|
|
301
|
+
}
|
|
302
|
+
function AlertDialogHeader({
|
|
303
|
+
className,
|
|
304
|
+
...props
|
|
305
|
+
}) {
|
|
306
|
+
return /* @__PURE__ */ jsx(
|
|
307
|
+
"div",
|
|
308
|
+
{
|
|
309
|
+
"data-slot": "alert-dialog-header",
|
|
310
|
+
className: cn(
|
|
311
|
+
"flex flex-col gap-1.5 text-center sm:text-left",
|
|
312
|
+
className
|
|
313
|
+
),
|
|
314
|
+
...props
|
|
315
|
+
}
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
function AlertDialogFooter({
|
|
319
|
+
className,
|
|
320
|
+
...props
|
|
321
|
+
}) {
|
|
322
|
+
return /* @__PURE__ */ jsx(
|
|
323
|
+
"div",
|
|
324
|
+
{
|
|
325
|
+
"data-slot": "alert-dialog-footer",
|
|
326
|
+
className: cn(
|
|
327
|
+
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
|
328
|
+
className
|
|
329
|
+
),
|
|
330
|
+
...props
|
|
331
|
+
}
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
function AlertDialogTitle({
|
|
335
|
+
className,
|
|
336
|
+
...props
|
|
337
|
+
}) {
|
|
338
|
+
return /* @__PURE__ */ jsx(
|
|
339
|
+
AlertDialogPrimitive.Title,
|
|
340
|
+
{
|
|
341
|
+
"data-slot": "alert-dialog-title",
|
|
342
|
+
className: cn("text-lg font-semibold", className),
|
|
343
|
+
...props
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
function AlertDialogDescription({
|
|
348
|
+
className,
|
|
349
|
+
...props
|
|
350
|
+
}) {
|
|
351
|
+
return /* @__PURE__ */ jsx(
|
|
352
|
+
AlertDialogPrimitive.Description,
|
|
353
|
+
{
|
|
354
|
+
"data-slot": "alert-dialog-description",
|
|
355
|
+
className: cn("text-sm text-muted-foreground", className),
|
|
356
|
+
...props
|
|
357
|
+
}
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
function AlertDialogAction({
|
|
361
|
+
className,
|
|
362
|
+
variant = "default",
|
|
363
|
+
size = "default",
|
|
364
|
+
...props
|
|
365
|
+
}) {
|
|
366
|
+
return /* @__PURE__ */ jsx(Button, { variant, size, asChild: true, children: /* @__PURE__ */ jsx(
|
|
367
|
+
AlertDialogPrimitive.Action,
|
|
368
|
+
{
|
|
369
|
+
"data-slot": "alert-dialog-action",
|
|
370
|
+
className: cn(className),
|
|
371
|
+
...props
|
|
372
|
+
}
|
|
373
|
+
) });
|
|
374
|
+
}
|
|
375
|
+
function AlertDialogCancel({
|
|
376
|
+
className,
|
|
377
|
+
variant = "outline",
|
|
378
|
+
size = "default",
|
|
379
|
+
...props
|
|
380
|
+
}) {
|
|
381
|
+
return /* @__PURE__ */ jsx(Button, { variant, size, asChild: true, children: /* @__PURE__ */ jsx(
|
|
382
|
+
AlertDialogPrimitive.Cancel,
|
|
383
|
+
{
|
|
384
|
+
"data-slot": "alert-dialog-cancel",
|
|
385
|
+
className: cn(className),
|
|
386
|
+
...props
|
|
387
|
+
}
|
|
388
|
+
) });
|
|
389
|
+
}
|
|
390
|
+
function ConfirmDestructiveDialog({
|
|
391
|
+
open,
|
|
392
|
+
onOpenChange,
|
|
393
|
+
title,
|
|
394
|
+
description,
|
|
395
|
+
confirmLabel = "Delete",
|
|
396
|
+
cancelLabel = "Cancel",
|
|
397
|
+
onConfirm
|
|
398
|
+
}) {
|
|
399
|
+
return /* @__PURE__ */ jsx(AlertDialog, { open, onOpenChange, children: /* @__PURE__ */ jsxs(AlertDialogContent, { size: "sm", children: [
|
|
400
|
+
/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
|
|
401
|
+
/* @__PURE__ */ jsx(AlertDialogTitle, { children: title }),
|
|
402
|
+
/* @__PURE__ */ jsx(AlertDialogDescription, { children: description })
|
|
403
|
+
] }),
|
|
404
|
+
/* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
|
|
405
|
+
/* @__PURE__ */ jsx(AlertDialogCancel, { children: cancelLabel }),
|
|
406
|
+
/* @__PURE__ */ jsx(
|
|
407
|
+
AlertDialogAction,
|
|
408
|
+
{
|
|
409
|
+
variant: "destructive",
|
|
410
|
+
onClick: () => {
|
|
411
|
+
onConfirm();
|
|
412
|
+
onOpenChange(false);
|
|
413
|
+
},
|
|
414
|
+
children: confirmLabel
|
|
415
|
+
}
|
|
416
|
+
)
|
|
417
|
+
] })
|
|
418
|
+
] }) });
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// src/components/editable/types.ts
|
|
422
|
+
var DEFAULT_EDITABLE_SECTION_LABELS = {
|
|
423
|
+
edit: "Edit",
|
|
424
|
+
save: "Save",
|
|
425
|
+
saving: "Saving\u2026",
|
|
426
|
+
cancel: "Cancel",
|
|
427
|
+
saved: "Saved",
|
|
428
|
+
discardTitle: "Discard changes?",
|
|
429
|
+
discardDescription: "If you leave now, unsaved changes will be lost.",
|
|
430
|
+
discardConfirm: "Discard",
|
|
431
|
+
discardCancel: "Keep editing"
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
// src/components/editable/useEditableSection.ts
|
|
435
|
+
function focusFirstField(container) {
|
|
436
|
+
if (!container) return;
|
|
437
|
+
const target = container.querySelector(
|
|
438
|
+
"[data-autofocus], input:not([type='hidden']):not([disabled]), select:not([disabled]), textarea:not([disabled]), [contenteditable='true']"
|
|
439
|
+
);
|
|
440
|
+
target?.focus();
|
|
441
|
+
}
|
|
442
|
+
function useEditableSection({
|
|
443
|
+
onSave,
|
|
444
|
+
onDiscard,
|
|
445
|
+
isDirty = false,
|
|
446
|
+
labelledBy,
|
|
447
|
+
title,
|
|
448
|
+
labels,
|
|
449
|
+
stableHeight = false
|
|
450
|
+
}) {
|
|
451
|
+
const resolvedLabels = {
|
|
452
|
+
...DEFAULT_EDITABLE_SECTION_LABELS,
|
|
453
|
+
...labels
|
|
454
|
+
};
|
|
455
|
+
const [mode, setMode] = useState("reading");
|
|
456
|
+
const [status, setStatus] = useState(null);
|
|
457
|
+
const [confirmOpen, setConfirmOpen] = useState(false);
|
|
458
|
+
const [minHeightPx, setMinHeightPx] = useState(void 0);
|
|
459
|
+
const contentRef = useRef(null);
|
|
460
|
+
const editButtonRef = useRef(null);
|
|
461
|
+
const measuredHeightRef = useRef(0);
|
|
462
|
+
const shouldFocusEditRef = useRef(false);
|
|
463
|
+
const shouldFocusFirstFieldRef = useRef(false);
|
|
464
|
+
const editButtonId = useId();
|
|
465
|
+
const contentFormId = useId();
|
|
466
|
+
const isEditing = mode === "editing" || mode === "saving";
|
|
467
|
+
const isSaving = mode === "saving";
|
|
468
|
+
useEffect(() => {
|
|
469
|
+
if (mode === "reading" && shouldFocusEditRef.current) {
|
|
470
|
+
shouldFocusEditRef.current = false;
|
|
471
|
+
editButtonRef.current?.focus();
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
if (mode === "editing" && shouldFocusFirstFieldRef.current) {
|
|
475
|
+
shouldFocusFirstFieldRef.current = false;
|
|
476
|
+
const invalid = contentRef.current?.querySelector(
|
|
477
|
+
"[aria-invalid='true']"
|
|
478
|
+
);
|
|
479
|
+
if (invalid) {
|
|
480
|
+
invalid.focus();
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
focusFirstField(contentRef.current);
|
|
484
|
+
}
|
|
485
|
+
}, [mode]);
|
|
486
|
+
const exitToReading = useCallback(() => {
|
|
487
|
+
setConfirmOpen(false);
|
|
488
|
+
shouldFocusEditRef.current = true;
|
|
489
|
+
setMode("reading");
|
|
490
|
+
onDiscard?.();
|
|
491
|
+
}, [onDiscard]);
|
|
492
|
+
const startEdit = useCallback(() => {
|
|
493
|
+
setStatus(null);
|
|
494
|
+
shouldFocusFirstFieldRef.current = true;
|
|
495
|
+
setMode("editing");
|
|
496
|
+
}, []);
|
|
497
|
+
const requestCancel = useCallback(() => {
|
|
498
|
+
if (isSaving) return;
|
|
499
|
+
if (isDirty) {
|
|
500
|
+
setConfirmOpen(true);
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
exitToReading();
|
|
504
|
+
}, [exitToReading, isDirty, isSaving]);
|
|
505
|
+
const handleSubmit = useCallback(
|
|
506
|
+
(event) => {
|
|
507
|
+
event.preventDefault();
|
|
508
|
+
if (isSaving) return;
|
|
509
|
+
void (async () => {
|
|
510
|
+
setMode("saving");
|
|
511
|
+
setStatus(null);
|
|
512
|
+
try {
|
|
513
|
+
await onSave();
|
|
514
|
+
setStatus(resolvedLabels.saved);
|
|
515
|
+
shouldFocusEditRef.current = true;
|
|
516
|
+
setMode("reading");
|
|
517
|
+
} catch {
|
|
518
|
+
shouldFocusFirstFieldRef.current = true;
|
|
519
|
+
setMode("editing");
|
|
520
|
+
}
|
|
521
|
+
})();
|
|
522
|
+
},
|
|
523
|
+
[isSaving, onSave, resolvedLabels.saved]
|
|
524
|
+
);
|
|
525
|
+
const handleFormKeyDown = useCallback(
|
|
526
|
+
(event) => {
|
|
527
|
+
if (event.key !== "Escape") return;
|
|
528
|
+
event.preventDefault();
|
|
529
|
+
requestCancel();
|
|
530
|
+
},
|
|
531
|
+
[requestCancel]
|
|
532
|
+
);
|
|
533
|
+
useEffect(() => {
|
|
534
|
+
if (!stableHeight || !isEditing) return;
|
|
535
|
+
const el = contentRef.current;
|
|
536
|
+
if (!el) return;
|
|
537
|
+
const measure = () => {
|
|
538
|
+
const height = el.getBoundingClientRect().height;
|
|
539
|
+
if (height > measuredHeightRef.current) {
|
|
540
|
+
measuredHeightRef.current = height;
|
|
541
|
+
setMinHeightPx(height);
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
measure();
|
|
545
|
+
const observer = new ResizeObserver(measure);
|
|
546
|
+
observer.observe(el);
|
|
547
|
+
return () => observer.disconnect();
|
|
548
|
+
}, [isEditing, stableHeight]);
|
|
549
|
+
const editButtonNameProps = labelledBy != null ? { "aria-labelledby": `${labelledBy} ${editButtonId}` } : title != null && title.length > 0 ? { "aria-label": `${resolvedLabels.edit} ${title}` } : { "aria-label": resolvedLabels.edit };
|
|
550
|
+
return {
|
|
551
|
+
mode,
|
|
552
|
+
isEditing,
|
|
553
|
+
isSaving,
|
|
554
|
+
startEdit,
|
|
555
|
+
requestCancel,
|
|
556
|
+
formProps: {
|
|
557
|
+
onSubmit: handleSubmit,
|
|
558
|
+
onKeyDown: handleFormKeyDown,
|
|
559
|
+
noValidate: true
|
|
560
|
+
},
|
|
561
|
+
contentRef,
|
|
562
|
+
editButtonRef,
|
|
563
|
+
contentFormId,
|
|
564
|
+
editButtonProps: {
|
|
565
|
+
type: "button",
|
|
566
|
+
id: editButtonId,
|
|
567
|
+
onClick: startEdit,
|
|
568
|
+
ref: editButtonRef,
|
|
569
|
+
...editButtonNameProps
|
|
570
|
+
},
|
|
571
|
+
saveButtonProps: {
|
|
572
|
+
type: "submit",
|
|
573
|
+
disabled: isSaving
|
|
574
|
+
},
|
|
575
|
+
cancelButtonProps: {
|
|
576
|
+
type: "button",
|
|
577
|
+
onClick: requestCancel,
|
|
578
|
+
disabled: isSaving
|
|
579
|
+
},
|
|
580
|
+
status,
|
|
581
|
+
statusProps: {
|
|
582
|
+
role: "status",
|
|
583
|
+
"aria-live": "polite",
|
|
584
|
+
className: "sr-only"
|
|
585
|
+
},
|
|
586
|
+
confirmDiscard: {
|
|
587
|
+
open: confirmOpen,
|
|
588
|
+
onOpenChange: setConfirmOpen,
|
|
589
|
+
title: resolvedLabels.discardTitle,
|
|
590
|
+
description: resolvedLabels.discardDescription,
|
|
591
|
+
confirmLabel: resolvedLabels.discardConfirm,
|
|
592
|
+
cancelLabel: resolvedLabels.discardCancel,
|
|
593
|
+
onConfirm: exitToReading
|
|
594
|
+
},
|
|
595
|
+
resolvedLabels,
|
|
596
|
+
contentStyle: stableHeight && minHeightPx != null ? { minHeight: minHeightPx } : void 0,
|
|
597
|
+
actionsClassName: "flex min-h-9 min-w-[11rem] flex-wrap items-center justify-end gap-2"
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
function EditableSection({
|
|
601
|
+
readView,
|
|
602
|
+
editView,
|
|
603
|
+
children,
|
|
604
|
+
className,
|
|
605
|
+
...options
|
|
606
|
+
}) {
|
|
607
|
+
const section = useEditableSection(options);
|
|
608
|
+
const {
|
|
609
|
+
isEditing,
|
|
610
|
+
isSaving,
|
|
611
|
+
formProps,
|
|
612
|
+
contentRef,
|
|
613
|
+
contentFormId,
|
|
614
|
+
editButtonProps,
|
|
615
|
+
saveButtonProps,
|
|
616
|
+
cancelButtonProps,
|
|
617
|
+
status,
|
|
618
|
+
statusProps,
|
|
619
|
+
confirmDiscard,
|
|
620
|
+
resolvedLabels,
|
|
621
|
+
contentStyle,
|
|
622
|
+
actionsClassName,
|
|
623
|
+
mode
|
|
624
|
+
} = section;
|
|
625
|
+
const actionButtons = !isEditing ? /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", ...editButtonProps, children: resolvedLabels.edit }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
626
|
+
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", ...cancelButtonProps, children: resolvedLabels.cancel }),
|
|
627
|
+
/* @__PURE__ */ jsx(
|
|
628
|
+
Button,
|
|
629
|
+
{
|
|
630
|
+
size: "sm",
|
|
631
|
+
type: "submit",
|
|
632
|
+
form: contentFormId,
|
|
633
|
+
disabled: saveButtonProps.disabled,
|
|
634
|
+
children: isSaving ? resolvedLabels.saving : resolvedLabels.save
|
|
635
|
+
}
|
|
636
|
+
)
|
|
637
|
+
] });
|
|
638
|
+
const actions = /* @__PURE__ */ jsx("div", { "data-slot": "editable-section-actions", className: actionsClassName, children: actionButtons });
|
|
639
|
+
const content = isEditing ? /* @__PURE__ */ jsx(
|
|
640
|
+
"form",
|
|
641
|
+
{
|
|
642
|
+
id: contentFormId,
|
|
643
|
+
ref: contentRef,
|
|
644
|
+
"data-slot": "editable-section-content",
|
|
645
|
+
className: cn("livo-editable-section-content space-y-4"),
|
|
646
|
+
style: contentStyle,
|
|
647
|
+
...formProps,
|
|
648
|
+
children: editView()
|
|
649
|
+
}
|
|
650
|
+
) : /* @__PURE__ */ jsx(
|
|
651
|
+
"div",
|
|
652
|
+
{
|
|
653
|
+
ref: contentRef,
|
|
654
|
+
"data-slot": "editable-section-content",
|
|
655
|
+
className: "livo-editable-section-content",
|
|
656
|
+
style: contentStyle,
|
|
657
|
+
children: readView()
|
|
658
|
+
}
|
|
659
|
+
);
|
|
660
|
+
const statusNode = /* @__PURE__ */ jsx("span", { ...statusProps, "data-slot": "editable-section-status", children: status });
|
|
661
|
+
const dialog = /* @__PURE__ */ jsx(
|
|
662
|
+
ConfirmDestructiveDialog,
|
|
663
|
+
{
|
|
664
|
+
open: confirmDiscard.open,
|
|
665
|
+
onOpenChange: confirmDiscard.onOpenChange,
|
|
666
|
+
title: confirmDiscard.title,
|
|
667
|
+
description: confirmDiscard.description,
|
|
668
|
+
confirmLabel: confirmDiscard.confirmLabel,
|
|
669
|
+
cancelLabel: confirmDiscard.cancelLabel,
|
|
670
|
+
onConfirm: confirmDiscard.onConfirm
|
|
671
|
+
}
|
|
672
|
+
);
|
|
673
|
+
if (children) {
|
|
674
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
675
|
+
children({
|
|
676
|
+
actions,
|
|
677
|
+
content,
|
|
678
|
+
status: statusNode,
|
|
679
|
+
mode,
|
|
680
|
+
isSaving,
|
|
681
|
+
isEditing
|
|
682
|
+
}),
|
|
683
|
+
dialog
|
|
684
|
+
] });
|
|
685
|
+
}
|
|
686
|
+
return /* @__PURE__ */ jsxs("div", { "data-slot": "editable-section", className: cn("space-y-4", className), children: [
|
|
687
|
+
actions,
|
|
688
|
+
content,
|
|
689
|
+
statusNode,
|
|
690
|
+
dialog
|
|
691
|
+
] });
|
|
692
|
+
}
|
|
693
|
+
function DataList({ className, ...props }) {
|
|
694
|
+
return /* @__PURE__ */ jsx(
|
|
695
|
+
"dl",
|
|
696
|
+
{
|
|
697
|
+
"data-slot": "data-list",
|
|
698
|
+
className: cn("grid gap-4 sm:grid-cols-2", className),
|
|
699
|
+
...props
|
|
700
|
+
}
|
|
701
|
+
);
|
|
702
|
+
}
|
|
703
|
+
function DataListItem({
|
|
704
|
+
label,
|
|
705
|
+
children,
|
|
706
|
+
empty = "\u2014",
|
|
707
|
+
className,
|
|
708
|
+
labelClassName,
|
|
709
|
+
valueClassName
|
|
710
|
+
}) {
|
|
711
|
+
const isEmpty = children == null || children === false || typeof children === "string" && children.trim().length === 0;
|
|
712
|
+
return /* @__PURE__ */ jsxs(
|
|
713
|
+
"div",
|
|
714
|
+
{
|
|
715
|
+
"data-slot": "data-list-item",
|
|
716
|
+
className: cn("flex flex-col gap-1.5", className),
|
|
717
|
+
children: [
|
|
718
|
+
/* @__PURE__ */ jsx(
|
|
719
|
+
"dt",
|
|
720
|
+
{
|
|
721
|
+
className: cn(
|
|
722
|
+
"text-sm leading-none font-medium peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
|
|
723
|
+
labelClassName
|
|
724
|
+
),
|
|
725
|
+
children: label
|
|
726
|
+
}
|
|
727
|
+
),
|
|
728
|
+
/* @__PURE__ */ jsx(
|
|
729
|
+
"dd",
|
|
730
|
+
{
|
|
731
|
+
className: cn(
|
|
732
|
+
"text-sm wrap-break-word",
|
|
733
|
+
isEmpty && "text-muted-foreground",
|
|
734
|
+
valueClassName
|
|
735
|
+
),
|
|
736
|
+
children: isEmpty ? empty : children
|
|
737
|
+
}
|
|
738
|
+
)
|
|
739
|
+
]
|
|
740
|
+
}
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
function FieldMessage({
|
|
744
|
+
id,
|
|
745
|
+
children,
|
|
746
|
+
className,
|
|
747
|
+
...props
|
|
748
|
+
}) {
|
|
749
|
+
const hasMessage = children != null && children !== false && !(typeof children === "string" && children.trim().length === 0);
|
|
750
|
+
return /* @__PURE__ */ jsx(
|
|
751
|
+
"p",
|
|
752
|
+
{
|
|
753
|
+
id,
|
|
754
|
+
role: hasMessage ? "alert" : void 0,
|
|
755
|
+
"data-slot": "field-message",
|
|
756
|
+
className: cn("min-h-5 text-xs text-destructive", className),
|
|
757
|
+
...props,
|
|
758
|
+
children: hasMessage ? children : "\xA0"
|
|
759
|
+
}
|
|
760
|
+
);
|
|
761
|
+
}
|
|
762
|
+
function isBrokenImage(img) {
|
|
763
|
+
return img.complete && img.naturalWidth === 0;
|
|
764
|
+
}
|
|
765
|
+
function SafeImage({
|
|
766
|
+
src,
|
|
767
|
+
fallback,
|
|
768
|
+
alt = "",
|
|
769
|
+
onError,
|
|
770
|
+
...imgProps
|
|
771
|
+
}) {
|
|
772
|
+
const [failed, setFailed] = useState(false);
|
|
773
|
+
const imgRef = useRef(null);
|
|
774
|
+
const resolvedSrc = typeof src === "string" && src.length > 0 ? src : null;
|
|
775
|
+
useLayoutEffect(() => {
|
|
776
|
+
setFailed(false);
|
|
777
|
+
}, [resolvedSrc]);
|
|
778
|
+
useLayoutEffect(() => {
|
|
779
|
+
const img = imgRef.current;
|
|
780
|
+
if (img && isBrokenImage(img)) {
|
|
781
|
+
setFailed(true);
|
|
782
|
+
}
|
|
783
|
+
}, [resolvedSrc, failed]);
|
|
784
|
+
if (!resolvedSrc || failed) {
|
|
785
|
+
return /* @__PURE__ */ jsx(Fragment, { children: fallback });
|
|
786
|
+
}
|
|
787
|
+
return /* @__PURE__ */ jsx(
|
|
788
|
+
"img",
|
|
789
|
+
{
|
|
790
|
+
...imgProps,
|
|
791
|
+
ref: imgRef,
|
|
792
|
+
src: resolvedSrc,
|
|
793
|
+
alt,
|
|
794
|
+
onError: (event) => {
|
|
795
|
+
setFailed(true);
|
|
796
|
+
onError?.(event);
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
);
|
|
800
|
+
}
|
|
801
|
+
var miniMenuContentClassName = "max-h-none overflow-x-visible overflow-y-visible";
|
|
802
|
+
var miniMenuContentDefaults = {
|
|
803
|
+
sideOffset: 8,
|
|
804
|
+
collisionPadding: 12
|
|
805
|
+
};
|
|
806
|
+
function DropdownMenu({
|
|
807
|
+
...props
|
|
808
|
+
}) {
|
|
809
|
+
return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Root, { "data-slot": "dropdown-menu", ...props });
|
|
810
|
+
}
|
|
811
|
+
function DropdownMenuTrigger({
|
|
812
|
+
...props
|
|
813
|
+
}) {
|
|
814
|
+
return /* @__PURE__ */ jsx(
|
|
815
|
+
DropdownMenuPrimitive.Trigger,
|
|
816
|
+
{
|
|
817
|
+
"data-slot": "dropdown-menu-trigger",
|
|
818
|
+
...props
|
|
819
|
+
}
|
|
820
|
+
);
|
|
821
|
+
}
|
|
822
|
+
function DropdownMenuContent({
|
|
823
|
+
className,
|
|
824
|
+
sideOffset = 4,
|
|
825
|
+
...props
|
|
826
|
+
}) {
|
|
827
|
+
return /* @__PURE__ */ jsx(DropdownMenuPrimitive.Portal, { children: /* @__PURE__ */ jsx(
|
|
828
|
+
DropdownMenuPrimitive.Content,
|
|
829
|
+
{
|
|
830
|
+
"data-slot": "dropdown-menu-content",
|
|
831
|
+
sideOffset,
|
|
832
|
+
className: cn(
|
|
833
|
+
"bg-popover text-popover-foreground data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 z-[200] max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border p-1 shadow-md",
|
|
834
|
+
className
|
|
835
|
+
),
|
|
836
|
+
...props
|
|
837
|
+
}
|
|
838
|
+
) });
|
|
839
|
+
}
|
|
840
|
+
function DropdownMenuItem({
|
|
841
|
+
className,
|
|
842
|
+
inset,
|
|
843
|
+
variant = "default",
|
|
844
|
+
...props
|
|
845
|
+
}) {
|
|
846
|
+
return /* @__PURE__ */ jsx(
|
|
847
|
+
DropdownMenuPrimitive.Item,
|
|
848
|
+
{
|
|
849
|
+
"data-slot": "dropdown-menu-item",
|
|
850
|
+
"data-inset": inset,
|
|
851
|
+
"data-variant": variant,
|
|
852
|
+
className: cn(
|
|
853
|
+
"relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[highlighted]:[&_svg:not([class*='text-'])]:text-accent-foreground focus:bg-accent focus:text-accent-foreground focus:[&_svg:not([class*='text-'])]:text-accent-foreground data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:data-[highlighted]:bg-destructive/10 dark:data-[variant=destructive]:focus:bg-destructive/20 dark:data-[variant=destructive]:data-[highlighted]:bg-destructive/20 data-[variant=destructive]:focus:text-destructive data-[variant=destructive]:data-[highlighted]:text-destructive data-[variant=destructive]:*:[svg]:!text-destructive [&_svg:not([class*='text-'])]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
854
|
+
className
|
|
855
|
+
),
|
|
856
|
+
...props
|
|
857
|
+
}
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
var defaultLabels = {
|
|
861
|
+
theme: "Theme",
|
|
862
|
+
system: "System",
|
|
863
|
+
light: "Light",
|
|
864
|
+
dark: "Dark"
|
|
865
|
+
};
|
|
866
|
+
var sizeClasses = {
|
|
867
|
+
sm: {
|
|
868
|
+
container: "h-7 p-0.5",
|
|
869
|
+
button: "h-6 w-6",
|
|
870
|
+
buttonMini: "h-7 w-7",
|
|
871
|
+
icon: "h-3.5 w-3.5",
|
|
872
|
+
iconMini: "h-3.5 w-3.5"
|
|
873
|
+
},
|
|
874
|
+
md: {
|
|
875
|
+
container: "h-8 p-1",
|
|
876
|
+
button: "h-6 w-6",
|
|
877
|
+
buttonMini: "h-8 w-8",
|
|
878
|
+
icon: "h-4 w-4",
|
|
879
|
+
iconMini: "h-4 w-4"
|
|
880
|
+
},
|
|
881
|
+
lg: {
|
|
882
|
+
container: "h-9 p-1",
|
|
883
|
+
button: "h-7 w-7",
|
|
884
|
+
buttonMini: "h-9 w-9",
|
|
885
|
+
icon: "h-4 w-4",
|
|
886
|
+
iconMini: "h-4.5 w-4.5"
|
|
887
|
+
}
|
|
888
|
+
};
|
|
889
|
+
var shapeClasses = {
|
|
890
|
+
rounded: "rounded-md",
|
|
891
|
+
pill: "rounded-full"
|
|
892
|
+
};
|
|
893
|
+
var themes = [
|
|
894
|
+
{ key: "system", icon: Monitor },
|
|
895
|
+
{ key: "light", icon: Sun },
|
|
896
|
+
{ key: "dark", icon: Moon }
|
|
897
|
+
];
|
|
898
|
+
function ThemeSwitcher({
|
|
899
|
+
className,
|
|
900
|
+
size = "sm",
|
|
901
|
+
shape = "rounded",
|
|
902
|
+
variant = "default",
|
|
903
|
+
align = "end",
|
|
904
|
+
side = "bottom",
|
|
905
|
+
labels: userLabels
|
|
906
|
+
}) {
|
|
907
|
+
const { theme, setTheme } = useTheme();
|
|
908
|
+
const [mounted, setMounted] = useState(false);
|
|
909
|
+
const reduceMotion = useReducedMotion();
|
|
910
|
+
const sizes = sizeClasses[size];
|
|
911
|
+
const shapeClass = shapeClasses[shape];
|
|
912
|
+
const labels = { ...defaultLabels, ...userLabels };
|
|
913
|
+
const handleThemeClick = useCallback(
|
|
914
|
+
(themeKey) => {
|
|
915
|
+
setTheme(themeKey);
|
|
916
|
+
},
|
|
917
|
+
[setTheme]
|
|
918
|
+
);
|
|
919
|
+
useEffect(() => {
|
|
920
|
+
setMounted(true);
|
|
921
|
+
}, []);
|
|
922
|
+
if (!mounted) {
|
|
923
|
+
return /* @__PURE__ */ jsx(
|
|
924
|
+
"div",
|
|
925
|
+
{
|
|
926
|
+
className: cn(
|
|
927
|
+
variant === "mini" ? sizes.buttonMini : sizes.container,
|
|
928
|
+
shapeClass,
|
|
929
|
+
variant === "default" && "bg-background ring-1 ring-border",
|
|
930
|
+
className
|
|
931
|
+
)
|
|
932
|
+
}
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
const currentTheme = theme;
|
|
936
|
+
const CurrentIcon = themes.find((t) => t.key === currentTheme)?.icon || Monitor;
|
|
937
|
+
if (variant === "mini") {
|
|
938
|
+
return /* @__PURE__ */ jsxs(DropdownMenu, { modal: false, children: [
|
|
939
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
940
|
+
Button,
|
|
941
|
+
{
|
|
942
|
+
"data-testid": "theme-switcher",
|
|
943
|
+
variant: "ghost",
|
|
944
|
+
size: "icon",
|
|
945
|
+
"aria-label": labels.theme,
|
|
946
|
+
className: cn(sizes.buttonMini, shapeClass, className),
|
|
947
|
+
children: /* @__PURE__ */ jsx(CurrentIcon, { className: sizes.iconMini })
|
|
948
|
+
}
|
|
949
|
+
) }),
|
|
950
|
+
/* @__PURE__ */ jsx(
|
|
951
|
+
DropdownMenuContent,
|
|
952
|
+
{
|
|
953
|
+
side,
|
|
954
|
+
align,
|
|
955
|
+
sideOffset: miniMenuContentDefaults.sideOffset,
|
|
956
|
+
collisionPadding: miniMenuContentDefaults.collisionPadding,
|
|
957
|
+
className: miniMenuContentClassName,
|
|
958
|
+
children: themes.map(({ key, icon: Icon }) => /* @__PURE__ */ jsxs(
|
|
959
|
+
DropdownMenuItem,
|
|
960
|
+
{
|
|
961
|
+
onClick: () => handleThemeClick(key),
|
|
962
|
+
className: cn(
|
|
963
|
+
"gap-2 cursor-pointer",
|
|
964
|
+
currentTheme === key && "bg-accent text-accent-foreground [&_svg]:text-accent-foreground"
|
|
965
|
+
),
|
|
966
|
+
children: [
|
|
967
|
+
/* @__PURE__ */ jsx(Icon, { className: "h-4 w-4" }),
|
|
968
|
+
/* @__PURE__ */ jsx("span", { children: labels[key] })
|
|
969
|
+
]
|
|
970
|
+
},
|
|
971
|
+
key
|
|
972
|
+
))
|
|
973
|
+
}
|
|
974
|
+
)
|
|
975
|
+
] });
|
|
976
|
+
}
|
|
977
|
+
return /* @__PURE__ */ jsx(
|
|
978
|
+
"div",
|
|
979
|
+
{
|
|
980
|
+
"data-testid": "theme-switcher",
|
|
981
|
+
className: cn(
|
|
982
|
+
"relative isolate flex bg-background ring-1 ring-border",
|
|
983
|
+
sizes.container,
|
|
984
|
+
shapeClass,
|
|
985
|
+
className
|
|
986
|
+
),
|
|
987
|
+
children: themes.map(({ key, icon: Icon }) => {
|
|
988
|
+
const isActive = currentTheme === key;
|
|
989
|
+
return /* @__PURE__ */ jsxs(
|
|
990
|
+
"button",
|
|
991
|
+
{
|
|
992
|
+
"aria-label": labels[key],
|
|
993
|
+
"aria-pressed": isActive,
|
|
994
|
+
className: cn("relative", sizes.button, shapeClass),
|
|
995
|
+
onClick: () => handleThemeClick(key),
|
|
996
|
+
type: "button",
|
|
997
|
+
children: [
|
|
998
|
+
reduceMotion ? isActive ? /* @__PURE__ */ jsx(
|
|
999
|
+
"div",
|
|
1000
|
+
{
|
|
1001
|
+
className: cn("absolute inset-0 bg-secondary", shapeClass)
|
|
1002
|
+
}
|
|
1003
|
+
) : null : /* @__PURE__ */ jsx(AnimatePresence, { children: isActive && /* @__PURE__ */ jsx(
|
|
1004
|
+
motion.div,
|
|
1005
|
+
{
|
|
1006
|
+
className: cn("absolute inset-0 bg-secondary", shapeClass),
|
|
1007
|
+
layoutId: "activeTheme",
|
|
1008
|
+
initial: { opacity: 0 },
|
|
1009
|
+
animate: { opacity: 1 },
|
|
1010
|
+
exit: { opacity: 0 },
|
|
1011
|
+
transition: { type: "spring", duration: 0.5 }
|
|
1012
|
+
}
|
|
1013
|
+
) }),
|
|
1014
|
+
/* @__PURE__ */ jsx(
|
|
1015
|
+
Icon,
|
|
1016
|
+
{
|
|
1017
|
+
className: cn(
|
|
1018
|
+
"relative z-10 m-auto",
|
|
1019
|
+
sizes.icon,
|
|
1020
|
+
isActive ? "text-foreground" : "text-muted-foreground"
|
|
1021
|
+
)
|
|
1022
|
+
}
|
|
1023
|
+
)
|
|
1024
|
+
]
|
|
1025
|
+
},
|
|
1026
|
+
key
|
|
1027
|
+
);
|
|
1028
|
+
})
|
|
1029
|
+
}
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
var defaultLanguages = [
|
|
1033
|
+
{ key: "en", label: "EN", nativeName: "English" },
|
|
1034
|
+
{ key: "es", label: "ES", nativeName: "Espa\xF1ol" },
|
|
1035
|
+
{ key: "pt", label: "PT", nativeName: "Portugu\xEAs" }
|
|
1036
|
+
];
|
|
1037
|
+
var sizeClasses2 = {
|
|
1038
|
+
sm: {
|
|
1039
|
+
container: "h-7 p-0.5 text-xs",
|
|
1040
|
+
button: "h-6 px-2",
|
|
1041
|
+
buttonMini: "h-7 w-7",
|
|
1042
|
+
icon: "size-3",
|
|
1043
|
+
iconMini: "size-3.5"
|
|
1044
|
+
},
|
|
1045
|
+
md: {
|
|
1046
|
+
container: "h-8 p-0.5 text-xs",
|
|
1047
|
+
button: "h-7 px-2.5",
|
|
1048
|
+
buttonMini: "h-8 w-8",
|
|
1049
|
+
icon: "size-3.5",
|
|
1050
|
+
iconMini: "size-4"
|
|
1051
|
+
},
|
|
1052
|
+
lg: {
|
|
1053
|
+
container: "h-9 p-0.5 text-sm",
|
|
1054
|
+
button: "h-8 px-3",
|
|
1055
|
+
buttonMini: "h-9 w-9",
|
|
1056
|
+
icon: "size-4",
|
|
1057
|
+
iconMini: "size-4.5"
|
|
1058
|
+
}
|
|
1059
|
+
};
|
|
1060
|
+
var shapeClasses2 = {
|
|
1061
|
+
rounded: "rounded-md",
|
|
1062
|
+
squared: "rounded-sm",
|
|
1063
|
+
pill: "rounded-full"
|
|
1064
|
+
};
|
|
1065
|
+
function LanguageSwitcher({
|
|
1066
|
+
languages: propLanguages,
|
|
1067
|
+
currentLanguage: propCurrentLanguage,
|
|
1068
|
+
onLanguageChange: propOnLanguageChange,
|
|
1069
|
+
labels = {},
|
|
1070
|
+
className,
|
|
1071
|
+
size = "sm",
|
|
1072
|
+
shape = "rounded",
|
|
1073
|
+
variant = "default",
|
|
1074
|
+
showIcon = true,
|
|
1075
|
+
align = "end",
|
|
1076
|
+
side = "bottom"
|
|
1077
|
+
}) {
|
|
1078
|
+
const context = useLanguageContext();
|
|
1079
|
+
const contextLanguages = context?.languages?.map((lang) => ({
|
|
1080
|
+
key: lang.code,
|
|
1081
|
+
label: lang.code.toUpperCase(),
|
|
1082
|
+
nativeName: lang.name
|
|
1083
|
+
}));
|
|
1084
|
+
const languages = propLanguages ?? contextLanguages ?? defaultLanguages;
|
|
1085
|
+
const currentLanguage = propCurrentLanguage ?? context?.language ?? "en";
|
|
1086
|
+
const onLanguageChange = propOnLanguageChange ?? context?.setLanguage;
|
|
1087
|
+
const sizes = sizeClasses2[size];
|
|
1088
|
+
const shapeClass = shapeClasses2[shape];
|
|
1089
|
+
const reduceMotion = useReducedMotion();
|
|
1090
|
+
const defaultLabels2 = {
|
|
1091
|
+
language: labels.language ?? "Language"
|
|
1092
|
+
};
|
|
1093
|
+
if (variant === "mini") {
|
|
1094
|
+
return /* @__PURE__ */ jsxs(DropdownMenu, { modal: false, children: [
|
|
1095
|
+
/* @__PURE__ */ jsx(DropdownMenuTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
1096
|
+
Button,
|
|
1097
|
+
{
|
|
1098
|
+
variant: "ghost",
|
|
1099
|
+
size: "icon",
|
|
1100
|
+
"aria-label": defaultLabels2.language,
|
|
1101
|
+
className: cn(sizes.buttonMini, shapeClass, className),
|
|
1102
|
+
children: /* @__PURE__ */ jsx(Languages, { className: sizes.iconMini })
|
|
1103
|
+
}
|
|
1104
|
+
) }),
|
|
1105
|
+
/* @__PURE__ */ jsx(
|
|
1106
|
+
DropdownMenuContent,
|
|
1107
|
+
{
|
|
1108
|
+
side,
|
|
1109
|
+
align,
|
|
1110
|
+
sideOffset: miniMenuContentDefaults.sideOffset,
|
|
1111
|
+
collisionPadding: miniMenuContentDefaults.collisionPadding,
|
|
1112
|
+
className: cn(miniMenuContentClassName, "min-w-0 w-auto"),
|
|
1113
|
+
children: languages.map(({ key, nativeName }) => /* @__PURE__ */ jsx(
|
|
1114
|
+
DropdownMenuItem,
|
|
1115
|
+
{
|
|
1116
|
+
onClick: () => onLanguageChange?.(key),
|
|
1117
|
+
className: cn(
|
|
1118
|
+
"justify-center text-xs font-semibold cursor-pointer px-3",
|
|
1119
|
+
currentLanguage === key && "bg-accent text-accent-foreground"
|
|
1120
|
+
),
|
|
1121
|
+
children: nativeName
|
|
1122
|
+
},
|
|
1123
|
+
key
|
|
1124
|
+
))
|
|
1125
|
+
}
|
|
1126
|
+
)
|
|
1127
|
+
] });
|
|
1128
|
+
}
|
|
1129
|
+
return /* @__PURE__ */ jsxs(
|
|
1130
|
+
"div",
|
|
1131
|
+
{
|
|
1132
|
+
className: cn(
|
|
1133
|
+
"relative isolate flex items-center bg-background ring-1 ring-border",
|
|
1134
|
+
sizes.container,
|
|
1135
|
+
shapeClass,
|
|
1136
|
+
className
|
|
1137
|
+
),
|
|
1138
|
+
children: [
|
|
1139
|
+
showIcon && /* @__PURE__ */ jsx(
|
|
1140
|
+
Languages,
|
|
1141
|
+
{
|
|
1142
|
+
className: cn(sizes.icon, "ml-1.5 mr-1.5 text-muted-foreground")
|
|
1143
|
+
}
|
|
1144
|
+
),
|
|
1145
|
+
languages.map(({ key, label }) => {
|
|
1146
|
+
const isActive = currentLanguage === key;
|
|
1147
|
+
return /* @__PURE__ */ jsxs(
|
|
1148
|
+
"button",
|
|
1149
|
+
{
|
|
1150
|
+
"aria-label": label,
|
|
1151
|
+
"aria-pressed": isActive,
|
|
1152
|
+
className: cn("relative font-semibold", sizes.button, shapeClass),
|
|
1153
|
+
onClick: () => onLanguageChange?.(key),
|
|
1154
|
+
type: "button",
|
|
1155
|
+
children: [
|
|
1156
|
+
reduceMotion ? isActive ? /* @__PURE__ */ jsx(
|
|
1157
|
+
"div",
|
|
1158
|
+
{
|
|
1159
|
+
className: cn("absolute inset-0 bg-secondary", shapeClass)
|
|
1160
|
+
}
|
|
1161
|
+
) : null : /* @__PURE__ */ jsx(AnimatePresence, { children: isActive && /* @__PURE__ */ jsx(
|
|
1162
|
+
motion.div,
|
|
1163
|
+
{
|
|
1164
|
+
className: cn("absolute inset-0 bg-secondary", shapeClass),
|
|
1165
|
+
layoutId: "activeLanguage",
|
|
1166
|
+
initial: { opacity: 0 },
|
|
1167
|
+
animate: { opacity: 1 },
|
|
1168
|
+
exit: { opacity: 0 },
|
|
1169
|
+
transition: { type: "spring", duration: 0.5 }
|
|
1170
|
+
}
|
|
1171
|
+
) }),
|
|
1172
|
+
/* @__PURE__ */ jsx(
|
|
1173
|
+
"span",
|
|
1174
|
+
{
|
|
1175
|
+
className: cn(
|
|
1176
|
+
"relative z-10",
|
|
1177
|
+
isActive ? "text-foreground" : "text-muted-foreground"
|
|
1178
|
+
),
|
|
1179
|
+
children: label
|
|
1180
|
+
}
|
|
1181
|
+
)
|
|
1182
|
+
]
|
|
1183
|
+
},
|
|
1184
|
+
key
|
|
1185
|
+
);
|
|
1186
|
+
})
|
|
1187
|
+
]
|
|
1188
|
+
}
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
function Slider({
|
|
1192
|
+
className,
|
|
1193
|
+
defaultValue,
|
|
1194
|
+
value,
|
|
1195
|
+
min = 0,
|
|
1196
|
+
max = 100,
|
|
1197
|
+
...props
|
|
1198
|
+
}) {
|
|
1199
|
+
const _values = React3.useMemo(
|
|
1200
|
+
() => Array.isArray(value) ? value : Array.isArray(defaultValue) ? defaultValue : [min, max],
|
|
1201
|
+
[value, defaultValue, min, max]
|
|
1202
|
+
);
|
|
1203
|
+
return /* @__PURE__ */ jsxs(
|
|
1204
|
+
SliderPrimitive.Root,
|
|
1205
|
+
{
|
|
1206
|
+
"data-slot": "slider",
|
|
1207
|
+
defaultValue,
|
|
1208
|
+
value,
|
|
1209
|
+
min,
|
|
1210
|
+
max,
|
|
1211
|
+
className: cn(
|
|
1212
|
+
"relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",
|
|
1213
|
+
className
|
|
1214
|
+
),
|
|
1215
|
+
...props,
|
|
1216
|
+
children: [
|
|
1217
|
+
/* @__PURE__ */ jsx(
|
|
1218
|
+
SliderPrimitive.Track,
|
|
1219
|
+
{
|
|
1220
|
+
"data-slot": "slider-track",
|
|
1221
|
+
className: cn(
|
|
1222
|
+
"bg-muted relative grow overflow-hidden rounded-full data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"
|
|
1223
|
+
),
|
|
1224
|
+
children: /* @__PURE__ */ jsx(
|
|
1225
|
+
SliderPrimitive.Range,
|
|
1226
|
+
{
|
|
1227
|
+
"data-slot": "slider-range",
|
|
1228
|
+
className: cn(
|
|
1229
|
+
"bg-primary absolute data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full"
|
|
1230
|
+
)
|
|
1231
|
+
}
|
|
1232
|
+
)
|
|
1233
|
+
}
|
|
1234
|
+
),
|
|
1235
|
+
Array.from({ length: _values.length }, (_, index) => /* @__PURE__ */ jsx(
|
|
1236
|
+
SliderPrimitive.Thumb,
|
|
1237
|
+
{
|
|
1238
|
+
"data-slot": "slider-thumb",
|
|
1239
|
+
className: "border-primary ring-ring/50 block size-4 shrink-0 rounded-full border bg-white shadow-sm transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"
|
|
1240
|
+
},
|
|
1241
|
+
index
|
|
1242
|
+
))
|
|
1243
|
+
]
|
|
1244
|
+
}
|
|
1245
|
+
);
|
|
1246
|
+
}
|
|
1247
|
+
var toggleVariants = cva(
|
|
1248
|
+
"inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium hover:bg-muted hover:text-muted-foreground disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 [&_svg]:shrink-0 focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] outline-none transition-[color,box-shadow] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive whitespace-nowrap",
|
|
1249
|
+
{
|
|
1250
|
+
variants: {
|
|
1251
|
+
variant: {
|
|
1252
|
+
default: "bg-transparent",
|
|
1253
|
+
outline: "border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground"
|
|
1254
|
+
},
|
|
1255
|
+
size: {
|
|
1256
|
+
default: "h-9 px-2 min-w-9",
|
|
1257
|
+
sm: "h-8 px-1.5 min-w-8",
|
|
1258
|
+
lg: "h-10 px-2.5 min-w-10"
|
|
1259
|
+
}
|
|
1260
|
+
},
|
|
1261
|
+
defaultVariants: {
|
|
1262
|
+
variant: "default",
|
|
1263
|
+
size: "default"
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1266
|
+
);
|
|
1267
|
+
function Toggle({
|
|
1268
|
+
className,
|
|
1269
|
+
variant,
|
|
1270
|
+
size,
|
|
1271
|
+
...props
|
|
1272
|
+
}) {
|
|
1273
|
+
return /* @__PURE__ */ jsx(
|
|
1274
|
+
TogglePrimitive.Root,
|
|
1275
|
+
{
|
|
1276
|
+
"data-slot": "toggle",
|
|
1277
|
+
className: cn(toggleVariants({ variant, size, className })),
|
|
1278
|
+
...props
|
|
1279
|
+
}
|
|
1280
|
+
);
|
|
1281
|
+
}
|
|
1282
|
+
var DEFAULT_LABELS = {
|
|
1283
|
+
uploadAria: "Upload image",
|
|
1284
|
+
uploadHint: "Click to upload",
|
|
1285
|
+
uploadFormats: "PNG, JPG up to 10MB",
|
|
1286
|
+
dragging: "Dragging",
|
|
1287
|
+
zoomOut: "Zoom out",
|
|
1288
|
+
zoomIn: "Zoom in",
|
|
1289
|
+
zoomLevel: "Zoom level",
|
|
1290
|
+
rotateLeft: "Rotate left 15 degrees",
|
|
1291
|
+
rotateRight: "Rotate right 15 degrees",
|
|
1292
|
+
toggleGrid: "Toggle grid overlay",
|
|
1293
|
+
reset: "Reset all transforms",
|
|
1294
|
+
replace: "Upload new image",
|
|
1295
|
+
discard: "Discard image"
|
|
1296
|
+
};
|
|
1297
|
+
function AvatarEditor({
|
|
1298
|
+
value: _value,
|
|
1299
|
+
onChange,
|
|
1300
|
+
size = 280,
|
|
1301
|
+
showGrid: initialShowGrid = false,
|
|
1302
|
+
outputSize = 256,
|
|
1303
|
+
outputFormat = "png",
|
|
1304
|
+
outputQuality = 0.92,
|
|
1305
|
+
className,
|
|
1306
|
+
controlSize = "default",
|
|
1307
|
+
labels
|
|
1308
|
+
}) {
|
|
1309
|
+
const t = { ...DEFAULT_LABELS, ...labels };
|
|
1310
|
+
const canvasRef = useRef(null);
|
|
1311
|
+
const fileInputRef = useRef(null);
|
|
1312
|
+
const containerRef = useRef(null);
|
|
1313
|
+
const [image, setImage] = useState(null);
|
|
1314
|
+
const [imageLoaded, setImageLoaded] = useState(false);
|
|
1315
|
+
const [zoom, setZoom] = useState(1);
|
|
1316
|
+
const [rotation, setRotation] = useState(0);
|
|
1317
|
+
const [position, setPosition] = useState({ x: 0, y: 0 });
|
|
1318
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
1319
|
+
const [dragStart, setDragStart] = useState({ x: 0, y: 0 });
|
|
1320
|
+
const [showGrid, setShowGrid] = useState(initialShowGrid);
|
|
1321
|
+
const generateOutput = useCallback(() => {
|
|
1322
|
+
if (!canvasRef.current || !image) return null;
|
|
1323
|
+
const outputCanvas = document.createElement("canvas");
|
|
1324
|
+
outputCanvas.width = outputSize;
|
|
1325
|
+
outputCanvas.height = outputSize;
|
|
1326
|
+
const ctx = outputCanvas.getContext("2d");
|
|
1327
|
+
if (!ctx) return null;
|
|
1328
|
+
ctx.drawImage(canvasRef.current, 0, 0, outputSize, outputSize);
|
|
1329
|
+
const mimeType = `image/${outputFormat}`;
|
|
1330
|
+
return outputCanvas.toDataURL(mimeType, outputQuality);
|
|
1331
|
+
}, [image, outputSize, outputFormat, outputQuality]);
|
|
1332
|
+
useEffect(() => {
|
|
1333
|
+
if (!canvasRef.current || !image || !imageLoaded) return;
|
|
1334
|
+
const canvas = canvasRef.current;
|
|
1335
|
+
const ctx = canvas.getContext("2d");
|
|
1336
|
+
if (!ctx) return;
|
|
1337
|
+
const displaySize = size;
|
|
1338
|
+
canvas.width = displaySize;
|
|
1339
|
+
canvas.height = displaySize;
|
|
1340
|
+
ctx.clearRect(0, 0, displaySize, displaySize);
|
|
1341
|
+
ctx.save();
|
|
1342
|
+
ctx.translate(displaySize / 2, displaySize / 2);
|
|
1343
|
+
ctx.rotate(rotation * Math.PI / 180);
|
|
1344
|
+
const scale = zoom;
|
|
1345
|
+
const imgAspect = image.width / image.height;
|
|
1346
|
+
let drawWidth, drawHeight;
|
|
1347
|
+
if (imgAspect > 1) {
|
|
1348
|
+
drawHeight = displaySize * scale;
|
|
1349
|
+
drawWidth = drawHeight * imgAspect;
|
|
1350
|
+
} else {
|
|
1351
|
+
drawWidth = displaySize * scale;
|
|
1352
|
+
drawHeight = drawWidth / imgAspect;
|
|
1353
|
+
}
|
|
1354
|
+
ctx.drawImage(
|
|
1355
|
+
image,
|
|
1356
|
+
-drawWidth / 2 + position.x,
|
|
1357
|
+
-drawHeight / 2 + position.y,
|
|
1358
|
+
drawWidth,
|
|
1359
|
+
drawHeight
|
|
1360
|
+
);
|
|
1361
|
+
ctx.restore();
|
|
1362
|
+
const dataUrl = generateOutput();
|
|
1363
|
+
if (dataUrl) {
|
|
1364
|
+
onChange?.(dataUrl);
|
|
1365
|
+
}
|
|
1366
|
+
}, [
|
|
1367
|
+
image,
|
|
1368
|
+
imageLoaded,
|
|
1369
|
+
zoom,
|
|
1370
|
+
rotation,
|
|
1371
|
+
position,
|
|
1372
|
+
size,
|
|
1373
|
+
generateOutput,
|
|
1374
|
+
onChange
|
|
1375
|
+
]);
|
|
1376
|
+
const resetTransforms = useCallback(() => {
|
|
1377
|
+
setZoom(1);
|
|
1378
|
+
setRotation(0);
|
|
1379
|
+
setPosition({ x: 0, y: 0 });
|
|
1380
|
+
}, []);
|
|
1381
|
+
const handleFileSelect = useCallback(
|
|
1382
|
+
(e) => {
|
|
1383
|
+
const file = e.target.files?.[0];
|
|
1384
|
+
if (!file) return;
|
|
1385
|
+
const reader = new FileReader();
|
|
1386
|
+
reader.onload = (event) => {
|
|
1387
|
+
const img = new Image();
|
|
1388
|
+
img.crossOrigin = "anonymous";
|
|
1389
|
+
img.onload = () => {
|
|
1390
|
+
setImage(img);
|
|
1391
|
+
setImageLoaded(true);
|
|
1392
|
+
resetTransforms();
|
|
1393
|
+
};
|
|
1394
|
+
img.src = event.target?.result;
|
|
1395
|
+
};
|
|
1396
|
+
reader.readAsDataURL(file);
|
|
1397
|
+
},
|
|
1398
|
+
[resetTransforms]
|
|
1399
|
+
);
|
|
1400
|
+
const handleMouseDown = useCallback(
|
|
1401
|
+
(e) => {
|
|
1402
|
+
if (!imageLoaded) return;
|
|
1403
|
+
setIsDragging(true);
|
|
1404
|
+
setDragStart({ x: e.clientX - position.x, y: e.clientY - position.y });
|
|
1405
|
+
},
|
|
1406
|
+
[imageLoaded, position]
|
|
1407
|
+
);
|
|
1408
|
+
const handleMouseMove = useCallback(
|
|
1409
|
+
(e) => {
|
|
1410
|
+
if (!isDragging) return;
|
|
1411
|
+
setPosition({
|
|
1412
|
+
x: e.clientX - dragStart.x,
|
|
1413
|
+
y: e.clientY - dragStart.y
|
|
1414
|
+
});
|
|
1415
|
+
},
|
|
1416
|
+
[isDragging, dragStart]
|
|
1417
|
+
);
|
|
1418
|
+
const handleMouseUp = useCallback(() => {
|
|
1419
|
+
setIsDragging(false);
|
|
1420
|
+
}, []);
|
|
1421
|
+
const handleTouchStart = useCallback(
|
|
1422
|
+
(e) => {
|
|
1423
|
+
if (!imageLoaded) return;
|
|
1424
|
+
const touch = e.touches[0];
|
|
1425
|
+
setIsDragging(true);
|
|
1426
|
+
setDragStart({
|
|
1427
|
+
x: touch.clientX - position.x,
|
|
1428
|
+
y: touch.clientY - position.y
|
|
1429
|
+
});
|
|
1430
|
+
},
|
|
1431
|
+
[imageLoaded, position]
|
|
1432
|
+
);
|
|
1433
|
+
const handleTouchMove = useCallback(
|
|
1434
|
+
(e) => {
|
|
1435
|
+
if (!isDragging) return;
|
|
1436
|
+
const touch = e.touches[0];
|
|
1437
|
+
setPosition({
|
|
1438
|
+
x: touch.clientX - dragStart.x,
|
|
1439
|
+
y: touch.clientY - dragStart.y
|
|
1440
|
+
});
|
|
1441
|
+
},
|
|
1442
|
+
[isDragging, dragStart]
|
|
1443
|
+
);
|
|
1444
|
+
const handleDiscard = useCallback(() => {
|
|
1445
|
+
setImage(null);
|
|
1446
|
+
setImageLoaded(false);
|
|
1447
|
+
resetTransforms();
|
|
1448
|
+
if (fileInputRef.current) {
|
|
1449
|
+
fileInputRef.current.value = "";
|
|
1450
|
+
}
|
|
1451
|
+
onChange?.(null);
|
|
1452
|
+
}, [resetTransforms, onChange]);
|
|
1453
|
+
const handleZoomIn = () => setZoom((z) => Math.min(z + 0.1, 3));
|
|
1454
|
+
const handleZoomOut = () => setZoom((z) => Math.max(z - 0.1, 0.5));
|
|
1455
|
+
const handleRotateLeft = () => setRotation((r) => r - 15);
|
|
1456
|
+
const handleRotateRight = () => setRotation((r) => r + 15);
|
|
1457
|
+
const isLarge = controlSize === "large";
|
|
1458
|
+
const buttonSize = isLarge ? "h-12 w-12" : "h-8 w-8";
|
|
1459
|
+
const iconSize = isLarge ? "w-6 h-6" : "w-4 h-4";
|
|
1460
|
+
const smallIconSize = isLarge ? "w-5 h-5" : "w-3 h-3";
|
|
1461
|
+
const textSize = isLarge ? "text-sm" : "text-xs";
|
|
1462
|
+
const uploadIconSize = isLarge ? "w-12 h-12" : "w-8 h-8";
|
|
1463
|
+
const uploadContainerSize = isLarge ? "w-24 h-24" : "w-16 h-16";
|
|
1464
|
+
const gapSize = isLarge ? "gap-6" : "gap-4";
|
|
1465
|
+
const controlGap = isLarge ? "gap-3" : "gap-2";
|
|
1466
|
+
const sliderHeight = isLarge ? "[&_[role=slider]]:h-6 [&_[role=slider]]:w-6" : "";
|
|
1467
|
+
const guideRadius = size / 2 - 2;
|
|
1468
|
+
const guideCenter = size / 2;
|
|
1469
|
+
return /* @__PURE__ */ jsxs(
|
|
1470
|
+
"div",
|
|
1471
|
+
{
|
|
1472
|
+
className: cn("flex flex-col", gapSize, className),
|
|
1473
|
+
style: { width: size },
|
|
1474
|
+
children: [
|
|
1475
|
+
/* @__PURE__ */ jsxs(
|
|
1476
|
+
"div",
|
|
1477
|
+
{
|
|
1478
|
+
ref: containerRef,
|
|
1479
|
+
className: "relative bg-muted rounded-2xl overflow-hidden",
|
|
1480
|
+
style: { width: size, height: size },
|
|
1481
|
+
children: [
|
|
1482
|
+
!imageLoaded && /* @__PURE__ */ jsxs(
|
|
1483
|
+
"button",
|
|
1484
|
+
{
|
|
1485
|
+
onClick: () => fileInputRef.current?.click(),
|
|
1486
|
+
className: cn(
|
|
1487
|
+
"absolute inset-0 z-10 flex flex-col items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted/80 transition-colors cursor-pointer",
|
|
1488
|
+
isLarge ? "gap-4" : "gap-3"
|
|
1489
|
+
),
|
|
1490
|
+
"aria-label": t.uploadAria,
|
|
1491
|
+
type: "button",
|
|
1492
|
+
children: [
|
|
1493
|
+
/* @__PURE__ */ jsx(
|
|
1494
|
+
"div",
|
|
1495
|
+
{
|
|
1496
|
+
className: cn(
|
|
1497
|
+
"rounded-full bg-primary/10 flex items-center justify-center",
|
|
1498
|
+
uploadContainerSize
|
|
1499
|
+
),
|
|
1500
|
+
children: /* @__PURE__ */ jsx(Upload, { className: cn("text-primary", uploadIconSize) })
|
|
1501
|
+
}
|
|
1502
|
+
),
|
|
1503
|
+
/* @__PURE__ */ jsx(
|
|
1504
|
+
"span",
|
|
1505
|
+
{
|
|
1506
|
+
className: cn("font-medium", isLarge ? "text-base" : "text-sm"),
|
|
1507
|
+
children: t.uploadHint
|
|
1508
|
+
}
|
|
1509
|
+
),
|
|
1510
|
+
/* @__PURE__ */ jsx("span", { className: cn("text-muted-foreground", textSize), children: t.uploadFormats })
|
|
1511
|
+
]
|
|
1512
|
+
}
|
|
1513
|
+
),
|
|
1514
|
+
/* @__PURE__ */ jsx(
|
|
1515
|
+
"canvas",
|
|
1516
|
+
{
|
|
1517
|
+
ref: canvasRef,
|
|
1518
|
+
className: cn(
|
|
1519
|
+
"absolute inset-0",
|
|
1520
|
+
imageLoaded ? "cursor-move" : "pointer-events-none opacity-0"
|
|
1521
|
+
),
|
|
1522
|
+
style: { width: size, height: size },
|
|
1523
|
+
onMouseDown: handleMouseDown,
|
|
1524
|
+
onMouseMove: handleMouseMove,
|
|
1525
|
+
onMouseUp: handleMouseUp,
|
|
1526
|
+
onMouseLeave: handleMouseUp,
|
|
1527
|
+
onTouchStart: handleTouchStart,
|
|
1528
|
+
onTouchMove: handleTouchMove,
|
|
1529
|
+
onTouchEnd: handleMouseUp
|
|
1530
|
+
}
|
|
1531
|
+
),
|
|
1532
|
+
imageLoaded && /* @__PURE__ */ jsxs(
|
|
1533
|
+
"svg",
|
|
1534
|
+
{
|
|
1535
|
+
width: size,
|
|
1536
|
+
height: size,
|
|
1537
|
+
className: "pointer-events-none absolute inset-0",
|
|
1538
|
+
"aria-hidden": "true",
|
|
1539
|
+
children: [
|
|
1540
|
+
/* @__PURE__ */ jsx(
|
|
1541
|
+
"path",
|
|
1542
|
+
{
|
|
1543
|
+
d: `M0 0H${size}V${size}H0Z M${guideCenter - guideRadius} ${guideCenter}a${guideRadius} ${guideRadius} 0 1 0 ${guideRadius * 2} 0a${guideRadius} ${guideRadius} 0 1 0 ${-guideRadius * 2} 0`,
|
|
1544
|
+
fill: "rgb(0 0 0 / 0.45)",
|
|
1545
|
+
fillRule: "evenodd"
|
|
1546
|
+
}
|
|
1547
|
+
),
|
|
1548
|
+
/* @__PURE__ */ jsx(
|
|
1549
|
+
"circle",
|
|
1550
|
+
{
|
|
1551
|
+
cx: guideCenter,
|
|
1552
|
+
cy: guideCenter,
|
|
1553
|
+
r: guideRadius,
|
|
1554
|
+
fill: "none",
|
|
1555
|
+
stroke: "hsl(var(--primary))",
|
|
1556
|
+
strokeWidth: "3"
|
|
1557
|
+
}
|
|
1558
|
+
)
|
|
1559
|
+
]
|
|
1560
|
+
}
|
|
1561
|
+
),
|
|
1562
|
+
showGrid && imageLoaded && /* @__PURE__ */ jsx(
|
|
1563
|
+
"div",
|
|
1564
|
+
{
|
|
1565
|
+
className: "absolute inset-0 pointer-events-none",
|
|
1566
|
+
style: { width: size, height: size },
|
|
1567
|
+
children: /* @__PURE__ */ jsxs("svg", { width: size, height: size, className: "opacity-30", children: [
|
|
1568
|
+
/* @__PURE__ */ jsx(
|
|
1569
|
+
"line",
|
|
1570
|
+
{
|
|
1571
|
+
x1: size / 3,
|
|
1572
|
+
y1: 0,
|
|
1573
|
+
x2: size / 3,
|
|
1574
|
+
y2: size,
|
|
1575
|
+
stroke: "white",
|
|
1576
|
+
strokeWidth: "1"
|
|
1577
|
+
}
|
|
1578
|
+
),
|
|
1579
|
+
/* @__PURE__ */ jsx(
|
|
1580
|
+
"line",
|
|
1581
|
+
{
|
|
1582
|
+
x1: size * 2 / 3,
|
|
1583
|
+
y1: 0,
|
|
1584
|
+
x2: size * 2 / 3,
|
|
1585
|
+
y2: size,
|
|
1586
|
+
stroke: "white",
|
|
1587
|
+
strokeWidth: "1"
|
|
1588
|
+
}
|
|
1589
|
+
),
|
|
1590
|
+
/* @__PURE__ */ jsx(
|
|
1591
|
+
"line",
|
|
1592
|
+
{
|
|
1593
|
+
x1: 0,
|
|
1594
|
+
y1: size / 3,
|
|
1595
|
+
x2: size,
|
|
1596
|
+
y2: size / 3,
|
|
1597
|
+
stroke: "white",
|
|
1598
|
+
strokeWidth: "1"
|
|
1599
|
+
}
|
|
1600
|
+
),
|
|
1601
|
+
/* @__PURE__ */ jsx(
|
|
1602
|
+
"line",
|
|
1603
|
+
{
|
|
1604
|
+
x1: 0,
|
|
1605
|
+
y1: size * 2 / 3,
|
|
1606
|
+
x2: size,
|
|
1607
|
+
y2: size * 2 / 3,
|
|
1608
|
+
stroke: "white",
|
|
1609
|
+
strokeWidth: "1"
|
|
1610
|
+
}
|
|
1611
|
+
),
|
|
1612
|
+
/* @__PURE__ */ jsx(
|
|
1613
|
+
"line",
|
|
1614
|
+
{
|
|
1615
|
+
x1: size / 2 - 10,
|
|
1616
|
+
y1: size / 2,
|
|
1617
|
+
x2: size / 2 + 10,
|
|
1618
|
+
y2: size / 2,
|
|
1619
|
+
stroke: "white",
|
|
1620
|
+
strokeWidth: "1"
|
|
1621
|
+
}
|
|
1622
|
+
),
|
|
1623
|
+
/* @__PURE__ */ jsx(
|
|
1624
|
+
"line",
|
|
1625
|
+
{
|
|
1626
|
+
x1: size / 2,
|
|
1627
|
+
y1: size / 2 - 10,
|
|
1628
|
+
x2: size / 2,
|
|
1629
|
+
y2: size / 2 + 10,
|
|
1630
|
+
stroke: "white",
|
|
1631
|
+
strokeWidth: "1"
|
|
1632
|
+
}
|
|
1633
|
+
)
|
|
1634
|
+
] })
|
|
1635
|
+
}
|
|
1636
|
+
),
|
|
1637
|
+
imageLoaded && isDragging && /* @__PURE__ */ jsxs(
|
|
1638
|
+
"div",
|
|
1639
|
+
{
|
|
1640
|
+
className: cn(
|
|
1641
|
+
"absolute top-2 left-1/2 -translate-x-1/2 bg-black/60 rounded text-white flex items-center",
|
|
1642
|
+
isLarge ? "px-3 py-2 text-sm gap-2" : "px-2 py-1 text-xs gap-1"
|
|
1643
|
+
),
|
|
1644
|
+
children: [
|
|
1645
|
+
/* @__PURE__ */ jsx(Move, { className: smallIconSize }),
|
|
1646
|
+
t.dragging
|
|
1647
|
+
]
|
|
1648
|
+
}
|
|
1649
|
+
)
|
|
1650
|
+
]
|
|
1651
|
+
}
|
|
1652
|
+
),
|
|
1653
|
+
imageLoaded && /* @__PURE__ */ jsxs("div", { className: cn("space-y-4", isLarge && "space-y-5"), children: [
|
|
1654
|
+
/* @__PURE__ */ jsxs("div", { className: cn("flex items-center", controlGap), children: [
|
|
1655
|
+
/* @__PURE__ */ jsx(
|
|
1656
|
+
Button,
|
|
1657
|
+
{
|
|
1658
|
+
variant: "ghost",
|
|
1659
|
+
size: "icon",
|
|
1660
|
+
className: cn(buttonSize, "shrink-0"),
|
|
1661
|
+
onClick: handleZoomOut,
|
|
1662
|
+
"aria-label": t.zoomOut,
|
|
1663
|
+
type: "button",
|
|
1664
|
+
children: /* @__PURE__ */ jsx(ZoomOut, { className: iconSize })
|
|
1665
|
+
}
|
|
1666
|
+
),
|
|
1667
|
+
/* @__PURE__ */ jsx(
|
|
1668
|
+
Slider,
|
|
1669
|
+
{
|
|
1670
|
+
value: [zoom],
|
|
1671
|
+
onValueChange: ([v]) => setZoom(v),
|
|
1672
|
+
min: 0.5,
|
|
1673
|
+
max: 3,
|
|
1674
|
+
step: 0.01,
|
|
1675
|
+
className: cn("flex-1", sliderHeight),
|
|
1676
|
+
"aria-label": t.zoomLevel
|
|
1677
|
+
}
|
|
1678
|
+
),
|
|
1679
|
+
/* @__PURE__ */ jsx(
|
|
1680
|
+
Button,
|
|
1681
|
+
{
|
|
1682
|
+
variant: "ghost",
|
|
1683
|
+
size: "icon",
|
|
1684
|
+
className: cn(buttonSize, "shrink-0"),
|
|
1685
|
+
onClick: handleZoomIn,
|
|
1686
|
+
"aria-label": t.zoomIn,
|
|
1687
|
+
type: "button",
|
|
1688
|
+
children: /* @__PURE__ */ jsx(ZoomIn, { className: iconSize })
|
|
1689
|
+
}
|
|
1690
|
+
)
|
|
1691
|
+
] }),
|
|
1692
|
+
/* @__PURE__ */ jsxs("div", { className: cn("flex items-center justify-between", controlGap), children: [
|
|
1693
|
+
/* @__PURE__ */ jsxs(
|
|
1694
|
+
"div",
|
|
1695
|
+
{
|
|
1696
|
+
className: cn("flex items-center", isLarge ? "gap-2" : "gap-1"),
|
|
1697
|
+
children: [
|
|
1698
|
+
/* @__PURE__ */ jsx(
|
|
1699
|
+
Button,
|
|
1700
|
+
{
|
|
1701
|
+
variant: "ghost",
|
|
1702
|
+
size: "icon",
|
|
1703
|
+
className: buttonSize,
|
|
1704
|
+
onClick: handleRotateLeft,
|
|
1705
|
+
"aria-label": t.rotateLeft,
|
|
1706
|
+
type: "button",
|
|
1707
|
+
children: /* @__PURE__ */ jsx(RotateCcw, { className: iconSize })
|
|
1708
|
+
}
|
|
1709
|
+
),
|
|
1710
|
+
/* @__PURE__ */ jsxs(
|
|
1711
|
+
"span",
|
|
1712
|
+
{
|
|
1713
|
+
className: cn(
|
|
1714
|
+
"text-muted-foreground text-center tabular-nums",
|
|
1715
|
+
textSize,
|
|
1716
|
+
isLarge ? "w-16" : "w-12"
|
|
1717
|
+
),
|
|
1718
|
+
children: [
|
|
1719
|
+
rotation,
|
|
1720
|
+
"\xB0"
|
|
1721
|
+
]
|
|
1722
|
+
}
|
|
1723
|
+
),
|
|
1724
|
+
/* @__PURE__ */ jsx(
|
|
1725
|
+
Button,
|
|
1726
|
+
{
|
|
1727
|
+
variant: "ghost",
|
|
1728
|
+
size: "icon",
|
|
1729
|
+
className: buttonSize,
|
|
1730
|
+
onClick: handleRotateRight,
|
|
1731
|
+
"aria-label": t.rotateRight,
|
|
1732
|
+
type: "button",
|
|
1733
|
+
children: /* @__PURE__ */ jsx(RotateCw, { className: iconSize })
|
|
1734
|
+
}
|
|
1735
|
+
)
|
|
1736
|
+
]
|
|
1737
|
+
}
|
|
1738
|
+
),
|
|
1739
|
+
/* @__PURE__ */ jsxs(
|
|
1740
|
+
"div",
|
|
1741
|
+
{
|
|
1742
|
+
className: cn("flex items-center", isLarge ? "gap-2" : "gap-1"),
|
|
1743
|
+
children: [
|
|
1744
|
+
/* @__PURE__ */ jsx(
|
|
1745
|
+
Toggle,
|
|
1746
|
+
{
|
|
1747
|
+
pressed: showGrid,
|
|
1748
|
+
onPressedChange: setShowGrid,
|
|
1749
|
+
size: "sm",
|
|
1750
|
+
className: cn(buttonSize, "p-0"),
|
|
1751
|
+
"aria-label": t.toggleGrid,
|
|
1752
|
+
children: /* @__PURE__ */ jsx(Grid3X3, { className: iconSize })
|
|
1753
|
+
}
|
|
1754
|
+
),
|
|
1755
|
+
/* @__PURE__ */ jsx(
|
|
1756
|
+
Button,
|
|
1757
|
+
{
|
|
1758
|
+
variant: "ghost",
|
|
1759
|
+
size: "icon",
|
|
1760
|
+
className: buttonSize,
|
|
1761
|
+
onClick: resetTransforms,
|
|
1762
|
+
"aria-label": t.reset,
|
|
1763
|
+
type: "button",
|
|
1764
|
+
children: /* @__PURE__ */ jsx(RefreshCw, { className: iconSize })
|
|
1765
|
+
}
|
|
1766
|
+
),
|
|
1767
|
+
/* @__PURE__ */ jsx(
|
|
1768
|
+
Button,
|
|
1769
|
+
{
|
|
1770
|
+
variant: "ghost",
|
|
1771
|
+
size: "icon",
|
|
1772
|
+
className: buttonSize,
|
|
1773
|
+
onClick: () => fileInputRef.current?.click(),
|
|
1774
|
+
"aria-label": t.replace,
|
|
1775
|
+
type: "button",
|
|
1776
|
+
children: /* @__PURE__ */ jsx(Upload, { className: iconSize })
|
|
1777
|
+
}
|
|
1778
|
+
),
|
|
1779
|
+
/* @__PURE__ */ jsx(
|
|
1780
|
+
Button,
|
|
1781
|
+
{
|
|
1782
|
+
variant: "ghost",
|
|
1783
|
+
size: "icon",
|
|
1784
|
+
className: cn(
|
|
1785
|
+
buttonSize,
|
|
1786
|
+
"text-destructive hover:text-destructive hover:bg-destructive/10"
|
|
1787
|
+
),
|
|
1788
|
+
onClick: handleDiscard,
|
|
1789
|
+
"aria-label": t.discard,
|
|
1790
|
+
type: "button",
|
|
1791
|
+
children: /* @__PURE__ */ jsx(X, { className: iconSize })
|
|
1792
|
+
}
|
|
1793
|
+
)
|
|
1794
|
+
]
|
|
1795
|
+
}
|
|
1796
|
+
)
|
|
1797
|
+
] })
|
|
1798
|
+
] }),
|
|
1799
|
+
/* @__PURE__ */ jsx(
|
|
1800
|
+
"input",
|
|
1801
|
+
{
|
|
1802
|
+
ref: fileInputRef,
|
|
1803
|
+
type: "file",
|
|
1804
|
+
accept: "image/*",
|
|
1805
|
+
onChange: handleFileSelect,
|
|
1806
|
+
className: "hidden",
|
|
1807
|
+
"aria-hidden": "true"
|
|
1808
|
+
}
|
|
1809
|
+
)
|
|
1810
|
+
]
|
|
1811
|
+
}
|
|
1812
|
+
);
|
|
1813
|
+
}
|
|
1814
|
+
function Dialog({
|
|
1815
|
+
...props
|
|
1816
|
+
}) {
|
|
1817
|
+
return /* @__PURE__ */ jsx(DialogPrimitive.Root, { "data-slot": "dialog", ...props });
|
|
1818
|
+
}
|
|
1819
|
+
function DialogPortal({
|
|
1820
|
+
...props
|
|
1821
|
+
}) {
|
|
1822
|
+
return /* @__PURE__ */ jsx(DialogPrimitive.Portal, { "data-slot": "dialog-portal", ...props });
|
|
1823
|
+
}
|
|
1824
|
+
function DialogClose({
|
|
1825
|
+
...props
|
|
1826
|
+
}) {
|
|
1827
|
+
return /* @__PURE__ */ jsx(DialogPrimitive.Close, { "data-slot": "dialog-close", ...props });
|
|
1828
|
+
}
|
|
1829
|
+
function DialogOverlay({
|
|
1830
|
+
className,
|
|
1831
|
+
...props
|
|
1832
|
+
}) {
|
|
1833
|
+
return /* @__PURE__ */ jsx(
|
|
1834
|
+
DialogPrimitive.Overlay,
|
|
1835
|
+
{
|
|
1836
|
+
"data-slot": "dialog-overlay",
|
|
1837
|
+
className: cn(
|
|
1838
|
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
|
1839
|
+
className
|
|
1840
|
+
),
|
|
1841
|
+
...props
|
|
1842
|
+
}
|
|
1843
|
+
);
|
|
1844
|
+
}
|
|
1845
|
+
function DialogContent({
|
|
1846
|
+
className,
|
|
1847
|
+
children,
|
|
1848
|
+
showCloseButton = true,
|
|
1849
|
+
...props
|
|
1850
|
+
}) {
|
|
1851
|
+
return /* @__PURE__ */ jsxs(DialogPortal, { "data-slot": "dialog-portal", children: [
|
|
1852
|
+
/* @__PURE__ */ jsx(DialogOverlay, {}),
|
|
1853
|
+
/* @__PURE__ */ jsxs(
|
|
1854
|
+
DialogPrimitive.Content,
|
|
1855
|
+
{
|
|
1856
|
+
"data-slot": "dialog-content",
|
|
1857
|
+
className: cn(
|
|
1858
|
+
"bg-background data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border p-6 shadow-lg duration-200 outline-none sm:max-w-lg",
|
|
1859
|
+
className
|
|
1860
|
+
),
|
|
1861
|
+
...props,
|
|
1862
|
+
children: [
|
|
1863
|
+
children,
|
|
1864
|
+
showCloseButton && /* @__PURE__ */ jsxs(
|
|
1865
|
+
DialogPrimitive.Close,
|
|
1866
|
+
{
|
|
1867
|
+
"data-slot": "dialog-close",
|
|
1868
|
+
className: "ring-offset-background focus:ring-ring data-[state=open]:bg-accent data-[state=open]:text-muted-foreground absolute top-4 right-4 rounded-xs opacity-70 transition-opacity hover:opacity-100 focus:ring-2 focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
1869
|
+
children: [
|
|
1870
|
+
/* @__PURE__ */ jsx(XIcon, {}),
|
|
1871
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
|
|
1872
|
+
]
|
|
1873
|
+
}
|
|
1874
|
+
)
|
|
1875
|
+
]
|
|
1876
|
+
}
|
|
1877
|
+
)
|
|
1878
|
+
] });
|
|
1879
|
+
}
|
|
1880
|
+
function DialogHeader({ className, ...props }) {
|
|
1881
|
+
return /* @__PURE__ */ jsx(
|
|
1882
|
+
"div",
|
|
1883
|
+
{
|
|
1884
|
+
"data-slot": "dialog-header",
|
|
1885
|
+
className: cn("flex flex-col gap-2 text-center sm:text-left", className),
|
|
1886
|
+
...props
|
|
1887
|
+
}
|
|
1888
|
+
);
|
|
1889
|
+
}
|
|
1890
|
+
function DialogFooter({ className, ...props }) {
|
|
1891
|
+
return /* @__PURE__ */ jsx(
|
|
1892
|
+
"div",
|
|
1893
|
+
{
|
|
1894
|
+
"data-slot": "dialog-footer",
|
|
1895
|
+
className: cn(
|
|
1896
|
+
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
|
1897
|
+
className
|
|
1898
|
+
),
|
|
1899
|
+
...props
|
|
1900
|
+
}
|
|
1901
|
+
);
|
|
1902
|
+
}
|
|
1903
|
+
function DialogTitle({
|
|
1904
|
+
className,
|
|
1905
|
+
...props
|
|
1906
|
+
}) {
|
|
1907
|
+
return /* @__PURE__ */ jsx(
|
|
1908
|
+
DialogPrimitive.Title,
|
|
1909
|
+
{
|
|
1910
|
+
"data-slot": "dialog-title",
|
|
1911
|
+
className: cn("text-lg leading-none font-semibold", className),
|
|
1912
|
+
...props
|
|
1913
|
+
}
|
|
1914
|
+
);
|
|
1915
|
+
}
|
|
1916
|
+
function Drawer({
|
|
1917
|
+
...props
|
|
1918
|
+
}) {
|
|
1919
|
+
return /* @__PURE__ */ jsx(Drawer$1.Root, { "data-slot": "drawer", ...props });
|
|
1920
|
+
}
|
|
1921
|
+
function DrawerPortal({
|
|
1922
|
+
...props
|
|
1923
|
+
}) {
|
|
1924
|
+
return /* @__PURE__ */ jsx(Drawer$1.Portal, { "data-slot": "drawer-portal", ...props });
|
|
1925
|
+
}
|
|
1926
|
+
function DrawerClose({
|
|
1927
|
+
...props
|
|
1928
|
+
}) {
|
|
1929
|
+
return /* @__PURE__ */ jsx(Drawer$1.Close, { "data-slot": "drawer-close", ...props });
|
|
1930
|
+
}
|
|
1931
|
+
function DrawerOverlay({
|
|
1932
|
+
className,
|
|
1933
|
+
...props
|
|
1934
|
+
}) {
|
|
1935
|
+
return /* @__PURE__ */ jsx(
|
|
1936
|
+
Drawer$1.Overlay,
|
|
1937
|
+
{
|
|
1938
|
+
"data-slot": "drawer-overlay",
|
|
1939
|
+
className: cn(
|
|
1940
|
+
"data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/50",
|
|
1941
|
+
className
|
|
1942
|
+
),
|
|
1943
|
+
...props
|
|
1944
|
+
}
|
|
1945
|
+
);
|
|
1946
|
+
}
|
|
1947
|
+
function DrawerContent({
|
|
1948
|
+
className,
|
|
1949
|
+
children,
|
|
1950
|
+
...props
|
|
1951
|
+
}) {
|
|
1952
|
+
return /* @__PURE__ */ jsxs(DrawerPortal, { "data-slot": "drawer-portal", children: [
|
|
1953
|
+
/* @__PURE__ */ jsx(DrawerOverlay, {}),
|
|
1954
|
+
/* @__PURE__ */ jsxs(
|
|
1955
|
+
Drawer$1.Content,
|
|
1956
|
+
{
|
|
1957
|
+
"data-slot": "drawer-content",
|
|
1958
|
+
className: cn(
|
|
1959
|
+
"group/drawer-content bg-background fixed z-50 flex h-auto flex-col",
|
|
1960
|
+
"data-[vaul-drawer-direction=top]:inset-x-0 data-[vaul-drawer-direction=top]:top-0 data-[vaul-drawer-direction=top]:mb-24 data-[vaul-drawer-direction=top]:max-h-[80vh] data-[vaul-drawer-direction=top]:rounded-b-lg data-[vaul-drawer-direction=top]:border-b",
|
|
1961
|
+
"data-[vaul-drawer-direction=bottom]:inset-x-0 data-[vaul-drawer-direction=bottom]:bottom-0 data-[vaul-drawer-direction=bottom]:mt-24 data-[vaul-drawer-direction=bottom]:max-h-[80vh] data-[vaul-drawer-direction=bottom]:rounded-t-lg data-[vaul-drawer-direction=bottom]:border-t",
|
|
1962
|
+
"data-[vaul-drawer-direction=right]:inset-y-0 data-[vaul-drawer-direction=right]:right-0 data-[vaul-drawer-direction=right]:w-3/4 data-[vaul-drawer-direction=right]:border-l data-[vaul-drawer-direction=right]:sm:max-w-sm",
|
|
1963
|
+
"data-[vaul-drawer-direction=left]:inset-y-0 data-[vaul-drawer-direction=left]:left-0 data-[vaul-drawer-direction=left]:w-3/4 data-[vaul-drawer-direction=left]:border-r data-[vaul-drawer-direction=left]:sm:max-w-sm",
|
|
1964
|
+
className
|
|
1965
|
+
),
|
|
1966
|
+
...props,
|
|
1967
|
+
children: [
|
|
1968
|
+
/* @__PURE__ */ jsx("div", { className: "bg-muted mx-auto mt-4 hidden h-2 w-[100px] shrink-0 rounded-full group-data-[vaul-drawer-direction=bottom]/drawer-content:block" }),
|
|
1969
|
+
children
|
|
1970
|
+
]
|
|
1971
|
+
}
|
|
1972
|
+
)
|
|
1973
|
+
] });
|
|
1974
|
+
}
|
|
1975
|
+
function DrawerHeader({ className, ...props }) {
|
|
1976
|
+
return /* @__PURE__ */ jsx(
|
|
1977
|
+
"div",
|
|
1978
|
+
{
|
|
1979
|
+
"data-slot": "drawer-header",
|
|
1980
|
+
className: cn(
|
|
1981
|
+
"flex flex-col gap-0.5 p-4 group-data-[vaul-drawer-direction=bottom]/drawer-content:text-center group-data-[vaul-drawer-direction=top]/drawer-content:text-center md:gap-1.5 md:text-left",
|
|
1982
|
+
className
|
|
1983
|
+
),
|
|
1984
|
+
...props
|
|
1985
|
+
}
|
|
1986
|
+
);
|
|
1987
|
+
}
|
|
1988
|
+
function DrawerFooter({ className, ...props }) {
|
|
1989
|
+
return /* @__PURE__ */ jsx(
|
|
1990
|
+
"div",
|
|
1991
|
+
{
|
|
1992
|
+
"data-slot": "drawer-footer",
|
|
1993
|
+
className: cn("mt-auto flex flex-col gap-2 p-4", className),
|
|
1994
|
+
...props
|
|
1995
|
+
}
|
|
1996
|
+
);
|
|
1997
|
+
}
|
|
1998
|
+
function DrawerTitle({
|
|
1999
|
+
className,
|
|
2000
|
+
...props
|
|
2001
|
+
}) {
|
|
2002
|
+
return /* @__PURE__ */ jsx(
|
|
2003
|
+
Drawer$1.Title,
|
|
2004
|
+
{
|
|
2005
|
+
"data-slot": "drawer-title",
|
|
2006
|
+
className: cn("text-foreground font-semibold", className),
|
|
2007
|
+
...props
|
|
2008
|
+
}
|
|
2009
|
+
);
|
|
2010
|
+
}
|
|
2011
|
+
function useMediaQuery(query) {
|
|
2012
|
+
const [matches, setMatches] = useState(false);
|
|
2013
|
+
useEffect(() => {
|
|
2014
|
+
const media = window.matchMedia(query);
|
|
2015
|
+
if (media.matches !== matches) {
|
|
2016
|
+
setMatches(media.matches);
|
|
2017
|
+
}
|
|
2018
|
+
const listener = () => setMatches(media.matches);
|
|
2019
|
+
media.addEventListener("change", listener);
|
|
2020
|
+
return () => media.removeEventListener("change", listener);
|
|
2021
|
+
}, [matches, query]);
|
|
2022
|
+
return matches;
|
|
2023
|
+
}
|
|
2024
|
+
function AvatarEditorDialog({
|
|
2025
|
+
value,
|
|
2026
|
+
onChange,
|
|
2027
|
+
onSave,
|
|
2028
|
+
displaySize = 120,
|
|
2029
|
+
editorSize = 280,
|
|
2030
|
+
outputSize = 256,
|
|
2031
|
+
placeholder = "Add Photo",
|
|
2032
|
+
editLabel = "Edit avatar",
|
|
2033
|
+
dialogTitle = "Edit Avatar",
|
|
2034
|
+
acceptText = "Accept",
|
|
2035
|
+
cancelText = "Cancel",
|
|
2036
|
+
savingText = "Saving...",
|
|
2037
|
+
savedText = "Saved!",
|
|
2038
|
+
successMessage = "Avatar saved successfully!",
|
|
2039
|
+
errorMessage = "Failed to save avatar. Please try again.",
|
|
2040
|
+
className,
|
|
2041
|
+
editorLabels
|
|
2042
|
+
}) {
|
|
2043
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
2044
|
+
const [editedValue, setEditedValue] = useState(value ?? null);
|
|
2045
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
2046
|
+
const [feedback, setFeedback] = useState(null);
|
|
2047
|
+
const isMobile = useMediaQuery("(max-width: 640px)");
|
|
2048
|
+
const caption = (placeholder ?? "").trim();
|
|
2049
|
+
const handleOpenChange = useCallback(
|
|
2050
|
+
(open) => {
|
|
2051
|
+
if (open) {
|
|
2052
|
+
setEditedValue(value ?? null);
|
|
2053
|
+
setFeedback(null);
|
|
2054
|
+
}
|
|
2055
|
+
setIsOpen(open);
|
|
2056
|
+
},
|
|
2057
|
+
[value]
|
|
2058
|
+
);
|
|
2059
|
+
const handleAccept = useCallback(async () => {
|
|
2060
|
+
if (!editedValue) return;
|
|
2061
|
+
setIsSaving(true);
|
|
2062
|
+
setFeedback(null);
|
|
2063
|
+
try {
|
|
2064
|
+
if (onSave) {
|
|
2065
|
+
const result = await onSave(editedValue);
|
|
2066
|
+
if (result) {
|
|
2067
|
+
onChange?.(editedValue);
|
|
2068
|
+
setFeedback({ type: "success", message: successMessage });
|
|
2069
|
+
setTimeout(() => {
|
|
2070
|
+
setIsOpen(false);
|
|
2071
|
+
setFeedback(null);
|
|
2072
|
+
}, 1500);
|
|
2073
|
+
} else {
|
|
2074
|
+
setFeedback({ type: "error", message: errorMessage });
|
|
2075
|
+
}
|
|
2076
|
+
} else {
|
|
2077
|
+
onChange?.(editedValue);
|
|
2078
|
+
setFeedback({ type: "success", message: successMessage });
|
|
2079
|
+
setTimeout(() => {
|
|
2080
|
+
setIsOpen(false);
|
|
2081
|
+
setFeedback(null);
|
|
2082
|
+
}, 1500);
|
|
2083
|
+
}
|
|
2084
|
+
} catch {
|
|
2085
|
+
setFeedback({ type: "error", message: errorMessage });
|
|
2086
|
+
} finally {
|
|
2087
|
+
setIsSaving(false);
|
|
2088
|
+
}
|
|
2089
|
+
}, [editedValue, onChange, onSave, successMessage, errorMessage]);
|
|
2090
|
+
const AvatarDisplay = /* @__PURE__ */ jsxs(
|
|
2091
|
+
"div",
|
|
2092
|
+
{
|
|
2093
|
+
className: cn("relative group", className),
|
|
2094
|
+
style: { width: displaySize, height: displaySize },
|
|
2095
|
+
children: [
|
|
2096
|
+
/* @__PURE__ */ jsx(
|
|
2097
|
+
"div",
|
|
2098
|
+
{
|
|
2099
|
+
className: "relative w-full h-full rounded-full overflow-hidden bg-muted border-2 border-border flex items-center justify-center",
|
|
2100
|
+
style: { width: displaySize, height: displaySize },
|
|
2101
|
+
children: /* @__PURE__ */ jsx(
|
|
2102
|
+
SafeImage,
|
|
2103
|
+
{
|
|
2104
|
+
src: value,
|
|
2105
|
+
alt: "Avatar",
|
|
2106
|
+
className: "absolute object-cover",
|
|
2107
|
+
fallback: /* @__PURE__ */ jsxs(
|
|
2108
|
+
"div",
|
|
2109
|
+
{
|
|
2110
|
+
className: cn(
|
|
2111
|
+
"flex flex-col items-center justify-center text-muted-foreground",
|
|
2112
|
+
caption ? "gap-1" : "gap-0"
|
|
2113
|
+
),
|
|
2114
|
+
children: [
|
|
2115
|
+
/* @__PURE__ */ jsx(
|
|
2116
|
+
User,
|
|
2117
|
+
{
|
|
2118
|
+
className: "h-1/2 w-1/2 max-h-[55%] max-w-[55%] shrink-0",
|
|
2119
|
+
"aria-hidden": true
|
|
2120
|
+
}
|
|
2121
|
+
),
|
|
2122
|
+
caption ? /* @__PURE__ */ jsx("span", { className: "text-xs text-center px-1", children: caption }) : null
|
|
2123
|
+
]
|
|
2124
|
+
}
|
|
2125
|
+
)
|
|
2126
|
+
}
|
|
2127
|
+
)
|
|
2128
|
+
}
|
|
2129
|
+
),
|
|
2130
|
+
/* @__PURE__ */ jsx(
|
|
2131
|
+
"button",
|
|
2132
|
+
{
|
|
2133
|
+
onClick: () => handleOpenChange(true),
|
|
2134
|
+
className: "absolute bottom-0 right-0 w-8 h-8 rounded-full bg-primary text-primary-foreground flex items-center justify-center shadow-lg hover:bg-primary/90 transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2",
|
|
2135
|
+
"aria-label": editLabel,
|
|
2136
|
+
type: "button",
|
|
2137
|
+
children: /* @__PURE__ */ jsx(Pencil, { className: "w-4 h-4" })
|
|
2138
|
+
}
|
|
2139
|
+
)
|
|
2140
|
+
]
|
|
2141
|
+
}
|
|
2142
|
+
);
|
|
2143
|
+
const mobileEditorSize = isMobile ? Math.min(editorSize + 40, window.innerWidth - 48) : editorSize;
|
|
2144
|
+
const EditorContent = /* @__PURE__ */ jsxs("div", { className: "flex flex-col items-center gap-4", children: [
|
|
2145
|
+
/* @__PURE__ */ jsx(
|
|
2146
|
+
AvatarEditor,
|
|
2147
|
+
{
|
|
2148
|
+
value: editedValue,
|
|
2149
|
+
onChange: setEditedValue,
|
|
2150
|
+
size: mobileEditorSize,
|
|
2151
|
+
outputSize,
|
|
2152
|
+
controlSize: isMobile ? "large" : "default",
|
|
2153
|
+
labels: editorLabels
|
|
2154
|
+
}
|
|
2155
|
+
),
|
|
2156
|
+
/* @__PURE__ */ jsx(AnimatePresence, { children: feedback && /* @__PURE__ */ jsxs(
|
|
2157
|
+
motion.div,
|
|
2158
|
+
{
|
|
2159
|
+
initial: { opacity: 0, y: -10 },
|
|
2160
|
+
animate: { opacity: 1, y: 0 },
|
|
2161
|
+
exit: { opacity: 0, y: -10 },
|
|
2162
|
+
className: cn(
|
|
2163
|
+
"flex items-center gap-2 rounded-lg font-medium",
|
|
2164
|
+
isMobile ? "px-5 py-3 text-base" : "px-4 py-2 text-sm",
|
|
2165
|
+
feedback.type === "success" ? "bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-400" : "bg-red-100 text-red-800 dark:bg-red-900/30 dark:text-red-400"
|
|
2166
|
+
),
|
|
2167
|
+
children: [
|
|
2168
|
+
feedback.type === "success" ? /* @__PURE__ */ jsx(Check, { className: isMobile ? "w-5 h-5" : "w-4 h-4" }) : /* @__PURE__ */ jsx(X, { className: isMobile ? "w-5 h-5" : "w-4 h-4" }),
|
|
2169
|
+
feedback.message
|
|
2170
|
+
]
|
|
2171
|
+
}
|
|
2172
|
+
) })
|
|
2173
|
+
] });
|
|
2174
|
+
const FooterButtons = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2175
|
+
isMobile ? /* @__PURE__ */ jsx(DrawerClose, { asChild: true, children: /* @__PURE__ */ jsx(
|
|
2176
|
+
Button,
|
|
2177
|
+
{
|
|
2178
|
+
variant: "outline",
|
|
2179
|
+
disabled: isSaving,
|
|
2180
|
+
size: "lg",
|
|
2181
|
+
className: "flex-1 bg-transparent",
|
|
2182
|
+
children: cancelText
|
|
2183
|
+
}
|
|
2184
|
+
) }) : /* @__PURE__ */ jsx(DialogClose, { asChild: true, children: /* @__PURE__ */ jsx(Button, { variant: "outline", disabled: isSaving, children: cancelText }) }),
|
|
2185
|
+
/* @__PURE__ */ jsx(
|
|
2186
|
+
Button,
|
|
2187
|
+
{
|
|
2188
|
+
onClick: handleAccept,
|
|
2189
|
+
disabled: !editedValue || isSaving || feedback?.type === "success",
|
|
2190
|
+
size: isMobile ? "lg" : "default",
|
|
2191
|
+
className: isMobile ? "flex-1" : "",
|
|
2192
|
+
children: isSaving ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2193
|
+
/* @__PURE__ */ jsx(
|
|
2194
|
+
Loader2,
|
|
2195
|
+
{
|
|
2196
|
+
className: cn(
|
|
2197
|
+
"mr-2 animate-spin",
|
|
2198
|
+
isMobile ? "w-5 h-5" : "w-4 h-4"
|
|
2199
|
+
)
|
|
2200
|
+
}
|
|
2201
|
+
),
|
|
2202
|
+
savingText
|
|
2203
|
+
] }) : feedback?.type === "success" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2204
|
+
/* @__PURE__ */ jsx(Check, { className: cn("mr-2", isMobile ? "w-5 h-5" : "w-4 h-4") }),
|
|
2205
|
+
savedText
|
|
2206
|
+
] }) : acceptText
|
|
2207
|
+
}
|
|
2208
|
+
)
|
|
2209
|
+
] });
|
|
2210
|
+
if (isMobile) {
|
|
2211
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2212
|
+
AvatarDisplay,
|
|
2213
|
+
/* @__PURE__ */ jsx(Drawer, { open: isOpen, onOpenChange: handleOpenChange, children: /* @__PURE__ */ jsxs(DrawerContent, { className: "max-h-[96vh]", children: [
|
|
2214
|
+
/* @__PURE__ */ jsx(DrawerHeader, { className: "text-center", children: /* @__PURE__ */ jsx(DrawerTitle, { className: "text-xl", children: dialogTitle }) }),
|
|
2215
|
+
/* @__PURE__ */ jsx("div", { className: "px-6 pb-6 overflow-y-auto", children: EditorContent }),
|
|
2216
|
+
/* @__PURE__ */ jsx(DrawerFooter, { className: "flex-row gap-3 px-6 pb-8", children: FooterButtons })
|
|
2217
|
+
] }) })
|
|
2218
|
+
] });
|
|
2219
|
+
}
|
|
2220
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
2221
|
+
AvatarDisplay,
|
|
2222
|
+
/* @__PURE__ */ jsx(Dialog, { open: isOpen, onOpenChange: handleOpenChange, children: /* @__PURE__ */ jsxs(DialogContent, { className: "sm:max-w-md", children: [
|
|
2223
|
+
/* @__PURE__ */ jsx(DialogHeader, { children: /* @__PURE__ */ jsx(DialogTitle, { children: dialogTitle }) }),
|
|
2224
|
+
/* @__PURE__ */ jsx("div", { className: "flex justify-center py-4", children: EditorContent }),
|
|
2225
|
+
/* @__PURE__ */ jsx(DialogFooter, { className: "sm:gap-3", children: FooterButtons })
|
|
2226
|
+
] }) })
|
|
2227
|
+
] });
|
|
2228
|
+
}
|
|
2229
|
+
|
|
2230
|
+
// src/components/video/hls-config.ts
|
|
2231
|
+
function shouldRetryLiveEdge404(retryConfig, retryCount, _isTimeout, loaderResponse, defaultRetry) {
|
|
2232
|
+
if (loaderResponse?.code === 404) {
|
|
2233
|
+
return retryConfig != null && retryCount < retryConfig.maxNumRetry;
|
|
2234
|
+
}
|
|
2235
|
+
return defaultRetry;
|
|
2236
|
+
}
|
|
2237
|
+
var liveEdgeErrorRetry = {
|
|
2238
|
+
maxNumRetry: 8,
|
|
2239
|
+
retryDelayMs: 250,
|
|
2240
|
+
maxRetryDelayMs: 4e3,
|
|
2241
|
+
backoff: "exponential",
|
|
2242
|
+
shouldRetry: shouldRetryLiveEdge404
|
|
2243
|
+
};
|
|
2244
|
+
function createLiveHlsConfig() {
|
|
2245
|
+
return {
|
|
2246
|
+
enableWorker: true,
|
|
2247
|
+
// No custom request headers: Cache-Control/Pragma are not
|
|
2248
|
+
// CORS-safelisted and would force an OPTIONS preflight before every
|
|
2249
|
+
// manifest poll and segment fetch. Freshness is controlled by the
|
|
2250
|
+
// origin's response Cache-Control headers instead.
|
|
2251
|
+
liveSyncDurationCount: 4,
|
|
2252
|
+
liveMaxLatencyDurationCount: 12,
|
|
2253
|
+
fragLoadPolicy: {
|
|
2254
|
+
default: {
|
|
2255
|
+
maxTimeToFirstByteMs: 1e4,
|
|
2256
|
+
maxLoadTimeMs: 12e4,
|
|
2257
|
+
timeoutRetry: {
|
|
2258
|
+
maxNumRetry: 4,
|
|
2259
|
+
retryDelayMs: 0,
|
|
2260
|
+
maxRetryDelayMs: 0
|
|
2261
|
+
},
|
|
2262
|
+
errorRetry: liveEdgeErrorRetry
|
|
2263
|
+
}
|
|
2264
|
+
},
|
|
2265
|
+
playlistLoadPolicy: {
|
|
2266
|
+
default: {
|
|
2267
|
+
maxTimeToFirstByteMs: 1e4,
|
|
2268
|
+
maxLoadTimeMs: 3e4,
|
|
2269
|
+
timeoutRetry: {
|
|
2270
|
+
maxNumRetry: 2,
|
|
2271
|
+
retryDelayMs: 0,
|
|
2272
|
+
maxRetryDelayMs: 0
|
|
2273
|
+
},
|
|
2274
|
+
errorRetry: {
|
|
2275
|
+
...liveEdgeErrorRetry,
|
|
2276
|
+
maxNumRetry: 6
|
|
2277
|
+
}
|
|
2278
|
+
}
|
|
2279
|
+
}
|
|
2280
|
+
};
|
|
2281
|
+
}
|
|
2282
|
+
function createVodHlsConfig() {
|
|
2283
|
+
return {
|
|
2284
|
+
enableWorker: true
|
|
2285
|
+
};
|
|
2286
|
+
}
|
|
2287
|
+
|
|
2288
|
+
// src/components/video/hls-errors.ts
|
|
2289
|
+
var MEDIA_ERROR_NAMES = {
|
|
2290
|
+
1: "MEDIA_ERR_ABORTED",
|
|
2291
|
+
2: "MEDIA_ERR_NETWORK",
|
|
2292
|
+
3: "MEDIA_ERR_DECODE",
|
|
2293
|
+
4: "MEDIA_ERR_SRC_NOT_SUPPORTED"
|
|
2294
|
+
};
|
|
2295
|
+
var MEDIA_ERR_NETWORK = 2;
|
|
2296
|
+
var MEDIA_ERR_DECODE = 3;
|
|
2297
|
+
var MEDIA_ERR_SRC_NOT_SUPPORTED = 4;
|
|
2298
|
+
function errorMessageFromUnknown(error) {
|
|
2299
|
+
if (error instanceof Error) return error.message;
|
|
2300
|
+
if (typeof error === "string") return error;
|
|
2301
|
+
return void 0;
|
|
2302
|
+
}
|
|
2303
|
+
function isNotFound(httpStatus, details) {
|
|
2304
|
+
return httpStatus === 404 || details === "manifestLoadError" || details === "levelLoadError" || details === "fragLoadError";
|
|
2305
|
+
}
|
|
2306
|
+
function kindForHls(input) {
|
|
2307
|
+
const httpStatus = input.response?.code;
|
|
2308
|
+
if (input.type === "networkError" && isNotFound(httpStatus, input.details)) {
|
|
2309
|
+
return input.context.mode === "vod" || !input.context.manifestParsed ? "unavailable" : "network";
|
|
2310
|
+
}
|
|
2311
|
+
if (input.type === "mediaError" || input.details === "bufferAppendError" || input.details === "bufferSeekOverHole") {
|
|
2312
|
+
return "media";
|
|
2313
|
+
}
|
|
2314
|
+
return "generic";
|
|
2315
|
+
}
|
|
2316
|
+
function kindForNative(input) {
|
|
2317
|
+
const code = input.mediaError?.code;
|
|
2318
|
+
if (code === MEDIA_ERR_DECODE) return "media";
|
|
2319
|
+
if (code === MEDIA_ERR_SRC_NOT_SUPPORTED) return "unsupported";
|
|
2320
|
+
if (code === MEDIA_ERR_NETWORK) return "unavailable";
|
|
2321
|
+
return "generic";
|
|
2322
|
+
}
|
|
2323
|
+
function describeAvResync(input) {
|
|
2324
|
+
const lag = Number.isFinite(input.lagSeconds) ? input.lagSeconds : 0;
|
|
2325
|
+
return {
|
|
2326
|
+
summary: `av-resync lag=${lag.toFixed(3)}s (non-fatal)`,
|
|
2327
|
+
kind: "resync",
|
|
2328
|
+
detail: {
|
|
2329
|
+
source: input.context.source,
|
|
2330
|
+
kind: "resync",
|
|
2331
|
+
fatal: false,
|
|
2332
|
+
reason: `presented frame lag ${lag.toFixed(3)}s`,
|
|
2333
|
+
context: input.context
|
|
2334
|
+
}
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
function describePlaybackError(input) {
|
|
2338
|
+
if (input.source === "unsupported") {
|
|
2339
|
+
return {
|
|
2340
|
+
summary: "playback unsupported (hls.js unavailable, native HLS unsupported)",
|
|
2341
|
+
kind: "unsupported",
|
|
2342
|
+
detail: {
|
|
2343
|
+
source: "unsupported",
|
|
2344
|
+
kind: "unsupported",
|
|
2345
|
+
context: input.context
|
|
2346
|
+
}
|
|
2347
|
+
};
|
|
2348
|
+
}
|
|
2349
|
+
if (input.source === "native") {
|
|
2350
|
+
const code = input.mediaError?.code;
|
|
2351
|
+
const kind2 = kindForNative(input);
|
|
2352
|
+
const detail2 = {
|
|
2353
|
+
source: "native",
|
|
2354
|
+
kind: kind2,
|
|
2355
|
+
mediaErrorCode: code,
|
|
2356
|
+
mediaErrorName: code !== void 0 ? MEDIA_ERROR_NAMES[code] : void 0,
|
|
2357
|
+
errorMessage: input.mediaError?.message,
|
|
2358
|
+
context: input.context
|
|
2359
|
+
};
|
|
2360
|
+
const name = detail2.mediaErrorName ?? "MEDIA_ERR_UNKNOWN";
|
|
2361
|
+
return {
|
|
2362
|
+
summary: `native ${name}${input.mediaError?.message ? `: ${input.mediaError.message}` : ""}`,
|
|
2363
|
+
kind: kind2,
|
|
2364
|
+
detail: detail2
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
const httpStatus = input.response?.code;
|
|
2368
|
+
const kind = kindForHls(input);
|
|
2369
|
+
const detail = {
|
|
2370
|
+
source: "hls",
|
|
2371
|
+
kind,
|
|
2372
|
+
type: input.type,
|
|
2373
|
+
details: input.details,
|
|
2374
|
+
fatal: input.fatal,
|
|
2375
|
+
httpStatus,
|
|
2376
|
+
url: input.url,
|
|
2377
|
+
reason: input.reason,
|
|
2378
|
+
errorMessage: errorMessageFromUnknown(input.error),
|
|
2379
|
+
context: input.context
|
|
2380
|
+
};
|
|
2381
|
+
const statusSuffix = httpStatus !== void 0 ? ` ${httpStatus}` : "";
|
|
2382
|
+
const summary = [
|
|
2383
|
+
"hls",
|
|
2384
|
+
input.type ?? "unknown",
|
|
2385
|
+
input.details ?? "unknown",
|
|
2386
|
+
input.fatal ? "(fatal)" : "(non-fatal)",
|
|
2387
|
+
statusSuffix.trim()
|
|
2388
|
+
].filter(Boolean).join(" ");
|
|
2389
|
+
return { summary, kind, detail };
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
// src/components/video/useHlsPlayback.ts
|
|
2393
|
+
var RETRY_INTERVAL_MS = 3e3;
|
|
2394
|
+
var MAX_MEDIA_ERROR_RETRIES = 5;
|
|
2395
|
+
var DRIFT_THRESHOLD_S = 0.4;
|
|
2396
|
+
var DRIFT_CONSECUTIVE_SAMPLES = 3;
|
|
2397
|
+
var RESYNC_COOLDOWN_MS = 1e4;
|
|
2398
|
+
var LIVE_EDGE_RESYNC_THRESHOLD_S = 8;
|
|
2399
|
+
function useHlsPlayback({
|
|
2400
|
+
src,
|
|
2401
|
+
mode,
|
|
2402
|
+
active,
|
|
2403
|
+
autoPlay = false,
|
|
2404
|
+
muted = false,
|
|
2405
|
+
onError,
|
|
2406
|
+
onPlayingChange
|
|
2407
|
+
}) {
|
|
2408
|
+
const videoRef = React3.useRef(null);
|
|
2409
|
+
const hlsRef = React3.useRef(null);
|
|
2410
|
+
const [state, setState] = React3.useState("idle");
|
|
2411
|
+
const [qualities, setQualities] = React3.useState([]);
|
|
2412
|
+
const [activeLevel, setActiveLevel] = React3.useState(-1);
|
|
2413
|
+
const [autoplayState, setAutoplayState] = React3.useState("none");
|
|
2414
|
+
const [error, setError] = React3.useState(null);
|
|
2415
|
+
const [reloadKey, setReloadKey] = React3.useState(0);
|
|
2416
|
+
const onErrorRef = React3.useRef(onError);
|
|
2417
|
+
const onPlayingChangeRef = React3.useRef(onPlayingChange);
|
|
2418
|
+
React3.useEffect(() => {
|
|
2419
|
+
onErrorRef.current = onError;
|
|
2420
|
+
onPlayingChangeRef.current = onPlayingChange;
|
|
2421
|
+
}, [onError, onPlayingChange]);
|
|
2422
|
+
const retry = React3.useCallback(() => {
|
|
2423
|
+
setError(null);
|
|
2424
|
+
setState("loading");
|
|
2425
|
+
setAutoplayState("none");
|
|
2426
|
+
setReloadKey((k) => k + 1);
|
|
2427
|
+
}, []);
|
|
2428
|
+
React3.useEffect(() => {
|
|
2429
|
+
const media = videoRef.current;
|
|
2430
|
+
if (!media || !src || !active) {
|
|
2431
|
+
setState("idle");
|
|
2432
|
+
return;
|
|
2433
|
+
}
|
|
2434
|
+
let cancelled = false;
|
|
2435
|
+
let retryTimer = null;
|
|
2436
|
+
let manifestParsed = false;
|
|
2437
|
+
let mediaErrorRetries = 0;
|
|
2438
|
+
let playbackSource = "hls";
|
|
2439
|
+
const teardown = [];
|
|
2440
|
+
media.muted = muted;
|
|
2441
|
+
setState("loading");
|
|
2442
|
+
setError(null);
|
|
2443
|
+
setAutoplayState("none");
|
|
2444
|
+
setQualities([]);
|
|
2445
|
+
setActiveLevel(-1);
|
|
2446
|
+
function baseContext() {
|
|
2447
|
+
return {
|
|
2448
|
+
mode,
|
|
2449
|
+
src,
|
|
2450
|
+
manifestParsed,
|
|
2451
|
+
retryCount: mediaErrorRetries,
|
|
2452
|
+
source: playbackSource
|
|
2453
|
+
};
|
|
2454
|
+
}
|
|
2455
|
+
function clearRetryTimer() {
|
|
2456
|
+
if (retryTimer !== null) {
|
|
2457
|
+
clearTimeout(retryTimer);
|
|
2458
|
+
retryTimer = null;
|
|
2459
|
+
}
|
|
2460
|
+
}
|
|
2461
|
+
function destroyHls() {
|
|
2462
|
+
hlsRef.current?.destroy();
|
|
2463
|
+
hlsRef.current = null;
|
|
2464
|
+
}
|
|
2465
|
+
function reportFatal(input) {
|
|
2466
|
+
const described = describePlaybackError(input);
|
|
2467
|
+
onErrorRef.current?.(described);
|
|
2468
|
+
setError(described);
|
|
2469
|
+
setState("error");
|
|
2470
|
+
}
|
|
2471
|
+
function attemptAutoplay(el) {
|
|
2472
|
+
void el.play().then(
|
|
2473
|
+
() => setAutoplayState("playing"),
|
|
2474
|
+
() => {
|
|
2475
|
+
el.muted = true;
|
|
2476
|
+
void el.play().then(
|
|
2477
|
+
() => setAutoplayState("muted"),
|
|
2478
|
+
() => setAutoplayState("blocked")
|
|
2479
|
+
);
|
|
2480
|
+
}
|
|
2481
|
+
);
|
|
2482
|
+
}
|
|
2483
|
+
function scheduleRetry(retryFn) {
|
|
2484
|
+
clearRetryTimer();
|
|
2485
|
+
if (cancelled) return;
|
|
2486
|
+
setState("waiting");
|
|
2487
|
+
retryTimer = setTimeout(() => {
|
|
2488
|
+
retryTimer = null;
|
|
2489
|
+
if (!cancelled) retryFn();
|
|
2490
|
+
}, RETRY_INTERVAL_MS);
|
|
2491
|
+
}
|
|
2492
|
+
function startDriftWatchdog(el) {
|
|
2493
|
+
if (typeof el.requestVideoFrameCallback !== "function") return;
|
|
2494
|
+
let consecutiveLagSamples = 0;
|
|
2495
|
+
let lastResyncAt = 0;
|
|
2496
|
+
let handle = null;
|
|
2497
|
+
const tick = (_now, metadata) => {
|
|
2498
|
+
if (cancelled) return;
|
|
2499
|
+
handle = el.requestVideoFrameCallback(tick);
|
|
2500
|
+
if (el.paused || el.ended) {
|
|
2501
|
+
consecutiveLagSamples = 0;
|
|
2502
|
+
return;
|
|
2503
|
+
}
|
|
2504
|
+
const lag = el.currentTime - metadata.mediaTime;
|
|
2505
|
+
if (!(lag > DRIFT_THRESHOLD_S)) {
|
|
2506
|
+
consecutiveLagSamples = 0;
|
|
2507
|
+
return;
|
|
2508
|
+
}
|
|
2509
|
+
consecutiveLagSamples += 1;
|
|
2510
|
+
if (consecutiveLagSamples < DRIFT_CONSECUTIVE_SAMPLES) return;
|
|
2511
|
+
const nowMs = performance.now();
|
|
2512
|
+
if (nowMs - lastResyncAt < RESYNC_COOLDOWN_MS) return;
|
|
2513
|
+
lastResyncAt = nowMs;
|
|
2514
|
+
consecutiveLagSamples = 0;
|
|
2515
|
+
if (mode === "live" && el.seekable.length > 0) {
|
|
2516
|
+
const edge = el.seekable.end(el.seekable.length - 1);
|
|
2517
|
+
if (edge - el.currentTime > LIVE_EDGE_RESYNC_THRESHOLD_S) {
|
|
2518
|
+
el.currentTime = edge;
|
|
2519
|
+
} else {
|
|
2520
|
+
el.currentTime = el.currentTime + 1e-3;
|
|
2521
|
+
}
|
|
2522
|
+
} else {
|
|
2523
|
+
el.currentTime = el.currentTime + 1e-3;
|
|
2524
|
+
}
|
|
2525
|
+
onErrorRef.current?.(
|
|
2526
|
+
describeAvResync({
|
|
2527
|
+
lagSeconds: lag,
|
|
2528
|
+
context: baseContext()
|
|
2529
|
+
})
|
|
2530
|
+
);
|
|
2531
|
+
};
|
|
2532
|
+
handle = el.requestVideoFrameCallback(tick);
|
|
2533
|
+
teardown.push(() => {
|
|
2534
|
+
if (handle != null && typeof el.cancelVideoFrameCallback === "function") {
|
|
2535
|
+
el.cancelVideoFrameCallback(handle);
|
|
2536
|
+
}
|
|
2537
|
+
});
|
|
2538
|
+
}
|
|
2539
|
+
function onPlaying() {
|
|
2540
|
+
manifestParsed = true;
|
|
2541
|
+
mediaErrorRetries = 0;
|
|
2542
|
+
clearRetryTimer();
|
|
2543
|
+
setState("ready");
|
|
2544
|
+
onPlayingChangeRef.current?.(true);
|
|
2545
|
+
}
|
|
2546
|
+
function onPaused() {
|
|
2547
|
+
onPlayingChangeRef.current?.(false);
|
|
2548
|
+
}
|
|
2549
|
+
media.addEventListener("playing", onPlaying);
|
|
2550
|
+
media.addEventListener("pause", onPaused);
|
|
2551
|
+
media.addEventListener("ended", onPaused);
|
|
2552
|
+
teardown.push(() => {
|
|
2553
|
+
media.removeEventListener("playing", onPlaying);
|
|
2554
|
+
media.removeEventListener("pause", onPaused);
|
|
2555
|
+
media.removeEventListener("ended", onPaused);
|
|
2556
|
+
});
|
|
2557
|
+
startDriftWatchdog(media);
|
|
2558
|
+
function initNative() {
|
|
2559
|
+
playbackSource = "native";
|
|
2560
|
+
manifestParsed = false;
|
|
2561
|
+
media.removeAttribute("src");
|
|
2562
|
+
media.load();
|
|
2563
|
+
media.src = src;
|
|
2564
|
+
const onReady = () => {
|
|
2565
|
+
manifestParsed = true;
|
|
2566
|
+
clearRetryTimer();
|
|
2567
|
+
setState("ready");
|
|
2568
|
+
if (mode === "live" || autoPlay) attemptAutoplay(media);
|
|
2569
|
+
};
|
|
2570
|
+
const onErr = () => {
|
|
2571
|
+
if (manifestParsed) {
|
|
2572
|
+
reportFatal({
|
|
2573
|
+
source: "native",
|
|
2574
|
+
mediaError: media.error,
|
|
2575
|
+
context: baseContext()
|
|
2576
|
+
});
|
|
2577
|
+
return;
|
|
2578
|
+
}
|
|
2579
|
+
onErrorRef.current?.(
|
|
2580
|
+
describePlaybackError({
|
|
2581
|
+
source: "native",
|
|
2582
|
+
mediaError: media.error,
|
|
2583
|
+
context: baseContext()
|
|
2584
|
+
})
|
|
2585
|
+
);
|
|
2586
|
+
scheduleRetry(() => {
|
|
2587
|
+
media.src = src;
|
|
2588
|
+
media.load();
|
|
2589
|
+
});
|
|
2590
|
+
};
|
|
2591
|
+
media.addEventListener("loadedmetadata", onReady);
|
|
2592
|
+
media.addEventListener("error", onErr);
|
|
2593
|
+
teardown.push(() => {
|
|
2594
|
+
media.removeEventListener("loadedmetadata", onReady);
|
|
2595
|
+
media.removeEventListener("error", onErr);
|
|
2596
|
+
});
|
|
2597
|
+
}
|
|
2598
|
+
function initHlsJs(Hls) {
|
|
2599
|
+
playbackSource = "hls";
|
|
2600
|
+
destroyHls();
|
|
2601
|
+
manifestParsed = false;
|
|
2602
|
+
const config = mode === "live" ? createLiveHlsConfig() : createVodHlsConfig();
|
|
2603
|
+
const hls = new Hls(config);
|
|
2604
|
+
hlsRef.current = hls;
|
|
2605
|
+
hls.loadSource(src);
|
|
2606
|
+
hls.attachMedia(media);
|
|
2607
|
+
hls.on(Hls.Events.MANIFEST_PARSED, (_e, data) => {
|
|
2608
|
+
manifestParsed = true;
|
|
2609
|
+
clearRetryTimer();
|
|
2610
|
+
setQualities(
|
|
2611
|
+
data.levels.map((l, index) => ({ index, height: l.height }))
|
|
2612
|
+
);
|
|
2613
|
+
setState("ready");
|
|
2614
|
+
if (mode === "live" || autoPlay) attemptAutoplay(media);
|
|
2615
|
+
});
|
|
2616
|
+
hls.on(Hls.Events.LEVEL_SWITCHED, (_e, data) => {
|
|
2617
|
+
if (hls.autoLevelEnabled) setActiveLevel(-1);
|
|
2618
|
+
else setActiveLevel(data.level);
|
|
2619
|
+
});
|
|
2620
|
+
hls.on(Hls.Events.ERROR, (_e, data) => {
|
|
2621
|
+
onErrorRef.current?.(
|
|
2622
|
+
describePlaybackError({
|
|
2623
|
+
source: "hls",
|
|
2624
|
+
type: data.type,
|
|
2625
|
+
details: data.details,
|
|
2626
|
+
fatal: data.fatal,
|
|
2627
|
+
url: data.url,
|
|
2628
|
+
response: data.response,
|
|
2629
|
+
reason: data.reason,
|
|
2630
|
+
error: data.error,
|
|
2631
|
+
context: baseContext()
|
|
2632
|
+
})
|
|
2633
|
+
);
|
|
2634
|
+
if (!data.fatal) return;
|
|
2635
|
+
if (data.type === Hls.ErrorTypes.NETWORK_ERROR) {
|
|
2636
|
+
if (!manifestParsed) {
|
|
2637
|
+
scheduleRetry(() => initHlsJs(Hls));
|
|
2638
|
+
return;
|
|
2639
|
+
}
|
|
2640
|
+
hls.startLoad();
|
|
2641
|
+
return;
|
|
2642
|
+
}
|
|
2643
|
+
mediaErrorRetries += 1;
|
|
2644
|
+
if (mediaErrorRetries === 1) {
|
|
2645
|
+
hls.recoverMediaError();
|
|
2646
|
+
return;
|
|
2647
|
+
}
|
|
2648
|
+
if (mediaErrorRetries === 2) {
|
|
2649
|
+
hls.swapAudioCodec();
|
|
2650
|
+
hls.recoverMediaError();
|
|
2651
|
+
return;
|
|
2652
|
+
}
|
|
2653
|
+
if (mediaErrorRetries < MAX_MEDIA_ERROR_RETRIES) {
|
|
2654
|
+
scheduleRetry(() => initHlsJs(Hls));
|
|
2655
|
+
return;
|
|
2656
|
+
}
|
|
2657
|
+
reportFatal({
|
|
2658
|
+
source: "hls",
|
|
2659
|
+
type: data.type,
|
|
2660
|
+
details: data.details,
|
|
2661
|
+
fatal: true,
|
|
2662
|
+
url: data.url,
|
|
2663
|
+
response: data.response,
|
|
2664
|
+
reason: data.reason,
|
|
2665
|
+
error: data.error,
|
|
2666
|
+
context: baseContext()
|
|
2667
|
+
});
|
|
2668
|
+
});
|
|
2669
|
+
}
|
|
2670
|
+
async function setup() {
|
|
2671
|
+
let Hls = null;
|
|
2672
|
+
try {
|
|
2673
|
+
Hls = (await import('hls.js')).default;
|
|
2674
|
+
} catch {
|
|
2675
|
+
Hls = null;
|
|
2676
|
+
}
|
|
2677
|
+
if (cancelled) return;
|
|
2678
|
+
if (Hls && Hls.isSupported()) {
|
|
2679
|
+
initHlsJs(Hls);
|
|
2680
|
+
} else if (media.canPlayType("application/vnd.apple.mpegurl")) {
|
|
2681
|
+
initNative();
|
|
2682
|
+
} else {
|
|
2683
|
+
playbackSource = "unsupported";
|
|
2684
|
+
reportFatal({
|
|
2685
|
+
source: "unsupported",
|
|
2686
|
+
context: baseContext()
|
|
2687
|
+
});
|
|
2688
|
+
}
|
|
2689
|
+
}
|
|
2690
|
+
void setup();
|
|
2691
|
+
return () => {
|
|
2692
|
+
cancelled = true;
|
|
2693
|
+
clearRetryTimer();
|
|
2694
|
+
for (const fn of teardown) fn();
|
|
2695
|
+
destroyHls();
|
|
2696
|
+
};
|
|
2697
|
+
}, [src, mode, active, autoPlay, muted, reloadKey]);
|
|
2698
|
+
const setLevel = React3.useCallback((index) => {
|
|
2699
|
+
const hls = hlsRef.current;
|
|
2700
|
+
if (!hls) return;
|
|
2701
|
+
hls.nextLevel = index;
|
|
2702
|
+
setActiveLevel(index);
|
|
2703
|
+
}, []);
|
|
2704
|
+
return {
|
|
2705
|
+
videoRef,
|
|
2706
|
+
state,
|
|
2707
|
+
qualities,
|
|
2708
|
+
activeLevel,
|
|
2709
|
+
setLevel,
|
|
2710
|
+
autoplayState,
|
|
2711
|
+
error,
|
|
2712
|
+
retry
|
|
2713
|
+
};
|
|
2714
|
+
}
|
|
2715
|
+
var DEFAULT_LABELS2 = {
|
|
2716
|
+
play: "Play",
|
|
2717
|
+
pause: "Pause",
|
|
2718
|
+
mute: "Mute",
|
|
2719
|
+
unmute: "Unmute",
|
|
2720
|
+
enterFullscreen: "Fullscreen",
|
|
2721
|
+
exitFullscreen: "Exit fullscreen",
|
|
2722
|
+
pictureInPicture: "Picture in picture",
|
|
2723
|
+
settings: "Settings",
|
|
2724
|
+
quality: "Quality",
|
|
2725
|
+
auto: "Auto",
|
|
2726
|
+
speed: "Speed",
|
|
2727
|
+
live: "LIVE",
|
|
2728
|
+
goLive: "Go live",
|
|
2729
|
+
tapToUnmute: "Tap to unmute",
|
|
2730
|
+
loading: "Loading\u2026",
|
|
2731
|
+
waiting: "Waiting for stream\u2026",
|
|
2732
|
+
retry: "Retry",
|
|
2733
|
+
errorUnavailable: "This video isn't available yet.",
|
|
2734
|
+
errorNetwork: "We couldn't load the video. Check your connection.",
|
|
2735
|
+
errorMedia: "There was a playback problem.",
|
|
2736
|
+
errorUnsupported: "Your browser can't play this video.",
|
|
2737
|
+
errorGeneric: "We couldn't play this video."
|
|
2738
|
+
};
|
|
2739
|
+
var PLAYBACK_RATES = [0.75, 1, 1.25, 1.5, 2];
|
|
2740
|
+
var CONTROLS_HIDE_MS = 3e3;
|
|
2741
|
+
var LIVE_EDGE_THRESHOLD_S = 8;
|
|
2742
|
+
var SEEK_STEP_S = 5;
|
|
2743
|
+
function asWebkitVideo(video) {
|
|
2744
|
+
return video;
|
|
2745
|
+
}
|
|
2746
|
+
function hasWebkitVideoFullscreen(video) {
|
|
2747
|
+
const webkit = asWebkitVideo(video);
|
|
2748
|
+
return typeof webkit?.webkitEnterFullscreen === "function";
|
|
2749
|
+
}
|
|
2750
|
+
function hasStandardFullscreen() {
|
|
2751
|
+
if (typeof document === "undefined") return false;
|
|
2752
|
+
if (document.fullscreenEnabled) return true;
|
|
2753
|
+
const doc = document;
|
|
2754
|
+
return !!doc.webkitFullscreenEnabled;
|
|
2755
|
+
}
|
|
2756
|
+
function formatTime(seconds) {
|
|
2757
|
+
if (!Number.isFinite(seconds) || seconds < 0) return "0:00";
|
|
2758
|
+
const total = Math.floor(seconds);
|
|
2759
|
+
const h = Math.floor(total / 3600);
|
|
2760
|
+
const m = Math.floor(total % 3600 / 60);
|
|
2761
|
+
const s = total % 60;
|
|
2762
|
+
const mm = h > 0 ? String(m).padStart(2, "0") : String(m);
|
|
2763
|
+
const ss = String(s).padStart(2, "0");
|
|
2764
|
+
return h > 0 ? `${h}:${mm}:${ss}` : `${mm}:${ss}`;
|
|
2765
|
+
}
|
|
2766
|
+
function VideoPlayer({
|
|
2767
|
+
src,
|
|
2768
|
+
mode,
|
|
2769
|
+
poster,
|
|
2770
|
+
autoPlay = false,
|
|
2771
|
+
muted = false,
|
|
2772
|
+
stats,
|
|
2773
|
+
labels,
|
|
2774
|
+
showQualitySelector = true,
|
|
2775
|
+
paused = false,
|
|
2776
|
+
onPlayingChange,
|
|
2777
|
+
onFirstPlay,
|
|
2778
|
+
onError,
|
|
2779
|
+
fit = "aspect-video",
|
|
2780
|
+
className
|
|
2781
|
+
}) {
|
|
2782
|
+
const t = { ...DEFAULT_LABELS2, ...labels };
|
|
2783
|
+
const containerRef = React3.useRef(null);
|
|
2784
|
+
const firstPlayFiredRef = React3.useRef(false);
|
|
2785
|
+
const [userStarted, setUserStarted] = React3.useState(false);
|
|
2786
|
+
const active = autoPlay || !poster || userStarted;
|
|
2787
|
+
const autoplayActive = autoPlay || userStarted;
|
|
2788
|
+
const handlePlayingChange = React3.useCallback(
|
|
2789
|
+
(playing) => {
|
|
2790
|
+
setIsPlaying(playing);
|
|
2791
|
+
if (playing && !firstPlayFiredRef.current) {
|
|
2792
|
+
firstPlayFiredRef.current = true;
|
|
2793
|
+
onFirstPlay?.();
|
|
2794
|
+
}
|
|
2795
|
+
onPlayingChange?.(playing);
|
|
2796
|
+
},
|
|
2797
|
+
[onFirstPlay, onPlayingChange]
|
|
2798
|
+
);
|
|
2799
|
+
const {
|
|
2800
|
+
videoRef,
|
|
2801
|
+
state,
|
|
2802
|
+
qualities,
|
|
2803
|
+
activeLevel,
|
|
2804
|
+
setLevel,
|
|
2805
|
+
autoplayState,
|
|
2806
|
+
error,
|
|
2807
|
+
retry
|
|
2808
|
+
} = useHlsPlayback({
|
|
2809
|
+
src,
|
|
2810
|
+
mode,
|
|
2811
|
+
active,
|
|
2812
|
+
autoPlay: autoplayActive,
|
|
2813
|
+
muted,
|
|
2814
|
+
onError,
|
|
2815
|
+
onPlayingChange: handlePlayingChange
|
|
2816
|
+
});
|
|
2817
|
+
const [isPlaying, setIsPlaying] = React3.useState(false);
|
|
2818
|
+
const [isMuted, setIsMuted] = React3.useState(muted);
|
|
2819
|
+
const [volume, setVolume] = React3.useState(1);
|
|
2820
|
+
const [currentTime, setCurrentTime] = React3.useState(0);
|
|
2821
|
+
const [duration, setDuration] = React3.useState(0);
|
|
2822
|
+
const [buffered, setBuffered] = React3.useState(0);
|
|
2823
|
+
const [isFullscreen, setIsFullscreen] = React3.useState(false);
|
|
2824
|
+
const [pipActive, setPipActive] = React3.useState(false);
|
|
2825
|
+
const [controlsVisible, setControlsVisible] = React3.useState(true);
|
|
2826
|
+
const [playbackRate, setPlaybackRate] = React3.useState(1);
|
|
2827
|
+
const [openMenu, setOpenMenu] = React3.useState(
|
|
2828
|
+
null
|
|
2829
|
+
);
|
|
2830
|
+
const [behindLive, setBehindLive] = React3.useState(false);
|
|
2831
|
+
const [webkitFullscreenSupported, setWebkitFullscreenSupported] = React3.useState(false);
|
|
2832
|
+
const hideTimerRef = React3.useRef(null);
|
|
2833
|
+
const pipSupported = typeof document !== "undefined" && "pictureInPictureEnabled" in document && document.pictureInPictureEnabled;
|
|
2834
|
+
const fullscreenSupported = hasStandardFullscreen() || webkitFullscreenSupported;
|
|
2835
|
+
React3.useEffect(() => {
|
|
2836
|
+
const video = videoRef.current;
|
|
2837
|
+
if (!video || !active) return;
|
|
2838
|
+
const onTimeUpdate = () => {
|
|
2839
|
+
setCurrentTime(video.currentTime);
|
|
2840
|
+
if (video.buffered.length > 0) {
|
|
2841
|
+
setBuffered(video.buffered.end(video.buffered.length - 1));
|
|
2842
|
+
}
|
|
2843
|
+
if (mode === "live" && video.seekable.length > 0) {
|
|
2844
|
+
const edge = video.seekable.end(video.seekable.length - 1);
|
|
2845
|
+
setBehindLive(edge - video.currentTime > LIVE_EDGE_THRESHOLD_S);
|
|
2846
|
+
}
|
|
2847
|
+
};
|
|
2848
|
+
const onDuration = () => setDuration(video.duration);
|
|
2849
|
+
const onVolume = () => {
|
|
2850
|
+
setIsMuted(video.muted);
|
|
2851
|
+
setVolume(video.volume);
|
|
2852
|
+
};
|
|
2853
|
+
const onRate = () => setPlaybackRate(video.playbackRate);
|
|
2854
|
+
video.addEventListener("timeupdate", onTimeUpdate);
|
|
2855
|
+
video.addEventListener("durationchange", onDuration);
|
|
2856
|
+
video.addEventListener("loadedmetadata", onDuration);
|
|
2857
|
+
video.addEventListener("volumechange", onVolume);
|
|
2858
|
+
video.addEventListener("ratechange", onRate);
|
|
2859
|
+
onVolume();
|
|
2860
|
+
return () => {
|
|
2861
|
+
video.removeEventListener("timeupdate", onTimeUpdate);
|
|
2862
|
+
video.removeEventListener("durationchange", onDuration);
|
|
2863
|
+
video.removeEventListener("loadedmetadata", onDuration);
|
|
2864
|
+
video.removeEventListener("volumechange", onVolume);
|
|
2865
|
+
video.removeEventListener("ratechange", onRate);
|
|
2866
|
+
};
|
|
2867
|
+
}, [videoRef, active, mode]);
|
|
2868
|
+
React3.useEffect(() => {
|
|
2869
|
+
const video = videoRef.current;
|
|
2870
|
+
if (!paused || !video || !isPlaying) return;
|
|
2871
|
+
video.pause();
|
|
2872
|
+
}, [paused, videoRef, isPlaying]);
|
|
2873
|
+
React3.useEffect(() => {
|
|
2874
|
+
setWebkitFullscreenSupported(hasWebkitVideoFullscreen(videoRef.current));
|
|
2875
|
+
}, [videoRef, active]);
|
|
2876
|
+
React3.useEffect(() => {
|
|
2877
|
+
const onFsChange = () => setIsFullscreen(document.fullscreenElement === containerRef.current);
|
|
2878
|
+
document.addEventListener("fullscreenchange", onFsChange);
|
|
2879
|
+
return () => document.removeEventListener("fullscreenchange", onFsChange);
|
|
2880
|
+
}, []);
|
|
2881
|
+
React3.useEffect(() => {
|
|
2882
|
+
const video = asWebkitVideo(videoRef.current);
|
|
2883
|
+
if (!video) return;
|
|
2884
|
+
const onBegin = () => setIsFullscreen(true);
|
|
2885
|
+
const onEnd = () => setIsFullscreen(false);
|
|
2886
|
+
video.addEventListener("webkitbeginfullscreen", onBegin);
|
|
2887
|
+
video.addEventListener("webkitendfullscreen", onEnd);
|
|
2888
|
+
return () => {
|
|
2889
|
+
video.removeEventListener("webkitbeginfullscreen", onBegin);
|
|
2890
|
+
video.removeEventListener("webkitendfullscreen", onEnd);
|
|
2891
|
+
};
|
|
2892
|
+
}, [videoRef, active]);
|
|
2893
|
+
React3.useEffect(() => {
|
|
2894
|
+
const video = videoRef.current;
|
|
2895
|
+
if (!video) return;
|
|
2896
|
+
const onEnter = () => setPipActive(true);
|
|
2897
|
+
const onLeave = () => setPipActive(false);
|
|
2898
|
+
video.addEventListener("enterpictureinpicture", onEnter);
|
|
2899
|
+
video.addEventListener("leavepictureinpicture", onLeave);
|
|
2900
|
+
return () => {
|
|
2901
|
+
video.removeEventListener("enterpictureinpicture", onEnter);
|
|
2902
|
+
video.removeEventListener("leavepictureinpicture", onLeave);
|
|
2903
|
+
};
|
|
2904
|
+
}, [videoRef]);
|
|
2905
|
+
const scheduleHide = React3.useCallback(() => {
|
|
2906
|
+
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
2907
|
+
hideTimerRef.current = setTimeout(() => {
|
|
2908
|
+
setControlsVisible(false);
|
|
2909
|
+
setOpenMenu(null);
|
|
2910
|
+
}, CONTROLS_HIDE_MS);
|
|
2911
|
+
}, []);
|
|
2912
|
+
const revealControls = React3.useCallback(() => {
|
|
2913
|
+
setControlsVisible(true);
|
|
2914
|
+
scheduleHide();
|
|
2915
|
+
}, [scheduleHide]);
|
|
2916
|
+
React3.useEffect(() => {
|
|
2917
|
+
return () => {
|
|
2918
|
+
if (hideTimerRef.current) clearTimeout(hideTimerRef.current);
|
|
2919
|
+
};
|
|
2920
|
+
}, []);
|
|
2921
|
+
function togglePlay() {
|
|
2922
|
+
const video = videoRef.current;
|
|
2923
|
+
if (!video) return;
|
|
2924
|
+
if (video.paused) void video.play();
|
|
2925
|
+
else video.pause();
|
|
2926
|
+
}
|
|
2927
|
+
function toggleMute() {
|
|
2928
|
+
const video = videoRef.current;
|
|
2929
|
+
if (!video) return;
|
|
2930
|
+
video.muted = !video.muted;
|
|
2931
|
+
}
|
|
2932
|
+
function changeVolume(next) {
|
|
2933
|
+
const video = videoRef.current;
|
|
2934
|
+
if (!video) return;
|
|
2935
|
+
video.volume = next;
|
|
2936
|
+
video.muted = next === 0;
|
|
2937
|
+
}
|
|
2938
|
+
function seekTo(next) {
|
|
2939
|
+
const video = videoRef.current;
|
|
2940
|
+
if (!video) return;
|
|
2941
|
+
video.currentTime = next;
|
|
2942
|
+
setCurrentTime(next);
|
|
2943
|
+
}
|
|
2944
|
+
function seekBy(delta) {
|
|
2945
|
+
const video = videoRef.current;
|
|
2946
|
+
if (!video) return;
|
|
2947
|
+
seekTo(Math.min(Math.max(video.currentTime + delta, 0), duration || 0));
|
|
2948
|
+
}
|
|
2949
|
+
function goToLiveEdge() {
|
|
2950
|
+
const video = videoRef.current;
|
|
2951
|
+
if (!video || video.seekable.length === 0) return;
|
|
2952
|
+
video.currentTime = video.seekable.end(video.seekable.length - 1);
|
|
2953
|
+
if (video.paused) void video.play();
|
|
2954
|
+
}
|
|
2955
|
+
function toggleFullscreen() {
|
|
2956
|
+
const el = containerRef.current;
|
|
2957
|
+
const video = asWebkitVideo(videoRef.current);
|
|
2958
|
+
if (el && document.fullscreenElement === el) {
|
|
2959
|
+
void document.exitFullscreen();
|
|
2960
|
+
return;
|
|
2961
|
+
}
|
|
2962
|
+
if (video?.webkitDisplayingFullscreen && video.webkitExitFullscreen) {
|
|
2963
|
+
video.webkitExitFullscreen();
|
|
2964
|
+
return;
|
|
2965
|
+
}
|
|
2966
|
+
if (el && hasStandardFullscreen() && typeof el.requestFullscreen === "function") {
|
|
2967
|
+
void el.requestFullscreen();
|
|
2968
|
+
return;
|
|
2969
|
+
}
|
|
2970
|
+
if (video && typeof video.webkitEnterFullscreen === "function") {
|
|
2971
|
+
video.webkitEnterFullscreen();
|
|
2972
|
+
}
|
|
2973
|
+
}
|
|
2974
|
+
function togglePip() {
|
|
2975
|
+
const video = videoRef.current;
|
|
2976
|
+
if (!video) return;
|
|
2977
|
+
if (document.pictureInPictureElement === video) {
|
|
2978
|
+
void document.exitPictureInPicture();
|
|
2979
|
+
} else {
|
|
2980
|
+
void video.requestPictureInPicture?.();
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
function changeRate(rate) {
|
|
2984
|
+
const video = videoRef.current;
|
|
2985
|
+
if (video) video.playbackRate = rate;
|
|
2986
|
+
setPlaybackRate(rate);
|
|
2987
|
+
setOpenMenu(null);
|
|
2988
|
+
}
|
|
2989
|
+
function chooseLevel(index) {
|
|
2990
|
+
setLevel(index);
|
|
2991
|
+
setOpenMenu(null);
|
|
2992
|
+
}
|
|
2993
|
+
function handleKeyDown(e) {
|
|
2994
|
+
if (!active) return;
|
|
2995
|
+
switch (e.key) {
|
|
2996
|
+
case " ":
|
|
2997
|
+
case "k":
|
|
2998
|
+
e.preventDefault();
|
|
2999
|
+
togglePlay();
|
|
3000
|
+
break;
|
|
3001
|
+
case "m":
|
|
3002
|
+
toggleMute();
|
|
3003
|
+
break;
|
|
3004
|
+
case "f":
|
|
3005
|
+
toggleFullscreen();
|
|
3006
|
+
break;
|
|
3007
|
+
case "ArrowLeft":
|
|
3008
|
+
if (mode === "vod") {
|
|
3009
|
+
e.preventDefault();
|
|
3010
|
+
seekBy(-SEEK_STEP_S);
|
|
3011
|
+
}
|
|
3012
|
+
break;
|
|
3013
|
+
case "ArrowRight":
|
|
3014
|
+
if (mode === "vod") {
|
|
3015
|
+
e.preventDefault();
|
|
3016
|
+
seekBy(SEEK_STEP_S);
|
|
3017
|
+
}
|
|
3018
|
+
break;
|
|
3019
|
+
case "ArrowUp":
|
|
3020
|
+
e.preventDefault();
|
|
3021
|
+
changeVolume(Math.min((videoRef.current?.volume ?? 1) + 0.1, 1));
|
|
3022
|
+
break;
|
|
3023
|
+
case "ArrowDown":
|
|
3024
|
+
e.preventDefault();
|
|
3025
|
+
changeVolume(Math.max((videoRef.current?.volume ?? 0) - 0.1, 0));
|
|
3026
|
+
break;
|
|
3027
|
+
}
|
|
3028
|
+
revealControls();
|
|
3029
|
+
}
|
|
3030
|
+
function errorMessage(err) {
|
|
3031
|
+
switch (err.kind) {
|
|
3032
|
+
case "unavailable":
|
|
3033
|
+
return t.errorUnavailable;
|
|
3034
|
+
case "network":
|
|
3035
|
+
return t.errorNetwork;
|
|
3036
|
+
case "media":
|
|
3037
|
+
return t.errorMedia;
|
|
3038
|
+
case "unsupported":
|
|
3039
|
+
return t.errorUnsupported;
|
|
3040
|
+
case "resync":
|
|
3041
|
+
return t.errorMedia;
|
|
3042
|
+
case "generic":
|
|
3043
|
+
return t.errorGeneric;
|
|
3044
|
+
default: {
|
|
3045
|
+
const _exhaustive = err.kind;
|
|
3046
|
+
return _exhaustive;
|
|
3047
|
+
}
|
|
3048
|
+
}
|
|
3049
|
+
}
|
|
3050
|
+
const VolumeIcon = isMuted || volume === 0 ? VolumeX : volume < 0.5 ? Volume1 : Volume2;
|
|
3051
|
+
const showSpinner = active && (state === "loading" || state === "waiting");
|
|
3052
|
+
const showControls = active && state === "ready" && (controlsVisible || !isPlaying);
|
|
3053
|
+
const showPoster = !active && !!poster;
|
|
3054
|
+
const currentLevelLabel = activeLevel < 0 ? t.auto : `${qualities.find((q) => q.index === activeLevel)?.height ?? ""}p`;
|
|
3055
|
+
return /* @__PURE__ */ jsxs(
|
|
3056
|
+
"div",
|
|
3057
|
+
{
|
|
3058
|
+
ref: containerRef,
|
|
3059
|
+
"data-slot": "video-player",
|
|
3060
|
+
"data-mode": mode,
|
|
3061
|
+
"data-fit": fit,
|
|
3062
|
+
className: cn(
|
|
3063
|
+
"group relative w-full overflow-hidden rounded-lg bg-black text-white select-none",
|
|
3064
|
+
fit === "contain" ? "h-full min-h-0 aspect-auto" : "aspect-video",
|
|
3065
|
+
className
|
|
3066
|
+
),
|
|
3067
|
+
onMouseMove: revealControls,
|
|
3068
|
+
onMouseLeave: () => {
|
|
3069
|
+
if (isPlaying) setControlsVisible(false);
|
|
3070
|
+
},
|
|
3071
|
+
onKeyDown: handleKeyDown,
|
|
3072
|
+
tabIndex: 0,
|
|
3073
|
+
role: "region",
|
|
3074
|
+
"aria-label": "Video player",
|
|
3075
|
+
children: [
|
|
3076
|
+
/* @__PURE__ */ jsx(
|
|
3077
|
+
"video",
|
|
3078
|
+
{
|
|
3079
|
+
ref: videoRef,
|
|
3080
|
+
playsInline: true,
|
|
3081
|
+
className: "h-full w-full bg-black object-contain",
|
|
3082
|
+
onClick: active ? togglePlay : void 0,
|
|
3083
|
+
poster
|
|
3084
|
+
}
|
|
3085
|
+
),
|
|
3086
|
+
showPoster && /* @__PURE__ */ jsx(
|
|
3087
|
+
"button",
|
|
3088
|
+
{
|
|
3089
|
+
type: "button",
|
|
3090
|
+
"aria-label": t.play,
|
|
3091
|
+
onClick: () => {
|
|
3092
|
+
setUserStarted(true);
|
|
3093
|
+
revealControls();
|
|
3094
|
+
},
|
|
3095
|
+
className: "absolute inset-0 flex items-center justify-center bg-black bg-contain bg-center bg-no-repeat",
|
|
3096
|
+
style: poster ? { backgroundImage: `url(${poster})` } : void 0,
|
|
3097
|
+
children: /* @__PURE__ */ jsx("span", { className: "flex size-16 items-center justify-center rounded-full bg-black/50 backdrop-blur-sm transition group-hover:bg-black/70", children: /* @__PURE__ */ jsx(Play, { className: "size-8 translate-x-0.5", fill: "currentColor" }) })
|
|
3098
|
+
}
|
|
3099
|
+
),
|
|
3100
|
+
showSpinner && /* @__PURE__ */ jsxs("div", { className: "absolute inset-0 flex flex-col items-center justify-center gap-3 bg-black/50 text-sm", children: [
|
|
3101
|
+
/* @__PURE__ */ jsx(Loader2, { className: "size-8 animate-spin" }),
|
|
3102
|
+
/* @__PURE__ */ jsx("span", { children: state === "loading" ? t.loading : t.waiting })
|
|
3103
|
+
] }),
|
|
3104
|
+
state === "error" && error && /* @__PURE__ */ jsxs("div", { className: "absolute inset-0 flex flex-col items-center justify-center gap-4 bg-black/70 px-6 text-center text-sm", children: [
|
|
3105
|
+
/* @__PURE__ */ jsx(AlertCircle, { className: "text-red-400 size-8" }),
|
|
3106
|
+
/* @__PURE__ */ jsx("p", { className: "text-red-200", children: errorMessage(error) }),
|
|
3107
|
+
/* @__PURE__ */ jsxs(
|
|
3108
|
+
"button",
|
|
3109
|
+
{
|
|
3110
|
+
type: "button",
|
|
3111
|
+
onClick: retry,
|
|
3112
|
+
className: "inline-flex items-center gap-2 rounded-md bg-white/15 px-3 py-1.5 text-sm hover:bg-white/25",
|
|
3113
|
+
children: [
|
|
3114
|
+
/* @__PURE__ */ jsx(RotateCw, { className: "size-4" }),
|
|
3115
|
+
t.retry
|
|
3116
|
+
]
|
|
3117
|
+
}
|
|
3118
|
+
)
|
|
3119
|
+
] }),
|
|
3120
|
+
state === "ready" && autoplayState === "blocked" && /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/40", children: /* @__PURE__ */ jsx(
|
|
3121
|
+
"button",
|
|
3122
|
+
{
|
|
3123
|
+
type: "button",
|
|
3124
|
+
"aria-label": t.play,
|
|
3125
|
+
onClick: togglePlay,
|
|
3126
|
+
className: "flex size-16 items-center justify-center rounded-full bg-white/20 backdrop-blur-sm transition hover:bg-white/30",
|
|
3127
|
+
children: /* @__PURE__ */ jsx(Play, { className: "size-8 translate-x-0.5", fill: "currentColor" })
|
|
3128
|
+
}
|
|
3129
|
+
) }),
|
|
3130
|
+
state === "ready" && autoplayState === "muted" && /* @__PURE__ */ jsxs(
|
|
3131
|
+
"button",
|
|
3132
|
+
{
|
|
3133
|
+
type: "button",
|
|
3134
|
+
onClick: toggleMute,
|
|
3135
|
+
className: "absolute top-3 right-3 flex items-center gap-1.5 rounded-full bg-black/70 px-3 py-1.5 text-xs backdrop-blur-sm transition hover:bg-black/90",
|
|
3136
|
+
children: [
|
|
3137
|
+
/* @__PURE__ */ jsx(VolumeX, { className: "size-4" }),
|
|
3138
|
+
t.tapToUnmute
|
|
3139
|
+
]
|
|
3140
|
+
}
|
|
3141
|
+
),
|
|
3142
|
+
mode === "live" && active && state === "ready" && /* @__PURE__ */ jsxs("div", { className: "absolute top-3 left-3 flex items-center gap-2", children: [
|
|
3143
|
+
/* @__PURE__ */ jsxs("span", { className: "flex items-center gap-1.5 rounded bg-red-600 px-2 py-0.5 text-xs font-semibold tracking-wide", children: [
|
|
3144
|
+
/* @__PURE__ */ jsx("span", { className: "size-1.5 animate-pulse rounded-full bg-white" }),
|
|
3145
|
+
t.live
|
|
3146
|
+
] }),
|
|
3147
|
+
typeof stats?.viewers === "number" && /* @__PURE__ */ jsx("span", { className: "rounded bg-black/60 px-2 py-0.5 text-xs", children: t.formatViewers ? t.formatViewers(stats.viewers) : `\u{1F441} ${stats.viewers}` })
|
|
3148
|
+
] }),
|
|
3149
|
+
active && /* @__PURE__ */ jsxs(
|
|
3150
|
+
"div",
|
|
3151
|
+
{
|
|
3152
|
+
className: cn(
|
|
3153
|
+
"absolute inset-x-0 bottom-0 flex flex-col gap-1 bg-gradient-to-t from-black/80 to-transparent px-3 pt-8 pb-2 transition-opacity",
|
|
3154
|
+
showControls ? "opacity-100" : "pointer-events-none opacity-0"
|
|
3155
|
+
),
|
|
3156
|
+
"data-slot": "video-controls",
|
|
3157
|
+
children: [
|
|
3158
|
+
mode === "vod" && /* @__PURE__ */ jsxs("div", { className: "relative w-full", children: [
|
|
3159
|
+
/* @__PURE__ */ jsx(
|
|
3160
|
+
Slider,
|
|
3161
|
+
{
|
|
3162
|
+
"aria-label": "Seek",
|
|
3163
|
+
min: 0,
|
|
3164
|
+
max: duration || 0,
|
|
3165
|
+
step: 0.1,
|
|
3166
|
+
value: [Math.min(currentTime, duration || 0)],
|
|
3167
|
+
onValueChange: (v) => seekTo(v[0] ?? 0),
|
|
3168
|
+
className: "w-full"
|
|
3169
|
+
}
|
|
3170
|
+
),
|
|
3171
|
+
duration > 0 && buffered > currentTime && /* @__PURE__ */ jsx(
|
|
3172
|
+
"span",
|
|
3173
|
+
{
|
|
3174
|
+
"aria-hidden": "true",
|
|
3175
|
+
className: "pointer-events-none absolute top-1/2 left-0 h-1.5 -translate-y-1/2 rounded-full bg-white/25",
|
|
3176
|
+
style: {
|
|
3177
|
+
width: `${Math.min(buffered / duration * 100, 100)}%`
|
|
3178
|
+
}
|
|
3179
|
+
}
|
|
3180
|
+
)
|
|
3181
|
+
] }),
|
|
3182
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
3183
|
+
/* @__PURE__ */ jsx(
|
|
3184
|
+
ControlButton,
|
|
3185
|
+
{
|
|
3186
|
+
label: isPlaying ? t.pause : t.play,
|
|
3187
|
+
onClick: togglePlay,
|
|
3188
|
+
children: isPlaying ? /* @__PURE__ */ jsx(Pause, { className: "size-5", fill: "currentColor" }) : /* @__PURE__ */ jsx(Play, { className: "size-5", fill: "currentColor" })
|
|
3189
|
+
}
|
|
3190
|
+
),
|
|
3191
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1", children: [
|
|
3192
|
+
/* @__PURE__ */ jsx(
|
|
3193
|
+
ControlButton,
|
|
3194
|
+
{
|
|
3195
|
+
label: isMuted ? t.unmute : t.mute,
|
|
3196
|
+
onClick: toggleMute,
|
|
3197
|
+
children: /* @__PURE__ */ jsx(VolumeIcon, { className: "size-5" })
|
|
3198
|
+
}
|
|
3199
|
+
),
|
|
3200
|
+
/* @__PURE__ */ jsx("div", { className: "w-20 px-1", children: /* @__PURE__ */ jsx(
|
|
3201
|
+
Slider,
|
|
3202
|
+
{
|
|
3203
|
+
"aria-label": "Volume",
|
|
3204
|
+
min: 0,
|
|
3205
|
+
max: 1,
|
|
3206
|
+
step: 0.05,
|
|
3207
|
+
value: [isMuted ? 0 : volume],
|
|
3208
|
+
onValueChange: (v) => changeVolume(v[0] ?? 0)
|
|
3209
|
+
}
|
|
3210
|
+
) })
|
|
3211
|
+
] }),
|
|
3212
|
+
mode === "vod" && /* @__PURE__ */ jsxs("span", { className: "ml-1 text-xs tabular-nums", children: [
|
|
3213
|
+
formatTime(currentTime),
|
|
3214
|
+
" / ",
|
|
3215
|
+
formatTime(duration)
|
|
3216
|
+
] }),
|
|
3217
|
+
mode === "live" && behindLive && /* @__PURE__ */ jsxs(
|
|
3218
|
+
"button",
|
|
3219
|
+
{
|
|
3220
|
+
type: "button",
|
|
3221
|
+
onClick: goToLiveEdge,
|
|
3222
|
+
className: "ml-1 flex items-center gap-1 rounded bg-white/15 px-2 py-0.5 text-xs hover:bg-white/25",
|
|
3223
|
+
children: [
|
|
3224
|
+
/* @__PURE__ */ jsx("span", { className: "size-1.5 rounded-full bg-red-500" }),
|
|
3225
|
+
t.goLive
|
|
3226
|
+
]
|
|
3227
|
+
}
|
|
3228
|
+
),
|
|
3229
|
+
/* @__PURE__ */ jsxs("div", { className: "ml-auto flex items-center gap-1", children: [
|
|
3230
|
+
mode === "vod" && typeof stats?.views === "number" && /* @__PURE__ */ jsx("span", { className: "mr-1 text-xs", children: t.formatViews ? t.formatViews(stats.views) : `${stats.views} views` }),
|
|
3231
|
+
mode === "vod" && /* @__PURE__ */ jsx(
|
|
3232
|
+
MenuControl,
|
|
3233
|
+
{
|
|
3234
|
+
label: t.speed,
|
|
3235
|
+
open: openMenu === "speed",
|
|
3236
|
+
onOpenChange: (o) => setOpenMenu(o ? "speed" : null),
|
|
3237
|
+
trigger: /* @__PURE__ */ jsxs("span", { className: "text-xs font-semibold", children: [
|
|
3238
|
+
playbackRate,
|
|
3239
|
+
"\xD7"
|
|
3240
|
+
] }),
|
|
3241
|
+
children: PLAYBACK_RATES.map((rate) => /* @__PURE__ */ jsxs(
|
|
3242
|
+
MenuItem,
|
|
3243
|
+
{
|
|
3244
|
+
selected: rate === playbackRate,
|
|
3245
|
+
onSelect: () => changeRate(rate),
|
|
3246
|
+
children: [
|
|
3247
|
+
rate,
|
|
3248
|
+
"\xD7"
|
|
3249
|
+
]
|
|
3250
|
+
},
|
|
3251
|
+
rate
|
|
3252
|
+
))
|
|
3253
|
+
}
|
|
3254
|
+
),
|
|
3255
|
+
showQualitySelector && qualities.length > 1 && /* @__PURE__ */ jsxs(
|
|
3256
|
+
MenuControl,
|
|
3257
|
+
{
|
|
3258
|
+
label: t.quality,
|
|
3259
|
+
open: openMenu === "quality",
|
|
3260
|
+
onOpenChange: (o) => setOpenMenu(o ? "quality" : null),
|
|
3261
|
+
trigger: /* @__PURE__ */ jsx(Settings, { className: "size-5" }),
|
|
3262
|
+
triggerBadge: currentLevelLabel,
|
|
3263
|
+
children: [
|
|
3264
|
+
/* @__PURE__ */ jsx(
|
|
3265
|
+
MenuItem,
|
|
3266
|
+
{
|
|
3267
|
+
selected: activeLevel < 0,
|
|
3268
|
+
onSelect: () => chooseLevel(-1),
|
|
3269
|
+
children: t.auto
|
|
3270
|
+
}
|
|
3271
|
+
),
|
|
3272
|
+
qualities.map((q) => /* @__PURE__ */ jsxs(
|
|
3273
|
+
MenuItem,
|
|
3274
|
+
{
|
|
3275
|
+
selected: activeLevel === q.index,
|
|
3276
|
+
onSelect: () => chooseLevel(q.index),
|
|
3277
|
+
children: [
|
|
3278
|
+
q.height,
|
|
3279
|
+
"p"
|
|
3280
|
+
]
|
|
3281
|
+
},
|
|
3282
|
+
q.index
|
|
3283
|
+
))
|
|
3284
|
+
]
|
|
3285
|
+
}
|
|
3286
|
+
),
|
|
3287
|
+
pipSupported && /* @__PURE__ */ jsx(ControlButton, { label: t.pictureInPicture, onClick: togglePip, children: /* @__PURE__ */ jsx(
|
|
3288
|
+
PictureInPicture2,
|
|
3289
|
+
{
|
|
3290
|
+
className: cn("size-5", pipActive && "text-primary")
|
|
3291
|
+
}
|
|
3292
|
+
) }),
|
|
3293
|
+
fullscreenSupported && /* @__PURE__ */ jsx(
|
|
3294
|
+
ControlButton,
|
|
3295
|
+
{
|
|
3296
|
+
label: isFullscreen ? t.exitFullscreen : t.enterFullscreen,
|
|
3297
|
+
onClick: toggleFullscreen,
|
|
3298
|
+
children: isFullscreen ? /* @__PURE__ */ jsx(Minimize, { className: "size-5" }) : /* @__PURE__ */ jsx(Maximize, { className: "size-5" })
|
|
3299
|
+
}
|
|
3300
|
+
)
|
|
3301
|
+
] })
|
|
3302
|
+
] })
|
|
3303
|
+
]
|
|
3304
|
+
}
|
|
3305
|
+
)
|
|
3306
|
+
]
|
|
3307
|
+
}
|
|
3308
|
+
);
|
|
3309
|
+
}
|
|
3310
|
+
function ControlButton({
|
|
3311
|
+
label,
|
|
3312
|
+
onClick,
|
|
3313
|
+
children
|
|
3314
|
+
}) {
|
|
3315
|
+
return /* @__PURE__ */ jsx(
|
|
3316
|
+
"button",
|
|
3317
|
+
{
|
|
3318
|
+
type: "button",
|
|
3319
|
+
"aria-label": label,
|
|
3320
|
+
title: label,
|
|
3321
|
+
onClick,
|
|
3322
|
+
className: "flex size-8 items-center justify-center rounded-md text-white/90 outline-none hover:bg-white/15 hover:text-white focus-visible:ring-2 focus-visible:ring-white/60",
|
|
3323
|
+
children
|
|
3324
|
+
}
|
|
3325
|
+
);
|
|
3326
|
+
}
|
|
3327
|
+
function MenuControl({
|
|
3328
|
+
label,
|
|
3329
|
+
open,
|
|
3330
|
+
onOpenChange,
|
|
3331
|
+
trigger,
|
|
3332
|
+
triggerBadge,
|
|
3333
|
+
children
|
|
3334
|
+
}) {
|
|
3335
|
+
return /* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
3336
|
+
/* @__PURE__ */ jsxs(
|
|
3337
|
+
"button",
|
|
3338
|
+
{
|
|
3339
|
+
type: "button",
|
|
3340
|
+
"aria-label": label,
|
|
3341
|
+
"aria-haspopup": "menu",
|
|
3342
|
+
"aria-expanded": open,
|
|
3343
|
+
title: label,
|
|
3344
|
+
onClick: () => onOpenChange(!open),
|
|
3345
|
+
className: "flex h-8 items-center gap-1 rounded-md px-1.5 text-white/90 outline-none hover:bg-white/15 hover:text-white focus-visible:ring-2 focus-visible:ring-white/60",
|
|
3346
|
+
children: [
|
|
3347
|
+
trigger,
|
|
3348
|
+
triggerBadge && /* @__PURE__ */ jsx("span", { className: "text-[10px] font-medium", children: triggerBadge })
|
|
3349
|
+
]
|
|
3350
|
+
}
|
|
3351
|
+
),
|
|
3352
|
+
open && /* @__PURE__ */ jsx(
|
|
3353
|
+
"div",
|
|
3354
|
+
{
|
|
3355
|
+
role: "menu",
|
|
3356
|
+
className: "absolute right-0 bottom-full z-10 mb-2 min-w-24 rounded-md bg-black/90 p-1 text-sm shadow-lg backdrop-blur-sm",
|
|
3357
|
+
children
|
|
3358
|
+
}
|
|
3359
|
+
)
|
|
3360
|
+
] });
|
|
3361
|
+
}
|
|
3362
|
+
function MenuItem({
|
|
3363
|
+
selected,
|
|
3364
|
+
onSelect,
|
|
3365
|
+
children
|
|
3366
|
+
}) {
|
|
3367
|
+
return /* @__PURE__ */ jsxs(
|
|
3368
|
+
"button",
|
|
3369
|
+
{
|
|
3370
|
+
type: "button",
|
|
3371
|
+
role: "menuitemradio",
|
|
3372
|
+
"aria-checked": selected,
|
|
3373
|
+
onClick: onSelect,
|
|
3374
|
+
className: "flex w-full items-center justify-between gap-3 rounded px-2 py-1.5 text-left text-white/90 hover:bg-white/15",
|
|
3375
|
+
children: [
|
|
3376
|
+
children,
|
|
3377
|
+
selected && /* @__PURE__ */ jsx(Check, { className: "size-4" })
|
|
3378
|
+
]
|
|
3379
|
+
}
|
|
3380
|
+
);
|
|
3381
|
+
}
|
|
3382
|
+
|
|
3383
|
+
// src/components/video/feedPlaybackCoordinator.ts
|
|
3384
|
+
var players = /* @__PURE__ */ new Map();
|
|
3385
|
+
function registerFeedPlayer(id, pause) {
|
|
3386
|
+
players.set(id, pause);
|
|
3387
|
+
return () => {
|
|
3388
|
+
if (players.get(id) === pause) {
|
|
3389
|
+
players.delete(id);
|
|
3390
|
+
}
|
|
3391
|
+
};
|
|
3392
|
+
}
|
|
3393
|
+
function claimFeedPlaying(id) {
|
|
3394
|
+
for (const [otherId, pause] of players) {
|
|
3395
|
+
if (otherId !== id) pause();
|
|
3396
|
+
}
|
|
3397
|
+
}
|
|
3398
|
+
|
|
3399
|
+
// src/components/video/useFeedExclusivePlayback.ts
|
|
3400
|
+
var VISIBILITY_THRESHOLDS = [0, 0.5, 1];
|
|
3401
|
+
var MIN_VISIBLE_RATIO = 0.5;
|
|
3402
|
+
function videoInPictureInPicture(container) {
|
|
3403
|
+
if (typeof document === "undefined" || !container) return false;
|
|
3404
|
+
const pip = document.pictureInPictureElement;
|
|
3405
|
+
if (!pip) return false;
|
|
3406
|
+
return container.contains(pip);
|
|
3407
|
+
}
|
|
3408
|
+
function useFeedExclusivePlayback(playbackId) {
|
|
3409
|
+
const containerRef = React3.useRef(null);
|
|
3410
|
+
const [forcePaused, setForcePaused] = React3.useState(false);
|
|
3411
|
+
const requestPause = React3.useCallback(() => {
|
|
3412
|
+
if (videoInPictureInPicture(containerRef.current)) return;
|
|
3413
|
+
setForcePaused(true);
|
|
3414
|
+
}, []);
|
|
3415
|
+
React3.useEffect(() => {
|
|
3416
|
+
return registerFeedPlayer(playbackId, requestPause);
|
|
3417
|
+
}, [playbackId, requestPause]);
|
|
3418
|
+
React3.useEffect(() => {
|
|
3419
|
+
const node = containerRef.current;
|
|
3420
|
+
if (!node || typeof IntersectionObserver === "undefined") return;
|
|
3421
|
+
const observer = new IntersectionObserver(
|
|
3422
|
+
(entries) => {
|
|
3423
|
+
const entry = entries[0];
|
|
3424
|
+
if (!entry) return;
|
|
3425
|
+
if (!entry.isIntersecting || entry.intersectionRatio < MIN_VISIBLE_RATIO) {
|
|
3426
|
+
requestPause();
|
|
3427
|
+
}
|
|
3428
|
+
},
|
|
3429
|
+
{ threshold: [...VISIBILITY_THRESHOLDS] }
|
|
3430
|
+
);
|
|
3431
|
+
observer.observe(node);
|
|
3432
|
+
return () => observer.disconnect();
|
|
3433
|
+
}, [requestPause]);
|
|
3434
|
+
React3.useEffect(() => {
|
|
3435
|
+
const onVisibility = () => {
|
|
3436
|
+
if (document.hidden) requestPause();
|
|
3437
|
+
};
|
|
3438
|
+
document.addEventListener("visibilitychange", onVisibility);
|
|
3439
|
+
return () => document.removeEventListener("visibilitychange", onVisibility);
|
|
3440
|
+
}, [requestPause]);
|
|
3441
|
+
const onPlayingChange = React3.useCallback(
|
|
3442
|
+
(playing) => {
|
|
3443
|
+
if (!playing) return;
|
|
3444
|
+
setForcePaused(false);
|
|
3445
|
+
claimFeedPlaying(playbackId);
|
|
3446
|
+
},
|
|
3447
|
+
[playbackId]
|
|
3448
|
+
);
|
|
3449
|
+
return {
|
|
3450
|
+
containerRef,
|
|
3451
|
+
paused: forcePaused,
|
|
3452
|
+
onPlayingChange
|
|
3453
|
+
};
|
|
3454
|
+
}
|
|
3455
|
+
function FeedVideoPlayer({
|
|
3456
|
+
playbackId,
|
|
3457
|
+
onPlayingChange,
|
|
3458
|
+
paused: pausedProp,
|
|
3459
|
+
fit = "aspect-video",
|
|
3460
|
+
className,
|
|
3461
|
+
...playerProps
|
|
3462
|
+
}) {
|
|
3463
|
+
const {
|
|
3464
|
+
containerRef,
|
|
3465
|
+
paused: exclusivePaused,
|
|
3466
|
+
onPlayingChange: onExclusivePlayingChange
|
|
3467
|
+
} = useFeedExclusivePlayback(playbackId);
|
|
3468
|
+
const handlePlayingChange = React3.useCallback(
|
|
3469
|
+
(playing) => {
|
|
3470
|
+
onExclusivePlayingChange(playing);
|
|
3471
|
+
onPlayingChange?.(playing);
|
|
3472
|
+
},
|
|
3473
|
+
[onExclusivePlayingChange, onPlayingChange]
|
|
3474
|
+
);
|
|
3475
|
+
return /* @__PURE__ */ jsx(
|
|
3476
|
+
"div",
|
|
3477
|
+
{
|
|
3478
|
+
ref: containerRef,
|
|
3479
|
+
"data-slot": "feed-video-player",
|
|
3480
|
+
className: cn(fit === "contain" && "h-full min-h-0 w-full", className),
|
|
3481
|
+
children: /* @__PURE__ */ jsx(
|
|
3482
|
+
VideoPlayer,
|
|
3483
|
+
{
|
|
3484
|
+
...playerProps,
|
|
3485
|
+
fit,
|
|
3486
|
+
paused: pausedProp || exclusivePaused,
|
|
3487
|
+
onPlayingChange: handlePlayingChange,
|
|
3488
|
+
className: fit === "contain" ? "h-full min-h-0" : void 0
|
|
3489
|
+
}
|
|
3490
|
+
)
|
|
3491
|
+
}
|
|
3492
|
+
);
|
|
3493
|
+
}
|
|
3494
|
+
function usePlaybackStats(statsUrl, { intervalMs = 15e3, enabled = true } = {}) {
|
|
3495
|
+
const [stats, setStats] = React3.useState({});
|
|
3496
|
+
React3.useEffect(() => {
|
|
3497
|
+
if (!statsUrl || !enabled) return;
|
|
3498
|
+
let cancelled = false;
|
|
3499
|
+
const controller = new AbortController();
|
|
3500
|
+
async function poll() {
|
|
3501
|
+
try {
|
|
3502
|
+
const res = await fetch(statsUrl, {
|
|
3503
|
+
signal: controller.signal
|
|
3504
|
+
});
|
|
3505
|
+
if (!res.ok) return;
|
|
3506
|
+
const data = await res.json();
|
|
3507
|
+
if (cancelled) return;
|
|
3508
|
+
setStats({
|
|
3509
|
+
viewers: typeof data.viewers === "number" ? data.viewers : void 0,
|
|
3510
|
+
views: typeof data.views === "number" ? data.views : void 0
|
|
3511
|
+
});
|
|
3512
|
+
} catch {
|
|
3513
|
+
}
|
|
3514
|
+
}
|
|
3515
|
+
void poll();
|
|
3516
|
+
const timer = setInterval(() => void poll(), intervalMs);
|
|
3517
|
+
return () => {
|
|
3518
|
+
cancelled = true;
|
|
3519
|
+
controller.abort();
|
|
3520
|
+
clearInterval(timer);
|
|
3521
|
+
};
|
|
3522
|
+
}, [statsUrl, intervalMs, enabled]);
|
|
3523
|
+
return stats;
|
|
3524
|
+
}
|
|
3525
|
+
function useMediaQuery2(query) {
|
|
3526
|
+
const [matches, setMatches] = useState(false);
|
|
3527
|
+
useEffect(() => {
|
|
3528
|
+
if (typeof window === "undefined" || !window.matchMedia) return;
|
|
3529
|
+
const mql = window.matchMedia(query);
|
|
3530
|
+
const onChange = () => setMatches(mql.matches);
|
|
3531
|
+
onChange();
|
|
3532
|
+
mql.addEventListener("change", onChange);
|
|
3533
|
+
return () => mql.removeEventListener("change", onChange);
|
|
3534
|
+
}, [query]);
|
|
3535
|
+
return matches;
|
|
3536
|
+
}
|
|
3537
|
+
|
|
3538
|
+
// src/lib/avatar.ts
|
|
3539
|
+
var EMPTY_COLORS = {
|
|
3540
|
+
backgroundColor: "#9ca3af",
|
|
3541
|
+
color: "#111111"
|
|
3542
|
+
};
|
|
3543
|
+
var AVATAR_PALETTE = [
|
|
3544
|
+
"#4f6d8c",
|
|
3545
|
+
// slate blue
|
|
3546
|
+
"#3d7a6a",
|
|
3547
|
+
// teal
|
|
3548
|
+
"#6b5b8a",
|
|
3549
|
+
// muted purple
|
|
3550
|
+
"#8a5a4a",
|
|
3551
|
+
// warm brown
|
|
3552
|
+
"#4a7a8a",
|
|
3553
|
+
// steel cyan
|
|
3554
|
+
"#7a6b4a",
|
|
3555
|
+
// olive
|
|
3556
|
+
"#5a6b8a",
|
|
3557
|
+
// periwinkle
|
|
3558
|
+
"#8a4a5a",
|
|
3559
|
+
// rose
|
|
3560
|
+
"#4a8a6b",
|
|
3561
|
+
// green
|
|
3562
|
+
"#6b4a7a",
|
|
3563
|
+
// plum
|
|
3564
|
+
"#8a6b4a",
|
|
3565
|
+
// amber brown
|
|
3566
|
+
"#4a5a8a",
|
|
3567
|
+
// indigo
|
|
3568
|
+
"#7a4a6b",
|
|
3569
|
+
// mauve
|
|
3570
|
+
"#5a8a4a",
|
|
3571
|
+
// leaf
|
|
3572
|
+
"#8a5a7a",
|
|
3573
|
+
// dusty pink
|
|
3574
|
+
"#3d6b7a"
|
|
3575
|
+
// deep teal
|
|
3576
|
+
];
|
|
3577
|
+
function hashString(input) {
|
|
3578
|
+
let hash = 2166136261;
|
|
3579
|
+
for (let i = 0; i < input.length; i++) {
|
|
3580
|
+
hash ^= input.charCodeAt(i);
|
|
3581
|
+
hash = Math.imul(hash, 16777619);
|
|
3582
|
+
}
|
|
3583
|
+
return hash >>> 0;
|
|
3584
|
+
}
|
|
3585
|
+
function srgbToLinear(channel) {
|
|
3586
|
+
const c = channel / 255;
|
|
3587
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4;
|
|
3588
|
+
}
|
|
3589
|
+
function relativeLuminance(hex) {
|
|
3590
|
+
const normalized = hex.replace("#", "");
|
|
3591
|
+
const r = Number.parseInt(normalized.slice(0, 2), 16);
|
|
3592
|
+
const g = Number.parseInt(normalized.slice(2, 4), 16);
|
|
3593
|
+
const b = Number.parseInt(normalized.slice(4, 6), 16);
|
|
3594
|
+
return 0.2126 * srgbToLinear(r) + 0.7152 * srgbToLinear(g) + 0.0722 * srgbToLinear(b);
|
|
3595
|
+
}
|
|
3596
|
+
function contrastingTextColor(backgroundHex) {
|
|
3597
|
+
return relativeLuminance(backgroundHex) > 0.179 ? "#111111" : "#ffffff";
|
|
3598
|
+
}
|
|
3599
|
+
function getInitials(name, max = 2) {
|
|
3600
|
+
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
3601
|
+
if (parts.length === 0) return "?";
|
|
3602
|
+
return parts.slice(0, Math.max(1, max)).map((part) => part.charAt(0)).join("").toUpperCase();
|
|
3603
|
+
}
|
|
3604
|
+
function getAvatarColors(name) {
|
|
3605
|
+
const normalized = name.trim().toLowerCase();
|
|
3606
|
+
if (!normalized) {
|
|
3607
|
+
return { ...EMPTY_COLORS };
|
|
3608
|
+
}
|
|
3609
|
+
const backgroundColor = AVATAR_PALETTE[hashString(normalized) % AVATAR_PALETTE.length];
|
|
3610
|
+
return {
|
|
3611
|
+
backgroundColor,
|
|
3612
|
+
color: contrastingTextColor(backgroundColor)
|
|
3613
|
+
};
|
|
3614
|
+
}
|
|
3615
|
+
function avatarFallbackStyle(name) {
|
|
3616
|
+
return getAvatarColors(name);
|
|
3617
|
+
}
|
|
3618
|
+
|
|
3619
|
+
export { AvatarEditor, AvatarEditorDialog, ConfirmDestructiveDialog, DEFAULT_EDITABLE_SECTION_LABELS, DataList, DataListItem, EditableSection, Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyState, EmptyTitle, ErrorState, FeedVideoPlayer, FieldMessage, LanguageContext, LanguageSwitcher, LoadingState, SafeImage, ThemeSwitcher, VideoPlayer, avatarFallbackStyle, cn, createLiveHlsConfig, createVodHlsConfig, defaultLanguages, describeAvResync, describePlaybackError, getAvatarColors, getInitials, shouldRetryLiveEdge404, useEditableSection, useFeedExclusivePlayback, useHlsPlayback, useLanguageContext, useMediaQuery2 as useMediaQuery, usePlaybackStats };
|
|
3620
|
+
//# sourceMappingURL=index.js.map
|
|
3621
|
+
//# sourceMappingURL=index.js.map
|