@k2b/ui 0.16.0 → 0.18.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 (88) hide show
  1. package/dist/browser/chat/ChatComposer.js +261 -274
  2. package/dist/browser/chat/ChatComposer.js.map +1 -1
  3. package/dist/browser/chat/ChatPrimitives.js +9 -6
  4. package/dist/browser/chat/ChatPrimitives.js.map +1 -1
  5. package/dist/browser/content/FileView.js +62 -36
  6. package/dist/browser/content/FileView.js.map +1 -1
  7. package/dist/browser/content/MarkdownView.js +9 -3
  8. package/dist/browser/content/MarkdownView.js.map +1 -1
  9. package/dist/browser/content/VideoPlayer.js +279 -0
  10. package/dist/browser/content/VideoPlayer.js.map +1 -0
  11. package/dist/browser/content/file-view-preview.js +2 -2
  12. package/dist/browser/content/file-view-preview.js.map +1 -1
  13. package/dist/browser/content/index.js +2 -0
  14. package/dist/browser/content/index.js.map +1 -1
  15. package/dist/browser/content/markdown-links.js +178 -0
  16. package/dist/browser/content/markdown-links.js.map +1 -0
  17. package/dist/browser/inputs/FileDropTarget.js +129 -0
  18. package/dist/browser/inputs/FileDropTarget.js.map +1 -0
  19. package/dist/browser/inputs/FileInputs.js +37 -11
  20. package/dist/browser/inputs/FileInputs.js.map +1 -1
  21. package/dist/browser/inputs/file-drop.js +338 -0
  22. package/dist/browser/inputs/file-drop.js.map +1 -0
  23. package/dist/browser/inputs/index.js +1 -0
  24. package/dist/browser/inputs/index.js.map +1 -1
  25. package/dist/browser/inputs/markdown/MarkdownEditor.js +72 -78
  26. package/dist/browser/inputs/markdown/MarkdownEditor.js.map +1 -1
  27. package/dist/browser/intl/messages.js +97 -4
  28. package/dist/browser/intl/messages.js.map +1 -1
  29. package/dist/browser/layout/AppWorkspace.js +210 -44
  30. package/dist/browser/layout/AppWorkspace.js.map +1 -1
  31. package/dist/browser/layout/Navigation.js +278 -170
  32. package/dist/browser/layout/Navigation.js.map +1 -1
  33. package/dist/browser/layout/index.js.map +1 -1
  34. package/dist/browser/layout/navigation-model.js +3 -1
  35. package/dist/browser/layout/navigation-model.js.map +1 -1
  36. package/dist/browser/surfaces/NoticeCard.js +47 -44
  37. package/dist/browser/surfaces/NoticeCard.js.map +1 -1
  38. package/dist/ssr/chat/ChatComposer.js +59 -48
  39. package/dist/ssr/chat/ChatComposer.js.map +1 -1
  40. package/dist/ssr/chat/ChatPrimitives.js +9 -6
  41. package/dist/ssr/chat/ChatPrimitives.js.map +1 -1
  42. package/dist/ssr/content/FileView.js +30 -6
  43. package/dist/ssr/content/FileView.js.map +1 -1
  44. package/dist/ssr/content/MarkdownView.js +9 -3
  45. package/dist/ssr/content/MarkdownView.js.map +1 -1
  46. package/dist/ssr/content/VideoPlayer.js +208 -0
  47. package/dist/ssr/content/VideoPlayer.js.map +1 -0
  48. package/dist/ssr/content/file-view-preview.js +2 -2
  49. package/dist/ssr/content/file-view-preview.js.map +1 -1
  50. package/dist/ssr/content/index.js +2 -0
  51. package/dist/ssr/content/index.js.map +1 -1
  52. package/dist/ssr/content/markdown-links.js +178 -0
  53. package/dist/ssr/content/markdown-links.js.map +1 -0
  54. package/dist/ssr/inputs/FileDropTarget.js +103 -0
  55. package/dist/ssr/inputs/FileDropTarget.js.map +1 -0
  56. package/dist/ssr/inputs/FileInputs.js +32 -10
  57. package/dist/ssr/inputs/FileInputs.js.map +1 -1
  58. package/dist/ssr/inputs/file-drop.js +338 -0
  59. package/dist/ssr/inputs/file-drop.js.map +1 -0
  60. package/dist/ssr/inputs/index.js +1 -0
  61. package/dist/ssr/inputs/index.js.map +1 -1
  62. package/dist/ssr/inputs/markdown/MarkdownEditor.js +14 -2
  63. package/dist/ssr/inputs/markdown/MarkdownEditor.js.map +1 -1
  64. package/dist/ssr/intl/messages.js +97 -4
  65. package/dist/ssr/intl/messages.js.map +1 -1
  66. package/dist/ssr/layout/AppWorkspace.js +173 -27
  67. package/dist/ssr/layout/AppWorkspace.js.map +1 -1
  68. package/dist/ssr/layout/Navigation.js +175 -102
  69. package/dist/ssr/layout/Navigation.js.map +1 -1
  70. package/dist/ssr/layout/index.js.map +1 -1
  71. package/dist/ssr/layout/navigation-model.js +3 -1
  72. package/dist/ssr/layout/navigation-model.js.map +1 -1
  73. package/dist/ssr/surfaces/NoticeCard.js +17 -12
  74. package/dist/ssr/surfaces/NoticeCard.js.map +1 -1
  75. package/dist/styles.css +1 -1
  76. package/dist/types/chat/ChatPrimitives.d.ts +1 -1
  77. package/dist/types/content/VideoPlayer.d.ts +41 -0
  78. package/dist/types/content/index.d.ts +2 -0
  79. package/dist/types/content/markdown-links.d.ts +66 -0
  80. package/dist/types/inputs/FileDropTarget.d.ts +23 -0
  81. package/dist/types/inputs/FileInputs.d.ts +2 -0
  82. package/dist/types/inputs/file-drop.d.ts +80 -0
  83. package/dist/types/inputs/index.d.ts +2 -0
  84. package/dist/types/intl/messages.d.ts +47 -0
  85. package/dist/types/layout/AppWorkspace.d.ts +21 -0
  86. package/dist/types/layout/index.d.ts +2 -2
  87. package/dist/types/layout/navigation-model.d.ts +29 -0
  88. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["content/FileView.tsx"],"sourcesContent":["/**\n * FileView — renders one file through a small renderer registry keyed by\n * media type / path. Editing is enabled purely by the presence of `save`;\n * without it every renderer is read-only. IDE-style chrome: editors reuse\n * the markdown editor's surface (toolbar with an in-toolbar save, Ctrl/Cmd+S),\n * previews are quiet paper panels with icon-only actions overlaid top-right.\n * A plain preview drops the panel and sits on its host's surface instead.\n * Custom renderers are passed per instance, which keeps SSR requests and\n * independently mounted applications isolated.\n */\n\nimport { mutation } from \"@k2b/stdlib/solid\";\nimport {\n type Component,\n createContext,\n createEffect,\n createMemo,\n createResource,\n createSignal,\n For,\n type JSX,\n Match,\n onCleanup,\n onMount,\n Show,\n Switch,\n untrack,\n useContext,\n} from \"solid-js\";\nimport { Button } from \"../actions/Button\";\nimport { prompts } from \"../feedback/prompts\";\nimport { Tooltip } from \"../feedback/Tooltip\";\nimport { toast } from \"../feedback/toast\";\nimport { MarkdownEditor } from \"../inputs/markdown/MarkdownEditor\";\nimport { Select } from \"../inputs/Select\";\nimport { useUiMessages } from \"../intl/messages\";\nimport Placeholder from \"../surfaces/Placeholder\";\nimport CodeDisplay, { type CodeDisplayLanguage } from \"./CodeDisplay\";\nimport { type DelimitedPreferences, decodeDelimitedContent, readDelimitedPreferences } from \"./delimited-preferences\";\nimport { type FileViewFile, fileViewExtension, getFileViewPreviewKind, parseDelimitedText } from \"./file-view-preview\";\nimport MarkdownView from \"./MarkdownView\";\nimport { leadingMarkdownTitle } from \"./markdown-title\";\nimport PdfPreview from \"./PdfPreview\";\nimport StructuredDataPreview, { type StructuredDataValue } from \"./StructuredDataPreview\";\n\nexport type { FileViewFile, FileViewPreviewKind } from \"./file-view-preview\";\nexport { canPreviewFile, getFileViewPreviewKind } from \"./file-view-preview\";\nexport type FileViewContent = { encoding: \"utf8\" | \"base64\"; content: string; mediaType: string };\n\nexport type FileViewProps = {\n /**\n * Plain previews inherit the surrounding surface without a frame or inset padding. They keep their natural height,\n * so the host scrolls them and owns the actions around them; a host that stretches one gets its scrolling back.\n */\n variant?: \"default\" | \"plain\";\n /**\n * Lifts a leading Markdown level-one heading into the host, for example a dialog title. Reports its plain text and\n * leaves that heading out of the preview, or reports null when the shown file has none, the heading holds a link or\n * image or is the whole document, or the file fails to load.\n */\n onDocumentTitle?: (title: string | null) => void;\n /** Read-only excerpt limit; omitted renders the complete preview. */\n previewLines?: number;\n onExpandPreview?: () => void;\n headingScale?: \"compact\" | \"normal\" | \"large\";\n /** Optional browser-local preference scope, owned by the host. */\n previewPreferencesKey?: string;\n file: FileViewFile;\n load: () => Promise<FileViewContent>;\n /** Refetch the current path when this host-owned revision changes. */\n revision?: unknown;\n /** Register an awaitable refresh for the currently visible preview. */\n registerRefresh?: (refresh: () => Promise<void>) => void | (() => void);\n /** Presence enables editing for text-based renderers. */\n save?: (content: string) => Promise<void>;\n /** Authenticated inline URL used by browser-native image, PDF, audio, and video previews. */\n previewHref?: string | null;\n /** CORS mode for native image/audio/video previews. Omit to preserve browser defaults. */\n crossOrigin?: \"anonymous\" | \"use-credentials\";\n /** Native media failed to load; the host can renew a signed URL and offer retry. */\n onPreviewError?: () => void;\n /** Download actions only; never a preview source, because an attachment response does not render inline. */\n downloadHref?: string | null;\n /** App-specific renderers matched before the built-ins for this instance. */\n renderers?: readonly FileViewRenderer[];\n /** Reports local edit state so a parent browser can guard navigation. */\n onDirtyChange?: (dirty: boolean) => void;\n class?: string;\n};\n\nexport type FileViewRendererProps = {\n /** Read-only excerpt limit; omitted renders the complete preview. */\n previewLines?: number;\n onExpandPreview?: () => void;\n headingScale?: \"compact\" | \"normal\" | \"large\";\n /** Optional browser-local preference scope, owned by the host. */\n previewPreferencesKey?: string;\n file: FileViewFile;\n content: FileViewContent;\n previewHref: string | null;\n crossOrigin?: \"anonymous\" | \"use-credentials\";\n onPreviewError?: () => void;\n downloadHref: string | null;\n /** Null when the file is read-only. */\n editor: {\n draft: () => string;\n setDraft: (value: string) => void;\n dirty: () => boolean;\n saving: () => boolean;\n save: () => Promise<void>;\n } | null;\n};\n\nexport type FileViewRenderer = {\n id: string;\n match: (file: FileViewFile, content: FileViewContent) => boolean;\n component: Component<FileViewRendererProps>;\n /** Text renderers that support the edit affordance when `save` is present. */\n editable?: boolean;\n};\n\n/** Instance options that reach the built-in renderers without widening the public renderer props. */\nconst FileViewHost = createContext({ plain: false, liftTitle: false });\n\nconst codeLanguage = (path: string): CodeDisplayLanguage => {\n const extension = fileViewExtension(path);\n if (extension === \"ts\" || extension === \"mts\" || extension === \"cts\") return \"ts\";\n if (extension === \"tsx\") return \"tsx\";\n if (extension === \"js\" || extension === \"mjs\" || extension === \"cjs\") return \"js\";\n if (extension === \"jsx\") return \"jsx\";\n if (extension === \"md\" || extension === \"markdown\") return \"md\";\n return \"text\";\n};\n\nconst isMarkdown = (file: FileViewFile, content: FileViewContent) =>\n content.encoding === \"utf8\" && getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"markdown\";\n\n/** Rendered previews hide a leading YAML frontmatter block — it's metadata, not content. */\nconst stripFrontmatter = (text: string): string => {\n const match = /^---\\r?\\n[\\s\\S]*?\\r?\\n---\\r?\\n?/.exec(text.trimStart());\n return match ? text.trimStart().slice(match[0].length) : text;\n};\n\n/** Icon-only download link with the shared tooltip, for toolbars that style their own controls. */\nfunction DownloadLink(props: { class: string; href: string; download: string; label: string; icon: string }) {\n let link: HTMLAnchorElement | undefined;\n return (\n <>\n <a ref={link} class={props.class} href={props.href} download={props.download} aria-label={props.label}>\n <i class={props.icon} aria-hidden=\"true\" />\n <span class=\"k2b-sr-only\">{props.label}</span>\n </a>\n <Tooltip content={props.label} target={() => link} />\n </>\n );\n}\n\n/** Icon-only action, IDE style — sits in the floating top-right cluster of previews. */\nfunction OverlayAction(props: { icon: string; title: string; onClick?: () => void; href?: string; download?: string }) {\n const classes = \"k2b-content-file-view__action\";\n return (\n <Show\n when={props.href}\n fallback={\n <Tooltip.Trigger type=\"button\" class={classes} content={props.title} aria-label={props.title} onClick={props.onClick}>\n <i class={`ti ${props.icon}`} aria-hidden=\"true\" />\n </Tooltip.Trigger>\n }\n >\n {(href) => (\n <DownloadLink class={classes} href={href()} download={props.download ?? \"\"} label={props.title} icon={`ti ${props.icon}`} />\n )}\n </Show>\n );\n}\n\n/** Scrollable preview panel with the floating action cluster overlaid top-right. */\nfunction OverlayPanel(props: { actions?: JSX.Element; children: JSX.Element }) {\n return (\n <div class=\"k2b-content-file-view__panel\">\n <div class=\"k2b-content-file-view__preview\">{props.children}</div>\n <Show when={props.actions}>\n <div class=\"k2b-content-file-view__overlay\">{props.actions}</div>\n </Show>\n </div>\n );\n}\n\nconst DownloadAction = (props: FileViewRendererProps): JSX.Element => {\n const messages = useUiMessages();\n return (\n <Show when={props.downloadHref}>\n {(href) => (\n <OverlayAction\n icon=\"ti-download\"\n title={messages().download}\n href={href()}\n download={props.file.path.slice(props.file.path.lastIndexOf(\"/\") + 1)}\n />\n )}\n </Show>\n );\n};\n\n/** Toolbar-styled icon button — reuses the package markdown-editor tool primitive. */\nfunction EditorToolButton(props: { icon: string; title: string; onClick: () => void; disabled?: boolean }) {\n return (\n <Tooltip.Trigger\n type=\"button\"\n class=\"k2b-markdown-editor__tool\"\n content={props.title}\n aria-label={props.title}\n tabIndex={-1}\n disabled={props.disabled}\n onMouseDown={(e) => e.preventDefault()}\n onClick={props.onClick}\n >\n <i class={props.icon} aria-hidden=\"true\" />\n </Tooltip.Trigger>\n );\n}\n\n// ── Built-in renderers ──────────────────────────────────────────────────────\n\nfunction MoreLines(props: { count: number; onClick?: () => void }) {\n const messages = useUiMessages();\n return (\n <Show when={props.count > 0}>\n <div class=\"k2b-content-file-view__truncated\">\n <Show when={props.onClick} fallback={<span>{messages().previewMoreLines(props.count)}</span>}>\n <Button size=\"sm\" variant=\"ghost\" onClick={props.onClick}>\n {messages().previewMoreLines(props.count)}\n </Button>\n </Show>\n </div>\n </Show>\n );\n}\nfunction TextExcerpt(props: { renderer: FileViewRendererProps; text: string; markdown?: boolean }) {\n const lines = createMemo(() => props.text.replace(/\\r\\n?/g, \"\\n\").replace(/\\n$/, \"\").split(\"\\n\"));\n const limit = () => (props.renderer.previewLines === undefined ? lines().length : Math.max(1, props.renderer.previewLines));\n const text = () => lines().slice(0, limit()).join(\"\\n\");\n const host = useContext(FileViewHost);\n // A plain preview has no code box: the host frames the file and owns its copy action.\n const content = () => (\n <Show\n when={props.markdown}\n fallback={<CodeDisplay code={text()} language={codeLanguage(props.renderer.file.path)} copy={host.plain ? false : undefined} />}\n >\n <MarkdownView markdown={text()} headingScale={props.renderer.headingScale ?? \"compact\"} />\n </Show>\n );\n // Only an excerpt needs a clipping box; a complete preview keeps its content\n // a direct child of the preview frame, which the frame's styles expect.\n return (\n <>\n <Show when={props.renderer.previewLines !== undefined} fallback={content()}>\n <div class=\"k2b-content-file-view__excerpt\">{content()}</div>\n </Show>\n <MoreLines count={lines().length - limit()} onClick={props.renderer.onExpandPreview} />\n </>\n );\n}\n\nfunction MarkdownRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n const host = useContext(FileViewHost);\n const [editing, setEditing] = createSignal(false);\n const markdown = () => {\n const text = stripFrontmatter(props.editor?.draft() ?? props.content.content);\n return host.liftTitle ? (leadingMarkdownTitle(text)?.body ?? text) : text;\n };\n return (\n <Show\n when={props.editor && editing()}\n fallback={\n <OverlayPanel\n actions={\n <>\n <Show when={props.editor}>\n <OverlayAction icon=\"ti-pencil\" title={messages().edit} onClick={() => setEditing(true)} />\n </Show>\n <DownloadAction {...props} />\n </>\n }\n >\n <div class=\"k2b-content-file-view__document\">\n <TextExcerpt renderer={props} text={markdown()} markdown />\n </div>\n </OverlayPanel>\n }\n >\n {(_) => {\n const editor = props.editor!;\n return (\n <div class=\"k2b-content-file-view__editor\">\n <MarkdownEditor\n class=\"k2b-content-file-view__markdown-field\"\n aria-label={`Edit ${props.file.path.slice(props.file.path.lastIndexOf(\"/\") + 1)}`}\n fill\n value={editor.draft()}\n onValueChange={editor.setDraft}\n showStats={false}\n onSave={() => void editor.save()}\n saveDisabled={!editor.dirty()}\n saving={editor.saving()}\n toolbarTrailing={<EditorToolButton icon=\"ti ti-eye\" title={messages().preview} onClick={() => setEditing(false)} />}\n />\n </div>\n );\n }}\n </Show>\n );\n}\n\nfunction TextRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n return (\n <Show\n when={props.editor}\n fallback={\n <OverlayPanel actions={<DownloadAction {...props} />}>\n <TextExcerpt renderer={props} text={props.content.content} />\n </OverlayPanel>\n }\n >\n {(editor) => (\n // Same chrome as the markdown editor — literally the same classes, so\n // border, radius, focus ring, toolbar height and text metrics cannot drift.\n <div class=\"k2b-content-file-view__editor\">\n <div\n class=\"k2b-markdown-editor\"\n data-fill=\"true\"\n role=\"group\"\n aria-label={messages().textEditor}\n onKeyDown={(event) => {\n if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === \"s\") {\n event.preventDefault();\n if (editor().dirty() && !editor().saving()) void editor().save();\n }\n }}\n >\n {/* No formatting tools here — the divider under an actions-only bar reads lost. */}\n <div class=\"k2b-markdown-editor__toolbar k2b-content-file-view__code-toolbar\">\n <span class=\"k2b-content-file-view__code-language\">{codeLanguage(props.file.path)}</span>\n <span class=\"k2b-markdown-editor__trailing\">\n <Show when={props.downloadHref}>\n {(href) => (\n <DownloadLink\n class=\"k2b-markdown-editor__tool\"\n href={href()}\n download={props.file.path.slice(props.file.path.lastIndexOf(\"/\") + 1)}\n label={messages().download}\n icon=\"ti ti-download\"\n />\n )}\n </Show>\n <EditorToolButton\n icon={editor().saving() ? \"ti ti-loader-2 k2b-spin\" : \"ti ti-device-floppy\"}\n title={messages().saveShortcut}\n disabled={!editor().dirty() || editor().saving()}\n onClick={() => void editor().save()}\n />\n </span>\n </div>\n <div class=\"k2b-markdown-editor__surface\">\n <textarea\n class=\"k2b-content-file-view__code-input\"\n value={editor().draft()}\n spellcheck={false}\n onInput={(event) => editor().setDraft(event.currentTarget.value)}\n />\n </div>\n </div>\n </div>\n )}\n </Show>\n );\n}\n\nfunction JsonRenderer(props: FileViewRendererProps) {\n const parsed = createMemo(() => {\n try {\n return { ok: true as const, value: JSON.parse(props.content.content) as StructuredDataValue };\n } catch {\n return { ok: false as const };\n }\n });\n const parsedValue = (): StructuredDataValue => {\n const result = parsed();\n return result.ok ? result.value : null;\n };\n\n return (\n <OverlayPanel actions={<DownloadAction {...props} />}>\n <div class=\"k2b-content-file-view__document\">\n <Show when={parsed().ok} fallback={<TextExcerpt renderer={props} text={props.content.content} />}>\n <Show\n when={props.previewLines === undefined}\n fallback={<TextExcerpt renderer={props} text={JSON.stringify(parsedValue(), null, 2)} />}\n >\n <StructuredDataPreview data={parsedValue()} maxRows={200} />\n </Show>\n </Show>\n </div>\n </OverlayPanel>\n );\n}\n\nfunction DelimitedTextRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n const [preferences, setPreferences] = createSignal<DelimitedPreferences>({ encoding: \"utf-8\", delimiter: \"auto\", view: \"table\" });\n onMount(() => {\n if (!props.previewPreferencesKey) return;\n try {\n setPreferences(readDelimitedPreferences(localStorage.getItem(props.previewPreferencesKey)));\n } catch {\n /* Storage may be disabled. */\n }\n });\n const update = (patch: Partial<DelimitedPreferences>) => {\n const next = { ...preferences(), ...patch };\n setPreferences(next);\n if (props.previewPreferencesKey) {\n try {\n localStorage.setItem(props.previewPreferencesKey, JSON.stringify(next));\n } catch {\n /* Keep the local selection. */\n }\n }\n };\n const text = createMemo(() => decodeDelimitedContent(props.content, preferences().encoding));\n const delimiter = () =>\n preferences().delimiter === \"auto\"\n ? fileViewExtension(props.file.path) === \"tsv\" || props.content.mediaType === \"text/tab-separated-values\"\n ? \"\\t\"\n : \",\"\n : preferences().delimiter;\n const [page, setPage] = createSignal(0);\n createEffect(() => {\n text();\n delimiter();\n props.previewLines;\n setPage(0);\n });\n const pageSize = () => (props.previewLines === undefined ? 200 : Math.max(1, props.previewLines));\n const preview = createMemo(() => parseDelimitedText(text(), delimiter(), { rows: pageSize() + 1, offset: page() * pageSize() }));\n const settings = () =>\n prompts.dialog(\n () => (\n <div class=\"k2b-content-file-view__settings\">\n <Select\n label={messages().csvEncoding}\n value={preferences().encoding}\n disabled={props.content.encoding !== \"base64\"}\n options={[\"utf-8\", \"windows-1252\", \"utf-16le\", \"utf-16be\"]}\n onValueChange={(value) => {\n if (value) update({ encoding: value });\n }}\n />\n <Select\n label={messages().csvSeparator}\n value={preferences().delimiter}\n options={[\n { value: \"auto\", label: messages().csvDefaultSeparator },\n { value: \",\", label: messages().csvComma },\n { value: \";\", label: messages().csvSemicolon },\n { value: \"\\t\", label: messages().csvTab },\n { value: \"|\", label: \"|\" },\n ]}\n onValueChange={(value) => {\n if (value) update({ delimiter: value });\n }}\n />\n <Select\n label={messages().csvView}\n value={preferences().view}\n options={[\n { value: \"table\", label: messages().dataTable },\n { value: \"raw\", label: messages().csvRaw },\n ]}\n onValueChange={(value) => {\n if (value === \"table\" || value === \"raw\") update({ view: value });\n }}\n />\n </div>\n ),\n { title: messages().csvSettings },\n );\n const headers = createMemo(() => preview().rows[0] ?? []);\n const rows = createMemo(() => preview().rows.slice(1));\n\n return (\n <OverlayPanel\n actions={\n <>\n <OverlayAction icon=\"ti-adjustments-horizontal\" title={messages().csvSettings} onClick={() => void settings()} />\n <DownloadAction {...props} />\n </>\n }\n >\n <Show when={preferences().view === \"table\"} fallback={<TextExcerpt renderer={props} text={text()} />}>\n <Show\n when={headers().length > 0}\n fallback={<Placeholder icon=\"ti ti-table\" title={messages().emptyFile} description={messages().delimitedFileEmpty} />}\n >\n <div class=\"k2b-content-file-view__sheet\">\n <table class=\"k2b-content-file-view__table\">\n <thead>\n <tr>\n <For each={headers()}>\n {(header, index) => (\n <th scope=\"col\">\n <span>{header || messages().column({ number: index() + 1 })}</span>\n </th>\n )}\n </For>\n </tr>\n </thead>\n <tbody>\n <For each={rows()}>\n {(row) => (\n <tr>\n <For each={headers()}>{(_, index) => <td>{row[index()] ?? \"\"}</td>}</For>\n </tr>\n )}\n </For>\n </tbody>\n </table>\n <Show when={preview().columnsTruncated}>\n <div class=\"k2b-content-file-view__truncated\">{messages().previewColumnsLimited}</div>\n </Show>\n <Show\n when={props.previewLines !== undefined}\n fallback={\n <Show when={preview().totalRows > 201}>\n <div class=\"k2b-content-file-view__pagination\">\n <Button size=\"sm\" variant=\"ghost\" disabled={page() === 0} onClick={() => setPage(page() - 1)}>\n {messages().previous}\n </Button>\n <span>\n {page() * pageSize() + 1}–{Math.min((page() + 1) * pageSize(), preview().totalRows - 1)} / {preview().totalRows - 1}\n </span>\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={(page() + 1) * pageSize() >= preview().totalRows - 1}\n onClick={() => setPage(page() + 1)}\n >\n {messages().next}\n </Button>\n </div>\n </Show>\n }\n >\n <MoreLines count={preview().totalRows - rows().length - 1} onClick={props.onExpandPreview} />\n </Show>\n </div>\n </Show>\n </Show>\n </OverlayPanel>\n );\n}\n\nconst mediaSource = (props: FileViewRendererProps): string =>\n props.previewHref ?? `data:${props.content.mediaType};base64,${props.content.content}`;\n\nfunction ImageRenderer(props: FileViewRendererProps) {\n return (\n <OverlayPanel actions={<DownloadAction {...props} />}>\n <div class=\"k2b-content-file-view__media\">\n <img crossOrigin={props.crossOrigin} onError={props.onPreviewError} src={mediaSource(props)} alt={props.file.path} />\n </div>\n </OverlayPanel>\n );\n}\n\nconst pdfBlob = (content: FileViewContent): Blob => {\n if (content.encoding === \"utf8\") return new Blob([content.content], { type: \"application/pdf\" });\n const binary = atob(content.content);\n const bytes = new Uint8Array(binary.length);\n for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);\n return new Blob([bytes], { type: \"application/pdf\" });\n};\n\n/**\n * A host inline URL goes to the browser's native viewer. Without one, the\n * loaded bytes become a local PDF Blob: a download URL is an attachment and\n * would leave a native viewer empty.\n */\nfunction PdfRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n // A new Blob remounts the preview, so changed bytes show the new file. A revision refetch\n // often returns the same bytes (the Assistant refetches on every tool step); keeping the\n // Blob then keeps the reader's page instead of reloading the viewer.\n const bytes = createMemo(() => props.content, undefined, {\n equals: (previous, next) => previous.encoding === next.encoding && previous.content === next.content,\n });\n const blob = createMemo(() => (props.previewHref || !bytes().content ? null : pdfBlob(bytes())));\n return (\n <Show\n when={props.previewHref}\n fallback={\n <Show\n keyed\n when={blob()}\n fallback={<Placeholder icon=\"ti ti-file-type-pdf\" title=\"PDF\" description={messages().noInlinePreview} />}\n >\n {(pdf) => (\n // Composed without the standalone heading: the host already names the file, and the frame keeps the\n // file name as its accessible title.\n <PdfPreview autoLoad title={props.file.path.slice(props.file.path.lastIndexOf(\"/\") + 1)} request={async () => pdf}>\n {(parts) => (\n <div class=\"k2b-content-file-view__pdf-viewer\">\n {parts.actions}\n {parts.content}\n </div>\n )}\n </PdfPreview>\n )}\n </Show>\n }\n >\n {(href) => <object data={href()} type=\"application/pdf\" class=\"k2b-content-file-view__pdf\" aria-label={props.file.path} />}\n </Show>\n );\n}\n\nfunction AudioRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n return (\n <OverlayPanel actions={<DownloadAction {...props} />}>\n <div class=\"k2b-content-file-view__media\" data-kind=\"audio\">\n <audio\n crossOrigin={props.crossOrigin}\n onError={props.onPreviewError}\n controls\n preload=\"metadata\"\n src={mediaSource(props)}\n aria-label={props.file.path}\n >\n {messages().audioUnsupported}\n </audio>\n </div>\n </OverlayPanel>\n );\n}\n\nfunction VideoRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n return (\n <OverlayPanel actions={<DownloadAction {...props} />}>\n <div class=\"k2b-content-file-view__media\" data-kind=\"video\">\n <video\n crossOrigin={props.crossOrigin}\n onError={props.onPreviewError}\n controls\n preload=\"metadata\"\n playsinline\n src={mediaSource(props)}\n aria-label={props.file.path}\n >\n {messages().videoUnsupported}\n </video>\n </div>\n </OverlayPanel>\n );\n}\n\nfunction BinaryRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n return (\n <Placeholder\n icon=\"ti ti-file-unknown\"\n title={messages().noPreview}\n description={props.content.mediaType || messages().binaryFile}\n action={\n <Show when={props.downloadHref}>\n {(href) => (\n <a class=\"k2b-button\" data-variant=\"secondary\" data-size=\"sm\" href={href()} download=\"\">\n <i class=\"ti ti-download\" aria-hidden=\"true\" />\n {messages().download}\n </a>\n )}\n </Show>\n }\n />\n );\n}\n\nconst BUILTIN_RENDERERS: FileViewRenderer[] = [\n { id: \"markdown\", match: isMarkdown, component: MarkdownRenderer, editable: true },\n {\n id: \"image\",\n match: (file, content) => getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"image\",\n component: ImageRenderer,\n },\n {\n id: \"pdf\",\n match: (file, content) => getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"pdf\",\n component: PdfRenderer,\n },\n {\n id: \"json\",\n match: (file, content) =>\n content.encoding === \"utf8\" && getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"json\",\n component: JsonRenderer,\n },\n {\n id: \"delimited-text\",\n match: (file, content) => getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"delimited-text\",\n component: DelimitedTextRenderer,\n },\n {\n id: \"audio\",\n match: (file, content) => getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"audio\",\n component: AudioRenderer,\n },\n {\n id: \"video\",\n match: (file, content) => getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"video\",\n component: VideoRenderer,\n },\n { id: \"text\", match: (_file, content) => content.encoding === \"utf8\", component: TextRenderer, editable: true },\n { id: \"binary\", match: () => true, component: BinaryRenderer },\n];\n\n// ── Component ───────────────────────────────────────────────────────────────\n\nexport const formatFileViewSize = (bytes: number): string => {\n if (bytes < 1024) return `${bytes} B`;\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n};\n\nexport default function FileView(props: FileViewProps) {\n const messages = useUiMessages();\n const [draft, setDraft] = createSignal(\"\");\n const [savedDraft, setSavedDraft] = createSignal(\"\");\n const [nativeRevision, setNativeRevision] = createSignal(0);\n const dirty = createMemo(() => draft() !== savedDraft());\n const instanceRenderers = () => props.renderers ?? [];\n const saveMutation = mutation.create<{ path: string; content: string }, { path: string; content: string }>({\n mutation: async (input) => {\n await props.save!(input.content);\n return input;\n },\n onSuccess: (saved) => {\n if (props.file.path === saved.path) setSavedDraft(saved.content);\n toast.success(messages().fileSaved);\n },\n onError: (error) => toast.error(error.message),\n });\n const nativePreviewHref = createMemo(() => {\n const href = props.previewHref;\n if (!href) return null;\n const separator = href.includes(\"?\") ? \"&\" : \"?\";\n return `${href}${separator}preview-revision=${nativeRevision()}`;\n });\n const browserPreviewContent = createMemo<FileViewContent | null>(() => {\n const kind = getFileViewPreviewKind(props.file);\n if (kind !== \"image\" && kind !== \"pdf\" && kind !== \"audio\" && kind !== \"video\") return null;\n const href = nativePreviewHref();\n if (!href) return null;\n\n const candidate: FileViewContent = {\n encoding: \"base64\",\n content: \"\",\n mediaType: props.file.mediaType ?? \"application/octet-stream\",\n };\n return instanceRenderers().some((renderer) => renderer.match(props.file, candidate)) ? null : candidate;\n });\n const [content, { refetch }] = createResource(\n () => (browserPreviewContent() ? null : { path: props.file.path, revision: props.revision }),\n async () => {\n saveMutation.abort();\n // `load` is an imperative source adapter. Host signal reads inside it\n // must not turn this resource into a hidden reactive feedback loop.\n const loaded = await untrack(() => props.load());\n const loadedDraft = loaded.encoding === \"utf8\" ? loaded.content : \"\";\n setDraft(loadedDraft);\n setSavedDraft(loadedDraft);\n return loaded;\n },\n );\n createEffect(() => {\n if (!props.registerRefresh) return;\n const unregister = props.registerRefresh(async () => {\n if (browserPreviewContent()) setNativeRevision((value) => value + 1);\n else await refetch();\n });\n if (unregister) onCleanup(unregister);\n });\n // An errored resource throws when read; the error state below shows it instead.\n const resolvedContent = createMemo(() => browserPreviewContent() ?? (content.error ? undefined : content()));\n\n const renderer = createMemo(() => {\n const loaded = resolvedContent();\n if (!loaded) return null;\n return [...instanceRenderers(), ...BUILTIN_RENDERERS].find((candidate) => candidate.match(props.file, loaded)) ?? null;\n });\n\n createEffect(() => {\n props.onDirtyChange?.(dirty());\n });\n\n const save = async () => {\n if (!props.save || saveMutation.loading()) return;\n await saveMutation.mutate({ path: props.file.path, content: draft() });\n };\n\n const editor = () =>\n props.save && renderer()?.editable && resolvedContent()?.encoding === \"utf8\"\n ? {\n draft,\n setDraft,\n dirty,\n saving: saveMutation.loading,\n save,\n }\n : null;\n\n // Undefined while loading; the host keeps its own placeholder until the shown file decides.\n const documentTitle = createMemo<string | null | undefined>(() => {\n if (!props.onDocumentTitle) return undefined;\n if (content.error) return null;\n const loaded = resolvedContent();\n if (!loaded) return undefined;\n if (renderer()?.component !== MarkdownRenderer) return null;\n return leadingMarkdownTitle(stripFrontmatter(editor()?.draft() ?? loaded.content))?.title ?? null;\n });\n createEffect(() => {\n const title = documentTitle();\n if (title !== undefined) props.onDocumentTitle?.(title);\n });\n\n return (\n <div\n class={`k2b-content-file-view ${props.class ?? \"\"}`}\n data-variant={props.variant}\n data-excerpt={props.previewLines !== undefined ? \"true\" : undefined}\n >\n <FileViewHost.Provider\n value={{\n get plain() {\n return props.variant === \"plain\";\n },\n get liftTitle() {\n return Boolean(props.onDocumentTitle);\n },\n }}\n >\n <Switch>\n <Match when={content.loading && content() === undefined}>\n <Placeholder icon=\"ti ti-loader-2\" title={messages().loading} />\n </Match>\n <Match when={content.error}>\n <Placeholder icon=\"ti ti-alert-circle\" title={messages().failedLoadFile} description={String(content.error?.message ?? \"\")} />\n </Match>\n <Match when={resolvedContent() && renderer()}>\n {(active) => {\n const Renderer = active().component;\n return (\n <Renderer\n previewLines={props.previewLines}\n onExpandPreview={props.onExpandPreview}\n headingScale={props.headingScale}\n previewPreferencesKey={props.previewPreferencesKey}\n file={props.file}\n content={resolvedContent()!}\n previewHref={nativePreviewHref()}\n crossOrigin={props.crossOrigin}\n onPreviewError={props.onPreviewError}\n downloadHref={props.downloadHref ?? null}\n editor={editor()}\n />\n );\n }}\n </Match>\n </Switch>\n </FileViewHost.Provider>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,QAAQ,QAAQ,mBAAmB;AAC5C,SAEE,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,EACd,YAAY,EACZ,GAAG,EAEH,KAAK,EACL,SAAS,EACT,OAAO,EACP,IAAI,EACJ,MAAM,EACN,OAAO,EACP,UAAU,QACL,UAAU;AACjB,SAAS,MAAM,QAAQ,mBAAmB;AAC1C,SAAS,OAAO,QAAQ,qBAAqB;AAC7C,SAAS,OAAO,QAAQ,qBAAqB;AAC7C,SAAS,KAAK,Q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BAAA,IAChC,WAAW;kBAAA,OAAE,KAAK,CAAC,WAAW;gBAAA;gBAAA,IAC9B,cAAc;kBAAA,OAAE,KAAK,CAAC,cAAc;gBAAA;gBAAA,IACpC,YAAY;kBAAA,OAAE,KAAK,CAAC,YAAY,IAAI,IAAI;gBAAA;gBAAA,IACxC,MAAM;kBAAA,OAAE,MAAM,CAAC,CAAC;gBAAA;cAAA;YAGtB;UAAC;QAAA;MAAA;IAAA;EAAA;AAMb","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["content/FileView.tsx"],"sourcesContent":["/**\n * FileView — renders one file through a small renderer registry keyed by\n * media type / path. Editing is enabled purely by the presence of `save`;\n * without it every renderer is read-only. IDE-style chrome: editors reuse\n * the markdown editor's surface (toolbar with an in-toolbar save, Ctrl/Cmd+S),\n * previews are quiet paper panels with icon-only actions overlaid top-right.\n * A plain preview drops the panel and sits on its host's surface instead.\n * Custom renderers are passed per instance, which keeps SSR requests and\n * independently mounted applications isolated.\n */\n\nimport { mutation } from \"@k2b/stdlib/solid\";\nimport {\n type Component,\n createContext,\n createEffect,\n createMemo,\n createResource,\n createSignal,\n For,\n type JSX,\n Match,\n onCleanup,\n onMount,\n Show,\n Switch,\n untrack,\n useContext,\n} from \"solid-js\";\nimport { Button } from \"../actions/Button\";\nimport { prompts } from \"../feedback/prompts\";\nimport { Tooltip } from \"../feedback/Tooltip\";\nimport { toast } from \"../feedback/toast\";\nimport { MarkdownEditor } from \"../inputs/markdown/MarkdownEditor\";\nimport { Select } from \"../inputs/Select\";\nimport { useUiMessages } from \"../intl/messages\";\nimport Placeholder from \"../surfaces/Placeholder\";\nimport CodeDisplay, { type CodeDisplayLanguage } from \"./CodeDisplay\";\nimport { type DelimitedPreferences, decodeDelimitedContent, readDelimitedPreferences } from \"./delimited-preferences\";\nimport { type FileViewFile, fileViewExtension, getFileViewPreviewKind, parseDelimitedText } from \"./file-view-preview\";\nimport MarkdownView from \"./MarkdownView\";\nimport { leadingMarkdownTitle } from \"./markdown-title\";\nimport PdfPreview from \"./PdfPreview\";\nimport StructuredDataPreview, { type StructuredDataValue } from \"./StructuredDataPreview\";\nimport VideoPlayer from \"./VideoPlayer\";\n\nexport type { FileViewFile, FileViewPreviewKind } from \"./file-view-preview\";\nexport { canPreviewFile, getFileViewPreviewKind } from \"./file-view-preview\";\nexport type FileViewContent = { encoding: \"utf8\" | \"base64\"; content: string; mediaType: string };\n\nexport type FileViewProps = {\n /**\n * Plain previews inherit the surrounding surface without a frame or inset padding. They keep their natural height,\n * so the host scrolls them and owns the actions around them; a host that stretches one gets its scrolling back.\n */\n variant?: \"default\" | \"plain\";\n /**\n * Lifts a leading Markdown level-one heading into the host, for example a dialog title. Reports its plain text and\n * leaves that heading out of the preview, or reports null when the shown file has none, the heading holds a link or\n * image or is the whole document, or the file fails to load.\n */\n onDocumentTitle?: (title: string | null) => void;\n /** Read-only excerpt limit; omitted renders the complete preview. */\n previewLines?: number;\n onExpandPreview?: () => void;\n headingScale?: \"compact\" | \"normal\" | \"large\";\n /** Optional browser-local preference scope, owned by the host. */\n previewPreferencesKey?: string;\n file: FileViewFile;\n load: () => Promise<FileViewContent>;\n /** Refetch the current path when this host-owned revision changes. */\n revision?: unknown;\n /** Register an awaitable refresh for the currently visible preview. */\n registerRefresh?: (refresh: () => Promise<void>) => void | (() => void);\n /** Presence enables editing for text-based renderers. */\n save?: (content: string) => Promise<void>;\n /** Authenticated inline URL used by browser-native image, PDF, audio, and video previews. */\n previewHref?: string | null;\n /** CORS mode for native image/audio/video previews. Omit to preserve browser defaults. */\n crossOrigin?: \"anonymous\" | \"use-credentials\";\n /** Native media failed to load; the host can renew a signed URL and offer retry. */\n onPreviewError?: () => void;\n /** Download actions only; never a preview source, because an attachment response does not render inline. */\n downloadHref?: string | null;\n /** App-specific renderers matched before the built-ins for this instance. */\n renderers?: readonly FileViewRenderer[];\n /** Reports local edit state so a parent browser can guard navigation. */\n onDirtyChange?: (dirty: boolean) => void;\n class?: string;\n};\n\nexport type FileViewRendererProps = {\n /** Read-only excerpt limit; omitted renders the complete preview. */\n previewLines?: number;\n onExpandPreview?: () => void;\n headingScale?: \"compact\" | \"normal\" | \"large\";\n /** Optional browser-local preference scope, owned by the host. */\n previewPreferencesKey?: string;\n file: FileViewFile;\n content: FileViewContent;\n previewHref: string | null;\n crossOrigin?: \"anonymous\" | \"use-credentials\";\n onPreviewError?: () => void;\n downloadHref: string | null;\n /** Null when the file is read-only. */\n editor: {\n draft: () => string;\n setDraft: (value: string) => void;\n dirty: () => boolean;\n saving: () => boolean;\n save: () => Promise<void>;\n } | null;\n};\n\nexport type FileViewRenderer = {\n id: string;\n match: (file: FileViewFile, content: FileViewContent) => boolean;\n component: Component<FileViewRendererProps>;\n /** Text renderers that support the edit affordance when `save` is present. */\n editable?: boolean;\n};\n\n/** Instance options that reach the built-in renderers without widening the public renderer props. */\nconst FileViewHost = createContext({ plain: false, liftTitle: false });\n\nconst codeLanguage = (path: string): CodeDisplayLanguage => {\n const extension = fileViewExtension(path);\n if (extension === \"ts\" || extension === \"mts\" || extension === \"cts\") return \"ts\";\n if (extension === \"tsx\") return \"tsx\";\n if (extension === \"js\" || extension === \"mjs\" || extension === \"cjs\") return \"js\";\n if (extension === \"jsx\") return \"jsx\";\n if (extension === \"md\" || extension === \"markdown\") return \"md\";\n return \"text\";\n};\n\nconst isMarkdown = (file: FileViewFile, content: FileViewContent) =>\n content.encoding === \"utf8\" && getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"markdown\";\n\n/** Rendered previews hide a leading YAML frontmatter block — it's metadata, not content. */\nconst stripFrontmatter = (text: string): string => {\n const match = /^---\\r?\\n[\\s\\S]*?\\r?\\n---\\r?\\n?/.exec(text.trimStart());\n return match ? text.trimStart().slice(match[0].length) : text;\n};\n\n/** Icon-only download link with the shared tooltip, for toolbars that style their own controls. */\nfunction DownloadLink(props: { class: string; href: string; download: string; label: string; icon: string }) {\n let link: HTMLAnchorElement | undefined;\n return (\n <>\n <a ref={link} class={props.class} href={props.href} download={props.download} aria-label={props.label}>\n <i class={props.icon} aria-hidden=\"true\" />\n <span class=\"k2b-sr-only\">{props.label}</span>\n </a>\n <Tooltip content={props.label} target={() => link} />\n </>\n );\n}\n\n/** Icon-only action, IDE style — sits in the floating top-right cluster of previews. */\nfunction OverlayAction(props: { icon: string; title: string; onClick?: () => void; href?: string; download?: string }) {\n const classes = \"k2b-content-file-view__action\";\n return (\n <Show\n when={props.href}\n fallback={\n <Tooltip.Trigger type=\"button\" class={classes} content={props.title} aria-label={props.title} onClick={props.onClick}>\n <i class={`ti ${props.icon}`} aria-hidden=\"true\" />\n </Tooltip.Trigger>\n }\n >\n {(href) => (\n <DownloadLink class={classes} href={href()} download={props.download ?? \"\"} label={props.title} icon={`ti ${props.icon}`} />\n )}\n </Show>\n );\n}\n\n/** Scrollable preview panel with the floating action cluster overlaid top-right. */\nfunction OverlayPanel(props: { actions?: JSX.Element; children: JSX.Element }) {\n return (\n <div class=\"k2b-content-file-view__panel\">\n <div class=\"k2b-content-file-view__preview\">{props.children}</div>\n <Show when={props.actions}>\n <div class=\"k2b-content-file-view__overlay\">{props.actions}</div>\n </Show>\n </div>\n );\n}\n\nconst DownloadAction = (props: FileViewRendererProps): JSX.Element => {\n const messages = useUiMessages();\n return (\n <Show when={props.downloadHref}>\n {(href) => (\n <OverlayAction\n icon=\"ti-download\"\n title={messages().download}\n href={href()}\n download={props.file.path.slice(props.file.path.lastIndexOf(\"/\") + 1)}\n />\n )}\n </Show>\n );\n};\n\n/** Toolbar-styled icon button — reuses the package markdown-editor tool primitive. */\nfunction EditorToolButton(props: { icon: string; title: string; onClick: () => void; disabled?: boolean }) {\n return (\n <Tooltip.Trigger\n type=\"button\"\n class=\"k2b-markdown-editor__tool\"\n content={props.title}\n aria-label={props.title}\n tabIndex={-1}\n disabled={props.disabled}\n onMouseDown={(e) => e.preventDefault()}\n onClick={props.onClick}\n >\n <i class={props.icon} aria-hidden=\"true\" />\n </Tooltip.Trigger>\n );\n}\n\n// ── Built-in renderers ──────────────────────────────────────────────────────\n\nfunction MoreLines(props: { count: number; onClick?: () => void }) {\n const messages = useUiMessages();\n return (\n <Show when={props.count > 0}>\n <div class=\"k2b-content-file-view__truncated\">\n <Show when={props.onClick} fallback={<span>{messages().previewMoreLines(props.count)}</span>}>\n <Button size=\"sm\" variant=\"ghost\" onClick={props.onClick}>\n {messages().previewMoreLines(props.count)}\n </Button>\n </Show>\n </div>\n </Show>\n );\n}\nfunction TextExcerpt(props: { renderer: FileViewRendererProps; text: string; markdown?: boolean }) {\n const lines = createMemo(() => props.text.replace(/\\r\\n?/g, \"\\n\").replace(/\\n$/, \"\").split(\"\\n\"));\n const limit = () => (props.renderer.previewLines === undefined ? lines().length : Math.max(1, props.renderer.previewLines));\n const text = () => lines().slice(0, limit()).join(\"\\n\");\n const host = useContext(FileViewHost);\n // A plain preview has no code box: the host frames the file and owns its copy action.\n const content = () => (\n <Show\n when={props.markdown}\n fallback={<CodeDisplay code={text()} language={codeLanguage(props.renderer.file.path)} copy={host.plain ? false : undefined} />}\n >\n <MarkdownView markdown={text()} headingScale={props.renderer.headingScale ?? \"compact\"} />\n </Show>\n );\n // Only an excerpt needs a clipping box; a complete preview keeps its content\n // a direct child of the preview frame, which the frame's styles expect.\n return (\n <>\n <Show when={props.renderer.previewLines !== undefined} fallback={content()}>\n <div class=\"k2b-content-file-view__excerpt\">{content()}</div>\n </Show>\n <MoreLines count={lines().length - limit()} onClick={props.renderer.onExpandPreview} />\n </>\n );\n}\n\nfunction MarkdownRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n const host = useContext(FileViewHost);\n const [editing, setEditing] = createSignal(false);\n const markdown = () => {\n const text = stripFrontmatter(props.editor?.draft() ?? props.content.content);\n return host.liftTitle ? (leadingMarkdownTitle(text)?.body ?? text) : text;\n };\n return (\n <Show\n when={props.editor && editing()}\n fallback={\n <OverlayPanel\n actions={\n <>\n <Show when={props.editor}>\n <OverlayAction icon=\"ti-pencil\" title={messages().edit} onClick={() => setEditing(true)} />\n </Show>\n <DownloadAction {...props} />\n </>\n }\n >\n <div class=\"k2b-content-file-view__document\">\n <TextExcerpt renderer={props} text={markdown()} markdown />\n </div>\n </OverlayPanel>\n }\n >\n {(_) => {\n const editor = props.editor!;\n return (\n <div class=\"k2b-content-file-view__editor\">\n <MarkdownEditor\n class=\"k2b-content-file-view__markdown-field\"\n aria-label={`Edit ${props.file.path.slice(props.file.path.lastIndexOf(\"/\") + 1)}`}\n fill\n value={editor.draft()}\n onValueChange={editor.setDraft}\n showStats={false}\n onSave={() => void editor.save()}\n saveDisabled={!editor.dirty()}\n saving={editor.saving()}\n toolbarTrailing={<EditorToolButton icon=\"ti ti-eye\" title={messages().preview} onClick={() => setEditing(false)} />}\n />\n </div>\n );\n }}\n </Show>\n );\n}\n\nfunction TextRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n return (\n <Show\n when={props.editor}\n fallback={\n <OverlayPanel actions={<DownloadAction {...props} />}>\n <TextExcerpt renderer={props} text={props.content.content} />\n </OverlayPanel>\n }\n >\n {(editor) => (\n // Same chrome as the markdown editor — literally the same classes, so\n // border, radius, focus ring, toolbar height and text metrics cannot drift.\n <div class=\"k2b-content-file-view__editor\">\n <div\n class=\"k2b-markdown-editor\"\n data-fill=\"true\"\n role=\"group\"\n aria-label={messages().textEditor}\n onKeyDown={(event) => {\n if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === \"s\") {\n event.preventDefault();\n if (editor().dirty() && !editor().saving()) void editor().save();\n }\n }}\n >\n {/* No formatting tools here — the divider under an actions-only bar reads lost. */}\n <div class=\"k2b-markdown-editor__toolbar k2b-content-file-view__code-toolbar\">\n <span class=\"k2b-content-file-view__code-language\">{codeLanguage(props.file.path)}</span>\n <span class=\"k2b-markdown-editor__trailing\">\n <Show when={props.downloadHref}>\n {(href) => (\n <DownloadLink\n class=\"k2b-markdown-editor__tool\"\n href={href()}\n download={props.file.path.slice(props.file.path.lastIndexOf(\"/\") + 1)}\n label={messages().download}\n icon=\"ti ti-download\"\n />\n )}\n </Show>\n <EditorToolButton\n icon={editor().saving() ? \"ti ti-loader-2 k2b-spin\" : \"ti ti-device-floppy\"}\n title={messages().saveShortcut}\n disabled={!editor().dirty() || editor().saving()}\n onClick={() => void editor().save()}\n />\n </span>\n </div>\n <div class=\"k2b-markdown-editor__surface\">\n <textarea\n class=\"k2b-content-file-view__code-input\"\n value={editor().draft()}\n spellcheck={false}\n onInput={(event) => editor().setDraft(event.currentTarget.value)}\n />\n </div>\n </div>\n </div>\n )}\n </Show>\n );\n}\n\nfunction JsonRenderer(props: FileViewRendererProps) {\n const parsed = createMemo(() => {\n try {\n return { ok: true as const, value: JSON.parse(props.content.content) as StructuredDataValue };\n } catch {\n return { ok: false as const };\n }\n });\n const parsedValue = (): StructuredDataValue => {\n const result = parsed();\n return result.ok ? result.value : null;\n };\n\n return (\n <OverlayPanel actions={<DownloadAction {...props} />}>\n <div class=\"k2b-content-file-view__document\">\n <Show when={parsed().ok} fallback={<TextExcerpt renderer={props} text={props.content.content} />}>\n <Show\n when={props.previewLines === undefined}\n fallback={<TextExcerpt renderer={props} text={JSON.stringify(parsedValue(), null, 2)} />}\n >\n <StructuredDataPreview data={parsedValue()} maxRows={200} />\n </Show>\n </Show>\n </div>\n </OverlayPanel>\n );\n}\n\nfunction DelimitedTextRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n const [preferences, setPreferences] = createSignal<DelimitedPreferences>({ encoding: \"utf-8\", delimiter: \"auto\", view: \"table\" });\n onMount(() => {\n if (!props.previewPreferencesKey) return;\n try {\n setPreferences(readDelimitedPreferences(localStorage.getItem(props.previewPreferencesKey)));\n } catch {\n /* Storage may be disabled. */\n }\n });\n const update = (patch: Partial<DelimitedPreferences>) => {\n const next = { ...preferences(), ...patch };\n setPreferences(next);\n if (props.previewPreferencesKey) {\n try {\n localStorage.setItem(props.previewPreferencesKey, JSON.stringify(next));\n } catch {\n /* Keep the local selection. */\n }\n }\n };\n const text = createMemo(() => decodeDelimitedContent(props.content, preferences().encoding));\n const delimiter = () =>\n preferences().delimiter === \"auto\"\n ? fileViewExtension(props.file.path) === \"tsv\" || props.content.mediaType === \"text/tab-separated-values\"\n ? \"\\t\"\n : \",\"\n : preferences().delimiter;\n const [page, setPage] = createSignal(0);\n createEffect(() => {\n text();\n delimiter();\n props.previewLines;\n setPage(0);\n });\n const pageSize = () => (props.previewLines === undefined ? 200 : Math.max(1, props.previewLines));\n const preview = createMemo(() => parseDelimitedText(text(), delimiter(), { rows: pageSize() + 1, offset: page() * pageSize() }));\n const settings = () =>\n prompts.dialog(\n () => (\n <div class=\"k2b-content-file-view__settings\">\n <Select\n label={messages().csvEncoding}\n value={preferences().encoding}\n disabled={props.content.encoding !== \"base64\"}\n options={[\"utf-8\", \"windows-1252\", \"utf-16le\", \"utf-16be\"]}\n onValueChange={(value) => {\n if (value) update({ encoding: value });\n }}\n />\n <Select\n label={messages().csvSeparator}\n value={preferences().delimiter}\n options={[\n { value: \"auto\", label: messages().csvDefaultSeparator },\n { value: \",\", label: messages().csvComma },\n { value: \";\", label: messages().csvSemicolon },\n { value: \"\\t\", label: messages().csvTab },\n { value: \"|\", label: \"|\" },\n ]}\n onValueChange={(value) => {\n if (value) update({ delimiter: value });\n }}\n />\n <Select\n label={messages().csvView}\n value={preferences().view}\n options={[\n { value: \"table\", label: messages().dataTable },\n { value: \"raw\", label: messages().csvRaw },\n ]}\n onValueChange={(value) => {\n if (value === \"table\" || value === \"raw\") update({ view: value });\n }}\n />\n </div>\n ),\n { title: messages().csvSettings },\n );\n const headers = createMemo(() => preview().rows[0] ?? []);\n const rows = createMemo(() => preview().rows.slice(1));\n\n return (\n <OverlayPanel\n actions={\n <>\n <OverlayAction icon=\"ti-adjustments-horizontal\" title={messages().csvSettings} onClick={() => void settings()} />\n <DownloadAction {...props} />\n </>\n }\n >\n <Show when={preferences().view === \"table\"} fallback={<TextExcerpt renderer={props} text={text()} />}>\n <Show\n when={headers().length > 0}\n fallback={<Placeholder icon=\"ti ti-table\" title={messages().emptyFile} description={messages().delimitedFileEmpty} />}\n >\n <div class=\"k2b-content-file-view__sheet\">\n <table class=\"k2b-content-file-view__table\">\n <thead>\n <tr>\n <For each={headers()}>\n {(header, index) => (\n <th scope=\"col\">\n <span>{header || messages().column({ number: index() + 1 })}</span>\n </th>\n )}\n </For>\n </tr>\n </thead>\n <tbody>\n <For each={rows()}>\n {(row) => (\n <tr>\n <For each={headers()}>{(_, index) => <td>{row[index()] ?? \"\"}</td>}</For>\n </tr>\n )}\n </For>\n </tbody>\n </table>\n <Show when={preview().columnsTruncated}>\n <div class=\"k2b-content-file-view__truncated\">{messages().previewColumnsLimited}</div>\n </Show>\n <Show\n when={props.previewLines !== undefined}\n fallback={\n <Show when={preview().totalRows > 201}>\n <div class=\"k2b-content-file-view__pagination\">\n <Button size=\"sm\" variant=\"ghost\" disabled={page() === 0} onClick={() => setPage(page() - 1)}>\n {messages().previous}\n </Button>\n <span>\n {page() * pageSize() + 1}–{Math.min((page() + 1) * pageSize(), preview().totalRows - 1)} / {preview().totalRows - 1}\n </span>\n <Button\n size=\"sm\"\n variant=\"ghost\"\n disabled={(page() + 1) * pageSize() >= preview().totalRows - 1}\n onClick={() => setPage(page() + 1)}\n >\n {messages().next}\n </Button>\n </div>\n </Show>\n }\n >\n <MoreLines count={preview().totalRows - rows().length - 1} onClick={props.onExpandPreview} />\n </Show>\n </div>\n </Show>\n </Show>\n </OverlayPanel>\n );\n}\n\nconst mediaSource = (props: FileViewRendererProps): string =>\n props.previewHref ?? `data:${props.content.mediaType};base64,${props.content.content}`;\n\nfunction ImageRenderer(props: FileViewRendererProps) {\n return (\n <OverlayPanel actions={<DownloadAction {...props} />}>\n <div class=\"k2b-content-file-view__media\">\n <img crossOrigin={props.crossOrigin} onError={props.onPreviewError} src={mediaSource(props)} alt={props.file.path} />\n </div>\n </OverlayPanel>\n );\n}\n\nconst pdfBlob = (content: FileViewContent): Blob => {\n if (content.encoding === \"utf8\") return new Blob([content.content], { type: \"application/pdf\" });\n const binary = atob(content.content);\n const bytes = new Uint8Array(binary.length);\n for (let index = 0; index < binary.length; index += 1) bytes[index] = binary.charCodeAt(index);\n return new Blob([bytes], { type: \"application/pdf\" });\n};\n\n/**\n * A host inline URL goes to the browser's native viewer. Without one, the\n * loaded bytes become a local PDF Blob: a download URL is an attachment and\n * would leave a native viewer empty.\n */\nfunction PdfRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n // A new Blob remounts the preview, so changed bytes show the new file. A revision refetch\n // often returns the same bytes (the Assistant refetches on every tool step); keeping the\n // Blob then keeps the reader's page instead of reloading the viewer.\n const bytes = createMemo(() => props.content, undefined, {\n equals: (previous, next) => previous.encoding === next.encoding && previous.content === next.content,\n });\n const blob = createMemo(() => (props.previewHref || !bytes().content ? null : pdfBlob(bytes())));\n return (\n <Show\n when={props.previewHref}\n fallback={\n <Show\n keyed\n when={blob()}\n fallback={<Placeholder icon=\"ti ti-file-type-pdf\" title=\"PDF\" description={messages().noInlinePreview} />}\n >\n {(pdf) => (\n // Composed without the standalone heading: the host already names the file, and the frame keeps the\n // file name as its accessible title.\n <PdfPreview autoLoad title={props.file.path.slice(props.file.path.lastIndexOf(\"/\") + 1)} request={async () => pdf}>\n {(parts) => (\n <div class=\"k2b-content-file-view__pdf-viewer\">\n {parts.actions}\n {parts.content}\n </div>\n )}\n </PdfPreview>\n )}\n </Show>\n }\n >\n {(href) => <object data={href()} type=\"application/pdf\" class=\"k2b-content-file-view__pdf\" aria-label={props.file.path} />}\n </Show>\n );\n}\n\nfunction AudioRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n return (\n <OverlayPanel actions={<DownloadAction {...props} />}>\n <div class=\"k2b-content-file-view__media\" data-kind=\"audio\">\n <audio\n crossOrigin={props.crossOrigin}\n onError={props.onPreviewError}\n controls\n preload=\"metadata\"\n src={mediaSource(props)}\n aria-label={props.file.path}\n >\n {messages().audioUnsupported}\n </audio>\n </div>\n </OverlayPanel>\n );\n}\n\nfunction VideoRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n const name = () => props.file.path.slice(props.file.path.lastIndexOf(\"/\") + 1);\n return (\n <OverlayPanel actions={<DownloadAction {...props} />}>\n <div class=\"k2b-content-file-view__media\" data-kind=\"video\">\n <VideoPlayer\n src={mediaSource(props)}\n label={name()}\n crossOrigin={props.crossOrigin}\n onFallback={props.onPreviewError}\n fallbackAction={\n <Show when={props.downloadHref}>\n {(href) => (\n <a class=\"k2b-button\" data-variant=\"secondary\" data-size=\"sm\" href={href()} download={name()}>\n <i class=\"ti ti-download\" aria-hidden=\"true\" />\n {messages().download}\n </a>\n )}\n </Show>\n }\n />\n </div>\n </OverlayPanel>\n );\n}\n\nfunction BinaryRenderer(props: FileViewRendererProps) {\n const messages = useUiMessages();\n return (\n <Placeholder\n icon=\"ti ti-file-unknown\"\n title={messages().noPreview}\n description={props.content.mediaType || messages().binaryFile}\n action={\n <Show when={props.downloadHref}>\n {(href) => (\n <a class=\"k2b-button\" data-variant=\"secondary\" data-size=\"sm\" href={href()} download=\"\">\n <i class=\"ti ti-download\" aria-hidden=\"true\" />\n {messages().download}\n </a>\n )}\n </Show>\n }\n />\n );\n}\n\nconst BUILTIN_RENDERERS: FileViewRenderer[] = [\n { id: \"markdown\", match: isMarkdown, component: MarkdownRenderer, editable: true },\n {\n id: \"image\",\n match: (file, content) => getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"image\",\n component: ImageRenderer,\n },\n {\n id: \"pdf\",\n match: (file, content) => getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"pdf\",\n component: PdfRenderer,\n },\n {\n id: \"json\",\n match: (file, content) =>\n content.encoding === \"utf8\" && getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"json\",\n component: JsonRenderer,\n },\n {\n id: \"delimited-text\",\n match: (file, content) => getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"delimited-text\",\n component: DelimitedTextRenderer,\n },\n {\n id: \"audio\",\n match: (file, content) => getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"audio\",\n component: AudioRenderer,\n },\n {\n id: \"video\",\n match: (file, content) => getFileViewPreviewKind({ ...file, mediaType: content.mediaType || file.mediaType }) === \"video\",\n component: VideoRenderer,\n },\n { id: \"text\", match: (_file, content) => content.encoding === \"utf8\", component: TextRenderer, editable: true },\n { id: \"binary\", match: () => true, component: BinaryRenderer },\n];\n\n// ── Component ───────────────────────────────────────────────────────────────\n\nexport const formatFileViewSize = (bytes: number): string => {\n if (bytes < 1024) return `${bytes} B`;\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n};\n\nexport default function FileView(props: FileViewProps) {\n const messages = useUiMessages();\n const [draft, setDraft] = createSignal(\"\");\n const [savedDraft, setSavedDraft] = createSignal(\"\");\n const [nativeRevision, setNativeRevision] = createSignal(0);\n const dirty = createMemo(() => draft() !== savedDraft());\n const instanceRenderers = () => props.renderers ?? [];\n const saveMutation = mutation.create<{ path: string; content: string }, { path: string; content: string }>({\n mutation: async (input) => {\n await props.save!(input.content);\n return input;\n },\n onSuccess: (saved) => {\n if (props.file.path === saved.path) setSavedDraft(saved.content);\n toast.success(messages().fileSaved);\n },\n onError: (error) => toast.error(error.message),\n });\n const nativePreviewHref = createMemo(() => {\n const href = props.previewHref;\n if (!href) return null;\n const separator = href.includes(\"?\") ? \"&\" : \"?\";\n return `${href}${separator}preview-revision=${nativeRevision()}`;\n });\n const browserPreviewContent = createMemo<FileViewContent | null>(() => {\n const kind = getFileViewPreviewKind(props.file);\n if (kind !== \"image\" && kind !== \"pdf\" && kind !== \"audio\" && kind !== \"video\") return null;\n const href = nativePreviewHref();\n if (!href) return null;\n\n const candidate: FileViewContent = {\n encoding: \"base64\",\n content: \"\",\n mediaType: props.file.mediaType ?? \"application/octet-stream\",\n };\n return instanceRenderers().some((renderer) => renderer.match(props.file, candidate)) ? null : candidate;\n });\n const [content, { refetch }] = createResource(\n () => (browserPreviewContent() ? null : { path: props.file.path, revision: props.revision }),\n async () => {\n saveMutation.abort();\n // `load` is an imperative source adapter. Host signal reads inside it\n // must not turn this resource into a hidden reactive feedback loop.\n const loaded = await untrack(() => props.load());\n const loadedDraft = loaded.encoding === \"utf8\" ? loaded.content : \"\";\n setDraft(loadedDraft);\n setSavedDraft(loadedDraft);\n return loaded;\n },\n );\n createEffect(() => {\n if (!props.registerRefresh) return;\n const unregister = props.registerRefresh(async () => {\n if (browserPreviewContent()) setNativeRevision((value) => value + 1);\n else await refetch();\n });\n if (unregister) onCleanup(unregister);\n });\n // An errored resource throws when read; the error state below shows it instead.\n const resolvedContent = createMemo(() => browserPreviewContent() ?? (content.error ? undefined : content()));\n\n const renderer = createMemo(() => {\n const loaded = resolvedContent();\n if (!loaded) return null;\n return [...instanceRenderers(), ...BUILTIN_RENDERERS].find((candidate) => candidate.match(props.file, loaded)) ?? null;\n });\n\n createEffect(() => {\n props.onDirtyChange?.(dirty());\n });\n\n const save = async () => {\n if (!props.save || saveMutation.loading()) return;\n await saveMutation.mutate({ path: props.file.path, content: draft() });\n };\n\n const editor = () =>\n props.save && renderer()?.editable && resolvedContent()?.encoding === \"utf8\"\n ? {\n draft,\n setDraft,\n dirty,\n saving: saveMutation.loading,\n save,\n }\n : null;\n\n // Undefined while loading; the host keeps its own placeholder until the shown file decides.\n const documentTitle = createMemo<string | null | undefined>(() => {\n if (!props.onDocumentTitle) return undefined;\n if (content.error) return null;\n const loaded = resolvedContent();\n if (!loaded) return undefined;\n if (renderer()?.component !== MarkdownRenderer) return null;\n return leadingMarkdownTitle(stripFrontmatter(editor()?.draft() ?? loaded.content))?.title ?? null;\n });\n createEffect(() => {\n const title = documentTitle();\n if (title !== undefined) props.onDocumentTitle?.(title);\n });\n\n return (\n <div\n class={`k2b-content-file-view ${props.class ?? \"\"}`}\n data-variant={props.variant}\n data-excerpt={props.previewLines !== undefined ? \"true\" : undefined}\n >\n <FileViewHost.Provider\n value={{\n get plain() {\n return props.variant === \"plain\";\n },\n get liftTitle() {\n return Boolean(props.onDocumentTitle);\n },\n }}\n >\n <Switch>\n <Match when={content.loading && content() === undefined}>\n <Placeholder icon=\"ti ti-loader-2\" title={messages().loading} />\n </Match>\n <Match when={content.error}>\n <Placeholder icon=\"ti ti-alert-circle\" title={messages().failedLoadFile} description={String(content.error?.message ?? \"\")} />\n </Match>\n <Match when={resolvedContent() && renderer()}>\n {(active) => {\n const Renderer = active().component;\n return (\n <Renderer\n previewLines={props.previewLines}\n onExpandPreview={props.onExpandPreview}\n headingScale={props.headingScale}\n previewPreferencesKey={props.previewPreferencesKey}\n file={props.file}\n content={resolvedContent()!}\n previewHref={nativePreviewHref()}\n crossOrigin={props.crossOrigin}\n onPreviewError={props.onPreviewError}\n downloadHref={props.downloadHref ?? null}\n editor={editor()}\n />\n );\n }}\n </Match>\n </Switch>\n </FileViewHost.Provider>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAS,QAAQ,QAAQ,mBAAmB;AAC5C,SAEE,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,EACd,YAAY,EACZ,GAAG,EAEH,KAAK,EACL,SAAS,EACT,OAAO,EACP,IAAI,EACJ,MAAM,EACN,OAAO,EACP,UAAU,QACL,UAAU;AACjB,SAAS,MAAM,QAAQ,mBAAmB;AAC1C,SAAS,OAAO,QAAQ,qBAAqB;AAC7C,SAAS,OAAO,QAAQ,qBAAqB;AAC7C,SAAS,KAAK,QAAQ,mBAAmB;AACzC,SAAS,cAAc,QAAQ,mCAAmC;AAClE,SAAS,MAAM,QAAQ,kBAAkB;AACzC,SAAS,aAAa,QAAQ,kBAAkB;AAChD,OAAO,WAAW,MAAM,yBAAyB;AACjD,OAAO,WAAW,MAAoC,eAAe;AACr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AAK,CAAC,eAAe;gBAAA;gBAAA,IACtC,YAAY;kBAAA,OAAE,KAAK,CAAC,YAAY;gBAAA;gBAAA,IAChC,qBAAqB;kBAAA,OAAE,KAAK,CAAC,qBAAqB;gBAAA;gBAAA,IAClD,IAAI;kBAAA,OAAE,KAAK,CAAC,IAAI;gBAAA;gBAAA,IAChB,OAAO;kBAAA,OAAE,eAAe,CAAC,CAAC;gBAAA;gBAAA,IAC1B,WAAW;kBAAA,OAAE,iBAAiB,CAAC,CAAC;gBAAA;gBAAA,IAChC,WAAW;kBAAA,OAAE,KAAK,CAAC,WAAW;gBAAA;gBAAA,IAC9B,cAAc;kBAAA,OAAE,KAAK,CAAC,cAAc;gBAAA;gBAAA,IACpC,YAAY;kBAAA,OAAE,KAAK,CAAC,YAAY,IAAI,IAAI;gBAAA;gBAAA,IACxC,MAAM;kBAAA,OAAE,MAAM,CAAC,CAAC;gBAAA;cAAA;YAGtB;UAAC;QAAA;MAAA;IAAA;EAAA;AAMb","ignoreList":[]}
@@ -5,6 +5,7 @@ var _tmpl$ = ["<div class=\"", "\"", ">", "</div>"];
5
5
  import { Marked, Renderer } from "marked";
6
6
  import { useLocale } from "../intl/locale";
7
7
  import { markdownInfoBlocks } from "./markdown-info-blocks";
8
+ import { markdownLinkReference, renderMarkdownLink } from "./markdown-links";
8
9
  export const escapeHtml = value => value.replaceAll("&", "&amp;").replaceAll("<", "&lt;").replaceAll(">", "&gt;").replaceAll('"', "&quot;").replaceAll("'", "&#39;");
9
10
  const safeUrl = value => {
10
11
  const normalized = value.trim().replace(/[\u0000-\u001f\u007f-\u009f\s]+/g, "");
@@ -55,9 +56,14 @@ export const createSafeRenderer = (options = {}) => {
55
56
  return body;
56
57
  }
57
58
  }
58
- const titleAttribute = title ? ` title="${escapeHtml(title)}"` : "";
59
- const target = options.linkTarget === "_blank" ? ' target="_blank" rel="noopener noreferrer"' : "";
60
- return `<a href="${escapeHtml(url)}"${titleAttribute}${target}>${body}</a>`;
59
+ return renderMarkdownLink({
60
+ href: url,
61
+ html: body,
62
+ title: title ?? undefined,
63
+ target: options.linkTarget,
64
+ reference: markdownLinkReference(url),
65
+ locale: options.locale
66
+ });
61
67
  };
62
68
  renderer.image = ({
63
69
  href,
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["content/MarkdownView.tsx"],"sourcesContent":["import { Marked, Renderer, type Tokens } from \"marked\";\nimport { useLocale } from \"../intl/locale\";\nimport { markdownInfoBlocks } from \"./markdown-info-blocks\";\n\ntype CommonProps = MarkdownRenderOptions & {\n /** Optional additional CSS classes */\n class?: string;\n /**\n * Visual heading scale. Markdown heading levels and document structure stay\n * unchanged.\n */\n headingScale?: \"compact\" | \"normal\" | \"large\";\n};\n\nexport type MarkdownViewProps = CommonProps &\n (\n | {\n /** Untrusted Markdown. Raw HTML and unsafe link protocols are escaped. */\n markdown: string;\n /** Exact standalone text tokens to emphasize without changing Markdown parsing or trusted-HTML boundaries. */\n inlineTokens?: readonly string[];\n trustedHtml?: never;\n }\n | {\n /** Explicitly trusted, already-rendered HTML. The caller owns sanitization. */\n trustedHtml: string;\n markdown?: never;\n inlineTokens?: never;\n }\n );\n\nexport type MarkdownRenderOptions = {\n inlineTokens?: readonly string[];\n /** Whether to render images. False renders alt text without resource requests. Defaults to true. */\n allowImages?: boolean;\n /** Optional protocol allowlist, including trailing colons. Relative URLs resolve as HTTPS. */\n linkProtocols?: readonly string[];\n linkTarget?: \"_blank\";\n /** Locale for the screen-reader names of untitled info blocks. `MarkdownView` passes the inherited render locale. */\n locale?: string;\n};\n\nexport const escapeHtml = (value: string): string =>\n value.replaceAll(\"&\", \"&amp;\").replaceAll(\"<\", \"&lt;\").replaceAll(\">\", \"&gt;\").replaceAll('\"', \"&quot;\").replaceAll(\"'\", \"&#39;\");\n\nconst safeUrl = (value: string): string | null => {\n const normalized = value.trim().replace(/[\\u0000-\\u001f\\u007f-\\u009f\\s]+/g, \"\");\n if (/^(?:javascript|vbscript|data):/i.test(normalized)) return null;\n return value;\n};\n\nconst normalizeInlineTokens = (tokens: readonly string[] | undefined): string[] =>\n [...new Set(tokens?.filter(Boolean) ?? [])].sort((left, right) => right.length - left.length);\n\nconst isStandaloneInlineToken = (text: string, start: number, value: string): boolean => {\n const before = text[start - 1];\n if (before && /[a-zA-Z0-9_.%+\\-]/.test(before)) return false;\n const end = start + value.length;\n const after = text[end];\n if (after && /[a-zA-Z0-9_@]/.test(after)) return false;\n return !(after === \".\" && /[a-zA-Z0-9_]/.test(text[end + 1] ?? \"\"));\n};\n\nexport const createSafeRenderer = (options: MarkdownRenderOptions = {}): Renderer => {\n const renderer = new Renderer();\n const inlineTokens = normalizeInlineTokens(options.inlineTokens);\n const baseText = renderer.text.bind(renderer);\n // marked flags text that follows an inline <pre>, <code>, <kbd> or <script>\n // tag as already escaped, because it expects that tag to reach the output as\n // HTML. The tag is escaped here, so the text after it is escaped as well.\n const renderText: Renderer[\"text\"] = (token) => baseText(token.type === \"text\" && token.escaped ? { ...token, escaped: false } : token);\n const renderTable = renderer.table.bind(renderer);\n renderer.table = (token: Tokens.Table) => {\n const table = renderTable(token);\n const content = token.header.every((cell) => !cell.text.trim()) ? table.replace(/<thead>[\\s\\S]*?<\\/thead>\\n?/, \"\") : table;\n return `<div class=\"k2b-content-markdown__table\" tabindex=\"0\">${content}</div>`;\n };\n renderer.html = ({ text }: Tokens.HTML | Tokens.Tag) => escapeHtml(text);\n renderer.link = function ({ href, title, tokens }: Tokens.Link) {\n const body = this.parser.parseInline(tokens);\n const url = safeUrl(href);\n if (!url) return body;\n if (options.linkProtocols) {\n try {\n if (!options.linkProtocols.includes(new URL(url, \"https://markdown.invalid/\").protocol)) return body;\n } catch {\n return body;\n }\n }\n const titleAttribute = title ? ` title=\"${escapeHtml(title)}\"` : \"\";\n const target = options.linkTarget === \"_blank\" ? ' target=\"_blank\" rel=\"noopener noreferrer\"' : \"\";\n return `<a href=\"${escapeHtml(url)}\"${titleAttribute}${target}>${body}</a>`;\n };\n renderer.image = ({ href, title, text }: Tokens.Image) => {\n const url = safeUrl(href);\n if (!url || options.allowImages === false) return escapeHtml(text);\n const titleAttribute = title ? ` title=\"${escapeHtml(title)}\"` : \"\";\n return `<img src=\"${escapeHtml(url)}\" alt=\"${escapeHtml(text)}\"${titleAttribute}>`;\n };\n renderer.text = (token) => {\n if (inlineTokens.length === 0 || token.type === \"escape\" || (\"tokens\" in token && token.tokens)) return renderText(token);\n const parts: string[] = [];\n let plainStart = 0;\n let cursor = 0;\n while (cursor < token.text.length) {\n const inlineToken = inlineTokens.find(\n (candidate) => token.text.startsWith(candidate, cursor) && isStandaloneInlineToken(token.text, cursor, candidate),\n );\n if (!inlineToken) {\n cursor += 1;\n continue;\n }\n if (plainStart < cursor) {\n const text = token.text.slice(plainStart, cursor);\n parts.push(renderText({ ...token, raw: text, text }));\n }\n parts.push(\n `<span class=\"k2b-content-markdown__inline-token\">${renderText({ ...token, raw: inlineToken, text: inlineToken })}</span>`,\n );\n cursor += inlineToken.length;\n plainStart = cursor;\n }\n if (plainStart === 0) return renderText(token);\n if (plainStart < token.text.length) {\n const text = token.text.slice(plainStart);\n parts.push(renderText({ ...token, raw: text, text }));\n }\n return parts.join(\"\");\n };\n return renderer;\n};\n\nexport const renderSafeMarkdown = (markdown: string, options: MarkdownRenderOptions = {}): string =>\n createSafeMarked(options.locale).parse(markdown, { async: false, renderer: createSafeRenderer(options) }) as string;\n\n/**\n * Internal to the package: the Markdown grammar of `renderSafeMarkdown`, for a component that renders with an adjusted\n * safe renderer or reads the tokens, as `MessageRow` does.\n */\nexport const createSafeMarked = (locale?: string): Marked => new Marked(markdownInfoBlocks({ locale }));\n\n/**\n * Markdown View Component (SSR)\n *\n * Renders untrusted Markdown safely by default. Raw HTML and unsafe link\n * protocols are escaped. Info blocks (`:::note`, `:::info`, `:::success`,\n * `:::warning`, `:::danger`) render as the calm `NoticeCard`. Already-rendered\n * HTML requires the deliberately named `trustedHtml` boundary; the caller owns\n * sanitization in that mode.\n *\n * @example\n * ```tsx\n * import { MarkdownView } from \"@k2b/ui\";\n *\n * <MarkdownView markdown={source} />;\n * ```\n *\n * @example Compact headings, e.g. inside comments or file previews:\n * ```tsx\n * <MarkdownView markdown={source} headingScale=\"compact\" />;\n * ```\n */\nexport default function MarkdownView(props: MarkdownViewProps) {\n const locale = useLocale();\n const html = () =>\n props.markdown !== undefined\n ? renderSafeMarkdown(props.markdown, {\n inlineTokens: props.inlineTokens,\n allowImages: props.allowImages,\n linkProtocols: props.linkProtocols,\n linkTarget: props.linkTarget,\n locale: locale(),\n })\n : props.trustedHtml;\n return (\n <div\n class={`k2b-content-markdown ${props.class ?? \"\"}`}\n data-heading-scale={props.headingScale && props.headingScale !== \"normal\" ? props.headingScale : undefined}\n innerHTML={html()}\n />\n );\n}\n"],"mappings":";;;;AAAA,SAAS,MAAM,EAAE,QAAQ,QAAqB,QAAQ;AACtD,SAAS,SAAS,QAAQ,gBAAgB;AAC1C,SAAS,kBAAkB,QAAQ,wBAAwB;AAwC3D,OAAO,MAAM,UAAU,GAAI,KAAa,IACtC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;AAEnI,MAAM,OAAO,GAAI,KAAa,IAAoB;EAChD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,kCAAkC,EAAE,EAAE,CAAC;EAC/E,IAAI,iCAAiC,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,OAAO,IAAI;EACnE,OAAO,KAAK;AACd,CAAC;AAED,MAAM,qBAAqB,GAAI,MAAqC,IAClE,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAA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AW;IAC9B,aAAa,EAAE,KAAK,CAAC,aAAa;IAClC,UAAU,EAAE,KAAK,CAAC,UAAU;IAC5B,MAAM,EAAE,MAAM,CAAC;EACjB,CAAC,CAAC,GACF,KAAK,CAAC,WAAW;EACvB,qBAEW,iCAAwB,KAAK,CAAC,KAAK,IAAI,EAAE,SAAE,uCAC9B,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,YAAY,KAAK,QAAQ,YAAG,KAAK,CAAC,YAAY,mBAAG,SAAS,iBAC/F,IAAI,CAAC,CAAC;AAGvB","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["content/MarkdownView.tsx"],"sourcesContent":["import { Marked, Renderer, type Tokens } from \"marked\";\nimport { useLocale } from \"../intl/locale\";\nimport { markdownInfoBlocks } from \"./markdown-info-blocks\";\nimport { markdownLinkReference, renderMarkdownLink } from \"./markdown-links\";\n\ntype CommonProps = MarkdownRenderOptions & {\n /** Optional additional CSS classes */\n class?: string;\n /**\n * Visual heading scale. Markdown heading levels and document structure stay\n * unchanged.\n */\n headingScale?: \"compact\" | \"normal\" | \"large\";\n};\n\nexport type MarkdownViewProps = CommonProps &\n (\n | {\n /** Untrusted Markdown. Raw HTML and unsafe link protocols are escaped. */\n markdown: string;\n /** Exact standalone text tokens to emphasize without changing Markdown parsing or trusted-HTML boundaries. */\n inlineTokens?: readonly string[];\n trustedHtml?: never;\n }\n | {\n /** Explicitly trusted, already-rendered HTML. The caller owns sanitization. */\n trustedHtml: string;\n markdown?: never;\n inlineTokens?: never;\n }\n );\n\nexport type MarkdownRenderOptions = {\n inlineTokens?: readonly string[];\n /** Whether to render images. False renders alt text without resource requests. Defaults to true. */\n allowImages?: boolean;\n /** Optional protocol allowlist, including trailing colons. Relative URLs resolve as HTTPS. */\n linkProtocols?: readonly string[];\n linkTarget?: \"_blank\";\n /** Locale for the screen-reader names of untitled info blocks. `MarkdownView` passes the inherited render locale. */\n locale?: string;\n};\n\nexport const escapeHtml = (value: string): string =>\n value.replaceAll(\"&\", \"&amp;\").replaceAll(\"<\", \"&lt;\").replaceAll(\">\", \"&gt;\").replaceAll('\"', \"&quot;\").replaceAll(\"'\", \"&#39;\");\n\nconst safeUrl = (value: string): string | null => {\n const normalized = value.trim().replace(/[\\u0000-\\u001f\\u007f-\\u009f\\s]+/g, \"\");\n if (/^(?:javascript|vbscript|data):/i.test(normalized)) return null;\n return value;\n};\n\nconst normalizeInlineTokens = (tokens: readonly string[] | undefined): string[] =>\n [...new Set(tokens?.filter(Boolean) ?? [])].sort((left, right) => right.length - left.length);\n\nconst isStandaloneInlineToken = (text: string, start: number, value: string): boolean => {\n const before = text[start - 1];\n if (before && /[a-zA-Z0-9_.%+\\-]/.test(before)) return false;\n const end = start + value.length;\n const after = text[end];\n if (after && /[a-zA-Z0-9_@]/.test(after)) return false;\n return !(after === \".\" && /[a-zA-Z0-9_]/.test(text[end + 1] ?? \"\"));\n};\n\nexport const createSafeRenderer = (options: MarkdownRenderOptions = {}): Renderer => {\n const renderer = new Renderer();\n const inlineTokens = normalizeInlineTokens(options.inlineTokens);\n const baseText = renderer.text.bind(renderer);\n // marked flags text that follows an inline <pre>, <code>, <kbd> or <script>\n // tag as already escaped, because it expects that tag to reach the output as\n // HTML. The tag is escaped here, so the text after it is escaped as well.\n const renderText: Renderer[\"text\"] = (token) => baseText(token.type === \"text\" && token.escaped ? { ...token, escaped: false } : token);\n const renderTable = renderer.table.bind(renderer);\n renderer.table = (token: Tokens.Table) => {\n const table = renderTable(token);\n const content = token.header.every((cell) => !cell.text.trim()) ? table.replace(/<thead>[\\s\\S]*?<\\/thead>\\n?/, \"\") : table;\n return `<div class=\"k2b-content-markdown__table\" tabindex=\"0\">${content}</div>`;\n };\n renderer.html = ({ text }: Tokens.HTML | Tokens.Tag) => escapeHtml(text);\n renderer.link = function ({ href, title, tokens }: Tokens.Link) {\n const body = this.parser.parseInline(tokens);\n const url = safeUrl(href);\n if (!url) return body;\n if (options.linkProtocols) {\n try {\n if (!options.linkProtocols.includes(new URL(url, \"https://markdown.invalid/\").protocol)) return body;\n } catch {\n return body;\n }\n }\n return renderMarkdownLink({\n href: url,\n html: body,\n title: title ?? undefined,\n target: options.linkTarget,\n reference: markdownLinkReference(url),\n locale: options.locale,\n });\n };\n renderer.image = ({ href, title, text }: Tokens.Image) => {\n const url = safeUrl(href);\n if (!url || options.allowImages === false) return escapeHtml(text);\n const titleAttribute = title ? ` title=\"${escapeHtml(title)}\"` : \"\";\n return `<img src=\"${escapeHtml(url)}\" alt=\"${escapeHtml(text)}\"${titleAttribute}>`;\n };\n renderer.text = (token) => {\n if (inlineTokens.length === 0 || token.type === \"escape\" || (\"tokens\" in token && token.tokens)) return renderText(token);\n const parts: string[] = [];\n let plainStart = 0;\n let cursor = 0;\n while (cursor < token.text.length) {\n const inlineToken = inlineTokens.find(\n (candidate) => token.text.startsWith(candidate, cursor) && isStandaloneInlineToken(token.text, cursor, candidate),\n );\n if (!inlineToken) {\n cursor += 1;\n continue;\n }\n if (plainStart < cursor) {\n const text = token.text.slice(plainStart, cursor);\n parts.push(renderText({ ...token, raw: text, text }));\n }\n parts.push(\n `<span class=\"k2b-content-markdown__inline-token\">${renderText({ ...token, raw: inlineToken, text: inlineToken })}</span>`,\n );\n cursor += inlineToken.length;\n plainStart = cursor;\n }\n if (plainStart === 0) return renderText(token);\n if (plainStart < token.text.length) {\n const text = token.text.slice(plainStart);\n parts.push(renderText({ ...token, raw: text, text }));\n }\n return parts.join(\"\");\n };\n return renderer;\n};\n\nexport const renderSafeMarkdown = (markdown: string, options: MarkdownRenderOptions = {}): string =>\n createSafeMarked(options.locale).parse(markdown, { async: false, renderer: createSafeRenderer(options) }) as string;\n\n/**\n * Internal to the package: the Markdown grammar of `renderSafeMarkdown`, for a component that renders with an adjusted\n * safe renderer or reads the tokens, as `MessageRow` does.\n */\nexport const createSafeMarked = (locale?: string): Marked => new Marked(markdownInfoBlocks({ locale }));\n\n/**\n * Markdown View Component (SSR)\n *\n * Renders untrusted Markdown safely by default. Raw HTML and unsafe link\n * protocols are escaped. Info blocks (`:::note`, `:::info`, `:::success`,\n * `:::warning`, `:::danger`) render as the calm `NoticeCard`. Already-rendered\n * HTML requires the deliberately named `trustedHtml` boundary; the caller owns\n * sanitization in that mode.\n *\n * @example\n * ```tsx\n * import { MarkdownView } from \"@k2b/ui\";\n *\n * <MarkdownView markdown={source} />;\n * ```\n *\n * @example Compact headings, e.g. inside comments or file previews:\n * ```tsx\n * <MarkdownView markdown={source} headingScale=\"compact\" />;\n * ```\n */\nexport default function MarkdownView(props: MarkdownViewProps) {\n const locale = useLocale();\n const html = () =>\n props.markdown !== undefined\n ? renderSafeMarkdown(props.markdown, {\n inlineTokens: props.inlineTokens,\n allowImages: props.allowImages,\n linkProtocols: props.linkProtocols,\n linkTarget: props.linkTarget,\n locale: locale(),\n })\n : props.trustedHtml;\n return (\n <div\n class={`k2b-content-markdown ${props.class ?? \"\"}`}\n data-heading-scale={props.headingScale && props.headingScale !== \"normal\" ? props.headingScale : undefined}\n innerHTML={html()}\n />\n );\n}\n"],"mappings":";;;;AAAA,SAAS,MAAM,EAAE,QAAQ,QAAqB,QAAQ;AACtD,SAAS,SAAS,QAAQ,gBAAgB;AAC1C,SAAS,kBAAkB,QAAQ,wBAAwB;AAC3D,SAAS,qBAAqB,EAAE,kBAAkB,QAAQ,kBAAkB;AAwC5E,OAAO,MAAM,UAAU,GAAI,KAAa,IACtC,KAAK,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;AAEnI,MAAM,OAAO,GAAI,KAAa,IAAoB;EAChD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,kCAAkC,EAAE,EAAE,CAAC;EAC/E,IAA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,MAAM,GAAG,SAAS,CAAC,CAAC;EAC1B,MAAM,IAAI,GAAG,MACX,KAAK,CAAC,QAAQ,KAAK,SAAS,GACxB,kBAAkB,CAAC,KAAK,CAAC,QAAQ,EAAE;IACjC,YAAY,EAAE,KAAK,CAAC,YAAY;IAChC,WAAW,EAAE,KAAK,CAAC,WAAW;IAC9B,aAAa,EAAE,KAAK,CAAC,aAAa;IAClC,UAAU,EAAE,KAAK,CAAC,UAAU;IAC5B,MAAM,EAAE,MAAM,CAAC;EACjB,CAAC,CAAC,GACF,KAAK,CAAC,WAAW;EACvB,qBAEW,iCAAwB,KAAK,CAAC,KAAK,IAAI,EAAE,SAAE,uCAC9B,KAAK,CAAC,YAAY,IAAI,KAAK,CAAC,YAAY,KAAK,QAAQ,YAAG,KAAK,CAAC,YAAY,mBAAG,SAAS,iBAC/F,IAAI,CAAC,CAAC;AAGvB","ignoreList":[]}
@@ -0,0 +1,208 @@
1
+ import { ssr as _$ssr } from "solid-js/web";
2
+ import { createComponent as _$createComponent } from "solid-js/web";
3
+ import { ssrStyleProperty as _$ssrStyleProperty } from "solid-js/web";
4
+ import { ssrAttribute as _$ssrAttribute } from "solid-js/web";
5
+ import { escape as _$escape } from "solid-js/web";
6
+ var _tmpl$ = ["<video class=\"k2b-video-player__video\"", " controls playsinline preload=\"metadata\" tabindex=\"0\"", ">", "</video>"],
7
+ _tmpl$2 = ["<div class=\"", "\"", " style=\"", "\">", "</div>"],
8
+ _tmpl$3 = ["<div class=\"k2b-video-player__fallback\">", "</div>"];
9
+ /**
10
+ * VideoPlayer — one video with the browser's own controls inside a frame whose
11
+ * size never depends on the video. The frame fills the height its host gives
12
+ * it, or keeps a ratio where the host leaves the height open. The picture fits
13
+ * inside uncropped, so a portrait reel and a wide recording both show whole and
14
+ * nothing moves while the video loads.
15
+ */
16
+
17
+ import { createEffect, createSignal, Match, Switch } from "solid-js";
18
+ import { useUiMessages } from "../intl/messages";
19
+ import Placeholder from "../surfaces/Placeholder";
20
+ /** How far the arrow keys move playback, in seconds. */
21
+ const SEEK_STEP = 5;
22
+
23
+ /**
24
+ * How long a renewed address has to hold at the point where its predecessor failed before a failure there counts as
25
+ * new. A video that cannot play at a point fails again within moments, also where the engine reads or decodes ahead of
26
+ * playback; an expired address fails only after its lifetime, which for a signed URL is typically a minute or more.
27
+ */
28
+ const RENEWED_GRACE_MS = 10_000;
29
+
30
+ /** Safari on iOS shows no frame before playback without a poster; a media fragment makes it load and show the first one. */
31
+ const withFirstFrame = src => src.includes("#") ? src : `${src}#t=0.001`;
32
+
33
+ /** Where focus goes when the fallback replaces the focused video. */
34
+ const FALLBACK_FOCUS = ".k2b-video-player__fallback :is(a[href], button:not(:disabled))";
35
+ export function VideoPlayer(props) {
36
+ const messages = useUiMessages();
37
+ const [source, setSource] = createSignal(props.src);
38
+ const [failed, setFailed] = createSignal(false);
39
+ let frame;
40
+ let video;
41
+ /**
42
+ * The last renewal: where to continue once the renewed address has loaded, and since when it shows that point. Until
43
+ * it has held there for a while, a failure means the video itself does not play, not that the address expired.
44
+ */
45
+ let renewal = null;
46
+ /** Playing as the viewer meant it; a failing source may stop without a pause event. */
47
+ let playing = false;
48
+
49
+ // A new address from the host is another video: start over without resuming. It counts as new against the address
50
+ // the player started with, because the host may change it before this effect first runs, for example on mount.
51
+ let hostSrc = props.src;
52
+ createEffect(() => {
53
+ const src = props.src;
54
+ if (src === hostSrc) return;
55
+ hostSrc = src;
56
+ renewal = null;
57
+ playing = false;
58
+ setFailed(false);
59
+ setSource(src);
60
+ });
61
+ const videoSource = () => {
62
+ const src = source();
63
+ return src && !props.poster ? withFirstFrame(src) : src ?? undefined;
64
+ };
65
+ const giveUp = () => {
66
+ // The fallback replaces the video, so focus on the video would drop to the page; it moves into the fallback.
67
+ const focused = video !== undefined && document.activeElement === video;
68
+ setFailed(true);
69
+ if (focused) (frame?.querySelector(FALLBACK_FOCUS) ?? frame)?.focus();
70
+ props.onFallback?.();
71
+ };
72
+ const fail = async () => {
73
+ const element = video;
74
+ if (!element || failed()) return;
75
+ const recent = renewal && (renewal.readyAt === null || performance.now() - renewal.readyAt < RENEWED_GRACE_MS);
76
+ if (!props.renew || recent) return giveUp();
77
+ const requested = props.src;
78
+ renewal = {
79
+ time: element.currentTime,
80
+ rate: element.playbackRate,
81
+ playing,
82
+ loaded: false,
83
+ readyAt: null
84
+ };
85
+ try {
86
+ const renewed = await props.renew();
87
+ if (requested !== props.src) return;
88
+ if (renewed === source()) element.load();else setSource(renewed);
89
+ } catch {
90
+ if (requested === props.src) giveUp();
91
+ }
92
+ };
93
+ const loaded = () => {
94
+ const element = video;
95
+ if (!element) return;
96
+ // Sound in an empty frame: the browser cannot decode the picture, for example HEVC outside Safari. A fresh address
97
+ // does not change that.
98
+ if (element.videoWidth === 0 && element.videoHeight === 0) return giveUp();
99
+ if (!renewal || renewal.loaded) return;
100
+ renewal.loaded = true;
101
+ if (renewal.time > 0) element.currentTime = renewal.time;
102
+ element.playbackRate = renewal.rate;
103
+ if (renewal.playing) void element.play().catch(() => undefined);
104
+ };
105
+
106
+ /** The renewed address holds once the video shows the point where it continues. */
107
+ const ready = event => {
108
+ const element = event.currentTarget;
109
+ if (renewal?.loaded && renewal.readyAt === null && !element.seeking && element.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) renewal.readyAt = performance.now();
110
+ };
111
+ const fullscreen = element => {
112
+ if (document.fullscreenElement) return void document.exitFullscreen().catch(() => undefined);
113
+ if (element.requestFullscreen) return void element.requestFullscreen().catch(() => undefined);
114
+ // Safari on iOS has no element fullscreen for video, only its own player.
115
+ if ("webkitEnterFullscreen" in element && typeof element.webkitEnterFullscreen === "function") element.webkitEnterFullscreen();
116
+ };
117
+ const toggle = element => {
118
+ if (element.paused) void element.play().catch(() => undefined);else element.pause();
119
+ };
120
+
121
+ /** Whether the video was paused when Space went down; null while no Space press is open. */
122
+ let spacePaused = null;
123
+
124
+ // Native controls differ per engine: WebKit has no keyboard playback at all, so the player gives every engine the
125
+ // same keys. The keys reach the player only while the video itself has focus, not one of the browser's buttons.
126
+ const onKeyDown = event => {
127
+ if (event.altKey || event.ctrlKey || event.metaKey) return;
128
+ const element = event.currentTarget;
129
+ switch (event.key) {
130
+ case " ":
131
+ // Chromium toggles on release whatever the page does, so Space waits for it and toggles only if it did not.
132
+ if (!event.repeat) spacePaused = element.paused;
133
+ break;
134
+ case "k":
135
+ toggle(element);
136
+ break;
137
+ case "ArrowLeft":
138
+ element.currentTime = Math.max(0, element.currentTime - SEEK_STEP);
139
+ break;
140
+ case "ArrowRight":
141
+ element.currentTime = Number.isFinite(element.duration) ? Math.min(element.duration, element.currentTime + SEEK_STEP) : element.currentTime + SEEK_STEP;
142
+ break;
143
+ case "m":
144
+ element.muted = !element.muted;
145
+ break;
146
+ case "f":
147
+ fullscreen(element);
148
+ break;
149
+ default:
150
+ return;
151
+ }
152
+ event.preventDefault();
153
+ };
154
+ const onKeyUp = event => {
155
+ if (event.key !== " " || spacePaused === null) return;
156
+ const element = event.currentTarget;
157
+ const paused = spacePaused;
158
+ spacePaused = null;
159
+ setTimeout(() => {
160
+ if (element.paused === paused) toggle(element);
161
+ });
162
+ };
163
+ return _$ssr(_tmpl$2, `k2b-video-player ${_$escape(props.class ?? "", true)}`, _$ssrAttribute("data-state", failed() ? "failed" : _$escape(undefined, true), false) + _$ssrAttribute("tabindex", failed() ? -1 : _$escape(undefined, true), false), _$ssrStyleProperty("aspect-ratio:", _$escape(String(props.ratio && props.ratio > 0 ? props.ratio : 16 / 9), true)), _$escape(_$createComponent(Switch, {
164
+ get fallback() {
165
+ return _$createComponent(Placeholder, {
166
+ "class": "k2b-video-player__fallback",
167
+ state: "loading"
168
+ });
169
+ },
170
+ get children() {
171
+ return [_$createComponent(Match, {
172
+ get when() {
173
+ return props.error;
174
+ },
175
+ children: error => _$ssr(_tmpl$3, _$escape(error()))
176
+ }), _$createComponent(Match, {
177
+ get when() {
178
+ return failed();
179
+ },
180
+ get children() {
181
+ return _$createComponent(Placeholder, {
182
+ "class": "k2b-video-player__fallback",
183
+ state: "error",
184
+ icon: "ti ti-video-off",
185
+ get title() {
186
+ return messages().videoCannotPlay;
187
+ },
188
+ get description() {
189
+ return messages().videoCannotPlayDescription;
190
+ },
191
+ get action() {
192
+ return props.fallbackAction;
193
+ }
194
+ });
195
+ }
196
+ }), _$createComponent(Match, {
197
+ get when() {
198
+ return source();
199
+ },
200
+ get children() {
201
+ return _$ssr(_tmpl$, _$ssrAttribute("src", _$escape(videoSource(), true), false) + _$ssrAttribute("poster", _$escape(props.poster, true), false) + _$ssrAttribute("crossorigin", _$escape(props.crossOrigin, true), false), _$ssrAttribute("aria-label", _$escape(props.label, true), false), _$escape(messages().videoUnsupported));
202
+ }
203
+ })];
204
+ }
205
+ })));
206
+ }
207
+ export default VideoPlayer;
208
+ //# sourceMappingURL=VideoPlayer.js.map