@seclai/react 0.0.18 → 0.0.19
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/README.md +23 -15
- package/dist/index.d.ts +40 -19
- package/dist/index.js +205 -55
- package/dist/styles.css +99 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -253,28 +253,40 @@ import { MediaGallery, MediaPreview, MediaSkeleton, MediaViewer } from "@seclai/
|
|
|
253
253
|
/>
|
|
254
254
|
```
|
|
255
255
|
|
|
256
|
-
- **`MediaPreview`** shows one attachment
|
|
257
|
-
-
|
|
256
|
+
- **`MediaPreview`** shows one attachment as a card, chosen by its mime type (ignoring case and parameters such as `; codecs=…`). Every card has a download link, an optional number badge and an `actions` slot:
|
|
257
|
+
- **Images** (`image/*`, SVG included) sit in a fixed-ratio frame, so the layout doesn't jump while they load.
|
|
258
|
+
- **Audio** (`audio/*`) plays in the browser's own `<audio controls>`, under the file's name.
|
|
259
|
+
- **Video** (`video/*`) plays in the browser's own `<video controls playsinline>`, in a frame like an image's.
|
|
260
|
+
- **PDFs** (`application/pdf`) show in the browser's PDF viewer, in an `<object>`. Browsers without one, including most mobile browsers, show a download link in its place.
|
|
261
|
+
- **Anything else**, HTML included, is a download link.
|
|
262
|
+
|
|
263
|
+
Audio and video load only their metadata until played (`preload="metadata"`). A file that fails to load says so in its card, and keeps its download link.
|
|
264
|
+
- **`MediaGallery`** lays out a run's images, audio, video and PDFs as cards, numbered in the attachments' order so the numbers match the agent's numbered list. Images open a full-size viewer. "Download all" saves every card's file when there's more than one, one at a time, because browsers block a burst of simultaneous downloads. Other files follow the cards as download links.
|
|
258
265
|
- **`MediaSkeleton`** is a placeholder card for an image that's still being generated. It pulses, unless the user prefers reduced motion.
|
|
259
|
-
- **`MediaViewer`** is the gallery's full-size viewer, a modal `<dialog>` with previous and next (also on the arrow keys) and a download button. Escape, the close button or a click on the backdrop closes it, and focus goes back to where it was. It's controlled: pass the `index` to show, or `null` when closed.
|
|
260
|
-
- **`attachmentFileName(attachment, number?)`** is the filename the components save a file as: its own name, or else `image
|
|
266
|
+
- **`MediaViewer`** is the gallery's full-size image viewer, a modal `<dialog>` with previous and next (also on the arrow keys) and a download button. Escape, the close button or a click on the backdrop closes it, and focus goes back to where it was. It's controlled: pass the `index` to show, or `null` when closed. Pass `numbers` to name each image by its card number rather than its position. Video and PDFs don't open in it: video has its own full-screen control, and a PDF its browser viewer.
|
|
267
|
+
- **`attachmentFileName(attachment, number?)`** is the filename the components save a file as: its own name, or else its kind and number (`image-2.png`, `audio-3.mp3`, `video-1.mp4`, `pdf-4.pdf`, `file-5.zip`), or its id without a number, with an extension from the mime type.
|
|
261
268
|
|
|
262
269
|
| `MediaPreview` prop | |
|
|
263
270
|
|---|---|
|
|
264
271
|
| `attachment` | Required. The file to show |
|
|
265
|
-
| `aspectRatio` |
|
|
266
|
-
| `number` | A badge on the
|
|
272
|
+
| `aspectRatio` | An image or video frame's ratio, as a number (`16 / 9`) or a string (`"16 / 9"`). Without it the frame takes the file's own ratio once it loads, and `--seclai-media-aspect-ratio` (square) until then. Audio and PDF cards don't use it |
|
|
273
|
+
| `number` | A badge on the card, matching the agent's numbered list. Also names an unnamed file, such as `image-<number>` or `audio-<number>`, for download and for screen readers ("Audio 2") |
|
|
267
274
|
| `actions` | App-specific buttons after the download link: a node, or a function of the attachment |
|
|
268
|
-
| `onOpen` | Makes
|
|
275
|
+
| `onOpen` | Makes an image a button, for opening a viewer. Other files ignore it |
|
|
269
276
|
|
|
270
277
|
| `MediaGallery` prop | |
|
|
271
278
|
|---|---|
|
|
272
279
|
| `attachments` | Required. A run's attachments |
|
|
273
|
-
| `aspectRatio` | Every card's ratio. Without it each
|
|
274
|
-
| `pending` | How many skeleton cards to show after the
|
|
275
|
-
| `actions` | `(attachment, number) => ReactNode`, for each
|
|
280
|
+
| `aspectRatio` | Every image and video card's ratio. Without it each takes its file's own ratio |
|
|
281
|
+
| `pending` | How many skeleton cards to show after the cards, numbered on from them |
|
|
282
|
+
| `actions` | `(attachment, number) => ReactNode`, for each card |
|
|
276
283
|
|
|
277
|
-
The stylesheet adds these variables for media: `--seclai-media-aspect-ratio` (a frame's ratio before its image loads, `1 / 1`), `--seclai-media-fit` (`object-fit` in the frame, `scale-down`, so small images keep their natural size), `--seclai-media-min-width` (a gallery column's minimum width, `220px`)
|
|
284
|
+
The stylesheet adds these variables for media: `--seclai-media-aspect-ratio` (a frame's ratio before its image or video loads, `1 / 1`), `--seclai-media-fit` (`object-fit` in the frame, `scale-down`, so small images keep their natural size), `--seclai-media-min-width` (a gallery column's minimum width, `220px`), `--seclai-media-max-width` (a card's width outside a gallery, `480px`) and `--seclai-media-pdf-aspect-ratio` (a PDF's frame, `3 / 4`). Each kind of card has a class: `.seclai-media-image`, `.seclai-media-audio`, `.seclai-media-video` and `.seclai-media-pdf`, all with `.seclai-media-card`. The viewer is dark in both colour schemes.
|
|
285
|
+
|
|
286
|
+
### Audio, video and PDFs
|
|
287
|
+
|
|
288
|
+
- **Seeking doesn't work yet, and Safari may not play video.** The previews stream through the `download` handler, and the Seclai API doesn't answer HTTP `Range` requests for run attachments yet ([seclai/seclai#2556](https://github.com/seclai/seclai/issues/2556)), nor can `@seclai/sdk` send them ([seclai/seclai-javascript#21](https://github.com/seclai/seclai-javascript/issues/21)). So audio and video play from the start but can't skip ahead, and Safari, which wants `206 Partial Content` for video, may refuse to play it at all. The download link still works. The handler will forward `Range` once both land.
|
|
289
|
+
- **Your Content Security Policy** must let the page load media and objects from the handler's URL: if you set `media-src` or `object-src` (or `default-src`), they need `'self'`, or wherever you mount the handler. `object-src 'none'`, a common recommendation, stops PDFs from showing, as do `frame-ancestors 'none'` and `X-Frame-Options: DENY` on the handler's responses (`SAMEORIGIN` is fine). The handler's own `sandbox` policy on the files it serves doesn't stop `<audio>` and `<video>` from playing them: a response's policy only applies when it's opened as a page.
|
|
278
290
|
|
|
279
291
|
### Saving files
|
|
280
292
|
|
|
@@ -430,10 +442,6 @@ The stylesheet styles Markdown with the same `--seclai-*` variables, in light an
|
|
|
430
442
|
|
|
431
443
|
Two more variables: `--seclai-code-font` (the monospace font for code) and `--seclai-code-surface` (the background of code blocks and inline code).
|
|
432
444
|
|
|
433
|
-
## Placeholders
|
|
434
|
-
|
|
435
|
-
`MediaPreview` is exported so the API is in place, but it's minimal until it's ported from the main Seclai app: it shows image cards (see [Media](#media)) and a download link for everything else. Audio, video and PDF previews are still to come.
|
|
436
|
-
|
|
437
445
|
## License
|
|
438
446
|
|
|
439
447
|
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -351,42 +351,56 @@ type MediaAspectRatio = number | string;
|
|
|
351
351
|
interface MediaPreviewProps {
|
|
352
352
|
attachment: AgentAttachment;
|
|
353
353
|
/**
|
|
354
|
-
* The image frame's aspect ratio. Without it the frame takes the
|
|
355
|
-
* ratio once it loads, and `--seclai-media-aspect-ratio` (square
|
|
356
|
-
* until then.
|
|
354
|
+
* The image or video frame's aspect ratio. Without it the frame takes the
|
|
355
|
+
* file's own ratio once it loads, and `--seclai-media-aspect-ratio` (square
|
|
356
|
+
* by default) until then. Audio and PDF cards don't use it.
|
|
357
357
|
*/
|
|
358
358
|
aspectRatio?: MediaAspectRatio;
|
|
359
|
-
/** A badge on the
|
|
359
|
+
/** A badge on the card, matching the agent's numbered list ("1.", "2."). */
|
|
360
360
|
number?: number;
|
|
361
361
|
/** App-specific buttons, shown after the download link. A function gets the attachment. */
|
|
362
362
|
actions?: ReactNode | ((attachment: AgentAttachment) => ReactNode);
|
|
363
|
-
/** Makes
|
|
363
|
+
/** Makes an image a button, for opening a full-size viewer. Other files ignore it. */
|
|
364
364
|
onOpen?(): void;
|
|
365
365
|
}
|
|
366
366
|
/**
|
|
367
|
-
* Shows a file from a run
|
|
368
|
-
*
|
|
369
|
-
*
|
|
367
|
+
* Shows a file from a run, by its mime type (ignoring case and parameters):
|
|
368
|
+
*
|
|
369
|
+
* - an image in a fixed-ratio frame, which can open a full-size viewer;
|
|
370
|
+
* - audio with the browser's own controls;
|
|
371
|
+
* - video with the browser's own controls, in a frame like an image's;
|
|
372
|
+
* - a PDF in the browser's PDF viewer, or a download link where there isn't one;
|
|
373
|
+
* - anything else as a download link.
|
|
374
|
+
*
|
|
375
|
+
* Every card has a download link, an optional number badge and an `actions`
|
|
376
|
+
* slot. A file that fails to load says so, and keeps its download link.
|
|
370
377
|
*/
|
|
371
378
|
declare function MediaPreview({ attachment, aspectRatio, number, actions, onOpen }: MediaPreviewProps): react.JSX.Element;
|
|
372
379
|
|
|
373
380
|
interface MediaGalleryProps {
|
|
374
|
-
/**
|
|
381
|
+
/**
|
|
382
|
+
* A run's attachments. Images, audio, video and PDFs become cards, numbered in
|
|
383
|
+
* this order; other files follow as download links.
|
|
384
|
+
*/
|
|
375
385
|
attachments: AgentAttachment[];
|
|
376
|
-
/**
|
|
386
|
+
/**
|
|
387
|
+
* Every image and video card's aspect ratio. Without it each takes its file's
|
|
388
|
+
* own ratio. Audio and PDF cards keep their own shape.
|
|
389
|
+
*/
|
|
377
390
|
aspectRatio?: MediaAspectRatio;
|
|
378
391
|
/**
|
|
379
|
-
* Skeleton cards to show after the
|
|
380
|
-
* They're numbered on from the last
|
|
392
|
+
* Skeleton cards to show after the cards, for images still being generated.
|
|
393
|
+
* They're numbered on from the last card.
|
|
381
394
|
*/
|
|
382
395
|
pending?: number;
|
|
383
396
|
/** App-specific buttons for each card. Gets the attachment and its 1-based number. */
|
|
384
397
|
actions?(attachment: AgentAttachment, number: number): ReactNode;
|
|
385
398
|
}
|
|
386
399
|
/**
|
|
387
|
-
* Lays out a run's images
|
|
388
|
-
*
|
|
389
|
-
*
|
|
400
|
+
* Lays out a run's images, audio, video and PDFs as numbered cards, in the
|
|
401
|
+
* attachments' order, so the numbers match the agent's numbered list. Images
|
|
402
|
+
* open a full-size viewer. "Download all" saves every card's file when there's
|
|
403
|
+
* more than one. Other files follow the cards as download links.
|
|
390
404
|
*/
|
|
391
405
|
declare function MediaGallery({ attachments, aspectRatio, pending, actions, }: MediaGalleryProps): react.JSX.Element;
|
|
392
406
|
|
|
@@ -406,8 +420,14 @@ interface MediaSkeletonProps {
|
|
|
406
420
|
declare function MediaSkeleton({ aspectRatio, number, label }: MediaSkeletonProps): react.JSX.Element;
|
|
407
421
|
|
|
408
422
|
interface MediaViewerProps {
|
|
409
|
-
/** The images to page through, in order. Image `i` is numbered `i + 1
|
|
423
|
+
/** The images to page through, in order. Image `i` is numbered `i + 1`, unless `numbers` says otherwise. */
|
|
410
424
|
attachments: AgentAttachment[];
|
|
425
|
+
/**
|
|
426
|
+
* Each image's number, as on its card, for its name and filename. A gallery
|
|
427
|
+
* with audio, video or PDF cards between its images passes these, so image 3
|
|
428
|
+
* isn't called "Image 2" because it's the second image.
|
|
429
|
+
*/
|
|
430
|
+
numbers?: readonly number[];
|
|
411
431
|
/** The image showing, or `null` when the viewer is closed. */
|
|
412
432
|
index: number | null;
|
|
413
433
|
/** Called with the new index when the user goes to the previous or next image. */
|
|
@@ -421,11 +441,12 @@ interface MediaViewerProps {
|
|
|
421
441
|
* show, and `null` to close it. Focus moves into the viewer when it opens and
|
|
422
442
|
* back to where it was when it closes.
|
|
423
443
|
*/
|
|
424
|
-
declare function MediaViewer({ attachments, index, onIndexChange, onClose }: MediaViewerProps): react.JSX.Element;
|
|
444
|
+
declare function MediaViewer({ attachments, numbers, index, onIndexChange, onClose }: MediaViewerProps): react.JSX.Element;
|
|
425
445
|
|
|
426
446
|
/**
|
|
427
|
-
* The filename to save an attachment as: its own name, or else
|
|
428
|
-
* (
|
|
447
|
+
* The filename to save an attachment as: its own name, or else its kind and
|
|
448
|
+
* number (`image-2`, `audio-3`, `video-1`, `pdf-4`, or `file-5` for anything
|
|
449
|
+
* else), or its id without a number, with an extension from its mime type.
|
|
429
450
|
*/
|
|
430
451
|
declare function attachmentFileName(attachment: AgentAttachment, number?: number): string;
|
|
431
452
|
/**
|
package/dist/index.js
CHANGED
|
@@ -561,9 +561,6 @@ var MarkdownContent = memo(function MarkdownContent2({
|
|
|
561
561
|
// src/media/MediaGallery.tsx
|
|
562
562
|
import { useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
|
|
563
563
|
|
|
564
|
-
// src/placeholders/MediaPreview.tsx
|
|
565
|
-
import { useEffect as useEffect2, useRef, useState as useState3 } from "react";
|
|
566
|
-
|
|
567
564
|
// src/media/files.ts
|
|
568
565
|
var EXTENSIONS = {
|
|
569
566
|
"image/jpeg": "jpg",
|
|
@@ -576,11 +573,22 @@ var EXTENSIONS = {
|
|
|
576
573
|
"text/markdown": "md",
|
|
577
574
|
"application/octet-stream": "bin"
|
|
578
575
|
};
|
|
576
|
+
function baseMime(mime) {
|
|
577
|
+
return mime.split(";")[0].trim().toLowerCase();
|
|
578
|
+
}
|
|
579
579
|
function isImage(attachment) {
|
|
580
|
-
return attachment.mime
|
|
580
|
+
return baseMime(attachment.mime).startsWith("image/");
|
|
581
|
+
}
|
|
582
|
+
function mediaKind(attachment) {
|
|
583
|
+
const type = baseMime(attachment.mime);
|
|
584
|
+
if (type.startsWith("image/")) return "image";
|
|
585
|
+
if (type.startsWith("audio/")) return "audio";
|
|
586
|
+
if (type.startsWith("video/")) return "video";
|
|
587
|
+
if (type === "application/pdf") return "pdf";
|
|
588
|
+
return null;
|
|
581
589
|
}
|
|
582
590
|
function extensionForMime(mime) {
|
|
583
|
-
const type = mime
|
|
591
|
+
const type = baseMime(mime);
|
|
584
592
|
const known = EXTENSIONS[type];
|
|
585
593
|
if (known) return known;
|
|
586
594
|
const subtype = type.split("/")[1] ?? "";
|
|
@@ -589,7 +597,7 @@ function extensionForMime(mime) {
|
|
|
589
597
|
}
|
|
590
598
|
function attachmentFileName(attachment, number) {
|
|
591
599
|
if (attachment.name) return attachment.name;
|
|
592
|
-
const base2 = number != null ?
|
|
600
|
+
const base2 = number != null ? `${mediaKind(attachment) ?? "file"}-${number}` : attachment.id;
|
|
593
601
|
return `${base2}.${extensionForMime(attachment.mime)}`;
|
|
594
602
|
}
|
|
595
603
|
var SAFE_PROTOCOLS = /* @__PURE__ */ new Set(["http:", "https:", "blob:"]);
|
|
@@ -646,7 +654,8 @@ function wait(ms, signal) {
|
|
|
646
654
|
});
|
|
647
655
|
}
|
|
648
656
|
|
|
649
|
-
// src/
|
|
657
|
+
// src/media/MediaPreview.tsx
|
|
658
|
+
import { useEffect as useEffect2, useRef, useState as useState3 } from "react";
|
|
650
659
|
import { Fragment as Fragment2, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
651
660
|
function hasContent(node) {
|
|
652
661
|
return node != null && node !== false && node !== "";
|
|
@@ -654,35 +663,66 @@ function hasContent(node) {
|
|
|
654
663
|
function aspectRatioStyle(ratio) {
|
|
655
664
|
return ratio == null ? void 0 : { aspectRatio: String(ratio) };
|
|
656
665
|
}
|
|
657
|
-
|
|
658
|
-
|
|
666
|
+
var KIND_LABELS = {
|
|
667
|
+
image: "Image",
|
|
668
|
+
audio: "Audio",
|
|
669
|
+
video: "Video",
|
|
670
|
+
pdf: "PDF"
|
|
671
|
+
};
|
|
672
|
+
function kindLabel(attachment) {
|
|
673
|
+
const kind = mediaKind(attachment);
|
|
674
|
+
return kind ? KIND_LABELS[kind] : "File";
|
|
675
|
+
}
|
|
676
|
+
function mediaLabel(attachment, number) {
|
|
677
|
+
if (attachment.name) return attachment.name;
|
|
678
|
+
const kind = kindLabel(attachment);
|
|
679
|
+
return number != null ? `${kind} ${number}` : kind;
|
|
659
680
|
}
|
|
660
681
|
function MediaPreview({ attachment, aspectRatio, number, actions, onOpen }) {
|
|
661
682
|
const filename = attachmentFileName(attachment, number);
|
|
662
683
|
const extra = typeof actions === "function" ? actions(attachment) : actions;
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
684
|
+
const card = { attachment, number, filename, extra };
|
|
685
|
+
switch (mediaKind(attachment)) {
|
|
686
|
+
case "image":
|
|
687
|
+
return /* @__PURE__ */ jsx3(ImageCard, { ...card, aspectRatio, onOpen });
|
|
688
|
+
case "video":
|
|
689
|
+
return /* @__PURE__ */ jsx3(VideoCard, { ...card, aspectRatio });
|
|
690
|
+
case "audio":
|
|
691
|
+
return /* @__PURE__ */ jsx3(AudioCard, { ...card });
|
|
692
|
+
case "pdf":
|
|
693
|
+
return /* @__PURE__ */ jsx3(PdfCard, { ...card });
|
|
694
|
+
default:
|
|
695
|
+
return /* @__PURE__ */ jsx3("figure", { className: "seclai-media", children: /* @__PURE__ */ jsxs("figcaption", { children: [
|
|
696
|
+
/* @__PURE__ */ jsx3("a", { href: attachment.url, download: filename, children: attachment.name || filename }),
|
|
697
|
+
hasContent(extra) && /* @__PURE__ */ jsx3("span", { className: "seclai-media-actions", children: extra })
|
|
698
|
+
] }) });
|
|
668
699
|
}
|
|
669
|
-
return /* @__PURE__ */ jsx3(
|
|
670
|
-
ImageCard,
|
|
671
|
-
{
|
|
672
|
-
attachment,
|
|
673
|
-
aspectRatio,
|
|
674
|
-
number,
|
|
675
|
-
filename,
|
|
676
|
-
extra,
|
|
677
|
-
onOpen
|
|
678
|
-
}
|
|
679
|
-
);
|
|
680
700
|
}
|
|
681
|
-
function
|
|
701
|
+
function Badge({ number }) {
|
|
702
|
+
return number != null ? /* @__PURE__ */ jsx3("span", { className: "seclai-media-badge", children: number }) : null;
|
|
703
|
+
}
|
|
704
|
+
function CardBar({ attachment, number, filename, extra }) {
|
|
705
|
+
return /* @__PURE__ */ jsxs("figcaption", { className: "seclai-media-bar", children: [
|
|
706
|
+
/* @__PURE__ */ jsx3("a", { href: attachment.url, download: filename, "aria-label": `Download ${mediaLabel(attachment, number)}`, children: "Download" }),
|
|
707
|
+
hasContent(extra) && /* @__PURE__ */ jsx3("span", { className: "seclai-media-actions", children: extra })
|
|
708
|
+
] });
|
|
709
|
+
}
|
|
710
|
+
function CardHead({ attachment, number }) {
|
|
711
|
+
return /* @__PURE__ */ jsxs("div", { className: "seclai-media-head", children: [
|
|
712
|
+
/* @__PURE__ */ jsx3(Badge, { number }),
|
|
713
|
+
/* @__PURE__ */ jsx3("span", { className: "seclai-media-title", children: attachment.name || kindLabel(attachment) })
|
|
714
|
+
] });
|
|
715
|
+
}
|
|
716
|
+
function ImageCard({
|
|
717
|
+
aspectRatio,
|
|
718
|
+
onOpen,
|
|
719
|
+
...card
|
|
720
|
+
}) {
|
|
721
|
+
const { attachment, number } = card;
|
|
682
722
|
const img = useRef(null);
|
|
683
723
|
const [natural, setNatural] = useState3(null);
|
|
684
724
|
const [failed, setFailed] = useState3(false);
|
|
685
|
-
const label =
|
|
725
|
+
const label = mediaLabel(attachment, number);
|
|
686
726
|
function measure() {
|
|
687
727
|
const el = img.current;
|
|
688
728
|
if (el && el.naturalWidth > 0 && el.naturalHeight > 0) {
|
|
@@ -711,10 +751,10 @@ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen })
|
|
|
711
751
|
onError: () => setFailed(true)
|
|
712
752
|
}
|
|
713
753
|
),
|
|
714
|
-
|
|
754
|
+
/* @__PURE__ */ jsx3(Badge, { number })
|
|
715
755
|
] });
|
|
716
756
|
const frameStyle = aspectRatioStyle(aspectRatio ?? natural ?? void 0);
|
|
717
|
-
return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-image", children: [
|
|
757
|
+
return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-card seclai-media-image", children: [
|
|
718
758
|
onOpen ? /* @__PURE__ */ jsx3(
|
|
719
759
|
"button",
|
|
720
760
|
{
|
|
@@ -727,10 +767,108 @@ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen })
|
|
|
727
767
|
children: frameContent
|
|
728
768
|
}
|
|
729
769
|
) : /* @__PURE__ */ jsx3("div", { className: "seclai-media-frame", style: frameStyle, children: frameContent }),
|
|
730
|
-
/* @__PURE__ */
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
770
|
+
/* @__PURE__ */ jsx3(CardBar, { ...card })
|
|
771
|
+
] });
|
|
772
|
+
}
|
|
773
|
+
function VideoCard({ aspectRatio, ...card }) {
|
|
774
|
+
const { attachment, number } = card;
|
|
775
|
+
const video = useRef(null);
|
|
776
|
+
const [natural, setNatural] = useState3(null);
|
|
777
|
+
const [failed, setFailed] = useState3(false);
|
|
778
|
+
function measure() {
|
|
779
|
+
const el = video.current;
|
|
780
|
+
if (el && el.videoWidth > 0 && el.videoHeight > 0) {
|
|
781
|
+
setNatural(`${el.videoWidth} / ${el.videoHeight}`);
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
useEffect2(() => {
|
|
785
|
+
setNatural(null);
|
|
786
|
+
setFailed(false);
|
|
787
|
+
const el = video.current;
|
|
788
|
+
if (el?.error) setFailed(true);
|
|
789
|
+
else if (el && el.readyState >= HTMLMediaElement.HAVE_METADATA) measure();
|
|
790
|
+
}, [attachment.url]);
|
|
791
|
+
return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-card seclai-media-video", children: [
|
|
792
|
+
/* @__PURE__ */ jsxs("div", { className: "seclai-media-frame", style: aspectRatioStyle(aspectRatio ?? natural ?? void 0), children: [
|
|
793
|
+
failed ? /* @__PURE__ */ jsx3("span", { className: "seclai-media-error", children: "Couldn't load the video." }) : /* @__PURE__ */ jsx3(
|
|
794
|
+
"video",
|
|
795
|
+
{
|
|
796
|
+
ref: video,
|
|
797
|
+
src: attachment.url,
|
|
798
|
+
controls: true,
|
|
799
|
+
preload: "metadata",
|
|
800
|
+
playsInline: true,
|
|
801
|
+
"aria-label": mediaLabel(attachment, number),
|
|
802
|
+
onLoadedMetadata: measure,
|
|
803
|
+
onError: () => setFailed(true)
|
|
804
|
+
}
|
|
805
|
+
),
|
|
806
|
+
/* @__PURE__ */ jsx3(Badge, { number })
|
|
807
|
+
] }),
|
|
808
|
+
/* @__PURE__ */ jsx3(CardBar, { ...card })
|
|
809
|
+
] });
|
|
810
|
+
}
|
|
811
|
+
function AudioCard(card) {
|
|
812
|
+
const { attachment, number } = card;
|
|
813
|
+
const audio = useRef(null);
|
|
814
|
+
const [failed, setFailed] = useState3(false);
|
|
815
|
+
useEffect2(() => {
|
|
816
|
+
setFailed(audio.current?.error != null);
|
|
817
|
+
}, [attachment.url]);
|
|
818
|
+
return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-card seclai-media-audio", children: [
|
|
819
|
+
/* @__PURE__ */ jsx3(CardHead, { attachment, number }),
|
|
820
|
+
/* @__PURE__ */ jsx3("div", { className: "seclai-media-body", children: failed ? /* @__PURE__ */ jsx3("span", { className: "seclai-media-error", children: "Couldn't load the audio." }) : /* @__PURE__ */ jsx3(
|
|
821
|
+
"audio",
|
|
822
|
+
{
|
|
823
|
+
ref: audio,
|
|
824
|
+
src: attachment.url,
|
|
825
|
+
controls: true,
|
|
826
|
+
preload: "metadata",
|
|
827
|
+
"aria-label": mediaLabel(attachment, number),
|
|
828
|
+
onError: () => setFailed(true)
|
|
829
|
+
}
|
|
830
|
+
) }),
|
|
831
|
+
/* @__PURE__ */ jsx3(CardBar, { ...card })
|
|
832
|
+
] });
|
|
833
|
+
}
|
|
834
|
+
function PdfCard(card) {
|
|
835
|
+
const { attachment, number, filename } = card;
|
|
836
|
+
const object = useRef(null);
|
|
837
|
+
const [failed, setFailed] = useState3(false);
|
|
838
|
+
const label = mediaLabel(attachment, number);
|
|
839
|
+
useEffect2(() => setFailed(false), [attachment.url]);
|
|
840
|
+
useEffect2(() => {
|
|
841
|
+
const el = object.current;
|
|
842
|
+
if (!el) return;
|
|
843
|
+
const fail = () => setFailed(true);
|
|
844
|
+
el.addEventListener("error", fail);
|
|
845
|
+
return () => el.removeEventListener("error", fail);
|
|
846
|
+
}, [attachment.url, failed]);
|
|
847
|
+
return /* @__PURE__ */ jsxs("figure", { className: "seclai-media seclai-media-card seclai-media-pdf", children: [
|
|
848
|
+
/* @__PURE__ */ jsx3(CardHead, { attachment, number }),
|
|
849
|
+
/* @__PURE__ */ jsx3("div", { className: "seclai-media-frame", children: failed ? /* @__PURE__ */ jsx3("span", { className: "seclai-media-error", children: "Couldn't load the PDF." }) : (
|
|
850
|
+
// Keyed on the URL: browsers don't reliably reload an <object> whose
|
|
851
|
+
// data changes.
|
|
852
|
+
/* @__PURE__ */ jsx3(
|
|
853
|
+
"object",
|
|
854
|
+
{
|
|
855
|
+
ref: object,
|
|
856
|
+
type: "application/pdf",
|
|
857
|
+
data: attachment.url,
|
|
858
|
+
"aria-label": label,
|
|
859
|
+
children: /* @__PURE__ */ jsxs("span", { className: "seclai-media-fallback", children: [
|
|
860
|
+
"This browser can't show the PDF here.",
|
|
861
|
+
" ",
|
|
862
|
+
/* @__PURE__ */ jsxs("a", { href: attachment.url, download: filename, children: [
|
|
863
|
+
"Download ",
|
|
864
|
+
label
|
|
865
|
+
] })
|
|
866
|
+
] })
|
|
867
|
+
},
|
|
868
|
+
attachment.url
|
|
869
|
+
)
|
|
870
|
+
) }),
|
|
871
|
+
/* @__PURE__ */ jsx3(CardBar, { ...card })
|
|
734
872
|
] });
|
|
735
873
|
}
|
|
736
874
|
|
|
@@ -738,7 +876,7 @@ function ImageCard({ attachment, aspectRatio, number, filename, extra, onOpen })
|
|
|
738
876
|
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
739
877
|
function MediaSkeleton({ aspectRatio, number, label }) {
|
|
740
878
|
const name = label ?? (number != null ? `Image ${number} is being generated` : "Image is being generated");
|
|
741
|
-
return /* @__PURE__ */ jsxs2("div", { className: "seclai-media seclai-media-image seclai-media-skeleton", role: "img", "aria-label": name, children: [
|
|
879
|
+
return /* @__PURE__ */ jsxs2("div", { className: "seclai-media seclai-media-card seclai-media-image seclai-media-skeleton", role: "img", "aria-label": name, children: [
|
|
742
880
|
/* @__PURE__ */ jsx4("div", { className: "seclai-media-frame", style: aspectRatioStyle(aspectRatio), children: number != null && /* @__PURE__ */ jsx4("span", { className: "seclai-media-badge", children: number }) }),
|
|
743
881
|
/* @__PURE__ */ jsx4("div", { className: "seclai-media-bar", children: /* @__PURE__ */ jsx4("span", { className: "seclai-media-skeleton-line" }) })
|
|
744
882
|
] });
|
|
@@ -747,7 +885,7 @@ function MediaSkeleton({ aspectRatio, number, label }) {
|
|
|
747
885
|
// src/media/MediaViewer.tsx
|
|
748
886
|
import { useEffect as useEffect3, useId, useRef as useRef2 } from "react";
|
|
749
887
|
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
750
|
-
function MediaViewer({ attachments, index, onIndexChange, onClose }) {
|
|
888
|
+
function MediaViewer({ attachments, numbers, index, onIndexChange, onClose }) {
|
|
751
889
|
const dialog = useRef2(null);
|
|
752
890
|
const closeButton = useRef2(null);
|
|
753
891
|
const returnFocus = useRef2(null);
|
|
@@ -805,8 +943,9 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
|
|
|
805
943
|
function onClick(event) {
|
|
806
944
|
if (event.target === event.currentTarget) onClose();
|
|
807
945
|
}
|
|
808
|
-
const
|
|
809
|
-
const
|
|
946
|
+
const position = index != null ? index + 1 : 0;
|
|
947
|
+
const number = index != null ? numbers?.[index] ?? position : 0;
|
|
948
|
+
const label = current ? mediaLabel(current, number) : "";
|
|
810
949
|
return /* @__PURE__ */ jsx5(
|
|
811
950
|
"dialog",
|
|
812
951
|
{
|
|
@@ -823,7 +962,7 @@ function MediaViewer({ attachments, index, onIndexChange, onClose }) {
|
|
|
823
962
|
/* @__PURE__ */ jsxs3("p", { className: "seclai-viewer-title", id: titleId, children: [
|
|
824
963
|
label,
|
|
825
964
|
attachments.length > 1 && /* @__PURE__ */ jsxs3("span", { className: "seclai-viewer-count", children: [
|
|
826
|
-
|
|
965
|
+
position,
|
|
827
966
|
" of ",
|
|
828
967
|
attachments.length
|
|
829
968
|
] })
|
|
@@ -866,8 +1005,15 @@ function MediaGallery({
|
|
|
866
1005
|
pending = 0,
|
|
867
1006
|
actions
|
|
868
1007
|
}) {
|
|
869
|
-
const
|
|
870
|
-
const files = attachments.filter((attachment) =>
|
|
1008
|
+
const cards = attachments.filter((attachment) => mediaKind(attachment) != null);
|
|
1009
|
+
const files = attachments.filter((attachment) => mediaKind(attachment) == null);
|
|
1010
|
+
const images = [];
|
|
1011
|
+
const imageNumbers = [];
|
|
1012
|
+
const viewerIndexes = cards.map((card, i) => {
|
|
1013
|
+
if (!isImage(card)) return null;
|
|
1014
|
+
imageNumbers.push(i + 1);
|
|
1015
|
+
return images.push(card) - 1;
|
|
1016
|
+
});
|
|
871
1017
|
const [viewing, setViewing] = useState4(null);
|
|
872
1018
|
const [downloading, setDownloading] = useState4(false);
|
|
873
1019
|
const abort = useRef3(null);
|
|
@@ -880,7 +1026,7 @@ function MediaGallery({
|
|
|
880
1026
|
setDownloading(true);
|
|
881
1027
|
try {
|
|
882
1028
|
await saveFiles(
|
|
883
|
-
|
|
1029
|
+
cards.map((card, i) => ({ source: card.url, filename: attachmentFileName(card, i + 1) })),
|
|
884
1030
|
{ delayMs: DOWNLOAD_ALL_DELAY_MS, signal: controller.signal }
|
|
885
1031
|
);
|
|
886
1032
|
} finally {
|
|
@@ -889,27 +1035,30 @@ function MediaGallery({
|
|
|
889
1035
|
}
|
|
890
1036
|
const skeletons = Math.max(0, Math.floor(pending));
|
|
891
1037
|
return /* @__PURE__ */ jsxs4("div", { className: "seclai-gallery", children: [
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
{
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
1038
|
+
cards.length + skeletons > 0 && /* @__PURE__ */ jsxs4("ul", { className: "seclai-gallery-grid", children: [
|
|
1039
|
+
cards.map((card, i) => {
|
|
1040
|
+
const image = viewerIndexes[i];
|
|
1041
|
+
return /* @__PURE__ */ jsx6("li", { children: /* @__PURE__ */ jsx6(
|
|
1042
|
+
MediaPreview,
|
|
1043
|
+
{
|
|
1044
|
+
attachment: card,
|
|
1045
|
+
aspectRatio,
|
|
1046
|
+
number: i + 1,
|
|
1047
|
+
actions: actions?.(card, i + 1),
|
|
1048
|
+
onOpen: image != null ? () => setViewing(image) : void 0
|
|
1049
|
+
}
|
|
1050
|
+
) }, card.id);
|
|
1051
|
+
}),
|
|
1052
|
+
Array.from({ length: skeletons }, (_, i) => /* @__PURE__ */ jsx6("li", { children: /* @__PURE__ */ jsx6(MediaSkeleton, { aspectRatio, number: cards.length + i + 1 }) }, `pending-${i}`))
|
|
904
1053
|
] }),
|
|
905
|
-
|
|
1054
|
+
cards.length > 1 && /* @__PURE__ */ jsx6("div", { className: "seclai-gallery-actions", children: /* @__PURE__ */ jsx6(
|
|
906
1055
|
"button",
|
|
907
1056
|
{
|
|
908
1057
|
type: "button",
|
|
909
1058
|
className: "seclai-button",
|
|
910
1059
|
"aria-disabled": downloading,
|
|
911
1060
|
onClick: downloadAll,
|
|
912
|
-
children: downloading ? "Downloading\u2026" : `Download all ${
|
|
1061
|
+
children: downloading ? "Downloading\u2026" : `Download all ${cards.length}`
|
|
913
1062
|
}
|
|
914
1063
|
) }),
|
|
915
1064
|
files.map((file) => /* @__PURE__ */ jsx6(MediaPreview, { attachment: file }, file.id)),
|
|
@@ -917,6 +1066,7 @@ function MediaGallery({
|
|
|
917
1066
|
MediaViewer,
|
|
918
1067
|
{
|
|
919
1068
|
attachments: images,
|
|
1069
|
+
numbers: imageNumbers,
|
|
920
1070
|
index: viewing,
|
|
921
1071
|
onIndexChange: setViewing,
|
|
922
1072
|
onClose: () => setViewing(null)
|
package/dist/styles.css
CHANGED
|
@@ -686,23 +686,25 @@ div.seclai-markdown-math {
|
|
|
686
686
|
}
|
|
687
687
|
|
|
688
688
|
/*
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
* --seclai-media-
|
|
692
|
-
* --seclai-media-
|
|
693
|
-
* --seclai-media-
|
|
689
|
+
* Media cards (image, video, audio and PDF), galleries, skeletons and the
|
|
690
|
+
* viewer. Also themable with:
|
|
691
|
+
* --seclai-media-aspect-ratio a frame's ratio before its image or video loads (1 / 1)
|
|
692
|
+
* --seclai-media-fit object-fit for the image in its frame (scale-down)
|
|
693
|
+
* --seclai-media-min-width a gallery column's minimum width (220px)
|
|
694
|
+
* --seclai-media-max-width a card's width outside a gallery (480px)
|
|
695
|
+
* --seclai-media-pdf-aspect-ratio a PDF frame's ratio (3 / 4)
|
|
694
696
|
*/
|
|
695
697
|
.seclai-gallery,
|
|
696
698
|
.seclai-gallery *,
|
|
697
|
-
.seclai-media-
|
|
698
|
-
.seclai-media-
|
|
699
|
+
.seclai-media-card,
|
|
700
|
+
.seclai-media-card *,
|
|
699
701
|
.seclai-viewer,
|
|
700
702
|
.seclai-viewer * {
|
|
701
703
|
box-sizing: border-box;
|
|
702
704
|
}
|
|
703
705
|
|
|
704
706
|
.seclai-gallery :focus-visible,
|
|
705
|
-
.seclai-media-
|
|
707
|
+
.seclai-media-card :focus-visible,
|
|
706
708
|
.seclai-viewer :focus-visible {
|
|
707
709
|
outline: 2px solid var(--seclai-focus);
|
|
708
710
|
outline-offset: 2px;
|
|
@@ -724,7 +726,7 @@ div.seclai-markdown-math {
|
|
|
724
726
|
}
|
|
725
727
|
}
|
|
726
728
|
|
|
727
|
-
.seclai-media-
|
|
729
|
+
.seclai-media-card {
|
|
728
730
|
width: 100%;
|
|
729
731
|
max-width: var(--seclai-media-max-width, 480px);
|
|
730
732
|
gap: 0;
|
|
@@ -774,6 +776,78 @@ button.seclai-media-frame:focus-visible {
|
|
|
774
776
|
}
|
|
775
777
|
}
|
|
776
778
|
|
|
779
|
+
.seclai-media-frame > video,
|
|
780
|
+
.seclai-media-frame > object {
|
|
781
|
+
display: block;
|
|
782
|
+
width: 100%;
|
|
783
|
+
height: 100%;
|
|
784
|
+
border: 0;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/* Black bars, as in any video player, rather than the frame's tint. */
|
|
788
|
+
.seclai-media-frame:has(> video) {
|
|
789
|
+
background: #000000;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
.seclai-media-frame > video {
|
|
793
|
+
object-fit: contain;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
/* Inset, as on an image's button: the frame fills the card and clips anything outside it. */
|
|
797
|
+
.seclai-media-frame > video:focus-visible,
|
|
798
|
+
.seclai-media-frame > object:focus-visible {
|
|
799
|
+
outline-offset: -2px;
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
.seclai-media-pdf .seclai-media-frame {
|
|
803
|
+
aspect-ratio: var(--seclai-media-pdf-aspect-ratio, 3 / 4);
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
/* Shown in place of the PDF by browsers without a PDF viewer. */
|
|
807
|
+
.seclai-media-fallback {
|
|
808
|
+
display: flex;
|
|
809
|
+
flex-direction: column;
|
|
810
|
+
align-items: center;
|
|
811
|
+
justify-content: center;
|
|
812
|
+
gap: 8px;
|
|
813
|
+
height: 100%;
|
|
814
|
+
padding: 12px;
|
|
815
|
+
color: var(--seclai-muted);
|
|
816
|
+
text-align: center;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
/* Audio and PDF cards name the file above it, with the badge. */
|
|
820
|
+
.seclai-media-head {
|
|
821
|
+
display: flex;
|
|
822
|
+
align-items: center;
|
|
823
|
+
gap: 8px;
|
|
824
|
+
min-width: 0;
|
|
825
|
+
padding: 8px 12px;
|
|
826
|
+
border-bottom: 1px solid var(--seclai-border);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
.seclai-media-title {
|
|
830
|
+
overflow: hidden;
|
|
831
|
+
font-weight: 600;
|
|
832
|
+
text-overflow: ellipsis;
|
|
833
|
+
white-space: nowrap;
|
|
834
|
+
}
|
|
835
|
+
|
|
836
|
+
.seclai-media-body {
|
|
837
|
+
padding: 8px 12px 0;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
.seclai-media-audio audio {
|
|
841
|
+
display: block;
|
|
842
|
+
width: 100%;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
.seclai-media-audio .seclai-media-error {
|
|
846
|
+
position: static;
|
|
847
|
+
justify-content: flex-start;
|
|
848
|
+
padding: 0;
|
|
849
|
+
}
|
|
850
|
+
|
|
777
851
|
/*
|
|
778
852
|
* A number badge, on an image and on the matching item of a numbered list in
|
|
779
853
|
* the agent's text. Fixed colours: the badge sits on the image, not on the page.
|
|
@@ -799,6 +873,16 @@ button.seclai-media-frame:focus-visible {
|
|
|
799
873
|
position: absolute;
|
|
800
874
|
top: 8px;
|
|
801
875
|
inset-inline-start: 8px;
|
|
876
|
+
/* Clicks go through to the video under it. */
|
|
877
|
+
pointer-events: none;
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
/* On the page rather than on a picture, so it inverts in a dark colour scheme, like a list number's. */
|
|
881
|
+
.seclai-media-head .seclai-media-badge {
|
|
882
|
+
position: static;
|
|
883
|
+
flex: none;
|
|
884
|
+
color: light-dark(#ffffff, #000000);
|
|
885
|
+
background: light-dark(rgb(0 0 0 / 0.72), rgb(255 255 255 / 0.85));
|
|
802
886
|
}
|
|
803
887
|
|
|
804
888
|
/* On the page, the same badge inverts in a dark colour scheme, so it still stands out. */
|
|
@@ -882,11 +966,16 @@ button.seclai-media-frame:focus-visible {
|
|
|
882
966
|
min-width: 0;
|
|
883
967
|
}
|
|
884
968
|
|
|
885
|
-
.seclai-gallery-grid .seclai-media-
|
|
969
|
+
.seclai-gallery-grid .seclai-media-card {
|
|
886
970
|
max-width: none;
|
|
887
971
|
height: 100%;
|
|
888
972
|
}
|
|
889
973
|
|
|
974
|
+
/* In a row of taller cards, an audio card's player sits at the top and its bar at the bottom. */
|
|
975
|
+
.seclai-gallery-grid .seclai-media-audio .seclai-media-body {
|
|
976
|
+
flex: 1;
|
|
977
|
+
}
|
|
978
|
+
|
|
890
979
|
.seclai-gallery-actions {
|
|
891
980
|
display: flex;
|
|
892
981
|
flex-wrap: wrap;
|