@k2b/ui 0.55.0 → 0.57.0

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.
Files changed (126) hide show
  1. package/dist/browser/actions/SplitButton.js +5 -7
  2. package/dist/browser/actions/SplitButton.js.map +1 -1
  3. package/dist/browser/actions/Toolbar.js +16 -7
  4. package/dist/browser/actions/Toolbar.js.map +1 -1
  5. package/dist/browser/actions/ViewTabs.js +6 -5
  6. package/dist/browser/actions/ViewTabs.js.map +1 -1
  7. package/dist/browser/chat/ChatComposer.js +28 -27
  8. package/dist/browser/chat/ChatComposer.js.map +1 -1
  9. package/dist/browser/content/Lightbox.js +917 -283
  10. package/dist/browser/content/Lightbox.js.map +1 -1
  11. package/dist/browser/content/PdfPages.js +8 -3
  12. package/dist/browser/content/PdfPages.js.map +1 -1
  13. package/dist/browser/content/PdfThumbnails.js +271 -0
  14. package/dist/browser/content/PdfThumbnails.js.map +1 -0
  15. package/dist/browser/content/PdfViewer.js +11 -3
  16. package/dist/browser/content/PdfViewer.js.map +1 -1
  17. package/dist/browser/content/Timeline.js +116 -117
  18. package/dist/browser/content/Timeline.js.map +1 -1
  19. package/dist/browser/content/code-highlight.js +24 -11
  20. package/dist/browser/content/code-highlight.js.map +1 -1
  21. package/dist/browser/content/index.js +5 -1
  22. package/dist/browser/content/index.js.map +1 -1
  23. package/dist/browser/content/lightbox-messages.js +64 -18
  24. package/dist/browser/content/lightbox-messages.js.map +1 -1
  25. package/dist/browser/content/lightbox-renderers.js +6 -0
  26. package/dist/browser/content/lightbox-renderers.js.map +1 -0
  27. package/dist/browser/content/map-view-worker.js +3 -3
  28. package/dist/browser/content/pdf-messages.js +16 -2
  29. package/dist/browser/content/pdf-messages.js.map +1 -1
  30. package/dist/browser/content/pdf-viewer-engine.js +15 -15
  31. package/dist/browser/content/pdf-viewer-worker.js +4 -5
  32. package/dist/browser/feedback/prompt-confirm.js +2 -0
  33. package/dist/browser/feedback/prompt-confirm.js.map +1 -1
  34. package/dist/browser/internal/truncated-title.js +9 -0
  35. package/dist/browser/internal/truncated-title.js.map +1 -0
  36. package/dist/browser/intl/messages.js +1 -1
  37. package/dist/browser/intl/messages.js.map +1 -1
  38. package/dist/browser/layout/DetailPanel.js +3 -5
  39. package/dist/browser/layout/DetailPanel.js.map +1 -1
  40. package/dist/browser/layout/FloatingWindow.js +416 -122
  41. package/dist/browser/layout/FloatingWindow.js.map +1 -1
  42. package/dist/browser/layout/PanelDialog.js +3 -1
  43. package/dist/browser/layout/PanelDialog.js.map +1 -1
  44. package/dist/browser/layout/PersonPopover.js +406 -0
  45. package/dist/browser/layout/PersonPopover.js.map +1 -0
  46. package/dist/browser/layout/floating-window-geometry.js +58 -2
  47. package/dist/browser/layout/floating-window-geometry.js.map +1 -1
  48. package/dist/browser/layout/floating-window-messages.js +12 -0
  49. package/dist/browser/layout/floating-window-messages.js.map +1 -1
  50. package/dist/browser/layout/index.js +1 -0
  51. package/dist/browser/layout/index.js.map +1 -1
  52. package/dist/ssr/actions/CommandMenu.js +2 -2
  53. package/dist/ssr/actions/CommandMenu.js.map +1 -1
  54. package/dist/ssr/actions/SplitButton.js +5 -7
  55. package/dist/ssr/actions/SplitButton.js.map +1 -1
  56. package/dist/ssr/actions/Toolbar.js +16 -7
  57. package/dist/ssr/actions/Toolbar.js.map +1 -1
  58. package/dist/ssr/actions/ViewTabs.js +6 -5
  59. package/dist/ssr/actions/ViewTabs.js.map +1 -1
  60. package/dist/ssr/chat/ChatComposer.js +31 -30
  61. package/dist/ssr/chat/ChatComposer.js.map +1 -1
  62. package/dist/ssr/content/Lightbox.js +659 -150
  63. package/dist/ssr/content/Lightbox.js.map +1 -1
  64. package/dist/ssr/content/PdfPages.js +8 -3
  65. package/dist/ssr/content/PdfPages.js.map +1 -1
  66. package/dist/ssr/content/PdfThumbnails.js +189 -0
  67. package/dist/ssr/content/PdfThumbnails.js.map +1 -0
  68. package/dist/ssr/content/PdfViewer.js +11 -3
  69. package/dist/ssr/content/PdfViewer.js.map +1 -1
  70. package/dist/ssr/content/Timeline.js +2 -5
  71. package/dist/ssr/content/Timeline.js.map +1 -1
  72. package/dist/ssr/content/code-highlight.js +24 -11
  73. package/dist/ssr/content/code-highlight.js.map +1 -1
  74. package/dist/ssr/content/index.js +5 -1
  75. package/dist/ssr/content/index.js.map +1 -1
  76. package/dist/ssr/content/lightbox-messages.js +64 -18
  77. package/dist/ssr/content/lightbox-messages.js.map +1 -1
  78. package/dist/ssr/content/lightbox-renderers.js +6 -0
  79. package/dist/ssr/content/lightbox-renderers.js.map +1 -0
  80. package/dist/ssr/content/pdf-messages.js +16 -2
  81. package/dist/ssr/content/pdf-messages.js.map +1 -1
  82. package/dist/ssr/feedback/prompt-confirm.js +1 -0
  83. package/dist/ssr/feedback/prompt-confirm.js.map +1 -1
  84. package/dist/ssr/inputs/ChoiceInputs.js +2 -2
  85. package/dist/ssr/inputs/ChoiceInputs.js.map +1 -1
  86. package/dist/ssr/inputs/SignatureInput.js +2 -2
  87. package/dist/ssr/inputs/SignatureInput.js.map +1 -1
  88. package/dist/ssr/inputs/markdown/SlashCommands.js +2 -2
  89. package/dist/ssr/inputs/markdown/SlashCommands.js.map +1 -1
  90. package/dist/ssr/internal/truncated-title.js +9 -0
  91. package/dist/ssr/internal/truncated-title.js.map +1 -0
  92. package/dist/ssr/intl/messages.js +1 -1
  93. package/dist/ssr/intl/messages.js.map +1 -1
  94. package/dist/ssr/layout/DetailPanel.js +1 -4
  95. package/dist/ssr/layout/DetailPanel.js.map +1 -1
  96. package/dist/ssr/layout/FloatingWindow.js +286 -73
  97. package/dist/ssr/layout/FloatingWindow.js.map +1 -1
  98. package/dist/ssr/layout/PanelDialog.js +1 -0
  99. package/dist/ssr/layout/PanelDialog.js.map +1 -1
  100. package/dist/ssr/layout/PersonPopover.js +248 -0
  101. package/dist/ssr/layout/PersonPopover.js.map +1 -0
  102. package/dist/ssr/layout/floating-window-geometry.js +58 -2
  103. package/dist/ssr/layout/floating-window-geometry.js.map +1 -1
  104. package/dist/ssr/layout/floating-window-messages.js +12 -0
  105. package/dist/ssr/layout/floating-window-messages.js.map +1 -1
  106. package/dist/ssr/layout/index.js +1 -0
  107. package/dist/ssr/layout/index.js.map +1 -1
  108. package/dist/styles.css +1 -1
  109. package/dist/types/actions/SplitButton.d.ts +2 -0
  110. package/dist/types/actions/Toolbar.d.ts +6 -0
  111. package/dist/types/chat/ChatComposer.d.ts +1 -0
  112. package/dist/types/content/Lightbox.d.ts +54 -14
  113. package/dist/types/content/PdfPages.d.ts +7 -1
  114. package/dist/types/content/PdfThumbnails.d.ts +26 -0
  115. package/dist/types/content/PdfViewer.d.ts +12 -3
  116. package/dist/types/content/index.d.ts +4 -2
  117. package/dist/types/content/lightbox-messages.d.ts +31 -8
  118. package/dist/types/content/lightbox-renderers.d.ts +3 -0
  119. package/dist/types/content/pdf-messages.d.ts +7 -0
  120. package/dist/types/internal/truncated-title.d.ts +7 -0
  121. package/dist/types/layout/FloatingWindow.d.ts +29 -1
  122. package/dist/types/layout/PersonPopover.d.ts +70 -0
  123. package/dist/types/layout/floating-window-geometry.d.ts +20 -3
  124. package/dist/types/layout/floating-window-messages.d.ts +6 -0
  125. package/dist/types/layout/index.d.ts +3 -2
  126. package/package.json +20 -20
@@ -1,227 +1,736 @@
1
1
  import { memo as _$memo } from "solid-js/web";
2
- import { createComponent as _$createComponent } from "solid-js/web";
3
2
  import { ssr as _$ssr } from "solid-js/web";
3
+ import { ssrStyleProperty as _$ssrStyleProperty } from "solid-js/web";
4
+ import { createComponent as _$createComponent } from "solid-js/web";
5
+ import { ssrStyle as _$ssrStyle } from "solid-js/web";
4
6
  import { ssrAttribute as _$ssrAttribute } from "solid-js/web";
5
7
  import { escape as _$escape } from "solid-js/web";
6
- var _tmpl$ = ["<span class=\"k2b-content-lightbox__counter k2b-overlay-surface\" aria-live=\"polite\">", " / ", "</span>"],
7
- _tmpl$2 = ["<div class=\"k2b-content-lightbox__caption k2b-overlay-surface\"><div class=\"k2b-content-lightbox__caption-text\">", "</div></div>"],
8
- _tmpl$3 = ["<a", " download class=\"k2b-content-lightbox__button k2b-overlay-surface\"", "><i class=\"ti ti-download\" aria-hidden=\"true\"></i><span class=\"k2b-content-lightbox__button-label\">", "</span></a>"],
9
- _tmpl$4 = ["<button type=\"button\" class=\"k2b-content-lightbox__nav k2b-overlay-surface\" data-direction=\"previous\"", "><i class=\"ti ti-chevron-left\" aria-hidden=\"true\"></i></button>"],
10
- _tmpl$5 = ["<button type=\"button\" class=\"k2b-content-lightbox__nav k2b-overlay-surface\" data-direction=\"next\"", "><i class=\"ti ti-chevron-right\" aria-hidden=\"true\"></i></button>"],
11
- _tmpl$6 = ["<div class=\"k2b-content-lightbox__dots k2b-overlay-surface\" role=\"group\"", ">", "</div>"],
12
- _tmpl$7 = ["<dialog class=\"k2b-content-lightbox\"", "><div class=\"k2b-content-lightbox__bar\"><div class=\"k2b-content-lightbox__meta\">", "", "</div><div class=\"k2b-content-lightbox__actions\">", "", "<button type=\"button\" class=\"k2b-content-lightbox__button k2b-overlay-surface\"", "><i class=\"ti ti-x\" aria-hidden=\"true\"></i><span class=\"k2b-content-lightbox__button-label\">", "</span></button></div></div><div class=\"k2b-content-lightbox__stage\">", "</div>", "", "", "</dialog>"],
13
- _tmpl$8 = ["<button type=\"button\" class=\"k2b-content-lightbox__button k2b-overlay-surface\"", "><i", " aria-hidden=\"true\"></i><span class=\"k2b-content-lightbox__button-label\">", "</span></button>"],
14
- _tmpl$9 = ["<img", " class=\"k2b-content-lightbox__image\" draggable=\"false\">"],
15
- _tmpl$0 = ["<button type=\"button\" class=\"k2b-content-lightbox__dot\"", "></button>"];
16
- import { createEffect, createSignal, For, onCleanup, onMount, Show } from "solid-js";
8
+ var _tmpl$ = ["<button type=\"button\" class=\"k2b-lightbox__edge k2b-overlay-surface\" data-direction=\"previous\"", " title=\"", "\" style=\"", "\"><i class=\"ti ti-chevron-left\" aria-hidden=\"true\"></i></button>"],
9
+ _tmpl$2 = ["<button type=\"button\" class=\"k2b-lightbox__edge k2b-overlay-surface\" data-direction=\"next\"", " title=\"", "\" style=\"", "\"><i class=\"ti ti-chevron-right\" aria-hidden=\"true\"></i></button>"],
10
+ _tmpl$3 = ["<span>", "</span>"],
11
+ _tmpl$4 = "<i class=\"ti ti-x\" aria-hidden=\"true\"></i>",
12
+ _tmpl$5 = ["<span aria-live=\"polite\">", "</span>"],
13
+ _tmpl$6 = ["<dialog class=\"k2b-lightbox\"", " style=\"", "\"><div class=\"k2b-lightbox__main\"><div class=\"k2b-lightbox__stage\" tabindex=\"-1\"", ">", "</div>", "</div><div class=\"k2b-lightbox__head\"><p class=\"k2b-lightbox__name k2b-overlay-surface\"><b>", "</b>", "</p><div class=\"k2b-lightbox__actions k2b-overlay-surface\" role=\"group\"", ">", "", "", "", "", "<span class=\"k2b-lightbox__separator\" aria-hidden=\"true\"></span>", "</div></div><div class=\"k2b-lightbox__bar\" style=\"", "\">", "</div>", "</dialog>"],
14
+ _tmpl$7 = "<i class=\"ti ti-external-link\" aria-hidden=\"true\"></i>",
15
+ _tmpl$8 = ["<i", " aria-hidden=\"true\"></i>"],
16
+ _tmpl$9 = ["<span class=\"k2b-lightbox__action-label\">", "</span>"],
17
+ _tmpl$0 = "<i class=\"ti ti-download\" aria-hidden=\"true\"></i>",
18
+ _tmpl$1 = "<i class=\"ti ti-refresh\" aria-hidden=\"true\"></i>",
19
+ _tmpl$10 = ["<div class=\"k2b-lightbox__notice\" role=\"alert\"><i class=\"ti ti-file-alert k2b-lightbox__notice-icon\" aria-hidden=\"true\"></i><b>", "</b><span>", "</span><div class=\"k2b-lightbox__notice-actions\">", "", "", "</div></div>"],
20
+ _tmpl$11 = ["<span class=\"k2b-lightbox__converting\">", "</span>"],
21
+ _tmpl$12 = ["<div class=\"k2b-lightbox__placeholder k2b-skeleton\"", " role=\"status\"", ">", "</div>"],
22
+ _tmpl$13 = ["<article class=\"k2b-lightbox__text\" style=\"", "\">", "</article>"],
23
+ _tmpl$14 = ["<div class=\"k2b-lightbox__notice-actions\">", "</div>"],
24
+ _tmpl$15 = ["<div class=\"k2b-lightbox__notice\">", "<b>", "</b><span>", "</span>", "</div>"],
25
+ _tmpl$16 = ["<div class=\"k2b-lightbox__content\"", ">", "", "", "</div>"],
26
+ _tmpl$17 = ["<div class=\"k2b-lightbox__video\">", "</div>"],
27
+ _tmpl$18 = ["<div class=\"k2b-lightbox__audio\">", "<audio", " controls preload=\"metadata\"></audio></div>"],
28
+ _tmpl$19 = ["<img class=\"k2b-lightbox__image\"", " draggable=\"false\"", " style=\"", "\">"];
29
+ import { createEffect, createSignal, For, lazy, Match, on, onCleanup, onMount, Show, Switch, untrack } from "solid-js";
30
+ import { Button, ButtonLink, IconButton, IconButtonLink } from "../actions/Button";
31
+ import { Toolbar } from "../actions/Toolbar";
17
32
  import { returnFocus, ringOnReturn } from "../internal/focus-return";
18
- import { useUiMessages } from "../intl/messages";
33
+ import { showTruncatedTitle } from "../internal/truncated-title";
34
+ import { createDelayedLoading } from "../surfaces/Skeleton";
35
+ import { FileTypeIcon } from "./FileTypeIcon";
36
+ import { getFileViewPreviewKind } from "./file-view-preview";
19
37
  import { useLightboxMessages } from "./lightbox-messages";
20
38
  import { ThumbnailStrip } from "./ThumbnailStrip";
21
39
 
22
- /** One more thing to do with the shown image, beside Download: a short label, its icon class, and what it does. */
40
+ /*
41
+ * The renderers load when a file needs them, so a page that offers the Lightbox carries only its frame: a gallery of
42
+ * pictures never loads the document, PDF and video code, and an app's first script stays within its budget.
43
+ */
44
+ const renderers = () => import("./lightbox-renderers");
45
+ const FileView = lazy(() => renderers().then(module => ({
46
+ default: module.FileView
47
+ })));
48
+ const PdfViewer = lazy(() => renderers().then(module => ({
49
+ default: module.PdfViewer
50
+ })));
51
+ const VideoPlayer = lazy(() => renderers().then(module => ({
52
+ default: module.VideoPlayer
53
+ })));
54
+
55
+ /** One more command for the shown file, in the action pill before Download: a short label, its icon, and what it does. */
56
+
57
+ /**
58
+ * One file the Lightbox can show. Give what the file has: `src` for an image, video, audio file or PDF the browser
59
+ * reads from an address; `load` for text, Markdown, code or PDF bytes; `preview` for a document that only exists as
60
+ * a preview PDF, such as an Office file. `file` names the type when the name alone does not.
61
+ */
62
+
63
+ const ZOOM_STEPS = [0.5, 0.75, 1, 1.25, 1.5, 2, 3];
64
+ const SWIPE = 60;
65
+ const PULL_CLOSE = 110;
66
+ /** Seconds the arrows seek in a video or audio file, as `VideoPlayer`'s own keys do. */
67
+ const MEDIA_SEEK = 5;
68
+ const SPREADSHEET = /\.(xlsx?|ods|csv)$/i;
69
+ const kindOf = item => {
70
+ if (item.preview) return "office";
71
+ const kind = getFileViewPreviewKind(item.file ?? {
72
+ path: item.name
73
+ });
74
+ if (kind === "image" || kind === "video" || kind === "audio") return item.src ? kind : "none";
75
+ if (kind === "pdf") return item.src || item.load ? "pdf" : "none";
76
+ if (kind && item.load) return "text";
77
+ return "none";
78
+ };
79
+ const zoomable = kind => kind === "image" || kind === "pdf" || kind === "office" || kind === "text";
80
+ /** Keys inside these keep their own meaning. */
81
+ const interactive = target => target instanceof Element && Boolean(target.closest("button, a[href], input, textarea, select, video, audio, [contenteditable=''], [contenteditable=true]"));
82
+ /** A focused video or audio file keeps its keys: the arrows seek there instead of stepping to the next file. */
83
+ const media = target => target instanceof Element && Boolean(target.closest("video, audio"));
84
+ const bytes = content => content.encoding === "base64" ? new Blob([Uint8Array.from(atob(content.content), character => character.charCodeAt(0))], {
85
+ type: "application/pdf"
86
+ }) : new Blob([content.content], {
87
+ type: "application/pdf"
88
+ });
23
89
 
24
- /** From this many images the gallery shows a thumbnail strip instead of dots. */
25
- const STRIP_FROM = 4;
26
90
  /**
27
- * Minimal, accessible lightbox using native <dialog>.
28
- * Supports keyboard navigation, touch swipe gestures, and screen readers.
91
+ * The one large view of a file anywhere in Cloud: an image, PDF, video, audio file, text, Markdown, code, or a document
92
+ * shown through its preview PDF, and for anything else its icon, facts and Download. It loads the file itself and
93
+ * shows every state: a placeholder after a short wait, a failure with "Try again", and "Preview not possible".
94
+ *
95
+ * The name sits in a pill at the top left; Open (when the caller gives a target), the caller's commands, Download
96
+ * and Close in a pill at the top right. Large round buttons at the screen edges step between files, as do ← and →
97
+ * and the film strip from two files on; there is no "2 / 8" counter. The only pill at the bottom holds zoom and the
98
+ * page. Escape, Close, a press beside the file or a swipe down close it, and focus returns to the opener. On a phone
99
+ * it fills the screen and a swipe steps between files.
29
100
  */
30
101
  export default function Lightbox(props) {
31
- const messages = useUiMessages();
32
- const lightboxMessages = useLightboxMessages();
33
- const clampIndex = (value, images = props.images) => images.length === 0 ? 0 : Math.max(0, Math.min(value, images.length - 1));
34
- const [index, setIndex] = createSignal(clampIndex(props.initialIndex ?? 0));
35
- let dialogRef;
102
+ const t = useLightboxMessages();
103
+ const [zoom, setZoom] = createSignal(1);
104
+ const [pages, setPages] = createSignal(0);
105
+ const [page, setPage] = createSignal(0);
106
+ const [title, setTitle] = createSignal(null);
107
+ const [pull, setPull] = createSignal(0);
108
+ let dialog;
109
+ let stage;
36
110
  let opener = null;
37
111
  let openerRing = true;
38
- createEffect(previous => {
39
- const images = props.images;
40
- const initialIndex = props.initialIndex;
41
- setIndex(currentIndex => {
42
- if (initialIndex !== previous.initialIndex) return clampIndex(initialIndex ?? 0, images);
43
- const previousImage = previous.images[currentIndex];
44
- const retained = previousImage ? images.findIndex(image => image === previousImage || image.src === previousImage.src) : -1;
45
- return retained >= 0 ? retained : clampIndex(currentIndex, images);
46
- });
47
- return {
48
- images,
49
- initialIndex
50
- };
51
- }, {
52
- images: props.images,
53
- initialIndex: props.initialIndex
54
- });
55
-
56
- // Touch gesture tracking
57
- let touchStartX = 0;
58
- let touchStartY = 0;
59
- const SWIPE_THRESHOLD = 50;
60
- const current = () => props.images[index()];
61
- const isMultiple = () => props.images.length > 1;
62
- const prev = () => {
63
- if (!isMultiple()) return;
64
- setIndex(i => (i - 1 + props.images.length) % props.images.length);
112
+ const index = () => Math.max(0, Math.min(props.index, props.items.length - 1));
113
+ const item = () => props.items[index()];
114
+ const kind = () => item() ? kindOf(item()) : "none";
115
+ /** The shown video or audio element, once the file plays on the stage. */
116
+ const playing = () => kind() === "video" || kind() === "audio" ? stage?.querySelector("video, audio") ?? null : null;
117
+ createEffect(on(item, () => {
118
+ setZoom(1);
119
+ setPages(0);
120
+ setPage(0);
121
+ setTitle(null);
122
+ }));
123
+ const step = direction => {
124
+ const next = index() + direction;
125
+ if (next >= 0 && next < props.items.length) props.onIndexChange(next);
65
126
  };
66
- const next = () => {
67
- if (!isMultiple()) return;
68
- setIndex(i => (i + 1) % props.images.length);
127
+ const zoomBy = direction => {
128
+ if (!zoomable(kind())) return;
129
+ const value = zoom();
130
+ const next = direction > 0 ? ZOOM_STEPS.find(candidate => candidate > value + 0.001) : [...ZOOM_STEPS].reverse().find(candidate => candidate < value - 0.001);
131
+ if (next !== undefined) setZoom(next);
69
132
  };
70
133
  const close = () => {
71
- dialogRef.close();
134
+ if (dialog.open) dialog.close();
72
135
  returnFocus(opener, openerRing);
73
136
  props.onClose();
74
137
  };
75
138
 
76
- // A key belongs to the Lightbox while focus is inside it, or on the page with no other dialog open. A dialog opened
77
- // from one of its actions keeps its own keys: Escape closes that dialog, and arrows stay in its fields.
78
- const ownsKey = target => target instanceof Node && (dialogRef.contains(target) || target === document.body && Array.from(document.querySelectorAll("dialog[open]")).every(dialog => dialog === dialogRef));
79
-
80
- // Keyboard navigation
81
- const handleKeyDown = e => {
82
- // A part that handled the key itself, such as the thumbnail strip moving its focus, keeps it.
83
- if (e.defaultPrevented || !ownsKey(e.target)) return;
84
- switch (e.key) {
85
- case "Escape":
86
- // Handled here, so WebKit does not light the returned focus for this key.
87
- e.preventDefault();
88
- close();
89
- break;
90
- case "ArrowLeft":
91
- prev();
92
- break;
93
- case "ArrowRight":
94
- next();
95
- break;
96
- }
139
+ // A key belongs to the Lightbox while focus is inside it, or on the page with no other dialog open above it.
140
+ const ownsKey = target => target instanceof Node && (dialog.contains(target) || target === document.body && Array.from(document.querySelectorAll("dialog[open]")).every(open => open === dialog));
141
+ const keys = event => {
142
+ if (event.defaultPrevented || event.altKey || event.ctrlKey || event.metaKey || !ownsKey(event.target)) return;
143
+ const handled = (() => {
144
+ switch (event.key) {
145
+ case "Escape":
146
+ close();
147
+ return true;
148
+ case " ":
149
+ {
150
+ if (interactive(event.target)) return false;
151
+ // Space plays and pauses a video or audio file; elsewhere it closes, as it opened the Lightbox in a list.
152
+ const shown = playing();
153
+ if (!shown) {
154
+ close();
155
+ return true;
156
+ }
157
+ if (shown.paused) void shown.play().catch(() => {});else shown.pause();
158
+ return true;
159
+ }
160
+ case "ArrowLeft":
161
+ case "ArrowRight":
162
+ {
163
+ if (media(event.target)) return false;
164
+ const direction = event.key === "ArrowRight" ? 1 : -1;
165
+ // A video or audio file keeps the arrows wherever the focus is, in every engine: they seek in it, as its own
166
+ // controls do. The edge buttons and the film strip still step to the next file.
167
+ const shown = playing();
168
+ if (shown) {
169
+ const end = Number.isFinite(shown.duration) ? shown.duration : shown.currentTime + MEDIA_SEEK;
170
+ shown.currentTime = Math.min(end, Math.max(0, shown.currentTime + direction * MEDIA_SEEK));
171
+ return true;
172
+ }
173
+ step(direction);
174
+ return true;
175
+ }
176
+ case "+":
177
+ case "=":
178
+ zoomBy(1);
179
+ return true;
180
+ case "-":
181
+ zoomBy(-1);
182
+ return true;
183
+ case "0":
184
+ setZoom(1);
185
+ return true;
186
+ default:
187
+ return false;
188
+ }
189
+ })();
190
+ if (handled) event.preventDefault();
97
191
  };
98
192
 
99
- // Touch handlers for swipe gestures
100
- const handleTouchStart = e => {
101
- const touch = e.touches[0];
102
- if (touch) {
103
- touchStartX = touch.clientX;
104
- touchStartY = touch.clientY;
105
- }
193
+ // Touch: a sideways swipe steps, a pull down closes. A zoomed picture keeps its own drag.
194
+ let touch = null;
195
+ const touchStart = event => {
196
+ const first = event.touches.length === 1 ? event.touches[0] : undefined;
197
+ touch = first && zoom() === 1 ? {
198
+ x: first.clientX,
199
+ y: first.clientY
200
+ } : null;
106
201
  };
107
- const handleTouchEnd = e => {
108
- const touch = e.changedTouches[0];
109
- if (!touch) return;
110
- const deltaX = touch.clientX - touchStartX;
111
- const deltaY = touch.clientY - touchStartY;
112
-
113
- // Only trigger swipe if horizontal movement is dominant
114
- if (Math.abs(deltaX) > Math.abs(deltaY) && Math.abs(deltaX) > SWIPE_THRESHOLD) {
115
- if (deltaX > 0) {
116
- prev();
117
- } else {
118
- next();
119
- }
120
- }
202
+ const touchMove = event => {
203
+ const first = event.touches[0];
204
+ if (!touch || !first) return;
205
+ const dy = first.clientY - touch.y;
206
+ setPull(dy > 0 && dy > Math.abs(first.clientX - touch.x) && stage.scrollTop <= 0 ? dy : 0);
121
207
  };
122
-
123
- // Click on backdrop closes lightbox
124
- const handleBackdropClick = e => {
125
- if (e.target === dialogRef) {
126
- close();
127
- }
208
+ const touchEnd = event => {
209
+ const last = event.changedTouches[0];
210
+ const start = touch;
211
+ touch = null;
212
+ const pulled = pull();
213
+ setPull(0);
214
+ if (!start || !last) return;
215
+ if (pulled > PULL_CLOSE) return close();
216
+ const dx = last.clientX - start.x;
217
+ if (Math.abs(dx) > SWIPE && Math.abs(dx) > Math.abs(last.clientY - start.y)) step(dx < 0 ? 1 : -1);
128
218
  };
129
-
130
- // The browser cancels the dialog itself, as on the Android back gesture;
131
- // closing here still returns focus and tells the owner.
132
- const handleCancel = e => {
133
- e.preventDefault();
134
- close();
219
+ // A press on the stage beside the file closes, like a press beside a dialog.
220
+ const stagePress = event => {
221
+ if (event.target === stage || event.target === dialog) close();
135
222
  };
136
223
 
137
- // Registration and teardown both live in onMount: onCleanup also runs when an
138
- // SSR render is disposed, where `document` does not exist.
224
+ // Registration and teardown both live in onMount: onCleanup also runs when an SSR render is disposed.
139
225
  onMount(() => {
140
226
  opener = document.activeElement instanceof HTMLElement ? document.activeElement : null;
141
227
  openerRing = ringOnReturn(opener);
142
- // The native dialog would return focus with a ring of the browser's choosing.
143
228
  opener?.blur();
144
- dialogRef.showModal();
145
- document.addEventListener("keydown", handleKeyDown);
146
- onCleanup(() => document.removeEventListener("keydown", handleKeyDown));
229
+ dialog.showModal();
230
+ // The file has the focus, not the first command: the keys step and zoom at once, and no ring lands on Open.
231
+ stage.focus({
232
+ preventScroll: true
233
+ });
234
+ document.addEventListener("keydown", keys);
235
+ onCleanup(() => document.removeEventListener("keydown", keys));
236
+ });
237
+ const shownName = () => title() ?? item()?.name ?? "";
238
+ const meta = () => {
239
+ const current = item();
240
+ if (!current) return "";
241
+ const facts = title() ? [current.name, current.meta] : [current.meta];
242
+ if (kind() === "office") facts.push(t().viewOnly);
243
+ return facts.filter(Boolean).join(" · ");
244
+ };
245
+ const pageLabel = () => SPREADSHEET.test(item()?.name ?? "") ? t().sheet({
246
+ number: page() + 1,
247
+ total: pages()
248
+ }) : t().page({
249
+ number: page() + 1,
250
+ total: pages()
147
251
  });
148
- return _$ssr(_tmpl$7, _$ssrAttribute("aria-label", _$escape(lightboxMessages().imageLightbox, true), false), _$escape(_$createComponent(Show, {
252
+ return _$ssr(_tmpl$6, _$ssrAttribute("aria-label", _$escape(shownName(), true), false) + _$ssrAttribute("data-kind", _$escape(kind(), true), false), _$ssrStyle(pull() ? {
253
+ "--k2b-lightbox-pull": String(Math.min(1, pull() / (PULL_CLOSE * 2)))
254
+ } : undefined), _$ssrAttribute("data-zoomed", zoom() !== 1 ? "" : _$escape(undefined, true), false), _$escape(_$createComponent(Show, {
255
+ keyed: true,
256
+ get when() {
257
+ return item();
258
+ },
259
+ children: shown => _$createComponent(LightboxStage, {
260
+ item: shown,
261
+ get kind() {
262
+ return untrack(kind);
263
+ },
264
+ zoom: zoom,
265
+ onPages: setPages,
266
+ onPage: setPage,
267
+ onTitle: setTitle
268
+ })
269
+ })), _$escape(_$createComponent(Show, {
149
270
  get when() {
150
- return isMultiple();
271
+ return props.items.length > 1;
151
272
  },
152
273
  get children() {
153
- return _$ssr(_tmpl$, _$escape(index()) + 1, _$escape(props.images.length));
274
+ return [_$ssr(_tmpl$, _$ssrAttribute("aria-label", _$escape(t().previous, true), false), `${_$escape(t().previous, true)} (←)`, _$ssrStyleProperty("visibility:", index() > 0 ? "visible" : "hidden")), _$ssr(_tmpl$2, _$ssrAttribute("aria-label", _$escape(t().next, true), false), `${_$escape(t().next, true)} (→)`, _$ssrStyleProperty("visibility:", index() < props.items.length - 1 ? "visible" : "hidden"))];
154
275
  }
155
- })), _$escape(_$createComponent(Show, {
276
+ })), _$escape(shownName()), _$escape(_$createComponent(Show, {
156
277
  get when() {
157
- return current()?.alt;
278
+ return meta();
158
279
  },
159
280
  get children() {
160
- return _$ssr(_tmpl$2, _$escape(current()?.alt));
281
+ return _$ssr(_tmpl$3, _$escape(meta()));
161
282
  }
162
- })), _$escape(_$createComponent(For, {
163
- get each() {
164
- return current()?.actions ?? [];
283
+ })), _$ssrAttribute("aria-label", _$escape(t().actions, true), false), _$escape(_$createComponent(Show, {
284
+ get when() {
285
+ return item()?.open;
165
286
  },
166
- children: action => _$ssr(_tmpl$8, _$ssrAttribute("aria-label", _$escape(action.label, true), false), _$ssrAttribute("class", _$escape(action.icon, true), false), _$escape(action.label))
287
+ children: open => _$createComponent(Button, {
288
+ size: "sm",
289
+ "class": "k2b-lightbox__open",
290
+ onClick: () => open().onOpen(),
291
+ get children() {
292
+ return [_$ssr(_tmpl$7), open().label ?? t().open];
293
+ }
294
+ })
167
295
  })), _$escape(_$createComponent(Show, {
168
296
  get when() {
169
- return current()?.downloadUrl;
297
+ return item();
170
298
  },
171
- get children() {
172
- return _$ssr(_tmpl$3, _$ssrAttribute("href", _$escape(current().downloadUrl, true), false), _$ssrAttribute("aria-label", _$escape(lightboxMessages().downloadImage, true), false), _$escape(messages().download));
173
- }
174
- })), _$ssrAttribute("aria-label", _$escape(lightboxMessages().closeLightbox, true), false), _$escape(messages().close), _$escape(_$createComponent(Show, {
299
+ children: shown => props.actions?.(shown())
300
+ })), _$escape(_$createComponent(For, {
301
+ get each() {
302
+ return item()?.actions ?? [];
303
+ },
304
+ children: action => _$createComponent(Button, {
305
+ size: "sm",
306
+ variant: "ghost",
307
+ "class": "k2b-lightbox__action",
308
+ get ["aria-label"]() {
309
+ return action.label;
310
+ },
311
+ get onClick() {
312
+ return action.onClick;
313
+ },
314
+ get children() {
315
+ return [_$ssr(_tmpl$8, _$ssrAttribute("class", _$escape(action.icon, true), false)), _$ssr(_tmpl$9, _$escape(action.label))];
316
+ }
317
+ })
318
+ })), _$escape(_$createComponent(Show, {
175
319
  get when() {
176
- return current();
320
+ return item()?.downloadUrl;
177
321
  },
178
- children: image => _$ssr(_tmpl$9, _$ssrAttribute("src", _$escape(image().src, true), false) + _$ssrAttribute("alt", _$escape(image().alt ?? "", true), false))
322
+ children: href => _$createComponent(IconButtonLink, {
323
+ variant: "ghost",
324
+ get label() {
325
+ return t().download;
326
+ },
327
+ get href() {
328
+ return href();
329
+ },
330
+ download: "",
331
+ navigation: "document",
332
+ get children() {
333
+ return _$ssr(_tmpl$0);
334
+ }
335
+ })
179
336
  })), _$escape(_$createComponent(Show, {
180
337
  get when() {
181
- return isMultiple();
338
+ return _$memo(() => !!!item()?.downloadUrl)() && item()?.onDownload;
339
+ },
340
+ children: download => _$createComponent(IconButton, {
341
+ variant: "ghost",
342
+ get label() {
343
+ return t().download;
344
+ },
345
+ onClick: () => download()(),
346
+ get children() {
347
+ return _$ssr(_tmpl$0);
348
+ }
349
+ })
350
+ })), _$escape(_$createComponent(IconButton, {
351
+ variant: "ghost",
352
+ get label() {
353
+ return t().close;
354
+ },
355
+ get tooltip() {
356
+ return t().closeHint;
357
+ },
358
+ onClick: close,
359
+ get children() {
360
+ return _$ssr(_tmpl$4);
361
+ }
362
+ })), _$ssrStyleProperty("visibility:", zoomable(kind()) || pages() > 1 ? "visible" : "hidden"), _$escape(_$createComponent(Toolbar, {
363
+ get label() {
364
+ return t().view;
182
365
  },
366
+ "class": "k2b-lightbox__tools k2b-overlay-surface",
183
367
  get children() {
184
- return [_$ssr(_tmpl$4, _$ssrAttribute("aria-label", _$escape(lightboxMessages().previousImage, true), false)), _$ssr(_tmpl$5, _$ssrAttribute("aria-label", _$escape(lightboxMessages().nextImage, true), false))];
368
+ return [_$createComponent(Toolbar.Action, {
369
+ get label() {
370
+ return t().zoomOut;
371
+ },
372
+ icon: "ti ti-minus",
373
+ get disabled() {
374
+ return !zoomable(kind()) || zoom() <= ZOOM_STEPS[0];
375
+ },
376
+ onClick: () => zoomBy(-1)
377
+ }), _$createComponent(Toolbar.Label, {
378
+ "class": "k2b-lightbox__percent",
379
+ get children() {
380
+ return _$ssr(_tmpl$5, zoomable(kind()) ? _$escape(t().percent({
381
+ value: Math.round(zoom() * 100)
382
+ })) : "");
383
+ }
384
+ }), _$createComponent(Toolbar.Action, {
385
+ get label() {
386
+ return t().zoomIn;
387
+ },
388
+ icon: "ti ti-plus",
389
+ get disabled() {
390
+ return !zoomable(kind()) || zoom() >= ZOOM_STEPS[ZOOM_STEPS.length - 1];
391
+ },
392
+ onClick: () => zoomBy(1)
393
+ }), _$createComponent(Show, {
394
+ get when() {
395
+ return pages() > 1;
396
+ },
397
+ get children() {
398
+ return [_$createComponent(Toolbar.Separator, {}), _$createComponent(Toolbar.Label, {
399
+ "class": "k2b-lightbox__page",
400
+ get children() {
401
+ return pageLabel();
402
+ }
403
+ })];
404
+ }
405
+ })];
185
406
  }
186
407
  })), _$escape(_$createComponent(Show, {
187
408
  get when() {
188
- return props.images.length >= STRIP_FROM;
409
+ return props.items.length > 1;
189
410
  },
190
411
  get children() {
191
412
  return _$createComponent(ThumbnailStrip, {
192
- "class": "k2b-content-lightbox__strip k2b-overlay-surface",
413
+ "class": "k2b-lightbox__strip",
193
414
  get label() {
194
- return lightboxMessages().imageNavigation;
415
+ return t().files;
195
416
  },
196
417
  get items() {
197
- return props.images.map((image, i) => ({
198
- id: String(i),
199
- name: image.alt || lightboxMessages().goToImage({
200
- index: i + 1
201
- }),
202
- thumbnail: image.thumbnail ?? image.src
418
+ return props.items.map((entry, position) => ({
419
+ id: String(position),
420
+ name: entry.name,
421
+ thumbnail: entry.thumbnail ?? (() => _$createComponent(FileTypeIcon, {
422
+ get name() {
423
+ return entry.file?.path ?? entry.name;
424
+ }
425
+ }))
203
426
  }));
204
427
  },
205
428
  get currentItem() {
206
429
  return String(index());
207
430
  },
208
- onSelectItem: id => setIndex(Number(id))
431
+ onSelectItem: id => props.onIndexChange(Number(id))
432
+ });
433
+ }
434
+ })));
435
+ }
436
+
437
+ /** One file on the stage: it loads, and shows a placeholder after a short wait, a failure with retry, or the file. */
438
+ function LightboxStage(props) {
439
+ const t = useLightboxMessages();
440
+ // Each attempt mounts the content anew; "Try again" starts the next one.
441
+ const [attempt, setAttempt] = createSignal(0);
442
+ const [state, setState] = createSignal(props.kind === "none" ? "ready" : "loading");
443
+ const placeholder = createDelayedLoading(() => state() === "loading");
444
+ const [document_, setDocument] = createSignal(null);
445
+ // The address the browser reads; a resolver runs once per attempt, so a retry asks for a fresh signed address.
446
+ const [source, setSource] = createSignal(null);
447
+ const failed = () => setState("failed");
448
+ const ready = () => setState("ready");
449
+ /*
450
+ * A video or audio file takes the focus once its player is there, which can be a moment after the frame when the
451
+ * player's code still loads; so its own keys and the screen reader start on it in every engine. The focus moves only
452
+ * while it still rests on the stage or the page, never away from a control the person chose meanwhile.
453
+ */
454
+ const focusMediaWhenShown = host => {
455
+ const take = () => {
456
+ const shown = host.querySelector("video, audio");
457
+ if (!shown || !shown.isConnected) return false;
458
+ const active = document.activeElement;
459
+ const stage = host.closest(".k2b-lightbox__stage");
460
+ if (!active || active === document.body || active === stage || host.contains(active)) shown.focus({
461
+ preventScroll: true
462
+ });
463
+ return true;
464
+ };
465
+ // The host is not in the page yet while its ref runs; the first look waits for the mount.
466
+ const watch = new MutationObserver(() => {
467
+ if (take()) watch.disconnect();
468
+ });
469
+ watch.observe(host, {
470
+ childList: true,
471
+ subtree: true
472
+ });
473
+ onCleanup(() => watch.disconnect());
474
+ const look = () => {
475
+ if (take()) watch.disconnect();
476
+ };
477
+ queueMicrotask(look);
478
+ requestAnimationFrame(look);
479
+ };
480
+ const downloadable = () => Boolean(props.item.downloadUrl || props.item.onDownload);
481
+ const download = variant => _$createComponent(Show, {
482
+ get when() {
483
+ return props.item.downloadUrl;
484
+ },
485
+ get fallback() {
486
+ return _$createComponent(Show, {
487
+ get when() {
488
+ return props.item.onDownload;
489
+ },
490
+ children: run => _$createComponent(Button, {
491
+ size: "sm",
492
+ variant: variant,
493
+ onClick: () => run()(),
494
+ get children() {
495
+ return [_$ssr(_tmpl$0), t().download];
496
+ }
497
+ })
209
498
  });
499
+ },
500
+ children: href => _$createComponent(ButtonLink, {
501
+ size: "sm",
502
+ variant: variant,
503
+ get href() {
504
+ return href();
505
+ },
506
+ download: "",
507
+ navigation: "document",
508
+ get children() {
509
+ return [_$ssr(_tmpl$0), t().download];
510
+ }
511
+ })
512
+ });
513
+
514
+ // Each attempt owns a signal: moving on, closing, or trying again stops what the previous one still loads.
515
+ let loading;
516
+ onCleanup(() => loading?.abort());
517
+ const signal = () => loading?.signal ?? new AbortController().signal;
518
+ const settle = then => value => {
519
+ if (!signal().aborted) then(value);
520
+ };
521
+ const fail = () => {
522
+ if (!signal().aborted) failed();
523
+ };
524
+ const resolveSource = () => {
525
+ const src = props.item.src;
526
+ return typeof src === "function" ? src(signal()) : Promise.resolve(src ?? null);
527
+ };
528
+
529
+ // Addresses, PDFs from bytes and preview PDFs load here; the viewers then draw them.
530
+ createEffect(on(attempt, () => {
531
+ loading?.abort();
532
+ loading = new AbortController();
533
+ setState(props.kind === "none" ? "ready" : "loading");
534
+ setDocument(null);
535
+ setSource(null);
536
+ if (props.kind === "office" && props.item.preview) props.item.preview(signal()).then(settle(setDocument), fail);else if (props.kind === "pdf" && !props.item.src) props.item.load?.(signal()).then(settle(content => setDocument(bytes(content))), fail);else if (props.item.src) resolveSource().then(settle(value => {
537
+ if (!value) return failed();
538
+ setSource(value);
539
+ if (props.kind === "pdf") setDocument(value);
540
+ // The video player shows its own loading; the frame is ready as soon as it has an address.
541
+ if (props.kind === "video") ready();
542
+ }), fail);
543
+ }));
544
+ return _$ssr(_tmpl$16, _$ssrAttribute("data-state", _$escape(state(), true), false), _$escape(_$createComponent(Show, {
545
+ get when() {
546
+ return state() === "failed";
547
+ },
548
+ get children() {
549
+ return _$ssr(_tmpl$10, props.kind === "office" ? _$escape(t().notPossible) : _$escape(t().failed), props.kind === "office" ? _$escape(t().notPossibleHint) : _$escape(t().failedHint), _$escape(_$createComponent(Show, {
550
+ get when() {
551
+ return _$memo(() => props.kind === "office")() && props.item.open;
552
+ },
553
+ children: open => _$createComponent(Button, {
554
+ size: "sm",
555
+ onClick: () => open().onOpen(),
556
+ get children() {
557
+ return open().label ?? t().open;
558
+ }
559
+ })
560
+ })), _$escape(_$createComponent(Show, {
561
+ get when() {
562
+ return props.kind !== "office";
563
+ },
564
+ get children() {
565
+ return _$createComponent(Button, {
566
+ size: "sm",
567
+ variant: "secondary",
568
+ onClick: () => setAttempt(value => value + 1),
569
+ get children() {
570
+ return [_$ssr(_tmpl$1), t().retry];
571
+ }
572
+ });
573
+ }
574
+ })), _$escape(download("secondary")));
210
575
  }
211
576
  })), _$escape(_$createComponent(Show, {
212
577
  get when() {
213
- return _$memo(() => !!isMultiple())() && props.images.length < STRIP_FROM;
578
+ return placeholder();
214
579
  },
215
580
  get children() {
216
- return _$ssr(_tmpl$6, _$ssrAttribute("aria-label", _$escape(lightboxMessages().imageNavigation, true), false), _$escape(_$createComponent(For, {
217
- get each() {
218
- return props.images;
581
+ return _$ssr(_tmpl$12, _$ssrAttribute("data-kind", _$escape(props.kind, true), false), _$ssrAttribute("aria-label", _$escape(t().loading, true), false), _$escape(_$createComponent(Show, {
582
+ get when() {
583
+ return props.kind === "office";
219
584
  },
220
- children: (_, i) => _$ssr(_tmpl$0, _$ssrAttribute("aria-current", index() === i() ? "true" : _$escape(undefined, true), false) + _$ssrAttribute("aria-label", _$escape(lightboxMessages().goToImage({
221
- index: i() + 1
222
- }), true), false))
585
+ get children() {
586
+ return _$ssr(_tmpl$11, _$escape(t().converting));
587
+ }
223
588
  })));
224
589
  }
590
+ })), _$escape(_$createComponent(Show, {
591
+ keyed: true,
592
+ get when() {
593
+ return _$memo(() => state() !== "failed")() && attempt() + 1;
594
+ },
595
+ get children() {
596
+ return _$createComponent(Switch, {
597
+ get children() {
598
+ return [_$createComponent(Match, {
599
+ get when() {
600
+ return _$memo(() => props.kind === "image")() && source();
601
+ },
602
+ children: src => _$createComponent(LightboxImage, {
603
+ get src() {
604
+ return src();
605
+ },
606
+ get name() {
607
+ return props.item.name;
608
+ },
609
+ get zoom() {
610
+ return props.zoom;
611
+ },
612
+ onReady: ready,
613
+ onError: failed
614
+ })
615
+ }), _$createComponent(Match, {
616
+ get when() {
617
+ return _$memo(() => !!(props.kind === "pdf" || props.kind === "office"))() && document_();
618
+ },
619
+ children: data => _$createComponent(PdfViewer, {
620
+ "class": "k2b-lightbox__pdf",
621
+ get data() {
622
+ return data();
623
+ },
624
+ get title() {
625
+ return props.item.name;
626
+ },
627
+ zoom: false,
628
+ fit: "page",
629
+ get scale() {
630
+ return props.zoom();
631
+ },
632
+ onReady: drawn => {
633
+ props.onPages(drawn.pages);
634
+ ready();
635
+ },
636
+ get onPage() {
637
+ return props.onPage;
638
+ },
639
+ onError: failed
640
+ })
641
+ }), _$createComponent(Match, {
642
+ get when() {
643
+ return _$memo(() => props.kind === "video")() && source();
644
+ },
645
+ children: src => // The shared player renews a short-lived address and goes on at the same time; it has the keys at once.
646
+ _$ssr(_tmpl$17, _$escape(_$createComponent(VideoPlayer, {
647
+ get src() {
648
+ return src();
649
+ },
650
+ get label() {
651
+ return props.item.name;
652
+ },
653
+ get renew() {
654
+ return typeof props.item.src === "function" ? () => resolveSource().then(value => value ?? src()) : undefined;
655
+ },
656
+ get fallbackAction() {
657
+ return download("secondary");
658
+ }
659
+ })))
660
+ }), _$createComponent(Match, {
661
+ get when() {
662
+ return _$memo(() => props.kind === "audio")() && source();
663
+ },
664
+ children: src => _$ssr(_tmpl$18, _$escape(_$createComponent(FileTypeIcon, {
665
+ get name() {
666
+ return props.item.file?.path ?? props.item.name;
667
+ },
668
+ size: "lg"
669
+ })), _$ssrAttribute("src", _$escape(src(), true), false))
670
+ }), _$createComponent(Match, {
671
+ get when() {
672
+ return props.kind === "text";
673
+ },
674
+ get children() {
675
+ return _$ssr(_tmpl$13, _$ssrStyleProperty("--k2b-lightbox-text-scale:", _$escape(String(props.zoom()), true)), _$escape(_$createComponent(FileView, {
676
+ variant: "plain",
677
+ get file() {
678
+ return props.item.file ?? {
679
+ path: props.item.name
680
+ };
681
+ },
682
+ load: () => props.item.load(signal()).then(content => {
683
+ ready();
684
+ return content;
685
+ }, error => {
686
+ failed();
687
+ throw error;
688
+ }),
689
+ get onDocumentTitle() {
690
+ return props.onTitle;
691
+ }
692
+ })));
693
+ }
694
+ }), _$createComponent(Match, {
695
+ get when() {
696
+ return props.kind === "none";
697
+ },
698
+ get children() {
699
+ return _$ssr(_tmpl$15, _$escape(_$createComponent(FileTypeIcon, {
700
+ get name() {
701
+ return props.item.file?.path ?? props.item.name;
702
+ },
703
+ size: "lg"
704
+ })), _$escape(t().noPreview), downloadable() ? _$escape(t().noPreviewHint) : _$escape(props.item.meta), _$escape(_$createComponent(Show, {
705
+ get when() {
706
+ return downloadable();
707
+ },
708
+ get children() {
709
+ return _$ssr(_tmpl$14, _$escape(download("primary")));
710
+ }
711
+ })));
712
+ }
713
+ })];
714
+ }
715
+ });
716
+ }
225
717
  })));
226
718
  }
719
+
720
+ /** A picture fitted to the stage; zoomed in, it follows the pointer while dragged. */
721
+ function LightboxImage(props) {
722
+ const [pan, setPan] = createSignal({
723
+ x: 0,
724
+ y: 0
725
+ });
726
+ const [dragging, setDragging] = createSignal(false);
727
+ createEffect(on(props.zoom, value => {
728
+ if (value <= 1) setPan({
729
+ x: 0,
730
+ y: 0
731
+ });
732
+ }));
733
+ let start = null;
734
+ return _$ssr(_tmpl$19, _$ssrAttribute("src", _$escape(props.src, true), false) + _$ssrAttribute("alt", _$escape(props.name, true), false), _$ssrAttribute("data-dragging", dragging() ? "" : _$escape(undefined, true), false), _$ssrStyleProperty("transform:", `translate(${_$escape(pan().x, true)}px, ${_$escape(pan().y, true)}px) scale(${_$escape(props.zoom(), true)})`));
735
+ }
227
736
  //# sourceMappingURL=Lightbox.js.map