@ai-matrx/media 0.4.2 → 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/CHANGELOG.md +17 -0
- package/dist/viewers.cjs +11 -121
- package/dist/viewers.cjs.map +1 -1
- package/dist/viewers.js +9 -119
- package/dist/viewers.js.map +1 -1
- package/package.json +1 -1
package/dist/viewers.js
CHANGED
|
@@ -1391,105 +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, useLayoutEffect, 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
|
-
const recoveryInFlightRef = useRef3(false);
|
|
1416
|
-
useEffect6(() => {
|
|
1417
|
-
attemptRef.current = 0;
|
|
1418
|
-
recoveryInFlightRef.current = false;
|
|
1419
|
-
}, [src]);
|
|
1420
|
-
useLayoutEffect(() => {
|
|
1421
|
-
recoveryInFlightRef.current = false;
|
|
1422
|
-
}, [result.retryKey]);
|
|
1423
|
-
const identity = () => failureMediaIdentity(failureRef ?? null, src);
|
|
1424
|
-
const onLoadError = (event) => {
|
|
1425
|
-
if (recoveryInFlightRef.current) return;
|
|
1426
|
-
if (!src || !recoverable) {
|
|
1427
|
-
setResult({ source: src, retryKey: 0, failed: true });
|
|
1428
|
-
if (src) {
|
|
1429
|
-
capture({
|
|
1430
|
-
phase: "element-load",
|
|
1431
|
-
mediaRef: identity(),
|
|
1432
|
-
terminal: true,
|
|
1433
|
-
retryOutcome: "not-attempted",
|
|
1434
|
-
message: "media element failed to load and the source is unrecoverable (foreign/object URL \u2014 a session refresh cannot fix it)"
|
|
1435
|
-
});
|
|
1436
|
-
}
|
|
1437
|
-
onTerminal?.(event);
|
|
1438
|
-
return;
|
|
1439
|
-
}
|
|
1440
|
-
recoveryInFlightRef.current = true;
|
|
1441
|
-
attemptRef.current += 1;
|
|
1442
|
-
const attempt = attemptRef.current;
|
|
1443
|
-
client.recoverLoadError(mintDurableSrc(src), attempt).then(
|
|
1444
|
-
(outcome) => {
|
|
1445
|
-
const report = normalizeOutcome(outcome);
|
|
1446
|
-
if (report.secretSource === "ephemeral") {
|
|
1447
|
-
capture({
|
|
1448
|
-
phase: "session",
|
|
1449
|
-
mediaRef: EPHEMERAL_SECRET_IDENTITY,
|
|
1450
|
-
terminal: false,
|
|
1451
|
-
message: "server cookie secret is ephemeral \u2014 private renders will break across restarts/instances (set a persistent files-session secret on the server)"
|
|
1452
|
-
});
|
|
1453
|
-
}
|
|
1454
|
-
if (report.verdict === "retry") {
|
|
1455
|
-
setResult((current) => ({
|
|
1456
|
-
source: src,
|
|
1457
|
-
retryKey: current.source === src ? current.retryKey + 1 : 1,
|
|
1458
|
-
failed: false
|
|
1459
|
-
}));
|
|
1460
|
-
} else {
|
|
1461
|
-
setResult({ source: src, retryKey: 0, failed: true });
|
|
1462
|
-
capture({
|
|
1463
|
-
phase: attempt > 1 ? "element-load" : "recovery",
|
|
1464
|
-
mediaRef: identity(),
|
|
1465
|
-
terminal: true,
|
|
1466
|
-
retryOutcome: attempt > 1 ? "retried" : "not-attempted",
|
|
1467
|
-
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)",
|
|
1468
|
-
...report.status !== void 0 ? { status: report.status } : {}
|
|
1469
|
-
});
|
|
1470
|
-
onTerminal?.(event);
|
|
1471
|
-
}
|
|
1472
|
-
},
|
|
1473
|
-
(err) => {
|
|
1474
|
-
setResult({ source: src, retryKey: 0, failed: true });
|
|
1475
|
-
capture({
|
|
1476
|
-
phase: "session",
|
|
1477
|
-
mediaRef: identity(),
|
|
1478
|
-
terminal: true,
|
|
1479
|
-
retryOutcome: "recovery-failed",
|
|
1480
|
-
message: `session recovery failed: ${err instanceof Error ? err.message : String(err ?? "unknown error")}`
|
|
1481
|
-
});
|
|
1482
|
-
onTerminal?.(event);
|
|
1483
|
-
}
|
|
1484
|
-
);
|
|
1485
|
-
};
|
|
1486
|
-
return {
|
|
1487
|
-
retryKey: result.source === src ? result.retryKey : 0,
|
|
1488
|
-
onLoadError,
|
|
1489
|
-
failed: result.source === src ? result.failed : false
|
|
1490
|
-
};
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
1394
|
// src/viewers/transparency-grid.ts
|
|
1494
1395
|
var TRANSPARENCY_GRID_STYLE = {
|
|
1495
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%)",
|
|
@@ -1524,30 +1425,21 @@ function SvgViewer(props) {
|
|
|
1524
1425
|
);
|
|
1525
1426
|
}
|
|
1526
1427
|
function SvgRenderedView({ source, fileName }) {
|
|
1527
|
-
const
|
|
1528
|
-
const
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
if (unavailable) {
|
|
1533
|
-
return /* @__PURE__ */ jsx9(
|
|
1534
|
-
ViewerError,
|
|
1535
|
-
{
|
|
1536
|
-
title: "This SVG isn't available",
|
|
1537
|
-
hint: "You may not have access to it, or it may have been deleted."
|
|
1538
|
-
}
|
|
1539
|
-
);
|
|
1540
|
-
}
|
|
1541
|
-
if (!url) return /* @__PURE__ */ jsx9(ViewerSkeleton, { className: "flex-1" });
|
|
1542
|
-
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) {
|
|
1543
1433
|
return /* @__PURE__ */ jsx9(
|
|
1544
1434
|
ViewerError,
|
|
1545
1435
|
{
|
|
1546
1436
|
title: "SVG could not be rendered",
|
|
1437
|
+
message: error,
|
|
1547
1438
|
hint: "Switch to the Source view to inspect the markup."
|
|
1548
1439
|
}
|
|
1549
1440
|
);
|
|
1550
1441
|
}
|
|
1442
|
+
if (loading || !url) return /* @__PURE__ */ jsx9(ViewerSkeleton, { className: "flex-1" });
|
|
1551
1443
|
return /* @__PURE__ */ jsx9(
|
|
1552
1444
|
"div",
|
|
1553
1445
|
{
|
|
@@ -1558,10 +1450,8 @@ function SvgRenderedView({ source, fileName }) {
|
|
|
1558
1450
|
{
|
|
1559
1451
|
src: url,
|
|
1560
1452
|
alt: fileName,
|
|
1561
|
-
className: "max-h-full max-w-full object-contain drop-shadow-sm"
|
|
1562
|
-
|
|
1563
|
-
},
|
|
1564
|
-
retryKey
|
|
1453
|
+
className: "max-h-full max-w-full object-contain drop-shadow-sm"
|
|
1454
|
+
}
|
|
1565
1455
|
)
|
|
1566
1456
|
}
|
|
1567
1457
|
);
|