@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.js CHANGED
@@ -2232,6 +2232,37 @@ function AvatarEditorDialog({
2232
2232
  ] }) })
2233
2233
  ] });
2234
2234
  }
2235
+ var DEFAULT_LABELS2 = {
2236
+ play: "Play",
2237
+ tapToUnmute: "Tap to unmute",
2238
+ mute: "Mute",
2239
+ unmute: "Unmute"
2240
+ };
2241
+ var CURTAIN_VIDEO_STYLE = `
2242
+ .livo-curtain-video::-webkit-media-controls-start-playback-button {
2243
+ display: none !important;
2244
+ -webkit-appearance: none;
2245
+ }
2246
+ .livo-curtain-video::-webkit-media-controls {
2247
+ display: none !important;
2248
+ }
2249
+ `;
2250
+ function isAudioTrackList(value) {
2251
+ return typeof value === "object" && value !== null && typeof value.getTrackById === "function";
2252
+ }
2253
+ function probeVideoAudio(el) {
2254
+ const video = el;
2255
+ if (typeof video.mozHasAudio === "boolean") {
2256
+ return video.mozHasAudio ? "yes" : "no";
2257
+ }
2258
+ if (typeof video.webkitAudioDecodedByteCount === "number" && video.webkitAudioDecodedByteCount > 0) {
2259
+ return "yes";
2260
+ }
2261
+ if (isAudioTrackList(video.audioTracks)) {
2262
+ return video.audioTracks.length > 0 ? "yes" : "no";
2263
+ }
2264
+ return "unknown";
2265
+ }
2235
2266
  function usePrefersReducedMotion() {
2236
2267
  const [reduced, setReduced] = React7.useState(false);
2237
2268
  React7.useEffect(() => {
@@ -2243,39 +2274,154 @@ function usePrefersReducedMotion() {
2243
2274
  }, []);
2244
2275
  return reduced;
2245
2276
  }
2246
- function CurtainStage({
2247
- kind,
2277
+ function CurtainVideo({
2248
2278
  url,
2249
- alt = "",
2279
+ alt,
2250
2280
  className,
2251
- reducedMotion
2281
+ freeze,
2282
+ allowSound,
2283
+ labels
2252
2284
  }) {
2253
- const prefersReduced = usePrefersReducedMotion();
2254
- const freeze = reducedMotion ?? prefersReduced;
2255
- if (kind === "video" && !freeze) {
2256
- return /* @__PURE__ */ jsx(
2285
+ const videoRef = React7.useRef(null);
2286
+ const [playback, setPlayback] = React7.useState("pending");
2287
+ const [muted, setMuted] = React7.useState(true);
2288
+ const [audio, setAudio] = React7.useState("unknown");
2289
+ React7.useEffect(() => {
2290
+ const el = videoRef.current;
2291
+ if (!el) return;
2292
+ el.setAttribute("webkit-playsinline", "");
2293
+ el.muted = true;
2294
+ setMuted(true);
2295
+ setAudio("unknown");
2296
+ setPlayback("pending");
2297
+ if (freeze) {
2298
+ el.pause();
2299
+ return;
2300
+ }
2301
+ let cancelled = false;
2302
+ const applyAudio = () => {
2303
+ const next = probeVideoAudio(el);
2304
+ if (next !== "unknown") setAudio(next);
2305
+ };
2306
+ const tryPlay = () => {
2307
+ if (cancelled) return;
2308
+ void el.play().then(
2309
+ () => {
2310
+ if (cancelled) return;
2311
+ setPlayback("playing");
2312
+ applyAudio();
2313
+ },
2314
+ () => {
2315
+ if (!cancelled && el.paused) setPlayback("blocked");
2316
+ }
2317
+ );
2318
+ };
2319
+ tryPlay();
2320
+ el.addEventListener("canplay", tryPlay);
2321
+ el.addEventListener("timeupdate", applyAudio);
2322
+ el.addEventListener("loadedmetadata", applyAudio);
2323
+ return () => {
2324
+ cancelled = true;
2325
+ el.removeEventListener("canplay", tryPlay);
2326
+ el.removeEventListener("timeupdate", applyAudio);
2327
+ el.removeEventListener("loadedmetadata", applyAudio);
2328
+ };
2329
+ }, [url, freeze]);
2330
+ const startPlayback = React7.useCallback(() => {
2331
+ const el = videoRef.current;
2332
+ if (!el) return;
2333
+ el.muted = true;
2334
+ setMuted(true);
2335
+ void el.play().then(
2336
+ () => {
2337
+ setPlayback("playing");
2338
+ const next = probeVideoAudio(el);
2339
+ if (next !== "unknown") setAudio(next);
2340
+ },
2341
+ () => {
2342
+ if (el.paused) setPlayback("blocked");
2343
+ }
2344
+ );
2345
+ }, []);
2346
+ const setVideoMuted = React7.useCallback((next) => {
2347
+ const el = videoRef.current;
2348
+ if (el) el.muted = next;
2349
+ setMuted(next);
2350
+ }, []);
2351
+ const showUnmute = allowSound && !freeze && playback === "playing" && muted && audio !== "no";
2352
+ const showMute = allowSound && !freeze && playback === "playing" && !muted;
2353
+ return /* @__PURE__ */ jsxs("div", { className: cn("relative h-full w-full", className), children: [
2354
+ /* @__PURE__ */ jsx("style", { children: CURTAIN_VIDEO_STYLE }),
2355
+ /* @__PURE__ */ jsx(
2257
2356
  "video",
2258
2357
  {
2358
+ ref: videoRef,
2259
2359
  src: url,
2260
- className: cn("h-full w-full object-cover", className),
2261
- autoPlay: true,
2262
- muted: true,
2263
- loop: true,
2360
+ className: "livo-curtain-video h-full w-full object-cover",
2361
+ autoPlay: !freeze,
2362
+ muted,
2363
+ loop: !freeze,
2264
2364
  playsInline: true,
2365
+ preload: freeze ? "metadata" : void 0,
2265
2366
  "aria-hidden": alt ? void 0 : true
2266
2367
  }
2267
- );
2268
- }
2269
- if (kind === "video" && freeze) {
2368
+ ),
2369
+ playback === "blocked" && !freeze ? /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-black/40", children: /* @__PURE__ */ jsx(
2370
+ "button",
2371
+ {
2372
+ type: "button",
2373
+ "aria-label": labels.play,
2374
+ onClick: startPlayback,
2375
+ className: "flex size-16 items-center justify-center rounded-full bg-white/20 backdrop-blur-sm transition hover:bg-white/30",
2376
+ children: /* @__PURE__ */ jsx(Play, { className: "size-8 translate-x-0.5", fill: "currentColor" })
2377
+ }
2378
+ ) }) : null,
2379
+ showUnmute ? /* @__PURE__ */ jsxs(
2380
+ "button",
2381
+ {
2382
+ type: "button",
2383
+ onClick: () => setVideoMuted(false),
2384
+ 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",
2385
+ children: [
2386
+ /* @__PURE__ */ jsx(VolumeX, { className: "size-4" }),
2387
+ labels.tapToUnmute
2388
+ ]
2389
+ }
2390
+ ) : null,
2391
+ showMute ? /* @__PURE__ */ jsx(
2392
+ "button",
2393
+ {
2394
+ type: "button",
2395
+ "aria-label": labels.mute,
2396
+ onClick: () => setVideoMuted(true),
2397
+ 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",
2398
+ children: /* @__PURE__ */ jsx(Volume2, { className: "size-4" })
2399
+ }
2400
+ ) : null
2401
+ ] });
2402
+ }
2403
+ function CurtainStage({
2404
+ kind,
2405
+ url,
2406
+ alt = "",
2407
+ className,
2408
+ reducedMotion,
2409
+ allowSound = false,
2410
+ labels
2411
+ }) {
2412
+ const prefersReduced = usePrefersReducedMotion();
2413
+ const freeze = reducedMotion ?? prefersReduced;
2414
+ const copy = { ...DEFAULT_LABELS2, ...labels };
2415
+ if (kind === "video") {
2270
2416
  return /* @__PURE__ */ jsx(
2271
- "video",
2417
+ CurtainVideo,
2272
2418
  {
2273
- src: url,
2274
- className: cn("h-full w-full object-cover", className),
2275
- muted: true,
2276
- playsInline: true,
2277
- preload: "metadata",
2278
- "aria-hidden": alt ? void 0 : true
2419
+ url,
2420
+ alt,
2421
+ className,
2422
+ freeze,
2423
+ allowSound,
2424
+ labels: copy
2279
2425
  }
2280
2426
  );
2281
2427
  }
@@ -2843,6 +2989,7 @@ function WaitingRoom({
2843
2989
  {
2844
2990
  kind: curtain.kind,
2845
2991
  url: curtain.url,
2992
+ allowSound: true,
2846
2993
  className: "absolute inset-0"
2847
2994
  }
2848
2995
  ) : /* @__PURE__ */ jsx("div", { className: "absolute inset-0 bg-gradient-to-br from-zinc-900 to-zinc-950" }),
@@ -3399,7 +3546,7 @@ function useHlsPlayback({
3399
3546
  retry
3400
3547
  };
3401
3548
  }
3402
- var DEFAULT_LABELS2 = {
3549
+ var DEFAULT_LABELS3 = {
3403
3550
  play: "Play",
3404
3551
  pause: "Pause",
3405
3552
  mute: "Mute",
@@ -3467,7 +3614,7 @@ function VideoPlayer({
3467
3614
  fit = "aspect-video",
3468
3615
  className
3469
3616
  }) {
3470
- const t = { ...DEFAULT_LABELS2, ...labels };
3617
+ const t = { ...DEFAULT_LABELS3, ...labels };
3471
3618
  const containerRef = React7.useRef(null);
3472
3619
  const firstPlayFiredRef = React7.useRef(false);
3473
3620
  const [userStarted, setUserStarted] = React7.useState(false);
@@ -4222,6 +4369,434 @@ function usePlaybackStats(statsUrl, { intervalMs = 15e3, enabled = true } = {})
4222
4369
  return stats;
4223
4370
  }
4224
4371
 
4372
+ // src/components/upload/part-math.ts
4373
+ function partRanges(fileSize, partSize) {
4374
+ if (partSize <= 0) {
4375
+ throw new Error("partSize must be greater than 0");
4376
+ }
4377
+ if (fileSize <= 0) {
4378
+ return [{ partNumber: 1, start: 0, end: 0 }];
4379
+ }
4380
+ const count = Math.ceil(fileSize / partSize);
4381
+ return Array.from({ length: count }, (_, index) => {
4382
+ const start = index * partSize;
4383
+ return {
4384
+ partNumber: index + 1,
4385
+ start,
4386
+ end: Math.min(fileSize, start + partSize)
4387
+ };
4388
+ });
4389
+ }
4390
+ function progressFromBytes(loaded, total) {
4391
+ const safeTotal = Math.max(0, total);
4392
+ const safeLoaded = Math.min(Math.max(0, loaded), safeTotal);
4393
+ const percent = safeTotal > 0 ? Math.round(safeLoaded / safeTotal * 100) : 0;
4394
+ return { loaded: safeLoaded, total: safeTotal, percent };
4395
+ }
4396
+ function fileMatchesAccept(file, accept) {
4397
+ if (!accept?.trim()) return true;
4398
+ const type = file.type.toLowerCase();
4399
+ const name = file.name.toLowerCase();
4400
+ return accept.split(",").some((token) => {
4401
+ const trimmed = token.trim().toLowerCase();
4402
+ if (!trimmed) return false;
4403
+ if (trimmed.endsWith("/*")) {
4404
+ return type.startsWith(trimmed.slice(0, -1));
4405
+ }
4406
+ if (trimmed.startsWith(".")) {
4407
+ return name.endsWith(trimmed);
4408
+ }
4409
+ return type === trimmed;
4410
+ });
4411
+ }
4412
+
4413
+ // src/components/upload/types.ts
4414
+ var DEFAULT_FILE_DROPZONE_LABELS = {
4415
+ idle: "Drop a file here or browse",
4416
+ hint: "Click or press Enter to choose a file",
4417
+ browse: "Browse",
4418
+ rejectType: "This file type is not allowed",
4419
+ rejectSize: "This file is too large"
4420
+ };
4421
+ var DEFAULT_FILE_UPLOAD_TRAY_LABELS = {
4422
+ title: "Uploads",
4423
+ pause: "Pause",
4424
+ resume: "Resume",
4425
+ cancel: "Cancel",
4426
+ uploading: "Uploading",
4427
+ paused: "Paused",
4428
+ completing: "Finishing",
4429
+ completed: "Uploaded",
4430
+ cancelled: "Cancelled",
4431
+ error: "Failed"
4432
+ };
4433
+ var DEFAULT_FILE_UPLOAD_LABELS = {
4434
+ dropzone: DEFAULT_FILE_DROPZONE_LABELS,
4435
+ tray: DEFAULT_FILE_UPLOAD_TRAY_LABELS
4436
+ };
4437
+ function FileDropzone({
4438
+ accept,
4439
+ maxSize,
4440
+ disabled = false,
4441
+ labels: labelOverrides,
4442
+ onFile,
4443
+ onReject,
4444
+ className
4445
+ }) {
4446
+ const labels = { ...DEFAULT_FILE_DROPZONE_LABELS, ...labelOverrides };
4447
+ const inputId = useId();
4448
+ const inputRef = useRef(null);
4449
+ const [dragging, setDragging] = useState(false);
4450
+ const [message, setMessage] = useState(null);
4451
+ function takeFile(file) {
4452
+ if (!file || disabled) return;
4453
+ if (!fileMatchesAccept(file, accept)) {
4454
+ setMessage(labels.rejectType);
4455
+ onReject?.("type");
4456
+ return;
4457
+ }
4458
+ if (maxSize != null && file.size > maxSize) {
4459
+ setMessage(labels.rejectSize);
4460
+ onReject?.("size");
4461
+ return;
4462
+ }
4463
+ setMessage(null);
4464
+ onFile(file);
4465
+ }
4466
+ function onDrop(event) {
4467
+ event.preventDefault();
4468
+ setDragging(false);
4469
+ takeFile(event.dataTransfer.files[0]);
4470
+ }
4471
+ function onKeyDown(event) {
4472
+ if (disabled) return;
4473
+ if (event.key === "Enter" || event.key === " ") {
4474
+ event.preventDefault();
4475
+ inputRef.current?.click();
4476
+ }
4477
+ }
4478
+ return /* @__PURE__ */ jsxs("div", { className: cn("grid gap-2", className), children: [
4479
+ /* @__PURE__ */ jsxs(
4480
+ "div",
4481
+ {
4482
+ role: "button",
4483
+ tabIndex: disabled ? -1 : 0,
4484
+ "aria-disabled": disabled,
4485
+ "aria-describedby": message ? `${inputId}-message` : `${inputId}-hint`,
4486
+ "aria-controls": inputId,
4487
+ "data-dragging": dragging || void 0,
4488
+ className: cn(
4489
+ "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]",
4490
+ dragging && "border-primary bg-primary/5",
4491
+ disabled && "pointer-events-none opacity-50"
4492
+ ),
4493
+ onClick: () => {
4494
+ if (!disabled) inputRef.current?.click();
4495
+ },
4496
+ onKeyDown,
4497
+ onDragEnter: (event) => {
4498
+ event.preventDefault();
4499
+ if (!disabled) setDragging(true);
4500
+ },
4501
+ onDragOver: (event) => {
4502
+ event.preventDefault();
4503
+ },
4504
+ onDragLeave: (event) => {
4505
+ if (event.currentTarget.contains(event.relatedTarget)) {
4506
+ return;
4507
+ }
4508
+ setDragging(false);
4509
+ },
4510
+ onDrop,
4511
+ children: [
4512
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: labels.idle }),
4513
+ /* @__PURE__ */ jsx(
4514
+ "p",
4515
+ {
4516
+ id: `${inputId}-hint`,
4517
+ className: "text-muted-foreground mt-1 text-xs",
4518
+ children: labels.hint
4519
+ }
4520
+ ),
4521
+ /* @__PURE__ */ jsx("span", { className: "text-primary mt-3 inline-flex text-sm font-medium underline-offset-4", children: labels.browse })
4522
+ ]
4523
+ }
4524
+ ),
4525
+ /* @__PURE__ */ jsx(
4526
+ "input",
4527
+ {
4528
+ id: inputId,
4529
+ ref: inputRef,
4530
+ type: "file",
4531
+ accept,
4532
+ disabled,
4533
+ "aria-label": labels.browse,
4534
+ className: "sr-only",
4535
+ onChange: (event) => {
4536
+ takeFile(event.target.files?.[0]);
4537
+ event.target.value = "";
4538
+ }
4539
+ }
4540
+ ),
4541
+ message ? /* @__PURE__ */ jsx(
4542
+ "p",
4543
+ {
4544
+ id: `${inputId}-message`,
4545
+ role: "alert",
4546
+ className: "text-destructive text-sm",
4547
+ children: message
4548
+ }
4549
+ ) : null
4550
+ ] });
4551
+ }
4552
+ function statusLabel(status, labels) {
4553
+ switch (status) {
4554
+ case "uploading":
4555
+ return labels.uploading;
4556
+ case "paused":
4557
+ return labels.paused;
4558
+ case "completing":
4559
+ return labels.completing;
4560
+ case "completed":
4561
+ return labels.completed;
4562
+ case "cancelled":
4563
+ return labels.cancelled;
4564
+ case "error":
4565
+ return labels.error;
4566
+ default: {
4567
+ const _exhaustive = status;
4568
+ return _exhaustive;
4569
+ }
4570
+ }
4571
+ }
4572
+ function FileUploadTray({
4573
+ jobs,
4574
+ labels: labelOverrides,
4575
+ onPause,
4576
+ onResume,
4577
+ onCancel,
4578
+ className
4579
+ }) {
4580
+ const labels = { ...DEFAULT_FILE_UPLOAD_TRAY_LABELS, ...labelOverrides };
4581
+ const visible = jobs.filter((job) => job.status !== "cancelled");
4582
+ if (visible.length === 0) return null;
4583
+ return /* @__PURE__ */ jsxs(
4584
+ "section",
4585
+ {
4586
+ "aria-label": labels.title,
4587
+ className: cn(
4588
+ "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",
4589
+ className
4590
+ ),
4591
+ children: [
4592
+ /* @__PURE__ */ jsx("h2", { className: "mb-2 text-sm font-medium", children: labels.title }),
4593
+ /* @__PURE__ */ jsx("ul", { className: "grid gap-3", children: visible.map((job) => {
4594
+ const active = job.status === "uploading" || job.status === "completing";
4595
+ const canPause = job.status === "uploading";
4596
+ const canResume = job.status === "paused";
4597
+ const canCancel = job.status === "uploading" || job.status === "paused" || job.status === "error";
4598
+ return /* @__PURE__ */ jsxs("li", { className: "grid gap-1.5", children: [
4599
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
4600
+ /* @__PURE__ */ jsx("p", { className: "min-w-0 flex-1 truncate text-sm font-medium", children: job.name }),
4601
+ /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs", children: statusLabel(job.status, labels) }),
4602
+ canPause ? /* @__PURE__ */ jsx(
4603
+ Button,
4604
+ {
4605
+ type: "button",
4606
+ variant: "ghost",
4607
+ size: "icon-sm",
4608
+ "aria-label": `${labels.pause} ${job.name}`,
4609
+ onClick: () => onPause(job.id),
4610
+ children: /* @__PURE__ */ jsx(Pause, {})
4611
+ }
4612
+ ) : null,
4613
+ canResume ? /* @__PURE__ */ jsx(
4614
+ Button,
4615
+ {
4616
+ type: "button",
4617
+ variant: "ghost",
4618
+ size: "icon-sm",
4619
+ "aria-label": `${labels.resume} ${job.name}`,
4620
+ onClick: () => onResume(job.id),
4621
+ children: /* @__PURE__ */ jsx(Play, {})
4622
+ }
4623
+ ) : null,
4624
+ canCancel ? /* @__PURE__ */ jsx(
4625
+ Button,
4626
+ {
4627
+ type: "button",
4628
+ variant: "ghost",
4629
+ size: "icon-sm",
4630
+ "aria-label": `${labels.cancel} ${job.name}`,
4631
+ onClick: () => onCancel(job.id),
4632
+ children: /* @__PURE__ */ jsx(X, {})
4633
+ }
4634
+ ) : null
4635
+ ] }),
4636
+ /* @__PURE__ */ jsx(
4637
+ "div",
4638
+ {
4639
+ role: "progressbar",
4640
+ "aria-valuemin": 0,
4641
+ "aria-valuemax": 100,
4642
+ "aria-valuenow": job.percent,
4643
+ "aria-label": job.name,
4644
+ className: "bg-muted h-2 overflow-hidden rounded-full",
4645
+ children: /* @__PURE__ */ jsx(
4646
+ "div",
4647
+ {
4648
+ className: cn(
4649
+ "bg-primary h-full",
4650
+ active && "motion-safe:transition-[width]"
4651
+ ),
4652
+ style: { width: `${job.percent}%` }
4653
+ }
4654
+ )
4655
+ }
4656
+ ),
4657
+ job.error ? /* @__PURE__ */ jsx("p", { role: "alert", className: "text-destructive text-xs", children: job.error }) : null
4658
+ ] }, job.id);
4659
+ }) })
4660
+ ]
4661
+ }
4662
+ );
4663
+ }
4664
+
4665
+ // src/components/upload/createMultipartUploadController.ts
4666
+ function readEtag(xhr) {
4667
+ const raw = xhr.getResponseHeader("ETag") ?? xhr.getResponseHeader("etag") ?? "";
4668
+ const etag = raw.trim();
4669
+ if (!etag) {
4670
+ throw new Error("Upload part missing ETag");
4671
+ }
4672
+ return etag;
4673
+ }
4674
+ function putPart(input) {
4675
+ return new Promise((resolve, reject) => {
4676
+ input.xhr.open("PUT", input.url);
4677
+ input.xhr.upload.onprogress = (event) => {
4678
+ input.onProgress(event.loaded);
4679
+ };
4680
+ input.xhr.onload = () => {
4681
+ if (input.xhr.status >= 200 && input.xhr.status < 300) {
4682
+ try {
4683
+ resolve(readEtag(input.xhr));
4684
+ } catch (error) {
4685
+ reject(error);
4686
+ }
4687
+ return;
4688
+ }
4689
+ reject(new Error(`Upload failed (${input.xhr.status})`));
4690
+ };
4691
+ input.xhr.onerror = () => {
4692
+ reject(new Error("Upload failed"));
4693
+ };
4694
+ input.xhr.onabort = () => {
4695
+ reject(new DOMException("The operation was aborted.", "AbortError"));
4696
+ };
4697
+ input.xhr.send(input.body);
4698
+ });
4699
+ }
4700
+ function createMultipartUploadController(options) {
4701
+ const ranges = partRanges(options.file.size, options.partSize);
4702
+ const completed = [];
4703
+ const state = { status: "idle" };
4704
+ let currentXhr = null;
4705
+ let run = null;
4706
+ let resumeIndex = 0;
4707
+ function currentStatus() {
4708
+ return state.status;
4709
+ }
4710
+ function isStopped() {
4711
+ const status = currentStatus();
4712
+ return status === "paused" || status === "cancelled";
4713
+ }
4714
+ function emitProgress(currentPartLoaded = 0) {
4715
+ const completedBytes = completed.reduce((sum, part) => {
4716
+ const range = ranges[part.partNumber - 1];
4717
+ return sum + (range ? range.end - range.start : 0);
4718
+ }, 0);
4719
+ options.onProgress?.(
4720
+ progressFromBytes(completedBytes + currentPartLoaded, options.file.size)
4721
+ );
4722
+ }
4723
+ async function uploadFrom(startIndex) {
4724
+ state.status = "uploading";
4725
+ for (let index = startIndex; index < ranges.length; index += 1) {
4726
+ if (state.status !== "uploading") return;
4727
+ resumeIndex = index;
4728
+ const range = ranges[index];
4729
+ if (!range) continue;
4730
+ const url = await options.adapter.requestPartUrl(range.partNumber);
4731
+ if (state.status !== "uploading") return;
4732
+ const xhr = options.xhrFactory ? options.xhrFactory() : new XMLHttpRequest();
4733
+ currentXhr = xhr;
4734
+ const body = options.file.slice(range.start, range.end);
4735
+ try {
4736
+ const etag = await putPart({
4737
+ url,
4738
+ body,
4739
+ xhr,
4740
+ onProgress: (loaded) => emitProgress(loaded)
4741
+ });
4742
+ completed.push({ partNumber: range.partNumber, etag });
4743
+ emitProgress(0);
4744
+ } catch (error) {
4745
+ currentXhr = null;
4746
+ if (isStopped()) return;
4747
+ state.status = "error";
4748
+ throw error;
4749
+ } finally {
4750
+ if (currentXhr === xhr) currentXhr = null;
4751
+ }
4752
+ }
4753
+ if (state.status !== "uploading") return;
4754
+ state.status = "completing";
4755
+ await options.adapter.complete([...completed]);
4756
+ state.status = "completed";
4757
+ emitProgress(0);
4758
+ }
4759
+ async function start() {
4760
+ if (run) return run;
4761
+ run = uploadFrom(0).catch((error) => {
4762
+ if (isStopped()) return;
4763
+ state.status = "error";
4764
+ throw error;
4765
+ });
4766
+ return run;
4767
+ }
4768
+ function pause() {
4769
+ if (state.status !== "uploading") return;
4770
+ state.status = "paused";
4771
+ currentXhr?.abort();
4772
+ }
4773
+ async function resume() {
4774
+ if (state.status !== "paused") return;
4775
+ run = uploadFrom(resumeIndex).catch((error) => {
4776
+ if (isStopped()) return;
4777
+ state.status = "error";
4778
+ throw error;
4779
+ });
4780
+ return run;
4781
+ }
4782
+ async function cancel() {
4783
+ if (state.status === "completed" || state.status === "cancelled" || state.status === "idle") {
4784
+ state.status = "cancelled";
4785
+ return;
4786
+ }
4787
+ state.status = "cancelled";
4788
+ currentXhr?.abort();
4789
+ await options.adapter.abort?.();
4790
+ }
4791
+ return {
4792
+ start,
4793
+ pause,
4794
+ resume,
4795
+ cancel,
4796
+ getStatus: () => state.status
4797
+ };
4798
+ }
4799
+
4225
4800
  // src/lib/avatar.ts
4226
4801
  var EMPTY_COLORS = {
4227
4802
  backgroundColor: "#9ca3af",
@@ -4303,6 +4878,6 @@ function avatarFallbackStyle(name) {
4303
4878
  return getAvatarColors(name);
4304
4879
  }
4305
4880
 
4306
- export { AvatarEditor, AvatarEditorDialog, ConfirmDestructiveDialog, CurtainPicker, CurtainPickerSkeleton, CurtainPreview, CurtainStage, DEFAULT_CURTAIN_PICKER_LABELS, DEFAULT_EDITABLE_SECTION_LABELS, DataList, DataListItem, EditableSection, Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyState, EmptyTitle, ErrorState, FeedVideoPlayer, FieldMessage, LanguageContext, LanguageSwitcher, LoadingState, SafeImage, ThemeSwitcher, VideoPlayer, WaitingRoom, avatarFallbackStyle, castHlsUrl, cn, createLiveHlsConfig, createVodHlsConfig, defaultLanguages, describeAvResync, describePlaybackError, getAvatarColors, getInitials, loadCastSender, shouldRetryLiveEdge404, useEditableSection, useFeedExclusivePlayback, useHlsPlayback, useLanguageContext, useMediaQuery2 as useMediaQuery, usePlaybackStats };
4881
+ export { AvatarEditor, AvatarEditorDialog, ConfirmDestructiveDialog, CurtainPicker, CurtainPickerSkeleton, CurtainPreview, CurtainStage, DEFAULT_CURTAIN_PICKER_LABELS, DEFAULT_EDITABLE_SECTION_LABELS, DEFAULT_FILE_DROPZONE_LABELS, DEFAULT_FILE_UPLOAD_LABELS, DEFAULT_FILE_UPLOAD_TRAY_LABELS, DataList, DataListItem, EditableSection, Empty, EmptyContent, EmptyDescription, EmptyHeader, EmptyMedia, EmptyState, EmptyTitle, ErrorState, FeedVideoPlayer, FieldMessage, FileDropzone, FileUploadTray, LanguageContext, LanguageSwitcher, LoadingState, SafeImage, ThemeSwitcher, VideoPlayer, WaitingRoom, avatarFallbackStyle, castHlsUrl, cn, createLiveHlsConfig, createMultipartUploadController, createVodHlsConfig, defaultLanguages, describeAvResync, describePlaybackError, fileMatchesAccept, getAvatarColors, getInitials, loadCastSender, partRanges, progressFromBytes, shouldRetryLiveEdge404, useEditableSection, useFeedExclusivePlayback, useHlsPlayback, useLanguageContext, useMediaQuery2 as useMediaQuery, usePlaybackStats };
4307
4882
  //# sourceMappingURL=index.js.map
4308
4883
  //# sourceMappingURL=index.js.map