@ai-matrx/media 0.4.1 → 0.4.3

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/viewers.js CHANGED
@@ -1391,98 +1391,6 @@ function HtmlSourceView({ source, maxBytes = 1024 * 1024 }) {
1391
1391
  return /* @__PURE__ */ jsx8("pre", { className: "h-full w-full overflow-auto bg-muted/10 p-4 font-mono text-xs leading-relaxed break-all whitespace-pre-wrap", children: text });
1392
1392
  }
1393
1393
 
1394
- // src/core/use-media-load-recovery.ts
1395
- import { useEffect as useEffect6, useRef as useRef3, useState as useState8 } from "react";
1396
-
1397
- // src/types.ts
1398
- function mintDurableSrc(url) {
1399
- return url;
1400
- }
1401
-
1402
- // src/core/use-media-load-recovery.ts
1403
- function normalizeOutcome(outcome) {
1404
- return typeof outcome === "string" ? { verdict: outcome } : outcome;
1405
- }
1406
- var EPHEMERAL_SECRET_IDENTITY = "server:files-session-secret";
1407
- function useMediaLoadRecovery(src, options) {
1408
- const client = useMediaClient();
1409
- const capture = useMediaFailureCapture();
1410
- const recoverable = options?.recoverable !== false;
1411
- const onTerminal = options?.onTerminal;
1412
- const failureRef = options?.failureRef;
1413
- const [result, setResult] = useState8({ source: src, retryKey: 0, failed: false });
1414
- const attemptRef = useRef3(0);
1415
- useEffect6(() => {
1416
- attemptRef.current = 0;
1417
- }, [src]);
1418
- const identity = () => failureMediaIdentity(failureRef ?? null, src);
1419
- const onLoadError = (event) => {
1420
- if (!src || !recoverable) {
1421
- setResult({ source: src, retryKey: 0, failed: true });
1422
- if (src) {
1423
- capture({
1424
- phase: "element-load",
1425
- mediaRef: identity(),
1426
- terminal: true,
1427
- retryOutcome: "not-attempted",
1428
- message: "media element failed to load and the source is unrecoverable (foreign/object URL \u2014 a session refresh cannot fix it)"
1429
- });
1430
- }
1431
- onTerminal?.(event);
1432
- return;
1433
- }
1434
- attemptRef.current += 1;
1435
- const attempt = attemptRef.current;
1436
- client.recoverLoadError(mintDurableSrc(src), attempt).then(
1437
- (outcome) => {
1438
- const report = normalizeOutcome(outcome);
1439
- if (report.secretSource === "ephemeral") {
1440
- capture({
1441
- phase: "session",
1442
- mediaRef: EPHEMERAL_SECRET_IDENTITY,
1443
- terminal: false,
1444
- message: "server cookie secret is ephemeral \u2014 private renders will break across restarts/instances (set a persistent files-session secret on the server)"
1445
- });
1446
- }
1447
- if (report.verdict === "retry") {
1448
- setResult((current) => ({
1449
- source: src,
1450
- retryKey: current.source === src ? current.retryKey + 1 : 1,
1451
- failed: false
1452
- }));
1453
- } else {
1454
- setResult({ source: src, retryKey: 0, failed: true });
1455
- capture({
1456
- phase: attempt > 1 ? "element-load" : "recovery",
1457
- mediaRef: identity(),
1458
- terminal: true,
1459
- retryOutcome: attempt > 1 ? "retried" : "not-attempted",
1460
- message: attempt > 1 ? "media element failed to load after the session-refresh retry" : "media load recovery declined on the first attempt (session refresh did not produce a usable session)",
1461
- ...report.status !== void 0 ? { status: report.status } : {}
1462
- });
1463
- onTerminal?.(event);
1464
- }
1465
- },
1466
- (err) => {
1467
- setResult({ source: src, retryKey: 0, failed: true });
1468
- capture({
1469
- phase: "session",
1470
- mediaRef: identity(),
1471
- terminal: true,
1472
- retryOutcome: "recovery-failed",
1473
- message: `session recovery failed: ${err instanceof Error ? err.message : String(err ?? "unknown error")}`
1474
- });
1475
- onTerminal?.(event);
1476
- }
1477
- );
1478
- };
1479
- return {
1480
- retryKey: result.source === src ? result.retryKey : 0,
1481
- onLoadError,
1482
- failed: result.source === src ? result.failed : false
1483
- };
1484
- }
1485
-
1486
1394
  // src/viewers/transparency-grid.ts
1487
1395
  var TRANSPARENCY_GRID_STYLE = {
1488
1396
  backgroundImage: "linear-gradient(45deg, rgb(0 0 0 / 0.08) 25%, transparent 25%), linear-gradient(-45deg, rgb(0 0 0 / 0.08) 25%, transparent 25%), linear-gradient(45deg, transparent 75%, rgb(0 0 0 / 0.08) 75%), linear-gradient(-45deg, transparent 75%, rgb(0 0 0 / 0.08) 75%)",
@@ -1517,30 +1425,21 @@ function SvgViewer(props) {
1517
1425
  );
1518
1426
  }
1519
1427
  function SvgRenderedView({ source, fileName }) {
1520
- const { url, recoverable, unavailable } = useViewerDisplayUrl(source);
1521
- const { retryKey, onLoadError, failed } = useMediaLoadRecovery(url, {
1522
- recoverable,
1523
- ...source.kind === "ref" ? { failureRef: source.ref } : {}
1524
- });
1525
- if (unavailable) {
1526
- return /* @__PURE__ */ jsx9(
1527
- ViewerError,
1528
- {
1529
- title: "This SVG isn't available",
1530
- hint: "You may not have access to it, or it may have been deleted."
1531
- }
1532
- );
1533
- }
1534
- if (!url) return /* @__PURE__ */ jsx9(ViewerSkeleton, { className: "flex-1" });
1535
- if (failed) {
1428
+ const fromClient = useMediaBlob(source.kind === "ref" ? source.ref : null);
1429
+ const url = source.kind === "blob" ? source.url : fromClient.url;
1430
+ const loading = source.kind === "ref" && fromClient.loading;
1431
+ const error = source.kind === "ref" ? fromClient.error : null;
1432
+ if (error) {
1536
1433
  return /* @__PURE__ */ jsx9(
1537
1434
  ViewerError,
1538
1435
  {
1539
1436
  title: "SVG could not be rendered",
1437
+ message: error,
1540
1438
  hint: "Switch to the Source view to inspect the markup."
1541
1439
  }
1542
1440
  );
1543
1441
  }
1442
+ if (loading || !url) return /* @__PURE__ */ jsx9(ViewerSkeleton, { className: "flex-1" });
1544
1443
  return /* @__PURE__ */ jsx9(
1545
1444
  "div",
1546
1445
  {
@@ -1551,10 +1450,8 @@ function SvgRenderedView({ source, fileName }) {
1551
1450
  {
1552
1451
  src: url,
1553
1452
  alt: fileName,
1554
- className: "max-h-full max-w-full object-contain drop-shadow-sm",
1555
- onError: onLoadError
1556
- },
1557
- retryKey
1453
+ className: "max-h-full max-w-full object-contain drop-shadow-sm"
1454
+ }
1558
1455
  )
1559
1456
  }
1560
1457
  );