@livo-tv/blocks 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +608 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +118 -4
- package/dist/index.d.ts +118 -4
- package/dist/index.js +600 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2258,6 +2258,37 @@ function AvatarEditorDialog({
|
|
|
2258
2258
|
] }) })
|
|
2259
2259
|
] });
|
|
2260
2260
|
}
|
|
2261
|
+
var DEFAULT_LABELS2 = {
|
|
2262
|
+
play: "Play",
|
|
2263
|
+
tapToUnmute: "Tap to unmute",
|
|
2264
|
+
mute: "Mute",
|
|
2265
|
+
unmute: "Unmute"
|
|
2266
|
+
};
|
|
2267
|
+
var CURTAIN_VIDEO_STYLE = `
|
|
2268
|
+
.livo-curtain-video::-webkit-media-controls-start-playback-button {
|
|
2269
|
+
display: none !important;
|
|
2270
|
+
-webkit-appearance: none;
|
|
2271
|
+
}
|
|
2272
|
+
.livo-curtain-video::-webkit-media-controls {
|
|
2273
|
+
display: none !important;
|
|
2274
|
+
}
|
|
2275
|
+
`;
|
|
2276
|
+
function isAudioTrackList(value) {
|
|
2277
|
+
return typeof value === "object" && value !== null && typeof value.getTrackById === "function";
|
|
2278
|
+
}
|
|
2279
|
+
function probeVideoAudio(el) {
|
|
2280
|
+
const video = el;
|
|
2281
|
+
if (typeof video.mozHasAudio === "boolean") {
|
|
2282
|
+
return video.mozHasAudio ? "yes" : "no";
|
|
2283
|
+
}
|
|
2284
|
+
if (typeof video.webkitAudioDecodedByteCount === "number" && video.webkitAudioDecodedByteCount > 0) {
|
|
2285
|
+
return "yes";
|
|
2286
|
+
}
|
|
2287
|
+
if (isAudioTrackList(video.audioTracks)) {
|
|
2288
|
+
return video.audioTracks.length > 0 ? "yes" : "no";
|
|
2289
|
+
}
|
|
2290
|
+
return "unknown";
|
|
2291
|
+
}
|
|
2261
2292
|
function usePrefersReducedMotion() {
|
|
2262
2293
|
const [reduced, setReduced] = React7__namespace.useState(false);
|
|
2263
2294
|
React7__namespace.useEffect(() => {
|
|
@@ -2269,39 +2300,154 @@ function usePrefersReducedMotion() {
|
|
|
2269
2300
|
}, []);
|
|
2270
2301
|
return reduced;
|
|
2271
2302
|
}
|
|
2272
|
-
function
|
|
2273
|
-
kind,
|
|
2303
|
+
function CurtainVideo({
|
|
2274
2304
|
url,
|
|
2275
|
-
alt
|
|
2305
|
+
alt,
|
|
2276
2306
|
className,
|
|
2277
|
-
|
|
2307
|
+
freeze,
|
|
2308
|
+
allowSound,
|
|
2309
|
+
labels
|
|
2278
2310
|
}) {
|
|
2279
|
-
const
|
|
2280
|
-
const
|
|
2281
|
-
|
|
2282
|
-
|
|
2311
|
+
const videoRef = React7__namespace.useRef(null);
|
|
2312
|
+
const [playback, setPlayback] = React7__namespace.useState("pending");
|
|
2313
|
+
const [muted, setMuted] = React7__namespace.useState(true);
|
|
2314
|
+
const [audio, setAudio] = React7__namespace.useState("unknown");
|
|
2315
|
+
React7__namespace.useEffect(() => {
|
|
2316
|
+
const el = videoRef.current;
|
|
2317
|
+
if (!el) return;
|
|
2318
|
+
el.setAttribute("webkit-playsinline", "");
|
|
2319
|
+
el.muted = true;
|
|
2320
|
+
setMuted(true);
|
|
2321
|
+
setAudio("unknown");
|
|
2322
|
+
setPlayback("pending");
|
|
2323
|
+
if (freeze) {
|
|
2324
|
+
el.pause();
|
|
2325
|
+
return;
|
|
2326
|
+
}
|
|
2327
|
+
let cancelled = false;
|
|
2328
|
+
const applyAudio = () => {
|
|
2329
|
+
const next = probeVideoAudio(el);
|
|
2330
|
+
if (next !== "unknown") setAudio(next);
|
|
2331
|
+
};
|
|
2332
|
+
const tryPlay = () => {
|
|
2333
|
+
if (cancelled) return;
|
|
2334
|
+
void el.play().then(
|
|
2335
|
+
() => {
|
|
2336
|
+
if (cancelled) return;
|
|
2337
|
+
setPlayback("playing");
|
|
2338
|
+
applyAudio();
|
|
2339
|
+
},
|
|
2340
|
+
() => {
|
|
2341
|
+
if (!cancelled && el.paused) setPlayback("blocked");
|
|
2342
|
+
}
|
|
2343
|
+
);
|
|
2344
|
+
};
|
|
2345
|
+
tryPlay();
|
|
2346
|
+
el.addEventListener("canplay", tryPlay);
|
|
2347
|
+
el.addEventListener("timeupdate", applyAudio);
|
|
2348
|
+
el.addEventListener("loadedmetadata", applyAudio);
|
|
2349
|
+
return () => {
|
|
2350
|
+
cancelled = true;
|
|
2351
|
+
el.removeEventListener("canplay", tryPlay);
|
|
2352
|
+
el.removeEventListener("timeupdate", applyAudio);
|
|
2353
|
+
el.removeEventListener("loadedmetadata", applyAudio);
|
|
2354
|
+
};
|
|
2355
|
+
}, [url, freeze]);
|
|
2356
|
+
const startPlayback = React7__namespace.useCallback(() => {
|
|
2357
|
+
const el = videoRef.current;
|
|
2358
|
+
if (!el) return;
|
|
2359
|
+
el.muted = true;
|
|
2360
|
+
setMuted(true);
|
|
2361
|
+
void el.play().then(
|
|
2362
|
+
() => {
|
|
2363
|
+
setPlayback("playing");
|
|
2364
|
+
const next = probeVideoAudio(el);
|
|
2365
|
+
if (next !== "unknown") setAudio(next);
|
|
2366
|
+
},
|
|
2367
|
+
() => {
|
|
2368
|
+
if (el.paused) setPlayback("blocked");
|
|
2369
|
+
}
|
|
2370
|
+
);
|
|
2371
|
+
}, []);
|
|
2372
|
+
const setVideoMuted = React7__namespace.useCallback((next) => {
|
|
2373
|
+
const el = videoRef.current;
|
|
2374
|
+
if (el) el.muted = next;
|
|
2375
|
+
setMuted(next);
|
|
2376
|
+
}, []);
|
|
2377
|
+
const showUnmute = allowSound && !freeze && playback === "playing" && muted && audio !== "no";
|
|
2378
|
+
const showMute = allowSound && !freeze && playback === "playing" && !muted;
|
|
2379
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("relative h-full w-full", className), children: [
|
|
2380
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: CURTAIN_VIDEO_STYLE }),
|
|
2381
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2283
2382
|
"video",
|
|
2284
2383
|
{
|
|
2384
|
+
ref: videoRef,
|
|
2285
2385
|
src: url,
|
|
2286
|
-
className:
|
|
2287
|
-
autoPlay:
|
|
2288
|
-
muted
|
|
2289
|
-
loop:
|
|
2386
|
+
className: "livo-curtain-video h-full w-full object-cover",
|
|
2387
|
+
autoPlay: !freeze,
|
|
2388
|
+
muted,
|
|
2389
|
+
loop: !freeze,
|
|
2290
2390
|
playsInline: true,
|
|
2391
|
+
preload: freeze ? "metadata" : void 0,
|
|
2291
2392
|
"aria-hidden": alt ? void 0 : true
|
|
2292
2393
|
}
|
|
2293
|
-
)
|
|
2294
|
-
|
|
2295
|
-
|
|
2394
|
+
),
|
|
2395
|
+
playback === "blocked" && !freeze ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/40", children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
2396
|
+
"button",
|
|
2397
|
+
{
|
|
2398
|
+
type: "button",
|
|
2399
|
+
"aria-label": labels.play,
|
|
2400
|
+
onClick: startPlayback,
|
|
2401
|
+
className: "flex size-16 items-center justify-center rounded-full bg-white/20 backdrop-blur-sm transition hover:bg-white/30",
|
|
2402
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, { className: "size-8 translate-x-0.5", fill: "currentColor" })
|
|
2403
|
+
}
|
|
2404
|
+
) }) : null,
|
|
2405
|
+
showUnmute ? /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2406
|
+
"button",
|
|
2407
|
+
{
|
|
2408
|
+
type: "button",
|
|
2409
|
+
onClick: () => setVideoMuted(false),
|
|
2410
|
+
className: "absolute top-3 right-3 z-20 flex items-center gap-1.5 rounded-full bg-black/70 px-3 py-1.5 text-xs text-white backdrop-blur-sm transition hover:bg-black/90",
|
|
2411
|
+
children: [
|
|
2412
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.VolumeX, { className: "size-4" }),
|
|
2413
|
+
labels.tapToUnmute
|
|
2414
|
+
]
|
|
2415
|
+
}
|
|
2416
|
+
) : null,
|
|
2417
|
+
showMute ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2418
|
+
"button",
|
|
2419
|
+
{
|
|
2420
|
+
type: "button",
|
|
2421
|
+
"aria-label": labels.mute,
|
|
2422
|
+
onClick: () => setVideoMuted(true),
|
|
2423
|
+
className: "absolute top-3 right-3 z-20 flex items-center gap-1.5 rounded-full bg-black/70 px-3 py-1.5 text-xs text-white backdrop-blur-sm transition hover:bg-black/90",
|
|
2424
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Volume2, { className: "size-4" })
|
|
2425
|
+
}
|
|
2426
|
+
) : null
|
|
2427
|
+
] });
|
|
2428
|
+
}
|
|
2429
|
+
function CurtainStage({
|
|
2430
|
+
kind,
|
|
2431
|
+
url,
|
|
2432
|
+
alt = "",
|
|
2433
|
+
className,
|
|
2434
|
+
reducedMotion,
|
|
2435
|
+
allowSound = false,
|
|
2436
|
+
labels
|
|
2437
|
+
}) {
|
|
2438
|
+
const prefersReduced = usePrefersReducedMotion();
|
|
2439
|
+
const freeze = reducedMotion ?? prefersReduced;
|
|
2440
|
+
const copy = { ...DEFAULT_LABELS2, ...labels };
|
|
2441
|
+
if (kind === "video") {
|
|
2296
2442
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2297
|
-
|
|
2443
|
+
CurtainVideo,
|
|
2298
2444
|
{
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2445
|
+
url,
|
|
2446
|
+
alt,
|
|
2447
|
+
className,
|
|
2448
|
+
freeze,
|
|
2449
|
+
allowSound,
|
|
2450
|
+
labels: copy
|
|
2305
2451
|
}
|
|
2306
2452
|
);
|
|
2307
2453
|
}
|
|
@@ -2869,6 +3015,7 @@ function WaitingRoom({
|
|
|
2869
3015
|
{
|
|
2870
3016
|
kind: curtain.kind,
|
|
2871
3017
|
url: curtain.url,
|
|
3018
|
+
allowSound: true,
|
|
2872
3019
|
className: "absolute inset-0"
|
|
2873
3020
|
}
|
|
2874
3021
|
) : /* @__PURE__ */ jsxRuntime.jsx("div", { className: "absolute inset-0 bg-gradient-to-br from-zinc-900 to-zinc-950" }),
|
|
@@ -3425,7 +3572,7 @@ function useHlsPlayback({
|
|
|
3425
3572
|
retry
|
|
3426
3573
|
};
|
|
3427
3574
|
}
|
|
3428
|
-
var
|
|
3575
|
+
var DEFAULT_LABELS3 = {
|
|
3429
3576
|
play: "Play",
|
|
3430
3577
|
pause: "Pause",
|
|
3431
3578
|
mute: "Mute",
|
|
@@ -3493,7 +3640,7 @@ function VideoPlayer({
|
|
|
3493
3640
|
fit = "aspect-video",
|
|
3494
3641
|
className
|
|
3495
3642
|
}) {
|
|
3496
|
-
const t = { ...
|
|
3643
|
+
const t = { ...DEFAULT_LABELS3, ...labels };
|
|
3497
3644
|
const containerRef = React7__namespace.useRef(null);
|
|
3498
3645
|
const firstPlayFiredRef = React7__namespace.useRef(false);
|
|
3499
3646
|
const [userStarted, setUserStarted] = React7__namespace.useState(false);
|
|
@@ -4248,6 +4395,434 @@ function usePlaybackStats(statsUrl, { intervalMs = 15e3, enabled = true } = {})
|
|
|
4248
4395
|
return stats;
|
|
4249
4396
|
}
|
|
4250
4397
|
|
|
4398
|
+
// src/components/upload/part-math.ts
|
|
4399
|
+
function partRanges(fileSize, partSize) {
|
|
4400
|
+
if (partSize <= 0) {
|
|
4401
|
+
throw new Error("partSize must be greater than 0");
|
|
4402
|
+
}
|
|
4403
|
+
if (fileSize <= 0) {
|
|
4404
|
+
return [{ partNumber: 1, start: 0, end: 0 }];
|
|
4405
|
+
}
|
|
4406
|
+
const count = Math.ceil(fileSize / partSize);
|
|
4407
|
+
return Array.from({ length: count }, (_, index) => {
|
|
4408
|
+
const start = index * partSize;
|
|
4409
|
+
return {
|
|
4410
|
+
partNumber: index + 1,
|
|
4411
|
+
start,
|
|
4412
|
+
end: Math.min(fileSize, start + partSize)
|
|
4413
|
+
};
|
|
4414
|
+
});
|
|
4415
|
+
}
|
|
4416
|
+
function progressFromBytes(loaded, total) {
|
|
4417
|
+
const safeTotal = Math.max(0, total);
|
|
4418
|
+
const safeLoaded = Math.min(Math.max(0, loaded), safeTotal);
|
|
4419
|
+
const percent = safeTotal > 0 ? Math.round(safeLoaded / safeTotal * 100) : 0;
|
|
4420
|
+
return { loaded: safeLoaded, total: safeTotal, percent };
|
|
4421
|
+
}
|
|
4422
|
+
function fileMatchesAccept(file, accept) {
|
|
4423
|
+
if (!accept?.trim()) return true;
|
|
4424
|
+
const type = file.type.toLowerCase();
|
|
4425
|
+
const name = file.name.toLowerCase();
|
|
4426
|
+
return accept.split(",").some((token) => {
|
|
4427
|
+
const trimmed = token.trim().toLowerCase();
|
|
4428
|
+
if (!trimmed) return false;
|
|
4429
|
+
if (trimmed.endsWith("/*")) {
|
|
4430
|
+
return type.startsWith(trimmed.slice(0, -1));
|
|
4431
|
+
}
|
|
4432
|
+
if (trimmed.startsWith(".")) {
|
|
4433
|
+
return name.endsWith(trimmed);
|
|
4434
|
+
}
|
|
4435
|
+
return type === trimmed;
|
|
4436
|
+
});
|
|
4437
|
+
}
|
|
4438
|
+
|
|
4439
|
+
// src/components/upload/types.ts
|
|
4440
|
+
var DEFAULT_FILE_DROPZONE_LABELS = {
|
|
4441
|
+
idle: "Drop a file here or browse",
|
|
4442
|
+
hint: "Click or press Enter to choose a file",
|
|
4443
|
+
browse: "Browse",
|
|
4444
|
+
rejectType: "This file type is not allowed",
|
|
4445
|
+
rejectSize: "This file is too large"
|
|
4446
|
+
};
|
|
4447
|
+
var DEFAULT_FILE_UPLOAD_TRAY_LABELS = {
|
|
4448
|
+
title: "Uploads",
|
|
4449
|
+
pause: "Pause",
|
|
4450
|
+
resume: "Resume",
|
|
4451
|
+
cancel: "Cancel",
|
|
4452
|
+
uploading: "Uploading",
|
|
4453
|
+
paused: "Paused",
|
|
4454
|
+
completing: "Finishing",
|
|
4455
|
+
completed: "Uploaded",
|
|
4456
|
+
cancelled: "Cancelled",
|
|
4457
|
+
error: "Failed"
|
|
4458
|
+
};
|
|
4459
|
+
var DEFAULT_FILE_UPLOAD_LABELS = {
|
|
4460
|
+
dropzone: DEFAULT_FILE_DROPZONE_LABELS,
|
|
4461
|
+
tray: DEFAULT_FILE_UPLOAD_TRAY_LABELS
|
|
4462
|
+
};
|
|
4463
|
+
function FileDropzone({
|
|
4464
|
+
accept,
|
|
4465
|
+
maxSize,
|
|
4466
|
+
disabled = false,
|
|
4467
|
+
labels: labelOverrides,
|
|
4468
|
+
onFile,
|
|
4469
|
+
onReject,
|
|
4470
|
+
className
|
|
4471
|
+
}) {
|
|
4472
|
+
const labels = { ...DEFAULT_FILE_DROPZONE_LABELS, ...labelOverrides };
|
|
4473
|
+
const inputId = React7.useId();
|
|
4474
|
+
const inputRef = React7.useRef(null);
|
|
4475
|
+
const [dragging, setDragging] = React7.useState(false);
|
|
4476
|
+
const [message, setMessage] = React7.useState(null);
|
|
4477
|
+
function takeFile(file) {
|
|
4478
|
+
if (!file || disabled) return;
|
|
4479
|
+
if (!fileMatchesAccept(file, accept)) {
|
|
4480
|
+
setMessage(labels.rejectType);
|
|
4481
|
+
onReject?.("type");
|
|
4482
|
+
return;
|
|
4483
|
+
}
|
|
4484
|
+
if (maxSize != null && file.size > maxSize) {
|
|
4485
|
+
setMessage(labels.rejectSize);
|
|
4486
|
+
onReject?.("size");
|
|
4487
|
+
return;
|
|
4488
|
+
}
|
|
4489
|
+
setMessage(null);
|
|
4490
|
+
onFile(file);
|
|
4491
|
+
}
|
|
4492
|
+
function onDrop(event) {
|
|
4493
|
+
event.preventDefault();
|
|
4494
|
+
setDragging(false);
|
|
4495
|
+
takeFile(event.dataTransfer.files[0]);
|
|
4496
|
+
}
|
|
4497
|
+
function onKeyDown(event) {
|
|
4498
|
+
if (disabled) return;
|
|
4499
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
4500
|
+
event.preventDefault();
|
|
4501
|
+
inputRef.current?.click();
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4504
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("grid gap-2", className), children: [
|
|
4505
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
4506
|
+
"div",
|
|
4507
|
+
{
|
|
4508
|
+
role: "button",
|
|
4509
|
+
tabIndex: disabled ? -1 : 0,
|
|
4510
|
+
"aria-disabled": disabled,
|
|
4511
|
+
"aria-describedby": message ? `${inputId}-message` : `${inputId}-hint`,
|
|
4512
|
+
"aria-controls": inputId,
|
|
4513
|
+
"data-dragging": dragging || void 0,
|
|
4514
|
+
className: cn(
|
|
4515
|
+
"border-input bg-background focus-visible:border-ring focus-visible:ring-ring/50 rounded-lg border border-dashed px-4 py-8 text-center outline-none focus-visible:ring-[3px]",
|
|
4516
|
+
dragging && "border-primary bg-primary/5",
|
|
4517
|
+
disabled && "pointer-events-none opacity-50"
|
|
4518
|
+
),
|
|
4519
|
+
onClick: () => {
|
|
4520
|
+
if (!disabled) inputRef.current?.click();
|
|
4521
|
+
},
|
|
4522
|
+
onKeyDown,
|
|
4523
|
+
onDragEnter: (event) => {
|
|
4524
|
+
event.preventDefault();
|
|
4525
|
+
if (!disabled) setDragging(true);
|
|
4526
|
+
},
|
|
4527
|
+
onDragOver: (event) => {
|
|
4528
|
+
event.preventDefault();
|
|
4529
|
+
},
|
|
4530
|
+
onDragLeave: (event) => {
|
|
4531
|
+
if (event.currentTarget.contains(event.relatedTarget)) {
|
|
4532
|
+
return;
|
|
4533
|
+
}
|
|
4534
|
+
setDragging(false);
|
|
4535
|
+
},
|
|
4536
|
+
onDrop,
|
|
4537
|
+
children: [
|
|
4538
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm font-medium", children: labels.idle }),
|
|
4539
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4540
|
+
"p",
|
|
4541
|
+
{
|
|
4542
|
+
id: `${inputId}-hint`,
|
|
4543
|
+
className: "text-muted-foreground mt-1 text-xs",
|
|
4544
|
+
children: labels.hint
|
|
4545
|
+
}
|
|
4546
|
+
),
|
|
4547
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-primary mt-3 inline-flex text-sm font-medium underline-offset-4", children: labels.browse })
|
|
4548
|
+
]
|
|
4549
|
+
}
|
|
4550
|
+
),
|
|
4551
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4552
|
+
"input",
|
|
4553
|
+
{
|
|
4554
|
+
id: inputId,
|
|
4555
|
+
ref: inputRef,
|
|
4556
|
+
type: "file",
|
|
4557
|
+
accept,
|
|
4558
|
+
disabled,
|
|
4559
|
+
"aria-label": labels.browse,
|
|
4560
|
+
className: "sr-only",
|
|
4561
|
+
onChange: (event) => {
|
|
4562
|
+
takeFile(event.target.files?.[0]);
|
|
4563
|
+
event.target.value = "";
|
|
4564
|
+
}
|
|
4565
|
+
}
|
|
4566
|
+
),
|
|
4567
|
+
message ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4568
|
+
"p",
|
|
4569
|
+
{
|
|
4570
|
+
id: `${inputId}-message`,
|
|
4571
|
+
role: "alert",
|
|
4572
|
+
className: "text-destructive text-sm",
|
|
4573
|
+
children: message
|
|
4574
|
+
}
|
|
4575
|
+
) : null
|
|
4576
|
+
] });
|
|
4577
|
+
}
|
|
4578
|
+
function statusLabel(status, labels) {
|
|
4579
|
+
switch (status) {
|
|
4580
|
+
case "uploading":
|
|
4581
|
+
return labels.uploading;
|
|
4582
|
+
case "paused":
|
|
4583
|
+
return labels.paused;
|
|
4584
|
+
case "completing":
|
|
4585
|
+
return labels.completing;
|
|
4586
|
+
case "completed":
|
|
4587
|
+
return labels.completed;
|
|
4588
|
+
case "cancelled":
|
|
4589
|
+
return labels.cancelled;
|
|
4590
|
+
case "error":
|
|
4591
|
+
return labels.error;
|
|
4592
|
+
default: {
|
|
4593
|
+
const _exhaustive = status;
|
|
4594
|
+
return _exhaustive;
|
|
4595
|
+
}
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
function FileUploadTray({
|
|
4599
|
+
jobs,
|
|
4600
|
+
labels: labelOverrides,
|
|
4601
|
+
onPause,
|
|
4602
|
+
onResume,
|
|
4603
|
+
onCancel,
|
|
4604
|
+
className
|
|
4605
|
+
}) {
|
|
4606
|
+
const labels = { ...DEFAULT_FILE_UPLOAD_TRAY_LABELS, ...labelOverrides };
|
|
4607
|
+
const visible = jobs.filter((job) => job.status !== "cancelled");
|
|
4608
|
+
if (visible.length === 0) return null;
|
|
4609
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
4610
|
+
"section",
|
|
4611
|
+
{
|
|
4612
|
+
"aria-label": labels.title,
|
|
4613
|
+
className: cn(
|
|
4614
|
+
"bg-background/95 supports-backdrop-filter:bg-background/80 fixed right-4 bottom-4 z-40 w-[min(100%-2rem,22rem)] rounded-xl border p-3 shadow-lg backdrop-blur",
|
|
4615
|
+
className
|
|
4616
|
+
),
|
|
4617
|
+
children: [
|
|
4618
|
+
/* @__PURE__ */ jsxRuntime.jsx("h2", { className: "mb-2 text-sm font-medium", children: labels.title }),
|
|
4619
|
+
/* @__PURE__ */ jsxRuntime.jsx("ul", { className: "grid gap-3", children: visible.map((job) => {
|
|
4620
|
+
const active = job.status === "uploading" || job.status === "completing";
|
|
4621
|
+
const canPause = job.status === "uploading";
|
|
4622
|
+
const canResume = job.status === "paused";
|
|
4623
|
+
const canCancel = job.status === "uploading" || job.status === "paused" || job.status === "error";
|
|
4624
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("li", { className: "grid gap-1.5", children: [
|
|
4625
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2", children: [
|
|
4626
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "min-w-0 flex-1 truncate text-sm font-medium", children: job.name }),
|
|
4627
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground text-xs", children: statusLabel(job.status, labels) }),
|
|
4628
|
+
canPause ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4629
|
+
Button,
|
|
4630
|
+
{
|
|
4631
|
+
type: "button",
|
|
4632
|
+
variant: "ghost",
|
|
4633
|
+
size: "icon-sm",
|
|
4634
|
+
"aria-label": `${labels.pause} ${job.name}`,
|
|
4635
|
+
onClick: () => onPause(job.id),
|
|
4636
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pause, {})
|
|
4637
|
+
}
|
|
4638
|
+
) : null,
|
|
4639
|
+
canResume ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4640
|
+
Button,
|
|
4641
|
+
{
|
|
4642
|
+
type: "button",
|
|
4643
|
+
variant: "ghost",
|
|
4644
|
+
size: "icon-sm",
|
|
4645
|
+
"aria-label": `${labels.resume} ${job.name}`,
|
|
4646
|
+
onClick: () => onResume(job.id),
|
|
4647
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Play, {})
|
|
4648
|
+
}
|
|
4649
|
+
) : null,
|
|
4650
|
+
canCancel ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4651
|
+
Button,
|
|
4652
|
+
{
|
|
4653
|
+
type: "button",
|
|
4654
|
+
variant: "ghost",
|
|
4655
|
+
size: "icon-sm",
|
|
4656
|
+
"aria-label": `${labels.cancel} ${job.name}`,
|
|
4657
|
+
onClick: () => onCancel(job.id),
|
|
4658
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, {})
|
|
4659
|
+
}
|
|
4660
|
+
) : null
|
|
4661
|
+
] }),
|
|
4662
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
4663
|
+
"div",
|
|
4664
|
+
{
|
|
4665
|
+
role: "progressbar",
|
|
4666
|
+
"aria-valuemin": 0,
|
|
4667
|
+
"aria-valuemax": 100,
|
|
4668
|
+
"aria-valuenow": job.percent,
|
|
4669
|
+
"aria-label": job.name,
|
|
4670
|
+
className: "bg-muted h-2 overflow-hidden rounded-full",
|
|
4671
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
4672
|
+
"div",
|
|
4673
|
+
{
|
|
4674
|
+
className: cn(
|
|
4675
|
+
"bg-primary h-full",
|
|
4676
|
+
active && "motion-safe:transition-[width]"
|
|
4677
|
+
),
|
|
4678
|
+
style: { width: `${job.percent}%` }
|
|
4679
|
+
}
|
|
4680
|
+
)
|
|
4681
|
+
}
|
|
4682
|
+
),
|
|
4683
|
+
job.error ? /* @__PURE__ */ jsxRuntime.jsx("p", { role: "alert", className: "text-destructive text-xs", children: job.error }) : null
|
|
4684
|
+
] }, job.id);
|
|
4685
|
+
}) })
|
|
4686
|
+
]
|
|
4687
|
+
}
|
|
4688
|
+
);
|
|
4689
|
+
}
|
|
4690
|
+
|
|
4691
|
+
// src/components/upload/createMultipartUploadController.ts
|
|
4692
|
+
function readEtag(xhr) {
|
|
4693
|
+
const raw = xhr.getResponseHeader("ETag") ?? xhr.getResponseHeader("etag") ?? "";
|
|
4694
|
+
const etag = raw.trim();
|
|
4695
|
+
if (!etag) {
|
|
4696
|
+
throw new Error("Upload part missing ETag");
|
|
4697
|
+
}
|
|
4698
|
+
return etag;
|
|
4699
|
+
}
|
|
4700
|
+
function putPart(input) {
|
|
4701
|
+
return new Promise((resolve, reject) => {
|
|
4702
|
+
input.xhr.open("PUT", input.url);
|
|
4703
|
+
input.xhr.upload.onprogress = (event) => {
|
|
4704
|
+
input.onProgress(event.loaded);
|
|
4705
|
+
};
|
|
4706
|
+
input.xhr.onload = () => {
|
|
4707
|
+
if (input.xhr.status >= 200 && input.xhr.status < 300) {
|
|
4708
|
+
try {
|
|
4709
|
+
resolve(readEtag(input.xhr));
|
|
4710
|
+
} catch (error) {
|
|
4711
|
+
reject(error);
|
|
4712
|
+
}
|
|
4713
|
+
return;
|
|
4714
|
+
}
|
|
4715
|
+
reject(new Error(`Upload failed (${input.xhr.status})`));
|
|
4716
|
+
};
|
|
4717
|
+
input.xhr.onerror = () => {
|
|
4718
|
+
reject(new Error("Upload failed"));
|
|
4719
|
+
};
|
|
4720
|
+
input.xhr.onabort = () => {
|
|
4721
|
+
reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
4722
|
+
};
|
|
4723
|
+
input.xhr.send(input.body);
|
|
4724
|
+
});
|
|
4725
|
+
}
|
|
4726
|
+
function createMultipartUploadController(options) {
|
|
4727
|
+
const ranges = partRanges(options.file.size, options.partSize);
|
|
4728
|
+
const completed = [];
|
|
4729
|
+
const state = { status: "idle" };
|
|
4730
|
+
let currentXhr = null;
|
|
4731
|
+
let run = null;
|
|
4732
|
+
let resumeIndex = 0;
|
|
4733
|
+
function currentStatus() {
|
|
4734
|
+
return state.status;
|
|
4735
|
+
}
|
|
4736
|
+
function isStopped() {
|
|
4737
|
+
const status = currentStatus();
|
|
4738
|
+
return status === "paused" || status === "cancelled";
|
|
4739
|
+
}
|
|
4740
|
+
function emitProgress(currentPartLoaded = 0) {
|
|
4741
|
+
const completedBytes = completed.reduce((sum, part) => {
|
|
4742
|
+
const range = ranges[part.partNumber - 1];
|
|
4743
|
+
return sum + (range ? range.end - range.start : 0);
|
|
4744
|
+
}, 0);
|
|
4745
|
+
options.onProgress?.(
|
|
4746
|
+
progressFromBytes(completedBytes + currentPartLoaded, options.file.size)
|
|
4747
|
+
);
|
|
4748
|
+
}
|
|
4749
|
+
async function uploadFrom(startIndex) {
|
|
4750
|
+
state.status = "uploading";
|
|
4751
|
+
for (let index = startIndex; index < ranges.length; index += 1) {
|
|
4752
|
+
if (state.status !== "uploading") return;
|
|
4753
|
+
resumeIndex = index;
|
|
4754
|
+
const range = ranges[index];
|
|
4755
|
+
if (!range) continue;
|
|
4756
|
+
const url = await options.adapter.requestPartUrl(range.partNumber);
|
|
4757
|
+
if (state.status !== "uploading") return;
|
|
4758
|
+
const xhr = options.xhrFactory ? options.xhrFactory() : new XMLHttpRequest();
|
|
4759
|
+
currentXhr = xhr;
|
|
4760
|
+
const body = options.file.slice(range.start, range.end);
|
|
4761
|
+
try {
|
|
4762
|
+
const etag = await putPart({
|
|
4763
|
+
url,
|
|
4764
|
+
body,
|
|
4765
|
+
xhr,
|
|
4766
|
+
onProgress: (loaded) => emitProgress(loaded)
|
|
4767
|
+
});
|
|
4768
|
+
completed.push({ partNumber: range.partNumber, etag });
|
|
4769
|
+
emitProgress(0);
|
|
4770
|
+
} catch (error) {
|
|
4771
|
+
currentXhr = null;
|
|
4772
|
+
if (isStopped()) return;
|
|
4773
|
+
state.status = "error";
|
|
4774
|
+
throw error;
|
|
4775
|
+
} finally {
|
|
4776
|
+
if (currentXhr === xhr) currentXhr = null;
|
|
4777
|
+
}
|
|
4778
|
+
}
|
|
4779
|
+
if (state.status !== "uploading") return;
|
|
4780
|
+
state.status = "completing";
|
|
4781
|
+
await options.adapter.complete([...completed]);
|
|
4782
|
+
state.status = "completed";
|
|
4783
|
+
emitProgress(0);
|
|
4784
|
+
}
|
|
4785
|
+
async function start() {
|
|
4786
|
+
if (run) return run;
|
|
4787
|
+
run = uploadFrom(0).catch((error) => {
|
|
4788
|
+
if (isStopped()) return;
|
|
4789
|
+
state.status = "error";
|
|
4790
|
+
throw error;
|
|
4791
|
+
});
|
|
4792
|
+
return run;
|
|
4793
|
+
}
|
|
4794
|
+
function pause() {
|
|
4795
|
+
if (state.status !== "uploading") return;
|
|
4796
|
+
state.status = "paused";
|
|
4797
|
+
currentXhr?.abort();
|
|
4798
|
+
}
|
|
4799
|
+
async function resume() {
|
|
4800
|
+
if (state.status !== "paused") return;
|
|
4801
|
+
run = uploadFrom(resumeIndex).catch((error) => {
|
|
4802
|
+
if (isStopped()) return;
|
|
4803
|
+
state.status = "error";
|
|
4804
|
+
throw error;
|
|
4805
|
+
});
|
|
4806
|
+
return run;
|
|
4807
|
+
}
|
|
4808
|
+
async function cancel() {
|
|
4809
|
+
if (state.status === "completed" || state.status === "cancelled" || state.status === "idle") {
|
|
4810
|
+
state.status = "cancelled";
|
|
4811
|
+
return;
|
|
4812
|
+
}
|
|
4813
|
+
state.status = "cancelled";
|
|
4814
|
+
currentXhr?.abort();
|
|
4815
|
+
await options.adapter.abort?.();
|
|
4816
|
+
}
|
|
4817
|
+
return {
|
|
4818
|
+
start,
|
|
4819
|
+
pause,
|
|
4820
|
+
resume,
|
|
4821
|
+
cancel,
|
|
4822
|
+
getStatus: () => state.status
|
|
4823
|
+
};
|
|
4824
|
+
}
|
|
4825
|
+
|
|
4251
4826
|
// src/lib/avatar.ts
|
|
4252
4827
|
var EMPTY_COLORS = {
|
|
4253
4828
|
backgroundColor: "#9ca3af",
|
|
@@ -4338,6 +4913,9 @@ exports.CurtainPreview = CurtainPreview;
|
|
|
4338
4913
|
exports.CurtainStage = CurtainStage;
|
|
4339
4914
|
exports.DEFAULT_CURTAIN_PICKER_LABELS = DEFAULT_CURTAIN_PICKER_LABELS;
|
|
4340
4915
|
exports.DEFAULT_EDITABLE_SECTION_LABELS = DEFAULT_EDITABLE_SECTION_LABELS;
|
|
4916
|
+
exports.DEFAULT_FILE_DROPZONE_LABELS = DEFAULT_FILE_DROPZONE_LABELS;
|
|
4917
|
+
exports.DEFAULT_FILE_UPLOAD_LABELS = DEFAULT_FILE_UPLOAD_LABELS;
|
|
4918
|
+
exports.DEFAULT_FILE_UPLOAD_TRAY_LABELS = DEFAULT_FILE_UPLOAD_TRAY_LABELS;
|
|
4341
4919
|
exports.DataList = DataList;
|
|
4342
4920
|
exports.DataListItem = DataListItem;
|
|
4343
4921
|
exports.EditableSection = EditableSection;
|
|
@@ -4351,6 +4929,8 @@ exports.EmptyTitle = EmptyTitle;
|
|
|
4351
4929
|
exports.ErrorState = ErrorState;
|
|
4352
4930
|
exports.FeedVideoPlayer = FeedVideoPlayer;
|
|
4353
4931
|
exports.FieldMessage = FieldMessage;
|
|
4932
|
+
exports.FileDropzone = FileDropzone;
|
|
4933
|
+
exports.FileUploadTray = FileUploadTray;
|
|
4354
4934
|
exports.LanguageContext = LanguageContext;
|
|
4355
4935
|
exports.LanguageSwitcher = LanguageSwitcher;
|
|
4356
4936
|
exports.LoadingState = LoadingState;
|
|
@@ -4362,13 +4942,17 @@ exports.avatarFallbackStyle = avatarFallbackStyle;
|
|
|
4362
4942
|
exports.castHlsUrl = castHlsUrl;
|
|
4363
4943
|
exports.cn = cn;
|
|
4364
4944
|
exports.createLiveHlsConfig = createLiveHlsConfig;
|
|
4945
|
+
exports.createMultipartUploadController = createMultipartUploadController;
|
|
4365
4946
|
exports.createVodHlsConfig = createVodHlsConfig;
|
|
4366
4947
|
exports.defaultLanguages = defaultLanguages;
|
|
4367
4948
|
exports.describeAvResync = describeAvResync;
|
|
4368
4949
|
exports.describePlaybackError = describePlaybackError;
|
|
4950
|
+
exports.fileMatchesAccept = fileMatchesAccept;
|
|
4369
4951
|
exports.getAvatarColors = getAvatarColors;
|
|
4370
4952
|
exports.getInitials = getInitials;
|
|
4371
4953
|
exports.loadCastSender = loadCastSender;
|
|
4954
|
+
exports.partRanges = partRanges;
|
|
4955
|
+
exports.progressFromBytes = progressFromBytes;
|
|
4372
4956
|
exports.shouldRetryLiveEdge404 = shouldRetryLiveEdge404;
|
|
4373
4957
|
exports.useEditableSection = useEditableSection;
|
|
4374
4958
|
exports.useFeedExclusivePlayback = useFeedExclusivePlayback;
|