@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/CHANGELOG.md +31 -0
- package/README.md +4 -0
- package/dist/core.cjs +7 -0
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +8 -1
- package/dist/core.js.map +1 -1
- package/dist/react.cjs +7 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +8 -1
- package/dist/react.js.map +1 -1
- package/dist/viewers.cjs +11 -114
- package/dist/viewers.cjs.map +1 -1
- package/dist/viewers.js +9 -112
- package/dist/viewers.js.map +1 -1
- package/package.json +1 -1
package/dist/viewers.cjs
CHANGED
|
@@ -47,7 +47,7 @@ __export(viewers_exports, {
|
|
|
47
47
|
module.exports = __toCommonJS(viewers_exports);
|
|
48
48
|
|
|
49
49
|
// src/viewers/media-file-viewer.tsx
|
|
50
|
-
var
|
|
50
|
+
var import_react11 = require("react");
|
|
51
51
|
|
|
52
52
|
// src/viewers/registry.ts
|
|
53
53
|
var VIEWER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.media.viewer-registry");
|
|
@@ -1433,98 +1433,6 @@ function HtmlSourceView({ source, maxBytes = 1024 * 1024 }) {
|
|
|
1433
1433
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("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 });
|
|
1434
1434
|
}
|
|
1435
1435
|
|
|
1436
|
-
// src/core/use-media-load-recovery.ts
|
|
1437
|
-
var import_react11 = require("react");
|
|
1438
|
-
|
|
1439
|
-
// src/types.ts
|
|
1440
|
-
function mintDurableSrc(url) {
|
|
1441
|
-
return url;
|
|
1442
|
-
}
|
|
1443
|
-
|
|
1444
|
-
// src/core/use-media-load-recovery.ts
|
|
1445
|
-
function normalizeOutcome(outcome) {
|
|
1446
|
-
return typeof outcome === "string" ? { verdict: outcome } : outcome;
|
|
1447
|
-
}
|
|
1448
|
-
var EPHEMERAL_SECRET_IDENTITY = "server:files-session-secret";
|
|
1449
|
-
function useMediaLoadRecovery(src, options) {
|
|
1450
|
-
const client = useMediaClient();
|
|
1451
|
-
const capture = useMediaFailureCapture();
|
|
1452
|
-
const recoverable = options?.recoverable !== false;
|
|
1453
|
-
const onTerminal = options?.onTerminal;
|
|
1454
|
-
const failureRef = options?.failureRef;
|
|
1455
|
-
const [result, setResult] = (0, import_react11.useState)({ source: src, retryKey: 0, failed: false });
|
|
1456
|
-
const attemptRef = (0, import_react11.useRef)(0);
|
|
1457
|
-
(0, import_react11.useEffect)(() => {
|
|
1458
|
-
attemptRef.current = 0;
|
|
1459
|
-
}, [src]);
|
|
1460
|
-
const identity = () => failureMediaIdentity(failureRef ?? null, src);
|
|
1461
|
-
const onLoadError = (event) => {
|
|
1462
|
-
if (!src || !recoverable) {
|
|
1463
|
-
setResult({ source: src, retryKey: 0, failed: true });
|
|
1464
|
-
if (src) {
|
|
1465
|
-
capture({
|
|
1466
|
-
phase: "element-load",
|
|
1467
|
-
mediaRef: identity(),
|
|
1468
|
-
terminal: true,
|
|
1469
|
-
retryOutcome: "not-attempted",
|
|
1470
|
-
message: "media element failed to load and the source is unrecoverable (foreign/object URL \u2014 a session refresh cannot fix it)"
|
|
1471
|
-
});
|
|
1472
|
-
}
|
|
1473
|
-
onTerminal?.(event);
|
|
1474
|
-
return;
|
|
1475
|
-
}
|
|
1476
|
-
attemptRef.current += 1;
|
|
1477
|
-
const attempt = attemptRef.current;
|
|
1478
|
-
client.recoverLoadError(mintDurableSrc(src), attempt).then(
|
|
1479
|
-
(outcome) => {
|
|
1480
|
-
const report = normalizeOutcome(outcome);
|
|
1481
|
-
if (report.secretSource === "ephemeral") {
|
|
1482
|
-
capture({
|
|
1483
|
-
phase: "session",
|
|
1484
|
-
mediaRef: EPHEMERAL_SECRET_IDENTITY,
|
|
1485
|
-
terminal: false,
|
|
1486
|
-
message: "server cookie secret is ephemeral \u2014 private renders will break across restarts/instances (set a persistent files-session secret on the server)"
|
|
1487
|
-
});
|
|
1488
|
-
}
|
|
1489
|
-
if (report.verdict === "retry") {
|
|
1490
|
-
setResult((current) => ({
|
|
1491
|
-
source: src,
|
|
1492
|
-
retryKey: current.source === src ? current.retryKey + 1 : 1,
|
|
1493
|
-
failed: false
|
|
1494
|
-
}));
|
|
1495
|
-
} else {
|
|
1496
|
-
setResult({ source: src, retryKey: 0, failed: true });
|
|
1497
|
-
capture({
|
|
1498
|
-
phase: attempt > 1 ? "element-load" : "recovery",
|
|
1499
|
-
mediaRef: identity(),
|
|
1500
|
-
terminal: true,
|
|
1501
|
-
retryOutcome: attempt > 1 ? "retried" : "not-attempted",
|
|
1502
|
-
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)",
|
|
1503
|
-
...report.status !== void 0 ? { status: report.status } : {}
|
|
1504
|
-
});
|
|
1505
|
-
onTerminal?.(event);
|
|
1506
|
-
}
|
|
1507
|
-
},
|
|
1508
|
-
(err) => {
|
|
1509
|
-
setResult({ source: src, retryKey: 0, failed: true });
|
|
1510
|
-
capture({
|
|
1511
|
-
phase: "session",
|
|
1512
|
-
mediaRef: identity(),
|
|
1513
|
-
terminal: true,
|
|
1514
|
-
retryOutcome: "recovery-failed",
|
|
1515
|
-
message: `session recovery failed: ${err instanceof Error ? err.message : String(err ?? "unknown error")}`
|
|
1516
|
-
});
|
|
1517
|
-
onTerminal?.(event);
|
|
1518
|
-
}
|
|
1519
|
-
);
|
|
1520
|
-
};
|
|
1521
|
-
return {
|
|
1522
|
-
retryKey: result.source === src ? result.retryKey : 0,
|
|
1523
|
-
onLoadError,
|
|
1524
|
-
failed: result.source === src ? result.failed : false
|
|
1525
|
-
};
|
|
1526
|
-
}
|
|
1527
|
-
|
|
1528
1436
|
// src/viewers/transparency-grid.ts
|
|
1529
1437
|
var TRANSPARENCY_GRID_STYLE = {
|
|
1530
1438
|
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%)",
|
|
@@ -1559,30 +1467,21 @@ function SvgViewer(props) {
|
|
|
1559
1467
|
);
|
|
1560
1468
|
}
|
|
1561
1469
|
function SvgRenderedView({ source, fileName }) {
|
|
1562
|
-
const
|
|
1563
|
-
const
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
if (unavailable) {
|
|
1568
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1569
|
-
ViewerError,
|
|
1570
|
-
{
|
|
1571
|
-
title: "This SVG isn't available",
|
|
1572
|
-
hint: "You may not have access to it, or it may have been deleted."
|
|
1573
|
-
}
|
|
1574
|
-
);
|
|
1575
|
-
}
|
|
1576
|
-
if (!url) return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ViewerSkeleton, { className: "flex-1" });
|
|
1577
|
-
if (failed) {
|
|
1470
|
+
const fromClient = useMediaBlob(source.kind === "ref" ? source.ref : null);
|
|
1471
|
+
const url = source.kind === "blob" ? source.url : fromClient.url;
|
|
1472
|
+
const loading = source.kind === "ref" && fromClient.loading;
|
|
1473
|
+
const error = source.kind === "ref" ? fromClient.error : null;
|
|
1474
|
+
if (error) {
|
|
1578
1475
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1579
1476
|
ViewerError,
|
|
1580
1477
|
{
|
|
1581
1478
|
title: "SVG could not be rendered",
|
|
1479
|
+
message: error,
|
|
1582
1480
|
hint: "Switch to the Source view to inspect the markup."
|
|
1583
1481
|
}
|
|
1584
1482
|
);
|
|
1585
1483
|
}
|
|
1484
|
+
if (loading || !url) return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(ViewerSkeleton, { className: "flex-1" });
|
|
1586
1485
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
1587
1486
|
"div",
|
|
1588
1487
|
{
|
|
@@ -1593,10 +1492,8 @@ function SvgRenderedView({ source, fileName }) {
|
|
|
1593
1492
|
{
|
|
1594
1493
|
src: url,
|
|
1595
1494
|
alt: fileName,
|
|
1596
|
-
className: "max-h-full max-w-full object-contain drop-shadow-sm"
|
|
1597
|
-
|
|
1598
|
-
},
|
|
1599
|
-
retryKey
|
|
1495
|
+
className: "max-h-full max-w-full object-contain drop-shadow-sm"
|
|
1496
|
+
}
|
|
1600
1497
|
)
|
|
1601
1498
|
}
|
|
1602
1499
|
);
|
|
@@ -1750,7 +1647,7 @@ function MediaFileViewer({
|
|
|
1750
1647
|
}) {
|
|
1751
1648
|
const kind = previewKind ?? getPreviewKind(props.fileName, props.mimeType ?? null);
|
|
1752
1649
|
const viewer = getMediaViewer(kind) ?? BUILT_IN[kind];
|
|
1753
|
-
if (viewer) return (0,
|
|
1650
|
+
if (viewer) return (0, import_react11.createElement)(viewer, props);
|
|
1754
1651
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MediaViewerUnavailable, { ...props, kind });
|
|
1755
1652
|
}
|
|
1756
1653
|
//# sourceMappingURL=viewers.cjs.map
|