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