@ai-matrx/media 0.4.5 → 0.5.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/react.cjs CHANGED
@@ -66,7 +66,6 @@ __export(react_exports, {
66
66
  VolumeXIcon: () => VolumeXIcon,
67
67
  XIcon: () => XIcon,
68
68
  cn: () => cn,
69
- formatFileSize: () => formatFileSize,
70
69
  useMediaDropzone: () => useMediaDropzone
71
70
  });
72
71
  module.exports = __toCommonJS(react_exports);
@@ -1453,7 +1452,9 @@ function useThumbnailSource(ref, options = {}) {
1453
1452
  mode: "thumbnail",
1454
1453
  loading: false,
1455
1454
  resolution,
1456
- recoverable: explicitThumb.recoverable !== false
1455
+ recoverable: explicitThumb.recoverable !== false,
1456
+ blobBacked: false,
1457
+ retryBlob: blob.retry
1457
1458
  };
1458
1459
  }
1459
1460
  if (resolution?.thumbnailSrc) {
@@ -1462,7 +1463,9 @@ function useThumbnailSource(ref, options = {}) {
1462
1463
  mode: "thumbnail",
1463
1464
  loading: false,
1464
1465
  resolution,
1465
- recoverable: resolution.recoverable !== false
1466
+ recoverable: resolution.recoverable !== false,
1467
+ blobBacked: false,
1468
+ retryBlob: blob.retry
1466
1469
  };
1467
1470
  }
1468
1471
  if (allowSourceFallback && resolution) {
@@ -1472,7 +1475,9 @@ function useThumbnailSource(ref, options = {}) {
1472
1475
  mode: blob.url ? resolution.kind === "video" ? "live-video-poster" : "live-image" : "icon",
1473
1476
  loading: blob.loading,
1474
1477
  resolution,
1475
- recoverable: false
1478
+ recoverable: false,
1479
+ blobBacked: true,
1480
+ retryBlob: blob.retry
1476
1481
  };
1477
1482
  }
1478
1483
  if (resolution.kind === "image") {
@@ -1481,7 +1486,9 @@ function useThumbnailSource(ref, options = {}) {
1481
1486
  mode: "live-image",
1482
1487
  loading: false,
1483
1488
  resolution,
1484
- recoverable: resolution.recoverable !== false
1489
+ recoverable: resolution.recoverable !== false,
1490
+ blobBacked: false,
1491
+ retryBlob: blob.retry
1485
1492
  };
1486
1493
  }
1487
1494
  if (resolution.kind === "video") {
@@ -1490,7 +1497,9 @@ function useThumbnailSource(ref, options = {}) {
1490
1497
  mode: "live-video-poster",
1491
1498
  loading: false,
1492
1499
  resolution,
1493
- recoverable: resolution.recoverable !== false
1500
+ recoverable: resolution.recoverable !== false,
1501
+ blobBacked: false,
1502
+ retryBlob: blob.retry
1494
1503
  };
1495
1504
  }
1496
1505
  }
@@ -1499,7 +1508,9 @@ function useThumbnailSource(ref, options = {}) {
1499
1508
  mode: "icon",
1500
1509
  loading: false,
1501
1510
  resolution,
1502
- recoverable: false
1511
+ recoverable: false,
1512
+ blobBacked: false,
1513
+ retryBlob: blob.retry
1503
1514
  };
1504
1515
  }
1505
1516
 
@@ -1529,6 +1540,8 @@ function MediaThumbnail({
1529
1540
  url: source.src,
1530
1541
  mediaRef,
1531
1542
  recoverable: source.recoverable,
1543
+ blobBacked: source.blobBacked,
1544
+ retryBlob: source.retryBlob,
1532
1545
  fallback
1533
1546
  }
1534
1547
  );
@@ -1540,6 +1553,8 @@ function MediaThumbnail({
1540
1553
  alt: fileName,
1541
1554
  mediaRef,
1542
1555
  recoverable: source.recoverable,
1556
+ blobBacked: source.blobBacked,
1557
+ retryBlob: source.retryBlob,
1543
1558
  fallback
1544
1559
  }
1545
1560
  );
@@ -1558,13 +1573,21 @@ function ImageThumb({
1558
1573
  alt,
1559
1574
  mediaRef,
1560
1575
  recoverable,
1576
+ blobBacked,
1577
+ retryBlob,
1561
1578
  fallback
1562
1579
  }) {
1563
1580
  const { retryKey, onLoadError, failed } = useMediaLoadRecovery(url, {
1564
1581
  recoverable,
1565
1582
  failureRef: mediaRef
1566
1583
  });
1567
- if (failed) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: fallback });
1584
+ const blobRecovery = useMediaBlobLoadRecovery(
1585
+ blobBacked ? mediaRef : null,
1586
+ blobBacked ? url : null,
1587
+ { onRetry: retryBlob }
1588
+ );
1589
+ const activeRecovery = blobBacked ? { retryKey: 0, ...blobRecovery } : { retryKey, onLoadError, failed };
1590
+ if (activeRecovery.failed) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: fallback });
1568
1591
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1569
1592
  "img",
1570
1593
  {
@@ -1572,21 +1595,29 @@ function ImageThumb({
1572
1595
  alt,
1573
1596
  loading: url.startsWith("blob:") ? "eager" : "lazy",
1574
1597
  className: "h-full w-full object-cover",
1575
- onError: onLoadError
1598
+ onError: activeRecovery.onLoadError
1576
1599
  },
1577
- retryKey
1600
+ activeRecovery.retryKey
1578
1601
  );
1579
1602
  }
1580
1603
  function VideoPosterThumb({
1581
1604
  url,
1582
1605
  mediaRef,
1583
1606
  recoverable,
1607
+ blobBacked,
1608
+ retryBlob,
1584
1609
  fallback
1585
1610
  }) {
1586
1611
  const { retryKey, onLoadError, failed } = useMediaLoadRecovery(url, {
1587
1612
  recoverable,
1588
1613
  failureRef: mediaRef
1589
1614
  });
1615
+ const blobRecovery = useMediaBlobLoadRecovery(
1616
+ blobBacked ? mediaRef : null,
1617
+ blobBacked ? url : null,
1618
+ { onRetry: retryBlob }
1619
+ );
1620
+ const activeRecovery = blobBacked ? { retryKey: 0, ...blobRecovery } : { retryKey, onLoadError, failed };
1590
1621
  const ref = (0, import_react9.useRef)(null);
1591
1622
  (0, import_react9.useEffect)(() => {
1592
1623
  const v = ref.current;
@@ -1600,7 +1631,7 @@ function VideoPosterThumb({
1600
1631
  v.addEventListener("loadedmetadata", onMeta);
1601
1632
  return () => v.removeEventListener("loadedmetadata", onMeta);
1602
1633
  }, []);
1603
- if (failed) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: fallback });
1634
+ if (activeRecovery.failed) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: fallback });
1604
1635
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1605
1636
  "video",
1606
1637
  {
@@ -1610,9 +1641,9 @@ function VideoPosterThumb({
1610
1641
  preload: "metadata",
1611
1642
  muted: true,
1612
1643
  playsInline: true,
1613
- onError: onLoadError
1644
+ onError: activeRecovery.onLoadError
1614
1645
  },
1615
- retryKey
1646
+ activeRecovery.retryKey
1616
1647
  );
1617
1648
  }
1618
1649
 
@@ -1893,20 +1924,9 @@ function useMediaUpload() {
1893
1924
 
1894
1925
  // src/react/upload-progress-list.tsx
1895
1926
  var import_react12 = require("react");
1927
+ var import_format = require("@ai-matrx/kit/format");
1896
1928
  var import_jsx_runtime5 = require("react/jsx-runtime");
1897
1929
  var AUTO_DISMISS_MS = 1e4;
1898
- function formatFileSize(bytes) {
1899
- if (bytes == null || !Number.isFinite(bytes) || bytes < 0) return "\u2014";
1900
- if (bytes < 1024) return `${bytes} B`;
1901
- const units = ["KB", "MB", "GB", "TB"];
1902
- let value = bytes;
1903
- let unit = -1;
1904
- do {
1905
- value /= 1024;
1906
- unit += 1;
1907
- } while (value >= 1024 && unit < units.length - 1);
1908
- return `${value >= 10 ? Math.round(value) : value.toFixed(1)} ${units[unit] ?? "TB"}`;
1909
- }
1910
1930
  function UploadProgressListImpl({
1911
1931
  uploads,
1912
1932
  onDismiss,
@@ -2016,10 +2036,10 @@ function UploadProgressListImpl({
2016
2036
  }
2017
2037
  ) }),
2018
2038
  failed && u.error ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("p", { className: "mt-0.5 truncate text-[10px] text-destructive", children: u.error }) : !done ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("p", { className: "mt-0.5 text-[10px] text-muted-foreground", children: [
2019
- formatFileSize(u.bytesUploaded),
2039
+ (0, import_format.formatFileSize)(u.bytesUploaded),
2020
2040
  " /",
2021
2041
  " ",
2022
- formatFileSize(u.fileSize)
2042
+ (0, import_format.formatFileSize)(u.fileSize)
2023
2043
  ] }) : null
2024
2044
  ] }),
2025
2045
  canOpen ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "flex shrink-0 items-center gap-1 rounded px-1.5 py-0.5 text-[11px] font-medium text-primary", children: [